hyperframes 0.6.8 → 0.6.9
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.9" : "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
|
});
|
|
@@ -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">
|
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-CGWN-iUB.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-Ckqo37Co.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|