hyperframes 0.6.9 → 0.6.10

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.9" : "0.0.0-dev";
57
+ VERSION = true ? "0.6.10" : "0.0.0-dev";
58
58
  }
59
59
  });
60
60
 
@@ -26298,35 +26298,80 @@ var init_htmlDocument = __esm({
26298
26298
  // ../core/src/studio-api/helpers/subComposition.ts
26299
26299
  import { existsSync as existsSync11, readFileSync as readFileSync11 } from "fs";
26300
26300
  import { join as join14 } from "path";
26301
- function buildSubCompositionHtml(projectDir, compPath, runtimeUrl, baseHref) {
26302
- const compFile = join14(projectDir, compPath);
26303
- if (!existsSync11(compFile)) return null;
26304
- const rawComp = readFileSync11(compFile, "utf-8");
26305
- const templateMatch = rawComp.match(/<template[^>]*>([\s\S]*)<\/template>/i);
26306
- const content = templateMatch?.[1] ?? rawComp;
26307
- const { document: contentDoc } = parseHTML(
26308
- `<!DOCTYPE html><html><head></head><body>${content}</body></html>`
26309
- );
26301
+ function isFullHtmlDocument(html) {
26302
+ return /^\s*(?:<!doctype\s|<html[\s>])/i.test(html);
26303
+ }
26304
+ function rewriteRelativePaths(root, compPath) {
26310
26305
  rewriteAssetPaths(
26311
- contentDoc.querySelectorAll("[src], [href]"),
26306
+ root.querySelectorAll("[src], [href]"),
26312
26307
  compPath,
26313
26308
  (el, attr) => el.getAttribute(attr),
26314
- (el, attr, value) => {
26315
- el.setAttribute(attr, value);
26316
- }
26309
+ (el, attr, value) => el.setAttribute(attr, value)
26317
26310
  );
26318
26311
  rewriteInlineStyleAssetUrls(
26319
- contentDoc.querySelectorAll("[style]"),
26312
+ root.querySelectorAll("[style]"),
26320
26313
  compPath,
26321
26314
  (el) => el.getAttribute("style"),
26322
- (el, value) => {
26323
- el.setAttribute("style", value);
26324
- }
26315
+ (el, value) => el.setAttribute("style", value)
26325
26316
  );
26326
- for (const styleEl of contentDoc.querySelectorAll("style")) {
26317
+ for (const styleEl of root.querySelectorAll("style")) {
26327
26318
  styleEl.textContent = rewriteCssAssetUrls(styleEl.textContent || "", compPath);
26328
26319
  }
26329
- const rewrittenContent = contentDoc.body.innerHTML || content;
26320
+ }
26321
+ function extractFullDocumentParts(rawHtml, compPath) {
26322
+ const { document: doc } = parseHTML(rawHtml);
26323
+ const rewriteTargets = [doc.head, doc.body].filter(Boolean);
26324
+ for (const target of rewriteTargets) {
26325
+ rewriteRelativePaths(target, compPath);
26326
+ }
26327
+ const headContent = doc.head?.innerHTML ?? "";
26328
+ const bodyContent = doc.body?.innerHTML ?? "";
26329
+ const htmlEl = doc.documentElement;
26330
+ const htmlAttrs = extractElementAttrs(htmlEl);
26331
+ const bodyAttrs = doc.body ? extractElementAttrs(doc.body) : "";
26332
+ return { headContent, bodyContent, htmlAttrs, bodyAttrs };
26333
+ }
26334
+ function extractElementAttrs(el) {
26335
+ const parts = [];
26336
+ for (let i2 = 0; i2 < el.attributes.length; i2++) {
26337
+ const attr = el.attributes[i2];
26338
+ if (attr.value === "") {
26339
+ parts.push(attr.name);
26340
+ } else {
26341
+ parts.push(`${attr.name}="${attr.value}"`);
26342
+ }
26343
+ }
26344
+ return parts.join(" ");
26345
+ }
26346
+ function buildSubCompositionHtml(projectDir, compPath, runtimeUrl, baseHref) {
26347
+ const compFile = join14(projectDir, compPath);
26348
+ if (!existsSync11(compFile)) return null;
26349
+ const rawComp = readFileSync11(compFile, "utf-8");
26350
+ let compHeadContent = "";
26351
+ let rewrittenContent;
26352
+ let htmlAttrs = "";
26353
+ let bodyAttrs = "";
26354
+ const templateMatch = rawComp.match(/<template[^>]*>([\s\S]*)<\/template>/i);
26355
+ if (templateMatch) {
26356
+ const content = templateMatch[1];
26357
+ const { document: contentDoc } = parseHTML(
26358
+ `<!DOCTYPE html><html><head></head><body>${content}</body></html>`
26359
+ );
26360
+ rewriteRelativePaths(contentDoc, compPath);
26361
+ rewrittenContent = contentDoc.body.innerHTML || content;
26362
+ } else if (isFullHtmlDocument(rawComp)) {
26363
+ const parts = extractFullDocumentParts(rawComp, compPath);
26364
+ compHeadContent = parts.headContent;
26365
+ rewrittenContent = parts.bodyContent;
26366
+ htmlAttrs = parts.htmlAttrs;
26367
+ bodyAttrs = parts.bodyAttrs;
26368
+ } else {
26369
+ const { document: contentDoc } = parseHTML(
26370
+ `<!DOCTYPE html><html><head></head><body>${rawComp}</body></html>`
26371
+ );
26372
+ rewriteRelativePaths(contentDoc, compPath);
26373
+ rewrittenContent = contentDoc.body.innerHTML || rawComp;
26374
+ }
26330
26375
  const indexPath = join14(projectDir, "index.html");
26331
26376
  let headContent = "";
26332
26377
  if (existsSync11(indexPath)) {
@@ -26338,6 +26383,8 @@ function buildSubCompositionHtml(projectDir, compPath, runtimeUrl, baseHref) {
26338
26383
  headContent = `<base href="${baseHref}">
26339
26384
  ${headContent}`;
26340
26385
  }
26386
+ if (compHeadContent) headContent += `
26387
+ ${compHeadContent}`;
26341
26388
  if (!headContent.includes("hyperframe.runtime") && !headContent.includes("hyperframes-preview-runtime")) {
26342
26389
  headContent += `
26343
26390
  <script data-hyperframes-preview-runtime="1" src="${runtimeUrl}"></script>`;
@@ -26346,12 +26393,14 @@ ${headContent}`;
26346
26393
  headContent += `
26347
26394
  <script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>`;
26348
26395
  }
26396
+ const htmlOpen = htmlAttrs ? `<html ${htmlAttrs}>` : "<html>";
26397
+ const bodyOpen = bodyAttrs ? `<body ${bodyAttrs}>` : "<body>";
26349
26398
  return `<!DOCTYPE html>
26350
- <html>
26399
+ ${htmlOpen}
26351
26400
  <head>
26352
26401
  ${headContent}
26353
26402
  </head>
26354
- <body>
26403
+ ${bodyOpen}
26355
26404
  <script>window.__timelines=window.__timelines||{};</script>
26356
26405
  ${rewrittenContent}
26357
26406
  </body>
@@ -77,7 +77,7 @@ ${m.join(`
77
77
 
78
78
  </body>
79
79
  </html>
80
- `);const ue=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`,{method:"POST",headers:{"Content-Type":"text/plain"},body:te});if(ue.ok)await H(),M(K);else{const me=await ue.json().catch(()=>({error:"unknown"}));console.error(`Create file failed: ${me.error}`)}},[H,M]),X=h.useCallback(async K=>{const ee=A.current;if(!ee)return;const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K+"/.gitkeep")}`,{method:"POST",headers:{"Content-Type":"text/plain"},body:""});if(te.ok)await H();else{const ue=await te.json().catch(()=>({error:"unknown"}));console.error(`Create folder failed: ${ue.error}`)}},[H]),V=h.useCallback(async K=>{const ee=A.current;if(!ee)return;const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`,{method:"DELETE"});if(te.ok)w.current===K&&o(null),await H();else{const ue=await te.json().catch(()=>({error:"unknown"}));console.error(`Delete failed: ${ue.error}`)}},[H]),F=h.useCallback(async(K,ee)=>{const te=A.current;if(!te)return;const ue=await fetch(`/api/projects/${te}/files/${encodeURIComponent(K)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({newPath:ee})});if(ue.ok)w.current===K&&M(ee),await H(),i(me=>me+1);else{const me=await ue.json().catch(()=>({error:"unknown"}));console.error(`Rename failed: ${me.error}`)}},[H,M,i]),D=h.useCallback(async K=>{const ee=A.current;if(!ee)return;const te=await fetch(`/api/projects/${ee}/duplicate-file`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:K})});if(te.ok){const ue=await te.json();await H(),ue.path&&M(ue.path)}else{const ue=await te.json().catch(()=>({error:"unknown"}));console.error(`Duplicate failed: ${ue.error}`)}},[H,M]),B=F,I=h.useCallback(async(K,ee)=>U(Array.from(K),ee),[U]),Z=h.useCallback(async K=>{const ee=await U(Array.from(K).filter(me=>v1.test(me.name)),"assets/fonts"),te=A.current,ue=ee.filter(me=>v1.test(me)).map(me=>({family:Ks(me),path:me,url:`/api/projects/${te}/preview/${me}`}));return Q.current=[...ue,...Q.current.filter(me=>!ue.some(oe=>oe.family.toLowerCase()===me.family.toLowerCase()))],ue},[U]),R=h.useMemo(()=>m.filter(K=>K==="index.html"||K.startsWith("compositions/")),[m]),Y=h.useMemo(()=>m.filter(K=>!K.endsWith(".html")&&!K.endsWith(".md")&&!K.endsWith(".json")),[m]),W=h.useMemo(()=>Y.filter(K=>v1.test(K)).map(K=>({family:Ks(K),path:K,url:`/api/projects/${t}/preview/${K}`})),[Y,t]);return{editingFile:l,setEditingFile:o,projectDir:c,fileTree:m,fileTreeLoaded:g,setFileTree:p,editingPathRef:w,projectIdRef:A,saveTimerRef:k,importedFontAssetsRef:Q,readProjectFile:E,writeProjectFile:C,readOptionalProjectFile:P,revealSourceOffset:v,openSourceForSelection:L,handleFileSelect:M,handleContentChange:j,refreshFileTree:H,uploadProjectFiles:U,handleCreateFile:re,handleCreateFolder:X,handleDeleteFile:V,handleRenameFile:F,handleDuplicateFile:D,handleMoveFile:B,handleImportFiles:I,handleImportFonts:Z,compositions:R,assets:Y,fontAssets:W}}const vr="--hf-studio-offset-x",Sr="--hf-studio-offset-y",li="--hf-studio-width",si="--hf-studio-height",wr="--hf-studio-rotation",Di="data-hf-studio-path-offset",Bc="data-hf-studio-manual-edit-gesture",Xi="data-hf-studio-box-size",zi="data-hf-studio-rotation",oi="data-hf-studio-original-translate",ci="data-hf-studio-original-inline-translate",vl="data-hf-studio-original-width",Sl="data-hf-studio-original-height",wl="data-hf-studio-original-min-width",Al="data-hf-studio-original-min-height",kl="data-hf-studio-original-max-width",Tl="data-hf-studio-original-max-height",Ml="data-hf-studio-original-flex-basis",Cl="data-hf-studio-original-flex-grow",El="data-hf-studio-original-flex-shrink",$l="data-hf-studio-original-box-sizing",jr="data-hf-studio-original-scale",Hi="data-hf-studio-original-transform-origin",Ql="data-hf-studio-original-display",ui="data-hf-studio-original-rotate",fi="data-hf-studio-original-inline-rotate",Rr="data-hf-studio-original-rotation-transform-origin",Vl="data-hf-studio-rotation-draft",gn="data-hf-studio-original-transform-display",V$="__hfStudioManualEditsApply",Em="__hfStudioManualEditsWrapped",Z0="__hfStudioManualEditsPlaybackFrame",L$="center center";function _$(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function zv(t){return Math.round(t*10)/10}function j0(t){return t.trim().replace(/\\/g,"/").replace(/^\.?\//,"")}function $m(t){if(typeof t=="string"){const n=t.trim();if(!n)return null;if(n.startsWith("{"))try{return $m(JSON.parse(n))}catch{return j0(n)}return j0(n)}if(!t||typeof t!="object")return null;const e=t;return typeof e.path=="string"?j0(e.path):typeof e.filePath=="string"?j0(e.filePath):"data"in e?$m(e.data):null}function D$(t){return $m(t)}const Qm=".hyperframes/studio-motion.json",d2="studio-motion",Pa="data-hf-studio-motion",Pl="data-hf-studio-motion-original-transform",Js="data-hf-studio-motion-original-opacity",eo="data-hf-studio-motion-original-visibility",R0=["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"],bc={x1:.215,y1:.61,x2:.355,y2:1},X$={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}},z$=/^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 r3(t,e){return Number.isFinite(t)&&t>0?t:e}function H$(t,e){return Number.isFinite(t)&&t>=0?t:e}function Y$(t){return t.trim()||"none"}function vc(t){return Math.round(t*1e3)/1e3}function N0(t,e,n,r){return Number.isFinite(t)?Math.min(n,Math.max(e,t)):r}function V0(t){const e=vc(t);return Object.is(e,-0)?"0":`${e}`}function Pm(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function Gp(t){return{x1:vc(N0(t.x1??bc.x1,0,1,.215)),y1:vc(N0(t.y1??bc.y1,-.6,1.6,.61)),x2:vc(N0(t.x2??bc.x2,0,1,.355)),y2:vc(N0(t.y2??bc.y2,-.6,1.6,1))}}function i3(t){if(!t)return null;const e=t.trim().match(z$);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)?Gp(n):null}function Hv(t){const e=Gp(t);return`M0,0 C${V0(e.x1)},${V0(e.y1)} ${V0(e.x2)},${V0(e.y2)} 1,1`}function Yv(t){return X$[t]??bc}function B$(t,e){const n=H$(e.start,0),r=r3(e.duration,.6),i=r3(e.distance,32),l=Y$(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,m=o==="down"?-i:o==="up"?i:0;return{...c,from:{x:f,y:m,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 a3(t){if(!t||typeof t!="object")return null;const e=t,n={};for(const r of["x","y","scale","rotation","opacity","autoAlpha"]){const i=Pm(e[r]);i!=null&&(n[r]=i)}return Object.keys(n).length>0?n:null}function F$(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 Bv(t){const e=t.getAttribute(Pa);if(!e||e==="true")return null;try{const n=JSON.parse(e);if(!n||typeof n!="object")return null;const r=n,i=Pm(r.start),l=Pm(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=a3(r.from),f=a3(r.to);return!c||!f?null:{start:i,duration:l,ease:o,customEase:F$(r.customEase),from:c,to:f}}catch{return null}}function q$(t,e){t.getAttribute(Pl)||(t.setAttribute(Pl,t.style.transform),t.setAttribute(Js,t.style.opacity),t.setAttribute(eo,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(Pa,JSON.stringify(n))}function U$(t,e){var n;t.hasAttribute(Pa)&&((n=e==null?void 0:e.set)==null||n.call(e,t,{clearProps:"transform,opacity,visibility"}),t.style.transform=t.getAttribute(Pl)??"",t.style.opacity=t.getAttribute(Js)??"",t.style.visibility=t.getAttribute(eo)??"",t.removeAttribute(Pa),t.removeAttribute(Pl),t.removeAttribute(Js),t.removeAttribute(eo))}function I$(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 Zm(t,e){var m,p,g,x,v,S;const n=t.defaultView;if(!n)return 0;const r=n.gsap;n.__timelines=n.__timelines??{},(p=(m=n.__timelines[d2])==null?void 0:m.kill)==null||p.call(m),delete n.__timelines[d2];const i=(g=t.defaultView)==null?void 0:g.HTMLElement;if(!i)return 0;const l=[];for(const w of Array.from(t.querySelectorAll(`[${Pa}]`))){if(!(w instanceof i))continue;const A=Bv(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},$=W$(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[d2]=o,(v=o.pause)==null||v.call(o);const f=I$(n);return o.totalTime?o.totalTime(f,!1):(S=o.time)==null||S.call(o,f),c}function W$(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}}function G$(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(li),studioHeight:t.style.getPropertyValue(si),marker:t.getAttribute(Xi),originalWidth:t.getAttribute(vl),originalHeight:t.getAttribute(Sl),originalMinWidth:t.getAttribute(wl),originalMinHeight:t.getAttribute(Al),originalMaxWidth:t.getAttribute(kl),originalMaxHeight:t.getAttribute(Tl),originalFlexBasis:t.getAttribute(Ml),originalFlexGrow:t.getAttribute(Cl),originalFlexShrink:t.getAttribute(El),originalBoxSizing:t.getAttribute($l),originalScale:t.getAttribute(jr),originalTransformOrigin:t.getAttribute(Hi),originalDisplay:t.getAttribute(Ql)}}function K$(t){return{rotate:t.style.getPropertyValue("rotate"),transformOrigin:t.style.getPropertyValue("transform-origin"),studioRotation:t.style.getPropertyValue(wr),marker:t.getAttribute(zi),draftMarker:t.getAttribute(Vl),originalRotate:t.getAttribute(ui),originalInlineRotate:t.getAttribute(fi),originalTransformOrigin:t.getAttribute(Rr)}}function Kp(t){return{translate:t.style.getPropertyValue("translate"),x:t.style.getPropertyValue(vr),y:t.style.getPropertyValue(Sr),marker:t.getAttribute(Di),originalTranslate:t.getAttribute(oi),originalInlineTranslate:t.getAttribute(ci)}}function Qt(t,e,n){n==null?t.removeAttribute(e):t.setAttribute(e,n)}function Gt(t,e,n){n?t.style.setProperty(e,n):t.style.removeProperty(e)}function m2(t,e){Gt(t,"width",e.width),Gt(t,"height",e.height),Gt(t,"min-width",e.minWidth),Gt(t,"min-height",e.minHeight),Gt(t,"max-width",e.maxWidth),Gt(t,"max-height",e.maxHeight),Gt(t,"flex-basis",e.flexBasis),Gt(t,"flex-grow",e.flexGrow),Gt(t,"flex-shrink",e.flexShrink),Gt(t,"box-sizing",e.boxSizing),Gt(t,"scale",e.scale),Gt(t,"transform-origin",e.transformOrigin),Gt(t,"display",e.display),Gt(t,li,e.studioWidth),Gt(t,si,e.studioHeight),Qt(t,Xi,e.marker),Qt(t,vl,e.originalWidth),Qt(t,Sl,e.originalHeight),Qt(t,wl,e.originalMinWidth),Qt(t,Al,e.originalMinHeight),Qt(t,kl,e.originalMaxWidth),Qt(t,Tl,e.originalMaxHeight),Qt(t,Ml,e.originalFlexBasis),Qt(t,Cl,e.originalFlexGrow),Qt(t,El,e.originalFlexShrink),Qt(t,$l,e.originalBoxSizing),Qt(t,jr,e.originalScale),Qt(t,Hi,e.originalTransformOrigin),Qt(t,Ql,e.originalDisplay)}function p2(t,e){Gt(t,"rotate",e.rotate),Gt(t,"transform-origin",e.transformOrigin),Gt(t,wr,e.studioRotation),Qt(t,zi,e.marker),Qt(t,Vl,e.draftMarker),Qt(t,ui,e.originalRotate),Qt(t,fi,e.originalInlineRotate),Qt(t,Rr,e.originalTransformOrigin)}function hl(t,e){e.translate?t.style.setProperty("translate",e.translate):t.style.removeProperty("translate"),e.x?t.style.setProperty(vr,e.x):t.style.removeProperty(vr),e.y?t.style.setProperty(Sr,e.y):t.style.removeProperty(Sr),Qt(t,Di,e.marker),Qt(t,oi,e.originalTranslate),Qt(t,ci,e.originalInlineTranslate)}function In(t,e,n){const r=t.getAttribute(n);r==null||r===""?t.style.removeProperty(e):t.style.setProperty(e,r),t.removeAttribute(n)}function J$(t){const e=t.getAttribute(fi);e==null||e===""?t.style.removeProperty("rotate"):t.style.setProperty("rotate",e),t.removeAttribute(fi),t.removeAttribute(ui);const n=t.getAttribute(Rr);n!=null&&(n===""?t.style.removeProperty("transform-origin"):t.style.setProperty("transform-origin",n)),t.removeAttribute(Rr)}function eQ(t){const e=t.getAttribute(ci);e==null||e===""?t.style.removeProperty("translate"):t.style.setProperty("translate",e),t.removeAttribute(ci),t.removeAttribute(oi)}function tQ(t){(t.hasAttribute(Di)||Nm(t.style.getPropertyValue("translate")))&&eQ(t),eg(t),t.style.removeProperty(vr),t.style.removeProperty(Sr),t.removeAttribute(Di),t.removeAttribute(oi),t.removeAttribute(ci)}function nQ(t){(t.hasAttribute(zi)||Vm(t.style.getPropertyValue("rotate")))&&J$(t),eg(t),t.style.removeProperty(wr),t.removeAttribute(zi),t.removeAttribute(Vl),t.removeAttribute(ui),t.removeAttribute(fi),t.removeAttribute(Rr)}function rQ(t){(t.hasAttribute(Xi)||s3(t.style.getPropertyValue("width"))||s3(t.style.getPropertyValue("height"))||t.hasAttribute(jr))&&(In(t,"width",vl),In(t,"height",Sl),In(t,"min-width",wl),In(t,"min-height",Al),In(t,"max-width",kl),In(t,"max-height",Tl),In(t,"flex-basis",Ml),In(t,"flex-grow",Cl),In(t,"flex-shrink",El),In(t,"box-sizing",$l),In(t,"scale",jr),In(t,"transform-origin",Hi),In(t,"display",Ql)),eg(t),t.style.removeProperty(li),t.style.removeProperty(si),t.removeAttribute(Xi)}let l3=0;function Fv(t){l3+=1;const e=`gesture-${l3}`;return t.setAttribute(Bc,e),e}function Cr(t,e){e&&t.getAttribute(Bc)!==e||t.removeAttribute(Bc)}function qv(t){return t.hasAttribute(Bc)}function L0(t,e){return t.getAttribute(Bc)===e}function L1(t,e){const n=Number.parseFloat(t.style.getPropertyValue(e));return Number.isFinite(n)?n:0}function jm(t){return{x:L1(t,vr),y:L1(t,Sr)}}function _1(t){return{width:L1(t,li),height:L1(t,si)}}function Uv(t){const e=Number.parseFloat(t.style.getPropertyValue(wr));return{angle:Number.isFinite(e)?e:0}}function Jp(t,e){var n;try{return((n=t.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(t).getPropertyValue(e))??""}catch{return""}}function Rm(t,e){return t.style.getPropertyValue(e)||Jp(t,e)}function Iv(t,e){const n=Rm(t,e).trim();return n==="none"?"":n}function Nm(t){return t.includes(vr)||t.includes(Sr)}function s3(t){return t.includes(li)||t.includes(si)}function Vm(t){return t.includes(wr)}function o3(t){return t.replace(/\s+/g,"").toLowerCase()}function iQ(t,e){if(!t.hasAttribute(Vl))return!1;const n=t.style.getPropertyValue(wr).trim();return!n||!e.trim()?!1:o3(e)===o3(ng(t,n))}function mo(t){Jp(t,"display")==="inline"&&(t.hasAttribute(gn)||t.setAttribute(gn,t.style.getPropertyValue("display")),t.style.setProperty("display","inline-block"))}function eg(t){const e=t.getAttribute(gn);e!=null&&(e===""?t.style.removeProperty("display"):t.style.setProperty("display",e),t.removeAttribute(gn))}function aQ(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 Wv(t,e,n){var l;const r=(l=t.getAttribute(oi))==null?void 0:l.trim();if(!r||r==="none")return`${e} ${n}`;const i=aQ(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 lQ(t,e){const n=t.style.getPropertyValue("translate"),r=Iv(t,"translate"),i=t.hasAttribute(Di),l=!Nm(r);i?e&&l&&!qv(t)&&t.setAttribute(oi,r):(t.setAttribute(ci,Nm(n)?"":n),t.setAttribute(oi,l?r:""))}function Gv(t,e,n={}){lQ(t,n.updateBase??!0),t.setAttribute(Di,"true"),t.style.setProperty(vr,`${Math.round(e.x)}px`),t.style.setProperty(Sr,`${Math.round(e.y)}px`)}function Kv(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 D1(t,e,n={}){mo(t),Gv(t,e,{updateBase:n.updateBase??!0}),t.style.setProperty("translate",Wv(t,`var(${vr}, 0px)`,`var(${Sr}, 0px)`)),Kv(t)}function A1(t,e){mo(t),Gv(t,e,{updateBase:!1}),t.style.setProperty("translate",Wv(t,`${Math.round(e.x)}px`,`${Math.round(e.y)}px`)),Kv(t)}function sQ(t,e){const n=t.parentElement;if(!n)return null;const r=Rm(n,"display").trim();if(r!=="flex"&&r!=="inline-flex")return null;const i=Rm(n,"flex-direction").trim();return Math.round(Math.max(1,i.startsWith("column")?e.height:e.width))}function oQ(t){if(!t.hasAttribute(jr))return;const e=t.getAttribute(jr);e==null||e===""?t.style.removeProperty("scale"):t.style.setProperty("scale",e),t.removeAttribute(jr);const n=t.getAttribute(Hi);n==null||n===""?t.style.removeProperty("transform-origin"):t.style.setProperty("transform-origin",n),t.removeAttribute(Hi)}function cQ(t,e){t.hasAttribute(Xi)||(t.setAttribute(vl,t.style.getPropertyValue("width")),t.setAttribute(Sl,t.style.getPropertyValue("height")),t.setAttribute(wl,t.style.getPropertyValue("min-width")),t.setAttribute(Al,t.style.getPropertyValue("min-height")),t.setAttribute(kl,t.style.getPropertyValue("max-width")),t.setAttribute(Tl,t.style.getPropertyValue("max-height")),t.setAttribute(Ml,t.style.getPropertyValue("flex-basis")),t.setAttribute(Cl,t.style.getPropertyValue("flex-grow")),t.setAttribute(El,t.style.getPropertyValue("flex-shrink")),t.setAttribute($l,t.style.getPropertyValue("box-sizing")),t.setAttribute(jr,t.style.getPropertyValue("scale")),t.setAttribute(Hi,t.style.getPropertyValue("transform-origin")),t.setAttribute(Ql,t.style.getPropertyValue("display"))),t.setAttribute(Xi,"true"),t.style.setProperty(li,`${Math.round(Math.max(1,e.width))}px`),t.style.setProperty(si,`${Math.round(Math.max(1,e.height))}px`)}function Jv(t,e){cQ(t,e),oQ(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=sQ(t,e);i!=null&&(t.style.setProperty("flex-basis",`${i}px`),t.style.setProperty("flex-grow","0"),t.style.setProperty("flex-shrink","0")),Jp(t,"display")==="inline"&&t.style.setProperty("display","inline-block")}function tg(t,e){mo(t),Jv(t,e)}function uQ(t,e){mo(t),Jv(t,e)}function fQ(t){return/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|rad|turn|grad)$/.test(t.trim())}function ng(t,e){var r;const n=(r=t.getAttribute(ui))==null?void 0:r.trim();return!n||n==="none"||!fQ(n)?e:`calc(${n} + ${e})`}function hQ(t,e){const n=t.style.getPropertyValue("rotate"),r=Iv(t,"rotate"),i=t.hasAttribute(zi),l=!Vm(r)&&!iQ(t,r);i?e&&l&&!qv(t)&&t.setAttribute(ui,r):(t.setAttribute(fi,Vm(n)?"":n),t.setAttribute(ui,l?r:"")),t.hasAttribute(Rr)||t.setAttribute(Rr,t.style.getPropertyValue("transform-origin"))}function eS(t,e,n={}){hQ(t,n.updateBase??!0),t.setAttribute(zi,"true"),t.style.setProperty(wr,`${zv(e.angle)}deg`),t.style.setProperty("transform-origin",L$)}function rg(t,e){mo(t),eS(t,e),t.removeAttribute(Vl),t.style.setProperty("rotate",ng(t,`var(${wr}, 0deg)`))}function dQ(t,e){mo(t),eS(t,e,{updateBase:!1}),t.setAttribute(Vl,"true"),t.style.setProperty("rotate",ng(t,`${zv(e.angle)}deg`))}function c3(t){const e=t.style.getPropertyValue(vr),n=t.style.getPropertyValue(Sr),r=t.style.getPropertyValue("translate"),i=t.getAttribute(oi),l=t.getAttribute(ci),o=t.style.getPropertyValue("display"),c=t.getAttribute(gn),f=[];return e&&f.push({type:"inline-style",property:vr,value:e}),n&&f.push({type:"inline-style",property:Sr,value:n}),r&&f.push({type:"inline-style",property:"translate",value:r}),f.push({type:"attribute",property:Di,value:"true"}),i!==null&&f.push({type:"attribute",property:oi,value:i}),l!==null&&f.push({type:"attribute",property:ci,value:l}),o&&f.push({type:"inline-style",property:"display",value:o}),c!==null&&f.push({type:"attribute",property:gn,value:c}),f}function mQ(t){const e=t.getAttribute(ci),n=[{type:"inline-style",property:vr,value:null},{type:"inline-style",property:Sr,value:null},{type:"inline-style",property:"translate",value:e||null},{type:"attribute",property:Di,value:null},{type:"attribute",property:oi,value:null},{type:"attribute",property:ci,value:null}],r=t.getAttribute(gn);return r!==null&&(n.push({type:"inline-style",property:"display",value:r||null}),n.push({type:"attribute",property:gn,value:null})),n}function pQ(t){const e=[],n=t.style.getPropertyValue(li),r=t.style.getPropertyValue(si);n&&e.push({type:"inline-style",property:li,value:n}),r&&e.push({type:"inline-style",property:si,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"),m=t.style.getPropertyValue("max-height"),p=t.style.getPropertyValue("flex-basis"),g=t.style.getPropertyValue("flex-grow"),x=t.style.getPropertyValue("flex-shrink"),v=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}),m&&e.push({type:"inline-style",property:"max-height",value:m}),p&&e.push({type:"inline-style",property:"flex-basis",value:p}),g&&e.push({type:"inline-style",property:"flex-grow",value:g}),x&&e.push({type:"inline-style",property:"flex-shrink",value:x}),v&&e.push({type:"inline-style",property:"box-sizing",value:v}),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:Xi,value:"true"});const k=t.getAttribute(vl),$=t.getAttribute(Sl),Q=t.getAttribute(wl),E=t.getAttribute(Al),C=t.getAttribute(kl),P=t.getAttribute(Tl),M=t.getAttribute(Ml),j=t.getAttribute(Cl),_=t.getAttribute(El),z=t.getAttribute($l),L=t.getAttribute(jr),H=t.getAttribute(Hi),U=t.getAttribute(Ql),re=t.getAttribute(gn);return k!==null&&e.push({type:"attribute",property:vl,value:k}),$!==null&&e.push({type:"attribute",property:Sl,value:$}),Q!==null&&e.push({type:"attribute",property:wl,value:Q}),E!==null&&e.push({type:"attribute",property:Al,value:E}),C!==null&&e.push({type:"attribute",property:kl,value:C}),P!==null&&e.push({type:"attribute",property:Tl,value:P}),M!==null&&e.push({type:"attribute",property:Ml,value:M}),j!==null&&e.push({type:"attribute",property:Cl,value:j}),_!==null&&e.push({type:"attribute",property:El,value:_}),z!==null&&e.push({type:"attribute",property:$l,value:z}),L!==null&&e.push({type:"attribute",property:jr,value:L}),H!==null&&e.push({type:"attribute",property:Hi,value:H}),U!==null&&e.push({type:"attribute",property:Ql,value:U}),re!==null&&e.push({type:"attribute",property:gn,value:re}),e}function gQ(t){const e=[{type:"inline-style",property:li,value:null},{type:"inline-style",property:si,value:null},{type:"attribute",property:Xi,value:null}],n=[[vl,"width"],[Sl,"height"],[wl,"min-width"],[Al,"min-height"],[kl,"max-width"],[Tl,"max-height"],[Ml,"flex-basis"],[Cl,"flex-grow"],[El,"flex-shrink"],[$l,"box-sizing"],[jr,"scale"],[Hi,"transform-origin"],[Ql,"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(gn);return r!==null&&(e.push({type:"inline-style",property:"display",value:r||null}),e.push({type:"attribute",property:gn,value:null})),e}function OQ(t){const e=[],n=t.style.getPropertyValue(wr),r=t.style.getPropertyValue("rotate"),i=t.style.getPropertyValue("transform-origin"),l=t.style.getPropertyValue("display");n&&e.push({type:"inline-style",property:wr,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:zi,value:"true"});const o=t.getAttribute(ui),c=t.getAttribute(fi),f=t.getAttribute(Rr),m=t.getAttribute(gn);return o!==null&&e.push({type:"attribute",property:ui,value:o}),c!==null&&e.push({type:"attribute",property:fi,value:c}),f!==null&&e.push({type:"attribute",property:Rr,value:f}),m!==null&&e.push({type:"attribute",property:gn,value:m}),e}function yQ(t){const e=t.getAttribute(fi),n=t.getAttribute(Rr),r=[{type:"inline-style",property:wr,value:null},{type:"inline-style",property:"rotate",value:e||null},{type:"inline-style",property:"transform-origin",value:n!==null&&n||null},{type:"attribute",property:zi,value:null},{type:"attribute",property:Vl,value:null},{type:"attribute",property:ui,value:null},{type:"attribute",property:fi,value:null},{type:"attribute",property:Rr,value:null}],i=t.getAttribute(gn);return i!==null&&(r.push({type:"inline-style",property:"display",value:i||null}),r.push({type:"attribute",property:gn,value:null})),r}function xQ(t){const e=t.getAttribute(Pa);if(!e)return[];const n=[{type:"attribute",property:Pa,value:e}],r=t.getAttribute(Pl);r!==null&&n.push({type:"attribute",property:Pl,value:r});const i=t.getAttribute(Js);i!==null&&n.push({type:"attribute",property:Js,value:i});const l=t.getAttribute(eo);return l!==null&&n.push({type:"attribute",property:eo,value:l}),n}function bQ(t){return[{type:"attribute",property:Pa,value:null},{type:"attribute",property:Pl,value:null},{type:"attribute",property:Js,value:null},{type:"attribute",property:eo,value:null}]}function vQ(t){var l;const e=(l=t.defaultView)==null?void 0:l.HTMLElement;if(!e)return;const n=Array.from(t.querySelectorAll(`[${Di}="true"]`)).filter(o=>o instanceof e);for(const o of n){const c=o.style.getPropertyValue(vr),f=o.style.getPropertyValue(Sr);(c||f)&&D1(o,{x:Number.parseFloat(c)||0,y:Number.parseFloat(f)||0})}const r=Array.from(t.querySelectorAll(`[${Xi}="true"]`)).filter(o=>o instanceof e);for(const o of r){const c=Number.parseFloat(o.style.getPropertyValue(li)),f=Number.parseFloat(o.style.getPropertyValue(si));Number.isFinite(c)&&Number.isFinite(f)&&c>0&&f>0&&tg(o,{width:c,height:f})}const i=Array.from(t.querySelectorAll(`[${zi}="true"]`)).filter(o=>o instanceof e);for(const o of i){const c=Number.parseFloat(o.style.getPropertyValue(wr));Number.isFinite(c)&&rg(o,{angle:c})}Zm(t)}function ig(t){try{Object.defineProperty(t,Em,{configurable:!1,enumerable:!1,value:!0})}catch{try{t[Em]=!0}catch{}}}function ag(t){return!!t[Em]}function uc(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(ag(i))return!0;const l=function(...o){var f;const c=i.apply(this,o);return(f=t.__hfStudioManualEditsApply)==null||f.call(t),c};ig(l);try{e[n]=l}catch{return!1}return!0}function fc(t,e){const n=t[e];if(typeof n!="function")return null;try{return _$(n.call(t))}catch{return null}}function SQ(t){const e=fc(t,"duration")??fc(t,"getDuration");if(e==null)return!0;if(e<=0)return!1;const n=fc(t,"time")??fc(t,"totalTime")??fc(t,"getTime");return n==null?!0:n<e}function g2(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 SQ(t)}const r=t.isActive;if(typeof r=="function")try{return!!r.call(t)}catch{return!1}return!1}function tS(t){return g2(t.__player)||g2(t.__timeline)?!0:Object.values(t.__timelines??{}).some(g2)}function nS(t){var n;if((n=t.__hfStudioManualEditsApply)==null||n.call(t),t[Z0]!=null)return;const e=()=>{var r;if((r=t.__hfStudioManualEditsApply)==null||r.call(t),!tS(t)){t[Z0]=null;return}t[Z0]=t.requestAnimationFrame(e)};t[Z0]=t.requestAnimationFrame(e)}function O2(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(ag(i))return!0;const l=function(...o){const c=i.apply(this,o);return nS(t),c};ig(l);try{e[n]=l}catch{return!1}return!0}function y2(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(ag(i))return!0;const l=function(...o){var f;const c=i.apply(this,o);return(f=t.__hfStudioManualEditsApply)==null||f.call(t),c};ig(l);try{e[n]=l}catch{return!1}return!0}function wQ(t,e){const n=t;n[V$]=e;const r=uc(n,n.__hf,"seek"),i=uc(n,n.__player,"seek"),l=uc(n,n.__player,"renderSeek"),o=uc(n,n.__timeline,"seek"),c=O2(n,n.__player,"play"),f=O2(n,n.__timeline,"play"),m=y2(n,n.__player,"pause"),p=y2(n,n.__timeline,"pause");let g=!1,x=!1,v=!1;for(const S of Object.values(n.__timelines??{}))g=uc(n,S,"seek")||g,x=O2(n,S,"play")||x,v=y2(n,S,"pause")||v;return tS(n)&&nS(n),r||i||l||o||c||f||m||p||g||x||v}function AQ({projectId:t,showToast:e,readOptionalProjectFile:n,writeProjectFile:r,recordEdit:i,previewIframeRef:l,activeCompPathRef:o,domEditSaveTimestampRef:c,reloadPreview:f}){const m=h.useRef(0),p=h.useRef(Promise.resolve()),g=h.useRef(async()=>{}),x=h.useRef(t);x.current=t;const v=h.useCallback($=>{const Q=p.current.catch(()=>{}).then($);return p.current=Q.then(()=>{},()=>{}),Q},[]),S=h.useCallback(async()=>{await p.current.catch(()=>{})},[]),w=h.useCallback(($=l.current)=>{var M,j,_,z,L,H;if(!$)return;let Q=null;try{Q=$.contentDocument}catch{return}if(!Q)return;const E=()=>{let U=null;try{U=$.contentDocument}catch{return}U&&vQ(U)},C=()=>{E(),$.contentWindow&&wQ($.contentWindow,E)},P=$.contentWindow;C(),(M=P==null?void 0:P.requestAnimationFrame)==null||M.call(P,C),(j=P==null?void 0:P.setTimeout)==null||j.call(P,C,80),(_=P==null?void 0:P.setTimeout)==null||_.call(P,C,250),(z=P==null?void 0:P.setTimeout)==null||z.call(P,C,500),(L=P==null?void 0:P.setTimeout)==null||L.call(P,C,1e3),(H=P==null?void 0:P.setTimeout)==null||H.call(P,C,2e3)},[l]),A=h.useCallback(async($=l.current)=>{w($)},[w,l]);g.current=A;const k=h.useCallback(async $=>{f()},[f]);return Tt(()=>{n(Qm).then($=>{if($){try{const Q=JSON.parse($);if(!Array.isArray(Q.motions)||Q.motions.length===0)return}catch{return}return r(Qm,JSON.stringify({version:1,motions:[]}))}}).catch(()=>{})}),Tt(()=>{const $=E=>{if(!D$(E))return;Date.now()-c.current<1200||f()},Q=new EventSource("/api/events");return Q.addEventListener("file-change",$),()=>Q.close()}),{domTextCommitVersionRef:m,domEditSaveQueueRef:p,applyStudioManualEditsToPreviewRef:g,queueDomEditSave:v,waitForPendingDomEditSaves:S,applyCurrentStudioManualEditsToPreview:w,applyStudioManualEditsToPreview:A,syncHistoryPreviewAfterApply:k}}function Ps(t){return t.label||t.id||t.tag}function u3(t){const e=t.trim(),n=/^[a-z]+:\/\//i.test(e)?new URL(e).pathname:e;return decodeURIComponent(n).replace(/\\/g,"/").replace(/^\.?\//,"")}function kQ(t,e){const n=u3(t).split("/").filter(Boolean),r=u3(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 TQ(t){return/^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(t)}function MQ(t,e){const n=e.trim();if(!n)return;const r=n.replace(/\\/g,"/");if(TQ(r))return r;const i=t==null?void 0:t.trim().replace(/\\/g,"/").replace(/\/+$/,"");if(i)return`${i}/${r.replace(/^\.?\//,"")}`}function x2(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 f3(t){return/^url\(/i.test(t.trim())}function CQ(t){return t==="left"||t==="top"||t==="width"||t==="height"}function rS(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 h3(t){const e=rS(t);return e?!!e.closest("input, textarea, select, [contenteditable='true'], [role='textbox'], .cm-editor"):!1}function _0(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 Lm(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 X1(t,e,n){return n<e?e:Math.min(Math.max(t,e),n)}function EQ(t){return Array.from(t.matchAll(/\bid="([^"]+)"/g),e=>e[1]??"")}const D0={image:3,video:5,audio:5};async function d3(t,e,n){if(n==="image")return D0.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(D0[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:D0[n])},{once:!0}),r.addEventListener("error",()=>c(D0[n]),{once:!0})});return r.src="",r.load(),i}function Es(t){return t.domId?{id:t.domId,selector:t.selector,selectorIndex:t.selectorIndex}:t.selector?{selector:t.selector,selectorIndex:t.selectorIndex}:null}async function X0(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 $Q({projectId:t,activeCompPath:e,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:l,domEditSaveTimestampRef:o,reloadPreview:c,uploadProjectFiles:f}){const m=h.useRef(t);m.current=t;const p=h.useRef(0),g=h.useCallback(async(k,$)=>{const Q=m.current;if(!Q)throw new Error("No active project");const E=k.sourceFile||e||"index.html",C=await X0(Q,E),P=Es(k);if(!P)throw new Error(`Timeline element ${k.id} is missing a patchable target`);const M=E,j=n.map(L=>(L.key??L.id)===(k.key??k.id)?{...L,start:$.start,track:$.track}:L).filter(L=>(L.sourceFile||e||"index.html")===M),_=u2(j.map(L=>L.track));let z=Zi(C,P,{type:"attribute",property:"start",value:sl($.start)});z=Zi(z,P,{type:"attribute",property:"track-index",value:String($.track)});for(const L of j){const H=Es(L);if(!H)continue;const U=_.get(L.track);U!=null&&(z=Zi(z,H,{type:"inline-style",property:"z-index",value:String(U)}))}if(z===C)throw new Error(`Unable to patch timeline element ${k.id} in ${E}`);o.current=Date.now(),await fl({projectId:Q,label:"Move timeline clip",kind:"timeline",files:{[E]:z},readFile:async()=>C,writeFile:i,recordEdit:l}),c()},[e,l,n,i,o,c]),x=h.useCallback(async(k,$)=>{const Q=m.current;if(!Q)throw new Error("No active project");const E=k.sourceFile||e||"index.html",C=await X0(Q,E),P=Es(k);if(!P)throw new Error(`Timeline element ${k.id} is missing a patchable target`);const M=k.playbackStartAttr==="playback-start"?"playback-start":"media-start",j=n3(C,P,"playback-start")??n3(C,P,"media-start"),_=j!=null?parseFloat(j):void 0,z=$.start-k.start,L=$.playbackStart==null&&z!==0&&Number.isFinite(_)&&_!=null?Math.max(0,_+z*Math.max(k.playbackRate??1,.1)):void 0,H=$.playbackStart??L;let U=C;if(U=Zi(U,P,{type:"attribute",property:"start",value:sl($.start)}),U=Zi(U,P,{type:"attribute",property:"duration",value:sl($.duration)}),H!=null&&(U=Zi(U,P,{type:"attribute",property:M,value:sl(H)})),U===C)throw new Error(`Unable to patch timeline element ${k.id} in ${E}`);o.current=Date.now(),await fl({projectId:Q,label:"Resize timeline clip",kind:"timeline",files:{[E]:U},readFile:async()=>C,writeFile:i,recordEdit:l}),c()},[e,l,i,o,c]),v=h.useCallback(async k=>{const $=m.current;if(!$)throw new Error("No active project");const Q=Ps(k),E=k.sourceFile||e||"index.html";try{const C=await X0($,E),P=Es(k);if(!P)throw new Error(`Timeline element ${k.id} is missing a patchable target`);const M=E||"index.html",j=n.filter(U=>(U.key??U.id)!==(k.key??k.id)&&(U.sourceFile||e||"index.html")===M),_=u2(j.map(U=>U.track)),z=await fetch(`/api/projects/${$}/file-mutations/remove-element/${encodeURIComponent(E)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:P})});if(!z.ok)throw new Error(`Failed to delete ${k.id} from ${E}`);const L=await z.json();let H=typeof L.content=="string"?L.content:C;for(const U of j){const re=Es(U);if(!re)continue;const X=_.get(U.track);X!=null&&(H=Zi(H,re,{type:"inline-style",property:"z-index",value:String(X)}))}o.current=Date.now(),await fl({projectId:$,label:"Delete timeline clip",kind:"timeline",files:{[E]:H},readFile:async()=>C,writeFile:i,recordEdit:l}),pe.getState().setElements(n.filter(U=>(U.key??U.id)!==(k.key??k.id))),pe.getState().setSelectedElementId(null),c(),r(`Deleted ${Q}. Use Undo to restore it.`,"info")}catch(C){const P=C instanceof Error?C.message:"Failed to delete timeline clip";r(P)}},[e,l,r,n,i,o,c]),S=h.useCallback(async(k,$,Q)=>{const E=m.current;if(!E)throw new Error("No active project");const C=X5(k);if(!C){r("Only image, video, and audio assets can be dropped onto the timeline.");return}const P=e||"index.html";try{const M=await X0(E,P),j=Number(sl($.start)),_=Number.isFinite(Q)&&Q!=null&&Q>0?Q:await d3(E,k,C),z=Number(sl(_)),L=uC(k,EQ(M)),H=fC(P,k),U=P||"index.html",re=n.filter(F=>(F.sourceFile||e||"index.html")===U),X=u2([...re.map(F=>F.track),$.track]);let V=M;for(const F of re){const D=Es(F);if(!D)continue;const B=X.get(F.track);B!=null&&(V=Zi(V,D,{type:"inline-style",property:"z-index",value:String(B)}))}V=pC(V,mC({id:L,assetPath:H,kind:C,start:j,duration:z,track:$.track,zIndex:X.get($.track)??1,geometry:dC(M)})),o.current=Date.now(),await fl({projectId:E,label:"Add timeline asset",kind:"timeline",files:{[P]:V},readFile:async()=>M,writeFile:i,recordEdit:l}),c()}catch(M){const j=M instanceof Error?M.message:"Failed to drop asset onto timeline";r(j)}},[e,l,r,n,i,o,c]),w=h.useCallback(async(k,$)=>{const Q=m.current;if(!Q)return;const E=await f(k);if(E.length===0)return;const C=[];for(const M of E){const j=X5(M),_=j?await d3(Q,M,j):0;C.push(Number(sl(_)))}const P=hC($??{start:0,track:0},C,n.filter(M=>(M.sourceFile||e||"index.html")===(e||"index.html")).map(M=>({start:M.start,duration:M.duration,track:M.track})));for(const[M,j]of E.entries())await S(j,P[M]??P[0],C[M])},[e,S,n,f]),A=h.useCallback(k=>{const $=Date.now();$-p.current<1500||(p.current=$,r("This clip can't be moved or resized from the timeline yet.","info"))},[r]);return{handleTimelineElementMove:g,handleTimelineElementResize:x,handleTimelineElementDelete:v,handleTimelineAssetDrop:S,handleTimelineFileDrop:w,handleBlockedTimelineEdit:A}}const QQ={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},PQ="VITE_STUDIO_ENABLE_PREVIEW_MANUAL_DRAGGING",ZQ="VITE_STUDIO_ENABLE_INSPECTOR_PANELS",jQ="VITE_STUDIO_ENABLE_MOTION_PANEL",RQ="VITE_STUDIO_ENABLE_TIMELINE_LAYER_INSPECTOR",NQ=new Set(["1","true","yes","on","enabled"]),VQ=new Set(["0","false","no","off","disabled"]);function Sf(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(NQ.has(l))return!0;if(VQ.has(l))return!1}}return n}const wf=QQ,LQ=Sf(wf,[PQ,"VITE_STUDIO_PREVIEW_MANUAL_EDITING_ENABLED"],!0),Ut=Sf(wf,[ZQ,"VITE_STUDIO_INSPECTOR_PANELS_ENABLED"],!0),lg=Sf(wf,[jQ,"VITE_STUDIO_MOTION_PANEL_ENABLED"],!1);Ut&&Sf(wf,[RQ,"VITE_STUDIO_TIMELINE_LAYER_INSPECTOR_ENABLED"],!0);const _m=Ut,m3="Manual editing is temporarily disabled",iS=["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"];function ri(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&typeof t.nodeType=="number"&&t.nodeType===1}function va(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 _Q(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 aS(t){return["div","span","p","strong","h1","h2","h3","h4","h5","h6"].includes(t)}function lS(t){var r;const e={},n=(r=t.ownerDocument.defaultView)==null?void 0:r.getComputedStyle(t);if(!n)return e;for(const i of iS){const l=n.getPropertyValue(i);l&&(e[i]=l)}return e}function sS(t){const e={};for(const n of iS){const r=t.style.getPropertyValue(n);r&&(e[n]=r)}return e}function DQ(t){const e={};for(const n of t.attributes)n.name.startsWith("data-")&&(e[n.name.slice(5)]=n.value);return e}function p3(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 XQ(t){let e=0,n=t.parentElement;for(;n;)e+=1,n=n.parentElement;return e}function Ol(t,e){const n=p3(t,["data-composition-file","data-composition-src"]),r=p3(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 g3(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 oS(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,m=l>=1&&l<=31||l===127,p=r===0&&o,g=r===1&&t.startsWith("-")&&o;if(m||p||g){n+=`\\${l.toString(16)} `;continue}if(c||f||o||i==="-"||i==="_"||l>=128){n+=i;continue}n+=`\\${i}`}return n}function Dm(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\a ").replace(/\r/g,"\\d ").replace(/\f/g,"\\c ")}function Xm(t,e){try{return Array.from(t.querySelectorAll(e))}catch{return[]}}function z0(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 cS(t){if(t.id)return`#${oS(t.id)}`;const e=t.getAttribute("data-composition-id");return e?`[data-composition-id="${Dm(e)}"]`:uS(t)}function uS(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?`.${oS(n)}`:void 0}function fS(t,e,n,r,i){if(!(n!=null&&n.startsWith(".")))return;const o=Xm(t,n).filter(c=>ri(c)&&Ol(c,i).sourceFile===r).indexOf(e);return o>=0?o:void 0}function sg(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 O3=new Set(["img","video","canvas","svg","audio"]);function zQ(t){const e=t.tagName.toLowerCase();if(O3.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(ri(i)&&(O3.has(i.tagName.toLowerCase())||sg(i)))return!1}return!0}function HQ(t){const e=t.getBoundingClientRect();return!(e.width<=1||e.height<=1||!sg(t)||zQ(t))}function YQ(t){return aS(t.tagName.toLowerCase())&&t.children.length===0}function BQ(t,e){const n=t.tagName.toLowerCase(),r=t.getBoundingClientRect(),i=Math.max(1,r.width*r.height),l=Math.max(0,1e6-Math.min(i,1e6))/1e3,o=YQ(t)||["img","video","canvas","svg"].includes(n)?2e3:0;return XQ(t)*1e4+o+l-e}const FQ=new Set(["base","br","canvas","link","meta","script","source","style","template","track","wbr"]);function qQ(t){var r;const e=t.tagName.toLowerCase();if(FQ.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 Af(t,e){if(!qQ(t)||t.hasAttribute("data-composition-id"))return null;const n=cS(t);if(!n)return null;const{sourceFile:r}=Ol(t,e);return{id:t.id||void 0,selector:n,selectorIndex:fS(t.ownerDocument,t,n,r,e),sourceFile:r}}function UQ(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 IQ(t,e){if(e.preferClipAncestor){const n=UQ(t);if(n)return n}return t}function WQ(t,e){let n=null,r=0;for(const i of t){if(!ri(i)){r+=1;continue}if(HQ(i)&&Af(i,e.activeCompositionPath)){const l=BQ(i,r);(!n||l>n.score)&&(n={element:i,score:l})}r+=1}return(n==null?void 0:n.element)??null}function GQ(t){var n;const e=(n=t.computedStyles["background-image"])==null?void 0:n.trim();return!!(e&&e!=="none")}function KQ(t,e){if(!(t.tagName.toLowerCase()==="img"||GQ(t)))return!1;const{width:i,height:l}=t.boundingBox;if(i<=1||l<=1)return!1;if(!e||e.width<=1||e.height<=1)return i>=960&&l>=540;const o=i*l/(e.width*e.height),c=i/e.width,f=l/e.height;return o>=.4||c>=.7&&f>=.5}function Or(t,e,n=null){if(e.id){const i=t.getElementById(e.id);if(ri(i)&&(!e.sourceFile||Ol(i,n).sourceFile===e.sourceFile))return i}return e.selector?e.selector.startsWith(".")&&e.selectorIndex!=null?Xm(t,e.selector).filter(l=>ri(l)&&(!e.sourceFile||Ol(l,n).sourceFile===e.sourceFile))[e.selectorIndex]??null:Xm(t,e.selector).filter(i=>ri(i)&&(!e.sourceFile||Ol(i,n).sourceFile===e.sourceFile))[0]??null:null}function JQ(t,e,n){var g;const r=typeof e.id=="string"?e.id:"",i=g3(e.compositionSrc)??((g=n.compIdToSrc)==null?void 0:g.get(r)),l=i??g3(e.sourceFile)??n.activeCompositionPath??"index.html",o=Dm(r),c=i?Dm(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=Or(t,{id:e.domId??void 0,selector:f,selectorIndex:e.selectorIndex,sourceFile:l},n.activeCompositionPath);if(x)return x}const m=!!(e.domId||e.selector||i);if(n.isMasterView||m||!n.activeCompositionPath)return null;const p=t.querySelector("[data-composition-id]");return ri(p)&&Ol(p,n.activeCompositionPath).sourceFile===l?p:null}function eP(t,e){return Array.from(t.children).filter(n=>ri(n)&&Af(n,e.activeCompositionPath)!==null)}function y3(t){return aS(t.tagName.toLowerCase())&&t.children.length===0}function tP(t,e,n,r){return r==="self"||n===1?"Content":`Text ${e+1}`}function x3(t,e,n,r){const i=t.tagName.toLowerCase();return{key:t.getAttribute("data-hf-text-key")??`${r}:${e}:${i}`,label:tP(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:sS(t),computedStyles:lS(t),source:r}}function nP(t){const e=Array.from(t.children).filter(ri).filter(y3);return e.length>0?e.map((n,r)=>x3(n,r,e.length,"child")):y3(t)?[x3(t,0,1,"self")]:[]}function rP(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function iP(t){const e=Object.entries(t.inlineStyles).filter(([,n])=>!!n);return e.length===0?"":e.map(([n,r])=>`${n}: ${r}`).join("; ")}function b3(t){return t.filter(e=>e.source==="child").map(e=>{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=iP(e),i=r?` style="${r.replace(/"/g,"&quot;")}"`:"";return`<${e.tagName}${n}${i}>${rP(e.value)}</${e.tagName}>`}).join("")}function aP(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 lP(t){if(!t.selector)return{canSelect:!1,canEditStyles:!1,canMove:!1,canResize:!1,canApplyManualOffset:!1,canApplyManualSize:!1,canApplyManualRotation:!1,reasonIfDisabled:"Studio could not resolve a stable patch target for this element."};const e=t.computedStyles.position,n=va(t.inlineStyles.left)??va(t.computedStyles.left),r=va(t.inlineStyles.top)??va(t.computedStyles.top),i=va(t.inlineStyles.width)??va(t.computedStyles.width),l=va(t.inlineStyles.height)??va(t.computedStyles.height),o=!_Q(t.computedStyles.transform),c=(e==="absolute"||e==="fixed")&&n!=null&&r!=null&&!o,f=c&&(i!=null||l!=null),m=!t.isCompositionHost,p=m,g=m,x=m,v=m?void 0:"Select an internal layer to transform it.";return t.isCompositionHost&&t.isMasterView?{canSelect:!0,canEditStyles:!1,canMove:c,canResize:f,canApplyManualOffset:p,canApplyManualSize:g,canApplyManualRotation:x,reasonIfDisabled:v}:{canSelect:!0,canEditStyles:!0,canMove:c,canResize:f,canApplyManualOffset:p,canApplyManualSize:g,canApplyManualRotation:x,reasonIfDisabled:v}}function hS(t){const e=t.getAttribute("data-composition-id");if(e&&e!=="main")return z0(e);const n=t.getAttribute("data-composition-src")??t.getAttribute("data-composition-file");if(n)return z0(n);if(t.id)return z0(t.id);const r=uS(t);if(r)return z0(r.replace(/^\./,""));const i=(t.textContent??"").trim().replace(/\s+/g," ");return i?i.length>40?`${i.slice(0,39)}…`:i:t.tagName.toLowerCase()}function og(t,e){var i;if(!t)return null;const n=t.ownerDocument;let r=IQ(t,e);for(;r&&r!==n.body&&r!==n.documentElement;){const l=cS(r);if(!l){r=r.parentElement;continue}const{sourceFile:o,compositionPath:c}=Ol(r,e.activeCompositionPath),f=fS(n,r,l,o,e.activeCompositionPath),m=r.getAttribute("data-composition-src")??r.getAttribute("data-composition-file")??void 0,p=sS(r),g=lS(r),x=nP(r),v=lP({selector:l,tagName:r.tagName.toLowerCase(),className:r.className,inlineStyles:p,computedStyles:g,isCompositionHost:!!m,isMasterView:e.isMasterView}),S=r.getBoundingClientRect();return{element:r,id:r.id||void 0,selector:l,selectorIndex:f,sourceFile:o,compositionPath:c,compositionSrc:m,isCompositionHost:!!m,label:hS(r),tagName:r.tagName.toLowerCase(),boundingBox:{x:S.left,y:S.top,width:S.width,height:S.height},textContent:((i=r.textContent)==null?void 0:i.trim())||null,dataAttributes:DQ(r),inlineStyles:p,computedStyles:g,textFields:x,capabilities:v}}return null}function cg(t){const e=t.selectorIndex??0;return`${t.sourceFile}:${t.id??t.selector??"layer"}:${e}`}function dS(t,e,n=80){if(!t)return[];const r=[],i=(l,o)=>{if(r.length>=n)return;const c=Af(l,e.activeCompositionPath);c&&r.push({key:cg(c),element:l,label:hS(l),tagName:l.tagName.toLowerCase(),depth:o,childCount:eP(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 m of Array.from(l.children))if(ri(m)&&(i(m,f),r.length>=n))return};return i(t,0),r}function H0(t,e){return{type:"inline-style",property:t,value:e}}function v3(t){return{type:"text-content",property:"text",value:t}}function ji(t){return[t.sourceFile||"index.html",t.id??"",t.selector??"",t.selectorIndex??""].join("|")}function ug(t){return t.textFields.length>0&&!t.isCompositionHost}function sP(t){return`x=${Math.round(t.x)}, y=${Math.round(t.y)}, width=${Math.round(t.width)}, height=${Math.round(t.height)}`}function S3(t){return Object.entries(t).filter(([,e])=>e&&e!=="initial").map(([e,n])=>`${e}: ${n}`).join(`
80
+ `);const ue=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`,{method:"POST",headers:{"Content-Type":"text/plain"},body:te});if(ue.ok)await H(),M(K);else{const me=await ue.json().catch(()=>({error:"unknown"}));console.error(`Create file failed: ${me.error}`)}},[H,M]),X=h.useCallback(async K=>{const ee=A.current;if(!ee)return;const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K+"/.gitkeep")}`,{method:"POST",headers:{"Content-Type":"text/plain"},body:""});if(te.ok)await H();else{const ue=await te.json().catch(()=>({error:"unknown"}));console.error(`Create folder failed: ${ue.error}`)}},[H]),V=h.useCallback(async K=>{const ee=A.current;if(!ee)return;const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`,{method:"DELETE"});if(te.ok)w.current===K&&o(null),await H();else{const ue=await te.json().catch(()=>({error:"unknown"}));console.error(`Delete failed: ${ue.error}`)}},[H]),F=h.useCallback(async(K,ee)=>{const te=A.current;if(!te)return;const ue=await fetch(`/api/projects/${te}/files/${encodeURIComponent(K)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({newPath:ee})});if(ue.ok)w.current===K&&M(ee),await H(),i(me=>me+1);else{const me=await ue.json().catch(()=>({error:"unknown"}));console.error(`Rename failed: ${me.error}`)}},[H,M,i]),D=h.useCallback(async K=>{const ee=A.current;if(!ee)return;const te=await fetch(`/api/projects/${ee}/duplicate-file`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:K})});if(te.ok){const ue=await te.json();await H(),ue.path&&M(ue.path)}else{const ue=await te.json().catch(()=>({error:"unknown"}));console.error(`Duplicate failed: ${ue.error}`)}},[H,M]),B=F,I=h.useCallback(async(K,ee)=>U(Array.from(K),ee),[U]),Z=h.useCallback(async K=>{const ee=await U(Array.from(K).filter(me=>v1.test(me.name)),"assets/fonts"),te=A.current,ue=ee.filter(me=>v1.test(me)).map(me=>({family:Ks(me),path:me,url:`/api/projects/${te}/preview/${me}`}));return Q.current=[...ue,...Q.current.filter(me=>!ue.some(oe=>oe.family.toLowerCase()===me.family.toLowerCase()))],ue},[U]),R=h.useMemo(()=>m.filter(K=>K==="index.html"||K.startsWith("compositions/")),[m]),Y=h.useMemo(()=>m.filter(K=>!K.endsWith(".html")&&!K.endsWith(".md")&&!K.endsWith(".json")),[m]),W=h.useMemo(()=>Y.filter(K=>v1.test(K)).map(K=>({family:Ks(K),path:K,url:`/api/projects/${t}/preview/${K}`})),[Y,t]);return{editingFile:l,setEditingFile:o,projectDir:c,fileTree:m,fileTreeLoaded:g,setFileTree:p,editingPathRef:w,projectIdRef:A,saveTimerRef:k,importedFontAssetsRef:Q,readProjectFile:E,writeProjectFile:C,readOptionalProjectFile:P,revealSourceOffset:v,openSourceForSelection:L,handleFileSelect:M,handleContentChange:j,refreshFileTree:H,uploadProjectFiles:U,handleCreateFile:re,handleCreateFolder:X,handleDeleteFile:V,handleRenameFile:F,handleDuplicateFile:D,handleMoveFile:B,handleImportFiles:I,handleImportFonts:Z,compositions:R,assets:Y,fontAssets:W}}const vr="--hf-studio-offset-x",Sr="--hf-studio-offset-y",li="--hf-studio-width",si="--hf-studio-height",wr="--hf-studio-rotation",Di="data-hf-studio-path-offset",Bc="data-hf-studio-manual-edit-gesture",Xi="data-hf-studio-box-size",zi="data-hf-studio-rotation",oi="data-hf-studio-original-translate",ci="data-hf-studio-original-inline-translate",vl="data-hf-studio-original-width",Sl="data-hf-studio-original-height",wl="data-hf-studio-original-min-width",Al="data-hf-studio-original-min-height",kl="data-hf-studio-original-max-width",Tl="data-hf-studio-original-max-height",Ml="data-hf-studio-original-flex-basis",Cl="data-hf-studio-original-flex-grow",El="data-hf-studio-original-flex-shrink",$l="data-hf-studio-original-box-sizing",jr="data-hf-studio-original-scale",Hi="data-hf-studio-original-transform-origin",Ql="data-hf-studio-original-display",ui="data-hf-studio-original-rotate",fi="data-hf-studio-original-inline-rotate",Rr="data-hf-studio-original-rotation-transform-origin",Vl="data-hf-studio-rotation-draft",gn="data-hf-studio-original-transform-display",V$="__hfStudioManualEditsApply",Em="__hfStudioManualEditsWrapped",Z0="__hfStudioManualEditsPlaybackFrame",L$="center center";function _$(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function zv(t){return Math.round(t*10)/10}function j0(t){return t.trim().replace(/\\/g,"/").replace(/^\.?\//,"")}function $m(t){if(typeof t=="string"){const n=t.trim();if(!n)return null;if(n.startsWith("{"))try{return $m(JSON.parse(n))}catch{return j0(n)}return j0(n)}if(!t||typeof t!="object")return null;const e=t;return typeof e.path=="string"?j0(e.path):typeof e.filePath=="string"?j0(e.filePath):"data"in e?$m(e.data):null}function D$(t){return $m(t)}const Qm=".hyperframes/studio-motion.json",d2="studio-motion",Pa="data-hf-studio-motion",Pl="data-hf-studio-motion-original-transform",Js="data-hf-studio-motion-original-opacity",eo="data-hf-studio-motion-original-visibility",R0=["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"],bc={x1:.215,y1:.61,x2:.355,y2:1},X$={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}},z$=/^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 r3(t,e){return Number.isFinite(t)&&t>0?t:e}function H$(t,e){return Number.isFinite(t)&&t>=0?t:e}function Y$(t){return t.trim()||"none"}function vc(t){return Math.round(t*1e3)/1e3}function N0(t,e,n,r){return Number.isFinite(t)?Math.min(n,Math.max(e,t)):r}function V0(t){const e=vc(t);return Object.is(e,-0)?"0":`${e}`}function Pm(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function Gp(t){return{x1:vc(N0(t.x1??bc.x1,0,1,.215)),y1:vc(N0(t.y1??bc.y1,-.6,1.6,.61)),x2:vc(N0(t.x2??bc.x2,0,1,.355)),y2:vc(N0(t.y2??bc.y2,-.6,1.6,1))}}function i3(t){if(!t)return null;const e=t.trim().match(z$);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)?Gp(n):null}function Hv(t){const e=Gp(t);return`M0,0 C${V0(e.x1)},${V0(e.y1)} ${V0(e.x2)},${V0(e.y2)} 1,1`}function Yv(t){return X$[t]??bc}function B$(t,e){const n=H$(e.start,0),r=r3(e.duration,.6),i=r3(e.distance,32),l=Y$(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,m=o==="down"?-i:o==="up"?i:0;return{...c,from:{x:f,y:m,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 a3(t){if(!t||typeof t!="object")return null;const e=t,n={};for(const r of["x","y","scale","rotation","opacity","autoAlpha"]){const i=Pm(e[r]);i!=null&&(n[r]=i)}return Object.keys(n).length>0?n:null}function F$(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 Bv(t){const e=t.getAttribute(Pa);if(!e||e==="true")return null;try{const n=JSON.parse(e);if(!n||typeof n!="object")return null;const r=n,i=Pm(r.start),l=Pm(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=a3(r.from),f=a3(r.to);return!c||!f?null:{start:i,duration:l,ease:o,customEase:F$(r.customEase),from:c,to:f}}catch{return null}}function q$(t,e){t.getAttribute(Pl)||(t.setAttribute(Pl,t.style.transform),t.setAttribute(Js,t.style.opacity),t.setAttribute(eo,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(Pa,JSON.stringify(n))}function U$(t,e){var n;t.hasAttribute(Pa)&&((n=e==null?void 0:e.set)==null||n.call(e,t,{clearProps:"transform,opacity,visibility"}),t.style.transform=t.getAttribute(Pl)??"",t.style.opacity=t.getAttribute(Js)??"",t.style.visibility=t.getAttribute(eo)??"",t.removeAttribute(Pa),t.removeAttribute(Pl),t.removeAttribute(Js),t.removeAttribute(eo))}function I$(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 Zm(t,e){var m,p,g,x,v,S;const n=t.defaultView;if(!n)return 0;const r=n.gsap;n.__timelines=n.__timelines??{},(p=(m=n.__timelines[d2])==null?void 0:m.kill)==null||p.call(m),delete n.__timelines[d2];const i=(g=t.defaultView)==null?void 0:g.HTMLElement;if(!i)return 0;const l=[];for(const w of Array.from(t.querySelectorAll(`[${Pa}]`))){if(!(w instanceof i))continue;const A=Bv(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},$=W$(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[d2]=o,(v=o.pause)==null||v.call(o);const f=I$(n);return o.totalTime?o.totalTime(f,!1):(S=o.time)==null||S.call(o,f),c}function W$(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}}function G$(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(li),studioHeight:t.style.getPropertyValue(si),marker:t.getAttribute(Xi),originalWidth:t.getAttribute(vl),originalHeight:t.getAttribute(Sl),originalMinWidth:t.getAttribute(wl),originalMinHeight:t.getAttribute(Al),originalMaxWidth:t.getAttribute(kl),originalMaxHeight:t.getAttribute(Tl),originalFlexBasis:t.getAttribute(Ml),originalFlexGrow:t.getAttribute(Cl),originalFlexShrink:t.getAttribute(El),originalBoxSizing:t.getAttribute($l),originalScale:t.getAttribute(jr),originalTransformOrigin:t.getAttribute(Hi),originalDisplay:t.getAttribute(Ql)}}function K$(t){return{rotate:t.style.getPropertyValue("rotate"),transformOrigin:t.style.getPropertyValue("transform-origin"),studioRotation:t.style.getPropertyValue(wr),marker:t.getAttribute(zi),draftMarker:t.getAttribute(Vl),originalRotate:t.getAttribute(ui),originalInlineRotate:t.getAttribute(fi),originalTransformOrigin:t.getAttribute(Rr)}}function Kp(t){return{translate:t.style.getPropertyValue("translate"),x:t.style.getPropertyValue(vr),y:t.style.getPropertyValue(Sr),marker:t.getAttribute(Di),originalTranslate:t.getAttribute(oi),originalInlineTranslate:t.getAttribute(ci)}}function Qt(t,e,n){n==null?t.removeAttribute(e):t.setAttribute(e,n)}function Gt(t,e,n){n?t.style.setProperty(e,n):t.style.removeProperty(e)}function m2(t,e){Gt(t,"width",e.width),Gt(t,"height",e.height),Gt(t,"min-width",e.minWidth),Gt(t,"min-height",e.minHeight),Gt(t,"max-width",e.maxWidth),Gt(t,"max-height",e.maxHeight),Gt(t,"flex-basis",e.flexBasis),Gt(t,"flex-grow",e.flexGrow),Gt(t,"flex-shrink",e.flexShrink),Gt(t,"box-sizing",e.boxSizing),Gt(t,"scale",e.scale),Gt(t,"transform-origin",e.transformOrigin),Gt(t,"display",e.display),Gt(t,li,e.studioWidth),Gt(t,si,e.studioHeight),Qt(t,Xi,e.marker),Qt(t,vl,e.originalWidth),Qt(t,Sl,e.originalHeight),Qt(t,wl,e.originalMinWidth),Qt(t,Al,e.originalMinHeight),Qt(t,kl,e.originalMaxWidth),Qt(t,Tl,e.originalMaxHeight),Qt(t,Ml,e.originalFlexBasis),Qt(t,Cl,e.originalFlexGrow),Qt(t,El,e.originalFlexShrink),Qt(t,$l,e.originalBoxSizing),Qt(t,jr,e.originalScale),Qt(t,Hi,e.originalTransformOrigin),Qt(t,Ql,e.originalDisplay)}function p2(t,e){Gt(t,"rotate",e.rotate),Gt(t,"transform-origin",e.transformOrigin),Gt(t,wr,e.studioRotation),Qt(t,zi,e.marker),Qt(t,Vl,e.draftMarker),Qt(t,ui,e.originalRotate),Qt(t,fi,e.originalInlineRotate),Qt(t,Rr,e.originalTransformOrigin)}function hl(t,e){e.translate?t.style.setProperty("translate",e.translate):t.style.removeProperty("translate"),e.x?t.style.setProperty(vr,e.x):t.style.removeProperty(vr),e.y?t.style.setProperty(Sr,e.y):t.style.removeProperty(Sr),Qt(t,Di,e.marker),Qt(t,oi,e.originalTranslate),Qt(t,ci,e.originalInlineTranslate)}function In(t,e,n){const r=t.getAttribute(n);r==null||r===""?t.style.removeProperty(e):t.style.setProperty(e,r),t.removeAttribute(n)}function J$(t){const e=t.getAttribute(fi);e==null||e===""?t.style.removeProperty("rotate"):t.style.setProperty("rotate",e),t.removeAttribute(fi),t.removeAttribute(ui);const n=t.getAttribute(Rr);n!=null&&(n===""?t.style.removeProperty("transform-origin"):t.style.setProperty("transform-origin",n)),t.removeAttribute(Rr)}function eQ(t){const e=t.getAttribute(ci);e==null||e===""?t.style.removeProperty("translate"):t.style.setProperty("translate",e),t.removeAttribute(ci),t.removeAttribute(oi)}function tQ(t){(t.hasAttribute(Di)||Nm(t.style.getPropertyValue("translate")))&&eQ(t),eg(t),t.style.removeProperty(vr),t.style.removeProperty(Sr),t.removeAttribute(Di),t.removeAttribute(oi),t.removeAttribute(ci)}function nQ(t){(t.hasAttribute(zi)||Vm(t.style.getPropertyValue("rotate")))&&J$(t),eg(t),t.style.removeProperty(wr),t.removeAttribute(zi),t.removeAttribute(Vl),t.removeAttribute(ui),t.removeAttribute(fi),t.removeAttribute(Rr)}function rQ(t){(t.hasAttribute(Xi)||s3(t.style.getPropertyValue("width"))||s3(t.style.getPropertyValue("height"))||t.hasAttribute(jr))&&(In(t,"width",vl),In(t,"height",Sl),In(t,"min-width",wl),In(t,"min-height",Al),In(t,"max-width",kl),In(t,"max-height",Tl),In(t,"flex-basis",Ml),In(t,"flex-grow",Cl),In(t,"flex-shrink",El),In(t,"box-sizing",$l),In(t,"scale",jr),In(t,"transform-origin",Hi),In(t,"display",Ql)),eg(t),t.style.removeProperty(li),t.style.removeProperty(si),t.removeAttribute(Xi)}let l3=0;function Fv(t){l3+=1;const e=`gesture-${l3}`;return t.setAttribute(Bc,e),e}function Cr(t,e){e&&t.getAttribute(Bc)!==e||t.removeAttribute(Bc)}function qv(t){return t.hasAttribute(Bc)}function L0(t,e){return t.getAttribute(Bc)===e}function L1(t,e){const n=Number.parseFloat(t.style.getPropertyValue(e));return Number.isFinite(n)?n:0}function jm(t){return{x:L1(t,vr),y:L1(t,Sr)}}function _1(t){return{width:L1(t,li),height:L1(t,si)}}function Uv(t){const e=Number.parseFloat(t.style.getPropertyValue(wr));return{angle:Number.isFinite(e)?e:0}}function Jp(t,e){var n;try{return((n=t.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(t).getPropertyValue(e))??""}catch{return""}}function Rm(t,e){return t.style.getPropertyValue(e)||Jp(t,e)}function Iv(t,e){const n=Rm(t,e).trim();return n==="none"?"":n}function Nm(t){return t.includes(vr)||t.includes(Sr)}function s3(t){return t.includes(li)||t.includes(si)}function Vm(t){return t.includes(wr)}function o3(t){return t.replace(/\s+/g,"").toLowerCase()}function iQ(t,e){if(!t.hasAttribute(Vl))return!1;const n=t.style.getPropertyValue(wr).trim();return!n||!e.trim()?!1:o3(e)===o3(ng(t,n))}function mo(t){Jp(t,"display")==="inline"&&(t.hasAttribute(gn)||t.setAttribute(gn,t.style.getPropertyValue("display")),t.style.setProperty("display","inline-block"))}function eg(t){const e=t.getAttribute(gn);e!=null&&(e===""?t.style.removeProperty("display"):t.style.setProperty("display",e),t.removeAttribute(gn))}function aQ(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 Wv(t,e,n){var l;const r=(l=t.getAttribute(oi))==null?void 0:l.trim();if(!r||r==="none")return`${e} ${n}`;const i=aQ(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 lQ(t,e){const n=t.style.getPropertyValue("translate"),r=Iv(t,"translate"),i=t.hasAttribute(Di),l=!Nm(r);i?e&&l&&!qv(t)&&t.setAttribute(oi,r):(t.setAttribute(ci,Nm(n)?"":n),t.setAttribute(oi,l?r:""))}function Gv(t,e,n={}){lQ(t,n.updateBase??!0),t.setAttribute(Di,"true"),t.style.setProperty(vr,`${Math.round(e.x)}px`),t.style.setProperty(Sr,`${Math.round(e.y)}px`)}function Kv(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 D1(t,e,n={}){mo(t),Gv(t,e,{updateBase:n.updateBase??!0}),t.style.setProperty("translate",Wv(t,`var(${vr}, 0px)`,`var(${Sr}, 0px)`)),Kv(t)}function A1(t,e){mo(t),Gv(t,e,{updateBase:!1}),t.style.setProperty("translate",Wv(t,`${Math.round(e.x)}px`,`${Math.round(e.y)}px`)),Kv(t)}function sQ(t,e){const n=t.parentElement;if(!n)return null;const r=Rm(n,"display").trim();if(r!=="flex"&&r!=="inline-flex")return null;const i=Rm(n,"flex-direction").trim();return Math.round(Math.max(1,i.startsWith("column")?e.height:e.width))}function oQ(t){if(!t.hasAttribute(jr))return;const e=t.getAttribute(jr);e==null||e===""?t.style.removeProperty("scale"):t.style.setProperty("scale",e),t.removeAttribute(jr);const n=t.getAttribute(Hi);n==null||n===""?t.style.removeProperty("transform-origin"):t.style.setProperty("transform-origin",n),t.removeAttribute(Hi)}function cQ(t,e){t.hasAttribute(Xi)||(t.setAttribute(vl,t.style.getPropertyValue("width")),t.setAttribute(Sl,t.style.getPropertyValue("height")),t.setAttribute(wl,t.style.getPropertyValue("min-width")),t.setAttribute(Al,t.style.getPropertyValue("min-height")),t.setAttribute(kl,t.style.getPropertyValue("max-width")),t.setAttribute(Tl,t.style.getPropertyValue("max-height")),t.setAttribute(Ml,t.style.getPropertyValue("flex-basis")),t.setAttribute(Cl,t.style.getPropertyValue("flex-grow")),t.setAttribute(El,t.style.getPropertyValue("flex-shrink")),t.setAttribute($l,t.style.getPropertyValue("box-sizing")),t.setAttribute(jr,t.style.getPropertyValue("scale")),t.setAttribute(Hi,t.style.getPropertyValue("transform-origin")),t.setAttribute(Ql,t.style.getPropertyValue("display"))),t.setAttribute(Xi,"true"),t.style.setProperty(li,`${Math.round(Math.max(1,e.width))}px`),t.style.setProperty(si,`${Math.round(Math.max(1,e.height))}px`)}function Jv(t,e){cQ(t,e),oQ(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=sQ(t,e);i!=null&&(t.style.setProperty("flex-basis",`${i}px`),t.style.setProperty("flex-grow","0"),t.style.setProperty("flex-shrink","0")),Jp(t,"display")==="inline"&&t.style.setProperty("display","inline-block")}function tg(t,e){mo(t),Jv(t,e)}function uQ(t,e){mo(t),Jv(t,e)}function fQ(t){return/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|rad|turn|grad)$/.test(t.trim())}function ng(t,e){var r;const n=(r=t.getAttribute(ui))==null?void 0:r.trim();return!n||n==="none"||!fQ(n)?e:`calc(${n} + ${e})`}function hQ(t,e){const n=t.style.getPropertyValue("rotate"),r=Iv(t,"rotate"),i=t.hasAttribute(zi),l=!Vm(r)&&!iQ(t,r);i?e&&l&&!qv(t)&&t.setAttribute(ui,r):(t.setAttribute(fi,Vm(n)?"":n),t.setAttribute(ui,l?r:"")),t.hasAttribute(Rr)||t.setAttribute(Rr,t.style.getPropertyValue("transform-origin"))}function eS(t,e,n={}){hQ(t,n.updateBase??!0),t.setAttribute(zi,"true"),t.style.setProperty(wr,`${zv(e.angle)}deg`),t.style.setProperty("transform-origin",L$)}function rg(t,e){mo(t),eS(t,e),t.removeAttribute(Vl),t.style.setProperty("rotate",ng(t,`var(${wr}, 0deg)`))}function dQ(t,e){mo(t),eS(t,e,{updateBase:!1}),t.setAttribute(Vl,"true"),t.style.setProperty("rotate",ng(t,`${zv(e.angle)}deg`))}function c3(t){const e=t.style.getPropertyValue(vr),n=t.style.getPropertyValue(Sr),r=t.style.getPropertyValue("translate"),i=t.getAttribute(oi),l=t.getAttribute(ci),o=t.style.getPropertyValue("display"),c=t.getAttribute(gn),f=[];return e&&f.push({type:"inline-style",property:vr,value:e}),n&&f.push({type:"inline-style",property:Sr,value:n}),r&&f.push({type:"inline-style",property:"translate",value:r}),f.push({type:"attribute",property:Di,value:"true"}),i!==null&&f.push({type:"attribute",property:oi,value:i}),l!==null&&f.push({type:"attribute",property:ci,value:l}),o&&f.push({type:"inline-style",property:"display",value:o}),c!==null&&f.push({type:"attribute",property:gn,value:c}),f}function mQ(t){const e=t.getAttribute(ci),n=[{type:"inline-style",property:vr,value:null},{type:"inline-style",property:Sr,value:null},{type:"inline-style",property:"translate",value:e||null},{type:"attribute",property:Di,value:null},{type:"attribute",property:oi,value:null},{type:"attribute",property:ci,value:null}],r=t.getAttribute(gn);return r!==null&&(n.push({type:"inline-style",property:"display",value:r||null}),n.push({type:"attribute",property:gn,value:null})),n}function pQ(t){const e=[],n=t.style.getPropertyValue(li),r=t.style.getPropertyValue(si);n&&e.push({type:"inline-style",property:li,value:n}),r&&e.push({type:"inline-style",property:si,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"),m=t.style.getPropertyValue("max-height"),p=t.style.getPropertyValue("flex-basis"),g=t.style.getPropertyValue("flex-grow"),x=t.style.getPropertyValue("flex-shrink"),v=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}),m&&e.push({type:"inline-style",property:"max-height",value:m}),p&&e.push({type:"inline-style",property:"flex-basis",value:p}),g&&e.push({type:"inline-style",property:"flex-grow",value:g}),x&&e.push({type:"inline-style",property:"flex-shrink",value:x}),v&&e.push({type:"inline-style",property:"box-sizing",value:v}),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:Xi,value:"true"});const k=t.getAttribute(vl),$=t.getAttribute(Sl),Q=t.getAttribute(wl),E=t.getAttribute(Al),C=t.getAttribute(kl),P=t.getAttribute(Tl),M=t.getAttribute(Ml),j=t.getAttribute(Cl),_=t.getAttribute(El),z=t.getAttribute($l),L=t.getAttribute(jr),H=t.getAttribute(Hi),U=t.getAttribute(Ql),re=t.getAttribute(gn);return k!==null&&e.push({type:"attribute",property:vl,value:k}),$!==null&&e.push({type:"attribute",property:Sl,value:$}),Q!==null&&e.push({type:"attribute",property:wl,value:Q}),E!==null&&e.push({type:"attribute",property:Al,value:E}),C!==null&&e.push({type:"attribute",property:kl,value:C}),P!==null&&e.push({type:"attribute",property:Tl,value:P}),M!==null&&e.push({type:"attribute",property:Ml,value:M}),j!==null&&e.push({type:"attribute",property:Cl,value:j}),_!==null&&e.push({type:"attribute",property:El,value:_}),z!==null&&e.push({type:"attribute",property:$l,value:z}),L!==null&&e.push({type:"attribute",property:jr,value:L}),H!==null&&e.push({type:"attribute",property:Hi,value:H}),U!==null&&e.push({type:"attribute",property:Ql,value:U}),re!==null&&e.push({type:"attribute",property:gn,value:re}),e}function gQ(t){const e=[{type:"inline-style",property:li,value:null},{type:"inline-style",property:si,value:null},{type:"attribute",property:Xi,value:null}],n=[[vl,"width"],[Sl,"height"],[wl,"min-width"],[Al,"min-height"],[kl,"max-width"],[Tl,"max-height"],[Ml,"flex-basis"],[Cl,"flex-grow"],[El,"flex-shrink"],[$l,"box-sizing"],[jr,"scale"],[Hi,"transform-origin"],[Ql,"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(gn);return r!==null&&(e.push({type:"inline-style",property:"display",value:r||null}),e.push({type:"attribute",property:gn,value:null})),e}function OQ(t){const e=[],n=t.style.getPropertyValue(wr),r=t.style.getPropertyValue("rotate"),i=t.style.getPropertyValue("transform-origin"),l=t.style.getPropertyValue("display");n&&e.push({type:"inline-style",property:wr,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:zi,value:"true"});const o=t.getAttribute(ui),c=t.getAttribute(fi),f=t.getAttribute(Rr),m=t.getAttribute(gn);return o!==null&&e.push({type:"attribute",property:ui,value:o}),c!==null&&e.push({type:"attribute",property:fi,value:c}),f!==null&&e.push({type:"attribute",property:Rr,value:f}),m!==null&&e.push({type:"attribute",property:gn,value:m}),e}function yQ(t){const e=t.getAttribute(fi),n=t.getAttribute(Rr),r=[{type:"inline-style",property:wr,value:null},{type:"inline-style",property:"rotate",value:e||null},{type:"inline-style",property:"transform-origin",value:n!==null&&n||null},{type:"attribute",property:zi,value:null},{type:"attribute",property:Vl,value:null},{type:"attribute",property:ui,value:null},{type:"attribute",property:fi,value:null},{type:"attribute",property:Rr,value:null}],i=t.getAttribute(gn);return i!==null&&(r.push({type:"inline-style",property:"display",value:i||null}),r.push({type:"attribute",property:gn,value:null})),r}function xQ(t){const e=t.getAttribute(Pa);if(!e)return[];const n=[{type:"attribute",property:Pa,value:e}],r=t.getAttribute(Pl);r!==null&&n.push({type:"attribute",property:Pl,value:r});const i=t.getAttribute(Js);i!==null&&n.push({type:"attribute",property:Js,value:i});const l=t.getAttribute(eo);return l!==null&&n.push({type:"attribute",property:eo,value:l}),n}function bQ(t){return[{type:"attribute",property:Pa,value:null},{type:"attribute",property:Pl,value:null},{type:"attribute",property:Js,value:null},{type:"attribute",property:eo,value:null}]}function vQ(t){var l;const e=(l=t.defaultView)==null?void 0:l.HTMLElement;if(!e)return;const n=Array.from(t.querySelectorAll(`[${Di}="true"]`)).filter(o=>o instanceof e);for(const o of n){const c=o.style.getPropertyValue(vr),f=o.style.getPropertyValue(Sr);(c||f)&&D1(o,{x:Number.parseFloat(c)||0,y:Number.parseFloat(f)||0})}const r=Array.from(t.querySelectorAll(`[${Xi}="true"]`)).filter(o=>o instanceof e);for(const o of r){const c=Number.parseFloat(o.style.getPropertyValue(li)),f=Number.parseFloat(o.style.getPropertyValue(si));Number.isFinite(c)&&Number.isFinite(f)&&c>0&&f>0&&tg(o,{width:c,height:f})}const i=Array.from(t.querySelectorAll(`[${zi}="true"]`)).filter(o=>o instanceof e);for(const o of i){const c=Number.parseFloat(o.style.getPropertyValue(wr));Number.isFinite(c)&&rg(o,{angle:c})}Zm(t)}function ig(t){try{Object.defineProperty(t,Em,{configurable:!1,enumerable:!1,value:!0})}catch{try{t[Em]=!0}catch{}}}function ag(t){return!!t[Em]}function uc(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(ag(i))return!0;const l=function(...o){var f;const c=i.apply(this,o);return(f=t.__hfStudioManualEditsApply)==null||f.call(t),c};ig(l);try{e[n]=l}catch{return!1}return!0}function fc(t,e){const n=t[e];if(typeof n!="function")return null;try{return _$(n.call(t))}catch{return null}}function SQ(t){const e=fc(t,"duration")??fc(t,"getDuration");if(e==null)return!0;if(e<=0)return!1;const n=fc(t,"time")??fc(t,"totalTime")??fc(t,"getTime");return n==null?!0:n<e}function g2(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 SQ(t)}const r=t.isActive;if(typeof r=="function")try{return!!r.call(t)}catch{return!1}return!1}function tS(t){return g2(t.__player)||g2(t.__timeline)?!0:Object.values(t.__timelines??{}).some(g2)}function nS(t){var n;if((n=t.__hfStudioManualEditsApply)==null||n.call(t),t[Z0]!=null)return;const e=()=>{var r;if((r=t.__hfStudioManualEditsApply)==null||r.call(t),!tS(t)){t[Z0]=null;return}t[Z0]=t.requestAnimationFrame(e)};t[Z0]=t.requestAnimationFrame(e)}function O2(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(ag(i))return!0;const l=function(...o){const c=i.apply(this,o);return nS(t),c};ig(l);try{e[n]=l}catch{return!1}return!0}function y2(t,e,n){const r=e==null?void 0:e[n];if(!e||typeof r!="function")return!1;const i=r;if(ag(i))return!0;const l=function(...o){var f;const c=i.apply(this,o);return(f=t.__hfStudioManualEditsApply)==null||f.call(t),c};ig(l);try{e[n]=l}catch{return!1}return!0}function wQ(t,e){const n=t;n[V$]=e;const r=uc(n,n.__hf,"seek"),i=uc(n,n.__player,"seek"),l=uc(n,n.__player,"renderSeek"),o=uc(n,n.__timeline,"seek"),c=O2(n,n.__player,"play"),f=O2(n,n.__timeline,"play"),m=y2(n,n.__player,"pause"),p=y2(n,n.__timeline,"pause");let g=!1,x=!1,v=!1;for(const S of Object.values(n.__timelines??{}))g=uc(n,S,"seek")||g,x=O2(n,S,"play")||x,v=y2(n,S,"pause")||v;return tS(n)&&nS(n),r||i||l||o||c||f||m||p||g||x||v}function AQ({projectId:t,showToast:e,readOptionalProjectFile:n,writeProjectFile:r,recordEdit:i,previewIframeRef:l,activeCompPathRef:o,domEditSaveTimestampRef:c,reloadPreview:f}){const m=h.useRef(0),p=h.useRef(Promise.resolve()),g=h.useRef(async()=>{}),x=h.useRef(t);x.current=t;const v=h.useCallback($=>{const Q=p.current.catch(()=>{}).then($);return p.current=Q.then(()=>{},()=>{}),Q},[]),S=h.useCallback(async()=>{await p.current.catch(()=>{})},[]),w=h.useCallback(($=l.current)=>{var M,j,_,z,L,H;if(!$)return;let Q=null;try{Q=$.contentDocument}catch{return}if(!Q)return;const E=()=>{let U=null;try{U=$.contentDocument}catch{return}U&&vQ(U)},C=()=>{E(),$.contentWindow&&wQ($.contentWindow,E)},P=$.contentWindow;C(),(M=P==null?void 0:P.requestAnimationFrame)==null||M.call(P,C),(j=P==null?void 0:P.setTimeout)==null||j.call(P,C,80),(_=P==null?void 0:P.setTimeout)==null||_.call(P,C,250),(z=P==null?void 0:P.setTimeout)==null||z.call(P,C,500),(L=P==null?void 0:P.setTimeout)==null||L.call(P,C,1e3),(H=P==null?void 0:P.setTimeout)==null||H.call(P,C,2e3)},[l]),A=h.useCallback(async($=l.current)=>{w($)},[w,l]);g.current=A;const k=h.useCallback(async $=>{f()},[f]);return Tt(()=>{n(Qm).then($=>{if($){try{const Q=JSON.parse($);if(!Array.isArray(Q.motions)||Q.motions.length===0)return}catch{return}return r(Qm,JSON.stringify({version:1,motions:[]}))}}).catch(()=>{})}),Tt(()=>{const $=E=>{if(!D$(E))return;Date.now()-c.current<1200||f()},Q=new EventSource("/api/events");return Q.addEventListener("file-change",$),()=>Q.close()}),{domTextCommitVersionRef:m,domEditSaveQueueRef:p,applyStudioManualEditsToPreviewRef:g,queueDomEditSave:v,waitForPendingDomEditSaves:S,applyCurrentStudioManualEditsToPreview:w,applyStudioManualEditsToPreview:A,syncHistoryPreviewAfterApply:k}}function Ps(t){return t.label||t.id||t.tag}function u3(t){const e=t.trim(),n=/^[a-z]+:\/\//i.test(e)?new URL(e).pathname:e;return decodeURIComponent(n).replace(/\\/g,"/").replace(/^\.?\//,"")}function kQ(t,e){const n=u3(t).split("/").filter(Boolean),r=u3(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 TQ(t){return/^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(t)}function MQ(t,e){const n=e.trim();if(!n)return;const r=n.replace(/\\/g,"/");if(TQ(r))return r;const i=t==null?void 0:t.trim().replace(/\\/g,"/").replace(/\/+$/,"");if(i)return`${i}/${r.replace(/^\.?\//,"")}`}function x2(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 f3(t){return/^url\(/i.test(t.trim())}function CQ(t){return t==="left"||t==="top"||t==="width"||t==="height"}function rS(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 h3(t){const e=rS(t);return e?!!e.closest("input, textarea, select, [contenteditable='true'], [role='textbox'], .cm-editor"):!1}function _0(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 Lm(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 X1(t,e,n){return n<e?e:Math.min(Math.max(t,e),n)}function EQ(t){return Array.from(t.matchAll(/\bid="([^"]+)"/g),e=>e[1]??"")}const D0={image:3,video:5,audio:5};async function d3(t,e,n){if(n==="image")return D0.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(D0[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:D0[n])},{once:!0}),r.addEventListener("error",()=>c(D0[n]),{once:!0})});return r.src="",r.load(),i}function Es(t){return t.domId?{id:t.domId,selector:t.selector,selectorIndex:t.selectorIndex}:t.selector?{selector:t.selector,selectorIndex:t.selectorIndex}:null}async function X0(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 $Q({projectId:t,activeCompPath:e,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:l,domEditSaveTimestampRef:o,reloadPreview:c,uploadProjectFiles:f}){const m=h.useRef(t);m.current=t;const p=h.useRef(0),g=h.useCallback(async(k,$)=>{const Q=m.current;if(!Q)throw new Error("No active project");const E=k.sourceFile||e||"index.html",C=await X0(Q,E),P=Es(k);if(!P)throw new Error(`Timeline element ${k.id} is missing a patchable target`);const M=E,j=n.map(L=>(L.key??L.id)===(k.key??k.id)?{...L,start:$.start,track:$.track}:L).filter(L=>(L.sourceFile||e||"index.html")===M),_=u2(j.map(L=>L.track));let z=Zi(C,P,{type:"attribute",property:"start",value:sl($.start)});z=Zi(z,P,{type:"attribute",property:"track-index",value:String($.track)});for(const L of j){const H=Es(L);if(!H)continue;const U=_.get(L.track);U!=null&&(z=Zi(z,H,{type:"inline-style",property:"z-index",value:String(U)}))}if(z===C)throw new Error(`Unable to patch timeline element ${k.id} in ${E}`);o.current=Date.now(),await fl({projectId:Q,label:"Move timeline clip",kind:"timeline",files:{[E]:z},readFile:async()=>C,writeFile:i,recordEdit:l}),c()},[e,l,n,i,o,c]),x=h.useCallback(async(k,$)=>{const Q=m.current;if(!Q)throw new Error("No active project");const E=k.sourceFile||e||"index.html",C=await X0(Q,E),P=Es(k);if(!P)throw new Error(`Timeline element ${k.id} is missing a patchable target`);const M=k.playbackStartAttr==="playback-start"?"playback-start":"media-start",j=n3(C,P,"playback-start")??n3(C,P,"media-start"),_=j!=null?parseFloat(j):void 0,z=$.start-k.start,L=$.playbackStart==null&&z!==0&&Number.isFinite(_)&&_!=null?Math.max(0,_+z*Math.max(k.playbackRate??1,.1)):void 0,H=$.playbackStart??L;let U=C;if(U=Zi(U,P,{type:"attribute",property:"start",value:sl($.start)}),U=Zi(U,P,{type:"attribute",property:"duration",value:sl($.duration)}),H!=null&&(U=Zi(U,P,{type:"attribute",property:M,value:sl(H)})),U===C)throw new Error(`Unable to patch timeline element ${k.id} in ${E}`);o.current=Date.now(),await fl({projectId:Q,label:"Resize timeline clip",kind:"timeline",files:{[E]:U},readFile:async()=>C,writeFile:i,recordEdit:l}),c()},[e,l,i,o,c]),v=h.useCallback(async k=>{const $=m.current;if(!$)throw new Error("No active project");const Q=Ps(k),E=k.sourceFile||e||"index.html";try{const C=await X0($,E),P=Es(k);if(!P)throw new Error(`Timeline element ${k.id} is missing a patchable target`);const M=E||"index.html",j=n.filter(U=>(U.key??U.id)!==(k.key??k.id)&&(U.sourceFile||e||"index.html")===M),_=u2(j.map(U=>U.track)),z=await fetch(`/api/projects/${$}/file-mutations/remove-element/${encodeURIComponent(E)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:P})});if(!z.ok)throw new Error(`Failed to delete ${k.id} from ${E}`);const L=await z.json();let H=typeof L.content=="string"?L.content:C;for(const U of j){const re=Es(U);if(!re)continue;const X=_.get(U.track);X!=null&&(H=Zi(H,re,{type:"inline-style",property:"z-index",value:String(X)}))}o.current=Date.now(),await fl({projectId:$,label:"Delete timeline clip",kind:"timeline",files:{[E]:H},readFile:async()=>C,writeFile:i,recordEdit:l}),pe.getState().setElements(n.filter(U=>(U.key??U.id)!==(k.key??k.id))),pe.getState().setSelectedElementId(null),c(),r(`Deleted ${Q}. Use Undo to restore it.`,"info")}catch(C){const P=C instanceof Error?C.message:"Failed to delete timeline clip";r(P)}},[e,l,r,n,i,o,c]),S=h.useCallback(async(k,$,Q)=>{const E=m.current;if(!E)throw new Error("No active project");const C=X5(k);if(!C){r("Only image, video, and audio assets can be dropped onto the timeline.");return}const P=e||"index.html";try{const M=await X0(E,P),j=Number(sl($.start)),_=Number.isFinite(Q)&&Q!=null&&Q>0?Q:await d3(E,k,C),z=Number(sl(_)),L=uC(k,EQ(M)),H=fC(P,k),U=P||"index.html",re=n.filter(F=>(F.sourceFile||e||"index.html")===U),X=u2([...re.map(F=>F.track),$.track]);let V=M;for(const F of re){const D=Es(F);if(!D)continue;const B=X.get(F.track);B!=null&&(V=Zi(V,D,{type:"inline-style",property:"z-index",value:String(B)}))}V=pC(V,mC({id:L,assetPath:H,kind:C,start:j,duration:z,track:$.track,zIndex:X.get($.track)??1,geometry:dC(M)})),o.current=Date.now(),await fl({projectId:E,label:"Add timeline asset",kind:"timeline",files:{[P]:V},readFile:async()=>M,writeFile:i,recordEdit:l}),c()}catch(M){const j=M instanceof Error?M.message:"Failed to drop asset onto timeline";r(j)}},[e,l,r,n,i,o,c]),w=h.useCallback(async(k,$)=>{const Q=m.current;if(!Q)return;const E=await f(k);if(E.length===0)return;const C=[];for(const M of E){const j=X5(M),_=j?await d3(Q,M,j):0;C.push(Number(sl(_)))}const P=hC($??{start:0,track:0},C,n.filter(M=>(M.sourceFile||e||"index.html")===(e||"index.html")).map(M=>({start:M.start,duration:M.duration,track:M.track})));for(const[M,j]of E.entries())await S(j,P[M]??P[0],C[M])},[e,S,n,f]),A=h.useCallback(k=>{const $=Date.now();$-p.current<1500||(p.current=$,r("This clip can't be moved or resized from the timeline yet.","info"))},[r]);return{handleTimelineElementMove:g,handleTimelineElementResize:x,handleTimelineElementDelete:v,handleTimelineAssetDrop:S,handleTimelineFileDrop:w,handleBlockedTimelineEdit:A}}const QQ={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},PQ="VITE_STUDIO_ENABLE_PREVIEW_MANUAL_DRAGGING",ZQ="VITE_STUDIO_ENABLE_INSPECTOR_PANELS",jQ="VITE_STUDIO_ENABLE_MOTION_PANEL",RQ="VITE_STUDIO_ENABLE_TIMELINE_LAYER_INSPECTOR",NQ=new Set(["1","true","yes","on","enabled"]),VQ=new Set(["0","false","no","off","disabled"]);function Sf(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(NQ.has(l))return!0;if(VQ.has(l))return!1}}return n}const wf=QQ??{},LQ=Sf(wf,[PQ,"VITE_STUDIO_PREVIEW_MANUAL_EDITING_ENABLED"],!0),Ut=Sf(wf,[ZQ,"VITE_STUDIO_INSPECTOR_PANELS_ENABLED"],!0),lg=Sf(wf,[jQ,"VITE_STUDIO_MOTION_PANEL_ENABLED"],!1);Ut&&Sf(wf,[RQ,"VITE_STUDIO_TIMELINE_LAYER_INSPECTOR_ENABLED"],!0);const _m=Ut,m3="Manual editing is temporarily disabled",iS=["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"];function ri(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&typeof t.nodeType=="number"&&t.nodeType===1}function va(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 _Q(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 aS(t){return["div","span","p","strong","h1","h2","h3","h4","h5","h6"].includes(t)}function lS(t){var r;const e={},n=(r=t.ownerDocument.defaultView)==null?void 0:r.getComputedStyle(t);if(!n)return e;for(const i of iS){const l=n.getPropertyValue(i);l&&(e[i]=l)}return e}function sS(t){const e={};for(const n of iS){const r=t.style.getPropertyValue(n);r&&(e[n]=r)}return e}function DQ(t){const e={};for(const n of t.attributes)n.name.startsWith("data-")&&(e[n.name.slice(5)]=n.value);return e}function p3(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 XQ(t){let e=0,n=t.parentElement;for(;n;)e+=1,n=n.parentElement;return e}function Ol(t,e){const n=p3(t,["data-composition-file","data-composition-src"]),r=p3(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 g3(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 oS(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,m=l>=1&&l<=31||l===127,p=r===0&&o,g=r===1&&t.startsWith("-")&&o;if(m||p||g){n+=`\\${l.toString(16)} `;continue}if(c||f||o||i==="-"||i==="_"||l>=128){n+=i;continue}n+=`\\${i}`}return n}function Dm(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\a ").replace(/\r/g,"\\d ").replace(/\f/g,"\\c ")}function Xm(t,e){try{return Array.from(t.querySelectorAll(e))}catch{return[]}}function z0(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 cS(t){if(t.id)return`#${oS(t.id)}`;const e=t.getAttribute("data-composition-id");return e?`[data-composition-id="${Dm(e)}"]`:uS(t)}function uS(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?`.${oS(n)}`:void 0}function fS(t,e,n,r,i){if(!(n!=null&&n.startsWith(".")))return;const o=Xm(t,n).filter(c=>ri(c)&&Ol(c,i).sourceFile===r).indexOf(e);return o>=0?o:void 0}function sg(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 O3=new Set(["img","video","canvas","svg","audio"]);function zQ(t){const e=t.tagName.toLowerCase();if(O3.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(ri(i)&&(O3.has(i.tagName.toLowerCase())||sg(i)))return!1}return!0}function HQ(t){const e=t.getBoundingClientRect();return!(e.width<=1||e.height<=1||!sg(t)||zQ(t))}function YQ(t){return aS(t.tagName.toLowerCase())&&t.children.length===0}function BQ(t,e){const n=t.tagName.toLowerCase(),r=t.getBoundingClientRect(),i=Math.max(1,r.width*r.height),l=Math.max(0,1e6-Math.min(i,1e6))/1e3,o=YQ(t)||["img","video","canvas","svg"].includes(n)?2e3:0;return XQ(t)*1e4+o+l-e}const FQ=new Set(["base","br","canvas","link","meta","script","source","style","template","track","wbr"]);function qQ(t){var r;const e=t.tagName.toLowerCase();if(FQ.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 Af(t,e){if(!qQ(t)||t.hasAttribute("data-composition-id"))return null;const n=cS(t);if(!n)return null;const{sourceFile:r}=Ol(t,e);return{id:t.id||void 0,selector:n,selectorIndex:fS(t.ownerDocument,t,n,r,e),sourceFile:r}}function UQ(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 IQ(t,e){if(e.preferClipAncestor){const n=UQ(t);if(n)return n}return t}function WQ(t,e){let n=null,r=0;for(const i of t){if(!ri(i)){r+=1;continue}if(HQ(i)&&Af(i,e.activeCompositionPath)){const l=BQ(i,r);(!n||l>n.score)&&(n={element:i,score:l})}r+=1}return(n==null?void 0:n.element)??null}function GQ(t){var n;const e=(n=t.computedStyles["background-image"])==null?void 0:n.trim();return!!(e&&e!=="none")}function KQ(t,e){if(!(t.tagName.toLowerCase()==="img"||GQ(t)))return!1;const{width:i,height:l}=t.boundingBox;if(i<=1||l<=1)return!1;if(!e||e.width<=1||e.height<=1)return i>=960&&l>=540;const o=i*l/(e.width*e.height),c=i/e.width,f=l/e.height;return o>=.4||c>=.7&&f>=.5}function Or(t,e,n=null){if(e.id){const i=t.getElementById(e.id);if(ri(i)&&(!e.sourceFile||Ol(i,n).sourceFile===e.sourceFile))return i}return e.selector?e.selector.startsWith(".")&&e.selectorIndex!=null?Xm(t,e.selector).filter(l=>ri(l)&&(!e.sourceFile||Ol(l,n).sourceFile===e.sourceFile))[e.selectorIndex]??null:Xm(t,e.selector).filter(i=>ri(i)&&(!e.sourceFile||Ol(i,n).sourceFile===e.sourceFile))[0]??null:null}function JQ(t,e,n){var g;const r=typeof e.id=="string"?e.id:"",i=g3(e.compositionSrc)??((g=n.compIdToSrc)==null?void 0:g.get(r)),l=i??g3(e.sourceFile)??n.activeCompositionPath??"index.html",o=Dm(r),c=i?Dm(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=Or(t,{id:e.domId??void 0,selector:f,selectorIndex:e.selectorIndex,sourceFile:l},n.activeCompositionPath);if(x)return x}const m=!!(e.domId||e.selector||i);if(n.isMasterView||m||!n.activeCompositionPath)return null;const p=t.querySelector("[data-composition-id]");return ri(p)&&Ol(p,n.activeCompositionPath).sourceFile===l?p:null}function eP(t,e){return Array.from(t.children).filter(n=>ri(n)&&Af(n,e.activeCompositionPath)!==null)}function y3(t){return aS(t.tagName.toLowerCase())&&t.children.length===0}function tP(t,e,n,r){return r==="self"||n===1?"Content":`Text ${e+1}`}function x3(t,e,n,r){const i=t.tagName.toLowerCase();return{key:t.getAttribute("data-hf-text-key")??`${r}:${e}:${i}`,label:tP(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:sS(t),computedStyles:lS(t),source:r}}function nP(t){const e=Array.from(t.children).filter(ri).filter(y3);return e.length>0?e.map((n,r)=>x3(n,r,e.length,"child")):y3(t)?[x3(t,0,1,"self")]:[]}function rP(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function iP(t){const e=Object.entries(t.inlineStyles).filter(([,n])=>!!n);return e.length===0?"":e.map(([n,r])=>`${n}: ${r}`).join("; ")}function b3(t){return t.filter(e=>e.source==="child").map(e=>{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=iP(e),i=r?` style="${r.replace(/"/g,"&quot;")}"`:"";return`<${e.tagName}${n}${i}>${rP(e.value)}</${e.tagName}>`}).join("")}function aP(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 lP(t){if(!t.selector)return{canSelect:!1,canEditStyles:!1,canMove:!1,canResize:!1,canApplyManualOffset:!1,canApplyManualSize:!1,canApplyManualRotation:!1,reasonIfDisabled:"Studio could not resolve a stable patch target for this element."};const e=t.computedStyles.position,n=va(t.inlineStyles.left)??va(t.computedStyles.left),r=va(t.inlineStyles.top)??va(t.computedStyles.top),i=va(t.inlineStyles.width)??va(t.computedStyles.width),l=va(t.inlineStyles.height)??va(t.computedStyles.height),o=!_Q(t.computedStyles.transform),c=(e==="absolute"||e==="fixed")&&n!=null&&r!=null&&!o,f=c&&(i!=null||l!=null),m=!t.isCompositionHost,p=m,g=m,x=m,v=m?void 0:"Select an internal layer to transform it.";return t.isCompositionHost&&t.isMasterView?{canSelect:!0,canEditStyles:!1,canMove:c,canResize:f,canApplyManualOffset:p,canApplyManualSize:g,canApplyManualRotation:x,reasonIfDisabled:v}:{canSelect:!0,canEditStyles:!0,canMove:c,canResize:f,canApplyManualOffset:p,canApplyManualSize:g,canApplyManualRotation:x,reasonIfDisabled:v}}function hS(t){const e=t.getAttribute("data-composition-id");if(e&&e!=="main")return z0(e);const n=t.getAttribute("data-composition-src")??t.getAttribute("data-composition-file");if(n)return z0(n);if(t.id)return z0(t.id);const r=uS(t);if(r)return z0(r.replace(/^\./,""));const i=(t.textContent??"").trim().replace(/\s+/g," ");return i?i.length>40?`${i.slice(0,39)}…`:i:t.tagName.toLowerCase()}function og(t,e){var i;if(!t)return null;const n=t.ownerDocument;let r=IQ(t,e);for(;r&&r!==n.body&&r!==n.documentElement;){const l=cS(r);if(!l){r=r.parentElement;continue}const{sourceFile:o,compositionPath:c}=Ol(r,e.activeCompositionPath),f=fS(n,r,l,o,e.activeCompositionPath),m=r.getAttribute("data-composition-src")??r.getAttribute("data-composition-file")??void 0,p=sS(r),g=lS(r),x=nP(r),v=lP({selector:l,tagName:r.tagName.toLowerCase(),className:r.className,inlineStyles:p,computedStyles:g,isCompositionHost:!!m,isMasterView:e.isMasterView}),S=r.getBoundingClientRect();return{element:r,id:r.id||void 0,selector:l,selectorIndex:f,sourceFile:o,compositionPath:c,compositionSrc:m,isCompositionHost:!!m,label:hS(r),tagName:r.tagName.toLowerCase(),boundingBox:{x:S.left,y:S.top,width:S.width,height:S.height},textContent:((i=r.textContent)==null?void 0:i.trim())||null,dataAttributes:DQ(r),inlineStyles:p,computedStyles:g,textFields:x,capabilities:v}}return null}function cg(t){const e=t.selectorIndex??0;return`${t.sourceFile}:${t.id??t.selector??"layer"}:${e}`}function dS(t,e,n=80){if(!t)return[];const r=[],i=(l,o)=>{if(r.length>=n)return;const c=Af(l,e.activeCompositionPath);c&&r.push({key:cg(c),element:l,label:hS(l),tagName:l.tagName.toLowerCase(),depth:o,childCount:eP(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 m of Array.from(l.children))if(ri(m)&&(i(m,f),r.length>=n))return};return i(t,0),r}function H0(t,e){return{type:"inline-style",property:t,value:e}}function v3(t){return{type:"text-content",property:"text",value:t}}function ji(t){return[t.sourceFile||"index.html",t.id??"",t.selector??"",t.selectorIndex??""].join("|")}function ug(t){return t.textFields.length>0&&!t.isCompositionHost}function sP(t){return`x=${Math.round(t.x)}, y=${Math.round(t.y)}, width=${Math.round(t.width)}, height=${Math.round(t.height)}`}function S3(t){return Object.entries(t).filter(([,e])=>e&&e!=="initial").map(([e,n])=>`${e}: ${n}`).join(`
81
81
  `)}function oP(t){return t.map(e=>`- key=${e.key}; tag=<${e.tagName}>; source=${e.source}; text=${JSON.stringify(e.value)}`).join(`
82
82
  `)}function cP({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: ${cn(e)}`,`Source file: ${o}`,`DOM id: ${t.id??"(none)"}`,`Selector: ${t.selector??"(none)"}`,`Selector index: ${t.selectorIndex??0}`,`Tag: <${t.tagName}>`,`Bounds: ${sP(t.boundingBox)}`];t.textContent&&c.push(`Text: ${t.textContent}`);const f=r==null?void 0:r.trim();f&&c.push("","Selection context:",f);const m=oP(t.textFields);m&&c.push("","Text fields:",m);const p=S3(t.inlineStyles);p&&c.push("","Inline styles:",p);const g=S3(t.computedStyles);return g&&c.push("","Computed styles (browser-resolved):",g),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(`
83
83
  `)}function uP({activeCompPath:t,projectDir:e,projectIdRef:n,currentTime:r,showToast:i,domEditSelectionRef:l,domEditSelection:o}){const[c,f]=h.useState(),[m,p]=h.useState(),[g,x]=h.useState(null),[v,S]=h.useState(!1),[w,A]=h.useState(!1),k=h.useRef(null),$=h.useCallback(async C=>{const P=n.current;if(!P)return;const M=C.sourceFile||t||"index.html";try{const j=await fetch(`/api/projects/${P}/files/${encodeURIComponent(M)}`);if(!j.ok)return;const z=(await j.json()).content,L=typeof z=="string"?$$(z,C):void 0;f(H=>l.current!==C?H:L)}catch{}},[t,l,n]),Q=h.useCallback(()=>{o&&(f(void 0),p(void 0),x(null),$(o),A(!0))},[o,$]),E=h.useCallback(async C=>{if(!o)return;const P=o.sourceFile||t||"index.html",M=c??o.element.outerHTML,j=cP({selection:o,currentTime:r,tagSnippet:M,selectionContext:m,userInstruction:C,sourceFilePath:MQ(e,P)});if(!await zc(j)){i("Could not copy prompt to clipboard.","error");return}A(!1),p(void 0),x(null),k.current&&clearTimeout(k.current),S(!0),k.current=setTimeout(()=>S(!1),1600)},[t,m,c,r,o,e,i]);return h.useEffect(()=>{f(void 0),p(void 0),x(null),S(!1)},[o]),h.useEffect(()=>()=>{k.current&&clearTimeout(k.current)},[]),{agentModalOpen:w,agentModalAnchorPoint:g,copiedAgentPrompt:v,agentPromptSelectionContext:m,setAgentModalOpen:A,setAgentPromptSelectionContext:p,setAgentModalAnchorPoint:x,preloadAgentPromptSnippet:$,handleAskAgent:Q,handleAgentModalSubmit:E}}function mS(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,m=(c==null?void 0:c.height)||n.innerHeight;if(!f||!m)return null;const p=l.width/f,g=l.height/m;return{x:(r-l.left)/p,y:(i-l.top)/g,viewport:{width:f,height:m}}}function fP(t,e,n){let r=null,i=null;try{r=t.contentDocument,i=t.contentWindow}catch{return null}return!r||!i?null:mS(t,r,i,e,n)}const hP="__hf_studio_pointer_events_override__";function dP(t){try{const e=t.createElement("style");return e.id=hP,e.textContent="* { pointer-events: auto !important; }",t.head.appendChild(e),e}catch{return null}}function mP(t){try{t==null||t.remove()}catch{}}function pP(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=mS(t,i,l,e,n);if(!o)return null;const c=dP(i);try{if(typeof i.elementsFromPoint=="function"){const m=WQ(i.elementsFromPoint(o.x,o.y),{activeCompositionPath:r});if(m)return m}const f=rS(i.elementFromPoint(o.x,o.y));return!f||!Af(f,r)||!sg(f)?null:f}finally{mP(c)}}function gP(t,e){return["The user clicked a large raster/background element in the Studio preview.",`Preview click: x=${Math.round(e.x)}px, y=${Math.round(e.y)}px in a ${Math.round(e.viewport.width)}x${Math.round(e.viewport.height)} composition.`,`Selected target: <${t.tagName}> ${t.selector??t.id??t.label}.`,"Visible copy or artwork at that point may be baked into the selected image/background rather than a selectable DOM text layer.","If the request mentions text seen at the click location, inspect or replace the image asset, or recreate that visible copy as editable DOM."].join(`
@@ -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-CGWN-iUB.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-D4g6rWoS.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-Ckqo37Co.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.9",
3
+ "version": "0.6.10",
4
4
  "description": "HyperFrames CLI — create, preview, and render HTML video compositions",
5
5
  "repository": {
6
6
  "type": "git",