import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import test from 'node:test'; import { stampHfIdsInPlace } from '@hyperframes/parsers/hf-ids'; import { applyCanvasCommand } from '../../packages/edit-core/canvas-commands.ts'; import { extractGsapScriptBlock } from '../../packages/edit-core/gsap-block.ts'; import { applyGsapMutationsInMemory } from '../../packages/edit-core/gsap-mutations.ts'; import { createTextPatch } from '../../shared/create-text-patch.ts'; import { applyTextPatch } from '../../shared/text-patch.ts'; const timeline = 'const tl=gsap.timeline();\r\ntl.to("#title",{x:10,duration:1},0);'; test('writes the selected timeline to its own source span, including when other scripts are identical', () => { const replacements = timeline.replace('x:10', 'x:40'); const prefix = "\r\n
" + `\r\n` + `` + `\r\n\r\n`; const file = prefix + timeline + suffix; const block = extractGsapScriptBlock(file)!; assert.equal(block.replaceScript(timeline), file); assert.equal(block.replaceScript(replacements), prefix + replacements + suffix); const selected = block.document.querySelector('script[data-note]')!; selected.replaceWith(selected.cloneNode(true)); assert.throws(() => block.replaceScript(replacements), /Cannot locate/); }); test('a final timeline script inside a fragment keeps preceding scripts, comments and trailing newlines intact', () => { const prefix = "\r\n\r\n" + "Text
\r\n'; const file = prefix + timeline + suffix; const next = timeline.replace('duration:1', 'duration:3'); assert.equal(extractGsapScriptBlock(file)!.replaceScript(next), prefix + next + suffix); }); test('batched animations preserve template markup and clear only the animated elements’ old offsets', () => { const target = "