@officexapp/vidfarm-devcli 0.21.14 → 0.21.15

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/demo/dist/app.js CHANGED
@@ -883,7 +883,7 @@ Then run the review loop from the hyperframes-core skill (references/review-loop
883
883
  [data-caption-animation="glow-pulse"] [data-cap-word] { animation-name:vf-cap-glow; }
884
884
  @keyframes vf-cap-bounce { 25% { transform:translateY(-0.22em) scale(1.08); } 55% { transform:translateY(0.05em); } 75% { transform:none; } }
885
885
  [data-caption-animation="bounce-wave"] [data-cap-word] { animation-name:vf-cap-bounce; }
886
- `,mYe=[{id:"spotlight",animation:"highlight-pop",color:"#ffffff",background:"#000000",textBackgroundStyle:"outline",highlightColor:"#7C3AED",activeColor:"#ffffff",fontWeight:800,uppercase:!0},{id:"karaoke",animation:"karaoke-fill",color:"#ffffff",background:"#000000",textBackgroundStyle:"outline",activeColor:"#FFE14D",fontWeight:800},{id:"word-pop",animation:"word-pop",color:"#ffffff",background:"#000000",textBackgroundStyle:"outline",fontWeight:900,uppercase:!0},{id:"stack-up",animation:"cumulative-reveal",color:"#ffffff",background:"#000000",textBackgroundStyle:"highlight-translucent",fontWeight:700},{id:"neon",animation:"glow-pulse",color:"#eafff1",background:"#04140a",textBackgroundStyle:"plain",activeColor:"#9BFF57",fontWeight:800,uppercase:!0},{id:"bounce",animation:"bounce-wave",color:"#FFE14D",background:"#000000",textBackgroundStyle:"outline",activeColor:"#FFE14D",fontWeight:900,uppercase:!0}];function gYe(t){if(!t)return null;let e=String(t).trim().toLowerCase();return mYe.find(r=>r.id===e)??null}function yYe(t){return t&&hYe.includes(t)?t:null}function $0e(t,e){let r=String(t||"").trim().split(/\s+/).filter(Boolean),n=Number.isFinite(e)&&e>0?e:r.length*.32;if(!r.length)return[];let i=r.map(l=>Math.max(2,l.length)+1.5),o=i.reduce((l,c)=>l+c,0),a=[],s=0;for(let l=0;l<r.length;l+=1){let c=i[l]/o*n,u=Math.min(.03,c*.1);a.push({text:r[l],start:Number(s.toFixed(3)),end:Number(Math.max(s+.05,s+c-u).toFixed(3))}),s+=c}return a}function _rr(t,e,r,n=4){let i=$0e(t,r),o=[],a=[],s=()=>{if(!a.length)return;let l=a[0].start,c=a[a.length-1].end+.12;o.push({text:a.map(u=>u.text).join(" "),start:Number((e+l).toFixed(3)),duration:Number(Math.max(.2,c-l).toFixed(3)),words:a.map(u=>({text:u.text,start:Number((u.start-l).toFixed(3)),end:Number((u.end-l).toFixed(3))}))}),a=[]};for(let l of i)(a.length>=n||a.length>0&&/[.!?…]["')\]]?$/.test(a[a.length-1].text))&&s(),a.push(l);s();for(let l=0;l<o.length-1;l+=1){let c=o[l+1].start-.02;o[l].start+o[l].duration>c&&(o[l].duration=Number(Math.max(.1,c-o[l].start).toFixed(3)))}return o}function XM(t){return t==="Georgia"?"Georgia":`'${t}'`}function bYe(t,e){let r=t.trim(),n=r.startsWith("#")?r.slice(1):"";if(n.length===3||n.length===6){let i=n.length===3?n.split("").map(a=>a+a).join(""):n,o=Number.parseInt(i,16);if(Number.isFinite(o))return`rgba(${o>>16&255}, ${o>>8&255}, ${o&255}, ${e})`}return r.startsWith("rgba(")||r.startsWith("rgb(")?r:`rgba(0, 0, 0, ${e})`}function xYe(t){return t==="plain"||t==="outline"||t==="highlight-solid"||t==="highlight-translucent"?t:"plain"}function Irr(t,e,r,n,i){let o=["display:inline","box-decoration-break:clone","-webkit-box-decoration-break:clone","line-height:inherit"];return t==="plain"&&o.push("padding:0","border-radius:0","background:transparent","text-shadow:none","-webkit-text-stroke:0 transparent"),t==="outline"&&o.push("padding:0","border-radius:0","background:transparent",`text-shadow:2px 0 ${r},-2px 0 ${r},0 2px ${r},0 -2px ${r},1.5px 1.5px ${r},-1.5px 1.5px ${r},1.5px -1.5px ${r},-1.5px -1.5px ${r}`,`-webkit-text-stroke:1.5px ${r}`,"paint-order:stroke fill"),t==="highlight-solid"&&o.push("padding:0.07em 0.46em 0.09em","border-radius:0.32em",`background:${r}`,"text-shadow:none","-webkit-text-stroke:0 transparent"),t==="highlight-translucent"&&o.push("padding:0.07em 0.46em 0.09em","border-radius:0.32em",`background:${bYe(r,.34)}`,"text-shadow:none","-webkit-text-stroke:0 transparent"),n&&o.push(`font-family:${XM(n)}, 'TikTok Sans'`),i&&o.push(`font-weight:${i}`),o.push(`color:${e}`),o.join(";")}function vYe(t,e,r,n,i,o,a){t.textContent="",t.style.background="transparent",t.setAttribute("data-text-background-style",r),t.setAttribute("data-text-background-color",i),o&&(t.setAttribute("data-font-family",o),t.style.fontFamily=`${XM(o)}, 'TikTok Sans'`),a&&(t.style.fontWeight=String(a));let s=t.ownerDocument,l=s.createElement("span");l.setAttribute("data-vf-text-lines","true"),l.style.cssText="display:block;max-width:100%;text-align:inherit;line-height:1.48;white-space:pre-wrap;overflow:visible";let c=s.createElement("span");c.setAttribute("data-vf-text-inline","true"),o&&c.setAttribute("data-font-family",o),c.style.cssText=Irr(r,n,i,o,a),c.textContent=e,l.append(c),t.append(l)}function SYe(t){return Array.from(t.querySelectorAll("[data-cap-word]")).map(e=>({text:(e.textContent||"").trim(),start:Number(e.getAttribute("data-word-start"))||0,end:Number(e.getAttribute("data-word-end"))||0})).filter(e=>e.text)}function AYe(t){let e=SYe(t);return e.length?e.map(r=>r.text).join(" "):t.querySelector("[data-vf-text-inline]")?.textContent||t.textContent||""}function nZ(t,e,r){if(!t.hasAttribute("data-caption-animation"))return;let n=t.querySelector("[data-vf-text-inline]");if(!n)return;let i=SYe(t),o=e!==void 0?e:i.length?i.map(c=>c.text).join(" "):n.textContent||"",a=String(o||"").trim().split(/\s+/).filter(Boolean),s;r&&r.length?s=r:i.length===a.length&&i.every((c,u)=>c.text===a[u])&&i.some(c=>c.end>c.start)?s=i:s=$0e(a.join(" "),sf(t)),n.textContent="";let l=t.ownerDocument;s.forEach((c,u)=>{let f=l.createElement("span");f.setAttribute("data-cap-word","true"),f.setAttribute("data-word-start",String(Number(c.start.toFixed(3)))),f.setAttribute("data-word-end",String(Number(c.end.toFixed(3)))),f.style.animationDelay=`${Number(c.start.toFixed(3))}s`,f.style.animationDuration=`${Number(Math.max(.05,c.end-c.start).toFixed(3))}s`,f.textContent=c.text,u>0&&n.append(l.createTextNode(" ")),n.append(f)})}function wYe(t,e,r){let n=yYe(e);if(!n){let i=AYe(t).trim();t.removeAttribute("data-caption-animation"),t.hasAttribute("data-caption-uppercase")&&(t.removeAttribute("data-caption-uppercase"),t.style.textTransform="none"),t.style.removeProperty("--vf-cap-active"),t.style.removeProperty("--vf-cap-hl");let o=t.querySelector("[data-vf-text-inline]");o&&i&&(o.textContent=i);return}t.setAttribute("data-caption-animation",n),r?.uppercase!==void 0&&(r.uppercase?t.setAttribute("data-caption-uppercase","1"):t.removeAttribute("data-caption-uppercase"),t.style.textTransform=r.uppercase?"uppercase":"none"),r?.activeColor&&t.style.setProperty("--vf-cap-active",r.activeColor),r?.highlightColor&&t.style.setProperty("--vf-cap-hl",r.highlightColor),nZ(t,r?.text,r?.words)}function Prr(t){if(!t.querySelector("[data-caption-animation]"))return;for(let r of Array.from(t.querySelectorAll("style")))if((r.textContent??"").includes(pYe))return;let e=t.createElement("style");e.textContent=krr,(t.head??t.documentElement)?.appendChild(e)}function EYe(t,e,r,n){let i=Xe(r,"caption_animation")==="none",o=i?null:gYe(Xe(r,"caption_style"))??(Xe(r,"caption_animation")?null:mYe[0]),a=i?null:yYe(Xe(r,"caption_animation")??o?.animation);if(!i&&!a)return{ok:!1,error:`Unknown caption_animation "${Xe(r,"caption_animation")}". Use one of: ${hYe.join(", ")}, or "none" for static captions.`};let l=(Array.isArray(r.captions)?r.captions:[]).filter(C=>C&&typeof C.text=="string"&&C.text.trim()&&typeof C.start=="number"&&typeof C.duration=="number"&&C.duration>0).map(C=>{let k=Array.isArray(C.words)?C.words.map(_=>({text:String(_.text??"").trim(),start:Number(_.start)||0,end:Number(_.end)||0})).filter(_=>_.text&&_.end>_.start):[];return{text:C.text.trim(),start:C.start,duration:C.duration,words:k.length?k:$0e(C.text,C.duration)}});if(!l.length&&Xe(r,"text")){let C=n>0?n:60,k=Math.max(0,et(r,"start")??0),_=Math.max(.4,et(r,"duration")??C-k);l=_rr(Xe(r,"text"),k,_)}if(!l.length)return{ok:!1,error:"set_captions needs captions (array of {text,start,duration,words?}) or text (+ optional start/duration window)."};let c=Xe(r,"color")??o?.color??"#ffffff",u=Xe(r,"background")??o?.background??"#000000",f=xYe(Xe(r,"background_style")??o?.textBackgroundStyle),p=(C,k)=>C!=null&&C>0?C:k,d=(C,k)=>C??k,h=Xe(r,"font_family")?.trim()||"Montserrat",m=et(r,"font_weight")??o?.fontWeight??800,g=p(et(r,"font_size"),38),y={x:Pb(d(et(r,"x"),10),0,100),y:Pb(d(et(r,"y"),70),0,100),width:Pb(p(et(r,"width"),80),1,100),height:Pb(p(et(r,"height"),14),1,100)},b=0,x=new Set;for(let C of Array.from(t.querySelectorAll("[data-caption-animation]")))x.add(C);for(let C of Array.from(t.querySelectorAll('[data-layer-kind="caption"]')))x.add(C);for(let C of x)C.parentNode?.removeChild(C),b+=1;let S=Math.min(...l.map(C=>C.start)),v=Math.max(...l.map(C=>C.start+C.duration)),w=et(r,"track")!=null?Math.max(0,Math.floor(et(r,"track"))):qM(t)+1,A=YM(t,S,Math.max(.1,v-S),w),E=p0(r,"caption_uppercase")??o?.uppercase,O=Date.now().toString(36);l.forEach((C,k)=>{let _=`vf_cap_${O}_${k}`,P=t.createElement("div");P.id=_,P.setAttribute("data-hf-id",_),P.setAttribute("data-layer-mode","publish"),P.setAttribute("data-layer-kind","caption"),P.setAttribute("data-start",jr(C.start)),P.setAttribute("data-duration",jr(C.duration)),P.setAttribute("data-end",jr(C.start+C.duration)),Mb(P,A),P.setAttribute("data-label",C.text.slice(0,48)),P.classList.add("clip"),P.setAttribute("data-text-background-style",f),P.setAttribute("data-text-background-color",u),P.setAttribute("data-font-family",h),P.style.position="absolute",P.style.left=`${y.x}%`,P.style.top=`${y.y}%`,P.style.width=`${y.width}%`,P.style.height=`${y.height}%`,P.style.zIndex=String(A),P.style.display="flex",P.style.alignItems="center",P.style.justifyContent="center",P.style.padding="3px",P.style.boxSizing="border-box",P.style.textAlign="center",P.style.color=c,P.style.background="transparent",P.style.fontFamily=`${XM(h)}, 'TikTok Sans', sans-serif`,P.style.fontWeight=String(m),P.style.fontSize=`${g}px`,P.style.lineHeight="1.2",P.style.overflow="visible",vYe(P,C.text,f,c,u,h,m),a&&wYe(P,a,{activeColor:Xe(r,"caption_active_color")??o?.activeColor,highlightColor:Xe(r,"caption_highlight_color")??o?.highlightColor,uppercase:E,text:C.text,words:C.words}),e.append(P)}),Prr(t);let T=b>0?` (replaced ${b} previous caption cue(s))`:"";return{ok:!0,summary:`Set ${l.length} ${a?"animated":"static"} caption cue(s) on track ${A}, style ${o?.id??a??"none (static text)"}${T}.`}}function OYe(t,e){let r=[],n=t.querySelector("[data-vf-text-inline]"),i=Xe(e,"color");i&&(t.style.color=i,n&&(n.style.color=i),r.push(`color=${i}`));let o=Xe(e,"background_style"),a=Xe(e,"background");if(o||a&&n){let v=xYe(o??t.getAttribute("data-text-background-style")),w=a??t.getAttribute("data-text-background-color")??"#000000",A=i??t.style.color??"#ffffff";if(n){let E=t.getAttribute("data-font-family")??void 0,O=AYe(t);vYe(t,O,v,A,w,E,void 0),t.hasAttribute("data-caption-animation")&&nZ(t,O)}else v==="plain"?(t.style.background="transparent",t.style.textShadow="none"):v==="outline"?(t.style.background="transparent",t.style.setProperty("-webkit-text-stroke",`1.5px ${w}`),t.style.textShadow=`2px 0 ${w},-2px 0 ${w},0 2px ${w},0 -2px ${w}`):(t.style.background=v==="highlight-translucent"?bYe(w,.34):w,t.style.padding="0.07em 0.46em 0.09em",t.style.borderRadius="0.32em");o&&r.push(`background_style=${v}`),a&&r.push(`background=${a}`)}else a&&(t.style.background=a,r.push(`background=${a}`));let s=et(e,"font_size");s!=null&&(t.style.fontSize=`${s}px`,r.push(`font_size=${s}`));let l=Xe(e,"font_family");l&&(t.setAttribute("data-font-family",l),t.style.fontFamily=`${XM(l)}, 'TikTok Sans'`,n&&(n.style.fontFamily=`${XM(l)}, 'TikTok Sans'`),r.push(`font_family=${l}`));let c=et(e,"font_weight");c!=null&&(t.style.fontWeight=String(c),n&&(n.style.fontWeight=String(c)),r.push(`font_weight=${c}`));let u=p0(e,"italic");u!=null&&(t.style.fontStyle=u?"italic":"normal",r.push(`italic=${u}`));let f=p0(e,"underline");f!=null&&(t.style.textDecorationLine=f?"underline":"none",r.push(`underline=${f}`));let p=Xe(e,"text_align");p&&(t.style.textAlign=p,r.push(`text_align=${p}`));let d=et(e,"line_height");d!=null&&(t.style.lineHeight=String(d),r.push(`line_height=${d}`));let h=et(e,"letter_spacing");h!=null&&(t.style.letterSpacing=`${h}px`,r.push(`letter_spacing=${h}`));let m=et(e,"border_radius");m!=null&&(t.style.borderRadius=`${m}px`,r.push(`border_radius=${m}`));let g=gYe(Xe(e,"caption_style")),y=Xe(e,"caption_animation")??g?.animation,b=Xe(e,"caption_active_color")??g?.activeColor,x=Xe(e,"caption_highlight_color")??g?.highlightColor,S=p0(e,"caption_uppercase")??g?.uppercase;if(g&&r.push(`caption_style=${g.id}`),y!==void 0||b!==void 0||x!==void 0||S!==void 0){let v=y==="none"?null:y??t.getAttribute("data-caption-animation");wYe(t,v,{activeColor:b,highlightColor:x,uppercase:S}),r.push(`caption_animation=${v??"none"}`)}return r}function Nrr(t){let e=(t??"").trim().toLowerCase();return["linear","ease","ease-in","ease-out","ease-in-out","step-start","step-end"].includes(e)||/^cubic-bezier\(\s*(-?\d*\.?\d+\s*,\s*){3}-?\d*\.?\d+\s*\)$/.test(e)||/^steps\(\s*\d+\s*(,\s*(start|end|jump-(start|end|none|both))\s*)?\)$/.test(e)?e:"linear"}function TYe(t,e,r){let i=(Array.isArray(r.keyframes)?r.keyframes:[]).filter(p=>p&&Number.isFinite(p.offset)).sort((p,d)=>p.offset-d.offset);if(i.length<2)return{ok:!1,error:"set_layer_keyframes requires a keyframes array with at least 2 stops, each with an offset (0..1)."};if(i.every(p=>p.opacity===void 0&&p.translate_x===void 0&&p.translate_y===void 0&&p.scale===void 0&&p.rotate===void 0))return{ok:!1,error:"each keyframe needs at least one animated property (opacity, translate_x, translate_y, scale, rotate)."};let o=e.getAttribute("data-hf-id")||e.id||"layer",a=`hfk-${o.replace(/[^A-Za-z0-9_-]/g,"-")}`,s=et(r,"keyframe_duration"),l=s!=null&&s>0?s:sf(e)>0?sf(e):1,c=Nrr(Xe(r,"keyframe_easing")),u=i.map(p=>{let d=Number(Pb(p.offset*100,0,100).toFixed(3)).toString(),h=[];(p.translate_x!==void 0||p.translate_y!==void 0)&&h.push(`translate(${p.translate_x??0}%, ${p.translate_y??0}%)`),p.scale!==void 0&&h.push(`scale(${p.scale})`),p.rotate!==void 0&&h.push(`rotate(${p.rotate}deg)`);let m=[];return h.length&&m.push(`transform:${h.join(" ")}`),p.opacity!==void 0&&m.push(`opacity:${Pb(p.opacity,0,1)}`),`${d}%{${m.join(";")}}`}).join("");for(let p of Array.from(t.querySelectorAll(`style[data-vf-keyframes-for="${Mrr(o)}"]`)))p.parentNode?.removeChild(p);let f=t.createElement("style");return f.setAttribute("data-vf-keyframes-for",o),f.textContent=`@keyframes ${a}{${u}}`,(t.head??t.body??t.documentElement).appendChild(f),e.style.setProperty("animation",`${a} ${jr(l)}s ${c} both paused`),{ok:!0,summary:`Set a ${i.length}-stop CSS keyframe animation on ${o} (${jr(l)}s ${c}).`}}function Mrr(t){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(t):t.replace(/["\\]/g,"\\$&")}var Rrr="data:image/svg+xml;charset=utf-8,"+encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='360' height='640' viewBox='0 0 360 640'><rect width='360' height='640' fill='#0c0f0a'/><circle cx='180' cy='300' r='34' fill='none' stroke='#3ad07a' stroke-width='6' stroke-linecap='round' stroke-dasharray='150 60'/><text x='180' y='378' fill='#8ad9a6' font-family='monospace' font-size='20' text-anchor='middle'>Generating\u2026</text></svg>"),Drr="data:image/svg+xml;charset=utf-8,"+encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='360' height='640' viewBox='0 0 360 640'><rect width='360' height='640' fill='#210d10'/><circle cx='180' cy='292' r='34' fill='none' stroke='#ff6577' stroke-width='6'/><path d='M164 276l32 32m0-32l-32 32' stroke='#ff6577' stroke-width='6' stroke-linecap='round'/><text x='180' y='374' fill='#ffb4bd' font-family='sans-serif' font-size='18' text-anchor='middle'>Generation failed</text><text x='180' y='405' fill='#d999a1' font-family='sans-serif' font-size='12' text-anchor='middle'>Open this clip for details</text></svg>");function HC(t,e){let r=e.slice(0,200);t.setAttribute("data-vf-gen-status","error"),t.setAttribute("data-vf-gen-error",r),t.setAttribute("data-label",`Generation failed: ${r}`),t.setAttribute("alt",`Generation failed: ${r}`),t.setAttribute("title",r),t.tagName.toLowerCase()==="img"&&t.setAttribute("src",Drr)}function CYe(t,e,r,n,i){let o=(Xe(e,"prompt")??"").trim(),a=o.length>140?`${o.slice(0,137)}\u2026`:o,s=t.createElement("img");s.id=r,s.setAttribute("data-hf-id",r),s.setAttribute("data-layer-mode","publish"),s.setAttribute("data-layer-kind",n),s.setAttribute("data-viral-note",`AI generating ${n}: ${a}`),s.setAttribute("data-start",jr(i.start)),s.setAttribute("data-duration",jr(i.duration)),s.setAttribute("data-end",jr(i.start+i.duration)),Mb(s,i.track),s.setAttribute("data-label",`Generating ${n}\u2026`),s.classList.add("clip");let l=Xe(e,"slug");if(l&&s.setAttribute("data-hf-slug",l),s.setAttribute("data-vf-gen","1"),s.setAttribute("data-vf-gen-media",n),s.setAttribute("data-vf-gen-status","submitting"),s.setAttribute("data-vf-gen-prompt",a),s.style.position="absolute",s.style.left=`${i.x}%`,s.style.top=`${i.y}%`,s.style.width=`${i.width}%`,s.style.height=`${i.height}%`,s.style.zIndex=String(i.track),s.style.overflow="hidden",s.style.objectFit=Xe(e,"object_fit")??"cover",s.style.background="#0c0f0a",s.setAttribute("src",Rrr),n==="video")s.setAttribute("data-volume","1"),s.setAttribute("data-media-start","0"),s.setAttribute("data-playback-start","0");else{let c=Xe(e,"ken_burns");if(c&&c!=="none"){s.setAttribute("data-kenburns",c);let u=et(e,"ken_burns_intensity");u!=null&&s.setAttribute("data-kenburns-intensity",String(u))}}return KM(s,e),s}function kYe(t){if(!t)return null;let e=l=>typeof l=="string"&&l.trim()?l.trim():null,r=l=>l&&typeof l=="object"?l:null,n=r(t.result)??{},i=r(n.output)??n,o=e(i.primary_file_url)??e(r(i.video)?.file_url)??e(r(i.image)?.file_url)??e(r(i.render)?.output_url);if(o)return o;let a=i.files;if(Array.isArray(a))for(let l of a){let c=e(typeof l=="string"?l:r(l)?.file_url??r(l)?.url);if(c)return c}let s=Array.isArray(t.artifacts)?t.artifacts:[];for(let l of s){let c=e(r(l)?.public_url);if(c)return c}return null}function _Ye(t,e){let r=t.error;if(typeof r=="string"&&r.trim())return r.trim();if(r&&typeof r=="object"){let n=r;for(let i of["message","error","detail"]){let o=n[i];if(typeof o=="string"&&o.trim())return o.trim()}}return e}function IYe(t,e){let r=t.getAttribute("data-vf-gen-media"),n=t;if(r==="video"&&t.tagName.toLowerCase()!=="video"){let o=t.ownerDocument.createElement("video");for(let a of Array.from(t.attributes))o.setAttribute(a.name,a.value);o.setAttribute("playsinline",""),o.setAttribute("preload","auto"),t.replaceWith(o),n=o}n.setAttribute("src",e),D0e(e)&&F0e(n),n.removeAttribute("poster"),n.removeAttribute("alt"),n.removeAttribute("title");for(let o of["data-vf-gen","data-vf-gen-media","data-vf-gen-prompt","data-vf-gen-job","data-vf-gen-tracer","data-vf-gen-error","data-vf-gen-status"])n.removeAttribute(o);let i=n.getAttribute("data-label");i&&/generating/i.test(i)&&n.setAttribute("data-label",r==="image"?"AI image":"AI video"),n.setAttribute("data-viral-note",`AI generated ${r==="image"?"image":"video"}.`)}function Lrr(t){if(t.tagName.toLowerCase()==="audio"||t.hasAttribute("data-caption-animation"))return!1;let e=(t.getAttribute("data-layer-kind")??"").toLowerCase();if(e==="audio"||e==="caption")return!1;if(e==="video"||e==="image"||e==="html"||e==="shape"||e==="text"||t.getAttribute("data-vf-timeline-proxy")!==null)return!0;let r=t.tagName.toLowerCase();return r==="video"||r==="img"}function PYe(t){let e=[];for(let r of m1(t)){if(!Lrr(r))continue;let n=sf(r);if(!(n>0))continue;let i=af(r);e.push({start:i,end:i+n})}return e}function NYe(t,e){let n=l=>Number(l.toFixed(3));if(!Number.isFinite(e)||e<=0)return[];let i=t.filter(l=>Number.isFinite(l.start)&&Number.isFinite(l.end)&&l.end>l.start).sort((l,c)=>l.start-c.start),o=[];for(let l of i){let c=o[o.length-1];c&&l.start<=c.end+.001?c.end=Math.max(c.end,l.end):o.push({start:Math.max(0,l.start),end:l.end})}let a=[],s=0;for(let l of o)l.start-s>=.2&&a.push({start:n(s),end:n(l.start),duration:n(l.start-s)}),s=Math.max(s,l.end);return e-s>=.2&&a.push({start:n(s),end:n(e),duration:n(e-s)}),a}function U0e(t,e){let r=Number.isFinite(e)&&e>0?e:0,n=0;for(let i of m1(t)){let o=af(i),a=sf(i);Number.isFinite(o)&&Number.isFinite(a)&&(n=Math.max(n,o+a))}return n>0?n:r}function MYe(t,e,r){let n=1/0;for(let i of m1(t)){let o=i.getAttribute("data-hf-id")||i.id;if(o&&r.has(o))continue;let a=(i.getAttribute("data-layer-kind")||"").toLowerCase(),s=i.getAttribute("data-vf-timeline-proxy")!==null;if(!(s||["video","image","html","shape"].includes(a))||!(s||i.getAttribute("data-vf-full-canvas")==="true"||Number.parseFloat(i.style.width)>=99.5&&Number.parseFloat(i.style.height)>=99.5))continue;let u=af(i);Number.isFinite(u)&&u>e+.05&&(n=Math.min(n,u))}return n}function RYe(t){let e=[];for(let r of Array.from(t.querySelectorAll("[data-vf-gen-media]"))){let n=r.getAttribute("data-vf-gen-media"),i=n==="image"?"image":n==="video"?"video":null;if(!i)continue;let o=af(r),a=sf(r);e.push({layer_key:r.getAttribute("data-hf-id")||r.id||null,media_type:i,status:r.getAttribute("data-vf-gen-status")||"generating",job_id:r.getAttribute("data-vf-gen-job")||void 0,start:Number.isFinite(o)?o:void 0,duration:Number.isFinite(a)?a:void 0,prompt:r.getAttribute("data-vf-gen-prompt")||void 0,error:r.getAttribute("data-vf-gen-error")||void 0})}return e}function DYe(t){return m1(t).map(e=>{let r=e.tagName.toLowerCase(),n=e.getAttribute("data-layer-kind")??(r==="img"?"image":r==="video"||r==="audio"?r:"html"),i=e.style?.animationName||null,o=e.getAttribute("data-volume");return{element_id:e.getAttribute("data-hf-id")??(e.id||null),slug:e.getAttribute("data-hf-slug"),note:e.getAttribute("data-hf-note")??e.getAttribute("data-viral-note"),kind:n,src:e.getAttribute("src"),label:e.getAttribute("data-label"),start:af(e),duration:sf(e),track:Nb(e),transition:e.getAttribute("data-transition"),transition_out:e.getAttribute("data-transition-out"),ken_burns:e.getAttribute("data-kenburns"),animation:i&&i!=="none"?i:null,volume:o!=null?Number(o):null,muted:e.hasAttribute("muted"),loop:e.getAttribute("data-loop")==="true"||e.hasAttribute("loop")}})}function LYe(t,e){if(!(t>0)||!(e>0))return null;let r=(i,o)=>o?r(o,i%o):i,n=r(Math.round(t),Math.round(e));return`${Math.round(t)/n}:${Math.round(e)/n}`}var iZ=[],Frr=8;function Brr(t){iZ.push(t),iZ.length>Frr&&iZ.shift()}var JM="idle",FYe=null,z0e=null,BYe=!0;async function Uh(t,e){let r=await ZM(t,e);return BYe=r,r}function tR(t){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(t):t.replace(/["\\]/g,"\\$&")}function $Ye(t,e=8e3){return new Promise(r=>{let n=document.createElement("video"),i=!1,o=s=>{i||(i=!0,n.removeAttribute("src"),n.load(),r(s))},a=setTimeout(()=>o(null),e);n.preload="metadata",n.muted=!0,n.addEventListener("loadedmetadata",()=>{clearTimeout(a),o(Number.isFinite(n.duration)&&n.duration>0?n.duration:null)}),n.addEventListener("error",()=>{clearTimeout(a),o(null)}),n.src=t})}function aZ(t,e){return t.querySelector(`[data-hf-id="${tR(e)}"]`)||t.querySelector(`[data-hf-slug="${tR(e)}"]`)||t.getElementById(e)}function g1(t,e){let r=new DOMParser().parseFromString(t,"text/html");return e(r)?WM(r):null}function Q0e(t){let e=new Set;return t.querySelectorAll("[data-hf-id]").forEach(r=>{let n=r.getAttribute("data-hf-id");n&&e.add(n)}),t.querySelectorAll("[data-hf-slug]").forEach(r=>{let n=r.getAttribute("data-hf-slug");n&&e.add(n)}),Array.from(e)}function $rr(t,e){let r=e.length?` Available layer keys: ${e.join(", ")}.`:"";return{ok:!1,error:`layer "${t}" not found.${r} Use a layer_key from the current editor_context.`}}async function sd(t,e,r){let n=!1,i=[],o=await Uh(t,a=>g1(a,s=>{let l=aZ(s,e);return l?(n=!0,r(l,s)):(i=Q0e(s),!1)})??a);return n?o?{ok:!0}:{ok:!1,error:"couldn't save the edit \u2014 composition read/write failed; try again"}:o?$rr(e,i):{ok:!1,error:"couldn't read the composition to edit \u2014 try again"}}async function H0e(t,e,r){let n=[],i=[],o=[];if(!await Uh(t,s=>g1(s,l=>{n.length=0,i.length=0;for(let c of e){let u=aZ(l,c);if(!u){i.push(c);continue}n.push(c),r(u,l,c)}return i.length&&(o=Q0e(l)),n.length>0})??s))return{outcome:{ok:!1,error:"couldn't save the edit \u2014 composition read/write failed; try again"},matched:n,missed:i};if(n.length===0){let s=o.length?` Available layer keys: ${o.join(", ")}.`:"";return{outcome:{ok:!1,error:`no matching layers for ${e.map(l=>`"${l}"`).join(", ")}.${s}`},matched:n,missed:i}}return{outcome:{ok:!0},matched:n,missed:i}}function V0e(t){return t.length?` (not found: ${t.join(", ")})`:""}async function _E(t,e,r){return await Uh(t,n=>g1(n,i=>{let o=i.querySelector(`[data-hf-id="${tR(e)}"]`);return o?(r(o),!0):!1})??n)}async function Urr(t,e,r,n,i){let o=r==="video"?"/api/v1/primitives/videos/generate":"/api/v1/primitives/images/generate",a=h=>typeof h=="string"&&/^https?:\/\//i.test(h),s=(Array.isArray(i.input_references)?i.input_references:[]).filter(a),l=(Array.isArray(i.prompt_attachments)?i.prompt_attachments:[]).filter(a),c={prompt:n},u=Xe(i,"aspect_ratio")?.trim();u&&(c.aspect_ratio=u);let f=Xe(i,"provider")?.trim();f&&(c.provider=f);let p=Xe(i,"model")?.trim();if(p&&(c.model=p),r==="video"){let h=et(i,"gen_duration");h!=null&&(c.duration=Math.round(h));let m=Xe(i,"resolution");m&&(c.resolution=m);let g=p0(i,"generate_audio");g!=null&&(c.generate_audio=g),s.length&&(c.input_references=s.slice(0,8))}else l.length&&(c.prompt_attachments=l.slice(0,16));let d=`editor-gen-${Date.now().toString(36)}`;try{let h=await fetch(o,{method:"POST",credentials:"same-origin",headers:JQ({"content-type":"application/json"}),body:JSON.stringify({tracer:d,payload:c})}),m=await h.json().catch(()=>({}));if(!h.ok||!m.job_id){let g=m.error||`generation request failed (${h.status})`;await _E(t,e,y=>HC(y,g));return}await _E(t,e,g=>{g.setAttribute("data-vf-gen-job",m.job_id),g.setAttribute("data-vf-gen-tracer",d),g.setAttribute("data-vf-gen-status","generating")}),Z0e()}catch(h){await _E(t,e,m=>HC(m,h instanceof Error?h.message:String(h)))}}var eR=null,oZ=null,j0e=!1;function Z0e(){eR!=null||typeof window>"u"||(eR=setInterval(()=>{Hrr()},6e3))}function G0e(){eR!=null&&(clearInterval(eR),eR=null)}async function Hrr(){if(!j0e){j0e=!0;try{let t=oZ?.()??null;if(!t){G0e();return}let r=(await Ib(t))?.content;if(!r)return;if(!(r.includes('data-vf-gen-status="generating"')||r.includes('data-vf-gen-status="submitting"'))){G0e();return}let i=new DOMParser().parseFromString(r,"text/html"),o=Array.from(i.querySelectorAll('[data-vf-gen-status="generating"][data-vf-gen-job]'));for(let a of o){let s=a.getAttribute("data-hf-id")||a.id,l=a.getAttribute("data-vf-gen-job");if(!(!s||!l))try{let c=await fetch(`/api/v1/user/me/jobs/${encodeURIComponent(l)}`,{credentials:"same-origin",headers:JQ()});if(!c.ok){c.status>=400&&c.status<500&&c.status!==429&&await _E(t,s,d=>HC(d,`generation job unavailable (${c.status})`));continue}let u=await c.json().catch(()=>null);if(!u)continue;let f=kYe(u);if(f){await _E(t,s,d=>IYe(d,f));continue}let p=typeof u.status=="string"?u.status:"";if(p==="failed"||p==="cancelled"){let d=_Ye(u,`generation ${p}`);await _E(t,s,h=>HC(h,d))}else p==="succeeded"&&await _E(t,s,d=>HC(d,"generation succeeded without a usable media URL"))}catch{}}}finally{j0e=!1}}}async function Vrr(t,e){let r=Xe(e,"media_type")??Xe(e,"kind"),n=r==="image"?"image":r==="video"?"video":null;if(!n)return{ok:!1,error:"generate_layer requires media_type 'video' or 'image'."};let i=Xe(e,"prompt").trim(),o=Xe(e,"intent")??(Xe(e,"replace_layer_key")?"replace_layer":"add"),a=null,s="",l="",c=await Uh(t,u=>g1(u,f=>{a=null;let p=Wv(f);if(!p)return a="composition root not found",!1;let d=et(e,"start"),h=et(e,"duration"),m=et(e,"track"),g=et(e,"x"),y=et(e,"y"),b=et(e,"width"),x=et(e,"height"),S=null,v=null;if(o==="replace_layer"){let N=(Xe(e,"replace_layer_key")??Xe(e,"layer_key")??"").trim();if(!N)return a="generate_layer intent=replace_layer requires replace_layer_key (the layer to replace).",!1;if(v=aZ(f,N),!v){let G=Q0e(f);return a=`generate_layer: layer to replace not found: ${N}.${G.length?` Available layer keys: ${G.join(", ")}.`:""}`,!1}S=v.getAttribute("data-hf-id")||v.id||N;let H=v.getAttribute("data-vf-timeline-proxy")!==null||v.getAttribute("data-vf-full-canvas")==="true"||v.style.width==="100%"&&v.style.height==="100%";if(d==null&&(d=af(v)),h==null&&(h=sf(v)>0?sf(v):null),m==null&&(m=Nb(v)),H)g=0,y=0,b=100,x=100;else{let G=j=>{let Q=Number.parseFloat(j);return Number.isFinite(Q)?Q:null};g==null&&(g=G(v.style.left)),y==null&&(y=G(v.style.top)),b==null&&(b=G(v.style.width)),x==null&&(x=G(v.style.height))}}let w=Xe(e,"layer_key")?.trim(),A=w&&w!==S&&/^[A-Za-z][\w-]{0,63}$/.test(w)?w:`vf-gen-${Date.now().toString(36)}${Math.floor(Math.random()*1e3).toString(36)}`,E=U0e(f,parseFloat(p.getAttribute("data-duration")??"0")||0),O=d??0,T=Math.max(0,E>0?Math.min(E-.1,O):O),C=E>0?Math.max(.1,E-T):4,k=h??Math.min(n==="video"?et(e,"gen_duration")??4:4,C),_=Math.max(.1,E>0?Math.min(k,C):k),P=N=>Math.max(0,Math.min(100,N)),F=P(g??0),V=P(y??0),$=P(b??100),z=P(x??100);v&&v.remove();let B=1,U=$>=99.5&&z>=99.5&&F<=.5&&V<=.5;if(et(e,"duration")==null&&U&&_<B){let N=new Set([A]);S&&N.add(S);let H=MYe(f,T,N),j=(Number.isFinite(H)?H:E>0?E:T+4)-T;_=Math.max(B,Number.isFinite(j)&&j>0?j:Math.min(4,C))}let L=m!=null?Math.max(0,Math.trunc(m)):qM(f)+1,D=YM(f,T,_,L),R=CYe(f,e,A,n,{start:T,duration:_,track:D,x:F,y:V,width:$,height:z});p.appendChild(R),l=A;let I=o==="replace_layer"?`replacing ${S}`:`at ${T.toFixed(2)}s`;return s=`Started ${n} generation (${I}). A placeholder is on the timeline as ${A}; it will swap to the finished media automatically. Watch editor_context.pending_generations.`,!0})??u);return a?{ok:!1,error:a}:!c||!l?{ok:!1,error:"couldn't save the generation placeholder \u2014 composition read/write failed; try again"}:(Urr(t,l,n,i,e),Z0e(),{ok:!0,summary:s})}async function jrr(t,e,r){let n=e.action_type??"",i=e.layer_key??"",o=e;switch(n){case"replace_composition_html":{let a=typeof e.composition_html=="string"?e.composition_html:null;return a?await Uh(t,()=>a)?{ok:!0,summary:"Replaced composition."}:{ok:!1,error:"write failed"}:{ok:!1,error:"missing composition_html"}}case"add_layer":case"generate_layer":{let a=typeof e.layer_html=="string"?e.layer_html:null;if(a)return await Uh(t,m=>eZ(m,a))?{ok:!0,summary:"Added a layer."}:{ok:!1,error:"write failed"};let s=Xe(o,"src");if(n==="generate_layer"){if(Xe(o,"prompt")?.trim())return await Vrr(t,o);if(!s)return{ok:!1,error:"generate_layer requires a prompt (what to generate) \u2014 or use add_layer with a src for media that already exists."}}let l=Xe(o,"kind")??Xe(o,"media_type")??(s?L0e(s):null)??(Xe(o,"text")?"text":Xe(o,"html")?"html":null);if(!l)return{ok:!1,error:"add_layer needs kind (video|image|audio|text|html) or a src/text/html to infer it from"};let c=Math.max(0,et(o,"start")??0),u=et(o,"duration")??0;u>0||(u=l==="video"&&s?await $Ye(s)??3:3);let f=null,p="",d=await Uh(t,h=>g1(h,m=>{let g=Wv(m);if(!g)return f="composition root not found",!1;let y=et(o,"track"),b=y!=null?Math.max(0,Math.trunc(y)):YM(m,c,u,qM(m)+1),x=B0e(m,o,{kind:l,start:c,duration:u,track:b});if("error"in x)return f=x.error,!1;g.appendChild(x.el);let S=c+u,v=parseFloat(g.getAttribute("data-duration")??"0")||0;return S>v&&g.setAttribute("data-duration",jr(S)),p=`Added ${l} layer "${x.id}" at ${jr(c)}s for ${jr(u)}s on track ${b}.`,!0})??h);return f?{ok:!1,error:f}:d?{ok:!0,summary:p}:{ok:!1,error:"couldn't save the new layer \u2014 composition read/write failed; try again"}}case"set_layer_text":{let a=typeof e.text=="string"?e.text:null;if(!i||a==null)return{ok:!1,error:"missing layer_key/text"};let s=await sd(t,i,l=>{if(l.hasAttribute("data-caption-animation")&&l.querySelector("[data-vf-text-inline]"))nZ(l,a);else{let c=l.querySelector("[data-vf-text-inline]");c?c.textContent=a:l.textContent=a}return l.hasAttribute("data-label")&&l.setAttribute("data-label",a.slice(0,48)),!0});return s.ok?{ok:!0,summary:`Set text on ${i}.`}:s}case"set_captions":{let a=null,s=await Uh(t,l=>g1(l,c=>{let u=Wv(c);if(!u)return a={ok:!1,error:"composition root not found"},!1;let f=parseFloat(u.getAttribute("data-duration")??"0")||0;return a=EYe(c,u,o,f),a.ok})??l);return a&&!a.ok?a:s?a??{ok:!1,error:"couldn't read the composition to edit \u2014 try again"}:{ok:!1,error:"couldn't save the captions \u2014 composition read/write failed; try again"}}case"set_layer_media":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Xe(o,"src"),s=[],l=!1,c=await sd(t,i,u=>{s.length=0;let f=u.matches("img,video,audio")?u:u.querySelector("img,video,audio"),p=f?.tagName.toLowerCase()??"";if(a){if(!f)return l=!0,!1;f.setAttribute("src",a),D0e(a)&&F0e(f),s.push("src")}let d=Xe(o,"object_fit");d&&f&&(f.style.objectFit=d,s.push(`object_fit=${d}`));let h=Xe(o,"object_position");h&&f&&(f.style.objectPosition=h,s.push(`object_position=${h}`));let m=et(o,"volume");m!=null&&f&&(f.setAttribute("data-volume",String(Math.max(0,Math.min(1,m)))),s.push(`volume=${m}`));let g=p0(o,"muted");g!=null&&f&&(g?f.setAttribute("muted",""):f.removeAttribute("muted"),s.push(`muted=${g}`));let y=p0(o,"loop");y!=null&&f&&p==="video"&&(y?(f.setAttribute("loop",""),f.setAttribute("data-loop","true")):(f.removeAttribute("loop"),f.removeAttribute("data-loop")),s.push(`loop=${y}`));let b=Xe(o,"ken_burns");if(b&&f){if(b==="none")f.removeAttribute("data-kenburns"),f.removeAttribute("data-kenburns-intensity");else{f.setAttribute("data-kenburns",b);let S=et(o,"ken_burns_intensity");S!=null&&f.setAttribute("data-kenburns-intensity",String(S))}s.push(`ken_burns=${b}`)}let x=et(o,"playback_start");return x!=null&&f&&(f.setAttribute("data-playback-start",jr(Math.max(0,x))),s.push(`playback_start=${x}`)),s.push(...KM(u,o)),s.length>0});return c.ok?l?{ok:!1,error:`layer "${i}" has no img/video/audio element to swap.`}:s.length===0?{ok:!1,error:"set_layer_media needs at least one field (src, object_fit, object_position, volume, muted, loop, ken_burns, playback_start, transition\u2026)"}:{ok:!0,summary:`Updated media on ${i} (${s.join(", ")}).`}:c}case"set_layer_style":{if(!i)return{ok:!1,error:"missing layer_key"};let a=[],s=await sd(t,i,l=>(a=OYe(l,o),a.length>0));return s.ok?a.length===0?{ok:!1,error:"set_layer_style needs at least one style field."}:{ok:!0,summary:`Restyled ${i} (${a.join(", ")}).`}:s}case"set_layer_identity":{if(!i)return{ok:!1,error:"missing layer_key"};let a=await sd(t,i,s=>(typeof e.slug=="string"&&s.setAttribute("data-hf-slug",e.slug),typeof e.note=="string"&&(e.note===""?s.removeAttribute("data-hf-note"):s.setAttribute("data-hf-note",e.note)),!0));return a.ok?{ok:!0,summary:`Tagged ${i}.`}:a}case"remove_layer":{if(!i)return{ok:!1,error:"missing layer_key"};let a=await sd(t,i,s=>(s.remove(),!0));return a.ok?{ok:!0,summary:`Removed ${i}.`}:a}case"set_composition":{let a=et(o,"canvas_width"),s=et(o,"canvas_height"),l=et(o,"canvas_duration"),c=Xe(o,"background_color");if(a==null&&s==null&&l==null&&!c)return{ok:!1,error:"set_composition needs canvas_width, canvas_height, canvas_duration and/or background_color"};let u=[];return await Uh(t,p=>g1(p,d=>{u.length=0;let h=Wv(d)??d.body;return h?(a!=null&&(h.setAttribute("data-width",String(Math.round(a))),u.push(`width=${Math.round(a)}`)),s!=null&&(h.setAttribute("data-height",String(Math.round(s))),u.push(`height=${Math.round(s)}`)),l!=null&&l>0&&(h.setAttribute("data-duration",jr(l)),u.push(`duration=${l}`)),c&&(h.style.background=c,u.push(`background=${c}`)),u.length>0):!1})??p)?u.length===0?{ok:!1,error:"no valid set_composition field applied"}:{ok:!0,summary:`Updated composition (${u.join(", ")}).`}:{ok:!1,error:"couldn't save \u2014 composition read/write failed; try again"}}case"set_layer_timing":{if(!i)return{ok:!1,error:"missing layer_key"};let a=[],s=await sd(t,i,l=>{a.length=0;let c=et(o,"start"),u=et(o,"duration");(c!=null||u!=null)&&(h1(l,c??void 0,u??void 0),c!=null&&a.push(`start=${c}`),u!=null&&a.push(`duration=${u}`));let f=et(o,"track");f!=null&&(Mb(l,f),a.push(`track=${f}`));let p=et(o,"playback_start");return p!=null&&(l.setAttribute("data-playback-start",jr(Math.max(0,p))),a.push(`playback_start=${p}`)),a.length>0});return s.ok?a.length===0?{ok:!1,error:"set_layer_timing needs start, duration, track and/or playback_start"}:{ok:!0,summary:`Retimed ${i} (${a.join(", ")}).`}:s}case"trim_layer":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Xe(o,"edge"),s=et(o,"to_time");if(a&&s!=null){let u=null,f="",p=await sd(t,i,d=>{let h=af(d),m=h+sf(d);if(a==="start"){if(!(s<m))return u=`to_time ${s}s must be before the clip's end (${jr(m)}s) for edge=start.`,!1;let g=Math.max(0,s),y=g-h;h1(d,g,m-g);let b=d.tagName.toLowerCase(),x=b==="video"||b==="audio"?d:d.querySelector("video,audio");x&&x.setAttribute("data-playback-start",jr(Math.max(0,R0e(x)+y))),f=`Trimmed ${i} start to ${jr(g)}s (duration ${jr(m-g)}s).`}else{if(!(s>h))return u=`to_time ${s}s must be after the clip's start (${jr(h)}s) for edge=end.`,!1;h1(d,void 0,s-h),f=`Trimmed ${i} end to ${jr(s)}s (duration ${jr(s-h)}s).`}return!0});return u?{ok:!1,error:u}:p.ok?{ok:!0,summary:f}:p}let l=[],c=await sd(t,i,u=>{l.length=0;let f=et(o,"start"),p=et(o,"duration");(f!=null||p!=null)&&h1(u,f??void 0,p??void 0),f!=null&&l.push(`start=${f}`),p!=null&&l.push(`duration=${p}`);let d=et(o,"track");return d!=null&&(Mb(u,d),l.push(`track=${d}`)),l.length>0});return c.ok?l.length===0?{ok:!1,error:"trim_layer needs edge ('start'|'end') + to_time, or start/duration/track"}:{ok:!0,summary:`Retimed ${i} (${l.join(", ")}).`}:c}case"set_transitions":{if(i){let l=[],c=await sd(t,i,u=>(l=KM(u,o),l.length>0));return c.ok?l.length===0?{ok:!1,error:"set_transitions needs transition, transition_out and/or their durations"}:{ok:!0,summary:`Set transitions on ${i} (${l.join(", ")}).`}:c}let a=null,s=await Uh(t,l=>g1(l,c=>(a=dYe(c,o),a.ok))??l);return a&&!a.ok?a:s?a??{ok:!1,error:"couldn't read the composition to edit \u2014 try again"}:{ok:!1,error:"couldn't save the transitions \u2014 composition read/write failed; try again"}}case"set_layer_zindex":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Xe(o,"z_order"),s=et(o,"track");if(!a&&s==null)return{ok:!1,error:"set_layer_zindex needs z_order (front|back|forward|backward) or track"};let l="",c=await sd(t,i,(u,f)=>{let p=Nb(u),d=p;return s!=null?d=Math.max(0,Math.trunc(s)):a==="front"?d=m1(f).filter(h=>h!==u).reduce((h,m)=>Math.max(h,Nb(m)),-1)+1:a==="back"?d=0:a==="forward"?d=p+1:a==="backward"&&(d=Math.max(0,p-1)),Mb(u,d),u.style.zIndex&&(u.style.zIndex=String(d)),l=`Restacked ${i}: track ${p} \u2192 ${d}.`,d!==p||s!=null});return c.ok?{ok:!0,summary:l||`Restacked ${i}.`}:c}case"set_layer_visual":{if(!i)return{ok:!1,error:"missing layer_key"};let a=[],s=await sd(t,i,l=>{a.length=0;let c=et(o,"x");c!=null&&(l.style.left=`${c}%`,a.push(`x=${c}`));let u=et(o,"y");u!=null&&(l.style.top=`${u}%`,a.push(`y=${u}`));let f=et(o,"width");f!=null&&(l.style.width=`${f}%`,a.push(`width=${f}`));let p=et(o,"height");p!=null&&(l.style.height=`${p}%`,a.push(`height=${p}`));let d=et(o,"opacity");d!=null&&(l.style.opacity=String(Math.max(0,Math.min(1,d))),a.push(`opacity=${d}`));let h=et(o,"font_size");h!=null&&(l.style.fontSize=`${h}px`,a.push(`font_size=${h}`));let m=et(o,"border_radius");return m!=null&&(l.style.borderRadius=`${m}px`,l.style.overflow="hidden",a.push(`border_radius=${m}`)),a.length>0});return s.ok?a.length===0?{ok:!1,error:"no visual fields (x, y, width, height, opacity, font_size, border_radius)"}:{ok:!0,summary:`Adjusted ${i} (${a.join(", ")}).`}:s}case"duplicate_layer":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Array.isArray(e.layer_keys)&&typeof e.layer_keys[1]=="string"?e.layer_keys[1]:null,s="",l=await sd(t,i,(c,u)=>{s=a&&!aZ(u,a)?M0e(a):`vf_${Date.now().toString(36)}`;let f=c.cloneNode(!0);f.setAttribute("data-hf-id",s),f.id=s,f.removeAttribute("data-hf-slug");let p=et(o,"start"),d=et(o,"duration");(p!=null||d!=null)&&h1(f,p??void 0,d??void 0);let h=et(o,"track");h!=null&&Mb(f,h);let m=Xe(o,"label");return m&&f.setAttribute("data-label",m),c.parentNode?.insertBefore(f,c.nextSibling),!0});return l.ok?{ok:!0,summary:`Duplicated ${i} as ${s}.`}:l}case"split_layer":{let a=typeof e.split_time=="number"?e.split_time:null;if(!i||a==null)return{ok:!1,error:"missing layer_key/split_time"};let s=!1,l=await sd(t,i,c=>{let u=af(c),f=sf(c),p=u+f;if(!(a>u&&a<p))return s=!0,!1;h1(c,void 0,a-u);let d=c.cloneNode(!0),h=`vf_${Date.now().toString(36)}`;d.setAttribute("data-hf-id",h),d.id=h,d.removeAttribute("data-hf-slug"),h1(d,a,p-a);let m=d.tagName.toLowerCase(),g=m==="video"||m==="audio"?d:d.querySelector("video,audio");return g&&g.setAttribute("data-playback-start",jr(Math.max(0,R0e(g)+(a-u)))),c.parentNode?.insertBefore(d,c.nextSibling),!0});return l.ok&&s?{ok:!1,error:`split_time ${a}s is outside layer "${i}"'s span.`}:l.ok?{ok:!0,summary:`Split ${i} at ${a}s.`}:l}case"nudge_layers":{let a=Array.isArray(e.layer_keys)?e.layer_keys.map(String):i?[i]:[];if(a.length===0)return{ok:!1,error:"missing layer_keys"};let s=typeof e.delta_start=="number"?e.delta_start:0,l=typeof e.delta_track=="number"?e.delta_track:0;if(s===0&&l===0)return{ok:!1,error:"no delta"};let c=new Set,u=null,{outcome:f,matched:p,missed:d}=await H0e(t,a,(h,m)=>{u!==m&&(c.clear(),u=m);let g=h.getAttribute("data-vf-group"),y=g?Array.from(m.querySelectorAll(`[data-vf-group="${tR(g)}"][data-start]`)):[h];for(let b of y)c.has(b)||(c.add(b),s!==0&&h1(b,Math.max(0,af(b)+s),void 0),l!==0&&Mb(b,Nb(b)+l))});return f.ok?{ok:!0,summary:`Nudged ${p.length} layer(s) by ${s}s / ${l} lane(s).${V0e(d)}`}:f}case"ripple_edit":{let a=typeof e.at_time=="number"?e.at_time:null,s=typeof e.delta_start=="number"?e.delta_start:null;if(a==null||s==null)return{ok:!1,error:"missing at_time/delta_start"};let l=0;return await Uh(t,u=>g1(u,f=>{l=0;for(let p of m1(f)){let d=af(p);d>=a&&(h1(p,Math.max(0,d+s),void 0),l+=1)}return l>0})??u)?l===0?{ok:!1,error:`no clips start at or after ${a}s`}:{ok:!0,summary:`Rippled ${l} clip(s) by ${s}s at ${a}s.`}:{ok:!1,error:"couldn't save the ripple \u2014 composition read/write failed; try again"}}case"group_layers":{let a=Array.isArray(e.layer_keys)?e.layer_keys.map(String):[];if(a.length<2)return{ok:!1,error:"group_layers requires layer_keys with at least two entries."};let s=`vf-group-${Date.now().toString(36)}`,l=Xe(o,"group_label")??"Vidfarm group",{outcome:c,matched:u,missed:f}=await H0e(t,a,p=>{p.setAttribute("data-vf-group",s),p.setAttribute("data-vf-group-label",l)});return c.ok?f.length?{ok:!0,summary:`Grouped ${u.length} layer(s) as ${s} \u2014 WARNING, not found: ${f.join(", ")}.`}:{ok:!0,summary:`Grouped ${u.length} layers as ${s}.`}:c}case"ungroup_layers":{let a=Array.isArray(e.layer_keys)?e.layer_keys.map(String):i?[i]:[];if(a.length===0)return{ok:!1,error:"ungroup_layers requires layer_keys."};let s=0,{outcome:l,matched:c,missed:u}=await H0e(t,a,(f,p)=>{let d=f.getAttribute("data-vf-group");if(d)for(let h of Array.from(p.querySelectorAll(`[data-vf-group="${tR(d)}"]`)))h.removeAttribute("data-vf-group"),h.removeAttribute("data-vf-group-label"),s+=1});return l.ok?s===0?{ok:!1,error:`layers ${c.join(", ")} weren't grouped.${V0e(u)}`}:{ok:!0,summary:`Ungrouped ${s} layer(s).${V0e(u)}`}:l}case"set_layer_keyframes":{if(!i)return{ok:!1,error:"missing layer_key"};let a=null,s=await sd(t,i,(l,c)=>(a=TYe(c,l,o),a.ok));return a&&!a.ok?a:s.ok?a??{ok:!1,error:"couldn't apply keyframes"}:s}case"export_composition":return JM==="rendering"?{ok:!1,error:"a render is already in flight \u2014 wait for it to finish (the MP4 URL will appear as last_export_url)."}:(JM="rendering",z0e=null,await new Promise(a=>{let s=!1,l=c=>{s||(s=!0,a(c))};UC({forkId:t,apiKey:r.apiKey??null,title:r.title??null},{onAccepted:c=>{l({ok:!0,summary:`Cloud render started (${c}). The finished MP4 URL will appear in the next editor_context as last_export_url.`})},onDone:c=>{JM="ok",FYe=c,l({ok:!0,summary:c?`Render finished: ${c}`:"Render finished (no output URL returned)."})},onError:c=>{JM="error",z0e=c,l({ok:!1,error:c})}})}));case"fork_composition":{let a=Xe(o,"fork_from")==="default"?"default":"current",s;try{s=await fetch(`/api/v1/compositions/${encodeURIComponent(t)}/fork`,{method:"POST",credentials:"same-origin",headers:JQ({"content-type":"application/json"}),body:JSON.stringify({from:a})})}catch(f){return{ok:!1,error:`fork request failed: ${f instanceof Error?f.message:String(f)}`}}let l=await s.json().catch(()=>null);if(!s.ok||!l?.fork_id)return{ok:!1,error:l?.error??`fork failed (HTTP ${s.status})`};let c=l.template_id??window.location.pathname.split("/")[2]??"original",u=`/editor/${encodeURIComponent(c)}/fork/${encodeURIComponent(l.fork_id)}`;return setTimeout(()=>{window.location.assign(u)},400),{ok:!0,summary:`Forked (${a}) \u2192 ${l.fork_id}. Opening ${u}\u2026`}}default:return{ok:!1,error:`action "${n}" isn't available in this editor build yet`}}}async function zrr(t){let e=q.getState(),r={fork_id:t,selected_element_id:e.selectedElementId,playhead:e.currentTime??0,last_export_url:FYe,last_export_status:JM,last_export_error:z0e,recent_action_results:iZ.slice(),save_status:BYe?"ok":"error"};if(!t)return{...r,composition_id:null,duration:e.duration,layers:[],composition_context:null};let n=await Ib(t);if(!n?.content)return{...r,composition_id:null,duration:e.duration,layers:e.elements.map(p=>({element_id:p.id,label:p.label??null,start:p.start,duration:p.duration,track:p.track})),composition_context:null,snapshot_source:"player-store (composition read failed)"};let i=new DOMParser().parseFromString(n.content,"text/html"),o=Wv(i),a=Number(o?.getAttribute("data-width"))||0,s=Number(o?.getAttribute("data-height"))||0,l=null,c=o?.getAttribute("data-viral-dna")??i.body?.getAttribute("data-viral-dna");if(c)try{l=JSON.parse(c)}catch{}let u=U0e(i,Number(o?.getAttribute("data-duration"))||e.duration||0),f=RYe(i);return f.some(p=>p.status==="generating"||p.status==="submitting")&&Z0e(),{...r,composition_id:o?.getAttribute("data-composition-id")??i.body?.getAttribute("data-composition-id")??null,duration:u,canvas_width:a||null,canvas_height:s||null,composition_width:a||null,composition_height:s||null,aspect_ratio:LYe(a,s),layers:DYe(i),timeline_gaps:NYe(PYe(i),u),pending_generations:f,composition_context:l?{viral_dna:l}:null}}function UYe(t,e={}){oZ=t;let r={apply:async n=>{let i=n?.action_type??"",o=t(),a;if(!o)a={ok:!1,error:"no fork open"};else try{a=await jrr(o,n,e)}catch(s){a={ok:!1,error:s instanceof Error?s.message:String(s)}}return Brr({action_type:i||"(unknown)",ok:a.ok,...a.summary?{summary:a.summary}:{},...a.error?{error:a.error}:{}}),a},getCompositionHtml:async()=>{let n=t();return n?(await Ib(n))?.content??null:null},getSnapshot:()=>zrr(t()),placeMediaAtPlayhead:async n=>{let i=t();if(!i)return{ok:!1,error:"no fork open"};let o=n.src??n.url??n.path;if(!o)return{ok:!1,error:"no media src"};let a=q.getState().currentTime||0,s=L0e(o,n.contentType)??"image",l=s==="video"?await $Ye(o)??3:3,c=n.name??"Inserted media",u={kind:s,src:o,start:a,duration:l,label:c},f="";return await Uh(i,d=>g1(d,h=>{let m=Wv(h);if(!m)return!1;let g=YM(h,a,l,qM(h)+1),y=B0e(h,u,{kind:s,start:a,duration:l,track:g});if("error"in y)return!1;m.appendChild(y.el);let b=a+l,x=parseFloat(m.getAttribute("data-duration")??"0")||0;return b>x&&m.setAttribute("data-duration",jr(b)),f=`Placed ${s} at ${jr(a)}s on track ${g}.`,!0})??d)?{ok:!0,summary:f||"Placed media at playhead."}:{ok:!1,error:"couldn't save \u2014 composition read/write failed"}}};return window.__vidfarmEditorAction=r,()=>{window.__vidfarmEditorAction===r&&delete window.__vidfarmEditorAction,oZ===t&&(oZ=null,G0e())}}var rR=M(se(),1);nYe();function HYe(){if(typeof document>"u")return null;let t=document.getElementById("hf-boot");if(!t?.textContent)return null;try{return JSON.parse(t.textContent)}catch{return null}}function lZ(){if(typeof window>"u")return null;let t=window.location.pathname.match(/^\/editor\/[^/]+\/fork\/([^/]+)\/?$/);if(!t)return null;let e=decodeURIComponent(t[1]);return e==="new"?null:e}function VYe(){let t=lZ();if(!t)return;let e=`#project/${encodeURIComponent(t)}`;window.location.hash!==e&&window.history.replaceState(null,"",window.location.pathname+window.location.search+e)}function Grr(){let t="data-vidfarm-logo",e=()=>{let i=document.createElement("div");i.setAttribute(t,""),i.style.cssText="display:inline-flex;align-items:center;gap:8px;user-select:none;line-height:1";let o=document.createElement("span");o.style.cssText="display:inline-grid;place-items:center;width:24px;height:24px;border-radius:7px;background:#f5c518;color:#1c1608;font-weight:800;font-size:14px;font-family:var(--rk-font-display,system-ui,sans-serif)",o.textContent="V";let a=document.createElement("span");return a.style.cssText="font-weight:800;font-size:15px;letter-spacing:-.01em;color:#fffbe6;font-family:var(--rk-font-display,system-ui,sans-serif)",a.textContent="VidFarm",i.append(o,a),i},r=()=>{document.querySelectorAll('svg[aria-label="Hyperframes"]').forEach(o=>{o.previousElementSibling?.hasAttribute?.(t)||o.getAttribute("data-vidfarm-hidden")==="1"||(o.setAttribute("data-vidfarm-hidden","1"),o.style.display="none",o.parentElement?.insertBefore(e(),o))})};r();let n=new MutationObserver(r);return n.observe(document.body,{childList:!0,subtree:!0}),()=>n.disconnect()}function Qrr(t){if(t?.localRender!==!1)return()=>{};let e="data-vidfarm-cloud-render",r=o=>{let a=document.createElement("button");a.type="button",a.setAttribute(e,""),a.className=o.className,a.textContent="Render",a.title="Render this composition in the cloud (MP4)";let s=!1,l=null;return a.addEventListener("click",()=>{if(s)return;if(l){window.open(l,"_blank","noopener");return}let c=lZ();if(!c){a.textContent="No project yet",setTimeout(()=>{a.textContent="Render"},2e3);return}s=!0,a.disabled=!0,a.textContent="Rendering\u2026",UC({forkId:c,apiKey:t?.vidfarmApiKey??null,title:t?.title??null},{onProgress:u=>{a.textContent=u!=null?`Rendering\u2026 ${Math.round(u*100)}%`:"Rendering\u2026"},onDone:u=>{s=!1,a.disabled=!1,l=u,a.textContent=u?"Open MP4 \u2197":"Rendered",u&&window.open(u,"_blank","noopener"),setTimeout(()=>{a.textContent="Render",l=null},2e4)},onError:u=>{s=!1,a.disabled=!1,a.textContent="Render failed",a.title=u,setTimeout(()=>{a.textContent="Render",a.title="Render this composition in the cloud (MP4)"},4e3)}})}),a},n=()=>{document.querySelectorAll("button").forEach(a=>{a.hasAttribute(e)||a.getAttribute("data-vidfarm-hidden")==="1"||a.previousElementSibling?.hasAttribute?.(e)||(a.textContent||"").trim().toLowerCase()==="export"&&a.className.includes("studio-accent")&&(a.setAttribute("data-vidfarm-hidden","1"),a.style.display="none",a.parentElement?.insertBefore(r(a),a))})};n();let i=new MutationObserver(n);return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()}function jYe({boot:t}){let e=lZ();return aYe(t?.vidfarmApiKey??null),(0,sZ.useEffect)(()=>UYe(()=>lZ(),{apiKey:t?.vidfarmApiKey??null,title:t?.title??null}),[t]),(0,sZ.useEffect)(()=>Grr(),[]),(0,sZ.useEffect)(()=>Qrr(t),[t]),(0,rR.jsxs)("div",{className:"vidfarm-editor-root",style:{position:"fixed",inset:0},children:[(0,rR.jsx)(tYe,{}),(0,rR.jsx)(fYe,{boot:t,forkId:e})]})}var Xv=M(se(),1);VYe();J6e();c6("boot.entry-loaded");var W0e=document.getElementById("root");if(!W0e){l6("boot.root-missing");let t=new Error("Missing #root element");throw ZS(t),t}var VC=HYe();c6("boot.config-resolved",VC??{source:"none"});VC?.templateId&&yT.setTag("hyperframes.template_id",VC.templateId);VC?.compositionId&&yT.setTag("hyperframes.composition_id",VC.compositionId);function Zrr(){return(0,Xv.jsxs)("section",{style:{display:"grid",placeItems:"center",height:"100vh",padding:"24px",textAlign:"center",gap:"12px",color:"#fffbe6",background:"#050604"},children:[(0,Xv.jsx)("strong",{style:{fontSize:"0.72rem",letterSpacing:"0.14em",textTransform:"uppercase"},children:"Editor crashed"}),(0,Xv.jsx)("span",{style:{fontSize:"0.92rem",opacity:.75},children:"Something went wrong loading the editor. Reload the page to try again."})]})}try{c6("boot.render-start",{rootChildren:W0e.childNodes.length}),(0,zYe.createRoot)(W0e).render((0,Xv.jsx)(yT.ErrorBoundary,{fallback:(0,Xv.jsx)(Zrr,{}),onError:t=>l6("boot.render-error",t instanceof Error?t.stack:t),children:(0,Xv.jsx)(jYe,{boot:VC})})),c6("boot.render-called")}catch(t){throw l6("boot.render-error",t instanceof Error?t.stack:t),ZS(t),t}
886
+ `,mYe=[{id:"spotlight",animation:"highlight-pop",color:"#ffffff",background:"#000000",textBackgroundStyle:"outline",highlightColor:"#7C3AED",activeColor:"#ffffff",fontWeight:800,uppercase:!0},{id:"karaoke",animation:"karaoke-fill",color:"#ffffff",background:"#000000",textBackgroundStyle:"outline",activeColor:"#FFE14D",fontWeight:800},{id:"word-pop",animation:"word-pop",color:"#ffffff",background:"#000000",textBackgroundStyle:"outline",fontWeight:900,uppercase:!0},{id:"stack-up",animation:"cumulative-reveal",color:"#ffffff",background:"#000000",textBackgroundStyle:"highlight-translucent",fontWeight:700},{id:"neon",animation:"glow-pulse",color:"#eafff1",background:"#04140a",textBackgroundStyle:"plain",activeColor:"#9BFF57",fontWeight:800,uppercase:!0},{id:"bounce",animation:"bounce-wave",color:"#FFE14D",background:"#000000",textBackgroundStyle:"outline",activeColor:"#FFE14D",fontWeight:900,uppercase:!0}];function gYe(t){if(!t)return null;let e=String(t).trim().toLowerCase();return mYe.find(r=>r.id===e)??null}function yYe(t){return t&&hYe.includes(t)?t:null}function $0e(t,e){let r=String(t||"").trim().split(/\s+/).filter(Boolean),n=Number.isFinite(e)&&e>0?e:r.length*.32;if(!r.length)return[];let i=r.map(l=>Math.max(2,l.length)+1.5),o=i.reduce((l,c)=>l+c,0),a=[],s=0;for(let l=0;l<r.length;l+=1){let c=i[l]/o*n,u=Math.min(.03,c*.1);a.push({text:r[l],start:Number(s.toFixed(3)),end:Number(Math.max(s+.05,s+c-u).toFixed(3))}),s+=c}return a}function _rr(t,e,r,n=4){let i=$0e(t,r),o=[],a=[],s=()=>{if(!a.length)return;let l=a[0].start,c=a[a.length-1].end+.12;o.push({text:a.map(u=>u.text).join(" "),start:Number((e+l).toFixed(3)),duration:Number(Math.max(.2,c-l).toFixed(3)),words:a.map(u=>({text:u.text,start:Number((u.start-l).toFixed(3)),end:Number((u.end-l).toFixed(3))}))}),a=[]};for(let l of i)(a.length>=n||a.length>0&&/[.!?…]["')\]]?$/.test(a[a.length-1].text))&&s(),a.push(l);s();for(let l=0;l<o.length-1;l+=1){let c=o[l+1].start-.02;o[l].start+o[l].duration>c&&(o[l].duration=Number(Math.max(.1,c-o[l].start).toFixed(3)))}return o}function XM(t){return t==="Georgia"?"Georgia":`'${t}'`}function bYe(t,e){let r=t.trim(),n=r.startsWith("#")?r.slice(1):"";if(n.length===3||n.length===6){let i=n.length===3?n.split("").map(a=>a+a).join(""):n,o=Number.parseInt(i,16);if(Number.isFinite(o))return`rgba(${o>>16&255}, ${o>>8&255}, ${o&255}, ${e})`}return r.startsWith("rgba(")||r.startsWith("rgb(")?r:`rgba(0, 0, 0, ${e})`}function xYe(t){return t==="plain"||t==="outline"||t==="highlight-solid"||t==="highlight-translucent"?t:"plain"}function Irr(t,e,r,n,i){let o=["display:inline","box-decoration-break:clone","-webkit-box-decoration-break:clone","line-height:inherit"];return t==="plain"&&o.push("padding:0","border-radius:0","background:transparent","text-shadow:none","-webkit-text-stroke:0 transparent"),t==="outline"&&o.push("padding:0","border-radius:0","background:transparent",`text-shadow:2px 0 ${r},-2px 0 ${r},0 2px ${r},0 -2px ${r},1.5px 1.5px ${r},-1.5px 1.5px ${r},1.5px -1.5px ${r},-1.5px -1.5px ${r}`,`-webkit-text-stroke:1.5px ${r}`,"paint-order:stroke fill"),t==="highlight-solid"&&o.push("padding:0.07em 0.46em 0.09em","border-radius:0.32em",`background:${r}`,"text-shadow:none","-webkit-text-stroke:0 transparent"),t==="highlight-translucent"&&o.push("padding:0.07em 0.46em 0.09em","border-radius:0.32em",`background:${bYe(r,.34)}`,"text-shadow:none","-webkit-text-stroke:0 transparent"),n&&o.push(`font-family:${XM(n)}, 'TikTok Sans', 'Noto Color Emoji'`),i&&o.push(`font-weight:${i}`),o.push(`color:${e}`),o.join(";")}function vYe(t,e,r,n,i,o,a){t.textContent="",t.style.background="transparent",t.setAttribute("data-text-background-style",r),t.setAttribute("data-text-background-color",i),o&&(t.setAttribute("data-font-family",o),t.style.fontFamily=`${XM(o)}, 'TikTok Sans'`),a&&(t.style.fontWeight=String(a));let s=t.ownerDocument,l=s.createElement("span");l.setAttribute("data-vf-text-lines","true"),l.style.cssText="display:block;max-width:100%;text-align:inherit;line-height:1.48;white-space:pre-wrap;overflow:visible";let c=s.createElement("span");c.setAttribute("data-vf-text-inline","true"),o&&c.setAttribute("data-font-family",o),c.style.cssText=Irr(r,n,i,o,a),c.textContent=e,l.append(c),t.append(l)}function SYe(t){return Array.from(t.querySelectorAll("[data-cap-word]")).map(e=>({text:(e.textContent||"").trim(),start:Number(e.getAttribute("data-word-start"))||0,end:Number(e.getAttribute("data-word-end"))||0})).filter(e=>e.text)}function AYe(t){let e=SYe(t);return e.length?e.map(r=>r.text).join(" "):t.querySelector("[data-vf-text-inline]")?.textContent||t.textContent||""}function nZ(t,e,r){if(!t.hasAttribute("data-caption-animation"))return;let n=t.querySelector("[data-vf-text-inline]");if(!n)return;let i=SYe(t),o=e!==void 0?e:i.length?i.map(c=>c.text).join(" "):n.textContent||"",a=String(o||"").trim().split(/\s+/).filter(Boolean),s;r&&r.length?s=r:i.length===a.length&&i.every((c,u)=>c.text===a[u])&&i.some(c=>c.end>c.start)?s=i:s=$0e(a.join(" "),sf(t)),n.textContent="";let l=t.ownerDocument;s.forEach((c,u)=>{let f=l.createElement("span");f.setAttribute("data-cap-word","true"),f.setAttribute("data-word-start",String(Number(c.start.toFixed(3)))),f.setAttribute("data-word-end",String(Number(c.end.toFixed(3)))),f.style.animationDelay=`${Number(c.start.toFixed(3))}s`,f.style.animationDuration=`${Number(Math.max(.05,c.end-c.start).toFixed(3))}s`,f.textContent=c.text,u>0&&n.append(l.createTextNode(" ")),n.append(f)})}function wYe(t,e,r){let n=yYe(e);if(!n){let i=AYe(t).trim();t.removeAttribute("data-caption-animation"),t.hasAttribute("data-caption-uppercase")&&(t.removeAttribute("data-caption-uppercase"),t.style.textTransform="none"),t.style.removeProperty("--vf-cap-active"),t.style.removeProperty("--vf-cap-hl");let o=t.querySelector("[data-vf-text-inline]");o&&i&&(o.textContent=i);return}t.setAttribute("data-caption-animation",n),r?.uppercase!==void 0&&(r.uppercase?t.setAttribute("data-caption-uppercase","1"):t.removeAttribute("data-caption-uppercase"),t.style.textTransform=r.uppercase?"uppercase":"none"),r?.activeColor&&t.style.setProperty("--vf-cap-active",r.activeColor),r?.highlightColor&&t.style.setProperty("--vf-cap-hl",r.highlightColor),nZ(t,r?.text,r?.words)}function Prr(t){if(!t.querySelector("[data-caption-animation]"))return;for(let r of Array.from(t.querySelectorAll("style")))if((r.textContent??"").includes(pYe))return;let e=t.createElement("style");e.textContent=krr,(t.head??t.documentElement)?.appendChild(e)}function EYe(t,e,r,n){let i=Xe(r,"caption_animation")==="none",o=i?null:gYe(Xe(r,"caption_style"))??(Xe(r,"caption_animation")?null:mYe[0]),a=i?null:yYe(Xe(r,"caption_animation")??o?.animation);if(!i&&!a)return{ok:!1,error:`Unknown caption_animation "${Xe(r,"caption_animation")}". Use one of: ${hYe.join(", ")}, or "none" for static captions.`};let l=(Array.isArray(r.captions)?r.captions:[]).filter(C=>C&&typeof C.text=="string"&&C.text.trim()&&typeof C.start=="number"&&typeof C.duration=="number"&&C.duration>0).map(C=>{let k=Array.isArray(C.words)?C.words.map(_=>({text:String(_.text??"").trim(),start:Number(_.start)||0,end:Number(_.end)||0})).filter(_=>_.text&&_.end>_.start):[];return{text:C.text.trim(),start:C.start,duration:C.duration,words:k.length?k:$0e(C.text,C.duration)}});if(!l.length&&Xe(r,"text")){let C=n>0?n:60,k=Math.max(0,et(r,"start")??0),_=Math.max(.4,et(r,"duration")??C-k);l=_rr(Xe(r,"text"),k,_)}if(!l.length)return{ok:!1,error:"set_captions needs captions (array of {text,start,duration,words?}) or text (+ optional start/duration window)."};let c=Xe(r,"color")??o?.color??"#ffffff",u=Xe(r,"background")??o?.background??"#000000",f=xYe(Xe(r,"background_style")??o?.textBackgroundStyle),p=(C,k)=>C!=null&&C>0?C:k,d=(C,k)=>C??k,h=Xe(r,"font_family")?.trim()||"Montserrat",m=et(r,"font_weight")??o?.fontWeight??800,g=p(et(r,"font_size"),38),y={x:Pb(d(et(r,"x"),10),0,100),y:Pb(d(et(r,"y"),70),0,100),width:Pb(p(et(r,"width"),80),1,100),height:Pb(p(et(r,"height"),14),1,100)},b=0,x=new Set;for(let C of Array.from(t.querySelectorAll("[data-caption-animation]")))x.add(C);for(let C of Array.from(t.querySelectorAll('[data-layer-kind="caption"]')))x.add(C);for(let C of x)C.parentNode?.removeChild(C),b+=1;let S=Math.min(...l.map(C=>C.start)),v=Math.max(...l.map(C=>C.start+C.duration)),w=et(r,"track")!=null?Math.max(0,Math.floor(et(r,"track"))):qM(t)+1,A=YM(t,S,Math.max(.1,v-S),w),E=p0(r,"caption_uppercase")??o?.uppercase,O=Date.now().toString(36);l.forEach((C,k)=>{let _=`vf_cap_${O}_${k}`,P=t.createElement("div");P.id=_,P.setAttribute("data-hf-id",_),P.setAttribute("data-layer-mode","publish"),P.setAttribute("data-layer-kind","caption"),P.setAttribute("data-start",jr(C.start)),P.setAttribute("data-duration",jr(C.duration)),P.setAttribute("data-end",jr(C.start+C.duration)),Mb(P,A),P.setAttribute("data-label",C.text.slice(0,48)),P.classList.add("clip"),P.setAttribute("data-text-background-style",f),P.setAttribute("data-text-background-color",u),P.setAttribute("data-font-family",h),P.style.position="absolute",P.style.left=`${y.x}%`,P.style.top=`${y.y}%`,P.style.width=`${y.width}%`,P.style.height=`${y.height}%`,P.style.zIndex=String(A),P.style.display="flex",P.style.alignItems="center",P.style.justifyContent="center",P.style.padding="3px",P.style.boxSizing="border-box",P.style.textAlign="center",P.style.color=c,P.style.background="transparent",P.style.fontFamily=`${XM(h)}, 'TikTok Sans', sans-serif`,P.style.fontWeight=String(m),P.style.fontSize=`${g}px`,P.style.lineHeight="1.2",P.style.overflow="visible",vYe(P,C.text,f,c,u,h,m),a&&wYe(P,a,{activeColor:Xe(r,"caption_active_color")??o?.activeColor,highlightColor:Xe(r,"caption_highlight_color")??o?.highlightColor,uppercase:E,text:C.text,words:C.words}),e.append(P)}),Prr(t);let T=b>0?` (replaced ${b} previous caption cue(s))`:"";return{ok:!0,summary:`Set ${l.length} ${a?"animated":"static"} caption cue(s) on track ${A}, style ${o?.id??a??"none (static text)"}${T}.`}}function OYe(t,e){let r=[],n=t.querySelector("[data-vf-text-inline]"),i=Xe(e,"color");i&&(t.style.color=i,n&&(n.style.color=i),r.push(`color=${i}`));let o=Xe(e,"background_style"),a=Xe(e,"background");if(o||a&&n){let v=xYe(o??t.getAttribute("data-text-background-style")),w=a??t.getAttribute("data-text-background-color")??"#000000",A=i??t.style.color??"#ffffff";if(n){let E=t.getAttribute("data-font-family")??void 0,O=AYe(t);vYe(t,O,v,A,w,E,void 0),t.hasAttribute("data-caption-animation")&&nZ(t,O)}else v==="plain"?(t.style.background="transparent",t.style.textShadow="none"):v==="outline"?(t.style.background="transparent",t.style.setProperty("-webkit-text-stroke",`1.5px ${w}`),t.style.textShadow=`2px 0 ${w},-2px 0 ${w},0 2px ${w},0 -2px ${w}`):(t.style.background=v==="highlight-translucent"?bYe(w,.34):w,t.style.padding="0.07em 0.46em 0.09em",t.style.borderRadius="0.32em");o&&r.push(`background_style=${v}`),a&&r.push(`background=${a}`)}else a&&(t.style.background=a,r.push(`background=${a}`));let s=et(e,"font_size");s!=null&&(t.style.fontSize=`${s}px`,r.push(`font_size=${s}`));let l=Xe(e,"font_family");l&&(t.setAttribute("data-font-family",l),t.style.fontFamily=`${XM(l)}, 'TikTok Sans'`,n&&(n.style.fontFamily=`${XM(l)}, 'TikTok Sans'`),r.push(`font_family=${l}`));let c=et(e,"font_weight");c!=null&&(t.style.fontWeight=String(c),n&&(n.style.fontWeight=String(c)),r.push(`font_weight=${c}`));let u=p0(e,"italic");u!=null&&(t.style.fontStyle=u?"italic":"normal",r.push(`italic=${u}`));let f=p0(e,"underline");f!=null&&(t.style.textDecorationLine=f?"underline":"none",r.push(`underline=${f}`));let p=Xe(e,"text_align");p&&(t.style.textAlign=p,r.push(`text_align=${p}`));let d=et(e,"line_height");d!=null&&(t.style.lineHeight=String(d),r.push(`line_height=${d}`));let h=et(e,"letter_spacing");h!=null&&(t.style.letterSpacing=`${h}px`,r.push(`letter_spacing=${h}`));let m=et(e,"border_radius");m!=null&&(t.style.borderRadius=`${m}px`,r.push(`border_radius=${m}`));let g=gYe(Xe(e,"caption_style")),y=Xe(e,"caption_animation")??g?.animation,b=Xe(e,"caption_active_color")??g?.activeColor,x=Xe(e,"caption_highlight_color")??g?.highlightColor,S=p0(e,"caption_uppercase")??g?.uppercase;if(g&&r.push(`caption_style=${g.id}`),y!==void 0||b!==void 0||x!==void 0||S!==void 0){let v=y==="none"?null:y??t.getAttribute("data-caption-animation");wYe(t,v,{activeColor:b,highlightColor:x,uppercase:S}),r.push(`caption_animation=${v??"none"}`)}return r}function Nrr(t){let e=(t??"").trim().toLowerCase();return["linear","ease","ease-in","ease-out","ease-in-out","step-start","step-end"].includes(e)||/^cubic-bezier\(\s*(-?\d*\.?\d+\s*,\s*){3}-?\d*\.?\d+\s*\)$/.test(e)||/^steps\(\s*\d+\s*(,\s*(start|end|jump-(start|end|none|both))\s*)?\)$/.test(e)?e:"linear"}function TYe(t,e,r){let i=(Array.isArray(r.keyframes)?r.keyframes:[]).filter(p=>p&&Number.isFinite(p.offset)).sort((p,d)=>p.offset-d.offset);if(i.length<2)return{ok:!1,error:"set_layer_keyframes requires a keyframes array with at least 2 stops, each with an offset (0..1)."};if(i.every(p=>p.opacity===void 0&&p.translate_x===void 0&&p.translate_y===void 0&&p.scale===void 0&&p.rotate===void 0))return{ok:!1,error:"each keyframe needs at least one animated property (opacity, translate_x, translate_y, scale, rotate)."};let o=e.getAttribute("data-hf-id")||e.id||"layer",a=`hfk-${o.replace(/[^A-Za-z0-9_-]/g,"-")}`,s=et(r,"keyframe_duration"),l=s!=null&&s>0?s:sf(e)>0?sf(e):1,c=Nrr(Xe(r,"keyframe_easing")),u=i.map(p=>{let d=Number(Pb(p.offset*100,0,100).toFixed(3)).toString(),h=[];(p.translate_x!==void 0||p.translate_y!==void 0)&&h.push(`translate(${p.translate_x??0}%, ${p.translate_y??0}%)`),p.scale!==void 0&&h.push(`scale(${p.scale})`),p.rotate!==void 0&&h.push(`rotate(${p.rotate}deg)`);let m=[];return h.length&&m.push(`transform:${h.join(" ")}`),p.opacity!==void 0&&m.push(`opacity:${Pb(p.opacity,0,1)}`),`${d}%{${m.join(";")}}`}).join("");for(let p of Array.from(t.querySelectorAll(`style[data-vf-keyframes-for="${Mrr(o)}"]`)))p.parentNode?.removeChild(p);let f=t.createElement("style");return f.setAttribute("data-vf-keyframes-for",o),f.textContent=`@keyframes ${a}{${u}}`,(t.head??t.body??t.documentElement).appendChild(f),e.style.setProperty("animation",`${a} ${jr(l)}s ${c} both paused`),{ok:!0,summary:`Set a ${i.length}-stop CSS keyframe animation on ${o} (${jr(l)}s ${c}).`}}function Mrr(t){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(t):t.replace(/["\\]/g,"\\$&")}var Rrr="data:image/svg+xml;charset=utf-8,"+encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='360' height='640' viewBox='0 0 360 640'><rect width='360' height='640' fill='#0c0f0a'/><circle cx='180' cy='300' r='34' fill='none' stroke='#3ad07a' stroke-width='6' stroke-linecap='round' stroke-dasharray='150 60'/><text x='180' y='378' fill='#8ad9a6' font-family='monospace' font-size='20' text-anchor='middle'>Generating\u2026</text></svg>"),Drr="data:image/svg+xml;charset=utf-8,"+encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='360' height='640' viewBox='0 0 360 640'><rect width='360' height='640' fill='#210d10'/><circle cx='180' cy='292' r='34' fill='none' stroke='#ff6577' stroke-width='6'/><path d='M164 276l32 32m0-32l-32 32' stroke='#ff6577' stroke-width='6' stroke-linecap='round'/><text x='180' y='374' fill='#ffb4bd' font-family='sans-serif' font-size='18' text-anchor='middle'>Generation failed</text><text x='180' y='405' fill='#d999a1' font-family='sans-serif' font-size='12' text-anchor='middle'>Open this clip for details</text></svg>");function HC(t,e){let r=e.slice(0,200);t.setAttribute("data-vf-gen-status","error"),t.setAttribute("data-vf-gen-error",r),t.setAttribute("data-label",`Generation failed: ${r}`),t.setAttribute("alt",`Generation failed: ${r}`),t.setAttribute("title",r),t.tagName.toLowerCase()==="img"&&t.setAttribute("src",Drr)}function CYe(t,e,r,n,i){let o=(Xe(e,"prompt")??"").trim(),a=o.length>140?`${o.slice(0,137)}\u2026`:o,s=t.createElement("img");s.id=r,s.setAttribute("data-hf-id",r),s.setAttribute("data-layer-mode","publish"),s.setAttribute("data-layer-kind",n),s.setAttribute("data-viral-note",`AI generating ${n}: ${a}`),s.setAttribute("data-start",jr(i.start)),s.setAttribute("data-duration",jr(i.duration)),s.setAttribute("data-end",jr(i.start+i.duration)),Mb(s,i.track),s.setAttribute("data-label",`Generating ${n}\u2026`),s.classList.add("clip");let l=Xe(e,"slug");if(l&&s.setAttribute("data-hf-slug",l),s.setAttribute("data-vf-gen","1"),s.setAttribute("data-vf-gen-media",n),s.setAttribute("data-vf-gen-status","submitting"),s.setAttribute("data-vf-gen-prompt",a),s.style.position="absolute",s.style.left=`${i.x}%`,s.style.top=`${i.y}%`,s.style.width=`${i.width}%`,s.style.height=`${i.height}%`,s.style.zIndex=String(i.track),s.style.overflow="hidden",s.style.objectFit=Xe(e,"object_fit")??"cover",s.style.background="#0c0f0a",s.setAttribute("src",Rrr),n==="video")s.setAttribute("data-volume","1"),s.setAttribute("data-media-start","0"),s.setAttribute("data-playback-start","0");else{let c=Xe(e,"ken_burns");if(c&&c!=="none"){s.setAttribute("data-kenburns",c);let u=et(e,"ken_burns_intensity");u!=null&&s.setAttribute("data-kenburns-intensity",String(u))}}return KM(s,e),s}function kYe(t){if(!t)return null;let e=l=>typeof l=="string"&&l.trim()?l.trim():null,r=l=>l&&typeof l=="object"?l:null,n=r(t.result)??{},i=r(n.output)??n,o=e(i.primary_file_url)??e(r(i.video)?.file_url)??e(r(i.image)?.file_url)??e(r(i.render)?.output_url);if(o)return o;let a=i.files;if(Array.isArray(a))for(let l of a){let c=e(typeof l=="string"?l:r(l)?.file_url??r(l)?.url);if(c)return c}let s=Array.isArray(t.artifacts)?t.artifacts:[];for(let l of s){let c=e(r(l)?.public_url);if(c)return c}return null}function _Ye(t,e){let r=t.error;if(typeof r=="string"&&r.trim())return r.trim();if(r&&typeof r=="object"){let n=r;for(let i of["message","error","detail"]){let o=n[i];if(typeof o=="string"&&o.trim())return o.trim()}}return e}function IYe(t,e){let r=t.getAttribute("data-vf-gen-media"),n=t;if(r==="video"&&t.tagName.toLowerCase()!=="video"){let o=t.ownerDocument.createElement("video");for(let a of Array.from(t.attributes))o.setAttribute(a.name,a.value);o.setAttribute("playsinline",""),o.setAttribute("preload","auto"),t.replaceWith(o),n=o}n.setAttribute("src",e),D0e(e)&&F0e(n),n.removeAttribute("poster"),n.removeAttribute("alt"),n.removeAttribute("title");for(let o of["data-vf-gen","data-vf-gen-media","data-vf-gen-prompt","data-vf-gen-job","data-vf-gen-tracer","data-vf-gen-error","data-vf-gen-status"])n.removeAttribute(o);let i=n.getAttribute("data-label");i&&/generating/i.test(i)&&n.setAttribute("data-label",r==="image"?"AI image":"AI video"),n.setAttribute("data-viral-note",`AI generated ${r==="image"?"image":"video"}.`)}function Lrr(t){if(t.tagName.toLowerCase()==="audio"||t.hasAttribute("data-caption-animation"))return!1;let e=(t.getAttribute("data-layer-kind")??"").toLowerCase();if(e==="audio"||e==="caption")return!1;if(e==="video"||e==="image"||e==="html"||e==="shape"||e==="text"||t.getAttribute("data-vf-timeline-proxy")!==null)return!0;let r=t.tagName.toLowerCase();return r==="video"||r==="img"}function PYe(t){let e=[];for(let r of m1(t)){if(!Lrr(r))continue;let n=sf(r);if(!(n>0))continue;let i=af(r);e.push({start:i,end:i+n})}return e}function NYe(t,e){let n=l=>Number(l.toFixed(3));if(!Number.isFinite(e)||e<=0)return[];let i=t.filter(l=>Number.isFinite(l.start)&&Number.isFinite(l.end)&&l.end>l.start).sort((l,c)=>l.start-c.start),o=[];for(let l of i){let c=o[o.length-1];c&&l.start<=c.end+.001?c.end=Math.max(c.end,l.end):o.push({start:Math.max(0,l.start),end:l.end})}let a=[],s=0;for(let l of o)l.start-s>=.2&&a.push({start:n(s),end:n(l.start),duration:n(l.start-s)}),s=Math.max(s,l.end);return e-s>=.2&&a.push({start:n(s),end:n(e),duration:n(e-s)}),a}function U0e(t,e){let r=Number.isFinite(e)&&e>0?e:0,n=0;for(let i of m1(t)){let o=af(i),a=sf(i);Number.isFinite(o)&&Number.isFinite(a)&&(n=Math.max(n,o+a))}return n>0?n:r}function MYe(t,e,r){let n=1/0;for(let i of m1(t)){let o=i.getAttribute("data-hf-id")||i.id;if(o&&r.has(o))continue;let a=(i.getAttribute("data-layer-kind")||"").toLowerCase(),s=i.getAttribute("data-vf-timeline-proxy")!==null;if(!(s||["video","image","html","shape"].includes(a))||!(s||i.getAttribute("data-vf-full-canvas")==="true"||Number.parseFloat(i.style.width)>=99.5&&Number.parseFloat(i.style.height)>=99.5))continue;let u=af(i);Number.isFinite(u)&&u>e+.05&&(n=Math.min(n,u))}return n}function RYe(t){let e=[];for(let r of Array.from(t.querySelectorAll("[data-vf-gen-media]"))){let n=r.getAttribute("data-vf-gen-media"),i=n==="image"?"image":n==="video"?"video":null;if(!i)continue;let o=af(r),a=sf(r);e.push({layer_key:r.getAttribute("data-hf-id")||r.id||null,media_type:i,status:r.getAttribute("data-vf-gen-status")||"generating",job_id:r.getAttribute("data-vf-gen-job")||void 0,start:Number.isFinite(o)?o:void 0,duration:Number.isFinite(a)?a:void 0,prompt:r.getAttribute("data-vf-gen-prompt")||void 0,error:r.getAttribute("data-vf-gen-error")||void 0})}return e}function DYe(t){return m1(t).map(e=>{let r=e.tagName.toLowerCase(),n=e.getAttribute("data-layer-kind")??(r==="img"?"image":r==="video"||r==="audio"?r:"html"),i=e.style?.animationName||null,o=e.getAttribute("data-volume");return{element_id:e.getAttribute("data-hf-id")??(e.id||null),slug:e.getAttribute("data-hf-slug"),note:e.getAttribute("data-hf-note")??e.getAttribute("data-viral-note"),kind:n,src:e.getAttribute("src"),label:e.getAttribute("data-label"),start:af(e),duration:sf(e),track:Nb(e),transition:e.getAttribute("data-transition"),transition_out:e.getAttribute("data-transition-out"),ken_burns:e.getAttribute("data-kenburns"),animation:i&&i!=="none"?i:null,volume:o!=null?Number(o):null,muted:e.hasAttribute("muted"),loop:e.getAttribute("data-loop")==="true"||e.hasAttribute("loop")}})}function LYe(t,e){if(!(t>0)||!(e>0))return null;let r=(i,o)=>o?r(o,i%o):i,n=r(Math.round(t),Math.round(e));return`${Math.round(t)/n}:${Math.round(e)/n}`}var iZ=[],Frr=8;function Brr(t){iZ.push(t),iZ.length>Frr&&iZ.shift()}var JM="idle",FYe=null,z0e=null,BYe=!0;async function Uh(t,e){let r=await ZM(t,e);return BYe=r,r}function tR(t){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(t):t.replace(/["\\]/g,"\\$&")}function $Ye(t,e=8e3){return new Promise(r=>{let n=document.createElement("video"),i=!1,o=s=>{i||(i=!0,n.removeAttribute("src"),n.load(),r(s))},a=setTimeout(()=>o(null),e);n.preload="metadata",n.muted=!0,n.addEventListener("loadedmetadata",()=>{clearTimeout(a),o(Number.isFinite(n.duration)&&n.duration>0?n.duration:null)}),n.addEventListener("error",()=>{clearTimeout(a),o(null)}),n.src=t})}function aZ(t,e){return t.querySelector(`[data-hf-id="${tR(e)}"]`)||t.querySelector(`[data-hf-slug="${tR(e)}"]`)||t.getElementById(e)}function g1(t,e){let r=new DOMParser().parseFromString(t,"text/html");return e(r)?WM(r):null}function Q0e(t){let e=new Set;return t.querySelectorAll("[data-hf-id]").forEach(r=>{let n=r.getAttribute("data-hf-id");n&&e.add(n)}),t.querySelectorAll("[data-hf-slug]").forEach(r=>{let n=r.getAttribute("data-hf-slug");n&&e.add(n)}),Array.from(e)}function $rr(t,e){let r=e.length?` Available layer keys: ${e.join(", ")}.`:"";return{ok:!1,error:`layer "${t}" not found.${r} Use a layer_key from the current editor_context.`}}async function sd(t,e,r){let n=!1,i=[],o=await Uh(t,a=>g1(a,s=>{let l=aZ(s,e);return l?(n=!0,r(l,s)):(i=Q0e(s),!1)})??a);return n?o?{ok:!0}:{ok:!1,error:"couldn't save the edit \u2014 composition read/write failed; try again"}:o?$rr(e,i):{ok:!1,error:"couldn't read the composition to edit \u2014 try again"}}async function H0e(t,e,r){let n=[],i=[],o=[];if(!await Uh(t,s=>g1(s,l=>{n.length=0,i.length=0;for(let c of e){let u=aZ(l,c);if(!u){i.push(c);continue}n.push(c),r(u,l,c)}return i.length&&(o=Q0e(l)),n.length>0})??s))return{outcome:{ok:!1,error:"couldn't save the edit \u2014 composition read/write failed; try again"},matched:n,missed:i};if(n.length===0){let s=o.length?` Available layer keys: ${o.join(", ")}.`:"";return{outcome:{ok:!1,error:`no matching layers for ${e.map(l=>`"${l}"`).join(", ")}.${s}`},matched:n,missed:i}}return{outcome:{ok:!0},matched:n,missed:i}}function V0e(t){return t.length?` (not found: ${t.join(", ")})`:""}async function _E(t,e,r){return await Uh(t,n=>g1(n,i=>{let o=i.querySelector(`[data-hf-id="${tR(e)}"]`);return o?(r(o),!0):!1})??n)}async function Urr(t,e,r,n,i){let o=r==="video"?"/api/v1/primitives/videos/generate":"/api/v1/primitives/images/generate",a=h=>typeof h=="string"&&/^https?:\/\//i.test(h),s=(Array.isArray(i.input_references)?i.input_references:[]).filter(a),l=(Array.isArray(i.prompt_attachments)?i.prompt_attachments:[]).filter(a),c={prompt:n},u=Xe(i,"aspect_ratio")?.trim();u&&(c.aspect_ratio=u);let f=Xe(i,"provider")?.trim();f&&(c.provider=f);let p=Xe(i,"model")?.trim();if(p&&(c.model=p),r==="video"){let h=et(i,"gen_duration");h!=null&&(c.duration=Math.round(h));let m=Xe(i,"resolution");m&&(c.resolution=m);let g=p0(i,"generate_audio");g!=null&&(c.generate_audio=g),s.length&&(c.input_references=s.slice(0,8))}else l.length&&(c.prompt_attachments=l.slice(0,16));let d=`editor-gen-${Date.now().toString(36)}`;try{let h=await fetch(o,{method:"POST",credentials:"same-origin",headers:JQ({"content-type":"application/json"}),body:JSON.stringify({tracer:d,payload:c})}),m=await h.json().catch(()=>({}));if(!h.ok||!m.job_id){let g=m.error||`generation request failed (${h.status})`;await _E(t,e,y=>HC(y,g));return}await _E(t,e,g=>{g.setAttribute("data-vf-gen-job",m.job_id),g.setAttribute("data-vf-gen-tracer",d),g.setAttribute("data-vf-gen-status","generating")}),Z0e()}catch(h){await _E(t,e,m=>HC(m,h instanceof Error?h.message:String(h)))}}var eR=null,oZ=null,j0e=!1;function Z0e(){eR!=null||typeof window>"u"||(eR=setInterval(()=>{Hrr()},6e3))}function G0e(){eR!=null&&(clearInterval(eR),eR=null)}async function Hrr(){if(!j0e){j0e=!0;try{let t=oZ?.()??null;if(!t){G0e();return}let r=(await Ib(t))?.content;if(!r)return;if(!(r.includes('data-vf-gen-status="generating"')||r.includes('data-vf-gen-status="submitting"'))){G0e();return}let i=new DOMParser().parseFromString(r,"text/html"),o=Array.from(i.querySelectorAll('[data-vf-gen-status="generating"][data-vf-gen-job]'));for(let a of o){let s=a.getAttribute("data-hf-id")||a.id,l=a.getAttribute("data-vf-gen-job");if(!(!s||!l))try{let c=await fetch(`/api/v1/user/me/jobs/${encodeURIComponent(l)}`,{credentials:"same-origin",headers:JQ()});if(!c.ok){c.status>=400&&c.status<500&&c.status!==429&&await _E(t,s,d=>HC(d,`generation job unavailable (${c.status})`));continue}let u=await c.json().catch(()=>null);if(!u)continue;let f=kYe(u);if(f){await _E(t,s,d=>IYe(d,f));continue}let p=typeof u.status=="string"?u.status:"";if(p==="failed"||p==="cancelled"){let d=_Ye(u,`generation ${p}`);await _E(t,s,h=>HC(h,d))}else p==="succeeded"&&await _E(t,s,d=>HC(d,"generation succeeded without a usable media URL"))}catch{}}}finally{j0e=!1}}}async function Vrr(t,e){let r=Xe(e,"media_type")??Xe(e,"kind"),n=r==="image"?"image":r==="video"?"video":null;if(!n)return{ok:!1,error:"generate_layer requires media_type 'video' or 'image'."};let i=Xe(e,"prompt").trim(),o=Xe(e,"intent")??(Xe(e,"replace_layer_key")?"replace_layer":"add"),a=null,s="",l="",c=await Uh(t,u=>g1(u,f=>{a=null;let p=Wv(f);if(!p)return a="composition root not found",!1;let d=et(e,"start"),h=et(e,"duration"),m=et(e,"track"),g=et(e,"x"),y=et(e,"y"),b=et(e,"width"),x=et(e,"height"),S=null,v=null;if(o==="replace_layer"){let N=(Xe(e,"replace_layer_key")??Xe(e,"layer_key")??"").trim();if(!N)return a="generate_layer intent=replace_layer requires replace_layer_key (the layer to replace).",!1;if(v=aZ(f,N),!v){let G=Q0e(f);return a=`generate_layer: layer to replace not found: ${N}.${G.length?` Available layer keys: ${G.join(", ")}.`:""}`,!1}S=v.getAttribute("data-hf-id")||v.id||N;let H=v.getAttribute("data-vf-timeline-proxy")!==null||v.getAttribute("data-vf-full-canvas")==="true"||v.style.width==="100%"&&v.style.height==="100%";if(d==null&&(d=af(v)),h==null&&(h=sf(v)>0?sf(v):null),m==null&&(m=Nb(v)),H)g=0,y=0,b=100,x=100;else{let G=j=>{let Q=Number.parseFloat(j);return Number.isFinite(Q)?Q:null};g==null&&(g=G(v.style.left)),y==null&&(y=G(v.style.top)),b==null&&(b=G(v.style.width)),x==null&&(x=G(v.style.height))}}let w=Xe(e,"layer_key")?.trim(),A=w&&w!==S&&/^[A-Za-z][\w-]{0,63}$/.test(w)?w:`vf-gen-${Date.now().toString(36)}${Math.floor(Math.random()*1e3).toString(36)}`,E=U0e(f,parseFloat(p.getAttribute("data-duration")??"0")||0),O=d??0,T=Math.max(0,E>0?Math.min(E-.1,O):O),C=E>0?Math.max(.1,E-T):4,k=h??Math.min(n==="video"?et(e,"gen_duration")??4:4,C),_=Math.max(.1,E>0?Math.min(k,C):k),P=N=>Math.max(0,Math.min(100,N)),F=P(g??0),V=P(y??0),$=P(b??100),z=P(x??100);v&&v.remove();let B=1,U=$>=99.5&&z>=99.5&&F<=.5&&V<=.5;if(et(e,"duration")==null&&U&&_<B){let N=new Set([A]);S&&N.add(S);let H=MYe(f,T,N),j=(Number.isFinite(H)?H:E>0?E:T+4)-T;_=Math.max(B,Number.isFinite(j)&&j>0?j:Math.min(4,C))}let L=m!=null?Math.max(0,Math.trunc(m)):qM(f)+1,D=YM(f,T,_,L),R=CYe(f,e,A,n,{start:T,duration:_,track:D,x:F,y:V,width:$,height:z});p.appendChild(R),l=A;let I=o==="replace_layer"?`replacing ${S}`:`at ${T.toFixed(2)}s`;return s=`Started ${n} generation (${I}). A placeholder is on the timeline as ${A}; it will swap to the finished media automatically. Watch editor_context.pending_generations.`,!0})??u);return a?{ok:!1,error:a}:!c||!l?{ok:!1,error:"couldn't save the generation placeholder \u2014 composition read/write failed; try again"}:(Urr(t,l,n,i,e),Z0e(),{ok:!0,summary:s})}async function jrr(t,e,r){let n=e.action_type??"",i=e.layer_key??"",o=e;switch(n){case"replace_composition_html":{let a=typeof e.composition_html=="string"?e.composition_html:null;return a?await Uh(t,()=>a)?{ok:!0,summary:"Replaced composition."}:{ok:!1,error:"write failed"}:{ok:!1,error:"missing composition_html"}}case"add_layer":case"generate_layer":{let a=typeof e.layer_html=="string"?e.layer_html:null;if(a)return await Uh(t,m=>eZ(m,a))?{ok:!0,summary:"Added a layer."}:{ok:!1,error:"write failed"};let s=Xe(o,"src");if(n==="generate_layer"){if(Xe(o,"prompt")?.trim())return await Vrr(t,o);if(!s)return{ok:!1,error:"generate_layer requires a prompt (what to generate) \u2014 or use add_layer with a src for media that already exists."}}let l=Xe(o,"kind")??Xe(o,"media_type")??(s?L0e(s):null)??(Xe(o,"text")?"text":Xe(o,"html")?"html":null);if(!l)return{ok:!1,error:"add_layer needs kind (video|image|audio|text|html) or a src/text/html to infer it from"};let c=Math.max(0,et(o,"start")??0),u=et(o,"duration")??0;u>0||(u=l==="video"&&s?await $Ye(s)??3:3);let f=null,p="",d=await Uh(t,h=>g1(h,m=>{let g=Wv(m);if(!g)return f="composition root not found",!1;let y=et(o,"track"),b=y!=null?Math.max(0,Math.trunc(y)):YM(m,c,u,qM(m)+1),x=B0e(m,o,{kind:l,start:c,duration:u,track:b});if("error"in x)return f=x.error,!1;g.appendChild(x.el);let S=c+u,v=parseFloat(g.getAttribute("data-duration")??"0")||0;return S>v&&g.setAttribute("data-duration",jr(S)),p=`Added ${l} layer "${x.id}" at ${jr(c)}s for ${jr(u)}s on track ${b}.`,!0})??h);return f?{ok:!1,error:f}:d?{ok:!0,summary:p}:{ok:!1,error:"couldn't save the new layer \u2014 composition read/write failed; try again"}}case"set_layer_text":{let a=typeof e.text=="string"?e.text:null;if(!i||a==null)return{ok:!1,error:"missing layer_key/text"};let s=await sd(t,i,l=>{if(l.hasAttribute("data-caption-animation")&&l.querySelector("[data-vf-text-inline]"))nZ(l,a);else{let c=l.querySelector("[data-vf-text-inline]");c?c.textContent=a:l.textContent=a}return l.hasAttribute("data-label")&&l.setAttribute("data-label",a.slice(0,48)),!0});return s.ok?{ok:!0,summary:`Set text on ${i}.`}:s}case"set_captions":{let a=null,s=await Uh(t,l=>g1(l,c=>{let u=Wv(c);if(!u)return a={ok:!1,error:"composition root not found"},!1;let f=parseFloat(u.getAttribute("data-duration")??"0")||0;return a=EYe(c,u,o,f),a.ok})??l);return a&&!a.ok?a:s?a??{ok:!1,error:"couldn't read the composition to edit \u2014 try again"}:{ok:!1,error:"couldn't save the captions \u2014 composition read/write failed; try again"}}case"set_layer_media":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Xe(o,"src"),s=[],l=!1,c=await sd(t,i,u=>{s.length=0;let f=u.matches("img,video,audio")?u:u.querySelector("img,video,audio"),p=f?.tagName.toLowerCase()??"";if(a){if(!f)return l=!0,!1;f.setAttribute("src",a),D0e(a)&&F0e(f),s.push("src")}let d=Xe(o,"object_fit");d&&f&&(f.style.objectFit=d,s.push(`object_fit=${d}`));let h=Xe(o,"object_position");h&&f&&(f.style.objectPosition=h,s.push(`object_position=${h}`));let m=et(o,"volume");m!=null&&f&&(f.setAttribute("data-volume",String(Math.max(0,Math.min(1,m)))),s.push(`volume=${m}`));let g=p0(o,"muted");g!=null&&f&&(g?f.setAttribute("muted",""):f.removeAttribute("muted"),s.push(`muted=${g}`));let y=p0(o,"loop");y!=null&&f&&p==="video"&&(y?(f.setAttribute("loop",""),f.setAttribute("data-loop","true")):(f.removeAttribute("loop"),f.removeAttribute("data-loop")),s.push(`loop=${y}`));let b=Xe(o,"ken_burns");if(b&&f){if(b==="none")f.removeAttribute("data-kenburns"),f.removeAttribute("data-kenburns-intensity");else{f.setAttribute("data-kenburns",b);let S=et(o,"ken_burns_intensity");S!=null&&f.setAttribute("data-kenburns-intensity",String(S))}s.push(`ken_burns=${b}`)}let x=et(o,"playback_start");return x!=null&&f&&(f.setAttribute("data-playback-start",jr(Math.max(0,x))),s.push(`playback_start=${x}`)),s.push(...KM(u,o)),s.length>0});return c.ok?l?{ok:!1,error:`layer "${i}" has no img/video/audio element to swap.`}:s.length===0?{ok:!1,error:"set_layer_media needs at least one field (src, object_fit, object_position, volume, muted, loop, ken_burns, playback_start, transition\u2026)"}:{ok:!0,summary:`Updated media on ${i} (${s.join(", ")}).`}:c}case"set_layer_style":{if(!i)return{ok:!1,error:"missing layer_key"};let a=[],s=await sd(t,i,l=>(a=OYe(l,o),a.length>0));return s.ok?a.length===0?{ok:!1,error:"set_layer_style needs at least one style field."}:{ok:!0,summary:`Restyled ${i} (${a.join(", ")}).`}:s}case"set_layer_identity":{if(!i)return{ok:!1,error:"missing layer_key"};let a=await sd(t,i,s=>(typeof e.slug=="string"&&s.setAttribute("data-hf-slug",e.slug),typeof e.note=="string"&&(e.note===""?s.removeAttribute("data-hf-note"):s.setAttribute("data-hf-note",e.note)),!0));return a.ok?{ok:!0,summary:`Tagged ${i}.`}:a}case"remove_layer":{if(!i)return{ok:!1,error:"missing layer_key"};let a=await sd(t,i,s=>(s.remove(),!0));return a.ok?{ok:!0,summary:`Removed ${i}.`}:a}case"set_composition":{let a=et(o,"canvas_width"),s=et(o,"canvas_height"),l=et(o,"canvas_duration"),c=Xe(o,"background_color");if(a==null&&s==null&&l==null&&!c)return{ok:!1,error:"set_composition needs canvas_width, canvas_height, canvas_duration and/or background_color"};let u=[];return await Uh(t,p=>g1(p,d=>{u.length=0;let h=Wv(d)??d.body;return h?(a!=null&&(h.setAttribute("data-width",String(Math.round(a))),u.push(`width=${Math.round(a)}`)),s!=null&&(h.setAttribute("data-height",String(Math.round(s))),u.push(`height=${Math.round(s)}`)),l!=null&&l>0&&(h.setAttribute("data-duration",jr(l)),u.push(`duration=${l}`)),c&&(h.style.background=c,u.push(`background=${c}`)),u.length>0):!1})??p)?u.length===0?{ok:!1,error:"no valid set_composition field applied"}:{ok:!0,summary:`Updated composition (${u.join(", ")}).`}:{ok:!1,error:"couldn't save \u2014 composition read/write failed; try again"}}case"set_layer_timing":{if(!i)return{ok:!1,error:"missing layer_key"};let a=[],s=await sd(t,i,l=>{a.length=0;let c=et(o,"start"),u=et(o,"duration");(c!=null||u!=null)&&(h1(l,c??void 0,u??void 0),c!=null&&a.push(`start=${c}`),u!=null&&a.push(`duration=${u}`));let f=et(o,"track");f!=null&&(Mb(l,f),a.push(`track=${f}`));let p=et(o,"playback_start");return p!=null&&(l.setAttribute("data-playback-start",jr(Math.max(0,p))),a.push(`playback_start=${p}`)),a.length>0});return s.ok?a.length===0?{ok:!1,error:"set_layer_timing needs start, duration, track and/or playback_start"}:{ok:!0,summary:`Retimed ${i} (${a.join(", ")}).`}:s}case"trim_layer":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Xe(o,"edge"),s=et(o,"to_time");if(a&&s!=null){let u=null,f="",p=await sd(t,i,d=>{let h=af(d),m=h+sf(d);if(a==="start"){if(!(s<m))return u=`to_time ${s}s must be before the clip's end (${jr(m)}s) for edge=start.`,!1;let g=Math.max(0,s),y=g-h;h1(d,g,m-g);let b=d.tagName.toLowerCase(),x=b==="video"||b==="audio"?d:d.querySelector("video,audio");x&&x.setAttribute("data-playback-start",jr(Math.max(0,R0e(x)+y))),f=`Trimmed ${i} start to ${jr(g)}s (duration ${jr(m-g)}s).`}else{if(!(s>h))return u=`to_time ${s}s must be after the clip's start (${jr(h)}s) for edge=end.`,!1;h1(d,void 0,s-h),f=`Trimmed ${i} end to ${jr(s)}s (duration ${jr(s-h)}s).`}return!0});return u?{ok:!1,error:u}:p.ok?{ok:!0,summary:f}:p}let l=[],c=await sd(t,i,u=>{l.length=0;let f=et(o,"start"),p=et(o,"duration");(f!=null||p!=null)&&h1(u,f??void 0,p??void 0),f!=null&&l.push(`start=${f}`),p!=null&&l.push(`duration=${p}`);let d=et(o,"track");return d!=null&&(Mb(u,d),l.push(`track=${d}`)),l.length>0});return c.ok?l.length===0?{ok:!1,error:"trim_layer needs edge ('start'|'end') + to_time, or start/duration/track"}:{ok:!0,summary:`Retimed ${i} (${l.join(", ")}).`}:c}case"set_transitions":{if(i){let l=[],c=await sd(t,i,u=>(l=KM(u,o),l.length>0));return c.ok?l.length===0?{ok:!1,error:"set_transitions needs transition, transition_out and/or their durations"}:{ok:!0,summary:`Set transitions on ${i} (${l.join(", ")}).`}:c}let a=null,s=await Uh(t,l=>g1(l,c=>(a=dYe(c,o),a.ok))??l);return a&&!a.ok?a:s?a??{ok:!1,error:"couldn't read the composition to edit \u2014 try again"}:{ok:!1,error:"couldn't save the transitions \u2014 composition read/write failed; try again"}}case"set_layer_zindex":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Xe(o,"z_order"),s=et(o,"track");if(!a&&s==null)return{ok:!1,error:"set_layer_zindex needs z_order (front|back|forward|backward) or track"};let l="",c=await sd(t,i,(u,f)=>{let p=Nb(u),d=p;return s!=null?d=Math.max(0,Math.trunc(s)):a==="front"?d=m1(f).filter(h=>h!==u).reduce((h,m)=>Math.max(h,Nb(m)),-1)+1:a==="back"?d=0:a==="forward"?d=p+1:a==="backward"&&(d=Math.max(0,p-1)),Mb(u,d),u.style.zIndex&&(u.style.zIndex=String(d)),l=`Restacked ${i}: track ${p} \u2192 ${d}.`,d!==p||s!=null});return c.ok?{ok:!0,summary:l||`Restacked ${i}.`}:c}case"set_layer_visual":{if(!i)return{ok:!1,error:"missing layer_key"};let a=[],s=await sd(t,i,l=>{a.length=0;let c=et(o,"x");c!=null&&(l.style.left=`${c}%`,a.push(`x=${c}`));let u=et(o,"y");u!=null&&(l.style.top=`${u}%`,a.push(`y=${u}`));let f=et(o,"width");f!=null&&(l.style.width=`${f}%`,a.push(`width=${f}`));let p=et(o,"height");p!=null&&(l.style.height=`${p}%`,a.push(`height=${p}`));let d=et(o,"opacity");d!=null&&(l.style.opacity=String(Math.max(0,Math.min(1,d))),a.push(`opacity=${d}`));let h=et(o,"font_size");h!=null&&(l.style.fontSize=`${h}px`,a.push(`font_size=${h}`));let m=et(o,"border_radius");return m!=null&&(l.style.borderRadius=`${m}px`,l.style.overflow="hidden",a.push(`border_radius=${m}`)),a.length>0});return s.ok?a.length===0?{ok:!1,error:"no visual fields (x, y, width, height, opacity, font_size, border_radius)"}:{ok:!0,summary:`Adjusted ${i} (${a.join(", ")}).`}:s}case"duplicate_layer":{if(!i)return{ok:!1,error:"missing layer_key"};let a=Array.isArray(e.layer_keys)&&typeof e.layer_keys[1]=="string"?e.layer_keys[1]:null,s="",l=await sd(t,i,(c,u)=>{s=a&&!aZ(u,a)?M0e(a):`vf_${Date.now().toString(36)}`;let f=c.cloneNode(!0);f.setAttribute("data-hf-id",s),f.id=s,f.removeAttribute("data-hf-slug");let p=et(o,"start"),d=et(o,"duration");(p!=null||d!=null)&&h1(f,p??void 0,d??void 0);let h=et(o,"track");h!=null&&Mb(f,h);let m=Xe(o,"label");return m&&f.setAttribute("data-label",m),c.parentNode?.insertBefore(f,c.nextSibling),!0});return l.ok?{ok:!0,summary:`Duplicated ${i} as ${s}.`}:l}case"split_layer":{let a=typeof e.split_time=="number"?e.split_time:null;if(!i||a==null)return{ok:!1,error:"missing layer_key/split_time"};let s=!1,l=await sd(t,i,c=>{let u=af(c),f=sf(c),p=u+f;if(!(a>u&&a<p))return s=!0,!1;h1(c,void 0,a-u);let d=c.cloneNode(!0),h=`vf_${Date.now().toString(36)}`;d.setAttribute("data-hf-id",h),d.id=h,d.removeAttribute("data-hf-slug"),h1(d,a,p-a);let m=d.tagName.toLowerCase(),g=m==="video"||m==="audio"?d:d.querySelector("video,audio");return g&&g.setAttribute("data-playback-start",jr(Math.max(0,R0e(g)+(a-u)))),c.parentNode?.insertBefore(d,c.nextSibling),!0});return l.ok&&s?{ok:!1,error:`split_time ${a}s is outside layer "${i}"'s span.`}:l.ok?{ok:!0,summary:`Split ${i} at ${a}s.`}:l}case"nudge_layers":{let a=Array.isArray(e.layer_keys)?e.layer_keys.map(String):i?[i]:[];if(a.length===0)return{ok:!1,error:"missing layer_keys"};let s=typeof e.delta_start=="number"?e.delta_start:0,l=typeof e.delta_track=="number"?e.delta_track:0;if(s===0&&l===0)return{ok:!1,error:"no delta"};let c=new Set,u=null,{outcome:f,matched:p,missed:d}=await H0e(t,a,(h,m)=>{u!==m&&(c.clear(),u=m);let g=h.getAttribute("data-vf-group"),y=g?Array.from(m.querySelectorAll(`[data-vf-group="${tR(g)}"][data-start]`)):[h];for(let b of y)c.has(b)||(c.add(b),s!==0&&h1(b,Math.max(0,af(b)+s),void 0),l!==0&&Mb(b,Nb(b)+l))});return f.ok?{ok:!0,summary:`Nudged ${p.length} layer(s) by ${s}s / ${l} lane(s).${V0e(d)}`}:f}case"ripple_edit":{let a=typeof e.at_time=="number"?e.at_time:null,s=typeof e.delta_start=="number"?e.delta_start:null;if(a==null||s==null)return{ok:!1,error:"missing at_time/delta_start"};let l=0;return await Uh(t,u=>g1(u,f=>{l=0;for(let p of m1(f)){let d=af(p);d>=a&&(h1(p,Math.max(0,d+s),void 0),l+=1)}return l>0})??u)?l===0?{ok:!1,error:`no clips start at or after ${a}s`}:{ok:!0,summary:`Rippled ${l} clip(s) by ${s}s at ${a}s.`}:{ok:!1,error:"couldn't save the ripple \u2014 composition read/write failed; try again"}}case"group_layers":{let a=Array.isArray(e.layer_keys)?e.layer_keys.map(String):[];if(a.length<2)return{ok:!1,error:"group_layers requires layer_keys with at least two entries."};let s=`vf-group-${Date.now().toString(36)}`,l=Xe(o,"group_label")??"Vidfarm group",{outcome:c,matched:u,missed:f}=await H0e(t,a,p=>{p.setAttribute("data-vf-group",s),p.setAttribute("data-vf-group-label",l)});return c.ok?f.length?{ok:!0,summary:`Grouped ${u.length} layer(s) as ${s} \u2014 WARNING, not found: ${f.join(", ")}.`}:{ok:!0,summary:`Grouped ${u.length} layers as ${s}.`}:c}case"ungroup_layers":{let a=Array.isArray(e.layer_keys)?e.layer_keys.map(String):i?[i]:[];if(a.length===0)return{ok:!1,error:"ungroup_layers requires layer_keys."};let s=0,{outcome:l,matched:c,missed:u}=await H0e(t,a,(f,p)=>{let d=f.getAttribute("data-vf-group");if(d)for(let h of Array.from(p.querySelectorAll(`[data-vf-group="${tR(d)}"]`)))h.removeAttribute("data-vf-group"),h.removeAttribute("data-vf-group-label"),s+=1});return l.ok?s===0?{ok:!1,error:`layers ${c.join(", ")} weren't grouped.${V0e(u)}`}:{ok:!0,summary:`Ungrouped ${s} layer(s).${V0e(u)}`}:l}case"set_layer_keyframes":{if(!i)return{ok:!1,error:"missing layer_key"};let a=null,s=await sd(t,i,(l,c)=>(a=TYe(c,l,o),a.ok));return a&&!a.ok?a:s.ok?a??{ok:!1,error:"couldn't apply keyframes"}:s}case"export_composition":return JM==="rendering"?{ok:!1,error:"a render is already in flight \u2014 wait for it to finish (the MP4 URL will appear as last_export_url)."}:(JM="rendering",z0e=null,await new Promise(a=>{let s=!1,l=c=>{s||(s=!0,a(c))};UC({forkId:t,apiKey:r.apiKey??null,title:r.title??null},{onAccepted:c=>{l({ok:!0,summary:`Cloud render started (${c}). The finished MP4 URL will appear in the next editor_context as last_export_url.`})},onDone:c=>{JM="ok",FYe=c,l({ok:!0,summary:c?`Render finished: ${c}`:"Render finished (no output URL returned)."})},onError:c=>{JM="error",z0e=c,l({ok:!1,error:c})}})}));case"fork_composition":{let a=Xe(o,"fork_from")==="default"?"default":"current",s;try{s=await fetch(`/api/v1/compositions/${encodeURIComponent(t)}/fork`,{method:"POST",credentials:"same-origin",headers:JQ({"content-type":"application/json"}),body:JSON.stringify({from:a})})}catch(f){return{ok:!1,error:`fork request failed: ${f instanceof Error?f.message:String(f)}`}}let l=await s.json().catch(()=>null);if(!s.ok||!l?.fork_id)return{ok:!1,error:l?.error??`fork failed (HTTP ${s.status})`};let c=l.template_id??window.location.pathname.split("/")[2]??"original",u=`/editor/${encodeURIComponent(c)}/fork/${encodeURIComponent(l.fork_id)}`;return setTimeout(()=>{window.location.assign(u)},400),{ok:!0,summary:`Forked (${a}) \u2192 ${l.fork_id}. Opening ${u}\u2026`}}default:return{ok:!1,error:`action "${n}" isn't available in this editor build yet`}}}async function zrr(t){let e=q.getState(),r={fork_id:t,selected_element_id:e.selectedElementId,playhead:e.currentTime??0,last_export_url:FYe,last_export_status:JM,last_export_error:z0e,recent_action_results:iZ.slice(),save_status:BYe?"ok":"error"};if(!t)return{...r,composition_id:null,duration:e.duration,layers:[],composition_context:null};let n=await Ib(t);if(!n?.content)return{...r,composition_id:null,duration:e.duration,layers:e.elements.map(p=>({element_id:p.id,label:p.label??null,start:p.start,duration:p.duration,track:p.track})),composition_context:null,snapshot_source:"player-store (composition read failed)"};let i=new DOMParser().parseFromString(n.content,"text/html"),o=Wv(i),a=Number(o?.getAttribute("data-width"))||0,s=Number(o?.getAttribute("data-height"))||0,l=null,c=o?.getAttribute("data-viral-dna")??i.body?.getAttribute("data-viral-dna");if(c)try{l=JSON.parse(c)}catch{}let u=U0e(i,Number(o?.getAttribute("data-duration"))||e.duration||0),f=RYe(i);return f.some(p=>p.status==="generating"||p.status==="submitting")&&Z0e(),{...r,composition_id:o?.getAttribute("data-composition-id")??i.body?.getAttribute("data-composition-id")??null,duration:u,canvas_width:a||null,canvas_height:s||null,composition_width:a||null,composition_height:s||null,aspect_ratio:LYe(a,s),layers:DYe(i),timeline_gaps:NYe(PYe(i),u),pending_generations:f,composition_context:l?{viral_dna:l}:null}}function UYe(t,e={}){oZ=t;let r={apply:async n=>{let i=n?.action_type??"",o=t(),a;if(!o)a={ok:!1,error:"no fork open"};else try{a=await jrr(o,n,e)}catch(s){a={ok:!1,error:s instanceof Error?s.message:String(s)}}return Brr({action_type:i||"(unknown)",ok:a.ok,...a.summary?{summary:a.summary}:{},...a.error?{error:a.error}:{}}),a},getCompositionHtml:async()=>{let n=t();return n?(await Ib(n))?.content??null:null},getSnapshot:()=>zrr(t()),placeMediaAtPlayhead:async n=>{let i=t();if(!i)return{ok:!1,error:"no fork open"};let o=n.src??n.url??n.path;if(!o)return{ok:!1,error:"no media src"};let a=q.getState().currentTime||0,s=L0e(o,n.contentType)??"image",l=s==="video"?await $Ye(o)??3:3,c=n.name??"Inserted media",u={kind:s,src:o,start:a,duration:l,label:c},f="";return await Uh(i,d=>g1(d,h=>{let m=Wv(h);if(!m)return!1;let g=YM(h,a,l,qM(h)+1),y=B0e(h,u,{kind:s,start:a,duration:l,track:g});if("error"in y)return!1;m.appendChild(y.el);let b=a+l,x=parseFloat(m.getAttribute("data-duration")??"0")||0;return b>x&&m.setAttribute("data-duration",jr(b)),f=`Placed ${s} at ${jr(a)}s on track ${g}.`,!0})??d)?{ok:!0,summary:f||"Placed media at playhead."}:{ok:!1,error:"couldn't save \u2014 composition read/write failed"}}};return window.__vidfarmEditorAction=r,()=>{window.__vidfarmEditorAction===r&&delete window.__vidfarmEditorAction,oZ===t&&(oZ=null,G0e())}}var rR=M(se(),1);nYe();function HYe(){if(typeof document>"u")return null;let t=document.getElementById("hf-boot");if(!t?.textContent)return null;try{return JSON.parse(t.textContent)}catch{return null}}function lZ(){if(typeof window>"u")return null;let t=window.location.pathname.match(/^\/editor\/[^/]+\/fork\/([^/]+)\/?$/);if(!t)return null;let e=decodeURIComponent(t[1]);return e==="new"?null:e}function VYe(){let t=lZ();if(!t)return;let e=`#project/${encodeURIComponent(t)}`;window.location.hash!==e&&window.history.replaceState(null,"",window.location.pathname+window.location.search+e)}function Grr(){let t="data-vidfarm-logo",e=()=>{let i=document.createElement("div");i.setAttribute(t,""),i.style.cssText="display:inline-flex;align-items:center;gap:8px;user-select:none;line-height:1";let o=document.createElement("span");o.style.cssText="display:inline-grid;place-items:center;width:24px;height:24px;border-radius:7px;background:#f5c518;color:#1c1608;font-weight:800;font-size:14px;font-family:var(--rk-font-display,system-ui,sans-serif)",o.textContent="V";let a=document.createElement("span");return a.style.cssText="font-weight:800;font-size:15px;letter-spacing:-.01em;color:#fffbe6;font-family:var(--rk-font-display,system-ui,sans-serif)",a.textContent="VidFarm",i.append(o,a),i},r=()=>{document.querySelectorAll('svg[aria-label="Hyperframes"]').forEach(o=>{o.previousElementSibling?.hasAttribute?.(t)||o.getAttribute("data-vidfarm-hidden")==="1"||(o.setAttribute("data-vidfarm-hidden","1"),o.style.display="none",o.parentElement?.insertBefore(e(),o))})};r();let n=new MutationObserver(r);return n.observe(document.body,{childList:!0,subtree:!0}),()=>n.disconnect()}function Qrr(t){if(t?.localRender!==!1)return()=>{};let e="data-vidfarm-cloud-render",r=o=>{let a=document.createElement("button");a.type="button",a.setAttribute(e,""),a.className=o.className,a.textContent="Render",a.title="Render this composition in the cloud (MP4)";let s=!1,l=null;return a.addEventListener("click",()=>{if(s)return;if(l){window.open(l,"_blank","noopener");return}let c=lZ();if(!c){a.textContent="No project yet",setTimeout(()=>{a.textContent="Render"},2e3);return}s=!0,a.disabled=!0,a.textContent="Rendering\u2026",UC({forkId:c,apiKey:t?.vidfarmApiKey??null,title:t?.title??null},{onProgress:u=>{a.textContent=u!=null?`Rendering\u2026 ${Math.round(u*100)}%`:"Rendering\u2026"},onDone:u=>{s=!1,a.disabled=!1,l=u,a.textContent=u?"Open MP4 \u2197":"Rendered",u&&window.open(u,"_blank","noopener"),setTimeout(()=>{a.textContent="Render",l=null},2e4)},onError:u=>{s=!1,a.disabled=!1,a.textContent="Render failed",a.title=u,setTimeout(()=>{a.textContent="Render",a.title="Render this composition in the cloud (MP4)"},4e3)}})}),a},n=()=>{document.querySelectorAll("button").forEach(a=>{a.hasAttribute(e)||a.getAttribute("data-vidfarm-hidden")==="1"||a.previousElementSibling?.hasAttribute?.(e)||(a.textContent||"").trim().toLowerCase()==="export"&&a.className.includes("studio-accent")&&(a.setAttribute("data-vidfarm-hidden","1"),a.style.display="none",a.parentElement?.insertBefore(r(a),a))})};n();let i=new MutationObserver(n);return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()}function jYe({boot:t}){let e=lZ();return aYe(t?.vidfarmApiKey??null),(0,sZ.useEffect)(()=>UYe(()=>lZ(),{apiKey:t?.vidfarmApiKey??null,title:t?.title??null}),[t]),(0,sZ.useEffect)(()=>Grr(),[]),(0,sZ.useEffect)(()=>Qrr(t),[t]),(0,rR.jsxs)("div",{className:"vidfarm-editor-root",style:{position:"fixed",inset:0},children:[(0,rR.jsx)(tYe,{}),(0,rR.jsx)(fYe,{boot:t,forkId:e})]})}var Xv=M(se(),1);VYe();J6e();c6("boot.entry-loaded");var W0e=document.getElementById("root");if(!W0e){l6("boot.root-missing");let t=new Error("Missing #root element");throw ZS(t),t}var VC=HYe();c6("boot.config-resolved",VC??{source:"none"});VC?.templateId&&yT.setTag("hyperframes.template_id",VC.templateId);VC?.compositionId&&yT.setTag("hyperframes.composition_id",VC.compositionId);function Zrr(){return(0,Xv.jsxs)("section",{style:{display:"grid",placeItems:"center",height:"100vh",padding:"24px",textAlign:"center",gap:"12px",color:"#fffbe6",background:"#050604"},children:[(0,Xv.jsx)("strong",{style:{fontSize:"0.72rem",letterSpacing:"0.14em",textTransform:"uppercase"},children:"Editor crashed"}),(0,Xv.jsx)("span",{style:{fontSize:"0.92rem",opacity:.75},children:"Something went wrong loading the editor. Reload the page to try again."})]})}try{c6("boot.render-start",{rootChildren:W0e.childNodes.length}),(0,zYe.createRoot)(W0e).render((0,Xv.jsx)(yT.ErrorBoundary,{fallback:(0,Xv.jsx)(Zrr,{}),onError:t=>l6("boot.render-error",t instanceof Error?t.stack:t),children:(0,Xv.jsx)(jYe,{boot:VC})})),c6("boot.render-called")}catch(t){throw l6("boot.render-error",t instanceof Error?t.stack:t),ZS(t),t}
887
887
  /*! Bundled license information:
888
888
 
889
889
  react/cjs/react.production.js:
@@ -705,7 +705,7 @@ function layerStyle(layer) {
705
705
  }
706
706
  if (["caption", "text", "shape", "html"].includes(layer.kind)) {
707
707
  const fontFamily = layer.fontFamily || "TikTok Sans";
708
- styles.push("display:flex", "align-items:center", "justify-content:center", "padding:3px", `font-family:${fontCssFamily(fontFamily)}, 'TikTok Sans', Montserrat, Abel, sans-serif`, `font-weight:${positiveInteger(layer.fontWeight, 700)}`, `line-height:${positiveNumber(layer.lineHeight, 1.18)}`, "text-align:center", "text-transform:none", `font-size:${positiveInteger(layer.fontSize, 32)}px`, `color:${layer.color || "#ffffff"}`, layer.kind === "shape" && layer.textBackgroundStyle === "panel"
708
+ styles.push("display:flex", "align-items:center", "justify-content:center", "padding:3px", `font-family:${fontCssFamily(fontFamily)}, 'TikTok Sans', Montserrat, Abel, sans-serif, 'Noto Color Emoji'`, `font-weight:${positiveInteger(layer.fontWeight, 700)}`, `line-height:${positiveNumber(layer.lineHeight, 1.18)}`, "text-align:center", "text-transform:none", `font-size:${positiveInteger(layer.fontSize, 32)}px`, `color:${layer.color || "#ffffff"}`, layer.kind === "shape" && layer.textBackgroundStyle === "panel"
709
709
  ? `background:${layer.background || "transparent"}`
710
710
  : "background:transparent");
711
711
  }
@@ -733,7 +733,7 @@ function textInlineCss(style, color, background, fontFamily, fontWeight) {
733
733
  else if (style === "highlight-translucent") {
734
734
  styles.push("padding:0.07em 0.46em 0.09em", "border-radius:0.32em", `background:${rgbaFromColor(background, 0.34)}`, "text-shadow:none", "-webkit-text-stroke:0 transparent");
735
735
  }
736
- styles.push(`font-family:${fontCssFamily(fontFamily)}, 'TikTok Sans', sans-serif`);
736
+ styles.push(`font-family:${fontCssFamily(fontFamily)}, 'TikTok Sans', sans-serif, 'Noto Color Emoji'`);
737
737
  styles.push(`font-weight:${fontWeight}`);
738
738
  styles.push(`color:${color}`);
739
739
  return styles.join(";");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@officexapp/vidfarm-devcli",
3
- "version": "0.21.14",
3
+ "version": "0.21.15",
4
4
  "description": "Local bridge for the Vidfarm Trackpad Editor. `vidfarm serve <template_id>` boots the FULL editor on localhost (disk-backed records/storage, free in-process render); edit composition.html on disk (Claude Code, Codex, etc.) and the browser live-morphs it.",
5
5
  "type": "module",
6
6
  "bin": {