@motionscript/core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @motionscript/core
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b996da5: Versioned component-API paths. `@motionscript/sdk/v1`, `@motionscript/sdk/v1/component` and each kit's `@motionscript/<kit>/v1` are the v1 API, today exactly the bare paths. A custom component imports the `/v1` paths, so a later major, which ships a v1 shim in the same engine, keeps it linking against one core. A bare import means the latest API, for npm users who follow the newest release. Each kit's `./kit` stays unstable and unversioned.
8
+
9
+ A dynamic node's `require("@motionscript/sdk/v1")` resolves to the host's `sdk`, as `@motionscript/sdk` does, and the error for an unknown specifier now names `@motionscript/sdk/v1`. `@motionscript/sdk/v1/component` and the kit paths link through `dynamicNodes.modules`, like `@motionscript/sdk/component`.
10
+
11
+ ## 0.4.0-alpha.0
12
+
13
+ ### Minor Changes
14
+
15
+ - b996da5: Versioned component-API paths. `@motionscript/sdk/v1`, `@motionscript/sdk/v1/component` and each kit's `@motionscript/<kit>/v1` are the v1 API, today exactly the bare paths. A custom component imports the `/v1` paths, so a later major, which ships a v1 shim in the same engine, keeps it linking against one core. A bare import means the latest API, for npm users who follow the newest release. Each kit's `./kit` stays unstable and unversioned.
16
+
17
+ A dynamic node's `require("@motionscript/sdk/v1")` resolves to the host's `sdk`, as `@motionscript/sdk` does, and the error for an unknown specifier now names `@motionscript/sdk/v1`. `@motionscript/sdk/v1/component` and the kit paths link through `dynamicNodes.modules`, like `@motionscript/sdk/component`.
18
+
3
19
  ## 0.3.0
4
20
 
5
21
  ### Minor Changes
@@ -2,7 +2,7 @@ import{$b as Gt,$d as Po,Ac as gr,Ae as en,Bb as lr,Bc as ke,Be as Go,Cb as he,C
2
2
  `);throw new Error(`Invalid project document:
3
3
  ${s}`)}}function r_(n,e){let{valid:t,issues:r}=Qr(n,e);if(!t){let s=r.map(o=>` ${o.path||"<root>"}: ${o.message}`).join(`
4
4
  `);throw new Error(`Invalid clip document:
5
- ${s}`)}return n}var gu=T({key:"missingNode2d"}),yu=P({key:"missingNode3d"}),_u=mt({key:"missingNodeAudio"}),Ia={"2d":gu.node,"3d":yu.node,audio:_u.node},wu=new Set(["effects","blend","clip","shadow"]),xu=Object.fromEntries(Object.entries(Ia).map(([n,e])=>[n,new Set(dt(Object.create(e.prototype)).map(t=>t.key).filter(t=>!wu.has(t)))])),Da=new WeakMap,es=Symbol("missingNodeType");function Fa(n,e,t){let r=new Ia[n]({...ts(n,t),id:e.id,...e.key!==void 0&&{key:e.key}});return Da.set(r,{type:e.type,props:e.props}),r}function ts(n,e){let t=xu[n],r={};for(let[s,o]of Object.entries(e))t.has(s)&&(r[s]=o);return r}function St(n){return Da.get(n)}function vu(n){let e={};for(let t of n.nodeKeys()){let r={};for(let[s,o]of Object.entries(n.describe(t)?.properties??{}))r[s]={kind:o.kind,...o.default!==void 0&&{default:JSON.parse(JSON.stringify(o.default))}};e[t]={properties:r,commands:n.commandKeys(t)}}return{nodes:e,commands:n.commandKeys()}}function bu(n,e){let t=[];for(let r of n.commands)e.commands.includes(r)||t.push({name:r,what:"command removed"});for(let[r,s]of Object.entries(n.nodes)){let o=e.nodes[r];if(!o){t.push({name:r,what:"node type removed"});continue}for(let[i,{default:a}]of Object.entries(s.properties)){let c=o.properties[i];c?JSON.stringify(a)!==JSON.stringify(c.default)&&t.push({name:`${r}.${i}`,what:"default changed"}):t.push({name:`${r}.${i}`,what:"prop removed"})}for(let i of s.commands)o.commands.includes(i)||t.push({name:`${r}.${i}`,what:"command removed"})}return t}var ku={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:sa,"ambient-light3d":Zi,"directional-light3d":ea,"point-light3d":ta,"spot-light3d":na,"hemisphere-light3d":Qi,"area-light3d":ra,fog3d:oa,environment3d:ia};function fn(n,e){return(t,r,s,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:r[e],duration:s,easing:o})}}var Su={number:Ws,vector2:er,vector3:yr,color:((n,e,t)=>{let[r,s,o,i]=nr(ze(String(n)),ze(String(e)),t),a=c=>Math.round(Math.min(Math.max(c,0),1)*255);return`rgba(${a(r)}, ${a(s)}, ${a(o)}, ${Number(i.toFixed(4))})`}),step:((n,e,t)=>t>=1?e:n)};function $a(n){for(let[e,t]of Object.entries(ku))n.addNode(e,t);for(let[e,t]of Object.entries(Su))n.addLerp(e,t);n.addCommand("to",(e,t,r,s)=>e.to({data:{...t},duration:r,easing:s})),n.addCommand("set",(e,t)=>{let r=t;return Pe(0,()=>{e.set(r)})},{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,r,s)=>{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(r,l=>{u||(d=e.get(),u=!0),e.set(c(d,o,l))},s)}),n.addVariableCommand("variableSet",(e,t)=>Pe(0,()=>{e.set(t.value)})),n.addCommand("save",e=>Pe(0,()=>{e.save()}))}var ns=["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"],Au=new Set(["eval","arguments"]),Na=ns.filter(n=>Au.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 Mu=["@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,r]of Object.entries(e.nodes??{}))this.addNode(t,r);for(let[t,r]of Object.entries(e.lerps??{}))this.addLerp(t,r);for(let[t,r]of Object.entries(e.eases??{}))this.addEase(t,r);for(let[t,r]of Object.entries(e.shaders??{}))this.addShader(t,r)}addNode(e,t,r){let s=typeof t=="function",o=s?t:e,i=typeof o.node=="function"?o.node:o,a=s?r:t,c=s?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 gr(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 r=await this._dynamicNodes.compile(e),s=this._evalNodeModule(r);return this.addNode(s,t),s}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 r=this._nodes.get(e.type);if(!r)throw new Error(`Unknown node type "${e.type}" (node ${e.id}). This registry knows: ${this.nodeKeys().join(", ")||"nothing"}.`);let s=Ar(r.ctor),o=t??e.props;return new r.ctor({...s?Ao(s,o).props:o,id:e.id,...e.key!==void 0&&{key:e.key}})}addCommand(e,t,r){return this._claimed(e,t)?this:(this._commands.set(e,{key:e,scope:"node",factory:t,...r?.args?{args:this._describeArgs(r.args)}:{},binds:r?.binds,...r?.method?{method:r.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 s=this._nodes.get(e)?.commands.get(t);if(s)return(o,i,a,c)=>{let d=o[s.method];if(typeof d!="function")throw new Error(`Command "${t}" needs a "${s.method}" method on ${o.constructor.name}, which has none.`);let u={};for(let l of s.args)u[l.key]=i[l.key];return d.call(o,{data:u,duration:a,easing:c})}}takesCommand(e,t){let r=this._nodes.get(e);if(!r)return!1;if(r.commands.has(t))return!0;let s=this._commands.get(t);return s?.scope!=="node"?!1:s.method===void 0?!0:typeof r.ctor.prototype[s.method]=="function"}commandKeys(e){return[...e===void 0?this._commands.keys():this._nodes.get(e)?.commands.keys()??[]].sort()}addLerp(e,t){let r=this._lerps.get(e);if(r&&r!==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,r){let s=e??(typeof t=="number"?"number":"step"),o=this._lerps.get(s);if(!o)throw new Error(`Unknown variable lerp "${s}" (${r}). Registered: ${this.lerpKeys().join(", ")||"none"}.`);return o}addEase(e,t){let r=this._eases.get(e);if(r&&r!==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,r){let s=ci(t),o=this._shaders.get(e);if(o){if(o.scope===s.scope&&o.source===s.source&&o.name===s.name)return o;if(!r?.replace)throw new Error(`Shader "${e}" is already registered to a different pack ("${o.name}" vs "${s.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,s),s}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:r}=this._dynamicNodes,s=c=>{if(Mu.includes(c))return t;if(r&&Object.hasOwn(r,c))return r[c];let d=["@motionscript/sdk",...Object.keys(r??{})];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",...ns,`"use strict";
5
+ ${s}`)}return n}var gu=T({key:"missingNode2d"}),yu=P({key:"missingNode3d"}),_u=mt({key:"missingNodeAudio"}),Ia={"2d":gu.node,"3d":yu.node,audio:_u.node},wu=new Set(["effects","blend","clip","shadow"]),xu=Object.fromEntries(Object.entries(Ia).map(([n,e])=>[n,new Set(dt(Object.create(e.prototype)).map(t=>t.key).filter(t=>!wu.has(t)))])),Da=new WeakMap,es=Symbol("missingNodeType");function Fa(n,e,t){let r=new Ia[n]({...ts(n,t),id:e.id,...e.key!==void 0&&{key:e.key}});return Da.set(r,{type:e.type,props:e.props}),r}function ts(n,e){let t=xu[n],r={};for(let[s,o]of Object.entries(e))t.has(s)&&(r[s]=o);return r}function St(n){return Da.get(n)}function vu(n){let e={};for(let t of n.nodeKeys()){let r={};for(let[s,o]of Object.entries(n.describe(t)?.properties??{}))r[s]={kind:o.kind,...o.default!==void 0&&{default:JSON.parse(JSON.stringify(o.default))}};e[t]={properties:r,commands:n.commandKeys(t)}}return{nodes:e,commands:n.commandKeys()}}function bu(n,e){let t=[];for(let r of n.commands)e.commands.includes(r)||t.push({name:r,what:"command removed"});for(let[r,s]of Object.entries(n.nodes)){let o=e.nodes[r];if(!o){t.push({name:r,what:"node type removed"});continue}for(let[i,{default:a}]of Object.entries(s.properties)){let c=o.properties[i];c?JSON.stringify(a)!==JSON.stringify(c.default)&&t.push({name:`${r}.${i}`,what:"default changed"}):t.push({name:`${r}.${i}`,what:"prop removed"})}for(let i of s.commands)o.commands.includes(i)||t.push({name:`${r}.${i}`,what:"command removed"})}return t}var ku={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:sa,"ambient-light3d":Zi,"directional-light3d":ea,"point-light3d":ta,"spot-light3d":na,"hemisphere-light3d":Qi,"area-light3d":ra,fog3d:oa,environment3d:ia};function fn(n,e){return(t,r,s,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:r[e],duration:s,easing:o})}}var Su={number:Ws,vector2:er,vector3:yr,color:((n,e,t)=>{let[r,s,o,i]=nr(ze(String(n)),ze(String(e)),t),a=c=>Math.round(Math.min(Math.max(c,0),1)*255);return`rgba(${a(r)}, ${a(s)}, ${a(o)}, ${Number(i.toFixed(4))})`}),step:((n,e,t)=>t>=1?e:n)};function $a(n){for(let[e,t]of Object.entries(ku))n.addNode(e,t);for(let[e,t]of Object.entries(Su))n.addLerp(e,t);n.addCommand("to",(e,t,r,s)=>e.to({data:{...t},duration:r,easing:s})),n.addCommand("set",(e,t)=>{let r=t;return Pe(0,()=>{e.set(r)})},{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,r,s)=>{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(r,l=>{u||(d=e.get(),u=!0),e.set(c(d,o,l))},s)}),n.addVariableCommand("variableSet",(e,t)=>Pe(0,()=>{e.set(t.value)})),n.addCommand("save",e=>Pe(0,()=>{e.save()}))}var ns=["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"],Au=new Set(["eval","arguments"]),Na=ns.filter(n=>Au.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 Mu=["@motionscript/sdk/v1","@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,r]of Object.entries(e.nodes??{}))this.addNode(t,r);for(let[t,r]of Object.entries(e.lerps??{}))this.addLerp(t,r);for(let[t,r]of Object.entries(e.eases??{}))this.addEase(t,r);for(let[t,r]of Object.entries(e.shaders??{}))this.addShader(t,r)}addNode(e,t,r){let s=typeof t=="function",o=s?t:e,i=typeof o.node=="function"?o.node:o,a=s?r:t,c=s?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 gr(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 r=await this._dynamicNodes.compile(e),s=this._evalNodeModule(r);return this.addNode(s,t),s}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 r=this._nodes.get(e.type);if(!r)throw new Error(`Unknown node type "${e.type}" (node ${e.id}). This registry knows: ${this.nodeKeys().join(", ")||"nothing"}.`);let s=Ar(r.ctor),o=t??e.props;return new r.ctor({...s?Ao(s,o).props:o,id:e.id,...e.key!==void 0&&{key:e.key}})}addCommand(e,t,r){return this._claimed(e,t)?this:(this._commands.set(e,{key:e,scope:"node",factory:t,...r?.args?{args:this._describeArgs(r.args)}:{},binds:r?.binds,...r?.method?{method:r.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 s=this._nodes.get(e)?.commands.get(t);if(s)return(o,i,a,c)=>{let d=o[s.method];if(typeof d!="function")throw new Error(`Command "${t}" needs a "${s.method}" method on ${o.constructor.name}, which has none.`);let u={};for(let l of s.args)u[l.key]=i[l.key];return d.call(o,{data:u,duration:a,easing:c})}}takesCommand(e,t){let r=this._nodes.get(e);if(!r)return!1;if(r.commands.has(t))return!0;let s=this._commands.get(t);return s?.scope!=="node"?!1:s.method===void 0?!0:typeof r.ctor.prototype[s.method]=="function"}commandKeys(e){return[...e===void 0?this._commands.keys():this._nodes.get(e)?.commands.keys()??[]].sort()}addLerp(e,t){let r=this._lerps.get(e);if(r&&r!==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,r){let s=e??(typeof t=="number"?"number":"step"),o=this._lerps.get(s);if(!o)throw new Error(`Unknown variable lerp "${s}" (${r}). Registered: ${this.lerpKeys().join(", ")||"none"}.`);return o}addEase(e,t){let r=this._eases.get(e);if(r&&r!==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,r){let s=ci(t),o=this._shaders.get(e);if(o){if(o.scope===s.scope&&o.source===s.source&&o.name===s.name)return o;if(!r?.replace)throw new Error(`Shader "${e}" is already registered to a different pack ("${o.name}" vs "${s.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,s),s}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:r}=this._dynamicNodes,s=c=>{if(Mu.includes(c))return t;if(r&&Object.hasOwn(r,c))return r[c];let d=["@motionscript/sdk/v1",...Object.keys(r??{})];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",...ns,`"use strict";
6
6
  return function () {
7
7
  ${e}
8
8
  };`)(o.exports,s,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 r=this._commands.get(e);if(!r)return!1;if(r.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 r of dt(Object.create(e.prototype))){let s=r.editor??{};t[r.key]={...s,kind:s.kind??this._inferKind(r.default),...r.default!==void 0?{default:r.default}:{}}}return t}_describeEvolution(e,t){let r=Ar(e);if(!r)return t;let s={...t.properties};for(let[i,a]of Object.entries(r.deprecated))s[i]&&(s[i]={...s[i],deprecated:a});let o=Object.keys(r.renamed).length>0?{renamed:{...r.renamed}}:{};return{...t,...o,properties:s}}_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 Ou="canvas3d";function Tu(n,e,t){let r=new Set;for(let s=e;s!==void 0&&!r.has(s);s=n.describe(s)?.parentKey){if(s===t)return!0;r.add(s)}return!1}function pn(n,e,t,r){return t.some(s=>Tu(n,e,s)||r.isA?.(e,s)===!0)}function Eu(n,e,t,r={}){let s=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=s?.within??[];if(i.length>0&&(t===null||!pn(n,t,i,r)))return{kind:"within",within:i};if(t!==null&&o?.closed===!0&&!pn(n,t,i,r))return{kind:"closed",parent:t};let a=t!==null&&(o?.dimension==="3d"||o?.holds?.includes("3d")===!0||pn(n,t,[Ou],r));return s?.dimension==="3d"!==a?{kind:"dimension",parent:t}:null}function Cu(n,e,t,r={}){let s=n.describe(e)?.beside??[];return s.length===0||t.some(o=>pn(n,o,s,r))?null:{kind:"beside",beside:s}}function z_(n,e,t={}){let r=a=>a.parentId===b?null:a.parentId,s=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(r(a));c?c.push(a.type):o.set(r(a),[a.type])}let i=new Map;for(let a of e){if(a.id===b||!n.hasNode(a.type))continue;let c=r(a),d=c===null?null:s.get(c)?.type??null,u=Eu(n,a.type,d,t)??Cu(n,a.type,Pu(o.get(c)??[],a.type),t);u&&i.set(a.id,u)}return i}function Pu(n,e){let t=n.indexOf(e);return t===-1?[...n]:[...n.slice(0,t),...n.slice(t+1)]}var mn="@bus";function Iu(){return{id:mn,type:"audioBus",parentId:null,layerOrder:0,props:{}}}function Du(){return{id:"",type:"canvas2d",parentId:null,layerOrder:0,props:{}}}function Fu(n){let e=[Du()];n.nodes.some(Ra)||e.push(Iu());for(let t of n.nodes)e.push($u(t));return{kind:"composition",duration:n.duration,variables:n.variables,nodes:e,commands:n.commands.map(Nu)}}function Ra(n){return n.id===""&&n.type==="audioBus"}function $u(n){return Ra(n)?{...n,id:mn,parentId:null}:n.parentId===null||n.parentId===""?{...n,parentId:mn}:n}function Nu(n){return n.targetId===null||n.targetId===""?{...n,targetId:mn}:n}function Ru(n){let e=new Set(n.commands.filter(r=>r.type==="play").map(r=>r.targetId)),t=[];for(let r of n.nodes){if(r.type!=="sound"&&r.type!=="video"||e.has(r.id))continue;let{start:s,end:o}=U(r),i=r.type==="video"?r.props.segments:void 0;if(Array.isArray(i)&&i.length>0){i.forEach((a,c)=>{t.push({id:`@play:${r.id}:${c}`,type:"play",targetId:r.id,at:s+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:${r.id}`,type:"play",targetId:r.id,at:s,duration:Number.isFinite(o)?o-s:0,args:{}})}return t.length===0?n:{...n,commands:[...n.commands,...t]}}function Ye(n){let e=ln(n)?Fu(n):n;return Ue(e)?e:Ru(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 r=zu.has(e.type),s=n.command(e.type);if(s?.scope==="variable"){let f=Lu.has(e.type);return{scope:"variable",known:f,lifecycle:r,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(s){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=!r&&a!==void 0&&Ju(i.ctor,a);if(!c)return{scope:"node",known:c,lifecycle:r,readsLayout:!0,writesLayout:!0};let d=e.args??{},u=o.props??{},l=qu(e.type,d);return{scope:"node",known:c,lifecycle:r,readsLayout:Xu(e.type,d,u,l),writesLayout:l===void 0||l.some(f=>!is(n,o.type,f))}}function ss(n,e){return n!==null&&n.known&&!n.lifecycle&&ju.has(e.type)&&I.collect(e.args??{},"").length===0}function Ka(n,e,t){let r=n.command(e.type),s=t??(e.targetId===null?Ya:void 0),o=r?r.scope==="node"?r.args:void 0:s?n.node(s.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 os(n){for(let e of I.collect(n,"")){let t=I.tryParse(e.source);if("error"in t||t.expression.refs.some(r=>r.includes(".")))return!0}return!1}function is(n,e,t){let r=n.node(e);return r?r.descriptor.dimension==="audio"||Ua(n,e,t)?!0:qa().ctors.has(r.ctor)&&Bu.has(t):!1}function Ua(n,e,t){let r=n.node(e)?.descriptor.dimension;return r==="3d"?Ku.has(t):r==="2d"&&Vu.has(t)}function Ga(n,e,t){let s=n.node(e.type)?.descriptor.dimension==="3d"?Gu:Uu;return Ua(n,e.type,t)&&!Object.keys(e.props).some(o=>s.has(o))}var zu=new Set(["removeChildAt","addChildAt","reparent"]),Lu=new Set(["variableTo","variableSet"]),ju=new Set(["to","set","moveTo","fadeTo","rotateTo","scaleTo","layoutTo","effectTo","pulse","wiggle","fillTo","strokeTo","shadowTo","overlayTo","progressTo","zoomTo","panTo","headingTo","variableTo","variableSet"]),Bu=new Set(["x","y","rotation","scale","opacity","fill","stroke","shadow","overlay","effects","blend","transformOrigin","zoom","lookAt","heading"]),Vu=new Set(["x","y","rotation","scale","opacity"]),Ku=new Set(["x","y","z","rotationX","rotationY","rotationZ","scaleX","scaleY","scaleZ"]),Uu=new Set(["center","topLeft","topRight","bottomLeft","bottomRight","topCenter","bottomCenter","centerLeft","centerRight"]),Gu=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"]},Yu={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:[]},Wu=new Set(Object.keys(Xa).filter(n=>n!=="set"&&n!=="save"));function Xu(n,e,t,r){if(La(e)||n==="moveTo"&&typeof e.target=="string"&&e.target!=="")return!0;let s=La(t),o=Hu(t);return n==="save"||n==="restore"?s||o.size>0:Wu.has(n)?(n==="append"||n==="prepend"?["text"]:n==="countTo"?["value"]:r??[]).some(a=>o.has(a)||s&&(a==="x"||a==="y")):!1}function qu(n,e){let t=Yu[n];if(t)return t;if(n!=="to"&&n!=="set")return;let r=[];for(let s of Object.keys(e))s==="size"?r.push("width","height"):n==="to"&&s==="pivot"?r.push("transformOrigin"):n==="to"&&Va.includes(s)?r.push("x","y","transformOrigin"):r.push(s);return r}function La(n){return Va.some(e=>n[e]!==void 0)}var ja=new WeakMap;function Hu(n){let e=ja.get(n);if(!e){let t=new Set;for(let r of Object.keys(n))os(n[r])&&t.add(r);ja.set(n,e=t)}return e}function gn(n,e){return n.prototype[e]}var Ba=new WeakMap;function Ju(n,e){let t=Ba.get(n);t||Ba.set(n,t=new Map);let r=t.get(e);return r===void 0&&(r=e.every(s=>{let o=gn(n,s);return o===void 0||Zu(s).has(o)}),t.set(e,r)),r}var rs=null;function qa(){if(!rs){let n=new hn;rs={ctors:new Set(n.nodeKeys().map(e=>n.node(e).ctor)),methods:new Map}}return rs}function Zu(n){let e=qa(),t=e.methods.get(n);if(!t){let r=new Set;for(let s of e.ctors)for(let o=s.prototype;o&&o!==Object.prototype;o=Object.getPrototypeOf(o)){let i=Object.getOwnPropertyDescriptor(o,n);i&&typeof i.value=="function"&&r.add(i.value)}e.methods.set(n,t=r)}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,r=e,s=0;for(let o of Object.keys(t)){let i=t[o];if(i!==void 0&&(s++,!N(i,r[o])))return!1}for(let o of Object.keys(r))r[o]!==void 0&&s--;return s===0}function Qu(){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=Qu();if(n===e)return t;if(n.kind!==e.kind)return t.kindChanged=!0,t.identical=!1,t;let r=Ha(n),s=Ha(e);t.themeChanged=!N(n.theme,e.theme),t.duration=ue(r)!==ue(s),n.nodes!==e.nodes&&el(r.nodes,s.nodes,t),n.variables!==e.variables&&rl(r.variables??[],s.variables??[],t);let o=r.kind==="composition"?r.commands:[],i=s.kind==="composition"?s.commands:[];return n.commands!==e.commands&&nl(o,i,t),t.identical=!t.themeChanged&&!t.rootChanged&&!t.duration&&t.remappedKeys.size===0&&as(t.nodes)&&t.nodes.reorderedParents.size===0&&as(t.commands)&&t.commands.reorderedAts.size===0&&as(t.variables),t}function Ha(n){return Ye(n)}function as(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 el(n,e,t){let r=We(n),s=We(e),o=t.nodes,i=r.get(b)??Ja,a=s.get(b)??Ja;t.rootChanged=i!==a&&!tl(i,a);for(let[l,f]of r){if(l===b)continue;let h=s.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 s.keys())l!==b&&!r.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 tl(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),r=U(e);return t.start===r.start&&t.end===r.end}function nl(n,e,t){let r=We(n),s=We(e),o=t.commands;for(let[c,d]of r){let u=s.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 s.keys())r.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 rl(n,e,t){let r=We(n),s=We(e),o=t.variables;for(let[i,a]of r){let c=s.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 s.keys())r.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((r,s)=>{if(r.id===b)return;let o=r.parentId??b,i=e.get(o);i||e.set(o,i=[]),i.push({id:r.id,order:r.layerOrder,index:s})});let t=new Map;for(let[r,s]of e)s.sort((o,i)=>o.order-i.order||o.index-i.index),t.set(r,s.map(o=>o.id));return t}function ec(n){let e=new Map;for(let t of n){let r=e.get(t.at);r||e.set(t.at,r=[]),r.push(t.id)}return e}function nc(n,e){let t=new Set(e),r=new Set(n),s=n.filter(i=>t.has(i)),o=e.filter(i=>r.has(i));if(s.length!==o.length)return!1;for(let i=0;i<s.length;i++)if(s[i]!==o[i])return!1;return!0}function sl(n){let e=n.indexOf(".");return e<0?void 0:{key:n.slice(0,e),prop:n.slice(e+1)}}function cs(n,e=""){let t=[],r=[],s=0,o=new Set;for(let i of I.collect(n,e)){let a=I.tryParse(i.source);if("error"in a){s++;continue}for(let c of a.expression.refs){if(o.has(c))continue;o.add(c);let d=sl(c);d?r.push([d.key,d.prop]):t.push(c)}}return{vars:t,keys:r,unparsable:s}}function us(n){return new ds(Ye(n))}var ol=Object.freeze({vars:[],keys:[],unparsable:0}),il=new Map,rc=[];function wn(n,e){return n!==void 0&&e>=n.start&&e<n.end}var ds=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 r of e.variables??[])(this.variables.has(r.id)||this.nodes.has(r.id))&&(this.issues.duplicateIds=!0),this.variables.set(r.id,r);this.ordered=t.map((r,s)=>({spec:r,index:s})).sort((r,s)=>r.spec.at-s.spec.at||r.index-s.index).map(r=>r.spec);for(let r of this.ordered){this.commands.has(r.id)&&(this.issues.duplicateIds=!0),this.commands.set(r.id,r);let s=this.targetOf(r),o=this.byTarget.get(s);o||this.byTarget.set(s,o=[]),o.push(r.id);let i=this._byAt.get(r.at);i||this._byAt.set(r.at,i=[]),i.push(r)}this._ats=[...this._byAt.keys()],this._indexRefs(t)}children(e){return this._children.get(e)??rc}descendants(e){let t=[],r=new Set([e]),s=[...this.children(e)].reverse();for(;s.length>0;){let o=s.pop();if(r.has(o))continue;r.add(o),t.push(o);let i=this.children(o);for(let a=i.length-1;a>=0;a--)s.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 r=[],s=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(s.has(i.id)||(s.add(i.id),r.push(i),i.id===b||i.parentId===null))break;i=this.nodes.get(i.parentId)}for(let a=r.length-1;a>=0;a--){let c=U(r[a]);o={start:Math.max(o.start,c.start),end:Math.min(o.end,c.end)},this._eff.set(r[a].id,o)}return this._eff.get(e)}targetOf(e){return e.targetId??b}commandsAt(e){return this._byAt.get(e)??rc}bindings(e){return this._bindings.get(e)??il}refs(e){return this._refs.get(e)??ol}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 r=0,s=this._ats.length;for(;r<s;){let i=r+s>>1;this._ats[i]<t.start?r=i+1:s=i}let o=this._ats[r];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((s,o)=>{if(this.nodes.has(s.id)&&(this.issues.duplicateIds=!0),this.nodes.set(s.id,s),s.key&&(this.keyed.has(s.key)&&(this.issues.duplicateKeys=!0),this.keyed.set(s.key,s.id)),s.id===b){(s.type!=="canvas2d"||s.parentId!==null)&&(this.issues.invalidRoot=!0);return}let i=s.parentId??b,a=t.get(i);a||t.set(i,a=[]),a.push({id:s.id,order:s.layerOrder,index:o})}),this.nodes.has(b)||this.nodes.set(b,{id:b,type:"canvas2d",parentId:null,layerOrder:0,props:{}});for(let[s,o]of t)o.sort((i,a)=>i.order-a.order||i.index-a.index),this._children.set(s,o.map(i=>i.id));let r=new Set([b]);for(let s of this.nodes.values()){s.parentId!==null&&!this.nodes.has(s.parentId)&&(this.issues.unresolvedParent=!0);let o=new Set,i=s;for(;i&&!r.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)r.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 r=this.targetOf(t);if(this.nodes.has(r)){this._bind(r,t.args);continue}}cs(t.args).unparsable>0&&(this.issues.unparsable=!0)}for(let[t,r]of this._bindings){let s=new Set,o=new Map,i=0;for(let a of r.values()){for(let c of a.vars)s.add(c);for(let c of a.keys)o.set(`${c[0]}.${c[1]}`,c);i+=a.unparsable}this._refs.set(t,{vars:[...s],keys:[...o.values()],unparsable:i});for(let a of s){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 r of Object.keys(t)){let s=cs(t[r]);if(s.unparsable>0&&(this.issues.unparsable=!0),s.vars.length===0&&s.keys.length===0)continue;let o=this._bindings.get(e);o||this._bindings.set(e,o=new Map);let i=o.get(r);if(!i){o.set(r,s);continue}let a=new Set([...i.vars,...s.vars]),c=new Map([...i.keys,...s.keys].map(d=>[`${d[0]}.${d[1]}`,d]));o.set(r,{vars:[...a],keys:[...c.values()],unparsable:i.unparsable+s.unparsable})}}};var vn=class n{_finish;_tracks;_replayed;static build(e){let t=new Float64Array(e.length).fill(NaN),r=new Map,s=[],o=[],i=new Set;for(let a=0;a<e.length;a++){let c=e[a],d=Yt(c.command),u=d&&!al(c.writes,i)?ul(c.start,c.duration):NaN;if(Number.isNaN(u)){if(!d&&c.reads)for(let f of c.reads)i.add(f);s.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=r.get(f),p={order:a,finish:u,end:f.snapshot()};h?h.push(p):r.set(f,[p])}}return s.length===e.length?null:new n(e,t,[...r].map(([a,c])=>new ls(a,c)),s,o)}holds(e){return!Number.isNaN(this._finish[e])}evaluate(e,t){let r=this._tracks,s=this._held;for(let f=0;f<r.length;f++){let h=s[f]=r[f].at(t);h>=0&&r[f].slot.restoreFrom(r[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=s[_];v>=0&&r[_].order[v]>g&&r[_].slot.restoreFrom(r[_].ends[v])}}}}constructor(e,t,r,s,o){this._finish=t,this._tracks=r,this._replayed=s,this._held=new Int32Array(r.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(cl,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>dl)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(r.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 al(n,e){if(e.size===0)return!1;for(let t of n)if(e.has(t))return!0;return!1}var xn=2147483647,cl=1024,dl=32,ls=class{slot;finish;order;ends;_best;constructor(e,t){this.slot=e,t.sort((s,o)=>s.finish-o.finish||s.order-o.order),this.finish=Float64Array.from(t,s=>s.finish),this.order=Int32Array.from(t,s=>s.order),this.ends=t.map(s=>s.end),this._best=new Int32Array(t.length);let r=0;for(let s=0;s<t.length;s++)this.order[s]>this.order[r]&&(r=s),this._best[s]=r}at(e){let t=0,r=this.finish.length;for(;t<r;){let s=t+r>>>1;this.finish[s]<=e?t=s+1:r=s}return t===0?-1:this._best[t-1]}};function ul(n,e){if(!(e>0))return n;let t=s=>(s-n)/e>=1,r=n+e;if(!Number.isFinite(r))return NaN;for(let s=0;!t(r);s++){if(s===8)return NaN;r=sc(r,!0)}for(let s=0;s<8;s++){let o=sc(r,!1);if(!t(o))return r;r=o}return NaN}var fs=new Float64Array(1),ll=new BigInt64Array(fs.buffer);function sc(n,e){return n===0?e?Number.MIN_VALUE:-Number.MIN_VALUE:(fs[0]=n,ll[0]+=n>0===e?1n:-1n,fs[0])}var fl=16;function lc(n,e,t,r,s={}){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&&!hl(o,i)||e.issues.unparsable||e.issues.unresolvedRefs||t.remappedKeys.size>0)return null;let a=ic(n,r),c=a&&ic(e,r);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||r.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&&r.isContextProvider(S)||C!==void 0&&r.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)pl(n,e,y,r)?V.add(y):H(y);for(let y of f)if(H(y),dc(n,y,r)||dc(e,y,r))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=r.ctorOf(y);S!==void 0&&r.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()]))yl(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)gl(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),r))||t.rootChanged&&uc(o,i,r),te=new Set([...d,...u,...nt,...V]);t.rootChanged&&te.add(b);let Ad=[...ac(n,r),...ac(e,r)],Gs=(y,S)=>{let C=e.nodes.get(y)?.type;if(C===void 0||r.dimensionOf?.(C)==="audio")return!1;for(let[W,G]of e.bindings(y))if(S(G)&&!r.isLayoutNeutralProp(C,W))return!0;return!1},Ys=-1;for(;Ys!==D.size+J.size+M.size+te.size+(ce?1:0);){Ys=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&&Gs(S,C=>C.vars.includes(y))&&(ce=!0);for(let y of te)for(let S of ml(n,e,y))for(let C of e.dependents.byKey.get(S)??[])te.add(C),!ce&&Gs(C,W=>W.keys.some(([G])=>G===S))&&(ce=!0);for(let{reader:y,ref:S}of Ad)(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 Md=Math.max((s.rebuildFraction??.5)*e.nodeCount,s.minRebuildNodes??fl);if(M.size>Md)return null;for(let y of M)V.delete(y);let rt;if([...D,...J].some(y=>m(e,c,y,S=>S.readsLayout||!S.known)))rt="all";else{rt=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)&&rt.add(W);for(let[W]of C.keys){let G=e.keyed.get(W);G!==void 0&&(!D.has(G)&&g(G)&&rt.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:rt,captures:Zn,layoutChanged:ce}}function oc(n){let{duplicateIds:e,duplicateKeys:t,unresolvedParent:r,cycle:s,invalidRoot:o}=n.issues;return e||t||r||s||o}function ic(n,e){let t=new Map;for(let r of n.ordered){let s=n.targetOf(r),o=n.nodes.get(s),i=e.traits(r,o);if(!i||i.lifecycle||(i.scope==="variable"?!n.variables.has(s):!o))return null;t.set(r.id,i)}return t}function ac(n,e){if(!e.nodeRefs)return[];let t=[];for(let r of n.ordered){let s=n.targetOf(r);for(let o of e.nodeRefs(r,n.nodes.get(s)))t.push({reader:s,ref:o})}return t}function cc(n,e,t){let r=new Set,s=e;for(;s!==void 0&&!r.has(s);){if(t.has(s))return!0;r.add(s);let o=n.nodes.get(s);if(!o||s===b)return!1;s=o.parentId??b}return!1}function dc(n,e,t){let r=new Set([e]),s=n.nodes.get(e);for(;s&&s.id!==b;){let o=s.parentId??b;if(r.has(o))return!1;if(r.add(o),s=n.nodes.get(o),s&&t.isContextProvider(s.type))return!0}return!1}function hl(n,e){let t=U(n),r=U(e);return n.type===e.type&&n.key===e.key&&n.parentId===e.parentId&&n.layerOrder===e.layerOrder&&t.start===r.start&&t.end===r.end}function pl(n,e,t,r){let s=n.nodes.get(t),o=e.nodes.get(t);if(!r.writesInPlace||s.type!==o.type||s.key!==o.key)return!1;let i=n.bindings(t),a=e.bindings(t);for(let c of new Set([...Object.keys(s.props),...Object.keys(o.props)]))if(!N(s.props[c],o.props[c])&&(o.props[c]===void 0||i.has(c)||a.has(c)||!r.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 r of new Set([...Object.keys(n.props),...Object.keys(e.props)]))if(!N(n.props[r],e.props[r])&&!t.isLayoutNeutralProp(e.type,r))return!0;return!1}function ml(n,e,t){let r=[],s=n.nodes.get(t)?.key,o=e.nodes.get(t)?.key;return s&&r.push(s),o&&o!==s&&r.push(o),r}function gl(n,e){return n?.start===e?.start&&n?.end===e?.end}function yl(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 _l(n,e){if(n)return it(n,t=>e.ease(t),()=>e.easeKeys())}function wl(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 xl=new Set;function fc(n,e,t){if(Yt(n))return xl;for(let r of t)e.reads.add(r);return e.reads}function hc(n,e){return n&&e?co(e):e}function vl(){return{id:b,type:"canvas2d",parentId:null,layerOrder:0,props:{}}}function pc(n){let e=[],t;for(let r of n){if(r.id===b&&r.type==="canvas2d"){t=r;continue}e.push(r)}return{root:t??vl(),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,r){this.canvas=r,this._doc=e,this._registry=t;let{root:s,rest:o}=pc(e.nodes);this._rootSpec=s,this._specs=o,this._varSpecs=e.variables??[],this._keyed=new Map([s,...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=mr(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 r=Mo(t.command);if(r)for(let s of r.sounds)e.push({node:r.host,at:t.start+s.at,until:s.until===void 0?void 0:t.start+s.until,src:s.src,options:s.options})}return e}placedCommands(){return this._placed}issues(){let e=[];for(let{spec:t,node:r}of this._live.values()){let s=St(r);s&&e.push({code:"unknown-node-type",nodeId:t.id,type:s.type,message:`Unknown node type "${s.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:r,baseline:s}of this._slotRestore)r.restoreFrom(s);this._settled.evaluate(this._placed,e);return}this._restoreBaselines();for(let r of this._placed){if(e<r.holdFrom)continue;let s=e<r.start?0:r.duration>0?(e-r.start)/r.duration:1;r.command.at(ot(s))}}syncPresence(e){let t=this._presenceIndex().crossed(e);if(t.length===0)return!1;let r=[],s=[];for(let i of t){let a=kn(i,e);a!==this._present.has(i.id)&&(a?r:s).push(i)}if(this._arrived=r,r.length===0&&s.length===0)return!1;s.sort(wc);for(let i of s){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))}r.sort(wc);let o=new Map;for(let i of r){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 r=t.baseline===Ae?t.initial:t.baseline,s={};for(let[o,i]of r)s[o]=i.fn?i.fn():i.value;return s}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??=us(this._doc);return lc(t,us(e),_n(this._doc,e),this._patchEnvironment())}applyUpdate(e,t,r){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 s=this._updateStructure(e);for(let l of s){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&&!s.has(f)&&_c(f)}r();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 r=this._keyed.get(e.slice(0,t));if(r===void 0)return;let s=e.slice(t+1);return()=>this._nodeById(r)?.[s]}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 r=0;t&&r<=this._live.size;r++)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 r=Zt(this._registry,e.type,e.props).props,{literal:s,bindings:o,hasBindings:i}=I.bindProps(r,this._resolveVariable);if(!this._registry.strict&&!this._registry.hasNode(e.type)){let c=this._placeholderDimension(e,t),d=Fa(c,e,s),u=ts(c,o);return Object.keys(u).length>0&&d.set(u),d}let a=this._registry.instantiate(e,s);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 r=this._registry.requireLerp(e.lerp,e.value,`variable "${e.id}"`);return{id:e.id,get:()=>t.get(),set:s=>t.set(s),lerp:r}}_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 r=t.node;Wt(r,t.baseline),r._stateStack.length>t.baseStackDepth&&(r._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,r=wl(this._doc.commands),s=this._refBound(r),o=this._settleWindows(r,i=>this._readsLayout(r[i],s));for(let i=0;i<r.length;i++){let a=r[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,r=new Map;this._placed.forEach((s,o)=>{let i=e.holds(o);i||t.add(s.owner);for(let a of s.writes){let c=a._host,d=c===null?void 0:c.id===b?this._root:this._live.get(c.id);d&&(i?r.has(d)?r.get(d).add(a):r.set(d,new Set([a])):t.add(d))}}),this._wholeRestore=[],this._slotRestore=[];for(let s of this._animated){let o=t.has(s)?null:kl(s,r.get(s));o?this._slotRestore.push(...o):this._wholeRestore.push(s)}}_collectDisplaced(){let e=[];for(let t of this._present){let r=this._live.get(t),s=r&&this._declaredParent(t);r&&s&&r.node.parent!==s&&e.push(r)}return e.sort((t,r)=>this._presenceIndex().row(t.spec.id).slot-this._presenceIndex().row(r.spec.id).slot),this._displaced=e}_restoreDisplaced(e){let t=!1;for(let r of e){let s=r.spec.id,o=this._presenceIndex().row(s),i=this._declaredParent(s);if(!o||!i||!this._present.has(s)||r.node.parent===i)continue;r.node.parent?.remove(r.node);let a=this._baseChildCount.get(o.siblings.parentId)??0;i.addChildAt({data:{child:r.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&&ps(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&&(ps(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 r=e.duration??0,s=_l(e.easing,this._registry),o=new hs(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=ss(At(this._registry,e,void 0),e),_=pe(o,()=>yc(()=>a(hc(x,m(g.target,e.args,r,s)))));return{spec:e,start:e.at,holdFrom:e.at,entrance:!1,duration:i?_.duration:r,command:_,writes:o.writes,reads:fc(_,o,[g.cell]),readsLayout:o.readsLayout,owner:g}}let c=this._targetOrThrow(e),d=bl.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=ss(At(this._registry,e,c.entry.spec),e),h=pe(o,()=>yc(()=>a(hc(f,l(c.node,u,r,s))))),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:r,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 r of this._placed){if(r.holdFrom=r.start,r.entrance){let o=r.owner.spec.id;t??=new Map(this._specs.map(a=>[a.id,a]));let i=o===b?0:Ge(t,o)?.start??r.start;for(let a of r.writes)i=Math.max(i,e.get(a)??-1/0);i<r.start&&(r.holdFrom=Math.max(0,i))}let s=r.start+r.duration;for(let o of r.writes)s<=(e.get(o)??-1/0)||e.set(o,s)}}_unlimitedFill(e){return Math.max(0,this._duration-e)}_touch(e,t){this._touchOwner(e.owner,t);for(let r of e.writes){let s=r._host;if(s===null)continue;let o=s.id===b?this._root:this._live.get(s.id);o?this._touchOwner(o,t):this._partBaselines.has(r)&&!t.has(r)&&(t.add(r),this._animatedParts.push(r))}}_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:r}=I.bindProps(e,this._resolveVariable,"args");return{...t,...r}}_assertNoExpressions(e){let t=I.collect(e.args,"args");if(t.length===0)return;let{path:r,source:s}=t[0];throw new Error(`Command ${e.id} ("${e.type}") carries an expression at ${r}: ${JSON.stringify(s)}. 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,r){return this._skipped.set(e.id,{code:"unknown-command",commandId:e.id,...e.targetId!==null&&{nodeId:e.targetId},type:r,message:t}),null}_placeholderDimension(e,t){let r=new Map(t.map(i=>[i.id,i])),s=new Set,o=i=>{s.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:r.get(i.parentId);if(!a)return"2d";let c=this._registry.describe(a.type);if(!c)return s.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 r=0;pe({read:()=>{},write:o=>t(r,o)},()=>{for(;r<this._placed.length;r++){let o=this._placed[r];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 r=this._presenceIndex(),s=new Uint8Array(e.length),o=-1,i=r.time;for(let a=0;a<e.length;a++){let{at:c}=e[a];r.differs(i,c)&&(o=a),i=c,!(o<0||s[o])&&t(a)&&(s[o]=1)}return s}_readsLayout(e,t){let r=e.targetId??b,s=e.targetId===null?this._rootSpec:this._live.get(e.targetId)?.spec,o=At(this._registry,e,s);return o===null||o.readsLayout||t.has(r)}_refBound(e){let t=new Set;for(let r of e){let s=this._registry.command(r.type);s?.scope==="node"&&s.binds&&os(r.args)&&t.add(r.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,r)=>At(e,t,r),nodeRefs:(t,r)=>Ka(e,t,r),isContextProvider:t=>yn(e,t),isLayoutNeutralProp:(t,r)=>is(e,t,r),writesInPlace:(t,r)=>Ga(e,t,r),ctorOf:t=>{let r=this._live.get(t)?.node;return r&&St(r)?es:r?.constructor},registeredCtor:t=>e.node(t)?.ctor??(e.strict?void 0:es),dimensionOf:t=>e.node(t)?.descriptor.dimension}}_writeInPlace(e,t){let r={};for(let[i,a]of Object.entries(e.spec.props))N(t.props[i],a)||(r[i]=a);_c(e);let{literal:s,bindings:o}=I.bindProps(r,this._resolveVariable);e.node.set({...s,...o}),Mt(e)}_updateVariables(e){let{added:t,removed:r,changed:s}=e.diff.variables;for(let o of r)this._vars.delete(o);for(let o of t)this._vars.set(o,this._liveVariable(e.next.variables.get(o)));for(let o of s){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 r=c=>this._live.get(c.id)?.node===c;for(let c of e.removed){let d=this._live.get(c);d&&(ms(d.node,r),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&&ms(d.node,r)}let{root:s,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=s,this._root.spec=s,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,r){let s=new Map;if(Ue(this._doc))return s;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&&(r(),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);_&&s.set(m.id,_)}return s}},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,bl=new Set(["to","set"]),hs=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 ps(n){let e=n.node;n.baseline=mr(e),n.baseStackDepth=e._stateStack.length}function kl(n,e){if(!e)return[];let t=n.node.__cells?.slots;if(!t)return null;let r=[];for(let[s,o]of t){let i=e.has(o)?n.baseline.get(s):void 0;i&&r.push({slot:o,baseline:i})}return r.length===e.size?r:null}function Mt(n){ps(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 ms(n,e){for(let t of n._allChildren)e(t)||ms(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 gs=class{parentId;constructor(e,t){this.parentId=e,this._tree=new Int32Array(t+1)}add(e,t){for(let r=e+1;r<this._tree.length;r+=r&-r)this._tree[r]+=t}before(e){let t=0;for(let r=e;r>0;r-=r&-r)t+=this._tree[r];return t}_tree},Sn=class{time=-1/0;constructor(e,t){let r=new Map;e.forEach((s,o)=>{if(!t.has(s.id))return;let i=s.parentId??b,a=r.get(i);a?a.push({spec:s,order:o}):r.set(i,[{spec:s,order:o}])});for(let[s,o]of r){o.sort((a,c)=>a.spec.layerOrder-c.spec.layerOrder);let i=new gs(s,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((s,o)=>s.time-o.time)}crossed(e){this.time=e;let t=this._upperBound(e);if(t===this._cursor)return Sl;let r=Math.min(t,this._cursor),s=Math.max(t,this._cursor);this._cursor=t;let o=++this._pass,i=[];for(let a=r;a<s;a++){let{row:c}=this._events[a];c.pass!==o&&(c.pass=o,i.push(c))}return i}differs(e,t){let r=this._upperBound(Math.min(e,t)),s=this._upperBound(Math.max(e,t));for(let o=r;o<s;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,r=this._events.length;for(;t<r;){let s=t+r>>>1;this._events[s].time<=e?t=s+1:r=s}return t}},Sl=[];function Uw(n){let e=n.width??0,t=n.height??0,{x:r,y:s,pivot:o}=So(n,e,t);return{...ko(n),rotation:n.rotation??0,scale:n.scale??1,x:r,y:s,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 Ww(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 Xw(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 ys(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 ws(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 _s=class extends Error{issue;name="RenderBackendError";retryable;constructor(e){super(e.message),this.issue=e,this.retryable=e.kind==="device-lost"}};function Al(n){return n.kind==="device-lost"||n.kind==="crashed"}var Ml={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})},Ol={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})},Tl={image:(n,e)=>({src:n,...e}),data:(n,e,t,r)=>({data:n,width:e,height:t,...r}),surface:(n,e)=>({width:512,height:512,...e,source:n})};function El(n,e){return n===void 0?e.map(xs):typeof n=="number"?e.map(()=>xs(n)):e.map((t,r)=>xs(n[r]??t))}function xs(n){return Math.max(1,Math.floor(n))}function Cl(n,e){return e<=0?3:Math.max(3,Math.min(16,Math.round(n/e*40)))}function Pl(n){let e=[n.width/2,n.height/2,n.depth/2],t=Math.max(e[0],e[1],e[2]),r=Math.max(0,Math.min(n.radius,e[0],e[1],e[2])),s=[Math.max(0,e[0]-r),Math.max(0,e[1]-r),Math.max(0,e[2]-r)],o=Cl(r,t),i=[],a=[],c=[],d=[];for(let u of Il(e,s,r,n.segments,o))Dl(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*Il(n,e,t,r,s){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=$l(a,u);yield{uSteps:r[c],vSteps:r[d],normal:()=>l,position:(f,h)=>{let p=[0,0,0];return p[a]=u*n[a],p[c]=vs(-e[c],e[c],f),p[d]=vs(-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:s,vSteps:r[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]=vs(-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:s,vSteps:s,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 Dl(n,e,t,r,s,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]),r.push(p[0],p[1],p[2]);let[g,m]=Fl(h,p,e);s.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,r,o,l,h,f),vc(t,r,o,f,h,p)}}function vc(n,e,t,r,s,o){let i=n[r*3],a=n[r*3+1],c=n[r*3+2],d=n[s*3],u=n[s*3+1],l=n[s*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[r*3]+O*e[r*3+1]+H*e[r*3+2]>=0?t.push(r,s,o):t.push(r,o,s)}function Fl(n,e,t){let r=Math.abs(e[0]),s=Math.abs(e[1]),o=Math.abs(e[2]),i=r>=s&&r>=o?0:s>=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 $l(n,e){let t=[0,0,0];return t[n]=e,t}function vs(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 Nl(n){return n===void 0||n===!0?!0:n===!1?!1:n==="receive"||typeof n=="object"}function Rl(n){return bc(n)?typeof n=="object"?n:{}:null}function ks(n){return n===void 0?[1,1]:typeof n=="number"?[n,n]:[n[0]??1,n[1]??n[0]??1]}function zl(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 Ll(n){let e=n.segments,[t,r]=typeof e=="number"?[e,e]:[e[0]??1,e[1]??e[0]??1],s=Math.max(1,Math.floor(t))+1,o=Math.max(1,Math.floor(r))+1,i=new Float32Array(s*o*3),a=new Float32Array(s*o*2),c=n.color?new Float32Array(s*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<s;p++){let g=p/(s-1),m=f*s+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 _=jl(n.color(g,h,d));c[m*3]=_[0],c[m*3+1]=_[1],c[m*3+2]=_[2]}}}let u=new Uint32Array((s-1)*(o-1)*6),l=0;for(let f=0;f<o-1;f++)for(let h=0;h<s-1;h++){let p=f*s+h,g=p+1,m=p+s,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 jl(n){let[e,t,r]=typeof n=="string"?ze(n):n;return[bs(e),bs(t),bs(r)]}function bs(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 r=0;r<4;r++){let s=e[r*4],o=e[r*4+1],i=e[r*4+2],a=e[r*4+3];t[r*4]=n[0]*s+n[4]*o+n[8]*i+n[12]*a,t[r*4+1]=n[1]*s+n[5]*o+n[9]*i+n[13]*a,t[r*4+2]=n[2]*s+n[6]*o+n[10]*i+n[14]*a,t[r*4+3]=n[3]*s+n[7]*o+n[11]*i+n[15]*a}return t}function Ot(n){let[e,t,r,s,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*_+r*v+s*A;if(M===0)return null;let O=1/M;return[x*O,(p*l*s-u*g*s-p*r*f+t*g*f+u*r*m-t*l*m)*O,(i*g*s-p*a*s+p*r*c-t*g*c-i*r*m+t*a*m)*O,(u*a*s-i*l*s-u*r*c+t*l*c+i*r*f-t*a*f)*O,_*O,(d*g*s-h*l*s+h*r*f-e*g*f-d*r*m+e*l*m)*O,(h*a*s-o*g*s-h*r*c+e*g*c+o*r*m-e*a*m)*O,(o*l*s-d*a*s+d*r*c-e*l*c-o*r*f+e*a*f)*O,v*O,(h*u*s-d*p*s-h*t*f+e*p*f+d*t*m-e*u*m)*O,(o*p*s-h*i*s+h*t*c-e*p*c-o*t*m+e*i*m)*O,(d*i*s-o*u*s-d*t*c+e*u*c+o*t*f-e*i*f)*O,A*O,(d*p*r-h*u*r+h*t*l-e*p*l-d*t*g+e*u*g)*O,(h*i*r-o*p*r-h*t*a+e*p*a+o*t*g-e*i*g)*O,(o*u*r-d*i*r+d*t*a-e*u*a-o*t*l+e*i*l)*O]}function le(n,e){let{x:t,y:r,z:s}=e;return{x:n[0]*t+n[4]*r+n[8]*s+n[12],y:n[1]*t+n[5]*r+n[9]*s+n[13],z:n[2]*t+n[6]*r+n[10]*s+n[14],w:n[3]*t+n[7]*r+n[11]*s+n[15]}}function kc(n,e,t){let{x:r,y:s,z:o,w:i}=e,a=r+r,c=s+s,d=o+o,u=r*a,l=r*c,f=r*d,h=s*c,p=s*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=Bl){let r=n.x-e.x,s=n.y-e.y,o=n.z-e.z,i=Math.hypot(r,s,o);i===0&&(o=1,i=1),r/=i,s/=i,o/=i;let a=t.y*o-t.z*s,c=t.z*r-t.x*o,d=t.x*s-t.y*r,u=Math.hypot(a,c,d);u===0&&(Math.abs(t.z)===1?r+=1e-4:o+=1e-4,i=Math.hypot(r,s,o),r/=i,s/=i,o/=i,a=t.y*o-t.z*s,c=t.z*r-t.x*o,d=t.x*s-t.y*r,u=Math.hypot(a,c,d)),a/=u,c/=u,d/=u;let l=s*d-o*c,f=o*a-r*d,h=r*c-s*a;return[a,c,d,0,l,f,h,0,r,s,o,0,0,0,0,1]}var Bl={x:0,y:1,z:0};function Et(n,e){if(!n)return Mn();let t=Z(n.position),r=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),Kl(r))}let s=n.quaternion??_r(Vl(n.rotation));return kc(t,s,r)}function Vl(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 Kl(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,r=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]/r,n[9]/r,n[10]/r,0,0,0,0,1]}function On(n,e,t,r,s){let o=t*Math.tan(n*Math.PI/360)/s,i=2*o,a=e*i,c=-.5*a;return Ul(c,c+a,o,o-i,t,r)}function Ul(n,e,t,r,s,o){let i=2*s/(e-n),a=2*s/(t-r),c=(e+n)/(e-n),d=(t+r)/(t-r),u=-(o+s)/(o-s),l=-2*o*s/(o-s);return[i,0,0,0,0,a,0,0,c,d,u,-1,0,0,l,0]}function Ss(n,e,t,r,s,o,i){let a=(e-n)/(2*i),c=(t-r)/(2*i),d=(e+n)/2,u=(t+r)/2,l=d-a,f=d+a,h=u+c,p=u-c,g=1/(f-l),m=1/(h-p),x=1/(o-s);return[2*g,0,0,0,0,2*m,0,0,0,0,-2*x,0,-(f+l)*g,-(h+p)*m,-(o+s)*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,r=1/0,s=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<r&&(r=d.y),d.z<s&&(s=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:r,z:s},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]=ks(n.radius),r=Math.max(e,t);return q(r,(n.height??1)/2,r)}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,r=-1/0;for(let s of n.points){let o=Z(s);e=Math.max(e,Math.abs(o.x)),t=Math.min(t,o.y),r=Math.max(r,o.y)}return Number.isFinite(t)?{min:{x:-e,y:t,z:-e},max:{x:e,y:r,z:e}}:null}case"tube":{let e=n.points.map(r=>Z(r)),t=Gl(e);return t?Wl(t,n.radius??1):null}case"buffer":return Yl(n.position);case"edges":case"wireframe":return En(n.source);default:return null}}function Gl(n){if(n.length===0)return null;let e=1/0,t=1/0,r=1/0,s=-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<r&&(r=a.z),a.x>s&&(s=a.x),a.y>o&&(o=a.y),a.z>i&&(i=a.z);return{min:{x:e,y:t,z:r},max:{x:s,y:o,z:i}}}function Yl(n){if(n.length<3)return null;let e=1/0,t=1/0,r=1/0,s=-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<r&&(r=u),c>s&&(s=c),d>o&&(o=d),u>i&&(i=u)}return{min:{x:e,y:t,z:r},max:{x:s,y:o,z:i}}}function Wl(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 Xl=["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"],ql=["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,r,s=o=>console.error(`[AssetManager] ${o.message}`)){this.onError=s,this.precomp=e,this.layoutGateKeys=Ac(e),this.storageAdapter=t,this.audioDevice=r}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[r,s]of this.precomp.assets){if(s.record.type==="loader"){let o=this.syncLoader(r,s,e);o&&t.push(o);continue}s.cacheAt<=e&&s.record.endFrame>=e&&t.push(this.storageAdapter.loadAsset(r,s.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,r]of this.precomp.assets){if(r.record.type==="loader"){this.syncLoader(t,r,e)?.catch(s=>{console.error(`[AssetManager] loader failed for ${t}:`,s)});continue}r.cacheAt<=e&&r.record.endFrame>=e&&this.storageAdapter.loadAsset(t,r.record).catch(s=>{console.error(`[AssetManager] prefetch failed for ${t}:`,s)})}}syncLoader(e,t,r){if(t.record.type!=="loader")return;let s=t.discardAt??1/0;if(!(t.cacheAt<=r&&r<=s)){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 r=this.loaderInFlight.get(e);if(r)return r;let s=t().then(o=>{this.loaderDisposers.set(e,o??Hl)}).finally(()=>{this.loaderInFlight.delete(e)});return this.loaderInFlight.set(e,s),s}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,r=[],s=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=Jl(d,u);i.has(h)||(i.add(h),r.push({...d,id:h,startAt:l,endAt:f,...d.bus&&{bus:d.bus.map(p=>({...p,startAt:u+p.startAt,endAt:u+p.endAt}))}}),s.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 s)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)s.has(d)?o.has(d)&&this.reportAudio(d,u):(this.audioFailed.delete(d),this.audioReported.delete(d));let c=Ql(r);c!==this.lastAudioRequestKey&&(this.audioDevice.schedule(r),this.lastAudioRequestKey=c),(this.lastAudioSrcs===null||!ef(this.lastAudioSrcs,s))&&(this.audioDevice.retain(s),this.lastAudioSrcs=s)}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 r=t instanceof Error?t.message:String(t);this.onError(new Error(`audio "${e}" could not be loaded: ${r}`,{cause:t}))}};function Ac(n){let e=new Set;for(let t of n.tracks)for(let r of t.layoutGates??[])e.add(r);return e}var Hl=()=>{};function Jl(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)}|${Zl(n.bus)}`}function Zl(n){return!n||n.length===0?"":n.map(Dr).join(">")}function Ql(n){return n.length===0?"":n.map(e=>e.id).sort().join(`
@@ -10,4 +10,4 @@ ${e}
10
10
 
11
11
  Loading it directly also failed: ${String(o)}`))}),!0):!1}recordFor(e,t,r){try{return e==="font"?{type:"font",src:t,startFrame:r,endFrame:r,fontFamily:t,fontWeight:400}:e==="image"?(this.assetCatalog.getImageMeta(t),{type:"image",src:t,startFrame:r,endFrame:r}):(this.assetCatalog.getVideoMeta(t),{type:"video",src:t,startFrame:r,endFrame:r,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 r={registry:e.registry,viewport:this.viewport,fps:this.fps,assets:e.assets,measurer:this.measurer};this.store=new Oe(t,r,{profile:e.precompProfile,isReady:s=>this.assetManager?.isReady(s)??!1}),this.precomper=new Vn(t,r,{store:this.store}),this.precomp=this.precomper.ensureCovering(0),this.stateEvaluator=new jn(t,r,this.store),this.assetManager=new Cn(this.precomp,this.storageAdapter,this.audioDevice,s=>this.captureRenderError(s)),this.masterClock.setDuration(this.totalDuration),this.masterClock.onPlay((s,o,i)=>{this.audioDevice.play(s,o,i),this.storageAdapter.setPlaying(!0)}),this.masterClock.onPause(()=>{this.audioDevice.stop(),this.storageAdapter.setPlaying(!1)}),this.masterClock.onTick(async s=>{let o=++this.seekGeneration,i=xe(s,this.fps);i>=this.totalFrames&&this.masterClock.pause(),this.discoverThrough(i),await this.loadFrame(i),this.isCurrent(o)&&(this.audioDevice.syncTo(s),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 r of Me(this.store.spans,Math.floor(e)))for(let s of this.store.layoutGates(r.id))this.assetManager.isReady(s.src)||t.push(s);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(Uf*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 r=ws(t);this.captureRenderError(new Error(r.message),void 0,r)}}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 r=Math.max(0,Math.min(e,this.totalFrames));if(this.masterClock.pause(),this.discoverThrough(r),this.masterClock.seek(Re(r,this.fps)),await this.loadFrame(r),!this.isCurrent(t)||await this.settle(()=>this.renderAt(r),t)==="superseded")return;this.assetManager.prefetch(r),this.trimAround(r)}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 r=Math.min(this.currentFrame,Math.max(0,this.totalFrames-1));this.pendingSwap=t,this.paintInFlight=t,this.lastReplacePaint=this.loadAndRepaint(r,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(r){console.error("[PlaybackController] swap asset load failed:",r);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,r=!1){let s=r?Gf(this.storageAdapter):this.storageAdapter,o=await Lc(e,s,()=>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),r=t?.startFrame??0,s=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,s);f&&o.set(l,{startFrame:r+f.startFrame,endFrame:r+f.endFrame})});let a=Wf(t?.audioRequests??[],i);return yd(e.canvas,"",o,a)}getNodeState(e){let t=this.stateEvaluator.currentCanvas;if(!t)return null;let r=_d(t,e);return r?{id:r.id,type:r.className,properties:r.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 r=Te(t,e);return r?r.properties:null}getNodeBoxes(){let e=this.stateEvaluator.currentCanvas;if(!e)return[];let t=[];return Ks(e,"",t,!0),t}projectNode3D(e,t,r){let s=this.stateEvaluator.currentCanvas;return s?dd(s,e,t,r):null}parentPlanePoint(e,t){let r=this.stateEvaluator.currentCanvas;return r?ed(r,e,t):null}childPlanePoint(e,t){let r=this.stateEvaluator.currentCanvas;return r?td(r,e,t):null}reparentPlacement(e,t,r){let s=this.stateEvaluator.currentCanvas;return s?nd(s,e,t,r):null}nodeHandles(e){let t=this.stateEvaluator.currentCanvas;return t?rd(t,e):null}handleValue(e,t,r){let s=this.stateEvaluator.currentCanvas;return s?sd(s,e,t,r):null}getTextLayout(e){let t=this.stateEvaluator.currentCanvas;if(!t)return null;let r=gd(t,e);return r instanceof R?this.textLayoutOf(r,e):null}textLayoutOf(e,t){let r=xc(this.measurer);return r?md(e,t,r):null}pickNode(e,t=0){let r=this.stateEvaluator.currentCanvas;return r?ud(r,e,t):null}setNodeOverride(e,t){let r=this.overrides.get(e);this.overrides.set(e,r?{...r,...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,r]=await Promise.all([this.storageAdapter.warmPendingDecodes(),this.storageAdapter.warmPendingUpgrades()]);if(!(t||r)||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,r]of this.overrides)gd(e,t)?.set(r)}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()}},Uf=30;function Gf(n){return{async warmPendingDecodes(){let[e,t]=await Promise.all([n.warmPendingDecodes(),n.warmPendingUpgrades()]);return e||t}}}function Yf(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,r){let s={id:n.id,path:e,type:n.className,children:n._allChildren.map((a,c)=>yd(a,ye(e,c),t,r))},o=r.get(e);o&&o.length>0&&(s.waveform=o);let i=t.get(e);return i&&(s.startFrame=i.startFrame,s.endFrame=i.endFrame),s}function Wf(n,e){let t=new Map;for(let r of n){let s=r.ownerId!==void 0?e.get(r.ownerId):"";if(s===void 0)continue;let o={src:r.src,startTime:r.startAt,endTime:Number.isFinite(r.endAt)?r.endAt:null},i=t.get(s);i?i.push(o):t.set(s,[o])}return t}function gd(n,e){if(e==="")return n;let t=n;for(let r of e.split(".")){let s=t._allChildren[Number(r)];if(!s)return null;t=s}return t}function _d(n,e){if(n.id===e)return n;for(let t of n._allChildren){let r=_d(t,e);if(r)return r}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),r=this.manifest.audio[t];if(r)return r.duration;let s=this.manifest.video[t];if(s)return s.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:r}=this.getImageMeta(e);return{width:t,height:r}}};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 r of this.timeCallbacks)r(e)}setPlaying(e){this._isPlaying=e}play(e,t){this._isPlaying=!0;for(let r of this.playCallbacks)r(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 r={catalog:this._catalog,viewport:this.viewport,fps:this.fps};this._storage=e.platform.createStorageAdapter(r),this._renderContext=e.platform.createRenderContext(this._storage);let s=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:s,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(){tr(this._project.theme)}_override;_project;_catalog;_storage;_renderContext;_controller;_playback;_unsubscribe};function xd(n,e,t){let r=da(n),s=Hr(r),o=s.changes.length>0?s.document:r,i={...o,viewport:e.viewport??o.viewport??t.viewport,fps:e.fps??o.fps??t.fps};return Pa(i),i}function Xk(n,e={}){let t=e.delimiter??",",r=Hf(n,t);if(r.length===0)return[];let s=r[0].map(d=>d.trim()),i=r.slice(1).map(d=>{let u={};return s.forEach((l,f)=>{u[l]=d[f]??""}),u}),a=Xf(s,i,e.numeric),c=qf(s,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 qk(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 Xf(n,e,t){return t===!1?[]:Array.isArray(t)?t:n.filter(r=>{let s=!1;for(let o of e){let i=o[r];if(i!==""){if(!Number.isFinite(Number(i)))return!1;s=!0}}return s})}function qf(n,e,t,r){if(r===!1)return[];if(Array.isArray(r))return r;let s=new Set(t);return n.filter(o=>{if(s.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 Hf(n,e){let t=[],r=[],s="",o=!1,i=!1,a=()=>{r.push(s),s=""},c=()=>{a(),t.push(r),r=[],i=!1};for(let d=0;d<n.length;d++){let u=n[d];if(o){u==='"'?n[d+1]==='"'?(s+='"',d++):o=!1:s+=u;continue}if(u==='"'){o=!0,i=!0;continue}if(u===e){i=!0,a();continue}if(u!=="\r"){if(u===`
12
12
  `){(i||s)&&c();continue}s+=u,i=!0}}return(i||s)&&c(),t}var vd=new Set;function Jf(){return typeof process<"u"&&!0}function bd(n){return`[motionscript] ${n.name} is deprecated and will be removed in ${n.removeIn}; use ${n.use} instead.`}function kd(n){Jf()||vd.has(n.name)||(vd.add(n.name),console.warn(bd(n)))}function Zf(n,e){let t=function(...r){return kd(e),n.apply(this,r)};return Object.defineProperty(t,"name",{value:e.name}),t}var Zk=(n,e)=>{let t=new Array(n);for(let r=0;r<n;r++)t[r]=e(r);return t};function eS(){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,r)=>(t=(t<<5)-t+r.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}},Sd=4294967296,Us=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,r)=>(t<<5)-t+r.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=Sd){return Math.floor(this.gen.next()*(t-e))+e}floatArray(e,t=0,r=1){let s=new Array(e);for(let o=0;o<e;o++)s[o]=this.nextFloat(t,r);return s}intArray(e,t=0,r=Sd){let s=new Array(e);for(let o=0;o<e;o++)s[o]=this.nextInt(t,r);return s}gauss(e=0,t=1){if(this.spareGauss!==null){let a=this.spareGauss;return this.spareGauss=null,e+t*a}let r,s,o;do r=this.gen.next()*2-1,s=this.gen.next()*2-1,o=r*r+s*s;while(o>=1||o===0);let i=Math.sqrt(-2*Math.log(o)/o);return this.spareGauss=s*i,e+t*(r*i)}noise(e,t=1){let r=e*t,s=Math.floor(r),o=r-s,i=o*o*(3-2*o),a=this.latticeValue(s),c=this.latticeValue(s+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 hS(n){return typeof n?._stepper=="function"}export{Ve as a,Od as b,Td as c,Ir as d,gt as e,Cd as f,Up as g,Ke as h,Dr as i,Tm as j,ii as k,ai as l,ci as m,ye as n,on as o,an as p,Nr as q,Ie as r,ui as s,li as t,fi as u,hi as v,pi as w,Eg as x,Cg as y,Pg as z,Ig as A,Dg as B,Fg as C,$g 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,Ur 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,Ny as na,Zi as oa,Qi as pa,ea as qa,ta as ra,na as sa,ra as ta,sa as ua,oa as va,ia as wa,aa as xa,Ue as ya,Vy as za,ln as Aa,Wd as Ba,b as Ca,U as Da,Ky as Ea,ca as Fa,Ge as Ga,Uy as Ha,Xd as Ia,ue as Ja,qd as Ka,da as La,Xr as Ma,kt as Na,ua as Oa,qr as Pa,Hr as Qa,Qr as Ra,pu as Sa,Pa as Ta,r_ as Ua,St as Va,vu as Wa,bu as Xa,hn as Ya,Tu as Za,Eu as _a,Cu as $a,z_ as ab,mn as bb,Fu as cb,Ru as db,Ye as eb,bn as fb,Uw as gb,Ww as hb,Xw as ib,ys as jb,ws as kb,An as lb,_s as mb,Al as nb,Ml as ob,Ol as pb,Tl as qb,El as rb,Pl as sb,bc as tb,Nl as ub,Rl as vb,ks as wb,zl as xb,Ll 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,Ss as Jb,q as Kb,Xe as Lb,Tn as Mb,qe as Nb,En as Ob,Xl as Pb,ql as Qb,Cn as Rb,Pn as Sb,we as Tb,In as Ub,Yv as Vb,Re as Wb,xe as Xb,Xv as Yb,He as Zb,Pt as _b,Oc as $b,Me as ac,re as bc,Je as cc,Dn as dc,jt as ec,Oe as fc,jn as gc,Fs as hc,Lc as ic,Yb as jc,Vn as kc,et as lc,Ls as mc,Wc as nc,Xc as oc,se as pc,ed as qc,td as rc,nd as sc,rd as tc,sd as uc,Kt as vc,ad as wc,Te as xc,dd as yc,ud as zc,Ks as Ac,md as Bc,pk as Cc,mk as Dc,Gn as Ec,Yn as Fc,Wn as Gc,Xn as Hc,qn as Ic,wd as Jc,xd as Kc,Xk as Lc,qk as Mc,bd as Nc,kd as Oc,Zf as Pc,Zk as Qc,eS as Rc,Hn as Sc,Us as Tc,hS as Uc};
13
- //# sourceMappingURL=chunk-65DNLAPH.js.map
13
+ //# sourceMappingURL=chunk-LJSYPGYX.js.map