@motionscript/core 0.2.0 → 0.4.0-alpha.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.
@@ -1,13 +0,0 @@
1
- import{$b as Gt,$d as Po,Ac as gs,Ae as en,Bb as ls,Bc as ke,Be as Go,Cb as he,Cc as je,Cd as I,Ce as Yo,Db as j,Dc as ho,Dd as As,De as Wo,Eb as de,Ed as Zt,F as Xr,Fa as Ut,Fb as fs,Fc as Z,Fd as Ao,Fe as mt,Ga as Zr,Gc as ys,Gd as Mo,Ge as P,Hb as hs,He as w,Ie as tn,Ja as os,Jd as Oo,Je as me,Ka as ve,Kd as T,Ke as nn,Lb as ct,Ld as k,Le as Xo,Mb as ps,Md as Se,Me as ge,Nb as so,Nc as _s,Nd as Be,Ne as qo,Oe as sn,Pc as ws,Pd as B,Pe as Ho,Qc as po,Qd as K,Qe as Jo,Rc as mo,Rd as z,Sc as go,Se as Zo,Tc as xs,Td as To,Te as Qo,Ua as as,Uc as Xt,Ud as F,Ue as ei,Vb as dt,Vc as yo,Vd as $,Ve as ti,Wa as ot,Wb as ro,Wc as qt,Wd as Q,X as ss,Xb as ne,Xc as vs,Xd as E,Yb as oo,Yc as _o,Zb as ut,Zc as R,Zd as Eo,_b as Le,_d as Co,aa as rs,ac as be,ad as ht,ae as Qt,bc as Ce,bd as bs,be as Io,cb as cs,cc as pe,cd as ks,ce as Do,dc as lt,dd as Ss,de as Ms,ea as qr,eb as ds,ec as ft,f as Qn,fa as Hr,fb as it,fd as wo,fe as Fo,ga as rt,gc as io,gd as xo,ge as $o,hc as ao,he as No,id as Ht,jd as Jt,kb as at,kc as co,lc as Yt,m as ns,md as ko,me as Os,nb as Qr,nd as So,ne as Ts,oa as Jr,ob as Y,oc as Pe,oe as Es,pb as eo,pc as uo,pe as Lo,qe as jo,ra as fe,re as Bo,sb as to,se as Vo,tb as no,vc as lo,ve as Cs,wb as Ee,wc as fo,we as Ps,xc as ms,xe as Ko,yc as Wt,ye as pt,zb as us,ze as Uo}from"./chunk-XCGYJHZR.js";import{b as Ro,f as zo}from"./chunk-GEJEQQER.js";import{b as Wr,d as es,f as ts,h as ze,m as is,n as vo,o as bo}from"./chunk-5TDMGUXQ.js";function ni(n){return Number.isFinite(n)&&n>0?n:1}function Ve(n,e,t=e){return at(n)?to(n,e,t):Math.max(0,Math.min(t,e))/ni(n)}function Sd(n,e,t){return at(n)?no(n,e,t):Math.max(0,Math.min(e,t*ni(n)))}function Ad(n,e){let t=Math.max(0,(n.trimEnd??e)-(n.trimStart??0));return Ve(n.speed??1,t)}function si(n,e,t,s){let r=n.at??0,o=n.until??1/0,i=n.trimStart??0,a=n.trimEnd??1/0,c=n.loop??!1,d=Ee(n.effects),u=e.getMediaDuration(n.src),l=n.speed??1;c&&at(l)&&(l=Qr(l,1));let f=Math.max(0,(Number.isFinite(a)?a:u)-i),h={id:`${t}|${n.src}|${r}|${s}`,src:n.src,startAt:r,endAt:1/0,trimStart:i,volume:n.volume??1,speed:l,loop:c,ownerId:t};if(at(l)&&(h.sourceLength=f),d.length>0&&(h.effects=d),n.transitionIn&&(h.transitionIn=n.transitionIn),n.transitionOut&&(h.transitionOut=n.transitionOut),n.bus&&(h.bus=n.bus),n.optional&&(h.optional=!0),c&&a>i&&Number.isFinite(a)&&(h.trimEnd=a),c&&Number.isFinite(o))h.endAt=o;else if(c)h.open=!0;else if(Number.isFinite(a))h.endAt=Math.min(o,r+Ve(l,f));else{let p=Ve(l,f);Number.isFinite(o)?h.endAt=Math.min(o,r+p):(h.open=!0,h.mediaDuration=p)}return h}var Is=class{src;volume;speed;loop;trimStart;trimEnd;effects;constructor(e){this.src=e.src,this.volume=e.volume??1,this.speed=e.speed??1,this.loop=e.loop??!1,this.trimStart=e.trimStart??0,this.trimEnd=e.trimEnd??e.duration??1/0,this.effects=Ee(e.effects)}clipDurationFor(e){return Ve(this.speed,e)}get clipDuration(){return this.trimEnd!==1/0?this.clipDurationFor(this.trimEnd-this.trimStart):void 0}};function gt(n){return!n||n.length===0?"":n.map(e=>{switch(e.type){case"gain":return`gain:${Y(e.value)}`;case"highpass":case"lowpass":return`${e.type}:${Y(e.frequency)}:${Y(e.q)}`;case"tremolo":return`tremolo:${Y(e.rate)}:${Y(e.depth)}`;case"echo":return`echo:${Y(e.delay)}:${Y(e.feedback)}:${Y(e.mix)}`}}).join("|")}var Md=n=>Math.sin(Math.max(0,Math.min(1,n))*Math.PI/2),ri=new WeakMap;function oi(n){let e=n.curve;if(e===void 0||e==="equalPower")return Md;let t=ri.get(e);return t||ri.set(e,t=it(e)),t}function Od(n,e,t){let s={in:Math.max(0,e?.duration??0),out:Math.max(0,t?.duration??0)};if(!Number.isFinite(n))return{in:s.in,out:0};let r=s.in+s.out;if(r<=n||r===0)return s;let o=Math.max(0,n)/r;return{in:s.in*o,out:s.out*o}}function Lp(n,e,t,s){let r=Od(e,t,s),o=1;return t&&r.in>0&&n<r.in&&(o*=Math.max(0,oi(t)(Math.max(0,n)/r.in))),s&&r.out>0&&n>e-r.out&&(o*=Math.max(0,oi(s)(Math.max(0,e-n)/r.out))),o}function Ke(n){return n?`${n.duration}:${typeof n.curve=="object"?JSON.stringify(n.curve):n.curve??"equalPower"}`:"_"}function Ds(n){return`${n.id}:${Y(n.volume)}:${Y(n.pan)}:${n.mute?1:0}:${gt(n.effects)}:${Ke(n.transitionIn)}:${Ke(n.transitionOut)}:${n.startAt}:${n.endAt}`}var Td=new Set(["number","slider","angle","hue","boolean","color","vector","point"]);function km(n){return Td.has(n.kind)}var ii=64,ai=64e3;function ci(n){if(typeof n!="object"||n===null)throw new Error("A shader pack must be an object.");let e=n,t=e.scope;if(t!=="fill"&&t!=="effect")throw new Error(`A shader pack needs scope "fill" or "effect", got ${JSON.stringify(t)}. The two are written against different contracts \u2014 a fill has no backdrop to sample and an effect has no shape box to map coordinates onto.`);let s=typeof e.source=="string"?e.source.trim():"";if(s==="")throw new Error(`Shader pack "${String(e.name??"?")}" has no source.`);if(s.length>ai)throw new Error(`Shader pack "${String(e.name??"?")}" source is ${s.length} characters, over the ${ai} ceiling.`);if(e.language!==void 0&&e.language!=="wgsl")throw new Error(`Shader pack "${String(e.name??"?")}" is written in ${JSON.stringify(e.language)}; only WGSL is supported. Port it to WGSL.`);let r={...typeof e.$kind=="string"?{$kind:e.$kind}:{},...typeof e.id=="string"?{id:e.id}:{},name:typeof e.name=="string"&&e.name!==""?e.name:"Shader",...typeof e.description=="string"?{description:e.description}:{},language:"wgsl",source:s,..._t(e.uniforms)?{uniforms:e.uniforms}:{},properties:Ed(e.properties,String(e.name??"?"))};if(t==="fill"){let o=Array.isArray(e.textures)?e.textures.filter(i=>_t(i)&&typeof i.name=="string").map(i=>({name:i.name,...typeof i.description=="string"?{description:i.description}:{}})):[];return{...r,scope:"fill",...o.length?{textures:o}:{}}}return{...r,scope:"effect",...e.backdrop===!0?{backdrop:!0}:{}}}function Ed(n,e){if(!_t(n))return{};let t={},s=new Map;for(let[r,o]of Object.entries(n)){if(Object.keys(t).length>=ii){yt(`shader "${e}" declares more than ${ii} properties; the rest are ignored.`);break}if(!_t(o)||typeof o.kind!="string"){yt(`shader "${e}" property "${r}" has no kind; ignored.`);continue}let i=o.inputs;if(!_t(i)||Object.keys(i).length===0){yt(`shader "${e}" property "${r}" names no uniform in "inputs"; ignored.`);continue}let a=!1;for(let c of Object.values(i)){if(typeof c!="string"){yt(`shader "${e}" property "${r}" has a non-string uniform name; ignored.`),a=!0;break}let d=s.get(c);if(d!==void 0){yt(`shader "${e}" properties "${d}" and "${r}" both write uniform "${c}"; "${r}" ignored.`),a=!0;break}s.set(c,r)}a||(t[r]=o)}return t}function _t(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}var rn=new Set;function yt(n){rn.has(n)||(rn.size>256&&rn.clear(),rn.add(n),console.warn(`[shader] ${n}`))}function ye(n,e){return n===""?String(e):`${n}.${e}`}function Fs(n,e){n.declareAssets(e)}function $s(n,e){if(!n.mounted)return;Fs(n,e);let t=n._allChildren;for(let s=0;s<t.length;s++)$s(t[s],e)}function di(n,e){n.attachDetached(e)}function on(n){n._sample();for(let e of n.children)on(e)}function an(n,e){n._primeMotion(e);for(let t of n.children)an(t,e)}function Ns(n,e){let t=s=>{let r=s.key!==void 0?e?.[s.key]:void 0;s._setEditorState(r?.hidden===!0,r?.locked===!0);for(let o of s._allChildren)t(o)};t(n)}var Ie=class extends R{constructor(e){super(e)}zoomTo(e){return this.to({data:e.data,duration:e.duration,easing:e.easing})}panTo(e){return this.to({data:e.data,duration:e.duration,easing:e.easing})}orbitTo(e){return this.to({data:e.data,duration:e.duration,easing:e.easing})}dollyTo(e){return this.to({data:e.data,duration:e.duration,easing:e.easing})}headingTo(e){return this.to({data:e.data,duration:e.duration,easing:e.easing})}fillTo(e){let t=this.fill,s=ve.resolve(e.data),r=e.lerp??ve.lerp;return this.command(o=>({fill:r(t,s,o)}),e.duration,e.easing)}overlayTo(e){let t=this.overlay,s=ve.resolve(e.data),r=e.lerp??ve.lerp;return this.command(o=>({overlay:r(t,s,o)}),e.duration,e.easing)}flowArrangement(){return this}shapeGraphics(){return new rt().rect({width:this.layoutBounds.width,height:this.layoutBounds.height})}renderSelf(e){let t=this.fill;t.length!==0&&e.draw(this.shapeGraphics().fill(t))}renderOverlay(e){let t=this.overlay;t.length!==0&&e.draw(this.shapeGraphics().fill(t))}acceptsChild(e){return e.dimension==="2d"||e.dimension==="audio"}get _childTrees(){return["2d","audio"]}get childrenAudio(){return this._allChildren.filter(e=>e instanceof ht)}declareAssets(e){super.declareAssets(e),e.fill(this.fill),e.fill(this.overlay)}clipSelf(){return new xs().rect({width:this.layoutBounds.width,height:this.layoutBounds.height})}_cameraScope(){return this.space3D||this.zoom===1&&this.heading===0&&this.lookAt.x===0&&this.lookAt.y===0?null:{lookAt:this.lookAt,zoom:this.zoom,heading:this.heading}}_spaceCamera(){if(!this.space3D)return null;let e=this.layoutBounds;return{perspective:this.perspective,orbit:this.orbit,elevation:this.elevation,dolly:this.dolly,lookAt:this.lookAt,zoom:this.zoom,heading:this.heading,viewportX:e?.x??0,viewportY:-(e?.y??0)}}_projection(){return this.space3D?hs:super._projection()}renderChildren(e){let t=this._spaceCamera();if(t){this._renderInSpace(e,Xt(this,t));return}if(this.zoom===1&&this.heading===0&&this.lookAt.x===0&&this.lookAt.y===0){super.renderChildren(e);return}let s=this.layoutBounds,r=s?.width??0,o=s?.height??0,i=s?.x??0,a=s?.y??0;e.beginCamera({x:i,y:-a,width:r,height:o},this.lookAt,this.zoom,this.heading);for(let c of this._children)c instanceof R&&c.render(e);e.endCamera()}};ro(Ie,{fill:ws(),overlay:ws(),flow:mo(),gap:ne({default:0}),wrap:ne({default:!1}),crossGap:ne({default:void 0}),columns:ne({default:1}),align:po(),zoom:ne({default:1}),lookAt:ne({default:{x:0,y:0},tween:ct}),heading:ne({default:0}),space3D:ne({default:!1}),orbit:ne({default:0}),elevation:ne({default:0}),dolly:ne({default:0}),zoomTo:ke({args:[{key:"zoom",kind:"number",min:.01,step:.1,unit:"\xD7"}]}),panTo:ke({args:[{key:"lookAt",kind:"vector2",properties:{x:{kind:"number"},y:{kind:"number"},z:{kind:"number"}}}]}),orbitTo:ke({args:[{key:"orbit",kind:"number",step:1,unit:"\xB0"},{key:"elevation",kind:"number",step:1,unit:"\xB0"}]}),dollyTo:ke({args:[{key:"dolly",kind:"number",step:10}]}),headingTo:ke({args:[{key:"heading",kind:"number",step:1,unit:"\xB0"}]}),fillTo:ke(),overlayTo:ke()});var dn={cornerRadius:k.number(0),cornerStyle:k.custom("rounded",{lerp:Qn})},ui=T({key:"rect",state:{...F,...B,...Se},commands:{...$},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Be(n.size,e))}),li=T({key:"ellipse",state:{...F,...B,startAngle:k.number(0),sweep:k.number(360),ratio:k.number(0)},commands:{...$},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Eo(n.size,e))}),fi=T({key:"polygon",state:{...F,...B,sides:k.number(5),...dn},commands:{...$},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Co(n.size,e))}),hi=T({key:"polygram",state:{...F,...B,sides:k.number(5),ratio:k.number(.5),...dn},commands:{...$},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Po(n.size,e))}),pi=T({key:"path",state:{...F,...B,data:k.path},commands:{...$},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Io(n.size,e.data),{clipShape:Qt(n.size)})}),Sg=T({key:"facePath",state:{...F,...B,data:k.path},defaults:{width:"hug",height:"hug"},commands:{...$},measure:(n,e)=>{let t=is.size(e.data),s=e.padding;return{width:t.width+s.left+s.right,height:t.height+s.top+s.bottom}},layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Do(e.data),{clipShape:null})});function xt(n,e){return T({key:n,state:{...F,...B,...dn},commands:{...$},measure:(t,s,r)=>K(t,s,r,E(s)),layout:(t,s,r)=>z(t,s,r,E(s)),render:(t,s)=>Q(t,s,Ms(e,t.size,s),{clipShape:Qt(t.size)})})}var Ag=xt("triangle","triangle"),Mg=xt("rightTriangle","rightTriangle"),Og=xt("pentagon","pentagon"),Tg=xt("hexagon","hexagon"),Eg=xt("octagon","octagon"),Cg=T({key:"star",state:{...F,...B,...dn,points:k.number(bo),ratio:k.number(vo)},commands:{...$},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Ms("star",n.size,{cornerRadius:e.cornerRadius,cornerStyle:e.cornerStyle,sides:Math.max(3,Math.round(e.points)),ratio:e.ratio}),{clipShape:Qt(n.size)})});var mi=T({key:"boolean",state:{...F,...B,op:k.oneOf(["union","subtract","intersect","exclude"])},commands:{...$},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>n.merge(e.op,e)}),gi=T({key:"mask",state:{mode:k.oneOf(["alpha","vector","luminance"]),inverted:!1},render:(n,e)=>n.mask(e)});var wi=T({key:"camera",state:{...F,...B,...Fo,...Se},commands:{...$,...$o},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>Q(n,e,Be(n.size,e),{children:()=>No(n,e)})}),yi={lookAt:k.custom({x:0,y:0},{lerp:ct,kind:"vector2",properties:{x:{kind:"number"},y:{kind:"number"},z:{kind:"number"}}}),zoom:k.number(1,{min:.01,step:.1,unit:"\xD7"}),heading:k.number(0,{step:1,unit:"\xB0"}),orbit:k.number(0,{step:1,unit:"\xB0"}),elevation:k.number(0,{step:1,unit:"\xB0"}),dolly:k.number(0,{step:10}),orbitSpeed:k.number(0)},xi=T({key:"orbitCamera",state:yi,defaults:{width:"hug",height:"hug",perspective:1e3},commands:To(yi,{orbitTo:{args:["orbit","elevation"]},dollyTo:{args:["dolly"]},zoomTo:{args:["zoom"]},panTo:{args:["lookAt"]},headingTo:{args:["heading"]}}),render:(n,e)=>n.space({perspective:e.perspective,orbit:e.orbit+e.orbitSpeed*n.time.total,elevation:e.elevation,dolly:e.dolly,lookAt:e.lookAt,zoom:e.zoom,heading:e.heading,viewportX:0,viewportY:0})}),vi=T({key:"rotated-box",state:{angle:k.number(-90)},defaults:{rotation:n=>n.angle},measure:(n,e,t)=>{let{cos:s,sin:r}=_i(e.angle),{width:o,height:i}=n.max,a=Math.abs(e.angle%180)===90,c=o!==void 0&&i!==void 0?{width:o*s+i*r,height:o*r+i*s}:{width:a?i:o,height:a?o:i},d=0,u=0;for(let l of t){let f=l.measure(c);d=Math.max(d,f.width),u=Math.max(u,f.height)}return{width:d*s+u*r,height:d*r+u*s}},layout:(n,e,t)=>{let{cos:s,sin:r}=_i(e.angle),o={x:0,y:0,width:n.width*s+n.height*r,height:n.width*r+n.height*s};return z(o,e,t)}});function _i(n){let e=n*(Math.PI/180);return{cos:Math.abs(Math.cos(e)),sin:Math.abs(Math.sin(e))}}var{overlay:Hg,...Bs}=F,{overlayTo:Jg,...Vs}=$,js=n=>n.fontSize==="autofit"?"fill":"hug",Cd=[];function Pd(n){return n==null?null:n instanceof Hr?n.toCommands():n}function Id(n){return Array.isArray(n)?n.map(({fill:e,stroke:t,...s})=>({...s,...e===void 0?{}:{fill:ve.resolve(e)},...t===void 0?{}:{stroke:as.resolve(t)}})):[]}var Dd={...Bs,...en,text:k.text("",{typing:!0}),wrap:!1,path:k.custom(null,{resolve:Pd}),runs:k.custom([],{resolve:Id,animatable:!1})},zs=n=>({text:n.text,wraps:n.wrap,glyphPath:n.path,runs:n.runs}),un=T({key:"text",allowedChildren:[],state:Dd,defaults:{width:n=>n.fontSize==="autofit"||n.wrap?"fill":"hug",height:js},commands:{...Vs,append:{args:{text:k.text("",{multiline:!0})},run:(n,e)=>n.tween({text:e.text+n.args.text})},prepend:{args:{text:k.text("",{multiline:!0})},run:(n,e)=>n.tween({text:n.args.text+e.text})}},load:(n,e)=>Es(n,e,zs(e)),measure:(n,e)=>Os(n,e,zs(e)),render:(n,e)=>Ts(n,e,zs(e))}),Fd={...Bs,...en,value:0,format:k.custom("number"),customPattern:"",fractionDigits:0,grouped:!0,currencySymbol:"$"},Ls=n=>({text:Ro(n.value,zo(n)),wraps:!1,glyphPath:null,runs:Cd}),bi=T({key:"number",allowedChildren:[],state:Fd,defaults:{width:js,height:js},commands:{...Vs,countTo:{args:["value"]}},load:(n,e)=>Es(n,e,Ls(e)),measure:(n,e)=>Os(n,e,Ls(e)),render:(n,e)=>Ts(n,e,Ls(e))}),{verticalAlign:Zg,textDecoration:Qg,textCase:ey,minFontSize:ty,...$d}=en,ki=T({key:"richtext",allowedChildren:[],state:{...Bs,...$d,fontSize:k.number(48,{inherit:Uo("fontSize",{autofit:!1})}),spans:k.custom([],{resolve:n=>n==null?[]:Array.isArray(n)?n:[n]})},defaults:{width:"hug",height:"hug"},commands:{...Vs},load:(n,e)=>Vo(n,e),measure:(n,e)=>jo(n,e),render:(n,e)=>Bo(n,e)}),Si=T({key:"default-text-style",state:Go,provide:(n,e)=>Yo(n,e),render:(n,e)=>n.textStyle(Wo(e),()=>n.children())});var Ai=T({key:"provider",state:{context:k.custom(void 0),value:k.custom(void 0)},provide:n=>n.context?[pt(n.context,n.value!==void 0?n.value:n.context.defaultValue)]:[]}),Mi=T({key:"theme-provider",state:{theme:k.custom(void 0),data:k.custom(void 0),seed:k.custom(void 0)},provide:(n,e)=>{let t=[];return n.theme&&t.push(pt(Cs,{...e(Cs),...n.theme})),n.data&&t.push(pt(Ps,{...e(Ps),...n.data})),n.seed!==void 0&&t.push(pt(Ko,n.seed)),t}});var Oi=mt({key:"sound",state:{src:k.custom(void 0),trimStart:0,trimEnd:k.custom(void 0),loop:!1,speed:k.custom(1,{lerp:eo,kind:"audioParam"})},allowedChildren:[],commands:{play:(n,e)=>n.sound(e.src,{trimStart:e.trimStart,trimEnd:e.trimEnd,loop:e.loop,volume:e.volume,speed:e.speed,effects:e.effects,transitionIn:e.transitionIn,transitionOut:e.transitionOut})}}),Ti=mt({key:"audioBus",state:{solo:!1}});var Nd={src:k.custom(void 0),fit:k.custom(void 0),crop:k.insets,zoom:1,anchor:k.alignment,matrix:k.custom(void 0),filters:k.custom([],{resolve:n=>rs(n),lerp:ss}),playing:!0,timestamp:k.custom(void 0),trimStart:k.custom(void 0),trimEnd:k.custom(void 0),speed:k.custom(void 0),loop:k.custom(void 0),duration:k.custom(void 0),volume:1,muted:!1,audioEffects:k.custom([],{resolve:n=>Ee(n)}),bus:k.custom(void 0),segments:k.custom([])};function Rd(n,e){if(n.segments.length===0)return null;let t=0;for(let s of n.segments){if(e<=s.at)break;t+=Math.min(e-s.at,s.duration)*(s.speed??n.speed??1)}return t}function zd(n,e){let t=Rd(n,e);if(t===null)return;let s=n.trimStart??0,r=n.segments[0];return qr(t+(r?r.from-s:0),s,n.trimEnd??1/0,n.loop,n.duration)}var Ks=new WeakMap;function Ld(n,e,t){if(!e.src)return Ks.delete(n),null;let s=zd(e,t),r=e.crop,o=e.anchor,i=[e.src,e.fit??"",e.zoom,e.playing?1:0,r.left,r.right,r.top,r.bottom,o.x,o.y,e.timestamp??"",e.trimStart??"",e.trimEnd??"",e.speed??"",e.loop??"",e.duration??"",s??""].join("|"),a=Ks.get(n);if(a&&a.key===i)return a.fill;let c={type:"video",src:e.src,fit:e.fit,crop:e.crop,zoom:e.zoom,anchor:e.anchor,matrix:e.matrix,preset:{adjustments:e.filters},playing:e.playing,timestamp:e.timestamp??s,trimStart:e.trimStart,trimEnd:e.trimEnd,speed:e.speed,loop:e.loop,duration:e.duration},d=Ut(c);return Ks.set(n,{key:i,fill:d}),d}var Ei=T({key:"video",state:{...F,...B,...Se,...Nd},commands:{...$,play:{args:{from:k.custom(void 0),volume:k.custom(void 0),speed:k.custom(void 0)},run:(n,e)=>{let t=e,s=n.args.from!==void 0;if(!t.src||t.muted||!s&&!t.playing)return n.together([]);let r=n.args.speed??t.speed??1,o=!s&&(t.loop??"none")!=="none";return n.sound(t.src,{volume:n.args.volume??t.volume,loop:o,trimStart:s?n.args.from:t.trimStart,trimEnd:t.trimEnd,speed:r,effects:t.audioEffects,bus:t.bus,optional:!0,closed:!o})}}},load:(n,e)=>{e.src&&n.fill(Ut({type:"video",src:e.src,preset:{adjustments:e.filters},trimStart:e.trimStart,trimEnd:e.trimEnd}))},measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>{let t=e,s=Ld(Oo(n).host,t,n.time.elapsed),r={width:n.size.width,height:n.size.height,cornerRadius:t.cornerRadius,cornerStyle:t.cornerStyle,start:t.start,end:t.end};Q(n,e,Be(n.size,e),{fill:[s??Zr,...e.fill],overlay:()=>s?new rt().mask().rect(r).fill([s]).applyMask().rect(r).fill(e.overlay).endMask():null})}});var De={orbit:0,elevation:0,distance:10};function Ci(n){return n.orbit!==void 0||n.elevation!==void 0||n.distance!==void 0}function Us(n){let e=Z(n.target??0);if(!Ci(n)){let i=n.lookAt??n.target;return{position:Z(n.position??0),lookAt:i===void 0?void 0:Z(i)}}let t=n.distance??De.distance,s=(n.orbit??De.orbit)*Math.PI/180,r=jd(n.elevation??De.elevation,-89.9,89.9)*Math.PI/180,o=Math.cos(r)*t;return{position:{x:e.x+Math.sin(s)*o,y:e.y+Math.sin(r)*t,z:e.z+Math.cos(s)*o},lookAt:e}}function jd(n,e,t){return n<e?e:n>t?t:n}var Pi=P({key:"group3d"}),vt={geometry:w(),...qo},Ii=P({key:"mesh3d",state:vt,render:(n,e)=>n.draw(sn(e,e.geometry))}),Fe={startAngle:w(),sweep:w()},$e=["startAngle","sweep"];function ee(n,e,t,s){return P({key:n,state:{...vt,...t},render:(r,o)=>r.draw(sn(o,ge(e,o,s)))})}var Di=ee("box3d","box",{width:w(),height:w(),depth:w(),cornerRadius:w(),segments:w()},["width","height","depth","cornerRadius","segments"]),Fi=ee("sphere3d","sphere",{radius:w(),segments:w(),...Fe,startLatitude:w(),latitudeSweep:w()},["radius","segments","startLatitude","latitudeSweep",...$e]),$i=ee("plane3d","plane",{width:w(),height:w(),segments:w()},["width","height","segments"]),Ni=ee("cylinder3d","cylinder",{radius:w(),height:w(),segments:w(),capped:w(),...Fe},["radius","height","segments","capped",...$e]),Ri=ee("cone3d","cone",{radius:w(),height:w(),segments:w(),capped:w(),...Fe},["radius","height","segments","capped",...$e]),zi=ee("torus3d","torus",{radius:w(),thickness:w(),segments:w(),...Fe},["radius","thickness","segments",...$e]),Li=ee("torus-knot3d","torusKnot",{radius:w(),thickness:w(),segments:w(),windings:w()},["radius","thickness","segments","windings"]),ji=ee("circle3d","circle",{radius:w(),segments:w(),...Fe},["radius","segments",...$e]),Bi=ee("ring3d","ring",{radius:w(),innerRadius:w(),segments:w(),...Fe},["radius","innerRadius","segments",...$e]),Vi=ee("capsule3d","capsule",{radius:w(),height:w(),segments:w()},["radius","height","segments"]),Ki=P({key:"polyhedron3d",state:{...vt,shape:k.custom("icosahedron"),radius:w(),segments:w()},render:(n,e)=>n.draw(sn(e,ge("polyhedron",e,["shape","radius","segments"])))}),Ui=ee("extrude3d","extrude",{path:w(),depth:w(),segments:w(),bevel:w()},["path","depth","segments","bevel"]),Gi=ee("lathe3d","lathe",{points:w(),segments:w(),...Fe},["points","segments",...$e]),Yi=ee("tube3d","tube",{points:w(),radius:w(),segments:w(),closed:w()},["points","radius","segments","closed"]),Wi=P({key:"instances3d",state:{...vt,instances:w(),colors:w()},render:(n,e)=>{!e.geometry||!e.instances?.length||n.draw(new fe().instances(e.geometry,Ho(e),e.instances,{colors:e.colors}))}}),Xi=P({key:"points3d",state:vt,render:(n,e)=>{e.geometry&&n.draw(new fe().points(e.geometry,Jo(e)))}}),qi=P({key:"line3d",state:{points:w(),geometry:w(),closed:k.custom(!1),segments:k.custom(!1),stroke:w(),opacity:w(),material:w()},render:(n,e)=>{!e.geometry&&!e.points?.length||n.draw(new fe().line({points:e.geometry?void 0:e.points,geometry:e.geometry,closed:e.closed,segments:e.segments,stroke:e.stroke,opacity:e.opacity,material:e.material}))}}),Hi=P({key:"sprite3d",state:{fill:k.custom(void 0,{lerp:Jr}),opacity:w(),material:w()},render:(n,e)=>n.draw(new fe().sprite({fill:e.fill,opacity:e.opacity,material:e.material}))}),Ji=P({key:"model3d",state:{src:w(),animation:w(),override:w()},render:(n,e)=>{e.src&&n.draw(new fe().model({src:e.src,animation:e.animation,override:e.override}))}}),Py=P({key:"modelView3d",state:{src:w(),animation:w(),override:w(),clip:"",clipTime:0},render:(n,e)=>{if(!e.src){n.draw(new fe().box({width:1,height:1,depth:1,material:{type:"basic",color:"#6b7280",wireframe:!0,transparent:!0,opacity:.7}}));return}n.draw(new fe().model({src:e.src,animation:{clip:Bd(e.clip),time:e.clipTime},override:e.override}))}});function Bd(n){let e=n.trim();if(e==="")return;let t=Number(e);return Number.isInteger(t)&&t>=0?t:e}var Gs={shadow:!1},Zi=P({key:"ambient-light3d",state:{color:me(),intensity:w()},render:(n,e)=>n.light(ge("ambient",e,["color","intensity"]))}),Qi=P({key:"hemisphere-light3d",state:{sky:me(),ground:me(),intensity:w()},render:(n,e)=>n.light(ge("hemisphere",e,["sky","ground","intensity"]))}),ea=P({key:"directional-light3d",state:{color:me(),intensity:w(),target:nn("origin")},defaults:Gs,render:(n,e)=>n.light(ge("directional",e,["color","intensity","target","shadow"]))}),ta=P({key:"point-light3d",state:{color:me(),intensity:w(),distance:w(),decay:w()},defaults:Gs,render:(n,e)=>n.light(ge("point",e,["color","intensity","distance","decay","shadow"]))}),na=P({key:"spot-light3d",state:{color:me(),intensity:w(),distance:w(),angle:w(),penumbra:w(),decay:w(),target:nn("origin")},defaults:Gs,render:(n,e)=>n.light(ge("spot",e,["color","intensity","distance","angle","penumbra","decay","target","shadow"]))}),sa=P({key:"area-light3d",state:{color:me(),intensity:w(),width:w(),height:w()},render:(n,e)=>n.light(ge("area",e,["color","intensity","width","height"]))}),Vd=["target","orbit","elevation","distance","fov","frustumHeight","near","far","zoom"],Kd=["orbit","elevation","distance"],ra=P({key:"camera3d",state:{type:k.custom("perspective"),target:nn("origin"),orbit:w(),elevation:w(),distance:w(),fov:w(),frustumHeight:w(),near:w(),far:w(),zoom:w()},commands:{orbitTo:{args:{orbit:tn({step:1,unit:"\xB0"}),elevation:tn({min:-89,max:89,step:1,unit:"\xB0"}),distance:tn({min:.01,step:.1})},run:(n,e)=>{let t={orbit:e.orbit??De.orbit,elevation:e.elevation??De.elevation,distance:e.distance??De.distance};return n.animate(s=>{let r={};for(let o of Kd){let i=n.args[o];i!==void 0&&(r[o]=t[o]+(i-t[o])*s)}return r})}},lookTo:{args:["target"]}},render:(n,e)=>{let t={type:e.type};for(let s of Vd)e[s]!==void 0&&(t[s]=e[s]);n.camera(t)}}),oa=P({key:"fog3d",state:{color:me(),near:w(),far:w(),density:w()},render:(n,e)=>{let t={};e.color!==void 0&&(t.color=e.color),e.density!==void 0?t.density=e.density:(e.near!==void 0&&(t.near=e.near),e.far!==void 0&&(t.far=e.far)),n.fog(t)}}),ia=P({key:"environment3d",state:{src:w(),faces:w(),preset:w(),intensity:w(),background:w(),blur:w()},render:(n,e)=>{if(e.src===void 0&&e.faces===void 0&&e.preset===void 0)return n.environment(null);let t=Xo(e,["src","faces","preset","intensity","background","blur"]);(e.rotationX||e.rotationY||e.rotationZ)&&(t.rotation=[e.rotationX,e.rotationY,e.rotationZ]),n.environment(t)}});var aa=T({key:"canvas3d",state:{...F,...B,...Se,...Zo},defaults:{width:"fill",height:"fill"},commands:{...$,...Qo},allowedChildren:["2d","3d"],load:n=>ei(n),measure:(n,e,t)=>K(n,e,t,E(e)),layout:(n,e,t)=>z(n,e,t,E(e)),render:(n,e)=>ti(n,e)});function Ue(n){return n.kind==="still"}function Ry(n){return n.kind==="composition"}function ln(n){return n.kind==="audio"}function Ud(n){return n.kind!=="still"}var b="";function U(n){let e=n;return{start:e.startAt??0,end:e.endAt??1/0}}function zy(n,e){return Ge(new Map(n.map(t=>[t.id,t])),e)}function ca(n){let e=new Map(n.map(o=>[o.id,o])),t=new Map,s=[],r=new Set;for(let o of e.values()){if(t.has(o.id))continue;s.length=0,r.clear();let i,a=o;for(;a;){let c=t.get(a.id);if(c){i=c;break}if(r.has(a.id)){for(let d of s)t.set(d.id,Ge(e,d.id));s.length=0;break}s.push(a),r.add(a.id),a=a.parentId===null?void 0:e.get(a.parentId)}for(let c=s.length-1;c>=0;c--){let d=U(s[c]);i&&(d.start=Math.max(d.start,i.start),d.end=Math.min(d.end,i.end)),t.set(s[c].id,d),i=d}}return t}function Ge(n,e){let t=n.get(e);if(!t)return;let s=U(t),r=new Set;for(;t.parentId!==null&&!r.has(t.id);){r.add(t.id);let o=n.get(t.parentId);if(!o)break;let i=U(o);s.start=Math.max(s.start,i.start),s.end=Math.min(s.end,i.end),t=o}return s}function Ly(n){let{startAt:e,endAt:t,...s}=n;return s}function Gd(n){let e=n.duration??0;return e<=0||!n.loop||n.loop.count===null?e:e*io(n.loop)}function ue(n){if(!Ud(n))return 0;if(n.duration!==void 0)return n.duration;let e=0;for(let t of n.commands)e=Math.max(e,t.at+Gd(t));for(let t of n.nodes)t.startAt!==void 0&&(e=Math.max(e,t.startAt)),t.endAt!==void 0&&Number.isFinite(t.endAt)&&(e=Math.max(e,t.endAt));return e}function Yd(n){return typeof n=="object"&&n!==null&&n.kind==="project"}function da(n,e={}){return Yd(n)?n:{kind:"project",...n.formatVersion!==void 0&&{formatVersion:n.formatVersion},name:e.name??"Untitled",fps:e.fps,viewport:e.viewport,theme:n.theme,tracks:[{id:"clip",clip:n,duration:ue(n)}]}}var Xs=3,kt=class extends Error{version;supported;constructor(e,t=3){super(`This document is format ${e}, newer than this engine reads (format ${t}). Open it with a newer engine.`),this.name="DocumentTooNewError",this.version=e,this.supported=t}},ua=[{from:0,description:"Documents start carrying `formatVersion`; a clip's retired `constants` rows become `variables`.",clip:(n,e)=>{if(!Array.isArray(n.constants))return n;let{constants:t,...s}=n,r=Array.isArray(s.variables)?[...s.variables]:[];for(let o of t){if(typeof o!="object"||o===null){r.push(o);continue}let{kind:i,...a}=o;r.push(a)}return e("constants",`${t.length} constant row(s) moved into \`variables\`.`),{...s,variables:r}}},{from:1,description:'SkSL is retired: every shader fill, shader effect and shader pack written in it says `language: "sksl"`, the `sksl` effect key becomes `shader`, and `coords` is dropped.',clip:(n,e)=>Ys(n,"",e)},{from:2,description:"An image or video fill's retired `filters` prop moves into `preset.adjustments`.",clip:(n,e)=>Ws(n,"",e)}],Wd=/\b(?:half4|float4|vec4)\s+main\s*\(|^\s*uniform\s+\w+\s+\w+/m,bt=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function Ys(n,e,t){if(Array.isArray(n)){let r;return n.forEach((o,i)=>{let a=Ys(o,`${e}[${i}]`,t);a!==o&&((r??=[...n])[i]=a)}),r??n}if(!bt(n))return n;let s;for(let[r,o]of Object.entries(n)){let i=Ys(o,e?`${e}.${r}`:r,t);i!==o&&((s??={...n})[r]=i)}return Xd(s??n,e,t)}function Xd(n,e,t){let s=n.type==="sksl";if(!(s||n.type==="shader"&&(typeof n.source=="string"||typeof n.shader=="string")||(n.scope==="fill"||n.scope==="effect")&&typeof n.source=="string"))return n;let o={...n};s&&(o.type="shader");let i=o.type==="shader"&&typeof o.shader=="string"&&o.source===void 0;i&&(o.source=o.shader,delete o.shader);let a=o.language==="sksl"||o.language===void 0&&(s||Wd.test(typeof o.source=="string"?o.source:"")),c=a&&o.language===void 0;c&&(o.language="sksl");let d="coords"in o;return delete o.coords,a?t(e,"SkSL shaders no longer draw; port it to WGSL."):s?t(e,"The retired `sksl` effect key is now `shader`."):i?t(e,"The shader's `shader` field is now `source`."):d&&t(e,"`coords` dropped; it only ever applied to SkSL."),s||i||c||d?o:n}function Ws(n,e,t){if(Array.isArray(n)){let d;return n.forEach((u,l)=>{let f=Ws(u,`${e}[${l}]`,t);f!==u&&((d??=[...n])[l]=f)}),d??n}if(!bt(n))return n;let s;for(let[d,u]of Object.entries(n)){let l=Ws(u,e?`${e}.${d}`:d,t);l!==u&&((s??={...n})[d]=l)}let r=s??n;if(!("filters"in r)||!(r.type==="image"||r.type==="video")||typeof r.src!="string")return r;let{filters:o,preset:i,...a}=r,c=bt(i)&&i.adjustments!==void 0;return t(e,c?"`filters` dropped; the fill's `preset.adjustments` already says the grade.":"`filters` moved to `preset.adjustments`."),c||i!==void 0&&!bt(i)?{...a,preset:i}:{...a,preset:{...bt(i)?i:{},adjustments:o}}}function qs(n){if(typeof n!="object"||n===null)return 0;let e=n.formatVersion;if(e===void 0)return 0;if(typeof e!="number"||!Number.isInteger(e)||e<0)throw new TypeError(`formatVersion must be a whole number >= 0 (got ${JSON.stringify(e)}).`);return e}function Hs(n){return qd(n,ua,3)}function qd(n,e,t){let s=qs(n);if(s>t)throw new kt(s,t);if(typeof n!="object"||n===null||Array.isArray(n))return{document:n,from:s,to:s,changes:[]};let r=[],o=n;return{document:o.kind==="project"?Hd(o,s,e,t,r):ha(o,s,e,t,r,""),from:s,to:t,changes:r}}function la(n,e,t){let s=[];for(let r=n;r<e;r++){let o=t.find(i=>i.from===r);if(!o)throw new Error(`No document migration from format ${r} to ${r+1}.`);s.push(o)}return s}function fa(n,e,t){return(s,r)=>n.push({from:e,path:t&&s?`${t}.${s}`:t||s,message:r})}function ha(n,e,t,s,r,o,i=!0){if(e===s)return n;let a=n;for(let c of la(e,s,t))c.clip&&(a=c.clip(a,fa(r,c.from,o)));return i?{...a,formatVersion:s}:a}function Hd(n,e,t,s,r){let o=n;if(e<s)for(let c of la(e,s,t))c.project&&(o=c.project(o,fa(r,c.from,"")));let i=!1,a=Array.isArray(o.tracks)?o.tracks.map((c,d)=>{if(typeof c!="object"||c===null)return c;let u=c.clip;if(typeof u!="object"||u===null||Array.isArray(u))return c;let l=u.formatVersion!==void 0,f=l?qs(u):e;if(f>s)throw new kt(f,s);let h=ha(u,f,t,s,r,`tracks[${d}].clip`,l);return h===u?c:(i=!0,{...c,clip:h})}):o.tracks;return e===s&&!i?n:{...o,...i?{tracks:a}:{},formatVersion:s}}var pa=new Set(["normal","reverse","alternate"]);function L(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function ie(n){return typeof n=="number"&&Number.isFinite(n)&&n>=0}function _a(n,e,t){if(n===void 0)return;if(!L(n)){t.push({path:e,message:"easing must be an object with a `kind`."});return}let{kind:s,args:r}=n;if(typeof s!="string"||!ds.has(s)){t.push({path:`${e}.kind`,message:`easing kind must be one of ${[...ds].join(", ")} (got ${JSON.stringify(s)}).`});return}s==="custom"&&r!==void 0&&typeof r!="string"&&!cs(r)&&t.push({path:`${e}.args`,message:"a custom easing's args must be its curve \u2014 two or more `{ x, y }` points \u2014 or a registered ease's key."})}function wa(n,e,t){_a(n,e,t),L(n)&&n.kind==="custom"&&!cs(n.args)&&t.push({path:`${e}.args`,message:"an audio ease cannot name a registered ease; draw its curve (two or more `{ x, y }` points) instead."})}function ma(n,e,t){if(!(n===void 0||typeof n=="number"&&Number.isFinite(n)||I.isSource(n))){if(!L(n)||!Array.isArray(n.keys)){t.push({path:e,message:"must be a finite number, an expression or a ramp, `{ keys: [{ at, value }, \u2026] }`."});return}n.keys.forEach((s,r)=>{let o=`${e}.keys[${r}]`;if(!L(s)){t.push({path:o,message:"a ramp key must be an object."});return}(s.at===void 0==(s.before===void 0)||!ie(s.at??s.before))&&t.push({path:o,message:"a ramp key needs exactly one of `at` (seconds after the start) or `before` (seconds before the end), >= 0."}),(typeof s.value!="number"||!Number.isFinite(s.value))&&t.push({path:`${o}.value`,message:"a ramp key's value must be a finite number."}),wa(s.ease,`${o}.ease`,t)})}}var Jd=new Set(["duration","curve"]);function ga(n,e,t){if(n!==void 0){if(!L(n)){t.push({path:e,message:"a transition must be an object, `{ duration, curve? }`."});return}ie(n.duration)||t.push({path:`${e}.duration`,message:"a transition's duration must be a finite number of seconds >= 0."}),n.curve!==void 0&&n.curve!=="equalPower"&&wa(n.curve,`${e}.curve`,t);for(let s of Object.keys(n))Jd.has(s)||t.push({path:`${e}.${s}`,message:`a transition has no "${s}" (yet): only duration and curve.`})}}function Zd(n,e,t,s){"filters"in e&&s.push({path:`${t}.filters`,message:"audio `filters` was renamed to `effects`."});for(let o of["volume","pan",...n==="sound"?["speed"]:[]])ma(e[o],`${t}.${o}`,s);n==="sound"&&e.loop===!0&&L(e.speed)&&s.push({path:`${t}.speed`,message:"a looping sound cannot ramp its speed: there is no one pass of the source for the ramp to run over."});let r=e.effects;r!==void 0&&(Array.isArray(r)?r:[r]).forEach((i,a)=>{let c=Array.isArray(r)?`${t}.effects[${a}]`:`${t}.effects`;if(!L(i)||typeof i.type!="string"){s.push({path:c,message:"an effect must be an object with a `type`."});return}for(let[d,u]of Object.entries(i))d!=="type"&&ma(u,`${c}.${d}`,s)}),ga(e.transitionIn,`${t}.transitionIn`,s),ga(e.transitionOut,`${t}.transitionOut`,s)}function Qd(n,e,t){if(n===void 0)return;if(!L(n)){t.push({path:e,message:"loop must be an object with a `count`."});return}let{direction:s,count:r}=n;r!==null&&(typeof r!="number"||!Number.isInteger(r)||r<0)&&t.push({path:`${e}.count`,message:"loop count must be a whole number of repeats >= 0, or null to repeat for the rest of the clip."}),s!==void 0&&!pa.has(s)&&t.push({path:`${e}.direction`,message:`loop direction must be one of ${[...pa].join(", ")} (got ${JSON.stringify(s)}).`})}function eu(n,e,t){if(!L(n))return t.push({path:e,message:"node must be an object."}),!1;let s=!0,{id:r,type:o,parentId:i,layerOrder:a,props:c,key:d}=n;return typeof r!="string"&&(t.push({path:`${e}.id`,message:"id must be a string."}),s=!1),(typeof o!="string"||o.length===0)&&(t.push({path:`${e}.type`,message:"type must be a non-empty string."}),s=!1),i!==null&&typeof i!="string"&&(t.push({path:`${e}.parentId`,message:"parentId must be a node id or null."}),s=!1),(typeof a!="number"||!Number.isFinite(a))&&(t.push({path:`${e}.layerOrder`,message:"layerOrder must be a finite number."}),s=!1),L(c)?(o==="sound"||o==="audioBus")&&Zd(o,c,`${e}.props`,t):(t.push({path:`${e}.props`,message:"props must be an object (`{}` when nothing is set)."}),s=!1),d!==void 0&&(typeof d!="string"||d.length===0?(t.push({path:`${e}.key`,message:"key must be a non-empty string when present."}),s=!1):(d.includes("]")||d.includes("."))&&(t.push({path:`${e}.key`,message:`node key "${d}" cannot contain "]" or "." \u2014 it is referenced as "[${d}.prop]".`}),s=!1)),s}function xa(n,e){let t=new Map;for(let s of n){let r=s.spec.key;if(typeof r!="string"||r.length===0)continue;let o=t.get(r);if(o){e.push({path:`${s.path}.key`,message:`duplicate node key "${r}" (also declared at ${o.path}).`});continue}t.set(r,s)}return t}function tu(n,e,t,s){n.id===""&&(n.type!==t||n.parentId!==null)&&s.push({path:e,message:`the node with id "" is this document's root and must be \`{ type: "${t}", parentId: null }\`.`})}function nu(n,e,t){if(!L(n))return t.push({path:e,message:"command must be an object."}),!1;let s=!0,{id:r,type:o,targetId:i,at:a,duration:c,args:d}=n;return(typeof r!="string"||r.length===0)&&(t.push({path:`${e}.id`,message:"id must be a non-empty string."}),s=!1),(typeof o!="string"||o.length===0)&&(t.push({path:`${e}.type`,message:"type must be a non-empty string."}),s=!1),i!==null&&typeof i!="string"&&(t.push({path:`${e}.targetId`,message:"targetId must be a node id, or null for the scene root."}),s=!1),ie(a)||(t.push({path:`${e}.at`,message:"at must be a finite number of seconds >= 0."}),s=!1),c!==void 0&&!ie(c)&&(t.push({path:`${e}.duration`,message:"duration must be a finite number of seconds >= 0."}),s=!1),L(d)||(t.push({path:`${e}.args`,message:"args must be an object (`{}` when there are none)."}),s=!1),_a(n.easing,`${e}.easing`,t),Qd(n.loop,`${e}.loop`,t),s}function su(n,e,t){if(!L(n))return t.push({path:e,message:"variable must be an object."}),!1;let s=!0,{id:r,name:o,value:i,lerp:a}=n;return typeof r!="string"||r.length===0?(t.push({path:`${e}.id`,message:"id must be a non-empty string."}),s=!1):r.includes("]")&&(t.push({path:`${e}.id`,message:`variable id "${r}" cannot contain "]" \u2014 it is referenced as "[${r}]".`}),s=!1),o!==void 0&&typeof o!="string"&&(t.push({path:`${e}.name`,message:"name must be a string when present."}),s=!1),"value"in n?I.isSource(i)&&(t.push({path:`${e}.value`,message:"a variable holds a value, not an expression \u2014 only a node prop can be bound."}),s=!1):(t.push({path:`${e}.value`,message:"value is required \u2014 a variable is what it holds before anything changes it."}),s=!1),a!==void 0&&typeof a!="string"&&(t.push({path:`${e}.lerp`,message:"lerp must be a registered lerp key when present."}),s=!1),s}function va(n,e){if(n===void 0)return[];if(!Array.isArray(n))return e.push({path:"variables",message:"variables must be an array."}),[];let t=[];return n.forEach((s,r)=>{let o=`variables[${r}]`;su(s,o,e)&&t.push({spec:s,path:o})}),t}function ba(n,e){let t=new Map;for(let s of n){let r=t.get(s.spec.id);if(r){e.push({path:`${s.path}.id`,message:`duplicate variable id "${s.spec.id}" (also declared at ${r.path}).`});continue}t.set(s.spec.id,s)}return t}function ka(n){let e=n.indexOf(".");return e<0?void 0:{key:n.slice(0,e),prop:n.slice(e+1)}}function Js(n,e,t,s,r){for(let o of I.collect(n,e)){let i=I.tryParse(o.source);if("error"in i){r.push({path:o.path,message:i.error});continue}for(let a of i.expression.refs){let c=ka(a);if(!c){if(t.has(a))continue;r.push({path:o.path,message:s.has(a)?`expression references "[${a}]", which is a node key \u2014 a node is not a value, so name the prop too: "[${a}.x]".`:`expression references "[${a}]", which this document does not declare. Declared: ${[...t].map(d=>`[${d}]`).join(", ")||"none"}.`});continue}if(c.key.length===0||c.prop.length===0||c.prop.includes(".")){r.push({path:o.path,message:`expression references "[${a}]", which is not a node reference \u2014 one is "[key.prop]".`});continue}s.has(c.key)||r.push({path:o.path,message:`expression references "[${a}]", but no node in this document is keyed "${c.key}". Keyed: ${[...s].join(", ")||"none"}.`})}}}function Zs(n,e,t,s){if(L(e))for(let r of Object.keys(e)){let o=[];for(let i of I.collect(e[r],`${t}.${r}`)){let a=I.tryParse(i.source);if(!("error"in a))for(let c of a.expression.refs)ka(c)&&o.push(c)}o.length>0&&s.push({id:`${n}.${r}`,path:`${t}.${r}`,reads:o})}}function Sa(n,e){let t=new Map(n.map(a=>[a.id,a])),s=new Set,r=[],o=new Set,i=a=>{let c=t.get(a);if(!c||s.has(a))return;let d=r.indexOf(a);if(d>=0){if(!o.has(a)){let u=[...r.slice(d),a];for(let l of u)o.add(l);e.push({path:c.path,message:`expression cycle ${u.join(" \u2192 ")} \u2014 a prop cannot read a prop that reads it back.`})}return}r.push(a);for(let u of c.reads)i(u);r.pop(),s.add(a)};for(let a of n)i(a.id)}function ru(n,e){let t=new Map;for(let r of n){if(t.has(r.spec.id)){e.push({path:`${r.path}.id`,message:`duplicate node id "${r.spec.id}".`});continue}t.set(r.spec.id,r)}for(let r of n){let o=r.spec.parentId;o!==null&&!t.has(o)&&e.push({path:`${r.path}.parentId`,message:`parentId "${o}" is not a node in this document.`})}let s=new Set;for(let{spec:r}of n){if(s.has(r.id))continue;let o=new Set,i=r;for(;i;){if(o.has(i.id)){e.push({path:`${t.get(i.id)?.path}.parentId`,message:`node "${i.id}" is its own ancestor \u2014 parent chain forms a cycle.`});break}if(o.add(i.id),s.has(i.id))break;let a=i.parentId;i=a===null?void 0:t.get(a)?.spec}for(let a of o)s.add(a)}}function Aa(n,e,t){for(let s of n){let r=e.get(s.id);r&&t.push({path:`${r.path}.id`,message:`"${s.id}" is already a node id \u2014 nodes and variables share one id space.`})}}function Ma(n,e){n.constants!==void 0&&e.push({path:"constants",message:"constants were merged into `variables` \u2014 move each row there and drop its `kind`."})}function Oa(n,e){let t=n.formatVersion;t!==void 0&&(typeof t!="number"||!Number.isInteger(t)||t<0?e.push({path:"formatVersion",message:"formatVersion must be a whole number >= 0 when present."}):t>3&&e.push({path:"formatVersion",message:`format ${t} is newer than this engine reads (${3}) \u2014 open it with a newer engine.`}))}var ou={visualTracks:"visual and audio tracks were merged into `tracks` \u2014 move each row there.",audioTracks:"visual and audio tracks were merged into `tracks` \u2014 move each row there.",backgrounds:"a background is a track \u2014 put it first in `tracks`.",overlays:"an overlay is a track \u2014 put it last in `tracks`.",commands:"a project has no commands \u2014 each clip carries its own.",constants:"a project has no constants \u2014 declare `variables` in each clip."};function Ta(n,e,t,s,r,o){let i=new Map([["",t]]);for(let a of n)i.set(a.spec.id,a.spec.type),r.hasNode(a.spec.type)||o.push({path:`${a.path}.type`,message:`node type "${a.spec.type}" is not registered.`});for(let{spec:a,path:c}of e){if(r.command(a.type))continue;if(a.targetId!==null&&s.has(a.targetId)){o.push({path:`${c}.type`,message:`"${a.type}" is not a variable command.`});continue}let d=i.get(a.targetId??"");d===void 0||!r.hasNode(d)||r.takesCommand(d,a.type)||o.push({path:`${c}.type`,message:`node type "${d}" has no command "${a.type}".`})}}function Ea(n,e,t){if(!Array.isArray(n))return t.push({path:"nodes",message:"nodes must be an array."}),[];let s=[];return n.forEach((r,o)=>{let i=`nodes[${o}]`;eu(r,i,t)&&(s.push({spec:r,path:i}),tu(r,i,e,t))}),ru(s,t),s}function iu(n,e,t){let{startAt:s,endAt:r}=n;s!==void 0&&!ie(s)&&t.push({path:`${e}.startAt`,message:"startAt must be a finite number of seconds >= 0."}),r!==void 0&&!ie(r)&&t.push({path:`${e}.endAt`,message:"endAt must be a finite number of seconds >= 0."}),ie(r)&&r<=(ie(s)?s:0)&&t.push({path:`${e}.endAt`,message:`endAt (${r}s) must be after startAt (${s??0}s).`}),n.id===""&&(s!==void 0||r!==void 0)&&t.push({path:e,message:"the root is present for the whole clip \u2014 it cannot carry startAt or endAt."})}function au(n,e,t){Ma(n,e),n.commands!==void 0&&e.push({path:"commands",message:"a still has no timeline, so no commands \u2014 make it a composition to animate it."});let s=ba(va(n.variables,e),e),r=Ea(n.nodes,"canvas2d",e);for(let u of r){let{startAt:l,endAt:f}=u.spec;(l!==void 0||f!==void 0)&&e.push({path:u.path,message:"a still has no timeline \u2014 drop startAt/endAt, or make it a composition."})}let o=r.map(u=>u.spec);Aa(o,s,e),t&&Ta(r,[],"canvas2d",s,t,e);let i=xa(r,e),a=new Set(s.keys()),c=new Set(i.keys()),d=[];for(let u of r)Js(u.spec.props,`${u.path}.props`,a,c,e),u.spec.key&&Zs(u.spec.key,u.spec.props,`${u.path}.props`,d);Sa(d,e)}function cu(n,e,t){Ca(n,"canvas2d",e,t)}function du(n,e,t){Ca(n,"audioBus",e,t)}var uu={add:"a node is a row in `nodes` \u2014 its `startAt` is when it enters.",variable:"a variable is declared in `variables`."};function Ca(n,e,t,s){if(Ma(n,t),!Array.isArray(n.commands)){t.push({path:"commands",message:"commands must be an array."});return}n.duration!==void 0&&!ie(n.duration)&&t.push({path:"duration",message:"duration must be a finite number of seconds >= 0."});let r=ba(va(n.variables,t),t),o=Ea(n.nodes,e,t);for(let p of o)iu(p.spec,p.path,t);let i=o.map(p=>p.spec);Aa(i,r,t);let a=xa(o,t),c=[],d=new Set;n.commands.forEach((p,g)=>{if(!nu(p,`commands[${g}]`,t))return;if(d.has(p.id)){t.push({path:`commands[${g}].id`,message:`duplicate command id "${p.id}".`});return}let m=uu[p.type];if(m){t.push({path:`commands[${g}].type`,message:`there is no "${p.type}" command \u2014 ${m}`});return}d.add(p.id),c.push({spec:p,path:`commands[${g}]`})});let u=new Map(i.map(p=>[p.id,p]));s&&Ta(o,c,e,r,s,t);for(let{spec:p,path:g}of c){if(p.targetId===null||r.has(p.targetId))continue;let m=Ge(u,p.targetId);m===void 0?t.push({path:`${g}.targetId`,message:`targetId "${p.targetId}" is not a node or variable in this document.`}):p.at<m.start&&t.push({path:`${g}.at`,message:`command runs at ${p.at}s but its target "${p.targetId}" is not present until ${m.start}s.`})}let l=new Set(r.keys()),f=new Set(a.keys());for(let p of o)Js(p.spec.props,`${p.path}.props`,l,f,t);for(let{spec:p,path:g}of c)Js(p.args,`${g}.args`,l,f,t);let h=[];for(let p of o)p.spec.key&&Zs(p.spec.key,p.spec.props,`${p.path}.props`,h);for(let{spec:p,path:g}of c){if(p.type!=="set"||p.targetId===null)continue;let m=u.get(p.targetId)?.key;m&&Zs(m,p.args,`${g}.args`,h)}Sa(h,t)}function Qs(n,e={}){let t=[];if(!L(n))return{valid:!1,issues:[{path:"",message:"document must be an object."}]};Oa(n,t);let{registry:s}=e,r=n.kind;return r==="still"?au(n,t,s):r==="composition"?cu(n,t,s):r==="audio"?du(n,t,s):t.push({path:"kind",message:`kind must be "still", "composition" or "audio" (got ${JSON.stringify(r)}).`}),{valid:t.length===0,issues:t}}function lu(n,e={}){let t=[];if(!L(n))return{valid:!1,issues:[{path:"",message:"document must be an object."}]};let s=n;s.kind!=="project"&&t.push({path:"kind",message:`kind must be "project" (got ${JSON.stringify(s.kind)}).`}),(typeof s.name!="string"||s.name.length===0)&&t.push({path:"name",message:"name must be a non-empty string."}),s.fps!==void 0&&(typeof s.fps!="number"||!(s.fps>0)||!Number.isFinite(s.fps))&&t.push({path:"fps",message:"fps must be a positive number when present."}),Oa(s,t);for(let[o,i]of Object.entries(ou))s[o]!==void 0&&t.push({path:o,message:i});if(!Array.isArray(s.tracks))return t.push({path:"tracks",message:"tracks must be an array."}),{valid:!1,issues:t};let r=new Set;return s.tracks.forEach((o,i)=>{let a=`tracks[${i}]`;if(!L(o)){t.push({path:a,message:"track must be an object."});return}let c=o;if(typeof c.id!="string"||c.id.length===0?t.push({path:`${a}.id`,message:"id must be a non-empty string."}):r.has(c.id)?t.push({path:`${a}.id`,message:`duplicate track id "${c.id}".`}):r.add(c.id),c.name!==void 0&&typeof c.name!="string"&&t.push({path:`${a}.name`,message:"name must be a string when present."}),c.startAt!==void 0&&!ie(c.startAt)&&t.push({path:`${a}.startAt`,message:"startAt must be a finite number of seconds >= 0."}),ie(c.duration)||t.push({path:`${a}.duration`,message:"duration is required, and must be a finite number of seconds >= 0."}),c.clip===void 0){t.push({path:`${a}.clip`,message:"clip is required \u2014 a track places a clip document inline."});return}for(let d of fu(c.clip,e))t.push({path:`${a}.clip${d.path?`.${d.path}`:""}`,message:d.message})}),{valid:t.length===0,issues:t}}var ya=new WeakMap;function fu(n,e){if(!L(n)||e.registry)return Qs(n,e).issues;let t=ya.get(n);return t||(t=Qs(n).issues,ya.set(n,t)),t}function Pa(n,e){let{valid:t,issues:s}=lu(n,e);if(!t){let r=s.map(o=>` ${o.path||"<root>"}: ${o.message}`).join(`
2
- `);throw new Error(`Invalid project document:
3
- ${r}`)}}function Zy(n,e){let{valid:t,issues:s}=Qs(n,e);if(!t){let r=s.map(o=>` ${o.path||"<root>"}: ${o.message}`).join(`
4
- `);throw new Error(`Invalid clip document:
5
- ${r}`)}return n}var hu=T({key:"missingNode2d"}),pu=P({key:"missingNode3d"}),mu=mt({key:"missingNodeAudio"}),Ia={"2d":hu.node,"3d":pu.node,audio:mu.node},gu=new Set(["effects","blend","clip","shadow"]),yu=Object.fromEntries(Object.entries(Ia).map(([n,e])=>[n,new Set(dt(Object.create(e.prototype)).map(t=>t.key).filter(t=>!gu.has(t)))])),Da=new WeakMap,er=Symbol("missingNodeType");function Fa(n,e,t){let s=new Ia[n]({...tr(n,t),id:e.id,...e.key!==void 0&&{key:e.key}});return Da.set(s,{type:e.type,props:e.props}),s}function tr(n,e){let t=yu[n],s={};for(let[r,o]of Object.entries(e))t.has(r)&&(s[r]=o);return s}function St(n){return Da.get(n)}function _u(n){let e={};for(let t of n.nodeKeys()){let s={};for(let[r,o]of Object.entries(n.describe(t)?.properties??{}))s[r]={kind:o.kind,...o.default!==void 0&&{default:JSON.parse(JSON.stringify(o.default))}};e[t]={properties:s,commands:n.commandKeys(t)}}return{nodes:e,commands:n.commandKeys()}}function wu(n,e){let t=[];for(let s of n.commands)e.commands.includes(s)||t.push({name:s,what:"command removed"});for(let[s,r]of Object.entries(n.nodes)){let o=e.nodes[s];if(!o){t.push({name:s,what:"node type removed"});continue}for(let[i,{default:a}]of Object.entries(r.properties)){let c=o.properties[i];c?JSON.stringify(a)!==JSON.stringify(c.default)&&t.push({name:`${s}.${i}`,what:"default changed"}):t.push({name:`${s}.${i}`,what:"prop removed"})}for(let i of r.commands)o.commands.includes(i)||t.push({name:`${s}.${i}`,what:"command removed"})}return t}var xu={canvas2d:Ie,provider:Ai,"theme-provider":Mi,"default-text-style":Si,rect:ui,ellipse:li,path:pi,polygon:fi,polygram:hi,boolean:mi,mask:gi,camera:wi,orbitCamera:xi,"rotated-box":vi,text:un,richtext:ki,number:bi,video:Ei,audioBus:Ti,sound:Oi,canvas3d:aa,group3d:Pi,mesh3d:Ii,box3d:Di,sphere3d:Fi,plane3d:$i,circle3d:ji,cylinder3d:Ni,cone3d:Ri,capsule3d:Vi,torus3d:zi,"torus-knot3d":Li,tube3d:Yi,lathe3d:Gi,extrude3d:Ui,ring3d:Bi,polyhedron3d:Ki,points3d:Xi,line3d:qi,sprite3d:Hi,instances3d:Wi,model3d:Ji,camera3d:ra,"ambient-light3d":Zi,"directional-light3d":ea,"point-light3d":ta,"spot-light3d":na,"hemisphere-light3d":Qi,"area-light3d":sa,fog3d:oa,environment3d:ia};function fn(n,e){return(t,s,r,o)=>{let i=t[n];if(typeof i!="function")throw new Error(`Command "${n}" is not available on ${t.constructor.name}.`);return i.call(t,{data:s[e],duration:r,easing:o})}}var vu={number:Wr,vector2:es,vector3:ys,color:((n,e,t)=>{let[s,r,o,i]=ns(ze(String(n)),ze(String(e)),t),a=c=>Math.round(Math.min(Math.max(c,0),1)*255);return`rgba(${a(s)}, ${a(r)}, ${a(o)}, ${Number(i.toFixed(4))})`}),step:((n,e,t)=>t>=1?e:n)};function $a(n){for(let[e,t]of Object.entries(xu))n.addNode(e,t);for(let[e,t]of Object.entries(vu))n.addLerp(e,t);n.addCommand("to",(e,t,s,r)=>e.to({data:{...t},duration:s,easing:r})),n.addCommand("set",(e,t)=>{let s=t;return Pe(0,()=>{e.set(s)})},{binds:!0}),n.addCommand("fillTo",fn("fillTo","fill"),{args:[{key:"fill",kind:"fills"}],method:"fillTo"}),n.addCommand("overlayTo",fn("overlayTo","overlay"),{args:[{key:"overlay",kind:"fills"}],method:"overlayTo"}),n.addCommand("strokeTo",fn("strokeTo","stroke"),{args:[{key:"stroke",kind:"strokes"}],method:"strokeTo"}),n.addCommand("shadowTo",fn("shadowTo","shadow"),{args:[{key:"shadow",kind:"shadows"}],method:"shadowTo"}),n.addVariableCommand("variableTo",(e,t,s,r)=>{let o=t.value,i=t.lerp,a=typeof i=="string"?n.lerp(i):void 0;if(i!==void 0&&!a)throw new Error(`A "lerp" param must name a registered lerp (variable "${e.id}"), got ${JSON.stringify(i)}. Registered: ${n.lerpKeys().join(", ")}.`);let c=a??e.lerp,d,u=!1;return Pe(s,l=>{u||(d=e.get(),u=!0),e.set(c(d,o,l))},r)}),n.addVariableCommand("variableSet",(e,t)=>Pe(0,()=>{e.set(t.value)})),n.addCommand("save",e=>Pe(0,()=>{e.save()}))}var nr=["globalThis","window","self","top","parent","frames","Function","importScripts","document","navigator","location","history","screen","customElements","fetch","XMLHttpRequest","WebSocket","EventSource","Request","Response","Headers","localStorage","sessionStorage","indexedDB","caches","cookieStore","crypto","Worker","SharedWorker","ServiceWorker","MessageChannel","BroadcastChannel","postMessage","alert","confirm","prompt","open","print","Notification"],bu=new Set(["eval","arguments"]),Na=nr.filter(n=>bu.has(n));if(Na.length>0)throw new Error(`DENIED_GLOBALS cannot contain ${Na.join(", ")}: strict mode forbids binding those names, so no dynamic node would link at all. See the note in this file.`);var ku=["@motionscript/sdk","motionscript","motion-script"],hn=class n{static MAX_SHADERS=512;strict;constructor(e={}){if(this._dynamicNodes=e.dynamicNodes,this.strict=e.strict===!0,e.builtins!==!1&&$a(this),Array.isArray(e.nodes))for(let t of e.nodes)this.addNode(t);else for(let[t,s]of Object.entries(e.nodes??{}))this.addNode(t,s);for(let[t,s]of Object.entries(e.lerps??{}))this.addLerp(t,s);for(let[t,s]of Object.entries(e.eases??{}))this.addEase(t,s);for(let[t,s]of Object.entries(e.shaders??{}))this.addShader(t,s)}addNode(e,t,s){let r=typeof t=="function",o=r?t:e,i=typeof o.node=="function"?o.node:o,a=r?s:t,c=r?e:Ht(i);if(c===void 0)throw new Error(`${i.name||"The class"} is no component, so it has no document key. Make it with component2d({ key }), or register it explicitly: addNode("myKey", TheClass).`);let d=typeof c=="string"?{key:c}:c,u=d.key,l=this._nodes.get(u);if(l){if(l.ctor===i)return this;if(!a?.replace)throw new Error(`Node type "${u}" is already registered to a different class (${l.ctor.name} vs ${i.name}). Keys must be unique \u2014 a document naming this type would otherwise resolve differently depending on registration order.`)}let f=new Map;for(let h of gs(Object.create(i.prototype)))f.set(h.key,{method:h.method,args:this._describeArgs(h.args),...h.entrance?{entrance:!0}:{}});return this._nodes.set(u,{key:u,ctor:i,commands:f,descriptor:this._describeEvolution(i,{...d,dimension:this._describeDimension(i),holds:this._describeHolds(i),properties:this._describeProperties(i)})}),this}async addNodeFromSource(e,t){if(!this._dynamicNodes)throw new Error("addNodeFromSource needs `dynamicNodes: { sdk, compile }` on the Registry constructor.");let s=await this._dynamicNodes.compile(e),r=this._evalNodeModule(s);return this.addNode(r,t),r}node(e){return this._nodes.get(e)}hasNode(e){return this._nodes.has(e)}nodeKeys(){return[...this._nodes.keys()].sort()}describe(e){return this._nodes.get(e)?.descriptor}instantiate(e,t){let s=this._nodes.get(e.type);if(!s)throw new Error(`Unknown node type "${e.type}" (node ${e.id}). This registry knows: ${this.nodeKeys().join(", ")||"nothing"}.`);let r=As(s.ctor),o=t??e.props;return new s.ctor({...r?Ao(r,o).props:o,id:e.id,...e.key!==void 0&&{key:e.key}})}addCommand(e,t,s){return this._claimed(e,t)?this:(this._commands.set(e,{key:e,scope:"node",factory:t,...s?.args?{args:this._describeArgs(s.args)}:{},binds:s?.binds,...s?.method?{method:s.method}:{}}),this)}addVariableCommand(e,t){return this._claimed(e,t)?this:(this._commands.set(e,{key:e,scope:"variable",factory:t}),this)}command(e){return this._commands.get(e)}nodeCommand(e,t){let r=this._nodes.get(e)?.commands.get(t);if(r)return(o,i,a,c)=>{let d=o[r.method];if(typeof d!="function")throw new Error(`Command "${t}" needs a "${r.method}" method on ${o.constructor.name}, which has none.`);let u={};for(let l of r.args)u[l.key]=i[l.key];return d.call(o,{data:u,duration:a,easing:c})}}takesCommand(e,t){let s=this._nodes.get(e);if(!s)return!1;if(s.commands.has(t))return!0;let r=this._commands.get(t);return r?.scope!=="node"?!1:r.method===void 0?!0:typeof s.ctor.prototype[r.method]=="function"}commandKeys(e){return[...e===void 0?this._commands.keys():this._nodes.get(e)?.commands.keys()??[]].sort()}addLerp(e,t){let s=this._lerps.get(e);if(s&&s!==t)throw new Error(`Variable lerp "${e}" is already registered to a different function. Keys must be unique.`);return this._lerps.set(e,t),this}lerp(e){return this._lerps.get(e)}lerpKeys(){return[...this._lerps.keys()].sort()}requireLerp(e,t,s){let r=e??(typeof t=="number"?"number":"step"),o=this._lerps.get(r);if(!o)throw new Error(`Unknown variable lerp "${r}" (${s}). Registered: ${this.lerpKeys().join(", ")||"none"}.`);return o}addEase(e,t){let s=this._eases.get(e);if(s&&s!==t)throw new Error(`Ease "${e}" is already registered to a different function. Keys must be unique.`);return this._eases.set(e,t),this}ease(e){return this._eases.get(e)}easeKeys(){return[...this._eases.keys()].sort()}addShader(e,t,s){let r=ci(t),o=this._shaders.get(e);if(o){if(o.scope===r.scope&&o.source===r.source&&o.name===r.name)return o;if(!s?.replace)throw new Error(`Shader "${e}" is already registered to a different pack ("${o.name}" vs "${r.name}"). Keys must be unique \u2014 a document naming this shader would otherwise resolve differently depending on registration order.`)}else if(this._shaders.size>=n.MAX_SHADERS)throw new Error(`Cannot register shader "${e}": the ${n.MAX_SHADERS}-shader ceiling is reached.`);return this._shaders.set(e,r),r}shader(e){return this._shaders.get(e)}fillShader(e){let t=this._shaders.get(e);return t?.scope==="fill"?t:void 0}effectShader(e){let t=this._shaders.get(e);return t?.scope==="effect"?t:void 0}shaderKeys(){return[...this._shaders.keys()].sort()}_nodes=new Map;_commands=new Map;_lerps=new Map;_eases=new Map;_shaders=new Map;_dynamicNodes;_evalNodeModule(e){let{sdk:t,modules:s}=this._dynamicNodes,r=c=>{if(ku.includes(c))return t;if(s&&Object.hasOwn(s,c))return s[c];let d=["@motionscript/sdk",...Object.keys(s??{})];throw new Error(`"${c}" isn't available to a custom node. It can require ${d.map(u=>`"${u}"`).join(", ")}; a host supplies more through \`dynamicNodes.modules\`.`)},o={exports:{}};new Function("exports","require","module",...nr,`"use strict";
6
- return function () {
7
- ${e}
8
- };`)(o.exports,r,o)();let a=o.exports.default;if(typeof a!="function"||Ht(typeof a.node=="function"?a.node:a)===void 0)throw new Error('This script must `export default` a component: `component2d({ key: "\u2026", \u2026 })`.');return a}_claimed(e,t){let s=this._commands.get(e);if(!s)return!1;if(s.factory===t)return!0;throw new Error(`Command type "${e}" is already registered to a different factory. Keys must be unique.`)}_describeProperties(e){let t={};for(let s of dt(Object.create(e.prototype))){let r=s.editor??{};t[s.key]={...r,kind:r.kind??this._inferKind(s.default),...s.default!==void 0?{default:s.default}:{}}}return t}_describeEvolution(e,t){let s=As(e);if(!s)return t;let r={...t.properties};for(let[i,a]of Object.entries(s.deprecated))r[i]&&(r[i]={...r[i],deprecated:a});let o=Object.keys(s.renamed).length>0?{renamed:{...s.renamed}}:{};return{...t,...o,properties:r}}_describeDimension(e){let t=Object.create(e.prototype).dimension;return typeof t=="string"?t:void 0}_describeHolds(e){let t=Object.create(e.prototype)._childTrees;return Array.isArray(t)?[...t]:void 0}_inferKind(e){switch(typeof e){case"number":return"number";case"string":return"text";case"boolean":return"boolean";case"object":return e===null?"unknown":Array.isArray(e)&&e.every(t=>typeof t=="number")?"vector":"object";default:return"unknown"}}_describeArgs(e){return(e??[]).map(t=>typeof t=="string"?{key:t,kind:"unknown"}:{kind:"unknown",...t})}};var Su="canvas3d";function Au(n,e,t){let s=new Set;for(let r=e;r!==void 0&&!s.has(r);r=n.describe(r)?.parentKey){if(r===t)return!0;s.add(r)}return!1}function pn(n,e,t,s){return t.some(r=>Au(n,e,r)||s.isA?.(e,r)===!0)}function Mu(n,e,t,s={}){let r=n.describe(e),o=t===null?void 0:n.describe(t);if(t!==null&&(o?.layout?.acceptsChildren===!1||o?.holds?.length===0))return{kind:"leaf",parent:t};let i=r?.within??[];if(i.length>0&&(t===null||!pn(n,t,i,s)))return{kind:"within",within:i};if(t!==null&&o?.closed===!0&&!pn(n,t,i,s))return{kind:"closed",parent:t};let a=t!==null&&(o?.dimension==="3d"||o?.holds?.includes("3d")===!0||pn(n,t,[Su],s));return r?.dimension==="3d"!==a?{kind:"dimension",parent:t}:null}function Ou(n,e,t,s={}){let r=n.describe(e)?.beside??[];return r.length===0||t.some(o=>pn(n,o,r,s))?null:{kind:"beside",beside:r}}function D_(n,e,t={}){let s=a=>a.parentId===b?null:a.parentId,r=new Map(e.map(a=>[a.id,a])),o=new Map;for(let a of e){if(a.id===b)continue;let c=o.get(s(a));c?c.push(a.type):o.set(s(a),[a.type])}let i=new Map;for(let a of e){if(a.id===b||!n.hasNode(a.type))continue;let c=s(a),d=c===null?null:r.get(c)?.type??null,u=Mu(n,a.type,d,t)??Ou(n,a.type,Tu(o.get(c)??[],a.type),t);u&&i.set(a.id,u)}return i}function Tu(n,e){let t=n.indexOf(e);return t===-1?[...n]:[...n.slice(0,t),...n.slice(t+1)]}var mn="@bus";function Eu(){return{id:mn,type:"audioBus",parentId:null,layerOrder:0,props:{}}}function Cu(){return{id:"",type:"canvas2d",parentId:null,layerOrder:0,props:{}}}function Pu(n){let e=[Cu()];n.nodes.some(Ra)||e.push(Eu());for(let t of n.nodes)e.push(Iu(t));return{kind:"composition",duration:n.duration,variables:n.variables,nodes:e,commands:n.commands.map(Du)}}function Ra(n){return n.id===""&&n.type==="audioBus"}function Iu(n){return Ra(n)?{...n,id:mn,parentId:null}:n.parentId===null||n.parentId===""?{...n,parentId:mn}:n}function Du(n){return n.targetId===null||n.targetId===""?{...n,targetId:mn}:n}function Fu(n){let e=new Set(n.commands.filter(s=>s.type==="play").map(s=>s.targetId)),t=[];for(let s of n.nodes){if(s.type!=="sound"&&s.type!=="video"||e.has(s.id))continue;let{start:r,end:o}=U(s),i=s.type==="video"?s.props.segments:void 0;if(Array.isArray(i)&&i.length>0){i.forEach((a,c)=>{t.push({id:`@play:${s.id}:${c}`,type:"play",targetId:s.id,at:r+a.at,duration:Number.isFinite(a.duration)?a.duration:0,args:{from:a.from,...a.speed!==void 0&&{speed:a.speed},...a.volume!==void 0&&{volume:a.volume}}})});continue}t.push({id:`@play:${s.id}`,type:"play",targetId:s.id,at:r,duration:Number.isFinite(o)?o-r:0,args:{}})}return t.length===0?n:{...n,commands:[...n.commands,...t]}}function Ye(n){let e=ln(n)?Pu(n):n;return Ue(e)?e:Fu(e)}var Va=["center","topLeft","topRight","bottomLeft","bottomRight","topCenter","bottomCenter","centerLeft","centerRight"],za={scope:"node",known:!0,lifecycle:!1,readsLayout:!1,writesLayout:!1};function At(n,e,t){let s=$u.has(e.type),r=n.command(e.type);if(r?.scope==="variable"){let f=Nu.has(e.type);return{scope:"variable",known:f,lifecycle:s,readsLayout:!f,writesLayout:!1}}let o=t??(e.targetId===null?Ya:void 0),i=o?n.node(o.type):void 0;if(!o)return null;if(!i)return n.strict?null:za;let a;if(r){if(a=Wa[e.type],a&&typeof gn(i.ctor,a[0])!="function")return null}else{let f=i.commands.get(e.type);if(!f)return n.strict?null:za;a=f.method===e.type?Xa[e.type]:void 0}let c=!s&&a!==void 0&&Xu(i.ctor,a);if(!c)return{scope:"node",known:c,lifecycle:s,readsLayout:!0,writesLayout:!0};let d=e.args??{},u=o.props??{},l=Yu(e.type,d);return{scope:"node",known:c,lifecycle:s,readsLayout:Gu(e.type,d,u,l),writesLayout:l===void 0||l.some(f=>!ir(n,o.type,f))}}function rr(n,e){return n!==null&&n.known&&!n.lifecycle&&Ru.has(e.type)&&I.collect(e.args??{},"").length===0}function Ka(n,e,t){let s=n.command(e.type),r=t??(e.targetId===null?Ya:void 0),o=s?s.scope==="node"?s.args:void 0:r?n.node(r.type)?.commands.get(e.type)?.args:void 0,i=[];for(let a of o??[]){let c=e.args?.[a.key];a.kind==="nodeRef"&&typeof c=="string"&&c!==""&&i.push(c)}return i}function yn(n,e){let t=n.node(e)?.ctor;return t!==void 0&&gn(t,"provideContext")!==gn(je,"provideContext")}function or(n){for(let e of I.collect(n,"")){let t=I.tryParse(e.source);if("error"in t||t.expression.refs.some(s=>s.includes(".")))return!0}return!1}function ir(n,e,t){let s=n.node(e);return s?s.descriptor.dimension==="audio"||Ua(n,e,t)?!0:qa().ctors.has(s.ctor)&&zu.has(t):!1}function Ua(n,e,t){let s=n.node(e)?.descriptor.dimension;return s==="3d"?ju.has(t):s==="2d"&&Lu.has(t)}function Ga(n,e,t){let r=n.node(e.type)?.descriptor.dimension==="3d"?Vu:Bu;return Ua(n,e.type,t)&&!Object.keys(e.props).some(o=>r.has(o))}var $u=new Set(["removeChildAt","addChildAt","reparent"]),Nu=new Set(["variableTo","variableSet"]),Ru=new Set(["to","set","moveTo","fadeTo","rotateTo","scaleTo","layoutTo","effectTo","pulse","wiggle","fillTo","strokeTo","shadowTo","overlayTo","progressTo","zoomTo","panTo","headingTo","variableTo","variableSet"]),zu=new Set(["x","y","rotation","scale","opacity","fill","stroke","shadow","overlay","effects","blend","transformOrigin","zoom","lookAt","heading"]),Lu=new Set(["x","y","rotation","scale","opacity"]),ju=new Set(["x","y","z","rotationX","rotationY","rotationZ","scaleX","scaleY","scaleZ"]),Bu=new Set(["center","topLeft","topRight","bottomLeft","bottomRight","topCenter","bottomCenter","centerLeft","centerRight"]),Vu=new Set(["position","rotation","scale"]),Ya={id:b,type:"canvas2d",parentId:null,layerOrder:0,props:{}},X=["to","_prepareStep","_writeProp"],Ne=["command","set","_writeProp"],Wa={to:X,set:["set","_writeProp"],save:["save"],fillTo:["fillTo",...Ne],overlayTo:["overlayTo",...Ne],strokeTo:["strokeTo",...Ne],shadowTo:["shadowTo",...Ne]},Xa={...Wa,restore:["restore","_prepareStep","_writeProp"],fadeTo:["fadeTo",...X],rotateTo:["rotateTo",...X],scaleTo:["scaleTo",...X],layoutTo:["layoutTo",...X],effectTo:["effectTo",...X],progressTo:["progressTo",...X],pulse:["pulse",...Ne],wiggle:["wiggle",...Ne],flash:["flash",...Ne],moveTo:["moveTo",...X,"command","set"],zoomTo:["zoomTo",...X],panTo:["panTo",...X],headingTo:["headingTo",...X],countTo:["countTo",...X],append:["append",...X],prepend:["prepend",...X],play:["play"]},Ku={fadeTo:["opacity"],rotateTo:["rotation"],scaleTo:["scale"],layoutTo:["width","height","padding"],effectTo:["effects"],progressTo:["start","end"],pulse:["scale"],wiggle:["rotation"],flash:["start","end"],moveTo:["x","y"],zoomTo:["zoom"],panTo:["lookAt"],headingTo:["heading"],fillTo:["fill"],overlayTo:["overlay"],strokeTo:["stroke"],shadowTo:["shadow"],play:[]},Uu=new Set(Object.keys(Xa).filter(n=>n!=="set"&&n!=="save"));function Gu(n,e,t,s){if(La(e)||n==="moveTo"&&typeof e.target=="string"&&e.target!=="")return!0;let r=La(t),o=Wu(t);return n==="save"||n==="restore"?r||o.size>0:Uu.has(n)?(n==="append"||n==="prepend"?["text"]:n==="countTo"?["value"]:s??[]).some(a=>o.has(a)||r&&(a==="x"||a==="y")):!1}function Yu(n,e){let t=Ku[n];if(t)return t;if(n!=="to"&&n!=="set")return;let s=[];for(let r of Object.keys(e))r==="size"?s.push("width","height"):n==="to"&&r==="pivot"?s.push("transformOrigin"):n==="to"&&Va.includes(r)?s.push("x","y","transformOrigin"):s.push(r);return s}function La(n){return Va.some(e=>n[e]!==void 0)}var ja=new WeakMap;function Wu(n){let e=ja.get(n);if(!e){let t=new Set;for(let s of Object.keys(n))or(n[s])&&t.add(s);ja.set(n,e=t)}return e}function gn(n,e){return n.prototype[e]}var Ba=new WeakMap;function Xu(n,e){let t=Ba.get(n);t||Ba.set(n,t=new Map);let s=t.get(e);return s===void 0&&(s=e.every(r=>{let o=gn(n,r);return o===void 0||qu(r).has(o)}),t.set(e,s)),s}var sr=null;function qa(){if(!sr){let n=new hn;sr={ctors:new Set(n.nodeKeys().map(e=>n.node(e).ctor)),methods:new Map}}return sr}function qu(n){let e=qa(),t=e.methods.get(n);if(!t){let s=new Set;for(let r of e.ctors)for(let o=r.prototype;o&&o!==Object.prototype;o=Object.getPrototypeOf(o)){let i=Object.getOwnPropertyDescriptor(o,n);i&&typeof i.value=="function"&&s.add(i.value)}e.methods.set(n,t=s)}return t}function N(n,e){if(n===e)return!0;if(typeof n!="object"||typeof e!="object"||n===null||e===null)return n!==n&&e!==e;if(Array.isArray(n)){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let o=0;o<n.length;o++)if(!N(n[o],e[o]))return!1;return!0}if(Array.isArray(e))return!1;let t=n,s=e,r=0;for(let o of Object.keys(t)){let i=t[o];if(i!==void 0&&(r++,!N(i,s[o])))return!1}for(let o of Object.keys(s))s[o]!==void 0&&r--;return r===0}function Hu(){return{identical:!0,kindChanged:!1,themeChanged:!1,rootChanged:!1,duration:!1,nodes:{added:new Set,removed:new Set,changed:new Set,respec:new Set,moved:new Set,span:new Set,reorderedParents:new Set},commands:{added:new Set,removed:new Set,changed:new Set,reorderedAts:new Set},variables:{added:new Set,removed:new Set,changed:new Set},remappedKeys:new Set}}function _n(n,e){let t=Hu();if(n===e)return t;if(n.kind!==e.kind)return t.kindChanged=!0,t.identical=!1,t;let s=Ha(n),r=Ha(e);t.themeChanged=!N(n.theme,e.theme),t.duration=ue(s)!==ue(r),n.nodes!==e.nodes&&Ju(s.nodes,r.nodes,t),n.variables!==e.variables&&el(s.variables??[],r.variables??[],t);let o=s.kind==="composition"?s.commands:[],i=r.kind==="composition"?r.commands:[];return n.commands!==e.commands&&Qu(o,i,t),t.identical=!t.themeChanged&&!t.rootChanged&&!t.duration&&t.remappedKeys.size===0&&ar(t.nodes)&&t.nodes.reorderedParents.size===0&&ar(t.commands)&&t.commands.reorderedAts.size===0&&ar(t.variables),t}function Ha(n){return Ye(n)}function ar(n){return n.added.size===0&&n.removed.size===0&&n.changed.size===0}var Ja={id:b,type:"canvas2d",parentId:null,layerOrder:0,props:{}};function Ju(n,e,t){let s=We(n),r=We(e),o=t.nodes,i=s.get(b)??Ja,a=r.get(b)??Ja;t.rootChanged=i!==a&&!Zu(i,a);for(let[l,f]of s){if(l===b)continue;let h=r.get(l);if(!h){o.removed.add(l);continue}if(f===h)continue;let p=!1;(f.type!==h.type||f.key!==h.key||!N(f.props,h.props))&&(o.respec.add(l),p=!0),f.parentId!==h.parentId&&(o.moved.add(l),p=!0),tc(f,h)||(o.span.add(l),p=!0),(p||f.layerOrder!==h.layerOrder)&&o.changed.add(l)}for(let l of r.keys())l!==b&&!s.has(l)&&o.added.add(l);let c=Za(n);for(let[l,f]of Za(e)){let h=c.get(l);h!==void 0&&h!==f&&t.remappedKeys.add(l)}let d=Qa(n),u=Qa(e);for(let[l,f]of d){let h=u.get(l);h&&!nc(f,h)&&o.reorderedParents.add(l)}}function Zu(n,e){return n.type===e.type&&n.key===e.key&&n.parentId===e.parentId&&n.layerOrder===e.layerOrder&&N(n.props,e.props)&&tc(n,e)}function tc(n,e){let t=U(n),s=U(e);return t.start===s.start&&t.end===s.end}function Qu(n,e,t){let s=We(n),r=We(e),o=t.commands;for(let[c,d]of s){let u=r.get(c);if(!u){o.removed.add(c);continue}d!==u&&(d.type!==u.type||d.targetId!==u.targetId||d.at!==u.at||(d.duration??0)!==(u.duration??0)||!N(d.easing,u.easing)||!N(d.loop,u.loop)||!N(d.args,u.args))&&o.changed.add(c)}for(let c of r.keys())s.has(c)||o.added.add(c);let i=ec(n),a=ec(e);for(let[c,d]of i){let u=a.get(c);u&&!nc(d,u)&&o.reorderedAts.add(c)}}function el(n,e,t){let s=We(n),r=We(e),o=t.variables;for(let[i,a]of s){let c=r.get(i);if(!c){o.removed.add(i);continue}a!==c&&(a.lerp!==c.lerp||!N(a.value,c.value))&&o.changed.add(i)}for(let i of r.keys())s.has(i)||o.added.add(i)}function We(n){let e=new Map;for(let t of n)e.set(t.id,t);return e}function Za(n){let e=new Map;for(let t of n)t.key&&e.set(t.key,t.id);return e}function Qa(n){let e=new Map;n.forEach((s,r)=>{if(s.id===b)return;let o=s.parentId??b,i=e.get(o);i||e.set(o,i=[]),i.push({id:s.id,order:s.layerOrder,index:r})});let t=new Map;for(let[s,r]of e)r.sort((o,i)=>o.order-i.order||o.index-i.index),t.set(s,r.map(o=>o.id));return t}function ec(n){let e=new Map;for(let t of n){let s=e.get(t.at);s||e.set(t.at,s=[]),s.push(t.id)}return e}function nc(n,e){let t=new Set(e),s=new Set(n),r=n.filter(i=>t.has(i)),o=e.filter(i=>s.has(i));if(r.length!==o.length)return!1;for(let i=0;i<r.length;i++)if(r[i]!==o[i])return!1;return!0}function tl(n){let e=n.indexOf(".");return e<0?void 0:{key:n.slice(0,e),prop:n.slice(e+1)}}function cr(n,e=""){let t=[],s=[],r=0,o=new Set;for(let i of I.collect(n,e)){let a=I.tryParse(i.source);if("error"in a){r++;continue}for(let c of a.expression.refs){if(o.has(c))continue;o.add(c);let d=tl(c);d?s.push([d.key,d.prop]):t.push(c)}}return{vars:t,keys:s,unparsable:r}}function ur(n){return new dr(Ye(n))}var nl=Object.freeze({vars:[],keys:[],unparsable:0}),sl=new Map,sc=[];function wn(n,e){return n!==void 0&&e>=n.start&&e<n.end}var dr=class{doc;nodes=new Map;nodeCount;variables=new Map;commands=new Map;ordered;byTarget=new Map;keyed=new Map;dependents={byVar:new Map,byKey:new Map};duration;issues={duplicateIds:!1,duplicateKeys:!1,unresolvedParent:!1,cycle:!1,invalidRoot:!1,unparsable:!1,unresolvedRefs:!1};constructor(e){this.doc=e,this.duration=ue(e);let t=e.kind==="composition"?e.commands:[];this._indexNodes(e.nodes),this.nodeCount=this.nodes.size-1;for(let s of e.variables??[])(this.variables.has(s.id)||this.nodes.has(s.id))&&(this.issues.duplicateIds=!0),this.variables.set(s.id,s);this.ordered=t.map((s,r)=>({spec:s,index:r})).sort((s,r)=>s.spec.at-r.spec.at||s.index-r.index).map(s=>s.spec);for(let s of this.ordered){this.commands.has(s.id)&&(this.issues.duplicateIds=!0),this.commands.set(s.id,s);let r=this.targetOf(s),o=this.byTarget.get(r);o||this.byTarget.set(r,o=[]),o.push(s.id);let i=this._byAt.get(s.at);i||this._byAt.set(s.at,i=[]),i.push(s)}this._ats=[...this._byAt.keys()],this._indexRefs(t)}children(e){return this._children.get(e)??sc}descendants(e){let t=[],s=new Set([e]),r=[...this.children(e)].reverse();for(;r.length>0;){let o=r.pop();if(s.has(o))continue;s.add(o),t.push(o);let i=this.children(o);for(let a=i.length-1;a>=0;a--)r.push(i[a])}return t}ownSpan(e){let t=this.nodes.get(e);return t?U(t):void 0}effSpan(e){let t=this._eff.get(e);if(t)return t;if(!this.nodes.has(e))return;let s=[],r=new Set,o={start:0,end:1/0},i=this.nodes.get(e);for(;i;){let a=this._eff.get(i.id);if(a){o=a;break}if(r.has(i.id)||(r.add(i.id),s.push(i),i.id===b||i.parentId===null))break;i=this.nodes.get(i.parentId)}for(let a=s.length-1;a>=0;a--){let c=U(s[a]);o={start:Math.max(o.start,c.start),end:Math.min(o.end,c.end)},this._eff.set(s[a].id,o)}return this._eff.get(e)}targetOf(e){return e.targetId??b}commandsAt(e){return this._byAt.get(e)??sc}bindings(e){return this._bindings.get(e)??sl}refs(e){return this._refs.get(e)??nl}initialKey(e){return wn(this.ownSpan(e),0)?wn(this.effSpan(e),0)?"mounted":"unmounted":"absent"}captureKey(e){let t=this.captureTime(e);return t===void 0?"none":wn(this.effSpan(e),t)?"arrival-mounted":"arrival-unmounted"}captureTime(e){let t=this.ownSpan(e);if(!t||wn(t,0))return;let s=0,r=this._ats.length;for(;s<r;){let i=s+r>>1;this._ats[i]<t.start?s=i+1:r=i}let o=this._ats[s];return o!==void 0&&o<t.end?o:void 0}_children=new Map;_eff=new Map;_byAt=new Map;_ats=[];_bindings=new Map;_refs=new Map;_indexNodes(e){let t=new Map;e.forEach((r,o)=>{if(this.nodes.has(r.id)&&(this.issues.duplicateIds=!0),this.nodes.set(r.id,r),r.key&&(this.keyed.has(r.key)&&(this.issues.duplicateKeys=!0),this.keyed.set(r.key,r.id)),r.id===b){(r.type!=="canvas2d"||r.parentId!==null)&&(this.issues.invalidRoot=!0);return}let i=r.parentId??b,a=t.get(i);a||t.set(i,a=[]),a.push({id:r.id,order:r.layerOrder,index:o})}),this.nodes.has(b)||this.nodes.set(b,{id:b,type:"canvas2d",parentId:null,layerOrder:0,props:{}});for(let[r,o]of t)o.sort((i,a)=>i.order-a.order||i.index-a.index),this._children.set(r,o.map(i=>i.id));let s=new Set([b]);for(let r of this.nodes.values()){r.parentId!==null&&!this.nodes.has(r.parentId)&&(this.issues.unresolvedParent=!0);let o=new Set,i=r;for(;i&&!s.has(i.id);){if(o.has(i.id)){this.issues.cycle=!0;break}o.add(i.id),i=i.parentId===null?void 0:this.nodes.get(i.parentId)}for(let a of o)s.add(a)}}_indexRefs(e){for(let t of this.nodes.values())this._bind(t.id,t.props);for(let t of e){if(t.type==="set"){let s=this.targetOf(t);if(this.nodes.has(s)){this._bind(s,t.args);continue}}cr(t.args).unparsable>0&&(this.issues.unparsable=!0)}for(let[t,s]of this._bindings){let r=new Set,o=new Map,i=0;for(let a of s.values()){for(let c of a.vars)r.add(c);for(let c of a.keys)o.set(`${c[0]}.${c[1]}`,c);i+=a.unparsable}this._refs.set(t,{vars:[...r],keys:[...o.values()],unparsable:i});for(let a of r){this.variables.has(a)||(this.issues.unresolvedRefs=!0);let c=this.dependents.byVar.get(a);c||this.dependents.byVar.set(a,c=new Set),c.add(t)}for(let[a]of o.values()){this.keyed.has(a)||(this.issues.unresolvedRefs=!0);let c=this.dependents.byKey.get(a);c||this.dependents.byKey.set(a,c=new Set),c.add(t)}}}_bind(e,t){if(t)for(let s of Object.keys(t)){let r=cr(t[s]);if(r.unparsable>0&&(this.issues.unparsable=!0),r.vars.length===0&&r.keys.length===0)continue;let o=this._bindings.get(e);o||this._bindings.set(e,o=new Map);let i=o.get(s);if(!i){o.set(s,r);continue}let a=new Set([...i.vars,...r.vars]),c=new Map([...i.keys,...r.keys].map(d=>[`${d[0]}.${d[1]}`,d]));o.set(s,{vars:[...a],keys:[...c.values()],unparsable:i.unparsable+r.unparsable})}}};var vn=class n{_finish;_tracks;_replayed;static build(e){let t=new Float64Array(e.length).fill(NaN),s=new Map,r=[],o=[],i=new Set;for(let a=0;a<e.length;a++){let c=e[a],d=Yt(c.command),u=d&&!rl(c.writes,i)?al(c.start,c.duration):NaN;if(Number.isNaN(u)){if(!d&&c.reads)for(let f of c.reads)i.add(f);r.push(a);continue}t[a]=u,u>(c.holdFrom??c.start)&&o.push(a);let l=new Set;pe({read:()=>{},write:f=>l.add(f)},()=>c.command.at(1));for(let f of l){let h=s.get(f),p={order:a,finish:u,end:f.snapshot()};h?h.push(p):s.set(f,[p])}}return r.length===e.length?null:new n(e,t,[...s].map(([a,c])=>new lr(a,c)),r,o)}holds(e){return!Number.isNaN(this._finish[e])}evaluate(e,t){let s=this._tracks,r=this._held;for(let f=0;f<s.length;f++){let h=r[f]=s[f].at(t);h>=0&&s[f].slot.restoreFrom(s[f].ends[h])}let o=this._replayed,i=this._long,a=this._binOf(t),c=this._binStart[a+1],d=0,u=this._binStart[a],l=0;for(;;){let f=d<o.length?o[d]:xn,h=u<c?this._binItems[u]:xn,p=l<i.length?i[l]:xn,g;if(f<h&&f<p)g=f,d++;else if(h<p)g=h,u++;else if(p!==xn)g=p,l++;else break;let m=e[g];if(!(t<(m.holdFrom??m.start)||this._finish[g]<=t)){m.command.at(t<m.start?0:ot(m.duration>0?(t-m.start)/m.duration:1));for(let x=this._fixStart[g];x<this._fixStart[g+1];x++){let _=this._fixTracks[x],v=r[_];v>=0&&s[_].order[v]>g&&s[_].slot.restoreFrom(s[_].ends[v])}}}}constructor(e,t,s,r,o){this._finish=t,this._tracks=s,this._replayed=r,this._held=new Int32Array(s.length);let i=1/0,a=-1/0;for(let h of o)i=Math.min(i,e[h].holdFrom??e[h].start),a=Math.max(a,t[h]);let c=Math.max(1,Math.min(ol,o.length));this._from=Number.isFinite(i)?i:0,this._width=a>i?(a-i)/c:1,this._bins=c;let d=Array.from({length:c},()=>[]),u=[];for(let h of o){let p=this._binOf(e[h].holdFrom??e[h].start),g=this._binOf(t[h]);if(g-p>il)u.push(h);else for(let m=p;m<=g;m++)d[m].push(h)}this._long=u,this._binStart=new Int32Array(c+1);for(let h=0;h<c;h++)this._binStart[h+1]=this._binStart[h]+d[h].length;this._binItems=Int32Array.from(d.flat());let l=new Map(s.map((h,p)=>[h.slot,p])),f=[];this._fixStart=new Int32Array(e.length+1);for(let h=0;h<e.length;h++){for(let p of e[h].writes){let g=l.get(p);g!==void 0&&f.push(g)}this._fixStart[h+1]=f.length}this._fixTracks=Int32Array.from(f)}_held;_from;_width;_bins;_binStart;_binItems;_long;_fixStart;_fixTracks;_binOf(e){let t=Math.floor((e-this._from)/this._width);return t<0?0:t>=this._bins?this._bins-1:t}};function rl(n,e){if(e.size===0)return!1;for(let t of n)if(e.has(t))return!0;return!1}var xn=2147483647,ol=1024,il=32,lr=class{slot;finish;order;ends;_best;constructor(e,t){this.slot=e,t.sort((r,o)=>r.finish-o.finish||r.order-o.order),this.finish=Float64Array.from(t,r=>r.finish),this.order=Int32Array.from(t,r=>r.order),this.ends=t.map(r=>r.end),this._best=new Int32Array(t.length);let s=0;for(let r=0;r<t.length;r++)this.order[r]>this.order[s]&&(s=r),this._best[r]=s}at(e){let t=0,s=this.finish.length;for(;t<s;){let r=t+s>>>1;this.finish[r]<=e?t=r+1:s=r}return t===0?-1:this._best[t-1]}};function al(n,e){if(!(e>0))return n;let t=r=>(r-n)/e>=1,s=n+e;if(!Number.isFinite(s))return NaN;for(let r=0;!t(s);r++){if(r===8)return NaN;s=rc(s,!0)}for(let r=0;r<8;r++){let o=rc(s,!1);if(!t(o))return s;s=o}return NaN}var fr=new Float64Array(1),cl=new BigInt64Array(fr.buffer);function rc(n,e){return n===0?e?Number.MIN_VALUE:-Number.MIN_VALUE:(fr[0]=n,cl[0]+=n>0===e?1n:-1n,fr[0])}var dl=16;function lc(n,e,t,s,r={}){if(t.kindChanged||t.themeChanged||oc(n)||oc(e))return null;let o=n.nodes.get(b),i=e.nodes.get(b);if(t.rootChanged&&!ul(o,i)||e.issues.unparsable||e.issues.unresolvedRefs||t.remappedKeys.size>0)return null;let a=ic(n,s),c=a&&ic(e,s);if(!a||!c)return null;let{added:d,removed:u,respec:l,moved:f,span:h,reorderedParents:p}=t.nodes,g=y=>(e.byTarget.get(y)?.length??0)>0,m=(y,S,C,W)=>y.byTarget.get(C)?.some(G=>W(S.get(G)))??!1,x=y=>m(n,a,y,S=>!S.known)||m(e,c,y,S=>!S.known),_=(y,S)=>{let C=y.nodes.get(S)?.type;return C===void 0||s.dimensionOf?.(C)!=="audio"},v=y=>_(n,y)||_(e,y),A=[];for(let y of e.nodes.keys())y!==b&&n.nodes.has(y)&&A.push(y);let M=new Set,O=y=>{let S=n.nodes.get(y)?.type,C=e.nodes.get(y)?.type;return S!==void 0&&s.isContextProvider(S)||C!==void 0&&s.isContextProvider(C)},H=y=>{if(!M.has(y)&&(M.add(y),O(y)))for(let S of e.descendants(y))M.add(S)},V=new Set;for(let y of l)ll(n,e,y,s)?V.add(y):H(y);for(let y of f)if(H(y),dc(n,y,s)||dc(e,y,s))for(let S of e.descendants(y))M.add(S);for(let y of[...d,...u])if(O(y))for(let S of e.descendants(y))M.add(S);let tt=!1;for(let y of A){let S=s.ctorOf(y);S!==void 0&&s.registeredCtor(e.nodes.get(y).type)!==S&&(H(y),v(y)&&(tt=!0)),g(y)&&n.initialKey(y)!==e.initialKey(y)&&H(y)}let D=new Set,J=new Set,oe=y=>{e.variables.has(y)?J.add(y):e.nodes.has(y)&&D.add(y)};for(let y of t.commands.added)oe(e.targetOf(e.commands.get(y)));for(let y of t.commands.removed)oe(n.targetOf(n.commands.get(y)));for(let y of t.commands.changed)oe(n.targetOf(n.commands.get(y))),oe(e.targetOf(e.commands.get(y)));for(let y of new Set([...n.byTarget.keys(),...e.byTarget.keys()]))pl(n.byTarget.get(y),e.byTarget.get(y))||oe(y);for(let y of t.commands.reorderedAts){for(let S of n.commandsAt(y))oe(n.targetOf(S));for(let S of e.commandsAt(y))oe(e.targetOf(S))}if(t.duration)for(let y of e.commands.values())y.loop?.count===null&&oe(e.targetOf(y));for(let y of t.variables.added)J.add(y);for(let y of t.variables.changed)J.add(y);let nt=new Set;for(let y of A)hl(n.effSpan(y),e.effSpan(y))?g(y)&&(n.captureKey(y)!==e.captureKey(y)||n.captureTime(y)!==e.captureTime(y))&&D.add(y):(nt.add(y),g(y)&&D.add(y));let ce=p.size>0||tt||[...d].some(y=>_(e,y))||[...u].some(y=>_(n,y))||[...f].some(v)||[...h].some(v)||[...l].some(y=>v(y)&&uc(n.nodes.get(y),e.nodes.get(y),s))||t.rootChanged&&uc(o,i,s),te=new Set([...d,...u,...nt,...V]);t.rootChanged&&te.add(b);let bd=[...ac(n,s),...ac(e,s)],Gr=(y,S)=>{let C=e.nodes.get(y)?.type;if(C===void 0||s.dimensionOf?.(C)==="audio")return!1;for(let[W,G]of e.bindings(y))if(S(G)&&!s.isLayoutNeutralProp(C,W))return!0;return!1},Yr=-1;for(;Yr!==D.size+J.size+M.size+te.size+(ce?1:0);){Yr=D.size+J.size+M.size+te.size+(ce?1:0);for(let y of M)g(y)&&D.add(y);for(let y of M)te.add(y);for(let y of D)te.add(y);for(let y of J)for(let S of e.dependents.byVar.get(y)??[])te.add(S),!ce&&Gr(S,C=>C.vars.includes(y))&&(ce=!0);for(let y of te)for(let S of fl(n,e,y))for(let C of e.dependents.byKey.get(S)??[])te.add(C),!ce&&Gr(C,W=>W.keys.some(([G])=>G===S))&&(ce=!0);for(let{reader:y,ref:S}of bd)(cc(n,S,te)||cc(e,S,te))&&te.add(y);for(let y of te)e.nodes.has(y)&&g(y)&&D.add(y);for(let y of D)y!==b&&x(y)&&H(y);if(!ce){for(let y of[...D,...J])if(m(n,a,y,S=>S.writesLayout)||m(e,c,y,S=>S.writesLayout)){ce=!0;break}}if(ce)for(let y of e.byTarget.keys())e.nodes.has(y)&&m(e,c,y,S=>S.readsLayout)&&D.add(y)}if(D.has(b)&&x(b))return null;let kd=Math.max((r.rebuildFraction??.5)*e.nodeCount,r.minRebuildNodes??dl);if(M.size>kd)return null;for(let y of M)V.delete(y);let st;if([...D,...J].some(y=>m(e,c,y,S=>S.readsLayout||!S.known)))st="all";else{st=new Set;let y=[],S=new Set;for(let C of D){let W=e.refs(C);W.vars.length===0&&W.keys.length===0||(e.byTarget.get(C)??[]).some(G=>e.commands.get(G).type!=="set")&&(S.add(C),y.push(C))}for(;y.length>0;){let C=e.refs(y.pop());for(let W of C.vars)!J.has(W)&&g(W)&&st.add(W);for(let[W]of C.keys){let G=e.keyed.get(W);G!==void 0&&(!D.has(G)&&g(G)&&st.add(G),S.has(G)||(S.add(G),y.push(G)))}}}let Jn=new Set([...u,...M]);for(let y of p)for(let S of e.children(y))n.nodes.has(S)&&Jn.add(S);for(let y of M)for(let S of e.children(y))Jn.add(S);let Zn=[];for(let y of new Set([...D,...M,...d])){if(!g(y))continue;let S=e.captureTime(y);S!==void 0&&Zn.push({at:S,id:y})}return Zn.sort((y,S)=>y.at-S.at),{prev:n,next:e,diff:t,added:d,removed:u,reinstantiate:M,inPlace:V,detach:Jn,dirtyNodes:D,dirtyVariables:J,replay:st,captures:Zn,layoutChanged:ce}}function oc(n){let{duplicateIds:e,duplicateKeys:t,unresolvedParent:s,cycle:r,invalidRoot:o}=n.issues;return e||t||s||r||o}function ic(n,e){let t=new Map;for(let s of n.ordered){let r=n.targetOf(s),o=n.nodes.get(r),i=e.traits(s,o);if(!i||i.lifecycle||(i.scope==="variable"?!n.variables.has(r):!o))return null;t.set(s.id,i)}return t}function ac(n,e){if(!e.nodeRefs)return[];let t=[];for(let s of n.ordered){let r=n.targetOf(s);for(let o of e.nodeRefs(s,n.nodes.get(r)))t.push({reader:r,ref:o})}return t}function cc(n,e,t){let s=new Set,r=e;for(;r!==void 0&&!s.has(r);){if(t.has(r))return!0;s.add(r);let o=n.nodes.get(r);if(!o||r===b)return!1;r=o.parentId??b}return!1}function dc(n,e,t){let s=new Set([e]),r=n.nodes.get(e);for(;r&&r.id!==b;){let o=r.parentId??b;if(s.has(o))return!1;if(s.add(o),r=n.nodes.get(o),r&&t.isContextProvider(r.type))return!0}return!1}function ul(n,e){let t=U(n),s=U(e);return n.type===e.type&&n.key===e.key&&n.parentId===e.parentId&&n.layerOrder===e.layerOrder&&t.start===s.start&&t.end===s.end}function ll(n,e,t,s){let r=n.nodes.get(t),o=e.nodes.get(t);if(!s.writesInPlace||r.type!==o.type||r.key!==o.key)return!1;let i=n.bindings(t),a=e.bindings(t);for(let c of new Set([...Object.keys(r.props),...Object.keys(o.props)]))if(!N(r.props[c],o.props[c])&&(o.props[c]===void 0||i.has(c)||a.has(c)||!s.writesInPlace(o,c)))return!1;return!0}function uc(n,e,t){if(n.type!==e.type||n.key!==e.key)return!0;for(let s of new Set([...Object.keys(n.props),...Object.keys(e.props)]))if(!N(n.props[s],e.props[s])&&!t.isLayoutNeutralProp(e.type,s))return!0;return!1}function fl(n,e,t){let s=[],r=n.nodes.get(t)?.key,o=e.nodes.get(t)?.key;return r&&s.push(r),o&&o!==r&&s.push(o),s}function hl(n,e){return n?.start===e?.start&&n?.end===e?.end}function pl(n,e){if(n===e)return!0;if(!n||!e||n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}function ml(n,e){if(n)return it(n,t=>e.ease(t),()=>e.easeKeys())}function gl(n){return n.map((e,t)=>({spec:e,index:t})).sort((e,t)=>e.spec.at-t.spec.at||e.index-t.index).map(e=>e.spec)}var yl=new Set;function fc(n,e,t){if(Yt(n))return yl;for(let s of t)e.reads.add(s);return e.reads}function hc(n,e){return n&&e?co(e):e}function _l(){return{id:b,type:"canvas2d",parentId:null,layerOrder:0,props:{}}}function pc(n){let e=[],t;for(let s of n){if(s.id===b&&s.type==="canvas2d"){t=s;continue}e.push(s)}return{root:t??_l(),rest:e}}function mc(n){let e=new Map;for(let t of n.nodes)e.set(t.id,U(t));return e.delete(b),e}var bn=class{canvas;constructor(e,t,s){this.canvas=s,this._doc=e,this._registry=t;let{root:r,rest:o}=pc(e.nodes);this._rootSpec=r,this._specs=o,this._varSpecs=e.variables??[],this._keyed=new Map([r,...o].filter(i=>!!i.key).map(i=>[i.key,i.id])),this._spans=mc(e),this._duration=ue(e)}get duration(){return this._duration}build(){this._buildVariables(),this._pristineRoot=ms(this.canvas),this._applyRootProps();for(let e of this._specs)this._live.set(e.id,{spec:e,node:this._instantiate(e),initial:Ae,initialStackDepth:0,baseline:Ae,baseStackDepth:0,presence:new ut(!1,null,be+e.id)});this._baseChildCount.set(b,this.canvas._allChildren.length);for(let[e,t]of this._live)this._baseChildCount.set(e,t.node._allChildren.length);this.syncPresence(0),this._root={spec:this._rootSpec,node:this.canvas,initial:Ae,initialStackDepth:0,baseline:Ae,baseStackDepth:0,presence:new ut(!0,null,be+b)};for(let e of this._live.values())Mt(e);Mt(this._root),this._baselined=new Set(this._present);for(let e of this._present)this._live.get(e)?.node.mounted===!1&&(this._baselined.delete(e),this._unmounted.add(e))}compile(e=()=>{}){this._settled=null,this._compileCommands(e),this._restoreBaselines();let t=this.syncPresence(0);(this._restoreDisplaced(this._collectDisplaced())||t)&&e(),this._holdEntrances(),this._indexSettled()}variableValue(e){return this._vars.get(e)?.cell.get()}variables(){return this._varSpecs}get presenceTime(){return this._presenceIndex().time}commandSounds(){let e=[];for(let t of this._placed){let s=Mo(t.command);if(s)for(let r of s.sounds)e.push({node:s.host,at:t.start+r.at,until:r.until===void 0?void 0:t.start+r.until,src:r.src,options:r.options})}return e}placedCommands(){return this._placed}issues(){let e=[];for(let{spec:t,node:s}of this._live.values()){let r=St(s);r&&e.push({code:"unknown-node-type",nodeId:t.id,type:r.type,message:`Unknown node type "${r.type}" (node ${t.id}): it builds as an empty placeholder, keeping its children.`})}return e.push(...this._skipped.values()),e}evaluateAt(e,t){if(t){lt(()=>this._restoreBaselines()),this._evaluateObserved(e,t);return}if(this._settled){this._restoreBaselines(this._wholeRestore);for(let{slot:s,baseline:r}of this._slotRestore)s.restoreFrom(r);this._settled.evaluate(this._placed,e);return}this._restoreBaselines();for(let s of this._placed){if(e<s.holdFrom)continue;let r=e<s.start?0:s.duration>0?(e-s.start)/s.duration:1;s.command.at(ot(r))}}syncPresence(e){let t=this._presenceIndex().crossed(e);if(t.length===0)return!1;let s=[],r=[];for(let i of t){let a=kn(i,e);a!==this._present.has(i.id)&&(a?s:r).push(i)}if(this._arrived=s,s.length===0&&r.length===0)return!1;r.sort(wc);for(let i of r){this._present.delete(i.id),i.siblings.add(i.slot,-1);let a=this._live.get(i.id);a&&(a.presence.set(!1),this._parentNodeOf(a.spec)?.remove(a.node))}s.sort(wc);let o=new Map;for(let i of s){let a=o.get(i.siblings);a?a.push(i):o.set(i.siblings,[i])}for(let[i,a]of o){a.sort((u,l)=>u.slot-l.slot);let c=i.parentId===b?this.canvas:this._live.get(i.parentId)?.node,d=this._baseChildCount.get(i.parentId)??0;for(let u of a){this._present.add(u.id);let l=d+i.before(u.slot);i.add(u.slot,1);let f=this._live.get(u.id);f&&(f.presence.set(!0),c?.addChildAt({data:{child:f.node,index:l}}))}}return!0}liveNode(e){return e===b?this.canvas:this._live.get(e)?.node}baselineProps(e){let t=e===b?this._root:this._live.get(e);if(!t)return;let s=t.baseline===Ae?t.initial:t.baseline,r={};for(let[o,i]of s)r[o]=i.fn?i.fn():i.value;return r}presenceSlot(e){return e===b?this._root?.presence:this._live.get(e)?.presence}variableSlot(e){return this._vars.get(e)?.cell}planUpdate(e){let t=this._docIndex??=ur(this._doc);return lc(t,ur(e),_n(this._doc,e),this._patchEnvironment())}applyUpdate(e,t,s){if(!this._root)throw new Error("ClipTimeline.applyUpdate needs a built timeline.");if(e.prev!==this._docIndex)throw new Error("This patch was planned against a different version of the document.");this._settled=null,this._restoreBaselines(),this.syncPresence(0),this._updateVariables(e),this._keyed.clear();for(let[l,f]of e.next.keyed)this._keyed.set(l,f);let r=this._updateStructure(e);for(let l of r){Mt(l);let f=l.spec.id;this._present.has(f)&&(l.node.mounted?this._baselined.add(f):this._unmounted.add(f))}for(let l of e.inPlace){let f=this._live.get(l);f&&this._writeInPlace(f,e.prev.nodes.get(l))}if(e.diff.rootChanged){let l=this.canvas;Wt(l,this._pristineRoot),l._stateStack.length=0,this._applyRootProps(),Mt(this._root)}for(let l of e.dirtyNodes){let f=l===b?this._root:this._live.get(l);f&&!r.has(f)&&_c(f)}s();let o=new Map;for(let l of this._placed)o.set(l.spec.id,l);let i=this._walkPatch(e,o,t),a=l=>e.dirtyNodes.has(l)||e.dirtyVariables.has(l),c=[],d=new Set;if(this._animated=[],this._animatedVars=[],this._animatedParts=[],!Ue(this._doc))for(let l of e.next.ordered){let f=i.get(l.id);if(!f&&!a(e.next.targetOf(l))){let h=o.get(l.id);h&&(f=h.spec===l?h:{...h,spec:l})}f&&(c.push(f),this._touch(f,d))}this._placed=c;for(let l of this._skipped.keys())e.next.commands.has(l)||this._skipped.delete(l);this._restoreBaselines();let u=this.syncPresence(0);(this._restoreDisplaced(this._collectDisplaced())||u)&&t(),this._holdEntrances(),this._indexSettled()}_doc;_registry;_rootSpec;_specs;_varSpecs;_spans;_duration;_docIndex=null;_pristineRoot=Ae;_live=new Map;_vars=new Map;_keyed;_placed=[];_skipped=new Map;_settled=null;_wholeRestore=[];_slotRestore=[];_root=null;_animated=[];_animatedVars=[];_animatedParts=[];_partBaselines=new WeakMap;_baseChildCount=new Map;_present=new Set;_baselined=new Set;_displaced=[];_unmounted=new Set;_presence=null;_arrived=[];_resolveVariable=e=>{let t=e.indexOf(".");if(t>0){let s=this._keyed.get(e.slice(0,t));if(s===void 0)return;let r=e.slice(t+1);return()=>this._nodeById(s)?.[r]}return this._vars.get(e)?.read};_nodeById(e){if(e===b)return this.canvas;let t=this._live.get(e);if(t)return oo!==null&&this._readPresence(t),t.node.mounted?t.node:void 0}_readPresence(e){let t=e;for(let s=0;t&&s<=this._live.size;s++)t.presence.get(),t=t.spec.parentId===null?void 0:this._live.get(t.spec.parentId)}_applyRootProps(){let{literal:e,bindings:t}=I.bindProps(this._rootSpec.props,this._resolveVariable);this.canvas.set({...e,...t})}_instantiate(e,t=this._specs){let s=Zt(this._registry,e.type,e.props).props,{literal:r,bindings:o,hasBindings:i}=I.bindProps(s,this._resolveVariable);if(!this._registry.strict&&!this._registry.hasNode(e.type)){let c=this._placeholderDimension(e,t),d=Fa(c,e,r),u=tr(c,o);return Object.keys(u).length>0&&d.set(u),d}let a=this._registry.instantiate(e,r);return i&&a.set(o),a}_buildVariables(){for(let e of this._varSpecs){if(this._vars.has(e.id))throw new Error(`Duplicate variable id "${e.id}". Ids must be unique \u2014 an expression writing "[${e.id}]" would otherwise name whichever declaration was read last.`);this._vars.set(e.id,this._liveVariable(e))}}_liveVariable(e){let t=new ut(e.value,null,Gt+e.id);return{spec:e,cell:t,read:()=>t.get(),target:this._variableTarget(e,t),baseline:e.value}}_variableTarget(e,t){let s=this._registry.requireLerp(e.lerp,e.value,`variable "${e.id}"`);return{id:e.id,get:()=>t.get(),set:r=>t.set(r),lerp:s}}_restoreBaselines(e=this._animated){this._restoreDisplaced(this._displaced);for(let t of this._animatedVars)t.cell.set(t.baseline);for(let t of e){let s=t.node;Wt(s,t.baseline),s._stateStack.length>t.baseStackDepth&&(s._stateStack.length=t.baseStackDepth)}for(let t of this._animatedParts)t.restoreFrom(this._partBaselines.get(t))}_compileCommands(e){if(Ue(this._doc))return;let t=new Set,s=gl(this._doc.commands),r=this._refBound(s),o=this._settleWindows(s,i=>this._readsLayout(s[i],r));for(let i=0;i<s.length;i++){let a=s[i];if(this.syncPresence(a.at)){for(let d of this._arrived)this._baselined.has(d.id)||this._baselineArrival(d.id);this._baselineMounted(),o[i]&&e()}let c=this._buildPlaced(a);c&&(this._placed.push(c),this._touch(c,t))}}_indexSettled(){let e=this._settled=vn.build(this._placed);if(!e)return;this._restoreBaselines();let t=new Set,s=new Map;this._placed.forEach((r,o)=>{let i=e.holds(o);i||t.add(r.owner);for(let a of r.writes){let c=a._host,d=c===null?void 0:c.id===b?this._root:this._live.get(c.id);d&&(i?s.has(d)?s.get(d).add(a):s.set(d,new Set([a])):t.add(d))}}),this._wholeRestore=[],this._slotRestore=[];for(let r of this._animated){let o=t.has(r)?null:xl(r,s.get(r));o?this._slotRestore.push(...o):this._wholeRestore.push(r)}}_collectDisplaced(){let e=[];for(let t of this._present){let s=this._live.get(t),r=s&&this._declaredParent(t);s&&r&&s.node.parent!==r&&e.push(s)}return e.sort((t,s)=>this._presenceIndex().row(t.spec.id).slot-this._presenceIndex().row(s.spec.id).slot),this._displaced=e}_restoreDisplaced(e){let t=!1;for(let s of e){let r=s.spec.id,o=this._presenceIndex().row(r),i=this._declaredParent(r);if(!o||!i||!this._present.has(r)||s.node.parent===i)continue;s.node.parent?.remove(s.node);let a=this._baseChildCount.get(o.siblings.parentId)??0;i.addChildAt({data:{child:s.node,index:a+o.siblings.before(o.slot)}}),t=!0}return t}_declaredParent(e){let t=this._presenceIndex().row(e)?.siblings.parentId;if(t!==void 0)return t===b?this.canvas:this._live.get(t)?.node}_baselineArrival(e){let t=this._live.get(e);if(t&&!t.node.mounted){this._unmounted.add(e);return}t&&pr(t),this._baselined.add(e),this._unmounted.delete(e)}_baselineMounted(){for(let e of this._unmounted){let t=this._live.get(e);t?t.node.mounted&&(pr(t),this._baselined.add(e),this._unmounted.delete(e)):this._unmounted.delete(e)}}_buildPlaced(e){let t=this._registry.command(e.type);if(t?.scope!=="variable"){let g=St(this._targetOrThrow(e).node);if(g)return this._skip(e,`Command ${e.id} ("${e.type}") targets "${e.targetId}", a placeholder for unknown node type "${g.type}"; it is skipped.`,e.type)}if(!t){let g=this._targetOrThrow(e).entry.spec.type,m=this._registry.nodeCommand(g,e.type);if(!m){let x=`Node type "${g}" has no command "${e.type}" (command ${e.id}). It publishes: ${this._registry.commandKeys(g).join(", ")||"none"}.`+(gc[e.type]?` ${gc[e.type]}`:"");if(this._registry.strict)throw new Error(x);return this._skip(e,`${x} It is skipped.`,e.type)}t={key:e.type,scope:"node",factory:m}}this._skipped.delete(e.id);let s=e.duration??0,r=ml(e.easing,this._registry),o=new hr(this._notePartWrite),i=ao(e.loop)?e.loop:void 0,a=g=>g&&i?uo(g,i,this._unlimitedFill(e.at)):g;if(t.scope==="variable"){let g=e.targetId===null?void 0:this._vars.get(e.targetId);if(!g)throw new Error(`Command ${e.id} ("${e.type}") targets variable "${e.targetId}", which this document does not declare.`);this._assertNoExpressions(e);let{factory:m}=t,x=rr(At(this._registry,e,void 0),e),_=pe(o,()=>yc(()=>a(hc(x,m(g.target,e.args,s,r)))));return{spec:e,start:e.at,holdFrom:e.at,entrance:!1,duration:i?_.duration:s,command:_,writes:o.writes,reads:fc(_,o,[g.cell]),readsLayout:o.readsLayout,owner:g}}let c=this._targetOrThrow(e),d=wl.has(e.type)?Zt(this._registry,c.entry.spec.type,e.args).props:e.args,u=t.binds?this._bindArgs(d):(this._assertNoExpressions(e),d),{factory:l}=t,f=rr(At(this._registry,e,c.entry.spec),e),h=pe(o,()=>yc(()=>a(hc(f,l(c.node,u,s,r))))),p=t.scope==="node"&&this._registry.node(c.entry.spec.type)?.commands.get(e.type)?.entrance===!0;return{spec:e,start:e.at,holdFrom:e.at,entrance:p,duration:i?h.duration:s,command:h,writes:o.writes,reads:fc(h,o,c.node.__cells?.slots.values()??[]),readsLayout:o.readsLayout,owner:c.entry}}_holdEntrances(){let e=new Map,t;for(let s of this._placed){if(s.holdFrom=s.start,s.entrance){let o=s.owner.spec.id;t??=new Map(this._specs.map(a=>[a.id,a]));let i=o===b?0:Ge(t,o)?.start??s.start;for(let a of s.writes)i=Math.max(i,e.get(a)??-1/0);i<s.start&&(s.holdFrom=Math.max(0,i))}let r=s.start+s.duration;for(let o of s.writes)r<=(e.get(o)??-1/0)||e.set(o,r)}}_unlimitedFill(e){return Math.max(0,this._duration-e)}_touch(e,t){this._touchOwner(e.owner,t);for(let s of e.writes){let r=s._host;if(r===null)continue;let o=r.id===b?this._root:this._live.get(r.id);o?this._touchOwner(o,t):this._partBaselines.has(s)&&!t.has(s)&&(t.add(s),this._animatedParts.push(s))}}_touchOwner(e,t){t.has(e)||(t.add(e),"cell"in e?this._animatedVars.push(e):this._animated.push(e))}_notePartWrite=e=>{let t=e._host;t===null||this._partBaselines.has(e)||t.id===b||this._live.has(t.id)||this._partBaselines.set(e,e.snapshot())};_bindArgs(e){let{literal:t,bindings:s}=I.bindProps(e,this._resolveVariable,"args");return{...t,...s}}_assertNoExpressions(e){let t=I.collect(e.args,"args");if(t.length===0)return;let{path:s,source:r}=t[0];throw new Error(`Command ${e.id} ("${e.type}") carries an expression at ${s}: ${JSON.stringify(r)}. Expressions bind a prop to a variable; they are not tween destinations. Bind the prop where the node is authored (or with a "set" command) and animate the variable with "variableTo" instead.`)}_skip(e,t,s){return this._skipped.set(e.id,{code:"unknown-command",commandId:e.id,...e.targetId!==null&&{nodeId:e.targetId},type:s,message:t}),null}_placeholderDimension(e,t){let s=new Map(t.map(i=>[i.id,i])),r=new Set,o=i=>{r.add(i.id);for(let u of t){if(u.parentId!==i.id)continue;let l=this._registry.describe(u.type)?.dimension;if(l)return l}let a=i.parentId===null?void 0:s.get(i.parentId);if(!a)return"2d";let c=this._registry.describe(a.type);if(!c)return r.has(a.id)?"2d":o(a);let d=(c.holds??[]).filter(u=>u!=="audio");return d.length===0?c.holds?.includes("audio")?"audio":c.dimension??"2d":d.find(u=>u!==c.dimension)??d[0]};return o(e)}_targetOrThrow(e){let t=this._targetOf(e);if(!t)throw new Error(`Command ${e.id} ("${e.type}") targets node "${e.targetId}", which this document does not declare.`);return t}_targetOf(e){if(e.targetId===null)return this._root?{id:b,node:this._root.node,entry:this._root}:null;let t=this._live.get(e.targetId);return t?{id:e.targetId,node:t.node,entry:t}:null}_evaluateObserved(e,t){let s=0;pe({read:()=>{},write:o=>t(s,o)},()=>{for(;s<this._placed.length;s++){let o=this._placed[s];if(e<o.holdFrom)continue;let i=e<o.start?0:o.duration>0?(e-o.start)/o.duration:1;o.command.at(ot(i))}})}_settleWindows(e,t){let s=this._presenceIndex(),r=new Uint8Array(e.length),o=-1,i=s.time;for(let a=0;a<e.length;a++){let{at:c}=e[a];s.differs(i,c)&&(o=a),i=c,!(o<0||r[o])&&t(a)&&(r[o]=1)}return r}_readsLayout(e,t){let s=e.targetId??b,r=e.targetId===null?this._rootSpec:this._live.get(e.targetId)?.spec,o=At(this._registry,e,r);return o===null||o.readsLayout||t.has(s)}_refBound(e){let t=new Set;for(let s of e){let r=this._registry.command(s.type);r?.scope==="node"&&r.binds&&or(s.args)&&t.add(s.targetId??b)}return t}_presenceIndex(){return this._presence??=new Sn(this._specs,this._spans)}_parentNodeOf(e){return e.parentId===null?this.canvas:this._live.get(e.parentId)?.node}_patchEnvironment(){let e=this._registry;return{traits:(t,s)=>At(e,t,s),nodeRefs:(t,s)=>Ka(e,t,s),isContextProvider:t=>yn(e,t),isLayoutNeutralProp:(t,s)=>ir(e,t,s),writesInPlace:(t,s)=>Ga(e,t,s),ctorOf:t=>{let s=this._live.get(t)?.node;return s&&St(s)?er:s?.constructor},registeredCtor:t=>e.node(t)?.ctor??(e.strict?void 0:er),dimensionOf:t=>e.node(t)?.descriptor.dimension}}_writeInPlace(e,t){let s={};for(let[i,a]of Object.entries(e.spec.props))N(t.props[i],a)||(s[i]=a);_c(e);let{literal:r,bindings:o}=I.bindProps(s,this._resolveVariable);e.node.set({...r,...o}),Mt(e)}_updateVariables(e){let{added:t,removed:s,changed:r}=e.diff.variables;for(let o of s)this._vars.delete(o);for(let o of t)this._vars.set(o,this._liveVariable(e.next.variables.get(o)));for(let o of r){let i=e.next.variables.get(o),a=this._vars.get(o);if(!a){this._vars.set(o,this._liveVariable(i));continue}a.baseline=i.value,a.target=this._variableTarget(i,a.cell)}for(let o of e.next.variables.values()){let i=this._vars.get(o.id);i&&(i.spec=o)}for(let o of e.dirtyVariables){let i=this._vars.get(o);i&&i.cell.set(i.baseline)}}_updateStructure(e){let{next:t}=e;for(let c of e.detach){let d=this._live.get(c);d&&(d.node.parent?.remove(d.node),d.presence.set(!1),this._present.delete(c))}let s=c=>this._live.get(c.id)?.node===c;for(let c of e.removed){let d=this._live.get(c);d&&(mr(d.node,s),this._live.delete(c),this._baseChildCount.delete(c),this._baselined.delete(c),this._unmounted.delete(c))}for(let c of e.reinstantiate){let d=this._live.get(c);d&&mr(d.node,s)}let{root:r,rest:o}=pc(t.doc.nodes),i=new Set;for(let c of o){let d=this._live.get(c.id);if(d&&!e.reinstantiate.has(c.id)){d.spec=c;continue}let u=this._instantiate(c,o);d?(d.spec=c,d.node=u,this._baselined.delete(c.id),this._unmounted.delete(c.id)):(d={spec:c,node:u,initial:Ae,initialStackDepth:0,baseline:Ae,baseStackDepth:0,presence:new ut(!1,null,be+c.id)},this._live.set(c.id,d)),this._baseChildCount.set(c.id,u._allChildren.length),i.add(d)}this._doc=t.doc,this._docIndex=t,this._rootSpec=r,this._root.spec=r,this._specs=o,this._varSpecs=t.doc.variables??[],this._spans=mc(t.doc),this._duration=ue(t.doc);let a=this._presence=new Sn(this._specs,this._spans);for(let c of[...this._present]){let d=a.row(c);if(d&&kn(d,0)){d.siblings.add(d.slot,1);continue}this._present.delete(c);let u=this._live.get(c);u&&(u.presence.set(!1),u.node.parent?.remove(u.node))}return this.syncPresence(0),i}_walkPatch(e,t,s){let r=new Map;if(Ue(this._doc))return r;let{next:o}=e,i=p=>e.dirtyNodes.has(p)||e.dirtyVariables.has(p),a=this._refBound(o.ordered),c=e.replay;c!=="all"&&[...a].some(i)&&(c="all");let d=[],{captures:u}=e,l=0;for(let p of o.ordered){for(;l<u.length&&u[l].at<=p.at;)d.push({at:u[l].at,capture:u[l++].id});let g=o.targetOf(p);(c==="all"||i(g)||c.has(g))&&d.push({at:p.at,spec:p})}for(;l<u.length;l++)d.push({at:u[l].at,capture:u[l].id});let f=this._settleWindows(d,p=>{let g=d[p].spec;return g!==void 0&&i(o.targetOf(g))&&this._readsLayout(g,a)}),h=!1;for(let p=0;p<d.length;p++){let g=d[p];if(f[p]&&(h=!0),this.syncPresence(g.at)&&this._baselineMounted(),g.capture!==void 0){this._baselined.delete(g.capture),this._baselineArrival(g.capture);continue}h&&(s(),h=!1);let m=g.spec,x=t.get(m.id);if(x&&!i(o.targetOf(m))){x.command.at(1);continue}let _=this._buildPlaced(m);_&&r.set(m.id,_)}return r}},gc={add:"A node is a row in `nodes`, entering at its `startAt`.",remove:"A node leaves at its `endAt`.",variable:"A variable is declared in `variables`."},Ae=new Map,wl=new Set(["to","set"]),hr=class{firstWrite;writes=new Set;reads=new Set;readsLayout=!1;constructor(e){this.firstWrite=e}read(e){e._name===Le&&(this.readsLayout=!0),this.reads.add(e)}write(e){this.writes.has(e)||(this.firstWrite(e),this.writes.add(e))}};function yc(n){let e=n();return e?(e.at(1),e):Pe(0,()=>{n()})}function pr(n){let e=n.node;n.baseline=ms(e),n.baseStackDepth=e._stateStack.length}function xl(n,e){if(!e)return[];let t=n.node.__cells?.slots;if(!t)return null;let s=[];for(let[r,o]of t){let i=e.has(o)?n.baseline.get(r):void 0;i&&s.push({slot:o,baseline:i})}return s.length===e.size?s:null}function Mt(n){pr(n),n.initial=n.baseline,n.initialStackDepth=n.baseStackDepth}function _c(n){let e=n.node;Wt(e,n.initial),e._stateStack.length>n.initialStackDepth&&(e._stateStack.length=n.initialStackDepth),n.baseline=n.initial,n.baseStackDepth=n.initialStackDepth}function mr(n,e){for(let t of n._allChildren)e(t)||mr(t,e);n.dispose()}function kn(n,e){return e>=n.start&&e<n.end}function wc(n,e){return n.order-e.order}var gr=class{parentId;constructor(e,t){this.parentId=e,this._tree=new Int32Array(t+1)}add(e,t){for(let s=e+1;s<this._tree.length;s+=s&-s)this._tree[s]+=t}before(e){let t=0;for(let s=e;s>0;s-=s&-s)t+=this._tree[s];return t}_tree},Sn=class{time=-1/0;constructor(e,t){let s=new Map;e.forEach((r,o)=>{if(!t.has(r.id))return;let i=r.parentId??b,a=s.get(i);a?a.push({spec:r,order:o}):s.set(i,[{spec:r,order:o}])});for(let[r,o]of s){o.sort((a,c)=>a.spec.layerOrder-c.spec.layerOrder);let i=new gr(r,o.length);o.forEach(({spec:a,order:c},d)=>{let{start:u,end:l}=t.get(a.id),f={id:a.id,start:u,end:l,order:c,slot:d,siblings:i,pass:0};this._rows.set(a.id,f),this._events.push({time:u,row:f}),Number.isFinite(l)&&this._events.push({time:l,row:f})})}this._events.sort((r,o)=>r.time-o.time)}crossed(e){this.time=e;let t=this._upperBound(e);if(t===this._cursor)return vl;let s=Math.min(t,this._cursor),r=Math.max(t,this._cursor);this._cursor=t;let o=++this._pass,i=[];for(let a=s;a<r;a++){let{row:c}=this._events[a];c.pass!==o&&(c.pass=o,i.push(c))}return i}differs(e,t){let s=this._upperBound(Math.min(e,t)),r=this._upperBound(Math.max(e,t));for(let o=s;o<r;o++){let{row:i}=this._events[o];if(kn(i,e)!==kn(i,t))return!0}return!1}row(e){return this._rows.get(e)}_events=[];_rows=new Map;_cursor=0;_pass=0;_upperBound(e){let t=0,s=this._events.length;for(;t<s;){let r=t+s>>>1;this._events[r].time<=e?t=r+1:s=r}return t}},vl=[];function Lw(n){let e=n.width??0,t=n.height??0,{x:s,y:r,pivot:o}=So(n,e,t);return{...ko(n),rotation:n.rotation??0,scale:n.scale??1,x:s,y:r,start:n.start??0,end:n.end??1,pivot:Jt(o),spans:n.spans??[],lineHeight:n.lineHeight??1.2,textAlign:n.textAlign??"center",width:e,height:t}}function Vw(n){return typeof n=="string"?n:n.map(e=>{switch(e.type){case"M":case"m":return`${e.type} ${e.x} ${e.y}`;case"L":case"l":return`${e.type} ${e.x} ${e.y}`;case"T":case"t":return`${e.type} ${e.x} ${e.y}`;case"H":case"h":return`${e.type} ${e.x}`;case"V":case"v":return`${e.type} ${e.y}`;case"C":case"c":return`${e.type} ${e.x1} ${e.y1} ${e.x2} ${e.y2} ${e.x} ${e.y}`;case"S":case"s":return`${e.type} ${e.x2} ${e.y2} ${e.x} ${e.y}`;case"Q":case"q":return`${e.type} ${e.x1} ${e.y1} ${e.x} ${e.y}`;case"A":case"a":return`${e.type} ${e.rx} ${e.ry} ${e.rotation} ${e.largeArc} ${e.sweep} ${e.x} ${e.y}`;case"Z":case"z":return e.type}}).join(" ")}function Kw(n){return{rotation:n.rotation??0,scale:n.scale??1,x:n.x??0,y:n.y??0,start:n.start??0,end:n.end??1,width:n.width??0,height:n.height??0,pivot:Jt(n.pivot),data:n.data??"",centerBounds:n.centerBounds}}function yr(n){let e=n.lines[n.lines.length-1];return e?e.end+1:1}function xc(n){return typeof n?.layoutTextBlock=="function"?n:null}function wr(n){return typeof n=="string"?{kind:"shader",message:n}:n}function An(n){return`${n.kind}|${n.feature??""}|${n.nodeId??""}|${n.feature?"":n.message}`}var _r=class extends Error{issue;name="RenderBackendError";retryable;constructor(e){super(e.message),this.issue=e,this.retryable=e.kind==="device-lost"}};function bl(n){return n.kind==="device-lost"||n.kind==="crashed"}var kl={box:n=>({type:"box",...n}),sphere:n=>({type:"sphere",...n}),plane:n=>({type:"plane",...n}),cylinder:n=>({type:"cylinder",...n}),cone:n=>({type:"cone",...n}),torus:n=>({type:"torus",...n}),torusKnot:n=>({type:"torusKnot",...n}),circle:n=>({type:"circle",...n}),ring:n=>({type:"ring",...n}),capsule:n=>({type:"capsule",...n}),tetrahedron:n=>({type:"polyhedron",shape:"tetrahedron",...n}),octahedron:n=>({type:"polyhedron",shape:"octahedron",...n}),icosahedron:n=>({type:"polyhedron",shape:"icosahedron",...n}),dodecahedron:n=>({type:"polyhedron",shape:"dodecahedron",...n}),extrude:n=>({type:"extrude",...n}),lathe:n=>({type:"lathe",...n}),tube:n=>({type:"tube",...n}),buffer:n=>({type:"buffer",...n}),parametric:n=>({type:"parametric",...n}),edges:(n,e)=>({type:"edges",source:n,...e}),wireframe:n=>({type:"wireframe",source:n}),model:(n,e)=>({type:"modelGeometry",src:n,...e})},Sl={basic:n=>({type:"basic",...n}),standard:n=>({type:"standard",...n}),physical:n=>({type:"physical",...n}),phong:n=>({type:"phong",...n}),lambert:n=>({type:"lambert",...n}),toon:n=>({type:"toon",...n}),normal:n=>({type:"normal",...n}),depth:n=>({type:"depth",...n}),matcap:n=>({type:"matcap",...n}),points:n=>({type:"points",...n}),lineBasic:n=>({type:"lineBasic",...n}),lineDashed:n=>({type:"lineDashed",...n}),sprite:n=>({type:"sprite",...n}),shadow:n=>({type:"shadow",...n}),shader:n=>({type:"shader",...n})},Al={image:(n,e)=>({src:n,...e}),data:(n,e,t,s)=>({data:n,width:e,height:t,...s}),surface:(n,e)=>({width:512,height:512,...e,source:n})};function Ml(n,e){return n===void 0?e.map(xr):typeof n=="number"?e.map(()=>xr(n)):e.map((t,s)=>xr(n[s]??t))}function xr(n){return Math.max(1,Math.floor(n))}function Ol(n,e){return e<=0?3:Math.max(3,Math.min(16,Math.round(n/e*40)))}function Tl(n){let e=[n.width/2,n.height/2,n.depth/2],t=Math.max(e[0],e[1],e[2]),s=Math.max(0,Math.min(n.radius,e[0],e[1],e[2])),r=[Math.max(0,e[0]-s),Math.max(0,e[1]-s),Math.max(0,e[2]-s)],o=Ol(s,t),i=[],a=[],c=[],d=[];for(let u of El(e,r,s,n.segments,o))Cl(u,e,i,a,c,d);return{type:"buffer",position:new Float32Array(i),normal:new Float32Array(a),uv:new Float32Array(c),index:new Uint32Array(d),staticData:!0}}function*El(n,e,t,s,r){let o=[0,1,2],i=[-1,1];for(let a of o){let c=(a+1)%3,d=(a+2)%3;for(let u of i){let l=Il(a,u);yield{uSteps:s[c],vSteps:s[d],normal:()=>l,position:(f,h)=>{let p=[0,0,0];return p[a]=u*n[a],p[c]=vr(-e[c],e[c],f),p[d]=vr(-e[d],e[d],h),p}}}}if(!(t<=0)){for(let a of o){let c=(a+1)%3,d=(a+2)%3;for(let u of i)for(let l of i)yield{uSteps:r,vSteps:s[a],normal:f=>{let h=f*Math.PI/2,p=[0,0,0];return p[c]=u*Math.cos(h),p[d]=l*Math.sin(h),p},position:(f,h)=>{let p=f*Math.PI/2,g=[0,0,0];return g[c]=u*(e[c]+t*Math.cos(p)),g[d]=l*(e[d]+t*Math.sin(p)),g[a]=vr(-e[a],e[a],h),g}}}for(let a of i)for(let c of i)for(let d of i){let u=[a*e[0],c*e[1],d*e[2]],l=(f,h)=>{let p=f*Math.PI/2,g=h*Math.PI/2;return[a*Math.sin(p)*Math.cos(g),c*Math.cos(p),d*Math.sin(p)*Math.sin(g)]};yield{uSteps:r,vSteps:r,normal:l,position:(f,h)=>{let p=l(f,h);return[u[0]+t*p[0],u[1]+t*p[1],u[2]+t*p[2]]}}}}}function Cl(n,e,t,s,r,o){let i=t.length/3,a=n.uSteps+1,c=n.vSteps+1;for(let d=0;d<c;d++)for(let u=0;u<a;u++){let l=n.uSteps===0?0:u/n.uSteps,f=n.vSteps===0?0:d/n.vSteps,h=n.position(l,f),p=n.normal(l,f);t.push(h[0],h[1],h[2]),s.push(p[0],p[1],p[2]);let[g,m]=Pl(h,p,e);r.push(g,m)}for(let d=0;d<n.vSteps;d++)for(let u=0;u<n.uSteps;u++){let l=i+d*a+u,f=l+1,h=l+a,p=h+1;vc(t,s,o,l,h,f),vc(t,s,o,f,h,p)}}function vc(n,e,t,s,r,o){let i=n[s*3],a=n[s*3+1],c=n[s*3+2],d=n[r*3],u=n[r*3+1],l=n[r*3+2],f=n[o*3],h=n[o*3+1],p=n[o*3+2],g=d-i,m=u-a,x=l-c,_=f-i,v=h-a,A=p-c,M=m*A-x*v,O=x*_-g*A,H=g*v-m*_;if(M*M+O*O+H*H<1e-20)return;M*e[s*3]+O*e[s*3+1]+H*e[s*3+2]>=0?t.push(s,r,o):t.push(s,o,r)}function Pl(n,e,t){let s=Math.abs(e[0]),r=Math.abs(e[1]),o=Math.abs(e[2]),i=s>=r&&s>=o?0:r>=o?1:2,a=(i+1)%3,c=(i+2)%3;return[t[a]===0?.5:.5+n[a]/(2*t[a]),t[c]===0?.5:.5+n[c]/(2*t[c])]}function Il(n,e){let t=[0,0,0];return t[n]=e,t}function vr(n,e,t){return n+(e-n)*t}function bc(n){return n===void 0||n===!0?!0:n===!1?!1:n==="cast"||typeof n=="object"}function Dl(n){return n===void 0||n===!0?!0:n===!1?!1:n==="receive"||typeof n=="object"}function Fl(n){return bc(n)?typeof n=="object"?n:{}:null}function kr(n){return n===void 0?[1,1]:typeof n=="number"?[n,n]:[n[0]??1,n[1]??n[0]??1]}function $l(n){if(n===void 0)return null;let e=typeof n=="number"?{size:n}:n,t=e.size??.1;return{size:t,thickness:e.thickness??t*2,offset:e.offset??0,segments:e.segments??3}}function Nl(n){let e=n.segments,[t,s]=typeof e=="number"?[e,e]:[e[0]??1,e[1]??e[0]??1],r=Math.max(1,Math.floor(t))+1,o=Math.max(1,Math.floor(s))+1,i=new Float32Array(r*o*3),a=new Float32Array(r*o*2),c=n.color?new Float32Array(r*o*3):void 0,d={x:0,y:0,z:0};for(let f=0;f<o;f++){let h=f/(o-1);for(let p=0;p<r;p++){let g=p/(r-1),m=f*r+p,x=n.vertex(g,h);if(Array.isArray(x))d.x=x[0],d.y=x[1],d.z=x[2];else{let _=x;d.x=_.x,d.y=_.y,d.z=_.z}if(i[m*3]=d.x,i[m*3+1]=d.y,i[m*3+2]=d.z,a[m*2]=g,a[m*2+1]=h,c&&n.color){let _=Rl(n.color(g,h,d));c[m*3]=_[0],c[m*3+1]=_[1],c[m*3+2]=_[2]}}}let u=new Uint32Array((r-1)*(o-1)*6),l=0;for(let f=0;f<o-1;f++)for(let h=0;h<r-1;h++){let p=f*r+h,g=p+1,m=p+r,x=m+1;u[l++]=p,u[l++]=m,u[l++]=g,u[l++]=g,u[l++]=m,u[l++]=x}return{type:"buffer",position:i,uv:a,color:c,index:u,computeNormals:n.computeNormals,params:n.params}}function Rl(n){let[e,t,s]=typeof n=="string"?ze(n):n;return[br(e),br(t),br(s)]}function br(n){return n<=.04045?n/12.92:Math.pow((n+.055)/1.055,2.4)}function Mn(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}function ae(n,e){let t=new Array(16);for(let s=0;s<4;s++){let r=e[s*4],o=e[s*4+1],i=e[s*4+2],a=e[s*4+3];t[s*4]=n[0]*r+n[4]*o+n[8]*i+n[12]*a,t[s*4+1]=n[1]*r+n[5]*o+n[9]*i+n[13]*a,t[s*4+2]=n[2]*r+n[6]*o+n[10]*i+n[14]*a,t[s*4+3]=n[3]*r+n[7]*o+n[11]*i+n[15]*a}return t}function Ot(n){let[e,t,s,r,o,i,a,c,d,u,l,f,h,p,g,m]=n,x=u*g*c-p*l*c+p*a*f-i*g*f-u*a*m+i*l*m,_=h*l*c-d*g*c-h*a*f+o*g*f+d*a*m-o*l*m,v=d*p*c-h*u*c+h*i*f-o*p*f-d*i*m+o*u*m,A=h*u*a-d*p*a-h*i*l+o*p*l+d*i*g-o*u*g,M=e*x+t*_+s*v+r*A;if(M===0)return null;let O=1/M;return[x*O,(p*l*r-u*g*r-p*s*f+t*g*f+u*s*m-t*l*m)*O,(i*g*r-p*a*r+p*s*c-t*g*c-i*s*m+t*a*m)*O,(u*a*r-i*l*r-u*s*c+t*l*c+i*s*f-t*a*f)*O,_*O,(d*g*r-h*l*r+h*s*f-e*g*f-d*s*m+e*l*m)*O,(h*a*r-o*g*r-h*s*c+e*g*c+o*s*m-e*a*m)*O,(o*l*r-d*a*r+d*s*c-e*l*c-o*s*f+e*a*f)*O,v*O,(h*u*r-d*p*r-h*t*f+e*p*f+d*t*m-e*u*m)*O,(o*p*r-h*i*r+h*t*c-e*p*c-o*t*m+e*i*m)*O,(d*i*r-o*u*r-d*t*c+e*u*c+o*t*f-e*i*f)*O,A*O,(d*p*s-h*u*s+h*t*l-e*p*l-d*t*g+e*u*g)*O,(h*i*s-o*p*s-h*t*a+e*p*a+o*t*g-e*i*g)*O,(o*u*s-d*i*s+d*t*a-e*u*a-o*t*l+e*i*l)*O]}function le(n,e){let{x:t,y:s,z:r}=e;return{x:n[0]*t+n[4]*s+n[8]*r+n[12],y:n[1]*t+n[5]*s+n[9]*r+n[13],z:n[2]*t+n[6]*s+n[10]*r+n[14],w:n[3]*t+n[7]*s+n[11]*r+n[15]}}function kc(n,e,t){let{x:s,y:r,z:o,w:i}=e,a=s+s,c=r+r,d=o+o,u=s*a,l=s*c,f=s*d,h=r*c,p=r*d,g=o*d,m=i*a,x=i*c,_=i*d;return[(1-(h+g))*t.x,(l+_)*t.x,(f-x)*t.x,0,(l-_)*t.y,(1-(u+g))*t.y,(p+m)*t.y,0,(f+x)*t.z,(p-m)*t.z,(1-(u+h))*t.z,0,n.x,n.y,n.z,1]}function Tt(n,e,t=zl){let s=n.x-e.x,r=n.y-e.y,o=n.z-e.z,i=Math.hypot(s,r,o);i===0&&(o=1,i=1),s/=i,r/=i,o/=i;let a=t.y*o-t.z*r,c=t.z*s-t.x*o,d=t.x*r-t.y*s,u=Math.hypot(a,c,d);u===0&&(Math.abs(t.z)===1?s+=1e-4:o+=1e-4,i=Math.hypot(s,r,o),s/=i,r/=i,o/=i,a=t.y*o-t.z*r,c=t.z*s-t.x*o,d=t.x*r-t.y*s,u=Math.hypot(a,c,d)),a/=u,c/=u,d/=u;let l=r*d-o*c,f=o*a-s*d,h=s*c-r*a;return[a,c,d,0,l,f,h,0,s,r,o,0,0,0,0,1]}var zl={x:0,y:1,z:0};function Et(n,e){if(!n)return Mn();let t=Z(n.position),s=Z(n.scale===void 0?1:n.scale);if(n.lookAt!==void 0){let o=Z(n.lookAt),i=e?le(e,t):{...t,w:1},a={x:i.x,y:i.y,z:i.z},c=Tt(o,a);if(e){let d=Ot(Sc(e));d&&(c=ae(d,c))}return ae(ae(Ct(t),c),jl(s))}let r=n.quaternion??_s(Ll(n.rotation));return kc(t,r,s)}function Ll(n){return{...Z(n),order:n?.order}}function Ct(n){return[1,0,0,0,0,1,0,0,0,0,1,0,n.x,n.y,n.z,1]}function jl(n){return[n.x,0,0,0,0,n.y,0,0,0,0,n.z,0,0,0,0,1]}function Sc(n){let e=Math.hypot(n[0],n[1],n[2])||1,t=Math.hypot(n[4],n[5],n[6])||1,s=Math.hypot(n[8],n[9],n[10])||1;return[n[0]/e,n[1]/e,n[2]/e,0,n[4]/t,n[5]/t,n[6]/t,0,n[8]/s,n[9]/s,n[10]/s,0,0,0,0,1]}function On(n,e,t,s,r){let o=t*Math.tan(n*Math.PI/360)/r,i=2*o,a=e*i,c=-.5*a;return Bl(c,c+a,o,o-i,t,s)}function Bl(n,e,t,s,r,o){let i=2*r/(e-n),a=2*r/(t-s),c=(e+n)/(e-n),d=(t+s)/(t-s),u=-(o+r)/(o-r),l=-2*o*r/(o-r);return[i,0,0,0,0,a,0,0,c,d,u,-1,0,0,l,0]}function Sr(n,e,t,s,r,o,i){let a=(e-n)/(2*i),c=(t-s)/(2*i),d=(e+n)/2,u=(t+s)/2,l=d-a,f=d+a,h=u+c,p=u-c,g=1/(f-l),m=1/(h-p),x=1/(o-r);return[2*g,0,0,0,0,2*m,0,0,0,0,-2*x,0,-(f+l)*g,-(h+p)*m,-(o+r)*x,1]}function q(n,e,t){return{min:{x:-n,y:-e,z:-t},max:{x:n,y:e,z:t}}}function Xe(n,e){return n?e?{min:{x:Math.min(n.min.x,e.min.x),y:Math.min(n.min.y,e.min.y),z:Math.min(n.min.z,e.min.z)},max:{x:Math.max(n.max.x,e.max.x),y:Math.max(n.max.y,e.max.y),z:Math.max(n.max.z,e.max.z)}}:n:e}function Tn(n){let{min:e,max:t}=n;return[{x:e.x,y:e.y,z:e.z},{x:t.x,y:e.y,z:e.z},{x:e.x,y:t.y,z:e.z},{x:t.x,y:t.y,z:e.z},{x:e.x,y:e.y,z:t.z},{x:t.x,y:e.y,z:t.z},{x:e.x,y:t.y,z:t.z},{x:t.x,y:t.y,z:t.z}]}function qe(n,e){let t=1/0,s=1/0,r=1/0,o=-1/0,i=-1/0,a=-1/0;for(let c of Tn(n)){let d=le(e,c);d.x<t&&(t=d.x),d.y<s&&(s=d.y),d.z<r&&(r=d.z),d.x>o&&(o=d.x),d.y>i&&(i=d.y),d.z>a&&(a=d.z)}return{min:{x:t,y:s,z:r},max:{x:o,y:i,z:a}}}function En(n){if(!n)return null;switch(n.type){case"box":return q((n.width??1)/2,(n.height??1)/2,(n.depth??1)/2);case"sphere":return q(n.radius??1,n.radius??1,n.radius??1);case"plane":return q((n.width??1)/2,(n.height??1)/2,0);case"cylinder":{let[e,t]=kr(n.radius),s=Math.max(e,t);return q(s,(n.height??1)/2,s)}case"cone":{let e=n.radius??1;return q(e,(n.height??1)/2,e)}case"torus":{let e=n.radius??1,t=n.thickness??.4;return q(e+t,e+t,t)}case"torusKnot":{let e=n.radius??1,t=n.thickness??.4;return q(e*1.5+t,e*1.5+t,e*.5+t)}case"circle":return q(n.radius??1,n.radius??1,0);case"ring":{let e=n.radius??1;return q(e,e,0)}case"capsule":{let e=n.radius??.5;return q(e,(n.height??1)/2+e,e)}case"polyhedron":{let e=n.radius??1;return q(e,e,e)}case"lathe":{let e=0,t=1/0,s=-1/0;for(let r of n.points){let o=Z(r);e=Math.max(e,Math.abs(o.x)),t=Math.min(t,o.y),s=Math.max(s,o.y)}return Number.isFinite(t)?{min:{x:-e,y:t,z:-e},max:{x:e,y:s,z:e}}:null}case"tube":{let e=n.points.map(s=>Z(s)),t=Vl(e);return t?Ul(t,n.radius??1):null}case"buffer":return Kl(n.position);case"edges":case"wireframe":return En(n.source);default:return null}}function Vl(n){if(n.length===0)return null;let e=1/0,t=1/0,s=1/0,r=-1/0,o=-1/0,i=-1/0;for(let a of n)a.x<e&&(e=a.x),a.y<t&&(t=a.y),a.z<s&&(s=a.z),a.x>r&&(r=a.x),a.y>o&&(o=a.y),a.z>i&&(i=a.z);return{min:{x:e,y:t,z:s},max:{x:r,y:o,z:i}}}function Kl(n){if(n.length<3)return null;let e=1/0,t=1/0,s=1/0,r=-1/0,o=-1/0,i=-1/0;for(let a=0;a+2<n.length;a+=3){let c=n[a],d=n[a+1],u=n[a+2];c<e&&(e=c),d<t&&(t=d),u<s&&(s=u),c>r&&(r=c),d>o&&(o=d),u>i&&(i=u)}return{min:{x:e,y:t,z:s},max:{x:r,y:o,z:i}}}function Ul(n,e){return{min:{x:n.min.x-e,y:n.min.y-e,z:n.min.z-e},max:{x:n.max.x+e,y:n.max.y+e,z:n.max.z+e}}}var Gl=["color","opacity","visible","emission","emissionStrength","roughness","metalness","shininess","specular","reflectivity","clearcoat","clearcoatRoughness","transmission","thickness","ior","sheen","sheenColor","sheenRoughness","iridescence","iridescenceIOR","specularIntensity","specularColor","anisotropy","anisotropyRotation","attenuationColor","attenuationDistance","aoMapIntensity","lightMapIntensity","envMapIntensity","normalScale","displacementScale","displacementBias","size","width","dashSize","gapSize","scale","rotation","depthWrite","depthTest","polygonOffsetFactor","polygonOffsetUnits"],Yl=["transparent","alphaTest","faces","wireframe","blend","vertexColors","toneMapped","shading","dithering","polygonOffset","raw","extends","defines"];var Cn=class{onError;precomp;storageAdapter;audioDevice;lastAudioRequestKey="";lastAudioSrcs=new Set;audioFetching=new Map;audioFailed=new Map;audioReported=new Set;audioRequired=new Set;layoutGateKeys;disposed=!1;loaderDisposers=new Map;loaderInFlight=new Map;constructor(e,t,s,r=o=>console.error(`[AssetManager] ${o.message}`)){this.onError=r,this.precomp=e,this.layoutGateKeys=Ac(e),this.storageAdapter=t,this.audioDevice=s}setPrecomp(e){this.precomp=e,this.layoutGateKeys=Ac(e);for(let t of this.audioReported)this.audioFailed.delete(t);this.audioReported.clear(),this.lastAudioRequestKey=null,this.lastAudioSrcs=null}async loadAt(e){let t=[];for(let[s,r]of this.precomp.assets){if(r.record.type==="loader"){let o=this.syncLoader(s,r,e);o&&t.push(o);continue}r.cacheAt<=e&&r.record.endFrame>=e&&t.push(this.storageAdapter.loadAsset(s,r.record))}await Promise.all(t),this.audioDevice.schedulesAudio&&this.syncAudio(e)}isReady(e){return this.loaderDisposers.has(e)||this.storageAdapter.isLoaded(e)}async loadRecords(e){await Promise.all(e.map(t=>t.type==="loader"?this.runLoader(t.src,t.load):this.storageAdapter.loadAsset(t.src,t)))}prefetch(e){for(let[t,s]of this.precomp.assets){if(s.record.type==="loader"){this.syncLoader(t,s,e)?.catch(r=>{console.error(`[AssetManager] loader failed for ${t}:`,r)});continue}s.cacheAt<=e&&s.record.endFrame>=e&&this.storageAdapter.loadAsset(t,s.record).catch(r=>{console.error(`[AssetManager] prefetch failed for ${t}:`,r)})}}syncLoader(e,t,s){if(t.record.type!=="loader")return;let r=t.discardAt??1/0;if(!(t.cacheAt<=s&&s<=r)){if(this.layoutGateKeys.has(e))return;let i=this.loaderDisposers.get(e);i&&(this.loaderDisposers.delete(e),i());return}return this.runLoader(e,t.record.load)}runLoader(e,t){if(this.loaderDisposers.has(e))return;let s=this.loaderInFlight.get(e);if(s)return s;let r=t().then(o=>{this.loaderDisposers.set(e,o??Wl)}).finally(()=>{this.loaderInFlight.delete(e)});return this.loaderInFlight.set(e,r),r}dispose(){for(let e of this.loaderDisposers.values())e();this.loaderDisposers.clear(),this.loaderInFlight.clear(),this.disposed=!0}syncAudio(e){let t=e/this.precomp.fps,s=[],r=new Set,o=new Set,i=new Set,a=(d,u)=>{let l=u+d.startAt,f=u+d.endAt;if(f<t||l>t+10)return;d.optional||o.add(d.src);let h=Xl(d,u);i.has(h)||(i.add(h),s.push({...d,id:h,startAt:l,endAt:f,...d.bus&&{bus:d.bus.map(p=>({...p,startAt:u+p.startAt,endAt:u+p.endAt}))}}),r.add(d.src))};for(let d of this.precomp.tracks){let u=d.startFrame/this.precomp.fps;for(let l of d.audioRequests)a(l,u)}this.audioRequired=o;for(let d of r)if(!this.audioDevice.has(d)&&!this.audioFetching.has(d)&&!this.audioFailed.has(d)){let u=this.storageAdapter.fetchAudioData(d).then(l=>this.audioDevice.append(d,l)).catch(l=>this.failAudio(d,l)).finally(()=>this.audioFetching.delete(d));this.audioFetching.set(d,u)}for(let[d,u]of this.audioFailed)r.has(d)?o.has(d)&&this.reportAudio(d,u):(this.audioFailed.delete(d),this.audioReported.delete(d));let c=Hl(s);c!==this.lastAudioRequestKey&&(this.audioDevice.schedule(s),this.lastAudioRequestKey=c),(this.lastAudioSrcs===null||!Jl(this.lastAudioSrcs,r))&&(this.audioDevice.retain(r),this.lastAudioSrcs=r)}failAudio(e,t){this.disposed||(this.audioFailed.set(e,t),this.audioRequired.has(e)&&this.reportAudio(e,t))}reportAudio(e,t){if(this.audioReported.has(e))return;this.audioReported.add(e);let s=t instanceof Error?t.message:String(t);this.onError(new Error(`audio "${e}" could not be loaded: ${s}`,{cause:t}))}};function Ac(n){let e=new Set;for(let t of n.tracks)for(let s of t.layoutGates??[])e.add(s);return e}var Wl=()=>{};function Xl(n,e){return`${n.src}|${e+n.startAt}|${e+n.endAt}|${n.trimStart}|${n.trimEnd??"_"}|${n.loop?1:0}|${Y(n.volume)}|${Y(n.speed)}|${n.sourceLength??"_"}|${gt(n.effects)}|${Ke(n.transitionIn)}|${Ke(n.transitionOut)}|${ql(n.bus)}`}function ql(n){return!n||n.length===0?"":n.map(Ds).join(">")}function Hl(n){return n.length===0?"":n.map(e=>e.id).sort().join(`
9
- `)}function Jl(n,e){if(n.size!==e.size)return!1;for(let t of n)if(!e.has(t))return!1;return!0}function Mc(n){switch(n.type){case"image":case"video":return n.src;case"font":return n.family;case"loader":return n.key}}function Zl(n){return typeof n=="number"?Number.isFinite(n)?n:400:typeof n=="string"&&parseInt(n,10)||400}var Pn=class{catalog;constructor(e,t={}){this.catalog=e,this._options=t}get declarations(){return this._decls}image(e){!e||this._decls.has(e)||(this.catalog.getImageMeta(e),this._decls.set(e,{type:"image",src:e}))}video(e,t){!e||this._decls.has(e)||(this.catalog.getVideoMeta(e),this._decls.set(e,{type:"video",src:e,trimStart:t?.start??0,trimEnd:t?.end??this.catalog.getVideoDuration(e)}))}font(e,t){!e||this._decls.has(e)||this._decls.set(e,{type:"font",family:e,weight:Zl(t)})}loader(e,t,s){let r=s?.gate??"render",o=this._decls.get(e);if(o===void 0){this._decls.set(e,{type:"loader",key:e,load:t,gate:r});return}o.type==="loader"&&(o.load,r==="layout"&&o.gate!=="layout"&&this._decls.set(e,{...o,gate:r}))}fill(e){if(e){if(!Array.isArray(e)){os(e,this);return}for(let t of e)os(t,this)}}effects(e){if(e)for(let t of e)Xr(t,this)}subtree(e){this._subtrees??=new Set,!this._subtrees.has(e)&&(this._subtrees.add(e),this._options.bindSubtree?.(e),this._options.onSubtree?this._options.onSubtree(e,this):$s(e,this))}_options;_decls=new Map;_subtrees};function we(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Ql(){let n=globalThis.scheduler;return typeof n?.yield=="function"?n.yield.bind(n):void 0}var _e=null,Ar=[];function ef(){return typeof MessageChannel!="function"?null:(_e||(_e=new MessageChannel,_e.port1.onmessage=()=>Ar.shift()?.(),_e.port1.unref?.(),_e.port2.unref?.()),new Promise(n=>{Ar.push(n),_e.port2.postMessage(null)}))}function In(){let n=Ql();return n?n():ef()??new Promise(e=>setTimeout(e,0))}function Bv(){_e?.port1.close(),_e?.port2.close(),_e=null,Ar.length=0}function Re(n,e){return n*(1/e)}function xe(n,e){let t=n*e,s=Math.round(t);return Math.abs(t-s)<=1e-9*Math.max(1,Math.abs(t))?s:t}function Kv(n,e){return{kind:"frame",frame:Math.round(xe(n,e))}}function He(n,e){return typeof n!="number"||!Number.isFinite(n)?1:Math.max(1,Math.ceil(xe(n,e)))}function Pt(n,e){return n.map((t,s)=>{let r=Math.max(0,Math.round(xe(t.startAt??0,e)));return{id:t.id,index:s,startFrame:r,endFrame:r+He(t.duration,e)-1}})}function Oc(n){let e=0;for(let t of n)e=Math.max(e,t.endFrame+1);return e}function Me(n,e){return n.filter(t=>e>=t.startFrame&&e<=t.endFrame)}function se(n,e,t){return Math.min(Re(n,e),t)}function Je(n,e,t){let s=t-1,r=a=>se(a,e,1/0),o=Math.min(s+1,Math.max(0,Math.ceil(n.start*e)));for(;o>0&&r(o-1)>=n.start;)o--;for(;o<=s&&r(o)<n.start;)o++;let i=s;if(n.end!==1/0){for(i=Math.max(-1,Math.min(s,Math.ceil(n.end*e)));i>=0&&r(i)>=n.end;)i--;for(;i<s&&r(i+1)<n.end;)i++}return o<=i?{startFrame:o,endFrame:i}:null}var Dn=class{_scope;canvas;constructor(e,t,s){this._scope=s,this._clip=e,this._duration=t,this._doc=Tc(e);let{width:r,height:o}=s.viewport;this.canvas=new Ie({id:b,width:r,height:o,flow:"freeform"}),this._timeline=new bn(this._doc,s.registry,this.canvas),this._indexRows()}get duration(){return this._duration}get clip(){return this._clip}build(e=this._scope.measurer){this.attach(0),this._timeline.build(),this.sample(),this.layout(e),this._timeline.compile(()=>{this.sample(),this.layout(e)}),this.layout(e)}update(e,t){if(e===this._clip)return this._duration=t,!0;let s=this.planUpdate(e);return s?(this.applyUpdate(s,e,t),!0):!1}planUpdate(e){return this._timeline.planUpdate(Tc(e))}applyUpdate(e,t,s,r=this._scope.measurer){this.attach(0);let o=()=>{this.sample(),this.layout(r)};this._timeline.applyUpdate(e,o,o),this.layout(r),this._clip=t,this._doc=e.next.doc,this._duration=s,this._indexRows()}placedCommands(){return this._timeline.placedCommands()}issues(){return this._timeline.issues()}commandSounds(){return this._timeline.commandSounds()}atPresence(e,t){let s=this._timeline.presenceTime;this._timeline.syncPresence(e);try{return t()}finally{this._timeline.syncPresence(s)}}evaluateAt(e,t){this._timeline.syncPresence(e),this._timeline.evaluateAt(e,t)}attach(e,t){this.canvas.attach({assets:this._scope.assets,context:lo.EMPTY,time:e}),Ns(this.canvas,t)}layout(e=this._scope.measurer){let{width:t,height:s}=this._scope.viewport;this.canvas.layout({x:0,y:0,width:t,height:s},e)}render(e){this.canvas.render(e)}sample(){on(this.canvas)}primeMotion(e){an(this.canvas,e)}node(e){return this._timeline.liveNode(e)}baselineProps(e){return this._timeline.baselineProps(e)}rowSpans(){return[...this._rows.values()].map(e=>e.span)}rowSpan(e){return this._rows.get(e)?.span}ownerKeyOf(e){let t="";for(let s=e;;){if(s===this.canvas||this._timeline.liveNode(s.id)===s){let i=s===this.canvas?b:s.id;return t===""?i:`${i}/${t}`}let r=s.parent;if(!r)return;let o=r._allChildren.indexOf(s);t=t===""?String(o):`${o}.${t}`,s=r}}spanOf(e){for(let t=e;t;t=t.parent){if(t===this.canvas)return{start:0,end:this.duration};let s=this._rowSpan(t);if(s)return{...s}}}forEachOwner(e){let t=(s,r,o,i,a)=>{if(!s.mounted)return;let c=s===this.canvas?void 0:this._rowSpan(s);c&&(r=s.id,o="",i=c),e(s,o===""?r:`${r}/${o}`,i,a);let d=s._allChildren;for(let u=0;u<d.length;u++)t(d[u],r,o===""?String(u):`${o}.${u}`,i,ye(a,u))};t(this.canvas,b,"",{start:0,end:this.duration},"")}dispose(){for(let e of this.canvas.children)e.dispose();this.canvas.dispose()}_clip;_doc;_duration;_timeline;_rows=new Map;_indexRows(){this._rows.clear();let e=ca(this._doc.nodes);for(let t of this._doc.nodes)t.id!==b&&this._rows.set(t.id,{parentId:t.parentId,span:e.get(t.id)})}_rowSpan(e){let t=this._rows.get(e.id);if(!t)return;let s=e.parent;return(t.parentId===null||t.parentId===b?s===this.canvas:s!==null&&s.id===t.parentId)?t.span:void 0}};function Tc(n){return Ye(n)}var tf=new Set,It=class{constructor(e){this._frameCount=Math.max(0,e)}setOwner(e,t){let s=new Set,r=this._owners.get(e);r&&this._unlink(e,r,s);let o={declared:new Map,learned:new Map};for(let i of t)i.endFrame>=i.startFrame&&nf(o.declared,{...i});return o.declared.size>0?(this._owners.set(e,o),this._link(e,o,s)):this._owners.delete(e),this._refresh(s)}removeOwner(e){let t=this._owners.get(e);if(!t)return{keys:new Set};let s=new Set;return this._unlink(e,t,s),this._owners.delete(e),this._refresh(s)}learn(e,t,s){let r=Mc(t),o=this._owners.get(e);o||(o={declared:new Map,learned:new Map},this._owners.set(e,o));let i=o.learned.get(r)??[],a=i.findIndex(d=>s>=d.startFrame-1&&s<=d.endFrame+1);if(a<0)i.push({key:r,decl:t,startFrame:s,endFrame:s});else{let d=i[a];i[a]={...d,startFrame:Math.min(d.startFrame,s),endFrame:Math.max(d.endFrame,s)}}o.learned.set(r,i);let c=this._byKey.get(r);return c||this._byKey.set(r,c=new Set),c.add(e),this._refresh(new Set([r]))}setFrameCount(e){let t=Math.max(0,e);return t===this._frameCount?{keys:new Set}:(this._frameCount=t,this._refresh(new Set(this._byKey.keys())))}owners(e){return this._byKey.get(e)??tf}segmentsOf(e){let t=this._owners.get(e);if(!t)return[];let s=[];for(let r of t.declared.values())s.push(...r);for(let r of t.learned.values())s.push(...r);return s}declaredSegmentsOf(e){let t=this._owners.get(e);if(!t)return[];let s=[];for(let r of t.declared.values())s.push(...r);return s}ownerKeys(){return this._owners.keys()}records(){return this._records}layoutGates(){if(this._layoutGates===null){let e=[];for(let t of this._entries.values())t.layout&&e.push(t.record);this._layoutGates=e}return this._layoutGates}_frameCount;_owners=new Map;_byKey=new Map;_entries=new Map;_records=new Map;_layoutGates=null;_link(e,t,s){for(let r of t.declared.keys()){let o=this._byKey.get(r);o||this._byKey.set(r,o=new Set),o.add(e),s.add(r)}}_unlink(e,t,s){for(let r of[t.declared,t.learned])for(let o of r.keys()){let i=this._byKey.get(o);i&&(i.delete(e),i.size===0&&this._byKey.delete(o)),s.add(o)}}_refresh(e){let t=new Set;for(let s of e){let r=this._entries.get(s),o=this._compute(s);if(o===void 0){if(r===void 0)continue;this._entries.delete(s),this._records.delete(s)}else{if(r!==void 0&&r.layout===o.layout&&rf(r.record,o.record))continue;this._entries.set(s,o),this._records.set(s,o.record)}t.add(s)}return t.size>0&&(this._layoutGates=null),{keys:t}}_compute(e){let t=this._byKey.get(e);if(!t)return;let s=this._frameCount-1,r,o=1/0,i=-1/0,a=!1,c=d=>{if(d)for(let u of d){let l=Math.max(0,u.startFrame),f=Math.min(s,u.endFrame);f<l||(l<o&&(o=l,r=u),f>i&&(i=f),u.decl.type==="loader"&&u.decl.gate==="layout"&&(a=!0))}};for(let d of t){let u=this._owners.get(d);u&&(c(u.declared.get(e)),c(u.learned.get(e)))}if(r!==void 0)return{record:sf(r.decl,o,i),layout:r.decl.type==="font"||a}}};function nf(n,e){let t=n.get(e.key);t?t.push(e):n.set(e.key,[e])}function sf(n,e,t){switch(n.type){case"image":return{type:"image",startFrame:e,endFrame:t,src:n.src};case"video":return{type:"video",startFrame:e,endFrame:t,src:n.src,trimStart:n.trimStart,trimEnd:n.trimEnd};case"font":return{type:"font",startFrame:e,endFrame:t,fontWeight:n.weight,fontFamily:n.family,src:n.family};case"loader":return{type:"loader",src:n.key,startFrame:e,endFrame:t,load:n.load}}}function rf(n,e){if(n.type!==e.type||n.src!==e.src||n.startFrame!==e.startFrame||n.endFrame!==e.endFrame)return!1;switch(n.type){case"video":{let t=e;return n.trimStart===t.trimStart&&n.trimEnd===t.trimEnd}case"font":return n.fontWeight===e.fontWeight;case"loader":return n.load===e.load;default:return!0}}var Fn=class{recall(e,t){return this._byOwner.get(e)?.get(t)}remember(e,t,s){let r=this._byOwner.get(e);r||this._byOwner.set(e,r=new Map),r.set(t,s)}forget(e){this._byOwner.delete(e)}_byOwner=new Map};function*Tr(n,e){let t=new Mr(n,e);for(;t.step();)yield;return t.result()}var Ec=3,Mr=class{_instance;_options;constructor(e,t){this._instance=e,this._options=t,this._last=t.frameCount-1;let{owners:s,below:r}=t,o=s!==void 0||r!==void 0;if(!(this._last<0||o&&(s?.size??0)+(r?.size??0)===0)){if(o){this._start=1/0;for(let i of[...s?.values()??[],...r?.values()??[]])this._start=Math.min(this._start,Math.max(0,i))}if(!(this._start>this._last)){this._walked=this._start-1,this._placed=e.placedCommands().map(i=>({id:i.spec.id,...this._activeFrames(i.holdFrom,i.start-i.holdFrom+i.duration),writes:new Set(i.writes)}));for(let i=0;i<this._placed.length;i++)for(let a of this._placed[i].writes)this._addWriter(a,i);this._enqueue(this._start);for(let i of this._structureSpans()){let a=Je(i,t.fps,t.frameCount);a&&(this._structureFrame(a.startFrame),this._structureFrame(a.endFrame+1))}for(let i of this._placed)[...i.writes].some(Dt)&&this._forEachDueFrame(i,this._start,a=>this._structureFrame(a))}}}step(){let e=ff(this._heap);return e===void 0?!1:(this._queued.delete(e),this._frame=e,this._dueTaken=!1,this._evaluate(e),this._declareDue(e),this._heap.length>0)}result(){let e=new Map,t=new Map;for(let s of this._owners.values()){let r=s.present?[...s.intervals,[s.arrivedAt,1/0]]:s.intervals;e.set(s.key,{ownerKey:s.key,nodeId:s.node.id,segments:s.error?[]:df(s.history,r),deps:s.allDeps,...s.error&&{error:s.error}});for(let o of s.allDeps){let i=t.get(o);i||t.set(o,i=new Set),i.add(s.key)}}for(let s of this._options.owners?.keys()??[])e.has(s)||e.set(s,{ownerKey:s,nodeId:void 0,segments:[],deps:new Set});return{owners:e,readers:t}}_last;_start=0;_walked=-1;_placed=[];_writers=new Map;_heap=[];_queued=new Set;_due=new Map;_structureFrames=new Set;_owners=new Map;_readers=new Map;_pseudo=new Set;_rewound=new Set;_frame=-1;_dueTaken=!1;_dev=uf();_presenceObserver={read:()=>{},write:e=>{Dt(e)&&this._pseudo.add(e)}};_structureSpans(){let{owners:e,below:t}=this._options;if(e===void 0&&t===void 0)return this._instance.rowSpans();let s=new Set(t?.keys());for(let o of e?.keys()??[]){let i=o.indexOf("/");s.add(i<0?o:o.slice(0,i))}let r=[];for(let o of s){let i=this._instance.rowSpan(o);i&&r.push(i)}return r}_activeFrames(e,t){let{fps:s}=this._options,r=e+Math.max(0,t),o=Math.max(0,Math.ceil(e*s));for(;o>0&&se(o-1,s,1/0)>=e;)o--;for(;se(o,s,1/0)<e;)o++;let i=Math.max(-1,Math.floor(r*s));for(;se(i+1,s,1/0)<=r;)i++;for(;i>=0&&se(i,s,1/0)>r;)i--;return{from:o,to:i}}_evaluate(e){this._options.onPhase?.("evaluate");let t=se(e,this._options.fps,this._instance.duration);if(e>this._walked&&(e===this._start||this._structureFrames.has(e))&&this._instance.attach(t),this._pseudo.clear(),pe(this._presenceObserver,()=>this._instance.evaluateAt(t,(s,r)=>{Dt(r)&&this._pseudo.add(r),this._commandWrote(s,r)})),!(e<=this._walked)){(e===this._start||this._pseudo.size>0)&&this._reconcile(e);for(let s of this._pseudo)for(let r of this._readers.get(s)??[])r.stale=!0,this._queueOwner(r,e);this._walked=e}}_reconcile(e){let t=new Set;this._instance.forEachOwner((s,r,o)=>{let i=this._limitOf(r);if(i===void 0)return;let a=this._owners.get(r);a||(a={key:r,node:s,span:o,from:i,present:!1,arrivedAt:-1,arrived:!1,intervals:[],history:[],deps:null,values:[],stale:!0,allDeps:new Set,scheduled:new Set,rounds:0},this._owners.set(r,a)),t.add(a),a.node!==s&&(a.node=s,a.stale=!0,a.present&&this._queueOwner(a,Math.max(e,a.from))),!a.present&&(a.present=!0,a.arrivedAt=Math.max(e,a.from),a.stale=!0,this._queueOwner(a,a.arrivedAt),a.arrived||(a.arrived=!0,this._options.onArrive?.(s,r,o,e)))});for(let s of this._owners.values())!s.present||t.has(s)||(e-1>=s.arrivedAt&&s.intervals.push([s.arrivedAt,e-1]),s.present=!1)}_limitOf(e){let{owners:t,below:s}=this._options;if(t===void 0&&s===void 0)return this._start;let r=t?.get(e);if(s)for(let o=e.indexOf("/");o>=0;o=e.indexOf("/",o+1)){let i=s.get(e.slice(0,o));i!==void 0&&(r===void 0||i<r)&&(r=i)}return r}_declareDue(e){this._dueTaken=!0;let t=this._due.get(e);if(this._due.delete(e),this._options.declare!==!1){for(let s of t??[])s.error||this._rewound.has(s)||!of(s,e)||!s.stale&&af(s)||this._declare(s,e);for(let s of this._rewound)this._queueOwner(s,e);this._rewound.clear()}}_declare(e,t){if(this._options.onPhase?.("declare"),this._recall(e,t))return;let s=e.node,r=new Set,o=[],i,a=!1,c=!1,d=!1,u=this._options.bindSubtree??(g=>di(s,g)),l=new Pn(this._options.catalog,{bindSubtree:g=>{d=!0,lt(()=>u(g))}});try{pe({read:g=>{r.add(g),i=g,g._name===Le&&(a=!0)},write:g=>{o.push(g)},clock:()=>{c=!0}},()=>Fs(s,l))}catch(g){let m=g instanceof Error?g:new Error(String(g));e.error={message:m.message,stack:m.stack,...i&&{prop:ft(i)}};return}if(this._dev){let g=s.constructor.name;if(o.length>0){let m=[...new Set(o.map(ft))].join(", ");Ft(`${g}:write:${m}`,`[assets] ${g} wrote ${m} while declaring its assets. A declaration is re-run only when something it read changes, so a write there is a frame-order dependency.`)}a&&Ft(`${g}:layout`,`[assets] ${g}.declareAssets read layoutBounds. Declarations run without layout; decode size follows the draw, so declare the asset without a size.`),c&&Ft(`${g}:clock`,`[assets] ${g}.declareAssets read time. Declarations are re-run only when a prop they read changes, so anything following the clock is missed between those frames.`)}let f=[...r],h=f.map(g=>g.get()),p=this._options.memo;if(p&&!d&&!a&&!c&&o.length===0){let g=this._named(e,f);g&&p.remember(e.key,t,{ctor:s.constructor,reads:g,values:h,decls:l.declarations})}this._settle(e,t,f,h,l.declarations)}_recall(e,t){let s=this._options.memo?.recall(e.key,t);if(!s||s.ctor!==e.node.constructor)return!1;let r=[],o=[];for(let i=0;i<s.reads.length;i++){let[a,c]=s.reads[i],d=a===e.key?e.node:this._owners.get(a)?.node,u=d&&fo(d,c);if(!u)return!1;let l=lt(()=>u.get());if(!Or(l,s.values[i]))return!1;r.push(u),o.push(l)}return this._settle(e,t,r,o,s.decls),!0}_named(e,t){let s=[];for(let r of t){let o=r._host;if(!(o instanceof je)||Dt(r))return null;let i=o===e.node?e.key:this._instance.ownerKeyOf(o);if(i===void 0)return null;s.push([i,r._name])}return s}_settle(e,t,s,r,o){e.stale=!1,e.deps=s,e.values=r;for(let a of s){if(e.allDeps.has(a))continue;e.allDeps.add(a);let c=this._readers.get(a);c||this._readers.set(a,c=new Set),c.add(e)}let i=e.history[e.history.length-1];(!i||i.frame<e.arrivedAt||!cf(i.decls,o))&&e.history.push({frame:t,decls:o}),this._scheduleWriters(e,t+1)}_scheduleWriters(e,t){for(let s of e.deps??[]){let r=this._writers.get(s);if(r)for(let o of r)e.scheduled.has(o)||(e.scheduled.add(o),this._forEachDueFrame(this._placed[o],t,i=>this._queueOwner(e,i)))}}_forEachDueFrame(e,t,s){let r=Math.max(t,e.from),o=Math.min(this._last,e.to);for(let a=r;a<=o;a++)s(a);let i=Math.max(e.to+1,e.from);i>=t&&i<=this._last&&s(i)}_commandWrote(e,t){let s=this._placed[e];if(!(!s||s.writes.has(t))){s.writes.add(t),this._addWriter(t,e),this._dev&&Ft(`command:${s.id}:${ft(t)}`,`[assets] Command ${s.id} wrote ${ft(t)} at frame ${this._frame}, which compile did not record it writing. Owners reading it are re-declared over the command's span.`);for(let r of this._readers.get(t)??[])this._requeue(r,Math.max(s.from,r.from),s.id)}}_requeue(e,t,s){if(!e.error){if(t>this._frame){this._scheduleWriters(e,t);return}if(t===this._frame){this._queueOwner(e,t);return}if(e.rounds>=Ec){this._dev&&Ft(`requeue:${e.key}`,`[assets] ${e.key} was re-queued ${Ec} times (last by command ${s}); its asset windows may be incomplete.`);return}e.rounds++,e.history=e.history.filter(r=>r.frame<t),e.stale=!0,e.scheduled.clear(),this._queueOwner(e,t);for(let[r]of e.intervals)r>t&&this._queueOwner(e,r);if(e.present&&e.arrivedAt>t&&this._queueOwner(e,e.arrivedAt),e.deps?.some(Dt))for(let r of this._structureFrames)r>=t&&r<=this._walked&&this._queueOwner(e,r);this._rewound.add(e)}}_addWriter(e,t){let s=this._writers.get(e);s?s.push(t):this._writers.set(e,[t])}_structureFrame(e){e<=this._start||e>this._last||(this._structureFrames.add(e),this._enqueue(e))}_queueOwner(e,t){if(t>this._last)return;let s=this._due.get(t);s||this._due.set(t,s=new Set),s.add(e),this._enqueue(t)}_enqueue(e){this._queued.has(e)||e===this._frame&&!this._dueTaken||(this._queued.add(e),lf(this._heap,e))}};function Dt(n){return n._name===Ce||n._name.startsWith(be)}function of(n,e){if(n.present&&e>=n.arrivedAt)return!0;for(let[t,s]of n.intervals)if(e>=t&&e<=s)return!0;return!1}function af(n){let e=n.deps;if(e===null)return!1;for(let t=0;t<e.length;t++)if(!Object.is(e[t].get(),n.values[t]))return!1;return!0}function Or(n,e){if(Object.is(n,e))return!0;if(Array.isArray(n)){if(!Array.isArray(e)||n.length!==e.length)return!1;for(let s=0;s<n.length;s++)if(!Or(n[s],e[s]))return!1;return!0}if(!Cc(n)||!Cc(e))return!1;let t=Object.keys(n);if(t.length!==Object.keys(e).length)return!1;for(let s of t)if(!Object.hasOwn(e,s)||!Or(n[s],e[s]))return!1;return!0}function Cc(n){if(typeof n!="object"||n===null)return!1;let e=Object.getPrototypeOf(n);return e===Object.prototype||e===null}function cf(n,e){if(n.size!==e.size)return!1;for(let[t,s]of n){let r=e.get(t);if(!r||!Ic(s,r))return!1}return!0}function Ic(n,e){switch(n.type){case"image":return e.type==="image"&&n.src===e.src;case"video":return e.type==="video"&&n.src===e.src&&n.trimStart===e.trimStart&&n.trimEnd===e.trimEnd;case"font":return e.type==="font"&&n.family===e.family;case"loader":return e.type==="loader"&&n.key===e.key&&n.load===e.load&&n.gate===e.gate}}function df(n,e){let t=[];for(let[s,r]of e){let o=new Map;for(let i of n)if(!(i.frame<s||i.frame>r)){for(let[a,c]of o){let d=i.decls.get(a);d&&Ic(c.decl,d)||(t.push({...c,endFrame:i.frame-1}),o.delete(a))}for(let[a,c]of i.decls)o.has(a)||o.set(a,{key:a,decl:c,startFrame:i.frame,endFrame:r})}for(let i of o.values())t.push({...i,endFrame:r})}return t}function uf(){return!1}var Pc=new Set;function Ft(n,e){Pc.has(n)||(Pc.add(n),console.warn(e))}function lf(n,e){let t=n.length;for(n.push(e);t>0;){let s=t-1>>1;if(n[s]<=e)break;n[t]=n[s],t=s}n[t]=e}function ff(n){if(n.length===0)return;let e=n[0],t=n.pop();if(n.length===0)return e;let s=0;for(;;){let r=2*s+1;if(r>=n.length)break;let o=r+1,i=o<n.length&&n[o]<n[r]?o:r;if(n[i]>=t)break;n[s]=n[i],s=i}return n[s]=t,e}var Pr="",zn="",Ln="";function Nn(n,e){return n+Pr+e}function Dc(n){return zn+n}function Fc(n){if(!(n.startsWith(zn)||n.startsWith(Ln)))return n.slice(0,n.lastIndexOf(Pr))}function Rn(n){return n.startsWith(zn)||n.startsWith(Ln)?n.slice(1):n.slice(n.lastIndexOf(Pr)+1)}var Qe=class{_instance;constructor(e){this._instance=e}idOf(e){let t=e._host;if(t===null)return zn+e._name;let s=this._keys.get(t);return s===void 0&&(s=t instanceof je?this._instance.ownerKeyOf(t)??null:null,this._keys.set(t,s)),s===null?Ln+e._name:Nn(s,e._name)}idsOf(e){let t=[];for(let s of e)t.push(this.idOf(s));return t}_keys=new Map};function $n(n){let e=[];for(let t=n.indexOf("/");t>=0;t=n.indexOf("/",t+1))e.push(n.slice(0,t));return e}function $t(n,e,t){let s=n.get(e);s||n.set(e,s=new Set),s.add(t)}function Nt(n,e,t){let s=n.get(e);return!s||(s.delete(t),s.size>0)?!1:(n.delete(e),!0)}var Ze=new Set,Rt=class{set(e,t){this.remove(e);let s=new Set(t);this._deps.set(e,s);for(let r of $n(e))$t(this._ownersBelow,r,e);for(let r of s)this._readers.has(r)||this._index(r),$t(this._readers,r,e)}remove(e){let t=this._deps.get(e);if(t){this._deps.delete(e);for(let s of $n(e))Nt(this._ownersBelow,s,e);for(let s of t)Nt(this._readers,s,e)&&this._unindex(s)}}has(e){return this._deps.has(e)}depsOf(e){return this._deps.get(e)??Ze}readersOf(e){return this._readers.get(e)??Ze}ownersBelow(e){return this._ownersBelow.get(e)??Ze}slotsHostedBy(e){return this._byHost.get(e)??Ze}*slotsHostedBelow(e){for(let t of this._hostsBelow.get(e)??Ze)yield*this.slotsHostedBy(t)}slotsNamed(e){return this._byName.get(e)??Ze}_deps=new Map;_readers=new Map;_ownersBelow=new Map;_byHost=new Map;_hostsBelow=new Map;_byName=new Map;_index(e){$t(this._byName,Rn(e),e);let t=Fc(e);if(t!==void 0){$t(this._byHost,t,e);for(let s of $n(t))$t(this._hostsBelow,s,t)}}_unindex(e){Nt(this._byName,Rn(e),e);let t=Fc(e);if(t!==void 0&&Nt(this._byHost,t,e))for(let s of $n(t))Nt(this._hostsBelow,s,t)}};function $c(n){let{patch:e,deps:t,fps:s}=n,{prev:r,next:o,diff:i}=e,a={owners:new Map,below:new Map,removed:new Set,arrivalOwners:new Set,arrivalBelow:new Set},c=(m,x,_)=>{let v=m.get(x);(v===void 0||_<v)&&m.set(x,_)},d=(m,x,_)=>{c(a.owners,m,x),_&&a.arrivalOwners.add(m)},u=(m,x,_)=>{for(let v of t.readersOf(m))d(v,x,_)},l=(m,x)=>{!n.buildsChildren(m)&&t.ownersBelow(m).size===0||(c(a.below,m,x),a.arrivalBelow.add(m))},f=(m,x)=>{let _=m.effSpan(x);return _?Er(_.start,s):1/0},h=(m,x)=>{u(Dc(be+m),x,!0),u(Nn(m,Ce),x,!0);for(let _ of[r,o]){let v=_.nodes.get(m);v&&u(Nn(v.parentId??b,Ce),x,!0)}},p=(m,x,_)=>{for(let v of t.slotsHostedBy(m)){let A=Rn(v);(_===null||_.has(A)||A===Ce)&&u(v,x,!0)}for(let v of t.slotsHostedBelow(m))u(v,x,!0)};for(let[m,x]of n.before){if(n.after.has(m))continue;let _=Er(x.start,s);for(let v of x.writes)u(v,_,!1)}for(let[m,x]of n.after){if(n.before.has(m))continue;let _=Er(x.start,s);for(let v of x.writes)u(v,_,!1)}for(let m of i.variables.changed)u(Dc(Gt+m),0,!0);if(e.layoutChanged)for(let m of t.slotsNamed(Le))u(m,0,!0);for(let m of i.nodes.reorderedParents)u(Nn(m,Ce),0,!0);for(let m of i.nodes.removed){let x=f(r,m);a.removed.add(m),h(m,x),p(m,x,null)}for(let m of i.nodes.added){let x=f(o,m);x!==1/0&&(d(m,x,!0),l(m,x),h(m,x))}for(let m of o.nodes.keys()){if(m===b||!r.nodes.has(m))continue;let x=r.effSpan(m),_=o.effSpan(m);if(x?.start===_?.start&&x?.end===_?.end)continue;let v=Math.min(f(r,m),f(o,m));v!==1/0&&(d(m,v,!0),l(m,v),h(m,v))}let g=new Set([...e.reinstantiate,...i.nodes.added,...i.nodes.removed]);for(let m of e.reinstantiate){let x=hf(m,n,g);p(m,0,x),l(m,0);for(let _ of[m,...t.ownersBelow(m)])for(let v of t.depsOf(_))if(v.startsWith(Ln)){d(_,0,!0);break}i.nodes.moved.has(m)&&h(m,0)}for(let m of e.inPlace){let x=Cr(r.nodes.get(m),o.nodes.get(m),n.propsOf(m)??new Set);for(let _ of t.slotsHostedBy(m))(x===null||x.has(Rn(_)))&&u(_,0,!0)}if(i.rootChanged){let m=n.propsOf(b);p(b,0,m?Cr(r.nodes.get(b),o.nodes.get(b),m):null)}return a}function hf(n,e,t){let{prev:s,next:r,diff:o}=e.patch,i=s.nodes.get(n),a=r.nodes.get(n);if(!i||!a||!o.nodes.respec.has(n)||o.nodes.moved.has(n)||i.type!==a.type||i.key!==a.key)return null;for(let d of[s,r])if(pf(d,n,t,e))return null;let c=e.propsOf(n);return c?Cr(i,a,c):null}function Cr(n,e,t){let s=new Set;for(let r of new Set([...Object.keys(n.props),...Object.keys(e.props)]))if(!N(n.props[r],e.props[r])){if(!t.has(r))return null;s.add(r)}return s}function pf(n,e,t,s){let r=new Set([e]),o=n.nodes.get(e)?.parentId??null;for(;o!==null&&o!==b&&!r.has(o);){r.add(o);let i=n.nodes.get(o);if(!i)return!1;if(t.has(o)&&s.isContextProvider(i.type))return!0;o=i.parentId}return!1}function Er(n,e){if(!(n>0))return 0;if(!Number.isFinite(n))return 1/0;let t=Math.max(0,Math.ceil(n*e));for(;t>0&&se(t-1,e,1/0)>=n;)t--;for(;se(t,e,1/0)<n;)t++;return t}var zt=class{setOwner(e,t){if(t.length===0)return this.removeOwner(e);let s=this._owners.get(e);return s&&Nc(s,t)?!1:(this._owners.set(e,t),!0)}removeOwner(e){return this._owners.delete(e)}requests(){let e=[];for(let t of this._owners.values())e.push(...t);return e}_owners=new Map};function Nc(n,e){if(Object.is(n,e))return!0;if(typeof n!="object"||typeof e!="object"||n===null||e===null||Object.getPrototypeOf(n)!==Object.getPrototypeOf(e))return!1;let t=Object.keys(n);if(t.length!==Object.keys(e).length)return!1;for(let s of t)if(!Nc(n[s],e[s]))return!1;return!0}var mf="@commands",jt=8,Oe=class{_scope;constructor(e,t,s={}){this._scope=t,this._options=s,this._refine=s.assets!==!1?"assets":s.audio!==!1?"audio":"none",this._project=e;for(let r of e.tracks)this._entries.set(r.id,this._fresh(r));this._spans=Pt(e.tracks,t.fps)}get project(){return this._project}get tracks(){return this._project.tracks}get spans(){return this._spans}get version(){return this._version}get profile(){return this._options.profile}setProject(e){let t={deltas:new Map,rebuilt:[]};if(this._disposed||e===this._project)return t;let s=!N(this._project.theme,e.theme);this._project=e;let r=this._entries;this._entries=new Map;for(let a of e.tracks){let c=r.get(a.id),d=c&&!s?this._reconcile(c,a,t):this._fresh(a);c&&d!==c&&t.rebuilt.push(a.id),this._entries.set(a.id,d)}let o=t.rebuilt.length>0||r.size!==this._entries.size;for(let[a,c]of r)this._entries.get(a)!==c&&(this._discard(c),o=!0);let i=Pt(e.tracks,this._scope.fps);return(o||!xf(i,this._spans))&&this._version++,this._spans=i,t}reset(){if(this._disposed)return;let e=this._entries;this._entries=new Map;for(let t of this._project.tracks)this._entries.set(t.id,this._fresh(t));for(let t of e.values())this._discard(t);this._version++}ensureBuilt(e){let t=this._entries.get(e);return!t||t.running||this._disposed?null:(t.steps&&this._drain(t),!t.instance&&!t.failure&&(this._start(t,!0,this._refine!=="none"&&!t.discovered),this._drain(t)),t.instance)}discover(e){let t=this._entries.get(e);if(!(!t||t.running||this._disposed)){if(this._refine==="none"){this.ensureBuilt(e);return}t.discovered||(t.steps||this._start(t,!t.instance,!0),this._drain(t))}}async runAsync(e={}){let{budgetMs:t=jt,isCancelled:s,onProgress:r}=e;if(this._refine!=="none")for(;;){if(this._disposed||s?.())return;let o=this._nextUndiscovered();if(!o)return;o.steps||this._start(o,!o.instance,!0);let i=we()+t,a=this._step(o);for(;!a;){if(we()>=i){if(o.profile?.suspend(),await In(),this._disposed||s?.())return;if(o.discarded||!o.steps)break;o.profile?.resume(),i=we()+t}a=this._step(o)}!o.discarded&&o.discovered&&r?.()}}instanceOf(e){let t=this._entries.get(e);return t&&!t.steps?t.instance:null}generationOf(e){return this._entries.get(e)?.generation??-1}failed(e){return!!this._entries.get(e)?.failure}isDiscovered(e){return!!this._entries.get(e)?.discovered}trackAssets(e){return this._entries.get(e)?.discovered??void 0}errorsOf(e){let t=this._entries.get(e);return t?.discovered?t.errors:[]}ownersOf(e,t){return this._entries.get(e)?.index.owners(t)??new Set}layoutGates(e){let t=this._entries.get(e);return t?.discovered?t.index.layoutGates():[]}learn(e,t,s,r){let o=this._entries.get(e);return!o?.discovered||o.index.learn(t,s,r).keys.size===0?!1:this._refresh(o)}settleGates(e){let t=this._options.isReady;if(!t)return!1;let s=!1;for(let r of e){let o=this._entries.get(r);if(!o||o.unready.size===0||!o.instance||o.steps||o.running)continue;let i=o.discovered?new Set(o.index.layoutGates().map(c=>c.src)):null,a=!1;for(let c of[...o.unready])i&&!i.has(c)?o.unready.delete(c):t(c)&&(a=!0);a&&(this._rebuildInstance(o),s=!0)}return s}rebuild(e){let t=this._entries.get(e);!t||t.running||t.steps||(t.instance?.dispose(),t.instance=null,t.unready.clear(),t.generation++,t.failure&&(t.failure=null,t.discovered=null,this._version++))}release(e){let t=this._entries.get(e);!t||!t.instance||t.running||t.steps||!t.discovered||(t.instance.dispose(),t.instance=null,t.generation++)}trim(e,t){for(let s=0;s<this._spans.length;s++){let r=this._spans[s];r.endFrame>=e-t&&r.startFrame<=e+t||this.release(r.id)}}dispose(){this._disposed=!0;for(let e of this._entries.values())this._discard(e)}_options;_refine;_project;_entries=new Map;_spans;_version=0;_disposed=!1;_fresh(e,t=new Fn){let s=He(e.duration,this._scope.fps);return{track:e,frameCount:s,instance:null,steps:null,running:!1,discarded:!1,profile:void 0,discovered:null,errors:[],index:new It(s),audio:new zt,commandAudio:new Set,commandSounds:null,deps:new Rt,assetDeps:new Map,audioDeps:new Map,ownerErrors:new Map,audioErrors:new Map,issues:[],failure:null,refineError:null,generation:0,writes:new WeakMap,unready:new Set,memo:t}}_reconcile(e,t,s){let r=He(t.duration,this._scope.fps),o=N(zc(e.track.clip),zc(t.clip))?e.memo:void 0;if(e.track.clip===t.clip)return this._resize(e,t,r);if(e.steps||e.failure)return this._fresh(t,o);if(!e.instance)return e.discovered&&_n(e.track.clip,t.clip).identical?this._resize(e,t,r):this._fresh(t,o);let i=e.instance,a;try{a=i.planUpdate(t.clip)}catch{a=null}if(!a)return this._fresh(t,o);if(a.diff.identical)return this._resize(e,t,r);let c=e.discovered!==null&&this._refine!=="none",d=c?this._placedWrites(e):void 0;try{this._compile(e,f=>i.applyUpdate(a,t.clip,t.duration,f))}catch{return this._fresh(t,o)}if(e.issues=Rc(t.id,i),e.generation++,e.track=t,!c)return e.frameCount=r,e;if(r>e.frameCount)return this._undiscover(e,r),e;let u=$c({patch:a,deps:e.deps,before:d,after:this._placedWrites(e),fps:this._scope.fps,propsOf:f=>{let h=i.node(f);return h?new Set(h.__cells?.slots.keys()??[]):void 0},buildsChildren:f=>{let h=i.node(f);return!!h&&h._allChildren.some(p=>i.node(p.id)!==p)},isContextProvider:f=>yn(this._scope.registry,f)}),l=this._applyDirty(e,u,r);if(r!==e.frameCount){e.frameCount=r;for(let f of e.index.setFrameCount(r).keys)l.add(f)}return this._refresh(e)&&s.deltas.set(t.id,l),e}_resize(e,t,s){let r=e.track.duration;return e.track=t,t.duration===r?e:e.steps?this._fresh(t,e.memo):(e.instance?.update(e.instance.clip,t.duration),this._refine==="none"||!e.discovered?e.frameCount=s:s>e.frameCount?this._undiscover(e,s):s!==e.frameCount&&(e.frameCount=s,e.index.setFrameCount(s),this._refresh(e)),e)}_undiscover(e,t){e.frameCount=t,e.discovered=null,this._version++}_discard(e){e.discarded=!0,!e.running&&(e.steps?.return(void 0),e.steps=null,e.instance?.dispose(),e.instance=null)}_nextUndiscovered(){let e,t=1/0;for(let s of this._spans){let r=this._entries.get(s.id);!r||r.discovered||r.running||(!e||s.startFrame<t)&&(e=r,t=s.startFrame)}return e}_start(e,t,s){let r=this._project.tracks.findIndex(o=>o.id===e.track.id);e.profile=s?this._options.profile?.track(r,e.track.id):void 0,e.steps=this._steps(e,t,s)}_drain(e){for(;e.steps&&!this._step(e););}_step(e){let t=e.steps;if(!t)return!0;e.running=!0;let s;try{s=t.next()}finally{e.running=!1}return e.generation++,e.discarded||this._disposed?(s.done||t.return(void 0),e.steps=null,e.instance?.dispose(),e.instance=null,!0):s.done?(e.steps=null,!0):!1}*_steps(e,t,s){let r=e.profile,{fps:o,assets:i}=this._scope;if(t){r?.enter("build"),e.unready.clear();try{let l=new Dn(e.track.clip,e.track.duration,this._scope);e.instance=l,this._compile(e,f=>l.build(f)),e.issues=Rc(e.track.id,l)}catch(l){e.instance?.dispose(),e.instance=null,e.failure=Ir(e.track.id,l),e.issues=[],s&&(this._resetAssets(e),this._refresh(e,!0),r?.done(e.frameCount));return}if(!s)return;yield}let a=e.instance,c=e.frameCount;this._resetAssets(e);let d=new Map;try{let l=yield*Tr(a,{fps:o,frameCount:c,catalog:i,declare:this._refine==="assets",memo:e.memo,onPhase:f=>r?.enter(f),onArrive:(f,h)=>{r?.enter("audio"),this._declareAudio(e,h,d)}});this._commit(e,l,d)}catch(l){e.refineError=Ir(e.track.id,l)}let u=this._options.isReady;if(u)for(let l of e.index.layoutGates())l.type==="loader"&&!u(l.src)&&e.unready.add(l.src);this._refresh(e,!0),r?.done(c),this._options.keepInstances===!1&&(a.dispose(),e.instance=null)}_resetAssets(e){e.index=new It(e.frameCount),e.audio=new zt,e.commandAudio=new Set,e.commandSounds=null,e.deps=new Rt,e.assetDeps.clear(),e.audioDeps.clear(),e.ownerErrors.clear(),e.audioErrors.clear(),e.refineError=null}_commit(e,t,s){let r=new Qe(e.instance);for(let o of t.owners.values()){let i=o.ownerKey;o.error?e.ownerErrors.set(i,this._ownerError(e,o)):e.index.setOwner(i,o.segments),e.assetDeps.set(i,r.idsOf(o.deps))}for(let[o,i]of s)e.audioDeps.set(o,r.idsOf(i));for(let o of new Set([...e.assetDeps.keys(),...e.audioDeps.keys()]))this._link(e,o)}_applyDirty(e,t,s){let r=new Set,o=_=>{for(let v of _.keys)r.add(v)};for(let _ of t.removed)for(let v of[_,...e.deps.ownersBelow(_)])this._drop(e,v,o);if(t.owners.size===0&&t.below.size===0)return r;let i=e.instance,{fps:a,assets:c}=this._scope,d=new Set,u=new Map,l=Tr(i,{fps:a,frameCount:s,catalog:c,owners:t.owners,below:t.below,declare:this._refine==="assets",memo:e.memo,onArrive:(_,v,A,M)=>{d.add(v),M===Je(A,a,s)?.startFrame&&this._declareAudio(e,v,u)}}),f=l.next();for(;!f.done;)f=l.next();e.generation++;let h=f.value,p=_=>{let v=t.owners.get(_);for(let A=_.indexOf("/");A>=0;A=_.indexOf("/",A+1)){let M=t.below.get(_.slice(0,A));M!==void 0&&(v===void 0||M<v)&&(v=M)}return v??0},g=_=>{if(t.arrivalOwners.has(_))return!0;for(let v=_.indexOf("/");v>=0;v=_.indexOf("/",v+1))if(t.arrivalBelow.has(_.slice(0,v)))return!0;return!1},m=new Set(h.owners.keys());for(let _ of t.below.keys())for(let v of e.deps.ownersBelow(_))m.add(v);let x=new Qe(i);for(let _ of m){let v=p(_),A=h.owners.get(_);if(!A&&v===0){this._drop(e,_,o);continue}let M=v>0?gf(e.index.declaredSegmentsOf(_),v):[];if(A?.error?e.ownerErrors.set(_,this._ownerError(e,A)):e.ownerErrors.delete(_),o(e.index.setOwner(_,A&&!A.error?[...M,...A.segments]:M)),A){let O=x.idsOf(A.deps);e.assetDeps.set(_,v>0?[...new Set([...e.assetDeps.get(_)??[],...O])]:O)}g(_)&&!d.has(_)&&(e.audio.removeOwner(_),e.audioDeps.delete(_),e.audioErrors.delete(_)),this._link(e,_)}for(let[_,v]of u)e.audioDeps.set(_,x.idsOf(v)),this._link(e,_);return r}_drop(e,t,s){s(e.index.removeOwner(t)),e.audio.removeOwner(t),e.assetDeps.delete(t),e.audioDeps.delete(t),e.ownerErrors.delete(t),e.audioErrors.delete(t),e.deps.remove(t),e.memo.forget(t)}_link(e,t){let s=e.assetDeps.get(t),r=e.audioDeps.get(t);s===void 0&&r===void 0?e.deps.remove(t):e.deps.set(t,[...s??[],...r??[]])}_declareAudio(e,t,s){s.set(t,[]);let r=e.instance?this._commandSoundsOf(e,e.instance).get(t):void 0;if(r)return this._setCommandAudio(e,e.instance,t,r);e.audio.removeOwner(t),e.audioErrors.delete(t)}_declareCommandAudio(e){let t=e.instance;if(e.commandSounds=null,!t||this._refine==="none")return;let s=this._commandSoundsOf(e,t);for(let r of e.commandAudio)s.has(r)||(e.audio.removeOwner(r),e.audioErrors.delete(r));e.commandAudio=new Set(s.keys());for(let[r,o]of s)this._setCommandAudio(e,t,r,o);e.commandSounds=null}_commandSoundsOf(e,t){if(e.commandSounds)return e.commandSounds;let s=new Map;for(let r of t.commandSounds()){let o=t.ownerKeyOf(r.node)??mf,i=s.get(o);i?i.push(r):s.set(o,[r])}return e.commandSounds=s}_setCommandAudio(e,t,s,r){let o=this._scope.assets,i=a=>{let c=t.spanOf(a);if(!c)throw new Error(`${a.className} is not in the tree, so it has no span.`);return c};try{let a=r.map((c,d)=>{let{bus:u,closed:l,...f}=c.options,h=t.atPresence(c.at,()=>{let g=u?Ss(c.node,u):null;return g?ks(g,i):c.node instanceof ht?bs(c.node,i):void 0}),p=f.trimEnd??(l?o.getMediaDuration(c.src):void 0);return si({...f,trimEnd:p,src:c.src,at:c.at,until:c.until,bus:h},o,s,d)});e.audio.setOwner(s,a),e.audioErrors.delete(s),e.commandAudio.add(s)}catch(a){e.audio.removeOwner(s),e.audioErrors.set(s,{...Ir(e.track.id,a),nodeId:r[0].node.id})}}_ownerError(e,t){let s=t.error;return{trackId:e.track.id,message:s.message,...s.stack!==void 0&&{stack:s.stack},...t.nodeId!==void 0&&{nodeId:t.nodeId},...s.prop!==void 0&&{prop:s.prop}}}_refresh(e,t=!1){this._declareCommandAudio(e);let s=e.discovered,{fps:r}=this._scope,o=s&&wf(s.assetRecords,e.index.records())?s.assetRecords:new Map(e.index.records()),i=yf(e.audio.requests(),e.frameCount/r),a=e.index.layoutGates().map(d=>d.src),c=[...e.issues,...e.audioErrors.values(),...e.ownerErrors.values(),...e.failure?[e.failure]:[],...e.refineError?[e.refineError]:[]];return!t&&s&&o===s.assetRecords&&s.frameCount===e.frameCount&&Lt(s.audioRequests,i)&&Lt(s.layoutGates,a)&&Lt(e.errors,c)?!1:(e.discovered={id:e.track.id,discovered:!0,frameCount:e.frameCount,startFrame:0,audioRequests:i,assetRecords:o,layoutGates:a},e.errors=c,this._version++,!0)}_placedWrites(e){let t=e.instance,s=new Map,r;for(let o of t.placedCommands()){let i=e.writes.get(o.writes);(!i||i.start!==o.holdFrom)&&(r??=new Qe(t),i={start:o.holdFrom,writes:r.idsOf(o.writes)},e.writes.set(o.writes,i)),s.set(o.writes,i)}return s}_compile(e,t){let s=this._options.isReady,r=this._scope.measurer;if(!s){t(r);return}let o=new Set;t({measureText(i,a,c,d,u,l){return o.add(c),r.measureText(i,a,c,d,u,l)}});for(let i of o)s(i)||e.unready.add(i)}_rebuildInstance(e){e.instance?.dispose(),e.instance=null,e.generation++,this._start(e,!0,!1),this._drain(e),e.failure&&e.discovered&&this._refresh(e)}};function Rc(n,e){return e.issues().map(({code:t,message:s,nodeId:r,commandId:o})=>({trackId:n,message:s,code:t,...r!==void 0&&{nodeId:r},...o!==void 0&&{commandId:o}}))}function Ir(n,e){let t=e instanceof Error?e:new Error(String(e));return{trackId:n,message:t.message,stack:t.stack}}function gf(n,e){let t=[];for(let s of n)s.startFrame>=e||t.push(s.endFrame>=e?{...s,endFrame:e-1}:s);return t}function yf(n,e){let t=[];for(let s of n){let r=s.bus&&_f(s.bus,e),o=r===s.bus?{...s}:{...s,bus:r};if(s.open){t.push(o);continue}if(s.startAt>=e)continue;let i=Math.min(s.endAt,e);i<=s.startAt||t.push(i===s.endAt?o:{...o,endAt:i})}return t}function _f(n,e){return n.every(t=>t.endAt<=e)?n:n.map(t=>t.endAt<=e?t:{...t,endAt:e})}function wf(n,e){if(n.size!==e.size)return!1;for(let[t,s]of n){let r=e.get(t);if(!r||!Lt(s,r))return!1}return!0}function xf(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t].id!==e[t].id||n[t].startFrame!==e[t].startFrame||n[t].endFrame!==e[t].endFrame)return!1;return!0}function Lt(n,e){if(Object.is(n,e))return!0;if(typeof n!="object"||typeof e!="object"||n===null||e===null||Array.isArray(n)!==Array.isArray(e))return!1;let t=Object.keys(n);if(t.length!==Object.keys(e).length)return!1;for(let s of t)if(!Lt(n[s],e[s]))return!1;return!0}function zc(n){return"theme"in n?n.theme:void 0}var jn=class{_scope;constructor(e,t,s){this._scope=t,this._owned=s===void 0,this._store=s??new Oe(e,t,{assets:!1,audio:!1}),this._slots=this._slotsFor(e.tracks,new Map),this._currentTrackId=Dr(this._slots)?.track.id??null}get currentFrame(){return this._currentFrame}get currentTrackId(){return this._currentTrackId}get currentCanvas(){return this.currentInstance?.canvas??null}get currentInstance(){let e=this._slotOf(this._currentTrackId);return e?.instance&&e.instance===this._store.instanceOf(e.track.id)?e.instance:null}get activeTrackIds(){return this._active.map(e=>e.track.id)}stateAt(e){if(this._disposed)return;let t=Math.max(0,Math.floor(e)),s=this._slotsToDraw(t);if(!this._stale&&t===this._currentFrame&&vf(s,this._active)&&s.every(o=>this._settled(o)))return;this._active=s;let r=Dr([...s].reverse());r&&(this._currentTrackId=r.track.id);for(let o of s)o.instance=this._store.ensureBuilt(o.track.id);for(let o of s)o.instance&&(this._evaluate(o,t-o.span.startFrame),o.generation=this._store.generationOf(o.track.id));this._currentFrame=t,this._stale=!1}layout(e=this._scope.measurer){for(let t of this._active)this._live(t)?.layout(e)}render(e){for(let t of this._active)this._live(t)?.render(e)}invalidate(){this._stale=!0}rebuild(e=this._currentTrackId){e!==null&&(this._store.rebuild(e),this._stale=!0)}setProject(e){if(this._disposed)return;this._store.setProject(e);let t=new Map(this._slots.map(r=>[r.track.id,r]));this._slots=this._slotsFor(e.tracks,t);let s=new Set(this._slots);for(let r of this._editorStates.keys())this._slotOf(r)||this._editorStates.delete(r);this._active=this._active.filter(r=>s.has(r)),this._slotOf(this._currentTrackId)||(this._currentTrackId=Dr(this._slots)?.track.id??null),this._stale=!0}setEditorStates(e,t){t?this._editorStates.set(e,t):this._editorStates.delete(e),this._stale=!0}dispose(){this._disposed=!0,this._active=[];for(let e of this._slots)e.instance=null;this._owned&&this._store.dispose()}_store;_owned;_slots;_active=[];_currentFrame=0;_currentTrackId;_stale=!1;_disposed=!1;_editorStates=new Map;_slotsFor(e,t){let s=Pt(e,this._scope.fps);return e.map((r,o)=>{let i=t.get(r.id);return i?(i.track=r,i.span=s[o],i):{track:r,span:s[o],instance:null,generation:-1}})}_slotOf(e){return e===null?void 0:this._slots.find(t=>t.track.id===e)}_settled(e){let t=e.track.id;return e.instance?e.instance===this._store.instanceOf(t)&&e.generation===this._store.generationOf(t):this._store.failed(t)}_live(e){return e.instance&&e.instance===this._store.instanceOf(e.track.id)?e.instance:null}_slotsToDraw(e){let t=this._slots.map(r=>r.span),s=Me(t,e);if(s.length===0){let r=Math.max(-1,...t.map(o=>o.endFrame));e>r&&r>=0&&(s=Me(t,r))}return s.map(r=>this._slots[r.index])}_evaluate(e,t){let s=e.instance,r=Re(1,this._scope.fps),o=se(t,this._scope.fps,e.track.duration);s.attach(o,this._editorStates.get(e.track.id));let i=Math.max(0,o-r);s.evaluateAt(i),s.layout(),s.primeMotion(i),s.evaluateAt(o),s.layout(),s.sample()}};function Dr(n){return n.find(e=>!ln(e.track.clip))}function vf(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}var Fr=4;async function Lc(n,e,t){for(let s=0;s<4;s++){if(!t())return"superseded";if(n(),!await e.warmPendingDecodes())return"settled";if(!t())return"superseded"}return"exhausted"}var Bn=class{_fps;_catalog;constructor(e,t){this._fps=e,this._catalog=t}update(e){let t=new Set,s=new Set;for(let o of e){s.add(o.id);let i=this._tracks.get(o.id);if(i&&i.records===o.records&&i.startFrame===o.startFrame)continue;let a=!i||i.startFrame!==o.startFrame;for(let[c,d]of o.records){let u=i?.records.get(c);(a||!u||!Vc(u,d))&&t.add(c),this._holders(c).add(o.id)}if(i)for(let c of i.records.keys())o.records.has(c)||(t.add(c),this._release(c,o.id));this._tracks.set(o.id,{id:o.id,startFrame:o.startFrame,records:o.records})}for(let[o,i]of this._tracks)if(!s.has(o)){this._tracks.delete(o);for(let a of i.records.keys())t.add(a),this._release(a,o)}let r;for(let o of t){let i=this._entryOf(o),a=this._map.get(o);if(i===void 0){if(a===void 0)continue;r??=new Map(this._map),r.delete(o)}else(a===void 0||!Tf(a,i))&&(r??=new Map(this._map),r.set(o,i))}return r&&(this._map=r),this._map}_tracks=new Map;_byKey=new Map;_map=new Map;_holders(e){let t=this._byKey.get(e);return t||this._byKey.set(e,t=new Set),t}_release(e,t){let s=this._byKey.get(e);s&&(s.delete(t),s.size===0&&this._byKey.delete(e))}_entryOf(e){let t=this._byKey.get(e);if(!t)return;let s;for(let r of t){let o=this._tracks.get(r),i=o.records.get(e);i&&(s=kf(s,bf(i,o.startFrame)))}return s&&Of(s,this._fps,this._catalog)}};function bf(n,e){return e===0?n:{...n,startFrame:n.startFrame+e,endFrame:n.endFrame+e}}function kf(n,e){return n?{...n,startFrame:Math.min(n.startFrame,e.startFrame),endFrame:Math.max(n.endFrame,e.endFrame)}:e}function jc(n,e){let t;try{t=n.type==="image"?e.getImageMeta(n.src):e.getVideoMeta(n.src)}catch{return 0}return!(t.width>0)&&!(t.height>0)?0:Mf(t.width,t.height)}var Sf=2,Af=2,Nr=120,$r=30;function Mf(n,e){return n*e*4/(1024*1024)}function Bc(n){return Math.min(Nr,Math.max(Af,Math.round(n*Sf)))}function Of(n,e,t){switch(n.type){case"image":{let s=Bc(jc(n,t));return{record:n,cacheAt:Math.max(0,n.startFrame-s),discardAt:n.endFrame+$r}}case"video":{let s=Math.min(Nr,Bc(jc(n,t))*2+Math.round(e));return{record:n,cacheAt:Math.max(0,n.startFrame-s),discardAt:n.endFrame+$r}}case"font":return{record:n,cacheAt:0,discardAt:null};case"loader":return{record:n,cacheAt:Math.max(0,n.startFrame-Nr),discardAt:n.endFrame+$r};default:return}}function Tf(n,e){return n.cacheAt===e.cacheAt&&n.discardAt===e.discardAt&&Vc(n.record,e.record)}function Vc(n,e){if(n===e)return!0;if(n.type!==e.type||n.src!==e.src||n.startFrame!==e.startFrame||n.endFrame!==e.endFrame)return!1;switch(n.type){case"video":{let t=e;return n.trimStart===t.trimStart&&n.trimEnd===t.trimEnd}case"font":{let t=e;return n.fontWeight===t.fontWeight&&n.fontFamily===t.fontFamily}case"loader":return n.load===e.load;default:return!0}}var Ef=["build","declare","evaluate","audio"];function Bb(){let n=[];return{timings:n,track(e,t){let s=Object.fromEntries(Ef.map(c=>[c,0])),r=null,o=we(),i=0,a=()=>{let c=we()-o;r&&(s[r]+=c),i+=c};return{enter(c){a(),r=c,o=we()},suspend(){a(),r=null},resume(){o=we()},done(c){a(),r=null,n[e]={trackId:t,trackIndex:e,frameCount:c,totalMs:i,phases:s}}}}}}var Vn=class{_scope;constructor(e,t,s={}){this._scope=t,this._owned=s.store===void 0,this._store=s.store??new Oe(e,t,{profile:s.profile,assets:s.assets,keepInstances:!1}),this._assets=new Bn(t.fps,t.assets)}get store(){return this._store}get discoveredCount(){let e=0;for(let t of this._store.tracks)this._store.isDiscovered(t.id)&&e++;return e}result(){return this._assemble()}ensureCovering(e){for(let t of Me(this._store.spans,e))this._store.discover(t.id);return this._assemble()}run(){for(let e of this._store.tracks)this._store.discover(e.id);return this._assemble()}async runAsync(e={}){let{budgetMs:t=jt,isCancelled:s,onProgress:r}=e;return await this._store.runAsync({budgetMs:t,isCancelled:s,onProgress:r&&(()=>r(this._assemble()))}),this._assemble()}setProject(e){return this._store.setProject(e),this._assemble()}learn(e,t,s,r){return this._store.learn(e,t,s,r),this._assemble()}dispose(){this._owned&&this._store.dispose()}_store;_owned;_assets;_result=null;_version=-1;_assemble(){let e=this._store;if(this._result&&this._version===e.version)return this._result;let{fps:t}=this._scope,s=e.spans,r=Oc(s),o=r/t,i=[],a=[],c=!0,d=s.map(f=>{let h=e.trackAssets(f.id);return h||(c=!1),a.push(...e.errorsOf(f.id)),h??Cf(f.id,f.endFrame-f.startFrame+1)}),u=this._assets.update(d.map((f,h)=>({id:f.id,startFrame:s[h].startFrame,records:f.assetRecords})));for(let f=0;f<d.length;f++)i.push(Pf({...d[f],startFrame:s[f].startFrame},t,o));let l=e.profile;return this._version=e.version,this._result={fps:t,tracks:i,totalFrames:r,totalDuration:o,assets:u,buildErrors:a,complete:c,timings:l?.timings?.slice()}}};function Cf(n,e){return{id:n,discovered:!1,frameCount:e,startFrame:0,audioRequests:[],assetRecords:new Map,layoutGates:[]}}function Pf(n,e,t){if(!n.audioRequests.some(o=>o.open))return n;let s=n.startFrame/e,r=n.audioRequests.map(o=>{if(!o.open)return o;let i=s+o.startAt,a=o.loop?t:Math.min(i+(o.mediaDuration??0),t);return{...o,endAt:Math.max(o.startAt,a-s)}});return{...n,audioRequests:r}}function et(n){return typeof n?._isViewport3D=="function"&&n._isViewport3D()}function Lr(n,e,t){let s=Br(n);if(!s)return[];let r=[];for(let o of jr(n,t)){let i=s.boxes.get(o.node.id);if(!i)continue;let a=Jc(i,s);a&&r.push({box:Zc(o.node,o.path,a.rect,e),depth:a.depth})}return r.sort((o,i)=>i.depth-o.depth),r.map(o=>o.box)}var If={x:0,y:0,z:0};function Wc(n,e,t,s,r,o){let i=jr(n,t).find(h=>h.path===s);if(!i)return null;let a=Br(n,i.node.id);if(!a)return null;let c=a.matrices.get(i.node.id),d=a.parentMatrices.get(i.node.id);if(!c||!d)return null;let u=(h,p)=>p.map(g=>Kc(h,g,a,e)),l=wo(i.node),f=l?r.map(h=>l.toLocal(h.x,h.y,h.z)):r;return{origin:Kc(c,If,a,e),parentPoints:u(d,f),localPoints:u(c,o),bounds:a.localBounds}}function Kc(n,e,t,s){let r=le(n,e),o=le(t.clip,{x:r.x,y:r.y,z:r.z});if(o.w<=Bt)return null;let i=o.x/o.w,a=o.y/o.w,c=t.centerX+i*(t.width/2),d=t.centerY+a*(t.height/2),u=j(s.matrix,{x:c,y:-d});return{x:u.x,y:-u.y}}function Xc(n,e,t,s,r){let o=Br(n);if(!o)return null;let i=de(e.matrix);if(!i)return null;let a=j(i,{x:t.x,y:-t.y}),c={x:a.x,y:-a.y},d=null,u=-1/0;for(let l of jr(n,r)){let f=o.boxes.get(l.node.id);if(!f)continue;let h=Jc(f,o);h&&zf(h.rect,c,s)&&(h.depth<=u||(u=h.depth,d={node:l.node,path:l.path,rect:h.rect}))}return d?Zc(d.node,d.path,d.rect,e):null}function jr(n,e){let t=[];return qc(n._allChildren,e,t),t}function qc(n,e,t){for(let s=0;s<n.length;s++){let r=n[s];if(!(r instanceof xo))continue;let o=ye(e,s);t.push({node:r,path:o}),qc(r._allChildren,o,t)}}function Br(n,e){let t=n._localBounds();if(!(t.width>0)||!(t.height>0))return null;let s=n._scene3D();if(!s)return null;let r=Df(s,e);if(r.boxes.size===0)return null;let o=Ot(r.camera);if(!o)return null;let i=t.width/t.height;return{boxes:r.boxes,matrices:r.matrices,parentMatrices:r.parentMatrices,clip:ae(Nf(r.descriptor,i),o),view:o,width:t.width,height:t.height,centerX:t.x,centerY:t.y,localBounds:r.localBounds}}function Df(n,e){let t=new Map,s=new Map,r=new Map,i=[{key:void 0,matrix:Mn(),visible:!0,box:null}],a=null,c=null,d=null,u=null,l=()=>i[i.length-1];for(let f of n.ops()){let h=l();switch(f.kind){case"push":{let p=Hc(h.matrix,f.transform);if(f.transform?.key!==void 0&&(s.set(f.transform.key,p),r.set(f.transform.key,h.matrix),f.transform.key===e)){let g=Ot(p);g&&(d={depth:i.length,inverse:g})}i.push({key:f.transform?.key,matrix:p,visible:h.visible&&f.transform?.visible!==!1,box:null});break}case"pop":{if(i.length===1)break;d?.depth===i.length-1&&(d=null);let p=i.pop();if(!p.visible||!p.box)break;p.key!==void 0&&t.set(p.key,p.box);let g=l();g.box=Xe(g.box,p.box);break}case"camera":{c=f.camera,a=Ff(f.camera,h.matrix);break}case"light":break;default:{if(!h.visible)break;let p=Uc(f,h.matrix);p&&(h.box=Xe(h.box,p)),d&&(u=Xe(u,Uc(f,h.matrix,d.inverse)));break}}}return{boxes:t,matrices:s,parentMatrices:r,camera:a??$f,descriptor:c,localBounds:u}}function Hc(n,e){return ae(n,Et(e,n))}function Uc(n,e,t){if(n.kind==="model"||!("transform"in n))return null;let s=Hc(e,n.transform),r=t?ae(t,s):s;if(n.kind==="sprite")return qe(q(.5,.5,0),r);if(!("geometry"in n))return null;let o=En(n.geometry);if(!o)return null;if(n.kind==="instances"){let i=null;for(let a of n.instances)i=Xe(i,qe(o,Et(a,null)));return i?qe(i,r):null}return qe(o,r)}function Ff(n,e){let t=Us(n);if(t.lookAt===void 0)return ae(e,Et({...n,position:t.position},e));let s=le(e,t.position),r={x:s.x,y:s.y,z:s.z};return ae(Ct(r),Tt(r,t.lookAt))}var $f=ae(Ct({x:0,y:0,z:5}),Tt({x:0,y:0,z:5},{x:0,y:0,z:0})),Gc=50,Rr=.1,zr=1e3;function Nf(n,e){if(n===null)return On(Gc,e,Rr,zr,1);if(n.type==="perspective")return On(n.fov??Gc,e,n.near??Rr,n.far??zr,n.zoom??1);let t=(n.frustumHeight??10)/2;return Sr(-t*e,t*e,t,-t,n.near??Rr,n.far??zr,n.zoom??1)}var Rf=[[0,1],[2,3],[4,5],[6,7],[0,2],[1,3],[4,6],[5,7],[0,4],[1,5],[2,6],[3,7]],Bt=1e-4,Yc=8;function Jc(n,e){let s=Tn(n).map(x=>le(e.clip,x)),r=1/0,o=1/0,i=-1/0,a=-1/0,c=!1,d=(x,_,v)=>{let A=x/v,M=_/v;A<r&&(r=A),M<o&&(o=M),A>i&&(i=A),M>a&&(a=M),c=!0};for(let[x,_]of Rf){let v=s[x],A=s[_],M=v.w>Bt,O=A.w>Bt;if(!M&&!O||(M&&d(v.x,v.y,v.w),O&&d(A.x,A.y,A.w),M===O))continue;let H=(Bt-v.w)/(A.w-v.w);d(v.x+(A.x-v.x)*H,v.y+(A.y-v.y)*H,Bt)}if(!c)return null;let u=e.width/2,l=e.height/2,f=u*Yc,h=l*Yc,p={minX:Kn(e.centerX+r*u,e.centerX-f,e.centerX+f),maxX:Kn(e.centerX+i*u,e.centerX-f,e.centerX+f),minY:Kn(e.centerY+o*l,e.centerY-h,e.centerY+h),maxY:Kn(e.centerY+a*l,e.centerY-h,e.centerY+h)},g={x:(n.min.x+n.max.x)/2,y:(n.min.y+n.max.y)/2,z:(n.min.z+n.max.z)/2},m=le(e.view,g);return{rect:p,depth:m.z}}function Kn(n,e,t){return n<e?e:n>t?t:n}function zf(n,e,t){return e.x>=n.minX-t&&e.x<=n.maxX+t&&e.y>=n.minY-t&&e.y<=n.maxY+t}function Zc(n,e,t,s){let r=(o,i)=>{let a=j(s.matrix,{x:o,y:-i});return{x:a.x,y:-a.y}};return{id:n.id,path:e,type:n.className,topLeft:r(t.minX,t.maxY),topRight:r(t.maxX,t.maxY),bottomRight:r(t.maxX,t.minY),bottomLeft:r(t.minX,t.minY),center:r((t.minX+t.maxX)/2,(t.minY+t.maxY)/2),width:t.maxX-t.minX,height:t.maxY-t.minY,rotation:s.box.rotation,scale:s.box.scale,opacity:s.box.opacity,locked:n.locked}}function re(n){let e=qt(n);if(e)return he(re(e.root),e.screen);let t=n.parent;return t?he(Vt(t),n._localMatrix()):n._localMatrix()}function Vt(n){let e=re(n),t=n._spaceCamera();if(t)return he(e,Xt(n,t).screen);let s=n._cameraScope();if(!s)return e;let r=n.layoutBounds;return he(e,fs(r.x,-r.y,s.lookAt,s.zoom,s.heading))}function ed(n,e,t){if(e==="")return null;let s=Te(n,e),r=s instanceof R?s.parent:null;if(!(s instanceof R)||!r)return null;let o=od(s,r),i=de(o);if(!i)return null;let a=j(i,{x:t.x,y:-t.y});if(Vr(o,a))return null;let c=r._planeOf(s);if(!c)return{x:a.x,y:-a.y};let d=s._placement()?null:s.layoutBounds;return c.toCoords(a.x-(d?.x??0),(d?.y??0)-a.y)}function td(n,e,t){let s=Te(n,e);if(!(s instanceof R))return null;let r=s._planeOf(null);if(!r)return null;let o=de(Vt(s));if(!o)return null;let i=j(o,{x:t.x,y:-t.y});return r.toCoords(i.x,-i.y)}function nd(n,e,t,s){let r=Te(n,e),o=Te(n,t),i=r instanceof R?r.parent:null;if(!(r instanceof R)||!(i instanceof R)||!(o instanceof R))return null;for(let V=o;V;V=V.parent)if(V===r)return null;let a=r.layoutBounds,c=o._planeOf(null),d=c?null:o._slotFor({width:a?.width??0,height:a?.height??0});if(!c&&!d)return null;let u=od(r,i),l=de(u),f=de(Vt(o));if(!l||!f)return null;let h=r._placement(),p=Qc(i),g=Qc(o),m=p.rotation+(h?.rotation??0)-g.rotation,x=g.scale===0?1:p.scale*(h?.scale??1)/g.scale,_=r._centreShift(r.rotation+m,r.scale*x),v=j(l,j(re(r),{x:0,y:0})),A=i._planeOf(r),M=V=>A?{...A.toOffset(V.x,V.y)}:V,O=M({x:r.x,y:r.y});return{offsets:s.map(V=>{let tt=M(V),D=j(u,{x:v.x+tt.x-O.x,y:v.y-(tt.y-O.y)}),J=j(f,D),oe=J.x-_.x,nt=J.y-_.y;return c?c.toCoords(oe,-nt):{x:oe-d.x,y:d.y-nt}}),turn:m,scale:x}}function Qc(n){let e=id(n),t=n._cameraScope();return t?{rotation:e.rotation-t.heading,scale:e.scale*t.zoom}:e}function sd(n,e){let t=Te(n,e);if(!(t instanceof R))return null;let s=re(t);return t._handles().map(({prop:r,at:o})=>{let i=j(s,{x:o.x,y:-o.y});return{prop:r,at:{x:i.x,y:-i.y}}})}function rd(n,e,t,s){let r=Te(n,e);if(!(r instanceof R))return null;let o=re(r),i=de(o);if(!i)return null;let a=j(i,{x:s.x,y:-s.y});return Vr(o,a)?null:r._handleValue(t,{x:a.x,y:-a.y})}function od(n,e){let t=qt(n)?vs(e):null;if(!t){let i=n._slotMatrix();return i?he(Vt(e),i):Vt(e)}let s=n._slotAffine(),r=s?ps(t.view,s):t.view,o=ps(r,[1,0,0,0,0,1,0,0,0,0,1,n.depth]);return he(re(t.root),so(t.camera,o))}function Vr(n,e){return us(n)&&(n.g??0)*e.x+(n.h??0)*e.y+(n.i??1)<=0}function id(n){let e=0,t=1,s=1;for(let r=n;r;r=r.parent){let o=r._placement();e+=r.rotation+(o?.rotation??0),t*=r.scale*(o?.scale??1),s*=r.opacity*(o?.opacity??1);let i=r!==n?r._cameraScope():null;i&&(e-=i.heading,t*=i.zoom)}return{rotation:e,scale:t,opacity:s}}function Kt(n,e){let t=n._localBounds(),s=t.x===0&&t.y===0?re(n):he(re(n),ls(t.x,-t.y)),r=go(s,t.width/2,t.height/2),o=id(n);return{id:n.id,path:e,type:n.className,topLeft:r.topLeft,topRight:r.topRight,bottomRight:r.bottomRight,bottomLeft:r.bottomLeft,center:r.center,width:t.width,height:t.height,rotation:o.rotation,scale:o.scale,opacity:o.opacity,locked:n.locked}}function ad(n,e){if(e==="")return Kt(n,e);let t=n,s=null,r=e.split(".");for(let i=0;i<r.length;i++){et(t)&&(s={node:t,path:cd(r,i)});let a=t._allChildren[Number(r[i])];if(!a)return null;t=a}if(t instanceof R)return Kt(t,e);if(!s)return null;let o=Un(s.node,s.path);return Lr(s.node,o,s.path).find(i=>i.path===e)??null}function Te(n,e){if(e==="")return n;let t=n;for(let s of e.split(".")){let r=t._allChildren[Number(s)];if(!r)return null;t=r}return t}function cd(n,e){return n.slice(0,e).join(".")}function dd(n,e,t,s){if(e==="")return null;let r=n,o=null,i=e.split(".");for(let c=0;c<i.length;c++){et(r)&&(o={node:r,path:cd(i,c)});let d=r._allChildren[Number(i[c])];if(!d)return null;r=d}if(r instanceof R||!o)return null;let a=Un(o.node,o.path);return Wc(o.node,a,o.path,e,t,s)}function ud(n,e,t=0){return ld(n,"",e,t,!0)}function ld(n,e,t,s,r){if(n.opacity===0||n.hidden)return null;let o=fd(n,r);if(o==="none")return null;let i=o==="all"&&Lf(n,t,s);if(!i&&o==="all"&&n._confinesChildren())return null;let a=pd(n),c=hd(n,a);for(let d=c.length-1;d>=0;d--){let u=c[d],l=a[u];if(l===null)continue;let f=ld(l,ye(e,u),t,s,!1);if(f)return f}if(et(n)&&i){let d=Xc(n,Un(n,e),t,s,e);if(d)return d}return r||n.locked?null:i?Kt(n,e):null}function Kr(n,e,t,s){if(n.opacity===0||n.hidden)return;let r=fd(n,s);if(r==="none")return;if(!s&&r==="all"&&t.push(Kt(n,e)),et(n))for(let i of Lr(n,Un(n,e),e))t.push(i);let o=pd(n);for(let i of hd(n,o)){let a=o[i];a!==null&&Kr(a,ye(e,i),t,!1)}}function fd(n,e){if(e)return"all";let t=qt(n);return t?!n.backfaceVisible&&t.facesAway?"none":t.paints?"all":n._rendersChildrenInSpace()?"children":"none":"all"}function hd(n,e){let t=e.map((i,a)=>a),s=vs(n);if(!s)return t;let r=t.filter(i=>e[i]!==null),o=r.map(i=>yo(s,e[i]));return _o(o).map(i=>r[i])}function pd(n){return et(n)?n._allChildren.map(e=>e instanceof R?e:null):n.children}function Un(n,e){return{box:Kt(n,e),matrix:re(n)}}function Lf(n,e,t){let s=re(n),r=de(s);if(!r)return!1;let o=j(r,{x:e.x,y:-e.y});return Vr(s,o)?!1:n._hitTestSelf({x:o.x,y:-o.y},t)}function md(n,e,t){let s=n instanceof un?Lo(n):null;if(!s)return null;let r=t.layoutTextBlock(s);if(!r)return null;let o=re(n),i=(d,u)=>{let l=j(o,{x:d,y:u});return{x:l.x,y:-l.y}},a=new Array(yr(r)),c=[];for(let d of r.lines){c.push({start:d.start,end:d.end});for(let u=0;u<d.carets.length;u++){let l=d.carets[u];a[d.start+u]={offset:d.start+u,top:i(l,d.top),bottom:i(l,d.bottom)}}}return{path:e,text:n.text,carets:a,lines:c}}function dk(n,e){let t=0,s=1/0;for(let r of n.carets){let o=jf(e,r.top,r.bottom);o<s&&(s=o,t=r.offset)}return t}function uk(n,e,t){let s=Math.max(0,Math.min(e,t)),r=Math.min(n.carets.length-1,Math.max(e,t)),o=[];for(let i of n.lines){let a=Math.max(s,i.start),c=Math.min(r,i.end);if(a>=c)continue;let d=n.carets[a],u=n.carets[c];o.push({topLeft:d.top,topRight:u.top,bottomRight:u.bottom,bottomLeft:d.bottom})}return o}function jf(n,e,t){let s=t.x-e.x,r=t.y-e.y,o=s*s+r*r,i=o===0?0:Math.max(0,Math.min(1,((n.x-e.x)*s+(n.y-e.y)*r)/o));return Math.hypot(n.x-(e.x+i*s),n.y-(e.y+i*r))}var Gn=class{renderContext;measurer;storageAdapter;masterClock;stateEvaluator;assetManager;audioDevice;assetCatalog;onFramePainted;disposed=!1;precompRunning=!1;hasPainted=!1;seekGeneration=0;precompBudgetMs;onPrecompProgress;fps;viewport;precomper;store;overrides=new Map;precomp;get spans(){return this.precomp.tracks.map((e,t)=>({id:e.id,index:t,startFrame:e.startFrame,endFrame:e.startFrame+e.frameCount-1}))}get totalFrames(){return this.precomp.totalFrames}get totalDuration(){return this.precomp.totalDuration}get currentTrackId(){return this.stateEvaluator.currentTrackId}get buildErrors(){return this.renderErrors.length===0?this.precomp.buildErrors:[...this.precomp.buildErrors,...this.renderErrors]}renderErrors=[];onRenderError;captureRenderError(e,t,s){let r=e instanceof Error?e:new Error(String(e));if(!(t!==void 0&&this.recoverMissingAsset(r,t))){if(s){let o=An(s);if(this.renderErrors.some(i=>i.issue&&An(i.issue)===o))return}else if(this.renderErrors.some(o=>!o.issue&&o.message===r.message))return;this.renderErrors.push({trackId:this.stateEvaluator.currentTrackId??"",message:r.message,...s?{issue:s,...s.nodeId!==void 0&&{nodeId:s.nodeId}}:{stack:r.stack}}),this.onRenderError?.(this.buildErrors)}}learnMissingAsset(e,t){let s=Kf(e,this.assetCatalog);if(s)for(let r of[...this.stateEvaluator.activeTrackIds].reverse()){let o=this.store.instanceOf(r),i=this.precomp.tracks.find(d=>d.id===r);if(!o||!i)continue;let a;if(e.nodeId!==void 0&&o.forEachOwner((d,u)=>{a===void 0&&d.id===e.nodeId&&(a=u)}),a??=this.store.ownersOf(r,e.src).values().next().value,a===void 0)continue;let c=this.precomper.learn(r,a,s,Math.floor(t)-i.startFrame);c!==this.precomp&&this.adoptPrecomp(c);return}}rescuedAssets=new Set;recoverMissingAsset(e,t){if(!(e instanceof ho)||e.assetType==="audio")return!1;let s=`${e.assetType}:${e.src}`;if(this.rescuedAssets.has(s))return!1;this.rescuedAssets.add(s),this.learnMissingAsset(e,t);let r=this.recordFor(e.assetType,e.src,t);return r?(this.storageAdapter.loadAsset(e.src,r).then(()=>{this.disposed||(this.renderAt(this.stateEvaluator.currentFrame),this.settleTrailing())}).catch(o=>{this.disposed||this.captureRenderError(new Error(`${e.message}
10
-
11
- Loading it directly also failed: ${String(o)}`))}),!0):!1}recordFor(e,t,s){try{return e==="font"?{type:"font",src:t,startFrame:s,endFrame:s,fontFamily:t,fontWeight:400}:e==="image"?(this.assetCatalog.getImageMeta(t),{type:"image",src:t,startFrame:s,endFrame:s}):(this.assetCatalog.getVideoMeta(t),{type:"video",src:t,startFrame:s,endFrame:s,trimStart:0,trimEnd:this.assetCatalog.getVideoDuration(t)})}catch{return null}}clearRenderErrors(){this.rescuedAssets.clear(),this.renderErrors.length!==0&&(this.renderErrors.length=0,this.onRenderError?.(this.buildErrors))}constructor(e){let{project:t}=e;if(t.fps===void 0||t.viewport===void 0)throw new Error("PlaybackController takes a project whose fps and viewport are resolved \u2014 see Session.");this.renderContext=e.renderContext,this.measurer=e.measurer,this.masterClock=e.masterClock,this.storageAdapter=e.storageAdapter,this.audioDevice=e.audioDevice,this.fps=t.fps,this.viewport=t.viewport,this.precompBudgetMs=e.precompBudgetMs??jt,this.onPrecompProgress=e.onPrecompProgress,this.assetCatalog=e.assets;let s={registry:e.registry,viewport:this.viewport,fps:this.fps,assets:e.assets,measurer:this.measurer};this.store=new Oe(t,s,{profile:e.precompProfile,isReady:r=>this.assetManager?.isReady(r)??!1}),this.precomper=new Vn(t,s,{store:this.store}),this.precomp=this.precomper.ensureCovering(0),this.stateEvaluator=new jn(t,s,this.store),this.assetManager=new Cn(this.precomp,this.storageAdapter,this.audioDevice,r=>this.captureRenderError(r)),this.masterClock.setDuration(this.totalDuration),this.masterClock.onPlay((r,o,i)=>{this.audioDevice.play(r,o,i),this.storageAdapter.setPlaying(!0)}),this.masterClock.onPause(()=>{this.audioDevice.stop(),this.storageAdapter.setPlaying(!1)}),this.masterClock.onTick(async r=>{let o=++this.seekGeneration,i=xe(r,this.fps);i>=this.totalFrames&&this.masterClock.pause(),this.discoverThrough(i),await this.loadFrame(i),this.isCurrent(o)&&(this.audioDevice.syncTo(r),this.renderAt(i),this.assetManager.prefetch(i),this.trimAround(i))}),this.startBackgroundPrecomp()}startBackgroundPrecomp(){this.precompRunning||this.disposed||this.precomp.complete||(this.precompRunning=!0,(async()=>{try{for(await In();!this.disposed&&!this.precomp.complete;){let e=await this.precomper.runAsync({budgetMs:this.precompBudgetMs,isCancelled:()=>this.disposed,onProgress:t=>this.adoptPrecomp(t)});if(this.disposed)return;this.precomp.complete||this.adoptPrecomp(e)}}finally{this.precompRunning=!1}})())}adoptPrecomp(e){this.disposed||(this.precomp=e,this.assetManager.setPrecomp(e),this.masterClock.setDuration(this.totalDuration),this.onPrecompProgress?.(e))}discoverThrough(e){let t=this.precomper.ensureCovering(Math.floor(e));t!==this.precomp&&this.adoptPrecomp(t)}async loadFrame(e){let t=[];for(let s of Me(this.store.spans,Math.floor(e)))for(let r of this.store.layoutGates(s.id))this.assetManager.isReady(r.src)||t.push(r);if(t.length===0){await this.assetManager.loadAt(e);return}await Promise.all([this.assetManager.loadAt(e),this.assetManager.loadRecords(t)])}trimAround(e){Math.abs(e-this.lastTrimFrame)<this.fps||(this.lastTrimFrame=e,this.store.trim(Math.floor(e),Math.ceil(Bf*this.fps)))}lastTrimFrame=0;get isPlaying(){return this.masterClock.isPlaying}get currentTime(){return this.masterClock.currentTime}get currentFrame(){return xe(this.masterClock.currentTime,this.fps)}onTime(e){this.masterClock.onTime(e)}onPlay(e){this.masterClock.onPlay(()=>e())}onPause(e){this.masterClock.onPause(e)}isCurrent(e){return!this.disposed&&e===this.seekGeneration}renderAt(e){if(!this.disposed){this.hasPainted=!0,this.renders++;try{this.store.settleGates(Me(this.store.spans,Math.floor(e)).map(t=>t.id)),this.stateEvaluator.stateAt(e),this.applyOverrides(),this.stateEvaluator.layout(this.measurer),this.renderContext.execute(()=>{this.stateEvaluator.render(this.renderContext)});for(let t of this.renderContext.takeRenderIssues()){let s=wr(t);this.captureRenderError(new Error(s.message),void 0,s)}}catch(t){this.captureRenderError(t,e)}this.announcePaint(e)}}announcePaint(e){if(this.onFramePainted)try{this.onFramePainted(Math.floor(e))}catch(t){console.error("[PlaybackController] onFramePainted listener threw:",t)}}async seek(e){if(this.disposed)return;let t=++this.seekGeneration;this.paintInFlight=t;try{let s=Math.max(0,Math.min(e,this.totalFrames));if(this.masterClock.pause(),this.discoverThrough(s),this.masterClock.seek(Re(s,this.fps)),await this.loadFrame(s),!this.isCurrent(t)||await this.settle(()=>this.renderAt(s),t)==="superseded")return;this.assetManager.prefetch(s),this.trimAround(s)}finally{this.paintLanded(t)}}setProject(e){if(this.disposed)return;let t=++this.seekGeneration;this.precomper.setProject(e),this.stateEvaluator.setProject(e),this.discoverThrough(this.currentFrame),this.clearRenderErrors(),this.masterClock.setDuration(this.totalDuration);let s=Math.min(this.currentFrame,Math.max(0,this.totalFrames-1));this.pendingSwap=t,this.paintInFlight=t,this.lastReplacePaint=this.loadAndRepaint(s,t),this.startBackgroundPrecomp()}reconcileCatalog(){this.disposed||(this.store.reset(),this.setProject(this.store.project))}whenReplaced(){return this.lastReplacePaint}lastReplacePaint=Promise.resolve();pendingSwap=0;async loadAndRepaint(e,t){try{try{await this.loadFrame(e)}catch(s){console.error("[PlaybackController] swap asset load failed:",s);return}await this.settle(()=>this.renderAt(e),t)}finally{this.pendingSwap===t&&(this.pendingSwap=0),this.paintLanded(t)}}seekWhilePlaying(e){++this.seekGeneration;let t=Math.max(0,Math.min(e,this.totalFrames));this.masterClock.seek(Re(t,this.fps))}async screenshot(){let e=this.stateEvaluator.currentFrame,t=++this.seekGeneration;this.paintInFlight=t;try{return await this.loadFrame(e),!this.isCurrent(t)||await this.settle(()=>this.renderAt(e),t,!0)==="superseded"?void 0:this.renderContext.screenshot()}finally{this.paintLanded(t)}}async settle(e,t,s=!1){let r=s?Vf(this.storageAdapter):this.storageAdapter,o=await Lc(e,r,()=>this.isCurrent(t));return o==="exhausted"&&console.warn(`[PlaybackController] frame ${this.stateEvaluator.currentFrame} still had decodes pending after ${4} passes`),o}paintInFlight=0;renders=0;repaintOwedSince=null;paintLanded(e){if(!(this.paintInFlight!==e||this.disposed)){if(this.paintInFlight=0,this.repaintOwedSince!==null){let t=this.renders===this.repaintOwedSince;this.repaintOwedSince=null,t&&!this.isPlaying&&this.renderAt(this.stateEvaluator.currentFrame)}this.settleTrailing()}}getTreeState(){let e=this.stateEvaluator.currentInstance;if(!e)return null;let t=this.precomp.tracks.find(c=>c.id===this.stateEvaluator.currentTrackId),s=t?.startFrame??0,r=t?.frameCount??He(e.duration,this.fps),o=new Map,i=new Map;e.forEachOwner((c,d,u,l)=>{i.set(d,l);let f=Je(u,this.fps,r);f&&o.set(l,{startFrame:s+f.startFrame,endFrame:s+f.endFrame})});let a=Uf(t?.audioRequests??[],i);return yd(e.canvas,"",o,a)}getNodeState(e){let t=this.stateEvaluator.currentCanvas;if(!t)return null;let s=_d(t,e);return s?{id:s.id,type:s.className,properties:s.properties}:null}getNodeInitialProps(e){return this.stateEvaluator.currentInstance?.baselineProps(e)??null}getNodeBox(e){let t=this.stateEvaluator.currentCanvas;return t?ad(t,e):null}getNodePropsAt(e){let t=this.stateEvaluator.currentCanvas;if(!t)return null;let s=Te(t,e);return s?s.properties:null}getNodeBoxes(){let e=this.stateEvaluator.currentCanvas;if(!e)return[];let t=[];return Kr(e,"",t,!0),t}projectNode3D(e,t,s){let r=this.stateEvaluator.currentCanvas;return r?dd(r,e,t,s):null}parentPlanePoint(e,t){let s=this.stateEvaluator.currentCanvas;return s?ed(s,e,t):null}childPlanePoint(e,t){let s=this.stateEvaluator.currentCanvas;return s?td(s,e,t):null}reparentPlacement(e,t,s){let r=this.stateEvaluator.currentCanvas;return r?nd(r,e,t,s):null}nodeHandles(e){let t=this.stateEvaluator.currentCanvas;return t?sd(t,e):null}handleValue(e,t,s){let r=this.stateEvaluator.currentCanvas;return r?rd(r,e,t,s):null}getTextLayout(e){let t=this.stateEvaluator.currentCanvas;if(!t)return null;let s=gd(t,e);return s instanceof R?this.textLayoutOf(s,e):null}textLayoutOf(e,t){let s=xc(this.measurer);return s?md(e,t,s):null}pickNode(e,t=0){let s=this.stateEvaluator.currentCanvas;return s?ud(s,e,t):null}setNodeOverride(e,t){let s=this.overrides.get(e);this.overrides.set(e,s?{...s,...t}:{...t}),this.applyOverrides()}clearNodeOverrides(e){(e===void 0?this.overrides.size>0&&(this.overrides.clear(),!0):this.overrides.delete(e))&&(this.stateEvaluator.rebuild(),this.repaint())}setEditorStates(e,t){this.stateEvaluator.setEditorStates(e,t),this.repaint()}repaint(){this.hasPainted&&(this.pendingSwap!==0&&this.isCurrent(this.pendingSwap)||(this.renderAt(this.stateEvaluator.currentFrame),this.settleTrailing()))}settleTrailing(){this.trailingSettle||this.disposed||this.isPlaying||!this.hasBackgroundDecodes()||this.repaintBehindDecodes().catch(e=>{console.error("[PlaybackController] background decode failed:",e)})}trailingSettle=!1;hasBackgroundDecodes(){return this.storageAdapter.hasPendingDecodes()||this.storageAdapter.hasPendingUpgrades()}async repaintBehindDecodes(){this.trailingSettle=!0;try{for(let e=0;e<4&&this.hasBackgroundDecodes();e++){let[t,s]=await Promise.all([this.storageAdapter.warmPendingDecodes(),this.storageAdapter.warmPendingUpgrades()]);if(!(t||s)||this.disposed||this.isPlaying)return;if(this.paintInFlight!==0){this.repaintOwedSince=this.renders;return}this.renderAt(this.stateEvaluator.currentFrame)}}finally{this.trailingSettle=!1}}applyOverrides(){if(this.overrides.size===0)return;let e=this.stateEvaluator.currentCanvas;if(e)for(let[t,s]of this.overrides)gd(e,t)?.set(s)}play(e=1,t=!1){if(this.currentFrame>=this.totalFrames){this.seek(0).then(()=>this.masterClock.play(e,t)).catch(()=>{});return}this.masterClock.play(e,t)}pause(){this.masterClock.pause()}setMuted(e){this.audioDevice.setMuted(e)}dispose(){this.disposed=!0,this.masterClock.dispose(),this.audioDevice.dispose(),this.stateEvaluator.dispose(),this.store.dispose(),this.assetManager.dispose()}},Bf=30;function Vf(n){return{async warmPendingDecodes(){let[e,t]=await Promise.all([n.warmPendingDecodes(),n.warmPendingUpgrades()]);return e||t}}}function Kf(n,e){switch(n.assetType){case"image":return{type:"image",src:n.src};case"font":return{type:"font",family:n.src,weight:400};case"video":try{return{type:"video",src:n.src,trimStart:0,trimEnd:e.getVideoDuration(n.src)}}catch{return}default:return}}function yd(n,e,t,s){let r={id:n.id,path:e,type:n.className,children:n._allChildren.map((a,c)=>yd(a,ye(e,c),t,s))},o=s.get(e);o&&o.length>0&&(r.waveform=o);let i=t.get(e);return i&&(r.startFrame=i.startFrame,r.endFrame=i.endFrame),r}function Uf(n,e){let t=new Map;for(let s of n){let r=s.ownerId!==void 0?e.get(s.ownerId):"";if(r===void 0)continue;let o={src:s.src,startTime:s.startAt,endTime:Number.isFinite(s.endAt)?s.endAt:null},i=t.get(r);i?i.push(o):t.set(r,[o])}return t}function gd(n,e){if(e==="")return n;let t=n;for(let s of e.split(".")){let r=t._allChildren[Number(s)];if(!r)return null;t=r}return t}function _d(n,e){if(n.id===e)return n;for(let t of n._allChildren){let s=_d(t,e);if(s)return s}return null}var Yn=class{manifest;constructor(e){this.manifest=e}reconcile(e){this.manifest=e}normalizeKey(e){return e.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,"")}getImageMeta(e){let t=this.manifest.image[this.normalizeKey(e)];if(!t)throw new Error(`Image asset not found: "${e}". Check the file exists in your public folder and the src matches its filename.`);return t}getVideoMeta(e){let t=this.manifest.video[this.normalizeKey(e)];if(!t)throw new Error(`Video asset not found: "${e}". Check the file exists in your public folder and the src matches its filename.`);return t}getAudioMeta(e){let t=this.manifest.audio[this.normalizeKey(e)];if(!t)throw new Error(`No audio metadata for src: ${e}`);return t}getFontMeta(e){let t=this.manifest.font[e];if(!t)throw new Error(`No font metadata for key: ${e}`);return t}getFontFamilyMetas(e){return Object.values(this.manifest.font).filter(t=>t.fontFamily===e)}getVideoDuration(e){return this.getVideoMeta(e).duration}getAudioDuration(e){return this.getAudioMeta(e).duration}getMediaDuration(e){let t=this.normalizeKey(e),s=this.manifest.audio[t];if(s)return s.duration;let r=this.manifest.video[t];if(r)return r.duration;throw new Error(`Audio asset not found: "${e}". Check the file exists in your public folder and the src matches its filename.`)}getImageSize(e){let{width:t,height:s}=this.getImageMeta(e);return{width:t,height:s}}};var Wn=class{controller;constructor(e){this.controller=e}get isPlaying(){return this.controller.isPlaying}get frame(){return this.controller.currentFrame}play(e=1,t=!1){this.controller.play(e,t)}pause(){this.controller.pause()}seekFrame(e){this.controller.seekWhilePlaying(e)}setMuted(e){this.controller.setMuted(e)}onTime(e){this.controller.onTime(e)}onPlay(e){this.controller.onPlay(e)}onPause(e){this.controller.onPause(e)}};var Xn=class{_isPlaying=!1;_currentTime=0;_duration=0;get isPlaying(){return this._isPlaying}get currentTime(){return this._currentTime}get duration(){return this._duration}setDuration(e){this._duration=e}setCurrentTime(e,t=!0){if(this._currentTime!==e&&(this._currentTime=e,!!t))for(let s of this.timeCallbacks)s(e)}setPlaying(e){this._isPlaying=e}play(e,t){this._isPlaying=!0;for(let s of this.playCallbacks)s(this._currentTime,e,t)}async tick(){await Promise.all(this.tickCallbacks.map(e=>e(this._currentTime)))}pause(){this._isPlaying=!1;for(let e of this.pauseCallbacks)e()}tickCallbacks=[];playCallbacks=[];pauseCallbacks=[];timeCallbacks=[];dispose(){this.tickCallbacks.length=0,this.playCallbacks.length=0,this.pauseCallbacks.length=0,this.timeCallbacks.length=0}onTick(e){this.tickCallbacks.push(e)}onPlay(e){this.playCallbacks.push(e)}onPause(e){this.pauseCallbacks.push(e)}onTime(e){this.timeCallbacks.push(e)}};var qn=class extends Xn{seek(e){this.setCurrentTime(e)}};var wd=class{engine;viewport;fps;constructor(e,t){this.engine=e,this._override={viewport:t.viewport,fps:t.fps},this._project=xd(t.document,t,e),this.viewport=this._project.viewport,this.fps=this._project.fps,this._catalog=new Yn(e.manifest),this._unsubscribe=e._onManifestChange(a=>{this._catalog.reconcile(a),this._storage.setCatalog(this._catalog),this._controller.reconcileCatalog()});let s={catalog:this._catalog,viewport:this.viewport,fps:this.fps};this._storage=e.platform.createStorageAdapter(s),this._renderContext=e.platform.createRenderContext(this._storage);let r=e.platform.createMeasureContext(this._storage),o=e.platform.createAudioSink(),i=e.platform.createTicker(this.fps,o);this.applyGlobals(),t.target!==void 0&&this._renderContext.mount(t.target),this._controller=new Gn({project:this._project,registry:e._registry,renderContext:this._renderContext,measurer:r,storageAdapter:this._storage,masterClock:i??new qn,audioDevice:o,assets:this._catalog,onPrecompProgress:t.onPrecompProgress}),this._playback=i===null?null:new Wn(this._controller)}get document(){return this._project}get playback(){return this._playback}get controller(){return this._controller}get surface(){return this._renderContext}get duration(){return this._controller.totalDuration}get totalFrames(){return this._controller.totalFrames}async seek(e){await this.seekFrame(Math.round(xe(e,this.fps)))}async seekFrame(e){this.applyGlobals(),await this._controller.seek(e)}replace(e){let t=xd(e,this._override,this);if(t.fps!==this.fps||t.viewport.width!==this.viewport.width||t.viewport.height!==this.viewport.height)throw new Error(`Cannot replace a ${this.viewport.width}\xD7${this.viewport.height} @ ${this.fps}fps document with a ${t.viewport.width}\xD7${t.viewport.height} @ ${t.fps}fps one \u2014 open a new session.`);this._project=t,this.applyGlobals(),this._controller.setProject(t)}image(e={}){return this.applyGlobals(),this.engine.exporter.exportStill({...e,frame:e.frame??{kind:"last"},project:this._project,registry:this.engine._registry,manifest:e.manifest??this.engine.manifest})}export(e={}){return this.applyGlobals(),this.engine.exporter.exportVideo({...e,project:this._project,registry:this.engine._registry,manifest:e.manifest??this.engine.manifest})}dispose(){this._unsubscribe(),this._controller.dispose(),this._renderContext.dispose()}applyGlobals(){ts(this._project.theme)}_override;_project;_catalog;_storage;_renderContext;_controller;_playback;_unsubscribe};function xd(n,e,t){let s=da(n),r=Hs(s),o=r.changes.length>0?r.document:s,i={...o,viewport:e.viewport??o.viewport??t.viewport,fps:e.fps??o.fps??t.fps};return Pa(i),i}function Kk(n,e={}){let t=e.delimiter??",",s=Wf(n,t);if(s.length===0)return[];let r=s[0].map(d=>d.trim()),i=s.slice(1).map(d=>{let u={};return r.forEach((l,f)=>{u[l]=d[f]??""}),u}),a=Gf(r,i,e.numeric),c=Yf(r,i,a,e.boolean);return a.length===0&&c.length===0?i:i.map(d=>{let u={...d};for(let l of a){let f=d[l];f!==""&&(u[l]=Number(f))}for(let l of c){let f=d[l];f!==""&&(u[l]=f==="true")}return u})}function Uk(n,e){throw new Error(`parseData("${n}") must be called with a static string literal so the @motionscript/vite-plugin macro can inline it at build time. If you're seeing this error at runtime, either the plugin isn't installed/registered, or this call's argument isn't a plain string literal.`)}function Gf(n,e,t){return t===!1?[]:Array.isArray(t)?t:n.filter(s=>{let r=!1;for(let o of e){let i=o[s];if(i!==""){if(!Number.isFinite(Number(i)))return!1;r=!0}}return r})}function Yf(n,e,t,s){if(s===!1)return[];if(Array.isArray(s))return s;let r=new Set(t);return n.filter(o=>{if(r.has(o))return!1;let i=!1;for(let a of e){let c=a[o];if(c!==""){if(c!=="true"&&c!=="false")return!1;i=!0}}return i})}function Wf(n,e){let t=[],s=[],r="",o=!1,i=!1,a=()=>{s.push(r),r=""},c=()=>{a(),t.push(s),s=[],i=!1};for(let d=0;d<n.length;d++){let u=n[d];if(o){u==='"'?n[d+1]==='"'?(r+='"',d++):o=!1:r+=u;continue}if(u==='"'){o=!0,i=!0;continue}if(u===e){i=!0,a();continue}if(u!=="\r"){if(u===`
12
- `){(i||r)&&c();continue}r+=u,i=!0}}return(i||r)&&c(),t}var Yk=(n,e)=>{let t=new Array(n);for(let s=0;s<n;s++)t[s]=e(s);return t};function Xk(){let n=null;function e(t){if(t!==void 0)n=t;else{if(n===null)throw new Error("Reference not assigned yet");return n}}return e}var Hn=class{state=0;constructor(e){this.setSeed(e)}setSeed(e){this.state=typeof e=="string"?e.split("").reduce((t,s)=>(t=(t<<5)-t+s.charCodeAt(0),t&t),0):e}next(){this.state|=0,this.state=this.state+1831565813|0;var e=Math.imul(this.state^this.state>>>15,1|this.state);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}},vd=4294967296,Ur=class n{_seed;numericSeed;gen;spareGauss=null;constructor(e){this.gen=new Hn(e),this.adopt(e)}get seed(){return this._seed}set seed(e){this.adopt(e)}static toNumeric(e){return typeof e=="string"?e.split("").reduce((t,s)=>(t<<5)-t+s.charCodeAt(0),0):e}adopt(e){this._seed=e,this.numericSeed=n.toNumeric(e),this.gen.setSeed(e),this.spareGauss=null}nextFloat(e=0,t=1){return this.gen.next()*(t-e)+e}nextInt(e=0,t=vd){return Math.floor(this.gen.next()*(t-e))+e}floatArray(e,t=0,s=1){let r=new Array(e);for(let o=0;o<e;o++)r[o]=this.nextFloat(t,s);return r}intArray(e,t=0,s=vd){let r=new Array(e);for(let o=0;o<e;o++)r[o]=this.nextInt(t,s);return r}gauss(e=0,t=1){if(this.spareGauss!==null){let a=this.spareGauss;return this.spareGauss=null,e+t*a}let s,r,o;do s=this.gen.next()*2-1,r=this.gen.next()*2-1,o=s*s+r*r;while(o>=1||o===0);let i=Math.sqrt(-2*Math.log(o)/o);return this.spareGauss=r*i,e+t*(s*i)}noise(e,t=1){let s=e*t,r=Math.floor(s),o=s-r,i=o*o*(3-2*o),a=this.latticeValue(r),c=this.latticeValue(r+1);return a+(c-a)*i}reset(e=this._seed){this.adopt(e)}latticeValue(e){let t=Math.sin(e+this.numericSeed)*1e4;return t-Math.floor(t)}};function iS(n){return typeof n?._stepper=="function"}export{Ve as a,Sd as b,Ad as c,Is as d,gt as e,Od as f,Lp as g,Ke as h,Ds as i,km as j,ii as k,ai as l,ci as m,ye as n,on as o,an as p,Ns as q,Ie as r,ui as s,li as t,fi as u,hi as v,pi as w,Sg as x,Ag as y,Mg as z,Og as A,Tg as B,Eg as C,Cg as D,mi as E,gi as F,wi as G,xi as H,vi as I,un as J,bi as K,ki as L,Si as M,Ai as N,Mi as O,Oi as P,Ti as Q,Ei as R,Ci as S,Us as T,Pi as U,Ii as V,Di as W,Fi as X,$i as Y,Ni as Z,Ri as _,zi as $,Li as aa,ji as ba,Bi as ca,Vi as da,Ki as ea,Ui as fa,Gi as ga,Yi as ha,Wi as ia,Xi as ja,qi as ka,Hi as la,Ji as ma,Py as na,Zi as oa,Qi as pa,ea as qa,ta as ra,na as sa,sa as ta,ra as ua,oa as va,ia as wa,aa as xa,Ue as ya,Ry as za,ln as Aa,Ud as Ba,b as Ca,U as Da,zy as Ea,ca as Fa,Ge as Ga,Ly as Ha,Gd as Ia,ue as Ja,Yd as Ka,da as La,Xs as Ma,kt as Na,ua as Oa,qs as Pa,Hs as Qa,Qs as Ra,lu as Sa,Pa as Ta,Zy as Ua,St as Va,_u as Wa,wu as Xa,hn as Ya,Au as Za,Mu as _a,Ou as $a,D_ as ab,mn as bb,Pu as cb,Fu as db,Ye as eb,bn as fb,Lw as gb,Vw as hb,Kw as ib,yr as jb,wr as kb,An as lb,_r as mb,bl as nb,kl as ob,Sl as pb,Al as qb,Ml as rb,Tl as sb,bc as tb,Dl as ub,Fl as vb,kr as wb,$l as xb,Nl as yb,Mn as zb,ae as Ab,Ot as Bb,le as Cb,kc as Db,Tt as Eb,Et as Fb,Ct as Gb,Sc as Hb,On as Ib,Sr as Jb,q as Kb,Xe as Lb,Tn as Mb,qe as Nb,En as Ob,Gl as Pb,Yl as Qb,Cn as Rb,Pn as Sb,we as Tb,In as Ub,Bv as Vb,Re as Wb,xe as Xb,Kv as Yb,He as Zb,Pt as _b,Oc as $b,Me as ac,se as bc,Je as cc,Dn as dc,jt as ec,Oe as fc,jn as gc,Fr as hc,Lc as ic,Bb as jc,Vn as kc,et as lc,Lr as mc,Wc as nc,Xc as oc,re as pc,ed as qc,td as rc,nd as sc,sd as tc,rd as uc,Kt as vc,ad as wc,Te as xc,dd as yc,ud as zc,Kr as Ac,md as Bc,dk as Cc,uk as Dc,Gn as Ec,Yn as Fc,Wn as Gc,Xn as Hc,qn as Ic,wd as Jc,xd as Kc,Kk as Lc,Uk as Mc,Yk as Nc,Xk as Oc,Hn as Pc,Ur as Qc,iS as Rc};
13
- //# sourceMappingURL=chunk-FPYU47XX.js.map