hyperframes 0.6.33 → 0.6.34

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.
package/dist/cli.js CHANGED
@@ -54,7 +54,7 @@ var VERSION;
54
54
  var init_version = __esm({
55
55
  "src/version.ts"() {
56
56
  "use strict";
57
- VERSION = true ? "0.6.33" : "0.0.0-dev";
57
+ VERSION = true ? "0.6.34" : "0.0.0-dev";
58
58
  }
59
59
  });
60
60
 
@@ -32572,7 +32572,7 @@ function injectInterceptor(html, runtimeMode = "inline") {
32572
32572
  tag = `<script ${RUNTIME_BOOTSTRAP_ATTR}="1">${inlinedRuntime}</script>`;
32573
32573
  }
32574
32574
  if (sanitized.includes("</head>")) {
32575
- return sanitized.replace("</head>", `${tag}
32575
+ return sanitized.replace("</head>", () => `${tag}
32576
32576
  </head>`);
32577
32577
  }
32578
32578
  const htmlOpenMatch = sanitized.match(/<html\b[^>]*>/i);
@@ -82,7 +82,7 @@ ${h.join(`
82
82
  </body>
83
83
  </html>
84
84
  `);const ce=await fetch(`/api/projects/${te}/files/${encodeURIComponent(U)}`,{method:"POST",headers:{"Content-Type":"text/plain"},body:ne});if(ce.ok)await z(),E(U);else{const me=await ce.json().catch(()=>({error:"unknown"}));console.error(`Create file failed: ${me.error}`)}},[z,E]),W=d.useCallback(async U=>{const te=A.current;if(!te)return;const ne=await fetch(`/api/projects/${te}/files/${encodeURIComponent(U+"/.gitkeep")}`,{method:"POST",headers:{"Content-Type":"text/plain"},body:""});if(ne.ok)await z();else{const ce=await ne.json().catch(()=>({error:"unknown"}));console.error(`Create folder failed: ${ce.error}`)}},[z]),V=d.useCallback(async U=>{const te=A.current;if(!te)return;const ne=await fetch(`/api/projects/${te}/files/${encodeURIComponent(U)}`,{method:"DELETE"});if(ne.ok)w.current===U&&o(null),await z();else{const ce=await ne.json().catch(()=>({error:"unknown"}));console.error(`Delete failed: ${ce.error}`)}},[z]),G=d.useCallback(async(U,te)=>{const ne=A.current;if(!ne)return;const ce=await fetch(`/api/projects/${ne}/files/${encodeURIComponent(U)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({newPath:te})});if(ce.ok)w.current===U&&E(te),await z(),i(me=>me+1);else{const me=await ce.json().catch(()=>({error:"unknown"}));console.error(`Rename failed: ${me.error}`)}},[z,E,i]),q=d.useCallback(async U=>{const te=A.current;if(!te)return;const ne=await fetch(`/api/projects/${te}/duplicate-file`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:U})});if(ne.ok){const ce=await ne.json();await z(),ce.path&&E(ce.path)}else{const ce=await ne.json().catch(()=>({error:"unknown"}));console.error(`Duplicate failed: ${ce.error}`)}},[z,E]),B=G,D=d.useCallback(async(U,te)=>F(Array.from(U),te),[F]),P=d.useCallback(async U=>{const te=await F(Array.from(U).filter(me=>j1.test(me.name)),"assets/fonts"),ne=A.current,ce=te.filter(me=>j1.test(me)).map(me=>({family:lo(me),path:me,url:`/api/projects/${ne}/preview/${me}`}));return Q.current=[...ce,...Q.current.filter(me=>!ce.some(Se=>Se.family.toLowerCase()===me.family.toLowerCase()))],ce},[F]),R=d.useMemo(()=>h.filter(U=>U==="index.html"||U.startsWith("compositions/")),[h]),X=d.useMemo(()=>h.filter(U=>!U.endsWith(".html")&&!U.endsWith(".md")&&!U.endsWith(".json")),[h]),Y=d.useMemo(()=>X.filter(U=>j1.test(U)).map(U=>({family:lo(U),path:U,url:`/api/projects/${t}/preview/${U}`})),[X,t]);return{editingFile:l,setEditingFile:o,projectDir:c,fileTree:h,fileTreeLoaded:O,setFileTree:g,editingPathRef:w,projectIdRef:A,saveRafRef:k,importedFontAssetsRef:Q,readProjectFile:C,writeProjectFile:M,readOptionalProjectFile:j,revealSourceOffset:b,openSourceForSelection:L,handleFileSelect:E,handleContentChange:Z,refreshFileTree:z,uploadProjectFiles:F,handleCreateFile:K,handleCreateFolder:W,handleDeleteFile:V,handleRenameFile:G,handleDuplicateFile:q,handleMoveFile:B,handleImportFiles:D,handleImportFonts:P,compositions:R,assets:X,fontAssets:Y}}const Nr="--hf-studio-offset-x",Vr="--hf-studio-offset-y",Si="--hf-studio-width",wi="--hf-studio-height",Lr="--hf-studio-rotation",ta="data-hf-studio-path-offset",ru="data-hf-studio-manual-edit-gesture",na="data-hf-studio-box-size",ra="data-hf-studio-rotation",Ai="data-hf-studio-original-translate",ki="data-hf-studio-original-inline-translate",El="data-hf-studio-original-width",$l="data-hf-studio-original-height",Ql="data-hf-studio-original-min-width",Pl="data-hf-studio-original-min-height",jl="data-hf-studio-original-max-width",Zl="data-hf-studio-original-max-height",Rl="data-hf-studio-original-flex-basis",Nl="data-hf-studio-original-flex-grow",Vl="data-hf-studio-original-flex-shrink",Ll="data-hf-studio-original-box-sizing",Gr="data-hf-studio-original-scale",ia="data-hf-studio-original-transform-origin",_l="data-hf-studio-original-display",Mi="data-hf-studio-original-rotate",Ti="data-hf-studio-original-inline-rotate",Jr="data-hf-studio-original-rotation-transform-origin",Yl="data-hf-studio-rotation-draft",Cn="data-hf-studio-original-transform-display",hP="__hfStudioManualEditsApply",ep="__hfStudioManualEditsWrapped",Y0="__hfStudioManualEditsPlaybackFrame",mP="center center";function pP(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function jS(t){return Math.round(t*10)/10}function B0(t){return t.trim().replace(/\\/g,"/").replace(/^\.?\//,"")}function tp(t){if(typeof t=="string"){const n=t.trim();if(!n)return null;if(n.startsWith("{"))try{return tp(JSON.parse(n))}catch{return B0(n)}return B0(n)}if(!t||typeof t!="object")return null;const e=t;return typeof e.path=="string"?B0(e.path):typeof e.filePath=="string"?B0(e.filePath):"data"in e?tp(e.data):null}function gP(t){return tp(t)}const np=".hyperframes/studio-motion.json",C2="studio-motion",Ya="data-hf-studio-motion",Dl="data-hf-studio-motion-original-transform",so="data-hf-studio-motion-original-opacity",oo="data-hf-studio-motion-original-visibility",q0=["none","power1.in","power1.out","power1.inOut","power2.in","power2.out","power2.inOut","power3.in","power3.out","power3.inOut","power4.in","power4.out","power4.inOut","sine.in","sine.out","sine.inOut","expo.in","expo.out","expo.inOut","circ.in","circ.out","circ.inOut","back.in(1.7)","back.out(1.7)","back.inOut(1.7)","elastic.out(1, 0.45)","bounce.out"],$c={x1:.215,y1:.61,x2:.355,y2:1},OP={none:{x1:0,y1:0,x2:1,y2:1},"power1.in":{x1:.55,y1:.085,x2:.68,y2:.53},"power1.out":{x1:.25,y1:.46,x2:.45,y2:.94},"power1.inOut":{x1:.455,y1:.03,x2:.515,y2:.955},"power2.in":{x1:.55,y1:.055,x2:.675,y2:.19},"power2.out":{x1:.215,y1:.61,x2:.355,y2:1},"power2.inOut":{x1:.645,y1:.045,x2:.355,y2:1},"power3.in":{x1:.895,y1:.03,x2:.685,y2:.22},"power3.out":{x1:.165,y1:.84,x2:.44,y2:1},"power3.inOut":{x1:.77,y1:0,x2:.175,y2:1},"power4.in":{x1:.755,y1:.05,x2:.855,y2:.06},"power4.out":{x1:.23,y1:1,x2:.32,y2:1},"power4.inOut":{x1:.86,y1:0,x2:.07,y2:1},"sine.in":{x1:.47,y1:0,x2:.745,y2:.715},"sine.out":{x1:.39,y1:.575,x2:.565,y2:1},"sine.inOut":{x1:.445,y1:.05,x2:.55,y2:.95},"expo.in":{x1:.95,y1:.05,x2:.795,y2:.035},"expo.out":{x1:.19,y1:1,x2:.22,y2:1},"expo.inOut":{x1:1,y1:0,x2:0,y2:1},"circ.in":{x1:.6,y1:.04,x2:.98,y2:.335},"circ.out":{x1:.075,y1:.82,x2:.165,y2:1},"circ.inOut":{x1:.785,y1:.135,x2:.15,y2:.86},"back.in(1.7)":{x1:.6,y1:-.28,x2:.735,y2:.045},"back.out(1.7)":{x1:.175,y1:.885,x2:.32,y2:1.275},"back.inOut(1.7)":{x1:.68,y1:-.55,x2:.265,y2:1.55},"elastic.out(1, 0.45)":{x1:.16,y1:1.32,x2:.28,y2:.86},"bounce.out":{x1:.34,y1:1.56,x2:.64,y2:.74}},xP=/^M\s*0\s*,\s*0\s*C\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s+(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s+1\s*,\s*1\s*$/i;function $x(t,e){return Number.isFinite(t)&&t>0?t:e}function yP(t,e){return Number.isFinite(t)&&t>=0?t:e}function bP(t){return t.trim()||"none"}function Qc(t){return Math.round(t*1e3)/1e3}function I0(t,e,n,r){return Number.isFinite(t)?Math.min(n,Math.max(e,t)):r}function U0(t){const e=Qc(t);return Object.is(e,-0)?"0":`${e}`}function rp(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function Cg(t){return{x1:Qc(I0(t.x1??$c.x1,0,1,.215)),y1:Qc(I0(t.y1??$c.y1,-.6,1.6,.61)),x2:Qc(I0(t.x2??$c.x2,0,1,.355)),y2:Qc(I0(t.y2??$c.y2,-.6,1.6,1))}}function Qx(t){if(!t)return null;const e=t.trim().match(xP);if(!e)return null;const n={x1:Number.parseFloat(e[1]??""),y1:Number.parseFloat(e[2]??""),x2:Number.parseFloat(e[3]??""),y2:Number.parseFloat(e[4]??"")};return Object.values(n).every(Number.isFinite)?Cg(n):null}function ZS(t){const e=Cg(t);return`M0,0 C${U0(e.x1)},${U0(e.y1)} ${U0(e.x2)},${U0(e.y2)} 1,1`}function RS(t){return OP[t]??$c}function vP(t,e){const n=yP(e.start,0),r=$x(e.duration,.6),i=$x(e.distance,32),l=bP(e.ease),o=e.direction??"up",c={start:n,duration:r,ease:l,customEase:e.customEase};if(t==="pop")return{...c,from:{scale:.88,autoAlpha:0},to:{scale:1,autoAlpha:1}};if(t==="slide"){const f=o==="right"?-i:o==="left"?i:0,h=o==="down"?-i:o==="up"?i:0;return{...c,from:{x:f,y:h,autoAlpha:0},to:{x:0,y:0,autoAlpha:1}}}return{...c,from:{y:o==="down"?-i:i,autoAlpha:0},to:{y:0,autoAlpha:1}}}function Px(t){if(!t||typeof t!="object")return null;const e=t,n={};for(const r of["x","y","scale","rotation","opacity","autoAlpha"]){const i=rp(e[r]);i!=null&&(n[r]=i)}return Object.keys(n).length>0?n:null}function SP(t){if(!t||typeof t!="object")return;const e=t,n=typeof e.id=="string"?e.id.trim():"",r=typeof e.data=="string"?e.data.trim():"";if(!(!n||!r))return{id:n,data:r}}function NS(t){const e=t.getAttribute(Ya);if(!e||e==="true")return null;try{const n=JSON.parse(e);if(!n||typeof n!="object")return null;const r=n,i=rp(r.start),l=rp(r.duration);if(i==null||l==null||i<0||l<=0)return null;const o=typeof r.ease=="string"&&r.ease.trim()?r.ease.trim():"none",c=Px(r.from),f=Px(r.to);return!c||!f?null:{start:i,duration:l,ease:o,customEase:SP(r.customEase),from:c,to:f}}catch{return null}}function wP(t,e){t.getAttribute(Dl)||(t.setAttribute(Dl,t.style.transform),t.setAttribute(so,t.style.opacity),t.setAttribute(oo,t.style.visibility));const n={start:e.start,duration:e.duration,ease:e.ease,from:e.from,to:e.to};e.customEase&&(n.customEase=e.customEase),t.setAttribute(Ya,JSON.stringify(n))}function AP(t,e){var n;t.hasAttribute(Ya)&&((n=e==null?void 0:e.set)==null||n.call(e,t,{clearProps:"transform,opacity,visibility"}),t.style.transform=t.getAttribute(Dl)??"",t.style.opacity=t.getAttribute(so)??"",t.style.visibility=t.getAttribute(oo)??"",t.removeAttribute(Ya),t.removeAttribute(Dl),t.removeAttribute(so),t.removeAttribute(oo))}function kP(t,e){var n,r,i,l;try{const o=(r=(n=t.__player)==null?void 0:n.getTime)==null?void 0:r.call(n);if(typeof o=="number"&&Number.isFinite(o))return Math.max(0,o)}catch{}try{const o=(l=(i=t.__timeline)==null?void 0:i.time)==null?void 0:l.call(i);if(typeof o=="number"&&Number.isFinite(o))return Math.max(0,o)}catch{}return 0}function ip(t,e){var h,g,O,x,b,S;const n=t.defaultView;if(!n)return 0;const r=n.gsap;n.__timelines=n.__timelines??{},(g=(h=n.__timelines[C2])==null?void 0:h.kill)==null||g.call(h),delete n.__timelines[C2];const i=(O=t.defaultView)==null?void 0:O.HTMLElement;if(!i)return 0;const l=[];for(const w of Array.from(t.querySelectorAll(`[${Ya}]`))){if(!(w instanceof i))continue;const A=NS(w);A&&l.push({element:w,motion:A})}if(!(r!=null&&r.timeline)||l.length===0)return 0;const o=r.timeline({paused:!0,defaults:{overwrite:"auto"}});let c=0;for(const{element:w,motion:A}of l){if(!o.fromTo)continue;const k={...A.from},$=MP(n,A),Q={...A.to,duration:A.duration,ease:$,overwrite:"auto",immediateRender:!1};o.fromTo(w,k,Q,A.start),c+=1}if(c===0)return(x=o.kill)==null||x.call(o),0;n.__timelines[C2]=o,(b=o.pause)==null||b.call(o);const f=kP(n);return o.totalTime?o.totalTime(f,!1):(S=o.time)==null||S.call(o,f),c}function MP(t,e){var i,l;const n=e.customEase;if(!n)return e.ease;const r=t.CustomEase;if(typeof(r==null?void 0:r.create)!="function")return e.ease;try{return(l=(i=t.gsap)==null?void 0:i.registerPlugin)==null||l.call(i,r),r.create(n.id,n.data),n.id}catch{return e.ease}}let jx=0;function VS(t){jx+=1;const e=`gesture-${jx}`;return t.setAttribute(ru,e),e}function Fr(t,e){e&&t.getAttribute(ru)!==e||t.removeAttribute(ru)}function LS(t){return t.hasAttribute(ru)}function W0(t,e){return t.getAttribute(ru)===e}function W1(t,e){const n=Number.parseFloat(t.style.getPropertyValue(e));return Number.isFinite(n)?n:0}function ap(t){return{x:W1(t,Nr),y:W1(t,Vr)}}function G1(t){return{width:W1(t,Si),height:W1(t,wi)}}function _S(t){const e=Number.parseFloat(t.style.getPropertyValue(Lr));return{angle:Number.isFinite(e)?e:0}}function Eg(t,e){var n;try{return((n=t.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(t).getPropertyValue(e))??""}catch{return""}}function lp(t,e){return t.style.getPropertyValue(e)||Eg(t,e)}function DS(t,e){const n=lp(t,e).trim();return n==="none"?"":n}function sp(t){return t.includes(Nr)||t.includes(Vr)}function Zx(t){return t.includes(Si)||t.includes(wi)}function op(t){return t.includes(Lr)}function Rx(t){return t.replace(/\s+/g,"").toLowerCase()}function TP(t,e){if(!t.hasAttribute(Yl))return!1;const n=t.style.getPropertyValue(Lr).trim();return!n||!e.trim()?!1:Rx(e)===Rx(Pg(t,n))}function So(t){Eg(t,"display")==="inline"&&(t.hasAttribute(Cn)||t.setAttribute(Cn,t.style.getPropertyValue("display")),t.style.setProperty("display","inline-block"))}function $g(t){const e=t.getAttribute(Cn);e!=null&&(e===""?t.style.removeProperty("display"):t.style.setProperty("display",e),t.removeAttribute(Cn))}function CP(t){const e=[];let n=0,r="";for(const i of t.trim())i==="("&&(n+=1),i===")"&&(n=Math.max(0,n-1)),/\s/.test(i)&&n===0?(r&&e.push(r),r=""):r+=i;return r&&e.push(r),e}function HS(t,e,n){var l;const r=(l=t.getAttribute(Ai))==null?void 0:l.trim();if(!r||r==="none")return`${e} ${n}`;const i=CP(r);return i.length===1?`calc(${i[0]} + ${e}) ${n}`:i.length===2?`calc(${i[0]} + ${e}) calc(${i[1]} + ${n})`:i.length===3?`calc(${i[0]} + ${e}) calc(${i[1]} + ${n}) ${i[2]}`:`${e} ${n}`}function EP(t,e){const n=t.style.getPropertyValue("translate"),r=DS(t,"translate"),i=t.hasAttribute(ta),l=!sp(r);i?e&&l&&!LS(t)&&t.setAttribute(Ai,r):(t.setAttribute(ki,sp(n)?"":n),t.setAttribute(Ai,l?r:""))}function XS(t,e,n={}){EP(t,n.updateBase??!0),t.setAttribute(ta,"true"),t.style.setProperty(Nr,`${Math.round(e.x)}px`),t.style.setProperty(Vr,`${Math.round(e.y)}px`)}function zS(t){const e=t.style.getPropertyValue("transform");if(!e||e==="none")return;const n=t.ownerDocument.defaultView,r=n==null?void 0:n.DOMMatrix;if(r)try{const i=new r(e);if(i.m41===0&&i.m42===0)return;i.m41=0,i.m42=0,i.is2D&&i.a===1&&i.b===0&&i.c===0&&i.d===1?t.style.removeProperty("transform"):t.style.setProperty("transform",i.toString())}catch{}}function K1(t,e,n={}){So(t),XS(t,e,{updateBase:n.updateBase??!0}),t.style.setProperty("translate",HS(t,`var(${Nr}, 0px)`,`var(${Vr}, 0px)`)),zS(t)}function R1(t,e){So(t),XS(t,e,{updateBase:!1}),t.style.setProperty("translate",HS(t,`${Math.round(e.x)}px`,`${Math.round(e.y)}px`)),zS(t)}function $P(t,e){const n=t.parentElement;if(!n)return null;const r=lp(n,"display").trim();if(r!=="flex"&&r!=="inline-flex")return null;const i=lp(n,"flex-direction").trim();return Math.round(Math.max(1,i.startsWith("column")?e.height:e.width))}function QP(t){if(!t.hasAttribute(Gr))return;const e=t.getAttribute(Gr);e==null||e===""?t.style.removeProperty("scale"):t.style.setProperty("scale",e),t.removeAttribute(Gr);const n=t.getAttribute(ia);n==null||n===""?t.style.removeProperty("transform-origin"):t.style.setProperty("transform-origin",n),t.removeAttribute(ia)}function PP(t,e){t.hasAttribute(na)||(t.setAttribute(El,t.style.getPropertyValue("width")),t.setAttribute($l,t.style.getPropertyValue("height")),t.setAttribute(Ql,t.style.getPropertyValue("min-width")),t.setAttribute(Pl,t.style.getPropertyValue("min-height")),t.setAttribute(jl,t.style.getPropertyValue("max-width")),t.setAttribute(Zl,t.style.getPropertyValue("max-height")),t.setAttribute(Rl,t.style.getPropertyValue("flex-basis")),t.setAttribute(Nl,t.style.getPropertyValue("flex-grow")),t.setAttribute(Vl,t.style.getPropertyValue("flex-shrink")),t.setAttribute(Ll,t.style.getPropertyValue("box-sizing")),t.setAttribute(Gr,t.style.getPropertyValue("scale")),t.setAttribute(ia,t.style.getPropertyValue("transform-origin")),t.setAttribute(_l,t.style.getPropertyValue("display"))),t.setAttribute(na,"true"),t.style.setProperty(Si,`${Math.round(Math.max(1,e.width))}px`),t.style.setProperty(wi,`${Math.round(Math.max(1,e.height))}px`)}function FS(t,e){PP(t,e),QP(t);const n=Math.round(Math.max(1,e.width)),r=Math.round(Math.max(1,e.height));t.style.setProperty("box-sizing","border-box"),t.style.setProperty("width",`${n}px`),t.style.setProperty("height",`${r}px`),t.style.setProperty("min-width","0px"),t.style.setProperty("min-height","0px"),t.style.setProperty("max-width","none"),t.style.setProperty("max-height","none");const i=$P(t,e);i!=null&&(t.style.setProperty("flex-basis",`${i}px`),t.style.setProperty("flex-grow","0"),t.style.setProperty("flex-shrink","0")),Eg(t,"display")==="inline"&&t.style.setProperty("display","inline-block")}function Qg(t,e){So(t),FS(t,e)}function jP(t,e){So(t),FS(t,e)}function ZP(t){return/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|rad|turn|grad)$/.test(t.trim())}function Pg(t,e){var r;const n=(r=t.getAttribute(Mi))==null?void 0:r.trim();return!n||n==="none"||!ZP(n)?e:`calc(${n} + ${e})`}function RP(t,e){const n=t.style.getPropertyValue("rotate"),r=DS(t,"rotate"),i=t.hasAttribute(ra),l=!op(r)&&!TP(t,r);i?e&&l&&!LS(t)&&t.setAttribute(Mi,r):(t.setAttribute(Ti,op(n)?"":n),t.setAttribute(Mi,l?r:"")),t.hasAttribute(Jr)||t.setAttribute(Jr,t.style.getPropertyValue("transform-origin"))}function YS(t,e,n={}){RP(t,n.updateBase??!0),t.setAttribute(ra,"true"),t.style.setProperty(Lr,`${jS(e.angle)}deg`),t.style.setProperty("transform-origin",mP)}function jg(t,e){So(t),YS(t,e),t.removeAttribute(Yl),t.style.setProperty("rotate",Pg(t,`var(${Lr}, 0deg)`))}function NP(t,e){So(t),YS(t,e,{updateBase:!1}),t.setAttribute(Yl,"true"),t.style.setProperty("rotate",Pg(t,`${jS(e.angle)}deg`))}function Nx(t){const e=t.style.getPropertyValue(Nr),n=t.style.getPropertyValue(Vr),r=t.style.getPropertyValue("translate"),i=t.getAttribute(Ai),l=t.getAttribute(ki),o=t.style.getPropertyValue("display"),c=t.getAttribute(Cn),f=[];return e&&f.push({type:"inline-style",property:Nr,value:e}),n&&f.push({type:"inline-style",property:Vr,value:n}),r&&f.push({type:"inline-style",property:"translate",value:r}),f.push({type:"attribute",property:ta,value:"true"}),i!==null&&f.push({type:"attribute",property:Ai,value:i}),l!==null&&f.push({type:"attribute",property:ki,value:l}),o&&f.push({type:"inline-style",property:"display",value:o}),c!==null&&f.push({type:"attribute",property:Cn,value:c}),f}function VP(t){const e=t.getAttribute(ki),n=[{type:"inline-style",property:Nr,value:null},{type:"inline-style",property:Vr,value:null},{type:"inline-style",property:"translate",value:e||null},{type:"attribute",property:ta,value:null},{type:"attribute",property:Ai,value:null},{type:"attribute",property:ki,value:null}],r=t.getAttribute(Cn);return r!==null&&(n.push({type:"inline-style",property:"display",value:r||null}),n.push({type:"attribute",property:Cn,value:null})),n}function LP(t){const e=[],n=t.style.getPropertyValue(Si),r=t.style.getPropertyValue(wi);n&&e.push({type:"inline-style",property:Si,value:n}),r&&e.push({type:"inline-style",property:wi,value:r});const i=t.style.getPropertyValue("width"),l=t.style.getPropertyValue("height"),o=t.style.getPropertyValue("min-width"),c=t.style.getPropertyValue("min-height"),f=t.style.getPropertyValue("max-width"),h=t.style.getPropertyValue("max-height"),g=t.style.getPropertyValue("flex-basis"),O=t.style.getPropertyValue("flex-grow"),x=t.style.getPropertyValue("flex-shrink"),b=t.style.getPropertyValue("box-sizing"),S=t.style.getPropertyValue("scale"),w=t.style.getPropertyValue("transform-origin"),A=t.style.getPropertyValue("display");i&&e.push({type:"inline-style",property:"width",value:i}),l&&e.push({type:"inline-style",property:"height",value:l}),o&&e.push({type:"inline-style",property:"min-width",value:o}),c&&e.push({type:"inline-style",property:"min-height",value:c}),f&&e.push({type:"inline-style",property:"max-width",value:f}),h&&e.push({type:"inline-style",property:"max-height",value:h}),g&&e.push({type:"inline-style",property:"flex-basis",value:g}),O&&e.push({type:"inline-style",property:"flex-grow",value:O}),x&&e.push({type:"inline-style",property:"flex-shrink",value:x}),b&&e.push({type:"inline-style",property:"box-sizing",value:b}),S&&e.push({type:"inline-style",property:"scale",value:S}),w&&e.push({type:"inline-style",property:"transform-origin",value:w}),A&&e.push({type:"inline-style",property:"display",value:A}),e.push({type:"attribute",property:na,value:"true"});const k=t.getAttribute(El),$=t.getAttribute($l),Q=t.getAttribute(Ql),C=t.getAttribute(Pl),M=t.getAttribute(jl),j=t.getAttribute(Zl),E=t.getAttribute(Rl),Z=t.getAttribute(Nl),_=t.getAttribute(Vl),H=t.getAttribute(Ll),L=t.getAttribute(Gr),z=t.getAttribute(ia),F=t.getAttribute(_l),K=t.getAttribute(Cn);return k!==null&&e.push({type:"attribute",property:El,value:k}),$!==null&&e.push({type:"attribute",property:$l,value:$}),Q!==null&&e.push({type:"attribute",property:Ql,value:Q}),C!==null&&e.push({type:"attribute",property:Pl,value:C}),M!==null&&e.push({type:"attribute",property:jl,value:M}),j!==null&&e.push({type:"attribute",property:Zl,value:j}),E!==null&&e.push({type:"attribute",property:Rl,value:E}),Z!==null&&e.push({type:"attribute",property:Nl,value:Z}),_!==null&&e.push({type:"attribute",property:Vl,value:_}),H!==null&&e.push({type:"attribute",property:Ll,value:H}),L!==null&&e.push({type:"attribute",property:Gr,value:L}),z!==null&&e.push({type:"attribute",property:ia,value:z}),F!==null&&e.push({type:"attribute",property:_l,value:F}),K!==null&&e.push({type:"attribute",property:Cn,value:K}),e}function _P(t){const e=[{type:"inline-style",property:Si,value:null},{type:"inline-style",property:wi,value:null},{type:"attribute",property:na,value:null}],n=[[El,"width"],[$l,"height"],[Ql,"min-width"],[Pl,"min-height"],[jl,"max-width"],[Zl,"max-height"],[Rl,"flex-basis"],[Nl,"flex-grow"],[Vl,"flex-shrink"],[Ll,"box-sizing"],[Gr,"scale"],[ia,"transform-origin"],[_l,"display"]];for(const[i,l]of n){const o=t.getAttribute(i);o!==null&&e.push({type:"inline-style",property:l,value:o||null}),e.push({type:"attribute",property:i,value:null})}const r=t.getAttribute(Cn);return r!==null&&(e.push({type:"inline-style",property:"display",value:r||null}),e.push({type:"attribute",property:Cn,value:null})),e}function DP(t){const e=[],n=t.style.getPropertyValue(Lr),r=t.style.getPropertyValue("rotate"),i=t.style.getPropertyValue("transform-origin"),l=t.style.getPropertyValue("display");n&&e.push({type:"inline-style",property:Lr,value:n}),r&&e.push({type:"inline-style",property:"rotate",value:r}),i&&e.push({type:"inline-style",property:"transform-origin",value:i}),l&&e.push({type:"inline-style",property:"display",value:l}),e.push({type:"attribute",property:ra,value:"true"});const o=t.getAttribute(Mi),c=t.getAttribute(Ti),f=t.getAttribute(Jr),h=t.getAttribute(Cn);return o!==null&&e.push({type:"attribute",property:Mi,value:o}),c!==null&&e.push({type:"attribute",property:Ti,value:c}),f!==null&&e.push({type:"attribute",property:Jr,value:f}),h!==null&&e.push({type:"attribute",property:Cn,value:h}),e}function HP(t){const e=t.getAttribute(Ti),n=t.getAttribute(Jr),r=[{type:"inline-style",property:Lr,value:null},{type:"inline-style",property:"rotate",value:e||null},{type:"inline-style",property:"transform-origin",value:n!==null&&n||null},{type:"attribute",property:ra,value:null},{type:"attribute",property:Yl,value:null},{type:"attribute",property:Mi,value:null},{type:"attribute",property:Ti,value:null},{type:"attribute",property:Jr,value:null}],i=t.getAttribute(Cn);return i!==null&&(r.push({type:"inline-style",property:"display",value:i||null}),r.push({type:"attribute",property:Cn,value:null})),r}function XP(t){const e=t.getAttribute(Ya);if(!e)return[];const n=[{type:"attribute",property:Ya,value:e}],r=t.getAttribute(Dl);r!==null&&n.push({type:"attribute",property:Dl,value:r});const i=t.getAttribute(so);i!==null&&n.push({type:"attribute",property:so,value:i});const l=t.getAttribute(oo);return l!==null&&n.push({type:"attribute",property:oo,value:l}),n}function zP(t){return[{type:"attribute",property:Ya,value:null},{type:"attribute",property:Dl,value:null},{type:"attribute",property:so,value:null},{type:"attribute",property:oo,value:null}]}function FP(t){var l;const e=(l=t.defaultView)==null?void 0:l.HTMLElement;if(!e)return;const n=Array.from(t.querySelectorAll(`[${ta}="true"]`)).filter(o=>o instanceof e);for(const o of n){const c=o.style.getPropertyValue(Nr),f=o.style.getPropertyValue(Vr);(c||f)&&K1(o,{x:Number.parseFloat(c)||0,y:Number.parseFloat(f)||0})}const r=Array.from(t.querySelectorAll(`[${na}="true"]`)).filter(o=>o instanceof e);for(const o of r){const c=Number.parseFloat(o.style.getPropertyValue(Si)),f=Number.parseFloat(o.style.getPropertyValue(wi));Number.isFinite(c)&&Number.isFinite(f)&&c>0&&f>0&&Qg(o,{width:c,height:f})}const i=Array.from(t.querySelectorAll(`[${ra}="true"]`)).filter(o=>o instanceof e);for(const o of i){const c=Number.parseFloat(o.style.getPropertyValue(Lr));Number.isFinite(c)&&jg(o,{angle:c})}ip(t)}function YP(t){return{width:t.style.getPropertyValue("width"),height:t.style.getPropertyValue("height"),minWidth:t.style.getPropertyValue("min-width"),minHeight:t.style.getPropertyValue("min-height"),maxWidth:t.style.getPropertyValue("max-width"),maxHeight:t.style.getPropertyValue("max-height"),flexBasis:t.style.getPropertyValue("flex-basis"),flexGrow:t.style.getPropertyValue("flex-grow"),flexShrink:t.style.getPropertyValue("flex-shrink"),boxSizing:t.style.getPropertyValue("box-sizing"),scale:t.style.getPropertyValue("scale"),transformOrigin:t.style.getPropertyValue("transform-origin"),display:t.style.getPropertyValue("display"),studioWidth:t.style.getPropertyValue(Si),studioHeight:t.style.getPropertyValue(wi),marker:t.getAttribute(na),originalWidth:t.getAttribute(El),originalHeight:t.getAttribute($l),originalMinWidth:t.getAttribute(Ql),originalMinHeight:t.getAttribute(Pl),originalMaxWidth:t.getAttribute(jl),originalMaxHeight:t.getAttribute(Zl),originalFlexBasis:t.getAttribute(Rl),originalFlexGrow:t.getAttribute(Nl),originalFlexShrink:t.getAttribute(Vl),originalBoxSizing:t.getAttribute(Ll),originalScale:t.getAttribute(Gr),originalTransformOrigin:t.getAttribute(ia),originalDisplay:t.getAttribute(_l)}}function BP(t){return{rotate:t.style.getPropertyValue("rotate"),transformOrigin:t.style.getPropertyValue("transform-origin"),studioRotation:t.style.getPropertyValue(Lr),marker:t.getAttribute(ra),draftMarker:t.getAttribute(Yl),originalRotate:t.getAttribute(Mi),originalInlineRotate:t.getAttribute(Ti),originalTransformOrigin:t.getAttribute(Jr)}}function Zg(t){return{translate:t.style.getPropertyValue("translate"),x:t.style.getPropertyValue(Nr),y:t.style.getPropertyValue(Vr),marker:t.getAttribute(ta),originalTranslate:t.getAttribute(Ai),originalInlineTranslate:t.getAttribute(ki)}}function Zt(t,e,n){n==null?t.removeAttribute(e):t.setAttribute(e,n)}function on(t,e,n){n?t.style.setProperty(e,n):t.style.removeProperty(e)}function E2(t,e){on(t,"width",e.width),on(t,"height",e.height),on(t,"min-width",e.minWidth),on(t,"min-height",e.minHeight),on(t,"max-width",e.maxWidth),on(t,"max-height",e.maxHeight),on(t,"flex-basis",e.flexBasis),on(t,"flex-grow",e.flexGrow),on(t,"flex-shrink",e.flexShrink),on(t,"box-sizing",e.boxSizing),on(t,"scale",e.scale),on(t,"transform-origin",e.transformOrigin),on(t,"display",e.display),on(t,Si,e.studioWidth),on(t,wi,e.studioHeight),Zt(t,na,e.marker),Zt(t,El,e.originalWidth),Zt(t,$l,e.originalHeight),Zt(t,Ql,e.originalMinWidth),Zt(t,Pl,e.originalMinHeight),Zt(t,jl,e.originalMaxWidth),Zt(t,Zl,e.originalMaxHeight),Zt(t,Rl,e.originalFlexBasis),Zt(t,Nl,e.originalFlexGrow),Zt(t,Vl,e.originalFlexShrink),Zt(t,Ll,e.originalBoxSizing),Zt(t,Gr,e.originalScale),Zt(t,ia,e.originalTransformOrigin),Zt(t,_l,e.originalDisplay)}function $2(t,e){on(t,"rotate",e.rotate),on(t,"transform-origin",e.transformOrigin),on(t,Lr,e.studioRotation),Zt(t,ra,e.marker),Zt(t,Yl,e.draftMarker),Zt(t,Mi,e.originalRotate),Zt(t,Ti,e.originalInlineRotate),Zt(t,Jr,e.originalTransformOrigin)}function bl(t,e){e.translate?t.style.setProperty("translate",e.translate):t.style.removeProperty("translate"),e.x?t.style.setProperty(Nr,e.x):t.style.removeProperty(Nr),e.y?t.style.setProperty(Vr,e.y):t.style.removeProperty(Vr),Zt(t,ta,e.marker),Zt(t,Ai,e.originalTranslate),Zt(t,ki,e.originalInlineTranslate)}function lr(t,e,n){const r=t.getAttribute(n);r==null||r===""?t.style.removeProperty(e):t.style.setProperty(e,r),t.removeAttribute(n)}function qP(t){const e=t.getAttribute(Ti);e==null||e===""?t.style.removeProperty("rotate"):t.style.setProperty("rotate",e),t.removeAttribute(Ti),t.removeAttribute(Mi);const n=t.getAttribute(Jr);n!=null&&(n===""?t.style.removeProperty("transform-origin"):t.style.setProperty("transform-origin",n)),t.removeAttribute(Jr)}function IP(t){const e=t.getAttribute(ki);e==null||e===""?t.style.removeProperty("translate"):t.style.setProperty("translate",e),t.removeAttribute(ki),t.removeAttribute(Ai)}function UP(t){(t.hasAttribute(ta)||sp(t.style.getPropertyValue("translate")))&&IP(t),$g(t),t.style.removeProperty(Nr),t.style.removeProperty(Vr),t.removeAttribute(ta),t.removeAttribute(Ai),t.removeAttribute(ki)}function WP(t){(t.hasAttribute(ra)||op(t.style.getPropertyValue("rotate")))&&qP(t),$g(t),t.style.removeProperty(Lr),t.removeAttribute(ra),t.removeAttribute(Yl),t.removeAttribute(Mi),t.removeAttribute(Ti),t.removeAttribute(Jr)}function GP(t){(t.hasAttribute(na)||Zx(t.style.getPropertyValue("width"))||Zx(t.style.getPropertyValue("height"))||t.hasAttribute(Gr))&&(lr(t,"width",El),lr(t,"height",$l),lr(t,"min-width",Ql),lr(t,"min-height",Pl),lr(t,"max-width",jl),lr(t,"max-height",Zl),lr(t,"flex-basis",Rl),lr(t,"flex-grow",Nl),lr(t,"flex-shrink",Vl),lr(t,"box-sizing",Ll),lr(t,"scale",Gr),lr(t,"transform-origin",ia),lr(t,"display",_l)),$g(t),t.style.removeProperty(Si),t.style.removeProperty(wi),t.removeAttribute(na)}function Rg(t){try{Object.defineProperty(t,ep,{configurable:!1,enumerable:!1,value:!0})}catch{try{t[ep]=!0}catch{}}}function Ng(t){return!!t[ep]}function bc(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(Ng(i))return!0;const l=function(...o){var f;const c=i.apply(this,o);return(f=t.__hfStudioManualEditsApply)==null||f.call(t),c};Rg(l);try{e[n]=l}catch{return!1}return!0}function vc(t,e){const n=t[e];if(typeof n!="function")return null;try{return pP(n.call(t))}catch{return null}}function KP(t){const e=vc(t,"duration")??vc(t,"getDuration");if(e==null)return!0;if(e<=0)return!1;const n=vc(t,"time")??vc(t,"totalTime")??vc(t,"getTime");return n==null?!0:n<e}function Q2(t){if(!t)return!1;const e=t.isPlaying;if(typeof e=="function")try{return!!e.call(t)}catch{return!1}const n=t.paused;if(typeof n=="function"){try{if(n.call(t))return!1}catch{return!1}const i=t.isActive;if(typeof i=="function")try{if(i.call(t))return!0}catch{return!1}return KP(t)}const r=t.isActive;if(typeof r=="function")try{return!!r.call(t)}catch{return!1}return!1}function BS(t){return Q2(t.__player)||Q2(t.__timeline)?!0:Object.values(t.__timelines??{}).some(Q2)}function qS(t){var n;if((n=t.__hfStudioManualEditsApply)==null||n.call(t),t[Y0]!=null)return;const e=()=>{var r;if((r=t.__hfStudioManualEditsApply)==null||r.call(t),!BS(t)){t[Y0]=null;return}t[Y0]=t.requestAnimationFrame(e)};t[Y0]=t.requestAnimationFrame(e)}function P2(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(Ng(i))return!0;const l=function(...o){const c=i.apply(this,o);return qS(t),c};Rg(l);try{e[n]=l}catch{return!1}return!0}function j2(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(Ng(i))return!0;const l=function(...o){var f;const c=i.apply(this,o);return(f=t.__hfStudioManualEditsApply)==null||f.call(t),c};Rg(l);try{e[n]=l}catch{return!1}return!0}function JP(t,e){const n=t;n[hP]=e;const r=bc(n,n.__hf,"seek"),i=bc(n,n.__player,"seek"),l=bc(n,n.__player,"renderSeek"),o=bc(n,n.__timeline,"seek"),c=P2(n,n.__player,"play"),f=P2(n,n.__timeline,"play"),h=j2(n,n.__player,"pause"),g=j2(n,n.__timeline,"pause");let O=!1,x=!1,b=!1;for(const S of Object.values(n.__timelines??{}))O=bc(n,S,"seek")||O,x=P2(n,S,"play")||x,b=j2(n,S,"pause")||b;return BS(n)&&qS(n),r||i||l||o||c||f||h||g||O||x||b}function ej({projectId:t,showToast:e,readOptionalProjectFile:n,writeProjectFile:r,recordEdit:i,previewIframeRef:l,activeCompPathRef:o,domEditSaveTimestampRef:c,reloadPreview:f,pendingTimelineEditPathRef:h}){const g=d.useRef(0),O=d.useRef(Promise.resolve()),x=d.useRef(async()=>{}),b=d.useRef(t);b.current=t;const S=d.useCallback(Q=>{const C=O.current.catch(()=>{}).then(Q);return O.current=C.then(()=>{},()=>{}),C},[]),w=d.useCallback(async()=>{await O.current.catch(()=>{})},[]),A=d.useCallback((Q=l.current)=>{var Z,_,H,L,z,F;if(!Q)return;let C=null;try{C=Q.contentDocument}catch{return}if(!C)return;const M=()=>{let K=null;try{K=Q.contentDocument}catch{return}K&&FP(K)},j=()=>{M(),Q.contentWindow&&JP(Q.contentWindow,M)},E=Q.contentWindow;j(),(Z=E==null?void 0:E.requestAnimationFrame)==null||Z.call(E,j),(_=E==null?void 0:E.setTimeout)==null||_.call(E,j,80),(H=E==null?void 0:E.setTimeout)==null||H.call(E,j,250),(L=E==null?void 0:E.setTimeout)==null||L.call(E,j,500),(z=E==null?void 0:E.setTimeout)==null||z.call(E,j,1e3),(F=E==null?void 0:E.setTimeout)==null||F.call(E,j,2e3)},[l]),k=d.useCallback(async(Q=l.current)=>{A(Q)},[A,l]);x.current=k;const $=d.useCallback(async Q=>{f()},[f]);return Qt(()=>{n(np).then(Q=>{if(Q){try{const C=JSON.parse(Q);if(!Array.isArray(C.motions)||C.motions.length===0)return}catch{return}return r(np,JSON.stringify({version:1,motions:[]}))}}).catch(()=>{})}),Qt(()=>{const Q=M=>{const j=gP(M);if(!j)return;const E=Date.now()-c.current<4e3;if(h!=null&&h.current.has(j)){h.current.delete(j);return}E||f()},C=new EventSource("/api/events");return C.addEventListener("file-change",Q),()=>C.close()}),{domTextCommitVersionRef:g,domEditSaveQueueRef:O,applyStudioManualEditsToPreviewRef:x,queueDomEditSave:S,waitForPendingDomEditSaves:w,applyCurrentStudioManualEditsToPreview:A,applyStudioManualEditsToPreview:k,syncHistoryPreviewAfterApply:$}}function Ls(t){return t.label||t.id||t.tag}function Vx(t){const e=t.trim(),n=/^[a-z]+:\/\//i.test(e)?new URL(e).pathname:e;return decodeURIComponent(n).replace(/\\/g,"/").replace(/^\.?\//,"")}function tj(t,e){const n=Vx(t).split("/").filter(Boolean),r=Vx(e).split("/").filter(Boolean);for(n.pop();n.length>0&&r.length>0&&n[0]===r[0];)n.shift(),r.shift();return[...n.map(()=>".."),...r].join("/")||e}function nj(t){return/^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(t)}function rj(t,e){const n=e.trim();if(!n)return;const r=n.replace(/\\/g,"/");if(nj(r))return r;const i=t==null?void 0:t.trim().replace(/\\/g,"/").replace(/\/+$/,"");if(i)return`${i}/${r.replace(/^\.?\//,"")}`}function Z2(t,e){const n=e.trim();return n&&(["border-radius","border-width","font-size","letter-spacing"].includes(t)&&/^-?\d+(\.\d+)?$/.test(n)?`${n}px`:n)}function Lx(t){return/^url\(/i.test(t.trim())}function ij(t){return t==="left"||t==="top"||t==="width"||t==="height"}function IS(t){if(!t||typeof t!="object")return null;const e=t;return e.nodeType===1?t:e.nodeType===3&&e.parentElement?e.parentElement:null}function _x(t){const e=IS(t);return e?!!e.closest("input, textarea, select, [contenteditable='true'], [role='textbox'], .cm-editor"):!1}function G0(t){const n=typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/i.test(navigator.platform)?"Cmd":"Ctrl";return t==="undo"?`${n}+Z`:`${n}+Shift+Z`}function cp(t,e){const n=t.sourceFile||"index.html";for(const r of e){const i=r.sourceFile||"index.html";if(t.id&&r.domId===t.id&&i===n||t.isCompositionHost&&t.compositionSrc&&r.compositionSrc===t.compositionSrc||t.selector&&r.selector===t.selector&&(r.selectorIndex??0)===(t.selectorIndex??0)&&(r.sourceFile??"index.html")===t.sourceFile)return r.key??r.id}return null}function aj(t,e){if(!e||!Number.isFinite(e.start)||!Number.isFinite(e.duration))return null;const n=Math.max(0,e.start),r=Math.max(n,n+Math.max(0,e.duration)),i=Number.isFinite(t)?t:n;return iu(i,n,r)}function iu(t,e,n){return n<e?e:Math.min(Math.max(t,e),n)}function Vg(t){return Array.from(t.matchAll(/\bid="([^"]+)"/g),e=>e[1]??"")}const K0={image:3,video:5,audio:5};async function Dx(t,e,n){if(n==="image")return K0.image;const r=document.createElement(n==="video"?"video":"audio");r.preload="metadata",r.src=`/api/projects/${t}/preview/${e}`;const i=await new Promise(l=>{const o=window.setTimeout(()=>l(K0[n]),3e3),c=f=>{window.clearTimeout(o),l(f)};r.addEventListener("loadedmetadata",()=>{const f=Number(r.duration);c(Number.isFinite(f)&&f>0?Math.round(f*100)/100:K0[n])},{once:!0}),r.addEventListener("error",()=>c(K0[n]),{once:!0})});return r.src="",r.load(),i}function US(t){return t.domId?{id:t.domId,selector:t.selector,selectorIndex:t.selectorIndex}:t.selector?{selector:t.selector,selectorIndex:t.selectorIndex}:null}function Hx(t,e,n){try{const r=t==null?void 0:t.contentDocument;if(!r)return;const i=e.domId?r.getElementById(e.domId):e.selector?r.querySelectorAll(e.selector)[e.selectorIndex??0]??null:null;if(!i)return;for(const[l,o]of n)i.setAttribute(l,o)}catch{}}function lj(t,e,n,r){if(r.playbackStart!=null)return{attrName:n.playbackStartAttr==="playback-start"?"playback-start":"media-start",value:r.playbackStart};const i=r.start-n.start;if(i===0)return null;const l=Ex(t,e,"playback-start")??Ex(t,e,"media-start"),o=l!=null?parseFloat(l):void 0;return o==null||!Number.isFinite(o)?null:{attrName:n.playbackStartAttr==="playback-start"?"playback-start":"media-start",value:Math.max(0,o+i*Math.max(n.playbackRate??1,.1))}}async function sj(t){const e=t.element.sourceFile||t.activeCompPath||"index.html",n=await up(t.projectId,e),r=US(t.element);if(!r)throw new Error(`Timeline element ${t.element.id} is missing a patchable target`);const i=t.buildPatches(n,r);if(i===n)throw new Error(`Unable to patch timeline element ${t.element.id} in ${e}`);t.pendingTimelineEditPathRef.current.add(e),t.domEditSaveTimestampRef.current=Date.now(),await Cl({projectId:t.projectId,label:t.label,kind:"timeline",files:{[e]:i},readFile:async()=>n,writeFile:t.writeProjectFile,recordEdit:t.recordEdit}),t.domEditSaveTimestampRef.current=Date.now()}async function up(t,e){const n=await fetch(`/api/projects/${t}/files/${encodeURIComponent(e)}`);if(!n.ok)throw new Error(`Failed to read ${e}`);const r=await n.json();if(typeof r.content!="string")throw new Error(`Missing file contents for ${e}`);return r.content}function oj({projectId:t,activeCompPath:e,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:l,domEditSaveTimestampRef:o,reloadPreview:c,previewIframeRef:f,pendingTimelineEditPathRef:h,uploadProjectFiles:g}){const O=d.useRef(t);O.current=t;const x=d.useRef(Promise.resolve()),b=d.useRef(0),S=d.useCallback((M,j,E)=>{const Z=O.current;if(!Z)return Promise.resolve();const _=x.current.then(()=>sj({projectId:Z,element:M,activeCompPath:e,label:j,buildPatches:E,writeProjectFile:i,recordEdit:l,domEditSaveTimestampRef:o,pendingTimelineEditPathRef:h}));return x.current=_.catch(H=>{console.error(`[Timeline] Failed to persist: ${j}`,H)}),_},[e,l,i,o,h]),w=d.useCallback((M,j)=>(Hx(f.current,M,[["data-start",wn(j.start)],["data-track-index",String(j.track)]]),S(M,"Move timeline clip",(E,Z)=>{let _=yc(E,Z,{type:"attribute",property:"start",value:wn(j.start)});return yc(_,Z,{type:"attribute",property:"track-index",value:String(j.track)})})),[f,S]),A=d.useCallback((M,j)=>(Hx(f.current,M,[["data-start",wn(j.start)],["data-duration",wn(j.duration)]]),S(M,"Resize timeline clip",(E,Z)=>{const _=lj(E,Z,M,j);let H=yc(E,Z,{type:"attribute",property:"start",value:wn(j.start)});return H=yc(H,Z,{type:"attribute",property:"duration",value:wn(j.duration)}),_&&(H=yc(H,Z,{type:"attribute",property:_.attrName,value:wn(_.value)})),H})),[f,S]),k=d.useCallback(async M=>{const j=O.current;if(!j)throw new Error("No active project");const E=Ls(M),Z=M.sourceFile||e||"index.html";try{const _=await up(j,Z),H=US(M);if(!H)throw new Error(`Timeline element ${M.id} is missing a patchable target`);const L=await fetch(`/api/projects/${j}/file-mutations/remove-element/${encodeURIComponent(Z)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:H})});if(!L.ok)throw new Error(`Failed to delete ${M.id} from ${Z}`);const z=await L.json(),F=typeof z.content=="string"?z.content:_;o.current=Date.now(),await Cl({projectId:j,label:"Delete timeline clip",kind:"timeline",files:{[Z]:F},readFile:async()=>_,writeFile:i,recordEdit:l}),ge.getState().setElements(n.filter(K=>(K.key??K.id)!==(M.key??M.id))),ge.getState().setSelectedElementId(null),c(),r(`Deleted ${E}. Use Undo to restore it.`,"info")}catch(_){const H=_ instanceof Error?_.message:"Failed to delete timeline clip";r(H)}},[e,l,r,n,i,o,c]),$=d.useCallback(async(M,j,E)=>{const Z=O.current;if(!Z)throw new Error("No active project");const _=px(M);if(!_){r("Only image, video, and audio assets can be dropped onto the timeline.");return}const H=e||"index.html";try{const L=await up(Z,H),z=Number(wn(j.start)),F=Number.isFinite(E)&&E!=null&&E>0?E:await Dx(Z,M,_),K=Number(wn(F)),W=kE(M,Vg(L)),V=ME(H,M),G=H||"index.html",q=n.filter(P=>(P.sourceFile||e||"index.html")===G),B=Math.max(1,q.length+1),D=Ag(L,CE({id:W,assetPath:V,kind:_,start:z,duration:K,track:j.track,zIndex:B,geometry:Qv(L)}));o.current=Date.now(),await Cl({projectId:Z,label:"Add timeline asset",kind:"timeline",files:{[H]:D},readFile:async()=>L,writeFile:i,recordEdit:l}),c()}catch(L){const z=L instanceof Error?L.message:"Failed to drop asset onto timeline";r(z)}},[e,l,r,n,i,o,c]),Q=d.useCallback(async(M,j)=>{const E=O.current;if(!E)return;const Z=await g(M);if(Z.length===0)return;const _=[];for(const L of Z){const z=px(L),F=z?await Dx(E,L,z):0;_.push(Number(wn(F)))}const H=TE(j??{start:0,track:0},_,n.filter(L=>(L.sourceFile||e||"index.html")===(e||"index.html")).map(L=>({start:L.start,duration:L.duration,track:L.track})));for(const[L,z]of Z.entries())await $(z,H[L]??H[0],_[L])},[e,$,n,g]),C=d.useCallback(M=>{const j=Date.now();j-b.current<1500||(b.current=j,r("This clip can't be moved or resized from the timeline yet.","info"))},[r]);return{handleTimelineElementMove:w,handleTimelineElementResize:A,handleTimelineElementDelete:k,handleTimelineAssetDrop:$,handleTimelineFileDrop:Q,handleBlockedTimelineEdit:C}}function cj(t){try{const e=t==null?void 0:t.contentDocument;if(!e)return 0;let n=0;for(const r of e.body.querySelectorAll("*")){const i=parseInt(getComputedStyle(r).zIndex,10);Number.isFinite(i)&&i>n&&(n=i)}return n}catch{return 0}}function uj(t,e){const n=new Set(e);if(!n.has(t))return t;let r=2;for(;n.has(`${t}_${r}`);)r++;return`${t}_${r}`}async function R2(t){const{projectId:e,blockName:n,activeCompPath:r,placement:i,visualPosition:l,timelineElements:o,readProjectFile:c,writeProjectFile:f,recordEdit:h,refreshFileTree:g,reloadPreview:O,showToast:x}=t;try{const b=await fetch(`/api/projects/${e}/registry/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({blockName:n})});if(!b.ok){const k=await b.json().catch(()=>({error:"Install failed"}));return x(k.error||"Failed to install block"),null}const{written:S,block:w}=await b.json(),A=S.find(k=>k.endsWith(".html"))??S[0];if(!A)return x("Installed but no composition file was written"),null;if(w.type==="hyperframes:component"){const k=await c(A),$=k.replace(/background:\s*(?:#(?:0a0a0a|000000|000|0a0805)|rgba?\([^)]*\))\s*;/g,"background: transparent;");$!==k&&await f(A,$)}{const k=r||"index.html",$=await c(k),Q=Vg($),C=uj(w.name,Q),M=k||"index.html",j=o.filter(X=>(X.sourceFile||r||"index.html")===M),E=w.type==="hyperframes:block",Z=Qv($),_=t.currentTime??0,H=Number(wn(i?i.start:_)),z=("duration"in w?w.duration:void 0)??j.reduce((X,Y)=>Math.max(X,(Y.start??0)+(Y.duration??0)),10),F=(i==null?void 0:i.track)??(E?0:j.length>0?Math.max(...j.map(X=>X.track))+1:1),K=cj(t.previewIframe??null)+1,W=Z.width,V=Z.height,G=l?Math.round(l.left):0,q=l?Math.round(l.top):0,B=["<div",` data-composition-id="${C}"`,` data-composition-src="${A}"`,` data-start="${wn(H)}"`,` data-duration="${wn(z)}"`,` data-track-index="${F}"`,` data-width="${W}"`,` data-height="${V}"`,` style="position: absolute; left: ${G}px; top: ${q}px; width: ${W}px; height: ${V}px; z-index: ${K}"`,"></div>"].join(`
85
- `);let D=Ag($,B);const P=H+z,R=D.match(/(<[^>]*data-composition-id="[^"]*"[^>]*data-duration=")([^"]*)(")/);if(R){const X=parseFloat(R[2]);P>X&&(D=D.replace(R[0],`${R[1]}${wn(P)}${R[3]}`))}await Cl({projectId:e,label:`Add ${E?"block":"component"}: ${w.title}`,kind:"timeline",files:{[k]:D},readFile:async()=>$,writeFile:f,recordEdit:h})}return await g(),O(),{block:w,compositionPath:A}}catch(b){const S=b instanceof Error?b.message:"Failed to add block";return x(S),null}}const fj={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},dj="VITE_STUDIO_ENABLE_PREVIEW_MANUAL_DRAGGING",hj="VITE_STUDIO_ENABLE_INSPECTOR_PANELS",mj="VITE_STUDIO_ENABLE_MOTION_PANEL",pj=new Set(["1","true","yes","on","enabled"]),gj=new Set(["0","false","no","off","disabled"]);function Nf(t,e,n){for(const r of e){const i=t[r];if(typeof i=="boolean")return i;if(typeof i!="string")continue;const l=i.trim().toLowerCase();if(l){if(pj.has(l))return!0;if(gj.has(l))return!1}}return n}const Oj=typeof window<"u"?window.__HF_STUDIO_ENV__??{}:{},Vf={...fj??{},...Oj},xj=Nf(Vf,[dj,"VITE_STUDIO_PREVIEW_MANUAL_EDITING_ENABLED"],!0),un=Nf(Vf,[hj,"VITE_STUDIO_INSPECTOR_PANELS_ENABLED"],!0),Lg=Nf(Vf,[mj,"VITE_STUDIO_MOTION_PANEL_ENABLED"],!1),N2=Nf(Vf,["VITE_STUDIO_ENABLE_BLOCKS_PANEL","VITE_STUDIO_BLOCKS_PANEL_ENABLED"],!1),fp=un,Xx="Manual editing is temporarily disabled",WS=["position","display","top","left","right","bottom","inset","width","height","gap","justify-content","align-items","flex-direction","font-size","font-style","font-weight","font-family","line-height","letter-spacing","text-align","text-transform","color","background-color","background-image","opacity","mix-blend-mode","border-radius","border-width","border-style","border-color","border-top-width","border-top-style","border-top-color","outline-color","overflow","clip-path","box-shadow","filter","backdrop-filter","z-index","transform","object-fit","object-position"];function Kr(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&typeof t.nodeType=="number"&&t.nodeType===1}function Za(t){if(!t)return null;const e=t.trim();if(!e.endsWith("px"))return null;const n=parseFloat(e);return Number.isFinite(n)?n:null}function yj(t){const e=(t??"none").trim();if(!e||e==="none")return!0;const n=e.match(/^matrix\(([^)]+)\)$/i);if(n){const o=n[1].split(",").map(c=>Number.parseFloat(c.trim()));return o.length!==6||o.some(c=>!Number.isFinite(c))?!1:Math.abs(o[0]-1)<1e-4&&Math.abs(o[1])<1e-4&&Math.abs(o[2])<1e-4&&Math.abs(o[3]-1)<1e-4&&Math.abs(o[4])<1e-4&&Math.abs(o[5])<1e-4}const r=e.match(/^matrix3d\(([^)]+)\)$/i);if(!r)return!1;const i=r[1].split(",").map(o=>Number.parseFloat(o.trim()));if(i.length!==16||i.some(o=>!Number.isFinite(o)))return!1;const l=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];return i.every((o,c)=>Math.abs(o-l[c])<1e-4)}function bj(t){return["div","span","p","strong","h1","h2","h3","h4","h5","h6"].includes(t)}function GS(t){var r;const e={},n=(r=t.ownerDocument.defaultView)==null?void 0:r.getComputedStyle(t);if(!n)return e;for(const i of WS){const l=n.getPropertyValue(i);l&&(e[i]=l)}return e}function KS(t){const e={};for(const n of WS){const r=t.style.getPropertyValue(n);r&&(e[n]=r)}return e}function vj(t){const e={};for(const n of t.attributes)n.name.startsWith("data-")&&(e[n.name.slice(5)]=n.value);return e}function dp(t,e){let n=t;for(;n;){const r=n;if(e.some(i=>r.hasAttribute(i)))return r;n=n.parentElement}return null}function Ml(t,e){const n=dp(t,["data-composition-file","data-composition-src"]),r=dp(t,["data-composition-id"]),i=(n==null?void 0:n.getAttribute("data-composition-file"))??(n==null?void 0:n.getAttribute("data-composition-src"))??(r==null?void 0:r.getAttribute("data-composition-file"))??(r==null?void 0:r.getAttribute("data-composition-src"))??e??"index.html";return{sourceFile:i,compositionPath:i}}function zx(t){const e=t==null?void 0:t.trim();if(!e)return;let n=e;try{n=new URL(e,"http://studio.local").pathname}catch{n=e}for(const r of["/preview/comp/","/preview/"]){const i=n.indexOf(r);if(i<0)continue;return n.slice(i+r.length).replace(/^\/+/,"")||e}return e}function JS(t){const e=globalThis.CSS;if(typeof(e==null?void 0:e.escape)=="function")return e.escape(t);if(t==="-")return"\\-";let n="";for(let r=0;r<t.length;r+=1){const i=t[r]??"",l=i.charCodeAt(0);if(l===0){n+="�";continue}const o=l>=48&&l<=57,c=l>=65&&l<=90,f=l>=97&&l<=122,h=l>=1&&l<=31||l===127,g=r===0&&o,O=r===1&&t.startsWith("-")&&o;if(h||g||O){n+=`\\${l.toString(16)} `;continue}if(c||f||o||i==="-"||i==="_"||l>=128){n+=i;continue}n+=`\\${i}`}return n}function hp(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\a ").replace(/\r/g,"\\d ").replace(/\f/g,"\\c ")}function mp(t,e){try{return Array.from(t.querySelectorAll(e))}catch{return[]}}function J0(t){var e;return((e=t.replace(/\.html$/i,"").replace(/^compositions\//i,"").split("/").at(-1))==null?void 0:e.replace(/[-_]+/g," ").replace(/\b\w/g,n=>n.toUpperCase()))??t}function e7(t){if(t.id)return`#${JS(t.id)}`;const e=t.getAttribute("data-composition-id");return e?`[data-composition-id="${hp(e)}"]`:t7(t)}function t7(t){const e=Array.from(t.classList).map(r=>r.trim()).filter(Boolean);if(e.length===0)return;const n=e.find(r=>r!=="clip"&&!r.startsWith("__hf-"))??e[0];return n?`.${JS(n)}`:void 0}function n7(t,e,n,r,i){if(!(n!=null&&n.startsWith(".")))return;const o=mp(t,n).filter(c=>Kr(c)&&Ml(c,i).sourceFile===r).indexOf(e);return o>=0?o:void 0}function _g(t){const e=t.ownerDocument.defaultView;if(!e)return!0;let n=t;for(;n;){const r=e.getComputedStyle(n);if(r.display==="none"||r.visibility==="hidden")return!1;const i=Number.parseFloat(r.opacity);if(Number.isFinite(i)&&i<=.01)return!1;n=n.parentElement}return!0}const Fx=new Set(["img","video","canvas","svg","audio"]);function Sj(t){const e=t.tagName.toLowerCase();if(Fx.has(e))return!1;const{children:n}=t;if(n.length===0)return(t.textContent??"").trim().length===0;for(let r=0;r<n.length;r+=1){const i=n[r];if(Kr(i)&&(Fx.has(i.tagName.toLowerCase())||_g(i)))return!1}return!0}function wj(t){const e=t.getBoundingClientRect();return!(e.width<=1||e.height<=1||!_g(t)||Sj(t))}const Aj=new Set(["base","br","canvas","link","meta","script","source","style","template","track","wbr"]);function kj(t){var r;const e=t.tagName.toLowerCase();if(Aj.has(e))return!1;const n=(r=t.ownerDocument.defaultView)==null?void 0:r.getComputedStyle(t);return!((n==null?void 0:n.display)==="none"||(n==null?void 0:n.visibility)==="hidden")}function Lf(t,e){if(!kj(t)||t.hasAttribute("data-composition-id"))return null;const n=e7(t);if(!n)return null;const{sourceFile:r}=Ml(t,e);return{id:t.id||void 0,selector:n,selectorIndex:n7(t.ownerDocument,t,n,r,e),sourceFile:r}}function Mj(t){let e=t;for(;e;){if(e.classList.contains("clip")&&(!(e.hasAttribute("data-composition-src")||e.hasAttribute("data-composition-file"))||e===t))return e;e=e.parentElement}return null}function Tj(t,e){if(e.preferClipAncestor){const n=Mj(t);if(n)return n}return t}function Cj(t,e){const n=[];for(const i of t)Kr(i)&&wj(i)&&Lf(i,e.activeCompositionPath)&&n.push(i);if(n.length===0)return null;let r=n[0];for(let i=1;i<n.length;i++){const l=n[i];r.contains(l)&&(r=l)}return r}function Bn(t,e,n=null){if(e.id){const i=t.getElementById(e.id);if(Kr(i)&&(!e.sourceFile||Ml(i,n).sourceFile===e.sourceFile))return i}return e.selector?e.selector.startsWith(".")&&e.selectorIndex!=null?mp(t,e.selector).filter(l=>Kr(l)&&(!e.sourceFile||Ml(l,n).sourceFile===e.sourceFile))[e.selectorIndex]??null:mp(t,e.selector).filter(i=>Kr(i)&&(!e.sourceFile||Ml(i,n).sourceFile===e.sourceFile))[0]??null:null}function Ej(t,e,n){var O;const r=typeof e.id=="string"?e.id:"",i=zx(e.compositionSrc)??((O=n.compIdToSrc)==null?void 0:O.get(r)),l=i??zx(e.sourceFile)??n.activeCompositionPath??"index.html",o=hp(r),c=i?hp(i):null,f=e.selector??(i?`[data-composition-src="${c}"],[data-composition-file="${c}"],[data-composition-id="${o}"]`:o?`[data-composition-id="${o}"]`:void 0);if(f||e.domId){const x=Bn(t,{id:e.domId??void 0,selector:f,selectorIndex:e.selectorIndex,sourceFile:l},n.activeCompositionPath);if(x)return x}const h=!!(e.domId||e.selector||i);if(n.isMasterView||h||!n.activeCompositionPath)return null;const g=t.querySelector("[data-composition-id]");return Kr(g)&&Ml(g,n.activeCompositionPath).sourceFile===l?g:null}function $j(t,e){return Array.from(t.children).filter(n=>Kr(n)&&Lf(n,e.activeCompositionPath)!==null)}function V2(t){return bj(t.tagName.toLowerCase())&&t.children.length===0}function Qj(t,e,n,r){return r==="self"||n===1?"Content":`Text ${e+1}`}function L2(t,e,n,r){const i=t.tagName.toLowerCase();return{key:t.getAttribute("data-hf-text-key")??`${r}:${e}:${i}`,label:Qj(i,e,n,r),value:t.textContent??"",tagName:i,attributes:Array.from(t.attributes).filter(o=>o.name!=="style").map(o=>({name:o.name,value:o.value})),inlineStyles:KS(t),computedStyles:GS(t),source:r}}function Pj(t){const e=Array.from(t.children).filter(Kr).filter(V2);if(e.length>0){if(Array.from(t.childNodes).some(r=>{var i;return r.nodeType===3&&((i=r.textContent)==null?void 0:i.trim())})){const r=[];let i=0;for(const l of t.childNodes)if(l.nodeType===3){const o=l.textContent??"";if(!o.trim())continue;r.push({key:`text-node:${i}`,label:`Text ${i+1}`,value:o,tagName:"#text",attributes:[],inlineStyles:{},computedStyles:{},source:"text-node"}),i++}else Kr(l)&&V2(l)&&(r.push(L2(l,i,e.length,"child")),i++);return r}return e.map((r,i)=>L2(r,i,e.length,"child"))}return V2(t)?[L2(t,0,1,"self")]:[]}function Yx(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function jj(t){const e=Object.entries(t.inlineStyles).filter(([,n])=>!!n);return e.length===0?"":e.map(([n,r])=>`${n}: ${r}`).join("; ")}function Bx(t){return t.filter(e=>e.source==="child"||e.source==="text-node").map(e=>{if(e.source==="text-node")return Yx(e.value);const n=[...e.attributes.filter(l=>l.name!=="data-hf-text-key"),{name:"data-hf-text-key",value:e.key}].map(l=>` ${l.name}="${l.value.replace(/"/g,"&quot;")}"`).join(""),r=jj(e),i=r?` style="${r.replace(/"/g,"&quot;")}"`:"";return`<${e.tagName}${n}${i}>${Yx(e.value)}</${e.tagName}>`}).join("")}function Zj(t){var e,n,r,i;return{key:`child:new:${Date.now()}`,label:"Text",value:"New text",tagName:"span",attributes:[],inlineStyles:{"font-family":((e=t==null?void 0:t.computedStyles)==null?void 0:e["font-family"])??"inherit","font-size":((n=t==null?void 0:t.computedStyles)==null?void 0:n["font-size"])??"16px","font-weight":((r=t==null?void 0:t.computedStyles)==null?void 0:r["font-weight"])??"400",color:((i=t==null?void 0:t.computedStyles)==null?void 0:i.color)??"inherit"},computedStyles:{},source:"child"}}function Rj(t){if(!t.selector||t.isInsideLockedComposition)return{canSelect:!t.isInsideLockedComposition,canEditStyles:!1,canMove:!1,canResize:!1,canApplyManualOffset:!1,canApplyManualSize:!1,canApplyManualRotation:!1,reasonIfDisabled:t.isInsideLockedComposition?"This element belongs to a locked composition.":"Studio could not resolve a stable patch target for this element."};const e=t.computedStyles.position,n=Za(t.inlineStyles.left)??Za(t.computedStyles.left),r=Za(t.inlineStyles.top)??Za(t.computedStyles.top),i=Za(t.inlineStyles.width)??Za(t.computedStyles.width),l=Za(t.inlineStyles.height)??Za(t.computedStyles.height),o=!yj(t.computedStyles.transform),c=(e==="absolute"||e==="fixed")&&n!=null&&r!=null&&!o,f=c&&(i!=null||l!=null),h=!t.isCompositionHost,g=h,O=h,x=h,b=h?void 0:"Select an internal layer to transform it.";return t.isCompositionHost&&t.isMasterView?{canSelect:!0,canEditStyles:!1,canMove:c,canResize:f,canApplyManualOffset:g,canApplyManualSize:O,canApplyManualRotation:x,reasonIfDisabled:b}:{canSelect:!0,canEditStyles:!0,canMove:c,canResize:f,canApplyManualOffset:g,canApplyManualSize:O,canApplyManualRotation:x,reasonIfDisabled:b}}function r7(t){const e=t.getAttribute("data-composition-id");if(e&&e!=="main")return J0(e);const n=t.getAttribute("data-composition-src")??t.getAttribute("data-composition-file");if(n)return J0(n);if(t.id)return J0(t.id);const r=t7(t);if(r)return J0(r.replace(/^\./,""));const i=(t.textContent??"").trim().replace(/\s+/g," ");return i?i.length>40?`${i.slice(0,39)}…`:i:t.tagName.toLowerCase()}function i7(t,e){var i;if(!t)return null;const n=t.ownerDocument;let r=Tj(t,e);for(;r&&r!==n.body&&r!==n.documentElement;){const l=e7(r);if(!l){r=r.parentElement;continue}const{sourceFile:o,compositionPath:c}=Ml(r,e.activeCompositionPath),f=n7(n,r,l,o,e.activeCompositionPath),h=r.getAttribute("data-composition-src")??r.getAttribute("data-composition-file")??void 0,g=KS(r),O=GS(r),x=Pj(r),b=!!dp(r,["data-timeline-locked"]),S=Rj({selector:l,tagName:r.tagName.toLowerCase(),className:r.className,inlineStyles:g,computedStyles:O,isCompositionHost:!!h,isInsideLockedComposition:b,isMasterView:e.isMasterView}),w=r.getBoundingClientRect();return{element:r,id:r.id||void 0,selector:l,selectorIndex:f,sourceFile:o,compositionPath:c,compositionSrc:h,isCompositionHost:!!h,isInsideLockedComposition:b,label:r7(r),tagName:r.tagName.toLowerCase(),boundingBox:{x:w.left,y:w.top,width:w.width,height:w.height},textContent:((i=r.textContent)==null?void 0:i.trim())||null,dataAttributes:vj(r),inlineStyles:g,computedStyles:O,textFields:x,capabilities:S}}return null}function a7(t){const e=t.selectorIndex??0;return`${t.sourceFile}:${t.id??t.selector??"layer"}:${e}`}function Nj(t,e,n=80){if(!t)return[];const r=[],i=(l,o)=>{if(r.length>=n)return;const c=Lf(l,e.activeCompositionPath);c&&r.push({key:a7(c),element:l,label:r7(l),tagName:l.tagName.toLowerCase(),depth:o,childCount:$j(l,e).length,id:c.id??void 0,selector:c.selector??void 0,selectorIndex:c.selectorIndex,sourceFile:c.sourceFile});const f=c?o+1:o;for(const h of Array.from(l.children))if(Kr(h)&&(i(h,f),r.length>=n))return};return i(t,0),r}function e1(t,e){return{type:"inline-style",property:t,value:e}}function qx(t){return{type:"text-content",property:"text",value:t}}function Yr(t){return[t.sourceFile||"index.html",t.id??"",t.selector??"",t.selectorIndex??""].join("|")}function Dg(t){return t.textFields.length>0&&!t.isCompositionHost&&!t.isInsideLockedComposition}function Vj(t){return`x=${Math.round(t.x)}, y=${Math.round(t.y)}, width=${Math.round(t.width)}, height=${Math.round(t.height)}`}function Ix(t){return Object.entries(t).filter(([,e])=>e&&e!=="initial").map(([e,n])=>`${e}: ${n}`).join(`
85
+ `);let D=Ag($,B);const P=H+z,R=D.match(/(<[^>]*data-composition-id="[^"]*"[^>]*data-duration=")([^"]*)(")/);if(R){const X=parseFloat(R[2]);P>X&&(D=D.replace(R[0],`${R[1]}${wn(P)}${R[3]}`))}await Cl({projectId:e,label:`Add ${E?"block":"component"}: ${w.title}`,kind:"timeline",files:{[k]:D},readFile:async()=>$,writeFile:f,recordEdit:h})}return await g(),O(),{block:w,compositionPath:A}}catch(b){const S=b instanceof Error?b.message:"Failed to add block";return x(S),null}}const fj={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},dj="VITE_STUDIO_ENABLE_PREVIEW_MANUAL_DRAGGING",hj="VITE_STUDIO_ENABLE_INSPECTOR_PANELS",mj="VITE_STUDIO_ENABLE_MOTION_PANEL",pj=new Set(["1","true","yes","on","enabled"]),gj=new Set(["0","false","no","off","disabled"]);function Nf(t,e,n){for(const r of e){const i=t[r];if(typeof i=="boolean")return i;if(typeof i!="string")continue;const l=i.trim().toLowerCase();if(l){if(pj.has(l))return!0;if(gj.has(l))return!1}}return n}const Oj=typeof window<"u"?window.__HF_STUDIO_ENV__??{}:{},Vf={...fj??{},...Oj},xj=Nf(Vf,[dj,"VITE_STUDIO_PREVIEW_MANUAL_EDITING_ENABLED"],!0),un=Nf(Vf,[hj,"VITE_STUDIO_INSPECTOR_PANELS_ENABLED"],!0),Lg=Nf(Vf,[mj,"VITE_STUDIO_MOTION_PANEL_ENABLED"],!1),N2=Nf(Vf,["VITE_STUDIO_ENABLE_BLOCKS_PANEL","VITE_STUDIO_BLOCKS_PANEL_ENABLED"],!0),fp=un,Xx="Manual editing is temporarily disabled",WS=["position","display","top","left","right","bottom","inset","width","height","gap","justify-content","align-items","flex-direction","font-size","font-style","font-weight","font-family","line-height","letter-spacing","text-align","text-transform","color","background-color","background-image","opacity","mix-blend-mode","border-radius","border-width","border-style","border-color","border-top-width","border-top-style","border-top-color","outline-color","overflow","clip-path","box-shadow","filter","backdrop-filter","z-index","transform","object-fit","object-position"];function Kr(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&typeof t.nodeType=="number"&&t.nodeType===1}function Za(t){if(!t)return null;const e=t.trim();if(!e.endsWith("px"))return null;const n=parseFloat(e);return Number.isFinite(n)?n:null}function yj(t){const e=(t??"none").trim();if(!e||e==="none")return!0;const n=e.match(/^matrix\(([^)]+)\)$/i);if(n){const o=n[1].split(",").map(c=>Number.parseFloat(c.trim()));return o.length!==6||o.some(c=>!Number.isFinite(c))?!1:Math.abs(o[0]-1)<1e-4&&Math.abs(o[1])<1e-4&&Math.abs(o[2])<1e-4&&Math.abs(o[3]-1)<1e-4&&Math.abs(o[4])<1e-4&&Math.abs(o[5])<1e-4}const r=e.match(/^matrix3d\(([^)]+)\)$/i);if(!r)return!1;const i=r[1].split(",").map(o=>Number.parseFloat(o.trim()));if(i.length!==16||i.some(o=>!Number.isFinite(o)))return!1;const l=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];return i.every((o,c)=>Math.abs(o-l[c])<1e-4)}function bj(t){return["div","span","p","strong","h1","h2","h3","h4","h5","h6"].includes(t)}function GS(t){var r;const e={},n=(r=t.ownerDocument.defaultView)==null?void 0:r.getComputedStyle(t);if(!n)return e;for(const i of WS){const l=n.getPropertyValue(i);l&&(e[i]=l)}return e}function KS(t){const e={};for(const n of WS){const r=t.style.getPropertyValue(n);r&&(e[n]=r)}return e}function vj(t){const e={};for(const n of t.attributes)n.name.startsWith("data-")&&(e[n.name.slice(5)]=n.value);return e}function dp(t,e){let n=t;for(;n;){const r=n;if(e.some(i=>r.hasAttribute(i)))return r;n=n.parentElement}return null}function Ml(t,e){const n=dp(t,["data-composition-file","data-composition-src"]),r=dp(t,["data-composition-id"]),i=(n==null?void 0:n.getAttribute("data-composition-file"))??(n==null?void 0:n.getAttribute("data-composition-src"))??(r==null?void 0:r.getAttribute("data-composition-file"))??(r==null?void 0:r.getAttribute("data-composition-src"))??e??"index.html";return{sourceFile:i,compositionPath:i}}function zx(t){const e=t==null?void 0:t.trim();if(!e)return;let n=e;try{n=new URL(e,"http://studio.local").pathname}catch{n=e}for(const r of["/preview/comp/","/preview/"]){const i=n.indexOf(r);if(i<0)continue;return n.slice(i+r.length).replace(/^\/+/,"")||e}return e}function JS(t){const e=globalThis.CSS;if(typeof(e==null?void 0:e.escape)=="function")return e.escape(t);if(t==="-")return"\\-";let n="";for(let r=0;r<t.length;r+=1){const i=t[r]??"",l=i.charCodeAt(0);if(l===0){n+="�";continue}const o=l>=48&&l<=57,c=l>=65&&l<=90,f=l>=97&&l<=122,h=l>=1&&l<=31||l===127,g=r===0&&o,O=r===1&&t.startsWith("-")&&o;if(h||g||O){n+=`\\${l.toString(16)} `;continue}if(c||f||o||i==="-"||i==="_"||l>=128){n+=i;continue}n+=`\\${i}`}return n}function hp(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\a ").replace(/\r/g,"\\d ").replace(/\f/g,"\\c ")}function mp(t,e){try{return Array.from(t.querySelectorAll(e))}catch{return[]}}function J0(t){var e;return((e=t.replace(/\.html$/i,"").replace(/^compositions\//i,"").split("/").at(-1))==null?void 0:e.replace(/[-_]+/g," ").replace(/\b\w/g,n=>n.toUpperCase()))??t}function e7(t){if(t.id)return`#${JS(t.id)}`;const e=t.getAttribute("data-composition-id");return e?`[data-composition-id="${hp(e)}"]`:t7(t)}function t7(t){const e=Array.from(t.classList).map(r=>r.trim()).filter(Boolean);if(e.length===0)return;const n=e.find(r=>r!=="clip"&&!r.startsWith("__hf-"))??e[0];return n?`.${JS(n)}`:void 0}function n7(t,e,n,r,i){if(!(n!=null&&n.startsWith(".")))return;const o=mp(t,n).filter(c=>Kr(c)&&Ml(c,i).sourceFile===r).indexOf(e);return o>=0?o:void 0}function _g(t){const e=t.ownerDocument.defaultView;if(!e)return!0;let n=t;for(;n;){const r=e.getComputedStyle(n);if(r.display==="none"||r.visibility==="hidden")return!1;const i=Number.parseFloat(r.opacity);if(Number.isFinite(i)&&i<=.01)return!1;n=n.parentElement}return!0}const Fx=new Set(["img","video","canvas","svg","audio"]);function Sj(t){const e=t.tagName.toLowerCase();if(Fx.has(e))return!1;const{children:n}=t;if(n.length===0)return(t.textContent??"").trim().length===0;for(let r=0;r<n.length;r+=1){const i=n[r];if(Kr(i)&&(Fx.has(i.tagName.toLowerCase())||_g(i)))return!1}return!0}function wj(t){const e=t.getBoundingClientRect();return!(e.width<=1||e.height<=1||!_g(t)||Sj(t))}const Aj=new Set(["base","br","canvas","link","meta","script","source","style","template","track","wbr"]);function kj(t){var r;const e=t.tagName.toLowerCase();if(Aj.has(e))return!1;const n=(r=t.ownerDocument.defaultView)==null?void 0:r.getComputedStyle(t);return!((n==null?void 0:n.display)==="none"||(n==null?void 0:n.visibility)==="hidden")}function Lf(t,e){if(!kj(t)||t.hasAttribute("data-composition-id"))return null;const n=e7(t);if(!n)return null;const{sourceFile:r}=Ml(t,e);return{id:t.id||void 0,selector:n,selectorIndex:n7(t.ownerDocument,t,n,r,e),sourceFile:r}}function Mj(t){let e=t;for(;e;){if(e.classList.contains("clip")&&(!(e.hasAttribute("data-composition-src")||e.hasAttribute("data-composition-file"))||e===t))return e;e=e.parentElement}return null}function Tj(t,e){if(e.preferClipAncestor){const n=Mj(t);if(n)return n}return t}function Cj(t,e){const n=[];for(const i of t)Kr(i)&&wj(i)&&Lf(i,e.activeCompositionPath)&&n.push(i);if(n.length===0)return null;let r=n[0];for(let i=1;i<n.length;i++){const l=n[i];r.contains(l)&&(r=l)}return r}function Bn(t,e,n=null){if(e.id){const i=t.getElementById(e.id);if(Kr(i)&&(!e.sourceFile||Ml(i,n).sourceFile===e.sourceFile))return i}return e.selector?e.selector.startsWith(".")&&e.selectorIndex!=null?mp(t,e.selector).filter(l=>Kr(l)&&(!e.sourceFile||Ml(l,n).sourceFile===e.sourceFile))[e.selectorIndex]??null:mp(t,e.selector).filter(i=>Kr(i)&&(!e.sourceFile||Ml(i,n).sourceFile===e.sourceFile))[0]??null:null}function Ej(t,e,n){var O;const r=typeof e.id=="string"?e.id:"",i=zx(e.compositionSrc)??((O=n.compIdToSrc)==null?void 0:O.get(r)),l=i??zx(e.sourceFile)??n.activeCompositionPath??"index.html",o=hp(r),c=i?hp(i):null,f=e.selector??(i?`[data-composition-src="${c}"],[data-composition-file="${c}"],[data-composition-id="${o}"]`:o?`[data-composition-id="${o}"]`:void 0);if(f||e.domId){const x=Bn(t,{id:e.domId??void 0,selector:f,selectorIndex:e.selectorIndex,sourceFile:l},n.activeCompositionPath);if(x)return x}const h=!!(e.domId||e.selector||i);if(n.isMasterView||h||!n.activeCompositionPath)return null;const g=t.querySelector("[data-composition-id]");return Kr(g)&&Ml(g,n.activeCompositionPath).sourceFile===l?g:null}function $j(t,e){return Array.from(t.children).filter(n=>Kr(n)&&Lf(n,e.activeCompositionPath)!==null)}function V2(t){return bj(t.tagName.toLowerCase())&&t.children.length===0}function Qj(t,e,n,r){return r==="self"||n===1?"Content":`Text ${e+1}`}function L2(t,e,n,r){const i=t.tagName.toLowerCase();return{key:t.getAttribute("data-hf-text-key")??`${r}:${e}:${i}`,label:Qj(i,e,n,r),value:t.textContent??"",tagName:i,attributes:Array.from(t.attributes).filter(o=>o.name!=="style").map(o=>({name:o.name,value:o.value})),inlineStyles:KS(t),computedStyles:GS(t),source:r}}function Pj(t){const e=Array.from(t.children).filter(Kr).filter(V2);if(e.length>0){if(Array.from(t.childNodes).some(r=>{var i;return r.nodeType===3&&((i=r.textContent)==null?void 0:i.trim())})){const r=[];let i=0;for(const l of t.childNodes)if(l.nodeType===3){const o=l.textContent??"";if(!o.trim())continue;r.push({key:`text-node:${i}`,label:`Text ${i+1}`,value:o,tagName:"#text",attributes:[],inlineStyles:{},computedStyles:{},source:"text-node"}),i++}else Kr(l)&&V2(l)&&(r.push(L2(l,i,e.length,"child")),i++);return r}return e.map((r,i)=>L2(r,i,e.length,"child"))}return V2(t)?[L2(t,0,1,"self")]:[]}function Yx(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function jj(t){const e=Object.entries(t.inlineStyles).filter(([,n])=>!!n);return e.length===0?"":e.map(([n,r])=>`${n}: ${r}`).join("; ")}function Bx(t){return t.filter(e=>e.source==="child"||e.source==="text-node").map(e=>{if(e.source==="text-node")return Yx(e.value);const n=[...e.attributes.filter(l=>l.name!=="data-hf-text-key"),{name:"data-hf-text-key",value:e.key}].map(l=>` ${l.name}="${l.value.replace(/"/g,"&quot;")}"`).join(""),r=jj(e),i=r?` style="${r.replace(/"/g,"&quot;")}"`:"";return`<${e.tagName}${n}${i}>${Yx(e.value)}</${e.tagName}>`}).join("")}function Zj(t){var e,n,r,i;return{key:`child:new:${Date.now()}`,label:"Text",value:"New text",tagName:"span",attributes:[],inlineStyles:{"font-family":((e=t==null?void 0:t.computedStyles)==null?void 0:e["font-family"])??"inherit","font-size":((n=t==null?void 0:t.computedStyles)==null?void 0:n["font-size"])??"16px","font-weight":((r=t==null?void 0:t.computedStyles)==null?void 0:r["font-weight"])??"400",color:((i=t==null?void 0:t.computedStyles)==null?void 0:i.color)??"inherit"},computedStyles:{},source:"child"}}function Rj(t){if(!t.selector||t.isInsideLockedComposition)return{canSelect:!t.isInsideLockedComposition,canEditStyles:!1,canMove:!1,canResize:!1,canApplyManualOffset:!1,canApplyManualSize:!1,canApplyManualRotation:!1,reasonIfDisabled:t.isInsideLockedComposition?"This element belongs to a locked composition.":"Studio could not resolve a stable patch target for this element."};const e=t.computedStyles.position,n=Za(t.inlineStyles.left)??Za(t.computedStyles.left),r=Za(t.inlineStyles.top)??Za(t.computedStyles.top),i=Za(t.inlineStyles.width)??Za(t.computedStyles.width),l=Za(t.inlineStyles.height)??Za(t.computedStyles.height),o=!yj(t.computedStyles.transform),c=(e==="absolute"||e==="fixed")&&n!=null&&r!=null&&!o,f=c&&(i!=null||l!=null),h=!t.isCompositionHost,g=h,O=h,x=h,b=h?void 0:"Select an internal layer to transform it.";return t.isCompositionHost&&t.isMasterView?{canSelect:!0,canEditStyles:!1,canMove:c,canResize:f,canApplyManualOffset:g,canApplyManualSize:O,canApplyManualRotation:x,reasonIfDisabled:b}:{canSelect:!0,canEditStyles:!0,canMove:c,canResize:f,canApplyManualOffset:g,canApplyManualSize:O,canApplyManualRotation:x,reasonIfDisabled:b}}function r7(t){const e=t.getAttribute("data-composition-id");if(e&&e!=="main")return J0(e);const n=t.getAttribute("data-composition-src")??t.getAttribute("data-composition-file");if(n)return J0(n);if(t.id)return J0(t.id);const r=t7(t);if(r)return J0(r.replace(/^\./,""));const i=(t.textContent??"").trim().replace(/\s+/g," ");return i?i.length>40?`${i.slice(0,39)}…`:i:t.tagName.toLowerCase()}function i7(t,e){var i;if(!t)return null;const n=t.ownerDocument;let r=Tj(t,e);for(;r&&r!==n.body&&r!==n.documentElement;){const l=e7(r);if(!l){r=r.parentElement;continue}const{sourceFile:o,compositionPath:c}=Ml(r,e.activeCompositionPath),f=n7(n,r,l,o,e.activeCompositionPath),h=r.getAttribute("data-composition-src")??r.getAttribute("data-composition-file")??void 0,g=KS(r),O=GS(r),x=Pj(r),b=!!dp(r,["data-timeline-locked"]),S=Rj({selector:l,tagName:r.tagName.toLowerCase(),className:r.className,inlineStyles:g,computedStyles:O,isCompositionHost:!!h,isInsideLockedComposition:b,isMasterView:e.isMasterView}),w=r.getBoundingClientRect();return{element:r,id:r.id||void 0,selector:l,selectorIndex:f,sourceFile:o,compositionPath:c,compositionSrc:h,isCompositionHost:!!h,isInsideLockedComposition:b,label:r7(r),tagName:r.tagName.toLowerCase(),boundingBox:{x:w.left,y:w.top,width:w.width,height:w.height},textContent:((i=r.textContent)==null?void 0:i.trim())||null,dataAttributes:vj(r),inlineStyles:g,computedStyles:O,textFields:x,capabilities:S}}return null}function a7(t){const e=t.selectorIndex??0;return`${t.sourceFile}:${t.id??t.selector??"layer"}:${e}`}function Nj(t,e,n=80){if(!t)return[];const r=[],i=(l,o)=>{if(r.length>=n)return;const c=Lf(l,e.activeCompositionPath);c&&r.push({key:a7(c),element:l,label:r7(l),tagName:l.tagName.toLowerCase(),depth:o,childCount:$j(l,e).length,id:c.id??void 0,selector:c.selector??void 0,selectorIndex:c.selectorIndex,sourceFile:c.sourceFile});const f=c?o+1:o;for(const h of Array.from(l.children))if(Kr(h)&&(i(h,f),r.length>=n))return};return i(t,0),r}function e1(t,e){return{type:"inline-style",property:t,value:e}}function qx(t){return{type:"text-content",property:"text",value:t}}function Yr(t){return[t.sourceFile||"index.html",t.id??"",t.selector??"",t.selectorIndex??""].join("|")}function Dg(t){return t.textFields.length>0&&!t.isCompositionHost&&!t.isInsideLockedComposition}function Vj(t){return`x=${Math.round(t.x)}, y=${Math.round(t.y)}, width=${Math.round(t.width)}, height=${Math.round(t.height)}`}function Ix(t){return Object.entries(t).filter(([,e])=>e&&e!=="initial").map(([e,n])=>`${e}: ${n}`).join(`
86
86
  `)}function Lj(t){return t.map(e=>`- key=${e.key}; tag=<${e.tagName}>; source=${e.source}; text=${JSON.stringify(e.value)}`).join(`
87
87
  `)}function _j({selection:t,currentTime:e,tagSnippet:n,selectionContext:r,userInstruction:i,sourceFilePath:l}){const o=(l==null?void 0:l.trim())||t.sourceFile,c=["## HyperFrames element edit request v1","Schema version: 1","",(i==null?void 0:i.trim())||"Edit this selected HyperFrames element.","",`Composition: ${t.compositionPath}`,`Playback time: ${nn(e)}`,`Source file: ${o}`,`DOM id: ${t.id??"(none)"}`,`Selector: ${t.selector??"(none)"}`,`Selector index: ${t.selectorIndex??0}`,`Tag: <${t.tagName}>`,`Bounds: ${Vj(t.boundingBox)}`];t.textContent&&c.push(`Text: ${t.textContent}`);const f=r==null?void 0:r.trim();f&&c.push("","Selection context:",f);const h=Lj(t.textFields);h&&c.push("","Text fields:",h);const g=Ix(t.inlineStyles);g&&c.push("","Inline styles:",g);const O=Ix(t.computedStyles);return O&&c.push("","Computed styles (browser-resolved):",O),n&&c.push("","Target HTML:",n),c.push("","Guardrails:","- Make a targeted change to this element only.","- Preserve the rest of the composition and its timing.","- Do not modify other elements' data-* attributes or positioning.","- Prefer existing inline styles or existing CSS rules for this element over adding unrelated selectors."),c.join(`
88
88
  `)}function Dj({activeCompPath:t,projectDir:e,projectIdRef:n,currentTime:r,showToast:i,domEditSelectionRef:l,domEditSelection:o}){const[c,f]=d.useState(),[h,g]=d.useState(),[O,x]=d.useState(null),[b,S]=d.useState(!1),[w,A]=d.useState(!1),k=d.useRef(null),$=d.useCallback(async M=>{const j=n.current;if(!j)return;const E=M.sourceFile||t||"index.html";try{const Z=await fetch(`/api/projects/${j}/files/${encodeURIComponent(E)}`);if(!Z.ok)return;const H=(await Z.json()).content,L=typeof H=="string"?rP(H,M):void 0;f(z=>l.current!==M?z:L)}catch{}},[t,l,n]),Q=d.useCallback(()=>{o&&(f(void 0),g(void 0),x(null),$(o),A(!0))},[o,$]),C=d.useCallback(async M=>{if(!o)return;const j=o.sourceFile||t||"index.html",E=c??o.element.outerHTML,Z=_j({selection:o,currentTime:r,tagSnippet:E,selectionContext:h,userInstruction:M,sourceFilePath:rj(e,j)});if(!await eu(Z)){i("Could not copy prompt to clipboard.","error");return}A(!1),g(void 0),x(null),k.current&&clearTimeout(k.current),S(!0),k.current=setTimeout(()=>S(!1),1600)},[t,h,c,r,o,e,i]);return d.useEffect(()=>{f(void 0),g(void 0),x(null),S(!1)},[o]),d.useEffect(()=>()=>{k.current&&clearTimeout(k.current)},[]),{agentModalOpen:w,agentModalAnchorPoint:O,copiedAgentPrompt:b,agentPromptSelectionContext:h,setAgentModalOpen:A,setAgentPromptSelectionContext:g,setAgentModalAnchorPoint:x,preloadAgentPromptSnippet:$,handleAskAgent:Q,handleAgentModalSubmit:C}}function Hj(t,e,n,r,i){const l=t.getBoundingClientRect(),o=e.querySelector("[data-composition-id]")??e.documentElement??null,c=o==null?void 0:o.getBoundingClientRect(),f=(c==null?void 0:c.width)||n.innerWidth,h=(c==null?void 0:c.height)||n.innerHeight;if(!f||!h)return null;const g=l.width/f,O=l.height/h;return{x:(r-l.left)/g,y:(i-l.top)/O,viewport:{width:f,height:h}}}const Xj="__hf_studio_pointer_events_override__";function zj(t){try{const e=t.createElement("style");return e.id=Xj,e.textContent="* { pointer-events: auto !important; }",t.head.appendChild(e),e}catch{return null}}function Fj(t){try{t==null||t.remove()}catch{}}function Yj(t,e,n,r){let i=null,l=null;try{i=t.contentDocument,l=t.contentWindow}catch{return null}if(!i||!l)return null;const o=Hj(t,i,l,e,n);if(!o)return null;const c=zj(i);try{if(typeof i.elementsFromPoint=="function"){const h=Cj(i.elementsFromPoint(o.x,o.y),{activeCompositionPath:r});if(h)return h}const f=IS(i.elementFromPoint(o.x,o.y));return!f||!Lf(f,r)||!_g(f)?null:f}finally{Fj(c)}}function t1(t){return t&&(typeof t=="object"||typeof t=="function")?t:null}function _2(t,e){const n=t?Reflect.get(t,e):null;if(typeof n=="function")try{n.call(t)}catch{}}function D2(t,e){const n=t?Reflect.get(t,e):null;if(typeof n!="function")return null;try{const r=n.call(t);return typeof r=="number"&&Number.isFinite(r)?r:null}catch{return null}}function Bj(t){const e=t==null?void 0:t.contentWindow;if(!e)return null;try{const n=t1(Reflect.get(e,"__player")),r=D2(n,"getTime");if(typeof(n?Reflect.get(n,"pause"):null)=="function")return _2(n,"pause"),r;let l=null;const o=t1(Reflect.get(e,"__timeline"));l=l??D2(o,"time"),_2(o,"pause");const c=t1(Reflect.get(e,"__timelines"));if(c)for(const f of Object.values(c)){const h=t1(f);l=l??D2(h,"time"),_2(h,"pause")}return l}catch{return null}}function vl(t,e){return t===e?!0:!t||!e?!1:Yr(t)===Yr(e)}function _c(t,e){return e?t.some(n=>vl(n,e)):!1}function qj(t,e){return _c(t,e)?t.filter(n=>!vl(n,e)):[...t,e]}function Ij(t,e){let n=!1;const r=t.map(i=>vl(i,e)?(n=!0,e):i);return n?r:[...t,e]}function Uj(t,e){return!e||_c(t,e)?t:[e,...t]}function Wj({projectId:t,activeCompPath:e,isMasterView:n,compIdToSrc:r,captionEditMode:i,previewIframeRef:l,timelineElements:o,setSelectedTimelineElementId:c,setRightCollapsed:f,setRightPanelTab:h,previewIframe:g,refreshKey:O,rightPanelTab:x}){const[b,S]=d.useState(null),[w,A]=d.useState([]),[k,$]=d.useState(null),Q=d.useRef(b),C=d.useRef(w),M=d.useRef(k);Q.current=b,C.current=w,M.current=k;const j=d.useCallback((W,V)=>{if(!W){Q.current=null,C.current=[],S(null),A([]),c(null);return}if(!un){Q.current=null,C.current=[],S(null),A([]),c(null);return}const G=!!(V!=null&&V.additive),q=Q.current,B=C.current,D=G?Uj(B,q):B,P=_c(D,W),R=V!=null&&V.preserveGroup?Ij(D,W):G?qj(D,W):[W],X=V!=null&&V.preserveGroup?W:G&&P?vl(q,W)?R[0]??null:_c(R,q)?q:R[0]??null:W;if(Q.current=X,C.current=R,S(X),A(R),X){(V==null?void 0:V.revealPanel)!==!1&&(f(!1),x!=="layers"&&h("design"));const Y=cp(X,o);c(Y);return}c(null)},[c,o,f,h,x]),E=d.useCallback(()=>{j(null,{revealPanel:!1})},[j]),Z=d.useCallback((W,V)=>i7(W,{activeCompositionPath:e,isMasterView:n,preferClipAncestor:V==null?void 0:V.preferClipAncestor}),[e,n]),_=d.useCallback((W,V,G)=>{const q=l.current;if(!q||i)return null;const B=Yj(q,W,V,e);return B?Z(B,{preferClipAncestor:G==null?void 0:G.preferClipAncestor}):null},[e,Z,i,l]),H=d.useCallback(W=>{vl(M.current,W)||(M.current=W,$(W))},[]),L=d.useCallback(W=>{const V=l.current;let G=null;try{G=(V==null?void 0:V.contentDocument)??null}catch{return null}if(!G)return null;const q=Ej(G,W,{activeCompositionPath:e,compIdToSrc:r,isMasterView:n});return q?Z(q,{preferClipAncestor:!1}):null},[e,Z,r,n,l]),z=d.useCallback(W=>{if(!un)return;if(!W){j(null,{revealPanel:!1});return}const V=L(W);V&&j(V)},[j,L]),F=d.useCallback(W=>{const V=l.current;let G=null;try{G=(V==null?void 0:V.contentDocument)??null}catch{return}if(!G)return;const q=Bn(G,W,e);if(!q)return;const B=Z(q);B&&j(B,{revealPanel:!1,preserveGroup:!0})},[e,j,Z,l]),K=d.useCallback(W=>{const V=l.current;let G=null;try{G=(V==null?void 0:V.contentDocument)??null}catch{return}if(!G)return;const q=[];for(const P of W){const R=Bn(G,P,e);if(!R)continue;const X=Z(R);X&&q.push(X)}if(q.length===0)return;const B=Q.current,D=q.find(P=>vl(P,B))??q[0]??null;Q.current=D,C.current=q,S(D),A(q),c(D?cp(D,o):null)},[e,Z,c,o,l]);return d.useEffect(()=>{i&&H(null)},[i,H]),d.useEffect(()=>{H(null)},[e,t,g,O,H]),d.useEffect(()=>{if(!k)return;const W=vl(k,b),V=_c(w,k);!W&&!V||H(null)},[w,k,b,H]),d.useEffect(()=>{k&&(k.element.isConnected||H(null))},[k,H]),d.useEffect(()=>{i&&j(null,{revealPanel:!1})},[j,i]),d.useEffect(()=>{un||(H(null),j(null,{revealPanel:!1}),x!=="renders"&&h("renders"))},[j,x,H,h]),{domEditSelection:b,domEditGroupSelections:w,domEditHoverSelection:k,domEditSelectionRef:Q,domEditGroupSelectionsRef:C,domEditHoverSelectionRef:M,setDomEditSelection:S,setDomEditGroupSelections:A,applyDomSelection:j,clearDomSelection:E,buildDomSelectionFromTarget:Z,resolveDomSelectionFromPreviewPoint:_,updateDomEditHoverSelection:H,buildDomSelectionForTimelineElement:L,handleTimelineElementSelect:z,refreshDomEditSelectionFromPreview:F,refreshDomEditGroupSelectionsFromPreview:K}}function Gj({captionEditMode:t,compositionLoading:e,previewIframeRef:n,showToast:r,applyDomSelection:i,resolveDomSelectionFromPreviewPoint:l,updateDomEditHoverSelection:o,onClickToSource:c}){const f=d.useCallback((b,S)=>{if(!fp||t||e)return;const w=l(b.clientX,b.clientY,{preferClipAncestor:(S==null?void 0:S.preferClipAncestor)??!1});if(!w){b.shiftKey||i(null,{revealPanel:!1});return}b.preventDefault(),b.stopPropagation(),i(w,{additive:b.shiftKey}),!b.shiftKey&&b.altKey&&c&&c(w)},[i,t,e,c,l]),h=d.useCallback((b,S)=>{if(!fp||t||e)return o(null),null;const w=l(b.clientX,b.clientY,{preferClipAncestor:(S==null?void 0:S.preferClipAncestor)??!1});return o(w),w},[t,e,l,o]),g=d.useCallback(()=>{o(null)},[o]),O=d.useCallback(b=>{r(b.capabilities.reasonIfDisabled??"This element can't be adjusted directly from the preview.","info")},[r]),x=d.useCallback(()=>{const b=Bj(n.current),S=ge.getState();S.setIsPlaying(!1),b!=null&&(S.setCurrentTime(b),Pr.notify(b))},[n]);return{handlePreviewCanvasMouseDown:f,handlePreviewCanvasPointerMove:h,handlePreviewCanvasPointerLeave:g,handleBlockedDomMove:O,handleDomManualDragStart:x}}const Ux=["ABeeZee","Abel","Abril Fatface","Alegreya","Alegreya Sans","Anton","Archivo","Archivo Black","Arimo","Assistant","Barlow","Barlow Condensed","Bebas Neue","Bitter","Bricolage Grotesque","Cabin","Cardo","Catamaran","Caveat","Chivo","Cormorant Garamond","Crimson Text","Dancing Script","DM Sans","DM Serif Display","Domine","EB Garamond","Exo 2","Figtree","Fira Code","Fira Sans","Fraunces","Fredoka","IBM Plex Mono","IBM Plex Sans","IBM Plex Serif","Inconsolata","Instrument Sans","Instrument Serif","Inter","JetBrains Mono","Josefin Sans","Jost","Kanit","Karla","Lato","League Gothic","Lexend","Libre Baskerville","Libre Franklin","Lora","Manrope","Merriweather","Montserrat","Mukta","Mulish","Newsreader","Noto Sans","Noto Sans JP","Noto Serif","Nunito","Nunito Sans","Open Sans","Oswald","Outfit","Overpass","Pacifico","Pathway Extreme","Permanent Marker","Playfair Display","Plus Jakarta Sans","Poppins","Prata","PT Sans","PT Serif","Public Sans","Quicksand","Raleway","Red Hat Display","Roboto","Roboto Condensed","Roboto Mono","Roboto Serif","Rubik","Schibsted Grotesk","Signika","Source Code Pro","Source Sans 3","Source Serif 4","Space Grotesk","Space Mono","Spectral","Sora","Syne","Teko","Titillium Web","Ubuntu","Ubuntu Mono","Unbounded","Urbanist","Varela Round","Work Sans","Young Serif","Zilla Slab"],pp=["TT Norms Pro","SF Pro Display","SF Pro Text","Avenir","Avenir Next","Helvetica Neue","Arial","Georgia","Times New Roman","Menlo","Monaco","Courier New"];function l7(t){return`https://fonts.googleapis.com/css2?family=${encodeURIComponent(t.trim()).replace(/%20/g,"+")}:wght@300;400;500;600;700;800;900&display=swap`}const Kj=new Set(["inherit","initial","revert","revert-layer","serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-sans-serif","ui-serif","ui-monospace","ui-rounded","emoji","math","fangsong"]);function Jj(t){return(t.split(",")[0]??"").trim().replace(/^["']|["']$/g,"")}function eZ(t){var e;return((e=t.split(",")[0])==null?void 0:e.trim().replace(/^["']|["']$/g,"").trim())??""}function Wx(t,e){const n=Jj(e);if(!n||Kj.has(n.toLowerCase()))return;const r=`studio-preview-google-font-${n.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;if(t.getElementById(r))return;const i=t.createElement("link");i.id=r,i.rel="stylesheet",i.href=l7(n),t.head.appendChild(i)}function Gx(t,e){const n=`studio-imported-font-${e.family.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`;if(t.getElementById(n))return;const r=t.createElement("style");r.id=n,r.textContent=Mg(e),t.head.appendChild(r)}function Kx(t,e,n){const r=Mg(e,tj(n,e.path));if(t.includes(r))return t;const l=/<style\b[^>]*data-hf-studio-fonts=(["'])true\1[^>]*>([\s\S]*?)<\/style>/i.exec(t);if(l){const c=`${l[2].trim()}
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
6
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
7
  <title>HyperFrames Studio</title>
8
- <script type="module" crossorigin src="/assets/index-CSG9kRJg.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-D1edGAWj.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-SKRp8mGz.css">
10
10
  </head>
11
11
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperframes",
3
- "version": "0.6.33",
3
+ "version": "0.6.34",
4
4
  "description": "HyperFrames CLI — create, preview, and render HTML video compositions",
5
5
  "repository": {
6
6
  "type": "git",