{A(),g(),F=setInterval(g,u*1e3)},A=()=>F!==void 0&&clearInterval(F);return{setDuration:D,start:m,stop:()=>{c=0,a=0,A()},pause:()=>A(),duration:i,getPhase:()=>a}}class Lr{worker;pattern;started=!1;cps=1;getTime;phase=0;constructor({interval:t,onTrigger:i,onToggle:u,onError:n,getTime:c,latency:a=.1}){this.getTime=c,this.onToggle=u;const f=p=>Math.round(p*1e3)/1e3;this.clock=Pr(c,(p,D,g)=>{g===0&&(this.origin=p);const F=f(p-this.origin);this.phase=F-a;const m=f(F+D),A=c();try{this.pattern.queryArc(F,m).forEach(C=>{if(C.part.begin.equals(C.whole.begin)){const x=C.whole.begin+this.origin-A+a,P=C.duration*1;i?.(C,x,P)}})}catch(v){console.warn("scheduler error",v),n?.(v)}},t)}getPhase(){return this.phase}setStarted(t){this.started=t,this.onToggle?.(t)}start(){if(!this.pattern)throw new Error("Scheduler: no pattern set! call .setPattern first.");this.clock.start(),this.setStarted(!0)}pause(){this.clock.stop(),this.setStarted(!1)}stop(){delete this.origin,this.clock.stop(),this.setStarted(!1)}setPattern(t,i=!1){this.pattern=t,i&&!this.started&&this.start()}setCps(t=1){this.cps=t}log(t,i,u){const n=u.filter(c=>c.hasOnset());console.log(`${t.toFixed(4)} - ${i.toFixed(4)} ${Array(n.length).fill("I").join("")}`)}}const{isPattern:Nr,Pattern:Tr}=Fr;let kt=!1;const Mr=async(...e)=>{kt&&console.warn("evalScope was called more than once."),kt=!0;const t=await Promise.allSettled(e),i=t.filter(u=>u.status==="fulfilled").map(u=>u.value);t.forEach((u,n)=>{u.status==="rejected"&&console.warn(`evalScope: module with index ${n} could not be loaded:`,u.reason)}),Object.assign(globalThis,...i,Tr.prototype.bootstrap())};function Rr(e,t={}){const{wrapExpression:i=!0,wrapAsync:u=!0}=t;i&&(e=`{${e}}`),u&&(e=`(async ()=>${e})()`);const n=`"use strict";return (${e})`;return Function(n)()}const Or=async(e,t)=>{kt||await Mr(),t&&(e=t(e));let u=await Rr(e,{wrapExpression:!!t});if(!Nr(u)){console.log("evaluated",u);const n=`got "${typeof u}" instead of pattern`;throw new Error(n+(typeof u=="function"?", did you forget to call a function?":"."))}return{mode:"javascript",pattern:u}};function Vr({interval:e,defaultOutput:t,onSchedulerError:i,onEvalError:u,onEval:n,getTime:c,transpiler:a,onToggle:f}){const p=new Lr({interval:e,onTrigger:t,onError:i,getTime:c,onToggle:f});return{scheduler:p,evaluate:async g=>{if(!g)throw new Error("no code to evaluate");try{const{pattern:F}=await Or(g,a);p.setPattern(F,!0),n?.({pattern:F,code:g})}catch(F){console.warn(`eval error: ${F.message}`),u?.(F)}}}}var qr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},gi={},mi={};(function(e){(function t(i){var u,n,c,a,f,p;function D(E){var S={},B,w;for(B in E)E.hasOwnProperty(B)&&(w=E[B],typeof w=="object"&&w!==null?S[B]=D(w):S[B]=w);return S}function g(E,S){var B,w,U,T;for(w=E.length,U=0;w;)B=w>>>1,T=U+B,S(E[T])?w=B:(U=T+1,w-=B+1);return U}u={AssignmentExpression:"AssignmentExpression",AssignmentPattern:"AssignmentPattern",ArrayExpression:"ArrayExpression",ArrayPattern:"ArrayPattern",ArrowFunctionExpression:"ArrowFunctionExpression",AwaitExpression:"AwaitExpression",BlockStatement:"BlockStatement",BinaryExpression:"BinaryExpression",BreakStatement:"BreakStatement",CallExpression:"CallExpression",CatchClause:"CatchClause",ChainExpression:"ChainExpression",ClassBody:"ClassBody",ClassDeclaration:"ClassDeclaration",ClassExpression:"ClassExpression",ComprehensionBlock:"ComprehensionBlock",ComprehensionExpression:"ComprehensionExpression",ConditionalExpression:"ConditionalExpression",ContinueStatement:"ContinueStatement",DebuggerStatement:"DebuggerStatement",DirectiveStatement:"DirectiveStatement",DoWhileStatement:"DoWhileStatement",EmptyStatement:"EmptyStatement",ExportAllDeclaration:"ExportAllDeclaration",ExportDefaultDeclaration:"ExportDefaultDeclaration",ExportNamedDeclaration:"ExportNamedDeclaration",ExportSpecifier:"ExportSpecifier",ExpressionStatement:"ExpressionStatement",ForStatement:"ForStatement",ForInStatement:"ForInStatement",ForOfStatement:"ForOfStatement",FunctionDeclaration:"FunctionDeclaration",FunctionExpression:"FunctionExpression",GeneratorExpression:"GeneratorExpression",Identifier:"Identifier",IfStatement:"IfStatement",ImportExpression:"ImportExpression",ImportDeclaration:"ImportDeclaration",ImportDefaultSpecifier:"ImportDefaultSpecifier",ImportNamespaceSpecifier:"ImportNamespaceSpecifier",ImportSpecifier:"ImportSpecifier",Literal:"Literal",LabeledStatement:"LabeledStatement",LogicalExpression:"LogicalExpression",MemberExpression:"MemberExpression",MetaProperty:"MetaProperty",MethodDefinition:"MethodDefinition",ModuleSpecifier:"ModuleSpecifier",NewExpression:"NewExpression",ObjectExpression:"ObjectExpression",ObjectPattern:"ObjectPattern",PrivateIdentifier:"PrivateIdentifier",Program:"Program",Property:"Property",PropertyDefinition:"PropertyDefinition",RestElement:"RestElement",ReturnStatement:"ReturnStatement",SequenceExpression:"SequenceExpression",SpreadElement:"SpreadElement",Super:"Super",SwitchStatement:"SwitchStatement",SwitchCase:"SwitchCase",TaggedTemplateExpression:"TaggedTemplateExpression",TemplateElement:"TemplateElement",TemplateLiteral:"TemplateLiteral",ThisExpression:"ThisExpression",ThrowStatement:"ThrowStatement",TryStatement:"TryStatement",UnaryExpression:"UnaryExpression",UpdateExpression:"UpdateExpression",VariableDeclaration:"VariableDeclaration",VariableDeclarator:"VariableDeclarator",WhileStatement:"WhileStatement",WithStatement:"WithStatement",YieldExpression:"YieldExpression"},c={AssignmentExpression:["left","right"],AssignmentPattern:["left","right"],ArrayExpression:["elements"],ArrayPattern:["elements"],ArrowFunctionExpression:["params","body"],AwaitExpression:["argument"],BlockStatement:["body"],BinaryExpression:["left","right"],BreakStatement:["label"],CallExpression:["callee","arguments"],CatchClause:["param","body"],ChainExpression:["expression"],ClassBody:["body"],ClassDeclaration:["id","superClass","body"],ClassExpression:["id","superClass","body"],ComprehensionBlock:["left","right"],ComprehensionExpression:["blocks","filter","body"],ConditionalExpression:["test","consequent","alternate"],ContinueStatement:["label"],DebuggerStatement:[],DirectiveStatement:[],DoWhileStatement:["body","test"],EmptyStatement:[],ExportAllDeclaration:["source"],ExportDefaultDeclaration:["declaration"],ExportNamedDeclaration:["declaration","specifiers","source"],ExportSpecifier:["exported","local"],ExpressionStatement:["expression"],ForStatement:["init","test","update","body"],ForInStatement:["left","right","body"],ForOfStatement:["left","right","body"],FunctionDeclaration:["id","params","body"],FunctionExpression:["id","params","body"],GeneratorExpression:["blocks","filter","body"],Identifier:[],IfStatement:["test","consequent","alternate"],ImportExpression:["source"],ImportDeclaration:["specifiers","source"],ImportDefaultSpecifier:["local"],ImportNamespaceSpecifier:["local"],ImportSpecifier:["imported","local"],Literal:[],LabeledStatement:["label","body"],LogicalExpression:["left","right"],MemberExpression:["object","property"],MetaProperty:["meta","property"],MethodDefinition:["key","value"],ModuleSpecifier:[],NewExpression:["callee","arguments"],ObjectExpression:["properties"],ObjectPattern:["properties"],PrivateIdentifier:[],Program:["body"],Property:["key","value"],PropertyDefinition:["key","value"],RestElement:["argument"],ReturnStatement:["argument"],SequenceExpression:["expressions"],SpreadElement:["argument"],Super:[],SwitchStatement:["discriminant","cases"],SwitchCase:["test","consequent"],TaggedTemplateExpression:["tag","quasi"],TemplateElement:[],TemplateLiteral:["quasis","expressions"],ThisExpression:[],ThrowStatement:["argument"],TryStatement:["block","handler","finalizer"],UnaryExpression:["argument"],UpdateExpression:["argument"],VariableDeclaration:["declarations"],VariableDeclarator:["id","init"],WhileStatement:["test","body"],WithStatement:["object","body"],YieldExpression:["argument"]},a={},f={},p={},n={Break:a,Skip:f,Remove:p};function F(E,S){this.parent=E,this.key=S}F.prototype.replace=function(S){this.parent[this.key]=S},F.prototype.remove=function(){return Array.isArray(this.parent)?(this.parent.splice(this.key,1),!0):(this.replace(null),!1)};function m(E,S,B,w){this.node=E,this.path=S,this.wrap=B,this.ref=w}function A(){}A.prototype.path=function(){var S,B,w,U,T,G;function q(M,K){if(Array.isArray(K))for(w=0,U=K.length;w=0;--B)if(E[B].node===S)return!0;return!1}A.prototype.traverse=function(S,B){var w,U,T,G,q,M,K,te,se,ee,Y,me;for(this.__initialize(S,B),me={},w=this.__worklist,U=this.__leavelist,w.push(new m(S,null,null,null)),U.push(new m(null,null,null,null));w.length;){if(T=w.pop(),T===me){if(T=U.pop(),M=this.__execute(B.leave,T),this.__state===a||M===a)return;continue}if(T.node){if(M=this.__execute(B.enter,T),this.__state===a||M===a)return;if(w.push(me),U.push(T),this.__state===f||M===f)continue;if(G=T.node,q=G.type||T.wrap,ee=this.__keys[q],!ee)if(this.__fallback)ee=this.__fallback(G);else throw new Error("Unknown node type "+q+".");for(te=ee.length;(te-=1)>=0;)if(K=ee[te],Y=G[K],!!Y){if(Array.isArray(Y)){for(se=Y.length;(se-=1)>=0;)if(!!Y[se]&&!x(U,Y[se])){if(C(q,ee[te]))T=new m(Y[se],[K,se],"Property",null);else if(v(Y[se]))T=new m(Y[se],[K,se],null,null);else continue;w.push(T)}}else if(v(Y)){if(x(U,Y))continue;w.push(new m(Y,K,null,null))}}}}},A.prototype.replace=function(S,B){var w,U,T,G,q,M,K,te,se,ee,Y,me,ye;function N(Te){var ze,He,Z,De;if(Te.ref.remove()){for(He=Te.ref.key,De=Te.ref.parent,ze=w.length;ze--;)if(Z=w[ze],Z.ref&&Z.ref.parent===De){if(Z.ref.key TODO126))){o+=ar(d,r.charCodeAt(s+1));continue}o+=String.fromCharCode(d)}if(k=!(m==="double"||m==="auto"&&_=0&&!a.code.isLineTerminator(r.charCodeAt(o));--o);return r.length-1-o}function fr(r,o){var s,l,d,b,_,k,L,H;for(s=r.split(/\r\n|[\r\n]/),k=Number.MAX_VALUE,l=1,d=s.length;l