hyperframes 0.6.8 → 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.
|
|
57
|
+
VERSION = true ? "0.6.10" : "0.0.0-dev";
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -25929,8 +25929,14 @@ function updateReferences(projectDir, oldPath, newPath) {
|
|
|
25929
25929
|
}
|
|
25930
25930
|
function registerFileRoutes(api, adapter2) {
|
|
25931
25931
|
api.get("/projects/:id/files/*", async (c3) => {
|
|
25932
|
-
const res = await resolveProjectFile(c3, adapter2
|
|
25932
|
+
const res = await resolveProjectFile(c3, adapter2);
|
|
25933
25933
|
if ("error" in res) return res.error;
|
|
25934
|
+
if (!existsSync10(res.absPath)) {
|
|
25935
|
+
if (c3.req.query("optional") === "1") {
|
|
25936
|
+
return c3.json({ filename: res.filePath, content: "" });
|
|
25937
|
+
}
|
|
25938
|
+
return c3.json({ error: "not found" }, 404);
|
|
25939
|
+
}
|
|
25934
25940
|
const content = readFileSync10(res.absPath, "utf-8");
|
|
25935
25941
|
return c3.json({ filename: res.filePath, content });
|
|
25936
25942
|
});
|
|
@@ -26292,35 +26298,80 @@ var init_htmlDocument = __esm({
|
|
|
26292
26298
|
// ../core/src/studio-api/helpers/subComposition.ts
|
|
26293
26299
|
import { existsSync as existsSync11, readFileSync as readFileSync11 } from "fs";
|
|
26294
26300
|
import { join as join14 } from "path";
|
|
26295
|
-
function
|
|
26296
|
-
|
|
26297
|
-
|
|
26298
|
-
|
|
26299
|
-
const templateMatch = rawComp.match(/<template[^>]*>([\s\S]*)<\/template>/i);
|
|
26300
|
-
const content = templateMatch?.[1] ?? rawComp;
|
|
26301
|
-
const { document: contentDoc } = parseHTML(
|
|
26302
|
-
`<!DOCTYPE html><html><head></head><body>${content}</body></html>`
|
|
26303
|
-
);
|
|
26301
|
+
function isFullHtmlDocument(html) {
|
|
26302
|
+
return /^\s*(?:<!doctype\s|<html[\s>])/i.test(html);
|
|
26303
|
+
}
|
|
26304
|
+
function rewriteRelativePaths(root, compPath) {
|
|
26304
26305
|
rewriteAssetPaths(
|
|
26305
|
-
|
|
26306
|
+
root.querySelectorAll("[src], [href]"),
|
|
26306
26307
|
compPath,
|
|
26307
26308
|
(el, attr) => el.getAttribute(attr),
|
|
26308
|
-
(el, attr, value) =>
|
|
26309
|
-
el.setAttribute(attr, value);
|
|
26310
|
-
}
|
|
26309
|
+
(el, attr, value) => el.setAttribute(attr, value)
|
|
26311
26310
|
);
|
|
26312
26311
|
rewriteInlineStyleAssetUrls(
|
|
26313
|
-
|
|
26312
|
+
root.querySelectorAll("[style]"),
|
|
26314
26313
|
compPath,
|
|
26315
26314
|
(el) => el.getAttribute("style"),
|
|
26316
|
-
(el, value) =>
|
|
26317
|
-
el.setAttribute("style", value);
|
|
26318
|
-
}
|
|
26315
|
+
(el, value) => el.setAttribute("style", value)
|
|
26319
26316
|
);
|
|
26320
|
-
for (const styleEl of
|
|
26317
|
+
for (const styleEl of root.querySelectorAll("style")) {
|
|
26321
26318
|
styleEl.textContent = rewriteCssAssetUrls(styleEl.textContent || "", compPath);
|
|
26322
26319
|
}
|
|
26323
|
-
|
|
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
|
+
}
|
|
26324
26375
|
const indexPath = join14(projectDir, "index.html");
|
|
26325
26376
|
let headContent = "";
|
|
26326
26377
|
if (existsSync11(indexPath)) {
|
|
@@ -26332,6 +26383,8 @@ function buildSubCompositionHtml(projectDir, compPath, runtimeUrl, baseHref) {
|
|
|
26332
26383
|
headContent = `<base href="${baseHref}">
|
|
26333
26384
|
${headContent}`;
|
|
26334
26385
|
}
|
|
26386
|
+
if (compHeadContent) headContent += `
|
|
26387
|
+
${compHeadContent}`;
|
|
26335
26388
|
if (!headContent.includes("hyperframe.runtime") && !headContent.includes("hyperframes-preview-runtime")) {
|
|
26336
26389
|
headContent += `
|
|
26337
26390
|
<script data-hyperframes-preview-runtime="1" src="${runtimeUrl}"></script>`;
|
|
@@ -26340,12 +26393,14 @@ ${headContent}`;
|
|
|
26340
26393
|
headContent += `
|
|
26341
26394
|
<script src="https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js"></script>`;
|
|
26342
26395
|
}
|
|
26396
|
+
const htmlOpen = htmlAttrs ? `<html ${htmlAttrs}>` : "<html>";
|
|
26397
|
+
const bodyOpen = bodyAttrs ? `<body ${bodyAttrs}>` : "<body>";
|
|
26343
26398
|
return `<!DOCTYPE html>
|
|
26344
|
-
|
|
26399
|
+
${htmlOpen}
|
|
26345
26400
|
<head>
|
|
26346
26401
|
${headContent}
|
|
26347
26402
|
</head>
|
|
26348
|
-
|
|
26403
|
+
${bodyOpen}
|
|
26349
26404
|
<script>window.__timelines=window.__timelines||{};</script>
|
|
26350
26405
|
${rewrittenContent}
|
|
26351
26406
|
</body>
|
|
@@ -68,7 +68,7 @@ Project path: ${window.location.href}
|
|
|
68
68
|
|
|
69
69
|
${m.join(`
|
|
70
70
|
|
|
71
|
-
`)}`;await zc(p)&&(c(!0),setTimeout(()=>c(!1),2e3))};return O.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:n,children:O.jsxs("div",{className:"bg-neutral-950 border border-neutral-800 rounded-xl shadow-2xl w-full max-w-xl max-h-[80vh] flex flex-col overflow-hidden",onClick:m=>m.stopPropagation(),children:[O.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-neutral-800",children:[O.jsxs("div",{className:"flex items-center gap-3",children:[l?O.jsx("div",{className:"w-8 h-8 rounded-full bg-red-500/10 flex items-center justify-center",children:O.jsx(S1,{size:18,className:"text-red-400",weight:"fill"})}):O.jsx("div",{className:"w-8 h-8 rounded-full bg-studio-accent/10 flex items-center justify-center",children:O.jsx(rv,{size:18,className:"text-studio-accent",weight:"fill"})}),O.jsxs("div",{children:[O.jsx("h2",{className:"text-sm font-semibold text-neutral-200",children:l?`${r.length} error${r.length!==1?"s":""}, ${i.length} warning${i.length!==1?"s":""}`:"All checks passed"}),O.jsx("p",{className:"text-xs text-neutral-500",children:"HyperFrame Lint Results"})]})]}),O.jsx("button",{onClick:n,className:"p-1.5 rounded-lg text-neutral-500 hover:text-neutral-200 hover:bg-neutral-800 transition-colors",children:O.jsx(Ip,{size:16})})]}),l&&O.jsx("div",{className:"flex items-center justify-end px-5 py-2 border-b border-neutral-800/50",children:O.jsx("button",{onClick:f,className:`px-3 py-1 text-xs font-medium rounded-lg transition-colors ${o?"bg-green-600 text-white":"bg-studio-accent hover:bg-studio-accent/80 text-white"}`,children:o?"Copied!":"Copy to Agent"})}),O.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-3",children:[!l&&O.jsx("div",{className:"py-8 text-center text-neutral-500 text-sm",children:"No errors or warnings found. Your composition looks good!"}),r.map((m,p)=>O.jsx("div",{className:"py-3 border-b border-neutral-800/50 last:border-0",children:O.jsxs("div",{className:"flex items-start gap-2",children:[O.jsx(S1,{size:14,className:"text-red-400 flex-shrink-0 mt-0.5",weight:"fill"}),O.jsxs("div",{className:"min-w-0",children:[O.jsx("p",{className:"text-sm text-neutral-200",children:m.message}),m.file&&O.jsx("p",{className:"text-xs text-neutral-600 font-mono mt-0.5",children:m.file}),m.fixHint&&O.jsxs("div",{className:"flex items-start gap-1 mt-1.5",children:[O.jsx(N1,{size:10,className:"text-studio-accent flex-shrink-0 mt-0.5"}),O.jsx("p",{className:"text-xs text-studio-accent",children:m.fixHint})]})]})]})},`e-${p}`)),i.map((m,p)=>O.jsx("div",{className:"py-3 border-b border-neutral-800/50 last:border-0",children:O.jsxs("div",{className:"flex items-start gap-2",children:[O.jsx(S1,{size:14,className:"text-amber-400 flex-shrink-0 mt-0.5"}),O.jsxs("div",{className:"min-w-0",children:[O.jsx("p",{className:"text-sm text-neutral-300",children:m.message}),m.file&&O.jsx("p",{className:"text-xs text-neutral-600 font-mono mt-0.5",children:m.file}),m.fixHint&&O.jsxs("div",{className:"flex items-start gap-1 mt-1.5",children:[O.jsx(N1,{size:10,className:"text-studio-accent flex-shrink-0 mt-0.5"}),O.jsx("p",{className:"text-xs text-studio-accent",children:m.fixHint})]})]})]})},`w-${p}`))]})]})})}function o$(t){const e=[];let n=0;for(const r of t.groupOrder){const i=t.groups.get(r);if(i)for(const l of i.segmentIds){const o=t.segments.get(l);if(o&&Object.keys(o.style).length>0){const c={wordIndex:n};o.wordId&&(c.wordId=o.wordId);const f=o.style;f.x!==void 0&&(c.x=f.x),f.y!==void 0&&(c.y=f.y),f.scaleX!==void 0&&(c.scale=f.scaleX),f.rotation!==void 0&&(c.rotation=f.rotation),f.activeColor!==void 0&&(c.activeColor=f.activeColor),f.dimColor!==void 0&&(c.dimColor=f.dimColor),f.opacity!==void 0&&(c.opacity=f.opacity),f.fontSize!==void 0&&(c.fontSize=f.fontSize),f.fontWeight!==void 0&&(c.fontWeight=f.fontWeight),f.fontFamily!==void 0&&(c.fontFamily=f.fontFamily),e.push(c)}n++}}return e}function c$(t){const e=h.useRef(t);e.current=t;const n=h.useRef(null),r=h.useRef(!1),i=h.useCallback(()=>{const o=et.getState();if(!o.model||!o.sourceFilePath||!o.isEditMode)return;const c=e.current;if(!c)return;const f=o$(o.model);fetch(`/api/projects/${c}/files/${encodeURIComponent("caption-overrides.json")}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:JSON.stringify(f,null,2)}).catch(m=>console.warn("[captions] auto-save failed:",m))},[]);Tt(()=>{let o=et.getState().model;const c=et.subscribe(f=>{if(!(!f.isEditMode||f.model===o||!f.model)){if(o=f.model,r.current){r.current=!1;return}n.current&&clearTimeout(n.current),n.current=setTimeout(i,800)}});return()=>{c(),n.current&&clearTimeout(n.current)}});const l=h.useCallback(async()=>{const o=et.getState();if(!o.model||!o.sourceFilePath)return;const c=e.current;if(c)try{const f=await fetch(`/api/projects/${c}/files/${encodeURIComponent("caption-overrides.json")}`);if(!f.ok)return;const m=await f.json();if(!m.content)return;const p=JSON.parse(m.content);if(!Array.isArray(p))return;const g=o.model,x=[],v=new Map;for(const w of g.groupOrder){const A=g.groups.get(w);if(A)for(const k of A.segmentIds){x.push(k);const $=g.segments.get(k);$!=null&&$.wordId&&v.set($.wordId,k)}}const S=new Map(g.segments);for(const w of p){const A=(w.wordId?v.get(w.wordId):void 0)??x[w.wordIndex];if(!A)continue;const k=S.get(A);if(!k)continue;const $={...k.style};w.x!==void 0&&($.x=w.x),w.y!==void 0&&($.y=w.y),w.scale!==void 0&&($.scaleX=w.scale,$.scaleY=w.scale),w.rotation!==void 0&&($.rotation=w.rotation),w.activeColor!==void 0&&($.activeColor=w.activeColor),w.dimColor!==void 0&&($.dimColor=w.dimColor),w.opacity!==void 0&&($.opacity=w.opacity),w.fontSize!==void 0&&($.fontSize=w.fontSize),w.fontWeight!==void 0&&($.fontWeight=w.fontWeight),w.fontFamily!==void 0&&($.fontFamily=w.fontFamily),S.set(A,{...k,style:$})}r.current=!0,et.getState().setModel({...g,segments:S})}catch{}},[]);return{save:i,loadOverrides:l}}const u$=100,f$=1500;function Mm(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}function Cm(t){return{version:1,updatedAt:0,undo:[],redo:[]}}function h$(t){const e={};for(const[n,r]of Object.entries(t.files))r.before!==r.after&&(e[n]={before:r.before,after:r.after,beforeHash:Mm(r.before),afterHash:Mm(r.after)});return{id:t.id,projectId:t.projectId,label:t.label,kind:t.kind??"manual",coalesceKey:t.coalesceKey,createdAt:t.now,files:e}}function d$(t,e,n){if(Object.keys(e.files).length===0)return t;const r=f$,i=u$,l=t.undo[t.undo.length-1];let o=t.undo;if(l&&l.coalesceKey&&l.coalesceKey===e.coalesceKey&&e.createdAt-l.createdAt<=r){const c={};for(const[f,m]of Object.entries(e.files)){const p=l.files[f];c[f]=p?{before:p.before,after:m.after,beforeHash:p.beforeHash,afterHash:m.afterHash}:m}o=[...t.undo.slice(0,-1),{...e,files:c}]}else o=[...t.undo,e];return{version:1,updatedAt:e.createdAt,undo:o.slice(Math.max(0,o.length-i)),redo:[]}}function Vv(t,e,n){for(const[r,i]of Object.entries(t.files)){const l=e==="undo"?i.afterHash:i.beforeHash;if(n[r]!==l)return{ok:!1,reason:"content-mismatch",path:r}}return{ok:!0}}function m$(t,e,n){const r=t.undo[t.undo.length-1];if(!r)return{ok:!1,reason:"empty",state:t,filesToWrite:{}};const i=Vv(r,"undo",e);return i.ok?{ok:!0,entry:r,filesToWrite:Object.fromEntries(Object.entries(r.files).map(([l,o])=>[l,o.before])),state:{version:1,updatedAt:n,undo:t.undo.slice(0,-1),redo:[...t.redo,r]}}:{ok:!1,reason:i.reason,path:i.path,state:t,filesToWrite:{}}}function p$(t,e,n){const r=t.redo[t.redo.length-1];if(!r)return{ok:!1,reason:"empty",state:t,filesToWrite:{}};const i=Vv(r,"redo",e);return i.ok?{ok:!0,entry:r,filesToWrite:Object.fromEntries(Object.entries(r.files).map(([l,o])=>[l,o.after])),state:{version:1,updatedAt:n,undo:[...t.undo,r],redo:t.redo.slice(0,-1)}}:{ok:!1,reason:i.reason,path:i.path,state:t,filesToWrite:{}}}const g$="hyperframes-studio-edit-history",O$=1,V1="project-history";function y$(){return new Promise((t,e)=>{if(!globalThis.indexedDB){e(new Error("IndexedDB is not available"));return}const n=globalThis.indexedDB.open(g$,O$);n.onupgradeneeded=()=>{const r=n.result;r.objectStoreNames.contains(V1)||r.createObjectStore(V1)},n.onerror=()=>e(n.error??new Error("Failed to open edit history db")),n.onsuccess=()=>t(n.result)})}function h2(t,e){return y$().then(n=>new Promise((r,i)=>{const l=n.transaction(V1,t),o=e(l.objectStore(V1));o.onerror=()=>i(o.error??new Error("IndexedDB request failed")),o.onsuccess=()=>r(o.result),l.oncomplete=()=>n.close(),l.onerror=()=>{n.close(),i(l.error??new Error("IndexedDB transaction failed"))}}))}function x$(){return{async get(t){return await h2("readonly",e=>e.get(t))??null},async set(t,e){await h2("readwrite",n=>n.put(e,t))},async delete(t){await h2("readwrite",e=>e.delete(t))}}}async function b$(t,e){return await t.get(e)??Cm()}async function v$(t,e,n){await t.set(e,n)}function S$(t){return`edit-${t.toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Lv(t){const e=t.undo[t.undo.length-1]??null,n=t.redo[t.redo.length-1]??null;return{canUndo:!!e,canRedo:!!n,undoLabel:(e==null?void 0:e.label)??null,redoLabel:(n==null?void 0:n.label)??null,undoPaths:e?Object.keys(e.files):[],redoPaths:n?Object.keys(n.files):[],state:t}}async function W5(t,e){const n={},r={};for(const i of t){const l=await e(i);n[i]=l,r[i]=Mm(l)}return{currentFiles:n,currentHashes:r}}async function G5({files:t,rollbackFiles:e,writeFile:n}){const r=[];try{for(const[i,l]of Object.entries(t))await n(i,l),r.push(i)}catch(i){try{for(const l of r.reverse())await n(l,e[l])}catch(l){throw new AggregateError([i,l],"Failed to apply edit history and rollback did not complete")}throw i}}function K5({projectId:t,storage:e,initialState:n,now:r=Date.now,onChange:i}){let l=n,o=Promise.resolve();const c=async m=>{l=m,i(m);try{await v$(e,t,m)}catch{}},f=async m=>{const p=o.then(async()=>{const{state:g,result:x}=await m(l);return g!==l&&await c(g),x});return o=p.then(()=>{},()=>{}),p};return{snapshot:()=>Lv(l),async recordEdit(m){await f(async p=>{const g=r(),x=h$({...m,id:S$(g),projectId:t,now:g});return{state:d$(p,x),result:void 0}})},async undo(m){return f(async p=>{const g=p.undo[p.undo.length-1];if(!g)return{state:p,result:{ok:!1,reason:"empty"}};const{currentFiles:x,currentHashes:v}=await W5(Object.keys(g.files),m.readFile),S=m$(p,v,r());return S.ok?(await G5({files:S.filesToWrite,rollbackFiles:x,writeFile:m.writeFile}),{state:S.state,result:{ok:!0,label:S.entry.label,paths:Object.keys(S.entry.files)}}):{state:p,result:{ok:!1,reason:S.reason}}})},async redo(m){return f(async p=>{const g=p.redo[p.redo.length-1];if(!g)return{state:p,result:{ok:!1,reason:"empty"}};const{currentFiles:x,currentHashes:v}=await W5(Object.keys(g.files),m.readFile),S=p$(p,v,r());return S.ok?(await G5({files:S.filesToWrite,rollbackFiles:x,writeFile:m.writeFile}),{state:S.state,result:{ok:!0,label:S.entry.label,paths:Object.keys(S.entry.files)}}):{state:p,result:{ok:!1,reason:S.reason}}})}}}function w$(t){const e=h.useMemo(()=>t.storage??x$(),[t.storage]),n=t.now??Date.now,[r,i]=h.useState(()=>Cm()),[l,o]=h.useState(!1),c=t.projectId,f=h.useRef(null);h.useEffect(()=>{let x=!1;const v=Cm();if(f.current=null,i(v),o(!1),!c){o(!0);return}return b$(e,c).then(S=>{x||(f.current=K5({projectId:c,storage:e,initialState:S,now:n,onChange:i}),i(S))}).catch(()=>{x||(f.current=K5({projectId:c,storage:e,initialState:v,now:n,onChange:i}),i(v))}).finally(()=>{x||o(!0)}),()=>{x=!0}},[n,c,e]);const m=h.useCallback(async x=>{var v;await((v=f.current)==null?void 0:v.recordEdit(x))},[]),p=h.useCallback(async x=>{var v;return((v=f.current)==null?void 0:v.undo(x))??{ok:!1,reason:"empty"}},[]),g=h.useCallback(async x=>{var v;return((v=f.current)==null?void 0:v.redo(x))??{ok:!1,reason:"empty"}},[]);return{loaded:l,...Lv(r),recordEdit:m,undo:p,redo:g}}function A$(t){const[e,n]=h.useState(240),[r,i]=h.useState(400),[l,o]=h.useState(()=>_c().leftCollapsed??!1),[c,f]=h.useState((t==null?void 0:t.rightCollapsed)??!0),[m,p]=h.useState((t==null?void 0:t.rightPanelTab)??"renders"),g=h.useRef(null),x=h.useCallback(()=>{o(A=>(Dc({leftCollapsed:!A}),!A))},[]),v=h.useCallback((A,k)=>{k.preventDefault(),k.target.setPointerCapture(k.pointerId),g.current={side:A,startX:k.clientX,startW:A==="left"?e:r}},[e,r]),S=h.useCallback(A=>{const k=g.current;if(!k)return;const $=A.clientX-k.startX,Q=Math.floor(window.innerWidth*.5),E=Math.max(160,Math.min(k.side==="left"?Q:600,k.startW+(k.side==="left"?$:-$)));k.side==="left"?n(E):i(E)},[]),w=h.useCallback(()=>{g.current=null},[]);return{leftWidth:e,setLeftWidth:n,rightWidth:r,leftCollapsed:l,setLeftCollapsed:o,rightCollapsed:c,setRightCollapsed:f,rightPanelTab:m,setRightPanelTab:p,toggleLeftSidebar:x,handlePanelResizeStart:v,handlePanelResizeMove:S,handlePanelResizeEnd:w}}const k$=/\.(eot|otf|ttc|ttf|woff2?)$/i,J5=/\s+(thin|extralight|extra light|light|regular|roman|medium|semibold|semi bold|bold|extrabold|extra bold|black|italic|oblique|variable)$/i;function e3(t){return JSON.stringify(t)}function Ks(t){const e=decodeURIComponent(t.split(/[\\/]/).pop()??t).replace(k$,"");let n=e.replace(/[_-]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim();for(;J5.test(n);)n=n.replace(J5,"").trim();return n||e}function Wp(t,e=t.url){return`@font-face { font-family: ${e3(t.family)}; src: url(${e3(e)}); font-display: swap; }`}async function fl({label:t,kind:e,coalesceKey:n,files:r,readFile:i,writeFile:l,recordEdit:o}){const c={};for(const[p,g]of Object.entries(r)){const x=await i(p);x!==g&&(c[p]={before:x,after:g})}const f=Object.keys(c);if(f.length===0)return[];const m=[];try{for(const p of f)await l(p,c[p].after),m.push(p);await o({label:t,kind:e,coalesceKey:n,files:c})}catch(p){try{for(const g of m.reverse())await l(g,c[g].before)}catch(g){throw new AggregateError([p,g],"Failed to save project files and rollback did not complete")}throw p}return f}function Zr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function t3(t,e){return e==='"'?t.replace(/"/g,"""):t.replace(/'/g,"'")}function _v(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function T$(t){return t.replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}function M$(t){const e=[];let n="",r=null,i=!1,l=0;for(const o of t){if(i){n+=o,o===";"&&(i=!1);continue}if(o==="&"){i=!0,n+=o;continue}if(r){n+=o,o===r&&(r=null);continue}if(o==='"'||o==="'"){r=o,n+=o;continue}if(o==="("){l+=1,n+=o;continue}if(o===")"){l=Math.max(0,l-1),n+=o;continue}if(o===";"&&l===0){e.push(n),n="";continue}n+=o}return n&&e.push(n),e}function C$(t,e,n,r){const l=new RegExp(`(<[^>]*\\bid=(["'])${Zr(e)}\\2[^>]*)>`,"i").exec(t);if(!l)return t;const o=l[1];return Dv(t,o,n,r)}function Dv(t,e,n,r){if(!e)return t;const i=/\bstyle=(["'])([\s\S]*?)\1/.exec(e);if(i){const l=i[2],o=i[1],c=new Map;for(const p of M$(l)){const g=p.indexOf(":");if(g<0)continue;const x=p.slice(0,g).trim(),v=p.slice(g+1).trim();x&&c.set(x,v)}r===null?c.delete(n):c.set(n,r);const f=Array.from(c.entries()).map(([p,g])=>`${p}: ${t3(g,o)}`).join("; "),m=e.replace(i[0],`style=${o}${f}${o}`);return t.replace(e,m)}else{if(r===null)return t;const l=e.replace(/>$/,"")+` style="${n}: ${t3(r,'"')}"`;return t.replace(e,l)}}function E$(t,e,n,r){const i=bl(t,e);if(!i)return t;const l=Dv(i.tag,i.tag,n,r);return w1(t,i,l)}function w1(t,e,n){return`${t.slice(0,e.start)}${n}${t.slice(e.end)}`}function bl(t,e){if(e.id){const l=new RegExp(`(<[^>]*\\bid=(["'])${Zr(e.id)}\\2[^>]*)>`,"i").exec(t);if((l==null?void 0:l.index)!=null)return{tag:l[1],start:l.index,end:l.index+l[1].length}}if(!e.selector)return null;const n=e.selector.match(/^\[data-composition-id="([^"]+)"\]$/);if(n){const i=n[1],o=new RegExp(`(<[^>]*\\bdata-composition-id=(["'])${Zr(i)}\\2[^>]*)>`,"i").exec(t);if((o==null?void 0:o.index)!=null)return{tag:o[1],start:o.index,end:o.index+o[1].length}}const r=e.selector.match(/^\.([a-zA-Z0-9_-]+)$/);if(r){const i=r[1],l=new RegExp(`(<[^>]*\\bclass=(["'])[^"']*\\b${Zr(i)}\\b[^"']*\\2[^>]*)>`,"gi"),o=e.selectorIndex??0;let c,f=0;for(;(c=l.exec(t))!==null;){if(f===o&&c.index!=null)return{tag:c[1],start:c.index,end:c.index+c[1].length};f+=1}}return null}function n3(t,e,n){const r=bl(t,e);if(!r)return;const i=n.startsWith("data-")?n:`data-${n}`,l=new RegExp(`\\b${i}=(["'])([^"']*)\\1`).exec(r.tag);return(l==null?void 0:l[2])!=null?T$(l[2]):void 0}function $$(t,e){const n=bl(t,e);return n==null?void 0:n.tag}function Q$(t,e,n,r){const i=bl(t,e);if(!i)return t;const l=n.startsWith("data-")?n:`data-${n}`,o=new RegExp(`\\b${Zr(l)}=(["'])([^"']*)\\1`),c=i.tag;if(r===null){if(!o.test(c))return t;const p=new RegExp(`\\s+${Zr(l)}=(["'])[^"']*\\1`),g=c.replace(p,"");return w1(t,i,g)}const f=_v(r);if(o.test(c)){const p=c.replace(o,`${l}="${f}"`);return w1(t,i,p)}const m=c+` ${l}="${f}"`;return w1(t,i,m)}function P$(t,e,n,r){const l=new RegExp(`(<[^>]*\\bid=(["'])${Zr(e)}\\2[^>]*)>`,"i").exec(t);if(!l)return t;const o=l[1],c=n.startsWith("data-")?n:`data-${n}`,f=new RegExp(`\\b${Zr(c)}=(["'])([^"']*)\\1`);if(r===null){if(!f.test(o))return t;const p=new RegExp(`\\s+${Zr(c)}=(["'])[^"']*\\1`),g=o.replace(p,"");return t.replace(o,g)}const m=_v(r);if(f.test(o)){const p=o.replace(f,`${c}="${m}"`);return t.replace(o,p)}else{const p=o+` ${c}="${m}"`;return t.replace(o,p)}}function Z$(t,e,n){const i=new RegExp(`(<([a-z0-9-]+)[^>]*\\bid=(["'])${Zr(e)}\\3[^>]*>)`,"i").exec(t);if(!i||i.index==null)return t;const l=i[1],o=i[2],c=i.index+l.length,f=Xv(t,o,c);return f<0?t:`${t.slice(0,c)}${n}${t.slice(f)}`}function Xv(t,e,n){const r=new RegExp(`</?${Zr(e)}\\b[^>]*>`,"gi");r.lastIndex=n;let i=1,l;for(;(l=r.exec(t))!==null;){const o=l[0];if(o.startsWith("</")){if(i-=1,i===0)return l.index;continue}o.endsWith("/>")||(i+=1)}return-1}function j$(t,e,n){const r=bl(t,e);if(!r)return t;const i=/^<([a-z0-9-]+)/i.exec(r.tag),l=i==null?void 0:i[1];if(!l)return t;const o=Xv(t,l,r.end+1);return o<0?t:`${t.slice(0,r.end+1)}${n}${t.slice(o)}`}function R$(t,e,n){switch(n.type){case"inline-style":return C$(t,e,n.property,n.value);case"attribute":return P$(t,e,n.property,n.value);case"text-content":return n.value!==null?Z$(t,e,n.value):t;default:return t}}function Zi(t,e,n){if(e.id){const r=R$(t,e.id,n);if(r!==t||!e.selector)return r}switch(n.type){case"inline-style":return E$(t,e,n.property,n.value);case"attribute":return Q$(t,e,n.property,n.value);case"text-content":return n.value!==null?j$(t,e,n.value):t;default:return t}}function N$({projectId:t,showToast:e,recordEdit:n,domEditSaveTimestampRef:r,setRefreshKey:i}){const[l,o]=h.useState(null),[c,f]=h.useState(null),[m,p]=h.useState([]),[g,x]=h.useState(!1),[v,S]=h.useState(null),w=h.useRef(l==null?void 0:l.path);w.current=l==null?void 0:l.path;const A=h.useRef(t);A.current=t;const k=h.useRef(null),$=h.useRef(null),Q=h.useRef([]);h.useEffect(()=>{if(!t){x(!1);return}let K=!1;return x(!1),fetch(`/api/projects/${t}`).then(ee=>ee.json()).then(ee=>{!K&&ee.files&&p(ee.files),K||f(typeof ee.dir=="string"?ee.dir:null)}).catch(()=>{K||f(null)}).finally(()=>{K||x(!0)}),()=>{K=!0}},[t]);const E=h.useCallback(async K=>{const ee=A.current;if(!ee)throw new Error("No active project");const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`);if(!te.ok)throw new Error(`Failed to read ${K}`);const ue=await te.json();if(typeof ue.content!="string")throw new Error(`Missing file contents for ${K}`);return ue.content},[]),C=h.useCallback(async(K,ee)=>{const te=A.current;if(!te)throw new Error("No active project");if(!(await fetch(`/api/projects/${te}/files/${encodeURIComponent(K)}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:ee})).ok)throw new Error(`Failed to save ${K}`);w.current===K&&o({path:K,content:ee})},[]),P=h.useCallback(async K=>{const ee=A.current;if(!ee)throw new Error("No active project");const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`);if(te.status===404)return"";if(!te.ok)throw new Error(`Failed to read ${K}`);const ue=await te.json();return typeof ue.content=="string"?ue.content:""},[]),M=h.useCallback(K=>{const ee=A.current;if(ee){if(Fb(K)){o({path:K,content:null});return}fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`).then(te=>te.json()).then(te=>{te.content!=null&&o({path:K,content:te.content})}).catch(()=>{})}},[]),j=h.useCallback(K=>{const ee=A.current;if(!ee)return;const te=w.current;te&&(k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{r.current=Date.now(),fl({projectId:ee,label:"Edit source",kind:"source",coalesceKey:`source:${te}`,files:{[te]:K},readFile:E,writeFile:C,recordEdit:n}).then(()=>{$.current&&clearTimeout($.current),$.current=setTimeout(()=>i(ue=>ue+1),600)}).catch(()=>{})},600))},[r,E,n,i,C]),_=h.useRef(0),z=h.useRef(null),L=h.useCallback((K,ee)=>{var oe;const te=A.current;if(!te||!K)return;if((oe=z.current)==null||oe.abort(),z.current=null,w.current===K&&(l==null?void 0:l.content)!=null){const ge=bl(l.content,ee);S(ge?ge.start:null);return}const ue=++_.current,me=new AbortController;z.current=me,fetch(`/api/projects/${te}/files/${encodeURIComponent(K)}`,{signal:me.signal}).then(ge=>ge.json()).then(ge=>{if(ue===_.current&&ge.content!=null){o({path:K,content:ge.content});const ve=bl(ge.content,ee);S(ve?ve.start:null)}}).catch(()=>{})},[l==null?void 0:l.content]),H=h.useCallback(async()=>{const K=A.current;if(!K)return;const te=await(await fetch(`/api/projects/${K}`)).json();te.files&&p(te.files)},[]),U=h.useCallback(async(K,ee)=>{var ge,ve;const te=A.current,ue=Array.from(K);if(!te||ue.length===0)return[];const me=new FormData;for(const we of ue)me.append("file",we);const oe=ee?`?dir=${encodeURIComponent(ee)}`:"";try{const we=await fetch(`/api/projects/${te}/upload${oe}`,{method:"POST",body:me});if(we.ok){const Ze=await we.json();if((ge=Ze.skipped)!=null&&ge.length&&e(`Skipped (too large): ${Ze.skipped.join(", ")}`),(ve=Ze.invalid)!=null&&ve.length){const Re=Ze.invalid.map(at=>at.name).join(", ");e(`Unsupported media skipped: ${Re}`)}return await H(),i(Re=>Re+1),Array.isArray(Ze.files)?Ze.files:[]}else we.status===413?e("Upload rejected: payload too large"):e(`Upload failed (${we.status})`)}catch{e("Upload failed: network error")}return[]},[H,i,e]),re=h.useCallback(async K=>{const ee=A.current;if(!ee)return;let te="";K.endsWith(".html")&&(te=`<!DOCTYPE html>
|
|
71
|
+
`)}`;await zc(p)&&(c(!0),setTimeout(()=>c(!1),2e3))};return O.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:n,children:O.jsxs("div",{className:"bg-neutral-950 border border-neutral-800 rounded-xl shadow-2xl w-full max-w-xl max-h-[80vh] flex flex-col overflow-hidden",onClick:m=>m.stopPropagation(),children:[O.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-neutral-800",children:[O.jsxs("div",{className:"flex items-center gap-3",children:[l?O.jsx("div",{className:"w-8 h-8 rounded-full bg-red-500/10 flex items-center justify-center",children:O.jsx(S1,{size:18,className:"text-red-400",weight:"fill"})}):O.jsx("div",{className:"w-8 h-8 rounded-full bg-studio-accent/10 flex items-center justify-center",children:O.jsx(rv,{size:18,className:"text-studio-accent",weight:"fill"})}),O.jsxs("div",{children:[O.jsx("h2",{className:"text-sm font-semibold text-neutral-200",children:l?`${r.length} error${r.length!==1?"s":""}, ${i.length} warning${i.length!==1?"s":""}`:"All checks passed"}),O.jsx("p",{className:"text-xs text-neutral-500",children:"HyperFrame Lint Results"})]})]}),O.jsx("button",{onClick:n,className:"p-1.5 rounded-lg text-neutral-500 hover:text-neutral-200 hover:bg-neutral-800 transition-colors",children:O.jsx(Ip,{size:16})})]}),l&&O.jsx("div",{className:"flex items-center justify-end px-5 py-2 border-b border-neutral-800/50",children:O.jsx("button",{onClick:f,className:`px-3 py-1 text-xs font-medium rounded-lg transition-colors ${o?"bg-green-600 text-white":"bg-studio-accent hover:bg-studio-accent/80 text-white"}`,children:o?"Copied!":"Copy to Agent"})}),O.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-3",children:[!l&&O.jsx("div",{className:"py-8 text-center text-neutral-500 text-sm",children:"No errors or warnings found. Your composition looks good!"}),r.map((m,p)=>O.jsx("div",{className:"py-3 border-b border-neutral-800/50 last:border-0",children:O.jsxs("div",{className:"flex items-start gap-2",children:[O.jsx(S1,{size:14,className:"text-red-400 flex-shrink-0 mt-0.5",weight:"fill"}),O.jsxs("div",{className:"min-w-0",children:[O.jsx("p",{className:"text-sm text-neutral-200",children:m.message}),m.file&&O.jsx("p",{className:"text-xs text-neutral-600 font-mono mt-0.5",children:m.file}),m.fixHint&&O.jsxs("div",{className:"flex items-start gap-1 mt-1.5",children:[O.jsx(N1,{size:10,className:"text-studio-accent flex-shrink-0 mt-0.5"}),O.jsx("p",{className:"text-xs text-studio-accent",children:m.fixHint})]})]})]})},`e-${p}`)),i.map((m,p)=>O.jsx("div",{className:"py-3 border-b border-neutral-800/50 last:border-0",children:O.jsxs("div",{className:"flex items-start gap-2",children:[O.jsx(S1,{size:14,className:"text-amber-400 flex-shrink-0 mt-0.5"}),O.jsxs("div",{className:"min-w-0",children:[O.jsx("p",{className:"text-sm text-neutral-300",children:m.message}),m.file&&O.jsx("p",{className:"text-xs text-neutral-600 font-mono mt-0.5",children:m.file}),m.fixHint&&O.jsxs("div",{className:"flex items-start gap-1 mt-1.5",children:[O.jsx(N1,{size:10,className:"text-studio-accent flex-shrink-0 mt-0.5"}),O.jsx("p",{className:"text-xs text-studio-accent",children:m.fixHint})]})]})]})},`w-${p}`))]})]})})}function o$(t){const e=[];let n=0;for(const r of t.groupOrder){const i=t.groups.get(r);if(i)for(const l of i.segmentIds){const o=t.segments.get(l);if(o&&Object.keys(o.style).length>0){const c={wordIndex:n};o.wordId&&(c.wordId=o.wordId);const f=o.style;f.x!==void 0&&(c.x=f.x),f.y!==void 0&&(c.y=f.y),f.scaleX!==void 0&&(c.scale=f.scaleX),f.rotation!==void 0&&(c.rotation=f.rotation),f.activeColor!==void 0&&(c.activeColor=f.activeColor),f.dimColor!==void 0&&(c.dimColor=f.dimColor),f.opacity!==void 0&&(c.opacity=f.opacity),f.fontSize!==void 0&&(c.fontSize=f.fontSize),f.fontWeight!==void 0&&(c.fontWeight=f.fontWeight),f.fontFamily!==void 0&&(c.fontFamily=f.fontFamily),e.push(c)}n++}}return e}function c$(t){const e=h.useRef(t);e.current=t;const n=h.useRef(null),r=h.useRef(!1),i=h.useCallback(()=>{const o=et.getState();if(!o.model||!o.sourceFilePath||!o.isEditMode)return;const c=e.current;if(!c)return;const f=o$(o.model);fetch(`/api/projects/${c}/files/${encodeURIComponent("caption-overrides.json")}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:JSON.stringify(f,null,2)}).catch(m=>console.warn("[captions] auto-save failed:",m))},[]);Tt(()=>{let o=et.getState().model;const c=et.subscribe(f=>{if(!(!f.isEditMode||f.model===o||!f.model)){if(o=f.model,r.current){r.current=!1;return}n.current&&clearTimeout(n.current),n.current=setTimeout(i,800)}});return()=>{c(),n.current&&clearTimeout(n.current)}});const l=h.useCallback(async()=>{const o=et.getState();if(!o.model||!o.sourceFilePath)return;const c=e.current;if(c)try{const f=await fetch(`/api/projects/${c}/files/${encodeURIComponent("caption-overrides.json")}`);if(!f.ok)return;const m=await f.json();if(!m.content)return;const p=JSON.parse(m.content);if(!Array.isArray(p))return;const g=o.model,x=[],v=new Map;for(const w of g.groupOrder){const A=g.groups.get(w);if(A)for(const k of A.segmentIds){x.push(k);const $=g.segments.get(k);$!=null&&$.wordId&&v.set($.wordId,k)}}const S=new Map(g.segments);for(const w of p){const A=(w.wordId?v.get(w.wordId):void 0)??x[w.wordIndex];if(!A)continue;const k=S.get(A);if(!k)continue;const $={...k.style};w.x!==void 0&&($.x=w.x),w.y!==void 0&&($.y=w.y),w.scale!==void 0&&($.scaleX=w.scale,$.scaleY=w.scale),w.rotation!==void 0&&($.rotation=w.rotation),w.activeColor!==void 0&&($.activeColor=w.activeColor),w.dimColor!==void 0&&($.dimColor=w.dimColor),w.opacity!==void 0&&($.opacity=w.opacity),w.fontSize!==void 0&&($.fontSize=w.fontSize),w.fontWeight!==void 0&&($.fontWeight=w.fontWeight),w.fontFamily!==void 0&&($.fontFamily=w.fontFamily),S.set(A,{...k,style:$})}r.current=!0,et.getState().setModel({...g,segments:S})}catch{}},[]);return{save:i,loadOverrides:l}}const u$=100,f$=1500;function Mm(t){let e=2166136261;for(let n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}function Cm(t){return{version:1,updatedAt:0,undo:[],redo:[]}}function h$(t){const e={};for(const[n,r]of Object.entries(t.files))r.before!==r.after&&(e[n]={before:r.before,after:r.after,beforeHash:Mm(r.before),afterHash:Mm(r.after)});return{id:t.id,projectId:t.projectId,label:t.label,kind:t.kind??"manual",coalesceKey:t.coalesceKey,createdAt:t.now,files:e}}function d$(t,e,n){if(Object.keys(e.files).length===0)return t;const r=f$,i=u$,l=t.undo[t.undo.length-1];let o=t.undo;if(l&&l.coalesceKey&&l.coalesceKey===e.coalesceKey&&e.createdAt-l.createdAt<=r){const c={};for(const[f,m]of Object.entries(e.files)){const p=l.files[f];c[f]=p?{before:p.before,after:m.after,beforeHash:p.beforeHash,afterHash:m.afterHash}:m}o=[...t.undo.slice(0,-1),{...e,files:c}]}else o=[...t.undo,e];return{version:1,updatedAt:e.createdAt,undo:o.slice(Math.max(0,o.length-i)),redo:[]}}function Vv(t,e,n){for(const[r,i]of Object.entries(t.files)){const l=e==="undo"?i.afterHash:i.beforeHash;if(n[r]!==l)return{ok:!1,reason:"content-mismatch",path:r}}return{ok:!0}}function m$(t,e,n){const r=t.undo[t.undo.length-1];if(!r)return{ok:!1,reason:"empty",state:t,filesToWrite:{}};const i=Vv(r,"undo",e);return i.ok?{ok:!0,entry:r,filesToWrite:Object.fromEntries(Object.entries(r.files).map(([l,o])=>[l,o.before])),state:{version:1,updatedAt:n,undo:t.undo.slice(0,-1),redo:[...t.redo,r]}}:{ok:!1,reason:i.reason,path:i.path,state:t,filesToWrite:{}}}function p$(t,e,n){const r=t.redo[t.redo.length-1];if(!r)return{ok:!1,reason:"empty",state:t,filesToWrite:{}};const i=Vv(r,"redo",e);return i.ok?{ok:!0,entry:r,filesToWrite:Object.fromEntries(Object.entries(r.files).map(([l,o])=>[l,o.after])),state:{version:1,updatedAt:n,undo:[...t.undo,r],redo:t.redo.slice(0,-1)}}:{ok:!1,reason:i.reason,path:i.path,state:t,filesToWrite:{}}}const g$="hyperframes-studio-edit-history",O$=1,V1="project-history";function y$(){return new Promise((t,e)=>{if(!globalThis.indexedDB){e(new Error("IndexedDB is not available"));return}const n=globalThis.indexedDB.open(g$,O$);n.onupgradeneeded=()=>{const r=n.result;r.objectStoreNames.contains(V1)||r.createObjectStore(V1)},n.onerror=()=>e(n.error??new Error("Failed to open edit history db")),n.onsuccess=()=>t(n.result)})}function h2(t,e){return y$().then(n=>new Promise((r,i)=>{const l=n.transaction(V1,t),o=e(l.objectStore(V1));o.onerror=()=>i(o.error??new Error("IndexedDB request failed")),o.onsuccess=()=>r(o.result),l.oncomplete=()=>n.close(),l.onerror=()=>{n.close(),i(l.error??new Error("IndexedDB transaction failed"))}}))}function x$(){return{async get(t){return await h2("readonly",e=>e.get(t))??null},async set(t,e){await h2("readwrite",n=>n.put(e,t))},async delete(t){await h2("readwrite",e=>e.delete(t))}}}async function b$(t,e){return await t.get(e)??Cm()}async function v$(t,e,n){await t.set(e,n)}function S$(t){return`edit-${t.toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Lv(t){const e=t.undo[t.undo.length-1]??null,n=t.redo[t.redo.length-1]??null;return{canUndo:!!e,canRedo:!!n,undoLabel:(e==null?void 0:e.label)??null,redoLabel:(n==null?void 0:n.label)??null,undoPaths:e?Object.keys(e.files):[],redoPaths:n?Object.keys(n.files):[],state:t}}async function W5(t,e){const n={},r={};for(const i of t){const l=await e(i);n[i]=l,r[i]=Mm(l)}return{currentFiles:n,currentHashes:r}}async function G5({files:t,rollbackFiles:e,writeFile:n}){const r=[];try{for(const[i,l]of Object.entries(t))await n(i,l),r.push(i)}catch(i){try{for(const l of r.reverse())await n(l,e[l])}catch(l){throw new AggregateError([i,l],"Failed to apply edit history and rollback did not complete")}throw i}}function K5({projectId:t,storage:e,initialState:n,now:r=Date.now,onChange:i}){let l=n,o=Promise.resolve();const c=async m=>{l=m,i(m);try{await v$(e,t,m)}catch{}},f=async m=>{const p=o.then(async()=>{const{state:g,result:x}=await m(l);return g!==l&&await c(g),x});return o=p.then(()=>{},()=>{}),p};return{snapshot:()=>Lv(l),async recordEdit(m){await f(async p=>{const g=r(),x=h$({...m,id:S$(g),projectId:t,now:g});return{state:d$(p,x),result:void 0}})},async undo(m){return f(async p=>{const g=p.undo[p.undo.length-1];if(!g)return{state:p,result:{ok:!1,reason:"empty"}};const{currentFiles:x,currentHashes:v}=await W5(Object.keys(g.files),m.readFile),S=m$(p,v,r());return S.ok?(await G5({files:S.filesToWrite,rollbackFiles:x,writeFile:m.writeFile}),{state:S.state,result:{ok:!0,label:S.entry.label,paths:Object.keys(S.entry.files)}}):{state:p,result:{ok:!1,reason:S.reason}}})},async redo(m){return f(async p=>{const g=p.redo[p.redo.length-1];if(!g)return{state:p,result:{ok:!1,reason:"empty"}};const{currentFiles:x,currentHashes:v}=await W5(Object.keys(g.files),m.readFile),S=p$(p,v,r());return S.ok?(await G5({files:S.filesToWrite,rollbackFiles:x,writeFile:m.writeFile}),{state:S.state,result:{ok:!0,label:S.entry.label,paths:Object.keys(S.entry.files)}}):{state:p,result:{ok:!1,reason:S.reason}}})}}}function w$(t){const e=h.useMemo(()=>t.storage??x$(),[t.storage]),n=t.now??Date.now,[r,i]=h.useState(()=>Cm()),[l,o]=h.useState(!1),c=t.projectId,f=h.useRef(null);h.useEffect(()=>{let x=!1;const v=Cm();if(f.current=null,i(v),o(!1),!c){o(!0);return}return b$(e,c).then(S=>{x||(f.current=K5({projectId:c,storage:e,initialState:S,now:n,onChange:i}),i(S))}).catch(()=>{x||(f.current=K5({projectId:c,storage:e,initialState:v,now:n,onChange:i}),i(v))}).finally(()=>{x||o(!0)}),()=>{x=!0}},[n,c,e]);const m=h.useCallback(async x=>{var v;await((v=f.current)==null?void 0:v.recordEdit(x))},[]),p=h.useCallback(async x=>{var v;return((v=f.current)==null?void 0:v.undo(x))??{ok:!1,reason:"empty"}},[]),g=h.useCallback(async x=>{var v;return((v=f.current)==null?void 0:v.redo(x))??{ok:!1,reason:"empty"}},[]);return{loaded:l,...Lv(r),recordEdit:m,undo:p,redo:g}}function A$(t){const[e,n]=h.useState(240),[r,i]=h.useState(400),[l,o]=h.useState(()=>_c().leftCollapsed??!1),[c,f]=h.useState((t==null?void 0:t.rightCollapsed)??!0),[m,p]=h.useState((t==null?void 0:t.rightPanelTab)??"renders"),g=h.useRef(null),x=h.useCallback(()=>{o(A=>(Dc({leftCollapsed:!A}),!A))},[]),v=h.useCallback((A,k)=>{k.preventDefault(),k.target.setPointerCapture(k.pointerId),g.current={side:A,startX:k.clientX,startW:A==="left"?e:r}},[e,r]),S=h.useCallback(A=>{const k=g.current;if(!k)return;const $=A.clientX-k.startX,Q=Math.floor(window.innerWidth*.5),E=Math.max(160,Math.min(k.side==="left"?Q:600,k.startW+(k.side==="left"?$:-$)));k.side==="left"?n(E):i(E)},[]),w=h.useCallback(()=>{g.current=null},[]);return{leftWidth:e,setLeftWidth:n,rightWidth:r,leftCollapsed:l,setLeftCollapsed:o,rightCollapsed:c,setRightCollapsed:f,rightPanelTab:m,setRightPanelTab:p,toggleLeftSidebar:x,handlePanelResizeStart:v,handlePanelResizeMove:S,handlePanelResizeEnd:w}}const k$=/\.(eot|otf|ttc|ttf|woff2?)$/i,J5=/\s+(thin|extralight|extra light|light|regular|roman|medium|semibold|semi bold|bold|extrabold|extra bold|black|italic|oblique|variable)$/i;function e3(t){return JSON.stringify(t)}function Ks(t){const e=decodeURIComponent(t.split(/[\\/]/).pop()??t).replace(k$,"");let n=e.replace(/[_-]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim();for(;J5.test(n);)n=n.replace(J5,"").trim();return n||e}function Wp(t,e=t.url){return`@font-face { font-family: ${e3(t.family)}; src: url(${e3(e)}); font-display: swap; }`}async function fl({label:t,kind:e,coalesceKey:n,files:r,readFile:i,writeFile:l,recordEdit:o}){const c={};for(const[p,g]of Object.entries(r)){const x=await i(p);x!==g&&(c[p]={before:x,after:g})}const f=Object.keys(c);if(f.length===0)return[];const m=[];try{for(const p of f)await l(p,c[p].after),m.push(p);await o({label:t,kind:e,coalesceKey:n,files:c})}catch(p){try{for(const g of m.reverse())await l(g,c[g].before)}catch(g){throw new AggregateError([p,g],"Failed to save project files and rollback did not complete")}throw p}return f}function Zr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function t3(t,e){return e==='"'?t.replace(/"/g,"""):t.replace(/'/g,"'")}function _v(t){return t.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function T$(t){return t.replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&")}function M$(t){const e=[];let n="",r=null,i=!1,l=0;for(const o of t){if(i){n+=o,o===";"&&(i=!1);continue}if(o==="&"){i=!0,n+=o;continue}if(r){n+=o,o===r&&(r=null);continue}if(o==='"'||o==="'"){r=o,n+=o;continue}if(o==="("){l+=1,n+=o;continue}if(o===")"){l=Math.max(0,l-1),n+=o;continue}if(o===";"&&l===0){e.push(n),n="";continue}n+=o}return n&&e.push(n),e}function C$(t,e,n,r){const l=new RegExp(`(<[^>]*\\bid=(["'])${Zr(e)}\\2[^>]*)>`,"i").exec(t);if(!l)return t;const o=l[1];return Dv(t,o,n,r)}function Dv(t,e,n,r){if(!e)return t;const i=/\bstyle=(["'])([\s\S]*?)\1/.exec(e);if(i){const l=i[2],o=i[1],c=new Map;for(const p of M$(l)){const g=p.indexOf(":");if(g<0)continue;const x=p.slice(0,g).trim(),v=p.slice(g+1).trim();x&&c.set(x,v)}r===null?c.delete(n):c.set(n,r);const f=Array.from(c.entries()).map(([p,g])=>`${p}: ${t3(g,o)}`).join("; "),m=e.replace(i[0],`style=${o}${f}${o}`);return t.replace(e,m)}else{if(r===null)return t;const l=e.replace(/>$/,"")+` style="${n}: ${t3(r,'"')}"`;return t.replace(e,l)}}function E$(t,e,n,r){const i=bl(t,e);if(!i)return t;const l=Dv(i.tag,i.tag,n,r);return w1(t,i,l)}function w1(t,e,n){return`${t.slice(0,e.start)}${n}${t.slice(e.end)}`}function bl(t,e){if(e.id){const l=new RegExp(`(<[^>]*\\bid=(["'])${Zr(e.id)}\\2[^>]*)>`,"i").exec(t);if((l==null?void 0:l.index)!=null)return{tag:l[1],start:l.index,end:l.index+l[1].length}}if(!e.selector)return null;const n=e.selector.match(/^\[data-composition-id="([^"]+)"\]$/);if(n){const i=n[1],o=new RegExp(`(<[^>]*\\bdata-composition-id=(["'])${Zr(i)}\\2[^>]*)>`,"i").exec(t);if((o==null?void 0:o.index)!=null)return{tag:o[1],start:o.index,end:o.index+o[1].length}}const r=e.selector.match(/^\.([a-zA-Z0-9_-]+)$/);if(r){const i=r[1],l=new RegExp(`(<[^>]*\\bclass=(["'])[^"']*\\b${Zr(i)}\\b[^"']*\\2[^>]*)>`,"gi"),o=e.selectorIndex??0;let c,f=0;for(;(c=l.exec(t))!==null;){if(f===o&&c.index!=null)return{tag:c[1],start:c.index,end:c.index+c[1].length};f+=1}}return null}function n3(t,e,n){const r=bl(t,e);if(!r)return;const i=n.startsWith("data-")?n:`data-${n}`,l=new RegExp(`\\b${i}=(["'])([^"']*)\\1`).exec(r.tag);return(l==null?void 0:l[2])!=null?T$(l[2]):void 0}function $$(t,e){const n=bl(t,e);return n==null?void 0:n.tag}function Q$(t,e,n,r){const i=bl(t,e);if(!i)return t;const l=n.startsWith("data-")?n:`data-${n}`,o=new RegExp(`\\b${Zr(l)}=(["'])([^"']*)\\1`),c=i.tag;if(r===null){if(!o.test(c))return t;const p=new RegExp(`\\s+${Zr(l)}=(["'])[^"']*\\1`),g=c.replace(p,"");return w1(t,i,g)}const f=_v(r);if(o.test(c)){const p=c.replace(o,`${l}="${f}"`);return w1(t,i,p)}const m=c+` ${l}="${f}"`;return w1(t,i,m)}function P$(t,e,n,r){const l=new RegExp(`(<[^>]*\\bid=(["'])${Zr(e)}\\2[^>]*)>`,"i").exec(t);if(!l)return t;const o=l[1],c=n.startsWith("data-")?n:`data-${n}`,f=new RegExp(`\\b${Zr(c)}=(["'])([^"']*)\\1`);if(r===null){if(!f.test(o))return t;const p=new RegExp(`\\s+${Zr(c)}=(["'])[^"']*\\1`),g=o.replace(p,"");return t.replace(o,g)}const m=_v(r);if(f.test(o)){const p=o.replace(f,`${c}="${m}"`);return t.replace(o,p)}else{const p=o+` ${c}="${m}"`;return t.replace(o,p)}}function Z$(t,e,n){const i=new RegExp(`(<([a-z0-9-]+)[^>]*\\bid=(["'])${Zr(e)}\\3[^>]*>)`,"i").exec(t);if(!i||i.index==null)return t;const l=i[1],o=i[2],c=i.index+l.length,f=Xv(t,o,c);return f<0?t:`${t.slice(0,c)}${n}${t.slice(f)}`}function Xv(t,e,n){const r=new RegExp(`</?${Zr(e)}\\b[^>]*>`,"gi");r.lastIndex=n;let i=1,l;for(;(l=r.exec(t))!==null;){const o=l[0];if(o.startsWith("</")){if(i-=1,i===0)return l.index;continue}o.endsWith("/>")||(i+=1)}return-1}function j$(t,e,n){const r=bl(t,e);if(!r)return t;const i=/^<([a-z0-9-]+)/i.exec(r.tag),l=i==null?void 0:i[1];if(!l)return t;const o=Xv(t,l,r.end+1);return o<0?t:`${t.slice(0,r.end+1)}${n}${t.slice(o)}`}function R$(t,e,n){switch(n.type){case"inline-style":return C$(t,e,n.property,n.value);case"attribute":return P$(t,e,n.property,n.value);case"text-content":return n.value!==null?Z$(t,e,n.value):t;default:return t}}function Zi(t,e,n){if(e.id){const r=R$(t,e.id,n);if(r!==t||!e.selector)return r}switch(n.type){case"inline-style":return E$(t,e,n.property,n.value);case"attribute":return Q$(t,e,n.property,n.value);case"text-content":return n.value!==null?j$(t,e,n.value):t;default:return t}}function N$({projectId:t,showToast:e,recordEdit:n,domEditSaveTimestampRef:r,setRefreshKey:i}){const[l,o]=h.useState(null),[c,f]=h.useState(null),[m,p]=h.useState([]),[g,x]=h.useState(!1),[v,S]=h.useState(null),w=h.useRef(l==null?void 0:l.path);w.current=l==null?void 0:l.path;const A=h.useRef(t);A.current=t;const k=h.useRef(null),$=h.useRef(null),Q=h.useRef([]);h.useEffect(()=>{if(!t){x(!1);return}let K=!1;return x(!1),fetch(`/api/projects/${t}`).then(ee=>ee.json()).then(ee=>{!K&&ee.files&&p(ee.files),K||f(typeof ee.dir=="string"?ee.dir:null)}).catch(()=>{K||f(null)}).finally(()=>{K||x(!0)}),()=>{K=!0}},[t]);const E=h.useCallback(async K=>{const ee=A.current;if(!ee)throw new Error("No active project");const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`);if(!te.ok)throw new Error(`Failed to read ${K}`);const ue=await te.json();if(typeof ue.content!="string")throw new Error(`Missing file contents for ${K}`);return ue.content},[]),C=h.useCallback(async(K,ee)=>{const te=A.current;if(!te)throw new Error("No active project");if(!(await fetch(`/api/projects/${te}/files/${encodeURIComponent(K)}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:ee})).ok)throw new Error(`Failed to save ${K}`);w.current===K&&o({path:K,content:ee})},[]),P=h.useCallback(async K=>{const ee=A.current;if(!ee)throw new Error("No active project");const te=await fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}?optional=1`);if(!te.ok)throw new Error(`Failed to read ${K}`);const ue=await te.json();return typeof ue.content=="string"?ue.content:""},[]),M=h.useCallback(K=>{const ee=A.current;if(ee){if(Fb(K)){o({path:K,content:null});return}fetch(`/api/projects/${ee}/files/${encodeURIComponent(K)}`).then(te=>te.json()).then(te=>{te.content!=null&&o({path:K,content:te.content})}).catch(()=>{})}},[]),j=h.useCallback(K=>{const ee=A.current;if(!ee)return;const te=w.current;te&&(k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{r.current=Date.now(),fl({projectId:ee,label:"Edit source",kind:"source",coalesceKey:`source:${te}`,files:{[te]:K},readFile:E,writeFile:C,recordEdit:n}).then(()=>{$.current&&clearTimeout($.current),$.current=setTimeout(()=>i(ue=>ue+1),600)}).catch(()=>{})},600))},[r,E,n,i,C]),_=h.useRef(0),z=h.useRef(null),L=h.useCallback((K,ee)=>{var oe;const te=A.current;if(!te||!K)return;if((oe=z.current)==null||oe.abort(),z.current=null,w.current===K&&(l==null?void 0:l.content)!=null){const ge=bl(l.content,ee);S(ge?ge.start:null);return}const ue=++_.current,me=new AbortController;z.current=me,fetch(`/api/projects/${te}/files/${encodeURIComponent(K)}`,{signal:me.signal}).then(ge=>ge.json()).then(ge=>{if(ue===_.current&&ge.content!=null){o({path:K,content:ge.content});const ve=bl(ge.content,ee);S(ve?ve.start:null)}}).catch(()=>{})},[l==null?void 0:l.content]),H=h.useCallback(async()=>{const K=A.current;if(!K)return;const te=await(await fetch(`/api/projects/${K}`)).json();te.files&&p(te.files)},[]),U=h.useCallback(async(K,ee)=>{var ge,ve;const te=A.current,ue=Array.from(K);if(!te||ue.length===0)return[];const me=new FormData;for(const we of ue)me.append("file",we);const oe=ee?`?dir=${encodeURIComponent(ee)}`:"";try{const we=await fetch(`/api/projects/${te}/upload${oe}`,{method:"POST",body:me});if(we.ok){const Ze=await we.json();if((ge=Ze.skipped)!=null&&ge.length&&e(`Skipped (too large): ${Ze.skipped.join(", ")}`),(ve=Ze.invalid)!=null&&ve.length){const Re=Ze.invalid.map(at=>at.name).join(", ");e(`Unsupported media skipped: ${Re}`)}return await H(),i(Re=>Re+1),Array.isArray(Ze.files)?Ze.files:[]}else we.status===413?e("Upload rejected: payload too large"):e(`Upload failed (${we.status})`)}catch{e("Upload failed: network error")}return[]},[H,i,e]),re=h.useCallback(async K=>{const ee=A.current;if(!ee)return;let te="";K.endsWith(".html")&&(te=`<!DOCTYPE html>
|
|
72
72
|
<html>
|
|
73
73
|
<head>
|
|
74
74
|
<meta charset="UTF-8">
|
|
@@ -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,"&").replace(/</g,"<").replace(/>/g,">")}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,""")}"`).join(""),r=iP(e),i=r?` style="${r.replace(/"/g,""")}"`:"";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,"&").replace(/</g,"<").replace(/>/g,">")}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,""")}"`).join(""),r=iP(e),i=r?` style="${r.replace(/"/g,""")}"`:"";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(`
|
package/dist/studio/index.html
CHANGED
|
@@ -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-
|
|
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>
|