@hyperframes/studio 0.9.39 → 0.9.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{A as Ht,m as Ke,I as qt,v as le,p as Di,t as oe,b as Ni,a as m,w as Hi,B as we,F as yt,c as ce,d as K,e as Rt,f as Qe,r as vs,g as As,h as Ms,i as Is,j as qi,k as _e,l as Oi,s as Fs,n as $i,o as Bs,q as Be,u as gt,x as Ki,y as Rs,U as Ot,R as Ws,z as ve,C as Oe,D as Qi,V as $e,P as je,E as Gi,G as $t,T as Kt,M as Qt,H as zs,J as Us,K as Vs,L as Ls,N as Ds,O as ji,Q as Xi,S as Ns,W as Yi,X as Ee,Y as Hs,Z as qs,_ as Xe,$ as Os,a0 as $s,a1 as Ks,a2 as Qs,a3 as Gs,a4 as Zi,a5 as ft,a6 as Ji,a7 as es,a8 as ts,a9 as is,aa as ss,ab as js,ac as rs,ad as as,ae as Xs,af as ns,ag as Ys,ah as ht,ai as Jt,aj as bt,ak as Zs,al as w,am as ei,an as Js,ao as er,ap as tr,aq as Me,ar as ir,as as ti,at as Je,au as sr,av as rr,aw as ar,ax as nr,ay as or,az as ii,aA as cr,aB as ur,aC as Y,aD as dr,aE as si,aF as os,aG as ri,aH as cs,aI as us,aJ as _t,aK as Wt,aL as ai,aM as ni,aN as lr,aO as mr,aP as fr,aQ as hr,aR as pr,aS as lt,aT as gr,aU as wr,aV as Tr,aW as oi,aX as yr,aY as br,aZ as _r,a_ as ci,a$ as ui,b0 as di,b1 as Ne,b2 as li,b3 as kr,b4 as Sr,b5 as zt,b6 as et,b7 as tt,b8 as it,b9 as Cr,ba as mt,bb as xr,bc as be,bd as Ut,be as Vt,bf as st,bg as Re,bh as Fe,bi as ke,bj as Ue,bk as Ye,bl as Pr,bm as Ve,bn as We,bo as kt,bp as Er,bq as mi,br as vr,bs as Ar,bt as Lt,bu as Dt,bv as Mr,bw as Ir,bx as Fr,by as Br,bz as ze,bA as rt,bB as fi,bC as Rr,bD as hi,bE as pi,bF as gi,bG as Wr,bH as zr,bI as Ur,bJ as Vr,bK as Lr,bL as Dr}from"./codec-CY6KnWXa.js";import{bM as $n,bN as Kn,bO as Qn,bP as Gn,bQ as jn,bR as Xn,bS as Yn,bT as Zn,bU as Jn,bV as eo,bW as to,bX as io,bY as so,bZ as ro,b_ as ao,b$ as no,c0 as oo,c1 as co,c2 as uo,c3 as lo,c4 as mo,c5 as fo,c6 as ho,c7 as po,c8 as go,c9 as wo,ca as To,cb as yo,cc as bo,cd as _o,ce as ko,cf as So,cg as Co,ch as xo,ci as Po,cj as Eo,ck as vo,cl as Ao,cm as Mo,cn as Io,co as Fo,cp as Bo,cq as Ro,cr as Wo,cs as zo,ct as Uo,cu as Vo,cv as Lo,cw as Do,cx as No,cy as Ho,cz as qo,cA as Oo,cB as $o,cC as Ko,cD as Qo,cE as Go,cF as jo,cG as Xo,cH as Yo,cI as Zo,cJ as Jo,cK as ec,cL as tc,cM as ic,cN as sc,cO as rc,cP as ac,cQ as nc,cR as oc,cS as cc,cT as uc,cU as dc,cV as lc,cW as mc,cX as fc,cY as hc,cZ as pc,c_ as gc,c$ as wc,d0 as Tc,d1 as yc,d2 as bc,d3 as _c,d4 as kc,d5 as Sc,d6 as Cc,d7 as xc,d8 as Pc}from"./codec-CY6KnWXa.js";import{n as wi}from"./index-_pkzoYYF.js";/*!
1
+ import{A as Ht,m as Ke,I as qt,v as le,p as Di,t as oe,b as Ni,a as m,w as Hi,B as we,F as yt,c as ce,d as K,e as Rt,f as Qe,r as vs,g as As,h as Ms,i as Is,j as qi,k as _e,l as Oi,s as Fs,n as $i,o as Bs,q as Be,u as gt,x as Ki,y as Rs,U as Ot,R as Ws,z as ve,C as Oe,D as Qi,V as $e,P as je,E as Gi,G as $t,T as Kt,M as Qt,H as zs,J as Us,K as Vs,L as Ls,N as Ds,O as ji,Q as Xi,S as Ns,W as Yi,X as Ee,Y as Hs,Z as qs,_ as Xe,$ as Os,a0 as $s,a1 as Ks,a2 as Qs,a3 as Gs,a4 as Zi,a5 as ft,a6 as Ji,a7 as es,a8 as ts,a9 as is,aa as ss,ab as js,ac as rs,ad as as,ae as Xs,af as ns,ag as Ys,ah as ht,ai as Jt,aj as bt,ak as Zs,al as w,am as ei,an as Js,ao as er,ap as tr,aq as Me,ar as ir,as as ti,at as Je,au as sr,av as rr,aw as ar,ax as nr,ay as or,az as ii,aA as cr,aB as ur,aC as Y,aD as dr,aE as si,aF as os,aG as ri,aH as cs,aI as us,aJ as _t,aK as Wt,aL as ai,aM as ni,aN as lr,aO as mr,aP as fr,aQ as hr,aR as pr,aS as lt,aT as gr,aU as wr,aV as Tr,aW as oi,aX as yr,aY as br,aZ as _r,a_ as ci,a$ as ui,b0 as di,b1 as Ne,b2 as li,b3 as kr,b4 as Sr,b5 as zt,b6 as et,b7 as tt,b8 as it,b9 as Cr,ba as mt,bb as xr,bc as be,bd as Ut,be as Vt,bf as st,bg as Re,bh as Fe,bi as ke,bj as Ue,bk as Ye,bl as Pr,bm as Ve,bn as We,bo as kt,bp as Er,bq as mi,br as vr,bs as Ar,bt as Lt,bu as Dt,bv as Mr,bw as Ir,bx as Fr,by as Br,bz as ze,bA as rt,bB as fi,bC as Rr,bD as hi,bE as pi,bF as gi,bG as Wr,bH as zr,bI as Ur,bJ as Vr,bK as Lr,bL as Dr}from"./codec-BPK_2CLL.js";import{bM as $n,bN as Kn,bO as Qn,bP as Gn,bQ as jn,bR as Xn,bS as Yn,bT as Zn,bU as Jn,bV as eo,bW as to,bX as io,bY as so,bZ as ro,b_ as ao,b$ as no,c0 as oo,c1 as co,c2 as uo,c3 as lo,c4 as mo,c5 as fo,c6 as ho,c7 as po,c8 as go,c9 as wo,ca as To,cb as yo,cc as bo,cd as _o,ce as ko,cf as So,cg as Co,ch as xo,ci as Po,cj as Eo,ck as vo,cl as Ao,cm as Mo,cn as Io,co as Fo,cp as Bo,cq as Ro,cr as Wo,cs as zo,ct as Uo,cu as Vo,cv as Lo,cw as Do,cx as No,cy as Ho,cz as qo,cA as Oo,cB as $o,cC as Ko,cD as Qo,cE as Go,cF as jo,cG as Xo,cH as Yo,cI as Zo,cJ as Jo,cK as ec,cL as tc,cM as ic,cN as sc,cO as rc,cP as ac,cQ as nc,cR as oc,cS as cc,cT as uc,cU as dc,cV as lc,cW as mc,cX as fc,cY as hc,cZ as pc,c_ as gc,c$ as wc,d0 as Tc,d1 as yc,d2 as bc,d3 as _c,d4 as kc,d5 as Sc,d6 as Cc,d7 as xc,d8 as Pc}from"./codec-BPK_2CLL.js";import{n as wi}from"./index-CdA00Ybn.js";/*!
2
2
  * Copyright (c) 2026-present, Vanilagy and contributors
3
3
  *
4
4
  * This Source Code Form is subject to the terms of the Mozilla Public
@@ -1 +1 @@
1
- import{l as V}from"./index-_pkzoYYF.js";import{bw as G,bN as K,cH as Q,bE as X}from"./codec-CY6KnWXa.js";const x=1e-5,k=1e-9,T=h=>!h.variableFrameRate&&(h.frameRate??0)>0;function Y(h,i){const{sourceLead:r,inputLead:l,timeResolution:w,frameRate:p=0}=i;if(!T(i))return Math.max(l,h-r+l)+k;const d=Math.max(0,Math.floor((h-r)*p+k)),f=l+d/p;return(w>0?Math.round(f*w)/w:f)+x}function J(h,i,r){const{frameRate:l=0,sourceLead:w,inputLead:p}=r,d=T(r)?Math.round((h-p)*l)/l+w:h-p+w,f=Math.min(i,d);return{timestamp:f,duration:Math.max(T(r)?1/l:0,i-f+x)}}const E=64*1024*1024,M=4,Z=.5,$=2e3;async function q(h,i){if(!h.transparent)return h.sink.getSample(i);let r=null;try{for await(const l of h.sink.samplesAtTimestamps([i]))r==null||r.close(),r=l;return r}catch(l){throw r==null||r.close(),l}}function ot(h){const i=new Map,r=new Map,l=new Map,w=new Map,p=new Map;let d=0,f=!1;const _=t=>{var o,n;let e=new URL(t,location.href).pathname;try{e=decodeURIComponent(e)}catch{}return(n=Object.entries(((o=h.contentWindow)==null?void 0:o.__HF_MEDIA_SOURCE_FACTS__)??{}).filter(([s])=>e.endsWith(s)).sort(([s],[a])=>a.length-s.length)[0])==null?void 0:n[1]},g=(t=E)=>{for(const[e,o]of p){if(d<=t)break;e.pins>0||(p.delete(e),o.cache.delete(e.timestamp),d-=e.bytes,e.image.close())}},v=async t=>{if(t.disposed)return;t.disposed=!0,clearTimeout(t.idleTimer),r.get(t.key)===t&&r.delete(t.key);const e=(async()=>{t.transparent&&await t.tail,t.cancelReads(),t.input.dispose(),await y(t).catch(()=>{});for(const o of t.cache.values())p.delete(o),d-=o.bytes,o.image.close();t.cache.clear(),t.canvas.width=t.canvas.height=0})();return t.transparent?new Promise((o,n)=>{const s=setTimeout(()=>{t.cancelReads(),o()},$);e.then(o,n).finally(()=>clearTimeout(s))}):e},P=t=>{clearTimeout(t.idleTimer),!(t.disposed||t.users>0||[...t.cache.values()].some(e=>e.pins>0))&&(t.idleTimer=setTimeout(()=>{t.users>0||[...t.cache.values()].some(e=>e.pins>0)||r.get(t.key)===t&&(i.delete(t.key),v(t))},1e4))},D=async t=>{const e=V("thumbnail"),o=new G({source:new Q(t,e),formats:K});l.set(o,e.cancelReads);try{const n=await o.getPrimaryVideoTrack();if(!n||f)throw new Error("Preview video unavailable");const[s,a,u,c,m,S,F,B,j]=await Promise.all([n.getDisplayWidth(),n.getDisplayHeight(),n.getFirstTimestamp(),n.getTimeResolution(),n.getSquarePixelWidth(),n.getSquarePixelHeight(),n.getRotation(),n.getFlip(),n.canBeTransparent()]),b=document.createElement("canvas");b.width=Math.max(1,Math.ceil(s));const z=F%180===0?m/S:S/m;return b.height=Math.max(1,Math.round(b.width/z)),{key:t,input:o,cancelReads:e.cancelReads,sink:new X(n),canvas:b,rotation:F,flip:B,width:s,height:a,lead:u,ticks:c,transparent:j,tail:Promise.resolve(),iterator:null,iteratorEnd:0,lastTime:-1/0,cache:new Map,users:0,disposed:!1}}catch(n){throw o.dispose(),e.cancelReads(),n}finally{l.delete(o)}},I=()=>{for(const[t]of i){if(i.size<M)break;const e=r.get(t);e&&e.users===0&&![...e.cache.values()].some(o=>o.pins>0)&&(i.delete(t),v(e))}if(i.size>=M)throw new Error("Preview decoder budget reached")},L=async t=>{const e=t;if((w.get(e)??0)>performance.now())throw new Error("Preview decoder cooling down");let o=i.get(e);o||(I(),o=D(t),i.set(e,o)),i.delete(e),i.set(e,o);let n;try{n=await o}catch(s){throw i.get(e)===o&&(i.delete(e),w.set(e,performance.now()+5e3)),s}if(f||n.disposed)throw new DOMException("Preview disposed","AbortError");return r.set(e,n),n.users++,clearTimeout(n.idleTimer),n},y=async t=>{const e=t.iterator;t.iterator=null,await(e==null?void 0:e.return())},R=(t,e)=>{if(e.throwIfAborted(),f||t.disposed)throw new Error("Preview disposed")},O=async(t,e,o)=>{for(t.iterator||(t.iteratorEnd=e+8,t.iterator=t.sink.samples(e,t.iteratorEnd));;){R(t,o);const n=await t.iterator.next();if(n.done)return null;const s=n.value;let a=!1;try{if(R(t,o),s.timestamp>e+1e-6)return null;if(a=s.timestamp+s.duration>e+1e-6,a)return s}finally{a||s.close()}}},A=(t,e)=>(e.pins++,p.delete(e),p.set(e,t),e),W=async(t,e,o,n,s)=>{const a=t.canvas.getContext("2d",{alpha:!0});if(!a)throw new Error("Preview canvas unavailable");a.clearRect(0,0,t.canvas.width,t.canvas.height),a.imageSmoothingQuality="high",e.drawWithFit(a,{fit:"fill",rotation:t.rotation,flip:t.flip});const u=await createImageBitmap(t.canvas);if(s.aborted||f||t.disposed)throw u.close(),s.throwIfAborted(),new Error("Preview disposed");const c={image:u,...J(e.timestamp,o,n),bytes:u.width*u.height*4,pins:1},m=t.cache.get(c.timestamp);if(m)return m.duration=Math.max(m.duration,c.duration),u.close(),A(t,m);if(g(E-c.bytes),d+c.bytes>E)throw u.close(),new Error("Preview frame budget reached");return t.cache.set(c.timestamp,c),p.set(c,t),d+=c.bytes,c},H=(t,e,o)=>!t.transparent&&!o.variableFrameRate&&(o.frameRate??0)>0&&e>t.lastTime+1e-6&&e-t.lastTime<=Z,N=async(t,e,o,n)=>{R(t,n);const s=[...t.cache.values()].find(m=>e>=m.timestamp-1e-6&&e<m.timestamp+m.duration-1e-6);if(s)return A(t,s);const a=Y(e,o),u=H(t,e,o);let c=null;try{if((!u||a>=t.iteratorEnd)&&await y(t),c=u?await O(t,a,n):null,c||(await y(t),c=await q(t,a)),!c)throw new Error("No preview frame at requested time");return R(t,n),t.lastTime=e,await W(t,c,e,o,n)}finally{c==null||c.close(),(n.aborted||f)&&await y(t).catch(()=>{})}},U=(t,e)=>{const o=_(t.source);return{frameRate:o==null?void 0:o.frameRate,variableFrameRate:o==null?void 0:o.variableFrameRate,sourceLead:e.lead,inputLead:e.lead,timeResolution:e.ticks}},C=async(t,e)=>{e.throwIfAborted();const o=t.source;if(!o)throw new Error("Preview source unavailable");const n=await L(o);try{const s=U(t,n),a=n.tail.then(()=>N(n,t.time,s,e));n.tail=a.then(()=>{},()=>{});const u=await a;let c=!1;return g(),{source:u.image,timestamp:u.timestamp,duration:u.duration,width:n.width,height:n.height,release(){c||(c=!0,u.pins--,g(),P(n))}}}finally{n.users--,P(n)}};return{async decode(t,e){if(f)throw new DOMException("Preview disposed","AbortError");if(new Set(t.map(({source:a})=>a)).size>M)throw new Error("Preview decoder budget reached");const o=await Promise.allSettled(t.map(a=>C(a,e))),n=o.find(a=>a.status==="rejected"),s=o.flatMap(a=>a.status==="fulfilled"?[a.value]:[]);if(n||f||e.aborted){for(const a of s)a.release();throw n?n.reason:new DOMException("Preview cancelled","AbortError")}return s},async suspend(){const t=[...i.values()].map(e=>e.then(v).catch(()=>{}));i.clear();for(const[e,o]of l)o(),e.dispose();await Promise.all(t)},dispose(){if(!f){f=!0;for(const[t,e]of l)e(),t.dispose();for(const t of i.values())t.then(v).catch(()=>{});i.clear(),w.clear()}}}}export{ot as createPausedVideoDecoder};
1
+ import{l as V}from"./index-CdA00Ybn.js";import{bw as G,bN as K,cH as Q,bE as X}from"./codec-BPK_2CLL.js";const x=1e-5,k=1e-9,T=h=>!h.variableFrameRate&&(h.frameRate??0)>0;function Y(h,i){const{sourceLead:r,inputLead:l,timeResolution:w,frameRate:p=0}=i;if(!T(i))return Math.max(l,h-r+l)+k;const d=Math.max(0,Math.floor((h-r)*p+k)),f=l+d/p;return(w>0?Math.round(f*w)/w:f)+x}function J(h,i,r){const{frameRate:l=0,sourceLead:w,inputLead:p}=r,d=T(r)?Math.round((h-p)*l)/l+w:h-p+w,f=Math.min(i,d);return{timestamp:f,duration:Math.max(T(r)?1/l:0,i-f+x)}}const E=64*1024*1024,M=4,Z=.5,$=2e3;async function q(h,i){if(!h.transparent)return h.sink.getSample(i);let r=null;try{for await(const l of h.sink.samplesAtTimestamps([i]))r==null||r.close(),r=l;return r}catch(l){throw r==null||r.close(),l}}function ot(h){const i=new Map,r=new Map,l=new Map,w=new Map,p=new Map;let d=0,f=!1;const _=t=>{var o,n;let e=new URL(t,location.href).pathname;try{e=decodeURIComponent(e)}catch{}return(n=Object.entries(((o=h.contentWindow)==null?void 0:o.__HF_MEDIA_SOURCE_FACTS__)??{}).filter(([s])=>e.endsWith(s)).sort(([s],[a])=>a.length-s.length)[0])==null?void 0:n[1]},g=(t=E)=>{for(const[e,o]of p){if(d<=t)break;e.pins>0||(p.delete(e),o.cache.delete(e.timestamp),d-=e.bytes,e.image.close())}},v=async t=>{if(t.disposed)return;t.disposed=!0,clearTimeout(t.idleTimer),r.get(t.key)===t&&r.delete(t.key);const e=(async()=>{t.transparent&&await t.tail,t.cancelReads(),t.input.dispose(),await y(t).catch(()=>{});for(const o of t.cache.values())p.delete(o),d-=o.bytes,o.image.close();t.cache.clear(),t.canvas.width=t.canvas.height=0})();return t.transparent?new Promise((o,n)=>{const s=setTimeout(()=>{t.cancelReads(),o()},$);e.then(o,n).finally(()=>clearTimeout(s))}):e},P=t=>{clearTimeout(t.idleTimer),!(t.disposed||t.users>0||[...t.cache.values()].some(e=>e.pins>0))&&(t.idleTimer=setTimeout(()=>{t.users>0||[...t.cache.values()].some(e=>e.pins>0)||r.get(t.key)===t&&(i.delete(t.key),v(t))},1e4))},D=async t=>{const e=V("thumbnail"),o=new G({source:new Q(t,e),formats:K});l.set(o,e.cancelReads);try{const n=await o.getPrimaryVideoTrack();if(!n||f)throw new Error("Preview video unavailable");const[s,a,u,c,m,S,F,B,j]=await Promise.all([n.getDisplayWidth(),n.getDisplayHeight(),n.getFirstTimestamp(),n.getTimeResolution(),n.getSquarePixelWidth(),n.getSquarePixelHeight(),n.getRotation(),n.getFlip(),n.canBeTransparent()]),b=document.createElement("canvas");b.width=Math.max(1,Math.ceil(s));const z=F%180===0?m/S:S/m;return b.height=Math.max(1,Math.round(b.width/z)),{key:t,input:o,cancelReads:e.cancelReads,sink:new X(n),canvas:b,rotation:F,flip:B,width:s,height:a,lead:u,ticks:c,transparent:j,tail:Promise.resolve(),iterator:null,iteratorEnd:0,lastTime:-1/0,cache:new Map,users:0,disposed:!1}}catch(n){throw o.dispose(),e.cancelReads(),n}finally{l.delete(o)}},I=()=>{for(const[t]of i){if(i.size<M)break;const e=r.get(t);e&&e.users===0&&![...e.cache.values()].some(o=>o.pins>0)&&(i.delete(t),v(e))}if(i.size>=M)throw new Error("Preview decoder budget reached")},L=async t=>{const e=t;if((w.get(e)??0)>performance.now())throw new Error("Preview decoder cooling down");let o=i.get(e);o||(I(),o=D(t),i.set(e,o)),i.delete(e),i.set(e,o);let n;try{n=await o}catch(s){throw i.get(e)===o&&(i.delete(e),w.set(e,performance.now()+5e3)),s}if(f||n.disposed)throw new DOMException("Preview disposed","AbortError");return r.set(e,n),n.users++,clearTimeout(n.idleTimer),n},y=async t=>{const e=t.iterator;t.iterator=null,await(e==null?void 0:e.return())},R=(t,e)=>{if(e.throwIfAborted(),f||t.disposed)throw new Error("Preview disposed")},O=async(t,e,o)=>{for(t.iterator||(t.iteratorEnd=e+8,t.iterator=t.sink.samples(e,t.iteratorEnd));;){R(t,o);const n=await t.iterator.next();if(n.done)return null;const s=n.value;let a=!1;try{if(R(t,o),s.timestamp>e+1e-6)return null;if(a=s.timestamp+s.duration>e+1e-6,a)return s}finally{a||s.close()}}},A=(t,e)=>(e.pins++,p.delete(e),p.set(e,t),e),W=async(t,e,o,n,s)=>{const a=t.canvas.getContext("2d",{alpha:!0});if(!a)throw new Error("Preview canvas unavailable");a.clearRect(0,0,t.canvas.width,t.canvas.height),a.imageSmoothingQuality="high",e.drawWithFit(a,{fit:"fill",rotation:t.rotation,flip:t.flip});const u=await createImageBitmap(t.canvas);if(s.aborted||f||t.disposed)throw u.close(),s.throwIfAborted(),new Error("Preview disposed");const c={image:u,...J(e.timestamp,o,n),bytes:u.width*u.height*4,pins:1},m=t.cache.get(c.timestamp);if(m)return m.duration=Math.max(m.duration,c.duration),u.close(),A(t,m);if(g(E-c.bytes),d+c.bytes>E)throw u.close(),new Error("Preview frame budget reached");return t.cache.set(c.timestamp,c),p.set(c,t),d+=c.bytes,c},H=(t,e,o)=>!t.transparent&&!o.variableFrameRate&&(o.frameRate??0)>0&&e>t.lastTime+1e-6&&e-t.lastTime<=Z,N=async(t,e,o,n)=>{R(t,n);const s=[...t.cache.values()].find(m=>e>=m.timestamp-1e-6&&e<m.timestamp+m.duration-1e-6);if(s)return A(t,s);const a=Y(e,o),u=H(t,e,o);let c=null;try{if((!u||a>=t.iteratorEnd)&&await y(t),c=u?await O(t,a,n):null,c||(await y(t),c=await q(t,a)),!c)throw new Error("No preview frame at requested time");return R(t,n),t.lastTime=e,await W(t,c,e,o,n)}finally{c==null||c.close(),(n.aborted||f)&&await y(t).catch(()=>{})}},U=(t,e)=>{const o=_(t.source);return{frameRate:o==null?void 0:o.frameRate,variableFrameRate:o==null?void 0:o.variableFrameRate,sourceLead:e.lead,inputLead:e.lead,timeResolution:e.ticks}},C=async(t,e)=>{e.throwIfAborted();const o=t.source;if(!o)throw new Error("Preview source unavailable");const n=await L(o);try{const s=U(t,n),a=n.tail.then(()=>N(n,t.time,s,e));n.tail=a.then(()=>{},()=>{});const u=await a;let c=!1;return g(),{source:u.image,timestamp:u.timestamp,duration:u.duration,width:n.width,height:n.height,release(){c||(c=!0,u.pins--,g(),P(n))}}}finally{n.users--,P(n)}};return{async decode(t,e){if(f)throw new DOMException("Preview disposed","AbortError");if(new Set(t.map(({source:a})=>a)).size>M)throw new Error("Preview decoder budget reached");const o=await Promise.allSettled(t.map(a=>C(a,e))),n=o.find(a=>a.status==="rejected"),s=o.flatMap(a=>a.status==="fulfilled"?[a.value]:[]);if(n||f||e.aborted){for(const a of s)a.release();throw n?n.reason:new DOMException("Preview cancelled","AbortError")}return s},async suspend(){const t=[...i.values()].map(e=>e.then(v).catch(()=>{}));i.clear();for(const[e,o]of l)o(),e.dispose();await Promise.all(t)},dispose(){if(!f){f=!0;for(const[t,e]of l)e(),t.dispose();for(const t of i.values())t.then(v).catch(()=>{});i.clear(),w.clear()}}}}export{ot as createPausedVideoDecoder};
@@ -47,6 +47,12 @@ function getSourceScopedSelectorIndex(doc, el, selector, sourceFile, resolveSour
47
47
  // src/components/editor/domEditingDom.ts
48
48
  import { getLogicalOpacity } from "@hyperframes/core/studio-preview-mark";
49
49
  import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading";
50
+ import {
51
+ buildStableSelector,
52
+ escapeCssString,
53
+ getPreferredClassSelector,
54
+ readElementSource
55
+ } from "@hyperframes/core/runtime/editing-port";
50
56
 
51
57
  // src/components/editor/domEditingTypes.ts
52
58
  var CURATED_STYLE_PROPERTIES = [
@@ -179,16 +185,13 @@ function setCompositionSourceMap(map) {
179
185
  function getCompositionSourceMapRevision() {
180
186
  return compositionSourceMapRevision;
181
187
  }
182
- function sourceFromCompositionId(ownerRoot) {
183
- if (!ownerRoot || compositionSourceMap.size === 0) return void 0;
184
- const authored = ownerRoot.getAttribute("data-hf-original-composition-id");
185
- const current = ownerRoot.getAttribute("data-composition-id");
186
- return (authored ? compositionSourceMap.get(authored) : void 0) ?? (current ? compositionSourceMap.get(current) : void 0);
188
+ function resolveElementSourceFile(source, activeCompositionPath) {
189
+ const { file, compositionId, originalCompositionId } = source;
190
+ const mapped = compositionSourceMap.size ? (originalCompositionId ? compositionSourceMap.get(originalCompositionId) : void 0) ?? (compositionId ? compositionSourceMap.get(compositionId) : void 0) : void 0;
191
+ return file ?? mapped ?? activeCompositionPath ?? "index.html";
187
192
  }
188
193
  function getSourceFileForElement(el, activeCompositionPath) {
189
- const sourceHost = findClosestByAttribute(el, ["data-composition-file", "data-composition-src"]);
190
- const ownerRoot = findClosestByAttribute(el, ["data-composition-id"]);
191
- const sourceFile = sourceHost?.getAttribute("data-composition-file") ?? sourceHost?.getAttribute("data-composition-src") ?? ownerRoot?.getAttribute("data-composition-file") ?? ownerRoot?.getAttribute("data-composition-src") ?? sourceFromCompositionId(ownerRoot) ?? activeCompositionPath ?? "index.html";
194
+ const sourceFile = resolveElementSourceFile(readElementSource(el), activeCompositionPath);
192
195
  return {
193
196
  sourceFile,
194
197
  compositionPath: sourceFile
@@ -212,39 +215,6 @@ function normalizeTimelineCompositionSource(value) {
212
215
  }
213
216
  return trimmed;
214
217
  }
215
- function escapeCssIdentifier(value) {
216
- const css = globalThis.CSS;
217
- if (typeof css?.escape === "function") return css.escape(value);
218
- if (value === "-") return "\\-";
219
- let escaped = "";
220
- for (let index = 0; index < value.length; index += 1) {
221
- const char = value[index] ?? "";
222
- const code = char.charCodeAt(0);
223
- if (code === 0) {
224
- escaped += "\uFFFD";
225
- continue;
226
- }
227
- const isDigit = code >= 48 && code <= 57;
228
- const isUpperAlpha = code >= 65 && code <= 90;
229
- const isLowerAlpha = code >= 97 && code <= 122;
230
- const isControl = code >= 1 && code <= 31 || code === 127;
231
- const isLeadingDigit = index === 0 && isDigit;
232
- const isSecondDigitAfterDash = index === 1 && value.startsWith("-") && isDigit;
233
- if (isControl || isLeadingDigit || isSecondDigitAfterDash) {
234
- escaped += `\\${code.toString(16)} `;
235
- continue;
236
- }
237
- if (isUpperAlpha || isLowerAlpha || isDigit || char === "-" || char === "_" || code >= 128) {
238
- escaped += char;
239
- continue;
240
- }
241
- escaped += `\\${char}`;
242
- }
243
- return escaped;
244
- }
245
- function escapeCssString(value) {
246
- return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\a ").replace(/\r/g, "\\d ").replace(/\f/g, "\\c ");
247
- }
248
218
  function querySelectorAllSafely(doc, selector) {
249
219
  try {
250
220
  return Array.from(doc.querySelectorAll(selector));
@@ -255,20 +225,6 @@ function querySelectorAllSafely(doc, selector) {
255
225
  function humanizeIdentifier(value) {
256
226
  return value.replace(/\.html$/i, "").replace(/^compositions\//i, "").split("/").at(-1)?.replace(/[-_]+/g, " ").replace(/\b\w/g, (char) => char.toUpperCase()) ?? value;
257
227
  }
258
- function buildStableSelector(el) {
259
- if (el.id) return `#${escapeCssIdentifier(el.id)}`;
260
- const compositionId = el.getAttribute("data-composition-id");
261
- if (compositionId) return `[data-composition-id="${escapeCssString(compositionId)}"]`;
262
- const group = el.getAttribute("data-hf-group");
263
- if (group) return `[data-hf-group="${escapeCssString(group)}"]`;
264
- return getPreferredClassSelector(el);
265
- }
266
- function getPreferredClassSelector(el) {
267
- const classes = Array.from(el.classList).map((value) => value.trim()).filter(Boolean);
268
- if (classes.length === 0) return void 0;
269
- const preferred = classes.find((value) => value !== "clip" && !value.startsWith("__hf-")) ?? classes[0];
270
- return preferred ? `.${escapeCssIdentifier(preferred)}` : void 0;
271
- }
272
228
  function buildElementLabel(el) {
273
229
  const compositionId = el.getAttribute("data-hf-original-composition-id") ?? el.getAttribute("data-composition-id");
274
230
  if (compositionId && compositionId !== "main") {
@@ -1144,6 +1100,8 @@ export {
1144
1100
  hsvToRgb,
1145
1101
  withSelectorIndexPass,
1146
1102
  getLogicalOpacity,
1103
+ buildStableSelector,
1104
+ escapeCssString,
1147
1105
  isHtmlElement,
1148
1106
  isEditableTextLeaf,
1149
1107
  isElementVisibleThroughAncestors,
@@ -1155,9 +1113,7 @@ export {
1155
1113
  getCompositionSourceMapRevision,
1156
1114
  getSourceFileForElement,
1157
1115
  normalizeTimelineCompositionSource,
1158
- escapeCssString,
1159
1116
  querySelectorAllSafely,
1160
- buildStableSelector,
1161
1117
  buildElementLabel,
1162
1118
  getSelectorIndex,
1163
1119
  parsePx,
@@ -5,7 +5,7 @@ import {
5
5
  buildProjectApiPath,
6
6
  splitTimelineElementKey,
7
7
  studioApiFetch
8
- } from "./chunk-44VRMER6.js";
8
+ } from "./chunk-AV2PV7NE.js";
9
9
 
10
10
  // src/player/lib/time.ts
11
11
  var STUDIO_PREVIEW_FPS = 30;
@@ -1733,8 +1733,7 @@ function setFrameLoopStart(iframe, seconds) {
1733
1733
  });
1734
1734
  }
1735
1735
  var AGENT_PROBE_MS = 1e3;
1736
- async function previewSeekPainted(iframe, timeoutMs) {
1737
- const client = previewEditingClient(iframe);
1736
+ async function agentConnected(client) {
1738
1737
  let timer;
1739
1738
  const probe = new Promise(
1740
1739
  (resolve) => timer = setTimeout(resolve, AGENT_PROBE_MS, false)
@@ -1747,11 +1746,18 @@ async function previewSeekPainted(iframe, timeoutMs) {
1747
1746
  probe
1748
1747
  ]);
1749
1748
  clearTimeout(timer);
1750
- if (connected) await client.request("wait-for-seek", {}, { timeoutMs }).catch(() => {
1751
- });
1749
+ return connected;
1750
+ }
1751
+ async function previewRequest(iframe, kind, params, timeoutMs) {
1752
+ const client = previewEditingClient(iframe);
1753
+ if (!await agentConnected(client)) return null;
1754
+ return client.request(kind, params, { timeoutMs }).catch(() => null);
1755
+ }
1756
+ async function previewSeekPainted(iframe, timeoutMs) {
1757
+ await previewRequest(iframe, "wait-for-seek", {}, timeoutMs);
1752
1758
  }
1753
1759
  async function previewClipManifest(iframe) {
1754
- const snapshot = await previewEditingClient(iframe).request("runtime-snapshot", {});
1760
+ const snapshot = await previewRequest(iframe, "runtime-snapshot", {});
1755
1761
  const manifest = snapshot?.clipManifest;
1756
1762
  if (typeof manifest !== "object" || manifest === null) return null;
1757
1763
  const { clips, durationInFrames } = manifest;
@@ -1760,7 +1766,7 @@ async function previewClipManifest(iframe) {
1760
1766
  return manifest;
1761
1767
  }
1762
1768
  async function previewComputedStyles(iframe, selector, properties) {
1763
- const reply = await previewEditingClient(iframe).request("computed-styles", { selector, properties }).catch(() => null);
1769
+ const reply = await previewRequest(iframe, "computed-styles", { selector, properties });
1764
1770
  const styles = reply?.styles;
1765
1771
  if (typeof styles !== "object" || styles === null) return null;
1766
1772
  const read = {};
@@ -19,7 +19,7 @@ import {
19
19
  querySelectorAllSafely,
20
20
  studioApiFetch,
21
21
  withSelectorIndexPass
22
- } from "./chunk-44VRMER6.js";
22
+ } from "./chunk-AV2PV7NE.js";
23
23
 
24
24
  // src/components/editor/domEditingLayers.ts
25
25
  import { isClipHiddenByRuntime, PREVIEW_ONLY_ATTRS } from "@hyperframes/core/studio-preview-mark";
@@ -19,8 +19,8 @@ import {
19
19
  resolveDomEditCapabilities,
20
20
  resolveDomEditSelection,
21
21
  serializeDomEditTextFields
22
- } from "./chunk-ATDO3YLX.js";
23
- import "./chunk-44VRMER6.js";
22
+ } from "./chunk-VZ5MD32A.js";
23
+ import "./chunk-AV2PV7NE.js";
24
24
  import "./chunk-MLKGABMK.js";
25
25
  export {
26
26
  buildDefaultDomEditTextField,
package/dist/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  document.documentElement.dataset.theme = "paper";
15
15
  }
16
16
  </script>
17
- <script type="module" crossorigin src="/assets/index-_pkzoYYF.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-CdA00Ybn.js"></script>
18
18
  <link rel="stylesheet" crossorigin href="/assets/index-4VGEAZyf.css">
19
19
  </head>
20
20
  <body>
package/dist/index.js CHANGED
@@ -87,7 +87,7 @@ import {
87
87
  whileScriptWrites,
88
88
  writeStudioUiPreferences,
89
89
  zoomToSelectedClips
90
- } from "./chunk-NBULUIWH.js";
90
+ } from "./chunk-KF6YVXJP.js";
91
91
  import {
92
92
  Button,
93
93
  ContextMenu,
@@ -153,7 +153,7 @@ import {
153
153
  resolveAllVisualDomEditTargets,
154
154
  resolveDomEditSelection,
155
155
  serializeDomEditTextFields
156
- } from "./chunk-ATDO3YLX.js";
156
+ } from "./chunk-VZ5MD32A.js";
157
157
  import {
158
158
  LAYER_REVEAL_PRIOR_POSITION_ATTR,
159
159
  LAYER_REVEAL_PRIOR_Z_ATTR,
@@ -222,7 +222,7 @@ import {
222
222
  toHexColor,
223
223
  withSelectorIndexPass,
224
224
  wrapTimeline
225
- } from "./chunk-44VRMER6.js";
225
+ } from "./chunk-AV2PV7NE.js";
226
226
  import {
227
227
  MediaFetchError,
228
228
  mediaUrlSourceOptions,
@@ -39145,7 +39145,7 @@ function OffCanvasIndicators({
39145
39145
  const selectOffCanvas = async () => {
39146
39146
  const el = elements.current.get(r.key);
39147
39147
  if (!el) return;
39148
- const { resolveDomEditSelection: resolveDomEditSelection2 } = await import("./domEditingLayers-FRVHP6IB.js");
39148
+ const { resolveDomEditSelection: resolveDomEditSelection2 } = await import("./domEditingLayers-4KRREI5C.js");
39149
39149
  const acp = activeCompositionPathRef.current ?? "index.html";
39150
39150
  const sel = await resolveDomEditSelection2(el, {
39151
39151
  activeCompositionPath: acp,
package/dist/player.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Player
3
- } from "./chunk-NBULUIWH.js";
3
+ } from "./chunk-KF6YVXJP.js";
4
4
  import "./chunk-52AJB4PN.js";
5
- import "./chunk-44VRMER6.js";
5
+ import "./chunk-AV2PV7NE.js";
6
6
  import "./chunk-MLKGABMK.js";
7
7
  export {
8
8
  Player
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.9.39",
3
+ "version": "0.9.40",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,12 +64,12 @@
64
64
  "dockview-react": "8.3.1",
65
65
  "gsap": "^3.13.0",
66
66
  "mediabunny": "^1.65.2",
67
- "@hyperframes/parsers": "0.9.39",
68
- "@hyperframes/sdk": "0.9.39",
69
- "@hyperframes/player": "0.9.39",
70
- "@hyperframes/shader-transitions": "0.9.39",
71
- "@hyperframes/studio-server": "0.9.39",
72
- "@hyperframes/core": "0.9.39"
67
+ "@hyperframes/parsers": "0.9.40",
68
+ "@hyperframes/player": "0.9.40",
69
+ "@hyperframes/sdk": "0.9.40",
70
+ "@hyperframes/core": "0.9.40",
71
+ "@hyperframes/shader-transitions": "0.9.40",
72
+ "@hyperframes/studio-server": "0.9.40"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@tailwindcss/vite": "^4.3.3",
@@ -86,7 +86,7 @@
86
86
  "vite": "^6.4.2",
87
87
  "vitest": "^4.1.11",
88
88
  "zustand": "^5.0.0",
89
- "@hyperframes/producer": "0.9.39"
89
+ "@hyperframes/producer": "0.9.40"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "react": "19",
@@ -5,6 +5,13 @@
5
5
  */
6
6
  import { getLogicalOpacity } from "@hyperframes/core/studio-preview-mark";
7
7
  import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "@hyperframes/core/color-grading";
8
+ import {
9
+ buildStableSelector,
10
+ escapeCssString,
11
+ getPreferredClassSelector,
12
+ readElementSource,
13
+ type EditingElementSource,
14
+ } from "@hyperframes/core/runtime/editing-port";
8
15
  import { getSourceScopedSelectorIndex } from "../../utils/sourceScopedSelectorIndex";
9
16
  import { CURATED_STYLE_PROPERTIES } from "./domEditingTypes";
10
17
 
@@ -36,6 +43,8 @@ export function isEditableTextLeaf(el: HTMLElement): boolean {
36
43
  }
37
44
 
38
45
  export { getLogicalOpacity };
46
+ // One addressing rule for Studio and the runtime that describes elements to it.
47
+ export { buildStableSelector, escapeCssString };
39
48
 
40
49
  /** Does this node render AT ALL, ignoring what it inherits? Sole owner of the
41
50
  * rule; the walk below only decides which nodes to ask it about. */
@@ -171,33 +180,24 @@ export function getCompositionSourceMapRevision(): number {
171
180
  return compositionSourceMapRevision;
172
181
  }
173
182
 
174
- function sourceFromCompositionId(ownerRoot: HTMLElement | null): string | undefined {
175
- if (!ownerRoot || compositionSourceMap.size === 0) return undefined;
176
- // The runtime may rename the mounted id to a runtime-unique one, preserving the
177
- // authored id on `data-hf-original-composition-id` — prefer that, then the current id.
178
- const authored = ownerRoot.getAttribute("data-hf-original-composition-id");
179
- const current = ownerRoot.getAttribute("data-composition-id");
180
- return (
181
- (authored ? compositionSourceMap.get(authored) : undefined) ??
182
- (current ? compositionSourceMap.get(current) : undefined)
183
- );
183
+ /** The source file `source` names (see `EditingElementSource`), with this project's composition map. */
184
+ export function resolveElementSourceFile(
185
+ source: EditingElementSource,
186
+ activeCompositionPath: string | null,
187
+ ): string {
188
+ const { file, compositionId, originalCompositionId } = source;
189
+ const mapped = compositionSourceMap.size
190
+ ? ((originalCompositionId ? compositionSourceMap.get(originalCompositionId) : undefined) ??
191
+ (compositionId ? compositionSourceMap.get(compositionId) : undefined))
192
+ : undefined;
193
+ return file ?? mapped ?? activeCompositionPath ?? "index.html";
184
194
  }
185
195
 
186
196
  export function getSourceFileForElement(
187
197
  el: HTMLElement,
188
198
  activeCompositionPath: string | null,
189
199
  ): { sourceFile: string; compositionPath: string } {
190
- const sourceHost = findClosestByAttribute(el, ["data-composition-file", "data-composition-src"]);
191
- const ownerRoot = findClosestByAttribute(el, ["data-composition-id"]);
192
- const sourceFile =
193
- sourceHost?.getAttribute("data-composition-file") ??
194
- sourceHost?.getAttribute("data-composition-src") ??
195
- ownerRoot?.getAttribute("data-composition-file") ??
196
- ownerRoot?.getAttribute("data-composition-src") ??
197
- sourceFromCompositionId(ownerRoot) ??
198
- activeCompositionPath ??
199
- "index.html";
200
-
200
+ const sourceFile = resolveElementSourceFile(readElementSource(el), activeCompositionPath);
201
201
  return {
202
202
  sourceFile,
203
203
  compositionPath: sourceFile,
@@ -228,49 +228,6 @@ export function normalizeTimelineCompositionSource(value: string | undefined): s
228
228
 
229
229
  // ─── CSS escaping ─────────────────────────────────────────────────────────────
230
230
 
231
- function escapeCssIdentifier(value: string): string {
232
- const css = globalThis.CSS as { escape?: (input: string) => string } | undefined;
233
- if (typeof css?.escape === "function") return css.escape(value);
234
-
235
- if (value === "-") return "\\-";
236
-
237
- let escaped = "";
238
- for (let index = 0; index < value.length; index += 1) {
239
- const char = value[index] ?? "";
240
- const code = char.charCodeAt(0);
241
- if (code === 0) {
242
- escaped += "�";
243
- continue;
244
- }
245
-
246
- const isDigit = code >= 48 && code <= 57;
247
- const isUpperAlpha = code >= 65 && code <= 90;
248
- const isLowerAlpha = code >= 97 && code <= 122;
249
- const isControl = (code >= 1 && code <= 31) || code === 127;
250
- const isLeadingDigit = index === 0 && isDigit;
251
- const isSecondDigitAfterDash = index === 1 && value.startsWith("-") && isDigit;
252
- if (isControl || isLeadingDigit || isSecondDigitAfterDash) {
253
- escaped += `\\${code.toString(16)} `;
254
- continue;
255
- }
256
- if (isUpperAlpha || isLowerAlpha || isDigit || char === "-" || char === "_" || code >= 128) {
257
- escaped += char;
258
- continue;
259
- }
260
- escaped += `\\${char}`;
261
- }
262
- return escaped;
263
- }
264
-
265
- export function escapeCssString(value: string): string {
266
- return value
267
- .replace(/\\/g, "\\\\")
268
- .replace(/"/g, '\\"')
269
- .replace(/\n/g, "\\a ")
270
- .replace(/\r/g, "\\d ")
271
- .replace(/\f/g, "\\c ");
272
- }
273
-
274
231
  export function querySelectorAllSafely(doc: Document, selector: string): Element[] {
275
232
  try {
276
233
  return Array.from(doc.querySelectorAll(selector));
@@ -293,31 +250,6 @@ function humanizeIdentifier(value: string): string {
293
250
 
294
251
  // ─── CSS selector building ────────────────────────────────────────────────────
295
252
 
296
- export function buildStableSelector(el: HTMLElement): string | undefined {
297
- if (el.id) return `#${escapeCssIdentifier(el.id)}`;
298
-
299
- const compositionId = el.getAttribute("data-composition-id");
300
- if (compositionId) return `[data-composition-id="${escapeCssString(compositionId)}"]`;
301
-
302
- // Group wrappers carry no id/class; their data-hf-group value is the unique,
303
- // stable handle the source mutations write — use it so the wrapper is
304
- // selectable, patchable (move/scale), and addressable for ungroup.
305
- const group = el.getAttribute("data-hf-group");
306
- if (group) return `[data-hf-group="${escapeCssString(group)}"]`;
307
-
308
- return getPreferredClassSelector(el);
309
- }
310
-
311
- function getPreferredClassSelector(el: HTMLElement): string | undefined {
312
- const classes = Array.from(el.classList)
313
- .map((value) => value.trim())
314
- .filter(Boolean);
315
- if (classes.length === 0) return undefined;
316
- const preferred =
317
- classes.find((value) => value !== "clip" && !value.startsWith("__hf-")) ?? classes[0];
318
- return preferred ? `.${escapeCssIdentifier(preferred)}` : undefined;
319
- }
320
-
321
253
  // fallow-ignore-next-line complexity
322
254
  export function buildElementLabel(el: HTMLElement): string {
323
255
  const compositionId =
@@ -1,7 +1,10 @@
1
1
  // Runtime-state reads over a preview frame's editing port; an opaque frame's window is out of reach.
2
2
  import {
3
3
  createEditingPortClient,
4
+ type EditingParams,
4
5
  type EditingPortClient,
6
+ type EditingRequestKind,
7
+ type EditingResult,
5
8
  } from "@hyperframes/core/runtime/editing-port";
6
9
  import type { ClipManifest, IframeWindow } from "./playbackTypes";
7
10
 
@@ -51,9 +54,7 @@ export function setFrameLoopStart(iframe: HTMLIFrameElement, seconds: number | n
51
54
 
52
55
  export const AGENT_PROBE_MS = 1_000;
53
56
 
54
- /** Gives up after AGENT_PROBE_MS with no port: a runtime without the editing agent never answers. */
55
- export async function previewSeekPainted(iframe: HTMLIFrameElement, timeoutMs?: number) {
56
- const client = previewEditingClient(iframe);
57
+ async function agentConnected(client: EditingPortClient): Promise<boolean> {
57
58
  let timer: ReturnType<typeof setTimeout> | undefined;
58
59
  const probe = new Promise<boolean>(
59
60
  (resolve) => (timer = setTimeout(resolve, AGENT_PROBE_MS, false)),
@@ -66,12 +67,28 @@ export async function previewSeekPainted(iframe: HTMLIFrameElement, timeoutMs?:
66
67
  probe,
67
68
  ]);
68
69
  clearTimeout(timer);
69
- if (connected) await client.request("wait-for-seek", {}, { timeoutMs }).catch(() => {});
70
+ return connected;
71
+ }
72
+
73
+ /** Null when no port comes within AGENT_PROBE_MS (a runtime without the editing agent), or on error. */
74
+ export async function previewRequest<K extends EditingRequestKind>(
75
+ iframe: HTMLIFrameElement,
76
+ kind: K,
77
+ params: EditingParams<K>,
78
+ timeoutMs?: number,
79
+ ): Promise<EditingResult<K> | null> {
80
+ const client = previewEditingClient(iframe);
81
+ if (!(await agentConnected(client))) return null;
82
+ return client.request(kind, params, { timeoutMs }).catch(() => null);
83
+ }
84
+
85
+ export async function previewSeekPainted(iframe: HTMLIFrameElement, timeoutMs?: number) {
86
+ await previewRequest(iframe, "wait-for-seek", {}, timeoutMs);
70
87
  }
71
88
 
72
89
  /** The reply is frame data, so its shape is checked. */
73
90
  export async function previewClipManifest(iframe: HTMLIFrameElement): Promise<ClipManifest | null> {
74
- const snapshot = await previewEditingClient(iframe).request("runtime-snapshot", {});
91
+ const snapshot = await previewRequest(iframe, "runtime-snapshot", {});
75
92
  const manifest: unknown = snapshot?.clipManifest;
76
93
  if (typeof manifest !== "object" || manifest === null) return null;
77
94
  const { clips, durationInFrames } = manifest as Partial<ClipManifest>;
@@ -86,9 +103,7 @@ export async function previewComputedStyles(
86
103
  selector: string,
87
104
  properties: string[],
88
105
  ): Promise<Record<string, string> | null> {
89
- const reply = await previewEditingClient(iframe)
90
- .request("computed-styles", { selector, properties })
91
- .catch(() => null);
106
+ const reply = await previewRequest(iframe, "computed-styles", { selector, properties });
92
107
  const styles: unknown = reply?.styles;
93
108
  if (typeof styles !== "object" || styles === null) return null;
94
109
  const read: Record<string, string> = {};