(
code: CodeTree,
time: number,
timingFunction: TimingFunction,
)
| 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; |
nothing calls this directly
no test coverage detected