diff --git a/sdk/ui/src/html/page/time.ts b/sdk/ui/src/html/page/time.ts index 6d618f0b..3b1e4fef 100644 --- a/sdk/ui/src/html/page/time.ts +++ b/sdk/ui/src/html/page/time.ts @@ -101,9 +101,11 @@ export async function seek(t: number) { } catch (e) { warn(`gsap tick: ${e}`); } + // a paused timeline's playhead starts at 0, so totalTime(0) is a no-op and its time-0 sets never apply (#79): force that render + const to = (tl: any, x: number) => (x === 0 && typeof tl.render === "function" ? tl.render(0, false, true) : tl.totalTime(x, false)); try { - S.rootTl?.totalTime(Math.max(0, Math.min(t, S.rootTl.totalDuration())), false); - for (const [tl, at] of S.nested) tl.totalTime(Math.max(0, Math.min(t - at, tl.totalDuration())), false); + if (S.rootTl) to(S.rootTl, Math.max(0, Math.min(t, S.rootTl.totalDuration()))); + for (const [tl, at] of S.nested) to(tl, Math.max(0, Math.min(t - at, tl.totalDuration()))); } catch (e) { warn(`timeline seek: ${e}`); } diff --git a/sdk/ui/test/html-frame-zero.test.ts b/sdk/ui/test/html-frame-zero.test.ts new file mode 100644 index 00000000..7f787e54 --- /dev/null +++ b/sdk/ui/test/html-frame-zero.test.ts @@ -0,0 +1,24 @@ +// Frame 0 of an HTML page applies its GSAP timeline's time-0 sets (issue #79). A paused timeline's playhead starts +// at 0, so seeking it to 0 was a no-op and frame 0 showed the page's raw CSS. Uses GSAP from jsdelivr, as +// bench/html-png does (html-run caches it under ~/Library/Caches/raea). +import { expect, test } from "bun:test"; +import { mkdtempSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; + +test("frame 0 shows the timeline's sets at 0 (#79)", async () => { + const dir = mkdtempSync(join(tmpdir(), "raea-html-frame0-")); + writeFileSync( + join(dir, "index.html"), + ` +
A
B
+`, + ); + const run = Bun.spawn(["bun", join(import.meta.dir, "html-run.ts"), dir, "0"], { stdout: "pipe", stderr: "pipe" }); + const out = await new Response(run.stdout).text(); + await run.exited; + expect(out).toMatch(/id=a \{"opacity":0\}/); + expect(out).toMatch(/id=b \{"transform":"translate\(200px, 0px\)"\}/); +}, 30_000);