Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(core): a caption line shows again after the playhead jumps back over it (#5690)
Miguel Ángel4e6fcdb3a9f3
diff --git a/packages/core/src/runtime/init.test.ts b/packages/core/src/runtime/init.test.tsindex f67fbaa534..2a56463e91 100644--- a/packages/core/src/runtime/init.test.ts+++ b/packages/core/src/runtime/init.test.ts@@ -513,6 +513,25 @@ describe("initSandboxRuntimeModular", () => {}});+ it.each(["seek", "renderSeek"] as const)(+ "shows a clip's child again after a %s skipped past the GSAP set that hides it at the clip's end",+ (seek) => {+ document.body.innerHTML =+ `<div data-composition-id="main" data-root="true" data-start="0" data-duration="10" data-width="1920" data-height="1080">` ++ `<div id="line" style="position: absolute" data-start="2" data-duration="2"><div id="words"></div></div>` ++ `</div>`;+ const tl = gsap.timeline({ paused: true });+ tl.set("#words", { visibility: "hidden" }, 3.9);+ window.__timelines = { main: tl as unknown as RuntimeTimelineLike };+ initSandboxRuntimeModular();+ const words = document.getElementById("words")!;+ // The set first renders on this jump, while its clip is off screen.+ window.__player?.[seek](6);+ window.__player?.[seek](3);+ expect(getComputedStyle(words).visibility).toBe("visible");+ },+ );+it("keeps a hidden scene's contents hidden when a rewound GSAP set marks one visible inline", () => {hideTimedClipsUntilFirstPass();try {diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.tsindex f856b13a99..e3d109a141 100644--- a/packages/core/src/runtime/init.ts+++ b/packages/core/src/runtime/init.ts@@ -10,6 +10,7 @@ import {CLIP_HIDDEN_ATTR,revealTimedClipsAfterFirstPass,SKIPPED_CLIP,+ showHiddenClips,skipsHiddenImages,} from "./timedClipHide";import {@@ -4235,6 +4236,7 @@ export function initSandboxRuntimeModular(): void {// Reuse a completed seek only for the exact requested time and captured timeline.// Paused players and host ticks can share the frame without suppressing a newer time.let lastTransportSeekTime = Number.NaN;+ let tweensRenderedThrough = { revision: Number.NaN, time: Number.NEGATIVE_INFINITY };let lastTransportSeekTimeline: RuntimeTimelineLike | null = null;let pausedSeekDeferredByManualGesture = false;// Set while the transport is parked (see scheduleNextTransportFrame).@@ -4394,6 +4396,12 @@ export function initSandboxRuntimeModular(): void {opts?: { activateChildren?: boolean; suppressEvents?: boolean },): () => Animation[] {const suppressEvents = opts?.suppressEvents === true;+ const revision = readCompositionTimingRevision();+ if (revision !== tweensRenderedThrough.revision)+ tweensRenderedThrough = { revision, time: Number.NEGATIVE_INFINITY };+ const jumped = !(Math.abs(t - lastTransportSeekTime) <= 1.5 / state.canonicalFps);+ const firstRenders = jumped && t > tweensRenderedThrough.time;+ const hideClipsAgain = firstRenders ? showHiddenClips() : null;if (tl) {// #10: when data-duration exceeds the timeline's intrinsic length the// engine requests frames past the last tween. Seeking a paused GSAP@@ -4442,6 +4450,8 @@ export function initSandboxRuntimeModular(): void {// the deterministic adapters, syncTimedElementVisibility, the hf-timelines-built// handler and __hfReseekGpu. It only ever moved the state the seek left behind.seekStandaloneRegisteredTimelines(t, opts);+ hideClipsAgain?.();+ tweensRenderedThrough.time = Math.max(tweensRenderedThrough.time, t);const pageAnimations = pageAnimationsForOnePass();for (const adapter of state.deterministicAdapters) {if (adapter.name === "gsap" && tl) continue;diff --git a/packages/core/src/runtime/timedClipHide.ts b/packages/core/src/runtime/timedClipHide.tsindex af55f3e8c8..5e141066f0 100644--- a/packages/core/src/runtime/timedClipHide.ts+++ b/packages/core/src/runtime/timedClipHide.ts@@ -19,6 +19,14 @@ export const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";const CONTENTS_ATTR = "data-hf-hidden-clip-contents";const HIDE_HIDDEN_CLIP_CONTENTS = `[${CLIP_HIDDEN_ATTR}][style*="visibility: hidden"] * { visibility: hidden !important; }`;+export function showHiddenClips(): () => void {+ const hidden = Array.from(document.querySelectorAll<HTMLElement>(`[${CLIP_HIDDEN_ATTR}]`));+ for (const el of hidden) el.style.visibility = "visible";+ return () => {+ for (const el of hidden) el.style.visibility = "hidden";+ };+}+type FirstPassWindow = Window & {__hfFirstPassHidden?: boolean;__hyperframeRuntimeBootstrapped?: boolean;