@dnyantra/dtly 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -8
- package/dist/agents.d.ts +1 -0
- package/dist/agents.js +9 -4
- package/dist/agents.js.map +1 -1
- package/dist/cli.js +35 -5
- package/dist/cli.js.map +1 -1
- package/dist/core/anim.js +20 -0
- package/dist/core/anim.js.map +1 -1
- package/dist/core/captions.d.ts +13 -0
- package/dist/core/captions.js +57 -0
- package/dist/core/captions.js.map +1 -0
- package/dist/core/geo.d.ts +13 -0
- package/dist/core/geo.js +41 -0
- package/dist/core/geo.js.map +1 -0
- package/dist/core/model.d.ts +112 -9
- package/dist/core/model.js.map +1 -1
- package/dist/core/path.d.ts +35 -0
- package/dist/core/path.js +324 -0
- package/dist/core/path.js.map +1 -0
- package/dist/core/svg.d.ts +22 -0
- package/dist/core/svg.js +217 -0
- package/dist/core/svg.js.map +1 -0
- package/dist/core/text.d.ts +3 -1
- package/dist/core/text.js +49 -3
- package/dist/core/text.js.map +1 -1
- package/dist/mcp/server.js +28 -1
- package/dist/mcp/server.js.map +1 -1
- package/dist/ops/ops.d.ts +7 -0
- package/dist/ops/ops.js +11 -1
- package/dist/ops/ops.js.map +1 -1
- package/dist/presets/app.d.ts +2 -0
- package/dist/presets/app.js +82 -0
- package/dist/presets/app.js.map +1 -0
- package/dist/presets/captions.d.ts +2 -0
- package/dist/presets/captions.js +48 -0
- package/dist/presets/captions.js.map +1 -0
- package/dist/presets/charts.d.ts +2 -0
- package/dist/presets/charts.js +162 -0
- package/dist/presets/charts.js.map +1 -0
- package/dist/presets/index.d.ts +1 -1
- package/dist/presets/index.js +62 -1
- package/dist/presets/index.js.map +1 -1
- package/dist/presets/maps.d.ts +2 -0
- package/dist/presets/maps.js +79 -0
- package/dist/presets/maps.js.map +1 -0
- package/dist/render/fx.d.ts +11 -0
- package/dist/render/fx.js +87 -0
- package/dist/render/fx.js.map +1 -0
- package/dist/render/grade.d.ts +20 -0
- package/dist/render/grade.js +178 -0
- package/dist/render/grade.js.map +1 -0
- package/dist/render/lottie.d.ts +36 -0
- package/dist/render/lottie.js +523 -0
- package/dist/render/lottie.js.map +1 -0
- package/dist/render/node-host.d.ts +1 -0
- package/dist/render/node-host.js +15 -4
- package/dist/render/node-host.js.map +1 -1
- package/dist/render/perspective.d.ts +5 -0
- package/dist/render/perspective.js +71 -0
- package/dist/render/perspective.js.map +1 -0
- package/dist/render/renderer.d.ts +6 -0
- package/dist/render/renderer.js +156 -95
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/shapes.d.ts +6 -0
- package/dist/render/shapes.js +129 -0
- package/dist/render/shapes.js.map +1 -0
- package/dist/render/tiles.d.ts +11 -0
- package/dist/render/tiles.js +42 -0
- package/dist/render/tiles.js.map +1 -0
- package/dist/render/transcribe.d.ts +14 -0
- package/dist/render/transcribe.js +55 -0
- package/dist/render/transcribe.js.map +1 -0
- package/dist/studio/server.js +14 -1
- package/dist/studio/server.js.map +1 -1
- package/dist/studio-app/app.js +5 -4
- package/dist/studio-app/app.js.map +4 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/plugin/skills/{dtly → moti}/SKILL.md +26 -6
package/dist/studio-app/app.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
var O,Ht,Yn,ge,ut,Ge,Bt,Je,Kt,ht,mt,Gn,Ze={},Qe=[],Zn=/^m(i|n|o|s|text|space)$/,gt=Array.isArray,Wt=Qe.slice,ke=Object.assign;function xe(e){e&&e.parentNode&&e.remove()}function Xe(e,t,n,o,i){var r={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i||++Ht,__i:-1,__u:0};return!i&&O.vnode&&O.vnode(r),r}function ye(e){return e.children}function Ye(e,t){this.props=e,this.context=t,this.__g=0}function be(e,t){if(t==null)return e.__&&be(e.__,e.__i+1);for(var n;t<e.__k.length;t++)if((n=e.__k[t])&&n.__e)return n.__e;return typeof e.type!="function"||e.props.__P?null:be(e)}function Ut(e){if((e=e.__)&&e.__c&&!e.props.__P)return e.__e=null,e.__k.some(function(t){return t&&(e.__e=t.__e)}),Ut(e)}function Dt(e){(8&e.__g||(e.__g|=8,ge.push(e),Ge++))&&ut==O.debounceRendering||((ut=O.debounceRendering)||queueMicrotask)(qt)}function qt(){var e,t,n,o,i,r,a,s,c;try{for(t=1;ge.length;)ge.length>t&&ge.sort(Bt),e=ge.shift(),t=ge.length,8&e.__g&&(o=void 0,i=void 0,r=(i=(n=e).__v).__e,a=[],s=[],(c=n.__P)&&((o=ke({constructor:void 0},i)).__v=i.__v+1,O.vnode&&O.vnode(o),bt(c,o,i,n.__n,c.namespaceURI,32&i.__u?[r]:null,a,r||be(i),32&i.__u,s),o.__v=i.__v,o.__.__k[o.__i]=o,Gt(a,o,s),i.__=i.__e=null,o.__e!=r&&Ut(o)))}finally{(Ge=ge.length)&&(ut||queueMicrotask)(qt)}}function Jt(e,t,n,o,i,r,a,s,c,u,p){var m,h,d,f,g,v,y=o.__k||Qe,k=t.length;for(c=Qn(n,t,y,c,k),m=0;m<k;m++)(d=n.__k[m])!=null&&(h=~d.__i&&y[d.__i]||Ze,d.__i=m,v=bt(e,d,h,i,r,a,s,c,u,p),f=d.__e,(h.ref!=d.ref||8&h.__u)&&(h.ref&&yt(h.ref,null,d,h),d.ref&&p.push(d.ref,d.__c||f,d)),g=g||f,4&d.__u?(c=Xt(d,c,e,!h.__v),h.__e&&(h.__e=null)):typeof d.type=="function"&&v!==void 0?c=v:f&&(c=f.nextSibling),d.__u&=-21);return n.__e=g,c}function Qn(e,t,n,o,i){var r,a,s,c,u,p,m,h,d,f=n.length,g=f,v=0,y=0,k=e.__k=Array(i);for(r=0;r<i;r++)(a=t[r])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a!="object"||a.constructor==String?a=k[r]=Xe(null,a):gt(a)?a=k[r]=Xe(ye,{children:a}):a.constructor===void 0&&a.__b?a=k[r]=Xe(a.type,a.props,a.key,a.ref,a.__v):k[r]=a,c=r+v,a.__=e,a.__b=e.__b+1,s=null,~(u=a.__i=eo(a,n,c,g))&&(g--,(s=n[u])&&(s.__u|=2)),s&&s.__v?(a.__u|=16,u==c-1?v--:u==c+1?v++:u!=c&&(u>c?v--:v++,y=1)):(~u||(i>f?v--:i<f&&v++),typeof a.type!="function"&&(a.__u|=4))):k[r]=null;if(y){for(p=[],m=[],r=0;r<i;r++)if((a=k[r])&&16&a.__u){for(v=0,h=p.length;v<h;)p[d=v+h>>1]<a.__i?v=d+1:h=d;p[v]=a.__i,m[r]=v+1}for(v=p.length;r--;)m[r]&&(m[r]==v?v--:k[r].__u|=4)}if(g)for(r=0;r<f;r++)!(s=n[r])||2&s.__u||(s.__e==o&&(o=be(s)),_t(s,s));return o}function Xt(e,t,n,o){var i,r,a,s;if(typeof e.type=="function"){if(e.props.__P)return t;if(i=e.__k)for(r=0;r<i.length;r++)i[r]&&(i[r].__=e,t=Xt(i[r],t,n,!1));return t}for(t&&!t.parentNode&&(t=be(e))&&!t.parentNode&&(t=null),a=e.__e,s=t;s&&s.nodeType==8;)s=s.nextSibling;for(a!=s&&(!o&&n.moveBefore&&a.parentNode?n.moveBefore(a,t):n.insertBefore(a,t||null)),t=a;(t=t&&t.nextSibling)&&t.nodeType==8&&!t.data.startsWith("$s"););return t}function eo(e,t,n,o){var i,r=e.key,a=e.type,s=t[n],c=s&&!(2&s.__u);if(s===null&&r==null||c&&r==s.key&&a==s.type)return n;if(o>(c?1:0)){for(i=n-1;i>=0;i--)if((s=t[i])&&!(2&s.__u)&&r==s.key&&a==s.type)return i;for(i=n+1;i<t.length;i++)if((s=t[i])&&!(2&s.__u)&&r==s.key&&a==s.type)return i}return-1}function Vt(e,t,n){n==null&&(n=""),t[0]=="-"?e.setProperty(t,n):e[t]=n}function qe(e,t,n,o,i){var r,a;if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||Vt(e.style,t);if(n)for(t in n)o&&n[t]==o[t]||Vt(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")(e.__e||(e.__e={}))[t]=n,n&&o||(a=mt[t]||(mt[t]=to(t)),(e.__a||(e.__a={}))[t]=ht,r=t!=(t=t.replace(Kt,"$1")),(t=t.slice(2))[0]<"a"&&(t=t.toLowerCase()),n?e.addEventListener(t,a,r):e.removeEventListener(t,a,r));else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{return void(e[t]=n??"")}catch{}if(typeof n=="function")return;n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n)}}function to(e){return function(t){var n=this.__e;if(n){if(n=n[e],t[Je]==null)t[Je]=ht++;else if(t[Je]<this.__a[e])return;return n(O.event?O.event(t):t)}}}function bt(e,t,n,o,i,r,a,s,c,u){var p,m,h,d,f,g,v,y,k,L,b,M,w,$,_,x,C,P,T=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(c=32&n.__u,p=n.__c.__z)&&(t.__u|=c,m=r=[],p.nodeType==8?s=ft(p,r):r.push(p),s=r[0]||s),(p=O.__b)&&p(t);e:if(typeof T=="function"){h=a.length;try{if(y=t.props,k=(p=T.prototype)&&p.render,L=(p=T.contextType)&&o[p.__c],b=p?L?L.props.value:p.__:o,(d=n.__c)?(t.__c=d,2&d.__g&&(d.__g|=1)):(k?t.__c=d=new T(y,b):(t.__c=d=new Ye(y,b),d.constructor=T,d.render=oo),L&&L.sub(d),d.state||(d.state={}),d.__n=o,d.__g|=8,d.__h=[],d.__k=[]),k&&(d.__s||(d.__s=d.state),T.getDerivedStateFromProps&&(d.__s==d.state&&(d.__s=ke({},d.__s)),ke(d.__s,T.getDerivedStateFromProps(y,d.__s)))),f=d.props,g=d.state,d.__v=t,n.__c){if(y!==f&&k&&!T.getDerivedStateFromProps&&d.componentWillReceiveProps&&d.componentWillReceiveProps(y,b),t.__v==n.__v&&!(8&d.__g)||!(4&d.__g)&&d.shouldComponentUpdate&&d.shouldComponentUpdate(y,d.__s,b)===!1){t.__v!=n.__v&&(d.props=y,d.state=d.__s,d.__g&=-9),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(j){j&&(j.__=t)}),Qe.push.apply(d.__h,d.__k),d.__k=[],d.__h.length&&a.push(d),s=be(n);break e}d.componentWillUpdate&&d.componentWillUpdate(y,d.__s,b),k&&d.componentDidUpdate&&d.__h.push(function(){d.componentDidUpdate(f,g,v)})}else k&&!T.getDerivedStateFromProps&&d.componentWillMount&&d.componentWillMount(),k&&d.componentDidMount&&d.__h.push(d.componentDidMount);if(d.context=b,d.props=y,d.__P=e,d.__g&=-5,M=O.__r,w=0,k)d.state=d.__s,d.__g&=-9,M&&M(t),p=d.render(d.props,d.state,d.context),Qe.push.apply(d.__h,d.__k),d.__k=[];else do d.__g&=-9,M&&M(t),p=d.render(d.props,d.state,d.context),d.state=d.__s;while(8&d.__g&&++w<25);d.state=d.__s,d.getChildContext&&(o=ke({},o,d.getChildContext())),k&&n.__c&&d.getSnapshotBeforeUpdate&&(v=d.getSnapshotBeforeUpdate(f,g)),$=p&&p.type===ye&&p.key==null?p.props.children:p,y.__P&&(p=s,i=(e=y.__P).namespaceURI,c=r=null,n.props&&n.props.__P!=e&&(n.__k.some(function(j){j&&_t(j,j)}),n.__k=null),s=n.__k?be(n,0):null),s=Jt(e,gt($)?$:[$],t,n,o,i,r,a,s,c,u),y.__P&&(t.__e=null,s=p),t.__u&=-161,m&&m.some(xe),d.__h.length&&a.push(d),1&d.__g&&(d.__g&=-4)}catch(j){if(a.length=h,t.__v=null,c||r)if(j.then){if(_=0,t.__u|=128|c,r){for(~(C=r.indexOf(s||void 0))||(C=r.length);(P=r[C-1])&&P.nodeType==8;)C--;for(;C<r.length;C++)if(P=r[C]){if(r[C]=null,P.nodeType==8){if(P.data.startsWith("$s"))_++||(x=P);else if(_&&P.data.startsWith("/$s")&&!--_)break}else if(!_)break}}if(!x){for(;s&&s.nodeType==8&&s.nextSibling;)s=s.nextSibling;x=s}(p=ft(x=t.__c.__z||(t.__c.__z=x)))?(t.__e=x,s=p):t.__e=s,s=s&&s.nextSibling}else r&&r.some(xe);else t.__e=n.__e;t.__k||(t.__k=n.__k||[]),j.then||Yt(t),O.__e(j,t,n)}}else s=t.__e=no(n.__e,t,n,o,i,r,a,c,u,e);return(p=O.diffed)&&p(t),s}function ft(e,t){if(e&&e.nodeType==8&&e.data.startsWith("$s"))for(var n=1;e=e.nextSibling;){if(e.nodeType==8){if(e.data.startsWith("$s"))n++;else if(e.data.startsWith("/$s")&&!--n)return e}t&&t.push(e)}}function Yt(e){e&&(e.__c&&(e.__c.__g|=4),e.__k&&e.__k.some(Yt))}function Gt(e,t,n){for(var o=0;o<n.length;)yt(n[o++],n[o++],n[o++]);O.__c&&O.__c(t,e),e.some(function(i){try{e=i.__h,i.__h=[],e.some(function(r){r.call(i)})}catch(r){O.__e(r,i.__v)}})}function no(e,t,n,o,i,r,a,s,c,u){var p,m,h,d,f,g,v,y,k,L=n.props||Ze,b=t.props,M=t.type;if(M=="svg"?i="http://www.w3.org/2000/svg":M=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),r){for(p=0;p<r.length;p++)if((f=r[p])&&(M?f.localName==M:f.nodeType==3)){e=f,r[p]=null;break}}if(!e){if(y=u.ownerDocument||document,!M)return y.createTextNode(b);e=y.createElementNS(i,M,b.is&&b),s&&(O.__m&&O.__m(t,r),s=!1),r=null}if(M){if(u=M=="template"?e.content:e,r=M=="textarea"&&b.defaultValue!=null?null:r&&Wt.call(u.childNodes),!s&&r)for(L={},p=0;p<e.attributes.length;p++)L[(f=e.attributes[p]).name]=f.value;for(p in L)f=L[p],p=="dangerouslySetInnerHTML"?h=f:p=="children"||p in b||p=="value"&&"defaultValue"in b||p=="checked"&&"defaultChecked"in b||qe(e,p,null,f,i);for(p in k=1&n.__u,b)f=b[p],p=="children"?d=f:p=="dangerouslySetInnerHTML"?m=f:p=="value"?g=f:p=="checked"?v=f:s&&typeof f!="function"||!(L[p]!==f||k&&f!=null)||qe(e,p,f,L[p],i);m?(s||h&&(m.__html==h.__html||m.__html==e.innerHTML)||(e.innerHTML=m.__html),t.__k=[]):(h&&(e.textContent=""),(M=="foreignObject"||i=="http://www.w3.org/1998/Math/MathML"&&Zn.test(M))&&(i="http://www.w3.org/1999/xhtml"),Jt(u,gt(d)?d:[d],t,n,o,i,r,a,r?r[0]:n.__k&&be(n,0),s,c),r&&r.some(xe)),s&&M!="textarea"||(p="value",M=="progress"&&g==null?e.removeAttribute(p):g==null||g===e[p]&&(M!="progress"||g)||qe(e,p,g,L[p],i),p="checked",v!=null&&v!=e[p]&&qe(e,p,v,L[p],i))}else L===b||s&&e.data==b||(e.data=b);return e}function yt(e,t,n,o){try{typeof e=="function"?t?t.__x=e(t)||1:o&&(o=o.__c||o.__e)&&(t=o.__x)&&(o.__x=null,typeof t=="function"?t():e(null)):e.current=t}catch(i){O.__e(i,n)}}function _t(e,t,n){var o,i,r,a;if(O.unmount&&O.unmount(e),!(o=e.ref)||o.current&&o.current!=e.__e||yt(o,null,t,e),o=e.__c){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(s){O.__e(s,t)}o.__P=o.__n=null}if(o=e.__k)for(a=0;a<o.length;a++)o[a]&&_t(o[a],t,typeof e.type!="function"||n&&!e.props.__P);!n&&(o=e.__c)&&(o=o.__z)&&(i=ft(o,r=[]))&&(o==e.__e&&r.some(xe),xe(i),xe(o)),(o=e.__e)&&(n||xe(o),o.__e&&(o.__e=null)),e.__e=e.__c=e.__=null}function oo(e,t,n){return this.constructor(e,n)}function Zt(e,t){var n,o,i,r;O.__&&O.__(e,t),t.nodeType==9&&(t=t.documentElement),o=(n=e&&32&e.__u)?null:t.__k,t.__k=Xe(ye,{children:[e]}),i=[],r=[],bt(t,t.__k,o||Ze,Ze,t.namespaceURI,o?null:t.firstChild?Wt.call(t.childNodes):null,i,o?o.__e:t.firstChild,n,r),Gt(i,t.__k,r),t.__k.props.children=null}O={__e:function(e,t,n,o){for(var i,r,a;t=t.__;)if((i=t.__c)&&!(1&i.__g)){i.__g|=4;try{if((a=(r=i.constructor)&&r.getDerivedStateFromError)&&i.setState(r.getDerivedStateFromError(e)),i.componentDidCatch&&(i.componentDidCatch(e,o||{}),a=1),a&&8&i.__g)return void(i.__g|=2)}catch(s){e=s}}throw Ge=0,e}},Ht=0,Yn=function(e){return e!=null&&e.constructor===void 0},Ye.prototype.setState=function(e,t){var n=this.__s;n&&n!=this.state||(n=this.__s=ke({},this.state)),typeof e=="function"&&(e=e(ke({},n),this.props)),e&&(ke(n,e),this.__v&&(t&&this.__k.push(t),Dt(this)))},Ye.prototype.forceUpdate=function(e){this.__v&&(this.__g|=4,e&&this.__h.push(e),Dt(this))},Ye.prototype.render=ye,ge=[],Ge=0,Bt=function(e,t){return e.__v.__b-t.__v.__b},Je=Symbol(),Kt=/(PointerCapture)$|Capture$/i,ht=0,mt={},Gn=0;var Fe,B,vt,Qt,wt=Object.is,et=0,cn=[],xt=[],V=O,en=V.__b,tn=V.__r,nn=V.diffed,on=V.__c,rn=V.unmount,an=V.__;function Ct(e,t){V.__h&&V.__h(B,e,et||t),et=0;var n=B.__H||(B.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function Y(e){return et=1,ro(pn,e)}function ro(e,t,n){var o=Ct(Fe++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):pn(void 0,t),function(r){var a=o.__N?o.__N[0]:o.__[0],s=o.t(a,r);wt(a,s)||(o.__N=[s,o.__[1]],o.__c.setState({}))}],o.__c=B,!B.__f)){B.__f=!0;var i=B.shouldComponentUpdate;B.shouldComponentUpdate=function(r,a,s){var c=this.__H;if(!c)return!0;var u=!1,p=this.props!=r;if(c.__.some(function(h){h.__N&&(u=!0,wt(h.__[0],h.__N[0])||(p=!0))}),i){var m=i.call(this,r,a,s);return u?m||p:m}return!u||p}}return o.__}function ae(e,t){var n=Ct(Fe++,3);!V.__s&&dn(n.__H,t)&&(n.__P=!0,n.__=e,n.u=t,B.__H.__h.push(n))}function re(e){return et=5,io(function(){return{current:e}},[])}function io(e,t){var n=Ct(Fe++,7);return dn(n.__H,t)&&(n.__=e(),n.__H=t),n.__}function ao(){var e;do{for(;e=xt.shift();)try{Oe(e)}catch(n){V.__e(n,{__:(e=e.__P)&&e.__v})}for(;e=cn.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Oe),t.__h.some(kt),t.__h=[]}catch(n){t.__h=[],V.__e(n,e.__v)}}}while(xt.length)}V.__b=function(e){B=null,en&&en(e)},V.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),an&&an(e,t)},V.__r=function(e){tn&&tn(e),Fe=0;var t=(B=e.__c).__H;t&&(vt==B?B.__h=[]:(t.__h.some(Oe),t.__h.some(kt),Fe=0),t.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})),vt=B},V.diffed=function(e){nn&&nn(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&ln(cn.push(t)),t.__H.__.some(function(n){n.u&&(n.__H=n.u)})),vt=B=null},V.__c=function(e,t){t.some(function(n){try{n.__h.some(Oe),n.__h=n.__h.filter(function(o){return!o.__||kt(o)})}catch(o){t.some(function(i){i.__h&&(i.__h=[])}),t=[],V.__e(o,n.__v)}}),on&&on(e,t)},V.unmount=function(e){rn&&rn(e);var t,n,o=e.__c;o&&o.__H&&(o.__H.__.some(function(i){try{if(i.__P&&i.__c){if(n===void 0){for(n=e.__;n&&(!n.__c||!n.__c.__P);)n=n.__;n=n&&n.__c}i.__P=n,ln(xt.push(i))}else Oe(i)}catch(r){t=r}}),o.__H=void 0,t&&V.__e(t,o.__v))};var sn=typeof requestAnimationFrame=="function";function so(e){var t,n=function(){clearTimeout(o),sn&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);sn&&(t=requestAnimationFrame(n))}function ln(e){e!=1&&Qt==V.requestAnimationFrame||((Qt=V.requestAnimationFrame)||so)(ao)}function Oe(e){var t=B,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),B=t}function kt(e){var t=B;e.__c=e.__(),B=t}function dn(e,t){return!e||e.length!=t.length||t.some(function(n,o){return!wt(n,e[o])})}function pn(e,t){return typeof t=="function"?t(e):t}var te=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&"keyframes"in e;var Q=class extends Error{};var pe=(e,t)=>{let n=e.comps.find(o=>o.id===(t??e.root));if(!n)throw new Q(`No composition "${t}". Comps: ${e.comps.map(o=>o.id).join(", ")}`);return n},K=(e,t)=>{for(let n of e.comps){let o=n.layers.findIndex(i=>i.id===t);if(o>=0)return{comp:n,layer:n.layers[o],index:o}}throw new Q(`No layer "${t}"`)},un=e=>new Set(e.comps.flatMap(t=>t.layers.map(n=>n.id))),mn=(e,t)=>{let n=un(e),o=t.replace(/[^a-zA-Z0-9_-]+/g,"-").replace(/^-|-$/g,"")||"layer";if(!n.has(o))return o;let i=2;for(;n.has(`${o}-${i}`);)i++;return`${o}-${i}`},fn=(e,t)=>{if(e.comps.some(i=>i.id===t.id))throw new Q(`Composition "${t.id}" already exists`);let n=pe(e),o={width:n.width,height:n.height,fps:n.fps,duration:n.duration,layers:[],...t};return e.comps.push(o),o},hn=(e,t,n)=>{Object.assign(pe(e,t),n)},ie=(e,t,n,o=0)=>{let i=pe(e,t),r=n.id?un(e).has(n.id)?(()=>{throw new Q(`Layer id "${n.id}" already used`)})():n.id:mn(e,n.name??n.type),a={...n,id:r};return i.layers.splice(Math.max(0,Math.min(o,i.layers.length)),0,a),a},Pt=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),gn=(e,t)=>{for(let[n,o]of Object.entries(t))o===null?delete e[n]:Pt(o)&&Pt(e[n])&&!("keyframes"in o)?gn(e[n],o):e[n]=o;return e},ee=(e,t,n)=>{if("id"in n)throw new Q("Cannot change a layer id; duplicate it instead");let{layer:o}=K(e,t);return gn(o,n),o},tt=(e,t)=>{let{comp:n,index:o}=K(e,t);n.layers.splice(o,1);for(let i of e.comps)for(let r of i.layers)r.parent===t&&delete r.parent,r.matte?.layer===t&&delete r.matte},St=(e,t,n)=>{let{comp:o,index:i,layer:r}=K(e,t);o.layers.splice(i,1),o.layers.splice(Math.max(0,Math.min(n,o.layers.length)),0,r)},Mt=(e,t)=>{Array.isArray(e)?e.forEach(n=>Mt(n,t)):Pt(e)&&(Array.isArray(e.keyframes)&&t(e.keyframes),Object.values(e).forEach(n=>Mt(n,t)))},ze=(e,t,n)=>{let{layer:o}=K(e,t);(o.inPoint!==void 0||n)&&(o.inPoint=(o.inPoint??0)+n),o.outPoint!==void 0&&(o.outPoint+=n),Mt(o,i=>i.forEach(r=>r.t=+(r.t+n).toFixed(4)))},nt=(e,t,n={})=>{let{comp:o,index:i,layer:r}=K(e,t),a=structuredClone(r);return a.id=n.newId??mn(e,r.id),o.layers.splice(i,0,a),n.timeShift&&ze(e,a.id,n.timeShift),a},bn=e=>e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t),ot=(e,t)=>bn(t).reduce((n,o)=>n?.[o],e),Lt=(e,t,n)=>{let o=bn(t),i=e;o.slice(0,-1).forEach((r,a)=>{i[r]==null&&(i[r]=typeof o[a+1]=="number"?[]:{}),i=i[r]}),i[o[o.length-1]]=n},Le=.001,Ne=(e,t,n,o)=>{let{layer:i}=K(e,t);Lt(i,n,o)},q=(e,t,n,o,i,r)=>{let{layer:a}=K(e,t),s=ot(a,n),c;if(te(s))c=s.keyframes;else{c=[];let p=a.inPoint??0;s!==void 0&&Math.abs(p-o)>Le&&c.push({t:p,v:s}),Lt(a,n,{keyframes:c})}let u=c.find(p=>Math.abs(p.t-o)<Le);return u?(u.v=i,r!==void 0&&(u.ease=r)):c.push(r!==void 0?{t:o,v:i,ease:r}:{t:o,v:i}),c.sort((p,m)=>p.t-m.t),c},Re=(e,t,n,o)=>{let{layer:i}=K(e,t),r=ot(i,n);if(!r||!te(r))throw new Q(`${t}.${n} is not animated`);let a=r.keyframes.findIndex(s=>Math.abs(s.t-o)<Le);if(a<0)throw new Q(`No keyframe at ${o}s on ${t}.${n}`);r.keyframes.splice(a,1),r.keyframes.length===1&&!r.wiggle&&Lt(i,n,r.keyframes[0].v)},yn=(e,t,n,o,i)=>{let{layer:r}=K(e,t),a=ot(r,n),s=a?.keyframes?.find(u=>Math.abs(u.t-o)<Le);if(!a||!s)throw new Q(`No keyframe at ${o}s on ${t}.${n}`);let c=Math.round(i*1e3)/1e3;if(a.keyframes.some(u=>u!==s&&Math.abs(u.t-c)<Le))throw new Q(`There is already a keyframe at ${c}s`);s.t=c,a.keyframes.sort((u,p)=>u.t-p.t)},Et=(e,t,n,o,i)=>{let{layer:r}=K(e,t),s=ot(r,n)?.keyframes?.find(c=>Math.abs(c.t-o)<Le);if(!s)throw new Q(`No keyframe at ${o}s on ${t}.${n}`);s.ease=i};var _e={typewriter:{description:"Letters appear one by one with no motion.",animators:[{unit:"grapheme",stagger:.05,duration:.01,ease:"hold",from:{opacity:0}}]},fadeUp:{description:"Words fade in while rising slightly. Calm, readable default.",animators:[{unit:"word",stagger:.08,duration:.6,ease:"cubicOut",from:{opacity:0,y:40}}]},popIn:{description:"Words scale up from zero with an overshoot. Playful, energetic.",animators:[{unit:"word",stagger:.1,duration:.55,ease:"backOut",from:{opacity:0,scale:0}}]},slam:{description:"Words crash in from huge and blurred. Punchy kinetic typography.",animators:[{unit:"word",stagger:.18,duration:.35,ease:"expoOut",from:{opacity:0,scale:320,blur:14}}]},blurIn:{description:"Letters sharpen from a blur. Elegant, premium.",animators:[{unit:"grapheme",stagger:.03,duration:.7,ease:"cubicOut",from:{opacity:0,blur:18,x:-20}}]},maskedLines:{description:"Each line slides up from behind its own mask. The classic title reveal.",animators:[{unit:"line",stagger:.12,duration:.8,ease:"expoOut",clip:!0,from:{y:120}}]},cascade:{description:"Letters drop and rotate into place with an overshoot.",animators:[{unit:"grapheme",stagger:.035,duration:.7,ease:"backOut",from:{opacity:0,y:-70,rotation:-25}}]},trackingIn:{description:"Letter spacing collapses from wide to normal while fading in. Cinematic openers.",animators:[{unit:"grapheme",stagger:0,duration:1.4,ease:"expoOut",from:{opacity:0,tracking:60}}]},centerOut:{description:"Letters grow outward from the middle of the word.",animators:[{unit:"grapheme",order:"center",stagger:.04,duration:.5,ease:"backOut",from:{opacity:0,scale:0}}]},randomFlicker:{description:"Letters switch on in random order.",animators:[{unit:"grapheme",order:"random",stagger:.03,duration:.08,ease:"hold",from:{opacity:0}}]},colorSweep:{description:"A highlight colour sweeps through the letters, settling to the text colour.",animators:[{unit:"grapheme",stagger:.04,duration:.5,ease:"easeOut",from:{color:"#FFC93C",scale:115}}]},fadeOutDown:{description:"Exit: words fade out while dropping.",animators:[{unit:"word",mode:"out",stagger:.05,duration:.4,ease:"easeIn",from:{opacity:0,y:40}}]},blurOut:{description:"Exit: letters blur away.",animators:[{unit:"grapheme",mode:"out",stagger:.02,duration:.45,ease:"easeIn",from:{opacity:0,blur:16}}]},maskedLinesOut:{description:"Exit: lines slide up out of their masks.",animators:[{unit:"line",mode:"out",stagger:.08,duration:.5,ease:"expoInOut",clip:!0,from:{y:-120}}]}};var D=(e,t)=>typeof e=="number"?e:t,R=(e,t)=>typeof e=="string"?e:t,Ee=e=>Math.round(e*1e3)/1e3,G=(...e)=>({keyframes:e.map(([t,n,o])=>o?{t:Ee(t),v:n,ease:o}:{t:Ee(t),v:n})}),J={};for(let[e,t]of Object.entries(_e))J[`text.${e}`]={kind:"text",description:t.description,params:"{layer: textLayerId, delay?: s, stagger?: s, duration?: s, replace?: boolean}",apply:(n,o,i)=>{let{layer:r}=K(n,R(i.layer,""));if(r.type!=="text")throw new Q(`${r.id} is not a text layer`);let a=t.animators.map(s=>({...s,...i.delay!==void 0&&{delay:D(i.delay,0)},...i.stagger!==void 0&&{stagger:D(i.stagger,0)},...i.duration!==void 0&&{duration:D(i.duration,.5)}}));return r.animators=i.replace===!1?[...r.animators??[],...a]:[...(r.animators??[]).filter(s=>s.mode==="out"!=(a[0].mode==="out")),...a],{created:[],note:`Applied ${e} to ${r.id}`}}};J["kinetic.sequence"]={kind:"kinetic",description:"Classic kinetic typography: phrases appear one after another in the same spot, each with its own entrance, emphasis words bigger and coloured.",params:'{phrases: string[], start?: s, each?: s (default by length), position?: [x,y], size?: px, color?, accent?: color, emphasis?: string[] (words to highlight), style?: "slam"|"popIn"|"fadeUp"|"blurIn"|"cascade", font?, maxWidth?, holdLast?: boolean (default true: last phrase stays to the end of the comp)}',apply:(e,t,n)=>{let o=pe(e,t),i=n.phrases??[],r=n.position??[o.width/2,o.height/2],a=D(n.size,Math.round(o.width/9)),s=R(n.style,"slam"),c=new Set((n.emphasis??[]).map(h=>h.toLowerCase())),u=D(n.start,0),p=[],m=n.holdLast!==!1;return i.forEach((h,d)=>{let f=h.split(/\s+/).length,g=D(n.each,Math.max(.7,.35+f*.32)),v=m&&d===i.length-1,y=v?Math.max(o.duration,u+g):u+g,k=h.split(/\s+/).some(b=>c.has(b.toLowerCase())),L=ie(e,o.id,{type:"text",name:`kinetic-${d+1}`,text:h,inPoint:Ee(u),outPoint:Ee(y),size:k?Math.round(a*1.35):a,weight:800,font:n.font,color:k?R(n.accent,"#FFC93C"):R(n.color,"#ffffff"),maxWidth:D(n.maxWidth,o.width*.86),transform:{position:r,scale:G([u,[100,100]],[y,[100+8*((y-u)/g),100+8*((y-u)/g)]])},animators:[..._e[s in _e?s:"slam"].animators,...v?[]:[{unit:"word",mode:"out",stagger:.03,duration:.18,ease:"easeIn",from:{opacity:0,scale:80}}]]});p.push(L.id),u=Ee(u+g)}),{created:p,note:`Sequence ends at ${u.toFixed(2)}s`}}};J["opener.logoReveal"]={kind:"opener",description:"Brand opener: a ring draws on and bursts, the title tracks in, an accent line draws, and a tagline reveals from a mask.",params:"{title: string, tagline?: string, start?: s, color?: brand colour, accent?: colour, textColor?, position?: [x,y], size?: px, font?}",apply:(e,t,n)=>{let o=pe(e,t),i=D(n.start,0),[r,a]=n.position??[o.width/2,o.height/2],s=R(n.color,"#E8692A"),c=R(n.accent,"#FFC93C"),u=D(n.size,Math.round(o.width/7.5)),p=Math.min(o.width,o.height)*.42,m=[],h=d=>m.push(ie(e,o.id,d).id);return h({type:"shape",name:"reveal-ring",shape:"ellipse",size:[p,p],stroke:s,strokeWidth:10,inPoint:i,outPoint:i+1.6,motionBlur:{samples:8},transform:{position:[r,a],rotation:G([i,-120,"expoOut"],[i+1,0]),scale:G([i+.7,[100,100],"expoOut"],[i+1.4,[260,260]]),opacity:G([i+.9,100],[i+1.4,0])},trim:{end:G([i,0,"expoOut"],[i+.8,100])}}),h({type:"shape",name:"reveal-burst",shape:"ellipse",size:[p*.9,p*.9],fill:s,inPoint:i+.7,outPoint:i+1.5,transform:{position:[r,a],scale:G([i+.7,[0,0],"expoOut"],[i+1.2,[220,220]]),opacity:G([i+.9,90],[i+1.5,0])}}),h({type:"text",name:"opener-title",text:R(n.title,"TITLE"),size:u,weight:800,color:R(n.textColor,"#ffffff"),font:n.font,inPoint:i+.8,maxWidth:o.width*.88,transform:{position:[r,a]},animators:[{unit:"grapheme",stagger:.025,duration:1.1,ease:"expoOut",from:{opacity:0,tracking:40,blur:10}}],effects:[{type:"dropShadow",blur:30,distance:0,opacity:50}]}),h({type:"shape",name:"opener-line",shape:"line",points:[[-o.width*.3,0],[o.width*.3,0]],stroke:c,strokeWidth:8,inPoint:i+1.2,transform:{position:[r,a+u*.85]},trim:{start:G([i+1.2,50,"expoOut"],[i+1.9,0]),end:G([i+1.2,50,"expoOut"],[i+1.9,100])}}),n.tagline&&h({type:"text",name:"opener-tagline",text:R(n.tagline,""),size:Math.round(u*.42),weight:600,color:c,font:n.font,inPoint:i+1.5,transform:{position:[r,a+u*1.4]},animators:[{unit:"line",clip:!0,stagger:.1,duration:.8,ease:"expoOut",from:{y:u*.6}}]}),{created:m,note:`Opener settles at ${(i+2.3).toFixed(1)}s`}}};J["opener.bars"]={kind:"opener",description:"Coloured bars sweep across the frame in a stagger, uncovering a title that slams in.",params:'{title: string, start?: s, colors?: string[], textColor?, size?: px, font?, direction?: "left"|"right"}',apply:(e,t,n)=>{let o=pe(e,t),i=D(n.start,0),r=n.colors??["#E8692A","#FFC93C","#F6EEDF","#1A1512"],a=n.direction==="right"?-1:1,s=o.height/r.length,c=[];return r.forEach((u,p)=>{let m=i+p*.08;c.push(ie(e,o.id,{type:"solid",name:`bar-${p+1}`,color:u,size:[o.width,s+2],inPoint:i,outPoint:i+1.6,transform:{anchor:[0,0],position:G([m,[-o.width*a,p*s],"expoInOut"],[m+.6,[0,p*s],"expoInOut"],[m+.85,[0,p*s],"expoInOut"],[m+1.4,[o.width*a,p*s]])}}).id)}),c.unshift(ie(e,o.id,{type:"text",name:"bars-title",text:R(n.title,"TITLE"),size:D(n.size,Math.round(o.width/8)),weight:800,color:R(n.textColor,"#ffffff"),font:n.font,inPoint:i+.9,maxWidth:o.width*.88,animators:_e.slam.animators},0).id),{created:c}}};J["slides.slideshow"]={kind:"slides",description:"Slider/slideshow from images and clips: each slide gets a slow Ken Burns move, an optional caption, and a transition into the next.",params:'{items: [{src, type?: "image"|"video", caption?, trimIn?, speed?}], start?: s, each?: s, transition?: type or list of types cycled per cut ("push"|"crossfade"|"zoom"|"wipe"|"whip"|"slideUp"), transitionDuration?: s, captionStyle?: text preset name, captionColor?, captionY?: px, plate?: colour, fitComp?: boolean (default true: comp duration = slideshow end)}',apply:(e,t,n)=>{let o=pe(e,t),i=n.items??[],r=D(n.each,3),a=D(n.transitionDuration,.5),s=D(n.start,0),c=[],u=[];i.forEach((h,d)=>{let f=s+d*(r-a),g=f+r,v=h.type??(/\.(mp4|mov|webm|m4v)$/i.test(h.src)?"video":"image"),y=d%2===0,k=ie(e,o.id,{type:v,name:`slide-${d+1}`,src:h.src,inPoint:+f.toFixed(3),outPoint:+g.toFixed(3),...v==="video"?{trimIn:h.trimIn??0,speed:h.speed??1}:{},transform:{scale:G([f,y?[104,104]:[118,118]],[g,y?[118,118]:[104,104]])}},o.layers.length);u.push(k.id),c.push(k.id),h.caption&&c.push(ie(e,o.id,{type:"text",name:`caption-${d+1}`,text:h.caption,size:Math.round(o.width/15),weight:800,color:R(n.captionColor,"#ffffff"),inPoint:+(f+a*.6).toFixed(3),outPoint:+(g-a).toFixed(3),maxWidth:o.width*.84,transform:{position:[o.width/2,D(n.captionY,o.height*.78)]},box:n.plate?{color:R(n.plate,"#000000"),padding:[32,16],radius:18,reveal:G([f+a*.6,0,"expoOut"],[f+a*.6+.5,100])}:void 0,shadow:n.plate?void 0:{color:"rgba(0,0,0,0.7)",blur:18,y:4},animators:[..._e[R(n.captionStyle,"fadeUp")]?.animators??_e.fadeUp.animators,..._e.fadeOutDown.animators]},0).id)});let p=Array.isArray(n.transition)?n.transition:[R(n.transition,"push")];for(let h=1;h<u.length;h++)J["transition.between"].apply(e,o.id,{from:u[h-1],to:u[h],type:p[(h-1)%p.length],duration:a});let m=Ee(s+i.length*(r-a)+a);return n.fitComp!==!1&&(o.duration=m),{created:c,note:`Slideshow ends at ${m}s${n.fitComp!==!1?" (comp duration set to match)":""}`}}};J["transition.between"]={kind:"transition",description:"Animates two overlapping layers (clips, images or precomps) so one hands over to the other at the overlap.",params:'{from: layerId (outgoing), to: layerId (incoming, must start before `from` ends), type: "push"|"crossfade"|"zoom"|"wipe"|"whip"|"slideUp", duration?: s}',apply:(e,t,n)=>{let o=K(e,R(n.from,"")),i=K(e,R(n.to,"")),r=o.comp,a=D(n.duration,.5),s=i.layer.inPoint??0,c=s+a,u=r.width,p=r.height,m=[u/2,p/2],h=R(n.type,"push"),d=(f,...g)=>g.forEach(([v,y,k])=>q(e,f,"transform.position",v,y,k));switch(i.index>o.index&&(r.layers.splice(i.index,1),r.layers.splice(o.index,0,i.layer)),h){case"crossfade":q(e,i.layer.id,"transform.opacity",s,0,"easyEase"),q(e,i.layer.id,"transform.opacity",c,100);break;case"zoom":q(e,o.layer.id,"transform.opacity",s,100,"easeIn"),q(e,o.layer.id,"transform.opacity",c,0),ee(e,o.layer.id,{effects:[...o.layer.effects??[],{type:"blur",radius:G([s,0,"easeIn"],[c,25])}]}),q(e,i.layer.id,"transform.opacity",s,0,"easeOut"),q(e,i.layer.id,"transform.opacity",c,100);break;case"wipe":ee(e,i.layer.id,{masks:[{shape:"rect",rect:G([s,[0,0,0,p],"expoInOut"],[c,[0,0,u*1.2,p]])}]});break;case"slideUp":d(o.layer.id,[s,m,"expoInOut"],[c,[u/2,-p/2]]),d(i.layer.id,[s,[u/2,p*1.5],"expoInOut"],[c,m]);break;case"whip":d(o.layer.id,[s,m,"expoIn"],[c,[-u/2,p/2]]),d(i.layer.id,[s,[u*1.5,p/2],"expoOut"],[c,m]);for(let f of[o.layer.id,i.layer.id])ee(e,f,{motionBlur:{samples:12,shutter:360}});break;default:d(o.layer.id,[s,m,"expoInOut"],[c,[-u/2,p/2]]),d(i.layer.id,[s,[u*1.5,p/2],"expoInOut"],[c,m])}return{created:[],note:`${h} from ${o.layer.id} to ${i.layer.id} at ${s}s\u2013${c}s`}}};J["element.lowerThird"]={kind:"element",description:"Lower third: an accent bar wipes in, then name and title slide out from behind it.",params:"{name: string, title?: string, start?: s, duration?: s, color?, textColor?, y?: px, font?}",apply:(e,t,n)=>{let o=pe(e,t),i=D(n.start,0),r=D(n.duration,4),a=D(n.y,o.height*.72),s=R(n.color,"#E8692A"),c=o.width*.08,u=[],p=ie(e,o.id,{type:"solid",name:"lt-bar",color:s,size:[12,170],inPoint:i,outPoint:i+r,transform:{anchor:[0,0],position:[c,a],scale:G([i,[100,0],"expoOut"],[i+.5,[100,100]],[i+r-.5,[100,100],"expoIn"],[i+r,[100,0]])}});u.push(p.id);let m=(h,d,f,g,v,y)=>u.push(ie(e,o.id,{type:"text",name:y,text:h,size:d,weight:800,align:"left",color:v,font:n.font,inPoint:i+g,outPoint:i+r,transform:{position:[c+34,a+f]},masks:[{shape:"rect",rect:[0,-200,o.width,400]}],animators:[{unit:"line",duration:.7,ease:"expoOut",from:{x:-o.width*.6}},{unit:"line",mode:"out",duration:.5,ease:"expoIn",from:{x:-o.width*.6}}]}).id);return m(R(n.name,"Name"),Math.round(o.width/15),55,.25,R(n.textColor,"#ffffff"),"lt-name"),n.title&&m(R(n.title,""),Math.round(o.width/28),125,.4,s,"lt-title"),{created:u}}};J["element.highlightWord"]={kind:"element",description:"Adds a background plate that wipes in behind an existing text layer (marker highlight).",params:"{layer: textLayerId, color?, at?: s, duration?: s, padding?: [x,y], radius?}",apply:(e,t,n)=>{let{layer:o}=K(e,R(n.layer,""));if(o.type!=="text")throw new Q(`${o.id} is not a text layer`);let i=D(n.at,o.inPoint??0),r=D(n.duration,.45);return o.box={color:R(n.color,"#E8692A"),padding:n.padding??[26,10],radius:D(n.radius,14),reveal:G([i,0,"expoOut"],[i+r,100])},{created:[]}}};var ue=window.DTLY;var lo=(e,t,n,o)=>{let i=3*e,r=3*(n-e)-i,a=1-i-r,s=3*t,c=3*(o-t)-s,u=1-s-c,p=d=>((a*d+r)*d+i)*d,m=d=>((u*d+c)*d+s)*d,h=d=>(3*a*d+2*r)*d+i;return d=>{let f=d;for(let y=0;y<8;y++){let k=p(f)-d;if(Math.abs(k)<1e-6)return m(f);let L=h(f);if(Math.abs(L)<1e-6)break;f-=k/L}let g=0,v=1;f=d;for(let y=0;y<40;y++){let k=p(f);if(Math.abs(k-d)<1e-6)break;k<d?g=f:v=f,f=(g+v)/2}return m(f)}},vn={easeIn:[.42,0,1,1],easeOut:[0,0,.58,1],easyEase:[.333,0,.667,1],quadOut:[.25,.46,.45,.94],cubicOut:[.215,.61,.355,1],expoIn:[.95,.05,.795,.035],expoOut:[.19,1,.22,1],expoInOut:[1,0,0,1],backOut:[.175,.885,.32,1.275],backIn:[.6,-.28,.735,.045]},_n=new Map,co=e=>e===0||e===1?e:Math.pow(2,-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,po=e=>e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375,uo=(e,{stiffness:t=170,damping:n=18,mass:o=1}={})=>{let i=Math.sqrt(t/o),r=n/(2*Math.sqrt(t*o));if(r<1){let a=i*Math.sqrt(1-r*r);return 1-Math.exp(-r*i*e)*(Math.cos(a*e)+r*i/a*Math.sin(a*e))}return 1-Math.exp(-i*e)*(1+i*e)},Ce=(e,t,n=1)=>{if(!e||e==="linear")return t;if(e==="hold")return t>=1?1:0;if(e==="elasticOut")return co(t);if(e==="bounceOut")return po(t);if(typeof e=="object"&&!Array.isArray(e))return t>=1?1:uo(t*n,e.spring);let o=Array.isArray(e)?e:vn[e];if(!o)return t;let i=o.join(","),r=_n.get(i);return r||_n.set(i,r=lo(...o)),r(t)},wn=["linear","hold",...Object.keys(vn),"elasticOut","bounceOut"];var mo={white:"#ffffff",black:"#000000",red:"#ff0000",green:"#008000",blue:"#0000ff",yellow:"#ffff00",orange:"#ffa500",transparent:"#00000000",gray:"#808080",grey:"#808080"},ve=e=>{let t=(mo[e.trim().toLowerCase()]??e).trim();if(t.startsWith("#")){let o=t.slice(1);if((o.length===3||o.length===4)&&(o=[...o].map(r=>r+r).join("")),o.length!==6&&o.length!==8)return null;let i=r=>parseInt(o.slice(r,r+2),16);return[i(0),i(2),i(4),o.length===8?i(6)/255:1]}let n=t.match(/^rgba?\(([^)]+)\)$/i);if(n){let o=n[1].split(/[\s,\/]+/).filter(Boolean).map(Number);return[o[0],o[1],o[2],o[3]??1]}return null},$e=([e,t,n,o])=>`rgba(${Math.round(e)},${Math.round(t)},${Math.round(n)},${Math.max(0,Math.min(1,o)).toFixed(4)})`;var rt=(e,t,n)=>e+(t-e)*n,fo=(e,t,n)=>{if(typeof e=="number"&&typeof t=="number")return rt(e,t,n);if(Array.isArray(e)&&Array.isArray(t))return e.map((o,i)=>rt(o,t[i]??o,n));if(typeof e=="string"&&typeof t=="string"){let o=ve(e),i=ve(t);if(o&&i)return $e(o.map((r,a)=>rt(r,i[a],n)))}return n<1?e:t},xn=e=>{let t=Math.sin(e*127.1+311.7)*43758.5453;return t-Math.floor(t)},ho=(e,t)=>{let n=Math.floor(e),o=e-n,i=o*o*(3-2*o);return rt(xn(n+t*1e3)*2-1,xn(n+1+t*1e3)*2-1,i)},go=(e,t,n)=>{let o=i=>ho(t*n.freq,(n.seed??1)+i*17.3)*n.amp;return typeof e=="number"?e+o(0):Array.isArray(e)?e.map((i,r)=>i+o(r)):e},bo=(e,t)=>{if(e.length===0)throw new Error("empty keyframes");if(t<=e[0].t)return e[0].v;let n=e[e.length-1];if(t>=n.t)return n.v;let o=0;for(;o<e.length-2&&t>=e[o+1].t;)o++;let i=e[o],r=e[o+1],a=r.t-i.t,s=Ce(i.ease,a<=0?1:(t-i.t)/a,a);return fo(i.v,r.v,s)};function E(e,t,n){if(e==null)return n;if(!te(e))return e;let o=[...e.keyframes].sort((r,a)=>r.t-a.t),i=bo(o,t);return e.wiggle?go(i,t,e.wiggle):i}var it=e=>`/api/media?src=${encodeURIComponent(e)}&token=${ue.token}`,kn=(e,t,n=2e3)=>new Promise(o=>{let i=()=>{clearTimeout(r),e.removeEventListener(t,i),o()},r=setTimeout(i,n);e.addEventListener(t,i,{once:!0})}),at=class{defaultFont="Baloo 2";playing=!1;images=new Map;videos=new Map;frameNo=0;createCanvas(t,n){let o=document.createElement("canvas");return o.width=t,o.height=n,o}image(t){return this.images.has(t)||this.images.set(t,new Promise((n,o)=>{let i=new Image;i.onload=()=>n(i),i.onerror=()=>o(new Error(`Could not load ${t}`)),i.src=it(t)})),this.images.get(t)}async videoFrame(t,n,o,i,r){let a=`${t.id}|${t.src}`,s=this.videos.get(a);if(!s){let g=document.createElement("video");g.muted=!0,g.playsInline=!0,g.preload="auto",g.crossOrigin="anonymous",g.src=it(t.src),s={el:g,canvas:document.createElement("canvas"),used:0},this.videos.set(a,s),await kn(g,"loadeddata",5e3)}s.used=this.frameNo;let c=s.el,u=Math.max(0,Math.min(n,(c.duration||1/0)-.001));this.playing?(c.playbackRate=t.speed??1,Math.abs(c.currentTime-u)>.25&&(c.currentTime=u),c.paused&&c.play().catch(()=>{})):(c.paused||c.pause(),Math.abs(c.currentTime-u)>.5/r&&(c.currentTime=u,await kn(c,"seeked")));let p=s.canvas;(p.width!==o||p.height!==i)&&(p.width=o,p.height=i);let m=p.getContext("2d");m.clearRect(0,0,o,i);let h=c.videoWidth||o,d=c.videoHeight||i,f=t.fit??"cover";if(f==="fill")m.drawImage(c,0,0,o,i);else{let g=f==="cover"?Math.max(o/h,i/d):Math.min(o/h,i/d);m.drawImage(c,(o-h*g)/2,(i-d*g)/2,h*g,d*g)}return p}endFrame(){for(let t of this.videos.values())t.used!==this.frameNo&&!t.el.paused&&t.el.pause();this.frameNo++}stopAll(){for(let t of this.videos.values())t.el.pause()}},st=class{els=new Map;sync(t,n,o,i){let r=new Set;for(let a of n.layers){if(a.type!=="audio"&&!(a.type==="video"&&a.volume))continue;let s=a,c=`${s.id}|${s.src}`,u=this.els.get(c);u||(u=new Audio(it(s.src)),u.preload="auto",this.els.set(c,u)),r.add(c);let p=s.inPoint??0,m=s.outPoint??n.duration;if(!(i&&o>=p&&o<m)){u.paused||u.pause();continue}let d=s.type==="video"?s.speed??1:1,f=(s.trimIn??0)+(o-p)*d,g=Math.max(0,Math.min(1,E(s.volume,o,1)));s.type==="audio"&&(s.fadeIn&&o-p<s.fadeIn&&(g*=(o-p)/s.fadeIn),s.fadeOut&&m-o<s.fadeOut&&(g*=(m-o)/s.fadeOut)),u.volume=g,u.playbackRate=d,Math.abs(u.currentTime-f)>.2&&(u.currentTime=f),u.paused&&u.play().catch(()=>{})}for(let[a,s]of this.els)!r.has(a)&&!s.paused&&s.pause()}stop(){for(let t of this.els.values())t.pause()}},Cn=async e=>{let t=[new FontFace("Baloo 2","url(/fonts/Baloo2.ttf)",{weight:"400 800"}),new FontFace("Mukta","url(/fonts/Mukta-Bold.ttf)",{weight:"400 800"})];for(let[n,o]of Object.entries(e.fonts??{}))for(let i of o)t.push(new FontFace(n,`url(${it(i)})`));await Promise.all(t.map(async n=>{try{document.fonts.add(await n.load())}catch{}}))};var yo=0;function l(e,t,n,o,i,r){t||(t={});var a,s,c=t;if("ref"in c&&typeof e!="function")for(s in c={},t)s=="ref"?a=t[s]:c[s]=t[s];var u={type:e,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--yo,__i:-1,__u:0};return(i||r)&&(u.__source=i,u.__self=r),O.vnode&&O.vnode(u),u}var Pn=e=>Number.isInteger(e)?String(e):e.toFixed(Math.abs(e)<10?2:1),Te=({value:e,onChange:t,onDragStart:n,onDragEnd:o,step:i=1,min:r,max:a,title:s})=>{let[c,u]=Y(null),p=re(null),m=h=>Math.min(a??1/0,Math.max(r??-1/0,h));return c!==null?l("input",{class:"num editing",value:c,autoFocus:!0,title:s,onInput:h=>u(h.target.value),onBlur:()=>{let h=Number(c);Number.isFinite(h)&&t(m(h),!1),u(null)},onKeyDown:h=>{h.key==="Enter"&&h.target.blur(),h.key==="Escape"&&u(null),h.stopPropagation()}}):l("span",{class:"num",title:s??"Drag to scrub, click to type",onPointerDown:h=>{h.target.setPointerCapture(h.pointerId),p.current={x:h.clientX,v:e,moved:!1}},onPointerMove:h=>{let d=p.current;if(!d)return;let f=h.clientX-d.x;!d.moved&&Math.abs(f)>2&&(d.moved=!0,n?.()),d.moved&&t(m(+(d.v+f*i*(h.shiftKey?10:h.altKey?.1:1)).toFixed(4)),!0)},onPointerUp:()=>{let h=p.current;p.current=null,h?.moved?o?.():u(Pn(e))},children:Pn(e)})},De=({value:e,onChange:t,onDragStart:n,onDragEnd:o,step:i=1,labels:r=["x","y"]})=>l("span",{class:"vec",children:e.map((a,s)=>l("span",{class:"vec-item",children:[l("label",{children:r[s]}),l(Te,{value:a,step:i,onDragStart:n,onDragEnd:o,onChange:(c,u)=>t(e.map((p,m)=>m===s?c:p),u)})]},s))}),_o=e=>{if(/^#[0-9a-f]{6}$/i.test(e))return e;if(/^#[0-9a-f]{3}$/i.test(e))return`#${[...e.slice(1)].map(n=>n+n).join("")}`;let t=e.match(/rgba?\(([^)]+)\)/);return t?`#${t[1].split(",").slice(0,3).map(n=>Math.round(Number(n)).toString(16).padStart(2,"0")).join("")}`:"#ffffff"},$t=({value:e,onChange:t})=>l("span",{class:"color",children:[l("input",{type:"color",value:_o(e),onInput:n=>t(n.target.value)}),l("input",{class:"text",value:e,onChange:n=>t(n.target.value),onKeyDown:n=>n.stopPropagation()})]}),je=({value:e,onChange:t,multiline:n})=>n?l("textarea",{class:"text",value:e,rows:3,onChange:o=>t(o.target.value),onKeyDown:o=>o.stopPropagation()}):l("input",{class:"text",value:e,onChange:o=>t(o.target.value),onKeyDown:o=>o.stopPropagation()}),se=({value:e,options:t,onChange:n})=>l("select",{value:e,onChange:o=>n(o.target.value),children:t.map(o=>l("option",{value:o,children:o},o))});var F={project:null,rev:0,comp:"main",time:0,playing:!1,loop:!0,layer:null,key:null,expanded:{},zoom:120,status:"loading",message:"",warnings:[],render:{active:!1}},Tt=new Set,I=()=>F,S=e=>{F={...F,...e},Tt.forEach(t=>t())},A=e=>{let[,t]=Y(0);return ae(()=>{let n=()=>t(o=>o+1);return Tt.add(n),()=>{Tt.delete(n)}},[]),e(F)},jt=(e,t={})=>fetch(e,{...t,headers:{"Content-Type":"application/json","X-DTLY-Token":ue.token,...t.headers??{}}}),Me=[],Ve=[],vo=200,Mn,lt=()=>{S({status:"saving"}),clearTimeout(Mn),Mn=window.setTimeout(wo,250)},wo=async()=>{if(F.project)try{let e=await jt("/api/project",{method:"PUT",body:JSON.stringify({project:F.project})});if(!e.ok)throw new Error(await e.text());let{rev:t,warnings:n}=await e.json();S({rev:t,warnings:n,status:"saved",message:""})}catch(e){S({status:"error",message:`Save failed: ${e.message}`})}},z=e=>{if(!F.project)return;let t=JSON.stringify(F.project),n=JSON.parse(t);try{e(n)}catch(o){S({message:o.message});return}Me.push(t),Me.length>vo&&Me.shift(),Ve.length=0,S({project:n,message:""}),lt()},Pe=null,le=()=>{Pe=F.project?JSON.stringify(F.project):null},me=e=>{if(!Pe)return;let t=JSON.parse(Pe);try{e(t)}catch{return}S({project:t})},ce=()=>{Pe&&JSON.stringify(F.project)!==Pe&&(Me.push(Pe),Ve.length=0,lt()),Pe=null},At=()=>{let e=Me.pop();!e||!F.project||(Ve.push(JSON.stringify(F.project)),S({project:JSON.parse(e)}),lt())},ct=()=>{let e=Ve.pop();!e||!F.project||(Me.push(JSON.stringify(F.project)),S({project:JSON.parse(e)}),lt())},It=async(e=!1)=>{let t=await jt("/api/project"),{rev:n,project:o}=await t.json();e&&F.project&&(Me.push(JSON.stringify(F.project)),Ve.length=0);let i=o.comps.some(a=>a.id===F.comp)?F.comp:o.root,r=F.layer&&o.comps.some(a=>a.layers.some(s=>s.id===F.layer))?F.layer:null;S({project:o,rev:n,comp:i,layer:r,key:r?F.key:null,status:e?"reloaded":"saved",message:e?"Reloaded: the file changed on disk":""})},Sn=()=>{let e=new EventSource(`/api/events?token=${ue.token}`);e.addEventListener("project",t=>{let{rev:n}=JSON.parse(t.data);n>F.rev&&It(!0)}),e.addEventListener("render",t=>{let n=JSON.parse(t.data);n.error?S({render:{active:!1,error:n.error}}):n.finished?S({render:{active:!1,out:n.out},message:`Rendered ${n.out} in ${n.took?.toFixed(1)}s`}):S({render:{active:!0,done:n.done,total:n.total}})})},Ln=async()=>{S({render:{active:!0,done:0}});let e=await jt("/api/render",{method:"POST",body:JSON.stringify({comp:F.comp})});e.ok||S({render:{active:!1,error:await e.text()}})},Z=()=>F.project?.comps.find(e=>e.id===F.comp)??F.project?.comps[0],En=()=>Z()?.layers.find(e=>e.id===F.layer),Ot=e=>{let t=[],n=(o,i)=>{if(Array.isArray(o))o.forEach((r,a)=>typeof r=="object"&&r!==null&&n(r,`${i}.${a}`));else if(typeof o=="object"&&o!==null)if(te(o))t.push({path:i,keyframes:o.keyframes});else for(let[r,a]of Object.entries(o))r!=="animators"&&n(a,i?`${i}.${r}`:r)};return n(e,""),t},He=(e,t)=>t.split(".").reduce((n,o)=>n?.[o],e),H=(e,t)=>Math.round(Math.round(e*t)/t*1e3)/1e3;var W=({layer:e,path:t,label:n,kind:o,fallback:i,step:r=1,min:a,max:s})=>{let c=A(w=>w.time),u=Z(),p=He(e,t),m=te(p),h=E(p,c,i),d=H(c,u.fps),f=(w,$)=>m?q(w,e.id,t,d,$):Ne(w,e.id,t,$),g=(w,$)=>$?me(_=>f(_,w)):z(_=>f(_,w)),v=m?p.keyframes.map(w=>w.t):[],y=v.some(w=>Math.abs(w-d)<.001),k=[...v].reverse().find(w=>w<d-.001),L=v.find(w=>w>d+.001),b=()=>z(w=>m?Ne(w,e.id,t,h):q(w,e.id,t,d,h)),M=()=>z(w=>y?Re(w,e.id,t,d):q(w,e.id,t,d,h));return l("div",{class:"prop",children:[l("button",{class:`watch ${m?"on":""}`,title:m?"Stop animating (keep current value)":"Animate: add a keyframe at the playhead",onClick:b,children:"\u23F1"}),l("label",{children:n}),l("span",{class:"prop-value",children:[o==="num"&&l(Te,{value:Number(h??0),step:r,min:a,max:s,onChange:g,onDragStart:le,onDragEnd:ce}),o==="vec"&&l(De,{value:h??[0,0],step:r,onChange:g,onDragStart:le,onDragEnd:ce}),o==="color"&&l($t,{value:String(h??"#ffffff"),onChange:w=>g(w,!1)})]}),m&&l("span",{class:"keynav",children:[l("button",{disabled:k===void 0,onClick:()=>S({time:k}),children:"\u25C0"}),l("button",{class:y?"on":"",title:y?"Remove keyframe here":"Add keyframe here",onClick:M,children:"\u25C6"}),l("button",{disabled:L===void 0,onClick:()=>S({time:L}),children:"\u25B6"})]})]})},N=({label:e,children:t})=>l("div",{class:"prop",children:[l("span",{class:"watch-space"}),l("label",{children:e}),l("span",{class:"prop-value",children:t})]}),U=(e,t)=>z(n=>ee(n,e.id,t)),de=(e,t,n,o,i,r=1)=>l(N,{label:t,children:l(Te,{value:o??i,step:r,onChange:(a,s)=>s?me(c=>ee(c,e.id,{[n]:a})):U(e,{[n]:a}),onDragStart:le,onDragEnd:ce})}),ne=({title:e,children:t,open:n=!0})=>l("details",{class:"section",open:n,children:[l("summary",{children:e}),t]}),Se=({value:e,onApply:t,rows:n=8})=>{let o=JSON.stringify(e,null,2),[i,r]=Y(o),[a,s]=Y("");return ae(()=>{r(o),s("")},[o]),l("div",{class:"json",children:[l("textarea",{rows:n,value:i,spellcheck:!1,onInput:c=>r(c.target.value),onKeyDown:c=>c.stopPropagation()}),l("div",{class:"row",children:[a&&l("span",{class:"error",children:a}),l("button",{disabled:i===o,onClick:()=>{try{t(JSON.parse(i)),s("")}catch(c){s(c.message)}},children:"Apply"})]})]})},xo=()=>{let e=A(a=>a.key),t=A(a=>a.project);if(!e||!t)return null;let n;try{let{layer:a}=K(t,e.layer);n=He(a,e.path)?.keyframes?.find(s=>Math.abs(s.t-e.t)<.001)}catch{}if(!n)return null;let o=n.ease??"linear",i=typeof o=="string"?o:Array.isArray(o)?"bezier":"spring",r=a=>z(s=>Et(s,e.layer,e.path,e.t,a));return l(ne,{title:`Keyframe \xB7 ${e.path} @ ${e.t}s`,children:[l(N,{label:"Ease out",children:l(se,{value:i,options:[...wn,"bezier","spring"],onChange:a=>r(a==="bezier"?[.25,.1,.25,1]:a==="spring"?{spring:{stiffness:170,damping:18}}:a)})}),Array.isArray(o)&&l(N,{label:"Bezier",children:l(De,{value:o,step:.01,labels:["x1","y1","x2","y2"],onChange:(a,s)=>s?me(c=>Et(c,e.layer,e.path,e.t,a)):r(a),onDragStart:le,onDragEnd:ce})}),i==="spring"&&typeof o=="object"&&!Array.isArray(o)&&l(N,{label:"Spring",children:l(De,{value:[o.spring.stiffness??170,o.spring.damping??18],labels:["stiff","damp"],onChange:a=>r({spring:{stiffness:a[0],damping:a[1]}})})}),l(ko,{ease:o}),l(N,{label:"Value",children:l(Se,{value:n.v,rows:2,onApply:a=>z(s=>q(s,e.layer,e.path,e.t,a))})}),l("div",{class:"row",children:l("button",{onClick:()=>{z(a=>Re(a,e.layer,e.path,e.t)),S({key:null})},children:"Delete keyframe"})})]})},ko=({ease:e})=>{let t=[];for(let n=0;n<=40;n++){let o=n/40,i=Ce(e,o);t.push(`${(o*180+10).toFixed(1)},${(110-i*90).toFixed(1)}`)}return l("svg",{class:"ease-graph",viewBox:"0 0 200 130",children:[l("line",{x1:"10",y1:"110",x2:"190",y2:"110"}),l("line",{x1:"10",y1:"20",x2:"190",y2:"20",class:"guide"}),l("polyline",{points:t.join(" ")})]})},Co=(e,t)=>{if(e.type==="solid"||e.type==="image"||e.type==="video")return[(e.size?.[0]??t.width)/2,(e.size?.[1]??t.height)/2];if(e.type==="precomp"){let n=I().project?.comps.find(o=>o.id===e.comp);return[(n?.width??t.width)/2,(n?.height??t.height)/2]}return[0,0]},Po=({layer:e,comp:t})=>{let n=t.layers.filter(r=>r.id!==e.id),o=t.layers.indexOf(e),i=["Baloo 2","Mukta",...Object.keys(I().project?.fonts??{})];return l(ye,{children:[l(ne,{title:`${e.type} \xB7 ${e.id}`,children:[l(N,{label:"Name",children:l(je,{value:e.name??"",onChange:r=>U(e,{name:r||null})})}),de(e,"In","inPoint",e.inPoint,0,1/t.fps),de(e,"Out","outPoint",e.outPoint,t.duration,1/t.fps),l(N,{label:"Parent",children:l(se,{value:e.parent??"(none)",options:["(none)",...n.map(r=>r.id)],onChange:r=>U(e,{parent:r==="(none)"?null:r})})}),l(N,{label:"Blend",children:l(se,{value:e.blendMode??"normal",options:["normal","multiply","screen","overlay","add","darken","lighten","softLight","difference"],onChange:r=>U(e,{blendMode:r==="normal"?null:r})})}),l(N,{label:"Motion blur",children:l("input",{type:"checkbox",checked:!!e.motionBlur,onChange:r=>U(e,{motionBlur:r.target.checked?{samples:8}:null})})}),l("div",{class:"row",children:[l("button",{disabled:o<=0,onClick:()=>z(r=>St(r,e.id,o-1)),children:"Up"}),l("button",{disabled:o>=t.layers.length-1,onClick:()=>z(r=>St(r,e.id,o+1)),children:"Down"}),l("button",{onClick:()=>z(r=>{let a=nt(r,e.id);S({layer:a.id})}),children:"Duplicate"}),l("button",{class:"danger",onClick:()=>{z(r=>tt(r,e.id)),S({layer:null,key:null})},children:"Delete"})]})]}),e.type!=="audio"&&l(ne,{title:"Transform",children:[l(W,{layer:e,path:"transform.position",label:"Position",kind:"vec",fallback:[t.width/2,t.height/2]}),l(W,{layer:e,path:"transform.scale",label:"Scale %",kind:"vec",fallback:[100,100]}),l(W,{layer:e,path:"transform.rotation",label:"Rotation \xB0",kind:"num",fallback:0}),l(W,{layer:e,path:"transform.opacity",label:"Opacity %",kind:"num",fallback:100,min:0,max:100}),l(W,{layer:e,path:"transform.anchor",label:"Anchor",kind:"vec",fallback:Co(e,t)}),l(W,{layer:e,path:"transform.skew",label:"Skew \xB0",kind:"num",fallback:0})]}),e.type==="text"&&l(ne,{title:"Text",children:[l(N,{label:"Text",children:l(je,{multiline:!0,value:e.text,onChange:r=>U(e,{text:r})})}),l(W,{layer:e,path:"size",label:"Size",kind:"num",fallback:72,min:1}),l(W,{layer:e,path:"color",label:"Color",kind:"color",fallback:"#ffffff"}),l(W,{layer:e,path:"tracking",label:"Tracking",kind:"num",fallback:0}),l(N,{label:"Font",children:l(se,{value:e.font??"Baloo 2",options:i,onChange:r=>U(e,{font:r})})}),l(N,{label:"Weight",children:l(se,{value:String(e.weight??700),options:["400","500","600","700","800"],onChange:r=>U(e,{weight:Number(r)})})}),l(N,{label:"Align",children:l(se,{value:e.align??"center",options:["left","center","right"],onChange:r=>U(e,{align:r})})}),de(e,"Max width","maxWidth",e.maxWidth,0,5),de(e,"Line height","lineHeight",e.lineHeight,1.25,.01),l(N,{label:"Animators",children:l(Se,{value:e.animators??[],rows:6,onApply:r=>U(e,{animators:r})})}),l("div",{class:"presets",children:Object.entries(J).filter(([,r])=>r.kind==="text").map(([r])=>l("button",{title:J[r].description,onClick:()=>z(a=>J[r].apply(a,t.id,{layer:e.id})),children:r.slice(5)},r))})]}),e.type==="shape"&&l(ne,{title:"Shape",children:[l(N,{label:"Shape",children:l(se,{value:e.shape,options:["rect","ellipse","polygon","path","line"],onChange:r=>U(e,{shape:r})})}),(e.shape==="rect"||e.shape==="ellipse")&&l(W,{layer:e,path:"size",label:"Size",kind:"vec",fallback:[200,200]}),(e.shape==="rect"||e.shape==="polygon")&&l(W,{layer:e,path:"radius",label:"Radius",kind:"num",fallback:e.shape==="rect"?0:100}),(typeof e.fill=="string"||te(e.fill)||e.fill===void 0)&&l(W,{layer:e,path:"fill",label:"Fill",kind:"color",fallback:"#ffffff"}),l(W,{layer:e,path:"stroke",label:"Stroke",kind:"color",fallback:"#ffffff"}),l(W,{layer:e,path:"strokeWidth",label:"Stroke width",kind:"num",fallback:4,min:0}),l(W,{layer:e,path:"trim.start",label:"Trim start %",kind:"num",fallback:0,min:0,max:100}),l(W,{layer:e,path:"trim.end",label:"Trim end %",kind:"num",fallback:100,min:0,max:100})]}),e.type==="solid"&&l(ne,{title:"Solid",children:l(W,{layer:e,path:"color",label:"Color",kind:"color",fallback:"#000000"})}),(e.type==="image"||e.type==="video")&&l(ne,{title:e.type==="video"?"Video":"Image",children:[l(N,{label:"Source",children:l(je,{value:e.src,onChange:r=>U(e,{src:r})})}),l(N,{label:"Fit",children:l(se,{value:e.fit??"cover",options:["cover","contain","fill"],onChange:r=>U(e,{fit:r})})}),e.type==="video"&&de(e,"Trim in (s)","trimIn",e.trimIn,0,.05),e.type==="video"&&de(e,"Speed","speed",e.speed,1,.01),e.type==="video"&&l(W,{layer:e,path:"volume",label:"Volume",kind:"num",fallback:0,step:.01,min:0,max:1})]}),e.type==="audio"&&l(ne,{title:"Audio",children:[l(N,{label:"Source",children:l(je,{value:e.src,onChange:r=>U(e,{src:r})})}),de(e,"Trim in (s)","trimIn",e.trimIn,0,.05),l(W,{layer:e,path:"volume",label:"Volume",kind:"num",fallback:1,step:.01,min:0,max:1}),de(e,"Fade in (s)","fadeIn",e.fadeIn,0,.05),de(e,"Fade out (s)","fadeOut",e.fadeOut,0,.05)]}),e.type==="precomp"&&l(ne,{title:"Precomp",children:[l(N,{label:"Comp",children:l(se,{value:e.comp,options:I().project.comps.filter(r=>r.id!==t.id).map(r=>r.id),onChange:r=>U(e,{comp:r})})}),de(e,"Time offset","timeOffset",e.timeOffset,0,.05),l("div",{class:"row",children:l("button",{onClick:()=>S({comp:e.comp,layer:null,key:null,time:0}),children:"Open comp"})})]}),l(ne,{title:"Effects, masks & matte (JSON)",open:!1,children:[l(N,{label:"Effects",children:l(Se,{value:e.effects??[],rows:5,onApply:r=>U(e,{effects:r})})}),l(N,{label:"Masks",children:l(Se,{value:e.masks??[],rows:4,onApply:r=>U(e,{masks:r})})}),l(N,{label:"Matte",children:l(Se,{value:e.matte??null,rows:2,onApply:r=>U(e,{matte:r})})})]}),l(ne,{title:"Layer JSON",open:!1,children:l(Se,{value:e,rows:16,onApply:r=>z(a=>{let s=r;if(s.id!==e.id)throw new Error("The id cannot change here");let c=a.comps.find(u=>u.id===t.id);c.layers[c.layers.findIndex(u=>u.id===e.id)]=s})})})]})},Mo=({comp:e})=>{let t=I().project,n=o=>z(i=>hn(i,e.id,o));return l(ne,{title:`Composition \xB7 ${e.id}`,children:[l(N,{label:"Name",children:l(je,{value:e.name??"",onChange:o=>n({name:o||void 0})})}),l(N,{label:"Size",children:l(De,{value:[e.width,e.height],labels:["w","h"],onChange:o=>n({width:Math.round(o[0]),height:Math.round(o[1])})})}),l(N,{label:"FPS",children:l(Te,{value:e.fps,onChange:o=>n({fps:Math.max(1,Math.round(o))})})}),l(N,{label:"Duration (s)",children:l(Te,{value:e.duration,step:.1,min:.1,onChange:o=>n({duration:o})})}),l(N,{label:"Background",children:l($t,{value:e.background??"#000000",onChange:o=>n({background:o})})}),l(N,{label:"Markers",children:l(Se,{value:e.markers??[],rows:3,onApply:o=>n({markers:o})})}),t.root!==e.id&&l("div",{class:"row",children:l("button",{onClick:()=>z(o=>{o.root=e.id}),children:"Render this comp"})})]})},$n=()=>{let e=A(r=>r.project),t=A(r=>r.comp),n=A(r=>r.layer),o=e?.comps.find(r=>r.id===t);if(!o)return l("aside",{class:"inspector"});let i=o.layers.find(r=>r.id===n);return l("aside",{class:"inspector",children:[l(xo,{}),i?l(Po,{layer:i,comp:o},i.id):l(Mo,{comp:o})]})};var Ft=230,Tn={text:"#e0a84a",shape:"#5fb3a0",solid:"#9b7fd1",image:"#5b9bd5",video:"#d36c6c",audio:"#7fb35f",precomp:"#c78bc0",null:"#888"},So=e=>e.replace(/^transform\./,"").replace(/\.(\d+)\./g,"[$1]."),Lo=(e,t)=>{let o=[.1,.25,.5,1,2,5,10,30,60].find(r=>r*t>=60)??60,i=[];for(let r=0;r<=e+1e-6;r+=o)i.push(+r.toFixed(3));return{out:i,step:o}},jn=(e,t)=>{let n=()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",n),t()};window.addEventListener("pointermove",e),window.addEventListener("pointerup",n)},An=e=>e.ease==="hold"?"hold":!e.ease||e.ease==="linear"?"linear":"eased",In=()=>{let e=A(b=>b.project),t=A(b=>b.comp),n=A(b=>b.time),o=A(b=>b.zoom),i=A(b=>b.layer),r=A(b=>b.key),a=A(b=>b.expanded),s=re(null),c=e?.comps.find(b=>b.id===t);if(!c)return l("div",{class:"timeline"});let u=c.duration*o+120,p=c.fps,m=b=>{let M=s.current.getBoundingClientRect();return Math.max(0,Math.min(c.duration,(b-M.left-Ft+s.current.scrollLeft)/o))},h=b=>{let M=I().time;return Math.abs(b-M)*o<6?M:H(b,p)},d=b=>{b.currentTarget.setPointerCapture(b.pointerId),S({time:H(m(b.clientX),p),playing:!1})},f=b=>{(b.buttons&1)!==0&&S({time:H(m(b.clientX),p)})},g=(b,M,w)=>{b.stopPropagation(),S({layer:M.id,key:null});let $=b.clientX,_=M.inPoint??0,x=M.outPoint??c.duration,C=!1;jn(T=>{let j=(T.clientX-$)/o;if(!C){if(Math.abs(T.clientX-$)<3)return;C=!0,le()}me(X=>{if(w==="move"){let oe=h(_+j);ze(X,M.id,oe-_)}else w==="in"?ee(X,M.id,{inPoint:Math.min(x-1/p,Math.max(0,h(_+j)))}):ee(X,M.id,{outPoint:Math.max(_+1/p,h(x+j))})})},()=>{C&&ce()})},v=(b,M,w,$)=>{b.stopPropagation(),S({layer:M.id,key:{layer:M.id,path:w,t:$.t},time:b.altKey?I().time:$.t,playing:!1});let _=b.clientX,x=$.t,C=!1;jn(T=>{if(!C){if(Math.abs(T.clientX-_)<3)return;C=!0,le()}let j=Math.max(0,h(x+(T.clientX-_)/o));me(X=>yn(X,M.id,w,x,j)),S({key:{layer:M.id,path:w,t:j},time:j})},()=>{C&&ce()})},y=(b,M,w)=>{let $=H(m(b.clientX),p),_=He(M,w),x=E(_,$,void 0);z(C=>q(C,M.id,w,$,x)),S({key:{layer:M.id,path:w,t:$},time:$})},{out:k}=Lo(c.duration,o);return l("div",{class:"timeline",children:l("div",{class:"tl-scroll",ref:s,onWheel:b=>{(b.ctrlKey||b.metaKey)&&(b.preventDefault(),S({zoom:Math.min(2e3,Math.max(10,o*(b.deltaY<0?1.15:1/1.15)))}))},children:l("div",{class:"tl-inner",style:{width:`${Ft+u}px`},children:[l("div",{class:"tl-ruler-row",children:[l("div",{class:"tl-label tl-corner",children:[c.name??c.id," \xB7 ",c.fps," fps"]}),l("div",{class:"tl-ruler",style:{width:`${u}px`},onPointerDown:d,onPointerMove:f,children:[k.map(b=>l("div",{class:"tick",style:{left:`${b*o}px`},children:l("span",{children:[b,"s"]})},b)),(c.markers??[]).map(b=>l("div",{class:"marker",style:{left:`${b.t*o}px`},title:b.label},b.t)),l("div",{class:"tl-end",style:{left:`${c.duration*o}px`}})]})]}),c.layers.map((b,M)=>{let w=b.inPoint??0,$=b.outPoint??c.duration,_=Ot(b),x=a[b.id];return l("div",{class:`tl-group ${i===b.id?"selected":""}`,children:[l("div",{class:"tl-row layer-row",children:[l("div",{class:"tl-label",onPointerDown:()=>S({layer:b.id,key:null}),children:[l("button",{class:`twirl ${x?"open":""} ${_.length?"":"empty"}`,onClick:C=>{C.stopPropagation(),S({expanded:{...a,[b.id]:!x}})},children:"\u25B8"}),l("button",{class:`eye ${b.hidden?"off":""}`,title:"Show/hide",onClick:C=>{C.stopPropagation(),z(P=>ee(P,b.id,{hidden:b.hidden?null:!0}))},children:"\u25CF"}),l("span",{class:"idx",children:M+1}),l("span",{class:"chip",style:{background:Tn[b.type]}}),l("span",{class:"name",title:b.id,children:b.name??b.id})]}),l("div",{class:"tl-track",style:{width:`${u}px`},onPointerDown:d,onPointerMove:f,children:[l("div",{class:`bar ${b.hidden?"hidden":""}`,style:{left:`${w*o}px`,width:`${Math.max(2,($-w)*o)}px`,background:Tn[b.type]},onPointerDown:C=>g(C,b,"move"),children:[l("span",{class:"handle in",onPointerDown:C=>g(C,b,"in")}),l("span",{class:"bar-name",children:b.type==="text"?b.text.split(`
|
|
2
|
-
`)[0]:b.name??b.id}),l("span",{class:"handle out",onPointerDown:C=>g(C,b,"out")})]}),!x&&_.flatMap(C=>C.keyframes.map(P=>l("span",{class:"mini-key",style:{left:`${P.t*o}px`}},`${C.path}${P.t}`)))]})]}),x&&_.map(C=>l("div",{class:"tl-row prop-row",children:[l("div",{class:"tl-label prop-label",title:C.path,children:So(C.path)}),l("div",{class:"tl-track",style:{width:`${u}px`},onPointerDown:d,onPointerMove:f,onDblClick:P=>y(P,b,C.path),children:[C.keyframes.map((P,T)=>{let j=C.keyframes[T+1];return j?l("span",{class:`seg ${An(P)}`,style:{left:`${P.t*o}px`,width:`${(j.t-P.t)*o}px`}},`seg${P.t}`):null}),C.keyframes.map((P,T)=>{let j=r&&r.layer===b.id&&r.path===C.path&&Math.abs(r.t-P.t)<.001;return l("span",{class:`key ${An(P)} ${j?"active":""}`,style:{left:`${P.t*o}px`},title:`${P.t}s = ${JSON.stringify(P.v)}${P.ease?` \xB7 ${typeof P.ease=="string"?P.ease:JSON.stringify(P.ease)}`:""}`,onPointerDown:X=>v(X,b,C.path,P)},T)})]})]},C.path))]},b.id)}),l("div",{class:"playhead",style:{left:`${Ft+n*o}px`}})]})})})},On=e=>{let t=I();if(!t.project)return[];let{layer:n}=K(t.project,e);return[...new Set(Ot(n).flatMap(o=>o.keyframes.map(i=>i.t)))].sort((o,i)=>o-i)};var Eo=new Intl.Segmenter(void 0,{granularity:"grapheme"}),Fn=e=>[...Eo.segment(e)].map(t=>t.segment),zt=(e,t,n)=>`${e.weight??700} ${t}px "${e.font??n}"`,dt=new Map,Nt=(e,t,n,o,i)=>{let r=[t.text,i,o,t.maxWidth,t.align,t.lineHeight].join("|"),a=dt.get(r);if(a)return a;e.font=i;let s=e.measureText("|").width,c=y=>/\s$/.test(y)?e.measureText(`${y}|`).width-s:e.measureText(y).width,u=y=>c(y)+o*Math.max(0,Fn(y).length-1),p=(t.lineHeight??1.25)*n,m=[];for(let y of t.text.split(`
|
|
3
|
-
`)){if(!t.maxWidth){m.push(y);continue}let k="";for(let L of y.split(" ")){let b=k?`${k} ${L}`:L;k&&u(b)>t.maxWidth?(m.push(k),k=L):k=b}m.push(k)}let h=t.align??"center",d=-(m.length*p)/2,f={lines:[],graphemes:[],words:[],width:0,height:m.length*p,top:d,size:n},g=0,v=0;return m.forEach((y,k)=>{let L=u(y);f.width=Math.max(f.width,L);let b=h==="left"?0:h==="right"?-L:-L/2,M=d+k*p+p*.5+n*.32;f.lines.push({text:y,x:b,y:M,w:L});let w=Fn(y),$="",_=null,x="",C=P=>{_!==null&&f.words.push({text:x,x:_,y:M,w:P-_,line:k,word:v++,grapheme:g}),_=null,x=""};w.forEach((P,T)=>{let j=b+($?c($):0)+o*T,X=e.measureText(P).width;P===" "?C(j):(_===null&&(_=j),x+=P,f.graphemes.push({text:P,x:j,y:M,w:X,line:k,word:v,grapheme:g++})),$+=P}),C(b+L)}),dt.size>500&&dt.clear(),dt.set(r,f),f},$o=(e,t,n,o=1)=>{switch(n){case"reverse":return t-1-e;case"center":return Math.abs(e-(t-1)/2);case"edges":return(t-1)/2-Math.abs(e-(t-1)/2);case"random":return[...Array(t).keys()].sort((r,a)=>Math.sin(r*91.7+o)-Math.sin(a*91.7+o)).indexOf(e);default:return e}},To=(e,t,n,o,i,r)=>{let a={opacity:1,x:0,y:0,scale:1,rotation:0,blur:0,tracking:0};for(let s of e){let c=n[s.unit],u=t[s.unit],p=s.stagger??.05,m=s.duration??.5,h=s.delay??0,d=$o(u,c,s.order,s.seed),f=s.order==="center"||s.order==="edges"?(c-1)/2:c-1,g;if(s.mode==="out"){let k=i-h-m-(f-d)*p;g=1-Ce(s.ease??"easeIn",Math.min(1,Math.max(0,(o-k)/m)),m)}else{let k=h+d*p;g=Ce(s.ease??"cubicOut",Math.min(1,Math.max(0,(o-k)/m)),m)}let v=1-g,y=s.from;if(y.opacity!==void 0&&(a.opacity*=(y.opacity+(100-y.opacity)*g)/100),y.x&&(a.x+=y.x*v),y.y&&(a.y+=y.y*v),y.scale!==void 0&&(a.scale*=(y.scale+(100-y.scale)*g)/100),y.rotation&&(a.rotation+=y.rotation*v),y.blur&&(a.blur+=y.blur*v),y.tracking&&(a.tracking+=y.tracking*v),y.color){let k=ve(y.color),L=ve(r);k&&L&&(a.color=$e(k.map((b,M)=>b+(L[M]-b)*g)))}}return a},jo=(e,t,n,o,i,r)=>{e.beginPath(),e.roundRect(t,n,o,i,r)},zn=(e,t,n,o,i,r)=>{let a=E(t.size,n,72),s=E(t.tracking,n,0),c=E(t.color,n,"#ffffff"),u=zt(t,a,r),p=Nt(e,t,a,s,u);if(e.font=u,e.textAlign="left",e.textBaseline="alphabetic",t.box){let[w,$]=t.box.padding??[24,12],_=E(t.box.reveal,n,100)/100,x=Math.min(...p.lines.map(T=>T.x))-w,C=p.width+w*2,P=p.height+$*2;_>0&&(e.save(),e.beginPath(),e.rect(x,p.top-$,C*_,P),e.clip(),e.fillStyle=E(t.box.color,n,"#000"),jo(e,x,p.top-$,C,P,t.box.radius??12),e.fill(),e.restore())}t.shadow&&(e.shadowColor=t.shadow.color,e.shadowBlur=t.shadow.blur,e.shadowOffsetX=t.shadow.x??0,e.shadowOffsetY=t.shadow.y??0);let m=(w,$,_,x)=>{t.stroke&&(e.lineJoin="round",e.lineWidth=t.stroke.width,e.strokeStyle=t.stroke.color,e.strokeText(w,$,_)),e.fillStyle=x,e.fillText(w,$,_)},h=t.animators??[];if(h.length===0){for(let w of p.lines)m(w.text,w.x,w.y,c);return}let d=h.some(w=>w.unit==="grapheme")?"grapheme":h.some(w=>w.unit==="word")?"word":"line",f=d==="grapheme"?p.graphemes:d==="word"?p.words:p.lines.map((w,$)=>({...w,line:$,word:0,grapheme:0})),g={grapheme:p.graphemes.length,word:p.words.length,line:p.lines.length},v=n-o,y=i-o,k=h.some(w=>w.clip),L=p.height/p.lines.length,b=new Map;for(let w of f)b.set(w.line,(b.get(w.line)??0)+1);let M=new Map;for(let w of f){let $=M.get(w.line)??0;M.set(w.line,$+1);let _=To(h,{grapheme:w.grapheme,word:w.word,line:w.line},g,v,y,c);if(_.opacity<=.001)continue;e.save(),k&&(e.beginPath(),e.rect(-1e5,p.top+w.line*L,2e5,L),e.clip());let x=_.tracking*($-((b.get(w.line)??1)-1)/2),C=w.x+w.w/2+_.x+x,P=w.y-a*.35+_.y;e.translate(C,P),_.rotation&&e.rotate(_.rotation*Math.PI/180),_.scale!==1&&e.scale(_.scale,_.scale),e.globalAlpha*=_.opacity,_.blur>.1&&(e.filter=`blur(${_.blur.toFixed(2)}px)`),m(w.text,-w.w/2,a*.35,_.color??c),e.restore()}};var Be=(e,t)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]],Nn={normal:"source-over",multiply:"multiply",screen:"screen",overlay:"overlay",add:"lighter",darken:"darken",lighten:"lighten",softLight:"soft-light",difference:"difference"},pt=class{constructor(t,n){this.project=t;this.host=n}project;host;pool=new Map;comp(t){let n=this.project.comps.find(o=>o.id===t);if(!n)throw new Error(`Unknown composition "${t}"`);return n}acquire(t,n){let i=this.pool.get(`${t}x${n}`)?.pop()??this.host.createCanvas(t,n),r=i.getContext("2d");return r.setTransform(1,0,0,1,0,0),r.clearRect(0,0,t,n),i}release(t){let n=`${t.width}x${t.height}`;this.pool.has(n)||this.pool.set(n,[]),this.pool.get(n).push(t)}layerSize(t,n,o){switch(t.type){case"solid":return t.size??[n.width,n.height];case"image":case"video":return t.size??[n.width,n.height];case"precomp":{let i=this.comp(t.comp);return[i.width,i.height]}default:return[0,0]}}matrix(t,n,o,i=0){let r=t.transform??{},a=this.layerSize(t,n,o),s=E(r.anchor,o,[a[0]/2,a[1]/2]),c=E(r.position,o,[n.width/2,n.height/2]),[u,p]=E(r.scale,o,[100,100]),m=E(r.rotation,o,0)*Math.PI/180,h=Math.tan(E(r.skew,o,0)*Math.PI/180),d=Math.cos(m),f=Math.sin(m),g=[1,0,0,1,c[0],c[1]];if(g=Be(g,[d,f,-f,d,0,0]),g=Be(g,[1,0,h,1,0,0]),g=Be(g,[u/100,0,0,p/100,0,0]),g=Be(g,[1,0,0,1,-s[0],-s[1]]),t.parent&&i<20){let v=n.layers.find(y=>y.id===t.parent);v&&(g=Be(this.matrix(v,n,o,i+1),g))}return g}async renderComp(t,n,o,i=!0){i&&n.background&&(t.save(),t.setTransform(1,0,0,1,0,0),t.fillStyle=n.background,t.fillRect(0,0,n.width,n.height),t.restore());let r=new Set(n.layers.map(a=>a.matte?.layer).filter(Boolean));for(let a=n.layers.length-1;a>=0;a--){let s=n.layers[a];s.hidden||s.type==="audio"||s.type==="null"||r.has(s.id)||await this.renderLayer(t,s,n,o)}}isActive(t,n,o){return o>=(t.inPoint??0)&&o<(t.outPoint??n.duration)}async renderLayer(t,n,o,i){if(!this.isActive(n,o,i))return;let r=n.transform??{},a=E(r.opacity,i,100)/100;if(a<=0)return;let s=n.type==="video"?this.host.bakedVideoEffects?.(n):void 0,c=(n.effects??[]).filter(f=>!s?.has(f));if(!n.masks?.length&&!n.matte&&!n.motionBlur&&c.every(f=>Ao.has(f.type))){t.save(),t.globalAlpha*=a,t.globalCompositeOperation=Nn[n.blendMode??"normal"];let f=Rn(c,i);f&&(t.filter=f),this.applyShadow(t,c,i),t.setTransform(...this.matrix(n,o,i)),await this.drawContent(t,n,o,i),t.restore();return}let p=this.acquire(o.width,o.height),m=p.getContext("2d");if(n.motionBlur){let f=Math.max(2,n.motionBlur.samples??8),g=(n.motionBlur.shutter??180)/360/o.fps;for(let v=0;v<f;v++){let y=i-g/2+g*v/(f-1);m.save(),m.globalAlpha=1/(v+1),m.setTransform(...this.matrix(n,o,y)),await this.drawContent(m,n,o,y),m.restore()}}else m.save(),m.setTransform(...this.matrix(n,o,i)),await this.drawContent(m,n,o,i),m.restore();if(n.masks?.length){let f=this.matrix(n,o,i);for(let g of n.masks){if(m.save(),m.setTransform(...f),m.globalCompositeOperation=g.inverted?"destination-out":"destination-in",m.beginPath(),g.shape==="path"&&g.points?.length)g.points.forEach(([v,y],k)=>k?m.lineTo(v,y):m.moveTo(v,y)),m.closePath();else{let[v,y,k,L]=E(g.rect,i,[0,0,0,0]);g.shape==="ellipse"?m.ellipse(v+k/2,y+L/2,Math.abs(k/2),Math.abs(L/2),0,0,Math.PI*2):m.roundRect(v,y,k,L,g.radius??0)}m.fillStyle="#000",m.fill(),m.restore()}}for(let f of c)f.type==="fill"&&(m.save(),m.globalCompositeOperation="source-in",m.globalAlpha=E(f.opacity,i,100)/100,m.fillStyle=f.color,m.fillRect(0,0,o.width,o.height),m.restore());if(n.matte){let f=o.layers.find(g=>g.id===n.matte.layer);if(f){let g=this.acquire(o.width,o.height);await this.renderLayer(g.getContext("2d"),{...f,hidden:!1,matte:void 0},o,i),m.save(),m.globalCompositeOperation=n.matte.mode==="alphaInverted"?"destination-out":"destination-in",m.drawImage(g,0,0),m.restore(),this.release(g)}}t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha*=a,t.globalCompositeOperation=Nn[n.blendMode??"normal"];let h=Rn(c,i);h&&(t.filter=h),this.applyShadow(t,c,i);let d=c.find(f=>f.type==="glow");if(d){let f=E(d.strength,i,100)/100;if(t.save(),t.shadowColor="transparent",t.filter=`blur(${E(d.radius,i,24)}px)`,t.globalCompositeOperation="lighter",t.globalAlpha*=f,d.color){let g=this.acquire(o.width,o.height),v=g.getContext("2d");v.drawImage(p,0,0),v.globalCompositeOperation="source-in",v.fillStyle=d.color,v.fillRect(0,0,o.width,o.height),t.drawImage(g,0,0),this.release(g)}else t.drawImage(p,0,0);t.restore()}t.drawImage(p,0,0),t.restore(),this.release(p)}applyShadow(t,n,o){let i=n.find(c=>c.type==="dropShadow");if(!i)return;let r=E(i.distance,o,8),a=(i.angle??135)*Math.PI/180,s=ve(i.color??"#000")??[0,0,0,1];t.shadowColor=$e([s[0],s[1],s[2],s[3]*(E(i.opacity,o,60)/100)]),t.shadowBlur=E(i.blur,o,16),t.shadowOffsetX=Math.sin(a)*r,t.shadowOffsetY=-Math.cos(a)*r}async drawContent(t,n,o,i){let r=n.inPoint??0;switch(n.type){case"solid":{let[a,s]=n.size??[o.width,o.height];t.fillStyle=E(n.color,i,"#000"),t.fillRect(0,0,a,s);return}case"shape":return Oo(t,n,i);case"text":return zn(t,n,i,r,n.outPoint??o.duration,this.project.fonts?Object.keys(this.project.fonts)[0]??this.host.defaultFont:this.host.defaultFont);case"image":{let a=await this.host.image(n.src),[s,c]=n.size??[o.width,o.height];Io(t,a,s,c,n.fit??"cover");return}case"video":{let[a,s]=n.size??[o.width,o.height],c=(n.trimIn??0)+(i-r)*(n.speed??1),u=await this.host.videoFrame(n,c,a,s,o.fps);t.drawImage(u,0,0,a,s);return}case"precomp":{let a=this.comp(n.comp),s=(i-r)*(n.speed??1)+(n.timeOffset??0),c=this.acquire(a.width,a.height);await this.renderComp(c.getContext("2d"),a,s,!0),t.drawImage(c,0,0),this.release(c);return}}}},Ao=new Set(["blur","brightness","saturate","contrast","dropShadow"]),Rn=(e,t)=>e.map(n=>{if(n.type==="blur"){let o=E(n.radius,t,0);return o>.05?`blur(${o}px)`:""}return n.type==="brightness"?`brightness(${E(n.amount,t,100)}%)`:n.type==="saturate"?`saturate(${E(n.amount,t,100)}%)`:n.type==="contrast"?`contrast(${E(n.amount,t,100)}%)`:""}).filter(Boolean).join(" "),Io=(e,t,n,o,i)=>{if(i==="fill")return e.drawImage(t,0,0,n,o);let r=i==="cover"?Math.max(n/t.width,o/t.height):Math.min(n/t.width,o/t.height),a=t.width*r,s=t.height*r;e.save(),e.beginPath(),e.rect(0,0,n,o),e.clip(),e.drawImage(t,(n-a)/2,(o-s)/2,a,s),e.restore()},Dn=(e,t)=>{let[n,o]=E(e.size,t,[200,200]);switch(e.shape){case"rect":return{pts:[[-n/2,-o/2],[n/2,-o/2],[n/2,o/2],[-n/2,o/2]],closed:!0};case"ellipse":return{pts:[...Array(96).keys()].map(i=>{let r=i/96*Math.PI*2-Math.PI/2;return[Math.cos(r)*n/2,Math.sin(r)*o/2]}),closed:!0};case"polygon":{let i=E(e.radius,t,100),r=e.sides??6;return{pts:[...Array(r).keys()].map(a=>{let s=a/r*Math.PI*2-Math.PI/2;return[Math.cos(s)*i,Math.sin(s)*i]}),closed:!0}}default:return{pts:e.points??[],closed:e.closed??e.shape==="path"}}},Oo=(e,t,n)=>{let o=E(t.trim?.start,n,0)/100,i=E(t.trim?.end,n,100)/100;if(e.beginPath(),t.trim&&(o>0||i<1)){let{pts:a,closed:s}=Dn(t,n),c=s?[...a,a[0]]:a,u=c.slice(1).map((g,v)=>Math.hypot(g[0]-c[v][0],g[1]-c[v][1])),p=u.reduce((g,v)=>g+v,0),m=Math.min(o,i)*p,h=Math.max(o,i)*p,d=0,f=!1;for(let g=0;g<u.length;g++){let v=d,y=d+u[g];if(d=y,y<m||v>h)continue;let k=M=>{let w=u[g]?(M-v)/u[g]:0;return[c[g][0]+(c[g+1][0]-c[g][0])*w,c[g][1]+(c[g+1][1]-c[g][1])*w]},L=k(Math.max(m,v)),b=k(Math.min(h,y));f||(e.moveTo(...L),f=!0),e.lineTo(...b)}}else if(t.shape==="rect"){let[a,s]=E(t.size,n,[200,200]);e.roundRect(-a/2,-s/2,a,s,E(t.radius,n,0))}else if(t.shape==="ellipse"){let[a,s]=E(t.size,n,[200,200]);e.ellipse(0,0,Math.abs(a/2),Math.abs(s/2),0,0,Math.PI*2)}else{let{pts:a,closed:s}=Dn(t,n);a.forEach((c,u)=>u?e.lineTo(...c):e.moveTo(...c)),s&&e.closePath()}let r=!!t.trim&&(o>0||i<1);if(t.fill&&!r&&t.shape!=="line"){if(typeof t.fill=="object"&&"linear"in t.fill){let a=e.createLinearGradient(...t.fill.linear.from,...t.fill.linear.to);for(let[s,c]of t.fill.linear.stops)a.addColorStop(s,c);e.fillStyle=a}else e.fillStyle=E(t.fill,n,"#fff");e.fill()}t.stroke&&(e.strokeStyle=E(t.stroke,n,"#fff"),e.lineWidth=E(t.strokeWidth,n,4),e.lineCap=t.lineCap??"round",e.lineJoin="round",e.stroke())};var Ke=(e,[t,n])=>[e[0]*t+e[2]*n+e[4],e[1]*t+e[3]*n+e[5]],Fo=e=>{let t=e[0]*e[3]-e[1]*e[2];return Math.abs(t)<1e-9?null:[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[3]*e[4])/t,(e[1]*e[4]-e[0]*e[5])/t]},Vn=(e,t,n,o,i)=>{switch(e.type){case"solid":case"image":case"video":case"precomp":{let[r,a]=o.layerSize(e,t,n);return[0,0,r,a]}case"shape":{if(e.shape==="rect"||e.shape==="ellipse"){let[u,p]=E(e.size,n,[200,200]);return[-u/2,-p/2,u,p]}if(e.shape==="polygon"){let u=E(e.radius,n,100);return[-u,-u,u*2,u*2]}let r=e.points??[];if(!r.length)return null;let a=r.map(u=>u[0]),s=r.map(u=>u[1]),c=E(e.strokeWidth,n,4)/2+4;return[Math.min(...a)-c,Math.min(...s)-c,Math.max(...a)-Math.min(...a)+c*2,Math.max(...s)-Math.min(...s)+c*2]}case"text":{let r=E(e.size,n,72),a=Nt(i,e,r,E(e.tracking,n,0),zt(e,r,o.host.defaultFont));return[Math.min(...a.lines.map(c=>c.x)),a.top,a.width,a.height]}default:return null}},Hn=(e,t,n,o,i)=>{let r=Vn(e,t,n,o,i);if(!r)return null;let a=o.matrix(e,t,n),[s,c,u,p]=r;return[Ke(a,[s,c]),Ke(a,[s+u,c]),Ke(a,[s+u,c+p]),Ke(a,[s,c+p])]},Bn=(e,t,n,o,i)=>{for(let r of t.layers){if(r.hidden||r.type==="audio"||r.type==="null"||!o.isActive(r,t,n))continue;let a=Vn(r,t,n,o,i),s=Fo(o.matrix(r,t,n));if(!a||!s)continue;let[c,u]=Ke(s,e);if(c>=a[0]&&c<=a[0]+a[2]&&u>=a[1]&&u<=a[1]+a[3])return r.id}return null};var We=new at,fe=null,Ae=document.createElement("canvas"),Kn=()=>{let e=A(_=>_.project),t=A(_=>_.time),n=A(_=>_.comp),o=A(_=>_.layer),i=A(_=>_.playing),r=re(null),a=re(null),s=re(null),[c,u]=Y({w:400,h:600}),[p,m]=Y(0),h=re(!1),d=re(!1),f=e?.comps.find(_=>_.id===n);ae(()=>{let _=r.current;if(!_)return;let x=new ResizeObserver(()=>u({w:_.clientWidth-24,h:_.clientHeight-24}));return x.observe(_),()=>x.disconnect()},[]);let g=f?Math.min(c.w/f.width,c.h/f.height):1,v=async()=>{if(h.current){d.current=!0;return}let _=I(),x=Z();if(!(!_.project||!x||!a.current)){h.current=!0;try{fe||(fe=new pt(_.project,We)),fe.project=_.project,We.playing=_.playing;let C=a.current;(Ae.width!==x.width||Ae.height!==x.height)&&(Ae.width=x.width,Ae.height=x.height);let P=Ae.getContext("2d"),T=performance.now();P.setTransform(1,0,0,1,0,0),P.clearRect(0,0,x.width,x.height),x.background||(P.fillStyle="#000",P.fillRect(0,0,x.width,x.height)),await fe.renderComp(P,x,_.time),We.endFrame(),(C.width!==x.width||C.height!==x.height)&&(C.width=x.width,C.height=x.height),C.getContext("2d").drawImage(Ae,0,0),C.dataset.time=String(_.time),m(performance.now()-T),y()}catch(C){S({message:`Preview error: ${C.message}`})}finally{h.current=!1,d.current&&(d.current=!1,v())}}},y=()=>{let _=I(),x=Z(),C=s.current;if(!C||!x||!fe)return;(C.width!==x.width||C.height!==x.height)&&(C.width=x.width,C.height=x.height);let P=C.getContext("2d");P.clearRect(0,0,C.width,C.height);let T=x.layers.find(he=>he.id===_.layer);if(!T||_.playing||!fe.isActive(T,x,_.time))return;let j=Hn(T,x,_.time,fe,P),X=2/g;P.strokeStyle="#4da3ff",P.lineWidth=X,j&&(P.beginPath(),j.forEach((he,Xn)=>Xn?P.lineTo(...he):P.moveTo(...he)),P.closePath(),P.stroke());let[oe,we]=E(T.transform?.position,_.time,[x.width/2,x.height/2]);P.beginPath(),P.arc(oe,we,6/g,0,Math.PI*2),P.moveTo(oe-12/g,we),P.lineTo(oe+12/g,we),P.moveTo(oe,we-12/g),P.lineTo(oe,we+12/g),P.stroke()};ae(()=>{v()},[e,t,n,i]),ae(()=>{y()},[o,g]);let k=_=>{let x=s.current.getBoundingClientRect();return[(_.clientX-x.left)/x.width*f.width,(_.clientY-x.top)/x.height*f.height]},L=re(null),b=_=>{if(!f||!fe)return;let x=k(_),C=I(),P=s.current.getContext("2d"),T=Bn(x,f,C.time,fe,P);if(S({layer:T,key:null}),!T)return;let j=f.layers.find(X=>X.id===T);_.target.setPointerCapture(_.pointerId),L.current={start:x,pos:E(j.transform?.position,C.time,[f.width/2,f.height/2]),layer:T,moved:!1}},M=_=>{let x=L.current;if(!x||!f)return;let C=k(_),P=C[0]-x.start[0],T=C[1]-x.start[1];if(!x.moved&&Math.hypot(P,T)*g<3)return;x.moved||(x.moved=!0,le());let j=H(I().time,f.fps),X=[Math.round(x.pos[0]+P),Math.round(x.pos[1]+(_.shiftKey?0:T))];me(oe=>{let we=oe.comps.find(he=>he.id===f.id).layers.find(he=>he.id===x.layer);te(we.transform?.position)?q(oe,x.layer,"transform.position",j,X):Ne(oe,x.layer,"transform.position",X)})},w=()=>{L.current?.moved&&ce(),L.current=null};if(!f)return l("div",{class:"viewer",ref:r});let $={width:`${f.width*g}px`,height:`${f.height*g}px`};return l("div",{class:"viewer",ref:r,children:[l("div",{class:"stage",style:$,children:[l("canvas",{ref:a,class:"frame",style:$}),l("canvas",{ref:s,class:"overlay",style:$,onPointerDown:b,onPointerMove:M,onPointerUp:w})]}),l("div",{class:"viewer-info",children:[f.width,"\xD7",f.height," \xB7 ",Math.round(g*100),"% \xB7 ",p.toFixed(0)," ms/frame"]})]})};var Un=new st,Rt=0,qn=()=>{let e=Z();if(!e)return;I().time>=e.duration-1/e.fps&&S({time:0});let t=performance.now()-I().time*1e3;S({playing:!0});let n=o=>{let i=I(),r=Z();if(!i.playing||!r)return;let a=(o-t)/1e3;if(a>=r.duration){if(i.loop){a=0,Ue(),S({time:0}),qn();return}Ue(),S({time:H(r.duration-1/r.fps,r.fps)});return}S({time:a}),Un.sync(i.project,r,a,!0),Rt=requestAnimationFrame(n)};Rt=requestAnimationFrame(n)},Ue=()=>{cancelAnimationFrame(Rt);let e=Z();S({playing:!1,time:e?H(I().time,e.fps):I().time}),Un.stop(),We.stopAll()},Jn=()=>I().playing?Ue():qn(),Ie=e=>{let t=Z(),n="";z(o=>{n=ie(o,t.id,{inPoint:H(I().time,t.fps),...e}).id}),n&&S({layer:n,key:null})},zo={Text:()=>Ie({type:"text",name:"Text",text:"Your text",size:Math.round(Z().width/10),color:"#ffffff",weight:800}),Shape:()=>Ie({type:"shape",name:"Shape",shape:"ellipse",size:[300,300],fill:"#E8692A"}),Solid:()=>Ie({type:"solid",name:"Solid",color:"#1f2933"}),Null:()=>Ie({type:"null",name:"Null"}),"Image / video / audio\u2026":()=>{let e=prompt("Path to the file, relative to the project file:");if(!e)return;let t=/\.(mp4|mov|webm|m4v)$/i.test(e)?"video":/\.(mp3|wav|m4a|aac|ogg)$/i.test(e)?"audio":"image";Ie({type:t,name:e.split("/").pop(),src:e})},"New comp (precomp)\u2026":()=>{let e=prompt("Id for the new composition:");if(!e)return;let t=Z();z(n=>{fn(n,{id:e,name:e,duration:t.duration,width:t.width,height:t.height,fps:t.fps})}),Ie({type:"precomp",name:e,comp:e})}},No=({onClose:e})=>{let t=En(),[n,o]=Y(t?.type==="text"?"text.fadeUp":"opener.logoReveal"),i=J[n],r=m=>J[m].kind==="text"||m==="element.highlightWord"?{layer:I().layer??""}:m==="opener.logoReveal"||m==="opener.bars"?{title:"Your Brand",start:H(I().time,30)}:m==="kinetic.sequence"?{phrases:["Make","it","move"],start:H(I().time,30),style:"slam"}:m==="element.lowerThird"?{name:"Your Name",title:"Your title",start:H(I().time,30)}:m==="transition.between"?{from:"",to:"",type:"push",duration:.5}:m==="slides.slideshow"?{items:[{src:"photo1.jpg",caption:"Caption"}],each:3,transition:"push"}:{},[a,s]=Y(JSON.stringify(r(n),null,2)),[c,u]=Y("");return l("div",{class:"modal",onClick:e,children:l("div",{class:"dialog",onClick:m=>m.stopPropagation(),onKeyDown:m=>m.stopPropagation(),children:[l("div",{class:"dialog-list",children:["text","kinetic","opener","slides","transition","element"].map(m=>l("div",{children:[l("div",{class:"group",children:m}),Object.entries(J).filter(([,h])=>h.kind===m).map(([h])=>l("button",{class:h===n?"active":"",onClick:()=>{o(h),s(JSON.stringify(r(h),null,2)),u("")},children:h.split(".")[1]},h))]},m))}),l("div",{class:"dialog-body",children:[l("h3",{children:n}),l("p",{children:i.description}),l("p",{class:"hint",children:["Params: ",i.params]}),l("textarea",{rows:10,value:a,spellcheck:!1,onInput:m=>s(m.target.value)}),c&&l("div",{class:"error",children:c}),l("div",{class:"row",children:[l("button",{onClick:e,children:"Cancel"}),l("button",{class:"primary",onClick:()=>{try{let m=JSON.parse(a),h=[],d=I().project;if(z(f=>{h=i.apply(f,I().comp,m).created}),I().project===d)throw new Error(I().message||"Preset failed");h[0]&&S({layer:h[0]}),e()}catch(m){u(m.message)}},children:"Apply"})]})]})]})})},Wn=e=>{if(e.target.closest?.("input, textarea, select"))return;let n=I(),o=Z();if(!o)return;let i=e.metaKey||e.ctrlKey,r=1/o.fps,a=s=>S({time:Math.max(0,Math.min(o.duration,H(s,o.fps))),playing:!1});if(e.code==="Space")e.preventDefault(),Jn();else if(i&&e.key.toLowerCase()==="z")e.preventDefault(),e.shiftKey?ct():At();else if(i&&e.key.toLowerCase()==="y")e.preventDefault(),ct();else if(i&&e.key.toLowerCase()==="d"&&n.layer)e.preventDefault(),z(s=>{let c=nt(s,n.layer);S({layer:c.id})});else if(e.key==="ArrowLeft")e.preventDefault(),a(n.time-r*(e.shiftKey?10:1));else if(e.key==="ArrowRight")e.preventDefault(),a(n.time+r*(e.shiftKey?10:1));else if(e.key==="Home")a(0);else if(e.key==="End")a(o.duration-r);else if((e.key==="j"||e.key==="k")&&n.layer){let s=On(n.layer),c=e.key==="j"?[...s].reverse().find(u=>u<n.time-.001):s.find(u=>u>n.time+.001);c!==void 0&&a(c)}else e.key==="["&&n.layer?z(s=>{let c=s.comps.find(u=>u.id===o.id).layers.find(u=>u.id===n.layer);ze(s,n.layer,H(n.time,o.fps)-(c.inPoint??0))}):e.key==="]"&&n.layer?z(s=>ee(s,n.layer,{outPoint:H(n.time,o.fps)})):e.key==="Delete"||e.key==="Backspace"?n.key?(z(s=>Re(s,n.key.layer,n.key.path,n.key.t)),S({key:null})):n.layer&&(z(s=>tt(s,n.layer)),S({layer:null})):e.key==="Escape"?S({layer:null,key:null}):e.key==="="||e.key==="+"?S({zoom:Math.min(2e3,n.zoom*1.25)}):e.key==="-"&&S({zoom:Math.max(10,n.zoom/1.25)})},Ro=(e,t)=>{let n=Math.round(e*t),o=Math.floor(n/t);return`${String(Math.floor(o/60)).padStart(2,"0")}:${String(o%60).padStart(2,"0")}:${String(n%t).padStart(2,"0")}`},Do=()=>{let e=A(r=>r.time),t=A(r=>r.playing),n=A(r=>r.loop),o=A(r=>r.zoom),i=Z();return i?l("div",{class:"transport",children:[l("button",{title:"Start (Home)",onClick:()=>S({time:0}),children:"\u23EE"}),l("button",{title:"Previous frame (\u2190)",onClick:()=>S({time:Math.max(0,H(e-1/i.fps,i.fps))}),children:"\u25C0\uFE0E"}),l("button",{class:"play",title:"Play / pause (Space)",onClick:Jn,children:t?"\u275A\u275A":"\u25B6"}),l("button",{title:"Next frame (\u2192)",onClick:()=>S({time:Math.min(i.duration,H(e+1/i.fps,i.fps))}),children:"\u25B6\uFE0E"}),l("button",{class:n?"on":"",title:"Loop",onClick:()=>S({loop:!n}),children:"\u27F2"}),l("span",{class:"timecode",children:Ro(e,i.fps)}),l("span",{class:"muted",children:[e.toFixed(2),"s / ",i.duration,"s"]}),l("span",{class:"spacer"}),l("span",{class:"muted",children:"Zoom"}),l("button",{onClick:()=>S({zoom:Math.max(10,o/1.25)}),children:"\u2212"}),l("button",{onClick:()=>S({zoom:Math.min(2e3,o*1.25)}),children:"+"})]}):null},Vo=({onPresets:e})=>{let t=A(u=>u.project),n=A(u=>u.comp),o=A(u=>u.status),i=A(u=>u.message),r=A(u=>u.warnings),a=A(u=>u.render),[s,c]=Y(!1);return l("header",{class:"topbar",children:[l("div",{class:"brand",children:[l("b",{children:"DT.ly"})," Studio ",l("span",{class:"muted",children:["\xB7 ",ue.file]})]}),l("nav",{class:"comps",children:t?.comps.map(u=>l("button",{class:u.id===n?"active":"",onClick:()=>{Ue(),S({comp:u.id,layer:null,key:null,time:0})},children:[u.name??u.id,t.root===u.id?" \u2605":""]},u.id))}),l("div",{class:"actions",children:[l("div",{class:"menu-wrap",children:[l("button",{onClick:()=>c(!s),children:"+ Layer \u25BE"}),s&&l("div",{class:"menu",onMouseLeave:()=>c(!1),children:Object.entries(zo).map(([u,p])=>l("button",{onClick:()=>{c(!1),p()},children:u},u))})]}),l("button",{onClick:e,children:"Presets\u2026"}),l("button",{title:"Undo (\u2318Z)",onClick:At,children:"\u21B6"}),l("button",{title:"Redo (\u21E7\u2318Z)",onClick:ct,children:"\u21B7"}),l("button",{class:"primary",disabled:a.active,onClick:()=>{Ue(),Ln()},children:a.active?`Rendering ${a.total?Math.round((a.done??0)/a.total*100):0}%`:"Render MP4"})]}),l("div",{class:`status ${o}`,title:r.join(`
|
|
4
|
-
`),children:[i||(o==="saving"?"Saving\u2026":o==="error"?"Save failed":o==="reloaded"?"Reloaded from disk":"Saved"),r.length>0&&l("span",{class:"warn",children:[" \xB7 ",r.length," warning",r.length>1?"s":""]}),a.out&&!a.active&&l("a",{href:`/api/media?src=${encodeURIComponent(a.out)}&token=${ue.token}`,target:"_blank",children:[" \xB7 open ",a.out]}),a.error&&l("span",{class:"error",children:[" \xB7 render failed: ",a.error]})]})]})},Ho=()=>{let e=A(o=>o.project),[t,n]=Y(!1);return ae(()=>(document.addEventListener("keydown",Wn),()=>document.removeEventListener("keydown",Wn)),[]),e?l("div",{class:"app",children:[l(Vo,{onPresets:()=>n(!0)}),l("main",{class:"workspace",children:[l(Kn,{}),l($n,{})]}),l("section",{class:"bottom",children:[l(Do,{}),l(In,{})]}),t&&l(No,{onClose:()=>n(!1)})]}):l("div",{class:"loading",children:"Loading project\u2026"})};(async()=>{document.title=`${ue.file} \u2014 DT.ly Studio`,await It();let e=Z();e&&S({zoom:Math.max(20,Math.min(400,(window.innerWidth-260)/e.duration))}),await Cn(I().project),Sn(),Zt(l(Ho,{}),document.getElementById("root"))})();
|
|
1
|
+
var F,no,Kr,Fe,un,Ot,oo,Et,ro,fn,dn,Ur,Nt={},At=[],Gr=/^m(i|n|o|s|text|space)$/,hn=Array.isArray,so=At.slice,Xe=Object.assign;function qe(e){e&&e.parentNode&&e.remove()}function Tt(e,t,n,o,s){var r={type:e,props:t,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:s||++no,__i:-1,__u:0};return!s&&F.vnode&&F.vnode(r),r}function We(e){return e.children}function It(e,t){this.props=e,this.context=t,this.__g=0}function De(e,t){if(t==null)return e.__&&De(e.__,e.__i+1);for(var n;t<e.__k.length;t++)if((n=e.__k[t])&&n.__e)return n.__e;return typeof e.type!="function"||e.props.__P?null:De(e)}function ao(e){if((e=e.__)&&e.__c&&!e.props.__P)return e.__e=null,e.__k.some(function(t){return t&&(e.__e=t.__e)}),ao(e)}function eo(e){(8&e.__g||(e.__g|=8,Fe.push(e),Ot++))&&un==F.debounceRendering||((un=F.debounceRendering)||queueMicrotask)(io)}function io(){var e,t,n,o,s,r,a,i,c;try{for(t=1;Fe.length;)Fe.length>t&&Fe.sort(oo),e=Fe.shift(),t=Fe.length,8&e.__g&&(o=void 0,s=void 0,r=(s=(n=e).__v).__e,a=[],i=[],(c=n.__P)&&((o=Xe({constructor:void 0},s)).__v=s.__v+1,F.vnode&&F.vnode(o),gn(c,o,s,n.__n,c.namespaceURI,32&s.__u?[r]:null,a,r||De(s),32&s.__u,i),o.__v=s.__v,o.__.__k[o.__i]=o,uo(a,o,i),s.__=s.__e=null,o.__e!=r&&ao(o)))}finally{(Ot=Fe.length)&&(un||queueMicrotask)(io)}}function co(e,t,n,o,s,r,a,i,c,l,u){var d,f,p,m,h,b,y=o.__k||At,v=t.length;for(c=qr(n,t,y,c,v),d=0;d<v;d++)(p=n.__k[d])!=null&&(f=~p.__i&&y[p.__i]||Nt,p.__i=d,b=gn(e,p,f,s,r,a,i,c,l,u),m=p.__e,(f.ref!=p.ref||8&f.__u)&&(f.ref&&bn(f.ref,null,p,f),p.ref&&u.push(p.ref,p.__c||m,p)),h=h||m,4&p.__u?(c=lo(p,c,e,!f.__v),f.__e&&(f.__e=null)):typeof p.type=="function"&&b!==void 0?c=b:m&&(c=m.nextSibling),p.__u&=-21);return n.__e=h,c}function qr(e,t,n,o,s){var r,a,i,c,l,u,d,f,p,m=n.length,h=m,b=0,y=0,v=e.__k=Array(s);for(r=0;r<s;r++)(a=t[r])!=null&&typeof a!="boolean"&&typeof a!="function"?(typeof a!="object"||a.constructor==String?a=v[r]=Tt(null,a):hn(a)?a=v[r]=Tt(We,{children:a}):a.constructor===void 0&&a.__b?a=v[r]=Tt(a.type,a.props,a.key,a.ref,a.__v):v[r]=a,c=r+b,a.__=e,a.__b=e.__b+1,i=null,~(l=a.__i=Xr(a,n,c,h))&&(h--,(i=n[l])&&(i.__u|=2)),i&&i.__v?(a.__u|=16,l==c-1?b--:l==c+1?b++:l!=c&&(l>c?b--:b++,y=1)):(~l||(s>m?b--:s<m&&b++),typeof a.type!="function"&&(a.__u|=4))):v[r]=null;if(y){for(u=[],d=[],r=0;r<s;r++)if((a=v[r])&&16&a.__u){for(b=0,f=u.length;b<f;)u[p=b+f>>1]<a.__i?b=p+1:f=p;u[b]=a.__i,d[r]=b+1}for(b=u.length;r--;)d[r]&&(d[r]==b?b--:v[r].__u|=4)}if(h)for(r=0;r<m;r++)!(i=n[r])||2&i.__u||(i.__e==o&&(o=De(i)),yn(i,i));return o}function lo(e,t,n,o){var s,r,a,i;if(typeof e.type=="function"){if(e.props.__P)return t;if(s=e.__k)for(r=0;r<s.length;r++)s[r]&&(s[r].__=e,t=lo(s[r],t,n,!1));return t}for(t&&!t.parentNode&&(t=De(e))&&!t.parentNode&&(t=null),a=e.__e,i=t;i&&i.nodeType==8;)i=i.nextSibling;for(a!=i&&(!o&&n.moveBefore&&a.parentNode?n.moveBefore(a,t):n.insertBefore(a,t||null)),t=a;(t=t&&t.nextSibling)&&t.nodeType==8&&!t.data.startsWith("$s"););return t}function Xr(e,t,n,o){var s,r=e.key,a=e.type,i=t[n],c=i&&!(2&i.__u);if(i===null&&r==null||c&&r==i.key&&a==i.type)return n;if(o>(c?1:0)){for(s=n-1;s>=0;s--)if((i=t[s])&&!(2&i.__u)&&r==i.key&&a==i.type)return s;for(s=n+1;s<t.length;s++)if((i=t[s])&&!(2&i.__u)&&r==i.key&&a==i.type)return s}return-1}function to(e,t,n){n==null&&(n=""),t[0]=="-"?e.setProperty(t,n):e[t]=n}function $t(e,t,n,o,s){var r,a;if(t=="style")if(typeof n=="string")e.style.cssText=n;else{if(typeof o=="string"&&(e.style.cssText=o=""),o)for(t in o)n&&t in n||to(e.style,t);if(n)for(t in n)o&&n[t]==o[t]||to(e.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")(e.__e||(e.__e={}))[t]=n,n&&o||(a=dn[t]||(dn[t]=Zr(t)),(e.__a||(e.__a={}))[t]=fn,r=t!=(t=t.replace(ro,"$1")),(t=t.slice(2))[0]<"a"&&(t=t.toLowerCase()),n?e.addEventListener(t,a,r):e.removeEventListener(t,a,r));else{if(s=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in e)try{return void(e[t]=n??"")}catch{}if(typeof n=="function")return;n==null||n===!1&&t[4]!="-"?e.removeAttribute(t):e.setAttribute(t,t=="popover"&&n==1?"":n)}}function Zr(e){return function(t){var n=this.__e;if(n){if(n=n[e],t[Et]==null)t[Et]=fn++;else if(t[Et]<this.__a[e])return;return n(F.event?F.event(t):t)}}}function gn(e,t,n,o,s,r,a,i,c,l){var u,d,f,p,m,h,b,y,v,k,w,L,C,S,_,x,M,P,$=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(c=32&n.__u,u=n.__c.__z)&&(t.__u|=c,d=r=[],u.nodeType==8?i=mn(u,r):r.push(u),i=r[0]||i),(u=F.__b)&&u(t);e:if(typeof $=="function"){f=a.length;try{if(y=t.props,v=(u=$.prototype)&&u.render,k=(u=$.contextType)&&o[u.__c],w=u?k?k.props.value:u.__:o,(p=n.__c)?(t.__c=p,2&p.__g&&(p.__g|=1)):(v?t.__c=p=new $(y,w):(t.__c=p=new It(y,w),p.constructor=$,p.render=Qr),k&&k.sub(p),p.state||(p.state={}),p.__n=o,p.__g|=8,p.__h=[],p.__k=[]),v&&(p.__s||(p.__s=p.state),$.getDerivedStateFromProps&&(p.__s==p.state&&(p.__s=Xe({},p.__s)),Xe(p.__s,$.getDerivedStateFromProps(y,p.__s)))),m=p.props,h=p.state,p.__v=t,n.__c){if(y!==m&&v&&!$.getDerivedStateFromProps&&p.componentWillReceiveProps&&p.componentWillReceiveProps(y,w),t.__v==n.__v&&!(8&p.__g)||!(4&p.__g)&&p.shouldComponentUpdate&&p.shouldComponentUpdate(y,p.__s,w)===!1){t.__v!=n.__v&&(p.props=y,p.state=p.__s,p.__g&=-9),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(I){I&&(I.__=t)}),At.push.apply(p.__h,p.__k),p.__k=[],p.__h.length&&a.push(p),i=De(n);break e}p.componentWillUpdate&&p.componentWillUpdate(y,p.__s,w),v&&p.componentDidUpdate&&p.__h.push(function(){p.componentDidUpdate(m,h,b)})}else v&&!$.getDerivedStateFromProps&&p.componentWillMount&&p.componentWillMount(),v&&p.componentDidMount&&p.__h.push(p.componentDidMount);if(p.context=w,p.props=y,p.__P=e,p.__g&=-5,L=F.__r,C=0,v)p.state=p.__s,p.__g&=-9,L&&L(t),u=p.render(p.props,p.state,p.context),At.push.apply(p.__h,p.__k),p.__k=[];else do p.__g&=-9,L&&L(t),u=p.render(p.props,p.state,p.context),p.state=p.__s;while(8&p.__g&&++C<25);p.state=p.__s,p.getChildContext&&(o=Xe({},o,p.getChildContext())),v&&n.__c&&p.getSnapshotBeforeUpdate&&(b=p.getSnapshotBeforeUpdate(m,h)),S=u&&u.type===We&&u.key==null?u.props.children:u,y.__P&&(u=i,s=(e=y.__P).namespaceURI,c=r=null,n.props&&n.props.__P!=e&&(n.__k.some(function(I){I&&yn(I,I)}),n.__k=null),i=n.__k?De(n,0):null),i=co(e,hn(S)?S:[S],t,n,o,s,r,a,i,c,l),y.__P&&(t.__e=null,i=u),t.__u&=-161,d&&d.some(qe),p.__h.length&&a.push(p),1&p.__g&&(p.__g&=-4)}catch(I){if(a.length=f,t.__v=null,c||r)if(I.then){if(_=0,t.__u|=128|c,r){for(~(M=r.indexOf(i||void 0))||(M=r.length);(P=r[M-1])&&P.nodeType==8;)M--;for(;M<r.length;M++)if(P=r[M]){if(r[M]=null,P.nodeType==8){if(P.data.startsWith("$s"))_++||(x=P);else if(_&&P.data.startsWith("/$s")&&!--_)break}else if(!_)break}}if(!x){for(;i&&i.nodeType==8&&i.nextSibling;)i=i.nextSibling;x=i}(u=mn(x=t.__c.__z||(t.__c.__z=x)))?(t.__e=x,i=u):t.__e=i,i=i&&i.nextSibling}else r&&r.some(qe);else t.__e=n.__e;t.__k||(t.__k=n.__k||[]),I.then||po(t),F.__e(I,t,n)}}else i=t.__e=Yr(n.__e,t,n,o,s,r,a,c,l,e);return(u=F.diffed)&&u(t),i}function mn(e,t){if(e&&e.nodeType==8&&e.data.startsWith("$s"))for(var n=1;e=e.nextSibling;){if(e.nodeType==8){if(e.data.startsWith("$s"))n++;else if(e.data.startsWith("/$s")&&!--n)return e}t&&t.push(e)}}function po(e){e&&(e.__c&&(e.__c.__g|=4),e.__k&&e.__k.some(po))}function uo(e,t,n){for(var o=0;o<n.length;)bn(n[o++],n[o++],n[o++]);F.__c&&F.__c(t,e),e.some(function(s){try{e=s.__h,s.__h=[],e.some(function(r){r.call(s)})}catch(r){F.__e(r,s.__v)}})}function Yr(e,t,n,o,s,r,a,i,c,l){var u,d,f,p,m,h,b,y,v,k=n.props||Nt,w=t.props,L=t.type;if(L=="svg"?s="http://www.w3.org/2000/svg":L=="math"?s="http://www.w3.org/1998/Math/MathML":s||(s="http://www.w3.org/1999/xhtml"),r){for(u=0;u<r.length;u++)if((m=r[u])&&(L?m.localName==L:m.nodeType==3)){e=m,r[u]=null;break}}if(!e){if(y=l.ownerDocument||document,!L)return y.createTextNode(w);e=y.createElementNS(s,L,w.is&&w),i&&(F.__m&&F.__m(t,r),i=!1),r=null}if(L){if(l=L=="template"?e.content:e,r=L=="textarea"&&w.defaultValue!=null?null:r&&so.call(l.childNodes),!i&&r)for(k={},u=0;u<e.attributes.length;u++)k[(m=e.attributes[u]).name]=m.value;for(u in k)m=k[u],u=="dangerouslySetInnerHTML"?f=m:u=="children"||u in w||u=="value"&&"defaultValue"in w||u=="checked"&&"defaultChecked"in w||$t(e,u,null,m,s);for(u in v=1&n.__u,w)m=w[u],u=="children"?p=m:u=="dangerouslySetInnerHTML"?d=m:u=="value"?h=m:u=="checked"?b=m:i&&typeof m!="function"||!(k[u]!==m||v&&m!=null)||$t(e,u,m,k[u],s);d?(i||f&&(d.__html==f.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[]):(f&&(e.textContent=""),(L=="foreignObject"||s=="http://www.w3.org/1998/Math/MathML"&&Gr.test(L))&&(s="http://www.w3.org/1999/xhtml"),co(l,hn(p)?p:[p],t,n,o,s,r,a,r?r[0]:n.__k&&De(n,0),i,c),r&&r.some(qe)),i&&L!="textarea"||(u="value",L=="progress"&&h==null?e.removeAttribute(u):h==null||h===e[u]&&(L!="progress"||h)||$t(e,u,h,k[u],s),u="checked",b!=null&&b!=e[u]&&$t(e,u,b,k[u],s))}else k===w||i&&e.data==w||(e.data=w);return e}function bn(e,t,n,o){try{typeof e=="function"?t?t.__x=e(t)||1:o&&(o=o.__c||o.__e)&&(t=o.__x)&&(o.__x=null,typeof t=="function"?t():e(null)):e.current=t}catch(s){F.__e(s,n)}}function yn(e,t,n){var o,s,r,a;if(F.unmount&&F.unmount(e),!(o=e.ref)||o.current&&o.current!=e.__e||bn(o,null,t,e),o=e.__c){if(o.componentWillUnmount)try{o.componentWillUnmount()}catch(i){F.__e(i,t)}o.__P=o.__n=null}if(o=e.__k)for(a=0;a<o.length;a++)o[a]&&yn(o[a],t,typeof e.type!="function"||n&&!e.props.__P);!n&&(o=e.__c)&&(o=o.__z)&&(s=mn(o,r=[]))&&(o==e.__e&&r.some(qe),qe(s),qe(o)),(o=e.__e)&&(n||qe(o),o.__e&&(o.__e=null)),e.__e=e.__c=e.__=null}function Qr(e,t,n){return this.constructor(e,n)}function mo(e,t){var n,o,s,r;F.__&&F.__(e,t),t.nodeType==9&&(t=t.documentElement),o=(n=e&&32&e.__u)?null:t.__k,t.__k=Tt(We,{children:[e]}),s=[],r=[],gn(t,t.__k,o||Nt,Nt,t.namespaceURI,o?null:t.firstChild?so.call(t.childNodes):null,s,o?o.__e:t.firstChild,n,r),uo(s,t.__k,r),t.__k.props.children=null}F={__e:function(e,t,n,o){for(var s,r,a;t=t.__;)if((s=t.__c)&&!(1&s.__g)){s.__g|=4;try{if((a=(r=s.constructor)&&r.getDerivedStateFromError)&&s.setState(r.getDerivedStateFromError(e)),s.componentDidCatch&&(s.componentDidCatch(e,o||{}),a=1),a&&8&s.__g)return void(s.__g|=2)}catch(i){e=i}}throw Ot=0,e}},no=0,Kr=function(e){return e!=null&&e.constructor===void 0},It.prototype.setState=function(e,t){var n=this.__s;n&&n!=this.state||(n=this.__s=Xe({},this.state)),typeof e=="function"&&(e=e(Xe({},n),this.props)),e&&(Xe(n,e),this.__v&&(t&&this.__k.push(t),eo(this)))},It.prototype.forceUpdate=function(e){this.__v&&(this.__g|=4,e&&this.__h.push(e),eo(this))},It.prototype.render=We,Fe=[],Ot=0,oo=function(e,t){return e.__v.__b-t.__v.__b},Et=Symbol(),ro=/(PointerCapture)$|Capture$/i,fn=0,dn={},Ur=0;var pt,oe,wn,fo,vn=Object.is,jt=0,_o=[],xn=[],Q=F,ho=Q.__b,go=Q.__r,bo=Q.diffed,yo=Q.__c,wo=Q.unmount,vo=Q.__;function _n(e,t){Q.__h&&Q.__h(oe,e,jt||t),jt=0;var n=oe.__H||(oe.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function le(e){return jt=1,es(Po,e)}function es(e,t,n){var o=_n(pt++,2);if(o.t=e,!o.__c&&(o.__=[n?n(t):Po(void 0,t),function(r){var a=o.__N?o.__N[0]:o.__[0],i=o.t(a,r);vn(a,i)||(o.__N=[i,o.__[1]],o.__c.setState({}))}],o.__c=oe,!oe.__f)){oe.__f=!0;var s=oe.shouldComponentUpdate;oe.shouldComponentUpdate=function(r,a,i){var c=this.__H;if(!c)return!0;var l=!1,u=this.props!=r;if(c.__.some(function(f){f.__N&&(l=!0,vn(f.__[0],f.__N[0])||(u=!0))}),s){var d=s.call(this,r,a,i);return l?d||u:d}return!l||u}}return o.__}function Pe(e,t){var n=_n(pt++,3);!Q.__s&&Mo(n.__H,t)&&(n.__P=!0,n.__=e,n.u=t,oe.__H.__h.push(n))}function xe(e){return jt=5,ts(function(){return{current:e}},[])}function ts(e,t){var n=_n(pt++,7);return Mo(n.__H,t)&&(n.__=e(),n.__H=t),n.__}function ns(){var e;do{for(;e=xn.shift();)try{lt(e)}catch(n){Q.__e(n,{__:(e=e.__P)&&e.__v})}for(;e=_o.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(lt),t.__h.some(kn),t.__h=[]}catch(n){t.__h=[],Q.__e(n,e.__v)}}}while(xn.length)}Q.__b=function(e){oe=null,ho&&ho(e)},Q.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),vo&&vo(e,t)},Q.__r=function(e){go&&go(e),pt=0;var t=(oe=e.__c).__H;t&&(wn==oe?oe.__h=[]:(t.__h.some(lt),t.__h.some(kn),pt=0),t.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})),wn=oe},Q.diffed=function(e){bo&&bo(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&ko(_o.push(t)),t.__H.__.some(function(n){n.u&&(n.__H=n.u)})),wn=oe=null},Q.__c=function(e,t){t.some(function(n){try{n.__h.some(lt),n.__h=n.__h.filter(function(o){return!o.__||kn(o)})}catch(o){t.some(function(s){s.__h&&(s.__h=[])}),t=[],Q.__e(o,n.__v)}}),yo&&yo(e,t)},Q.unmount=function(e){wo&&wo(e);var t,n,o=e.__c;o&&o.__H&&(o.__H.__.some(function(s){try{if(s.__P&&s.__c){if(n===void 0){for(n=e.__;n&&(!n.__c||!n.__c.__P);)n=n.__;n=n&&n.__c}s.__P=n,ko(xn.push(s))}else lt(s)}catch(r){t=r}}),o.__H=void 0,t&&Q.__e(t,o.__v))};var xo=typeof requestAnimationFrame=="function";function os(e){var t,n=function(){clearTimeout(o),xo&&cancelAnimationFrame(t),setTimeout(e)},o=setTimeout(n,35);xo&&(t=requestAnimationFrame(n))}function ko(e){e!=1&&fo==Q.requestAnimationFrame||((fo=Q.requestAnimationFrame)||os)(ns)}function lt(e){var t=oe,n=e.__c;typeof n=="function"&&(e.__c=void 0,n()),oe=t}function kn(e){var t=oe;e.__c=e.__(),oe=t}function Mo(e,t){return!e||e.length!=t.length||t.some(function(n,o){return!vn(n,e[o])})}function Po(e,t){return typeof t=="function"?t(e):t}var be=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&"keyframes"in e;var rs={white:"#ffffff",black:"#000000",red:"#ff0000",green:"#008000",blue:"#0000ff",yellow:"#ffff00",orange:"#ffa500",transparent:"#00000000",gray:"#808080",grey:"#808080"},ke=e=>{let t=(rs[e.trim().toLowerCase()]??e).trim();if(t.startsWith("#")){let o=t.slice(1);if((o.length===3||o.length===4)&&(o=[...o].map(r=>r+r).join("")),o.length!==6&&o.length!==8)return null;let s=r=>parseInt(o.slice(r,r+2),16);return[s(0),s(2),s(4),o.length===8?s(6)/255:1]}let n=t.match(/^rgba?\(([^)]+)\)$/i);if(n){let o=n[1].split(/[\s,\/]+/).filter(Boolean).map(Number);return[o[0],o[1],o[2],o[3]??1]}return null},Oe=([e,t,n,o])=>`rgba(${Math.round(e)},${Math.round(t)},${Math.round(n)},${Math.max(0,Math.min(1,o)).toFixed(4)})`;var ue=e=>{let t=[],n=e.match(/[a-df-z]|-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?/gi)??[],o=0,s="",r=[0,0],a=[0,0],i=null,c=null,l=()=>Number(n[o++]),u=()=>o<n.length&&!/^[a-z]$/i.test(n[o]);for(;o<n.length;){if(/^[a-z]$/i.test(n[o]))s=n[o++];else if(!s){o++;continue}let d=s===s.toLowerCase(),f=m=>d?[r[0]+m[0],r[1]+m[1]]:m,p=s.toUpperCase();if(!(p==="Z"&&(t.push({kind:"Z"}),r=a,i=c=null,!u())))do{if(p==="M"){r=f([l(),l()]),a=r,t.push({kind:"M",p:r}),s=d?"l":"L",i=c=null;break}if(p==="L")r=f([l(),l()]),t.push({kind:"L",p:r}),i=c=null;else if(p==="H"){let m=l();r=[d?r[0]+m:m,r[1]],t.push({kind:"L",p:r}),i=c=null}else if(p==="V"){let m=l();r=[r[0],d?r[1]+m:m],t.push({kind:"L",p:r}),i=c=null}else if(p==="C"){let m=f([l(),l()]),h=f([l(),l()]),b=f([l(),l()]);t.push({kind:"C",c1:m,c2:h,p:b}),r=b,i=h,c=null}else if(p==="S"){let m=i?[2*r[0]-i[0],2*r[1]-i[1]]:r,h=f([l(),l()]),b=f([l(),l()]);t.push({kind:"C",c1:m,c2:h,p:b}),r=b,i=h,c=null}else if(p==="Q"||p==="T"){let m=p==="Q"?f([l(),l()]):c?[2*r[0]-c[0],2*r[1]-c[1]]:r,h=f([l(),l()]);t.push({kind:"C",c1:[r[0]+.6666666666666666*(m[0]-r[0]),r[1]+.6666666666666666*(m[1]-r[1])],c2:[h[0]+.6666666666666666*(m[0]-h[0]),h[1]+.6666666666666666*(m[1]-h[1])],p:h}),r=h,c=m,i=null}else if(p==="A"){let m=l(),h=l(),b=l(),y=l(),v=l(),k=f([l(),l()]);for(let w of ss(r,k,m,h,b,!!y,!!v))t.push(w);r=k,i=c=null}else{o++;break}}while(u())}return t},ss=(e,t,n,o,s,r,a)=>{if(!n||!o)return[{kind:"L",p:t}];n=Math.abs(n),o=Math.abs(o);let i=s*Math.PI/180,c=Math.cos(i),l=Math.sin(i),u=(e[0]-t[0])/2,d=(e[1]-t[1])/2,f=c*u+l*d,p=-l*u+c*d,m=f*f/(n*n)+p*p/(o*o);m>1&&(n*=Math.sqrt(m),o*=Math.sqrt(m));let h=r===a?-1:1,b=n*n*o*o-n*n*p*p-o*o*f*f,y=h*Math.sqrt(Math.max(0,b/(n*n*p*p+o*o*f*f))),v=y*n*p/o,k=-y*o*f/n,w=c*v-l*k+(e[0]+t[0])/2,L=l*v+c*k+(e[1]+t[1])/2,C=(O,V,B,ge)=>Math.atan2(O*ge-V*B,O*B+V*ge),S=C(1,0,(f-v)/n,(p-k)/o),_=C((f-v)/n,(p-k)/o,(-f-v)/n,(-p-k)/o);!a&&_>0&&(_-=Math.PI*2),a&&_<0&&(_+=Math.PI*2);let x=Math.ceil(Math.abs(_)/(Math.PI/2)),M=[],P=_/x,$=4/3*Math.tan(P/4),I=O=>[w+n*Math.cos(O)*c-o*Math.sin(O)*l,L+n*Math.cos(O)*l+o*Math.sin(O)*c],N=O=>[-n*Math.sin(O)*c-o*Math.cos(O)*l,-n*Math.sin(O)*l+o*Math.cos(O)*c];for(let O=0;O<x;O++){let V=S,B=S+P,ge=I(V),ae=I(B),pe=N(V),Me=N(B);M.push({kind:"C",c1:[ge[0]+$*pe[0],ge[1]+$*pe[1]],c2:[ae[0]-$*Me[0],ae[1]-$*Me[1]],p:O===x-1?t:ae}),S=B}return M},Vt=e=>e.map(t=>{let n=o=>`${+o[0].toFixed(2)} ${+o[1].toFixed(2)}`;return t.kind==="Z"?"Z":t.kind==="C"?`C${n(t.c1)} ${n(t.c2)} ${n(t.p)}`:`${t.kind}${n(t.p)}`}).join(" "),So=(e,t)=>{let n=([o,s])=>[t[0]*o+t[2]*s+t[4],t[1]*o+t[3]*s+t[5]];return e.map(o=>o.kind==="Z"?o:o.kind==="C"?{kind:"C",c1:n(o.c1),c2:n(o.c2),p:n(o.p)}:{kind:o.kind,p:n(o.p)})},zt=(e,t)=>{for(let n of t)n.kind==="M"?e.moveTo(...n.p):n.kind==="L"?e.lineTo(...n.p):n.kind==="C"?e.bezierCurveTo(...n.c1,...n.c2,...n.p):e.closePath()},as=(e,t,n,o,s)=>{let r=1-s;return[r*r*r*e[0]+3*r*r*s*t[0]+3*r*s*s*n[0]+s*s*s*o[0],r*r*r*e[1]+3*r*r*s*t[1]+3*r*s*s*n[1]+s*s*s*o[1]]},He=(e,t=.75)=>{let n=[],o=null,s=[0,0],r=[0,0];for(let a of e){if(a.kind==="M"){o={pts:[a.p],closed:!1},n.push(o),s=r=a.p;continue}if(o||(o={pts:[s],closed:!1},n.push(o)),a.kind==="L")o.pts.push(a.p),s=a.p;else if(a.kind==="C"){let i=Math.hypot(a.c1[0]-s[0],a.c1[1]-s[1])+Math.hypot(a.c2[0]-a.c1[0],a.c2[1]-a.c1[1])+Math.hypot(a.p[0]-a.c2[0],a.p[1]-a.c2[1]),c=Math.max(4,Math.min(200,Math.ceil(Math.sqrt(i/t)*2)));for(let l=1;l<=c;l++)o.pts.push(as(s,a.c1,a.c2,a.p,l/c));s=a.p}else o.closed=!0,s=r,o=null}return n.filter(a=>a.pts.length>1)},is=(e,t)=>{let n=0,o=t?e.length:e.length-1;for(let s=0;s<o;s++){let r=e[s],a=e[(s+1)%e.length];n+=Math.hypot(a[0]-r[0],a[1]-r[1])}return n},Co=(e,t,n)=>{let o=t?[...e,e[0]]:e,s=o.slice(1).map((l,u)=>Math.hypot(l[0]-o[u][0],l[1]-o[u][1])),r=s.reduce((l,u)=>l+u,0)||1,a=[],i=0,c=0;for(let l=0;l<n;l++){let u=(t?l/n:l/(n-1))*r;for(;i<s.length-1&&c+s[i]<u;)c+=s[i],i++;let d=s[i]?(u-c)/s[i]:0;a.push([o[i][0]+(o[i+1][0]-o[i][0])*d,o[i][1]+(o[i+1][1]-o[i][1])*d])}return a},$o=(e,t,n,o=0)=>{let s=e.reduce((u,d)=>u+is(d.pts,d.closed),0);if(!s)return[];let r=Math.min(t,n)+o,a=Math.max(t,n)+o,i=[],c=Math.floor(r);r-=c,a-=c,a<=1?i.push([r,a]):(i.push([r,1]),i.push([0,Math.min(1,a-1)]));let l=[];for(let[u,d]of i){let f=u*s,p=d*s,m=0;for(let h of e){let b=h.closed?[...h.pts,h.pts[0]]:h.pts,y=null;for(let v=0;v<b.length-1;v++){let k=b[v],w=b[v+1],L=Math.hypot(w[0]-k[0],w[1]-k[1]),C=m,S=m+L;if(m=S,S<f||C>p||!L){if(y&&C>p)break;continue}let _=x=>{let M=(x-C)/L;return[k[0]+(w[0]-k[0])*M,k[1]+(w[1]-k[1])*M]};y||(y=[_(Math.max(f,C))],l.push(y)),y.push(_(Math.min(p,S)))}}}return l},Lo=e=>e.reduce((t,n,o)=>{let s=e[(o+1)%e.length];return t+n[0]*s[1]-s[0]*n[1]},0)/2;var Eo=(e,t,n)=>{let o=He(e),s=He(t),r=Math.max(o.length,s.length),a=[];for(let i=0;i<r;i++){let c=o[i]??o[o.length-1],l=s[i]??s[s.length-1];if(!c||!l)continue;let u=c.closed||l.closed,d=Co(c.pts,u,160),f=Co(l.pts,u,160);if(u){Math.sign(Lo(d))!==Math.sign(Lo(f))&&(f=f.reverse());let p=0,m=1/0;for(let b=0;b<160;b++){let y=0;for(let v=0;v<160;v+=4){let k=f[(v+b)%160];y+=(d[v][0]-k[0])**2+(d[v][1]-k[1])**2}y<m&&(m=y,p=b)}let h=f;f=h.map((b,y)=>h[(y+p)%160])}d.forEach((p,m)=>a.push({kind:m?"L":"M",p:[p[0]+(f[m][0]-p[0])*n,p[1]+(f[m][1]-p[1])*n]})),u&&a.push({kind:"Z"})}return a},Rt=e=>{let t=He(e).flatMap(a=>a.pts);if(!t.length)return null;let n=t.map(a=>a[0]),o=t.map(a=>a[1]),s=Math.min(...n),r=Math.min(...o);return[s,r,Math.max(...n)-s,Math.max(...o)-r]},To=(e,t)=>{let n=He(e).flatMap(u=>u.pts);if(n.length<2)return{p:n[0]??[0,0],angle:0};let o=n.slice(1).map((u,d)=>Math.hypot(u[0]-n[d][0],u[1]-n[d][1])),s=o.reduce((u,d)=>u+d,0),r=Math.max(0,Math.min(1,t))*s,a=0;for(;a<o.length-1&&r>o[a];)r-=o[a],a++;let i=n[a],c=n[a+1],l=o[a]?r/o[a]:0;return{p:[i[0]+(c[0]-i[0])*l,i[1]+(c[1]-i[1])*l],angle:Math.atan2(c[1]-i[1],c[0]-i[0])*180/Math.PI}};var Ft=(e,t)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]],Mn=[1,0,0,1,0,0],cs=e=>{let t={tag:"#root",attrs:{},children:[],text:""},n=[t],o=/<!--[\s\S]*?-->|<!\[CDATA\[([\s\S]*?)\]\]>|<\?[\s\S]*?\?>|<!DOCTYPE[\s\S]*?>|<\/([\w:-]+)\s*>|<([\w:-]+)((?:\s+[\w:.-]+\s*=\s*(?:"[^"]*"|'[^']*'))*)\s*(\/?)>|([^<]+)/g,s;for(;s=o.exec(e);){let r=n[n.length-1];if(s[1]!==void 0)r.text+=s[1];else if(s[2])n.length>1&&n.pop();else if(s[3]){let a={};for(let c of s[4].matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))a[c[1]]=(c[2]??c[3]).replace(/"/g,'"').replace(/&/g,"&");let i={tag:s[3].replace(/^svg:/,""),attrs:a,children:[],text:""};r.children.push(i),s[5]||n.push(i)}else s[6]&&(r.text+=s[6])}return t},Io=e=>{if(!e)return Mn;let t=Mn;for(let[,n,o]of e.matchAll(/(\w+)\s*\(([^)]*)\)/g)){let s=o.split(/[\s,]+/).filter(Boolean).map(Number),r=Mn;if(n==="matrix")r=s;else if(n==="translate")r=[1,0,0,1,s[0]??0,s[1]??0];else if(n==="scale")r=[s[0],0,0,s[1]??s[0],0,0];else if(n==="rotate"){let a=(s[0]??0)*Math.PI/180,i=Math.cos(a),c=Math.sin(a);r=[i,c,-c,i,0,0],s.length>=3&&(r=Ft(Ft([1,0,0,1,s[1],s[2]],r),[1,0,0,1,-s[1],-s[2]]))}else n==="skewX"?r=[1,0,Math.tan((s[0]??0)*Math.PI/180),1,0,0]:n==="skewY"&&(r=[1,Math.tan((s[0]??0)*Math.PI/180),0,1,0,0]);t=Ft(t,r)}return t},R=(e,t=0)=>e===void 0||e===""?t:e.trim().endsWith("%")?parseFloat(e)/100:parseFloat(e),ls=e=>{let t=e.attrs;switch(e.tag){case"path":return t.d?ue(t.d):null;case"rect":{let n=R(t.x),o=R(t.y),s=R(t.width),r=R(t.height),a=R(t.rx,NaN),i=R(t.ry,NaN);return isNaN(a)&&(a=isNaN(i)?0:i),isNaN(i)&&(i=a),a=Math.min(a,s/2),i=Math.min(i,r/2),a?ue(`M${n+a} ${o}H${n+s-a}A${a} ${i} 0 0 1 ${n+s} ${o+i}V${o+r-i}A${a} ${i} 0 0 1 ${n+s-a} ${o+r}H${n+a}A${a} ${i} 0 0 1 ${n} ${o+r-i}V${o+i}A${a} ${i} 0 0 1 ${n+a} ${o}Z`):ue(`M${n} ${o}H${n+s}V${o+r}H${n}Z`)}case"circle":case"ellipse":{let n=R(t.cx),o=R(t.cy),s=e.tag==="circle"?R(t.r):R(t.rx),r=e.tag==="circle"?R(t.r):R(t.ry);return ue(`M${n} ${o-r}A${s} ${r} 0 1 1 ${n} ${o+r}A${s} ${r} 0 1 1 ${n} ${o-r}Z`)}case"line":return ue(`M${R(t.x1)} ${R(t.y1)}L${R(t.x2)} ${R(t.y2)}`);case"polyline":case"polygon":{let n=(t.points??"").trim().split(/[\s,]+/).map(Number);return n.length<4?null:ue(`M${n[0]} ${n[1]}${Array.from({length:n.length/2-1},(o,s)=>`L${n[2*s+2]} ${n[2*s+3]}`).join("")}${e.tag==="polygon"?"Z":""}`)}default:return null}},ps=["fill","stroke","stroke-width","opacity","fill-opacity","stroke-opacity","fill-rule","stroke-linecap","stroke-linejoin","display","visibility"],Oo=(e,t={})=>{let n=cs(e).children.find(C=>C.tag==="svg");if(!n)throw new Error("Not an SVG file");let o=(n.attrs.viewBox??"").split(/[\s,]+/).map(Number),s=o.length===4?o[2]:R(n.attrs.width,100),r=o.length===4?o[3]:R(n.attrs.height,100),a=o.length===4?o[0]:0,i=o.length===4?o[1]:0,c=t.width??600,l=c/s,u=[c,r*l],d=[l,0,0,l,-a*l-u[0]/2,-i*l-u[1]/2],f={},p={},m=C=>{if(C.tag==="style")for(let[,S,_]of C.text.matchAll(/([^{}]+)\{([^}]*)\}/g)){let x=Object.fromEntries(_.split(";").map(M=>M.split(":").map(P=>P.trim())).filter(M=>M.length===2&&M[0]));for(let M of S.split(",")){let P=M.trim().match(/^\.([\w-]+)$/);P&&(f[P[1]]={...f[P[1]],...x})}}(C.tag==="linearGradient"||C.tag==="radialGradient")&&C.attrs.id&&(p[C.attrs.id]=C),C.children.forEach(m)};m(n);let h=C=>{let S={};for(let _ of(C.attrs.class??"").split(/\s+/))Object.assign(S,f[_]??{});for(let _ of ps)C.attrs[_]!==void 0&&(S[_]=C.attrs[_]);for(let _ of(C.attrs.style??"").split(";")){let[x,M]=_.split(":").map(P=>P?.trim());x&&M&&(S[x]=M)}return S},b=(C,S,_,x)=>{if(!C||C==="none"||C==="transparent")return;C==="currentColor"&&(C=t.color??"#000000");let M=C.match(/url\(#([^)]+)\)/);if(M){let $=p[M[1]],I=($?.children??[]).filter(ae=>ae.tag==="stop").map(ae=>{let pe={...Object.fromEntries((ae.attrs.style??"").split(";").map(Ie=>Ie.split(":").map(et=>et.trim())).filter(Ie=>Ie.length===2)),...ae.attrs},Me=pe.offset?.endsWith("%")?parseFloat(pe.offset)/100:R(pe.offset),Te=ke(pe["stop-color"]??"#000")??[0,0,0,1];return[Me,Oe([Te[0],Te[1],Te[2],Te[3]*R(pe["stop-opacity"],1)*S])]});if(!$||!I.length)return;let N=$.attrs.gradientUnits==="userSpaceOnUse"?null:x,O=(ae,pe)=>N?[N[0]+ae*N[2],N[1]+pe*N[3]]:[ae,pe],V=Io($.attrs.gradientTransform),B=(ae,pe)=>{let[Me,Te]=O(ae,pe),Ie=V[0]*Me+V[2]*Te+V[4],et=V[1]*Me+V[3]*Te+V[5];return[_[0]*Ie+_[2]*et+_[4],_[1]*Ie+_[3]*et+_[5]]};if($.tag==="linearGradient")return{linear:{from:B(R($.attrs.x1),R($.attrs.y1)),to:B(R($.attrs.x2,1),R($.attrs.y2)),stops:I}};let ge=R($.attrs.r,.5)*(N?Math.max(N[2],N[3]):1)*Math.hypot(_[0],_[1])*Math.hypot(V[0],V[1]);return{radial:{center:B(R($.attrs.cx,.5),R($.attrs.cy,.5)),radius:ge,stops:I}}}let P=ke(C);return P&&(S<1||P[3]<1)?Oe([P[0],P[1],P[2],P[3]*S]):C},y=t.name??"svg",v=[],k=[],w=0,L=(C,S,_)=>{if(["defs","style","title","desc","metadata","clipPath","mask","symbol","linearGradient","radialGradient","pattern","filter"].includes(C.tag))return;let x=h(C),M={fill:x.fill??_.fill,stroke:x.stroke??_.stroke,strokeWidth:x["stroke-width"]!==void 0?parseFloat(x["stroke-width"]):_.strokeWidth,opacity:_.opacity*R(x.opacity,1),fillOpacity:x["fill-opacity"]!==void 0?R(x["fill-opacity"],1):_.fillOpacity,strokeOpacity:x["stroke-opacity"]!==void 0?R(x["stroke-opacity"],1):_.strokeOpacity,fillRule:x["fill-rule"]??_.fillRule,lineCap:x["stroke-linecap"]??_.lineCap,lineJoin:x["stroke-linejoin"]??_.lineJoin,display:x.display==="none"||x.visibility==="hidden"?"none":_.display};if(M.display==="none")return;let P=Ft(S,Io(C.attrs.transform)),$=ls(C);if($&&He($).length){let I=So($,P),N=Math.sqrt(Math.abs(P[0]*P[3]-P[1]*P[2])),O=Rt($),V=C.tag==="line"||C.tag==="polyline"?void 0:b(M.fill,M.opacity*M.fillOpacity,P,O),B=b(M.stroke,M.opacity*M.strokeOpacity,P,O);(V||B)&&k.push({type:"shape",name:C.attrs.id??`${y}-part-${++w}`,shape:"path",path:Vt(I),parent:"__group__",transform:{anchor:[0,0],position:[0,0]},...V?{fill:V}:{},...typeof B=="string"?{stroke:B,strokeWidth:+(M.strokeWidth*N).toFixed(2)}:{},...M.fillRule==="evenodd"?{fillRule:"evenodd"}:{},...M.lineCap?{lineCap:M.lineCap}:{},...M.lineJoin?{lineJoin:M.lineJoin}:{},...t.inPoint!==void 0?{inPoint:t.inPoint}:{}})}for(let I of C.children)L(I,P,M)};return L(n,d,{fill:"#000000",stroke:"none",strokeWidth:1,opacity:1,fillOpacity:1,strokeOpacity:1}),v.push({type:"null",name:y,transform:{position:t.position??[540,960]},...t.inPoint!==void 0?{inPoint:t.inPoint}:{}}),v.push(...k.reverse()),{layers:v,size:u,parts:k.length}};var de=class extends Error{};var U=(e,t)=>{let n=e.comps.find(o=>o.id===(t??e.root));if(!n)throw new de(`No composition "${t}". Comps: ${e.comps.map(o=>o.id).join(", ")}`);return n},te=(e,t)=>{for(let n of e.comps){let o=n.layers.findIndex(s=>s.id===t);if(o>=0)return{comp:n,layer:n.layers[o],index:o}}throw new de(`No layer "${t}"`)},No=e=>new Set(e.comps.flatMap(t=>t.layers.map(n=>n.id))),Dt=(e,t)=>{let n=No(e),o=t.replace(/[^a-zA-Z0-9_-]+/g,"-").replace(/^-|-$/g,"")||"layer";if(!n.has(o))return o;let s=2;for(;n.has(`${o}-${s}`);)s++;return`${o}-${s}`},Wt=(e,t)=>{if(e.comps.some(s=>s.id===t.id))throw new de(`Composition "${t.id}" already exists`);let n=U(e),o={width:n.width,height:n.height,fps:n.fps,duration:n.duration,layers:[],...t};return e.comps.push(o),o},Ao=(e,t,n)=>{Object.assign(U(e,t),n)},H=(e,t,n,o=0)=>{let s=U(e,t),r=n.id?No(e).has(n.id)?(()=>{throw new de(`Layer id "${n.id}" already used`)})():n.id:Dt(e,n.name??n.type),a={...n,id:r};return s.layers.splice(Math.max(0,Math.min(o,s.layers.length)),0,a),a},Pn=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),jo=(e,t)=>{for(let[n,o]of Object.entries(t))o===null?delete e[n]:Pn(o)&&Pn(e[n])&&!("keyframes"in o)?jo(e[n],o):e[n]=o;return e},fe=(e,t,n)=>{if("id"in n)throw new de("Cannot change a layer id; duplicate it instead");let{layer:o}=te(e,t);return jo(o,n),o},Ht=(e,t)=>{let{comp:n,index:o}=te(e,t);n.layers.splice(o,1);for(let s of e.comps)for(let r of s.layers)r.parent===t&&delete r.parent,r.matte?.layer===t&&delete r.matte},Ln=(e,t,n)=>{let{comp:o,index:s,layer:r}=te(e,t);o.layers.splice(s,1),o.layers.splice(Math.max(0,Math.min(n,o.layers.length)),0,r)},Cn=(e,t)=>{Array.isArray(e)?e.forEach(n=>Cn(n,t)):Pn(e)&&(Array.isArray(e.keyframes)&&t(e.keyframes),Object.values(e).forEach(n=>Cn(n,t)))},ut=(e,t,n)=>{let{layer:o}=te(e,t);(o.inPoint!==void 0||n)&&(o.inPoint=(o.inPoint??0)+n),o.outPoint!==void 0&&(o.outPoint+=n),Cn(o,s=>s.forEach(r=>r.t=+(r.t+n).toFixed(4)))},Bt=(e,t,n={})=>{let{comp:o,index:s,layer:r}=te(e,t),a=structuredClone(r);return a.id=n.newId??Dt(e,r.id),o.layers.splice(s,0,a),n.timeShift&&ut(e,a.id,n.timeShift),a},Vo=e=>e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t),Jt=(e,t)=>Vo(t).reduce((n,o)=>n?.[o],e),Sn=(e,t,n)=>{let o=Vo(t),s=e;o.slice(0,-1).forEach((r,a)=>{s[r]==null&&(s[r]=typeof o[a+1]=="number"?[]:{}),s=s[r]}),s[o[o.length-1]]=n},tt=.001,dt=(e,t,n,o)=>{let{layer:s}=te(e,t);Sn(s,n,o)},q=(e,t,n,o,s,r)=>{let{layer:a}=te(e,t),i=Jt(a,n),c;if(be(i))c=i.keyframes;else{c=[];let u=a.inPoint??0;i!==void 0&&Math.abs(u-o)>tt&&c.push({t:u,v:i}),Sn(a,n,{keyframes:c})}let l=c.find(u=>Math.abs(u.t-o)<tt);return l?(l.v=s,r!==void 0&&(l.ease=r)):c.push(r!==void 0?{t:o,v:s,ease:r}:{t:o,v:s}),c.sort((u,d)=>u.t-d.t),c},mt=(e,t,n,o)=>{let{layer:s}=te(e,t),r=Jt(s,n);if(!r||!be(r))throw new de(`${t}.${n} is not animated`);let a=r.keyframes.findIndex(i=>Math.abs(i.t-o)<tt);if(a<0)throw new de(`No keyframe at ${o}s on ${t}.${n}`);r.keyframes.splice(a,1),r.keyframes.length===1&&!r.wiggle&&Sn(s,n,r.keyframes[0].v)},zo=(e,t,n,o,s)=>{let{layer:r}=te(e,t),a=Jt(r,n),i=a?.keyframes?.find(l=>Math.abs(l.t-o)<tt);if(!a||!i)throw new de(`No keyframe at ${o}s on ${t}.${n}`);let c=Math.round(s*1e3)/1e3;if(a.keyframes.some(l=>l!==i&&Math.abs(l.t-c)<tt))throw new de(`There is already a keyframe at ${c}s`);i.t=c,a.keyframes.sort((l,u)=>l.t-u.t)},$n=(e,t,n,o,s)=>{let{layer:r}=te(e,t),i=Jt(r,n)?.keyframes?.find(c=>Math.abs(c.t-o)<tt);if(!i)throw new de(`No keyframe at ${o}s on ${t}.${n}`);i.ease=s},Ro=(e,t,n,o={})=>{let{layers:s,size:r,parts:a}=Oo(n,o),[i,...c]=s,l=H(e,t,i,0),u=c.reverse().map(d=>H(e,t,{...d,parent:l.id},1).id);return{group:l.id,parts:a,size:r,ids:u}};var Be={typewriter:{description:"Letters appear one by one with no motion.",animators:[{unit:"grapheme",stagger:.05,duration:.01,ease:"hold",from:{opacity:0}}]},fadeUp:{description:"Words fade in while rising slightly. Calm, readable default.",animators:[{unit:"word",stagger:.08,duration:.6,ease:"cubicOut",from:{opacity:0,y:40}}]},popIn:{description:"Words scale up from zero with an overshoot. Playful, energetic.",animators:[{unit:"word",stagger:.1,duration:.55,ease:"backOut",from:{opacity:0,scale:0}}]},slam:{description:"Words crash in from huge and blurred. Punchy kinetic typography.",animators:[{unit:"word",stagger:.18,duration:.35,ease:"expoOut",from:{opacity:0,scale:320,blur:14}}]},blurIn:{description:"Letters sharpen from a blur. Elegant, premium.",animators:[{unit:"grapheme",stagger:.03,duration:.7,ease:"cubicOut",from:{opacity:0,blur:18,x:-20}}]},maskedLines:{description:"Each line slides up from behind its own mask. The classic title reveal.",animators:[{unit:"line",stagger:.12,duration:.8,ease:"expoOut",clip:!0,from:{y:120}}]},cascade:{description:"Letters drop and rotate into place with an overshoot.",animators:[{unit:"grapheme",stagger:.035,duration:.7,ease:"backOut",from:{opacity:0,y:-70,rotation:-25}}]},trackingIn:{description:"Letter spacing collapses from wide to normal while fading in. Cinematic openers.",animators:[{unit:"grapheme",stagger:0,duration:1.4,ease:"expoOut",from:{opacity:0,tracking:60}}]},centerOut:{description:"Letters grow outward from the middle of the word.",animators:[{unit:"grapheme",order:"center",stagger:.04,duration:.5,ease:"backOut",from:{opacity:0,scale:0}}]},randomFlicker:{description:"Letters switch on in random order.",animators:[{unit:"grapheme",order:"random",stagger:.03,duration:.08,ease:"hold",from:{opacity:0}}]},colorSweep:{description:"A highlight colour sweeps through the letters, settling to the text colour.",animators:[{unit:"grapheme",stagger:.04,duration:.5,ease:"easeOut",from:{color:"#FFC93C",scale:115}}]},fadeOutDown:{description:"Exit: words fade out while dropping.",animators:[{unit:"word",mode:"out",stagger:.05,duration:.4,ease:"easeIn",from:{opacity:0,y:40}}]},blurOut:{description:"Exit: letters blur away.",animators:[{unit:"grapheme",mode:"out",stagger:.02,duration:.45,ease:"easeIn",from:{opacity:0,blur:16}}]},maskedLinesOut:{description:"Exit: lines slide up out of their masks.",animators:[{unit:"line",mode:"out",stagger:.08,duration:.5,ease:"expoInOut",clip:!0,from:{y:-120}}]}};var Je=["#E8692A","#FFC93C","#4DA3FF","#5FB3A0","#C78BC0","#E5534B","#9BD35A","#F28FB0"],Tn=e=>Math.round(e*1e3)/1e3,se=(...e)=>({keyframes:e.map(([t,n,o])=>o?{t:Tn(t),v:n,ease:o}:{t:Tn(t),v:n})}),X=(e,t)=>typeof e=="number"?e:t,me=(e,t)=>typeof e=="string"?e:t,Kt=e=>({prefix:e.prefix,suffix:e.suffix,decimals:e.decimals,locale:e.locale}),ft=(e,t,n,o)=>{let s=H(e,t,n,0),r=[s.id];return[...o].reverse().forEach(a=>r.push(H(e,t,{...a,parent:s.id},1).id)),r},En=e=>(e.data??[]).map(t=>typeof t=="number"?{value:t}:t),Fo={"chart.bar":{kind:"chart",description:"Bar chart: bars grow from the baseline one after another while their values count up; labels underneath.",params:"{data: [{label, value, color?}], position?: [x,y] (centre), size?: [w,h], start?: s, duration?: s, stagger?: s, color?, colors?: string[], max?, prefix?, suffix?, decimals?, locale? (en-IN), textColor?, showValues?: true, name?}",apply:(e,t,n)=>{let o=U(e,t),s=En(n),r=X(n.start,0),a=X(n.duration,.9),i=X(n.stagger,.12),[c,l]=n.size??[o.width*.8,o.height*.3],u=X(n.max,Math.max(...s.map(y=>y.value),1)),d=c/Math.max(1,s.length),f=d*.62,p=l/2,m=Math.round(Math.min(d*.32,o.width/22)),h=me(n.textColor,"#ffffff"),b=[{type:"shape",name:"axis",shape:"line",points:[[-c/2,p],[c/2,p]],stroke:h,strokeWidth:3,transform:{anchor:[0,0],position:[0,0],opacity:60},inPoint:r,trim:{end:se([r,0,"expoOut"],[r+.6,100])}}];return s.forEach((y,v)=>{let k=y.value/u*l,w=-c/2+d*(v+.5),L=r+.2+v*i,C=y.color??n.colors?.[v]??me(n.color,Je[v%Je.length]);b.push({type:"shape",name:`bar-${v+1}`,shape:"rect",size:[f,k],radius:Math.min(12,f/6),fill:C,inPoint:r,transform:{anchor:[0,k/2],position:[w,p],scale:se([L,[100,0],"expoOut"],[L+a,[100,100]])}}),n.showValues!==!1&&b.push({type:"text",name:`value-${v+1}`,text:"{value}",value:se([L,0,"expoOut"],[L+a,y.value]),format:Kt(n),size:m,weight:800,color:h,inPoint:r,transform:{position:[w,p-k-m*.8],opacity:se([L,0],[L+.25,100])}}),y.label&&b.push({type:"text",name:`label-${v+1}`,text:y.label,size:Math.round(m*.8),weight:600,color:h,inPoint:r,maxWidth:d*.95,transform:{position:[w,p+m*.95]},animators:[{unit:"line",delay:L-r,duration:.5,ease:"cubicOut",from:{opacity:0,y:20}}]})}),{created:ft(e,t,{type:"null",name:me(n.name,"bar-chart"),inPoint:r,transform:{position:n.position??[o.width/2,o.height/2]}},b)}}},"chart.line":{kind:"chart",description:"Line chart: a smooth line draws on across the points, dots pop in as it passes them, an area fill fades in underneath.",params:"{data: [{label?, value}] or numbers, position?, size?: [w,h], start?, duration?, color?, area?: true, showValues?: false, prefix?, suffix?, decimals?, locale?, textColor?, name?}",apply:(e,t,n)=>{let o=U(e,t),s=En(n),r=X(n.start,0),a=X(n.duration,1.6),i=me(n.color,Je[0]),c=me(n.textColor,"#ffffff"),[l,u]=n.size??[o.width*.8,o.height*.28],d=X(n.max,Math.max(...s.map(y=>y.value),1)),f=X(n.min,Math.min(0,...s.map(y=>y.value))),p=s.map((y,v)=>[-l/2+l*v/Math.max(1,s.length-1),u/2-(y.value-f)/(d-f||1)*u]),m=`M${p[0][0]} ${p[0][1]}`;for(let y=0;y<p.length-1;y++){let v=p[y-1]??p[y],k=p[y],w=p[y+1],L=p[y+2]??w;m+=` C${k[0]+(w[0]-v[0])/6} ${k[1]+(w[1]-v[1])/6} ${w[0]-(L[0]-k[0])/6} ${w[1]-(L[1]-k[1])/6} ${w[0]} ${w[1]}`}let h=Math.round(o.width/30),b=[];return p.forEach((y,v)=>{let k=r+a*v/Math.max(1,p.length-1);b.push({type:"shape",name:`dot-${v+1}`,shape:"ellipse",size:[22,22],fill:"#ffffff",stroke:i,strokeWidth:6,inPoint:r,transform:{position:y,scale:se([k-.05,[0,0],"backOut"],[k+.35,[100,100]])}}),n.showValues&&b.push({type:"text",name:`value-${v+1}`,text:"{value}",value:s[v].value,format:Kt(n),size:h,weight:800,color:c,inPoint:Tn(k),transform:{position:[y[0],y[1]-h*1.1]},animators:[{unit:"line",duration:.4,ease:"backOut",from:{opacity:0,scale:50}}]}),s[v].label&&b.push({type:"text",name:`label-${v+1}`,text:s[v].label,size:Math.round(h*.8),weight:600,color:c,inPoint:r,transform:{position:[y[0],u/2+h*1.2],opacity:se([k-.1,0],[k+.2,70])}})}),b.push({type:"shape",name:"line",shape:"path",path:m,stroke:i,strokeWidth:8,transform:{anchor:[0,0],position:[0,0]},inPoint:r,trim:{end:se([r,0,"easyEase"],[r+a,100])}}),n.area!==!1&&b.push({type:"shape",name:"area",shape:"path",path:`${m} L${p[p.length-1][0]} ${u/2} L${p[0][0]} ${u/2} Z`,inPoint:r,fill:{linear:{from:[0,-u/2],to:[0,u/2],stops:[[0,`${i}88`],[1,`${i}00`]]}},transform:{anchor:[0,0],position:[0,0]},masks:[{shape:"rect",rect:se([r,[-l/2-10,-u,0,u*2],"easyEase"],[r+a,[-l/2-10,-u,l+20,u*2]])}]}),b.push({type:"shape",name:"axis",shape:"line",points:[[-l/2,u/2],[l/2,u/2]],stroke:c,strokeWidth:3,inPoint:r,transform:{anchor:[0,0],position:[0,0],opacity:50},trim:{end:se([r,0,"expoOut"],[r+.6,100])}}),{created:ft(e,t,{type:"null",name:me(n.name,"line-chart"),inPoint:r,transform:{position:n.position??[o.width/2,o.height/2]}},b)}}},"chart.donut":{kind:"chart",description:"Donut / pie chart: segments sweep round one after another; the centre shows the total (or a title) and a legend lists each part.",params:'{data: [{label, value, color?}], position?, diameter?, thickness? (diameter/2 = pie), start?, duration?, stagger?, centerText?: string | "total", prefix?, suffix?, decimals?, locale?, legend?: true, textColor?, name?}',apply:(e,t,n)=>{let o=U(e,t),s=En(n),r=X(n.start,0),a=X(n.duration,.8),i=X(n.stagger,.25),c=me(n.textColor,"#ffffff"),l=X(n.diameter,o.width*.55),u=Math.min(X(n.thickness,l*.18),l/2),d=s.reduce((h,b)=>h+b.value,0)||1,f=[],p=0;s.forEach((h,b)=>{let y=p/d*100,v=(p+h.value)/d*100,k=r+b*i;p+=h.value,f.push({type:"shape",name:`segment-${b+1}`,shape:"ellipse",size:[l-u,l-u],stroke:h.color??Je[b%Je.length],strokeWidth:u,lineCap:"butt",inPoint:r,trim:{start:y,end:se([k,y,"cubicOut"],[k+a,v])},transform:{position:[0,0]}})});let m=n.centerText??"total";if(m&&u<l/2&&f.unshift(m==="total"?{type:"text",name:"total",text:"{value}",value:se([r,0,"expoOut"],[r+i*s.length+a,d]),format:Kt(n),size:Math.round(l*.16),weight:800,color:c,inPoint:r,transform:{position:[0,0]}}:{type:"text",name:"center",text:String(m),size:Math.round(l*.12),weight:800,color:c,inPoint:r,maxWidth:l-u*2.2,transform:{position:[0,0]},animators:[{unit:"word",stagger:.08,duration:.5,ease:"backOut",from:{opacity:0,scale:60}}]}),n.legend!==!1){let h=Math.round(o.width/30),b=h*1.6;s.forEach((y,v)=>{let k=l/2+h*2+v*b,w=r+v*i;f.push({type:"shape",name:`legend-dot-${v+1}`,shape:"ellipse",size:[h*.7,h*.7],fill:y.color??Je[v%Je.length],inPoint:r,transform:{position:[-l*.42,k],opacity:se([w,0],[w+.3,100])}}),f.push({type:"text",name:`legend-${v+1}`,text:`${y.label??`Part ${v+1}`} \xB7 ${Math.round(y.value/d*100)}%`,size:h,weight:600,align:"left",color:c,inPoint:r,transform:{position:[-l*.42+h,k]},animators:[{unit:"line",delay:w-r,duration:.5,ease:"cubicOut",from:{opacity:0,x:-30}}]})})}return{created:ft(e,t,{type:"null",name:me(n.name,"donut-chart"),inPoint:r,transform:{position:n.position??[o.width/2,o.height*.42]}},f)}}},"chart.progress":{kind:"chart",description:"Progress ring (or bar) that fills to a percentage while the number counts up in the middle.",params:'{value: 0-100, style?: "ring"|"bar", label?, position?, diameter? (ring) | size?: [w,h] (bar), thickness?, start?, duration?, color?, trackColor?, textColor?, name?}',apply:(e,t,n)=>{let o=U(e,t),s=X(n.value,75),r=X(n.start,0),a=X(n.duration,1.4),i=me(n.color,Je[0]),c=me(n.trackColor,"#ffffff22"),l=me(n.textColor,"#ffffff"),u=[];if(n.style==="bar"){let[d,f]=n.size??[o.width*.75,36];u.push({type:"text",name:"percent",text:"{value}",value:se([r,0,"expoOut"],[r+a,s]),format:{suffix:"%"},size:Math.round(f*1.6),weight:800,align:"right",color:l,inPoint:r,transform:{position:[d/2,-f*1.6]}}),n.label&&u.push({type:"text",name:"label",text:String(n.label),size:Math.round(f*1.1),weight:600,align:"left",color:l,inPoint:r,transform:{position:[-d/2,-f*1.6]}}),u.push({type:"shape",name:"fill",shape:"rect",size:[d,f],radius:f/2,fill:i,inPoint:r,transform:{anchor:[-d/2,0],position:[-d/2,0],scale:se([r,[0,100],"expoOut"],[r+a,[s,100]])}}),u.push({type:"shape",name:"track",shape:"rect",size:[d,f],radius:f/2,fill:c,inPoint:r,transform:{position:[0,0]}})}else{let d=X(n.diameter,o.width*.5),f=X(n.thickness,d*.09);u.push({type:"text",name:"percent",text:"{value}",value:se([r,0,"expoOut"],[r+a,s]),format:{suffix:"%"},size:Math.round(d*.24),weight:800,color:l,inPoint:r,transform:{position:[0,n.label?-d*.05:0]}}),n.label&&u.push({type:"text",name:"label",text:String(n.label),size:Math.round(d*.08),weight:600,color:l,inPoint:r,maxWidth:d*.7,transform:{position:[0,d*.15]}}),u.push({type:"shape",name:"ring",shape:"ellipse",size:[d,d],stroke:i,strokeWidth:f,inPoint:r,trim:{end:se([r,0,"expoOut"],[r+a,s])},transform:{position:[0,0]}}),u.push({type:"shape",name:"track",shape:"ellipse",size:[d,d],stroke:c,strokeWidth:f,inPoint:r,transform:{position:[0,0]}})}return{created:ft(e,t,{type:"null",name:me(n.name,"progress"),inPoint:r,transform:{position:n.position??[o.width/2,o.height/2]}},u)}}},"element.counter":{kind:"element",description:"A big number that counts up (\u20B94,999 \xB7 10,000+ customers \xB7 98%), with an optional caption under it.",params:"{to: number, from?: 0, start?, duration?, prefix?, suffix?, decimals?, locale? (en-IN groups as 1,00,000), label?, size?, color?, labelColor?, position?, name?}",apply:(e,t,n)=>{let o=U(e,t),s=X(n.start,0),r=X(n.duration,1.5),a=X(n.size,Math.round(o.width/6)),i=[{type:"text",name:"number",text:"{value}",value:se([s,X(n.from,0),"expoOut"],[s+r,X(n.to,100)]),format:Kt(n),size:a,weight:800,color:me(n.color,"#ffffff"),inPoint:s,transform:{position:[0,0],scale:se([s,[70,70],"backOut"],[s+.5,[100,100]])},animators:[{unit:"line",duration:.3,from:{opacity:0}}]}];return n.label&&i.push({type:"text",name:"caption",text:String(n.label),size:Math.round(a*.32),weight:600,color:me(n.labelColor,"#ffffffcc"),inPoint:s,maxWidth:o.width*.8,transform:{position:[0,a*.85]},animators:[{unit:"word",delay:.3,stagger:.06,duration:.5,ease:"cubicOut",from:{opacity:0,y:24}}]}),{created:ft(e,t,{type:"null",name:me(n.name,"counter"),inPoint:s,transform:{position:n.position??[o.width/2,o.height/2]}},i)}}}};var ot=e=>Math.round(e*1e3)/1e3,Ke=(...e)=>({keyframes:e.map(([t,n,o])=>o?{t:ot(t),v:n,ease:o}:{t:ot(t),v:n})}),nt=(e,t)=>typeof e=="number"?e:t,Ce=(e,t)=>typeof e=="string"?e:t,us="M0 0 L0 34 L9 26 L15 40 L21 37 L15 24 L27 24 Z",ds="M14 0 C18 0 20 3 20 7 L20 24 C22 22 27 22 29 25 C31 23 36 24 37 28 C39 27 44 28 44 33 L44 48 C44 58 37 66 27 66 L22 66 C16 66 12 63 9 58 L1 44 C-1 40 2 36 6 38 L8 40 L8 7 C8 3 10 0 14 0 Z",Do={"element.phoneMockup":{kind:"element",description:"Phone mockup around a screenshot or screen recording (image or video), tilted in 3D and settling flat \u2014 for app and website promos.",params:"{src: image or video path (the screen), position?: [x,y], height?: px (default 70% of comp), start?, duration?: s (tilt-in), from?: [rotateX, rotateY] (default [18,-28]), to?: [rx, ry] (default [0,0]), body?: colour, trimIn?, speed?, name?}",apply:(e,t,n)=>{let o=U(e,t),s=Math.round(nt(n.height,o.height*.7)),r=Math.round(s*.49),a=Math.round(r*.045),i=Math.round(r*.16),c=r-a*2,l=s-a*2,u=nt(n.start,0),d=nt(n.duration,1.4),f=Dt(e,Ce(n.name,"phone")),p=Ce(n.src,""),m=/\.(mp4|mov|webm|m4v)$/i.test(p);Wt(e,{id:f,name:f,width:r,height:s,duration:o.duration,fps:o.fps});let h=[{type:"shape",name:"sheen",shape:"rect",size:[c,l],radius:i-a,transform:{position:[r/2,s/2],opacity:35},blendMode:"screen",fill:{linear:{from:[-c/2,-l/2],to:[c/2,l/2],stops:[[0,"#ffffff55"],[.35,"#ffffff00"],[1,"#ffffff00"]]}}},{type:"shape",name:"notch",shape:"rect",size:[Math.round(r*.28),Math.round(r*.075)],radius:Math.round(r*.04),fill:"#0b0b0d",transform:{position:[r/2,a+Math.round(r*.06)]}},{type:m?"video":"image",name:"screen",src:p,size:[c,l],fit:"cover",transform:{position:[r/2,s/2]},masks:[{shape:"rect",rect:[0,0,c,l],radius:i-a}],...m?{trimIn:nt(n.trimIn,0),speed:nt(n.speed,1)}:{}},{type:"shape",name:"body",shape:"rect",size:[r,s],radius:i,fill:Ce(n.body,"#16171b"),stroke:"#3a3d44",strokeWidth:Math.max(2,Math.round(r*.006)),transform:{position:[r/2,s/2]}}];for(let L of[...h].reverse())H(e,f,L,0);let[b,y]=n.from??[18,-28],[v,k]=n.to??[0,0];return{created:[H(e,t,{type:"precomp",name:f,comp:f,inPoint:u,transform:{position:n.position??[o.width/2,o.height/2]},effects:[{type:"tilt",rotateX:Ke([u,b,"expoOut"],[u+d,v]),rotateY:Ke([u,y,"expoOut"],[u+d,k]),perspective:s*2.2},{type:"dropShadow",blur:60,distance:30,angle:160,opacity:55}]},0).id],note:`Phone comp "${f}" (${r}\xD7${s}); its "screen" layer holds ${p||"your image/video"} \u2014 open the comp to adjust`}}},"element.cursor":{kind:"element",description:"Mouse pointer or finger that glides between points and taps, with a ripple on each tap \u2014 for app, website and UI demos.",params:'{points: [{t: s, x, y, tap?: boolean}], style?: "pointer"|"finger"|"dot", size?: px, color?, rippleColor?, name?}',apply:(e,t,n)=>{let o=U(e,t),s=(n.points??[]).sort((m,h)=>m.t-h.t);if(!s.length)throw new Error("cursor needs points: [{t, x, y, tap?}]");let r=Ce(n.style,"pointer"),a=nt(n.size,Math.round(o.width/10)),i=[],c={keyframes:s.map((m,h)=>({t:ot(m.t),v:[m.x,m.y],...h<s.length-1?{ease:"easyEase"}:{}}))},l=[];for(let m of s.filter(h=>h.tap))l.push([m.t,[100,100],"easeIn"],[m.t+.08,[82,82],"backOut"],[m.t+.28,[100,100]]);let u=Math.max(0,s[0].t-.3),d={inPoint:ot(u),effects:[{type:"dropShadow",blur:10,distance:4,opacity:45}]},f;if(r==="dot")f={type:"shape",name:Ce(n.name,"cursor"),shape:"ellipse",size:[a*.6,a*.6],fill:Ce(n.color,"#ffffffdd"),stroke:"#00000055",strokeWidth:2,transform:{position:c,...l.length?{scale:Ke(...l)}:{},opacity:Ke([u,0],[u+.25,100])},...d};else{let m=r==="finger"?ds:us,h=r==="finger"?a/66:a/40;f={type:"shape",name:Ce(n.name,"cursor"),shape:"path",path:m,fill:Ce(n.color,"#ffffff"),stroke:"#111111",strokeWidth:2.2,lineJoin:"round",transform:{anchor:r==="finger"?[14,2]:[1,1],position:c,scale:l.length?Ke(...l.map(([b,y,v])=>[b,[y[0]*h,y[1]*h],v])):[h*100,h*100],opacity:Ke([u,0],[u+.25,100])},...d},l.length||(f.transform.scale=[h*100,h*100])}let p=H(e,t,f,0);return i.push(p.id),s.filter(m=>m.tap).forEach((m,h)=>{let b=H(e,t,{type:"shape",name:`tap-${h+1}`,shape:"ellipse",size:[a*1.6,a*1.6],stroke:Ce(n.rippleColor,"#ffffff"),strokeWidth:4,fill:`${Ce(n.rippleColor,"#ffffff")}33`,inPoint:ot(m.t),outPoint:ot(m.t+.6),transform:{position:[m.x,m.y],scale:Ke([m.t,[10,10],"cubicOut"],[m.t+.55,[100,100]]),opacity:Ke([m.t,90],[m.t+.55,0])}},1);i.push(b.id)}),{created:i}}}};var Wo=e=>{let t=e.trim().replace(",",".").match(/(?:(\d+):)?(\d+):(\d+(?:\.\d+)?)/);return t?(t[1]?Number(t[1])*3600:0)+Number(t[2])*60+Number(t[3]):NaN},Ho=e=>{let t=[];for(let n of e.replace(/\r/g,"").split(/\n\s*\n/)){let o=n.split(`
|
|
2
|
+
`).map(c=>c.trim()).filter(Boolean),s=o.findIndex(c=>c.includes("-->"));if(s<0)continue;let[r,a]=o[s].split("-->"),i=o.slice(s+1).join(" ").replace(/<[^>]+>/g,"").trim();i&&t.push({start:Wo(r),end:Wo(a.split(/\s+/).filter(Boolean)[0]??a),text:i})}return t.filter(n=>Number.isFinite(n.start)&&Number.isFinite(n.end))},Bo=e=>e.flatMap(t=>{let n=t.text.split(/\s+/).filter(Boolean),o=n.map(a=>Math.max(1,[...a].length)+1),s=o.reduce((a,i)=>a+i,0),r=t.start;return n.map((a,i)=>{let c=(t.end-t.start)*o[i]/s,l={text:a,start:+r.toFixed(3),end:+(r+c).toFixed(3)};return r+=c,l})}),Jo=(e,t=4,n=22)=>{let o=[],s=[],r=a=>a.reduce((i,c)=>i+[...c.text].length+1,0);for(let a of e){let i=s.length&&a.start-s[s.length-1].end>.6;s.length&&(s.length>=t||r([...s,a])>n||i)&&(o.push(s),s=[]),s.push(a),/[.!?।,;:]$/.test(a.text)&&s.length>=2&&(o.push(s),s=[])}return s.length&&o.push(s),o};var Ut=(e,t)=>typeof e=="number"?e:t,rt=(e,t)=>typeof e=="string"?e:t,Gt=e=>Math.round(e*1e3)/1e3,Ko={"captions.add":{kind:"captions",description:"Captions with the current word highlighted (Reels/Shorts style), from word timings, cues or SRT/VTT text. Pages of a few words appear in sync; every page is an editable text layer.",params:'{words?: [{text, start, end}], cues?: [{start, end, text}], srt?: string (SRT or VTT text), offset?: s, maxWords?: 4, maxChars?: 22, position?: [x,y] (default lower third), size?, color?, highlight?: colour, mode?: "current"|"spoken", box?: highlight plate colour, plate?: colour behind the whole line, uppercase?: boolean, style?: "pop"|"fade"|"none", font?, name?}',apply:(e,t,n)=>{let o=U(e,t),s=n.words??[];if(!s.length){let d=n.cues??(typeof n.srt=="string"?Ho(n.srt):[]);s=Bo(d)}if(!s.length)throw new Error("No captions: pass words, cues or srt");let r=Ut(n.offset,0),a=Jo(s.map(d=>({...d,start:d.start+r,end:d.end+r})),Ut(n.maxWords,4),Ut(n.maxChars,22)),i=n.position??[o.width/2,o.height*.72],c=Ut(n.size,Math.round(o.width/13)),l=rt(n.style,"pop"),u=[];return a.forEach((d,f)=>{let p=d[0].start,m=a[f+1]?.[0].start,h=Math.min(m??1/0,d[d.length-1].end+.35),b=d.map(v=>n.uppercase?v.text.toUpperCase():v.text).join(" "),y=H(e,o.id,{type:"text",name:`${rt(n.name,"caption")}-${f+1}`,text:b,size:c,weight:800,color:rt(n.color,"#ffffff"),font:n.font,inPoint:Gt(p),outPoint:Gt(Math.max(h,p+.3)),maxWidth:o.width*.86,transform:{position:i},stroke:{color:"#000000",width:Math.max(4,Math.round(c*.1))},...n.plate?{box:{color:rt(n.plate,"#000000aa"),padding:[Math.round(c*.35),Math.round(c*.18)],radius:Math.round(c*.25)}}:{},karaoke:{words:d.map(v=>[Gt(v.start),Gt(v.end)]),color:rt(n.highlight,"#FFC93C"),mode:n.mode==="spoken"?"spoken":"current",...n.box?{box:rt(n.box,"#E8692A")}:{}},animators:l==="none"?[]:l==="fade"?[{unit:"line",duration:.18,ease:"easeOut",from:{opacity:0}}]:[{unit:"word",stagger:.04,duration:.22,ease:"backOut",from:{opacity:0,scale:70}}]},0);u.push(y.id)}),{created:u,note:`${a.length} caption pages from ${s.length} words`}}}};var ht=([e,t],n=0)=>{let o=256*2**n,s=Math.sin(Math.max(-85.05,Math.min(85.05,e))*Math.PI/180);return[(t+180)/360*o,(.5-Math.log((1+s)/(1-s))/(4*Math.PI))*o]},Uo=([e,t],n=0)=>{let o=256*2**n,s=e/o*360-180,r=Math.PI-2*Math.PI*t/o;return[180/Math.PI*Math.atan(.5*(Math.exp(r)-Math.exp(-r))),s]},Go=(e,t,n,o=.12)=>{let s=e.map(m=>ht(m,0)),r=Math.min(...s.map(m=>m[0])),a=Math.max(...s.map(m=>m[0])),i=Math.min(...s.map(m=>m[1])),c=Math.max(...s.map(m=>m[1])),l=(r+a)/2,u=(i+c)/2,d=Math.max(a-r,1e-6)/(1-2*o),f=Math.max(c-i,1e-6)/(1-2*o);return d/f>t/n?f=d*n/t:d=f*t/n,r=l-d/2,a=l+d/2,i=u-f/2,c=u+f/2,{toPx:m=>{let[h,b]=ht(m,0);return[(h-r)/(a-r)*t,(b-i)/(c-i)*n]},view:{bounds:[Uo([r,i]),Uo([a,c])],size:[t,n]}}},qo=e=>{let[t,n]=[ht(e.bounds[0],0),ht(e.bounds[1],0)];return o=>{let[s,r]=ht(o,0);return[(s-t[0])/(n[0]-t[0])*e.size[0],(r-t[1])/(n[1]-t[1])*e.size[1]]}},Xo=(e,t)=>{let o=(t[0]-e[0])*Math.PI/180,s=(t[1]-e[1])*Math.PI/180,r=Math.sin(o/2)**2+Math.cos(e[0]*Math.PI/180)*Math.cos(t[0]*Math.PI/180)*Math.sin(s/2)**2;return 12742*Math.asin(Math.sqrt(r))};var In=(e,t)=>typeof e=="number"?e:t,gt=(e,t)=>typeof e=="string"?e:t,st=e=>Math.round(e*1e3)/1e3,qt=(...e)=>({keyframes:e.map(([t,n,o])=>o?{t:st(t),v:n,ease:o}:{t:st(t),v:n})}),ms="M0 0 C-6 -10 -18 -16 -18 -28 C-18 -38 -10 -46 0 -46 C10 -46 18 -38 18 -28 C18 -16 6 -10 0 0 Z",Zo={"map.route":{kind:"map",description:"Animated map route from real coordinates: the path draws on, a marker travels along it, start/end pins drop in with labels. Optional real map background (see `dtly map-tiles`).",params:'{route: [[lat, lon], ...], labels?: string[] (one per point, "" to skip), start?, duration?, color?, width?, dashed?: boolean, smooth?: true, marker?: "dot"|"pin"|"none", background?: {src, bounds: [[latNW, lonNW], [latSE, lonSE]]}, size?: [w,h], position?, pinColor?, labelColor?, showDistance?: boolean, name?}',apply:(e,t,n)=>{let o=U(e,t),s=n.route??[];if(s.length<2)throw new Error("map.route needs at least two [lat, lon] points");let r=n.background,[a,i]=n.size??[o.width,o.height],c=r?qo({bounds:r.bounds,size:[a,i]}):Go(s,a,i).toPx,l=s.map(L=>{let[C,S]=c(L);return[C-a/2,S-i/2]}),u=In(n.start,0),d=In(n.duration,3),f=gt(n.color,"#E8692A"),p=In(n.width,Math.round(o.width/90)),m=`M${l[0][0]} ${l[0][1]}`;if(n.smooth!==!1&&l.length>2)for(let L=0;L<l.length-1;L++){let C=l[L-1]??l[L],S=l[L],_=l[L+1],x=l[L+2]??_;m+=` C${S[0]+(_[0]-C[0])/6} ${S[1]+(_[1]-C[1])/6} ${_[0]-(x[0]-S[0])/6} ${_[1]-(x[1]-S[1])/6} ${_[0]} ${_[1]}`}else for(let L of l.slice(1))m+=` L${L[0]} ${L[1]}`;let h=[],b=H(e,t,{type:"null",name:gt(n.name,"route"),inPoint:u,transform:{position:n.position??[o.width/2,o.height/2]}},0);h.push(b.id);let y=U(e,t).layers.indexOf(b),v=L=>h.push(H(e,t,{...L,parent:b.id},y+h.length).id),k=n.labels??[],w=Math.round(o.width/26);if(l.forEach((L,C)=>{if(!(C===0||C===l.length-1)&&!k[C])return;let _=u+(C===0?0:d*C/(l.length-1));k[C]&&v({type:"text",name:`label-${C+1}`,text:k[C],size:w,weight:800,color:gt(n.labelColor,"#ffffff"),inPoint:st(_),box:{color:"#000000aa",padding:[Math.round(w*.45),Math.round(w*.2)],radius:Math.round(w*.3)},transform:{position:[L[0],L[1]-w*2.6]},animators:[{unit:"line",duration:.4,ease:"backOut",from:{opacity:0,y:30,scale:80}}]}),v({type:"shape",name:`pin-${C+1}`,shape:"path",path:ms,fill:C===l.length-1?gt(n.pinColor,f):"#ffffff",stroke:"#00000066",strokeWidth:2,inPoint:st(_),transform:{anchor:[0,0],position:L,scale:qt([_,[0,0],"backOut"],[_+.45,[100*w/30,100*w/30]])},effects:[{type:"dropShadow",blur:8,distance:4,opacity:40}]})}),n.marker!=="none"){let L=ue(m),C=40,S=Array.from({length:C+1},(_,x)=>({t:st(u+d*x/C),v:To(L,x/C).p}));v({type:"shape",name:"marker",shape:"ellipse",size:[p*2.6,p*2.6],fill:"#ffffff",stroke:f,strokeWidth:p*.6,inPoint:u,outPoint:st(u+d+.2),transform:{position:{keyframes:S}},effects:[{type:"glow",color:f,radius:18,strength:70}]})}if(v({type:"shape",name:"route-line",shape:"path",path:m,stroke:f,strokeWidth:p,...n.dashed?{dash:[p*2,p*1.6],lineCap:"butt"}:{},inPoint:u,transform:{anchor:[0,0],position:[0,0]},trim:{end:qt([u,0,"linear"],[u+d,100])}}),v({type:"shape",name:"route-casing",shape:"path",path:m,stroke:"#00000055",strokeWidth:p*1.9,inPoint:u,transform:{anchor:[0,0],position:[0,0]},trim:{end:qt([u,0,"linear"],[u+d,100])}}),n.showDistance){let L=s.slice(1).reduce((C,S,_)=>C+Xo(s[_],S),0);v({type:"text",name:"distance",text:"{value}",value:qt([u,0],[u+d,Math.round(L)]),format:{suffix:" km"},size:Math.round(w*1.4),weight:800,color:gt(n.labelColor,"#ffffff"),inPoint:u,box:{color:"#000000aa",padding:[w*.5,w*.25],radius:w*.3},transform:{position:[0,i/2-w*4]}})}return r&&v({type:"image",name:"map",src:r.src,size:[a,i],fit:"fill",inPoint:u,transform:{position:[0,0],anchor:[a/2,i/2]}}),{created:h,note:r?"Route drawn over the map image":"No background: add a map image (dtly map-tiles) or a solid underneath"}}}};var J=(e,t)=>typeof e=="number"?e:t,G=(e,t)=>typeof e=="string"?e:t,ye=e=>Math.round(e*1e3)/1e3,Z=(...e)=>({keyframes:e.map(([t,n,o])=>o?{t:ye(t),v:n,ease:o}:{t:ye(t),v:n})}),ne={};for(let[e,t]of Object.entries(Be))ne[`text.${e}`]={kind:"text",description:t.description,params:"{layer: textLayerId, delay?: s, stagger?: s, duration?: s, replace?: boolean}",apply:(n,o,s)=>{let{layer:r}=te(n,G(s.layer,""));if(r.type!=="text")throw new de(`${r.id} is not a text layer`);let a=t.animators.map(i=>({...i,...s.delay!==void 0&&{delay:J(s.delay,0)},...s.stagger!==void 0&&{stagger:J(s.stagger,0)},...s.duration!==void 0&&{duration:J(s.duration,.5)}}));return r.animators=s.replace===!1?[...r.animators??[],...a]:[...(r.animators??[]).filter(i=>i.mode==="out"!=(a[0].mode==="out")),...a],{created:[],note:`Applied ${e} to ${r.id}`}}};ne["kinetic.sequence"]={kind:"kinetic",description:"Classic kinetic typography: phrases appear one after another in the same spot, each with its own entrance, emphasis words bigger and coloured.",params:'{phrases: string[], start?: s, each?: s (default by length), position?: [x,y], size?: px, color?, accent?: color, emphasis?: string[] (words to highlight), style?: "slam"|"popIn"|"fadeUp"|"blurIn"|"cascade", font?, maxWidth?, holdLast?: boolean (default true: last phrase stays to the end of the comp)}',apply:(e,t,n)=>{let o=U(e,t),s=n.phrases??[],r=n.position??[o.width/2,o.height/2],a=J(n.size,Math.round(o.width/9)),i=G(n.style,"slam"),c=new Set((n.emphasis??[]).map(f=>f.toLowerCase())),l=J(n.start,0),u=[],d=n.holdLast!==!1;return s.forEach((f,p)=>{let m=f.split(/\s+/).length,h=J(n.each,Math.max(.7,.35+m*.32)),b=d&&p===s.length-1,y=b?Math.max(o.duration,l+h):l+h,v=f.split(/\s+/).some(w=>c.has(w.toLowerCase())),k=H(e,o.id,{type:"text",name:`kinetic-${p+1}`,text:f,inPoint:ye(l),outPoint:ye(y),size:v?Math.round(a*1.35):a,weight:800,font:n.font,color:v?G(n.accent,"#FFC93C"):G(n.color,"#ffffff"),maxWidth:J(n.maxWidth,o.width*.86),transform:{position:r,scale:Z([l,[100,100]],[y,[100+8*((y-l)/h),100+8*((y-l)/h)]])},animators:[...Be[i in Be?i:"slam"].animators,...b?[]:[{unit:"word",mode:"out",stagger:.03,duration:.18,ease:"easeIn",from:{opacity:0,scale:80}}]]});u.push(k.id),l=ye(l+h)}),{created:u,note:`Sequence ends at ${l.toFixed(2)}s`}}};ne["opener.logoReveal"]={kind:"opener",description:"Brand opener: a ring draws on and bursts, the title tracks in, an accent line draws, and a tagline reveals from a mask.",params:"{title: string, tagline?: string, start?: s, color?: brand colour, accent?: colour, textColor?, position?: [x,y], size?: px, font?}",apply:(e,t,n)=>{let o=U(e,t),s=J(n.start,0),[r,a]=n.position??[o.width/2,o.height/2],i=G(n.color,"#E8692A"),c=G(n.accent,"#FFC93C"),l=J(n.size,Math.round(o.width/7.5)),u=Math.min(o.width,o.height)*.42,d=[],f=p=>d.push(H(e,o.id,p).id);return f({type:"shape",name:"reveal-ring",shape:"ellipse",size:[u,u],stroke:i,strokeWidth:10,inPoint:s,outPoint:s+1.6,motionBlur:{samples:8},transform:{position:[r,a],rotation:Z([s,-120,"expoOut"],[s+1,0]),scale:Z([s+.7,[100,100],"expoOut"],[s+1.4,[260,260]]),opacity:Z([s+.9,100],[s+1.4,0])},trim:{end:Z([s,0,"expoOut"],[s+.8,100])}}),f({type:"shape",name:"reveal-burst",shape:"ellipse",size:[u*.9,u*.9],fill:i,inPoint:s+.7,outPoint:s+1.5,transform:{position:[r,a],scale:Z([s+.7,[0,0],"expoOut"],[s+1.2,[220,220]]),opacity:Z([s+.9,90],[s+1.5,0])}}),f({type:"text",name:"opener-title",text:G(n.title,"TITLE"),size:l,weight:800,color:G(n.textColor,"#ffffff"),font:n.font,inPoint:s+.8,maxWidth:o.width*.88,transform:{position:[r,a]},animators:[{unit:"grapheme",stagger:.025,duration:1.1,ease:"expoOut",from:{opacity:0,tracking:40,blur:10}}],effects:[{type:"dropShadow",blur:30,distance:0,opacity:50}]}),f({type:"shape",name:"opener-line",shape:"line",points:[[-o.width*.3,0],[o.width*.3,0]],stroke:c,strokeWidth:8,inPoint:s+1.2,transform:{position:[r,a+l*.85]},trim:{start:Z([s+1.2,50,"expoOut"],[s+1.9,0]),end:Z([s+1.2,50,"expoOut"],[s+1.9,100])}}),n.tagline&&f({type:"text",name:"opener-tagline",text:G(n.tagline,""),size:Math.round(l*.42),weight:600,color:c,font:n.font,inPoint:s+1.5,transform:{position:[r,a+l*1.4]},animators:[{unit:"line",clip:!0,stagger:.1,duration:.8,ease:"expoOut",from:{y:l*.6}}]}),{created:d,note:`Opener settles at ${(s+2.3).toFixed(1)}s`}}};ne["opener.bars"]={kind:"opener",description:"Coloured bars sweep across the frame in a stagger, uncovering a title that slams in.",params:'{title: string, start?: s, colors?: string[], textColor?, size?: px, font?, direction?: "left"|"right"}',apply:(e,t,n)=>{let o=U(e,t),s=J(n.start,0),r=n.colors??["#E8692A","#FFC93C","#F6EEDF","#1A1512"],a=n.direction==="right"?-1:1,i=o.height/r.length,c=[];return r.forEach((l,u)=>{let d=s+u*.08;c.push(H(e,o.id,{type:"solid",name:`bar-${u+1}`,color:l,size:[o.width,i+2],inPoint:s,outPoint:s+1.6,transform:{anchor:[0,0],position:Z([d,[-o.width*a,u*i],"expoInOut"],[d+.6,[0,u*i],"expoInOut"],[d+.85,[0,u*i],"expoInOut"],[d+1.4,[o.width*a,u*i]])}}).id)}),c.unshift(H(e,o.id,{type:"text",name:"bars-title",text:G(n.title,"TITLE"),size:J(n.size,Math.round(o.width/8)),weight:800,color:G(n.textColor,"#ffffff"),font:n.font,inPoint:s+.9,maxWidth:o.width*.88,animators:Be.slam.animators},0).id),{created:c}}};ne["slides.slideshow"]={kind:"slides",description:"Slider/slideshow from images and clips: each slide gets a slow Ken Burns move, an optional caption, and a transition into the next.",params:'{items: [{src, type?: "image"|"video", caption?, trimIn?, speed?}], start?: s, each?: s, transition?: type or list of types cycled per cut ("push"|"crossfade"|"zoom"|"wipe"|"whip"|"slideUp"), transitionDuration?: s, captionStyle?: text preset name, captionColor?, captionY?: px, plate?: colour, fitComp?: boolean (default true: comp duration = slideshow end)}',apply:(e,t,n)=>{let o=U(e,t),s=n.items??[],r=J(n.each,3),a=J(n.transitionDuration,.5),i=J(n.start,0),c=[],l=[];s.forEach((f,p)=>{let m=i+p*(r-a),h=m+r,b=f.type??(/\.(mp4|mov|webm|m4v)$/i.test(f.src)?"video":"image"),y=p%2===0,v=H(e,o.id,{type:b,name:`slide-${p+1}`,src:f.src,inPoint:+m.toFixed(3),outPoint:+h.toFixed(3),...b==="video"?{trimIn:f.trimIn??0,speed:f.speed??1}:{},transform:{scale:Z([m,y?[104,104]:[118,118]],[h,y?[118,118]:[104,104]])}},o.layers.length);l.push(v.id),c.push(v.id),f.caption&&c.push(H(e,o.id,{type:"text",name:`caption-${p+1}`,text:f.caption,size:Math.round(o.width/15),weight:800,color:G(n.captionColor,"#ffffff"),inPoint:+(m+a*.6).toFixed(3),outPoint:+(h-a).toFixed(3),maxWidth:o.width*.84,transform:{position:[o.width/2,J(n.captionY,o.height*.78)]},box:n.plate?{color:G(n.plate,"#000000"),padding:[32,16],radius:18,reveal:Z([m+a*.6,0,"expoOut"],[m+a*.6+.5,100])}:void 0,shadow:n.plate?void 0:{color:"rgba(0,0,0,0.7)",blur:18,y:4},animators:[...Be[G(n.captionStyle,"fadeUp")]?.animators??Be.fadeUp.animators,...Be.fadeOutDown.animators]},0).id)});let u=Array.isArray(n.transition)?n.transition:[G(n.transition,"push")];for(let f=1;f<l.length;f++)ne["transition.between"].apply(e,o.id,{from:l[f-1],to:l[f],type:u[(f-1)%u.length],duration:a});let d=ye(i+s.length*(r-a)+a);return n.fitComp!==!1&&(o.duration=d),{created:c,note:`Slideshow ends at ${d}s${n.fitComp!==!1?" (comp duration set to match)":""}`}}};ne["transition.between"]={kind:"transition",description:"Animates two overlapping layers (clips, images or precomps) so one hands over to the other at the overlap.",params:'{from: layerId (outgoing), to: layerId (incoming, must start before `from` ends), type: "push"|"crossfade"|"zoom"|"wipe"|"whip"|"slideUp"|"glitch"|"rgbWhip"|"warp"|"flash", duration?: s}',apply:(e,t,n)=>{let o=te(e,G(n.from,"")),s=te(e,G(n.to,"")),r=o.comp,a=J(n.duration,.5),i=s.layer.inPoint??0,c=i+a,l=r.width,u=r.height,d=[l/2,u/2],f=G(n.type,"push"),p=(m,...h)=>h.forEach(([b,y,v])=>q(e,m,"transform.position",b,y,v));switch(s.index>o.index&&(r.layers.splice(s.index,1),r.layers.splice(o.index,0,s.layer)),f){case"crossfade":q(e,s.layer.id,"transform.opacity",i,0,"easyEase"),q(e,s.layer.id,"transform.opacity",c,100);break;case"zoom":q(e,o.layer.id,"transform.opacity",i,100,"easeIn"),q(e,o.layer.id,"transform.opacity",c,0),fe(e,o.layer.id,{effects:[...o.layer.effects??[],{type:"blur",radius:Z([i,0,"easeIn"],[c,25])}]}),q(e,s.layer.id,"transform.opacity",i,0,"easeOut"),q(e,s.layer.id,"transform.opacity",c,100);break;case"wipe":fe(e,s.layer.id,{masks:[{shape:"rect",rect:Z([i,[0,0,0,u],"expoInOut"],[c,[0,0,l*1.2,u]])}]});break;case"slideUp":p(o.layer.id,[i,d,"expoInOut"],[c,[l/2,-u/2]]),p(s.layer.id,[i,[l/2,u*1.5],"expoInOut"],[c,d]);break;case"whip":p(o.layer.id,[i,d,"expoIn"],[c,[-l/2,u/2]]),p(s.layer.id,[i,[l*1.5,u/2],"expoOut"],[c,d]);for(let m of[o.layer.id,s.layer.id])fe(e,m,{motionBlur:{samples:12,shutter:360}});break;case"glitch":{let m=ye(i+a/2);bt(e,o.layer.id,{type:"glitch",amount:Z([i,0],[m,100])}),bt(e,s.layer.id,{type:"glitch",amount:Z([m,100],[c,0])}),q(e,s.layer.id,"transform.opacity",i,0,"hold"),q(e,s.layer.id,"transform.opacity",m,100);break}case"rgbWhip":p(o.layer.id,[i,d,"expoIn"],[c,[-l/2,u/2]]),p(s.layer.id,[i,[l*1.5,u/2],"expoOut"],[c,d]);for(let m of[o.layer.id,s.layer.id])fe(e,m,{motionBlur:{samples:10,shutter:270}}),bt(e,m,{type:"rgbSplit",amount:Z([i,0,"easeIn"],[ye(i+a/2),40,"easeOut"],[c,0])});break;case"warp":{let m=ye(i+a/2);bt(e,o.layer.id,{type:"wave",amplitude:Z([i,0,"easeIn"],[c,80]),wavelength:260,speed:2}),bt(e,s.layer.id,{type:"wave",amplitude:Z([i,80,"easeOut"],[c,0]),wavelength:260,speed:2}),q(e,s.layer.id,"transform.opacity",i,0,"easyEase"),q(e,s.layer.id,"transform.opacity",m,100);break}case"flash":q(e,s.layer.id,"transform.opacity",i,0,"hold"),q(e,s.layer.id,"transform.opacity",ye(i+a/2),100),ne["overlay.lightLeak"].apply(e,r.id,{start:i-a*.2,duration:a*1.6,intensity:100});break;default:p(o.layer.id,[i,d,"expoInOut"],[c,[-l/2,u/2]]),p(s.layer.id,[i,[l*1.5,u/2],"expoInOut"],[c,d])}return{created:[],note:`${f} from ${o.layer.id} to ${s.layer.id} at ${i}s\u2013${c}s`}}};var bt=(e,t,n)=>{let{layer:o}=te(e,t);o.effects=[...o.effects??[],n]};ne["overlay.lightLeak"]={kind:"overlay",description:"Warm film light leak: soft glowing colour blobs drift across the frame (screen blend) \u2014 on cuts, openers or to add warmth.",params:'{start?: s, duration?: s (default 1.2), colors?: string[], intensity?: 0-100 (default 80), direction?: "left"|"right"}',apply:(e,t,n)=>{let o=U(e,t),s=Math.max(0,J(n.start,0)),r=J(n.duration,1.2),a=J(n.intensity,80),i=n.colors??["#ff8a3d","#ffd166","#ff4f6d"],c=n.direction==="left"?-1:1,l=o.width,u=o.height,d=[];return i.forEach((f,p)=>{let m=Math.max(l,u)*(.55+p*.12),h=u*(.25+.3*p);d.push(H(e,o.id,{type:"shape",name:`light-leak-${p+1}`,shape:"ellipse",size:[m*2,m*2],blendMode:"screen",fill:{radial:{center:[0,0],radius:m,stops:[[0,`${f}ee`],[.45,`${f}66`],[1,`${f}00`]]}},inPoint:ye(s),outPoint:ye(s+r),transform:{position:Z([s,[l/2-c*l*(.8+p*.2),h],"easyEase"],[s+r,[l/2+c*l*(.6+p*.15),h+u*.1]]),opacity:Z([s,0,"easeOut"],[s+r*.4,a,"easeIn"],[s+r,0])}},0).id)}),{created:d}}};ne["element.lowerThird"]={kind:"element",description:"Lower third: an accent bar wipes in, then name and title slide out from behind it.",params:"{name: string, title?: string, start?: s, duration?: s, color?, textColor?, y?: px, font?}",apply:(e,t,n)=>{let o=U(e,t),s=J(n.start,0),r=J(n.duration,4),a=J(n.y,o.height*.72),i=G(n.color,"#E8692A"),c=o.width*.08,l=[],u=H(e,o.id,{type:"solid",name:"lt-bar",color:i,size:[12,170],inPoint:s,outPoint:s+r,transform:{anchor:[0,0],position:[c,a],scale:Z([s,[100,0],"expoOut"],[s+.5,[100,100]],[s+r-.5,[100,100],"expoIn"],[s+r,[100,0]])}});l.push(u.id);let d=(f,p,m,h,b,y)=>l.push(H(e,o.id,{type:"text",name:y,text:f,size:p,weight:800,align:"left",color:b,font:n.font,inPoint:s+h,outPoint:s+r,transform:{position:[c+34,a+m]},masks:[{shape:"rect",rect:[0,-200,o.width,400]}],animators:[{unit:"line",duration:.7,ease:"expoOut",from:{x:-o.width*.6}},{unit:"line",mode:"out",duration:.5,ease:"expoIn",from:{x:-o.width*.6}}]}).id);return d(G(n.name,"Name"),Math.round(o.width/15),55,.25,G(n.textColor,"#ffffff"),"lt-name"),n.title&&d(G(n.title,""),Math.round(o.width/28),125,.4,i,"lt-title"),{created:l}}};ne["element.highlightWord"]={kind:"element",description:"Adds a background plate that wipes in behind an existing text layer (marker highlight).",params:"{layer: textLayerId, color?, at?: s, duration?: s, padding?: [x,y], radius?}",apply:(e,t,n)=>{let{layer:o}=te(e,G(n.layer,""));if(o.type!=="text")throw new de(`${o.id} is not a text layer`);let s=J(n.at,o.inPoint??0),r=J(n.duration,.45);return o.box={color:G(n.color,"#E8692A"),padding:n.padding??[26,10],radius:J(n.radius,14),reveal:Z([s,0,"expoOut"],[s+r,100])},{created:[]}}};Object.assign(ne,Fo,Do,Ko,Zo);var Le=window.DTLY;var fs=(e,t,n,o)=>{let s=3*e,r=3*(n-e)-s,a=1-s-r,i=3*t,c=3*(o-t)-i,l=1-i-c,u=p=>((a*p+r)*p+s)*p,d=p=>((l*p+c)*p+i)*p,f=p=>(3*a*p+2*r)*p+s;return p=>{let m=p;for(let y=0;y<8;y++){let v=u(m)-p;if(Math.abs(v)<1e-6)return d(m);let k=f(m);if(Math.abs(k)<1e-6)break;m-=v/k}let h=0,b=1;m=p;for(let y=0;y<40;y++){let v=u(m);if(Math.abs(v-p)<1e-6)break;v<p?h=m:b=m,m=(h+b)/2}return d(m)}},Qo={easeIn:[.42,0,1,1],easeOut:[0,0,.58,1],easyEase:[.333,0,.667,1],quadOut:[.25,.46,.45,.94],cubicOut:[.215,.61,.355,1],expoIn:[.95,.05,.795,.035],expoOut:[.19,1,.22,1],expoInOut:[1,0,0,1],backOut:[.175,.885,.32,1.275],backIn:[.6,-.28,.735,.045]},Yo=new Map,hs=e=>e===0||e===1?e:Math.pow(2,-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,gs=e=>e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375,bs=(e,{stiffness:t=170,damping:n=18,mass:o=1}={})=>{let s=Math.sqrt(t/o),r=n/(2*Math.sqrt(t*o));if(r<1){let a=s*Math.sqrt(1-r*r);return 1-Math.exp(-r*s*e)*(Math.cos(a*e)+r*s/a*Math.sin(a*e))}return 1-Math.exp(-s*e)*(1+s*e)},Ne=(e,t,n=1)=>{if(!e||e==="linear")return t;if(e==="hold")return t>=1?1:0;if(e==="elasticOut")return hs(t);if(e==="bounceOut")return gs(t);if(typeof e=="object"&&!Array.isArray(e))return t>=1?1:bs(t*n,e.spring);let o=Array.isArray(e)?e:Qo[e];if(!o)return t;let s=o.join(","),r=Yo.get(s);return r||Yo.set(s,r=fs(...o)),r(t)},er=["linear","hold",...Object.keys(Qo),"elasticOut","bounceOut"];var Xt=new Map,tr=e=>{let t=Xt.get(e);return t||(t=ue(e),Xt.size>200&&Xt.clear(),Xt.set(e,t)),t},Zt=(e,t,n)=>e+(t-e)*n,ys=(e,t,n)=>{if(typeof e=="number"&&typeof t=="number")return Zt(e,t,n);if(Array.isArray(e)&&Array.isArray(t))return e.map((o,s)=>Zt(o,t[s]??o,n));if(typeof e=="string"&&typeof t=="string"){let o=ke(e),s=ke(t);if(o&&s)return Oe(o.map((r,a)=>Zt(r,s[a],n)));if(/^\s*[Mm]/.test(e)&&/^\s*[Mm]/.test(t))return n<=0?e:n>=1?t:Vt(Eo(tr(e),tr(t),n))}return n<1?e:t},nr=e=>{let t=Math.sin(e*127.1+311.7)*43758.5453;return t-Math.floor(t)},ws=(e,t)=>{let n=Math.floor(e),o=e-n,s=o*o*(3-2*o);return Zt(nr(n+t*1e3)*2-1,nr(n+1+t*1e3)*2-1,s)},vs=(e,t,n)=>{let o=s=>ws(t*n.freq,(n.seed??1)+s*17.3)*n.amp;return typeof e=="number"?e+o(0):Array.isArray(e)?e.map((s,r)=>s+o(r)):e},xs=(e,t)=>{if(e.length===0)throw new Error("empty keyframes");if(t<=e[0].t)return e[0].v;let n=e[e.length-1];if(t>=n.t)return n.v;let o=0;for(;o<e.length-2&&t>=e[o+1].t;)o++;let s=e[o],r=e[o+1],a=r.t-s.t,i=Ne(s.ease,a<=0?1:(t-s.t)/a,a);return ys(s.v,r.v,i)};function E(e,t,n){if(e==null)return n;if(!be(e))return e;let o=[...e.keyframes].sort((r,a)=>r.t-a.t),s=xs(o,t);return e.wiggle?vs(s,t,e.wiggle):s}var yt=e=>e.startsWith("data:")?e:`/api/media?src=${encodeURIComponent(e)}&token=${Le.token}`,or=(e,t,n=2e3)=>new Promise(o=>{let s=()=>{clearTimeout(r),e.removeEventListener(t,s),o()},r=setTimeout(s,n);e.addEventListener(t,s,{once:!0})}),Yt=class{defaultFont="Baloo 2";playing=!1;images=new Map;videos=new Map;frameNo=0;createCanvas(t,n){let o=document.createElement("canvas");return o.width=t,o.height=n,o}async data(t){let n=await fetch(yt(t));if(!n.ok)throw new Error(`Could not load ${t}`);return n.text()}image(t){return this.images.has(t)||this.images.set(t,new Promise((n,o)=>{let s=new Image;s.onload=()=>n(s),s.onerror=()=>o(new Error(`Could not load ${t}`)),s.src=yt(t)})),this.images.get(t)}async videoFrame(t,n,o,s,r){let a=`${t.id}|${t.src}`,i=this.videos.get(a);if(!i){let h=document.createElement("video");h.muted=!0,h.playsInline=!0,h.preload="auto",h.crossOrigin="anonymous",h.src=yt(t.src),i={el:h,canvas:document.createElement("canvas"),used:0},this.videos.set(a,i),await or(h,"loadeddata",5e3)}i.used=this.frameNo;let c=i.el,l=Math.max(0,Math.min(n,(c.duration||1/0)-.001));this.playing?(c.playbackRate=t.speed??1,Math.abs(c.currentTime-l)>.25&&(c.currentTime=l),c.paused&&c.play().catch(()=>{})):(c.paused||c.pause(),Math.abs(c.currentTime-l)>.5/r&&(c.currentTime=l,await or(c,"seeked")));let u=i.canvas;(u.width!==o||u.height!==s)&&(u.width=o,u.height=s);let d=u.getContext("2d");d.clearRect(0,0,o,s);let f=c.videoWidth||o,p=c.videoHeight||s,m=t.fit??"cover";if(m==="fill")d.drawImage(c,0,0,o,s);else{let h=m==="cover"?Math.max(o/f,s/p):Math.min(o/f,s/p);d.drawImage(c,(o-f*h)/2,(s-p*h)/2,f*h,p*h)}return u}endFrame(){for(let t of this.videos.values())t.used!==this.frameNo&&!t.el.paused&&t.el.pause();this.frameNo++}stopAll(){for(let t of this.videos.values())t.el.pause()}},Qt=class{els=new Map;sync(t,n,o,s){let r=new Set;for(let a of n.layers){if(a.type!=="audio"&&!(a.type==="video"&&a.volume))continue;let i=a,c=`${i.id}|${i.src}`,l=this.els.get(c);l||(l=new Audio(yt(i.src)),l.preload="auto",this.els.set(c,l)),r.add(c);let u=i.inPoint??0,d=i.outPoint??n.duration;if(!(s&&o>=u&&o<d)){l.paused||l.pause();continue}let p=i.type==="video"?i.speed??1:1,m=(i.trimIn??0)+(o-u)*p,h=Math.max(0,Math.min(1,E(i.volume,o,1)));i.type==="audio"&&(i.fadeIn&&o-u<i.fadeIn&&(h*=(o-u)/i.fadeIn),i.fadeOut&&d-o<i.fadeOut&&(h*=(d-o)/i.fadeOut)),l.volume=h,l.playbackRate=p,Math.abs(l.currentTime-m)>.2&&(l.currentTime=m),l.paused&&l.play().catch(()=>{})}for(let[a,i]of this.els)!r.has(a)&&!i.paused&&i.pause()}stop(){for(let t of this.els.values())t.pause()}},rr=async e=>{let t=[new FontFace("Baloo 2","url(/fonts/Baloo2.ttf)",{weight:"400 800"}),new FontFace("Mukta","url(/fonts/Mukta-Bold.ttf)",{weight:"400 800"})];for(let[n,o]of Object.entries(e.fonts??{}))for(let s of o)t.push(new FontFace(n,`url(${yt(s)})`));await Promise.all(t.map(async n=>{try{document.fonts.add(await n.load())}catch{}}))};var ks=0;function g(e,t,n,o,s,r){t||(t={});var a,i,c=t;if("ref"in c&&typeof e!="function")for(i in c={},t)i=="ref"?a=t[i]:c[i]=t[i];var l={type:e,props:c,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ks,__i:-1,__u:0};return(s||r)&&(l.__source=s,l.__self=r),F.vnode&&F.vnode(l),l}var sr=e=>Number.isInteger(e)?String(e):e.toFixed(Math.abs(e)<10?2:1),at=({value:e,onChange:t,onDragStart:n,onDragEnd:o,step:s=1,min:r,max:a,title:i})=>{let[c,l]=le(null),u=xe(null),d=f=>Math.min(a??1/0,Math.max(r??-1/0,f));return c!==null?g("input",{class:"num editing",value:c,autoFocus:!0,title:i,onInput:f=>l(f.target.value),onBlur:()=>{let f=Number(c);Number.isFinite(f)&&t(d(f),!1),l(null)},onKeyDown:f=>{f.key==="Enter"&&f.target.blur(),f.key==="Escape"&&l(null),f.stopPropagation()}}):g("span",{class:"num",title:i??"Drag to scrub, click to type",onPointerDown:f=>{f.target.setPointerCapture(f.pointerId),u.current={x:f.clientX,v:e,moved:!1}},onPointerMove:f=>{let p=u.current;if(!p)return;let m=f.clientX-p.x;!p.moved&&Math.abs(m)>2&&(p.moved=!0,n?.()),p.moved&&t(d(+(p.v+m*s*(f.shiftKey?10:f.altKey?.1:1)).toFixed(4)),!0)},onPointerUp:()=>{let f=u.current;u.current=null,f?.moved?o?.():l(sr(e))},children:sr(e)})},wt=({value:e,onChange:t,onDragStart:n,onDragEnd:o,step:s=1,labels:r=["x","y"]})=>g("span",{class:"vec",children:e.map((a,i)=>g("span",{class:"vec-item",children:[g("label",{children:r[i]}),g(at,{value:a,step:s,onDragStart:n,onDragEnd:o,onChange:(c,l)=>t(e.map((u,d)=>d===i?c:u),l)})]},i))}),_s=e=>{if(/^#[0-9a-f]{6}$/i.test(e))return e;if(/^#[0-9a-f]{3}$/i.test(e))return`#${[...e.slice(1)].map(n=>n+n).join("")}`;let t=e.match(/rgba?\(([^)]+)\)/);return t?`#${t[1].split(",").slice(0,3).map(n=>Math.round(Number(n)).toString(16).padStart(2,"0")).join("")}`:"#ffffff"},On=({value:e,onChange:t})=>g("span",{class:"color",children:[g("input",{type:"color",value:_s(e),onInput:n=>t(n.target.value)}),g("input",{class:"text",value:e,onChange:n=>t(n.target.value),onKeyDown:n=>n.stopPropagation()})]}),Ze=({value:e,onChange:t,multiline:n})=>n?g("textarea",{class:"text",value:e,rows:3,onChange:o=>t(o.target.value),onKeyDown:o=>o.stopPropagation()}):g("input",{class:"text",value:e,onChange:o=>t(o.target.value),onKeyDown:o=>o.stopPropagation()}),Se=({value:e,options:t,onChange:n})=>g("select",{value:e,onChange:o=>n(o.target.value),children:t.map(o=>g("option",{value:o,children:o},o))});var D={project:null,rev:0,comp:"main",time:0,playing:!1,loop:!0,layer:null,key:null,expanded:{},zoom:120,status:"loading",message:"",warnings:[],render:{active:!1}},Nn=new Set,A=()=>D,T=e=>{D={...D,...e},Nn.forEach(t=>t())},j=e=>{let[,t]=le(0);return Pe(()=>{let n=()=>t(o=>o+1);return Nn.add(n),()=>{Nn.delete(n)}},[]),e(D)},An=(e,t={})=>fetch(e,{...t,headers:{"Content-Type":"application/json","X-DTLY-Token":Le.token,...t.headers??{}}}),Qe=[],vt=[],Ms=200,ar,en=()=>{T({status:"saving"}),clearTimeout(ar),ar=window.setTimeout(Ps,250)},Ps=async()=>{if(D.project)try{let e=await An("/api/project",{method:"PUT",body:JSON.stringify({project:D.project})});if(!e.ok)throw new Error(await e.text());let{rev:t,warnings:n}=await e.json();T({rev:t,warnings:n,status:"saved",message:""})}catch(e){T({status:"error",message:`Save failed: ${e.message}`})}},W=e=>{if(!D.project)return;let t=JSON.stringify(D.project),n=JSON.parse(t);try{e(n)}catch(o){T({message:o.message});return}Qe.push(t),Qe.length>Ms&&Qe.shift(),vt.length=0,T({project:n,message:""}),en()},Ye=null,$e=()=>{Ye=D.project?JSON.stringify(D.project):null},Ae=e=>{if(!Ye)return;let t=JSON.parse(Ye);try{e(t)}catch{return}T({project:t})},Ee=()=>{Ye&&JSON.stringify(D.project)!==Ye&&(Qe.push(Ye),vt.length=0,en()),Ye=null},jn=()=>{let e=Qe.pop();!e||!D.project||(vt.push(JSON.stringify(D.project)),T({project:JSON.parse(e)}),en())},tn=()=>{let e=vt.pop();!e||!D.project||(Qe.push(JSON.stringify(D.project)),T({project:JSON.parse(e)}),en())},Vn=async(e=!1)=>{let t=await An("/api/project"),{rev:n,project:o}=await t.json();e&&D.project&&(Qe.push(JSON.stringify(D.project)),vt.length=0);let s=o.comps.some(a=>a.id===D.comp)?D.comp:o.root,r=D.layer&&o.comps.some(a=>a.layers.some(i=>i.id===D.layer))?D.layer:null;T({project:o,rev:n,comp:s,layer:r,key:r?D.key:null,status:e?"reloaded":"saved",message:e?"Reloaded: the file changed on disk":""})},ir=()=>{let e=new EventSource(`/api/events?token=${Le.token}`);e.addEventListener("project",t=>{let{rev:n}=JSON.parse(t.data);n>D.rev&&Vn(!0)}),e.addEventListener("render",t=>{let n=JSON.parse(t.data);n.error?T({render:{active:!1,error:n.error}}):n.finished?T({render:{active:!1,out:n.out},message:`Rendered ${n.out} in ${n.took?.toFixed(1)}s`}):T({render:{active:!0,done:n.done,total:n.total}})})},cr=async()=>{T({render:{active:!0,done:0}});let e=await An("/api/render",{method:"POST",body:JSON.stringify({comp:D.comp})});e.ok||T({render:{active:!1,error:await e.text()}})},ce=()=>D.project?.comps.find(e=>e.id===D.comp)??D.project?.comps[0],lr=()=>ce()?.layers.find(e=>e.id===D.layer),zn=e=>{let t=[],n=(o,s)=>{if(Array.isArray(o))o.forEach((r,a)=>typeof r=="object"&&r!==null&&n(r,`${s}.${a}`));else if(typeof o=="object"&&o!==null)if(be(o))t.push({path:s,keyframes:o.keyframes});else for(let[r,a]of Object.entries(o))r!=="animators"&&n(a,s?`${s}.${r}`:r)};return n(e,""),t},xt=(e,t)=>t.split(".").reduce((n,o)=>n?.[o],e),Y=(e,t)=>Math.round(Math.round(e*t)/t*1e3)/1e3;var re=({layer:e,path:t,label:n,kind:o,fallback:s,step:r=1,min:a,max:i})=>{let c=j(C=>C.time),l=ce(),u=xt(e,t),d=be(u),f=E(u,c,s),p=Y(c,l.fps),m=(C,S)=>d?q(C,e.id,t,p,S):dt(C,e.id,t,S),h=(C,S)=>S?Ae(_=>m(_,C)):W(_=>m(_,C)),b=d?u.keyframes.map(C=>C.t):[],y=b.some(C=>Math.abs(C-p)<.001),v=[...b].reverse().find(C=>C<p-.001),k=b.find(C=>C>p+.001),w=()=>W(C=>d?dt(C,e.id,t,f):q(C,e.id,t,p,f)),L=()=>W(C=>y?mt(C,e.id,t,p):q(C,e.id,t,p,f));return g("div",{class:"prop",children:[g("button",{class:`watch ${d?"on":""}`,title:d?"Stop animating (keep current value)":"Animate: add a keyframe at the playhead",onClick:w,children:"\u23F1"}),g("label",{children:n}),g("span",{class:"prop-value",children:[o==="num"&&g(at,{value:Number(f??0),step:r,min:a,max:i,onChange:h,onDragStart:$e,onDragEnd:Ee}),o==="vec"&&g(wt,{value:f??[0,0],step:r,onChange:h,onDragStart:$e,onDragEnd:Ee}),o==="color"&&g(On,{value:String(f??"#ffffff"),onChange:C=>h(C,!1)})]}),d&&g("span",{class:"keynav",children:[g("button",{disabled:v===void 0,onClick:()=>T({time:v}),children:"\u25C0"}),g("button",{class:y?"on":"",title:y?"Remove keyframe here":"Add keyframe here",onClick:L,children:"\u25C6"}),g("button",{disabled:k===void 0,onClick:()=>T({time:k}),children:"\u25B6"})]})]})},z=({label:e,children:t})=>g("div",{class:"prop",children:[g("span",{class:"watch-space"}),g("label",{children:e}),g("span",{class:"prop-value",children:t})]}),ee=(e,t)=>W(n=>fe(n,e.id,t)),we=(e,t,n,o,s,r=1)=>g(z,{label:t,children:g(at,{value:o??s,step:r,onChange:(a,i)=>i?Ae(c=>fe(c,e.id,{[n]:a})):ee(e,{[n]:a}),onDragStart:$e,onDragEnd:Ee})}),he=({title:e,children:t,open:n=!0})=>g("details",{class:"section",open:n,children:[g("summary",{children:e}),t]}),Ue=({value:e,onApply:t,rows:n=8})=>{let o=JSON.stringify(e,null,2),[s,r]=le(o),[a,i]=le("");return Pe(()=>{r(o),i("")},[o]),g("div",{class:"json",children:[g("textarea",{rows:n,value:s,spellcheck:!1,onInput:c=>r(c.target.value),onKeyDown:c=>c.stopPropagation()}),g("div",{class:"row",children:[a&&g("span",{class:"error",children:a}),g("button",{disabled:s===o,onClick:()=>{try{t(JSON.parse(s)),i("")}catch(c){i(c.message)}},children:"Apply"})]})]})},Cs=()=>{let e=j(a=>a.key),t=j(a=>a.project);if(!e||!t)return null;let n;try{let{layer:a}=te(t,e.layer);n=xt(a,e.path)?.keyframes?.find(i=>Math.abs(i.t-e.t)<.001)}catch{}if(!n)return null;let o=n.ease??"linear",s=typeof o=="string"?o:Array.isArray(o)?"bezier":"spring",r=a=>W(i=>$n(i,e.layer,e.path,e.t,a));return g(he,{title:`Keyframe \xB7 ${e.path} @ ${e.t}s`,children:[g(z,{label:"Ease out",children:g(Se,{value:s,options:[...er,"bezier","spring"],onChange:a=>r(a==="bezier"?[.25,.1,.25,1]:a==="spring"?{spring:{stiffness:170,damping:18}}:a)})}),Array.isArray(o)&&g(z,{label:"Bezier",children:g(wt,{value:o,step:.01,labels:["x1","y1","x2","y2"],onChange:(a,i)=>i?Ae(c=>$n(c,e.layer,e.path,e.t,a)):r(a),onDragStart:$e,onDragEnd:Ee})}),s==="spring"&&typeof o=="object"&&!Array.isArray(o)&&g(z,{label:"Spring",children:g(wt,{value:[o.spring.stiffness??170,o.spring.damping??18],labels:["stiff","damp"],onChange:a=>r({spring:{stiffness:a[0],damping:a[1]}})})}),g(Ls,{ease:o}),g(z,{label:"Value",children:g(Ue,{value:n.v,rows:2,onApply:a=>W(i=>q(i,e.layer,e.path,e.t,a))})}),g("div",{class:"row",children:g("button",{onClick:()=>{W(a=>mt(a,e.layer,e.path,e.t)),T({key:null})},children:"Delete keyframe"})})]})},Ls=({ease:e})=>{let t=[];for(let n=0;n<=40;n++){let o=n/40,s=Ne(e,o);t.push(`${(o*180+10).toFixed(1)},${(110-s*90).toFixed(1)}`)}return g("svg",{class:"ease-graph",viewBox:"0 0 200 130",children:[g("line",{x1:"10",y1:"110",x2:"190",y2:"110"}),g("line",{x1:"10",y1:"20",x2:"190",y2:"20",class:"guide"}),g("polyline",{points:t.join(" ")})]})},Ss=(e,t)=>{if(e.type==="solid"||e.type==="image"||e.type==="video")return[(e.size?.[0]??t.width)/2,(e.size?.[1]??t.height)/2];if(e.type==="precomp"){let n=A().project?.comps.find(o=>o.id===e.comp);return[(n?.width??t.width)/2,(n?.height??t.height)/2]}return[0,0]},$s=({layer:e,comp:t})=>{let n=t.layers.filter(r=>r.id!==e.id),o=t.layers.indexOf(e),s=["Baloo 2","Mukta",...Object.keys(A().project?.fonts??{})];return g(We,{children:[g(he,{title:`${e.type} \xB7 ${e.id}`,children:[g(z,{label:"Name",children:g(Ze,{value:e.name??"",onChange:r=>ee(e,{name:r||null})})}),we(e,"In","inPoint",e.inPoint,0,1/t.fps),we(e,"Out","outPoint",e.outPoint,t.duration,1/t.fps),g(z,{label:"Parent",children:g(Se,{value:e.parent??"(none)",options:["(none)",...n.map(r=>r.id)],onChange:r=>ee(e,{parent:r==="(none)"?null:r})})}),g(z,{label:"Blend",children:g(Se,{value:e.blendMode??"normal",options:["normal","multiply","screen","overlay","add","darken","lighten","softLight","difference"],onChange:r=>ee(e,{blendMode:r==="normal"?null:r})})}),g(z,{label:"Motion blur",children:g("input",{type:"checkbox",checked:!!e.motionBlur,onChange:r=>ee(e,{motionBlur:r.target.checked?{samples:8}:null})})}),g("div",{class:"row",children:[g("button",{disabled:o<=0,onClick:()=>W(r=>Ln(r,e.id,o-1)),children:"Up"}),g("button",{disabled:o>=t.layers.length-1,onClick:()=>W(r=>Ln(r,e.id,o+1)),children:"Down"}),g("button",{onClick:()=>W(r=>{let a=Bt(r,e.id);T({layer:a.id})}),children:"Duplicate"}),g("button",{class:"danger",onClick:()=>{W(r=>Ht(r,e.id)),T({layer:null,key:null})},children:"Delete"})]})]}),e.type!=="audio"&&g(he,{title:"Transform",children:[g(re,{layer:e,path:"transform.position",label:"Position",kind:"vec",fallback:[t.width/2,t.height/2]}),g(re,{layer:e,path:"transform.scale",label:"Scale %",kind:"vec",fallback:[100,100]}),g(re,{layer:e,path:"transform.rotation",label:"Rotation \xB0",kind:"num",fallback:0}),g(re,{layer:e,path:"transform.opacity",label:"Opacity %",kind:"num",fallback:100,min:0,max:100}),g(re,{layer:e,path:"transform.anchor",label:"Anchor",kind:"vec",fallback:Ss(e,t)}),g(re,{layer:e,path:"transform.skew",label:"Skew \xB0",kind:"num",fallback:0})]}),e.type==="text"&&g(he,{title:"Text",children:[g(z,{label:"Text",children:g(Ze,{multiline:!0,value:e.text,onChange:r=>ee(e,{text:r})})}),g(re,{layer:e,path:"size",label:"Size",kind:"num",fallback:72,min:1}),g(re,{layer:e,path:"color",label:"Color",kind:"color",fallback:"#ffffff"}),g(re,{layer:e,path:"tracking",label:"Tracking",kind:"num",fallback:0}),g(z,{label:"Font",children:g(Se,{value:e.font??"Baloo 2",options:s,onChange:r=>ee(e,{font:r})})}),g(z,{label:"Weight",children:g(Se,{value:String(e.weight??700),options:["400","500","600","700","800"],onChange:r=>ee(e,{weight:Number(r)})})}),g(z,{label:"Align",children:g(Se,{value:e.align??"center",options:["left","center","right"],onChange:r=>ee(e,{align:r})})}),we(e,"Max width","maxWidth",e.maxWidth,0,5),we(e,"Line height","lineHeight",e.lineHeight,1.25,.01),g(z,{label:"Animators",children:g(Ue,{value:e.animators??[],rows:6,onApply:r=>ee(e,{animators:r})})}),g("div",{class:"presets",children:Object.entries(ne).filter(([,r])=>r.kind==="text").map(([r])=>g("button",{title:ne[r].description,onClick:()=>W(a=>ne[r].apply(a,t.id,{layer:e.id})),children:r.slice(5)},r))})]}),e.type==="shape"&&g(he,{title:"Shape",children:[g(z,{label:"Shape",children:g(Se,{value:e.shape,options:["rect","ellipse","polygon","path","line"],onChange:r=>ee(e,{shape:r})})}),(e.shape==="rect"||e.shape==="ellipse")&&g(re,{layer:e,path:"size",label:"Size",kind:"vec",fallback:[200,200]}),(e.shape==="rect"||e.shape==="polygon")&&g(re,{layer:e,path:"radius",label:"Radius",kind:"num",fallback:e.shape==="rect"?0:100}),(typeof e.fill=="string"||be(e.fill)||e.fill===void 0)&&g(re,{layer:e,path:"fill",label:"Fill",kind:"color",fallback:"#ffffff"}),g(re,{layer:e,path:"stroke",label:"Stroke",kind:"color",fallback:"#ffffff"}),g(re,{layer:e,path:"strokeWidth",label:"Stroke width",kind:"num",fallback:4,min:0}),g(re,{layer:e,path:"trim.start",label:"Trim start %",kind:"num",fallback:0,min:0,max:100}),g(re,{layer:e,path:"trim.end",label:"Trim end %",kind:"num",fallback:100,min:0,max:100})]}),e.type==="solid"&&g(he,{title:"Solid",children:g(re,{layer:e,path:"color",label:"Color",kind:"color",fallback:"#000000"})}),(e.type==="image"||e.type==="video")&&g(he,{title:e.type==="video"?"Video":"Image",children:[g(z,{label:"Source",children:g(Ze,{value:e.src,onChange:r=>ee(e,{src:r})})}),g(z,{label:"Fit",children:g(Se,{value:e.fit??"cover",options:["cover","contain","fill"],onChange:r=>ee(e,{fit:r})})}),e.type==="video"&&we(e,"Trim in (s)","trimIn",e.trimIn,0,.05),e.type==="video"&&we(e,"Speed","speed",e.speed,1,.01),e.type==="video"&&g(re,{layer:e,path:"volume",label:"Volume",kind:"num",fallback:0,step:.01,min:0,max:1})]}),e.type==="lottie"&&g(he,{title:"Lottie",children:[g(z,{label:"Source",children:g(Ze,{value:e.src,onChange:r=>ee(e,{src:r})})}),g(z,{label:"Loop",children:g("input",{type:"checkbox",checked:e.loop!==!1,onChange:r=>ee(e,{loop:r.target.checked?null:!1})})}),we(e,"Speed","speed",e.speed,1,.01),we(e,"Time offset (s)","timeOffset",e.timeOffset,0,.05),g(z,{label:"Box size",children:g(Ue,{value:e.size??null,rows:1,onApply:r=>ee(e,{size:r})})})]}),e.type==="audio"&&g(he,{title:"Audio",children:[g(z,{label:"Source",children:g(Ze,{value:e.src,onChange:r=>ee(e,{src:r})})}),we(e,"Trim in (s)","trimIn",e.trimIn,0,.05),g(re,{layer:e,path:"volume",label:"Volume",kind:"num",fallback:1,step:.01,min:0,max:1}),we(e,"Fade in (s)","fadeIn",e.fadeIn,0,.05),we(e,"Fade out (s)","fadeOut",e.fadeOut,0,.05)]}),e.type==="precomp"&&g(he,{title:"Precomp",children:[g(z,{label:"Comp",children:g(Se,{value:e.comp,options:A().project.comps.filter(r=>r.id!==t.id).map(r=>r.id),onChange:r=>ee(e,{comp:r})})}),we(e,"Time offset","timeOffset",e.timeOffset,0,.05),g("div",{class:"row",children:g("button",{onClick:()=>T({comp:e.comp,layer:null,key:null,time:0}),children:"Open comp"})})]}),g(he,{title:"Effects, masks & matte (JSON)",open:!1,children:[g(z,{label:"Effects",children:g(Ue,{value:e.effects??[],rows:5,onApply:r=>ee(e,{effects:r})})}),g(z,{label:"Masks",children:g(Ue,{value:e.masks??[],rows:4,onApply:r=>ee(e,{masks:r})})}),g(z,{label:"Matte",children:g(Ue,{value:e.matte??null,rows:2,onApply:r=>ee(e,{matte:r})})})]}),g(he,{title:"Layer JSON",open:!1,children:g(Ue,{value:e,rows:16,onApply:r=>W(a=>{let i=r;if(i.id!==e.id)throw new Error("The id cannot change here");let c=a.comps.find(l=>l.id===t.id);c.layers[c.layers.findIndex(l=>l.id===e.id)]=i})})})]})},Es=({comp:e})=>{let t=A().project,n=o=>W(s=>Ao(s,e.id,o));return g(he,{title:`Composition \xB7 ${e.id}`,children:[g(z,{label:"Name",children:g(Ze,{value:e.name??"",onChange:o=>n({name:o||void 0})})}),g(z,{label:"Size",children:g(wt,{value:[e.width,e.height],labels:["w","h"],onChange:o=>n({width:Math.round(o[0]),height:Math.round(o[1])})})}),g(z,{label:"FPS",children:g(at,{value:e.fps,onChange:o=>n({fps:Math.max(1,Math.round(o))})})}),g(z,{label:"Duration (s)",children:g(at,{value:e.duration,step:.1,min:.1,onChange:o=>n({duration:o})})}),g(z,{label:"Background",children:g(On,{value:e.background??"#000000",onChange:o=>n({background:o})})}),g(z,{label:"Markers",children:g(Ue,{value:e.markers??[],rows:3,onApply:o=>n({markers:o})})}),t.root!==e.id&&g("div",{class:"row",children:g("button",{onClick:()=>W(o=>{o.root=e.id}),children:"Render this comp"})})]})},pr=()=>{let e=j(r=>r.project),t=j(r=>r.comp),n=j(r=>r.layer),o=e?.comps.find(r=>r.id===t);if(!o)return g("aside",{class:"inspector"});let s=o.layers.find(r=>r.id===n);return g("aside",{class:"inspector",children:[g(Cs,{}),s?g($s,{layer:s,comp:o},s.id):g(Es,{comp:o})]})};var Rn=230,ur={text:"#e0a84a",shape:"#5fb3a0",solid:"#9b7fd1",image:"#5b9bd5",video:"#d36c6c",audio:"#7fb35f",precomp:"#c78bc0",lottie:"#4fc1c9",adjustment:"#b0b0b0",null:"#888"},Ts=e=>e.replace(/^transform\./,"").replace(/\.(\d+)\./g,"[$1]."),Is=(e,t)=>{let o=[.1,.25,.5,1,2,5,10,30,60].find(r=>r*t>=60)??60,s=[];for(let r=0;r<=e+1e-6;r+=o)s.push(+r.toFixed(3));return{out:s,step:o}},dr=(e,t)=>{let n=()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",n),t()};window.addEventListener("pointermove",e),window.addEventListener("pointerup",n)},mr=e=>e.ease==="hold"?"hold":!e.ease||e.ease==="linear"?"linear":"eased",fr=()=>{let e=j(w=>w.project),t=j(w=>w.comp),n=j(w=>w.time),o=j(w=>w.zoom),s=j(w=>w.layer),r=j(w=>w.key),a=j(w=>w.expanded),i=xe(null),c=e?.comps.find(w=>w.id===t);if(!c)return g("div",{class:"timeline"});let l=c.duration*o+120,u=c.fps,d=w=>{let L=i.current.getBoundingClientRect();return Math.max(0,Math.min(c.duration,(w-L.left-Rn+i.current.scrollLeft)/o))},f=w=>{let L=A().time;return Math.abs(w-L)*o<6?L:Y(w,u)},p=w=>{w.currentTarget.setPointerCapture(w.pointerId),T({time:Y(d(w.clientX),u),playing:!1})},m=w=>{(w.buttons&1)!==0&&T({time:Y(d(w.clientX),u)})},h=(w,L,C)=>{w.stopPropagation(),T({layer:L.id,key:null});let S=w.clientX,_=L.inPoint??0,x=L.outPoint??c.duration,M=!1;dr($=>{let I=($.clientX-S)/o;if(!M){if(Math.abs($.clientX-S)<3)return;M=!0,$e()}Ae(N=>{if(C==="move"){let O=f(_+I);ut(N,L.id,O-_)}else C==="in"?fe(N,L.id,{inPoint:Math.min(x-1/u,Math.max(0,f(_+I)))}):fe(N,L.id,{outPoint:Math.max(_+1/u,f(x+I))})})},()=>{M&&Ee()})},b=(w,L,C,S)=>{w.stopPropagation(),T({layer:L.id,key:{layer:L.id,path:C,t:S.t},time:w.altKey?A().time:S.t,playing:!1});let _=w.clientX,x=S.t,M=!1;dr($=>{if(!M){if(Math.abs($.clientX-_)<3)return;M=!0,$e()}let I=Math.max(0,f(x+($.clientX-_)/o));Ae(N=>zo(N,L.id,C,x,I)),T({key:{layer:L.id,path:C,t:I},time:I})},()=>{M&&Ee()})},y=(w,L,C)=>{let S=Y(d(w.clientX),u),_=xt(L,C),x=E(_,S,void 0);W(M=>q(M,L.id,C,S,x)),T({key:{layer:L.id,path:C,t:S},time:S})},{out:v}=Is(c.duration,o);return g("div",{class:"timeline",children:g("div",{class:"tl-scroll",ref:i,onWheel:w=>{(w.ctrlKey||w.metaKey)&&(w.preventDefault(),T({zoom:Math.min(2e3,Math.max(10,o*(w.deltaY<0?1.15:1/1.15)))}))},children:g("div",{class:"tl-inner",style:{width:`${Rn+l}px`},children:[g("div",{class:"tl-ruler-row",children:[g("div",{class:"tl-label tl-corner",children:[c.name??c.id," \xB7 ",c.fps," fps"]}),g("div",{class:"tl-ruler",style:{width:`${l}px`},onPointerDown:p,onPointerMove:m,children:[v.map(w=>g("div",{class:"tick",style:{left:`${w*o}px`},children:g("span",{children:[w,"s"]})},w)),(c.markers??[]).map(w=>g("div",{class:"marker",style:{left:`${w.t*o}px`},title:w.label},w.t)),g("div",{class:"tl-end",style:{left:`${c.duration*o}px`}})]})]}),c.layers.map((w,L)=>{let C=w.inPoint??0,S=w.outPoint??c.duration,_=zn(w),x=a[w.id];return g("div",{class:`tl-group ${s===w.id?"selected":""}`,children:[g("div",{class:"tl-row layer-row",children:[g("div",{class:"tl-label",onPointerDown:()=>T({layer:w.id,key:null}),children:[g("button",{class:`twirl ${x?"open":""} ${_.length?"":"empty"}`,onClick:M=>{M.stopPropagation(),T({expanded:{...a,[w.id]:!x}})},children:"\u25B8"}),g("button",{class:`eye ${w.hidden?"off":""}`,title:"Show/hide",onClick:M=>{M.stopPropagation(),W(P=>fe(P,w.id,{hidden:w.hidden?null:!0}))},children:"\u25CF"}),g("span",{class:"idx",children:L+1}),g("span",{class:"chip",style:{background:ur[w.type]}}),g("span",{class:"name",title:w.id,children:w.name??w.id})]}),g("div",{class:"tl-track",style:{width:`${l}px`},onPointerDown:p,onPointerMove:m,children:[g("div",{class:`bar ${w.hidden?"hidden":""}`,style:{left:`${C*o}px`,width:`${Math.max(2,(S-C)*o)}px`,background:ur[w.type]},onPointerDown:M=>h(M,w,"move"),children:[g("span",{class:"handle in",onPointerDown:M=>h(M,w,"in")}),g("span",{class:"bar-name",children:w.type==="text"?w.text.split(`
|
|
3
|
+
`)[0]:w.name??w.id}),g("span",{class:"handle out",onPointerDown:M=>h(M,w,"out")})]}),!x&&_.flatMap(M=>M.keyframes.map(P=>g("span",{class:"mini-key",style:{left:`${P.t*o}px`}},`${M.path}${P.t}`)))]})]}),x&&_.map(M=>g("div",{class:"tl-row prop-row",children:[g("div",{class:"tl-label prop-label",title:M.path,children:Ts(M.path)}),g("div",{class:"tl-track",style:{width:`${l}px`},onPointerDown:p,onPointerMove:m,onDblClick:P=>y(P,w,M.path),children:[M.keyframes.map((P,$)=>{let I=M.keyframes[$+1];return I?g("span",{class:`seg ${mr(P)}`,style:{left:`${P.t*o}px`,width:`${(I.t-P.t)*o}px`}},`seg${P.t}`):null}),M.keyframes.map((P,$)=>{let I=r&&r.layer===w.id&&r.path===M.path&&Math.abs(r.t-P.t)<.001;return g("span",{class:`key ${mr(P)} ${I?"active":""}`,style:{left:`${P.t*o}px`},title:`${P.t}s = ${JSON.stringify(P.v)}${P.ease?` \xB7 ${typeof P.ease=="string"?P.ease:JSON.stringify(P.ease)}`:""}`,onPointerDown:N=>b(N,w,M.path,P)},$)})]})]},M.path))]},w.id)}),g("div",{class:"playhead",style:{left:`${Rn+n*o}px`}})]})})})},hr=e=>{let t=A();if(!t.project)return[];let{layer:n}=te(t.project,e);return[...new Set(zn(n).flatMap(o=>o.keyframes.map(s=>s.t)))].sort((o,s)=>o-s)};var Os=new Intl.Segmenter(void 0,{granularity:"grapheme"}),gr=e=>[...Os.segment(e)].map(t=>t.segment),Fn=(e,t,n)=>`${e.weight??700} ${t}px "${e.font??n}"`,nn=new Map,Dn=(e,t,n,o,s)=>{let r=[t.text,s,o,t.maxWidth,t.align,t.lineHeight].join("|"),a=nn.get(r);if(a)return a;e.font=s;let i=e.measureText("|").width,c=y=>/\s$/.test(y)?e.measureText(`${y}|`).width-i:e.measureText(y).width,l=y=>c(y)+o*Math.max(0,gr(y).length-1),u=(t.lineHeight??1.25)*n,d=[];for(let y of t.text.split(`
|
|
4
|
+
`)){if(!t.maxWidth){d.push(y);continue}let v="";for(let k of y.split(" ")){let w=v?`${v} ${k}`:k;v&&l(w)>t.maxWidth?(d.push(v),v=k):v=w}d.push(v)}let f=t.align??"center",p=-(d.length*u)/2,m={lines:[],graphemes:[],words:[],width:0,height:d.length*u,top:p,size:n},h=0,b=0;return d.forEach((y,v)=>{let k=l(y);m.width=Math.max(m.width,k);let w=f==="left"?0:f==="right"?-k:-k/2,L=p+v*u+u*.5+n*.32;m.lines.push({text:y,x:w,y:L,w:k});let C=gr(y),S="",_=null,x="",M=P=>{_!==null&&m.words.push({text:x,x:_,y:L,w:P-_,line:v,word:b++,grapheme:h}),_=null,x=""};C.forEach((P,$)=>{let I=w+(S?c(S):0)+o*$,N=e.measureText(P).width;P===" "?M(I):(_===null&&(_=I),x+=P,m.graphemes.push({text:P,x:I,y:L,w:N,line:v,word:b,grapheme:h++})),S+=P}),M(w+k)}),nn.size>500&&nn.clear(),nn.set(r,m),m},Ns=(e,t,n,o=1)=>{switch(n){case"reverse":return t-1-e;case"center":return Math.abs(e-(t-1)/2);case"edges":return(t-1)/2-Math.abs(e-(t-1)/2);case"random":return[...Array(t).keys()].sort((r,a)=>Math.sin(r*91.7+o)-Math.sin(a*91.7+o)).indexOf(e);default:return e}},As=(e,t,n,o,s,r)=>{let a={opacity:1,x:0,y:0,scale:1,rotation:0,blur:0,tracking:0};for(let i of e){let c=n[i.unit],l=t[i.unit],u=i.stagger??.05,d=i.duration??.5,f=i.delay??0,p=Ns(l,c,i.order,i.seed),m=i.order==="center"||i.order==="edges"?(c-1)/2:c-1,h;if(i.mode==="out"){let v=s-f-d-(m-p)*u;h=1-Ne(i.ease??"easeIn",Math.min(1,Math.max(0,(o-v)/d)),d)}else{let v=f+p*u;h=Ne(i.ease??"cubicOut",Math.min(1,Math.max(0,(o-v)/d)),d)}let b=1-h,y=i.from;if(y.opacity!==void 0&&(a.opacity*=(y.opacity+(100-y.opacity)*h)/100),y.x&&(a.x+=y.x*b),y.y&&(a.y+=y.y*b),y.scale!==void 0&&(a.scale*=(y.scale+(100-y.scale)*h)/100),y.rotation&&(a.rotation+=y.rotation*b),y.blur&&(a.blur+=y.blur*b),y.tracking&&(a.tracking+=y.tracking*b),y.color){let v=ke(y.color),k=ke(r);v&&k&&(a.color=Oe(v.map((w,L)=>w+(k[L]-w)*h)))}}return a},js=(e,t,n,o,s,r)=>{e.beginPath(),e.roundRect(t,n,o,s,r)},br=new Map,Vs=(e,t={})=>{let n=t.decimals??0,o=`${t.locale??"en-IN"}|${n}|${t.grouping!==!1}`,s=br.get(o);return s||br.set(o,s=new Intl.NumberFormat(t.locale??"en-IN",{minimumFractionDigits:n,maximumFractionDigits:n,useGrouping:t.grouping!==!1})),`${t.prefix??""}${s.format(e)}${t.suffix??""}`},Wn=(e,t)=>{if(e.value===void 0)return e.text;let n=Vs(E(e.value,t,0),e.format);return e.text.includes("{value}")?e.text.replace(/\{value\}/g,n):n},yr=(e,t,n,o,s,r)=>{let a=t.value===void 0?t:{...t,text:Wn(t,n)},i=E(a.size,n,72),c=E(a.tracking,n,0),l=E(a.color,n,"#ffffff"),u=Fn(a,i,r),d=Dn(e,a,i,c,u);if(e.font=u,e.textAlign="left",e.textBaseline="alphabetic",a.box){let[x,M]=a.box.padding??[24,12],P=E(a.box.reveal,n,100)/100,$=Math.min(...d.lines.map(O=>O.x))-x,I=d.width+x*2,N=d.height+M*2;P>0&&(e.save(),e.beginPath(),e.rect($,d.top-M,I*P,N),e.clip(),e.fillStyle=E(a.box.color,n,"#000"),js(e,$,d.top-M,I,N,a.box.radius??12),e.fill(),e.restore())}a.shadow&&(e.shadowColor=a.shadow.color,e.shadowBlur=a.shadow.blur,e.shadowOffsetX=a.shadow.x??0,e.shadowOffsetY=a.shadow.y??0);let f=(x,M,P,$)=>{a.stroke&&(e.lineJoin="round",e.lineWidth=a.stroke.width,e.strokeStyle=a.stroke.color,e.strokeText(x,M,P)),e.fillStyle=$,e.fillText(x,M,P)},p=a.animators??[],m=a.karaoke;if(p.length===0&&!m){for(let x of d.lines)f(x.text,x.x,x.y,l);return}let h=x=>{if(!m)return null;let M=m.words[x];if(!M||!(m.mode==="spoken"?n>=M[0]:n>=M[0]&&n<M[1]))return null;let $=Math.min(1,(n-M[0])/.12);return{color:m.color??"#FFC93C",scale:1+((m.scale??100)/100-1)*(m.mode==="spoken"?0:1-(1-$)*(1-$)),box:m.box}},b=p.some(x=>x.unit==="grapheme")?"grapheme":p.some(x=>x.unit==="word")||m?"word":"line",y=b==="grapheme"?d.graphemes:b==="word"?d.words:d.lines.map((x,M)=>({...x,line:M,word:0,grapheme:0})),v={grapheme:d.graphemes.length,word:d.words.length,line:d.lines.length},k=n-o,w=s-o,L=p.some(x=>x.clip),C=d.height/d.lines.length,S=new Map;for(let x of y)S.set(x.line,(S.get(x.line)??0)+1);let _=new Map;for(let x of y){let M=_.get(x.line)??0;_.set(x.line,M+1);let P=As(p,{grapheme:x.grapheme,word:x.word,line:x.line},v,k,w,l);if(P.opacity<=.001)continue;let $=b==="word"?h(x.word):null;$&&(P.color=$.color,P.scale*=$.scale),e.save(),L&&(e.beginPath(),e.rect(-1e5,d.top+x.line*C,2e5,C),e.clip());let I=P.tracking*(M-((S.get(x.line)??1)-1)/2),N=x.x+x.w/2+P.x+I,O=x.y-i*.35+P.y;e.translate(N,O),P.rotation&&e.rotate(P.rotation*Math.PI/180),P.scale!==1&&e.scale(P.scale,P.scale),e.globalAlpha*=P.opacity,P.blur>.1&&(e.filter=`blur(${P.blur.toFixed(2)}px)`),$?.box&&(e.save(),e.shadowColor="transparent",e.fillStyle=$.box,e.beginPath(),e.roundRect(-x.w/2-i*.12,-i*.62,x.w+i*.24,i*1.2,i*.18),e.fill(),e.restore()),f(x.text,-x.w/2,i*.35,P.color??l),e.restore()}};var je=.5522847498,on=new Map,zs=e=>{let t=on.get(e);return t||(t=ue(e),on.size>300&&on.clear(),on.set(e,t)),t},Hn=(e,t)=>{switch(e.shape){case"rect":{let[n,o]=E(e.size,t,[200,200]),s=Math.min(E(e.radius,t,0),Math.abs(n)/2,Math.abs(o)/2),r=-n/2,a=-o/2,i=s*(1-je);return s<=0?[{kind:"M",p:[r,a]},{kind:"L",p:[r+n,a]},{kind:"L",p:[r+n,a+o]},{kind:"L",p:[r,a+o]},{kind:"Z"}]:[{kind:"M",p:[r+s,a]},{kind:"L",p:[r+n-s,a]},{kind:"C",c1:[r+n-i,a],c2:[r+n,a+i],p:[r+n,a+s]},{kind:"L",p:[r+n,a+o-s]},{kind:"C",c1:[r+n,a+o-i],c2:[r+n-i,a+o],p:[r+n-s,a+o]},{kind:"L",p:[r+s,a+o]},{kind:"C",c1:[r+i,a+o],c2:[r,a+o-i],p:[r,a+o-s]},{kind:"L",p:[r,a+s]},{kind:"C",c1:[r,a+i],c2:[r+i,a],p:[r+s,a]},{kind:"Z"}]}case"ellipse":{let[n,o]=E(e.size,t,[200,200]),s=n/2,r=o/2;return[{kind:"M",p:[0,-r]},{kind:"C",c1:[s*je,-r],c2:[s,-r*je],p:[s,0]},{kind:"C",c1:[s,r*je],c2:[s*je,r],p:[0,r]},{kind:"C",c1:[-s*je,r],c2:[-s,r*je],p:[-s,0]},{kind:"C",c1:[-s,-r*je],c2:[-s*je,-r],p:[0,-r]},{kind:"Z"}]}case"polygon":case"star":{let n=Math.max(3,e.sides??(e.shape==="star"?5:6)),o=E(e.radius,t,100),s=E(e.innerRadius,t,o*.45),r=e.shape==="star"?n*2:n,a=[];for(let i=0;i<r;i++){let c=e.shape==="star"&&i%2?s:o,l=i/r*Math.PI*2-Math.PI/2;a.push({kind:i?"L":"M",p:[Math.cos(l)*c,Math.sin(l)*c]})}return a.push({kind:"Z"}),a}default:{if(e.path!==void 0)return zs(E(e.path,t,""));let o=(e.points??[]).map((s,r)=>({kind:r?"L":"M",p:s}));return(e.closed??e.shape==="path")&&o.push({kind:"Z"}),o}}},Rs=(e,t)=>{let n="linear"in t?e.createLinearGradient(...t.linear.from,...t.linear.to):e.createRadialGradient(...t.radial.center,0,...t.radial.center,t.radial.radius);for(let[o,s]of"linear"in t?t.linear.stops:t.radial.stops)n.addColorStop(o,s);return n},wr=(e,t,n,o)=>{let s=E(t.trim?.start,o,0)/100,r=E(t.trim?.end,o,100)/100,a=E(t.trim?.offset,o,0)/100,i=!!t.trim&&(s>0||r<1||a!==0);if(!(i&&Math.abs(r-s)<1e-4)){if(e.beginPath(),i)for(let c of $o(He(n),s,r,a))c.forEach((l,u)=>u?e.lineTo(...l):e.moveTo(...l));else zt(e,n);t.fill&&!i&&t.shape!=="line"&&(e.fillStyle=typeof t.fill=="object"&&("linear"in t.fill||"radial"in t.fill)?Rs(e,t.fill):E(t.fill,o,"#fff"),e.fill(t.fillRule??"nonzero")),t.stroke&&(e.strokeStyle=E(t.stroke,o,"#fff"),e.lineWidth=E(t.strokeWidth,o,4),e.lineCap=t.lineCap??"round",e.lineJoin=t.lineJoin??"round",t.dash&&e.setLineDash(t.dash),e.stroke(),t.dash&&e.setLineDash([]))}},vr=(e,t,n)=>{let o=Hn(t,n),s=t.repeater;if(!s)return wr(e,t,o,n);let r=Math.max(1,Math.round(E(s.copies,n,3))),[a,i]=s.position??[100,0],[c,l]=s.scale??[100,100],[u,d]=s.anchor??[0,0],f=(s.startOpacity??100)/100,p=(s.endOpacity??100)/100,m=e.globalAlpha;for(let h=0;h<r;h++){let b=h+(s.offset??0);e.save(),e.translate(a*b+u,i*b+d),e.rotate((s.rotation??0)*b*Math.PI/180),e.scale(Math.pow(c/100,b),Math.pow(l/100,b)),e.translate(-u,-d),e.globalAlpha=m*(r>1?f+(p-f)*h/(r-1):f),wr(e,t,o,n),e.restore()}};var Fs=new Set(["rgbSplit","glitch","wave"]),rn=e=>{let t=Math.sin(e*12.9898+78.233)*43758.5453;return t-Math.floor(t)},Bn=(e,t,n)=>{let o=t(e.width,e.height),s=o.getContext("2d");return s.drawImage(e,0,0),s.globalCompositeOperation="multiply",s.fillStyle=n,s.fillRect(0,0,o.width,o.height),s.globalCompositeOperation="destination-in",s.drawImage(e,0,0),o},xr=(e,t,n,o,s,r)=>{if(Math.abs(s)+Math.abs(r)<.5){e.drawImage(t,0,0);return}let a=Bn(t,n,"#ff0000"),i=Bn(t,n,"#00ff00"),c=Bn(t,n,"#0000ff");e.save(),e.globalCompositeOperation="lighter",e.drawImage(a,s,r),e.drawImage(i,0,0),e.drawImage(c,-s,-r),e.restore(),[a,i,c].forEach(o)},Jn=(e,t,n,o,s,r,a)=>{let i=n.filter(d=>Fs.has(d.type));if(!i.length)return!1;let c=t,l=[],u=()=>{let d=r(t.width,t.height);return l.push(d),d};for(let d of i){let f=u(),p=f.getContext("2d"),m=t.width,h=t.height;if(d.type==="wave"){let b=E(d.amplitude,o,20),y=d.wavelength??240,v=o*(d.speed??1)*Math.PI*2,k=4;if(Math.abs(b)<.1)p.drawImage(c,0,0);else if((d.direction??"horizontal")==="horizontal")for(let w=0;w<h;w+=k)p.drawImage(c,0,w,m,k,Math.sin(w/y*Math.PI*2+v)*b,w,m,k);else for(let w=0;w<m;w+=k)p.drawImage(c,w,0,k,h,w,Math.sin(w/y*Math.PI*2+v)*b,k,h)}else if(d.type==="glitch"){let b=E(d.amount,o,50)/100,y=Math.floor(o*s/(d.hold??2)),v=(d.seed??1)*1e3+y;if(b<=.001)p.drawImage(c,0,0);else{let k=0,w=0;for(;k<h;){let L=Math.max(4,Math.round((.01+rn(v+w*7.1)*.08)*h)),S=rn(v+w*3.3)<.35+b*.4?(rn(v+w*5.7)-.5)*2*b*m*.08:0;p.drawImage(c,0,k,m,L,S,k,m,L),k+=L,w++}if(d.rgb!==!1){let L=u(),C=L.getContext("2d");xr(C,f,r,a,b*14*(rn(v)>.5?1:-1),0),c=L;continue}}}else if(d.type==="rgbSplit"){let b=E(d.amount,o,10),y=(d.angle??0)*Math.PI/180;xr(p,c,r,a,Math.cos(y)*b,Math.sin(y)*b)}c=f}return e.drawImage(c,0,0),l.forEach(a),!0};var kr=new Set(["curves","colorBalance","exposure","temperature","lut"]),sn=e=>{if(!e||e.length<2)return null;let t=[...e].sort((i,c)=>i[0]-c[0]),n=t.length,o=[],s=[],r=[];for(let i=0;i<n-1;i++)o.push(t[i+1][0]-t[i][0]||1e-6),r.push((t[i+1][1]-t[i][1])/o[i]);s.push(r[0]);for(let i=1;i<n-1;i++)s.push(r[i-1]*r[i]<=0?0:(r[i-1]+r[i])/2);s.push(r[n-2]);let a=new Float32Array(256);for(let i=0;i<256;i++){let c=i/255,l=0;for(;l<n-2&&c>t[l+1][0];)l++;if(c<=t[0][0]){a[i]=t[0][1];continue}if(c>=t[n-1][0]){a[i]=t[n-1][1];continue}let u=o[l],d=(c-t[l][0])/u,f=d*d,p=f*d;a[i]=(2*p-3*f+1)*t[l][1]+(p-2*f+d)*u*s[l]+(-2*p+3*f)*t[l+1][1]+(p-f)*u*s[l+1]}return a},Kn=new Map,Ds=e=>{let t=0,n=[0,0,0],o=[1,1,1],s=[];for(let r of e.split(/\r?\n/)){let a=r.trim();if(!(!a||a.startsWith("#"))){if(/^LUT_3D_SIZE/i.test(a))t=parseInt(a.split(/\s+/)[1]);else if(/^DOMAIN_MIN/i.test(a))n=a.split(/\s+/).slice(1).map(Number);else if(/^DOMAIN_MAX/i.test(a))o=a.split(/\s+/).slice(1).map(Number);else if(/^[-\d.]/.test(a)){let i=a.split(/\s+/).map(Number);i.length>=3&&s.push(i[0],i[1],i[2])}}}if(!t||s.length<t**3*3)throw new Error("Not a 3D .cube LUT");return{size:t,data:Float32Array.from(s),min:n,max:o}},_r=async(e,t)=>{for(let n of e)n.type==="lut"&&!Kn.has(n.src)&&Kn.set(n.src,Ds(await t.loadText(n.src)))},Ws=e=>e<0?0:e>255?255:e,Mr=(e,t,n,o,s)=>{if(!o.length)return;let r=[new Float32Array(256),new Float32Array(256),new Float32Array(256)];for(let p=0;p<3;p++)for(let m=0;m<256;m++)r[p][m]=m/255;let a,i=1;for(let p of o)if(p.type==="exposure"){let m=Math.pow(2,E(p.stops,s,0));for(let h of r)for(let b=0;b<256;b++)h[b]*=m}else if(p.type==="temperature"){let m=E(p.amount,s,0)/100;for(let h=0;h<256;h++)r[0][h]*=1+.18*m,r[1][h]*=1+.03*m,r[2][h]*=1-.2*m}else if(p.type==="colorBalance"){let m=p.shadows??[0,0,0],h=p.midtones??[0,0,0],b=p.highlights??[0,0,0];for(let y=0;y<3;y++)for(let v=0;v<256;v++){let k=r[y][v],w=Math.max(0,1-k*3),L=Math.max(0,k*3-2),C=1-Math.abs(k-.5)*2;r[y][v]=k+m[y]*.25*w+h[y]*.25*C+b[y]*.25*L}}else if(p.type==="curves"){let m=sn(p.master),h=[sn(p.r),sn(p.g),sn(p.b)];for(let b=0;b<3;b++)for(let y=0;y<256;y++){let v=Math.min(1,Math.max(0,r[b][y]));m&&(v=m[Math.round(v*255)]),h[b]&&(v=h[b][Math.round(Math.min(1,Math.max(0,v))*255)]),r[b][y]=v}}else p.type==="lut"&&(a=Kn.get(p.src),i=E(p.intensity,s,100)/100);let c=new Uint8ClampedArray(256),l=new Uint8ClampedArray(256),u=new Uint8ClampedArray(256);for(let p=0;p<256;p++)c[p]=r[0][p]*255,l[p]=r[1][p]*255,u[p]=r[2][p]*255;let d=e.getImageData(0,0,t,n),f=d.data;if(a){let p=a.size,m=p*p,h=a.data,b=(p-1)/255,y=i,v=1-i;for(let k=0;k<f.length;k+=4){if(!f[k+3])continue;let w=c[f[k]],L=l[f[k+1]],C=u[f[k+2]],S=w*b,_=L*b,x=C*b,M=S|0,P=_|0,$=x|0,I=M<p-1?M+1:M,N=P<p-1?P+1:P,O=$<p-1?$+1:$,V=S-M,B=_-P,ge=x-$,ae=(M+P*p+$*m)*3,pe=(I+P*p+$*m)*3,Me=(M+N*p+$*m)*3,Te=(I+N*p+$*m)*3,Ie=(M+P*p+O*m)*3,et=(I+P*p+O*m)*3,Zn=(M+N*p+O*m)*3,Dr=(I+N*p+O*m)*3;for(let ie=0;ie<3;ie++){let Yn=h[ae+ie]+(h[pe+ie]-h[ae+ie])*V,Wr=h[Me+ie]+(h[Te+ie]-h[Me+ie])*V,Qn=h[Ie+ie]+(h[et+ie]-h[Ie+ie])*V,Hr=h[Zn+ie]+(h[Dr+ie]-h[Zn+ie])*V,Br=((Yn+(Wr-Yn)*B)*(1-ge)+(Qn+(Hr-Qn)*B)*ge)*255,Jr=ie===0?w:ie===1?L:C;f[k+ie]=Ws(Br*y+Jr*v)}}}else for(let p=0;p<f.length;p+=4)f[p+3]&&(f[p]=c[f[p]],f[p+1]=l[f[p+1]],f[p+2]=u[f[p+2]]);e.putImageData(d,0,0)},Pr=(e,t,n,o,s=.5,r="#000")=>{if(o<=0)return;let a=Math.hypot(t,n)/2,i=e.createRadialGradient(t/2,n/2,a*(1-s)*.75,t/2,n/2,a);i.addColorStop(0,"rgba(0,0,0,0)"),i.addColorStop(1,r.startsWith("#")&&r.length===7?`${r}${Math.round(Math.min(1,o/100)*255).toString(16).padStart(2,"0")}`:r),e.save(),e.setTransform(1,0,0,1,0,0),e.globalCompositeOperation="source-atop",e.fillStyle=i,e.fillRect(0,0,t,n),e.restore()};var Hs=([e,t],[n,o],[s,r],[a,i])=>{let c=n-s,l=a-s,u=e-n+s-a,d=o-r,f=i-r,p=t-o+r-i,m=0,h=0,b=c*f-l*d;Math.abs(b)>1e-12&&(m=(u*f-l*p)/b,h=(c*p-u*d)/b);let y=n-e+m*n,v=a-e+h*a,k=e,w=o-t+m*o,L=i-t+h*i,C=t;return(S,_)=>{let x=m*S+h*_+1;return[(y*S+v*_+k)/x,(w*S+L*_+C)/x]}},Cr=(e,t,n,o,s,r=16)=>{let a=Hs(...s),i=(c,l,u)=>{let d=a(c[0]/n,c[1]/o),f=a(l[0]/n,l[1]/o),p=a(u[0]/n,u[1]/o),m=(l[0]-c[0])*(u[1]-c[1])-(u[0]-c[0])*(l[1]-c[1]);if(Math.abs(m)<1e-9)return;let h=((f[0]-d[0])*(u[1]-c[1])-(p[0]-d[0])*(l[1]-c[1]))/m,b=((f[1]-d[1])*(u[1]-c[1])-(p[1]-d[1])*(l[1]-c[1]))/m,y=((p[0]-d[0])*(l[0]-c[0])-(f[0]-d[0])*(u[0]-c[0]))/m,v=((p[1]-d[1])*(l[0]-c[0])-(f[1]-d[1])*(u[0]-c[0]))/m,k=d[0]-h*c[0]-y*c[1],w=d[1]-b*c[0]-v*c[1],L=(d[0]+f[0]+p[0])/3,C=(d[1]+f[1]+p[1])/3,S=_=>{let x=_[0]-L,M=_[1]-C,P=Math.hypot(x,M)||1;return[_[0]+x/P*.6,_[1]+M/P*.6]};e.save(),e.beginPath(),e.moveTo(...S(d)),e.lineTo(...S(f)),e.lineTo(...S(p)),e.closePath(),e.clip(),e.transform(h,b,y,v,k,w),e.drawImage(t,0,0),e.restore()};for(let c=0;c<r;c++)for(let l=0;l<r;l++){let u=n*l/r,d=n*(l+1)/r,f=o*c/r,p=o*(c+1)/r;i([u,f],[d,f],[u,p]),i([d,f],[d,p],[u,p])}},Lr=(e,t,n,o,s=0,r=2e3)=>{let a=n*Math.PI/180,i=o*Math.PI/180,c=s*Math.PI/180;return[[-e/2,-t/2],[e/2,-t/2],[e/2,t/2],[-e/2,t/2]].map(([u,d])=>{let f=u*Math.cos(c)-d*Math.sin(c),p=u*Math.sin(c)+d*Math.cos(c),m=0,h=p*Math.cos(a)-m*Math.sin(a),b=p*Math.sin(a)+m*Math.cos(a);p=h,m=b;let y=f*Math.cos(i)+m*Math.sin(i),v=-f*Math.sin(i)+m*Math.cos(i);f=y,m=v;let k=r/(r+m);return[f*k+e/2,p*k+t/2]})};var an=[1,0,0,1,0,0],_e=(e,t)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]],ze=(e,t,n)=>[e[0]*t+e[2]*n+e[4],e[1]*t+e[3]*n+e[5]],kt=(e,t=0)=>Array.isArray(e)?e[0]??t:e??t,_t=(e,t,n)=>typeof e=="number"?e+(t-e)*n:Array.isArray(e)?e.map((o,s)=>_t(o,t?.[s]??o,n)):e&&typeof e=="object"&&e.v?{c:e.c,i:_t(e.i,t.i,n),o:_t(e.o,t.o,n),v:_t(e.v,t.v,n)}:n<1?e:t,it=(e,t)=>{if(!e)return;let n=e.k;if(!(e.a===1||Array.isArray(n)&&n.length&&typeof n[0]=="object"&&n[0]!==null&&"t"in n[0]))return n;let s=n;if(t<=s[0].t)return s[0].s??s[0].e;let r=0;for(;r<s.length-1&&t>=s[r+1].t;)r++;let a=s[r],i=s[r+1];if(!i||a.s===void 0)return a.s??s[r-1]?.e??s[r-1]?.s;let c=a.s,l=a.e??i.s;if(a.h===1||l===void 0)return c;let u=(t-a.t)/(i.t-a.t),d=kt(a.o?.x,0),f=kt(a.o?.y,0),p=kt(a.i?.x,1),m=kt(a.i?.y,1),h=Ne([d,f,p,m],Math.max(0,Math.min(1,u)));if(a.to&&a.ti&&Array.isArray(c)&&c.length>=2&&(a.to.some(b=>b)||a.ti.some(b=>b))){let b=c.map((k,w)=>k+(a.to[w]??0)),y=l.map((k,w)=>k+(a.ti[w]??0)),v=1-h;return c.map((k,w)=>v*v*v*k+3*v*v*h*b[w]+3*v*h*h*y[w]+h*h*h*l[w])}return _t(c,l,h)},K=(e,t,n=0)=>{let o=it(e,t);return o===void 0?n:kt(o,n)},ve=(e,t,n)=>{let o=it(e,t);return o===void 0?n:Array.isArray(o)?o:[o,o]},cn=(e,t)=>{let n=(e[0]??0)>1||(e[1]??0)>1||(e[2]??0)>1||(e[3]??0)>1?.00392156862745098:1;return`rgba(${Math.round((e[0]??0)*n*255)},${Math.round((e[1]??0)*n*255)},${Math.round((e[2]??0)*n*255)},${Math.max(0,Math.min(1,(e[3]??1/n)*n*t)).toFixed(4)})`},Un=(e,t)=>{if(!e)return an;let n=ve(e.a,t,[0,0]),o;e.p?.s?o=[K(e.p.x,t),K(e.p.y,t)]:o=ve(e.p,t,[0,0]);let s=ve(e.s,t,[100,100]),r=(e.r?K(e.r,t):K(e.rz,t))*Math.PI/180,a=K(e.sk,t)*Math.PI/180,i=K(e.sa,t)*Math.PI/180,c=[1,0,0,1,o[0]??0,o[1]??0];if(c=_e(c,[Math.cos(r),Math.sin(r),-Math.sin(r),Math.cos(r),0,0]),a){let l=Math.cos(i),u=Math.sin(i);c=_e(c,_e(_e([l,u,-u,l,0,0],[1,0,Math.tan(-a),1,0,0]),[l,-u,u,l,0,0]))}return c=_e(c,[(s[0]??100)/100,0,0,(s[1]??100)/100,0,0]),_e(c,[1,0,0,1,-(n[0]??0),-(n[1]??0)])},$r=(e,t)=>e?.o?K(e.o,t,100)/100:1,Mt=(e,t,n=!1)=>{if(Array.isArray(e)&&(e=e[0]),!e?.v?.length)return{subs:[]};let o=e.v,s=e.i??[],r=e.o??[];if(n){o=[...o].reverse();let u=[...r].reverse(),d=[...s].reverse();s=u,r=d}let a=o.length,i=[],c=u=>ze(t,o[u][0],o[u][1]),l=e.c?a:a-1;for(let u=0;u<l;u++){let d=(u+1)%a,f=ze(t,o[u][0]+(r[u]?.[0]??0),o[u][1]+(r[u]?.[1]??0)),p=ze(t,o[d][0]+(s[d]?.[0]??0),o[d][1]+(s[d]?.[1]??0)),m=c(d);i.push([f[0],f[1],p[0],p[1],m[0],m[1]])}return{subs:[{start:c(0),cubics:i,closed:!!e.c}]}},Ve=.5522847498,Bs=(e,t,n)=>{let[o,s]=ve(e.p,t,[0,0]),[r,a]=ve(e.s,t,[0,0]),i=r/2,c=a/2,l={c:!0,v:[[o,s-c],[o+i,s],[o,s+c],[o-i,s]],o:[[i*Ve,0],[0,c*Ve],[-i*Ve,0],[0,-c*Ve]],i:[[-i*Ve,0],[0,-c*Ve],[i*Ve,0],[0,c*Ve]]};return Mt(l,n,e.d===3)},Js=(e,t,n)=>{let[o,s]=ve(e.p,t,[0,0]),[r,a]=ve(e.s,t,[0,0]),i=Math.min(K(e.r,t),r/2,a/2),c=o-r/2,l=s-a/2,u=i*Ve,d=i>0?{c:!0,v:[[c+r,l+i],[c+r,l+a-i],[c+r-i,l+a],[c+i,l+a],[c,l+a-i],[c,l+i],[c+i,l],[c+r-i,l]],i:[[0,-u],[0,0],[u,0],[0,0],[0,u],[0,0],[-u,0],[0,0]],o:[[0,0],[0,u],[0,0],[-u,0],[0,0],[0,-u],[0,0],[u,0]]}:{c:!0,v:[[c+r,l],[c+r,l+a],[c,l+a],[c,l]],i:[[0,0],[0,0],[0,0],[0,0]],o:[[0,0],[0,0],[0,0],[0,0]]};return Mt(d,n,e.d===3)},Ks=(e,t,n)=>{let o=Math.max(3,Math.round(K(e.pt,t,5))),[s,r]=ve(e.p,t,[0,0]),a=(K(e.r,t)-90)*Math.PI/180,i=K(e.or,t,100),c=K(e.ir,t,50),l=e.sy===1?o*2:o,u=[];for(let d=0;d<l;d++){let f=e.sy===1&&d%2?c:i,p=a+d/l*Math.PI*2;u.push([s+Math.cos(p)*f,r+Math.sin(p)*f])}return Mt({c:!0,v:u,i:u.map(()=>[0,0]),o:u.map(()=>[0,0])},n,e.d===3)},Er=(e,t)=>{for(let n of t.subs){e.moveTo(...n.start);for(let o of n.cubics)e.bezierCurveTo(o[0],o[1],o[2],o[3],o[4],o[5]);n.closed&&e.closePath()}},Us=(e,t,n,o)=>{let s=e.subs.map(f=>{let p=[f.start],m=f.start;for(let h of f.cubics){for(let y=1;y<=24;y++){let v=y/24,k=1-v;p.push([k*k*k*m[0]+3*k*k*v*h[0]+3*k*v*v*h[2]+v*v*v*h[4],k*k*k*m[1]+3*k*k*v*h[1]+3*k*v*v*h[3]+v*v*v*h[5]])}m=[h[4],h[5]]}return p}),a=s.map(f=>f.slice(1).reduce((p,m,h)=>p+Math.hypot(m[0]-f[h][0],m[1]-f[h][1]),0)).reduce((f,p)=>f+p,0);if(!a)return{subs:[]};let i=Math.min(t,n)+o,c=Math.max(t,n)+o,l=Math.floor(i);i-=l,c-=l;let u=c<=1?[[i,c]]:[[i,1],[0,c-1]],d={subs:[]};for(let[f,p]of u){let m=f*a,h=p*a,b=0;s.forEach(y=>{let v=null;for(let k=0;k<y.length-1;k++){let w=y[k],L=y[k+1],C=Math.hypot(L[0]-w[0],L[1]-w[1]),S=b,_=b+C;if(b=_,_<m||S>h||!C)continue;let x=M=>{let P=(M-S)/C;return[w[0]+(L[0]-w[0])*P,w[1]+(L[1]-w[1])*P]};v||(v=[x(Math.max(m,S))]),v.push(x(Math.min(h,_)))}v&&v.length>1&&d.subs.push({start:v[0],cubics:v.slice(1).map((k,w)=>{let L=v[w];return[L[0],L[1],k[0],k[1],k[0],k[1]]}),closed:!1})})}return d},Sr=(e,t,n,o,s)=>{let r=ve(t.s,n,[0,0]),a=ve(t.e,n,[0,0]),[i,c]=ze(o,r[0],r[1]),[l,u]=ze(o,a[0],a[1]),d=t.t===2?e.createRadialGradient(i,c,0,i,c,Math.hypot(l-i,u-c)):e.createLinearGradient(i,c,l,u),f=t.g?.p??0,p=it(t.g?.k,n)??[],m=h=>{let b=p.slice(f*4);if(b.length<2)return 1;for(let y=0;y<b.length-2;y+=2)if(h>=b[y]&&h<=b[y+2]){let v=(h-b[y])/(b[y+2]-b[y]||1);return b[y+1]+(b[y+3]-b[y+1])*v}return h<b[0]?b[1]:b[b.length-1]};for(let h=0;h<f;h++){let b=p[h*4];d.addColorStop(Math.max(0,Math.min(1,b)),cn([p[h*4+1],p[h*4+2],p[h*4+3],m(b)],s))}return d},Gs=(e,t,n)=>{for(let o=t.length-1;o>=0;o--){let{kind:s,it:r,geos:a,alpha:i,m:c}=t[o];if(!a.length||r.hd)continue;e.beginPath();for(let u of a)Er(e,u);let l=K(r.o,n,100)/100*i;if(s==="fill")e.fillStyle=r.ty==="gf"?Sr(e,r,n,c,l):cn(ve(r.c,n,[0,0,0,1]),l),e.fill(r.r===2?"evenodd":"nonzero");else{if(e.strokeStyle=r.ty==="gs"?Sr(e,r,n,c,l):cn(ve(r.c,n,[0,0,0,1]),l),e.lineWidth=K(r.w,n,1)*(Gn.get(r)??1),e.lineCap=["butt","butt","round","square"][r.lc??2]??"round",e.lineJoin=["miter","miter","round","bevel"][r.lj??2]??"round",e.miterLimit=r.ml??4,r.d?.length){let u=r.d.filter(f=>f.n!=="o").map(f=>K(f.v,n)*(Gn.get(r)??1));e.setLineDash(u);let d=r.d.find(f=>f.n==="o");e.lineDashOffset=d?K(d.v,n):0}e.stroke(),e.setLineDash([])}}},Gn=new WeakMap,Tr=(e,t,n,o,s,r)=>{let a=e.find(f=>f.ty==="tr"),i=a?_e(n,Un(a,t)):n,c=o*(a?$r(a,t):1),l=Math.sqrt(Math.abs(i[0]*i[3]-i[1]*i[2])),u=[],d=[];for(let f of e)if(!f.hd)switch(f.ty){case"sh":u.push(Mt(it(f.ks,t),i,f.d===3));break;case"el":u.push(Bs(f,t,i));break;case"rc":u.push(Js(f,t,i));break;case"sr":u.push(Ks(f,t,i));break;case"gr":Tr(f.it??[],t,i,c,d,u);break;case"fl":case"gf":d.push({kind:"fill",it:f,geos:[...u],alpha:c,m:i});break;case"st":case"gs":Gn.set(f,l),d.push({kind:"stroke",it:f,geos:[...u],alpha:c,m:i});break;case"tm":{let p=K(f.s,t)/100,m=K(f.e,t,100)/100,h=K(f.o,t)/360,b=u.map(y=>Us(y,p,m,h));u.splice(0,u.length,...b);break}case"rp":{let p=Math.round(K(f.c,t,1)),m=K(f.o,t),h=f.tr,b=[...u],y=h?.so?K(h.so,t,100)/100:1,v=h?.eo?K(h.eo,t,100)/100:1;u.length=0;let k=Un(h,t);for(let w=0;w<p;w++){let L=an;for(let _=0;_<w+m;_++)L=_e(L,k);let C=qs(i),S=C?_e(i,_e(L,C)):an;for(let _ of b)u.push({subs:_.subs.map(x=>({start:ze(S,...x.start),cubics:x.cubics.map(M=>{let P=ze(S,M[0],M[1]),$=ze(S,M[2],M[3]),I=ze(S,M[4],M[5]);return[P[0],P[1],$[0],$[1],I[0],I[1]]}),closed:x.closed}))})}break}default:break}s.push(...d),r.push(...u)},qs=e=>{let t=e[0]*e[3]-e[1]*e[2];return Math.abs(t)<1e-12?null:[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[3]*e[4])/t,(e[1]*e[4]-e[0]*e[5])/t]},ln=class{constructor(t,n){this.data=t;this.host=n;this.w=t.w,this.h=t.h,this.fr=t.fr||30,this.ip=t.ip??0,this.op=t.op??60;for(let o of t.assets??[])this.assets.set(o.id,o)}data;host;w;h;fr;ip;op;assets=new Map;images=new Map;pool=[];get duration(){return(this.op-this.ip)/this.fr}async preload(){for(let t of this.data.assets??[]){if(!t.p||t.layers)continue;let n=t.e===1||String(t.p).startsWith("data:")?t.p:`${t.u??""}${t.p}`;try{this.images.set(t.id,await this.host.image(n))}catch{}}}buf(t,n){let o=this.pool.find(s=>s.width===t&&s.height===n);if(o){this.pool.splice(this.pool.indexOf(o),1);let s=o.getContext("2d");return s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,t,n),o}return this.host.createCanvas(t,n)}release(t){this.pool.length<8&&this.pool.push(t)}draw(t,n){this.drawLayers(t,this.data.layers??[],n,this.w,this.h)}layerMatrix(t,n,o,s=0){let r=Un(t.ks,o);if(t.parent!==void 0&&s<30){let a=n.get(t.parent);a&&(r=_e(this.layerMatrix(a,n,o,s+1),r))}return r}drawLayers(t,n,o,s,r){let a=new Map;for(let c of n)c.ind!==void 0&&a.set(c.ind,c);let i=t.getTransform();for(let c=n.length-1;c>=0;c--){let l=n[c];if(l.td||l.hd||o<(l.ip??-1/0)||o>=(l.op??1/0))continue;let u=l.tt?n[c-1]:null;if(!l.masksProperties?.length&&!u){t.save(),this.drawLayer(t,l,a,o,i),t.restore();continue}let d=t.canvas.width,f=t.canvas.height,p=this.buf(d,f),m=p.getContext("2d");if(m.setTransform(i),this.drawLayer(m,l,a,o,i),l.masksProperties?.length&&this.applyMasks(m,l,a,o,i,d,f),u){let h=this.buf(d,f),b=h.getContext("2d");b.setTransform(i),this.drawLayer(b,u,a,o,i),(l.tt===3||l.tt===4)&&Xs(b,d,f,l.tt===4),m.setTransform(1,0,0,1,0,0),m.globalCompositeOperation=l.tt===2?"destination-out":"destination-in",m.drawImage(h,0,0),this.release(h)}t.save(),t.setTransform(1,0,0,1,0,0),t.drawImage(p,0,0),t.restore(),this.release(p)}}applyMasks(t,n,o,s,r,a,i){let c=this.layerMatrix(n,o,s),l=this.buf(a,i),u=l.getContext("2d"),d=n.masksProperties.filter(f=>f.mode!=="n");if(!d.length){this.release(l);return}d[0].mode==="s"&&(u.fillStyle="#000",u.fillRect(0,0,a,i));for(let f of d){u.setTransform(r),u.transform(...c),u.beginPath(),Er(u,Mt(it(f.pt,s),an));let p=K(f.o,s,100)/100;u.fillStyle=`rgba(0,0,0,${p})`,f.inv&&u.rect(-1e5,-1e5,2e5,2e5),u.globalCompositeOperation=f.mode==="s"?"destination-out":f.mode==="i"?"destination-in":"source-over",u.fill(f.inv?"evenodd":"nonzero")}t.save(),t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation="destination-in",t.drawImage(l,0,0),t.restore(),this.release(l)}drawLayer(t,n,o,s,r){let a=this.layerMatrix(n,o,s),i=$r(n.ks,s);if(i<=0)return;t.setTransform(r),t.globalAlpha*=i;let c=(s-(n.st??0))/(n.sr??1);switch(n.ty){case 4:{let l=[];Tr(n.shapes??[],c,a,1,l,[]),t.setTransform(r),Gs(t,l,c);break}case 1:{t.transform(...a),t.fillStyle=n.sc??"#000",t.fillRect(0,0,n.sw??0,n.sh??0);break}case 2:{let l=this.images.get(n.refId);l&&(t.transform(...a),t.drawImage(l,0,0));break}case 0:{let l=this.assets.get(n.refId);if(!l?.layers)break;t.transform(...a),t.beginPath(),t.rect(0,0,n.w??this.w,n.h??this.h),t.clip();let u=n.tm?K(n.tm,c)*this.fr:c;this.drawLayers(t,l.layers,u,n.w,n.h);break}case 5:{let l=it(n.t?.d,c),u=l?.t!==void 0&&typeof l.t=="string"?l:l?.s??n.t?.d?.k?.[0]?.s;if(!u?.t)break;t.transform(...a);let d=(this.data.fonts?.list??[]).find(p=>p.fName===u.f);t.font=`${d?.fWeight??(/bold/i.test(u.f??"")?700:400)} ${u.s??24}px "${d?.fFamily??"Mukta"}", "Baloo 2", sans-serif`,t.fillStyle=cn(u.fc??[0,0,0],1),t.textAlign=["left","right","center"][u.j??0]??"left","letterSpacing"in t&&(t.letterSpacing=`${(u.tr??0)/1e3*(u.s??24)}px`);let f=u.lh??(u.s??24)*1.2;String(u.t).split(/\r|\n/).forEach((p,m)=>t.fillText(p,0,m*f));break}default:break}}},Xs=(e,t,n,o)=>{let s=e.getImageData(0,0,t,n),r=s.data;for(let a=0;a<r.length;a+=4){let i=(.299*r[a]+.587*r[a+1]+.114*r[a+2])/255*(r[a+3]/255);r[a+3]=Math.round((o?1-i:i)*255)}e.putImageData(s,0,0)};var Pt=(e,t)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]],Ir={normal:"source-over",multiply:"multiply",screen:"screen",overlay:"overlay",add:"lighter",darken:"darken",lighten:"lighten",softLight:"soft-light",difference:"difference"},pn=class{constructor(t,n){this.project=t;this.host=n}project;host;pool=new Map;comp(t){let n=this.project.comps.find(o=>o.id===t);if(!n)throw new Error(`Unknown composition "${t}"`);return n}acquire(t,n){let s=this.pool.get(`${t}x${n}`)?.pop()??this.host.createCanvas(t,n),r=s.getContext("2d");return r.setTransform(1,0,0,1,0,0),r.globalCompositeOperation="source-over",r.globalAlpha=1,r.filter="none",r.shadowColor="transparent",r.shadowBlur=0,r.shadowOffsetX=0,r.shadowOffsetY=0,r.setLineDash([]),r.clearRect(0,0,t,n),s}release(t){let n=`${t.width}x${t.height}`;this.pool.has(n)||this.pool.set(n,[]),this.pool.get(n).push(t)}layerSize(t,n,o){switch(t.type){case"solid":return t.size??[n.width,n.height];case"image":case"video":return t.size??[n.width,n.height];case"precomp":{let s=this.comp(t.comp);return[s.width,s.height]}case"lottie":{let s=this.lotties.get(t.src);return t.size??(s?[s.w,s.h]:[n.width,n.width])}default:return[0,0]}}matrix(t,n,o,s=0){let r=t.transform??{},a=this.layerSize(t,n,o),i=E(r.anchor,o,[a[0]/2,a[1]/2]),c=E(r.position,o,[n.width/2,n.height/2]),[l,u]=E(r.scale,o,[100,100]),d=E(r.rotation,o,0)*Math.PI/180,f=Math.tan(E(r.skew,o,0)*Math.PI/180),p=Math.cos(d),m=Math.sin(d),h=[1,0,0,1,c[0],c[1]];if(h=Pt(h,[p,m,-m,p,0,0]),h=Pt(h,[1,0,f,1,0,0]),h=Pt(h,[l/100,0,0,u/100,0,0]),h=Pt(h,[1,0,0,1,-i[0],-i[1]]),t.parent&&s<20){let b=n.layers.find(y=>y.id===t.parent);b&&(h=Pt(this.matrix(b,n,o,s+1),h))}return h}lotties=new Map;async preload(t){for(let n of t.layers){if(n.type==="lottie"&&!this.lotties.has(n.src)){let o=new ln(JSON.parse(await this.host.data(n.src)),this.host);await o.preload(),this.lotties.set(n.src,o)}n.type==="precomp"&&await this.preload(this.comp(n.comp)),n.effects?.some(o=>o.type==="lut")&&await _r(n.effects,{loadText:o=>this.host.data(o)})}}async renderComp(t,n,o,s=!0){await this.preload(n),s&&n.background&&(t.save(),t.setTransform(1,0,0,1,0,0),t.fillStyle=n.background,t.fillRect(0,0,n.width,n.height),t.restore());let r=new Set(n.layers.map(a=>a.matte?.layer).filter(Boolean));for(let a=n.layers.length-1;a>=0;a--){let i=n.layers[a];if(!(i.hidden||i.type==="audio"||i.type==="null")&&!r.has(i.id)){if(i.type==="adjustment"){this.renderAdjustment(t,i,n,o);continue}await this.renderLayer(t,i,n,o)}}}isActive(t,n,o){return o>=(t.inPoint??0)&&o<(t.outPoint??n.duration)}async renderLayer(t,n,o,s){if(!this.isActive(n,o,s))return;let r=n.transform??{},a=E(r.opacity,s,100)/100;if(a<=0)return;let i=n.type==="video"?this.host.bakedVideoEffects?.(n):void 0,c=(n.effects??[]).filter(m=>!i?.has(m));if(!n.masks?.length&&!n.matte&&!n.motionBlur&&c.every(m=>Zs.has(m.type))){t.save(),t.globalAlpha*=a,t.globalCompositeOperation=Ir[n.blendMode??"normal"];let m=qn(c,s);m&&(t.filter=m),this.applyShadow(t,c,s),t.setTransform(...this.matrix(n,o,s)),await this.drawContent(t,n,o,s),t.restore();return}let u=this.acquire(o.width,o.height),d=u.getContext("2d");if(n.motionBlur){let m=Math.max(2,n.motionBlur.samples??8),h=(n.motionBlur.shutter??180)/360/o.fps;for(let b=0;b<m;b++){let y=s-h/2+h*b/(m-1);d.save(),d.globalAlpha=1/(b+1),d.setTransform(...this.matrix(n,o,y)),await this.drawContent(d,n,o,y),d.restore()}}else if(c.some(m=>m.type==="cornerPin"||m.type==="tilt")){let[m,h]=this.layerSize(n,o,s);if(m>0&&h>0){let b=this.acquire(Math.ceil(m),Math.ceil(h));await this.drawContent(b.getContext("2d"),n,o,s);let y=c.find(w=>w.type==="cornerPin"),v=c.find(w=>w.type==="tilt"),k=y?E(y.corners,s,[[0,0],[m,0],[m,h],[0,h]]):Lr(m,h,E(v.rotateX,s,0),E(v.rotateY,s,0),E(v.rotateZ,s,0),v.perspective??Math.max(m,h)*2);d.save(),d.setTransform(...this.matrix(n,o,s)),Cr(d,b,m,h,k),d.restore(),this.release(b)}}else d.save(),d.setTransform(...this.matrix(n,o,s)),await this.drawContent(d,n,o,s),d.restore();n.masks?.length&&this.applyMasks(d,n,o,s);for(let m of c)m.type==="fill"&&(d.save(),d.globalCompositeOperation="source-in",d.globalAlpha=E(m.opacity,s,100)/100,d.fillStyle=m.color,d.fillRect(0,0,o.width,o.height),d.restore());if(this.grade(d,c,o,s),n.matte){let m=o.layers.find(h=>h.id===n.matte.layer);if(m){let h=this.acquire(o.width,o.height);await this.renderLayer(h.getContext("2d"),{...m,hidden:!1,matte:void 0},o,s),d.save(),d.globalCompositeOperation=n.matte.mode==="alphaInverted"?"destination-out":"destination-in",d.drawImage(h,0,0),d.restore(),this.release(h)}}t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha*=a,t.globalCompositeOperation=Ir[n.blendMode??"normal"];let f=qn(c,s);f&&(t.filter=f),this.applyShadow(t,c,s);let p=c.find(m=>m.type==="glow");if(p){let m=E(p.strength,s,100)/100;if(t.save(),t.shadowColor="transparent",t.filter=`blur(${E(p.radius,s,24)}px)`,t.globalCompositeOperation="lighter",t.globalAlpha*=m,p.color){let h=this.acquire(o.width,o.height),b=h.getContext("2d");b.drawImage(u,0,0),b.globalCompositeOperation="source-in",b.fillStyle=p.color,b.fillRect(0,0,o.width,o.height),t.drawImage(h,0,0),this.release(h)}else t.drawImage(u,0,0);t.restore()}Jn(t,u,c,s,o.fps,(m,h)=>this.acquire(m,h),m=>this.release(m))||t.drawImage(u,0,0),t.restore(),this.release(u)}applyMasks(t,n,o,s){let r=n.masks??[],a=this.matrix(n,o,s),i=this.acquire(o.width,o.height),c=i.getContext("2d");r.forEach((l,u)=>{if(c.save(),u===0&&l.inverted&&(c.fillStyle="#000",c.fillRect(0,0,o.width,o.height)),c.setTransform(...a),c.globalCompositeOperation=l.inverted?"destination-out":"source-over",c.beginPath(),l.shape==="path"&&l.points?.length)l.points.forEach(([d,f],p)=>p?c.lineTo(d,f):c.moveTo(d,f)),c.closePath();else if(l.shape==="path"&&l.path)zt(c,ue(E(l.path,s,"")));else{let[d,f,p,m]=E(l.rect,s,[0,0,0,0]);Math.abs(p)>.01&&Math.abs(m)>.01&&(l.shape==="ellipse"?c.ellipse(d+p/2,f+m/2,Math.abs(p/2),Math.abs(m/2),0,0,Math.PI*2):c.roundRect(d,f,p,m,l.radius??0))}c.fillStyle="#000",c.fill(),c.restore()}),t.save(),t.setTransform(1,0,0,1,0,0),t.globalCompositeOperation="destination-in",t.drawImage(i,0,0),t.restore(),this.release(i)}grade(t,n,o,s){let r=n.filter(a=>kr.has(a.type));r.length&&Mr(t,o.width,o.height,r,s);for(let a of n)a.type==="vignette"&&Pr(t,o.width,o.height,E(a.amount,s,50),a.softness,a.color)}renderAdjustment(t,n,o,s){if(!this.isActive(n,o,s))return;let r=E(n.transform?.opacity,s,100)/100,a=n.effects??[];if(r<=0||!a.length)return;let i=o.width,c=o.height,l=this.acquire(i,c),u=l.getContext("2d"),d=qn(a,s);d&&(u.filter=d),u.drawImage(t.canvas,0,0),u.filter="none",this.grade(u,a,o,s),n.masks?.length&&this.applyMasks(u,n,o,s),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha*=r,Jn(t,l,a,s,o.fps,(f,p)=>this.acquire(f,p),f=>this.release(f))||t.drawImage(l,0,0),t.restore(),this.release(l)}applyShadow(t,n,o){let s=n.find(c=>c.type==="dropShadow");if(!s)return;let r=E(s.distance,o,8),a=(s.angle??135)*Math.PI/180,i=ke(s.color??"#000")??[0,0,0,1];t.shadowColor=Oe([i[0],i[1],i[2],i[3]*(E(s.opacity,o,60)/100)]),t.shadowBlur=E(s.blur,o,16),t.shadowOffsetX=Math.sin(a)*r,t.shadowOffsetY=-Math.cos(a)*r}async drawContent(t,n,o,s){let r=n.inPoint??0;switch(n.type){case"solid":{let[a,i]=n.size??[o.width,o.height];t.fillStyle=E(n.color,s,"#000"),t.fillRect(0,0,a,i);return}case"shape":return vr(t,n,s);case"text":return yr(t,n,s,r,n.outPoint??o.duration,this.project.fonts?Object.keys(this.project.fonts)[0]??this.host.defaultFont:this.host.defaultFont);case"image":{let a=await this.host.image(n.src),[i,c]=n.size??[o.width,o.height];Ys(t,a,i,c,n.fit??"cover");return}case"video":{let[a,i]=n.size??[o.width,o.height],c=(n.trimIn??0)+(s-r)*(n.speed??1),l=await this.host.videoFrame(n,c,a,i,o.fps);t.drawImage(l,0,0,a,i);return}case"lottie":{let a=this.lotties.get(n.src);if(!a)return;let[i,c]=n.size??[a.w,a.h],l=Math.min(i/a.w,c/a.h),[u,d]=n.frames??[a.ip,a.op],f=Math.max(1,d-u),p=((s-r)*(n.speed??1)+(n.timeOffset??0))*a.fr;p=n.loop===!1?Math.min(p,f-.001):(p%f+f)%f,t.save(),t.translate((i-a.w*l)/2,(c-a.h*l)/2),t.scale(l,l),a.draw(t,u+p),t.restore();return}case"precomp":{let a=this.comp(n.comp),i=(s-r)*(n.speed??1)+(n.timeOffset??0),c=this.acquire(a.width,a.height);await this.renderComp(c.getContext("2d"),a,i,!0),t.drawImage(c,0,0),this.release(c);return}}}},Zs=new Set(["blur","brightness","saturate","contrast","dropShadow"]),qn=(e,t)=>e.map(n=>{if(n.type==="blur"){let o=E(n.radius,t,0);return o>.05?`blur(${o}px)`:""}return n.type==="brightness"?`brightness(${E(n.amount,t,100)}%)`:n.type==="saturate"?`saturate(${E(n.amount,t,100)}%)`:n.type==="contrast"?`contrast(${E(n.amount,t,100)}%)`:""}).filter(Boolean).join(" "),Ys=(e,t,n,o,s)=>{if(s==="fill")return e.drawImage(t,0,0,n,o);let r=s==="cover"?Math.max(n/t.width,o/t.height):Math.min(n/t.width,o/t.height),a=t.width*r,i=t.height*r;e.save(),e.beginPath(),e.rect(0,0,n,o),e.clip(),e.drawImage(t,(n-a)/2,(o-i)/2,a,i),e.restore()};var Ct=(e,[t,n])=>[e[0]*t+e[2]*n+e[4],e[1]*t+e[3]*n+e[5]],Qs=e=>{let t=e[0]*e[3]-e[1]*e[2];return Math.abs(t)<1e-9?null:[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[3]*e[4])/t,(e[1]*e[4]-e[0]*e[5])/t]},Or=(e,t,n,o,s)=>{switch(e.type){case"solid":case"image":case"video":case"precomp":{let[r,a]=o.layerSize(e,t,n);return[0,0,r,a]}case"shape":{let r=Rt(Hn(e,n));if(!r)return null;let a=e.stroke?E(e.strokeWidth,n,4)/2+2:0;return[r[0]-a,r[1]-a,r[2]+a*2,r[3]+a*2]}case"text":{let r=E(e.size,n,72),a=Dn(s,{...e,text:Wn(e,n)},r,E(e.tracking,n,0),Fn(e,r,o.host.defaultFont));return[Math.min(...a.lines.map(c=>c.x)),a.top,a.width,a.height]}default:return null}},Nr=(e,t,n,o,s)=>{let r=Or(e,t,n,o,s);if(!r)return null;let a=o.matrix(e,t,n),[i,c,l,u]=r;return[Ct(a,[i,c]),Ct(a,[i+l,c]),Ct(a,[i+l,c+u]),Ct(a,[i,c+u])]},Ar=(e,t,n,o,s)=>{for(let r of t.layers){if(r.hidden||r.type==="audio"||r.type==="null"||r.type==="adjustment"||!o.isActive(r,t,n))continue;let a=Or(r,t,n,o,s),i=Qs(o.matrix(r,t,n));if(!a||!i)continue;let[c,l]=Ct(i,e);if(c>=a[0]&&c<=a[0]+a[2]&&l>=a[1]&&l<=a[1]+a[3])return r.id}return null};var Lt=new Yt,Re=null,ct=document.createElement("canvas"),jr=()=>{let e=j(_=>_.project),t=j(_=>_.time),n=j(_=>_.comp),o=j(_=>_.layer),s=j(_=>_.playing),r=xe(null),a=xe(null),i=xe(null),[c,l]=le({w:400,h:600}),[u,d]=le(0),f=xe(!1),p=xe(!1),m=e?.comps.find(_=>_.id===n);Pe(()=>{let _=r.current;if(!_)return;let x=new ResizeObserver(()=>l({w:_.clientWidth-24,h:_.clientHeight-24}));return x.observe(_),()=>x.disconnect()},[]);let h=m?Math.min(c.w/m.width,c.h/m.height):1,b=async()=>{if(f.current){p.current=!0;return}let _=A(),x=ce();if(!(!_.project||!x||!a.current)){f.current=!0;try{Re||(Re=new pn(_.project,Lt)),Re.project=_.project,Lt.playing=_.playing;let M=a.current;(ct.width!==x.width||ct.height!==x.height)&&(ct.width=x.width,ct.height=x.height);let P=ct.getContext("2d"),$=performance.now();P.setTransform(1,0,0,1,0,0),P.clearRect(0,0,x.width,x.height),x.background||(P.fillStyle="#000",P.fillRect(0,0,x.width,x.height)),await Re.renderComp(P,x,_.time),Lt.endFrame(),(M.width!==x.width||M.height!==x.height)&&(M.width=x.width,M.height=x.height),M.getContext("2d").drawImage(ct,0,0),M.dataset.time=String(_.time),d(performance.now()-$),y()}catch(M){T({message:`Preview error: ${M.message}`})}finally{f.current=!1,p.current&&(p.current=!1,b())}}},y=()=>{let _=A(),x=ce(),M=i.current;if(!M||!x||!Re)return;(M.width!==x.width||M.height!==x.height)&&(M.width=x.width,M.height=x.height);let P=M.getContext("2d");P.clearRect(0,0,M.width,M.height);let $=x.layers.find(B=>B.id===_.layer);if(!$||_.playing||!Re.isActive($,x,_.time))return;let I=Nr($,x,_.time,Re,P),N=2/h;P.strokeStyle="#4da3ff",P.lineWidth=N,I&&(P.beginPath(),I.forEach((B,ge)=>ge?P.lineTo(...B):P.moveTo(...B)),P.closePath(),P.stroke());let[O,V]=E($.transform?.position,_.time,[x.width/2,x.height/2]);P.beginPath(),P.arc(O,V,6/h,0,Math.PI*2),P.moveTo(O-12/h,V),P.lineTo(O+12/h,V),P.moveTo(O,V-12/h),P.lineTo(O,V+12/h),P.stroke()};Pe(()=>{b()},[e,t,n,s]),Pe(()=>{y()},[o,h]);let v=_=>{let x=i.current.getBoundingClientRect();return[(_.clientX-x.left)/x.width*m.width,(_.clientY-x.top)/x.height*m.height]},k=xe(null),w=_=>{if(!m||!Re)return;let x=v(_),M=A(),P=i.current.getContext("2d"),$=Ar(x,m,M.time,Re,P);if(T({layer:$,key:null}),!$)return;let I=m.layers.find(N=>N.id===$);_.target.setPointerCapture(_.pointerId),k.current={start:x,pos:E(I.transform?.position,M.time,[m.width/2,m.height/2]),layer:$,moved:!1}},L=_=>{let x=k.current;if(!x||!m)return;let M=v(_),P=M[0]-x.start[0],$=M[1]-x.start[1];if(!x.moved&&Math.hypot(P,$)*h<3)return;x.moved||(x.moved=!0,$e());let I=Y(A().time,m.fps),N=[Math.round(x.pos[0]+P),Math.round(x.pos[1]+(_.shiftKey?0:$))];Ae(O=>{let V=O.comps.find(B=>B.id===m.id).layers.find(B=>B.id===x.layer);be(V.transform?.position)?q(O,x.layer,"transform.position",I,N):dt(O,x.layer,"transform.position",N)})},C=()=>{k.current?.moved&&Ee(),k.current=null};if(!m)return g("div",{class:"viewer",ref:r});let S={width:`${m.width*h}px`,height:`${m.height*h}px`};return g("div",{class:"viewer",ref:r,children:[g("div",{class:"stage",style:S,children:[g("canvas",{ref:a,class:"frame",style:S}),g("canvas",{ref:i,class:"overlay",style:S,onPointerDown:w,onPointerMove:L,onPointerUp:C})]}),g("div",{class:"viewer-info",children:[m.width,"\xD7",m.height," \xB7 ",Math.round(h*100),"% \xB7 ",u.toFixed(0)," ms/frame"]})]})};var zr=new Qt,Xn=0,Rr=()=>{let e=ce();if(!e)return;A().time>=e.duration-1/e.fps&&T({time:0});let t=performance.now()-A().time*1e3;T({playing:!0});let n=o=>{let s=A(),r=ce();if(!s.playing||!r)return;let a=(o-t)/1e3;if(a>=r.duration){if(s.loop){a=0,St(),T({time:0}),Rr();return}St(),T({time:Y(r.duration-1/r.fps,r.fps)});return}T({time:a}),zr.sync(s.project,r,a,!0),Xn=requestAnimationFrame(n)};Xn=requestAnimationFrame(n)},St=()=>{cancelAnimationFrame(Xn);let e=ce();T({playing:!1,time:e?Y(A().time,e.fps):A().time}),zr.stop(),Lt.stopAll()},Fr=()=>A().playing?St():Rr(),Ge=e=>{let t=ce(),n="";W(o=>{n=H(o,t.id,{inPoint:Y(A().time,t.fps),...e}).id}),n&&T({layer:n,key:null})},ea={Text:()=>Ge({type:"text",name:"Text",text:"Your text",size:Math.round(ce().width/10),color:"#ffffff",weight:800}),Shape:()=>Ge({type:"shape",name:"Shape",shape:"ellipse",size:[300,300],fill:"#E8692A"}),Solid:()=>Ge({type:"solid",name:"Solid",color:"#1f2933"}),Null:()=>Ge({type:"null",name:"Null"}),"Adjustment layer (grade)":()=>Ge({type:"adjustment",name:"Grade",effects:[{type:"curves",master:[[0,0],[.25,.2],[.75,.82],[1,1]]},{type:"vignette",amount:40}]}),"Image / video / audio\u2026":()=>{let e=prompt("Path to the file, relative to the project file:");if(!e)return;let t=/\.(mp4|mov|webm|m4v)$/i.test(e)?"video":/\.(mp3|wav|m4a|aac|ogg)$/i.test(e)?"audio":"image";Ge({type:t,name:e.split("/").pop(),src:e})},"Lottie animation\u2026":()=>{let e=prompt("Path to the Lottie .json file, relative to the project file:");e&&Ge({type:"lottie",name:e.split("/").pop().replace(/\.json$/i,""),src:e})},"SVG as editable shapes\u2026":async()=>{let e=prompt("Path to the .svg file, relative to the project file:");if(!e)return;let t=await fetch(`/api/svg?src=${encodeURIComponent(e)}&token=${Le.token}`);if(!t.ok){T({message:await t.text()});return}let n=await t.text(),o=ce(),s="";W(r=>{s=Ro(r,o.id,n,{name:e.split("/").pop().replace(/\.svg$/i,""),width:Math.round(o.width*.5),position:[o.width/2,o.height/2],inPoint:Y(A().time,o.fps)}).group}),s&&T({layer:s,key:null})},"New comp (precomp)\u2026":()=>{let e=prompt("Id for the new composition:");if(!e)return;let t=ce();W(n=>{Wt(n,{id:e,name:e,duration:t.duration,width:t.width,height:t.height,fps:t.fps})}),Ge({type:"precomp",name:e,comp:e})}},ta=({onClose:e})=>{let t=lr(),[n,o]=le(t?.type==="text"?"text.fadeUp":"opener.logoReveal"),s=ne[n],r=d=>ne[d].kind==="text"||d==="element.highlightWord"?{layer:A().layer??""}:d==="opener.logoReveal"||d==="opener.bars"?{title:"Your Brand",start:Y(A().time,30)}:d==="kinetic.sequence"?{phrases:["Make","it","move"],start:Y(A().time,30),style:"slam"}:d==="element.lowerThird"?{name:"Your Name",title:"Your title",start:Y(A().time,30)}:d==="transition.between"?{from:"",to:"",type:"push",duration:.5}:d==="slides.slideshow"?{items:[{src:"photo1.jpg",caption:"Caption"}],each:3,transition:"push"}:{},[a,i]=le(JSON.stringify(r(n),null,2)),[c,l]=le("");return g("div",{class:"modal",onClick:e,children:g("div",{class:"dialog",onClick:d=>d.stopPropagation(),onKeyDown:d=>d.stopPropagation(),children:[g("div",{class:"dialog-list",children:["text","kinetic","opener","slides","transition","element","chart","overlay","map","captions"].map(d=>g("div",{children:[g("div",{class:"group",children:d}),Object.entries(ne).filter(([,f])=>f.kind===d).map(([f])=>g("button",{class:f===n?"active":"",onClick:()=>{o(f),i(JSON.stringify(r(f),null,2)),l("")},children:f.split(".")[1]},f))]},d))}),g("div",{class:"dialog-body",children:[g("h3",{children:n}),g("p",{children:s.description}),g("p",{class:"hint",children:["Params: ",s.params]}),g("textarea",{rows:10,value:a,spellcheck:!1,onInput:d=>i(d.target.value)}),c&&g("div",{class:"error",children:c}),g("div",{class:"row",children:[g("button",{onClick:e,children:"Cancel"}),g("button",{class:"primary",onClick:()=>{try{let d=JSON.parse(a),f=[],p=A().project;if(W(m=>{f=s.apply(m,A().comp,d).created}),A().project===p)throw new Error(A().message||"Preset failed");f[0]&&T({layer:f[0]}),e()}catch(d){l(d.message)}},children:"Apply"})]})]})]})})},Vr=e=>{if(e.target.closest?.("input, textarea, select"))return;let n=A(),o=ce();if(!o)return;let s=e.metaKey||e.ctrlKey,r=1/o.fps,a=i=>T({time:Math.max(0,Math.min(o.duration,Y(i,o.fps))),playing:!1});if(e.code==="Space")e.preventDefault(),Fr();else if(s&&e.key.toLowerCase()==="z")e.preventDefault(),e.shiftKey?tn():jn();else if(s&&e.key.toLowerCase()==="y")e.preventDefault(),tn();else if(s&&e.key.toLowerCase()==="d"&&n.layer)e.preventDefault(),W(i=>{let c=Bt(i,n.layer);T({layer:c.id})});else if(e.key==="ArrowLeft")e.preventDefault(),a(n.time-r*(e.shiftKey?10:1));else if(e.key==="ArrowRight")e.preventDefault(),a(n.time+r*(e.shiftKey?10:1));else if(e.key==="Home")a(0);else if(e.key==="End")a(o.duration-r);else if((e.key==="j"||e.key==="k")&&n.layer){let i=hr(n.layer),c=e.key==="j"?[...i].reverse().find(l=>l<n.time-.001):i.find(l=>l>n.time+.001);c!==void 0&&a(c)}else e.key==="["&&n.layer?W(i=>{let c=i.comps.find(l=>l.id===o.id).layers.find(l=>l.id===n.layer);ut(i,n.layer,Y(n.time,o.fps)-(c.inPoint??0))}):e.key==="]"&&n.layer?W(i=>fe(i,n.layer,{outPoint:Y(n.time,o.fps)})):e.key==="Delete"||e.key==="Backspace"?n.key?(W(i=>mt(i,n.key.layer,n.key.path,n.key.t)),T({key:null})):n.layer&&(W(i=>Ht(i,n.layer)),T({layer:null})):e.key==="Escape"?T({layer:null,key:null}):e.key==="="||e.key==="+"?T({zoom:Math.min(2e3,n.zoom*1.25)}):e.key==="-"&&T({zoom:Math.max(10,n.zoom/1.25)})},na=(e,t)=>{let n=Math.round(e*t),o=Math.floor(n/t);return`${String(Math.floor(o/60)).padStart(2,"0")}:${String(o%60).padStart(2,"0")}:${String(n%t).padStart(2,"0")}`},oa=()=>{let e=j(r=>r.time),t=j(r=>r.playing),n=j(r=>r.loop),o=j(r=>r.zoom),s=ce();return s?g("div",{class:"transport",children:[g("button",{title:"Start (Home)",onClick:()=>T({time:0}),children:"\u23EE"}),g("button",{title:"Previous frame (\u2190)",onClick:()=>T({time:Math.max(0,Y(e-1/s.fps,s.fps))}),children:"\u25C0\uFE0E"}),g("button",{class:"play",title:"Play / pause (Space)",onClick:Fr,children:t?"\u275A\u275A":"\u25B6"}),g("button",{title:"Next frame (\u2192)",onClick:()=>T({time:Math.min(s.duration,Y(e+1/s.fps,s.fps))}),children:"\u25B6\uFE0E"}),g("button",{class:n?"on":"",title:"Loop",onClick:()=>T({loop:!n}),children:"\u27F2"}),g("span",{class:"timecode",children:na(e,s.fps)}),g("span",{class:"muted",children:[e.toFixed(2),"s / ",s.duration,"s"]}),g("span",{class:"spacer"}),g("span",{class:"muted",children:"Zoom"}),g("button",{onClick:()=>T({zoom:Math.max(10,o/1.25)}),children:"\u2212"}),g("button",{onClick:()=>T({zoom:Math.min(2e3,o*1.25)}),children:"+"})]}):null},ra=({onPresets:e})=>{let t=j(l=>l.project),n=j(l=>l.comp),o=j(l=>l.status),s=j(l=>l.message),r=j(l=>l.warnings),a=j(l=>l.render),[i,c]=le(!1);return g("header",{class:"topbar",children:[g("div",{class:"brand",children:[g("b",{children:"DT.ly"})," Studio ",g("span",{class:"muted",children:["\xB7 ",Le.file]})]}),g("nav",{class:"comps",children:t?.comps.map(l=>g("button",{class:l.id===n?"active":"",onClick:()=>{St(),T({comp:l.id,layer:null,key:null,time:0})},children:[l.name??l.id,t.root===l.id?" \u2605":""]},l.id))}),g("div",{class:"actions",children:[g("div",{class:"menu-wrap",children:[g("button",{onClick:()=>c(!i),children:"+ Layer \u25BE"}),i&&g("div",{class:"menu",onMouseLeave:()=>c(!1),children:Object.entries(ea).map(([l,u])=>g("button",{onClick:()=>{c(!1),u()},children:l},l))})]}),g("button",{onClick:e,children:"Presets\u2026"}),g("button",{title:"Undo (\u2318Z)",onClick:jn,children:"\u21B6"}),g("button",{title:"Redo (\u21E7\u2318Z)",onClick:tn,children:"\u21B7"}),g("button",{class:"primary",disabled:a.active,onClick:()=>{St(),cr()},children:a.active?`Rendering ${a.total?Math.round((a.done??0)/a.total*100):0}%`:"Render MP4"})]}),g("div",{class:`status ${o}`,title:r.join(`
|
|
5
|
+
`),children:[s||(o==="saving"?"Saving\u2026":o==="error"?"Save failed":o==="reloaded"?"Reloaded from disk":"Saved"),r.length>0&&g("span",{class:"warn",children:[" \xB7 ",r.length," warning",r.length>1?"s":""]}),a.out&&!a.active&&g("a",{href:`/api/media?src=${encodeURIComponent(a.out)}&token=${Le.token}`,target:"_blank",children:[" \xB7 open ",a.out]}),a.error&&g("span",{class:"error",children:[" \xB7 render failed: ",a.error]})]})]})},sa=()=>{let e=j(o=>o.project),[t,n]=le(!1);return Pe(()=>(document.addEventListener("keydown",Vr),()=>document.removeEventListener("keydown",Vr)),[]),e?g("div",{class:"app",children:[g(ra,{onPresets:()=>n(!0)}),g("main",{class:"workspace",children:[g(jr,{}),g(pr,{})]}),g("section",{class:"bottom",children:[g(oa,{}),g(fr,{})]}),t&&g(ta,{onClose:()=>n(!1)})]}):g("div",{class:"loading",children:"Loading project\u2026"})};(async()=>{document.title=`${Le.file} \u2014 DT.ly Studio`,await Vn();let e=ce();e&&T({zoom:Math.max(20,Math.min(400,(window.innerWidth-260)/e.duration))}),await rr(A().project),ir(),mo(g(sa,{}),document.getElementById("root"))})();
|
|
5
6
|
//# sourceMappingURL=app.js.map
|