MCPcopy
hub / github.com/midrender/revideo / tweenCode

Method tweenCode

packages/2d/src/lib/components/CodeBlock.ts:286–334  ·  view source on GitHub ↗
(
    code: CodeTree,
    time: number,
    timingFunction: TimingFunction,
  )

Source from the content-addressed store, hash-verified

284
285 @threadable()
286 public *tweenCode(
287 code: CodeTree,
288 time: number,
289 timingFunction: TimingFunction,
290 ) {
291 if (typeof code === 'function') throw new Error();
292 if (!CodeBlock.initialized()) return;
293
294 const currentParsedCode = parse(this.code(), {codeStyle: this.theme()});
295 const newParsedCode = parse(code, {codeStyle: this.theme()});
296 this.currentLineCount = this.getLineCountOfTokenArray(currentParsedCode);
297 this.newLineCount = this.getLineCountOfTokenArray(newParsedCode);
298
299 const autoWidth = this.width.isInitial();
300 const autoHeight = this.height.isInitial();
301 const fromSize = this.size();
302 const toSize = this.getTokensSize(newParsedCode);
303
304 const beginning = 0.2;
305 const ending = 0.8;
306
307 this.codeProgress(0);
308 this.diffed = diff(this.code(), code, {codeStyle: this.theme()});
309 yield* tween(
310 time,
311 value => {
312 const progress = timingFunction(value);
313 const remapped = clampRemap(beginning, ending, 0, 1, progress);
314 this.codeProgress(progress);
315 if (autoWidth) {
316 this.width(easeInOutSine(remapped, fromSize.x, toSize.x));
317 }
318 if (autoHeight) {
319 this.height(easeInOutSine(remapped, fromSize.y, toSize.y));
320 }
321 },
322 () => {
323 this.codeProgress(null);
324 this.diffed = null;
325 if (autoWidth) {
326 this.width.reset();
327 }
328 if (autoHeight) {
329 this.height.reset();
330 }
331 this.code(code);
332 },
333 );
334 }
335
336 protected override async draw(context: CanvasRenderingContext2D) {
337 if (!CodeBlock.initialized()) return;

Callers

nothing calls this directly

Calls 10

getTokensSizeMethod · 0.95
tweenFunction · 0.90
clampRemapFunction · 0.90
easeInOutSineFunction · 0.90
sizeMethod · 0.80
isInitialMethod · 0.65
resetMethod · 0.65
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected