MCPcopy Create free account
hub / github.com/pomber/code-surfer / CodeSurferContent

Function CodeSurferContent

packs/standalone/src/frame.tsx:72–153  ·  view source on GitHub ↗
({
  dimensions,
  stepPair,
  t,
  tokens,
  types,
  maxLineCount,
  showNumbers
}: {
  dimensions?: Dimensions;
  stepPair: Tuple<Step>;
  t: number;
  tokens: string[][];
  types: string[][];
  maxLineCount: number;
  showNumbers: boolean;
})

Source from the content-addressed store, hash-verified

70}
71
72function CodeSurferContent({
73 dimensions,
74 stepPair,
75 t,
76 tokens,
77 types,
78 maxLineCount,
79 showNumbers
80}: {
81 dimensions?: Dimensions;
82 stepPair: Tuple<Step>;
83 t: number;
84 tokens: string[][];
85 types: string[][];
86 maxLineCount: number;
87 showNumbers: boolean;
88}) {
89 const ref = React.useRef<HTMLPreElement | null>(null);
90
91 const scaleAnimation = React.useMemo(
92 () => scaleToFocus(stepPair, dimensions),
93 [stepPair, dimensions]
94 );
95
96 const scrollAnimation = React.useMemo(
97 () => scrollToFocus(stepPair, dimensions),
98 [stepPair, dimensions]
99 );
100
101 const scale = scaleAnimation(t);
102 const scrollTop = scrollAnimation(t);
103 const verticalOrigin = dimensions
104 ? dimensions.containerHeight / 2 + scrollTop
105 : 0;
106
107 React.useLayoutEffect(() => {
108 if (ref.current == null) return;
109 ref.current.scrollTop = scrollTop;
110 }, [scrollTop]);
111
112 const unfocusedStyle = useUnfocusedStyle();
113
114 return (
115 <Styled.Pre
116 className="cs-content"
117 ref={ref}
118 style={{
119 margin: 0,
120 height: "100%",
121 overflow: "hidden"
122 }}
123 >
124 <Styled.Code
125 className="cs-scaled-content"
126 style={{
127 display: "block",
128 //TODO isnt contentHeight always undefined?
129 height: dimensions ? dimensions.contentHeight : "100%",

Callers

nothing calls this directly

Calls 3

scaleToFocusFunction · 0.90
scrollToFocusFunction · 0.90
useUnfocusedStyleFunction · 0.90

Tested by

no test coverage detected