From 531313c4b15fc14fe25692f072d5a8aa3b6644c8 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Thu, 15 Oct 2026 10:33:08 -0700 Subject: [PATCH 1/3] fix(core): timed svg clips hide outside their window --- packages/core/src/runtime/init.test.ts | 40 ++++++++++++++++++++++++++ packages/core/src/runtime/init.ts | 5 ++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/core/src/runtime/init.test.ts b/packages/core/src/runtime/init.test.ts index 5c3f5d763ca..f67fbaa534a 100644 --- a/packages/core/src/runtime/init.test.ts +++ b/packages/core/src/runtime/init.test.ts @@ -1472,6 +1472,46 @@ describe("initSandboxRuntimeModular", () => { expect(earlyClip.style.visibility).toBe("hidden"); }); + it("shows only the full-frame clip whose window holds the seek", () => { + const root = buildRoot(); + const SVG_NS = "http://www.w3.org/2000/svg"; + const windows = [ + [0, 4], + [4, 8], + [12, 8], + ]; + const layers = windows.map(([start, duration]) => { + const svg = document.createElementNS(SVG_NS, "svg"); + svg.setAttribute("data-start", String(start)); + svg.setAttribute("data-duration", String(duration)); + // A timed shape that outlives its layer must still go with it. + const shape = document.createElementNS(SVG_NS, "rect"); + shape.setAttribute("data-start", "0"); + shape.setAttribute("data-duration", "20"); + svg.appendChild(shape); + root.appendChild(svg); + return { svg, shape }; + }); + window.__timelines = { main: createMockTimeline(20) }; + initSandboxRuntimeModular(); + + for (const [time, shown] of [ + [1, 0], + [5, 1], + [16, 2], + ]) { + window.__player?.renderSeek(time); + expect( + layers.map(({ svg }) => svg.style.visibility), + `layers at ${time}s`, + ).toEqual(layers.map((_, i) => (i === shown ? "visible" : "hidden"))); + expect( + layers.map(({ shape }) => shape.style.visibility), + `shapes at ${time}s`, + ).toEqual(layers.map((_, i) => (i === shown ? "visible" : "hidden"))); + } + }); + it("never shows two back-to-back clips at their shared boundary", () => { const root = buildRoot(); const first = addClip(root, 0, 2.5); diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.ts index d1147382352..ef9a16a1dba 100644 --- a/packages/core/src/runtime/init.ts +++ b/packages/core/src/runtime/init.ts @@ -161,6 +161,7 @@ import { isHtmlElement, isImageElement, isMediaElement, + isStylableElement, isVideoElement, } from "./domRealm"; import { audibleVideoNeedsWebAudio, isAudibleVideoElement } from "../audibleVideo"; @@ -2690,7 +2691,7 @@ export function initSandboxRuntimeModular(): void { rootComp: HTMLElement | null, ) => { for (let node = from; node && node !== rootComp; node = node.parentElement) - if (isHtmlElement(node) && node.hasAttribute("data-start") && !visibleAt(node, time)) + if (isStylableElement(node) && node.hasAttribute("data-start") && !visibleAt(node, time)) return false; return true; }; @@ -2802,7 +2803,7 @@ export function initSandboxRuntimeModular(): void { let decidedTimedClip = false; const visibleAt = timedVisibilityAt(timingRevision); for (const rawNode of visibilityNodes) { - if (!isHtmlElement(rawNode)) continue; + if (!isStylableElement(rawNode)) continue; if (rawNode.hasAttribute("data-hidden")) { if (!dataHiddenDisplayNodes.has(rawNode)) { From 279a36020a30a72bbccd9e54137948776b6faf89 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Thu, 15 Oct 2026 14:23:08 -0700 Subject: [PATCH 2/3] fix(core): type the clip visibility path for SVG as well as HTML elements --- packages/core/src/compositionReadiness.ts | 2 +- packages/core/src/runtime/domRealm.ts | 5 ++++- packages/core/src/runtime/init.ts | 19 ++++++++++--------- packages/core/src/runtime/positionEdits.ts | 10 +--------- packages/core/src/runtime/timeline.ts | 2 +- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/packages/core/src/compositionReadiness.ts b/packages/core/src/compositionReadiness.ts index f1b959deb23..7361ecad921 100644 --- a/packages/core/src/compositionReadiness.ts +++ b/packages/core/src/compositionReadiness.ts @@ -63,7 +63,7 @@ function isActiveAtFirstFrame( while (current) { if (isTimedElement(current)) { if ( - !isRuntimeElementVisibleAt(current as HTMLElement, { + !isRuntimeElementVisibleAt(current, { currentTime: 0, compositionDuration: Number.POSITIVE_INFINITY, canonicalFps: 30, diff --git a/packages/core/src/runtime/domRealm.ts b/packages/core/src/runtime/domRealm.ts index f43c3d0d7e3..2758e0581fc 100644 --- a/packages/core/src/runtime/domRealm.ts +++ b/packages/core/src/runtime/domRealm.ts @@ -101,12 +101,15 @@ export function isLinkElement(value: unknown): value is HTMLLinkElement { return isHtmlTag(value, "link"); } +/** HTML or SVG: TypeScript narrows an `Element` by `HTMLElement | SVGElement` to `HTMLElement` alone. */ +export type StylableElement = Element & ElementCSSInlineStyle; + /** * An element that carries a CSS `style` map: HTML **or** SVG. Position edits and * transform writes apply to both (authored SVG ``/shapes honour the CSS * `translate` longhand exactly as HTML does). */ -export function isStylableElement(value: unknown): value is HTMLElement | SVGElement { +export function isStylableElement(value: unknown): value is StylableElement { return ( isElementNode(value) && ((value as NodeLike).namespaceURI === XHTML_NS || diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.ts index ef9a16a1dba..f856b13a994 100644 --- a/packages/core/src/runtime/init.ts +++ b/packages/core/src/runtime/init.ts @@ -163,6 +163,7 @@ import { isMediaElement, isStylableElement, isVideoElement, + type StylableElement, } from "./domRealm"; import { audibleVideoNeedsWebAudio, isAudibleVideoElement } from "../audibleVideo"; @@ -2557,7 +2558,7 @@ export function initSandboxRuntimeModular(): void { // instead of overlapping it. Positioned clips keep `visibility:hidden` (cheaper, // and avoids disturbing absolute media playback). Computed once per element. let timedClipInFlow = new WeakMap(); - const isTimedClipInFlow = (el: HTMLElement): boolean => { + const isTimedClipInFlow = (el: Element): boolean => { const cached = timedClipInFlow.get(el); if (cached !== undefined) return cached; const pos = window.getComputedStyle(el).position; @@ -2573,7 +2574,7 @@ export function initSandboxRuntimeModular(): void { // show. `visibility:hidden` doesn't have this problem (a child can override it // with `visibility:visible`), so containers keep that and only leaves leave-flow. let timedClipIsLeaf = new WeakMap(); - const isTimedClipLeaf = (el: HTMLElement): boolean => { + const isTimedClipLeaf = (el: Element): boolean => { const cached = timedClipIsLeaf.get(el); if (cached !== undefined) return cached; const leaf = el.querySelector("[data-start]") === null; @@ -2595,8 +2596,8 @@ export function initSandboxRuntimeModular(): void { // visibility pass applied, so showing the element puts exactly that back. Keyed on // what was applied, not on `isTimedClipInFlow`: that answer can flip between the hide // and the show pass once `applyClipLayout` force-absolutizes the clip. - const displayBeforeHide = new WeakMap(); - const hideByDisplay = (el: HTMLElement, plainNoneMayBeLeftover: boolean) => { + const displayBeforeHide = new WeakMap(); + const hideByDisplay = (el: StylableElement, plainNoneMayBeLeftover: boolean) => { if (!displayBeforeHide.has(el)) { const value = el.style.getPropertyValue("display"); const priority = el.style.getPropertyPriority("display"); @@ -2606,14 +2607,14 @@ export function initSandboxRuntimeModular(): void { } el.style.display = "none"; }; - const restoreDisplay = (el: HTMLElement) => { + const restoreDisplay = (el: StylableElement) => { const before = displayBeforeHide.get(el); if (!before) return; displayBeforeHide.delete(el); if (before.value) el.style.setProperty("display", before.value, before.priority); else el.style.removeProperty("display"); }; - const dataHiddenDisplayNodes = new WeakSet(); + const dataHiddenDisplayNodes = new WeakSet(); // A data-hidden toggle on (or affecting) an audio element must re-schedule // WebAudio playback so the hidden clip's source is dropped/restored mid- // playback. Batched to one call per syncTimedElementVisibility pass, not @@ -2632,7 +2633,7 @@ export function initSandboxRuntimeModular(): void { isMediaElement(el) && el.hasAttribute("data-start") && (joinsWebAudio(el) || webAudio.routesElement(el)); - const nodeAffectsAudio = (node: HTMLElement): boolean => + const nodeAffectsAudio = (node: Element): boolean => affectsAudio(node) || Array.from(node.querySelectorAll(WEB_AUDIO_MEDIA)).some(affectsAudio); // An `` carries no `data-start`, so it is never among @@ -2673,7 +2674,7 @@ export function initSandboxRuntimeModular(): void { 0, timingRevision, ); - return (node: HTMLElement, time: number) => + return (node: Element, time: number) => isRuntimeElementVisibleAt(node, { currentTime: time, compositionDuration, @@ -2702,7 +2703,7 @@ export function initSandboxRuntimeModular(): void { // Unskipped while within the window on either side of the playhead, so a step or shuttle back // across a cut finds the clip it left still loaded; the edge checks catch a clip shorter than it. const dueSoon = ( - node: HTMLElement, + node: Element, visibleAt: ReturnType, t: number, ahead = LOOKAHEAD_SECONDS, diff --git a/packages/core/src/runtime/positionEdits.ts b/packages/core/src/runtime/positionEdits.ts index 12d2c8e4df4..3a2550dc5ce 100644 --- a/packages/core/src/runtime/positionEdits.ts +++ b/packages/core/src/runtime/positionEdits.ts @@ -25,20 +25,12 @@ */ import { emitAnalyticsEvent } from "./analytics"; -import { isStylableElement } from "./domRealm"; +import { isStylableElement, type StylableElement } from "./domRealm"; export const EDIT_BASE_X_ATTR = "data-hf-edit-base-x"; export const EDIT_BASE_Y_ATTR = "data-hf-edit-base-y"; export const EDIT_ORIGINAL_TRANSLATE_ATTR = "data-hf-edit-original-translate"; -/** - * Elements a position edit can apply to: HTML elements AND SVG graphics (authored `` labels, - * shapes, groups). Both expose `.style` and honor the CSS `translate` longhand in modern Chrome, so - * the same delta→translate compose logic works for either. (SVG was previously excluded by an - * `instanceof HTMLElement`-only guard, which silently dropped every move on an SVG element.) - */ -type StylableElement = HTMLElement | SVGElement; - const num = (value: string | null): number => { const n = parseFloat(value ?? ""); return Number.isFinite(n) ? n : 0; diff --git a/packages/core/src/runtime/timeline.ts b/packages/core/src/runtime/timeline.ts index 459959432f0..e27f836bb50 100644 --- a/packages/core/src/runtime/timeline.ts +++ b/packages/core/src/runtime/timeline.ts @@ -32,7 +32,7 @@ import { LOOP_INFLATED_TIMELINE_SECONDS } from "./compositionLength"; import { cutToHostSlots } from "../mediaTiming"; export function isRuntimeElementVisibleAt( - rawNode: HTMLElement, + rawNode: Element, options: { currentTime: number; compositionDuration: number; From 6a3000bada7328b64a8bea9a911bf3a4d8679817 Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Thu, 15 Oct 2026 14:51:44 -0700 Subject: [PATCH 3/3] chore(core): regenerate the position edits render script --- packages/core/src/generated/position-edits-render-inline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/generated/position-edits-render-inline.ts b/packages/core/src/generated/position-edits-render-inline.ts index 5788290675c..b88bcede30d 100644 --- a/packages/core/src/generated/position-edits-render-inline.ts +++ b/packages/core/src/generated/position-edits-render-inline.ts @@ -1,6 +1,6 @@ // Generated by scripts/build-position-edits-render.ts; do not edit. const POSITION_EDITS_RENDER_IIFE: string = - '"use strict";(()=>{function T(){return globalThis}function P(e,t){if(typeof window>"u")return;let o=T(),r=o.__hf?.onSwallowed;if(r)try{r({label:e,error:t})}catch(s){}(o.__hfDebug||o.__HYPERFRAMES_DEBUG)&&console.debug(`[hyperframes] ${e} swallowed:`,t)}var x=null;function R(e,t){if(x)try{x({source:"hf-preview",type:"analytics",event:e,properties:t??{}})}catch(o){P("runtime.analytics.site1",o)}}var W="http://www.w3.org/1999/xhtml";function N(e){return e!=null&&e.nodeType===1}function k(e){return N(e)&&(e.namespaceURI===W||e.namespaceURI==="http://www.w3.org/2000/svg")}var w="data-hf-edit-base-x",y="data-hf-edit-base-y",m="data-hf-edit-original-translate",_=e=>{let t=parseFloat(e??"");return Number.isFinite(t)?t:0},O=e=>{let t=[],o=0,r="";for(let s of e.trim())s==="("&&(o+=1),s===")"&&(o=Math.max(0,o-1)),/\\s/.test(s)&&o===0?(r&&t.push(r),r=""):r+=s;return r&&t.push(r),t},L=/^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)px$/,E=(e,t)=>L.test(e)&&L.test(t)?`${parseFloat(e)+parseFloat(t)}px`:`calc(${e} + ${t})`,V=(e,t,o)=>{if(!e||e==="none")return`${t} ${o}`;let[r,s,a]=O(e);if(r===void 0)return`${t} ${o}`;if(s===void 0)return`${E(r,t)} ${o}`;let i=a===void 0?"":` ${a}`;return`${E(r,t)} ${E(s,o)}${i}`},j=e=>{try{e.ownerDocument.defaultView?.gsap?.getProperty?.(e,"x")}catch{}},C=e=>{let t=e.style.getPropertyValue("translate").trim();if(t)return t==="none"?"":t;try{let o=e.ownerDocument.defaultView,r=o?o.getComputedStyle(e).getPropertyValue("translate").trim():"";return r==="none"?"":r}catch{return""}},b=new WeakMap;function G(e,t){let o=b.get(e);if(!t?.force&&o!==void 0&&e.style.getPropertyValue("translate")!==o){R("position_edit_fold_skipped",{hfId:e.getAttribute("data-hf-id")});return}let r=_(e.getAttribute("data-x"))-_(e.getAttribute(w)),s=_(e.getAttribute("data-y"))-_(e.getAttribute(y));e.hasAttribute(m)||e.setAttribute(m,C(e)),o===void 0&&j(e);let a=e.getAttribute(m)??"",i=V(a,`${r}px`,`${s}px`);e.style.setProperty("translate",i),b.set(e,e.style.getPropertyValue("translate"))}function S(e,t){let o=e.querySelectorAll(`[${m}]:not([${w}]):not([${y}])`);for(let a=0;a{try{S(t.document)}catch{}},r=n=>typeof n=="function"&&(D.has(n)||!!n[$]),s=n=>{D.add(n);try{Object.defineProperty(n,$,{value:!0})}catch{}},a=n=>{if(typeof n!="function"||r(n))return n;let l=function(...u){let d=n.apply(this,u);return o(),d};return s(l),l},i=(n,l)=>{let u=M.get(n);if(u?.has(l))return!0;let d=Object.getOwnPropertyDescriptor(n,l);if(d?.configurable===!1){let c=n[l];return typeof c=="function"&&(n[l]=a(c),o()),!1}let p=n[l],f=d?.set;return Object.defineProperty(n,l,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>p,set:c=>{p=a(c),f?.call(n,c)}}),p=a(p),u??(u=new Set),u.add(l),M.set(n,u),o(),!0},g=(n,l)=>{let u=H.get(t),d=Object.getOwnPropertyDescriptor(t,n);if(!u?.has(n)){if(d?.configurable===!1){let c=t[n];return c?i(c,l):!1}let f=t[n];Object.defineProperty(t,n,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>f,set:c=>{f=c,f&&i(f,l)}}),u??(u=new Set),u.add(n),H.set(t,u)}let p=t[n];return p?i(p,l):!1},h=()=>{let n=g("__hf","seek"),l=g("__player","renderSeek");return n&&l};if(h())return;let v=120,A=t.setInterval(()=>{if(h()){t.clearInterval(A);return}v-=1,v<=0&&t.clearInterval(A)},50)}function I(){document.querySelector(`[${w}], [${y}]`)&&(S(document),F(window))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",I,{once:!0}):I();})();\n'; + '"use strict";(()=>{function T(){return globalThis}function P(e,t){if(typeof window>"u")return;let o=T(),r=o.__hf?.onSwallowed;if(r)try{r({label:e,error:t})}catch(s){}(o.__hfDebug||o.__HYPERFRAMES_DEBUG)&&console.debug(`[hyperframes] ${e} swallowed:`,t)}var x=null;function R(e,t){if(x)try{x({source:"hf-preview",type:"analytics",event:e,properties:t??{}})}catch(o){P("runtime.analytics.site1",o)}}var W="http://www.w3.org/1999/xhtml";function N(e){return e!=null&&e.nodeType===1}function k(e){return N(e)&&(e.namespaceURI===W||e.namespaceURI==="http://www.w3.org/2000/svg")}var w="data-hf-edit-base-x",y="data-hf-edit-base-y",m="data-hf-edit-original-translate",_=e=>{let t=parseFloat(e??"");return Number.isFinite(t)?t:0},O=e=>{let t=[],o=0,r="";for(let s of e.trim())s==="("&&(o+=1),s===")"&&(o=Math.max(0,o-1)),/\\s/.test(s)&&o===0?(r&&t.push(r),r=""):r+=s;return r&&t.push(r),t},$=/^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)px$/,E=(e,t)=>$.test(e)&&$.test(t)?`${parseFloat(e)+parseFloat(t)}px`:`calc(${e} + ${t})`,C=(e,t,o)=>{if(!e||e==="none")return`${t} ${o}`;let[r,s,a]=O(e);if(r===void 0)return`${t} ${o}`;if(s===void 0)return`${E(r,t)} ${o}`;let i=a===void 0?"":` ${a}`;return`${E(r,t)} ${E(s,o)}${i}`},V=e=>{try{e.ownerDocument.defaultView?.gsap?.getProperty?.(e,"x")}catch{}},j=e=>{let t=e.style.getPropertyValue("translate").trim();if(t)return t==="none"?"":t;try{let o=e.ownerDocument.defaultView,r=o?o.getComputedStyle(e).getPropertyValue("translate").trim():"";return r==="none"?"":r}catch{return""}},b=new WeakMap;function B(e,t){let o=b.get(e);if(!t?.force&&o!==void 0&&e.style.getPropertyValue("translate")!==o){R("position_edit_fold_skipped",{hfId:e.getAttribute("data-hf-id")});return}let r=_(e.getAttribute("data-x"))-_(e.getAttribute(w)),s=_(e.getAttribute("data-y"))-_(e.getAttribute(y));e.hasAttribute(m)||e.setAttribute(m,j(e)),o===void 0&&V(e);let a=e.getAttribute(m)??"",i=C(a,`${r}px`,`${s}px`);e.style.setProperty("translate",i),b.set(e,e.style.getPropertyValue("translate"))}function S(e,t){let o=e.querySelectorAll(`[${m}]:not([${w}]):not([${y}])`);for(let a=0;a{try{S(t.document)}catch{}},r=n=>typeof n=="function"&&(D.has(n)||!!n[L]),s=n=>{D.add(n);try{Object.defineProperty(n,L,{value:!0})}catch{}},a=n=>{if(typeof n!="function"||r(n))return n;let l=function(...u){let d=n.apply(this,u);return o(),d};return s(l),l},i=(n,l)=>{let u=F.get(n);if(u?.has(l))return!0;let d=Object.getOwnPropertyDescriptor(n,l);if(d?.configurable===!1){let c=n[l];return typeof c=="function"&&(n[l]=a(c),o()),!1}let p=n[l],f=d?.set;return Object.defineProperty(n,l,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>p,set:c=>{p=a(c),f?.call(n,c)}}),p=a(p),u??(u=new Set),u.add(l),F.set(n,u),o(),!0},g=(n,l)=>{let u=M.get(t),d=Object.getOwnPropertyDescriptor(t,n);if(!u?.has(n)){if(d?.configurable===!1){let c=t[n];return c?i(c,l):!1}let f=t[n];Object.defineProperty(t,n,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>f,set:c=>{f=c,f&&i(f,l)}}),u??(u=new Set),u.add(n),M.set(t,u)}let p=t[n];return p?i(p,l):!1},h=()=>{let n=g("__hf","seek"),l=g("__player","renderSeek");return n&&l};if(h())return;let v=120,A=t.setInterval(()=>{if(h()){t.clearInterval(A);return}v-=1,v<=0&&t.clearInterval(A)},50)}function I(){document.querySelector(`[${w}], [${y}]`)&&(S(document),H(window))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",I,{once:!0}):I();})();\n'; /** Returns the pre-built position-edits render IIFE as a string constant. */ export function getPositionEditsRenderScript(): string {