Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(core): resolve long nested media in local time (#3535)
Miguel Ángel3dc18562323c
diff --git a/packages/core/src/runtime/init.test.ts b/packages/core/src/runtime/init.test.tsindex e7328a4175..87e467c73c 100644--- a/packages/core/src/runtime/init.test.ts+++ b/packages/core/src/runtime/init.test.ts@@ -1187,6 +1187,43 @@ describe("initSandboxRuntimeModular", () => {expect(video.style.visibility).toBe("visible");});+ it("keeps a long video starting at zero local to its delayed composition host", () => {+ const root = document.createElement("div");+ root.setAttribute("data-composition-id", "main");+ root.setAttribute("data-root", "true");+ root.setAttribute("data-start", "0");+ root.setAttribute("data-duration", "120");+ document.body.appendChild(root);++ const host = document.createElement("div");+ host.setAttribute("data-composition-id", "nested-video");+ host.setAttribute("data-composition-file", "compositions/nested.html");+ host.setAttribute("data-start", "39.233");+ host.setAttribute("data-duration", "80");+ root.appendChild(host);++ const video = document.createElement("video");+ video.setAttribute("data-start", "0");+ video.setAttribute("data-duration", "80");+ video.load = () => {};+ host.appendChild(video);++ window.__timelines = {+ main: createMockTimeline(120),+ "nested-video": createMockTimeline(80),+ };++ initSandboxRuntimeModular();++ for (const globalTime of [+ 42.353, 49.412, 56.471, 63.529, 70.588, 77.647, 84.706, 91.765, 98.824, 105.882, 112.941,+ ]) {+ window.__player?.renderSeek(globalTime);+ expect(video.style.visibility, `global ${globalTime}s`).toBe("visible");+ }+ expect(window.__hfResolveMediaStartSeconds?.(video)).toBeCloseTo(39.233);+ });+it("uses the canonical resolver for reference starts, auto-start media, and inline hosts", () => {const root = document.createElement("div");root.setAttribute("data-composition-id", "main");diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.tsindex 4f172652fc..880c9692bb 100644--- a/packages/core/src/runtime/init.ts+++ b/packages/core/src/runtime/init.ts@@ -663,22 +663,15 @@ export function initSandboxRuntimeModular(): void {// Both timing conventions exist in shipped projects:// - composition-local media, e.g. host@20 + video@0 => root@20- // Preserve the global value when its authored window already intersects- // the host's absolute window. Otherwise it is unambiguously local and- // must inherit the recursively-resolved host start.- const authoredDuration = parseStrictFiniteTimingNumber(element.getAttribute("data-duration"));+ // Preserve the global value when its authored start already falls inside+ // the host's absolute window. A long local clip can overlap that window+ // even when its start is local ([email protected] + video@0/duration=80), so the+ // duration cannot disambiguate the timing convention.const hostDuration = context.inheritedDuration;const hostEnd = hostDuration != null && hostDuration > 0 ? inheritedStart + hostDuration : null;- const authoredEnd =- authoredDuration != null && authoredDuration > 0- ? authoredStart + authoredDuration- : authoredStart;- const overlapsHostWindow =- hostEnd == null- ? authoredStart >= inheritedStart- : authoredStart < hostEnd &&- (authoredEnd > inheritedStart || authoredStart === inheritedStart);- return overlapsHostWindow ? authoredStart : inheritedStart + authoredStart;+ const startsInsideHostWindow =+ authoredStart >= inheritedStart && (hostEnd == null || authoredStart < hostEnd);+ return startsInsideHostWindow ? authoredStart : inheritedStart + authoredStart;};window.__hfResolveMediaStartSeconds = resolveAbsoluteMediaStartSeconds;