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

Function scrollToFocus

packs/standalone/src/animation.ts:142–174  ·  view source on GitHub ↗
(
  stepPair: Tuple<Step>,
  dimensions?: Dimensions
)

Source from the content-addressed store, hash-verified

140}
141
142export function scrollToFocus(
143 stepPair: Tuple<Step>,
144 dimensions?: Dimensions
145): Animation<number> {
146 if (!dimensions) {
147 return () => 0;
148 }
149
150 const [prevStep, nextStep] = stepPair.spread();
151
152 const prevCenter = prevStep
153 ? prevStep.focusCenter * dimensions.lineHeight
154 : 0;
155 const nextCenter = nextStep
156 ? nextStep.focusCenter * dimensions.lineHeight
157 : 0;
158
159 const animation = chain(
160 [
161 [EXIT, undefined],
162 [
163 SCROLL,
164 t => ({
165 scroll: tween(prevCenter, nextCenter, t, easing.easeInOutCubic)
166 })
167 ],
168 [ENTER, undefined]
169 ],
170 { scroll: prevCenter }
171 );
172
173 return t => animation(t).scroll;
174}
175
176export function scaleToFocus(
177 stepPair: Tuple<Step>,

Callers 1

CodeSurferContentFunction · 0.90

Calls 4

chainFunction · 0.85
tweenFunction · 0.85
animationFunction · 0.85
spreadMethod · 0.80

Tested by

no test coverage detected