@clickmax/studio-bridge 0.0.0 → 12.5.7

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.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/lib-DlEuZBGC.js","assets/rolldown-runtime-B0Z9INg1.js","assets/src-DDA8OuTJ.js","assets/__vite-browser-external-CV6URZNE.js","assets/domEditingLayers-KBTPQKGA-C_mwj3u9.js","assets/chunk-UYWON5AX-8myO-fst.js"])))=>i.map(i=>d[i]);
2
- import{a as e,i as t,n,r,t as i}from"./rolldown-runtime-B0Z9INg1.js";import{$ as a,$n as o,$t as s,A as c,An as l,At as u,B as d,Bn as f,Bt as p,C as m,Cn as h,Ct as g,D as _,Dn as v,Dt as y,E as b,En as x,Et as S,F as C,Fn as w,Ft as T,G as E,Gn as D,Gt as O,H as k,Hn as A,Ht as j,I as M,In as N,It as P,J as F,Jn as I,Jt as L,K as R,Kn as z,Kt as B,L as V,Ln as ee,Lt as te,M as H,Mn as ne,Mt as re,N as ie,Nn as ae,Nt as oe,O as se,On as ce,Ot as le,P as ue,Pn as de,Pt as fe,Q as pe,Qn as me,Qt as he,R as ge,Rn as _e,Rt as ve,S as ye,Sn as be,St as xe,T as Se,Tn as Ce,Tt as we,U as Te,Un as Ee,Ut as De,V as Oe,Vt as ke,W as Ae,Wn as je,Wt as Me,X as Ne,Xn as Pe,Xt as Fe,Y as Ie,Yn as Le,Yt as Re,Z as ze,Zn as Be,Zt as Ve,_ as He,_n as Ue,_t as We,a as Ge,an as Ke,at as qe,b as Je,bn as Ye,bt as Xe,c as Ze,cn as Qe,ct as $e,d as et,dn as tt,dt as nt,en as rt,er as it,et as at,f as ot,fn as st,ft as ct,g as lt,gn as ut,gt as dt,h as ft,hn as pt,ht as mt,i as ht,in as gt,it as _t,j as vt,jn as yt,jt as bt,k as xt,kn as St,kt as Ct,l as wt,ln as Tt,lt as Et,m as Dt,mn as Ot,mt as kt,n as At,nn as jt,nt as Mt,o as Nt,on as Pt,ot as Ft,pn as It,pt as Lt,q as Rt,qn as zt,qt as Bt,r as Vt,rn as Ht,rt as Ut,s as Wt,sn as Gt,st as Kt,t as qt,tn as Jt,tr as Yt,tt as Xt,u as Zt,un as Qt,ut as $t,v as en,vn as tn,vt as nn,w as rn,wn as an,wt as on,x as sn,xn as cn,xt as ln,y as un,yn as dn,yt as fn,z as pn,zn as mn,zt as hn}from"./chunk-UYWON5AX-8myO-fst.js";import{t as gn}from"./__vite-browser-external-CV6URZNE.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})(),window.__HF_CLI_TELEMETRY_DISABLED=!0;var _n=i((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.8`})),vn=i(((e,t)=>{t.exports=_n()})),U=e(vn()),yn=i((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),eee=i(((e,t)=>{t.exports=yn()})),bn=i((e=>{var t=vn();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.8`})),tee=i(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=bn()})),xn=i((e=>{var t=eee(),n=vn(),r=tee();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),m=Symbol.for(`react.transitional.element`),h=Symbol.for(`react.portal`),g=Symbol.for(`react.fragment`),_=Symbol.for(`react.strict_mode`),v=Symbol.for(`react.profiler`),y=Symbol.for(`react.consumer`),b=Symbol.for(`react.context`),x=Symbol.for(`react.forward_ref`),S=Symbol.for(`react.suspense`),C=Symbol.for(`react.suspense_list`),w=Symbol.for(`react.memo`),T=Symbol.for(`react.lazy`),E=Symbol.for(`react.activity`),D=Symbol.for(`react.memo_cache_sentinel`),O=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=O&&e[O]||e[`@@iterator`],typeof e==`function`?e:null)}var A=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===A?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case g:return`Fragment`;case v:return`Profiler`;case _:return`StrictMode`;case S:return`Suspense`;case C:return`SuspenseList`;case E:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case h:return`Portal`;case b:return e.displayName||`Context`;case y:return(e._context.displayName||`Context`)+`.Consumer`;case x:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case w:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case T:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var M=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},I=[],L=-1;function R(e){return{current:e}}function z(e){0>L||(e.current=I[L],I[L]=null,L--)}function B(e,t){L++,I[L]=e.current,e.current=t}var V=R(null),ee=R(null),te=R(null),H=R(null);function ne(e,t){switch(B(te,t),B(ee,e),B(V,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Cu(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Cu(t),e=wu(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}z(V),B(V,e)}function re(){z(V),z(ee),z(te)}function ie(e){e.memoizedState!==null&&B(H,e);var t=V.current,n=wu(t,e.type);t!==n&&(B(ee,e),B(V,n))}function ae(e){ee.current===e&&(z(V),z(ee)),H.current===e&&(z(H),vd._currentValue=F)}var oe,se;function ce(e){if(oe===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);oe=t&&t[1]||``,se=-1<e.stack.indexOf(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/lib-DlEuZBGC.js","assets/rolldown-runtime-B0Z9INg1.js","assets/src-DDA8OuTJ.js","assets/__vite-browser-external-CV6URZNE.js","assets/domEditingLayers-KBTPQKGA-tvsAmAbb.js","assets/chunk-UYWON5AX-NUuRHjnO.js"])))=>i.map(i=>d[i]);
2
+ import{a as e,i as t,n,r,t as i}from"./rolldown-runtime-B0Z9INg1.js";import{$ as a,$n as o,$t as s,A as c,An as l,At as u,B as d,Bn as f,Bt as p,C as m,Cn as h,Ct as g,D as _,Dn as v,Dt as y,E as b,En as x,Et as S,F as C,Fn as w,Ft as T,G as E,Gn as D,Gt as O,H as k,Hn as A,Ht as j,I as M,In as N,It as P,J as F,Jn as I,Jt as L,K as R,Kn as z,Kt as B,L as V,Ln as ee,Lt as te,M as H,Mn as ne,Mt as re,N as ie,Nn as ae,Nt as oe,O as se,On as ce,Ot as le,P as ue,Pn as de,Pt as fe,Q as pe,Qn as me,Qt as he,R as ge,Rn as _e,Rt as ve,S as ye,Sn as be,St as xe,T as Se,Tn as Ce,Tt as we,U as Te,Un as Ee,Ut as De,V as Oe,Vt as ke,W as Ae,Wn as je,Wt as Me,X as Ne,Xn as Pe,Xt as Fe,Y as Ie,Yn as Le,Yt as Re,Z as ze,Zn as Be,Zt as Ve,_ as He,_n as Ue,_t as We,a as Ge,an as Ke,at as qe,b as Je,bn as Ye,bt as Xe,c as Ze,cn as Qe,ct as $e,d as et,dn as tt,dt as nt,en as rt,er as it,et as at,f as ot,fn as st,ft as ct,g as lt,gn as ut,gt as dt,h as ft,hn as pt,ht as mt,i as ht,in as gt,it as _t,j as vt,jn as yt,jt as bt,k as xt,kn as St,kt as Ct,l as wt,ln as Tt,lt as Et,m as Dt,mn as Ot,mt as kt,n as At,nn as jt,nt as Mt,o as Nt,on as Pt,ot as Ft,pn as It,pt as Lt,q as Rt,qn as zt,qt as Bt,r as Vt,rn as Ht,rt as Ut,s as Wt,sn as Gt,st as Kt,t as qt,tn as Jt,tr as Yt,tt as Xt,u as Zt,un as Qt,ut as $t,v as en,vn as tn,vt as nn,w as rn,wn as an,wt as on,x as sn,xn as cn,xt as ln,y as un,yn as dn,yt as fn,z as pn,zn as mn,zt as hn}from"./chunk-UYWON5AX-NUuRHjnO.js";import{t as gn}from"./__vite-browser-external-CV6URZNE.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})(),window.__HF_CLI_TELEMETRY_DISABLED=!0;var _n=i((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.iterator;function m(e){return typeof e!=`object`||!e?null:(e=p&&e[p]||e[`@@iterator`],typeof e==`function`?e:null)}var h={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},g=Object.assign,_={};function v(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}v.prototype.isReactComponent={},v.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},v.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function y(){}y.prototype=v.prototype;function b(e,t,n){this.props=e,this.context=t,this.refs=_,this.updater=n||h}var x=b.prototype=new y;x.constructor=b,g(x,v.prototype),x.isPureReactComponent=!0;var S=Array.isArray;function C(){}var w={H:null,A:null,T:null,S:null},T=Object.prototype.hasOwnProperty;function E(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function D(e,t){return E(e.type,t,e.props)}function O(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function k(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var A=/\/+/g;function j(e,t){return typeof e==`object`&&e&&e.key!=null?k(``+e.key):t.toString(36)}function M(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(C,C):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function N(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,N(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+j(e,0):a,S(o)?(i=``,c!=null&&(i=c.replace(A,`$&/`)+`/`),N(o,r,i,``,function(e){return e})):o!=null&&(O(o)&&(o=D(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(A,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(S(e))for(var u=0;u<e.length;u++)a=e[u],s=l+j(a,u),c+=N(a,r,i,s,o);else if(u=m(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+j(a,u++),c+=N(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return N(M(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function P(e,t,n){if(e==null)return e;var r=[],i=0;return N(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function F(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var I=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)},L={map:P,forEach:function(e,t,n){P(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return P(e,function(){t++}),t},toArray:function(e){return P(e,function(e){return e})||[]},only:function(e){if(!O(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=L,e.Component=v,e.Fragment=r,e.Profiler=a,e.PureComponent=b,e.StrictMode=i,e.Suspense=l,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=w,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return w.H.useMemoCache(e)}},e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=g({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!T.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return E(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)T.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return E(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=O,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:F}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=function(e){var t=w.T,n={};w.T=n;try{var r=e(),i=w.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(C,I)}catch(e){I(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),w.T=t}},e.unstable_useCacheRefresh=function(){return w.H.useCacheRefresh()},e.use=function(e){return w.H.use(e)},e.useActionState=function(e,t,n){return w.H.useActionState(e,t,n)},e.useCallback=function(e,t){return w.H.useCallback(e,t)},e.useContext=function(e){return w.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return w.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return w.H.useEffect(e,t)},e.useEffectEvent=function(e){return w.H.useEffectEvent(e)},e.useId=function(){return w.H.useId()},e.useImperativeHandle=function(e,t,n){return w.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return w.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return w.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return w.H.useMemo(e,t)},e.useOptimistic=function(e,t){return w.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return w.H.useReducer(e,t,n)},e.useRef=function(e){return w.H.useRef(e)},e.useState=function(e){return w.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return w.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return w.H.useTransition()},e.version=`19.2.8`})),vn=i(((e,t)=>{t.exports=_n()})),U=e(vn()),yn=i((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m)if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&j(x,t.startTime-e)}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&j(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var k=new MessageChannel,A=k.port2;k.port1.onmessage=D,O=function(){A.postMessage(null)}}else O=function(){_(D,0)};function j(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,j(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),eee=i(((e,t)=>{t.exports=yn()})),bn=i((e=>{var t=vn();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`);function o(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var s=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function c(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return o(e,t,null,r)},e.flushSync=function(e){var t=s.T,n=i.p;try{if(s.T=null,i.p=2,e)return e()}finally{s.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=c(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??i.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=c(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=c(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else i.d.m(e)},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return s.H.useFormState(e,t,n)},e.useFormStatus=function(){return s.H.useHostTransitionStatus()},e.version=`19.2.8`})),tee=i(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=bn()})),xn=i((e=>{var t=eee(),n=vn(),r=tee();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function d(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=d(e),t!==null)return t;e=e.sibling}return null}var f=Object.assign,p=Symbol.for(`react.element`),m=Symbol.for(`react.transitional.element`),h=Symbol.for(`react.portal`),g=Symbol.for(`react.fragment`),_=Symbol.for(`react.strict_mode`),v=Symbol.for(`react.profiler`),y=Symbol.for(`react.consumer`),b=Symbol.for(`react.context`),x=Symbol.for(`react.forward_ref`),S=Symbol.for(`react.suspense`),C=Symbol.for(`react.suspense_list`),w=Symbol.for(`react.memo`),T=Symbol.for(`react.lazy`),E=Symbol.for(`react.activity`),D=Symbol.for(`react.memo_cache_sentinel`),O=Symbol.iterator;function k(e){return typeof e!=`object`||!e?null:(e=O&&e[O]||e[`@@iterator`],typeof e==`function`?e:null)}var A=Symbol.for(`react.client.reference`);function j(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===A?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case g:return`Fragment`;case v:return`Profiler`;case _:return`StrictMode`;case S:return`Suspense`;case C:return`SuspenseList`;case E:return`Activity`}if(typeof e==`object`)switch(e.$$typeof){case h:return`Portal`;case b:return e.displayName||`Context`;case y:return(e._context.displayName||`Context`)+`.Consumer`;case x:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case w:return t=e.displayName||null,t===null?j(e.type)||`Memo`:t;case T:t=e._payload,e=e._init;try{return j(e(t))}catch{}}return null}var M=Array.isArray,N=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,F={pending:!1,data:null,method:null,action:null},I=[],L=-1;function R(e){return{current:e}}function z(e){0>L||(e.current=I[L],I[L]=null,L--)}function B(e,t){L++,I[L]=e.current,e.current=t}var V=R(null),ee=R(null),te=R(null),H=R(null);function ne(e,t){switch(B(te,t),B(ee,e),B(V,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?Cu(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=Cu(t),e=wu(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}z(V),B(V,e)}function re(){z(V),z(ee),z(te)}function ie(e){e.memoizedState!==null&&B(H,e);var t=V.current,n=wu(t,e.type);t!==n&&(B(ee,e),B(V,n))}function ae(e){ee.current===e&&(z(V),z(ee)),H.current===e&&(z(H),vd._currentValue=F)}var oe,se;function ce(e){if(oe===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);oe=t&&t[1]||``,se=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+oe+e+se}var le=!1;function ue(e,t){if(!e||le)return``;le=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}e.call(n.prototype)}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
5
5
  `),l=s.split(`
@@ -329,7 +329,7 @@ ${a}${o}${e.slice(r)}`}var mq=`application/x-hyperframes-composition`;function O
329
329
  `,r.start)+1,a=/^[ \t]*$/.test(e.slice(i,r.start))?e.slice(i,r.start):``,o=a?`
330
330
  ${a}`:``;return`${e.slice(0,r.start)}${n}${o}${e.slice(r.start)}`}function n8t(e){let{video:t,target:n}=e,r=Z6t(t.ownerDocument),i=!1,a=[],o=n1(`src`,e.cutoutSrc),c=[n1(`muted`,`true`),r1(`has-audio`,null)];for(let e of t1){let n=t.getAttribute(e);n!==null&&(a.push([e,n]),c.push(r1(i1(e),null)))}let l=t.getAttribute(s);if(l!==null){let{videoKeeps:e,audioTakes:t}=$6t(l);a.push([s,t]),c.push(r1(i1(s),e))}return c.push(r1(i1(ZC),r),r1(i1(tw),r)),{ops:c,prepareContent:s=>{let c=a1(s,n),l=X6t(`${e.videoId||`video`}-audio`,new Set(t$(s))),u=[];for(let e of G6t){let t=OZ(s,n,e);t!==void 0&&u.push([`data-${e}`,t])}let d=[[`id`,l],[`data-hf-id`,`hf-${nG()}`],[`class`,`clip`],[`src`,c],...u,[`data-track-index`,String(Q6t(s))],[ZC,r],[tw,r],...a];t.hasAttribute(`loop`)&&d.push([`loop`,``]),t.hasAttribute(`data-hidden`)&&d.push([`data-hidden`,``]);let f=AZ(s,n,o),p=t8t(f,n,`<audio ${e8t(d)}></audio>`);return i=p!==f,p},audioInserted:()=>i}}var r8t=e=>e.tagName===`video`;async function i8t(e,t){let n=r8t(e.element),r=n&&!t&&e.projectId&&e.projectSrc?await m2t(e.projectId,e.projectSrc):null;await e.commit(e.element,q6t({isVideo:n,nextMuted:t,probedHasAudio:r}),{label:`Edit muted`})}async function a8t(e,t){await e.commit(e.element,J6t(t),{label:`Edit has audio`})}async function o8t(e,t,n){let r=r8t(e.element),i=`Remove background`;if(!(r&&n)){if(!await e.commit(e.element,Y6t({isVideo:r,cutoutSrc:t}),{label:i}))throw Error(`Couldn't apply the cutout`);return`Applied cutout`}let{landed:a,soundKept:o}=await s8t(e,t,i);if(!a)throw Error(`Couldn't apply the cutout`);if(!o)throw Error(W6t);return U6t}async function s8t(e,t,n){let r=n8t({video:e.element.element,videoId:e.element.id??null,target:Wt(e.element),cutoutSrc:t}),i=await e.commit(e.element,r.ops,{label:n,prepareContent:r.prepareContent});return{landed:i,soundKept:i&&r.audioInserted()}}var o1=ZC.slice(5),s1=`data-hidden`,c1=tw.slice(5),c8t=.001,l1=(e,t)=>({type:`attribute`,property:e.startsWith(`data-`)?e.slice(5):e,value:t}),l8t=(e,t)=>({type:`html-attribute`,property:e,value:t});function u1(e,t,n){return n.reduce((e,n)=>AZ(e,t,n),e)}function u8t(e){let t=Array.from(e.matchAll(/\bdata-(?:link|sync-origin)=["']([^"']+)["']/g),e=>e[1]??``);return MRe([...t$(e),...t])}function d8t(e,t,n){return t.reduce((e,t)=>AZ(e,t,l1(o1,n)),e)}function f8t(e,t,n={syncOrigin:!0}){let r=u8t(e),i=n.syncOrigin?[l1(o1,r),l1(c1,r)]:[l1(o1,r)];return t.reduce((e,t)=>u1(e,t,i),e)}function p8t(e,t){let n=DZ(e,t);if(!n)return e;let r=`</${/^<([a-zA-Z][\w-]*)/.exec(n.tag)?.[1]?.toLowerCase()??``}>`,i=n.tag.endsWith(`/>`)?-1:e.toLowerCase().indexOf(r,n.end+1),a=i>=0?i+r.length:n.end+1,o=n.start,s=e.lastIndexOf(`
331
331
  `,o)+1;return/^[ \t]*$/.test(e.slice(s,o))&&e[a]===`
332
- `&&(o=s,a+=1),e.slice(0,o)+e.slice(a)}function d1(e,t,n){let r=DZ(e,t)?.tag??``;return RegExp(`\\s${n}(?=[\\s=/>]|$)`,`i`).test(r)}function m8t(e,t){let{target:n}=t;if(!DZ(e,n))return null;let r=u8t(e),i=X6t(`${t.videoId||`video`}-audio`,new Set(t$(e))),a=[],o=[l8t(`muted`,`true`),l1(`has-audio`,null)];for(let t of t1){let r=OZ(e,n,t);r!==void 0&&(a.push([t,r]),o.push(l1(t,null)))}let c=OZ(e,n,s);if(c!==void 0){let{videoKeeps:e,audioTakes:t}=$6t(c);a.push([s,t]),o.push(l1(s,e))}o.push(l1(o1,r),l1(c1,r));let l=[];for(let t of G6t){let r=OZ(e,n,t);r!==void 0&&l.push([`data-${t}`,r])}let u=[[`id`,i],[`data-hf-id`,`hf-${nG()}`],[`class`,`clip`],[`src`,a1(e,n)],...l,[`data-track-index`,String(t.track)],[ZC,r],[tw,r],...a];return d1(e,n,`loop`)&&u.push([`loop`,``]),d1(e,n,s1)&&u.push([s1,``]),{html:u1(t8t(e,n,`<audio ${e8t(u)}></audio>`),n,o),audioId:i,linkId:r}}function h8t(e,t){let{videoTarget:n,audioTarget:r}=t;if(!DZ(e,n)||!DZ(e,r))return null;let i=t=>Eq({src:a1(e,t)}),a=i(n);if(!a||a!==i(r))return null;let o=t=>d1(e,t,s1);if(o(n)!==o(r))return null;let c=[];for(let t of t1){let n=OZ(e,r,t);c.push(l1(t,n??null))}let l=OZ(e,r,s);return l!==void 0&&c.push(l1(s,l)),c.push(l8t(`muted`,null),l1(o1,null),l1(c1,null),l1(`has-audio`,`true`)),u1(p8t(e,r),n,c)}var f1=e=>e.tag.trim().toLowerCase(),g8t=e=>e.key??e.id,p1=(e,t)=>Math.abs(e-t)<=c8t;function _8t(e,t){return p1(e.start,t.start)&&p1(e.duration,t.duration)&&p1(e.playbackStart??0,t.playbackStart??0)&&p1(e.playbackRate??1,t.playbackRate??1)}var v8t=(e,t)=>{let n=Eq(e);return n!==null&&n===Eq(t)&&zK(e,t)};function y8t(e){return f1(e)===`video`&&e.muted!==!0&&e.hasAudio===!0}function b8t(e,t){let n=f1(e)===`video`;if(!n&&f1(e)!==`audio`)return null;let r=n?`audio`:`video`,i=t.filter(t=>g8t(t)!==g8t(e)&&f1(t)===r&&v8t(t,e)),a=i.find(t=>Oq(t,e))??i.find(t=>_8t(t,e));if(!a)return null;let o=n?e:a,s=n?a:e;return o.hidden===!0==(s.hidden===!0)&&o.muted===!0?{video:o,audio:s}:null}function x8t(e){if(e.length!==2)return!1;let[t,n]=e;if(!t||!n||t.link||n.link)return!1;let r=new Set([f1(t),f1(n)]);return r.has(`video`)&&r.has(`audio`)&&zK(t,n)}function S8t(e){let[t,n]=e;return e.length===2&&!!t&&!!n&&v8t(t,n)}function C8t(e,t){let n=e=>({start:e.start,mediaStart:e.playbackStart??0,playbackRate:e.playbackRate??1}),[r,i]=[n(e),n(t)];return p1(r.playbackRate,i.playbackRate)&&p1(rw(r),rw(i))}function w8t(e,t){let n=e=>e.authoredTrack??e.track,r=e.filter(e=>f1(e)!==`audio`).map(n),i=Math.max(-1,...r)+1,a=t.start+t.duration,o=e.map(n),s=Math.max(i-1,...o)+1;for(let r=i;r<s;r+=1)if(e.filter(e=>n(e)===r).every(e=>f1(e)===`audio`&&(e.start>=a||e.start+e.duration<=t.start)))return r;return s}var m1=e=>e.key??e.id,h1=e=>e.tag.trim().toLowerCase();function T8t(e,t){let n={video:`audio`,audio:`video`}[h1(e)];if(!n||e.link)return null;let r=t.filter(t=>!t.link&&h1(t)===n&&t.track!==e.track&&S8t([e,t]));return r.length===1?r[0]??null:null}function g1(e,t){let n=t.filter(t=>m1(t)!==m1(e)),[r]=n;return n.length!==1||!r?``:[h1(e),h1(r)].sort().join(`+`)===`audio+video`?` ${h1(r)}`:``}function E8t(e,t,n,r,i){let a=x8t(n)&&r.has(m1(e)),o=n.every(t=>m1(t)===m1(e)),s=!a&&o?T8t(e,t):null,c=a?n:s?[e,s]:null;if(!c)return null;let l=g1(e,c);return{label:`Link${l&&` to${l}`}`,...a?{shortcut:`⌘L`}:{},run:()=>i({kind:`link`,elements:c})}}function D8t(e){let{element:t,elements:n,selectedKeys:r,onLinkEdit:i,onDeleteElementOnly:a}=e,o=[];if(!i)return o;let s=kq(t,n),c=s.length>1;y8t(t)&&o.push({label:`Detach audio`,shortcut:`⌥⇧D`,run:()=>i({kind:`detach`,element:t})});let l=n.filter(e=>r.has(m1(e)));if(c)o.push({label:`Unlink${g1(t,s)&&` from${g1(t,s)}`}`,shortcut:`⌘L`,run:()=>i({kind:`unlink`,elements:s})});else{let e=E8t(t,n,l,r,i);e&&o.push(e)}let u=b8t(t,n);return u&&o.push({label:`Merge audio back into video`,disabledReason:C8t(u.video,u.audio)?void 0:`Move into Sync first`,run:()=>i({kind:`merge`,...u})}),c&&a&&o.push({label:`Delete this clip only`,shortcut:`⌥⌫`,destructive:!0,run:()=>a(t)}),o}function O8t({part:e,element:t,onClose:n}){let{onLinkEdit:r,onDeleteElementOnly:i}=VX(),a=D8t({element:t,elements:X(e=>e.elements),selectedKeys:X(e=>e.selectedElementIds),onLinkEdit:r,onDeleteElementOnly:i}).filter(t=>t.destructive===!0==(e===`delete`));return a.length===0?null:(0,W.jsx)(W.Fragment,{children:a.map(e=>(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,disabled:e.disabledReason!==void 0,title:e.disabledReason,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-left outline-hidden ${e.disabledReason===void 0?`cursor-pointer hover:bg-neutral-800 focus-visible:bg-neutral-800 ${e.destructive?`text-red-400`:`text-neutral-300`}`:`text-neutral-600 cursor-not-allowed`}`,onClick:()=>{e.run(),n()},children:[(0,W.jsx)(`span`,{children:e.label}),e.shortcut&&(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:e.shortcut})]},e.label))})}var k8t=8;function A8t(e,t){let[n,r]=(0,U.useState)(0);return(0,U.useLayoutEffect)(()=>{let t=e.current;if(!t||(r(t.offsetHeight),typeof ResizeObserver>`u`))return;let n=new ResizeObserver(()=>r(t.offsetHeight));return n.observe(t),()=>n.disconnect()},[e,t]),n}var _1=e=>`${wQ.row} flex items-center justify-between ${e?wQ.rowEnabled:wQ.rowDisabled}`;function j8t({items:e,onClose:t}){return(0,W.jsx)(W.Fragment,{children:e.map(e=>(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!e.disabled),disabled:e.disabled,onClick:()=>{t(),e.onSelect()},children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.icon,e.label]}),e.shortcut&&(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:e.shortcut})]},e.id))})}var M8t=(0,U.memo)(function({x:e,y:t,element:n,currentTime:r,onClose:i,onSplit:a,onDelete:o,onCopy:s,onPaste:c,onDuplicate:l,canPaste:u,hostItems:d=[],splitShortcut:f=SG}){let p=yG(i);CQ(p);let m=VX().clipMenuTools!==!1,h=X(e=>{let t=n.key??n.id;return e.selectedElementIds.size>1&&e.selectedElementIds.has(t)?e.selectedElementIds.size:1}),g=kQ(n)&&[`video`,`audio`,`img`].includes(n.tag),_=g&&r>n.start&&r<n.start+n.duration,v=g?_?`Split at ${r.toFixed(2)}s`:`Split (move playhead inside clip)`:null,y=e+200>window.innerWidth?e-200:e,b=t+A8t(p,`${e},${t},${n.key??n.id}`)-window.innerHeight,x=b>0?Math.max(k8t,t-b-k8t):t;return(0,pm.createPortal)((0,W.jsxs)(`div`,{ref:p,role:`menu`,"aria-label":`Clip actions`,className:`${wQ.panel} fixed z-200 min-w-[180px]`,style:{left:y,top:x},children:[d.length>0&&(0,W.jsx)(`div`,{role:`group`,"aria-label":`Host`,className:wQ.group,children:(0,W.jsx)(j8t,{items:d,onClose:i})}),(0,W.jsxs)(`div`,{role:`group`,"aria-label":`Time`,className:wQ.group,children:[v&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-left outline-hidden focus-visible:bg-neutral-800 ${_?`text-neutral-300 hover:bg-neutral-800 cursor-pointer`:`text-neutral-600 cursor-not-allowed`}`,disabled:!_,onClick:()=>{_&&(a(n,r),i())},children:[(0,W.jsx)(`span`,{children:v}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:f})]}),m&&v&&(0,W.jsx)(K$,{group:`time`,element:n,currentTime:r,onClose:i})]}),(0,W.jsx)(`div`,{role:`group`,"aria-label":`Sound`,className:wQ.group,children:m&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(j6t,{part:`gain`,element:n,onClose:i}),(0,W.jsx)(K$,{group:`sound`,element:n,currentTime:r,onClose:i}),(0,W.jsx)(O8t,{part:`link`,element:n,onClose:i}),(0,W.jsx)(j6t,{part:`duck`,element:n,onClose:i})]})}),(0,W.jsx)(`div`,{role:`group`,"aria-label":`Picture`,className:wQ.group,children:m&&(0,W.jsx)(K$,{group:`picture`,element:n,currentTime:r,onClose:i})}),(0,W.jsxs)(`div`,{role:`group`,"aria-label":`Clipboard`,className:wQ.group,children:[s&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!0),onClick:()=>{s(),i()},children:[(0,W.jsx)(`span`,{children:h>1?`Copy ${h} clips`:`Copy`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌘C`})]}),c&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!!u),disabled:!u,onClick:()=>{u&&(c(),i())},children:[(0,W.jsx)(`span`,{children:`Paste`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌘V`})]}),l&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!0),onClick:()=>{l(),i()},children:[(0,W.jsx)(`span`,{children:h>1?`Duplicate ${h} clips`:`Duplicate`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌘D`})]})]}),(0,W.jsxs)(`div`,{role:`group`,"aria-label":`Delete`,children:[(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-danger-ink hover:bg-neutral-800 focus-visible:bg-neutral-800 outline-hidden cursor-pointer text-left`,onClick:()=>{o(n),i()},children:[(0,W.jsx)(`span`,{children:`Delete`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌫`})]}),m&&(0,W.jsx)(O8t,{part:`delete`,element:n,onClose:i})]})]}),document.body)}),N8t=(0,U.memo)(function({x:e,y:t,gapWidth:n,canCloseGap:r,canCloseAllGaps:i,hasAnyGaps:a,onClose:o,onCloseGap:s,onCloseAllGaps:c,onHoverAction:l}){let u=yG(o),d=t+68-window.innerHeight,f=e+200>window.innerWidth?e-200:e,p=d>0?t-d-8:t,m=e=>`${wQ.row} flex items-center justify-between ${e?wQ.rowEnabled:wQ.rowDisabled}`,h=r?void 0:n==null?`No gap here`:`A clip on this track can't be moved`,g=i?void 0:a?`A clip on this track can't be moved`:`No gaps on this track`;return(0,pm.createPortal)((0,W.jsxs)(`div`,{ref:u,className:`${wQ.panel} fixed z-200 min-w-[180px]`,style:{left:f,top:p},onPointerLeave:()=>l(null),children:[(0,W.jsxs)(`button`,{type:`button`,className:m(r),disabled:!r,title:h,onPointerEnter:()=>l(r?`close-gap`:null),onClick:()=>{r&&(s(),o())},children:[(0,W.jsx)(`span`,{children:`Close gap`}),n!=null&&(0,W.jsxs)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:[n.toFixed(2),`s`]})]}),(0,W.jsx)(`button`,{type:`button`,className:m(i),disabled:!i,title:g,onPointerEnter:()=>l(i?`close-all`:null),onClick:()=>{i&&(c(),o())},children:(0,W.jsx)(`span`,{children:`Close all gaps`})})]}),document.body)});function P8t({theme:e}){return(0,W.jsx)(`div`,{className:`absolute bottom-2 right-3 pointer-events-none z-20`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-md border`,style:{background:`var(--timeline-shortcut-bg)`,borderColor:e.gutterBorder},children:[(0,W.jsx)(`kbd`,{className:`text-[9px] font-mono px-1 py-0.5 rounded-sm`,style:{color:e.textSecondary,background:`var(--timeline-tick-minor)`},children:`Shift`}),(0,W.jsx)(`span`,{className:`text-[9px]`,style:{color:e.textSecondary},children:`+ drag/click to edit range`})]})})}function v1({capturedElement:e,targetSessionEpoch:t,sessionEpoch:n,selectedElementId:r,elements:i}){let a=e.key??e.id;return t!==n||r!==a?null:i.find(e=>(e.key??e.id)===a)??null}function F8t(){let{state:e}=UX(),{showShortcutHint:t,showPopover:n,rangeSelection:r,theme:i}=e.overlays;return!t||n||r?null:(0,W.jsx)(P8t,{theme:i})}function I8t(){let{state:e}=UX(),{showPopover:t,rangeSelection:n,setShowPopover:r,setRangeSelection:i}=e.overlays;return!t||!n?null:(0,W.jsx)($3t,{rangeStart:n.start,rangeEnd:n.end,anchorX:n.anchorX,anchorY:n.anchorY,onClose:()=>{r(!1),i(null)}})}function L8t(){let{state:e,actions:t}=UX(),n=e.overlays,{kfContextMenu:r,setKfContextMenu:i}=n,{selectedElementId:a,sessionEpoch:o,keyframeCache:s}=e,c=r?.sessionEpoch,l=r?v1({capturedElement:r.element,targetSessionEpoch:c,sessionEpoch:o,selectedElementId:a,elements:n.elements}):null;if((0,U.useEffect)(()=>{r&&!l&&i(null)},[l,r,i]),!r||!l)return null;let u=()=>v1({capturedElement:l,targetSessionEpoch:c,sessionEpoch:o,selectedElementId:a,elements:n.elementsRef.current}),d=r;return(0,W.jsx)(t6t,{state:{...d,element:l},onClose:()=>i(null),onDelete:(...e)=>{u()&&n.onDeleteKeyframe?.(...e)},onDeleteAll:(e,t)=>{let r=u();r&&n.onDeleteAllKeyframes?.(r,t)},onMoveToPlayhead:n.onMoveKeyframeToPlayhead?(e,...t)=>{let r=u();r&&n.onMoveKeyframeToPlayhead?.(r,...t)}:void 0,onEditEase:d.animationId!==void 0&&d.tweenPercentage!==void 0?(e,n)=>{n.animationId!==void 0&&n.tweenPercentage!==void 0&&(t.setFocusedEaseSegment({animationId:n.animationId,collidingAnimationTargets:n.collidingAnimationTargets,tweenPercentage:n.tweenPercentage,elementId:e}),_Y({action:`open`}))}:void 0,onCopyProperties:(e,t)=>{let n=s.get(e)?.keyframes.find(e=>Math.abs(e.percentage-t.percentage)<.5);return n?U$(JSON.stringify(n.properties,null,2)):!1}})}function R8t(){let{state:e}=UX(),t=e.overlays,{clipContextMenu:n,setClipContextMenu:r}=t,{selectedElementId:i,sessionEpoch:a}=e,o=n?.sessionEpoch,s=n?v1({capturedElement:n.element,targetSessionEpoch:o,sessionEpoch:a,selectedElementId:i,elements:t.elements}):null;(0,U.useEffect)(()=>{n&&!s&&r(null)},[s,n,r]);let{clipMenuItems:c}=t,l=(0,U.useMemo)(()=>s?c?.(s):void 0,[c,s]);if(!n||!s)return null;let u=()=>v1({capturedElement:s,targetSessionEpoch:o,sessionEpoch:a,selectedElementId:i,elements:t.elementsRef.current}),d=n;return(0,W.jsx)(M8t,{x:d.x,y:d.y,element:s,currentTime:t.currentTime,onClose:()=>r(null),onSplit:(e,n)=>{let r=u();r&&t.onSplitElement?.(r,n)},onDelete:()=>{let e=u();e&&(t.pinZoomBeforeEdit(),t.onDeleteElement?.(e))},onCopy:t.onCopyClip,onPaste:t.onPasteClip,onDuplicate:t.onDuplicateClip,canPaste:t.canPasteClip?.()??!1,hostItems:l,splitShortcut:t.splitShortcut})}function z8t(){let{state:e}=UX(),t=e.overlays.gapContextMenu,n=e.overlays;return t?(0,W.jsx)(N8t,{x:t.x,y:t.y,gapWidth:t.gapWidth,canCloseGap:t.canCloseGap,canCloseAllGaps:t.canCloseAllGaps,hasAnyGaps:t.hasAnyGaps,onClose:n.onDismissGapContextMenu,onCloseGap:n.onCloseTrackGap,onCloseAllGaps:n.onCloseAllTrackGaps,onHoverAction:n.onHoverGapAction}):null}function B8t(){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(F8t,{}),(0,W.jsx)(I8t,{}),(0,W.jsx)(L8t,{}),(0,W.jsx)(R8t,{}),(0,W.jsx)(z8t,{}),(0,W.jsx)(q3t,{})]})}function V8t({isDragOver:e,onFileDrop:t,onDragOver:n,onDragLeave:r,onDrop:i}){return(0,W.jsxs)(`div`,{className:`h-full border-t bg-[var(--timeline-shell-bg)] flex flex-col select-none transition-colors duration-150 ${e?`border-studio-accent/50 bg-studio-accent/3`:`border-neutral-800/50`}`,onDragOver:n,onDragLeave:r,onDrop:i,children:[(0,W.jsx)(`div`,{className:`shrink-0 border-b border-neutral-800/40 flex items-end relative`,style:{height:JG,paddingLeft:GG},children:[0,10,20,30,40,50].map(e=>(0,W.jsxs)(`div`,{className:`flex flex-col items-center`,style:{position:`absolute`,left:GG+e*14},children:[(0,W.jsx)(`span`,{className:`text-[9px] text-neutral-600 font-mono tabular-nums leading-none mb-0.5`,children:`${Math.floor(e/60).toString().padStart(2,`0`)}:${(e%60).toString().padStart(2,`0`)}`}),(0,W.jsx)(`div`,{className:`w-px h-[5px] bg-neutral-700/40`})]},e))}),(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,W.jsx)(`div`,{className:`flex items-center gap-3 px-6 py-3 border border-dashed rounded-lg transition-colors duration-150 ${e?`border-studio-accent/60 bg-studio-accent/6`:`border-neutral-700/50`}`,children:e?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`text-accent-ink shrink-0`,children:[(0,W.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,W.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,W.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]}),(0,W.jsx)(`span`,{className:`text-[13px] text-accent-ink`,children:`Drop media files to import`})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`text-neutral-600 shrink-0`,children:[(0,W.jsx)(`rect`,{x:`2`,y:`2`,width:`20`,height:`20`,rx:`2`}),(0,W.jsx)(`path`,{d:`M7 2v20`}),(0,W.jsx)(`path`,{d:`M17 2v20`}),(0,W.jsx)(`path`,{d:`M2 7h20`}),(0,W.jsx)(`path`,{d:`M2 17h20`})]}),(0,W.jsx)(`span`,{className:`text-[13px] text-neutral-500`,children:t?`Drop media here or describe your video to start`:`Describe your video to start creating`})]})})})]})}function H8t(){return(0,W.jsx)(d3t,{})}var U8t=QYt;function W8t(){let{state:e,actions:t}=UX(),n=e.canvas;return(0,W.jsx)(c3t,{...n,renderClipContent:t.renderClipContent,renderClipOverlay:t.renderClipOverlay})}function G8t(){let{state:e}=UX(),t=e.canvas;return(0,W.jsx)(eXt,{scrubbing:t.isScrubbing})}function K8t(){let{meta:e}=UX();return e.razorGuide}function q8t(){let{meta:e}=UX();return(0,W.jsx)(V8t,{...e.emptyState})}function J8t(){return(0,W.jsx)(F8t,{})}function Y8t(){return(0,W.jsx)(I8t,{})}function X8t(){return(0,W.jsx)(R8t,{})}function Z8t(){return(0,W.jsx)(L8t,{})}function Q8t(){return(0,W.jsx)(z8t,{})}function $8t(){let{state:e,meta:t}=UX(),{timelineReady:n,elements:r}=e;return!n||r.length===0?(0,W.jsx)(q8t,{}):(0,W.jsxs)(`div`,{...t.containerProps,children:[(0,W.jsxs)(`div`,{...t.viewportProps,children:[(0,W.jsx)(H8t,{}),(0,W.jsx)(K8t,{})]}),(0,W.jsx)(B8t,{})]})}var e5t=(0,U.memo)(function(e={}){return(0,W.jsx)(GYt,{...e,children:(0,W.jsx)($8t,{})})}),t5t=Object.assign(e5t,{Provider:GYt,Frame:H8t,Ruler:U8t,Lanes:W8t,Playhead:G8t,RazorGuide:K8t,ShortcutHint:J8t,EditPopover:Y8t,ClipMenu:X8t,KeyframeMenu:Z8t,GapMenu:Q8t,EmptyState:q8t,Overlays:B8t}),n5t=.001;function r5t(e,t,n){let r=Math.max(0,Number.isFinite(e)?e:0),i=Math.max(0,Number.isFinite(t)?t:0),a=Math.max(1,Number.isFinite(n)?Math.floor(n):1);return a===1?[r+i/2]:[...Array.from({length:a},(e,t)=>r+i*t/a),r+Math.max(0,i-n5t)]}var y1=new Map,i5t=new Map,a5t=(e,t,n)=>n>=e.sourceStart&&t-n<=(t>=e.end?0:e.lead);function o5t(e,t,n){let r=y1.get(e)?.find(e=>a5t(n,t,e.decodedAt));return r&&(r.users+=1),r}function s5t(e,t,n){let r=y1.get(e)??[],i=r.find(e=>e.decodedAt===t);if(i)return i.users+=1,URL.revokeObjectURL(n),i;let a={url:n,decodedAt:t,users:1};return y1.set(e,[...r,a]),a}function c5t(e){for(let{key:t,frame:n}of e.splice(0)){if(--n.users>0)continue;let e=y1.get(t)?.filter(e=>e!==n)??[];e.length>0?y1.set(t,e):y1.delete(t),URL.revokeObjectURL(n.url)}}async function l5t(e){return e instanceof HTMLCanvasElement?new Promise((t,n)=>{e.toBlob(e=>e?t(e):n(Error(`Video thumbnail encode failed`)),`image/jpeg`,.72)}):e.convertToBlob({type:`image/jpeg`,quality:.72})}function b1(e){if(e.aborted)throw new DOMException(`Aborted`,`AbortError`)}function x1(e){e.urls.length=0,c5t(e.held);for(let t of e.canvases)t.width=0,t.height=0;e.canvases.clear()}function u5t(e,t){let n=Math.max(1,Math.min(t.posterMaxPhysicalWidth,Math.round(t.posterMaxPhysicalHeight*e)));return{width:n,height:Math.max(1,Math.min(t.posterMaxPhysicalHeight,Math.round(n/e)))}}function d5t(e,t,n){let r=Math.max(0,e.sourceStart??0),i=Math.max(0,t.metadataDuration??r+(e.sourceRangeDuration??0)),a=Math.min(r,i),o=e.sourceRangeDuration??Math.max(0,i-a),s=Math.min(Math.max(0,o),Math.max(0,i-a)),c=r5t(a,s,Math.min(e.frameCount,n.richPreviewFrameCount)),l=Math.max(1,c.length-1);return{window:{sourceStart:a,lead:s/Math.max(2,l)/2,end:c.length>1?c.at(-1):1/0},timestamps:c}}function f5t({timestamps:e,window:t},n,r){let i=[];return e.forEach((e,a)=>{let o=n(e),s=o5t(o,e,t);if(!s)return void i.push(a);r.urls[a]=s.url,r.held.push({key:o,frame:s})}),i}async function p5t(e,t,n,r,i){let a=0;for await(let o of e.canvasesAtTimestamps(t)){b1(r);let e=n[a++];if(!o||e?.decodedAt===void 0)continue;i.canvases.add(o.canvas);let t=await l5t(o.canvas);b1(r);let s=s5t(e.key,e.decodedAt,URL.createObjectURL(t));i.urls[e.slot]=s.url,i.held.push({key:e.key,frame:s})}b1(r)}function m5t(e,t,n,r=e.urls.length){let i=e.urls.filter(e=>e!==void 0),a=i[0];if(!a)throw Error(`Video source returned no thumbnail frames`);let o=a,s=Array.from({length:r},(t,n)=>o=e.urls[n]??o),{width:c,height:l}=u5t(t,n);return{value:s.length===1?{kind:`image`,url:a,aspect:t}:{kind:`filmstrip`,urls:s,aspect:t},weight:c*l*4*i.length,dispose:()=>x1(e)}}async function h5t(e,t,n=iK){let r=e.fit??`cover`,i=qX({source:e.source,version:e.contentVersion}),a=e=>`${i}\0${r}\0${e}`,o={urls:[],held:[],canvases:new Set},s=i5t.get(e.source),c=s?.version===e.contentVersion?s?.info:void 0;try{if(c){if(f5t(d5t(e,c,n),a,o).length===0)return b1(t),m5t(o,c.aspect,n);x1(o)}return await g5t(e,t,n,a,o)}catch(e){throw x1(o),e}}async function g5t(e,t,n,r,i){let a=await Mb(()=>import(`./src-DDA8OuTJ.js`),__vite__mapDeps([2,1,3]));b1(t);let o=new a.Input({source:new a.UrlSource(e.source),formats:a.ALL_FORMATS});try{let s=await o.getPrimaryVideoTrack();if(b1(t),!s)throw Error(`Video source has no decodable video track`);let[c,l]=await Promise.all([s.getDisplayWidth(),s.getDisplayHeight()]);if(b1(t),!(c>0&&l>0))throw Error(`Video source has invalid dimensions`);let u=await s.getDurationFromMetadata({skipLiveWait:!0});b1(t);let d={aspect:c/l,metadataDuration:u};i5t.set(e.source,{version:e.contentVersion,info:d});let f=d5t(e,d,n),{timestamps:p,window:m}=f,h=f5t(f,r,i).map(e=>({slot:e,key:r(p[e])}));if(h.length>0){let r=new a.EncodedPacketSink(s);async function*o(){for(let e of h){let n=p[e.slot],i=await r.getKeyPacket(n,{metadataOnly:!0});if(t.aborted)return;e.decodedAt=i&&a5t(m,n,i.timestamp)?i.timestamp:n,yield e.decodedAt}}let c=u5t(d.aspect,n);await p5t(new a.CanvasSink(s,{width:c.width,height:c.height,fit:e.fit??`cover`,poolSize:1}),o(),h,t,i)}return m5t(i,d.aspect,n,p.length)}finally{o.dispose()}}function S1({strip:e,frameW:t,frameCount:n,watchGap:r,style:i,children:a}){let o=Math.min(n,Math.ceil(e.inViewEnd/t)),s=Math.min(o,Math.floor(e.inViewStart/t));return(0,W.jsxs)(`div`,{className:`absolute inset-0 flex`,style:{...i,paddingLeft:s*t},children:[(0,W.jsx)(`div`,{ref:r,"data-thumbnail-gap":`start`,className:`pointer-events-none absolute inset-y-0 left-0`,style:{width:s*t}}),Array.from({length:o-s},(e,t)=>a(s+t)),(0,W.jsx)(`div`,{ref:r,"data-thumbnail-gap":`end`,className:`pointer-events-none absolute inset-y-0 right-0`,style:{left:o*t}})]})}function _5t(e,t,n){let{videoSrc:r,sourceStart:i,sourceRangeDuration:a,duration:o,projectId:s,sessionEpoch:c,priority:l}=e;return{key:qX({kind:`video`,source:r,start:i,duration:a??o,frames:t}),projectId:s,sessionEpoch:c,kind:`video`,priority:l,rich:n,load:e=>h5t({source:r,contentVersion:qX({project:s,session:c}),sourceStart:i,sourceRangeDuration:a??o,frameCount:t,fit:`cover`},e)}}function v5t(e,t,n){return t.status===`ready`?t:n.status===`ready`?n:e.status===`ready`?e:t.status===`loading`||e.status===`loading`?{status:`loading`}:e}function y5t(e,t,n){let r=XX(e),i=XX(t),[a,o]=(0,U.useState)({media:n,request:t});return(i.status===`ready`||t===null)&&a.request!==t&&o({media:n,request:t}),v5t(r,i,XX(a.media===n?a.request:null))}var b5t=(0,U.memo)(function({videoSrc:e,label:t,labelColor:n,duration:r=5,sourceStart:i,sourceRangeDuration:a,projectId:o=e,sessionEpoch:s=0,priority:c=`visible`}){let[l,u,d]=oZ(),f=FLt(g3t(M$(l.width,16/9,l.height).frameCount)),p=(0,U.useMemo)(()=>({videoSrc:e,sourceStart:i,sourceRangeDuration:a,duration:r,projectId:o,sessionEpoch:s,priority:c}),[r,c,o,s,a,i,e]),m=(0,U.useMemo)(()=>_5t(p,1,!1),[p]),h=(0,U.useMemo)(()=>_5t(p,f,!0),[f,p]),g=FLt(l.width>0),_=y5t(g?m:null,g&&f>1?h:null,m.key),v=_.status===`ready`?_.value:null,y=v?.kind===`filmstrip`?v.urls:v?.kind===`image`?[v.url]:[],b=v?.kind===`image`||v?.kind===`filmstrip`?v.aspect:16/9,{frameW:x,frameCount:S}=M$(l.width,b,l.height);return(0,W.jsxs)(`div`,{ref:u,className:`absolute inset-0 overflow-hidden`,children:[y.length>0&&(0,W.jsx)(S1,{strip:l,frameW:x,frameCount:S,watchGap:d,children:e=>{let t=y[_3t(e,S,y.length)];return(0,W.jsx)(`div`,{className:`relative h-full shrink-0 overflow-hidden bg-neutral-900`,style:{width:x},children:(0,W.jsx)(`img`,{src:t,alt:``,draggable:!1,className:`absolute inset-0 h-full w-full object-cover`})},e)}}),_.status===`loading`&&y.length===0&&(0,W.jsx)(`div`,{className:`absolute inset-0 animate-pulse motion-reduce:animate-none`,style:{background:`var(--timeline-thumbnail-shimmer)`}}),_.status===`error`&&(0,W.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-neutral-900/60`,children:(0,W.jsx)(`span`,{className:`rounded-sm bg-black/50 px-1 text-[8px] text-neutral-500`,children:`no preview`})}),t&&(0,W.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 z-10 px-1.5 pb-0.5 pt-3`,style:{background:`var(--timeline-thumbnail-label-gradient)`},children:(0,W.jsx)(`span`,{className:`block truncate text-[9px] font-semibold leading-tight`,style:{color:n,textShadow:`var(--timeline-thumbnail-label-shadow)`},children:t})})]})}),x5t=`v3`,C1=3;function S5t(e){return Number.isFinite(e)&&e!=null&&e>0&&e<=C1?e/2:C1}function C5t({previewUrl:e,seekTime:t=2,duration:n=5,selector:r,selectorIndex:i,origin:a,output:o,contentRevision:s=0}){let c=e.replace(`/preview/comp/`,`/thumbnail/`).replace(/\/preview$/,`/thumbnail/index.html`),l=new URL(c,a);return l.searchParams.set(`t`,(t+n/2).toFixed(2)),l.searchParams.set(`v`,x5t),l.searchParams.set(`revision`,String(s)),o&&l.searchParams.set(`output`,o),r&&(l.searchParams.set(`selector`,r),i!=null&&i>0&&l.searchParams.set(`selectorIndex`,String(i))),l.toString()}function w5t(e){let t=/\/preview\/comp\/([^?#]+)/.exec(e);return t?.[1]?decodeURIComponent(t[1]):`index.html`}function T5t(e,t,{sessionEpoch:n=0,priority:r=`visible`,rich:i=!1}={}){return{key:qX({kind:`composition`,url:e}),projectId:t,sessionEpoch:n,kind:`composition`,priority:r,rich:i,load:t=>E5t(e,t)}}async function E5t(e,t){let n=await H(e,{signal:t});if(!n.ok)throw Error(`Composition thumbnail failed (${n.status})`);let r=await n.blob();if(t.aborted)throw new DOMException(`Aborted`,`AbortError`);let i=URL.createObjectURL(r);try{return{value:{kind:`image`,url:i,aspect:await v3t(i,t)},weight:iK.posterMaxPhysicalWidth*iK.posterMaxPhysicalHeight*4,dispose:()=>URL.revokeObjectURL(i)}}catch(e){throw URL.revokeObjectURL(i),e}}var w1=(0,U.memo)(function({previewUrl:e,label:t,labelColor:n,selector:r,selectorIndex:i,seekTime:a=2,duration:o=5,projectId:s=e,sessionEpoch:c=0,contentRevision:l=0,priority:u=`visible`}){let[d,f,p]=oZ(),m=C5t({previewUrl:e,seekTime:a,duration:o,selector:r,selectorIndex:i,origin:window.location.origin,contentRevision:l}),h=XX((0,U.useMemo)(()=>T5t(m,s,{sessionEpoch:c,priority:u,rich:!0}),[u,s,c,m])),g=h.status===`ready`&&h.value.kind===`image`?h.value:null,{frameW:_,frameCount:v}=M$(d.width,g?.aspect??16/9,d.height,48);return(0,W.jsxs)(`div`,{ref:f,className:`absolute inset-0 overflow-hidden`,children:[g&&(0,W.jsx)(S1,{strip:d,frameW:_,frameCount:v,watchGap:p,style:{animation:`hf-thumb-fade 200ms ease-out`,mixBlendMode:`var(--timeline-composition-thumbnail-blend)`},children:e=>(0,W.jsx)(`div`,{className:`relative h-full shrink-0 overflow-hidden`,style:{width:_},children:(0,W.jsx)(`img`,{src:g.url,alt:``,draggable:!1,className:`absolute inset-0 h-full w-full object-contain`,style:{opacity:`var(--timeline-composition-thumbnail-opacity)`}})},e)}),h.status===`loading`&&(0,W.jsx)(`div`,{className:`absolute inset-0 animate-pulse bg-text-0/[0.035]`}),t&&(0,W.jsx)(`div`,{className:`absolute inset-y-0 left-3 z-10 flex items-center`,children:(0,W.jsx)(`span`,{className:`block max-w-full truncate text-[10px] font-semibold leading-none`,style:{color:n,textShadow:g?`0 1px 4px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6)`:`none`},children:t})})]})}),D5t=0,O5t=50,k5t=800,A5t={isEditMode:!1,dismissed:!1,model:null,selectedSegmentIds:new Set,selectedGroupId:null,sourceFilePath:null,syncError:null,retrySave:null,past:[],future:[]},T1=null,E1=0;function D1(e,t){if(!e.model)return{};let n=Date.now();return T1===t&&n-E1<k5t?(E1=n,{future:[]}):(T1=t,E1=n,{past:[...e.past,e.model].slice(-O5t),future:[]})}var O1=gb((e,t)=>({...A5t,setEditMode:t=>e({isEditMode:t}),setDismissed:t=>e({dismissed:t}),setModel:t=>e({model:t}),setSourceFilePath:t=>e({sourceFilePath:t}),setSyncError:t=>e({syncError:t}),setRetrySave:t=>e({retrySave:t}),undo:()=>{let{model:n,past:r,future:i}=t(),a=r[r.length-1];return!a||!n?null:(T1=null,e({model:a,past:r.slice(0,-1),future:[...i,n]}),a)},redo:()=>{let{model:n,past:r,future:i}=t(),a=i[i.length-1];return!a||!n?null:(T1=null,e({model:a,past:[...r,n].slice(-O5t),future:i.slice(0,-1)}),a)},selectSegment:(t,n=!1)=>e(e=>{if(n){let n=new Set(e.selectedSegmentIds);return n.has(t)?n.delete(t):n.add(t),{selectedSegmentIds:n,selectedGroupId:null}}return{selectedSegmentIds:new Set([t]),selectedGroupId:null}}),selectGroup:n=>{let r=t().model?.groups.get(n);r&&e({selectedSegmentIds:new Set(r.segmentIds),selectedGroupId:n})},selectAll:()=>e(e=>e.model?{selectedSegmentIds:new Set(e.model.segments.keys()),selectedGroupId:null}:{}),clearSelection:()=>{let{selectedSegmentIds:n,selectedGroupId:r}=t();(n.size!==0||r!==null)&&e({selectedSegmentIds:new Set,selectedGroupId:null})},updateSegmentStyle:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.segments.get(t);if(!r)return{};let i=new Map(e.model.segments);return i.set(t,{...r,style:{...r.style,...n}}),{...D1(e,`seg-style:${t}`),model:{...e.model,segments:i}}}),updateSegmentText:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.segments.get(t);if(!r)return{};let i=new Map(e.model.segments);return i.set(t,{...r,text:n}),{...D1(e,`seg-text:${t}`),model:{...e.model,segments:i}}}),updateSegmentTiming:(t,n,r)=>e(e=>{if(!e.model)return{};let i=e.model.segments.get(t);if(!i)return{};let a=new Map(e.model.segments);return a.set(t,{...i,start:n,end:r}),{...D1(e,`seg-timing:${t}`),model:{...e.model,segments:a}}}),updateGroupStyle:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t);if(!r)return{};let i=new Map(e.model.groups);return i.set(t,{...r,style:{...r.style,...n}}),{...D1(e,`group-style:${t}`),model:{...e.model,groups:i}}}),updateGroupContainer:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t);if(!r)return{};let i=new Map(e.model.groups);return i.set(t,{...r,containerStyle:{...r.containerStyle,...n}}),{...D1(e,`group-container:${t}`),model:{...e.model,groups:i}}}),updateGroupAnimation:(t,n,r)=>e(e=>{if(!e.model)return{};let i=e.model.groups.get(t);if(!i)return{};let a=new Map(e.model.groups),o=i.animation[n],s=o===null?r:{...o,...r};return a.set(t,{...i,animation:{...i.animation,[n]:s}}),{...D1(e,`group-anim:${t}:${n}`),model:{...e.model,groups:a}}}),splitGroup:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t);if(!r)return{};let i=r.segmentIds.indexOf(n);if(i<=0)return{};let a=r.segmentIds.slice(0,i),o=r.segmentIds.slice(i),s=`group-split-${D5t++}`,c=new Map(e.model.groups);c.set(t,{...r,segmentIds:a}),c.set(s,{...r,id:s,segmentIds:o});let l=e.model.groupOrder.indexOf(t),u=[...e.model.groupOrder];u.splice(l+1,0,s);let d=new Map(e.model.segments);return o.forEach((e,t)=>{let n=d.get(e);n&&d.set(e,{...n,groupIndex:t})}),{...D1(e,`split:${t}:${n}:${D5t}`),model:{...e.model,groups:c,segments:d,groupOrder:u}}}),mergeGroups:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t),i=e.model.groups.get(n);if(!r||!i)return{};let a=[...r.segmentIds,...i.segmentIds],o=new Map(e.model.groups);o.set(t,{...r,segmentIds:a}),o.delete(n);let s=e.model.groupOrder.filter(e=>e!==n),c=new Map(e.model.segments);i.segmentIds.forEach((e,t)=>{let n=c.get(e);n&&c.set(e,{...n,groupIndex:r.segmentIds.length+t})});let l=e.selectedGroupId===n?null:e.selectedGroupId;return{...D1(e,`merge:${t}:${n}`),model:{...e.model,groups:o,segments:c,groupOrder:s},selectedGroupId:l}}),updateSelectedStyle:t=>e(e=>{if(!e.model||e.selectedSegmentIds.size===0)return{};let n=new Map(e.model.segments);for(let r of e.selectedSegmentIds){let e=n.get(r);e&&n.set(r,{...e,style:{...e.style,...t}})}return{...D1(e,`sel-style:${[...e.selectedSegmentIds].join(`,`)}`),model:{...e.model,segments:n}}}),applyAnimationToAll:t=>e(e=>{if(!e.model)return{};let n=new Map(e.model.groups);for(let[e,r]of n)n.set(e,{...r,animation:t});return{...D1(e,`apply-anim-all`),model:{...e.model,groups:n}}}),reset:()=>{T1=null,e(e=>({...A5t,retrySave:e.retrySave,selectedSegmentIds:new Set,past:[],future:[]}))}})),j5t=new Set([`ArrowLeft`,`ArrowRight`]),M5t=[`button`,`a[href]`,`[role='button']`,`[role='checkbox']`,`[role='menuitem']`,`[role='menuitemradio']`,`[role='radio']`,`[role='spinbutton']`].join(`,`);function N5t(e){if(oX(e))return!0;if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.closest==`function`&&t.closest.call(e,M5t)!==null}var P5t=`[role=dialog][aria-modal=true]`;function F5t(){let e=globalThis.document;if(!e)return!1;let t=e.fullscreenElement;return Array.from(e.querySelectorAll(P5t)).some(e=>(!t||t.contains(e))&&!e.closest(`[inert]`)&&(typeof e.checkVisibility!=`function`||e.checkVisibility({visibilityProperty:!0})))}function I5t(e,t={isCaptionEditMode:!1,selectedCaptionSegmentCount:0}){return e.metaKey||e.ctrlKey||e.altKey||N5t(e.target)||F5t()?!0:j5t.has(e.code)&&t.isCaptionEditMode&&t.selectedCaptionSegmentCount>0}var L5t=[1,2,4],k1=0;function R5t(){k1+=1;let e=!1;return()=>{e||(e=!0,--k1)}}function z5t(){return k1>0}function B5t(e){return!e.shiftKey&&!e.altKey&&X.getState().activeTool===`razor`}function V5t({iframeRef:e,shuttleDirectionRef:t,shuttleSpeedIndexRef:n,iframeShortcutCleanupRef:r,getAdapter:i,play:a,playBackward:o,pause:s,seek:c}){let l=(0,U.useRef)(new Set),u=(0,U.useRef)(()=>{}),d=(0,U.useRef)(()=>{}),f=(0,U.useCallback)(e=>{c(XMe(i()?.getTime()??X.getState().currentTime,e,30))},[i,c]),p=(0,U.useCallback)(e=>{if(X.getState().playLocked)return;n.current=t.current===e?Math.min(n.current+1,L5t.length-1):0;let r=L5t[n.current];X.getState().setPlaybackRate(r),e===`forward`?a():o(r)},[a,o,t,n]),m=(0,U.useCallback)(()=>{X.getState().isPlaying?s():a()},[a,s]),h=(0,U.useCallback)(e=>{if(e.defaultPrevented)return;let t=O1.getState();if(I5t(e,{isCaptionEditMode:t.isEditMode,selectedCaptionSegmentCount:t.selectedSegmentIds.size}))return;let n=e.key.toLowerCase();if(l.current.add(n),e.code===`Space`){e.preventDefault(),m();return}if(!((e.code===`ArrowLeft`||e.code===`ArrowRight`)&&z5t())){if(e.code===`ArrowLeft`){e.preventDefault(),f(e.shiftKey?-10:-1);return}if(e.code===`ArrowRight`){e.preventDefault(),f(e.shiftKey?10:1);return}if(!e.repeat){if(n===`m`){e.preventDefault();let t=X.getState();t.setAudioMuted(!t.audioMuted);return}if(n===`l`&&e.shiftKey){e.preventDefault();let t=X.getState();t.setLoopEnabled(!t.loopEnabled);return}if(n===`k`){e.preventDefault(),s();return}if(n===`j`){if(e.preventDefault(),l.current.has(`k`)){f(-1);return}p(`backward`);return}if(n===`l`){if(e.preventDefault(),l.current.has(`k`)){f(1);return}p(`forward`);return}if(n===`i`){e.preventDefault();let t=i()?.getTime()??X.getState().currentTime;X.getState().setInPoint(e.shiftKey?null:t);return}if(n===`o`){e.preventDefault();let t=i()?.getTime()??X.getState().currentTime;X.getState().setOutPoint(e.shiftKey?null:t);return}if(n===`a`){if(B5t(e))return;e.preventDefault(),c(X.getState().inPoint??0,{keepPlaying:!0});return}if(n===`e`){e.preventDefault();let{outPoint:t}=X.getState();c(t??i()?.getDuration()??X.getState().duration,{keepPlaying:!0});return}}}},[s,p,f,m,i,c]),g=(0,U.useCallback)(e=>{l.current.delete(e.key.toLowerCase())},[]);return u.current=h,d.current=g,{playbackKeyDownRef:u,playbackKeyUpRef:d,attachIframeShortcutListeners:(0,U.useCallback)(()=>{r.current?.(),r.current=null;let t=null,n=null;try{t=e.current?.contentWindow??null,n=e.current?.contentDocument??null}catch{return}if(!t&&!n)return;let i=e=>u.current(e),a=e=>d.current(e);try{t?.addEventListener(`keydown`,i,!0),t?.addEventListener(`keyup`,a,!0)}catch{}n?.addEventListener(`keydown`,i,!0),n?.addEventListener(`keyup`,a,!0),r.current=()=>{try{t?.removeEventListener(`keydown`,i,!0),t?.removeEventListener(`keyup`,a,!0)}catch{}n?.removeEventListener(`keydown`,i,!0),n?.removeEventListener(`keyup`,a,!0)}},[e,r]),togglePlay:m}}var A1=new WeakMap,j1=new WeakMap,M1=new WeakMap;function H5t(e,t){t.some(e=>e.type!==`childList`||[...e.addedNodes,...e.removedNodes].some(e=>Me(e)&&(e.tagName.toLowerCase()===`hf-audio-group`||e.hasAttribute(`data-audio-group`)||e.querySelector?.(`hf-audio-group,[data-audio-group]`)!=null)))&&j1.set(e,(j1.get(e)??0)+1)}function U5t(e){if(M1.has(e)||typeof MutationObserver>`u`||!e.body)return;let t=new MutationObserver(t=>H5t(e,t));M1.set(e,t),t.observe(e.body,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[Re,yt,s,`data-label`,`data-volume`,`data-hidden`,`id`]})}function N1(e){e&&A1.delete(e)}function P1(e,t){if(!e)return{label:t,volume:1,hidden:!1};U5t(e);let n=M1.get(e)?.takeRecords();n?.length&&H5t(e,n);let r=j1.get(e)??0,i=A1.get(e),a=i&&i.revision===r?i.entries:void 0;return a||(a=new Map(Ve(e).map(e=>[e.id,{label:e.label,volume:e.volume,hidden:e.hidden,...e.fxChain?{fxChain:e.fxChain}:{},...e.automation?{automation:e.automation}:{}}])),A1.set(e,{revision:r,entries:a})),a.get(t)??{label:t,volume:1,hidden:!1}}var W5t=`hf:transition:`;function G5t(e){if(!e.startsWith(W5t))return null;let t=e.slice(W5t.length).split(`:`);return t.length<3||!t[0]||!t[1]?null:[t[0],t[1]]}function K5t(e,t){for(let n of[t,`el-${t}`]){let t=e.getElementById(n);if(t?.hasAttribute(`data-start`))return t}return Array.from(e.querySelectorAll(`[data-start]`)).find(e=>e.getAttribute(`data-hf-id`)===t||e.getAttribute(`data-composition-id`)===t)??null}function F1(e,t){let n=new Map;if(!t)return n;for(let r of Object.values(t)){let t=r.getLabels?.()??r.labels??{};for(let r of Object.keys(t)){let t=G5t(r);if(!t)continue;let i=K5t(e,t[0]),a=K5t(e,t[1]);i&&a&&(n.set(i,r),n.set(a,r))}}return n}function q5t(e,t={},n=30){return{...t,source:`hf-parent`,type:`control`,action:e,...vMe(n)}}function I1(e,t,n={},r=30){e?.postMessage(q5t(t,n,r),`*`)}function L1(e){return bMe(e,30)}function J5t(e){e.status===`unsupported`&&window.dispatchEvent(new CustomEvent(`runtimeprotocolerror`,{detail:{code:e.code,receivedVersion:e.receivedVersion}}))}function R1(e){let t=L1(e);return t.status===`unsupported`?(J5t(t),null):t}function Y5t(e){let t=L1(e);return t.status===`supported`?t.fps:30}function X5t(e,t){e.documentElement&&(e.documentElement.style.overflow=`hidden`,e.documentElement.style.margin=`0`),e.body&&(e.body.style.overflow=`hidden`,e.body.style.margin=`0`),t.scrollTo({top:0,left:0,behavior:`auto`})}function Z5t(e){let t=/data-composition-id=["']([^"']+)["']/gi,n=new Set,r=Array.from(e.querySelectorAll(`style, script`));for(let e of r){let r=e.textContent||``;if(!r)continue;let i;for(;(i=t.exec(r))!==null;){let e=(i[1]||``).trim();e&&n.add(e)}}if(n.size===0)return;let i=new Set,a=Array.from(e.querySelectorAll(`[data-composition-id]`));for(let e of a){let t=e.getAttribute(`data-composition-id`);t&&i.add(t)}for(let t of n){if(t===`root`||i.has(t))continue;let n=e.getElementById(`${t}-layer`)||e.getElementById(`${t}-comp`)||e.getElementById(t);n&&(n.getAttribute(`data-composition-id`)||n.setAttribute(`data-composition-id`,t))}}function Q5t(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):1}function $5t(e){return e instanceof HTMLElement}function z1(e){let t=e.getRootNode();return typeof ShadowRoot<`u`&&t instanceof ShadowRoot&&$5t(t.host)?t.host:null}function B1(e,t,n){I1(e.contentWindow,t,n)}function e7t(e,t){if(e)try{let n=z1(e);if(n&&typeof n.muted==`boolean`){n.muted=t;return}B1(e,`set-muted`,{muted:t})}catch{}}function t7t(e,t){if(!e)return;let n=Q5t(t);try{let t=z1(e);if(t&&typeof t.volume==`number`){t.volume=n;return}B1(e,`set-volume`,{volume:n})}catch{}}function n7t(e,t,n){e7t(e,t),t7t(e,n)}function r7t(e,t){if(!e)return;let n=Number.isFinite(t)&&t>0?t:1;try{let t=z1(e);if(t&&typeof t.playbackRate==`number`){t.playbackRate=n;return}B1(e,`set-playback-rate`,{playbackRate:n})}catch{}}var i7t=.25,V1=null,H1=null,U1=null,W1=null;function a7t(e){return e!==null&&e.namespaceURI===`http://www.w3.org/1999/xhtml`&&e.localName===`audio`}function o7t(e,t){if(t){let n=mt(e,`audio`)(t);if(a7t(n))return n}return e.querySelector(`audio[data-timeline-role='music']`)??e.querySelector(`audio`)}function s7t(e){e.ownerDocument.defaultView?.__hf?.leasePausedMedia?.(e)}function c7t(e){e.ownerDocument.defaultView?.__hf?.releasePausedMedia?.(e)}function l7t(e,t,n){V1&&V1!==e&&G1(),U1===null&&(U1=e.muted),W1===null&&(W1=e.volume),V1=e,s7t(e);try{e.muted=!1,e.volume=i7t*Q5t(n),Math.abs(e.currentTime-t)>.04&&(e.currentTime=t),e.paused&&e.play().catch(()=>{})}catch{}H1&&clearTimeout(H1),H1=setTimeout(G1,140)}function u7t(e,t,n,r=1){if(!e)return;if(t===null){G1();return}let i=null;try{i=e.contentDocument}catch{return}if(!i)return;let a=o7t(i,n);a&&l7t(a,t,r)}function G1(){H1&&=(clearTimeout(H1),null);let e=V1;if(V1=null,e){c7t(e);try{e.pause(),U1!==null&&(e.muted=U1),W1!==null&&(e.volume=W1)}catch{}U1=null,W1=null}}function d7t(e,t){return e.__timelines?.[t]?.duration?.()??0}function f7t(e){let t=new Map;for(let n of e.querySelectorAll(`[data-start]`))for(let e of[n.id,n.getAttribute(`data-hf-id`),n.getAttribute(`data-composition-id`)])e&&t.set(e,n);return t}function p7t(e,t){let n=(r,i)=>{if(i.has(r))return null;let a=e.get(r);if(!a)return null;let o=new Set(i).add(r),s=Tb(a,{resolveReferenceEnd:e=>n(e,o)});if(s.end!=null)return s.end;let c=a.getAttribute(`data-composition-id`),l=c?d7t(t,c):0;return s.start==null||l<=0?null:s.start+l};return n}function m7t(e,t,n){if(!Number.isFinite(t)||t<=0)return null;let r=Number.isFinite(e)?e:0;if(!Number.isFinite(n)||n<=0)return{start:r,duration:t};if(r>=n)return null;let i=Math.min(t,Math.max(0,n-r));return i>0?{start:r,duration:i}:null}function h7t(e,t){return e||t}function K1(e){return e||void 0}function g7t(e,t,n){if(n)return{...e,compositionSrc:n};let r=t.querySelector(`video[src]`);return r?{...e,src:K1(r.getAttribute(`src`)),tag:`video`}:e}function _7t(e){let{doc:t,iframeWin:n,element:r,compositionId:i,rootDuration:a,fallbackIndex:o}=e,{resolveEnd:s,masterTime:c}=e,l=F1(t,n.__timelines),u=Tb(r,{resolveReferenceEnd:e=>s(e,new Set([i]))}),d=m7t(c.resolveStartForElement(r),u.duration??d7t(n,i),a);if(!d)return null;let f=h7t(r.id,i),p=r.getAttribute(`data-composition-src`)??r.getAttribute(`data-composition-file`),m=at(r),h=Mt(r),g=Xt(t,r,m),_=pe({id:f,label:r.getAttribute(`data-timeline-label`)??r.getAttribute(`data-label`),tag:r.tagName}),v=pn({preferredId:f,label:_,fallbackIndex:o,domId:K1(r.id),selector:m,selectorIndex:g,sourceFile:h});return g7t({id:v.id,label:_,transitionLabel:l.get(r)??r.getAttribute(`data-transition-label`)??void 0,key:v.key,tag:r.tagName.toLowerCase(),start:d.start,parentCompositionStart:c.resolveHostStartForElement(r),duration:d.duration,track:u.trackIndex,authoredTrack:u.trackIndex,domId:K1(r.id),hfId:K1(r.getAttribute(`data-hf-id`)),selector:m,selectorIndex:g,sourceFile:h,zIndex:fn(r),src:K1(r.getAttribute(`src`))?new URL(r.getAttribute(`src`),r.baseURI).href:void 0},r,p)}function v7t(e,t,n,r){let i=new Set(n.map(e=>e.id)),a=e.querySelector(`[data-composition-id]`)?.getAttribute(`data-composition-id`),o=e.querySelectorAll(`[data-composition-id][data-start]`),s=[],c=p7t(f7t(e),t),l=Eb({timelineRegistry:t.__timelines,includeAuthoredTimingAttrs:!0,documentRef:e});for(let n of o){let o=n,u=o.getAttribute(`data-composition-id`);if(!u||u===a||i.has(o.id)||i.has(u))continue;let d=_7t({doc:e,iframeWin:t,element:o,compositionId:u,rootDuration:r,fallbackIndex:s.length,resolveEnd:c,masterTime:l});d&&s.push(d)}let u=!1,d=mt(e);return{missing:s,updatedEls:n.map(t=>{if(t.compositionSrc)return t;let n=d(t)??e.querySelector(`[data-composition-id="${CSS.escape(t.id)}"]`);if(!n)return t;let r=n.getAttribute(`data-composition-src`)||n.getAttribute(`data-composition-file`);return r?(u=!0,{...t,compositionSrc:r}):t}),patched:u}}function y7t(e){return e.tagName||e.kind||`div`}function b7t(e){let{clip:t,fallbackIndex:n,doc:r}=e,i=e.hostEl??null,a=r?F1(r,r.defaultView?.__timelines):new Map,o=pe({id:t.id,label:t.label,tag:y7t(t)}),s,c,l,u,d;i&&(s=i.id||void 0,d=i.getAttribute(`data-hf-id`)||void 0,c=at(i),l=r&&c?Xt(r,i,c):void 0,u=Mt(i));let f=pn({preferredId:t.id,label:o,fallbackIndex:n,domId:s,selector:c,selectorIndex:l,sourceFile:u}),p={id:f.id,label:o,transitionLabel:i&&a.get(i)||i?.getAttribute(`data-transition-label`)||void 0,key:f.key,kind:t.kind,tag:y7t(t),start:t.start,duration:t.duration,track:t.track,authoredTrack:t.track,stackingContextId:t.stackingContextId??null,domId:s,hfId:d,selector:c,selectorIndex:l,sourceFile:u,playbackStart:t.playbackStart,playbackRate:t.playbackRate};if(i){if(C(p,i),!p.src){let e=i.getAttribute(`src`);e&&(p.src=new URL(e,i.baseURI).href)}i.hasAttribute(`data-hidden`)&&(p.hidden=!0);let e=i.getAttribute(`data-timeline-role`);e&&(p.timelineRole=e);let t=i.getAttribute(`data-link`);t&&(p.link=t);let n=ew(i)?.getAttribute(`data-composition-id`);n&&(p.compositionScope=n);let a=i.getAttribute(`data-sync-origin`);a&&(p.syncOrigin=a);let o=i.getAttribute(`data-audio-group`);if(o){p.audioGroup=o;let e=P1(r??i.ownerDocument,o);p.audioGroupLabel=e.label,p.audioGroupVolume=e.volume,p.audioGroupHidden=e.hidden,e.fxChain&&(p.audioGroupFxChain=e.fxChain),e.automation&&(p.audioGroupAutomation=e.automation)}let s=i.getAttribute(`data-fx-chain`);s&&(p.fxChain=s);let c=i.getAttribute(`data-automation`);c&&(p.automation=c),p.zIndex=fn(i)}if(t.assetUrl&&(p.src=t.assetUrl),t.kind===`composition`&&t.compositionId){p.playbackStart??=0,p.playbackRate??=1;let e=t.compositionSrc;if(e||=(i?.getAttribute(`data-composition-id`)!==t.compositionId&&(i=r?.querySelector(`[data-composition-id="${CSS.escape(t.compositionId)}"]`)??i),i?.getAttribute(`data-composition-src`)??i?.getAttribute(`data-composition-file`)??null),e)p.compositionSrc=e;else if(i){let e=i.querySelector(`video[src]`);e&&(p.src=e.getAttribute(`src`)||void 0,p.tag=`video`)}if(i){p.domId=i.id||void 0,p.hfId=i.getAttribute(`data-hf-id`)||void 0,p.selector=at(i),p.selectorIndex=r&&p.selector?Xt(r,i,p.selector):void 0,p.sourceFile=Mt(i);let e=pn({preferredId:t.id,label:o,fallbackIndex:n,domId:p.domId,selector:p.selector,selectorIndex:p.selectorIndex,sourceFile:p.sourceFile});p.id=e.id,p.key=e.key}}return p}function q1(e,t,n){let r=e.querySelector(`[data-composition-id]`),i=e.querySelectorAll(`[data-start]`),a=[],o=0,s=n??e.defaultView?.__timelines,c=F1(e,s),l=Eb({timelineRegistry:s,includeAuthoredTimingAttrs:!0,documentRef:e});return i.forEach(n=>{if(n===r||Kt(n))return;let i=n,s=Tb(i);if(s.start==null)return;let u=i.tagName.toLowerCase(),d=u===`video`||u===`audio`?l.resolveMediaStartForElement(i):l.resolveStartForElement(i);if(Number.isFinite(t)&&t>0&&d>=t)return;let f=s.duration??0;if(f<=0&&(f=Math.max(0,t-d)),Number.isFinite(t)&&t>0&&(f=Math.min(f,Math.max(0,t-d))),!Number.isFinite(f)||f<=0)return;let p=s.trackSource==="default"?o++:s.trackIndex,m=i.getAttribute(`data-composition-id`),h=at(i),g=Mt(i),_=Xt(e,i,h),v=pe({id:i.id||i.getAttribute(`data-hf-original-composition-id`)||m||null,label:i.getAttribute(`data-timeline-label`)??i.getAttribute(`data-label`),tag:u}),y=pn({preferredId:i.id||m||null,label:v,fallbackIndex:a.length,domId:i.id||void 0,selector:h,selectorIndex:_,sourceFile:g}),b={id:y.id,label:v,transitionLabel:c.get(i)??i.getAttribute(`data-transition-label`)??void 0,key:y.key,kind:m&&m!==r?.getAttribute(`data-composition-id`)?`composition`:u===`video`||u===`audio`?u:u===`img`?`image`:`element`,tag:u,start:d,parentCompositionStart:l.resolveHostStartForElement(i),...l.isRootGlobalMediaStartForElement(i)&&{authoredStartIsMasterTime:!0},duration:f,track:p,domId:i.id||void 0,hfId:i.getAttribute(`data-hf-id`)||void 0,selector:h,selectorIndex:_,sourceFile:g,stackingContextId:eMe(i),zIndex:fn(i)},x=xe(i);if(C(b,i),x){x.tagName===`IMG`&&(b.tag=`img`);let e=x.src||void 0;e&&(b.src=e)}let S=i.getAttribute(`data-fx-chain`);S&&(b.fxChain=S);let w=i.getAttribute(`data-automation`);w&&(b.automation=w),i.hasAttribute(`data-timeline-locked`)&&(b.timelineLocked=!0),i.hasAttribute(`data-hidden`)&&(b.hidden=!0);let T=i.getAttribute(`data-timeline-role`);T&&(b.timelineRole=T);let E=i.getAttribute(`data-link`);E&&(b.link=E);let D=ew(i)?.getAttribute(`data-composition-id`);D&&(b.compositionScope=D);let O=i.getAttribute(`data-sync-origin`);O&&(b.syncOrigin=O);let k=i.getAttribute(`data-audio-group`);if(k){b.audioGroup=k;let t=P1(e,k);b.audioGroupLabel=t.label,b.audioGroupVolume=t.volume,b.audioGroupHidden=t.hidden,t.fxChain&&(b.audioGroupFxChain=t.fxChain),t.automation&&(b.audioGroupAutomation=t.automation)}let A=i.getAttribute(`data-composition-src`)||i.getAttribute(`data-composition-file`);if(A)b.compositionSrc=A;else if(m&&m!==r?.getAttribute(`data-composition-id`)){let e=i.querySelector(`video[src], img[src]`);e&&(b.src=e.getAttribute(`src`)||void 0,b.tag=e.tagName===`IMG`?`img`:`video`)}b.kind===`composition`&&(b.playbackStart??=0,b.playbackRate??=1),a.push(b)}),a}function x7t(e,t,n,r,i=()=>!0){let o=Number.isFinite(n)?n:0,s=Number.isFinite(r)?r:0;if(e.length===0||t.length>=e.length||s>o)return t;let c=new Set(t.map(a)),l=e.filter(e=>!c.has(a(e))&&e.compositionSrc!=null&&i(e));return l.length===0?t:[...t,...l]}function S7t(e){let t=e.match(/\/preview\/comp\/(.+?)(?:\?|$)/);return t?decodeURIComponent(t[1]):void 0}function C7t(e){if(!Number.isFinite(e.rootDuration)||e.rootDuration<=0)return null;let t=S7t(e.iframeSrc);return{id:e.compositionId,label:pe({id:e.compositionId,tag:e.tagName}),key:d({id:e.compositionId,fallbackIndex:0,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:t}),tag:e.tagName.toLowerCase()||`div`,start:0,duration:e.rootDuration,track:0,compositionSrc:t,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:t}}function J1(e){return Number.isFinite(e)&&e>0&&e<7200?e:0}function w7t(e){let t=e.getAttribute(Re);if(!t)return{};let n=P1(e.ownerDocument,t);return{audioGroup:t,audioGroupLabel:n.label,audioGroupVolume:n.volume,audioGroupHidden:n.hidden,...n.fxChain?{audioGroupFxChain:n.fxChain}:{},...n.automation?{audioGroupAutomation:n.automation}:{}}}function T7t(e){let t=new Map,n=e?.__clipTree;if(!n)return t;let r=e=>{for(let n of e)n.id&&n.parentId&&t.set(n.id,n.parentId),n.children.length>0&&r(n.children)};return r(n.roots),t}function Y1(e,t,n,r,i){for(let a of Array.from(t.children)){if(!a.id){Y1(e,a,n,r,i);continue}let t=a.hasAttribute(`data-hf-group`);i.push({id:a.id,parentId:n,hostId:e,label:t&&a.getAttribute(`data-hf-group`)||a.id,stackingContextId:eMe(a),...w7t(a)}),r.set(a.id,n),t&&Y1(e,a,a.id,r,i)}}function E7t(e,t,n){let r=[];if(!e)return r;for(let i of t){if(i.kind!==`composition`||!i.id)continue;let t=R(e,i);if(!t)continue;let a=t.querySelector(`[data-hf-inner-root]`)??t;Y1(i.id,a,i.id,n,r)}return r}function D7t(e){let t={};e.hasAttribute(`data-hidden`)&&(t.hidden=!0),e.hasAttribute(`data-timeline-locked`)&&(t.timelineLocked=!0);let n=e.getAttribute(`data-timeline-role`);n&&(t.timelineRole=n);let r=e.getAttribute(`data-fx-chain`);r&&(t.fxChain=r);let i=e.getAttribute(`data-automation`);return i&&(t.automation=i),Object.keys(t).length>0?t:null}function O7t(e,t){let n=new Map;if(!e)return n;for(let r of t){if(r.kind!==`composition`||!r.id)continue;let t=R(e,r);if(t)for(let e of Array.from(t.querySelectorAll(`[id]`))){let t=D7t(e);t&&n.set(e.id,t)}}return n}function X1(e){try{return e?.contentDocument??null}catch{return null}}function k7t(e,t){let n=t?Oe(t):null;return e.map((e,r)=>b7t({clip:e,fallbackIndex:r,doc:t,hostEl:n?.(e,r)??null}))}function A7t(e,t,n,r){let i=t>0&&e.length>0;r(j7t(e,i?t:n),i?t:void 0)}function j7t(e,t){return t<=0?[...e]:e.filter(e=>e.start<t).map(e=>({...e,duration:Math.min(e.duration,t-e.start)})).filter(e=>e.duration>0)}function M7t(e){let t=e.pendingSeek??e.requestedSeek??e.storeCurrentTime;return!Number.isFinite(t)||t<=0?0:!Number.isFinite(e.duration)||e.duration<=0?t:Math.min(t,e.duration)}function N7t(e,t){let n=Number.isFinite(t)&&t>0?t:0;e.seek(n>.001?Math.max(0,n-.001):.001),e.seek(n)}function P7t(e,t){let n=X.getState().requestedSeekTime,r=M7t({pendingSeek:t.current,requestedSeek:n,storeCurrentTime:X.getState().currentTime,duration:e.getDuration()});return t.current=null,n!=null&&X.getState().clearSeekRequest(),N7t(e,r),r}function F7t(e,t){let n=J1(e.getDuration());n>0&&n!==X.getState().duration&&t(n)}function I7t(e,t,n,r){let i=q1(e,n);if(i.length>0){r(i);return}let a=e.querySelector(`[data-composition-id]`);if(!a||n<=0)return;let o=C7t({compositionId:a.getAttribute(`data-composition-id`)||`composition`,tagName:a.tagName||`div`,rootDuration:n,iframeSrc:t?.src||``,selector:at(a)});o&&r([o])}function L7t(e,t){return!e.source||!t||e.source===t.contentWindow}function R7t(e,t){if(!L7t(e,t))return!1;let n=e.data;return n?.source!==`hf-preview`||n?.type!==`state`&&n?.type!==`timeline`?!1:L1(n).status!==`unsupported`}function z7t(e,t,n){!e||!t||(X5t(e,t),Z5t(e),n())}function B7t(e,t){let n=e?.__clipManifest;n&&n.clips.length>0&&t(n)}function V7t(e){let{iframe:t,adapter:n,syncTimelineElements:r}=e;try{let i=X1(t),a=t?.contentWindow??null;z7t(i,a,e.attachIframeShortcutListeners),B7t(a,e.processTimelineMessage),e.enrichMissingCompositions(),e.applyPreviewAudioState(),i&&X.getState().elements.length===0&&I7t(i,t,n.getDuration(),r)}catch{}}function H7t(e){e&&e.style.visibility===`hidden`&&(e.style.visibility=``)}function U7t(e,t,n){H7t(e),n()}function W7t(e,t,n){let r=e.find(e=>e.role===`live`);return r?[r,{gen:t,role:`shadow`,url:n}]:[{gen:t,role:`live`}]}function G7t(e){return e.filter(e=>e.role===`live`)}function K7t(e,t){let n=e.find(e=>e.gen===t&&e.role===`shadow`);return n?[{...n,role:`live`}]:e}function q7t(e){return Math.max(J1(e.manifestDurationSeconds),J1(e.authoredRootDurationSeconds))}function J7t({iframeRef:e,probeIntervalRef:t,pendingSeekRef:n,isRefreshingRef:r,getAdapter:i,syncTimelineElements:a,setDuration:o,setCurrentTime:s,requestTimelineReady:c,setIsPlaying:l,attachIframeShortcutListeners:u,applyPreviewAudioState:d,onAdapterReady:f=U7t,isCurrent:p,onLoadGiveUp:m}){let h=(0,U.useCallback)(t=>{if(!t.clips)return;X.getState().setClipManifest(t.clips);let n=new Set(t.clips.map(e=>e.compositionId).filter(Boolean)),r=t.clips.filter(e=>!e.parentCompositionId||!n.has(e.parentCompositionId)),i=X1(e.current);try{let n=T7t(e.current?.contentWindow??null),r=E7t(i,t.clips,n);X.getState().setClipParentMap(n),X.getState().setDomClipChildren(r),X.getState().setSubCompositionHostState(O7t(i,t.clips))}catch{}let o=k7t(r,i),s=Y5t(t);Nq.getState().setCompositionFps(s),A7t(o,q7t({manifestDurationSeconds:t.durationInFrames/s,authoredRootDurationSeconds:nn(i)}),X.getState().duration,a)},[e,a]),g=(0,U.useCallback)(()=>{try{let t=e.current,n=t?.contentDocument,r=t?.contentWindow;if(!n||!r)return;let i=X.getState().elements,o=X.getState().duration,{missing:s,updatedEls:c,patched:l}=v7t(n,r,i,o);if(s.length>0||l){let e=new Set(c.map(e=>e.id)),t=s.filter(t=>!e.has(t.id));a([...c,...t])}}catch{}},[e,a]),_=(0,U.useCallback)(t=>{if(p&&!p(t))return!0;let m=i();if(!m||m.getDuration()<=0)return!1;m.pause();let _=P7t(m,n);return f(e.current,t,()=>{Lb.notify(_),F7t(m,o),s(_),r.current||c(X1(e.current)),r.current=!1,l(!1),V7t({iframe:e.current,adapter:m,processTimelineMessage:h,enrichMissingCompositions:g,applyPreviewAudioState:d,attachIframeShortcutListeners:u,syncTimelineElements:a})}),!0},[i,o,s,c,l,h,g,a,u,d,f,p,e,r,n]),v=(0,U.useRef)(null),y=(0,U.useCallback)(n=>{let r=X1(e.current);if(r&&X.getState().markPreviewLoadStep(r),d(),t.current&&clearInterval(t.current),v.current?.(),v.current=null,_(n))return;let i=e.current,a=!1,o=0,s=()=>{window.removeEventListener(`message`,l),cancelAnimationFrame(o)},c=()=>{if(!a){if(_(n)){a=!0,s(),t.current&&clearInterval(t.current);return}cancelAnimationFrame(o),o=requestAnimationFrame(c)}},l=e=>{R7t(e,i)&&c()};window.addEventListener(`message`,l),v.current=s,t.current=setTimeout(()=>{a||c(),s(),a||m?.(n),H7t(e.current)},5e3)},[_,e,t,d,m]),b=(0,U.useCallback)(()=>{t.current&&clearInterval(t.current),v.current?.(),v.current=null},[t]);return{processTimelineMessage:h,processTimelineMessageRef:{current:h},enrichMissingCompositions:g,enrichMissingCompositionsRef:{current:g},initializeAdapter:_,onIframeLoad:y,cancelPendingLoad:b}}var Z1=`--hf-studio-rotation`,Q1=`data-hf-studio-path-offset`,$1=`data-hf-studio-edit-at`,e0=`data-hf-studio-box-size`,t0=`data-hf-studio-rotation`,n0=`data-hf-studio-original-translate`,r0=`data-hf-studio-original-inline-translate`,i0=`data-hf-studio-original-width`,a0=`data-hf-studio-original-height`,o0=`data-hf-studio-original-box-width`,s0=`data-hf-studio-original-box-height`,c0=`data-hf-studio-original-min-width`,l0=`data-hf-studio-original-min-height`,u0=`data-hf-studio-original-max-width`,d0=`data-hf-studio-original-max-height`,f0=`data-hf-studio-original-flex-basis`,p0=`data-hf-studio-original-flex-grow`,m0=`data-hf-studio-original-flex-shrink`,h0=`data-hf-studio-original-box-sizing`,g0=`data-hf-studio-original-scale`,_0=`data-hf-studio-original-transform-origin`,v0=`data-hf-studio-original-display`,y0=`data-hf-studio-original-rotate`,b0=`data-hf-studio-original-inline-rotate`,x0=`data-hf-studio-original-rotation-transform-origin`,S0=`data-hf-studio-rotation-draft`,C0=`data-hf-studio-original-transform-display`,Y7t=`__hfStudioManualEditsApply`,w0=`__hfStudioManualEditsWrapped`,T0=`__hfStudioManualEditsPlaybackFrame`,X7t=`center center`;function Z7t(e){return!!e&&typeof e.x==`number`&&typeof e.y==`number`}function Q7t(e){if(!e||typeof e!=`object`)return null;let t=e,n=Array.isArray(e)?e:t.path;if(!Array.isArray(n))return null;let r=n.filter(Z7t).map(e=>({x:e.x,y:e.y}));return r.length<2?null:{coords:r,curviness:typeof t.curviness==`number`?t.curviness:1,autoRotate:typeof t.autoRotate==`number`?t.autoRotate:t.autoRotate===!0,isCubic:t.type===`cubic`}}function $7t(e,t){let n=Q7t(e.motionPath),r=n&&VQe(n.coords,n.curviness,n.autoRotate,n.isCubic);if(!r)return null;let i=r.waypoints.length;return{keyframes:r.waypoints.map((e,t)=>({percentage:i>1?Math.round(t/(i-1)*100):0,properties:{x:e.x,y:e.y}})),arcPath:r.arcPath,runEase:t??sHt}}function E0(e,t){if(!e.targets)return!1;for(let n of e.targets())if(n===t||t.id&&n.id===t.id)return!0;return!1}var D0=null;function e9t(e){let t=D0;D0??=new WeakMap;try{return e()}finally{D0=t}}function t9t(e){let t={byElement:new Map,byId:new Map},n=(e,t,n)=>{let r=e.get(t);r?r.at(-1)!==n&&r.push(n):e.set(t,[n])};for(let r of e)for(let e of r.targets?.()??[]){n(t.byElement,e,r);let i=e.id;i&&n(t.byId,i,r)}return t}function n9t(e,t){if(!e||typeof e!=`object`||!D0)return(e?.getChildren?.(!0)??[]).filter(e=>E0(e,t));let n=D0.get(e);return n||D0.set(e,n=t9t(e.getChildren?.(!0)??[])),(t.id?n.byId.get(t.id):n.byElement.get(t))??[]}var r9t={scale:`scaleX`,rotate:`rotation`};function i9t(e,t){for(let n=e;n;n=n._next){if(n.p===t&&typeof n.s==`number`&&typeof n.c==`number`)return n;let e=i9t(n.d?._pt,t);if(e)return e}return null}function a9t(e,t){let n=i9t(e._pt,r9t[t]??t);if(!n)return null;let r=[n.s,n.s+n.c];return e._from?[r[1],r[0]]:r}function o9t(e,t){let n=t,r=e.keyframes[0];if(!Array.isArray(n.vars?.keyframes)&&!((r?.percentage??0)>0))return e;let i=n.timeline?.getChildren?.()??[n],a={};for(let e of[`x`,`y`,`width`,`height`]){let t=i.map(t=>a9t(t,e)).find(Boolean);t&&(a[e]=t[0])}return Object.entries(a).some(([e,t])=>t!==r?.properties[e])?{...e,start:a}:e}function O0(e,t,n){let r=e?.contentWindow,i=Xq(n);if(!r?.__timelines||i==null)return null;let a=n.keyframes?.keyframes.map(e=>e.properties)??[n.properties],o=[...new Set(a.flatMap(e=>Object.keys(e)))],s=!!n.keyframes;for(let e of Object.values(r.__timelines))for(let n of e?.getChildren?.(!0)??[]){let e=n.targets?.()??[];if(!e.includes(t)&&!e.some(e=>t.id&&e.id===t.id)||!s9t(n,i))continue;let a=n.vars??{};if(!(!(s?`keyframes`in a:o.some(e=>e in a))||!((n.duration?.()??0)>0)))return l9t(r,t,n,o),n}return null}function s9t(e,t){let n=Number(e.vars?.delay)||0;return Math.abs((e.startTime?.()??NaN)-n-t)<=.001}function c9t(e,t){let n=t?.startTime?.();return{...e,...Number.isFinite(n)&&{resolvedStart:n},...e.duration==null&&t&&{duration:t.duration?.()}}}function l9t(e,t,n,r){let i=!u9t(n)&&d9t(e,n);if(!i)return;let{parent:a,gsap:o}=i,s=f9t(n,t),c=a.time(),l=n.startTime?.()??0;o.set(t,{clearProps:r.join(`,`)});for(let e of r)o.getProperty(t,e);try{a.seek(l,!0),a.seek(l+(n.duration?.()??0),!0)}finally{a.seek(c,!0),p9t(s)}}function u9t(e){let t=e.timeline?.getChildren?.()??[];return!!e._initted&&t.every(e=>e._initted)}function d9t(e,t){let{parent:n}=t,r=e.gsap;return!n?.seek||!n.time||!r?.getProperty||!r.set?null:{parent:{seek:n.seek.bind(n),time:n.time.bind(n)},gsap:{getProperty:r.getProperty.bind(r),set:r.set.bind(r)}}}function f9t(e,t){let n=new Set([t]);for(let t of e.parent?.getChildren?.(!0,!0,!1)??[])for(let e of HZ(t))n.add(e);return[...n].map(e=>({layer:e,attributes:new Map([...e.attributes].map(e=>[e.name,e.value])),cache:e._gsap&&{...e._gsap}}))}function p9t(e){for(let{layer:t,attributes:n,cache:r}of e)m9t(t,n),r&&t._gsap&&h9t(t._gsap,r)}function m9t(e,t){for(let{name:n}of[...e.attributes])t.has(n)||e.removeAttribute(n);for(let[n,r]of t)e.getAttribute(n)!==r&&e.setAttribute(n,r)}function h9t(e,t){for(let n of Object.keys(e))n in t||delete e[n];Object.assign(e,t)}function g9t(e){return(t,n)=>{if(!e)return null;for(let r of _9t(e,n)){let e=a9t(r,t);if(e)return n===`start`?e[0]:e[1];if(t in(r.vars??{}))return null}return null}}function _9t(e,t){let n=e.timeline?.getChildren?.()??[];return n.length===0?[e]:t===`start`?n:[...n].reverse()}function v9t(e,t){if(!t)return null;let n=e?.contentWindow,r=t.vars?.ease??t.parent?.vars?.defaults?.ease??n?.gsap?.defaults?.().ease;return typeof r==`string`?r:typeof r==`function`?y9t.find(e=>n?.gsap?.parseEase?.(e)===r)??null:null}var y9t=[`none`,...[`power1`,`power2`,`power3`,`power4`,`sine`,`expo`,`circ`,`back`,`elastic`,`bounce`].flatMap(e=>[`${e}.in`,`${e}.out`,`${e}.inOut`])];function b9t(e,t){let n=e.keyframes,r=t?.timeline?.getChildren?.()??[];if(n?.format!==`object-array`||r.length!==n.keyframes.length)return e;let i=r.map(e=>(e.startTime?.()??0)+(e.duration?.()??0)),a=Math.max(...i);if(!(a>0)||i.some(e=>!Number.isFinite(e)))return e;let o=n.keyframes.map((e,t)=>({...e,percentage:Math.round(i[t]/a*1e5)/1e3}));return{...e,keyframes:{...n,keyframes:o}}}function x9t(e,t){let n=-1;return e.forEach((r,i)=>{let a=Math.abs(r.percentage-t);a<=nJ&&(n<0||a<Math.abs(e[n].percentage-t))&&(n=i)}),n}function S9t(e,t,n){let r=x9t(e.keyframes?.keyframes??[],n);return b9t(e,t).keyframes?.keyframes[r]?.percentage??n}var k0=e=>!!e._gsap?.renderTransform;function C9t(e,t,n){for(let r of t){let t=e.style.getPropertyValue(r);t&&n.push({type:`inline-style`,property:r,value:t})}}function w9t(e,t,n){for(let r of t){let t=e.getAttribute(r);t!==null&&n.push({type:`attribute`,property:r,value:t})}}function T9t(e,t){let n=e.getAttribute(C0);n!==null&&(t.push({type:`inline-style`,property:`display`,value:n||null}),t.push({type:`attribute`,property:C0,value:null}))}function E9t(e){let t=e.getAttribute(r0),n=[{type:`inline-style`,property:nj,value:null},{type:`inline-style`,property:rj,value:null},{type:`inline-style`,property:`translate`,value:t||null},{type:`attribute`,property:Q1,value:null},{type:`attribute`,property:n0,value:null},{type:`attribute`,property:r0,value:null}];return T9t(e,n),n}var A0=[`width`,`height`,`min-width`,`min-height`,`max-width`,`max-height`,`flex-basis`,`flex-grow`,`flex-shrink`,`box-sizing`,`scale`,`transform-origin`,`display`],D9t=[[i0,`width`],[a0,`height`],[o0,``],[s0,``],[c0,`min-width`],[l0,`min-height`],[u0,`max-width`],[d0,`max-height`],[f0,`flex-basis`],[p0,`flex-grow`],[m0,`flex-shrink`],[h0,`box-sizing`],[g0,`scale`],[_0,`transform-origin`],[v0,`display`],[C0,``]];function O9t(e){let t=[];return C9t(e,[ij,aj],t),C9t(e,k0(e)?A0.filter(e=>e!==`scale`):A0,t),t.push({type:`attribute`,property:e0,value:`true`}),w9t(e,D9t.map(([e])=>e),t),t}function k9t(e){let t=[{type:`inline-style`,property:ij,value:null},{type:`inline-style`,property:aj,value:null},{type:`attribute`,property:e0,value:null}];for(let[n,r]of D9t){let i=e.getAttribute(n);i!==null&&r&&t.push({type:`inline-style`,property:r,value:i||null}),t.push({type:`attribute`,property:n,value:null})}return t}function A9t(e){let t=e.getAttribute(b0),n=e.getAttribute(x0),r=[{type:`inline-style`,property:Z1,value:null},{type:`inline-style`,property:`rotate`,value:t||null},{type:`inline-style`,property:`transform-origin`,value:n===null?null:n||null},{type:`attribute`,property:t0,value:null},{type:`attribute`,property:S0,value:null},{type:`attribute`,property:y0,value:null},{type:`attribute`,property:b0,value:null},{type:`attribute`,property:x0,value:null}];return T9t(e,r),r}var j9t=new Set([`ease`,`duration`,`delay`,`stagger`,`motionPath`,`overwrite`,`immediateRender`,`onComplete`,`onUpdate`,`onStart`,`keyframes`]);function j0(e){if(!e?.contentWindow)return null;try{return e.contentWindow.__timelines??null}catch{return null}}function M0(e){return!(e>0)}function M9t(e){let t={};for(let[n,r]of Object.entries(e))j9t.has(n)||(typeof r==`number`?t[n]=S(r):typeof r==`string`&&(t[n]=r));return Object.keys(t).length===0?null:[{percentage:0,properties:t},{percentage:100,properties:t}]}var N9t=e=>typeof e==`string`?e:void 0;function N0(e){let t=N9t(e.ease);if(e.keyframes&&typeof e.keyframes==`object`){let n=SHt(e.keyframes),r=N9t(e.keyframes.ease);if(n)return{...n,runEase:r??t}}let n=$7t(e,t);if(n)return n;let r=M9t(e);return r?{keyframes:r}:null}function P9t(e){let t=typeof e.startTime==`function`?e.startTime():0,n=typeof e.duration==`function`?e.duration():0;return{start:Number.isFinite(t)?t:0,duration:Number.isFinite(n)?n:0}}function F9t(e,t){if(!e)return!1;for(let n of t)if(Object.prototype.hasOwnProperty.call(e,n))return!0;return!1}function P0(e,t){let n=e?.keyframes;return!n||typeof n!=`object`?!1:!Array.isArray(n)&&t.some(e=>Object.prototype.hasOwnProperty.call(n,e))?!0:(Array.isArray(n)?n:Object.values(n)).some(e=>typeof e==`object`&&!!e&&t.some(t=>Object.prototype.hasOwnProperty.call(e,t)))}function I9t(e,t,n,r,i){let a=j0(e);if(!a)return null;let o=null;try{o=e?.contentDocument?.querySelector(t)??null}catch{return null}if(!o)return null;let s=r?[r]:Object.keys(a).filter(e=>typeof a[e]?.getChildren==`function`),c=i&&i.length>0?i:null,l=null,u=null;for(let e of s){let t=a[e];if(!t?.getChildren)continue;let r=typeof t.time==`function`?t.time():null;for(let e of t.getChildren(!0)){if(!e.vars||!E0(e,o))continue;let i=typeof e.duration==`function`?e.duration():0,a=!(i>0);if(!(n===`set`?!a:a)){if(c){(n===`set`?F9t(e.vars,c):P0(e.vars,c))?u===null&&(u={tween:e,timeline:t}):l===null&&(l={tween:e,timeline:t});continue}if(l===null&&(l={tween:e,timeline:t}),n===`keyframe`&&r!=null){let n=typeof e.startTime==`function`?e.startTime():0;if(r>=n-.001&&r<=n+i+.001)return{tween:e,timeline:t}}}}}return u??l}function L9t(e,t){return e.keyframes.some(e=>t.some(t=>e.properties[t]!=null))}function F0(e,t,n,r){let i=j0(e);if(!i)return null;let a=null;try{a=e?.contentDocument?.querySelector(t)??null}catch{return null}if(!a)return null;let o=n?[n]:Object.keys(i).filter(e=>typeof i[e]?.getChildren==`function`);if(o.length===0)return null;let s=null;for(let e of o){let t=i[e];if(!t?.getChildren)continue;let n=typeof t.time==`function`?t.time():null;for(let e of t.getChildren(!0)){if(!e.vars||!E0(e,a))continue;let t=typeof e.duration==`function`?e.duration():0;if(M0(t))continue;let i=N0(e.vars);if(i&&!(r&&!L9t(i,r))&&(s===null&&(s=o9t(i,e)),n!=null)){let r=typeof e.startTime==`function`?e.startTime():0;if(n>=r-.001&&n<=r+t+.001)return o9t(i,e)}}}return s}function I0(e,t,n,r){let i=null;try{i=e?.contentDocument?.querySelector(t)??null}catch{return!1}return!!i&&q9t(j0(e),i,r,n)}var L0=[`x`,`y`,`xPercent`,`yPercent`,`left`,`top`,`translateX`,`translateY`],R9t=[...L0,`motionPath`],z9t=new Set(`x,y,z,scale,scaleX,scaleY,xPercent,yPercent,rotation,rotationX,rotationY,skewX,skewY,transformOrigin,svgOrigin,force3D,smoothOrigin,transformPerspective,translateX,translateY,translateZ,rotate,rotationZ,rotateZ,rotateX,rotateY`.split(`,`));function R0(e,t){let n=e.ownerDocument.defaultView;return Object.values(n?.__timelines??{}).some(n=>n9t(n,e).some(e=>!!e.vars&&(t.some(t=>t in e.vars)||P0(e.vars,t))))}var z0=[`rotation`,`rotationX`,`rotationY`,`rotationZ`,`rotate`,`rotateX`,`rotateY`,`rotateZ`];function B9t(e){return k0(e)||R0(e,R9t)}function V9t(e){return k0(e)||R0(e,z0)}function H9t(e){let t=e._gsap;return[`x`,`y`,`xPercent`,`yPercent`].some(e=>!!Number.parseFloat(String(t?.[e])))}var U9t=[...A0.map(e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())),`scaleX`,`scaleY`];function W9t(e){return B9t(e)||R0(e,U9t)}var G9t={move:B9t,resize:W9t,rotate:V9t};function B0(e,t){return!G9t[t](e)}function K9t(e,t){let n=e.ownerDocument.defaultView;return q9t(n?.__timelines??null,e,t)}function q9t(e,t,n,r){if(!e)return!1;for(let i of r?[r]:Object.keys(e))for(let r of n9t(e[i],t)){if(!r.vars||M0(typeof r.duration==`function`?r.duration():0))continue;if(n&&P0(r.vars,n))return!0;let e=N0(r.vars);if(e&&(!n||L9t(e,n)))return!0}return!1}function J9t(e,t,n,r){let{keyframes:i,runEase:a}=e;return!r||r.duration<=0?i:i.map(e=>{let i=CHt(t,n,qq(a,e.percentage));return{...e,percentage:Math.round((i-r.start)/r.duration*1e5)/1e3}})}function Y9t(e,t,n,r){return{keyframes:J9t(e,t,n,r),tweenStart:t,tweenDuration:n,...e.easeEach?{easeEach:e.easeEach}:{},...e.arcPath?{arcPath:e.arcPath}:{}}}function X9t(e,t,n){if(!t.targets||!t.vars)return;let{start:r,duration:i}=P9t(t);if(M0(i))return;let a=N0(t.vars);if(a)for(let o of t.targets()){let t=o.id;t&&!e.has(t)&&e.set(t,Y9t(a,r,i,n?.get(t)))}}function Z9t(e,t){let n=new Map,r=j0(e);if(!r)return n;for(let e of Object.values(r))if(e?.getChildren)for(let r of e.getChildren(!0))X9t(n,r,t);return n}function V0(e){let t=[],n=0,r=``;for(let i of e.trim())i===`(`&&(n+=1),i===`)`&&(n=Math.max(0,n-1)),/\s/.test(i)&&n===0?(r&&t.push(r),r=``):r+=i;return r&&t.push(r),t}var Q9t=0,$9t=[`translate`,nj,rj],een={move:$9t,resize:[...$9t,ij,aj,...A0],rotate:[`rotate`,`transform`,`transform-origin`,`display`,Z1],edit:[]};function H0(e,t,n){Q9t+=1;let r=`gesture-${Q9t}:${t}`;return e.setAttribute(oj,r),n?e.setAttribute($1,JSON.stringify(n)):e.removeAttribute($1),r}var U0=`hf-manual-edit-gesture-ended`;function W0(e,t){if(t&&e.getAttribute(`data-hf-studio-manual-edit-gesture`)!==t||!e.hasAttribute(`data-hf-studio-manual-edit-gesture`))return;e.removeAttribute(oj),e.removeAttribute($1);let n=e.ownerDocument;n.dispatchEvent(new((n.defaultView?.Event)??Event)(U0))}function G0(e){return e.querySelector(`[${oj}]`)!==null}function ten(e,t){let n=()=>{G0(e)||(r(),t())},r=()=>e.removeEventListener(U0,n);return e.addEventListener(U0,n),r}var nen=new WeakMap;function ren(e){return nen.get(e)??0}function K0(e){nen.set(e,ren(e)+1)}function q0(e,t){let n=e.ownerDocument,r=()=>K0(n);r();let i=t();return Promise.resolve(i).then(r,r),i}function ien(e){let t=e.getAttribute(oj);return t===null?null:een[t.split(`:`)[1]]??[]}function aen(e){return e.hasAttribute(oj)}function J0(e,t){return e.getAttribute(oj)===t}function Y0(e,t){let n=Number.parseFloat(e.style.getPropertyValue(t));return Number.isFinite(n)?n:0}function oen(e){return{x:Y0(e,nj),y:Y0(e,rj)}}function sen(e){return(e.style.translate||``).includes(`--hf-studio-offset-x`)?oen(e):{x:0,y:0}}function X0(e){return{width:Y0(e,ij),height:Y0(e,aj)}}function cen(e){let t=Number.parseFloat(e.style.getPropertyValue(Z1));return{angle:Number.isFinite(t)?t:0}}function Z0(e,t){try{return e.ownerDocument.defaultView?.getComputedStyle(e).getPropertyValue(t)??``}catch{return``}}function Q0(e,t){return e.style.getPropertyValue(t)||Z0(e,t)}function len(e,t){let n=Q0(e,t).trim();return n===`none`?``:n}function $0(e){return e.includes(`--hf-studio-offset-x`)||e.includes(`--hf-studio-offset-y`)}function uen(e){return e.includes(`--hf-studio-width`)||e.includes(`--hf-studio-height`)}function e2(e){return e.includes(Z1)}function den(e){return e.replace(/\s+/g,``).toLowerCase()}function fen(e,t){if(!e.hasAttribute(S0))return!1;let n=e.style.getPropertyValue(Z1).trim();return!n||!t.trim()?!1:den(t)===den(Oen(e,n))}function t2(e){Z0(e,`display`)===`inline`&&(e.hasAttribute(C0)||e.setAttribute(C0,e.style.getPropertyValue(`display`)),e.style.setProperty(`display`,`inline-block`))}function n2(e){let t=e.getAttribute(C0);t!=null&&(t===``?e.style.removeProperty(`display`):e.style.setProperty(`display`,t),e.removeAttribute(C0))}function pen(e,t,n){let r=e.getAttribute(n0)?.trim();if(!r||r===`none`)return`${t} ${n}`;let i=V0(r);return i.length===1?`calc(${i[0]} + ${t}) ${n}`:i.length===2?`calc(${i[0]} + ${t}) calc(${i[1]} + ${n})`:i.length===3?`calc(${i[0]} + ${t}) calc(${i[1]} + ${n}) ${i[2]}`:`${t} ${n}`}function men(e,t){let n=e.style.getPropertyValue(`translate`),r=len(e,`translate`),i=e.hasAttribute(Q1),a=!$0(r);i?t&&a&&!aen(e)&&e.setAttribute(n0,r):(e.setAttribute(r0,$0(n)?``:n),e.setAttribute(n0,a?r:``))}function hen(e,t,n={}){men(e,n.updateBase??!0),e.setAttribute(Q1,`true`),e.style.setProperty(nj,`${S(t.x)}px`),e.style.setProperty(rj,`${S(t.y)}px`)}function gen(e){return e.is2D&&e.a===1&&e.b===0&&e.c===0&&e.d===1}function _en(e){if(e.hasAttribute(`data-hf-studio-manual-edit-gesture`))return;let t=e.style.getPropertyValue(`transform`);if(!t||t===`none`)return;let n=e.ownerDocument.defaultView?.DOMMatrix;if(n)try{let r=new n(t);if(r.m41===0&&r.m42===0)return;let i=Y0(e,nj),a=Y0(e,rj),o=Math.atan2(r.b,r.a),s=Math.cos(o),c=Math.sin(o);r.m41-=i*s-a*c,r.m42-=i*c+a*s,Math.abs(r.m41)<.01&&Math.abs(r.m42)<.01&&gen(r)?e.style.removeProperty(`transform`):e.style.setProperty(`transform`,r.toString())}catch{}}function ven(e,t){if(!R0(e,[`x`,`y`]))return!1;e.style.setProperty(`translate`,`none`);let n=e.ownerDocument.defaultView;if(n?.gsap){let r=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-x`)??``),i=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-y`)??``),a=Number.parseFloat(e.getAttribute(`data-hf-drag-initial-offset-x`)??``),o=Number.parseFloat(e.getAttribute(`data-hf-drag-initial-offset-y`)??``),s=Number.isFinite(r)?r:n.gsap.getProperty(e,`x`),c=Number.isFinite(i)?i:n.gsap.getProperty(e,`y`);Number.isFinite(r)||e.setAttribute(`data-hf-drag-gsap-base-x`,String(s)),Number.isFinite(i)||e.setAttribute(`data-hf-drag-gsap-base-y`,String(c));let l=t.x-(Number.isFinite(a)?a:0),u=t.y-(Number.isFinite(o)?o:0);n.gsap.set(e,{x:s+l,y:c+u})}return!0}function yen(e,t,n={}){t2(e),hen(e,t,{updateBase:n.updateBase??!0}),!ven(e,t)&&(e.style.setProperty(`translate`,pen(e,`var(${nj}, 0px)`,`var(${rj}, 0px)`)),_en(e))}function ben(e,t){t2(e),hen(e,t,{updateBase:!1}),!ven(e,t)&&(e.style.setProperty(`translate`,pen(e,`${S(t.x)}px`,`${S(t.y)}px`)),_en(e))}function xen(e,t){let n=e.parentElement;if(!n)return null;let r=Q0(n,`display`).trim();if(r!==`flex`&&r!==`inline-flex`)return null;let i=Q0(n,`flex-direction`).trim();return le(Math.max(1,i.startsWith(`column`)?t.height:t.width))}function Sen(e){if(!e.hasAttribute(g0))return;let t=e.getAttribute(g0);t==null||t===``?e.style.removeProperty(`scale`):e.style.setProperty(`scale`,t),e.removeAttribute(g0);let n=e.getAttribute(_0);n==null||n===``?e.style.removeProperty(`transform-origin`):e.style.setProperty(`transform-origin`,n),e.removeAttribute(_0)}function Cen(e,t){e.hasAttribute(o0)||e.setAttribute(o0,String(e.offsetWidth)),e.hasAttribute(s0)||e.setAttribute(s0,String(e.offsetHeight)),e.hasAttribute(e0)||(e.setAttribute(i0,e.style.getPropertyValue(`width`)),e.setAttribute(a0,e.style.getPropertyValue(`height`)),e.setAttribute(c0,e.style.getPropertyValue(`min-width`)),e.setAttribute(l0,e.style.getPropertyValue(`min-height`)),e.setAttribute(u0,e.style.getPropertyValue(`max-width`)),e.setAttribute(d0,e.style.getPropertyValue(`max-height`)),e.setAttribute(f0,e.style.getPropertyValue(`flex-basis`)),e.setAttribute(p0,e.style.getPropertyValue(`flex-grow`)),e.setAttribute(m0,e.style.getPropertyValue(`flex-shrink`)),e.setAttribute(h0,e.style.getPropertyValue(`box-sizing`)),e.setAttribute(g0,e.style.getPropertyValue(`scale`)),e.setAttribute(_0,e.style.getPropertyValue(`transform-origin`)),e.setAttribute(v0,e.style.getPropertyValue(`display`))),e.setAttribute(e0,`true`),e.style.setProperty(ij,`${le(Math.max(1,t.width))}px`),e.style.setProperty(aj,`${le(Math.max(1,t.height))}px`)}function wen(e,t){Cen(e,t),Sen(e);let n=le(Math.max(1,t.width)),r=le(Math.max(1,t.height));e.style.setProperty(`box-sizing`,`border-box`),e.style.setProperty(`width`,`${n}px`),e.style.setProperty(`height`,`${r}px`),e.style.setProperty(`min-width`,`0px`),e.style.setProperty(`min-height`,`0px`),e.style.setProperty(`max-width`,`none`),e.style.setProperty(`max-height`,`none`);let i=xen(e,t);i!=null&&(e.style.setProperty(`flex-basis`,`${i}px`),e.style.setProperty(`flex-grow`,`0`),e.style.setProperty(`flex-shrink`,`0`)),Z0(e,`display`)===`inline`&&e.style.setProperty(`display`,`inline-block`)}function r2(e,t){t2(e),wen(e,t)}var i2=new WeakMap;function Ten(e){return i2.get(e)??null}function a2(e){i2.delete(e)}function Een(e,t){i2.has(e)||i2.set(e,{width:e.offsetWidth,height:e.offsetHeight}),t2(e),wen(e,t)}function Den(e){return/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|rad|turn|grad)$/.test(e.trim())}function Oen(e,t){let n=e.getAttribute(y0)?.trim();return!n||n===`none`||!Den(n)?t:`calc(${n} + ${t})`}function ken(e,t){let n=e.style.getPropertyValue(`rotate`),r=len(e,`rotate`),i=e.hasAttribute(t0),a=!e2(r)&&!fen(e,r);i?t&&a&&!aen(e)&&e.setAttribute(y0,r):(e.setAttribute(b0,e2(n)?``:n),e.setAttribute(y0,a?r:``)),e.hasAttribute(x0)||e.setAttribute(x0,e.style.getPropertyValue(`transform-origin`))}function Aen(e,t,n={}){ken(e,n.updateBase??!0),e.setAttribute(t0,`true`),e.style.setProperty(Z1,`${S(t.angle)}deg`),e.style.setProperty(`transform-origin`,X7t)}function jen(e,t){t2(e),Aen(e,t),e.removeAttribute(S0),e.style.setProperty(`rotate`,Oen(e,`var(${Z1}, 0deg)`))}function o2(e){let t=null;return(n,r={})=>{if(t===null)try{t=localStorage.getItem(`hf-${e}-debug`)===`1`}catch{t=!1}if(!t)return;let i=typeof r==`function`?r():r;i&&console.log(`[hf-${e}] ${JSON.stringify({stage:n,t:Math.round(performance.now()),...i})}`)}}var s2=o2(`reload`),Men=!1,c2=!1,l2=0,u2=!1,d2=()=>Men||c2||l2>0,f2=()=>{d2()||(u2=!1)};function Nen(){u2=d2()}function p2(e){Men=e,YX.setPreviewReloading(e),f2()}function Pen(){c2=!0}function Fen(){c2=!1,f2()}async function m2(e){l2+=1;try{return await e()}finally{--l2,f2()}}function Ien(){return d2()&&!u2}var h2=`hf-scenes-swapped`,Len=5e3;function g2(e,t){return e.addEventListener(`load`,t),e.addEventListener(h2,t),()=>{e.removeEventListener(`load`,t),e.removeEventListener(h2,t)}}var _2=`hf-preview-promoted`;function Ren(e){e.live.ownerDocument.dispatchEvent(new CustomEvent(_2,{detail:e}))}function zen(e,t){let n=e=>t(e.detail);return e.addEventListener(_2,n),()=>e.removeEventListener(_2,n)}function Ben(e,t){let n=e?.contentDocument,r=n?.querySelector(`meta[name="hf-scene-parts"]`);if(!n||!r)return;let i;try{i=JSON.parse(r.content)}catch{return}for(let e of t){let t=n.querySelectorAll(`[data-composition-file="${CSS.escape(e)}"]`);t.length===0&&e.endsWith(`.html`)&&(i.shared=``);for(let e of t){let t=e.closest(`[data-hf-scene]`)?.getAttribute(`data-hf-scene`);t&&t in i.scenes&&(i.scenes[t]=``)}}r.content=JSON.stringify(i)}function Ven(e){let t=e.contentWindow,n=t?.__hfSwapScenes;return typeof n==`function`?async(r,i,a)=>{if(a?.aborted)throw a.reason;let o=new AbortController,s=setTimeout(()=>o.abort(Error(`the preview took too long to swap`)),Len);a?.addEventListener(`abort`,()=>o.abort(a.reason),{once:!0});let c=(async()=>{let e=await H(r,{signal:o.signal});if(!e.ok)throw Error(`preview request failed with ${e.status}`);let a=await e.text();if(!i())throw Error(`superseded by a newer reload`);await n.call(t,a,o.signal)})(),l=new Promise((e,t)=>o.signal.addEventListener(`abort`,()=>t(o.signal.reason)));try{await Promise.race([c,l])}finally{clearTimeout(s)}e.dispatchEvent(new Event(h2))}:null}var Hen=15e3,Uen=3;function Wen(e){return(e?.contentWindow)?.__hfWaitForSeekCompletion?.().catch(()=>{})}function Gen(){return typeof document<`u`&&document.visibilityState===`hidden`}function Ken({iframeRef:e,getAdapter:t,pendingSeekRef:n,isRefreshingRef:r,syncTimelineElements:i,setDuration:a,setCurrentTime:o,requestTimelineReady:s,setIsPlaying:c,attachIframeShortcutListeners:l,applyPreviewAudioState:u,onPromoted:d,onReloadFailed:f,handOverPlayback:p}){let m=(0,U.useRef)(null),h=(0,U.useRef)(void 0),g=(0,U.useRef)(0),_=(0,U.useRef)(null),v=(0,U.useRef)(null),y=(0,U.useRef)(d);y.current=d;let b=(0,U.useRef)(f);b.current=f;let x=(0,U.useRef)(p);x.current=p;let S=(0,U.useRef)(void 0),C=(0,U.useRef)(0),w=(0,U.useRef)(null),T=(0,U.useRef)(()=>{}),E=(0,U.useRef)(()=>{}),D=(0,U.useRef)(``),O=(0,U.useRef)(0),k=(0,U.useRef)(()=>{}),A=(0,U.useRef)(()=>{}),[j,M]=(0,U.useState)([{gen:0,role:`live`}]),N=(0,U.useCallback)(()=>{clearTimeout(S.current),w.current=null,T.current(),E.current(),_.current=null,v.current=null},[]),P=(0,U.useCallback)((e,t)=>{if(e!==g.current)return;g.current+=1,N(),m.current=null,r.current=!1,n.current=null,M(G7t),p2(!1);let i=`The preview did not reload (${t}). The previous preview is still showing.`;s2(`shadow-failed`,{cause:t}),console.error(`[studio] ${i}`),b.current?.(i)},[N,r,n]),F=(0,U.useCallback)(()=>{let t=e.current?.contentDocument;return t?ren(t):0},[e]),I=(0,U.useCallback)((e,t,n)=>(clearTimeout(S.current),w.current=null,E.current(),s2(`shadow-held`,{gen:e,why:t}),E.current=n(()=>{s2(`shadow-hold-ended`,{gen:e,why:t}),A.current(e)}),!0),[]),L=(0,U.useCallback)(t=>{let n=e.current?.contentDocument;if(n&&G0(n))return I(t,`gesture`,e=>ten(n,e));if(F()===O.current)return!1;if(WKt())return I(t,`save`,GKt);s2(`shadow-reloaded-after-gesture-save`,{gen:t});let r=new URL(D.current,window.location.origin);return r.searchParams.set(`_t`,String(Date.now())),k.current(r.toString()),!0},[e,F,I]),R=(0,U.useCallback)(e=>{let t=m.current,n=_.current,r=n?.gen===e&&v.current===e;return t&&n&&r&&e===g.current?{shadow:t,pending:n}:null},[]),z=(0,U.useCallback)(n=>{let r=R(n);if(!r||L(n))return;let{shadow:i,pending:a}=r;N();let o=t(),s=o?.getTime(),c=X.getState().isPlaying;o?.pause();let d=e.current;e.current=i,a.commit(),m.current=null,l(),u(),M(e=>K7t(e,n)),s!=null&&x.current(s,c),Ren({retired:d,live:i}),y.current?.(),p2(!1)},[N,R,L,t,e,l,u]);A.current=z;let B=(0,U.useCallback)(()=>t(m.current),[t]),V=(0,U.useCallback)(e=>e===g.current,[]),ee=(0,U.useCallback)(()=>g.current,[]),{onIframeLoad:te,cancelPendingLoad:H}=J7t({iframeRef:m,probeIntervalRef:h,pendingSeekRef:n,isRefreshingRef:r,getAdapter:B,syncTimelineElements:i,setDuration:a,setCurrentTime:o,requestTimelineReady:s,setIsPlaying:c,attachIframeShortcutListeners:()=>{},applyPreviewAudioState:()=>{},onAdapterReady:(0,U.useCallback)((e,t,n)=>{if(t==null||t!==g.current)return;let r=()=>{t===g.current&&(_.current={gen:t,commit:n},z(t))},i=Wen(e);i?i.then(r):r()},[z]),isCurrent:V});T.current=H;let ne=(0,U.useCallback)((e,t)=>{e===g.current&&(v.current=t?e:null,t&&z(e))},[z]),re=(0,U.useCallback)(e=>{m.current=e},[]),ie=(0,U.useCallback)(e=>{clearTimeout(S.current),!Gen()&&(S.current=setTimeout(()=>{if(e===g.current){if(C.current+=1,C.current<Uen){s2(`shadow-slow`,{budgetsSpent:C.current}),ae.current(e);return}P(e,`it took too long to load`)}},Hen))},[P]),ae=(0,U.useRef)(ie);ae.current=ie;let oe=(0,U.useCallback)(e=>{g.current+=1;let t=g.current;N(),w.current=t,C.current=0,D.current=e,O.current=F(),ie(t),M(n=>W7t(n,t,e)),p2(!0)},[N,ie,F]);k.current=oe;let se=(0,U.useCallback)(()=>{g.current+=1,N(),m.current=null,r.current=!1,n.current=null,X.getState().setTimelineReady(!1),M(G7t),p2(!1)},[N,r,n]);return ax(()=>{let e=()=>{if(Gen()){clearTimeout(S.current);return}let e=w.current;e!=null&&e===g.current&&ae.current(e)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e),N(),p2(!1)}}),{previewSlots:j,onShadowIframeLoad:te,onShadowReadyChange:ne,onShadowError:P,setShadowIframeNode:re,beginShadowReload:oe,resetPreviewSlots:se,previewGeneration:ee}}function qen(e,t,n){let r=null;for(let i of Jen(e,t)){let e=Ie(i);if(e>0&&n<=e)return{match:i,fallback:r};e>0&&(r??=i)}return{match:null,fallback:r}}function*Jen(e,t){t.__timeline&&(yield fe(t.__timeline));let n=t.__timelines?Object.keys(t.__timelines):[];if(!t.__timelines||n.length===0)return;let r=e.contentDocument?.querySelector(`[data-composition-id]`)?.getAttribute(`data-composition-id`),i=r&&r in t.__timelines?r:n[n.length-1];yield fe(t.__timelines[i])}function Yen(e,t,n){let r=t.__player&&typeof t.__player.play==`function`?t.__player:null,i=nn(e.contentDocument),a=Ie(r);if(a>0&&i<=a)return ln(n.cache,n.warned),r;let o=qen(e,t,i);if(o.match)return ln(n.cache,n.warned),o.match;let s=o.fallback,c=r??s,l=Math.max(X.getState().duration,i,a);return c&&l>0&&(`renderSeek`in c||typeof c.seek==`function`)?on({cache:n.cache,warned:n.warned,bestAdapter:c,effectiveDuration:l,docDuration:i,clock:Ne(t),getPlaybackRate:()=>X.getState().playbackRate}):c}function Xen({rafRef:e,reverseRafRef:t,getAdapter:n,setCurrentTime:r,setIsPlaying:i,setLoopStart:a}){let o=(0,U.useCallback)(()=>{cancelAnimationFrame(t.current)},[t]);return{startRAFLoop:(0,U.useCallback)(()=>{let t=()=>{let o=n();if(o){let n=o.getTime(),s=o.getDuration(),c=s>0?Math.min(n,s):n;Lb.notify(c);let{inPoint:l,outPoint:u}=X.getState(),d=u===null?s:Math.min(u,s),f=l===null?0:l,p=f<d?d:s,m=f<d?f:0,h=X.getState().loopEnabled&&s>0;if(a(h?m:null),c>=p){if(h&&!X.getState().playLocked){o.seek(m,{keepPlaying:!0}),Lb.notify(m),o.play(),i(!0),e.current=requestAnimationFrame(t);return}o.isPlaying()&&o.pause(),r(c),i(!1),cancelAnimationFrame(e.current);return}}e.current=requestAnimationFrame(t)};e.current=requestAnimationFrame(t)},[e,n,r,i,a]),stopRAFLoop:(0,U.useCallback)(()=>{cancelAnimationFrame(e.current)},[e]),stopReverseLoop:o}}function Zen(e,t){let n=X.getState(),r=LG(n.elements).musicElement;if(!r||n.audioMuted)return;let i=t-r.start;u7t(e,i>=0&&i<=r.duration?(r.playbackStart??0)+i:null,r,n.audioVolume)}var v2=1e3,Qen=!1,$en=Object.freeze({"dense-short":{duration:120,clipDuration:1.5},"long-overlap":{duration:7200,clipDuration:120},"keyframe-heavy-expanded":{duration:600,clipDuration:8},"composition-heavy":{duration:900,clipDuration:12},"remote-unsupported":{duration:900,clipDuration:12}});function etn(e){Qen=e}function ttn(){return Qen}function ntn(e){if(e.elementCount!==1e3&&e.elementCount!==5e4)throw RangeError(`Timeline performance fixture elementCount must be 1000 or 50000`);if(!Object.hasOwn($en,e.profile))throw RangeError(`Unknown timeline performance fixture profile: ${e.profile}`);return $en[e.profile]}function rtn(e,t){if(e<v2)return e;if(t.profile!==`dense-short`)return e%v2;let n=Math.ceil((t.elementCount-v2)/127);return(e-v2)%Math.max(1,n)}function itn(e,t,n,r){let i=Math.max(0,n-r);return t===`dense-short`?e%128*.5:t===`long-overlap`?e*37%Math.max(1,i):e*17%Math.max(1,i)}function atn(){return{format:`percentage`,keyframes:[0,33,66,100].map(e=>({percentage:e,propertyGroup:`position`,properties:{x:e},ease:`power2.inOut`}))}}function otn(e,t,n){return{id:`animation-${e}`,targetSelector:`#${e}`,method:`to`,position:t,resolvedStart:t,duration:n,propertyGroup:`position`,fromProperties:{x:0},properties:{x:100},ease:`power2.inOut`}}function stn(e){let t=ntn(e),n=[],r=new Map,i=new Map,a=new Set;for(let o=0;o<e.elementCount;o+=1){let s=`perf-${e.profile}-${e.elementCount}-${o}`,c=itn(o,e.profile,t.duration,t.clipDuration),l=rtn(o,e),u={id:s,key:s,domId:s,selector:`#${s}`,label:`Fixture ${o+1}`,tag:e.profile===`remote-unsupported`&&o%2==0?`video`:`div`,start:c,duration:t.clipDuration,track:l,authoredTrack:l};e.profile===`composition-heavy`?u.compositionSrc=`compositions/perf-${o%32}.html`:e.profile===`remote-unsupported`&&(u.src=o%2==0?`https://media.invalid/perf-${o%32}.mp4`:`assets/perf-${o%32}.unsupported`),e.profile===`keyframe-heavy-expanded`&&(r.set(s,atn()),i.set(s,[otn(s,c,t.clipDuration)]),a.add(s)),n.push(u)}return{summary:Object.freeze({...e,duration:t.duration,trackCount:v2,keyframedElementCount:r.size,expandedElementCount:a.size}),elements:n,keyframeCache:r,gsapAnimations:i,expandedClipIds:a}}var y2=new Map,b2=new Map,x2=new Map,S2=0,C2=0,w2=0,ctn=[],T2=null;async function ltn(){if(T2===!1)return null;if(T2)return T2;try{return T2=await Mb(()=>import(`./src-DDA8OuTJ.js`),__vite__mapDeps([2,1,3])),T2}catch{return T2=!1,null}}function E2(e){try{return new URL(e,window.location.href).href}catch{return e}}async function utn(e){let t=await ltn();if(!t)return null;let n=new t.Input({source:new t.UrlSource(e),formats:t.ALL_FORMATS});try{let e=await n.getDurationFromMetadata();if(e==null||!Number.isFinite(e)||e<=0)return null;let t=await n.getPrimaryVideoTrack(),r=await n.getAudioTracks();return{duration:e,width:t?.displayWidth,height:t?.displayHeight,hasVideo:t!=null,hasAudio:r.length>0}}catch{return null}finally{n.dispose()}}function D2(e){let t=y2.get(E2(e));return t&&(t.lastAccess=++S2),t?.result}function dtn(e,t){return t?P$(e,t,window.location.origin):e}function ftn(){let e=y2.size+x2.size-iK.metadataRegistryEntries;if(e<=0)return;let t=[...Array.from(y2,([e,t])=>({key:e,at:t.lastAccess,failed:!1})),...Array.from(x2,([e,t])=>({key:e,at:t.lastAccess,failed:!0}))].sort((e,t)=>e.at-t.at);for(let n of t.slice(0,e))n.failed?x2.delete(n.key):y2.delete(n.key)}function ptn(e,t){return e.map(e=>{let n=e.tag.toLowerCase();if(!e.src||e.sourceDuration!=null||n!==`audio`&&n!==`video`)return e;let r=D2(dtn(e.src,t));return r?.duration&&r.duration>0?{...e,sourceDuration:r.duration}:e})}async function mtn(e,t,n){let r=e.flatMap(e=>{if(!e.src||e.sourceDuration!=null||![`video`,`audio`].includes(e.tag.toLowerCase()))return[];let n=dtn(e.src,t);return!D2(n)&&!htn(E2(n))?[{el:e,source:n}]:[]});r.length!==0&&await Promise.allSettled(r.map(async({el:e,source:t})=>{let r=await gtn(t);r&&n(e.key??e.id,r.duration)}))}function htn(e){let t=x2.get(e);return t===void 0?!1:Date.now()-t.failedAt<iK.metadataFailureTtlMs?(t.lastAccess=++S2,!0):(x2.delete(e),!1)}async function gtn(e){let t=E2(e),n=D2(t);if(n)return n;if(htn(t))return null;let r=b2.get(t);return r||(r=new Promise(e=>{ctn.push({key:t,epoch:w2,resolve:e}),_tn()}),b2.set(t,r),r)}function _tn(){for(;C2<iK.concurrentMetadataJobs;){let e=ctn.shift();if(!e)return;if(e.epoch!==w2){e.resolve(null);continue}C2++,utn(e.key).then(t=>e.epoch===w2?(b2.delete(e.key),t?y2.set(e.key,{result:t,lastAccess:++S2}):x2.set(e.key,{failedAt:Date.now(),lastAccess:++S2}),ftn(),t):null).then(e.resolve).finally(()=>{C2--,_tn()})}}function vtn(e){return!e.playLocked&&e.keepPlaying&&!e.wasReverseShuttle&&e.storeWasPlaying&&(e.duration<=0||e.nextTime<e.duration)}function ytn(e){return!e.keepPlaying||e.wasReverseShuttle}function btn(e,t){return!!(e.source&&t&&e.source!==t.contentWindow)}function xtn(e,t){if(ttn()||btn(e,t))return null;let n=e.data;return n?.source===`hf-preview`&&R1(n)?n:null}function Stn(e,t){try{if(X.getState().elements.length===0){let n=t?.contentWindow?.__clipManifest;n&&n.clips.length>0&&e.processTimelineMessageRef.current(n)}Date.now()-e.lastTimelineMessageRef.current>500&&e.enrichMissingCompositionsRef.current()}catch{}}function Ctn(e,t,n){if(e.lastTimelineMessageRef.current=Date.now(),e.processTimelineMessageRef.current(n),e.enrichMissingCompositionsRef.current(),!(X.getState().elements.length>0))try{let n=t?.contentDocument,r=e.getAdapter();if(!n||!r)return;let i=q1(n,r.getDuration());i.length>0&&e.syncTimelineElements(i)}catch{}}function wtn(e){return t=>{let n=e.iframeRef.current,r=xtn(t,n);if(r){if(r.type===`state`)return Stn(e,n);r.type===`timeline`&&Array.isArray(r.clips)&&Ctn(e,n,r)}}}var Ttn=[`id`,`start`,`duration`,`track`,`sourceDuration`,`muted`,`hasAudio`,`volume`,`playbackRate`,`hidden`,`audioGroup`,`audioGroupVolume`,`audioGroupHidden`,`fadeIn`,`fadeOut`,`src`,`link`];function Etn(e,t){return t.length!==e.length||t.some((t,n)=>{let r=e[n];return!r||Ttn.some(e=>t[e]!==r[e])||!u(t.text,r.text)})}var Dtn=(e,t)=>t?.follow===!1?Lb.notify(e):Lb.notifySeek(e);function Otn({onShadowPromoted:e,onPreviewReloadFailed:t}={}){let n=(0,U.useRef)(null),r=(0,U.useRef)(0),i=(0,U.useRef)(void 0),a=(0,U.useRef)(null),o=(0,U.useRef)(!1),s=(0,U.useRef)(0),c=(0,U.useRef)(null),l=(0,U.useRef)(0),u=(0,U.useRef)(null),d=(0,U.useRef)(0),f=(0,U.useRef)(null),p=(0,U.useRef)(!1),{setIsPlaying:m,setCurrentTime:h,setDuration:g,requestTimelineReady:_,setElements:v}=X.getState(),y=(0,U.useCallback)((e,t)=>{if(ttn())return;let r=X.getState(),i=t??r.duration,a=cKt(ptn(x7t(r.elements,e,r.duration,i,e=>vQ(n.current,{...e,kind:`composition`})!==null),r.timelineProjectId));Etn(r.elements,a)&&v(a),Number.isFinite(t)&&(t??0)>0&&t!==r.duration&&g(t??0),r.timelineReady||_(X1(n.current)),mtn(a,r.timelineProjectId,(e,t)=>{X.setState(n=>{let r=n.elements.findIndex(t=>(t.key??t.id)===e);if(r===-1||n.elements[r].sourceDuration!=null)return{};let i=n.elements.slice();return i[r]={...n.elements[r],sourceDuration:t},{elements:i}})})},[v,_,g]),b=(0,U.useCallback)(e=>{try{let t=e===void 0?n.current:e,r=t?.contentWindow;return!t||!r?null:dVt(Yen(t,r,{cache:f,warned:p}))}catch{return null}},[]),{startRAFLoop:x,stopRAFLoop:S,stopReverseLoop:C}=Xen({rafRef:r,reverseRafRef:s,getAdapter:b,setCurrentTime:h,setIsPlaying:m,setLoopStart:(0,U.useCallback)(e=>{try{n.current?.contentWindow?.__hf?.setLoopStart?.(e)}catch{}},[])}),w=(0,U.useCallback)(e=>{let t=n.current;if(t){r7t(t,e);try{let n=t.contentWindow;if(n?.__timelines)for(let t of Object.values(n.__timelines))t&&typeof t.timeScale==`function`&&t.timeScale(e)}catch{}}},[]),T=(0,U.useCallback)(()=>{let{audioMuted:e,audioVolume:t}=X.getState();n7t(n.current,e,t)},[]),E=(0,U.useCallback)(()=>{let{timelineReady:e,playLocked:t}=X.getState();if(!e||t)return;S(),C(),G1();let n=b();n&&(n.getTime()>=n.getDuration()&&n.seek(X.getState().inPoint??0),w(X.getState().playbackRate),T(),n.play(),c.current=`forward`,m(!0),x())},[b,m,x,w,T,S,C]),D=(0,U.useCallback)(e=>{S(),C();let t=b();if(!t)return;let n=Math.max(0,t.getDuration()),r=t.getTime()<=0&&n>0?n:t.getTime();t.pause(),r!==t.getTime()&&t.seek(r);let i=Math.max(.1,Math.min(4,e));w(i),T();let a=r,o=performance.now(),l=e=>{let r=(e-o)/1e3*i,u=a-r,{inPoint:d,outPoint:f}=X.getState(),p=f===null?n:Math.min(f,n),g=d===null?0:d,_=g<p?p:n,v=g<p?g:0;if(u<=v)if(X.getState().loopEnabled&&n>0)a=_,o=e,u=_;else{t.seek(v),Lb.notify(v),h(v),m(!1),c.current=null,s.current=0;return}t.seek(Math.max(0,u)),Lb.notify(Math.max(0,u)),m(!0),s.current=requestAnimationFrame(l)};m(!0),c.current=`backward`,s.current=requestAnimationFrame(l)},[b,h,m,w,T,S,C]),O=(0,U.useCallback)(()=>{C();let e=b();e?.pause(),e&&h(e.getTime()),m(!1),c.current=null,l.current=0,S()},[b,h,m,S,C]),k=(0,U.useCallback)((e,t)=>{let r=c.current===`backward`;C();let i=b();if(!i)return a.current=Math.max(0,e),!1;let o=Math.max(0,i.getDuration()),s=YMe(e,o),u=t?.keepPlaying===!0,{playLocked:d,isPlaying:f}=X.getState(),p=vtn({keepPlaying:u,wasReverseShuttle:r,storeWasPlaying:f,duration:o,nextTime:s,playLocked:d});return i.seek(s,t),Dtn(s,t),h(s),!u&&!d&&Zen(n.current,s),p?(S(),w(X.getState().playbackRate),T(),i.play(),m(!0),c.current=`forward`,l.current=0,x()):ytn({keepPlaying:u,wasReverseShuttle:r})&&(S(),X.getState().isPlaying&&m(!1),c.current=null,l.current=0),!0},[b,a,h,m,x,S,C,w,T,c,l]);(0,U.useEffect)(()=>X.subscribe((e,t)=>{e.playLocked&&!t.playLocked&&e.isPlaying&&O()}),[O]),(0,U.useEffect)(()=>X.subscribe((e,t)=>{e.requestedSeekTime!==null&&e.requestedSeekTime!==t.requestedSeekTime&&(k(e.requestedSeekTime),X.getState().clearSeekRequest());let n=e.playbackRequest;n&&n.nonce!==t.playbackRequest?.nonce&&(n.playing?E():(O(),n.returnTo!==null&&k(n.returnTo,{follow:!1})),X.getState().clearPlaybackRequest())}),[k,E,O]),(0,U.useEffect)(()=>fVt(b),[b]);let{playbackKeyDownRef:A,playbackKeyUpRef:j,attachIframeShortcutListeners:M,togglePlay:N}=V5t({iframeRef:n,shuttleDirectionRef:c,shuttleSpeedIndexRef:l,iframeShortcutCleanupRef:u,getAdapter:b,play:E,playBackward:D,pause:O,seek:k}),{processTimelineMessageRef:P,enrichMissingCompositionsRef:F,onIframeLoad:I,cancelPendingLoad:L}=J7t({iframeRef:n,probeIntervalRef:i,pendingSeekRef:a,isRefreshingRef:o,getAdapter:b,syncTimelineElements:y,setDuration:g,setCurrentTime:h,requestTimelineReady:_,setIsPlaying:m,attachIframeShortcutListeners:M,applyPreviewAudioState:T}),{previewSlots:R,onShadowIframeLoad:z,onShadowReadyChange:B,onShadowError:V,setShadowIframeNode:ee,beginShadowReload:te,resetPreviewSlots:H,previewGeneration:ne}=Ken({iframeRef:n,getAdapter:b,pendingSeekRef:a,isRefreshingRef:o,syncTimelineElements:y,setDuration:g,setCurrentTime:h,requestTimelineReady:_,setIsPlaying:m,attachIframeShortcutListeners:M,applyPreviewAudioState:T,onPromoted:e,onReloadFailed:t,handOverPlayback:(e,t)=>{k(e,{keepPlaying:!0,follow:!1});let n=b();t&&n&&n.getTime()<n.getDuration()&&E()}}),re=(0,U.useCallback)(()=>{if(!(o.current&&a.current!=null)){let e=b();e?a.current=e.getTime():a.current??=X.getState().currentTime??0}o.current=!0;let e=X.getState().isPlaying&&c.current!==`backward`;return C(),e?!0:(S(),m(!1),!1)},[b,S,m,C]),ie=(0,U.useCallback)(e=>{re()||b()?.pause(),te(e)},[re,b,te]),ae=(0,U.useRef)(0),oe=(0,U.useRef)(null),se=(0,U.useCallback)(()=>{let e=n.current;if(!e)return;oe.current?.abort(Error(`superseded by a newer edit`));let t=new AbortController;oe.current=t,s2(`refreshPlayer`,()=>({stack:Error(`refreshPlayer`).stack}));let r=new URL(e.src,window.location.origin);r.searchParams.set(`_t`,String(Date.now())),GNe(r);let i=++ae.current,a=ne(),s=()=>i===ae.current&&a===ne(),c=Ven(e),l=!!e.contentDocument&&G0(e.contentDocument);if(!c||o.current||l)return ie(r.toString());m2(()=>c(r.toString(),s,t.signal)).catch(e=>{s()&&(s2(`scene-swap-refused`,{reason:String(e)}),ie(r.toString()))})},[ie,ne]),ce=(0,U.useRef)(O);ce.current=O,ax(()=>{let e=e=>A.current(e),t=e=>j.current(e),r=wtn({iframeRef:n,processTimelineMessageRef:P,enrichMissingCompositionsRef:F,lastTimelineMessageRef:d,getAdapter:b,syncTimelineElements:y}),i=()=>{document.hidden&&X.getState().isPlaying&&ce.current()};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`keyup`,t,!0),window.addEventListener(`message`,r),document.addEventListener(`visibilitychange`,i),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`keyup`,t,!0),u.current?.(),u.current=null,window.removeEventListener(`message`,r),document.removeEventListener(`visibilitychange`,i),S(),C(),G1(),ln(f,p),L()}});let le=(0,U.useCallback)(()=>{S(),C(),L(),X.getState().reset()},[S,C,L]);return(0,U.useEffect)(()=>X.subscribe((e,t)=>{let n=e.playbackRate!==t.playbackRate,r=e.audioMuted!==t.audioMuted,i=e.audioVolume!==t.audioVolume;!n&&!r&&!i||(n&&w(e.playbackRate),T())}),[w,T]),{iframeRef:n,play:E,pause:O,togglePlay:N,seek:k,onIframeLoad:I,refreshPlayer:se,saveSeekPosition:re,resetPlayer:le,previewSlots:R,onShadowIframeLoad:z,onShadowReadyChange:B,onShadowError:V,setShadowIframeNode:ee,resetPreviewSlots:H}}function ktn({projectId:e,activeCompositionPath:t,onCompositionChange:n}){let[r,i]=(0,U.useState)([{id:`master`,label:`Master`,previewUrl:M(e,`/preview`)}]),a=(0,U.useRef)(n);a.current=n;let o=(0,U.useRef)(0),s=(0,U.useRef)(null),c=(0,U.useRef)(e);c.current=e;let l=(0,U.useRef)(r),u=(0,U.useCallback)(e=>{let t=l.current,n=typeof e==`function`?e(t):e;l.current=n;let r=X.getState();t.length===1&&n.length>1?(o.current=r.isPlaying?Lb.latest():r.currentTime,s.current=c.current):n.length===1&&t.length>1&&s.current===c.current&&r.setCurrentTime(o.current),i(n);let u=n[n.length-1]?.id;queueMicrotask(()=>a.current?.(u===`master`?null:u))},[]),[d,f]=(0,U.useState)(new Map),p=(0,U.useRef)(d);p.current=d;let m=(0,U.useCallback)(e=>{X.getState().setElements([]),u(t=>t.slice(0,e+1))},[]),h=(0,U.useCallback)(t=>{if(!t.compositionSrc)return;let n=p.current.get(t.id)??t.compositionSrc,r=(Et(n)??n).replace(/^(\.\/|\/)+/,``);X.getState().setElements([]),u(t=>{if(t[t.length-1].id===r&&t.length>1)return t.slice(0,-1);let n=r.split(`/`).pop()?.replace(/\.html$/,``)||r,i=M(e,`/preview/comp/${N$(r)}`);return[...t,{id:r,label:n,previewUrl:i}]})},[e]);return(0,U.useEffect)(()=>{let n={id:`master`,label:`Master`,previewUrl:M(e,`/preview`)};if(t===`index.html`)X.getState().setElements([]),u([n]);else if(t){let r=t.replace(/^compositions\//,``).replace(/\.html$/,``),i=M(e,`/preview/comp/${N$(t)}`);X.getState().setElements([]),u(e=>e[e.length-1]?.id===t?e:[n,{id:t,label:r,previewUrl:i}])}else X.getState().setElements([]),u([n])},[t,e,u]),{compositionStack:r,updateCompositionStack:u,handleNavigateComposition:m,handleDrillDown:h,masterSeekRef:o,compIdToSrc:d,setCompIdToSrc:f}}var O2=gb(e=>({previewAsset:null,previewProjectId:null,setPreviewAsset:(t,n)=>e({previewAsset:t,previewProjectId:n}),clearPreviewAsset:()=>e({previewAsset:null,previewProjectId:null})}));function Atn(e){return e}var jtn=jG(`NLEContext`,null);function k2(){let e=(0,U.useContext)(jtn);if(!e)throw Error(`useNLEContext must be used within an NLEProvider`);return e}function Mtn({projectId:e,refreshKey:t,activeCompositionPath:n,onIframeRef:r,onCompositionChange:i,onCompIdToSrcChange:a,onCompositionLoadingChange:o,onPreviewReloadFailed:s,children:c}){let l=(0,U.useRef)(()=>{}),u=(0,U.useRef)(null),{iframeRef:d,play:f,pause:p,togglePlay:m,seek:h,onIframeLoad:g,refreshPlayer:_,previewSlots:v,onShadowIframeLoad:y,onShadowReadyChange:b,onShadowError:x,setShadowIframeNode:S,resetPreviewSlots:C}=Otn({onShadowPromoted:()=>l.current(),onPreviewReloadFailed:s});(0,U.useEffect)(()=>{X.getState().beginTimelineSession(e),O2.getState().clearPreviewAsset()},[e]);let[w,T]=(0,U.useState)(null),E=(0,U.useRef)(t);(0,U.useEffect)(()=>{try{if(t===E.current)return;E.current=t,_()}finally{Fen()}},[t,_]);let D=(0,U.useCallback)(()=>{IQt(d.current),r?.(d.current)},[d,r]);l.current=D;let O=(0,U.useCallback)(()=>{g(),D()},[g,D]),{compositionStack:k,updateCompositionStack:A,handleNavigateComposition:j,handleDrillDown:N,compIdToSrc:P,setCompIdToSrc:F}=ktn({projectId:e,activeCompositionPath:n,onCompositionChange:i}),I=d,L=(0,U.useCallback)(e=>{if(!e.compositionSrc)return;X.getState().setSelectedElementId(null);let t=e.id,n=P.get(t);if(!n)try{let e=I.current?.contentDocument;if(e){let r=e.querySelector(`[data-composition-id="${CSS.escape(t)}"][data-composition-src]`);r&&(n=r.getAttribute(`data-composition-src`)||void 0)}}catch{}N({id:t,compositionSrc:n??e.compositionSrc})},[P,N,I]),R=(0,U.useRef)(P);R.current=P;let z=(0,U.useRef)(a);z.current=a,(0,U.useEffect)(()=>{let t=new AbortController,n=!0,r=new Map;return F(r),bt(r),z.current?.(r),H(M(e,`/files/index.html`),{signal:t.signal}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{if(!n)return;let t=e.content||``,r=new Map,i=/data-composition-id=["']([^"']+)["'][^>]*data-composition-src=["']([^"']+)["']|data-composition-src=["']([^"']+)["'][^>]*data-composition-id=["']([^"']+)["']/g,a;for(;(a=i.exec(t))!==null;){let e=a[1]||a[4],t=a[2]||a[3];e&&t&&r.set(e,t)}F(r),bt(r),z.current?.(r)}).catch(e=>{!n||t.signal.aborted||console.warn(`[studio] Couldn't load composition source map from index.html:`,e)}),()=>{n=!1,t.abort()}},[e,F]),(0,U.useEffect)(()=>{if(P.size===0)return;let e=e=>{let t=R.current;if(t.size===0)return null;let n=!1,r=e.map(e=>{if(e.compositionSrc)return e;let r=t.get(e.id)??t.get(e.id.replace(/-(host|comp|layer)$/,``));return r?(n=!0,{...e,compositionSrc:r}):e});return n?r:null},t=e(X.getState().elements);t&&X.getState().setElements(t);let n=!1;return X.subscribe((t,r)=>{if(n||t.elements===r.elements||t.elements.length===0||t.elements.every(e=>e.compositionSrc))return;n=!0;let i=e(t.elements);i&&t.setElements(i),n=!1})},[P]);let B=(0,U.useRef)(!1),[V,ee]=(0,U.useState)(!0),te=(0,U.useCallback)(e=>{e||(B.current=!0),!(e&&B.current)&&ee(e)},[]),ne=Atn(V),re=X(e=>e.timelineSessionEpoch);(0,U.useEffect)(()=>{o?.(V)},[V,o]);let ie=(0,U.useRef)(r);ie.current=r,(0,U.useEffect)(()=>{ie.current?.(d.current)},[k.length,t,d]);let ae={projectId:e,iframeRef:d,play:f,pause:p,containerRef:u,togglePlay:m,seek:h,refreshPlayer:_,onIframeLoad:O,previewSlots:v,onShadowIframeLoad:y,onShadowReadyChange:b,onShadowError:x,setShadowIframeNode:S,resetPreviewSlots:C,compositionStack:k,updateCompositionStack:A,handleNavigateComposition:j,handleDrillDown:L,compIdToSrc:P,compositionLoading:V,setCompositionLoading:te,timelineDisabled:ne,timelineSessionEpoch:re,hasLoadedOnceRef:B,previewCompositionSize:w,setPreviewCompositionSize:T};return(0,W.jsx)(jtn.Provider,{value:ae,children:c})}function Ntn(e){try{let t=e?.contentDocument,n=t?.querySelector(`[data-composition-id][data-width][data-height]`)??t?.querySelector(`[data-width][data-height]`);if(!n)return null;let r=Number.parseInt(n.getAttribute(`data-width`)??``,10),i=Number.parseInt(n.getAttribute(`data-height`)??``,10);return!Number.isFinite(r)||r<=0||!Number.isFinite(i)||i<=0?null:{width:r,height:i}}catch{return null}}var Ptn=25,Ftn=400,Itn=`[data-preview-pan-surface="true"]`,A2=48,j2={zoomPercent:100,panX:0,panY:0},Ltn=.007,Rtn=10,ztn=e=>Math.abs(e-100)<.5;function M2(e){return ztn(e.zoomPercent)&&Math.abs(e.panX)<.1&&Math.abs(e.panY)<.1}function N2(e){return Math.round(e*1e4)/1e4}function P2(e){return Number.isFinite(e)?Math.min(Ftn,Math.max(Ptn,e)):100}function Btn(e){return e===1}function F2(e,t){return e instanceof Element?t?.contains(e)?!0:!!e.closest(Itn):!1}function Vtn(e,t){if(!Number.isFinite(e))return P2(t);let n=-(Math.abs(e)>Rtn?Rtn*Math.sign(e):e)*Ltn;return P2(P2(t)*Math.exp(n))}function I2(e){let t=P2(e.zoomPercent)/100,n=e.contentWidth??e.viewportWidth,r=e.contentHeight??e.viewportHeight,i=Math.max(0,(n*t-e.viewportWidth)/2)+A2,a=Math.max(0,(r*t-e.viewportHeight)/2)+A2;return{panX:Math.min(i,Math.max(-i,e.panX)),panY:Math.min(a,Math.max(-a,e.panY))}}function Htn(e,t,n,r,i,a,o){let s=P2(n)/100,c=Math.abs(a*s-r)/2+A2,l=Math.abs(o*s-i)/2+A2;return{panX:Math.min(c,Math.max(-c,e)),panY:Math.min(l,Math.max(-l,t))}}function Utn(e){let t=P2(e.state.zoomPercent),n=Vtn(e.deltaY,t),r=t/100,i=n/100,a=e.state.panX,o=e.state.panY;if(e.cursorX!==void 0&&e.cursorY!==void 0){let t=i/r;a=e.cursorX*(1-t)+a*t,o=e.cursorY*(1-t)+o*t}let s=e.contentWidth??e.viewportWidth,c=e.contentHeight??e.viewportHeight;return{zoomPercent:n,...Htn(a,o,n,e.viewportWidth,e.viewportHeight,s,c)}}function Wtn(e){let t=I2({panX:e.state.panX-e.deltaX,panY:e.state.panY-e.deltaY,zoomPercent:e.state.zoomPercent,viewportWidth:e.viewportWidth,viewportHeight:e.viewportHeight,contentWidth:e.contentWidth,contentHeight:e.contentHeight});return{zoomPercent:P2(e.state.zoomPercent),...t}}function Gtn(e){let t=P2(e.state.zoomPercent)/100,n=(e,n,r)=>{let i=r*t;if(!(i>0))return[0,1];let a=t=>Math.min(1,Math.max(0,(t-e+i/2)/i)),o=a(-n/2);return[o,a(n/2)-o]},[r,i]=n(e.state.panX,e.viewportWidth,e.contentWidth),[a,o]=n(e.state.panY,e.viewportHeight,e.contentHeight);return{left:r,top:a,width:i,height:o}}var L2=16,R2=gb((e,t)=>{let n=Ub();return{rulerVisible:n.rulerVisible??!1,safeMarginsVisible:n.safeMarginsVisible??!1,toggle:n=>{let r=!t()[n];Wb({[n]:r}),e({[n]:r})}}}),z2=112;function Ktn(e){return ztn(e)?`Panned`:`Zoomed ${Math.round(e)}%`}function qtn(e){let t=e.width>0&&e.height>0?e.width/e.height:16/9;return t>=1?{width:z2,height:N2(z2/t)}:{width:N2(z2*t),height:z2}}function Jtn(e,t,n){let r=(0,U.useRef)(null),i=(0,U.useRef)(t);i.current=t;let a=(0,U.useCallback)(t=>{let n=r.current,a=e.current?.getBoundingClientRect();if(!n||!a)return;let o=Gtn({state:t,viewportWidth:a.width,viewportHeight:a.height,contentWidth:i.current.width,contentHeight:i.current.height});n.style.left=`${o.left*100}%`,n.style.top=`${o.top*100}%`,n.style.width=`${o.width*100}%`,n.style.height=`${o.height*100}%`},[e]),o=(0,U.useCallback)(e=>{r.current=e,a(n.current)},[a,n]);return(0,U.useEffect)(()=>a(n.current),[t,a,n]),{draw:a,setRegion:o}}function Ytn({zoom:e,stageSize:t,onFit:n,navigatorRegionRef:r}){return M2(e)?null:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`absolute top-3 left-1/2 -translate-x-1/2 z-50 flex items-center gap-1.5 rounded-md py-1 pl-2.5 pr-1 text-xs text-white/80 bg-black/60 backdrop-blur-xs`,"data-testid":`preview-zoom-chip`,onPointerDown:e=>e.stopPropagation(),children:[(0,W.jsx)(`span`,{className:`tabular-nums`,children:Ktn(e.zoomPercent)}),(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`text-white/30`,children:`·`}),(0,W.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 font-medium text-accent-ink hover:bg-white/10 transition-colors`,onClick:n,"aria-label":`Fit the whole frame in view`,"data-testid":`preview-zoom-fit`,children:`Fit`})]}),(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-3 right-3 z-50 rounded-md p-1.5 bg-black/60 backdrop-blur-xs`,"data-testid":`preview-zoom-navigator`,children:(0,W.jsx)(`div`,{className:`relative overflow-hidden bg-white/10`,style:qtn(t),children:(0,W.jsx)(`div`,{ref:r,className:`absolute rounded-[1px] border border-studio-accent bg-studio-accent/15`,"data-testid":`preview-zoom-navigator-region`})})})]})}function Xtn(e){if(!e)return{clip_count:0,media_clip_count:0};let t=q1(e,nn(e));return{clip_count:t.length,media_clip_count:t.filter(({tag:e})=>e===`video`||e===`audio`).length}}function Ztn(e){let t=(0,U.useRef)(e);t.current=e;let n=(0,U.useRef)(new Set);return(0,U.useCallback)((e,{iframe:r,startedAt:i,loadId:a})=>{if(!t.current.find(t=>t.gen===e.gen&&t.role===e.role))return;let o=`${e.role}:${e.gen}:${a}`;if(n.current.has(o))return;n.current.add(o);let s=Xtn(r.contentDocument);hWt({duration_ms:Math.max(0,Math.round(performance.now()-i)),composition_seconds:nn(r.contentDocument),...s,studio_version:tWt().studio_version})},[])}function Qtn(e,t){return M(e,`/thumbnail/index.html?${`t=0&output=source${t?`&cached=1`:``}`}`)}var $tn={position:`absolute`,inset:0,width:`100%`,height:`100%`,objectFit:`contain`,zIndex:2,pointerEvents:`none`};function enn({projectId:e,hidden:t,onSize:n,onLoaded:r,onMissing:i}){return(0,W.jsx)(`img`,{src:Qtn(e,!0),alt:``,"aria-hidden":!0,"data-testid":`preview-poster`,hidden:t,style:$tn,onLoad:e=>{let{naturalWidth:i,naturalHeight:a}=e.currentTarget;!t&&i>0&&a>0&&n({width:i,height:a}),r()},onError:i})}function tnn(e,t,n){let r=rnn(t),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null),c=(0,U.useRef)(null),l=(0,U.useRef)(null),u=(0,U.useCallback)(()=>{c.current===r&&l.current===r&&(c.current=null,nnn(e))},[r,e]),d=(0,U.useCallback)(e=>{e&&(a(r),l.current=r,u())},[r,u]);return{mountPoster:!n&&(i!==r||o!==r),hidePoster:i===r,onLiveReadyToShowChange:d,onPreviewError:()=>a(r),onPosterLoaded:()=>s(r),onPosterMissing:()=>{a(r),s(r),c.current=r,u()}}}function nnn(e){let t=Qtn(e,!1),n={key:qX({kind:`poster-render`,url:t}),projectId:e,sessionEpoch:0,kind:`composition`,priority:`overscan`,discardWhenReleased:!0,load:async e=>(await(await H(t,{signal:e})).arrayBuffer(),{value:{kind:`image`,url:t,aspect:16/9},weight:0})},r=()=>[`ready`,`error`].includes(YX.getSnapshot(n).status),i=null;i=YX.acquire(n,()=>{r()&&i?.release()}),r()&&i.release()}function rnn(e){let[t,n]=(0,U.useState)({key:e,visit:0});return t.key===e?t.visit:(n({key:e,visit:t.visit+1}),t.visit+1)}function inn({projectId:e,directUrl:t}){return t??e}var ann=1200,onn=200,snn=8,cnn={position:`absolute`,inset:0,visibility:`hidden`,clipPath:`inset(100%)`,pointerEvents:`none`};function lnn(e,t,n,r,i=0,a=snn){let o=Math.max(0,e-2*(a+i)),s=Math.max(0,t-2*(a+i)),c=n&&n.width>0&&n.height>0?n.width/n.height:r?9/16:16/9;if(o===0||s===0)return{width:0,height:0};let l=o,u=l/c;return u>s&&(u=s,l=u*c),{width:N2(l),height:N2(u)}}var unn=(0,U.memo)(function({projectId:e,iframeRef:t,onIframeLoad:n,previewSlots:r,onShadowIframeLoad:i,onShadowReadyChange:a,onShadowError:o,setShadowIframeNode:s,resetPreviewSlots:c,onCompositionLoadingChange:l,portrait:u,directUrl:d,suppressLoadingOverlay:f,onStageRef:p,onCompositionSizeChange:m,fillBox:h,compositionSizeHint:g}){let _=inn({projectId:e,directUrl:d}),v=(0,U.useRef)(null),y=(0,U.useRef)(null),b=(0,U.useRef)(null);(0,U.useEffect)(()=>{p?.(y)},[p]);let x=(0,U.useRef)(_);(0,U.useEffect)(()=>{x.current!==_&&(x.current=_,c())},[_,c]);let S=(0,U.useRef)(null),C=Ztn(r),[w,T]=(0,U.useState)(null),E=tnn(e,_,d),D=R2(e=>e.rulerVisible?L2:0),O=h?0:snn,[k,A]=(0,U.useState)(()=>lnn(0,0,null,u)),j=g?.width,M=g?.height,N=(0,U.useRef)(j2),[P,F]=(0,U.useState)(j2),I=(0,U.useRef)(null),L=(0,U.useRef)(null),R=(0,U.useRef)(null),z=(0,U.useRef)(!1),B=(0,U.useRef)(null);(0,U.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),L.current&&clearTimeout(L.current)},[]),(0,U.useEffect)(()=>{let e=v.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();A(lnn(t.width,t.height,w??(j&&M?{width:j,height:M}:null),u,D,O))};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[w,j,M,u,D,O]);let V=(0,U.useRef)(m);V.current=m;let ee=(0,U.useCallback)(()=>{let e=Ntn(b.current);T(t=>t?.width===e?.width&&t?.height===e?.height?t:e)},[]);(0,U.useEffect)(()=>{V.current?.(w)},[w]);let te=(0,U.useCallback)(e=>{b.current=e,t.current=e},[t]),H=(0,U.useRef)(k);H.current=k;let{draw:ne,setRegion:re}=Jtn(v,k,N),ie=(0,U.useCallback)(e=>{let t=y.current;if(!t)return;let n=N2(e.zoomPercent/100),r=N2(e.panX),i=N2(e.panY);t.style.transform=`translate3d(${r}px, ${i}px, 0) scale(${n})`,ne(e)},[ne]),ae=(0,U.useRef)(e);(0,U.useLayoutEffect)(()=>{ae.current!==e&&(ae.current=e,N.current=j2,ie(j2),F(j2))},[e,ie]);let oe=(0,U.useCallback)((e,t)=>{let n={zoomPercent:P2(e.zoomPercent),panX:Number.isFinite(e.panX)?e.panX:0,panY:Number.isFinite(e.panY)?e.panY:0};if(N.current=n,t){let e=I.current;e&&(z.current||(z.current=!0,e.style.opacity=`1`),e.textContent=M2(n)?`Fit`:`${Math.round(n.zoomPercent)}%`)}ie(n),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{z.current=!1;let e=N.current;if(F(t=>t.zoomPercent===e.zoomPercent&&t.panX===e.panX&&t.panY===e.panY?t:e),t){let t=I.current;t&&(t.textContent=M2(e)?`Fit`:`${Math.round(e.zoomPercent)}%`,L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{I.current&&(I.current.style.opacity=`0`)},ann))}},onn)},[ie]),se=(0,U.useCallback)(e=>oe(e,!0),[oe]),ce=(0,U.useCallback)(e=>oe(e,!1),[oe]),le=(0,U.useCallback)(()=>{let e=N.current;if(!M2(e)){let t=v.current?.getBoundingClientRect(),n=H.current;if(t&&t.width>0&&t.height>0&&n.width>0&&n.height>0){let r=I2({panX:e.panX,panY:e.panY,zoomPercent:e.zoomPercent,viewportWidth:t.width,viewportHeight:t.height,contentWidth:n.width,contentHeight:n.height});N.current={...e,...r}}ie(N.current)}},[ie]);(0,U.useEffect)(()=>{let e=r.find(e=>e.role===`live`);if(!e||e.gen===S.current)return;let n=S.current!==null;S.current=e.gen,n&&(b.current=t.current,ee(),le())},[r,t,ee,le]),(0,U.useEffect)(()=>{let e=v.current;if(!e)return;let t=t=>{let n=e.getBoundingClientRect();if(t.clientX<n.left||t.clientX>n.right||t.clientY<n.top||t.clientY>n.bottom)return;if(t.ctrlKey||t.metaKey){t.preventDefault(),t.stopPropagation();let e=H.current,r=t.clientX-(n.left+n.width/2),i=t.clientY-(n.top+n.height/2),a=Utn({state:N.current,deltaY:t.deltaY,viewportWidth:n.width,viewportHeight:n.height,contentWidth:e.width,contentHeight:e.height,cursorX:r,cursorY:i});se(a);return}if(!F2(t.target,y.current))return;t.preventDefault(),t.stopPropagation();let r=H.current,i=Wtn({state:N.current,deltaX:t.deltaX,deltaY:t.deltaY,viewportWidth:n.width,viewportHeight:n.height,contentWidth:r.width,contentHeight:r.height});ce(i)};return document.addEventListener(`wheel`,t,{passive:!1,capture:!0}),()=>document.removeEventListener(`wheel`,t,{capture:!0})},[se,ce]),(0,U.useEffect)(()=>{let e=(e,t)=>{let n=v.current;if(!n)return null;let r=n.getBoundingClientRect();return e<r.left||e>r.right||t<r.top||t>r.bottom?null:r},t=t=>{e(t.clientX,t.clientY)&&F2(t.target,y.current)&&Btn(t.button)&&(t.preventDefault(),B.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,originX:N.current.panX,originY:N.current.panY})},n=e=>{let t=B.current,n=v.current;if(!t||!n||t.pointerId!==e.pointerId)return;e.preventDefault();let r=n.getBoundingClientRect(),i=H.current,a=I2({panX:t.originX+e.clientX-t.startX,panY:t.originY+e.clientY-t.startY,zoomPercent:N.current.zoomPercent,viewportWidth:r.width,viewportHeight:r.height,contentWidth:i.width,contentHeight:i.height});ce({...N.current,...a})},r=e=>{B.current?.pointerId===e.pointerId&&(B.current=null)},i=t=>{t.button===1&&e(t.clientX,t.clientY)&&F2(t.target,y.current)&&t.preventDefault()};return document.addEventListener(`pointerdown`,t,{capture:!0}),document.addEventListener(`pointermove`,n,{capture:!0}),document.addEventListener(`pointerup`,r,{capture:!0}),document.addEventListener(`pointercancel`,r,{capture:!0}),document.addEventListener(`auxclick`,i,{capture:!0}),()=>{document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,n,{capture:!0}),document.removeEventListener(`pointerup`,r,{capture:!0}),document.removeEventListener(`pointercancel`,r,{capture:!0}),document.removeEventListener(`auxclick`,i,{capture:!0})}},[ce]);let ue=N.current;return(0,W.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,W.jsxs)(`div`,{ref:v,className:`relative flex-1 flex items-center justify-center overflow-hidden min-h-0 outline-hidden focus:ring-1 focus:ring-studio-accent/40 bg-[var(--studio-preview-bg,var(--color-neutral-950))]`,tabIndex:0,"aria-label":`Composition preview`,children:[(0,W.jsx)(`div`,{className:`absolute flex items-center justify-center pointer-events-none`,style:{inset:O},children:(0,W.jsxs)(`div`,{ref:y,className:`relative shrink-0 pointer-events-auto`,style:{width:`${k.width}px`,height:`${k.height}px`,transform:`translate3d(${N2(ue.panX)}px, ${N2(ue.panY)}px, 0) scale(${N2(ue.zoomPercent/100)})`,transformOrigin:`center center`},"data-testid":`preview-zoom-stage`,children:[d?.includes(`/components/`)&&(0,W.jsx)(lx,{projectId:e,onLoad:()=>{},portrait:u,suppressLoadingOverlay:!0,style:{position:`absolute`,inset:0,zIndex:0}},`backdrop-${e}`),r.map(t=>t.role===`live`?(0,W.jsx)(lx,{ref:te,projectId:d?void 0:e,directUrl:d,onLoad:()=>{ee(),n(),le()},onCompositionLoadingChange:l,onReadyToShowChange:E.onLiveReadyToShowChange,onPreviewError:E.onPreviewError,onPainted:e=>C(t,e),portrait:u,suppressLoadingOverlay:f,style:d?.includes(`/components/`)?{position:`absolute`,inset:0,zIndex:1}:void 0},`${_}-${t.gen}`):(0,W.jsx)(lx,{ref:s,directUrl:t.url,onLoad:()=>i(t.gen),onReadyToShowChange:e=>a(t.gen,e),onPainted:e=>C(t,e),onPreviewError:e=>o(t.gen,e),portrait:u,suppressLoadingOverlay:!0,style:cnn},`${_}-${t.gen}`)),E.mountPoster&&(0,W.jsx)(enn,{projectId:e,hidden:E.hidePoster,onSize:e=>T(t=>t??e),onLoaded:E.onPosterLoaded,onMissing:E.onPosterMissing},_)]})}),(0,W.jsx)(`div`,{ref:I,className:`pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 z-50 rounded-lg px-4 py-2 text-sm font-mono tabular-nums text-white/90 bg-black/60 backdrop-blur-xs shadow-lg`,style:{opacity:0,transition:`opacity 200ms ease-in`},"aria-live":`polite`}),(0,W.jsx)(Ytn,{zoom:P,stageSize:k,onFit:()=>{se(j2),v.current?.focus()},navigatorRegionRef:re})]})})});function dnn({stack:e,onNavigate:t}){return e.length<=1?null:(0,W.jsxs)(`nav`,{"aria-label":`Composition navigation`,className:`flex items-center gap-1 px-2 h-8 border-b border-hairline bg-bg-1 shrink-0`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>{mG(`navigation`,{action:`back`,target:e[e.length-2]?.label}),t(e.length-2)},className:`flex items-center gap-1 px-1.5 py-0.5 rounded-sm text-xs text-text-3 hover:text-text-0 hover:bg-hover active:scale-[0.98] transition-colors`,title:`Back (Esc, or double-click empty timeline)`,"aria-label":`Back to parent composition`,children:(0,W.jsx)(t5e,{size:12,weight:`bold`})}),e.map((n,r)=>{let i=r===e.length-1;return(0,W.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,W.jsx)(y5e,{size:10,className:`text-text-4 shrink-0`}),i?(0,W.jsx)(`span`,{className:`text-xs text-text-1 font-medium`,children:n.label}):(0,W.jsx)(`button`,{type:`button`,onClick:()=>{mG(`navigation`,{action:`breadcrumb`,target:n.label}),t(r)},className:`text-xs text-text-3 hover:text-text-1 transition-colors`,children:n.label})]},n.id)})]})}var fnn=`Preview is read-only.`,B2=jG(`PreviewReadOnlyContext`,{readOnly:!1,reason:fnn});function pnn({readOnly:e,reason:t,children:n}){let r=(0,U.useMemo)(()=>({readOnly:e,reason:t??fnn}),[e,t]);return(0,W.jsx)(B2,{value:r,children:n})}function V2(){return(0,U.useContext)(B2).readOnly}function mnn(){return(0,U.useContext)(B2).reason}function hnn(e,t={x:0,y:0}){let{readOnly:n}=(0,U.useContext)(B2),r=!Number.isFinite(t.x)||!Number.isFinite(t.y);return{manualOffsetEditingDisabled:!e?.canApplyManualOffset||n||r,manualSizeEditingDisabled:!e?.canApplyManualSize||n,manualRotationEditingDisabled:!e?.canApplyManualRotation||n}}function gnn(e){try{let t=JSON.parse(e);return t.name?t:null}catch{return null}}function _nn(e,t,n,r,i){if(n.width===0||n.height===0)return null;let a=(e-n.left)/n.width,o=(t-n.top)/n.height,s=r?.width??(i?1080:1920),c=r?.height??(i?1920:1080);return{left:Math.max(0,Math.min(a*s,s)),top:Math.max(0,Math.min(o*c,c))}}function vnn(e,t){let n=t.dimensions?.width??0,r=t.dimensions?.height??0;return{left:Math.max(0,e.left-n/2),top:Math.max(0,e.top-r/2)}}function ynn({portrait:e,compositionSize:t,stageRef:n,onBlockDrop:r}){let i=V2()?void 0:r,[a,o]=(0,U.useState)(!1),s=(0,U.useRef)(0);return{isDragOver:a,handleDragEnter:(0,U.useCallback)(e=>{i&&e.dataTransfer.types.includes(fq)&&(s.current+=1,o(!0))},[i]),handleDragOver:(0,U.useCallback)(e=>{i&&e.dataTransfer.types.includes(fq)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},[i]),handleDragLeave:(0,U.useCallback)(()=>{s.current=Math.max(0,s.current-1),s.current===0&&o(!1)},[]),handleDrop:(0,U.useCallback)(r=>{if(s.current=0,o(!1),!i)return;let a=r.dataTransfer.getData(fq);if(!a)return;r.preventDefault();let c=gnn(a),l=n.current;if(!c||!l)return;let u=_nn(r.clientX,r.clientY,l.getBoundingClientRect(),t,e);u&&i(c.name,vnn(u,c))},[i,n,t,e])}}var bnn=1e-6;function xnn(e,t){return t.isPlaying||t.requestedSeekTime!==null?!0:Math.abs(t.currentTime-e)>bnn}function Snn(e){return e.split(`/`).pop()??e}function Cnn(e){return iq.test(e)?`video`:rq.test(e)?`image`:`audio`}function wnn({kind:e,serveUrl:t,name:n}){return e===`image`?(0,W.jsx)(`img`,{src:t,alt:n,className:`max-w-full max-h-[40vh] rounded-sm object-contain`}):e===`video`?(0,W.jsx)(`video`,{src:t,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,className:`max-w-full max-h-[40vh] rounded-sm`}):(0,W.jsxs)(`div`,{className:`flex flex-col items-center gap-3 px-6 py-4`,children:[(0,W.jsxs)(`svg`,{width:`40`,height:`40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,className:`text-neutral-500`,children:[(0,W.jsx)(`path`,{d:`M9 18V5l12-2v13`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,W.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]}),(0,W.jsx)(`audio`,{src:t,controls:!0,className:`w-64`})]})}function Tnn(){let e=O2(e=>e.previewAsset),t=O2(e=>e.previewProjectId),n=O2(e=>e.clearPreviewAsset),r=(0,U.useCallback)(e=>{e.key===`Escape`&&n()},[n]);if((0,U.useEffect)(()=>{if(e)return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[e,r]),(0,U.useEffect)(()=>{if(!e)return;let t=X.getState(),r=t.currentTime;if(xnn(r,t)){n();return}return X.subscribe(e=>{xnn(r,e)&&n()})},[e,n]),!e||!t)return null;let i=P$(e,t),a=Snn(e);return(0,W.jsx)(`div`,{className:`absolute inset-0 z-50 flex flex-col items-center justify-center bg-black/20`,onClick:n,role:`dialog`,"aria-label":`Preview: ${a}`,children:(0,W.jsxs)(`div`,{className:`relative flex flex-col items-center gap-2 max-w-[58%] rounded-lg border border-neutral-800 bg-neutral-950/95 p-2 pt-8 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(`button`,{className:`absolute top-2 right-2 w-6 h-6 rounded-full bg-raised hover:bg-press text-text-2 hover:text-text-0 flex items-center justify-center transition-colors z-10`,onClick:e=>{e.stopPropagation(),n()},"aria-label":`Close preview`,children:(0,W.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2.5`,fill:`none`,strokeLinecap:`round`,children:[(0,W.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,W.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})}),(0,W.jsx)(wnn,{kind:Cnn(e),serveUrl:i,name:a}),(0,W.jsx)(`span`,{className:`text-[12px] text-neutral-400 truncate max-w-full px-2 text-center`,children:a})]})})}var Enn=400,Dnn=250,H2=new Set,U2=null,W2=null,G2=0,K2=!1,q2=null,Onn=[`pointerdown`,`pointermove`,`pointerup`,`wheel`,`keydown`,`keyup`,`scroll`,`resize`,`visibilitychange`],knn=null,Ann=null;function jnn(e){return typeof window>`u`||e.origin===window.location.origin}function Mnn(e){return typeof e!=`object`||!e?!1:e.source===`hf-preview`}function Nnn(e){if(e.type!==`state`)return null;let t=e.frame;return{frame:typeof t==`number`?t:null,playing:e.isPlaying===!0}}function Pnn(e){if(!jnn(e))return;let t=e.data;if(!Mnn(t))return;let n=Nnn(t);if(n){if(n.frame===knn&&n.playing===Ann)return;knn=n.frame,Ann=n.playing}Y2()}function Fnn(){if(U2=null,Inn(),X.getState().previewBooted)for(let e of H2)try{e()}catch(e){queueMicrotask(()=>{throw e})}}function Inn(){if(H2.size!==0&&U2==null&&W2==null){if(performance.now()<G2){U2=requestAnimationFrame(Fnn);return}W2=setTimeout(()=>{W2=null,U2=requestAnimationFrame(Fnn)},Dnn)}}var Lnn=3;function J2(e){let t=G2-performance.now();if(t>0){setTimeout(()=>J2(e),t);return}(window.requestIdleCallback??(e=>setTimeout(e,0)))(()=>{let t=performance.now()+Lnn;(performance.now()<G2||!e(()=>t-performance.now()))&&J2(e)})}function Y2(){G2=performance.now()+Enn,W2!=null&&(clearTimeout(W2),W2=null),Inn()}function Rnn(){if(!(K2||typeof window>`u`)){K2=!0;for(let e of Onn)window.addEventListener(e,Y2,{capture:!0,passive:!0});window.addEventListener(`message`,Pnn,{capture:!0,passive:!0}),q2=X.subscribe((e,t)=>{e.previewBooted&&!t.previewBooted&&Y2()})}}function znn(){if(!(!K2||typeof window>`u`)){K2=!1;for(let e of Onn)window.removeEventListener(e,Y2,{capture:!0});window.removeEventListener(`message`,Pnn,{capture:!0}),q2?.(),q2=null}}function X2(e){return H2.add(e),Rnn(),Y2(),()=>{H2.delete(e),!(H2.size>0)&&(U2!=null&&(cancelAnimationFrame(U2),U2=null),W2!=null&&(clearTimeout(W2),W2=null),znn())}}function Bnn(e,t){let n=n=>Math.abs(e[n]-t[n]);return n(`left`)<.5&&n(`top`)<.5&&n(`width`)<.5&&n(`height`)<.5&&n(`scaleX`)<.001&&n(`scaleY`)<.001}function Z2({iframeRef:e,overlayRef:t}){let[n,r]=(0,U.useState)({left:0,top:0,width:0,height:0,scaleX:1,scaleY:1});return ax(()=>X2(()=>{let n=e.current,i=t.current;if(!n||!i)return;let a=n.getBoundingClientRect(),o=i.getBoundingClientRect(),s=a.left-o.left,c=a.top-o.top;if(a.width<=0||a.height<=0)return;let l=n.contentDocument,u=l?.querySelector(`[data-composition-id]`)??l?.documentElement,d=Number.parseFloat(u?.getAttribute(`data-width`)??``),f=Number.parseFloat(u?.getAttribute(`data-height`)??``),p=d>0?a.width/d:1,m=f>0?a.height/f:1,h={left:s,top:c,width:a.width,height:a.height,scaleX:p,scaleY:m};r(e=>Bnn(e,h)?e:h)})),n}var Vnn=[90,80];function Hnn(e){return(100-e)/2}function Unn(e,t){let n=(0,U.useRef)(t);return n.current=t,(0,U.useEffect)(()=>{Y2()},[t]),Z2({iframeRef:n,overlayRef:e})}var Wnn=(0,U.createContext)(null);function Gnn(){let e=Ub();return{snapEnabled:e.snapEnabled??!0,gridVisible:e.gridVisible??!1,gridSpacing:e.gridSpacing??50,snapToGrid:e.snapToGrid??!1}}function Knn({iframe:e,children:t}){let n=(0,U.useRef)(null),[r,i]=(0,U.useState)(Gnn),a=R2(e=>e.rulerVisible),o=R2(e=>e.safeMarginsVisible),s=xZ(),c=e??s,l=(0,U.useRef)(c);l.current=c;let u={state:{snapPrefs:r,rulerVisible:a,safeMarginsVisible:o,iframeRef:l,compositionRect:Unn(n,c)},actions:{setSnapPrefs:e=>{Wb(e),i(t=>({...t,...e}))},toggleRulers:()=>R2.getState().toggle(`rulerVisible`),toggleSafeMargins:()=>R2.getState().toggle(`safeMarginsVisible`)}};return(0,W.jsx)(Wnn.Provider,{value:u,children:(0,W.jsx)(`div`,{ref:n,className:`pointer-events-none absolute inset-0`,children:t})})}function Q2(){let e=(0,U.useContext)(Wnn);if(!e)throw Error(`usePreviewOverlayContext must be used within PreviewOverlayProvider`);return e}var qnn=Array.from({length:11},(e,t)=>t*10),$2=`color-mix(in srgb, white 70%, transparent)`,Jnn=(0,U.memo)(function(){let{state:e}=Q2(),{rulerVisible:t,safeMarginsVisible:n}=e;return!t&&!n?null:(0,W.jsx)(Ynn,{iframeRef:e.iframeRef,rulerVisible:t,safeMarginsVisible:n})});function Ynn({iframeRef:e,rulerVisible:t,safeMarginsVisible:n}){let r=(0,U.useRef)(null),i=Z2({iframeRef:e,overlayRef:r}),a=i.width>0&&i.height>0;return(0,W.jsxs)(`div`,{ref:r,"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 z-20`,children:[a&&t&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{"data-testid":`preview-ruler-top`,className:`absolute bg-black/70`,style:{left:i.left,top:i.top-L2,width:i.width,height:L2},children:qnn.map(e=>(0,W.jsx)(`span`,{className:`absolute bottom-0 border-l text-[9px] leading-none tabular-nums pl-0.5 h-2.5`,style:{left:`${e}%`,borderColor:$2,color:$2},children:e},e))}),(0,W.jsx)(`div`,{"data-testid":`preview-ruler-left`,className:`absolute bg-black/70`,style:{left:i.left-L2,top:i.top,width:L2,height:i.height},children:qnn.map(e=>(0,W.jsx)(`span`,{className:`absolute right-0 border-t text-[9px] leading-none tabular-nums pt-0.5 w-2.5`,style:{top:`${e}%`,borderColor:$2,color:$2},children:e},e))})]}),a&&n&&(0,W.jsx)(`div`,{className:`absolute`,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:Vnn.map(e=>(0,W.jsx)(Znn,{boxPercent:e},e))})]})}var e4=7,Xnn=[{edge:`top`,style:{left:`50%`,top:-(e4+1)/2,width:1,height:e4}},{edge:`bottom`,style:{left:`50%`,bottom:-(e4+1)/2,width:1,height:e4}},{edge:`left`,style:{top:`50%`,left:-(e4+1)/2,width:e4,height:1}},{edge:`right`,style:{top:`50%`,right:-(e4+1)/2,width:e4,height:1}}];function Znn({boxPercent:e}){let t=`${Hnn(e)}%`;return(0,W.jsx)(`div`,{"data-testid":`preview-safe-${e}`,className:`absolute border border-white/90`,style:{left:t,top:t,right:t,bottom:t},children:Xnn.map(({edge:e,style:t})=>(0,W.jsx)(`span`,{className:`absolute bg-white/90`,style:t},e))})}function Qnn(e){return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)}function $nn(){return document.fullscreenElement}function ern(e,t,n){let r=t?.parentElement??t;if(!r)return;let i=r.getBoundingClientRect();(e.clientX<i.left||e.clientX>i.right||e.clientY<i.top||e.clientY>i.bottom)&&n?.(null)}function trn({portrait:e,previewOverlay:t,onSelectTimelineElement:n,onPreviewBlockDrop:r}){let{projectId:i,iframeRef:a,togglePlay:o,seek:s,onIframeLoad:c,previewSlots:l,onShadowIframeLoad:u,onShadowReadyChange:d,onShadowError:f,setShadowIframeNode:p,resetPreviewSlots:m,compositionStack:h,handleNavigateComposition:g,setCompositionLoading:_,timelineDisabled:v,hasLoadedOnceRef:y,previewCompositionSize:b,setPreviewCompositionSize:x}=k2(),S=(0,U.useRef)(null),C=(0,U.useCallback)(e=>{S.current=e.current},[]),{isDragOver:w,handleDragEnter:T,handleDragOver:E,handleDragLeave:D,handleDrop:O}=ynn({portrait:e,compositionSize:b,stageRef:S,onBlockDrop:r}),k=(0,U.useRef)(null),A=(0,U.useSyncExternalStore)(Qnn,$nn),j=A===k.current&&A!=null,M=(0,U.useCallback)(()=>{k.current&&(document.fullscreenElement?document.exitFullscreen():k.current.requestFullscreen())},[]),N=h[h.length-1],P=h.length>1?N.previewUrl:void 0;return(0,W.jsxs)(`div`,{ref:k,className:`scheme-dark flex-1 min-h-0 flex flex-col overflow-hidden bg-[var(--studio-preview-bg,var(--color-neutral-950))] ${j?``:`m-3 rounded-md border border-border`}`,"data-studio-fullscreen-target":``,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-h-0 relative overflow-hidden`,"data-preview-pan-surface":`true`,onPointerDown:e=>ern(e,a.current,n),onDragEnter:T,onDragOver:E,onDragLeave:D,onDrop:O,children:[(0,W.jsxs)(`div`,{className:`absolute inset-0 overflow-hidden`,children:[(0,W.jsx)(unn,{projectId:i,iframeRef:a,onIframeLoad:c,previewSlots:l,onShadowIframeLoad:u,onShadowReadyChange:d,onShadowError:f,setShadowIframeNode:p,resetPreviewSlots:m,onCompositionLoadingChange:_,portrait:e,directUrl:P,suppressLoadingOverlay:y.current,onStageRef:C,onCompositionSizeChange:x}),w&&(0,W.jsx)(`div`,{className:`absolute inset-2 z-40 rounded-lg border-2 border-dashed border-studio-accent/50 bg-studio-accent/4 pointer-events-none`}),(0,W.jsx)(Tnn,{})]}),(0,W.jsxs)(Knn,{children:[(0,W.jsx)(Jnn,{}),!j&&t]})]}),(0,W.jsxs)(`div`,{className:`shrink-0`,children:[!j&&h.length>1&&(0,W.jsx)(dnn,{stack:h,onNavigate:g}),(0,W.jsx)(xLt,{onTogglePlay:o,onSeek:s,disabled:v,isFullscreen:j,onToggleFullscreen:M})]})]})}var t4=gb(e=>({visible:Ub().audioMetersVisible??!1,setVisible:t=>{Wb({audioMetersVisible:t}),e({visible:t})}})),nrn=[0,-3,-6,-12,-24],rrn=-60,n4=[...nrn,rrn],irn=.9,arn=1200;function orn(e){let t=e>0?an(e):rrn;if(t>=0)return 1;if(t<=rrn)return 0;let n=n4.findIndex(e=>t>=e),r=n4[n-1],i=n4[n];return(n4.length-1-n+(t-i)/(r-i))/(n4.length-1)}function r4(e){return orn(be(e))}var srn={level:0,peak:0,peakAt:0};function crn(e,t,n,r){let i=r/1e3*irn,a=orn(t),o=Math.max(a,e.level-i);return a>=e.peak?{level:o,peak:a,peakAt:n}:n-e.peakAt<arn?{level:o,peak:e.peak,peakAt:e.peakAt}:{level:o,peak:Math.max(a,e.peak-i),peakAt:e.peakAt}}var lrn=e=>e.level===0&&e.peak===0;function urn(e,t,n,r){let[i,a]=e??[srn,srn],o=!t?.l&&!t?.r;return e&&o&&lrn(i)&&lrn(a)?e:[crn(i,t?.l??0,n,r),crn(a,t?.r??0,n,r)]}function drn(e){return e.some(e=>wG(e)||e.audioGroup!==void 0||e.hasAudio===!0&&!e.muted&&St(e))}function frn(){let e=X(e=>e.elements);return(0,U.useMemo)(()=>drn(e),[e])}var prn=`Monitor`,mrn=f3t;function hrn(e,t){return e||!t?e:Math.max(t.l,t.r)>=mrn}function i4(e,t){e&&(e.dataset.lit=String(t),e.style.setProperty(`background-color`,t?`var(--color-red-500)`:`var(--color-neutral-800)`),e.style.setProperty(`color`,t?`var(--color-white)`:`var(--color-neutral-500)`))}var a4=r4(-6),grn=r4(-3);function _rn(){let e=X(e=>e.elements),t=X(e=>e.audioVolume);return(0,U.useMemo)(()=>{let n=new Map,r=new Map;for(let t of e)t.audioGroup&&!n.has(t.audioGroup)&&(n.set(t.audioGroup,t.audioGroupLabel??t.audioGroup),r.set(t.audioGroup,t.audioGroupVolume??1));return[...[...n].map(([e,t])=>({id:e,label:t,volume:r.get(e)??1})),{id:null,label:prn,volume:t}]},[e,t])}function vrn(){let{onSetAudioGroupAttributeLive:e,onSetAudioGroupAttributeQuiet:t}=VX(),n=X(e=>e.setAudioVolume);return{onLive:(0,U.useCallback)((t,r)=>{t===null?n(r):e?.(t,`data-volume`,ce(r))},[e,n]),onCommit:(0,U.useCallback)((e,r)=>{e===null?n(r):t?.(e,`data-volume`,ce(r),`Set volume`)},[t,n])}}function yrn(e){try{return e?.contentWindow?.__hf?.audioMeter??null}catch{return null}}function brn(e,t){e&&(e.style.setProperty(`bottom`,`${t*100}%`),e.style.setProperty(`transform`,t>=1?`translateY(1px)`:`none`))}function xrn(e,t){t.forEach((t,n)=>{e?.[n]?.mask?.style.setProperty(`height`,`${(1-t.level)*100}%`),brn(e?.[n]?.peak??null,t.peak)})}function Srn(e,t){if(t===e)return e;try{e?.stop()}catch{}try{t?.start()}catch{}return t}function Crn(e,t){for(let n of[...e.keys()])t.has(n)||e.delete(n)}function wrn(e,t,n,r,i,a){for(let{id:o}of e){let e=t.get(o),s=urn(e,o===null?r?.master:r?.groups[o],i,a);s!==e&&(t.set(o,s),xrn(n.get(o),s))}}function Trn(e,t,n,r){let i=IX(),a=n??i?.previewIframeRef,o=(0,U.useRef)(e);o.current=e,(0,U.useEffect)(()=>{let e=0,n=null,i=performance.now(),s=new Map,c=l=>{e=requestAnimationFrame(c),n=Srn(n,yrn(a?.current));let u=n?.read(),d=l-i;i=l,Crn(s,new Set(o.current.map(e=>e.id))),wrn(o.current,s,t.current,u,l,d);let f=hrn(r.current.lit,u?.master);f!==r.current.lit&&(r.current.lit=f,i4(r.current.light,f))};return e=requestAnimationFrame(c),()=>{cancelAnimationFrame(e);try{n?.stop()}catch{}}},[a,t,r])}function Ern({clip:e}){return(0,W.jsx)(`button`,{type:`button`,"data-testid":`meter-clip-light`,"data-lit":`false`,title:`Lights when the preview reaches −1 dBFS, the export ceiling. Click to reset.`,ref:t=>{e.current.light=t,i4(t,e.current.lit)},onClick:()=>{e.current.lit=!1,i4(e.current.light,!1)},className:`rounded-[2px] px-1 font-mono text-[9px] leading-[14px] font-bold tracking-wide`,children:`CLIP`})}function Drn({maskRef:e,peakRef:t}){return(0,W.jsxs)(`div`,{className:`scheme-dark relative h-full w-[18px] overflow-hidden rounded-[2px] bg-neutral-900`,children:[(0,W.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-green-500`,style:{height:`${a4*100}%`}}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 bg-amber-500`,style:{bottom:`${a4*100}%`,height:`${(grn-a4)*100}%`}}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-0 bg-red-500`,style:{height:`${(1-grn)*100}%`}}),(0,W.jsx)(`div`,{ref:e,"data-testid":`meter-mask`,className:`absolute inset-x-0 top-0 bg-neutral-900`,style:{height:`100%`}}),(0,W.jsx)(`div`,{ref:t,"data-testid":`meter-peak`,className:`absolute inset-x-0 bottom-0 h-px bg-text-0`})]})}function Orn({label:e,title:t,volume:n,maxPosition:r,onLive:i,onCommit:a}){let o=(0,U.useRef)(null),s=(0,U.useRef)(null),c=Ce(n),l=r-cn,u=(c-cn)/l,d=x(n),f=(0,U.useCallback)(e=>{let t=o.current?.getBoundingClientRect();return!t||t.height===0?c:cn+e$(1-(e-t.top)/t.height,0,1)*l},[c,l]),p=e=>{let t=h(f(e));s.current=t,i(t)},m=()=>{if(s.current===null)return;let e=s.current;s.current=null,a(e)},g=new Map([[`ArrowUp`,c+l*.02],[`ArrowDown`,c-l*.02],[`PageUp`,c+l*.1],[`PageDown`,c-l*.1],[`Home`,cn],[`End`,r]]);return(0,W.jsx)(`div`,{ref:o,role:`slider`,tabIndex:0,"aria-label":e,title:`${t}: ${d}`,"aria-orientation":`vertical`,"aria-valuemin":cn,"aria-valuemax":r,"aria-valuenow":Math.round(c),"aria-valuetext":d,onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),p(e.clientY)},onPointerMove:e=>{s.current!==null&&p(e.clientY)},onPointerUp:m,onPointerCancel:m,onLostPointerCapture:m,onKeyDown:e=>{let t=g.get(e.key);t!==void 0&&(a(h(e$(t,cn,r))),e.preventDefault())},className:`relative h-full w-2 shrink-0 cursor-ns-resize touch-none rounded-full bg-neutral-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-studio-accent`,children:(0,W.jsx)(`div`,{className:`absolute inset-x-[-3px] h-1.5 -translate-y-1/2 rounded-full bg-neutral-200`,style:{bottom:`${u*100}%`}})})}function krn({strip:e,register:t,onLive:n,onCommit:r,clipLight:i}){let a=[(0,U.useRef)(null),(0,U.useRef)(null),(0,U.useRef)(null),(0,U.useRef)(null)];return(0,U.useEffect)(()=>(t(e.id,[{mask:a[0].current,peak:a[1].current},{mask:a[2].current,peak:a[3].current}]),()=>t(e.id,null)),[e.id,t]),(0,W.jsxs)(`div`,{className:`flex w-[104px] shrink-0 flex-col items-center gap-1 px-1.5 pt-2 pb-1`,children:[i,(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-stretch gap-1.5`,"aria-label":`${e.label} level`,children:[(0,W.jsx)(Orn,{label:`${e.label} volume`,title:e.id===null?`Preview monitor volume`:`${e.label} volume`,volume:e.volume,maxPosition:e.id===null?Ce(1):100,onLive:t=>n(e.id,t),onCommit:t=>r(e.id,t)}),(0,W.jsx)(`div`,{className:`relative w-5 font-mono text-[9px] leading-none text-neutral-500`,children:nrn.map(e=>(0,W.jsx)(`span`,{className:`absolute right-0 translate-y-1/2`,style:{bottom:`${r4(e)*100}%`},children:e},e))}),(0,W.jsxs)(`div`,{className:`flex items-stretch gap-0.5`,children:[(0,W.jsx)(Drn,{maskRef:a[0],peakRef:a[1]}),(0,W.jsx)(Drn,{maskRef:a[2],peakRef:a[3]})]})]}),(0,W.jsx)(`span`,{className:`max-w-full truncate text-[10px] text-neutral-400`,title:e.label,children:e.label})]})}var Arn=(0,U.memo)(function({previewIframeRef:e}){let t=t4(e=>e.visible),n=frn();return!t||!n?null:(0,W.jsx)(jrn,{previewIframeRef:e})});function jrn({previewIframeRef:e}){let t=_rn(),n=(0,U.useRef)(new Map),r=(0,U.useRef)((e,t)=>{t?n.current.set(e,t):n.current.delete(e)}).current,{onLive:i,onCommit:a}=vrn(),o=(0,U.useRef)({lit:!1,light:null});return Trn(t,n,e,o),(0,W.jsx)(`div`,{"data-testid":`audio-meter-strip`,className:`flex shrink-0 overflow-x-auto border-l border-neutral-800/50 bg-neutral-950`,children:t.map(e=>(0,W.jsx)(krn,{strip:e,register:r,onLive:i,onCommit:a,clipLight:e.id===null?(0,W.jsx)(Ern,{clip:o}):void 0},e.id??`master`))})}function Mrn({timelineToolbar:e,timelineFooter:t,timelineOverlay:n,renderClipContent:r,onFileDrop:i,onDeleteElement:a,onAssetDrop:o,onBlockDrop:s,onCompositionDrop:c,onBlockedEditAttempt:l,onSelectTimelineElement:u,onRangeSelect:d,onCopyClip:f,onPasteClip:p,onDuplicateClip:m,canPasteClip:h,clipMenuItems:g,splitShortcut:_}){let{seek:v,handleDrillDown:y,compositionStack:b,updateCompositionStack:x,timelineDisabled:S,timelineSessionEpoch:C}=k2(),{onMoveElement:w,onMoveElements:T,onResizeElement:E,onResizeElements:D,onSplitElement:O}=QJt();return(0,W.jsxs)(`div`,{className:`relative flex h-full flex-col`,"data-studio-timeline":`true`,"aria-disabled":S||void 0,children:[(0,W.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0 overflow-hidden`,onDoubleClick:e=>{e.target.closest(`[data-clip]`)||S||b.length>1&&x(e=>e.slice(0,-1))},children:[(0,W.jsx)(`div`,{className:`shrink-0`,children:e}),(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,W.jsx)(t5t,{sessionEpoch:C,onSeek:v,onDrillDown:y,renderClipContent:r,onFileDrop:i,onDeleteElement:a,onAssetDrop:o,onBlockDrop:s,onCompositionDrop:c,onMoveElement:w,onMoveElements:T,onResizeElement:E,onResizeElements:D,onBlockedEditAttempt:l,onSplitElement:O,onSelectElement:u,onRangeSelect:d,onCopyClip:f,onPasteClip:p,onDuplicateClip:m,canPasteClip:h,clipMenuItems:g,splitShortcut:_})}),(0,W.jsx)(Arn,{})]})]}),t&&(0,W.jsx)(`div`,{className:`shrink-0`,children:t}),n&&(0,W.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-20`,children:n}),S&&(0,W.jsx)(`div`,{className:`absolute inset-0 z-30 cursor-not-allowed bg-black/18 flex items-center justify-center`,"data-testid":`timeline-loading-disabled-overlay`,role:`status`,onPointerDown:e=>e.preventDefault(),onDragOver:e=>e.preventDefault(),onDrop:e=>e.preventDefault(),children:(0,W.jsx)(`span`,{className:`rounded-md bg-neutral-900/90 px-2.5 py-1 text-[11px] text-neutral-400`,children:`Loading composition…`})})]})}var Nrn=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`]);function Prn(e,t){return e.metaKey||e.ctrlKey||e.altKey||t!=null&&oX(t)?!1:Nrn.has(e.key)}function Frn(e,t,n){let r=null,i=null;try{r=e.contentDocument,i=e.contentWindow}catch{return[]}if(!r||!i)return[];let a=e.getBoundingClientRect(),o=n.getBoundingClientRect(),s=parseFloat(e.style.width)||a.width,c=a.width/s,l=a.left-o.left,u=a.top-o.top,d=r.querySelectorAll(`.caption-group`),f=[];for(let e=0;e<t.groupOrder.length;e++){let n=t.groupOrder[e],a=t.groups.get(n);if(!a)continue;let o=d[e];if(!o)continue;let s=i.getComputedStyle(o);if(parseFloat(s.opacity)<=.01||s.visibility===`hidden`)continue;let p=[];for(let e of o.children){let t=e;if(t.dataset.captionWrapper===`true`){let e=t.querySelector(`:scope > span`);e&&p.push(e)}else t.tagName===`SPAN`&&p.push(t)}if(p.length===0&&o.textContent?.trim()){let e=o.childNodes[0];if(e&&e.nodeType===Node.TEXT_NODE){let t=(e.textContent||``).split(/\s+/).filter(Boolean),n=r.createDocumentFragment();for(let e of t){let t=r.createElement(`span`);t.textContent=e+` `,t.style.display=`inline`,n.appendChild(t),p.push(t)}o.replaceChild(n,e)}else{let e=o.querySelector(`:scope > span`);if(e&&e.textContent?.trim()){let t=e.textContent.split(/\s+/).filter(Boolean),n=r.createDocumentFragment();for(let e of t){let t=r.createElement(`span`);t.textContent=e+` `,t.style.display=`inline`,n.appendChild(t),p.push(t)}e.replaceWith(n)}}}for(let t=0;t<a.segmentIds.length;t++){let r=a.segmentIds[t],i=p[t];if(!i)continue;let o=i.getBoundingClientRect();f.push({segmentId:r,groupId:n,groupIndex:e,wordIndex:t,x:o.left*c+l,y:o.top*c+u,width:o.width*c,height:o.height*c})}}return f}function o4(e,t,n){let r=null;try{r=e.contentDocument}catch{return null}if(!r)return null;let i=r.querySelectorAll(`.caption-group`)[t];if(!i)return null;let a=[];for(let e of i.children){let t=e;if(t.dataset.captionWrapper===`true`){let e=t.querySelector(`:scope > span`);e&&a.push(e)}else t.tagName===`SPAN`&&a.push(t)}return a[n]??null}function s4(e,t){let n=t.gsap;if(n&&n.getProperty)return{x:n.getProperty(e,`x`)||0,y:n.getProperty(e,`y`)||0,scale:n.getProperty(e,`scale`)||1,rotation:n.getProperty(e,`rotation`)||0};let r=e.style.transform||``,i=r.match(/scale\(([^)]+)\)/),a=r.match(/rotate\(([^)]+)deg\)/),o=r.match(/translate\(([^,]+)px,\s*([^)]+)px\)/);return{x:o?parseFloat(o[1]):0,y:o?parseFloat(o[2]):0,scale:i?parseFloat(i[1]):1,rotation:a?parseFloat(a[1]):0}}function c4(e){if(e.dataset.captionWrapper===`true`)return e;let t=e.parentElement;if(t&&t.dataset.captionWrapper===`true`)return t;let n=e.ownerDocument.createElement(`span`);return n.style.display=`inline-block`,n.dataset.captionWrapper=`true`,e.parentNode?.insertBefore(n,e),n.appendChild(e),n}function l4(e,t,n,r,i,a){let o=c4(e),s=t.gsap;s&&s.set?s.set(o,{x:n,y:r,scale:i,rotation:a}):o.style.transform=`translate(${n.toFixed(1)}px, ${r.toFixed(1)}px) rotate(${a.toFixed(1)}deg) scale(${i.toFixed(3)})`}var u4=null;function Irn(e){return u4=e,()=>{u4===e&&(u4=null)}}function Lrn(){let e=u4?.current;return!!(e?.isConnected&&e.offsetParent!==null)}function Rrn(e){let t=u4?.current;if(!t)return;let n=null;try{n=t.contentWindow}catch{return}if(n)for(let r=0;r<e.groupOrder.length;r++){let i=e.groups.get(e.groupOrder[r]);if(i)for(let a=0;a<i.segmentIds.length;a++){let o=e.segments.get(i.segmentIds[a]);if(!o)continue;let s=o4(t,r,a);if(!s)continue;let c=o.style;l4(s,n,c.x??0,c.y??0,c.scaleX??1,c.rotation??0)}}}function zrn(e,t){let{x:n,y:r,scale:i,rotation:a}=s4(c4(e),t),o={};return Math.abs(n)>.5&&(o.x=n),Math.abs(r)>.5&&(o.y=r),Math.abs(i-1)>.001&&(o.scaleX=i,o.scaleY=i),Math.abs(a)>.1&&(o.rotation=a),o}var d4=8,f4=24,p4=20;function Brn(e,t,n){let r=zrn(t,n);Object.keys(r).length>0&&O1.getState().updateSegmentStyle(e,r)}var Vrn=(0,U.memo)(function({iframeRef:e}){let t=O1(e=>e.isEditMode),n=xZ(),r=O1(e=>e.model),i=O1(e=>e.selectedSegmentIds),a=O1(e=>e.selectSegment),o=O1(e=>e.clearSelection),[s,c]=(0,U.useState)([]),l=(0,U.useRef)(null),u=(0,U.useRef)(r);u.current=r;let d=(0,U.useRef)(null),f=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!t)return;let n=Irn(e),r=[],i=null,a=()=>{i=null;let t=e.current,n=u.current,a=l.current;if(!t||!n||!a)return;let o=Frn(t,n,a);o.length===r.length&&o.every((e,t)=>Math.abs(e.x-r[t].x)<.5&&Math.abs(e.y-r[t].y)<.5)||(r=o,c(o))},o=()=>{i===null&&(i=requestAnimationFrame(a))},s=X.subscribe(o),p=t=>{!t.source||t.source!==e.current?.contentWindow||t.data?.source===`hf-preview`&&o()};window.addEventListener(`message`,p),window.addEventListener(`resize`,o);let m=new ResizeObserver(o);e.current&&m.observe(e.current),l.current&&m.observe(l.current);let h=null,g=()=>{let e=X.getState().isPlaying;e&&h===null?h=setInterval(o,66):!e&&h!==null&&(clearInterval(h),h=null)},_=X.subscribe(g);g(),a();let v=()=>{try{return e.current?.contentWindow??null}catch{return null}},y=()=>{let e=f.current;if(!e)return!1;let t=v();return t&&l4(e.wordEl,t,e.origTX,e.origTY,e.origScale,e.origRotation),f.current=null,!0};d.current=y;let b=t=>{let n=O1.getState(),{selectedSegmentIds:r,model:i}=n;if(t.key===`Escape`){if(y()){t.preventDefault(),o();return}r.size>0&&(t.preventDefault(),n.clearSelection());return}if((t.metaKey||t.ctrlKey)&&t.key.toLowerCase()===`a`&&!t.shiftKey&&!t.altKey&&!aX(t.target)){t.preventDefault(),n.selectAll();return}if(r.size===0||!i)return;let a=t.key;if(!Prn(t,t.target))return;t.preventDefault();let s=t.shiftKey?10:1,c=a===`ArrowLeft`?-s:a===`ArrowRight`?s:0,l=a===`ArrowUp`?-s:a===`ArrowDown`?s:0,u=e.current,d=u?.contentWindow;if(!(!u||!d)){for(let e of r)for(let t=0;t<i.groupOrder.length;t++){let n=i.groups.get(i.groupOrder[t]);if(!n)continue;let r=n.segmentIds.indexOf(e);if(r<0)continue;let a=o4(u,t,r);if(!a)continue;let o=s4(c4(a),d);l4(a,d,o.x+c,o.y+l,o.scale,o.rotation),Brn(e,a,d);break}o()}};return window.addEventListener(`keydown`,b),()=>{n(),s(),_(),h!==null&&clearInterval(h),i!==null&&cancelAnimationFrame(i),m.disconnect(),window.removeEventListener(`message`,p),window.removeEventListener(`resize`,o),window.removeEventListener(`keydown`,b),d.current=null}},[n]);let p=(0,U.useCallback)(()=>{let t=e.current;if(!t)return 1;let n=t.getBoundingClientRect(),r=parseFloat(t.style.width)||n.width;return n.width/r},[e]),m=(0,U.useCallback)((t,n,r,i)=>{i.stopPropagation(),i.currentTarget.setPointerCapture(i.pointerId);let a=e.current;if(!a)return;let o=o4(a,t,n),s=a.contentWindow;if(!o||!s)return;let c=s4(c4(o),s);f.current={type:`move`,wordEl:o,segmentId:r,startMX:i.clientX,startMY:i.clientY,origTX:c.x,origTY:c.y,origScale:c.scale,origRotation:c.rotation}},[e]),h=(0,U.useCallback)((t,n,r,i)=>{i.stopPropagation(),i.preventDefault(),i.currentTarget.setPointerCapture(i.pointerId);let a=e.current;if(!a)return;let o=o4(a,t,n),s=a.contentWindow;if(!o||!s)return;let c=o.getBoundingClientRect(),l=p(),u=c.left*l+(e.current?.getBoundingClientRect().left??0)+c.width*l/2,d=s4(c4(o),s);f.current={type:`scale`,wordEl:o,segmentId:r,startMX:i.clientX,startDxFromCenter:i.clientX-u,origTX:d.x,origTY:d.y,origScale:d.scale,origRotation:d.rotation}},[e,p]),g=(0,U.useCallback)((t,n)=>{n.stopPropagation(),n.preventDefault(),n.currentTarget.setPointerCapture(n.pointerId);let r=e.current;if(!r)return;let i=o4(r,t.groupIndex,t.wordIndex),a=r.contentWindow;if(!i||!a)return;let o=s4(c4(i),a);f.current={type:`rotate`,wordEl:i,segmentId:t.segmentId,startMX:n.clientX,origTX:o.x,origTY:o.y,origRotation:o.rotation,origScale:o.scale}},[e]),_=(0,U.useCallback)(()=>{try{return e.current?.contentWindow??null}catch{return null}},[e]),v=(0,U.useCallback)(e=>{let t=f.current;if(!t)return;let n=_();if(n){if(t.type===`move`){let r=p(),i=(e.clientX-t.startMX)/r,a=(e.clientY-t.startMY)/r;l4(t.wordEl,n,t.origTX+i,t.origTY+a,t.origScale,t.origRotation)}else if(t.type===`scale`){let r=t.startMX-t.startDxFromCenter,i=Math.abs(t.startDxFromCenter),a=Math.abs(e.clientX-r),o=i>5?a/i:1,s=Math.max(.1,t.origScale*o);l4(t.wordEl,n,t.origTX,t.origTY,s,t.origRotation)}else if(t.type===`rotate`){let r=(e.clientX-t.startMX)/200*90;l4(t.wordEl,n,t.origTX,t.origTY,t.origScale,t.origRotation+r)}}},[p,_]),y=(0,U.useCallback)(()=>{let e=f.current;if(e){let t=_();t&&Brn(e.segmentId,e.wordEl,t),f.current=null}},[_]),b=(0,U.useCallback)(e=>{e.target===e.currentTarget&&o()},[o]);return t?(0,W.jsxs)(`div`,{ref:l,className:`absolute inset-0 z-50`,style:{pointerEvents:`auto`},onClick:b,onPointerMove:v,onPointerUp:y,onLostPointerCapture:y,children:[s.length===0&&r&&r.segments.size>0&&(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-3 flex justify-center pointer-events-none`,children:(0,W.jsx)(`span`,{className:`px-2.5 py-1 rounded-full bg-black/60 border border-neutral-700 text-2xs text-neutral-300`,children:`No captions visible at this frame — scrub to a caption, or select one in the track below`})}),s.map(e=>{let t=i.has(e.segmentId);return(0,W.jsx)(`div`,{className:[`absolute`,t?`ring-2 ring-studio-accent`:`hover:ring-1 hover:ring-white/30`].join(` `),style:{left:e.x,top:e.y,width:e.width,height:e.height,cursor:t?`move`:`pointer`,touchAction:`none`,borderRadius:2},onClick:t=>{t.stopPropagation(),a(e.segmentId,t.shiftKey)},onPointerDown:n=>{t&&m(e.groupIndex,e.wordIndex,e.segmentId,n)},children:t&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{style:{position:`absolute`,left:`50%`,top:-p4-d4/2-f4/2,marginLeft:-f4/2,width:f4,height:f4,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`grab`,touchAction:`none`},onPointerDown:t=>g(e,t),children:(0,W.jsx)(`div`,{style:{width:d4,height:d4,borderRadius:`50%`,backgroundColor:`var(--hf-accent, #3CE6AC)`,border:`1px solid rgba(0,0,0,0.5)`}})}),(0,W.jsx)(`div`,{style:{position:`absolute`,left:`50%`,top:-p4,width:1,height:p4,marginLeft:-.5,backgroundColor:`var(--hf-accent, #3CE6AC)`,opacity:.5,pointerEvents:`none`}}),[{corner:{right:-f4/2,bottom:-f4/2},cursor:`nwse-resize`},{corner:{left:-f4/2,top:-f4/2},cursor:`nwse-resize`},{corner:{right:-f4/2,top:-f4/2},cursor:`nesw-resize`},{corner:{left:-f4/2,bottom:-f4/2},cursor:`nesw-resize`}].map(({corner:t,cursor:n},r)=>(0,W.jsx)(`div`,{style:{position:`absolute`,...t,width:f4,height:f4,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:n,touchAction:`none`},onPointerDown:t=>h(e.groupIndex,e.wordIndex,e.segmentId,t),children:(0,W.jsx)(`div`,{style:{width:d4,height:d4,backgroundColor:`var(--hf-accent, #3CE6AC)`,border:`1px solid rgba(0,0,0,0.5)`,borderRadius:2}})},r))]})},e.segmentId)})]}):null});function m4(e,t){mG(`feature_used`,{feature:e,surface:`preview`,method:t})}function h4(e,t,n){if(typeof n!=`object`||!n||Reflect.get(n,`ok`)===!1)return;let r=Reflect.get(n,`persistence`);(Reflect.get(n,`changed`)===!0||typeof r==`object`&&r&&Reflect.get(r,`changed`)===!0)&&m4(e,t)}var Hrn=.95,Urn=new Set([`video`,`img`,`canvas`,`svg`]);function Wrn(e,t){return t.width<=1||t.height<=1?!1:e.width/t.width>=Hrn&&e.height/t.height>=Hrn}function g4(e,t){return!Urn.has(e.tagName.toLowerCase())&&Wrn(e.getBoundingClientRect(),t)}function Grn(e,t,n,r,i){let a=e.getBoundingClientRect(),o=(t.querySelector(`[data-composition-id]`)??t.documentElement??null)?.getBoundingClientRect(),s=o?.width||n.innerWidth,c=o?.height||n.innerHeight;if(!s||!c)return null;let l=a.width/s,u=a.height/c;return{x:(r-a.left)/l,y:(i-a.top)/u,viewport:{width:s,height:c}}}var Krn=new WeakMap;function qrn(e,t){let n=Krn.get(e);if(n!==void 0)return n;let r=e.createElement(`div`),i=e.createElement(`div`);r.style.pointerEvents=`none`,r.appendChild(i);let a=e.body??e.documentElement;if(!a)return!1;a.appendChild(r);let o=t.getComputedStyle(i).pointerEvents!==`none`;return r.remove(),Krn.set(e,o),o}function Jrn(e,t){let n=t.getComputedStyle(e).pointerEvents;return n!==``&&n!==`inherit`&&n!==`unset`}function Yrn(e,t){let n=e.parentElement;for(;n;){if(t.getComputedStyle(n).pointerEvents===`none`){let r=e;for(;r&&r!==n;){if(Jrn(r,t))return t.getComputedStyle(r).pointerEvents===`none`;r=r.parentElement}return!0}n=n.parentElement}return!1}function _4(e){let t=e.ownerDocument.defaultView;return t?t.getComputedStyle(e).pointerEvents===`none`?!0:qrn(e.ownerDocument,t)?Yrn(e,t):!1:!1}function Xrn(e){let t=new WeakSet;for(let n of e)Ft(n)&&_4(n)&&t.add(n);return t}function Zrn(e,t){let n=Xrn(e);return xt(e,{activeCompositionPath:t}).filter(e=>!n.has(e))}function Qrn(e,t,n){let r=null,i=1/0;for(let a of Array.from(e.querySelectorAll(`[data-hf-group]`))){let e=1/0,o=1/0,s=-1/0,c=-1/0;for(let t of Array.from(a.children)){let n=t.getBoundingClientRect();(n.width!==0||n.height!==0)&&(e=Math.min(e,n.left),o=Math.min(o,n.top),s=Math.max(s,n.right),c=Math.max(c,n.bottom))}if(s<e||t<e||t>s||n<o||n>c)continue;let l=(s-e)*(c-o);l<i&&(i=l,r=a)}return r}function v4(e,t,n,r){let i=null,a=null;try{i=e.contentDocument,a=e.contentWindow}catch{return null}if(!i||!a)return null;let o=Grn(e,i,a,t,n);if(!o)return null;if(typeof i.elementsFromPoint==`function`){let e=Zrn(i.elementsFromPoint(o.x,o.y),r).find(e=>!g4(e,o.viewport))??null;if(e)return e}let s=Qrn(i,o.x,o.y);if(s&&!_4(s)&&ye(s,r))return s;let c=Q0t(i.elementFromPoint(o.x,o.y));return!c||!ye(c,r)||_4(c)||!m(c)||g4(c,o.viewport)?null:c}function $rn(e,t,n,r){let i=null,a=null;try{i=e.contentDocument,a=e.contentWindow}catch{return[]}if(!i||!a)return[];let o=Grn(e,i,a,t,n);if(!o)return[];if(typeof i.elementsFromPoint==`function`)return Zrn(i.elementsFromPoint(o.x,o.y),r).filter(e=>!g4(e,o.viewport));let s=Q0t(i.elementFromPoint(o.x,o.y));return!s||!ye(s,r)||_4(s)||!m(s)||g4(s,o.viewport)?[]:[s]}function y4(e){return e&&(typeof e==`object`||typeof e==`function`)?e:null}function b4(e,t){let n=e?Reflect.get(e,t):null;if(typeof n==`function`)try{n.call(e)}catch{}}function x4(e,t){let n=e?Reflect.get(e,t):null;if(typeof n!=`function`)return null;try{let t=n.call(e);return typeof t==`number`&&Number.isFinite(t)?t:null}catch{return null}}function ein(e){let t=e?.contentWindow;if(!t)return null;try{let e=y4(Reflect.get(t,`__player`)),n=x4(e,`getTime`);if(typeof(e?Reflect.get(e,`pause`):null)==`function`)return b4(e,`pause`),n;let r=null,i=y4(Reflect.get(t,`__timeline`));r??=x4(i,`time`),b4(i,`pause`);let a=y4(Reflect.get(t,`__timelines`));if(a)for(let e of Object.values(a)){let t=y4(e);r??=x4(t,`time`),b4(t,`pause`)}return r}catch{return null}}function S4(e){if(!e)return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}function tin(e){return e?.querySelector(`[data-composition-id]`)??e?.documentElement??null}function nin(e){if(!e)return null;let t=e.getBoundingClientRect(),n=S4(e.getAttribute(`data-width`))??t.width,r=S4(e.getAttribute(`data-height`))??t.height;return!n||!r?null:{width:n,height:r}}function C4(e,t,n){let r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),a=nin(tin(n));return a?{iframeRect:r,overlayRect:i,rootScaleX:r.width/a.width,rootScaleY:r.height/a.height}:null}var rin=`data-composition-id`;function iin(e){if(!e||e===`none`)return 0;let t=e.trim().split(/\s+/),n=t.at(-1);if(!n?.endsWith(`deg`))return 0;if(t.length===4){let[e,r,i]=t;if(Number(e)!==0||Number(r)!==0||Math.abs(Number(i))!==1)return 0;let a=Number.parseFloat(n);return Number.isFinite(a)?a*Math.sign(Number(i)):0}if(t.length!==1)return 0;let r=Number.parseFloat(n);return Number.isFinite(r)?r:0}function ain(e,t,n){let r=n(e);if(!r)return null;let i=r.transform,a=i&&i!==`none`?t.fromTransform(i):t.identity();if(!a)return null;let o=iin(r.rotate);return o===0?a:t.compose(t.fromRotate(o),a)}function oin(e,t,n,r){let i=[],a;for(let t=e;t&&(a=r?.get(t),!(a!==void 0||(i.push(t),t.hasAttribute(rin))));t=t.parentElement);let o=a===void 0?t.identity():a;for(let e=i.length-1;e>=0;--e){let a=i[e];if(o!==null){let e=ain(a,t,n);o=e===null?null:t.compose(o,e)}r?.set(a,o)}return o}function w4(e){let t=y(e);return Number.isInteger(t)?`${t}`:t.toFixed(2).replace(/0+$/,``).replace(/\.$/,``)}function sin(e){return`${w4(Math.max(0,e))}px`}function cin(e){let t=e.trim();if(t===`0`)return 0;let n=/^(-?\d+(?:\.\d+)?)px$/i.exec(t);if(!n)return null;let r=Number.parseFloat(n[1]);return Number.isFinite(r)?Math.max(0,r):null}function lin(e){if(e.length<1||e.length>4)return null;let[t,n=t,r=t,i=n]=e;return t===void 0||n===void 0||r===void 0||i===void 0?null:{top:t,right:n,bottom:r,left:i}}function T4(e){let t=e?.trim();return!t||t===`none`?`none`:/^inset\(/i.test(t)?`inset`:/^circle\(/i.test(t)?`circle`:`custom`}function E4(e){let t=/^inset\(([^()]*)\)$/i.exec(e?.trim()??``);if(!t)return null;let n=t[1].trim().replace(/\s+/g,` `).split(/ round /i),r=n[0]?.trim();if(!r||n.length>2)return null;let i=r.split(/\s+/).map(cin);if(i.some(e=>e==null))return null;let a=[];for(let e of i){if(e==null)return null;a.push(e)}let o=lin(a);if(!o)return null;let s=n[1]?.trim(),c=s?cin(s):0;return c==null?null:{...o,radius:c}}function uin(e){let t=E4(e);if(!t)return 0;let{top:n,right:r,bottom:i,left:a}=t;return n===r&&n===i&&n===a?n:0}function din(e,t,n){return e===`custom`?n?.trim()||`none`:e===`circle`?`circle(50% at 50% 50%)`:e===`inset`?`inset(0 round ${w4(Math.max(0,t))}px)`:`none`}function D4(e,t=0){let[n,r,i,a]=[e.top,e.right,e.bottom,e.left].map(sin),o=n===r&&n===i&&n===a?n:`${n} ${r} ${i} ${a}`,s=Math.max(0,t);return s>0?`inset(${o} round ${w4(s)}px)`:`inset(${o})`}function fin(e,t){return`inset(${sin(e)} round ${w4(Math.max(0,t))}px)`}function pin(e,t,n,r){let i=n>0?n:1,a=r>0?r:1;return{left:e.left+t.left*i,top:e.top+t.top*a,width:Math.max(0,e.width-(t.left+t.right)*i),height:Math.max(0,e.height-(t.top+t.bottom)*a)}}var O4=new WeakMap;function min(e){let t=e=>`"${e.replace(/["\\]/g,`\\$&`)}"`,n=e.getAttribute(`data-hf-id`);return n?`[data-hf-id=${t(n)}]`:e.id?`[id=${t(e.id)}]`:null}function hin(e){let t=min(e);if(!t||O4.has(e))return;let n=e.ownerDocument,r=n.createElement(`style`);r.textContent=`${t}{clip-path:none!important}`,(n.head??n.documentElement).append(r),O4.set(e,{rule:r})}function gin(e){O4.get(e)?.rule.remove(),O4.delete(e)}function _in(e){return O4.has(e)}var vin=e=>e.ownerDocument.defaultView?.getComputedStyle(e).clipPath.trim()||``;function yin(e){let t=e.style.getPropertyValue(`clip-path`).trim(),n=O4.get(e);if(t||!n)return t||vin(e);if(n.sheetClip===void 0){let{parentNode:t,nextSibling:r}=n.rule;n.rule.remove(),n.sheetClip=vin(e),t?.insertBefore(n.rule,r)}return n.sheetClip}function bin(e){return!e||e===`none`?{top:0,right:0,bottom:0,left:0,radius:0}:E4(e)}function k4(e){return bin(yin(e))}function xin(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function A4(e,t){return Number.isFinite(e)?Math.min(Math.max(0,e),Math.max(0,t)):0}function Sin(e){let t=e.scaleX>0?e.scaleX:1,n=e.scaleY>0?e.scaleY:1,r={...e.startInsets};return e.edge===`left`?r.left=A4(e.startInsets.left+e.deltaX/t,e.width-r.right):e.edge===`right`?r.right=A4(e.startInsets.right-e.deltaX/t,e.width-r.left):e.edge===`top`?r.top=A4(e.startInsets.top+e.deltaY/n,e.height-r.bottom):r.bottom=A4(e.startInsets.bottom-e.deltaY/n,e.height-r.top),r}function Cin(e){let t=e.scaleX>0?e.scaleX:1,n=e.scaleY>0?e.scaleY:1,r=e.startInsets.left+e.startInsets.right,i=e.startInsets.top+e.startInsets.bottom,a=Math.min(Math.max(0,e.startInsets.left+e.deltaX/t),r),o=Math.min(Math.max(0,e.startInsets.top+e.deltaY/n),i);return{left:a,right:r-a,top:o,bottom:i-o}}function j4(e,t){let n=_in(t)?null:k4(t);return!n||n.top<=0&&n.right<=0&&n.bottom<=0&&n.left<=0?e:pin(e,n,e.editScaleX,e.editScaleY)}var win={a:1,b:0,c:0,d:1},M4=1e-6;function Tin(e){let t=/^matrix\(([^)]+)\)$/.exec(e);if(t){let[e,n,r,i]=t[1].split(`,`).map(e=>Number.parseFloat(e));return[e,n,r,i].every(Number.isFinite)?{a:e,b:n,c:r,d:i}:null}let n=/^matrix3d\(([^)]+)\)$/.exec(e);if(!n)return null;let r=n[1].split(`,`).map(e=>Number.parseFloat(e));return r.length!==16||!r.every(Number.isFinite)||![r[3],r[7],r[11]].every(e=>Math.abs(e)<M4)?null:{a:r[0],b:r[1],c:r[4],d:r[5]}}var Ein={identity:()=>win,fromTransform:Tin,fromRotate:e=>{let t=e*Math.PI/180;return{a:Math.cos(t),b:Math.sin(t),c:-Math.sin(t),d:Math.cos(t)}},compose:(e,t)=>({a:e.a*t.a+e.c*t.b,b:e.b*t.a+e.d*t.b,c:e.a*t.c+e.c*t.d,d:e.b*t.c+e.d*t.d})};function Din(e){return Math.abs(e.a-1)<M4&&Math.abs(e.b)<M4&&Math.abs(e.c)<M4&&Math.abs(e.d-1)<M4}function Oin(e){let t=oin(e,Ein,e=>{try{return e.ownerDocument.defaultView?.getComputedStyle(e)??null}catch{return null}});return t&&!Din(t)?t:null}function kin(e,t){let n=t.editScaleX>0?t.editScaleX:1,r=t.editScaleY>0?t.editScaleY:1,i={angleDeg:0,left:t.left,top:t.top,width:t.width,height:t.height,scaleX:n,scaleY:r},a=Oin(e);if(!a)return i;let{a:o,b:s,c,d:l}=a,u=Math.hypot(o,s),d=o*l-s*c,f=u===0?1:Math.abs(d)/u;if(u<=0||f<=0)return i;let p=Math.atan2(s,o)*180/Math.PI,m=u*n,h=f*r,g=e.offsetWidth*m,_=e.offsetHeight*h;if(!(g>0)||!(_>0))return i;let v=t.left+t.width/2,y=t.top+t.height/2;return{angleDeg:p,left:v-g/2,top:y-_/2,width:g,height:_,scaleX:m,scaleY:h}}function Ain(e,t,n){if(n===0)return{deltaX:e,deltaY:t};let r=-n*Math.PI/180,i=Math.cos(r),a=Math.sin(r);return{deltaX:e*i-t*a,deltaY:e*a+t*i}}function jin(){return{visible:new Map,transform:new Map,sourceBoundary:new Map,sourceBoundaryRect:new Map}}function Min(e,t,n){let r=e.get(t);if(r!==void 0)return r;let i=n();return e.set(t,i),i}var N4=16,P4=(e,t,n)=>({...e,left:e.left+t,top:e.top+n});function F4(e){return qe(e)}var Nin=e=>e.hasAttribute(`data-composition-file`)||e.hasAttribute(`data-composition-src`);function Pin(e,t){let n=[],r;for(let i=e;i&&(r=t?.sourceBoundary.get(i),r===void 0);i=i.parentElement){if(Nin(i)){r=i,t?.sourceBoundary.set(i,i);break}n.push(i)}let i=r??null;if(t)for(let e of n)t.sourceBoundary.set(e,i);return i}function Fin(e){let t=e.rootScaleX>0?e.rootScaleX:1,n=e.rootScaleY>0?e.rootScaleY:1,r=e.sourceRectWidth&&e.sourceRectWidth>0&&e.sourceWidth&&e.sourceWidth>0?e.sourceRectWidth*t/e.sourceWidth:t,i=e.sourceRectHeight&&e.sourceRectHeight>0&&e.sourceHeight&&e.sourceHeight>0?e.sourceRectHeight*n/e.sourceHeight:n;return{scaleX:r>0?r:t,scaleY:i>0?i:n}}function I4(e,t,n,r){let i=L4(e,t,n,r);return i?{...i,...j4(i,n)}:null}function Iin(e,t,n){let r=C4(e,t,t.contentDocument);return r?n.map(n=>{let i=L4(e,t,n,r);return i?{...i,...j4(i,n)}:null}):n.map(()=>null)}function Lin(e,t,n){let r=e.DOMMatrix;if(!r)return null;let i=e.getComputedStyle(t),a={identity:()=>new r,fromTransform:e=>new r(e),fromRotate:e=>new r().rotateSelf(e),compose:(e,t)=>e.multiply(t)};try{let r=oin(t,a,n=>n===t?i:e.getComputedStyle(n),n?.transform);return r?{matrix:r,cs:i}:null}catch{return null}}function Rin(e){let t=Number.isFinite(e.a)?e.a:1,n=Number.isFinite(e.b)?e.b:0,r=Number.isFinite(e.c)?e.c:0,i=Number.isFinite(e.d)?e.d:1,a=Math.atan2(n,t)*180/Math.PI,o=t*i-n*r,s=Math.atan2(-r,i)*180/Math.PI,c=o<0&&Math.abs(s)<Math.abs(a)?s:a;return Number.isFinite(c)?c:0}var zin=1e-4;function L4(e,t,n,r,i){let a=r??C4(e,t,t.contentDocument);if(!a)return null;let{iframeRect:o,overlayRect:s,rootScaleX:c,rootScaleY:l}=a,u=n.getBoundingClientRect(),d=Pin(n,i),f=d&&i?Min(i.sourceBoundaryRect,d,()=>d.getBoundingClientRect()):d?.getBoundingClientRect(),p=Fin({rootScaleX:c,rootScaleY:l,sourceRectWidth:f?.width,sourceRectHeight:f?.height,sourceWidth:S4(d?.getAttribute(`data-width`)??null),sourceHeight:S4(d?.getAttribute(`data-height`)??null)});return{left:o.left-s.left+u.left*c,top:o.top-s.top+u.top*l,width:u.width*c,height:u.height*l,editScaleX:p.scaleX,editScaleY:p.scaleY}}function R4(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function Bin(e){return{x:(e.nw.x+e.ne.x+e.se.x+e.sw.x)/4,y:(e.nw.y+e.ne.y+e.se.y+e.sw.y)/4}}function z4(e,t,n,r,i){let a=t.contentWindow,o=t.contentDocument;if(!a||!o)return null;let s=a.DOMPoint;if(!s)return null;let c=r??C4(e,t,o);if(!c)return null;let{iframeRect:l,overlayRect:u,rootScaleX:d,rootScaleY:f}=c,p=i??Lin(a,n);if(!p)return null;let{matrix:m,cs:h}=p,g=n.offsetWidth,_=n.offsetHeight,v=h.transformOrigin.split(` `).map(e=>Number.parseFloat(e)),y=Number.isFinite(v[0])?v[0]:g/2,b=Number.isFinite(v[1])?v[1]:_/2,x=(e,t)=>{let n=m.transformPoint(new s(e-y,t-b));return{x:n.x,y:n.y}},S={nw:x(0,0),ne:x(g,0),se:x(g,_),sw:x(0,_)},C=[S.nw.x,S.ne.x,S.se.x,S.sw.x],w=[S.nw.y,S.ne.y,S.se.y,S.sw.y],T=n.getBoundingClientRect(),E=T.left-Math.min(...C),D=T.top-Math.min(...w),O=e=>({x:l.left-u.left+(e.x+E)*d,y:l.top-u.top+(e.y+D)*f});return{nw:O(S.nw),ne:O(S.ne),se:O(S.se),sw:O(S.sw)}}function B4(e,t,n,r,i){let a=r??C4(e,t,t.contentDocument);if(!a)return null;let o=L4(e,t,n,a,i);if(!o)return null;let s=t.contentWindow,c=s?Lin(s,n,i):null,l=c?Rin(c.matrix):0;if(Math.abs(l)<zin)return o;let u=z4(e,t,n,a,c);if(!u)return o;let d=R4(u.nw,u.ne),f=R4(u.nw,u.sw),p=(u.nw.x+u.se.x)/2,m=(u.nw.y+u.se.y)/2;return!Number.isFinite(d)||!Number.isFinite(f)||d<=0||f<=0?o:{left:p-d/2,top:m-f/2,width:d,height:f,editScaleX:o.editScaleX,editScaleY:o.editScaleY,angle:l}}function Vin(e,t,n,r){let i=B4(e,t,n,r);return i?{...i,...j4(i,n)}:null}var V4=.5,Hin=.1;function H4(e,t){return e===t?!0:!e||!t?!1:Math.abs(e.left-t.left)<V4&&Math.abs(e.top-t.top)<V4&&Math.abs(e.width-t.width)<V4&&Math.abs(e.height-t.height)<V4&&Math.abs(e.editScaleX-t.editScaleX)<.001&&Math.abs(e.editScaleY-t.editScaleY)<.001&&Math.abs((e.angle??0)-(t.angle??0))<Hin}function Uin(e,t){return e===t||e.length===t.length&&e.every((e,n)=>{let r=t[n];return!!(r&&e.key===r.key&&e.element===r.element&&e.selection===r.selection&&H4(e.rect,r.rect))})}function U4(e){let t=e[0];if(!t)return null;let n=t.left,r=t.top,i=t.left+t.width,a=t.top+t.height;for(let t of e.slice(1))n=Math.min(n,t.left),r=Math.min(r,t.top),i=Math.max(i,t.left+t.width),a=Math.max(a,t.top+t.height);return{left:n,top:r,width:i-n,height:a-r,editScaleX:1,editScaleY:1}}function Win(e,t,n,r,i){let a=L4(e,t,n,r,i);if(!a||!n.hasAttribute(`data-hf-group`))return a;let o=[];for(let a of Array.from(n.children)){let n=L4(e,t,a,r,i);n&&o.push(n)}let s=o.length>0?U4(o):null;return s?{...s,editScaleX:a.editScaleX,editScaleY:a.editScaleY}:a}function W4(e,t,n,r,i){return n.hasAttribute(`data-hf-group`)?Win(e,t,n,r,i):B4(e,t,n,r,i)}function Gin(e){return e.filter(t=>!e.some(e=>e!==t&&e.element.contains(t.element)))}function G4(e){return[e.sourceFile??``,e.hfId??``,e.id??``,e.selector??``,e.selectorIndex??``].join(`|`)}function Kin(e,t,n,r){let i=G4(t),a=r.current;if(a?.key===i&&a.element.isConnected&&a.element.ownerDocument===e)return a.element;let o=He(e,t,n);return r.current=o?{key:i,element:o}:null,o}var K4=o2(`select`),q4=4;function qin(e,t,n){return n?Math.abs(e)>=Math.abs(t)?{dx:e,dy:0,lockedAxis:`y`}:{dx:0,dy:t,lockedAxis:`x`}:{dx:e,dy:t}}var Jin=.05,Yin=15,Xin=.5;function J4(e,t){return t.pointerId===e.pointerId&&(t.buttons&1)==1}var Zin=`data-dom-edit-press-waiting`;function Qin(e){e?.focus({preventScroll:!0})}function $in(e,t){return!e||!t?!1:e===t||e.contains(t)}function ean(e){let t=$in(e.cached?.element,e.elementAtPoint);return K4(`shift-pointerdown`,{candidate:e.cached?e.cached.selector??null:null,pointTarget:e.elementAtPoint?.id??e.elementAtPoint?.tagName??null,cacheIsAboutThisPoint:t}),t?e.cached:null}function tan(e){return{dx:(e.originWidth-e.overlayWidth)/2,dy:(e.originHeight-e.overlayHeight)/2}}function nan(e,t,n,r){return Math.atan2(r-t,n-e)*180/Math.PI}function ran(e){return((e+180)%360+360)%360-180}function ian(e){let t=nan(e.centerX,e.centerY,e.startX,e.startY),n=ran(nan(e.centerX,e.centerY,e.currentX,e.currentY)-t),r=e.actualAngle+n;return{angle:e.snap?Math.round(r/Yin)*Yin:S(r)}}function aan(e,t){return Math.abs(t-e)>=Jin}function oan(e,t,n,r){return e?.every(e=>e.element.ownerDocument===t.contentDocument)?e:can(t,n,r)}var san=4;function can(e,t,n){let r=e.contentDocument;if(!r)return[];let i=r.querySelector(`[data-composition-id]`)??r.body,a=ot(i,{activeCompositionPath:n,isMasterView:!n||n===`index.html`}),o=r.querySelector(`[data-composition-id]`)??r.documentElement,s=Number.parseFloat(o?.getAttribute(`data-width`)??``),c=Number.parseFloat(o?.getAttribute(`data-height`)??``),l={width:s>0?s:o.getBoundingClientRect().width||1,height:c>0?c:o.getBoundingClientRect().height||1},u=[];for(let n of a){let r=n.element;if(!m(r)||Wrn(r.getBoundingClientRect(),l))continue;let i=I4(t,e,r);i&&u.push({element:r,rect:{left:i.left,top:i.top,width:i.width,height:i.height}})}return u}function lan(e,t){return t.filter(t=>Tqt(e,t.rect))}async function uan(e,t){let n=!t||t===`index.html`,r=[];for(let i of e){let e=await c(i,{activeCompositionPath:t,isMasterView:n,skipSourceProbe:!0});e&&r.push(e)}return r}function dan(e){e?.changed&&e.count>1&&m4(`multi_select`,`drag`)}function fan(e){try{e.target.releasePointerCapture(e.pointerId)}catch{}}function pan(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)([]),o=(0,U.useRef)(null),s=(0,U.useCallback)(async(t,n)=>{let r=e.iframeRef.current,i=e.overlayRef.current;if(!r||!i||!e.onMarqueeSelectRef.current)return;let a=e.activeCompositionPathRef.current??`index.html`,s=lan(t,oan(o.current,r,i,a)).map(e=>e.element),c=e.resolveHits,l=c?await c(s):await uan(s,a),u=e.onMarqueeSelectRef.current;u&&dan(u(l,n))},[e.iframeRef,e.overlayRef,e.onMarqueeSelectRef,e.activeCompositionPathRef,e.resolveHits]),c=(0,U.useCallback)(()=>{t.current=null,r(null),a([]),o.current=null},[]),l=(0,U.useCallback)(n=>{let r=e.overlayRef.current?.getBoundingClientRect();if(!r)return;n.currentTarget.setPointerCapture(n.pointerId);let i=n.clientX-r.left,a=n.clientY-r.top;t.current={startX:i,startY:a,currentX:i,currentY:a,pointerId:n.pointerId,pastThreshold:!1,target:n.currentTarget}},[e.overlayRef]),u=(0,U.useCallback)(()=>{t.current&&(fan(t.current),c())},[c]);(0,U.useEffect)(()=>{let e=e=>{e.key!==`Escape`||!t.current||(e.preventDefault(),e.stopPropagation(),u())};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[u]);let d=(0,U.useCallback)(t=>{let n=e.iframeRef.current,r=e.overlayRef.current;if(!n||!r)return;let i=e.activeCompositionPathRef.current??`index.html`;o.current??=can(n,r,i),a(lan(t,o.current).map(e=>e.rect))},[e.overlayRef,e.iframeRef,e.activeCompositionPathRef]);return{marqueeRect:n,candidateRects:i,begin:l,cancel:u,onPointerMove:(0,U.useCallback)(n=>{let i=t.current;if(i){if(!J4(i,n))return;let t=e.overlayRef.current?.getBoundingClientRect();if(!t)return;if(i.currentX=n.clientX-t.left,i.currentY=n.clientY-t.top,!i.pastThreshold){let e=i.currentX-i.startX,t=i.currentY-i.startY;if(Math.hypot(e,t)<san)return;i.pastThreshold=!0,o.current=null}let a={left:Math.min(i.startX,i.currentX),top:Math.min(i.startY,i.currentY),width:Math.abs(i.currentX-i.startX),height:Math.abs(i.currentY-i.startY)};r(a),d(a);return}e.gestures?.onPointerMove(n)},[e.gestures,e.overlayRef,d]),onPointerUp:(0,U.useCallback)(n=>{let r=t.current;if(r){fan(r),r.pastThreshold?s({left:Math.min(r.startX,r.currentX),top:Math.min(r.startY,r.currentY),width:Math.abs(r.currentX-r.startX),height:Math.abs(r.currentY-r.startY)},n.shiftKey):e.onMarqueeSelectRef.current?.([],!1),c();return}e.gestures?.onPointerUp(n)},[e.gestures,s,e.onMarqueeSelectRef,c]),onPointerCancel:(0,U.useCallback)(()=>{if(t.current)return u();e.selectionRef&&e.gestures?.clearPointerState(e.selectionRef)},[e.gestures,e.selectionRef,u])}}function man({candidateRects:e,marqueeRect:t}){return(0,W.jsxs)(W.Fragment,{children:[e.map((e,t)=>(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute rounded-xs border border-studio-accent bg-studio-accent/5`,style:{left:e.left,top:e.top,width:e.width,height:e.height}},t)),t&&(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute border border-dashed border-studio-accent bg-studio-accent/10`,style:{left:t.left,top:t.top,width:t.width,height:t.height}})]})}var han=600;function gan({overlayRef:e,iframeRef:t}){let[n,r]=(0,U.useState)(null),i=(0,U.useRef)(null);return(0,U.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),{zOrderFlashRect:n,handleZOrderCrossed:(0,U.useCallback)(n=>{let a=e.current,o=t.current;if(!a||!o)return;let s=I4(a,o,n);!s||s.width<=0||s.height<=0||(i.current&&clearTimeout(i.current),r(s),i.current=setTimeout(()=>{i.current=null,r(null)},han))},[e,t])}}function _an({rect:e}){return e?(0,W.jsx)(`div`,{"aria-hidden":`true`,"data-dom-edit-z-flash":`true`,className:`pointer-events-none absolute rounded-md border-2 border-studio-accent shadow-[0_0_0_2px_rgba(60,230,172,0.35)] animate-pulse`,style:{left:e.left,top:e.top,width:e.width,height:e.height}}):null}function van({selection:e,selectionRef:t,hoverSelectionRef:n,onCanvasPointerMoveRef:r,onSelectionChangeRef:i}){let[a,o]=(0,U.useState)(null),s=(0,U.useCallback)(()=>o(null),[]);return(0,U.useEffect)(()=>{a&&(!e||e.element!==a.sel.element)&&o(null)},[e,a]),{contextMenu:a,closeContextMenu:s,handleContextMenu:(0,U.useCallback)(async e=>{e.preventDefault();let a=t.current,s=a;if(a){let e=n.current;e&&e.element!==a.element&&(i.current(e,{revealPanel:!0}),s=e)}else{let t=e,n=await r.current(t);if(!n)return;i.current(n,{revealPanel:!0}),s=n}s&&o({x:e.clientX,y:e.clientY,sel:s})},[t,n,r,i])}}function yan(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!H4(e[n],t[n]))return!1;return!0}function ban({iframeRef:e,overlayRef:t,selectionRef:n,activeCompositionPathRef:r,groupSelectionsRef:i,hoverSelectionRef:a,rafPausedRef:o}){let[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)([]),[p,m]=(0,U.useState)([]),h=(0,U.useRef)(null),g=(0,U.useRef)(null),_=(0,U.useRef)([]),v=(0,U.useRef)(null),y=(0,U.useRef)(null),b=(0,U.useRef)(new Map),x=(0,U.useRef)([]),S=e=>{H4(h.current,e)||(h.current=e,c(e))},C=e=>{H4(g.current,e)||(g.current=e,u(e))},w=e=>{Uin(_.current,e)||(_.current=e,f(e))},T=(e,t)=>{let n=G4(t),i=b.current.get(n);if(i?.isConnected&&i.ownerDocument===e)return i;let a=He(e,t,r.current);return a?b.current.set(n,a):b.current.delete(n),a};return ax(()=>{let s=()=>{S(null),C(null),w([])};return X2(()=>{if(o.current){x.current.length>0&&(x.current=[],m([]));return}let c=n.current,l=e.current,u=t.current;if(!l||!u){v.current=null,y.current=null,b.current.clear(),s();return}let d=l.contentDocument;if(!d){v.current=null,y.current=null,b.current.clear(),s();return}let f=C4(u,l,d);if(c){let e=Kin(d,c,r.current,v);if(e&&F4(e)){let t=W4(u,l,e,f);S(t);let n=e.querySelectorAll(`*`);if(n.length>0&&n.length<=60){let e=[];for(let t=0;t<n.length;t++){let r=n[t];if(!r.getBoundingClientRect)continue;let i=Vin(u,l,r,f);i&&i.width>2&&i.height>2&&e.push(i)}yan(x.current,e)||(x.current=e,m(e))}else x.current.length>0&&(x.current=[],m([]))}else S(null),x.current.length>0&&(x.current=[],m([]))}else v.current=null,S(null),x.current.length>0&&(x.current=[],m([]));let p=i.current;if(p.length>0){let e=[],t=new Set;for(let n of p){let r=G4(n);if(t.has(r))continue;t.add(r);let i=T(d,n),a=i?Win(u,l,i,f):null,o=a&&i?{...a,...j4(a,i)}:a;i&&o&&e.push({key:r,selection:n,element:i,rect:o})}for(let e of b.current.keys())t.has(e)||b.current.delete(e);w(e)}else b.current.clear(),w([]);let h=a.current,g=!!(c&&h&&G4(c)===G4(h)),_=!!(h&&p.some(e=>G4(e)===G4(h)));if(!h||g||_){y.current=null,C(null);return}let E=Kin(d,h,r.current,y);if(!E){C(null);return}C(W4(u,l,E,f))})}),{overlayRect:s,overlayRectRef:h,setOverlayRect:S,hoverRect:l,hoverRectRef:g,setHoverRect:C,groupOverlayItems:d,groupOverlayItemsRef:_,setGroupOverlayItems:w,childRects:p}}function xan(e,t){let n=e.angle??0;if(!n){let n=Math.max(0,t.left-e.left),r=Math.max(0,t.top-e.top),i=Math.min(e.width,t.left+t.width-e.left),a=Math.min(e.height,t.top+t.height-e.top);return n>=i||r>=a?void 0:`polygon(evenodd, 0 0, ${e.width}px 0, ${e.width}px ${e.height}px, 0 ${e.height}px, 0 0, ${n}px ${r}px, ${i}px ${r}px, ${i}px ${a}px, ${n}px ${a}px, ${n}px ${r}px)`}let r=-n*Math.PI/180,i=Math.cos(r),a=Math.sin(r),o=e.left+e.width/2,s=e.top+e.height/2,c=(t,n)=>{let r=t-o,c=n-s;return`${e.width/2+r*i-c*a}px ${e.height/2+r*a+c*i}px`},l=t.left,u=t.top,d=l+t.width,f=u+t.height,p=[c(l,u),c(d,u),c(d,f),c(l,f),c(l,u)].join(`, `);return`polygon(evenodd, 0 0, ${e.width}px 0, ${e.width}px ${e.height}px, 0 ${e.height}px, 0 0, ${p})`}function San({rects:e,elements:t,compRect:n,selection:r,groupSelections:i,activeCompositionPathRef:a,onSelectionChangeRef:o}){return(0,W.jsx)(W.Fragment,{children:e.filter(e=>{let n=t.current.get(e.key);return!n||r?.element!==n&&!i.some(e=>e.element===n)}).map(e=>{let r={left:e.left,top:e.top,width:e.width,height:e.height,transform:e.angle?`rotate(${e.angle}deg)`:void 0,transformOrigin:`center`},i=xan(e,n),s=async()=>{let n=t.current.get(e.key);if(!n)return;let{resolveDomEditSelection:r}=await Mb(async()=>{let{resolveDomEditSelection:e}=await import(`./domEditingLayers-KBTPQKGA-C_mwj3u9.js`);return{resolveDomEditSelection:e}},__vite__mapDeps([4,5])),i=a.current??`index.html`,s=await r(n,{activeCompositionPath:i,isMasterView:!i||i===`index.html`,skipSourceProbe:!0});s&&o.current(s,{revealPanel:!0})};return(0,W.jsx)(`div`,{className:`pointer-events-none absolute`,style:r,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,"aria-label":`Select off-canvas element ${e.key}`,className:`pointer-events-auto absolute inset-0 border-2 border-dashed border-studio-accent/10 rounded-md cursor-pointer hover:border-studio-accent hover:bg-studio-accent/10 transition-colors`,style:i?{clipPath:i}:void 0,title:`Off-canvas: ${e.key} \u2014 click to select`,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),s())}})},`offcanvas-${e.key}`)})})}function Can({rects:e}){return(0,W.jsx)(W.Fragment,{children:e.map((e,t)=>(0,W.jsx)(`div`,{className:`pointer-events-none absolute border border-dashed border-white/20 rounded-xs`,style:{left:e.left,top:e.top,width:e.width,height:e.height,transform:e.angle?`rotate(${e.angle}deg)`:void 0}},t))})}var Y4=1,wan=3;function Tan(e){let t=Math.hypot(e.pointerStart.x-e.centerStart.x,e.pointerStart.y-e.centerStart.y);return!Number.isFinite(t)||t<wan?1:Math.hypot(e.pointer.x-e.centerStart.x,e.pointer.y-e.centerStart.y)/t}function Ean(e){let t=Math.max(e.baseWidth,Y4),n=Math.max(e.baseHeight,Y4),r=Tan({pointer:e.pointer,pointerStart:e.pointerStart,centerStart:e.centerStart}),i=Y4/Math.min(t,n),a=Math.max(i,r);return{width:t*a,height:n*a}}var Dan=[`ns-resize`,`nesw-resize`,`ew-resize`,`nwse-resize`,`ns-resize`,`nesw-resize`,`ew-resize`,`nwse-resize`],Oan={nw:315,ne:45,se:135,sw:225};function kan(e,t){let n=((Oan[e]+t)%360+360)%360;return Dan[Math.round(n/45)%8]}function Aan(e,t,n){let r=e??{dx:0,dy:0};return{dx:r.dx+(t.x-n.x),dy:r.dy+(t.y-n.y)}}function jan(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Man(e){return e.trim().replace(/\\/g,`/`).replace(/^\.?\//,``)}function X4(e){return e&&typeof e==`object`?e:null}function Z4(e,t){let n=X4(e)?.[t];return typeof n==`string`?n:null}function Q4(e){let t=Z4(e,`path`)??Z4(e,`filePath`);return t===null?null:Man(t)}function $4(e){return X4(e)?.affectsPreview!==!1}function e3(e){let t=X4(e)?.affectedCompositions;return!Array.isArray(t)||!t.every(e=>typeof e==`string`)?null:t.map(Man)}function t3(e,t){let n=e3(e),r=e3(t),i=n&&r?[...new Set([...n,...r])]:null,a=X4(t),o=$4(e)||$4(t);return Q4(e)===Q4(t)?{...a,affectsPreview:o,affectedCompositions:i}:{path:`.`,projectId:a?.projectId,affectsPreview:o,affectedCompositions:i}}function n3(e,t){let n=Array.from(e.querySelectorAll(`[${t}="true"]`)).filter(O),r=`data-${t}`;for(let i of e.querySelectorAll(`[${r}="true"]`))O(i)&&!i.hasAttribute(t)&&(i.setAttribute(t,`true`),i.removeAttribute(r),n.push(i));return n}function Nan(e){for(let t of n3(e,Q1)){if(R0(t,[`x`,`y`]))continue;let e=t.style.getPropertyValue(nj),n=t.style.getPropertyValue(rj);!e&&!n||yen(t,{x:Number.parseFloat(e)||0,y:Number.parseFloat(n)||0},{updateBase:!1})}}function Pan(e){for(let t of n3(e,e0)){let e=Number.parseFloat(t.style.getPropertyValue(ij)),n=Number.parseFloat(t.style.getPropertyValue(aj));Number.isFinite(e)&&Number.isFinite(n)&&e>0&&n>0&&r2(t,{width:e,height:n})}}function Fan(e){for(let t of n3(e,t0)){let e=Number.parseFloat(t.style.getPropertyValue(Z1));Number.isFinite(e)&&jen(t,{angle:e})}}var r3=[Q1,e0,t0].flatMap(e=>[e,`data-${e}`]).concat(IJ),Ian=r3.map(e=>e===IJ?`[${e}]`:`[${e}="true"]`),i3=new WeakMap;function Lan(e){return Ian.some(t=>e.querySelector(t)!==null)}function Ran(e){let t=e.defaultView?.MutationObserver;if(!t)return Lan(e);let n=i3.get(e);if(!n){let r={observer:new t(()=>{r.stale=!0}),stale:!0,has:!1};r.observer.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:r3}),i3.set(e,r),n=r}return n.observer.takeRecords().length>0&&(n.stale=!0),n.stale&&(n.has=Lan(e),n.stale=!1),n.has}function zan(e){return!!e.defaultView?.__timelines?.[FJ]||Ran(e)}function a3(e){zan(e)&&(Nan(e),Pan(e),Fan(e),aUt(e),i3.get(e)?.observer.takeRecords())}function o3(e){return{width:e.style.getPropertyValue(`width`),height:e.style.getPropertyValue(`height`),minWidth:e.style.getPropertyValue(`min-width`),minHeight:e.style.getPropertyValue(`min-height`),maxWidth:e.style.getPropertyValue(`max-width`),maxHeight:e.style.getPropertyValue(`max-height`),flexBasis:e.style.getPropertyValue(`flex-basis`),flexGrow:e.style.getPropertyValue(`flex-grow`),flexShrink:e.style.getPropertyValue(`flex-shrink`),boxSizing:e.style.getPropertyValue(`box-sizing`),scale:e.style.getPropertyValue(`scale`),transformOrigin:e.style.getPropertyValue(`transform-origin`),display:e.style.getPropertyValue(`display`),studioWidth:e.style.getPropertyValue(ij),studioHeight:e.style.getPropertyValue(aj),marker:e.getAttribute(e0),originalWidth:e.getAttribute(i0),originalHeight:e.getAttribute(a0),originalBoxWidth:e.getAttribute(o0),originalBoxHeight:e.getAttribute(s0),originalMinWidth:e.getAttribute(c0),originalMinHeight:e.getAttribute(l0),originalMaxWidth:e.getAttribute(u0),originalMaxHeight:e.getAttribute(d0),originalFlexBasis:e.getAttribute(f0),originalFlexGrow:e.getAttribute(p0),originalFlexShrink:e.getAttribute(m0),originalBoxSizing:e.getAttribute(h0),originalScale:e.getAttribute(g0),originalTransformOrigin:e.getAttribute(_0),originalDisplay:e.getAttribute(v0)}}function s3(e){return{rotate:e.style.getPropertyValue(`rotate`),transform:e.style.getPropertyValue(`transform`),display:e.style.getPropertyValue(`display`),transformOrigin:e.style.getPropertyValue(`transform-origin`),studioRotation:e.style.getPropertyValue(Z1),marker:e.getAttribute(t0),draftMarker:e.getAttribute(S0),originalRotate:e.getAttribute(y0),originalInlineRotate:e.getAttribute(b0),originalTransformOrigin:e.getAttribute(x0)}}function c3(e){return{translate:e.style.getPropertyValue(`translate`),x:e.style.getPropertyValue(nj),y:e.style.getPropertyValue(rj),marker:e.getAttribute(Q1),originalTranslate:e.getAttribute(n0),originalInlineTranslate:e.getAttribute(r0)}}function l3(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function u3(e,t,n){n?e.style.setProperty(t,n):e.style.removeProperty(t)}function d3(e,t){a2(e),u3(e,`width`,t.width),u3(e,`height`,t.height),u3(e,`min-width`,t.minWidth),u3(e,`min-height`,t.minHeight),u3(e,`max-width`,t.maxWidth),u3(e,`max-height`,t.maxHeight),u3(e,`flex-basis`,t.flexBasis),u3(e,`flex-grow`,t.flexGrow),u3(e,`flex-shrink`,t.flexShrink),u3(e,`box-sizing`,t.boxSizing),u3(e,`scale`,t.scale),u3(e,`transform-origin`,t.transformOrigin),u3(e,`display`,t.display),u3(e,ij,t.studioWidth),u3(e,aj,t.studioHeight),l3(e,e0,t.marker),l3(e,i0,t.originalWidth),l3(e,a0,t.originalHeight),l3(e,o0,t.originalBoxWidth),l3(e,s0,t.originalBoxHeight),l3(e,c0,t.originalMinWidth),l3(e,l0,t.originalMinHeight),l3(e,u0,t.originalMaxWidth),l3(e,d0,t.originalMaxHeight),l3(e,f0,t.originalFlexBasis),l3(e,p0,t.originalFlexGrow),l3(e,m0,t.originalFlexShrink),l3(e,h0,t.originalBoxSizing),l3(e,g0,t.originalScale),l3(e,_0,t.originalTransformOrigin),l3(e,v0,t.originalDisplay)}function f3(e,t){u3(e,`rotate`,t.rotate),u3(e,`transform-origin`,t.transformOrigin),u3(e,Z1,t.studioRotation),l3(e,t0,t.marker),l3(e,S0,t.draftMarker),l3(e,y0,t.originalRotate),l3(e,b0,t.originalInlineRotate),l3(e,x0,t.originalTransformOrigin)}function p3(e,t){t.translate?e.style.setProperty(`translate`,t.translate):e.style.removeProperty(`translate`),t.x?e.style.setProperty(nj,t.x):e.style.removeProperty(nj),t.y?e.style.setProperty(rj,t.y):e.style.removeProperty(rj),l3(e,Q1,t.marker),l3(e,n0,t.originalTranslate),l3(e,r0,t.originalInlineTranslate);let n=e.getAttribute(`data-hf-drag-gsap-base-x`),r=e.getAttribute(`data-hf-drag-gsap-base-y`);if(n!=null||r!=null){let t=e.ownerDocument.defaultView;if(t?.gsap){let i=Number.parseFloat(n??`0`)||0,a=Number.parseFloat(r??`0`)||0;t.gsap.set(e,{x:i,y:a})}e.removeAttribute(`data-hf-drag-gsap-base-x`),e.removeAttribute(`data-hf-drag-gsap-base-y`)}}function m3(e,t,n){let r=e.getAttribute(n);r==null||r===``?e.style.removeProperty(t):e.style.setProperty(t,r),e.removeAttribute(n)}function Ban(e){let t=e.getAttribute(b0);t==null||t===``?e.style.removeProperty(`rotate`):e.style.setProperty(`rotate`,t),e.removeAttribute(b0),e.removeAttribute(y0);let n=e.getAttribute(x0);n!=null&&(n===``?e.style.removeProperty(`transform-origin`):e.style.setProperty(`transform-origin`,n)),e.removeAttribute(x0)}function Van(e){let t=e.getAttribute(r0);t==null||t===``?e.style.removeProperty(`translate`):e.style.setProperty(`translate`,t),e.removeAttribute(r0),e.removeAttribute(n0)}function Han(e){(e.hasAttribute(Q1)||e.hasAttribute(r0)||$0(e.style.getPropertyValue(`translate`)))&&Van(e),n2(e),e.style.removeProperty(nj),e.style.removeProperty(rj),e.removeAttribute(Q1),e.removeAttribute(n0),e.removeAttribute(r0)}function Uan(e){(e.hasAttribute(t0)||e2(e.style.getPropertyValue(`rotate`)))&&Ban(e),n2(e),e.style.removeProperty(Z1),e.removeAttribute(t0),e.removeAttribute(S0),e.removeAttribute(y0),e.removeAttribute(b0),e.removeAttribute(x0)}function h3(e){a2(e),(e.hasAttribute(e0)||uen(e.style.getPropertyValue(`width`))||uen(e.style.getPropertyValue(`height`))||e.hasAttribute(g0))&&(m3(e,`width`,i0),m3(e,`height`,a0),m3(e,`min-width`,c0),m3(e,`min-height`,l0),m3(e,`max-width`,u0),m3(e,`max-height`,d0),m3(e,`flex-basis`,f0),m3(e,`flex-grow`,p0),m3(e,`flex-shrink`,m0),m3(e,`box-sizing`,h0),m3(e,`scale`,g0),m3(e,`transform-origin`,_0),m3(e,`display`,v0)),n2(e),e.style.removeProperty(ij),e.style.removeProperty(aj),e.removeAttribute(e0)}function g3(e){try{Object.defineProperty(e,w0,{configurable:!1,enumerable:!1,value:!0})}catch{try{e[w0]=!0}catch{}}}function _3(e){return!!e[w0]}function v3(e,t,n,r=!1){let i=t?.[n];if(!t||typeof i!=`function`)return!1;let a=i;if(_3(a))return!0;let o=function(...t){let n=a.apply(this,t);e.__hfStudioManualEditsApply?.();let i=r?n:void 0;return typeof i?.then==`function`&&i.then(()=>e.__hfStudioManualEditsApply?.()),n};g3(o);try{t[n]=o}catch{return!1}return!0}function y3(e,t){let n=e[t];if(typeof n!=`function`)return null;try{return jan(n.call(e))}catch{return null}}function Wan(e){let t=y3(e,`duration`)??y3(e,`getDuration`);if(t==null)return!0;if(t<=0)return!1;let n=y3(e,`time`)??y3(e,`totalTime`)??y3(e,`getTime`);return n==null||n<t}function Gan(e){let t=e.parent;for(let e=0;e<32&&t&&typeof t==`object`;e++){let e=t,n=e.paused;try{if(typeof n==`function`&&n.call(e))return!0}catch{return!1}t=e.parent}return!1}function b3(e){if(!e)return!1;let t=e.isPlaying;if(typeof t==`function`)try{return!!t.call(e)}catch{return!1}let n=e.paused;if(typeof n==`function`){try{if(n.call(e))return!1}catch{return!1}let t=e.isActive;if(typeof t==`function`)try{if(t.call(e))return!0}catch{return!1}return!Gan(e)&&Wan(e)}let r=e.isActive;if(typeof r==`function`)try{return!!r.call(e)}catch{return!1}return!1}function Kan(e){return b3(e.__player)||b3(e.__timeline)?!0:Object.values(e.__timelines??{}).some(b3)}function qan(e){if(e.__hfStudioManualEditsApply?.(),e[T0]!=null)return;let t=()=>{if(e.__hfStudioManualEditsApply?.(),!Kan(e)){e[T0]=null;return}e[T0]=e.requestAnimationFrame(t)};e[T0]=e.requestAnimationFrame(t)}function x3(e,t,n){let r=t?.[n];if(!t||typeof r!=`function`)return!1;let i=r;if(_3(i))return!0;let a=function(...t){let n=i.apply(this,t);return qan(e),n};g3(a);try{t[n]=a}catch{return!1}return!0}function S3(e,t,n){let r=t?.[n];if(!t||typeof r!=`function`)return!1;let i=r;if(_3(i))return!0;let a=function(...t){let n=i.apply(this,t);return e.__hfStudioManualEditsApply?.(),n};g3(a);try{t[n]=a}catch{return!1}return!0}function Jan(e,t){let n=e;n[Y7t]=t;let r=v3(n,n.__hf,`seek`),i=v3(n,n.__player,`seek`,!0),a=v3(n,n.__player,`renderSeek`),o=v3(n,n.__timeline,`seek`);v3(n,n.__timeline,`totalTime`);let s=x3(n,n.__player,`play`),c=x3(n,n.__timeline,`play`),l=S3(n,n.__player,`pause`),u=S3(n,n.__timeline,`pause`),d=!1,f=!1,p=!1;for(let e of Object.values(n.__timelines??{}))d=v3(n,e,`seek`)||d,v3(n,e,`totalTime`),f=x3(n,e,`play`)||f,p=S3(n,e,`pause`)||p;if(n.__timelines&&!n.__timelines.__proxied){let e=n.__timelines;n.__timelines=new Proxy(e,{set(e,t,r){if(e[t]=r,typeof r==`object`&&r){let e=r;v3(n,e,`seek`),v3(n,e,`totalTime`),x3(n,e,`play`),S3(n,e,`pause`),n.__hfStudioManualEditsApply?.()}return!0}}),n.__timelines.__proxied=!0}return Kan(n)&&qan(n),r||i||a||o||s||c||l||u||d||f||p}var C3=(e,t)=>{let n=e.getPropertyValue(t).trim();return n===`none`?``:n};function w3(e,t=!0){let n=e.ownerDocument.defaultView;if(!n)return 0;let r=n.getComputedStyle(e),i=t?C3(r,`rotate`):``,a=C3(r,`scale`),o=C3(r,`transform`),s=e=>{if(!e)return 0;let t=new n.DOMMatrix(e);return Math.atan2(t.b,t.a)*180/Math.PI},c=[i&&`rotate(${i})`,a&&`scale(${a.split(/\s+/).join(`,`)})`];try{return s([...c,o].join(` `).trim())}catch{return s(o)}}function T3(e){let t=t=>Number.parseFloat(e.getAttribute(t)??``);return{origX:t(`data-hf-drag-initial-offset-x`)||0,origY:t(`data-hf-drag-initial-offset-y`)||0,baseX:t(`data-hf-drag-gsap-base-x`),baseY:t(`data-hf-drag-gsap-base-y`),at:Yan(e)}}function Yan(e){let t=e.getAttribute($1);return t?JSON.parse(t):void 0}var E3=e=>({...T3(e),frozen:!0});function D3(e,t,n,r=T3(e)){let i=e.style.getPropertyValue(`--hf-studio-rotation`),a=-(Number.parseFloat(i)||0)*Math.PI/180,o=Math.cos(a),s=Math.sin(a),c=t.x-r.origX,l=t.y-r.origY,u=c*o-l*s,d=c*s+l*o,f=Number.isFinite(r.baseX)?r.baseX:n.x,p=Number.isFinite(r.baseY)?r.baseY:n.y;return{newX:S(f+u),newY:S(p+d),baseGsapX:f,baseGsapY:p}}function O3(e,t=T3(e)){t.frozen||(e.style.setProperty(`--hf-studio-offset-x`,`${t.origX}px`),e.style.setProperty(`--hf-studio-offset-y`,`${t.origY}px`),e.removeAttribute(`data-hf-drag-initial-offset-x`),e.removeAttribute(`data-hf-drag-initial-offset-y`))}var k3=/\s*(?:(\d*\.?\d+(?:e[-+]?\d+)?)(px|%)?|([a-z]+)\(|([-+*/(),]))/giy,Xan={"(":([e=NaN])=>e,"calc(":([e=NaN])=>e,"min(":e=>Math.min(...e),"max(":e=>Math.max(...e),"clamp(":([e=NaN,t=NaN,n=NaN])=>Math.max(e,Math.min(t,n))};function Zan(e,t){let n=[],r=e.trimEnd().length;k3.lastIndex=0;for(let i=k3.exec(e);i;i=k3.lastIndex<r?k3.exec(e):null)i[1]?n.push(Number(i[1])*(i[2]===`%`?t/100:1)):n.push(i[3]?`${i[3].toLowerCase()}(`:i[4]??``);return k3.lastIndex<r?[]:n}function A3(e,t){let n=Zan(e,t),r=0,i=()=>n[r++],a=(...e)=>e.includes(n[r])&&i();function o(){let e=s();for(let t=a(`+`,`-`);t;t=a(`+`,`-`))e+=(t===`+`?1:-1)*s();return e}function s(){let e=c();for(let t=a(`*`,`/`);t;t=a(`*`,`/`))e=t===`*`?e*c():e/c();return e}function c(){return a(`-`)?-c():l()}function l(){let e=i();if(typeof e==`number`)return e;let t=Xan[e??``];if(!t)return NaN;let n=[o()];for(;a(`,`);)n.push(o());return a(`)`)?t(n):NaN}let u=n.length?o():NaN;return r===n.length?u:NaN}var Qan=new Set([`content-box`,`fill-box`]);function $an(e,t,n,r){let i=t=>Number.parseFloat(e.getPropertyValue(t))||0,a=i(`padding-${n}`)+i(`padding-${r}`)+i(`border-${n}-width`)+i(`border-${r}-width`),o=i(t)-(e.boxSizing===`border-box`?a:0);return Qan.has(e.getPropertyValue(`transform-box`))?o:o+a}function eon(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=t?.translate||e.style.getPropertyValue(`translate`)||`none`;if(n===`none`)return{x:0,y:0};let[r=`0px`,i=`0px`]=V0(n),a=(e,n,r)=>t?$an(t,e,n,r):0;return{x:A3(r,a(`width`,`left`,`right`)),y:A3(i,a(`height`,`top`,`bottom`))}}function ton(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e).translate||`none`,[n=`0px`,r=`0px`]=t===`none`?[]:V0(t),i=e=>S(A3(e,0))||0;return{x:i(n),y:i(r)}}var non=`Studio can't read this layer's translate. Move it in the Code tab.`;function ron(e){return`${S(e.x)}px ${S(e.y)}px`}var ion=[nj,rj];function aon(e,t){j3(e,t);let n=[{type:`inline-style`,property:`translate`,value:ron(t)},{type:`attribute`,property:r0,value:e.getAttribute(r0)}];for(let t of ion.filter(t=>e.style.getPropertyValue(t)))e.style.removeProperty(t),n.push({type:`inline-style`,property:t,value:null});return e.hasAttribute(Q1)&&(e.removeAttribute(Q1),n.push({type:`attribute`,property:Q1,value:null})),n}function j3(e,t){if(!e.hasAttribute(r0)){let t=e.style.getPropertyValue(`translate`);e.setAttribute(r0,$0(t)?``:t)}e.style.setProperty(`translate`,ron(t))}function oon(e,t=B0(e,`move`)){return t?eon(e):oen(e)}function son(e){return B0(e,`rotate`)?{angle:S(w3(e))}:cen(e)}function M3(e){let t=e.ownerDocument.defaultView?.gsap;return t?.set&&t.getProperty?t:null}function con(e,t,n){let r=M3(e);if(!r)return!1;e.style.setProperty(`translate`,`none`);let{newX:i,newY:a}=D3(e,t,n);return r.set(e,{x:i,y:a}),!0}var lon=100,uon=.01,don=1e-6;function N3(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}function fon(e){return Math.hypot(e.x,e.y)}function pon(e){return Number.isFinite(e.left)&&Number.isFinite(e.top)&&Number.isFinite(e.width)&&Number.isFinite(e.height)}function mon(e){let t=e.document.documentElement,n=e.innerWidth||t.clientWidth||1,r=e.innerHeight||t.clientHeight||1;return{width:n>0?n:1,height:r>0?r:1}}function hon(e){try{let t=e.frameElement;return t&&O(t)?t:null}catch{return null}}function P3(e){let t=e.getBoundingClientRect();if(!pon(t)||t.width<=0&&t.height<=0)return null;let n={x:t.left+t.width/2,y:t.top+t.height/2};return F3(e.ownerDocument,n)}function F3(e,t){let n=e.defaultView;for(;n;){let e=hon(n);if(!e)break;let r=e.getBoundingClientRect();if(!pon(r)||r.width<=0||r.height<=0)return null;let i=mon(n);t={x:r.left+t.x*(r.width/i.width),y:r.top+t.y*(r.height/i.height)},n=e.ownerDocument.defaultView}return t}function gon(e){let t=e.a*e.d-e.b*e.c;return!Number.isFinite(t)||Math.abs(t)<don?null:{a:e.d/t,b:-e.b/t,c:-e.c/t,d:e.a/t}}function _on(e,t){return{x:e.a*t.x+e.c*t.y,y:e.b*t.x+e.d*t.y}}function von(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e).transform;if(!t||!t.startsWith(`matrix3d(`))return 1;let n=t.slice(9,-1).split(`,`),r=Number.parseFloat(n[15]??``);return Number.isFinite(r)&&r>0?r:1}function yon(e,t,n={}){let r=n.probeSize??lon;if(!Number.isFinite(r)||r<=0)return{ok:!1,reason:`Invalid movement probe size.`};let i=n.plainTranslate?j3:ben,a=c3(e);try{i(e,t);let n=P3(e);if(!n)return{ok:!1,reason:`Element has no measurable box.`};i(e,{x:t.x+r,y:t.y});let a=P3(e);if(!a)return{ok:!1,reason:`Element X movement could not be measured.`};i(e,{x:t.x,y:t.y+r});let o=P3(e);if(!o)return{ok:!1,reason:`Element Y movement could not be measured.`};let s={x:(a.x-n.x)/r,y:(a.y-n.y)/r},c={x:(o.x-n.x)/r,y:(o.y-n.y)/r};if(!N3(s)||!N3(c)||fon(s)<uon||fon(c)<uon)return{ok:!1,reason:`Element movement response is too small to measure.`};let l=gon({a:s.x,b:s.y,c:c.x,d:c.y});return l?{ok:!0,matrix:l}:{ok:!1,reason:`Element movement response is not invertible.`}}finally{p3(e,a)}}function bon(e){let t=_on(e.screenToOffset,{x:e.dx,y:e.dy});return{x:e.initialOffset.x+t.x,y:e.initialOffset.y+t.y}}function I3(e){let t=!!e.gesture&&B0(e.element,e.gesture===`resize`?`resize`:`move`),n=t?eon(e.element):sen(e.element);if(!N3(n))return{ok:!1,reason:non,selection:e.selection};let r=e.element.ownerDocument.defaultView,i={x:!t&&r?.gsap?.getProperty?.(e.element,`x`)||0,y:!t&&r?.gsap?.getProperty?.(e.element,`y`)||0};if(t||z3(e.element,n,i),r?.__timelines){let t=[];for(let[e,n]of Object.entries(r.__timelines))try{n?.pause&&!n.paused?.()&&(n.pause(),t.push(e))}catch{}t.length>0&&e.element.setAttribute(`data-hf-drag-paused-timelines`,t.join(`,`))}let a=c3(e.element),o=H0(e.element,e.gesture===`resize`?`resize`:`move`,e.at),s=yon(e.element,n,{scaleX:e.rect.editScaleX,scaleY:e.rect.editScaleY,plainTranslate:t});if(!s.ok){let r=e.rect.editScaleX||1,s=e.rect.editScaleY||1,c=von(e.element);return{ok:!0,member:{key:e.key,selection:e.selection,element:e.element,initialOffset:n,plainTranslate:t,baseGsap:i,initialPathOffset:a,gestureToken:o,screenToOffset:{a:c/r,b:0,c:0,d:c/s},originRect:e.rect}}}return{ok:!0,member:{key:e.key,selection:e.selection,element:e.element,initialOffset:n,plainTranslate:t,baseGsap:i,initialPathOffset:a,gestureToken:o,screenToOffset:s.matrix,originRect:e.rect}}}function xon(e,t,n){return bon({initialOffset:e.initialOffset,screenToOffset:e.screenToOffset,dx:t,dy:n})}function L3(e,t,n){if(e.plainTranslate)j3(e.element,t);else if(con(e.element,t,e.baseGsap))return;else n?yen(e.element,t):ben(e.element,t)}function R3(e,t,n){let r=xon(e,t,n);return L3(e,r,!1),r}function z3(e,t,n){e.setAttribute(`data-hf-drag-gsap-base-x`,String(n.x)),e.setAttribute(`data-hf-drag-gsap-base-y`,String(n.y)),e.setAttribute(`data-hf-drag-initial-offset-x`,String(t.x)),e.setAttribute(`data-hf-drag-initial-offset-y`,String(t.y))}function Son(e,t){return e.plainTranslate||z3(e.element,e.initialOffset,e.baseGsap),L3(e,t,!0),t}function B3(e,t,n){return Son(e,xon(e,t,n))}function Con(e,t){let n={x:e.initialOffset.x+t.x,y:e.initialOffset.y+t.y};return L3(e,n,!1),n}function won(e,t){return Son(e,{x:e.initialOffset.x+t.x,y:e.initialOffset.y+t.y})}function Ton(e){p3(e.element,e.initialPathOffset),e.plainTranslate||M3(e.element)?.set(e.element,{...e.baseGsap}),W0(e.element,e.gestureToken)}function V3(e){for(let t of e)Ton(t),Don(t.element)}function Eon(e,t){if(e.style.getPropertyValue(`translate`)===`none`&&e.style.removeProperty(`translate`),!t)return;let n=e.ownerDocument.defaultView?.getComputedStyle(e).getPropertyValue(`translate`);n&&n!==`none`&&e.style.setProperty(`translate`,`none`)}function H3(e){for(let t of e){if(!J0(t.element,t.gestureToken))continue;W0(t.element,t.gestureToken),t.element.removeAttribute(`data-hf-drag-initial-offset-x`),t.element.removeAttribute(`data-hf-drag-initial-offset-y`),t.element.removeAttribute(`data-hf-drag-gsap-base-x`),t.element.removeAttribute(`data-hf-drag-gsap-base-y`);let e=!t.plainTranslate&&!!M3(t.element);e&&Han(t.element),Eon(t.element,e),Don(t.element)}}function Don(e){let t=e.getAttribute(`data-hf-drag-paused-timelines`);if(e.removeAttribute(`data-hf-drag-paused-timelines`),!t)return;let n=e.ownerDocument.defaultView;if(!n)return;for(let e of t.split(`,`))try{n.__timelines?.[e]?.paused?.(!1)}catch{}let r=n.__player?.getTime?.()??0;n.__player?.seek?.(r)}var Oon=[`position`,`left`,`top`],kon=e=>Oon.map(t=>e.style.getPropertyValue(t));function Aon(e,t){Oon.forEach((n,r)=>{t[r]?e.style.setProperty(n,t[r]):e.style.removeProperty(n)})}function jon(e){let t=e.plainTranslate?null:M3(e.element);return{offset:c3(e.element),gsap:t&&{x:Number(t.getProperty(e.element,`x`)),y:Number(t.getProperty(e.element,`y`))},placement:kon(e.element)}}function Mon(e,t){p3(e.element,t.offset),Aon(e.element,t.placement),t.gsap&&M3(e.element)?.set(e.element,{...t.gsap}),e.plainTranslate||z3(e.element,e.initialOffset,e.baseGsap)}function U3(e){let t=e.map(e=>kon(e.element));return()=>{let n=e.map(jon);return e.forEach((e,n)=>Mon(e,{offset:e.initialPathOffset,gsap:e.plainTranslate?null:e.baseGsap,placement:t[n]})),()=>e.forEach((e,t)=>Mon(e,n[t]))}}var Non=[`x`,`y`,`rotation`,`scaleX`,`scaleY`];function Pon(e,t){let n=t?M3(e):null;return{style:e.getAttribute(`style`),gsap:n&&Object.fromEntries(Non.map(t=>[t,Number(n.getProperty(e,t))]))}}function Fon(e,t){t.style===null?e.removeAttribute(`style`):e.setAttribute(`style`,t.style),t.gsap&&M3(e)?.set(e,{...t.gsap})}function Ion(e,t){return()=>{let n=Pon(e,t.gsap!==null);return Fon(e,t),()=>Fon(e,n)}}function Lon(e){let t=``;for(let n of Array.from(e.ownerDocument.styleSheets)){let r=[];try{r=Array.from(n.cssRules)}catch{}for(let n of r){let r=n.style?.getPropertyValue(`transform`);r&&e.matches(n.selectorText)&&(t=r)}}return t}function Ron(e){let t=e.ownerDocument.defaultView,n=t?.getComputedStyle(e).transform??`none`,r=n===`none`?null:new t.DOMMatrix(n);if(!r||r.m41===0&&r.m42===0)return``;let i=e.style.getPropertyValue(`transform`)||Lon(e);return i===`none`?``:i}var zon=/^translate(?:3d|X|Y|Z)?\(/i,Bon=/^rotate\(\s*-?[\d.]+(?:e[+-]?\d+)?deg\s*\)$/i;function Von(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=t?.display===`inline`,r=Ron(e);if(!r)return{property:`rotate`,before:``,after:``,share:w3(e,!1),sign:1,inline:n};let i=V0(r),a=i.findIndex(e=>!zon.test(e)),o=a<0?i.length:a,s=i.slice(o);Bon.test(s[0]??``)&&s.shift();let[c,l]=[i.slice(0,o).join(` `),s.join(` `)],[u=1,d=u]=V0(t?.getPropertyValue(`scale`)??``).map(Number.parseFloat),f=e.style,p=[f.getPropertyValue(`transform`),f.getPropertyPriority(`transform`)];f.setProperty(`transform`,`${c} ${l}`.trim()||`none`);let m=w3(e);return f.setProperty(`transform`,p[0]??``,p[1]??``),{property:`transform`,before:c,after:l,share:m,sign:u*d<0?-1:1,inline:n}}function Hon(e,t,n=Von(e)){let r=`${S(n.sign*(t-n.share))}deg`,i=n.property===`rotate`?r:[n.before,`rotate(${r})`,n.after].filter(Boolean).join(` `),a=[{type:`inline-style`,property:n.property,value:i}];n.inline&&a.unshift({type:`inline-style`,property:`display`,value:`inline-block`});for(let t of a)e.style.setProperty(t.property,t.value);return a}function Uon(e,t){f3(e,t),e.style.setProperty(`transform`,t.transform),e.style.setProperty(`display`,t.display)}function Won(e,t,n){if(n)return void Hon(e,t,n);e.style.setProperty(`rotate`,`none`),M3(e)?.set(e,{rotation:t})}function Gon(e,t,n,r){if(r)return Uon(e,n);M3(e)?.set(e,{rotation:t-(Number.parseFloat(n.studioRotation)||0)}),f3(e,n)}function Kon(e,t){return t?w3(e):Number(M3(e)?.getProperty(e,`rotation`)??0)+cen(e).angle}var qon=4;function Jon(e,t){return Math.hypot(e,t)>=qon}var Yon=1;function W3(e){return e.left+e.width}function G3(e){return e.top+e.height}function K3(e){return e.left+e.width/2}function q3(e){return e.top+e.height/2}function Xon(e){return e.map(({rect:e,id:t})=>({left:e.left,top:e.top,right:W3(e),bottom:G3(e),centerX:K3(e),centerY:q3(e),id:t}))}function Zon(e){return{left:e.left,top:e.top,right:W3(e),bottom:G3(e),centerX:K3(e),centerY:q3(e),id:`composition`}}function Qon(e,t,n){let r=[],i=[];if(t<=0||n<=0)return{x:r,y:i};let a=t*n,o=e.left+a,s=e.left+e.width,c=0;for(;o<s;)r.push({position:o,source:`grid`,id:`grid-x-${c}`}),o+=a,c++;let l=e.top+a,u=e.top+e.height;for(c=0;l<u;)i.push({position:l,source:`grid`,id:`grid-y-${c}`}),l+=a,c++;return{x:r,y:i}}function $on(e,t,n,r,i){let a=[];for(let r of t){let t=n(r);for(let n of e)for(let e of t){let t=e-n,o=Math.abs(t);o<=i&&a.push({adjustment:t,distance:o,guidePosition:e,source:r.id===`composition`?`composition`:`element`,targetId:r.id})}}if(r)for(let t of r)for(let n of e){let e=t.position-n,r=Math.abs(e);r<=i&&a.push({adjustment:e,distance:r,guidePosition:t.position,source:`grid`,targetId:t.id})}return a}function esn(e){if(e.length===0)return null;let t=e.filter(e=>e.source===`element`||e.source===`composition`),n=e.filter(e=>e.source===`grid`),r;r=(t.length?Math.min(...t.map(e=>e.distance)):1/0)<=(n.length?Math.min(...n.map(e=>e.distance)):1/0)?t:n;let i=Math.min(...r.map(e=>e.distance)),a=r.filter(e=>e.distance===i),o=a.some(e=>e.adjustment>0),s=a.some(e=>e.adjustment<0);if(o&&s)return null;let c=a[0].adjustment;return{adjustment:c,matches:r.filter(e=>e.adjustment===c)}}function tsn(e,t,n,r){let i=[];if(e===`x`){i.push(t.top,G3(t));for(let e of n){let t=r.get(e);t&&i.push(t.top,t.bottom)}}else{i.push(t.left,W3(t));for(let e of n){let t=r.get(e);t&&i.push(t.left,t.right)}}return{from:Math.min(...i),to:Math.max(...i)}}function nsn(e,t,n,r){let i=[];for(let[a,o]of[[`x`,e],[`y`,t]]){if(!o)continue;let e=new Set;for(let t of o.matches){if(e.has(t.guidePosition))continue;e.add(t.guidePosition);let s=tsn(a,n,o.matches.filter(e=>e.guidePosition===t.guidePosition).map(e=>e.targetId),r);i.push({axis:a,position:t.guidePosition,from:s.from,to:s.to})}}return i}var rsn=(e,t)=>({dx:e,dy:t,guides:[],spacingGuides:[]});function isn(e){if(e.disabled||e.disabledForTravel||e.threshold<=0)return rsn(e.proposedDx,e.proposedDy);let t=e.movingRect,n={left:t.left+e.proposedDx,top:t.top+e.proposedDy,width:t.width,height:t.height},r=$on([n.left,K3(n),W3(n)],e.targets,e=>[e.left,e.centerX,e.right],e.gridEdges?.x,e.threshold),i=$on([n.top,q3(n),G3(n)],e.targets,e=>[e.top,e.centerY,e.bottom],e.gridEdges?.y,e.threshold),a=e.lockedAxis===`x`?null:esn(r),o=e.lockedAxis===`y`?null:esn(i),s=e.proposedDx+(a?.adjustment??0),c=e.proposedDy+(o?.adjustment??0);return{dx:s,dy:c,guides:nsn(a,o,{left:t.left+s,top:t.top+c,width:t.width,height:t.height},new Map(e.targets.map(e=>[e.id,e]))),spacingGuides:[]}}function asn(e,t){return e.axis===`x`?{left:e.position,top:t.top,width:1,height:t.height}:{left:t.left,top:e.position,width:t.width,height:1}}function osn(e){let t=[],n=e.movingRect,r={left:n.left,top:n.top,right:W3(n),bottom:G3(n),centerX:K3(n),centerY:q3(n),id:`\0__snap_moving__`},i=[...e.targets,r],a=[...i].sort((e,t)=>e.centerX-t.centerX);for(let e=0;e<a.length-2;e++){let n=a[e],r=a[e+1],i=a[e+2],o=r.left-n.right,s=i.left-r.right;if(!(o<0||s<0)&&(n.id===`\0__snap_moving__`||r.id===`\0__snap_moving__`||i.id===`\0__snap_moving__`)&&Math.abs(o-s)<=Yon){let e=Math.min(n.top,r.top,i.top),a=Math.max(n.bottom,r.bottom,i.bottom);t.push({axis:`x`,position:n.right,size:o,from:e,to:a}),t.push({axis:`x`,position:r.right,size:s,from:e,to:a})}}let o=[...i].sort((e,t)=>e.centerY-t.centerY);for(let e=0;e<o.length-2;e++){let n=o[e],r=o[e+1],i=o[e+2],a=r.top-n.bottom,s=i.top-r.bottom;if(!(a<0||s<0)&&(n.id===`\0__snap_moving__`||r.id===`\0__snap_moving__`||i.id===`\0__snap_moving__`)&&Math.abs(a-s)<=Yon){let e=Math.min(n.left,r.left,i.left),o=Math.max(n.right,r.right,i.right);t.push({axis:`y`,position:n.bottom,size:a,from:e,to:o}),t.push({axis:`y`,position:r.bottom,size:s,from:e,to:o})}}return t}function ssn(e){if(!e)return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}var csn=new Set([`script`,`style`,`link`,`meta`,`base`,`template`,`br`,`wbr`]);function lsn(e){return e.nodeType===1}function usn(e,t,n){let r=[],i=e=>{if(!(r.length>=n))for(let n of Array.from(e.children))lsn(n)&&(csn.has(n.tagName.toLowerCase())||n.hasAttribute(`data-composition-id`)||t.has(n)||F4(n)&&(r.push(n),i(n)))};return i(e),r}function dsn(e){let t=Ub(),n=t.snapEnabled??!0,r=e.iframe.contentDocument;if(!r)return{targets:[],compositionTarget:null,gridEdges:null,snapEnabled:n};let i=r.querySelector(`[data-composition-id]`)??r.documentElement,a=i?.getBoundingClientRect(),o=ssn(i?.getAttribute(`data-width`)??null),s=ssn(i?.getAttribute(`data-height`)??null),c=o??a?.width,l=s??a?.height;if(!c||!l||!a)return{targets:[],compositionTarget:null,gridEdges:null,snapEnabled:n};let u=e.iframe.getBoundingClientRect(),d=e.overlayEl.getBoundingClientRect(),f=u.width/c,p=u.height/l,m={left:u.left-d.left,top:u.top-d.top,width:u.width,height:u.height,editScaleX:f,editScaleY:p},h=Zon(m),g=usn(i,e.excludeElements,80),_=[];for(let t=0;t<g.length;t++){let n=I4(e.overlayEl,e.iframe,g[t]);n&&_.push({rect:n,id:`snap-target-${t}`})}let v=Xon(_),y=null,b=t.gridSpacing??50;return(t.snapToGrid??!1)&&b>0&&(y=Qon(m,b,f)),{targets:v,compositionTarget:h,gridEdges:y,snapEnabled:n}}function fsn(e){let t=new Set,n=e.selection;if(n?.element&&t.add(n.element),e.groupSelections)for(let n of e.groupSelections)n.element&&t.add(n.element);return t}var J3=o2(`resize`),Y3=0;function psn(e){J3(`move`,()=>(Y3+=1,Y3%8==1?{n:Y3,...e}:null))}function msn(){Y3=0}function hsn(e,t){let n=n=>{let r=e.getBoundingClientRect(),i=e.ownerDocument.defaultView?.getComputedStyle(e);return{tag:t,phase:n,rect:{x:r.x,y:r.y,w:r.width,h:r.height},cssW:i?.width,cssH:i?.height,transform:i?.transform,inlineStyle:e.getAttribute(`style`)}};J3(`settle`,()=>{let t=n(`t0`);return e.ownerDocument.defaultView?.setTimeout(()=>J3(`settle`,()=>n(`t200`)),200),t})}var X3=o2(`drag`),Z3=0;function gsn(e){X3(`move`,()=>(Z3+=1,Z3%8==1?{n:Z3,...e}:null))}function _sn(){Z3=0}function Q3(e){let t={};for(let{key:n,element:r}of e){let e=r.getBoundingClientRect();t[n]=`${Math.round(e.left)},${Math.round(e.top)}`}return t}function vsn(e,t){let n=new Map;for(let r of Object.keys(t)){let i=e[r]?.split(`,`).map(Number),a=t[r]?.split(`,`).map(Number);!i||!a||i.length!==2||a.length!==2||n.set(r,`${Math.round(a[0]-i[0])},${Math.round(a[1]-i[1])}`)}let r=new Map;for(let e of n.values())r.set(e,(r.get(e)??0)+1);let i=``,a=0;for(let[e,t]of r)t>a&&([i,a]=[e,t]);return[...n].filter(([,e])=>e!==i).map(([e,t])=>`${e.split(`|`)[2]??e} moved ${t}, group moved ${i}`)}function ysn(e,t){X3(e,()=>{let n=Q3(t),r=t[0]?.element.ownerDocument.defaultView;return r&&(r.setTimeout(()=>X3(`${e}+120ms`,()=>({at:Q3(t)})),120),r.setTimeout(()=>X3(`${e}+400ms`,()=>({at:Q3(t)})),400),r.setTimeout(()=>X3(`${e}+900ms`,()=>({at:Q3(t)})),900)),{at:n}})}function bsn(e,t,n){e.button!==0||n.capabilities.commitCheckPending||t.onBlockedMoveRef.current(n)}function xsn(e,t,n){let r=t.groupOverlayItemsRef.current;if(r.length<=1)return!1;let i=r.find(e=>!e.selection.capabilities.canApplyManualOffset)?.selection;if(i)return e.preventDefault(),e.stopPropagation(),bsn(e,t,i),!1;t.onManualDragStartRef.current?.();let a=Gin(r),o=[];for(let r of a){let i=I3({key:r.key,selection:r.selection,element:r.element,rect:r.rect,gesture:`drag`,at:n});if(!i.ok)return V3(o),e.preventDefault(),e.stopPropagation(),t.onBlockedMoveRef.current(i.selection,i.reason),!1;o.push(i.member)}try{_sn(),X3(`group-start`,{members:Object.fromEntries(o.map(e=>[e.key,{map:`${e.screenToOffset.a.toFixed(3)},${e.screenToOffset.d.toFixed(3)}`,base:`${Math.round(e.baseGsap.x)},${Math.round(e.baseGsap.y)}`,offset:`${Math.round(e.initialOffset.x)},${Math.round(e.initialOffset.y)}`}])),at:Q3(o)});let n=t.overlayRef.current,i=t.iframeRef.current,a=n&&i?dsn({overlayEl:n,iframe:i,excludeElements:fsn({iframe:i,groupSelections:r.map(e=>e.selection)})}):void 0;e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),t.rafPausedRef.current=!0,t.groupGestureRef.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,originItems:r,members:o,snapContext:a}}catch(e){throw t.groupGestureRef.current=null,V3(o),e}return!0}function Ssn(e,t,n,r){let i=r?.at,a=r?.selection??n.selectionRef.current,o=r?.rect??n.overlayRectRef.current,s=n.boxRef.current,c=n.overlayRef.current;if(!a||!o||e!==`drag`&&!s)return!1;let l=e===`rotate`?`rotation`:e===`drag`?`path-offset`:`box-size`;if(e===`drag`&&!a.capabilities.canApplyManualOffset||e===`resize`&&!a.capabilities.canApplyManualSize||e===`rotate`&&!a.capabilities.canApplyManualRotation||e===`resize`&&(!Number.isFinite(o.width)||!Number.isFinite(o.height)))return!1;let u=X0(a.element),d=a.element.offsetWidth,f=a.element.offsetHeight,p=u.width>0?u.width:d>0?d:o.width/o.editScaleX,m=u.height>0?u.height:f>0?f:o.height/o.editScaleY,h=o.width/(o.editScaleX*p),g=o.height/(o.editScaleY*m),_=Number.isFinite(h)&&h>0?h:1,v=Number.isFinite(g)&&g>0?g:1,y=Pon(a.element,e!==`drag`&&!B0(a.element,e===`rotate`?`rotate`:`resize`)),b=c3(a.element),x,S;if(e===`drag`){n.onManualDragStartRef.current?.();let e=I3({key:G4(a),selection:a,element:a.element,rect:o,gesture:`drag`,at:i});if(!e.ok)return n.onBlockedMoveRef.current(e.selection,e.reason),t.preventDefault(),!1;S=e.member,b=e.member.initialPathOffset,x=e.member.gestureToken}else if(e===`resize`&&a.capabilities.canApplyManualOffset){let e=I3({key:G4(a),selection:a,element:a.element,rect:o,gesture:`resize`,at:i});e.ok?(S=e.member,b=e.member.initialPathOffset,x=e.member.gestureToken,e.member.plainTranslate&&R3(e.member,0,0)):x=H0(a.element,`resize`,i)}else x=H0(a.element,e===`rotate`?`rotate`:`resize`,i);try{let i=!!S?.plainTranslate||B0(a.element,`rotate`),s=i&&e===`rotate`?Von(a.element):null,u={angle:Kon(a.element,i)},d=c?.getBoundingClientRect(),f=(d?.left??0)+o.left+o.width/2,h=(d?.top??0)+o.top+o.height/2,g=n.iframeRef.current,C;if(e===`resize`&&S&&c&&g){let e=z4(c,g,a.element);e&&(C=Bin(e))}let w=(e===`drag`||e===`resize`)&&c&&g?dsn({overlayEl:c,iframe:g,excludeElements:fsn({iframe:g,selection:a})}):void 0;t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),n.rafPausedRef.current=!0,n.gestureRef.current={kind:e,mode:l,selection:a,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,centerX:f,centerY:h,initialPathOffset:b,initialRotation:s3(a.element),initialBoxSize:o3(a.element),initialLook:y,pathOffsetMember:S,originLeft:o.left,originTop:o.top,originWidth:o.width,originHeight:o.height,actualWidth:p,actualHeight:m,actualRotation:u.angle,plainRotation:s,editScaleX:o.editScaleX,editScaleY:o.editScaleY,contentScaleX:_,contentScaleY:v,manualEditDragToken:x,snapContext:w,resizeHandle:e===`resize`?r?.resizeHandle??`se`:void 0,resizeFixedCenterStart:C},e===`resize`&&(msn(),J3(`start`,{handle:r?.resizeHandle??`se`,pointer:{x:t.clientX,y:t.clientY},center:{x:f,y:h},origin:{left:o.left,top:o.top,w:o.width,h:o.height},actual:{w:p,h:m},editScale:{x:o.editScaleX,y:o.editScaleY},contentScale:{x:_,y:v},rotation:u.angle,hasOffsetMember:!!S,fixedCenterStart:C??null,initialBoxSize:n.gestureRef.current?.initialBoxSize??null,initialInlineStyle:a.element.getAttribute(`style`)}))}catch(e){throw n.gestureRef.current=null,S?V3([S]):x&&W0(a.element,x),e}return!0}function $3(){let{currentTime:e,activeKeyframePct:t}=X.getState();return{time:e,keyframePct:t}}function e6(e){return e?.at??$3()}var Csn=60,wsn=1e4;function Tsn(e,t,n){let r=()=>{let t=e.waitingPressRef.current;for(;t&&!t.released;)t=t.after;let n=t;IKt(n&&(()=>c(n)))},i=()=>{e.boxRef.current?.removeAttribute(Zin),e.rafPausedRef.current=!1},a=(t,n)=>{for(let r=e.waitingPressRef.current;r;r=r.after)r.after===t&&(r.after=n)},o=(t=e.waitingPressRef.current)=>{for(let e=t;e&&!e.ended;e=e.after)e.ended=!0,cancelAnimationFrame(e.frame);t===e.waitingPressRef.current?(e.waitingPressRef.current=null,i()):t&&a(t,null),r()},s=t=>{let n=t.after;e.waitingPressRef.current=n;let r=n??t,a=n?.moved,[o,s]=a?[a.clientX-r.startX,a.clientY-r.startY]:[0,0];r.draw?.(o,s),n||i()},c=t=>!t.ended&&(t.ended=!0,cancelAnimationFrame(t.frame),t===e.waitingPressRef.current?s(t):a(t,t.after),r(),!0),l=()=>{let t=e.waitingPressRef.current;t&&!t.released&&c(t)},u=(e,t)=>{e.released=t,r()},d=t=>t&&((n,r)=>e.setOverlayRect(P4(t,n,r))),f=(t,n)=>{if(!t)return null;let r=e.overlayRef.current?.getBoundingClientRect(),i={x:(r?.left??0)+t.left+t.width/2,y:(r?.top??0)+t.top+t.height/2};return(r,a)=>{let o=Tan({pointer:{x:n.x+r,y:n.y+a},pointerStart:n,centerStart:i}),[s,c]=[t.width*o,t.height*o];e.setOverlayRect({...t,left:t.left+(t.width-s)/2,top:t.top+(t.height-c)/2,width:s,height:c})}},p=(r,i,a,s=null)=>{let c=$3();if(!Ien()&&!e.waitingPressRef.current)return a(r,c,!1);r.preventDefault(),r.stopPropagation(),r.currentTarget.setPointerCapture(r.pointerId);let l={setPointerCapture(){}},u={...r,currentTarget:l,preventDefault(){},stopPropagation(){}},d={pointerId:r.pointerId,startX:r.clientX,startY:r.clientY,draw:s,frame:0,moved:null,released:null,after:e.waitingPressRef.current,ended:!1};e.waitingPressRef.current=d,e.boxRef.current?.setAttribute(Zin,`true`),e.rafPausedRef.current=!0;let f=0,p=0,m=performance.now(),h=()=>{let t=i(),n=e.iframeRef.current?.contentDocument,r=!Ien();return f=r&&t.every(e=>e.ownerDocument===n)?f+1:0,p=r?p+1:0,t.length},g=()=>{if(d.after&&!d.after.ended)return`wait`;let e=h(),t=performance.now()-m>wsn;return t&&Nen(),e===0||p>Csn?`lost`:t||f>=2?`run`:`wait`},_=()=>{if(d.ended)return;let e=g();if(e===`wait`){d.frame=requestAnimationFrame(_);return}o(d),!(e===`lost`||!a(u,c,!0))&&(d.moved&&t(d.moved),d.released&&n(d.released))};return d.frame=requestAnimationFrame(_),!0},m=t=>{let n=e.iframeRef.current?.contentDocument;if(!n)return null;let r=He(n,t,e.activeCompositionPathRef.current);return r&&{...t,element:r}},h=t=>{let n=e.overlayRef.current,r=e.iframeRef.current;return n&&r&&W4(n,r,t)};return{startGesture:(t,n,r)=>{let i=r?.selection??e.selectionRef.current,a=null;return t===`drag`&&(a=d(e.overlayRectRef.current)),t===`resize`&&(a=f(e.overlayRectRef.current,{x:n.clientX,y:n.clientY})),p(n,()=>{let e=i&&m(i);return e?[e.element]:[]},(n,a,o)=>{if(!o)return Ssn(t,n,e,{...r,at:a});let s=i&&m(i),c=s&&h(s.element);return!!(s&&c)&&Ssn(t,n,e,{selection:s,rect:c,resizeHandle:r?.resizeHandle,at:a})},a)},startGroupDrag:t=>{let n=e.groupOverlayItemsRef.current;return p(t,()=>n.flatMap(e=>{let t=m(e.selection);return t?[t.element]:[]}),(t,r,i)=>{if(!i)return xsn(t,e,r);let a=e.overlayRef.current,o=e.iframeRef.current;if(!a||!o)return!1;let s=C4(a,o,o.contentDocument),c=n.flatMap(e=>{let t=m(e.selection),n=t&&W4(a,o,t.element,s);return t&&n?[{...e,selection:t,element:t.element,rect:n}]:[]});return c.length===n.length&&xsn(t,{...e,groupOverlayItemsRef:{current:c}},r)},(t,r)=>e.setGroupOverlayItems(n.map(e=>({...e,rect:P4(e.rect,t,r)}))))},endWaitingPress:o,endHeldPress:l,releaseWaitingPress:u}}function Esn(e,t,n){let r=e.resizeFixedCenterStart;if(t&&r)return Aan(e.lastResizeAnchor,r,Bin(t));let i=n();return tan({originWidth:e.originWidth,originHeight:e.originHeight,overlayWidth:i?i.width:e.originWidth,overlayHeight:i?i.height:e.originHeight})}function Dsn(e,t,n,r,i,a){let o=r&&i?z4(r,i,n):null,s=Esn(e,o,a);return e.lastResizeAnchor=s,R3(t,s.dx,s.dy),a()??{left:e.originLeft+s.dx,top:e.originTop+s.dy,width:o?R4(o.nw,o.ne):e.originWidth,height:o?R4(o.nw,o.sw):e.originHeight,editScaleX:e.editScaleX,editScaleY:e.editScaleY,angle:e.actualRotation}}function Osn(e,t,n,r,i){return e.pathOffsetMember?Dsn(e,e.pathOffsetMember,t,n,r,i):i()??{left:e.originLeft,top:e.originTop,width:e.originWidth,height:e.originHeight,editScaleX:e.editScaleX,editScaleY:e.editScaleY,angle:e.actualRotation}}function ksn(e,t){let n={},r=null,i=(t,n,r)=>{let i=t.snapContext;if(!i?.snapEnabled||i.targets.length===0)return r;if(!Jon(r.dx,r.dy))return e.snapGuidesRef.current=null,r;let a=U4(t.originItems.map(e=>e.rect));if(!a)return r;let o=i.compositionTarget?[...i.targets,i.compositionTarget]:i.targets,s=isn({movingRect:a,proposedDx:r.dx,proposedDy:r.dy,targets:o,gridEdges:i.gridEdges??void 0,threshold:6,disabled:n.altKey,lockedAxis:r.lockedAxis}),c={...a,left:a.left+s.dx,top:a.top+s.dy},l=n.altKey?[]:osn({movingRect:c,targets:o,threshold:6});return e.snapGuidesRef.current={guides:s.guides,spacingGuides:l},{dx:s.dx,dy:s.dy}};return(e,a)=>{e!==r&&(r=e,n={});let{dx:o,dy:s}=i(e,a,qin(a.clientX-e.startX,a.clientY-e.startY,a.shiftKey));e.lastSnappedDx=o,e.lastSnappedDy=s,t(e.originItems.map(e=>({...e,rect:{...e.rect,left:e.rect.left+o,top:e.rect.top+s}})));let c={};for(let t of e.members){let e=R3(t,o,s);c[t.key]=`${Math.round(e.x)},${Math.round(e.y)}`}let l=Q3(e.members),u={pointer:`${Math.round(a.clientX-e.startX)},${Math.round(a.clientY-e.startY)}`,applied:`${Math.round(o)},${Math.round(s)}`,at:l},d=vsn(n,l);d.length>0&&X3(`drift`,{...u,drift:d}),n=l,gsn({...u,offsets:c})}}var Asn=5,t6=class extends Error{constructor(){super(`Auto-save is paused. Dismiss the warning to retry DOM edits.`),this.name=`DomEditSaveQueueOpenError`}};function jsn(e={}){let t=e.failureThreshold??Asn,n=Promise.resolve(),r=0,i=0,a=!1,o=null,s=(t=!0)=>{let n=a;i=0,a=!1,o=null,t&&n&&e.onReset?.()},c=t=>{a||(a=!0,e.onOpen?.({consecutiveFailures:i,errorMessage:QY(t),statusCode:tX(t)??null}))},l=async e=>{try{let t=await e();return a||(i=0,o=null),t}catch(e){throw o=e,i+=1,(tX(e)===409||i>=t)&&c(e),e}};return{enqueue(e){if(a)return Promise.reject(new t6);r+=1;let t=n.catch(()=>void 0).then(()=>{if(a)throw new t6;return l(e)});return n=t.then(()=>void--r,()=>void--r),t},async waitForIdle(){return await n.catch(()=>void 0),o instanceof XY?{status:`conflict`,error:o}:o==null?{status:`clean`}:{status:`failed`,error:o}},isIdle:()=>r===0,reset:s,destroy(){s(!1)}}}function n6(e,t){return!e.travelled&&Math.hypot(t.clientX-e.startX,t.clientY-e.startY)<q4}function Msn(e,t){t instanceof t6||console.error(e,t)}function Nsn(e){let t=t=>{e.waitingPressRef.current||e.setOverlayRect(t)},n=e=>{t({left:e.originLeft,top:e.originTop,width:e.originWidth,height:e.originHeight,editScaleX:e.editScaleX,editScaleY:e.editScaleY,angle:e.actualRotation})},r=t=>{e.waitingPressRef.current||e.setGroupOverlayItems(t)},i=e=>{V3(e.members),r(e.originItems)},{startGesture:a,startGroupDrag:o,endWaitingPress:s,endHeldPress:c,releaseWaitingPress:l}=Tsn(e,e=>p(e),e=>h(e)),u=(t,n)=>{t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),e.blockedMoveRef.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY},bsn(t,e,n)},d=ksn(e,r),f=t=>{let n=e.waitingPressRef.current;if(n&&n.pointerId===t.pointerId){if(n.released||!J4(n,t))return;n.moved=t,n.draw?.(t.clientX-n.startX,t.clientY-n.startY);return}p(t)},p=n=>{let r=e.gestureRef.current,i=e.groupGestureRef.current,a=r?.selection??e.selectionRef.current,o=e.waitingPressRef.current?null:e.boxRef.current,s=e.blockedMoveRef.current;!s&&!r&&!i&&e.onCanvasPointerMoveRef.current(n,{preferClipAncestor:!1});let c=r??i;if(c&&!J4(c,n))return;if(s){let t=n.clientX-s.startX,r=n.clientY-s.startY;Math.hypot(t,r)>=q4&&(e.suppressNextBoxClickRef.current=!0);return}if(i){n6(i,n)||(i.travelled=!0),d(i,n);return}if(!r||!a)return;n6(r,n)||(r.travelled=!0);let l=n.clientX-r.startX,u=n.clientY-r.startY;if(r.kind===`rotate`){let e=ian({centerX:r.centerX,centerY:r.centerY,startX:r.startX,startY:r.startY,currentX:n.clientX,currentY:n.clientY,actualAngle:r.actualRotation,snap:n.shiftKey});Won(a.element,e.angle,r.plainRotation);return}if(r.kind===`drag`){let i=qin(l,u,n.shiftKey);l=i.dx,u=i.dy;let a=r.snapContext;if(!(Math.abs(r.actualRotation)>=Xin)&&a?.snapEnabled&&a.targets.length>0){let t=j4({left:r.originLeft,top:r.originTop,width:r.originWidth,height:r.originHeight,editScaleX:r.editScaleX,editScaleY:r.editScaleY},r.selection.element),o=a.compositionTarget?[...a.targets,a.compositionTarget]:a.targets,s=isn({movingRect:t,proposedDx:l,proposedDy:u,disabledForTravel:!Jon(l,u),targets:o,gridEdges:a.gridEdges??void 0,threshold:6,disabled:n.altKey,lockedAxis:i.lockedAxis});l=s.dx,u=s.dy;let c={left:t.left+l,top:t.top+u,width:t.width,height:t.height},d=n.altKey?[]:osn({movingRect:c,targets:o,threshold:6});e.snapGuidesRef.current={guides:s.guides,spacingGuides:d}}r.lastSnappedDx=l,r.lastSnappedDy=u;let s=r.originLeft+l,c=r.originTop+u;t({left:s,top:c,width:r.originWidth,height:r.originHeight,editScaleX:r.editScaleX,editScaleY:r.editScaleY,angle:r.actualRotation}),o&&(o.style.left=`${s}px`,o.style.top=`${c}px`),r.pathOffsetMember&&R3(r.pathOffsetMember,l,u)}else{let i=Ean({baseWidth:r.actualWidth,baseHeight:r.actualHeight,pointer:{x:n.clientX,y:n.clientY},pointerStart:{x:r.startX,y:r.startY},centerStart:{x:r.centerX,y:r.centerY}});Een(a.element,i);let s=e.overlayRef.current,c=e.iframeRef.current,l=Osn(r,a.element,s,c,()=>s&&c?B4(s,c,a.element):null);psn({pointer:{x:n.clientX,y:n.clientY},nextSize:i,anchor:r.lastResizeAnchor??null,draftRect:l,liveInlineStyle:a.element.getAttribute(`style`)}),o&&(o.style.left=`${l.left}px`,o.style.top=`${l.top}px`,o.style.width=`${l.width}px`,o.style.height=`${l.height}px`),t(l)}},m=t=>{let n=e.waitingPressRef.current;if(n&&n.pointerId===t.pointerId){l(n,t),e.suppressNextBoxClickRef.current=!0;return}h(t)},h=a=>{e.snapGuidesRef.current=null;let o=e.gestureRef.current,s=e.groupGestureRef.current,c=o?.selection??e.selectionRef.current,l=e.waitingPressRef.current?null:e.boxRef.current;if(e.blockedMoveRef.current=null,e.rafPausedRef.current=e.waitingPressRef.current!==null,s){e.groupGestureRef.current=null;let t=a.clientX-s.startX,n=a.clientY-s.startY;if(e.suppressNextBoxClickRef.current=!0,n6(s,a)){i(s),a.shiftKey&&e.onCanvasMouseDown(a,{preferClipAncestor:!1,hoverSelection:e.hoverSelectionRef.current});return}let o=s.lastSnappedDx??t,c=s.lastSnappedDy??n;r(s.originItems.map(e=>({...e,rect:P4(e.rect,o,c)})));let l=s.members.map(e=>({selection:e.selection,next:B3(e,o,c),plainTranslate:e.plainTranslate}));X3(`drop`,{pointer:`${Math.round(t)},${Math.round(n)}`,applied:`${Math.round(o)},${Math.round(c)}`,committed:Object.fromEntries(l.map((e,t)=>[s.members[t]?.key??String(t),`${Math.round(e.next.x)},${Math.round(e.next.y)}`])),at:Q3(s.members)});let u=mX(U3(s.members)),d=Promise.resolve(u.adopt(()=>e.onGroupPathOffsetCommitRef.current(l))).then(e=>h4(`move`,`drag`,e)).catch(()=>{for(let e of s.members)e.gestureToken&&J0(e.element,e.gestureToken)&&p3(e.element,e.initialPathOffset)}).finally(()=>{X3(`committed`,{at:Q3(s.members)}),H3(s.members),ysn(`settle`,s.members)});u.settle(d);return}if(e.gestureRef.current=null,!o||!c)return;let u=Math.hypot(a.clientX-o.startX,a.clientY-o.startY);if(o.kind===`drag`&&n6(o,a)){o.pathOffsetMember&&V3([o.pathOffsetMember]),l&&(l.style.left=`${o.originLeft}px`,l.style.top=`${o.originTop}px`),n(o),e.suppressNextBoxClickRef.current=!0,e.onCanvasMouseDown(a,{preferClipAncestor:!1,hoverSelection:e.hoverSelectionRef.current});return}if(o.kind===`resize`&&u<q4){d3(c.element,o.initialBoxSize),o.pathOffsetMember?V3([o.pathOffsetMember]):W0(c.element,o.manualEditDragToken),l&&(l.style.width=`${o.originWidth}px`,l.style.height=`${o.originHeight}px`),n(o),e.suppressNextBoxClickRef.current=!0;return}if(o.kind===`rotate`){let t=ian({centerX:o.centerX,centerY:o.centerY,startX:o.startX,startY:o.startY,currentX:a.clientX,currentY:a.clientY,actualAngle:o.actualRotation,snap:a.shiftKey}),n=()=>Gon(c.element,o.actualRotation,o.initialRotation,o.plainRotation!==null);if(!aan(o.actualRotation,t.angle)){n(),W0(c.element,o.manualEditDragToken);return}Won(c.element,t.angle,o.plainRotation);let r={...t,plain:o.plainRotation},i=mX(Ion(c.element,o.initialLook)),s=Promise.resolve(i.adopt(()=>e.onRotationCommitRef.current(c,r))).then(e=>h4(`rotate`,`drag`,e)).catch(e=>{Msn(`rotate commit failed`,e),o.manualEditDragToken&&J0(c.element,o.manualEditDragToken)&&n()}).finally(()=>W0(c.element,o.manualEditDragToken));i.settle(s)}else if(o.kind===`drag`){e.suppressNextBoxClickRef.current=!0;let n=o.lastSnappedDx??a.clientX-o.startX,r=o.lastSnappedDy??a.clientY-o.startY;if(!o.pathOffsetMember)return;let i=B3(o.pathOffsetMember,n,r),s=o.originLeft+n,u=o.originTop+r;t({left:s,top:u,width:o.originWidth,height:o.originHeight,editScaleX:o.editScaleX,editScaleY:o.editScaleY,angle:o.actualRotation}),l&&(l.style.left=`${s}px`,l.style.top=`${u}px`);let d=o.pathOffsetMember,f=mX(U3([d])),p=Promise.resolve(f.adopt(()=>e.onPathOffsetCommitRef.current(c,i,{altKey:a.altKey,plainTranslate:d.plainTranslate}))).then(e=>h4(`move`,`drag`,e)).catch(()=>{o.pathOffsetMember?.gestureToken&&J0(c.element,o.pathOffsetMember.gestureToken)&&p3(c.element,o.initialPathOffset)}).finally(()=>{o.pathOffsetMember&&H3([o.pathOffsetMember])});f.settle(p)}else{e.suppressNextBoxClickRef.current=!0;let t=X0(c.element);r2(c.element,t);let n=o.pathOffsetMember,r=o.lastResizeAnchor,i=n&&r&&(r.dx!==0||r.dy!==0)?B3(n,r.dx,r.dy):null;J3(`release`,{finalSize:t,anchor:r??null,finalOffset:i??null,hasMember:!!n,inlineStyle:c.element.getAttribute(`style`)});let a=()=>{!o.manualEditDragToken||!J0(c.element,o.manualEditDragToken)||(d3(c.element,o.initialBoxSize),i&&p3(c.element,o.initialPathOffset))},s=()=>e.onBoxSizeCommitRef.current(c,t,i??void 0,a,n),l=mX(Ion(c.element,o.initialLook)),u=Promise.resolve(l.adopt(s)).then(e=>h4(`resize`,`drag`,e)).catch(e=>{Msn(`resize commit failed`,e)}).finally(()=>{n?H3([n]):W0(c.element,o.manualEditDragToken)});l.settle(u),hsn(c.element,`post-release`)}},g=(t,r=!1)=>{r?s():c(),e.snapGuidesRef.current=null;let a=e.groupGestureRef.current;a&&i(a);let o=e.gestureRef.current,l=o?.selection??t.current;o?.mode===`path-offset`&&l&&(o.pathOffsetMember&&V3([o.pathOffsetMember]),n(o)),o?.mode===`box-size`&&l&&(d3(l.element,o.initialBoxSize),o.pathOffsetMember?V3([o.pathOffsetMember]):W0(l.element,o.manualEditDragToken),n(o)),o?.mode===`rotation`&&l&&(Gon(l.element,o.actualRotation,o.initialRotation,o.plainRotation!==null),W0(l.element,o.manualEditDragToken)),e.blockedMoveRef.current=null,e.groupGestureRef.current=null,e.gestureRef.current=null,e.rafPausedRef.current=e.waitingPressRef.current!==null};return{startGesture:a,startGroupDrag:o,startBlockedMove:u,onPointerMove:f,onPointerUp:m,onLostPointerCapture:t=>{let n=e.waitingPressRef.current;n?.pointerId===t.pointerId&&n.released||g(e.selectionRef)},clearPointerState:g}}var Psn=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`]),Fsn=1,Isn=10,Lsn=400;function Rsn(e){if(e.metaKey||e.ctrlKey||e.altKey||!Psn.has(e.key))return null;let t=e.shiftKey?Isn:Fsn;return{dx:e.key===`ArrowLeft`?-t:e.key===`ArrowRight`?t:0,dy:e.key===`ArrowUp`?-t:e.key===`ArrowDown`?t:0}}function r6(e){return e.length>0&&e.every(e=>e.capabilities.canApplyManualOffset)}function zsn(e){return e?[e.id??``,e.hfId??``,e.selector??``,e.selectorIndex??``,e.label].join(`\0`):``}function Bsn(e){return e.map(zsn).join(` `)}function Vsn(e){return r6(e.map(e=>e.selection))?Gin(e):null}function Hsn(e,t){return!e||!t||!e.capabilities.canApplyManualOffset||!e.element.isConnected?null:[{key:e.id??e.selector??e.label,selection:e,element:e.element,rect:t}]}function Usn(e,t){return!e.allowCanvasMovement||t.defaultPrevented||e.gestureRef.current||e.groupGestureRef.current||e.blockedMoveRef.current?!0:oX(t.target)}function Wsn(e){let t=(0,U.useRef)(null),n=(0,U.useRef)(e);n.current=e;let r=()=>{let e=t.current;if(!e)return;t.current=null,e.timer&&clearTimeout(e.timer);let r=n.current,i;try{let t=e.members.map(t=>({selection:t.selection,next:won(t,e.accum),plainTranslate:t.plainTranslate})),n=e.edit.adopt(()=>e.isGroup?r.onGroupPathOffsetCommitRef.current(t):r.onPathOffsetCommitRef.current(t[0].selection,t[0].next,{plainTranslate:t[0].plainTranslate}));if(e.edit.reverted())for(let t of e.members)p3(t.element,t.initialPathOffset);return i=Promise.resolve(n).then(e=>h4(`nudge`,`keyboard`,e)).catch(()=>{for(let t of e.members)J0(t.element,t.gestureToken)&&p3(t.element,t.initialPathOffset)}).finally(()=>H3(e.members)),i}finally{e.edit.settle(i)}},i=(0,U.useRef)(r);i.current=r,(0,U.useEffect)(()=>{if(e.allowCanvasMovement||!t.current)return;let n=t.current;t.current=null,n.timer&&clearTimeout(n.timer),V3(n.members),H3(n.members),n.edit.settle()},[e.allowCanvasMovement]);let a=e=>{let t=n.current,r=t.groupOverlayItemsRef.current,i=r.length>1,a=i?Vsn(r):Hsn(t.selectionRef.current,t.overlayRectRef.current);if(!a)return null;t.onManualDragStartRef.current?.();let o=[];for(let n of a){let r=I3({...n,gesture:`nudge`});if(!r.ok)return V3(o),e.repeat||t.onBlockedMoveRef.current(r.selection,r.reason),`refused`;o.push(r.member)}return o.length===0?null:{members:o,isGroup:i,accum:{x:0,y:0},timer:null,edit:mX(U3(o))}},o=e=>{let r=n.current;if(Usn(r,e))return;let o=Rsn(e);if(!o)return;let s=t.current??a(e);if(s===`refused`)return void e.preventDefault();if(s){t.current=s,e.preventDefault(),s.accum={x:s.accum.x+o.dx,y:s.accum.y+o.dy};for(let e of s.members)Con(e,s.accum);s.timer&&clearTimeout(s.timer),s.timer=setTimeout(()=>i.current(),Lsn)}},s=(0,U.useRef)(o);s.current=o,ax(()=>{let e=e=>s.current(e);window.addEventListener(`keydown`,e,!0);let t=XKt(()=>i.current());return()=>{window.removeEventListener(`keydown`,e,!0),t(),i.current()}});let c=zsn(e.selection),l=Bsn(e.groupSelections);return(0,U.useEffect)(()=>()=>void i.current(),[c,l]),(0,U.useEffect)(()=>{let t=e.groupSelections.length>1?e.groupSelections:e.selection?[e.selection]:[];if(!(!e.allowCanvasMovement||!r6(t)))return R5t()},[e.selection,e.groupSelections,e.allowCanvasMovement]),{flushNudge:(0,U.useCallback)(()=>i.current(),[])}}var Gsn=6,Ksn=4,qsn=`rgba(255, 68, 204, 0.85)`,i6=`rgba(255, 68, 204, 0.6)`,Jsn=`rgba(255, 68, 204, 0.15)`,Ysn=(0,U.memo)(function({snapGuidesRef:e,compositionLeft:t,compositionTop:n,compositionWidth:r,compositionHeight:i}){let a=(0,U.useRef)([]),o=(0,U.useRef)([]),s=(0,U.useRef)([]),c=(0,U.useRef)({left:t,top:n,width:r,height:i});return c.current={left:t,top:n,width:r,height:i},ax(()=>X2(()=>{let t=e.current,n=t?.guides??[],r=t?.spacingGuides??[],i=c.current;for(let e=0;e<Gsn;e++){let t=a.current[e];if(!t)continue;let r=n[e];if(!r){t.style.display=`none`;continue}t.style.display=``;let o=asn(r,i);t.style.left=`${o.left}px`,t.style.top=`${o.top}px`,t.style.width=`${o.width}px`,t.style.height=`${o.height}px`}for(let e=0;e<Ksn;e++){let t=o.current[e],n=s.current[e];if(!t)continue;let i=r[e];if(!i){t.style.display=`none`;continue}t.style.display=`flex`,t.style.alignItems=`center`,t.style.justifyContent=`center`,i.axis===`x`?(t.style.left=`${i.position}px`,t.style.top=`${i.from}px`,t.style.width=`${i.size}px`,t.style.height=`${i.to-i.from}px`,t.style.borderLeft=`1px dashed ${i6}`,t.style.borderRight=`1px dashed ${i6}`,t.style.borderTop=`none`,t.style.borderBottom=`none`):(t.style.left=`${i.from}px`,t.style.top=`${i.position}px`,t.style.width=`${i.to-i.from}px`,t.style.height=`${i.size}px`,t.style.borderTop=`1px dashed ${i6}`,t.style.borderBottom=`1px dashed ${i6}`,t.style.borderLeft=`none`,t.style.borderRight=`none`),n&&(n.textContent=`${Math.round(i.size)}`)}})),(0,W.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[Array.from({length:Gsn},(e,t)=>(0,W.jsx)(`div`,{ref:e=>{a.current[t]=e},style:{display:`none`,position:`absolute`,backgroundColor:qsn,zIndex:50}},`guide-${t}`)),Array.from({length:Ksn},(e,t)=>(0,W.jsx)(`div`,{ref:e=>{o.current[t]=e},style:{display:`none`,position:`absolute`,zIndex:50},children:(0,W.jsx)(`span`,{ref:e=>{s.current[t]=e},style:{fontSize:`10px`,fontFamily:`monospace`,color:qsn,backgroundColor:Jsn,padding:`0 3px`,borderRadius:`2px`,lineHeight:`14px`,whiteSpace:`nowrap`}})},`spacing-${t}`))]})}),a6=e=>({width:e.offsetWidth,height:e.offsetHeight});function Xsn(e){let t=R0(e,[`clipPath`]);return{width:!t&&!K9t(e,[`width`]),height:!t&&!K9t(e,[`height`])}}function Zsn(e,t,n,r){let i=r.width&&t.width>0?n.width/t.width:1,a=r.height&&t.height>0?n.height/t.height:1;return{top:e.top*a,right:e.right*i,bottom:e.bottom*a,left:e.left*i,radius:e.radius}}function o6(e){let t=k4(e),n=Ten(e);return t&&n?Zsn(t,n,a6(e),Xsn(e)):t}function s6(e){let t=Ten(e)??a6(e),n=e.style.getPropertyValue(`clip-path`),r=e.style.getPropertyPriority(`clip-path`),i=Xsn(e),a=k4(e);return()=>{a2(e);let o=a6(e),s=e.style.getPropertyValue(`clip-path`)===n;if(!a||!xin(a)||!s||!(o.width>0&&o.height>0))return null;let c=D4(Zsn(a,t,o,i),a.radius);return c===D4(a,a.radius)?null:(e.style.setProperty(`clip-path`,c,r),{patch:{type:`inline-style`,property:`clip-path`,value:r?`${c} !important`:c},revert:()=>{n?e.style.setProperty(`clip-path`,n,r):e.style.removeProperty(`clip-path`)}})}}async function Qsn(e,t,n,r){let i=e();if(i)try{return await n(t,[i.patch],{label:`Resize layer`,coalesceKey:r,coalesceMs:1/0})}catch(e){throw i.revert(),e}}var $sn=0;async function ecn(e,t,n,r,i){if(!n||!(`width`in t||`height`in t))return i();let a=s6(e.element),o=`size-write:${++$sn}`,s={coalesceKey:o,coalesceMs:1/0},c=(e,t,r)=>n(e,t,{...r,...s});if(n.batch){let e=n.batch;c.batch=(t,n)=>e(t,{...n,...s})}await i(c),await Qsn(a,e,r,o)}var tcn=[{label:`16:9`,ratio:16/9},{label:`9:16`,ratio:9/16},{label:`1:1`,ratio:1},{label:`4:5`,ratio:4/5}];function ncn(e,t,n){let r={top:0,right:0,bottom:0,left:0};if(e<=0||t<=0||n<=0)return r;if(e/t>n){let i=(e-t*n)/2;return i>1e-9?{...r,left:i,right:i}:r}let i=(t-e/n)/2;return i>1e-9?{...r,top:i,bottom:i}:r}var c6=`rounded-sm border border-white/20 px-1.5 py-0.5 text-[10px] text-white/85 hover:bg-white/10`;function rcn({left:e,top:t,elementWidth:n,elementHeight:r,onApply:i,onDone:a}){return(0,U.useEffect)(()=>{let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]),(0,W.jsxs)(`div`,{role:`toolbar`,"aria-label":`Crop presets`,"data-dom-edit-crop-bar":`true`,className:`pointer-events-auto absolute z-20 flex gap-1 rounded-md border border-white/15 bg-neutral-900/95 p-1 shadow-lg`,style:{left:e,top:Math.max(4,t-34),transform:`translateX(-50%)`},onPointerDown:e=>e.stopPropagation(),children:[(0,W.jsx)(`button`,{type:`button`,className:c6,title:`Drag the edges freely`,children:`Free`}),tcn.map(e=>(0,W.jsx)(`button`,{type:`button`,className:c6,onClick:()=>i(ncn(n,r,e.ratio)),children:e.label},e.label)),(0,W.jsx)(`button`,{type:`button`,className:c6,onClick:()=>i(null),children:`Reset`}),(0,W.jsx)(`button`,{type:`button`,className:`rounded-sm border border-studio-accent bg-studio-accent px-1.5 py-0.5 text-[10px] font-semibold text-black`,onClick:a,children:`Done`})]})}var l6=12,icn=32,acn=24,ocn=22;function scn(e,t){let n=e===`left`||e===`right`,r=Math.min(icn,(n?t.height:t.width)-N4);if(r<=0)return null;let i=Math.min(acn,r);return n?{hit:{left:e===`left`?t.left-l6:t.left+t.width,top:t.top+(t.height-r)/2,width:l6,height:r},cursor:`ew-resize`,pill:{width:4,height:i}}:{hit:{left:t.left+(t.width-r)/2,top:e===`top`?t.top-l6:t.top+t.height,width:r,height:l6},cursor:`ns-resize`,pill:{width:i,height:4}}}function ccn(e){return Math.min(ocn,Math.max(e.width,e.height)-N4)}var lcn=[`top`,`right`,`bottom`,`left`],u6={top:0,right:0,bottom:0,left:0,radius:0};function ucn({selection:e,overlayRect:t,onStyleCommit:n}){let r=(0,U.useRef)(null),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(null),c=e=>{let t=k4(e),{top:n,right:r,bottom:i,left:a}=t??u6;return{element:e,croppable:t!==null,insets:{top:n,right:r,bottom:i,left:a}}},[l,u]=(0,U.useState)(()=>c(e.element)),d=SQ(e=>e.openFor),f=SQ(e=>e.close),p=Z$t(e.element,d);l.element!==e.element&&u(c(e.element));let m=o6(e.element)??u6,h=i?l.insets:m,g=xin(h);(0,U.useEffect)(()=>{let t=e.element;if(k4(t)!==null)return hin(t),()=>gin(t)},[e.element]);let _=kin(e.element,t),v=_.width/_.scaleX,y=_.height/_.scaleY,b=pin({left:0,top:0,width:_.width,height:_.height},h,_.scaleX,_.scaleY),x=ccn(b),S=(t,i)=>{if(!n)return;i.preventDefault(),i.stopPropagation(),i.currentTarget.setPointerCapture(i.pointerId);let o=o6(e.element)??u6;r.current={edge:t,pointerId:i.pointerId,startX:i.clientX,startY:i.clientY,startInsets:o,insets:o,radius:o.radius,angleDeg:_.angleDeg,scaleX:_.scaleX,scaleY:_.scaleY},u(e=>({...e,insets:o})),a(!0)},C=e=>{let t=r.current;if(!t||!J4(t,e))return;e.preventDefault(),e.stopPropagation();let n=Ain(e.clientX-t.startX,e.clientY-t.startY,t.angleDeg),i={startInsets:t.startInsets,deltaX:n.deltaX,deltaY:n.deltaY,scaleX:t.scaleX,scaleY:t.scaleY},a=t.edge===`move`?Cin(i):Sin({...i,edge:t.edge,width:v,height:y});t.insets=a,u(e=>({...e,insets:a}))},w=e=>{let t=r.current;return!t||t.pointerId!==e.pointerId?null:(e.preventDefault(),e.stopPropagation(),r.current=null,a(!1),t)},T=e=>{let t=w(e);if(!t)return;let n=D4(t.insets,t.radius);n!==D4(t.startInsets,t.radius)&&E(n,`drag`)},E=(e,t)=>{let r=n?.(`clip-path`,e);Promise.resolve(r).then(e=>h4(`crop`,t,e)).catch(()=>void 0)},D=t=>{let n=t??{top:0,right:0,bottom:0,left:0};u(e=>({...e,insets:n}));let r=o6(e.element)?.radius??0;E(t===null?``:D4(n,r),`button`)},O=e=>{let t=w(e);t&&u(e=>({...e,insets:t.startInsets}))};return l.croppable?(0,W.jsxs)(W.Fragment,{children:[p&&n&&(0,W.jsx)(rcn,{left:_.left+_.width/2,top:_.top,elementWidth:v,elementHeight:y,onApply:D,onDone:f}),(0,W.jsxs)(`div`,{"data-dom-edit-crop-frame":`true`,className:`pointer-events-none absolute`,style:{left:_.left,top:_.top,width:_.width,height:_.height,transform:_.angleDeg===0?void 0:`rotate(${_.angleDeg}deg)`},children:[g&&(0,W.jsx)(`div`,{className:`pointer-events-none absolute inset-0 overflow-hidden`,children:(0,W.jsx)(`div`,{className:`absolute`,style:{left:b.left,top:b.top,width:b.width,height:b.height,boxShadow:`0 0 0 100000px rgba(8, 8, 12, 0.6)`}})}),(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute border border-dashed border-studio-accent`,style:{left:b.left,top:b.top,width:b.width,height:b.height},children:i&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`absolute inset-y-0 left-1/3 w-px bg-studio-accent/40`}),(0,W.jsx)(`div`,{className:`absolute inset-y-0 left-2/3 w-px bg-studio-accent/40`}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-1/3 h-px bg-studio-accent/40`}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-2/3 h-px bg-studio-accent/40`})]})}),g&&x>0&&(0,W.jsx)(`button`,{type:`button`,"aria-label":`Reposition crop`,title:`Reposition crop`,"data-dom-edit-crop-handle":`true`,className:`pointer-events-auto absolute rounded-full border-2 border-studio-accent bg-studio-accent/30 shadow-[0_0_0_1px_rgba(0,0,0,0.4)]`,style:{left:b.left+(b.width-x)/2,top:b.top+(b.height-x)/2,width:x,height:x,cursor:`move`,touchAction:`none`},onPointerDown:e=>S(`move`,e),onPointerMove:C,onPointerUp:T,onPointerCancel:O}),lcn.map(e=>{let t=scn(e,b);if(!t)return null;let n=i||g||o===e;return(0,W.jsx)(`button`,{type:`button`,"aria-label":`Crop ${e}`,title:`Crop`,"data-dom-edit-crop-handle":`true`,className:`pointer-events-auto absolute flex items-center justify-center border-0 bg-transparent p-0`,style:{...t.hit,cursor:t.cursor,touchAction:`none`},onPointerEnter:()=>s(e),onPointerLeave:()=>s(t=>t===e?null:t),onPointerDown:t=>S(e,t),onPointerMove:C,onPointerUp:T,onPointerCancel:O,children:(0,W.jsx)(`span`,{className:`pointer-events-none rounded-full bg-studio-accent/90 shadow-[0_0_0_1px_rgba(0,0,0,0.4)] transition-opacity duration-100`,style:{...t.pill,opacity:+!!n}})},e)})]})]}):null}function dcn({overlayRect:e,cropOutlineInsetPx:t,onStartRotate:n}){let r=t??{top:0,right:0,bottom:0,left:0},i=e.left+r.left,a=Math.max(0,e.width-r.left-r.right),o=e.top+e.height-r.bottom;return(0,W.jsx)(`button`,{type:`button`,className:`pointer-events-auto absolute flex items-center justify-center border-0 bg-transparent p-0`,style:{left:i+a/2,top:o+12,width:22,height:22,transform:`translateX(-50%)`,touchAction:`none`,cursor:`grabbing`},title:`Rotate`,"aria-label":`Rotate selection`,onPointerDown:n,children:(0,W.jsx)(`span`,{className:`pointer-events-none flex h-[18px] w-[18px] items-center justify-center rounded-full border border-studio-accent/70 bg-studio-surface text-accent-ink shadow-[0_0_3px_rgba(0,0,0,0.45)]`,children:(0,W.jsxs)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,W.jsx)(`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`}),(0,W.jsx)(`path`,{d:`M21 3v5h-5`}),(0,W.jsx)(`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`}),(0,W.jsx)(`path`,{d:`M8 16H3v5`})]})})})}var fcn=[{handle:`nw`,cursor:`nwse-resize`,x:`left`,y:`top`},{handle:`ne`,cursor:`nesw-resize`,x:`right`,y:`top`},{handle:`sw`,cursor:`nesw-resize`,x:`left`,y:`bottom`},{handle:`se`,cursor:`nwse-resize`,x:`right`,y:`bottom`}],pcn={top:0,right:0,bottom:0,left:0};function mcn(e,t,n){let r=N4/2,i=n??pcn,a={cursor:e.cursor,touchAction:`none`};return a.left=e.x===`left`?t.left+i.left-r:t.left+t.width-i.right-r,a.top=e.y===`top`?t.top+i.top-r:t.top+t.height-i.bottom-r,a}function hcn({groupOverlayItems:e,groupBounds:t,allowCanvasMovement:n,allowBodyDrag:r,groupCanMove:i,gestures:a,onBoxClick:o}){let s=n&&!V2();return(0,W.jsxs)(W.Fragment,{children:[e.map(e=>(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute rounded-xl border border-studio-accent/70`,style:{left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height}},e.key)),(0,W.jsx)(`div`,{"data-dom-edit-selection-box":`true`,className:`pointer-events-auto absolute rounded-xl border border-studio-accent shadow-[0_0_0_1px_rgba(60,230,172,0.3)]`,style:{left:t.left,top:t.top,width:t.width,height:t.height,cursor:r?s&&i?`move`:`default`:void 0},onPointerDown:e=>{!s||!r||e.shiftKey&&!i||a.startGroupDrag(e)},onClick:o})]})}function gcn({selection:e,overlayRect:t,allowCanvasMovement:n,allowBodyDrag:r,cropOutlineInsetPx:i,boxRef:a,boxChromeClass:o,boxClipPath:s,selectionKey:c,groupSelectionCount:l,gestures:u,onStyleCommit:d,onBoxClick:f,inlineText:p}){let m=p?.editing??!1,h=V2(),g=n&&!h;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{"data-dom-edit-chrome":`true`,className:`pointer-events-none absolute inset-0`,style:{transformOrigin:`${t.left+t.width/2}px ${t.top+t.height/2}px`,transform:t.angle?`rotate(${t.angle}deg)`:void 0},children:[g&&!m&&e.capabilities.canApplyManualRotation&&(0,W.jsx)(dcn,{overlayRect:t,cropOutlineInsetPx:i,onStartRotate:e=>{e.stopPropagation(),u.startGesture(`rotate`,e)}}),(0,W.jsx)(`div`,{ref:a,"data-dom-edit-selection-box":`true`,className:`${m?`pointer-events-none`:`pointer-events-auto`} absolute rounded-md ${o}`,style:{left:t.left,top:t.top,width:t.width,height:t.height,clipPath:s,cursor:r?g&&e.capabilities.canApplyManualOffset?`move`:`default`:void 0},onPointerDown:t=>{if(p?.startFromPress(t)){t.preventDefault(),t.stopPropagation();return}if(!(!r||!g)){if(e.capabilities.canApplyManualOffset){u.startGesture(`drag`,t);return}t.shiftKey||u.startBlockedMove(t,e)}},onClick:f,children:i&&(0,W.jsx)(`div`,{className:`pointer-events-none absolute rounded-md border border-studio-accent/80 shadow-[0_0_0_1px_rgba(60,230,172,0.25)]`,style:{left:i.left,top:i.top,right:i.right,bottom:i.bottom}})},c),g&&!m&&e.capabilities.canApplyManualSize&&fcn.map(n=>n.handle!==`se`&&!e.capabilities.canApplyManualOffset?null:(0,W.jsx)(`div`,{className:`pointer-events-auto absolute flex h-4 w-4 items-center justify-center`,style:{...mcn(n,t,i??void 0),cursor:kan(n.handle,t.angle??0)},onPointerDown:e=>{e.stopPropagation(),u.startGesture(`resize`,e,{resizeHandle:n.handle})},children:(0,W.jsx)(`div`,{className:`pointer-events-none h-[12px] w-[12px] rounded-full border-[1.5px] border-studio-accent bg-white shadow-[0_0_3px_rgba(0,0,0,0.45)]`})},n.handle))]}),e.capabilities.canCrop&&!m&&!h&&l<=1&&(0,W.jsx)(ucn,{selection:e,overlayRect:t,onStyleCommit:d})]})}function _cn(e){let{selection:t,overlayRect:n}=e,r=t&&!_in(t.element)?k4(t.element):null,i=!!(r&&(r.top>0||r.right>0||r.bottom>0||r.left>0)),a=n&&n.editScaleX>0?n.editScaleX:1,o=n&&n.editScaleY>0?n.editScaleY:1;return{hasCropInsets:i,cropOutlineInsetPx:r&&i?{top:r.top*o,right:r.right*a,bottom:r.bottom*o,left:r.left*a}:void 0}}function vcn(e){let t={borderRadius:8,clipPath:void 0};if(!e?.element)return t;try{let n=e.element.tagName.toLowerCase();if(n===`svg`||n===`img`||n===`video`||n===`canvas`)return t;let r=e.element.ownerDocument.defaultView;if(!r)return t;let i=r.getComputedStyle(e.element),a=i.borderRadius,o=i.clipPath;return{borderRadius:a&&a!==`0px`?a:4,clipPath:o&&o!==`none`?o:void 0}}catch{return t}}function ycn(e,t){return e?``:t?`shadow-[inset_0_0_0_2px_rgba(60,230,172,0.6)]`:`border border-studio-accent/80 shadow-[0_0_0_1px_rgba(60,230,172,0.25)]`}var bcn={"bring-forward":[`M3 11 L8 8.5 L13 11 L8 13.5 Z`,`M8 8.5 L8 2`,`M5.5 4.5 L8 2 L10.5 4.5`],"send-backward":[`M3 5 L8 2.5 L13 5 L8 7.5 Z`,`M8 7.5 L8 14`,`M5.5 11.5 L8 14 L10.5 11.5`],"bring-to-front":[`M3 9.5 L8 7 L13 9.5 L8 12 Z`,`M3 12.5 L8 10 L13 12.5 L8 15 Z`,`M8 12.5 L8 2`,`M5.5 4.5 L8 2 L10.5 4.5`],"send-to-back":[`M3 4 L8 1.5 L13 4 L8 6.5 Z`,`M3 7 L8 4.5 L13 7 L8 9.5 Z`,`M8 3.5 L8 14`,`M5.5 11.5 L8 14 L10.5 11.5`]};function xcn({action:e}){return(0,W.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`mr-2 shrink-0`,"aria-hidden":`true`,children:bcn[e].map(e=>(0,W.jsx)(`path`,{d:e},e))})}var Scn=[{action:`bring-to-front`,label:`Bring to front`},{action:`bring-forward`,label:`Bring forward`},{action:`send-backward`,label:`Send backward`},{action:`send-to-back`,label:`Send to back`}],Ccn=(0,U.memo)(function({x:e,y:t,selection:n,onClose:r,onApplyZIndex:i,onZOrderCrossed:a,onDelete:o}){let s=yG(r),c=!!i,l=!!o,u=c&&l,d=t+(8+(c?Scn.length*28:0)+ +!!u+(l?28:0)+8)-window.innerHeight,f=e+200>window.innerWidth?e-200:e,p=d>0?t-d-8:t,m=n.element;function h(e){if(!i)return;let t=FJt(m,e);if(t===null)return;let{patches:n,crossed:o}=t;i(n,e,o),o&&a&&a(o,e),r()}function g(){o&&(o(n),r())}if(!c&&!l)return null;let _=e=>{e.stopPropagation()};return(0,pm.createPortal)((0,W.jsxs)(`div`,{ref:s,className:`${wQ.panel} fixed z-200 min-w-[180px]`,style:{left:f,top:p},onPointerDown:_,onMouseDown:_,onClick:_,onContextMenu:e=>{e.preventDefault(),e.stopPropagation()},children:[c&&Scn.map(({action:e,label:t})=>{let n=PJt(m,e);return(0,W.jsxs)(`button`,{type:`button`,className:`w-full flex items-center px-3 py-1.5 text-xs text-left ${n?`text-neutral-300 hover:bg-neutral-800 cursor-pointer`:`text-neutral-600 cursor-not-allowed`}`,disabled:!n,onPointerDown:t=>{t.button===0&&(t.preventDefault(),t.stopPropagation(),n&&h(e))},children:[(0,W.jsx)(xcn,{action:e}),(0,W.jsx)(`span`,{children:t})]},e)}),u&&(0,W.jsx)(`div`,{className:wQ.divider}),l&&(0,W.jsxs)(`button`,{type:`button`,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-danger-ink hover:bg-neutral-800 cursor-pointer text-left`,onPointerDown:e=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),g())},children:[(0,W.jsx)(`span`,{children:`Delete`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌫`})]})]}),document.body)}),wcn=2;function Tcn({session:e,iframe:t}){let[n,r]=(0,U.useState)(null),i=e?.element??null;return(0,U.useEffect)(()=>{if(!i||!t){r(null);return}let e=i.ownerDocument,n=e.defaultView,a=t.ownerDocument.defaultView,o=Ecn(i),s=i.style.caretColor;i.style.caretColor=`transparent`;let c=!1,l=`after`,u=()=>r(c?null:kcn(i,t,o,l)),d=({key:e})=>{Dcn.has(e)||(l=Ocn[e]??`after`)},f=()=>void(l=`after`),p=e=>()=>{c=e,u()},m=p(!0),h=p(!1),g=``,_=0,v=()=>{let{left:e,top:n,width:r,height:i}=t.getBoundingClientRect(),o=`${e},${n},${r},${i}`;o!==g&&(g=o,u()),_=a?.requestAnimationFrame(v)??0};return e.addEventListener(`selectionchange`,u),i.addEventListener(`keydown`,d),i.addEventListener(`pointerdown`,f),i.addEventListener(`input`,u),i.addEventListener(`focus`,u),i.addEventListener(`blur`,u),i.addEventListener(`compositionstart`,m),i.addEventListener(`compositionend`,h),n?.addEventListener(`resize`,u),n?.addEventListener(`scroll`,u,!0),v(),()=>{a?.cancelAnimationFrame(_),e.removeEventListener(`selectionchange`,u),i.removeEventListener(`keydown`,d),i.removeEventListener(`pointerdown`,f),i.removeEventListener(`input`,u),i.removeEventListener(`focus`,u),i.removeEventListener(`blur`,u),i.removeEventListener(`compositionstart`,m),i.removeEventListener(`compositionend`,h),n?.removeEventListener(`resize`,u),n?.removeEventListener(`scroll`,u,!0),i.style.caretColor=s}},[i,t]),!n||!t?null:(0,pm.createPortal)((0,W.jsx)(`div`,{"data-inline-text-caret":`true`,"aria-hidden":`true`,className:`hf-inline-text-caret pointer-events-none fixed z-200`,style:{left:n.left,top:n.top,width:wcn,height:n.height,background:n.color}},`${n.left},${n.top}`),t.ownerDocument.body)}function Ecn(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e);return t?t.caretColor&&t.caretColor!==`auto`?t.caretColor:t.color:`currentColor`}var Dcn=new Set([`Shift`,`Control`,`Alt`,`Meta`]),Ocn={End:`before`};function kcn(e,t,n,r){let i=e.ownerDocument.defaultView,a=i?jcn(e,i):null;if(!i||!a)return null;let o=r===`before`&&Mcn(a)||Acn(a,e,i),s=t.getBoundingClientRect(),c=i.innerWidth?s.width/i.innerWidth:1;return{left:s.left+o.left*c-wcn/2,top:s.top+o.top*c,height:o.height*c,color:n}}function Acn(e,t,n){let r=[...e.getClientRects()].reverse().find(e=>e.height>0);if(r)return{left:r.left,top:r.top,height:r.height};let i=Ncn(e);if(i)return i;let a=n.getComputedStyle(t),o=t.getBoundingClientRect(),s=Number.parseFloat(a.fontSize)||16,c=Number.parseFloat(a.lineHeight)||s*1.2;return{left:o.left+(Number.parseFloat(a.paddingLeft)||0),top:o.top+(Number.parseFloat(a.paddingTop)||0),height:c}}function jcn(e,t){let n=e.ownerDocument,r=t.getSelection();if(!r||r.rangeCount===0||!r.isCollapsed||!n.hasFocus()||!e.contains(n.activeElement))return null;let i=r.getRangeAt(0);return e.contains(i.startContainer)?i:null}function Mcn({startContainer:e,startOffset:t}){if(e.nodeType!==Node.TEXT_NODE||t===0)return null;let n=e.ownerDocument.createRange(),r=/[\uDC00-\uDFFF]/.test(e.data[t-1]??``);n.setStart(e,t-(r&&t>1?2:1)),n.setEnd(e,t);let i=[...n.getClientRects()].find(e=>e.height>0);return i?{left:i.right,top:i.top,height:i.height}:null}function Ncn(e){let[t,n]=Pcn(e),r=t&&t.nodeName!==`BR`?t:n??t;if(!r)return null;let i=e.cloneRange();i.selectNode(r);let a=[...i.getClientRects()].filter(e=>e.height>0),o=r===t,s=o?a.at(-1):a[0];return s?{left:o?s.right:s.left,top:s.top,height:s.height}:null}function Pcn({startContainer:e,startOffset:t}){return e.nodeType===Node.TEXT_NODE?[e.previousSibling,e.nextSibling]:[e.childNodes[t-1]??null,e.childNodes[t]??null]}var Fcn={B:{"font-weight":`700`},STRONG:{"font-weight":`700`},I:{"font-style":`italic`},EM:{"font-style":`italic`},U:{"text-decoration-line":`underline`}},Icn=`\0`;function Lcn(e,t){if(e.collapsed)return;let n=Ucn(e.startContainer);if(!n||!Hcn(n,e))return;let r=Wcn(n),i=zcn(r,m6(n,e.startContainer,e.startOffset),m6(n,e.endContainer,e.endOffset));i&&(rln(n,Qcn(r,i.start,i.end,t)),Rcn(n),fln(n,i.start,i.end))}function Rcn(e){let t=e.ownerDocument.defaultView;if(t?.getComputedStyle)for(let n of e.querySelectorAll(`span`)){if(!n.style.color)continue;n.style.getPropertyValue(`-webkit-text-fill-color`)===n.style.color&&n.style.removeProperty(`-webkit-text-fill-color`);let e=t.getComputedStyle(n),r=e.webkitTextFillColor;!r||!e.color||r!==e.color&&n.style.setProperty(`-webkit-text-fill-color`,n.style.color)}}function zcn(e,t,n){if(t===null||n===null||t>=n)return null;let r=e.map(e=>e.text).join(``),i=new Intl.Segmenter(void 0,{granularity:`grapheme`}),a=[0,...Array.from(i.segment(r),Bcn)];return{start:Vcn(a,t),end:a.find(e=>e>=n)??n}}function Bcn({index:e,segment:t}){return e+t.length}function Vcn(e,t){let n=t;for(let r of e){if(r>t)return n;n=r}return n}function Hcn(e,t){return e.contains(t.startContainer)&&e.contains(t.endContainer)}function d6(e){let t=Ucn(e.startContainer);if(!t||!Hcn(t,e))return null;let n=m6(t,e.startContainer,e.startOffset),r=m6(t,e.endContainer,e.endOffset);if(n===null||r===null)return null;let i=n===r,a=Zcn(Wcn(t)).slice(i?Math.max(0,n-1):n,i?Math.max(1,n):r).map(e=>({char:e.char,style:e.style,painter:e.painter??null}));return a.length>0?a:null}function Ucn(e){let t=e.nodeType===1?e:e.parentElement,n=t?.closest(`[contenteditable]`);if(n)return n.getAttribute(`contenteditable`)?.toLowerCase()===`false`?null:n;for(;t?.parentElement&&Q9e(t.tagName);)t=t.parentElement;return t}function Wcn(e){let t=[],n=Array.from(e.childNodes,e=>({node:e,inherited:{},origin:null})).reverse();for(let e=n.pop();e;e=n.pop())n.push(...Gcn(e,t));return t}function Gcn(e,t){let{node:n,inherited:r,origin:i}=e;if(n.nodeType===3){let e=n.textContent??``;return e&&t.push({...qcn(e,r,i),painter:n.parentElement}),[]}if(!Kcn(n))return[];let a=n;return a.tagName===`BR`?(t.push(qcn(Icn,r,i)),[]):Jcn(a,r,i)}function Kcn(e){return e.nodeType===1&&`style`in e}function qcn(e,t,n){return{text:e,style:t,origin:n,identity:Ycn(n)}}function Jcn(e,t,n){let r=Q9e(e.tagName),i=r?{...t,...Fcn[e.tagName],...Xcn(e)}:t,a=r&&!n&&p6(e).size>0?e:n;return Array.from(e.childNodes,e=>({node:e,inherited:i,origin:a})).reverse()}function Ycn(e){return e?JSON.stringify([...p6(e)].sort(([e],[t])=>e<t?-1:1)):``}function Xcn(e){let t={};for(let n=0;n<e.style.length;n+=1){let r=e.style.item(n);if(!r)continue;let i=e.style.getPropertyValue(r);eet(r,i)&&(t[r]=i)}return t}function Zcn(e){let t=[];for(let n of e)for(let e=0;e<n.text.length;e+=1)t.push({char:n.text[e]??``,style:n.style,origin:n.origin,identity:n.identity,painter:n.painter});return t}function Qcn(e,t,n,r){let i=e.map(e=>e.text).join(``),a=Zcn(e),o=[];for(let e=0;e<i.length;e+=1)eln(o,i[e]??``,$cn(a[e],e>=t&&e<n,r));return o}function $cn(e,t,n){let r=e?.style??{};return{style:t?tln(r,n):r,origin:e?.origin??null,identity:e?.identity??``}}function eln(e,t,n){let r=e[e.length-1];if(r&&r.identity===n.identity&&nln(r.style,n.style)){r.text+=t;return}e.push({text:t,...n})}function tln(e,t){let n={...e};for(let[e,r]of Object.entries(t))r===null?delete n[e]:n[e]=r;return n}function nln(e,t){return f6(e)===f6(t)}function f6(e){return Object.keys(e).sort().map(t=>`${t}: ${e[t]}`).join(`; `)}function rln(e,t){let n=e.ownerDocument,r=iln(n,t);if(e.replaceChildren(),r.length>1&&cln(e)){let t=n.createElement(`span`);t.append(...r),e.append(t);return}e.append(...r)}function iln(e,t){let n=[],r=new Set;for(let i of t){let t=i.origin&&!r.has(i.origin)?p6(i.origin):new Map;t.size>0&&i.origin&&r.add(i.origin),n.push(...aln(e,i,t))}return n}function aln(e,t,n){let r=f6(t.style),i=[];for(let[a,o]of t.text.split(Icn).entries()){if(a>0&&i.push(e.createElement(`br`)),!o)continue;if(!r&&n.size===0){i.push(e.createTextNode(o));continue}let t=e.createElement(`span`);for(let[e,r]of n)t.setAttribute(e,r);r&&t.setAttribute(`style`,r),t.textContent=o,i.push(t),n.clear()}return i}var oln=`data-hf-id`;function p6(e){let t=new Map;for(let n of e.getAttributeNames()){if(n===`style`||n===oln)continue;let r=e.getAttribute(n)??``;$9e(n,r)&&t.set(n,r)}return t}var sln=new Set([`flex`,`inline-flex`,`grid`,`inline-grid`,`-webkit-box`,`-webkit-inline-box`]);function cln(e){let t=e.ownerDocument.defaultView;return t?sln.has(t.getComputedStyle(e).display):!1}function m6(e,t,n){if(t===e)return Array.from(e.childNodes).slice(0,n).reduce((e,t)=>e+uln(t),0);let r=0,i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),a=i.nextNode();for(;a;){if(a===t)return r+n;r+=lln(a),a=i.nextNode()}return null}function lln(e){return e.nodeType===3?(e.textContent??``).length:+(dln(e)===`BR`)}function uln(e){let t=0,n=[e];for(let e=n.pop();e;e=n.pop())t+=lln(e),n.push(...Array.from(e.childNodes));return t}function dln(e){return e.nodeType===1?e.tagName:``}function fln(e,t,n){let r=e.ownerDocument,i=r.defaultView?.getSelection(),a=pln(e,t),o=pln(e,n);if(!i||!a||!o)return;let s=r.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset),i.removeAllRanges(),i.addRange(s)}function pln(e,t){let n=0,r=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),i=r.nextNode(),a=null;for(;i;){if(i.nodeType!==3){dln(i)===`BR`&&(n+=1),i=r.nextNode();continue}let e=(i.textContent??``).length;if(n+e>=t)return{node:i,offset:t-n};n+=e,a=i,i=r.nextNode()}return a?{node:a,offset:(a.textContent??``).length}:{node:e,offset:0}}function mln(e,t){let n=d6(e);if(!n)return{};let r={};for(let e of t){let t=n[0]?.style[e];t!==void 0&&n.every(({style:n})=>n[e]===t)&&(r[e]=t)}return r}function hln(e,t){let n=d6(e);if(!n)return[];let r=new Set,i=[];for(let{char:e,style:a}of n){if(!e.trim())continue;let n=a[t];n===void 0||r.has(n)||(r.add(n),i.push(n))}return i}function gln(e,t){let n=d6(e);if(!n)return null;let r=n.filter(({char:e})=>e.trim());return(r.find(({style:e})=>e[t]!==void 0)??r[0]??n[0])?.painter??null}var _ln=[`color`,`font-weight`,`font-style`,`text-decoration-line`],vln=10,yln=34,bln=`#ffffff`;function xln({session:e,iframe:t}){let[n,r]=(0,U.useState)(null),i=(0,U.useCallback)(()=>{r(e&&t?wln(e.element,t):null)},[e,t]);(0,U.useEffect)(()=>{let t=e?.element.ownerDocument;if(!t){r(null);return}return t.addEventListener(`selectionchange`,i),()=>t.removeEventListener(`selectionchange`,i)},[e,i]);let a=(0,U.useCallback)(t=>{let n=(e?.element.ownerDocument)?.defaultView?.getSelection();!n||n.rangeCount===0||(Lcn(n.getRangeAt(0),t),i())},[e,i]);if(!n||!t)return null;let o=n.styles;return(0,pm.createPortal)((0,W.jsxs)(`div`,{"data-inline-text-toolbar":`true`,role:`toolbar`,"aria-label":`Text formatting`,className:`pointer-events-auto fixed z-200 flex items-center gap-1 rounded-lg border border-border bg-raised p-1 shadow-[0_8px_24px_rgba(0,0,0,0.55)]`,style:{left:n.left,top:n.top,transform:`translate(-50%, ${n.placeBelow?`0`:`-100%`})`},onPointerDown:Cln,onMouseDown:Cln,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`label`,{className:`group relative flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-hover`,title:`Text colour`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`h-4 w-4 rounded-full border-2 border-border-strong transition-transform duration-150 group-hover:scale-110 group-active:scale-95`,style:{background:Sln(n.colours,o.color),backgroundOrigin:`border-box`}}),(0,W.jsx)(`input`,{type:`color`,"aria-label":`Text colour`,className:`absolute inset-0 h-full w-full min-w-0 cursor-pointer opacity-0`,value:n.pickerColour,onChange:e=>a({color:e.target.value})})]}),(0,W.jsx)(h6,{label:`Bold`,glyph:`B`,bold:!0,on:Tln(o[`font-weight`]),onToggle:e=>a({"font-weight":e?`700`:null})}),(0,W.jsx)(h6,{label:`Italic`,glyph:`I`,italic:!0,on:o[`font-style`]===`italic`,onToggle:e=>a({"font-style":e?`italic`:null})}),(0,W.jsx)(h6,{label:`Underline`,glyph:`U`,underline:!0,on:o[`text-decoration-line`]===`underline`,onToggle:e=>a({"text-decoration-line":e?`underline`:null})})]}),t.ownerDocument.body)}function Sln(e,t){return e.length===0?t||bln:e.length===1?e[0]:`linear-gradient(135deg, ${e.map((t,n)=>`${t} ${(n/(e.length-1)*100).toFixed(2)}%`).join(`, `)})`}function Cln(e){e.preventDefault(),e.stopPropagation()}function h6({label:e,glyph:t,on:n,onToggle:r,bold:i,italic:a,underline:o}){return(0,W.jsx)(`button`,{type:`button`,title:e,"aria-label":e,"aria-pressed":n,className:`flex h-6 w-6 items-center justify-center rounded-md text-xs ${n?`bg-studio-accent/20 text-accent-ink`:`text-text-2 hover:bg-hover`}`,style:{fontWeight:i?700:400,fontStyle:a?`italic`:`normal`,textDecoration:o?`underline`:`none`},onClick:()=>r(!n),children:t})}function wln(e,t){let n=e.ownerDocument.defaultView,r=n?.getSelection();if(!n||!r||r.rangeCount===0||r.isCollapsed)return null;let i=r.getRangeAt(0);if(!e.contains(i.commonAncestorContainer))return null;let a=i.getBoundingClientRect(),o=t.getBoundingClientRect(),s=n.innerWidth?o.width/n.innerWidth:1,c=o.top+a.top*s-vln,l=c<yln,u=mln(i,_ln),d=hln(i,`color`);return{left:o.left+(a.left+a.width/2)*s,top:l?o.top+(a.top+a.height)*s+vln:c,placeBelow:l,styles:u,colours:d,pickerColour:g(u.color??d[0],gln(i,`color`),bln)}}function Tln(e){return e?e===`bold`||e===`bolder`||Number.parseInt(e,10)>=600:!1}var Eln=`true`,Dln=`2px solid #3CE6AC`;function Oln(e){let t=e.ownerDocument.defaultView?.getSelection();if(!t||t.rangeCount===0)return;let n=t.getRangeAt(0);!e.contains(n.startContainer)&&!e.contains(n.endContainer)||t.removeAllRanges()}function kln({onCommit:e,onPause:t}){let n=V2(),[r,i]=(0,U.useState)(null),a=(0,U.useRef)(null),o=(0,U.useRef)(null),s=(0,U.useCallback)(()=>{let e=a.current;return e?(o.current!==null&&(e.element.ownerDocument.defaultView?.cancelAnimationFrame(o.current),o.current=null),a.current=null,W0(e.element,e.gesture),i(null),e.element.isConnected&&(e.element.removeAttribute(`contenteditable`),e.element.style.outline=e.outline,e.element.style.outlineOffset=e.outlineOffset,Oln(e.element),e.element.blur()),e):null},[]),c=(0,U.useCallback)((e,r)=>{if(a.current||n)return!1;let s={element:e,original:e.innerHTML,outline:e.style.outline,outlineOffset:e.style.outlineOffset,gesture:H0(e,`edit`)};e.style.outline=Dln,e.style.outlineOffset=`2px`,a.current=s,i(s),t?.(),e.setAttribute(`contenteditable`,Eln);let c=e.ownerDocument.defaultView?.requestAnimationFrame(()=>{o.current=null,a.current?.element===e&&(e.focus({preventScroll:!0}),Aln(e,r))});return o.current=c??null,!0},[t,n]),l=(0,U.useCallback)(()=>{let t=a.current;if(!t)return;net(t.element);let n=t.element.innerHTML,r=()=>{};dX(new Promise(e=>r=e)),r(q0(t.element,()=>(s(),e({element:t.element,html:n,previousHtml:t.original}))))},[e,s]),u=(0,U.useCallback)(()=>{let e=a.current;e&&(e.element.isConnected&&(e.element.innerHTML=e.original),s())},[s]);(0,U.useEffect)(()=>{n&&a.current&&u()},[u,n]),(0,U.useEffect)(()=>{let e=r?.element;if(!e)return;let t=e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),l();return}e.key===`Escape`&&(e.preventDefault(),l())},n=()=>l(),i=t=>{t&&e.ownerDocument.execCommand(`insertText`,!1,t)},a=e=>{e.preventDefault(),i(e.clipboardData?.getData(`text/plain`)??``)},o=e=>e.preventDefault(),s=e=>{e.preventDefault(),i(e.dataTransfer?.getData(`text/plain`)??``)};return e.addEventListener(`keydown`,t),e.addEventListener(`blur`,n),e.addEventListener(`paste`,a),e.addEventListener(`dragover`,o),e.addEventListener(`drop`,s),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`blur`,n),e.removeEventListener(`paste`,a),e.removeEventListener(`dragover`,o),e.removeEventListener(`drop`,s)}},[r,l]);let d=(0,U.useRef)(l);return d.current=l,(0,U.useEffect)(()=>()=>d.current(),[]),{session:r,start:c,commit:l,cancel:u}}function Aln(e,t){let n=e.ownerDocument,r=n.defaultView?.getSelection();if(!r)return;let i=t?jln(n,t):null;if(i&&e.contains(i.startContainer)){r.removeAllRanges(),r.addRange(i);return}Mln(e)}function jln(e,t){let n=e;if(typeof n.caretRangeFromPoint==`function`)return n.caretRangeFromPoint(t.x,t.y);let r=e.caretPositionFromPoint?.(t.x,t.y);if(!r)return null;let i=e.createRange();return i.setStart(r.offsetNode,r.offset),i.collapse(!0),i}function Mln(e){let t=e.ownerDocument,n=t.defaultView?.getSelection();if(!n)return;let r=t.createRange(),i=e.lastChild;i&&i.nodeType===3?(r.setStart(i,i.textContent?.length??0),r.collapse(!0)):(r.selectNodeContents(e),r.collapse(!1)),n.removeAllRanges(),n.addRange(r)}function Nln(e){return!e||!Se(e)||e.isCompositionHost||e.isInsideLockedComposition?!1:e.textFields.length<=1||g6(e.element)}function g6(e){if(!e)return!1;let t=e.tagName;return t===`BODY`||t===`HTML`||!_6(e)||e.isContentEditable?!1:(e.textContent??``).trim().length>0}function _6(e){for(let t of Array.from(e.children))if(!Q9e(t.tagName)||!Pln(t)||!_6(t))return!1;return!0}function Pln(e){return e.namespaceURI===`http://www.w3.org/1999/xhtml`}var Fln=450,Iln=6;function Lln(e,t){return e?t.element!==null&&e.element===t.element&&t.at-e.at<=Fln&&Math.abs(t.x-e.x)<=Iln&&Math.abs(t.y-e.y)<=Iln:!1}function Rln(e,{enterFromWindow:t=!1}={}){let n=AX(),r=kln({onCommit:e=>n?.handleDomRichTextCommit(e),onPause:()=>X.getState().setIsPlaying(!1)}),i=(0,U.useRef)(null),a=t=>{let r=n?.previewIframeRef?.current;return r?v4(r,t.clientX,t.clientY,e.current?.compositionPath??null):null},o=e=>{let t=n?.previewIframeRef?.current,r=t?.contentWindow;if(!t||!r?.innerWidth)return;let i=t.getBoundingClientRect(),a=i.width/r.innerWidth||1;return{x:(e.clientX-i.left)/a,y:(e.clientY-i.top)/a}},s=t=>{if(t.key!==`Enter`||t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return!1;let n=e.current;return r.session||!n||!Nln(n)?!1:r.start(n.element)},c=(0,U.useRef)(s);return c.current=s,(0,U.useEffect)(()=>{if(!t)return;let e=e=>{let{body:t,documentElement:n}=window.document;e.defaultPrevented||e.target!==t&&e.target!==n||c.current(e)&&e.preventDefault()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),{editing:r.session!==null,toolbar:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(xln,{session:r.session,iframe:n?.previewIframeRef?.current??null}),(0,W.jsx)(Tcn,{session:r.session,iframe:n?.previewIframeRef?.current??null})]}),handleKeyDown:s,startFromPress:e=>{if(r.session)return!1;let t=a(e),n={x:e.clientX,y:e.clientY,at:Date.now(),element:t},s=Lln(i.current,n);return i.current=n,!s||!t||!g6(t)?!1:r.start(t,o(e))}}}function v6(e){return Math.round(e*100)/100}function zln(e){return e.map(e=>`${e.key}:${v6(e.left)},${v6(e.top)},${v6(e.width)},${v6(e.height)},${v6(e.angle??0)}`).join(`|`)}function Bln(e,t){let n=(e.angle??0)*Math.PI/180,r=(Math.abs(Math.cos(n))*e.width+Math.abs(Math.sin(n))*e.height)/2,i=(Math.abs(Math.sin(n))*e.width+Math.abs(Math.cos(n))*e.height)/2,a=e.left+e.width/2,o=e.top+e.height/2;return a-r<t.left||a+r>t.left+t.width||o-i<t.top||o+i>t.top+t.height}function Vln(e,t,n,r,i){if(!m(n,i.visible))return null;let a=W4(e,t,n,r,i);return a?{...a,...j4(a,n)}:null}function Hln(e,t,n,r,i,a,o,s,c){if(r.width<=0||!n){a.current=``,o.current=new Map,s([]);return}let l=n.querySelector(`[data-composition-id]`)??n.body,u=i??`index.html`,d=ot(l,{activeCompositionPath:u,isMasterView:!u||u===`index.html`},void 0,c),f=C4(t,e,n),p=jin(),m=[],h=new Map;for(let n of d){let i=Vln(t,e,n.element,f,p);i&&Bln(i,r)&&(m.push({key:n.key,left:i.left,top:i.top,width:i.width,height:i.height,angle:i.angle}),h.set(n.key,n.element))}let g=zln(m);g!==a.current&&(a.current=g,o.current=h,s(m))}function Uln(e){return`${Math.round(e.left)}:${Math.round(e.top)}:${Math.round(e.width)}:${Math.round(e.height)}`}function Wln(e){e.dirtyRef.current=!1,e.sigRef.current=``,e.elementsRef.current=new Map,e.setRects([])}function Gln(e,t,n){let r=e.defaultView?.MutationObserver??globalThis.MutationObserver;if(!r)return null;let i=new r(e=>{t.ingest(e),n()});return i.observe(e.documentElement,qt),i}var Kln=100;function qln(e,t,n){return e&&n-t>=Kln}function Jln(e){let t=``,n=-1/0,r=Dt(),i=()=>{e.dirtyRef.current=!0,Y2()},a=t=>{e.observerRef.current?.disconnect(),r.invalidateAll(),e.observerRef.current=t?.documentElement?Gln(t,r,i):null,e.observedDocRef.current=t,e.sigRef.current=``},o=X2(()=>{let o=e.iframeRef.current,s=e.overlayRef.current,c=o?.contentDocument??null;c!==e.observedDocRef.current&&(a(c),i());let l=e.compRectRef.current,u=Uln(l);if(u!==t&&(t=u,i()),!o||!s){e.dirtyRef.current&&Wln(e);return}let d=performance.now();qln(e.dirtyRef.current,n,d)&&(n=d,e.dirtyRef.current=!1,lt(e.observerRef.current,r),Hln(o,s,c,l,e.activeCompositionPathRef.current,e.sigRef,e.elementsRef,e.setRects,r))});return()=>{o(),e.observerRef.current?.disconnect(),e.observerRef.current=null,e.observedDocRef.current=null}}function Yln({iframeRef:e,overlayRef:t,compRectRef:n,activeCompositionPathRef:r,activeCompositionPath:i}){let a=(0,U.useRef)(new Map),[o,s]=(0,U.useState)([]),c=(0,U.useRef)(!0),l=(0,U.useRef)(``),u=(0,U.useRef)(null),d=(0,U.useRef)(null);return ax(()=>Jln({iframeRef:e,overlayRef:t,compRectRef:n,activeCompositionPathRef:r,dirtyRef:c,sigRef:l,observerRef:u,observedDocRef:d,elementsRef:a,setRects:s})),(0,U.useEffect)(()=>{c.current=!0},[i]),{offCanvasRects:o,offCanvasElementsRef:a}}var Xln=(0,U.memo)(function({iframeRef:e,activeCompositionPath:t,selection:n,groupSelections:r=[],hoverSelection:i,allowCanvasMovement:a=!0,allowBodyDrag:o=!0,canvasInput:s=`overlay`,onTextEditingChange:c,onSelectionBoxClick:l,onCanvasMouseDown:u,onCanvasPointerMove:d,onCanvasPointerLeave:f,onSelectionChange:p,onBlockedMove:m,onManualDragStart:h,onPathOffsetCommit:g,onGroupPathOffsetCommit:_,onBoxSizeCommit:v,onRotationCommit:y,onStyleCommit:b,onMarqueeSelect:x,onDeleteSelection:S,onApplyZIndex:C}){let w=V2(),T=s===`host`,E=o||!T,D=(0,U.useRef)(null),O=(0,U.useRef)(null),k=(0,U.useRef)(x);k.current=x;let A=vcn(n),j=(0,U.useRef)(null),M=(0,U.useRef)(null),N=(0,U.useRef)(null),P=(0,U.useRef)(null),F=(0,U.useRef)(!1),I=(0,U.useRef)(null),L=(0,U.useRef)(!1),R=(0,U.useRef)(n);R.current=n;let z=(e,t)=>{let n=R.current;n&&O.current?.contains(e.target)&&l?.(e,n),T||u(e,t)},{zOrderFlashRect:B,handleZOrderCrossed:V}=gan({overlayRef:D,iframeRef:e}),ee=(0,U.useRef)(t);ee.current=t;let te=(0,U.useRef)(r);te.current=r;let H=(0,U.useRef)(i);H.current=i;let ne=Rln(R,{enterFromWindow:T}),re=(0,U.useRef)(c);re.current=c,(0,U.useEffect)(()=>{if(ne.editing)return re.current?.(!0),()=>re.current?.(!1)},[ne.editing]);let ie=(0,U.useRef)(g);ie.current=(e,...t)=>q0(e.element,()=>g(e,...t));let ae=(0,U.useRef)(_);ae.current=e=>{let t=()=>_(e);return e[0]?q0(e[0].selection.element,t):t()};let oe=(0,U.useRef)(v);oe.current=(e,...t)=>q0(e.element,()=>v(e,...t));let se=(0,U.useRef)(y);se.current=(e,t)=>q0(e.element,()=>y(e,t));let ce=(0,U.useRef)(b);ce.current=b&&((e,t)=>{let n=()=>b(e,t);return R.current?q0(R.current.element,n):n()});let le=(0,U.useRef)(m);le.current=m;let ue=(0,U.useRef)(h);ue.current=h;let de=(0,U.useRef)(d);de.current=d;let fe=(0,U.useRef)(f);fe.current=f;let pe=(0,U.useRef)(p);pe.current=p;let{overlayRect:me,overlayRectRef:he,setOverlayRect:ge,hoverRect:_e,groupOverlayItems:ve,groupOverlayItemsRef:ye,setGroupOverlayItems:be,childRects:xe}=ban({iframeRef:e,overlayRef:D,selectionRef:R,activeCompositionPathRef:ee,groupSelectionsRef:te,hoverSelectionRef:H,rafPausedRef:L}),Se=Z2({iframeRef:e,overlayRef:D}),Ce=(0,U.useRef)(Se);Ce.current=Se;let{hasCropInsets:we,cropOutlineInsetPx:Te}=_cn({selection:n,overlayRect:me}),Ee=we?void 0:A.clipPath,De=ycn(!!Te,Ee),{offCanvasRects:Oe,offCanvasElementsRef:ke}=Yln({iframeRef:e,overlayRef:D,compRectRef:Ce,activeCompositionPathRef:ee,activeCompositionPath:t}),Ae=Nsn({activeCompositionPathRef:ee,overlayRef:D,iframeRef:e,boxRef:O,selectionRef:R,hoverSelectionRef:H,overlayRectRef:he,groupOverlayItemsRef:ye,gestureRef:j,groupGestureRef:M,blockedMoveRef:N,waitingPressRef:P,rafPausedRef:L,suppressNextBoxClickRef:F,setOverlayRect:ge,setGroupOverlayItems:be,onBlockedMoveRef:le,onManualDragStartRef:ue,onPathOffsetCommitRef:ie,onGroupPathOffsetCommitRef:ae,onBoxSizeCommitRef:oe,onRotationCommitRef:se,onCanvasPointerMoveRef:de,onCanvasMouseDown:z,snapGuidesRef:I});(0,U.useEffect)(()=>{w&&Ae.clearPointerState(R,!0)},[Ae,w,R]);let je=(0,U.useRef)(e=>{});je.current=e=>Ae.clearPointerState(R,e),ax(()=>{let e=()=>je.current();return window.addEventListener(`blur`,e),()=>{window.removeEventListener(`blur`,e),je.current(!0)}});let{flushNudge:Me}=Wsn({selection:n,groupSelections:r,allowCanvasMovement:a&&!w,selectionRef:R,overlayRectRef:he,groupOverlayItemsRef:ye,gestureRef:j,groupGestureRef:M,blockedMoveRef:N,onBlockedMoveRef:le,onManualDragStartRef:ue,onPathOffsetCommitRef:ie,onGroupPathOffsetCommitRef:ae}),Ne=pan({iframeRef:e,overlayRef:D,activeCompositionPathRef:ee,onMarqueeSelectRef:k,selectionRef:R,gestures:Ae}),Pe=(0,U.useMemo)(()=>n?`${n.sourceFile}:${n.id??n.selector??n.label}:${n.selectorIndex??0}`:`none`,[n]),Fe=(0,U.useMemo)(()=>U4(ve.map(e=>e.rect)),[ve]),Ie=r.length>1,Le=Ie&&ve.length>1&&ve.every(e=>e.selection.capabilities.canApplyManualOffset),Re=e=>{if(!a)return;let t=!!e.target?.closest(`[data-dom-edit-selection-box="true"]`);K4(`mousedown`,{shift:e.shiftKey,onBox:t}),!t&&z(e,{hoverSelection:H.current})},ze=t=>{if(!(!a||T||t.button!==0)){if(t.shiftKey){let n=e.current,r=ean({cached:H.current,elementAtPoint:n?v4(n,t.clientX,t.clientY,ee.current):null});if(!r)return;t.preventDefault(),t.stopPropagation(),F.current=!0,pe.current(r,{additive:!0});return}if(ne.startFromPress(t)){t.preventDefault(),t.stopPropagation();return}if(!t.target?.closest(`[data-dom-edit-selection-box="true"]`)&&!H.current&&k.current&&Se.width>0){let n=e.current;if(n&&v4(n,t.clientX,t.clientY,ee.current))return;if(D.current){t.preventDefault(),t.stopPropagation(),Ne.begin(t);return}}}},Be=e=>{if(a&&!(j.current||M.current)){if(F.current){F.current=!1,e.stopPropagation();return}z(e,{hoverSelection:H.current})}},{contextMenu:Ve,closeContextMenu:He,handleContextMenu:Ue}=van({selection:n,selectionRef:R,hoverSelectionRef:H,onCanvasPointerMoveRef:de,onSelectionChangeRef:pe});return(0,W.jsxs)(`div`,{ref:D,className:`absolute inset-0 z-10 outline-hidden ${ne.editing||T?`pointer-events-none`:`pointer-events-auto`}`,"data-editing-text":ne.editing?`true`:void 0,tabIndex:-1,"aria-label":`Composition canvas`,style:Ne.marqueeRect?{cursor:`crosshair`}:void 0,onPointerDownCapture:e=>{Me(),F.current=!1,ne.editing||Qin(e.currentTarget)},onKeyDown:e=>{ne.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())},onPointerDown:ze,onMouseDown:Re,onPointerMove:Ne.onPointerMove,onPointerLeave:()=>fe.current(),onPointerUp:Ne.onPointerUp,onPointerCancel:Ne.onPointerCancel,onLostPointerCapture:Ae.onLostPointerCapture,onContextMenu:T?void 0:Ue,children:[i&&_e&&Se.width>0&&(0,W.jsx)(`div`,{"aria-hidden":`true`,"data-dom-edit-hover-box":`true`,className:`pointer-events-none absolute rounded-md border border-studio-accent/80 shadow-[0_0_0_1px_rgba(60,230,172,0.25)]`,style:{...j4(_e,i.element),transform:_e.angle?`rotate(${_e.angle}deg)`:void 0}}),Ie&&ve.length>1&&Fe&&Se.width>0&&(0,W.jsx)(hcn,{groupOverlayItems:ve,groupBounds:Fe,allowCanvasMovement:a,allowBodyDrag:E,groupCanMove:Le,gestures:Ae,onBoxClick:Be}),!Ie&&n&&me&&Se.width>0&&(0,W.jsx)(gcn,{inlineText:ne,selection:n,overlayRect:me,allowCanvasMovement:a,allowBodyDrag:E,cropOutlineInsetPx:Te??void 0,boxRef:O,boxChromeClass:De,boxClipPath:Ee,selectionKey:Pe,groupSelectionCount:r.length,gestures:Ae,onStyleCommit:ce.current,onBoxClick:Be}),(0,W.jsx)(Can,{rects:Se.width>0?xe:[]}),ne.toolbar,(0,W.jsx)(San,{rects:T?[]:Oe,elements:ke,compRect:Se,selection:n,groupSelections:r,activeCompositionPathRef:ee,onSelectionChangeRef:pe}),(0,W.jsx)(man,{candidateRects:Ne.candidateRects,marqueeRect:Ne.marqueeRect}),Ve&&(0,W.jsx)(Ccn,{x:Ve.x,y:Ve.y,selection:Ve.sel,onClose:He,onDelete:S&&!w?e=>{He(),S(e)}:void 0,onApplyZIndex:C&&!w?(e,t,n)=>{C(Ve.sel,e,t,n)}:void 0,onZOrderCrossed:V}),(0,W.jsx)(_an,{rect:B}),(0,W.jsx)(Ysn,{snapGuidesRef:I,compositionLeft:Se.left,compositionTop:Se.top,compositionWidth:Se.width,compositionHeight:Se.height})]})}),Zln=`2147483000`,y6=`data-hf-studio-reveal-pending-commit`,Qln=0,b6=new WeakMap,$ln=16;function eun(e){b6.set(e,(b6.get(e)??0)+1);let t=!1;return()=>{if(t)return;t=!0;let n=(b6.get(e)??1)-1;n>0?b6.set(e,n):b6.delete(e)}}function x6(e,t,n){n?e.style.setProperty(t,n):e.style.removeProperty(t)}function S6(e){let t=e.getAttribute(y6);if(!t)return null;try{let e=JSON.parse(t);if(typeof e!=`object`||!e||!(`token`in e))return null;let n=e.token;if(typeof n!=`string`)return null;if(!(`releasedPriors`in e)||e.releasedPriors===void 0)return{token:n};let r=e.releasedPriors;if(typeof r!=`object`||!r||!(`zIndex`in r)||!(`position`in r))return null;let{zIndex:i,position:a}=r;return typeof i==`string`&&typeof a==`string`?{token:n,releasedPriors:{zIndex:i,position:a}}:null}catch{return null}}function tun(e,t){e.setAttribute(y6,JSON.stringify(t))}function nun(e){let t=e.getAttribute(ue);if(t==null)return null;let n={token:`reveal-z-${Qln++}`,priorZ:t,priorPosition:e.getAttribute(ie),activeLiftStyles:{zIndex:e.style.zIndex,position:e.style.position}};return tun(e,{token:n.token}),e.removeAttribute(ue),e.removeAttribute(ie),n}function run(e,t){S6(e)?.token===t.token&&e.removeAttribute(y6)}function iun(e,t){let n=S6(e);if(n?.token===t.token){if(e.removeAttribute(y6),e.removeAttribute(ue),e.removeAttribute(ie),n.releasedPriors){x6(e,`z-index`,n.releasedPriors.zIndex),x6(e,`position`,n.releasedPriors.position);return}x6(e,`z-index`,t.activeLiftStyles.zIndex),x6(e,`position`,t.activeLiftStyles.position),e.setAttribute(ue,t.priorZ),t.priorPosition!=null&&e.setAttribute(ie,t.priorPosition)}}function C6(e,t,n,r){n!=null&&e.style.getPropertyValue(t)===n&&x6(e,t,r)}function aun(e,t){let n=t.getComputedStyle(e),r=Number.parseFloat(n.opacity);return{display:n.display===`none`,visibility:n.visibility===`hidden`||n.visibility===`collapse`,opacity:Number.isFinite(r)&&r<=.01}}function oun(e,t,n){let r={display:e.style.display,visibility:e.style.visibility,opacity:e.style.opacity},i={};return n.display&&(e.style.removeProperty(`display`),t.getComputedStyle(e).display===`none`&&(e.style.display=`block`),i.display=e.style.display),n.visibility&&(e.style.visibility=`visible`,i.visibility=`visible`),n.opacity&&(e.style.opacity=`1`,i.opacity=`1`),{element:e,priors:r,applied:i}}function sun(e){let t=e.ownerDocument,n=t.defaultView;if(!n)return[];let r=[],i=e;for(;i&&i!==t.body&&i!==t.documentElement;){let e;try{e=aun(i,n)}catch{break}(e.display||e.visibility||e.opacity)&&r.push(oun(i,n,e)),i=i.parentElement}return r}function cun(e){let t=e.ownerDocument.defaultView;if(!t)return null;let n={zIndex:e.style.zIndex,position:e.style.position},r=!1;try{e.setAttribute(ue,String(RX(e))),t.getComputedStyle(e).position===`static`&&(e.setAttribute(ie,`static`),e.style.position=`relative`,r=!0)}catch{return e.removeAttribute(ue),null}return e.style.zIndex=Zln,{priors:n,positionLifted:r}}function lun(e,t){if(!e.hasAttribute(`data-hf-reveal-prior-z`)){let n=S6(e);n&&!n.releasedPriors&&tun(e,{...n,releasedPriors:t.priors});return}let n=e.hasAttribute(ie);e.removeAttribute(ue),e.removeAttribute(ie),e.style.zIndex===Zln&&x6(e,`z-index`,t.priors.zIndex),t.positionLifted&&n&&e.style.position===`relative`&&x6(e,`position`,t.priors.position)}function uun({isPlaying:e,selectedElement:t}){let n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)({isPlaying:e,selectedElement:t});i.current={isPlaying:e,selectedElement:t};let a=(0,U.useCallback)(()=>{let e=n.current;if(n.current=null,e){for(let{element:t,priors:n,applied:r}of e.nodes)t.isConnected&&(C6(t,`display`,r.display,n.display),C6(t,`visibility`,r.visibility,n.visibility),C6(t,`opacity`,r.opacity,n.opacity));e.lift&&e.base.isConnected&&lun(e.base,e.lift)}},[]),o=(0,U.useCallback)(e=>{a();let t=sun(e),r=cun(e);(t.length>0||r)&&(n.current={base:e,nodes:t,lift:r})},[a]),s=(0,U.useCallback)(()=>{let e=r.current;r.current=null,e&&window.clearTimeout(e.timer)},[]),c=(0,U.useCallback)((e,t)=>{if(s(),i.current.isPlaying)return;let n=()=>{let t=i.current;if(t.isPlaying||t.selectedElement!==e||!e.isConnected){r.current=null;return}if(b6.has(e)){let t=window.setTimeout(n,$ln);r.current={timer:t,element:e};return}r.current=null,o(e)},a=window.setTimeout(n,t);r.current={timer:a,element:e}},[s,o]);return(0,U.useEffect)(()=>{let i=r.current;(e||i&&i.element!==t)&&s();let o=n.current?.base;(e||o&&t!==o)&&a()},[s,e,a,t]),(0,U.useEffect)(()=>()=>{s(),a()},[s,a]),{scheduleReveal:c}}function dun(e){let t=e.current+1;return e.current=t,()=>e.current===t}function w6(e,t){let n=Symbol(`dom-edit-commit`);e.set(t,n);let r=()=>e.get(t)===n;return Object.assign(r,{release:()=>{r()&&e.delete(t)}})}async function T6(e){try{e.capture(),e.apply();try{await e.persist(),e.onSettled?.(!0)}catch(t){e.shouldRevert(t)&&e.revert(),e.onError(t),e.onSettled?.(!1)}if(!e.shouldResync())return;await e.resync()}finally{e.onFinally?.()}}function E6(e){return{ok:!1,reason:e}}async function fun(e){let t=!1,n;return await T6({...e,persist:async()=>{let t=await e.persist();pun(t)&&(n=t)},onSettled:n=>{t=n,e.onSettled?.(n)}}),t?n?{ok:!0,persistence:n}:{ok:!0}:E6(`persist-failed`)}function pun(e){return typeof e!=`object`||!e?!1:typeof Reflect.get(e,`sourceFile`)==`string`&&typeof Reflect.get(e,`version`)==`string`&&typeof Reflect.get(e,`changed`)==`boolean`}function mun(e,t){let n=[],r={},i=!1;for(let a of t)a.type===`inline-style`?(r[a.property]=a.value,i=!0):a.type===`text-content`?n.push({type:`setText`,target:e,value:a.value??``}):a.type===`attribute`?n.push({type:`setAttribute`,target:e,name:a.property.startsWith(`data-`)?a.property:`data-${a.property}`,value:a.value}):a.type===`html-attribute`&&n.push({type:`setAttribute`,target:e,name:a.property,value:a.value});return i&&n.unshift({type:`setStyle`,target:e,styles:r}),n}var D6={};function hun(e){D6[e]=(D6[e]??0)+1,xun()}function gun(){let e=Object.keys(D6);if(e.length===0)return null;let t={};for(let n of e)t[n]=D6[n],delete D6[n];return t}var _un=3e5,vun=null,yun=null;function bun(){let e=gun();e!==null&&mG(`sdk_resolver_shadow_attempt`,{counts:JSON.stringify(e)})}function xun(){vun||=setInterval(bun,_un),!yun&&typeof document<`u`&&(yun=()=>{document.visibilityState===`hidden`&&(bun(),cLt())},document.addEventListener(`visibilitychange`,yun))}function Sun(e){let t=e.type===`attribute`?e.property.startsWith(`data-`)?e.property:`data-${e.property}`:e.type===`html-attribute`?e.property:null;return t===null||!t.startsWith(`data-hf-`)}var Cun=new Set([`inline-style`,`text-content`,`attribute`,`html-attribute`]);function wun(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Tun(e){if(e==null)return null;let t=e.trim();return t===``?null:t}function Eun(e,t){return e.split(`data-hf-id="${t}"`).length-1+(e.split(`data-hf-id='${t}'`).length-1)}function O6(e,t){let n=e.getElements(),r=n.find(e=>e.scopedId===t);if(r)return r;let i=n.filter(e=>e.id===t);return i.find(e=>e.scopedId===e.id)??i[0]??null}function Dun(e,t){return{expected:e.value??null,actual:t.inlineStyles[wun(e.property)]??t.inlineStyles[e.property]??null}}function Oun(e,t){return{expected:Tun(e.value),actual:Tun(t.text)}}function kun(e,t){let n=e.type===`attribute`?e.property.startsWith(`data-`)?e.property:`data-${e.property}`:e.property;return{property:n,expected:e.value??null,actual:t.attributes[n]??null}}function Aun(e,t,n){let r,i,a;if(e.type===`inline-style`)r=e.property,{expected:i,actual:a}=Dun(e,t);else if(e.type===`text-content`)r=`text`,{expected:i,actual:a}=Oun(e,t);else if(e.type===`attribute`||e.type===`html-attribute`)({property:r,expected:i,actual:a}=kun(e,t));else return null;return a===i?null:{kind:`value_mismatch`,hfId:n,property:r,expected:i,actual:a}}function jun(e,t,n,r){if(!O6(e,t))return r!==void 0&&!r.includes(t)?[]:[{kind:`element_not_found`,hfId:t}];let i=n.filter(Sun);if(i.length===0||i.some(e=>!Cun.has(e.type)))return[];let a=[],o=e.on(`patch`,e=>a.push(...e.inversePatches));try{try{let n=mun(t,i);e.batch(()=>{for(let t of n)e.dispatch(t)})}catch(e){return[{kind:`dispatch_error`,hfId:t,error:String(e)}]}let n=O6(e,t);return n?i.map(e=>Aun(e,n,t)).filter(e=>e!==null):[{kind:`element_not_found`,hfId:t}]}finally{o(),a.length>0&&e.applyPatches(a)}}function Mun(e){return e==null?e:`[redacted len=${e.length}]`}function Nun(e){return e.map(e=>({...e,expected:Mun(e.expected),actual:Mun(e.actual)}))}var Pun=new WeakSet;function Fun(e,t){return e.getElements().length===0&&(Pun.has(e)||(Pun.add(e),mG(`sdk_resolver_shadow`,{opLabel:t,sessionEmpty:!0,sessionElementCount:0,mismatchCount:1,mismatches:JSON.stringify([{kind:`session_empty`}])})),!0)}function Iun(e){return e?.targetPath!==void 0&&e.compositionPath!=null&&e.targetPath!==e.compositionPath}function Lun(e,t,n,r,i){if(Ge&&t)try{if(Iun(i)||Fun(e,`dom-edit`))return;hun(`dom-edit`);let a=jun(e,t,n,r);if(a.length===0)return;let o=a.some(e=>e.kind===`element_not_found`)&&r!==void 0?Eun(r,t):void 0;mG(`sdk_resolver_shadow`,{hfId:t,sessionElementCount:e.getElements().length,...o===void 0?{}:{sourceHfIdCount:o},...o===0?{sourceLooseMatchOnly:!0}:{},mismatchCount:a.length,mismatches:JSON.stringify(Nun(a))})}catch{}}async function Run(e,t){if(!t)return{suppress:!1,sourceReadFailed:!1};let n;try{n=await t()}catch{return{suppress:!1,sourceReadFailed:!0}}return n===void 0?{suppress:!1,sourceReadFailed:!1}:n.includes(e)?{suppress:!1,strictCount:Eun(n,e),sourceReadFailed:!1}:{suppress:!0,sourceReadFailed:!1}}async function k6(e,t,n,r,i){if(Ge&&!(!e||!t))try{if(Iun(i)||Fun(e,n)||(hun(n),O6(e,t)))return;let a=e.getElements().length,o=await Run(t,r);if(o.suppress)return;let{strictCount:s,sourceReadFailed:c}=o;mG(`sdk_resolver_shadow`,{hfId:t,opLabel:n,sessionElementCount:a,...s===void 0?{}:{sourceHfIdCount:s},...s===0?{sourceLooseMatchOnly:!0}:{},...c?{sourceReadFailed:!0}:{},mismatchCount:1,mismatches:JSON.stringify([{kind:`element_not_found`,hfId:t}])})}catch{}}async function zun(e,t){let n;try{n=await t}catch{return{staleSession:!1,diskChecked:!1,sourceReadFailed:!0}}if(n===void 0)return{staleSession:!1,diskChecked:!1,sourceReadFailed:!1};let r;try{r=await Qj(n,{history:!1})}catch{return{staleSession:!1,diskChecked:!1,sourceReadFailed:!0}}try{return{staleSession:r.getAllAnimationIds().has(e),diskChecked:!0,sourceReadFailed:!1}}finally{r.dispose()}}async function Bun(e,t,n,r,i){if(Ge&&!(!e||!t))try{if(Iun(i))return;hun(n);let a=e.getElements();if(a.some(e=>e.animationIds.includes(t))||e.getAllAnimationIds().has(t))return;let o=a.length,s=!1,c=!1;if(r){let e=await zun(t,(async()=>r())());if(e.staleSession)return;s=e.diskChecked,c=e.sourceReadFailed}mG(`sdk_resolver_shadow`,{animationId:t,opLabel:n,sessionElementCount:o,...s?{diskChecked:!0}:{},...c?{sourceReadFailed:!0}:{},mismatchCount:1,mismatches:JSON.stringify([{kind:`animation_not_found`,animationId:t}])})}catch{}}var Vun=new Set(`id.class.style.title.name.for.type.lang.dir.translate.hidden.tabindex.draggable.contenteditable.role.slot.href.target.rel.src.srcset.sizes.alt.poster.loading.decoding.crossorigin.preload.autoplay.loop.muted.controls.playsinline.width.height.colspan.rowspan.scope.placeholder.value.min.max.step.pattern.required.disabled.readonly.checked.selected.multiple.accept.maxlength.minlength.rows.cols.wrap`.split(`.`)),Hun=new Set([`src`,`href`,`action`,`formaction`,`poster`,`srcset`,`xlink:href`]),Uun=/^(?:javascript|vbscript):/i,Wun=/^data\s*:\s*text\/html/i;function Gun(e){let t=e.toLowerCase();return!t.startsWith(`on`)&&!!(Vun.has(t)||t.startsWith(`data-`)||t.startsWith(`aria-`))}function Kun(e,t){if(Hun.has(e.toLowerCase())){let e=t.trim();if(Uun.test(e)||Wun.test(e))return!1}return!0}var qun=new Set([`inline-style`,`text-content`,`attribute`,`html-attribute`]),Jun=new Set([`data-hf-id`,`data-composition-id`,`data-width`,`data-height`,`data-start`,`data-end`,`data-track-index`,`data-hold-start`,`data-hold-end`,`data-hold-fill`]);function Yun(e){return e.type===`attribute`?e.property.startsWith(`data-`)?e.property:`data-${e.property}`:e.type===`html-attribute`?e.property:null}function Xun(e){let t=Yun(e);return t!==null&&Jun.has(t.toLowerCase())}function Zun(e){return e.some(e=>e.type===`html-attribute`&&(!Gun(e.property)||e.value!==null&&!Kun(e.property,e.value)))}function Qun(e){return e.some(e=>e.childSelector!==void 0)}function $un(e){return e.some(e=>e.type===`text-content`)}function edn(e){if(!e||typeof e!=`object`||!(`children`in e))return null;let t=e.children;return Array.isArray(t)?t:null}function tdn(e){if(!e||typeof e!=`object`||!(`tag`in e))return null;let t=e.tag;return typeof t==`string`?t.toLowerCase():null}var ndn=new Set([`svg`,`math`]);function rdn(e,t){if(!$un(t))return!1;let n=edn(e);if(!n)return!1;if(n.length>1)return!0;let r=tdn(n[0]);return r!==null&&ndn.has(r)}function A6(e,t){try{return O6(e,t)!==null}catch{return!1}}function idn(e,t){return e?t.length===0?`no_ops`:t.every(e=>qun.has(e.type))?Qun(t)?`child_scoped_op`:t.some(Xun)?`reserved_attribute`:Zun(t)?`unsafe_html_attribute`:null:`unsupported_op_type`:`target_unaddressable`}var adn=2e3,j6=new Map;function odn(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16)}function sdn(e,t){return e.filter(e=>t-e.at<adn)}function cdn(e,t,n=Date.now()){let r=sdn(j6.get(e)??[],n);r.push({hash:odn(t),at:n}),j6.set(e,r)}function ldn(e,t,n=Date.now()){let r=sdn(j6.get(e)??[],n),i=odn(t),a=r.findIndex(e=>e.hash===i);return a===-1?(j6.set(e,r),!1):(r.splice(a,1),j6.set(e,r),!0)}function M6(e,t,n){return mG(`sdk_cutover_declined`,{reason:e,family:t??null,...n?{resolverDisagreement:!0}:{}}),{status:`declined`,reason:e}}function N6(e){return e instanceof Error?e:Error(String(e))}var udn=/Failed to fetch|Load failed|NetworkError when attempting to fetch/;function ddn(e){return e instanceof YY?`network`:e instanceof XY?`conflict`:e instanceof JY?`http`:e.name===`TypeError`&&udn.test(e.message)?`network`:`sdk`}function P6(e,t,n={}){let r=N6(e);return mG(`sdk_cutover_failed`,{...n,family:t,error_kind:ddn(r),...r instanceof JY?{status:r.statusCode}:{},error:r.message}),{status:`failed`,error:r}}function F6(e){if(e.status===`failed`)throw e.error;return e.status===`committed`}async function fdn(e,t,n){return e.readProjectFile?e.readProjectFile(t):n}function pdn(e,t){e&&e!==t&&e.dispose()}function mdn(e,t,n){return n.createCandidateSession?n.createCandidateSession(e,t):Qj(e,{history:!1})}function hdn(e,t,n){return e===t||n.publishSession!==void 0}async function gdn(e,t,n,r){let i;try{let a=r??e.serialize();i=await mdn(a,e,t),i.batch(()=>n(i));let o=i.serialize();return o===a?(pdn(i,e),M6(`no_change`)):hdn(i,e,t)?{live:e,candidate:i,serializedBefore:a,after:o}:(pdn(i,e),{status:`failed`,error:Error(`SDK candidate publisher is unavailable`)})}catch(t){return pdn(i,e),{status:`failed`,error:N6(t)}}}function _dn(e){return`status`in e}async function vdn(e,t,n,r,i){try{return cdn(e,t),await r.writeProjectFile(e,t,n),i}catch(t){return AggregateError([i,N6(t)],`SDK edit failed and rollback could not restore ${e}`)}}async function ydn(e,t,n,r,i){cdn(t,e);try{await r.writeProjectFile(t,e,n)}catch(e){return N6(e)}try{return await r.editHistory.recordEdit({label:i?.label??`Edit layer`,...i?.coalesceKey?{coalesceKey:i.coalesceKey}:{},...i?.coalesceMs==null?{}:{coalesceMs:i.coalesceMs},files:{[t]:{before:n,after:e}}}),null}catch(i){return vdn(t,n,e,r,N6(i))}}function bdn(e,t,n){try{t.refresh?t.refresh(e):n?.skipRefresh||t.reloadPreview()}catch(e){mG(`sdk_cutover_refresh_failed`,{error:N6(e).message})}}async function xdn(e,t,n,r,i){let a=await ydn(e.after,t,n,r,i);if(a)return e.candidate!==e.live&&e.candidate.dispose(),{status:`failed`,error:a};let o=!0;try{if(e.candidate!==e.live){let n=r.publishSession({candidate:e.candidate,expectedSession:e.live,targetPath:t});n!==`published`&&e.candidate.dispose(),n===`rejected-inactive-target`&&(o=!1)}}catch(e){mG(`sdk_cutover_publish_failed`,{path:t,error:N6(e).message})}return o&&bdn(e.after,r,i),{status:`committed`,version:odn(e.after),before:n,after:e.after}}async function I6(e,t,n,r,i,a,o){return jZ(r.writeProjectFile,t,async()=>{let s=o??n,c;try{c=await fdn(r,t,s)}catch(e){return{status:`failed`,error:N6(e)}}let l=await gdn(e,r,i,r.readProjectFile?c:o);return _dn(l)?l:xdn(l,t,c,r,a)})}async function Sdn(e,t,n,r,i){await jZ(r.writeProjectFile,t,async()=>{let a=await fdn(r,t,n),o=await e(a);if(o===a)return;let s=await ydn(o,t,a,r,i);if(s)throw s;bdn(o,r,i)})}function L6(e){let t=Object.prototype.hasOwnProperty.call(_,`STUDIO_SDK_CUTOVER_FAMILIES`)?ht:void 0;return rn(Vt,t,e)}function Cdn(e,t,n){e.status===`committed`?mG(`sdk_cutover_success`,{...n,family:t}):e.status===`failed`&&P6(e.error,t,n)}function R6(e,t){return e.compositionPath!=null&&t!==e.compositionPath}function wdn(e,t){let n=e.readProjectFile;return n?()=>n(t):void 0}async function Tdn(e,t,n,r,i,a,o){if(!L6(`dom`))return M6(`feature_disabled`,`dom`);if(!i)return M6(`session_unavailable`,`dom`);let s=e.hfId,c=idn(s,t);if(c||!s)return M6(c??`target_unaddressable`,`dom`);let l=i.getElement(s);if(!l)return M6(`target_not_found`,`dom`,A6(i,s));if(rdn(l,t))return M6(`unsupported_text_target`,`dom`);if(R6(a,r))return M6(`wrong_composition_file`,`dom`);let u=await I6(i,r,n,a,e=>{for(let n of mun(s,t))e.dispatch(n)},o);return Cdn(u,`dom`,{hfId:s,opCount:t.length}),u}async function Edn(e,t,n,r,i,a){let o=i.readProjectFile;if(k6(r,e,`setTiming`,o?()=>o(t):void 0,{targetPath:t,compositionPath:i.compositionPath}),!L6(`timing`))return M6(`feature_disabled`,`timing`);if(!r)return M6(`session_unavailable`,`timing`);if(!r.getElement(e))return M6(`target_not_found`,`timing`,A6(r,e));if(R6(i,t))return M6(`wrong_composition_file`,`timing`);try{let o=r.serialize(),s=await I6(r,t,o,i,t=>t.setTiming(e,n),a,o);return Cdn(s,`timing`,{hfId:e,opCount:1}),s}catch(t){return P6(t,`timing`,{hfId:e,opCount:1})}}async function Ddn(e,t,n,r,i){let a=r.readProjectFile;for(let i of e)k6(n,i.hfId,`setTiming`,a?()=>a(t):void 0,{targetPath:t,compositionPath:r.compositionPath});if(!L6(`timing`))return M6(`feature_disabled`,`timing`);if(!n)return M6(`session_unavailable`,`timing`);if(R6(r,t))return M6(`wrong_composition_file`,`timing`);let o=e.find(e=>!n.getElement(e.hfId));if(o)return M6(`target_not_found`,`timing`,A6(n,o.hfId));try{let a=n.serialize(),o=await I6(n,t,a,r,t=>{for(let n of e)t.setTiming(n.hfId,n.timingUpdate)},i,a);return o.status===`failed`?P6(o.error,`timing`,{hfId:e[0]?.hfId??null,opCount:e.length}):(mG(`sdk_cutover_success`,{hfId:e[0]?.hfId??null,opCount:e.length,family:`timing`}),o)}catch(t){return P6(t,`timing`,{hfId:e[0]?.hfId??null,opCount:e.length})}}function z6(e,t,n,r,i){if(t.kind===`add`){let i=r.readProjectFile;k6(n,t.target,`addGsapTween`,i?()=>i(e):void 0,{targetPath:e,compositionPath:r.compositionPath})}else Bun(n,t.animationId,t.kind===`set`?`setGsapTween`:`removeGsapTween`,wdn(r,e),{targetPath:e,compositionPath:r.compositionPath});return L6(`gsap-animation`)?t.kind===`add`&&n&&!n.getElement(t.target)?Promise.resolve(M6(`target_not_found`,`gsap-animation`)):B6(`gsap-animation`,e,n,r,i,e=>{e.batch(()=>{t.kind===`add`?e.addGsapTween(t.target,t.spec):t.kind===`set`?e.setGsapTween(t.animationId,t.properties):e.removeGsapTween(t.animationId)})}):Promise.resolve(M6(`feature_disabled`,`gsap-animation`))}async function B6(e,t,n,r,i,a,o){if(o&&Bun(n,o.animationId,o.opLabel,wdn(r,t),{targetPath:t,compositionPath:r.compositionPath}),!L6(e))return M6(`feature_disabled`,e);if(!n)return M6(`session_unavailable`,e);if(R6(r,t))return M6(`wrong_composition_file`,e);let s=n;try{let n=s.serialize(),o=await I6(s,t,n,r,a,i,n);if(o.status===`committed`)mG(`sdk_cutover_success`,{opCount:1,family:e});else if(o.status===`failed`)return P6(o.error,e,{opCount:1});return o}catch(t){return P6(t,e,{opCount:1})}}function Odn(e,t,n,r,i,a,o){return B6(`gsap-keyframe`,e,i,a,o,e=>e.batch(()=>e.dispatch({type:`addGsapKeyframe`,animationId:t,position:n,value:r})),{animationId:t,opLabel:`addGsapKeyframe`})}function kdn(e,t,n,r,i,a){return B6(`gsap-keyframe`,e,r,i,a,e=>e.dispatch({type:`removeGsapKeyframe`,animationId:t,percentage:n}),{animationId:t,opLabel:`removeGsapKeyframe`})}function Adn(e,t,n,r,i,a,o){return B6(`gsap-animation`,e,i,a,o,e=>e.dispatch({type:`removeGsapProperty`,animationId:t,property:n,from:r}),{animationId:t,opLabel:`removeGsapProperty`})}function jdn(e,t,n,r,i){return B6(`gsap-animation`,e,n,r,i,e=>e.dispatch({type:`deleteAllForSelector`,selector:t}))}function Mdn(e,t,n,r,i){return B6(`gsap-keyframe`,e,n,r,i,e=>e.dispatch({type:`removeAllKeyframes`,animationId:t}),{animationId:t,opLabel:`removeAllKeyframes`})}function Ndn(e,t,n,r,i,a){return B6(`gsap-keyframe`,e,r,i,a,e=>e.dispatch({type:`convertToKeyframes`,animationId:t,resolvedFromValues:n}),{animationId:t,opLabel:`convertToKeyframes`})}function Pdn(e,t,n,r,i){return{targetSelector:e,position:t,duration:n,keyframes:r,...i?{ease:i}:{}}}function Fdn(e,t,n){n===void 0?e.dispatch({type:`addWithKeyframes`,...t}):e.dispatch({type:`replaceWithKeyframes`,animationId:n,...t})}function Idn(e){let t=Pdn(e.targetSelector,e.position,e.duration,e.keyframes,e.ease);return B6(`gsap-keyframe`,e.targetPath,e.sdkSession,e.deps,e.options,n=>Fdn(n,t,e.animationId),e.animationId?{animationId:e.animationId,opLabel:`replaceWithKeyframes`}:void 0)}function Ldn(e,t,n,r,i,a,o,s,c){return Idn({targetPath:e,targetSelector:t,position:n,duration:r,keyframes:i,ease:a,sdkSession:o,deps:s,options:c})}function Rdn(e,t,n,r,i,a,o,s,c,l){return Idn({targetPath:e,animationId:t,targetSelector:n,position:r,duration:i,keyframes:a,ease:o,sdkSession:s,deps:c,options:l})}async function zdn(e,t,n,r,i){if(k6(r,e,`removeElement`,()=>Promise.resolve(t),{targetPath:n,compositionPath:i.compositionPath}),!L6(`lifecycle`))return M6(`feature_disabled`,`lifecycle`);if(!r)return M6(`session_unavailable`,`lifecycle`);if(!r.getElement(e))return M6(`target_not_found`,`lifecycle`,A6(r,e));if(R6(i,n))return M6(`wrong_composition_file`,`lifecycle`);let a=await I6(r,n,t,i,t=>t.removeElement(e),{label:`Delete element`});return Cdn(a,`lifecycle`,{hfId:e,opCount:1}),a}var Bdn=0;function Vdn(e,t){let n=e.map(e=>e.id??e.selector??e.element.getAttribute(`data-hf-id`)??`el`).join(`:`);return`z-reorder:${t??`reorder`}:${n}:g${Bdn++}`}function Hdn({activeCompPath:e,showToast:t,writeProjectFile:n,editHistory:r,projectIdRef:i,reloadPreview:a,clearDomSelection:o,onTrySdkDelete:s,onReorderShadow:c,forceReloadSdkSession:l,commitDomEditPatchBatches:u,onElementDeleted:d}){return{handleDomEditElementsDelete:(0,U.useCallback)(async c=>{let u=i.current;if(!u)return E6(`no-project`);let[f]=c;if(!f)return E6(`no-selection`);let p=c.length===1?f.label||f.id||f.selector||f.tagName:`${c.length} elements`;c.length>1&&t(`Deleting ${p}...`,`info`);let m=f.sourceFile||e||`index.html`,h=c.filter(t=>(t.sourceFile||e||`index.html`)===m);try{let e=h.map(e=>Wt(e));if(e.some(e=>!e.id&&!e.selector&&!e.hfId))throw Error(`Selected element has no patchable target`);let i=h.map(e=>e.hfId).filter(e=>!!e);if(s&&i.length===h.length){let e=await NZ(u,m),n=!0;for(let t of i)if(!F6(await s(t,e,m))){n=!1;break}if(n)return o(),X.getState().setSelectedElementId(null),t(`Deleted ${p}. Use Undo to restore ${h.length===1?`it`:`them`}.`,`info`),{ok:!0}}if(!await FZ({projectId:u,path:m,label:`Delete element`,writeFile:n,recordEdit:r.recordEdit,rewrite:async t=>{let n=await H(M(u,`/file-mutations/remove-elements/${encodeURIComponent(m)}`),{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:JSON.stringify({targets:e})});if(!n.ok)throw await iX(n,`Failed to delete element from ${m}`);let r=await n.json();return r.changed?{disk:typeof r.content==`string`?r.content:t}:null}}))return a(),t(`Nothing to delete, the preview was out of date. Try again.`),E6(`preview-stale`);o(),X.getState().setSelectedElementId(null),l?.(),a();for(let e of h)d?.(e);return t(`Deleted ${p}. Use Undo to restore ${h.length===1?`it`:`them`}.`,`info`),{ok:!0}}catch(e){return t(e instanceof Error?e.message:`Failed to delete element`),E6(`persist-failed`)}},[e,o,r.recordEdit,s,d,l,i,a,t,n]),handleDomZIndexReorderCommit:(0,U.useCallback)((e,t,n)=>e.length===0?Promise.resolve():(async()=>{let r=e.map(e=>eun(e.element));try{c?.(e.map(e=>se(e.element)).filter(e=>e!=null));let r=t??Vdn(e,n),i=new Map,a=[],o=[];for(let t of e){let e=t.element.style.zIndex,n=t.element.style.position,r=t.key?X.getState().elements.find(e=>(e.key??e.id)===t.key):void 0,s=!1,c=t.element.getAttribute(ie),l=nun(t.element);l&&o.push({element:t.element,ownership:l}),t.element.style.zIndex=String(t.zIndex);let u=[{type:`inline-style`,property:`z-index`,value:String(t.zIndex)}];try{let e=t.element.ownerDocument?.defaultView;(c??(e?e.getComputedStyle(t.element).position:void 0))===`static`&&(t.element.style.position=`relative`,s=!0,u.push({type:`inline-style`,property:`position`,value:`relative`}))}catch{}t.key&&X.getState().updateElement(t.key,{zIndex:t.zIndex,hasExplicitZIndex:!0}),a.push(()=>{l?iun(t.element,l):(t.element.style.zIndex=e,s&&(t.element.style.position=n)),t.key&&r&&X.getState().updateElement(t.key,{zIndex:r.zIndex,hasExplicitZIndex:r.hasExplicitZIndex})});let d=i.get(t.sourceFile)??[];d.push({target:Wt({id:t.id,hfId:se(t.element),selector:t.selector,selectorIndex:t.selectorIndex}),operations:u}),i.set(t.sourceFile,d)}let s=[...i].map(([e,t])=>({sourceFile:e,patches:t}));X.getState().bumpZEditVersion();let l=()=>{for(let e of a)e();X.getState().bumpZEditVersion()};try{let e=await u(s,{label:`Reorder layers`,coalesceKey:r,coalesceMs:1/0,skipReload:!0});if(!e.durable)return l(),e;for(let{element:e,ownership:t}of o)run(e,t);return e}catch(e){throw l(),e}}finally{for(let e of r)e()}})(),[u,c])}}var V6=e=>e.key??e.id;function Udn(e,t){if(e.expandedHostKey==null)return null;let n=V6(e);return new Set(t.filter(t=>V6(t)!==n&&PY(t,e)).map(e=>e.track))}function Wdn(e){let{action:t,element:n,elements:r}=e;if(MY(n)===`audio`||!(n.duration>0))return null;let i=V6(n),a=n.start,o=n.start+n.duration,s=t===`bring-forward`||t===`bring-to-front`,c=r.filter(e=>V6(e)!==i&&MY(e)===`visual`&&LY(e,n)&&hq(a,o,e.start,e.start+e.duration)),l=Ydn(e,c,s);if(l==null)return null;let u=v$(r),d=v$(r.filter(e=>MY(e)===`visual`)),f=d.indexOf(l);if(f===-1)return null;let p=Kdn(t,c,l,s),m=Udn(n,r),h=qdn({elements:r,visualLanes:d,refIdx:f,up:s,boundLane:p,start:a,end:o,selfKey:i,allowedLanes:m});return h==null?m?null:{kind:`insert`,insertRow:u.indexOf(l)+ +!s}:h===n.track?null:{kind:`move`,displayTrack:h,persistTrack:FY(h,r,n)}}function Gdn(e){let{element:t,elements:n,desiredOrderKeys:r}=e;if(MY(t)===`audio`||!(t.duration>0))return null;let i=V6(t),a=r.indexOf(i);if(a===-1)return null;let o=e=>{if(e==null)return null;let r=n.find(t=>V6(t)===e);return r&&MY(r)===`visual`&&r.duration>0&&LY(r,t)&&V6(r)!==i?r.track:null},s=null;for(let e=a+1;e<r.length&&s==null;e++)s=o(r[e]);let c=null;for(let e=a-1;e>=0&&c==null;e--)c=o(r[e]);if(s==null&&c==null)return null;let l=v$(n),u=v$(n.filter(e=>MY(e)===`visual`)),d=Udn(t,n),f={elements:n,visualLanes:u,start:t.start,end:t.start+t.duration,selfKey:i,allowedLanes:d},p,m;if(s!=null){let e=u.indexOf(s);if(e===-1)return null;p=qdn({...f,refIdx:e,up:!1,boundLane:c}),m=l.indexOf(s)+1}else{let e=u.indexOf(c);if(e===-1)return null;p=qdn({...f,refIdx:e,up:!0,boundLane:null}),m=l.indexOf(c)}return p==null?d?null:{kind:`insert`,insertRow:m}:p===t.track?null:{kind:`move`,displayTrack:p,persistTrack:FY(p,n,t)}}function Kdn(e,t,n,r){if(e!==`bring-forward`&&e!==`send-backward`)return null;let i=t.map(e=>e.track).filter(e=>r?e<n:e>n);return i.length===0?null:(r?Math.max:Math.min)(...i)}function qdn(e){let{elements:t,visualLanes:n,refIdx:r,up:i,boundLane:a,start:o,end:s,selfKey:c,allowedLanes:l}=e,u=i?-1:1;for(let e=r+u;e>=0&&e<n.length;e+=u){let r=n[e];if(Jdn(r,a,i))break;if(!(l&&!l.has(r))&&BBt(t,r,o,s,c))return r}return null}function Jdn(e,t,n){return t==null?!1:n?e<=t:e>=t}function Ydn(e,t,n){let r=e.action===`bring-forward`||e.action===`send-backward`;if(r){let t=Xdn(e);if(t!=null)return t}let i=t.map(e=>e.track).filter(t=>n?t<e.element.track:t>e.element.track);return i.length===0?null:(r===n?Math.max:Math.min)(...i)}function Xdn({elements:e,crossedKey:t}){if(t==null)return null;let n=e.find(e=>V6(e)===t);return n&&MY(n)===`visual`?n.track:null}function Zdn(){let e=$dn(),t=IX()?.activeCompPath??null;return(0,U.useCallback)(n=>e(n.selectionKey,n.coalesceKey,(e,r)=>{let i=n.crossed?ge(n.crossed):void 0,a=n.crossed?k({domId:n.crossed.id||void 0,selector:i,selectorIndex:ze(n.crossed.ownerDocument,n.crossed,i,n.sourceFile,t),sourceFile:n.sourceFile}):null;return Wdn({action:n.action,element:e,elements:r,crossedKey:a})}),[e,t])}function Qdn(){let e=$dn();return(0,U.useCallback)(t=>e(t.selectionKey,t.coalesceKey,(e,n)=>Gdn({element:e,elements:n,desiredOrderKeys:t.desiredOrderKeys})),[e])}function $dn(){let e=X(e=>e.elements),t=(0,U.useRef)(e);t.current=e;let{onMoveElements:n}=VX();return(0,U.useCallback)((e,r,i)=>{let a=t.current,o=e?a.find(t=>(t.key??t.id)===e):void 0;if(!o||!n)return Promise.resolve(!1);let s=i(o,a);return s?iqt(o,s,{elements:a,trackOrder:v$(a),updateElement:(e,t)=>X.getState().updateElement(e,t),onMoveElements:n},r):Promise.resolve(!1)},[n])}function efn(e,t,n){return!!(t||n||se(e))}function tfn(e,t){return{element:e.element,zIndex:t,id:e.id??void 0,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile,key:k({domId:e.id??void 0,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile})}}function nfn(e,t,n,r){let i=e.id||void 0,a=ge(e);if(!efn(e,i,a))return null;let o=i?void 0:ze(e.ownerDocument,e,a,n,r);return{element:e,zIndex:t,id:i,selector:a,selectorIndex:o,sourceFile:n,key:k({domId:i,selector:a,selectorIndex:o,sourceFile:n})}}function rfn(e){if(e.id)return`#${e.id}`;let t=e.classList.item(0);return t?`${e.tagName.toLowerCase()}.${t}`:e.tagName.toLowerCase()}function ifn(e,t,n){let r=[],i=[];for(let a of t){if(a.element===e.element){r.push(tfn(e,a.zIndex));continue}let t=nfn(a.element,a.zIndex,e.sourceFile,n);t?r.push(t):i.push(a)}return{entries:r,dropped:i}}var afn=e=>e.isConnected&&e.ownerDocument.defaultView!==null;function ofn(){let{handleDomZIndexReorderCommit:e}=kX(),t=Zdn(),n=V2(),r=IX()?.activeCompPath??null,i=(0,U.useCallback)((e,t)=>!n&&afn(e.element)&&PJt(e.element,t),[n]),a=(0,U.useCallback)((i,a,o,s)=>{if(n)return!1;let{entries:c,dropped:l}=ifn(i,a,r);if(l.length>0){for(let e of l)e.element.style.zIndex=String(e.zIndex);console.warn(`[studio] z-index reorder: dropping sibling(s) with no stable id/selector (will revert on reload):`,l.map(e=>rfn(e.element)).join(`, `))}if(c.length===0)return!1;let u=Vdn(c,o),d=!1;return _Kt({commitZ:async()=>{let t=await e(c,u,o);return d=t?.durable===!0&&t.changed,t},mirror:()=>t({selectionKey:c.find(e=>e.element===i.element)?.key,action:o,crossed:s,sourceFile:i.sourceFile,coalesceKey:u})}).then(()=>{d&&m4(`z_order`,`button`)}).catch(()=>void 0),!0},[r,e,t,n]),o=(0,U.useCallback)((e,t)=>{if(!afn(e.element))return!1;let n=FJt(e.element,t);return n!==null&&a(e,n.patches,t,n.crossed)},[a]);return(0,U.useMemo)(()=>({enabled:i,apply:o,commit:a}),[i,o,a])}function sfn({activeCompositionPath:e,showHoverSelection:t,shouldShowSelectedDomBounds:n,isGestureRecording:r,canvasInput:i,allowBodyDrag:a,onTextEditingChange:o,onSelectionBoxClick:s}){let{domEditHoverSelection:c,domEditSelection:l,domEditGroupSelections:u}=jX(),{previewIframeRef:d,handlePreviewCanvasMouseDown:f,handlePreviewCanvasPointerMove:p,handlePreviewCanvasPointerLeave:m,applyDomSelection:h,handleBlockedDomMove:g,handleDomManualDragStart:_,handleDomPathOffsetCommit:v,handleDomGroupPathOffsetCommit:y,handleDomBoxSizeCommit:b,handleDomRotationCommit:x,handleDomStyleCommit:S,applyMarqueeSelection:C,handleDomEditElementDelete:w}=kX(),T=ofn();return(0,W.jsx)(Xln,{iframeRef:d,activeCompositionPath:e,hoverSelection:t?c:null,selection:n?l:null,groupSelections:n?u:[],allowCanvasMovement:!r,canvasInput:i,allowBodyDrag:a,onTextEditingChange:o,onSelectionBoxClick:s,onCanvasMouseDown:f,onCanvasPointerMove:p,onCanvasPointerLeave:m,onSelectionChange:h,onBlockedMove:g,onManualDragStart:_,onPathOffsetCommit:v,onGroupPathOffsetCommit:y,onBoxSizeCommit:b,onRotationCommit:x,onStyleCommit:S,onDeleteSelection:w,onApplyZIndex:T.commit,onMarqueeSelect:C})}var H6=`:`,cfn=`#`;function U6(e){let t=t=>!e.sourceFile||!e.activeCompositionPath?t:e.projectId?[`v2`,encodeURIComponent(e.projectId),encodeURIComponent(e.activeCompositionPath),encodeURIComponent(e.sourceFile),encodeURIComponent(t)].join(H6):[`v1`,encodeURIComponent(e.activeCompositionPath),encodeURIComponent(e.sourceFile),encodeURIComponent(t)].join(H6);if(e.hfId)return`hf${H6}${t(e.hfId)}`;if(e.domId)return`dom${H6}${t(e.domId)}`;if(e.selector){let n=e.selectorIndex??0;return`sel${H6}${t(e.selector)}${cfn}${n}`}return null}function lfn(e,t=`index.html`,n){let r=t??`index.html`;return{projectId:n,hfId:e.hfId,domId:e.domId,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile??r,activeCompositionPath:r}}function W6(e,t,n){return{projectId:n,hfId:e.hfId,domId:e.id,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile,activeCompositionPath:t}}function ufn(e,t,n){let r=e.split(H6);return r[0]!==t||r.length!==n+1?null:r.slice(1).map(pfn)}function dfn(e){let[t,n,r]=ufn(e,`v1`,3)??[];return!t||!n||!r?null:{version:1,value:r,sourceFile:n,activeCompositionPath:t}}function ffn(e){let[t,n,r,i]=ufn(e,`v2`,4)??[];return!t||!n||!r||!i?null:{version:2,projectId:t,value:i,sourceFile:r,activeCompositionPath:n}}function G6(e){return e.startsWith(`v1${H6}`)?dfn(e):e.startsWith(`v2${H6}`)?ffn(e):{value:e,version:0}}function pfn(e){try{return decodeURIComponent(e)||null}catch{return null}}function mfn(e){let t=e.indexOf(H6);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);if(!r)return null;if(n===`hf`||n===`dom`){let e=G6(r);return e?{scheme:n,...e,index:0}:null}if(n!==`sel`)return null;let i=r.lastIndexOf(cfn);if(i<=0){let e=G6(r);return e?{scheme:n,...e,index:0}:null}let a=Number(r.slice(i+1));if(!Number.isInteger(a)||a<0){let e=G6(r);return e?{scheme:n,...e,index:0}:null}let o=G6(r.slice(0,i));return o?{scheme:n,...o,index:a}:null}function hfn(e,t){let n=mfn(t);return n?He(e,{hfId:n.scheme===`hf`?n.value:void 0,id:n.scheme===`dom`?n.value:void 0,selector:n.scheme===`sel`?n.value:void 0,selectorIndex:n.scheme===`sel`?n.index:void 0,sourceFile:n.sourceFile},n.activeCompositionPath??null):null}function gfn(e,t){let n=mfn(e);return n?n.version!==2||!!t&&n.projectId===t:!1}async function _fn(e,t,n){let r=!1;for(let i=0;i<2;i+=1){let i=e();if(!i)return{status:`preview-unavailable`};let a=hfn(i,t);if(!a)return{status:r?`changed`:`not-found`};let o=await n(a);if(e()!==i||a.ownerDocument!==i||!a.isConnected||o!==null&&(o.element.ownerDocument!==i||!o.element.isConnected)){r=!0;continue}return o?{status:`ready`,selection:o}:{status:`unsupported`}}return{status:`changed`}}function K6(e){return{ok:!0,...e}}function q6(e,t,n){return n?{ok:!1,kind:e,reason:t,hint:n}:{ok:!1,kind:e,reason:t}}async function J6(e,t){try{return await t()}catch(t){let n=t instanceof Error?t.message:String(t);return t instanceof TypeError||t instanceof ReferenceError?(console.error(`[hf-webmcp] ${e} threw`,t),q6(`internal`,n)):q6(`failed`,n)}}var Y6="Read `stage` as the proof level: refused, dispatched, saved, verified, or failed. `changed` is separate, and evidence explains what was actually proven.",X6=new class{state={phase:`idle`};listeners=new Set;lastTerminalTarget=null;activeProjectId=null;callSequence=0;getSnapshot=()=>this.state;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));begin(e,t,n){this.activateProject(e);let r=`studio-edit-${++this.callSequence}`,i=this.lastTerminalTarget,a=i===null||i.projectId!==e||i.handle!==t.handle;return this.publish({callId:r,projectId:e,target:t,operation:n,targetChanged:a,phase:`dispatching`}),r}finish(e,t){this.state.phase!==`idle`&&this.state.callId===e&&(this.lastTerminalTarget={projectId:this.state.projectId,handle:this.state.target.handle},this.publish({...this.state,phase:t.ok?t.stage:`failed`,receipt:t}))}dismiss(e){this.state.phase!==`idle`&&this.state.callId===e&&this.publish({phase:`idle`})}reset(){this.activeProjectId=null,this.lastTerminalTarget=null,this.publish({phase:`idle`})}activateProject(e){this.activeProjectId!==e&&(this.activeProjectId=e,this.lastTerminalTarget=null,this.publish({phase:`idle`}))}publish(e){this.state=e;for(let e of this.listeners)e()}};async function vfn(e,t){let n=await _fn(e.getPreviewDocument,t,e.buildSelection);return n.status===`preview-unavailable`?{ok:!1,failure:q6(`blocked`,`the composition preview is not ready`)}:n.status===`not-found`?{ok:!1,failure:q6(`invalid`,`the target handle is stale`,`Call studio_look and retry.`)}:n.status===`unsupported`?{ok:!1,failure:q6(`blocked`,`the target resolved to an element Studio cannot edit`,`Try a parent or child element from studio_look.`)}:n.status===`changed`?{ok:!1,failure:q6(`invalid`,`the target changed while it was resolving`,`Call studio_look again.`)}:{ok:!0,selection:n.selection}}function Z6(e,t,n=!1){return{...t,stage:`refused`,operation:e,...n?{cancelRequested:!0}:{}}}function yfn(e,t,n,r){let i=r?{cancelRequested:!0}:{};return e.ok?{...e,target:t,operation:n,...i}:{...wfn(e),stage:`failed`,target:t,operation:n,...i}}function bfn(e){return{kind:e instanceof TypeError||e instanceof ReferenceError?`internal`:`failed`,reason:e instanceof Error?e.message:String(e)}}function xfn(e,t,n){let r=mfn(e);return!r||r.version!==2||!r.projectId?Z6(n,q6(`invalid`,`writes require a current project-scoped handle from studio_look`,`Call studio_look again and pass the returned handle unchanged.`)):r.projectId===t?null:Z6(n,q6(`invalid`,`the handle belongs to a different project`,`Call studio_look in the active project.`))}function Sfn(e,t){if(t.signal.aborted)return{ok:!1,result:Z6(t.operation,q6(`blocked`,`the write was cancelled before dispatch`),!0)};if(typeof t.handle!=`string`||!t.handle)return{ok:!1,result:Z6(t.operation,q6(`invalid`,`handle must name an element from studio_look`))};let n=e.getProjectId();if(!n)return{ok:!1,result:Z6(t.operation,q6(`blocked`,`there is no active project`))};let r=xfn(t.handle,n,t.operation);if(r)return{ok:!1,result:r};let i=e.getWriteBlockedReason();return i?{ok:!1,result:Z6(t.operation,q6(`blocked`,i,`Resolve it in Studio, then retry.`))}:{ok:!0,handle:t.handle,projectId:n}}async function Cfn(e,t,n){let r=await vfn(e,n);if(!r.ok)return{ok:!1,result:Z6(t.operation,r.failure)};let{selection:i}=r;if(i.isInsideLockedComposition)return{ok:!1,result:Z6(t.operation,q6(`blocked`,`the target is inside a locked composition`))};let a=await t.preflight?.(i);return a?{ok:!1,result:Z6(t.operation,a)}:t.signal.aborted?{ok:!1,result:Z6(t.operation,q6(`blocked`,`the write was cancelled before dispatch`),!0)}:{ok:!0,selection:i}}async function Q6(e,t){let n=Sfn(e,t);if(!n.ok)return n.result;let r;try{r=await Cfn(e,t,n.handle)}catch(e){let{kind:n,reason:r}=bfn(e);return n===`internal`&&console.error(`[hf-webmcp] ${t.operation} preflight threw`,e),Z6(t.operation,q6(n,r))}if(!r.ok)return r.result;if(e.getProjectId()!==n.projectId)return Z6(t.operation,q6(`blocked`,`the active project changed while the target was resolving`,`Call studio_look in the active project and retry.`));let{selection:i}=r,a={handle:n.handle,sourceFile:i.sourceFile};e.applySelection(i);let o=X6.begin(n.projectId,a,t.operation),s;try{s=await t.write(i)}catch(e){let{kind:n,reason:r}=bfn(e);n===`internal`&&console.error(`[hf-webmcp] ${t.operation} threw`,e);let i={ok:!1,kind:n,reason:r,stage:`failed`,target:a,operation:t.operation,...t.signal.aborted?{cancelRequested:!0}:{}};return X6.finish(o,i),i}let c=yfn(s,a,t.operation,t.signal.aborted);return X6.finish(o,c),c}function wfn(e){let t=e.kind===`invalid`||e.kind===`blocked`?`failed`:e.kind;return{...e,kind:t}}function $6(e,t){return{ok:!0,...e,stage:`dispatched`,changed:t,evidence:{kind:`dispatch`,followUp:`studio_inspect`}}}function Tfn(e,t){return{ok:!0,...e,stage:`saved`,changed:t.changed,evidence:{kind:`content-version`,sourceFile:t.sourceFile,version:t.version}}}function Efn(e,t,n){return{ok:!0,...e,stage:`verified`,changed:t.changed,evidence:{kind:`readback`,sourceFile:t.sourceFile,version:t.version,...n}}}function Dfn(e){return e.replace(/^https?:\/\/[^/]+/,``).replace(/^\/api\/projects\/[^/]+\/preview\//,``)}function Ofn(e){return{id:e.domId??e.id,label:e.label??null,kind:e.kind??e.tag.toLowerCase(),start:e.start,duration:e.duration,end:e.start+e.duration,trackIndex:e.authoredTrack??e.track,src:e.src?Dfn(e.src):null,sourceFile:e.sourceFile??null,volume:e.volume??null,lanes:EY(e).map(e=>({target:e.target,points:e.points.map(({t:e,v:t})=>({t:e,v:t}))})),playbackRate:e.playbackRate===1?null:e.playbackRate??null,audioGroup:e.audioGroup??null,role:e.timelineRole??null}}function kfn(e){return e.map(Ofn).sort(jje)}var Afn=200;function jfn(e){let t=kfn(e);if(t.length===0)return``;let n=t.slice(0,Afn).map(Ije),r=t.length-n.length;return[`Timeline (composition seconds; lane points are seconds from the clip start):`,...n,...r>0?[`(${r} more clips not listed)`]:[]].join(`
332
+ `&&(o=s,a+=1),e.slice(0,o)+e.slice(a)}function d1(e,t,n){let r=DZ(e,t)?.tag??``;return RegExp(`\\s${n}(?=[\\s=/>]|$)`,`i`).test(r)}function m8t(e,t){let{target:n}=t;if(!DZ(e,n))return null;let r=u8t(e),i=X6t(`${t.videoId||`video`}-audio`,new Set(t$(e))),a=[],o=[l8t(`muted`,`true`),l1(`has-audio`,null)];for(let t of t1){let r=OZ(e,n,t);r!==void 0&&(a.push([t,r]),o.push(l1(t,null)))}let c=OZ(e,n,s);if(c!==void 0){let{videoKeeps:e,audioTakes:t}=$6t(c);a.push([s,t]),o.push(l1(s,e))}o.push(l1(o1,r),l1(c1,r));let l=[];for(let t of G6t){let r=OZ(e,n,t);r!==void 0&&l.push([`data-${t}`,r])}let u=[[`id`,i],[`data-hf-id`,`hf-${nG()}`],[`class`,`clip`],[`src`,a1(e,n)],...l,[`data-track-index`,String(t.track)],[ZC,r],[tw,r],...a];return d1(e,n,`loop`)&&u.push([`loop`,``]),d1(e,n,s1)&&u.push([s1,``]),{html:u1(t8t(e,n,`<audio ${e8t(u)}></audio>`),n,o),audioId:i,linkId:r}}function h8t(e,t){let{videoTarget:n,audioTarget:r}=t;if(!DZ(e,n)||!DZ(e,r))return null;let i=t=>Eq({src:a1(e,t)}),a=i(n);if(!a||a!==i(r))return null;let o=t=>d1(e,t,s1);if(o(n)!==o(r))return null;let c=[];for(let t of t1){let n=OZ(e,r,t);c.push(l1(t,n??null))}let l=OZ(e,r,s);return l!==void 0&&c.push(l1(s,l)),c.push(l8t(`muted`,null),l1(o1,null),l1(c1,null),l1(`has-audio`,`true`)),u1(p8t(e,r),n,c)}var f1=e=>e.tag.trim().toLowerCase(),g8t=e=>e.key??e.id,p1=(e,t)=>Math.abs(e-t)<=c8t;function _8t(e,t){return p1(e.start,t.start)&&p1(e.duration,t.duration)&&p1(e.playbackStart??0,t.playbackStart??0)&&p1(e.playbackRate??1,t.playbackRate??1)}var v8t=(e,t)=>{let n=Eq(e);return n!==null&&n===Eq(t)&&zK(e,t)};function y8t(e){return f1(e)===`video`&&e.muted!==!0&&e.hasAudio===!0}function b8t(e,t){let n=f1(e)===`video`;if(!n&&f1(e)!==`audio`)return null;let r=n?`audio`:`video`,i=t.filter(t=>g8t(t)!==g8t(e)&&f1(t)===r&&v8t(t,e)),a=i.find(t=>Oq(t,e))??i.find(t=>_8t(t,e));if(!a)return null;let o=n?e:a,s=n?a:e;return o.hidden===!0==(s.hidden===!0)&&o.muted===!0?{video:o,audio:s}:null}function x8t(e){if(e.length!==2)return!1;let[t,n]=e;if(!t||!n||t.link||n.link)return!1;let r=new Set([f1(t),f1(n)]);return r.has(`video`)&&r.has(`audio`)&&zK(t,n)}function S8t(e){let[t,n]=e;return e.length===2&&!!t&&!!n&&v8t(t,n)}function C8t(e,t){let n=e=>({start:e.start,mediaStart:e.playbackStart??0,playbackRate:e.playbackRate??1}),[r,i]=[n(e),n(t)];return p1(r.playbackRate,i.playbackRate)&&p1(rw(r),rw(i))}function w8t(e,t){let n=e=>e.authoredTrack??e.track,r=e.filter(e=>f1(e)!==`audio`).map(n),i=Math.max(-1,...r)+1,a=t.start+t.duration,o=e.map(n),s=Math.max(i-1,...o)+1;for(let r=i;r<s;r+=1)if(e.filter(e=>n(e)===r).every(e=>f1(e)===`audio`&&(e.start>=a||e.start+e.duration<=t.start)))return r;return s}var m1=e=>e.key??e.id,h1=e=>e.tag.trim().toLowerCase();function T8t(e,t){let n={video:`audio`,audio:`video`}[h1(e)];if(!n||e.link)return null;let r=t.filter(t=>!t.link&&h1(t)===n&&t.track!==e.track&&S8t([e,t]));return r.length===1?r[0]??null:null}function g1(e,t){let n=t.filter(t=>m1(t)!==m1(e)),[r]=n;return n.length!==1||!r?``:[h1(e),h1(r)].sort().join(`+`)===`audio+video`?` ${h1(r)}`:``}function E8t(e,t,n,r,i){let a=x8t(n)&&r.has(m1(e)),o=n.every(t=>m1(t)===m1(e)),s=!a&&o?T8t(e,t):null,c=a?n:s?[e,s]:null;if(!c)return null;let l=g1(e,c);return{label:`Link${l&&` to${l}`}`,...a?{shortcut:`⌘L`}:{},run:()=>i({kind:`link`,elements:c})}}function D8t(e){let{element:t,elements:n,selectedKeys:r,onLinkEdit:i,onDeleteElementOnly:a}=e,o=[];if(!i)return o;let s=kq(t,n),c=s.length>1;y8t(t)&&o.push({label:`Detach audio`,shortcut:`⌥⇧D`,run:()=>i({kind:`detach`,element:t})});let l=n.filter(e=>r.has(m1(e)));if(c)o.push({label:`Unlink${g1(t,s)&&` from${g1(t,s)}`}`,shortcut:`⌘L`,run:()=>i({kind:`unlink`,elements:s})});else{let e=E8t(t,n,l,r,i);e&&o.push(e)}let u=b8t(t,n);return u&&o.push({label:`Merge audio back into video`,disabledReason:C8t(u.video,u.audio)?void 0:`Move into Sync first`,run:()=>i({kind:`merge`,...u})}),c&&a&&o.push({label:`Delete this clip only`,shortcut:`⌥⌫`,destructive:!0,run:()=>a(t)}),o}function O8t({part:e,element:t,onClose:n}){let{onLinkEdit:r,onDeleteElementOnly:i}=VX(),a=D8t({element:t,elements:X(e=>e.elements),selectedKeys:X(e=>e.selectedElementIds),onLinkEdit:r,onDeleteElementOnly:i}).filter(t=>t.destructive===!0==(e===`delete`));return a.length===0?null:(0,W.jsx)(W.Fragment,{children:a.map(e=>(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,disabled:e.disabledReason!==void 0,title:e.disabledReason,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-left outline-hidden ${e.disabledReason===void 0?`cursor-pointer hover:bg-neutral-800 focus-visible:bg-neutral-800 ${e.destructive?`text-red-400`:`text-neutral-300`}`:`text-neutral-600 cursor-not-allowed`}`,onClick:()=>{e.run(),n()},children:[(0,W.jsx)(`span`,{children:e.label}),e.shortcut&&(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:e.shortcut})]},e.label))})}var k8t=8;function A8t(e,t){let[n,r]=(0,U.useState)(0);return(0,U.useLayoutEffect)(()=>{let t=e.current;if(!t||(r(t.offsetHeight),typeof ResizeObserver>`u`))return;let n=new ResizeObserver(()=>r(t.offsetHeight));return n.observe(t),()=>n.disconnect()},[e,t]),n}var _1=e=>`${wQ.row} flex items-center justify-between ${e?wQ.rowEnabled:wQ.rowDisabled}`;function j8t({items:e,onClose:t}){return(0,W.jsx)(W.Fragment,{children:e.map(e=>(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!e.disabled),disabled:e.disabled,onClick:()=>{t(),e.onSelect()},children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-2`,children:[e.icon,e.label]}),e.shortcut&&(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:e.shortcut})]},e.id))})}var M8t=(0,U.memo)(function({x:e,y:t,element:n,currentTime:r,onClose:i,onSplit:a,onDelete:o,onCopy:s,onPaste:c,onDuplicate:l,canPaste:u,hostItems:d=[],splitShortcut:f=SG}){let p=yG(i);CQ(p);let m=VX().clipMenuTools!==!1,h=X(e=>{let t=n.key??n.id;return e.selectedElementIds.size>1&&e.selectedElementIds.has(t)?e.selectedElementIds.size:1}),g=kQ(n)&&[`video`,`audio`,`img`].includes(n.tag),_=g&&r>n.start&&r<n.start+n.duration,v=g?_?`Split at ${r.toFixed(2)}s`:`Split (move playhead inside clip)`:null,y=e+200>window.innerWidth?e-200:e,b=t+A8t(p,`${e},${t},${n.key??n.id}`)-window.innerHeight,x=b>0?Math.max(k8t,t-b-k8t):t;return(0,pm.createPortal)((0,W.jsxs)(`div`,{ref:p,role:`menu`,"aria-label":`Clip actions`,className:`${wQ.panel} fixed z-200 min-w-[180px]`,style:{left:y,top:x},children:[d.length>0&&(0,W.jsx)(`div`,{role:`group`,"aria-label":`Host`,className:wQ.group,children:(0,W.jsx)(j8t,{items:d,onClose:i})}),(0,W.jsxs)(`div`,{role:`group`,"aria-label":`Time`,className:wQ.group,children:[v&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-left outline-hidden focus-visible:bg-neutral-800 ${_?`text-neutral-300 hover:bg-neutral-800 cursor-pointer`:`text-neutral-600 cursor-not-allowed`}`,disabled:!_,onClick:()=>{_&&(a(n,r),i())},children:[(0,W.jsx)(`span`,{children:v}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:f})]}),m&&v&&(0,W.jsx)(K$,{group:`time`,element:n,currentTime:r,onClose:i})]}),(0,W.jsx)(`div`,{role:`group`,"aria-label":`Sound`,className:wQ.group,children:m&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(j6t,{part:`gain`,element:n,onClose:i}),(0,W.jsx)(K$,{group:`sound`,element:n,currentTime:r,onClose:i}),(0,W.jsx)(O8t,{part:`link`,element:n,onClose:i}),(0,W.jsx)(j6t,{part:`duck`,element:n,onClose:i})]})}),(0,W.jsx)(`div`,{role:`group`,"aria-label":`Picture`,className:wQ.group,children:m&&(0,W.jsx)(K$,{group:`picture`,element:n,currentTime:r,onClose:i})}),(0,W.jsxs)(`div`,{role:`group`,"aria-label":`Clipboard`,className:wQ.group,children:[s&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!0),onClick:()=>{s(),i()},children:[(0,W.jsx)(`span`,{children:h>1?`Copy ${h} clips`:`Copy`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌘C`})]}),c&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!!u),disabled:!u,onClick:()=>{u&&(c(),i())},children:[(0,W.jsx)(`span`,{children:`Paste`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌘V`})]}),l&&(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:_1(!0),onClick:()=>{l(),i()},children:[(0,W.jsx)(`span`,{children:h>1?`Duplicate ${h} clips`:`Duplicate`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌘D`})]})]}),(0,W.jsxs)(`div`,{role:`group`,"aria-label":`Delete`,children:[(0,W.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-danger-ink hover:bg-neutral-800 focus-visible:bg-neutral-800 outline-hidden cursor-pointer text-left`,onClick:()=>{o(n),i()},children:[(0,W.jsx)(`span`,{children:`Delete`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌫`})]}),m&&(0,W.jsx)(O8t,{part:`delete`,element:n,onClose:i})]})]}),document.body)}),N8t=(0,U.memo)(function({x:e,y:t,gapWidth:n,canCloseGap:r,canCloseAllGaps:i,hasAnyGaps:a,onClose:o,onCloseGap:s,onCloseAllGaps:c,onHoverAction:l}){let u=yG(o),d=t+68-window.innerHeight,f=e+200>window.innerWidth?e-200:e,p=d>0?t-d-8:t,m=e=>`${wQ.row} flex items-center justify-between ${e?wQ.rowEnabled:wQ.rowDisabled}`,h=r?void 0:n==null?`No gap here`:`A clip on this track can't be moved`,g=i?void 0:a?`A clip on this track can't be moved`:`No gaps on this track`;return(0,pm.createPortal)((0,W.jsxs)(`div`,{ref:u,className:`${wQ.panel} fixed z-200 min-w-[180px]`,style:{left:f,top:p},onPointerLeave:()=>l(null),children:[(0,W.jsxs)(`button`,{type:`button`,className:m(r),disabled:!r,title:h,onPointerEnter:()=>l(r?`close-gap`:null),onClick:()=>{r&&(s(),o())},children:[(0,W.jsx)(`span`,{children:`Close gap`}),n!=null&&(0,W.jsxs)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:[n.toFixed(2),`s`]})]}),(0,W.jsx)(`button`,{type:`button`,className:m(i),disabled:!i,title:g,onPointerEnter:()=>l(i?`close-all`:null),onClick:()=>{i&&(c(),o())},children:(0,W.jsx)(`span`,{children:`Close all gaps`})})]}),document.body)});function P8t({theme:e}){return(0,W.jsx)(`div`,{className:`absolute bottom-2 right-3 pointer-events-none z-20`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-md border`,style:{background:`var(--timeline-shortcut-bg)`,borderColor:e.gutterBorder},children:[(0,W.jsx)(`kbd`,{className:`text-[9px] font-mono px-1 py-0.5 rounded-sm`,style:{color:e.textSecondary,background:`var(--timeline-tick-minor)`},children:`Shift`}),(0,W.jsx)(`span`,{className:`text-[9px]`,style:{color:e.textSecondary},children:`+ drag/click to edit range`})]})})}function v1({capturedElement:e,targetSessionEpoch:t,sessionEpoch:n,selectedElementId:r,elements:i}){let a=e.key??e.id;return t!==n||r!==a?null:i.find(e=>(e.key??e.id)===a)??null}function F8t(){let{state:e}=UX(),{showShortcutHint:t,showPopover:n,rangeSelection:r,theme:i}=e.overlays;return!t||n||r?null:(0,W.jsx)(P8t,{theme:i})}function I8t(){let{state:e}=UX(),{showPopover:t,rangeSelection:n,setShowPopover:r,setRangeSelection:i}=e.overlays;return!t||!n?null:(0,W.jsx)($3t,{rangeStart:n.start,rangeEnd:n.end,anchorX:n.anchorX,anchorY:n.anchorY,onClose:()=>{r(!1),i(null)}})}function L8t(){let{state:e,actions:t}=UX(),n=e.overlays,{kfContextMenu:r,setKfContextMenu:i}=n,{selectedElementId:a,sessionEpoch:o,keyframeCache:s}=e,c=r?.sessionEpoch,l=r?v1({capturedElement:r.element,targetSessionEpoch:c,sessionEpoch:o,selectedElementId:a,elements:n.elements}):null;if((0,U.useEffect)(()=>{r&&!l&&i(null)},[l,r,i]),!r||!l)return null;let u=()=>v1({capturedElement:l,targetSessionEpoch:c,sessionEpoch:o,selectedElementId:a,elements:n.elementsRef.current}),d=r;return(0,W.jsx)(t6t,{state:{...d,element:l},onClose:()=>i(null),onDelete:(...e)=>{u()&&n.onDeleteKeyframe?.(...e)},onDeleteAll:(e,t)=>{let r=u();r&&n.onDeleteAllKeyframes?.(r,t)},onMoveToPlayhead:n.onMoveKeyframeToPlayhead?(e,...t)=>{let r=u();r&&n.onMoveKeyframeToPlayhead?.(r,...t)}:void 0,onEditEase:d.animationId!==void 0&&d.tweenPercentage!==void 0?(e,n)=>{n.animationId!==void 0&&n.tweenPercentage!==void 0&&(t.setFocusedEaseSegment({animationId:n.animationId,collidingAnimationTargets:n.collidingAnimationTargets,tweenPercentage:n.tweenPercentage,elementId:e}),_Y({action:`open`}))}:void 0,onCopyProperties:(e,t)=>{let n=s.get(e)?.keyframes.find(e=>Math.abs(e.percentage-t.percentage)<.5);return n?U$(JSON.stringify(n.properties,null,2)):!1}})}function R8t(){let{state:e}=UX(),t=e.overlays,{clipContextMenu:n,setClipContextMenu:r}=t,{selectedElementId:i,sessionEpoch:a}=e,o=n?.sessionEpoch,s=n?v1({capturedElement:n.element,targetSessionEpoch:o,sessionEpoch:a,selectedElementId:i,elements:t.elements}):null;(0,U.useEffect)(()=>{n&&!s&&r(null)},[s,n,r]);let{clipMenuItems:c}=t,l=(0,U.useMemo)(()=>s?c?.(s):void 0,[c,s]);if(!n||!s)return null;let u=()=>v1({capturedElement:s,targetSessionEpoch:o,sessionEpoch:a,selectedElementId:i,elements:t.elementsRef.current}),d=n;return(0,W.jsx)(M8t,{x:d.x,y:d.y,element:s,currentTime:t.currentTime,onClose:()=>r(null),onSplit:(e,n)=>{let r=u();r&&t.onSplitElement?.(r,n)},onDelete:()=>{let e=u();e&&(t.pinZoomBeforeEdit(),t.onDeleteElement?.(e))},onCopy:t.onCopyClip,onPaste:t.onPasteClip,onDuplicate:t.onDuplicateClip,canPaste:t.canPasteClip?.()??!1,hostItems:l,splitShortcut:t.splitShortcut})}function z8t(){let{state:e}=UX(),t=e.overlays.gapContextMenu,n=e.overlays;return t?(0,W.jsx)(N8t,{x:t.x,y:t.y,gapWidth:t.gapWidth,canCloseGap:t.canCloseGap,canCloseAllGaps:t.canCloseAllGaps,hasAnyGaps:t.hasAnyGaps,onClose:n.onDismissGapContextMenu,onCloseGap:n.onCloseTrackGap,onCloseAllGaps:n.onCloseAllTrackGaps,onHoverAction:n.onHoverGapAction}):null}function B8t(){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(F8t,{}),(0,W.jsx)(I8t,{}),(0,W.jsx)(L8t,{}),(0,W.jsx)(R8t,{}),(0,W.jsx)(z8t,{}),(0,W.jsx)(q3t,{})]})}function V8t({isDragOver:e,onFileDrop:t,onDragOver:n,onDragLeave:r,onDrop:i}){return(0,W.jsxs)(`div`,{className:`h-full border-t bg-[var(--timeline-shell-bg)] flex flex-col select-none transition-colors duration-150 ${e?`border-studio-accent/50 bg-studio-accent/3`:`border-neutral-800/50`}`,onDragOver:n,onDragLeave:r,onDrop:i,children:[(0,W.jsx)(`div`,{className:`shrink-0 border-b border-neutral-800/40 flex items-end relative`,style:{height:JG,paddingLeft:GG},children:[0,10,20,30,40,50].map(e=>(0,W.jsxs)(`div`,{className:`flex flex-col items-center`,style:{position:`absolute`,left:GG+e*14},children:[(0,W.jsx)(`span`,{className:`text-[9px] text-neutral-600 font-mono tabular-nums leading-none mb-0.5`,children:`${Math.floor(e/60).toString().padStart(2,`0`)}:${(e%60).toString().padStart(2,`0`)}`}),(0,W.jsx)(`div`,{className:`w-px h-[5px] bg-neutral-700/40`})]},e))}),(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,W.jsx)(`div`,{className:`flex items-center gap-3 px-6 py-3 border border-dashed rounded-lg transition-colors duration-150 ${e?`border-studio-accent/60 bg-studio-accent/6`:`border-neutral-700/50`}`,children:e?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`text-accent-ink shrink-0`,children:[(0,W.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,W.jsx)(`polyline`,{points:`7 10 12 15 17 10`}),(0,W.jsx)(`line`,{x1:`12`,y1:`15`,x2:`12`,y2:`3`})]}),(0,W.jsx)(`span`,{className:`text-[13px] text-accent-ink`,children:`Drop media files to import`})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`text-neutral-600 shrink-0`,children:[(0,W.jsx)(`rect`,{x:`2`,y:`2`,width:`20`,height:`20`,rx:`2`}),(0,W.jsx)(`path`,{d:`M7 2v20`}),(0,W.jsx)(`path`,{d:`M17 2v20`}),(0,W.jsx)(`path`,{d:`M2 7h20`}),(0,W.jsx)(`path`,{d:`M2 17h20`})]}),(0,W.jsx)(`span`,{className:`text-[13px] text-neutral-500`,children:t?`Drop media here or describe your video to start`:`Describe your video to start creating`})]})})})]})}function H8t(){return(0,W.jsx)(d3t,{})}var U8t=QYt;function W8t(){let{state:e,actions:t}=UX(),n=e.canvas;return(0,W.jsx)(c3t,{...n,renderClipContent:t.renderClipContent,renderClipOverlay:t.renderClipOverlay})}function G8t(){let{state:e}=UX(),t=e.canvas;return(0,W.jsx)(eXt,{scrubbing:t.isScrubbing})}function K8t(){let{meta:e}=UX();return e.razorGuide}function q8t(){let{meta:e}=UX();return(0,W.jsx)(V8t,{...e.emptyState})}function J8t(){return(0,W.jsx)(F8t,{})}function Y8t(){return(0,W.jsx)(I8t,{})}function X8t(){return(0,W.jsx)(R8t,{})}function Z8t(){return(0,W.jsx)(L8t,{})}function Q8t(){return(0,W.jsx)(z8t,{})}function $8t(){let{state:e,meta:t}=UX(),{timelineReady:n,elements:r}=e;return!n||r.length===0?(0,W.jsx)(q8t,{}):(0,W.jsxs)(`div`,{...t.containerProps,children:[(0,W.jsxs)(`div`,{...t.viewportProps,children:[(0,W.jsx)(H8t,{}),(0,W.jsx)(K8t,{})]}),(0,W.jsx)(B8t,{})]})}var e5t=(0,U.memo)(function(e={}){return(0,W.jsx)(GYt,{...e,children:(0,W.jsx)($8t,{})})}),t5t=Object.assign(e5t,{Provider:GYt,Frame:H8t,Ruler:U8t,Lanes:W8t,Playhead:G8t,RazorGuide:K8t,ShortcutHint:J8t,EditPopover:Y8t,ClipMenu:X8t,KeyframeMenu:Z8t,GapMenu:Q8t,EmptyState:q8t,Overlays:B8t}),n5t=.001;function r5t(e,t,n){let r=Math.max(0,Number.isFinite(e)?e:0),i=Math.max(0,Number.isFinite(t)?t:0),a=Math.max(1,Number.isFinite(n)?Math.floor(n):1);return a===1?[r+i/2]:[...Array.from({length:a},(e,t)=>r+i*t/a),r+Math.max(0,i-n5t)]}var y1=new Map,i5t=new Map,a5t=(e,t,n)=>n>=e.sourceStart&&t-n<=(t>=e.end?0:e.lead);function o5t(e,t,n){let r=y1.get(e)?.find(e=>a5t(n,t,e.decodedAt));return r&&(r.users+=1),r}function s5t(e,t,n){let r=y1.get(e)??[],i=r.find(e=>e.decodedAt===t);if(i)return i.users+=1,URL.revokeObjectURL(n),i;let a={url:n,decodedAt:t,users:1};return y1.set(e,[...r,a]),a}function c5t(e){for(let{key:t,frame:n}of e.splice(0)){if(--n.users>0)continue;let e=y1.get(t)?.filter(e=>e!==n)??[];e.length>0?y1.set(t,e):y1.delete(t),URL.revokeObjectURL(n.url)}}async function l5t(e){return e instanceof HTMLCanvasElement?new Promise((t,n)=>{e.toBlob(e=>e?t(e):n(Error(`Video thumbnail encode failed`)),`image/jpeg`,.72)}):e.convertToBlob({type:`image/jpeg`,quality:.72})}function b1(e){if(e.aborted)throw new DOMException(`Aborted`,`AbortError`)}function x1(e){e.urls.length=0,c5t(e.held);for(let t of e.canvases)t.width=0,t.height=0;e.canvases.clear()}function u5t(e,t){let n=Math.max(1,Math.min(t.posterMaxPhysicalWidth,Math.round(t.posterMaxPhysicalHeight*e)));return{width:n,height:Math.max(1,Math.min(t.posterMaxPhysicalHeight,Math.round(n/e)))}}function d5t(e,t,n){let r=Math.max(0,e.sourceStart??0),i=Math.max(0,t.metadataDuration??r+(e.sourceRangeDuration??0)),a=Math.min(r,i),o=e.sourceRangeDuration??Math.max(0,i-a),s=Math.min(Math.max(0,o),Math.max(0,i-a)),c=r5t(a,s,Math.min(e.frameCount,n.richPreviewFrameCount)),l=Math.max(1,c.length-1);return{window:{sourceStart:a,lead:s/Math.max(2,l)/2,end:c.length>1?c.at(-1):1/0},timestamps:c}}function f5t({timestamps:e,window:t},n,r){let i=[];return e.forEach((e,a)=>{let o=n(e),s=o5t(o,e,t);if(!s)return void i.push(a);r.urls[a]=s.url,r.held.push({key:o,frame:s})}),i}async function p5t(e,t,n,r,i){let a=0;for await(let o of e.canvasesAtTimestamps(t)){b1(r);let e=n[a++];if(!o||e?.decodedAt===void 0)continue;i.canvases.add(o.canvas);let t=await l5t(o.canvas);b1(r);let s=s5t(e.key,e.decodedAt,URL.createObjectURL(t));i.urls[e.slot]=s.url,i.held.push({key:e.key,frame:s})}b1(r)}function m5t(e,t,n,r=e.urls.length){let i=e.urls.filter(e=>e!==void 0),a=i[0];if(!a)throw Error(`Video source returned no thumbnail frames`);let o=a,s=Array.from({length:r},(t,n)=>o=e.urls[n]??o),{width:c,height:l}=u5t(t,n);return{value:s.length===1?{kind:`image`,url:a,aspect:t}:{kind:`filmstrip`,urls:s,aspect:t},weight:c*l*4*i.length,dispose:()=>x1(e)}}async function h5t(e,t,n=iK){let r=e.fit??`cover`,i=qX({source:e.source,version:e.contentVersion}),a=e=>`${i}\0${r}\0${e}`,o={urls:[],held:[],canvases:new Set},s=i5t.get(e.source),c=s?.version===e.contentVersion?s?.info:void 0;try{if(c){if(f5t(d5t(e,c,n),a,o).length===0)return b1(t),m5t(o,c.aspect,n);x1(o)}return await g5t(e,t,n,a,o)}catch(e){throw x1(o),e}}async function g5t(e,t,n,r,i){let a=await Mb(()=>import(`./src-DDA8OuTJ.js`),__vite__mapDeps([2,1,3]));b1(t);let o=new a.Input({source:new a.UrlSource(e.source),formats:a.ALL_FORMATS});try{let s=await o.getPrimaryVideoTrack();if(b1(t),!s)throw Error(`Video source has no decodable video track`);let[c,l]=await Promise.all([s.getDisplayWidth(),s.getDisplayHeight()]);if(b1(t),!(c>0&&l>0))throw Error(`Video source has invalid dimensions`);let u=await s.getDurationFromMetadata({skipLiveWait:!0});b1(t);let d={aspect:c/l,metadataDuration:u};i5t.set(e.source,{version:e.contentVersion,info:d});let f=d5t(e,d,n),{timestamps:p,window:m}=f,h=f5t(f,r,i).map(e=>({slot:e,key:r(p[e])}));if(h.length>0){let r=new a.EncodedPacketSink(s);async function*o(){for(let e of h){let n=p[e.slot],i=await r.getKeyPacket(n,{metadataOnly:!0});if(t.aborted)return;e.decodedAt=i&&a5t(m,n,i.timestamp)?i.timestamp:n,yield e.decodedAt}}let c=u5t(d.aspect,n);await p5t(new a.CanvasSink(s,{width:c.width,height:c.height,fit:e.fit??`cover`,poolSize:1}),o(),h,t,i)}return m5t(i,d.aspect,n,p.length)}finally{o.dispose()}}function S1({strip:e,frameW:t,frameCount:n,watchGap:r,style:i,children:a}){let o=Math.min(n,Math.ceil(e.inViewEnd/t)),s=Math.min(o,Math.floor(e.inViewStart/t));return(0,W.jsxs)(`div`,{className:`absolute inset-0 flex`,style:{...i,paddingLeft:s*t},children:[(0,W.jsx)(`div`,{ref:r,"data-thumbnail-gap":`start`,className:`pointer-events-none absolute inset-y-0 left-0`,style:{width:s*t}}),Array.from({length:o-s},(e,t)=>a(s+t)),(0,W.jsx)(`div`,{ref:r,"data-thumbnail-gap":`end`,className:`pointer-events-none absolute inset-y-0 right-0`,style:{left:o*t}})]})}function _5t(e,t,n){let{videoSrc:r,sourceStart:i,sourceRangeDuration:a,duration:o,projectId:s,sessionEpoch:c,priority:l}=e;return{key:qX({kind:`video`,source:r,start:i,duration:a??o,frames:t}),projectId:s,sessionEpoch:c,kind:`video`,priority:l,rich:n,load:e=>h5t({source:r,contentVersion:qX({project:s,session:c}),sourceStart:i,sourceRangeDuration:a??o,frameCount:t,fit:`cover`},e)}}function v5t(e,t,n){return t.status===`ready`?t:n.status===`ready`?n:e.status===`ready`?e:t.status===`loading`||e.status===`loading`?{status:`loading`}:e}function y5t(e,t,n){let r=XX(e),i=XX(t),[a,o]=(0,U.useState)({media:n,request:t});return(i.status===`ready`||t===null)&&a.request!==t&&o({media:n,request:t}),v5t(r,i,XX(a.media===n?a.request:null))}var b5t=(0,U.memo)(function({videoSrc:e,label:t,labelColor:n,duration:r=5,sourceStart:i,sourceRangeDuration:a,projectId:o=e,sessionEpoch:s=0,priority:c=`visible`}){let[l,u,d]=oZ(),f=FLt(g3t(M$(l.width,16/9,l.height).frameCount)),p=(0,U.useMemo)(()=>({videoSrc:e,sourceStart:i,sourceRangeDuration:a,duration:r,projectId:o,sessionEpoch:s,priority:c}),[r,c,o,s,a,i,e]),m=(0,U.useMemo)(()=>_5t(p,1,!1),[p]),h=(0,U.useMemo)(()=>_5t(p,f,!0),[f,p]),g=FLt(l.width>0),_=y5t(g?m:null,g&&f>1?h:null,m.key),v=_.status===`ready`?_.value:null,y=v?.kind===`filmstrip`?v.urls:v?.kind===`image`?[v.url]:[],b=v?.kind===`image`||v?.kind===`filmstrip`?v.aspect:16/9,{frameW:x,frameCount:S}=M$(l.width,b,l.height);return(0,W.jsxs)(`div`,{ref:u,className:`absolute inset-0 overflow-hidden`,children:[y.length>0&&(0,W.jsx)(S1,{strip:l,frameW:x,frameCount:S,watchGap:d,children:e=>{let t=y[_3t(e,S,y.length)];return(0,W.jsx)(`div`,{className:`relative h-full shrink-0 overflow-hidden bg-neutral-900`,style:{width:x},children:(0,W.jsx)(`img`,{src:t,alt:``,draggable:!1,className:`absolute inset-0 h-full w-full object-cover`})},e)}}),_.status===`loading`&&y.length===0&&(0,W.jsx)(`div`,{className:`absolute inset-0 animate-pulse motion-reduce:animate-none`,style:{background:`var(--timeline-thumbnail-shimmer)`}}),_.status===`error`&&(0,W.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-neutral-900/60`,children:(0,W.jsx)(`span`,{className:`rounded-sm bg-black/50 px-1 text-[8px] text-neutral-500`,children:`no preview`})}),t&&(0,W.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 z-10 px-1.5 pb-0.5 pt-3`,style:{background:`var(--timeline-thumbnail-label-gradient)`},children:(0,W.jsx)(`span`,{className:`block truncate text-[9px] font-semibold leading-tight`,style:{color:n,textShadow:`var(--timeline-thumbnail-label-shadow)`},children:t})})]})}),x5t=`v3`,C1=3;function S5t(e){return Number.isFinite(e)&&e!=null&&e>0&&e<=C1?e/2:C1}function C5t({previewUrl:e,seekTime:t=2,duration:n=5,selector:r,selectorIndex:i,origin:a,output:o,contentRevision:s=0}){let c=e.replace(`/preview/comp/`,`/thumbnail/`).replace(/\/preview$/,`/thumbnail/index.html`),l=new URL(c,a);return l.searchParams.set(`t`,(t+n/2).toFixed(2)),l.searchParams.set(`v`,x5t),l.searchParams.set(`revision`,String(s)),o&&l.searchParams.set(`output`,o),r&&(l.searchParams.set(`selector`,r),i!=null&&i>0&&l.searchParams.set(`selectorIndex`,String(i))),l.toString()}function w5t(e){let t=/\/preview\/comp\/([^?#]+)/.exec(e);return t?.[1]?decodeURIComponent(t[1]):`index.html`}function T5t(e,t,{sessionEpoch:n=0,priority:r=`visible`,rich:i=!1}={}){return{key:qX({kind:`composition`,url:e}),projectId:t,sessionEpoch:n,kind:`composition`,priority:r,rich:i,load:t=>E5t(e,t)}}async function E5t(e,t){let n=await H(e,{signal:t});if(!n.ok)throw Error(`Composition thumbnail failed (${n.status})`);let r=await n.blob();if(t.aborted)throw new DOMException(`Aborted`,`AbortError`);let i=URL.createObjectURL(r);try{return{value:{kind:`image`,url:i,aspect:await v3t(i,t)},weight:iK.posterMaxPhysicalWidth*iK.posterMaxPhysicalHeight*4,dispose:()=>URL.revokeObjectURL(i)}}catch(e){throw URL.revokeObjectURL(i),e}}var w1=(0,U.memo)(function({previewUrl:e,label:t,labelColor:n,selector:r,selectorIndex:i,seekTime:a=2,duration:o=5,projectId:s=e,sessionEpoch:c=0,contentRevision:l=0,priority:u=`visible`}){let[d,f,p]=oZ(),m=C5t({previewUrl:e,seekTime:a,duration:o,selector:r,selectorIndex:i,origin:window.location.origin,contentRevision:l}),h=XX((0,U.useMemo)(()=>T5t(m,s,{sessionEpoch:c,priority:u,rich:!0}),[u,s,c,m])),g=h.status===`ready`&&h.value.kind===`image`?h.value:null,{frameW:_,frameCount:v}=M$(d.width,g?.aspect??16/9,d.height,48);return(0,W.jsxs)(`div`,{ref:f,className:`absolute inset-0 overflow-hidden`,children:[g&&(0,W.jsx)(S1,{strip:d,frameW:_,frameCount:v,watchGap:p,style:{animation:`hf-thumb-fade 200ms ease-out`,mixBlendMode:`var(--timeline-composition-thumbnail-blend)`},children:e=>(0,W.jsx)(`div`,{className:`relative h-full shrink-0 overflow-hidden`,style:{width:_},children:(0,W.jsx)(`img`,{src:g.url,alt:``,draggable:!1,className:`absolute inset-0 h-full w-full object-contain`,style:{opacity:`var(--timeline-composition-thumbnail-opacity)`}})},e)}),h.status===`loading`&&(0,W.jsx)(`div`,{className:`absolute inset-0 animate-pulse bg-text-0/[0.035]`}),t&&(0,W.jsx)(`div`,{className:`absolute inset-y-0 left-3 z-10 flex items-center`,children:(0,W.jsx)(`span`,{className:`block max-w-full truncate text-[10px] font-semibold leading-none`,style:{color:n,textShadow:g?`0 1px 4px rgba(0,0,0,0.9), 0 0 8px rgba(0,0,0,0.6)`:`none`},children:t})})]})}),D5t=0,O5t=50,k5t=800,A5t={isEditMode:!1,dismissed:!1,model:null,selectedSegmentIds:new Set,selectedGroupId:null,sourceFilePath:null,syncError:null,retrySave:null,past:[],future:[]},T1=null,E1=0;function D1(e,t){if(!e.model)return{};let n=Date.now();return T1===t&&n-E1<k5t?(E1=n,{future:[]}):(T1=t,E1=n,{past:[...e.past,e.model].slice(-O5t),future:[]})}var O1=gb((e,t)=>({...A5t,setEditMode:t=>e({isEditMode:t}),setDismissed:t=>e({dismissed:t}),setModel:t=>e({model:t}),setSourceFilePath:t=>e({sourceFilePath:t}),setSyncError:t=>e({syncError:t}),setRetrySave:t=>e({retrySave:t}),undo:()=>{let{model:n,past:r,future:i}=t(),a=r[r.length-1];return!a||!n?null:(T1=null,e({model:a,past:r.slice(0,-1),future:[...i,n]}),a)},redo:()=>{let{model:n,past:r,future:i}=t(),a=i[i.length-1];return!a||!n?null:(T1=null,e({model:a,past:[...r,n].slice(-O5t),future:i.slice(0,-1)}),a)},selectSegment:(t,n=!1)=>e(e=>{if(n){let n=new Set(e.selectedSegmentIds);return n.has(t)?n.delete(t):n.add(t),{selectedSegmentIds:n,selectedGroupId:null}}return{selectedSegmentIds:new Set([t]),selectedGroupId:null}}),selectGroup:n=>{let r=t().model?.groups.get(n);r&&e({selectedSegmentIds:new Set(r.segmentIds),selectedGroupId:n})},selectAll:()=>e(e=>e.model?{selectedSegmentIds:new Set(e.model.segments.keys()),selectedGroupId:null}:{}),clearSelection:()=>{let{selectedSegmentIds:n,selectedGroupId:r}=t();(n.size!==0||r!==null)&&e({selectedSegmentIds:new Set,selectedGroupId:null})},updateSegmentStyle:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.segments.get(t);if(!r)return{};let i=new Map(e.model.segments);return i.set(t,{...r,style:{...r.style,...n}}),{...D1(e,`seg-style:${t}`),model:{...e.model,segments:i}}}),updateSegmentText:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.segments.get(t);if(!r)return{};let i=new Map(e.model.segments);return i.set(t,{...r,text:n}),{...D1(e,`seg-text:${t}`),model:{...e.model,segments:i}}}),updateSegmentTiming:(t,n,r)=>e(e=>{if(!e.model)return{};let i=e.model.segments.get(t);if(!i)return{};let a=new Map(e.model.segments);return a.set(t,{...i,start:n,end:r}),{...D1(e,`seg-timing:${t}`),model:{...e.model,segments:a}}}),updateGroupStyle:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t);if(!r)return{};let i=new Map(e.model.groups);return i.set(t,{...r,style:{...r.style,...n}}),{...D1(e,`group-style:${t}`),model:{...e.model,groups:i}}}),updateGroupContainer:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t);if(!r)return{};let i=new Map(e.model.groups);return i.set(t,{...r,containerStyle:{...r.containerStyle,...n}}),{...D1(e,`group-container:${t}`),model:{...e.model,groups:i}}}),updateGroupAnimation:(t,n,r)=>e(e=>{if(!e.model)return{};let i=e.model.groups.get(t);if(!i)return{};let a=new Map(e.model.groups),o=i.animation[n],s=o===null?r:{...o,...r};return a.set(t,{...i,animation:{...i.animation,[n]:s}}),{...D1(e,`group-anim:${t}:${n}`),model:{...e.model,groups:a}}}),splitGroup:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t);if(!r)return{};let i=r.segmentIds.indexOf(n);if(i<=0)return{};let a=r.segmentIds.slice(0,i),o=r.segmentIds.slice(i),s=`group-split-${D5t++}`,c=new Map(e.model.groups);c.set(t,{...r,segmentIds:a}),c.set(s,{...r,id:s,segmentIds:o});let l=e.model.groupOrder.indexOf(t),u=[...e.model.groupOrder];u.splice(l+1,0,s);let d=new Map(e.model.segments);return o.forEach((e,t)=>{let n=d.get(e);n&&d.set(e,{...n,groupIndex:t})}),{...D1(e,`split:${t}:${n}:${D5t}`),model:{...e.model,groups:c,segments:d,groupOrder:u}}}),mergeGroups:(t,n)=>e(e=>{if(!e.model)return{};let r=e.model.groups.get(t),i=e.model.groups.get(n);if(!r||!i)return{};let a=[...r.segmentIds,...i.segmentIds],o=new Map(e.model.groups);o.set(t,{...r,segmentIds:a}),o.delete(n);let s=e.model.groupOrder.filter(e=>e!==n),c=new Map(e.model.segments);i.segmentIds.forEach((e,t)=>{let n=c.get(e);n&&c.set(e,{...n,groupIndex:r.segmentIds.length+t})});let l=e.selectedGroupId===n?null:e.selectedGroupId;return{...D1(e,`merge:${t}:${n}`),model:{...e.model,groups:o,segments:c,groupOrder:s},selectedGroupId:l}}),updateSelectedStyle:t=>e(e=>{if(!e.model||e.selectedSegmentIds.size===0)return{};let n=new Map(e.model.segments);for(let r of e.selectedSegmentIds){let e=n.get(r);e&&n.set(r,{...e,style:{...e.style,...t}})}return{...D1(e,`sel-style:${[...e.selectedSegmentIds].join(`,`)}`),model:{...e.model,segments:n}}}),applyAnimationToAll:t=>e(e=>{if(!e.model)return{};let n=new Map(e.model.groups);for(let[e,r]of n)n.set(e,{...r,animation:t});return{...D1(e,`apply-anim-all`),model:{...e.model,groups:n}}}),reset:()=>{T1=null,e(e=>({...A5t,retrySave:e.retrySave,selectedSegmentIds:new Set,past:[],future:[]}))}})),j5t=new Set([`ArrowLeft`,`ArrowRight`]),M5t=[`button`,`a[href]`,`[role='button']`,`[role='checkbox']`,`[role='menuitem']`,`[role='menuitemradio']`,`[role='radio']`,`[role='spinbutton']`].join(`,`);function N5t(e){if(oX(e))return!0;if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.closest==`function`&&t.closest.call(e,M5t)!==null}var P5t=`[role=dialog][aria-modal=true]`;function F5t(){let e=globalThis.document;if(!e)return!1;let t=e.fullscreenElement;return Array.from(e.querySelectorAll(P5t)).some(e=>(!t||t.contains(e))&&!e.closest(`[inert]`)&&(typeof e.checkVisibility!=`function`||e.checkVisibility({visibilityProperty:!0})))}function I5t(e,t={isCaptionEditMode:!1,selectedCaptionSegmentCount:0}){return e.metaKey||e.ctrlKey||e.altKey||N5t(e.target)||F5t()?!0:j5t.has(e.code)&&t.isCaptionEditMode&&t.selectedCaptionSegmentCount>0}var L5t=[1,2,4],k1=0;function R5t(){k1+=1;let e=!1;return()=>{e||(e=!0,--k1)}}function z5t(){return k1>0}function B5t(e){return!e.shiftKey&&!e.altKey&&X.getState().activeTool===`razor`}function V5t({iframeRef:e,shuttleDirectionRef:t,shuttleSpeedIndexRef:n,iframeShortcutCleanupRef:r,getAdapter:i,play:a,playBackward:o,pause:s,seek:c}){let l=(0,U.useRef)(new Set),u=(0,U.useRef)(()=>{}),d=(0,U.useRef)(()=>{}),f=(0,U.useCallback)(e=>{c(XMe(i()?.getTime()??X.getState().currentTime,e,30))},[i,c]),p=(0,U.useCallback)(e=>{if(X.getState().playLocked)return;n.current=t.current===e?Math.min(n.current+1,L5t.length-1):0;let r=L5t[n.current];X.getState().setPlaybackRate(r),e===`forward`?a():o(r)},[a,o,t,n]),m=(0,U.useCallback)(()=>{X.getState().isPlaying?s():a()},[a,s]),h=(0,U.useCallback)(e=>{if(e.defaultPrevented)return;let t=O1.getState();if(I5t(e,{isCaptionEditMode:t.isEditMode,selectedCaptionSegmentCount:t.selectedSegmentIds.size}))return;let n=e.key.toLowerCase();if(l.current.add(n),e.code===`Space`){e.preventDefault(),m();return}if(!((e.code===`ArrowLeft`||e.code===`ArrowRight`)&&z5t())){if(e.code===`ArrowLeft`){e.preventDefault(),f(e.shiftKey?-10:-1);return}if(e.code===`ArrowRight`){e.preventDefault(),f(e.shiftKey?10:1);return}if(!e.repeat){if(n===`m`){e.preventDefault();let t=X.getState();t.setAudioMuted(!t.audioMuted);return}if(n===`l`&&e.shiftKey){e.preventDefault();let t=X.getState();t.setLoopEnabled(!t.loopEnabled);return}if(n===`k`){e.preventDefault(),s();return}if(n===`j`){if(e.preventDefault(),l.current.has(`k`)){f(-1);return}p(`backward`);return}if(n===`l`){if(e.preventDefault(),l.current.has(`k`)){f(1);return}p(`forward`);return}if(n===`i`){e.preventDefault();let t=i()?.getTime()??X.getState().currentTime;X.getState().setInPoint(e.shiftKey?null:t);return}if(n===`o`){e.preventDefault();let t=i()?.getTime()??X.getState().currentTime;X.getState().setOutPoint(e.shiftKey?null:t);return}if(n===`a`){if(B5t(e))return;e.preventDefault(),c(X.getState().inPoint??0,{keepPlaying:!0});return}if(n===`e`){e.preventDefault();let{outPoint:t}=X.getState();c(t??i()?.getDuration()??X.getState().duration,{keepPlaying:!0});return}}}},[s,p,f,m,i,c]),g=(0,U.useCallback)(e=>{l.current.delete(e.key.toLowerCase())},[]);return u.current=h,d.current=g,{playbackKeyDownRef:u,playbackKeyUpRef:d,attachIframeShortcutListeners:(0,U.useCallback)(()=>{r.current?.(),r.current=null;let t=null,n=null;try{t=e.current?.contentWindow??null,n=e.current?.contentDocument??null}catch{return}if(!t&&!n)return;let i=e=>u.current(e),a=e=>d.current(e);try{t?.addEventListener(`keydown`,i,!0),t?.addEventListener(`keyup`,a,!0)}catch{}n?.addEventListener(`keydown`,i,!0),n?.addEventListener(`keyup`,a,!0),r.current=()=>{try{t?.removeEventListener(`keydown`,i,!0),t?.removeEventListener(`keyup`,a,!0)}catch{}n?.removeEventListener(`keydown`,i,!0),n?.removeEventListener(`keyup`,a,!0)}},[e,r]),togglePlay:m}}var A1=new WeakMap,j1=new WeakMap,M1=new WeakMap;function H5t(e,t){t.some(e=>e.type!==`childList`||[...e.addedNodes,...e.removedNodes].some(e=>Me(e)&&(e.tagName.toLowerCase()===`hf-audio-group`||e.hasAttribute(`data-audio-group`)||e.querySelector?.(`hf-audio-group,[data-audio-group]`)!=null)))&&j1.set(e,(j1.get(e)??0)+1)}function U5t(e){if(M1.has(e)||typeof MutationObserver>`u`||!e.body)return;let t=new MutationObserver(t=>H5t(e,t));M1.set(e,t),t.observe(e.body,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[Re,yt,s,`data-label`,`data-volume`,`data-hidden`,`id`]})}function N1(e){e&&A1.delete(e)}function P1(e,t){if(!e)return{label:t,volume:1,hidden:!1};U5t(e);let n=M1.get(e)?.takeRecords();n?.length&&H5t(e,n);let r=j1.get(e)??0,i=A1.get(e),a=i&&i.revision===r?i.entries:void 0;return a||(a=new Map(Ve(e).map(e=>[e.id,{label:e.label,volume:e.volume,hidden:e.hidden,...e.fxChain?{fxChain:e.fxChain}:{},...e.automation?{automation:e.automation}:{}}])),A1.set(e,{revision:r,entries:a})),a.get(t)??{label:t,volume:1,hidden:!1}}var W5t=`hf:transition:`;function G5t(e){if(!e.startsWith(W5t))return null;let t=e.slice(W5t.length).split(`:`);return t.length<3||!t[0]||!t[1]?null:[t[0],t[1]]}function K5t(e,t){for(let n of[t,`el-${t}`]){let t=e.getElementById(n);if(t?.hasAttribute(`data-start`))return t}return Array.from(e.querySelectorAll(`[data-start]`)).find(e=>e.getAttribute(`data-hf-id`)===t||e.getAttribute(`data-composition-id`)===t)??null}function F1(e,t){let n=new Map;if(!t)return n;for(let r of Object.values(t)){let t=r.getLabels?.()??r.labels??{};for(let r of Object.keys(t)){let t=G5t(r);if(!t)continue;let i=K5t(e,t[0]),a=K5t(e,t[1]);i&&a&&(n.set(i,r),n.set(a,r))}}return n}function q5t(e,t={},n=30){return{...t,source:`hf-parent`,type:`control`,action:e,...vMe(n)}}function I1(e,t,n={},r=30){e?.postMessage(q5t(t,n,r),`*`)}function L1(e){return bMe(e,30)}function J5t(e){e.status===`unsupported`&&window.dispatchEvent(new CustomEvent(`runtimeprotocolerror`,{detail:{code:e.code,receivedVersion:e.receivedVersion}}))}function R1(e){let t=L1(e);return t.status===`unsupported`?(J5t(t),null):t}function Y5t(e){let t=L1(e);return t.status===`supported`?t.fps:30}function X5t(e,t){e.documentElement&&(e.documentElement.style.overflow=`hidden`,e.documentElement.style.margin=`0`),e.body&&(e.body.style.overflow=`hidden`,e.body.style.margin=`0`),t.scrollTo({top:0,left:0,behavior:`auto`})}function Z5t(e){let t=/data-composition-id=["']([^"']+)["']/gi,n=new Set,r=Array.from(e.querySelectorAll(`style, script`));for(let e of r){let r=e.textContent||``;if(!r)continue;let i;for(;(i=t.exec(r))!==null;){let e=(i[1]||``).trim();e&&n.add(e)}}if(n.size===0)return;let i=new Set,a=Array.from(e.querySelectorAll(`[data-composition-id]`));for(let e of a){let t=e.getAttribute(`data-composition-id`);t&&i.add(t)}for(let t of n){if(t===`root`||i.has(t))continue;let n=e.getElementById(`${t}-layer`)||e.getElementById(`${t}-comp`)||e.getElementById(t);n&&(n.getAttribute(`data-composition-id`)||n.setAttribute(`data-composition-id`,t))}}function Q5t(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):1}function $5t(e){return e instanceof HTMLElement}function z1(e){let t=e.getRootNode();return typeof ShadowRoot<`u`&&t instanceof ShadowRoot&&$5t(t.host)?t.host:null}function B1(e,t,n){I1(e.contentWindow,t,n)}function e7t(e,t){if(e)try{let n=z1(e);if(n&&typeof n.muted==`boolean`){n.muted=t;return}B1(e,`set-muted`,{muted:t})}catch{}}function t7t(e,t){if(!e)return;let n=Q5t(t);try{let t=z1(e);if(t&&typeof t.volume==`number`){t.volume=n;return}B1(e,`set-volume`,{volume:n})}catch{}}function n7t(e,t,n){e7t(e,t),t7t(e,n)}function r7t(e,t){if(!e)return;let n=Number.isFinite(t)&&t>0?t:1;try{let t=z1(e);if(t&&typeof t.playbackRate==`number`){t.playbackRate=n;return}B1(e,`set-playback-rate`,{playbackRate:n})}catch{}}var i7t=.25,V1=null,H1=null,U1=null,W1=null;function a7t(e){return e!==null&&e.namespaceURI===`http://www.w3.org/1999/xhtml`&&e.localName===`audio`}function o7t(e,t){if(t){let n=mt(e,`audio`)(t);if(a7t(n))return n}return e.querySelector(`audio[data-timeline-role='music']`)??e.querySelector(`audio`)}function s7t(e){e.ownerDocument.defaultView?.__hf?.leasePausedMedia?.(e)}function c7t(e){e.ownerDocument.defaultView?.__hf?.releasePausedMedia?.(e)}function l7t(e,t,n){V1&&V1!==e&&G1(),U1===null&&(U1=e.muted),W1===null&&(W1=e.volume),V1=e,s7t(e);try{e.muted=!1,e.volume=i7t*Q5t(n),Math.abs(e.currentTime-t)>.04&&(e.currentTime=t),e.paused&&e.play().catch(()=>{})}catch{}H1&&clearTimeout(H1),H1=setTimeout(G1,140)}function u7t(e,t,n,r=1){if(!e)return;if(t===null){G1();return}let i=null;try{i=e.contentDocument}catch{return}if(!i)return;let a=o7t(i,n);a&&l7t(a,t,r)}function G1(){H1&&=(clearTimeout(H1),null);let e=V1;if(V1=null,e){c7t(e);try{e.pause(),U1!==null&&(e.muted=U1),W1!==null&&(e.volume=W1)}catch{}U1=null,W1=null}}function d7t(e,t){return e.__timelines?.[t]?.duration?.()??0}function f7t(e){let t=new Map;for(let n of e.querySelectorAll(`[data-start]`))for(let e of[n.id,n.getAttribute(`data-hf-id`),n.getAttribute(`data-composition-id`)])e&&t.set(e,n);return t}function p7t(e,t){let n=(r,i)=>{if(i.has(r))return null;let a=e.get(r);if(!a)return null;let o=new Set(i).add(r),s=Tb(a,{resolveReferenceEnd:e=>n(e,o)});if(s.end!=null)return s.end;let c=a.getAttribute(`data-composition-id`),l=c?d7t(t,c):0;return s.start==null||l<=0?null:s.start+l};return n}function m7t(e,t,n){if(!Number.isFinite(t)||t<=0)return null;let r=Number.isFinite(e)?e:0;if(!Number.isFinite(n)||n<=0)return{start:r,duration:t};if(r>=n)return null;let i=Math.min(t,Math.max(0,n-r));return i>0?{start:r,duration:i}:null}function h7t(e,t){return e||t}function K1(e){return e||void 0}function g7t(e,t,n){if(n)return{...e,compositionSrc:n};let r=t.querySelector(`video[src]`);return r?{...e,src:K1(r.getAttribute(`src`)),tag:`video`}:e}function _7t(e){let{doc:t,iframeWin:n,element:r,compositionId:i,rootDuration:a,fallbackIndex:o}=e,{resolveEnd:s,masterTime:c}=e,l=F1(t,n.__timelines),u=Tb(r,{resolveReferenceEnd:e=>s(e,new Set([i]))}),d=m7t(c.resolveStartForElement(r),u.duration??d7t(n,i),a);if(!d)return null;let f=h7t(r.id,i),p=r.getAttribute(`data-composition-src`)??r.getAttribute(`data-composition-file`),m=at(r),h=Mt(r),g=Xt(t,r,m),_=pe({id:f,label:r.getAttribute(`data-timeline-label`)??r.getAttribute(`data-label`),tag:r.tagName}),v=pn({preferredId:f,label:_,fallbackIndex:o,domId:K1(r.id),selector:m,selectorIndex:g,sourceFile:h});return g7t({id:v.id,label:_,transitionLabel:l.get(r)??r.getAttribute(`data-transition-label`)??void 0,key:v.key,tag:r.tagName.toLowerCase(),start:d.start,parentCompositionStart:c.resolveHostStartForElement(r),duration:d.duration,track:u.trackIndex,authoredTrack:u.trackIndex,domId:K1(r.id),hfId:K1(r.getAttribute(`data-hf-id`)),selector:m,selectorIndex:g,sourceFile:h,zIndex:fn(r),src:K1(r.getAttribute(`src`))?new URL(r.getAttribute(`src`),r.baseURI).href:void 0},r,p)}function v7t(e,t,n,r){let i=new Set(n.map(e=>e.id)),a=e.querySelector(`[data-composition-id]`)?.getAttribute(`data-composition-id`),o=e.querySelectorAll(`[data-composition-id][data-start]`),s=[],c=p7t(f7t(e),t),l=Eb({timelineRegistry:t.__timelines,includeAuthoredTimingAttrs:!0,documentRef:e});for(let n of o){let o=n,u=o.getAttribute(`data-composition-id`);if(!u||u===a||i.has(o.id)||i.has(u))continue;let d=_7t({doc:e,iframeWin:t,element:o,compositionId:u,rootDuration:r,fallbackIndex:s.length,resolveEnd:c,masterTime:l});d&&s.push(d)}let u=!1,d=mt(e);return{missing:s,updatedEls:n.map(t=>{if(t.compositionSrc)return t;let n=d(t)??e.querySelector(`[data-composition-id="${CSS.escape(t.id)}"]`);if(!n)return t;let r=n.getAttribute(`data-composition-src`)||n.getAttribute(`data-composition-file`);return r?(u=!0,{...t,compositionSrc:r}):t}),patched:u}}function y7t(e){return e.tagName||e.kind||`div`}function b7t(e){let{clip:t,fallbackIndex:n,doc:r}=e,i=e.hostEl??null,a=r?F1(r,r.defaultView?.__timelines):new Map,o=pe({id:t.id,label:t.label,tag:y7t(t)}),s,c,l,u,d;i&&(s=i.id||void 0,d=i.getAttribute(`data-hf-id`)||void 0,c=at(i),l=r&&c?Xt(r,i,c):void 0,u=Mt(i));let f=pn({preferredId:t.id,label:o,fallbackIndex:n,domId:s,selector:c,selectorIndex:l,sourceFile:u}),p={id:f.id,label:o,transitionLabel:i&&a.get(i)||i?.getAttribute(`data-transition-label`)||void 0,key:f.key,kind:t.kind,tag:y7t(t),start:t.start,duration:t.duration,track:t.track,authoredTrack:t.track,stackingContextId:t.stackingContextId??null,domId:s,hfId:d,selector:c,selectorIndex:l,sourceFile:u,playbackStart:t.playbackStart,playbackRate:t.playbackRate};if(i){if(C(p,i),!p.src){let e=i.getAttribute(`src`);e&&(p.src=new URL(e,i.baseURI).href)}i.hasAttribute(`data-hidden`)&&(p.hidden=!0);let e=i.getAttribute(`data-timeline-role`);e&&(p.timelineRole=e);let t=i.getAttribute(`data-link`);t&&(p.link=t);let n=ew(i)?.getAttribute(`data-composition-id`);n&&(p.compositionScope=n);let a=i.getAttribute(`data-sync-origin`);a&&(p.syncOrigin=a);let o=i.getAttribute(`data-audio-group`);if(o){p.audioGroup=o;let e=P1(r??i.ownerDocument,o);p.audioGroupLabel=e.label,p.audioGroupVolume=e.volume,p.audioGroupHidden=e.hidden,e.fxChain&&(p.audioGroupFxChain=e.fxChain),e.automation&&(p.audioGroupAutomation=e.automation)}let s=i.getAttribute(`data-fx-chain`);s&&(p.fxChain=s);let c=i.getAttribute(`data-automation`);c&&(p.automation=c),p.zIndex=fn(i)}if(t.assetUrl&&(p.src=t.assetUrl),t.kind===`composition`&&t.compositionId){p.playbackStart??=0,p.playbackRate??=1;let e=t.compositionSrc;if(e||=(i?.getAttribute(`data-composition-id`)!==t.compositionId&&(i=r?.querySelector(`[data-composition-id="${CSS.escape(t.compositionId)}"]`)??i),i?.getAttribute(`data-composition-src`)??i?.getAttribute(`data-composition-file`)??null),e)p.compositionSrc=e;else if(i){let e=i.querySelector(`video[src]`);e&&(p.src=e.getAttribute(`src`)||void 0,p.tag=`video`)}if(i){p.domId=i.id||void 0,p.hfId=i.getAttribute(`data-hf-id`)||void 0,p.selector=at(i),p.selectorIndex=r&&p.selector?Xt(r,i,p.selector):void 0,p.sourceFile=Mt(i);let e=pn({preferredId:t.id,label:o,fallbackIndex:n,domId:p.domId,selector:p.selector,selectorIndex:p.selectorIndex,sourceFile:p.sourceFile});p.id=e.id,p.key=e.key}}return p}function q1(e,t,n){let r=e.querySelector(`[data-composition-id]`),i=e.querySelectorAll(`[data-start]`),a=[],o=0,s=n??e.defaultView?.__timelines,c=F1(e,s),l=Eb({timelineRegistry:s,includeAuthoredTimingAttrs:!0,documentRef:e});return i.forEach(n=>{if(n===r||Kt(n))return;let i=n,s=Tb(i);if(s.start==null)return;let u=i.tagName.toLowerCase(),d=u===`video`||u===`audio`?l.resolveMediaStartForElement(i):l.resolveStartForElement(i);if(Number.isFinite(t)&&t>0&&d>=t)return;let f=s.duration??0;if(f<=0&&(f=Math.max(0,t-d)),Number.isFinite(t)&&t>0&&(f=Math.min(f,Math.max(0,t-d))),!Number.isFinite(f)||f<=0)return;let p=s.trackSource==="default"?o++:s.trackIndex,m=i.getAttribute(`data-composition-id`),h=at(i),g=Mt(i),_=Xt(e,i,h),v=pe({id:i.id||i.getAttribute(`data-hf-original-composition-id`)||m||null,label:i.getAttribute(`data-timeline-label`)??i.getAttribute(`data-label`),tag:u}),y=pn({preferredId:i.id||m||null,label:v,fallbackIndex:a.length,domId:i.id||void 0,selector:h,selectorIndex:_,sourceFile:g}),b={id:y.id,label:v,transitionLabel:c.get(i)??i.getAttribute(`data-transition-label`)??void 0,key:y.key,kind:m&&m!==r?.getAttribute(`data-composition-id`)?`composition`:u===`video`||u===`audio`?u:u===`img`?`image`:`element`,tag:u,start:d,parentCompositionStart:l.resolveHostStartForElement(i),...l.isRootGlobalMediaStartForElement(i)&&{authoredStartIsMasterTime:!0},duration:f,track:p,domId:i.id||void 0,hfId:i.getAttribute(`data-hf-id`)||void 0,selector:h,selectorIndex:_,sourceFile:g,stackingContextId:eMe(i),zIndex:fn(i)},x=xe(i);if(C(b,i),x){x.tagName===`IMG`&&(b.tag=`img`);let e=x.src||void 0;e&&(b.src=e)}let S=i.getAttribute(`data-fx-chain`);S&&(b.fxChain=S);let w=i.getAttribute(`data-automation`);w&&(b.automation=w),i.hasAttribute(`data-timeline-locked`)&&(b.timelineLocked=!0),i.hasAttribute(`data-hidden`)&&(b.hidden=!0);let T=i.getAttribute(`data-timeline-role`);T&&(b.timelineRole=T);let E=i.getAttribute(`data-link`);E&&(b.link=E);let D=ew(i)?.getAttribute(`data-composition-id`);D&&(b.compositionScope=D);let O=i.getAttribute(`data-sync-origin`);O&&(b.syncOrigin=O);let k=i.getAttribute(`data-audio-group`);if(k){b.audioGroup=k;let t=P1(e,k);b.audioGroupLabel=t.label,b.audioGroupVolume=t.volume,b.audioGroupHidden=t.hidden,t.fxChain&&(b.audioGroupFxChain=t.fxChain),t.automation&&(b.audioGroupAutomation=t.automation)}let A=i.getAttribute(`data-composition-src`)||i.getAttribute(`data-composition-file`);if(A)b.compositionSrc=A;else if(m&&m!==r?.getAttribute(`data-composition-id`)){let e=i.querySelector(`video[src], img[src]`);e&&(b.src=e.getAttribute(`src`)||void 0,b.tag=e.tagName===`IMG`?`img`:`video`)}b.kind===`composition`&&(b.playbackStart??=0,b.playbackRate??=1),a.push(b)}),a}function x7t(e,t,n,r,i=()=>!0){let o=Number.isFinite(n)?n:0,s=Number.isFinite(r)?r:0;if(e.length===0||t.length>=e.length||s>o)return t;let c=new Set(t.map(a)),l=e.filter(e=>!c.has(a(e))&&e.compositionSrc!=null&&i(e));return l.length===0?t:[...t,...l]}function S7t(e){let t=e.match(/\/preview\/comp\/(.+?)(?:\?|$)/);return t?decodeURIComponent(t[1]):void 0}function C7t(e){if(!Number.isFinite(e.rootDuration)||e.rootDuration<=0)return null;let t=S7t(e.iframeSrc);return{id:e.compositionId,label:pe({id:e.compositionId,tag:e.tagName}),key:d({id:e.compositionId,fallbackIndex:0,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:t}),tag:e.tagName.toLowerCase()||`div`,start:0,duration:e.rootDuration,track:0,compositionSrc:t,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:t}}function J1(e){return Number.isFinite(e)&&e>0&&e<7200?e:0}function w7t(e){let t=e.getAttribute(Re);if(!t)return{};let n=P1(e.ownerDocument,t);return{audioGroup:t,audioGroupLabel:n.label,audioGroupVolume:n.volume,audioGroupHidden:n.hidden,...n.fxChain?{audioGroupFxChain:n.fxChain}:{},...n.automation?{audioGroupAutomation:n.automation}:{}}}function T7t(e){let t=new Map,n=e?.__clipTree;if(!n)return t;let r=e=>{for(let n of e)n.id&&n.parentId&&t.set(n.id,n.parentId),n.children.length>0&&r(n.children)};return r(n.roots),t}function Y1(e,t,n,r,i){for(let a of Array.from(t.children)){if(!a.id){Y1(e,a,n,r,i);continue}let t=a.hasAttribute(`data-hf-group`);i.push({id:a.id,parentId:n,hostId:e,label:t&&a.getAttribute(`data-hf-group`)||a.id,stackingContextId:eMe(a),...w7t(a)}),r.set(a.id,n),t&&Y1(e,a,a.id,r,i)}}function E7t(e,t,n){let r=[];if(!e)return r;for(let i of t){if(i.kind!==`composition`||!i.id)continue;let t=R(e,i);if(!t)continue;let a=t.querySelector(`[data-hf-inner-root]`)??t;Y1(i.id,a,i.id,n,r)}return r}function D7t(e){let t={};e.hasAttribute(`data-hidden`)&&(t.hidden=!0),e.hasAttribute(`data-timeline-locked`)&&(t.timelineLocked=!0);let n=e.getAttribute(`data-timeline-role`);n&&(t.timelineRole=n);let r=e.getAttribute(`data-fx-chain`);r&&(t.fxChain=r);let i=e.getAttribute(`data-automation`);return i&&(t.automation=i),Object.keys(t).length>0?t:null}function O7t(e,t){let n=new Map;if(!e)return n;for(let r of t){if(r.kind!==`composition`||!r.id)continue;let t=R(e,r);if(t)for(let e of Array.from(t.querySelectorAll(`[id]`))){let t=D7t(e);t&&n.set(e.id,t)}}return n}function X1(e){try{return e?.contentDocument??null}catch{return null}}function k7t(e,t){let n=t?Oe(t):null;return e.map((e,r)=>b7t({clip:e,fallbackIndex:r,doc:t,hostEl:n?.(e,r)??null}))}function A7t(e,t,n,r){let i=t>0&&e.length>0;r(j7t(e,i?t:n),i?t:void 0)}function j7t(e,t){return t<=0?[...e]:e.filter(e=>e.start<t).map(e=>({...e,duration:Math.min(e.duration,t-e.start)})).filter(e=>e.duration>0)}function M7t(e){let t=e.pendingSeek??e.requestedSeek??e.storeCurrentTime;return!Number.isFinite(t)||t<=0?0:!Number.isFinite(e.duration)||e.duration<=0?t:Math.min(t,e.duration)}function N7t(e,t){let n=Number.isFinite(t)&&t>0?t:0;e.seek(n>.001?Math.max(0,n-.001):.001),e.seek(n)}function P7t(e,t){let n=X.getState().requestedSeekTime,r=M7t({pendingSeek:t.current,requestedSeek:n,storeCurrentTime:X.getState().currentTime,duration:e.getDuration()});return t.current=null,n!=null&&X.getState().clearSeekRequest(),N7t(e,r),r}function F7t(e,t){let n=J1(e.getDuration());n>0&&n!==X.getState().duration&&t(n)}function I7t(e,t,n,r){let i=q1(e,n);if(i.length>0){r(i);return}let a=e.querySelector(`[data-composition-id]`);if(!a||n<=0)return;let o=C7t({compositionId:a.getAttribute(`data-composition-id`)||`composition`,tagName:a.tagName||`div`,rootDuration:n,iframeSrc:t?.src||``,selector:at(a)});o&&r([o])}function L7t(e,t){return!e.source||!t||e.source===t.contentWindow}function R7t(e,t){if(!L7t(e,t))return!1;let n=e.data;return n?.source!==`hf-preview`||n?.type!==`state`&&n?.type!==`timeline`?!1:L1(n).status!==`unsupported`}function z7t(e,t,n){!e||!t||(X5t(e,t),Z5t(e),n())}function B7t(e,t){let n=e?.__clipManifest;n&&n.clips.length>0&&t(n)}function V7t(e){let{iframe:t,adapter:n,syncTimelineElements:r}=e;try{let i=X1(t),a=t?.contentWindow??null;z7t(i,a,e.attachIframeShortcutListeners),B7t(a,e.processTimelineMessage),e.enrichMissingCompositions(),e.applyPreviewAudioState(),i&&X.getState().elements.length===0&&I7t(i,t,n.getDuration(),r)}catch{}}function H7t(e){e&&e.style.visibility===`hidden`&&(e.style.visibility=``)}function U7t(e,t,n){H7t(e),n()}function W7t(e,t,n){let r=e.find(e=>e.role===`live`);return r?[r,{gen:t,role:`shadow`,url:n}]:[{gen:t,role:`live`}]}function G7t(e){return e.filter(e=>e.role===`live`)}function K7t(e,t){let n=e.find(e=>e.gen===t&&e.role===`shadow`);return n?[{...n,role:`live`}]:e}function q7t(e){return Math.max(J1(e.manifestDurationSeconds),J1(e.authoredRootDurationSeconds))}function J7t({iframeRef:e,probeIntervalRef:t,pendingSeekRef:n,isRefreshingRef:r,getAdapter:i,syncTimelineElements:a,setDuration:o,setCurrentTime:s,requestTimelineReady:c,setIsPlaying:l,attachIframeShortcutListeners:u,applyPreviewAudioState:d,onAdapterReady:f=U7t,isCurrent:p,onLoadGiveUp:m}){let h=(0,U.useCallback)(t=>{if(!t.clips)return;X.getState().setClipManifest(t.clips);let n=new Set(t.clips.map(e=>e.compositionId).filter(Boolean)),r=t.clips.filter(e=>!e.parentCompositionId||!n.has(e.parentCompositionId)),i=X1(e.current);try{let n=T7t(e.current?.contentWindow??null),r=E7t(i,t.clips,n);X.getState().setClipParentMap(n),X.getState().setDomClipChildren(r),X.getState().setSubCompositionHostState(O7t(i,t.clips))}catch{}let o=k7t(r,i),s=Y5t(t);Nq.getState().setCompositionFps(s),A7t(o,q7t({manifestDurationSeconds:t.durationInFrames/s,authoredRootDurationSeconds:nn(i)}),X.getState().duration,a)},[e,a]),g=(0,U.useCallback)(()=>{try{let t=e.current,n=t?.contentDocument,r=t?.contentWindow;if(!n||!r)return;let i=X.getState().elements,o=X.getState().duration,{missing:s,updatedEls:c,patched:l}=v7t(n,r,i,o);if(s.length>0||l){let e=new Set(c.map(e=>e.id)),t=s.filter(t=>!e.has(t.id));a([...c,...t])}}catch{}},[e,a]),_=(0,U.useCallback)(t=>{if(p&&!p(t))return!0;let m=i();if(!m||m.getDuration()<=0)return!1;m.pause();let _=P7t(m,n);return f(e.current,t,()=>{Lb.notify(_),F7t(m,o),s(_),r.current||c(X1(e.current)),r.current=!1,l(!1),V7t({iframe:e.current,adapter:m,processTimelineMessage:h,enrichMissingCompositions:g,applyPreviewAudioState:d,attachIframeShortcutListeners:u,syncTimelineElements:a})}),!0},[i,o,s,c,l,h,g,a,u,d,f,p,e,r,n]),v=(0,U.useRef)(null),y=(0,U.useCallback)(n=>{let r=X1(e.current);if(r&&X.getState().markPreviewLoadStep(r),d(),t.current&&clearInterval(t.current),v.current?.(),v.current=null,_(n))return;let i=e.current,a=!1,o=0,s=()=>{window.removeEventListener(`message`,l),cancelAnimationFrame(o)},c=()=>{if(!a){if(_(n)){a=!0,s(),t.current&&clearInterval(t.current);return}cancelAnimationFrame(o),o=requestAnimationFrame(c)}},l=e=>{R7t(e,i)&&c()};window.addEventListener(`message`,l),v.current=s,t.current=setTimeout(()=>{a||c(),s(),a||m?.(n),H7t(e.current)},5e3)},[_,e,t,d,m]),b=(0,U.useCallback)(()=>{t.current&&clearInterval(t.current),v.current?.(),v.current=null},[t]);return{processTimelineMessage:h,processTimelineMessageRef:{current:h},enrichMissingCompositions:g,enrichMissingCompositionsRef:{current:g},initializeAdapter:_,onIframeLoad:y,cancelPendingLoad:b}}var Z1=`--hf-studio-rotation`,Q1=`data-hf-studio-path-offset`,$1=`data-hf-studio-edit-at`,e0=`data-hf-studio-box-size`,t0=`data-hf-studio-rotation`,n0=`data-hf-studio-original-translate`,r0=`data-hf-studio-original-inline-translate`,i0=`data-hf-studio-original-width`,a0=`data-hf-studio-original-height`,o0=`data-hf-studio-original-box-width`,s0=`data-hf-studio-original-box-height`,c0=`data-hf-studio-original-min-width`,l0=`data-hf-studio-original-min-height`,u0=`data-hf-studio-original-max-width`,d0=`data-hf-studio-original-max-height`,f0=`data-hf-studio-original-flex-basis`,p0=`data-hf-studio-original-flex-grow`,m0=`data-hf-studio-original-flex-shrink`,h0=`data-hf-studio-original-box-sizing`,g0=`data-hf-studio-original-scale`,_0=`data-hf-studio-original-transform-origin`,v0=`data-hf-studio-original-display`,y0=`data-hf-studio-original-rotate`,b0=`data-hf-studio-original-inline-rotate`,x0=`data-hf-studio-original-rotation-transform-origin`,S0=`data-hf-studio-rotation-draft`,C0=`data-hf-studio-original-transform-display`,Y7t=`__hfStudioManualEditsApply`,w0=`__hfStudioManualEditsWrapped`,T0=`__hfStudioManualEditsPlaybackFrame`,X7t=`center center`;function Z7t(e){return!!e&&typeof e.x==`number`&&typeof e.y==`number`}function Q7t(e){if(!e||typeof e!=`object`)return null;let t=e,n=Array.isArray(e)?e:t.path;if(!Array.isArray(n))return null;let r=n.filter(Z7t).map(e=>({x:e.x,y:e.y}));return r.length<2?null:{coords:r,curviness:typeof t.curviness==`number`?t.curviness:1,autoRotate:typeof t.autoRotate==`number`?t.autoRotate:t.autoRotate===!0,isCubic:t.type===`cubic`}}function $7t(e,t){let n=Q7t(e.motionPath),r=n&&VQe(n.coords,n.curviness,n.autoRotate,n.isCubic);if(!r)return null;let i=r.waypoints.length;return{keyframes:r.waypoints.map((e,t)=>({percentage:i>1?Math.round(t/(i-1)*100):0,properties:{x:e.x,y:e.y}})),arcPath:r.arcPath,runEase:t??sHt}}function E0(e,t){if(!e.targets)return!1;for(let n of e.targets())if(n===t||t.id&&n.id===t.id)return!0;return!1}var D0=null;function e9t(e){let t=D0;D0??=new WeakMap;try{return e()}finally{D0=t}}function t9t(e){let t={byElement:new Map,byId:new Map},n=(e,t,n)=>{let r=e.get(t);r?r.at(-1)!==n&&r.push(n):e.set(t,[n])};for(let r of e)for(let e of r.targets?.()??[]){n(t.byElement,e,r);let i=e.id;i&&n(t.byId,i,r)}return t}function n9t(e,t){if(!e||typeof e!=`object`||!D0)return(e?.getChildren?.(!0)??[]).filter(e=>E0(e,t));let n=D0.get(e);return n||D0.set(e,n=t9t(e.getChildren?.(!0)??[])),(t.id?n.byId.get(t.id):n.byElement.get(t))??[]}var r9t={scale:`scaleX`,rotate:`rotation`};function i9t(e,t){for(let n=e;n;n=n._next){if(n.p===t&&typeof n.s==`number`&&typeof n.c==`number`)return n;let e=i9t(n.d?._pt,t);if(e)return e}return null}function a9t(e,t){let n=i9t(e._pt,r9t[t]??t);if(!n)return null;let r=[n.s,n.s+n.c];return e._from?[r[1],r[0]]:r}function o9t(e,t){let n=t,r=e.keyframes[0];if(!Array.isArray(n.vars?.keyframes)&&!((r?.percentage??0)>0))return e;let i=n.timeline?.getChildren?.()??[n],a={};for(let e of[`x`,`y`,`width`,`height`]){let t=i.map(t=>a9t(t,e)).find(Boolean);t&&(a[e]=t[0])}return Object.entries(a).some(([e,t])=>t!==r?.properties[e])?{...e,start:a}:e}function O0(e,t,n){let r=e?.contentWindow,i=Xq(n);if(!r?.__timelines||i==null)return null;let a=n.keyframes?.keyframes.map(e=>e.properties)??[n.properties],o=[...new Set(a.flatMap(e=>Object.keys(e)))],s=!!n.keyframes;for(let e of Object.values(r.__timelines))for(let n of e?.getChildren?.(!0)??[]){let e=n.targets?.()??[];if(!e.includes(t)&&!e.some(e=>t.id&&e.id===t.id)||!s9t(n,i))continue;let a=n.vars??{};if(!(!(s?`keyframes`in a:o.some(e=>e in a))||!((n.duration?.()??0)>0)))return l9t(r,t,n,o),n}return null}function s9t(e,t){let n=Number(e.vars?.delay)||0;return Math.abs((e.startTime?.()??NaN)-n-t)<=.001}function c9t(e,t){let n=t?.startTime?.();return{...e,...Number.isFinite(n)&&{resolvedStart:n},...e.duration==null&&t&&{duration:t.duration?.()}}}function l9t(e,t,n,r){let i=!u9t(n)&&d9t(e,n);if(!i)return;let{parent:a,gsap:o}=i,s=f9t(n,t),c=a.time(),l=n.startTime?.()??0;o.set(t,{clearProps:r.join(`,`)});for(let e of r)o.getProperty(t,e);try{a.seek(l,!0),a.seek(l+(n.duration?.()??0),!0)}finally{a.seek(c,!0),p9t(s)}}function u9t(e){let t=e.timeline?.getChildren?.()??[];return!!e._initted&&t.every(e=>e._initted)}function d9t(e,t){let{parent:n}=t,r=e.gsap;return!n?.seek||!n.time||!r?.getProperty||!r.set?null:{parent:{seek:n.seek.bind(n),time:n.time.bind(n)},gsap:{getProperty:r.getProperty.bind(r),set:r.set.bind(r)}}}function f9t(e,t){let n=new Set([t]);for(let t of e.parent?.getChildren?.(!0,!0,!1)??[])for(let e of HZ(t))n.add(e);return[...n].map(e=>({layer:e,attributes:new Map([...e.attributes].map(e=>[e.name,e.value])),cache:e._gsap&&{...e._gsap}}))}function p9t(e){for(let{layer:t,attributes:n,cache:r}of e)m9t(t,n),r&&t._gsap&&h9t(t._gsap,r)}function m9t(e,t){for(let{name:n}of[...e.attributes])t.has(n)||e.removeAttribute(n);for(let[n,r]of t)e.getAttribute(n)!==r&&e.setAttribute(n,r)}function h9t(e,t){for(let n of Object.keys(e))n in t||delete e[n];Object.assign(e,t)}function g9t(e){return(t,n)=>{if(!e)return null;for(let r of _9t(e,n)){let e=a9t(r,t);if(e)return n===`start`?e[0]:e[1];if(t in(r.vars??{}))return null}return null}}function _9t(e,t){let n=e.timeline?.getChildren?.()??[];return n.length===0?[e]:t===`start`?n:[...n].reverse()}function v9t(e,t){if(!t)return null;let n=e?.contentWindow,r=t.vars?.ease??t.parent?.vars?.defaults?.ease??n?.gsap?.defaults?.().ease;return typeof r==`string`?r:typeof r==`function`?y9t.find(e=>n?.gsap?.parseEase?.(e)===r)??null:null}var y9t=[`none`,...[`power1`,`power2`,`power3`,`power4`,`sine`,`expo`,`circ`,`back`,`elastic`,`bounce`].flatMap(e=>[`${e}.in`,`${e}.out`,`${e}.inOut`])];function b9t(e,t){let n=e.keyframes,r=t?.timeline?.getChildren?.()??[];if(n?.format!==`object-array`||r.length!==n.keyframes.length)return e;let i=r.map(e=>(e.startTime?.()??0)+(e.duration?.()??0)),a=Math.max(...i);if(!(a>0)||i.some(e=>!Number.isFinite(e)))return e;let o=n.keyframes.map((e,t)=>({...e,percentage:Math.round(i[t]/a*1e5)/1e3}));return{...e,keyframes:{...n,keyframes:o}}}function x9t(e,t){let n=-1;return e.forEach((r,i)=>{let a=Math.abs(r.percentage-t);a<=nJ&&(n<0||a<Math.abs(e[n].percentage-t))&&(n=i)}),n}function S9t(e,t,n){let r=x9t(e.keyframes?.keyframes??[],n);return b9t(e,t).keyframes?.keyframes[r]?.percentage??n}var k0=e=>!!e._gsap?.renderTransform;function C9t(e,t,n){for(let r of t){let t=e.style.getPropertyValue(r);t&&n.push({type:`inline-style`,property:r,value:t})}}function w9t(e,t,n){for(let r of t){let t=e.getAttribute(r);t!==null&&n.push({type:`attribute`,property:r,value:t})}}function T9t(e,t){let n=e.getAttribute(C0);n!==null&&(t.push({type:`inline-style`,property:`display`,value:n||null}),t.push({type:`attribute`,property:C0,value:null}))}function E9t(e){let t=e.getAttribute(r0),n=[{type:`inline-style`,property:nj,value:null},{type:`inline-style`,property:rj,value:null},{type:`inline-style`,property:`translate`,value:t||null},{type:`attribute`,property:Q1,value:null},{type:`attribute`,property:n0,value:null},{type:`attribute`,property:r0,value:null}];return T9t(e,n),n}var A0=[`width`,`height`,`min-width`,`min-height`,`max-width`,`max-height`,`flex-basis`,`flex-grow`,`flex-shrink`,`box-sizing`,`scale`,`transform-origin`,`display`],D9t=[[i0,`width`],[a0,`height`],[o0,``],[s0,``],[c0,`min-width`],[l0,`min-height`],[u0,`max-width`],[d0,`max-height`],[f0,`flex-basis`],[p0,`flex-grow`],[m0,`flex-shrink`],[h0,`box-sizing`],[g0,`scale`],[_0,`transform-origin`],[v0,`display`],[C0,``]];function O9t(e){let t=[];return C9t(e,[ij,aj],t),C9t(e,k0(e)?A0.filter(e=>e!==`scale`):A0,t),t.push({type:`attribute`,property:e0,value:`true`}),w9t(e,D9t.map(([e])=>e),t),t}function k9t(e){let t=[{type:`inline-style`,property:ij,value:null},{type:`inline-style`,property:aj,value:null},{type:`attribute`,property:e0,value:null}];for(let[n,r]of D9t){let i=e.getAttribute(n);i!==null&&r&&t.push({type:`inline-style`,property:r,value:i||null}),t.push({type:`attribute`,property:n,value:null})}return t}function A9t(e){let t=e.getAttribute(b0),n=e.getAttribute(x0),r=[{type:`inline-style`,property:Z1,value:null},{type:`inline-style`,property:`rotate`,value:t||null},{type:`inline-style`,property:`transform-origin`,value:n===null?null:n||null},{type:`attribute`,property:t0,value:null},{type:`attribute`,property:S0,value:null},{type:`attribute`,property:y0,value:null},{type:`attribute`,property:b0,value:null},{type:`attribute`,property:x0,value:null}];return T9t(e,r),r}var j9t=new Set([`ease`,`duration`,`delay`,`stagger`,`motionPath`,`overwrite`,`immediateRender`,`onComplete`,`onUpdate`,`onStart`,`keyframes`]);function j0(e){if(!e?.contentWindow)return null;try{return e.contentWindow.__timelines??null}catch{return null}}function M0(e){return!(e>0)}function M9t(e){let t={};for(let[n,r]of Object.entries(e))j9t.has(n)||(typeof r==`number`?t[n]=S(r):typeof r==`string`&&(t[n]=r));return Object.keys(t).length===0?null:[{percentage:0,properties:t},{percentage:100,properties:t}]}var N9t=e=>typeof e==`string`?e:void 0;function N0(e){let t=N9t(e.ease);if(e.keyframes&&typeof e.keyframes==`object`){let n=SHt(e.keyframes),r=N9t(e.keyframes.ease);if(n)return{...n,runEase:r??t}}let n=$7t(e,t);if(n)return n;let r=M9t(e);return r?{keyframes:r}:null}function P9t(e){let t=typeof e.startTime==`function`?e.startTime():0,n=typeof e.duration==`function`?e.duration():0;return{start:Number.isFinite(t)?t:0,duration:Number.isFinite(n)?n:0}}function F9t(e,t){if(!e)return!1;for(let n of t)if(Object.prototype.hasOwnProperty.call(e,n))return!0;return!1}function P0(e,t){let n=e?.keyframes;return!n||typeof n!=`object`?!1:!Array.isArray(n)&&t.some(e=>Object.prototype.hasOwnProperty.call(n,e))?!0:(Array.isArray(n)?n:Object.values(n)).some(e=>typeof e==`object`&&!!e&&t.some(t=>Object.prototype.hasOwnProperty.call(e,t)))}function I9t(e,t,n,r,i){let a=j0(e);if(!a)return null;let o=null;try{o=e?.contentDocument?.querySelector(t)??null}catch{return null}if(!o)return null;let s=r?[r]:Object.keys(a).filter(e=>typeof a[e]?.getChildren==`function`),c=i&&i.length>0?i:null,l=null,u=null;for(let e of s){let t=a[e];if(!t?.getChildren)continue;let r=typeof t.time==`function`?t.time():null;for(let e of t.getChildren(!0)){if(!e.vars||!E0(e,o))continue;let i=typeof e.duration==`function`?e.duration():0,a=!(i>0);if(!(n===`set`?!a:a)){if(c){(n===`set`?F9t(e.vars,c):P0(e.vars,c))?u===null&&(u={tween:e,timeline:t}):l===null&&(l={tween:e,timeline:t});continue}if(l===null&&(l={tween:e,timeline:t}),n===`keyframe`&&r!=null){let n=typeof e.startTime==`function`?e.startTime():0;if(r>=n-.001&&r<=n+i+.001)return{tween:e,timeline:t}}}}}return u??l}function L9t(e,t){return e.keyframes.some(e=>t.some(t=>e.properties[t]!=null))}function F0(e,t,n,r){let i=j0(e);if(!i)return null;let a=null;try{a=e?.contentDocument?.querySelector(t)??null}catch{return null}if(!a)return null;let o=n?[n]:Object.keys(i).filter(e=>typeof i[e]?.getChildren==`function`);if(o.length===0)return null;let s=null;for(let e of o){let t=i[e];if(!t?.getChildren)continue;let n=typeof t.time==`function`?t.time():null;for(let e of t.getChildren(!0)){if(!e.vars||!E0(e,a))continue;let t=typeof e.duration==`function`?e.duration():0;if(M0(t))continue;let i=N0(e.vars);if(i&&!(r&&!L9t(i,r))&&(s===null&&(s=o9t(i,e)),n!=null)){let r=typeof e.startTime==`function`?e.startTime():0;if(n>=r-.001&&n<=r+t+.001)return o9t(i,e)}}}return s}function I0(e,t,n,r){let i=null;try{i=e?.contentDocument?.querySelector(t)??null}catch{return!1}return!!i&&q9t(j0(e),i,r,n)}var L0=[`x`,`y`,`xPercent`,`yPercent`,`left`,`top`,`translateX`,`translateY`],R9t=[...L0,`motionPath`],z9t=new Set(`x,y,z,scale,scaleX,scaleY,xPercent,yPercent,rotation,rotationX,rotationY,skewX,skewY,transformOrigin,svgOrigin,force3D,smoothOrigin,transformPerspective,translateX,translateY,translateZ,rotate,rotationZ,rotateZ,rotateX,rotateY`.split(`,`));function R0(e,t){let n=e.ownerDocument.defaultView;return Object.values(n?.__timelines??{}).some(n=>n9t(n,e).some(e=>!!e.vars&&(t.some(t=>t in e.vars)||P0(e.vars,t))))}var z0=[`rotation`,`rotationX`,`rotationY`,`rotationZ`,`rotate`,`rotateX`,`rotateY`,`rotateZ`];function B9t(e){return k0(e)||R0(e,R9t)}function V9t(e){return k0(e)||R0(e,z0)}function H9t(e){let t=e._gsap;return[`x`,`y`,`xPercent`,`yPercent`].some(e=>!!Number.parseFloat(String(t?.[e])))}var U9t=[...A0.map(e=>e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())),`scaleX`,`scaleY`];function W9t(e){return B9t(e)||R0(e,U9t)}var G9t={move:B9t,resize:W9t,rotate:V9t};function B0(e,t){return!G9t[t](e)}function K9t(e,t){let n=e.ownerDocument.defaultView;return q9t(n?.__timelines??null,e,t)}function q9t(e,t,n,r){if(!e)return!1;for(let i of r?[r]:Object.keys(e))for(let r of n9t(e[i],t)){if(!r.vars||M0(typeof r.duration==`function`?r.duration():0))continue;if(n&&P0(r.vars,n))return!0;let e=N0(r.vars);if(e&&(!n||L9t(e,n)))return!0}return!1}function J9t(e,t,n,r){let{keyframes:i,runEase:a}=e;return!r||r.duration<=0?i:i.map(e=>{let i=CHt(t,n,qq(a,e.percentage));return{...e,percentage:Math.round((i-r.start)/r.duration*1e5)/1e3}})}function Y9t(e,t,n,r){return{keyframes:J9t(e,t,n,r),tweenStart:t,tweenDuration:n,...e.easeEach?{easeEach:e.easeEach}:{},...e.arcPath?{arcPath:e.arcPath}:{}}}function X9t(e,t,n){if(!t.targets||!t.vars)return;let{start:r,duration:i}=P9t(t);if(M0(i))return;let a=N0(t.vars);if(a)for(let o of t.targets()){let t=o.id;t&&!e.has(t)&&e.set(t,Y9t(a,r,i,n?.get(t)))}}function Z9t(e,t){let n=new Map,r=j0(e);if(!r)return n;for(let e of Object.values(r))if(e?.getChildren)for(let r of e.getChildren(!0))X9t(n,r,t);return n}function V0(e){let t=[],n=0,r=``;for(let i of e.trim())i===`(`&&(n+=1),i===`)`&&(n=Math.max(0,n-1)),/\s/.test(i)&&n===0?(r&&t.push(r),r=``):r+=i;return r&&t.push(r),t}var Q9t=0,$9t=[`translate`,nj,rj],een={move:$9t,resize:[...$9t,ij,aj,...A0],rotate:[`rotate`,`transform`,`transform-origin`,`display`,Z1],edit:[]};function H0(e,t,n){Q9t+=1;let r=`gesture-${Q9t}:${t}`;return e.setAttribute(oj,r),n?e.setAttribute($1,JSON.stringify(n)):e.removeAttribute($1),r}var U0=`hf-manual-edit-gesture-ended`;function W0(e,t){if(t&&e.getAttribute(`data-hf-studio-manual-edit-gesture`)!==t||!e.hasAttribute(`data-hf-studio-manual-edit-gesture`))return;e.removeAttribute(oj),e.removeAttribute($1);let n=e.ownerDocument;n.dispatchEvent(new((n.defaultView?.Event)??Event)(U0))}function G0(e){return e.querySelector(`[${oj}]`)!==null}function ten(e,t){let n=()=>{G0(e)||(r(),t())},r=()=>e.removeEventListener(U0,n);return e.addEventListener(U0,n),r}var nen=new WeakMap;function ren(e){return nen.get(e)??0}function K0(e){nen.set(e,ren(e)+1)}function q0(e,t){let n=e.ownerDocument,r=()=>K0(n);r();let i=t();return Promise.resolve(i).then(r,r),i}function ien(e){let t=e.getAttribute(oj);return t===null?null:een[t.split(`:`)[1]]??[]}function aen(e){return e.hasAttribute(oj)}function J0(e,t){return e.getAttribute(oj)===t}function Y0(e,t){let n=Number.parseFloat(e.style.getPropertyValue(t));return Number.isFinite(n)?n:0}function oen(e){return{x:Y0(e,nj),y:Y0(e,rj)}}function sen(e){return(e.style.translate||``).includes(`--hf-studio-offset-x`)?oen(e):{x:0,y:0}}function X0(e){return{width:Y0(e,ij),height:Y0(e,aj)}}function cen(e){let t=Number.parseFloat(e.style.getPropertyValue(Z1));return{angle:Number.isFinite(t)?t:0}}function Z0(e,t){try{return e.ownerDocument.defaultView?.getComputedStyle(e).getPropertyValue(t)??``}catch{return``}}function Q0(e,t){return e.style.getPropertyValue(t)||Z0(e,t)}function len(e,t){let n=Q0(e,t).trim();return n===`none`?``:n}function $0(e){return e.includes(`--hf-studio-offset-x`)||e.includes(`--hf-studio-offset-y`)}function uen(e){return e.includes(`--hf-studio-width`)||e.includes(`--hf-studio-height`)}function e2(e){return e.includes(Z1)}function den(e){return e.replace(/\s+/g,``).toLowerCase()}function fen(e,t){if(!e.hasAttribute(S0))return!1;let n=e.style.getPropertyValue(Z1).trim();return!n||!t.trim()?!1:den(t)===den(Oen(e,n))}function t2(e){Z0(e,`display`)===`inline`&&(e.hasAttribute(C0)||e.setAttribute(C0,e.style.getPropertyValue(`display`)),e.style.setProperty(`display`,`inline-block`))}function n2(e){let t=e.getAttribute(C0);t!=null&&(t===``?e.style.removeProperty(`display`):e.style.setProperty(`display`,t),e.removeAttribute(C0))}function pen(e,t,n){let r=e.getAttribute(n0)?.trim();if(!r||r===`none`)return`${t} ${n}`;let i=V0(r);return i.length===1?`calc(${i[0]} + ${t}) ${n}`:i.length===2?`calc(${i[0]} + ${t}) calc(${i[1]} + ${n})`:i.length===3?`calc(${i[0]} + ${t}) calc(${i[1]} + ${n}) ${i[2]}`:`${t} ${n}`}function men(e,t){let n=e.style.getPropertyValue(`translate`),r=len(e,`translate`),i=e.hasAttribute(Q1),a=!$0(r);i?t&&a&&!aen(e)&&e.setAttribute(n0,r):(e.setAttribute(r0,$0(n)?``:n),e.setAttribute(n0,a?r:``))}function hen(e,t,n={}){men(e,n.updateBase??!0),e.setAttribute(Q1,`true`),e.style.setProperty(nj,`${S(t.x)}px`),e.style.setProperty(rj,`${S(t.y)}px`)}function gen(e){return e.is2D&&e.a===1&&e.b===0&&e.c===0&&e.d===1}function _en(e){if(e.hasAttribute(`data-hf-studio-manual-edit-gesture`))return;let t=e.style.getPropertyValue(`transform`);if(!t||t===`none`)return;let n=e.ownerDocument.defaultView?.DOMMatrix;if(n)try{let r=new n(t);if(r.m41===0&&r.m42===0)return;let i=Y0(e,nj),a=Y0(e,rj),o=Math.atan2(r.b,r.a),s=Math.cos(o),c=Math.sin(o);r.m41-=i*s-a*c,r.m42-=i*c+a*s,Math.abs(r.m41)<.01&&Math.abs(r.m42)<.01&&gen(r)?e.style.removeProperty(`transform`):e.style.setProperty(`transform`,r.toString())}catch{}}function ven(e,t){if(!R0(e,[`x`,`y`]))return!1;e.style.setProperty(`translate`,`none`);let n=e.ownerDocument.defaultView;if(n?.gsap){let r=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-x`)??``),i=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-y`)??``),a=Number.parseFloat(e.getAttribute(`data-hf-drag-initial-offset-x`)??``),o=Number.parseFloat(e.getAttribute(`data-hf-drag-initial-offset-y`)??``),s=Number.isFinite(r)?r:n.gsap.getProperty(e,`x`),c=Number.isFinite(i)?i:n.gsap.getProperty(e,`y`);Number.isFinite(r)||e.setAttribute(`data-hf-drag-gsap-base-x`,String(s)),Number.isFinite(i)||e.setAttribute(`data-hf-drag-gsap-base-y`,String(c));let l=t.x-(Number.isFinite(a)?a:0),u=t.y-(Number.isFinite(o)?o:0);n.gsap.set(e,{x:s+l,y:c+u})}return!0}function yen(e,t,n={}){t2(e),hen(e,t,{updateBase:n.updateBase??!0}),!ven(e,t)&&(e.style.setProperty(`translate`,pen(e,`var(${nj}, 0px)`,`var(${rj}, 0px)`)),_en(e))}function ben(e,t){t2(e),hen(e,t,{updateBase:!1}),!ven(e,t)&&(e.style.setProperty(`translate`,pen(e,`${S(t.x)}px`,`${S(t.y)}px`)),_en(e))}function xen(e,t){let n=e.parentElement;if(!n)return null;let r=Q0(n,`display`).trim();if(r!==`flex`&&r!==`inline-flex`)return null;let i=Q0(n,`flex-direction`).trim();return le(Math.max(1,i.startsWith(`column`)?t.height:t.width))}function Sen(e){if(!e.hasAttribute(g0))return;let t=e.getAttribute(g0);t==null||t===``?e.style.removeProperty(`scale`):e.style.setProperty(`scale`,t),e.removeAttribute(g0);let n=e.getAttribute(_0);n==null||n===``?e.style.removeProperty(`transform-origin`):e.style.setProperty(`transform-origin`,n),e.removeAttribute(_0)}function Cen(e,t){e.hasAttribute(o0)||e.setAttribute(o0,String(e.offsetWidth)),e.hasAttribute(s0)||e.setAttribute(s0,String(e.offsetHeight)),e.hasAttribute(e0)||(e.setAttribute(i0,e.style.getPropertyValue(`width`)),e.setAttribute(a0,e.style.getPropertyValue(`height`)),e.setAttribute(c0,e.style.getPropertyValue(`min-width`)),e.setAttribute(l0,e.style.getPropertyValue(`min-height`)),e.setAttribute(u0,e.style.getPropertyValue(`max-width`)),e.setAttribute(d0,e.style.getPropertyValue(`max-height`)),e.setAttribute(f0,e.style.getPropertyValue(`flex-basis`)),e.setAttribute(p0,e.style.getPropertyValue(`flex-grow`)),e.setAttribute(m0,e.style.getPropertyValue(`flex-shrink`)),e.setAttribute(h0,e.style.getPropertyValue(`box-sizing`)),e.setAttribute(g0,e.style.getPropertyValue(`scale`)),e.setAttribute(_0,e.style.getPropertyValue(`transform-origin`)),e.setAttribute(v0,e.style.getPropertyValue(`display`))),e.setAttribute(e0,`true`),e.style.setProperty(ij,`${le(Math.max(1,t.width))}px`),e.style.setProperty(aj,`${le(Math.max(1,t.height))}px`)}function wen(e,t){Cen(e,t),Sen(e);let n=le(Math.max(1,t.width)),r=le(Math.max(1,t.height));e.style.setProperty(`box-sizing`,`border-box`),e.style.setProperty(`width`,`${n}px`),e.style.setProperty(`height`,`${r}px`),e.style.setProperty(`min-width`,`0px`),e.style.setProperty(`min-height`,`0px`),e.style.setProperty(`max-width`,`none`),e.style.setProperty(`max-height`,`none`);let i=xen(e,t);i!=null&&(e.style.setProperty(`flex-basis`,`${i}px`),e.style.setProperty(`flex-grow`,`0`),e.style.setProperty(`flex-shrink`,`0`)),Z0(e,`display`)===`inline`&&e.style.setProperty(`display`,`inline-block`)}function r2(e,t){t2(e),wen(e,t)}var i2=new WeakMap;function Ten(e){return i2.get(e)??null}function a2(e){i2.delete(e)}function Een(e,t){i2.has(e)||i2.set(e,{width:e.offsetWidth,height:e.offsetHeight}),t2(e),wen(e,t)}function Den(e){return/^-?(?:\d+(?:\.\d+)?|\.\d+)(?:deg|rad|turn|grad)$/.test(e.trim())}function Oen(e,t){let n=e.getAttribute(y0)?.trim();return!n||n===`none`||!Den(n)?t:`calc(${n} + ${t})`}function ken(e,t){let n=e.style.getPropertyValue(`rotate`),r=len(e,`rotate`),i=e.hasAttribute(t0),a=!e2(r)&&!fen(e,r);i?t&&a&&!aen(e)&&e.setAttribute(y0,r):(e.setAttribute(b0,e2(n)?``:n),e.setAttribute(y0,a?r:``)),e.hasAttribute(x0)||e.setAttribute(x0,e.style.getPropertyValue(`transform-origin`))}function Aen(e,t,n={}){ken(e,n.updateBase??!0),e.setAttribute(t0,`true`),e.style.setProperty(Z1,`${S(t.angle)}deg`),e.style.setProperty(`transform-origin`,X7t)}function jen(e,t){t2(e),Aen(e,t),e.removeAttribute(S0),e.style.setProperty(`rotate`,Oen(e,`var(${Z1}, 0deg)`))}function o2(e){let t=null;return(n,r={})=>{if(t===null)try{t=localStorage.getItem(`hf-${e}-debug`)===`1`}catch{t=!1}if(!t)return;let i=typeof r==`function`?r():r;i&&console.log(`[hf-${e}] ${JSON.stringify({stage:n,t:Math.round(performance.now()),...i})}`)}}var s2=o2(`reload`),Men=!1,c2=!1,l2=0,u2=!1,d2=()=>Men||c2||l2>0,f2=()=>{d2()||(u2=!1)};function Nen(){u2=d2()}function p2(e){Men=e,YX.setPreviewReloading(e),f2()}function Pen(){c2=!0}function Fen(){c2=!1,f2()}async function m2(e){l2+=1;try{return await e()}finally{--l2,f2()}}function Ien(){return d2()&&!u2}var h2=`hf-scenes-swapped`,Len=5e3;function g2(e,t){return e.addEventListener(`load`,t),e.addEventListener(h2,t),()=>{e.removeEventListener(`load`,t),e.removeEventListener(h2,t)}}var _2=`hf-preview-promoted`;function Ren(e){e.live.ownerDocument.dispatchEvent(new CustomEvent(_2,{detail:e}))}function zen(e,t){let n=e=>t(e.detail);return e.addEventListener(_2,n),()=>e.removeEventListener(_2,n)}function Ben(e,t){let n=e?.contentDocument,r=n?.querySelector(`meta[name="hf-scene-parts"]`);if(!n||!r)return;let i;try{i=JSON.parse(r.content)}catch{return}for(let e of t){let t=n.querySelectorAll(`[data-composition-file="${CSS.escape(e)}"]`);t.length===0&&e.endsWith(`.html`)&&(i.shared=``);for(let e of t){let t=e.closest(`[data-hf-scene]`)?.getAttribute(`data-hf-scene`);t&&t in i.scenes&&(i.scenes[t]=``)}}r.content=JSON.stringify(i)}function Ven(e){let t=e.contentWindow,n=t?.__hfSwapScenes;return typeof n==`function`?async(r,i,a)=>{if(a?.aborted)throw a.reason;let o=new AbortController,s=setTimeout(()=>o.abort(Error(`the preview took too long to swap`)),Len);a?.addEventListener(`abort`,()=>o.abort(a.reason),{once:!0});let c=(async()=>{let e=await H(r,{signal:o.signal});if(!e.ok)throw Error(`preview request failed with ${e.status}`);let a=await e.text();if(!i())throw Error(`superseded by a newer reload`);await n.call(t,a,o.signal)})(),l=new Promise((e,t)=>o.signal.addEventListener(`abort`,()=>t(o.signal.reason)));try{await Promise.race([c,l])}finally{clearTimeout(s)}e.dispatchEvent(new Event(h2))}:null}var Hen=15e3,Uen=3;function Wen(e){return(e?.contentWindow)?.__hfWaitForSeekCompletion?.().catch(()=>{})}function Gen(){return typeof document<`u`&&document.visibilityState===`hidden`}function Ken({iframeRef:e,getAdapter:t,pendingSeekRef:n,isRefreshingRef:r,syncTimelineElements:i,setDuration:a,setCurrentTime:o,requestTimelineReady:s,setIsPlaying:c,attachIframeShortcutListeners:l,applyPreviewAudioState:u,onPromoted:d,onReloadFailed:f,handOverPlayback:p}){let m=(0,U.useRef)(null),h=(0,U.useRef)(void 0),g=(0,U.useRef)(0),_=(0,U.useRef)(null),v=(0,U.useRef)(null),y=(0,U.useRef)(d);y.current=d;let b=(0,U.useRef)(f);b.current=f;let x=(0,U.useRef)(p);x.current=p;let S=(0,U.useRef)(void 0),C=(0,U.useRef)(0),w=(0,U.useRef)(null),T=(0,U.useRef)(()=>{}),E=(0,U.useRef)(()=>{}),D=(0,U.useRef)(``),O=(0,U.useRef)(0),k=(0,U.useRef)(()=>{}),A=(0,U.useRef)(()=>{}),[j,M]=(0,U.useState)([{gen:0,role:`live`}]),N=(0,U.useCallback)(()=>{clearTimeout(S.current),w.current=null,T.current(),E.current(),_.current=null,v.current=null},[]),P=(0,U.useCallback)((e,t)=>{if(e!==g.current)return;g.current+=1,N(),m.current=null,r.current=!1,n.current=null,M(G7t),p2(!1);let i=`The preview did not reload (${t}). The previous preview is still showing.`;s2(`shadow-failed`,{cause:t}),console.error(`[studio] ${i}`),b.current?.(i)},[N,r,n]),F=(0,U.useCallback)(()=>{let t=e.current?.contentDocument;return t?ren(t):0},[e]),I=(0,U.useCallback)((e,t,n)=>(clearTimeout(S.current),w.current=null,E.current(),s2(`shadow-held`,{gen:e,why:t}),E.current=n(()=>{s2(`shadow-hold-ended`,{gen:e,why:t}),A.current(e)}),!0),[]),L=(0,U.useCallback)(t=>{let n=e.current?.contentDocument;if(n&&G0(n))return I(t,`gesture`,e=>ten(n,e));if(F()===O.current)return!1;if(WKt())return I(t,`save`,GKt);s2(`shadow-reloaded-after-gesture-save`,{gen:t});let r=new URL(D.current,window.location.origin);return r.searchParams.set(`_t`,String(Date.now())),k.current(r.toString()),!0},[e,F,I]),R=(0,U.useCallback)(e=>{let t=m.current,n=_.current,r=n?.gen===e&&v.current===e;return t&&n&&r&&e===g.current?{shadow:t,pending:n}:null},[]),z=(0,U.useCallback)(n=>{let r=R(n);if(!r||L(n))return;let{shadow:i,pending:a}=r;N();let o=t(),s=o?.getTime(),c=X.getState().isPlaying;o?.pause();let d=e.current;e.current=i,a.commit(),m.current=null,l(),u(),M(e=>K7t(e,n)),s!=null&&x.current(s,c),Ren({retired:d,live:i}),y.current?.(),p2(!1)},[N,R,L,t,e,l,u]);A.current=z;let B=(0,U.useCallback)(()=>t(m.current),[t]),V=(0,U.useCallback)(e=>e===g.current,[]),ee=(0,U.useCallback)(()=>g.current,[]),{onIframeLoad:te,cancelPendingLoad:H}=J7t({iframeRef:m,probeIntervalRef:h,pendingSeekRef:n,isRefreshingRef:r,getAdapter:B,syncTimelineElements:i,setDuration:a,setCurrentTime:o,requestTimelineReady:s,setIsPlaying:c,attachIframeShortcutListeners:()=>{},applyPreviewAudioState:()=>{},onAdapterReady:(0,U.useCallback)((e,t,n)=>{if(t==null||t!==g.current)return;let r=()=>{t===g.current&&(_.current={gen:t,commit:n},z(t))},i=Wen(e);i?i.then(r):r()},[z]),isCurrent:V});T.current=H;let ne=(0,U.useCallback)((e,t)=>{e===g.current&&(v.current=t?e:null,t&&z(e))},[z]),re=(0,U.useCallback)(e=>{m.current=e},[]),ie=(0,U.useCallback)(e=>{clearTimeout(S.current),!Gen()&&(S.current=setTimeout(()=>{if(e===g.current){if(C.current+=1,C.current<Uen){s2(`shadow-slow`,{budgetsSpent:C.current}),ae.current(e);return}P(e,`it took too long to load`)}},Hen))},[P]),ae=(0,U.useRef)(ie);ae.current=ie;let oe=(0,U.useCallback)(e=>{g.current+=1;let t=g.current;N(),w.current=t,C.current=0,D.current=e,O.current=F(),ie(t),M(n=>W7t(n,t,e)),p2(!0)},[N,ie,F]);k.current=oe;let se=(0,U.useCallback)(()=>{g.current+=1,N(),m.current=null,r.current=!1,n.current=null,X.getState().setTimelineReady(!1),M(G7t),p2(!1)},[N,r,n]);return ax(()=>{let e=()=>{if(Gen()){clearTimeout(S.current);return}let e=w.current;e!=null&&e===g.current&&ae.current(e)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e),N(),p2(!1)}}),{previewSlots:j,onShadowIframeLoad:te,onShadowReadyChange:ne,onShadowError:P,setShadowIframeNode:re,beginShadowReload:oe,resetPreviewSlots:se,previewGeneration:ee}}function qen(e,t,n){let r=null;for(let i of Jen(e,t)){let e=Ie(i);if(e>0&&n<=e)return{match:i,fallback:r};e>0&&(r??=i)}return{match:null,fallback:r}}function*Jen(e,t){t.__timeline&&(yield fe(t.__timeline));let n=t.__timelines?Object.keys(t.__timelines):[];if(!t.__timelines||n.length===0)return;let r=e.contentDocument?.querySelector(`[data-composition-id]`)?.getAttribute(`data-composition-id`),i=r&&r in t.__timelines?r:n[n.length-1];yield fe(t.__timelines[i])}function Yen(e,t,n){let r=t.__player&&typeof t.__player.play==`function`?t.__player:null,i=nn(e.contentDocument),a=Ie(r);if(a>0&&i<=a)return ln(n.cache,n.warned),r;let o=qen(e,t,i);if(o.match)return ln(n.cache,n.warned),o.match;let s=o.fallback,c=r??s,l=Math.max(X.getState().duration,i,a);return c&&l>0&&(`renderSeek`in c||typeof c.seek==`function`)?on({cache:n.cache,warned:n.warned,bestAdapter:c,effectiveDuration:l,docDuration:i,clock:Ne(t),getPlaybackRate:()=>X.getState().playbackRate}):c}function Xen({rafRef:e,reverseRafRef:t,getAdapter:n,setCurrentTime:r,setIsPlaying:i,setLoopStart:a}){let o=(0,U.useCallback)(()=>{cancelAnimationFrame(t.current)},[t]);return{startRAFLoop:(0,U.useCallback)(()=>{let t=()=>{let o=n();if(o){let n=o.getTime(),s=o.getDuration(),c=s>0?Math.min(n,s):n;Lb.notify(c);let{inPoint:l,outPoint:u}=X.getState(),d=u===null?s:Math.min(u,s),f=l===null?0:l,p=f<d?d:s,m=f<d?f:0,h=X.getState().loopEnabled&&s>0;if(a(h?m:null),c>=p){if(h&&!X.getState().playLocked){o.seek(m,{keepPlaying:!0}),Lb.notify(m),o.play(),i(!0),e.current=requestAnimationFrame(t);return}o.isPlaying()&&o.pause(),r(c),i(!1),cancelAnimationFrame(e.current);return}}e.current=requestAnimationFrame(t)};e.current=requestAnimationFrame(t)},[e,n,r,i,a]),stopRAFLoop:(0,U.useCallback)(()=>{cancelAnimationFrame(e.current)},[e]),stopReverseLoop:o}}function Zen(e,t){let n=X.getState(),r=LG(n.elements).musicElement;if(!r||n.audioMuted)return;let i=t-r.start;u7t(e,i>=0&&i<=r.duration?(r.playbackStart??0)+i:null,r,n.audioVolume)}var v2=1e3,Qen=!1,$en=Object.freeze({"dense-short":{duration:120,clipDuration:1.5},"long-overlap":{duration:7200,clipDuration:120},"keyframe-heavy-expanded":{duration:600,clipDuration:8},"composition-heavy":{duration:900,clipDuration:12},"remote-unsupported":{duration:900,clipDuration:12}});function etn(e){Qen=e}function ttn(){return Qen}function ntn(e){if(e.elementCount!==1e3&&e.elementCount!==5e4)throw RangeError(`Timeline performance fixture elementCount must be 1000 or 50000`);if(!Object.hasOwn($en,e.profile))throw RangeError(`Unknown timeline performance fixture profile: ${e.profile}`);return $en[e.profile]}function rtn(e,t){if(e<v2)return e;if(t.profile!==`dense-short`)return e%v2;let n=Math.ceil((t.elementCount-v2)/127);return(e-v2)%Math.max(1,n)}function itn(e,t,n,r){let i=Math.max(0,n-r);return t===`dense-short`?e%128*.5:t===`long-overlap`?e*37%Math.max(1,i):e*17%Math.max(1,i)}function atn(){return{format:`percentage`,keyframes:[0,33,66,100].map(e=>({percentage:e,propertyGroup:`position`,properties:{x:e},ease:`power2.inOut`}))}}function otn(e,t,n){return{id:`animation-${e}`,targetSelector:`#${e}`,method:`to`,position:t,resolvedStart:t,duration:n,propertyGroup:`position`,fromProperties:{x:0},properties:{x:100},ease:`power2.inOut`}}function stn(e){let t=ntn(e),n=[],r=new Map,i=new Map,a=new Set;for(let o=0;o<e.elementCount;o+=1){let s=`perf-${e.profile}-${e.elementCount}-${o}`,c=itn(o,e.profile,t.duration,t.clipDuration),l=rtn(o,e),u={id:s,key:s,domId:s,selector:`#${s}`,label:`Fixture ${o+1}`,tag:e.profile===`remote-unsupported`&&o%2==0?`video`:`div`,start:c,duration:t.clipDuration,track:l,authoredTrack:l};e.profile===`composition-heavy`?u.compositionSrc=`compositions/perf-${o%32}.html`:e.profile===`remote-unsupported`&&(u.src=o%2==0?`https://media.invalid/perf-${o%32}.mp4`:`assets/perf-${o%32}.unsupported`),e.profile===`keyframe-heavy-expanded`&&(r.set(s,atn()),i.set(s,[otn(s,c,t.clipDuration)]),a.add(s)),n.push(u)}return{summary:Object.freeze({...e,duration:t.duration,trackCount:v2,keyframedElementCount:r.size,expandedElementCount:a.size}),elements:n,keyframeCache:r,gsapAnimations:i,expandedClipIds:a}}var y2=new Map,b2=new Map,x2=new Map,S2=0,C2=0,w2=0,ctn=[],T2=null;async function ltn(){if(T2===!1)return null;if(T2)return T2;try{return T2=await Mb(()=>import(`./src-DDA8OuTJ.js`),__vite__mapDeps([2,1,3])),T2}catch{return T2=!1,null}}function E2(e){try{return new URL(e,window.location.href).href}catch{return e}}async function utn(e){let t=await ltn();if(!t)return null;let n=new t.Input({source:new t.UrlSource(e),formats:t.ALL_FORMATS});try{let e=await n.getDurationFromMetadata();if(e==null||!Number.isFinite(e)||e<=0)return null;let t=await n.getPrimaryVideoTrack(),r=await n.getAudioTracks();return{duration:e,width:t?.displayWidth,height:t?.displayHeight,hasVideo:t!=null,hasAudio:r.length>0}}catch{return null}finally{n.dispose()}}function D2(e){let t=y2.get(E2(e));return t&&(t.lastAccess=++S2),t?.result}function dtn(e,t){return t?P$(e,t,window.location.origin):e}function ftn(){let e=y2.size+x2.size-iK.metadataRegistryEntries;if(e<=0)return;let t=[...Array.from(y2,([e,t])=>({key:e,at:t.lastAccess,failed:!1})),...Array.from(x2,([e,t])=>({key:e,at:t.lastAccess,failed:!0}))].sort((e,t)=>e.at-t.at);for(let n of t.slice(0,e))n.failed?x2.delete(n.key):y2.delete(n.key)}function ptn(e,t){return e.map(e=>{let n=e.tag.toLowerCase();if(!e.src||e.sourceDuration!=null||n!==`audio`&&n!==`video`)return e;let r=D2(dtn(e.src,t));return r?.duration&&r.duration>0?{...e,sourceDuration:r.duration}:e})}async function mtn(e,t,n){let r=e.flatMap(e=>{if(!e.src||e.sourceDuration!=null||![`video`,`audio`].includes(e.tag.toLowerCase()))return[];let n=dtn(e.src,t);return!D2(n)&&!htn(E2(n))?[{el:e,source:n}]:[]});r.length!==0&&await Promise.allSettled(r.map(async({el:e,source:t})=>{let r=await gtn(t);r&&n(e.key??e.id,r.duration)}))}function htn(e){let t=x2.get(e);return t===void 0?!1:Date.now()-t.failedAt<iK.metadataFailureTtlMs?(t.lastAccess=++S2,!0):(x2.delete(e),!1)}async function gtn(e){let t=E2(e),n=D2(t);if(n)return n;if(htn(t))return null;let r=b2.get(t);return r||(r=new Promise(e=>{ctn.push({key:t,epoch:w2,resolve:e}),_tn()}),b2.set(t,r),r)}function _tn(){for(;C2<iK.concurrentMetadataJobs;){let e=ctn.shift();if(!e)return;if(e.epoch!==w2){e.resolve(null);continue}C2++,utn(e.key).then(t=>e.epoch===w2?(b2.delete(e.key),t?y2.set(e.key,{result:t,lastAccess:++S2}):x2.set(e.key,{failedAt:Date.now(),lastAccess:++S2}),ftn(),t):null).then(e.resolve).finally(()=>{C2--,_tn()})}}function vtn(e){return!e.playLocked&&e.keepPlaying&&!e.wasReverseShuttle&&e.storeWasPlaying&&(e.duration<=0||e.nextTime<e.duration)}function ytn(e){return!e.keepPlaying||e.wasReverseShuttle}function btn(e,t){return!!(e.source&&t&&e.source!==t.contentWindow)}function xtn(e,t){if(ttn()||btn(e,t))return null;let n=e.data;return n?.source===`hf-preview`&&R1(n)?n:null}function Stn(e,t){try{if(X.getState().elements.length===0){let n=t?.contentWindow?.__clipManifest;n&&n.clips.length>0&&e.processTimelineMessageRef.current(n)}Date.now()-e.lastTimelineMessageRef.current>500&&e.enrichMissingCompositionsRef.current()}catch{}}function Ctn(e,t,n){if(e.lastTimelineMessageRef.current=Date.now(),e.processTimelineMessageRef.current(n),e.enrichMissingCompositionsRef.current(),!(X.getState().elements.length>0))try{let n=t?.contentDocument,r=e.getAdapter();if(!n||!r)return;let i=q1(n,r.getDuration());i.length>0&&e.syncTimelineElements(i)}catch{}}function wtn(e){return t=>{let n=e.iframeRef.current,r=xtn(t,n);if(r){if(r.type===`state`)return Stn(e,n);r.type===`timeline`&&Array.isArray(r.clips)&&Ctn(e,n,r)}}}var Ttn=[`id`,`start`,`duration`,`track`,`sourceDuration`,`muted`,`hasAudio`,`volume`,`playbackRate`,`hidden`,`audioGroup`,`audioGroupVolume`,`audioGroupHidden`,`fadeIn`,`fadeOut`,`src`,`link`];function Etn(e,t){return t.length!==e.length||t.some((t,n)=>{let r=e[n];return!r||Ttn.some(e=>t[e]!==r[e])||!u(t.text,r.text)})}var Dtn=(e,t)=>t?.follow===!1?Lb.notify(e):Lb.notifySeek(e);function Otn({onShadowPromoted:e,onPreviewReloadFailed:t}={}){let n=(0,U.useRef)(null),r=(0,U.useRef)(0),i=(0,U.useRef)(void 0),a=(0,U.useRef)(null),o=(0,U.useRef)(!1),s=(0,U.useRef)(0),c=(0,U.useRef)(null),l=(0,U.useRef)(0),u=(0,U.useRef)(null),d=(0,U.useRef)(0),f=(0,U.useRef)(null),p=(0,U.useRef)(!1),{setIsPlaying:m,setCurrentTime:h,setDuration:g,requestTimelineReady:_,setElements:v}=X.getState(),y=(0,U.useCallback)((e,t)=>{if(ttn())return;let r=X.getState(),i=t??r.duration,a=cKt(ptn(x7t(r.elements,e,r.duration,i,e=>vQ(n.current,{...e,kind:`composition`})!==null),r.timelineProjectId));Etn(r.elements,a)&&v(a),Number.isFinite(t)&&(t??0)>0&&t!==r.duration&&g(t??0),r.timelineReady||_(X1(n.current)),mtn(a,r.timelineProjectId,(e,t)=>{X.setState(n=>{let r=n.elements.findIndex(t=>(t.key??t.id)===e);if(r===-1||n.elements[r].sourceDuration!=null)return{};let i=n.elements.slice();return i[r]={...n.elements[r],sourceDuration:t},{elements:i}})})},[v,_,g]),b=(0,U.useCallback)(e=>{try{let t=e===void 0?n.current:e,r=t?.contentWindow;return!t||!r?null:dVt(Yen(t,r,{cache:f,warned:p}))}catch{return null}},[]),{startRAFLoop:x,stopRAFLoop:S,stopReverseLoop:C}=Xen({rafRef:r,reverseRafRef:s,getAdapter:b,setCurrentTime:h,setIsPlaying:m,setLoopStart:(0,U.useCallback)(e=>{try{n.current?.contentWindow?.__hf?.setLoopStart?.(e)}catch{}},[])}),w=(0,U.useCallback)(e=>{let t=n.current;if(t){r7t(t,e);try{let n=t.contentWindow;if(n?.__timelines)for(let t of Object.values(n.__timelines))t&&typeof t.timeScale==`function`&&t.timeScale(e)}catch{}}},[]),T=(0,U.useCallback)(()=>{let{audioMuted:e,audioVolume:t}=X.getState();n7t(n.current,e,t)},[]),E=(0,U.useCallback)(()=>{let{timelineReady:e,playLocked:t}=X.getState();if(!e||t)return;S(),C(),G1();let n=b();n&&(n.getTime()>=n.getDuration()&&n.seek(X.getState().inPoint??0),w(X.getState().playbackRate),T(),n.play(),c.current=`forward`,m(!0),x())},[b,m,x,w,T,S,C]),D=(0,U.useCallback)(e=>{S(),C();let t=b();if(!t)return;let n=Math.max(0,t.getDuration()),r=t.getTime()<=0&&n>0?n:t.getTime();t.pause(),r!==t.getTime()&&t.seek(r);let i=Math.max(.1,Math.min(4,e));w(i),T();let a=r,o=performance.now(),l=e=>{let r=(e-o)/1e3*i,u=a-r,{inPoint:d,outPoint:f}=X.getState(),p=f===null?n:Math.min(f,n),g=d===null?0:d,_=g<p?p:n,v=g<p?g:0;if(u<=v)if(X.getState().loopEnabled&&n>0)a=_,o=e,u=_;else{t.seek(v),Lb.notify(v),h(v),m(!1),c.current=null,s.current=0;return}t.seek(Math.max(0,u)),Lb.notify(Math.max(0,u)),m(!0),s.current=requestAnimationFrame(l)};m(!0),c.current=`backward`,s.current=requestAnimationFrame(l)},[b,h,m,w,T,S,C]),O=(0,U.useCallback)(()=>{C();let e=b();e?.pause(),e&&h(e.getTime()),m(!1),c.current=null,l.current=0,S()},[b,h,m,S,C]),k=(0,U.useCallback)((e,t)=>{let r=c.current===`backward`;C();let i=b();if(!i)return a.current=Math.max(0,e),!1;let o=Math.max(0,i.getDuration()),s=YMe(e,o),u=t?.keepPlaying===!0,{playLocked:d,isPlaying:f}=X.getState(),p=vtn({keepPlaying:u,wasReverseShuttle:r,storeWasPlaying:f,duration:o,nextTime:s,playLocked:d});return i.seek(s,t),Dtn(s,t),h(s),!u&&!d&&Zen(n.current,s),p?(S(),w(X.getState().playbackRate),T(),i.play(),m(!0),c.current=`forward`,l.current=0,x()):ytn({keepPlaying:u,wasReverseShuttle:r})&&(S(),X.getState().isPlaying&&m(!1),c.current=null,l.current=0),!0},[b,a,h,m,x,S,C,w,T,c,l]);(0,U.useEffect)(()=>X.subscribe((e,t)=>{e.playLocked&&!t.playLocked&&e.isPlaying&&O()}),[O]),(0,U.useEffect)(()=>X.subscribe((e,t)=>{e.requestedSeekTime!==null&&e.requestedSeekTime!==t.requestedSeekTime&&(k(e.requestedSeekTime),X.getState().clearSeekRequest());let n=e.playbackRequest;n&&n.nonce!==t.playbackRequest?.nonce&&(n.playing?E():(O(),n.returnTo!==null&&k(n.returnTo,{follow:!1})),X.getState().clearPlaybackRequest())}),[k,E,O]),(0,U.useEffect)(()=>fVt(b),[b]);let{playbackKeyDownRef:A,playbackKeyUpRef:j,attachIframeShortcutListeners:M,togglePlay:N}=V5t({iframeRef:n,shuttleDirectionRef:c,shuttleSpeedIndexRef:l,iframeShortcutCleanupRef:u,getAdapter:b,play:E,playBackward:D,pause:O,seek:k}),{processTimelineMessageRef:P,enrichMissingCompositionsRef:F,onIframeLoad:I,cancelPendingLoad:L}=J7t({iframeRef:n,probeIntervalRef:i,pendingSeekRef:a,isRefreshingRef:o,getAdapter:b,syncTimelineElements:y,setDuration:g,setCurrentTime:h,requestTimelineReady:_,setIsPlaying:m,attachIframeShortcutListeners:M,applyPreviewAudioState:T}),{previewSlots:R,onShadowIframeLoad:z,onShadowReadyChange:B,onShadowError:V,setShadowIframeNode:ee,beginShadowReload:te,resetPreviewSlots:H,previewGeneration:ne}=Ken({iframeRef:n,getAdapter:b,pendingSeekRef:a,isRefreshingRef:o,syncTimelineElements:y,setDuration:g,setCurrentTime:h,requestTimelineReady:_,setIsPlaying:m,attachIframeShortcutListeners:M,applyPreviewAudioState:T,onPromoted:e,onReloadFailed:t,handOverPlayback:(e,t)=>{k(e,{keepPlaying:!0,follow:!1});let n=b();t&&n&&n.getTime()<n.getDuration()&&E()}}),re=(0,U.useCallback)(()=>{if(!(o.current&&a.current!=null)){let e=b();e?a.current=e.getTime():a.current??=X.getState().currentTime??0}o.current=!0;let e=X.getState().isPlaying&&c.current!==`backward`;return C(),e?!0:(S(),m(!1),!1)},[b,S,m,C]),ie=(0,U.useCallback)(e=>{re()||b()?.pause(),te(e)},[re,b,te]),ae=(0,U.useRef)(0),oe=(0,U.useRef)(null),se=(0,U.useCallback)(()=>{let e=n.current;if(!e)return;oe.current?.abort(Error(`superseded by a newer edit`));let t=new AbortController;oe.current=t,s2(`refreshPlayer`,()=>({stack:Error(`refreshPlayer`).stack}));let r=new URL(e.src,window.location.origin);r.searchParams.set(`_t`,String(Date.now())),GNe(r);let i=++ae.current,a=ne(),s=()=>i===ae.current&&a===ne(),c=Ven(e),l=!!e.contentDocument&&G0(e.contentDocument);if(!c||o.current||l)return ie(r.toString());m2(()=>c(r.toString(),s,t.signal)).catch(e=>{s()&&(s2(`scene-swap-refused`,{reason:String(e)}),ie(r.toString()))})},[ie,ne]),ce=(0,U.useRef)(O);ce.current=O,ax(()=>{let e=e=>A.current(e),t=e=>j.current(e),r=wtn({iframeRef:n,processTimelineMessageRef:P,enrichMissingCompositionsRef:F,lastTimelineMessageRef:d,getAdapter:b,syncTimelineElements:y}),i=()=>{document.hidden&&X.getState().isPlaying&&ce.current()};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`keyup`,t,!0),window.addEventListener(`message`,r),document.addEventListener(`visibilitychange`,i),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`keyup`,t,!0),u.current?.(),u.current=null,window.removeEventListener(`message`,r),document.removeEventListener(`visibilitychange`,i),S(),C(),G1(),ln(f,p),L()}});let le=(0,U.useCallback)(()=>{S(),C(),L(),X.getState().reset()},[S,C,L]);return(0,U.useEffect)(()=>X.subscribe((e,t)=>{let n=e.playbackRate!==t.playbackRate,r=e.audioMuted!==t.audioMuted,i=e.audioVolume!==t.audioVolume;!n&&!r&&!i||(n&&w(e.playbackRate),T())}),[w,T]),{iframeRef:n,play:E,pause:O,togglePlay:N,seek:k,onIframeLoad:I,refreshPlayer:se,saveSeekPosition:re,resetPlayer:le,previewSlots:R,onShadowIframeLoad:z,onShadowReadyChange:B,onShadowError:V,setShadowIframeNode:ee,resetPreviewSlots:H}}function ktn({projectId:e,activeCompositionPath:t,onCompositionChange:n}){let[r,i]=(0,U.useState)([{id:`master`,label:`Master`,previewUrl:M(e,`/preview`)}]),a=(0,U.useRef)(n);a.current=n;let o=(0,U.useRef)(0),s=(0,U.useRef)(null),c=(0,U.useRef)(e);c.current=e;let l=(0,U.useRef)(r),u=(0,U.useCallback)(e=>{let t=l.current,n=typeof e==`function`?e(t):e;l.current=n;let r=X.getState();t.length===1&&n.length>1?(o.current=r.isPlaying?Lb.latest():r.currentTime,s.current=c.current):n.length===1&&t.length>1&&s.current===c.current&&r.setCurrentTime(o.current),i(n);let u=n[n.length-1]?.id;queueMicrotask(()=>a.current?.(u===`master`?null:u))},[]),[d,f]=(0,U.useState)(new Map),p=(0,U.useRef)(d);p.current=d;let m=(0,U.useCallback)(e=>{X.getState().setElements([]),u(t=>t.slice(0,e+1))},[]),h=(0,U.useCallback)(t=>{if(!t.compositionSrc)return;let n=p.current.get(t.id)??t.compositionSrc,r=(Et(n)??n).replace(/^(\.\/|\/)+/,``);X.getState().setElements([]),u(t=>{if(t[t.length-1].id===r&&t.length>1)return t.slice(0,-1);let n=r.split(`/`).pop()?.replace(/\.html$/,``)||r,i=M(e,`/preview/comp/${N$(r)}`);return[...t,{id:r,label:n,previewUrl:i}]})},[e]);return(0,U.useEffect)(()=>{let n={id:`master`,label:`Master`,previewUrl:M(e,`/preview`)};if(t===`index.html`)X.getState().setElements([]),u([n]);else if(t){let r=t.replace(/^compositions\//,``).replace(/\.html$/,``),i=M(e,`/preview/comp/${N$(t)}`);X.getState().setElements([]),u(e=>e[e.length-1]?.id===t?e:[n,{id:t,label:r,previewUrl:i}])}else X.getState().setElements([]),u([n])},[t,e,u]),{compositionStack:r,updateCompositionStack:u,handleNavigateComposition:m,handleDrillDown:h,masterSeekRef:o,compIdToSrc:d,setCompIdToSrc:f}}var O2=gb(e=>({previewAsset:null,previewProjectId:null,setPreviewAsset:(t,n)=>e({previewAsset:t,previewProjectId:n}),clearPreviewAsset:()=>e({previewAsset:null,previewProjectId:null})}));function Atn(e){return e}var jtn=jG(`NLEContext`,null);function k2(){let e=(0,U.useContext)(jtn);if(!e)throw Error(`useNLEContext must be used within an NLEProvider`);return e}function Mtn({projectId:e,refreshKey:t,activeCompositionPath:n,onIframeRef:r,onCompositionChange:i,onCompIdToSrcChange:a,onCompositionLoadingChange:o,onPreviewReloadFailed:s,children:c}){let l=(0,U.useRef)(()=>{}),u=(0,U.useRef)(null),{iframeRef:d,play:f,pause:p,togglePlay:m,seek:h,onIframeLoad:g,refreshPlayer:_,previewSlots:v,onShadowIframeLoad:y,onShadowReadyChange:b,onShadowError:x,setShadowIframeNode:S,resetPreviewSlots:C}=Otn({onShadowPromoted:()=>l.current(),onPreviewReloadFailed:s});(0,U.useEffect)(()=>{X.getState().beginTimelineSession(e),O2.getState().clearPreviewAsset()},[e]);let[w,T]=(0,U.useState)(null),E=(0,U.useRef)(t);(0,U.useEffect)(()=>{try{if(t===E.current)return;E.current=t,_()}finally{Fen()}},[t,_]);let D=(0,U.useCallback)(()=>{IQt(d.current),r?.(d.current)},[d,r]);l.current=D;let O=(0,U.useCallback)(()=>{g(),D()},[g,D]),{compositionStack:k,updateCompositionStack:A,handleNavigateComposition:j,handleDrillDown:N,compIdToSrc:P,setCompIdToSrc:F}=ktn({projectId:e,activeCompositionPath:n,onCompositionChange:i}),I=d,L=(0,U.useCallback)(e=>{if(!e.compositionSrc)return;X.getState().setSelectedElementId(null);let t=e.id,n=P.get(t);if(!n)try{let e=I.current?.contentDocument;if(e){let r=e.querySelector(`[data-composition-id="${CSS.escape(t)}"][data-composition-src]`);r&&(n=r.getAttribute(`data-composition-src`)||void 0)}}catch{}N({id:t,compositionSrc:n??e.compositionSrc})},[P,N,I]),R=(0,U.useRef)(P);R.current=P;let z=(0,U.useRef)(a);z.current=a,(0,U.useEffect)(()=>{let t=new AbortController,n=!0,r=new Map;return F(r),bt(r),z.current?.(r),H(M(e,`/files/index.html`),{signal:t.signal}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{if(!n)return;let t=e.content||``,r=new Map,i=/data-composition-id=["']([^"']+)["'][^>]*data-composition-src=["']([^"']+)["']|data-composition-src=["']([^"']+)["'][^>]*data-composition-id=["']([^"']+)["']/g,a;for(;(a=i.exec(t))!==null;){let e=a[1]||a[4],t=a[2]||a[3];e&&t&&r.set(e,t)}F(r),bt(r),z.current?.(r)}).catch(e=>{!n||t.signal.aborted||console.warn(`[studio] Couldn't load composition source map from index.html:`,e)}),()=>{n=!1,t.abort()}},[e,F]),(0,U.useEffect)(()=>{if(P.size===0)return;let e=e=>{let t=R.current;if(t.size===0)return null;let n=!1,r=e.map(e=>{if(e.compositionSrc)return e;let r=t.get(e.id)??t.get(e.id.replace(/-(host|comp|layer)$/,``));return r?(n=!0,{...e,compositionSrc:r}):e});return n?r:null},t=e(X.getState().elements);t&&X.getState().setElements(t);let n=!1;return X.subscribe((t,r)=>{if(n||t.elements===r.elements||t.elements.length===0||t.elements.every(e=>e.compositionSrc))return;n=!0;let i=e(t.elements);i&&t.setElements(i),n=!1})},[P]);let B=(0,U.useRef)(!1),[V,ee]=(0,U.useState)(!0),te=(0,U.useCallback)(e=>{e||(B.current=!0),!(e&&B.current)&&ee(e)},[]),ne=Atn(V),re=X(e=>e.timelineSessionEpoch);(0,U.useEffect)(()=>{o?.(V)},[V,o]);let ie=(0,U.useRef)(r);ie.current=r,(0,U.useEffect)(()=>{ie.current?.(d.current)},[k.length,t,d]);let ae={projectId:e,iframeRef:d,play:f,pause:p,containerRef:u,togglePlay:m,seek:h,refreshPlayer:_,onIframeLoad:O,previewSlots:v,onShadowIframeLoad:y,onShadowReadyChange:b,onShadowError:x,setShadowIframeNode:S,resetPreviewSlots:C,compositionStack:k,updateCompositionStack:A,handleNavigateComposition:j,handleDrillDown:L,compIdToSrc:P,compositionLoading:V,setCompositionLoading:te,timelineDisabled:ne,timelineSessionEpoch:re,hasLoadedOnceRef:B,previewCompositionSize:w,setPreviewCompositionSize:T};return(0,W.jsx)(jtn.Provider,{value:ae,children:c})}function Ntn(e){try{let t=e?.contentDocument,n=t?.querySelector(`[data-composition-id][data-width][data-height]`)??t?.querySelector(`[data-width][data-height]`);if(!n)return null;let r=Number.parseInt(n.getAttribute(`data-width`)??``,10),i=Number.parseInt(n.getAttribute(`data-height`)??``,10);return!Number.isFinite(r)||r<=0||!Number.isFinite(i)||i<=0?null:{width:r,height:i}}catch{return null}}var Ptn=25,Ftn=400,Itn=`[data-preview-pan-surface="true"]`,A2=48,j2={zoomPercent:100,panX:0,panY:0},Ltn=.007,Rtn=10,ztn=e=>Math.abs(e-100)<.5;function M2(e){return ztn(e.zoomPercent)&&Math.abs(e.panX)<.1&&Math.abs(e.panY)<.1}function N2(e){return Math.round(e*1e4)/1e4}function P2(e){return Number.isFinite(e)?Math.min(Ftn,Math.max(Ptn,e)):100}function Btn(e){return e===1}function F2(e,t){return e instanceof Element?t?.contains(e)?!0:!!e.closest(Itn):!1}function Vtn(e,t){if(!Number.isFinite(e))return P2(t);let n=-(Math.abs(e)>Rtn?Rtn*Math.sign(e):e)*Ltn;return P2(P2(t)*Math.exp(n))}function I2(e){let t=P2(e.zoomPercent)/100,n=e.contentWidth??e.viewportWidth,r=e.contentHeight??e.viewportHeight,i=Math.max(0,(n*t-e.viewportWidth)/2)+A2,a=Math.max(0,(r*t-e.viewportHeight)/2)+A2;return{panX:Math.min(i,Math.max(-i,e.panX)),panY:Math.min(a,Math.max(-a,e.panY))}}function Htn(e,t,n,r,i,a,o){let s=P2(n)/100,c=Math.abs(a*s-r)/2+A2,l=Math.abs(o*s-i)/2+A2;return{panX:Math.min(c,Math.max(-c,e)),panY:Math.min(l,Math.max(-l,t))}}function Utn(e){let t=P2(e.state.zoomPercent),n=Vtn(e.deltaY,t),r=t/100,i=n/100,a=e.state.panX,o=e.state.panY;if(e.cursorX!==void 0&&e.cursorY!==void 0){let t=i/r;a=e.cursorX*(1-t)+a*t,o=e.cursorY*(1-t)+o*t}let s=e.contentWidth??e.viewportWidth,c=e.contentHeight??e.viewportHeight;return{zoomPercent:n,...Htn(a,o,n,e.viewportWidth,e.viewportHeight,s,c)}}function Wtn(e){let t=I2({panX:e.state.panX-e.deltaX,panY:e.state.panY-e.deltaY,zoomPercent:e.state.zoomPercent,viewportWidth:e.viewportWidth,viewportHeight:e.viewportHeight,contentWidth:e.contentWidth,contentHeight:e.contentHeight});return{zoomPercent:P2(e.state.zoomPercent),...t}}function Gtn(e){let t=P2(e.state.zoomPercent)/100,n=(e,n,r)=>{let i=r*t;if(!(i>0))return[0,1];let a=t=>Math.min(1,Math.max(0,(t-e+i/2)/i)),o=a(-n/2);return[o,a(n/2)-o]},[r,i]=n(e.state.panX,e.viewportWidth,e.contentWidth),[a,o]=n(e.state.panY,e.viewportHeight,e.contentHeight);return{left:r,top:a,width:i,height:o}}var L2=16,R2=gb((e,t)=>{let n=Ub();return{rulerVisible:n.rulerVisible??!1,safeMarginsVisible:n.safeMarginsVisible??!1,toggle:n=>{let r=!t()[n];Wb({[n]:r}),e({[n]:r})}}}),z2=112;function Ktn(e){return ztn(e)?`Panned`:`Zoomed ${Math.round(e)}%`}function qtn(e){let t=e.width>0&&e.height>0?e.width/e.height:16/9;return t>=1?{width:z2,height:N2(z2/t)}:{width:N2(z2*t),height:z2}}function Jtn(e,t,n){let r=(0,U.useRef)(null),i=(0,U.useRef)(t);i.current=t;let a=(0,U.useCallback)(t=>{let n=r.current,a=e.current?.getBoundingClientRect();if(!n||!a)return;let o=Gtn({state:t,viewportWidth:a.width,viewportHeight:a.height,contentWidth:i.current.width,contentHeight:i.current.height});n.style.left=`${o.left*100}%`,n.style.top=`${o.top*100}%`,n.style.width=`${o.width*100}%`,n.style.height=`${o.height*100}%`},[e]),o=(0,U.useCallback)(e=>{r.current=e,a(n.current)},[a,n]);return(0,U.useEffect)(()=>a(n.current),[t,a,n]),{draw:a,setRegion:o}}function Ytn({zoom:e,stageSize:t,onFit:n,navigatorRegionRef:r}){return M2(e)?null:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`absolute top-3 left-1/2 -translate-x-1/2 z-50 flex items-center gap-1.5 rounded-md py-1 pl-2.5 pr-1 text-xs text-white/80 bg-black/60 backdrop-blur-xs`,"data-testid":`preview-zoom-chip`,onPointerDown:e=>e.stopPropagation(),children:[(0,W.jsx)(`span`,{className:`tabular-nums`,children:Ktn(e.zoomPercent)}),(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`text-white/30`,children:`·`}),(0,W.jsx)(`button`,{type:`button`,className:`rounded px-1.5 py-0.5 font-medium text-accent-ink hover:bg-white/10 transition-colors`,onClick:n,"aria-label":`Fit the whole frame in view`,"data-testid":`preview-zoom-fit`,children:`Fit`})]}),(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute bottom-3 right-3 z-50 rounded-md p-1.5 bg-black/60 backdrop-blur-xs`,"data-testid":`preview-zoom-navigator`,children:(0,W.jsx)(`div`,{className:`relative overflow-hidden bg-white/10`,style:qtn(t),children:(0,W.jsx)(`div`,{ref:r,className:`absolute rounded-[1px] border border-studio-accent bg-studio-accent/15`,"data-testid":`preview-zoom-navigator-region`})})})]})}function Xtn(e){if(!e)return{clip_count:0,media_clip_count:0};let t=q1(e,nn(e));return{clip_count:t.length,media_clip_count:t.filter(({tag:e})=>e===`video`||e===`audio`).length}}function Ztn(e){let t=(0,U.useRef)(e);t.current=e;let n=(0,U.useRef)(new Set);return(0,U.useCallback)((e,{iframe:r,startedAt:i,loadId:a})=>{if(!t.current.find(t=>t.gen===e.gen&&t.role===e.role))return;let o=`${e.role}:${e.gen}:${a}`;if(n.current.has(o))return;n.current.add(o);let s=Xtn(r.contentDocument);hWt({duration_ms:Math.max(0,Math.round(performance.now()-i)),composition_seconds:nn(r.contentDocument),...s,studio_version:tWt().studio_version})},[])}function Qtn(e,t){return M(e,`/thumbnail/index.html?${`t=0&output=source${t?`&cached=1`:``}`}`)}var $tn={position:`absolute`,inset:0,width:`100%`,height:`100%`,objectFit:`contain`,zIndex:2,pointerEvents:`none`};function enn({projectId:e,hidden:t,onSize:n,onLoaded:r,onMissing:i}){return(0,W.jsx)(`img`,{src:Qtn(e,!0),alt:``,"aria-hidden":!0,"data-testid":`preview-poster`,hidden:t,style:$tn,onLoad:e=>{let{naturalWidth:i,naturalHeight:a}=e.currentTarget;!t&&i>0&&a>0&&n({width:i,height:a}),r()},onError:i})}function tnn(e,t,n){let r=rnn(t),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null),c=(0,U.useRef)(null),l=(0,U.useRef)(null),u=(0,U.useCallback)(()=>{c.current===r&&l.current===r&&(c.current=null,nnn(e))},[r,e]),d=(0,U.useCallback)(e=>{e&&(a(r),l.current=r,u())},[r,u]);return{mountPoster:!n&&(i!==r||o!==r),hidePoster:i===r,onLiveReadyToShowChange:d,onPreviewError:()=>a(r),onPosterLoaded:()=>s(r),onPosterMissing:()=>{a(r),s(r),c.current=r,u()}}}function nnn(e){let t=Qtn(e,!1),n={key:qX({kind:`poster-render`,url:t}),projectId:e,sessionEpoch:0,kind:`composition`,priority:`overscan`,discardWhenReleased:!0,load:async e=>(await(await H(t,{signal:e})).arrayBuffer(),{value:{kind:`image`,url:t,aspect:16/9},weight:0})},r=()=>[`ready`,`error`].includes(YX.getSnapshot(n).status),i=null;i=YX.acquire(n,()=>{r()&&i?.release()}),r()&&i.release()}function rnn(e){let[t,n]=(0,U.useState)({key:e,visit:0});return t.key===e?t.visit:(n({key:e,visit:t.visit+1}),t.visit+1)}function inn({projectId:e,directUrl:t}){return t??e}var ann=1200,onn=200,snn=8,cnn={position:`absolute`,inset:0,visibility:`hidden`,clipPath:`inset(100%)`,pointerEvents:`none`};function lnn(e,t,n,r,i=0,a=snn){let o=Math.max(0,e-2*(a+i)),s=Math.max(0,t-2*(a+i)),c=n&&n.width>0&&n.height>0?n.width/n.height:r?9/16:16/9;if(o===0||s===0)return{width:0,height:0};let l=o,u=l/c;return u>s&&(u=s,l=u*c),{width:N2(l),height:N2(u)}}var unn=(0,U.memo)(function({projectId:e,iframeRef:t,onIframeLoad:n,previewSlots:r,onShadowIframeLoad:i,onShadowReadyChange:a,onShadowError:o,setShadowIframeNode:s,resetPreviewSlots:c,onCompositionLoadingChange:l,portrait:u,directUrl:d,suppressLoadingOverlay:f,onStageRef:p,onCompositionSizeChange:m,fillBox:h,compositionSizeHint:g}){let _=inn({projectId:e,directUrl:d}),v=(0,U.useRef)(null),y=(0,U.useRef)(null),b=(0,U.useRef)(null);(0,U.useEffect)(()=>{p?.(y)},[p]);let x=(0,U.useRef)(_);(0,U.useEffect)(()=>{x.current!==_&&(x.current=_,c())},[_,c]);let S=(0,U.useRef)(null),C=Ztn(r),[w,T]=(0,U.useState)(null),E=tnn(e,_,d),D=R2(e=>e.rulerVisible?L2:0),O=h?0:snn,[k,A]=(0,U.useState)(()=>lnn(0,0,null,u)),j=g?.width,M=g?.height,N=(0,U.useRef)(j2),[P,F]=(0,U.useState)(j2),I=(0,U.useRef)(null),L=(0,U.useRef)(null),R=(0,U.useRef)(null),z=(0,U.useRef)(!1),B=(0,U.useRef)(null);(0,U.useEffect)(()=>()=>{R.current&&clearTimeout(R.current),L.current&&clearTimeout(L.current)},[]),(0,U.useEffect)(()=>{let e=v.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect();A(lnn(t.width,t.height,w??(j&&M?{width:j,height:M}:null),u,D,O))};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[w,j,M,u,D,O]);let V=(0,U.useRef)(m);V.current=m;let ee=(0,U.useCallback)(()=>{let e=Ntn(b.current);T(t=>t?.width===e?.width&&t?.height===e?.height?t:e)},[]);(0,U.useEffect)(()=>{V.current?.(w)},[w]);let te=(0,U.useCallback)(e=>{b.current=e,t.current=e},[t]),H=(0,U.useRef)(k);H.current=k;let{draw:ne,setRegion:re}=Jtn(v,k,N),ie=(0,U.useCallback)(e=>{let t=y.current;if(!t)return;let n=N2(e.zoomPercent/100),r=N2(e.panX),i=N2(e.panY);t.style.transform=`translate3d(${r}px, ${i}px, 0) scale(${n})`,ne(e)},[ne]),ae=(0,U.useRef)(e);(0,U.useLayoutEffect)(()=>{ae.current!==e&&(ae.current=e,N.current=j2,ie(j2),F(j2))},[e,ie]);let oe=(0,U.useCallback)((e,t)=>{let n={zoomPercent:P2(e.zoomPercent),panX:Number.isFinite(e.panX)?e.panX:0,panY:Number.isFinite(e.panY)?e.panY:0};if(N.current=n,t){let e=I.current;e&&(z.current||(z.current=!0,e.style.opacity=`1`),e.textContent=M2(n)?`Fit`:`${Math.round(n.zoomPercent)}%`)}ie(n),R.current&&clearTimeout(R.current),R.current=setTimeout(()=>{z.current=!1;let e=N.current;if(F(t=>t.zoomPercent===e.zoomPercent&&t.panX===e.panX&&t.panY===e.panY?t:e),t){let t=I.current;t&&(t.textContent=M2(e)?`Fit`:`${Math.round(e.zoomPercent)}%`,L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{I.current&&(I.current.style.opacity=`0`)},ann))}},onn)},[ie]),se=(0,U.useCallback)(e=>oe(e,!0),[oe]),ce=(0,U.useCallback)(e=>oe(e,!1),[oe]),le=(0,U.useCallback)(()=>{let e=N.current;if(!M2(e)){let t=v.current?.getBoundingClientRect(),n=H.current;if(t&&t.width>0&&t.height>0&&n.width>0&&n.height>0){let r=I2({panX:e.panX,panY:e.panY,zoomPercent:e.zoomPercent,viewportWidth:t.width,viewportHeight:t.height,contentWidth:n.width,contentHeight:n.height});N.current={...e,...r}}ie(N.current)}},[ie]);(0,U.useEffect)(()=>{let e=r.find(e=>e.role===`live`);if(!e||e.gen===S.current)return;let n=S.current!==null;S.current=e.gen,n&&(b.current=t.current,ee(),le())},[r,t,ee,le]),(0,U.useEffect)(()=>{let e=v.current;if(!e)return;let t=t=>{let n=e.getBoundingClientRect();if(t.clientX<n.left||t.clientX>n.right||t.clientY<n.top||t.clientY>n.bottom)return;if(t.ctrlKey||t.metaKey){t.preventDefault(),t.stopPropagation();let e=H.current,r=t.clientX-(n.left+n.width/2),i=t.clientY-(n.top+n.height/2),a=Utn({state:N.current,deltaY:t.deltaY,viewportWidth:n.width,viewportHeight:n.height,contentWidth:e.width,contentHeight:e.height,cursorX:r,cursorY:i});se(a);return}if(!F2(t.target,y.current))return;t.preventDefault(),t.stopPropagation();let r=H.current,i=Wtn({state:N.current,deltaX:t.deltaX,deltaY:t.deltaY,viewportWidth:n.width,viewportHeight:n.height,contentWidth:r.width,contentHeight:r.height});ce(i)};return document.addEventListener(`wheel`,t,{passive:!1,capture:!0}),()=>document.removeEventListener(`wheel`,t,{capture:!0})},[se,ce]),(0,U.useEffect)(()=>{let e=(e,t)=>{let n=v.current;if(!n)return null;let r=n.getBoundingClientRect();return e<r.left||e>r.right||t<r.top||t>r.bottom?null:r},t=t=>{e(t.clientX,t.clientY)&&F2(t.target,y.current)&&Btn(t.button)&&(t.preventDefault(),B.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,originX:N.current.panX,originY:N.current.panY})},n=e=>{let t=B.current,n=v.current;if(!t||!n||t.pointerId!==e.pointerId)return;e.preventDefault();let r=n.getBoundingClientRect(),i=H.current,a=I2({panX:t.originX+e.clientX-t.startX,panY:t.originY+e.clientY-t.startY,zoomPercent:N.current.zoomPercent,viewportWidth:r.width,viewportHeight:r.height,contentWidth:i.width,contentHeight:i.height});ce({...N.current,...a})},r=e=>{B.current?.pointerId===e.pointerId&&(B.current=null)},i=t=>{t.button===1&&e(t.clientX,t.clientY)&&F2(t.target,y.current)&&t.preventDefault()};return document.addEventListener(`pointerdown`,t,{capture:!0}),document.addEventListener(`pointermove`,n,{capture:!0}),document.addEventListener(`pointerup`,r,{capture:!0}),document.addEventListener(`pointercancel`,r,{capture:!0}),document.addEventListener(`auxclick`,i,{capture:!0}),()=>{document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,n,{capture:!0}),document.removeEventListener(`pointerup`,r,{capture:!0}),document.removeEventListener(`pointercancel`,r,{capture:!0}),document.removeEventListener(`auxclick`,i,{capture:!0})}},[ce]);let ue=N.current;return(0,W.jsx)(`div`,{className:`flex flex-col h-full min-h-0`,children:(0,W.jsxs)(`div`,{ref:v,className:`relative flex-1 flex items-center justify-center overflow-hidden min-h-0 outline-hidden focus:ring-1 focus:ring-studio-accent/40 bg-[var(--studio-preview-bg,var(--color-neutral-950))]`,tabIndex:0,"aria-label":`Composition preview`,children:[(0,W.jsx)(`div`,{className:`absolute flex items-center justify-center pointer-events-none`,style:{inset:O},children:(0,W.jsxs)(`div`,{ref:y,className:`relative shrink-0 pointer-events-auto`,style:{width:`${k.width}px`,height:`${k.height}px`,transform:`translate3d(${N2(ue.panX)}px, ${N2(ue.panY)}px, 0) scale(${N2(ue.zoomPercent/100)})`,transformOrigin:`center center`},"data-testid":`preview-zoom-stage`,children:[d?.includes(`/components/`)&&(0,W.jsx)(lx,{projectId:e,onLoad:()=>{},portrait:u,suppressLoadingOverlay:!0,style:{position:`absolute`,inset:0,zIndex:0}},`backdrop-${e}`),r.map(t=>t.role===`live`?(0,W.jsx)(lx,{ref:te,projectId:d?void 0:e,directUrl:d,onLoad:()=>{ee(),n(),le()},onCompositionLoadingChange:l,onReadyToShowChange:E.onLiveReadyToShowChange,onPreviewError:E.onPreviewError,onPainted:e=>C(t,e),portrait:u,suppressLoadingOverlay:f,style:d?.includes(`/components/`)?{position:`absolute`,inset:0,zIndex:1}:void 0},`${_}-${t.gen}`):(0,W.jsx)(lx,{ref:s,directUrl:t.url,onLoad:()=>i(t.gen),onReadyToShowChange:e=>a(t.gen,e),onPainted:e=>C(t,e),onPreviewError:e=>o(t.gen,e),portrait:u,suppressLoadingOverlay:!0,style:cnn},`${_}-${t.gen}`)),E.mountPoster&&(0,W.jsx)(enn,{projectId:e,hidden:E.hidePoster,onSize:e=>T(t=>t??e),onLoaded:E.onPosterLoaded,onMissing:E.onPosterMissing},_)]})}),(0,W.jsx)(`div`,{ref:I,className:`pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 z-50 rounded-lg px-4 py-2 text-sm font-mono tabular-nums text-white/90 bg-black/60 backdrop-blur-xs shadow-lg`,style:{opacity:0,transition:`opacity 200ms ease-in`},"aria-live":`polite`}),(0,W.jsx)(Ytn,{zoom:P,stageSize:k,onFit:()=>{se(j2),v.current?.focus()},navigatorRegionRef:re})]})})});function dnn({stack:e,onNavigate:t}){return e.length<=1?null:(0,W.jsxs)(`nav`,{"aria-label":`Composition navigation`,className:`flex items-center gap-1 px-2 h-8 border-b border-hairline bg-bg-1 shrink-0`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>{mG(`navigation`,{action:`back`,target:e[e.length-2]?.label}),t(e.length-2)},className:`flex items-center gap-1 px-1.5 py-0.5 rounded-sm text-xs text-text-3 hover:text-text-0 hover:bg-hover active:scale-[0.98] transition-colors`,title:`Back (Esc, or double-click empty timeline)`,"aria-label":`Back to parent composition`,children:(0,W.jsx)(t5e,{size:12,weight:`bold`})}),e.map((n,r)=>{let i=r===e.length-1;return(0,W.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,W.jsx)(y5e,{size:10,className:`text-text-4 shrink-0`}),i?(0,W.jsx)(`span`,{className:`text-xs text-text-1 font-medium`,children:n.label}):(0,W.jsx)(`button`,{type:`button`,onClick:()=>{mG(`navigation`,{action:`breadcrumb`,target:n.label}),t(r)},className:`text-xs text-text-3 hover:text-text-1 transition-colors`,children:n.label})]},n.id)})]})}var fnn=`Preview is read-only.`,B2=jG(`PreviewReadOnlyContext`,{readOnly:!1,reason:fnn});function pnn({readOnly:e,reason:t,children:n}){let r=(0,U.useMemo)(()=>({readOnly:e,reason:t??fnn}),[e,t]);return(0,W.jsx)(B2,{value:r,children:n})}function V2(){return(0,U.useContext)(B2).readOnly}function mnn(){return(0,U.useContext)(B2).reason}function hnn(e,t={x:0,y:0}){let{readOnly:n}=(0,U.useContext)(B2),r=!Number.isFinite(t.x)||!Number.isFinite(t.y);return{manualOffsetEditingDisabled:!e?.canApplyManualOffset||n||r,manualSizeEditingDisabled:!e?.canApplyManualSize||n,manualRotationEditingDisabled:!e?.canApplyManualRotation||n}}function gnn(e){try{let t=JSON.parse(e);return t.name?t:null}catch{return null}}function _nn(e,t,n,r,i){if(n.width===0||n.height===0)return null;let a=(e-n.left)/n.width,o=(t-n.top)/n.height,s=r?.width??(i?1080:1920),c=r?.height??(i?1920:1080);return{left:Math.max(0,Math.min(a*s,s)),top:Math.max(0,Math.min(o*c,c))}}function vnn(e,t){let n=t.dimensions?.width??0,r=t.dimensions?.height??0;return{left:Math.max(0,e.left-n/2),top:Math.max(0,e.top-r/2)}}function ynn({portrait:e,compositionSize:t,stageRef:n,onBlockDrop:r}){let i=V2()?void 0:r,[a,o]=(0,U.useState)(!1),s=(0,U.useRef)(0);return{isDragOver:a,handleDragEnter:(0,U.useCallback)(e=>{i&&e.dataTransfer.types.includes(fq)&&(s.current+=1,o(!0))},[i]),handleDragOver:(0,U.useCallback)(e=>{i&&e.dataTransfer.types.includes(fq)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},[i]),handleDragLeave:(0,U.useCallback)(()=>{s.current=Math.max(0,s.current-1),s.current===0&&o(!1)},[]),handleDrop:(0,U.useCallback)(r=>{if(s.current=0,o(!1),!i)return;let a=r.dataTransfer.getData(fq);if(!a)return;r.preventDefault();let c=gnn(a),l=n.current;if(!c||!l)return;let u=_nn(r.clientX,r.clientY,l.getBoundingClientRect(),t,e);u&&i(c.name,vnn(u,c))},[i,n,t,e])}}var bnn=1e-6;function xnn(e,t){return t.isPlaying||t.requestedSeekTime!==null?!0:Math.abs(t.currentTime-e)>bnn}function Snn(e){return e.split(`/`).pop()??e}function Cnn(e){return iq.test(e)?`video`:rq.test(e)?`image`:`audio`}function wnn({kind:e,serveUrl:t,name:n}){return e===`image`?(0,W.jsx)(`img`,{src:t,alt:n,className:`max-w-full max-h-[40vh] rounded-sm object-contain`}):e===`video`?(0,W.jsx)(`video`,{src:t,controls:!0,autoPlay:!0,muted:!0,playsInline:!0,className:`max-w-full max-h-[40vh] rounded-sm`}):(0,W.jsxs)(`div`,{className:`flex flex-col items-center gap-3 px-6 py-4`,children:[(0,W.jsxs)(`svg`,{width:`40`,height:`40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,className:`text-neutral-500`,children:[(0,W.jsx)(`path`,{d:`M9 18V5l12-2v13`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,W.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]}),(0,W.jsx)(`audio`,{src:t,controls:!0,className:`w-64`})]})}function Tnn(){let e=O2(e=>e.previewAsset),t=O2(e=>e.previewProjectId),n=O2(e=>e.clearPreviewAsset),r=(0,U.useCallback)(e=>{e.key===`Escape`&&n()},[n]);if((0,U.useEffect)(()=>{if(e)return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[e,r]),(0,U.useEffect)(()=>{if(!e)return;let t=X.getState(),r=t.currentTime;if(xnn(r,t)){n();return}return X.subscribe(e=>{xnn(r,e)&&n()})},[e,n]),!e||!t)return null;let i=P$(e,t),a=Snn(e);return(0,W.jsx)(`div`,{className:`absolute inset-0 z-50 flex flex-col items-center justify-center bg-black/20`,onClick:n,role:`dialog`,"aria-label":`Preview: ${a}`,children:(0,W.jsxs)(`div`,{className:`relative flex flex-col items-center gap-2 max-w-[58%] rounded-lg border border-neutral-800 bg-neutral-950/95 p-2 pt-8 shadow-2xl`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(`button`,{className:`absolute top-2 right-2 w-6 h-6 rounded-full bg-raised hover:bg-press text-text-2 hover:text-text-0 flex items-center justify-center transition-colors z-10`,onClick:e=>{e.stopPropagation(),n()},"aria-label":`Close preview`,children:(0,W.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,stroke:`currentColor`,strokeWidth:`2.5`,fill:`none`,strokeLinecap:`round`,children:[(0,W.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,W.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})}),(0,W.jsx)(wnn,{kind:Cnn(e),serveUrl:i,name:a}),(0,W.jsx)(`span`,{className:`text-[12px] text-neutral-400 truncate max-w-full px-2 text-center`,children:a})]})})}var Enn=400,Dnn=250,H2=new Set,U2=null,W2=null,G2=0,K2=!1,q2=null,Onn=[`pointerdown`,`pointermove`,`pointerup`,`wheel`,`keydown`,`keyup`,`scroll`,`resize`,`visibilitychange`],knn=null,Ann=null;function jnn(e){return typeof window>`u`||e.origin===window.location.origin}function Mnn(e){return typeof e!=`object`||!e?!1:e.source===`hf-preview`}function Nnn(e){if(e.type!==`state`)return null;let t=e.frame;return{frame:typeof t==`number`?t:null,playing:e.isPlaying===!0}}function Pnn(e){if(!jnn(e))return;let t=e.data;if(!Mnn(t))return;let n=Nnn(t);if(n){if(n.frame===knn&&n.playing===Ann)return;knn=n.frame,Ann=n.playing}Y2()}function Fnn(){if(U2=null,Inn(),X.getState().previewBooted)for(let e of H2)try{e()}catch(e){queueMicrotask(()=>{throw e})}}function Inn(){if(H2.size!==0&&U2==null&&W2==null){if(performance.now()<G2){U2=requestAnimationFrame(Fnn);return}W2=setTimeout(()=>{W2=null,U2=requestAnimationFrame(Fnn)},Dnn)}}var Lnn=3;function J2(e){let t=G2-performance.now();if(t>0){setTimeout(()=>J2(e),t);return}(window.requestIdleCallback??(e=>setTimeout(e,0)))(()=>{let t=performance.now()+Lnn;(performance.now()<G2||!e(()=>t-performance.now()))&&J2(e)})}function Y2(){G2=performance.now()+Enn,W2!=null&&(clearTimeout(W2),W2=null),Inn()}function Rnn(){if(!(K2||typeof window>`u`)){K2=!0;for(let e of Onn)window.addEventListener(e,Y2,{capture:!0,passive:!0});window.addEventListener(`message`,Pnn,{capture:!0,passive:!0}),q2=X.subscribe((e,t)=>{e.previewBooted&&!t.previewBooted&&Y2()})}}function znn(){if(!(!K2||typeof window>`u`)){K2=!1;for(let e of Onn)window.removeEventListener(e,Y2,{capture:!0});window.removeEventListener(`message`,Pnn,{capture:!0}),q2?.(),q2=null}}function X2(e){return H2.add(e),Rnn(),Y2(),()=>{H2.delete(e),!(H2.size>0)&&(U2!=null&&(cancelAnimationFrame(U2),U2=null),W2!=null&&(clearTimeout(W2),W2=null),znn())}}function Bnn(e,t){let n=n=>Math.abs(e[n]-t[n]);return n(`left`)<.5&&n(`top`)<.5&&n(`width`)<.5&&n(`height`)<.5&&n(`scaleX`)<.001&&n(`scaleY`)<.001}function Z2({iframeRef:e,overlayRef:t}){let[n,r]=(0,U.useState)({left:0,top:0,width:0,height:0,scaleX:1,scaleY:1});return ax(()=>X2(()=>{let n=e.current,i=t.current;if(!n||!i)return;let a=n.getBoundingClientRect(),o=i.getBoundingClientRect(),s=a.left-o.left,c=a.top-o.top;if(a.width<=0||a.height<=0)return;let l=n.contentDocument,u=l?.querySelector(`[data-composition-id]`)??l?.documentElement,d=Number.parseFloat(u?.getAttribute(`data-width`)??``),f=Number.parseFloat(u?.getAttribute(`data-height`)??``),p=d>0?a.width/d:1,m=f>0?a.height/f:1,h={left:s,top:c,width:a.width,height:a.height,scaleX:p,scaleY:m};r(e=>Bnn(e,h)?e:h)})),n}var Vnn=[90,80];function Hnn(e){return(100-e)/2}function Unn(e,t){let n=(0,U.useRef)(t);return n.current=t,(0,U.useEffect)(()=>{Y2()},[t]),Z2({iframeRef:n,overlayRef:e})}var Wnn=(0,U.createContext)(null);function Gnn(){let e=Ub();return{snapEnabled:e.snapEnabled??!0,gridVisible:e.gridVisible??!1,gridSpacing:e.gridSpacing??50,snapToGrid:e.snapToGrid??!1}}function Knn({iframe:e,children:t}){let n=(0,U.useRef)(null),[r,i]=(0,U.useState)(Gnn),a=R2(e=>e.rulerVisible),o=R2(e=>e.safeMarginsVisible),s=xZ(),c=e??s,l=(0,U.useRef)(c);l.current=c;let u={state:{snapPrefs:r,rulerVisible:a,safeMarginsVisible:o,iframeRef:l,compositionRect:Unn(n,c)},actions:{setSnapPrefs:e=>{Wb(e),i(t=>({...t,...e}))},toggleRulers:()=>R2.getState().toggle(`rulerVisible`),toggleSafeMargins:()=>R2.getState().toggle(`safeMarginsVisible`)}};return(0,W.jsx)(Wnn.Provider,{value:u,children:(0,W.jsx)(`div`,{ref:n,className:`pointer-events-none absolute inset-0`,children:t})})}function Q2(){let e=(0,U.useContext)(Wnn);if(!e)throw Error(`usePreviewOverlayContext must be used within PreviewOverlayProvider`);return e}var qnn=Array.from({length:11},(e,t)=>t*10),$2=`color-mix(in srgb, white 70%, transparent)`,Jnn=(0,U.memo)(function(){let{state:e}=Q2(),{rulerVisible:t,safeMarginsVisible:n}=e;return!t&&!n?null:(0,W.jsx)(Ynn,{iframeRef:e.iframeRef,rulerVisible:t,safeMarginsVisible:n})});function Ynn({iframeRef:e,rulerVisible:t,safeMarginsVisible:n}){let r=(0,U.useRef)(null),i=Z2({iframeRef:e,overlayRef:r}),a=i.width>0&&i.height>0;return(0,W.jsxs)(`div`,{ref:r,"aria-hidden":`true`,className:`pointer-events-none absolute inset-0 z-20`,children:[a&&t&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{"data-testid":`preview-ruler-top`,className:`absolute bg-black/70`,style:{left:i.left,top:i.top-L2,width:i.width,height:L2},children:qnn.map(e=>(0,W.jsx)(`span`,{className:`absolute bottom-0 border-l text-[9px] leading-none tabular-nums pl-0.5 h-2.5`,style:{left:`${e}%`,borderColor:$2,color:$2},children:e},e))}),(0,W.jsx)(`div`,{"data-testid":`preview-ruler-left`,className:`absolute bg-black/70`,style:{left:i.left-L2,top:i.top,width:L2,height:i.height},children:qnn.map(e=>(0,W.jsx)(`span`,{className:`absolute right-0 border-t text-[9px] leading-none tabular-nums pt-0.5 w-2.5`,style:{top:`${e}%`,borderColor:$2,color:$2},children:e},e))})]}),a&&n&&(0,W.jsx)(`div`,{className:`absolute`,style:{left:i.left,top:i.top,width:i.width,height:i.height},children:Vnn.map(e=>(0,W.jsx)(Znn,{boxPercent:e},e))})]})}var e4=7,Xnn=[{edge:`top`,style:{left:`50%`,top:-(e4+1)/2,width:1,height:e4}},{edge:`bottom`,style:{left:`50%`,bottom:-(e4+1)/2,width:1,height:e4}},{edge:`left`,style:{top:`50%`,left:-(e4+1)/2,width:e4,height:1}},{edge:`right`,style:{top:`50%`,right:-(e4+1)/2,width:e4,height:1}}];function Znn({boxPercent:e}){let t=`${Hnn(e)}%`;return(0,W.jsx)(`div`,{"data-testid":`preview-safe-${e}`,className:`absolute border border-white/90`,style:{left:t,top:t,right:t,bottom:t},children:Xnn.map(({edge:e,style:t})=>(0,W.jsx)(`span`,{className:`absolute bg-white/90`,style:t},e))})}function Qnn(e){return document.addEventListener(`fullscreenchange`,e),()=>document.removeEventListener(`fullscreenchange`,e)}function $nn(){return document.fullscreenElement}function ern(e,t,n){let r=t?.parentElement??t;if(!r)return;let i=r.getBoundingClientRect();(e.clientX<i.left||e.clientX>i.right||e.clientY<i.top||e.clientY>i.bottom)&&n?.(null)}function trn({portrait:e,previewOverlay:t,onSelectTimelineElement:n,onPreviewBlockDrop:r}){let{projectId:i,iframeRef:a,togglePlay:o,seek:s,onIframeLoad:c,previewSlots:l,onShadowIframeLoad:u,onShadowReadyChange:d,onShadowError:f,setShadowIframeNode:p,resetPreviewSlots:m,compositionStack:h,handleNavigateComposition:g,setCompositionLoading:_,timelineDisabled:v,hasLoadedOnceRef:y,previewCompositionSize:b,setPreviewCompositionSize:x}=k2(),S=(0,U.useRef)(null),C=(0,U.useCallback)(e=>{S.current=e.current},[]),{isDragOver:w,handleDragEnter:T,handleDragOver:E,handleDragLeave:D,handleDrop:O}=ynn({portrait:e,compositionSize:b,stageRef:S,onBlockDrop:r}),k=(0,U.useRef)(null),A=(0,U.useSyncExternalStore)(Qnn,$nn),j=A===k.current&&A!=null,M=(0,U.useCallback)(()=>{k.current&&(document.fullscreenElement?document.exitFullscreen():k.current.requestFullscreen())},[]),N=h[h.length-1],P=h.length>1?N.previewUrl:void 0;return(0,W.jsxs)(`div`,{ref:k,className:`scheme-dark flex-1 min-h-0 flex flex-col overflow-hidden bg-[var(--studio-preview-bg,var(--color-neutral-950))] ${j?``:`m-3 rounded-md border border-border`}`,"data-studio-fullscreen-target":``,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-h-0 relative overflow-hidden`,"data-preview-pan-surface":`true`,onPointerDown:e=>ern(e,a.current,n),onDragEnter:T,onDragOver:E,onDragLeave:D,onDrop:O,children:[(0,W.jsxs)(`div`,{className:`absolute inset-0 overflow-hidden`,children:[(0,W.jsx)(unn,{projectId:i,iframeRef:a,onIframeLoad:c,previewSlots:l,onShadowIframeLoad:u,onShadowReadyChange:d,onShadowError:f,setShadowIframeNode:p,resetPreviewSlots:m,onCompositionLoadingChange:_,portrait:e,directUrl:P,suppressLoadingOverlay:y.current,onStageRef:C,onCompositionSizeChange:x}),w&&(0,W.jsx)(`div`,{className:`absolute inset-2 z-40 rounded-lg border-2 border-dashed border-studio-accent/50 bg-studio-accent/4 pointer-events-none`}),(0,W.jsx)(Tnn,{})]}),(0,W.jsxs)(Knn,{children:[(0,W.jsx)(Jnn,{}),!j&&t]})]}),(0,W.jsxs)(`div`,{className:`shrink-0`,children:[!j&&h.length>1&&(0,W.jsx)(dnn,{stack:h,onNavigate:g}),(0,W.jsx)(xLt,{onTogglePlay:o,onSeek:s,disabled:v,isFullscreen:j,onToggleFullscreen:M})]})]})}var t4=gb(e=>({visible:Ub().audioMetersVisible??!1,setVisible:t=>{Wb({audioMetersVisible:t}),e({visible:t})}})),nrn=[0,-3,-6,-12,-24],rrn=-60,n4=[...nrn,rrn],irn=.9,arn=1200;function orn(e){let t=e>0?an(e):rrn;if(t>=0)return 1;if(t<=rrn)return 0;let n=n4.findIndex(e=>t>=e),r=n4[n-1],i=n4[n];return(n4.length-1-n+(t-i)/(r-i))/(n4.length-1)}function r4(e){return orn(be(e))}var srn={level:0,peak:0,peakAt:0};function crn(e,t,n,r){let i=r/1e3*irn,a=orn(t),o=Math.max(a,e.level-i);return a>=e.peak?{level:o,peak:a,peakAt:n}:n-e.peakAt<arn?{level:o,peak:e.peak,peakAt:e.peakAt}:{level:o,peak:Math.max(a,e.peak-i),peakAt:e.peakAt}}var lrn=e=>e.level===0&&e.peak===0;function urn(e,t,n,r){let[i,a]=e??[srn,srn],o=!t?.l&&!t?.r;return e&&o&&lrn(i)&&lrn(a)?e:[crn(i,t?.l??0,n,r),crn(a,t?.r??0,n,r)]}function drn(e){return e.some(e=>wG(e)||e.audioGroup!==void 0||e.hasAudio===!0&&!e.muted&&St(e))}function frn(){let e=X(e=>e.elements);return(0,U.useMemo)(()=>drn(e),[e])}var prn=`Monitor`,mrn=f3t;function hrn(e,t){return e||!t?e:Math.max(t.l,t.r)>=mrn}function i4(e,t){e&&(e.dataset.lit=String(t),e.style.setProperty(`background-color`,t?`var(--color-red-500)`:`var(--color-neutral-800)`),e.style.setProperty(`color`,t?`var(--color-white)`:`var(--color-neutral-500)`))}var a4=r4(-6),grn=r4(-3);function _rn(){let e=X(e=>e.elements),t=X(e=>e.audioVolume);return(0,U.useMemo)(()=>{let n=new Map,r=new Map;for(let t of e)t.audioGroup&&!n.has(t.audioGroup)&&(n.set(t.audioGroup,t.audioGroupLabel??t.audioGroup),r.set(t.audioGroup,t.audioGroupVolume??1));return[...[...n].map(([e,t])=>({id:e,label:t,volume:r.get(e)??1})),{id:null,label:prn,volume:t}]},[e,t])}function vrn(){let{onSetAudioGroupAttributeLive:e,onSetAudioGroupAttributeQuiet:t}=VX(),n=X(e=>e.setAudioVolume);return{onLive:(0,U.useCallback)((t,r)=>{t===null?n(r):e?.(t,`data-volume`,ce(r))},[e,n]),onCommit:(0,U.useCallback)((e,r)=>{e===null?n(r):t?.(e,`data-volume`,ce(r),`Set volume`)},[t,n])}}function yrn(e){try{return e?.contentWindow?.__hf?.audioMeter??null}catch{return null}}function brn(e,t){e&&(e.style.setProperty(`bottom`,`${t*100}%`),e.style.setProperty(`transform`,t>=1?`translateY(1px)`:`none`))}function xrn(e,t){t.forEach((t,n)=>{e?.[n]?.mask?.style.setProperty(`height`,`${(1-t.level)*100}%`),brn(e?.[n]?.peak??null,t.peak)})}function Srn(e,t){if(t===e)return e;try{e?.stop()}catch{}try{t?.start()}catch{}return t}function Crn(e,t){for(let n of[...e.keys()])t.has(n)||e.delete(n)}function wrn(e,t,n,r,i,a){for(let{id:o}of e){let e=t.get(o),s=urn(e,o===null?r?.master:r?.groups[o],i,a);s!==e&&(t.set(o,s),xrn(n.get(o),s))}}function Trn(e,t,n,r){let i=IX(),a=n??i?.previewIframeRef,o=(0,U.useRef)(e);o.current=e,(0,U.useEffect)(()=>{let e=0,n=null,i=performance.now(),s=new Map,c=l=>{e=requestAnimationFrame(c),n=Srn(n,yrn(a?.current));let u=n?.read(),d=l-i;i=l,Crn(s,new Set(o.current.map(e=>e.id))),wrn(o.current,s,t.current,u,l,d);let f=hrn(r.current.lit,u?.master);f!==r.current.lit&&(r.current.lit=f,i4(r.current.light,f))};return e=requestAnimationFrame(c),()=>{cancelAnimationFrame(e);try{n?.stop()}catch{}}},[a,t,r])}function Ern({clip:e}){return(0,W.jsx)(`button`,{type:`button`,"data-testid":`meter-clip-light`,"data-lit":`false`,title:`Lights when the preview reaches −1 dBFS, the export ceiling. Click to reset.`,ref:t=>{e.current.light=t,i4(t,e.current.lit)},onClick:()=>{e.current.lit=!1,i4(e.current.light,!1)},className:`rounded-[2px] px-1 font-mono text-[9px] leading-[14px] font-bold tracking-wide`,children:`CLIP`})}function Drn({maskRef:e,peakRef:t}){return(0,W.jsxs)(`div`,{className:`scheme-dark relative h-full w-[18px] overflow-hidden rounded-[2px] bg-neutral-900`,children:[(0,W.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 bg-green-500`,style:{height:`${a4*100}%`}}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 bg-amber-500`,style:{bottom:`${a4*100}%`,height:`${(grn-a4)*100}%`}}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-0 bg-red-500`,style:{height:`${(1-grn)*100}%`}}),(0,W.jsx)(`div`,{ref:e,"data-testid":`meter-mask`,className:`absolute inset-x-0 top-0 bg-neutral-900`,style:{height:`100%`}}),(0,W.jsx)(`div`,{ref:t,"data-testid":`meter-peak`,className:`absolute inset-x-0 bottom-0 h-px bg-text-0`})]})}function Orn({label:e,title:t,volume:n,maxPosition:r,onLive:i,onCommit:a}){let o=(0,U.useRef)(null),s=(0,U.useRef)(null),c=Ce(n),l=r-cn,u=(c-cn)/l,d=x(n),f=(0,U.useCallback)(e=>{let t=o.current?.getBoundingClientRect();return!t||t.height===0?c:cn+e$(1-(e-t.top)/t.height,0,1)*l},[c,l]),p=e=>{let t=h(f(e));s.current=t,i(t)},m=()=>{if(s.current===null)return;let e=s.current;s.current=null,a(e)},g=new Map([[`ArrowUp`,c+l*.02],[`ArrowDown`,c-l*.02],[`PageUp`,c+l*.1],[`PageDown`,c-l*.1],[`Home`,cn],[`End`,r]]);return(0,W.jsx)(`div`,{ref:o,role:`slider`,tabIndex:0,"aria-label":e,title:`${t}: ${d}`,"aria-orientation":`vertical`,"aria-valuemin":cn,"aria-valuemax":r,"aria-valuenow":Math.round(c),"aria-valuetext":d,onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),p(e.clientY)},onPointerMove:e=>{s.current!==null&&p(e.clientY)},onPointerUp:m,onPointerCancel:m,onLostPointerCapture:m,onKeyDown:e=>{let t=g.get(e.key);t!==void 0&&(a(h(e$(t,cn,r))),e.preventDefault())},className:`relative h-full w-2 shrink-0 cursor-ns-resize touch-none rounded-full bg-neutral-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-studio-accent`,children:(0,W.jsx)(`div`,{className:`absolute inset-x-[-3px] h-1.5 -translate-y-1/2 rounded-full bg-neutral-200`,style:{bottom:`${u*100}%`}})})}function krn({strip:e,register:t,onLive:n,onCommit:r,clipLight:i}){let a=[(0,U.useRef)(null),(0,U.useRef)(null),(0,U.useRef)(null),(0,U.useRef)(null)];return(0,U.useEffect)(()=>(t(e.id,[{mask:a[0].current,peak:a[1].current},{mask:a[2].current,peak:a[3].current}]),()=>t(e.id,null)),[e.id,t]),(0,W.jsxs)(`div`,{className:`flex w-[104px] shrink-0 flex-col items-center gap-1 px-1.5 pt-2 pb-1`,children:[i,(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-stretch gap-1.5`,"aria-label":`${e.label} level`,children:[(0,W.jsx)(Orn,{label:`${e.label} volume`,title:e.id===null?`Preview monitor volume`:`${e.label} volume`,volume:e.volume,maxPosition:e.id===null?Ce(1):100,onLive:t=>n(e.id,t),onCommit:t=>r(e.id,t)}),(0,W.jsx)(`div`,{className:`relative w-5 font-mono text-[9px] leading-none text-neutral-500`,children:nrn.map(e=>(0,W.jsx)(`span`,{className:`absolute right-0 translate-y-1/2`,style:{bottom:`${r4(e)*100}%`},children:e},e))}),(0,W.jsxs)(`div`,{className:`flex items-stretch gap-0.5`,children:[(0,W.jsx)(Drn,{maskRef:a[0],peakRef:a[1]}),(0,W.jsx)(Drn,{maskRef:a[2],peakRef:a[3]})]})]}),(0,W.jsx)(`span`,{className:`max-w-full truncate text-[10px] text-neutral-400`,title:e.label,children:e.label})]})}var Arn=(0,U.memo)(function({previewIframeRef:e}){let t=t4(e=>e.visible),n=frn();return!t||!n?null:(0,W.jsx)(jrn,{previewIframeRef:e})});function jrn({previewIframeRef:e}){let t=_rn(),n=(0,U.useRef)(new Map),r=(0,U.useRef)((e,t)=>{t?n.current.set(e,t):n.current.delete(e)}).current,{onLive:i,onCommit:a}=vrn(),o=(0,U.useRef)({lit:!1,light:null});return Trn(t,n,e,o),(0,W.jsx)(`div`,{"data-testid":`audio-meter-strip`,className:`flex shrink-0 overflow-x-auto border-l border-neutral-800/50 bg-neutral-950`,children:t.map(e=>(0,W.jsx)(krn,{strip:e,register:r,onLive:i,onCommit:a,clipLight:e.id===null?(0,W.jsx)(Ern,{clip:o}):void 0},e.id??`master`))})}function Mrn({timelineToolbar:e,timelineFooter:t,timelineOverlay:n,renderClipContent:r,onFileDrop:i,onDeleteElement:a,onAssetDrop:o,onBlockDrop:s,onCompositionDrop:c,onBlockedEditAttempt:l,onSelectTimelineElement:u,onRangeSelect:d,onCopyClip:f,onPasteClip:p,onDuplicateClip:m,canPasteClip:h,clipMenuItems:g,splitShortcut:_}){let{seek:v,handleDrillDown:y,compositionStack:b,updateCompositionStack:x,timelineDisabled:S,timelineSessionEpoch:C}=k2(),{onMoveElement:w,onMoveElements:T,onResizeElement:E,onResizeElements:D,onSplitElement:O}=QJt();return(0,W.jsxs)(`div`,{className:`relative flex h-full flex-col`,"data-studio-timeline":`true`,"aria-disabled":S||void 0,children:[(0,W.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0 overflow-hidden`,onDoubleClick:e=>{e.target.closest(`[data-clip]`)||S||b.length>1&&x(e=>e.slice(0,-1))},children:[(0,W.jsx)(`div`,{className:`shrink-0`,children:e}),(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,W.jsx)(t5t,{sessionEpoch:C,onSeek:v,onDrillDown:y,renderClipContent:r,onFileDrop:i,onDeleteElement:a,onAssetDrop:o,onBlockDrop:s,onCompositionDrop:c,onMoveElement:w,onMoveElements:T,onResizeElement:E,onResizeElements:D,onBlockedEditAttempt:l,onSplitElement:O,onSelectElement:u,onRangeSelect:d,onCopyClip:f,onPasteClip:p,onDuplicateClip:m,canPasteClip:h,clipMenuItems:g,splitShortcut:_})}),(0,W.jsx)(Arn,{})]})]}),t&&(0,W.jsx)(`div`,{className:`shrink-0`,children:t}),n&&(0,W.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-20`,children:n}),S&&(0,W.jsx)(`div`,{className:`absolute inset-0 z-30 cursor-not-allowed bg-black/18 flex items-center justify-center`,"data-testid":`timeline-loading-disabled-overlay`,role:`status`,onPointerDown:e=>e.preventDefault(),onDragOver:e=>e.preventDefault(),onDrop:e=>e.preventDefault(),children:(0,W.jsx)(`span`,{className:`rounded-md bg-neutral-900/90 px-2.5 py-1 text-[11px] text-neutral-400`,children:`Loading composition…`})})]})}var Nrn=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`]);function Prn(e,t){return e.metaKey||e.ctrlKey||e.altKey||t!=null&&oX(t)?!1:Nrn.has(e.key)}function Frn(e,t,n){let r=null,i=null;try{r=e.contentDocument,i=e.contentWindow}catch{return[]}if(!r||!i)return[];let a=e.getBoundingClientRect(),o=n.getBoundingClientRect(),s=parseFloat(e.style.width)||a.width,c=a.width/s,l=a.left-o.left,u=a.top-o.top,d=r.querySelectorAll(`.caption-group`),f=[];for(let e=0;e<t.groupOrder.length;e++){let n=t.groupOrder[e],a=t.groups.get(n);if(!a)continue;let o=d[e];if(!o)continue;let s=i.getComputedStyle(o);if(parseFloat(s.opacity)<=.01||s.visibility===`hidden`)continue;let p=[];for(let e of o.children){let t=e;if(t.dataset.captionWrapper===`true`){let e=t.querySelector(`:scope > span`);e&&p.push(e)}else t.tagName===`SPAN`&&p.push(t)}if(p.length===0&&o.textContent?.trim()){let e=o.childNodes[0];if(e&&e.nodeType===Node.TEXT_NODE){let t=(e.textContent||``).split(/\s+/).filter(Boolean),n=r.createDocumentFragment();for(let e of t){let t=r.createElement(`span`);t.textContent=e+` `,t.style.display=`inline`,n.appendChild(t),p.push(t)}o.replaceChild(n,e)}else{let e=o.querySelector(`:scope > span`);if(e&&e.textContent?.trim()){let t=e.textContent.split(/\s+/).filter(Boolean),n=r.createDocumentFragment();for(let e of t){let t=r.createElement(`span`);t.textContent=e+` `,t.style.display=`inline`,n.appendChild(t),p.push(t)}e.replaceWith(n)}}}for(let t=0;t<a.segmentIds.length;t++){let r=a.segmentIds[t],i=p[t];if(!i)continue;let o=i.getBoundingClientRect();f.push({segmentId:r,groupId:n,groupIndex:e,wordIndex:t,x:o.left*c+l,y:o.top*c+u,width:o.width*c,height:o.height*c})}}return f}function o4(e,t,n){let r=null;try{r=e.contentDocument}catch{return null}if(!r)return null;let i=r.querySelectorAll(`.caption-group`)[t];if(!i)return null;let a=[];for(let e of i.children){let t=e;if(t.dataset.captionWrapper===`true`){let e=t.querySelector(`:scope > span`);e&&a.push(e)}else t.tagName===`SPAN`&&a.push(t)}return a[n]??null}function s4(e,t){let n=t.gsap;if(n&&n.getProperty)return{x:n.getProperty(e,`x`)||0,y:n.getProperty(e,`y`)||0,scale:n.getProperty(e,`scale`)||1,rotation:n.getProperty(e,`rotation`)||0};let r=e.style.transform||``,i=r.match(/scale\(([^)]+)\)/),a=r.match(/rotate\(([^)]+)deg\)/),o=r.match(/translate\(([^,]+)px,\s*([^)]+)px\)/);return{x:o?parseFloat(o[1]):0,y:o?parseFloat(o[2]):0,scale:i?parseFloat(i[1]):1,rotation:a?parseFloat(a[1]):0}}function c4(e){if(e.dataset.captionWrapper===`true`)return e;let t=e.parentElement;if(t&&t.dataset.captionWrapper===`true`)return t;let n=e.ownerDocument.createElement(`span`);return n.style.display=`inline-block`,n.dataset.captionWrapper=`true`,e.parentNode?.insertBefore(n,e),n.appendChild(e),n}function l4(e,t,n,r,i,a){let o=c4(e),s=t.gsap;s&&s.set?s.set(o,{x:n,y:r,scale:i,rotation:a}):o.style.transform=`translate(${n.toFixed(1)}px, ${r.toFixed(1)}px) rotate(${a.toFixed(1)}deg) scale(${i.toFixed(3)})`}var u4=null;function Irn(e){return u4=e,()=>{u4===e&&(u4=null)}}function Lrn(){let e=u4?.current;return!!(e?.isConnected&&e.offsetParent!==null)}function Rrn(e){let t=u4?.current;if(!t)return;let n=null;try{n=t.contentWindow}catch{return}if(n)for(let r=0;r<e.groupOrder.length;r++){let i=e.groups.get(e.groupOrder[r]);if(i)for(let a=0;a<i.segmentIds.length;a++){let o=e.segments.get(i.segmentIds[a]);if(!o)continue;let s=o4(t,r,a);if(!s)continue;let c=o.style;l4(s,n,c.x??0,c.y??0,c.scaleX??1,c.rotation??0)}}}function zrn(e,t){let{x:n,y:r,scale:i,rotation:a}=s4(c4(e),t),o={};return Math.abs(n)>.5&&(o.x=n),Math.abs(r)>.5&&(o.y=r),Math.abs(i-1)>.001&&(o.scaleX=i,o.scaleY=i),Math.abs(a)>.1&&(o.rotation=a),o}var d4=8,f4=24,p4=20;function Brn(e,t,n){let r=zrn(t,n);Object.keys(r).length>0&&O1.getState().updateSegmentStyle(e,r)}var Vrn=(0,U.memo)(function({iframeRef:e}){let t=O1(e=>e.isEditMode),n=xZ(),r=O1(e=>e.model),i=O1(e=>e.selectedSegmentIds),a=O1(e=>e.selectSegment),o=O1(e=>e.clearSelection),[s,c]=(0,U.useState)([]),l=(0,U.useRef)(null),u=(0,U.useRef)(r);u.current=r;let d=(0,U.useRef)(null),f=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!t)return;let n=Irn(e),r=[],i=null,a=()=>{i=null;let t=e.current,n=u.current,a=l.current;if(!t||!n||!a)return;let o=Frn(t,n,a);o.length===r.length&&o.every((e,t)=>Math.abs(e.x-r[t].x)<.5&&Math.abs(e.y-r[t].y)<.5)||(r=o,c(o))},o=()=>{i===null&&(i=requestAnimationFrame(a))},s=X.subscribe(o),p=t=>{!t.source||t.source!==e.current?.contentWindow||t.data?.source===`hf-preview`&&o()};window.addEventListener(`message`,p),window.addEventListener(`resize`,o);let m=new ResizeObserver(o);e.current&&m.observe(e.current),l.current&&m.observe(l.current);let h=null,g=()=>{let e=X.getState().isPlaying;e&&h===null?h=setInterval(o,66):!e&&h!==null&&(clearInterval(h),h=null)},_=X.subscribe(g);g(),a();let v=()=>{try{return e.current?.contentWindow??null}catch{return null}},y=()=>{let e=f.current;if(!e)return!1;let t=v();return t&&l4(e.wordEl,t,e.origTX,e.origTY,e.origScale,e.origRotation),f.current=null,!0};d.current=y;let b=t=>{let n=O1.getState(),{selectedSegmentIds:r,model:i}=n;if(t.key===`Escape`){if(y()){t.preventDefault(),o();return}r.size>0&&(t.preventDefault(),n.clearSelection());return}if((t.metaKey||t.ctrlKey)&&t.key.toLowerCase()===`a`&&!t.shiftKey&&!t.altKey&&!aX(t.target)){t.preventDefault(),n.selectAll();return}if(r.size===0||!i)return;let a=t.key;if(!Prn(t,t.target))return;t.preventDefault();let s=t.shiftKey?10:1,c=a===`ArrowLeft`?-s:a===`ArrowRight`?s:0,l=a===`ArrowUp`?-s:a===`ArrowDown`?s:0,u=e.current,d=u?.contentWindow;if(!(!u||!d)){for(let e of r)for(let t=0;t<i.groupOrder.length;t++){let n=i.groups.get(i.groupOrder[t]);if(!n)continue;let r=n.segmentIds.indexOf(e);if(r<0)continue;let a=o4(u,t,r);if(!a)continue;let o=s4(c4(a),d);l4(a,d,o.x+c,o.y+l,o.scale,o.rotation),Brn(e,a,d);break}o()}};return window.addEventListener(`keydown`,b),()=>{n(),s(),_(),h!==null&&clearInterval(h),i!==null&&cancelAnimationFrame(i),m.disconnect(),window.removeEventListener(`message`,p),window.removeEventListener(`resize`,o),window.removeEventListener(`keydown`,b),d.current=null}},[n]);let p=(0,U.useCallback)(()=>{let t=e.current;if(!t)return 1;let n=t.getBoundingClientRect(),r=parseFloat(t.style.width)||n.width;return n.width/r},[e]),m=(0,U.useCallback)((t,n,r,i)=>{i.stopPropagation(),i.currentTarget.setPointerCapture(i.pointerId);let a=e.current;if(!a)return;let o=o4(a,t,n),s=a.contentWindow;if(!o||!s)return;let c=s4(c4(o),s);f.current={type:`move`,wordEl:o,segmentId:r,startMX:i.clientX,startMY:i.clientY,origTX:c.x,origTY:c.y,origScale:c.scale,origRotation:c.rotation}},[e]),h=(0,U.useCallback)((t,n,r,i)=>{i.stopPropagation(),i.preventDefault(),i.currentTarget.setPointerCapture(i.pointerId);let a=e.current;if(!a)return;let o=o4(a,t,n),s=a.contentWindow;if(!o||!s)return;let c=o.getBoundingClientRect(),l=p(),u=c.left*l+(e.current?.getBoundingClientRect().left??0)+c.width*l/2,d=s4(c4(o),s);f.current={type:`scale`,wordEl:o,segmentId:r,startMX:i.clientX,startDxFromCenter:i.clientX-u,origTX:d.x,origTY:d.y,origScale:d.scale,origRotation:d.rotation}},[e,p]),g=(0,U.useCallback)((t,n)=>{n.stopPropagation(),n.preventDefault(),n.currentTarget.setPointerCapture(n.pointerId);let r=e.current;if(!r)return;let i=o4(r,t.groupIndex,t.wordIndex),a=r.contentWindow;if(!i||!a)return;let o=s4(c4(i),a);f.current={type:`rotate`,wordEl:i,segmentId:t.segmentId,startMX:n.clientX,origTX:o.x,origTY:o.y,origRotation:o.rotation,origScale:o.scale}},[e]),_=(0,U.useCallback)(()=>{try{return e.current?.contentWindow??null}catch{return null}},[e]),v=(0,U.useCallback)(e=>{let t=f.current;if(!t)return;let n=_();if(n){if(t.type===`move`){let r=p(),i=(e.clientX-t.startMX)/r,a=(e.clientY-t.startMY)/r;l4(t.wordEl,n,t.origTX+i,t.origTY+a,t.origScale,t.origRotation)}else if(t.type===`scale`){let r=t.startMX-t.startDxFromCenter,i=Math.abs(t.startDxFromCenter),a=Math.abs(e.clientX-r),o=i>5?a/i:1,s=Math.max(.1,t.origScale*o);l4(t.wordEl,n,t.origTX,t.origTY,s,t.origRotation)}else if(t.type===`rotate`){let r=(e.clientX-t.startMX)/200*90;l4(t.wordEl,n,t.origTX,t.origTY,t.origScale,t.origRotation+r)}}},[p,_]),y=(0,U.useCallback)(()=>{let e=f.current;if(e){let t=_();t&&Brn(e.segmentId,e.wordEl,t),f.current=null}},[_]),b=(0,U.useCallback)(e=>{e.target===e.currentTarget&&o()},[o]);return t?(0,W.jsxs)(`div`,{ref:l,className:`absolute inset-0 z-50`,style:{pointerEvents:`auto`},onClick:b,onPointerMove:v,onPointerUp:y,onLostPointerCapture:y,children:[s.length===0&&r&&r.segments.size>0&&(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-3 flex justify-center pointer-events-none`,children:(0,W.jsx)(`span`,{className:`px-2.5 py-1 rounded-full bg-black/60 border border-neutral-700 text-2xs text-neutral-300`,children:`No captions visible at this frame — scrub to a caption, or select one in the track below`})}),s.map(e=>{let t=i.has(e.segmentId);return(0,W.jsx)(`div`,{className:[`absolute`,t?`ring-2 ring-studio-accent`:`hover:ring-1 hover:ring-white/30`].join(` `),style:{left:e.x,top:e.y,width:e.width,height:e.height,cursor:t?`move`:`pointer`,touchAction:`none`,borderRadius:2},onClick:t=>{t.stopPropagation(),a(e.segmentId,t.shiftKey)},onPointerDown:n=>{t&&m(e.groupIndex,e.wordIndex,e.segmentId,n)},children:t&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{style:{position:`absolute`,left:`50%`,top:-p4-d4/2-f4/2,marginLeft:-f4/2,width:f4,height:f4,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:`grab`,touchAction:`none`},onPointerDown:t=>g(e,t),children:(0,W.jsx)(`div`,{style:{width:d4,height:d4,borderRadius:`50%`,backgroundColor:`var(--hf-accent, #3CE6AC)`,border:`1px solid rgba(0,0,0,0.5)`}})}),(0,W.jsx)(`div`,{style:{position:`absolute`,left:`50%`,top:-p4,width:1,height:p4,marginLeft:-.5,backgroundColor:`var(--hf-accent, #3CE6AC)`,opacity:.5,pointerEvents:`none`}}),[{corner:{right:-f4/2,bottom:-f4/2},cursor:`nwse-resize`},{corner:{left:-f4/2,top:-f4/2},cursor:`nwse-resize`},{corner:{right:-f4/2,top:-f4/2},cursor:`nesw-resize`},{corner:{left:-f4/2,bottom:-f4/2},cursor:`nesw-resize`}].map(({corner:t,cursor:n},r)=>(0,W.jsx)(`div`,{style:{position:`absolute`,...t,width:f4,height:f4,display:`flex`,alignItems:`center`,justifyContent:`center`,cursor:n,touchAction:`none`},onPointerDown:t=>h(e.groupIndex,e.wordIndex,e.segmentId,t),children:(0,W.jsx)(`div`,{style:{width:d4,height:d4,backgroundColor:`var(--hf-accent, #3CE6AC)`,border:`1px solid rgba(0,0,0,0.5)`,borderRadius:2}})},r))]})},e.segmentId)})]}):null});function m4(e,t){mG(`feature_used`,{feature:e,surface:`preview`,method:t})}function h4(e,t,n){if(typeof n!=`object`||!n||Reflect.get(n,`ok`)===!1)return;let r=Reflect.get(n,`persistence`);(Reflect.get(n,`changed`)===!0||typeof r==`object`&&r&&Reflect.get(r,`changed`)===!0)&&m4(e,t)}var Hrn=.95,Urn=new Set([`video`,`img`,`canvas`,`svg`]);function Wrn(e,t){return t.width<=1||t.height<=1?!1:e.width/t.width>=Hrn&&e.height/t.height>=Hrn}function g4(e,t){return!Urn.has(e.tagName.toLowerCase())&&Wrn(e.getBoundingClientRect(),t)}function Grn(e,t,n,r,i){let a=e.getBoundingClientRect(),o=(t.querySelector(`[data-composition-id]`)??t.documentElement??null)?.getBoundingClientRect(),s=o?.width||n.innerWidth,c=o?.height||n.innerHeight;if(!s||!c)return null;let l=a.width/s,u=a.height/c;return{x:(r-a.left)/l,y:(i-a.top)/u,viewport:{width:s,height:c}}}var Krn=new WeakMap;function qrn(e,t){let n=Krn.get(e);if(n!==void 0)return n;let r=e.createElement(`div`),i=e.createElement(`div`);r.style.pointerEvents=`none`,r.appendChild(i);let a=e.body??e.documentElement;if(!a)return!1;a.appendChild(r);let o=t.getComputedStyle(i).pointerEvents!==`none`;return r.remove(),Krn.set(e,o),o}function Jrn(e,t){let n=t.getComputedStyle(e).pointerEvents;return n!==``&&n!==`inherit`&&n!==`unset`}function Yrn(e,t){let n=e.parentElement;for(;n;){if(t.getComputedStyle(n).pointerEvents===`none`){let r=e;for(;r&&r!==n;){if(Jrn(r,t))return t.getComputedStyle(r).pointerEvents===`none`;r=r.parentElement}return!0}n=n.parentElement}return!1}function _4(e){let t=e.ownerDocument.defaultView;return t?t.getComputedStyle(e).pointerEvents===`none`?!0:qrn(e.ownerDocument,t)?Yrn(e,t):!1:!1}function Xrn(e){let t=new WeakSet;for(let n of e)Ft(n)&&_4(n)&&t.add(n);return t}function Zrn(e,t){let n=Xrn(e);return xt(e,{activeCompositionPath:t}).filter(e=>!n.has(e))}function Qrn(e,t,n){let r=null,i=1/0;for(let a of Array.from(e.querySelectorAll(`[data-hf-group]`))){let e=1/0,o=1/0,s=-1/0,c=-1/0;for(let t of Array.from(a.children)){let n=t.getBoundingClientRect();(n.width!==0||n.height!==0)&&(e=Math.min(e,n.left),o=Math.min(o,n.top),s=Math.max(s,n.right),c=Math.max(c,n.bottom))}if(s<e||t<e||t>s||n<o||n>c)continue;let l=(s-e)*(c-o);l<i&&(i=l,r=a)}return r}function v4(e,t,n,r){let i=null,a=null;try{i=e.contentDocument,a=e.contentWindow}catch{return null}if(!i||!a)return null;let o=Grn(e,i,a,t,n);if(!o)return null;if(typeof i.elementsFromPoint==`function`){let e=Zrn(i.elementsFromPoint(o.x,o.y),r).find(e=>!g4(e,o.viewport))??null;if(e)return e}let s=Qrn(i,o.x,o.y);if(s&&!_4(s)&&ye(s,r))return s;let c=Q0t(i.elementFromPoint(o.x,o.y));return!c||!ye(c,r)||_4(c)||!m(c)||g4(c,o.viewport)?null:c}function $rn(e,t,n,r){let i=null,a=null;try{i=e.contentDocument,a=e.contentWindow}catch{return[]}if(!i||!a)return[];let o=Grn(e,i,a,t,n);if(!o)return[];if(typeof i.elementsFromPoint==`function`)return Zrn(i.elementsFromPoint(o.x,o.y),r).filter(e=>!g4(e,o.viewport));let s=Q0t(i.elementFromPoint(o.x,o.y));return!s||!ye(s,r)||_4(s)||!m(s)||g4(s,o.viewport)?[]:[s]}function y4(e){return e&&(typeof e==`object`||typeof e==`function`)?e:null}function b4(e,t){let n=e?Reflect.get(e,t):null;if(typeof n==`function`)try{n.call(e)}catch{}}function x4(e,t){let n=e?Reflect.get(e,t):null;if(typeof n!=`function`)return null;try{let t=n.call(e);return typeof t==`number`&&Number.isFinite(t)?t:null}catch{return null}}function ein(e){let t=e?.contentWindow;if(!t)return null;try{let e=y4(Reflect.get(t,`__player`)),n=x4(e,`getTime`);if(typeof(e?Reflect.get(e,`pause`):null)==`function`)return b4(e,`pause`),n;let r=null,i=y4(Reflect.get(t,`__timeline`));r??=x4(i,`time`),b4(i,`pause`);let a=y4(Reflect.get(t,`__timelines`));if(a)for(let e of Object.values(a)){let t=y4(e);r??=x4(t,`time`),b4(t,`pause`)}return r}catch{return null}}function S4(e){if(!e)return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}function tin(e){return e?.querySelector(`[data-composition-id]`)??e?.documentElement??null}function nin(e){if(!e)return null;let t=e.getBoundingClientRect(),n=S4(e.getAttribute(`data-width`))??t.width,r=S4(e.getAttribute(`data-height`))??t.height;return!n||!r?null:{width:n,height:r}}function C4(e,t,n){let r=t.getBoundingClientRect(),i=e.getBoundingClientRect(),a=nin(tin(n));return a?{iframeRect:r,overlayRect:i,rootScaleX:r.width/a.width,rootScaleY:r.height/a.height}:null}var rin=`data-composition-id`;function iin(e){if(!e||e===`none`)return 0;let t=e.trim().split(/\s+/),n=t.at(-1);if(!n?.endsWith(`deg`))return 0;if(t.length===4){let[e,r,i]=t;if(Number(e)!==0||Number(r)!==0||Math.abs(Number(i))!==1)return 0;let a=Number.parseFloat(n);return Number.isFinite(a)?a*Math.sign(Number(i)):0}if(t.length!==1)return 0;let r=Number.parseFloat(n);return Number.isFinite(r)?r:0}function ain(e,t,n){let r=n(e);if(!r)return null;let i=r.transform,a=i&&i!==`none`?t.fromTransform(i):t.identity();if(!a)return null;let o=iin(r.rotate);return o===0?a:t.compose(t.fromRotate(o),a)}function oin(e,t,n,r){let i=[],a;for(let t=e;t&&(a=r?.get(t),!(a!==void 0||(i.push(t),t.hasAttribute(rin))));t=t.parentElement);let o=a===void 0?t.identity():a;for(let e=i.length-1;e>=0;--e){let a=i[e];if(o!==null){let e=ain(a,t,n);o=e===null?null:t.compose(o,e)}r?.set(a,o)}return o}function w4(e){let t=y(e);return Number.isInteger(t)?`${t}`:t.toFixed(2).replace(/0+$/,``).replace(/\.$/,``)}function sin(e){return`${w4(Math.max(0,e))}px`}function cin(e){let t=e.trim();if(t===`0`)return 0;let n=/^(-?\d+(?:\.\d+)?)px$/i.exec(t);if(!n)return null;let r=Number.parseFloat(n[1]);return Number.isFinite(r)?Math.max(0,r):null}function lin(e){if(e.length<1||e.length>4)return null;let[t,n=t,r=t,i=n]=e;return t===void 0||n===void 0||r===void 0||i===void 0?null:{top:t,right:n,bottom:r,left:i}}function T4(e){let t=e?.trim();return!t||t===`none`?`none`:/^inset\(/i.test(t)?`inset`:/^circle\(/i.test(t)?`circle`:`custom`}function E4(e){let t=/^inset\(([^()]*)\)$/i.exec(e?.trim()??``);if(!t)return null;let n=t[1].trim().replace(/\s+/g,` `).split(/ round /i),r=n[0]?.trim();if(!r||n.length>2)return null;let i=r.split(/\s+/).map(cin);if(i.some(e=>e==null))return null;let a=[];for(let e of i){if(e==null)return null;a.push(e)}let o=lin(a);if(!o)return null;let s=n[1]?.trim(),c=s?cin(s):0;return c==null?null:{...o,radius:c}}function uin(e){let t=E4(e);if(!t)return 0;let{top:n,right:r,bottom:i,left:a}=t;return n===r&&n===i&&n===a?n:0}function din(e,t,n){return e===`custom`?n?.trim()||`none`:e===`circle`?`circle(50% at 50% 50%)`:e===`inset`?`inset(0 round ${w4(Math.max(0,t))}px)`:`none`}function D4(e,t=0){let[n,r,i,a]=[e.top,e.right,e.bottom,e.left].map(sin),o=n===r&&n===i&&n===a?n:`${n} ${r} ${i} ${a}`,s=Math.max(0,t);return s>0?`inset(${o} round ${w4(s)}px)`:`inset(${o})`}function fin(e,t){return`inset(${sin(e)} round ${w4(Math.max(0,t))}px)`}function pin(e,t,n,r){let i=n>0?n:1,a=r>0?r:1;return{left:e.left+t.left*i,top:e.top+t.top*a,width:Math.max(0,e.width-(t.left+t.right)*i),height:Math.max(0,e.height-(t.top+t.bottom)*a)}}var O4=new WeakMap;function min(e){let t=e=>`"${e.replace(/["\\]/g,`\\$&`)}"`,n=e.getAttribute(`data-hf-id`);return n?`[data-hf-id=${t(n)}]`:e.id?`[id=${t(e.id)}]`:null}function hin(e){let t=min(e);if(!t||O4.has(e))return;let n=e.ownerDocument,r=n.createElement(`style`);r.textContent=`${t}{clip-path:none!important}`,(n.head??n.documentElement).append(r),O4.set(e,{rule:r})}function gin(e){O4.get(e)?.rule.remove(),O4.delete(e)}function _in(e){return O4.has(e)}var vin=e=>e.ownerDocument.defaultView?.getComputedStyle(e).clipPath.trim()||``;function yin(e){let t=e.style.getPropertyValue(`clip-path`).trim(),n=O4.get(e);if(t||!n)return t||vin(e);if(n.sheetClip===void 0){let{parentNode:t,nextSibling:r}=n.rule;n.rule.remove(),n.sheetClip=vin(e),t?.insertBefore(n.rule,r)}return n.sheetClip}function bin(e){return!e||e===`none`?{top:0,right:0,bottom:0,left:0,radius:0}:E4(e)}function k4(e){return bin(yin(e))}function xin(e){return e.top>0||e.right>0||e.bottom>0||e.left>0}function A4(e,t){return Number.isFinite(e)?Math.min(Math.max(0,e),Math.max(0,t)):0}function Sin(e){let t=e.scaleX>0?e.scaleX:1,n=e.scaleY>0?e.scaleY:1,r={...e.startInsets};return e.edge===`left`?r.left=A4(e.startInsets.left+e.deltaX/t,e.width-r.right):e.edge===`right`?r.right=A4(e.startInsets.right-e.deltaX/t,e.width-r.left):e.edge===`top`?r.top=A4(e.startInsets.top+e.deltaY/n,e.height-r.bottom):r.bottom=A4(e.startInsets.bottom-e.deltaY/n,e.height-r.top),r}function Cin(e){let t=e.scaleX>0?e.scaleX:1,n=e.scaleY>0?e.scaleY:1,r=e.startInsets.left+e.startInsets.right,i=e.startInsets.top+e.startInsets.bottom,a=Math.min(Math.max(0,e.startInsets.left+e.deltaX/t),r),o=Math.min(Math.max(0,e.startInsets.top+e.deltaY/n),i);return{left:a,right:r-a,top:o,bottom:i-o}}function j4(e,t){let n=_in(t)?null:k4(t);return!n||n.top<=0&&n.right<=0&&n.bottom<=0&&n.left<=0?e:pin(e,n,e.editScaleX,e.editScaleY)}var win={a:1,b:0,c:0,d:1},M4=1e-6;function Tin(e){let t=/^matrix\(([^)]+)\)$/.exec(e);if(t){let[e,n,r,i]=t[1].split(`,`).map(e=>Number.parseFloat(e));return[e,n,r,i].every(Number.isFinite)?{a:e,b:n,c:r,d:i}:null}let n=/^matrix3d\(([^)]+)\)$/.exec(e);if(!n)return null;let r=n[1].split(`,`).map(e=>Number.parseFloat(e));return r.length!==16||!r.every(Number.isFinite)||![r[3],r[7],r[11]].every(e=>Math.abs(e)<M4)?null:{a:r[0],b:r[1],c:r[4],d:r[5]}}var Ein={identity:()=>win,fromTransform:Tin,fromRotate:e=>{let t=e*Math.PI/180;return{a:Math.cos(t),b:Math.sin(t),c:-Math.sin(t),d:Math.cos(t)}},compose:(e,t)=>({a:e.a*t.a+e.c*t.b,b:e.b*t.a+e.d*t.b,c:e.a*t.c+e.c*t.d,d:e.b*t.c+e.d*t.d})};function Din(e){return Math.abs(e.a-1)<M4&&Math.abs(e.b)<M4&&Math.abs(e.c)<M4&&Math.abs(e.d-1)<M4}function Oin(e){let t=oin(e,Ein,e=>{try{return e.ownerDocument.defaultView?.getComputedStyle(e)??null}catch{return null}});return t&&!Din(t)?t:null}function kin(e,t){let n=t.editScaleX>0?t.editScaleX:1,r=t.editScaleY>0?t.editScaleY:1,i={angleDeg:0,left:t.left,top:t.top,width:t.width,height:t.height,scaleX:n,scaleY:r},a=Oin(e);if(!a)return i;let{a:o,b:s,c,d:l}=a,u=Math.hypot(o,s),d=o*l-s*c,f=u===0?1:Math.abs(d)/u;if(u<=0||f<=0)return i;let p=Math.atan2(s,o)*180/Math.PI,m=u*n,h=f*r,g=e.offsetWidth*m,_=e.offsetHeight*h;if(!(g>0)||!(_>0))return i;let v=t.left+t.width/2,y=t.top+t.height/2;return{angleDeg:p,left:v-g/2,top:y-_/2,width:g,height:_,scaleX:m,scaleY:h}}function Ain(e,t,n){if(n===0)return{deltaX:e,deltaY:t};let r=-n*Math.PI/180,i=Math.cos(r),a=Math.sin(r);return{deltaX:e*i-t*a,deltaY:e*a+t*i}}function jin(){return{visible:new Map,transform:new Map,sourceBoundary:new Map,sourceBoundaryRect:new Map}}function Min(e,t,n){let r=e.get(t);if(r!==void 0)return r;let i=n();return e.set(t,i),i}var N4=16,P4=(e,t,n)=>({...e,left:e.left+t,top:e.top+n});function F4(e){return qe(e)}var Nin=e=>e.hasAttribute(`data-composition-file`)||e.hasAttribute(`data-composition-src`);function Pin(e,t){let n=[],r;for(let i=e;i&&(r=t?.sourceBoundary.get(i),r===void 0);i=i.parentElement){if(Nin(i)){r=i,t?.sourceBoundary.set(i,i);break}n.push(i)}let i=r??null;if(t)for(let e of n)t.sourceBoundary.set(e,i);return i}function Fin(e){let t=e.rootScaleX>0?e.rootScaleX:1,n=e.rootScaleY>0?e.rootScaleY:1,r=e.sourceRectWidth&&e.sourceRectWidth>0&&e.sourceWidth&&e.sourceWidth>0?e.sourceRectWidth*t/e.sourceWidth:t,i=e.sourceRectHeight&&e.sourceRectHeight>0&&e.sourceHeight&&e.sourceHeight>0?e.sourceRectHeight*n/e.sourceHeight:n;return{scaleX:r>0?r:t,scaleY:i>0?i:n}}function I4(e,t,n,r){let i=L4(e,t,n,r);return i?{...i,...j4(i,n)}:null}function Iin(e,t,n){let r=C4(e,t,t.contentDocument);return r?n.map(n=>{let i=L4(e,t,n,r);return i?{...i,...j4(i,n)}:null}):n.map(()=>null)}function Lin(e,t,n){let r=e.DOMMatrix;if(!r)return null;let i=e.getComputedStyle(t),a={identity:()=>new r,fromTransform:e=>new r(e),fromRotate:e=>new r().rotateSelf(e),compose:(e,t)=>e.multiply(t)};try{let r=oin(t,a,n=>n===t?i:e.getComputedStyle(n),n?.transform);return r?{matrix:r,cs:i}:null}catch{return null}}function Rin(e){let t=Number.isFinite(e.a)?e.a:1,n=Number.isFinite(e.b)?e.b:0,r=Number.isFinite(e.c)?e.c:0,i=Number.isFinite(e.d)?e.d:1,a=Math.atan2(n,t)*180/Math.PI,o=t*i-n*r,s=Math.atan2(-r,i)*180/Math.PI,c=o<0&&Math.abs(s)<Math.abs(a)?s:a;return Number.isFinite(c)?c:0}var zin=1e-4;function L4(e,t,n,r,i){let a=r??C4(e,t,t.contentDocument);if(!a)return null;let{iframeRect:o,overlayRect:s,rootScaleX:c,rootScaleY:l}=a,u=n.getBoundingClientRect(),d=Pin(n,i),f=d&&i?Min(i.sourceBoundaryRect,d,()=>d.getBoundingClientRect()):d?.getBoundingClientRect(),p=Fin({rootScaleX:c,rootScaleY:l,sourceRectWidth:f?.width,sourceRectHeight:f?.height,sourceWidth:S4(d?.getAttribute(`data-width`)??null),sourceHeight:S4(d?.getAttribute(`data-height`)??null)});return{left:o.left-s.left+u.left*c,top:o.top-s.top+u.top*l,width:u.width*c,height:u.height*l,editScaleX:p.scaleX,editScaleY:p.scaleY}}function R4(e,t){return Math.hypot(t.x-e.x,t.y-e.y)}function Bin(e){return{x:(e.nw.x+e.ne.x+e.se.x+e.sw.x)/4,y:(e.nw.y+e.ne.y+e.se.y+e.sw.y)/4}}function z4(e,t,n,r,i){let a=t.contentWindow,o=t.contentDocument;if(!a||!o)return null;let s=a.DOMPoint;if(!s)return null;let c=r??C4(e,t,o);if(!c)return null;let{iframeRect:l,overlayRect:u,rootScaleX:d,rootScaleY:f}=c,p=i??Lin(a,n);if(!p)return null;let{matrix:m,cs:h}=p,g=n.offsetWidth,_=n.offsetHeight,v=h.transformOrigin.split(` `).map(e=>Number.parseFloat(e)),y=Number.isFinite(v[0])?v[0]:g/2,b=Number.isFinite(v[1])?v[1]:_/2,x=(e,t)=>{let n=m.transformPoint(new s(e-y,t-b));return{x:n.x,y:n.y}},S={nw:x(0,0),ne:x(g,0),se:x(g,_),sw:x(0,_)},C=[S.nw.x,S.ne.x,S.se.x,S.sw.x],w=[S.nw.y,S.ne.y,S.se.y,S.sw.y],T=n.getBoundingClientRect(),E=T.left-Math.min(...C),D=T.top-Math.min(...w),O=e=>({x:l.left-u.left+(e.x+E)*d,y:l.top-u.top+(e.y+D)*f});return{nw:O(S.nw),ne:O(S.ne),se:O(S.se),sw:O(S.sw)}}function B4(e,t,n,r,i){let a=r??C4(e,t,t.contentDocument);if(!a)return null;let o=L4(e,t,n,a,i);if(!o)return null;let s=t.contentWindow,c=s?Lin(s,n,i):null,l=c?Rin(c.matrix):0;if(Math.abs(l)<zin)return o;let u=z4(e,t,n,a,c);if(!u)return o;let d=R4(u.nw,u.ne),f=R4(u.nw,u.sw),p=(u.nw.x+u.se.x)/2,m=(u.nw.y+u.se.y)/2;return!Number.isFinite(d)||!Number.isFinite(f)||d<=0||f<=0?o:{left:p-d/2,top:m-f/2,width:d,height:f,editScaleX:o.editScaleX,editScaleY:o.editScaleY,angle:l}}function Vin(e,t,n,r){let i=B4(e,t,n,r);return i?{...i,...j4(i,n)}:null}var V4=.5,Hin=.1;function H4(e,t){return e===t?!0:!e||!t?!1:Math.abs(e.left-t.left)<V4&&Math.abs(e.top-t.top)<V4&&Math.abs(e.width-t.width)<V4&&Math.abs(e.height-t.height)<V4&&Math.abs(e.editScaleX-t.editScaleX)<.001&&Math.abs(e.editScaleY-t.editScaleY)<.001&&Math.abs((e.angle??0)-(t.angle??0))<Hin}function Uin(e,t){return e===t||e.length===t.length&&e.every((e,n)=>{let r=t[n];return!!(r&&e.key===r.key&&e.element===r.element&&e.selection===r.selection&&H4(e.rect,r.rect))})}function U4(e){let t=e[0];if(!t)return null;let n=t.left,r=t.top,i=t.left+t.width,a=t.top+t.height;for(let t of e.slice(1))n=Math.min(n,t.left),r=Math.min(r,t.top),i=Math.max(i,t.left+t.width),a=Math.max(a,t.top+t.height);return{left:n,top:r,width:i-n,height:a-r,editScaleX:1,editScaleY:1}}function Win(e,t,n,r,i){let a=L4(e,t,n,r,i);if(!a||!n.hasAttribute(`data-hf-group`))return a;let o=[];for(let a of Array.from(n.children)){let n=L4(e,t,a,r,i);n&&o.push(n)}let s=o.length>0?U4(o):null;return s?{...s,editScaleX:a.editScaleX,editScaleY:a.editScaleY}:a}function W4(e,t,n,r,i){return n.hasAttribute(`data-hf-group`)?Win(e,t,n,r,i):B4(e,t,n,r,i)}function Gin(e){return e.filter(t=>!e.some(e=>e!==t&&e.element.contains(t.element)))}function G4(e){return[e.sourceFile??``,e.hfId??``,e.id??``,e.selector??``,e.selectorIndex??``].join(`|`)}function Kin(e,t,n,r){let i=G4(t),a=r.current;if(a?.key===i&&a.element.isConnected&&a.element.ownerDocument===e)return a.element;let o=He(e,t,n);return r.current=o?{key:i,element:o}:null,o}var K4=o2(`select`),q4=4;function qin(e,t,n){return n?Math.abs(e)>=Math.abs(t)?{dx:e,dy:0,lockedAxis:`y`}:{dx:0,dy:t,lockedAxis:`x`}:{dx:e,dy:t}}var Jin=.05,Yin=15,Xin=.5;function J4(e,t){return t.pointerId===e.pointerId&&(t.buttons&1)==1}var Zin=`data-dom-edit-press-waiting`;function Qin(e){e?.focus({preventScroll:!0})}function $in(e,t){return!e||!t?!1:e===t||e.contains(t)}function ean(e){let t=$in(e.cached?.element,e.elementAtPoint);return K4(`shift-pointerdown`,{candidate:e.cached?e.cached.selector??null:null,pointTarget:e.elementAtPoint?.id??e.elementAtPoint?.tagName??null,cacheIsAboutThisPoint:t}),t?e.cached:null}function tan(e){return{dx:(e.originWidth-e.overlayWidth)/2,dy:(e.originHeight-e.overlayHeight)/2}}function nan(e,t,n,r){return Math.atan2(r-t,n-e)*180/Math.PI}function ran(e){return((e+180)%360+360)%360-180}function ian(e){let t=nan(e.centerX,e.centerY,e.startX,e.startY),n=ran(nan(e.centerX,e.centerY,e.currentX,e.currentY)-t),r=e.actualAngle+n;return{angle:e.snap?Math.round(r/Yin)*Yin:S(r)}}function aan(e,t){return Math.abs(t-e)>=Jin}function oan(e,t,n,r){return e?.every(e=>e.element.ownerDocument===t.contentDocument)?e:can(t,n,r)}var san=4;function can(e,t,n){let r=e.contentDocument;if(!r)return[];let i=r.querySelector(`[data-composition-id]`)??r.body,a=ot(i,{activeCompositionPath:n,isMasterView:!n||n===`index.html`}),o=r.querySelector(`[data-composition-id]`)??r.documentElement,s=Number.parseFloat(o?.getAttribute(`data-width`)??``),c=Number.parseFloat(o?.getAttribute(`data-height`)??``),l={width:s>0?s:o.getBoundingClientRect().width||1,height:c>0?c:o.getBoundingClientRect().height||1},u=[];for(let n of a){let r=n.element;if(!m(r)||Wrn(r.getBoundingClientRect(),l))continue;let i=I4(t,e,r);i&&u.push({element:r,rect:{left:i.left,top:i.top,width:i.width,height:i.height}})}return u}function lan(e,t){return t.filter(t=>Tqt(e,t.rect))}async function uan(e,t){let n=!t||t===`index.html`,r=[];for(let i of e){let e=await c(i,{activeCompositionPath:t,isMasterView:n,skipSourceProbe:!0});e&&r.push(e)}return r}function dan(e){e?.changed&&e.count>1&&m4(`multi_select`,`drag`)}function fan(e){try{e.target.releasePointerCapture(e.pointerId)}catch{}}function pan(e){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)([]),o=(0,U.useRef)(null),s=(0,U.useCallback)(async(t,n)=>{let r=e.iframeRef.current,i=e.overlayRef.current;if(!r||!i||!e.onMarqueeSelectRef.current)return;let a=e.activeCompositionPathRef.current??`index.html`,s=lan(t,oan(o.current,r,i,a)).map(e=>e.element),c=e.resolveHits,l=c?await c(s):await uan(s,a),u=e.onMarqueeSelectRef.current;u&&dan(u(l,n))},[e.iframeRef,e.overlayRef,e.onMarqueeSelectRef,e.activeCompositionPathRef,e.resolveHits]),c=(0,U.useCallback)(()=>{t.current=null,r(null),a([]),o.current=null},[]),l=(0,U.useCallback)(n=>{let r=e.overlayRef.current?.getBoundingClientRect();if(!r)return;n.currentTarget.setPointerCapture(n.pointerId);let i=n.clientX-r.left,a=n.clientY-r.top;t.current={startX:i,startY:a,currentX:i,currentY:a,pointerId:n.pointerId,pastThreshold:!1,target:n.currentTarget}},[e.overlayRef]),u=(0,U.useCallback)(()=>{t.current&&(fan(t.current),c())},[c]);(0,U.useEffect)(()=>{let e=e=>{e.key!==`Escape`||!t.current||(e.preventDefault(),e.stopPropagation(),u())};return window.addEventListener(`keydown`,e,{capture:!0}),()=>window.removeEventListener(`keydown`,e,{capture:!0})},[u]);let d=(0,U.useCallback)(t=>{let n=e.iframeRef.current,r=e.overlayRef.current;if(!n||!r)return;let i=e.activeCompositionPathRef.current??`index.html`;o.current??=can(n,r,i),a(lan(t,o.current).map(e=>e.rect))},[e.overlayRef,e.iframeRef,e.activeCompositionPathRef]);return{marqueeRect:n,candidateRects:i,begin:l,cancel:u,onPointerMove:(0,U.useCallback)(n=>{let i=t.current;if(i){if(!J4(i,n))return;let t=e.overlayRef.current?.getBoundingClientRect();if(!t)return;if(i.currentX=n.clientX-t.left,i.currentY=n.clientY-t.top,!i.pastThreshold){let e=i.currentX-i.startX,t=i.currentY-i.startY;if(Math.hypot(e,t)<san)return;i.pastThreshold=!0,o.current=null}let a={left:Math.min(i.startX,i.currentX),top:Math.min(i.startY,i.currentY),width:Math.abs(i.currentX-i.startX),height:Math.abs(i.currentY-i.startY)};r(a),d(a);return}e.gestures?.onPointerMove(n)},[e.gestures,e.overlayRef,d]),onPointerUp:(0,U.useCallback)(n=>{let r=t.current;if(r){fan(r),r.pastThreshold?s({left:Math.min(r.startX,r.currentX),top:Math.min(r.startY,r.currentY),width:Math.abs(r.currentX-r.startX),height:Math.abs(r.currentY-r.startY)},n.shiftKey):e.onMarqueeSelectRef.current?.([],!1),c();return}e.gestures?.onPointerUp(n)},[e.gestures,s,e.onMarqueeSelectRef,c]),onPointerCancel:(0,U.useCallback)(()=>{if(t.current)return u();e.selectionRef&&e.gestures?.clearPointerState(e.selectionRef)},[e.gestures,e.selectionRef,u])}}function man({candidateRects:e,marqueeRect:t}){return(0,W.jsxs)(W.Fragment,{children:[e.map((e,t)=>(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute rounded-xs border border-studio-accent bg-studio-accent/5`,style:{left:e.left,top:e.top,width:e.width,height:e.height}},t)),t&&(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute border border-dashed border-studio-accent bg-studio-accent/10`,style:{left:t.left,top:t.top,width:t.width,height:t.height}})]})}var han=600;function gan({overlayRef:e,iframeRef:t}){let[n,r]=(0,U.useState)(null),i=(0,U.useRef)(null);return(0,U.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),{zOrderFlashRect:n,handleZOrderCrossed:(0,U.useCallback)(n=>{let a=e.current,o=t.current;if(!a||!o)return;let s=I4(a,o,n);!s||s.width<=0||s.height<=0||(i.current&&clearTimeout(i.current),r(s),i.current=setTimeout(()=>{i.current=null,r(null)},han))},[e,t])}}function _an({rect:e}){return e?(0,W.jsx)(`div`,{"aria-hidden":`true`,"data-dom-edit-z-flash":`true`,className:`pointer-events-none absolute rounded-md border-2 border-studio-accent shadow-[0_0_0_2px_rgba(60,230,172,0.35)] animate-pulse`,style:{left:e.left,top:e.top,width:e.width,height:e.height}}):null}function van({selection:e,selectionRef:t,hoverSelectionRef:n,onCanvasPointerMoveRef:r,onSelectionChangeRef:i}){let[a,o]=(0,U.useState)(null),s=(0,U.useCallback)(()=>o(null),[]);return(0,U.useEffect)(()=>{a&&(!e||e.element!==a.sel.element)&&o(null)},[e,a]),{contextMenu:a,closeContextMenu:s,handleContextMenu:(0,U.useCallback)(async e=>{e.preventDefault();let a=t.current,s=a;if(a){let e=n.current;e&&e.element!==a.element&&(i.current(e,{revealPanel:!0}),s=e)}else{let t=e,n=await r.current(t);if(!n)return;i.current(n,{revealPanel:!0}),s=n}s&&o({x:e.clientX,y:e.clientY,sel:s})},[t,n,r,i])}}function yan(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!H4(e[n],t[n]))return!1;return!0}function ban({iframeRef:e,overlayRef:t,selectionRef:n,activeCompositionPathRef:r,groupSelectionsRef:i,hoverSelectionRef:a,rafPausedRef:o}){let[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)([]),[p,m]=(0,U.useState)([]),h=(0,U.useRef)(null),g=(0,U.useRef)(null),_=(0,U.useRef)([]),v=(0,U.useRef)(null),y=(0,U.useRef)(null),b=(0,U.useRef)(new Map),x=(0,U.useRef)([]),S=e=>{H4(h.current,e)||(h.current=e,c(e))},C=e=>{H4(g.current,e)||(g.current=e,u(e))},w=e=>{Uin(_.current,e)||(_.current=e,f(e))},T=(e,t)=>{let n=G4(t),i=b.current.get(n);if(i?.isConnected&&i.ownerDocument===e)return i;let a=He(e,t,r.current);return a?b.current.set(n,a):b.current.delete(n),a};return ax(()=>{let s=()=>{S(null),C(null),w([])};return X2(()=>{if(o.current){x.current.length>0&&(x.current=[],m([]));return}let c=n.current,l=e.current,u=t.current;if(!l||!u){v.current=null,y.current=null,b.current.clear(),s();return}let d=l.contentDocument;if(!d){v.current=null,y.current=null,b.current.clear(),s();return}let f=C4(u,l,d);if(c){let e=Kin(d,c,r.current,v);if(e&&F4(e)){let t=W4(u,l,e,f);S(t);let n=e.querySelectorAll(`*`);if(n.length>0&&n.length<=60){let e=[];for(let t=0;t<n.length;t++){let r=n[t];if(!r.getBoundingClientRect)continue;let i=Vin(u,l,r,f);i&&i.width>2&&i.height>2&&e.push(i)}yan(x.current,e)||(x.current=e,m(e))}else x.current.length>0&&(x.current=[],m([]))}else S(null),x.current.length>0&&(x.current=[],m([]))}else v.current=null,S(null),x.current.length>0&&(x.current=[],m([]));let p=i.current;if(p.length>0){let e=[],t=new Set;for(let n of p){let r=G4(n);if(t.has(r))continue;t.add(r);let i=T(d,n),a=i?Win(u,l,i,f):null,o=a&&i?{...a,...j4(a,i)}:a;i&&o&&e.push({key:r,selection:n,element:i,rect:o})}for(let e of b.current.keys())t.has(e)||b.current.delete(e);w(e)}else b.current.clear(),w([]);let h=a.current,g=!!(c&&h&&G4(c)===G4(h)),_=!!(h&&p.some(e=>G4(e)===G4(h)));if(!h||g||_){y.current=null,C(null);return}let E=Kin(d,h,r.current,y);if(!E){C(null);return}C(W4(u,l,E,f))})}),{overlayRect:s,overlayRectRef:h,setOverlayRect:S,hoverRect:l,hoverRectRef:g,setHoverRect:C,groupOverlayItems:d,groupOverlayItemsRef:_,setGroupOverlayItems:w,childRects:p}}function xan(e,t){let n=e.angle??0;if(!n){let n=Math.max(0,t.left-e.left),r=Math.max(0,t.top-e.top),i=Math.min(e.width,t.left+t.width-e.left),a=Math.min(e.height,t.top+t.height-e.top);return n>=i||r>=a?void 0:`polygon(evenodd, 0 0, ${e.width}px 0, ${e.width}px ${e.height}px, 0 ${e.height}px, 0 0, ${n}px ${r}px, ${i}px ${r}px, ${i}px ${a}px, ${n}px ${a}px, ${n}px ${r}px)`}let r=-n*Math.PI/180,i=Math.cos(r),a=Math.sin(r),o=e.left+e.width/2,s=e.top+e.height/2,c=(t,n)=>{let r=t-o,c=n-s;return`${e.width/2+r*i-c*a}px ${e.height/2+r*a+c*i}px`},l=t.left,u=t.top,d=l+t.width,f=u+t.height,p=[c(l,u),c(d,u),c(d,f),c(l,f),c(l,u)].join(`, `);return`polygon(evenodd, 0 0, ${e.width}px 0, ${e.width}px ${e.height}px, 0 ${e.height}px, 0 0, ${p})`}function San({rects:e,elements:t,compRect:n,selection:r,groupSelections:i,activeCompositionPathRef:a,onSelectionChangeRef:o}){return(0,W.jsx)(W.Fragment,{children:e.filter(e=>{let n=t.current.get(e.key);return!n||r?.element!==n&&!i.some(e=>e.element===n)}).map(e=>{let r={left:e.left,top:e.top,width:e.width,height:e.height,transform:e.angle?`rotate(${e.angle}deg)`:void 0,transformOrigin:`center`},i=xan(e,n),s=async()=>{let n=t.current.get(e.key);if(!n)return;let{resolveDomEditSelection:r}=await Mb(async()=>{let{resolveDomEditSelection:e}=await import(`./domEditingLayers-KBTPQKGA-tvsAmAbb.js`);return{resolveDomEditSelection:e}},__vite__mapDeps([4,5])),i=a.current??`index.html`,s=await r(n,{activeCompositionPath:i,isMasterView:!i||i===`index.html`,skipSourceProbe:!0});s&&o.current(s,{revealPanel:!0})};return(0,W.jsx)(`div`,{className:`pointer-events-none absolute`,style:r,children:(0,W.jsx)(`div`,{role:`button`,tabIndex:0,"aria-label":`Select off-canvas element ${e.key}`,className:`pointer-events-auto absolute inset-0 border-2 border-dashed border-studio-accent/10 rounded-md cursor-pointer hover:border-studio-accent hover:bg-studio-accent/10 transition-colors`,style:i?{clipPath:i}:void 0,title:`Off-canvas: ${e.key} \u2014 click to select`,onClick:e=>{e.stopPropagation(),s()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),s())}})},`offcanvas-${e.key}`)})})}function Can({rects:e}){return(0,W.jsx)(W.Fragment,{children:e.map((e,t)=>(0,W.jsx)(`div`,{className:`pointer-events-none absolute border border-dashed border-white/20 rounded-xs`,style:{left:e.left,top:e.top,width:e.width,height:e.height,transform:e.angle?`rotate(${e.angle}deg)`:void 0}},t))})}var Y4=1,wan=3;function Tan(e){let t=Math.hypot(e.pointerStart.x-e.centerStart.x,e.pointerStart.y-e.centerStart.y);return!Number.isFinite(t)||t<wan?1:Math.hypot(e.pointer.x-e.centerStart.x,e.pointer.y-e.centerStart.y)/t}function Ean(e){let t=Math.max(e.baseWidth,Y4),n=Math.max(e.baseHeight,Y4),r=Tan({pointer:e.pointer,pointerStart:e.pointerStart,centerStart:e.centerStart}),i=Y4/Math.min(t,n),a=Math.max(i,r);return{width:t*a,height:n*a}}var Dan=[`ns-resize`,`nesw-resize`,`ew-resize`,`nwse-resize`,`ns-resize`,`nesw-resize`,`ew-resize`,`nwse-resize`],Oan={nw:315,ne:45,se:135,sw:225};function kan(e,t){let n=((Oan[e]+t)%360+360)%360;return Dan[Math.round(n/45)%8]}function Aan(e,t,n){let r=e??{dx:0,dy:0};return{dx:r.dx+(t.x-n.x),dy:r.dy+(t.y-n.y)}}function jan(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Man(e){return e.trim().replace(/\\/g,`/`).replace(/^\.?\//,``)}function X4(e){return e&&typeof e==`object`?e:null}function Z4(e,t){let n=X4(e)?.[t];return typeof n==`string`?n:null}function Q4(e){let t=Z4(e,`path`)??Z4(e,`filePath`);return t===null?null:Man(t)}function $4(e){return X4(e)?.affectsPreview!==!1}function e3(e){let t=X4(e)?.affectedCompositions;return!Array.isArray(t)||!t.every(e=>typeof e==`string`)?null:t.map(Man)}function t3(e,t){let n=e3(e),r=e3(t),i=n&&r?[...new Set([...n,...r])]:null,a=X4(t),o=$4(e)||$4(t);return Q4(e)===Q4(t)?{...a,affectsPreview:o,affectedCompositions:i}:{path:`.`,projectId:a?.projectId,affectsPreview:o,affectedCompositions:i}}function n3(e,t){let n=Array.from(e.querySelectorAll(`[${t}="true"]`)).filter(O),r=`data-${t}`;for(let i of e.querySelectorAll(`[${r}="true"]`))O(i)&&!i.hasAttribute(t)&&(i.setAttribute(t,`true`),i.removeAttribute(r),n.push(i));return n}function Nan(e){for(let t of n3(e,Q1)){if(R0(t,[`x`,`y`]))continue;let e=t.style.getPropertyValue(nj),n=t.style.getPropertyValue(rj);!e&&!n||yen(t,{x:Number.parseFloat(e)||0,y:Number.parseFloat(n)||0},{updateBase:!1})}}function Pan(e){for(let t of n3(e,e0)){let e=Number.parseFloat(t.style.getPropertyValue(ij)),n=Number.parseFloat(t.style.getPropertyValue(aj));Number.isFinite(e)&&Number.isFinite(n)&&e>0&&n>0&&r2(t,{width:e,height:n})}}function Fan(e){for(let t of n3(e,t0)){let e=Number.parseFloat(t.style.getPropertyValue(Z1));Number.isFinite(e)&&jen(t,{angle:e})}}var r3=[Q1,e0,t0].flatMap(e=>[e,`data-${e}`]).concat(IJ),Ian=r3.map(e=>e===IJ?`[${e}]`:`[${e}="true"]`),i3=new WeakMap;function Lan(e){return Ian.some(t=>e.querySelector(t)!==null)}function Ran(e){let t=e.defaultView?.MutationObserver;if(!t)return Lan(e);let n=i3.get(e);if(!n){let r={observer:new t(()=>{r.stale=!0}),stale:!0,has:!1};r.observer.observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:r3}),i3.set(e,r),n=r}return n.observer.takeRecords().length>0&&(n.stale=!0),n.stale&&(n.has=Lan(e),n.stale=!1),n.has}function zan(e){return!!e.defaultView?.__timelines?.[FJ]||Ran(e)}function a3(e){zan(e)&&(Nan(e),Pan(e),Fan(e),aUt(e),i3.get(e)?.observer.takeRecords())}function o3(e){return{width:e.style.getPropertyValue(`width`),height:e.style.getPropertyValue(`height`),minWidth:e.style.getPropertyValue(`min-width`),minHeight:e.style.getPropertyValue(`min-height`),maxWidth:e.style.getPropertyValue(`max-width`),maxHeight:e.style.getPropertyValue(`max-height`),flexBasis:e.style.getPropertyValue(`flex-basis`),flexGrow:e.style.getPropertyValue(`flex-grow`),flexShrink:e.style.getPropertyValue(`flex-shrink`),boxSizing:e.style.getPropertyValue(`box-sizing`),scale:e.style.getPropertyValue(`scale`),transformOrigin:e.style.getPropertyValue(`transform-origin`),display:e.style.getPropertyValue(`display`),studioWidth:e.style.getPropertyValue(ij),studioHeight:e.style.getPropertyValue(aj),marker:e.getAttribute(e0),originalWidth:e.getAttribute(i0),originalHeight:e.getAttribute(a0),originalBoxWidth:e.getAttribute(o0),originalBoxHeight:e.getAttribute(s0),originalMinWidth:e.getAttribute(c0),originalMinHeight:e.getAttribute(l0),originalMaxWidth:e.getAttribute(u0),originalMaxHeight:e.getAttribute(d0),originalFlexBasis:e.getAttribute(f0),originalFlexGrow:e.getAttribute(p0),originalFlexShrink:e.getAttribute(m0),originalBoxSizing:e.getAttribute(h0),originalScale:e.getAttribute(g0),originalTransformOrigin:e.getAttribute(_0),originalDisplay:e.getAttribute(v0)}}function s3(e){return{rotate:e.style.getPropertyValue(`rotate`),transform:e.style.getPropertyValue(`transform`),display:e.style.getPropertyValue(`display`),transformOrigin:e.style.getPropertyValue(`transform-origin`),studioRotation:e.style.getPropertyValue(Z1),marker:e.getAttribute(t0),draftMarker:e.getAttribute(S0),originalRotate:e.getAttribute(y0),originalInlineRotate:e.getAttribute(b0),originalTransformOrigin:e.getAttribute(x0)}}function c3(e){return{translate:e.style.getPropertyValue(`translate`),x:e.style.getPropertyValue(nj),y:e.style.getPropertyValue(rj),marker:e.getAttribute(Q1),originalTranslate:e.getAttribute(n0),originalInlineTranslate:e.getAttribute(r0)}}function l3(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function u3(e,t,n){n?e.style.setProperty(t,n):e.style.removeProperty(t)}function d3(e,t){a2(e),u3(e,`width`,t.width),u3(e,`height`,t.height),u3(e,`min-width`,t.minWidth),u3(e,`min-height`,t.minHeight),u3(e,`max-width`,t.maxWidth),u3(e,`max-height`,t.maxHeight),u3(e,`flex-basis`,t.flexBasis),u3(e,`flex-grow`,t.flexGrow),u3(e,`flex-shrink`,t.flexShrink),u3(e,`box-sizing`,t.boxSizing),u3(e,`scale`,t.scale),u3(e,`transform-origin`,t.transformOrigin),u3(e,`display`,t.display),u3(e,ij,t.studioWidth),u3(e,aj,t.studioHeight),l3(e,e0,t.marker),l3(e,i0,t.originalWidth),l3(e,a0,t.originalHeight),l3(e,o0,t.originalBoxWidth),l3(e,s0,t.originalBoxHeight),l3(e,c0,t.originalMinWidth),l3(e,l0,t.originalMinHeight),l3(e,u0,t.originalMaxWidth),l3(e,d0,t.originalMaxHeight),l3(e,f0,t.originalFlexBasis),l3(e,p0,t.originalFlexGrow),l3(e,m0,t.originalFlexShrink),l3(e,h0,t.originalBoxSizing),l3(e,g0,t.originalScale),l3(e,_0,t.originalTransformOrigin),l3(e,v0,t.originalDisplay)}function f3(e,t){u3(e,`rotate`,t.rotate),u3(e,`transform-origin`,t.transformOrigin),u3(e,Z1,t.studioRotation),l3(e,t0,t.marker),l3(e,S0,t.draftMarker),l3(e,y0,t.originalRotate),l3(e,b0,t.originalInlineRotate),l3(e,x0,t.originalTransformOrigin)}function p3(e,t){t.translate?e.style.setProperty(`translate`,t.translate):e.style.removeProperty(`translate`),t.x?e.style.setProperty(nj,t.x):e.style.removeProperty(nj),t.y?e.style.setProperty(rj,t.y):e.style.removeProperty(rj),l3(e,Q1,t.marker),l3(e,n0,t.originalTranslate),l3(e,r0,t.originalInlineTranslate);let n=e.getAttribute(`data-hf-drag-gsap-base-x`),r=e.getAttribute(`data-hf-drag-gsap-base-y`);if(n!=null||r!=null){let t=e.ownerDocument.defaultView;if(t?.gsap){let i=Number.parseFloat(n??`0`)||0,a=Number.parseFloat(r??`0`)||0;t.gsap.set(e,{x:i,y:a})}e.removeAttribute(`data-hf-drag-gsap-base-x`),e.removeAttribute(`data-hf-drag-gsap-base-y`)}}function m3(e,t,n){let r=e.getAttribute(n);r==null||r===``?e.style.removeProperty(t):e.style.setProperty(t,r),e.removeAttribute(n)}function Ban(e){let t=e.getAttribute(b0);t==null||t===``?e.style.removeProperty(`rotate`):e.style.setProperty(`rotate`,t),e.removeAttribute(b0),e.removeAttribute(y0);let n=e.getAttribute(x0);n!=null&&(n===``?e.style.removeProperty(`transform-origin`):e.style.setProperty(`transform-origin`,n)),e.removeAttribute(x0)}function Van(e){let t=e.getAttribute(r0);t==null||t===``?e.style.removeProperty(`translate`):e.style.setProperty(`translate`,t),e.removeAttribute(r0),e.removeAttribute(n0)}function Han(e){(e.hasAttribute(Q1)||e.hasAttribute(r0)||$0(e.style.getPropertyValue(`translate`)))&&Van(e),n2(e),e.style.removeProperty(nj),e.style.removeProperty(rj),e.removeAttribute(Q1),e.removeAttribute(n0),e.removeAttribute(r0)}function Uan(e){(e.hasAttribute(t0)||e2(e.style.getPropertyValue(`rotate`)))&&Ban(e),n2(e),e.style.removeProperty(Z1),e.removeAttribute(t0),e.removeAttribute(S0),e.removeAttribute(y0),e.removeAttribute(b0),e.removeAttribute(x0)}function h3(e){a2(e),(e.hasAttribute(e0)||uen(e.style.getPropertyValue(`width`))||uen(e.style.getPropertyValue(`height`))||e.hasAttribute(g0))&&(m3(e,`width`,i0),m3(e,`height`,a0),m3(e,`min-width`,c0),m3(e,`min-height`,l0),m3(e,`max-width`,u0),m3(e,`max-height`,d0),m3(e,`flex-basis`,f0),m3(e,`flex-grow`,p0),m3(e,`flex-shrink`,m0),m3(e,`box-sizing`,h0),m3(e,`scale`,g0),m3(e,`transform-origin`,_0),m3(e,`display`,v0)),n2(e),e.style.removeProperty(ij),e.style.removeProperty(aj),e.removeAttribute(e0)}function g3(e){try{Object.defineProperty(e,w0,{configurable:!1,enumerable:!1,value:!0})}catch{try{e[w0]=!0}catch{}}}function _3(e){return!!e[w0]}function v3(e,t,n,r=!1){let i=t?.[n];if(!t||typeof i!=`function`)return!1;let a=i;if(_3(a))return!0;let o=function(...t){let n=a.apply(this,t);e.__hfStudioManualEditsApply?.();let i=r?n:void 0;return typeof i?.then==`function`&&i.then(()=>e.__hfStudioManualEditsApply?.()),n};g3(o);try{t[n]=o}catch{return!1}return!0}function y3(e,t){let n=e[t];if(typeof n!=`function`)return null;try{return jan(n.call(e))}catch{return null}}function Wan(e){let t=y3(e,`duration`)??y3(e,`getDuration`);if(t==null)return!0;if(t<=0)return!1;let n=y3(e,`time`)??y3(e,`totalTime`)??y3(e,`getTime`);return n==null||n<t}function Gan(e){let t=e.parent;for(let e=0;e<32&&t&&typeof t==`object`;e++){let e=t,n=e.paused;try{if(typeof n==`function`&&n.call(e))return!0}catch{return!1}t=e.parent}return!1}function b3(e){if(!e)return!1;let t=e.isPlaying;if(typeof t==`function`)try{return!!t.call(e)}catch{return!1}let n=e.paused;if(typeof n==`function`){try{if(n.call(e))return!1}catch{return!1}let t=e.isActive;if(typeof t==`function`)try{if(t.call(e))return!0}catch{return!1}return!Gan(e)&&Wan(e)}let r=e.isActive;if(typeof r==`function`)try{return!!r.call(e)}catch{return!1}return!1}function Kan(e){return b3(e.__player)||b3(e.__timeline)?!0:Object.values(e.__timelines??{}).some(b3)}function qan(e){if(e.__hfStudioManualEditsApply?.(),e[T0]!=null)return;let t=()=>{if(e.__hfStudioManualEditsApply?.(),!Kan(e)){e[T0]=null;return}e[T0]=e.requestAnimationFrame(t)};e[T0]=e.requestAnimationFrame(t)}function x3(e,t,n){let r=t?.[n];if(!t||typeof r!=`function`)return!1;let i=r;if(_3(i))return!0;let a=function(...t){let n=i.apply(this,t);return qan(e),n};g3(a);try{t[n]=a}catch{return!1}return!0}function S3(e,t,n){let r=t?.[n];if(!t||typeof r!=`function`)return!1;let i=r;if(_3(i))return!0;let a=function(...t){let n=i.apply(this,t);return e.__hfStudioManualEditsApply?.(),n};g3(a);try{t[n]=a}catch{return!1}return!0}function Jan(e,t){let n=e;n[Y7t]=t;let r=v3(n,n.__hf,`seek`),i=v3(n,n.__player,`seek`,!0),a=v3(n,n.__player,`renderSeek`),o=v3(n,n.__timeline,`seek`);v3(n,n.__timeline,`totalTime`);let s=x3(n,n.__player,`play`),c=x3(n,n.__timeline,`play`),l=S3(n,n.__player,`pause`),u=S3(n,n.__timeline,`pause`),d=!1,f=!1,p=!1;for(let e of Object.values(n.__timelines??{}))d=v3(n,e,`seek`)||d,v3(n,e,`totalTime`),f=x3(n,e,`play`)||f,p=S3(n,e,`pause`)||p;if(n.__timelines&&!n.__timelines.__proxied){let e=n.__timelines;n.__timelines=new Proxy(e,{set(e,t,r){if(e[t]=r,typeof r==`object`&&r){let e=r;v3(n,e,`seek`),v3(n,e,`totalTime`),x3(n,e,`play`),S3(n,e,`pause`),n.__hfStudioManualEditsApply?.()}return!0}}),n.__timelines.__proxied=!0}return Kan(n)&&qan(n),r||i||a||o||s||c||l||u||d||f||p}var C3=(e,t)=>{let n=e.getPropertyValue(t).trim();return n===`none`?``:n};function w3(e,t=!0){let n=e.ownerDocument.defaultView;if(!n)return 0;let r=n.getComputedStyle(e),i=t?C3(r,`rotate`):``,a=C3(r,`scale`),o=C3(r,`transform`),s=e=>{if(!e)return 0;let t=new n.DOMMatrix(e);return Math.atan2(t.b,t.a)*180/Math.PI},c=[i&&`rotate(${i})`,a&&`scale(${a.split(/\s+/).join(`,`)})`];try{return s([...c,o].join(` `).trim())}catch{return s(o)}}function T3(e){let t=t=>Number.parseFloat(e.getAttribute(t)??``);return{origX:t(`data-hf-drag-initial-offset-x`)||0,origY:t(`data-hf-drag-initial-offset-y`)||0,baseX:t(`data-hf-drag-gsap-base-x`),baseY:t(`data-hf-drag-gsap-base-y`),at:Yan(e)}}function Yan(e){let t=e.getAttribute($1);return t?JSON.parse(t):void 0}var E3=e=>({...T3(e),frozen:!0});function D3(e,t,n,r=T3(e)){let i=e.style.getPropertyValue(`--hf-studio-rotation`),a=-(Number.parseFloat(i)||0)*Math.PI/180,o=Math.cos(a),s=Math.sin(a),c=t.x-r.origX,l=t.y-r.origY,u=c*o-l*s,d=c*s+l*o,f=Number.isFinite(r.baseX)?r.baseX:n.x,p=Number.isFinite(r.baseY)?r.baseY:n.y;return{newX:S(f+u),newY:S(p+d),baseGsapX:f,baseGsapY:p}}function O3(e,t=T3(e)){t.frozen||(e.style.setProperty(`--hf-studio-offset-x`,`${t.origX}px`),e.style.setProperty(`--hf-studio-offset-y`,`${t.origY}px`),e.removeAttribute(`data-hf-drag-initial-offset-x`),e.removeAttribute(`data-hf-drag-initial-offset-y`))}var k3=/\s*(?:(\d*\.?\d+(?:e[-+]?\d+)?)(px|%)?|([a-z]+)\(|([-+*/(),]))/giy,Xan={"(":([e=NaN])=>e,"calc(":([e=NaN])=>e,"min(":e=>Math.min(...e),"max(":e=>Math.max(...e),"clamp(":([e=NaN,t=NaN,n=NaN])=>Math.max(e,Math.min(t,n))};function Zan(e,t){let n=[],r=e.trimEnd().length;k3.lastIndex=0;for(let i=k3.exec(e);i;i=k3.lastIndex<r?k3.exec(e):null)i[1]?n.push(Number(i[1])*(i[2]===`%`?t/100:1)):n.push(i[3]?`${i[3].toLowerCase()}(`:i[4]??``);return k3.lastIndex<r?[]:n}function A3(e,t){let n=Zan(e,t),r=0,i=()=>n[r++],a=(...e)=>e.includes(n[r])&&i();function o(){let e=s();for(let t=a(`+`,`-`);t;t=a(`+`,`-`))e+=(t===`+`?1:-1)*s();return e}function s(){let e=c();for(let t=a(`*`,`/`);t;t=a(`*`,`/`))e=t===`*`?e*c():e/c();return e}function c(){return a(`-`)?-c():l()}function l(){let e=i();if(typeof e==`number`)return e;let t=Xan[e??``];if(!t)return NaN;let n=[o()];for(;a(`,`);)n.push(o());return a(`)`)?t(n):NaN}let u=n.length?o():NaN;return r===n.length?u:NaN}var Qan=new Set([`content-box`,`fill-box`]);function $an(e,t,n,r){let i=t=>Number.parseFloat(e.getPropertyValue(t))||0,a=i(`padding-${n}`)+i(`padding-${r}`)+i(`border-${n}-width`)+i(`border-${r}-width`),o=i(t)-(e.boxSizing===`border-box`?a:0);return Qan.has(e.getPropertyValue(`transform-box`))?o:o+a}function eon(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=t?.translate||e.style.getPropertyValue(`translate`)||`none`;if(n===`none`)return{x:0,y:0};let[r=`0px`,i=`0px`]=V0(n),a=(e,n,r)=>t?$an(t,e,n,r):0;return{x:A3(r,a(`width`,`left`,`right`)),y:A3(i,a(`height`,`top`,`bottom`))}}function ton(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e).translate||`none`,[n=`0px`,r=`0px`]=t===`none`?[]:V0(t),i=e=>S(A3(e,0))||0;return{x:i(n),y:i(r)}}var non=`Studio can't read this layer's translate. Move it in the Code tab.`;function ron(e){return`${S(e.x)}px ${S(e.y)}px`}var ion=[nj,rj];function aon(e,t){j3(e,t);let n=[{type:`inline-style`,property:`translate`,value:ron(t)},{type:`attribute`,property:r0,value:e.getAttribute(r0)}];for(let t of ion.filter(t=>e.style.getPropertyValue(t)))e.style.removeProperty(t),n.push({type:`inline-style`,property:t,value:null});return e.hasAttribute(Q1)&&(e.removeAttribute(Q1),n.push({type:`attribute`,property:Q1,value:null})),n}function j3(e,t){if(!e.hasAttribute(r0)){let t=e.style.getPropertyValue(`translate`);e.setAttribute(r0,$0(t)?``:t)}e.style.setProperty(`translate`,ron(t))}function oon(e,t=B0(e,`move`)){return t?eon(e):oen(e)}function son(e){return B0(e,`rotate`)?{angle:S(w3(e))}:cen(e)}function M3(e){let t=e.ownerDocument.defaultView?.gsap;return t?.set&&t.getProperty?t:null}function con(e,t,n){let r=M3(e);if(!r)return!1;e.style.setProperty(`translate`,`none`);let{newX:i,newY:a}=D3(e,t,n);return r.set(e,{x:i,y:a}),!0}var lon=100,uon=.01,don=1e-6;function N3(e){return Number.isFinite(e.x)&&Number.isFinite(e.y)}function fon(e){return Math.hypot(e.x,e.y)}function pon(e){return Number.isFinite(e.left)&&Number.isFinite(e.top)&&Number.isFinite(e.width)&&Number.isFinite(e.height)}function mon(e){let t=e.document.documentElement,n=e.innerWidth||t.clientWidth||1,r=e.innerHeight||t.clientHeight||1;return{width:n>0?n:1,height:r>0?r:1}}function hon(e){try{let t=e.frameElement;return t&&O(t)?t:null}catch{return null}}function P3(e){let t=e.getBoundingClientRect();if(!pon(t)||t.width<=0&&t.height<=0)return null;let n={x:t.left+t.width/2,y:t.top+t.height/2};return F3(e.ownerDocument,n)}function F3(e,t){let n=e.defaultView;for(;n;){let e=hon(n);if(!e)break;let r=e.getBoundingClientRect();if(!pon(r)||r.width<=0||r.height<=0)return null;let i=mon(n);t={x:r.left+t.x*(r.width/i.width),y:r.top+t.y*(r.height/i.height)},n=e.ownerDocument.defaultView}return t}function gon(e){let t=e.a*e.d-e.b*e.c;return!Number.isFinite(t)||Math.abs(t)<don?null:{a:e.d/t,b:-e.b/t,c:-e.c/t,d:e.a/t}}function _on(e,t){return{x:e.a*t.x+e.c*t.y,y:e.b*t.x+e.d*t.y}}function von(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e).transform;if(!t||!t.startsWith(`matrix3d(`))return 1;let n=t.slice(9,-1).split(`,`),r=Number.parseFloat(n[15]??``);return Number.isFinite(r)&&r>0?r:1}function yon(e,t,n={}){let r=n.probeSize??lon;if(!Number.isFinite(r)||r<=0)return{ok:!1,reason:`Invalid movement probe size.`};let i=n.plainTranslate?j3:ben,a=c3(e);try{i(e,t);let n=P3(e);if(!n)return{ok:!1,reason:`Element has no measurable box.`};i(e,{x:t.x+r,y:t.y});let a=P3(e);if(!a)return{ok:!1,reason:`Element X movement could not be measured.`};i(e,{x:t.x,y:t.y+r});let o=P3(e);if(!o)return{ok:!1,reason:`Element Y movement could not be measured.`};let s={x:(a.x-n.x)/r,y:(a.y-n.y)/r},c={x:(o.x-n.x)/r,y:(o.y-n.y)/r};if(!N3(s)||!N3(c)||fon(s)<uon||fon(c)<uon)return{ok:!1,reason:`Element movement response is too small to measure.`};let l=gon({a:s.x,b:s.y,c:c.x,d:c.y});return l?{ok:!0,matrix:l}:{ok:!1,reason:`Element movement response is not invertible.`}}finally{p3(e,a)}}function bon(e){let t=_on(e.screenToOffset,{x:e.dx,y:e.dy});return{x:e.initialOffset.x+t.x,y:e.initialOffset.y+t.y}}function I3(e){let t=!!e.gesture&&B0(e.element,e.gesture===`resize`?`resize`:`move`),n=t?eon(e.element):sen(e.element);if(!N3(n))return{ok:!1,reason:non,selection:e.selection};let r=e.element.ownerDocument.defaultView,i={x:!t&&r?.gsap?.getProperty?.(e.element,`x`)||0,y:!t&&r?.gsap?.getProperty?.(e.element,`y`)||0};if(t||z3(e.element,n,i),r?.__timelines){let t=[];for(let[e,n]of Object.entries(r.__timelines))try{n?.pause&&!n.paused?.()&&(n.pause(),t.push(e))}catch{}t.length>0&&e.element.setAttribute(`data-hf-drag-paused-timelines`,t.join(`,`))}let a=c3(e.element),o=H0(e.element,e.gesture===`resize`?`resize`:`move`,e.at),s=yon(e.element,n,{scaleX:e.rect.editScaleX,scaleY:e.rect.editScaleY,plainTranslate:t});if(!s.ok){let r=e.rect.editScaleX||1,s=e.rect.editScaleY||1,c=von(e.element);return{ok:!0,member:{key:e.key,selection:e.selection,element:e.element,initialOffset:n,plainTranslate:t,baseGsap:i,initialPathOffset:a,gestureToken:o,screenToOffset:{a:c/r,b:0,c:0,d:c/s},originRect:e.rect}}}return{ok:!0,member:{key:e.key,selection:e.selection,element:e.element,initialOffset:n,plainTranslate:t,baseGsap:i,initialPathOffset:a,gestureToken:o,screenToOffset:s.matrix,originRect:e.rect}}}function xon(e,t,n){return bon({initialOffset:e.initialOffset,screenToOffset:e.screenToOffset,dx:t,dy:n})}function L3(e,t,n){if(e.plainTranslate)j3(e.element,t);else if(con(e.element,t,e.baseGsap))return;else n?yen(e.element,t):ben(e.element,t)}function R3(e,t,n){let r=xon(e,t,n);return L3(e,r,!1),r}function z3(e,t,n){e.setAttribute(`data-hf-drag-gsap-base-x`,String(n.x)),e.setAttribute(`data-hf-drag-gsap-base-y`,String(n.y)),e.setAttribute(`data-hf-drag-initial-offset-x`,String(t.x)),e.setAttribute(`data-hf-drag-initial-offset-y`,String(t.y))}function Son(e,t){return e.plainTranslate||z3(e.element,e.initialOffset,e.baseGsap),L3(e,t,!0),t}function B3(e,t,n){return Son(e,xon(e,t,n))}function Con(e,t){let n={x:e.initialOffset.x+t.x,y:e.initialOffset.y+t.y};return L3(e,n,!1),n}function won(e,t){return Son(e,{x:e.initialOffset.x+t.x,y:e.initialOffset.y+t.y})}function Ton(e){p3(e.element,e.initialPathOffset),e.plainTranslate||M3(e.element)?.set(e.element,{...e.baseGsap}),W0(e.element,e.gestureToken)}function V3(e){for(let t of e)Ton(t),Don(t.element)}function Eon(e,t){if(e.style.getPropertyValue(`translate`)===`none`&&e.style.removeProperty(`translate`),!t)return;let n=e.ownerDocument.defaultView?.getComputedStyle(e).getPropertyValue(`translate`);n&&n!==`none`&&e.style.setProperty(`translate`,`none`)}function H3(e){for(let t of e){if(!J0(t.element,t.gestureToken))continue;W0(t.element,t.gestureToken),t.element.removeAttribute(`data-hf-drag-initial-offset-x`),t.element.removeAttribute(`data-hf-drag-initial-offset-y`),t.element.removeAttribute(`data-hf-drag-gsap-base-x`),t.element.removeAttribute(`data-hf-drag-gsap-base-y`);let e=!t.plainTranslate&&!!M3(t.element);e&&Han(t.element),Eon(t.element,e),Don(t.element)}}function Don(e){let t=e.getAttribute(`data-hf-drag-paused-timelines`);if(e.removeAttribute(`data-hf-drag-paused-timelines`),!t)return;let n=e.ownerDocument.defaultView;if(!n)return;for(let e of t.split(`,`))try{n.__timelines?.[e]?.paused?.(!1)}catch{}let r=n.__player?.getTime?.()??0;n.__player?.seek?.(r)}var Oon=[`position`,`left`,`top`],kon=e=>Oon.map(t=>e.style.getPropertyValue(t));function Aon(e,t){Oon.forEach((n,r)=>{t[r]?e.style.setProperty(n,t[r]):e.style.removeProperty(n)})}function jon(e){let t=e.plainTranslate?null:M3(e.element);return{offset:c3(e.element),gsap:t&&{x:Number(t.getProperty(e.element,`x`)),y:Number(t.getProperty(e.element,`y`))},placement:kon(e.element)}}function Mon(e,t){p3(e.element,t.offset),Aon(e.element,t.placement),t.gsap&&M3(e.element)?.set(e.element,{...t.gsap}),e.plainTranslate||z3(e.element,e.initialOffset,e.baseGsap)}function U3(e){let t=e.map(e=>kon(e.element));return()=>{let n=e.map(jon);return e.forEach((e,n)=>Mon(e,{offset:e.initialPathOffset,gsap:e.plainTranslate?null:e.baseGsap,placement:t[n]})),()=>e.forEach((e,t)=>Mon(e,n[t]))}}var Non=[`x`,`y`,`rotation`,`scaleX`,`scaleY`];function Pon(e,t){let n=t?M3(e):null;return{style:e.getAttribute(`style`),gsap:n&&Object.fromEntries(Non.map(t=>[t,Number(n.getProperty(e,t))]))}}function Fon(e,t){t.style===null?e.removeAttribute(`style`):e.setAttribute(`style`,t.style),t.gsap&&M3(e)?.set(e,{...t.gsap})}function Ion(e,t){return()=>{let n=Pon(e,t.gsap!==null);return Fon(e,t),()=>Fon(e,n)}}function Lon(e){let t=``;for(let n of Array.from(e.ownerDocument.styleSheets)){let r=[];try{r=Array.from(n.cssRules)}catch{}for(let n of r){let r=n.style?.getPropertyValue(`transform`);r&&e.matches(n.selectorText)&&(t=r)}}return t}function Ron(e){let t=e.ownerDocument.defaultView,n=t?.getComputedStyle(e).transform??`none`,r=n===`none`?null:new t.DOMMatrix(n);if(!r||r.m41===0&&r.m42===0)return``;let i=e.style.getPropertyValue(`transform`)||Lon(e);return i===`none`?``:i}var zon=/^translate(?:3d|X|Y|Z)?\(/i,Bon=/^rotate\(\s*-?[\d.]+(?:e[+-]?\d+)?deg\s*\)$/i;function Von(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=t?.display===`inline`,r=Ron(e);if(!r)return{property:`rotate`,before:``,after:``,share:w3(e,!1),sign:1,inline:n};let i=V0(r),a=i.findIndex(e=>!zon.test(e)),o=a<0?i.length:a,s=i.slice(o);Bon.test(s[0]??``)&&s.shift();let[c,l]=[i.slice(0,o).join(` `),s.join(` `)],[u=1,d=u]=V0(t?.getPropertyValue(`scale`)??``).map(Number.parseFloat),f=e.style,p=[f.getPropertyValue(`transform`),f.getPropertyPriority(`transform`)];f.setProperty(`transform`,`${c} ${l}`.trim()||`none`);let m=w3(e);return f.setProperty(`transform`,p[0]??``,p[1]??``),{property:`transform`,before:c,after:l,share:m,sign:u*d<0?-1:1,inline:n}}function Hon(e,t,n=Von(e)){let r=`${S(n.sign*(t-n.share))}deg`,i=n.property===`rotate`?r:[n.before,`rotate(${r})`,n.after].filter(Boolean).join(` `),a=[{type:`inline-style`,property:n.property,value:i}];n.inline&&a.unshift({type:`inline-style`,property:`display`,value:`inline-block`});for(let t of a)e.style.setProperty(t.property,t.value);return a}function Uon(e,t){f3(e,t),e.style.setProperty(`transform`,t.transform),e.style.setProperty(`display`,t.display)}function Won(e,t,n){if(n)return void Hon(e,t,n);e.style.setProperty(`rotate`,`none`),M3(e)?.set(e,{rotation:t})}function Gon(e,t,n,r){if(r)return Uon(e,n);M3(e)?.set(e,{rotation:t-(Number.parseFloat(n.studioRotation)||0)}),f3(e,n)}function Kon(e,t){return t?w3(e):Number(M3(e)?.getProperty(e,`rotation`)??0)+cen(e).angle}var qon=4;function Jon(e,t){return Math.hypot(e,t)>=qon}var Yon=1;function W3(e){return e.left+e.width}function G3(e){return e.top+e.height}function K3(e){return e.left+e.width/2}function q3(e){return e.top+e.height/2}function Xon(e){return e.map(({rect:e,id:t})=>({left:e.left,top:e.top,right:W3(e),bottom:G3(e),centerX:K3(e),centerY:q3(e),id:t}))}function Zon(e){return{left:e.left,top:e.top,right:W3(e),bottom:G3(e),centerX:K3(e),centerY:q3(e),id:`composition`}}function Qon(e,t,n){let r=[],i=[];if(t<=0||n<=0)return{x:r,y:i};let a=t*n,o=e.left+a,s=e.left+e.width,c=0;for(;o<s;)r.push({position:o,source:`grid`,id:`grid-x-${c}`}),o+=a,c++;let l=e.top+a,u=e.top+e.height;for(c=0;l<u;)i.push({position:l,source:`grid`,id:`grid-y-${c}`}),l+=a,c++;return{x:r,y:i}}function $on(e,t,n,r,i){let a=[];for(let r of t){let t=n(r);for(let n of e)for(let e of t){let t=e-n,o=Math.abs(t);o<=i&&a.push({adjustment:t,distance:o,guidePosition:e,source:r.id===`composition`?`composition`:`element`,targetId:r.id})}}if(r)for(let t of r)for(let n of e){let e=t.position-n,r=Math.abs(e);r<=i&&a.push({adjustment:e,distance:r,guidePosition:t.position,source:`grid`,targetId:t.id})}return a}function esn(e){if(e.length===0)return null;let t=e.filter(e=>e.source===`element`||e.source===`composition`),n=e.filter(e=>e.source===`grid`),r;r=(t.length?Math.min(...t.map(e=>e.distance)):1/0)<=(n.length?Math.min(...n.map(e=>e.distance)):1/0)?t:n;let i=Math.min(...r.map(e=>e.distance)),a=r.filter(e=>e.distance===i),o=a.some(e=>e.adjustment>0),s=a.some(e=>e.adjustment<0);if(o&&s)return null;let c=a[0].adjustment;return{adjustment:c,matches:r.filter(e=>e.adjustment===c)}}function tsn(e,t,n,r){let i=[];if(e===`x`){i.push(t.top,G3(t));for(let e of n){let t=r.get(e);t&&i.push(t.top,t.bottom)}}else{i.push(t.left,W3(t));for(let e of n){let t=r.get(e);t&&i.push(t.left,t.right)}}return{from:Math.min(...i),to:Math.max(...i)}}function nsn(e,t,n,r){let i=[];for(let[a,o]of[[`x`,e],[`y`,t]]){if(!o)continue;let e=new Set;for(let t of o.matches){if(e.has(t.guidePosition))continue;e.add(t.guidePosition);let s=tsn(a,n,o.matches.filter(e=>e.guidePosition===t.guidePosition).map(e=>e.targetId),r);i.push({axis:a,position:t.guidePosition,from:s.from,to:s.to})}}return i}var rsn=(e,t)=>({dx:e,dy:t,guides:[],spacingGuides:[]});function isn(e){if(e.disabled||e.disabledForTravel||e.threshold<=0)return rsn(e.proposedDx,e.proposedDy);let t=e.movingRect,n={left:t.left+e.proposedDx,top:t.top+e.proposedDy,width:t.width,height:t.height},r=$on([n.left,K3(n),W3(n)],e.targets,e=>[e.left,e.centerX,e.right],e.gridEdges?.x,e.threshold),i=$on([n.top,q3(n),G3(n)],e.targets,e=>[e.top,e.centerY,e.bottom],e.gridEdges?.y,e.threshold),a=e.lockedAxis===`x`?null:esn(r),o=e.lockedAxis===`y`?null:esn(i),s=e.proposedDx+(a?.adjustment??0),c=e.proposedDy+(o?.adjustment??0);return{dx:s,dy:c,guides:nsn(a,o,{left:t.left+s,top:t.top+c,width:t.width,height:t.height},new Map(e.targets.map(e=>[e.id,e]))),spacingGuides:[]}}function asn(e,t){return e.axis===`x`?{left:e.position,top:t.top,width:1,height:t.height}:{left:t.left,top:e.position,width:t.width,height:1}}function osn(e){let t=[],n=e.movingRect,r={left:n.left,top:n.top,right:W3(n),bottom:G3(n),centerX:K3(n),centerY:q3(n),id:`\0__snap_moving__`},i=[...e.targets,r],a=[...i].sort((e,t)=>e.centerX-t.centerX);for(let e=0;e<a.length-2;e++){let n=a[e],r=a[e+1],i=a[e+2],o=r.left-n.right,s=i.left-r.right;if(!(o<0||s<0)&&(n.id===`\0__snap_moving__`||r.id===`\0__snap_moving__`||i.id===`\0__snap_moving__`)&&Math.abs(o-s)<=Yon){let e=Math.min(n.top,r.top,i.top),a=Math.max(n.bottom,r.bottom,i.bottom);t.push({axis:`x`,position:n.right,size:o,from:e,to:a}),t.push({axis:`x`,position:r.right,size:s,from:e,to:a})}}let o=[...i].sort((e,t)=>e.centerY-t.centerY);for(let e=0;e<o.length-2;e++){let n=o[e],r=o[e+1],i=o[e+2],a=r.top-n.bottom,s=i.top-r.bottom;if(!(a<0||s<0)&&(n.id===`\0__snap_moving__`||r.id===`\0__snap_moving__`||i.id===`\0__snap_moving__`)&&Math.abs(a-s)<=Yon){let e=Math.min(n.left,r.left,i.left),o=Math.max(n.right,r.right,i.right);t.push({axis:`y`,position:n.bottom,size:a,from:e,to:o}),t.push({axis:`y`,position:r.bottom,size:s,from:e,to:o})}}return t}function ssn(e){if(!e)return null;let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:null}var csn=new Set([`script`,`style`,`link`,`meta`,`base`,`template`,`br`,`wbr`]);function lsn(e){return e.nodeType===1}function usn(e,t,n){let r=[],i=e=>{if(!(r.length>=n))for(let n of Array.from(e.children))lsn(n)&&(csn.has(n.tagName.toLowerCase())||n.hasAttribute(`data-composition-id`)||t.has(n)||F4(n)&&(r.push(n),i(n)))};return i(e),r}function dsn(e){let t=Ub(),n=t.snapEnabled??!0,r=e.iframe.contentDocument;if(!r)return{targets:[],compositionTarget:null,gridEdges:null,snapEnabled:n};let i=r.querySelector(`[data-composition-id]`)??r.documentElement,a=i?.getBoundingClientRect(),o=ssn(i?.getAttribute(`data-width`)??null),s=ssn(i?.getAttribute(`data-height`)??null),c=o??a?.width,l=s??a?.height;if(!c||!l||!a)return{targets:[],compositionTarget:null,gridEdges:null,snapEnabled:n};let u=e.iframe.getBoundingClientRect(),d=e.overlayEl.getBoundingClientRect(),f=u.width/c,p=u.height/l,m={left:u.left-d.left,top:u.top-d.top,width:u.width,height:u.height,editScaleX:f,editScaleY:p},h=Zon(m),g=usn(i,e.excludeElements,80),_=[];for(let t=0;t<g.length;t++){let n=I4(e.overlayEl,e.iframe,g[t]);n&&_.push({rect:n,id:`snap-target-${t}`})}let v=Xon(_),y=null,b=t.gridSpacing??50;return(t.snapToGrid??!1)&&b>0&&(y=Qon(m,b,f)),{targets:v,compositionTarget:h,gridEdges:y,snapEnabled:n}}function fsn(e){let t=new Set,n=e.selection;if(n?.element&&t.add(n.element),e.groupSelections)for(let n of e.groupSelections)n.element&&t.add(n.element);return t}var J3=o2(`resize`),Y3=0;function psn(e){J3(`move`,()=>(Y3+=1,Y3%8==1?{n:Y3,...e}:null))}function msn(){Y3=0}function hsn(e,t){let n=n=>{let r=e.getBoundingClientRect(),i=e.ownerDocument.defaultView?.getComputedStyle(e);return{tag:t,phase:n,rect:{x:r.x,y:r.y,w:r.width,h:r.height},cssW:i?.width,cssH:i?.height,transform:i?.transform,inlineStyle:e.getAttribute(`style`)}};J3(`settle`,()=>{let t=n(`t0`);return e.ownerDocument.defaultView?.setTimeout(()=>J3(`settle`,()=>n(`t200`)),200),t})}var X3=o2(`drag`),Z3=0;function gsn(e){X3(`move`,()=>(Z3+=1,Z3%8==1?{n:Z3,...e}:null))}function _sn(){Z3=0}function Q3(e){let t={};for(let{key:n,element:r}of e){let e=r.getBoundingClientRect();t[n]=`${Math.round(e.left)},${Math.round(e.top)}`}return t}function vsn(e,t){let n=new Map;for(let r of Object.keys(t)){let i=e[r]?.split(`,`).map(Number),a=t[r]?.split(`,`).map(Number);!i||!a||i.length!==2||a.length!==2||n.set(r,`${Math.round(a[0]-i[0])},${Math.round(a[1]-i[1])}`)}let r=new Map;for(let e of n.values())r.set(e,(r.get(e)??0)+1);let i=``,a=0;for(let[e,t]of r)t>a&&([i,a]=[e,t]);return[...n].filter(([,e])=>e!==i).map(([e,t])=>`${e.split(`|`)[2]??e} moved ${t}, group moved ${i}`)}function ysn(e,t){X3(e,()=>{let n=Q3(t),r=t[0]?.element.ownerDocument.defaultView;return r&&(r.setTimeout(()=>X3(`${e}+120ms`,()=>({at:Q3(t)})),120),r.setTimeout(()=>X3(`${e}+400ms`,()=>({at:Q3(t)})),400),r.setTimeout(()=>X3(`${e}+900ms`,()=>({at:Q3(t)})),900)),{at:n}})}function bsn(e,t,n){e.button!==0||n.capabilities.commitCheckPending||t.onBlockedMoveRef.current(n)}function xsn(e,t,n){let r=t.groupOverlayItemsRef.current;if(r.length<=1)return!1;let i=r.find(e=>!e.selection.capabilities.canApplyManualOffset)?.selection;if(i)return e.preventDefault(),e.stopPropagation(),bsn(e,t,i),!1;t.onManualDragStartRef.current?.();let a=Gin(r),o=[];for(let r of a){let i=I3({key:r.key,selection:r.selection,element:r.element,rect:r.rect,gesture:`drag`,at:n});if(!i.ok)return V3(o),e.preventDefault(),e.stopPropagation(),t.onBlockedMoveRef.current(i.selection,i.reason),!1;o.push(i.member)}try{_sn(),X3(`group-start`,{members:Object.fromEntries(o.map(e=>[e.key,{map:`${e.screenToOffset.a.toFixed(3)},${e.screenToOffset.d.toFixed(3)}`,base:`${Math.round(e.baseGsap.x)},${Math.round(e.baseGsap.y)}`,offset:`${Math.round(e.initialOffset.x)},${Math.round(e.initialOffset.y)}`}])),at:Q3(o)});let n=t.overlayRef.current,i=t.iframeRef.current,a=n&&i?dsn({overlayEl:n,iframe:i,excludeElements:fsn({iframe:i,groupSelections:r.map(e=>e.selection)})}):void 0;e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),t.rafPausedRef.current=!0,t.groupGestureRef.current={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,originItems:r,members:o,snapContext:a}}catch(e){throw t.groupGestureRef.current=null,V3(o),e}return!0}function Ssn(e,t,n,r){let i=r?.at,a=r?.selection??n.selectionRef.current,o=r?.rect??n.overlayRectRef.current,s=n.boxRef.current,c=n.overlayRef.current;if(!a||!o||e!==`drag`&&!s)return!1;let l=e===`rotate`?`rotation`:e===`drag`?`path-offset`:`box-size`;if(e===`drag`&&!a.capabilities.canApplyManualOffset||e===`resize`&&!a.capabilities.canApplyManualSize||e===`rotate`&&!a.capabilities.canApplyManualRotation||e===`resize`&&(!Number.isFinite(o.width)||!Number.isFinite(o.height)))return!1;let u=X0(a.element),d=a.element.offsetWidth,f=a.element.offsetHeight,p=u.width>0?u.width:d>0?d:o.width/o.editScaleX,m=u.height>0?u.height:f>0?f:o.height/o.editScaleY,h=o.width/(o.editScaleX*p),g=o.height/(o.editScaleY*m),_=Number.isFinite(h)&&h>0?h:1,v=Number.isFinite(g)&&g>0?g:1,y=Pon(a.element,e!==`drag`&&!B0(a.element,e===`rotate`?`rotate`:`resize`)),b=c3(a.element),x,S;if(e===`drag`){n.onManualDragStartRef.current?.();let e=I3({key:G4(a),selection:a,element:a.element,rect:o,gesture:`drag`,at:i});if(!e.ok)return n.onBlockedMoveRef.current(e.selection,e.reason),t.preventDefault(),!1;S=e.member,b=e.member.initialPathOffset,x=e.member.gestureToken}else if(e===`resize`&&a.capabilities.canApplyManualOffset){let e=I3({key:G4(a),selection:a,element:a.element,rect:o,gesture:`resize`,at:i});e.ok?(S=e.member,b=e.member.initialPathOffset,x=e.member.gestureToken,e.member.plainTranslate&&R3(e.member,0,0)):x=H0(a.element,`resize`,i)}else x=H0(a.element,e===`rotate`?`rotate`:`resize`,i);try{let i=!!S?.plainTranslate||B0(a.element,`rotate`),s=i&&e===`rotate`?Von(a.element):null,u={angle:Kon(a.element,i)},d=c?.getBoundingClientRect(),f=(d?.left??0)+o.left+o.width/2,h=(d?.top??0)+o.top+o.height/2,g=n.iframeRef.current,C;if(e===`resize`&&S&&c&&g){let e=z4(c,g,a.element);e&&(C=Bin(e))}let w=(e===`drag`||e===`resize`)&&c&&g?dsn({overlayEl:c,iframe:g,excludeElements:fsn({iframe:g,selection:a})}):void 0;t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),n.rafPausedRef.current=!0,n.gestureRef.current={kind:e,mode:l,selection:a,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,centerX:f,centerY:h,initialPathOffset:b,initialRotation:s3(a.element),initialBoxSize:o3(a.element),initialLook:y,pathOffsetMember:S,originLeft:o.left,originTop:o.top,originWidth:o.width,originHeight:o.height,actualWidth:p,actualHeight:m,actualRotation:u.angle,plainRotation:s,editScaleX:o.editScaleX,editScaleY:o.editScaleY,contentScaleX:_,contentScaleY:v,manualEditDragToken:x,snapContext:w,resizeHandle:e===`resize`?r?.resizeHandle??`se`:void 0,resizeFixedCenterStart:C},e===`resize`&&(msn(),J3(`start`,{handle:r?.resizeHandle??`se`,pointer:{x:t.clientX,y:t.clientY},center:{x:f,y:h},origin:{left:o.left,top:o.top,w:o.width,h:o.height},actual:{w:p,h:m},editScale:{x:o.editScaleX,y:o.editScaleY},contentScale:{x:_,y:v},rotation:u.angle,hasOffsetMember:!!S,fixedCenterStart:C??null,initialBoxSize:n.gestureRef.current?.initialBoxSize??null,initialInlineStyle:a.element.getAttribute(`style`)}))}catch(e){throw n.gestureRef.current=null,S?V3([S]):x&&W0(a.element,x),e}return!0}function $3(){let{currentTime:e,activeKeyframePct:t}=X.getState();return{time:e,keyframePct:t}}function e6(e){return e?.at??$3()}var Csn=60,wsn=1e4;function Tsn(e,t,n){let r=()=>{let t=e.waitingPressRef.current;for(;t&&!t.released;)t=t.after;let n=t;IKt(n&&(()=>c(n)))},i=()=>{e.boxRef.current?.removeAttribute(Zin),e.rafPausedRef.current=!1},a=(t,n)=>{for(let r=e.waitingPressRef.current;r;r=r.after)r.after===t&&(r.after=n)},o=(t=e.waitingPressRef.current)=>{for(let e=t;e&&!e.ended;e=e.after)e.ended=!0,cancelAnimationFrame(e.frame);t===e.waitingPressRef.current?(e.waitingPressRef.current=null,i()):t&&a(t,null),r()},s=t=>{let n=t.after;e.waitingPressRef.current=n;let r=n??t,a=n?.moved,[o,s]=a?[a.clientX-r.startX,a.clientY-r.startY]:[0,0];r.draw?.(o,s),n||i()},c=t=>!t.ended&&(t.ended=!0,cancelAnimationFrame(t.frame),t===e.waitingPressRef.current?s(t):a(t,t.after),r(),!0),l=()=>{let t=e.waitingPressRef.current;t&&!t.released&&c(t)},u=(e,t)=>{e.released=t,r()},d=t=>t&&((n,r)=>e.setOverlayRect(P4(t,n,r))),f=(t,n)=>{if(!t)return null;let r=e.overlayRef.current?.getBoundingClientRect(),i={x:(r?.left??0)+t.left+t.width/2,y:(r?.top??0)+t.top+t.height/2};return(r,a)=>{let o=Tan({pointer:{x:n.x+r,y:n.y+a},pointerStart:n,centerStart:i}),[s,c]=[t.width*o,t.height*o];e.setOverlayRect({...t,left:t.left+(t.width-s)/2,top:t.top+(t.height-c)/2,width:s,height:c})}},p=(r,i,a,s=null)=>{let c=$3();if(!Ien()&&!e.waitingPressRef.current)return a(r,c,!1);r.preventDefault(),r.stopPropagation(),r.currentTarget.setPointerCapture(r.pointerId);let l={setPointerCapture(){}},u={...r,currentTarget:l,preventDefault(){},stopPropagation(){}},d={pointerId:r.pointerId,startX:r.clientX,startY:r.clientY,draw:s,frame:0,moved:null,released:null,after:e.waitingPressRef.current,ended:!1};e.waitingPressRef.current=d,e.boxRef.current?.setAttribute(Zin,`true`),e.rafPausedRef.current=!0;let f=0,p=0,m=performance.now(),h=()=>{let t=i(),n=e.iframeRef.current?.contentDocument,r=!Ien();return f=r&&t.every(e=>e.ownerDocument===n)?f+1:0,p=r?p+1:0,t.length},g=()=>{if(d.after&&!d.after.ended)return`wait`;let e=h(),t=performance.now()-m>wsn;return t&&Nen(),e===0||p>Csn?`lost`:t||f>=2?`run`:`wait`},_=()=>{if(d.ended)return;let e=g();if(e===`wait`){d.frame=requestAnimationFrame(_);return}o(d),!(e===`lost`||!a(u,c,!0))&&(d.moved&&t(d.moved),d.released&&n(d.released))};return d.frame=requestAnimationFrame(_),!0},m=t=>{let n=e.iframeRef.current?.contentDocument;if(!n)return null;let r=He(n,t,e.activeCompositionPathRef.current);return r&&{...t,element:r}},h=t=>{let n=e.overlayRef.current,r=e.iframeRef.current;return n&&r&&W4(n,r,t)};return{startGesture:(t,n,r)=>{let i=r?.selection??e.selectionRef.current,a=null;return t===`drag`&&(a=d(e.overlayRectRef.current)),t===`resize`&&(a=f(e.overlayRectRef.current,{x:n.clientX,y:n.clientY})),p(n,()=>{let e=i&&m(i);return e?[e.element]:[]},(n,a,o)=>{if(!o)return Ssn(t,n,e,{...r,at:a});let s=i&&m(i),c=s&&h(s.element);return!!(s&&c)&&Ssn(t,n,e,{selection:s,rect:c,resizeHandle:r?.resizeHandle,at:a})},a)},startGroupDrag:t=>{let n=e.groupOverlayItemsRef.current;return p(t,()=>n.flatMap(e=>{let t=m(e.selection);return t?[t.element]:[]}),(t,r,i)=>{if(!i)return xsn(t,e,r);let a=e.overlayRef.current,o=e.iframeRef.current;if(!a||!o)return!1;let s=C4(a,o,o.contentDocument),c=n.flatMap(e=>{let t=m(e.selection),n=t&&W4(a,o,t.element,s);return t&&n?[{...e,selection:t,element:t.element,rect:n}]:[]});return c.length===n.length&&xsn(t,{...e,groupOverlayItemsRef:{current:c}},r)},(t,r)=>e.setGroupOverlayItems(n.map(e=>({...e,rect:P4(e.rect,t,r)}))))},endWaitingPress:o,endHeldPress:l,releaseWaitingPress:u}}function Esn(e,t,n){let r=e.resizeFixedCenterStart;if(t&&r)return Aan(e.lastResizeAnchor,r,Bin(t));let i=n();return tan({originWidth:e.originWidth,originHeight:e.originHeight,overlayWidth:i?i.width:e.originWidth,overlayHeight:i?i.height:e.originHeight})}function Dsn(e,t,n,r,i,a){let o=r&&i?z4(r,i,n):null,s=Esn(e,o,a);return e.lastResizeAnchor=s,R3(t,s.dx,s.dy),a()??{left:e.originLeft+s.dx,top:e.originTop+s.dy,width:o?R4(o.nw,o.ne):e.originWidth,height:o?R4(o.nw,o.sw):e.originHeight,editScaleX:e.editScaleX,editScaleY:e.editScaleY,angle:e.actualRotation}}function Osn(e,t,n,r,i){return e.pathOffsetMember?Dsn(e,e.pathOffsetMember,t,n,r,i):i()??{left:e.originLeft,top:e.originTop,width:e.originWidth,height:e.originHeight,editScaleX:e.editScaleX,editScaleY:e.editScaleY,angle:e.actualRotation}}function ksn(e,t){let n={},r=null,i=(t,n,r)=>{let i=t.snapContext;if(!i?.snapEnabled||i.targets.length===0)return r;if(!Jon(r.dx,r.dy))return e.snapGuidesRef.current=null,r;let a=U4(t.originItems.map(e=>e.rect));if(!a)return r;let o=i.compositionTarget?[...i.targets,i.compositionTarget]:i.targets,s=isn({movingRect:a,proposedDx:r.dx,proposedDy:r.dy,targets:o,gridEdges:i.gridEdges??void 0,threshold:6,disabled:n.altKey,lockedAxis:r.lockedAxis}),c={...a,left:a.left+s.dx,top:a.top+s.dy},l=n.altKey?[]:osn({movingRect:c,targets:o,threshold:6});return e.snapGuidesRef.current={guides:s.guides,spacingGuides:l},{dx:s.dx,dy:s.dy}};return(e,a)=>{e!==r&&(r=e,n={});let{dx:o,dy:s}=i(e,a,qin(a.clientX-e.startX,a.clientY-e.startY,a.shiftKey));e.lastSnappedDx=o,e.lastSnappedDy=s,t(e.originItems.map(e=>({...e,rect:{...e.rect,left:e.rect.left+o,top:e.rect.top+s}})));let c={};for(let t of e.members){let e=R3(t,o,s);c[t.key]=`${Math.round(e.x)},${Math.round(e.y)}`}let l=Q3(e.members),u={pointer:`${Math.round(a.clientX-e.startX)},${Math.round(a.clientY-e.startY)}`,applied:`${Math.round(o)},${Math.round(s)}`,at:l},d=vsn(n,l);d.length>0&&X3(`drift`,{...u,drift:d}),n=l,gsn({...u,offsets:c})}}var Asn=5,t6=class extends Error{constructor(){super(`Auto-save is paused. Dismiss the warning to retry DOM edits.`),this.name=`DomEditSaveQueueOpenError`}};function jsn(e={}){let t=e.failureThreshold??Asn,n=Promise.resolve(),r=0,i=0,a=!1,o=null,s=(t=!0)=>{let n=a;i=0,a=!1,o=null,t&&n&&e.onReset?.()},c=t=>{a||(a=!0,e.onOpen?.({consecutiveFailures:i,errorMessage:QY(t),statusCode:tX(t)??null}))},l=async e=>{try{let t=await e();return a||(i=0,o=null),t}catch(e){throw o=e,i+=1,(tX(e)===409||i>=t)&&c(e),e}};return{enqueue(e){if(a)return Promise.reject(new t6);r+=1;let t=n.catch(()=>void 0).then(()=>{if(a)throw new t6;return l(e)});return n=t.then(()=>void--r,()=>void--r),t},async waitForIdle(){return await n.catch(()=>void 0),o instanceof XY?{status:`conflict`,error:o}:o==null?{status:`clean`}:{status:`failed`,error:o}},isIdle:()=>r===0,reset:s,destroy(){s(!1)}}}function n6(e,t){return!e.travelled&&Math.hypot(t.clientX-e.startX,t.clientY-e.startY)<q4}function Msn(e,t){t instanceof t6||console.error(e,t)}function Nsn(e){let t=t=>{e.waitingPressRef.current||e.setOverlayRect(t)},n=e=>{t({left:e.originLeft,top:e.originTop,width:e.originWidth,height:e.originHeight,editScaleX:e.editScaleX,editScaleY:e.editScaleY,angle:e.actualRotation})},r=t=>{e.waitingPressRef.current||e.setGroupOverlayItems(t)},i=e=>{V3(e.members),r(e.originItems)},{startGesture:a,startGroupDrag:o,endWaitingPress:s,endHeldPress:c,releaseWaitingPress:l}=Tsn(e,e=>p(e),e=>h(e)),u=(t,n)=>{t.preventDefault(),t.stopPropagation(),t.currentTarget.setPointerCapture(t.pointerId),e.blockedMoveRef.current={pointerId:t.pointerId,startX:t.clientX,startY:t.clientY},bsn(t,e,n)},d=ksn(e,r),f=t=>{let n=e.waitingPressRef.current;if(n&&n.pointerId===t.pointerId){if(n.released||!J4(n,t))return;n.moved=t,n.draw?.(t.clientX-n.startX,t.clientY-n.startY);return}p(t)},p=n=>{let r=e.gestureRef.current,i=e.groupGestureRef.current,a=r?.selection??e.selectionRef.current,o=e.waitingPressRef.current?null:e.boxRef.current,s=e.blockedMoveRef.current;!s&&!r&&!i&&e.onCanvasPointerMoveRef.current(n,{preferClipAncestor:!1});let c=r??i;if(c&&!J4(c,n))return;if(s){let t=n.clientX-s.startX,r=n.clientY-s.startY;Math.hypot(t,r)>=q4&&(e.suppressNextBoxClickRef.current=!0);return}if(i){n6(i,n)||(i.travelled=!0),d(i,n);return}if(!r||!a)return;n6(r,n)||(r.travelled=!0);let l=n.clientX-r.startX,u=n.clientY-r.startY;if(r.kind===`rotate`){let e=ian({centerX:r.centerX,centerY:r.centerY,startX:r.startX,startY:r.startY,currentX:n.clientX,currentY:n.clientY,actualAngle:r.actualRotation,snap:n.shiftKey});Won(a.element,e.angle,r.plainRotation);return}if(r.kind===`drag`){let i=qin(l,u,n.shiftKey);l=i.dx,u=i.dy;let a=r.snapContext;if(!(Math.abs(r.actualRotation)>=Xin)&&a?.snapEnabled&&a.targets.length>0){let t=j4({left:r.originLeft,top:r.originTop,width:r.originWidth,height:r.originHeight,editScaleX:r.editScaleX,editScaleY:r.editScaleY},r.selection.element),o=a.compositionTarget?[...a.targets,a.compositionTarget]:a.targets,s=isn({movingRect:t,proposedDx:l,proposedDy:u,disabledForTravel:!Jon(l,u),targets:o,gridEdges:a.gridEdges??void 0,threshold:6,disabled:n.altKey,lockedAxis:i.lockedAxis});l=s.dx,u=s.dy;let c={left:t.left+l,top:t.top+u,width:t.width,height:t.height},d=n.altKey?[]:osn({movingRect:c,targets:o,threshold:6});e.snapGuidesRef.current={guides:s.guides,spacingGuides:d}}r.lastSnappedDx=l,r.lastSnappedDy=u;let s=r.originLeft+l,c=r.originTop+u;t({left:s,top:c,width:r.originWidth,height:r.originHeight,editScaleX:r.editScaleX,editScaleY:r.editScaleY,angle:r.actualRotation}),o&&(o.style.left=`${s}px`,o.style.top=`${c}px`),r.pathOffsetMember&&R3(r.pathOffsetMember,l,u)}else{let i=Ean({baseWidth:r.actualWidth,baseHeight:r.actualHeight,pointer:{x:n.clientX,y:n.clientY},pointerStart:{x:r.startX,y:r.startY},centerStart:{x:r.centerX,y:r.centerY}});Een(a.element,i);let s=e.overlayRef.current,c=e.iframeRef.current,l=Osn(r,a.element,s,c,()=>s&&c?B4(s,c,a.element):null);psn({pointer:{x:n.clientX,y:n.clientY},nextSize:i,anchor:r.lastResizeAnchor??null,draftRect:l,liveInlineStyle:a.element.getAttribute(`style`)}),o&&(o.style.left=`${l.left}px`,o.style.top=`${l.top}px`,o.style.width=`${l.width}px`,o.style.height=`${l.height}px`),t(l)}},m=t=>{let n=e.waitingPressRef.current;if(n&&n.pointerId===t.pointerId){l(n,t),e.suppressNextBoxClickRef.current=!0;return}h(t)},h=a=>{e.snapGuidesRef.current=null;let o=e.gestureRef.current,s=e.groupGestureRef.current,c=o?.selection??e.selectionRef.current,l=e.waitingPressRef.current?null:e.boxRef.current;if(e.blockedMoveRef.current=null,e.rafPausedRef.current=e.waitingPressRef.current!==null,s){e.groupGestureRef.current=null;let t=a.clientX-s.startX,n=a.clientY-s.startY;if(e.suppressNextBoxClickRef.current=!0,n6(s,a)){i(s),a.shiftKey&&e.onCanvasMouseDown(a,{preferClipAncestor:!1,hoverSelection:e.hoverSelectionRef.current});return}let o=s.lastSnappedDx??t,c=s.lastSnappedDy??n;r(s.originItems.map(e=>({...e,rect:P4(e.rect,o,c)})));let l=s.members.map(e=>({selection:e.selection,next:B3(e,o,c),plainTranslate:e.plainTranslate}));X3(`drop`,{pointer:`${Math.round(t)},${Math.round(n)}`,applied:`${Math.round(o)},${Math.round(c)}`,committed:Object.fromEntries(l.map((e,t)=>[s.members[t]?.key??String(t),`${Math.round(e.next.x)},${Math.round(e.next.y)}`])),at:Q3(s.members)});let u=mX(U3(s.members)),d=Promise.resolve(u.adopt(()=>e.onGroupPathOffsetCommitRef.current(l))).then(e=>h4(`move`,`drag`,e)).catch(()=>{for(let e of s.members)e.gestureToken&&J0(e.element,e.gestureToken)&&p3(e.element,e.initialPathOffset)}).finally(()=>{X3(`committed`,{at:Q3(s.members)}),H3(s.members),ysn(`settle`,s.members)});u.settle(d);return}if(e.gestureRef.current=null,!o||!c)return;let u=Math.hypot(a.clientX-o.startX,a.clientY-o.startY);if(o.kind===`drag`&&n6(o,a)){o.pathOffsetMember&&V3([o.pathOffsetMember]),l&&(l.style.left=`${o.originLeft}px`,l.style.top=`${o.originTop}px`),n(o),e.suppressNextBoxClickRef.current=!0,e.onCanvasMouseDown(a,{preferClipAncestor:!1,hoverSelection:e.hoverSelectionRef.current});return}if(o.kind===`resize`&&u<q4){d3(c.element,o.initialBoxSize),o.pathOffsetMember?V3([o.pathOffsetMember]):W0(c.element,o.manualEditDragToken),l&&(l.style.width=`${o.originWidth}px`,l.style.height=`${o.originHeight}px`),n(o),e.suppressNextBoxClickRef.current=!0;return}if(o.kind===`rotate`){let t=ian({centerX:o.centerX,centerY:o.centerY,startX:o.startX,startY:o.startY,currentX:a.clientX,currentY:a.clientY,actualAngle:o.actualRotation,snap:a.shiftKey}),n=()=>Gon(c.element,o.actualRotation,o.initialRotation,o.plainRotation!==null);if(!aan(o.actualRotation,t.angle)){n(),W0(c.element,o.manualEditDragToken);return}Won(c.element,t.angle,o.plainRotation);let r={...t,plain:o.plainRotation},i=mX(Ion(c.element,o.initialLook)),s=Promise.resolve(i.adopt(()=>e.onRotationCommitRef.current(c,r))).then(e=>h4(`rotate`,`drag`,e)).catch(e=>{Msn(`rotate commit failed`,e),o.manualEditDragToken&&J0(c.element,o.manualEditDragToken)&&n()}).finally(()=>W0(c.element,o.manualEditDragToken));i.settle(s)}else if(o.kind===`drag`){e.suppressNextBoxClickRef.current=!0;let n=o.lastSnappedDx??a.clientX-o.startX,r=o.lastSnappedDy??a.clientY-o.startY;if(!o.pathOffsetMember)return;let i=B3(o.pathOffsetMember,n,r),s=o.originLeft+n,u=o.originTop+r;t({left:s,top:u,width:o.originWidth,height:o.originHeight,editScaleX:o.editScaleX,editScaleY:o.editScaleY,angle:o.actualRotation}),l&&(l.style.left=`${s}px`,l.style.top=`${u}px`);let d=o.pathOffsetMember,f=mX(U3([d])),p=Promise.resolve(f.adopt(()=>e.onPathOffsetCommitRef.current(c,i,{altKey:a.altKey,plainTranslate:d.plainTranslate}))).then(e=>h4(`move`,`drag`,e)).catch(()=>{o.pathOffsetMember?.gestureToken&&J0(c.element,o.pathOffsetMember.gestureToken)&&p3(c.element,o.initialPathOffset)}).finally(()=>{o.pathOffsetMember&&H3([o.pathOffsetMember])});f.settle(p)}else{e.suppressNextBoxClickRef.current=!0;let t=X0(c.element);r2(c.element,t);let n=o.pathOffsetMember,r=o.lastResizeAnchor,i=n&&r&&(r.dx!==0||r.dy!==0)?B3(n,r.dx,r.dy):null;J3(`release`,{finalSize:t,anchor:r??null,finalOffset:i??null,hasMember:!!n,inlineStyle:c.element.getAttribute(`style`)});let a=()=>{!o.manualEditDragToken||!J0(c.element,o.manualEditDragToken)||(d3(c.element,o.initialBoxSize),i&&p3(c.element,o.initialPathOffset))},s=()=>e.onBoxSizeCommitRef.current(c,t,i??void 0,a,n),l=mX(Ion(c.element,o.initialLook)),u=Promise.resolve(l.adopt(s)).then(e=>h4(`resize`,`drag`,e)).catch(e=>{Msn(`resize commit failed`,e)}).finally(()=>{n?H3([n]):W0(c.element,o.manualEditDragToken)});l.settle(u),hsn(c.element,`post-release`)}},g=(t,r=!1)=>{r?s():c(),e.snapGuidesRef.current=null;let a=e.groupGestureRef.current;a&&i(a);let o=e.gestureRef.current,l=o?.selection??t.current;o?.mode===`path-offset`&&l&&(o.pathOffsetMember&&V3([o.pathOffsetMember]),n(o)),o?.mode===`box-size`&&l&&(d3(l.element,o.initialBoxSize),o.pathOffsetMember?V3([o.pathOffsetMember]):W0(l.element,o.manualEditDragToken),n(o)),o?.mode===`rotation`&&l&&(Gon(l.element,o.actualRotation,o.initialRotation,o.plainRotation!==null),W0(l.element,o.manualEditDragToken)),e.blockedMoveRef.current=null,e.groupGestureRef.current=null,e.gestureRef.current=null,e.rafPausedRef.current=e.waitingPressRef.current!==null};return{startGesture:a,startGroupDrag:o,startBlockedMove:u,onPointerMove:f,onPointerUp:m,onLostPointerCapture:t=>{let n=e.waitingPressRef.current;n?.pointerId===t.pointerId&&n.released||g(e.selectionRef)},clearPointerState:g}}var Psn=new Set([`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`]),Fsn=1,Isn=10,Lsn=400;function Rsn(e){if(e.metaKey||e.ctrlKey||e.altKey||!Psn.has(e.key))return null;let t=e.shiftKey?Isn:Fsn;return{dx:e.key===`ArrowLeft`?-t:e.key===`ArrowRight`?t:0,dy:e.key===`ArrowUp`?-t:e.key===`ArrowDown`?t:0}}function r6(e){return e.length>0&&e.every(e=>e.capabilities.canApplyManualOffset)}function zsn(e){return e?[e.id??``,e.hfId??``,e.selector??``,e.selectorIndex??``,e.label].join(`\0`):``}function Bsn(e){return e.map(zsn).join(` `)}function Vsn(e){return r6(e.map(e=>e.selection))?Gin(e):null}function Hsn(e,t){return!e||!t||!e.capabilities.canApplyManualOffset||!e.element.isConnected?null:[{key:e.id??e.selector??e.label,selection:e,element:e.element,rect:t}]}function Usn(e,t){return!e.allowCanvasMovement||t.defaultPrevented||e.gestureRef.current||e.groupGestureRef.current||e.blockedMoveRef.current?!0:oX(t.target)}function Wsn(e){let t=(0,U.useRef)(null),n=(0,U.useRef)(e);n.current=e;let r=()=>{let e=t.current;if(!e)return;t.current=null,e.timer&&clearTimeout(e.timer);let r=n.current,i;try{let t=e.members.map(t=>({selection:t.selection,next:won(t,e.accum),plainTranslate:t.plainTranslate})),n=e.edit.adopt(()=>e.isGroup?r.onGroupPathOffsetCommitRef.current(t):r.onPathOffsetCommitRef.current(t[0].selection,t[0].next,{plainTranslate:t[0].plainTranslate}));if(e.edit.reverted())for(let t of e.members)p3(t.element,t.initialPathOffset);return i=Promise.resolve(n).then(e=>h4(`nudge`,`keyboard`,e)).catch(()=>{for(let t of e.members)J0(t.element,t.gestureToken)&&p3(t.element,t.initialPathOffset)}).finally(()=>H3(e.members)),i}finally{e.edit.settle(i)}},i=(0,U.useRef)(r);i.current=r,(0,U.useEffect)(()=>{if(e.allowCanvasMovement||!t.current)return;let n=t.current;t.current=null,n.timer&&clearTimeout(n.timer),V3(n.members),H3(n.members),n.edit.settle()},[e.allowCanvasMovement]);let a=e=>{let t=n.current,r=t.groupOverlayItemsRef.current,i=r.length>1,a=i?Vsn(r):Hsn(t.selectionRef.current,t.overlayRectRef.current);if(!a)return null;t.onManualDragStartRef.current?.();let o=[];for(let n of a){let r=I3({...n,gesture:`nudge`});if(!r.ok)return V3(o),e.repeat||t.onBlockedMoveRef.current(r.selection,r.reason),`refused`;o.push(r.member)}return o.length===0?null:{members:o,isGroup:i,accum:{x:0,y:0},timer:null,edit:mX(U3(o))}},o=e=>{let r=n.current;if(Usn(r,e))return;let o=Rsn(e);if(!o)return;let s=t.current??a(e);if(s===`refused`)return void e.preventDefault();if(s){t.current=s,e.preventDefault(),s.accum={x:s.accum.x+o.dx,y:s.accum.y+o.dy};for(let e of s.members)Con(e,s.accum);s.timer&&clearTimeout(s.timer),s.timer=setTimeout(()=>i.current(),Lsn)}},s=(0,U.useRef)(o);s.current=o,ax(()=>{let e=e=>s.current(e);window.addEventListener(`keydown`,e,!0);let t=XKt(()=>i.current());return()=>{window.removeEventListener(`keydown`,e,!0),t(),i.current()}});let c=zsn(e.selection),l=Bsn(e.groupSelections);return(0,U.useEffect)(()=>()=>void i.current(),[c,l]),(0,U.useEffect)(()=>{let t=e.groupSelections.length>1?e.groupSelections:e.selection?[e.selection]:[];if(!(!e.allowCanvasMovement||!r6(t)))return R5t()},[e.selection,e.groupSelections,e.allowCanvasMovement]),{flushNudge:(0,U.useCallback)(()=>i.current(),[])}}var Gsn=6,Ksn=4,qsn=`rgba(255, 68, 204, 0.85)`,i6=`rgba(255, 68, 204, 0.6)`,Jsn=`rgba(255, 68, 204, 0.15)`,Ysn=(0,U.memo)(function({snapGuidesRef:e,compositionLeft:t,compositionTop:n,compositionWidth:r,compositionHeight:i}){let a=(0,U.useRef)([]),o=(0,U.useRef)([]),s=(0,U.useRef)([]),c=(0,U.useRef)({left:t,top:n,width:r,height:i});return c.current={left:t,top:n,width:r,height:i},ax(()=>X2(()=>{let t=e.current,n=t?.guides??[],r=t?.spacingGuides??[],i=c.current;for(let e=0;e<Gsn;e++){let t=a.current[e];if(!t)continue;let r=n[e];if(!r){t.style.display=`none`;continue}t.style.display=``;let o=asn(r,i);t.style.left=`${o.left}px`,t.style.top=`${o.top}px`,t.style.width=`${o.width}px`,t.style.height=`${o.height}px`}for(let e=0;e<Ksn;e++){let t=o.current[e],n=s.current[e];if(!t)continue;let i=r[e];if(!i){t.style.display=`none`;continue}t.style.display=`flex`,t.style.alignItems=`center`,t.style.justifyContent=`center`,i.axis===`x`?(t.style.left=`${i.position}px`,t.style.top=`${i.from}px`,t.style.width=`${i.size}px`,t.style.height=`${i.to-i.from}px`,t.style.borderLeft=`1px dashed ${i6}`,t.style.borderRight=`1px dashed ${i6}`,t.style.borderTop=`none`,t.style.borderBottom=`none`):(t.style.left=`${i.from}px`,t.style.top=`${i.position}px`,t.style.width=`${i.to-i.from}px`,t.style.height=`${i.size}px`,t.style.borderTop=`1px dashed ${i6}`,t.style.borderBottom=`1px dashed ${i6}`,t.style.borderLeft=`none`,t.style.borderRight=`none`),n&&(n.textContent=`${Math.round(i.size)}`)}})),(0,W.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[Array.from({length:Gsn},(e,t)=>(0,W.jsx)(`div`,{ref:e=>{a.current[t]=e},style:{display:`none`,position:`absolute`,backgroundColor:qsn,zIndex:50}},`guide-${t}`)),Array.from({length:Ksn},(e,t)=>(0,W.jsx)(`div`,{ref:e=>{o.current[t]=e},style:{display:`none`,position:`absolute`,zIndex:50},children:(0,W.jsx)(`span`,{ref:e=>{s.current[t]=e},style:{fontSize:`10px`,fontFamily:`monospace`,color:qsn,backgroundColor:Jsn,padding:`0 3px`,borderRadius:`2px`,lineHeight:`14px`,whiteSpace:`nowrap`}})},`spacing-${t}`))]})}),a6=e=>({width:e.offsetWidth,height:e.offsetHeight});function Xsn(e){let t=R0(e,[`clipPath`]);return{width:!t&&!K9t(e,[`width`]),height:!t&&!K9t(e,[`height`])}}function Zsn(e,t,n,r){let i=r.width&&t.width>0?n.width/t.width:1,a=r.height&&t.height>0?n.height/t.height:1;return{top:e.top*a,right:e.right*i,bottom:e.bottom*a,left:e.left*i,radius:e.radius}}function o6(e){let t=k4(e),n=Ten(e);return t&&n?Zsn(t,n,a6(e),Xsn(e)):t}function s6(e){let t=Ten(e)??a6(e),n=e.style.getPropertyValue(`clip-path`),r=e.style.getPropertyPriority(`clip-path`),i=Xsn(e),a=k4(e);return()=>{a2(e);let o=a6(e),s=e.style.getPropertyValue(`clip-path`)===n;if(!a||!xin(a)||!s||!(o.width>0&&o.height>0))return null;let c=D4(Zsn(a,t,o,i),a.radius);return c===D4(a,a.radius)?null:(e.style.setProperty(`clip-path`,c,r),{patch:{type:`inline-style`,property:`clip-path`,value:r?`${c} !important`:c},revert:()=>{n?e.style.setProperty(`clip-path`,n,r):e.style.removeProperty(`clip-path`)}})}}async function Qsn(e,t,n,r){let i=e();if(i)try{return await n(t,[i.patch],{label:`Resize layer`,coalesceKey:r,coalesceMs:1/0})}catch(e){throw i.revert(),e}}var $sn=0;async function ecn(e,t,n,r,i){if(!n||!(`width`in t||`height`in t))return i();let a=s6(e.element),o=`size-write:${++$sn}`,s={coalesceKey:o,coalesceMs:1/0},c=(e,t,r)=>n(e,t,{...r,...s});if(n.batch){let e=n.batch;c.batch=(t,n)=>e(t,{...n,...s})}await i(c),await Qsn(a,e,r,o)}var tcn=[{label:`16:9`,ratio:16/9},{label:`9:16`,ratio:9/16},{label:`1:1`,ratio:1},{label:`4:5`,ratio:4/5}];function ncn(e,t,n){let r={top:0,right:0,bottom:0,left:0};if(e<=0||t<=0||n<=0)return r;if(e/t>n){let i=(e-t*n)/2;return i>1e-9?{...r,left:i,right:i}:r}let i=(t-e/n)/2;return i>1e-9?{...r,top:i,bottom:i}:r}var c6=`rounded-sm border border-white/20 px-1.5 py-0.5 text-[10px] text-white/85 hover:bg-white/10`;function rcn({left:e,top:t,elementWidth:n,elementHeight:r,onApply:i,onDone:a}){return(0,U.useEffect)(()=>{let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]),(0,W.jsxs)(`div`,{role:`toolbar`,"aria-label":`Crop presets`,"data-dom-edit-crop-bar":`true`,className:`pointer-events-auto absolute z-20 flex gap-1 rounded-md border border-white/15 bg-neutral-900/95 p-1 shadow-lg`,style:{left:e,top:Math.max(4,t-34),transform:`translateX(-50%)`},onPointerDown:e=>e.stopPropagation(),children:[(0,W.jsx)(`button`,{type:`button`,className:c6,title:`Drag the edges freely`,children:`Free`}),tcn.map(e=>(0,W.jsx)(`button`,{type:`button`,className:c6,onClick:()=>i(ncn(n,r,e.ratio)),children:e.label},e.label)),(0,W.jsx)(`button`,{type:`button`,className:c6,onClick:()=>i(null),children:`Reset`}),(0,W.jsx)(`button`,{type:`button`,className:`rounded-sm border border-studio-accent bg-studio-accent px-1.5 py-0.5 text-[10px] font-semibold text-black`,onClick:a,children:`Done`})]})}var l6=12,icn=32,acn=24,ocn=22;function scn(e,t){let n=e===`left`||e===`right`,r=Math.min(icn,(n?t.height:t.width)-N4);if(r<=0)return null;let i=Math.min(acn,r);return n?{hit:{left:e===`left`?t.left-l6:t.left+t.width,top:t.top+(t.height-r)/2,width:l6,height:r},cursor:`ew-resize`,pill:{width:4,height:i}}:{hit:{left:t.left+(t.width-r)/2,top:e===`top`?t.top-l6:t.top+t.height,width:r,height:l6},cursor:`ns-resize`,pill:{width:i,height:4}}}function ccn(e){return Math.min(ocn,Math.max(e.width,e.height)-N4)}var lcn=[`top`,`right`,`bottom`,`left`],u6={top:0,right:0,bottom:0,left:0,radius:0};function ucn({selection:e,overlayRect:t,onStyleCommit:n}){let r=(0,U.useRef)(null),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(null),c=e=>{let t=k4(e),{top:n,right:r,bottom:i,left:a}=t??u6;return{element:e,croppable:t!==null,insets:{top:n,right:r,bottom:i,left:a}}},[l,u]=(0,U.useState)(()=>c(e.element)),d=SQ(e=>e.openFor),f=SQ(e=>e.close),p=Z$t(e.element,d);l.element!==e.element&&u(c(e.element));let m=o6(e.element)??u6,h=i?l.insets:m,g=xin(h);(0,U.useEffect)(()=>{let t=e.element;if(k4(t)!==null)return hin(t),()=>gin(t)},[e.element]);let _=kin(e.element,t),v=_.width/_.scaleX,y=_.height/_.scaleY,b=pin({left:0,top:0,width:_.width,height:_.height},h,_.scaleX,_.scaleY),x=ccn(b),S=(t,i)=>{if(!n)return;i.preventDefault(),i.stopPropagation(),i.currentTarget.setPointerCapture(i.pointerId);let o=o6(e.element)??u6;r.current={edge:t,pointerId:i.pointerId,startX:i.clientX,startY:i.clientY,startInsets:o,insets:o,radius:o.radius,angleDeg:_.angleDeg,scaleX:_.scaleX,scaleY:_.scaleY},u(e=>({...e,insets:o})),a(!0)},C=e=>{let t=r.current;if(!t||!J4(t,e))return;e.preventDefault(),e.stopPropagation();let n=Ain(e.clientX-t.startX,e.clientY-t.startY,t.angleDeg),i={startInsets:t.startInsets,deltaX:n.deltaX,deltaY:n.deltaY,scaleX:t.scaleX,scaleY:t.scaleY},a=t.edge===`move`?Cin(i):Sin({...i,edge:t.edge,width:v,height:y});t.insets=a,u(e=>({...e,insets:a}))},w=e=>{let t=r.current;return!t||t.pointerId!==e.pointerId?null:(e.preventDefault(),e.stopPropagation(),r.current=null,a(!1),t)},T=e=>{let t=w(e);if(!t)return;let n=D4(t.insets,t.radius);n!==D4(t.startInsets,t.radius)&&E(n,`drag`)},E=(e,t)=>{let r=n?.(`clip-path`,e);Promise.resolve(r).then(e=>h4(`crop`,t,e)).catch(()=>void 0)},D=t=>{let n=t??{top:0,right:0,bottom:0,left:0};u(e=>({...e,insets:n}));let r=o6(e.element)?.radius??0;E(t===null?``:D4(n,r),`button`)},O=e=>{let t=w(e);t&&u(e=>({...e,insets:t.startInsets}))};return l.croppable?(0,W.jsxs)(W.Fragment,{children:[p&&n&&(0,W.jsx)(rcn,{left:_.left+_.width/2,top:_.top,elementWidth:v,elementHeight:y,onApply:D,onDone:f}),(0,W.jsxs)(`div`,{"data-dom-edit-crop-frame":`true`,className:`pointer-events-none absolute`,style:{left:_.left,top:_.top,width:_.width,height:_.height,transform:_.angleDeg===0?void 0:`rotate(${_.angleDeg}deg)`},children:[g&&(0,W.jsx)(`div`,{className:`pointer-events-none absolute inset-0 overflow-hidden`,children:(0,W.jsx)(`div`,{className:`absolute`,style:{left:b.left,top:b.top,width:b.width,height:b.height,boxShadow:`0 0 0 100000px rgba(8, 8, 12, 0.6)`}})}),(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute border border-dashed border-studio-accent`,style:{left:b.left,top:b.top,width:b.width,height:b.height},children:i&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`absolute inset-y-0 left-1/3 w-px bg-studio-accent/40`}),(0,W.jsx)(`div`,{className:`absolute inset-y-0 left-2/3 w-px bg-studio-accent/40`}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-1/3 h-px bg-studio-accent/40`}),(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-2/3 h-px bg-studio-accent/40`})]})}),g&&x>0&&(0,W.jsx)(`button`,{type:`button`,"aria-label":`Reposition crop`,title:`Reposition crop`,"data-dom-edit-crop-handle":`true`,className:`pointer-events-auto absolute rounded-full border-2 border-studio-accent bg-studio-accent/30 shadow-[0_0_0_1px_rgba(0,0,0,0.4)]`,style:{left:b.left+(b.width-x)/2,top:b.top+(b.height-x)/2,width:x,height:x,cursor:`move`,touchAction:`none`},onPointerDown:e=>S(`move`,e),onPointerMove:C,onPointerUp:T,onPointerCancel:O}),lcn.map(e=>{let t=scn(e,b);if(!t)return null;let n=i||g||o===e;return(0,W.jsx)(`button`,{type:`button`,"aria-label":`Crop ${e}`,title:`Crop`,"data-dom-edit-crop-handle":`true`,className:`pointer-events-auto absolute flex items-center justify-center border-0 bg-transparent p-0`,style:{...t.hit,cursor:t.cursor,touchAction:`none`},onPointerEnter:()=>s(e),onPointerLeave:()=>s(t=>t===e?null:t),onPointerDown:t=>S(e,t),onPointerMove:C,onPointerUp:T,onPointerCancel:O,children:(0,W.jsx)(`span`,{className:`pointer-events-none rounded-full bg-studio-accent/90 shadow-[0_0_0_1px_rgba(0,0,0,0.4)] transition-opacity duration-100`,style:{...t.pill,opacity:+!!n}})},e)})]})]}):null}function dcn({overlayRect:e,cropOutlineInsetPx:t,onStartRotate:n}){let r=t??{top:0,right:0,bottom:0,left:0},i=e.left+r.left,a=Math.max(0,e.width-r.left-r.right),o=e.top+e.height-r.bottom;return(0,W.jsx)(`button`,{type:`button`,className:`pointer-events-auto absolute flex items-center justify-center border-0 bg-transparent p-0`,style:{left:i+a/2,top:o+12,width:22,height:22,transform:`translateX(-50%)`,touchAction:`none`,cursor:`grabbing`},title:`Rotate`,"aria-label":`Rotate selection`,onPointerDown:n,children:(0,W.jsx)(`span`,{className:`pointer-events-none flex h-[18px] w-[18px] items-center justify-center rounded-full border border-studio-accent/70 bg-studio-surface text-accent-ink shadow-[0_0_3px_rgba(0,0,0,0.45)]`,children:(0,W.jsxs)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,W.jsx)(`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`}),(0,W.jsx)(`path`,{d:`M21 3v5h-5`}),(0,W.jsx)(`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`}),(0,W.jsx)(`path`,{d:`M8 16H3v5`})]})})})}var fcn=[{handle:`nw`,cursor:`nwse-resize`,x:`left`,y:`top`},{handle:`ne`,cursor:`nesw-resize`,x:`right`,y:`top`},{handle:`sw`,cursor:`nesw-resize`,x:`left`,y:`bottom`},{handle:`se`,cursor:`nwse-resize`,x:`right`,y:`bottom`}],pcn={top:0,right:0,bottom:0,left:0};function mcn(e,t,n){let r=N4/2,i=n??pcn,a={cursor:e.cursor,touchAction:`none`};return a.left=e.x===`left`?t.left+i.left-r:t.left+t.width-i.right-r,a.top=e.y===`top`?t.top+i.top-r:t.top+t.height-i.bottom-r,a}function hcn({groupOverlayItems:e,groupBounds:t,allowCanvasMovement:n,allowBodyDrag:r,groupCanMove:i,gestures:a,onBoxClick:o}){let s=n&&!V2();return(0,W.jsxs)(W.Fragment,{children:[e.map(e=>(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute rounded-xl border border-studio-accent/70`,style:{left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height}},e.key)),(0,W.jsx)(`div`,{"data-dom-edit-selection-box":`true`,className:`pointer-events-auto absolute rounded-xl border border-studio-accent shadow-[0_0_0_1px_rgba(60,230,172,0.3)]`,style:{left:t.left,top:t.top,width:t.width,height:t.height,cursor:r?s&&i?`move`:`default`:void 0},onPointerDown:e=>{!s||!r||e.shiftKey&&!i||a.startGroupDrag(e)},onClick:o})]})}function gcn({selection:e,overlayRect:t,allowCanvasMovement:n,allowBodyDrag:r,cropOutlineInsetPx:i,boxRef:a,boxChromeClass:o,boxClipPath:s,selectionKey:c,groupSelectionCount:l,gestures:u,onStyleCommit:d,onBoxClick:f,inlineText:p}){let m=p?.editing??!1,h=V2(),g=n&&!h;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{"data-dom-edit-chrome":`true`,className:`pointer-events-none absolute inset-0`,style:{transformOrigin:`${t.left+t.width/2}px ${t.top+t.height/2}px`,transform:t.angle?`rotate(${t.angle}deg)`:void 0},children:[g&&!m&&e.capabilities.canApplyManualRotation&&(0,W.jsx)(dcn,{overlayRect:t,cropOutlineInsetPx:i,onStartRotate:e=>{e.stopPropagation(),u.startGesture(`rotate`,e)}}),(0,W.jsx)(`div`,{ref:a,"data-dom-edit-selection-box":`true`,className:`${m?`pointer-events-none`:`pointer-events-auto`} absolute rounded-md ${o}`,style:{left:t.left,top:t.top,width:t.width,height:t.height,clipPath:s,cursor:r?g&&e.capabilities.canApplyManualOffset?`move`:`default`:void 0},onPointerDown:t=>{if(p?.startFromPress(t)){t.preventDefault(),t.stopPropagation();return}if(!(!r||!g)){if(e.capabilities.canApplyManualOffset){u.startGesture(`drag`,t);return}t.shiftKey||u.startBlockedMove(t,e)}},onClick:f,children:i&&(0,W.jsx)(`div`,{className:`pointer-events-none absolute rounded-md border border-studio-accent/80 shadow-[0_0_0_1px_rgba(60,230,172,0.25)]`,style:{left:i.left,top:i.top,right:i.right,bottom:i.bottom}})},c),g&&!m&&e.capabilities.canApplyManualSize&&fcn.map(n=>n.handle!==`se`&&!e.capabilities.canApplyManualOffset?null:(0,W.jsx)(`div`,{className:`pointer-events-auto absolute flex h-4 w-4 items-center justify-center`,style:{...mcn(n,t,i??void 0),cursor:kan(n.handle,t.angle??0)},onPointerDown:e=>{e.stopPropagation(),u.startGesture(`resize`,e,{resizeHandle:n.handle})},children:(0,W.jsx)(`div`,{className:`pointer-events-none h-[12px] w-[12px] rounded-full border-[1.5px] border-studio-accent bg-white shadow-[0_0_3px_rgba(0,0,0,0.45)]`})},n.handle))]}),e.capabilities.canCrop&&!m&&!h&&l<=1&&(0,W.jsx)(ucn,{selection:e,overlayRect:t,onStyleCommit:d})]})}function _cn(e){let{selection:t,overlayRect:n}=e,r=t&&!_in(t.element)?k4(t.element):null,i=!!(r&&(r.top>0||r.right>0||r.bottom>0||r.left>0)),a=n&&n.editScaleX>0?n.editScaleX:1,o=n&&n.editScaleY>0?n.editScaleY:1;return{hasCropInsets:i,cropOutlineInsetPx:r&&i?{top:r.top*o,right:r.right*a,bottom:r.bottom*o,left:r.left*a}:void 0}}function vcn(e){let t={borderRadius:8,clipPath:void 0};if(!e?.element)return t;try{let n=e.element.tagName.toLowerCase();if(n===`svg`||n===`img`||n===`video`||n===`canvas`)return t;let r=e.element.ownerDocument.defaultView;if(!r)return t;let i=r.getComputedStyle(e.element),a=i.borderRadius,o=i.clipPath;return{borderRadius:a&&a!==`0px`?a:4,clipPath:o&&o!==`none`?o:void 0}}catch{return t}}function ycn(e,t){return e?``:t?`shadow-[inset_0_0_0_2px_rgba(60,230,172,0.6)]`:`border border-studio-accent/80 shadow-[0_0_0_1px_rgba(60,230,172,0.25)]`}var bcn={"bring-forward":[`M3 11 L8 8.5 L13 11 L8 13.5 Z`,`M8 8.5 L8 2`,`M5.5 4.5 L8 2 L10.5 4.5`],"send-backward":[`M3 5 L8 2.5 L13 5 L8 7.5 Z`,`M8 7.5 L8 14`,`M5.5 11.5 L8 14 L10.5 11.5`],"bring-to-front":[`M3 9.5 L8 7 L13 9.5 L8 12 Z`,`M3 12.5 L8 10 L13 12.5 L8 15 Z`,`M8 12.5 L8 2`,`M5.5 4.5 L8 2 L10.5 4.5`],"send-to-back":[`M3 4 L8 1.5 L13 4 L8 6.5 Z`,`M3 7 L8 4.5 L13 7 L8 9.5 Z`,`M8 3.5 L8 14`,`M5.5 11.5 L8 14 L10.5 11.5`]};function xcn({action:e}){return(0,W.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`mr-2 shrink-0`,"aria-hidden":`true`,children:bcn[e].map(e=>(0,W.jsx)(`path`,{d:e},e))})}var Scn=[{action:`bring-to-front`,label:`Bring to front`},{action:`bring-forward`,label:`Bring forward`},{action:`send-backward`,label:`Send backward`},{action:`send-to-back`,label:`Send to back`}],Ccn=(0,U.memo)(function({x:e,y:t,selection:n,onClose:r,onApplyZIndex:i,onZOrderCrossed:a,onDelete:o}){let s=yG(r),c=!!i,l=!!o,u=c&&l,d=t+(8+(c?Scn.length*28:0)+ +!!u+(l?28:0)+8)-window.innerHeight,f=e+200>window.innerWidth?e-200:e,p=d>0?t-d-8:t,m=n.element;function h(e){if(!i)return;let t=FJt(m,e);if(t===null)return;let{patches:n,crossed:o}=t;i(n,e,o),o&&a&&a(o,e),r()}function g(){o&&(o(n),r())}if(!c&&!l)return null;let _=e=>{e.stopPropagation()};return(0,pm.createPortal)((0,W.jsxs)(`div`,{ref:s,className:`${wQ.panel} fixed z-200 min-w-[180px]`,style:{left:f,top:p},onPointerDown:_,onMouseDown:_,onClick:_,onContextMenu:e=>{e.preventDefault(),e.stopPropagation()},children:[c&&Scn.map(({action:e,label:t})=>{let n=PJt(m,e);return(0,W.jsxs)(`button`,{type:`button`,className:`w-full flex items-center px-3 py-1.5 text-xs text-left ${n?`text-neutral-300 hover:bg-neutral-800 cursor-pointer`:`text-neutral-600 cursor-not-allowed`}`,disabled:!n,onPointerDown:t=>{t.button===0&&(t.preventDefault(),t.stopPropagation(),n&&h(e))},children:[(0,W.jsx)(xcn,{action:e}),(0,W.jsx)(`span`,{children:t})]},e)}),u&&(0,W.jsx)(`div`,{className:wQ.divider}),l&&(0,W.jsxs)(`button`,{type:`button`,className:`w-full flex items-center justify-between px-3 py-1.5 text-xs text-danger-ink hover:bg-neutral-800 cursor-pointer text-left`,onPointerDown:e=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),g())},children:[(0,W.jsx)(`span`,{children:`Delete`}),(0,W.jsx)(`span`,{className:`text-neutral-500 text-[10px] ml-3`,children:`⌫`})]})]}),document.body)}),wcn=2;function Tcn({session:e,iframe:t}){let[n,r]=(0,U.useState)(null),i=e?.element??null;return(0,U.useEffect)(()=>{if(!i||!t){r(null);return}let e=i.ownerDocument,n=e.defaultView,a=t.ownerDocument.defaultView,o=Ecn(i),s=i.style.caretColor;i.style.caretColor=`transparent`;let c=!1,l=`after`,u=()=>r(c?null:kcn(i,t,o,l)),d=({key:e})=>{Dcn.has(e)||(l=Ocn[e]??`after`)},f=()=>void(l=`after`),p=e=>()=>{c=e,u()},m=p(!0),h=p(!1),g=``,_=0,v=()=>{let{left:e,top:n,width:r,height:i}=t.getBoundingClientRect(),o=`${e},${n},${r},${i}`;o!==g&&(g=o,u()),_=a?.requestAnimationFrame(v)??0};return e.addEventListener(`selectionchange`,u),i.addEventListener(`keydown`,d),i.addEventListener(`pointerdown`,f),i.addEventListener(`input`,u),i.addEventListener(`focus`,u),i.addEventListener(`blur`,u),i.addEventListener(`compositionstart`,m),i.addEventListener(`compositionend`,h),n?.addEventListener(`resize`,u),n?.addEventListener(`scroll`,u,!0),v(),()=>{a?.cancelAnimationFrame(_),e.removeEventListener(`selectionchange`,u),i.removeEventListener(`keydown`,d),i.removeEventListener(`pointerdown`,f),i.removeEventListener(`input`,u),i.removeEventListener(`focus`,u),i.removeEventListener(`blur`,u),i.removeEventListener(`compositionstart`,m),i.removeEventListener(`compositionend`,h),n?.removeEventListener(`resize`,u),n?.removeEventListener(`scroll`,u,!0),i.style.caretColor=s}},[i,t]),!n||!t?null:(0,pm.createPortal)((0,W.jsx)(`div`,{"data-inline-text-caret":`true`,"aria-hidden":`true`,className:`hf-inline-text-caret pointer-events-none fixed z-200`,style:{left:n.left,top:n.top,width:wcn,height:n.height,background:n.color}},`${n.left},${n.top}`),t.ownerDocument.body)}function Ecn(e){let t=e.ownerDocument.defaultView?.getComputedStyle(e);return t?t.caretColor&&t.caretColor!==`auto`?t.caretColor:t.color:`currentColor`}var Dcn=new Set([`Shift`,`Control`,`Alt`,`Meta`]),Ocn={End:`before`};function kcn(e,t,n,r){let i=e.ownerDocument.defaultView,a=i?jcn(e,i):null;if(!i||!a)return null;let o=r===`before`&&Mcn(a)||Acn(a,e,i),s=t.getBoundingClientRect(),c=i.innerWidth?s.width/i.innerWidth:1;return{left:s.left+o.left*c-wcn/2,top:s.top+o.top*c,height:o.height*c,color:n}}function Acn(e,t,n){let r=[...e.getClientRects()].reverse().find(e=>e.height>0);if(r)return{left:r.left,top:r.top,height:r.height};let i=Ncn(e);if(i)return i;let a=n.getComputedStyle(t),o=t.getBoundingClientRect(),s=Number.parseFloat(a.fontSize)||16,c=Number.parseFloat(a.lineHeight)||s*1.2;return{left:o.left+(Number.parseFloat(a.paddingLeft)||0),top:o.top+(Number.parseFloat(a.paddingTop)||0),height:c}}function jcn(e,t){let n=e.ownerDocument,r=t.getSelection();if(!r||r.rangeCount===0||!r.isCollapsed||!n.hasFocus()||!e.contains(n.activeElement))return null;let i=r.getRangeAt(0);return e.contains(i.startContainer)?i:null}function Mcn({startContainer:e,startOffset:t}){if(e.nodeType!==Node.TEXT_NODE||t===0)return null;let n=e.ownerDocument.createRange(),r=/[\uDC00-\uDFFF]/.test(e.data[t-1]??``);n.setStart(e,t-(r&&t>1?2:1)),n.setEnd(e,t);let i=[...n.getClientRects()].find(e=>e.height>0);return i?{left:i.right,top:i.top,height:i.height}:null}function Ncn(e){let[t,n]=Pcn(e),r=t&&t.nodeName!==`BR`?t:n??t;if(!r)return null;let i=e.cloneRange();i.selectNode(r);let a=[...i.getClientRects()].filter(e=>e.height>0),o=r===t,s=o?a.at(-1):a[0];return s?{left:o?s.right:s.left,top:s.top,height:s.height}:null}function Pcn({startContainer:e,startOffset:t}){return e.nodeType===Node.TEXT_NODE?[e.previousSibling,e.nextSibling]:[e.childNodes[t-1]??null,e.childNodes[t]??null]}var Fcn={B:{"font-weight":`700`},STRONG:{"font-weight":`700`},I:{"font-style":`italic`},EM:{"font-style":`italic`},U:{"text-decoration-line":`underline`}},Icn=`\0`;function Lcn(e,t){if(e.collapsed)return;let n=Ucn(e.startContainer);if(!n||!Hcn(n,e))return;let r=Wcn(n),i=zcn(r,m6(n,e.startContainer,e.startOffset),m6(n,e.endContainer,e.endOffset));i&&(rln(n,Qcn(r,i.start,i.end,t)),Rcn(n),fln(n,i.start,i.end))}function Rcn(e){let t=e.ownerDocument.defaultView;if(t?.getComputedStyle)for(let n of e.querySelectorAll(`span`)){if(!n.style.color)continue;n.style.getPropertyValue(`-webkit-text-fill-color`)===n.style.color&&n.style.removeProperty(`-webkit-text-fill-color`);let e=t.getComputedStyle(n),r=e.webkitTextFillColor;!r||!e.color||r!==e.color&&n.style.setProperty(`-webkit-text-fill-color`,n.style.color)}}function zcn(e,t,n){if(t===null||n===null||t>=n)return null;let r=e.map(e=>e.text).join(``),i=new Intl.Segmenter(void 0,{granularity:`grapheme`}),a=[0,...Array.from(i.segment(r),Bcn)];return{start:Vcn(a,t),end:a.find(e=>e>=n)??n}}function Bcn({index:e,segment:t}){return e+t.length}function Vcn(e,t){let n=t;for(let r of e){if(r>t)return n;n=r}return n}function Hcn(e,t){return e.contains(t.startContainer)&&e.contains(t.endContainer)}function d6(e){let t=Ucn(e.startContainer);if(!t||!Hcn(t,e))return null;let n=m6(t,e.startContainer,e.startOffset),r=m6(t,e.endContainer,e.endOffset);if(n===null||r===null)return null;let i=n===r,a=Zcn(Wcn(t)).slice(i?Math.max(0,n-1):n,i?Math.max(1,n):r).map(e=>({char:e.char,style:e.style,painter:e.painter??null}));return a.length>0?a:null}function Ucn(e){let t=e.nodeType===1?e:e.parentElement,n=t?.closest(`[contenteditable]`);if(n)return n.getAttribute(`contenteditable`)?.toLowerCase()===`false`?null:n;for(;t?.parentElement&&Q9e(t.tagName);)t=t.parentElement;return t}function Wcn(e){let t=[],n=Array.from(e.childNodes,e=>({node:e,inherited:{},origin:null})).reverse();for(let e=n.pop();e;e=n.pop())n.push(...Gcn(e,t));return t}function Gcn(e,t){let{node:n,inherited:r,origin:i}=e;if(n.nodeType===3){let e=n.textContent??``;return e&&t.push({...qcn(e,r,i),painter:n.parentElement}),[]}if(!Kcn(n))return[];let a=n;return a.tagName===`BR`?(t.push(qcn(Icn,r,i)),[]):Jcn(a,r,i)}function Kcn(e){return e.nodeType===1&&`style`in e}function qcn(e,t,n){return{text:e,style:t,origin:n,identity:Ycn(n)}}function Jcn(e,t,n){let r=Q9e(e.tagName),i=r?{...t,...Fcn[e.tagName],...Xcn(e)}:t,a=r&&!n&&p6(e).size>0?e:n;return Array.from(e.childNodes,e=>({node:e,inherited:i,origin:a})).reverse()}function Ycn(e){return e?JSON.stringify([...p6(e)].sort(([e],[t])=>e<t?-1:1)):``}function Xcn(e){let t={};for(let n=0;n<e.style.length;n+=1){let r=e.style.item(n);if(!r)continue;let i=e.style.getPropertyValue(r);eet(r,i)&&(t[r]=i)}return t}function Zcn(e){let t=[];for(let n of e)for(let e=0;e<n.text.length;e+=1)t.push({char:n.text[e]??``,style:n.style,origin:n.origin,identity:n.identity,painter:n.painter});return t}function Qcn(e,t,n,r){let i=e.map(e=>e.text).join(``),a=Zcn(e),o=[];for(let e=0;e<i.length;e+=1)eln(o,i[e]??``,$cn(a[e],e>=t&&e<n,r));return o}function $cn(e,t,n){let r=e?.style??{};return{style:t?tln(r,n):r,origin:e?.origin??null,identity:e?.identity??``}}function eln(e,t,n){let r=e[e.length-1];if(r&&r.identity===n.identity&&nln(r.style,n.style)){r.text+=t;return}e.push({text:t,...n})}function tln(e,t){let n={...e};for(let[e,r]of Object.entries(t))r===null?delete n[e]:n[e]=r;return n}function nln(e,t){return f6(e)===f6(t)}function f6(e){return Object.keys(e).sort().map(t=>`${t}: ${e[t]}`).join(`; `)}function rln(e,t){let n=e.ownerDocument,r=iln(n,t);if(e.replaceChildren(),r.length>1&&cln(e)){let t=n.createElement(`span`);t.append(...r),e.append(t);return}e.append(...r)}function iln(e,t){let n=[],r=new Set;for(let i of t){let t=i.origin&&!r.has(i.origin)?p6(i.origin):new Map;t.size>0&&i.origin&&r.add(i.origin),n.push(...aln(e,i,t))}return n}function aln(e,t,n){let r=f6(t.style),i=[];for(let[a,o]of t.text.split(Icn).entries()){if(a>0&&i.push(e.createElement(`br`)),!o)continue;if(!r&&n.size===0){i.push(e.createTextNode(o));continue}let t=e.createElement(`span`);for(let[e,r]of n)t.setAttribute(e,r);r&&t.setAttribute(`style`,r),t.textContent=o,i.push(t),n.clear()}return i}var oln=`data-hf-id`;function p6(e){let t=new Map;for(let n of e.getAttributeNames()){if(n===`style`||n===oln)continue;let r=e.getAttribute(n)??``;$9e(n,r)&&t.set(n,r)}return t}var sln=new Set([`flex`,`inline-flex`,`grid`,`inline-grid`,`-webkit-box`,`-webkit-inline-box`]);function cln(e){let t=e.ownerDocument.defaultView;return t?sln.has(t.getComputedStyle(e).display):!1}function m6(e,t,n){if(t===e)return Array.from(e.childNodes).slice(0,n).reduce((e,t)=>e+uln(t),0);let r=0,i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),a=i.nextNode();for(;a;){if(a===t)return r+n;r+=lln(a),a=i.nextNode()}return null}function lln(e){return e.nodeType===3?(e.textContent??``).length:+(dln(e)===`BR`)}function uln(e){let t=0,n=[e];for(let e=n.pop();e;e=n.pop())t+=lln(e),n.push(...Array.from(e.childNodes));return t}function dln(e){return e.nodeType===1?e.tagName:``}function fln(e,t,n){let r=e.ownerDocument,i=r.defaultView?.getSelection(),a=pln(e,t),o=pln(e,n);if(!i||!a||!o)return;let s=r.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset),i.removeAllRanges(),i.addRange(s)}function pln(e,t){let n=0,r=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),i=r.nextNode(),a=null;for(;i;){if(i.nodeType!==3){dln(i)===`BR`&&(n+=1),i=r.nextNode();continue}let e=(i.textContent??``).length;if(n+e>=t)return{node:i,offset:t-n};n+=e,a=i,i=r.nextNode()}return a?{node:a,offset:(a.textContent??``).length}:{node:e,offset:0}}function mln(e,t){let n=d6(e);if(!n)return{};let r={};for(let e of t){let t=n[0]?.style[e];t!==void 0&&n.every(({style:n})=>n[e]===t)&&(r[e]=t)}return r}function hln(e,t){let n=d6(e);if(!n)return[];let r=new Set,i=[];for(let{char:e,style:a}of n){if(!e.trim())continue;let n=a[t];n===void 0||r.has(n)||(r.add(n),i.push(n))}return i}function gln(e,t){let n=d6(e);if(!n)return null;let r=n.filter(({char:e})=>e.trim());return(r.find(({style:e})=>e[t]!==void 0)??r[0]??n[0])?.painter??null}var _ln=[`color`,`font-weight`,`font-style`,`text-decoration-line`],vln=10,yln=34,bln=`#ffffff`;function xln({session:e,iframe:t}){let[n,r]=(0,U.useState)(null),i=(0,U.useCallback)(()=>{r(e&&t?wln(e.element,t):null)},[e,t]);(0,U.useEffect)(()=>{let t=e?.element.ownerDocument;if(!t){r(null);return}return t.addEventListener(`selectionchange`,i),()=>t.removeEventListener(`selectionchange`,i)},[e,i]);let a=(0,U.useCallback)(t=>{let n=(e?.element.ownerDocument)?.defaultView?.getSelection();!n||n.rangeCount===0||(Lcn(n.getRangeAt(0),t),i())},[e,i]);if(!n||!t)return null;let o=n.styles;return(0,pm.createPortal)((0,W.jsxs)(`div`,{"data-inline-text-toolbar":`true`,role:`toolbar`,"aria-label":`Text formatting`,className:`pointer-events-auto fixed z-200 flex items-center gap-1 rounded-lg border border-border bg-raised p-1 shadow-[0_8px_24px_rgba(0,0,0,0.55)]`,style:{left:n.left,top:n.top,transform:`translate(-50%, ${n.placeBelow?`0`:`-100%`})`},onPointerDown:Cln,onMouseDown:Cln,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`label`,{className:`group relative flex h-6 w-6 cursor-pointer items-center justify-center rounded-md hover:bg-hover`,title:`Text colour`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`h-4 w-4 rounded-full border-2 border-border-strong transition-transform duration-150 group-hover:scale-110 group-active:scale-95`,style:{background:Sln(n.colours,o.color),backgroundOrigin:`border-box`}}),(0,W.jsx)(`input`,{type:`color`,"aria-label":`Text colour`,className:`absolute inset-0 h-full w-full min-w-0 cursor-pointer opacity-0`,value:n.pickerColour,onChange:e=>a({color:e.target.value})})]}),(0,W.jsx)(h6,{label:`Bold`,glyph:`B`,bold:!0,on:Tln(o[`font-weight`]),onToggle:e=>a({"font-weight":e?`700`:null})}),(0,W.jsx)(h6,{label:`Italic`,glyph:`I`,italic:!0,on:o[`font-style`]===`italic`,onToggle:e=>a({"font-style":e?`italic`:null})}),(0,W.jsx)(h6,{label:`Underline`,glyph:`U`,underline:!0,on:o[`text-decoration-line`]===`underline`,onToggle:e=>a({"text-decoration-line":e?`underline`:null})})]}),t.ownerDocument.body)}function Sln(e,t){return e.length===0?t||bln:e.length===1?e[0]:`linear-gradient(135deg, ${e.map((t,n)=>`${t} ${(n/(e.length-1)*100).toFixed(2)}%`).join(`, `)})`}function Cln(e){e.preventDefault(),e.stopPropagation()}function h6({label:e,glyph:t,on:n,onToggle:r,bold:i,italic:a,underline:o}){return(0,W.jsx)(`button`,{type:`button`,title:e,"aria-label":e,"aria-pressed":n,className:`flex h-6 w-6 items-center justify-center rounded-md text-xs ${n?`bg-studio-accent/20 text-accent-ink`:`text-text-2 hover:bg-hover`}`,style:{fontWeight:i?700:400,fontStyle:a?`italic`:`normal`,textDecoration:o?`underline`:`none`},onClick:()=>r(!n),children:t})}function wln(e,t){let n=e.ownerDocument.defaultView,r=n?.getSelection();if(!n||!r||r.rangeCount===0||r.isCollapsed)return null;let i=r.getRangeAt(0);if(!e.contains(i.commonAncestorContainer))return null;let a=i.getBoundingClientRect(),o=t.getBoundingClientRect(),s=n.innerWidth?o.width/n.innerWidth:1,c=o.top+a.top*s-vln,l=c<yln,u=mln(i,_ln),d=hln(i,`color`);return{left:o.left+(a.left+a.width/2)*s,top:l?o.top+(a.top+a.height)*s+vln:c,placeBelow:l,styles:u,colours:d,pickerColour:g(u.color??d[0],gln(i,`color`),bln)}}function Tln(e){return e?e===`bold`||e===`bolder`||Number.parseInt(e,10)>=600:!1}var Eln=`true`,Dln=`2px solid #3CE6AC`;function Oln(e){let t=e.ownerDocument.defaultView?.getSelection();if(!t||t.rangeCount===0)return;let n=t.getRangeAt(0);!e.contains(n.startContainer)&&!e.contains(n.endContainer)||t.removeAllRanges()}function kln({onCommit:e,onPause:t}){let n=V2(),[r,i]=(0,U.useState)(null),a=(0,U.useRef)(null),o=(0,U.useRef)(null),s=(0,U.useCallback)(()=>{let e=a.current;return e?(o.current!==null&&(e.element.ownerDocument.defaultView?.cancelAnimationFrame(o.current),o.current=null),a.current=null,W0(e.element,e.gesture),i(null),e.element.isConnected&&(e.element.removeAttribute(`contenteditable`),e.element.style.outline=e.outline,e.element.style.outlineOffset=e.outlineOffset,Oln(e.element),e.element.blur()),e):null},[]),c=(0,U.useCallback)((e,r)=>{if(a.current||n)return!1;let s={element:e,original:e.innerHTML,outline:e.style.outline,outlineOffset:e.style.outlineOffset,gesture:H0(e,`edit`)};e.style.outline=Dln,e.style.outlineOffset=`2px`,a.current=s,i(s),t?.(),e.setAttribute(`contenteditable`,Eln);let c=e.ownerDocument.defaultView?.requestAnimationFrame(()=>{o.current=null,a.current?.element===e&&(e.focus({preventScroll:!0}),Aln(e,r))});return o.current=c??null,!0},[t,n]),l=(0,U.useCallback)(()=>{let t=a.current;if(!t)return;net(t.element);let n=t.element.innerHTML,r=()=>{};dX(new Promise(e=>r=e)),r(q0(t.element,()=>(s(),e({element:t.element,html:n,previousHtml:t.original}))))},[e,s]),u=(0,U.useCallback)(()=>{let e=a.current;e&&(e.element.isConnected&&(e.element.innerHTML=e.original),s())},[s]);(0,U.useEffect)(()=>{n&&a.current&&u()},[u,n]),(0,U.useEffect)(()=>{let e=r?.element;if(!e)return;let t=e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),l();return}e.key===`Escape`&&(e.preventDefault(),l())},n=()=>l(),i=t=>{t&&e.ownerDocument.execCommand(`insertText`,!1,t)},a=e=>{e.preventDefault(),i(e.clipboardData?.getData(`text/plain`)??``)},o=e=>e.preventDefault(),s=e=>{e.preventDefault(),i(e.dataTransfer?.getData(`text/plain`)??``)};return e.addEventListener(`keydown`,t),e.addEventListener(`blur`,n),e.addEventListener(`paste`,a),e.addEventListener(`dragover`,o),e.addEventListener(`drop`,s),()=>{e.removeEventListener(`keydown`,t),e.removeEventListener(`blur`,n),e.removeEventListener(`paste`,a),e.removeEventListener(`dragover`,o),e.removeEventListener(`drop`,s)}},[r,l]);let d=(0,U.useRef)(l);return d.current=l,(0,U.useEffect)(()=>()=>d.current(),[]),{session:r,start:c,commit:l,cancel:u}}function Aln(e,t){let n=e.ownerDocument,r=n.defaultView?.getSelection();if(!r)return;let i=t?jln(n,t):null;if(i&&e.contains(i.startContainer)){r.removeAllRanges(),r.addRange(i);return}Mln(e)}function jln(e,t){let n=e;if(typeof n.caretRangeFromPoint==`function`)return n.caretRangeFromPoint(t.x,t.y);let r=e.caretPositionFromPoint?.(t.x,t.y);if(!r)return null;let i=e.createRange();return i.setStart(r.offsetNode,r.offset),i.collapse(!0),i}function Mln(e){let t=e.ownerDocument,n=t.defaultView?.getSelection();if(!n)return;let r=t.createRange(),i=e.lastChild;i&&i.nodeType===3?(r.setStart(i,i.textContent?.length??0),r.collapse(!0)):(r.selectNodeContents(e),r.collapse(!1)),n.removeAllRanges(),n.addRange(r)}function Nln(e){return!e||!Se(e)||e.isCompositionHost||e.isInsideLockedComposition?!1:e.textFields.length<=1||g6(e.element)}function g6(e){if(!e)return!1;let t=e.tagName;return t===`BODY`||t===`HTML`||!_6(e)||e.isContentEditable?!1:(e.textContent??``).trim().length>0}function _6(e){for(let t of Array.from(e.children))if(!Q9e(t.tagName)||!Pln(t)||!_6(t))return!1;return!0}function Pln(e){return e.namespaceURI===`http://www.w3.org/1999/xhtml`}var Fln=450,Iln=6;function Lln(e,t){return e?t.element!==null&&e.element===t.element&&t.at-e.at<=Fln&&Math.abs(t.x-e.x)<=Iln&&Math.abs(t.y-e.y)<=Iln:!1}function Rln(e,{enterFromWindow:t=!1}={}){let n=AX(),r=kln({onCommit:e=>n?.handleDomRichTextCommit(e),onPause:()=>X.getState().setIsPlaying(!1)}),i=(0,U.useRef)(null),a=t=>{let r=n?.previewIframeRef?.current;return r?v4(r,t.clientX,t.clientY,e.current?.compositionPath??null):null},o=e=>{let t=n?.previewIframeRef?.current,r=t?.contentWindow;if(!t||!r?.innerWidth)return;let i=t.getBoundingClientRect(),a=i.width/r.innerWidth||1;return{x:(e.clientX-i.left)/a,y:(e.clientY-i.top)/a}},s=t=>{if(t.key!==`Enter`||t.shiftKey||t.ctrlKey||t.metaKey||t.altKey)return!1;let n=e.current;return r.session||!n||!Nln(n)?!1:r.start(n.element)},c=(0,U.useRef)(s);return c.current=s,(0,U.useEffect)(()=>{if(!t)return;let e=e=>{let{body:t,documentElement:n}=window.document;e.defaultPrevented||e.target!==t&&e.target!==n||c.current(e)&&e.preventDefault()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),{editing:r.session!==null,toolbar:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(xln,{session:r.session,iframe:n?.previewIframeRef?.current??null}),(0,W.jsx)(Tcn,{session:r.session,iframe:n?.previewIframeRef?.current??null})]}),handleKeyDown:s,startFromPress:e=>{if(r.session)return!1;let t=a(e),n={x:e.clientX,y:e.clientY,at:Date.now(),element:t},s=Lln(i.current,n);return i.current=n,!s||!t||!g6(t)?!1:r.start(t,o(e))}}}function v6(e){return Math.round(e*100)/100}function zln(e){return e.map(e=>`${e.key}:${v6(e.left)},${v6(e.top)},${v6(e.width)},${v6(e.height)},${v6(e.angle??0)}`).join(`|`)}function Bln(e,t){let n=(e.angle??0)*Math.PI/180,r=(Math.abs(Math.cos(n))*e.width+Math.abs(Math.sin(n))*e.height)/2,i=(Math.abs(Math.sin(n))*e.width+Math.abs(Math.cos(n))*e.height)/2,a=e.left+e.width/2,o=e.top+e.height/2;return a-r<t.left||a+r>t.left+t.width||o-i<t.top||o+i>t.top+t.height}function Vln(e,t,n,r,i){if(!m(n,i.visible))return null;let a=W4(e,t,n,r,i);return a?{...a,...j4(a,n)}:null}function Hln(e,t,n,r,i,a,o,s,c){if(r.width<=0||!n){a.current=``,o.current=new Map,s([]);return}let l=n.querySelector(`[data-composition-id]`)??n.body,u=i??`index.html`,d=ot(l,{activeCompositionPath:u,isMasterView:!u||u===`index.html`},void 0,c),f=C4(t,e,n),p=jin(),m=[],h=new Map;for(let n of d){let i=Vln(t,e,n.element,f,p);i&&Bln(i,r)&&(m.push({key:n.key,left:i.left,top:i.top,width:i.width,height:i.height,angle:i.angle}),h.set(n.key,n.element))}let g=zln(m);g!==a.current&&(a.current=g,o.current=h,s(m))}function Uln(e){return`${Math.round(e.left)}:${Math.round(e.top)}:${Math.round(e.width)}:${Math.round(e.height)}`}function Wln(e){e.dirtyRef.current=!1,e.sigRef.current=``,e.elementsRef.current=new Map,e.setRects([])}function Gln(e,t,n){let r=e.defaultView?.MutationObserver??globalThis.MutationObserver;if(!r)return null;let i=new r(e=>{t.ingest(e),n()});return i.observe(e.documentElement,qt),i}var Kln=100;function qln(e,t,n){return e&&n-t>=Kln}function Jln(e){let t=``,n=-1/0,r=Dt(),i=()=>{e.dirtyRef.current=!0,Y2()},a=t=>{e.observerRef.current?.disconnect(),r.invalidateAll(),e.observerRef.current=t?.documentElement?Gln(t,r,i):null,e.observedDocRef.current=t,e.sigRef.current=``},o=X2(()=>{let o=e.iframeRef.current,s=e.overlayRef.current,c=o?.contentDocument??null;c!==e.observedDocRef.current&&(a(c),i());let l=e.compRectRef.current,u=Uln(l);if(u!==t&&(t=u,i()),!o||!s){e.dirtyRef.current&&Wln(e);return}let d=performance.now();qln(e.dirtyRef.current,n,d)&&(n=d,e.dirtyRef.current=!1,lt(e.observerRef.current,r),Hln(o,s,c,l,e.activeCompositionPathRef.current,e.sigRef,e.elementsRef,e.setRects,r))});return()=>{o(),e.observerRef.current?.disconnect(),e.observerRef.current=null,e.observedDocRef.current=null}}function Yln({iframeRef:e,overlayRef:t,compRectRef:n,activeCompositionPathRef:r,activeCompositionPath:i}){let a=(0,U.useRef)(new Map),[o,s]=(0,U.useState)([]),c=(0,U.useRef)(!0),l=(0,U.useRef)(``),u=(0,U.useRef)(null),d=(0,U.useRef)(null);return ax(()=>Jln({iframeRef:e,overlayRef:t,compRectRef:n,activeCompositionPathRef:r,dirtyRef:c,sigRef:l,observerRef:u,observedDocRef:d,elementsRef:a,setRects:s})),(0,U.useEffect)(()=>{c.current=!0},[i]),{offCanvasRects:o,offCanvasElementsRef:a}}var Xln=(0,U.memo)(function({iframeRef:e,activeCompositionPath:t,selection:n,groupSelections:r=[],hoverSelection:i,allowCanvasMovement:a=!0,allowBodyDrag:o=!0,canvasInput:s=`overlay`,onTextEditingChange:c,onSelectionBoxClick:l,onCanvasMouseDown:u,onCanvasPointerMove:d,onCanvasPointerLeave:f,onSelectionChange:p,onBlockedMove:m,onManualDragStart:h,onPathOffsetCommit:g,onGroupPathOffsetCommit:_,onBoxSizeCommit:v,onRotationCommit:y,onStyleCommit:b,onMarqueeSelect:x,onDeleteSelection:S,onApplyZIndex:C}){let w=V2(),T=s===`host`,E=o||!T,D=(0,U.useRef)(null),O=(0,U.useRef)(null),k=(0,U.useRef)(x);k.current=x;let A=vcn(n),j=(0,U.useRef)(null),M=(0,U.useRef)(null),N=(0,U.useRef)(null),P=(0,U.useRef)(null),F=(0,U.useRef)(!1),I=(0,U.useRef)(null),L=(0,U.useRef)(!1),R=(0,U.useRef)(n);R.current=n;let z=(e,t)=>{let n=R.current;n&&O.current?.contains(e.target)&&l?.(e,n),T||u(e,t)},{zOrderFlashRect:B,handleZOrderCrossed:V}=gan({overlayRef:D,iframeRef:e}),ee=(0,U.useRef)(t);ee.current=t;let te=(0,U.useRef)(r);te.current=r;let H=(0,U.useRef)(i);H.current=i;let ne=Rln(R,{enterFromWindow:T}),re=(0,U.useRef)(c);re.current=c,(0,U.useEffect)(()=>{if(ne.editing)return re.current?.(!0),()=>re.current?.(!1)},[ne.editing]);let ie=(0,U.useRef)(g);ie.current=(e,...t)=>q0(e.element,()=>g(e,...t));let ae=(0,U.useRef)(_);ae.current=e=>{let t=()=>_(e);return e[0]?q0(e[0].selection.element,t):t()};let oe=(0,U.useRef)(v);oe.current=(e,...t)=>q0(e.element,()=>v(e,...t));let se=(0,U.useRef)(y);se.current=(e,t)=>q0(e.element,()=>y(e,t));let ce=(0,U.useRef)(b);ce.current=b&&((e,t)=>{let n=()=>b(e,t);return R.current?q0(R.current.element,n):n()});let le=(0,U.useRef)(m);le.current=m;let ue=(0,U.useRef)(h);ue.current=h;let de=(0,U.useRef)(d);de.current=d;let fe=(0,U.useRef)(f);fe.current=f;let pe=(0,U.useRef)(p);pe.current=p;let{overlayRect:me,overlayRectRef:he,setOverlayRect:ge,hoverRect:_e,groupOverlayItems:ve,groupOverlayItemsRef:ye,setGroupOverlayItems:be,childRects:xe}=ban({iframeRef:e,overlayRef:D,selectionRef:R,activeCompositionPathRef:ee,groupSelectionsRef:te,hoverSelectionRef:H,rafPausedRef:L}),Se=Z2({iframeRef:e,overlayRef:D}),Ce=(0,U.useRef)(Se);Ce.current=Se;let{hasCropInsets:we,cropOutlineInsetPx:Te}=_cn({selection:n,overlayRect:me}),Ee=we?void 0:A.clipPath,De=ycn(!!Te,Ee),{offCanvasRects:Oe,offCanvasElementsRef:ke}=Yln({iframeRef:e,overlayRef:D,compRectRef:Ce,activeCompositionPathRef:ee,activeCompositionPath:t}),Ae=Nsn({activeCompositionPathRef:ee,overlayRef:D,iframeRef:e,boxRef:O,selectionRef:R,hoverSelectionRef:H,overlayRectRef:he,groupOverlayItemsRef:ye,gestureRef:j,groupGestureRef:M,blockedMoveRef:N,waitingPressRef:P,rafPausedRef:L,suppressNextBoxClickRef:F,setOverlayRect:ge,setGroupOverlayItems:be,onBlockedMoveRef:le,onManualDragStartRef:ue,onPathOffsetCommitRef:ie,onGroupPathOffsetCommitRef:ae,onBoxSizeCommitRef:oe,onRotationCommitRef:se,onCanvasPointerMoveRef:de,onCanvasMouseDown:z,snapGuidesRef:I});(0,U.useEffect)(()=>{w&&Ae.clearPointerState(R,!0)},[Ae,w,R]);let je=(0,U.useRef)(e=>{});je.current=e=>Ae.clearPointerState(R,e),ax(()=>{let e=()=>je.current();return window.addEventListener(`blur`,e),()=>{window.removeEventListener(`blur`,e),je.current(!0)}});let{flushNudge:Me}=Wsn({selection:n,groupSelections:r,allowCanvasMovement:a&&!w,selectionRef:R,overlayRectRef:he,groupOverlayItemsRef:ye,gestureRef:j,groupGestureRef:M,blockedMoveRef:N,onBlockedMoveRef:le,onManualDragStartRef:ue,onPathOffsetCommitRef:ie,onGroupPathOffsetCommitRef:ae}),Ne=pan({iframeRef:e,overlayRef:D,activeCompositionPathRef:ee,onMarqueeSelectRef:k,selectionRef:R,gestures:Ae}),Pe=(0,U.useMemo)(()=>n?`${n.sourceFile}:${n.id??n.selector??n.label}:${n.selectorIndex??0}`:`none`,[n]),Fe=(0,U.useMemo)(()=>U4(ve.map(e=>e.rect)),[ve]),Ie=r.length>1,Le=Ie&&ve.length>1&&ve.every(e=>e.selection.capabilities.canApplyManualOffset),Re=e=>{if(!a)return;let t=!!e.target?.closest(`[data-dom-edit-selection-box="true"]`);K4(`mousedown`,{shift:e.shiftKey,onBox:t}),!t&&z(e,{hoverSelection:H.current})},ze=t=>{if(!(!a||T||t.button!==0)){if(t.shiftKey){let n=e.current,r=ean({cached:H.current,elementAtPoint:n?v4(n,t.clientX,t.clientY,ee.current):null});if(!r)return;t.preventDefault(),t.stopPropagation(),F.current=!0,pe.current(r,{additive:!0});return}if(ne.startFromPress(t)){t.preventDefault(),t.stopPropagation();return}if(!t.target?.closest(`[data-dom-edit-selection-box="true"]`)&&!H.current&&k.current&&Se.width>0){let n=e.current;if(n&&v4(n,t.clientX,t.clientY,ee.current))return;if(D.current){t.preventDefault(),t.stopPropagation(),Ne.begin(t);return}}}},Be=e=>{if(a&&!(j.current||M.current)){if(F.current){F.current=!1,e.stopPropagation();return}z(e,{hoverSelection:H.current})}},{contextMenu:Ve,closeContextMenu:He,handleContextMenu:Ue}=van({selection:n,selectionRef:R,hoverSelectionRef:H,onCanvasPointerMoveRef:de,onSelectionChangeRef:pe});return(0,W.jsxs)(`div`,{ref:D,className:`absolute inset-0 z-10 outline-hidden ${ne.editing||T?`pointer-events-none`:`pointer-events-auto`}`,"data-editing-text":ne.editing?`true`:void 0,tabIndex:-1,"aria-label":`Composition canvas`,style:Ne.marqueeRect?{cursor:`crosshair`}:void 0,onPointerDownCapture:e=>{Me(),F.current=!1,ne.editing||Qin(e.currentTarget)},onKeyDown:e=>{ne.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())},onPointerDown:ze,onMouseDown:Re,onPointerMove:Ne.onPointerMove,onPointerLeave:()=>fe.current(),onPointerUp:Ne.onPointerUp,onPointerCancel:Ne.onPointerCancel,onLostPointerCapture:Ae.onLostPointerCapture,onContextMenu:T?void 0:Ue,children:[i&&_e&&Se.width>0&&(0,W.jsx)(`div`,{"aria-hidden":`true`,"data-dom-edit-hover-box":`true`,className:`pointer-events-none absolute rounded-md border border-studio-accent/80 shadow-[0_0_0_1px_rgba(60,230,172,0.25)]`,style:{...j4(_e,i.element),transform:_e.angle?`rotate(${_e.angle}deg)`:void 0}}),Ie&&ve.length>1&&Fe&&Se.width>0&&(0,W.jsx)(hcn,{groupOverlayItems:ve,groupBounds:Fe,allowCanvasMovement:a,allowBodyDrag:E,groupCanMove:Le,gestures:Ae,onBoxClick:Be}),!Ie&&n&&me&&Se.width>0&&(0,W.jsx)(gcn,{inlineText:ne,selection:n,overlayRect:me,allowCanvasMovement:a,allowBodyDrag:E,cropOutlineInsetPx:Te??void 0,boxRef:O,boxChromeClass:De,boxClipPath:Ee,selectionKey:Pe,groupSelectionCount:r.length,gestures:Ae,onStyleCommit:ce.current,onBoxClick:Be}),(0,W.jsx)(Can,{rects:Se.width>0?xe:[]}),ne.toolbar,(0,W.jsx)(San,{rects:T?[]:Oe,elements:ke,compRect:Se,selection:n,groupSelections:r,activeCompositionPathRef:ee,onSelectionChangeRef:pe}),(0,W.jsx)(man,{candidateRects:Ne.candidateRects,marqueeRect:Ne.marqueeRect}),Ve&&(0,W.jsx)(Ccn,{x:Ve.x,y:Ve.y,selection:Ve.sel,onClose:He,onDelete:S&&!w?e=>{He(),S(e)}:void 0,onApplyZIndex:C&&!w?(e,t,n)=>{C(Ve.sel,e,t,n)}:void 0,onZOrderCrossed:V}),(0,W.jsx)(_an,{rect:B}),(0,W.jsx)(Ysn,{snapGuidesRef:I,compositionLeft:Se.left,compositionTop:Se.top,compositionWidth:Se.width,compositionHeight:Se.height})]})}),Zln=`2147483000`,y6=`data-hf-studio-reveal-pending-commit`,Qln=0,b6=new WeakMap,$ln=16;function eun(e){b6.set(e,(b6.get(e)??0)+1);let t=!1;return()=>{if(t)return;t=!0;let n=(b6.get(e)??1)-1;n>0?b6.set(e,n):b6.delete(e)}}function x6(e,t,n){n?e.style.setProperty(t,n):e.style.removeProperty(t)}function S6(e){let t=e.getAttribute(y6);if(!t)return null;try{let e=JSON.parse(t);if(typeof e!=`object`||!e||!(`token`in e))return null;let n=e.token;if(typeof n!=`string`)return null;if(!(`releasedPriors`in e)||e.releasedPriors===void 0)return{token:n};let r=e.releasedPriors;if(typeof r!=`object`||!r||!(`zIndex`in r)||!(`position`in r))return null;let{zIndex:i,position:a}=r;return typeof i==`string`&&typeof a==`string`?{token:n,releasedPriors:{zIndex:i,position:a}}:null}catch{return null}}function tun(e,t){e.setAttribute(y6,JSON.stringify(t))}function nun(e){let t=e.getAttribute(ue);if(t==null)return null;let n={token:`reveal-z-${Qln++}`,priorZ:t,priorPosition:e.getAttribute(ie),activeLiftStyles:{zIndex:e.style.zIndex,position:e.style.position}};return tun(e,{token:n.token}),e.removeAttribute(ue),e.removeAttribute(ie),n}function run(e,t){S6(e)?.token===t.token&&e.removeAttribute(y6)}function iun(e,t){let n=S6(e);if(n?.token===t.token){if(e.removeAttribute(y6),e.removeAttribute(ue),e.removeAttribute(ie),n.releasedPriors){x6(e,`z-index`,n.releasedPriors.zIndex),x6(e,`position`,n.releasedPriors.position);return}x6(e,`z-index`,t.activeLiftStyles.zIndex),x6(e,`position`,t.activeLiftStyles.position),e.setAttribute(ue,t.priorZ),t.priorPosition!=null&&e.setAttribute(ie,t.priorPosition)}}function C6(e,t,n,r){n!=null&&e.style.getPropertyValue(t)===n&&x6(e,t,r)}function aun(e,t){let n=t.getComputedStyle(e),r=Number.parseFloat(n.opacity);return{display:n.display===`none`,visibility:n.visibility===`hidden`||n.visibility===`collapse`,opacity:Number.isFinite(r)&&r<=.01}}function oun(e,t,n){let r={display:e.style.display,visibility:e.style.visibility,opacity:e.style.opacity},i={};return n.display&&(e.style.removeProperty(`display`),t.getComputedStyle(e).display===`none`&&(e.style.display=`block`),i.display=e.style.display),n.visibility&&(e.style.visibility=`visible`,i.visibility=`visible`),n.opacity&&(e.style.opacity=`1`,i.opacity=`1`),{element:e,priors:r,applied:i}}function sun(e){let t=e.ownerDocument,n=t.defaultView;if(!n)return[];let r=[],i=e;for(;i&&i!==t.body&&i!==t.documentElement;){let e;try{e=aun(i,n)}catch{break}(e.display||e.visibility||e.opacity)&&r.push(oun(i,n,e)),i=i.parentElement}return r}function cun(e){let t=e.ownerDocument.defaultView;if(!t)return null;let n={zIndex:e.style.zIndex,position:e.style.position},r=!1;try{e.setAttribute(ue,String(RX(e))),t.getComputedStyle(e).position===`static`&&(e.setAttribute(ie,`static`),e.style.position=`relative`,r=!0)}catch{return e.removeAttribute(ue),null}return e.style.zIndex=Zln,{priors:n,positionLifted:r}}function lun(e,t){if(!e.hasAttribute(`data-hf-reveal-prior-z`)){let n=S6(e);n&&!n.releasedPriors&&tun(e,{...n,releasedPriors:t.priors});return}let n=e.hasAttribute(ie);e.removeAttribute(ue),e.removeAttribute(ie),e.style.zIndex===Zln&&x6(e,`z-index`,t.priors.zIndex),t.positionLifted&&n&&e.style.position===`relative`&&x6(e,`position`,t.priors.position)}function uun({isPlaying:e,selectedElement:t}){let n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)({isPlaying:e,selectedElement:t});i.current={isPlaying:e,selectedElement:t};let a=(0,U.useCallback)(()=>{let e=n.current;if(n.current=null,e){for(let{element:t,priors:n,applied:r}of e.nodes)t.isConnected&&(C6(t,`display`,r.display,n.display),C6(t,`visibility`,r.visibility,n.visibility),C6(t,`opacity`,r.opacity,n.opacity));e.lift&&e.base.isConnected&&lun(e.base,e.lift)}},[]),o=(0,U.useCallback)(e=>{a();let t=sun(e),r=cun(e);(t.length>0||r)&&(n.current={base:e,nodes:t,lift:r})},[a]),s=(0,U.useCallback)(()=>{let e=r.current;r.current=null,e&&window.clearTimeout(e.timer)},[]),c=(0,U.useCallback)((e,t)=>{if(s(),i.current.isPlaying)return;let n=()=>{let t=i.current;if(t.isPlaying||t.selectedElement!==e||!e.isConnected){r.current=null;return}if(b6.has(e)){let t=window.setTimeout(n,$ln);r.current={timer:t,element:e};return}r.current=null,o(e)},a=window.setTimeout(n,t);r.current={timer:a,element:e}},[s,o]);return(0,U.useEffect)(()=>{let i=r.current;(e||i&&i.element!==t)&&s();let o=n.current?.base;(e||o&&t!==o)&&a()},[s,e,a,t]),(0,U.useEffect)(()=>()=>{s(),a()},[s,a]),{scheduleReveal:c}}function dun(e){let t=e.current+1;return e.current=t,()=>e.current===t}function w6(e,t){let n=Symbol(`dom-edit-commit`);e.set(t,n);let r=()=>e.get(t)===n;return Object.assign(r,{release:()=>{r()&&e.delete(t)}})}async function T6(e){try{e.capture(),e.apply();try{await e.persist(),e.onSettled?.(!0)}catch(t){e.shouldRevert(t)&&e.revert(),e.onError(t),e.onSettled?.(!1)}if(!e.shouldResync())return;await e.resync()}finally{e.onFinally?.()}}function E6(e){return{ok:!1,reason:e}}async function fun(e){let t=!1,n;return await T6({...e,persist:async()=>{let t=await e.persist();pun(t)&&(n=t)},onSettled:n=>{t=n,e.onSettled?.(n)}}),t?n?{ok:!0,persistence:n}:{ok:!0}:E6(`persist-failed`)}function pun(e){return typeof e!=`object`||!e?!1:typeof Reflect.get(e,`sourceFile`)==`string`&&typeof Reflect.get(e,`version`)==`string`&&typeof Reflect.get(e,`changed`)==`boolean`}function mun(e,t){let n=[],r={},i=!1;for(let a of t)a.type===`inline-style`?(r[a.property]=a.value,i=!0):a.type===`text-content`?n.push({type:`setText`,target:e,value:a.value??``}):a.type===`attribute`?n.push({type:`setAttribute`,target:e,name:a.property.startsWith(`data-`)?a.property:`data-${a.property}`,value:a.value}):a.type===`html-attribute`&&n.push({type:`setAttribute`,target:e,name:a.property,value:a.value});return i&&n.unshift({type:`setStyle`,target:e,styles:r}),n}var D6={};function hun(e){D6[e]=(D6[e]??0)+1,xun()}function gun(){let e=Object.keys(D6);if(e.length===0)return null;let t={};for(let n of e)t[n]=D6[n],delete D6[n];return t}var _un=3e5,vun=null,yun=null;function bun(){let e=gun();e!==null&&mG(`sdk_resolver_shadow_attempt`,{counts:JSON.stringify(e)})}function xun(){vun||=setInterval(bun,_un),!yun&&typeof document<`u`&&(yun=()=>{document.visibilityState===`hidden`&&(bun(),cLt())},document.addEventListener(`visibilitychange`,yun))}function Sun(e){let t=e.type===`attribute`?e.property.startsWith(`data-`)?e.property:`data-${e.property}`:e.type===`html-attribute`?e.property:null;return t===null||!t.startsWith(`data-hf-`)}var Cun=new Set([`inline-style`,`text-content`,`attribute`,`html-attribute`]);function wun(e){return e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function Tun(e){if(e==null)return null;let t=e.trim();return t===``?null:t}function Eun(e,t){return e.split(`data-hf-id="${t}"`).length-1+(e.split(`data-hf-id='${t}'`).length-1)}function O6(e,t){let n=e.getElements(),r=n.find(e=>e.scopedId===t);if(r)return r;let i=n.filter(e=>e.id===t);return i.find(e=>e.scopedId===e.id)??i[0]??null}function Dun(e,t){return{expected:e.value??null,actual:t.inlineStyles[wun(e.property)]??t.inlineStyles[e.property]??null}}function Oun(e,t){return{expected:Tun(e.value),actual:Tun(t.text)}}function kun(e,t){let n=e.type===`attribute`?e.property.startsWith(`data-`)?e.property:`data-${e.property}`:e.property;return{property:n,expected:e.value??null,actual:t.attributes[n]??null}}function Aun(e,t,n){let r,i,a;if(e.type===`inline-style`)r=e.property,{expected:i,actual:a}=Dun(e,t);else if(e.type===`text-content`)r=`text`,{expected:i,actual:a}=Oun(e,t);else if(e.type===`attribute`||e.type===`html-attribute`)({property:r,expected:i,actual:a}=kun(e,t));else return null;return a===i?null:{kind:`value_mismatch`,hfId:n,property:r,expected:i,actual:a}}function jun(e,t,n,r){if(!O6(e,t))return r!==void 0&&!r.includes(t)?[]:[{kind:`element_not_found`,hfId:t}];let i=n.filter(Sun);if(i.length===0||i.some(e=>!Cun.has(e.type)))return[];let a=[],o=e.on(`patch`,e=>a.push(...e.inversePatches));try{try{let n=mun(t,i);e.batch(()=>{for(let t of n)e.dispatch(t)})}catch(e){return[{kind:`dispatch_error`,hfId:t,error:String(e)}]}let n=O6(e,t);return n?i.map(e=>Aun(e,n,t)).filter(e=>e!==null):[{kind:`element_not_found`,hfId:t}]}finally{o(),a.length>0&&e.applyPatches(a)}}function Mun(e){return e==null?e:`[redacted len=${e.length}]`}function Nun(e){return e.map(e=>({...e,expected:Mun(e.expected),actual:Mun(e.actual)}))}var Pun=new WeakSet;function Fun(e,t){return e.getElements().length===0&&(Pun.has(e)||(Pun.add(e),mG(`sdk_resolver_shadow`,{opLabel:t,sessionEmpty:!0,sessionElementCount:0,mismatchCount:1,mismatches:JSON.stringify([{kind:`session_empty`}])})),!0)}function Iun(e){return e?.targetPath!==void 0&&e.compositionPath!=null&&e.targetPath!==e.compositionPath}function Lun(e,t,n,r,i){if(Ge&&t)try{if(Iun(i)||Fun(e,`dom-edit`))return;hun(`dom-edit`);let a=jun(e,t,n,r);if(a.length===0)return;let o=a.some(e=>e.kind===`element_not_found`)&&r!==void 0?Eun(r,t):void 0;mG(`sdk_resolver_shadow`,{hfId:t,sessionElementCount:e.getElements().length,...o===void 0?{}:{sourceHfIdCount:o},...o===0?{sourceLooseMatchOnly:!0}:{},mismatchCount:a.length,mismatches:JSON.stringify(Nun(a))})}catch{}}async function Run(e,t){if(!t)return{suppress:!1,sourceReadFailed:!1};let n;try{n=await t()}catch{return{suppress:!1,sourceReadFailed:!0}}return n===void 0?{suppress:!1,sourceReadFailed:!1}:n.includes(e)?{suppress:!1,strictCount:Eun(n,e),sourceReadFailed:!1}:{suppress:!0,sourceReadFailed:!1}}async function k6(e,t,n,r,i){if(Ge&&!(!e||!t))try{if(Iun(i)||Fun(e,n)||(hun(n),O6(e,t)))return;let a=e.getElements().length,o=await Run(t,r);if(o.suppress)return;let{strictCount:s,sourceReadFailed:c}=o;mG(`sdk_resolver_shadow`,{hfId:t,opLabel:n,sessionElementCount:a,...s===void 0?{}:{sourceHfIdCount:s},...s===0?{sourceLooseMatchOnly:!0}:{},...c?{sourceReadFailed:!0}:{},mismatchCount:1,mismatches:JSON.stringify([{kind:`element_not_found`,hfId:t}])})}catch{}}async function zun(e,t){let n;try{n=await t}catch{return{staleSession:!1,diskChecked:!1,sourceReadFailed:!0}}if(n===void 0)return{staleSession:!1,diskChecked:!1,sourceReadFailed:!1};let r;try{r=await Qj(n,{history:!1})}catch{return{staleSession:!1,diskChecked:!1,sourceReadFailed:!0}}try{return{staleSession:r.getAllAnimationIds().has(e),diskChecked:!0,sourceReadFailed:!1}}finally{r.dispose()}}async function Bun(e,t,n,r,i){if(Ge&&!(!e||!t))try{if(Iun(i))return;hun(n);let a=e.getElements();if(a.some(e=>e.animationIds.includes(t))||e.getAllAnimationIds().has(t))return;let o=a.length,s=!1,c=!1;if(r){let e=await zun(t,(async()=>r())());if(e.staleSession)return;s=e.diskChecked,c=e.sourceReadFailed}mG(`sdk_resolver_shadow`,{animationId:t,opLabel:n,sessionElementCount:o,...s?{diskChecked:!0}:{},...c?{sourceReadFailed:!0}:{},mismatchCount:1,mismatches:JSON.stringify([{kind:`animation_not_found`,animationId:t}])})}catch{}}var Vun=new Set(`id.class.style.title.name.for.type.lang.dir.translate.hidden.tabindex.draggable.contenteditable.role.slot.href.target.rel.src.srcset.sizes.alt.poster.loading.decoding.crossorigin.preload.autoplay.loop.muted.controls.playsinline.width.height.colspan.rowspan.scope.placeholder.value.min.max.step.pattern.required.disabled.readonly.checked.selected.multiple.accept.maxlength.minlength.rows.cols.wrap`.split(`.`)),Hun=new Set([`src`,`href`,`action`,`formaction`,`poster`,`srcset`,`xlink:href`]),Uun=/^(?:javascript|vbscript):/i,Wun=/^data\s*:\s*text\/html/i;function Gun(e){let t=e.toLowerCase();return!t.startsWith(`on`)&&!!(Vun.has(t)||t.startsWith(`data-`)||t.startsWith(`aria-`))}function Kun(e,t){if(Hun.has(e.toLowerCase())){let e=t.trim();if(Uun.test(e)||Wun.test(e))return!1}return!0}var qun=new Set([`inline-style`,`text-content`,`attribute`,`html-attribute`]),Jun=new Set([`data-hf-id`,`data-composition-id`,`data-width`,`data-height`,`data-start`,`data-end`,`data-track-index`,`data-hold-start`,`data-hold-end`,`data-hold-fill`]);function Yun(e){return e.type===`attribute`?e.property.startsWith(`data-`)?e.property:`data-${e.property}`:e.type===`html-attribute`?e.property:null}function Xun(e){let t=Yun(e);return t!==null&&Jun.has(t.toLowerCase())}function Zun(e){return e.some(e=>e.type===`html-attribute`&&(!Gun(e.property)||e.value!==null&&!Kun(e.property,e.value)))}function Qun(e){return e.some(e=>e.childSelector!==void 0)}function $un(e){return e.some(e=>e.type===`text-content`)}function edn(e){if(!e||typeof e!=`object`||!(`children`in e))return null;let t=e.children;return Array.isArray(t)?t:null}function tdn(e){if(!e||typeof e!=`object`||!(`tag`in e))return null;let t=e.tag;return typeof t==`string`?t.toLowerCase():null}var ndn=new Set([`svg`,`math`]);function rdn(e,t){if(!$un(t))return!1;let n=edn(e);if(!n)return!1;if(n.length>1)return!0;let r=tdn(n[0]);return r!==null&&ndn.has(r)}function A6(e,t){try{return O6(e,t)!==null}catch{return!1}}function idn(e,t){return e?t.length===0?`no_ops`:t.every(e=>qun.has(e.type))?Qun(t)?`child_scoped_op`:t.some(Xun)?`reserved_attribute`:Zun(t)?`unsafe_html_attribute`:null:`unsupported_op_type`:`target_unaddressable`}var adn=2e3,j6=new Map;function odn(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16)}function sdn(e,t){return e.filter(e=>t-e.at<adn)}function cdn(e,t,n=Date.now()){let r=sdn(j6.get(e)??[],n);r.push({hash:odn(t),at:n}),j6.set(e,r)}function ldn(e,t,n=Date.now()){let r=sdn(j6.get(e)??[],n),i=odn(t),a=r.findIndex(e=>e.hash===i);return a===-1?(j6.set(e,r),!1):(r.splice(a,1),j6.set(e,r),!0)}function M6(e,t,n){return mG(`sdk_cutover_declined`,{reason:e,family:t??null,...n?{resolverDisagreement:!0}:{}}),{status:`declined`,reason:e}}function N6(e){return e instanceof Error?e:Error(String(e))}var udn=/Failed to fetch|Load failed|NetworkError when attempting to fetch/;function ddn(e){return e instanceof YY?`network`:e instanceof XY?`conflict`:e instanceof JY?`http`:e.name===`TypeError`&&udn.test(e.message)?`network`:`sdk`}function P6(e,t,n={}){let r=N6(e);return mG(`sdk_cutover_failed`,{...n,family:t,error_kind:ddn(r),...r instanceof JY?{status:r.statusCode}:{},error:r.message}),{status:`failed`,error:r}}function F6(e){if(e.status===`failed`)throw e.error;return e.status===`committed`}async function fdn(e,t,n){return e.readProjectFile?e.readProjectFile(t):n}function pdn(e,t){e&&e!==t&&e.dispose()}function mdn(e,t,n){return n.createCandidateSession?n.createCandidateSession(e,t):Qj(e,{history:!1})}function hdn(e,t,n){return e===t||n.publishSession!==void 0}async function gdn(e,t,n,r){let i;try{let a=r??e.serialize();i=await mdn(a,e,t),i.batch(()=>n(i));let o=i.serialize();return o===a?(pdn(i,e),M6(`no_change`)):hdn(i,e,t)?{live:e,candidate:i,serializedBefore:a,after:o}:(pdn(i,e),{status:`failed`,error:Error(`SDK candidate publisher is unavailable`)})}catch(t){return pdn(i,e),{status:`failed`,error:N6(t)}}}function _dn(e){return`status`in e}async function vdn(e,t,n,r,i){try{return cdn(e,t),await r.writeProjectFile(e,t,n),i}catch(t){return AggregateError([i,N6(t)],`SDK edit failed and rollback could not restore ${e}`)}}async function ydn(e,t,n,r,i){cdn(t,e);try{await r.writeProjectFile(t,e,n)}catch(e){return N6(e)}try{return await r.editHistory.recordEdit({label:i?.label??`Edit layer`,...i?.coalesceKey?{coalesceKey:i.coalesceKey}:{},...i?.coalesceMs==null?{}:{coalesceMs:i.coalesceMs},files:{[t]:{before:n,after:e}}}),null}catch(i){return vdn(t,n,e,r,N6(i))}}function bdn(e,t,n){try{t.refresh?t.refresh(e):n?.skipRefresh||t.reloadPreview()}catch(e){mG(`sdk_cutover_refresh_failed`,{error:N6(e).message})}}async function xdn(e,t,n,r,i){let a=await ydn(e.after,t,n,r,i);if(a)return e.candidate!==e.live&&e.candidate.dispose(),{status:`failed`,error:a};let o=!0;try{if(e.candidate!==e.live){let n=r.publishSession({candidate:e.candidate,expectedSession:e.live,targetPath:t});n!==`published`&&e.candidate.dispose(),n===`rejected-inactive-target`&&(o=!1)}}catch(e){mG(`sdk_cutover_publish_failed`,{path:t,error:N6(e).message})}return o&&bdn(e.after,r,i),{status:`committed`,version:odn(e.after),before:n,after:e.after}}async function I6(e,t,n,r,i,a,o){return jZ(r.writeProjectFile,t,async()=>{let s=o??n,c;try{c=await fdn(r,t,s)}catch(e){return{status:`failed`,error:N6(e)}}let l=await gdn(e,r,i,r.readProjectFile?c:o);return _dn(l)?l:xdn(l,t,c,r,a)})}async function Sdn(e,t,n,r,i){await jZ(r.writeProjectFile,t,async()=>{let a=await fdn(r,t,n),o=await e(a);if(o===a)return;let s=await ydn(o,t,a,r,i);if(s)throw s;bdn(o,r,i)})}function L6(e){let t=Object.prototype.hasOwnProperty.call(_,`STUDIO_SDK_CUTOVER_FAMILIES`)?ht:void 0;return rn(Vt,t,e)}function Cdn(e,t,n){e.status===`committed`?mG(`sdk_cutover_success`,{...n,family:t}):e.status===`failed`&&P6(e.error,t,n)}function R6(e,t){return e.compositionPath!=null&&t!==e.compositionPath}function wdn(e,t){let n=e.readProjectFile;return n?()=>n(t):void 0}async function Tdn(e,t,n,r,i,a,o){if(!L6(`dom`))return M6(`feature_disabled`,`dom`);if(!i)return M6(`session_unavailable`,`dom`);let s=e.hfId,c=idn(s,t);if(c||!s)return M6(c??`target_unaddressable`,`dom`);let l=i.getElement(s);if(!l)return M6(`target_not_found`,`dom`,A6(i,s));if(rdn(l,t))return M6(`unsupported_text_target`,`dom`);if(R6(a,r))return M6(`wrong_composition_file`,`dom`);let u=await I6(i,r,n,a,e=>{for(let n of mun(s,t))e.dispatch(n)},o);return Cdn(u,`dom`,{hfId:s,opCount:t.length}),u}async function Edn(e,t,n,r,i,a){let o=i.readProjectFile;if(k6(r,e,`setTiming`,o?()=>o(t):void 0,{targetPath:t,compositionPath:i.compositionPath}),!L6(`timing`))return M6(`feature_disabled`,`timing`);if(!r)return M6(`session_unavailable`,`timing`);if(!r.getElement(e))return M6(`target_not_found`,`timing`,A6(r,e));if(R6(i,t))return M6(`wrong_composition_file`,`timing`);try{let o=r.serialize(),s=await I6(r,t,o,i,t=>t.setTiming(e,n),a,o);return Cdn(s,`timing`,{hfId:e,opCount:1}),s}catch(t){return P6(t,`timing`,{hfId:e,opCount:1})}}async function Ddn(e,t,n,r,i){let a=r.readProjectFile;for(let i of e)k6(n,i.hfId,`setTiming`,a?()=>a(t):void 0,{targetPath:t,compositionPath:r.compositionPath});if(!L6(`timing`))return M6(`feature_disabled`,`timing`);if(!n)return M6(`session_unavailable`,`timing`);if(R6(r,t))return M6(`wrong_composition_file`,`timing`);let o=e.find(e=>!n.getElement(e.hfId));if(o)return M6(`target_not_found`,`timing`,A6(n,o.hfId));try{let a=n.serialize(),o=await I6(n,t,a,r,t=>{for(let n of e)t.setTiming(n.hfId,n.timingUpdate)},i,a);return o.status===`failed`?P6(o.error,`timing`,{hfId:e[0]?.hfId??null,opCount:e.length}):(mG(`sdk_cutover_success`,{hfId:e[0]?.hfId??null,opCount:e.length,family:`timing`}),o)}catch(t){return P6(t,`timing`,{hfId:e[0]?.hfId??null,opCount:e.length})}}function z6(e,t,n,r,i){if(t.kind===`add`){let i=r.readProjectFile;k6(n,t.target,`addGsapTween`,i?()=>i(e):void 0,{targetPath:e,compositionPath:r.compositionPath})}else Bun(n,t.animationId,t.kind===`set`?`setGsapTween`:`removeGsapTween`,wdn(r,e),{targetPath:e,compositionPath:r.compositionPath});return L6(`gsap-animation`)?t.kind===`add`&&n&&!n.getElement(t.target)?Promise.resolve(M6(`target_not_found`,`gsap-animation`)):B6(`gsap-animation`,e,n,r,i,e=>{e.batch(()=>{t.kind===`add`?e.addGsapTween(t.target,t.spec):t.kind===`set`?e.setGsapTween(t.animationId,t.properties):e.removeGsapTween(t.animationId)})}):Promise.resolve(M6(`feature_disabled`,`gsap-animation`))}async function B6(e,t,n,r,i,a,o){if(o&&Bun(n,o.animationId,o.opLabel,wdn(r,t),{targetPath:t,compositionPath:r.compositionPath}),!L6(e))return M6(`feature_disabled`,e);if(!n)return M6(`session_unavailable`,e);if(R6(r,t))return M6(`wrong_composition_file`,e);let s=n;try{let n=s.serialize(),o=await I6(s,t,n,r,a,i,n);if(o.status===`committed`)mG(`sdk_cutover_success`,{opCount:1,family:e});else if(o.status===`failed`)return P6(o.error,e,{opCount:1});return o}catch(t){return P6(t,e,{opCount:1})}}function Odn(e,t,n,r,i,a,o){return B6(`gsap-keyframe`,e,i,a,o,e=>e.batch(()=>e.dispatch({type:`addGsapKeyframe`,animationId:t,position:n,value:r})),{animationId:t,opLabel:`addGsapKeyframe`})}function kdn(e,t,n,r,i,a){return B6(`gsap-keyframe`,e,r,i,a,e=>e.dispatch({type:`removeGsapKeyframe`,animationId:t,percentage:n}),{animationId:t,opLabel:`removeGsapKeyframe`})}function Adn(e,t,n,r,i,a,o){return B6(`gsap-animation`,e,i,a,o,e=>e.dispatch({type:`removeGsapProperty`,animationId:t,property:n,from:r}),{animationId:t,opLabel:`removeGsapProperty`})}function jdn(e,t,n,r,i){return B6(`gsap-animation`,e,n,r,i,e=>e.dispatch({type:`deleteAllForSelector`,selector:t}))}function Mdn(e,t,n,r,i){return B6(`gsap-keyframe`,e,n,r,i,e=>e.dispatch({type:`removeAllKeyframes`,animationId:t}),{animationId:t,opLabel:`removeAllKeyframes`})}function Ndn(e,t,n,r,i,a){return B6(`gsap-keyframe`,e,r,i,a,e=>e.dispatch({type:`convertToKeyframes`,animationId:t,resolvedFromValues:n}),{animationId:t,opLabel:`convertToKeyframes`})}function Pdn(e,t,n,r,i){return{targetSelector:e,position:t,duration:n,keyframes:r,...i?{ease:i}:{}}}function Fdn(e,t,n){n===void 0?e.dispatch({type:`addWithKeyframes`,...t}):e.dispatch({type:`replaceWithKeyframes`,animationId:n,...t})}function Idn(e){let t=Pdn(e.targetSelector,e.position,e.duration,e.keyframes,e.ease);return B6(`gsap-keyframe`,e.targetPath,e.sdkSession,e.deps,e.options,n=>Fdn(n,t,e.animationId),e.animationId?{animationId:e.animationId,opLabel:`replaceWithKeyframes`}:void 0)}function Ldn(e,t,n,r,i,a,o,s,c){return Idn({targetPath:e,targetSelector:t,position:n,duration:r,keyframes:i,ease:a,sdkSession:o,deps:s,options:c})}function Rdn(e,t,n,r,i,a,o,s,c,l){return Idn({targetPath:e,animationId:t,targetSelector:n,position:r,duration:i,keyframes:a,ease:o,sdkSession:s,deps:c,options:l})}async function zdn(e,t,n,r,i){if(k6(r,e,`removeElement`,()=>Promise.resolve(t),{targetPath:n,compositionPath:i.compositionPath}),!L6(`lifecycle`))return M6(`feature_disabled`,`lifecycle`);if(!r)return M6(`session_unavailable`,`lifecycle`);if(!r.getElement(e))return M6(`target_not_found`,`lifecycle`,A6(r,e));if(R6(i,n))return M6(`wrong_composition_file`,`lifecycle`);let a=await I6(r,n,t,i,t=>t.removeElement(e),{label:`Delete element`});return Cdn(a,`lifecycle`,{hfId:e,opCount:1}),a}var Bdn=0;function Vdn(e,t){let n=e.map(e=>e.id??e.selector??e.element.getAttribute(`data-hf-id`)??`el`).join(`:`);return`z-reorder:${t??`reorder`}:${n}:g${Bdn++}`}function Hdn({activeCompPath:e,showToast:t,writeProjectFile:n,editHistory:r,projectIdRef:i,reloadPreview:a,clearDomSelection:o,onTrySdkDelete:s,onReorderShadow:c,forceReloadSdkSession:l,commitDomEditPatchBatches:u,onElementDeleted:d}){return{handleDomEditElementsDelete:(0,U.useCallback)(async c=>{let u=i.current;if(!u)return E6(`no-project`);let[f]=c;if(!f)return E6(`no-selection`);let p=c.length===1?f.label||f.id||f.selector||f.tagName:`${c.length} elements`;c.length>1&&t(`Deleting ${p}...`,`info`);let m=f.sourceFile||e||`index.html`,h=c.filter(t=>(t.sourceFile||e||`index.html`)===m);try{let e=h.map(e=>Wt(e));if(e.some(e=>!e.id&&!e.selector&&!e.hfId))throw Error(`Selected element has no patchable target`);let i=h.map(e=>e.hfId).filter(e=>!!e);if(s&&i.length===h.length){let e=await NZ(u,m),n=!0;for(let t of i)if(!F6(await s(t,e,m))){n=!1;break}if(n)return o(),X.getState().setSelectedElementId(null),t(`Deleted ${p}. Use Undo to restore ${h.length===1?`it`:`them`}.`,`info`),{ok:!0}}if(!await FZ({projectId:u,path:m,label:`Delete element`,writeFile:n,recordEdit:r.recordEdit,rewrite:async t=>{let n=await H(M(u,`/file-mutations/remove-elements/${encodeURIComponent(m)}`),{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:JSON.stringify({targets:e})});if(!n.ok)throw await iX(n,`Failed to delete element from ${m}`);let r=await n.json();return r.changed?{disk:typeof r.content==`string`?r.content:t}:null}}))return a(),t(`Nothing to delete, the preview was out of date. Try again.`),E6(`preview-stale`);o(),X.getState().setSelectedElementId(null),l?.(),a();for(let e of h)d?.(e);return t(`Deleted ${p}. Use Undo to restore ${h.length===1?`it`:`them`}.`,`info`),{ok:!0}}catch(e){return t(e instanceof Error?e.message:`Failed to delete element`),E6(`persist-failed`)}},[e,o,r.recordEdit,s,d,l,i,a,t,n]),handleDomZIndexReorderCommit:(0,U.useCallback)((e,t,n)=>e.length===0?Promise.resolve():(async()=>{let r=e.map(e=>eun(e.element));try{c?.(e.map(e=>se(e.element)).filter(e=>e!=null));let r=t??Vdn(e,n),i=new Map,a=[],o=[];for(let t of e){let e=t.element.style.zIndex,n=t.element.style.position,r=t.key?X.getState().elements.find(e=>(e.key??e.id)===t.key):void 0,s=!1,c=t.element.getAttribute(ie),l=nun(t.element);l&&o.push({element:t.element,ownership:l}),t.element.style.zIndex=String(t.zIndex);let u=[{type:`inline-style`,property:`z-index`,value:String(t.zIndex)}];try{let e=t.element.ownerDocument?.defaultView;(c??(e?e.getComputedStyle(t.element).position:void 0))===`static`&&(t.element.style.position=`relative`,s=!0,u.push({type:`inline-style`,property:`position`,value:`relative`}))}catch{}t.key&&X.getState().updateElement(t.key,{zIndex:t.zIndex,hasExplicitZIndex:!0}),a.push(()=>{l?iun(t.element,l):(t.element.style.zIndex=e,s&&(t.element.style.position=n)),t.key&&r&&X.getState().updateElement(t.key,{zIndex:r.zIndex,hasExplicitZIndex:r.hasExplicitZIndex})});let d=i.get(t.sourceFile)??[];d.push({target:Wt({id:t.id,hfId:se(t.element),selector:t.selector,selectorIndex:t.selectorIndex}),operations:u}),i.set(t.sourceFile,d)}let s=[...i].map(([e,t])=>({sourceFile:e,patches:t}));X.getState().bumpZEditVersion();let l=()=>{for(let e of a)e();X.getState().bumpZEditVersion()};try{let e=await u(s,{label:`Reorder layers`,coalesceKey:r,coalesceMs:1/0,skipReload:!0});if(!e.durable)return l(),e;for(let{element:e,ownership:t}of o)run(e,t);return e}catch(e){throw l(),e}}finally{for(let e of r)e()}})(),[u,c])}}var V6=e=>e.key??e.id;function Udn(e,t){if(e.expandedHostKey==null)return null;let n=V6(e);return new Set(t.filter(t=>V6(t)!==n&&PY(t,e)).map(e=>e.track))}function Wdn(e){let{action:t,element:n,elements:r}=e;if(MY(n)===`audio`||!(n.duration>0))return null;let i=V6(n),a=n.start,o=n.start+n.duration,s=t===`bring-forward`||t===`bring-to-front`,c=r.filter(e=>V6(e)!==i&&MY(e)===`visual`&&LY(e,n)&&hq(a,o,e.start,e.start+e.duration)),l=Ydn(e,c,s);if(l==null)return null;let u=v$(r),d=v$(r.filter(e=>MY(e)===`visual`)),f=d.indexOf(l);if(f===-1)return null;let p=Kdn(t,c,l,s),m=Udn(n,r),h=qdn({elements:r,visualLanes:d,refIdx:f,up:s,boundLane:p,start:a,end:o,selfKey:i,allowedLanes:m});return h==null?m?null:{kind:`insert`,insertRow:u.indexOf(l)+ +!s}:h===n.track?null:{kind:`move`,displayTrack:h,persistTrack:FY(h,r,n)}}function Gdn(e){let{element:t,elements:n,desiredOrderKeys:r}=e;if(MY(t)===`audio`||!(t.duration>0))return null;let i=V6(t),a=r.indexOf(i);if(a===-1)return null;let o=e=>{if(e==null)return null;let r=n.find(t=>V6(t)===e);return r&&MY(r)===`visual`&&r.duration>0&&LY(r,t)&&V6(r)!==i?r.track:null},s=null;for(let e=a+1;e<r.length&&s==null;e++)s=o(r[e]);let c=null;for(let e=a-1;e>=0&&c==null;e--)c=o(r[e]);if(s==null&&c==null)return null;let l=v$(n),u=v$(n.filter(e=>MY(e)===`visual`)),d=Udn(t,n),f={elements:n,visualLanes:u,start:t.start,end:t.start+t.duration,selfKey:i,allowedLanes:d},p,m;if(s!=null){let e=u.indexOf(s);if(e===-1)return null;p=qdn({...f,refIdx:e,up:!1,boundLane:c}),m=l.indexOf(s)+1}else{let e=u.indexOf(c);if(e===-1)return null;p=qdn({...f,refIdx:e,up:!0,boundLane:null}),m=l.indexOf(c)}return p==null?d?null:{kind:`insert`,insertRow:m}:p===t.track?null:{kind:`move`,displayTrack:p,persistTrack:FY(p,n,t)}}function Kdn(e,t,n,r){if(e!==`bring-forward`&&e!==`send-backward`)return null;let i=t.map(e=>e.track).filter(e=>r?e<n:e>n);return i.length===0?null:(r?Math.max:Math.min)(...i)}function qdn(e){let{elements:t,visualLanes:n,refIdx:r,up:i,boundLane:a,start:o,end:s,selfKey:c,allowedLanes:l}=e,u=i?-1:1;for(let e=r+u;e>=0&&e<n.length;e+=u){let r=n[e];if(Jdn(r,a,i))break;if(!(l&&!l.has(r))&&BBt(t,r,o,s,c))return r}return null}function Jdn(e,t,n){return t==null?!1:n?e<=t:e>=t}function Ydn(e,t,n){let r=e.action===`bring-forward`||e.action===`send-backward`;if(r){let t=Xdn(e);if(t!=null)return t}let i=t.map(e=>e.track).filter(t=>n?t<e.element.track:t>e.element.track);return i.length===0?null:(r===n?Math.max:Math.min)(...i)}function Xdn({elements:e,crossedKey:t}){if(t==null)return null;let n=e.find(e=>V6(e)===t);return n&&MY(n)===`visual`?n.track:null}function Zdn(){let e=$dn(),t=IX()?.activeCompPath??null;return(0,U.useCallback)(n=>e(n.selectionKey,n.coalesceKey,(e,r)=>{let i=n.crossed?ge(n.crossed):void 0,a=n.crossed?k({domId:n.crossed.id||void 0,selector:i,selectorIndex:ze(n.crossed.ownerDocument,n.crossed,i,n.sourceFile,t),sourceFile:n.sourceFile}):null;return Wdn({action:n.action,element:e,elements:r,crossedKey:a})}),[e,t])}function Qdn(){let e=$dn();return(0,U.useCallback)(t=>e(t.selectionKey,t.coalesceKey,(e,n)=>Gdn({element:e,elements:n,desiredOrderKeys:t.desiredOrderKeys})),[e])}function $dn(){let e=X(e=>e.elements),t=(0,U.useRef)(e);t.current=e;let{onMoveElements:n}=VX();return(0,U.useCallback)((e,r,i)=>{let a=t.current,o=e?a.find(t=>(t.key??t.id)===e):void 0;if(!o||!n)return Promise.resolve(!1);let s=i(o,a);return s?iqt(o,s,{elements:a,trackOrder:v$(a),updateElement:(e,t)=>X.getState().updateElement(e,t),onMoveElements:n},r):Promise.resolve(!1)},[n])}function efn(e,t,n){return!!(t||n||se(e))}function tfn(e,t){return{element:e.element,zIndex:t,id:e.id??void 0,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile,key:k({domId:e.id??void 0,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile})}}function nfn(e,t,n,r){let i=e.id||void 0,a=ge(e);if(!efn(e,i,a))return null;let o=i?void 0:ze(e.ownerDocument,e,a,n,r);return{element:e,zIndex:t,id:i,selector:a,selectorIndex:o,sourceFile:n,key:k({domId:i,selector:a,selectorIndex:o,sourceFile:n})}}function rfn(e){if(e.id)return`#${e.id}`;let t=e.classList.item(0);return t?`${e.tagName.toLowerCase()}.${t}`:e.tagName.toLowerCase()}function ifn(e,t,n){let r=[],i=[];for(let a of t){if(a.element===e.element){r.push(tfn(e,a.zIndex));continue}let t=nfn(a.element,a.zIndex,e.sourceFile,n);t?r.push(t):i.push(a)}return{entries:r,dropped:i}}var afn=e=>e.isConnected&&e.ownerDocument.defaultView!==null;function ofn(){let{handleDomZIndexReorderCommit:e}=kX(),t=Zdn(),n=V2(),r=IX()?.activeCompPath??null,i=(0,U.useCallback)((e,t)=>!n&&afn(e.element)&&PJt(e.element,t),[n]),a=(0,U.useCallback)((i,a,o,s)=>{if(n)return!1;let{entries:c,dropped:l}=ifn(i,a,r);if(l.length>0){for(let e of l)e.element.style.zIndex=String(e.zIndex);console.warn(`[studio] z-index reorder: dropping sibling(s) with no stable id/selector (will revert on reload):`,l.map(e=>rfn(e.element)).join(`, `))}if(c.length===0)return!1;let u=Vdn(c,o),d=!1;return _Kt({commitZ:async()=>{let t=await e(c,u,o);return d=t?.durable===!0&&t.changed,t},mirror:()=>t({selectionKey:c.find(e=>e.element===i.element)?.key,action:o,crossed:s,sourceFile:i.sourceFile,coalesceKey:u})}).then(()=>{d&&m4(`z_order`,`button`)}).catch(()=>void 0),!0},[r,e,t,n]),o=(0,U.useCallback)((e,t)=>{if(!afn(e.element))return!1;let n=FJt(e.element,t);return n!==null&&a(e,n.patches,t,n.crossed)},[a]);return(0,U.useMemo)(()=>({enabled:i,apply:o,commit:a}),[i,o,a])}function sfn({activeCompositionPath:e,showHoverSelection:t,shouldShowSelectedDomBounds:n,isGestureRecording:r,canvasInput:i,allowBodyDrag:a,onTextEditingChange:o,onSelectionBoxClick:s}){let{domEditHoverSelection:c,domEditSelection:l,domEditGroupSelections:u}=jX(),{previewIframeRef:d,handlePreviewCanvasMouseDown:f,handlePreviewCanvasPointerMove:p,handlePreviewCanvasPointerLeave:m,applyDomSelection:h,handleBlockedDomMove:g,handleDomManualDragStart:_,handleDomPathOffsetCommit:v,handleDomGroupPathOffsetCommit:y,handleDomBoxSizeCommit:b,handleDomRotationCommit:x,handleDomStyleCommit:S,applyMarqueeSelection:C,handleDomEditElementDelete:w}=kX(),T=ofn();return(0,W.jsx)(Xln,{iframeRef:d,activeCompositionPath:e,hoverSelection:t?c:null,selection:n?l:null,groupSelections:n?u:[],allowCanvasMovement:!r,canvasInput:i,allowBodyDrag:a,onTextEditingChange:o,onSelectionBoxClick:s,onCanvasMouseDown:f,onCanvasPointerMove:p,onCanvasPointerLeave:m,onSelectionChange:h,onBlockedMove:g,onManualDragStart:_,onPathOffsetCommit:v,onGroupPathOffsetCommit:y,onBoxSizeCommit:b,onRotationCommit:x,onStyleCommit:S,onDeleteSelection:w,onApplyZIndex:T.commit,onMarqueeSelect:C})}var H6=`:`,cfn=`#`;function U6(e){let t=t=>!e.sourceFile||!e.activeCompositionPath?t:e.projectId?[`v2`,encodeURIComponent(e.projectId),encodeURIComponent(e.activeCompositionPath),encodeURIComponent(e.sourceFile),encodeURIComponent(t)].join(H6):[`v1`,encodeURIComponent(e.activeCompositionPath),encodeURIComponent(e.sourceFile),encodeURIComponent(t)].join(H6);if(e.hfId)return`hf${H6}${t(e.hfId)}`;if(e.domId)return`dom${H6}${t(e.domId)}`;if(e.selector){let n=e.selectorIndex??0;return`sel${H6}${t(e.selector)}${cfn}${n}`}return null}function lfn(e,t=`index.html`,n){let r=t??`index.html`;return{projectId:n,hfId:e.hfId,domId:e.domId,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile??r,activeCompositionPath:r}}function W6(e,t,n){return{projectId:n,hfId:e.hfId,domId:e.id,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile,activeCompositionPath:t}}function ufn(e,t,n){let r=e.split(H6);return r[0]!==t||r.length!==n+1?null:r.slice(1).map(pfn)}function dfn(e){let[t,n,r]=ufn(e,`v1`,3)??[];return!t||!n||!r?null:{version:1,value:r,sourceFile:n,activeCompositionPath:t}}function ffn(e){let[t,n,r,i]=ufn(e,`v2`,4)??[];return!t||!n||!r||!i?null:{version:2,projectId:t,value:i,sourceFile:r,activeCompositionPath:n}}function G6(e){return e.startsWith(`v1${H6}`)?dfn(e):e.startsWith(`v2${H6}`)?ffn(e):{value:e,version:0}}function pfn(e){try{return decodeURIComponent(e)||null}catch{return null}}function mfn(e){let t=e.indexOf(H6);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);if(!r)return null;if(n===`hf`||n===`dom`){let e=G6(r);return e?{scheme:n,...e,index:0}:null}if(n!==`sel`)return null;let i=r.lastIndexOf(cfn);if(i<=0){let e=G6(r);return e?{scheme:n,...e,index:0}:null}let a=Number(r.slice(i+1));if(!Number.isInteger(a)||a<0){let e=G6(r);return e?{scheme:n,...e,index:0}:null}let o=G6(r.slice(0,i));return o?{scheme:n,...o,index:a}:null}function hfn(e,t){let n=mfn(t);return n?He(e,{hfId:n.scheme===`hf`?n.value:void 0,id:n.scheme===`dom`?n.value:void 0,selector:n.scheme===`sel`?n.value:void 0,selectorIndex:n.scheme===`sel`?n.index:void 0,sourceFile:n.sourceFile},n.activeCompositionPath??null):null}function gfn(e,t){let n=mfn(e);return n?n.version!==2||!!t&&n.projectId===t:!1}async function _fn(e,t,n){let r=!1;for(let i=0;i<2;i+=1){let i=e();if(!i)return{status:`preview-unavailable`};let a=hfn(i,t);if(!a)return{status:r?`changed`:`not-found`};let o=await n(a);if(e()!==i||a.ownerDocument!==i||!a.isConnected||o!==null&&(o.element.ownerDocument!==i||!o.element.isConnected)){r=!0;continue}return o?{status:`ready`,selection:o}:{status:`unsupported`}}return{status:`changed`}}function K6(e){return{ok:!0,...e}}function q6(e,t,n){return n?{ok:!1,kind:e,reason:t,hint:n}:{ok:!1,kind:e,reason:t}}async function J6(e,t){try{return await t()}catch(t){let n=t instanceof Error?t.message:String(t);return t instanceof TypeError||t instanceof ReferenceError?(console.error(`[hf-webmcp] ${e} threw`,t),q6(`internal`,n)):q6(`failed`,n)}}var Y6="Read `stage` as the proof level: refused, dispatched, saved, verified, or failed. `changed` is separate, and evidence explains what was actually proven.",X6=new class{state={phase:`idle`};listeners=new Set;lastTerminalTarget=null;activeProjectId=null;callSequence=0;getSnapshot=()=>this.state;subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e));begin(e,t,n){this.activateProject(e);let r=`studio-edit-${++this.callSequence}`,i=this.lastTerminalTarget,a=i===null||i.projectId!==e||i.handle!==t.handle;return this.publish({callId:r,projectId:e,target:t,operation:n,targetChanged:a,phase:`dispatching`}),r}finish(e,t){this.state.phase!==`idle`&&this.state.callId===e&&(this.lastTerminalTarget={projectId:this.state.projectId,handle:this.state.target.handle},this.publish({...this.state,phase:t.ok?t.stage:`failed`,receipt:t}))}dismiss(e){this.state.phase!==`idle`&&this.state.callId===e&&this.publish({phase:`idle`})}reset(){this.activeProjectId=null,this.lastTerminalTarget=null,this.publish({phase:`idle`})}activateProject(e){this.activeProjectId!==e&&(this.activeProjectId=e,this.lastTerminalTarget=null,this.publish({phase:`idle`}))}publish(e){this.state=e;for(let e of this.listeners)e()}};async function vfn(e,t){let n=await _fn(e.getPreviewDocument,t,e.buildSelection);return n.status===`preview-unavailable`?{ok:!1,failure:q6(`blocked`,`the composition preview is not ready`)}:n.status===`not-found`?{ok:!1,failure:q6(`invalid`,`the target handle is stale`,`Call studio_look and retry.`)}:n.status===`unsupported`?{ok:!1,failure:q6(`blocked`,`the target resolved to an element Studio cannot edit`,`Try a parent or child element from studio_look.`)}:n.status===`changed`?{ok:!1,failure:q6(`invalid`,`the target changed while it was resolving`,`Call studio_look again.`)}:{ok:!0,selection:n.selection}}function Z6(e,t,n=!1){return{...t,stage:`refused`,operation:e,...n?{cancelRequested:!0}:{}}}function yfn(e,t,n,r){let i=r?{cancelRequested:!0}:{};return e.ok?{...e,target:t,operation:n,...i}:{...wfn(e),stage:`failed`,target:t,operation:n,...i}}function bfn(e){return{kind:e instanceof TypeError||e instanceof ReferenceError?`internal`:`failed`,reason:e instanceof Error?e.message:String(e)}}function xfn(e,t,n){let r=mfn(e);return!r||r.version!==2||!r.projectId?Z6(n,q6(`invalid`,`writes require a current project-scoped handle from studio_look`,`Call studio_look again and pass the returned handle unchanged.`)):r.projectId===t?null:Z6(n,q6(`invalid`,`the handle belongs to a different project`,`Call studio_look in the active project.`))}function Sfn(e,t){if(t.signal.aborted)return{ok:!1,result:Z6(t.operation,q6(`blocked`,`the write was cancelled before dispatch`),!0)};if(typeof t.handle!=`string`||!t.handle)return{ok:!1,result:Z6(t.operation,q6(`invalid`,`handle must name an element from studio_look`))};let n=e.getProjectId();if(!n)return{ok:!1,result:Z6(t.operation,q6(`blocked`,`there is no active project`))};let r=xfn(t.handle,n,t.operation);if(r)return{ok:!1,result:r};let i=e.getWriteBlockedReason();return i?{ok:!1,result:Z6(t.operation,q6(`blocked`,i,`Resolve it in Studio, then retry.`))}:{ok:!0,handle:t.handle,projectId:n}}async function Cfn(e,t,n){let r=await vfn(e,n);if(!r.ok)return{ok:!1,result:Z6(t.operation,r.failure)};let{selection:i}=r;if(i.isInsideLockedComposition)return{ok:!1,result:Z6(t.operation,q6(`blocked`,`the target is inside a locked composition`))};let a=await t.preflight?.(i);return a?{ok:!1,result:Z6(t.operation,a)}:t.signal.aborted?{ok:!1,result:Z6(t.operation,q6(`blocked`,`the write was cancelled before dispatch`),!0)}:{ok:!0,selection:i}}async function Q6(e,t){let n=Sfn(e,t);if(!n.ok)return n.result;let r;try{r=await Cfn(e,t,n.handle)}catch(e){let{kind:n,reason:r}=bfn(e);return n===`internal`&&console.error(`[hf-webmcp] ${t.operation} preflight threw`,e),Z6(t.operation,q6(n,r))}if(!r.ok)return r.result;if(e.getProjectId()!==n.projectId)return Z6(t.operation,q6(`blocked`,`the active project changed while the target was resolving`,`Call studio_look in the active project and retry.`));let{selection:i}=r,a={handle:n.handle,sourceFile:i.sourceFile};e.applySelection(i);let o=X6.begin(n.projectId,a,t.operation),s;try{s=await t.write(i)}catch(e){let{kind:n,reason:r}=bfn(e);n===`internal`&&console.error(`[hf-webmcp] ${t.operation} threw`,e);let i={ok:!1,kind:n,reason:r,stage:`failed`,target:a,operation:t.operation,...t.signal.aborted?{cancelRequested:!0}:{}};return X6.finish(o,i),i}let c=yfn(s,a,t.operation,t.signal.aborted);return X6.finish(o,c),c}function wfn(e){let t=e.kind===`invalid`||e.kind===`blocked`?`failed`:e.kind;return{...e,kind:t}}function $6(e,t){return{ok:!0,...e,stage:`dispatched`,changed:t,evidence:{kind:`dispatch`,followUp:`studio_inspect`}}}function Tfn(e,t){return{ok:!0,...e,stage:`saved`,changed:t.changed,evidence:{kind:`content-version`,sourceFile:t.sourceFile,version:t.version}}}function Efn(e,t,n){return{ok:!0,...e,stage:`verified`,changed:t.changed,evidence:{kind:`readback`,sourceFile:t.sourceFile,version:t.version,...n}}}function Dfn(e){return e.replace(/^https?:\/\/[^/]+/,``).replace(/^\/api\/projects\/[^/]+\/preview\//,``)}function Ofn(e){return{id:e.domId??e.id,label:e.label??null,kind:e.kind??e.tag.toLowerCase(),start:e.start,duration:e.duration,end:e.start+e.duration,trackIndex:e.authoredTrack??e.track,src:e.src?Dfn(e.src):null,sourceFile:e.sourceFile??null,volume:e.volume??null,lanes:EY(e).map(e=>({target:e.target,points:e.points.map(({t:e,v:t})=>({t:e,v:t}))})),playbackRate:e.playbackRate===1?null:e.playbackRate??null,audioGroup:e.audioGroup??null,role:e.timelineRole??null}}function kfn(e){return e.map(Ofn).sort(jje)}var Afn=200;function jfn(e){let t=kfn(e);if(t.length===0)return``;let n=t.slice(0,Afn).map(Ije),r=t.length-n.length;return[`Timeline (composition seconds; lane points are seconds from the clip start):`,...n,...r>0?[`(${r} more clips not listed)`]:[]].join(`
333
333
  `)}var e8=200,Mfn=128;function Nfn(e){return{start:e.start,duration:e.duration,track:e.track,zIndex:e.zIndex??null,kind:e.kind??null}}function Pfn(e,t,n,r){let{capabilities:i}=e;return{handle:U6(W6(e,n,r)),label:e.label,tagName:e.tagName,sourceFile:e.sourceFile,box:e.boundingBox,text:e.textContent,can:{editStyles:i.canEditStyles,move:i.canMove||i.canApplyManualOffset,resize:i.canResize||i.canApplyManualSize,editText:e.textFields.length>0,reasonIfDisabled:i.reasonIfDisabled??null},animationCount:t}}function Ffn(e,t){return[e.id,e.label,e.kind,e.src].some(e=>e?.toLowerCase().includes(t))}function Ifn(e){let t=e.compositionPath??`index.html`;return e.elements.map(n=>({...Ofn(n),handle:U6(lfn(n,t,e.projectId))}))}function Lfn(e,t){return e.label.toLowerCase().includes(t)||e.tag.toLowerCase().includes(t)||e.handle.toLowerCase().includes(t)}function Rfn(e,t,n){if(!e)return{status:`loading`};let r=e.querySelector(`[data-composition-id]`);if(!r)return{status:`loading`};let i=ot(r,{activeCompositionPath:t,isMasterView:!t||t===`index.html`,activeGroupElement:null}),a=n?.isConnected&&n.ownerDocument===e?n:null;return{status:`ready`,items:i,drillInItem:a?i.find(e=>e.element===a)??null:null}}function zfn(e){if(e.scene.status===`loading`)return{elements:[],drillIn:null};let t=e.compositionPath??`index.html`,n=new Map;for(let r of e.elements){let i=U6(lfn(r,t,e.projectId));i&&n.set(i,Nfn(r))}let r=[],i=e.scene.items.map(i=>{let a=U6(W6(i,t,e.projectId));if(!a)throw Error(`collectDomEditLayerItems returned an unaddressable layer`);let o=i.depth>0?r[i.depth-1]??null:null;return r[i.depth]=a,r.length=i.depth+1,{handle:a,parentHandle:o,label:i.label,tag:i.tagName,depth:i.depth,childCount:i.childCount,sourceFile:i.sourceFile,timeline:n.get(a)??null}}),a=e.scene.drillInItem,o=a?U6(W6(a,t,e.projectId)):null;return{elements:i,drillIn:a&&o?{handle:o,label:a.label,sourceFile:a.sourceFile}:null}}function Bfn(e,t={}){let n=zfn(e),r=t.filter?.slice(0,Mfn).trim().toLowerCase(),i=r?n.elements.filter(e=>Lfn(e,r)):n.elements,a=Number.isInteger(t.limit)&&t.limit>0?t.limit:e8,o=Math.min(a,e8),s=Ifn(e).sort(jje),c=r?s.filter(e=>Ffn(e,r)):s;return K6({projectId:e.projectId,compositionPath:e.compositionPath,playhead:e.currentTime,duration:e.duration,isPlaying:e.isPlaying,history:e.history,selection:e.selection?Pfn(e.selection,e.selectionAnimationCount,e.compositionPath??`index.html`,e.projectId):null,sceneStatus:e.scene.status,drillIn:n.drillIn,elementCount:i.length,truncated:i.length>o,elements:i.slice(0,o),clipCount:c.length,clipsTruncated:c.length>o,clips:c.slice(0,o)})}var Vfn={type:`object`,properties:{filter:{type:`string`,maxLength:Mfn,description:`Case-insensitive substring matched against element label, tag, and handle.`},limit:{type:`integer`,minimum:1,maximum:e8,description:`Cap the returned elements and clips (default and max ${e8} each). elementCount and clipCount always report the full match count.`}},additionalProperties:!1},Hfn=[`Read HyperFrames Studio's live state in one call: the open project and composition,`,`the playhead and duration, what the human currently has selected (including what that`,`element will and will not accept), and the live nested scene in DOM preorder.`,`Each scene element includes source ownership, hierarchy, and optional timeline timing.`,"`clips` lists every timeline clip, audio included: kind, start, duration, track, volume,",`volume/effect automation points, playback rate, audio group and role.`,`Pass a handle back to any tool that edits an element.`,"Returns an object with `ok: true`, or `ok: false` with `kind`, `reason` and often a `hint`.","`history.undoLabel` is worth checkpointing before a batch: if it later names something",`you did not do, a human pressed undo and your earlier edits are gone.`].join(` `);function Ufn(e,t){let n=e[t],r=t,i=n.depth-1;for(let a=t-1;a>=0&&i>=0;a--){let t=e[a];if(t.depth===i){if(t.sourceFile!==n.sourceFile)break;r=a,--i}}return r}function Wfn(e,t,n){let r=e[t],i=[];for(let a=t+1;a<e.length;a++){let t=e[a];if(t.depth<=r.depth)break;t.sourceFile===n.sourceFile&&t.element!==n.element&&i.push(t.element)}return i}function Gfn(e,t,n){let r=hfn(e,n);if(!r)return null;let i=Rfn(e,t,null);if(i.status===`loading`)return null;let a=i.items.findIndex(e=>e.element===r);if(a<0)return{context:r,target:r,contours:[]};let o=i.items[a],s=Ufn(i.items,a),c=i.items[s];return{context:r.closest(`[data-composition-file], [data-composition-src]`)??c.element,target:r,contours:Wfn(i.items,s,o)}}function Kfn(e){return!!(e&&e.width>0&&e.height>0)}function qfn(e){let t=e.iframe.contentDocument;if(!t)return null;let n=Gfn(t,e.activeCompositionPath,e.handle);if(!n)return null;let r=n.context===n.target,i=Iin(e.overlay,e.iframe,r?[n.target,...n.contours]:[n.context,n.target,...n.contours]),a=i[+!r];if(!Kfn(a))return null;let o=i[0],s=!r&&Kfn(o),c=r?1:2;return{field:{label:(s?n.context:n.target).tagName.toLowerCase(),rect:s?o:a},target:{label:n.target.tagName.toLowerCase(),rect:a},contours:i.slice(c).map((e,t)=>({label:n.contours[t].tagName.toLowerCase(),rect:e})).filter(e=>Kfn(e.rect))}}function Jfn(e){return{callId:e.callId,projectId:e.projectId,target:e.target,operation:e.operation}}function Yfn(e,t){if(t.type===`lifecycle`){let e=t.value;if(e.phase===`idle`)return{phase:`hidden`};let n=Jfn(e);switch(e.phase){case`dispatching`:return e.targetChanged?{...n,phase:`acquiring`}:{...n,phase:`localizing`,terminal:null};case`dispatched`:case`failed`:return{...n,phase:`localizing`,terminal:e.phase};case`saved`:case`verified`:return e.receipt?.ok&&e.receipt.changed===!1?{...n,phase:`localizing`,terminal:`no-change`}:{...n,phase:`sealing`,receiptStage:e.phase}}}return e.phase===`hidden`||e.callId!==t.callId?e:e.phase===`acquiring`?{...e,phase:`localizing`,terminal:null}:e}var Xfn=240,Zfn=180,Qfn=240;function t8(e){return{left:e.left,top:e.top,width:e.width,height:e.height}}function $fn(){return window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1}function epn(e){let t=window.matchMedia?.(`(prefers-reduced-motion: reduce)`);return t?(t.addEventListener(`change`,e),()=>t.removeEventListener(`change`,e)):()=>void 0}function tpn(){let e=(0,U.useSyncExternalStore)(X6.subscribe,X6.getSnapshot,X6.getSnapshot),[t,n]=(0,U.useReducer)(Yfn,e,e=>Yfn({phase:`hidden`},{type:`lifecycle`,value:e}));return(0,U.useEffect)(()=>n({type:`lifecycle`,value:e}),[e]),(0,U.useEffect)(()=>{if(t.phase===`hidden`)return;let e=t.phase===`acquiring`?Xfn:t.phase===`sealing`?Qfn:t.terminal?Zfn:null;if(e===null)return;let r=window.setTimeout(()=>{if(t.phase===`acquiring`){n({type:`acquisition-elapsed`,callId:t.callId});return}X6.dismiss(t.callId)},e);return()=>window.clearTimeout(r)},[t]),t}function npn({iframeRef:e,activeCompositionPath:t}){let n=(0,U.useRef)(null),r=tpn(),i=(0,U.useSyncExternalStore)(epn,$fn,()=>!1),[a,o]=(0,U.useState)(null),s=r.phase===`hidden`?null:r.callId,c=r.phase===`hidden`?null:r.target.handle,l=r.phase,u=(0,U.useRef)(s),d=(0,U.useRef)(null);u.current=s,(0,U.useLayoutEffect)(()=>{if(!s||!c){o(null);return}let r=n.current,i=e.current;if(!r||!i){o(null);return}let a=qfn({overlay:r,iframe:i,activeCompositionPath:t,handle:c});o(a?{callId:s,geometry:a}:null)},[t,s,c,e,l]);let f=xZ();(0,U.useEffect)(()=>{let t=e.current;return!t||!s?void 0:g2(t,()=>X6.dismiss(s))},[s,e,f]),(0,U.useEffect)(()=>(d.current!==null&&(window.clearTimeout(d.current),d.current=null),()=>{let e=u.current;e&&(d.current=window.setTimeout(()=>{d.current=null,X6.dismiss(e)},0))}),[]);let p=a?.callId===s?a.geometry:null,m=r.phase!==`hidden`&&p;return(0,W.jsx)(`div`,{ref:n,"aria-hidden":`true`,"data-topology-lens":m?r.phase:`hidden`,className:`pointer-events-none absolute inset-0 z-58 overflow-hidden`,children:m&&(0,W.jsxs)(W.Fragment,{children:[(r.phase===`acquiring`||r.phase===`sealing`)&&(0,W.jsx)(`div`,{"data-topology-field":`true`,"data-topology-node":p.field.label,"data-topology-phase":r.phase,className:`hf-topology-field pointer-events-none absolute overflow-hidden rounded-md`,style:t8(p.field.rect),children:r.phase===`sealing`&&(0,W.jsx)(Zke,{"data-topology-seal":r.receiptStage,className:`hf-topology-seal absolute right-2 top-2 h-7 w-11 overflow-visible`,viewBox:`0 18 100 64`})}),(r.phase===`acquiring`||r.phase===`sealing`)&&(0,W.jsxs)(W.Fragment,{children:[p.contours.map(({label:e,rect:t},n)=>(0,W.jsx)(`div`,{"data-topology-contour":`true`,"data-topology-node":e,className:`hf-topology-contour pointer-events-none absolute z-1 rounded-sm`,style:{...t8(t),animationDelay:`${Math.min(n,5)*28}ms`}},n)),!i&&(0,W.jsx)(`div`,{"data-topology-scan":`true`,className:`pointer-events-none absolute z-2 overflow-hidden rounded-sm`,style:t8(p.field.rect),children:(0,W.jsx)(`div`,{className:`hf-topology-scan absolute inset-y-0 left-0 w-1/4`})})]}),(0,W.jsx)(`div`,{"data-topology-target":`true`,"data-topology-node":p.target.label,"data-topology-phase":r.phase,"data-topology-terminal":r.phase===`localizing`?r.terminal??void 0:void 0,className:`hf-topology-target pointer-events-none absolute z-3 rounded-md`,style:t8(p.target.rect)})]})})}function rpn(e,t){if(Object.is(e,t))return!0;if(!e||!t||typeof e!=`object`||typeof t!=`object`||`nodeType`in e||`nodeType`in t||Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>rpn(e[n],t[n]))}function ipn(e,t){for(let[n,r]of t){let i=e.get(n);i!==void 0&&i!==r&&rpn(i,r)&&t.set(n,i)}}function apn(e,t){if(e.size!==t.size)return!1;for(let[n,r]of e)if(t.get(n)!==r)return!1;return!0}function n8(e){let{keyframeCache:t,gsapAnimations:n}=X.getState(),r={keyframeCache:new Map(t),gsapAnimations:new Map(n)};e(r),ipn(t,r.keyframeCache),ipn(n,r.gsapAnimations),!(apn(t,r.keyframeCache)&&apn(n,r.gsapAnimations))&&X.setState({keyframeCache:r.keyframeCache,gsapAnimations:r.gsapAnimations})}function opn(e,t,n,r,i){let{elements:a,domClipChildren:o}=X.getState(),s=new Set,c=new Map,l=new Map;for(let n of e){let e=n.keyframes?.keyframes??yJ(n)?.keyframes??[];if(e.length!==0)for(let r of aJ(n.targetSelector,i)){s.add(r),l.set(r,[...l.get(r)??[],n]);let{elStart:i,elDuration:u}=hJ(r,t,a,o),d=gJ(e,n,i,u),f=c.get(r);f?f.keyframes=vJ([...f.keyframes,...d]):c.set(r,{...n.keyframes,format:n.keyframes?.format??`percentage`,keyframes:d})}}let u=r.targetSelector,d=u?aJ(u,i):[],f=d.length>0?d:n?[n]:[];n8(e=>{for(let[n,r]of c)spn(e,t,n,r,l.get(n));for(let n of f)s.has(n)||r8(e,t,n)})}function spn(e,t,n,r,i){for(let a of a8(t,n))e.keyframeCache.set(a,r),i?e.gsapAnimations.set(a,i):e.gsapAnimations.delete(a)}function r8(e,t,n){for(let r of a8(t,n))e.keyframeCache.delete(r),e.gsapAnimations.delete(r)}function cpn(e,t){n8(n=>r8(n,e,t))}function lpn(e,t,n){let r=`${e}#`,i=new Set;for(let e of[...t.keys(),...n.keys()])e.startsWith(r)&&i.add(e.slice(r.length));if(e!==`index.html`)return i;for(let[e,n]of t){let a=e.indexOf(`#`),o=e.slice(a+1);a>0&&!e.startsWith(r)&&t.get(r+o)===n&&i.delete(o)}return i}function upn(e){let t=new Set(e),{keyframeCache:n,gsapAnimations:r}=X.getState(),i=new Map;for(let e of[...n.keys(),...r.keys()]){let n=e.indexOf(`#`);if(n<0)continue;let r=e.slice(0,n);if(t.has(r))continue;let a=i.get(r)??new Set;a.add(e.slice(n+1)),i.set(r,a)}n8(e=>{for(let[t,n]of i)for(let r of n)r8(e,t,r)})}function i8(e){return`${e.sourceFile||`index.html`}#${e.id}`}function a8(e,t){let n=typeof t==`string`?t:dpn(t,e);return e===`index.html`?[`index.html#${n}`,n]:[`${e}#${n}`,`index.html#${n}`,n]}function dpn(e,t){return mG(`cache_key_non_string`,{value_type:typeof e,constructor_name:e?.constructor?.name??null,is_array:Array.isArray(e),source_file:t}),String(e)}function fpn(e,t,n){n8(r=>{for(let t of lpn(e,r.keyframeCache,r.gsapAnimations))r8(r,e,t);for(let[i,a]of t)spn(r,e,i,a,n.get(i))})}function ppn(e,t,n){n8(r=>{for(let i of a8(e,t))n?r.gsapAnimations.set(i,n):r.gsapAnimations.delete(i)})}function mpn(e,t){return`${e}#${t}`}function hpn(e,t){if(t)return X.getState().keyframeCache.get(mpn(e,t))}function gpn(e,t,n){t&&X.getState().setKeyframeCache(mpn(e,t),n)}var _pn={"no-selector":`This layer needs a stable selector before Studio can save the edit.`,"unroll-required":`This motion comes from a helper or loop. Choose Unroll to edit it explicitly.`,"source-uneditable":`This animation is computed at runtime. Edit the animation in the Code tab.`,"keyframes-uneditable":`Studio can't add this edit to the animation's keyframes. Edit this animation in the Code tab.`,"mixed-files":`These layers are animated in different files. Move each file's layers separately.`},o8=`This animation's keyframes have a step`,s8=`Edit them in the Code tab.`,vpn={"array-step-delay":`${o8} with its own delay, which Studio can't keep while it edits them. ${s8}`,"array-step-callback":`${o8} that runs code as it plays (like onComplete), which an edit would run again. ${s8}`,"array-step-config":`${o8} with its own tween setting (like repeat or stagger), which Studio can't keep while it edits them. ${s8}`,"array-step-computed":`${o8} whose value comes from code, which Studio can't keep while it edits them. ${s8}`,"array-step-relative":`${o8} with a relative value (like "+=40"), which an edit would apply again. ${s8}`,"array-step-random":`${o8} with a random() value, which an edit would roll again. ${s8}`};function ypn(e,t){return(t&&vpn[t])??_pn[e]}var c8=class extends Error{constructor(e,t){super(ypn(e,t)),this.reason=e,this.detail=t,this.name=`GsapEditBlockedError`}reason;detail};function l8(e){if(e.status===`blocked`)throw new c8(e.reason,e.detail)}async function bpn(e,t){if(e.status===`element-offset`)return t();l8(e)}function xpn(e){let t=sVe(e.provenance);if(t===`unroll`)throw new c8(`unroll-required`);if(t===`source`)throw new c8(`source-uneditable`,`provenance-runtime-dynamic`);if(e.hasUnresolvedKeyframes)throw new c8(`source-uneditable`,`unresolved-keyframes`);if(e.hasUnresolvedSelector)throw new c8(`source-uneditable`,`unresolved-selector`)}function Spn(e){return e instanceof c8}function u8(e,t){return Object.keys(e.properties??{}).some(e=>t.has(e))||Object.keys(e.fromProperties??{}).some(e=>t.has(e))||!!e.keyframes?.keyframes.some(e=>Object.keys(e.properties).some(e=>t.has(e)))}function d8(e,t){try{for(let n of e)u8(n,t)&&xpn(n);return{status:`persisted`}}catch(e){if(Spn(e))return{status:`blocked`,reason:e.reason,detail:e.detail};throw e}}var Cpn=class extends Error{constructor(e){super(`Couldn't find this element in the source file (${e})`),this.name=`DomEditPersistUnresolvableError`}},f8=class extends Error{alreadyToasted;constructor(e,t={}){super(e),this.name=`DomEditPersistUnsafeValueError`,this.alreadyToasted=t.alreadyToasted??!1}},wpn=class extends Error{alreadyToasted=!0;constructor(e){super(`The edit saved but its follow-up write to ${e} did not`),this.name=`DomEditPersistPreparedWriteError`}};function Tpn(e){return e.map(e=>`${e.type}:${e.property}`).join(`, `)}function Epn(e){return{hfId:e.hfId,id:e.id,selector:e.selector,selectorIndex:e.selectorIndex,sourceFile:e.sourceFile}}function Dpn(e){return e instanceof Error?e.message:String(e)}function Opn(e){return e.label||e.selector||e.id||`this element`}function kpn(e){return(e instanceof f8||e instanceof wpn||e instanceof JY)&&e.alreadyToasted}function p8(e,t,n,r){let i=Dpn(n);console.warn(`[Studio] DOM edit persist failed`,{target:Epn(e),operations:Tpn(t),error:i}),!kpn(n)&&r(`Couldn't save "${Opn(e)}": ${i}`,`error`)}function Apn(e,t){console.warn(`[Studio] DOM edit persist no-op`,{target:Epn(e),operations:Tpn(t),detail:`Server matched the target but reported no change even though the client believed the value changed.`})}function jpn(e,t){return!t||kpn(e)?null:Spn(e)?e.message:`Failed to save animated edit.`}function Mpn(e,t){return(0,U.useCallback)((n,r,i,a,o)=>{(Spn(n)?DKt:rX)({source:`gsap_commit`,error:n,filePath:r?.sourceFile??e??`index.html`,mutationType:i,label:a,targetId:r?.id,targetSelector:r?.selector,targetSourceFile:r?.sourceFile});let s=jpn(n,o!==!1);s&&t(s,`error`)},[e,t])}var Npn=0,Ppn=new WeakSet;function Fpn(e){return Ppn.has(e)}function Ipn(e){let{x:t,y:n,width:r,height:i}=e.getBoundingClientRect();return{x:t,y:n,width:r,height:i}}function Lpn(e,t,n){let{coalesceKey:r,skipReload:i,softReload:a,...o}=e;return a?{...o,label:n,softReload:!0,coalesceKey:t,coalesceMs:1/0}:{...o,label:n,skipReload:!0,coalesceKey:t,coalesceMs:1/0}}function Rpn(e,t){return{x:t.x-e.x,y:t.y-e.y,width:t.width-e.width,height:t.height-e.height}}function zpn(e){return Object.values(e).some(e=>Math.abs(e)>1)}function m8(e){return Math.round(e*10)/10}function Bpn(e){let t=e.find(({options:e})=>e.softReload),n=t?.options??e.at(-1)?.options;if(!n)throw Error(`Cannot merge an empty gesture transaction`);let{skipReload:r,instantPatch:i,...a}=n;return t?{...a,softReload:!0}:{...a,skipReload:!0}}function Vpn(e){return e.filter(({options:e})=>e.softReload).length}async function Hpn(e){let t=e[0];if(!t)return 0;if(e.length===1)return await t.dispatch(t.selection,t.mutation,t.options),Vpn(e);if(e.every(({dispatch:e,selection:n})=>e===t.dispatch&&n.sourceFile===t.selection.sourceFile)&&t.dispatch.batch)return await t.dispatch.batch(e.map(({selection:e,mutation:t,options:n})=>({selection:e,mutation:t,options:n})),Bpn(e)),+(Vpn(e)>0);for(let{dispatch:t,selection:n,mutation:r,options:i}of e)await t(n,r,i);return Vpn(e)}var h8=o2(`commit`);function Upn(e){let t=performance.now(),n=`tx:${e.label}:${++Npn}`,r=0,i=0,a=[];h8(`start`,{label:e.label,coalesceKey:n}),e.settle(),h8(`settled`,{label:e.label,coalesceKey:n});let o=()=>e.draw?e.draw(()=>Ipn(e.element)):Ipn(e.element),s=e.skipPixelAssert?null:o();return e.persist(t=>{let i=(i,o,s)=>(r+=1,a.push({dispatch:t,selection:i,mutation:o,options:Lpn(s,n,e.label)}),Promise.resolve());return Ppn.add(i),i},n).then(async()=>{i=await Hpn(a),await e.afterBufferedCommitsSaved?.();let c=Math.round(performance.now()-t);if(h8(`persisted`,{label:e.label,coalesceKey:n}),s){let t=o(),n=Rpn(s,t);zpn(n)&&(h8(`persist-changed-pixels`,{label:e.label,before:s,after:t,delta:n}),mG(`commit_invariant_violation`,{label:e.label,delta_x:m8(n.x),delta_y:m8(n.y),delta_w:m8(n.width),delta_h:m8(n.height),mutation_count:r,reload_count:i,duration_ms:c}))}mG(`commit_transaction`,{label:e.label,mutation_count:r,reload_count:i,duration_ms:c,pixel_asserted:s!==null})}).catch(t=>{throw e.restore(),mG(`commit_transaction_failed`,{label:e.label,mutation_count:r,error_name:t instanceof Error?t.name:`unknown`,restore_ran:!0}),h8(`restore`,{label:e.label,coalesceKey:n}),t})}function Wpn(e,t,n=!1){let r={[t.property]:t.value};return{selector:e,change:{kind:n?`global-set`:`set`,props:r}}}function Gpn(e,t,n){return e.find(e=>e.method===`set`&&dJ(e.targetSelector,t,n)&&(`x`in e.properties||`y`in e.properties))??null}function Kpn(e,t,n){return Gpn(e,t,n)||(e.find(e=>dJ(e.targetSelector,t,n)&&e.propertyGroup===`position`&&tJ(e))??null)}function qpn(e,t,n){return e.find(e=>tJ(e)&&dJ(e.targetSelector,t,n)&&`rotation`in e.properties)??null}function Jpn(e,t,n){return e.find(e=>tJ(e)&&dJ(e.targetSelector,t,n)&&(`width`in e.properties||`height`in e.properties))??null}function g8(e){return lJ(e)}function _8(e,t,n=X.getState().currentTime){return fJ(n,e,t)}function v8(e,t){let n=pHt(t,e);n===null||Zq(e)<=0||X.getState().requestSeek(S(n))}async function Ypn(e,t,n,r){let i=g8(e);if(!i)throw new c8(`no-selector`);let a=async r=>{await r(e,{type:`add`,targetSelector:i,method:`set`,position:0,properties:n,global:!0},{label:`Move layer`,skipReload:!0}),await r(e,{type:`delete`,animationId:t.id},{label:`Move layer`,softReload:!0})};if(Fpn(r)){await a(r);return}await Upn({element:e.element,label:`Move layer`,settle:()=>void 0,persist:async e=>a(e(r)),restore:()=>void 0})}async function Xpn(e,t,n,r){if(!(!e.hasUnresolvedKeyframes&&!e.hasUnresolvedSelector))throw new c8(`source-uneditable`,`geometry-unresolved-source`)}function Zpn([e,t]){return e===`delay`?`array-step-delay`:/^on[A-Z]/.test(e)?`array-step-callback`:Art(e)?`array-step-config`:typeof t==`number`?null:Qpn.find(([e])=>e.test(t))?.[1]??null}var Qpn=[[/^__raw:/,`array-step-computed`],[/random\(/,`array-step-random`],[/[-+*/]=/,`array-step-relative`]];function $pn(e){let t=e.keyframes;return t?.format===`object-array`?t.keyframes.flatMap(e=>Object.entries(e.properties)).map(Zpn).find(Boolean)??null:null}function emn(e){let t=$pn(e);if(t)throw new c8(`keyframes-uneditable`,t)}async function tmn(e,t,n,r,i,a){let{newX:o,newY:s}=D3(e.element,t,n,a.stamp);if(i){if(i.keyframes){await Ypn(e,i,{x:o,y:s},a.commitMutation);return}let t={type:`update-properties`,animationId:i.id,properties:{x:o,y:s}},n=!!i.global;await a.commitMutation(e,t,{label:`Move layer`,softReload:!0,instantPatch:{selector:r,change:{kind:n?`global-set`:`set`,props:t.properties}}});return}let c=g8(e);if(!c)throw new c8(`no-selector`);await a.commitMutation(e,{type:`add`,targetSelector:c,method:`set`,position:0,properties:{x:o,y:s},global:!0},{label:`Move layer`,softReload:!0,instantPatch:{selector:c,change:{kind:`global-set`,props:{x:o,y:s}}}})}async function nmn(e,t,n,r,i){if(r){let a={type:`update-property`,animationId:r.id,property:`rotation`,value:t};await i.commitMutation(e,a,{label:`Rotate layer`,softReload:!0,instantPatch:Wpn(n,a,!!r.global)});return}let a=g8(e);if(!a)throw new c8(`no-selector`);await i.commitMutation(e,{type:`add`,targetSelector:a,method:`set`,position:0,properties:{rotation:t},global:!0},{label:`Rotate layer`,softReload:!0,instantPatch:{selector:a,change:{kind:`global-set`,props:{rotation:t}}}})}async function rmn(e,t,n,r,i){let a=le(t.width),o=le(t.height);if(r){await i.commitMutation(e,{type:`update-properties`,animationId:r.id,properties:{width:a,height:o}},{label:`Resize layer`,softReload:!0});return}let s=g8(e);if(!s)throw new c8(`no-selector`);await i.commitMutation(e,{type:`add`,targetSelector:s,method:`set`,position:0,properties:{width:a,height:o}},{label:`Resize layer`,softReload:!0})}async function imn(e,t,n,r,i,a,o){let s=e.element,c=o.stamp??T3(s),{newX:l,newY:u,baseGsapX:d,baseGsapY:f}=D3(s,n,r,c),p=l-d,m=u-f,h=()=>O3(s,c),g=t;if(t.keyframes){emn(t);let n=await Xpn(t,i,o.commitMutation,e);n&&(g={...t,id:n})}let _=Xq(g),v=Zq(g),y=g.keyframes?.keyframes??[];if(y.length===0){let e=g.fromProperties??{},t=g.properties??{},n=typeof e.x==`number`?e.x:(t.x,0),r=typeof e.y==`number`?e.y:(t.y,0),i=typeof t.x==`number`?t.x:n,a=typeof t.y==`number`?t.y:r;y=[{percentage:0,properties:{x:n,y:r}},{percentage:100,properties:{x:i,y:a}}]}let b=y.map(e=>({percentage:e.percentage,properties:{...e.properties,x:S((typeof e.properties.x==`number`?e.properties.x:0)+p),y:S((typeof e.properties.y==`number`?e.properties.y:0)+m)},...e.ease?{ease:e.ease}:{}}));await o.commitMutation(e,{type:`replace-with-keyframes`,animationId:g.id,targetSelector:g.targetSelector,position:S(_??0),duration:S(v||1),keyframes:b,...eJ(g)},{label:`Move animation path`,softReload:!0,beforeReload:h})}function amn(e,t,n){let r=(e,t,n)=>e===void 0?0:(e-t)*n;return{x:t.x+(e.x+r(e.w,t.w,t.ax))*n,y:t.y+(e.y+r(e.h,t.h,t.ay))*n}}function omn(e,t,n){if(n.length<2)return null;let r=null;for(let i=0;i<n.length-1;i++){let a=n[i],o=n[i+1],s=o.x-a.x,c=o.y-a.y,l=s*s+c*c,u=l===0?0:Math.max(0,Math.min(1,((e-a.x)*s+(t-a.y)*c)/l)),d=a.x+u*s,f=a.y+u*c,p=Math.hypot(e-d,t-f);(!r||p<r.dist)&&(r={x:d,y:f,segIndex:i,t:u,dist:p})}return r}var y8=e=>typeof e==`number`&&isFinite(e);function smn(e){return{...y8(e.width)&&{w:e.width},...y8(e.height)&&{h:e.height}}}function cmn(e,t={x:0,y:0}){if(!e)return null;let n=!!e.arcPath,r=[],i=e.keyframes.some(e=>y8(e.properties.x)),a=e.keyframes.some(e=>y8(e.properties.y));if(!i&&!a)return null;let o=e=>i&&!y8(e.x)||a&&!y8(e.y)?null:{x:i?e.x:t.x,y:a?e.y:t.y,...smn(e)};if(e.keyframes.forEach((e,t)=>{let i=o(e.properties);i&&r.push({...i,ref:n?{type:`waypoint`,index:t}:{type:`keyframe`,pct:e.percentage,...e.step==null?{}:{step:e.step}}})}),r.length<2)return null;let s=!n&&e.start?o(e.start):null;return{kind:n?`arc`:`linear`,points:r.map(e=>`${e.x},${e.y}`).join(` `),nodes:r,...s&&{start:s}}}function b8(e){return e?lJ(e):null}function lmn(e,t,n){let r=b8(n),i=e=>!e.hasUnresolvedKeyframes&&!e.hasUnresolvedSelector&&!e.provenance&&!!r&&dJ(e.targetSelector,r,n?.element);return t===`arc`?e.find(e=>e.arcPath?.enabled&&i(e))?.id??null:e.find(e=>e.keyframes&&i(e)&&(e.propertyGroup===`position`||e.keyframes.keyframes.some(e=>`x`in e.properties||`y`in e.properties)))?.id??null}var umn=`[data-dom-edit-selection-box="true"]`,dmn=`${umn}, [data-dom-edit-chrome="true"], [data-dom-edit-crop-frame="true"]`,fmn=(e,t)=>t?e*1.5:e;function pmn(e){let t=e.currentTarget.closest(`svg`),n=e.currentTarget.ownerDocument.elementsFromPoint(e.clientX,e.clientY).find(e=>!t?.contains(e));return n?.closest(dmn)?n:null}function mmn(e,t,n){let r=n&&Math.abs(t.x-n.x)<.5&&Math.abs(t.y-n.y)<.5;return pmn(e)??(r?e.currentTarget.ownerDocument.querySelector(umn):null)}function hmn(e,t){return!t||getComputedStyle(t).pointerEvents===`none`?!1:!t.dispatchEvent(new PointerEvent(`pointerdown`,e.nativeEvent))}function x8(e,t){let n=pJ(e);if(!n)return null;let r=mJ(e,t);return r?{x:Number(n.getProperty(r,`x`))||0,y:Number(n.getProperty(r,`y`))||0}:null}function gmn(e){if(e.keyframes?.keyframes.some(e=>`x`in e.properties||`y`in e.properties))return!0;if(e.method===`fromTo`){let t=e.fromProperties;return`x`in e.properties||`y`in e.properties||!!(t&&(`x`in t||`y`in t))}return`x`in e.properties||`y`in e.properties}function S8(e,t,n=X.getState().currentTime){if(e.length===0)return null;let r=e.filter(gmn).map(e=>{let r=0;return e.keyframes&&(r+=5),t&&e.targetSelector===t?r+=8:e.targetSelector.includes(`,`)&&(r-=5),{anim:e,score:r+_mn(e,n)}});return r.sort((e,t)=>t.score-e.score),r[0]?.anim??null}function _mn(e,t){let n=e.resolvedStart??(typeof e.position==`number`?e.position:0),r=Zq(e);return t>=n-.05&&t<=n+r+.05?50:-Math.round(Math.min(Math.abs(t-n),Math.abs(t-n-r))*5)}function vmn(e,t){let n=Zq(e);if(!(n>0))return!1;let r=(t-(Xq(e)??0))/n*100,i=e=>Math.abs(e-r)<=nJ,a=Hq(e);return e.keyframes?e.keyframes.keyframes.some(e=>i(qq(a,e.percentage))):e.method===`from`?i(0):i(100)||e.method===`fromTo`&&i(0)}function C8(e,t=X.getState().currentTime){return e.length<=1?e[0]??null:e.reduce((e,n)=>{let r=ymn(n,t),i=ymn(e,t);return r<i?n:(r===0&&i===0?bmn(n,e,t):null)||(r===i&&xmn(n)>xmn(e)?n:e)})}function ymn(e,t){let n=Xq(e)??0,r=n+Zq(e);return t>=n&&t<=r?0:Math.min(Math.abs(t-n),Math.abs(t-r))}function bmn(e,t,n){let[r,i]=[vmn(e,n),vmn(t,n)];if(r!==i)return r?e:t;let[a,o]=[Xq(e)??0,Xq(t)??0];return r&&a!==o?a>o?e:t:null}function xmn(e){return e.keyframes?.keyframes.length??0}var w8=`var(--hf-accent, #3CE6AC)`;function Smn(e){let{cx:t,cy:n,r,interactive:i,removable:a,grabbing:o,selected:s}=e,c=t+r*1.8,l=n-r*1.8,u=r*.55,d=fmn(r,s)*1.414;return(0,W.jsxs)(`g`,{onPointerEnter:e.onEnter,onPointerLeave:e.onLeave,children:[(0,W.jsx)(`rect`,{x:t-d/2,y:n-d/2,width:d,height:d,rx:d*.17,transform:`rotate(45 ${t} ${n})`,stroke:`#0b0f1a`,strokeWidth:1.5,vectorEffect:`non-scaling-stroke`,style:{fill:w8}}),i&&(0,W.jsx)(`circle`,{cx:t,cy:n,r:r*2.4,fill:`transparent`,className:`pointer-events-auto`,style:{cursor:o?`grabbing`:`grab`},onPointerDown:e.onPointerDown,onPointerMove:e.onPointerMove,onPointerUp:e.onPointerUp,onPointerCancel:e.onPointerUp,onContextMenu:e.onContextMenu}),a&&(0,W.jsxs)(`g`,{className:`pointer-events-auto`,style:{cursor:`pointer`},onPointerDown:e.onRemove,children:[(0,W.jsx)(`circle`,{cx:c,cy:l,r:r*1.3,stroke:`#0b0f1a`,strokeWidth:1,vectorEffect:`non-scaling-stroke`,style:{fill:w8}}),(0,W.jsx)(`line`,{x1:c-u,y1:l-u,x2:c+u,y2:l+u,stroke:`#0b0f1a`,strokeWidth:1.5,vectorEffect:`non-scaling-stroke`}),(0,W.jsx)(`line`,{x1:c+u,y1:l-u,x2:c-u,y2:l+u,stroke:`#0b0f1a`,strokeWidth:1.5,vectorEffect:`non-scaling-stroke`})]})]})}function Cmn(e){let{points:t,start:n,ghost:r,r:i}=e;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`polyline`,{points:n?`${n.x},${n.y} ${t}`:t,fill:`none`,style:{stroke:w8},strokeWidth:1.5,strokeDasharray:`5 5`,strokeLinejoin:`round`,strokeLinecap:`round`,vectorEffect:`non-scaling-stroke`,opacity:.85}),n&&(0,W.jsx)(`circle`,{"data-motion-path-start":!0,cx:n.x,cy:n.y,r:i*.6,fill:`none`,strokeWidth:1.5,vectorEffect:`non-scaling-stroke`,className:`pointer-events-none`,style:{stroke:w8}}),r&&(0,W.jsx)(`rect`,{x:r.x-i*.707,y:r.y-i*.707,width:i*1.414,height:i*1.414,rx:i*.24,transform:`rotate(45 ${r.x} ${r.y})`,fill:`none`,strokeWidth:1.5,strokeDasharray:`2 2`,vectorEffect:`non-scaling-stroke`,className:`pointer-events-none`,style:{stroke:w8}})]})}function wmn(e,t){let n=new Set;for(let[r,i]of e.entries()){let e=t?.[r];if(e){n.add(e);continue}switch(i.type){case`add-keyframe`:case`add-with-keyframes`:n.add(`add`);break;case`convert-to-keyframes`:n.add(`convert`);break;case`remove-all-keyframes`:n.add(`remove_all`)}}return n}function T8(e,t){mG(`keyframe`,t===void 0?{action:e}:{action:e,property:t})}function Tmn(e){return[`add`,`convert`,`remove_all`,`reset`].find(t=>e.has(t))}function Emn(e,t,n){if(!e.ok||e.changed!==!0)return[];let r=t===1?[!0]:e.mutationChanges;return!Array.isArray(r)||r.length!==t||r.some(e=>typeof e!=`boolean`)?[]:r.flatMap((e,t)=>e&&n?.[t]?.keyframeTelemetry!==!1?[t]:[])}function Dmn(e,t,n,r){if(!t.ok||t.changed!==!0||n.keyframeTelemetry===!1)return;let i=Emn(t,e.length,r),a=Tmn(wmn(i.map(t=>e[t]),i.map(t=>r?.[t]?.keyframeAction??(e.length===1?n.keyframeAction:void 0))));a&&T8(a,a===`add`?n.keyframeProperty:void 0)}function E8(e){let t=RKt(),n=e=>t?t.within(e):e(),r=!1,i=0,a=new Set,o=(e,n)=>(i+=1,{...n,...t&&{pendingEdit:t},keyframeTelemetry:!1,onResult:o=>{if(--i,n.onResult?.(o),!o.ok||o.changed!==!0)return;r=!0,t?.markSaved();let s=Emn(o,e.length,e.map(e=>e.options)).map(t=>e[t]);for(let e of wmn(s.map(e=>e.mutation),s.map(e=>e.options.keyframeAction)))a.add(e)}}),s=null;if(e&&(s=(t,r,i)=>n(()=>e(t,r,o([{selection:t,mutation:r,options:i}],i))),e.batch)){let t=e.batch;s.batch=(e,r)=>n(()=>t(e,o(e,r)))}return{commit:s,drawKeepingUndone:e=>t?t.drawKeepingUndone(e):e(),recordDomResult:e=>{r||=e?.changed===!0,e?.changed&&t?.markSaved()},finish:(e=!1)=>{if(i!==0)return{ok:!0,changed:!1};let t=Tmn(a);return t&&T8(t),{ok:!0,changed:r||e}}}}function D8(e,t){let n=t?.ownerDocument;if(!t?.isConnected||!n||e.hasUnresolvedSelector)return`unknown`;let r;try{r=[...n.querySelectorAll(e.targetSelector)]}catch{return`unknown`}return r.includes(t)?r.length===1?`own`:`shared`:`elsewhere`}function O8(e,t){return t.filter(t=>{let n=D8(t,e.element);return n===`own`||n===`unknown`})}var Omn=e=>Math.round(e*1e3)/1e3,kmn=e=>!e||e===`none`||e===`linear`;function k8(e){return{ok:!1,reason:e}}function Amn(e){let{anim:t}=e,n=t.keyframes;if(n){if(n.format===`simple-array`)return{reason:`simple-array-keyframes`};let e=n.format===`object-array`,r=$pn(t);return r?{reason:r}:{runEase:Hq(t),keyframes:n.keyframes.map(t=>({...t,properties:{...t.properties},...e?{ease:t.ease??oHt}:{}})),...n.easeEach&&!e?{easeEach:n.easeEach}:{}}}let r=t.ease??e.parsedEase;if(!r)return{reason:`unknown-ease`};let i={percentage:100,properties:{...t.properties}};if(t.method===`to`)return{keyframes:[i],easeEach:r};if(t.method===`fromTo`)return{keyframes:[{percentage:0,properties:{...t.fromProperties}},i],easeEach:r};if(t.method===`from`){let n={};for(let r of Object.keys(t.properties)){let t=e.implicitEndValue(r,`end`);if(t==null)return{reason:`implicit-end-unknown`};n[r]=t}return{keyframes:[{percentage:0,properties:{...t.properties}},{percentage:100,properties:n}],easeEach:r}}return{reason:`not-a-tween`}}function jmn(e,t,n){let r=e.filter(e=>e.properties[t]!=null),i=n===`first`?r[0]:r.at(-1);return i?{percentage:i.percentage,value:i.properties[t]}:null}var Mmn=(e,t)=>e[x9t(e,t)];function Nmn(e,t,n,r){let i=Mmn(e,t);if(i)return Object.assign(i.properties,n),i;let a={percentage:t,properties:n,...r?{ease:r}:{}};return e.push(a),a}function Pmn(e,t,n,r){let i=new Set(e.keyframes.flatMap(e=>Object.keys(e.properties))),a={};for(let o of i){let i=jmn(e.keyframes,o,t===`start`?`first`:`last`),s=i&&(t===`end`||i.percentage<=0)?i.value:r[o]??n(o,`start`);if(s==null)return null;a[o]=s}return a}function Fmn(e,t,n){let r=new Set(e.flatMap(e=>Object.keys(e.properties)));for(let i of r){let r;for(let a of e)if(a.properties[i]!=null)r=a.properties[i];else{if(r??=n[i]??t(i,`start`),r==null)return!1;a.properties[i]=r}}return!0}function Imn(e){let{anim:t,values:n}=e,r=Xq(t),i=Zq(t);if(r==null||!(i>0))return k8(`no-timing`);let a=Amn(e);if(`reason`in a)return k8(a.reason);let o=a.keyframes,s=o.length,c=t.keyframes?.format===`object-array`?[...o]:[];if(`scaleX`in n||`scaleY`in n)for(let e of o){let{scale:t,...n}=e.properties;t!=null&&(e.properties={scaleX:t,scaleY:t,...n})}let l={},u=new Set(c.filter(e=>Object.keys(e.properties).length===0));for(let[t,r]of Object.entries(e.backfill??{}))if(!(!(t in n)||o.some(e=>e.properties[t]!=null))){e.holdFromStart&&!o.some(e=>e.percentage<=0)&&o.unshift({percentage:0,properties:{}});for(let e of o)u.has(e)||(e.properties[t]=r);l[t]=r}if(Object.keys(n).some(e=>!o.some(t=>t.properties[e]!=null)))return k8(`implicit-end-unknown`);let d=r,f=i,p=`percentage`in e.at?e.at.percentage:Omn((e.at.time-r)/i*100),m=!kmn(a.runEase);if(p>=-nJ&&p<=100+nJ){let t=Math.min(100,Math.max(0,p)),r=Mmn(o,t),i=`percentage`in e.at||r?.percentage===0||r?.percentage===100;if(m&&!(r&&i))return k8(`eased-keyframes`);let a=[...o].sort((e,t)=>e.percentage-t.percentage).find(e=>e.percentage>t+nJ);Nmn(o,t,{...n},a?.ease)}else{if(m)return k8(`eased-keyframes`);let t=e.at.time,s=t<r,c=Pmn(a,s?`start`:`end`,e.implicitEndValue,l);if(!c)return k8(`implicit-end-unknown`);d=s?t:r,f=s?r+i-t:t-r;for(let e of o)e.percentage=Omn((r+e.percentage/100*i-d)/f*100);let u=Omn(((s?r:r+i)-d)/f*100),p=kmn(a.easeEach??aHt)?void 0:`none`,h=Nmn(o,u,c,p);s&&p&&(h.ease??=p),Nmn(o,s?0:100,{...c,...n},s?void 0:p)}return Fmn(c,e.implicitEndValue,l)?(o.sort((e,t)=>e.percentage-t.percentage),{ok:!0,mutation:{type:`replace-with-keyframes`,animationId:t.id,targetSelector:t.targetSelector,position:S(d),duration:S(f),keyframes:o,...a.runEase?{ease:a.runEase}:{},...a.easeEach?{easeEach:a.easeEach}:{}},added:o.length>s}):k8(`implicit-end-unknown`)}function Lmn(e,t,n,r,{backfill:i,holdFromStart:a,moment:o=$3()}={}){if(D8(t,e.element)===`shared`)return k8(`shared-tween`);let{keyframePct:s,time:c}=o,l=O0(r,e.element,t);return Imn({anim:c9t(b9t(t,l),l),at:s==null?{time:c}:{percentage:S9t(t,l,s)},values:n,backfill:i,holdFromStart:a,implicitEndValue:g9t(l),parsedEase:v9t(r,l)})}async function A8(e,t,n,r,i,a){await Xpn(t,r,i.commitMutation,e);let o=e6(i.stamp),{setActiveKeyframePct:s}=X.getState(),c=O0(r,e.element,t),l=o.keyframePct==null?null:S9t(t,c,o.keyframePct),u=Lmn(e,t,n,r,{...a,moment:o});return u.ok?(await i.commitMutation(e,u.mutation,{label:a.label,softReload:!0,beforeReload:a.beforeReload,...u.added&&{keyframeAction:`add`}}),l!=null&&(s(null),v8(t,l)),{status:`persisted`}):{status:`blocked`,reason:`keyframes-uneditable`,detail:u.reason}}async function j8(e,t,n,r,i,a,o){let s=t;if(t.keyframes){emn(t);let n=await Xpn(t,i,a.commitMutation,e);n&&(s={...t,id:n})}let c=Xq(s),l=Zq(s),u=Object.keys(n),d=(e,t)=>typeof e[t]==`number`?e[t]:$q[t]??0,f=s.keyframes?.keyframes??yJ(s)?.keyframes;if(!f||f.length===0){await a.commitMutation(e,{type:`update-properties`,animationId:s.id,properties:n},{label:o,softReload:!0});return}let p=f.reduce((e,t)=>Math.abs(t.percentage-r)<Math.abs(e.percentage-r)?t:e),m=f.map(e=>{let t={...e.properties};for(let e of u)t[e]=S(d(t,e)+(n[e]-d(p.properties,e)));return{percentage:e.percentage,properties:t,...e.ease?{ease:e.ease}:{}}});await a.commitMutation(e,{type:`replace-with-keyframes`,animationId:s.id,targetSelector:s.targetSelector,position:S(c??0),duration:S(l||1),keyframes:m,...eJ(s)},{label:o,softReload:!0})}var Rmn=1.5;function M8(e,t){return{label:e,softReload:!0,onResult:e=>{e.ok&&e.changed===!0&&m4(`motion_path`,t)}}}function zmn(e,t,n,r,i){return i(e.type===`keyframe`?{type:`update-keyframe`,animationId:r,percentage:e.pct,properties:{x:t,y:n}}:{type:`update-motion-path-point`,animationId:r,pointIndex:e.index,x:t,y:n},M8(e.type===`keyframe`?`Move keyframe`:`Move waypoint`,`drag`))}function Bmn(e){return e.type===`keyframe`?X.getState().autoKeyframeEnabled?`Move keyframe`:`Move animation path`:`Move waypoint`}function Vmn(e){let{ref:t,at:n,anim:r,selection:i,iframe:a,commitMutation:o}=e;if(t.type!==`keyframe`||!r||!i)return zmn(t,n.x,n.y,e.animId,o);let s=E8((e,t,n)=>o(t,n)),c={commitMutation:s.commit},l,u=X.getState(),d=(t.step==null?void 0:r.keyframes?.keyframes[t.step])?.percentage??t.pct;if(u.autoKeyframeEnabled){let e=u.activeKeyframePct;u.setActiveKeyframePct(d);let o=x8(a,b8(i)??``);l=A8(i,r,n,a,c,{label:Bmn(t),backfill:o??void 0}).then(l8).catch(t=>{throw X.getState().setActiveKeyframePct(e),t})}else l=j8(i,r,n,d,a,c,Bmn(t));return l.then(()=>h4(`motion_path`,`drag`,s.finish()))}function Hmn(e,t,n,r,i){return i({type:`add-motion-path-point`,animationId:e,index:t,x:n,y:r},M8(`Add waypoint`,`button`))}function Umn(e,t,n,r,i){return i({type:`add-keyframe`,animationId:e,percentage:t,properties:{x:n,y:r}},M8(`Add keyframe`,`button`))}function Wmn(e,t,n){return n({type:`remove-motion-path-point`,animationId:e,index:t},M8(`Remove waypoint`,`button`))}function Gmn(e,t,n,r,i){return i({type:`add-motion-path`,targetSelector:e,position:t,duration:Rmn,x:n,y:r},M8(`Create motion path`,`button`))}function Kmn(e){let t=e.ownerDocument?.defaultView?.getComputedStyle(e).transform;if(!t||t===`none`)return{x:0,y:0};let n=t.match(/matrix3d\(([^)]+)\)/);if(n){let e=n[1].split(`,`).map(Number);return{x:e[12]||0,y:e[13]||0}}let r=t.match(/matrix\(([^)]+)\)/);if(r){let e=r[1].split(`,`).map(Number);return{x:e[4]||0,y:e[5]||0}}return{x:0,y:0}}function qmn(e){let t=e.ownerDocument?.defaultView?.getComputedStyle(e).translate??`none`,[n=`0`,r=`0`]=t===`none`?[]:t.split(` `),i=(e,t)=>e.endsWith(`%`)?Number.parseFloat(e)/100*t:Number.parseFloat(e)||0;return[i(n,e.offsetWidth),i(r,e.offsetHeight)]}function Jmn(e,t,n){let r=e.ownerDocument?.defaultView?.getComputedStyle(e);if(!r||!/^(absolute|fixed)$/.test(r.position))return{ax:0,ay:0};let i=e.computedStyleMap?.(),a=e=>String(i?.get(e)??``)===`auto`,o=(e,t)=>a(e)&&!a(t)?-.5:.5;return{ax:o(`left`,`right`)+t,ay:o(`top`,`bottom`)+n}}function Ymn(e){let t=0,n=0,r=e;for(;r;){if(t+=r.offsetLeft,n+=r.offsetTop,r!==e){let e=Kmn(r);t+=e.x,n+=e.y}let i=r.offsetParent;if(!i||i.hasAttribute(`data-composition-id`))break;r=i}let i=e._gsap,a=i!==void 0&&`x`in i&&!i.uncache,[o,s]=qmn(e),c=(e,t,n)=>a?(Number(e)||0)/100:t&&Math.round(n/2)===Math.round(-t)?-.5:0,l=a?{x:0,y:0}:Kmn(e),[u,d]=[c(i?.xPercent,o+l.x,e.offsetWidth),c(i?.yPercent,s+l.y,e.offsetHeight)],f=t+e.offsetWidth*(.5+u)+(a?o:0),p=n+e.offsetHeight*(.5+d)+(a?s:0),{ax:m,ay:h}=Jmn(e,u,d);return{x:f,y:p,w:e.offsetWidth,h:e.offsetHeight,ax:m,ay:h}}function Xmn(e){let t=e.ownerDocument?.defaultView?.getComputedStyle(e).transform;if(!t||!t.startsWith(`matrix3d(`))return 1;let n=t.slice(9,-1).split(`,`),r=Number.parseFloat(n[15]??``);return Number.isFinite(r)&&r>0?r:1}function Zmn(e,t){return Math.abs(e.left-t.left)<.5&&Math.abs(e.top-t.top)<.5&&Math.abs(e.width-t.width)<.5&&Math.abs(e.height-t.height)<.5}function Qmn(e){try{return!!e?.contentWindow?.MotionPathPlugin}catch{return!1}}function $mn(e,t){let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),o=(0,U.useRef)(null),s=o.current===t,[c,l]=(0,U.useState)(!0),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(1),m=X(e=>e.motionPathArmed),h=i!==null||m;return(0,U.useEffect)(()=>{if(!t){r(null),d(null);return}return d(null),h?X2(()=>{let n=e.current;if(n){let e=n.getBoundingClientRect(),i=(n.ownerDocument?.querySelector(`[data-preview-pan-surface]`))?.getBoundingClientRect(),a={left:i?e.left-i.left:e.left,top:i?e.top-i.top:e.top,width:e.width,height:e.height};r(e=>e&&Zmn(e,a)?e:a);let o=null;try{o=n.contentDocument?.querySelector(t)??null}catch{}let s=O(o)?o:null,c=!s||F4(s);if(l(e=>e===c?e:c),s){let e=Ymn(s);d(t=>t&&Math.abs(t.x-e.x)<.5&&Math.abs(t.y-e.y)<.5&&t.w===e.w&&t.h===e.h&&t.ax===e.ax&&t.ay===e.ay?t:e);let t=1/Xmn(s);p(e=>Math.abs(e-t)<.001?e:t)}}}):void 0},[t,e,h]),(0,U.useEffect)(()=>{if(!t){a(null);return}let n=()=>{let n=F0(e.current,t,void 0,[`x`,`y`]),r=cmn(n,(n?x8(e.current,t):null)??void 0);a(e=>e?.kind===r?.kind&&JSON.stringify([e?.nodes,e?.start])===JSON.stringify([r?.nodes,r?.start])?e:r),o.current=t};n();let r=window.setInterval(n,250);return()=>window.clearInterval(r)},[t,e]),{rect:n,geometry:i,geometryResolved:s,visibleInPreview:c,home:u,pScale:f}}function ehn(e,t,n){return e?.type!==`keyframe`||t?.type!==`keyframe`?null:Math.round((e.pct+(t.pct-e.pct)*n)*1e3)/1e3}var thn=6,nhn=3,rhn=()=>{},ihn=(0,U.memo)(function({iframeRef:e,selection:t,compositionSize:n,isPlaying:r}){let{commitMutation:i,selectedGsapAnimations:a,handleGsapRemoveKeyframe:o,handleGsapRemoveAllKeyframes:s,handleGsapMoveKeyframeToPlayhead:c}=MX(),l=IX(),u=Mpn(l?.activeCompPath??null,l?.showToast??rhn),{rect:d,geometry:f,geometryResolved:p,visibleInPreview:m,home:h,pScale:g}=$mn(e,b8(t)),[_,v]=(0,U.useState)(null),[y,b]=(0,U.useState)(null),[x,S]=(0,U.useState)(`copy`),[C,w]=(0,U.useState)(null),[T,E]=(0,U.useState)(null),D=X(e=>e.activeKeyframePct),k=X(e=>{if(!t)return;let n=i8(t);return e.elements.find(e=>(e.key??e.id)===n||e.id===t.id)}),A=X(e=>e.motionPathArmed),j=X(e=>e.setMotionPathArmed),M=X(e=>e.setMotionPathCreateAvailable),N=(0,U.useRef)(null),P=(0,U.useRef)(void 0),F=lmn(a??[],f?.kind??`linear`,t);(0,U.useEffect)(()=>()=>clearTimeout(P.current),[F]);let I=p&&!f&&!!t?.element&&!r,L=I?b8(t):null,R=n?.width??null,z=xZ(),B=I&&!!L&&Qmn(z);if((0,U.useEffect)(()=>(M(!!B),()=>M(!1)),[B,M]),(0,U.useEffect)(()=>{A&&!B&&j(!1)},[A,B,j]),(0,U.useEffect)(()=>{if(!A||!L||!R)return;let t=e.current?.ownerDocument?.querySelector(`[data-preview-pan-surface]`)??null;if(!t)return;let n=t.style.cursor;t.style.cursor=`crosshair`;let r=t=>{if(t.button!==0)return;let n=e.current;if(!n||!Qmn(n))return;let r=n.getBoundingClientRect();if(t.clientX<r.left||t.clientX>r.right||t.clientY<r.top||t.clientY>r.bottom)return;let a=n.contentDocument?.querySelector(L);if(!O(a))return;t.stopPropagation(),t.preventDefault();let o=r.width/R,s=Ymn(a),c=1/Xmn(a),l=Math.round(((t.clientX-r.left)/o-s.x)/c),u=Math.round(((t.clientY-r.top)/o-s.y)/c),d=Math.round(X.getState().currentTime*100)/100;Gmn(L,d,l,u,i),j(!1)};return t.addEventListener(`pointerdown`,r,!0),()=>{t.removeEventListener(`pointerdown`,r,!0),t.style.cursor=n}},[A,L,R,e,i,j]),!d||d.width<=0||!n||n.width<=0||!m||!h)return null;if(!f){if(!A||!B)return null;let e=thn/(d.width/n.width)*1.6;return(0,W.jsx)(`svg`,{className:`pointer-events-none absolute z-40`,style:{left:d.left,top:d.top,width:d.width,height:d.height,overflow:`visible`},viewBox:`0 0 ${n.width} ${n.height}`,children:(0,W.jsx)(`circle`,{cx:h.x,cy:h.y,r:e,fill:`none`,strokeWidth:1.5,strokeDasharray:`3 3`,vectorEffect:`non-scaling-stroke`,style:{stroke:w8},opacity:.85})})}let V=d.width/n.width,ee=thn/V,te=!!F&&!r,H=f.kind===`arc`&&te&&f.nodes.length>2,ne=te,re=(_?f.nodes.map((e,t)=>t===_.index?{...e,x:_.x,y:_.y}:e):f.nodes).map(e=>{let t=amn(e,h,g);return{...e,ax:t.x,ay:t.y}}),ie=re.map(e=>`${e.ax},${e.ay}`).join(` `),ae=f.start&&amn(f.start,h,g),oe=t=>{let n=e.current?.getBoundingClientRect(),r=n?n.left:d.left,i=n?n.top:d.top;return{x:(t.clientX-r)/V,y:(t.clientY-i)/V}},se=(n,r,i,a,o)=>{if(!te||n.button!==0)return;n.stopPropagation();let s=x8(e.current,b8(t)??``);hmn(n,mmn(n,re[r],s))||(n.target.setPointerCapture(n.pointerId),N.current={index:r,startX:n.clientX,startY:n.clientY,initX:i,initY:a,scale:V,pScale:g,ref:o},v({index:r,x:i,y:a}))},ce=e=>{let t=N.current;t&&v({index:t.index,x:t.initX+(e.clientX-t.startX)/t.scale/t.pScale,y:t.initY+(e.clientY-t.startY)/t.scale/t.pScale})},le=n=>{let r=N.current;if(!r||(N.current=null,v(null),!F))return;let o=n.clientX-r.startX,s=n.clientY-r.startY,c=Math.round(r.initX+o/r.scale/r.pScale),l=Math.round(r.initY+s/r.scale/r.pScale);if(Math.hypot(o,s)<nhn){if(r.ref.type===`keyframe`){X.getState().setActiveKeyframePct(r.ref.pct);let e=r.ref;clearTimeout(P.current),n.detail<2&&(P.current=setTimeout(()=>{let t=a?.find(e=>e.id===F);t&&v8(t,e.pct)},250))}return}if(c===Math.round(r.initX)&&l===Math.round(r.initY))return;let d=r.ref.type===`keyframe`?a?.find(e=>e.id===F):void 0,f=Bmn(r.ref);Vmn({ref:r.ref,at:{x:c,y:l},animId:F,anim:d,selection:t,iframe:e.current,commitMutation:i}).catch(e=>u(e,t,`drag`,f)),r.ref.type===`keyframe`&&d&&v8(d,r.ref.pct)},ue=e=>{let t=pmn(e);S(t?getComputedStyle(t).cursor:`copy`);let n=oe(e),r=omn(n.x,n.y,re.map(e=>({x:e.ax,y:e.ay})));b(r&&!t?{x:r.x,y:r.y,segIndex:r.segIndex}:null)},de=e=>{if(hmn(e,pmn(e))){e.stopPropagation();return}if(!F)return;let t=oe(e),n=omn(t.x,t.y,re.map(e=>({x:e.ax,y:e.ay})));if(!n)return;let[r,a]=[re[n.segIndex],re[n.segIndex+1]],o=Math.round(r.x+n.t*(a.x-r.x)),s=Math.round(r.y+n.t*(a.y-r.y));if(f.kind===`arc`)e.stopPropagation(),Hmn(F,n.segIndex+1,o,s,i);else{let t=ehn(re[n.segIndex]?.ref,re[n.segIndex+1]?.ref,n.t);if(t===null)return;e.stopPropagation(),Umn(F,t,o,s,i)}b(null)},fe=(e,t)=>{e.stopPropagation(),F&&(w(null),Wmn(F,t,i))},pe=t?.id??null,me=(e,t)=>{!F||!pe||!k||(e.preventDefault(),e.stopPropagation(),E({ref:t,state:{x:e.clientX,y:e.clientY,element:k,elementId:pe,percentage:t.type===`keyframe`?t.pct:0,tweenPercentage:t.type===`keyframe`?t.pct:0}}))},he=T?.ref,ge=he===void 0||!F?void 0:he.type===`keyframe`?(e,t)=>{o(F,t.percentage)}:H?()=>{Wmn(F,he.index,i)}:void 0;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`svg`,{className:`pointer-events-none absolute z-40`,style:{left:d.left,top:d.top,width:d.width,height:d.height,overflow:`visible`},viewBox:`0 0 ${n.width} ${n.height}`,children:[ne&&(0,W.jsx)(`polyline`,{points:ie,fill:`none`,stroke:`transparent`,strokeWidth:14/V,className:`pointer-events-auto`,style:{cursor:x},onPointerMove:ue,onPointerLeave:()=>b(null),onPointerDown:de}),(0,W.jsx)(Cmn,{points:ie,start:ae,ghost:y,r:ee}),re.map((e,t)=>(0,W.jsx)(Smn,{cx:e.ax,cy:e.ay,r:ee,interactive:te,removable:H&&C===t,grabbing:_?.index===t,selected:e.ref.type===`keyframe`&&e.ref.pct===D,onEnter:()=>w(t),onLeave:()=>w(e=>e===t?null:e),onPointerDown:n=>se(n,t,e.x,e.y,e.ref),onPointerMove:ce,onPointerUp:le,onRemove:e=>fe(e,t),onContextMenu:t=>me(t,e.ref)},t))]}),T&&(0,W.jsx)(t6t,{state:T.state,onClose:()=>E(null),onDelete:ge,onDeleteAll:()=>F&&s(F),onMoveToPlayhead:T.ref.type===`keyframe`?(e,t)=>F&&c(F,t.percentage):void 0})]})}),ahn=(0,U.memo)(function(){let[e,t]=(0,U.useState)(!1),{state:n,actions:r}=Q2(),{snapPrefs:i,rulerVisible:a,safeMarginsVisible:o}=n,s=X(e=>e.motionPathCreateAvailable),c=X(e=>e.motionPathArmed),l=X(e=>e.setMotionPathArmed),u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useRef)(null),p=(0,U.useRef)(i.gridSpacing);p.current=i.gridSpacing;let m=(0,U.useCallback)(()=>{let e=f.current;f.current=null,e!==null&&e!==p.current&&m4(`grid_spacing`,`field`)},[]);(0,U.useEffect)(()=>m,[m]);let h=(0,U.useCallback)(e=>{r.setSnapPrefs(e)},[r]),g=(0,U.useCallback)(()=>{h({snapEnabled:!i.snapEnabled}),m4(`snapping`,`button`)},[i.snapEnabled,h]),_=(0,U.useCallback)(()=>{h({gridVisible:!i.gridVisible}),m4(`grid`,`button`)},[i.gridVisible,h]);return(0,U.useEffect)(()=>{let e=e=>{e.defaultPrevented||oX(e.target)||e.target instanceof HTMLIFrameElement||(e.key===`s`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&(e.preventDefault(),h({snapEnabled:!i.snapEnabled}),e.repeat||m4(`snapping`,`keyboard`)),e.key===`g`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&(e.preventDefault(),h({gridVisible:!i.gridVisible}),e.repeat||m4(`grid`,`keyboard`)))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i.gridVisible,i.snapEnabled,h]),(0,U.useEffect)(()=>{if(!e)return;let n=e=>{let n=e.target;u.current?.contains(n)||d.current?.contains(n)||(m(),t(!1))};return document.addEventListener(`mousedown`,n),()=>document.removeEventListener(`mousedown`,n)},[e,m]),(0,W.jsxs)(`div`,{className:`pointer-events-auto absolute top-2 right-2 z-50 flex items-center gap-1`,onPointerDown:e=>e.stopPropagation(),children:[s&&(0,W.jsx)(`button`,{type:`button`,className:`rounded-md p-1.5 transition-colors active:scale-[0.95] ${c?`bg-studio-accent/20 text-accent-ink`:`bg-black/40 text-white/60 hover:bg-black/60 hover:text-white/80`}`,onClick:()=>l(!c),title:c?`Click the canvas to set the destination`:`Set motion destination`,"aria-label":`Set motion destination`,children:(0,W.jsx)(a9e,{size:16,weight:c?`fill`:`regular`})}),[[`rulerVisible`,`Ruler`,p9e],[`safeMarginsVisible`,`Safe margins`,A7e]].map(([e,t,n])=>{let i=e===`rulerVisible`?a:o,s=e===`rulerVisible`?r.toggleRulers:r.toggleSafeMargins;return(0,W.jsx)(`button`,{type:`button`,className:`rounded-md p-1.5 transition-colors active:scale-[0.95] ${i?`bg-studio-accent/20 text-accent-ink`:`bg-black/40 text-white/60 hover:bg-black/60 hover:text-white/80`}`,onClick:()=>{s(),m4(e===`rulerVisible`?`ruler`:`safe_margins`,`button`)},title:`${t} ${i?`on`:`off`}`,"aria-label":`Toggle ${t.toLowerCase()}`,"aria-pressed":i,children:(0,W.jsx)(n,{size:16,weight:i?`fill`:`regular`})},e)}),(0,W.jsx)(`button`,{type:`button`,className:`rounded-md p-1.5 transition-colors active:scale-[0.95] ${i.snapEnabled?`bg-studio-accent/20 text-accent-ink`:`bg-black/40 text-white/60 hover:bg-black/60 hover:text-white/80`}`,onClick:g,title:i.snapEnabled?`Snap enabled (S)`:`Snap disabled (S)`,"aria-label":`Toggle snap`,children:(0,W.jsx)(G7e,{size:16,weight:i.snapEnabled?`fill`:`regular`})}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsx)(`button`,{ref:d,type:`button`,className:`rounded-md p-1.5 transition-colors active:scale-[0.95] ${i.gridVisible?`bg-studio-accent/20 text-accent-ink`:`bg-black/40 text-white/60 hover:bg-black/60 hover:text-white/80`}`,onClick:_,onContextMenu:n=>{n.preventDefault(),e&&m(),t(e=>!e)},title:i.gridVisible?`Grid visible (G) — right-click for spacing options`:`Grid hidden (G) — right-click for spacing options`,"aria-label":`Toggle grid`,children:(0,W.jsx)(P7e,{size:16,weight:i.gridVisible?`fill`:`regular`})}),(0,W.jsx)(`button`,{type:`button`,className:`absolute -right-0.5 -bottom-0.5 rounded-sm p-0.5 text-white/50 hover:text-white/90 bg-black/50`,onClick:()=>{e&&m(),t(e=>!e)},title:`Grid options`,"aria-label":`Grid options`,"aria-expanded":e,children:(0,W.jsx)(`svg`,{width:`7`,height:`7`,viewBox:`0 0 8 8`,fill:`currentColor`,"aria-hidden":`true`,children:(0,W.jsx)(`path`,{d:`M1 2.5l3 3 3-3z`})})}),e&&(0,W.jsxs)(`div`,{ref:u,className:`absolute right-0 top-full mt-1 rounded-lg bg-raised border border-border p-3 shadow-xl min-w-[180px]`,children:[(0,W.jsxs)(`label`,{className:`flex items-center justify-between text-xs text-white/80 mb-2`,children:[(0,W.jsx)(`span`,{children:`Grid spacing`}),(0,W.jsx)(`input`,{type:`number`,min:10,max:500,step:10,value:i.gridSpacing,onFocus:()=>{f.current=i.gridSpacing},onBlur:m,onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},onChange:e=>{let t=Number.parseInt(e.target.value,10);Number.isFinite(t)&&t>=10&&t<=500&&t!==i.gridSpacing&&h({gridSpacing:t})},className:`w-16 rounded-sm bg-neutral-900 border border-neutral-600 px-1.5 py-0.5 text-xs text-white text-right tabular-nums outline-hidden focus:border-studio-accent`})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-white/80 cursor-pointer`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:i.snapToGrid,onChange:()=>{h({snapToGrid:!i.snapToGrid}),m4(`snap_to_grid`,`button`)},className:`accent-studio-accent`}),(0,W.jsx)(`span`,{children:`Snap to grid`})]})]})]})]})}),ohn=(0,U.memo)(function(){let{state:e}=Q2(),{gridVisible:t,gridSpacing:n}=e.snapPrefs,{scaleX:r,scaleY:i,left:a,top:o,width:s,height:c}=e.compositionRect;if(!t||n<=0)return null;let l=n*r,u=n*i;return l<4||u<4?null:(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute`,style:{left:a,top:o,width:s,height:c,backgroundImage:[`repeating-linear-gradient(90deg, rgba(255,255,255,0.12) 0px, rgba(255,255,255,0.12) 1px, transparent 1px, transparent ${l}px)`,`repeating-linear-gradient(0deg, rgba(255,255,255,0.12) 0px, rgba(255,255,255,0.12) 1px, transparent 1px, transparent ${u}px)`].join(`, `),backgroundSize:`${l}px ${u}px`}})});function shn(e){if(!chn(e))return null;let t=e;return R1(t)?uhn(t.width,t.height):null}function chn(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.source===`hf-preview`&&t.type===`stage-size`}function lhn(e){return typeof e==`number`&&Number.isFinite(e)&&e>0?e:null}function uhn(e,t){let n=lhn(e),r=lhn(t);return n===null||r===null?null:{width:n,height:r}}function dhn(e){let[t,n]=(0,U.useState)(null),r=xZ();return(0,U.useEffect)(()=>{let e=Ntn(r);e&&n(t=>t&&t.width===e.width&&t.height===e.height?t:e)},[r]),ax(()=>{let t=t=>{if(!t.source||t.source!==e.current?.contentWindow)return;let r=shn(t.data);r&&n(e=>e&&e.width===r.width&&e.height===r.height?e:r)};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)}),t}function fhn({shouldShowMotionPath:e,shouldShowSelectedDomBounds:t,blockPreview:n,isGestureRecording:r,gestureOverlay:i}){let{activeCompPath:a,previewIframeRef:o}=FX(),{captionEditMode:s,compositionLoading:c,isPlaying:l}=LX(),u=dhn(o),d=V2(),f=s&&!d,p=O1(e=>e.model!==null),m=O1(e=>e.dismissed),h=O1(e=>e.syncError),g=(0,U.useCallback)(()=>{let e=O1.getState();e.clearSelection(),e.setDismissed(!0),e.setEditMode(!1)},[]),_=(0,U.useCallback)(()=>{let e=O1.getState();e.setDismissed(!1),e.setEditMode(!0)},[]),{domEditSelection:v}=jX();return n?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(npn,{iframeRef:o,activeCompositionPath:a}),(0,W.jsx)(`div`,{className:`absolute inset-0 z-30 bg-black pointer-events-none`,children:n.videoUrl?(0,W.jsx)(`video`,{src:n.videoUrl,autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:`w-full h-full object-contain`}):n.posterUrl?(0,W.jsx)(`img`,{src:n.posterUrl,alt:n.title,className:`w-full h-full object-contain`}):null})]}):f?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(npn,{iframeRef:o,activeCompositionPath:a}),(0,W.jsx)(Vrn,{iframeRef:o}),(0,W.jsxs)(`div`,{className:`pointer-events-auto absolute top-2 left-1/2 -translate-x-1/2 z-60 flex items-center gap-2 rounded-full border border-studio-accent/40 bg-black/70 px-2.5 py-1`,children:[(0,W.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-studio-accent`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{className:`text-2xs text-neutral-200`,children:`Editing captions`}),(0,W.jsx)(`button`,{type:`button`,onClick:g,className:`rounded-sm text-2xs text-neutral-400 underline underline-offset-2 hover:text-neutral-100 focus-visible:outline-solid focus-visible:outline-1 focus-visible:outline-studio-accent`,children:`Exit`})]}),h&&(0,W.jsxs)(`div`,{role:`alert`,className:`pointer-events-auto absolute top-10 left-1/2 -translate-x-1/2 z-60 flex items-center gap-2 rounded-full border border-red-500/50 bg-red-950/90 px-2.5 py-1`,children:[(0,W.jsx)(`span`,{className:`text-2xs text-red-200`,children:h}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>O1.getState().retrySave?.(),className:`rounded-sm text-2xs text-red-100 underline underline-offset-2 hover:text-white`,children:`Retry`}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>O1.getState().setSyncError(null),"aria-label":`Dismiss`,className:`rounded-sm px-0.5 text-2xs text-red-300/70 hover:text-red-100`,children:`✕`})]})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(npn,{iframeRef:o,activeCompositionPath:a}),(0,W.jsx)(ohn,{}),(0,W.jsx)(sfn,{activeCompositionPath:a,showHoverSelection:!f&&!c&&!l,shouldShowSelectedDomBounds:t,isGestureRecording:r}),(0,W.jsx)(ahn,{}),!d&&(0,W.jsx)(ihn,{iframeRef:o,selection:e?v:null,compositionSize:u,isPlaying:l}),i,p&&m&&(0,W.jsx)(`button`,{type:`button`,onClick:_,className:`pointer-events-auto absolute top-2 left-1/2 -translate-x-1/2 z-60 rounded-full border border-neutral-700 bg-black/60 px-2.5 py-1 text-2xs text-neutral-300 transition-colors hover:border-studio-accent/50 hover:text-accent-ink focus-visible:outline-solid focus-visible:outline-1 focus-visible:outline-studio-accent`,children:`Edit captions`})]})}function phn(e,t,n){if(n===`opacity`&&t.getAttribute(`data-hf-color-grading-source-hidden`)!=null&&t.id){let e=t.ownerDocument.getElementById(je+t.id),n=t.ownerDocument.defaultView;if(e&&n){let t=Number(n.getComputedStyle(e).opacity);if(Number.isFinite(t))return t}}return Number(e.getProperty(t,n))}function mhn(e,t,n){if(!t)return null;let r=pJ(e);if(!r)return null;let i=mJ(e,t);if(!i)return null;try{let e=phn(r,i,n);return Number.isFinite(e)?hhn.has(n)?Math.round(e):S(e):null}catch{return null}}var hhn=new Set([`x`,`y`,`xPercent`,`yPercent`]);function ghn(e,t,n,r){let i={};if(!e)return i;let a=pJ(e);if(!a)return i;let o=mJ(e,t);if(!o)return i;let s=null;try{s=e?.contentDocument??null}catch{}let c=new Set;if(n.keyframes)for(let e of n.keyframes.keyframes)for(let t of Object.keys(e.properties))typeof e.properties[t]==`number`&&c.add(t);else for(let e of Object.keys(n.properties))c.add(e);let l=e=>!r||DT(e)===r,u=new Set([...c].filter(l));for(let e of u){let t=phn(a,o,e);Number.isFinite(t)&&(i[e]=hhn.has(e)?Math.round(t):S(t))}let d=[`borderRadius`,`borderTopLeftRadius`,`borderTopRightRadius`,`borderBottomLeftRadius`,`borderBottomRightRadius`,`letterSpacing`,`wordSpacing`,`lineHeight`,`fontSize`,`outlineOffset`,`outlineWidth`,`strokeDashoffset`,`strokeWidth`,`backgroundPositionX`,`backgroundPositionY`],f=null;try{f=s?.defaultView?.getComputedStyle(o)??null}catch{}for(let e of d){if(e in i||!l(e)||R0(o,[e]))continue;let t=Number(a.getProperty(o,e));if(!Number.isFinite(t))continue;let n=NaN;if(f){let t=f.getPropertyValue(e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`));n=parseFloat(t)}Number.isFinite(n)&&Math.round(t*1e3)===Math.round(n*1e3)||(i[e]=S(t))}return i}function _hn(e,t,n){return[...vhn(e).filter(e=>Math.abs(e.percentage-t)>nJ).map(e=>({percentage:e.percentage,properties:{...e.properties},...e.ease?{ease:e.ease}:{}})),{percentage:t,properties:n}].sort((e,t)=>e.percentage-t.percentage)}function vhn(e){let t=Hq(e);return(e.keyframes?.keyframes??[]).map(e=>({...e,percentage:S(qq(t,e.percentage))}))}function yhn(e,t,n,r=Zq(e),i=Hq(e)){let a=Xq(e)??0,o=r,s=Math.min(a,t),c=Math.max(a+o,t),l=S(c-s),u=Hq(e),d=e=>{if(l<=0)return 0;let t=Kq(i,(e-s)/l*100);return Math.max(0,Math.min(100,Math.round(t*10)/10))},f=(e.keyframes?.keyframes??[]).map(e=>({percentage:d(a+qq(u,e.percentage)/100*o),properties:e.properties,...e.ease?{ease:e.ease}:{}})),p={percentage:d(t),properties:n},m=[...f,p].sort((e,t)=>e.percentage-t.percentage);return{position:S(s),duration:l,keyframes:m}}function bhn(e,t,n,r,i,a){if(t.arcPath?.enabled)return{status:`persisted`};let{newX:o,newY:s,baseGsapX:c,baseGsapY:l}=D3(e.element,n,r),u=Lmn(e,t,{x:o,y:s},i,{backfill:{x:c,y:l},moment:a});return u.ok?{status:`persisted`}:{status:`blocked`,reason:`keyframes-uneditable`,detail:u.reason}}async function xhn(e,t,n,r,i,a){let o=e.element,s=a.stamp??T3(o),{newX:c,newY:l,baseGsapX:u,baseGsapY:d}=D3(o,n,r,s),f=()=>O3(o,s);if(t.arcPath?.enabled){let{keyframePct:n,time:r}=e6(s),{setActiveKeyframePct:i}=X.getState(),o=Xq(t),u=Zq(t);if(n===null&&o!==null&&!Yq(r,o,u)){let n=yhn(t,r,{x:c,y:l},u,`none`);return await a.commitMutation(e,{type:`replace-with-keyframes`,animationId:t.id,targetSelector:t.targetSelector,...n,ease:`none`},{label:`Move layer (new keyframe)`,keyframeAction:`add`,softReload:!0,beforeReload:f}),{status:`persisted`}}let d=n??_8(e,t,r),p=t.keyframes?.keyframes??[],m=p.findIndex(e=>rJ(t,e.percentage,d));if(m>=0)return await a.commitMutation(e,{type:`update-motion-path-point`,animationId:t.id,pointIndex:m,x:c,y:l},{label:`Move layer (waypoint)`,softReload:!0,beforeReload:f}),i(null),v8(t,d),{status:`persisted`};if(o===null||u<=0||p.length<2)return{status:`persisted`};let h=_hn(t,S(qq(Hq(t),d)),{x:c,y:l});return await a.commitMutation(e,{type:`replace-with-keyframes`,animationId:t.id,targetSelector:t.targetSelector,position:S(o),duration:S(u),keyframes:h,ease:`none`},{label:`Move layer (new keyframe)`,keyframeAction:`add`,softReload:!0,beforeReload:f}),{status:`persisted`}}return A8(e,t,{x:c,y:l},i,{...a,stamp:s},{label:`Move layer`,backfill:{x:u,y:d},beforeReload:f})}function N8(e,t,n){let r=new Set;return t.id&&r.add(`#${t.id}`),t.selector&&r.add(t.selector),r.size===0&&!n?[]:e.filter(e=>e.targetSelector.split(`,`).some(e=>{let t=e.trim();if(!t)return!1;if(r.has(t))return!0;let i=t.split(/\s+/).pop();if(i&&r.has(i))return!0;if(n)try{if(n.matches(t))return!0}catch{return!1}return!1}))}var Shn=new Set(L0),P8=new Set(z0);async function F8(e,t,n,r,i,a){let o=t=>{let n=t.filter(t=>t.propertyGroup===e),r=new Set(jrt[e]),i=t.filter(e=>!e.propertyGroup&&u8(e,r));return C8(n.length>0?n:i,a)},s=o(t);if(s)return{anim:s,animations:t};if(!i)return null;let c=await i(),l=o(c);return l?{anim:l,animations:c}:null}var Chn=e=>u8(e,Shn);function whn(e,t){let n=t.filter(Chn);return n.some(t=>D8(t,e.element)===`shared`)&&O8(e,n).length===0}async function Thn(e,t,n,r,i){return Ehn(e,t,n,r?await r():[],i)}function Ehn(e,t,n,r=[],i=!1){let a=sJ(e);if(!a)return{status:`blocked`,reason:`no-selector`};let o=[...t,...r],s=d8(o.filter(t=>D8(t,e.element)!==`elsewhere`),Shn);if(s.status===`blocked`)return s;if(whn(e,o))return{status:`element-offset`};let c=O8(e,r.length>0?r:t),l=S8(i?N8(c,{id:e.id??null,selector:a}):c,a);return I0(n,a,void 0,L0)&&!l?{status:`blocked`,reason:`source-uneditable`,detail:`live-position-no-source-tween`}:!l&&!lJ(e)?{status:`blocked`,reason:`no-selector`}:{status:`persisted`}}var Dhn=0;function Ohn(e){if(Fpn(e))return e;let t=`gsap:drag:${++Dhn}`;return(n,r,i)=>e(n,r,{...i,coalesceKey:t,coalesceMs:1/0})}var khn=e=>t=>t.targetSelector===e&&$j(t);function Ahn(e,t){let n=e.filter(khn(t));return n.length<2||n.filter(e=>!tJ(e)).length>1?null:n.find(e=>e.keyframes)??n.find(e=>(e.duration??0)>0)??n[0]}function jhn(e,t,n,r){let i=I0(t,n,void 0,L0),a=!!e?.keyframes&&Zq(e)>0;return!i&&!a?`static`:r||!X.getState().autoKeyframeEnabled?`whole-path`:`at-playhead`}async function Mhn(e,t,n,r,i,a){let o=sJ(e);if(!o)return{status:`blocked`,reason:`no-selector`};let s=O8(e,n),c=Ahn(s,o),l=c?s.filter(e=>e===c||!khn(o)(e)):s,u=(await F8(`position`,l,e,async()=>{},void 0,a.time))?.anim??S8(l,o,a.time),d=jhn(u,r,o,i.altKey);if(d===`static`)return{status:`persisted`};if(!u)return{status:`blocked`,reason:`source-uneditable`,detail:`no-position-tween`};if(d===`whole-path`){let e=$pn(u);return e?{status:`blocked`,reason:`keyframes-uneditable`,detail:e}:{status:`persisted`}}return bhn(e,u,t,x8(r,o)??{x:0,y:0},r,a)}async function I8(e,t,n,r,i,a,o){let s=o?.stamp??T3(e.element),c=e6(s),l=c.time;if(!o?.preflightPassed){let i=await Thn(e,n,r,a,o?.group);if(i.status!==`persisted`)return i;if(o?.preflightOnly)return o.group?Mhn(e,t,n,r,o,c):i}let u=O8(e,n),d=a&&(async()=>O8(e,await a())),f=sJ(e);if(!f)return{status:`blocked`,reason:`no-selector`};let p=Ohn(i),m=u;if(u.filter(khn(f)).length>1&&d){let t=await d(),n=Ahn(t,f);n?(await p(e,{type:`consolidate-position-writes`,targetSelector:f,keepAnimationId:n.id},{label:`Consolidate position writes`,skipReload:!0}),m=await d()):m=t}let h=await F8(`position`,m,e,p,d,l),g=h?.anim??null,_=h?.animations??m;if(!g&&(g=S8(m,f,l),!g&&d)){let e=await d();_=e,g=S8(e,f,l)}let v=x8(r,f)??{x:0,y:0},y=jhn(g,r,f,o?.altKey);if(y===`static`)return await tmn(e,t,v,f,g&&tJ(g)&&g.targetSelector===f?g:Kpn(_,f,e.element),{commitMutation:p,fetchAnimations:d,stamp:o?.stamp}),{status:`persisted`};if(!g)return{status:`blocked`,reason:`source-uneditable`,detail:`no-position-tween`};if(d){let e=await d(),t=e.find(e=>e.id===g.id)??C8(e.filter(e=>e.targetSelector===g.targetSelector&&e.propertyGroup===g.propertyGroup&&$j(e)===$j(g)),l);t&&t.id!==g.id&&(g=t)}let b={commitMutation:p,fetchAnimations:d,stamp:s};if(y===`whole-path`)await imn(e,g,t,v,r,f,b);else return xhn(e,g,t,v,r,b);return{status:`persisted`}}function Nhn(e,t,n,r=[]){let i=sJ(e);if(!(i??lJ(e)))return{status:`blocked`,reason:`no-selector`};let a=d8([...t,...r],P8);return a.status===`blocked`?a:!(t.length>0?t:r).some(e=>u8(e,P8))&&i&&I0(n,i,void 0,z0)?{status:`blocked`,reason:`source-uneditable`,detail:`live-rotation-no-source-tween`}:{status:`persisted`}}async function Phn(e,t,n,r,i,a,o){let s=e6(o).time,c=a?await a():[],l=Nhn(e,n,r,c);if(l.status===`blocked`)return l;let u=sJ(e)??lJ(e),d=n.length>0?n:c,f=await F8(`rotation`,d,e,i,d.some(e=>!e.propertyGroup)?a:void 0,s),p=f?.animations??d,m=f?.anim&&u8(f.anim,P8)?f.anim:null;m||=C8(d.filter(e=>u8(e,P8)),s);let h=S(t);if(!m||tJ(m))return await nmn(e,h,u,m??qpn(p,u,e.element),{commitMutation:i,fetchAnimations:a}),{status:`persisted`};let g=_8(e,m,s);return X.getState().autoKeyframeEnabled?A8(e,m,{rotation:h},r,{commitMutation:i,fetchAnimations:a,stamp:o},{label:`Rotate`,backfill:{rotation:h},holdFromStart:!0}):(await j8(e,m,{rotation:h},g,r,{commitMutation:i,fetchAnimations:a},`Rotate animation`),{status:`persisted`})}function Fhn(e){return typeof e==`object`&&!!e&&`animations`in e&&Array.isArray(e.animations)}var L8=new Map,Ihn=(e,t)=>`${e}|${t}`;function R8(e,t,n={}){let r=Ihn(e,t);n.fresh&&L8.delete(r);let i=L8.get(r);if(i)return i;let a=Lhn(e,t).finally(()=>{L8.get(r)===a&&L8.delete(r)});return L8.set(r,a),a}async function Lhn(e,t){if(!WNe(e)&&!await ix(e))return null;try{let n=await H(`/api/projects/${encodeURIComponent(e)}/gsap-animations/${encodeURIComponent(t)}`,{cache:`no-cache`});if(!n.ok)return null;let r=await n.json();return Fhn(r)?{...r,animations:r.animations.filter(e=>!dVe(e))}:null}catch{return null}}async function Rhn(e,t,n){let r=await R8(e,t);if(!r)return!1;let{elements:i,domClipChildren:a}=X.getState(),o=new Map,s=new Map;for(let e of r.animations){if(e.hasUnresolvedKeyframes||_J(e))continue;let r=e.keyframes??yJ(e);if(r)for(let c of aJ(e.targetSelector,n)){s.set(c,[...s.get(c)??[],e]);let{elStart:n,elDuration:l}=hJ(c,t,i,a),u=gJ(r.keyframes,e,n,l),d=o.get(c);d?d.keyframes=vJ([...d.keyframes,...u]):o.set(c,{...r,keyframes:u})}}return fpn(t,o,s),!0}function zhn(e,t,n,r,i){let[a,o]=(0,U.useState)([]),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),d=(0,U.useRef)(``),f=X(e=>e.domClipChildren.map(e=>`${e.id}<${e.hostId}`).join(`|`));(0,U.useEffect)(()=>{let i=`${e}:${t}:${r}:${n?.id??n?.selector??``}`;if(i===d.current)return;if(d.current=i,!e){o([]),c(!1),u(!1);return}let a=!1;return R8(e,t).then(e=>{if(!a){if(!e){o([]),c(!1),u(!1);return}o(e.animations),c(e.multipleTimelines===!0),u(e.unsupportedTimelinePattern===!0)}}),()=>{a=!0}},[e,t,r,n?.id,n?.selector]);let p=n?.id??null,m=n?.selector??null,h=(0,U.useMemo)(()=>{if(!p&&!m)return[];let e=n?un(i?.current?.contentDocument,n):null;return N8(a,{id:p,selector:m},e)},[a,n,r,i]),g=(0,U.useMemo)(()=>{let e=i?.current,t=h;if(e&&(t=t.map(t=>{if(!t.hasUnresolvedKeyframes||t.keyframes)return t;let n=F0(e,t.targetSelector);return n?{...t,keyframes:{format:`percentage`,keyframes:n.keyframes,...n.easeEach?{easeEach:n.easeEach}:{}},...n.arcPath?{arcPath:n.arcPath}:{}}:t})),e&&p&&t.length===0){let n=a.filter(e=>e.hasUnresolvedSelector);if(n.length>0&&F0(e,`#${p}`)){let r=Z9t(e),i=r.get(p);if(i){let e=Array.from(r.keys()).indexOf(p),a=e>=0&&e<n.length?n[e]:n[0];a&&(t=[{...a,targetSelector:`#${p}`,keyframes:{format:`percentage`,keyframes:i.keyframes,...i.easeEach?{easeEach:i.easeEach}:{}},...i.arcPath?{arcPath:i.arcPath}:{}}])}}}return t},[h,a,i,p]),_=n?.id??null;return(0,U.useEffect)(()=>{if(!_)return;let e=g.filter(e=>!_J(e)&&(e.keyframes||yJ(e)));e.length>0&&ppn(t,_,e);let{elements:n,domClipChildren:r}=X.getState(),{elStart:i,elDuration:a}=hJ(_,t,n,r),o=[],s=`percentage`,c,l;for(let e of g){if(_J(e))continue;let t=e.keyframes??yJ(e);t&&(o.push(...gJ(t.keyframes,e,i,a)),s=t.format,t.ease&&(c=t.ease),t.easeEach&&(l=t.easeEach))}if(o.length===0){let{keyframeCache:e}=X.getState();a8(t,_).some(t=>e.has(t))||cpn(t,_);return}let u=vJ(o),d={format:s,keyframes:u,...c?{ease:c}:{},...l?{easeEach:l}:{}};n8(e=>{for(let n of a8(t,_))e.keyframeCache.set(n,d)})},[_,t,g,f]),{animations:g,multipleTimelines:s,unsupportedTimelinePattern:l}}function Bhn(){let[e,t]=(0,U.useState)(0);return{version:e,bump:(0,U.useCallback)(()=>t(e=>e+1),[])}}function Vhn(e,t,n,r){let i=X(e=>e.elements.length),a=X(e=>Array.from(new Set(e.elements.map(e=>e.compositionSrc).filter(e=>!!e))).sort().join(`|`)),o=X(e=>e.domClipChildren.map(e=>`${e.id}<${e.hostId}`).join(`|`)),s=(0,U.useRef)({dataKey:``,files:new Set}),c=(0,U.useRef)(``);(0,U.useEffect)(()=>{let l=`kf-cache:${e}:${n}:${i}:${o}:${a}`;if(!e)return;let u=Array.from(new Set([t,...a?a.split(`|`):[]])),d=s.current.dataKey===l,f=d?u.filter(e=>!s.current.files.has(e)):u,p=d?new Set([...s.current.files,...u]):new Set(u);if(s.current={dataKey:l,files:p},d||upn(u),f.length===0)return;c.current=``;let m=r?.current?.contentDocument;for(let t of f)Rhn(e,t,m).then(e=>{!e&&s.current.dataKey===l&&s.current.files.delete(t)})},[e,t,n,i,o,a]),(0,U.useEffect)(()=>{if(!e)return;let i=t,a=0,o=()=>{if(c.current===`kf-cache:${e}:${i}:${n}`)return!0;let t=r?.current;if(!t)return!1;let a=new Map;for(let e of X.getState().elements)e.domId&&a.set(e.domId,{start:e.start,duration:e.duration});let o=Z9t(t,a);return o.size!==0&&(n8(e=>{for(let[t,n]of o){let r=a8(i,t);if(r.some(t=>e.keyframeCache.has(t))||n.keyframes.length===1&&Object.keys(n.keyframes[0].properties).every(e=>e===`x`||e===`y`))continue;let a={format:`percentage`,keyframes:n.keyframes,...n.easeEach?{easeEach:n.easeEach}:{}};for(let t of r)e.keyframeCache.set(t,a)}}),c.current=`kf-cache:${e}:${i}:${n}`,!0)};if(o())return;let s=setInterval(()=>{a++,(o()||a>=10)&&clearInterval(s)},500);return()=>clearInterval(s)},[e,t,n,r])}var Hhn=.1,Uhn=1e-4,Whn=.01,z8=e=>Math.round(e*1e3)/1e3,Ghn=(e,t,n)=>Math.max(t,Math.min(n,e));function Khn(e){let{keyframeCount:t,draggedTweenPct:n,tweenStart:r,tweenEnd:i,dropAbsTime:a}=e;if(t>0)return null;if(n!==0&&n!==100||Math.abs(a-(n===0?r:i))<=Uhn)return{kind:`noop`};let o=n===0?a:r,s=(n===100?a:i)-o;return s<Whn?{kind:`noop`}:{kind:`resize`,position:z8(o),duration:z8(s),pctRemap:[]}}function qhn(e){let{keyframes:t,draggedTweenPct:n,tweenStart:r,tweenDuration:i,dropAbsTime:a,runEase:o}=e;if(i<=0)return{kind:`noop`};let s=r+i,c=Khn({keyframeCount:t.length,draggedTweenPct:n,tweenStart:r,tweenEnd:s,dropAbsTime:a});if(c)return c;if(a>=r-Uhn&&a<=s+Uhn){let e=z8(Kq(o,Ghn((a-r)/i*100,0,100)));return Math.abs(e-n)<Hhn?{kind:`noop`}:{kind:`move`,toTweenPct:e}}if(t.length===0)return{kind:`noop`};let l=Math.min(a,r),u=Math.max(Whn,Math.max(a,s)-l),d=0,f=1/0;t.forEach((e,t)=>{let r=Math.abs(e.percentage-n);r<f&&(f=r,d=t)});let p=t.map((e,t)=>{let n=((t===d?a:r+qq(o,e.percentage)/100*i)-l)/u*100;return{from:e.percentage,to:z8(Kq(o,n))}});return{kind:`resize`,position:z8(l),duration:z8(u),pctRemap:p}}function Jhn(e,t,n){let r=t.find(t=>Math.abs(t.percentage-e)<.2);if(!r)return null;let i=r.animationId?n.find(e=>e.id===r.animationId):void 0;if(r.animationId)return i?{animId:i.id,tweenPct:r.tweenPercentage??e}:null;let a=r?.propertyGroup,o=a?n.filter(e=>e.propertyGroup===a):n.filter(e=>!e.propertyGroup),s=o.length===1?o[0]:void 0;return s?{animId:s.id,tweenPct:r.tweenPercentage??e}:null}function Yhn({handleTimelineElementMove:e,handleTimelineElementsMove:t,handleTimelineElementResize:n,handleTimelineGroupResize:r,handleToggleTrackHidden:i,setAudioGroupAttribute:o,handleBlockedTimelineEdit:s,handleTimelineElementSplit:c,handleRazorSplit:l,handleRazorSplitAll:u,handleFreezeFrame:d,handleLinkEdit:f,handleTimelineElementDeleteOnly:p,handleGroupClips:m,setElementFxAttribute:h}){let{projectId:g,activeCompPath:_}=FX(),{domEditSelection:v,selectedGsapAnimations:y}=jX(),{handleGsapRemoveKeyframe:b,handleGsapMoveKeyframeToPlayhead:x,handleGsapMoveKeyframe:S,handleGsapResizeKeyframedTween:C,handleGsapUpdateMeta:w,handleGsapAddKeyframe:T,handleGsapAddKeyframeBatch:E,handleGsapConvertToKeyframes:D,handleGsapRemoveAllKeyframes:O,buildDomSelectionForTimelineElement:k}=kX(),A=(0,U.useCallback)(e=>{let{gsapAnimations:t}=X.getState(),{sourceFile:n,domId:r}=re(e),i=n??_??`index.html`;for(let e of a8(i,r)){let n=t.get(e);if(n)return n}return[]},[_]),j=(0,U.useCallback)((e,t,n=y)=>{let r=t.propertyGroup!==void 0||t.tweenPercentage!==void 0||t.animationId!==void 0,i=X.getState().keyframeCache,a=i.get(e)??i.get(re(e).domId);return Jhn(t.percentage,r?[t]:a?.keyframes??[],n)},[y]),M=(0,U.useCallback)((e,t,n)=>{b(e,t,void 0,n)},[b]);return(0,U.useMemo)(()=>({onMoveElement:e,onMoveElements:t,onResizeElement:n,onResizeElements:r,onToggleTrackHidden:i,onSetAudioGroupAttributeLive:o.setLive,onSetAudioGroupAttributeQuiet:o.setQuiet,onRevertAudioGroupAttributeLive:o.revertLive,onGroupClips:m,onSetElementAttributeLive:h?.setLive,onSetElementAttributeQuiet:h?.setQuiet,onSetElementsAttributeQuiet:h?.setMany,onRevertElementAttributeLive:h?.revertLive,onBlockedEditAttempt:s,onSplitElement:c,onRazorSplit:l,onRazorSplitAll:u,onFreezeFrame:d,onLinkEdit:f,onDeleteElementOnly:p,onDeleteAllKeyframes:(e,t)=>{let n=a(e),r=A(n),i=t?r.filter(e=>e.id===t):r.filter(e=>e.keyframes);i.length!==0&&k(e).then(async e=>{if(!e)return;let t=!1;for(let n of i)t=await O(n.id,e,!1)||t;t&&T8(`remove_all`)})},onDeleteKeyframe:(e,t)=>{let n=A(e),r=j(e,t,n);if(!r)return;let i=X.getState().elements.find(t=>(t.key??t.id)===e);if(!i){M(r.animId,r.tweenPct);return}k(i).then(e=>{e&&M(r.animId,r.tweenPct,e)})},onMoveKeyframeToPlayhead:(e,t)=>{let n=a(e),r=A(n),i=j(n,t,r),o=i?r.find(e=>e.id===i.animId):void 0;!i||!o||k(e).then(e=>{e&&x(i.animId,i.tweenPct,e,o)})},onMoveKeyframe:async(e,t,n)=>{let r=A(e),i=j(e,t,r);if(!i)return!1;let a=X.getState().elements.find(t=>(t.key??t.id)===e),o=a?await k(a):v;if(!o)return!1;let s=r.find(e=>e.id===i.animId),c=s?Xq(s):null;if(!s||c===null)return Promise.resolve(!1);let l=o.sourceFile||_||`index.html`,{elements:u,domClipChildren:d}=X.getState(),{elStart:f,elDuration:p}=hJ(o.id??``,l,u,d),m=Zq(s),h=f+n/100*p,g=qhn({keyframes:s.keyframes?.keyframes??[],draggedTweenPct:i.tweenPct,tweenStart:c,tweenDuration:m,dropAbsTime:h,runEase:Hq(s)});return g.kind===`move`&&g.toTweenPct!=null?S(i.animId,i.tweenPct,g.toTweenPct,o):g.kind===`resize`&&g.pctRemap&&g.position!=null&&g.duration!=null?g.pctRemap.length===0?w(i.animId,{position:g.position,duration:g.duration},o):C(i.animId,g.position,g.duration,g.pctRemap,o):Promise.resolve(!1)},onToggleKeyframeAtPlayhead:e=>{let t=X.getState().currentTime,n=e.duration>0?Math.max(0,Math.min(100,Math.round((t-e.start)/e.duration*100))):0,r=A(a(e));k(e).then(e=>{if(!e)return;let t=r.find(e=>e.keyframes);if(t?.keyframes){let r=t.keyframes.keyframes.find(e=>Math.abs(e.percentage-n)<=1);r?b(t.id,r.percentage,void 0,e):T(t.id,n,`x`,0,e)}else{let t=r.find(e=>!e.keyframes);t&&D(t.id,void 0,void 0,void 0,e)}})},onTogglePropertyGroupKeyframe:async(e,t)=>{let n=await k(e);if(n){if(t.remove){M(t.animationId,t.tweenPercentage,n);return}await E(t.animationId,t.tweenPercentage,t.properties,void 0,n)}}}),[e,t,n,r,i,o,m,h,s,c,l,u,d,f,p,O,A,j,M,y,x,S,C,w,T,E,D,k,g,_,v])}var Xhn=[`#3CE6AC`,`#FF6B6B`,`#4ECDC4`,`#FFE66D`,`#A78BFA`,`#F472B6`,`#34D399`,`#FB923C`,`#60A5FA`,`#C084FC`],Zhn=32,Qhn=(0,U.memo)(function({pixelsPerSecond:e,onSeek:t}){let n=O1(e=>e.model),r=O1(e=>e.selectedSegmentIds),i=O1(e=>e.selectSegment),a=X(e=>e.currentTime),o=(0,U.useCallback)((e,t)=>{e.stopPropagation(),i(t,e.shiftKey)},[i]),s=(0,U.useCallback)((e,t)=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),i(t,e.shiftKey))},[i]),c=(0,U.useCallback)(n=>{if(!t)return;let r=n.currentTarget.getBoundingClientRect(),i=n.clientX-r.left-Zhn;t(Math.max(0,i/e))},[t,e]);if(!n)return null;let l=Zhn+a*e;return(0,W.jsxs)(`div`,{className:`relative select-none overflow-x-auto`,style:{height:40,minWidth:`100%`},onClick:c,children:[n.groupOrder.map((t,i)=>{let a=n.groups.get(t);if(!a)return null;let c=Xhn[i%Xhn.length];return a.segmentIds.map(t=>{let i=n.segments.get(t);if(!i)return null;let a=Zhn+i.start*e,l=Math.max((i.end-i.start)*e,4),u=r.has(t);return(0,W.jsx)(`div`,{role:`button`,tabIndex:0,"aria-label":`Caption word "${i.text}"`,"aria-pressed":u,className:`absolute top-1 bottom-1 rounded flex items-center overflow-hidden cursor-pointer focus-visible:ring-1 focus-visible:ring-text-0 outline-hidden${u?` ring-1 ring-text-0/50 z-10`:``}`,style:{left:a,width:l,backgroundColor:c,zIndex:u?10:1},onClick:e=>o(e,t),onKeyDown:e=>s(e,t),children:(0,W.jsx)(`span`,{className:`flex-1 truncate px-2 pointer-events-none`,style:{fontSize:9,color:`#000000`,lineHeight:1},children:i.text})},t)})}),(0,W.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px bg-text-0/70 pointer-events-none z-20`,style:{left:l},"aria-hidden":`true`})]})}),$hn=3;function egn(e,t){let n=[...e];return!t||!e.has(t)?n:[t,...n.filter(e=>e!==t)]}function tgn(e,t,n,r){let i=new Set(e),a=new Set(t);if(i.size!==a.size)return!1;for(let e of a)if(!i.has(e))return!1;return n===r}function ngn(e,t){return e!==null&&!t.includes(e)}async function rgn(e,t,n){let r=e.map(e=>t.find(t=>(t.key??t.id)===e)).filter(e=>!!e);return(await Promise.all(r.map(e=>n(e)))).filter(e=>!!e)}function ign(e,t,n){e.length===0?t(null,{revealPanel:!1}):e.length===1?t(e[0]):n(e,!1)}function agn({selectedElementId:e,selectedElementIds:t,timelineElements:n,domEditSelection:r,domEditGroupSelections:i,activeCompPath:a,buildDomSelectionForTimelineElement:o,applyDomSelection:s,applyMarqueeSelection:c,onSelectionNotFound:l}){let u=(0,U.useMemo)(()=>egn(t,e),[e,t]),d=u.join(`\0`),f=(0,U.useRef)(r),p=(0,U.useRef)(i),m=(0,U.useRef)(``),h=(0,U.useRef)(``),g=(0,U.useRef)({id:``,count:0});f.current=r,p.current=i,(0,U.useEffect)(()=>{let t=m.current;m.current=d;let r=f.current,i=p.current,_=(i.length>1?i:r?[r]:[]).map(e=>$Q(e,n,a)).filter(e=>!!e),v=r?$Q(r,n,a):null;if(u.length===0){h.current=``,g.current={id:``,count:0},K4(`timeline-empty`,{had:_.length,previousKey:t.length>0,clearing:t.length>0&&_.length>0}),t.length>0&&_.length>0&&s(null,{revealPanel:!1});return}if(tgn(_,u,v,e)){h.current=``;return}let y=!1,b=()=>{h.current!==d&&(h.current=d,l())};return(async()=>{let e=await rgn(u,n,o);if(!y){if(e.length<u.length){if(DYt(g,d,$hn)){ngn(v,u)&&s(null,{revealPanel:!1,announce:!1});return}b()}else g.current={id:``,count:0},h.current=``;K4(`timeline-sync`,{wanted:u.length,had:_.length,resolved:e.length}),ign(e,s,c)}})(),()=>{y=!0}},[a,s,c,o,l,e,u,d,n])}function ogn(e){return typeof e!=`object`||!e?!1:typeof Reflect.get(e,`registerTool`)==`function`}function sgn(e=document){let t=Reflect.get(e,`modelContext`);return ogn(t)?t:null}var cgn=o2(`webmcp`),B8=null;async function lgn(){try{await Mb(()=>import(`./dist-DFhRmUKu.js`),[]);let e=sgn();return e?hY(`webmcp.polyfill_loaded`):(cgn(`polyfill`,{loaded:!0,modelContext:!1}),hY(`webmcp.polyfill_failed`,{error_name:`ModelContextMissingError`})),e}catch(e){return cgn(`polyfill`,{failed:e instanceof Error?e.message:String(e)}),hY(`webmcp.polyfill_failed`,{error_name:e instanceof Error?e.name:`NonError`}),null}}function ugn(){if(B8)return B8;let e=lgn();return B8=e,e.then(t=>{t===null&&B8===e&&(B8=null)}),B8}var dgn=/^[A-Za-z0-9_.-]{1,128}$/;function fgn(e){return dgn.test(e.name)?e.description.trim()?null:`description must not be empty`:`name must be 1-128 chars of A-Z a-z 0-9 _ - . (got ${JSON.stringify(e.name)})`}function pgn(e){return e instanceof DOMException&&e.name===`AbortError`}function mgn(e,t){return{tool:e,name:`InvalidStateError`,message:t}}async function hgn(e,t,n){let r=fgn(t);if(r)return{status:`failed`,failure:mgn(t.name,r)};try{return await e.registerTool(t,{signal:n}),{status:`registered`}}catch(e){return pgn(e)?{status:`aborted`}:{status:`failed`,failure:{tool:t.name,name:e instanceof DOMException?e.name:`Error`,message:e instanceof Error?e.message:String(e)}}}}async function ggn(e,t,n){let r={registered:[],failed:[]},i=new Set;for(let a of t){if(i.has(a.name)){r.failed.push(mgn(a.name,`duplicate tool name in this registration set`));continue}i.add(a.name);let t=await hgn(e,a,n);if(t.status===`aborted`)return r;t.status===`failed`?r.failed.push(t.failure):r.registered.push(a.name)}return r}async function _gn(e,t){if(typeof t!=`string`||!t.trim())return q6(`invalid`,`handle must be a non-empty string`,`Call studio_look first.`);if(!gfn(t,e.getProjectId()))return q6(`invalid`,`the handle belongs to a different project`,`Call studio_look in the active project.`);let n=await _fn(e.getPreviewDocument,t,e.buildSelection);if(n.status===`preview-unavailable`)return q6(`blocked`,`the preview is not mounted yet`,`Wait for the composition to load, then retry.`);if(n.status===`not-found`)return q6(`invalid`,`no element matches handle ${t}`,`The composition may have changed. Call studio_look for current handles.`);if(n.status===`unsupported`)return q6(`blocked`,`${t} resolved to an element Studio cannot select`,`Try a parent or child element from studio_look.`);if(n.status===`changed`)return q6(`invalid`,`the target changed while it was resolving`,`Call studio_look again.`);let{selection:r}=n;return e.applySelection(r),K6({handle:t,label:r.label,tagName:r.tagName,box:r.boundingBox})}function vgn(e,t){if(typeof t!=`number`||!Number.isFinite(t))return q6(`invalid`,`time must be a finite number of seconds`);let n=e.readPlayhead();e.requestSeek(t);let r=e.readPlayhead(),i=r.currentTime!==n.currentTime;return!i&&n.currentTime!==t?q6(`blocked`,`the playhead did not move; it is still at ${r.currentTime}`,`The preview may not be ready. Check studio_look, then retry.`):K6({playhead:r.currentTime,duration:r.duration,isPlaying:r.isPlaying,moved:i})}var ygn={type:`object`,properties:{handle:{type:`string`,description:`An element handle from studio_look.`}},required:[`handle`],additionalProperties:!1},bgn=[`Select an element in HyperFrames Studio, exactly as clicking it would:`,`the human sees the same selection box and inspector.`,`Call this before the first write to a target so the human sees the agent's intent.`,`Takes a handle from studio_look. Selection is visual context for the human;`,`element writes take their own explicit handle and do not require this tool first.`,"Returns `ok: true` with the resulting selection, or `ok: false` with `kind`, `reason` and a `hint`."].join(` `),xgn={type:`object`,properties:{time:{type:`number`,minimum:0,description:`Playhead position in seconds.`}},required:[`time`],additionalProperties:!1},Sgn=[`Move the playhead to a time in seconds. Pauses playback.`,"Out-of-range times are clamped by the player, so check the returned `playhead`",`for where it actually landed rather than assuming it matched your request.`,"Returns `ok: true`, or `ok: false` with `kind`, `reason` and a `hint`."].join(` `);function Cgn(e){return e&&e!==`master`?e:`index.html`}function wgn({projectId:e,compositionPath:t,currentTime:n,origin:r=window.location.origin,version:i=Date.now()}){let a=Cgn(t),o=new URL(M(e,`/thumbnail/${encodeURIComponent(a)}`),r);return o.searchParams.set(`t`,Math.max(0,n).toFixed(3)),o.searchParams.set(`format`,`png`),o.searchParams.set(`output`,`source`),o.searchParams.set(`v`,String(i)),o.toString()}function Tgn(e,t){return`${Cgn(e).split(`/`).pop()?.replace(/\.html$/i,``)||`frame`}-${Math.max(0,t).toFixed(3).replace(`.`,`-`)}s.png`}var Egn=150,Dgn=5e3;async function Ogn(e,t={}){let n=e.getProjectId();if(!n)return q6(`blocked`,`no project is open`);if(t.time!==void 0){if(typeof t.time!=`number`||!Number.isFinite(t.time)||t.time<0)return q6(`invalid`,`time must be a non-negative, finite number of seconds`);e.requestSeek(t.time)}let r=kgn(t.settleMs);r>0&&await e.wait(r);let{currentTime:i}=e.readPlayhead(),a=e.getCompositionPath(),o=wgn({projectId:n,compositionPath:a,currentTime:i}),s=await e.probeFrame(o);return s.ok?K6({url:o,time:i,compositionPath:a??`index.html`,settledMs:r}):q6(`failed`,`the renderer returned ${s.status} for this frame`,"The composition may not build. Try `hyperframes check`.")}function kgn(e){return e===void 0||typeof e!=`number`||!Number.isFinite(e)||e<0?Egn:Math.min(e,Dgn)}var Agn={type:`object`,properties:{time:{type:`number`,minimum:0,description:`Seconds. Omit to capture wherever the playhead already is.`},settleMs:{type:`integer`,minimum:0,maximum:Dgn,description:`Wait this long before capturing so a just-made edit is included. Default ${Egn}.`}},additionalProperties:!1},jgn=[`Render the composition to a PNG at a given time and return its URL, so you can`,`SEE the result instead of inferring it from source. Use this to judge a change:`,`edit, capture the instant it affects, look, adjust.`,`The frame is rendered from the file on disk, not the live preview.`,`A capture taken immediately after an edit can therefore predate that edit, because`,`the render cache is cleared by a file watcher. The tool waits briefly to cover that;`,"raise `settleMs` if a frame still looks stale, rather than concluding the edit failed.","Returns `ok: true` with `url` and the `time` actually captured, or `ok: false`."].join(` `);function Mgn(e){return{animationId:e.id,method:e.method,target:e.targetSelector,position:e.position,duration:e.duration??null,ease:e.ease??null,properties:e.properties,hasKeyframes:e.keyframes!==void 0,hasArcPath:e.arcPath!==void 0}}function Ngn(e,t){return e?t.multipleTimelines?`this composition has multiple GSAP timelines`:t.unsupportedTimelinePattern?`this composition's timeline pattern is not editable by Studio`:null:`animations are only readable for the current selection`}function Pgn(e,t,n,r){let{capabilities:i}=e,a=t.getGsapDiagnostics(),o=n?a.animations.map(Mgn):[],s=Ngn(n,a);return K6({handle:r??U6(W6(e,t.getCompositionPath()??`index.html`,t.getProjectId())),label:e.label,tagName:e.tagName,sourceFile:e.sourceFile,box:e.boundingBox,text:e.textContent,textFields:e.textFields.map(e=>({key:e.key,label:e.label,value:e.value,tagName:e.tagName})),styles:e.computedStyles,inlineStyles:e.inlineStyles,dataAttributes:e.dataAttributes,can:{editStyles:i.canEditStyles,move:i.canMove||i.canApplyManualOffset,resize:i.canResize||i.canApplyManualSize,rotate:i.canApplyManualRotation,crop:i.canCrop,editText:e.textFields.length>0,reasonIfDisabled:i.reasonIfDisabled??null},animations:o,animationEditingBlocked:s,isCurrentSelection:n})}async function Fgn(e,t={}){let n=e.getCurrentSelection();if(!t.handle)return n?Pgn(n,e,!0):q6(`invalid`,`nothing is selected and no handle was given`,`Pass a handle from studio_look, or call studio_select first.`);if(!gfn(t.handle,e.getProjectId()))return q6(`invalid`,`the handle belongs to a different project`,`Call studio_look in the active project.`);let r=await _fn(e.getPreviewDocument,t.handle,e.buildSelection);return r.status===`preview-unavailable`?q6(`blocked`,`the preview is not mounted yet`):r.status===`not-found`?q6(`invalid`,`no element matches handle ${t.handle}`,`Call studio_look for current handles.`):r.status===`unsupported`?q6(`blocked`,`${t.handle} resolved to an element Studio cannot inspect`):r.status===`changed`?q6(`invalid`,`the target changed while it was resolving`,`Call studio_look again.`):Pgn(r.selection,e,n?.element===r.selection.element,t.handle)}var Ign={type:`object`,properties:{handle:{type:`string`,description:`An element handle from studio_look. Omit to inspect the current selection.`}},additionalProperties:!1},Lgn=[`Everything about one element: its resolved styles, its text fields, its box,`,`its GSAP animations, and crucially what it will and will not accept.`,"Read this BEFORE editing. `can` tells you which edits are possible and","`can.reasonIfDisabled` says why one is not, so you can avoid a write that would be refused.","Animations are only readable for the CURRENT selection; `animationEditingBlocked` says when",`and why animation editing is unavailable.`,"Returns `ok: true`, or `ok: false` with `kind`, `reason` and a `hint`."].join(` `),Rgn={"no-selection":{kind:`invalid`,hint:`Call studio_select first.`},"no-project":{kind:`blocked`},"geometry-property":{kind:`blocked`,hint:`Position and size are not editable as styles. Use the transform tools.`},"styles-not-editable":{kind:`blocked`,hint:`studio_inspect reports why, in can.reasonIfDisabled.`},"not-text-editable":{kind:`blocked`,hint:`This element has no editable text. studio_inspect lists its textFields.`},"persist-failed":{kind:`failed`,hint:`The write did not reach the file. Check Studio.`}};function zgn(e,t){if(e.ok)return null;let n=Rgn[e.reason]??{kind:`failed`};return q6(n.kind,`${t} was not applied: ${e.reason}`,n.hint)}async function Bgn(e,t,n=new AbortController().signal){if(typeof t.text!=`string`)return Kgn(`set-text`,q6(`invalid`,`text must be a string`));let r=t.text,i=typeof t.field==`string`&&t.field?t.field:void 0,a;return Q6(e,{handle:t.handle,operation:`set-text`,signal:n,preflight:e=>{let t=e.textFields;return i&&!t.some(e=>e.key===i)?q6(`invalid`,`this element has no text field "${i}"`,`Its fields are: ${t.map(e=>e.key).join(`, `)||`none`}.`):(a=i??(t.length===1?t[0]?.key:void 0),a?null:t.length===0?q6(`blocked`,`this element has no editable text field`,`studio_inspect lists an element's textFields.`):q6(`invalid`,`this element has ${t.length} text fields, so one must be named`,`Pass field as one of: ${t.map(e=>e.key).join(`, `)}.`))},write:async t=>{let n=t.element.textContent,i=await e.setText(t,r,a);if(!i.ok)return zgn(i,`the text`);let o={text:r,changed:t.element.textContent!==n};return i.persistence?Tfn(o,i.persistence):$6(o,o.changed)}})}async function Vgn(e,t,n=new AbortController().signal){let r=t.styles;if(typeof r!=`object`||!r||Array.isArray(r))return Kgn(`set-style`,q6(`invalid`,`styles must be an object of CSS property to value`));let i=Object.entries(r).filter(e=>typeof e[1]==`string`);return i.length===0?Kgn(`set-style`,q6(`invalid`,`styles must contain at least one string value`)):Q6(e,{handle:t.handle,operation:`set-style`,signal:n,preflight:e=>e.capabilities.canEditStyles?null:q6(`blocked`,`this element's styles are not editable`,`studio_inspect reports why, in can.reasonIfDisabled.`),write:async t=>{let n={},r={},a={},o=null;for(let[s,c]of i){let i=await e.setStyle(t,s,c);if(!i.ok){r[s]=i.reason;continue}n[s]=c;let l=i.persistence?Tfn({},i.persistence):$6({},!0);a[s]={stage:l.stage,changed:l.changed,evidence:l.evidence},(!o||o.stage!==`dispatched`)&&(o=l)}if(!o)return q6(`blocked`,`no style was applied (${Object.entries(r).map(([e,t])=>`${e}: ${t}`).join(`, `)})`);let s={applied:n,rejected:r,partial:Object.keys(r).length>0,propertyReceipts:a},c=Object.values(a).some(e=>e.changed);return o.stage===`dispatched`?$6(s,c):{...o,...s,changed:c}}})}var Hgn={type:`object`,properties:{handle:{type:`string`,description:`A source-safe element handle from studio_look.`},text:{type:`string`,description:`The new text content.`},field:{type:`string`,description:`Which text field to write, from studio_inspect. Omit for the element's own text.`}},required:[`handle`,`text`],additionalProperties:!1},Ugn=[`Set one element's text using its source-safe handle from studio_look.`,`This is the edit a synthetic double-click cannot reach, because Studio's canvas`,`takes pointer capture and recognises the double press itself.`,"Returns `ok: true` with the resulting text and whether it changed, or `ok: false`","with `kind`, `reason` and usually a `hint` naming what to do instead.",Y6].join(` `),Wgn={type:`object`,properties:{handle:{type:`string`,description:`A source-safe element handle from studio_look.`},styles:{type:`object`,description:`CSS property to value, for example {"color": "red", "font-size": "48px"}.`,additionalProperties:{type:`string`}}},required:[`handle`,`styles`],additionalProperties:!1},Ggn=[`Set inline styles on one element using its source-safe handle from studio_look.`,`Each property is a separate commit, so N properties produce N undo entries.`,`Position and size properties (left, top, width, height) are refused here on purpose;`,`they belong to the transform tools.`,"Returns `ok: true` with `applied` and `rejected` maps, so a partial success is visible",`as a partial success rather than reported as a whole one.`,Y6].join(` `);function Kgn(e,t){return{...t,stage:`refused`,operation:e}}var qgn=`Move and rotate are written as GSAP code; a composition with no GSAP timeline has nothing to write to. studio_inspect reports the element's animations.`;function Jgn(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Ygn(e,t,n,r=-1/0){let i=Jgn(e),a=Jgn(t);return i===null&&a===null?{pair:null}:i===null||a===null?q6(`invalid`,`${n[0]} and ${n[1]} must be given together`):i<r||a<r?q6(`invalid`,`${n[0]} and ${n[1]} must be at least ${r}`):{pair:[i,a]}}function V8(e){return`ok`in e}function Xgn(e){let t=Ygn(e.x,e.y,[`x`,`y`]);if(V8(t))return t;let n=Ygn(e.width,e.height,[`width`,`height`],0);if(V8(n))return n;let r=Jgn(e.rotate);return!t.pair&&!n.pair&&r===null?q6(`invalid`,`give at least one of x, y, width, height, rotate as a finite number`):{move:t.pair?{x:t.pair[0],y:t.pair[1]}:null,size:n.pair?{width:n.pair[0],height:n.pair[1]}:null,rotate:r}}function Zgn(e,t){return e.size&&!t.capabilities.canResize&&!t.capabilities.canApplyManualSize?q6(`blocked`,`this target cannot be resized`):e.move&&!t.capabilities.canMove&&!t.capabilities.canApplyManualOffset?q6(`blocked`,`this target cannot be moved`):e.rotate!==null&&!t.capabilities.canApplyManualRotation?q6(`blocked`,`this target cannot be rotated`):null}async function Qgn(e,t,n){let r=e.readBox(t),i=await e.resizeTo(t,n);if(i&&!i.ok)return o_n(i.reason);let a=e.readBox(t),o=a.width!==r.width||a.height!==r.height;return{operation:`resize`,changed:o,...o?{}:{unchangedReason:`the element's size did not change`},...i?.ok&&i.persistence?{persistence:i.persistence}:{}}}async function $gn(e,t,n){let r=e.readBox(t),i=await e.moveTo(t,n);if(i&&!i.ok)return o_n(i.reason);let a=e.readBox(t),o=a.x!==r.x||a.y!==r.y;return{operation:`move`,changed:o,...o?{}:{unchangedReason:`the element did not move. ${qgn}`},...i?.ok&&i.persistence?{persistence:i.persistence}:{}}}async function e_n(e,t,n){let r=await e.rotateTo(t,{angle:n});return r&&!r.ok?o_n(r.reason):!r||!r.persistence?{operation:`rotate`,changed:!1,unchangedReason:`rotation was dispatched but not independently observed`}:r.persistence.changed?{operation:`rotate`,changed:!0,persistence:r.persistence}:{operation:`rotate`,changed:!1,unchangedReason:`the durable write reported no rotation change`,persistence:r.persistence}}function t_n(e,t){let n=!e.size||t.width===e.size.width&&t.height===e.size.height,r=!e.move||t.x===e.move.x&&t.y===e.move.y;return n&&r}function n_n(e,t,n,r,i){let a={box:n,applied:r.filter(e=>e.changed).map(e=>e.operation),unchanged:Object.fromEntries(r.flatMap(e=>e.unchangedReason?[[e.operation===`rotate`?`rotation`:e.operation,e.unchangedReason]]:[])),...i?{partial:!0,failed:{[i.operation]:i.reason}}:{}},o=r.some(e=>e.changed)||!a_n(t,n),s=r.every(e=>e.persistence!==void 0),c=r.at(-1)?.persistence;return!s||!c?$6(a,o):!i&&t_n(e,n)&&e.rotate===null?{...Efn(a,c,{before:t,after:n}),changed:o}:{...Tfn(a,c),changed:o}}async function r_n(e,t,n){let r=e.readBox(t),i=[];if(n.size){let r=await Qgn(e,t,n.size);if(V8(r))return r;i.push(r)}if(n.move){let a=await $gn(e,t,n.move);if(V8(a))return i.length===0?a:n_n(n,r,e.readBox(t),i,{operation:`move`,reason:a.reason});i.push(a)}if(n.rotate!==null){let a=await e_n(e,t,n.rotate);if(V8(a))return i.length===0?a:n_n(n,r,e.readBox(t),i,{operation:`rotate`,reason:a.reason});i.push(a)}return n_n(n,r,e.readBox(t),i)}async function i_n(e,t,n=new AbortController().signal){let r=Xgn(t);return V8(r)?{...r,stage:`refused`,operation:`transform`}:Q6(e,{handle:t.handle,operation:`transform`,signal:n,preflight:e=>Zgn(r,e),write:t=>r_n(e,t,r)})}function a_n(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function o_n(e){return q6(`failed`,`the transform was not applied: ${e}`)}var s_n={type:`object`,properties:{handle:{type:`string`,description:`A source-safe element handle from studio_look.`},x:{type:`number`,description:`New x offset in pixels. Must be paired with y.`},y:{type:`number`,description:`New y offset in pixels. Must be paired with x.`},width:{type:`number`,minimum:0,description:`New width. Must be paired with height.`},height:{type:`number`,minimum:0,description:`New height. Must be paired with width.`},rotate:{type:`number`,description:`Rotation in degrees.`}},required:[`handle`],additionalProperties:!1},c_n=[`Move, resize or rotate one element using its source-safe handle from studio_look.`,`Give x with y, and width with height.`,"The result's `box` is READ BACK after the write, not echoed from your request, and","`applied` lists what actually took effect. Check it.",`Move and rotate are written as GSAP code, so in a composition with no GSAP timeline they`,"do nothing; that shows up in `unchanged` rather than as a false success.","Rotation is reported as dispatched rather than verified, because the CSS `rotate` property",`does not appear in the element's computed transform.`,"Returns `ok: true`, or `ok: false` with `kind`, `reason` and a `hint`.",Y6].join(` `),l_n=[`to`,`from`,`set`,`fromTo`],H8=`Call studio_inspect to see the result.`;async function u_n(e,t,n){return(await e.getAnimationsForSelection(t)).some(e=>e.id===n)?null:q6(`invalid`,`animation ${n} does not belong to the target handle`,`Select the target, then call studio_inspect for its current animation ids.`)}function d_n(e){return typeof e==`string`&&e.trim()?e:null}function f_n(e){return typeof e==`string`&&e.startsWith(`__raw:`)}async function p_n(e,t,n=new AbortController().signal){let r=l_n.find(e=>e===t.method);return r?Q6(e,{handle:t.handle,operation:`add-animation`,signal:n,write:async t=>{let{currentTime:n}=e.readPlayhead();return await e.addAnimation(t,r)?$6({method:r,insertedAtSeconds:n,dispatched:!0},!1):q6(`failed`,`the animation did not land`,`The target may be stale. Call studio_look and try again with its current handle.`)}}):U8(`add-animation`,q6(`invalid`,`method must be one of ${l_n.join(`, `)}`))}async function m_n(e,t,n=new AbortController().signal){let r=d_n(t.animationId);if(!r)return U8(`update-animation`,q6(`invalid`,`animationId must be a non-empty string`,H8));let i={};if(typeof t.duration==`number`&&Number.isFinite(t.duration)){if(t.duration<0)return U8(`update-animation`,q6(`invalid`,`duration must not be negative`));i.duration=t.duration}return f_n(t.ease)?U8(`update-animation`,q6(`invalid`,`raw JavaScript expressions are not accepted`)):(typeof t.ease==`string`&&t.ease.trim()&&(i.ease=t.ease),typeof t.position==`number`&&Number.isFinite(t.position)&&(i.position=t.position),Object.keys(i).length===0?U8(`update-animation`,q6(`invalid`,`give at least one of duration, ease, position`)):Q6(e,{handle:t.handle,operation:`update-animation`,signal:n,preflight:t=>u_n(e,t,r),write:async t=>await e.updateAnimation(t,r,i)?$6({animationId:r,updated:i},!1):q6(`failed`,`the update to ${r} did not land`,`The animation id may be stale. studio_inspect lists the current ones.`)}))}async function h_n(e,t,n=new AbortController().signal){let r=d_n(t.animationId);if(!r)return U8(`add-keyframe`,q6(`invalid`,`animationId must be a non-empty string`,H8));let i=t.percent;if(typeof i!=`number`||!Number.isFinite(i)||i<0||i>100)return U8(`add-keyframe`,q6(`invalid`,`percent must be a number between 0 and 100`));let a=t.properties;if(typeof a!=`object`||!a||Array.isArray(a))return U8(`add-keyframe`,q6(`invalid`,`properties must be an object of GSAP property to value`));let o={};for(let[e,t]of Object.entries(a)){if(f_n(t))return U8(`add-keyframe`,q6(`invalid`,`raw JavaScript expressions are not accepted`));(typeof t==`number`||typeof t==`string`)&&(o[e]=t)}return Object.keys(o).length===0?U8(`add-keyframe`,q6(`invalid`,`properties must contain at least one number or string value`)):Q6(e,{handle:t.handle,operation:`add-keyframe`,signal:n,preflight:t=>u_n(e,t,r),write:async t=>(await e.addKeyframe(t,r,i,o),$6({animationId:r,percent:i,properties:o,dispatched:!0},!1))})}async function g_n(e,t,n=new AbortController().signal){let r=d_n(t.animationId);return r?Q6(e,{handle:t.handle,operation:`delete-animation`,signal:n,preflight:t=>u_n(e,t,r),write:async t=>await e.deleteAnimation(t,r)?$6({animationId:r,dispatched:!0},!1):q6(`failed`,`the delete of ${r} did not land`,`The animation id may be stale. studio_inspect lists the current ones.`)}):U8(`delete-animation`,q6(`invalid`,`animationId must be a non-empty string`,H8))}var __n=`Success means persistence and live-preview synchronization have finished. Inspect afterward when exact authored values matter.`,v_n=`Reports what was dispatched, not what landed: the keyframe actor does not report back. ${H8}`,y_n={type:`object`,properties:{handle:{type:`string`,description:`A source-safe element handle from studio_look.`},method:{type:`string`,enum:l_n,description:`The GSAP method to add.`}},required:[`handle`,`method`],additionalProperties:!1},b_n=[`Add a GSAP animation to one element using its source-safe handle from studio_look.`,`It is inserted AT THE PLAYHEAD, which this tool does not control: call studio_seek first`,`to choose when it starts. The result reports where the playhead actually was.`,__n,Y6].join(` `),x_n={type:`object`,properties:{handle:{type:`string`,description:`A source-safe element handle from studio_look.`},animationId:{type:`string`,description:`An animation id from studio_inspect.`},duration:{type:`number`,minimum:0,description:`Duration in seconds.`},ease:{type:`string`,description:`A GSAP ease, for example power2.out.`},position:{type:`number`,description:`Start position in seconds.`}},required:[`handle`,`animationId`],additionalProperties:!1},S_n=[`Change an existing animation's duration, ease or position.`,`It waits for persistence and live-preview synchronization before reporting success.`,`Get current ids from studio_inspect.`,Y6].join(` `),C_n={type:`object`,properties:{handle:{type:`string`,description:`A source-safe element handle from studio_look.`},animationId:{type:`string`,description:`An animation id from studio_inspect.`},percent:{type:`number`,minimum:0,maximum:100,description:`Where in the tween, 0 to 100.`},properties:{type:`object`,description:`GSAP property to value, for example {"y": -50, "opacity": 0}.`}},required:[`handle`,`animationId`,`percent`,`properties`],additionalProperties:!1},w_n=[`Add a keyframe to an existing animation at a percentage through it.`,`All the properties land in one commit, so they are one undo entry.`,v_n,Y6].join(` `),T_n={type:`object`,properties:{handle:{type:`string`,description:`A source-safe element handle from studio_look.`},animationId:{type:`string`,description:`An animation id from studio_inspect.`}},required:[`handle`,`animationId`],additionalProperties:!1},E_n=[`Remove an animation from the element named by handle. Undo reverses it.`,__n,Y6].join(` `);function U8(e,t){return{...t,stage:`refused`,operation:e}}var D_n=o2(`webmcp`);function O_n(e,t){D_n(`registered`,{native:t,...e});for(let t of e.failed)hY(`webmcp_registration_failed`,{error_name:t.name,tool_name:t.tool})}function k_n(e){let t=(t,n)=>(r,i)=>J6(t,()=>n(e.current,r,i?.signal));return[{name:`studio_look`,title:`Look at the composition`,description:Hfn,inputSchema:Vfn,annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:t=>J6(`studio_look`,async()=>Bfn(e.current.getSnapshot(),t))},{name:`studio_select`,title:`Select an element`,description:bgn,inputSchema:ygn,annotations:{readOnlyHint:!1,untrustedContentHint:!0},execute:t=>J6(`studio_select`,()=>_gn(e.current,A_n(t,`handle`)))},{name:`studio_seek`,title:`Move the playhead`,description:Sgn,inputSchema:xgn,annotations:{readOnlyHint:!1},execute:t=>J6(`studio_seek`,async()=>vgn(e.current,j_n(t,`time`)))},{name:`studio_frame`,title:`See the composition`,description:jgn,inputSchema:Agn,annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:t=>J6(`studio_frame`,()=>Ogn(e.current,t))},{name:`studio_inspect`,title:`Inspect one element`,description:Lgn,inputSchema:Ign,annotations:{readOnlyHint:!0,untrustedContentHint:!0},execute:t=>J6(`studio_inspect`,()=>Fgn(e.current,t))},{name:`studio_set_text`,title:`Set an element's text`,description:Ugn,inputSchema:Hgn,annotations:{readOnlyHint:!1,untrustedContentHint:!0},execute:t(`studio_set_text`,(e,t,n)=>Bgn(e,t,n))},{name:`studio_set_style`,title:`Set an element's styles`,description:Ggn,inputSchema:Wgn,annotations:{readOnlyHint:!1},execute:t(`studio_set_style`,(e,t,n)=>Vgn(e,t,n))},{name:`studio_transform`,title:`Move, resize or rotate`,description:c_n,inputSchema:s_n,annotations:{readOnlyHint:!1},execute:t(`studio_transform`,(e,t,n)=>i_n(e,t,n))},{name:`studio_add_animation`,title:`Add an animation`,description:b_n,inputSchema:y_n,annotations:{readOnlyHint:!1},execute:t(`studio_add_animation`,(e,t,n)=>p_n(e,t,n))},{name:`studio_update_animation`,title:`Change an animation`,description:S_n,inputSchema:x_n,annotations:{readOnlyHint:!1},execute:t(`studio_update_animation`,(e,t,n)=>m_n(e,t,n))},{name:`studio_add_keyframe`,title:`Add a keyframe`,description:w_n,inputSchema:C_n,annotations:{readOnlyHint:!1},execute:t(`studio_add_keyframe`,(e,t,n)=>h_n(e,t,n))},{name:`studio_delete_animation`,title:`Remove an animation`,description:E_n,inputSchema:T_n,annotations:{readOnlyHint:!1},execute:t(`studio_delete_animation`,(e,t,n)=>g_n(e,t,n))}]}function A_n(e,t){let n=Reflect.get(e,t);return typeof n==`string`?n:``}function j_n(e,t){let n=Reflect.get(e,t);return typeof n==`number`?n:NaN}function M_n(e){let t=(0,U.useRef)(e);t.current=e,(0,U.useEffect)(()=>{if(Ub().agentToolsEnabled===!1){D_n(`skipped`,{why:`disabled by preference`});return}let e=new AbortController;return(async()=>{let n=sgn();n&&hY(`webmcp.native_present`);let r=n??await ugn();if(!r){D_n(`skipped`,{why:`no model context, native or polyfilled`});return}e.signal.aborted||O_n(await ggn(r,k_n(t),e.signal),n!==null)})(),()=>e.abort()},[])}function N_n(e,t,n){let r=e?He(e,t,n):t.element;if(!r)throw Error(`the target is missing from the current Studio preview`);let i=r.getBoundingClientRect();return{x:i.x,y:i.y,width:i.width,height:i.height}}function P_n(e,t,n){let r=o3(e.element);return Een(e.element,t),n(e,t,void 0,()=>{d3(e.element,r)})}function F_n(){let{projectId:e,activeCompPath:t,editHistory:n,writeBlockedReason:r}=FX(),{domEditSelection:i,activeGroupElement:a,selectedGsapAnimations:o,gsapMultipleTimelines:s,gsapUnsupportedTimelinePattern:c}=jX(),{previewIframeRef:l,buildDomSelectionFromTarget:u,applyDomSelection:d,handleDomTextCommitForSelection:f,handleDomStyleCommitForSelection:p,handleDomPathOffsetCommit:m,handleDomBoxSizeCommit:h,handleDomRotationCommit:g,handleGsapAddAnimation:_,handleGsapUpdateMeta:v,handleGsapAddKeyframeBatch:y,handleGsapDeleteAnimation:b,getGsapAnimationsForSelection:x}=kX();(0,U.useEffect)(()=>(X6.activateProject(e),()=>X6.reset()),[e]);let S=(0,U.useCallback)(()=>{let r=X.getState();return{projectId:e,compositionPath:t,currentTime:r.currentTime,duration:r.duration,isPlaying:r.isPlaying,elements:r.elements,scene:Rfn(l.current?.contentDocument??null,t,a),selection:i,selectionAnimationCount:o.length,history:{canUndo:n.canUndo,canRedo:n.canRedo,undoLabel:n.undoLabel??null,redoLabel:n.redoLabel??null}}},[e,t,i,a,o,n,l]);return M_n((0,U.useMemo)(()=>({getSnapshot:S,getPreviewDocument:()=>l.current?.contentDocument??null,buildSelection:e=>u(e,{exactTarget:!0}),applySelection:e=>d(e,{revealPanel:!0}),requestSeek:e=>X.getState().requestSeek(e),readPlayhead:()=>{let e=X.getState();return{currentTime:e.currentTime,duration:e.duration,isPlaying:e.isPlaying}},getProjectId:()=>e,getCompositionPath:()=>t,probeFrame:async e=>{try{let t=await H(e,{method:`HEAD`});return{ok:t.ok,status:t.status}}catch{return{ok:!1,status:0}}},wait:e=>new Promise(t=>setTimeout(t,e)),getCurrentSelection:()=>i,getWriteBlockedReason:()=>r,setText:(e,t,n)=>f(e,t,n),setStyle:(e,t,n)=>p(e,t,n),readBox:e=>N_n(l.current?.contentDocument,e,t),moveTo:(e,t)=>m(e,t),resizeTo:(e,t)=>P_n(e,t,h),rotateTo:(e,t)=>g(e,t),addAnimation:(e,t)=>_(t,e),updateAnimation:(e,t,n)=>v(t,n,e),addKeyframe:(e,t,n,r)=>y(t,n,r,void 0,e),deleteAnimation:(e,t)=>b(t,e),getAnimationsForSelection:async e=>await x(e),getGsapDiagnostics:()=>({animations:o,multipleTimelines:s,unsupportedTimelinePattern:c})}),[S,l,u,d,e,t,r,f,p,m,h,g,_,v,y,b,x,i,o,s,c])),null}var I_n=16,L_n=64;function R_n(e){return e.closest(`.dv-split-view-container`)?.classList.contains(`dv-horizontal`)?`horizontal`:`vertical`}function z_n(e){for(let t of e.querySelectorAll(`.dv-sash`)){let e=R_n(t);t.tabIndex=0,t.setAttribute(`role`,`separator`),t.setAttribute(`aria-orientation`,e===`horizontal`?`vertical`:`horizontal`),t.setAttribute(`aria-label`,e===`horizontal`?`Resize columns`:`Resize rows`)}}function B_n(e,t,n){let r=e=>t===`horizontal`?{clientX:e,clientY:0}:{clientX:0,clientY:e},i=e.ownerDocument,a=(e,t,n)=>e.dispatchEvent(new MouseEvent(t,{...r(n),bubbles:!0,cancelable:!0}));a(e,`pointerdown`,0),a(i,`pointermove`,n),a(i,`pointerup`,n)}function V_n(e){return e.altKey||e.ctrlKey||e.metaKey}function H_n(e,t){if(V_n(e))return;let n=R_n(t),[r,i]=n===`horizontal`?[`ArrowLeft`,`ArrowRight`]:[`ArrowUp`,`ArrowDown`];if(e.key!==r&&e.key!==i)return;e.preventDefault();let a=e.shiftKey?L_n:I_n;B_n(t,n,e.key===i?a:-a)}function U_n(e,t,n){if(V_n(e))return;let r=[...t.closest(`[role="tablist"]`)?.querySelectorAll(`[role="tab"]`)??[]],i=r.indexOf(t),a=r.length-1,o=r[{ArrowRight:i===a?0:i+1,ArrowLeft:i===0?a:i-1,Home:0,End:a}[e.key]??-1];if(!o)return;e.preventDefault(),e.stopPropagation();let s=o.dataset.tabPanelId;s&&n.getPanel(s)?.api.setActive(),o.focus()}function W_n(e,t){let n=()=>z_n(t);n();let r=[e.onDidLayoutChange(n),e.onDidLayoutFromJSON(n),e.onDidAddPanel(n),e.onDidRemovePanel(n)],i=t=>{t.target instanceof HTMLElement&&(t.target.classList.contains(`dv-sash`)?H_n(t,t.target):t.target.getAttribute(`role`)===`tab`&&U_n(t,t.target,e))};return t.addEventListener(`keydown`,i,!0),()=>{t.removeEventListener(`keydown`,i,!0);for(let e of r)e.dispose()}}var W8=gb((e,t)=>({controller:null,panels:Rb,openPanels:new Set(Rb),visiblePanels:new Set(Rb),activePanel:null,lastActive:{},pendingActivation:null,attach:(t,n=Rb)=>e({controller:t,panels:n}),detach:()=>e({controller:null,lastActive:{}}),sync:t=>e(e=>{let n={...e.lastActive};for(let e of t.groupActivePanels??[]){let t=zb[e].zone;t!==`center`&&(n[t]=e)}let{activePanel:r}=t;return r&&(n[zb[r].zone]=r),{...t,lastActive:n}}),takePendingActivation:()=>{let{pendingActivation:n}=t();return e({pendingActivation:null}),n},activatePanel:n=>{let{controller:r}=t();if(!r){e({pendingActivation:n});return}r.setGroupVisible(n,!0),r.activate(n)},closePanel:e=>t().controller?.close(e),togglePanel:e=>{let{openPanels:n,activatePanel:r,closePanel:i}=t();n.has(e)?i(e):r(e)},setZoneVisible:(e,n)=>{let{controller:r,openPanels:i}=t();for(let t of Vb(e))i.has(t)&&r?.setGroupVisible(t,n)},resetLayout:()=>t().controller?.reset()}));function G8(e,t,n){let r=t[e];return r&&n.has(r)?r:Vb(e).find(e=>n.has(e))??null}function G_n({api:e,containerApi:t,panels:n,isGroupActive:r}){let i=(0,U.useCallback)(e=>{let n=t.onDidMaximizedGroupChange(e);return()=>n.dispose()},[t]),a=(0,U.useSyncExternalStore)(i,()=>e.isMaximized()),o=W8(e=>e.openPanels),s=W8(e=>e.togglePanel),c=W8(e=>e.resetLayout);if(!r)return null;let l=n.find(e=>Bb(e.id))?.id,u=Bb(l)?Vb(zb[l].zone):[];return(0,W.jsxs)(`div`,{className:`hf-dock-strip-actions`,children:[(0,W.jsxs)(aAe,{align:`end`,"aria-label":`Panel menu`,trigger:(0,W.jsx)(lb,{size:`sm`,"aria-label":`Panel menu`,icon:(0,W.jsx)(R5e,{size:16})}),children:[u.map(e=>(0,W.jsx)(cAe,{checked:o.has(e),onCheckedChange:()=>s(e),children:zb[e].title},e)),(0,W.jsx)(lAe,{}),(0,W.jsx)(sAe,{onClick:c,children:`Reset layout`})]}),(0,W.jsx)(lb,{size:`sm`,"aria-label":a?`Restore panel`:`Maximize panel`,icon:a?(0,W.jsx)(P5e,{size:16}):(0,W.jsx)(I5e,{size:16}),onClick:()=>a?e.exitMaximized():e.maximize()}),(0,W.jsx)(lb,{size:`sm`,"aria-label":`Close group`,icon:(0,W.jsx)(B9e,{size:16}),onClick:()=>e.close()})]})}var K_n={preview:$7e,timeline:x5e,compositions:L7e,assets:XA,code:A5e,catalog:D9e,design:_9e,layers:k9e,renders:S7e,variables:p5e,slideshow:d9e};function q_n({api:e}){let t=(0,U.useCallback)(t=>{let n=e.onDidTitleChange(t);return()=>n.dispose()},[e]),n=(0,U.useSyncExternalStore)(t,()=>e.title??``),r=Bb(e.id)?K_n[e.id]:null;return(0,W.jsxs)(`div`,{className:`hf-dock-tab`,children:[r?(0,W.jsx)(r,{className:`hf-dock-tab-icon`,size:14,"aria-hidden":!0}):null,(0,W.jsx)(`span`,{className:`hf-dock-tab-label`,children:n}),(0,W.jsx)(`div`,{role:`button`,tabIndex:-1,"aria-label":`Close ${n}`,className:`hf-dock-tab-close`,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),e.close()},children:(0,W.jsx)(B9e,{size:12,"aria-hidden":!0})})]})}var J_n=`hf-dock-tab-fill`;function Y_n(e){let t=e.querySelector(`:scope > .${J_n}`);if(t)return t;let n=document.createElement(`span`);return n.className=J_n,n.setAttribute(`aria-hidden`,`true`),e.prepend(n),requestAnimationFrame(()=>n.setAttribute(`data-ready`,``)),n}function X_n(e,t){return!e||t.width===0?!1:t.width<e.width||t.tab!==e.tab||t.left!==e.left||t.size!==e.size}function Z_n(e,t){return e.left<t?e.left:Math.max(t,e.left+e.size+1-e.width)}function Q_n(e,t){let n=Y_n(e),r=e.querySelector(`:scope > .dv-active-tab`),i={width:e.clientWidth,tab:r,left:r?.offsetLeft??0,size:r?.offsetWidth??0},a=r!==null&&X_n(t.get(e),i);i.width>0&&t.set(e,i);let o=e.scrollLeft,s=a?Z_n(i,o):o;return()=>{n.hidden=!r,r&&(n.style.width=`${i.size}px`,n.style.transform=`translateX(${i.left}px)`,s!==o&&(e.scrollLeft=s))}}function $_n(e){let t=[];e.scrollLeft>0&&t.push(`start`),e.scrollLeft+e.clientWidth<e.scrollWidth-1&&t.push(`end`);let n=t.join(` `);n?e.setAttribute(`data-clipped`,n):e.removeAttribute(`data-clipped`)}function evn(e,t){let n=()=>t.querySelectorAll(`.dv-tabs-container`),r=new ResizeObserver(()=>s()),i=new Set;function a(e){for(let e of i)e.isConnected||(r.unobserve(e),i.delete(e));for(let t of e)i.has(t)||(r.observe(t),i.add(t))}let o=new WeakMap;function s(){let e=[...n()],t=e.map(e=>Q_n(e,o));for(let e of t)e();for(let t of e)$_n(t);a(e.flatMap(e=>[e,...e.querySelectorAll(`:scope > .dv-tab`)]))}let c=e=>{let t=e.target;t instanceof HTMLElement&&t.classList.contains(`dv-tabs-container`)&&$_n(t)},l=[e.onDidActivePanelChange(s),e.onDidAddPanel(s),e.onDidRemovePanel(s),e.onDidMovePanel(s),e.onDidLayoutChange(s),e.onDidLayoutFromJSON(s)];return t.addEventListener(`scroll`,c,!0),s(),()=>{t.removeEventListener(`scroll`,c,!0);for(let e of l)e.dispose();r.disconnect()}}var K8=360,tvn=200,nvn=100,rvn=200,ivn=120,avn=240,ovn=[`compositions`,`assets`,`code`,`catalog`],svn=[`design`,`layers`,`renders`,`variables`];function cvn(e){let t=lvn(e),n=Math.max(t,Math.min(384,Math.round(e*.257))),r=Math.max(Math.min(280,t),Math.min(424,Math.round(e*.284))),i=n+r-Math.max(0,e-K8);if(i<=0)return{left:n,right:r};let a=Math.max(t,r-i);return{left:Math.max(t,n-(i-(r-a))),right:a}}function lvn(e){let t=Math.floor((e-K8)/2);return Math.min(rvn,Math.max(ivn,t))}function uvn(e){return e.panels.some(e=>e.id===`preview`)}function dvn(e){let t=e.panels.map(e=>Bb(e.id)?zb[e.id].zone:`center`),n=t[0];return t.every(e=>e!==`center`)&&n&&n!==`center`?n:null}function q8(e,t=window.innerWidth){let n=lvn(t),r=cvn(t);for(let t of e.groups){if(uvn(t)){t.api.setConstraints({minimumWidth:K8});continue}t.api.setConstraints({minimumWidth:n});let e=dvn(t),i=e===`right`?r.right:r.left;e&&n<rvn&&t.width>i&&t.api.setSize({width:i})}}function fvn(e){return e===`preview`?{minimumWidth:K8,minimumHeight:tvn}:e===`timeline`?{minimumHeight:nvn}:{minimumWidth:rvn}}function J8(e,t,n){return e.addPanel({id:t,component:iNe,title:zb[t].title,renderer:`always`,...fvn(t),...n?{position:n}:{}})}function pvn(e,t,n,r){let[i,...a]=t.filter(e=>n.includes(e));if(i){J8(e,i,{referencePanel:`preview`,direction:r});for(let t of a)J8(e,t,{referencePanel:i,direction:`within`});return e.getPanel(i)?.api.setActive(),i}}function mvn(e,t,n=Rb){e.clear();let r=cvn(t);J8(e,`preview`),J8(e,`timeline`,{referencePanel:`preview`,direction:`below`});let i=pvn(e,ovn,n,`left`),a=pvn(e,svn,n,`right`);q8(e,t),i&&e.getPanel(i)?.group.api.setSize({width:r.left}),a&&e.getPanel(a)?.group.api.setSize({width:r.right}),e.getPanel(`timeline`)?.group.api.setSize({height:avn})}var hvn=250,gvn=(0,U.createContext)(null);function _vn(){let e=(0,U.useContext)(gvn);if(!e)throw Error(`Dock.Panel must be rendered inside Dock.Root`);return e}function vvn({api:e}){let{registerSlot:t}=_vn(),n=e.id,r=(0,U.useCallback)(e=>{Bb(n)&&t(n,e)},[n,t]);return(0,W.jsx)(`div`,{ref:r,className:`h-full w-full min-h-0 min-w-0 overflow-hidden`})}var yvn={[iNe]:vvn};function bvn(e){let t=new Set,n=new Set;for(let r of e.panels)Bb(r.id)&&(t.add(r.id),r.api.isVisible&&r.group.api.isVisible&&n.add(r.id));let r=e.groups.flatMap(e=>{let t=e.activePanel?.id;return Bb(t)?[t]:[]}),i=e.activePanel?.id;return{openPanels:t,visiblePanels:n,activePanel:Bb(i)?i:null,groupActivePanels:r}}function xvn(e,t){let n=n=>{if(e.getPanel(n))return;let{zone:r,reopen:i}=zb[n],a=r===`center`||t.panels.includes(i.near)?i:{near:`preview`,direction:r},o=r===`center`?void 0:Vb(r).find(t=>t!==n&&e.getPanel(t));if(o){J8(e,n,{referencePanel:o,direction:`within`});return}let s=e.getPanel(a.near)!==void 0,c={referencePanel:a.near,direction:a.direction};J8(e,n,s?c:void 0)};return{open:n,activate:t=>{n(t),e.getPanel(t)?.api.setActive()},close:t=>{let n=e.getPanel(t);n&&e.removePanel(n)},setTitle:(t,n)=>e.getPanel(t)?.api.setTitle(n),setGroupVisible:(t,n)=>e.getPanel(t)?.group.api.setVisible(n),reset:()=>mvn(e,t.dockWidth(),t.panels)}}function Svn(e,t,n){let{dockLayout:r}=Ub(void 0,t,n.storageKey),i=lNe(r,n.panels);if(i)try{e.fromJSON(i);return}catch{}mvn(e,n.dockWidth(),n.panels)}var Cvn=()=>window.innerWidth;function wvn({projectId:e,panels:t=Rb,storageKey:n=`cx-studio-fixed-dock`,dockWidth:r=Cvn,children:i}){let[a,o]=(0,U.useState)({}),s=(0,U.useCallback)((e,t)=>{o(n=>{if(n[e]===(t??void 0))return n;let r={...n};return t?r[e]=t:delete r[e],r})},[]),c=(0,U.useRef)(()=>{});(0,U.useEffect)(()=>()=>c.current(),[]);let l=(0,U.useCallback)(({api:i})=>{c.current();let a={panels:t,storageKey:n,dockWidth:r};Svn(i,e,a),q8(i,r());let o=i.groups[0]?.element.closest(`.hf-dock`),s=o?W_n(i,o):()=>{},l=o?evn(i,o):()=>{},u=new ResizeObserver(()=>q8(i,r()));o&&u.observe(o);let d=W8.getState();d.attach(xvn(i,a),t),d.sync(bvn(i));let f=d.takePendingActivation();f&&i.getPanel(f)?.api.setActive();let p,m=()=>{clearTimeout(p),p=setTimeout(()=>{Wb({dockLayout:i.toJSON()},void 0,e,n)},hvn)},h=()=>{W8.getState().sync(bvn(i)),m()},g=[i.onDidAddPanel(()=>{q8(i,r()),h()}),i.onDidMovePanel(()=>{q8(i,r()),h()}),i.onDidRemovePanel(h),i.onDidActivePanelChange(h),i.onDidLayoutChange(h)];c.current=()=>{clearTimeout(p);for(let e of g)e.dispose();s(),l(),u.disconnect(),W8.getState().detach()}},[e,t,n,r]);return(0,W.jsxs)(gvn.Provider,{value:{slots:a,registerSlot:s},children:[(0,W.jsx)(nct,{className:`hf-dock flex-1 min-h-0`,components:yvn,defaultTabComponent:q_n,rightHeaderActionsComponent:G_n,defaultRenderer:`always`,disableFloatingGroups:!0,disableTabsOverflowList:!0,disableDnd:!0,onReady:l},e??``),i]})}function Tvn({id:e,title:t,children:n}){let r=_vn().slots[e],i=W8(t=>t.visiblePanels.has(e)),a=W8(e=>e.controller),o=W8(t=>t.openPanels.has(e)),s=t??zb[e].title;(0,U.useEffect)(()=>{o&&a?.setTitle(e,s)},[a,e,s,o]);let c=zb[e],l=i||c.keepMounted;return r&&l?(0,pm.createPortal)(n,r):null}function Evn(){let e=W8(e=>e.openPanels),t=W8(e=>e.panels),n=W8(e=>e.togglePanel),r=W8(e=>e.resetLayout),[i,a]=(0,U.useState)(!1),o=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[i]),(0,W.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,W.jsx)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":i,onClick:()=>a(e=>!e),className:`h-7 px-2.5 rounded-md text-[11px] font-medium text-neutral-400 hover:text-neutral-200 hover:bg-neutral-800 transition-colors`,children:`Window`}),i&&(0,W.jsxs)(`div`,{role:`menu`,className:`${wQ.panel} absolute right-0 top-8 z-50 w-44`,children:[t.map(t=>(0,W.jsxs)(`button`,{type:`button`,role:`menuitemcheckbox`,"aria-checked":e.has(t),onClick:()=>n(t),className:`${wQ.row} ${wQ.rowEnabled} flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`w-3 text-accent-ink`,children:e.has(t)?`✓`:``}),zb[t].title]},t)),(0,W.jsx)(`div`,{className:wQ.divider}),(0,W.jsx)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{r(),a(!1)},className:`${wQ.row} ${wQ.rowEnabled}`,children:`Reset layout`})]})]})}var Y8={Root:wvn,Panel:Tvn,WindowMenu:Evn},Dvn=(0,U.memo)(function({panels:e,timelineToolbar:t,renderClipContent:n,handleTimelineElementDelete:r,handleTimelineAssetDrop:i,handleTimelineBlockDrop:a,handleTimelineCompositionDrop:o,handlePreviewBlockDrop:s,handleTimelineFileDrop:c,handleTimelineElementMove:l,handleTimelineElementsMove:u,handleTimelineElementResize:d,handleTimelineGroupResize:f,handleToggleTrackHidden:p,setAudioGroupAttribute:m,handleGroupClips:h,setElementFxAttribute:g,handleBlockedTimelineEdit:_,handleTimelineElementSplit:v,handleRazorSplit:y,handleRazorSplitAll:b,handleFreezeFrame:x,handleLinkEdit:S,handleTimelineElementDeleteOnly:C,onCopyClip:w,onPasteClip:T,onDuplicateClip:E,canPasteClip:D,clipMenuItems:O,splitShortcut:k,setCompIdToSrc:A,setCompositionLoading:j,shouldShowMotionPath:M,shouldShowSelectedDomBounds:N,isGestureRecording:P,recordingState:F,onToggleRecording:I,blockPreview:L,gestureOverlay:R,readOnlyPreview:z=!1,readOnlyPreviewReason:B}){let{projectId:V,activeCompPath:ee,setActiveCompPath:te,handlePreviewIframeRef:H,showToast:ne}=FX(),{refreshKey:re,captionEditMode:ie,refreshPreviewDocumentVersion:ae,timelineElements:oe}=LX(),{handleTimelineElementSelect:se,buildDomSelectionForTimelineElement:ce,applyDomSelection:le,applyMarqueeSelection:ue}=kX(),{domEditSelection:de,domEditGroupSelections:fe}=jX();agn({selectedElementId:X(e=>e.selectedElementId),selectedElementIds:X(e=>e.selectedElementIds),timelineElements:oe,domEditSelection:de,domEditGroupSelections:fe,activeCompPath:ee,buildDomSelectionForTimelineElement:ce,applyDomSelection:le,applyMarqueeSelection:ue,onSelectionNotFound:(0,U.useCallback)(()=>{ne(`The selected clip is not available in the preview yet.`,`info`)},[ne])});let pe=Yhn({handleTimelineElementMove:l,handleTimelineElementsMove:u,handleTimelineElementResize:d,handleTimelineGroupResize:f,handleToggleTrackHidden:p,setAudioGroupAttribute:m,handleGroupClips:h,setElementFxAttribute:g,handleBlockedTimelineEdit:_,handleTimelineElementSplit:v,handleRazorSplit:y,handleRazorSplitAll:b,handleFreezeFrame:x,handleLinkEdit:S,handleTimelineElementDeleteOnly:C});return(0,W.jsx)(pnn,{readOnly:z,reason:B,children:(0,W.jsx)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:(0,W.jsx)(tYt,{value:pe,children:(0,W.jsx)(Mtn,{projectId:V,refreshKey:re,activeCompositionPath:ee,onIframeRef:H,onCompIdToSrcChange:A,onPreviewReloadFailed:e=>ne(e,`error`),onCompositionLoadingChange:j,onCompositionChange:e=>{e!==ee&&(te(e),ae())},children:(0,W.jsx)(Ovn,{projectId:V,panels:e,captionEditMode:ie,onSelectTimelineElement:se,onPreviewBlockDrop:s,timelineToolbar:t,renderClipContent:n,onFileDrop:c,onAssetDrop:i,onBlockDrop:a,onCompositionDrop:o,onDeleteElement:r,onCopyClip:w,onPasteClip:T,onDuplicateClip:E,canPasteClip:D,clipMenuItems:O,splitShortcut:k,previewOverlay:(0,W.jsx)(fhn,{shouldShowMotionPath:M,shouldShowSelectedDomBounds:N,blockPreview:L,isGestureRecording:P,recordingState:F,onToggleRecording:I,gestureOverlay:R})})})})})})});function Ovn({panels:e,projectId:t,captionEditMode:n,previewOverlay:r,onSelectTimelineElement:i,onPreviewBlockDrop:a,timelineToolbar:o,renderClipContent:s,onFileDrop:c,onAssetDrop:l,onBlockDrop:u,onCompositionDrop:d,onDeleteElement:f,onCopyClip:p,onPasteClip:m,onDuplicateClip:h,canPasteClip:g,clipMenuItems:_,splitShortcut:v}){let{compositionStack:y,updateCompositionStack:b,containerRef:x}=k2(),S=(0,U.useCallback)(e=>{X.getState().requestSeek(e)},[]),C=(0,U.useCallback)(e=>{e.key===`Escape`&&y.length>1&&b(e=>e.slice(0,-1))},[y.length,b]);return(0,W.jsxs)(`div`,{ref:x,className:`flex flex-col flex-1 min-h-0`,onKeyDown:C,tabIndex:-1,children:[(0,W.jsx)(F_n,{}),(0,W.jsxs)(Y8.Root,{projectId:t,children:[(0,W.jsx)(Y8.Panel,{id:`preview`,children:(0,W.jsx)(`div`,{className:`relative flex h-full w-full min-w-0 flex-col`,children:(0,W.jsx)(trn,{previewOverlay:r,onSelectTimelineElement:i,onPreviewBlockDrop:a})})}),(0,W.jsx)(Y8.Panel,{id:`timeline`,children:(0,W.jsx)(Mrn,{timelineToolbar:o,renderClipContent:s,onFileDrop:c,onAssetDrop:l,onBlockDrop:u,onCompositionDrop:d,onDeleteElement:f,onCopyClip:p,onPasteClip:m,onDuplicateClip:h,canPasteClip:g,clipMenuItems:_,splitShortcut:v,onSelectTimelineElement:i,timelineFooter:n?(0,W.jsxs)(`div`,{className:`border-t border-neutral-800/30 shrink-0`,style:{height:60},children:[(0,W.jsx)(`div`,{className:`flex items-center gap-1.5 px-2 py-0.5`,children:(0,W.jsx)(`span`,{className:`text-[9px] font-medium text-neutral-500 uppercase tracking-wider`,children:`Captions`})}),(0,W.jsx)(Qhn,{pixelsPerSecond:100,onSeek:S})]}):void 0})}),e]})]})}var kvn=e=>e.key===`Backspace`||e.key===`Delete`,Avn=e=>e.metaKey||e.ctrlKey,jvn=[[`⌘L`,e=>Avn(e)&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`l`],[`⌥⇧D`,e=>!Avn(e)&&e.altKey&&e.shiftKey&&e.code===`KeyD`],[`⌥⌫`,e=>!Avn(e)&&e.altKey&&!e.shiftKey&&kvn(e)]];function Mvn(e){return jvn.find(([,t])=>t(e))?.[0]??null}function Nvn(e,t){if(aX(e.target))return!1;let n=Mvn(e);if(!n)return!1;let{elements:r,selectedElementId:i,selectedElementIds:a}=X.getState(),o=r.find(e=>(e.key??e.id)===i);if(!o)return!1;let s=D8t({element:o,elements:r,selectedKeys:a,onLinkEdit:t.handleLinkEdit,onDeleteElementOnly:t.handleTimelineElementDeleteOnly}).find(e=>e.shortcut===n);return s?(e.preventDefault(),s.run(),!0):!1}function Pvn(e){let t=new URL(e,window.location.href);return t.origin!==window.location.origin||!/^\/api\/projects\/[^/]+\/preview\/.+\.jpe?g$/i.test(t.pathname)?e:(t.pathname=t.pathname.replace(/^(\/api\/projects\/[^/]+)\/preview\//,`$1/image-thumbnail/`),t.href)}function Fvn(e,t){return new Promise((n,r)=>{let i=new Image,a=()=>{i.onload=null,i.onerror=null,t.removeEventListener(`abort`,o)},o=()=>{a(),i.src=``,r(new DOMException(`Aborted`,`AbortError`))};if(t.aborted){o();return}i.onload=()=>{a(),n(i)},i.onerror=()=>{a(),/\.svg($|\?)/i.test(e)?n(i):(i.src=``,r(Error(`Image thumbnail failed to load`)))},t.addEventListener(`abort`,o,{once:!0}),i.src=e})}async function Ivn(e,t){let n=Pvn(e),r;try{r=await Fvn(n,t)}catch(i){if(t.aborted||n===e)throw i;n=e,r=await Fvn(e,t)}try{t.throwIfAborted();let e=r.naturalWidth||iK.posterMaxPhysicalWidth,i=r.naturalHeight||iK.posterMaxPhysicalHeight;return{value:{kind:`image`,url:n,aspect:e/i},weight:e*i*4}}finally{r.src=``}}var Lvn=(0,U.memo)(function({imageSrc:e,label:t,labelColor:n,projectId:r=e,sessionEpoch:i=0,priority:a=`visible`,rich:o=!1}){let[s,c,l]=oZ(),u=XX((0,U.useMemo)(()=>({key:qX({kind:`image`,source:e,rich:Number(o)}),projectId:r,sessionEpoch:i,kind:`image`,priority:a,rich:o,load:t=>Ivn(e,t)}),[e,a,r,o,i])),d=u.status===`ready`?u.value:null,f=d?.kind===`image`?d.aspect:16/9,{frameW:p,frameCount:m}=M$(s.width,f,s.height);return(0,W.jsxs)(`div`,{ref:c,className:`absolute inset-0 overflow-hidden`,children:[d?.kind===`image`&&(0,W.jsx)(S1,{strip:s,frameW:p,frameCount:m,watchGap:l,children:e=>(0,W.jsx)(`div`,{className:`relative h-full shrink-0 overflow-hidden bg-neutral-900`,style:{width:p},children:(0,W.jsx)(`img`,{src:d.url,alt:``,draggable:!1,loading:`lazy`,className:`absolute inset-0 h-full w-full object-cover`})},e)}),u.status===`loading`&&(0,W.jsx)(`div`,{className:`absolute inset-0 animate-pulse`,style:{background:`var(--timeline-thumbnail-shimmer)`}}),t&&(0,W.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 z-10 px-1.5 pb-0.5 pt-3`,style:{background:`var(--timeline-thumbnail-label-gradient)`},children:(0,W.jsx)(`span`,{className:`block truncate text-[9px] font-semibold leading-tight`,style:{color:n,textShadow:`var(--timeline-thumbnail-label-shadow)`},children:t})})]})});function Rvn(e){if(e.background)return e.background;let t=$t(e.color??``);return(t?.2126*t.red+.7152*t.green+.0722*t.blue:255)<128?`var(--timeline-text-clip-light-bg)`:`var(--timeline-text-clip-dark-bg)`}function zvn({text:e}){return(0,W.jsx)(`div`,{className:`absolute inset-0 flex items-center overflow-hidden px-2`,style:{background:Rvn(e)},children:(0,W.jsx)(`span`,{className:`whitespace-nowrap text-[15px] leading-none`,style:{fontFamily:e.fontFamily,fontWeight:e.fontWeight,color:e.color},children:e.value})})}var Bvn=.5,Vvn=`var(--timeline-clip-audio-bg)`;function Hvn({thumbnail:e,waveform:t}){let n=`${Bvn*100}%`;return(0,W.jsxs)(`div`,{className:`relative h-full w-full`,"data-testid":`audible-video-clip`,children:[(0,W.jsx)(`div`,{className:`absolute inset-x-0 top-0`,style:{bottom:n},children:e}),(0,W.jsx)(`div`,{className:`audible-video-wave absolute inset-x-0 bottom-0`,"data-testid":`audible-video-wave`,style:{height:n,backgroundColor:Vvn},children:t})]})}var Uvn=e=>`${e<0?`−`:`+`}${Math.abs(e).toFixed(1)} dBFS`;function Wvn({peaksUrl:e,sourceWindow:t,gain:n,children:r}){let[i,a]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(!e)return;let t=!0;return b3t(e).then(e=>{t&&a(e)}),()=>{t=!1}},[e]);let{runs:o,peakDbfs:s}=i?p3t(i,t,n):{runs:[],peakDbfs:null},c=o.length>0&&s!==null?`Peaks ${Uvn(s)} at this volume; export lowers the whole mix`:null,l=(0,U.useContext)(_1t);return(0,U.useEffect)(()=>(l?.(c),()=>l?.(null)),[c,l]),(0,W.jsxs)(`div`,{className:`relative isolate h-full w-full`,children:[r,c!==null&&(0,W.jsxs)(`div`,{className:`pointer-events-none absolute inset-0`,"data-testid":`clip-peak-marks`,children:[o.map(e=>(0,W.jsx)(`div`,{className:`absolute inset-y-0 bg-red-500/80`,style:{left:`${e.from*100}%`,width:`max(1px, ${(e.to-e.from)*100}%)`}},e.from)),(0,W.jsxs)(`span`,{className:`pointer-events-auto absolute right-4 bottom-1 font-mono text-[9px] leading-none text-red-400`,"data-peak-badge":!0,children:[`▲`,(0,W.jsx)(`span`,{"data-peak-text":!0,children:` Too loud`})]})]})]})}function Gvn(e,t,n){try{let r=new URL(e,n),i=M(t,`/preview/`);if(r.pathname.startsWith(i))return r.pathname.slice(i.length)}catch{}return e}function Kvn(e){let t=e.sourceDuration;if(t==null||t<=0)return{};let n=e.playbackStart??0,r=e.playbackRate??1,i=Math.max(0,Math.min(1,n/t));return{start:i,end:Math.max(i,Math.min(1,(n+e.duration*r)/t))}}function qvn(e,t,n,r,i,a,o){let s=P$(e.src??``,t,window.location.origin),c=j$(s,t,window.location.origin),l=c?N$(c):null,u=l?M(t,`/waveform/${l}`):void 0,{start:d,end:f}=Kvn(e),p=(0,U.createElement)(cZt,{audioUrl:s,waveformUrl:u,label:``,labelColor:r,trimStartFraction:d,trimEndFraction:f,projectId:t,sessionEpoch:n,priority:i.priority,labelInset:o,...EVt(e,a)});return(0,U.createElement)(Wvn,{peaksUrl:x3t(e.src,t),sourceWindow:S3t(e),gain:e.volume??1},p)}function Jvn(e,t,n){return e.tag!==`video`||!F$(e)?t:(0,U.createElement)(Hvn,{thumbnail:t,waveform:n(0)})}function Yvn({projectIdRef:e,compIdToSrc:t,activePreviewUrl:n,effectiveTimelineDuration:r}){let i=MNe(X(e=>e.thumbnailMode)),a=X(e=>e.timelineSessionEpoch),o=X(e=>e.thumbnailRevisions),s=X(e=>e.elements);return(0,U.useCallback)((c,l,u={priority:`visible`,rich:!1})=>{let d=e.current;if(!d)return null;let f=e=>qvn(c,d,a,l.label,u,s,e);if(i===`hidden`)return cZ(c)?f():Jvn(c,null,f);let p=c.compositionSrc;if(p&&=Gvn(p,d,window.location.origin),p&&t.size>0){let e=t.get(c.id)||t.get(p.replace(/^compositions\//,``).replace(/\.html$/,``));e&&(p=e)}if(p)return(0,U.createElement)(w1,{previewUrl:M(d,`/preview/comp/${N$(p)}`),label:``,labelColor:l.label,seekTime:S5t(c.duration),duration:0,projectId:d,sessionEpoch:a,contentRevision:Qb(o,p),priority:u.priority,rich:u.rich});if(cZ(c))return qvn(c,d,a,l.label,u,s);if(c.text)return(0,U.createElement)(zvn,{text:c.text});if(n&&c.duration>0)return(0,U.createElement)(w1,{previewUrl:n,label:``,labelColor:l.label,selector:c.selector,selectorIndex:c.selectorIndex,seekTime:c.start,duration:c.duration,projectId:d,sessionEpoch:a,contentRevision:Qb(o,w5t(n)),priority:u.priority,rich:u.rich});let m=c.duration>0&&r>0;if((c.tag===`video`||c.tag===`img`)&&c.src){let e=P$(c.src,d,window.location.origin);return c.tag===`img`?(0,U.createElement)(Lvn,{imageSrc:e,label:``,labelColor:l.label,projectId:d,sessionEpoch:a,priority:u.priority,rich:u.rich}):Jvn(c,(0,U.createElement)(b5t,{videoSrc:e,label:``,labelColor:l.label,duration:c.duration,sourceStart:c.playbackStart,sourceRangeDuration:c.duration*(c.playbackRate??1),projectId:d,sessionEpoch:a,priority:u.priority}),f)}return m?(0,U.createElement)(w1,{previewUrl:M(d,`/preview`),label:``,labelColor:l.label,selector:c.selector,selectorIndex:c.selectorIndex,seekTime:c.start,duration:c.duration,projectId:d,sessionEpoch:a,contentRevision:Qb(o,`index.html`),priority:u.priority,rich:u.rich}):null},[e,t,n,r,i,a,o,s])}Object.freeze({status:`loading`}),Object.freeze({status:`failed`});var Xvn=[SI.theme({"&":{height:`100%`,color:`var(--color-text-0)`,backgroundColor:`var(--color-surface)`},".cm-scroller":{overflow:`auto`},".cm-content":{caretColor:`var(--color-text-0)`},".cm-cursor, .cm-dropCursor":{borderLeftColor:`var(--color-text-0)`},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:`var(--color-on)`},".cm-activeLine":{backgroundColor:`var(--color-hover)`},".cm-selectionMatch":{backgroundColor:`transparent`,outline:`1px solid var(--color-text-muted)`},".cm-searchMatch":{backgroundColor:`transparent`,outline:`1px solid var(--color-text-muted)`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:`transparent`,outline:`2px solid var(--color-accent-ink)`},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:`var(--color-on)`},".cm-gutters":{backgroundColor:`var(--color-surface)`,color:`var(--color-text-muted)`,border:`none`},".cm-activeLineGutter":{backgroundColor:`var(--color-hover)`,color:`var(--color-text-2)`},".cm-foldPlaceholder":{backgroundColor:`transparent`,border:`none`,color:`var(--color-text-2)`},".cm-panels":{backgroundColor:`var(--color-raised)`,color:`var(--color-text-0)`},".cm-panels.cm-panels-top":{borderBottom:`1px solid var(--color-border)`},".cm-panels.cm-panels-bottom":{borderTop:`1px solid var(--color-border)`},".cm-textfield":{backgroundColor:`var(--color-input)`,color:`var(--color-text-0)`,border:`1px solid var(--color-border-input)`},".cm-button":{backgroundImage:`none`,backgroundColor:`var(--color-hover)`,color:`var(--color-text-0)`,border:`1px solid var(--color-border)`},"&.cm-editor .cm-button:active":{backgroundImage:`none`,backgroundColor:`var(--color-press)`},".cm-specialChar":{color:`var(--color-danger-ink)`}}),xvt(yvt.define([{tag:$.keyword,color:`var(--color-code-keyword)`},{tag:[$.name,$.deleted,$.character,$.propertyName,$.macroName],color:`var(--color-code-name)`},{tag:[$.function($.variableName),$.labelName],color:`var(--color-code-function)`},{tag:[$.color,$.constant($.name),$.standard($.name)],color:`var(--color-code-constant)`},{tag:[$.definition($.name),$.separator],color:`var(--color-text-0)`},{tag:[$.typeName,$.className,$.number,$.changed,$.annotation,$.modifier,$.self,$.namespace],color:`var(--color-code-type)`},{tag:[$.operator,$.operatorKeyword,$.url,$.escape,$.regexp,$.special($.string)],color:`var(--color-code-operator)`},{tag:[$.meta,$.comment],color:`var(--color-code-comment)`},{tag:$.strong,fontWeight:`bold`},{tag:$.emphasis,fontStyle:`italic`},{tag:$.strikethrough,textDecoration:`line-through`},{tag:$.link,color:`var(--color-code-comment)`,textDecoration:`underline`},{tag:$.heading,fontWeight:`bold`,color:`var(--color-code-name)`},{tag:[$.atom,$.bool,$.special($.variableName)],color:`var(--color-code-constant)`},{tag:[$.processingInstruction,$.string,$.inserted],color:`var(--color-code-string)`},{tag:$.invalid,color:`var(--color-danger-ink)`}]))],Zvn=mP.define(),Qvn={html:()=>UV(),css:()=>wwt(),markdown:()=>kDt(),md:()=>kDt(),javascript:()=>jV(),js:()=>jV(),typescript:()=>jV({typescript:!0}),ts:()=>jV({typescript:!0})};function $vn(e){return(Qvn[e]??UV)()}function eyn(e){return{html:`html`,htm:`html`,css:`css`,js:`javascript`,ts:`typescript`,jsx:`javascript`,tsx:`typescript`,json:`javascript`,md:`markdown`,markdown:`markdown`}[e.split(`.`).pop()?.toLowerCase()??``]??`html`}var tyn=(0,U.memo)(function({content:e,filePath:t,language:n,onChange:r,readOnly:i=!1,revealOffset:a}){let o=(0,U.useRef)(null),s=(0,U.useRef)(null),c=(0,U.useRef)(r);c.current=r;let l=(0,U.useRef)(e);l.current=e;let u=(0,U.useCallback)(e=>{if(o.current&&=(o.current.destroy(),null),!e)return;s.current=e;let r=n??(t?eyn(t):`html`),a=SI.updateListener.of(e=>{!e.docChanged||!c.current||e.transactions.some(e=>e.annotation(Zvn))||c.current(e.state.doc.toString())}),u=xP.create({doc:l.current,extensions:[mpt(),Kft(),vpt(),tyt(),_vt(),tvt(),Nvt(),lxt(),Pxt(),wI.of([...hxt,...Vbt,...lSt,...pyt]),$vn(r),Xvn,a,xP.readOnly.of(i)]});o.current=new SI({state:u,parent:e})},[t,n,i]);return(0,U.useEffect)(()=>{let t=o.current;if(!t)return;let n=t.state.doc.toString();n!==e&&(t.hasFocus||t.dispatch({changes:{from:0,to:n.length,insert:e},annotations:[Zvn.of(!0)]}))},[e]),(0,U.useEffect)(()=>{let e=o.current;if(!e||a==null||a<0)return;let t=e.state.doc.length,n=Math.min(a,t);e.dispatch({selection:{anchor:n},effects:SI.scrollIntoView(n,{y:`center`})})},[a]),(0,W.jsx)(`div`,{ref:u,className:`h-full w-full overflow-hidden`})}),nyn=600,ryn=new Map;function iyn(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():0}function X8(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/(^-|-$)/g,``)}function ayn(e){try{let t=X8(e.section)||`unknown`,n=X8(e.name),r=e.control||`unknown`,i=`${e.ui}:${t}:${r}:${n||`unnamed`}`,a=iyn(),o=ryn.get(i);if(o!==void 0&&a-o<nyn)return;ryn.set(i,a),mG(`design_input`,{ui:e.ui,section:t,control:r,name:n||`unnamed`})}catch{}}var oyn=jG(`DesignPanelInputContext`,{ui:`classic`,section:`unknown`});function Z8({ui:e,section:t,children:n}){let r=(0,U.useContext)(oyn),i=(0,U.useMemo)(()=>({ui:e??r.ui,section:t??r.section}),[e,t,r.ui,r.section]);return(0,W.jsx)(oyn.Provider,{value:i,children:n})}function Q8(){let{ui:e,section:t}=(0,U.useContext)(oyn);return(0,U.useCallback)((n,r)=>ayn({ui:e,section:t,control:n,name:r}),[e,t])}function syn({element:e,copied:t,onCopy:n,onClear:r,onUngroup:i,selectedElementId:a,selectedElementHidden:o,visibilityLabel:s,onToggleHidden:c}){let l=Q8();return(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[a&&c&&(0,W.jsx)(`button`,{type:`button`,"aria-label":s,title:s,onClick:()=>{l(`toggle`,`Element visibility`),c(a,!o)},className:`flex h-6 w-6 items-center justify-center rounded-sm text-neutral-500 transition-colors hover:bg-neutral-800 hover:text-neutral-300`,children:o?(0,W.jsx)(H5e,{size:13,weight:`bold`,"aria-hidden":`true`}):(0,W.jsx)(B5e,{size:13,weight:`bold`,"aria-hidden":`true`})}),i&&e.dataAttributes[`hf-group`]!=null&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>{l(`button`,`Ungroup`),i()},title:`Ungroup (⌘⇧G)`,className:`flex h-6 items-center rounded-sm px-2 text-[11px] font-medium text-neutral-400 transition-colors hover:bg-neutral-800 hover:text-neutral-200`,children:`Ungroup`}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>{l(`button`,`Copy element info`),n()},className:`flex h-6 w-6 items-center justify-center rounded transition-colors ${t?`text-accent-ink`:`text-neutral-500 hover:bg-neutral-800 hover:text-neutral-300`}`,title:t?`Copied!`:`Copy element info to clipboard`,children:(0,W.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,W.jsx)(`rect`,{x:`5`,y:`5`,width:`9`,height:`9`,rx:`1.5`}),(0,W.jsx)(`path`,{d:`M11 5V3.5A1.5 1.5 0 009.5 2h-6A1.5 1.5 0 002 3.5v6A1.5 1.5 0 003.5 11H5`})]})}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Clear selection`,onClick:()=>{l(`button`,`Clear selection`),r()},className:`flex h-6 w-6 items-center justify-center rounded-sm text-neutral-500 transition-colors hover:bg-neutral-800 hover:text-neutral-300`,children:(0,W.jsx)(m$,{size:13})})]})}var cyn=`ABeeZee.Abel.Abril Fatface.Alegreya.Alegreya Sans.Anton.Archivo.Archivo Black.Arimo.Assistant.Barlow.Barlow Condensed.Bebas Neue.Bitter.Bricolage Grotesque.Cabin.Cardo.Catamaran.Caveat.Chivo.Cormorant Garamond.Crimson Text.Dancing Script.DM Sans.DM Serif Display.Domine.EB Garamond.Exo 2.Figtree.Fira Code.Fira Sans.Fraunces.Fredoka.IBM Plex Mono.IBM Plex Sans.IBM Plex Serif.Inconsolata.Instrument Sans.Instrument Serif.Inter.JetBrains Mono.Josefin Sans.Jost.Kanit.Karla.Lato.League Gothic.Lexend.Libre Baskerville.Libre Franklin.Lora.Manrope.Merriweather.Montserrat.Mukta.Mulish.Newsreader.Noto Sans.Noto Sans JP.Noto Serif.Nunito.Nunito Sans.Open Sans.Oswald.Outfit.Overpass.Pacifico.Pathway Extreme.Permanent Marker.Playfair Display.Plus Jakarta Sans.Poppins.Prata.PT Sans.PT Serif.Public Sans.Quicksand.Raleway.Red Hat Display.Roboto.Roboto Condensed.Roboto Mono.Roboto Serif.Rubik.Schibsted Grotesk.Signika.Source Code Pro.Source Sans 3.Source Serif 4.Space Grotesk.Space Mono.Spectral.Sora.Syne.Teko.Titillium Web.Ubuntu.Ubuntu Mono.Unbounded.Urbanist.Varela Round.Work Sans.Young Serif.Zilla Slab`.split(`.`),lyn=[`TT Norms Pro`,`SF Pro Display`,`SF Pro Text`,`Avenir`,`Avenir Next`,`Menlo`,`Monaco`];function uyn(e){let t=BDt(e);if(!(!t||t.toLowerCase()===e.toLowerCase()))return t}function dyn(e){return`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e.trim()).replace(/%20/g,`+`)}:wght@300;400;500;600;700;800;900&display=swap`}function fyn(e){let t=e.indexOf(`?`),n=e.indexOf(`#`);return t<0?n<0?e:e.slice(0,n):n<0?e.slice(0,t):e.slice(0,Math.min(t,n))}function pyn(e,t){return t?e.find(e=>(e.key??e.id)===t)?.hidden===!0:!1}function myn(e){return[e.id??``,e.hfId??``,e.selector??``,String(e.selectorIndex??``),e.sourceFile??``].join(`|`)}var hyn=new Set([`inherit`,`initial`,`revert`,`revert-layer`,`serif`,`sans-serif`,`monospace`,`cursive`,`fantasy`,`system-ui`,`ui-sans-serif`,`ui-serif`,`ui-monospace`,`ui-rounded`,`emoji`,`math`,`fangsong`]),gyn=[...lyn,`Inter`,`system-ui`,`sans-serif`,`serif`,`monospace`];function _yn(e){return e.replace(/[^\w .-]+/g,` `).replace(/\s+/g,` `).trim()}function $8(e){let t=e.style?.toLowerCase()??``,n=e.fullName?.toLowerCase()??``;return t===`regular`||n.endsWith(` regular`)?0:t===`normal`||n.endsWith(` normal`)?1:t===`medium`||n.endsWith(` medium`)?2:3}function vyn(e,t=new Set){return e.reduce((e,n)=>{let r=n.trim();if(!r)return e;let i=r.toLowerCase();return t.has(i)?e:(t.add(i),e.push(r),e)},[])}function yyn(e){let t=new Set;return e.reduce((e,n)=>{let r=n.family.trim();if(!r)return e;let i=r.toLowerCase();return t.has(i)?e:(t.add(i),e.push({family:r,source:n.source}),e)},[])}function byn(e){return[...e].sort((e,t)=>{let n=xyn(e.source)-xyn(t.source);if(n!==0)return n;let r=lyn.findIndex(t=>t.toLowerCase()===e.family.toLowerCase()),i=lyn.findIndex(e=>e.toLowerCase()===t.family.toLowerCase()),a=(r===-1?2**53-1:r)-(i===-1?2**53-1:i);return a===0?e.family.localeCompare(t.family):a})}function xyn(e){return e===`Current`?0:e===`Document`?1:e===`Imported`?2:e===`Google`?3:e===`Local`?4:5}var e5=`min-w-0 rounded-md bg-panel-input px-3 py-[7px] text-panel-text-1 transition-colors focus-within:ring-1 focus-within:ring-panel-accent/30`,t5=`text-[11px] font-medium text-panel-text-3`,n5=`grid grid-cols-[repeat(auto-fit,minmax(118px,1fr))] gap-3`,Syn={},Cyn=`none`,wyn={none:`none`,soft:`0 12px 36px rgba(0, 0, 0, 0.28)`,lift:`0 18px 54px rgba(0, 0, 0, 0.38)`,glow:`0 0 0 1px rgba(60, 230, 172, 0.34), 0 18px 56px rgba(60, 230, 172, 0.2)`};function r5(e){return $t(e)??{red:0,green:0,blue:0,alpha:1}}function i5(e){if(!e)return null;let t=Number.parseFloat(e);return Number.isFinite(t)?t:null}function Tyn(e){let t=We(t=>e?.[t.slice(5)]);return{mediaStart:t.playbackStart??0,mediaStartAttr:kt(t).slice(5)}}function a5(e){return!Number.isFinite(e)||e<0?`0.00s`:`${e.toFixed(2)}s`}function o5(e){let t=y(e);return Number.isInteger(t)?`${t}`:t.toFixed(2).replace(/0+$/,``).replace(/\.$/,``)}function s5(e){if(!e)return null;let t=e.trim().match(/^(-?\d+(?:\.\d+)?)([a-z%]*)$/i);if(!t)return null;let n=Number.parseFloat(t[1]);return Number.isFinite(n)?{value:n,unit:t[2]??``}:null}function c5(e){let t=s5(e);return!t||t.unit&&t.unit.toLowerCase()!==`px`?null:t.value}function Eyn(e,t,n,r){return Number.isFinite(e)?Math.max(t,Math.min(n,e)):r}function Dyn(e,t={}){let n=s5(e.trim());return!n||n.unit&&n.unit.toLowerCase()!==`px`?null:`${o5(Eyn(n.value,t.min??-1/0,t.max??1/0,t.fallback??0))}px`}function l5(e){return`${o5(e)}px`}function u5(e,t){let n=t.trim();if(!n||n===`normal`)return n||`normal`;let r=s5(n);return r?e===`letter-spacing`?r.unit?n:`${o5(r.value)}px`:r.unit?n:r.value>4?`${o5(r.value)}px`:o5(r.value):n}function Oyn(e){let t=e.trim(),n=[],r=0,i=0;for(let e=0;e<t.length;e+=1){let a=t[e];if(a===`(`&&(r+=1),a===`)`&&(r=Math.max(0,r-1)),/\s/.test(a)&&r===0){let r=t.slice(i,e).trim();r&&n.push(r),i=e+1}}let a=t.slice(i).trim();return a&&n.push(a),n}function d5(e,t){let n=e?.trim();if(!n||n===Cyn)return 0;let r=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),i=RegExp(`(?:^|\\s)${r}\\((-?\\d+(?:\\.\\d+)?)px\\)`,`i`).exec(n);if(!i)return 0;let a=Number.parseFloat(i[1]);return Number.isFinite(a)?Math.max(0,a):0}function f5(e,t,n){let r=Eyn(n,0,200,0),i=Oyn(e&&e.trim()!==Cyn?e:``),a=t.toLowerCase(),o=i.filter(e=>!e.toLowerCase().startsWith(`${a}(`));return r>0&&o.push(`${t}(${o5(r)}px)`),o.length>0?o.join(` `):Cyn}function kyn(e){let t=e?.trim()||`none`;for(let[e,n]of Object.entries(wyn))if(t===n)return e;return t===`none`?`none`:`custom`}function Ayn(e,t){return e===`custom`?t?.trim()||`none`:wyn[e]}function jyn(e,t){let n=[[`border-width`,e]],r=s5(e),i=t?.trim().toLowerCase()||`none`;return r&&r.value>0&&(i===`none`||i===`hidden`)&&n.push([`border-style`,`solid`]),n}function Myn(e,t){let n=[[`border-style`,e]],r=e.trim().toLowerCase();if(!r||r===`none`||r===`hidden`)return n;let i=s5(t?.trim()||`0`);return(!i||i.value<=0)&&n.push([`border-width`,`1px`]),n}function Nyn(e,t,n){let r=s5(e);if(!r)return null;let i=n?.altKey?.1:n?.shiftKey?10:1;return`${o5(r.value+i*t)}${r.unit}`}function Pyn(e){if(!e)return``;let t=e.toLowerCase().indexOf(`url(`);if(t<0)return``;let n=t+4;for(;n<e.length&&(e[n]===` `||e[n]===`
334
334
  `||e[n]===`\r`||e[n]===` `||e[n]===`\f`);)n+=1;let r=e[n]===`"`||e[n]===`'`?e[n]:null;if(r){n+=1;let t=e.indexOf(r,n);return t>=n?e.slice(n,t):``}let i=e.indexOf(`)`,n);return i<n?``:e.slice(n,i).trim()}var Fyn=[`x`,`y`,`rotation`,`rotationX`,`rotationY`,`rotationZ`,`z`,`scale`,`transformPerspective`,`opacity`];function Iyn(e){let t=new Set(Fyn);for(let n of e){if(n.keyframes)for(let e of n.keyframes.keyframes)for(let n of Object.keys(e.properties))t.add(n);for(let e of Object.keys(n.properties))t.add(e)}return t}function Lyn(e,t,n,r){if(!e||t.length===0)return null;let i=r?.current;if(!i?.contentWindow)return null;try{let e=i.contentWindow.gsap;if(!e?.getProperty)return null;let r=un(i.contentDocument,n);if(!r)return null;let a=Iyn(t),o=!B0(r,`move`),s={};for(let t of a){if(!o&&z9t.has(t))continue;let n=Number(e.getProperty(r,t));Number.isFinite(n)&&(s[t]=y(n))}return Object.keys(s).length>0?s:null}catch{return null}}function Ryn(e,t,n,r){if((!e||!(`borderRadius`in e))&&!t.some(e=>`borderRadius`in e.properties||e.keyframes?.keyframes.some(e=>`borderRadius`in e.properties)))return null;let i=r?.current;if(!i?.contentDocument)return null;try{let e=un(i.contentDocument,n);if(!e||!i.contentWindow)return null;let t=i.contentWindow.getComputedStyle(e),r=e=>Number.parseFloat(e)||0;return{tl:r(t.borderTopLeftRadius),tr:r(t.borderTopRightRadius),br:r(t.borderBottomRightRadius),bl:r(t.borderBottomLeftRadius)}}catch{return null}}function zyn(e,t,n,r){let i=e.sourceFile??`index.html`,a=null;try{let t=r?.current?.contentDocument?.documentElement?.outerHTML??``;if(t&&e.id){let n=t.indexOf(`id="${e.id}"`);n>-1&&(a=t.slice(0,n).split(`
335
335
  `).length)}if(!a&&e.selector){let n=e.tagName.toLowerCase(),r=e.selector.startsWith(`.`)?e.selector.slice(1).split(`.`)[0]:null,i=r?`class="${r}`:`<${n}`,o=t.indexOf(i);o>-1&&(a=t.slice(0,o).split(`
@@ -359,7 +359,7 @@ ${n}`;return{preview(e,t,a){let s=d(e);n.has(s)||(n.set(s,t()),r.set(s,a),i.has(
359
359
  `;for(let[e,a]of r)e.startsWith(i)&&t.includes(a.path)&&u(e,_An(a,n))}}}function _An({path:e,target:t,attr:n},r){let i=r?.[e]?.restored;return i===void 0||!t?void 0:Y$t(i,t,n)}function vAn(e,t){let n=(0,U.useRef)(t);n.current=t;let[r]=(0,U.useState)(()=>gAn(()=>e.current??``,()=>n.current??``));return r}function yAn(e,t,n,r){let i=e?.contentDocument?.getElementById(t);i&&(r===null?i.removeAttribute(n):i.setAttribute(n,r),N1(e?.contentDocument))}function bAn(e,t){return`${e}\0${t}`}function xAn(e){if(!e)return 1;let t=parseFloat(e);return Number.isFinite(t)?t:1}var SAn={"data-hidden":e=>({audioGroupHidden:e!==null}),"data-volume":e=>({audioGroupVolume:xAn(e)}),"data-label":(e,t)=>({audioGroupLabel:e??t}),[yt]:e=>({audioGroupFxChain:e??void 0}),[s]:e=>({audioGroupAutomation:e??void 0})};function CAn(e,t,n){let r=SAn[t];if(!r)return;let i=r(n,e);X.setState(t=>{let n={elements:t.elements.map(t=>t.audioGroup===e?{...t,...i}:t)};return t.domClipChildren.some(t=>t.audioGroup===e)&&(n.domClipChildren=t.domClipChildren.map(t=>t.audioGroup===e?{...t,...i}:t)),n})}function wAn(e){let t=e?.parentElement??null;for(;t;){let e=t.closest(`[data-composition-id]`);if(!e)return;let n=e.getAttribute(`data-composition-file`)??e.getAttribute(`data-composition-src`);if(n)return n;t=e.parentElement}}function TAn(e,t,n){return{targetPath:wAn(e?.contentDocument?.getElementById(t)??null)||n||`index.html`,patchTarget:_Q({domId:t})}}function EAn(e,t,n,r){let{targetPath:i,patchTarget:a}=TAn(e,t,n);return{path:i,target:a,attr:r}}async function DAn({projectId:e,activeCompPath:t,groupId:n,attr:r,value:i,label:a,previewIframe:o,patchLive:s,onFileRead:c,writeProjectFile:l,recordEdit:u,pendingTimelineEditPathRef:d}){let{targetPath:f,patchTarget:p}=TAn(o,n,t);return p?X$t({projectId:e,targetPath:f,patchTarget:p,attr:r,value:i,label:a,writeProjectFile:l,recordEdit:u,pendingTimelineEditPathRef:d,patchLive:s,onFileRead:c}):null}function OAn({projectIdRef:e,activeCompPath:t,showToast:n,writeProjectFile:r,recordEdit:i,previewIframeRef:a,pendingTimelineEditPathRef:o,isRecordingRef:s}){let c=vAn(e,t),l=(0,U.useCallback)((e,n,r)=>{let i=bAn(e,n),o=a.current?.contentDocument?.getElementById(e);c.preview(i,()=>o?.getAttribute(n)??null,EAn(a.current,e,t,n)),yAn(a.current,e,n,r),CAn(e,n,r)},[c,a,t]),u=(0,U.useCallback)((e,t)=>({preview:n=>yAn(a.current,e,t,n),store:n=>CAn(e,t,n)}),[a]),d=(0,U.useCallback)((e,t,n)=>c.claim(bAn(e,t),u(e,t),n),[c,u]),f=(0,U.useCallback)((e,t)=>c.revert(bAn(e,t),u(e,t)),[c,u]);return{setLive:l,setQuiet:(0,U.useCallback)(async(c,l,u,f)=>{let p=e.current,m=fAn(s?.current,p,n),h=EAn(a.current,c,t,l),g=d(c,l,h),_=async e=>(g.settle(await J$t(p,h.path,h.target,l,r)),e);if(typeof m!=`string`)return _(m);try{return await DAn({projectId:m,activeCompPath:t,groupId:c,attr:l,value:u,label:f,previewIframe:a.current,patchLive:g.preview,onFileRead:g.read,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:o})?(g.settle(u),{status:`saved`}):_(W7(`This group has no id to save it by`,n))}catch(e){return console.error(`[Timeline] Failed to set group attribute`,e),_(W7(e instanceof Error?e.message:`Failed to update group`,n))}},[d,t,a,r,i,o,s,n,e]),revertLive:f,restoreLive:c.restore}}function kAn(e,t,n,r,i){let a=vQ(e,t,i);a&&(r===null?a.removeAttribute(n):a.setAttribute(n,r))}function AAn(e,t,n){return`${e.sourceFile||t||`index.html`}\0${e.key??e.domId??e.id}\0${n}`}function jAn(e,t){return{targetPath:e.sourceFile||t||`index.html`,patchTarget:_Q(e)}}function MAn(e,t,n){let{targetPath:r,patchTarget:i}=jAn(e,t);return{path:r,target:i,attr:n}}async function NAn({projectId:e,activeCompPath:t,element:n,attr:r,value:i,label:a,patchLive:o,onFileRead:s,writeProjectFile:c,recordEdit:l,pendingTimelineEditPathRef:u}){let{targetPath:d,patchTarget:f}=jAn(n,t);return f?X$t({projectId:e,targetPath:d,patchTarget:f,attr:r,value:i,label:a,writeProjectFile:c,recordEdit:l,pendingTimelineEditPathRef:u,patchLive:o,onFileRead:s}):null}function PAn({projectIdRef:e,activeCompPath:t,showToast:n,writeProjectFile:r,recordEdit:i,previewIframeRef:a,pendingTimelineEditPathRef:o,isRecordingRef:s}){let c=vAn(e,t),l=(0,U.useCallback)((e,n,r)=>{let i=AAn(e,t,n),o=vQ(a.current,e,t);c.preview(i,()=>o?.getAttribute(n)??null,MAn(e,t,n)),kAn(a.current,e,n,r,t)},[c,a,t]),u=(0,U.useCallback)((e,n)=>({preview:r=>kAn(a.current,e,n,r,t),store:t=>Lkn(e,n,t)}),[a,t]),d=(0,U.useCallback)((e,n)=>c.claim(AAn(e,t,n),u(e,n),MAn(e,t,n)),[c,u,t]),f=(0,U.useCallback)((e,n)=>c.revert(AAn(e,t,n),u(e,n)),[c,u,t]);return{setLive:l,setQuiet:(0,U.useCallback)(async(a,c,l,u)=>{let f=e.current,p=fAn(s?.current,f,n),m=d(a,c),h=async e=>{let{targetPath:n,patchTarget:i}=jAn(a,t);return m.settle(await J$t(f,n,i,c,r)),e};if(typeof p!=`string`)return h(p);try{return await NAn({projectId:p,activeCompPath:t,element:a,attr:c,value:l,label:u,patchLive:m.preview,onFileRead:m.read,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:o})?(m.settle(l),{status:`saved`}):h(W7(`This clip has no id to save it by`,n))}catch(e){return console.error(`[Timeline] Failed to set element attribute`,e),h(W7(e instanceof Error?e.message:`Failed to update effect`,n))}},[d,t,r,i,o,s,n,e]),revertLive:f,restoreLive:c.restore}}function FAn(e,t){let n=new Map;for(let{element:r,value:i}of e){let e=_Q(r);if(!e)throw Error(`A clip has no id to save it by`);let a=r.sourceFile||t||`index.html`;n.set(a,[...n.get(a)??[],{target:e,value:i}])}return n}function IAn(e,t,n,r){for(let{element:i,value:a}of t){let t=vQ(e,i,r);a===null?t?.removeAttribute(n):t?.setAttribute(n,a),Lkn(i,n,a)}}function LAn({projectIdRef:e,activeCompPath:t,showToast:n,writeProjectFile:r,recordEdit:i,previewIframeRef:a,pendingTimelineEditPathRef:o,isRecordingRef:s}){return(0,U.useCallback)(async(c,l,u)=>{let d=fAn(s?.current,e.current,n);if(typeof d!=`string`)return d;if(c.length===0)return{status:`saved`};try{let e=FAn(c,t),n=Object.fromEntries([...e].map(([e,t])=>[e,e=>t.reduce((e,{target:t,value:n})=>AZ(e,t,{type:`attribute`,property:l,value:n}),e)]));for(let t of e.keys())o.current.add(t);return await PZ({projectId:d,label:u,files:n,readFile:e=>lQ(d,e),writeFile:r,recordEdit:i}),IAn(a.current,c,l,t),{status:`saved`}}catch(e){let t=e instanceof Error?e.message:`Could not save the clips`;return n(t,`error`),{status:`failed`,reason:t}}},[e,t,n,r,i,a,o,s])}function RAn(e,t){if(!t)return e;let n=new Map(t.map(e=>[e.element,e.start]));return e.map(e=>{let t=n.get(e);return t==null?e:{...e,start:t}})}function zAn(e,t){let n=t.map(_Q).filter(e=>e!==null);return n.length>0?d8t(e,n,null):e}function BAn({projectIdRef:e,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:a,reloadPreview:o,isRecordingRef:s,forceReloadSdkSession:c,previewIframeRef:l,handleTimelineGroupMove:u}){let d=(0,U.useRef)(!1),f=(0,U.useCallback)(async(f,p=[])=>{if(s?.current){r(`Cannot edit timeline while recording`,`error`);return}let m=e.current;if(!m)throw Error(`No active project`);let[h]=f;if(!h)return;let g=f.length===1?U0t(h):`${f.length} clips`,_=h.sourceFile||t||`index.html`,v=f.filter(e=>(e.sourceFile||t||`index.html`)===_);try{let e=mQ(`main-track-ripple-delete`),s=`Delete timeline clip`,f=()=>{};try{await FZ({projectId:m,path:_,label:s,...e,writeFile:i,recordEdit:a,rewrite:async e=>{let n=v.map(e=>{let t=_Q(e);if(!t)throw Error(`Timeline element ${e.id} is missing a patchable target`);return t}),r=await H(M(m,`/file-mutations/remove-elements/${encodeURIComponent(_)}`),{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:JSON.stringify({targets:n})});if(!r.ok)throw Error(`Failed to delete ${v.length} clips from ${_}`);let i=await r.json(),a=typeof i.content==`string`?i.content:e,o=V$t(a),s=zAn(o.source,p);return f=dQ(l.current),o.contentEnd>0&&_===(t||`index.html`)&&X.getState().setDuration(o.contentEnd),{disk:a,after:s}}})}catch(e){throw f(),e}R$t(l.current,v,t);let h=new Set(v.map(e=>e.key??e.id)),y=n.filter(e=>!h.has(e.key??e.id)),b=sJt(y,v,X.getState().rippleEditEnabled),x=b?TX(y,b):null;X.getState().setElements(RAn(y,x));let S=!1;if(x)try{await u(x,{coalesceKey:e.coalesceKey,label:s,suppressFailureToast:!0})}catch(e){S=!0,X.getState().setElements(y),console.error(`[Timeline] ripple-edit failed to persist after delete`,e),r(`Clip deleted, but the gap could not be closed.`,`error`)}X.getState().setSelectedElementId(null),X.getState().setSelectedElementIds(new Set),c?.(),o(),S||r(`Deleted ${g}. Use Undo to restore ${v.length===1?`it`:`them`}.`,`info`),x&&!S&&!d.current&&(d.current=!0,r(`Ripple closed the gap on the main track. Undo (⌘Z) restores it, or turn off Ripple in the timeline toolbar.`,`info`))}catch(e){r(e instanceof Error?e.message:`Failed to delete timeline clip`)}},[t,e,a,r,n,i,o,s,c,l,u]);return{handleTimelineElementsDelete:f,handleTimelineElementDelete:(0,U.useCallback)(async e=>{await f([e])},[f])}}function VAn(e,t){let n=mAn(e,t),r=(0,U.useRef)(n);r.current=n;let i=(0,U.useRef)(new WeakMap);return(0,U.useCallback)((e,t,n)=>{let a=t,o=i.current.get(a);if(o)return o.resolveTargets=e,o.onRefused=n,o.wrapped;let s={};return s.resolveTargets=e,s.onRefused=n,s.wrapped=((...e)=>{let n=r.current(s.resolveTargets(...e));return n===null?t(...e):Promise.resolve(s.onRefused?.(n,...e))}),i.current.set(a,s),s.wrapped},[])}var HAn=e=>e.key??e.id;function UAn(e){let t=e.map(_Q);return t.every(e=>e!==null)?t:null}function WAn(e,t){let n=new Set(e.map(HAn)),r=new Map;for(let i of e){let e=t.filter(e=>Oq(e,i)&&!n.has(HAn(e)));e.length===1&&e[0]&&r.set(HAn(e[0]),e[0])}return[...e.filter(e=>e.link),...r.values()]}function GAn(e){let t=_Q(e.element);if(!t)return null;if(e.kind===`move-into-sync`){let n=ZK(LK(e.element,e.start));return{label:`Move into Sync`,anchor:e.element,transform:e=>bQ(AZ(e,t,{type:`attribute`,property:`start`,value:n}))}}let n=e.element.playbackStartAttr??`media-start`,r=ZK(e.mediaStart);return{label:`Slip into Sync`,anchor:e.element,transform:e=>AZ(e,t,{type:`attribute`,property:n,value:r})}}function KAn(e,t){switch(e.kind){case`unlink`:{let n=WAn(e.elements,t),r=UAn(n),i=n[0];return!r||!i?null:{label:`Unlink clips`,anchor:i,transform:e=>d8t(e,r,null)}}case`link`:{let t=UAn(e.elements),n=e.elements[0];return!t||!n?null:{label:`Link clips`,anchor:n,transform:n=>f8t(n,t,{syncOrigin:S8t(e.elements)})}}case`detach`:{let n=_Q(e.element);if(!n)return null;let r=w8t(t,e.element);return{label:`Detach audio`,anchor:e.element,transform:t=>m8t(t,{target:n,videoId:e.element.domId??null,track:r})?.html??null}}case`move-into-sync`:case`slip-into-sync`:return GAn(e);case`merge`:{let t=_Q(e.video),n=_Q(e.audio);return!t||!n?null:{label:`Merge audio back into video`,anchor:e.video,transform:e=>h8t(e,{videoTarget:t,audioTarget:n})}}}}var G7=e=>e.key??e.id;function qAn(e){switch(e.kind){case`unlink`:case`link`:return[...e.elements];case`detach`:case`move-into-sync`:case`slip-into-sync`:return[e.element];case`merge`:return[e.video,e.audio]}}function K7(e){let t=X.getState().elements,n=Aq(e.map(G7),t,Pq()),r=new Set(e.map(G7));return[...e,...t.filter(e=>n.has(G7(e))&&!r.has(G7(e)))]}function JAn(e){e.kind===`unlink`&&X.getState().clearSelection()}function YAn({projectIdRef:e,activeCompPath:t,editQueueRef:n,pendingTimelineEditPathRef:r,isRecordingRef:i,showToast:a,writeProjectFile:o,recordEdit:s,reloadPreview:c,forceReloadSdkSession:l,handleTimelineElementsDelete:u}){let d=(0,U.useCallback)(async u=>{if(i?.current){a(`Cannot edit timeline while recording`,`error`);return}let d=e.current,f=KAn(u,X.getState().elements);if(!d||!f)return;JAn(u);let p=f.anchor.sourceFile||t||`index.html`;r.current.add(p);let m=n.current.then(()=>PZ({projectId:d,label:f.label,files:{[p]:e=>{let t=f.transform(e);if(t===null||t===e)throw Error(`Couldn't ${f.label.toLowerCase()}`);return t}},readFile:e=>lQ(d,e),writeFile:o,recordEdit:s}));n.current=m.then(()=>void 0,()=>void 0);try{await m,l?.(),c()}catch(e){a(QY(e),`error`)}},[t,n,l,i,r,e,s,c,a,o]),f=(0,U.useCallback)(e=>{if(Pq())return u(K7(e));let t=new Set(e.map(G7));return u(e,WAn(e,X.getState().elements).filter(e=>!t.has(G7(e))))},[u]);return{handleLinkEdit:d,handleLinkedElementsDelete:f,handleLinkedElementDelete:(0,U.useCallback)(e=>f([e]),[f]),handleDeleteElementOnly:(0,U.useCallback)(e=>{let t=WAn([e],X.getState().elements).filter(t=>G7(t)!==G7(e));return u([e],t)},[u])}}function XAn(){let e=(0,U.useRef)(new WeakMap);return(0,U.useCallback)(t=>{let n=t,r=e.current.get(n);if(r)return r;let i=pX(t);return e.current.set(n,i),i},[])}function ZAn(e,t){return e.sourceFile||t||`index.html`}function QAn(e,t,n,r){for(let i of t){let t=vQ(e,i,r);t&&(n?t.setAttribute(`data-hidden`,``):t.removeAttribute(`data-hidden`))}}function q7(e){let t=X.getState();XZ(e,t.currentTime)||N7t({seek:t.requestSeek},t.currentTime)}function $An(e,t){let n=new Map;for(let r of e){let e=ZAn(r,t),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}async function ejn({projectId:e,activeCompPath:t,elements:n,hidden:r,label:i,previewIframe:a,writeProjectFile:o,recordEdit:s,pendingTimelineEditPathRef:c}){if(n.length===0)return[];QAn(a,n,r,t),q7(a);let l={type:`attribute`,property:`hidden`,value:r?``:null},u={};for(let[e,r]of $An(n,t))u[e]=t=>(c.current.add(e),xQ(t,e,K$t(r,l)));try{let t=await PZ({projectId:e,label:i,files:u,readFile:t=>lQ(e,t),writeFile:o,recordEdit:s});for(let e of n)X.getState().updateElement(e.key??e.id,{hidden:r});return t}catch(e){throw QAn(a,n,!r,t),q7(a),e}}async function tjn({projectId:e,activeCompPath:t,timelineElements:n,track:r,hidden:i,displayNumber:a,previewIframe:o,writeProjectFile:s,recordEdit:c,pendingTimelineEditPathRef:l}){let u=y$(a??G2t(v$(n),r)),d=n.filter(e=>e.track===r),f=!i;return ejn({projectId:e,activeCompPath:t,elements:d,hidden:i,label:`${b$(TG(d),f)} track${u}`,previewIframe:o,writeProjectFile:s,recordEdit:c,pendingTimelineEditPathRef:l})}async function njn({projectId:e,activeCompPath:t,timelineElements:n,elementKey:r,hidden:i,previewIframe:a,writeProjectFile:o,recordEdit:s,pendingTimelineEditPathRef:c}){let l=new Set(typeof r==`string`?[r]:r),u=n.filter(e=>l.has(e.key??e.id)),d=!i,f=b$(TG(u),d);return ejn({projectId:e,activeCompPath:t,elements:u,hidden:i,label:u.length>1?`${f} ${u.length} elements`:`${f} element`,previewIframe:a,writeProjectFile:o,recordEdit:s,pendingTimelineEditPathRef:c})}function rjn({projectIdRef:e,activeCompPath:t,showToast:n,writeProjectFile:r,recordEdit:i,previewIframeRef:a,pendingTimelineEditPathRef:o,isRecordingRef:s,forceReloadSdkSession:c}){let l=X(e=>e.elements);return(0,U.useCallback)(async(u,d,f)=>{if(s?.current){n(`Cannot edit timeline while recording`,`error`);return}let p=e.current;if(p)try{await tjn({projectId:p,activeCompPath:t,timelineElements:l,track:u,hidden:d,displayNumber:f,previewIframe:a.current,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:o}),c?.()}catch(e){console.error(`[Timeline] Failed to toggle track visibility`,e),n(e instanceof Error?e.message:`Failed to toggle track visibility`)}},[t,l,a,r,i,o,s,n,c,e])}function ijn({projectIdRef:e,activeCompPath:t,showToast:n,writeProjectFile:r,recordEdit:i,previewIframeRef:a,pendingTimelineEditPathRef:o,isRecordingRef:s,forceReloadSdkSession:c}){let l=X(e=>e.elements);return(0,U.useCallback)(async(u,d)=>{if(s?.current){n(`Cannot edit timeline while recording`,`error`);return}let f=e.current;if(!f)return;let p=typeof u==`string`?[u]:u;if(!l.some(e=>p.includes(e.key??e.id))){n(`This element is inside a sub-composition and has no timeline row to hide.`);return}try{await njn({projectId:f,activeCompPath:t,timelineElements:l,elementKey:u,hidden:d,previewIframe:a.current,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:o}),c?.()}catch(e){console.error(`[Timeline] Failed to toggle element visibility`,e),n(e instanceof Error?e.message:`Failed to toggle element visibility`)}},[t,l,a,r,i,o,s,n,c,e])}function ajn(e,t){if(e&&!e(t))throw Error(`Timeline edit blocked`)}function ojn(e,t,n,r,i){for(let a of t){let t=vQ(e,a,r);if(!t)continue;let o=i?i.get(a)??null:n;o?t.setAttribute(Re,o):t.removeAttribute(Re)}N1(e?.contentDocument)}function sjn(e,t,n){let r=new Map;for(let i of t){let t=vQ(e,i,n);r.set(i,t?.getAttribute(`data-audio-group`)??null)}return r}var cjn=/^[A-Za-z0-9_-]+$/;function ljn(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`)}function ujn(e,t,n){let r=kZ(e,{id:t});if(r!==void 0){if(RegExp(`^<\\s*hf-audio-group\\b`,`i`).test(r))return e;throw Error(`Cannot create audio group: id ${t} is already used in this file`)}let i=n?` data-label="${ljn(n)}"`:``,a=`<${Fe} id="${t}"${i}></${Fe}>`,o=e.lastIndexOf(`</body>`);return o<0?`${e}
360
360
  ${a}
361
361
  `:`${e.slice(0,o)} ${a}
362
- ${e.slice(o)}`}function djn(e,t,n){let r=e?.contentDocument;if(!r?.body||r.getElementById(t))return!1;let i=r.createElement(Fe);return i.id=t,n&&i.setAttribute(`data-label`,n),r.body.appendChild(i),N1(r),!0}async function fjn({projectId:e,activeCompPath:t,elements:n,groupId:r,groupLabel:i,previewIframe:a,writeProjectFile:o,recordEdit:s,pendingTimelineEditPathRef:c}){if(n.length<2)throw Error(`Cannot group ${n.length} clip(s) \u2014 a group needs at least two`);if(!cjn.test(r))throw Error(`Invalid audio group id ${JSON.stringify(r)}`);let l=sjn(a,n,t);ojn(a,n,r,t);let u=djn(a,r,i);q7(a);let d={type:`attribute`,property:Re,value:r},f=t||`index.html`,p=$An(n,t),m={};for(let e of new Set([...p.keys(),f]))m[e]=t=>{let n=xQ(t,e,K$t(p.get(e)??[],d));return e===f&&(n=ujn(n,r,i)),n!==t&&c.current.add(e),n};try{let t=await PZ({projectId:e,label:i?`Group ${n.length} clips as ${i}`:`Group ${n.length} voice clips`,files:m,readFile:t=>lQ(e,t),writeFile:o,recordEdit:s});for(let e of n)X.getState().updateElement(e.key??e.id,{audioGroup:r});return t}catch(e){throw ojn(a,n,null,t,l),u&&a?.contentDocument?.getElementById(r)?.remove(),q7(a),e}}function pjn({projectIdRef:e,activeCompPath:t,showToast:n,writeProjectFile:r,recordEdit:i,previewIframeRef:a,pendingTimelineEditPathRef:o,isRecordingRef:s,checkEditable:c}){let l=X(e=>e.elements);return(0,U.useCallback)(async(u,d,f)=>{if(s?.current){n(`Cannot edit timeline while recording`,`error`);return}let p=e.current;if(!p)return;let m=new Set(u),h=l.filter(e=>{let t=Ct(e);return t!==null&&m.has(t)});h.length===m.size&&ajn(c,h);try{if(h.length!==m.size){let e=[...m].filter(e=>!h.some(t=>Ct(t)===e));throw Error(`Cannot group: no timeline clip for ${e.join(`, `)}`)}await fjn({groupLabel:f,projectId:p,activeCompPath:t,elements:h,groupId:d,previewIframe:a.current,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:o})}catch(e){throw console.error(`[Timeline] Failed to group voice clips`,e),n(e instanceof Error?e.message:`Failed to group voice clips`),e}},[t,l,a,r,i,o,s,n,e,c])}function J7(e,t){return e.sourceFile||t||`index.html`}function mjn(e,t){let n=e[0]?J7(e[0].element,t):null;return n&&e.every(e=>J7(e.element,t)===n)?n:null}function hjn(e,t){return e.map(e=>e.element.hfId?{hfId:e.element.hfId,timingUpdate:t(e)}:null)}function gjn(e){return e.playbackStart!=null||e.start!==e.element.start&&e.element.playbackStart!=null}function _jn({activeCompPath:e,editQueueRef:t,forceReloadSdkSession:n,invalidateGsapCache:r,isRecordingRef:i,pendingTimelineEditPathRef:a,previewIframeRef:o,projectIdRef:s,recordEdit:c,reloadPreview:l,sdkSession:u,publishSdkSession:d,showToast:f,writeProjectFile:p}){let m=(0,U.useCallback)((e,n)=>{if(i?.current)return f(`Cannot edit timeline while recording`,`error`),Promise.reject(Error(`${e}: blocked while recording`));let r=s.current;if(!r)return Promise.reject(Error(`${e}: no active project`));let a=t.current.then(()=>n(r));return t.current=a.then(()=>void 0,t=>{console.error(`[Timeline] Failed to persist: ${e}`,t)}),a},[t,i,s,f]),h=(0,U.useCallback)(async(t,r,i,o,s)=>{await q$t({projectId:t,activeCompPath:e,label:r,changes:i,writeProjectFile:p,recordEdit:c,pendingTimelineEditPathRef:a,coalesceKey:o,coalesceMs:s}),n?.()},[e,n,a,c,p]),g=(0,U.useCallback)(async t=>{let n=mjn(t.changes,e);if(!(!t.needsExtension&&n!==null&&t.eligible&&t.sdkChanges.every(e=>e!==null)))return null;let r=await Ddn(t.sdkChanges.filter(e=>e!==null),n,u,{editHistory:{recordEdit:c},writeProjectFile:p,reloadPreview:l,compositionPath:e,readProjectFile:e=>lQ(s.current??``,e),publishSession:d},{label:t.label,coalesceKey:t.coalesceKey,coalesceMs:t.coalesceMs,skipRefresh:!0});return F6(r)?{sdkGsap:hQ(r)}:null},[e,s,d,c,l,u,p]);return{handleTimelineGroupMove:(0,U.useCallback)((t,n)=>{if(t.length===0)return Promise.resolve();for(let n of t){let t=[[`data-start`,XK(LK(n.element,n.start))]];n.track!=null&&t.push([`data-track-index`,XK(n.track)]),yQ(o.current,n.element,t,e)}let i=t.every(e=>e.start===e.element.start),a=Math.max(...t.map(e=>e.start+e.element.duration)),s=dQ(o.current),u=gQ(a);uQ(o.current);let{coalesceKey:d,coalesceMs:_}=mQ(`timeline-group-move`,n),v=n?.label??`Move timeline clips`;return m(v,async a=>{await n?.beforeTiming;let s=await g({changes:t,sdkChanges:hjn(t,e=>({start:LK(e.element,e.start)})),eligible:t.every(e=>e.track==null&&e.audioGroup===void 0),needsExtension:u,label:v,coalesceKey:d,coalesceMs:_});if(s||await h(a,v,t.map(e=>({element:e.element,buildPatches:(t,n)=>B$t(t,n,LK(e.element,e.start),e.element.duration,e.track,e.audioGroup)})),d,_),!i)try{await P$t({projectId:a,iframe:o.current,reloadPreview:l,label:v,errorLabel:`Failed to shift GSAP positions`,coalesceKey:d,recordEdit:c,writeProjectFile:p,activeCompPath:e,changes:t,sdkGsap:s?.sdkGsap,resolveChangePath:t=>J7(t,e),mutationFor:e=>k$t(e.element.domId,e.start-e.element.start)})}finally{r?.()}}).catch(e=>{throw s(),n?.suppressFailureToast?console.error(`[Timeline] group move failed to persist`,e):f(QY(e),`error`),e})},[e,m,h,o,c,l,g,f,r,p]),handleTimelineGroupResize:(0,U.useCallback)((t,n)=>{if(t.length===0)return Promise.resolve();for(let n of t){let t=[[`data-start`,XK(LK(n.element,n.start))],[`data-duration`,XK(n.duration)]];if(n.playbackStart!=null){let e=kt(n.element);t.push([e,ZK(n.playbackStart)])}yQ(o.current,n.element,t,e)}let i=Math.max(...t.map(e=>e.start+e.duration)),a=dQ(o.current),s=gQ(i);uQ(o.current);let{coalesceKey:u,coalesceMs:d}=mQ(`timeline-group-resize`,n);return m(`Resize timeline clips`,async i=>{await n?.beforeTiming;let a=await g({changes:t,sdkChanges:hjn(t,e=>({start:LK(e.element,e.start),duration:e.duration})),eligible:t.every(e=>!gjn(e)),needsExtension:s,label:`Resize timeline clips`,coalesceKey:u,coalesceMs:d});a||await h(i,`Resize timeline clips`,t.map(e=>({element:e.element,buildPatches:(t,n)=>U$t(t,n,e.element,{start:e.start,duration:e.duration,playbackStart:e.playbackStart})})),u,d);try{await P$t({projectId:i,iframe:o.current,reloadPreview:l,label:`Resize timeline clips`,errorLabel:`Failed to scale GSAP positions`,coalesceKey:u,recordEdit:c,writeProjectFile:p,activeCompPath:e,changes:t,sdkGsap:a?.sdkGsap,resolveChangePath:t=>J7(t,e),mutationFor:e=>A$t(e.element.domId,RK(e.element,e.element.start),e.element.duration,RK(e.element,e.start),e.duration)})}finally{r?.()}}).catch(e=>{throw a(),f(QY(e),`error`),e})},[e,m,h,o,c,l,g,f,r,p])}}function vjn({activeCompPath:e,timelineElements:t,showToast:n,writeProjectFile:r,recordEdit:i,reloadPreview:a,previewIframeRef:o,pendingTimelineEditPathRef:s,isRecordingRef:c,sdkSession:l,publishSdkSession:u,forceReloadSdkSession:d,invalidateGsapCache:f,handleDomZIndexReorderCommitRef:p,editQueueRef:m,projectIdRef:h}){let g=(0,U.useCallback)((t,a,o,l)=>{if(c?.current)return n(`Cannot edit timeline while recording`,`error`),Promise.resolve();let u=h.current;if(!u)return Promise.resolve();let f=m.current.then(()=>G$t({projectId:u,element:t,activeCompPath:e,label:a,buildPatches:o,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:s,...l})).then(()=>{d?.()});return m.current=f.catch(e=>{console.error(`[Timeline] Failed to persist: ${a}`,e)}),f},[e,i,r,s,n,c,d,m,h]);return{handleTimelineElementMove:(0,U.useCallback)((s,c)=>{let d=()=>{let d=s.sourceFile||e||`index.html`,m=c.start!==s.start,_=c.track!==s.track,v=LK(s,c.start);if(m||_){let t=[];m&&t.push([`data-start`,XK(v)]),_&&t.push([`data-track-index`,XK(c.track)]),yQ(o.current,s,t,e)}let y=L$t({element:s,stackingReorder:c.stackingReorder,timelineElements:t,iframe:o.current,activeCompPath:e,commit:p?.current});if(!m&&!_)return y;let b=dQ(o.current),x=gQ(c.start+s.duration);uQ(o.current);let S=(e,t)=>{let n=_?c.track:void 0;return H$t(e,t,v,s.duration,n)},C=mQ(`timeline-move`),w=e=>N$t({iframe:o.current,reloadPreview:a,projectId:h.current,targetPath:d,domId:s.domId,label:`Move timeline clip`,coalesceKey:C.coalesceKey,recordEdit:i,writeProjectFile:r,edit:{kind:`shift`,delta:c.start-s.start},sdkGsap:e}).finally(()=>f?.()),T=()=>g(s,`Move timeline clip`,S,C).then(()=>w());return y.then(()=>l&&s.hfId&&!s.link&&!x&&!_?Edn(s.hfId,d,{start:v},l,{editHistory:{recordEdit:i},writeProjectFile:r,reloadPreview:a,compositionPath:e,readProjectFile:e=>lQ(h.current??``,e),publishSession:u},{label:`Move timeline clip`,...C,skipRefresh:!0}).then(e=>F6(e)?w(hQ(e)):T()):T()).catch(e=>{throw b(),n(QY(e),`error`),e})};return c.stackingReorder?KY(d):d()},[o,g,e,l,u,i,r,a,t,p,n,f,h]),handleTimelineElementResize:(0,U.useCallback)((t,s)=>{let c=LK(t,s.start),d=[[`data-start`,XK(c)],[`data-duration`,XK(s.duration)]];if(s.playbackStart!=null){let e=kt(t);d.push([e,ZK(s.playbackStart)])}yQ(o.current,t,d,e);let p=dQ(o.current),m=gQ(s.start+s.duration);uQ(o.current);let _=t.sourceFile||e||`index.html`,v=(e,n)=>W$t(e,n,t,s),y=s.playbackStart!=null||s.start!==t.start&&t.playbackStart!=null,b=mQ(`timeline-resize`),x=e=>N$t({iframe:o.current,reloadPreview:a,projectId:h.current,targetPath:_,domId:t.domId,label:`Resize timeline clip`,coalesceKey:b.coalesceKey,recordEdit:i,writeProjectFile:r,edit:{kind:`scale`,from:{start:RK(t,t.start),duration:t.duration},to:{start:RK(t,s.start),duration:s.duration}},sdkGsap:e}).finally(()=>f?.()),S=()=>g(t,`Resize timeline clip`,v,b).then(()=>x());return(l&&t.hfId&&!t.link&&!y&&!m?Edn(t.hfId,_,{start:c,duration:s.duration},l,{editHistory:{recordEdit:i},writeProjectFile:r,reloadPreview:a,compositionPath:e,readProjectFile:e=>lQ(h.current??``,e),publishSession:u},{label:`Resize timeline clip`,...b,skipRefresh:!0}).then(e=>F6(e)?x(hQ(e)):S()):S()).catch(e=>{throw p(),n(QY(e),`error`),e})},[o,g,e,l,u,i,r,a,n,f,h])}}var yjn=1500;function bjn(e){let t=(0,U.useRef)(0);return(0,U.useCallback)(n=>{let r=Date.now();r-t.current<yjn||(t.current=r,e(`This clip can't be moved or resized from the timeline yet.`,`info`))},[e])}function xjn({projectId:e,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,observeProjectFileVersion:a,recordEdit:o,reloadPreview:s,previewIframeRef:c,pendingTimelineEditPathRef:l,uploadProjectFiles:u,isRecordingRef:d,sdkSession:f,publishSdkSession:p,forceReloadSdkSession:m,invalidateGsapCache:h,handleDomZIndexReorderCommitRef:g,canEdit:_}){let v=(0,U.useRef)(e);v.current=e;let y=(0,U.useRef)(Promise.resolve()),b=XAn(),x=hAn(_,r),S=VAn(_,r),C=_jn({activeCompPath:t,editQueueRef:y,forceReloadSdkSession:m,invalidateGsapCache:h,isRecordingRef:d,pendingTimelineEditPathRef:l,previewIframeRef:c,projectIdRef:v,recordEdit:o,reloadPreview:s,sdkSession:f,publishSdkSession:p,showToast:r,writeProjectFile:i}),{handleTimelineElementMove:w,handleTimelineElementResize:T}=vjn({activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,sdkSession:f,publishSdkSession:p,forceReloadSdkSession:m,invalidateGsapCache:h,handleDomZIndexReorderCommitRef:g,editQueueRef:y,projectIdRef:v}),E=rjn({projectIdRef:v,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,forceReloadSdkSession:m}),D=ijn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,forceReloadSdkSession:m}),O=pjn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,checkEditable:x}),k=PAn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d}),A=LAn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d}),j=OAn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d}),{handleTimelineElementsDelete:M}=BAn({projectIdRef:v,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,isRecordingRef:d,forceReloadSdkSession:m,previewIframeRef:c,handleTimelineGroupMove:C.handleTimelineGroupMove}),{handleTimelineAssetDrop:N,handleTimelineFileDrop:P,handleTimelineCompositionDrop:F}=dAn({projectIdRef:v,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,uploadProjectFiles:u,isRecordingRef:d,forceReloadSdkSession:m,observeProjectFileVersion:a,checkEditable:x}),I=YAn({projectIdRef:v,activeCompPath:t,editQueueRef:y,pendingTimelineEditPathRef:l,isRecordingRef:d,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,forceReloadSdkSession:m,handleTimelineElementsDelete:M}),L=bjn(r),{handleRazorSplit:R,handleRazorSplitAll:z,handleFreezeFrame:B}=nAn({projectId:e,activeCompPath:t,showToast:r,writeProjectFile:i,observeProjectFileVersion:a,recordEdit:o,reloadPreview:s,isRecordingRef:d,forceReloadSdkSession:m}),V=e=>({status:`refused`,reason:e}),ee=e=>{let t=X.getState(),n=t.elements.filter(t=>t.audioGroup===e),r=t.domClipChildren.filter(t=>t.audioGroup===e).map(e=>({id:e.id,domId:e.id,tag:`div`,start:0,duration:0,track:-1}));return[...n,...r]},te=N7({...j,setQuiet:b(S(ee,j.setQuiet,(e,t,n)=>(j.revertLive(t,n),V(e))))},e),H=N7({...k,setMany:b(S(e=>e.map(e=>e.element),A)),setQuiet:b(S(e=>[e],k.setQuiet,(e,t,n)=>(k.revertLive(t,n),V(e))))},e),ne=b(S(e=>K7([e]),R));return N7({handleTimelineElementMove:b(S(e=>[e],w)),handleTimelineElementResize:b(S(e=>[e],T)),handleToggleTrackHidden:b(S(e=>n.filter(t=>t.track===e),E)),handleToggleElementHidden:b(S(e=>{let t=new Set(Array.isArray(e)?e:[e]);return n.filter(e=>t.has(e.key??e.id))},D)),handleAutoGroupCarveSources:b(O),setAudioGroupAttribute:te,setElementFxAttribute:H,handleTimelineElementDelete:b(S(e=>K7([e]),I.handleLinkedElementDelete)),handleTimelineElementsDelete:b(S(K7,I.handleLinkedElementsDelete)),handleTimelineElementDeleteOnly:b(S(e=>[e],I.handleDeleteElementOnly)),handleLinkEdit:b(S(qAn,I.handleLinkEdit)),handleTimelineElementSplit:ne,handleRazorSplit:ne,handleFreezeFrame:b(S(e=>[e],B)),handleRazorSplitAll:b(S(e=>w1t(X.getState().elements,e),z)),handleTimelineAssetDrop:b(N),handleTimelineFileDrop:b(P),handleTimelineCompositionDrop:b(F),handleBlockedTimelineEdit:L,handleTimelineGroupMove:b(S(e=>e.map(e=>e.element),C.handleTimelineGroupMove)),handleTimelineGroupResize:b(S(e=>e.map(e=>e.element),C.handleTimelineGroupResize)),restoreLiveLanes:e=>{k.restoreLive(e),j.restoreLive(e)}},e)}function Sjn(e,t,n,r){return r.handleTimelineGroupMove(e.map(({element:e,updates:t})=>({element:e,start:t.start,audioGroup:t.audioGroup,track:n===`timing`?void 0:t.track})),{coalesceKey:t})}function Cjn(e){return(0,U.useCallback)(async(t,n,r=`timing`)=>{await Sjn(t,n,r,{handleTimelineGroupMove:e})},[e])}function wjn({activeCompPath:e,projectDir:t,projectIdRef:n,showToast:r,domEditSelectionRef:i,domEditSelection:a}){let[o,s]=(0,U.useState)(),[c,l]=(0,U.useState)(),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(!1),g=(0,U.useRef)(null),_=(0,U.useCallback)(async t=>{let r=n.current;if(!r)return;let a=t.sourceFile||e||`index.html`;try{let e=await H(M(r,`/files/${encodeURIComponent(a)}`));if(!e.ok)return;let n=(await e.json()).content,o=typeof n==`string`?kZ(n,t):void 0;s(e=>i.current===t?o:e)}catch{}},[e,i,n]),v=(0,U.useCallback)(()=>{a&&(s(void 0),l(void 0),d(null),_(a),h(!0))},[a,_]),y=(0,U.useCallback)(async n=>{if(!a)return;let i=a.sourceFile||e||`index.html`,s=o??vQt(a.element);if(!await U$(B6t({selection:a,currentTime:X.getState().currentTime,timeline:jfn(X.getState().elements),tagSnippet:s,selectionContext:c,userInstruction:n,sourceFilePath:q0t(t,i)}))){r(`Could not copy prompt to clipboard.`,`error`);return}h(!1),l(void 0),d(null),g.current&&clearTimeout(g.current),p(!0),g.current=setTimeout(()=>p(!1),1600)},[e,c,o,a,t,r]);return(0,U.useEffect)(()=>{s(void 0),l(void 0),d(null),p(!1)},[a]),(0,U.useEffect)(()=>()=>{g.current&&clearTimeout(g.current)},[]),{agentModalOpen:m,agentModalAnchorPoint:u,copiedAgentPrompt:f,agentPromptSelectionContext:c,setAgentModalOpen:h,setAgentPromptSelectionContext:l,setAgentModalAnchorPoint:d,preloadAgentPromptSnippet:_,handleAskAgent:v,handleAgentModalSubmit:y}}function Y7(e,t){return e===t?!0:!e||!t?!1:sn(e)===sn(t)}function Tjn(e,t){return rpn(e,t)}function X7(e,t){return t?e.some(e=>Y7(e,t)):!1}function Ejn(e,t){return X7(e,t)?e.filter(e=>!Y7(e,t)):[...e,t]}function Djn(e,t){let n=!1,r=e.map(e=>Y7(e,t)?(n=!0,t):e);return n?r:[...e,t]}function Z7(e,t){return!t||X7(e,t)?e:[t,...e]}function Ojn(e){let t=Number(e);return Number.isFinite(t)&&t>=0?t:0}function kjn(e){let t={idle:0,loading:0,ready:0,fallback:0,error:0};for(let n of e.querySelectorAll(`[data-timeline-poster-state]`)){let e=n.dataset.timelinePosterState;e&&Object.hasOwn(t,e)&&(t[e]+=1)}return Object.freeze(t)}function Ajn(e){let t=new Map;for(let n of e.querySelectorAll(`[data-clip="true"]`)){let e=n.closest(`[data-timeline-row]`);e&&t.set(e,(t.get(e)??0)+1)}return Math.max(0,...t.values())}function jjn(e,t,n){let r=0;for(let i of e.querySelectorAll(t))r+=Ojn(i.dataset[n]);return r}function Mjn(e=document){let t=e.querySelectorAll(`[aria-label="Timeline track view"]`),n=0;for(let e of t)n+=e.querySelectorAll(`*`).length;return Object.freeze({timelineRoots:t.length,mountedRows:e.querySelectorAll(`[data-timeline-row]`).length,mountedClipRoots:e.querySelectorAll(`[data-clip="true"]`).length,maxMountedClipRootsInOneRow:Ajn(e),mountedTimeGridCells:e.querySelectorAll(`[data-timeline-grid-cell]`).length,mountedTimelineDescendants:n,schedulerQueued:jjn(e,`[data-timeline-scheduler-queued]`,`timelineSchedulerQueued`),schedulerActive:jjn(e,`[data-timeline-scheduler-active]`,`timelineSchedulerActive`),cacheBytes:jjn(e,`[data-timeline-cache-bytes]`,`timelineCacheBytes`),posterStates:kjn(e)})}function Njn(){try{return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_HYPERFRAMES_NO_TELEMETRY:`1`}}catch{return}}var Pjn=Njn(),Fjn=Pjn?.DEV?`development`:`production`,Ijn=Pjn?.DEV===!0||Pjn?.MODE===`development`;function Ljn({previewIframeRef:e,buildDomSelectionFromTarget:t,applyDomSelection:n}){(0,U.useEffect)(()=>{if(!(!Ijn||typeof window>`u`))return window.__studioTest={runtimeMode:Fjn,selectByDomId:async r=>{let i=e.current?.contentDocument?.getElementById(r)??null;if(!i)return!1;let a=await t(i);return a?(n(a,{revealPanel:!0}),!0):!1},loadTimelinePerformanceFixture:e=>{let t=stn(e);return etn(!0),X.setState({...tx(),currentTime:0,duration:t.summary.duration,timelineReady:!0,loopEnabled:!1,zoomMode:`manual`,manualZoomPercent:2e3,elements:t.elements,selectedElementId:null,selectedElementIds:new Set,selectedKeyframes:new Set,keyframeCache:t.keyframeCache,gsapAnimations:t.gsapAnimations,expandedClipIds:t.expandedClipIds}),t.summary},resetTimelinePerformanceFixture:()=>{X.getState().reset()},readTimelinePerformanceDiagnostics:()=>Mjn(),timelineViewportBudgets:iK},()=>{delete window.__studioTest}},[n,t,e])}function Rjn(e,t,n,r=!1){let{timelineElements:i,getTimelineSelectionSet:a,setSelectedTimelineElementId:o,setTimelineSelectionSet:s}=e;if(!n){s(new Set),o(null);return}let c=e=>QQ(e,i)??s2t(e.element,i,e.sourceFile||`index.html`),l=t.map(c).filter(e=>!!e),u=c(n),d=new Set(l);u&&d.add(u);let f=u??l[0]??null;if(K4(`announce`,{group:t.length,published:d.size,anchor:u,anchorPublished:u!=null&&d.has(u)}),!f){n.tagName.toLowerCase()===`hf-audio-group`&&(s(new Set),o(null));return}(r||t.length>1||!a().has(f))&&s(d),o(f,{preserveSet:!0})}function zjn({projectId:e,activeCompPath:t,isMasterView:n,compIdToSrc:r,captionEditMode:i,previewIframeRef:a,timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:l,setTimelineSelectionSet:u,setRightCollapsed:d,setRightPanelTab:f,previewIframe:p,refreshKey:m,rightPanelTab:h}){let[g,_]=(0,U.useState)(null),[v,y]=(0,U.useState)([]),[b,x]=(0,U.useState)(null),[S,C]=(0,U.useState)(null),w=(0,U.useRef)(h);w.current=h;let T=(0,U.useRef)(g),E=(0,U.useRef)(v),D=(0,U.useRef)(b),O=(0,U.useRef)(S),k=(0,U.useRef)({activeCompPath:t,projectId:e}),A=(0,U.useRef)(0);T.current=g,E.current=v,D.current=b,O.current=S;let j=(0,U.useCallback)((e,t,n)=>Rjn({timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:l,setTimelineSelectionSet:u},e,t,n),[s,l,u,o]),M=(0,U.useCallback)((e,t)=>{if(!e){K4(`clear`,{hadGroup:E.current.length}),T.current=null,E.current=[],_(null),y([]),t?.announce!==!1&&j([],null);return}let n=!!t?.additive,r=T.current,i=E.current,a=!n&&!t?.preserveGroup&&i.length===1&&Y7(r,e)&&Y7(i[0],e);if(t?.preserveGroup&&r!==null&&(i.length===0||i.includes(r))&&Tjn(r,e))return;if(a){t?.revealPanel!==!1&&(d(!1),w.current!==`variables`&&f(`design`));return}let o=n?Z7(i,r):i,s=X7(o,e),c=t?.preserveGroup?Djn(o,e):n?Ejn(o,e):[e],l=t?.preserveGroup?e:n&&s?Y7(r,e)?c[0]??null:X7(c,r)?r:c[0]??null:e;K4(`apply`,{additive:n,target:e.selector??e.id??null,wasInGroup:s,prevGroup:i.length,nextGroup:c.length}),T.current=l,E.current=c,_(l),y(c);let u=O.current;if(u&&l&&!u.contains(l.element)&&(O.current=null,C(null)),l){t?.revealPanel!==!1&&(d(!1),w.current!==`variables`&&f(`design`)),j(c,l,n);return}j([],null)},[j,d,f]),N=(0,U.useCallback)(()=>{M(null,{revealPanel:!1})},[M]),P=(0,U.useCallback)(e=>{O.current!==e&&(O.current=e,C(e),M(null,{revealPanel:!1}))},[M]),F=(0,U.useCallback)((r,i)=>c(r,{activeCompositionPath:t,isMasterView:n,preferClipAncestor:i?.preferClipAncestor,skipSourceProbe:i?.skipSourceProbe,exactTarget:i?.exactTarget,previous:i?.previous,activeGroupElement:i&&`activeGroupElement`in i?i.activeGroupElement:O.current,projectId:e}),[t,n,e]),I=(0,U.useCallback)(async(e,n,r)=>{let o=a.current;if(!o||i)return null;try{o.contentDocument&&a3(o.contentDocument)}catch{}let s=v4(o,e,n,t);return s?F(s,r&&`activeGroupElement`in r?{preferClipAncestor:r.preferClipAncestor,skipSourceProbe:r.skipSourceProbe,activeGroupElement:r.activeGroupElement}:{preferClipAncestor:r?.preferClipAncestor,skipSourceProbe:r?.skipSourceProbe}):null},[t,F,i,a]),L=(0,U.useCallback)(async(e,n)=>{let r=a.current;if(!r||i)return[];try{r.contentDocument&&a3(r.contentDocument)}catch{}let o=$rn(r,e,n,t),s=[];for(let e of o){let t=await F(e,{skipSourceProbe:!0});t&&s.push(t)}return s},[t,F,i,a]),R=(0,U.useCallback)(e=>{Y7(D.current,e)||(D.current=e,x(e))},[]),z=(0,U.useCallback)(async e=>{let i=a.current,o=null;try{o=i?.contentDocument??null}catch{return null}if(!o)return null;a3(o);let s=en(o,e,{activeCompositionPath:t,compIdToSrc:r,isMasterView:n});return s?F(s,{preferClipAncestor:!1}):null},[t,F,r,n,a]),B=(0,U.useCallback)(async e=>{let t=++A.current;if(!e){M(null,{revealPanel:!1});return}let n=await z(e);if(t===A.current){if(n){M(n);return}M(null,{revealPanel:!1,announce:!1})}},[M,z]),V=(0,U.useRef)(async()=>{}),ee=(0,U.useCallback)(async e=>{let n=a.current,r=null;try{r=n?.contentDocument??null}catch{return}if(!r)return;let i=He(r,e,t);if(!i){let t=E.current;if(K4(`refresh-lost`,{target:e.selector??e.id??null,group:t.length}),t.length>1){await V.current(t);return}M(null,{revealPanel:!1});return}let o=await F(i,{previous:e});o&&M(o,{revealPanel:!1,preserveGroup:!0})},[t,M,F,a]),te=(0,U.useCallback)(async e=>{let n=a.current,r=null;try{r=n?.contentDocument??null}catch{return}if(!r)return;let i=[];for(let n of e){let e=He(r,n,t);if(!e)continue;let a=await F(e,{previous:n});a&&i.push(a)}if(i.length===0)return;let o=T.current,s=i.find(e=>Y7(e,o))??i[0]??null;T.current=s,E.current=i,_(s),y(i),j(i,s)},[t,j,F,a]);return(0,U.useEffect)(()=>{V.current=te},[te]),(0,U.useEffect)(()=>{R(null)},[t,e,p,m,R]),(0,U.useEffect)(()=>{let n=k.current;(n.activeCompPath!==t||n.projectId!==e)&&(k.current={activeCompPath:t,projectId:e},O.current=null,C(null),M(null,{revealPanel:!1}))},[t,e,M]),(0,U.useEffect)(()=>{b&&(i||Y7(b,g)||X7(v,b)||!b.element.isConnected)&&R(null)},[i,b,g,v,R]),(0,U.useEffect)(()=>{i&&M(null,{revealPanel:!1})},[M,i]),Ljn({previewIframeRef:a,buildDomSelectionFromTarget:F,applyDomSelection:M}),{domEditSelection:g,domEditGroupSelections:v,domEditHoverSelection:b,activeGroupElement:S,domEditSelectionRef:T,domEditGroupSelectionsRef:E,domEditHoverSelectionRef:D,activeGroupElementRef:O,setDomEditSelection:_,setDomEditGroupSelections:y,setActiveGroupElement:P,applyDomSelection:M,clearDomSelection:N,buildDomSelectionFromTarget:F,resolveDomSelectionFromPreviewPoint:I,resolveAllDomSelectionsFromPreviewPoint:L,updateDomEditHoverSelection:R,buildDomSelectionForTimelineElement:z,handleTimelineElementSelect:B,refreshDomEditSelectionFromPreview:ee,refreshDomEditGroupSelectionsFromPreview:te,applyMarqueeSelection:(0,U.useCallback)((e,t)=>{K4(`marquee`,{hits:e.length,additive:t});let n=T.current,r=E.current;if(e.length===0){let e=Z7(r,n).length;return t||M(null,{revealPanel:!1}),{changed:!t&&e>0,count:t?e:0}}let i;if(t){i=Z7(r,n);for(let t of e)X7(i,t)||(i=[...i,t])}else{i=[];for(let t of e)X7(i,t)||i.push(t)}let a=t&&n?n:e[0],o=Z7(r,n),s=o.length!==i.length||i.some(e=>!X7(o,e))||!Y7(n,a);return T.current=a,E.current=i,_(a),y(i),j(i,a,!0),{changed:s,count:i.length}},[M,j])}}var Bjn=6,Vjn=600,Hjn=400,Ujn=6;function Wjn({captionEditMode:e,compositionLoading:t,previewIframeRef:n,showToast:r,applyDomSelection:i,resolveDomSelectionFromPreviewPoint:a,resolveAllDomSelectionsFromPreviewPoint:o,updateDomEditHoverSelection:s,setActiveGroupElement:c,onClickToSource:l}){let u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useCallback)(()=>{let e=ein(n.current),t=X.getState();t.setIsPlaying(!1),e!=null&&(t.setCurrentTime(e),Lb.notify(e))},[n]);return{handlePreviewCanvasMouseDown:(0,U.useCallback)(async(n,r)=>{if(e||t)return;let s=Date.now(),p=d.current,m=n.detail>=2||p!=null&&s-p.t<Hjn&&Math.hypot(n.clientX-p.x,n.clientY-p.y)<Ujn;d.current={t:s,x:n.clientX,y:n.clientY};let h=X.getState().isPlaying;f();let g=()=>{h&&X.getState().requestPlayback(!0)};if(m&&!n.shiftKey){let e=await a(n.clientX,n.clientY),t=u.current,r=t!==null&&t.candidates.length>1&&Math.hypot(n.clientX-t.x,n.clientY-t.y)<Bjn&&s-t.at<Vjn;if(e?.element.hasAttribute(`data-hf-group`)){n.preventDefault(),n.stopPropagation(),u.current=null,mG(`group`,{action:`drill_in`}),c(e.element),i(await a(n.clientX,n.clientY,{activeGroupElement:e.element})??e);return}if(e&&!r&&!e.element.hasAttribute(`data-composition-src`)&&!e.element.hasAttribute(`data-composition-file`)){n.preventDefault(),n.stopPropagation(),u.current=null,i(e);return}}let _=Date.now(),v=u.current,y=v?n.clientX-v.x:1/0,b=v?n.clientY-v.y:1/0,x=v!==null&&Math.sqrt(y*y+b*b)<Bjn&&_-v.at<Vjn;if(n.shiftKey){u.current=null;let e=await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1})??r?.hoverSelection??null;if(!e){g();return}n.preventDefault(),n.stopPropagation(),i(e,{additive:!0}),m4(`multi_select`,`button`);return}if(x&&v){let e=(v.index+1)%v.candidates.length,t=v.candidates[e];u.current={...v,index:e,at:_},n.preventDefault(),n.stopPropagation(),i(t);return}let S=await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1});if(S||=(c(null),await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1,activeGroupElement:null})),S=S??r?.hoverSelection??null,!S){u.current=null,i(null,{revealPanel:!1}),g();return}n.preventDefault(),n.stopPropagation(),i(S),!n.shiftKey&&n.altKey&&l&&l(S);let C=await o(n.clientX,n.clientY);u.current=C.length>1?{x:n.clientX,y:n.clientY,candidates:C,index:0,at:_}:null},[i,e,t,l,f,o,a,c]),handlePreviewCanvasPointerMove:(0,U.useCallback)(async(n,r)=>{if(e||t)return s(null),null;let i=await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1,skipSourceProbe:!0});return s(i),i},[e,t,a,s]),handlePreviewCanvasPointerLeave:(0,U.useCallback)(()=>{s(null)},[s]),handleBlockedDomMove:(0,U.useCallback)((e,t)=>{r(t??e.capabilities.reasonIfDisabled??`This element can't be adjusted directly from the preview.`,`info`)},[r]),handleDomManualDragStart:(0,U.useCallback)(()=>{f()},[f])}}var Gjn=new Set([`inherit`,`initial`,`revert`,`revert-layer`,`serif`,`sans-serif`,`monospace`,`cursive`,`fantasy`,`system-ui`,`ui-sans-serif`,`ui-serif`,`ui-monospace`,`ui-rounded`,`emoji`,`math`,`fangsong`]);function Kjn(e){return(e.split(`,`)[0]??``).trim().replace(/^["']|["']$/g,``)}function qjn(e){return e.split(`,`)[0]?.trim().replace(/^["']|["']$/g,``).trim()??``}function Jjn(e,t){let n=Kjn(t);if(!n||Gjn.has(n.toLowerCase()))return;let r=`studio-preview-google-font-${n.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`;if(e.getElementById(r))return;let i=e.createElement(`link`);i.id=r,i.rel=`stylesheet`,i.href=dyn(n),e.head.appendChild(i)}function Yjn(e,t){let n=`studio-imported-font-${t.path.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`;if(e.getElementById(n))return;let r=e.createElement(`style`);r.id=n,r.textContent=Ubn(t),e.head.appendChild(r)}function Xjn(e,t){return Ubn(e,G0t(t,e.path))}function Zjn(e){if(e.id)return{selector:iJ(e.id)};let t=e.element,n=t.ownerDocument;if(e.selector&&cJ(n,e.selector,t))return{selector:e.selector};let r=t.tagName.toLowerCase(),i=r,a=1;for(;n.getElementById(i);)a+=1,i=`${r}-${a}`;return{selector:iJ(i),autoId:i}}var Qjn=class extends Error{constructor(e,t){super(nMn(e,t)),this.statusCode=e,this.responseBody=t,this.name=`GsapMutationHttpError`}statusCode;responseBody};function $jn(e){return typeof e==`object`&&!!e}function eMn(e){let t=Array.isArray(e)?e.filter(e=>typeof e==`string`):[];return t.length>0?` (${t.join(`, `)})`:``}async function tMn(e){return(e.headers.get(`content-type`)??``).includes(`application/json`)?await e.json().catch(()=>null):await e.text().catch(()=>null)}function nMn(e,t){return $jn(t)&&typeof t.error==`string`?t.error:`GSAP mutation failed with status ${e}`}function rMn(e){let t=e.responseBody;return $jn(t)?`Couldn't save animation: ${nMn(e.statusCode,t)}${eMn(t.fields)}`:`Couldn't save animation: ${e.message}`}function iMn(e){return e.map(e=>e.path).join(`, `)}function aMn(e){return e instanceof Error?e.message:String(e)}async function oMn(e){return(e.headers.get(`content-type`)??``).includes(`application/json`)?await e.json().catch(()=>null):null}function sMn(e){return e?.error?`Couldn't save edit: ${e.error}${eMn(e.fields)}`:`Couldn't save edit`}function cMn(e){return e.target.id??e.target.hfId??e.target.selector??`(unaddressed)`}function lMn(e,t){let n=e.patches.filter((e,n)=>t[n]===!1).map(cMn);n.length!==0&&(console.warn(`[studio] z-index reorder: server could not match ${n.length} patch target(s) in ${e.sourceFile} (the whole z-order gesture will revert on reload):`,n.join(`, `)),rX({source:`dom_edit`,error:Error(`Batch patch target(s) unmatched: ${n.join(`, `)}`),filePath:e.sourceFile,mutationType:`z-reorder-unmatched`}))}var uMn=class extends Error{constructor(e,t){super(e,t),this.name=`AtomicElementPatchConvergenceError`}};function dMn(e){return typeof e==`object`&&!!e&&`sourceFile`in e&&typeof e.sourceFile==`string`&&`changed`in e&&typeof e.changed==`boolean`&&(!(`matched`in e)||Array.isArray(e.matched)&&e.matched.every(e=>typeof e==`boolean`))&&`before`in e&&typeof e.before==`string`&&`after`in e&&typeof e.after==`string`&&e.changed===(e.before!==e.after)}async function fMn(e,t){let n=JSON.stringify({batches:t});try{let r=await H(`/api/projects/${encodeURIComponent(e)}/file-mutations/patch-element-batches`,{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:n});if(!r.ok)throw new JY(sMn(await oMn(r)),r.status);let i=await r.json().catch(()=>null);if(typeof i!=`object`||!i||!(`durable`in i)||typeof i.durable!=`boolean`||!(`files`in i)||!Array.isArray(i.files)||i.files.length!==t.length||!i.files.every(dMn)||!i.durable&&i.files.some(e=>e.changed))throw new JY(`Invalid atomic element patch response`,502);let a=i.files.map((e,n)=>{let r=t[n],i=e.matched??[];if(!r||e.sourceFile!==r.sourceFile||i.length!==0&&i.length!==r.patches.length)throw new JY(`Invalid atomic element patch response`,502);return lMn(r,i),{...e,matched:i,allMatched:i.length===r.patches.length&&i.every(Boolean)}});return{durable:i.durable,files:a}}catch(e){throw new uMn(aMn(e),{cause:e})}}function pMn(e){return e.every(e=>e.patches.every(e=>e.operations.every(e=>e.type===`inline-style`)))}async function mMn(e,t,n,r){let i=await H(M(e,`/file-mutations/patch-element/${encodeURIComponent(t)}`),{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:JSON.stringify(n)});if(!i.ok)throw r(sMn(await oMn(i)),`error`),await iX(i,`Failed to patch ${t}`,{alreadyToasted:!0});return await i.json()}async function hMn({projectId:e,targetPath:t,selection:n,autoId:r,showToast:i}){let a={target:{id:n.id,hfId:n.hfId,selector:n.selector,selectorIndex:n.selectorIndex},operations:[{type:`ensure-id`,property:`id`,value:r}]};if(bOt(a).length>0)return i(`Couldn't assign element id because the patch contains invalid values`,`error`),null;try{let{elementId:n}=await mMn(e,t,a,i);return n||(i(`Couldn't assign element id: element not found in ${t}`,`error`),null)}catch(e){if(e instanceof JY&&e.alreadyToasted)return null;throw e}}async function gMn(e,t,n,r,i){let a=n(t,e);if(a===t)return{content:t,failed:!1};try{return await r(e,a,t),{content:a,failed:!1}}catch(n){return i(`Saved, but couldn't finish updating ${e}: ${aMn(n)}`,`error`),{content:t,failed:!0}}}function _Mn({activeCompPath:e,previewIframeRef:t,showToast:n,queueDomEditSave:r,writeProjectFile:i,editHistory:a,projectIdRef:o,reloadPreview:s,forceReloadSdkSession:c,onTrySdkPersist:l}){let u=(0,U.useRef)(new Set),d=(0,U.useCallback)(async(r,d,f,p)=>{if(o.current!==p)throw Error(`Active project changed before the edit could be saved`);let m=p;if(f?.shouldSave&&!f.shouldSave())return;let h=r.sourceFile||e||`index.html`,g=(e,n)=>(f?.skipRefresh&&n&&!f.deferRender&&q7(t.current),e),_=async()=>{let e=await NZ(m,h);if(o.current!==p)throw Error(`Active project changed before the edit could be saved`);return f?.shouldSave&&!f.shouldSave()?null:e},v=Wt(r),y=f?.importedFont,b={target:v,operations:d,...y?{fontFaceCss:Xjn(y,h)}:{}},x=bOt(b);if(x.length>0){let e=iMn(x);throw n(`Couldn't save edit because it contains invalid layout values`,`error`),new f8(`DOM patch contains unsafe values: ${e}`,{alreadyToasted:!0})}if(l&&!y&&!f?.prepareContent){let e=await _();if(e===null)return;let t=await l(r,d,e,h,{label:f?.label,coalesceKey:f?.coalesceKey,skipRefresh:f?.skipRefresh});if(t.status===`failed`)throw t.error;if(t.status===`committed`)return g({sourceFile:h,version:t.version,changed:!0},!0)}let S={label:f?.label??`Edit layer`,coalesceKey:f?.coalesceKey,coalesceMs:f?.coalesceMs},C=f?.prepareContent,w=!1,T=await MZ(i,[h],async()=>{let e=await _();if(e===null)return null;let t=await mMn(m,h,b,n);if(!t.changed)return{patchData:t,patchedContent:null,finalContent:null};let r=typeof t.content==`string`?t.content:e,o=C?await gMn(h,r,C,i,n):{content:r,failed:!1};w=o.failed;let s=o.content;return await a.recordEdit({...S,files:{[h]:{before:e,after:s}}}),{patchData:t,patchedContent:r,finalContent:s}});if(T===null)return;let{patchData:E,patchedContent:D,finalContent:O}=T;if(O===null){if(E.matched===!1){let t=r.selector??r.id??`selection`;throw u.current.has(t)||(u.current.add(t),mG(`save_skipped_unresolvable`,{target_id:r.id??void 0,target_selector:r.selector??void 0,target_source_file:r.sourceFile??void 0,composition:e??void 0})),new Cpn(h)}return Apn(r,d),g(typeof E.path==`string`&&typeof E.version==`string`?{sourceFile:E.path,version:E.version,changed:!1}:void 0,!1)}c?.(),f?.skipRefresh||s();let k=g(O===D&&typeof E.path==`string`&&typeof E.version==`string`?{sourceFile:E.path,version:E.version,changed:!0}:void 0,!0);if(w)throw new wpn(h);return k},[e,a,i,o,s,n,c,l,t]);return(0,U.useCallback)((e,t,n)=>{let i=o.current;if(!i)return Promise.reject(Error(`No active project`));let a=()=>r(()=>d(e,t,n,i));return e.element?q0(e.element,a):a()},[d,o,r])}function vMn({activeCompPath:e,persistDomEditOperations:t,showToast:n}){return(0,U.useCallback)((r,i,a)=>t(r,i,{label:a.label,coalesceKey:a.coalesceKey,coalesceMs:a.coalesceMs,skipRefresh:a.skipRefresh??!0,deferRender:a.deferRender}).catch(t=>{throw t instanceof t6?t:(kpn(t)||n(t instanceof Error?t.message:`Failed to save position`),rX({source:`dom_edit`,error:t,filePath:r.sourceFile??e??`index.html`,mutationType:`position`,label:a.label,targetId:r.id,targetSelector:r.selector,targetSourceFile:r.sourceFile}),t)}),[e,t,n])}function yMn(e){let t=Mt(e),n=e.getAttribute(`data-hf-id`),r=at(e),i=r?Xt(e.ownerDocument,e,r)??0:0,{elements:o,updateElement:s}=X.getState(),c=o.find(e=>e.sourceFile===t&&(n?e.hfId===n:!!r&&e.selector===r&&(e.selectorIndex??0)===i));c&&s(a(c),{text:Xe(e)})}function bMn(e,t){return e.every((e,n)=>t[n]?.key===e.key)}function xMn(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:null}function SMn(e,t){return Array.from(new Set([...Object.keys(e),...Object.keys(t)]))}function CMn(e,t){if(e.length!==t.length||!bMn(e,t)||t.some(e=>e.source===`text-node`)||t.some(e=>e.source!==`child`)||e.some(e=>e.source!==`child`))return null;let n=new Map(e.map(e=>[e.key,e])),r=[];for(let i of t){let t=n.get(i.key),a=et(e,i.key);if(!t||!a)return null;i.value!==t.value&&r.push(Zt(i.value,a));for(let e of SMn(t.inlineStyles,i.inlineStyles)){let n=xMn(t.inlineStyles,e),o=xMn(i.inlineStyles,e);o!==n&&r.push(wt(e,o,a))}}return r}function wMn(e,t,n){return e.length===0?[]:e.map(e=>e.key===n?{...e,value:t}:e)}function TMn(e,t,n){let r=t.length>1||t.some(e=>e.source===`child`),i=r?vt(t):n;return{usesSerializedTextFields:r,nextContent:i,operations:(r?CMn(e,t):null)??(r?[Ze(i)]:[Zt(i)])}}var EMn=[[`background-position`,`center`],[`background-repeat`,`no-repeat`],[`background-size`,`contain`]];async function DMn(e,t,n){let r=Object.fromEntries(Object.entries(n).map(([e,t])=>[X0t(e),t])),i=Object.entries(r);if(i.length===0)return E6(`no-selection`);if(i.some(([e])=>Z0t(e)))return E6(`geometry-property`);if(!t.capabilities.canEditStyles)return E6(`styles-not-editable`);let{activeCompPath:a,previewIframeRef:o,persistDomEditOperations:s,showToast:c}=e,l=sn(t),u=i.map(([t])=>({property:t,isLatest:w6(e.versions,`${l}:${t}`)})),d=()=>u.some(({isLatest:e})=>e()),f=r[`font-family`],p=f===void 0?null:e.resolveImportedFontAsset?.(f)??null,m=o.current?.contentDocument,h=[],g=[];for(let[e,t]of i){let n=J0t(e,t);if(h.push(wt(e,n)),g.push([e,n]),e===`background-image`&&Y0t(t))for(let[e,t]of EMn)e in r||(h.push(wt(e,t)),g.push([e,t]))}let _=null,v=new Map;return fun({capture:()=>{let e=m?He(m,t,a):null;if(e){_=e;for(let[t]of i)v.set(t,e.style.getPropertyValue(t))}},apply:()=>{if(_){for(let[e,t]of g)_.style.setProperty(e,t);f!==void 0&&m&&(Jjn(m,f),p&&Yjn(m,p))}},persist:()=>s(t,h,{label:`Edit layer style`,skipRefresh:!0,importedFont:p??void 0}),shouldRevert:d,revert:()=>{let e=_;if(e)for(let{property:t,isLatest:n}of u){let r=v.get(t);r===void 0||!n()||(r===``?e.style.removeProperty(t):e.style.setProperty(t,r))}},onError:e=>p8(t,h,e,c),shouldResync:d,resync:()=>e.resync?.(t),onFinally:()=>u.forEach(({isLatest:e})=>e.release())})}function OMn(e,t){return t&&!e.startsWith(`data-`)?`data-${e}`:e}function kMn(e,t){return t===null||t===`false`&&nQt.has(e)?null:t}function AMn(e){return e.type===`attribute`?OMn(e.property,!0):e.property}function jMn(e){return e.type===`html-attribute`?kMn(e.property,e.value):e.value===``?null:e.value}function Q7(e,t,n){n===null?e.removeAttribute(t):e.setAttribute(t,n),(e.tagName.toLowerCase()===`hf-audio-group`||t===`data-audio-group`)&&N1(e.ownerDocument)}function MMn(e,t,n){return e?He(e,t,n):null}function NMn(e,t,n,r){let i=MMn(e,t,n);return i?{element:i,previousValues:new Map(r.map(e=>[e,i.getAttribute(e)]))}:null}function PMn(e,t,n,r){let i=MMn(e,t,n);return i?{element:i,previousValue:i.getAttribute(r)}:null}function FMn({activeCompPath:e,previewIframeRef:t,showToast:n,domEditSelection:r,refreshDomEditSelectionFromPreview:i,persistDomEditOperations:a}){let o=(0,U.useRef)(new Map),s=(0,U.useCallback)(async(s,c,l)=>{if(!r)return;let u=t.current,d=OMn(s,!0),f=`${l.coalescePrefix}:${s}:${sn(r)}`,p=w6(o.current,f),m={type:`attribute`,property:s,value:c},h=null,g=null;await T6({capture:()=>{let t=PMn(u?.contentDocument,r,e,d);t&&(h=t.element,g=t.previousValue)},apply:()=>{h&&Q7(h,d,c===null||c===``?null:c)},persist:l.previewOnly?async()=>{}:()=>a(r,[m],{label:l.label,coalesceKey:f,skipRefresh:l.skipRefresh}),shouldRevert:()=>p(),revert:()=>{h&&Q7(h,d,g)},onError:e=>p8(r,[m],e,n),shouldResync:()=>p()&&!!l.refreshAfter,resync:()=>{i(r),V7(t.current?.contentDocument??null)},onSettled:l.onSettled,onFinally:p.release})},[e,r,a,i,n,t]),c=(0,U.useCallback)(async(r,s,c)=>{let l=t.current,u=s.map(e=>({fullAttr:AMn(e),value:jMn(e)})),d=`${c.coalescePrefix}:${s.map(e=>e.property).sort().join(`,`)}:${sn(r)}`,f=w6(o.current,d),p=null,m=!1;return await T6({capture:()=>{p=NMn(l?.contentDocument,r,e,u.map(e=>e.fullAttr))},apply:()=>{if(p)for(let e of u)Q7(p.element,e.fullAttr,e.value)},persist:()=>a(r,s,{label:c.label,coalesceKey:d,skipRefresh:c.skipRefresh,prepareContent:c.prepareContent}),shouldRevert:e=>f()&&!(e instanceof wpn),revert:()=>{if(p)for(let e of u)Q7(p.element,e.fullAttr,p.previousValues.get(e.fullAttr)??null)},onError:e=>p8(r,s,e,n),shouldResync:()=>f()&&!!c.refreshAfter,resync:()=>{i(r),c.syncAutomation&&V7(t.current?.contentDocument??null)},onSettled:e=>{m=e,c.onSettled?.(e)},onFinally:f.release}),m},[e,a,i,n,t]),l=(0,U.useCallback)(async(e,t)=>{await c(e,Object.entries(t).map(([e,t])=>({type:`attribute`,property:e,value:t})),{label:`Edit timing`,coalescePrefix:`attrs`,skipRefresh:!1,refreshAfter:!0})},[c]),u=(0,U.useCallback)((e,t,n)=>c(e,t,{label:n.label,coalescePrefix:`attr-batch`,skipRefresh:!1,refreshAfter:!0,syncAutomation:!0,prepareContent:n.prepareContent}),[c]);return{handleDomAttributeCommit:(0,U.useCallback)(async(e,t)=>{await s(e,t,{label:`Edit ${e.replace(/-/g,` `)}`,coalescePrefix:`attr`,skipRefresh:!1,refreshAfter:!0})},[s]),handleDomAttributeLiveCommit:(0,U.useCallback)(async(e,t,n,r)=>{await s(e,t,{label:`Edit ${e.replace(/^(data-)?/,``).replace(/-/g,` `)}`,coalescePrefix:`attr-live`,skipRefresh:!0,onSettled:n,...r?.previewOnly?{previewOnly:!0}:{}})},[s]),handleDomAttributeQuietCommit:(0,U.useCallback)(async(e,t)=>{await s(e,t,{label:`Edit ${e.replace(/^(data-)?/,``).replace(/-/g,` `)}`,coalescePrefix:`attr-quiet`,skipRefresh:!0,refreshAfter:!0})},[s]),handleDomHtmlAttributeCommit:(0,U.useCallback)(async(s,c)=>{if(!r)return;let l=t.current,u=`html-attr:${s}:${sn(r)}`,d=w6(o.current,u),f={type:`html-attribute`,property:s,value:c},p=null,m=null;await T6({capture:()=>{let t=PMn(l?.contentDocument,r,e,s);t&&(p=t.element,m=t.previousValue)},apply:()=>{p&&Q7(p,s,kMn(s,c))},persist:()=>a(r,[f],{label:`Edit ${s}`,coalesceKey:u,skipRefresh:!1}),shouldRevert:()=>d(),revert:()=>{p&&Q7(p,s,m)},onError:e=>p8(r,[f],e,n),shouldResync:()=>d(),resync:()=>{i(r),V7(t.current?.contentDocument??null)},onFinally:d.release})},[e,r,a,i,n,t]),handleDomAttributesCommit:l,handleDomAttributeBatchCommit:u}}function IMn(e,t){return e.isCompositionHost||e.isInsideLockedComposition?!1:g6(t)}async function LMn(e,t,n,r,i){if(!e)return;let a=He(e,t,n);if(!a)return;yMn(a);let o=await r(a);o&&i(o,{revealPanel:!1,preserveGroup:!0})}function RMn({activeCompPath:e,previewIframeRef:t,showToast:n,domEditSelection:r,applyDomSelection:i,refreshDomEditSelectionFromPreview:a,buildDomSelectionFromTarget:o,persistDomEditOperations:s,resolveImportedFontAsset:c,readOnlyPreview:l}){let u=(0,U.useRef)(l);u.current=l;let d=(0,U.useRef)(r);d.current=r;let f=(0,U.useRef)(new Map),p=(0,U.useRef)(new Map),{handleDomAttributeCommit:m,handleDomAttributeLiveCommit:h,handleDomAttributeQuietCommit:g,handleDomHtmlAttributeCommit:_,handleDomAttributesCommit:v,handleDomAttributeBatchCommit:y}=FMn({activeCompPath:e,previewIframeRef:t,showToast:n,domEditSelection:r,refreshDomEditSelectionFromPreview:a,persistDomEditOperations:s}),b=(0,U.useCallback)((r,i,o=``)=>DMn({activeCompPath:e,previewIframeRef:t,persistDomEditOperations:s,showToast:n,versions:p.current,resolveImportedFontAsset:c,resync:a},r,typeof i==`string`?{[i]:o}:i),[e,s,a,c,n,t]),x=(0,U.useCallback)((e,t)=>r?b(r,e,t):Promise.resolve(E6(`no-selection`)),[r,b]),S=(0,U.useCallback)(async(r,a,c)=>{if(!Se(r))return E6(`not-text-editable`);let l=w6(f.current,sn(r)),u=wMn(r.textFields,a,c),d=TMn(r.textFields,u,a),p=t.current?.contentDocument,m=null,h=null;return fun({capture:()=>{if(!p)return;let t=He(p,r,e);t&&(m=t,h=t.innerHTML)},apply:()=>{m&&(d.usesSerializedTextFields?m.innerHTML=d.nextContent:m.textContent=a)},persist:()=>s(r,d.operations,{label:`Edit text`,skipRefresh:!0,shouldSave:l}),shouldRevert:()=>l(),revert:()=>{!m||h===null||(m.innerHTML=h)},onError:e=>p8(r,d.operations,e,n),shouldResync:l,resync:()=>LMn(p,r,e,o,i),onFinally:l.release})},[e,i,o,s,t,n]),C=(0,U.useCallback)((e,t)=>r?S(r,e,t):Promise.resolve(E6(`no-selection`)),[r,S]),w=(0,U.useCallback)(async({element:r,html:a,previousHtml:c})=>{let l=()=>{r.isConnected&&r.innerHTML===a&&(r.innerHTML=c)};if(u.current)return l();let p=e=>{console.error(`[Studio] text edit not saved:`,e,r),n(`Couldn't save the text edit: ${e}`,`error`),l()},m=t.current?.contentDocument;if(!m||!r.isConnected||r.ownerDocument!==m)return p(`the text's element is gone from the preview`);let h=await o(r,{exactTarget:!0,skipSourceProbe:!0});if(h?.element!==r)return p(`this text was not found in the composition's source`);if(!IMn(h,r))return p(`this text can't be edited in place`);let g=w6(f.current,sn(h)),_=[Ze(a)],v=``;await T6({capture:()=>{},apply:()=>{r.innerHTML=a,v=r.innerHTML},persist:async()=>{(await s(h,_,{label:`Edit text`,skipRefresh:!0,shouldSave:g}))?.changed&&m4(`text_edit`,`field`)},shouldRevert:()=>g(),revert:()=>{r.isConnected&&r.innerHTML===v&&(r.innerHTML=c)},onError:e=>p8(h,_,e,n),shouldResync:()=>g()&&d.current?.element===r,resync:()=>LMn(m,h,e,o,i),onFinally:g.release})},[e,i,o,s,t,n]),T=(0,U.useCallback)(async(r,a,c)=>{let l=w6(f.current,sn(r)),u=TMn(r.textFields,a,a[0]?.value??``),d=t.current?.contentDocument,p=null,m=null,h=c?.importedFont??null;await T6({capture:()=>{if(!d)return;let t=He(d,r,e);t&&(p=t,m=t.innerHTML)},apply:()=>{p&&(u.usesSerializedTextFields?p.innerHTML=u.nextContent:p.textContent=u.nextContent)},persist:async()=>{await s(r,u.operations,{label:`Edit text`,skipRefresh:!0,importedFont:h??void 0})},shouldRevert:()=>l(),revert:()=>{!p||m===null||(p.innerHTML=m)},onError:e=>p8(r,u.operations,e,n),shouldResync:l,resync:()=>LMn(d,r,e,o,i),onFinally:l.release})},[e,i,o,s,t,n]);return{handleDomStyleCommit:x,handleDomStyleCommitForSelection:b,handleDomAttributeCommit:m,handleDomAttributeLiveCommit:h,handleDomAttributeQuietCommit:g,handleDomHtmlAttributeCommit:_,handleDomAttributesCommit:v,handleDomAttributeBatchCommit:y,handleDomTextCommit:C,handleDomTextCommitForSelection:S,handleDomRichTextCommit:w,commitDomTextFields:T,handleDomTextFieldStyleCommit:(0,U.useCallback)(async(e,n,i)=>{if(!r)return;let a=r.textFields.find(t=>t.key===e);if(!a)return;if(a.source===`self`){await x(n,i);return}let o=J0t(n,i),s=n===`font-family`?c(i):null;if(n===`font-family`){let e=t.current?.contentDocument;e&&(Jjn(e,o),s&&Yjn(e,s))}let l=r.textFields.map(t=>t.key===e?{...t,inlineStyles:{...t.inlineStyles,[n]:o},computedStyles:{...t.computedStyles,[n]:o}}:t);await T(r,l,{importedFont:s})},[T,r,x,c,t]),handleDomAddTextField:(0,U.useCallback)(async e=>{if(!r||!r.textFields.some(e=>e.source===`child`))return null;let t=r.textFields.findIndex(t=>t.key===e),n=r.textFields[t>=0?t:0]??r.textFields[0],i=Nt(n),a=[...r.textFields];return a.splice(t>=0?t+1:a.length,0,i),await T(r,a),i.key},[T,r]),handleDomRemoveTextField:(0,U.useCallback)(async e=>{if(!r)return;let t=r.textFields.find(t=>t.key===e);if(!t)return;if(t.source===`self`){await C(``,e);return}let n=r.textFields.filter(t=>t.key!==e);await T(r,n)},[T,r,C])}}var zMn=e=>({left:e.offsetLeft,top:e.offsetTop,width:e.offsetWidth,height:e.offsetHeight});function BMn(e,t){let n=Number.parseFloat(e.getAttribute(`data-hf-drag-initial-offset-${t}`)??``);return Number.isFinite(n)?n:0}function VMn(e,t){let n=e.ownerDocument.defaultView?.getComputedStyle(e);if(!n)return`anchored`;let r=S(t.x-BMn(e,`x`)),i=S(t.y-BMn(e,`y`)),a=e.getAttribute(ie)===`static`,o=a||!/^(relative|absolute|fixed|sticky)$/.test(n.position);if(!o&&(n.left.endsWith(`%`)||n.top.endsWith(`%`)))return`percent`;let s=o?0:Number.parseFloat(n.left)||0,c=o?0:Number.parseFloat(n.top)||0,l={position:e.style.position,left:e.style.left,top:e.style.top},u=zMn(e);o&&(e.style.position=`relative`),e.style.left=`${S(s+r)}px`,e.style.top=`${S(c+i)}px`;let d=zMn(e);return Math.abs(d.left-u.left-r)<=1&&Math.abs(d.top-u.top-i)<=1&&Math.abs(d.width-u.width)<=1&&Math.abs(d.height-u.height)<=1?(a&&e.removeAttribute(ie),[...o?[{type:`inline-style`,property:`position`,value:`relative`}]:[],{type:`inline-style`,property:`left`,value:e.style.left},{type:`inline-style`,property:`top`,value:e.style.top}]):(Object.assign(e.style,l),`anchored`)}var HMn=`The animation took over this layer's position during the move, so it was not saved.`,UMn={anchored:`This layer is anchored from its right or bottom edge. Move it in the Code tab.`,percent:`This layer's position is set in percent. Move it in the Code tab.`};function WMn(e){return e.ownerDocument.defaultView?.gsap}function GMn(e){let t=WMn(e),n=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-x`)??``),r=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-y`)??``);t&&Number.isFinite(n)&&Number.isFinite(r)&&t.set(e,{x:n,y:r})}function KMn(e,t){if(H9t(e))throw WMn(e)?.set(e,{x:0,y:0,xPercent:0,yPercent:0}),t(HMn,`error`),$Y(Error(HMn))}var qMn=0;function JMn(e,t,n,r){let i=t.element,a=c3(i),o=aon(i,n),s=i.style.getPropertyValue(`translate`),c=()=>{i.style.getPropertyValue(`translate`)===s&&p3(i,a)},l={label:`Move layer`,coalesceKey:r??`move:${++qMn}`,coalesceMs:1/0};return{save:()=>e(t,o,l).catch(e=>{throw c(),e}),rollback:c}}function YMn({commitPositionPatchToHtml:e,showToast:t,readOnlyPreview:n},r,i,a,o){let s=r.element;if(n)return{save:()=>Promise.resolve(void 0),rollback:()=>void 0};if(a)return KMn(s,t),JMn(e,r,i,o);let c={position:s.style.position,left:s.style.left,top:s.style.top},l=s.getAttribute(ie),u=VMn(s,i);if(!Array.isArray(u))throw t(UMn[u],`error`),Error(UMn[u]);GMn(s);let d=()=>{Object.assign(s.style,c),l!==null&&s.setAttribute(ie,l)};return{save:()=>e(r,u,{label:`Move layer`,coalesceKey:o??`element-offset:${sn(r)}`,...o&&{coalesceMs:1/0}}).catch(e=>{throw d(),e}),rollback:d}}var XMn=0;function ZMn({commitPositionPatchToHtml:e,readOnlyPreview:t},n,r){if(t)return Promise.resolve(void 0);let{element:i}=n,a=s3(i),o=i.hasAttribute(t0)?A9t(i):[];o.length&&Uan(i);let s=Hon(i,r.angle,o.length?void 0:r.plain??void 0);o.push(...s);let c=s.at(-1);return e(n,o,{label:`Rotate layer`,coalesceKey:`rotate:${++XMn}`,coalesceMs:1/0}).catch(e=>{throw i.style.getPropertyValue(c.property)===c.value&&Uon(i,a),e})}var QMn=0;function $Mn({showToast:e,commitPositionPatchToHtml:t,readOnlyPreview:n}){return{stageElementPositionOffset:(0,U.useCallback)((r,i,a,o)=>YMn({commitPositionPatchToHtml:t,showToast:e,readOnlyPreview:n},r,i,a,o),[t,n,e]),handleDomBoxSizeCommit:(0,U.useCallback)((e,r,i,a,o)=>{if(n)return Promise.resolve(void 0);let s=e.element,c=o3(s),l=c3(s),u=s6(s);r2(s,r);let d=u(),f=O9t(s);return d&&f.push(d.patch),i&&f.push(...aon(s,i)),t(e,f,{label:`Resize layer box`,...o?{coalesceKey:o,coalesceMs:1/0,deferRender:!0}:{coalesceKey:`box-size:${++QMn}`,coalesceMs:1/0}}).catch(e=>{throw d3(s,c),i&&p3(s,l),d?.revert(),a?.(),e})},[t,n]),handleDomRotationCommit:(0,U.useCallback)((e,r)=>ZMn({commitPositionPatchToHtml:t,readOnlyPreview:n},e,r),[t,n]),handleDomManualEditsReset:(0,U.useCallback)(e=>{let n=e.element,r=c3(n),i=o3(n),a=s3(n),o=[...E9t(n),...k9t(n),...A9t(n)];return Han(n),h3(n),Uan(n),t(e,o,{label:`Reset layer edits`,coalesceKey:`manual-reset:${sn(e)}`,skipRefresh:!1}).catch(e=>{throw p3(n,r),d3(n,i),f3(n,a),e})},[t])}}function eNn({activeCompPath:e,previewIframeRef:t,showToast:n,queueDomEditSave:r,writeProjectFile:i,editHistory:a,fileTree:o,importedFontAssetsRef:s,projectId:c,projectIdRef:l,reloadPreview:u,domEditSelection:d,applyDomSelection:f,clearDomSelection:p,refreshDomEditSelectionFromPreview:m,buildDomSelectionFromTarget:h,forceReloadSdkSession:g,onTrySdkPersist:_,onTrySdkDelete:v,onReorderShadow:y,readOnlyPreview:b}){let x=(0,U.useCallback)(e=>{let t=qjn(e);if(!t)return null;let n=s.current.find(e=>e.family.toLowerCase()===t.toLowerCase());if(n)return n;let r=o.find(e=>oq.test(e)&&D5(e).toLowerCase()===t.toLowerCase());return!r||!c?null:{family:D5(r),path:r,url:M(c,`/preview/${r}`)}},[o,c,s]),S=_Mn({activeCompPath:e,previewIframeRef:t,showToast:n,queueDomEditSave:r,writeProjectFile:i,editHistory:a,projectIdRef:l,reloadPreview:u,forceReloadSdkSession:g,onTrySdkPersist:_}),C=(0,U.useCallback)((e,t)=>{let o=l.current;return o?r(async()=>{if(l.current!==o)throw Error(`Active project changed before the edit could be saved`);let r=o,s=e.flatMap(e=>e.patches.flatMap(e=>bOt(e)));if(s.length>0)throw n(`Couldn't save edit because it contains invalid layout values`,`error`),new f8(`DOM patch contains unsafe values: ${iMn(s)}`,{alreadyToasted:!0});let{allMatched:c,changed:d}=await MZ(i,e.map(e=>e.sourceFile),async()=>{let n=await fMn(r,e),i=Object.fromEntries(n.files.filter(e=>e.changed).map(e=>[e.sourceFile,{before:e.before,after:e.after}])),o=Object.keys(i).length>0;return o&&await a.recordEdit({label:t.label,coalesceKey:t.coalesceKey,coalesceMs:t.coalesceMs,files:i}),{allMatched:n.durable&&n.files.every(e=>e.allMatched),changed:o}});d&&g?.();let f=c,p=t.skipReload===!0&&pMn(e)&&f;return(!f||d&&!p)&&u(),{durable:f,allMatched:c,changed:d}}).catch(r=>{throw r instanceof uMn&&u(),(r instanceof JY||r instanceof f8)&&r.alreadyToasted||n(r instanceof Error?r.message:`Failed to reorder layers`,`error`),rX({source:`dom_edit`,error:r,filePath:e.map(e=>e.sourceFile).join(`,`),mutationType:`z-reorder`,label:t.label}),r}):Promise.reject(Error(`No active project`))},[a,g,l,r,u,n,i]),{handleDomStyleCommit:w,handleDomStyleCommitForSelection:T,handleDomAttributeCommit:E,handleDomAttributeLiveCommit:D,handleDomAttributeQuietCommit:O,handleDomHtmlAttributeCommit:k,handleDomAttributesCommit:A,handleDomAttributeBatchCommit:j,handleDomTextCommit:N,handleDomTextCommitForSelection:P,handleDomRichTextCommit:F,commitDomTextFields:I,handleDomTextFieldStyleCommit:L,handleDomAddTextField:R,handleDomRemoveTextField:z}=RMn({readOnlyPreview:b,activeCompPath:e,previewIframeRef:t,domEditSelection:d,applyDomSelection:f,refreshDomEditSelectionFromPreview:m,buildDomSelectionFromTarget:h,persistDomEditOperations:S,resolveImportedFontAsset:x,showToast:n}),B=vMn({activeCompPath:e,persistDomEditOperations:S,showToast:n}),{stageElementPositionOffset:V,handleDomBoxSizeCommit:ee,handleDomRotationCommit:te,handleDomManualEditsReset:H}=$Mn({showToast:n,commitPositionPatchToHtml:B,readOnlyPreview:b}),{handleDomEditElementsDelete:ne,handleDomZIndexReorderCommit:re}=Hdn({activeCompPath:e,showToast:n,writeProjectFile:i,editHistory:a,projectIdRef:l,reloadPreview:u,clearDomSelection:p,onTrySdkDelete:v,onReorderShadow:y,forceReloadSdkSession:g,commitDomEditPatchBatches:C});return{resolveImportedFontAsset:x,handleDomStyleCommit:w,handleDomStyleCommitForSelection:T,handleDomAttributeCommit:E,handleDomAttributeLiveCommit:D,handleDomAttributeQuietCommit:O,handleDomHtmlAttributeCommit:k,handleDomAttributesCommit:A,handleDomAttributeBatchCommit:j,handleDomTextCommit:N,handleDomTextCommitForSelection:P,handleDomRichTextCommit:F,commitDomTextFields:I,handleDomTextFieldStyleCommit:L,handleDomAddTextField:R,handleDomRemoveTextField:z,stageElementPositionOffset:V,commitPositionPatchToHtml:B,handleDomBoxSizeCommit:ee,handleDomRotationCommit:te,handleDomManualEditsReset:H,handleDomEditElementsDelete:ne,handleDomZIndexReorderCommit:re}}function tNn(e,t){let n=QQ(e,t);if(!n)return;let r=t.find(e=>(e.key??e.id)===n);if(r)return o2t(r)}function nNn(e,t){let n=e.map(e=>({target:Wt(e),left:e.element.offsetLeft,top:e.element.offsetTop,right:e.element.offsetLeft+e.element.offsetWidth,bottom:e.element.offsetTop+e.element.offsetHeight,track:tNn(e,t)})),r=Math.min(...n.map(e=>e.left)),i=Math.min(...n.map(e=>e.top));return{bbox:{left:r,top:i,width:Math.max(...n.map(e=>e.right))-r,height:Math.max(...n.map(e=>e.bottom))-i},targets:n.map(e=>e.target),rebases:n.map(e=>({target:e.target,left:e.left-r,top:e.top-i,track:e.track}))}}function rNn(e,t){let n=e.sourceFile||`index.html`,r=[];for(let i of Array.from(e.element.children)){let e=i.id||void 0,a=se(i);if(!e&&!a)continue;let o=tNn({id:e,hfId:a,sourceFile:n,isCompositionHost:!1},t);r.push({target:Wt({id:e,hfId:a}),track:o})}return r}async function iNn(e,t,n,r,i,a){let o={};return await FZ({projectId:e,path:t,label:i,writeFile:a.writeProjectFile,recordEdit:a.editHistory.recordEdit,rewrite:async a=>{let s=await H(M(e,`/file-mutations/${n}/${encodeURIComponent(t)}`),{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:JSON.stringify(r)});if(!s.ok){let e=await s.json().catch(()=>null);throw Error(e?.error??`Failed to ${i.toLowerCase()} in ${t}`)}return o=await s.json(),{disk:typeof o.content==`string`?o.content:a}}}),a.clearDomSelection(),a.forceReloadSdkSession?.(),a.reloadPreview(),o}function aNn(e){let{activeCompPath:t,showToast:n,projectIdRef:r,timelineElements:i}=e;return{groupSelection:(0,U.useCallback)(async a=>{let o=r.current;if(!o||a.length===0)return null;let s=a[0].sourceFile||t||`index.html`;if(a.some(e=>(e.sourceFile||t||`index.html`)!==s))return n(`Can't group elements from different files`,`error`),null;let c=`Group ${a[0].element.ownerDocument.querySelectorAll(`[data-hf-group]`).length+1}`,{bbox:l,targets:u,rebases:d}=nNn(a,i);try{return(await iNn(o,s,`wrap-elements`,{targets:u,groupId:c,bbox:l,rebases:d},`Group elements`,e)).groupId??c}catch(e){return n(e instanceof Error?e.message:`Failed to group elements`,`error`),null}},[t,r,n,e,i]),ungroupSelection:(0,U.useCallback)(async a=>{let o=r.current;if(!o)return;let s=a.sourceFile||t||`index.html`,c=rNn(a,i);try{await iNn(o,s,`unwrap-elements`,{target:Wt(a),childTracks:c},`Ungroup elements`,e)}catch(e){n(e instanceof Error?e.message:`Failed to ungroup elements`,`error`)}},[t,r,n,e,i])}}var oNn=[`x`,`y`,`rotation`,`rotationX`,`rotationY`,`rotationZ`,`z`,`transformPerspective`,`scaleX`,`scaleY`,`scale`,`opacity`];function sNn(e){let t={};for(let[n,r]of Object.entries(e)){if(typeof r!=`number`||!Number.isFinite(r))return null;t[n]=r}return Object.keys(t).length>0?t:null}function cNn(e,t,n){try{let r=e.contentWindow?.gsap,i=e.contentDocument?.querySelector(t)??null,a=sNn(n);return!r?.set||!i||!a?!1:(r.set(i,a),jQt(i,a),!0)}catch{return!1}}function lNn(e){try{return e.contentWindow?.__player??null}catch{return null}}function uNn(e){if(e.length===0)return!1;for(let t of e){if(!t||typeof t!=`object`)return!1;for(let e of Object.values(t))if(typeof e!=`number`||!Number.isFinite(e))return!1}return!0}function dNn(e,t){let n=e.vars;if(!n||`motionPath`in n)return!1;let r=!1;for(let e of oNn){let i=t[e];if(i!==void 0){if(typeof i!=`number`||!Number.isFinite(i)||typeof n[e]==`string`)return!1;n[e]=i,r=!0}}return r}function fNn(e,t){let n=e.vars;return!n||`motionPath`in n||!Array.isArray(n.keyframes)||!uNn(t)?!1:(n.keyframes=t.map(e=>({...e})),!0)}function pNn(e,t,n){let r={};for(let[t,n]of Object.entries(e))r[t]={...n};let i=null;for(let e of Object.keys(r)){let n=parseFloat(e);if(Number.isFinite(n)&&Math.abs(n-t)<.05){i=e;break}}return i===null&&(i=`${t}%`),r[i]={...r[i]??{},...n},r}function mNn(e,t,n){let r=e.vars;if(!r||`motionPath`in r)return!1;let i=r.keyframes;if(!i||typeof i!=`object`||Array.isArray(i))return!1;for(let e of Object.values(n))if(typeof e!=`number`||!Number.isFinite(e))return!1;let a=e.parent,o=e.targets?.();if(!a?.to||!o||o.length===0||typeof e.startTime!=`function`||typeof e.kill!=`function`)return!1;let s=pNn(i,t,n),c={...r,keyframes:s},l=e.startTime();return e.kill(),a.to(o,c,l),!0}function hNn(e){if(e.kind===`set`)return Object.keys(e.props).filter(t=>e.props[t]!==void 0);if(e.kind===`keyframe-rebuild`)return Object.keys(e.props)}function gNn(e,t){let n=lNn(e),r=typeof n?.getTime==`function`?n.getTime():typeof t.time==`function`?t.time():0;n?.seek?.(Number.isFinite(r)?r:0)}function _Nn(e){return e.kind===`set`||e.kind===`global-set`?e.props.opacity!==void 0:e.kind===`keyframes`?e.keyframes.some(e=>`opacity`in e):`opacity`in e.props}function vNn(e){let t=typeof e.targets==`function`?e.targets():[];for(let e of t??[]){let t=e;if(!t?.style||typeof t.getAttribute!=`function`)continue;let n=yQt(t);n!==null&&bQt(t.style,n)}}function yNn(e,t){return t.kind===`set`?dNn(e,t.props):t.kind===`keyframes`?fNn(e,t.keyframes):t.kind===`keyframe-rebuild`&&mNn(e,t.pct,t.props)}function bNn(e,t,n,r,i=!1){if(!e)return!1;if(n.kind===`global-set`)return cNn(e,t,n.props);try{let a=I9t(e,t,n.kind===`set`?`set`:`keyframe`,r,hNn(n));if(!a)return!1;let{tween:o,timeline:s}=a;return _Nn(n)&&vNn(o),yNn(o,n)?(n.kind!==`keyframe-rebuild`&&o.invalidate?.(),i||gNn(e,s),!0):!1}catch{return!1}}function xNn(){let e=new Map;return function(t,n){let r=(e.get(t)??Promise.resolve()).then(n,n);return e.set(t,r),r.then(()=>{e.get(t)===r&&e.delete(t)},()=>{e.get(t)===r&&e.delete(t)}),r}}function SNn(e,t){return e.sourceFile||t||`index.html`}function CNn({projectIdRef:e,activeCompPath:t,commitMutation:n,commitMutationSafely:r,showToast:i,sdkSession:a,sdkDeps:o,writeProjectFile:s}){return{updateGsapMeta:(0,U.useCallback)(async(e,n,i)=>{if(!(a&&o&&F6(await z6(e.sourceFile||t||`index.html`,{kind:`set`,animationId:n,properties:i},a,o,{label:`Edit GSAP animation`,coalesceKey:`gsap:${n}:meta`}))))return r(e,{type:`update-meta`,animationId:n,updates:i},{label:`Edit GSAP animation`,coalesceKey:`gsap:${n}:meta`,softReload:!0})},[r,t,a,o]),deleteGsapAnimation:(0,U.useCallback)(async(e,n)=>{if(!(a&&o&&F6(await z6(e.sourceFile||t||`index.html`,{kind:`remove`,animationId:n},a,o,{label:`Delete GSAP animation`}))))return r(e,{type:`delete`,animationId:n,stripStudioEdits:!0},{label:`Delete GSAP animation`,softReload:!0})},[r,t,a,o]),deleteAllForSelector:(0,U.useCallback)(async(e,r)=>{a&&o&&F6(await jdn(e.sourceFile||t||`index.html`,r,a,o,{label:`Delete all animations for element`}))||n(e,{type:`delete-all-for-selector`,targetSelector:r},{label:`Delete all animations for element`,softReload:!0})},[n,t,a,o]),addGsapAnimation:(0,U.useCallback)(async(r,c,l)=>{let u=Zjn(r),{autoId:d}=u,f=u.selector;if(d){let n=e.current;if(!n)return;let a=r.sourceFile||t||`index.html`,o=()=>hMn({projectId:n,targetPath:a,selection:r,autoId:d,showToast:i}),c=await(s?jZ(s,a,o):o());if(!c)return;r.element.setAttribute(`id`,c),f=iJ(c)}let p=Number.parseFloat(r.dataAttributes?.start??`0`)||0,m=Number.parseFloat(r.dataAttributes?.duration??`1`)||1,h=S(p),g=S(m),_={from:{opacity:0},to:{x:0,y:0,opacity:1},set:{opacity:1},fromTo:{x:0,y:0,opacity:1}};if(!d&&r.hfId&&a&&o){let e=r.sourceFile||t||`index.html`,n={method:c,position:h,...c===`set`?{}:{duration:g,ease:`power2.out`},properties:_[c]??{opacity:1},...c===`fromTo`?{fromProperties:{opacity:0}}:{}};if(F6(await z6(e,{kind:`add`,target:r.hfId,spec:n},a,o,{label:`Add GSAP ${c} animation`})))return}await n(r,{type:`add`,targetSelector:f,method:c,position:h,duration:c===`set`?void 0:g,ease:c===`set`?void 0:`power2.out`,properties:_[c]??{opacity:1},fromProperties:c===`fromTo`?{opacity:0}:void 0},{label:`Add GSAP ${c} animation`,softReload:!0})},[t,n,e,i,a,o,s]),addWithKeyframes:(0,U.useCallback)(async(e,r,i,s,c,l,u=`Add animation with keyframes`)=>{a&&o&&F6(await Ldn(e.sourceFile||t||`index.html`,r,i,s,c,l,a,o,{label:u}))||n(e,{type:`add-with-keyframes`,targetSelector:r,position:i,duration:s,keyframes:c,...l?{ease:l}:{}},{label:u,softReload:!0})},[n,t,a,o]),replaceWithKeyframes:(0,U.useCallback)(async(e,r,i,s,c,l,u,d=`Replace animation with keyframes`)=>{a&&o&&F6(await Rdn(e.sourceFile||t||`index.html`,r,i,s,c,l,u,a,o,{label:d}))||n(e,{type:`replace-with-keyframes`,animationId:r,targetSelector:i,position:s,duration:c,keyframes:l,...u?{ease:u}:{}},{label:d,softReload:!0})},[n,t,a,o])}}function wNn(e){return{setArcPath:(0,U.useCallback)((t,n,r)=>{e(t,{type:`set-arc-path`,animationId:n,...r},{label:r.enabled?`Enable arc path`:`Disable arc path`,softReload:!0})},[e]),updateArcSegment:(0,U.useCallback)((t,n,r,i)=>{e(t,{type:`update-arc-segment`,animationId:n,segmentIndex:r,...i},{label:`Update arc segment`,softReload:!0})},[e]),removeArcPath:(0,U.useCallback)((t,n)=>{e(t,{type:`remove-arc-path`,animationId:n},{label:`Remove arc path`,softReload:!0})},[e])}}async function TNn(e){let t=e.apply();try{await e.persist()}catch{e.rollback(t)}}async function ENn(e,t,n,r,i){let a=sJ(e);if(!a)return;let o=fHt(t,n,a);if(o){let n=Qq(t,o);if(n===null)return;o.keyframes&&o.keyframes.keyframes.length>0||await i(e,{type:`convert-to-keyframes`,animationId:o.id},{label:`Convert to keyframes`,keyframeTelemetry:!1,skipReload:!0});let a={};for(let e of Object.keys(r))a[e]=$q[e]??0;await i(e,{type:`add-keyframe`,animationId:o.id,percentage:n,properties:r,backfillDefaults:a},{label:`Add keyframe at ${y(t)}s`,coalesceKey:`keyframe:${o.id}:${n}`,softReload:!0})}else{let n=lJ(e);if(!n)return;await i(e,{type:`add-with-keyframes`,targetSelector:n,position:t,duration:.5,keyframes:[{percentage:0,properties:r},{percentage:100,properties:r}]},{label:`New animation at ${y(t)}s`,softReload:!0})}}function DNn(e){return TNn({apply:()=>{let t=hpn(e.sourceFile,e.elementId);return t&&gpn(e.sourceFile,e.elementId,e.apply(t)),t},persist:e.persist,rollback:t=>{gpn(e.sourceFile,e.elementId,t)}})}function ONn(e,t){return{label:e,coalesceKey:t?.coalesceKey,coalesceMs:t?.coalesceMs,skipRefresh:t?.skipReload}}function kNn({activeCompPath:e,commitMutation:t,commitMutationSafely:n,trackGsapSaveFailure:r,sdkSession:i,sdkDeps:a}){return{addKeyframe:(0,U.useCallback)((n,o,s,c,l)=>{let u=n.sourceFile||e||`index.html`,d={type:`add-keyframe`,animationId:o,percentage:s,properties:{[c]:l}};DNn({sourceFile:u,elementId:n.id,apply:e=>{let t=e.keyframes.findIndex(e=>Math.abs((e.tweenPercentage??e.percentage)-s)<=2);if(t>=0){let n=e.keyframes.slice();return n[t]={...n[t],properties:{...n[t].properties,[c]:l}},{...e,keyframes:n}}return{...e,keyframes:[...e.keyframes,{percentage:s,properties:{[c]:l}}].sort((e,t)=>e.percentage-t.percentage)}},persist:async()=>{if(i&&a){let e=await Odn(u,o,s,{[c]:l},i,a,{label:`Add keyframe at ${s}%`,coalesceKey:`gsap:${o}:kf:${s}`});if(F6(e)){e.before!==e.after&&T8(`add`,c);return}}await t(n,d,{label:`Add keyframe at ${s}%`,keyframeProperty:c,softReload:!0})}}).catch(e=>{r(e,n,d,`Add keyframe at ${s}%`)})},[e,t,r,i,a]),addKeyframeBatch:(0,U.useCallback)(async(n,r,o,s,c)=>{if(i&&a){let t=await Odn(n.sourceFile||e||`index.html`,r,o,s,i,a,ONn(`Add keyframe at ${o}%`,c));if(F6(t)){t.before!==t.after&&c?.keyframeTelemetry!==!1&&T8(`add`);return}}return t(n,{type:`add-keyframe`,animationId:r,percentage:o,properties:s},{label:`Add keyframe at ${o}%`,softReload:!0,...c})},[t,e,i,a]),removeKeyframe:(0,U.useCallback)((n,o,s,c)=>{let l=n.sourceFile||e||`index.html`,u={type:`remove-keyframe`,animationId:o,percentage:s};DNn({sourceFile:l,elementId:n.id,apply:e=>({...e,keyframes:e.keyframes.filter(e=>Math.abs((e.tweenPercentage??e.percentage)-s)>2)}),persist:async()=>{let e=`Remove keyframe at ${s}%`;if(i&&a&&F6(await kdn(l,o,s,i,a,ONn(e,c))))return;let r=c?.skipReload?{label:e,...c}:{label:e,softReload:!0,...c};await t(n,u,r)}}).catch(e=>{r(e,n,u,`Remove keyframe at ${s}%`)})},[e,t,r,i,a]),moveKeyframe:(0,U.useCallback)(async(e,n,i,a)=>{let o={type:`move-keyframe`,animationId:n,fromPercentage:i,toPercentage:a};try{let n=!1;return await t(e,o,{label:`Move keyframe to ${a}%`,softReload:!0,onResult:e=>{n=e.changed!==!1}}),n}catch(t){return r(t,e,o,`Move keyframe to ${a}%`),!1}},[t,r]),resizeKeyframedTween:(0,U.useCallback)(async(e,n,i,a,o)=>{let s={type:`resize-keyframed-tween`,animationId:n,position:i,duration:a,pctRemap:o};try{let n=!1;return await t(e,s,{label:`Retime keyframe (resize tween)`,softReload:!0,onResult:e=>{n=e.changed!==!1}}),n}catch(t){return r(t,e,s,`Retime keyframe (resize tween)`),!1}},[t,r]),convertToKeyframes:(0,U.useCallback)(async(n,r,o,s,c={softReload:!0})=>{if(i&&a){let t=await Ndn(n.sourceFile||e||`index.html`,r,o,i,a,ONn(`Convert to keyframes`,c));if(F6(t)){t.before!==t.after&&c.keyframeTelemetry!==!1&&T8(`convert`);return}}return t(n,{type:`convert-to-keyframes`,animationId:r,resolvedFromValues:o,duration:s},{label:`Convert to keyframes`,...c})},[t,e,i,a]),removeAllKeyframes:(0,U.useCallback)(async(t,r,o=`remove_all`,s=!0)=>{let c=t.sourceFile||e||`index.html`,l=()=>{let e=t.id||t.element?.id;e&&cpn(c,e)};if(i&&a){let e=await Mdn(c,r,i,a,{label:`Remove all keyframes`});if(F6(e)){l();let t=e.before!==e.after;return t&&s&&T8(o),t}}let u=!1;return await n(t,{type:`remove-all-keyframes`,animationId:r},{label:`Remove all keyframes`,keyframeAction:o,keyframeTelemetry:s,softReload:!0,onResult:e=>{u=e.ok&&e.changed===!0,u&&l()}}),u},[n,e,i,a]),commitKeyframeAtTime:(0,U.useCallback)((e,n,r,i)=>ENn(e,n,r,i,t),[t])}}var ANn=150;function $7(e,t,n,r){try{let i=JZ(e.serialize());if(!i)return{...n};let a=p0e(i).animations.find(e=>e.id===t);return a?{...r===`from`?a.fromProperties??{}:a.properties,...n}:{...n}}catch{return{...n}}}function jNn(e,t){let n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)(t);i.current=t;let a=(0,U.useCallback)(async()=>{let t=n.current;if(!t)return;n.current=null;let{selection:r,animationId:a,property:o,value:s}=t,c={type:`update-property`,animationId:a,property:o,value:s},l=`Edit GSAP ${o}`;try{let{sdkSession:t,sdkDeps:n,activeCompPath:u}=i.current??{};if(t&&n&&F6(await z6(r.sourceFile||u||`index.html`,{kind:`set`,animationId:a,properties:{properties:$7(t,a,{[o]:s},`to`)}},t,n,{label:l,coalesceKey:`gsap:${a}:${o}`})))return;await e(r,c,{label:l,coalesceKey:`gsap:${a}:${o}`,softReload:!0})}catch(e){i.current?.onFlushError?.(e,r,c,l)}},[e]),o=(0,U.useCallback)((e,t,i,o)=>{n.current={selection:e,animationId:t,property:i,value:o},r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a()},ANn)},[a]);(0,U.useEffect)(()=>()=>{r.current&&clearTimeout(r.current),a()},[a]);let s=(0,U.useCallback)(async(t,n,r)=>{let a=$q[r]??0,o=t.element;if(r===`width`||r===`height`){let e=o.getBoundingClientRect();a=Math.round(r===`width`?e.width:e.height)}else if(r===`opacity`||r===`autoAlpha`){let e=o.ownerDocument.defaultView?.getComputedStyle(o),t=e?Number.parseFloat(e.opacity):NaN;a=Number.isFinite(t)?t:1}let{sdkSession:s,sdkDeps:c,activeCompPath:l}=i.current??{};s&&c&&F6(await z6(t.sourceFile||l||`index.html`,{kind:`set`,animationId:n,properties:{properties:$7(s,n,{[r]:a},`to`)}},s,c,{label:`Add GSAP ${r}`}))||e(t,{type:`add-property`,animationId:n,property:r,defaultValue:a},{label:`Add GSAP ${r}`})},[e]),c=(0,U.useCallback)(async(t,n,r,a)=>{let{sdkSession:o,sdkDeps:s,activeCompPath:c}=i.current??{};o&&s&&F6(await Adn(t.sourceFile||c||`index.html`,n,r,a,o,s,{label:`Remove GSAP ${a?`from-${r}`:r}`}))||(a?e(t,{type:`remove-from-property`,animationId:n,property:r},{label:`Remove GSAP from-${r}`}):e(t,{type:`remove-property`,animationId:n,property:r},{label:`Remove GSAP ${r}`}))},[e]);return{updateGsapProperty:o,addGsapProperty:s,removeGsapProperty:(0,U.useCallback)((e,t,n)=>c(e,t,n,!1),[c]),updateGsapFromProperty:(0,U.useCallback)(async(t,n,r,a)=>{let{sdkSession:o,sdkDeps:s,activeCompPath:c}=i.current??{};o&&s&&F6(await z6(t.sourceFile||c||`index.html`,{kind:`set`,animationId:n,properties:{fromProperties:$7(o,n,{[r]:a},`from`)}},o,s,{label:`Edit GSAP from-${r}`,coalesceKey:`gsap:${n}:from:${r}`}))||e(t,{type:`update-from-property`,animationId:n,property:r,value:a},{label:`Edit GSAP from-${r}`,coalesceKey:`gsap:${n}:from:${r}`})},[e]),addGsapFromProperty:(0,U.useCallback)(async(t,n,r)=>{let a=$q[r]??0,{sdkSession:o,sdkDeps:s,activeCompPath:c}=i.current??{};o&&s&&F6(await z6(t.sourceFile||c||`index.html`,{kind:`set`,animationId:n,properties:{fromProperties:$7(o,n,{[r]:a},`from`)}},o,s,{label:`Add GSAP from-${r}`}))||e(t,{type:`add-from-property`,animationId:n,property:r,defaultValue:a},{label:`Add GSAP from-${r}`})},[e]),removeGsapFromProperty:(0,U.useCallback)((e,t,n)=>c(e,t,n,!0),[c])}}function MNn(e){return typeof e.type==`string`?e.type:`gsap`}function NNn(e){return(0,U.useCallback)((t,n,r,i)=>{rX({source:`gsap_commit`,error:t,filePath:n.sourceFile??e??`index.html`,mutationType:MNn(r),label:i,targetId:n.id,targetSelector:n.selector,targetSourceFile:n.sourceFile})},[e])}function PNn(e,t,n){return(0,U.useCallback)((r,i,a)=>e(r,i,a).catch(e=>{t(e,r,i,a.label),n?.(`Couldn't save animation: ${QY(e)}`,`error`)}),[e,t,n])}async function FNn(e,t,n,r){let i=await $Qt(e,t,n,r);if(!i.ok)throw new Qjn(i.status,await tMn(i));let a=await i.json();if(!a.ok)throw Error(`Failed to update GSAP in ${n}`);return a}function INn(e,t,n){t.changed===!1&&e.length===1&&e[0]?.type===`move-keyframe`&&n?.(`A keyframe already exists at that time`,`info`)}async function LNn(e,t,n,r){let i=e.flatMap(e=>fH(e));if(i.length>0){if(n?.(`Couldn't read element layout — try again at a different playhead time`,`error`),t.skipReload)return;throw $Y(Error(`Mutation contains unsafe values: ${i.map(e=>e.path).join(`, `)}`))}try{let t=await r();return INn(e,t,n),t}catch(e){if(e instanceof Qjn&&(n?.(rMn(e),`error`),$Y(e)),t.skipReload)return;throw e}}function RNn(e,t,n,r){return t.changed===!1&&(!n.skipReload&&(GNn(n).length>0||n.previewFallbackLatch?.pending)&&zNn(n,()=>WNn(e,t,n,r)),!0)}function zNn(e,t){e.pendingEdit?e.pendingEdit.drawUnlessUndone(t):t()}function BNn(e,t,n,r,i,a){zNn(n,()=>{n.beforeReload?.(),WNn(e,t,n,r,a)}),i()}function VNn(e,t,n,r){return e.current===n&&t.current===r}function HNn({iframe:e,selection:t,mutation:n,targetPath:r,result:i,options:a,onFileContentChanged:o,forceReloadSdkSession:s,reloadPreview:c,onCacheInvalidate:l,nestedFiles:u}){i.after!=null&&o?.(r,i.after),s?.(),!a.skipReload&&(i.parsed?.animations&&opn(i.parsed.animations,r,t.id??void 0,n,e?.contentDocument),BNn(e,i,a,c,l,u))}function UNn(e,t,n,r,i,a){let o=X.getState().currentTime,s=QZ(e,t,{onAsyncFailure:n,currentTimeOverride:o,authoredHtml:i,nestedFiles:a});s!==`applied`&&(mG(`gsap_soft_reload_outcome`,{origin:r,result:s,escalated:s===`cannot-soft-reload`}),s===`cannot-soft-reload`&&n())}function WNn(e,t,n,r,i){let a=GNn(n),o=a.length===0,s=n.previewFallbackLatch?.pending===!0||o;if(a.length>0){let t=n.deferPreviewSync===!0,r=a.find((n,r)=>!bNn(e,n.selector,n.change,void 0,t||r<a.length-1));if(r&&(mG(`gsap_instant_patch_fallback`,{selector:r.selector}),s=!0),!s)return}if(n.deferPreviewSync&&n.previewFallbackLatch){n.previewFallbackLatch.pending=s;return}n.deferPreviewSync&&!s||(n.previewFallbackLatch&&(n.previewFallbackLatch.pending=!1),n.softReload&&t.scriptText?UNn(e,t.scriptText,r,`preview_sync`,t.after??void 0,i):r())}function GNn(e){return[...e.instantPatches??[],...e.instantPatch?[e.instantPatch]:[]]}function KNn({projectIdRef:e,activeCompPath:t,previewIframeRef:n,editHistory:r,reloadPreview:i,onCacheInvalidate:a,onFileContentChanged:o,showToast:s,sdkSession:c,publishSdkSession:l,writeProjectFile:u,forceReloadSdkSession:d}){let f=e.current,p=(0,U.useRef)(t);p.current=t;let m=(0,U.useRef)(xNn()),h=(0,U.useCallback)(async(e,t,n)=>{t.before!=null&&t.after!=null&&await r.recordEdit({label:n.label,coalesceKey:n.coalesceKey,coalesceMs:n.coalesceMs,files:{[e]:{before:t.before,after:t.after}}})},[r]),g=(0,U.useCallback)(async(t,r,s,c,l,u,f)=>{if(e.current!==t)return;let m=VNn(e,p,t,r);if(u.changed===!1){m&&RNn(n.current,u,f,i);return}await h(l,u,f);let g=await $Z(u.scriptText?eQ(n.current,u.scriptText,e=>NZ(t,e)):null);VNn(e,p,t,r)&&HNn({iframe:n.current,selection:s,mutation:c,targetPath:l,result:u,options:f,onFileContentChanged:o,forceReloadSdkSession:d,reloadPreview:i,onCacheInvalidate:a,nestedFiles:g})},[e,n,i,a,o,d,h]),_=(0,U.useCallback)((e,t,n,r,i,a)=>m2(async()=>{let o=await LNn([i],a,s,()=>FNn(e,`gsap-mutations`,n,i));o&&(Dmn([i],o,a),a.onResult?.(o),await g(e,t,r,i,n,o,a))}),[s,g]),v=(0,U.useCallback)((e,t,n,r,i)=>m2(async()=>{let a=r[0],o=r.at(-1);if(!a||!o)return;let c=r.map(({mutation:e})=>e),l=await LNn(c,i,s,()=>FNn(e,`gsap-mutations-batch`,n,{mutations:c}));if(!l)return;Dmn(c,l,i,r.map(e=>e.options)),i.onResult?.(l);let u=r.flatMap(({options:e})=>e.instantPatch?[e.instantPatch]:[]),{instantPatch:d,...f}=i,p=u.length===r.length;await g(e,t,o.selection,o.mutation,n,l,p?{...f,instantPatches:u}:f)}),[s,g]),y=(0,U.useMemo)(()=>{let e=(e,t)=>u?jZ(u,e,t):m.current(`gsap-file:${e}`,t),n=(t,n,r)=>{let i=`gsap-file:${t}`,a=()=>e(t,r);return n&&(u||n!==i)?m.current(n,a):a()},r=pX((e,r,i)=>{if(!f)return Promise.resolve();let a=SNn(e,t);return n(a,i.serializeKey,()=>_(f,t,a,e,r,i))});return r.batch=pX((e,r)=>{if(!f)return Promise.resolve();let i=e[0]?SNn(e[0].selection,t):`index.html`;return n(i,r.serializeKey,()=>v(f,t,i,e,r))}),r},[_,v,t,f,u]),b=NNn(t),x=(0,U.useCallback)((e,t,n,r)=>{b(e,t,n,r),eX(e)||s?.(`Couldn't save animation: ${QY(e)}`,`error`)},[s,b]),S=PNn(y,x),C=(0,U.useCallback)(e=>{let t=JZ(e);t?UNn(n.current,t,i,`sdk_refresh`,e):i(),a()},[n,i,a]),w=(0,U.useCallback)(e=>{if(!f)throw Error(`No active project`);return NZ(f,e)},[f]),T=(0,U.useMemo)(()=>u?{editHistory:{recordEdit:r.recordEdit},writeProjectFile:u,reloadPreview:i,refresh:C,compositionPath:t,readProjectFile:w,publishSession:l}:null,[r.recordEdit,u,i,C,t,w,l]),E=jNn(S,{sdkSession:c,sdkDeps:T,activeCompPath:t,onFlushError:x}),D=CNn({projectIdRef:e,activeCompPath:t,commitMutation:y,commitMutationSafely:S,showToast:s,sdkSession:c,sdkDeps:T,writeProjectFile:u}),O=kNn({activeCompPath:t,commitMutation:y,commitMutationSafely:S,trackGsapSaveFailure:x,sdkSession:c,sdkDeps:T}),k=wNn(S);return{commitMutation:y,...E,...D,...O,...k}}function qNn({previewIframe:e,activeCompPath:t,captionEditMode:n,domEditSelectionRef:r,domEditGroupSelectionsRef:i,domEditSelection:a,applyDomSelection:o,refreshDomEditGroupSelectionsFromPreview:s,buildDomSelectionFromTarget:c,refreshPreviewDocumentVersion:l,syncPreviewHotkeys:u,applyStudioManualEditsToPreviewRef:d,openSourceForSelection:f,gsapCacheVersion:p}){(0,U.useEffect)(()=>{if(!e)return;let a=async()=>{if(n)return;let a=r.current;if(!a)return;let l=null;try{l=e.contentDocument}catch{return}if(!l)return;a3(l);let u=He(l,a,t);if(!u){let e=i.current;if(K4(`preview-sync-lost`,{target:a.selector??a.id??null,group:e.length}),e.length>1){await s(e);return}o(null,{revealPanel:!1});return}let d=await c(u,{previous:a});d&&o(d,{revealPanel:!1,preserveGroup:!0})};return u(e),d.current(e),a(),l(),g2(e,()=>{u(e),d.current(e),a(),l()})},[t,o,c,n,i,r,e,s,l,u,d,p]);let m=(0,U.useRef)(f);m.current=f,(0,U.useEffect)(()=>{!a||!m.current||a.sourceFile&&W8.getState().visiblePanels.has(`code`)&&m.current(a.sourceFile,{id:a.id,selector:a.selector,selectorIndex:a.selectorIndex})},[a])}var JNn=1,YNn=120,XNn=e=>new Promise(t=>setTimeout(t,e));function ZNn(e){return e.sourceFile||`index.html`}function QNn(e,t,n){return e?{kind:`resolved`,animations:N8(e.animations,t,n)}:{kind:`fetch-error`}}async function $Nn(e,t,n,r,i,a){for(let o=0;;o++){let s=await R8(e,t,{fresh:a});a=!1;let c=QNn(s,n,r);if(c.kind===`resolved`)return c.animations;if(o>=JNn){if(i)throw Error(`GSAP animation ownership could not be verified`);return[]}await XNn(YNn)}}function ePn(e){return(0,U.useCallback)((t,n)=>async()=>{if(!e)return[];let r={id:t.id??null,selector:t.selector??null};return $Nn(e,ZNn(t),r,t.element,n?.failOnFetchError===!0,n?.fresh===!0)},[e])}function tPn({domEditSelection:e,updateGsapProperty:t,updateGsapMeta:n,deleteGsapAnimation:r,deleteAllForSelector:i,addGsapAnimation:a,addGsapProperty:o,removeGsapProperty:s,updateGsapFromProperty:c,addGsapFromProperty:l,removeGsapFromProperty:u,addKeyframe:d,addKeyframeBatch:f,removeKeyframe:p,moveKeyframe:m,resizeKeyframedTween:h,convertToKeyframes:g,removeAllKeyframes:_,handleDomManualEditsReset:v,selectedGsapAnimations:y,showToast:b}){let x=(0,U.useRef)(null);e&&(x.current=e);let S=(0,U.useCallback)(t=>t===void 0?e??x.current:t,[e]),C=(0,U.useCallback)((e,t,n,r)=>{rX({source:`gsap_commit`,error:e,filePath:t.sourceFile??void 0,mutationType:n,label:r,targetId:t.id,targetSelector:t.selector,targetSourceFile:t.sourceFile}),eX(e)||b(`Couldn't save animation: ${QY(e)}`,`error`)},[b]),w=(0,U.useCallback)((e,t,n,r)=>e.then(()=>!0,e=>(C(e,t,n,r),!1)),[C]);return{handleGsapUpdateProperty:(0,U.useCallback)((n,r,i)=>{e&&t(e,n,r,i)},[e,t]),handleGsapUpdateMeta:(0,U.useCallback)((e,t,r)=>{let i=S(r);return i?w(n(i,e,t),i,`update-meta`,`Edit GSAP animation`):Promise.resolve(!1)},[S,w,n]),handleGsapDeleteAnimation:(0,U.useCallback)((e,t)=>{let n=S(t);return n?w(r(n,e),n,`delete`,`Delete GSAP animation`):Promise.resolve(!1)},[S,r,w]),handleGsapDeleteAllForElement:(0,U.useCallback)(t=>{let n=e??x.current;n&&(mG(`keyframe`,{action:`delete_all`}),w(i(n,t),n,`delete-all-for-selector`,`Delete all animations for element`))},[e,i,w]),handleGsapAddAnimation:(0,U.useCallback)((e,t)=>{let n=S(t);if(!n)return Promise.resolve(!1);let r=w(a(n,e,X.getState().currentTime),n,`add`,`Add GSAP ${e} animation`);return n.element.hasAttribute(`data-hf-studio-path-offset`)&&r.then(e=>{e&&v(n).catch(()=>void 0)}),r},[S,a,v,w]),handleGsapAddProperty:(0,U.useCallback)((t,n)=>{e&&w(o(e,t,n),e,`add-property`,`Add GSAP ${n}`)},[e,o,w]),handleGsapRemoveProperty:(0,U.useCallback)((t,n)=>{e&&w(s(e,t,n),e,`remove-property`,`Remove GSAP ${n}`)},[e,w,s]),handleGsapUpdateFromProperty:(0,U.useCallback)((t,n,r)=>{e&&w(c(e,t,n,r),e,`update-from-property`,`Edit GSAP from-${n}`)},[e,w,c]),handleGsapAddFromProperty:(0,U.useCallback)((t,n)=>{e&&w(l(e,t,n),e,`add-from-property`,`Add GSAP from-${n}`)},[e,l,w]),handleGsapRemoveFromProperty:(0,U.useCallback)((t,n)=>{e&&w(u(e,t,n),e,`remove-from-property`,`Remove GSAP from-${n}`)},[e,w,u]),handleGsapAddKeyframe:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);a&&d(a,e,t,n,r)},[S,d]),handleGsapAddKeyframeBatch:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);return a?f(a,e,t,n,r).catch(e=>{C(e,a,`add-keyframe`,`Add keyframe`)}):Promise.resolve()},[S,f,C]),handleGsapRemoveKeyframe:(0,U.useCallback)((e,t,n,r)=>{let i=S(r);i&&(mG(`keyframe`,{action:`remove`}),p(i,e,t,n))},[S,p]),handleGsapMoveKeyframeToPlayhead:(0,U.useCallback)((e,t,n,r)=>{let i=S(n);if(!i)return;let a=_8(i,r??y.find(t=>t.id===e));mG(`keyframe`,{action:`move_to_playhead`}),m(i,e,t,a)},[S,y,m]),handleGsapMoveKeyframe:(0,U.useCallback)((e,t,n,r)=>{let i=S(r);return i?(mG(`keyframe`,{action:`retime`}),m(i,e,t,n)):Promise.resolve(!1)},[S,m]),handleGsapResizeKeyframedTween:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);return a?(mG(`keyframe`,{action:`retime_resize`}),h(a,e,t,n,r)):Promise.resolve(!1)},[S,h]),handleGsapConvertToKeyframes:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);return a?g(a,e,t,n,r).catch(e=>{C(e,a,`convert-to-keyframes`,`Convert to keyframes`)}):Promise.resolve()},[S,g,C]),handleGsapRemoveAllKeyframes:(0,U.useCallback)((e,t,n=!0)=>{let r=S(t);return r?_(r,e,`remove_all`,n).catch(e=>(C(e,r,`remove-all-keyframes`,`Remove all keyframes`),!1)):Promise.resolve(!1)},[S,C,_]),handleResetSelectedElementKeyframes:(0,U.useCallback)(()=>{if(!e)return!1;let t=y.find(e=>e.keyframes);return t?(_(e,t.id,`reset`).catch(t=>{C(t,e,`remove-all-keyframes`,`Remove all keyframes`)}),!0):!1},[e,C,_,y])}}function nPn(e){let{projectId:t,activeCompPath:n,domEditSelection:r,domEditSelectionRef:i,domEditGroupSelectionsRef:a,refreshDomEditGroupSelectionsFromPreview:o,previewIframeRef:s,previewIframe:c,captionEditMode:l,refreshKey:u,gsapCacheVersion:d,bumpGsapCache:f,showToast:p,refreshPreviewDocumentVersion:m,syncPreviewHotkeys:h,applyStudioManualEditsToPreviewRef:g,applyDomSelection:_,buildDomSelectionFromTarget:v,openSourceForSelection:y,updateGsapProperty:b,updateGsapMeta:x,deleteGsapAnimation:S,deleteAllForSelector:C,addGsapAnimation:w,addGsapProperty:T,removeGsapProperty:E,updateGsapFromProperty:D,addGsapFromProperty:O,removeGsapFromProperty:k,addKeyframe:A,addKeyframeBatch:j,removeKeyframe:M,moveKeyframe:N,resizeKeyframedTween:P,convertToKeyframes:F,removeAllKeyframes:I,handleDomManualEditsReset:L}=e,R=(0,U.useCallback)(e=>{y&&e.sourceFile&&(W8.getState().activatePanel(`code`),y(e.sourceFile,{id:e.id,selector:e.selector,selectorIndex:e.selectorIndex}))},[y]);(0,U.useEffect)(()=>{if(!r?.id)return;let{selectedElementId:e,elements:t,setSelectedElementId:n}=X.getState(),i=t.find(e=>e.domId===r.id||e.id===r.id),a=i?i.key??i.id:null;a&&a!==e&&n(a)},[r?.id]);let z=(0,U.useRef)(u);(0,U.useEffect)(()=>{u!==z.current&&(z.current=u,f())},[u,f]);let B=r?.sourceFile||n||`index.html`;Vhn(t??null,B,d,s);let{animations:V,multipleTimelines:ee,unsupportedTimelinePattern:te}=zhn(t??null,B,r,d,s),H=Mpn(n,p),ne=ePn(t),re=tPn({domEditSelection:r,updateGsapProperty:b,updateGsapMeta:x,deleteGsapAnimation:S,deleteAllForSelector:C,addGsapAnimation:w,addGsapProperty:T,removeGsapProperty:E,updateGsapFromProperty:D,addGsapFromProperty:O,removeGsapFromProperty:k,addKeyframe:A,addKeyframeBatch:j,removeKeyframe:M,moveKeyframe:N,resizeKeyframedTween:P,convertToKeyframes:F,removeAllKeyframes:I,handleDomManualEditsReset:L,selectedGsapAnimations:V,showToast:p});return qNn({previewIframe:c,activeCompPath:n,captionEditMode:l,domEditSelectionRef:i,domEditGroupSelectionsRef:a,domEditSelection:r,applyDomSelection:_,refreshDomEditGroupSelectionsFromPreview:o,buildDomSelectionFromTarget:v,refreshPreviewDocumentVersion:m,syncPreviewHotkeys:h,applyStudioManualEditsToPreviewRef:g,openSourceForSelection:y,gsapCacheVersion:d}),{onClickToSource:R,selectedGsapAnimations:V,gsapMultipleTimelines:ee,gsapUnsupportedTimelinePattern:te,trackGsapInteractionFailure:H,makeFetchFallback:ne,...re}}function rPn(e,t,n,r){for(let[n,r]of e.entries()){if(r.status!==`rejected`)continue;let e=t[n]?.selection;if(e)return{error:r.reason,selection:e}}return iPn(t,n,r)}function iPn(e,t,n){let r=e.filter(({selection:e})=>!t.has(e)),i=e=>SNn(e,n),a=r[0]&&i(r[0].selection),o=r.find(({selection:e})=>i(e)!==a);return o?{error:new c8(`mixed-files`),selection:o.selection}:null}var aPn=0;function oPn({gsapCommitMutation:e,activeCompPath:t,previewIframeRef:n,makeFetchFallback:r,trackGsapInteractionFailure:i,stageElementPositionOffset:a,showToast:o}){return(0,U.useCallback)(async(s,c={})=>{let l=E8(e),u=l.commit;if(!u)return{ok:!0,changed:!1};let d=s.some(({selection:e,plainTranslate:t})=>!(t??B0(e.element,`move`))),f=async()=>{let e=new Map(s.map(e=>[e.selection,E3(e.selection.element)])),d=c.refusalToast!==!1,f=`group-drag:${++aPn}`,p=!1,m={pending:!1},h=e=>({...e,coalesceKey:f,coalesceMs:1/0,deferPreviewSync:!p,previewFallbackLatch:m}),g=[],_=async()=>{if(g.length===0)return;let e=g.splice(0,g.length);if(!u.batch){for(let t of e)await u(t.selection,t.mutation,t.options);return}await u.batch(e,{...e.at(-1)?.options??{label:`Move animated layer (group)`},label:`Move animated layer (group)`})},v=(e,t,n)=>(g.push({selection:e,mutation:t,options:h(n)}),Promise.resolve()),y=new Map,b=new Map,x=rPn(await Promise.allSettled(s.map(async({selection:e,next:t,plainTranslate:i})=>{if(i??B0(e.element,`move`)){KMn(e.element,d?o:()=>{}),b.set(e,!0);return}let a=await r(e,{failOnFetchError:!0})();y.set(e,a);let s=await I8(e,t,a,n.current,v,void 0,{preflightOnly:!0,group:!0});s.status===`element-offset`&&b.set(e,!1),l8(s)})),s,b,t);if(x)throw i(x.error,x.selection,`drag`,`Move animated layer (group)`,d),x.error;let S=s.findLastIndex(({selection:e})=>!b.has(e));for(let[t,{selection:o,next:c}]of s.entries()){p=t===S;let s=b.get(o);if(s!==void 0){let e=await l.drawKeepingUndone(()=>a(o,c,s,f)).save();l.recordDomResult(e);continue}try{l8(await I8(o,c,y.get(o)??[],n.current,v,async()=>(await _(),r(o,{fresh:!0})()),{preflightPassed:!0,stamp:e.get(o)}))}catch(e){throw i(e,o,`drag`,`Move animated layer (group)`),e}}try{return await _(),l.finish()}catch(e){throw i(e,null,`drag`,`Move animated layer (group)`),e}};return d?m2(f):f()},[e,t,n,r,i,a,o])}function sPn(e,t){let n=[...e,...t],r=n.some(e=>e.propertyGroup===`scale`)?`scale`:`size`;return{allKnownAnimations:n,resizeGroup:r,resizeProperties:r===`scale`?new Set([`scale`,`scaleX`,`scaleY`]):new Set([`width`,`height`]),workingAnimations:e.length>0?e:t}}function cPn(e,t,n,r=[]){let{allKnownAnimations:i,resizeGroup:a,resizeProperties:o,workingAnimations:s}=sPn(t,r),c=d8(i,o);if(c.status===`blocked`)return c;let l=s.some(e=>(e.propertyGroup===a||!e.propertyGroup)&&u8(e,o)),u=sJ(e);return!l&&u&&I0(n,u,void 0,[...o])?{status:`blocked`,reason:`source-uneditable`,detail:`live-resize-no-source-tween`}:{status:`persisted`}}var lPn=0;function uPn(e){if(!e)return[`x`,`y`];let t=Object.keys(e.properties??{});if(t.length>0)return t;let n=e.keyframes?.keyframes;if(n?.length){let e=new Set;for(let t of n)for(let n of Object.keys(t.properties??{}))e.add(n);if(e.size>0)return[...e]}return[`x`,`y`]}function dPn(e,t){let n=Xq(e);return n===null||Yq(t,n,Zq(e))}async function fPn(e,t,n,r,i,a){let o=e9(i,t,n);if(Object.keys(o).length===0)for(let[e,t]of Object.entries(n.properties??{}))typeof t==`number`&&(o[e]=t);if(Object.keys(o).length===0||!e.commitMutation)return;let s=pPn(t.dataAttributes?.start,t.dataAttributes?.duration,r);await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(s.start),duration:S(s.duration),keyframes:[{percentage:0,properties:o}],ease:n.ease},{label:`Enable keyframes`,keyframeAction:`add`,softReload:!0})}function e9(e,t,n){let r={};if(!e?.contentWindow)return r;let i;try{i=e.contentWindow.gsap}catch{return r}let a=t.element;if(!a?.isConnected||!i?.getProperty)return r;let o=uPn(n);for(let e of o){let t=Number(i.getProperty(a,e));Number.isFinite(t)&&(r[e]=hhn.has(e)?Math.round(t):S(t))}return r}function pPn(e,t,n){let r=Math.max(0,S(n)),i=e==null?NaN:Number.parseFloat(e),a=t==null?NaN:Number.parseFloat(t);if(!Number.isFinite(i)||!Number.isFinite(a)||a<=0)return{start:r,duration:1};let o=i+a,s=Math.min(Math.max(r,i),o);return{start:s,duration:Math.max(.5,S(o-s))}}function mPn(e,t,n){let r=lJ(e);if(!r)return null;let{start:i,duration:a}=pPn(e.dataAttributes?.start,e.dataAttributes?.duration,n);return{type:`add-with-keyframes`,targetSelector:r,position:S(i),duration:S(a),keyframes:[{percentage:0,properties:t}]}}async function hPn(e){let t=window.location.hash.match(/project\/([^?/]+)/)?.[1];if(!t)return null;let n=await R8(t,e.sourceFile||`index.html`);return n?N8(n.animations,{id:e.id,selector:e.selector}):null}async function gPn(e){return await hPn(e)??[]}async function _Pn(e,t,n,r,i,a,o){let s=uJ(n,t),c=e9(a,t,n);if(!s||Object.keys(c).length===0||!e.commitMutation)return;let l=yhn(n,r,c,i);await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:s,position:l.position,duration:l.duration,keyframes:l.keyframes,...eJ(n)},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0,...o})}async function vPn(e,t,n,r,i,a,o){let s=n.durationUnresolved===!0;if(s&&(n=c9t(n,o??O0(i,t.element,n))),s&&n.duration==null)return;let c=Zq(n),l=Xq(n);if(l!==null&&!Yq(r,l,c)){if(s)return;await _Pn(e,t,n,r,c,i,a);return}let u=l===null?fJ(r,t):Qq(r,n)??0,d=n.keyframes?.keyframes.find(e=>rJ(n,e.percentage,u));if(d){e.handleGsapRemoveKeyframe(n.id,d.percentage);return}if(e.handleGsapAddKeyframeBatch){let r=e9(i,t,n);Object.keys(r).length>0&&await e.handleGsapAddKeyframeBatch(n.id,u,r,a)}}async function yPn(e,t,n,r,i){let a=uJ(n,t),o=Xq(n)??0;if(!a||!e.commitMutation)return;if(r<=o){await fPn(e,t,n,r,i,a);return}let s=e9(i,t,n);if(Object.keys(s).length===0)return;let c={};for(let e of Object.keys(s)){let t=n.properties?.[e];typeof t==`number`&&(c[e]=t)}await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(o),duration:S(r-o),keyframes:[{percentage:0,properties:Object.keys(c).length>0?c:s,auto:!0},{percentage:100,properties:s}],ease:n.ease},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0})}async function bPn(e,t,n,r,i){if(!e.commitMutation)return;let a=uJ(n,t);if(!a)return;let o=Xq(n)??0,s=Zq(n);if(!Yq(r,o,s)){let c=e9(i,t,n);if(r<=o||typeof c.x!=`number`||typeof c.y!=`number`)return;let l=yhn(n,r,{x:c.x,y:c.y},s,`none`);await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:l.position,duration:l.duration,keyframes:l.keyframes,ease:`none`},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0});return}let c=vhn(n),l=Jq(r,o,s),u=c.findIndex(e=>Math.abs(e.percentage-l)<=nJ);if(u!==-1){u>0&&u<c.length-1&&await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(o),duration:S(s),keyframes:c.filter((e,t)=>t!==u),ease:`none`},{label:`Remove keyframe`,softReload:!0});return}let d=e9(i,t,n);typeof d.x==`number`&&typeof d.y==`number`&&await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(o),duration:S(s),keyframes:_hn(n,l,{x:d.x,y:d.y}),ease:`none`},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0})}function xPn(e){return(0,U.useCallback)(async()=>{let t=e.current;if(!t)return;let n=t.domEditSelection;if(!n)return;let r=X.getState().currentTime,i=t.previewIframeRef?.current??null,a=await hPn(n)??t.selectedGsapAnimations,o=a.find(e=>e.arcPath),s=a.find(e=>e.keyframes&&!e.arcPath),c=a.find(e=>tJ(e)&&!e.keyframes&&!e.arcPath),l=a.find(e=>!e.keyframes&&!e.arcPath&&!tJ(e));if(o)await bPn(t,n,o,r,i);else if(s)await vPn(t,n,s,r,i);else if(c)await yPn(t,n,c,r,i);else if(l){let e=l.durationUnresolved?O0(i,n.element,l):void 0;lPn+=1;let a=`enable-keyframes:${l.id}:${lPn}`,o={keyframeTelemetry:!1,skipReload:!0,coalesceKey:a,coalesceMs:1/0};await t.handleGsapConvertToKeyframes(l.id,void 0,void 0,o);let s=(await gPn(n)).find(e=>e.keyframes);s&&await vPn(t,n,s,r,i,{softReload:!0,coalesceKey:a,coalesceMs:1/0},e)}else{let e=e9(i,n,null);Object.keys(e).length===0&&Object.assign(e,ton(n.element));let a=mPn(n,e,r);a&&t.commitMutation?await t.commitMutation(a,{label:`Enable keyframes`,softReload:!0}):t.handleGsapAddAnimation(`to`)}},[e])}var SPn=new Set([`width`,`height`]),CPn=new Set([`x`,`y`]),wPn=new Set([`x`,`y`,`xPercent`,`yPercent`,`width`,`height`]);function t9(e,t,n){let r=Number.parseFloat(e?.getAttribute(t)??``);if(Number.isFinite(r)&&r>0)return r;let i=Number.parseFloat(e?.getAttribute(`data-hf-studio-original-${n}`)??``);return Number.isFinite(i)&&i>0?i:null}function TPn(e){let t=t9(e,o0,`width`),n=t9(e,s0,`height`);return{...t!=null&&{width:t},...n!=null&&{height:n}}}async function EPn(e,t,n,r,i,a){let o=sJ(e),s=i&&(i.x!==0||i.y!==0)&&o&&u8(t,CPn)?D3(e.element,i,x8(r,o)??{x:0,y:0},a.stamp):null,c=await A8(e,t,s?{...n,x:s.newX,y:s.newY}:n,r,a,{label:`Resize`,backfill:{...TPn(e.element),...s&&{x:s.baseGsapX,y:s.baseGsapY}},...s&&{beforeReload:()=>O3(e.element,a.stamp)}});return c.status===`persisted`&&s?{...c,ownsDragOffset:!0}:c}function DPn(e,t,n,r){let{width:i,height:a}=n;return t.status!==`persisted`||i==null||a==null||r(()=>{h3(e.element),SQt(e.element,i,a)}),t}function OPn(e,t,n,r,i){let{autoKeyframeEnabled:a}=X.getState(),o=r.some(e=>e.keyframes&&u8(e,wPn));return n!==`size`||!a||!o?null:mPn(e,t,i)}function kPn(e){let t=e=>e===`scaleX`||e===`scaleY`;return(e?.keyframes?.keyframes??[]).some(e=>Object.keys(e.properties??{}).some(t))||Object.keys(e?.properties??{}).some(t)}async function APn(e,t,n,r,i,a,o,s=e=>e(),c){let l=e6(c),u=a?await a():[],d=cPn(e,n,r,u);if(d.status===`blocked`)return d;let{allKnownAnimations:f,resizeGroup:p,resizeProperties:m,workingAnimations:h}=sPn(n,u),g=await F8(p,h,e,i,h.some(e=>!e.propertyGroup)?a:void 0,l.time),_=g?.anim&&u8(g.anim,m)?g.anim:null;if(J3(`intercept-enter`,{hasScaleGroup:p===`scale`,resizeGroup:p,animMethod:_?.method??null,animId:_?.id??null,size:t}),!_||tJ(_)){let n={width:le(t.width),height:le(t.height)};if(!f.some(e=>u8(e,SPn))){let t=OPn(e,n,p,h,l.time);return t?(await i(e,t,{label:`Resize`,softReload:!0}),DPn(e,{status:`persisted`},n,s)):{status:`element-size`}}let u=sJ(e)??lJ(e);if(!u)return{status:`blocked`,reason:`no-selector`};let d=p===`size`?_??Jpn(h,u,e.element):Jpn(h,u,e.element);if(p===`size`){let t=C8(h.filter(e=>!tJ(e)&&Zq(e)>0&&u8(e,m)),l.time);if(t)return J3(`intercept-route`,{route:`keyframed-size`,tweenId:t.id}),DPn(e,await EPn(e,t,n,r,o,{commitMutation:i,fetchAnimations:a,stamp:c}),n,s)}return J3(`intercept-route`,{route:`static-size-set`,hadSizeSet:!!d,resizeGroup:p}),await rmn(e,t,u,d,{commitMutation:i,fetchAnimations:a}),{status:`persisted`}}if(Zq(_)<=0)return{status:`blocked`,reason:`source-uneditable`,detail:`zero-duration-tween`};let{setActiveKeyframePct:v}=X.getState(),y=l.keyframePct,b=y??_8(e,_,l.time),x=sJ(e),C,w,T=null,E=null,D=null,O=!1,k=!1;if(p===`scale`){let e=r?.contentDocument?.querySelector(x??``),n=t9(e,o0,`width`)??200,i=t9(e,s0,`height`)??n,a=mhn(r,x??null,`scaleX`)??1,o=mhn(r,x??null,`scaleY`)??1,c=a>0?a:1,l=o>0?o:1,u=S(t.width*c/n),d=S(t.height*l/i);if(O=Math.abs(u-d)*i>.5,k=O||kPn(_),C=k?{scaleX:u,scaleY:d}:{scale:u},w={scaleX:c,scaleY:l},J3(`intercept-route`,{route:`scale-tween`,cssW:n,cssH:i,liveScaleX:c,liveScaleY:l,newScaleX:u,newScaleY:d,nonUniformScale:O}),T=e,D=k?{x:u,y:d}:{x:u,y:u},e){let t=s(()=>e.getBoundingClientRect());E={x:t.x,y:t.y}}}else C={width:le(t.width),height:le(t.height)},w=TPn(e.element);let A=async()=>{if(!T)return!1;let t=T;if(!E||!x)return s(()=>h3(t)),!1;let o=E,u=s(()=>{h3(t),D&&xQt(t,D.x,D.y);let n=x8(r,x)??{x:0,y:0},{baseGsapX:i,baseGsapY:a}=D3(e.element,{x:0,y:0},n,c),s={x:i,y:a};VZ(t,s.x,s.y);let l=t.getBoundingClientRect(),u={x:o.x-l.x,y:o.y-l.y};if(!Number.isFinite(u.x)||!Number.isFinite(u.y))return null;if(Math.abs(u.x)<.5&&Math.abs(u.y)<.5)return J3(`scale-finalize`,{skipped:`already-on-drop-point`,residual:u,base:s}),`settled`;let d={x:S(s.x+u.x),y:S(s.y+u.y)};return J3(`scale-finalize`,{dropPoint:o,post:{x:l.x,y:l.y},residual:u,gsapPos:n,base:s,corrected:d}),VZ(t,d.x,d.y),{base:s,corrected:d}});if(u===null)return!1;if(u===`settled`)return!0;let{base:d,corrected:f}=u,p=a?await a():g?.animations??n,m={x:f.x-d.x,y:f.y-d.y},h=C8(p.filter(e=>e.propertyGroup===`position`&&!tJ(e)&&Zq(e)>0),l.time);if(h)return J3(`scale-finalize`,{route:`position-keyframe`,tweenId:h.id}),l8(await xhn(e,h,m,d,r,{commitMutation:i,fetchAnimations:a,stamp:c})),!0;let _=Kpn(p,x,e.element);return await tmn(e,m,d,x,_,{commitMutation:i,fetchAnimations:a,stamp:c}),!0};if(!X.getState().autoKeyframeEnabled)return y!=null&&v(null),await j8(e,_,C,b,r,{commitMutation:i,fetchAnimations:a},`Resize animation`),{status:`persisted`,ownsDragOffset:await A()};let j={commitMutation:i,fetchAnimations:a,stamp:c};if(p===`size`)return DPn(e,await EPn(e,_,C,r,o,j),C,s);let M=await A8(e,_,C,r,j,{label:`Resize`,backfill:w});return M.status===`persisted`?{status:`persisted`,ownsDragOffset:await A()}:M}function jPn(e,t,n){let r=n?DT(n):void 0,i=r===void 0?e:e.filter(e=>e.propertyGroup===r);if(i.length===0)return;if(i.length===1)return i[0];let a=X.getState().currentTime,o=i.map(e=>{let n=0;e.keyframes&&(n+=10),t&&e.targetSelector===t?n+=5:e.targetSelector.includes(`,`)&&(n-=3);let r=e.resolvedStart??(typeof e.position==`number`?e.position:0),i=e.duration??0;return a>=r-.05&&a<=r+i+.05&&(n+=8),{anim:e,score:n}});return o.sort((e,t)=>t.score-e.score),o[0]?.anim}async function MPn(e,t,n,r){let i=n.find(e=>e.keyframes&&e.id!==t.id);i&&await r(e,{type:`convert-to-keyframes`,animationId:t.id,duration:i.duration??1},{label:`Keyframe 3D transform`,softReload:!0})}var NPn={position:`Move layer`,scale:`Resize layer`,size:`Resize layer`,rotation:`Rotate layer`,visual:`Set opacity`,other:`Set 3D transform`};function PPn(e){let t=new Set(e.map(([e])=>DT(e))),n=t.size===1?[...t][0]:void 0;return n&&NPn[n]||`Set properties`}async function FPn(e,t,n,r,i,a){let o=IPn(e,t,n,r);await a(o.selection,o.mutation,o.options),await MPn(e,t,i,a)}function IPn(e,t,n,r){let i=Object.fromEntries(n),a={};for(let[e,t]of n)typeof t==`number`&&(a[e]=t);let o=r&&Object.keys(a).length>0?{selector:r,change:{kind:t.global?`global-set`:`set`,props:a}}:void 0;return{selection:e,mutation:{type:`update-properties`,animationId:t.id,properties:i},options:{label:PPn(n),softReload:!0,...o?{instantPatch:o}:{}}}}async function LPn(e,t,n,r,i){let a=zPn(e,t,n,r),o=a[0];if(o){if(a.length===1){await i(o.selection,o.mutation,o.options);return}if(!i.batch)throw Error(`Atomic GSAP property batch is unavailable`);await i.batch(a,{label:PPn(t),softReload:!0})}}function RPn(e){let t=new Map;for(let n of e){let e=DT(n[0]),r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function zPn(e,t,n,r){let i=RPn(t),a=n?r.filter(t=>tJ(t)&&dJ(t.targetSelector,n,e.element)):[],o=new Map,s=[];for(let[e,t]of i){let n=BPn(a,e);n?o.set(n,[...o.get(n)??[],...t]):s.push(t)}return[...[...o].map(([t,r])=>IPn(e,t,r,n)),...s.map(t=>VPn(e,t))]}function BPn(e,t){return e.find(e=>e.propertyGroup===t)??e.find(e=>Object.keys(e.properties).some(e=>DT(e)===t))}function VPn(e,t){let n={};for(let[e,r]of t)typeof r==`number`&&(n[e]=r);let r=lJ(e);if(!r)throw new c8(`no-selector`);return{selection:e,mutation:{type:`add`,targetSelector:r,method:`set`,position:0,properties:Object.fromEntries(t),global:!0},options:{label:PPn(t),softReload:!0,...Object.keys(n).length>0?{instantPatch:{selector:r,change:{kind:`global-set`,props:n}}}:{}}}}async function HPn(e,t,n,r,i,a,o,s){let c=!!t.keyframes;c||await s(e,{type:`convert-to-keyframes`,animationId:t.id},{label:`Convert to keyframes`,keyframeTelemetry:!1,skipReload:!0});let l=X.getState().currentTime,u=a?ghn(o,a,t):{},d={...u,...n},f={...u};for(let[e,t]of r){if(!(e in u)&&a){let t=mhn(o,a,e);t!=null&&(f[e]=t)}f[e]=t}let p=t.keyframes?.keyframes,m=Xq(t),h=Zq(t),g=X.getState().activeKeyframePct!=null,_=m!==null&&h>0&&(l<m-.01||l>m+h+.01);if(c&&p&&_&&!g&&p&&m!==null){let n=Math.min(l,m),r=Math.max(l,m+h),a=Math.max(.01,r-n),o=Hq(t),c=e=>Math.round(Kq(o,(e-n)/a*100)*10)/10,u=p.map(e=>{let t=c(m+qq(o,e.percentage)/100*h),n={...e.properties};for(let e of Object.keys(d))!(e in n)&&f[e]!=null&&(n[e]=f[e]);return{percentage:t,properties:n,...e.ease?{ease:e.ease}:{}}});u.push({percentage:c(l),properties:d}),u.sort((e,t)=>e.percentage-t.percentage),await s(e,{type:`replace-with-keyframes`,animationId:t.id,targetSelector:t.targetSelector,position:S(n),duration:S(a),keyframes:u,...eJ(t)},{label:`Edit ${i} (extended keyframe)`,keyframeAction:`add`,softReload:!0});return}let v=fJ(l,e,t),y=t.keyframes?.keyframes.some(e=>Math.abs(e.percentage-v)<.05),b={};for(let[e,t]of Object.entries(d))typeof t==`number`&&(b[e]=t);let x=a&&Object.keys(b).length>0?{selector:a,change:{kind:`keyframe-rebuild`,pct:v,props:b}}:void 0;await s(e,y?{type:`update-keyframe`,animationId:t.id,percentage:v,properties:d}:{type:`add-keyframe`,animationId:t.id,percentage:v,properties:d,backfillDefaults:f},{label:`Edit ${i} (keyframe ${v}%)`,softReload:!0,...x?{instantPatch:x}:{}})}function UPn(e){let{selectedGsapAnimations:t,gsapCommitMutation:n,previewIframeRef:r,bumpGsapCache:i}=e,a=(0,U.useCallback)(async(e,a,o=n)=>{if(!o)return;let s=Object.entries(a);if(s.length===0)return;let c=s[0][0];l8(d8(t,new Set(s.map(([e])=>e))));let l=r.current,u=sJ(e),d=jPn(t,u,c);if(!d&&!lJ(e))throw new c8(`no-selector`);let f=t.some(e=>!!e.keyframes);try{if(f&&d){if(!X.getState().autoKeyframeEnabled){let t=fJ(X.getState().currentTime,e,d);await j8(e,d,Object.fromEntries(s.filter(e=>typeof e[1]==`number`)),t,l,{commitMutation:o},`Edit ${c} (whole animation)`);return}await HPn(e,d,a,s,c,u,l,o);return}if(!f){await LPn(e,s,u,t,o);return}if(d&&tJ(d)){await FPn(e,d,s,u,t,o);return}let n=lJ(e);if(n){let r=t.find(e=>!!e.keyframes),i=r?Xq(r)??0:0,a=r&&Zq(r)||1,l=X.getState().currentTime,u=a>0?Math.max(0,Math.min(100,Math.round((l-i)/a*1e3)/10)):0,d=Object.fromEntries(s),f=u<=.05?[{percentage:0,properties:d}]:[{percentage:0,properties:{...d,_auto:1}},{percentage:u,properties:d}];await o(e,{type:`add-with-keyframes`,targetSelector:n,position:S(i),duration:S(a),keyframes:f},{label:`Add ${c} keyframe`,softReload:!0});return}throw new c8(`no-selector`)}catch(e){throw i(),e}},[t,n,r,i]);return{commitAnimatedProperty:(0,U.useCallback)((e,t,n)=>a(e,{[t]:n}),[a]),commitAnimatedProperties:a}}function WPn({domEditSelection:e,selectedGsapAnimations:t,gsapCommitMutation:n,activeCompPath:r,previewIframeRef:i,showToast:a,bumpGsapCache:o,makeFetchFallback:s,trackGsapInteractionFailure:c,stageElementPositionOffset:l,handleDomBoxSizeCommit:u,handleDomRotationCommit:d,commitPositionPatchToHtml:f,addGsapAnimation:p,convertToKeyframes:m,setArcPath:h,updateArcSegment:g}){let _=(0,U.useCallback)(n=>e?.element===n.element?t:s(n,{failOnFetchError:!0})(),[e,t,s]),v=(0,U.useCallback)(async(e,t,r)=>{let a=E8(n);if(r?.plainTranslate??B0(e.element,`move`)){let n=await l(e,t,!0).save();return a.finish(n?.changed===!0)}let o=a.commit;if(o)return m2(async()=>{let n=E3(e.element);try{let c=_(e);return await bpn(await I8(e,t,Array.isArray(c)?c:await c,i.current,o,s(e),{...r,stamp:n}),async()=>{let n=a.drawKeepingUndone(()=>l(e,t,!1));a.recordDomResult(await n.save())}),a.finish()}catch(t){throw c(t,e,`drag`,`Move animated layer`),t}})},[n,i,s,c,_,l]),y=oPn({gsapCommitMutation:n,activeCompPath:r,previewIframeRef:i,makeFetchFallback:s,trackGsapInteractionFailure:c,stageElementPositionOffset:l,showToast:a}),b=(0,U.useCallback)(async(e,t,r,a=()=>void 0,o)=>{let d=E8(n);if(o?.plainTranslate??B0(e.element,`resize`)){let n=await u(e,t,r,a);return d.finish(n?.changed===!0)}return m2(async()=>{let n=E3(e.element),o;try{let t=_(e);o=Array.isArray(t)?t:await t}catch(t){throw a(),c(t,e,`resize`,`Resize animated layer`),t}let p=o.some(e=>e.propertyGroup===`scale`),m=sJ(e),h=m?I0(i.current,m,void 0,L0):!1;J3(`commit-route`,{next:t,offset:r??null,scaleRoute:p,animCount:o.length,animGroups:o.map(e=>`${e.propertyGroup}:${e.method}`)});let g=null,v=s6(e.element),y=null,b=async(t,a,c)=>{r&&!t&&await bpn(await I8(e,r,o,i.current,a,s(e),{stamp:n}),async()=>{let t=B0(e.element,`move`);g=d.drawKeepingUndone(()=>l(e,r,t,c))})};return await Upn({element:e.element,label:`Resize layer`,draw:d.drawKeepingUndone,settle:()=>{!r||p||!m||d.drawKeepingUndone(()=>{let t=x8(i.current,m)??{x:0,y:0},{newX:a,newY:o}=D3(e.element,r,t,n);J3(`sync-settle`,{gsapPos:t,offset:r,newX:a,newY:o}),VZ(e.element,a,o)})},persist:async(a,l)=>{if(d.commit){let f=a(d.commit);try{let a=await APn(e,t,o,i.current,f,s(e),r,d.drawKeepingUndone,n);if(l8(a),a.status===`element-size`){let n=await d.drawKeepingUndone(()=>u(e,t,void 0,void 0,l));d.recordDomResult(n)}else y=l;let c=a.status===`persisted`&&a.ownsDragOffset===!0;J3(`intercept-handled`,{scaleRoute:p,ownsDragOffset:c,willForwardOffset:!!(r&&!c)}),await b(c,f,l),hsn(e.element,c?`gsap-scale`:`gsap-size`);return}catch(t){throw c(t,e,`resize`,`Resize animated layer`),t}}throw Error(`Resize of a GSAP-owned box has no GSAP writer`)},afterBufferedCommitsSaved:async()=>{let t=await g?.save();if(d.recordDomResult(t),y){let t=await d.drawKeepingUndone(()=>Qsn(v,e,f,y));d.recordDomResult(t)}},restore:()=>{g?.rollback(),a()},skipPixelAssert:h}),d.finish()})},[u,f,l,n,i,s,c,_]),x=(0,U.useCallback)(async(e,t)=>{let r=E8(n);if(t.plain===void 0?B0(e.element,`rotate`):t.plain){let n=await d(e,t);return r.finish(n?.changed===!0)}let a=r.commit;if(a)return m2(async()=>{let n=E3(e.element);try{let o=await _(e);return l8(await Phn(e,t.angle,o,i.current,a,s(e),n)),r.finish()}catch(t){throw c(t,e,`rotation`,`Rotate animated layer`),t}})},[n,i,s,c,_,d]),{commitAnimatedProperties:S}=UPn({selectedGsapAnimations:t,gsapCommitMutation:n,addGsapAnimation:(e,t,n)=>p(e,t,n),convertToKeyframes:(e,t)=>m(e,t),previewIframeRef:i,bumpGsapCache:o}),C=(0,U.useCallback)(async(e,t)=>{try{await ecn(e,t,n,f,n=>S(e,t,n))}catch(t){throw c(t,e,`property`,`Edit animated property`),t}},[S,f,n,c]),w=(0,U.useCallback)((e,t,n)=>C(e,{[t]:n}),[C]),T=(0,U.useCallback)((t,n)=>{e&&h(e,t,n)},[e,h]),E=(0,U.useCallback)((t,n,r)=>{e&&g(e,t,n,r)},[e,g]),D=(0,U.useCallback)(async()=>{},[]),O=NNn(null),k=PNn(n??D,O,a),A=(0,U.useCallback)(async(t,n,r=e)=>{r&&await k(r,t,n)},[e,k]);return{getGsapAnimationsForSelection:_,handleGsapAwarePathOffsetCommit:v,handleGsapAwareGroupPathOffsetCommit:y,handleGsapAwareBoxSizeCommit:b,handleGsapAwareRotationCommit:x,commitAnimatedProperty:w,commitAnimatedProperties:C,handleSetArcPath:T,handleUpdateArcSegment:E,handleUnroll:(0,U.useCallback)(()=>{A({type:`unroll-timeline`},{label:`Unroll to literal tweens`,softReload:!0})},[A]),commitMutation:A}}function n9(e){return Math.round(e*1e3)/1e3}function GPn({projectId:e,selection:t,currentTime:n}){let r=encodeURIComponent(t.compositionPath||t.sourceFile||`index.html`),i=new URLSearchParams({t:String(n9(n)),format:`png`,output:`source`});return t.selector&&i.set(`selector`,t.selector),t.selectorIndex!=null&&i.set(`selectorIndex`,String(t.selectorIndex)),`/api/projects/${encodeURIComponent(e)}/thumbnail/${r}?${i.toString()}`}function KPn({projectId:e,selection:t,currentTime:n}){return{schemaVersion:1,projectId:e,compositionPath:t.compositionPath,sourceFile:t.sourceFile,currentTime:n9(n),target:{id:t.id,hfId:t.hfId,selector:t.selector,selectorIndex:t.selectorIndex},label:t.label,tagName:t.tagName,boundingBox:{x:n9(t.boundingBox.x),y:n9(t.boundingBox.y),width:n9(t.boundingBox.width),height:n9(t.boundingBox.height)},textContent:t.textContent,dataAttributes:{...t.dataAttributes},inlineStyles:{...t.inlineStyles},computedStyles:{...t.computedStyles},textFields:t.textFields.map(e=>({key:e.key,label:e.label,value:e.value,tagName:e.tagName,source:e.source})),capabilities:{...t.capabilities},thumbnailUrl:GPn({projectId:e,selection:t,currentTime:n})}}function qPn(e){e instanceof Error&&e.name===`AbortError`||(mG(`studio_selection_publish_failed`,{error_name:e instanceof Error?e.name:typeof e,error_message:(e instanceof Error?e.message:String(e)).slice(0,500)}),console.warn(`[Studio] Failed to update agent selection context`,e))}function JPn(e,t,n){return H(`/api/projects/${encodeURIComponent(e)}/selection`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({selection:t}),signal:n}).then(()=>void 0)}function YPn({projectId:e,domEditSelection:t,domEditSelectionRef:n,refreshKey:r,previewDocumentVersion:i,refreshDomEditSelectionFromPreview:a}){let o=(0,U.useRef)(r),s=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!e)return;let n=t?.element.isConnected?KPn({projectId:e,selection:t,currentTime:X.getState().currentTime}):null,r=new AbortController;return JPn(e,n,r.signal).catch(qPn),()=>r.abort()},[t,e]),(0,U.useEffect)(()=>{if(e)return()=>{JPn(e,null).catch(qPn)}},[e]),(0,U.useEffect)(()=>{if(o.current===r||(o.current=r,s.current=n.current?r:null,!e||!n.current))return;let t=new AbortController;return JPn(e,null,t.signal).catch(qPn),()=>t.abort()},[n,e,r]),(0,U.useEffect)(()=>{if(s.current===null)return;s.current=null;let e=n.current;e&&a(e)},[n,i,a])}function XPn({gsapCommitMutation:e,domEditSelectionRef:t}){let n=(0,U.useCallback)((n,r)=>{let i=t.current;if(!i||n.length===0)return;let a={label:n.length===1?`Update keyframe ease`:`Update segment ease`,softReload:!0},o=n.map(({animationId:e,tweenPercentage:t})=>({selection:i,mutation:{type:`update-keyframe`,animationId:e,percentage:t,properties:{},ease:r},options:a}));if(o.length===1){let t=o[0];t&&e(t.selection,t.mutation,t.options);return}let s=e.batch;if(s){s(o,a);return}for(let t of o)e(t.selection,t.mutation,t.options)},[e,t]);return{handleUpdateSegmentEase:n,handleUpdateKeyframeEase:(0,U.useCallback)((e,t,r)=>n([{animationId:e,tweenPercentage:t}],r),[n]),handleSetAllKeyframeEases:(0,U.useCallback)((n,r)=>{let i=t.current;i&&e(i,{type:`update-meta`,animationId:n,updates:{easeEach:r,resetKeyframeEases:!0}},{label:`Apply ease to all segments`,softReload:!0})},[e,t])}}function ZPn(e,t,n,r){let i=N8(t,{id:e.id??null,selector:e.selector??null},e.element);return{offset:Ehn(e,i,n,[],r),size:cPn(e,i,n),rotation:Nhn(e,i,n)}}var QPn=new WeakMap,$Pn=new WeakMap;function eFn(e,t){let n=$Pn.get(e);if(n?.animations===t.animations&&n.iframe===t.iframe&&n.group===t.group&&n.version===t.version)return n;let{animations:r,iframe:i,group:a}=t,o={...t,preflight:ZPn(e,r,i,a)};return $Pn.set(e,o),o}var tFn=e=>QPn.get(e)??e,nFn=[[`canApplyManualOffset`,`offset`],[`canApplyManualSize`,`size`],[`canApplyManualRotation`,`rotation`]];function rFn(e,t){let n=e?.[t];return n?n.status===`blocked`?ypn(n.reason,n.detail):null:``}function iFn(e,t){let n=tFn(e),r={...n.capabilities},i=[];for(let[e,n]of nFn){let a=rFn(t,n);!r[e]||a===null||(r[e]=!1,i.push(a))}if(i.length===0)return n;r.reasonIfDisabled=i.find(Boolean)||r.reasonIfDisabled,t||(r.commitCheckPending=!0);let a={...n,capabilities:r};return QPn.set(a,n),a}function aFn({projectId:e,enabled:t,selection:n,groupSelections:r,previewIframeRef:i,version:a}){let o=(0,U.useRef)(new Map),[s,c]=(0,U.useState)(0);return(0,U.useEffect)(()=>{if(!t||!e)return;let i=n?[n,...r]:r;for(let t of new Set(i.map(ZNn))){let n=Ihn(e,t),r=o.current.get(n);r?.version!==a&&(o.current.set(n,{version:a,animations:r?.animations??null}),R8(e,t).then(e=>{if(o.current.get(n)?.version===a){if(e){o.current.set(n,{version:a,animations:e.animations}),c(e=>e+1);return}r?.animations?o.current.set(n,r):o.current.delete(n)}}))}},[t,e,n,r,a]),(0,U.useMemo)(()=>{if(!t||!e)return{selection:n,groupSelections:r};let s=r.length>1,c=i.current,l=t=>{let n=ZNn(t),r=o.current.get(Ihn(e,n))?.animations;if(!r)return iFn(t,null);let i={animations:r,iframe:c,group:s,version:a},l=eFn(tFn(t),i);return l.narrowed??=iFn(t,l.preflight),l.narrowed};return e9t(()=>({selection:n&&l(n),groupSelections:r.map(l)}))},[t,e,n,r,s,i,a])}function oFn(e,t,n){return n?.expandGroup&&t.length>0?t:[e]}function sFn(e,t){let n=[];for(let r of e){let e=QQ(r,t),i=e?t.find(t=>(t.key??t.id)===e):void 0;if(!i)return null;n.push(i)}return n}function cFn(e){let[t,n]=(0,U.useState)(),r=e&&t?.host===e?t.live:e,i=(0,U.useRef)(r);return i.current=r,(0,U.useEffect)(()=>{if(e)return zen(e.ownerDocument,({retired:t,live:r})=>{t===i.current&&n({host:e,live:r})})},[e]),r}function lFn(e,t){let n=F3(e,{x:0,y:0}),r=F3(e,t);if(!n||!r)throw Error(`The preview has no measurable size.`);return{x:r.x-n.x,y:r.y-n.y}}function uFn(e,t){let{element:n}=e,r=n.getBoundingClientRect(),i=I3({key:e.id??e.selector??e.label,selection:e,element:n,rect:{left:r.left,top:r.top,width:r.width,height:r.height,editScaleX:t.x,editScaleY:t.y},gesture:`drag`});if(!i.ok)throw Error(i.reason);return i.member}async function dFn(e,t){let n=e.filter(({delta:e})=>e.x!==0||e.y!==0);if(n.length===0)return;let r=n.map(({selection:e})=>e);if(!r6(r)){let e=r.find(e=>!e.capabilities.canApplyManualOffset);throw Error(e?.capabilities.reasonIfDisabled??`${e?.label} can't be moved.`)}let i=n.map(({selection:e,delta:t})=>lFn(e.element.ownerDocument,t)),a=[];try{for(let e of r)a.push(uFn(e,lFn(e.element.ownerDocument,{x:1,y:1})))}catch(e){throw V3(a),e}let o=a.map((e,t)=>({selection:e.selection,next:B3(e,i[t].x,i[t].y),plainTranslate:e.plainTranslate}));try{await q0(a[0].element,()=>t(o))}catch(e){for(let e of a)J0(e.element,e.gestureToken)&&p3(e.element,e.initialPathOffset);throw e}finally{H3(a)}}function fFn({projectId:e,activeCompPath:t,compIdToSrc:n,captionEditMode:r,compositionLoading:i,previewIframeRef:a,timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:c,setTimelineSelectionSet:l,setRightCollapsed:u,setRightPanelTab:d,showToast:f,isRecordingRef:p,refreshPreviewDocumentVersion:m,queueDomEditSave:h,readProjectFile:g,writeProjectFile:_,updateEditingFileContent:v,editHistory:y,fileTree:b,importedFontAssetsRef:x,projectDir:S,projectIdRef:C,previewIframe:w,refreshKey:T,previewDocumentVersion:E,rightPanelTab:D,applyStudioManualEditsToPreviewRef:O,syncPreviewHotkeys:k,reloadPreview:A,openSourceForSelection:j,sdkSession:M,publishSdkSession:N,forceReloadSdkSession:P,handleTimelineElementsDelete:F,readOnlyPreview:I}){let L=!t||t===`index.html`,R=r&&!I,z=cFn(w),{domEditSelection:B,domEditGroupSelections:V,domEditHoverSelection:ee,activeGroupElement:te,domEditSelectionRef:H,domEditGroupSelectionsRef:ne,setActiveGroupElement:re,applyDomSelection:ie,clearDomSelection:ae,buildDomSelectionFromTarget:oe,resolveDomSelectionFromPreviewPoint:se,resolveAllDomSelectionsFromPreviewPoint:ce,updateDomEditHoverSelection:le,buildDomSelectionForTimelineElement:ue,handleTimelineElementSelect:de,refreshDomEditSelectionFromPreview:fe,refreshDomEditGroupSelectionsFromPreview:pe,applyMarqueeSelection:me}=zjn({projectId:e,activeCompPath:t,isMasterView:L,compIdToSrc:n,captionEditMode:R,previewIframeRef:a,timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:c,setTimelineSelectionSet:l,setRightCollapsed:u,setRightPanelTab:d,previewIframe:z,refreshKey:T,rightPanelTab:D}),{agentModalOpen:he,agentModalAnchorPoint:ge,copiedAgentPrompt:_e,agentPromptSelectionContext:ve,setAgentModalOpen:ye,setAgentPromptSelectionContext:be,setAgentModalAnchorPoint:xe,handleAskAgent:Se,handleAgentModalSubmit:Ce}=wjn({projectId:e,activeCompPath:t,projectDir:S,projectIdRef:C,showToast:f,domEditSelectionRef:H,domEditSelection:B});YPn({projectId:e,domEditSelection:B,domEditSelectionRef:H,refreshKey:T,previewDocumentVersion:E,refreshDomEditSelectionFromPreview:fe});let{version:we,bump:Te}=Bhn(),{commitMutation:Ee,setArcPath:De,updateArcSegment:Oe,...ke}=KNn({projectIdRef:C,activeCompPath:t,previewIframeRef:a,editHistory:y,reloadPreview:A,onCacheInvalidate:Te,onFileContentChanged:v,showToast:f,sdkSession:M,publishSdkSession:N,writeProjectFile:_,forceReloadSdkSession:P}),{resolveImportedFontAsset:Ae,handleDomStyleCommit:je,handleDomStyleCommitForSelection:Me,handleDomAttributeCommit:Ne,handleDomAttributeLiveCommit:Pe,handleDomAttributeQuietCommit:Fe,handleDomHtmlAttributeCommit:Ie,handleDomAttributesCommit:Le,handleDomAttributeBatchCommit:Re,handleDomTextCommit:ze,handleDomTextCommitForSelection:Be,handleDomRichTextCommit:Ve,handleDomTextFieldStyleCommit:He,handleDomAddTextField:Ue,handleDomRemoveTextField:We,stageElementPositionOffset:Ge,commitPositionPatchToHtml:Ke,handleDomBoxSizeCommit:qe,handleDomRotationCommit:Je,handleDomManualEditsReset:Ye,handleDomEditElementsDelete:Xe,handleDomZIndexReorderCommit:Ze}=eNn({activeCompPath:t,previewIframeRef:a,showToast:f,queueDomEditSave:h,writeProjectFile:_,editHistory:y,fileTree:b,importedFontAssetsRef:x,projectId:e,projectIdRef:C,reloadPreview:A,domEditSelection:B,applyDomSelection:ie,clearDomSelection:ae,refreshDomEditSelectionFromPreview:fe,buildDomSelectionFromTarget:oe,forceReloadSdkSession:P,readOnlyPreview:I,onTrySdkPersist:M?(e,n,r,i,a)=>(Lun(M,e.hfId,n,r,{targetPath:i,compositionPath:t}),Tdn(e,n,r,i,M,{editHistory:y,writeProjectFile:_,reloadPreview:A,compositionPath:t,readProjectFile:g,publishSession:N},a)):void 0,onTrySdkDelete:M?(e,n,r)=>zdn(e,n,r,M,{editHistory:y,writeProjectFile:_,reloadPreview:A,compositionPath:t,readProjectFile:g,publishSession:N}):void 0,onReorderShadow:M?e=>{let n,r=t?()=>n??=g(t):void 0;for(let t of e)k6(M,t,`reorderElements`,r)}:void 0}),{groupSelection:Qe,ungroupSelection:$e}=aNn({activeCompPath:t,showToast:f,writeProjectFile:_,editHistory:y,projectIdRef:C,reloadPreview:A,clearDomSelection:ae,forceReloadSdkSession:P,timelineElements:o}),et=(0,U.useCallback)(async(e,t)=>{if(p?.current){f(`Cannot edit timeline while recording`,`error`);return}let n=oFn(e,ne.current,t),r=sFn(n,o);if(r){await F(r);return}await Xe(n)},[ne,Xe,F,p,f,o]),tt=(0,U.useCallback)(()=>{let e=ne.current,t=H.current,n=e.length>0?e:t?[t]:[];if(n.length<2){f(`Select at least 2 elements to group`,`info`);return}if(n.some(e=>CG(e.element))){f(n.every(e=>CG(e.element))?`Audio clips group into a bus — use FX on the track header`:`Can't group audio clips with layout elements`,`info`);return}mG(`group`,{action:`create`,count:n.length}),Qe(n)},[ne,H,Qe,f]),nt=(0,U.useCallback)(()=>{let e=H.current;if(!e?.element.hasAttribute(`data-hf-group`)){f(`Select a group to ungroup`,`info`);return}mG(`group`,{action:`ungroup`}),re(null),$e(e)},[H,$e,re,f]),{onClickToSource:rt,selectedGsapAnimations:it,gsapMultipleTimelines:at,gsapUnsupportedTimelinePattern:ot,trackGsapInteractionFailure:st,makeFetchFallback:ct,handleGsapUpdateProperty:lt,handleGsapUpdateMeta:ut,handleGsapDeleteAnimation:dt,handleGsapDeleteAllForElement:ft,handleGsapAddAnimation:pt,handleGsapAddProperty:mt,handleGsapRemoveProperty:ht,handleGsapUpdateFromProperty:gt,handleGsapAddFromProperty:_t,handleGsapRemoveFromProperty:vt,handleGsapAddKeyframe:yt,handleGsapAddKeyframeBatch:bt,handleGsapRemoveKeyframe:xt,handleGsapMoveKeyframeToPlayhead:St,handleGsapMoveKeyframe:Ct,handleGsapResizeKeyframedTween:wt,handleGsapConvertToKeyframes:Tt,handleGsapRemoveAllKeyframes:Et,handleResetSelectedElementKeyframes:Dt}=nPn({projectId:e,activeCompPath:t,domEditSelection:B,domEditSelectionRef:H,domEditGroupSelectionsRef:ne,refreshDomEditGroupSelectionsFromPreview:pe,previewIframeRef:a,previewIframe:z,captionEditMode:R,refreshKey:T,gsapCacheVersion:we,bumpGsapCache:Te,showToast:f,refreshPreviewDocumentVersion:m,syncPreviewHotkeys:k,applyStudioManualEditsToPreviewRef:O,applyDomSelection:ie,buildDomSelectionFromTarget:oe,openSourceForSelection:j,...ke,handleDomManualEditsReset:Ye}),{handlePreviewCanvasMouseDown:Ot,handlePreviewCanvasPointerMove:kt,handlePreviewCanvasPointerLeave:At,handleBlockedDomMove:jt,handleDomManualDragStart:Mt}=Wjn({captionEditMode:R,compositionLoading:i,previewIframeRef:a,showToast:f,applyDomSelection:ie,resolveDomSelectionFromPreviewPoint:se,resolveAllDomSelectionsFromPreviewPoint:ce,updateDomEditHoverSelection:le,setActiveGroupElement:re,onClickToSource:rt}),{getGsapAnimationsForSelection:Nt,handleGsapAwarePathOffsetCommit:Pt,handleGsapAwareGroupPathOffsetCommit:Ft,handleGsapAwareBoxSizeCommit:It,handleGsapAwareRotationCommit:Lt,commitAnimatedProperty:Rt,commitAnimatedProperties:zt,handleSetArcPath:Bt,handleUpdateArcSegment:Vt,handleUnroll:Ht,commitMutation:Ut}=WPn({domEditSelection:B,selectedGsapAnimations:it,gsapCommitMutation:Ee,activeCompPath:t,previewIframeRef:a,showToast:f,bumpGsapCache:Te,makeFetchFallback:ct,trackGsapInteractionFailure:st,stageElementPositionOffset:Ge,handleDomBoxSizeCommit:qe,handleDomRotationCommit:Je,commitPositionPatchToHtml:Ke,addGsapAnimation:ke.addGsapAnimation,convertToKeyframes:ke.convertToKeyframes,setArcPath:De,updateArcSegment:Oe}),Wt=(0,U.useCallback)(e=>dFn(e,e=>Ft(e,{refusalToast:!1})),[Ft]),{handleUpdateSegmentEase:Gt,handleUpdateKeyframeEase:Kt,handleSetAllKeyframeEases:qt}=XPn({gsapCommitMutation:Ee,domEditSelectionRef:H}),Jt=aFn({projectId:e,enabled:Ee!==null,selection:B,groupSelections:V,previewIframeRef:a,version:we});return{domEditSelection:Jt.selection,domEditGroupSelections:Jt.groupSelections,domEditHoverSelection:ee,activeGroupElement:te,agentModalOpen:he,agentModalAnchorPoint:ge,copiedAgentPrompt:_e,agentPromptSelectionContext:ve,domEditSelectionRef:H,handleTimelineElementSelect:de,handlePreviewCanvasMouseDown:Ot,handlePreviewCanvasPointerMove:kt,handlePreviewCanvasPointerLeave:At,applyDomSelection:ie,clearDomSelection:ae,refreshDomEditSelectionFromPreview:fe,handleDomStyleCommit:je,handleDomStyleCommitForSelection:Me,handleDomAttributeCommit:Ne,handleDomAttributeLiveCommit:Pe,handleDomAttributeQuietCommit:Fe,handleDomHtmlAttributeCommit:Ie,handleDomAttributesCommit:Le,handleDomAttributeBatchCommit:Re,handleDomPathOffsetCommit:Pt,handleDomGroupPathOffsetCommit:Ft,handleDomGroupMoveBy:Wt,handleDomZIndexReorderCommit:Ze,handleDomBoxSizeCommit:It,handleDomRotationCommit:Lt,handleDomManualEditsReset:Ye,handleDomTextCommit:ze,handleDomTextCommitForSelection:Be,handleDomRichTextCommit:Ve,handleDomTextFieldStyleCommit:He,handleDomAddTextField:Ue,handleDomRemoveTextField:We,getGsapAnimationsForSelection:Nt,handleAskAgent:Se,handleAgentModalSubmit:Ce,handleBlockedDomMove:jt,handleDomManualDragStart:Mt,handleDomEditElementDelete:et,handleGroupSelection:tt,handleUngroupSelection:nt,setActiveGroupElement:re,buildDomSelectionFromTarget:oe,buildDomSelectionForTimelineElement:ue,updateDomEditHoverSelection:le,applyMarqueeSelection:me,resolveImportedFontAsset:Ae,setAgentModalOpen:ye,setAgentPromptSelectionContext:be,setAgentModalAnchorPoint:xe,selectedGsapAnimations:it,gsapMultipleTimelines:at,gsapUnsupportedTimelinePattern:ot,handleGsapUpdateProperty:lt,handleGsapUpdateMeta:ut,handleGsapDeleteAnimation:dt,handleGsapDeleteAllForElement:ft,handleGsapAddAnimation:pt,handleGsapAddProperty:mt,handleGsapRemoveProperty:ht,handleGsapUpdateFromProperty:gt,handleGsapAddFromProperty:_t,handleGsapRemoveFromProperty:vt,handleGsapAddKeyframe:yt,handleGsapAddKeyframeBatch:bt,handleGsapRemoveKeyframe:xt,handleGsapMoveKeyframeToPlayhead:St,handleGsapMoveKeyframe:Ct,handleGsapResizeKeyframedTween:wt,handleGsapConvertToKeyframes:Tt,handleGsapRemoveAllKeyframes:Et,handleResetSelectedElementKeyframes:Dt,handleUpdateKeyframeEase:Kt,handleUpdateSegmentEase:Gt,handleSetAllKeyframeEases:qt,commitAnimatedProperty:Rt,commitAnimatedProperties:zt,handleSetArcPath:Bt,handleUpdateArcSegment:Vt,handleUnroll:Ht,invalidateGsapCache:Te,previewIframeRef:a,commitMutation:Ut}}function pFn(e,t){return(e.length>0?e:t?[t]:[]).flatMap(e=>e.hfId?[e.hfId]:[])}function mFn(e,t,n){(0,U.useEffect)(()=>{e&&e.setSelection(pFn(n,t))},[e,t,n])}var hFn=new Set;function gFn(e){return hFn.add(e),()=>hFn.delete(e)}function _Fn(e){for(let t of hFn)try{t(e)}catch{}}var vFn=new Set([`absent_or_empty`,`absent`,`empty_file`]);function yFn(e,t,n){return mG(`sdk_session_unavailable`,{stage:`read`,reason:e.reason,...e.reason===`http_error`?{status:e.status,why:e.why}:{},...e.reason===`network`?{elapsed_ms:e.elapsedMs,hidden:e.hidden}:{},...e.reason===`invalid_json`?{content_type:e.contentType}:{},...vFn.has(e.reason)?{path_in_tree:n}:{}}),e.reason===`http_error`&&e.status===404?t:null}function bFn(e){return{ok:!1,reason:`network`,elapsedMs:Math.round(performance.now()-e),hidden:typeof document<`u`&&document.visibilityState===`hidden`}}async function xFn(e){let t=await e.json().catch(()=>null);return typeof t?.why==`string`?t.why:void 0}function SFn(e){return typeof e.content==`string`?e.content===``?e.missing===!0?{ok:!1,reason:`absent`}:e.missing===!1?{ok:!1,reason:`empty_file`}:{ok:!1,reason:`absent_or_empty`}:{ok:!0,content:e.content}:{ok:!1,reason:`missing_content`}}async function CFn(e,t){if(t.includes(`\0`)||t.includes(`..`))return{ok:!1,reason:`unsafe_path`};let n,r=performance.now();try{n=await H(`/api/projects/${encodeURIComponent(e)}/files/${encodeURIComponent(t)}?optional=1`)}catch{return bFn(r)}if(!n.ok){let e=await xFn(n);return{ok:!1,reason:`http_error`,status:n.status,...e?{why:e}:{}}}let i;try{i=await n.json()}catch{return{ok:!1,reason:`invalid_json`,contentType:n.headers.get(`content-type`)??``}}return SFn(i)}function wFn(e,t,n,r){return e?e.projectId===t&&e.path===n&&e.path===r:!1}function TFn(e,t,n,r,i){return e.generation===t&&e.projectId===n&&e.path===r&&e.reloadToken===i}function EFn(e,t,n,r){return e?e.session===n&&e.generation===t.generation&&e.reloadToken===r:!1}function r9(e){try{e.dispose()}catch(e){mG(`sdk_session_dispose_failed`,{error:e instanceof Error?e.message:String(e)})}}function DFn(e,t,n=[],r=!1,i){let[a,o]=(0,U.useState)(null),s=(0,U.useRef)(null),c=(0,U.useRef)(new WeakMap),l=(0,U.useRef)(0),u=(0,U.useRef)(e);u.current=e;let d=(0,U.useRef)(t);d.current=t;let[f,p]=(0,U.useState)(0),m=(0,U.useRef)(f);m.current=f;let[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(!1),y=(0,U.useRef)(new Set);(0,U.useEffect)(()=>{y.current.clear()},[e]);function b(e,t,a){let o=r?n.includes(a):null;if(g(yFn(e,t,o)),v(e.reason===`absent`),e.reason!==`absent`)return;let s=`${t}:${a}`;y.current.has(s)||(y.current.add(s),i?.(a))}(0,U.useEffect)(()=>gFn(e=>{(e===`.`||e===d.current)&&p(e=>e+1)}),[]),(0,U.useEffect)(()=>{let n=++l.current,r=!1,i=s.current;if(s.current=null,o(null),i&&r9(i.session),!e||!t)return g(null),v(!1),()=>{r=!0};let a={projectId:e,path:t,reloadToken:f,generation:n};return ix(e).then(n=>r||!n?null:CFn(e,t)).then(async n=>{if(!n||r)return;if(!n.ok){b(n,e,t);return}g(null),v(!1);let i=n.content,f=await Qj(i,{history:!1});if(r){r9(f);return}if(!TFn(a,l.current,u.current,d.current,m.current)){r9(f),mG(`sdk_session_superseded`,{});return}let p=s.current,h={...a,session:f};c.current.set(f,a),s.current=h,o(h),p&&p.session!==f&&r9(p.session)}).catch(e=>{!r&&l.current===n&&(o(null),mG(`sdk_session_unavailable`,{stage:`open`,error:e instanceof Error?e.message:String(e)}))}),()=>{r=!0;let e=s.current;e?.generation===n&&(s.current=null,r9(e.session))}},[e,t,f]);let x=(0,U.useCallback)(()=>p(e=>e+1),[]),S=(0,U.useCallback)(({candidate:e,expectedSession:t,targetPath:n})=>{let r=c.current.get(t),i=s.current;if(!wFn(r,u.current,d.current,n))return`rejected-inactive-target`;if(!EFn(i,r,t,m.current))return p(e=>e+1),`rejected-active-target`;let a={...i,session:e};return c.current.set(e,i),s.current=a,o(a),i.session!==e&&r9(i.session),`published`},[]);return{session:a?.projectId===e&&a.path===t&&a.reloadToken===f?a.session:null,publish:S,forceReload:x,unreachableProject:h,compositionMissing:_}}function OFn(e,t,n,r=[],i=!1,a){let o=DFn(e,t??n,r,i,a),s=t?o.session:null;return(0,U.useEffect)(()=>{ox.getState().setValues(null)},[e,t]),{sdkHandle:N7(o,e),editFlowSdkSession:s}}var kFn=`hyperframes-studio-external-conflicts`,AFn=1,i9=`file-conflicts`;function jFn(e,t){return`${e}\0${t}`}function MFn(){return new Promise((e,t)=>{if(!globalThis.indexedDB){t(Error(`IndexedDB is unavailable; conflict recovery snapshot was not saved`));return}let n=globalThis.indexedDB.open(kFn,AFn);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(i9)||n.result.createObjectStore(i9)},n.onerror=()=>t(n.error??Error(`Failed to open conflict storage`)),n.onsuccess=()=>e(n.result)})}function NFn(e,t){return MFn().then(n=>new Promise((r,i)=>{let a=n.transaction(i9,e),o=t(a.objectStore(i9)),s;o.onerror=()=>i(o.error??Error(`Conflict storage failed`)),o.onsuccess=()=>{s=o.result},a.oncomplete=()=>{n.close(),r(s)},a.onerror=()=>{n.close(),i(a.error??Error(`Conflict storage transaction failed`))},a.onabort=()=>{n.close(),i(a.error??Error(`Conflict storage transaction was aborted`))}}))}function PFn(){return{async get(e,t){return await NFn(`readonly`,n=>n.get(jFn(e,t)))??null},async set(e){await NFn(`readwrite`,t=>t.put(e,jFn(e.projectId,e.filePath)))},async delete(e,t){await NFn(`readwrite`,n=>n.delete(jFn(e,t)))}}}var a9=PFn();async function FFn(e,t){await a9.set({kind:`conflict`,projectId:e,filePath:t.filePath,externalVersion:t.currentVersion,externalContent:t.currentContent,studioContent:t.attemptedContent,createdAt:Date.now()})}async function IFn(e,t,n,r,i,a){await a9.set({kind:`failed`,projectId:e,filePath:t,externalVersion:r,externalContent:i,studioContent:n,failureMessage:a instanceof Error?a.message:String(a),createdAt:Date.now()})}async function LFn(e,t){return a9.get(e,t)}async function RFn(e,t){await a9.delete(e,t)}function zFn(){let e=globalThis.__HF_STUDIO_HOT_TEST_ADAPTER__;if(!e||typeof e!=`object`)return null;let t=e;return typeof t.on==`function`&&typeof t.off==`function`?t:null}var o9=e=>Z4(e,`content`),BFn=e=>Z4(e,`version`),VFn=e=>Z4(e,`writeToken`);function HFn(e){let t=e?.data;if(typeof t!=`string`)return e;try{return JSON.parse(t)}catch{return s2(`file-change`,{path:null,why:`unparseable payload`}),null}}function UFn(e,t){let n=new EventSource(`/api/events`);n.addEventListener(`file-change`,e);let r=!1;return n.addEventListener(`open`,()=>{r&&t(),r=!0}),()=>n.close()}function WFn(e,t){let n=BFn(t);if(n)return`${e}\0${n}`;let r=o9(t);return r==null?null:`${e}\0${r.length}\0${r}`}function GFn({projectId:e,activeCompPath:t,recoveryFilePath:n=t,pendingTimelineEditPathRef:r,drainPendingChanges:i,getPendingCandidate:a,discardPendingChanges:o,reloadPreview:s,reloadSdkSession:c,persistConflictSnapshot:l,persistFailureSnapshot:u,loadConflictSnapshot:d,deleteConflictSnapshot:f,overwriteConflict:p,readProjectFile:m,onUseExternalFile:h,resetSaveQueues:g,onAcceptedPersistedFileChange:_,refreshFileTree:v}){let[y,b]=(0,U.useState)(null),x=(0,U.useRef)(0),S=(0,U.useRef)(!0),C=(0,U.useRef)(null),w=(0,U.useRef)(null),T=(0,U.useRef)(Promise.resolve()),E=(0,U.useRef)(!1),D=(0,U.useRef)(null),O=(0,U.useCallback)(e=>{let t=w.current,n=e&&t?{...e,payload:t3(t.payload,e.payload)}:e;w.current=n,b(n)},[]);(0,U.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current+=1}),[]),(0,U.useEffect)(()=>{D.current=null},[e]),(0,U.useEffect)(()=>{x.current+=1,O(null),C.current=null},[e,t,O]),(0,U.useEffect)(()=>{if(!e||!n||!d)return;let t=++x.current,r=!1;return d(e,n).then(e=>{if(r||!e||!S.current||t!==x.current)return;let n={path:e.filePath,version:e.externalVersion,content:e.externalContent};if(e.kind===`failed`)O({status:`failed`,generation:t,path:e.filePath,error:Error(e.failureMessage),payload:n,studioContent:e.studioContent,recovered:!0});else{let r=new XY({filePath:e.filePath,currentVersion:e.externalVersion,currentContent:e.externalContent,attemptedContent:e.studioContent});O({status:`conflict`,generation:t,error:r,payload:n})}}).catch(()=>{}),()=>{r=!0}},[d,e,n,O]);let k=(0,U.useCallback)((e,t=!0)=>{let n=Q4(e)??`.`,r=$4(e);t&&_(n,e3(e)),s2(r?`reload`:`file-tree only`,{path:n,by:`external-change coordinator`}),r&&s(),c(n),v?.()},[_,s,c,v]),A=(0,U.useCallback)(async e=>{let t=T.current.catch(()=>void 0).then(e);T.current=t.then(()=>void 0,()=>void 0),await t},[]),j=(0,U.useCallback)(async t=>{let r=Q4(t);if(!r)return;let o=++x.current,s=a?.()?.path,c=await i();if(!(!S.current||o!==x.current)){if(c.status===`clean`){let n=w.current;if(n?.status===`failed`&&!n.recovered&&n.path===s&&f)try{await f(e,n.path)}catch(e){S.current&&o===x.current&&O({...n,generation:o,error:e,payload:t3(t,n.payload)});return}if(!S.current||o!==x.current)return;O(null);let r=n?.status===`failed`&&n.recovered;k(n&&!r?t3(n.payload,t):t);return}if(c.status===`failed`){let i=a?.(),s=i?.path??(r===`.`?n??r:r),l=i?.content??null,d=s===r?t:null,f=c.error;if(l!=null&&u)try{await A(()=>u(e,s,l,BFn(d),o9(d),c.error))}catch(e){f=Error(`Studio could not save the edit or its recovery snapshot: ${e instanceof Error?e.message:String(e)}`,{cause:c.error})}if(!S.current||o!==x.current)return;O({status:`failed`,generation:o,path:s,error:f,payload:t,studioContent:l,recovered:!1});return}try{await A(()=>l(e,c.error))}catch(e){if(!S.current||o!==x.current)return;O({status:`failed`,generation:o,path:c.error.filePath,error:e,payload:t,studioContent:c.error.attemptedContent,recovered:!1});return}!S.current||o!==x.current||O({status:`conflict`,generation:o,error:c.error,payload:t})}},[i,O,e,f,a,n,l,u,A,k]),M=(0,U.useRef)(j);M.current=j;let N=(0,U.useCallback)(async()=>{if(!E.current){E.current=!0;try{for(;S.current;){let e=D.current;if(!e)break;D.current=null,await M.current(e.payload)}}finally{E.current=!1}}},[]),P=(0,U.useCallback)(t=>{let n=Q4(t);if(!n||!e){s2(`file-change`,{path:null,why:n?`no project`:`no path in payload`});return}let i=Z4(t,`projectId`);if(i&&i!==e){s2(`suppressed`,{path:n,why:`other project`});return}r.current.delete(n);let a=o9(t),o=VFn(t);s2(`file-change`,{path:n,token:o??null,hasContent:a!=null});let s=WFn(n,t);if(s!=null&&s===C.current){s2(`suppressed`,{path:n,why:`duplicate event`});return}C.current=s;let c=GQt(o),l=a!=null&&ldn(n,a);if(c||l){_(n,e3(t)),s2(`suppressed`,{path:n,why:c?`own write token`:`own content echo`});return}let u=D.current?.payload;u!=null&&$4(u)&&!$4(t)||(D.current={payload:u==null?t:t3(u,t)}),N()},[e,r,N,_]),F=(0,U.useRef)(P);return F.current=P,(0,U.useEffect)(()=>{let e=e=>F.current(HFn(e)),t=zFn();return t?(t.on(`hf:file-change`,e),()=>t.off(`hf:file-change`,e)):UFn(e,()=>F.current({path:`.`}))},[]),{blocked:y,retry:(0,U.useCallback)(async()=>{let e=w.current;!e||e.status===`conflict`||e.recovered||(g?.(),C.current=null,P(e.payload))},[P,g]),useExternalFile:(0,U.useCallback)(async()=>{let t=w.current;if(!t||!e||t.generation!==x.current)return;let n=t.status===`conflict`?t.error.filePath:t.path,r=t.status===`conflict`&&t.error.currentContent!=null?t.error.currentContent:await m(n);t.generation===x.current&&(o(),g?.(),h?.(n,r),await f?.(e,n),O(null),k(t.payload))},[f,O,o,h,e,m,k,g]),keepStudioFile:(0,U.useCallback)(async()=>{let t=w.current;if(!t||!e||t.generation!==x.current)return;let n;if(t.status===`conflict`)n=t.error;else{if(!t.recovered||t.studioContent==null)return;try{let e=o9(t.payload)??await m(t.path);n=new XY({filePath:t.path,currentVersion:BFn(t.payload),currentContent:e,attemptedContent:t.studioContent})}catch(e){t.generation===x.current&&O({...t,error:e});return}}try{await p(n)}catch(e){t.generation===x.current&&O({status:`failed`,generation:t.generation,path:n.filePath,error:e,payload:t.payload,studioContent:n.attemptedContent,recovered:t.status===`failed`&&t.recovered});return}t.generation===x.current&&(o(),g?.(),await f?.(e,n.filePath),O(null),k(t3(t.payload,{path:n.filePath,affectsPreview:!0}),Q4(t.payload)!==n.filePath))},[f,O,o,p,e,m,k,g])}}function KFn({projectId:e,activeCompPath:t,masterCompPath:n,fileManager:r,previewPersistence:i,pendingTimelineEditPathRef:a,reloadPreview:o,onOutsideChange:s}){let{flushPendingSourceSave:c,discardPendingSourceSave:l}=r,{drainPendingDomEditSaves:u,resetDomEditSaveQueueBreaker:d}=i,f=X(e=>e.bumpThumbnailRevisions),p=(0,U.useCallback)((e,t)=>{s?.(),f(t)},[f,s]),m=(0,U.useCallback)(async()=>{let e=await c();return e.status===`clean`?u():e},[u,c]),h=(0,U.useCallback)(()=>{l(),d()},[l,d]);return GFn({projectId:e,activeCompPath:t,recoveryFilePath:r.editingFile?.path??t??n,pendingTimelineEditPathRef:a,drainPendingChanges:m,getPendingCandidate:r.getPendingSourceCandidate,discardPendingChanges:h,reloadPreview:o,reloadSdkSession:_Fn,persistConflictSnapshot:FFn,persistFailureSnapshot:IFn,loadConflictSnapshot:LFn,deleteConflictSnapshot:RFn,overwriteConflict:r.overwriteExternalConflict,readProjectFile:r.readProjectFile,onUseExternalFile:r.updateEditingFileContent,resetSaveQueues:d,onAcceptedPersistedFileChange:p,refreshFileTree:r.refreshFileTree})}function qFn(e){try{let t=e?.contentDocument;if(!t)return 0;let n=0;for(let e of t.body.querySelectorAll(`*`)){let t=parseInt(getComputedStyle(e).zIndex,10);Number.isFinite(t)&&t>n&&(n=t)}return n}catch{return 0}}function JFn(e,t){let n=new Set(t);if(!n.has(e))return e;let r=2;for(;n.has(`${e}_${r}`);)r++;return`${e}_${r}`}async function YFn({projectId:e,blockName:t,showToast:n}){let r=await H(M(e,`/registry/install`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({blockName:t})});if(!r.ok)return n((await r.json().catch(()=>({error:`Install failed`}))).error||`Failed to install block`),null;let{written:i,block:a}=await r.json(),o=i.find(e=>e.endsWith(`.html`))??i[0];return o?{block:a,compositionFile:o}:(n(`Installed but no composition file was written`),null)}async function XFn(e,t,n,r){e.type===`hyperframes:component`&&await jZ(r,t,async()=>{let e=await n(t),i=e.replace(/background:\s*(?:#(?:0a0a0a|000000|000|0a0805)|rgba?\([^)]*\))\s*;/g,`background: transparent;`);i!==e&&await r(t,i)})}function ZFn({block:e,placement:t,timelineElements:n,currentTime:r}){let i=e.type===`hyperframes:block`,{start:a=r,duration:o,track:s}=t??{},c=Number(XK(a)),l=`duration`in e?e.duration:void 0,u=o??l??n.reduce((e,t)=>Math.max(e,(t.start??0)+(t.duration??0)),10),d=Math.max(0,...n.map(e=>e.track))+1;return{duration:u,isBlock:i,start:c,track:s??(i?0:d)}}function QFn({id:e,compositionFile:t,start:n,duration:r,track:i,width:a,height:o,left:s,top:c,zIndex:l}){return[`<div`,` id="${e}"`,` data-hf-id="hf-${nG()}"`,` data-composition-id="${e}"`,` data-composition-src="${t}"`,` data-start="${XK(n)}"`,` data-duration="${XK(r)}"`,` data-track-index="${i}"`,` data-width="${a}"`,` data-height="${o}"`,` style="position: absolute; left: ${s}px; top: ${c}px; width: ${a}px; height: ${o}px; z-index: ${l}"`,`></div>`].join(`
362
+ ${e.slice(o)}`}function djn(e,t,n){let r=e?.contentDocument;if(!r?.body||r.getElementById(t))return!1;let i=r.createElement(Fe);return i.id=t,n&&i.setAttribute(`data-label`,n),r.body.appendChild(i),N1(r),!0}async function fjn({projectId:e,activeCompPath:t,elements:n,groupId:r,groupLabel:i,previewIframe:a,writeProjectFile:o,recordEdit:s,pendingTimelineEditPathRef:c}){if(n.length<2)throw Error(`Cannot group ${n.length} clip(s) \u2014 a group needs at least two`);if(!cjn.test(r))throw Error(`Invalid audio group id ${JSON.stringify(r)}`);let l=sjn(a,n,t);ojn(a,n,r,t);let u=djn(a,r,i);q7(a);let d={type:`attribute`,property:Re,value:r},f=t||`index.html`,p=$An(n,t),m={};for(let e of new Set([...p.keys(),f]))m[e]=t=>{let n=xQ(t,e,K$t(p.get(e)??[],d));return e===f&&(n=ujn(n,r,i)),n!==t&&c.current.add(e),n};try{let t=await PZ({projectId:e,label:i?`Group ${n.length} clips as ${i}`:`Group ${n.length} voice clips`,files:m,readFile:t=>lQ(e,t),writeFile:o,recordEdit:s});for(let e of n)X.getState().updateElement(e.key??e.id,{audioGroup:r});return t}catch(e){throw ojn(a,n,null,t,l),u&&a?.contentDocument?.getElementById(r)?.remove(),q7(a),e}}function pjn({projectIdRef:e,activeCompPath:t,showToast:n,writeProjectFile:r,recordEdit:i,previewIframeRef:a,pendingTimelineEditPathRef:o,isRecordingRef:s,checkEditable:c}){let l=X(e=>e.elements);return(0,U.useCallback)(async(u,d,f)=>{if(s?.current){n(`Cannot edit timeline while recording`,`error`);return}let p=e.current;if(!p)return;let m=new Set(u),h=l.filter(e=>{let t=Ct(e);return t!==null&&m.has(t)});h.length===m.size&&ajn(c,h);try{if(h.length!==m.size){let e=[...m].filter(e=>!h.some(t=>Ct(t)===e));throw Error(`Cannot group: no timeline clip for ${e.join(`, `)}`)}await fjn({groupLabel:f,projectId:p,activeCompPath:t,elements:h,groupId:d,previewIframe:a.current,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:o})}catch(e){throw console.error(`[Timeline] Failed to group voice clips`,e),n(e instanceof Error?e.message:`Failed to group voice clips`),e}},[t,l,a,r,i,o,s,n,e,c])}function J7(e,t){return e.sourceFile||t||`index.html`}function mjn(e,t){let n=e[0]?J7(e[0].element,t):null;return n&&e.every(e=>J7(e.element,t)===n)?n:null}function hjn(e,t){return e.map(e=>e.element.hfId?{hfId:e.element.hfId,timingUpdate:t(e)}:null)}function gjn(e){return e.playbackStart!=null||e.start!==e.element.start&&e.element.playbackStart!=null}function _jn({activeCompPath:e,editQueueRef:t,forceReloadSdkSession:n,invalidateGsapCache:r,isRecordingRef:i,pendingTimelineEditPathRef:a,previewIframeRef:o,projectIdRef:s,recordEdit:c,reloadPreview:l,sdkSession:u,publishSdkSession:d,showToast:f,writeProjectFile:p}){let m=(0,U.useCallback)((e,n)=>{if(i?.current)return f(`Cannot edit timeline while recording`,`error`),Promise.reject(Error(`${e}: blocked while recording`));let r=s.current;if(!r)return Promise.reject(Error(`${e}: no active project`));let a=t.current.then(()=>n(r));return t.current=a.then(()=>void 0,t=>{console.error(`[Timeline] Failed to persist: ${e}`,t)}),a},[t,i,s,f]),h=(0,U.useCallback)(async(t,r,i,o,s)=>{await q$t({projectId:t,activeCompPath:e,label:r,changes:i,writeProjectFile:p,recordEdit:c,pendingTimelineEditPathRef:a,coalesceKey:o,coalesceMs:s}),n?.()},[e,n,a,c,p]),g=(0,U.useCallback)(async t=>{let n=mjn(t.changes,e);if(!(!t.needsExtension&&n!==null&&t.eligible&&t.sdkChanges.every(e=>e!==null)))return null;let r=await Ddn(t.sdkChanges.filter(e=>e!==null),n,u,{editHistory:{recordEdit:c},writeProjectFile:p,reloadPreview:l,compositionPath:e,readProjectFile:e=>lQ(s.current??``,e),publishSession:d},{label:t.label,coalesceKey:t.coalesceKey,coalesceMs:t.coalesceMs,skipRefresh:!0});return F6(r)?{sdkGsap:hQ(r)}:null},[e,s,d,c,l,u,p]);return{handleTimelineGroupMove:(0,U.useCallback)((t,n)=>{if(t.length===0)return Promise.resolve();for(let n of t){let t=[[`data-start`,XK(LK(n.element,n.start))]];n.track!=null&&t.push([`data-track-index`,XK(n.track)]),yQ(o.current,n.element,t,e)}let i=t.every(e=>e.start===e.element.start),a=Math.max(...t.map(e=>e.start+e.element.duration)),s=dQ(o.current),u=gQ(a);uQ(o.current);let{coalesceKey:d,coalesceMs:_}=mQ(`timeline-group-move`,n),v=n?.label??`Move timeline clips`;return m(v,async a=>{await n?.beforeTiming;let s=await g({changes:t,sdkChanges:hjn(t,e=>({start:LK(e.element,e.start)})),eligible:t.every(e=>e.track==null&&e.audioGroup===void 0),needsExtension:u,label:v,coalesceKey:d,coalesceMs:_});if(s||await h(a,v,t.map(e=>({element:e.element,buildPatches:(t,n)=>B$t(t,n,LK(e.element,e.start),e.element.duration,e.track,e.audioGroup)})),d,_),!i)try{await P$t({projectId:a,iframe:o.current,reloadPreview:l,label:v,errorLabel:`Failed to shift GSAP positions`,coalesceKey:d,recordEdit:c,writeProjectFile:p,activeCompPath:e,changes:t,sdkGsap:s?.sdkGsap,resolveChangePath:t=>J7(t,e),mutationFor:e=>k$t(e.element.domId,e.start-e.element.start)})}finally{r?.()}}).catch(e=>{throw s(),n?.suppressFailureToast?console.error(`[Timeline] group move failed to persist`,e):f(QY(e),`error`),e})},[e,m,h,o,c,l,g,f,r,p]),handleTimelineGroupResize:(0,U.useCallback)((t,n)=>{if(t.length===0)return Promise.resolve();for(let n of t){let t=[[`data-start`,XK(LK(n.element,n.start))],[`data-duration`,XK(n.duration)]];if(n.playbackStart!=null){let e=kt(n.element);t.push([e,ZK(n.playbackStart)])}yQ(o.current,n.element,t,e)}let i=Math.max(...t.map(e=>e.start+e.duration)),a=dQ(o.current),s=gQ(i);uQ(o.current);let{coalesceKey:u,coalesceMs:d}=mQ(`timeline-group-resize`,n);return m(`Resize timeline clips`,async i=>{await n?.beforeTiming;let a=await g({changes:t,sdkChanges:hjn(t,e=>({start:LK(e.element,e.start),duration:e.duration})),eligible:t.every(e=>!gjn(e)),needsExtension:s,label:`Resize timeline clips`,coalesceKey:u,coalesceMs:d});a||await h(i,`Resize timeline clips`,t.map(e=>({element:e.element,buildPatches:(t,n)=>U$t(t,n,e.element,{start:e.start,duration:e.duration,playbackStart:e.playbackStart})})),u,d);try{await P$t({projectId:i,iframe:o.current,reloadPreview:l,label:`Resize timeline clips`,errorLabel:`Failed to scale GSAP positions`,coalesceKey:u,recordEdit:c,writeProjectFile:p,activeCompPath:e,changes:t,sdkGsap:a?.sdkGsap,resolveChangePath:t=>J7(t,e),mutationFor:e=>A$t(e.element.domId,RK(e.element,e.element.start),e.element.duration,RK(e.element,e.start),e.duration)})}finally{r?.()}}).catch(e=>{throw a(),f(QY(e),`error`),e})},[e,m,h,o,c,l,g,f,r,p])}}function vjn({activeCompPath:e,timelineElements:t,showToast:n,writeProjectFile:r,recordEdit:i,reloadPreview:a,previewIframeRef:o,pendingTimelineEditPathRef:s,isRecordingRef:c,sdkSession:l,publishSdkSession:u,forceReloadSdkSession:d,invalidateGsapCache:f,handleDomZIndexReorderCommitRef:p,editQueueRef:m,projectIdRef:h}){let g=(0,U.useCallback)((t,a,o,l)=>{if(c?.current)return n(`Cannot edit timeline while recording`,`error`),Promise.resolve();let u=h.current;if(!u)return Promise.resolve();let f=m.current.then(()=>G$t({projectId:u,element:t,activeCompPath:e,label:a,buildPatches:o,writeProjectFile:r,recordEdit:i,pendingTimelineEditPathRef:s,...l})).then(()=>{d?.()});return m.current=f.catch(e=>{console.error(`[Timeline] Failed to persist: ${a}`,e)}),f},[e,i,r,s,n,c,d,m,h]);return{handleTimelineElementMove:(0,U.useCallback)((s,c)=>{let d=()=>{let d=s.sourceFile||e||`index.html`,m=c.start!==s.start,_=c.track!==s.track,v=LK(s,c.start);if(m||_){let t=[];m&&t.push([`data-start`,XK(v)]),_&&t.push([`data-track-index`,XK(c.track)]),yQ(o.current,s,t,e)}let y=L$t({element:s,stackingReorder:c.stackingReorder,timelineElements:t,iframe:o.current,activeCompPath:e,commit:p?.current});if(!m&&!_)return y;let b=dQ(o.current),x=gQ(c.start+s.duration);uQ(o.current);let S=(e,t)=>{let n=_?c.track:void 0;return H$t(e,t,v,s.duration,n)},C=mQ(`timeline-move`),w=e=>N$t({iframe:o.current,reloadPreview:a,projectId:h.current,targetPath:d,domId:s.domId,label:`Move timeline clip`,coalesceKey:C.coalesceKey,recordEdit:i,writeProjectFile:r,edit:{kind:`shift`,delta:c.start-s.start},sdkGsap:e}).finally(()=>f?.()),T=()=>g(s,`Move timeline clip`,S,C).then(()=>w());return y.then(()=>l&&s.hfId&&!s.link&&!x&&!_?Edn(s.hfId,d,{start:v},l,{editHistory:{recordEdit:i},writeProjectFile:r,reloadPreview:a,compositionPath:e,readProjectFile:e=>lQ(h.current??``,e),publishSession:u},{label:`Move timeline clip`,...C,skipRefresh:!0}).then(e=>F6(e)?w(hQ(e)):T()):T()).catch(e=>{throw b(),n(QY(e),`error`),e})};return c.stackingReorder?KY(d):d()},[o,g,e,l,u,i,r,a,t,p,n,f,h]),handleTimelineElementResize:(0,U.useCallback)((t,s)=>{let c=LK(t,s.start),d=[[`data-start`,XK(c)],[`data-duration`,XK(s.duration)]];if(s.playbackStart!=null){let e=kt(t);d.push([e,ZK(s.playbackStart)])}yQ(o.current,t,d,e);let p=dQ(o.current),m=gQ(s.start+s.duration);uQ(o.current);let _=t.sourceFile||e||`index.html`,v=(e,n)=>W$t(e,n,t,s),y=s.playbackStart!=null||s.start!==t.start&&t.playbackStart!=null,b=mQ(`timeline-resize`),x=e=>N$t({iframe:o.current,reloadPreview:a,projectId:h.current,targetPath:_,domId:t.domId,label:`Resize timeline clip`,coalesceKey:b.coalesceKey,recordEdit:i,writeProjectFile:r,edit:{kind:`scale`,from:{start:RK(t,t.start),duration:t.duration},to:{start:RK(t,s.start),duration:s.duration}},sdkGsap:e}).finally(()=>f?.()),S=()=>g(t,`Resize timeline clip`,v,b).then(()=>x());return(l&&t.hfId&&!t.link&&!y&&!m?Edn(t.hfId,_,{start:c,duration:s.duration},l,{editHistory:{recordEdit:i},writeProjectFile:r,reloadPreview:a,compositionPath:e,readProjectFile:e=>lQ(h.current??``,e),publishSession:u},{label:`Resize timeline clip`,...b,skipRefresh:!0}).then(e=>F6(e)?x(hQ(e)):S()):S()).catch(e=>{throw p(),n(QY(e),`error`),e})},[o,g,e,l,u,i,r,a,n,f,h])}}var yjn=1500;function bjn(e){let t=(0,U.useRef)(0);return(0,U.useCallback)(n=>{let r=Date.now();r-t.current<yjn||(t.current=r,e(`This clip can't be moved or resized from the timeline yet.`,`info`))},[e])}function xjn({projectId:e,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,observeProjectFileVersion:a,recordEdit:o,reloadPreview:s,previewIframeRef:c,pendingTimelineEditPathRef:l,uploadProjectFiles:u,isRecordingRef:d,sdkSession:f,publishSdkSession:p,forceReloadSdkSession:m,invalidateGsapCache:h,handleDomZIndexReorderCommitRef:g,canEdit:_}){let v=(0,U.useRef)(e);v.current=e;let y=(0,U.useRef)(Promise.resolve()),b=XAn(),x=hAn(_,r),S=VAn(_,r),C=_jn({activeCompPath:t,editQueueRef:y,forceReloadSdkSession:m,invalidateGsapCache:h,isRecordingRef:d,pendingTimelineEditPathRef:l,previewIframeRef:c,projectIdRef:v,recordEdit:o,reloadPreview:s,sdkSession:f,publishSdkSession:p,showToast:r,writeProjectFile:i}),{handleTimelineElementMove:w,handleTimelineElementResize:T}=vjn({activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,sdkSession:f,publishSdkSession:p,forceReloadSdkSession:m,invalidateGsapCache:h,handleDomZIndexReorderCommitRef:g,editQueueRef:y,projectIdRef:v}),E=rjn({projectIdRef:v,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,forceReloadSdkSession:m}),D=ijn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,forceReloadSdkSession:m}),O=pjn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d,checkEditable:x}),k=PAn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d}),A=LAn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d}),j=OAn({projectIdRef:v,activeCompPath:t,showToast:r,writeProjectFile:i,recordEdit:o,previewIframeRef:c,pendingTimelineEditPathRef:l,isRecordingRef:d}),{handleTimelineElementsDelete:M}=BAn({projectIdRef:v,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,isRecordingRef:d,forceReloadSdkSession:m,previewIframeRef:c,handleTimelineGroupMove:C.handleTimelineGroupMove}),{handleTimelineAssetDrop:N,handleTimelineFileDrop:P,handleTimelineCompositionDrop:F}=dAn({projectIdRef:v,activeCompPath:t,timelineElements:n,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,uploadProjectFiles:u,isRecordingRef:d,forceReloadSdkSession:m,observeProjectFileVersion:a,checkEditable:x}),I=YAn({projectIdRef:v,activeCompPath:t,editQueueRef:y,pendingTimelineEditPathRef:l,isRecordingRef:d,showToast:r,writeProjectFile:i,recordEdit:o,reloadPreview:s,forceReloadSdkSession:m,handleTimelineElementsDelete:M}),L=bjn(r),{handleRazorSplit:R,handleRazorSplitAll:z,handleFreezeFrame:B}=nAn({projectId:e,activeCompPath:t,showToast:r,writeProjectFile:i,observeProjectFileVersion:a,recordEdit:o,reloadPreview:s,isRecordingRef:d,forceReloadSdkSession:m}),V=e=>({status:`refused`,reason:e}),ee=e=>{let t=X.getState(),n=t.elements.filter(t=>t.audioGroup===e),r=t.domClipChildren.filter(t=>t.audioGroup===e).map(e=>({id:e.id,domId:e.id,tag:`div`,start:0,duration:0,track:-1}));return[...n,...r]},te=N7({...j,setQuiet:b(S(ee,j.setQuiet,(e,t,n)=>(j.revertLive(t,n),V(e))))},e),H=N7({...k,setMany:b(S(e=>e.map(e=>e.element),A)),setQuiet:b(S(e=>[e],k.setQuiet,(e,t,n)=>(k.revertLive(t,n),V(e))))},e),ne=b(S(e=>K7([e]),R));return N7({handleTimelineElementMove:b(S(e=>[e],w)),handleTimelineElementResize:b(S(e=>[e],T)),handleToggleTrackHidden:b(S(e=>n.filter(t=>t.track===e),E)),handleToggleElementHidden:b(S(e=>{let t=new Set(Array.isArray(e)?e:[e]);return n.filter(e=>t.has(e.key??e.id))},D)),handleAutoGroupCarveSources:b(O),setAudioGroupAttribute:te,setElementFxAttribute:H,handleTimelineElementDelete:b(S(e=>K7([e]),I.handleLinkedElementDelete)),handleTimelineElementsDelete:b(S(K7,I.handleLinkedElementsDelete)),handleTimelineElementDeleteOnly:b(S(e=>[e],I.handleDeleteElementOnly)),handleLinkEdit:b(S(qAn,I.handleLinkEdit)),handleTimelineElementSplit:ne,handleRazorSplit:ne,handleFreezeFrame:b(S(e=>[e],B)),handleRazorSplitAll:b(S(e=>w1t(X.getState().elements,e),z)),handleTimelineAssetDrop:b(N),handleTimelineFileDrop:b(P),handleTimelineCompositionDrop:b(F),handleBlockedTimelineEdit:L,handleTimelineGroupMove:b(S(e=>e.map(e=>e.element),C.handleTimelineGroupMove)),handleTimelineGroupResize:b(S(e=>e.map(e=>e.element),C.handleTimelineGroupResize)),restoreLiveLanes:e=>{k.restoreLive(e),j.restoreLive(e)}},e)}function Sjn(e,t,n,r){return r.handleTimelineGroupMove(e.map(({element:e,updates:t})=>({element:e,start:t.start,audioGroup:t.audioGroup,track:n===`timing`?void 0:t.track})),{coalesceKey:t})}function Cjn(e){return(0,U.useCallback)(async(t,n,r=`timing`)=>{await Sjn(t,n,r,{handleTimelineGroupMove:e})},[e])}function wjn({activeCompPath:e,projectDir:t,projectIdRef:n,showToast:r,domEditSelectionRef:i,domEditSelection:a}){let[o,s]=(0,U.useState)(),[c,l]=(0,U.useState)(),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(!1),g=(0,U.useRef)(null),_=(0,U.useCallback)(async t=>{let r=n.current;if(!r)return;let a=t.sourceFile||e||`index.html`;try{let e=await H(M(r,`/files/${encodeURIComponent(a)}`));if(!e.ok)return;let n=(await e.json()).content,o=typeof n==`string`?kZ(n,t):void 0;s(e=>i.current===t?o:e)}catch{}},[e,i,n]),v=(0,U.useCallback)(()=>{a&&(s(void 0),l(void 0),d(null),_(a),h(!0))},[a,_]),y=(0,U.useCallback)(async n=>{if(!a)return;let i=a.sourceFile||e||`index.html`,s=o??vQt(a.element);if(!await U$(B6t({selection:a,currentTime:X.getState().currentTime,timeline:jfn(X.getState().elements),tagSnippet:s,selectionContext:c,userInstruction:n,sourceFilePath:q0t(t,i)}))){r(`Could not copy prompt to clipboard.`,`error`);return}h(!1),l(void 0),d(null),g.current&&clearTimeout(g.current),p(!0),g.current=setTimeout(()=>p(!1),1600)},[e,c,o,a,t,r]);return(0,U.useEffect)(()=>{s(void 0),l(void 0),d(null),p(!1)},[a]),(0,U.useEffect)(()=>()=>{g.current&&clearTimeout(g.current)},[]),{agentModalOpen:m,agentModalAnchorPoint:u,copiedAgentPrompt:f,agentPromptSelectionContext:c,setAgentModalOpen:h,setAgentPromptSelectionContext:l,setAgentModalAnchorPoint:d,preloadAgentPromptSnippet:_,handleAskAgent:v,handleAgentModalSubmit:y}}function Y7(e,t){return e===t?!0:!e||!t?!1:sn(e)===sn(t)}function Tjn(e,t){return rpn(e,t)}function X7(e,t){return t?e.some(e=>Y7(e,t)):!1}function Ejn(e,t){return X7(e,t)?e.filter(e=>!Y7(e,t)):[...e,t]}function Djn(e,t){let n=!1,r=e.map(e=>Y7(e,t)?(n=!0,t):e);return n?r:[...e,t]}function Z7(e,t){return!t||X7(e,t)?e:[t,...e]}function Ojn(e){let t=Number(e);return Number.isFinite(t)&&t>=0?t:0}function kjn(e){let t={idle:0,loading:0,ready:0,fallback:0,error:0};for(let n of e.querySelectorAll(`[data-timeline-poster-state]`)){let e=n.dataset.timelinePosterState;e&&Object.hasOwn(t,e)&&(t[e]+=1)}return Object.freeze(t)}function Ajn(e){let t=new Map;for(let n of e.querySelectorAll(`[data-clip="true"]`)){let e=n.closest(`[data-timeline-row]`);e&&t.set(e,(t.get(e)??0)+1)}return Math.max(0,...t.values())}function jjn(e,t,n){let r=0;for(let i of e.querySelectorAll(t))r+=Ojn(i.dataset[n]);return r}function Mjn(e=document){let t=e.querySelectorAll(`[aria-label="Timeline track view"]`),n=0;for(let e of t)n+=e.querySelectorAll(`*`).length;return Object.freeze({timelineRoots:t.length,mountedRows:e.querySelectorAll(`[data-timeline-row]`).length,mountedClipRoots:e.querySelectorAll(`[data-clip="true"]`).length,maxMountedClipRootsInOneRow:Ajn(e),mountedTimeGridCells:e.querySelectorAll(`[data-timeline-grid-cell]`).length,mountedTimelineDescendants:n,schedulerQueued:jjn(e,`[data-timeline-scheduler-queued]`,`timelineSchedulerQueued`),schedulerActive:jjn(e,`[data-timeline-scheduler-active]`,`timelineSchedulerActive`),cacheBytes:jjn(e,`[data-timeline-cache-bytes]`,`timelineCacheBytes`),posterStates:kjn(e)})}function Njn(){try{return{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_BUILD_ID:`v12.5.5`,VITE_HYPERFRAMES_NO_TELEMETRY:`1`}}catch{return}}var Pjn=Njn(),Fjn=Pjn?.DEV?`development`:`production`,Ijn=Pjn?.DEV===!0||Pjn?.MODE===`development`;function Ljn({previewIframeRef:e,buildDomSelectionFromTarget:t,applyDomSelection:n}){(0,U.useEffect)(()=>{if(!(!Ijn||typeof window>`u`))return window.__studioTest={runtimeMode:Fjn,selectByDomId:async r=>{let i=e.current?.contentDocument?.getElementById(r)??null;if(!i)return!1;let a=await t(i);return a?(n(a,{revealPanel:!0}),!0):!1},loadTimelinePerformanceFixture:e=>{let t=stn(e);return etn(!0),X.setState({...tx(),currentTime:0,duration:t.summary.duration,timelineReady:!0,loopEnabled:!1,zoomMode:`manual`,manualZoomPercent:2e3,elements:t.elements,selectedElementId:null,selectedElementIds:new Set,selectedKeyframes:new Set,keyframeCache:t.keyframeCache,gsapAnimations:t.gsapAnimations,expandedClipIds:t.expandedClipIds}),t.summary},resetTimelinePerformanceFixture:()=>{X.getState().reset()},readTimelinePerformanceDiagnostics:()=>Mjn(),timelineViewportBudgets:iK},()=>{delete window.__studioTest}},[n,t,e])}function Rjn(e,t,n,r=!1){let{timelineElements:i,getTimelineSelectionSet:a,setSelectedTimelineElementId:o,setTimelineSelectionSet:s}=e;if(!n){s(new Set),o(null);return}let c=e=>QQ(e,i)??s2t(e.element,i,e.sourceFile||`index.html`),l=t.map(c).filter(e=>!!e),u=c(n),d=new Set(l);u&&d.add(u);let f=u??l[0]??null;if(K4(`announce`,{group:t.length,published:d.size,anchor:u,anchorPublished:u!=null&&d.has(u)}),!f){n.tagName.toLowerCase()===`hf-audio-group`&&(s(new Set),o(null));return}(r||t.length>1||!a().has(f))&&s(d),o(f,{preserveSet:!0})}function zjn({projectId:e,activeCompPath:t,isMasterView:n,compIdToSrc:r,captionEditMode:i,previewIframeRef:a,timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:l,setTimelineSelectionSet:u,setRightCollapsed:d,setRightPanelTab:f,previewIframe:p,refreshKey:m,rightPanelTab:h}){let[g,_]=(0,U.useState)(null),[v,y]=(0,U.useState)([]),[b,x]=(0,U.useState)(null),[S,C]=(0,U.useState)(null),w=(0,U.useRef)(h);w.current=h;let T=(0,U.useRef)(g),E=(0,U.useRef)(v),D=(0,U.useRef)(b),O=(0,U.useRef)(S),k=(0,U.useRef)({activeCompPath:t,projectId:e}),A=(0,U.useRef)(0);T.current=g,E.current=v,D.current=b,O.current=S;let j=(0,U.useCallback)((e,t,n)=>Rjn({timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:l,setTimelineSelectionSet:u},e,t,n),[s,l,u,o]),M=(0,U.useCallback)((e,t)=>{if(!e){K4(`clear`,{hadGroup:E.current.length}),T.current=null,E.current=[],_(null),y([]),t?.announce!==!1&&j([],null);return}let n=!!t?.additive,r=T.current,i=E.current,a=!n&&!t?.preserveGroup&&i.length===1&&Y7(r,e)&&Y7(i[0],e);if(t?.preserveGroup&&r!==null&&(i.length===0||i.includes(r))&&Tjn(r,e))return;if(a){t?.revealPanel!==!1&&(d(!1),w.current!==`variables`&&f(`design`));return}let o=n?Z7(i,r):i,s=X7(o,e),c=t?.preserveGroup?Djn(o,e):n?Ejn(o,e):[e],l=t?.preserveGroup?e:n&&s?Y7(r,e)?c[0]??null:X7(c,r)?r:c[0]??null:e;K4(`apply`,{additive:n,target:e.selector??e.id??null,wasInGroup:s,prevGroup:i.length,nextGroup:c.length}),T.current=l,E.current=c,_(l),y(c);let u=O.current;if(u&&l&&!u.contains(l.element)&&(O.current=null,C(null)),l){t?.revealPanel!==!1&&(d(!1),w.current!==`variables`&&f(`design`)),j(c,l,n);return}j([],null)},[j,d,f]),N=(0,U.useCallback)(()=>{M(null,{revealPanel:!1})},[M]),P=(0,U.useCallback)(e=>{O.current!==e&&(O.current=e,C(e),M(null,{revealPanel:!1}))},[M]),F=(0,U.useCallback)((r,i)=>c(r,{activeCompositionPath:t,isMasterView:n,preferClipAncestor:i?.preferClipAncestor,skipSourceProbe:i?.skipSourceProbe,exactTarget:i?.exactTarget,previous:i?.previous,activeGroupElement:i&&`activeGroupElement`in i?i.activeGroupElement:O.current,projectId:e}),[t,n,e]),I=(0,U.useCallback)(async(e,n,r)=>{let o=a.current;if(!o||i)return null;try{o.contentDocument&&a3(o.contentDocument)}catch{}let s=v4(o,e,n,t);return s?F(s,r&&`activeGroupElement`in r?{preferClipAncestor:r.preferClipAncestor,skipSourceProbe:r.skipSourceProbe,activeGroupElement:r.activeGroupElement}:{preferClipAncestor:r?.preferClipAncestor,skipSourceProbe:r?.skipSourceProbe}):null},[t,F,i,a]),L=(0,U.useCallback)(async(e,n)=>{let r=a.current;if(!r||i)return[];try{r.contentDocument&&a3(r.contentDocument)}catch{}let o=$rn(r,e,n,t),s=[];for(let e of o){let t=await F(e,{skipSourceProbe:!0});t&&s.push(t)}return s},[t,F,i,a]),R=(0,U.useCallback)(e=>{Y7(D.current,e)||(D.current=e,x(e))},[]),z=(0,U.useCallback)(async e=>{let i=a.current,o=null;try{o=i?.contentDocument??null}catch{return null}if(!o)return null;a3(o);let s=en(o,e,{activeCompositionPath:t,compIdToSrc:r,isMasterView:n});return s?F(s,{preferClipAncestor:!1}):null},[t,F,r,n,a]),B=(0,U.useCallback)(async e=>{let t=++A.current;if(!e){M(null,{revealPanel:!1});return}let n=await z(e);if(t===A.current){if(n){M(n);return}M(null,{revealPanel:!1,announce:!1})}},[M,z]),V=(0,U.useRef)(async()=>{}),ee=(0,U.useCallback)(async e=>{let n=a.current,r=null;try{r=n?.contentDocument??null}catch{return}if(!r)return;let i=He(r,e,t);if(!i){let t=E.current;if(K4(`refresh-lost`,{target:e.selector??e.id??null,group:t.length}),t.length>1){await V.current(t);return}M(null,{revealPanel:!1});return}let o=await F(i,{previous:e});o&&M(o,{revealPanel:!1,preserveGroup:!0})},[t,M,F,a]),te=(0,U.useCallback)(async e=>{let n=a.current,r=null;try{r=n?.contentDocument??null}catch{return}if(!r)return;let i=[];for(let n of e){let e=He(r,n,t);if(!e)continue;let a=await F(e,{previous:n});a&&i.push(a)}if(i.length===0)return;let o=T.current,s=i.find(e=>Y7(e,o))??i[0]??null;T.current=s,E.current=i,_(s),y(i),j(i,s)},[t,j,F,a]);return(0,U.useEffect)(()=>{V.current=te},[te]),(0,U.useEffect)(()=>{R(null)},[t,e,p,m,R]),(0,U.useEffect)(()=>{let n=k.current;(n.activeCompPath!==t||n.projectId!==e)&&(k.current={activeCompPath:t,projectId:e},O.current=null,C(null),M(null,{revealPanel:!1}))},[t,e,M]),(0,U.useEffect)(()=>{b&&(i||Y7(b,g)||X7(v,b)||!b.element.isConnected)&&R(null)},[i,b,g,v,R]),(0,U.useEffect)(()=>{i&&M(null,{revealPanel:!1})},[M,i]),Ljn({previewIframeRef:a,buildDomSelectionFromTarget:F,applyDomSelection:M}),{domEditSelection:g,domEditGroupSelections:v,domEditHoverSelection:b,activeGroupElement:S,domEditSelectionRef:T,domEditGroupSelectionsRef:E,domEditHoverSelectionRef:D,activeGroupElementRef:O,setDomEditSelection:_,setDomEditGroupSelections:y,setActiveGroupElement:P,applyDomSelection:M,clearDomSelection:N,buildDomSelectionFromTarget:F,resolveDomSelectionFromPreviewPoint:I,resolveAllDomSelectionsFromPreviewPoint:L,updateDomEditHoverSelection:R,buildDomSelectionForTimelineElement:z,handleTimelineElementSelect:B,refreshDomEditSelectionFromPreview:ee,refreshDomEditGroupSelectionsFromPreview:te,applyMarqueeSelection:(0,U.useCallback)((e,t)=>{K4(`marquee`,{hits:e.length,additive:t});let n=T.current,r=E.current;if(e.length===0){let e=Z7(r,n).length;return t||M(null,{revealPanel:!1}),{changed:!t&&e>0,count:t?e:0}}let i;if(t){i=Z7(r,n);for(let t of e)X7(i,t)||(i=[...i,t])}else{i=[];for(let t of e)X7(i,t)||i.push(t)}let a=t&&n?n:e[0],o=Z7(r,n),s=o.length!==i.length||i.some(e=>!X7(o,e))||!Y7(n,a);return T.current=a,E.current=i,_(a),y(i),j(i,a,!0),{changed:s,count:i.length}},[M,j])}}var Bjn=6,Vjn=600,Hjn=400,Ujn=6;function Wjn({captionEditMode:e,compositionLoading:t,previewIframeRef:n,showToast:r,applyDomSelection:i,resolveDomSelectionFromPreviewPoint:a,resolveAllDomSelectionsFromPreviewPoint:o,updateDomEditHoverSelection:s,setActiveGroupElement:c,onClickToSource:l}){let u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useCallback)(()=>{let e=ein(n.current),t=X.getState();t.setIsPlaying(!1),e!=null&&(t.setCurrentTime(e),Lb.notify(e))},[n]);return{handlePreviewCanvasMouseDown:(0,U.useCallback)(async(n,r)=>{if(e||t)return;let s=Date.now(),p=d.current,m=n.detail>=2||p!=null&&s-p.t<Hjn&&Math.hypot(n.clientX-p.x,n.clientY-p.y)<Ujn;d.current={t:s,x:n.clientX,y:n.clientY};let h=X.getState().isPlaying;f();let g=()=>{h&&X.getState().requestPlayback(!0)};if(m&&!n.shiftKey){let e=await a(n.clientX,n.clientY),t=u.current,r=t!==null&&t.candidates.length>1&&Math.hypot(n.clientX-t.x,n.clientY-t.y)<Bjn&&s-t.at<Vjn;if(e?.element.hasAttribute(`data-hf-group`)){n.preventDefault(),n.stopPropagation(),u.current=null,mG(`group`,{action:`drill_in`}),c(e.element),i(await a(n.clientX,n.clientY,{activeGroupElement:e.element})??e);return}if(e&&!r&&!e.element.hasAttribute(`data-composition-src`)&&!e.element.hasAttribute(`data-composition-file`)){n.preventDefault(),n.stopPropagation(),u.current=null,i(e);return}}let _=Date.now(),v=u.current,y=v?n.clientX-v.x:1/0,b=v?n.clientY-v.y:1/0,x=v!==null&&Math.sqrt(y*y+b*b)<Bjn&&_-v.at<Vjn;if(n.shiftKey){u.current=null;let e=await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1})??r?.hoverSelection??null;if(!e){g();return}n.preventDefault(),n.stopPropagation(),i(e,{additive:!0}),m4(`multi_select`,`button`);return}if(x&&v){let e=(v.index+1)%v.candidates.length,t=v.candidates[e];u.current={...v,index:e,at:_},n.preventDefault(),n.stopPropagation(),i(t);return}let S=await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1});if(S||=(c(null),await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1,activeGroupElement:null})),S=S??r?.hoverSelection??null,!S){u.current=null,i(null,{revealPanel:!1}),g();return}n.preventDefault(),n.stopPropagation(),i(S),!n.shiftKey&&n.altKey&&l&&l(S);let C=await o(n.clientX,n.clientY);u.current=C.length>1?{x:n.clientX,y:n.clientY,candidates:C,index:0,at:_}:null},[i,e,t,l,f,o,a,c]),handlePreviewCanvasPointerMove:(0,U.useCallback)(async(n,r)=>{if(e||t)return s(null),null;let i=await a(n.clientX,n.clientY,{preferClipAncestor:r?.preferClipAncestor??!1,skipSourceProbe:!0});return s(i),i},[e,t,a,s]),handlePreviewCanvasPointerLeave:(0,U.useCallback)(()=>{s(null)},[s]),handleBlockedDomMove:(0,U.useCallback)((e,t)=>{r(t??e.capabilities.reasonIfDisabled??`This element can't be adjusted directly from the preview.`,`info`)},[r]),handleDomManualDragStart:(0,U.useCallback)(()=>{f()},[f])}}var Gjn=new Set([`inherit`,`initial`,`revert`,`revert-layer`,`serif`,`sans-serif`,`monospace`,`cursive`,`fantasy`,`system-ui`,`ui-sans-serif`,`ui-serif`,`ui-monospace`,`ui-rounded`,`emoji`,`math`,`fangsong`]);function Kjn(e){return(e.split(`,`)[0]??``).trim().replace(/^["']|["']$/g,``)}function qjn(e){return e.split(`,`)[0]?.trim().replace(/^["']|["']$/g,``).trim()??``}function Jjn(e,t){let n=Kjn(t);if(!n||Gjn.has(n.toLowerCase()))return;let r=`studio-preview-google-font-${n.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`;if(e.getElementById(r))return;let i=e.createElement(`link`);i.id=r,i.rel=`stylesheet`,i.href=dyn(n),e.head.appendChild(i)}function Yjn(e,t){let n=`studio-imported-font-${t.path.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}`;if(e.getElementById(n))return;let r=e.createElement(`style`);r.id=n,r.textContent=Ubn(t),e.head.appendChild(r)}function Xjn(e,t){return Ubn(e,G0t(t,e.path))}function Zjn(e){if(e.id)return{selector:iJ(e.id)};let t=e.element,n=t.ownerDocument;if(e.selector&&cJ(n,e.selector,t))return{selector:e.selector};let r=t.tagName.toLowerCase(),i=r,a=1;for(;n.getElementById(i);)a+=1,i=`${r}-${a}`;return{selector:iJ(i),autoId:i}}var Qjn=class extends Error{constructor(e,t){super(nMn(e,t)),this.statusCode=e,this.responseBody=t,this.name=`GsapMutationHttpError`}statusCode;responseBody};function $jn(e){return typeof e==`object`&&!!e}function eMn(e){let t=Array.isArray(e)?e.filter(e=>typeof e==`string`):[];return t.length>0?` (${t.join(`, `)})`:``}async function tMn(e){return(e.headers.get(`content-type`)??``).includes(`application/json`)?await e.json().catch(()=>null):await e.text().catch(()=>null)}function nMn(e,t){return $jn(t)&&typeof t.error==`string`?t.error:`GSAP mutation failed with status ${e}`}function rMn(e){let t=e.responseBody;return $jn(t)?`Couldn't save animation: ${nMn(e.statusCode,t)}${eMn(t.fields)}`:`Couldn't save animation: ${e.message}`}function iMn(e){return e.map(e=>e.path).join(`, `)}function aMn(e){return e instanceof Error?e.message:String(e)}async function oMn(e){return(e.headers.get(`content-type`)??``).includes(`application/json`)?await e.json().catch(()=>null):null}function sMn(e){return e?.error?`Couldn't save edit: ${e.error}${eMn(e.fields)}`:`Couldn't save edit`}function cMn(e){return e.target.id??e.target.hfId??e.target.selector??`(unaddressed)`}function lMn(e,t){let n=e.patches.filter((e,n)=>t[n]===!1).map(cMn);n.length!==0&&(console.warn(`[studio] z-index reorder: server could not match ${n.length} patch target(s) in ${e.sourceFile} (the whole z-order gesture will revert on reload):`,n.join(`, `)),rX({source:`dom_edit`,error:Error(`Batch patch target(s) unmatched: ${n.join(`, `)}`),filePath:e.sourceFile,mutationType:`z-reorder-unmatched`}))}var uMn=class extends Error{constructor(e,t){super(e,t),this.name=`AtomicElementPatchConvergenceError`}};function dMn(e){return typeof e==`object`&&!!e&&`sourceFile`in e&&typeof e.sourceFile==`string`&&`changed`in e&&typeof e.changed==`boolean`&&(!(`matched`in e)||Array.isArray(e.matched)&&e.matched.every(e=>typeof e==`boolean`))&&`before`in e&&typeof e.before==`string`&&`after`in e&&typeof e.after==`string`&&e.changed===(e.before!==e.after)}async function fMn(e,t){let n=JSON.stringify({batches:t});try{let r=await H(`/api/projects/${encodeURIComponent(e)}/file-mutations/patch-element-batches`,{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:n});if(!r.ok)throw new JY(sMn(await oMn(r)),r.status);let i=await r.json().catch(()=>null);if(typeof i!=`object`||!i||!(`durable`in i)||typeof i.durable!=`boolean`||!(`files`in i)||!Array.isArray(i.files)||i.files.length!==t.length||!i.files.every(dMn)||!i.durable&&i.files.some(e=>e.changed))throw new JY(`Invalid atomic element patch response`,502);let a=i.files.map((e,n)=>{let r=t[n],i=e.matched??[];if(!r||e.sourceFile!==r.sourceFile||i.length!==0&&i.length!==r.patches.length)throw new JY(`Invalid atomic element patch response`,502);return lMn(r,i),{...e,matched:i,allMatched:i.length===r.patches.length&&i.every(Boolean)}});return{durable:i.durable,files:a}}catch(e){throw new uMn(aMn(e),{cause:e})}}function pMn(e){return e.every(e=>e.patches.every(e=>e.operations.every(e=>e.type===`inline-style`)))}async function mMn(e,t,n,r){let i=await H(M(e,`/file-mutations/patch-element/${encodeURIComponent(t)}`),{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:JSON.stringify(n)});if(!i.ok)throw r(sMn(await oMn(i)),`error`),await iX(i,`Failed to patch ${t}`,{alreadyToasted:!0});return await i.json()}async function hMn({projectId:e,targetPath:t,selection:n,autoId:r,showToast:i}){let a={target:{id:n.id,hfId:n.hfId,selector:n.selector,selectorIndex:n.selectorIndex},operations:[{type:`ensure-id`,property:`id`,value:r}]};if(bOt(a).length>0)return i(`Couldn't assign element id because the patch contains invalid values`,`error`),null;try{let{elementId:n}=await mMn(e,t,a,i);return n||(i(`Couldn't assign element id: element not found in ${t}`,`error`),null)}catch(e){if(e instanceof JY&&e.alreadyToasted)return null;throw e}}async function gMn(e,t,n,r,i){let a=n(t,e);if(a===t)return{content:t,failed:!1};try{return await r(e,a,t),{content:a,failed:!1}}catch(n){return i(`Saved, but couldn't finish updating ${e}: ${aMn(n)}`,`error`),{content:t,failed:!0}}}function _Mn({activeCompPath:e,previewIframeRef:t,showToast:n,queueDomEditSave:r,writeProjectFile:i,editHistory:a,projectIdRef:o,reloadPreview:s,forceReloadSdkSession:c,onTrySdkPersist:l}){let u=(0,U.useRef)(new Set),d=(0,U.useCallback)(async(r,d,f,p)=>{if(o.current!==p)throw Error(`Active project changed before the edit could be saved`);let m=p;if(f?.shouldSave&&!f.shouldSave())return;let h=r.sourceFile||e||`index.html`,g=(e,n)=>(f?.skipRefresh&&n&&!f.deferRender&&q7(t.current),e),_=async()=>{let e=await NZ(m,h);if(o.current!==p)throw Error(`Active project changed before the edit could be saved`);return f?.shouldSave&&!f.shouldSave()?null:e},v=Wt(r),y=f?.importedFont,b={target:v,operations:d,...y?{fontFaceCss:Xjn(y,h)}:{}},x=bOt(b);if(x.length>0){let e=iMn(x);throw n(`Couldn't save edit because it contains invalid layout values`,`error`),new f8(`DOM patch contains unsafe values: ${e}`,{alreadyToasted:!0})}if(l&&!y&&!f?.prepareContent){let e=await _();if(e===null)return;let t=await l(r,d,e,h,{label:f?.label,coalesceKey:f?.coalesceKey,skipRefresh:f?.skipRefresh});if(t.status===`failed`)throw t.error;if(t.status===`committed`)return g({sourceFile:h,version:t.version,changed:!0},!0)}let S={label:f?.label??`Edit layer`,coalesceKey:f?.coalesceKey,coalesceMs:f?.coalesceMs},C=f?.prepareContent,w=!1,T=await MZ(i,[h],async()=>{let e=await _();if(e===null)return null;let t=await mMn(m,h,b,n);if(!t.changed)return{patchData:t,patchedContent:null,finalContent:null};let r=typeof t.content==`string`?t.content:e,o=C?await gMn(h,r,C,i,n):{content:r,failed:!1};w=o.failed;let s=o.content;return await a.recordEdit({...S,files:{[h]:{before:e,after:s}}}),{patchData:t,patchedContent:r,finalContent:s}});if(T===null)return;let{patchData:E,patchedContent:D,finalContent:O}=T;if(O===null){if(E.matched===!1){let t=r.selector??r.id??`selection`;throw u.current.has(t)||(u.current.add(t),mG(`save_skipped_unresolvable`,{target_id:r.id??void 0,target_selector:r.selector??void 0,target_source_file:r.sourceFile??void 0,composition:e??void 0})),new Cpn(h)}return Apn(r,d),g(typeof E.path==`string`&&typeof E.version==`string`?{sourceFile:E.path,version:E.version,changed:!1}:void 0,!1)}c?.(),f?.skipRefresh||s();let k=g(O===D&&typeof E.path==`string`&&typeof E.version==`string`?{sourceFile:E.path,version:E.version,changed:!0}:void 0,!0);if(w)throw new wpn(h);return k},[e,a,i,o,s,n,c,l,t]);return(0,U.useCallback)((e,t,n)=>{let i=o.current;if(!i)return Promise.reject(Error(`No active project`));let a=()=>r(()=>d(e,t,n,i));return e.element?q0(e.element,a):a()},[d,o,r])}function vMn({activeCompPath:e,persistDomEditOperations:t,showToast:n}){return(0,U.useCallback)((r,i,a)=>t(r,i,{label:a.label,coalesceKey:a.coalesceKey,coalesceMs:a.coalesceMs,skipRefresh:a.skipRefresh??!0,deferRender:a.deferRender}).catch(t=>{throw t instanceof t6?t:(kpn(t)||n(t instanceof Error?t.message:`Failed to save position`),rX({source:`dom_edit`,error:t,filePath:r.sourceFile??e??`index.html`,mutationType:`position`,label:a.label,targetId:r.id,targetSelector:r.selector,targetSourceFile:r.sourceFile}),t)}),[e,t,n])}function yMn(e){let t=Mt(e),n=e.getAttribute(`data-hf-id`),r=at(e),i=r?Xt(e.ownerDocument,e,r)??0:0,{elements:o,updateElement:s}=X.getState(),c=o.find(e=>e.sourceFile===t&&(n?e.hfId===n:!!r&&e.selector===r&&(e.selectorIndex??0)===i));c&&s(a(c),{text:Xe(e)})}function bMn(e,t){return e.every((e,n)=>t[n]?.key===e.key)}function xMn(e,t){return Object.prototype.hasOwnProperty.call(e,t)?e[t]:null}function SMn(e,t){return Array.from(new Set([...Object.keys(e),...Object.keys(t)]))}function CMn(e,t){if(e.length!==t.length||!bMn(e,t)||t.some(e=>e.source===`text-node`)||t.some(e=>e.source!==`child`)||e.some(e=>e.source!==`child`))return null;let n=new Map(e.map(e=>[e.key,e])),r=[];for(let i of t){let t=n.get(i.key),a=et(e,i.key);if(!t||!a)return null;i.value!==t.value&&r.push(Zt(i.value,a));for(let e of SMn(t.inlineStyles,i.inlineStyles)){let n=xMn(t.inlineStyles,e),o=xMn(i.inlineStyles,e);o!==n&&r.push(wt(e,o,a))}}return r}function wMn(e,t,n){return e.length===0?[]:e.map(e=>e.key===n?{...e,value:t}:e)}function TMn(e,t,n){let r=t.length>1||t.some(e=>e.source===`child`),i=r?vt(t):n;return{usesSerializedTextFields:r,nextContent:i,operations:(r?CMn(e,t):null)??(r?[Ze(i)]:[Zt(i)])}}var EMn=[[`background-position`,`center`],[`background-repeat`,`no-repeat`],[`background-size`,`contain`]];async function DMn(e,t,n){let r=Object.fromEntries(Object.entries(n).map(([e,t])=>[X0t(e),t])),i=Object.entries(r);if(i.length===0)return E6(`no-selection`);if(i.some(([e])=>Z0t(e)))return E6(`geometry-property`);if(!t.capabilities.canEditStyles)return E6(`styles-not-editable`);let{activeCompPath:a,previewIframeRef:o,persistDomEditOperations:s,showToast:c}=e,l=sn(t),u=i.map(([t])=>({property:t,isLatest:w6(e.versions,`${l}:${t}`)})),d=()=>u.some(({isLatest:e})=>e()),f=r[`font-family`],p=f===void 0?null:e.resolveImportedFontAsset?.(f)??null,m=o.current?.contentDocument,h=[],g=[];for(let[e,t]of i){let n=J0t(e,t);if(h.push(wt(e,n)),g.push([e,n]),e===`background-image`&&Y0t(t))for(let[e,t]of EMn)e in r||(h.push(wt(e,t)),g.push([e,t]))}let _=null,v=new Map;return fun({capture:()=>{let e=m?He(m,t,a):null;if(e){_=e;for(let[t]of i)v.set(t,e.style.getPropertyValue(t))}},apply:()=>{if(_){for(let[e,t]of g)_.style.setProperty(e,t);f!==void 0&&m&&(Jjn(m,f),p&&Yjn(m,p))}},persist:()=>s(t,h,{label:`Edit layer style`,skipRefresh:!0,importedFont:p??void 0}),shouldRevert:d,revert:()=>{let e=_;if(e)for(let{property:t,isLatest:n}of u){let r=v.get(t);r===void 0||!n()||(r===``?e.style.removeProperty(t):e.style.setProperty(t,r))}},onError:e=>p8(t,h,e,c),shouldResync:d,resync:()=>e.resync?.(t),onFinally:()=>u.forEach(({isLatest:e})=>e.release())})}function OMn(e,t){return t&&!e.startsWith(`data-`)?`data-${e}`:e}function kMn(e,t){return t===null||t===`false`&&nQt.has(e)?null:t}function AMn(e){return e.type===`attribute`?OMn(e.property,!0):e.property}function jMn(e){return e.type===`html-attribute`?kMn(e.property,e.value):e.value===``?null:e.value}function Q7(e,t,n){n===null?e.removeAttribute(t):e.setAttribute(t,n),(e.tagName.toLowerCase()===`hf-audio-group`||t===`data-audio-group`)&&N1(e.ownerDocument)}function MMn(e,t,n){return e?He(e,t,n):null}function NMn(e,t,n,r){let i=MMn(e,t,n);return i?{element:i,previousValues:new Map(r.map(e=>[e,i.getAttribute(e)]))}:null}function PMn(e,t,n,r){let i=MMn(e,t,n);return i?{element:i,previousValue:i.getAttribute(r)}:null}function FMn({activeCompPath:e,previewIframeRef:t,showToast:n,domEditSelection:r,refreshDomEditSelectionFromPreview:i,persistDomEditOperations:a}){let o=(0,U.useRef)(new Map),s=(0,U.useCallback)(async(s,c,l)=>{if(!r)return;let u=t.current,d=OMn(s,!0),f=`${l.coalescePrefix}:${s}:${sn(r)}`,p=w6(o.current,f),m={type:`attribute`,property:s,value:c},h=null,g=null;await T6({capture:()=>{let t=PMn(u?.contentDocument,r,e,d);t&&(h=t.element,g=t.previousValue)},apply:()=>{h&&Q7(h,d,c===null||c===``?null:c)},persist:l.previewOnly?async()=>{}:()=>a(r,[m],{label:l.label,coalesceKey:f,skipRefresh:l.skipRefresh}),shouldRevert:()=>p(),revert:()=>{h&&Q7(h,d,g)},onError:e=>p8(r,[m],e,n),shouldResync:()=>p()&&!!l.refreshAfter,resync:()=>{i(r),V7(t.current?.contentDocument??null)},onSettled:l.onSettled,onFinally:p.release})},[e,r,a,i,n,t]),c=(0,U.useCallback)(async(r,s,c)=>{let l=t.current,u=s.map(e=>({fullAttr:AMn(e),value:jMn(e)})),d=`${c.coalescePrefix}:${s.map(e=>e.property).sort().join(`,`)}:${sn(r)}`,f=w6(o.current,d),p=null,m=!1;return await T6({capture:()=>{p=NMn(l?.contentDocument,r,e,u.map(e=>e.fullAttr))},apply:()=>{if(p)for(let e of u)Q7(p.element,e.fullAttr,e.value)},persist:()=>a(r,s,{label:c.label,coalesceKey:d,skipRefresh:c.skipRefresh,prepareContent:c.prepareContent}),shouldRevert:e=>f()&&!(e instanceof wpn),revert:()=>{if(p)for(let e of u)Q7(p.element,e.fullAttr,p.previousValues.get(e.fullAttr)??null)},onError:e=>p8(r,s,e,n),shouldResync:()=>f()&&!!c.refreshAfter,resync:()=>{i(r),c.syncAutomation&&V7(t.current?.contentDocument??null)},onSettled:e=>{m=e,c.onSettled?.(e)},onFinally:f.release}),m},[e,a,i,n,t]),l=(0,U.useCallback)(async(e,t)=>{await c(e,Object.entries(t).map(([e,t])=>({type:`attribute`,property:e,value:t})),{label:`Edit timing`,coalescePrefix:`attrs`,skipRefresh:!1,refreshAfter:!0})},[c]),u=(0,U.useCallback)((e,t,n)=>c(e,t,{label:n.label,coalescePrefix:`attr-batch`,skipRefresh:!1,refreshAfter:!0,syncAutomation:!0,prepareContent:n.prepareContent}),[c]);return{handleDomAttributeCommit:(0,U.useCallback)(async(e,t)=>{await s(e,t,{label:`Edit ${e.replace(/-/g,` `)}`,coalescePrefix:`attr`,skipRefresh:!1,refreshAfter:!0})},[s]),handleDomAttributeLiveCommit:(0,U.useCallback)(async(e,t,n,r)=>{await s(e,t,{label:`Edit ${e.replace(/^(data-)?/,``).replace(/-/g,` `)}`,coalescePrefix:`attr-live`,skipRefresh:!0,onSettled:n,...r?.previewOnly?{previewOnly:!0}:{}})},[s]),handleDomAttributeQuietCommit:(0,U.useCallback)(async(e,t)=>{await s(e,t,{label:`Edit ${e.replace(/^(data-)?/,``).replace(/-/g,` `)}`,coalescePrefix:`attr-quiet`,skipRefresh:!0,refreshAfter:!0})},[s]),handleDomHtmlAttributeCommit:(0,U.useCallback)(async(s,c)=>{if(!r)return;let l=t.current,u=`html-attr:${s}:${sn(r)}`,d=w6(o.current,u),f={type:`html-attribute`,property:s,value:c},p=null,m=null;await T6({capture:()=>{let t=PMn(l?.contentDocument,r,e,s);t&&(p=t.element,m=t.previousValue)},apply:()=>{p&&Q7(p,s,kMn(s,c))},persist:()=>a(r,[f],{label:`Edit ${s}`,coalesceKey:u,skipRefresh:!1}),shouldRevert:()=>d(),revert:()=>{p&&Q7(p,s,m)},onError:e=>p8(r,[f],e,n),shouldResync:()=>d(),resync:()=>{i(r),V7(t.current?.contentDocument??null)},onFinally:d.release})},[e,r,a,i,n,t]),handleDomAttributesCommit:l,handleDomAttributeBatchCommit:u}}function IMn(e,t){return e.isCompositionHost||e.isInsideLockedComposition?!1:g6(t)}async function LMn(e,t,n,r,i){if(!e)return;let a=He(e,t,n);if(!a)return;yMn(a);let o=await r(a);o&&i(o,{revealPanel:!1,preserveGroup:!0})}function RMn({activeCompPath:e,previewIframeRef:t,showToast:n,domEditSelection:r,applyDomSelection:i,refreshDomEditSelectionFromPreview:a,buildDomSelectionFromTarget:o,persistDomEditOperations:s,resolveImportedFontAsset:c,readOnlyPreview:l}){let u=(0,U.useRef)(l);u.current=l;let d=(0,U.useRef)(r);d.current=r;let f=(0,U.useRef)(new Map),p=(0,U.useRef)(new Map),{handleDomAttributeCommit:m,handleDomAttributeLiveCommit:h,handleDomAttributeQuietCommit:g,handleDomHtmlAttributeCommit:_,handleDomAttributesCommit:v,handleDomAttributeBatchCommit:y}=FMn({activeCompPath:e,previewIframeRef:t,showToast:n,domEditSelection:r,refreshDomEditSelectionFromPreview:a,persistDomEditOperations:s}),b=(0,U.useCallback)((r,i,o=``)=>DMn({activeCompPath:e,previewIframeRef:t,persistDomEditOperations:s,showToast:n,versions:p.current,resolveImportedFontAsset:c,resync:a},r,typeof i==`string`?{[i]:o}:i),[e,s,a,c,n,t]),x=(0,U.useCallback)((e,t)=>r?b(r,e,t):Promise.resolve(E6(`no-selection`)),[r,b]),S=(0,U.useCallback)(async(r,a,c)=>{if(!Se(r))return E6(`not-text-editable`);let l=w6(f.current,sn(r)),u=wMn(r.textFields,a,c),d=TMn(r.textFields,u,a),p=t.current?.contentDocument,m=null,h=null;return fun({capture:()=>{if(!p)return;let t=He(p,r,e);t&&(m=t,h=t.innerHTML)},apply:()=>{m&&(d.usesSerializedTextFields?m.innerHTML=d.nextContent:m.textContent=a)},persist:()=>s(r,d.operations,{label:`Edit text`,skipRefresh:!0,shouldSave:l}),shouldRevert:()=>l(),revert:()=>{!m||h===null||(m.innerHTML=h)},onError:e=>p8(r,d.operations,e,n),shouldResync:l,resync:()=>LMn(p,r,e,o,i),onFinally:l.release})},[e,i,o,s,t,n]),C=(0,U.useCallback)((e,t)=>r?S(r,e,t):Promise.resolve(E6(`no-selection`)),[r,S]),w=(0,U.useCallback)(async({element:r,html:a,previousHtml:c})=>{let l=()=>{r.isConnected&&r.innerHTML===a&&(r.innerHTML=c)};if(u.current)return l();let p=e=>{console.error(`[Studio] text edit not saved:`,e,r),n(`Couldn't save the text edit: ${e}`,`error`),l()},m=t.current?.contentDocument;if(!m||!r.isConnected||r.ownerDocument!==m)return p(`the text's element is gone from the preview`);let h=await o(r,{exactTarget:!0,skipSourceProbe:!0});if(h?.element!==r)return p(`this text was not found in the composition's source`);if(!IMn(h,r))return p(`this text can't be edited in place`);let g=w6(f.current,sn(h)),_=[Ze(a)],v=``;await T6({capture:()=>{},apply:()=>{r.innerHTML=a,v=r.innerHTML},persist:async()=>{(await s(h,_,{label:`Edit text`,skipRefresh:!0,shouldSave:g}))?.changed&&m4(`text_edit`,`field`)},shouldRevert:()=>g(),revert:()=>{r.isConnected&&r.innerHTML===v&&(r.innerHTML=c)},onError:e=>p8(h,_,e,n),shouldResync:()=>g()&&d.current?.element===r,resync:()=>LMn(m,h,e,o,i),onFinally:g.release})},[e,i,o,s,t,n]),T=(0,U.useCallback)(async(r,a,c)=>{let l=w6(f.current,sn(r)),u=TMn(r.textFields,a,a[0]?.value??``),d=t.current?.contentDocument,p=null,m=null,h=c?.importedFont??null;await T6({capture:()=>{if(!d)return;let t=He(d,r,e);t&&(p=t,m=t.innerHTML)},apply:()=>{p&&(u.usesSerializedTextFields?p.innerHTML=u.nextContent:p.textContent=u.nextContent)},persist:async()=>{await s(r,u.operations,{label:`Edit text`,skipRefresh:!0,importedFont:h??void 0})},shouldRevert:()=>l(),revert:()=>{!p||m===null||(p.innerHTML=m)},onError:e=>p8(r,u.operations,e,n),shouldResync:l,resync:()=>LMn(d,r,e,o,i),onFinally:l.release})},[e,i,o,s,t,n]);return{handleDomStyleCommit:x,handleDomStyleCommitForSelection:b,handleDomAttributeCommit:m,handleDomAttributeLiveCommit:h,handleDomAttributeQuietCommit:g,handleDomHtmlAttributeCommit:_,handleDomAttributesCommit:v,handleDomAttributeBatchCommit:y,handleDomTextCommit:C,handleDomTextCommitForSelection:S,handleDomRichTextCommit:w,commitDomTextFields:T,handleDomTextFieldStyleCommit:(0,U.useCallback)(async(e,n,i)=>{if(!r)return;let a=r.textFields.find(t=>t.key===e);if(!a)return;if(a.source===`self`){await x(n,i);return}let o=J0t(n,i),s=n===`font-family`?c(i):null;if(n===`font-family`){let e=t.current?.contentDocument;e&&(Jjn(e,o),s&&Yjn(e,s))}let l=r.textFields.map(t=>t.key===e?{...t,inlineStyles:{...t.inlineStyles,[n]:o},computedStyles:{...t.computedStyles,[n]:o}}:t);await T(r,l,{importedFont:s})},[T,r,x,c,t]),handleDomAddTextField:(0,U.useCallback)(async e=>{if(!r||!r.textFields.some(e=>e.source===`child`))return null;let t=r.textFields.findIndex(t=>t.key===e),n=r.textFields[t>=0?t:0]??r.textFields[0],i=Nt(n),a=[...r.textFields];return a.splice(t>=0?t+1:a.length,0,i),await T(r,a),i.key},[T,r]),handleDomRemoveTextField:(0,U.useCallback)(async e=>{if(!r)return;let t=r.textFields.find(t=>t.key===e);if(!t)return;if(t.source===`self`){await C(``,e);return}let n=r.textFields.filter(t=>t.key!==e);await T(r,n)},[T,r,C])}}var zMn=e=>({left:e.offsetLeft,top:e.offsetTop,width:e.offsetWidth,height:e.offsetHeight});function BMn(e,t){let n=Number.parseFloat(e.getAttribute(`data-hf-drag-initial-offset-${t}`)??``);return Number.isFinite(n)?n:0}function VMn(e,t){let n=e.ownerDocument.defaultView?.getComputedStyle(e);if(!n)return`anchored`;let r=S(t.x-BMn(e,`x`)),i=S(t.y-BMn(e,`y`)),a=e.getAttribute(ie)===`static`,o=a||!/^(relative|absolute|fixed|sticky)$/.test(n.position);if(!o&&(n.left.endsWith(`%`)||n.top.endsWith(`%`)))return`percent`;let s=o?0:Number.parseFloat(n.left)||0,c=o?0:Number.parseFloat(n.top)||0,l={position:e.style.position,left:e.style.left,top:e.style.top},u=zMn(e);o&&(e.style.position=`relative`),e.style.left=`${S(s+r)}px`,e.style.top=`${S(c+i)}px`;let d=zMn(e);return Math.abs(d.left-u.left-r)<=1&&Math.abs(d.top-u.top-i)<=1&&Math.abs(d.width-u.width)<=1&&Math.abs(d.height-u.height)<=1?(a&&e.removeAttribute(ie),[...o?[{type:`inline-style`,property:`position`,value:`relative`}]:[],{type:`inline-style`,property:`left`,value:e.style.left},{type:`inline-style`,property:`top`,value:e.style.top}]):(Object.assign(e.style,l),`anchored`)}var HMn=`The animation took over this layer's position during the move, so it was not saved.`,UMn={anchored:`This layer is anchored from its right or bottom edge. Move it in the Code tab.`,percent:`This layer's position is set in percent. Move it in the Code tab.`};function WMn(e){return e.ownerDocument.defaultView?.gsap}function GMn(e){let t=WMn(e),n=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-x`)??``),r=Number.parseFloat(e.getAttribute(`data-hf-drag-gsap-base-y`)??``);t&&Number.isFinite(n)&&Number.isFinite(r)&&t.set(e,{x:n,y:r})}function KMn(e,t){if(H9t(e))throw WMn(e)?.set(e,{x:0,y:0,xPercent:0,yPercent:0}),t(HMn,`error`),$Y(Error(HMn))}var qMn=0;function JMn(e,t,n,r){let i=t.element,a=c3(i),o=aon(i,n),s=i.style.getPropertyValue(`translate`),c=()=>{i.style.getPropertyValue(`translate`)===s&&p3(i,a)},l={label:`Move layer`,coalesceKey:r??`move:${++qMn}`,coalesceMs:1/0};return{save:()=>e(t,o,l).catch(e=>{throw c(),e}),rollback:c}}function YMn({commitPositionPatchToHtml:e,showToast:t,readOnlyPreview:n},r,i,a,o){let s=r.element;if(n)return{save:()=>Promise.resolve(void 0),rollback:()=>void 0};if(a)return KMn(s,t),JMn(e,r,i,o);let c={position:s.style.position,left:s.style.left,top:s.style.top},l=s.getAttribute(ie),u=VMn(s,i);if(!Array.isArray(u))throw t(UMn[u],`error`),Error(UMn[u]);GMn(s);let d=()=>{Object.assign(s.style,c),l!==null&&s.setAttribute(ie,l)};return{save:()=>e(r,u,{label:`Move layer`,coalesceKey:o??`element-offset:${sn(r)}`,...o&&{coalesceMs:1/0}}).catch(e=>{throw d(),e}),rollback:d}}var XMn=0;function ZMn({commitPositionPatchToHtml:e,readOnlyPreview:t},n,r){if(t)return Promise.resolve(void 0);let{element:i}=n,a=s3(i),o=i.hasAttribute(t0)?A9t(i):[];o.length&&Uan(i);let s=Hon(i,r.angle,o.length?void 0:r.plain??void 0);o.push(...s);let c=s.at(-1);return e(n,o,{label:`Rotate layer`,coalesceKey:`rotate:${++XMn}`,coalesceMs:1/0}).catch(e=>{throw i.style.getPropertyValue(c.property)===c.value&&Uon(i,a),e})}var QMn=0;function $Mn({showToast:e,commitPositionPatchToHtml:t,readOnlyPreview:n}){return{stageElementPositionOffset:(0,U.useCallback)((r,i,a,o)=>YMn({commitPositionPatchToHtml:t,showToast:e,readOnlyPreview:n},r,i,a,o),[t,n,e]),handleDomBoxSizeCommit:(0,U.useCallback)((e,r,i,a,o)=>{if(n)return Promise.resolve(void 0);let s=e.element,c=o3(s),l=c3(s),u=s6(s);r2(s,r);let d=u(),f=O9t(s);return d&&f.push(d.patch),i&&f.push(...aon(s,i)),t(e,f,{label:`Resize layer box`,...o?{coalesceKey:o,coalesceMs:1/0,deferRender:!0}:{coalesceKey:`box-size:${++QMn}`,coalesceMs:1/0}}).catch(e=>{throw d3(s,c),i&&p3(s,l),d?.revert(),a?.(),e})},[t,n]),handleDomRotationCommit:(0,U.useCallback)((e,r)=>ZMn({commitPositionPatchToHtml:t,readOnlyPreview:n},e,r),[t,n]),handleDomManualEditsReset:(0,U.useCallback)(e=>{let n=e.element,r=c3(n),i=o3(n),a=s3(n),o=[...E9t(n),...k9t(n),...A9t(n)];return Han(n),h3(n),Uan(n),t(e,o,{label:`Reset layer edits`,coalesceKey:`manual-reset:${sn(e)}`,skipRefresh:!1}).catch(e=>{throw p3(n,r),d3(n,i),f3(n,a),e})},[t])}}function eNn({activeCompPath:e,previewIframeRef:t,showToast:n,queueDomEditSave:r,writeProjectFile:i,editHistory:a,fileTree:o,importedFontAssetsRef:s,projectId:c,projectIdRef:l,reloadPreview:u,domEditSelection:d,applyDomSelection:f,clearDomSelection:p,refreshDomEditSelectionFromPreview:m,buildDomSelectionFromTarget:h,forceReloadSdkSession:g,onTrySdkPersist:_,onTrySdkDelete:v,onReorderShadow:y,readOnlyPreview:b}){let x=(0,U.useCallback)(e=>{let t=qjn(e);if(!t)return null;let n=s.current.find(e=>e.family.toLowerCase()===t.toLowerCase());if(n)return n;let r=o.find(e=>oq.test(e)&&D5(e).toLowerCase()===t.toLowerCase());return!r||!c?null:{family:D5(r),path:r,url:M(c,`/preview/${r}`)}},[o,c,s]),S=_Mn({activeCompPath:e,previewIframeRef:t,showToast:n,queueDomEditSave:r,writeProjectFile:i,editHistory:a,projectIdRef:l,reloadPreview:u,forceReloadSdkSession:g,onTrySdkPersist:_}),C=(0,U.useCallback)((e,t)=>{let o=l.current;return o?r(async()=>{if(l.current!==o)throw Error(`Active project changed before the edit could be saved`);let r=o,s=e.flatMap(e=>e.patches.flatMap(e=>bOt(e)));if(s.length>0)throw n(`Couldn't save edit because it contains invalid layout values`,`error`),new f8(`DOM patch contains unsafe values: ${iMn(s)}`,{alreadyToasted:!0});let{allMatched:c,changed:d}=await MZ(i,e.map(e=>e.sourceFile),async()=>{let n=await fMn(r,e),i=Object.fromEntries(n.files.filter(e=>e.changed).map(e=>[e.sourceFile,{before:e.before,after:e.after}])),o=Object.keys(i).length>0;return o&&await a.recordEdit({label:t.label,coalesceKey:t.coalesceKey,coalesceMs:t.coalesceMs,files:i}),{allMatched:n.durable&&n.files.every(e=>e.allMatched),changed:o}});d&&g?.();let f=c,p=t.skipReload===!0&&pMn(e)&&f;return(!f||d&&!p)&&u(),{durable:f,allMatched:c,changed:d}}).catch(r=>{throw r instanceof uMn&&u(),(r instanceof JY||r instanceof f8)&&r.alreadyToasted||n(r instanceof Error?r.message:`Failed to reorder layers`,`error`),rX({source:`dom_edit`,error:r,filePath:e.map(e=>e.sourceFile).join(`,`),mutationType:`z-reorder`,label:t.label}),r}):Promise.reject(Error(`No active project`))},[a,g,l,r,u,n,i]),{handleDomStyleCommit:w,handleDomStyleCommitForSelection:T,handleDomAttributeCommit:E,handleDomAttributeLiveCommit:D,handleDomAttributeQuietCommit:O,handleDomHtmlAttributeCommit:k,handleDomAttributesCommit:A,handleDomAttributeBatchCommit:j,handleDomTextCommit:N,handleDomTextCommitForSelection:P,handleDomRichTextCommit:F,commitDomTextFields:I,handleDomTextFieldStyleCommit:L,handleDomAddTextField:R,handleDomRemoveTextField:z}=RMn({readOnlyPreview:b,activeCompPath:e,previewIframeRef:t,domEditSelection:d,applyDomSelection:f,refreshDomEditSelectionFromPreview:m,buildDomSelectionFromTarget:h,persistDomEditOperations:S,resolveImportedFontAsset:x,showToast:n}),B=vMn({activeCompPath:e,persistDomEditOperations:S,showToast:n}),{stageElementPositionOffset:V,handleDomBoxSizeCommit:ee,handleDomRotationCommit:te,handleDomManualEditsReset:H}=$Mn({showToast:n,commitPositionPatchToHtml:B,readOnlyPreview:b}),{handleDomEditElementsDelete:ne,handleDomZIndexReorderCommit:re}=Hdn({activeCompPath:e,showToast:n,writeProjectFile:i,editHistory:a,projectIdRef:l,reloadPreview:u,clearDomSelection:p,onTrySdkDelete:v,onReorderShadow:y,forceReloadSdkSession:g,commitDomEditPatchBatches:C});return{resolveImportedFontAsset:x,handleDomStyleCommit:w,handleDomStyleCommitForSelection:T,handleDomAttributeCommit:E,handleDomAttributeLiveCommit:D,handleDomAttributeQuietCommit:O,handleDomHtmlAttributeCommit:k,handleDomAttributesCommit:A,handleDomAttributeBatchCommit:j,handleDomTextCommit:N,handleDomTextCommitForSelection:P,handleDomRichTextCommit:F,commitDomTextFields:I,handleDomTextFieldStyleCommit:L,handleDomAddTextField:R,handleDomRemoveTextField:z,stageElementPositionOffset:V,commitPositionPatchToHtml:B,handleDomBoxSizeCommit:ee,handleDomRotationCommit:te,handleDomManualEditsReset:H,handleDomEditElementsDelete:ne,handleDomZIndexReorderCommit:re}}function tNn(e,t){let n=QQ(e,t);if(!n)return;let r=t.find(e=>(e.key??e.id)===n);if(r)return o2t(r)}function nNn(e,t){let n=e.map(e=>({target:Wt(e),left:e.element.offsetLeft,top:e.element.offsetTop,right:e.element.offsetLeft+e.element.offsetWidth,bottom:e.element.offsetTop+e.element.offsetHeight,track:tNn(e,t)})),r=Math.min(...n.map(e=>e.left)),i=Math.min(...n.map(e=>e.top));return{bbox:{left:r,top:i,width:Math.max(...n.map(e=>e.right))-r,height:Math.max(...n.map(e=>e.bottom))-i},targets:n.map(e=>e.target),rebases:n.map(e=>({target:e.target,left:e.left-r,top:e.top-i,track:e.track}))}}function rNn(e,t){let n=e.sourceFile||`index.html`,r=[];for(let i of Array.from(e.element.children)){let e=i.id||void 0,a=se(i);if(!e&&!a)continue;let o=tNn({id:e,hfId:a,sourceFile:n,isCompositionHost:!1},t);r.push({target:Wt({id:e,hfId:a}),track:o})}return r}async function iNn(e,t,n,r,i,a){let o={};return await FZ({projectId:e,path:t,label:i,writeFile:a.writeProjectFile,recordEdit:a.editHistory.recordEdit,rewrite:async a=>{let s=await H(M(e,`/file-mutations/${n}/${encodeURIComponent(t)}`),{method:`POST`,headers:{"Content-Type":`application/json`,...rQ()},body:JSON.stringify(r)});if(!s.ok){let e=await s.json().catch(()=>null);throw Error(e?.error??`Failed to ${i.toLowerCase()} in ${t}`)}return o=await s.json(),{disk:typeof o.content==`string`?o.content:a}}}),a.clearDomSelection(),a.forceReloadSdkSession?.(),a.reloadPreview(),o}function aNn(e){let{activeCompPath:t,showToast:n,projectIdRef:r,timelineElements:i}=e;return{groupSelection:(0,U.useCallback)(async a=>{let o=r.current;if(!o||a.length===0)return null;let s=a[0].sourceFile||t||`index.html`;if(a.some(e=>(e.sourceFile||t||`index.html`)!==s))return n(`Can't group elements from different files`,`error`),null;let c=`Group ${a[0].element.ownerDocument.querySelectorAll(`[data-hf-group]`).length+1}`,{bbox:l,targets:u,rebases:d}=nNn(a,i);try{return(await iNn(o,s,`wrap-elements`,{targets:u,groupId:c,bbox:l,rebases:d},`Group elements`,e)).groupId??c}catch(e){return n(e instanceof Error?e.message:`Failed to group elements`,`error`),null}},[t,r,n,e,i]),ungroupSelection:(0,U.useCallback)(async a=>{let o=r.current;if(!o)return;let s=a.sourceFile||t||`index.html`,c=rNn(a,i);try{await iNn(o,s,`unwrap-elements`,{target:Wt(a),childTracks:c},`Ungroup elements`,e)}catch(e){n(e instanceof Error?e.message:`Failed to ungroup elements`,`error`)}},[t,r,n,e,i])}}var oNn=[`x`,`y`,`rotation`,`rotationX`,`rotationY`,`rotationZ`,`z`,`transformPerspective`,`scaleX`,`scaleY`,`scale`,`opacity`];function sNn(e){let t={};for(let[n,r]of Object.entries(e)){if(typeof r!=`number`||!Number.isFinite(r))return null;t[n]=r}return Object.keys(t).length>0?t:null}function cNn(e,t,n){try{let r=e.contentWindow?.gsap,i=e.contentDocument?.querySelector(t)??null,a=sNn(n);return!r?.set||!i||!a?!1:(r.set(i,a),jQt(i,a),!0)}catch{return!1}}function lNn(e){try{return e.contentWindow?.__player??null}catch{return null}}function uNn(e){if(e.length===0)return!1;for(let t of e){if(!t||typeof t!=`object`)return!1;for(let e of Object.values(t))if(typeof e!=`number`||!Number.isFinite(e))return!1}return!0}function dNn(e,t){let n=e.vars;if(!n||`motionPath`in n)return!1;let r=!1;for(let e of oNn){let i=t[e];if(i!==void 0){if(typeof i!=`number`||!Number.isFinite(i)||typeof n[e]==`string`)return!1;n[e]=i,r=!0}}return r}function fNn(e,t){let n=e.vars;return!n||`motionPath`in n||!Array.isArray(n.keyframes)||!uNn(t)?!1:(n.keyframes=t.map(e=>({...e})),!0)}function pNn(e,t,n){let r={};for(let[t,n]of Object.entries(e))r[t]={...n};let i=null;for(let e of Object.keys(r)){let n=parseFloat(e);if(Number.isFinite(n)&&Math.abs(n-t)<.05){i=e;break}}return i===null&&(i=`${t}%`),r[i]={...r[i]??{},...n},r}function mNn(e,t,n){let r=e.vars;if(!r||`motionPath`in r)return!1;let i=r.keyframes;if(!i||typeof i!=`object`||Array.isArray(i))return!1;for(let e of Object.values(n))if(typeof e!=`number`||!Number.isFinite(e))return!1;let a=e.parent,o=e.targets?.();if(!a?.to||!o||o.length===0||typeof e.startTime!=`function`||typeof e.kill!=`function`)return!1;let s=pNn(i,t,n),c={...r,keyframes:s},l=e.startTime();return e.kill(),a.to(o,c,l),!0}function hNn(e){if(e.kind===`set`)return Object.keys(e.props).filter(t=>e.props[t]!==void 0);if(e.kind===`keyframe-rebuild`)return Object.keys(e.props)}function gNn(e,t){let n=lNn(e),r=typeof n?.getTime==`function`?n.getTime():typeof t.time==`function`?t.time():0;n?.seek?.(Number.isFinite(r)?r:0)}function _Nn(e){return e.kind===`set`||e.kind===`global-set`?e.props.opacity!==void 0:e.kind===`keyframes`?e.keyframes.some(e=>`opacity`in e):`opacity`in e.props}function vNn(e){let t=typeof e.targets==`function`?e.targets():[];for(let e of t??[]){let t=e;if(!t?.style||typeof t.getAttribute!=`function`)continue;let n=yQt(t);n!==null&&bQt(t.style,n)}}function yNn(e,t){return t.kind===`set`?dNn(e,t.props):t.kind===`keyframes`?fNn(e,t.keyframes):t.kind===`keyframe-rebuild`&&mNn(e,t.pct,t.props)}function bNn(e,t,n,r,i=!1){if(!e)return!1;if(n.kind===`global-set`)return cNn(e,t,n.props);try{let a=I9t(e,t,n.kind===`set`?`set`:`keyframe`,r,hNn(n));if(!a)return!1;let{tween:o,timeline:s}=a;return _Nn(n)&&vNn(o),yNn(o,n)?(n.kind!==`keyframe-rebuild`&&o.invalidate?.(),i||gNn(e,s),!0):!1}catch{return!1}}function xNn(){let e=new Map;return function(t,n){let r=(e.get(t)??Promise.resolve()).then(n,n);return e.set(t,r),r.then(()=>{e.get(t)===r&&e.delete(t)},()=>{e.get(t)===r&&e.delete(t)}),r}}function SNn(e,t){return e.sourceFile||t||`index.html`}function CNn({projectIdRef:e,activeCompPath:t,commitMutation:n,commitMutationSafely:r,showToast:i,sdkSession:a,sdkDeps:o,writeProjectFile:s}){return{updateGsapMeta:(0,U.useCallback)(async(e,n,i)=>{if(!(a&&o&&F6(await z6(e.sourceFile||t||`index.html`,{kind:`set`,animationId:n,properties:i},a,o,{label:`Edit GSAP animation`,coalesceKey:`gsap:${n}:meta`}))))return r(e,{type:`update-meta`,animationId:n,updates:i},{label:`Edit GSAP animation`,coalesceKey:`gsap:${n}:meta`,softReload:!0})},[r,t,a,o]),deleteGsapAnimation:(0,U.useCallback)(async(e,n)=>{if(!(a&&o&&F6(await z6(e.sourceFile||t||`index.html`,{kind:`remove`,animationId:n},a,o,{label:`Delete GSAP animation`}))))return r(e,{type:`delete`,animationId:n,stripStudioEdits:!0},{label:`Delete GSAP animation`,softReload:!0})},[r,t,a,o]),deleteAllForSelector:(0,U.useCallback)(async(e,r)=>{a&&o&&F6(await jdn(e.sourceFile||t||`index.html`,r,a,o,{label:`Delete all animations for element`}))||n(e,{type:`delete-all-for-selector`,targetSelector:r},{label:`Delete all animations for element`,softReload:!0})},[n,t,a,o]),addGsapAnimation:(0,U.useCallback)(async(r,c,l)=>{let u=Zjn(r),{autoId:d}=u,f=u.selector;if(d){let n=e.current;if(!n)return;let a=r.sourceFile||t||`index.html`,o=()=>hMn({projectId:n,targetPath:a,selection:r,autoId:d,showToast:i}),c=await(s?jZ(s,a,o):o());if(!c)return;r.element.setAttribute(`id`,c),f=iJ(c)}let p=Number.parseFloat(r.dataAttributes?.start??`0`)||0,m=Number.parseFloat(r.dataAttributes?.duration??`1`)||1,h=S(p),g=S(m),_={from:{opacity:0},to:{x:0,y:0,opacity:1},set:{opacity:1},fromTo:{x:0,y:0,opacity:1}};if(!d&&r.hfId&&a&&o){let e=r.sourceFile||t||`index.html`,n={method:c,position:h,...c===`set`?{}:{duration:g,ease:`power2.out`},properties:_[c]??{opacity:1},...c===`fromTo`?{fromProperties:{opacity:0}}:{}};if(F6(await z6(e,{kind:`add`,target:r.hfId,spec:n},a,o,{label:`Add GSAP ${c} animation`})))return}await n(r,{type:`add`,targetSelector:f,method:c,position:h,duration:c===`set`?void 0:g,ease:c===`set`?void 0:`power2.out`,properties:_[c]??{opacity:1},fromProperties:c===`fromTo`?{opacity:0}:void 0},{label:`Add GSAP ${c} animation`,softReload:!0})},[t,n,e,i,a,o,s]),addWithKeyframes:(0,U.useCallback)(async(e,r,i,s,c,l,u=`Add animation with keyframes`)=>{a&&o&&F6(await Ldn(e.sourceFile||t||`index.html`,r,i,s,c,l,a,o,{label:u}))||n(e,{type:`add-with-keyframes`,targetSelector:r,position:i,duration:s,keyframes:c,...l?{ease:l}:{}},{label:u,softReload:!0})},[n,t,a,o]),replaceWithKeyframes:(0,U.useCallback)(async(e,r,i,s,c,l,u,d=`Replace animation with keyframes`)=>{a&&o&&F6(await Rdn(e.sourceFile||t||`index.html`,r,i,s,c,l,u,a,o,{label:d}))||n(e,{type:`replace-with-keyframes`,animationId:r,targetSelector:i,position:s,duration:c,keyframes:l,...u?{ease:u}:{}},{label:d,softReload:!0})},[n,t,a,o])}}function wNn(e){return{setArcPath:(0,U.useCallback)((t,n,r)=>{e(t,{type:`set-arc-path`,animationId:n,...r},{label:r.enabled?`Enable arc path`:`Disable arc path`,softReload:!0})},[e]),updateArcSegment:(0,U.useCallback)((t,n,r,i)=>{e(t,{type:`update-arc-segment`,animationId:n,segmentIndex:r,...i},{label:`Update arc segment`,softReload:!0})},[e]),removeArcPath:(0,U.useCallback)((t,n)=>{e(t,{type:`remove-arc-path`,animationId:n},{label:`Remove arc path`,softReload:!0})},[e])}}async function TNn(e){let t=e.apply();try{await e.persist()}catch{e.rollback(t)}}async function ENn(e,t,n,r,i){let a=sJ(e);if(!a)return;let o=fHt(t,n,a);if(o){let n=Qq(t,o);if(n===null)return;o.keyframes&&o.keyframes.keyframes.length>0||await i(e,{type:`convert-to-keyframes`,animationId:o.id},{label:`Convert to keyframes`,keyframeTelemetry:!1,skipReload:!0});let a={};for(let e of Object.keys(r))a[e]=$q[e]??0;await i(e,{type:`add-keyframe`,animationId:o.id,percentage:n,properties:r,backfillDefaults:a},{label:`Add keyframe at ${y(t)}s`,coalesceKey:`keyframe:${o.id}:${n}`,softReload:!0})}else{let n=lJ(e);if(!n)return;await i(e,{type:`add-with-keyframes`,targetSelector:n,position:t,duration:.5,keyframes:[{percentage:0,properties:r},{percentage:100,properties:r}]},{label:`New animation at ${y(t)}s`,softReload:!0})}}function DNn(e){return TNn({apply:()=>{let t=hpn(e.sourceFile,e.elementId);return t&&gpn(e.sourceFile,e.elementId,e.apply(t)),t},persist:e.persist,rollback:t=>{gpn(e.sourceFile,e.elementId,t)}})}function ONn(e,t){return{label:e,coalesceKey:t?.coalesceKey,coalesceMs:t?.coalesceMs,skipRefresh:t?.skipReload}}function kNn({activeCompPath:e,commitMutation:t,commitMutationSafely:n,trackGsapSaveFailure:r,sdkSession:i,sdkDeps:a}){return{addKeyframe:(0,U.useCallback)((n,o,s,c,l)=>{let u=n.sourceFile||e||`index.html`,d={type:`add-keyframe`,animationId:o,percentage:s,properties:{[c]:l}};DNn({sourceFile:u,elementId:n.id,apply:e=>{let t=e.keyframes.findIndex(e=>Math.abs((e.tweenPercentage??e.percentage)-s)<=2);if(t>=0){let n=e.keyframes.slice();return n[t]={...n[t],properties:{...n[t].properties,[c]:l}},{...e,keyframes:n}}return{...e,keyframes:[...e.keyframes,{percentage:s,properties:{[c]:l}}].sort((e,t)=>e.percentage-t.percentage)}},persist:async()=>{if(i&&a){let e=await Odn(u,o,s,{[c]:l},i,a,{label:`Add keyframe at ${s}%`,coalesceKey:`gsap:${o}:kf:${s}`});if(F6(e)){e.before!==e.after&&T8(`add`,c);return}}await t(n,d,{label:`Add keyframe at ${s}%`,keyframeProperty:c,softReload:!0})}}).catch(e=>{r(e,n,d,`Add keyframe at ${s}%`)})},[e,t,r,i,a]),addKeyframeBatch:(0,U.useCallback)(async(n,r,o,s,c)=>{if(i&&a){let t=await Odn(n.sourceFile||e||`index.html`,r,o,s,i,a,ONn(`Add keyframe at ${o}%`,c));if(F6(t)){t.before!==t.after&&c?.keyframeTelemetry!==!1&&T8(`add`);return}}return t(n,{type:`add-keyframe`,animationId:r,percentage:o,properties:s},{label:`Add keyframe at ${o}%`,softReload:!0,...c})},[t,e,i,a]),removeKeyframe:(0,U.useCallback)((n,o,s,c)=>{let l=n.sourceFile||e||`index.html`,u={type:`remove-keyframe`,animationId:o,percentage:s};DNn({sourceFile:l,elementId:n.id,apply:e=>({...e,keyframes:e.keyframes.filter(e=>Math.abs((e.tweenPercentage??e.percentage)-s)>2)}),persist:async()=>{let e=`Remove keyframe at ${s}%`;if(i&&a&&F6(await kdn(l,o,s,i,a,ONn(e,c))))return;let r=c?.skipReload?{label:e,...c}:{label:e,softReload:!0,...c};await t(n,u,r)}}).catch(e=>{r(e,n,u,`Remove keyframe at ${s}%`)})},[e,t,r,i,a]),moveKeyframe:(0,U.useCallback)(async(e,n,i,a)=>{let o={type:`move-keyframe`,animationId:n,fromPercentage:i,toPercentage:a};try{let n=!1;return await t(e,o,{label:`Move keyframe to ${a}%`,softReload:!0,onResult:e=>{n=e.changed!==!1}}),n}catch(t){return r(t,e,o,`Move keyframe to ${a}%`),!1}},[t,r]),resizeKeyframedTween:(0,U.useCallback)(async(e,n,i,a,o)=>{let s={type:`resize-keyframed-tween`,animationId:n,position:i,duration:a,pctRemap:o};try{let n=!1;return await t(e,s,{label:`Retime keyframe (resize tween)`,softReload:!0,onResult:e=>{n=e.changed!==!1}}),n}catch(t){return r(t,e,s,`Retime keyframe (resize tween)`),!1}},[t,r]),convertToKeyframes:(0,U.useCallback)(async(n,r,o,s,c={softReload:!0})=>{if(i&&a){let t=await Ndn(n.sourceFile||e||`index.html`,r,o,i,a,ONn(`Convert to keyframes`,c));if(F6(t)){t.before!==t.after&&c.keyframeTelemetry!==!1&&T8(`convert`);return}}return t(n,{type:`convert-to-keyframes`,animationId:r,resolvedFromValues:o,duration:s},{label:`Convert to keyframes`,...c})},[t,e,i,a]),removeAllKeyframes:(0,U.useCallback)(async(t,r,o=`remove_all`,s=!0)=>{let c=t.sourceFile||e||`index.html`,l=()=>{let e=t.id||t.element?.id;e&&cpn(c,e)};if(i&&a){let e=await Mdn(c,r,i,a,{label:`Remove all keyframes`});if(F6(e)){l();let t=e.before!==e.after;return t&&s&&T8(o),t}}let u=!1;return await n(t,{type:`remove-all-keyframes`,animationId:r},{label:`Remove all keyframes`,keyframeAction:o,keyframeTelemetry:s,softReload:!0,onResult:e=>{u=e.ok&&e.changed===!0,u&&l()}}),u},[n,e,i,a]),commitKeyframeAtTime:(0,U.useCallback)((e,n,r,i)=>ENn(e,n,r,i,t),[t])}}var ANn=150;function $7(e,t,n,r){try{let i=JZ(e.serialize());if(!i)return{...n};let a=p0e(i).animations.find(e=>e.id===t);return a?{...r===`from`?a.fromProperties??{}:a.properties,...n}:{...n}}catch{return{...n}}}function jNn(e,t){let n=(0,U.useRef)(null),r=(0,U.useRef)(null),i=(0,U.useRef)(t);i.current=t;let a=(0,U.useCallback)(async()=>{let t=n.current;if(!t)return;n.current=null;let{selection:r,animationId:a,property:o,value:s}=t,c={type:`update-property`,animationId:a,property:o,value:s},l=`Edit GSAP ${o}`;try{let{sdkSession:t,sdkDeps:n,activeCompPath:u}=i.current??{};if(t&&n&&F6(await z6(r.sourceFile||u||`index.html`,{kind:`set`,animationId:a,properties:{properties:$7(t,a,{[o]:s},`to`)}},t,n,{label:l,coalesceKey:`gsap:${a}:${o}`})))return;await e(r,c,{label:l,coalesceKey:`gsap:${a}:${o}`,softReload:!0})}catch(e){i.current?.onFlushError?.(e,r,c,l)}},[e]),o=(0,U.useCallback)((e,t,i,o)=>{n.current={selection:e,animationId:t,property:i,value:o},r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{a()},ANn)},[a]);(0,U.useEffect)(()=>()=>{r.current&&clearTimeout(r.current),a()},[a]);let s=(0,U.useCallback)(async(t,n,r)=>{let a=$q[r]??0,o=t.element;if(r===`width`||r===`height`){let e=o.getBoundingClientRect();a=Math.round(r===`width`?e.width:e.height)}else if(r===`opacity`||r===`autoAlpha`){let e=o.ownerDocument.defaultView?.getComputedStyle(o),t=e?Number.parseFloat(e.opacity):NaN;a=Number.isFinite(t)?t:1}let{sdkSession:s,sdkDeps:c,activeCompPath:l}=i.current??{};s&&c&&F6(await z6(t.sourceFile||l||`index.html`,{kind:`set`,animationId:n,properties:{properties:$7(s,n,{[r]:a},`to`)}},s,c,{label:`Add GSAP ${r}`}))||e(t,{type:`add-property`,animationId:n,property:r,defaultValue:a},{label:`Add GSAP ${r}`})},[e]),c=(0,U.useCallback)(async(t,n,r,a)=>{let{sdkSession:o,sdkDeps:s,activeCompPath:c}=i.current??{};o&&s&&F6(await Adn(t.sourceFile||c||`index.html`,n,r,a,o,s,{label:`Remove GSAP ${a?`from-${r}`:r}`}))||(a?e(t,{type:`remove-from-property`,animationId:n,property:r},{label:`Remove GSAP from-${r}`}):e(t,{type:`remove-property`,animationId:n,property:r},{label:`Remove GSAP ${r}`}))},[e]);return{updateGsapProperty:o,addGsapProperty:s,removeGsapProperty:(0,U.useCallback)((e,t,n)=>c(e,t,n,!1),[c]),updateGsapFromProperty:(0,U.useCallback)(async(t,n,r,a)=>{let{sdkSession:o,sdkDeps:s,activeCompPath:c}=i.current??{};o&&s&&F6(await z6(t.sourceFile||c||`index.html`,{kind:`set`,animationId:n,properties:{fromProperties:$7(o,n,{[r]:a},`from`)}},o,s,{label:`Edit GSAP from-${r}`,coalesceKey:`gsap:${n}:from:${r}`}))||e(t,{type:`update-from-property`,animationId:n,property:r,value:a},{label:`Edit GSAP from-${r}`,coalesceKey:`gsap:${n}:from:${r}`})},[e]),addGsapFromProperty:(0,U.useCallback)(async(t,n,r)=>{let a=$q[r]??0,{sdkSession:o,sdkDeps:s,activeCompPath:c}=i.current??{};o&&s&&F6(await z6(t.sourceFile||c||`index.html`,{kind:`set`,animationId:n,properties:{fromProperties:$7(o,n,{[r]:a},`from`)}},o,s,{label:`Add GSAP from-${r}`}))||e(t,{type:`add-from-property`,animationId:n,property:r,defaultValue:a},{label:`Add GSAP from-${r}`})},[e]),removeGsapFromProperty:(0,U.useCallback)((e,t,n)=>c(e,t,n,!0),[c])}}function MNn(e){return typeof e.type==`string`?e.type:`gsap`}function NNn(e){return(0,U.useCallback)((t,n,r,i)=>{rX({source:`gsap_commit`,error:t,filePath:n.sourceFile??e??`index.html`,mutationType:MNn(r),label:i,targetId:n.id,targetSelector:n.selector,targetSourceFile:n.sourceFile})},[e])}function PNn(e,t,n){return(0,U.useCallback)((r,i,a)=>e(r,i,a).catch(e=>{t(e,r,i,a.label),n?.(`Couldn't save animation: ${QY(e)}`,`error`)}),[e,t,n])}async function FNn(e,t,n,r){let i=await $Qt(e,t,n,r);if(!i.ok)throw new Qjn(i.status,await tMn(i));let a=await i.json();if(!a.ok)throw Error(`Failed to update GSAP in ${n}`);return a}function INn(e,t,n){t.changed===!1&&e.length===1&&e[0]?.type===`move-keyframe`&&n?.(`A keyframe already exists at that time`,`info`)}async function LNn(e,t,n,r){let i=e.flatMap(e=>fH(e));if(i.length>0){if(n?.(`Couldn't read element layout — try again at a different playhead time`,`error`),t.skipReload)return;throw $Y(Error(`Mutation contains unsafe values: ${i.map(e=>e.path).join(`, `)}`))}try{let t=await r();return INn(e,t,n),t}catch(e){if(e instanceof Qjn&&(n?.(rMn(e),`error`),$Y(e)),t.skipReload)return;throw e}}function RNn(e,t,n,r){return t.changed===!1&&(!n.skipReload&&(GNn(n).length>0||n.previewFallbackLatch?.pending)&&zNn(n,()=>WNn(e,t,n,r)),!0)}function zNn(e,t){e.pendingEdit?e.pendingEdit.drawUnlessUndone(t):t()}function BNn(e,t,n,r,i,a){zNn(n,()=>{n.beforeReload?.(),WNn(e,t,n,r,a)}),i()}function VNn(e,t,n,r){return e.current===n&&t.current===r}function HNn({iframe:e,selection:t,mutation:n,targetPath:r,result:i,options:a,onFileContentChanged:o,forceReloadSdkSession:s,reloadPreview:c,onCacheInvalidate:l,nestedFiles:u}){i.after!=null&&o?.(r,i.after),s?.(),!a.skipReload&&(i.parsed?.animations&&opn(i.parsed.animations,r,t.id??void 0,n,e?.contentDocument),BNn(e,i,a,c,l,u))}function UNn(e,t,n,r,i,a){let o=X.getState().currentTime,s=QZ(e,t,{onAsyncFailure:n,currentTimeOverride:o,authoredHtml:i,nestedFiles:a});s!==`applied`&&(mG(`gsap_soft_reload_outcome`,{origin:r,result:s,escalated:s===`cannot-soft-reload`}),s===`cannot-soft-reload`&&n())}function WNn(e,t,n,r,i){let a=GNn(n),o=a.length===0,s=n.previewFallbackLatch?.pending===!0||o;if(a.length>0){let t=n.deferPreviewSync===!0,r=a.find((n,r)=>!bNn(e,n.selector,n.change,void 0,t||r<a.length-1));if(r&&(mG(`gsap_instant_patch_fallback`,{selector:r.selector}),s=!0),!s)return}if(n.deferPreviewSync&&n.previewFallbackLatch){n.previewFallbackLatch.pending=s;return}n.deferPreviewSync&&!s||(n.previewFallbackLatch&&(n.previewFallbackLatch.pending=!1),n.softReload&&t.scriptText?UNn(e,t.scriptText,r,`preview_sync`,t.after??void 0,i):r())}function GNn(e){return[...e.instantPatches??[],...e.instantPatch?[e.instantPatch]:[]]}function KNn({projectIdRef:e,activeCompPath:t,previewIframeRef:n,editHistory:r,reloadPreview:i,onCacheInvalidate:a,onFileContentChanged:o,showToast:s,sdkSession:c,publishSdkSession:l,writeProjectFile:u,forceReloadSdkSession:d}){let f=e.current,p=(0,U.useRef)(t);p.current=t;let m=(0,U.useRef)(xNn()),h=(0,U.useCallback)(async(e,t,n)=>{t.before!=null&&t.after!=null&&await r.recordEdit({label:n.label,coalesceKey:n.coalesceKey,coalesceMs:n.coalesceMs,files:{[e]:{before:t.before,after:t.after}}})},[r]),g=(0,U.useCallback)(async(t,r,s,c,l,u,f)=>{if(e.current!==t)return;let m=VNn(e,p,t,r);if(u.changed===!1){m&&RNn(n.current,u,f,i);return}await h(l,u,f);let g=await $Z(u.scriptText?eQ(n.current,u.scriptText,e=>NZ(t,e)):null);VNn(e,p,t,r)&&HNn({iframe:n.current,selection:s,mutation:c,targetPath:l,result:u,options:f,onFileContentChanged:o,forceReloadSdkSession:d,reloadPreview:i,onCacheInvalidate:a,nestedFiles:g})},[e,n,i,a,o,d,h]),_=(0,U.useCallback)((e,t,n,r,i,a)=>m2(async()=>{let o=await LNn([i],a,s,()=>FNn(e,`gsap-mutations`,n,i));o&&(Dmn([i],o,a),a.onResult?.(o),await g(e,t,r,i,n,o,a))}),[s,g]),v=(0,U.useCallback)((e,t,n,r,i)=>m2(async()=>{let a=r[0],o=r.at(-1);if(!a||!o)return;let c=r.map(({mutation:e})=>e),l=await LNn(c,i,s,()=>FNn(e,`gsap-mutations-batch`,n,{mutations:c}));if(!l)return;Dmn(c,l,i,r.map(e=>e.options)),i.onResult?.(l);let u=r.flatMap(({options:e})=>e.instantPatch?[e.instantPatch]:[]),{instantPatch:d,...f}=i,p=u.length===r.length;await g(e,t,o.selection,o.mutation,n,l,p?{...f,instantPatches:u}:f)}),[s,g]),y=(0,U.useMemo)(()=>{let e=(e,t)=>u?jZ(u,e,t):m.current(`gsap-file:${e}`,t),n=(t,n,r)=>{let i=`gsap-file:${t}`,a=()=>e(t,r);return n&&(u||n!==i)?m.current(n,a):a()},r=pX((e,r,i)=>{if(!f)return Promise.resolve();let a=SNn(e,t);return n(a,i.serializeKey,()=>_(f,t,a,e,r,i))});return r.batch=pX((e,r)=>{if(!f)return Promise.resolve();let i=e[0]?SNn(e[0].selection,t):`index.html`;return n(i,r.serializeKey,()=>v(f,t,i,e,r))}),r},[_,v,t,f,u]),b=NNn(t),x=(0,U.useCallback)((e,t,n,r)=>{b(e,t,n,r),eX(e)||s?.(`Couldn't save animation: ${QY(e)}`,`error`)},[s,b]),S=PNn(y,x),C=(0,U.useCallback)(e=>{let t=JZ(e);t?UNn(n.current,t,i,`sdk_refresh`,e):i(),a()},[n,i,a]),w=(0,U.useCallback)(e=>{if(!f)throw Error(`No active project`);return NZ(f,e)},[f]),T=(0,U.useMemo)(()=>u?{editHistory:{recordEdit:r.recordEdit},writeProjectFile:u,reloadPreview:i,refresh:C,compositionPath:t,readProjectFile:w,publishSession:l}:null,[r.recordEdit,u,i,C,t,w,l]),E=jNn(S,{sdkSession:c,sdkDeps:T,activeCompPath:t,onFlushError:x}),D=CNn({projectIdRef:e,activeCompPath:t,commitMutation:y,commitMutationSafely:S,showToast:s,sdkSession:c,sdkDeps:T,writeProjectFile:u}),O=kNn({activeCompPath:t,commitMutation:y,commitMutationSafely:S,trackGsapSaveFailure:x,sdkSession:c,sdkDeps:T}),k=wNn(S);return{commitMutation:y,...E,...D,...O,...k}}function qNn({previewIframe:e,activeCompPath:t,captionEditMode:n,domEditSelectionRef:r,domEditGroupSelectionsRef:i,domEditSelection:a,applyDomSelection:o,refreshDomEditGroupSelectionsFromPreview:s,buildDomSelectionFromTarget:c,refreshPreviewDocumentVersion:l,syncPreviewHotkeys:u,applyStudioManualEditsToPreviewRef:d,openSourceForSelection:f,gsapCacheVersion:p}){(0,U.useEffect)(()=>{if(!e)return;let a=async()=>{if(n)return;let a=r.current;if(!a)return;let l=null;try{l=e.contentDocument}catch{return}if(!l)return;a3(l);let u=He(l,a,t);if(!u){let e=i.current;if(K4(`preview-sync-lost`,{target:a.selector??a.id??null,group:e.length}),e.length>1){await s(e);return}o(null,{revealPanel:!1});return}let d=await c(u,{previous:a});d&&o(d,{revealPanel:!1,preserveGroup:!0})};return u(e),d.current(e),a(),l(),g2(e,()=>{u(e),d.current(e),a(),l()})},[t,o,c,n,i,r,e,s,l,u,d,p]);let m=(0,U.useRef)(f);m.current=f,(0,U.useEffect)(()=>{!a||!m.current||a.sourceFile&&W8.getState().visiblePanels.has(`code`)&&m.current(a.sourceFile,{id:a.id,selector:a.selector,selectorIndex:a.selectorIndex})},[a])}var JNn=1,YNn=120,XNn=e=>new Promise(t=>setTimeout(t,e));function ZNn(e){return e.sourceFile||`index.html`}function QNn(e,t,n){return e?{kind:`resolved`,animations:N8(e.animations,t,n)}:{kind:`fetch-error`}}async function $Nn(e,t,n,r,i,a){for(let o=0;;o++){let s=await R8(e,t,{fresh:a});a=!1;let c=QNn(s,n,r);if(c.kind===`resolved`)return c.animations;if(o>=JNn){if(i)throw Error(`GSAP animation ownership could not be verified`);return[]}await XNn(YNn)}}function ePn(e){return(0,U.useCallback)((t,n)=>async()=>{if(!e)return[];let r={id:t.id??null,selector:t.selector??null};return $Nn(e,ZNn(t),r,t.element,n?.failOnFetchError===!0,n?.fresh===!0)},[e])}function tPn({domEditSelection:e,updateGsapProperty:t,updateGsapMeta:n,deleteGsapAnimation:r,deleteAllForSelector:i,addGsapAnimation:a,addGsapProperty:o,removeGsapProperty:s,updateGsapFromProperty:c,addGsapFromProperty:l,removeGsapFromProperty:u,addKeyframe:d,addKeyframeBatch:f,removeKeyframe:p,moveKeyframe:m,resizeKeyframedTween:h,convertToKeyframes:g,removeAllKeyframes:_,handleDomManualEditsReset:v,selectedGsapAnimations:y,showToast:b}){let x=(0,U.useRef)(null);e&&(x.current=e);let S=(0,U.useCallback)(t=>t===void 0?e??x.current:t,[e]),C=(0,U.useCallback)((e,t,n,r)=>{rX({source:`gsap_commit`,error:e,filePath:t.sourceFile??void 0,mutationType:n,label:r,targetId:t.id,targetSelector:t.selector,targetSourceFile:t.sourceFile}),eX(e)||b(`Couldn't save animation: ${QY(e)}`,`error`)},[b]),w=(0,U.useCallback)((e,t,n,r)=>e.then(()=>!0,e=>(C(e,t,n,r),!1)),[C]);return{handleGsapUpdateProperty:(0,U.useCallback)((n,r,i)=>{e&&t(e,n,r,i)},[e,t]),handleGsapUpdateMeta:(0,U.useCallback)((e,t,r)=>{let i=S(r);return i?w(n(i,e,t),i,`update-meta`,`Edit GSAP animation`):Promise.resolve(!1)},[S,w,n]),handleGsapDeleteAnimation:(0,U.useCallback)((e,t)=>{let n=S(t);return n?w(r(n,e),n,`delete`,`Delete GSAP animation`):Promise.resolve(!1)},[S,r,w]),handleGsapDeleteAllForElement:(0,U.useCallback)(t=>{let n=e??x.current;n&&(mG(`keyframe`,{action:`delete_all`}),w(i(n,t),n,`delete-all-for-selector`,`Delete all animations for element`))},[e,i,w]),handleGsapAddAnimation:(0,U.useCallback)((e,t)=>{let n=S(t);if(!n)return Promise.resolve(!1);let r=w(a(n,e,X.getState().currentTime),n,`add`,`Add GSAP ${e} animation`);return n.element.hasAttribute(`data-hf-studio-path-offset`)&&r.then(e=>{e&&v(n).catch(()=>void 0)}),r},[S,a,v,w]),handleGsapAddProperty:(0,U.useCallback)((t,n)=>{e&&w(o(e,t,n),e,`add-property`,`Add GSAP ${n}`)},[e,o,w]),handleGsapRemoveProperty:(0,U.useCallback)((t,n)=>{e&&w(s(e,t,n),e,`remove-property`,`Remove GSAP ${n}`)},[e,w,s]),handleGsapUpdateFromProperty:(0,U.useCallback)((t,n,r)=>{e&&w(c(e,t,n,r),e,`update-from-property`,`Edit GSAP from-${n}`)},[e,w,c]),handleGsapAddFromProperty:(0,U.useCallback)((t,n)=>{e&&w(l(e,t,n),e,`add-from-property`,`Add GSAP from-${n}`)},[e,l,w]),handleGsapRemoveFromProperty:(0,U.useCallback)((t,n)=>{e&&w(u(e,t,n),e,`remove-from-property`,`Remove GSAP from-${n}`)},[e,w,u]),handleGsapAddKeyframe:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);a&&d(a,e,t,n,r)},[S,d]),handleGsapAddKeyframeBatch:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);return a?f(a,e,t,n,r).catch(e=>{C(e,a,`add-keyframe`,`Add keyframe`)}):Promise.resolve()},[S,f,C]),handleGsapRemoveKeyframe:(0,U.useCallback)((e,t,n,r)=>{let i=S(r);i&&(mG(`keyframe`,{action:`remove`}),p(i,e,t,n))},[S,p]),handleGsapMoveKeyframeToPlayhead:(0,U.useCallback)((e,t,n,r)=>{let i=S(n);if(!i)return;let a=_8(i,r??y.find(t=>t.id===e));mG(`keyframe`,{action:`move_to_playhead`}),m(i,e,t,a)},[S,y,m]),handleGsapMoveKeyframe:(0,U.useCallback)((e,t,n,r)=>{let i=S(r);return i?(mG(`keyframe`,{action:`retime`}),m(i,e,t,n)):Promise.resolve(!1)},[S,m]),handleGsapResizeKeyframedTween:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);return a?(mG(`keyframe`,{action:`retime_resize`}),h(a,e,t,n,r)):Promise.resolve(!1)},[S,h]),handleGsapConvertToKeyframes:(0,U.useCallback)((e,t,n,r,i)=>{let a=S(i);return a?g(a,e,t,n,r).catch(e=>{C(e,a,`convert-to-keyframes`,`Convert to keyframes`)}):Promise.resolve()},[S,g,C]),handleGsapRemoveAllKeyframes:(0,U.useCallback)((e,t,n=!0)=>{let r=S(t);return r?_(r,e,`remove_all`,n).catch(e=>(C(e,r,`remove-all-keyframes`,`Remove all keyframes`),!1)):Promise.resolve(!1)},[S,C,_]),handleResetSelectedElementKeyframes:(0,U.useCallback)(()=>{if(!e)return!1;let t=y.find(e=>e.keyframes);return t?(_(e,t.id,`reset`).catch(t=>{C(t,e,`remove-all-keyframes`,`Remove all keyframes`)}),!0):!1},[e,C,_,y])}}function nPn(e){let{projectId:t,activeCompPath:n,domEditSelection:r,domEditSelectionRef:i,domEditGroupSelectionsRef:a,refreshDomEditGroupSelectionsFromPreview:o,previewIframeRef:s,previewIframe:c,captionEditMode:l,refreshKey:u,gsapCacheVersion:d,bumpGsapCache:f,showToast:p,refreshPreviewDocumentVersion:m,syncPreviewHotkeys:h,applyStudioManualEditsToPreviewRef:g,applyDomSelection:_,buildDomSelectionFromTarget:v,openSourceForSelection:y,updateGsapProperty:b,updateGsapMeta:x,deleteGsapAnimation:S,deleteAllForSelector:C,addGsapAnimation:w,addGsapProperty:T,removeGsapProperty:E,updateGsapFromProperty:D,addGsapFromProperty:O,removeGsapFromProperty:k,addKeyframe:A,addKeyframeBatch:j,removeKeyframe:M,moveKeyframe:N,resizeKeyframedTween:P,convertToKeyframes:F,removeAllKeyframes:I,handleDomManualEditsReset:L}=e,R=(0,U.useCallback)(e=>{y&&e.sourceFile&&(W8.getState().activatePanel(`code`),y(e.sourceFile,{id:e.id,selector:e.selector,selectorIndex:e.selectorIndex}))},[y]);(0,U.useEffect)(()=>{if(!r?.id)return;let{selectedElementId:e,elements:t,setSelectedElementId:n}=X.getState(),i=t.find(e=>e.domId===r.id||e.id===r.id),a=i?i.key??i.id:null;a&&a!==e&&n(a)},[r?.id]);let z=(0,U.useRef)(u);(0,U.useEffect)(()=>{u!==z.current&&(z.current=u,f())},[u,f]);let B=r?.sourceFile||n||`index.html`;Vhn(t??null,B,d,s);let{animations:V,multipleTimelines:ee,unsupportedTimelinePattern:te}=zhn(t??null,B,r,d,s),H=Mpn(n,p),ne=ePn(t),re=tPn({domEditSelection:r,updateGsapProperty:b,updateGsapMeta:x,deleteGsapAnimation:S,deleteAllForSelector:C,addGsapAnimation:w,addGsapProperty:T,removeGsapProperty:E,updateGsapFromProperty:D,addGsapFromProperty:O,removeGsapFromProperty:k,addKeyframe:A,addKeyframeBatch:j,removeKeyframe:M,moveKeyframe:N,resizeKeyframedTween:P,convertToKeyframes:F,removeAllKeyframes:I,handleDomManualEditsReset:L,selectedGsapAnimations:V,showToast:p});return qNn({previewIframe:c,activeCompPath:n,captionEditMode:l,domEditSelectionRef:i,domEditGroupSelectionsRef:a,domEditSelection:r,applyDomSelection:_,refreshDomEditGroupSelectionsFromPreview:o,buildDomSelectionFromTarget:v,refreshPreviewDocumentVersion:m,syncPreviewHotkeys:h,applyStudioManualEditsToPreviewRef:g,openSourceForSelection:y,gsapCacheVersion:d}),{onClickToSource:R,selectedGsapAnimations:V,gsapMultipleTimelines:ee,gsapUnsupportedTimelinePattern:te,trackGsapInteractionFailure:H,makeFetchFallback:ne,...re}}function rPn(e,t,n,r){for(let[n,r]of e.entries()){if(r.status!==`rejected`)continue;let e=t[n]?.selection;if(e)return{error:r.reason,selection:e}}return iPn(t,n,r)}function iPn(e,t,n){let r=e.filter(({selection:e})=>!t.has(e)),i=e=>SNn(e,n),a=r[0]&&i(r[0].selection),o=r.find(({selection:e})=>i(e)!==a);return o?{error:new c8(`mixed-files`),selection:o.selection}:null}var aPn=0;function oPn({gsapCommitMutation:e,activeCompPath:t,previewIframeRef:n,makeFetchFallback:r,trackGsapInteractionFailure:i,stageElementPositionOffset:a,showToast:o}){return(0,U.useCallback)(async(s,c={})=>{let l=E8(e),u=l.commit;if(!u)return{ok:!0,changed:!1};let d=s.some(({selection:e,plainTranslate:t})=>!(t??B0(e.element,`move`))),f=async()=>{let e=new Map(s.map(e=>[e.selection,E3(e.selection.element)])),d=c.refusalToast!==!1,f=`group-drag:${++aPn}`,p=!1,m={pending:!1},h=e=>({...e,coalesceKey:f,coalesceMs:1/0,deferPreviewSync:!p,previewFallbackLatch:m}),g=[],_=async()=>{if(g.length===0)return;let e=g.splice(0,g.length);if(!u.batch){for(let t of e)await u(t.selection,t.mutation,t.options);return}await u.batch(e,{...e.at(-1)?.options??{label:`Move animated layer (group)`},label:`Move animated layer (group)`})},v=(e,t,n)=>(g.push({selection:e,mutation:t,options:h(n)}),Promise.resolve()),y=new Map,b=new Map,x=rPn(await Promise.allSettled(s.map(async({selection:e,next:t,plainTranslate:i})=>{if(i??B0(e.element,`move`)){KMn(e.element,d?o:()=>{}),b.set(e,!0);return}let a=await r(e,{failOnFetchError:!0})();y.set(e,a);let s=await I8(e,t,a,n.current,v,void 0,{preflightOnly:!0,group:!0});s.status===`element-offset`&&b.set(e,!1),l8(s)})),s,b,t);if(x)throw i(x.error,x.selection,`drag`,`Move animated layer (group)`,d),x.error;let S=s.findLastIndex(({selection:e})=>!b.has(e));for(let[t,{selection:o,next:c}]of s.entries()){p=t===S;let s=b.get(o);if(s!==void 0){let e=await l.drawKeepingUndone(()=>a(o,c,s,f)).save();l.recordDomResult(e);continue}try{l8(await I8(o,c,y.get(o)??[],n.current,v,async()=>(await _(),r(o,{fresh:!0})()),{preflightPassed:!0,stamp:e.get(o)}))}catch(e){throw i(e,o,`drag`,`Move animated layer (group)`),e}}try{return await _(),l.finish()}catch(e){throw i(e,null,`drag`,`Move animated layer (group)`),e}};return d?m2(f):f()},[e,t,n,r,i,a,o])}function sPn(e,t){let n=[...e,...t],r=n.some(e=>e.propertyGroup===`scale`)?`scale`:`size`;return{allKnownAnimations:n,resizeGroup:r,resizeProperties:r===`scale`?new Set([`scale`,`scaleX`,`scaleY`]):new Set([`width`,`height`]),workingAnimations:e.length>0?e:t}}function cPn(e,t,n,r=[]){let{allKnownAnimations:i,resizeGroup:a,resizeProperties:o,workingAnimations:s}=sPn(t,r),c=d8(i,o);if(c.status===`blocked`)return c;let l=s.some(e=>(e.propertyGroup===a||!e.propertyGroup)&&u8(e,o)),u=sJ(e);return!l&&u&&I0(n,u,void 0,[...o])?{status:`blocked`,reason:`source-uneditable`,detail:`live-resize-no-source-tween`}:{status:`persisted`}}var lPn=0;function uPn(e){if(!e)return[`x`,`y`];let t=Object.keys(e.properties??{});if(t.length>0)return t;let n=e.keyframes?.keyframes;if(n?.length){let e=new Set;for(let t of n)for(let n of Object.keys(t.properties??{}))e.add(n);if(e.size>0)return[...e]}return[`x`,`y`]}function dPn(e,t){let n=Xq(e);return n===null||Yq(t,n,Zq(e))}async function fPn(e,t,n,r,i,a){let o=e9(i,t,n);if(Object.keys(o).length===0)for(let[e,t]of Object.entries(n.properties??{}))typeof t==`number`&&(o[e]=t);if(Object.keys(o).length===0||!e.commitMutation)return;let s=pPn(t.dataAttributes?.start,t.dataAttributes?.duration,r);await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(s.start),duration:S(s.duration),keyframes:[{percentage:0,properties:o}],ease:n.ease},{label:`Enable keyframes`,keyframeAction:`add`,softReload:!0})}function e9(e,t,n){let r={};if(!e?.contentWindow)return r;let i;try{i=e.contentWindow.gsap}catch{return r}let a=t.element;if(!a?.isConnected||!i?.getProperty)return r;let o=uPn(n);for(let e of o){let t=Number(i.getProperty(a,e));Number.isFinite(t)&&(r[e]=hhn.has(e)?Math.round(t):S(t))}return r}function pPn(e,t,n){let r=Math.max(0,S(n)),i=e==null?NaN:Number.parseFloat(e),a=t==null?NaN:Number.parseFloat(t);if(!Number.isFinite(i)||!Number.isFinite(a)||a<=0)return{start:r,duration:1};let o=i+a,s=Math.min(Math.max(r,i),o);return{start:s,duration:Math.max(.5,S(o-s))}}function mPn(e,t,n){let r=lJ(e);if(!r)return null;let{start:i,duration:a}=pPn(e.dataAttributes?.start,e.dataAttributes?.duration,n);return{type:`add-with-keyframes`,targetSelector:r,position:S(i),duration:S(a),keyframes:[{percentage:0,properties:t}]}}async function hPn(e){let t=window.location.hash.match(/project\/([^?/]+)/)?.[1];if(!t)return null;let n=await R8(t,e.sourceFile||`index.html`);return n?N8(n.animations,{id:e.id,selector:e.selector}):null}async function gPn(e){return await hPn(e)??[]}async function _Pn(e,t,n,r,i,a,o){let s=uJ(n,t),c=e9(a,t,n);if(!s||Object.keys(c).length===0||!e.commitMutation)return;let l=yhn(n,r,c,i);await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:s,position:l.position,duration:l.duration,keyframes:l.keyframes,...eJ(n)},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0,...o})}async function vPn(e,t,n,r,i,a,o){let s=n.durationUnresolved===!0;if(s&&(n=c9t(n,o??O0(i,t.element,n))),s&&n.duration==null)return;let c=Zq(n),l=Xq(n);if(l!==null&&!Yq(r,l,c)){if(s)return;await _Pn(e,t,n,r,c,i,a);return}let u=l===null?fJ(r,t):Qq(r,n)??0,d=n.keyframes?.keyframes.find(e=>rJ(n,e.percentage,u));if(d){e.handleGsapRemoveKeyframe(n.id,d.percentage);return}if(e.handleGsapAddKeyframeBatch){let r=e9(i,t,n);Object.keys(r).length>0&&await e.handleGsapAddKeyframeBatch(n.id,u,r,a)}}async function yPn(e,t,n,r,i){let a=uJ(n,t),o=Xq(n)??0;if(!a||!e.commitMutation)return;if(r<=o){await fPn(e,t,n,r,i,a);return}let s=e9(i,t,n);if(Object.keys(s).length===0)return;let c={};for(let e of Object.keys(s)){let t=n.properties?.[e];typeof t==`number`&&(c[e]=t)}await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(o),duration:S(r-o),keyframes:[{percentage:0,properties:Object.keys(c).length>0?c:s,auto:!0},{percentage:100,properties:s}],ease:n.ease},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0})}async function bPn(e,t,n,r,i){if(!e.commitMutation)return;let a=uJ(n,t);if(!a)return;let o=Xq(n)??0,s=Zq(n);if(!Yq(r,o,s)){let c=e9(i,t,n);if(r<=o||typeof c.x!=`number`||typeof c.y!=`number`)return;let l=yhn(n,r,{x:c.x,y:c.y},s,`none`);await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:l.position,duration:l.duration,keyframes:l.keyframes,ease:`none`},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0});return}let c=vhn(n),l=Jq(r,o,s),u=c.findIndex(e=>Math.abs(e.percentage-l)<=nJ);if(u!==-1){u>0&&u<c.length-1&&await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(o),duration:S(s),keyframes:c.filter((e,t)=>t!==u),ease:`none`},{label:`Remove keyframe`,softReload:!0});return}let d=e9(i,t,n);typeof d.x==`number`&&typeof d.y==`number`&&await e.commitMutation({type:`replace-with-keyframes`,animationId:n.id,targetSelector:a,position:S(o),duration:S(s),keyframes:_hn(n,l,{x:d.x,y:d.y}),ease:`none`},{label:`Add keyframe`,keyframeAction:`add`,softReload:!0})}function xPn(e){return(0,U.useCallback)(async()=>{let t=e.current;if(!t)return;let n=t.domEditSelection;if(!n)return;let r=X.getState().currentTime,i=t.previewIframeRef?.current??null,a=await hPn(n)??t.selectedGsapAnimations,o=a.find(e=>e.arcPath),s=a.find(e=>e.keyframes&&!e.arcPath),c=a.find(e=>tJ(e)&&!e.keyframes&&!e.arcPath),l=a.find(e=>!e.keyframes&&!e.arcPath&&!tJ(e));if(o)await bPn(t,n,o,r,i);else if(s)await vPn(t,n,s,r,i);else if(c)await yPn(t,n,c,r,i);else if(l){let e=l.durationUnresolved?O0(i,n.element,l):void 0;lPn+=1;let a=`enable-keyframes:${l.id}:${lPn}`,o={keyframeTelemetry:!1,skipReload:!0,coalesceKey:a,coalesceMs:1/0};await t.handleGsapConvertToKeyframes(l.id,void 0,void 0,o);let s=(await gPn(n)).find(e=>e.keyframes);s&&await vPn(t,n,s,r,i,{softReload:!0,coalesceKey:a,coalesceMs:1/0},e)}else{let e=e9(i,n,null);Object.keys(e).length===0&&Object.assign(e,ton(n.element));let a=mPn(n,e,r);a&&t.commitMutation?await t.commitMutation(a,{label:`Enable keyframes`,softReload:!0}):t.handleGsapAddAnimation(`to`)}},[e])}var SPn=new Set([`width`,`height`]),CPn=new Set([`x`,`y`]),wPn=new Set([`x`,`y`,`xPercent`,`yPercent`,`width`,`height`]);function t9(e,t,n){let r=Number.parseFloat(e?.getAttribute(t)??``);if(Number.isFinite(r)&&r>0)return r;let i=Number.parseFloat(e?.getAttribute(`data-hf-studio-original-${n}`)??``);return Number.isFinite(i)&&i>0?i:null}function TPn(e){let t=t9(e,o0,`width`),n=t9(e,s0,`height`);return{...t!=null&&{width:t},...n!=null&&{height:n}}}async function EPn(e,t,n,r,i,a){let o=sJ(e),s=i&&(i.x!==0||i.y!==0)&&o&&u8(t,CPn)?D3(e.element,i,x8(r,o)??{x:0,y:0},a.stamp):null,c=await A8(e,t,s?{...n,x:s.newX,y:s.newY}:n,r,a,{label:`Resize`,backfill:{...TPn(e.element),...s&&{x:s.baseGsapX,y:s.baseGsapY}},...s&&{beforeReload:()=>O3(e.element,a.stamp)}});return c.status===`persisted`&&s?{...c,ownsDragOffset:!0}:c}function DPn(e,t,n,r){let{width:i,height:a}=n;return t.status!==`persisted`||i==null||a==null||r(()=>{h3(e.element),SQt(e.element,i,a)}),t}function OPn(e,t,n,r,i){let{autoKeyframeEnabled:a}=X.getState(),o=r.some(e=>e.keyframes&&u8(e,wPn));return n!==`size`||!a||!o?null:mPn(e,t,i)}function kPn(e){let t=e=>e===`scaleX`||e===`scaleY`;return(e?.keyframes?.keyframes??[]).some(e=>Object.keys(e.properties??{}).some(t))||Object.keys(e?.properties??{}).some(t)}async function APn(e,t,n,r,i,a,o,s=e=>e(),c){let l=e6(c),u=a?await a():[],d=cPn(e,n,r,u);if(d.status===`blocked`)return d;let{allKnownAnimations:f,resizeGroup:p,resizeProperties:m,workingAnimations:h}=sPn(n,u),g=await F8(p,h,e,i,h.some(e=>!e.propertyGroup)?a:void 0,l.time),_=g?.anim&&u8(g.anim,m)?g.anim:null;if(J3(`intercept-enter`,{hasScaleGroup:p===`scale`,resizeGroup:p,animMethod:_?.method??null,animId:_?.id??null,size:t}),!_||tJ(_)){let n={width:le(t.width),height:le(t.height)};if(!f.some(e=>u8(e,SPn))){let t=OPn(e,n,p,h,l.time);return t?(await i(e,t,{label:`Resize`,softReload:!0}),DPn(e,{status:`persisted`},n,s)):{status:`element-size`}}let u=sJ(e)??lJ(e);if(!u)return{status:`blocked`,reason:`no-selector`};let d=p===`size`?_??Jpn(h,u,e.element):Jpn(h,u,e.element);if(p===`size`){let t=C8(h.filter(e=>!tJ(e)&&Zq(e)>0&&u8(e,m)),l.time);if(t)return J3(`intercept-route`,{route:`keyframed-size`,tweenId:t.id}),DPn(e,await EPn(e,t,n,r,o,{commitMutation:i,fetchAnimations:a,stamp:c}),n,s)}return J3(`intercept-route`,{route:`static-size-set`,hadSizeSet:!!d,resizeGroup:p}),await rmn(e,t,u,d,{commitMutation:i,fetchAnimations:a}),{status:`persisted`}}if(Zq(_)<=0)return{status:`blocked`,reason:`source-uneditable`,detail:`zero-duration-tween`};let{setActiveKeyframePct:v}=X.getState(),y=l.keyframePct,b=y??_8(e,_,l.time),x=sJ(e),C,w,T=null,E=null,D=null,O=!1,k=!1;if(p===`scale`){let e=r?.contentDocument?.querySelector(x??``),n=t9(e,o0,`width`)??200,i=t9(e,s0,`height`)??n,a=mhn(r,x??null,`scaleX`)??1,o=mhn(r,x??null,`scaleY`)??1,c=a>0?a:1,l=o>0?o:1,u=S(t.width*c/n),d=S(t.height*l/i);if(O=Math.abs(u-d)*i>.5,k=O||kPn(_),C=k?{scaleX:u,scaleY:d}:{scale:u},w={scaleX:c,scaleY:l},J3(`intercept-route`,{route:`scale-tween`,cssW:n,cssH:i,liveScaleX:c,liveScaleY:l,newScaleX:u,newScaleY:d,nonUniformScale:O}),T=e,D=k?{x:u,y:d}:{x:u,y:u},e){let t=s(()=>e.getBoundingClientRect());E={x:t.x,y:t.y}}}else C={width:le(t.width),height:le(t.height)},w=TPn(e.element);let A=async()=>{if(!T)return!1;let t=T;if(!E||!x)return s(()=>h3(t)),!1;let o=E,u=s(()=>{h3(t),D&&xQt(t,D.x,D.y);let n=x8(r,x)??{x:0,y:0},{baseGsapX:i,baseGsapY:a}=D3(e.element,{x:0,y:0},n,c),s={x:i,y:a};VZ(t,s.x,s.y);let l=t.getBoundingClientRect(),u={x:o.x-l.x,y:o.y-l.y};if(!Number.isFinite(u.x)||!Number.isFinite(u.y))return null;if(Math.abs(u.x)<.5&&Math.abs(u.y)<.5)return J3(`scale-finalize`,{skipped:`already-on-drop-point`,residual:u,base:s}),`settled`;let d={x:S(s.x+u.x),y:S(s.y+u.y)};return J3(`scale-finalize`,{dropPoint:o,post:{x:l.x,y:l.y},residual:u,gsapPos:n,base:s,corrected:d}),VZ(t,d.x,d.y),{base:s,corrected:d}});if(u===null)return!1;if(u===`settled`)return!0;let{base:d,corrected:f}=u,p=a?await a():g?.animations??n,m={x:f.x-d.x,y:f.y-d.y},h=C8(p.filter(e=>e.propertyGroup===`position`&&!tJ(e)&&Zq(e)>0),l.time);if(h)return J3(`scale-finalize`,{route:`position-keyframe`,tweenId:h.id}),l8(await xhn(e,h,m,d,r,{commitMutation:i,fetchAnimations:a,stamp:c})),!0;let _=Kpn(p,x,e.element);return await tmn(e,m,d,x,_,{commitMutation:i,fetchAnimations:a,stamp:c}),!0};if(!X.getState().autoKeyframeEnabled)return y!=null&&v(null),await j8(e,_,C,b,r,{commitMutation:i,fetchAnimations:a},`Resize animation`),{status:`persisted`,ownsDragOffset:await A()};let j={commitMutation:i,fetchAnimations:a,stamp:c};if(p===`size`)return DPn(e,await EPn(e,_,C,r,o,j),C,s);let M=await A8(e,_,C,r,j,{label:`Resize`,backfill:w});return M.status===`persisted`?{status:`persisted`,ownsDragOffset:await A()}:M}function jPn(e,t,n){let r=n?DT(n):void 0,i=r===void 0?e:e.filter(e=>e.propertyGroup===r);if(i.length===0)return;if(i.length===1)return i[0];let a=X.getState().currentTime,o=i.map(e=>{let n=0;e.keyframes&&(n+=10),t&&e.targetSelector===t?n+=5:e.targetSelector.includes(`,`)&&(n-=3);let r=e.resolvedStart??(typeof e.position==`number`?e.position:0),i=e.duration??0;return a>=r-.05&&a<=r+i+.05&&(n+=8),{anim:e,score:n}});return o.sort((e,t)=>t.score-e.score),o[0]?.anim}async function MPn(e,t,n,r){let i=n.find(e=>e.keyframes&&e.id!==t.id);i&&await r(e,{type:`convert-to-keyframes`,animationId:t.id,duration:i.duration??1},{label:`Keyframe 3D transform`,softReload:!0})}var NPn={position:`Move layer`,scale:`Resize layer`,size:`Resize layer`,rotation:`Rotate layer`,visual:`Set opacity`,other:`Set 3D transform`};function PPn(e){let t=new Set(e.map(([e])=>DT(e))),n=t.size===1?[...t][0]:void 0;return n&&NPn[n]||`Set properties`}async function FPn(e,t,n,r,i,a){let o=IPn(e,t,n,r);await a(o.selection,o.mutation,o.options),await MPn(e,t,i,a)}function IPn(e,t,n,r){let i=Object.fromEntries(n),a={};for(let[e,t]of n)typeof t==`number`&&(a[e]=t);let o=r&&Object.keys(a).length>0?{selector:r,change:{kind:t.global?`global-set`:`set`,props:a}}:void 0;return{selection:e,mutation:{type:`update-properties`,animationId:t.id,properties:i},options:{label:PPn(n),softReload:!0,...o?{instantPatch:o}:{}}}}async function LPn(e,t,n,r,i){let a=zPn(e,t,n,r),o=a[0];if(o){if(a.length===1){await i(o.selection,o.mutation,o.options);return}if(!i.batch)throw Error(`Atomic GSAP property batch is unavailable`);await i.batch(a,{label:PPn(t),softReload:!0})}}function RPn(e){let t=new Map;for(let n of e){let e=DT(n[0]),r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function zPn(e,t,n,r){let i=RPn(t),a=n?r.filter(t=>tJ(t)&&dJ(t.targetSelector,n,e.element)):[],o=new Map,s=[];for(let[e,t]of i){let n=BPn(a,e);n?o.set(n,[...o.get(n)??[],...t]):s.push(t)}return[...[...o].map(([t,r])=>IPn(e,t,r,n)),...s.map(t=>VPn(e,t))]}function BPn(e,t){return e.find(e=>e.propertyGroup===t)??e.find(e=>Object.keys(e.properties).some(e=>DT(e)===t))}function VPn(e,t){let n={};for(let[e,r]of t)typeof r==`number`&&(n[e]=r);let r=lJ(e);if(!r)throw new c8(`no-selector`);return{selection:e,mutation:{type:`add`,targetSelector:r,method:`set`,position:0,properties:Object.fromEntries(t),global:!0},options:{label:PPn(t),softReload:!0,...Object.keys(n).length>0?{instantPatch:{selector:r,change:{kind:`global-set`,props:n}}}:{}}}}async function HPn(e,t,n,r,i,a,o,s){let c=!!t.keyframes;c||await s(e,{type:`convert-to-keyframes`,animationId:t.id},{label:`Convert to keyframes`,keyframeTelemetry:!1,skipReload:!0});let l=X.getState().currentTime,u=a?ghn(o,a,t):{},d={...u,...n},f={...u};for(let[e,t]of r){if(!(e in u)&&a){let t=mhn(o,a,e);t!=null&&(f[e]=t)}f[e]=t}let p=t.keyframes?.keyframes,m=Xq(t),h=Zq(t),g=X.getState().activeKeyframePct!=null,_=m!==null&&h>0&&(l<m-.01||l>m+h+.01);if(c&&p&&_&&!g&&p&&m!==null){let n=Math.min(l,m),r=Math.max(l,m+h),a=Math.max(.01,r-n),o=Hq(t),c=e=>Math.round(Kq(o,(e-n)/a*100)*10)/10,u=p.map(e=>{let t=c(m+qq(o,e.percentage)/100*h),n={...e.properties};for(let e of Object.keys(d))!(e in n)&&f[e]!=null&&(n[e]=f[e]);return{percentage:t,properties:n,...e.ease?{ease:e.ease}:{}}});u.push({percentage:c(l),properties:d}),u.sort((e,t)=>e.percentage-t.percentage),await s(e,{type:`replace-with-keyframes`,animationId:t.id,targetSelector:t.targetSelector,position:S(n),duration:S(a),keyframes:u,...eJ(t)},{label:`Edit ${i} (extended keyframe)`,keyframeAction:`add`,softReload:!0});return}let v=fJ(l,e,t),y=t.keyframes?.keyframes.some(e=>Math.abs(e.percentage-v)<.05),b={};for(let[e,t]of Object.entries(d))typeof t==`number`&&(b[e]=t);let x=a&&Object.keys(b).length>0?{selector:a,change:{kind:`keyframe-rebuild`,pct:v,props:b}}:void 0;await s(e,y?{type:`update-keyframe`,animationId:t.id,percentage:v,properties:d}:{type:`add-keyframe`,animationId:t.id,percentage:v,properties:d,backfillDefaults:f},{label:`Edit ${i} (keyframe ${v}%)`,softReload:!0,...x?{instantPatch:x}:{}})}function UPn(e){let{selectedGsapAnimations:t,gsapCommitMutation:n,previewIframeRef:r,bumpGsapCache:i}=e,a=(0,U.useCallback)(async(e,a,o=n)=>{if(!o)return;let s=Object.entries(a);if(s.length===0)return;let c=s[0][0];l8(d8(t,new Set(s.map(([e])=>e))));let l=r.current,u=sJ(e),d=jPn(t,u,c);if(!d&&!lJ(e))throw new c8(`no-selector`);let f=t.some(e=>!!e.keyframes);try{if(f&&d){if(!X.getState().autoKeyframeEnabled){let t=fJ(X.getState().currentTime,e,d);await j8(e,d,Object.fromEntries(s.filter(e=>typeof e[1]==`number`)),t,l,{commitMutation:o},`Edit ${c} (whole animation)`);return}await HPn(e,d,a,s,c,u,l,o);return}if(!f){await LPn(e,s,u,t,o);return}if(d&&tJ(d)){await FPn(e,d,s,u,t,o);return}let n=lJ(e);if(n){let r=t.find(e=>!!e.keyframes),i=r?Xq(r)??0:0,a=r&&Zq(r)||1,l=X.getState().currentTime,u=a>0?Math.max(0,Math.min(100,Math.round((l-i)/a*1e3)/10)):0,d=Object.fromEntries(s),f=u<=.05?[{percentage:0,properties:d}]:[{percentage:0,properties:{...d,_auto:1}},{percentage:u,properties:d}];await o(e,{type:`add-with-keyframes`,targetSelector:n,position:S(i),duration:S(a),keyframes:f},{label:`Add ${c} keyframe`,softReload:!0});return}throw new c8(`no-selector`)}catch(e){throw i(),e}},[t,n,r,i]);return{commitAnimatedProperty:(0,U.useCallback)((e,t,n)=>a(e,{[t]:n}),[a]),commitAnimatedProperties:a}}function WPn({domEditSelection:e,selectedGsapAnimations:t,gsapCommitMutation:n,activeCompPath:r,previewIframeRef:i,showToast:a,bumpGsapCache:o,makeFetchFallback:s,trackGsapInteractionFailure:c,stageElementPositionOffset:l,handleDomBoxSizeCommit:u,handleDomRotationCommit:d,commitPositionPatchToHtml:f,addGsapAnimation:p,convertToKeyframes:m,setArcPath:h,updateArcSegment:g}){let _=(0,U.useCallback)(n=>e?.element===n.element?t:s(n,{failOnFetchError:!0})(),[e,t,s]),v=(0,U.useCallback)(async(e,t,r)=>{let a=E8(n);if(r?.plainTranslate??B0(e.element,`move`)){let n=await l(e,t,!0).save();return a.finish(n?.changed===!0)}let o=a.commit;if(o)return m2(async()=>{let n=E3(e.element);try{let c=_(e);return await bpn(await I8(e,t,Array.isArray(c)?c:await c,i.current,o,s(e),{...r,stamp:n}),async()=>{let n=a.drawKeepingUndone(()=>l(e,t,!1));a.recordDomResult(await n.save())}),a.finish()}catch(t){throw c(t,e,`drag`,`Move animated layer`),t}})},[n,i,s,c,_,l]),y=oPn({gsapCommitMutation:n,activeCompPath:r,previewIframeRef:i,makeFetchFallback:s,trackGsapInteractionFailure:c,stageElementPositionOffset:l,showToast:a}),b=(0,U.useCallback)(async(e,t,r,a=()=>void 0,o)=>{let d=E8(n);if(o?.plainTranslate??B0(e.element,`resize`)){let n=await u(e,t,r,a);return d.finish(n?.changed===!0)}return m2(async()=>{let n=E3(e.element),o;try{let t=_(e);o=Array.isArray(t)?t:await t}catch(t){throw a(),c(t,e,`resize`,`Resize animated layer`),t}let p=o.some(e=>e.propertyGroup===`scale`),m=sJ(e),h=m?I0(i.current,m,void 0,L0):!1;J3(`commit-route`,{next:t,offset:r??null,scaleRoute:p,animCount:o.length,animGroups:o.map(e=>`${e.propertyGroup}:${e.method}`)});let g=null,v=s6(e.element),y=null,b=async(t,a,c)=>{r&&!t&&await bpn(await I8(e,r,o,i.current,a,s(e),{stamp:n}),async()=>{let t=B0(e.element,`move`);g=d.drawKeepingUndone(()=>l(e,r,t,c))})};return await Upn({element:e.element,label:`Resize layer`,draw:d.drawKeepingUndone,settle:()=>{!r||p||!m||d.drawKeepingUndone(()=>{let t=x8(i.current,m)??{x:0,y:0},{newX:a,newY:o}=D3(e.element,r,t,n);J3(`sync-settle`,{gsapPos:t,offset:r,newX:a,newY:o}),VZ(e.element,a,o)})},persist:async(a,l)=>{if(d.commit){let f=a(d.commit);try{let a=await APn(e,t,o,i.current,f,s(e),r,d.drawKeepingUndone,n);if(l8(a),a.status===`element-size`){let n=await d.drawKeepingUndone(()=>u(e,t,void 0,void 0,l));d.recordDomResult(n)}else y=l;let c=a.status===`persisted`&&a.ownsDragOffset===!0;J3(`intercept-handled`,{scaleRoute:p,ownsDragOffset:c,willForwardOffset:!!(r&&!c)}),await b(c,f,l),hsn(e.element,c?`gsap-scale`:`gsap-size`);return}catch(t){throw c(t,e,`resize`,`Resize animated layer`),t}}throw Error(`Resize of a GSAP-owned box has no GSAP writer`)},afterBufferedCommitsSaved:async()=>{let t=await g?.save();if(d.recordDomResult(t),y){let t=await d.drawKeepingUndone(()=>Qsn(v,e,f,y));d.recordDomResult(t)}},restore:()=>{g?.rollback(),a()},skipPixelAssert:h}),d.finish()})},[u,f,l,n,i,s,c,_]),x=(0,U.useCallback)(async(e,t)=>{let r=E8(n);if(t.plain===void 0?B0(e.element,`rotate`):t.plain){let n=await d(e,t);return r.finish(n?.changed===!0)}let a=r.commit;if(a)return m2(async()=>{let n=E3(e.element);try{let o=await _(e);return l8(await Phn(e,t.angle,o,i.current,a,s(e),n)),r.finish()}catch(t){throw c(t,e,`rotation`,`Rotate animated layer`),t}})},[n,i,s,c,_,d]),{commitAnimatedProperties:S}=UPn({selectedGsapAnimations:t,gsapCommitMutation:n,addGsapAnimation:(e,t,n)=>p(e,t,n),convertToKeyframes:(e,t)=>m(e,t),previewIframeRef:i,bumpGsapCache:o}),C=(0,U.useCallback)(async(e,t)=>{try{await ecn(e,t,n,f,n=>S(e,t,n))}catch(t){throw c(t,e,`property`,`Edit animated property`),t}},[S,f,n,c]),w=(0,U.useCallback)((e,t,n)=>C(e,{[t]:n}),[C]),T=(0,U.useCallback)((t,n)=>{e&&h(e,t,n)},[e,h]),E=(0,U.useCallback)((t,n,r)=>{e&&g(e,t,n,r)},[e,g]),D=(0,U.useCallback)(async()=>{},[]),O=NNn(null),k=PNn(n??D,O,a),A=(0,U.useCallback)(async(t,n,r=e)=>{r&&await k(r,t,n)},[e,k]);return{getGsapAnimationsForSelection:_,handleGsapAwarePathOffsetCommit:v,handleGsapAwareGroupPathOffsetCommit:y,handleGsapAwareBoxSizeCommit:b,handleGsapAwareRotationCommit:x,commitAnimatedProperty:w,commitAnimatedProperties:C,handleSetArcPath:T,handleUpdateArcSegment:E,handleUnroll:(0,U.useCallback)(()=>{A({type:`unroll-timeline`},{label:`Unroll to literal tweens`,softReload:!0})},[A]),commitMutation:A}}function n9(e){return Math.round(e*1e3)/1e3}function GPn({projectId:e,selection:t,currentTime:n}){let r=encodeURIComponent(t.compositionPath||t.sourceFile||`index.html`),i=new URLSearchParams({t:String(n9(n)),format:`png`,output:`source`});return t.selector&&i.set(`selector`,t.selector),t.selectorIndex!=null&&i.set(`selectorIndex`,String(t.selectorIndex)),`/api/projects/${encodeURIComponent(e)}/thumbnail/${r}?${i.toString()}`}function KPn({projectId:e,selection:t,currentTime:n}){return{schemaVersion:1,projectId:e,compositionPath:t.compositionPath,sourceFile:t.sourceFile,currentTime:n9(n),target:{id:t.id,hfId:t.hfId,selector:t.selector,selectorIndex:t.selectorIndex},label:t.label,tagName:t.tagName,boundingBox:{x:n9(t.boundingBox.x),y:n9(t.boundingBox.y),width:n9(t.boundingBox.width),height:n9(t.boundingBox.height)},textContent:t.textContent,dataAttributes:{...t.dataAttributes},inlineStyles:{...t.inlineStyles},computedStyles:{...t.computedStyles},textFields:t.textFields.map(e=>({key:e.key,label:e.label,value:e.value,tagName:e.tagName,source:e.source})),capabilities:{...t.capabilities},thumbnailUrl:GPn({projectId:e,selection:t,currentTime:n})}}function qPn(e){e instanceof Error&&e.name===`AbortError`||(mG(`studio_selection_publish_failed`,{error_name:e instanceof Error?e.name:typeof e,error_message:(e instanceof Error?e.message:String(e)).slice(0,500)}),console.warn(`[Studio] Failed to update agent selection context`,e))}function JPn(e,t,n){return H(`/api/projects/${encodeURIComponent(e)}/selection`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({selection:t}),signal:n}).then(()=>void 0)}function YPn({projectId:e,domEditSelection:t,domEditSelectionRef:n,refreshKey:r,previewDocumentVersion:i,refreshDomEditSelectionFromPreview:a}){let o=(0,U.useRef)(r),s=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!e)return;let n=t?.element.isConnected?KPn({projectId:e,selection:t,currentTime:X.getState().currentTime}):null,r=new AbortController;return JPn(e,n,r.signal).catch(qPn),()=>r.abort()},[t,e]),(0,U.useEffect)(()=>{if(e)return()=>{JPn(e,null).catch(qPn)}},[e]),(0,U.useEffect)(()=>{if(o.current===r||(o.current=r,s.current=n.current?r:null,!e||!n.current))return;let t=new AbortController;return JPn(e,null,t.signal).catch(qPn),()=>t.abort()},[n,e,r]),(0,U.useEffect)(()=>{if(s.current===null)return;s.current=null;let e=n.current;e&&a(e)},[n,i,a])}function XPn({gsapCommitMutation:e,domEditSelectionRef:t}){let n=(0,U.useCallback)((n,r)=>{let i=t.current;if(!i||n.length===0)return;let a={label:n.length===1?`Update keyframe ease`:`Update segment ease`,softReload:!0},o=n.map(({animationId:e,tweenPercentage:t})=>({selection:i,mutation:{type:`update-keyframe`,animationId:e,percentage:t,properties:{},ease:r},options:a}));if(o.length===1){let t=o[0];t&&e(t.selection,t.mutation,t.options);return}let s=e.batch;if(s){s(o,a);return}for(let t of o)e(t.selection,t.mutation,t.options)},[e,t]);return{handleUpdateSegmentEase:n,handleUpdateKeyframeEase:(0,U.useCallback)((e,t,r)=>n([{animationId:e,tweenPercentage:t}],r),[n]),handleSetAllKeyframeEases:(0,U.useCallback)((n,r)=>{let i=t.current;i&&e(i,{type:`update-meta`,animationId:n,updates:{easeEach:r,resetKeyframeEases:!0}},{label:`Apply ease to all segments`,softReload:!0})},[e,t])}}function ZPn(e,t,n,r){let i=N8(t,{id:e.id??null,selector:e.selector??null},e.element);return{offset:Ehn(e,i,n,[],r),size:cPn(e,i,n),rotation:Nhn(e,i,n)}}var QPn=new WeakMap,$Pn=new WeakMap;function eFn(e,t){let n=$Pn.get(e);if(n?.animations===t.animations&&n.iframe===t.iframe&&n.group===t.group&&n.version===t.version)return n;let{animations:r,iframe:i,group:a}=t,o={...t,preflight:ZPn(e,r,i,a)};return $Pn.set(e,o),o}var tFn=e=>QPn.get(e)??e,nFn=[[`canApplyManualOffset`,`offset`],[`canApplyManualSize`,`size`],[`canApplyManualRotation`,`rotation`]];function rFn(e,t){let n=e?.[t];return n?n.status===`blocked`?ypn(n.reason,n.detail):null:``}function iFn(e,t){let n=tFn(e),r={...n.capabilities},i=[];for(let[e,n]of nFn){let a=rFn(t,n);!r[e]||a===null||(r[e]=!1,i.push(a))}if(i.length===0)return n;r.reasonIfDisabled=i.find(Boolean)||r.reasonIfDisabled,t||(r.commitCheckPending=!0);let a={...n,capabilities:r};return QPn.set(a,n),a}function aFn({projectId:e,enabled:t,selection:n,groupSelections:r,previewIframeRef:i,version:a}){let o=(0,U.useRef)(new Map),[s,c]=(0,U.useState)(0);return(0,U.useEffect)(()=>{if(!t||!e)return;let i=n?[n,...r]:r;for(let t of new Set(i.map(ZNn))){let n=Ihn(e,t),r=o.current.get(n);r?.version!==a&&(o.current.set(n,{version:a,animations:r?.animations??null}),R8(e,t).then(e=>{if(o.current.get(n)?.version===a){if(e){o.current.set(n,{version:a,animations:e.animations}),c(e=>e+1);return}r?.animations?o.current.set(n,r):o.current.delete(n)}}))}},[t,e,n,r,a]),(0,U.useMemo)(()=>{if(!t||!e)return{selection:n,groupSelections:r};let s=r.length>1,c=i.current,l=t=>{let n=ZNn(t),r=o.current.get(Ihn(e,n))?.animations;if(!r)return iFn(t,null);let i={animations:r,iframe:c,group:s,version:a},l=eFn(tFn(t),i);return l.narrowed??=iFn(t,l.preflight),l.narrowed};return e9t(()=>({selection:n&&l(n),groupSelections:r.map(l)}))},[t,e,n,r,s,i,a])}function oFn(e,t,n){return n?.expandGroup&&t.length>0?t:[e]}function sFn(e,t){let n=[];for(let r of e){let e=QQ(r,t),i=e?t.find(t=>(t.key??t.id)===e):void 0;if(!i)return null;n.push(i)}return n}function cFn(e){let[t,n]=(0,U.useState)(),r=e&&t?.host===e?t.live:e,i=(0,U.useRef)(r);return i.current=r,(0,U.useEffect)(()=>{if(e)return zen(e.ownerDocument,({retired:t,live:r})=>{t===i.current&&n({host:e,live:r})})},[e]),r}function lFn(e,t){let n=F3(e,{x:0,y:0}),r=F3(e,t);if(!n||!r)throw Error(`The preview has no measurable size.`);return{x:r.x-n.x,y:r.y-n.y}}function uFn(e,t){let{element:n}=e,r=n.getBoundingClientRect(),i=I3({key:e.id??e.selector??e.label,selection:e,element:n,rect:{left:r.left,top:r.top,width:r.width,height:r.height,editScaleX:t.x,editScaleY:t.y},gesture:`drag`});if(!i.ok)throw Error(i.reason);return i.member}async function dFn(e,t){let n=e.filter(({delta:e})=>e.x!==0||e.y!==0);if(n.length===0)return;let r=n.map(({selection:e})=>e);if(!r6(r)){let e=r.find(e=>!e.capabilities.canApplyManualOffset);throw Error(e?.capabilities.reasonIfDisabled??`${e?.label} can't be moved.`)}let i=n.map(({selection:e,delta:t})=>lFn(e.element.ownerDocument,t)),a=[];try{for(let e of r)a.push(uFn(e,lFn(e.element.ownerDocument,{x:1,y:1})))}catch(e){throw V3(a),e}let o=a.map((e,t)=>({selection:e.selection,next:B3(e,i[t].x,i[t].y),plainTranslate:e.plainTranslate}));try{await q0(a[0].element,()=>t(o))}catch(e){for(let e of a)J0(e.element,e.gestureToken)&&p3(e.element,e.initialPathOffset);throw e}finally{H3(a)}}function fFn({projectId:e,activeCompPath:t,compIdToSrc:n,captionEditMode:r,compositionLoading:i,previewIframeRef:a,timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:c,setTimelineSelectionSet:l,setRightCollapsed:u,setRightPanelTab:d,showToast:f,isRecordingRef:p,refreshPreviewDocumentVersion:m,queueDomEditSave:h,readProjectFile:g,writeProjectFile:_,updateEditingFileContent:v,editHistory:y,fileTree:b,importedFontAssetsRef:x,projectDir:S,projectIdRef:C,previewIframe:w,refreshKey:T,previewDocumentVersion:E,rightPanelTab:D,applyStudioManualEditsToPreviewRef:O,syncPreviewHotkeys:k,reloadPreview:A,openSourceForSelection:j,sdkSession:M,publishSdkSession:N,forceReloadSdkSession:P,handleTimelineElementsDelete:F,readOnlyPreview:I}){let L=!t||t===`index.html`,R=r&&!I,z=cFn(w),{domEditSelection:B,domEditGroupSelections:V,domEditHoverSelection:ee,activeGroupElement:te,domEditSelectionRef:H,domEditGroupSelectionsRef:ne,setActiveGroupElement:re,applyDomSelection:ie,clearDomSelection:ae,buildDomSelectionFromTarget:oe,resolveDomSelectionFromPreviewPoint:se,resolveAllDomSelectionsFromPreviewPoint:ce,updateDomEditHoverSelection:le,buildDomSelectionForTimelineElement:ue,handleTimelineElementSelect:de,refreshDomEditSelectionFromPreview:fe,refreshDomEditGroupSelectionsFromPreview:pe,applyMarqueeSelection:me}=zjn({projectId:e,activeCompPath:t,isMasterView:L,compIdToSrc:n,captionEditMode:R,previewIframeRef:a,timelineElements:o,getTimelineSelectionSet:s,setSelectedTimelineElementId:c,setTimelineSelectionSet:l,setRightCollapsed:u,setRightPanelTab:d,previewIframe:z,refreshKey:T,rightPanelTab:D}),{agentModalOpen:he,agentModalAnchorPoint:ge,copiedAgentPrompt:_e,agentPromptSelectionContext:ve,setAgentModalOpen:ye,setAgentPromptSelectionContext:be,setAgentModalAnchorPoint:xe,handleAskAgent:Se,handleAgentModalSubmit:Ce}=wjn({projectId:e,activeCompPath:t,projectDir:S,projectIdRef:C,showToast:f,domEditSelectionRef:H,domEditSelection:B});YPn({projectId:e,domEditSelection:B,domEditSelectionRef:H,refreshKey:T,previewDocumentVersion:E,refreshDomEditSelectionFromPreview:fe});let{version:we,bump:Te}=Bhn(),{commitMutation:Ee,setArcPath:De,updateArcSegment:Oe,...ke}=KNn({projectIdRef:C,activeCompPath:t,previewIframeRef:a,editHistory:y,reloadPreview:A,onCacheInvalidate:Te,onFileContentChanged:v,showToast:f,sdkSession:M,publishSdkSession:N,writeProjectFile:_,forceReloadSdkSession:P}),{resolveImportedFontAsset:Ae,handleDomStyleCommit:je,handleDomStyleCommitForSelection:Me,handleDomAttributeCommit:Ne,handleDomAttributeLiveCommit:Pe,handleDomAttributeQuietCommit:Fe,handleDomHtmlAttributeCommit:Ie,handleDomAttributesCommit:Le,handleDomAttributeBatchCommit:Re,handleDomTextCommit:ze,handleDomTextCommitForSelection:Be,handleDomRichTextCommit:Ve,handleDomTextFieldStyleCommit:He,handleDomAddTextField:Ue,handleDomRemoveTextField:We,stageElementPositionOffset:Ge,commitPositionPatchToHtml:Ke,handleDomBoxSizeCommit:qe,handleDomRotationCommit:Je,handleDomManualEditsReset:Ye,handleDomEditElementsDelete:Xe,handleDomZIndexReorderCommit:Ze}=eNn({activeCompPath:t,previewIframeRef:a,showToast:f,queueDomEditSave:h,writeProjectFile:_,editHistory:y,fileTree:b,importedFontAssetsRef:x,projectId:e,projectIdRef:C,reloadPreview:A,domEditSelection:B,applyDomSelection:ie,clearDomSelection:ae,refreshDomEditSelectionFromPreview:fe,buildDomSelectionFromTarget:oe,forceReloadSdkSession:P,readOnlyPreview:I,onTrySdkPersist:M?(e,n,r,i,a)=>(Lun(M,e.hfId,n,r,{targetPath:i,compositionPath:t}),Tdn(e,n,r,i,M,{editHistory:y,writeProjectFile:_,reloadPreview:A,compositionPath:t,readProjectFile:g,publishSession:N},a)):void 0,onTrySdkDelete:M?(e,n,r)=>zdn(e,n,r,M,{editHistory:y,writeProjectFile:_,reloadPreview:A,compositionPath:t,readProjectFile:g,publishSession:N}):void 0,onReorderShadow:M?e=>{let n,r=t?()=>n??=g(t):void 0;for(let t of e)k6(M,t,`reorderElements`,r)}:void 0}),{groupSelection:Qe,ungroupSelection:$e}=aNn({activeCompPath:t,showToast:f,writeProjectFile:_,editHistory:y,projectIdRef:C,reloadPreview:A,clearDomSelection:ae,forceReloadSdkSession:P,timelineElements:o}),et=(0,U.useCallback)(async(e,t)=>{if(p?.current){f(`Cannot edit timeline while recording`,`error`);return}let n=oFn(e,ne.current,t),r=sFn(n,o);if(r){await F(r);return}await Xe(n)},[ne,Xe,F,p,f,o]),tt=(0,U.useCallback)(()=>{let e=ne.current,t=H.current,n=e.length>0?e:t?[t]:[];if(n.length<2){f(`Select at least 2 elements to group`,`info`);return}if(n.some(e=>CG(e.element))){f(n.every(e=>CG(e.element))?`Audio clips group into a bus — use FX on the track header`:`Can't group audio clips with layout elements`,`info`);return}mG(`group`,{action:`create`,count:n.length}),Qe(n)},[ne,H,Qe,f]),nt=(0,U.useCallback)(()=>{let e=H.current;if(!e?.element.hasAttribute(`data-hf-group`)){f(`Select a group to ungroup`,`info`);return}mG(`group`,{action:`ungroup`}),re(null),$e(e)},[H,$e,re,f]),{onClickToSource:rt,selectedGsapAnimations:it,gsapMultipleTimelines:at,gsapUnsupportedTimelinePattern:ot,trackGsapInteractionFailure:st,makeFetchFallback:ct,handleGsapUpdateProperty:lt,handleGsapUpdateMeta:ut,handleGsapDeleteAnimation:dt,handleGsapDeleteAllForElement:ft,handleGsapAddAnimation:pt,handleGsapAddProperty:mt,handleGsapRemoveProperty:ht,handleGsapUpdateFromProperty:gt,handleGsapAddFromProperty:_t,handleGsapRemoveFromProperty:vt,handleGsapAddKeyframe:yt,handleGsapAddKeyframeBatch:bt,handleGsapRemoveKeyframe:xt,handleGsapMoveKeyframeToPlayhead:St,handleGsapMoveKeyframe:Ct,handleGsapResizeKeyframedTween:wt,handleGsapConvertToKeyframes:Tt,handleGsapRemoveAllKeyframes:Et,handleResetSelectedElementKeyframes:Dt}=nPn({projectId:e,activeCompPath:t,domEditSelection:B,domEditSelectionRef:H,domEditGroupSelectionsRef:ne,refreshDomEditGroupSelectionsFromPreview:pe,previewIframeRef:a,previewIframe:z,captionEditMode:R,refreshKey:T,gsapCacheVersion:we,bumpGsapCache:Te,showToast:f,refreshPreviewDocumentVersion:m,syncPreviewHotkeys:k,applyStudioManualEditsToPreviewRef:O,applyDomSelection:ie,buildDomSelectionFromTarget:oe,openSourceForSelection:j,...ke,handleDomManualEditsReset:Ye}),{handlePreviewCanvasMouseDown:Ot,handlePreviewCanvasPointerMove:kt,handlePreviewCanvasPointerLeave:At,handleBlockedDomMove:jt,handleDomManualDragStart:Mt}=Wjn({captionEditMode:R,compositionLoading:i,previewIframeRef:a,showToast:f,applyDomSelection:ie,resolveDomSelectionFromPreviewPoint:se,resolveAllDomSelectionsFromPreviewPoint:ce,updateDomEditHoverSelection:le,setActiveGroupElement:re,onClickToSource:rt}),{getGsapAnimationsForSelection:Nt,handleGsapAwarePathOffsetCommit:Pt,handleGsapAwareGroupPathOffsetCommit:Ft,handleGsapAwareBoxSizeCommit:It,handleGsapAwareRotationCommit:Lt,commitAnimatedProperty:Rt,commitAnimatedProperties:zt,handleSetArcPath:Bt,handleUpdateArcSegment:Vt,handleUnroll:Ht,commitMutation:Ut}=WPn({domEditSelection:B,selectedGsapAnimations:it,gsapCommitMutation:Ee,activeCompPath:t,previewIframeRef:a,showToast:f,bumpGsapCache:Te,makeFetchFallback:ct,trackGsapInteractionFailure:st,stageElementPositionOffset:Ge,handleDomBoxSizeCommit:qe,handleDomRotationCommit:Je,commitPositionPatchToHtml:Ke,addGsapAnimation:ke.addGsapAnimation,convertToKeyframes:ke.convertToKeyframes,setArcPath:De,updateArcSegment:Oe}),Wt=(0,U.useCallback)(e=>dFn(e,e=>Ft(e,{refusalToast:!1})),[Ft]),{handleUpdateSegmentEase:Gt,handleUpdateKeyframeEase:Kt,handleSetAllKeyframeEases:qt}=XPn({gsapCommitMutation:Ee,domEditSelectionRef:H}),Jt=aFn({projectId:e,enabled:Ee!==null,selection:B,groupSelections:V,previewIframeRef:a,version:we});return{domEditSelection:Jt.selection,domEditGroupSelections:Jt.groupSelections,domEditHoverSelection:ee,activeGroupElement:te,agentModalOpen:he,agentModalAnchorPoint:ge,copiedAgentPrompt:_e,agentPromptSelectionContext:ve,domEditSelectionRef:H,handleTimelineElementSelect:de,handlePreviewCanvasMouseDown:Ot,handlePreviewCanvasPointerMove:kt,handlePreviewCanvasPointerLeave:At,applyDomSelection:ie,clearDomSelection:ae,refreshDomEditSelectionFromPreview:fe,handleDomStyleCommit:je,handleDomStyleCommitForSelection:Me,handleDomAttributeCommit:Ne,handleDomAttributeLiveCommit:Pe,handleDomAttributeQuietCommit:Fe,handleDomHtmlAttributeCommit:Ie,handleDomAttributesCommit:Le,handleDomAttributeBatchCommit:Re,handleDomPathOffsetCommit:Pt,handleDomGroupPathOffsetCommit:Ft,handleDomGroupMoveBy:Wt,handleDomZIndexReorderCommit:Ze,handleDomBoxSizeCommit:It,handleDomRotationCommit:Lt,handleDomManualEditsReset:Ye,handleDomTextCommit:ze,handleDomTextCommitForSelection:Be,handleDomRichTextCommit:Ve,handleDomTextFieldStyleCommit:He,handleDomAddTextField:Ue,handleDomRemoveTextField:We,getGsapAnimationsForSelection:Nt,handleAskAgent:Se,handleAgentModalSubmit:Ce,handleBlockedDomMove:jt,handleDomManualDragStart:Mt,handleDomEditElementDelete:et,handleGroupSelection:tt,handleUngroupSelection:nt,setActiveGroupElement:re,buildDomSelectionFromTarget:oe,buildDomSelectionForTimelineElement:ue,updateDomEditHoverSelection:le,applyMarqueeSelection:me,resolveImportedFontAsset:Ae,setAgentModalOpen:ye,setAgentPromptSelectionContext:be,setAgentModalAnchorPoint:xe,selectedGsapAnimations:it,gsapMultipleTimelines:at,gsapUnsupportedTimelinePattern:ot,handleGsapUpdateProperty:lt,handleGsapUpdateMeta:ut,handleGsapDeleteAnimation:dt,handleGsapDeleteAllForElement:ft,handleGsapAddAnimation:pt,handleGsapAddProperty:mt,handleGsapRemoveProperty:ht,handleGsapUpdateFromProperty:gt,handleGsapAddFromProperty:_t,handleGsapRemoveFromProperty:vt,handleGsapAddKeyframe:yt,handleGsapAddKeyframeBatch:bt,handleGsapRemoveKeyframe:xt,handleGsapMoveKeyframeToPlayhead:St,handleGsapMoveKeyframe:Ct,handleGsapResizeKeyframedTween:wt,handleGsapConvertToKeyframes:Tt,handleGsapRemoveAllKeyframes:Et,handleResetSelectedElementKeyframes:Dt,handleUpdateKeyframeEase:Kt,handleUpdateSegmentEase:Gt,handleSetAllKeyframeEases:qt,commitAnimatedProperty:Rt,commitAnimatedProperties:zt,handleSetArcPath:Bt,handleUpdateArcSegment:Vt,handleUnroll:Ht,invalidateGsapCache:Te,previewIframeRef:a,commitMutation:Ut}}function pFn(e,t){return(e.length>0?e:t?[t]:[]).flatMap(e=>e.hfId?[e.hfId]:[])}function mFn(e,t,n){(0,U.useEffect)(()=>{e&&e.setSelection(pFn(n,t))},[e,t,n])}var hFn=new Set;function gFn(e){return hFn.add(e),()=>hFn.delete(e)}function _Fn(e){for(let t of hFn)try{t(e)}catch{}}var vFn=new Set([`absent_or_empty`,`absent`,`empty_file`]);function yFn(e,t,n){return mG(`sdk_session_unavailable`,{stage:`read`,reason:e.reason,...e.reason===`http_error`?{status:e.status,why:e.why}:{},...e.reason===`network`?{elapsed_ms:e.elapsedMs,hidden:e.hidden}:{},...e.reason===`invalid_json`?{content_type:e.contentType}:{},...vFn.has(e.reason)?{path_in_tree:n}:{}}),e.reason===`http_error`&&e.status===404?t:null}function bFn(e){return{ok:!1,reason:`network`,elapsedMs:Math.round(performance.now()-e),hidden:typeof document<`u`&&document.visibilityState===`hidden`}}async function xFn(e){let t=await e.json().catch(()=>null);return typeof t?.why==`string`?t.why:void 0}function SFn(e){return typeof e.content==`string`?e.content===``?e.missing===!0?{ok:!1,reason:`absent`}:e.missing===!1?{ok:!1,reason:`empty_file`}:{ok:!1,reason:`absent_or_empty`}:{ok:!0,content:e.content}:{ok:!1,reason:`missing_content`}}async function CFn(e,t){if(t.includes(`\0`)||t.includes(`..`))return{ok:!1,reason:`unsafe_path`};let n,r=performance.now();try{n=await H(`/api/projects/${encodeURIComponent(e)}/files/${encodeURIComponent(t)}?optional=1`)}catch{return bFn(r)}if(!n.ok){let e=await xFn(n);return{ok:!1,reason:`http_error`,status:n.status,...e?{why:e}:{}}}let i;try{i=await n.json()}catch{return{ok:!1,reason:`invalid_json`,contentType:n.headers.get(`content-type`)??``}}return SFn(i)}function wFn(e,t,n,r){return e?e.projectId===t&&e.path===n&&e.path===r:!1}function TFn(e,t,n,r,i){return e.generation===t&&e.projectId===n&&e.path===r&&e.reloadToken===i}function EFn(e,t,n,r){return e?e.session===n&&e.generation===t.generation&&e.reloadToken===r:!1}function r9(e){try{e.dispose()}catch(e){mG(`sdk_session_dispose_failed`,{error:e instanceof Error?e.message:String(e)})}}function DFn(e,t,n=[],r=!1,i){let[a,o]=(0,U.useState)(null),s=(0,U.useRef)(null),c=(0,U.useRef)(new WeakMap),l=(0,U.useRef)(0),u=(0,U.useRef)(e);u.current=e;let d=(0,U.useRef)(t);d.current=t;let[f,p]=(0,U.useState)(0),m=(0,U.useRef)(f);m.current=f;let[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(!1),y=(0,U.useRef)(new Set);(0,U.useEffect)(()=>{y.current.clear()},[e]);function b(e,t,a){let o=r?n.includes(a):null;if(g(yFn(e,t,o)),v(e.reason===`absent`),e.reason!==`absent`)return;let s=`${t}:${a}`;y.current.has(s)||(y.current.add(s),i?.(a))}(0,U.useEffect)(()=>gFn(e=>{(e===`.`||e===d.current)&&p(e=>e+1)}),[]),(0,U.useEffect)(()=>{let n=++l.current,r=!1,i=s.current;if(s.current=null,o(null),i&&r9(i.session),!e||!t)return g(null),v(!1),()=>{r=!0};let a={projectId:e,path:t,reloadToken:f,generation:n};return ix(e).then(n=>r||!n?null:CFn(e,t)).then(async n=>{if(!n||r)return;if(!n.ok){b(n,e,t);return}g(null),v(!1);let i=n.content,f=await Qj(i,{history:!1});if(r){r9(f);return}if(!TFn(a,l.current,u.current,d.current,m.current)){r9(f),mG(`sdk_session_superseded`,{});return}let p=s.current,h={...a,session:f};c.current.set(f,a),s.current=h,o(h),p&&p.session!==f&&r9(p.session)}).catch(e=>{!r&&l.current===n&&(o(null),mG(`sdk_session_unavailable`,{stage:`open`,error:e instanceof Error?e.message:String(e)}))}),()=>{r=!0;let e=s.current;e?.generation===n&&(s.current=null,r9(e.session))}},[e,t,f]);let x=(0,U.useCallback)(()=>p(e=>e+1),[]),S=(0,U.useCallback)(({candidate:e,expectedSession:t,targetPath:n})=>{let r=c.current.get(t),i=s.current;if(!wFn(r,u.current,d.current,n))return`rejected-inactive-target`;if(!EFn(i,r,t,m.current))return p(e=>e+1),`rejected-active-target`;let a={...i,session:e};return c.current.set(e,i),s.current=a,o(a),i.session!==e&&r9(i.session),`published`},[]);return{session:a?.projectId===e&&a.path===t&&a.reloadToken===f?a.session:null,publish:S,forceReload:x,unreachableProject:h,compositionMissing:_}}function OFn(e,t,n,r=[],i=!1,a){let o=DFn(e,t??n,r,i,a),s=t?o.session:null;return(0,U.useEffect)(()=>{ox.getState().setValues(null)},[e,t]),{sdkHandle:N7(o,e),editFlowSdkSession:s}}var kFn=`hyperframes-studio-external-conflicts`,AFn=1,i9=`file-conflicts`;function jFn(e,t){return`${e}\0${t}`}function MFn(){return new Promise((e,t)=>{if(!globalThis.indexedDB){t(Error(`IndexedDB is unavailable; conflict recovery snapshot was not saved`));return}let n=globalThis.indexedDB.open(kFn,AFn);n.onupgradeneeded=()=>{n.result.objectStoreNames.contains(i9)||n.result.createObjectStore(i9)},n.onerror=()=>t(n.error??Error(`Failed to open conflict storage`)),n.onsuccess=()=>e(n.result)})}function NFn(e,t){return MFn().then(n=>new Promise((r,i)=>{let a=n.transaction(i9,e),o=t(a.objectStore(i9)),s;o.onerror=()=>i(o.error??Error(`Conflict storage failed`)),o.onsuccess=()=>{s=o.result},a.oncomplete=()=>{n.close(),r(s)},a.onerror=()=>{n.close(),i(a.error??Error(`Conflict storage transaction failed`))},a.onabort=()=>{n.close(),i(a.error??Error(`Conflict storage transaction was aborted`))}}))}function PFn(){return{async get(e,t){return await NFn(`readonly`,n=>n.get(jFn(e,t)))??null},async set(e){await NFn(`readwrite`,t=>t.put(e,jFn(e.projectId,e.filePath)))},async delete(e,t){await NFn(`readwrite`,n=>n.delete(jFn(e,t)))}}}var a9=PFn();async function FFn(e,t){await a9.set({kind:`conflict`,projectId:e,filePath:t.filePath,externalVersion:t.currentVersion,externalContent:t.currentContent,studioContent:t.attemptedContent,createdAt:Date.now()})}async function IFn(e,t,n,r,i,a){await a9.set({kind:`failed`,projectId:e,filePath:t,externalVersion:r,externalContent:i,studioContent:n,failureMessage:a instanceof Error?a.message:String(a),createdAt:Date.now()})}async function LFn(e,t){return a9.get(e,t)}async function RFn(e,t){await a9.delete(e,t)}function zFn(){let e=globalThis.__HF_STUDIO_HOT_TEST_ADAPTER__;if(!e||typeof e!=`object`)return null;let t=e;return typeof t.on==`function`&&typeof t.off==`function`?t:null}var o9=e=>Z4(e,`content`),BFn=e=>Z4(e,`version`),VFn=e=>Z4(e,`writeToken`);function HFn(e){let t=e?.data;if(typeof t!=`string`)return e;try{return JSON.parse(t)}catch{return s2(`file-change`,{path:null,why:`unparseable payload`}),null}}function UFn(e,t){let n=new EventSource(`/api/events`);n.addEventListener(`file-change`,e);let r=!1;return n.addEventListener(`open`,()=>{r&&t(),r=!0}),()=>n.close()}function WFn(e,t){let n=BFn(t);if(n)return`${e}\0${n}`;let r=o9(t);return r==null?null:`${e}\0${r.length}\0${r}`}function GFn({projectId:e,activeCompPath:t,recoveryFilePath:n=t,pendingTimelineEditPathRef:r,drainPendingChanges:i,getPendingCandidate:a,discardPendingChanges:o,reloadPreview:s,reloadSdkSession:c,persistConflictSnapshot:l,persistFailureSnapshot:u,loadConflictSnapshot:d,deleteConflictSnapshot:f,overwriteConflict:p,readProjectFile:m,onUseExternalFile:h,resetSaveQueues:g,onAcceptedPersistedFileChange:_,refreshFileTree:v}){let[y,b]=(0,U.useState)(null),x=(0,U.useRef)(0),S=(0,U.useRef)(!0),C=(0,U.useRef)(null),w=(0,U.useRef)(null),T=(0,U.useRef)(Promise.resolve()),E=(0,U.useRef)(!1),D=(0,U.useRef)(null),O=(0,U.useCallback)(e=>{let t=w.current,n=e&&t?{...e,payload:t3(t.payload,e.payload)}:e;w.current=n,b(n)},[]);(0,U.useEffect)(()=>(S.current=!0,()=>{S.current=!1,x.current+=1}),[]),(0,U.useEffect)(()=>{D.current=null},[e]),(0,U.useEffect)(()=>{x.current+=1,O(null),C.current=null},[e,t,O]),(0,U.useEffect)(()=>{if(!e||!n||!d)return;let t=++x.current,r=!1;return d(e,n).then(e=>{if(r||!e||!S.current||t!==x.current)return;let n={path:e.filePath,version:e.externalVersion,content:e.externalContent};if(e.kind===`failed`)O({status:`failed`,generation:t,path:e.filePath,error:Error(e.failureMessage),payload:n,studioContent:e.studioContent,recovered:!0});else{let r=new XY({filePath:e.filePath,currentVersion:e.externalVersion,currentContent:e.externalContent,attemptedContent:e.studioContent});O({status:`conflict`,generation:t,error:r,payload:n})}}).catch(()=>{}),()=>{r=!0}},[d,e,n,O]);let k=(0,U.useCallback)((e,t=!0)=>{let n=Q4(e)??`.`,r=$4(e);t&&_(n,e3(e)),s2(r?`reload`:`file-tree only`,{path:n,by:`external-change coordinator`}),r&&s(),c(n),v?.()},[_,s,c,v]),A=(0,U.useCallback)(async e=>{let t=T.current.catch(()=>void 0).then(e);T.current=t.then(()=>void 0,()=>void 0),await t},[]),j=(0,U.useCallback)(async t=>{let r=Q4(t);if(!r)return;let o=++x.current,s=a?.()?.path,c=await i();if(!(!S.current||o!==x.current)){if(c.status===`clean`){let n=w.current;if(n?.status===`failed`&&!n.recovered&&n.path===s&&f)try{await f(e,n.path)}catch(e){S.current&&o===x.current&&O({...n,generation:o,error:e,payload:t3(t,n.payload)});return}if(!S.current||o!==x.current)return;O(null);let r=n?.status===`failed`&&n.recovered;k(n&&!r?t3(n.payload,t):t);return}if(c.status===`failed`){let i=a?.(),s=i?.path??(r===`.`?n??r:r),l=i?.content??null,d=s===r?t:null,f=c.error;if(l!=null&&u)try{await A(()=>u(e,s,l,BFn(d),o9(d),c.error))}catch(e){f=Error(`Studio could not save the edit or its recovery snapshot: ${e instanceof Error?e.message:String(e)}`,{cause:c.error})}if(!S.current||o!==x.current)return;O({status:`failed`,generation:o,path:s,error:f,payload:t,studioContent:l,recovered:!1});return}try{await A(()=>l(e,c.error))}catch(e){if(!S.current||o!==x.current)return;O({status:`failed`,generation:o,path:c.error.filePath,error:e,payload:t,studioContent:c.error.attemptedContent,recovered:!1});return}!S.current||o!==x.current||O({status:`conflict`,generation:o,error:c.error,payload:t})}},[i,O,e,f,a,n,l,u,A,k]),M=(0,U.useRef)(j);M.current=j;let N=(0,U.useCallback)(async()=>{if(!E.current){E.current=!0;try{for(;S.current;){let e=D.current;if(!e)break;D.current=null,await M.current(e.payload)}}finally{E.current=!1}}},[]),P=(0,U.useCallback)(t=>{let n=Q4(t);if(!n||!e){s2(`file-change`,{path:null,why:n?`no project`:`no path in payload`});return}let i=Z4(t,`projectId`);if(i&&i!==e){s2(`suppressed`,{path:n,why:`other project`});return}r.current.delete(n);let a=o9(t),o=VFn(t);s2(`file-change`,{path:n,token:o??null,hasContent:a!=null});let s=WFn(n,t);if(s!=null&&s===C.current){s2(`suppressed`,{path:n,why:`duplicate event`});return}C.current=s;let c=GQt(o),l=a!=null&&ldn(n,a);if(c||l){_(n,e3(t)),s2(`suppressed`,{path:n,why:c?`own write token`:`own content echo`});return}let u=D.current?.payload;u!=null&&$4(u)&&!$4(t)||(D.current={payload:u==null?t:t3(u,t)}),N()},[e,r,N,_]),F=(0,U.useRef)(P);return F.current=P,(0,U.useEffect)(()=>{let e=e=>F.current(HFn(e)),t=zFn();return t?(t.on(`hf:file-change`,e),()=>t.off(`hf:file-change`,e)):UFn(e,()=>F.current({path:`.`}))},[]),{blocked:y,retry:(0,U.useCallback)(async()=>{let e=w.current;!e||e.status===`conflict`||e.recovered||(g?.(),C.current=null,P(e.payload))},[P,g]),useExternalFile:(0,U.useCallback)(async()=>{let t=w.current;if(!t||!e||t.generation!==x.current)return;let n=t.status===`conflict`?t.error.filePath:t.path,r=t.status===`conflict`&&t.error.currentContent!=null?t.error.currentContent:await m(n);t.generation===x.current&&(o(),g?.(),h?.(n,r),await f?.(e,n),O(null),k(t.payload))},[f,O,o,h,e,m,k,g]),keepStudioFile:(0,U.useCallback)(async()=>{let t=w.current;if(!t||!e||t.generation!==x.current)return;let n;if(t.status===`conflict`)n=t.error;else{if(!t.recovered||t.studioContent==null)return;try{let e=o9(t.payload)??await m(t.path);n=new XY({filePath:t.path,currentVersion:BFn(t.payload),currentContent:e,attemptedContent:t.studioContent})}catch(e){t.generation===x.current&&O({...t,error:e});return}}try{await p(n)}catch(e){t.generation===x.current&&O({status:`failed`,generation:t.generation,path:n.filePath,error:e,payload:t.payload,studioContent:n.attemptedContent,recovered:t.status===`failed`&&t.recovered});return}t.generation===x.current&&(o(),g?.(),await f?.(e,n.filePath),O(null),k(t3(t.payload,{path:n.filePath,affectsPreview:!0}),Q4(t.payload)!==n.filePath))},[f,O,o,p,e,m,k,g])}}function KFn({projectId:e,activeCompPath:t,masterCompPath:n,fileManager:r,previewPersistence:i,pendingTimelineEditPathRef:a,reloadPreview:o,onOutsideChange:s}){let{flushPendingSourceSave:c,discardPendingSourceSave:l}=r,{drainPendingDomEditSaves:u,resetDomEditSaveQueueBreaker:d}=i,f=X(e=>e.bumpThumbnailRevisions),p=(0,U.useCallback)((e,t)=>{s?.(),f(t)},[f,s]),m=(0,U.useCallback)(async()=>{let e=await c();return e.status===`clean`?u():e},[u,c]),h=(0,U.useCallback)(()=>{l(),d()},[l,d]);return GFn({projectId:e,activeCompPath:t,recoveryFilePath:r.editingFile?.path??t??n,pendingTimelineEditPathRef:a,drainPendingChanges:m,getPendingCandidate:r.getPendingSourceCandidate,discardPendingChanges:h,reloadPreview:o,reloadSdkSession:_Fn,persistConflictSnapshot:FFn,persistFailureSnapshot:IFn,loadConflictSnapshot:LFn,deleteConflictSnapshot:RFn,overwriteConflict:r.overwriteExternalConflict,readProjectFile:r.readProjectFile,onUseExternalFile:r.updateEditingFileContent,resetSaveQueues:d,onAcceptedPersistedFileChange:p,refreshFileTree:r.refreshFileTree})}function qFn(e){try{let t=e?.contentDocument;if(!t)return 0;let n=0;for(let e of t.body.querySelectorAll(`*`)){let t=parseInt(getComputedStyle(e).zIndex,10);Number.isFinite(t)&&t>n&&(n=t)}return n}catch{return 0}}function JFn(e,t){let n=new Set(t);if(!n.has(e))return e;let r=2;for(;n.has(`${e}_${r}`);)r++;return`${e}_${r}`}async function YFn({projectId:e,blockName:t,showToast:n}){let r=await H(M(e,`/registry/install`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({blockName:t})});if(!r.ok)return n((await r.json().catch(()=>({error:`Install failed`}))).error||`Failed to install block`),null;let{written:i,block:a}=await r.json(),o=i.find(e=>e.endsWith(`.html`))??i[0];return o?{block:a,compositionFile:o}:(n(`Installed but no composition file was written`),null)}async function XFn(e,t,n,r){e.type===`hyperframes:component`&&await jZ(r,t,async()=>{let e=await n(t),i=e.replace(/background:\s*(?:#(?:0a0a0a|000000|000|0a0805)|rgba?\([^)]*\))\s*;/g,`background: transparent;`);i!==e&&await r(t,i)})}function ZFn({block:e,placement:t,timelineElements:n,currentTime:r}){let i=e.type===`hyperframes:block`,{start:a=r,duration:o,track:s}=t??{},c=Number(XK(a)),l=`duration`in e?e.duration:void 0,u=o??l??n.reduce((e,t)=>Math.max(e,(t.start??0)+(t.duration??0)),10),d=Math.max(0,...n.map(e=>e.track))+1;return{duration:u,isBlock:i,start:c,track:s??(i?0:d)}}function QFn({id:e,compositionFile:t,start:n,duration:r,track:i,width:a,height:o,left:s,top:c,zIndex:l}){return[`<div`,` id="${e}"`,` data-hf-id="hf-${nG()}"`,` data-composition-id="${e}"`,` data-composition-src="${t}"`,` data-start="${XK(n)}"`,` data-duration="${XK(r)}"`,` data-track-index="${i}"`,` data-width="${a}"`,` data-height="${o}"`,` style="position: absolute; left: ${s}px; top: ${c}px; width: ${a}px; height: ${o}px; z-index: ${l}"`,`></div>`].join(`
363
363
  `)}async function s9(e){let{projectId:t,blockName:n,activeCompPath:r,placement:i,visualPosition:a,timelineElements:o,readProjectFile:s,writeProjectFile:c,recordEdit:l,refreshFileTree:u,reloadPreview:d,showToast:f}=e;try{let p=await YFn({projectId:t,blockName:n,showToast:f});if(!p)return null;let{block:m,compositionFile:h}=p;await XFn(m,h,s,c);let g=r||`index.html`,{duration:_,isBlock:v,start:y,track:b}=ZFn({block:m,placement:i,timelineElements:o.filter(e=>(e.sourceFile||g)===g),currentTime:e.currentTime??0}),x=``,S=t=>{let{width:n,height:r}=wBt(t);return x=JFn(m.name,t$(t)),uq(pq(t,QFn({id:x,compositionFile:h,start:y,duration:_,track:b,width:n,height:r,left:a?Math.round(a.left):0,top:a?Math.round(a.top):0,zIndex:qFn(e.previewIframe??null)+1})),y+_)};return await PZ({projectId:t,label:`Add ${v?`block`:`component`}: ${m.title}`,files:{[g]:S},readFile:s,writeFile:c,recordEdit:l}),await u(),d(),{block:m,compositionPath:h,hostKey:Te(x,g)}}catch(e){return f(e instanceof Error?e.message:`Failed to add block`),null}}function $Fn({projectId:e,blockCtxDeps:t,previewIframeRef:n,setRightCollapsed:r,setRightPanelTab:i}){let[a,o]=(0,U.useState)(null),s=(0,U.useMemo)(()=>({activeCompPath:t.activeCompPath,timelineElements:t.timelineElements,readProjectFile:t.readProjectFile,writeProjectFile:t.writeProjectFile,recordEdit:t.recordEdit,refreshFileTree:t.refreshFileTree,reloadPreview:t.reloadPreview,showToast:t.showToast}),[t.activeCompPath,t.timelineElements,t.readProjectFile,t.writeProjectFile,t.recordEdit,t.refreshFileTree,t.reloadPreview,t.showToast]),c=(0,U.useRef)(!1),{showToast:l,dismissToast:u}=t,d=(0,U.useCallback)(async(e,t)=>{if(c.current)return l(`A block is already installing — one moment…`,`info`),null;c.current=!0;let n=l(`Adding ${e}\u2026`,`info`);try{return await t()}finally{c.current=!1,u(n)}},[l,u]);return{activeBlockParams:a,setActiveBlockParams:o,handleAddBlock:(0,U.useCallback)(t=>{e&&(async()=>{let a=await d(t,()=>s9({projectId:e,blockName:t,...s,previewIframe:n.current,currentTime:X.getState().currentTime}));if(a===null)return;let c=a?.block.type===`hyperframes:block`?a.block.params:void 0;c?.length&&(o({blockName:a.block.name,blockTitle:a.block.title,params:c,compositionPath:a.compositionPath}),r(!1),i(`block-params`))})()},[e,s,n,d,r,i]),handleTimelineBlockDrop:(0,U.useCallback)((t,r)=>{e&&d(t,()=>s9({projectId:e,blockName:t,placement:r,...s,previewIframe:n.current,currentTime:X.getState().currentTime})).then(e=>{e&&U7(e.hostKey)})},[e,s,n,d]),handleAddMediaOverlay:(0,U.useCallback)(async(t,r)=>{if(!e)return;let{compositionPath:i,...a}=r;await d(t,()=>s9({projectId:e,blockName:t,...s,activeCompPath:i??s.activeCompPath,placement:a,previewIframe:n.current,currentTime:X.getState().currentTime}))},[e,s,n,d]),handlePreviewBlockDrop:(0,U.useCallback)((t,r)=>{e&&d(t,()=>s9({projectId:e,blockName:t,visualPosition:r,...s,previewIframe:n.current,currentTime:X.getState().currentTime})).then(e=>{e&&U7(e.hostKey)})},[e,s,n,d])}}function eIn(e,t,n){let r=e.key.toLowerCase();return r===`z`&&!e.shiftKey?(e.preventDefault(),t(),!0):r===`z`&&e.shiftKey||e.ctrlKey&&!e.metaKey&&r===`y`?(e.preventDefault(),n(),!0):!1}function tIn(e){return e.target instanceof Element&&e.target.closest(`[data-studio-timeline]`)!==null}function nIn(e,t,n){if(!$0t(e.target)&&eIn(e,()=>{mG(`keyboard_shortcut`,{action:`undo`}),n.handleUndo()},()=>{mG(`keyboard_shortcut`,{action:`redo`}),n.handleRedo()}))return!0;if(e.key===`1`)return e.preventDefault(),mG(`keyboard_shortcut`,{action:`tab_compositions`}),W8.getState().activatePanel(`compositions`),!0;if(e.key===`2`)return e.preventDefault(),mG(`keyboard_shortcut`,{action:`tab_assets`}),W8.getState().activatePanel(`assets`),!0;if(t===`g`&&!e.altKey&&!aX(e.target))return e.preventDefault(),n.readOnlyPreview||(e.shiftKey?n.onUngroupSelection?.():n.onGroupSelection?.()),!0;if(!e.shiftKey&&!e.altKey&&!aX(e.target)){if(w2t(e))return!0;if(t===`c`)return n.handleCopy()&&(e.preventDefault(),mG(`keyboard_shortcut`,{action:`copy`})),!0;if(n.readOnlyPreview&&n.domEditSelectionRef.current!==null&&!tIn(e)&&[`v`,`x`,`d`].includes(t))return e.preventDefault(),!0;if(t===`v`)return e.preventDefault(),mG(`keyboard_shortcut`,{action:`paste`}),n.handlePaste(),!0;if(t===`x`)return(X.getState().selectedElementId||n.domEditSelectionRef.current)&&(e.preventDefault(),mG(`keyboard_shortcut`,{action:`cut`}),n.handleCut()),!0;if(t===`d`)return e.preventDefault(),X.getState().selectedElementId&&(mG(`keyboard_shortcut`,{action:`duplicate`}),n.handleDuplicate()),!0}return!1}function rIn(e,t,n){if(!oX(e.target)){if(t===bG.fullscreen&&!e.shiftKey&&!e.altKey){e.preventDefault(),document.fullscreenElement?document.exitFullscreen():document.querySelector(`[data-studio-fullscreen-target]`)?.requestFullscreen();return}if(e.key===bG.split&&!e.altKey){if(e.preventDefault(),n.readOnlyPreview)return;let{selectedElementId:t,elements:r,currentTime:i}=X.getState();if(t){let e=r.find(e=>(e.key??e.id)===t);if(e&&kQ(e)&&i>e.start&&i<e.start+e.duration){n.handleTimelineElementSplit(e,i);return}if(!e&&t.includes(`#`)){n.showToast(`Use the razor tool (B) to split clips inside a sub-composition`,`info`);return}}}if(t===bG.audioGain&&!e.shiftKey&&!e.altKey&&!n.readOnlyPreview&&I3t()){e.preventDefault();return}if(t===`b`&&!e.shiftKey&&!e.altKey){e.preventDefault();let{activeTool:t,setActiveTool:n}=X.getState();n(t===`razor`?`select`:`razor`);return}if(t===`v`&&!e.shiftKey&&!e.altKey){e.preventDefault(),X.getState().setActiveTool(`select`);return}if((t===`[`||t===`]`)&&!e.shiftKey&&!e.altKey){e.preventDefault();let n=X.getState();t===`[`?n.selectLeftward():n.selectRightward();return}if(t===`a`&&!e.shiftKey&&!e.altKey){let{activeTool:t,setActiveTool:n}=X.getState();if(t===`razor`){e.preventDefault(),n(`select`);return}}if(e.key===`Escape`){let{activeTool:t,selectedElementId:n,setActiveTool:r,setSelectedElementId:i}=X.getState();if(t===`razor`){n?i(null):r(`select`),e.preventDefault();return}}if((e.key===`Delete`||e.key===`Backspace`)&&!e.altKey){if(X.getState().selectedKeyframes.size>0){n.onDeleteSelectedKeyframes(),X.getState().clearSelectedKeyframes(),e.preventDefault();return}if(X.getState().automationSelection)return;if(e.key===`Backspace`){let{selectedElementId:t,keyframeCache:r}=X.getState();if(t&&r.has(t)&&n.onResetKeyframes()){e.preventDefault();return}}let t=n.domEditSelectionRef.current,r=tIn(e);if(t&&!r){if(e.preventDefault(),n.readOnlyPreview)return;n.handleDomEditElementDelete(t,{expandGroup:!0});return}let{selectedElementId:i,selectedElementIds:a,elements:o}=X.getState(),s=new Set(a);i&&s.add(i);let c=o.filter(e=>s.has(e.key??e.id));c.length>0&&(e.preventDefault(),n.handleTimelineElementsDelete(c));return}e.key===bG.record&&!e.shiftKey&&!e.altKey&&n.onToggleRecording&&(e.preventDefault(),n.onToggleRecording())}}function iIn({editHistory:e,readOptionalProjectFile:t,readProjectFile:n,writeProjectFile:r,showToast:i,syncHistoryPreviewAfterApply:a,showHistoryRestoreNow:o,waitForPendingDomEditSaves:s,onAfterUndoRedo:c,activeCompPath:l,forceReloadSdkSession:u}){let d=(0,U.useCallback)(e=>e===PJ?t(e):n(e),[t,n]),f=(0,U.useCallback)((e,t)=>MZ(r,e,t),[r]),p=(0,U.useCallback)(async t=>{let n=t===`undo`?`Undo`:`Redo`;if(t===`undo`&&LKt())return;let r=t===`undo`?JKt():null,p=r?null:e.predict?.(t)??null,m=p?o?.(p.files)??null:null,h=m?UKt():null,g=m??r?.showAgain,_=r?.claimsAtBegin??(t===`undo`&&HKt()?e.claims?.():void 0),v={ok:!1,reason:`failed`},y=!1,b=!1;try{if(await s(),b=!!(r&&!await r.landed()),b)return;v=await e[t]({readFile:d,serialize:f,claimedAfter:_});let n=!!(v.ok&&v.label),i=r!==null&&(e.claims?.()??0)>r.claimsAtBegin;y=m?n&&v.undoes===p?.id:n&&i}finally{g&&!y&&!b&&g(),h?.()}if(!v.ok&&v.reason===`content-mismatch`){i(`Can't ${t}: ${v.paths?.join(`, `)} changed since that edit.`,`info`);return}if(!v.ok&&v.reason===`failed`){i(`${n} failed: ${v.message}`,`error`);return}if(v.ok&&v.label){let e=y&&m?aIn(v.files,p.files):v.files,t={paths:v.paths,files:e};c?.(t),l&&v.paths?.includes(l)&&u?.(),await a(t),i(v.label,`info`)}},[e,d,i,a,o,s,f,c,l,u]),m=(0,U.useCallback)(()=>p(`undo`),[p]),h=(0,U.useCallback)(()=>p(`redo`),[p]);return(0,U.useMemo)(()=>({undo:m,redo:h}),[m,h])}function aIn(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,{previous:t[e]?.restored??n.previous,restored:n.restored}]))}function oIn(e){try{return e?.contentWindow??null}catch{return null}}function sIn(e,t,n,r=!1){try{e?.addEventListener(t,n,r)}catch{}}function cIn(e,t,n,r=!1){try{e?.removeEventListener(t,n,r)}catch{}}function lIn(e,t,n){let r=X.getState(),i=e===`undo`?r.beatUndo:r.beatRedo,a=i[i.length-1]?.at??null;if(a===null)return!1;let o=t[e],s=o[o.length-1]?.createdAt??null;if(s!==null&&(e===`undo`?a<s:a>s))return!1;let c=e===`undo`?r.undoBeatEdits():r.redoBeatEdits();return c&&n(`${e===`undo`?`Undid`:`Redid`} ${c}`,`info`),!0}function uIn({projectId:e,handleTimelineElementsDelete:t,handleLinkEdit:n,handleTimelineElementDeleteOnly:r,handleTimelineElementSplit:i,handleDomEditElementDelete:a,domEditSelectionRef:o,editHistory:s,readOptionalProjectFile:c,readProjectFile:l,writeProjectFile:u,showToast:d,syncHistoryPreviewAfterApply:f,showHistoryRestoreNow:p,settlePendingEdits:m,handleCopy:h,handlePaste:g,handleCut:_,handleDuplicate:v,onResetKeyframes:y,onDeleteSelectedKeyframes:b,onAfterUndoRedo:x,onToggleRecording:S,onGroupSelection:C,onUngroupSelection:w,activeCompPath:T,forceReloadSdkSession:E,readOnlyPreview:D}){let O=(0,U.useRef)(null),k=iIn({editHistory:s,readOptionalProjectFile:c,readProjectFile:l,writeProjectFile:u,showToast:d,syncHistoryPreviewAfterApply:f,showHistoryRestoreNow:p,waitForPendingDomEditSaves:m,onAfterUndoRedo:x,activeCompPath:T,forceReloadSdkSession:E}),A=(0,U.useCallback)(async e=>{let t=O1.getState();if(t.isEditMode&&Lrn()){let n=e===`undo`?t.undo():t.redo();if(n){Rrn(n),d(`${e===`undo`?`Undid`:`Redid`} caption edit`,`info`);return}}lIn(e,s.state,d)||await k[e]()},[s.state,k,d]),j=(0,U.useCallback)(()=>A(`undo`),[A]),M=(0,U.useCallback)(()=>A(`redo`),[A]),N=(0,U.useRef)(null);N.current={handleTimelineElementsDelete:t,handleLinkEdit:n,handleTimelineElementDeleteOnly:r,handleTimelineElementSplit:i,handleDomEditElementDelete:a,handleUndo:j,handleRedo:M,handleCopy:h,handlePaste:g,handleCut:_,handleDuplicate:v,onResetKeyframes:y,onDeleteSelectedKeyframes:b,onToggleRecording:S,onGroupSelection:C,onUngroupSelection:w,domEditSelectionRef:o,showToast:d,readOnlyPreview:D};let P=(0,U.useCallback)(e=>{let t=N.current,n=e.key.toLowerCase();if(!Nvn(e,t)){if(e.metaKey||e.ctrlKey){nIn(e,n,t);return}rIn(e,n,t)}},[]);(0,U.useEffect)(()=>(window.addEventListener(`keydown`,P,!0),()=>window.removeEventListener(`keydown`,P,!0)),[P]);let F=(0,U.useCallback)(e=>{O.current?.(),O.current=null;let t=oIn(e);if(!t)return;let n=P;sIn(t,`keydown`,n,!0),O.current=()=>cIn(t,`keydown`,n,!0)},[P]);return(0,U.useEffect)(()=>()=>{O.current?.(),O.current=null},[]),N7({handleUndo:j,handleRedo:M,syncPreviewHotkeys:F},e)}function dIn(e,t,n,r){if(n){let i=r??0,a=0,o=null;if(n.startsWith(`#`)){let e=n.slice(1);o=RegExp(`<[a-z][^>]*\\bid="${e}"[^>]*>`,`gi`)}else if(n.startsWith(`.`)){let e=n.slice(1);o=RegExp(`<[a-z][^>]*\\bclass="[^"]*\\b${e}\\b[^"]*"[^>]*>`,`gi`)}else if(n.startsWith(`[`)){let e=n.slice(1,-1);o=RegExp(`<[a-z][^>]*\\b${e}[^>]*>`,`gi`)}if(o){let n;for(;(n=o.exec(e))!==null;){if(a===i){let r=fIn(e,n.index);if(r>0)return e.slice(0,r)+`
364
364
  `+t+e.slice(r)}a++}}}let i=pBt.exec(e);if(i&&i.index!=null){let n=i.index+i[0].length;return e.slice(0,n)+t+e.slice(n)}return e+t}function fIn(e,t){let n=e.indexOf(`>`,t);if(n<0)return-1;if(e[n-1]===`/`)return n+1;let r=e.slice(t).match(/^<([a-z][a-z0-9]*)/i);if(!r)return-1;let i=r[1],a=1,o=n+1,s=RegExp(`<${i}(?:\\s|>|/>)`,`gi`),c=RegExp(`</${i}\\s*>`,`gi`);for(;a>0&&o<e.length;){s.lastIndex=o,c.lastIndex=o;let t=s.exec(e),n=c.exec(e);if(!n)return-1;if(t&&t.index<n.index)e.lastIndexOf(`/`,e.indexOf(`>`,t.index))>t.index||a++,o=e.indexOf(`>`,t.index)+1;else{if(a--,a===0)return n.index+n[0].length;o=n.index+n[0].length}}return-1}var pIn=/(?<=\s)id="([^"]+)"/;function mIn(e,t){let n=new Set(t);return e.replace(new RegExp(pIn.source,`g`),(e,t)=>{if(!n.has(t))return e;let r=2;for(;n.has(`${t}-${r}`);)r++;let i=`${t}-${r}`;return n.add(i),`id="${i}"`})}var hIn=new RegExp(pIn.source,`g`),gIn=/(<script\b(?![^>]*\bsrc=)[^>]*>)([\s\S]*?)(<\/script>)|(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi;function _In(e,t){let n=e=>Array.from(e.matchAll(hIn),e=>e[1]),r=n(t),i=new Map;return n(e).forEach((e,t)=>{let n=r[t];n&&n!==e&&i.set(e,n)}),i}function vIn(e,t,n){let r=e;for(let[e,i]of t)r=r.replace(gIn,(t,r,a,o,s,c,l)=>r===void 0?s===void 0?t:s+yIn(c,e,i)+l:r+M4e(a,`#${e}`,`#${i}`,n)+o);return r}function yIn(e,t,n){let r=new CSSStyleSheet;r.replaceSync(e);let i=RegExp(`#${SZ(t)}(?![\\w-])`,`g`),a=RegExp(`:not\\([^)]*#${SZ(t)}(?![\\w-])`),o=e.match(/\n([ \t]*)\S/)?.[1]??``,s=Array.from(r.cssRules).flatMap(e=>{if(!(e instanceof CSSStyleRule))return[];let t=bIn(e.selectorText).filter(e=>e.match(i)&&!a.test(e));if(t.length===0)return[];let r=t.map(e=>e.replace(i,`#${n}`)).join(`, `);return[`
365
365
  ${o}${r}${e.cssText.slice(e.selectorText.length)}`]});if(s.length===0)return e;let c=e.trimEnd();return c+s.join(``)+e.slice(c.length)}function bIn(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i];a===`(`||a===`[`?n++:a===`)`||a===`]`?n--:a===`,`&&n===0&&(t.push(e.slice(r,i).trim()),r=i+1)}return t.push(e.slice(r).trim()),t}var xIn=(e,t,n,r)=>r?.inPlace&&e.copiedInComposition===t?Math.min(...e.clips.map(e=>e.start)):n,SIn=e=>e.kind===`timeline-clip`?{label:TIn(`Paste`,e.clips.length),toast:EIn(`Pasted`,e.clips.length)}:{label:`Paste element`,toast:`Pasted element`};function CIn(){let{selectedElementId:e,selectedElementIds:t,elements:n}=X.getState();if(!e)return[];let r=t.size>1?t:new Set([e]);return n.filter(e=>r.has(e.key??e.id))}function wIn(e,t){return d({id:e,fallbackIndex:0,domId:e,sourceFile:t})}function TIn(e,t){return`${e} ${t>1?`clips`:`clip`}`}function EIn(e,t){return t>1?`${e} ${t} clips`:`${e} clip`}function DIn(e,t,n){let r=null;try{r=e.current?.contentDocument??null}catch{return null}return r?He(r,t,n):null}function OIn(e,t,n){let r=zZ(e,t)??dQt(e,t);return r?_Qt(r,t,n):vQt(t)}async function kIn(e,t,n){let r=new Map;return Promise.all(t.map(async(t,i)=>(r.has(t)||r.set(t,e(t).then(LZ)),OIn(await r.get(t),n[i],t))))}function AIn(e,t){return e.track===t.track&&hq(e.start,e.start+e.duration,t.start,t.start+t.duration)}function jIn(e,t){return t.some(t=>AIn(e,t))?t.reduce((e,t)=>Math.max(e,t.track),e.track)+1:e.track}function MIn(e,t,n){let r=t.parseFromString(e,`text/html`).body.firstElementChild;if(!r)return e.replace(/\sdata-hf-id=("[^"]*"|'[^']*')/g,``);let i=[r];Yk(r,e=>i.push(e));for(let e of i)Gk.has(e.tagName.toLowerCase())?e.removeAttribute(`data-hf-id`):e.setAttribute(`data-hf-id`,qk(e,n));return r.outerHTML}var NIn=/\bdata-hf-id\s*=\s*["']?([^"'\s>]+)/gi,PIn=e=>new Set(Array.from(e.matchAll(NIn),e=>e[1]));function FIn(e,t,n=!1){let r=MIn(t.html,new DOMParser,PIn(e)),i=mIn(r,t$(e)),a=dIn(e,i,t.originSelector,t.originSelectorIndex);return n?vIn(a,_In(r,i),0):a}function IIn(e,t,n,r,i=!1){let a=Math.min(...t.map(e=>e.start)),o=t$(e),s=r.map(e=>({track:e.authoredTrack??e.track,start:e.start,duration:e.duration})),c=[],l=e,u=0,d=new DOMParser,f=PIn(e);for(let e of t){let t=MIn(e.html,d,f),r=mIn(t,o);o=o.concat(t$(r));let p=n+(e.start-a),m=jIn({track:e.track,start:p,duration:e.duration},s);s.push({track:m,start:p,duration:e.duration}),u=Math.max(u,p+e.duration);let h=r.indexOf(`>`),g=h>=0?r.slice(0,h+1):r,_=g.replace(/data-start="[^"]*"/,`data-start="${XK(p)}"`).replace(/data-track-index="[^"]*"/,`data-track-index="${m}"`),v=_+r.slice(h+1);if(l=pq(l,v),i){let n=Number(g.match(/data-start="([^"]*)"/)?.[1]),i=Number.isFinite(n)?n:e.start;l=vIn(l,_In(t,r),p-i)}let y=_.match(pIn)?.[1];y&&c.push(y)}return{content:l,ids:c,requiredEnd:u}}function LIn({projectId:e,activeCompPath:t,domEditSelectionRef:n,showToast:r,writeProjectFile:i,recordEdit:a,reloadPreview:o,handleTimelineElementsDelete:s,handleDomEditElementDelete:c,previewIframeRef:l,waitForPendingDomEditSaves:u}){let d=(0,U.useRef)(null),f=(0,U.useRef)(e);f.current=e;let p=(0,U.useCallback)(async e=>{let t=f.current;if(!t)throw Error(`No project is open.`);return await u().catch(()=>{}),MZ(i,[e],()=>lQ(t,e))},[u,i]),m=(0,U.useCallback)(()=>{let e=CIn();if(e.length===0)return null;let n=[];for(let i of e){let e=vQ(l.current,i,t);if(!e)return r(`Unable to copy "${i.label??i.id}".`,`info`),null;n.push(e)}return{elements:e,lives:n}},[t,l,r]),h=(0,U.useCallback)(async e=>{let n=e.elements.map(e=>e.sourceFile||t||`index.html`),r=await kIn(p,n,e.lives);return e.elements.map((e,t)=>({html:r[t],start:e.start,duration:e.duration,track:e.authoredTrack??e.track}))},[t,p]),g=(0,U.useCallback)(()=>{let e=m();if(!e)return null;let n=e.elements[0]?.sourceFile||t||`index.html`;return h(e).then(e=>(r(e.length>1?`Copied ${e.length} clips`:`Copied clip`,`info`),{kind:`timeline-clip`,clips:e,sourceFile:n,projectId:f.current??void 0,copiedInComposition:t||`index.html`}))},[t,m,h,r]),_=(0,U.useCallback)(e=>{let n=DIn(l,e,t);if(!n)return r(`Unable to copy this element.`,`info`),null;let i=e.sourceFile||t||`index.html`;return p(i).then(t=>(r(`Copied element`,`info`),{kind:`dom-element`,html:OIn(LZ(t),n,i),sourceFile:i,projectId:f.current??void 0,originSelector:e.selector,originSelectorIndex:e.selectorIndex}))},[t,l,p,r]),v=(0,U.useCallback)(()=>{let e=n.current,t;if(X.getState().selectedElementId)t=g();else if(e)t=_(e);else return r(`Nothing selected to copy.`,`info`),null;if(!t)return null;let i=t.catch(e=>(r(e instanceof Error?e.message:`Failed to copy`,`error`),null)),a=d.current,o=i.then(e=>e??a);return d.current=o,o.then(e=>{!e&&d.current===o&&(d.current=null)}),i},[_,g,n,r]),y=(0,U.useCallback)(()=>v()!==null,[v]),b=(0,U.useCallback)(async e=>{let n=await d.current;if(!n){r(`Nothing to paste.`,`info`);return}let s=f.current;if(!s)return;let c=t||`index.html`;try{let t=[],l=n.sourceFile===c&&n.projectId===s,u=r=>{if(n.kind!==`timeline-clip`)return FIn(r,n,l);let{currentTime:i,elements:a}=X.getState(),o=IIn(r,n.clips,xIn(n,c,i,e),a,l);return t=o.ids,uq(o.content,o.requiredEnd)},{label:d,toast:f}=SIn(n);await PZ({projectId:s,label:d,files:{[c]:u},readFile:e=>lQ(s,e),writeFile:i,recordEdit:a}),t.length>0&&X.getState().setSelection(t.map(e=>wIn(e,c))),o(),r(f,`info`)}catch(e){r(e instanceof Error?e.message:`Failed to paste`)}},[t,a,o,r,i]),x=(0,U.useCallback)(async e=>{let n=m();if(!n)return!1;let s=f.current;if(!s)return!1;let{elements:c}=n,l=e=>e.sourceFile||t||`index.html`,u=l(c[0]),d=LK(c[0],e?.inPlace?Math.min(...c.map(e=>e.start)):Math.max(...c.map(e=>e.start+e.duration)));try{let e=await h(n),t=[],c=n=>{let r=X.getState().elements.filter(e=>l(e)===u).map(e=>({...e,start:LK(e,e.start)})),i=IIn(n,e,d,r,!0);return t=i.ids,uq(i.content,i.requiredEnd)};return await PZ({projectId:s,label:TIn(`Duplicate`,e.length),files:{[u]:c},readFile:e=>lQ(s,e),writeFile:i,recordEdit:a}),t.length>0&&X.getState().setSelection(t.map(e=>wIn(e,u))),o(),r(EIn(`Duplicated`,e.length),`info`),!0}catch(e){return r(e instanceof Error?e.message:`Failed to duplicate`),!1}},[t,m,h,a,o,r,i]);return{handleCopy:y,handlePaste:b,handleCut:(0,U.useCallback)(async()=>{let e=CIn(),t=n.current,r=v();return!r||!await r?!1:e.length>0?(await s(e),!0):(t&&await c(t),!0)},[v,n,s,c]),handleDuplicate:x,canPaste:(0,U.useCallback)(()=>d.current!==null,[])}}var RIn={fontFamily:`sans-serif`,fontSize:48,fontWeight:700,fontStyle:`normal`,textDecoration:`none`,textTransform:`none`,letterSpacing:0,lineHeight:1.2,color:`#ffffff`,activeColor:`#ffffff`,dimColor:`rgba(255, 255, 255, 0.3)`,opacity:1,gradientFill:null,strokeWidth:0,strokeColor:`#000000`,shadows:[],glow:null,x:0,y:0,rotation:0,scaleX:1,scaleY:1,skewX:0,skewY:0,transformOrigin:`center center`,blendMode:`normal`},zIn={backgroundColor:`transparent`,backgroundOpacity:0,paddingTop:0,paddingRight:0,paddingBottom:0,paddingLeft:0,borderRadius:0,borderWidth:0,borderColor:`transparent`,borderStyle:`solid`,boxShadow:`none`},BIn={preset:`fade`,duration:.2,ease:`power2.out`,stagger:0,staggerDirection:`start`,intensity:1},c9={entrance:BIn,highlight:null,exit:{...BIn}};function VIn(e,t){let{width:n,height:r,duration:i,wordsPerGroup:a=5}=t,o=new Map,s=new Map,c=[];for(let t=0;t<e.length;t+=a){let n=e.slice(t,t+a),r=`group-${t/a}`,i=[];n.forEach((e,n)=>{let r=`segment-${t+n}`,a={id:r,wordId:e.id??`w${t+n}`,text:e.text,start:e.start,end:e.end,groupIndex:n,style:{},animation:{}};o.set(r,a),i.push(r)});let l={id:r,segmentIds:i,style:{...RIn},animation:{entrance:{...c9.entrance},highlight:c9.highlight,exit:{...c9.exit}},containerStyle:{...zIn}};s.set(r,l),c.push(r)}return{width:n,height:r,duration:i,segments:o,groups:s,groupOrder:c,defaultAnimation:{entrance:{...c9.entrance},highlight:c9.highlight,exit:{...c9.exit}}}}function HIn(e){let t=e.match(/(?:const|let|var)\s+(?:TRANSCRIPT|script)\s*=\s*(\[[\s\S]*?\]);/);if(!t)return[];let n=t[1];try{return WIn(n)}catch{return[]}}function UIn(e,t,n,r,i,a){let o=HIn(n);if(o.length===0)return null;let s=e.querySelectorAll(`.caption-group, .caption-line, .caption-block`),c=e.querySelectorAll(`.word, .caption-word`),l=5;s.length>0&&c.length>0&&(l=Math.round(c.length/s.length),l<1&&(l=1));let u=VIn(o,{width:r,height:i,duration:a,wordsPerGroup:l}),d=c.item(0),f=s.item(0),p=d??f;if(p){let e=t.getComputedStyle(p),n={},r=parseFloat(e.fontSize);!isNaN(r)&&r>0&&(n.fontSize=r);let i=e.fontWeight;if(i){let e=parseInt(i,10);n.fontWeight=isNaN(e)?i:e}let a=e.fontFamily;a&&(n.fontFamily=a);let o=e.color;o&&(n.color=o);let s=e.textTransform;(s===`none`||s===`uppercase`||s===`lowercase`||s===`capitalize`)&&(n.textTransform=s);let c=e.letterSpacing;if(c&&c!==`normal`){let e=parseFloat(c),t=n.fontSize??RIn.fontSize;!isNaN(e)&&t>0&&(n.letterSpacing=e/t)}let l={};if(f){let e=t.getComputedStyle(f),n=e.backgroundColor;n&&n!==`rgba(0, 0, 0, 0)`&&n!==`transparent`&&(l.backgroundColor=n,l.backgroundOpacity=1);let r=parseFloat(e.borderRadius);!isNaN(r)&&r>0&&(l.borderRadius=r);let i=parseFloat(e.paddingTop),a=parseFloat(e.paddingRight),o=parseFloat(e.paddingBottom),s=parseFloat(e.paddingLeft);isNaN(i)||(l.paddingTop=i),isNaN(a)||(l.paddingRight=a),isNaN(o)||(l.paddingBottom=o),isNaN(s)||(l.paddingLeft=s)}for(let e of u.groupOrder){let t=u.groups.get(e);t&&(t.style={...t.style,...n},t.containerStyle={...t.containerStyle,...l})}}return u}function WIn(e){let t;try{t=JSON.parse(e)}catch{let n=e;n=n.replace(/'((?:[^'\\]|\\.)*)'/g,(e,t)=>`"${t.replace(/\\'/g,`'`).replace(/"/g,`\\"`)}"`),n=n.replace(/([{,]\s*)([a-zA-Z_$][a-zA-Z0-9_$]*)\s*:/g,`$1"$2":`),n=n.replace(/,(\s*[}\]])/g,`$1`),t=JSON.parse(n)}if(!Array.isArray(t))return[];let n=[];for(let e of t)if(typeof e==`object`&&e&&typeof e.text==`string`&&typeof e.start==`number`&&typeof e.end==`number`){let t=e;n.push({...typeof t.id==`string`?{id:t.id}:{},text:t.text,start:t.start,end:t.end})}return n}function GIn({projectId:e,activeCompPath:t,compIdToSrc:n,captionEditMode:r,captionHasSelection:i,previewIframeRef:a,captionSync:o,setRightCollapsed:s}){let c=xZ(),l=(0,U.useRef)(t);(0,U.useEffect)(()=>{if(l.current!==t){l.current=t;let e=O1.getState();(e.model||e.isEditMode)&&(e.retrySave?.(),e.reset())}},[t]),(0,U.useEffect)(()=>{if(!e)return;let r=!1,i=()=>{let i=O1.getState();if(i.isEditMode||i.dismissed||r)return;let s=a.current,c=null,l=null;try{c=s?.contentDocument??null,l=s?.contentWindow??null}catch{return}if(!c||!l||c.querySelectorAll(`.caption-group`).length===0)return;let u=null,d=c.querySelectorAll(`[data-composition-src], [data-composition-file]`);for(let e of d){let t=e.getAttribute(`data-composition-src`)||e.getAttribute(`data-composition-file`);if(t&&t.includes(`captions`)){u=t;break}}if(!u){for(let[e,t]of n)if(e.includes(`caption`)||t.includes(`caption`)){u=t;break}}if(!u&&t?.includes(`captions`)&&(u=t),!u){let e=c.querySelector(`[data-composition-id*="caption"]`);if(e){let t=e.getAttribute(`data-composition-id`)||``;u=n.get(t)||null}}if(!u)return;r=!0;let f=u;H(M(e,`/files/${encodeURIComponent(f)}`)).then(e=>e.json()).then(e=>{if(!e.content||!c||!l||O1.getState().isEditMode)return;let t=c.querySelector(`[data-composition-id]`),n=parseInt(t?.getAttribute(`data-width`)??`1920`,10),r=parseInt(t?.getAttribute(`data-height`)??`1080`,10),i=parseFloat(t?.getAttribute(`data-duration`)??`0`),a=UIn(c,l,e.content,n,r,i);if(!a)return;let s=O1.getState();s.setModel(a),s.setSourceFilePath(f),s.setEditMode(!0),o.loadOverrides()}).catch(()=>{}).finally(()=>{r=!1})},s=e=>{if(!e.source||e.source!==a.current?.contentWindow)return;let t=e.data;if(t?.source===`hf-preview`&&(t?.type===`state`||t?.type===`timeline`)){if(!R1(t))return;i()}};return window.addEventListener(`message`,s),i(),()=>{window.removeEventListener(`message`,s)}},[t,e,n,o,a,c]),(0,U.useEffect)(()=>{r&&s(!i)},[i,r,s])}function KIn(e){let[t,n]=(0,U.useState)(null),r=(0,U.useRef)([]),i=(0,U.useCallback)(()=>{r.current=[],n(null)},[]);return(0,U.useEffect)(()=>{if(i(),!e)return;let t=null,a=null,o=null,s=()=>{let e=t;if(e){t=null;try{e.console.error=a,e.removeEventListener(`error`,o),delete e.__hfErrorCapture}catch{}a=null,o=null}},c=()=>{s(),i();try{let i=e.contentWindow;if(!i||i.__hfErrorCapture)return;i.__hfErrorCapture=!0,t=i;let s=e=>{e.length!==0&&(r.current=[...r.current,...e.map(e=>({severity:`error`,message:e}))],n([...r.current]))};a=i.console.error.bind(i.console),i.console.error=function(...e){a(...e);let t=e.map(e=>e instanceof Error?e.message:String(e)).join(` `);t.includes(`favicon`)||s([t])},o=e=>s([e.message||String(e)]),i.addEventListener(`error`,o);let c=Reflect.get(i,TMe);Array.isArray(c)&&s(c.map(String))}catch{}};return c(),e.addEventListener(`load`,c),()=>{e.removeEventListener(`load`,c),s()}},[e,i]),{consoleErrors:t,setConsoleErrors:n}}function qIn({projectId:e,activeCompPath:t,showToast:n,waitForPendingDomEditSaves:r}){let[i,a]=(0,U.useState)(()=>X.getState().currentTime),[o,s]=(0,U.useState)(!1),c=(0,U.useRef)(!1),l=(0,U.useRef)(i);ax(()=>Lb.subscribe(e=>{l.current=e}));let u=(0,U.useCallback)(()=>{let{isPlaying:e,currentTime:t}=X.getState();return e?l.current:t},[]),[d,f]=(0,U.useState)(Date.now),p=(0,U.useCallback)(()=>{a(u()),f(Date.now())},[u]),m=(0,U.useCallback)(async i=>{if(e&&(i.preventDefault(),!c.current)){c.current=!0,s(!0);try{let n=u();a(n),await Promise.race([r(),new Promise((e,t)=>setTimeout(()=>t(Error(`Save queue timed out`)),5e3))]);let i=wgn({projectId:e,compositionPath:t,currentTime:n}),o=Tgn(t,n),s=new AbortController,c=setTimeout(()=>s.abort(),3e4);try{let e=await H(i,{cache:`no-store`,signal:s.signal});if(clearTimeout(c),!e.ok){let t=`Capture failed (${e.status})`;try{let n=await e.json();n?.error&&(t=n.error)}catch{}throw Error(t)}let t=await e.blob(),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=o,document.body.appendChild(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}catch(e){throw clearTimeout(c),e instanceof DOMException&&e.name===`AbortError`?Error(`Capture timed out — the server took too long to respond`):e}}catch(e){n(e instanceof Error?e.message:`Capture failed`,`error`)}finally{c.current=!1,s(!1)}}},[t,u,e,n,r]);return{captureFrameHref:(0,U.useMemo)(()=>e?wgn({projectId:e,compositionPath:t,currentTime:i,version:d}):`#`,[e,t,i,d]),captureFrameFilename:Tgn(t,i),handleCaptureFrameClick:m,refreshCaptureFrameTime:p,capturing:o}}function JIn(e){return{severity:e.severity===`error`?`error`:`warning`,message:e.message??``,file:e.file,fixHint:e.fixHint,elementId:e.elementId}}async function YIn(e){return((await(await H(M(e,`/lint`))).json()).findings??[]).map(JIn)}function XIn(e,t){let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)([]),c=(0,U.useRef)(!1),l=(0,U.useCallback)(async()=>{if(e&&!(!WNe(e)&&!await ix(e)))try{s(await YIn(e))}catch{}},[e]),u=(0,U.useCallback)(async()=>{if(e){a(!0);try{let t=await YIn(e);r(t),s(t)}catch(e){let t=e instanceof Error?e.message:String(e);r([{severity:`error`,message:`Failed to run lint: ${t}`}])}finally{a(!1)}}},[e]),d=(0,U.useRef)(e);(0,U.useEffect)(()=>{e!==d.current&&(c.current=!1,d.current=e),!(!e||c.current)&&(c.current=!0,l())},[e,l]),(0,U.useEffect)(()=>{if(!e||!t)return;let n=setTimeout(()=>void l(),1e3);return()=>clearTimeout(n)},[e,t,l]);let f=(0,U.useCallback)(()=>r(null),[]),p=(0,U.useCallback)(e=>{let t=new Map;for(let n of o){let r=e(n);if(!r)continue;let i=t.get(r)??{count:0,messages:[]};i.count+=1,i.messages.push(n.message),t.set(r,i)}return t},[o]),m=(0,U.useMemo)(()=>p(e=>e.elementId),[p]),h=(0,U.useMemo)(()=>p(e=>e.file),[p]),g=n??o,_=g.length,v=g.some(e=>e.severity===`error`);return(0,U.useEffect)(()=>{X.getState().setLintFindingsByElement(m)},[m]),{lintModal:n,linting:i,handleLint:u,closeLintModal:f,backgroundFindings:o,findingsByElement:m,findingsByFile:h,lintFindingCount:_,hasLintError:v}}var ZIn=4e3,QIn=160,$In=3,eLn=1;function tLn(){let[e,t]=(0,U.useState)([]),n=(0,U.useRef)(new Map),r=(0,U.useCallback)(e=>{let t=n.current.get(e);t&&(clearTimeout(t),n.current.delete(e))},[]),i=(0,U.useCallback)(e=>{r(e),t(t=>t.filter(t=>t.id!==e))},[r]),a=(0,U.useCallback)(e=>{r(e),t(t=>t.map(t=>t.id===e?{...t,leaving:!0}:t));let a=setTimeout(()=>i(e),QIn);n.current.set(e,a)},[r,i]),o=(0,U.useCallback)((e,i=`error`)=>{let o=eLn++;if(t(t=>{let n=[...t,{id:o,message:e,tone:i}];for(;n.length>$In;){let e=n.shift();e&&r(e.id)}return n}),i!==`error`){let e=setTimeout(()=>a(o),ZIn);n.current.set(o,e)}return o},[r,a]);return ax(()=>()=>{for(let e of n.current.values())clearTimeout(e);n.current.clear()}),{toasts:e,showToast:o,dismissToast:a}}var nLn=[`layers`,`design`,`renders`,`slideshow`,`variables`];function rLn(e){return e.includes(`index.html`)?`index.html`:e.find(e=>e.endsWith(`.html`))??null}function iLn(e){return e.activeCompPath==null}function aLn(e){return!e||!nLn.includes(e)?null:e}function oLn(e,t){return!e||e===`index.html`?null:t.includes(e)?e:null}function sLn(e){return e===`1`||e!==`0`&&null}function cLn(e){if(e==null||e===``)return null;let t=Number(e);return Number.isFinite(t)?t:null}function lLn(e){return nLn.includes(e)?e:null}function uLn(e){return typeof e==`string`?e:void 0}function dLn(e){return typeof e==`number`&&Number.isFinite(e)?Math.max(0,Math.floor(e)):void 0}function fLn(e){if(!e||typeof e!=`object`)return null;let t=uLn(Reflect.get(e,`sourceFile`)),n=uLn(Reflect.get(e,`id`)),r=uLn(Reflect.get(e,`selector`));return!n&&!r?null:{sourceFile:t,id:n,selector:r,selectorIndex:dLn(Reflect.get(e,`selectorIndex`))}}function pLn(e){if(!e)return;let t;try{t=JSON.parse(e)}catch{let t=e.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>({id:e}));return t.length>0?t:void 0}if(!Array.isArray(t))return;let n=t.map(fLn).filter(e=>e!==null);return n.length>0?n:void 0}function mLn(e){let t=e.get(`selFile`)||void 0,n=e.get(`selId`)||void 0,r=e.get(`selSelector`)||void 0;if(!t&&!n&&!r)return null;let i=cLn(e.get(`selIndex`));return{sourceFile:t,id:n,selector:r,selectorIndex:i==null?void 0:Math.max(0,Math.floor(i)),group:pLn(e.get(`selGroup`))}}function hLn(){return{activeCompPath:null,currentTime:null,rightPanelTab:null,rightCollapsed:null,timelineVisible:null,selection:null}}function gLn(e){let t=nt(e);if(!t)return hLn();let{params:n}=t;return{activeCompPath:n.get(`comp`)||null,currentTime:cLn(n.get(`t`)),rightPanelTab:aLn(lLn(n.get(`tab`))),rightCollapsed:sLn(n.get(`rc`)),timelineVisible:sLn(n.get(`tv`)),selection:mLn(n)}}function _Ln(){return typeof window>`u`?hLn():gLn(window.location.hash)}function vLn(e,t){let n=new URLSearchParams;return n.set(`v`,`1`),t.activeCompPath&&n.set(`comp`,t.activeCompPath),t.currentTime!=null&&Number.isFinite(t.currentTime)&&n.set(`t`,String(Math.max(0,S(t.currentTime)))),t.rightPanelTab&&n.set(`tab`,t.rightPanelTab),t.rightCollapsed!=null&&n.set(`rc`,t.rightCollapsed?`1`:`0`),t.timelineVisible!=null&&n.set(`tv`,t.timelineVisible?`1`:`0`),t.selection&&(t.selection.sourceFile&&n.set(`selFile`,t.selection.sourceFile),t.selection.id&&n.set(`selId`,t.selection.id),t.selection.selector&&n.set(`selSelector`,t.selection.selector),typeof t.selection.selectorIndex==`number`&&n.set(`selIndex`,String(Math.max(0,Math.floor(t.selection.selectorIndex)))),t.selection.group?.length&&n.set(`selGroup`,JSON.stringify(t.selection.group))),V(e,n)}function yLn(e){return!e.id&&!e.selector?null:{sourceFile:e.sourceFile||void 0,id:e.id||void 0,selector:e.selector||void 0,selectorIndex:e.selectorIndex??void 0}}function bLn(e){return[e.sourceFile??``,e.id??``,e.selector??``,e.selectorIndex??``].join(`|`)}function xLn(e,t=[]){if(!e)return null;let n=yLn(e);if(!n)return null;let r=bLn(n),i=new Map;for(let e of t){let t=yLn(e);if(!t)continue;let n=bLn(t);n!==r&&i.set(n,t)}return{...n,group:i.size>0?[...i.values()]:void 0}}function SLn(e){typeof window>`u`||window.location.hash!==e&&window.history.replaceState(null,``,e)}function CLn(e,t,n,r){return He(e,{sourceFile:t.sourceFile??n,id:t.id,selector:t.selector,selectorIndex:t.selectorIndex},r)}async function wLn(e,t){return e?t(e,{preferClipAncestor:!1,skipSourceProbe:!0}):null}async function TLn({doc:e,primaryElement:t,selection:n,group:r,activeCompPath:i,isCurrent:a,buildDomSelection:o}){let s=await o(t,{preferClipAncestor:!1});if(!a())return null;if(!s)return[];let c=[s];for(let t of r){let r=await wLn(CLn(e,t,n.sourceFile??``,i),o);if(!a())return null;r&&c.push(r)}return c}function ELn({projectId:e,activeCompPath:t,duration:n,isPlaying:r,compositionLoading:i,refreshKey:a,previewIframeRef:o,rightPanelTab:s,rightCollapsed:c,activeCompPathHydrated:l,domEditSelection:u,domEditGroupSelections:d,applyMarqueeSelection:f,buildDomSelectionFromTarget:p,applyDomSelection:m,setRightPanelTab:h,initialState:g}){let _=X(e=>e.currentTime),v=(0,U.useRef)(g.currentTime==null),y=(0,U.useRef)(g.currentTime==null),b=(0,U.useRef)(g.selection==null),[x,S]=(0,U.useState)(g.selection==null),C=(0,U.useRef)(g.selection),w=(0,U.useRef)(g.currentTime),T=(0,U.useRef)(0),E=(0,U.useCallback)(()=>({activeCompPath:t,currentTime:w.current,rightPanelTab:s,rightCollapsed:c,timelineVisible:null,selection:b.current?xLn(u,d):C.current}),[t,d,u,c,s]),D=(0,U.useCallback)(e=>{let n=++T.current;if(!e)return m(null,{revealPanel:!1}),!0;let r=null;try{r=o.current?.contentDocument??null}catch{return!1}if(!r)return!1;let i=He(r,{sourceFile:e.sourceFile??``,id:e.id,selector:e.selector,selectorIndex:e.selectorIndex},t);if(!i)return m(null,{revealPanel:!1}),!0;let a=e.group??[];return TLn({doc:r,primaryElement:i,selection:e,group:a,activeCompPath:t,isCurrent:()=>n===T.current,buildDomSelection:p}).then(e=>{if(!e)return;let t=e[0];if(!t)return m(null,{revealPanel:!1});if(a.length===0)return m(t,{revealPanel:!1});f(e,!1)}),!0},[t,m,f,p,o]);(0,U.useEffect)(()=>{if(!e||v.current||i)return;let t=n>0?e$(g.currentTime??0,0,n):Math.max(0,g.currentTime??0);X.getState().requestSeek(t),w.current=t,v.current=!0},[e,i,n,g.currentTime]);let O=x?0:_;(0,U.useEffect)(()=>{if(!e||b.current||i||!v.current||g.currentTime!=null&&Math.abs(O-w.current)>.05)return;let t=()=>{b.current=!0,S(!0)},n=C.current;if(!n){t();return}D(n)&&(t(),C.current=null)},[D,i,O,g.currentTime,e,a]),(0,U.useEffect)(()=>{if(y.current)return;let e=w.current;if(e==null){y.current=!0;return}Math.abs(_-e)>.05||(y.current=!0)},[_]),(0,U.useEffect)(()=>{if(!l||!v.current||!y.current||!e||r)return;let t=window.setTimeout(()=>{w.current=e$(_,0,Math.max(0,n)),SLn(vLn(e,E()))},200);return()=>window.clearTimeout(t)},[l,E,_,n,r,e]),(0,U.useEffect)(()=>{l&&e&&SLn(vLn(e,E()))},[l,E,e]),(0,U.useEffect)(()=>{if(!e)return;let t=()=>{if(ct(window.location.hash)!==e)return;let t=gLn(window.location.hash);if(t.currentTime!=null){let e=n>0?e$(t.currentTime,0,n):Math.max(0,t.currentTime);Math.abs(X.getState().currentTime-e)>.05&&(X.getState().requestSeek(e),w.current=e)}D(t.selection),t.rightPanelTab&&h(t.rightPanelTab)};return window.addEventListener(`hashchange`,t),()=>window.removeEventListener(`hashchange`,t)},[e,n,D,h])}function DLn(e,t){return(0,U.useMemo)(()=>yqt(e,t),[e,t])}function OLn(e){return{projectId:e.projectId,activeCompPath:e.activeCompPath,setActiveCompPath:e.setActiveCompPath,showToast:e.showToast,previewIframeRef:e.previewIframeRef,captionEditMode:e.captionEditMode,compositionLoading:e.compositionLoading,refreshKey:e.refreshKey,setRefreshKey:e.setRefreshKey,timelineElements:e.timelineElements,isPlaying:e.isPlaying,editHistory:e.editHistory,writeBlockedReason:e.externalFileConflict?`an external change to this file is waiting to be resolved`:e.domEditSaveQueuePaused,handleUndo:e.handleUndo,handleRedo:e.handleRedo,renderQueue:e.renderQueue,compositionDimensions:e.compositionDimensions,waitForPendingDomEditSaves:e.waitForPendingDomEditSaves,handlePreviewIframeRef:e.handlePreviewIframeRef,refreshPreviewDocumentVersion:e.refreshPreviewDocumentVersion}}function kLn(e,t,n,r){return(0,U.useMemo)(()=>{let i=e===`layers`||e===`design`;return{inspectorPanelActive:i,shouldShowMotionPath:!!n&&!t&&!r,shouldShowSelectedDomBounds:(i||e===`variables`)&&!t&&!r}},[e,t,r,n])}function ALn(e){return{onDragOver:(0,U.useCallback)(e=>{e.dataTransfer.types.includes(`Files`)&&e.preventDefault()},[]),onDrop:(0,U.useCallback)(t=>{t.defaultPrevented||(t.preventDefault(),t.dataTransfer.files.length&&e(t.dataTransfer.files))},[e])}}function jLn(e){return ALn((0,U.useCallback)(t=>{let n=X.getState().currentTime;e(Array.from(t),{start:n,track:0})},[e]))}var MLn=jG(`PanelLayoutContext`,null);function NLn(){let e=(0,U.useContext)(MLn);if(!e)throw Error(`usePanelLayoutContext must be used within PanelLayoutProvider`);return e}function PLn({value:{rightCollapsed:e,setRightCollapsed:t,rightPanelTab:n,setRightPanelTab:r},children:i}){let a=(0,U.useMemo)(()=>({rightCollapsed:e,setRightCollapsed:t,rightPanelTab:n,setRightPanelTab:r}),[e,t,n,r]);return(0,W.jsx)(MLn,{value:a,children:i})}function FLn({size:e=16}){return(0,W.jsxs)(`svg`,{width:e,height:e,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,W.jsx)(`rect`,{x:`1.5`,y:`2`,width:`13`,height:`12`,rx:`1.5`}),(0,W.jsx)(`path`,{d:`M4 6h8M6 4.5v3M4 10h8m-2-1.5v3`})]})}var ILn=`M77.55 48.44 L122.77 65.85 L99.3 89.41 Z`,l9={cx:111.6,cy:68.2,r:11.5};function LLn({size:e,className:t,eyeRef:n}){return(0,W.jsxs)(`svg`,{width:e,height:e,viewBox:`58 30 82 76`,"aria-hidden":`true`,className:t,overflow:`visible`,children:[(0,W.jsx)(`path`,{d:ILn,fill:`var(--color-white)`,stroke:`var(--color-white)`,strokeWidth:24,strokeLinejoin:`round`}),(0,W.jsx)(`path`,{d:ILn,fill:`var(--color-framey)`,stroke:`var(--color-framey)`,strokeWidth:19,strokeLinejoin:`round`}),(0,W.jsx)(`circle`,{cx:l9.cx,cy:l9.cy,r:l9.r,fill:`var(--color-white)`}),(0,W.jsx)(`g`,{ref:n,className:`hf-framey-eye`,children:(0,W.jsx)(`path`,{d:`M${l9.cx-2.6} ${l9.cy-2} V${l9.cy+2} M${l9.cx+2.6} ${l9.cy-2} V${l9.cy+2}`,stroke:`var(--color-framey-ink)`,strokeWidth:2.4,strokeLinecap:`round`})})]})}var RLn=`/api/open-in-desktop`,zLn=2.2,BLn=1600;function VLn(){let[e,t]=(0,U.useState)(null);return(0,U.useEffect)(()=>{let e=!0;return H(RLn).then(e=>e.ok?e.json():null).then(n=>{if(!e||n?.available!==!0)return;let r=n.handoff===!0,i=typeof n.downloadUrl==`string`?n.downloadUrl:null;(r||i)&&t({handoff:r,downloadUrl:i})}).catch(()=>{}),()=>{e=!1}},[]),e}function HLn(e,t){(0,U.useEffect)(()=>{let n=0,r=r=>{cancelAnimationFrame(n),n=requestAnimationFrame(()=>{let n=e.current?.getBoundingClientRect();if(!n||!t.current)return;let i=r.clientX-(n.left+n.height/2),a=r.clientY-(n.top+n.height/2),o=Math.hypot(i,a)||1;t.current.style.transform=`translate(${i/o*zLn}px, ${a/o*zLn}px)`})};return window.addEventListener(`pointermove`,r),()=>{cancelAnimationFrame(n),window.removeEventListener(`pointermove`,r)}},[e,t])}function ULn(){let{showToast:e}=FX(),t=VLn(),[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(null),o=(0,U.useRef)(null),s=(0,U.useRef)(null);if(HLn(o,s),!t)return null;let c=async()=>{if(!t.handoff){mG(`toolbar_action`,{action:`open_in_desktop`}),a(t.downloadUrl);return}if(!n){r(!0),mG(`toolbar_action`,{action:`open_in_desktop`});try{let t=await(await H(RLn,{method:`POST`})).json();t.opened?(e(`Framey is opening this project in the HyperFrames desktop app`,`info`),await new Promise(e=>setTimeout(e,BLn))):a(t.downloadUrl)}catch{e(`Couldn't reach the preview server to open the app`,`error`)}finally{r(!1)}}};return(0,W.jsxs)(_Ae,{open:i!==null,onOpenChange:e=>{e?c():a(null)},side:`bottom`,align:`end`,arrow:!0,"aria-label":`Meet Framey`,className:`w-72`,trigger:(0,W.jsxs)(cb,{ref:o,variant:`ghost`,"data-testid":`header-open-in-desktop`,"data-opening":n||void 0,title:`Open this project in the HyperFrames desktop app and edit it with Framey`,className:`hf-framey-trigger gap-1.5 border border-accent/40 bg-accent/10 pl-1 font-semibold text-text-0 enabled:hover:bg-accent/20`,icon:(0,W.jsx)(LLn,{size:24,className:`hf-framey`,eyeRef:s}),children:[n?`Opening in the app…`:`Edit with Framey`,!n&&(0,W.jsx)(`span`,{className:`rounded-full bg-accent px-1.5 text-[10px] leading-4 font-bold text-on-accent`,children:`New`})]}),children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,W.jsx)(LLn,{size:36}),(0,W.jsx)(`p`,{className:`text-step-12 font-medium text-text-0`,children:`Meet Framey`})]}),(0,W.jsx)(`p`,{className:`mt-2 text-balance text-text-3`,children:`I live in the free HyperFrames desktop app:`}),(0,W.jsxs)(`ul`,{className:`mt-1.5 grid gap-1 text-text-1`,children:[(0,W.jsx)(`li`,{children:`Chat to change anything in the video`}),(0,W.jsx)(`li`,{children:`Draw on a frame to point at it`}),(0,W.jsx)(`li`,{children:`Watch me act out each edit`})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2 whitespace-nowrap`,children:[(0,W.jsx)(cb,{variant:`ghost`,onClick:()=>a(null),children:`Not now`}),(0,W.jsx)(`a`,{href:i??void 0,target:`_blank`,rel:`noopener noreferrer`,className:ib(ab,ob.primary,sb.md),onClick:()=>mG(`toolbar_action`,{action:`get_desktop_app`}),children:`Get the desktop app`})]})]})}function WLn(){return document.documentElement.dataset.theme===`paper`?`light`:`dark`}function GLn(e){Wb({theme:e});let t=document.documentElement;e===`light`?t.dataset.theme=`paper`:delete t.dataset.theme}function KLn(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributeFilter:[`data-theme`]}),()=>t.disconnect()}function qLn(){return(0,U.useSyncExternalStore)(KLn,WLn)}var JLn=null;function YLn(e,t,n){JLn=e;let r=()=>{JLn===e&&delete document.documentElement.dataset.themeReveal};e.finished.then(r,r),e.ready.then(()=>{document.documentElement.animate({clipPath:[`circle(0% ${t})`,`circle(${n}% ${t})`]},{duration:500,easing:`ease-in-out`,pseudoElement:`::view-transition-new(root)`})},()=>{})}function XLn(e){if(e.detail>0)return[e.clientX,e.clientY];let t=e.currentTarget.getBoundingClientRect();return[t.left+t.width/2,t.top+t.height/2]}var ZLn=(0,U.createContext)(!1);function QLn(){return!document.startViewTransition||window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches===!0}var $Ln={width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0};function eRn(){let e=qLn()===`dark`,t=`Switch to ${e?`light`:`dark`} theme`;function n(t){let n=()=>GLn(e?`light`:`dark`);if(QLn())return n();let[r,i]=XLn(t),a=window.innerWidth,o=window.innerHeight,s=Math.hypot(Math.max(r,a-r),Math.max(i,o-i)),c=`at ${r/a*100}% ${i/o*100}%`,l=s/(Math.hypot(a,o)/Math.SQRT2)*100;document.documentElement.dataset.themeReveal=``,YLn(document.startViewTransition(n),c,l)}return(0,W.jsx)(fb,{label:t,side:`bottom`,children:(0,W.jsx)(lb,{onClick:n,"aria-label":t,icon:e?(0,W.jsxs)(`svg`,{...$Ln,children:[(0,W.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,W.jsx)(`line`,{x1:`12`,y1:`1`,x2:`12`,y2:`3`}),(0,W.jsx)(`line`,{x1:`12`,y1:`21`,x2:`12`,y2:`23`}),(0,W.jsx)(`line`,{x1:`4.22`,y1:`4.22`,x2:`5.64`,y2:`5.64`}),(0,W.jsx)(`line`,{x1:`18.36`,y1:`18.36`,x2:`19.78`,y2:`19.78`}),(0,W.jsx)(`line`,{x1:`1`,y1:`12`,x2:`3`,y2:`12`}),(0,W.jsx)(`line`,{x1:`21`,y1:`12`,x2:`23`,y2:`12`}),(0,W.jsx)(`line`,{x1:`4.22`,y1:`19.78`,x2:`5.64`,y2:`18.36`}),(0,W.jsx)(`line`,{x1:`18.36`,y1:`5.64`,x2:`19.78`,y2:`4.22`})]}):(0,W.jsx)(`svg`,{...$Ln,children:(0,W.jsx)(`path`,{d:`M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z`})})})})}function tRn(e,t){return e||!t}var nRn=(0,U.memo)(function({captureFrameHref:e,captureFrameFilename:t,handleCaptureFrameClick:n,refreshCaptureFrameTime:r,capturing:i,inspectorButtonActive:a,inspectorPanelActive:o,onExport:s}){let c=(0,U.useContext)(ZLn),{projectId:l,renderQueue:u}=FX(),{rightCollapsed:d,setRightCollapsed:f,setRightPanelTab:p}=NLn(),m=u.isRendering,h=u.ffmpegMissing;return(0,W.jsxs)(`div`,{className:`flex items-center justify-between h-10 px-3 bg-surface border-b border-border-strong shrink-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(zxe,{}),(0,W.jsx)(`span`,{className:`text-text-5 select-none`,"aria-hidden":`true`,children:`|`}),(0,W.jsx)(`span`,{className:`text-step-11 font-medium text-text-1`,children:l})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex h-ctl items-center divide-x divide-border-strong overflow-hidden rounded-md border border-border-strong bg-bg-2`,children:[(0,W.jsx)(fb,{label:i?`Capturing frame…`:`Capture current frame`,side:`bottom`,children:(0,W.jsxs)(`a`,{href:e,download:t,onClick:e=>{if(i){e.preventDefault();return}mG(`toolbar_action`,{action:`capture_frame`}),n(e)},onFocus:r,onPointerDown:r,"aria-disabled":i||void 0,className:ib(ab,ob.ghost,sb.md,`h-full rounded-none max-[1000px]:px-2`,i?`text-text-4 cursor-default`:`hover:bg-hover hover:text-text-0 active:scale-[0.98]`),"aria-label":i?`Capturing frame`:`Capture current frame`,children:[i?(0,W.jsxs)(`svg`,{className:`animate-spin motion-reduce:animate-none h-3.5 w-3.5`,viewBox:`0 0 24 24`,fill:`none`,"aria-hidden":`true`,children:[(0,W.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,W.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}):(0,W.jsx)(I2t,{size:14}),(0,W.jsx)(`span`,{className:`max-[1000px]:hidden`,children:i?`Capturing…`:`Capture`})]})}),(0,W.jsx)(fb,{label:`Inspector`,side:`bottom`,children:(0,W.jsx)(cb,{variant:`ghost`,"aria-label":`Inspector`,"aria-pressed":a,className:ib(`h-full rounded-none`,a&&`bg-on text-accent-ink enabled:hover:bg-on-hover enabled:hover:text-accent-ink`),icon:(0,W.jsx)(FLn,{size:16}),onClick:()=>{if(tRn(d,o)){mG(`panel_toggle`,{panel:`inspector`,collapsed:!1}),p(`design`),f(!1);return}mG(`panel_toggle`,{panel:`inspector`,collapsed:!0}),f(!0)},children:`Inspector`})})]}),c&&(0,W.jsx)(eRn,{}),(0,W.jsx)(Y8.WindowMenu,{}),(0,W.jsx)(ULn,{}),(0,W.jsx)(fb,{label:h?`FFmpeg is not installed. Opens the Renders panel with the install command.`:m?`A render is already in progress`:`Render and export this composition`,side:`bottom`,children:(0,W.jsx)(cb,{variant:`primary`,"data-testid":`header-export`,disabled:m,onClick:()=>{m||(p(`renders`),f(!1),!h&&s?.())},children:m?`Rendering…`:`Export`})})]})]})});function rRn(e,t){let n=1,r=1,i=0,a=0;try{let o=t.contentWindow.gsap;o?.getProperty&&(n=Number(o.getProperty(e,`opacity`))||1,r=Number(o.getProperty(e,`scaleX`))||1,i=Number(o.getProperty(e,`x`))||0,a=Number(o.getProperty(e,`y`))||0)}catch{}let o=Number.parseFloat(e.style.getPropertyValue(`--hf-studio-offset-x`))||0,s=Number.parseFloat(e.style.getPropertyValue(`--hf-studio-offset-y`))||0;return(e.style.translate??``).includes(`var(`)&&(i+=o,a+=s),{baseX:i,baseY:a,baseOpacity:n,baseScale:r,cssOffX:o,cssOffY:s}}function iRn(e,t,n){try{let r=t.contentWindow,i=r?.__timelines?Object.entries(r.__timelines).find(([e,t])=>e!==`__proxied`&&typeof t?.seek==`function`)?.[1]??null:null;if(r?.gsap?.set&&i?.seek&&e.id){let t=i.duration();return{timeline:i,gsap:r.gsap,element:e,startTime:r.__player?.getTime()??0,maxSeekTime:n!=null&&n<t?n:t,savedVisibility:e.style.visibility,savedTranslate:e.style.getPropertyValue(`translate`)}}}catch{}return null}function aRn(e,t,n){let r=Math.min(e.startTime+t,e.maxSeekTime);e.timeline.seek(r),e.element.style.setProperty(`translate`,`none`),e.gsap.set(e.element,{...n}),e.element.style.visibility=`visible`,Lb.notify(r),X.getState().setCurrentTime(r)}function oRn(e,t,n){let r={time:Fb(Pb(t)),properties:{...n}},i=e.samples.length-1;e.samples[i]?.time===r.time?e.samples[i]=r:e.samples.push(r),e.trail.push({x:e.pointer.x,y:e.pointer.y})}function sRn(e){let t=e.getBoundingClientRect(),n=e.contentDocument,r=n?.querySelector(`[data-composition-id]`)??n?.documentElement,i=Number(r?.getAttribute(`data-width`))||1920;return i>0?t.width/i:1}function cRn(e,t,n,r,i){let a={},o=i.opacity,s=i.scale,c=i.z;return r.meta?(o=Math.max(0,Math.min(1,1-t*.005)),a.opacity=o,n!==0&&(s=Math.max(.01,i.scale+n*.01),a.scale=s)):r.shift?(a.rotationX=t*.5,a.rotationY=e*.5):r.alt?a.rotation=e*.5:(a.x=e,a.y=t),!r.meta&&n!==0&&(c=i.z+n,a.z=c),{properties:a,nextState:{opacity:o,scale:s,z:c}}}function lRn(){return{pointer:{x:0,y:0},startPointer:{x:0,y:0},hasMoved:!1,scrollDelta:0,modifiers:{shift:!1,alt:!1,meta:!1},accumulated:{opacity:1,scale:1,z:0},basePosition:{x:0,y:0},cssVarOffset:{x:0,y:0},scale:1,runtime:null,rafId:0,samples:[],trail:[],cleanup:null}}function uRn(e){let t=e.runtime;if(!t)return;let{element:n,savedVisibility:r,savedTranslate:i}=t;n.style.visibility=r,n.style.setProperty(`translate`,i||``);try{t.gsap.set(t.element,{clearProps:`x,y,scale,scaleX,scaleY,rotation,rotationX,rotationY,opacity,z`})}catch{}(e.cssVarOffset.x||e.cssVarOffset.y)&&(n.style.setProperty(`--hf-studio-offset-x`,`${e.cssVarOffset.x}px`),n.style.setProperty(`--hf-studio-offset-y`,`${e.cssVarOffset.y}px`)),e.runtime=null}function dRn(){let[e,t]=(0,U.useState)(!1),[n,r]=(0,U.useState)(0),i=(0,U.useRef)(!1),a=(0,U.useRef)(lRn()),o=(0,U.useRef)(a.current.samples),s=(0,U.useRef)(a.current.trail);return(0,U.useEffect)(()=>{let e=a.current;return()=>{i.current=!1,uRn(e),e.cleanup?.(),e.cleanup=null}},[]),{startRecording:(0,U.useCallback)((e,n,c)=>{if(i.current)return;i.current=!0;let l=a.current;l.samples=[],l.trail=[],l.hasMoved=!1,l.scrollDelta=0,o.current=l.samples,s.current=l.trail,r(0);let u=rRn(e,n);l.cssVarOffset={x:u.cssOffX,y:u.cssOffY},l.accumulated={opacity:u.baseOpacity,scale:u.baseScale,z:0},l.basePosition={x:u.baseX,y:u.baseY},l.scale=sRn(n),l.runtime=iRn(e,n,c),l.runtime&&(u.cssOffX||u.cssOffY)&&(e.style.setProperty(`--hf-studio-offset-x`,`0px`),e.style.setProperty(`--hf-studio-offset-y`,`0px`));let d=e=>{l.pointer={x:e.clientX,y:e.clientY},l.modifiers={shift:e.shiftKey,alt:e.altKey,meta:e.metaKey||e.ctrlKey}},f=e=>{l.hasMoved||=(l.startPointer={x:l.pointer.x,y:l.pointer.y},!0),l.scrollDelta+=e.deltaY,l.modifiers={shift:e.shiftKey,alt:e.altKey,meta:e.metaKey||e.ctrlKey}},p=e=>{l.modifiers={shift:e.shiftKey,alt:e.altKey,meta:e.metaKey||e.ctrlKey}};document.addEventListener(`pointermove`,d,{passive:!0}),document.addEventListener(`wheel`,f,{passive:!0}),document.addEventListener(`keydown`,p,{passive:!0}),document.addEventListener(`keyup`,p,{passive:!0});let m=performance.now();l.startPointer={...l.pointer};let h=e=>{l.hasMoved||=(l.startPointer={x:e.clientX,y:e.clientY},!0)};document.addEventListener(`pointermove`,h,{passive:!0,once:!0});let g=()=>{if(!i.current)return;let e=(performance.now()-m)/1e3,t=l.scale||1,n=(l.pointer.x-l.startPointer.x)/t,a=(l.pointer.y-l.startPointer.y)/t,o=l.scrollDelta;if(!l.hasMoved&&n===0&&a===0&&o===0){l.rafId=requestAnimationFrame(g);return}l.hasMoved=!0;let{properties:s,nextState:c}=cRn(n,a,o,l.modifiers,l.accumulated);if(`x`in s&&(s.x=Math.round(l.basePosition.x+s.x)),`y`in s&&(s.y=Math.round(l.basePosition.y+s.y)),l.accumulated=c,l.scrollDelta=0,l.runtime)try{aRn(l.runtime,e,s)}catch{uRn(l)}oRn(l,e,s),r(e),l.rafId=requestAnimationFrame(g)};t(!0),l.rafId=requestAnimationFrame(g),l.cleanup=()=>{cancelAnimationFrame(l.rafId),document.removeEventListener(`pointermove`,d),document.removeEventListener(`wheel`,f),document.removeEventListener(`keydown`,p),document.removeEventListener(`keyup`,p),document.removeEventListener(`pointermove`,h)}},[]),stopRecording:(0,U.useCallback)(()=>{if(!i.current)return[];i.current=!1;let e=a.current;uRn(e),e.cleanup?.(),e.cleanup=null;let n=e.samples.slice();return r(n.length>0?n[n.length-1]?.time??0:0),t(!1),n},[]),isRecording:e,samplesRef:o,trailRef:s,recordingDuration:n,clearSamples:(0,U.useCallback)(()=>{let e=a.current;e.samples=[],e.trail=[],o.current=e.samples,s.current=e.trail,r(0),e.accumulated={opacity:1,scale:1,z:0},e.scrollDelta=0},[])}}function fRn(e,t,n,r,i,a){if(i===n)return Math.abs(t-r);let o=r+(a-r)*(e-n)/(i-n);return Math.abs(t-o)}function pRn(e,t){if(e.length<=2||t<=0)return e;let n=e[0],r=e[e.length-1],i=0,a=0;for(let t=1;t<e.length-1;t++){let o=fRn(e[t].time,e[t].value,n.time,n.value,r.time,r.value);o>i&&(i=o,a=t)}if(i>t){let n=pRn(e.slice(0,a+1),t),r=pRn(e.slice(a),t);return n.slice(0,-1).concat(r)}return[n,r]}function mRn(e,t,n){if(e.length===0||t<=0)return new Map;let r=new Set;for(let t of e)for(let e of Object.keys(t.properties))r.add(e);let i=new Set;for(let t of r){let r=[];for(let n of e)t in n.properties&&r.push({time:n.time,value:n.properties[t]});let a=pRn(r,typeof n==`function`?n(t):n);for(let e of a)i.add(e.time)}let a=Array.from(i).sort((e,t)=>e-t),o=new Map;for(let n of a){let i=Math.round(n/t*1e3)/10,a={};for(let t of r)a[t]=hRn(e,t,n);o.set(i,a)}return o}function hRn(e,t,n){let r,i;for(let a of e){if(!(t in a.properties))continue;let e=a.properties[t];a.time<=n&&(r={time:a.time,value:e}),a.time>=n&&i===void 0&&(i={time:a.time,value:e})}if(r&&r.time===n)return r.value;if(i&&i.time===n||!r)return i.value;if(!i)return r.value;let a=(n-r.time)/(i.time-r.time);return r.value+(i.value-r.value)*a}var gRn=`custom(M0,0 C0.333,0 0.667,1 1,1)`,_Rn=`custom(M0,0 C0.333,0.333 0.667,1 1,1)`,vRn=`custom(M0,0 C0.333,0 0.667,0.667 1,1)`,yRn=.3;function bRn(e,t,n){let r=e.filter(e=>e.time>=t&&e.time<=n);if(r.length<2)return 0;let i=0;for(let e=1;e<r.length;e++){let t=r[e].time-r[e-1].time;t>0&&(i+=Math.abs(r[e].value-r[e-1].value)/t)}return i/(r.length-1)}function xRn(e,t,n,r){let i=e.filter(e=>r===`start`?e.time>=t&&e.time<=t+n:e.time>=t-n&&e.time<=t);if(i.length<2)return 0;let a=0;for(let e=1;e<i.length;e++){let t=i[e].time-i[e-1].time;t>0&&(a+=Math.abs(i[e].value-i[e-1].value)/t)}return a/(i.length-1)}function SRn(e,t,n){if(e.length<2||t.length<3)return e;let r=[...e.map(e=>({...e}))];for(let e=1;e<r.length;e++){let i=r[e-1].percentage,a=r[e].percentage,o=i/100*n,s=a/100*n,c=s-o;if(c<=0)continue;let l=Object.keys(r[e].properties),u=l[0]??`x`,d=0;for(let t of l){let n=Number(r[e-1].properties[t]??0),i=Number(r[e].properties[t]??0),a=Math.abs(i-n);a>d&&(d=a,u=t)}let f=t.filter(e=>e.time>=o&&e.time<=s).map(e=>({time:e.time,value:e.properties[u]??0}));if(f.length<3)continue;let p=c*.25,m=bRn(f,o,s);if(m<1e-6)continue;let h=xRn(f,o,p,`start`),g=xRn(f,s,p,`end`),_=h/m<yRn,v=g/m<yRn;_&&v?r[e].ease=gRn:v?r[e].ease=_Rn:_&&(r[e].ease=vRn)}return r}function CRn(e,t){return Math.exp(-(e*e)/(2*t*t))}function wRn(e,t){if(e.length<=2||t<=0)return e;let n=t/2,r=new Set;for(let t of e)for(let[e,n]of Object.entries(t.properties))typeof n==`number`&&r.add(e);return r.size===0?e:e.map((i,a)=>{if(a===0||a===e.length-1)return i;let o={...i.properties};for(let i of r){let r=0,s=0;for(let o=Math.max(0,a-t);o<=Math.min(e.length-1,a+t);o++){let t=e[o].properties[i];if(typeof t!=`number`)continue;let c=CRn(o-a,n);r+=c,s+=t*c}r>0&&(o[i]=Math.round(s/r*1e3)/1e3)}return{percentage:i.percentage,properties:o}})}function TRn(e){let t=[],n=new Map;for(let r of e){let e=new Map;for(let[t,n]of Object.entries(r.properties)){let r=DT(t),i=e.get(r);i||(i={},e.set(r,i)),i[t]=n}for(let[i,a]of e){let e=n.get(i);e||(e=[],n.set(i,e),t.push(i)),e.push({percentage:r.percentage,properties:a,...r.ease?{ease:r.ease}:{}})}}return t.map(e=>n.get(e))}function ERn(e,t){return e===t-1?{softReload:!0}:{skipReload:!0}}function DRn(e){let t=Number.parseFloat(e.dataAttributes?.start??`0`)||0,n=Number.parseFloat(e.dataAttributes?.duration??`0`)||0;return n>0?t+n:void 0}var ORn=0;function kRn({projectId:e,domEditSessionRef:t,previewIframeRef:n,showToast:r,isGestureRecordingRef:i,readOnlyPreview:a}){let o=dRn(),[s,c]=(0,U.useState)(`idle`),l=(0,U.useRef)(`idle`),u=(0,U.useRef)(void 0),d=(0,U.useRef)(`button`),f=(0,U.useRef)(0),p=(0,U.useRef)(!1),m=(0,U.useRef)(null),h=(0,U.useRef)([]);(0,U.useEffect)(()=>()=>clearInterval(u.current),[]);let g=(0,U.useCallback)(()=>{clearInterval(u.current),o.stopRecording(),o.clearSamples(),l.current=`idle`,i.current=!1,m.current=null,c(`idle`)},[o,i]);(0,U.useEffect)(()=>{a&&l.current===`recording`&&g()},[g,a]);let _=(0,U.useCallback)(async()=>{if(clearInterval(u.current),p.current)return;p.current=!0;let e={coalesceKey:`gesture-recording:${++ORn}`,coalesceMs:1/0};l.current=`idle`,i.current=!1;let n=o.stopRecording(),a=X.getState();a.setIsPlaying(!1);try{let i=t.current,a=m.current;if(!a){n.length>2&&r(`Selection lost during recording`,`error`);return}let o=n.length>0?n[n.length-1]?.time??0:0;if(n.length<=2){r(`No gesture detected — move the pointer while recording`,`error`);return}if(o<=0){r(`Recording too short — try again`,`error`);return}let s=mRn(n,o,e=>e===`opacity`||e===`scale`||e===`scaleX`||e===`scaleY`?.01:5),c=Array.from(s.keys()).sort((e,t)=>e-t);!s.has(0)&&n.length>0&&(s.set(0,n[0].properties),c.includes(0)||c.unshift(0));let l=a.id?iJ(a.id):a.selector;if(!l){r(`Cannot save — element has no selector`,`error`);return}let u=lJ(a);if(!u){r(`Cannot save: element has no unique selector`,`error`);return}if(i.commitMutation){let t=i.commitMutation,r=E8((e,n,r)=>t(n,r,a)),p=(e,t)=>r.commit(a,e,t),m=f.current,g=SRn(wRn(c.map(e=>({percentage:e,properties:s.get(e)})),3),n,o),_=g.some(e=>Object.keys(e.properties).some(e=>DT(e)===`position`)),v=h.current,y=_?v.find(e=>e.propertyGroup===`position`&&dJ(e.targetSelector,l,a.element)):void 0;if(y)if(tJ(y))await p({type:`replace-with-keyframes`,animationId:y.id,targetSelector:l,position:S(m),duration:S(o),keyframes:g},{label:`Gesture recording (replace set)`,softReload:!0,keyframeAction:`add`});else{let t=y.resolvedStart??0,n=Zq(y),r=t+n,i=m+o;if(m<r+.05&&i>t-.05){let e=y.keyframes?.keyframes??[],r=n>0?Math.max(0,(m-t)/n*100):0,a=n>0?Math.min(100,(i-t)/n*100):100,o=Hq(y),s=uHt(o)?e=>e:S,c=e.filter(e=>{let t=qq(o,e.percentage);return t<r-.5||t>a+.5}).map(e=>({percentage:e.percentage,properties:e.properties,...e.ease?{ease:e.ease}:{}})),u={ease:`none`},d=g.map((e,t)=>({percentage:s(Kq(o,r+e.percentage/100*(a-r))),properties:e.properties,...e.ease?{ease:e.ease}:t>0?u:{}})),f=[...c,...d].sort((e,t)=>e.percentage-t.percentage);await p({type:`replace-with-keyframes`,animationId:y.id,targetSelector:l,position:typeof y.position==`number`?y.position:t,duration:n,keyframes:f,...eJ(y)},{label:`Gesture recording (merge)`,softReload:!0,keyframeAction:`add`})}else{let t=TRn(g);for(let[n,r]of t.entries())await p({type:`add-with-keyframes`,targetSelector:u,position:S(m),duration:S(o),keyframes:r,easeEach:`none`},{label:`Gesture recording (new range)`,...e,...ERn(n,t.length)})}}else{let t=TRn(g);for(let[n,r]of t.entries())await p({type:`add-with-keyframes`,targetSelector:u,position:S(m),duration:S(o),keyframes:r,easeEach:`none`},{label:`Gesture recording`,...e,...ERn(n,t.length)})}h4(`gesture_recording`,d.current,r.finish())}r(`Recorded ${c.length} keyframes`,`info`)}catch(e){console.error(`[GR:error]`,e),r(`Gesture commit failed: ${e}`,`error`)}finally{a.requestSeek(f.current),o.clearSamples(),c(`idle`),p.current=!1}},[o,r,i,t]),v=(0,U.useCallback)(e=>{clearInterval(u.current);let t=e??1/0;u.current=setInterval(()=>{let{currentTime:e,duration:n}=X.getState(),r=Math.min(t,n);r>0&&e>=r-.05&&_()},100)},[_]),y=(0,U.useCallback)(e=>{if(a)return;let s=t.current.domEditSelection;if(!s){r(`Select an element first`,`error`);return}let u=n.current;if(!u){r(`Preview not ready — try again`,`error`);return}let p=X.getState();d.current=e,f.current=p.currentTime;let g=DRn(s);m.current=s,h.current=t.current.selectedGsapAnimations??[],o.startRecording(s.element,u,g),l.current=`recording`,i.current=!0,c(`recording`),v(g)},[o,r,n,t,i,a,v]);return N7({gestureState:s,gestureRecording:o,handleToggleRecording:(0,U.useCallback)((e=`button`)=>{if(!p.current){if(l.current===`recording`){a?g():_();return}y(e)}},[g,a,y,_])},e)}var ARn=(0,U.memo)(function({samples:e,sampleCount:t,trail:n,simplifiedPoints:r,canvasRect:i,compositionSize:a,mode:o,accentColor:s=`#3CE6AC`}){let c=(0,U.useMemo)(()=>i?n&&n.length>1?n.map(e=>`${e.x-i.left},${e.y-i.top}`).join(` `):e.length===0?``:e.filter(e=>e.properties.x!=null&&e.properties.y!=null).map(e=>`${e.properties.x},${e.properties.y}`).join(` `):``,[e,n,t,i?.left,i?.top]),l=(0,U.useMemo)(()=>{if(!r||r.size===0)return``;let e=[];for(let[t,n]of r)n.x!=null&&n.y!=null&&e.push({x:n.x,y:n.y,pct:t});return e.sort((e,t)=>e.pct-t.pct),e.length===0?``:e.map(e=>`${e.x},${e.y}`).join(` `)},[r]),u=(0,U.useMemo)(()=>{if(!r||r.size===0)return[];let e=[];for(let[t,n]of r)n.x!=null&&n.y!=null&&e.push({x:n.x,y:n.y,pct:t});return e.sort((e,t)=>e.pct-t.pct)},[r]);return!i||e.length<2&&!r?null:(0,W.jsxs)(`svg`,{className:`pointer-events-none fixed z-50`,style:{left:i.left,top:i.top,width:i.width,height:i.height},viewBox:n&&n.length>1?`0 0 ${i.width} ${i.height}`:`0 0 ${a?.width??i.width} ${a?.height??i.height}`,children:[o===`recording`&&c&&(0,W.jsx)(`polyline`,{points:c,fill:`none`,stroke:s,strokeWidth:`2`,strokeOpacity:`0.6`,strokeLinecap:`round`,strokeLinejoin:`round`}),o===`preview`&&(0,W.jsxs)(W.Fragment,{children:[c&&(0,W.jsx)(`polyline`,{points:c,fill:`none`,stroke:s,strokeWidth:`1`,strokeOpacity:`0.2`,strokeDasharray:`4 3`,strokeLinecap:`round`}),l&&(0,W.jsx)(`polyline`,{points:l,fill:`none`,stroke:s,strokeWidth:`2`,strokeOpacity:`0.8`,strokeLinecap:`round`,strokeLinejoin:`round`}),u.map(e=>(0,W.jsx)(`g`,{transform:`translate(${e.x}, ${e.y})`,children:(0,W.jsx)(`rect`,{x:`-4`,y:`-4`,width:`8`,height:`8`,rx:`1`,transform:`rotate(45)`,fill:s,fillOpacity:`0.9`})},e.pct))]})]})});function jRn({gestureState:e,gestureRecording:t},n,r){let i=(0,U.useRef)(null);if((0,U.useLayoutEffect)(()=>{if(e!==`recording`||!n){i.current=null;return}i.current=n.getBoundingClientRect()},[e,n]),!(e!==`recording`||!n))return(0,W.jsx)(ARn,{samples:t.samplesRef.current,sampleCount:t.samplesRef.current.length,trail:t.trailRef.current,canvasRect:i.current,compositionSize:r??void 0,mode:`recording`})}function MRn({name:e,filePath:t}){return(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 bg-neutral-950 gap-2`,children:[(0,W.jsxs)(`svg`,{width:`40`,height:`40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,className:`text-neutral-600`,"aria-hidden":`true`,children:[(0,W.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,W.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`,strokeLinecap:`round`}),(0,W.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`,strokeLinecap:`round`})]}),(0,W.jsx)(`span`,{className:`text-sm text-neutral-400 font-medium`,children:e}),(0,W.jsx)(`span`,{className:`text-[11px] text-neutral-600 font-mono`,children:t}),(0,W.jsx)(`span`,{className:`text-[10px] text-neutral-500`,children:`Couldn't load this file — it may be missing or corrupt`})]})}function NRn({projectId:e,filePath:t}){let n=M(e,`/preview/${t}`),r=t.split(`/`).pop()??t,[i,a]=(0,U.useState)(null),o=i===t,s=()=>a(t);return o?(0,W.jsx)(MRn,{name:r,filePath:t}):rq.test(t)?(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 bg-neutral-950`,children:[(0,W.jsx)(`img`,{src:n,alt:r,onError:s,className:`max-w-full max-h-[70%] object-contain rounded-sm border border-neutral-800`}),(0,W.jsx)(`span`,{className:`mt-3 text-[11px] text-neutral-500 font-mono`,children:t})]}):iq.test(t)?(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 bg-neutral-950`,children:[(0,W.jsx)(`video`,{src:n,controls:!0,onError:s,className:`max-w-full max-h-[70%] rounded-sm border border-neutral-800`}),(0,W.jsx)(`span`,{className:`mt-3 text-[11px] text-neutral-500 font-mono`,children:t})]}):aq.test(t)?(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 bg-neutral-950 gap-3`,children:[(0,W.jsxs)(`svg`,{width:`48`,height:`48`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,className:`text-neutral-600`,children:[(0,W.jsx)(`path`,{d:`M9 18V5l12-2v13`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,W.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]}),(0,W.jsx)(`audio`,{src:n,controls:!0,onError:s,className:`w-full max-w-[280px]`}),(0,W.jsx)(`span`,{className:`text-[11px] text-neutral-500 font-mono`,children:t})]}):(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full p-4 bg-neutral-950 gap-2`,children:[(0,W.jsxs)(`svg`,{width:`40`,height:`40`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,className:`text-neutral-600`,children:[(0,W.jsx)(`path`,{d:`M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`polyline`,{points:`14 2 14 8 20 8`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),(0,W.jsx)(`span`,{className:`text-sm text-neutral-400 font-medium`,children:r}),(0,W.jsx)(`span`,{className:`text-[11px] text-neutral-600 font-mono`,children:t}),(0,W.jsx)(`span`,{className:`text-[10px] text-neutral-600`,children:`Binary file — preview not available`})]})}function PRn({className:e=``,...t}){return(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md bg-panel-input px-2.5 py-[5px] ${e}`,children:[(0,W.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 256 256`,fill:`none`,className:`shrink-0`,"aria-hidden":`true`,children:[(0,W.jsx)(`circle`,{cx:`116`,cy:`116`,r:`76`,stroke:`currentColor`,strokeWidth:`22`,className:`text-panel-text-5`}),(0,W.jsx)(`line`,{x1:`170`,y1:`170`,x2:`232`,y2:`232`,stroke:`currentColor`,strokeWidth:`22`,strokeLinecap:`round`,className:`text-panel-text-5`})]}),(0,W.jsx)(`input`,{type:`text`,className:`min-w-0 w-full bg-transparent text-[11px] text-panel-text-1 outline-hidden placeholder:text-panel-text-5`,...t})]})}function FRn(e){return aq.test(e)?`audio`:rq.test(e)?`images`:iq.test(e)?`video`:oq.test(e)?`fonts`:null}function IRn(e){let t=e.toLowerCase();return t.includes(`/bgm/`)||t.includes(`/music/`)?`BGM`:t.includes(`/sfx/`)||t.includes(`/sound`)?`SFX`:t.includes(`/voice/`)||t.includes(`/narrat`)?`Voice`:`Audio`}function u9(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n>0?t.slice(0,n):t}function d9(e){return e.split(`/`).pop()??e}function LRn(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n>0?t.slice(n+1).toUpperCase():``}function RRn(e,t){if(e.length<=t)return e;let n=t-1,r=Math.floor(n/3),i=n-r;return e.slice(0,i)+`…`+e.slice(e.length-r)}function zRn(e){if(!Number.isFinite(e)||e<=0)return``;let t=Math.round(e),n=Math.floor(t/60),r=t%60;return`${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}var BRn={audio:`Audio`,images:`Images`,video:`Video`,fonts:`Fonts`},f9=[`audio`,`images`,`video`,`fonts`];function VRn(e){return e.length>0&&!/[/\\]/.test(e)&&!e.includes(`..`)}function HRn({x:e,y:t,asset:n,onClose:r,onCopy:i,onDelete:a,onRename:o,onAddAtPlayhead:s}){let c=(0,U.useRef)(null),[l,u]=(0,U.useState)({x:e,y:t}),[d,f]=(0,U.useState)(`menu`),[p,m]=(0,U.useState)(()=>d9(n)),[h,g]=(0,U.useState)(null);(0,U.useLayoutEffect)(()=>{let n=c.current;if(!n)return;let r=n.getBoundingClientRect();u({x:Math.min(e,window.innerWidth-r.width-8),y:Math.min(t,window.innerHeight-r.height-8)})},[e,t,d]),(0,U.useEffect)(()=>{let e=e=>{if(e.key===`Escape`){e.stopPropagation(),d===`menu`?r():f(`menu`);return}if(d!==`menu`||e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=Array.from(c.current?.querySelectorAll(`[role="menuitem"]`)??[]);t.length!==0&&(e.preventDefault(),t[(t.findIndex(e=>e===document.activeElement)+(e.key===`ArrowDown`?1:-1)+t.length)%t.length].focus())};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[d,r]),(0,U.useEffect)(()=>{d===`menu`&&c.current?.querySelector(`[role="menuitem"]`)?.focus()},[d]);let _=(0,U.useCallback)(()=>{let e=p.trim();if(e===d9(n)){r();return}if(!VRn(e)){g(`Name can't contain / or ..`);return}let t=n.includes(`/`)?n.slice(0,n.lastIndexOf(`/`)+1):``;o?.(n,`${t}${e}`),r()},[p,n,o,r]),v=`${wQ.row} ${wQ.rowEnabled} active:bg-neutral-700/70 transition-colors`;return(0,W.jsx)(`div`,{className:`fixed inset-0 z-200`,onClick:r,onContextMenu:e=>{e.preventDefault(),r()},children:(0,W.jsxs)(`div`,{ref:c,role:`menu`,"aria-label":`Actions for ${d9(n)}`,className:`${wQ.panel} absolute min-w-[160px] text-xs`,style:{left:l.x,top:l.y},onClick:e=>e.stopPropagation(),children:[d===`menu`&&(0,W.jsxs)(W.Fragment,{children:[s&&(0,W.jsx)(`button`,{role:`menuitem`,onClick:()=>{s(n),r()},className:v,children:`Add at playhead`}),(0,W.jsx)(`button`,{role:`menuitem`,onClick:()=>{i(n),r()},className:v,children:`Copy path`}),o&&(0,W.jsx)(`button`,{role:`menuitem`,onClick:()=>f(`rename`),className:v,children:`Rename`}),a&&(0,W.jsx)(`button`,{role:`menuitem`,onClick:()=>f(`confirm-delete`),className:`${wQ.row} ${wQ.rowDanger} active:bg-neutral-700/70 transition-colors`,children:`Delete`})]}),d===`confirm-delete`&&(0,W.jsx)(URn,{name:d9(n),onConfirm:()=>{a?.(n),r()},onCancel:()=>f(`menu`)}),d===`rename`&&(0,W.jsxs)(`div`,{className:`px-2 py-1.5 flex flex-col gap-1`,children:[(0,W.jsx)(`input`,{autoFocus:!0,value:p,onChange:e=>{m(e.target.value),g(null)},onKeyDown:e=>{e.key===`Enter`&&_(),e.key===`Escape`&&(e.stopPropagation(),f(`menu`))},"aria-label":`Rename ${d9(n)}`,className:`w-full bg-neutral-800 border border-neutral-600 rounded-sm px-1.5 py-1 text-[11px] text-text-0 focus:border-studio-accent/60 focus:outline-hidden`}),h&&(0,W.jsx)(`span`,{className:`text-[10px] text-danger-ink`,children:h}),(0,W.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,W.jsx)(`button`,{onClick:()=>f(`menu`),className:`px-2 py-0.5 text-[10px] rounded-sm text-neutral-400 hover:text-neutral-200 transition-colors`,children:`Cancel`}),(0,W.jsx)(`button`,{onClick:_,className:`px-2 py-0.5 text-[10px] rounded-sm bg-accent hover:bg-accent-hover text-on-accent transition-colors`,children:`Rename`})]})]})]})})}function URn({name:e,onConfirm:t,onCancel:n}){return(0,W.jsxs)(`div`,{className:`px-2 py-1.5 bg-danger/15 border-l-2 border-red-500 flex items-center justify-between gap-2`,children:[(0,W.jsxs)(`span`,{className:`text-[10px] text-danger-ink truncate`,children:[`Delete `,e,`?`]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,W.jsx)(`button`,{onClick:t,className:`px-2 py-0.5 text-[10px] rounded-sm bg-danger text-on-danger hover:brightness-95 active:brightness-90 transition-colors`,children:`Delete`}),(0,W.jsx)(`button`,{onClick:n,className:`px-2 py-0.5 text-[10px] rounded-sm text-neutral-400 hover:text-neutral-200 transition-colors`,children:`Cancel`})]})]})}function WRn(e,t){let n=null;for(let r of e)r.src&&GRn(r.src)===t&&(n===null||r.start<n.start)&&(n=r);return n}function GRn(e){let t=e;try{t=new URL(t).pathname}catch{}t=t.replace(/^\/api\/projects\/[^/]+\/preview\//,``).replace(/^\.?\//,``).split(/[?#]/)[0];try{t=decodeURIComponent(t)}catch{}return t}var KRn=4;function qRn(e,t){return Math.abs(e)<KRn&&Math.abs(t)<KRn}var p9=null;function JRn({projectId:e,asset:t,used:n,meta:r,onCopy:i,copyFeedback:a,onDelete:o,onRename:s,onAddAssetToTimeline:c}){let[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(!1),[p,m]=(0,U.useState)([]),h=(0,U.useRef)(null),g=(0,U.useRef)(null),_=(0,U.useRef)(null),v=(0,U.useRef)(null),y=(0,U.useRef)(0),b=u9(t),x=IRn(t),S=P$(t,e),C=a?.path===t&&a.ok,w=a?.path===t&&!a.ok,T=(0,U.useCallback)(()=>{h.current?.pause(),f(!1),cancelAnimationFrame(y.current)},[]),E=(0,U.useRef)(null),D=X(e=>e.setSelectedElementId),O=X(e=>e.requestTimelineFocus),k=X(e=>e.elements),A=O2(e=>e.setPreviewAsset),j=O2(e=>e.clearPreviewAsset),M=(0,U.useCallback)(()=>{if(n){let e=WRn(k,t);if(e){j();let t=e.key??e.id;D(t),O(Bq(t));return}}A(t,e)},[n,k,t,e,D,O,A,j]),N=(0,U.useCallback)(e=>{E.current={x:e.clientX,y:e.clientY}},[]),P=(0,U.useCallback)(e=>{let t=E.current;E.current=null,t&&qRn(e.clientX-t.x,e.clientY-t.y)&&M()},[M]);(0,U.useEffect)(()=>()=>{cancelAnimationFrame(y.current),h.current?.pause(),g.current?.close(),p9===T&&(p9=null)},[T]),(0,U.useEffect)(()=>{if(d){let e=()=>{let t=_.current;if(!t){y.current=requestAnimationFrame(e);return}let n=new Uint8Array(t.frequencyBinCount);t.getByteFrequencyData(n);let r=Math.floor(n.length/24),i=[];for(let e=0;e<24;e++){let t=0;for(let i=0;i<r;i++)t+=n[e*r+i];i.push(t/r/255)}m(i),h.current&&!h.current.paused&&(y.current=requestAnimationFrame(e))};y.current=requestAnimationFrame(e)}else m([]);return()=>cancelAnimationFrame(y.current)},[d]);let F=(0,U.useCallback)(async()=>{if(d){T(),p9===T&&(p9=null);return}if(p9&&p9!==T&&p9(),p9=T,g.current||(g.current=new AudioContext,_.current=g.current.createAnalyser(),_.current.fftSize=256,_.current.smoothingTimeConstant=.7),!h.current){let e=new Audio;e.onended=()=>{f(!1),cancelAnimationFrame(y.current)},e.src=S,h.current=e;let t=_.current;t&&MOt(e).kind===`web-audio`&&(v.current=g.current.createMediaElementSource(e),v.current.connect(t),t.connect(g.current.destination))}g.current.state===`suspended`&&await g.current.resume(),h.current.currentTime=0;try{await h.current.play(),f(!0)}catch{f(!1),p9===T&&(p9=null)}},[S,d,T]);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{draggable:!0,onPointerDown:N,onPointerUp:P,role:`button`,tabIndex:0,"aria-label":`${b} \u2014 open, drag to timeline, right-click for actions`,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),M())},onDragStart:e=>{e.dataTransfer.effectAllowed=`copy`,e.dataTransfer.setData(dq,JSON.stringify({path:t})),e.dataTransfer.setData(`text/plain`,t)},onContextMenu:e=>{e.preventDefault(),u({x:e.clientX,y:e.clientY})},className:`group w-full text-left px-4 py-1.5 flex items-center gap-2.5 transition-colors cursor-pointer outline-hidden focus-visible:bg-neutral-800/60 ${d?`bg-panel-accent/6`:C?`bg-panel-accent/10`:`hover:bg-panel-surface-hover`}`,children:[(0,W.jsx)(`button`,{"aria-label":d?`Pause preview of ${b}`:`Play preview of ${b}`,"aria-pressed":d,className:`w-7 h-7 rounded-md shrink-0 flex items-center justify-center transition-colors active:scale-[0.95] ${d?`bg-panel-accent/15 text-accent-ink`:`text-panel-text-5 group-hover:text-panel-text-3`}`,onClick:e=>{e.stopPropagation(),F()},children:d?(0,W.jsxs)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`currentColor`,children:[(0,W.jsx)(`rect`,{x:`6`,y:`4`,width:`4`,height:`16`,rx:`1`}),(0,W.jsx)(`rect`,{x:`14`,y:`4`,width:`4`,height:`16`,rx:`1`})]}):(0,W.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,W.jsx)(`polygon`,{points:`6,4 20,12 6,20`})})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[12px] font-medium truncate ${n?`text-panel-text-1`:`text-panel-text-3`}`,children:b}),!d&&(0,W.jsxs)(`span`,{className:`text-[11px] text-panel-text-5 shrink-0`,children:[r?.duration?`${r.duration}s \xB7 `:``,x]}),n&&(0,W.jsx)(`span`,{className:`text-[9px] font-medium text-accent-ink bg-panel-accent/10 px-1.5 py-px rounded-sm shrink-0`,children:`in use`}),(C||w)&&(0,W.jsx)(`span`,{role:`status`,className:`shrink-0 text-[9px] font-medium px-1.5 py-px rounded ${w?`text-danger-ink bg-red-500/10`:`text-accent-ink bg-panel-accent/10`}`,children:w?`Copy failed`:`Copied`})]}),p.length>0&&(0,W.jsx)(`div`,{className:`flex items-end gap-[2px] h-[14px] mt-0.5`,children:p.map((e,t)=>(0,W.jsx)(`div`,{className:`flex-1 rounded-[1px]`,style:{height:`${Math.max(10,e*100)}%`,background:`linear-gradient(to top, rgba(60, 230, 172, ${.3+e*.5}), rgba(60, 230, 172, ${.5+e*.5}))`,transition:`height 80ms ease-out`}},t))})]})]}),l&&(0,W.jsx)(HRn,{x:l.x,y:l.y,asset:t,onClose:()=>u(null),onCopy:i,onDelete:o,onRename:s,onAddAtPlayhead:c})]})}function YRn(e,t=``){let n=t.trim().toLowerCase();return e.filter(e=>!n||[e.id,e.type,e.description,e.entity].some(e=>e&&String(e).toLowerCase().includes(n))).map(e=>({id:e.id??e.sha??`asset`,type:e.type??`asset`,label:e.description||e.entity||e.id||e.sha||`asset`}))}function XRn({searchQuery:e}){let[t,n]=(0,U.useState)(null);(0,U.useEffect)(()=>{let e=!1;return H(`/api/assets/global`).then(e=>e.ok?e.json():{assets:[]}).then(t=>{e||n(Array.isArray(t.assets)?t.assets:[])}).catch(()=>{e||n([])}),()=>{e=!0}},[]);let r=(0,U.useMemo)(()=>YRn(t??[],e),[t,e]);return t===null?(0,W.jsx)(`p`,{className:`px-4 py-3 text-[11px] text-panel-text-5`,children:`Loading global assets…`}):r.length===0?(0,W.jsxs)(`p`,{className:`px-4 py-3 text-[11px] text-panel-text-5`,children:[`No assets in the global cache yet. Resolved media is promoted to `,(0,W.jsx)(`code`,{children:`~/.media`}),` and becomes reusable across projects.`]}):(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`px-4 py-2 border-t border-panel-border text-[11px] text-panel-text-5`,children:[r.length,` reusable across all projects`]}),r.map(e=>(0,W.jsxs)(`div`,{className:`px-4 py-1.5 flex items-center gap-2.5 border-l-2 border-transparent hover:bg-neutral-800/50`,title:`${e.id} \xB7 ${e.type}`,children:[(0,W.jsx)(`span`,{className:`text-[9px] font-medium text-neutral-600 uppercase w-10 shrink-0`,children:e.type}),(0,W.jsx)(`span`,{className:`text-xs text-panel-text-1 truncate`,children:e.label})]},e.id))]})}function ZRn({src:e,fallbackLabel:t}){let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{a(!1);let t=document.createElement(`video`);t.crossOrigin=`anonymous`,t.muted=!0,t.preload=`metadata`;let n=document.createElement(`canvas`),i=n.getContext(`2d`),o=()=>{t.removeEventListener(`error`,s),t.src=``,t.load()},s=()=>{t.getAttribute(`src`)&&(a(!0),o())};return t.addEventListener(`loadedmetadata`,()=>{t.currentTime=Math.min(2,t.duration*.1||2)}),t.addEventListener(`seeked`,()=>{i&&(n.width=t.videoWidth,n.height=t.videoHeight,i.drawImage(t,0,0),r(n.toDataURL(`image/jpeg`,.7)),o())}),t.addEventListener(`error`,s),t.src=e,t.load(),o},[e]),i&&!n?(0,W.jsx)(`div`,{className:`w-full h-full bg-neutral-800 flex items-center justify-center`,children:(0,W.jsx)(`span`,{className:`text-[9px] font-medium text-neutral-600`,children:t??`VIDEO`})}):n?(0,W.jsx)(`img`,{src:n,alt:``,draggable:!1,className:`w-full h-full object-contain`}):(0,W.jsx)(`div`,{className:`w-full h-full bg-neutral-800 animate-pulse motion-reduce:animate-none`})}function QRn(e,t){e.dataTransfer.effectAllowed=`copy`,e.dataTransfer.setData(dq,JSON.stringify({path:t})),e.dataTransfer.setData(`text/plain`,t)}function $Rn({feedback:e,asset:t}){return e?.path===t?(0,W.jsx)(`span`,{role:`status`,className:`shrink-0 text-[9px] font-medium px-1.5 py-px rounded ${e.ok?`text-accent-ink bg-panel-accent/10`:`text-danger-ink bg-red-500/10`}`,children:e.ok?`Copied`:`Copy failed`}):null}function ezn(e,t){e.preventDefault(),t({x:e.clientX,y:e.clientY})}function tzn(e,t){let[n,r]=(0,U.useState)(void 0);return(0,U.useEffect)(()=>{if(t)return;let n=!1,i,a=null;function o(e){e.onloadedmetadata=null,e.onerror=null,e.src=``}function s(t){if(n)return;let c=document.createElement(`video`);a=c,c.preload=`metadata`,c.muted=!0,c.onloadedmetadata=()=>{let e=Number.isFinite(c.duration)&&c.duration>0?c.duration:null;o(c),n||r(e)},c.onerror=()=>{o(c),n||(t<1?i=setTimeout(()=>s(t+1),50):r(null))},c.src=e}return s(0),()=>{n=!0,i&&clearTimeout(i),a&&o(a)}},[e,t]),n}function nzn({projectId:e,asset:t,used:n,duration:r,onCopy:i,copyFeedback:a,onDelete:o,onRename:s,onAddAssetToTimeline:c}){let[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(!1),[p,m]=(0,U.useState)(!1),h=a?.path===t&&a.ok,g=t.split(`/`).pop()??t,_=u9(t),v=LRn(t),y=P$(t,e),b=iq.test(t),x=rq.test(t),S=tzn(y,!b||r!=null),C=zRn(r??S??void 0??0),w=(0,U.useRef)(null),T=X(e=>e.setSelectedElementId),E=X(e=>e.requestTimelineFocus),D=X(e=>e.elements),O=O2(e=>e.setPreviewAsset),k=O2(e=>e.clearPreviewAsset),A=(0,U.useCallback)(e=>{w.current={x:e.clientX,y:e.clientY}},[]),j=(0,U.useCallback)(()=>{if(n){let e=WRn(D,t);if(e){k();let t=e.key??e.id;T(t),E(Bq(t));return}}O(t,e)},[n,D,t,e,T,E,O,k]),M=(0,U.useCallback)(e=>{let t=w.current;w.current=null,t&&qRn(e.clientX-t.x,e.clientY-t.y)&&j()},[j]);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{draggable:!0,role:`button`,tabIndex:0,"aria-label":`${_} \u2014 open, drag to timeline, right-click for actions`,onPointerDown:A,onPointerUp:M,onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),j())},onDragStart:e=>QRn(e,t),onContextMenu:e=>ezn(e,u),onPointerEnter:()=>f(!0),onPointerLeave:()=>f(!1),className:`flex flex-col gap-1 cursor-pointer rounded-md p-1 transition-colors outline-hidden focus-visible:bg-neutral-800/60 ${h?`bg-studio-accent/10`:`hover:bg-neutral-800/40`}`,children:[(0,W.jsxs)(`div`,{className:`w-full aspect-video rounded-sm overflow-hidden bg-neutral-900 relative`,children:[x&&!p&&(0,W.jsx)(`img`,{src:y,alt:_,loading:`lazy`,className:`w-full h-full object-cover`,onError:()=>m(!0)}),b&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(ZRn,{src:y}),d&&(0,W.jsx)(`video`,{src:y,autoPlay:!0,muted:!0,loop:!0,playsInline:!0,className:`absolute inset-0 w-full h-full object-cover`})]}),(!x&&!b||x&&p)&&(0,W.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,W.jsx)(`span`,{className:`text-[10px] font-medium text-neutral-600`,children:v})}),n&&(0,W.jsx)(`span`,{className:`absolute top-1 left-1 text-[9px] font-semibold leading-none px-1.5 py-[3px] rounded-sm bg-neutral-950/80 text-panel-text-1`,children:`Added`}),C&&(0,W.jsx)(`span`,{className:`absolute top-1 right-1 text-[9px] font-medium leading-none px-1.5 py-[3px] rounded-sm bg-neutral-950/80 text-panel-text-2 tabular-nums`,children:C})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-center gap-1`,children:[(0,W.jsx)(`span`,{className:`text-[10px] leading-tight text-center ${n?`text-panel-text-2`:`text-panel-text-4`}`,title:g,children:RRn(g,22)}),(0,W.jsx)($Rn,{feedback:a,asset:t})]})]}),l&&(0,W.jsx)(HRn,{x:l.x,y:l.y,asset:t,onClose:()=>u(null),onCopy:i,onDelete:o,onRename:s,onAddAtPlayhead:c})]})}function rzn({asset:e,used:t,onCopy:n,copyFeedback:r,onDelete:i,onRename:a,onAddAssetToTimeline:o}){let[s,c]=(0,U.useState)(null),l=u9(e),u=LRn(e),d=r?.path===e&&r.ok;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{draggable:!0,role:`button`,tabIndex:0,"aria-label":`${l} \u2014 copy path, drag to timeline, right-click for actions`,onClick:()=>n(e),onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},onDragStart:t=>QRn(t,e),onContextMenu:e=>ezn(e,c),className:`px-2.5 py-1.5 flex items-center gap-2.5 cursor-pointer transition-colors outline-hidden focus-visible:bg-neutral-800/60 ${d?`bg-studio-accent/10 border-l-2 border-studio-accent`:`border-l-2 border-transparent hover:bg-neutral-800/50`}`,children:[(0,W.jsx)(`div`,{className:`w-[50px] h-[32px] rounded-sm overflow-hidden bg-neutral-900 shrink-0 flex items-center justify-center`,children:(0,W.jsx)(`span`,{className:`text-[9px] font-medium text-text-muted`,children:u})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium truncate block ${t?`text-panel-text-1`:`text-panel-text-3`}`,children:l}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] text-neutral-600 truncate`,children:u}),t&&(0,W.jsx)(`span`,{className:`text-[9px] font-medium text-accent-ink bg-panel-accent/10 px-1.5 py-px rounded-sm`,children:`in use`}),(0,W.jsx)($Rn,{feedback:r,asset:e})]})]})]}),s&&(0,W.jsx)(HRn,{x:s.x,y:s.y,asset:e,onClose:()=>c(null),onCopy:n,onDelete:i,onRename:a,onAddAtPlayhead:o})]})}function izn(e,t,n){return n===`used`?e.filter(e=>t.has(e)):n===`unused`?e.filter(e=>!t.has(e)):e}function azn(e,t){let n=0;for(let r of e)t.has(r)&&n++;return{used:n,unused:e.length-n}}function ozn(e){let t=new Set;for(let n of e){if(!n.src)continue;let e=n.src;try{let t=new URL(e);e=t.pathname+(t.search?t.search:``)+(t.hash?t.hash:``)}catch{}e=e.replace(/^\/api\/projects\/[^/]+\/preview\//,``).replace(/^\.?\//,``).split(/[?#]/)[0];try{e=decodeURIComponent(e)}catch{}e&&t.add(e)}return t}function szn({importing:e,onClick:t}){return(0,W.jsxs)(`button`,{onClick:t,disabled:e,"aria-busy":e,className:`w-full flex items-center justify-center gap-1.5 rounded-md bg-panel-input px-3 py-[7px] text-[11px] font-medium text-panel-text-3 enabled:hover:text-panel-text-1 enabled:active:scale-[0.98] disabled:opacity-60 transition-colors mb-2.5`,children:[e?(0,W.jsxs)(`svg`,{className:`animate-spin`,width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,children:[(0,W.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,W.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z`})]}):(0,W.jsx)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,children:(0,W.jsx)(`path`,{d:`M12 5v14M5 12h14`})}),e?`Importing…`:`Import media`]})}function czn({searchQuery:e,onClearSearch:t}){return e?(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full px-4 gap-2`,children:[(0,W.jsxs)(`p`,{className:`text-[11px] text-neutral-500 text-center`,children:[`No assets match “`,e,`”`]}),(0,W.jsx)(`button`,{type:`button`,onClick:t,className:`px-2.5 py-1 text-[11px] font-medium rounded-md bg-panel-input text-panel-text-3 hover:text-panel-text-1 active:scale-[0.98] transition-colors`,children:`Clear search`})]}):(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full px-4 gap-2`,children:[(0,W.jsxs)(`svg`,{width:`24`,height:`24`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,className:`text-text-off`,children:[(0,W.jsx)(`path`,{d:`M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`polyline`,{points:`17 8 12 3 7 8`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`line`,{x1:`12`,y1:`3`,x2:`12`,y2:`15`,strokeLinecap:`round`})]}),(0,W.jsx)(`p`,{className:`text-[10px] text-neutral-600 text-center`,children:`Drop media files here`})]})}var lzn=(0,U.memo)(function({projectId:e,assets:t,onImport:n,onDelete:r,onRename:i,onAddAssetToTimeline:a}){let o=(0,U.useRef)(null),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(!1),[p,m]=(0,U.useState)(`all`),[h,g]=(0,U.useState)(`all`),[_,v]=(0,U.useState)(``),[y,b]=(0,U.useState)(`local`),[x,S]=(0,U.useState)(new Map),C=(0,U.useRef)(new Set),w=t.join(`|`);(0,U.useEffect)(()=>{if(C.current.has(e))return;let t=!1;return H(M(e,`/preview/.media/manifest.jsonl`)).then(t=>t.ok?t.text():(C.current.add(e),``)).then(e=>{if(t||!e)return;let n=new Map;for(let t of e.split(`