diff --git a/assets/index-b668f945.js b/assets/index-0cd81c9c.js
similarity index 97%
rename from assets/index-b668f945.js
rename to assets/index-0cd81c9c.js
index fb42a4f..cba1216 100644
--- a/assets/index-b668f945.js
+++ b/assets/index-0cd81c9c.js
@@ -525,15 +525,28 @@ mod(1) :: beat_warp([2,4,5,10,11].pick())
Now you know how to play some basic rhythmic music but you are a bit stuck in a one-bar long loop. Let's see how we can think about time flowing on longer periods. The functions you are going to learn now are _very fundamental_ and all the fun comes from mastering them. **Read and experiment a lot with the following examples**.
-- div(n: number): the div is a temporal switch. If the value 2 is given, the function will return true for two beats and false for two beats. There are multiple ways to use it effectively. You can pass an integer or a floating point number. Here are some examples.
+- div(n: number, ratio: number = 50): the div method is a temporal switch. If the value 2 is given, the function will return true for two beats and false for two beats. There are multiple ways to use it effectively. You can pass an integer or a floating point number.
+ - ratio: number = 50: this argument is ratio expressed in %. It determines how much of the period should be true or false. A ratio of 75 means that 75% of the period will be true. A ratio of 25 means that 25% of the period will be true.
-${e("Creating two beats of silence",`
-div(3)::mod([1,.5].beat())::sound('kick').shape(0.3).out(); // Playing every three beats
-mod(1)::snd('snare').out(); // Playing on every beat
-div(2)::mod(.75)::snd('hat').out(); // Playing only every two beats
+${e("Two beats of silence, two beats of playing",`
+div(4) :: mod(1) :: snd('kick').out()
+`,!0)}
+
+${e("Clapping on the edge",`
+div(2.5, 10) :: mod(.25) :: snd('cp').out()
+div(2.5, 75) :: mod(.25) :: snd('click').speed(2).end(0.2).out()
+div(2.5) :: mod(.5) :: snd('bd').out()
+`,!1)}
+
+${e("Good old true and false",`
+if (div(4, 75)) {
+ mod(1) :: snd('kick').out()
+} else {
+ mod(.5) :: snd('snare').out()
+}
`,!0)}
-You can also use it to think about **longer durations** spanning over multiple bars.
+div is extremely powerful and is used internally for a lot of other Topos functions. You can also use it to think about **longer durations** spanning over multiple bars.
${e("Clunky algorithmic rap music",`
// Rap God VS Lil Wild -- Adel Faure
@@ -554,22 +567,11 @@ if (div(16)) {
}
`,!0)}
-And you can use it for other things inside a method parameter:
+You can use it everywhere to spice things up, including as a method parameter picker:
${e("div is great for parameter variation",`
-mod(.5)::snd(div(2) ? 'kick' : 'hat').out()
+mod(.5)::snd(div(4) ? 'kick' : 'hat').out()
`,!0)}
-
-${e("div is great for pretty much everything",`
-div([1, .5].beat()) :: mod(.25) :: sound('shaker').out();
-div([4, .5].beat()) :: mod(.25) :: sound('shaker').speed(2).out();
-div([1, 2].beat()) :: mod(1.75) :: sound('snare').out();
-div(4) :: mod(.5) :: sound('tom').out()
-div(.125) :: mod(.5) :: sound('amencutup')
- .hcutoff(500).pan(sine())
- .n($(1)).shape(0.5).out()
-`,!0)}
-
- divbar(n: number): works just like div but at the level of bars instead of beats. It allows you to think about even bigger time cycles. You can also pair it with regular div for making complex algorithmic beats.
@@ -1893,7 +1895,7 @@ ${e("Live coded poetry with array and string chaining",`
`+c.line+" | "+_+`
`+m+" | "+t("",l.column-1," ")+t("",y,"^")}else a+=`
at `+d}return a},e.buildMessage=function(i,a){var s={literal:function(_){return'"'+l(_.text)+'"'},class:function(_){var b=_.parts.map(function(y){return Array.isArray(y)?c(y[0])+"-"+c(y[1]):c(y)});return"["+(_.inverted?"^":"")+b.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(_){return _.description}};function o(_){return _.charCodeAt(0).toString(16).toUpperCase()}function l(_){return _.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(b){return"\\x0"+o(b)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(b){return"\\x"+o(b)})}function c(_){return _.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(b){return"\\x0"+o(b)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(b){return"\\x"+o(b)})}function d(_){return s[_.type](_)}function p(_){var b=_.map(d),y,A;if(b.sort(),b.length>0){for(y=1,A=1;y>",re="<<",te="<",ee=">",M="_",G="?",K="r",X="#",oe="b",ie=/^[0-9]/,Oe=/^[ \n\r\t]/,xe=/^[mklpdcwyhnqaefsxtgujzo]/,we=mt("-",!1),Ee=vi([["0","9"]],!1,!1),Ae=mt(".",!1),ce=Ia("whitespace"),ke=vi([" ",`
-`,"\r"," "],!1,!1),Xe=mt(",",!1),Qe=mt("|",!1),Je=vi(["m","k","l","p","d","c","w","y","h","n","q","a","e","f","s","x","t","g","u","j","z","o"],!1,!1),rt=mt("(",!1),dt=mt(":",!1),vt=mt(")",!1),ft=mt("[:",!1),yt=mt("]",!1),Ft=mt("[",!1),Gr=mt("{",!1),qe=mt("}",!1),kr=mt("+",!1),at=mt("*",!1),ze=mt("/",!1),Mr=mt("%",!1),Ht=mt("^",!1),Sr=mt("&",!1),z=mt(">>",!1),me=mt("<<",!1),Ne=mt("<",!1),Re=mt(">",!1),je=mt("_",!1),ve=mt("?",!1),$t=mt("r",!1),st=mt("#",!1),bt=mt("b",!1),nn=function(D){return D.filter($=>$)},lt=function(){return parseFloat(Kt())},Zt=function(){return parseInt(Kt())},Tt=function(){},Ue=function(){return PM[Kt()]},Pr=function(D){return D.filter($=>$)},jn=function(D,$){return $?jt(AO,{item:D,times:$}):jt(RO,{items:D})},ot=function(D){return D},$r=function(D,$,W){return jt(rP,{left:D,operation:$,right:W})},vr=function(D,$){return jt(tP,{items:D,times:$})},Zi=function(D){return jt(DA,{items:D})},Ln=function(){return parseInt(Kt())},Qt=function(D){return D.map($=>typeof $=="number"?$:void 0)},_n=function(){return Math.ceil(RA(Kt()))},Ki=function(D){var $=D.filter(W=>W).map(W=>jt(gs,{pitch:W[0]},W.toString()));return jt(RO,{items:$})},Ei=function(D){return D},ji=function(){},an=function(D){return jt(Og,{items:D})},Jn=function(D){return jt(JM,{octave:D})},Sn=function(){return Kt().split("").reduce((D,$)=>D+($==="^"?1:-1),0)},zt=function(){return jt(yO,{seededRandom:a.seededRandom})},bi=function(D,$){return jt(yO,{min:D,max:$,seededRandom:a.seededRandom})},Ti=function(D,$){return jt(AO,{item:D,times:$})},Q=function(D){return jt(eP,{duration:D})},ne=function(D){return jt(lm,{duration:D})},le=function(D,$,W,ue){const Se=D?a.nodeOptions.octave+D:a.nodeOptions.octave;return jt(gs,{duration:$,pitch:ue,octave:Se,add:W})},he=function(D){return D.reduce(($,W)=>$+(W==="#"?1:-1),0)},Te=function(D,$){return jt(jM,{pitches:[D].concat($)})},N=0,_e=0,ht=[{line:1,column:1}],kt=0,yr=[],Le=0,De={},Ci;if("startRule"in a){if(!(a.startRule in l))throw new Error(`Can't start parsing from rule "`+a.startRule+'".');c=l[a.startRule]}function Kt(){return i.substring(_e,N)}function Ts(){return yi(_e,N)}function mt(D,$){return{type:"literal",text:D,ignoreCase:$}}function vi(D,$,W){return{type:"class",parts:D,inverted:$,ignoreCase:W}}function Cs(){return{type:"end"}}function Ia(D){return{type:"other",description:D}}function Na(D){var $=ht[D],W;if($)return $;for(W=D-1;!ht[W];)W--;for($=ht[W],$={line:$.line,column:$.column};Wkt&&(kt=N,yr=[]),yr.push(D))}function vs(D,$,W){return new e(e.buildMessage(D,$),D,$,W)}function wa(){var D,$,W=N*34+0,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,$=kn(),$!==s&&(_e=D,$=nn($)),D=$,De[W]={nextPos:N,result:D},D)}function Da(){var D,$,W,ue,Se,Ye,Ct,Vr=N*34+1,Ua=De[Vr];if(Ua)return N=Ua.nextPos,Ua.result;for(D=N,$=N,i.charCodeAt(N)===45?(W=d,N++):(W=s,Le===0&&Ie(we)),W===s&&(W=null),ue=[],ie.test(i.charAt(N))?(Se=i.charAt(N),N++):(Se=s,Le===0&&Ie(Ee));Se!==s;)ue.push(Se),ie.test(i.charAt(N))?(Se=i.charAt(N),N++):(Se=s,Le===0&&Ie(Ee));if(i.charCodeAt(N)===46?(Se=p,N++):(Se=s,Le===0&&Ie(Ae)),Se!==s){if(Ye=[],ie.test(i.charAt(N))?(Ct=i.charAt(N),N++):(Ct=s,Le===0&&Ie(Ee)),Ct!==s)for(;Ct!==s;)Ye.push(Ct),ie.test(i.charAt(N))?(Ct=i.charAt(N),N++):(Ct=s,Le===0&&Ie(Ee));else Ye=s;Ye!==s?(W=[W,ue,Se,Ye],$=W):(N=$,$=s)}else N=$,$=s;if($===s)if($=N,i.charCodeAt(N)===46?(W=p,N++):(W=s,Le===0&&Ie(Ae)),W!==s){if(ue=[],ie.test(i.charAt(N))?(Se=i.charAt(N),N++):(Se=s,Le===0&&Ie(Ee)),Se!==s)for(;Se!==s;)ue.push(Se),ie.test(i.charAt(N))?(Se=i.charAt(N),N++):(Se=s,Le===0&&Ie(Ee));else ue=s;ue!==s?(W=[W,ue],$=W):(N=$,$=s)}else N=$,$=s;return $!==s&&(_e=D,$=lt()),D=$,De[Vr]={nextPos:N,result:D},D}function ei(){var D,$,W=N*34+2,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,i.charCodeAt(N)===45?N++:Le===0&&Ie(we),ie.test(i.charAt(N))?($=i.charAt(N),N++):($=s,Le===0&&Ie(Ee)),$!==s?(_e=D,D=Zt()):(N=D,D=s),De[W]={nextPos:N,result:D},D)}function Ji(){var D,$,W=N*34+3,ue=De[W];return ue?(N=ue.nextPos,ue.result):(Le++,D=N,Oe.test(i.charAt(N))?($=i.charAt(N),N++):($=s,Le===0&&Ie(ke)),$!==s&&(_e=D,$=Tt()),D=$,Le--,D===s&&($=s,Le===0&&Ie(ce)),De[W]={nextPos:N,result:D},D)}function xa(){var D,$,W=N*34+7,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,xe.test(i.charAt(N))?($=i.charAt(N),N++):($=s,Le===0&&Ie(Je)),$!==s&&(_e=D,$=Ue()),D=$,De[W]={nextPos:N,result:D},D)}function ea(){var D,$=N*34+8,W=De[$];return W?(N=W.nextPos,W.result):(D=xa(),D===s&&(D=Da()),De[$]={nextPos:N,result:D},D)}function kn(){var D,$,W,ue=N*34+9,Se=De[ue];if(Se)return N=Se.nextPos,Se.result;if(D=N,$=[],W=Ni(),W===s&&(W=Qr(),W===s&&(W=ka(),W===s&&(W=ti(),W===s&&(W=gt(),W===s&&(W=Ri(),W===s&&(W=ri())))))),W!==s)for(;W!==s;)$.push(W),W=Ni(),W===s&&(W=Qr(),W===s&&(W=ka(),W===s&&(W=ti(),W===s&&(W=gt(),W===s&&(W=Ri(),W===s&&(W=ri()))))));else $=s;return $!==s&&(_e=D,$=Pr($)),D=$,De[ue]={nextPos:N,result:D},D}function ti(){var D,$,W,ue,Se,Ye=N*34+10,Ct=De[Ye];return Ct?(N=Ct.nextPos,Ct.result):(D=N,i.charCodeAt(N)===40?($=b,N++):($=s,Le===0&&Ie(rt)),$!==s?(i.charCodeAt(N)===58?N++:Le===0&&Ie(dt),W=kn(),W!==s?(ue=La(),ue===s&&(ue=null),i.charCodeAt(N)===41?(Se=A,N++):(Se=s,Le===0&&Ie(vt)),Se!==s?(_e=D,D=jn(W,ue)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Ye]={nextPos:N,result:D},D)}function La(){var D,$,W,ue=N*34+11,Se=De[ue];return Se?(N=Se.nextPos,Se.result):(D=N,i.charCodeAt(N)===58?($=y,N++):($=s,Le===0&&Ie(dt)),$!==s?(W=Mn(),W!==s?(_e=D,D=ot(W)):(N=D,D=s)):(N=D,D=s),De[ue]={nextPos:N,result:D},D)}function Qr(){var D,$,W,ue,Se=N*34+12,Ye=De[Se];return Ye?(N=Ye.nextPos,Ye.result):(D=N,$=ti(),$!==s?(W=ra(),W!==s?(ue=ti(),ue!==s?(_e=D,D=$r($,W,ue)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Se]={nextPos:N,result:D},D)}function gt(){var D,$,W,ue,Se,Ye=N*34+13,Ct=De[Ye];return Ct?(N=Ct.nextPos,Ct.result):(D=N,i.substr(N,2)===x?($=x,N+=2):($=s,Le===0&&Ie(ft)),$!==s?(W=kn(),W!==s?(ue=La(),ue===s&&(ue=null),i.charCodeAt(N)===93?(Se=U,N++):(Se=s,Le===0&&Ie(yt)),Se!==s?(_e=D,D=vr(W,ue)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Ye]={nextPos:N,result:D},D)}function ka(){var D,$,W,ue,Se=N*34+14,Ye=De[Se];return Ye?(N=Ye.nextPos,Ye.result):(D=N,i.charCodeAt(N)===91?($=Z,N++):($=s,Le===0&&Ie(Ft)),$!==s?(W=kn(),W!==s?(i.charCodeAt(N)===93?(ue=U,N++):(ue=s,Le===0&&Ie(yt)),ue!==s?(_e=D,D=Zi(W)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Se]={nextPos:N,result:D},D)}function Mn(){var D,$,W,ue=N*34+15,Se=De[ue];if(Se)return N=Se.nextPos,Se.result;if(D=N,i.charCodeAt(N)===45?N++:Le===0&&Ie(we),$=[],ie.test(i.charAt(N))?(W=i.charAt(N),N++):(W=s,Le===0&&Ie(Ee)),W!==s)for(;W!==s;)$.push(W),ie.test(i.charAt(N))?(W=i.charAt(N),N++):(W=s,Le===0&&Ie(Ee));else $=s;return $!==s?(_e=D,D=Ln()):(N=D,D=s),De[ue]={nextPos:N,result:D},D}function ta(){var D,$=N*34+16,W=De[$];return W?(N=W.nextPos,W.result):(D=Mn(),D===s&&(D=ei()),De[$]={nextPos:N,result:D},D)}function On(){var D,$,W,ue=N*34+17,Se=De[ue];if(Se)return N=Se.nextPos,Se.result;if(D=N,$=[],W=Ma(),W===s&&(W=ta()),W!==s)for(;W!==s;)$.push(W),W=Ma(),W===s&&(W=ta());else $=s;return $!==s&&(_e=D,$=Qt($)),D=$,De[ue]={nextPos:N,result:D},D}function Ma(){var D,$,W,ue,Se=N*34+18,Ye=De[Se];return Ye?(N=Ye.nextPos,Ye.result):(D=N,i.charCodeAt(N)===40?N++:Le===0&&Ie(rt),$=ta(),$!==s?(W=ra(),W!==s?(ue=On(),ue!==s?(i.charCodeAt(N)===41?N++:Le===0&&Ie(vt),_e=D,D=_n()):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Se]={nextPos:N,result:D},D)}function Ai(){var D,$,W,ue,Se=N*34+19,Ye=De[Se];if(Ye)return N=Ye.nextPos,Ye.result;if(D=N,i.charCodeAt(N)===123?($=f,N++):($=s,Le===0&&Ie(Gr)),$!==s){if(W=[],ue=On(),ue===s&&(ue=Ji()),ue!==s)for(;ue!==s;)W.push(ue),ue=On(),ue===s&&(ue=Ji());else W=s;W!==s?(i.charCodeAt(N)===125?(ue=E,N++):(ue=s,Le===0&&Ie(qe)),ue!==s?(_e=D,D=Ki(W)):(N=D,D=s)):(N=D,D=s)}else N=D,D=s;return De[Se]={nextPos:N,result:D},D}function ra(){var D,$=N*34+20,W=De[$];return W?(N=W.nextPos,W.result):(i.charCodeAt(N)===43?(D=S,N++):(D=s,Le===0&&Ie(kr)),D===s&&(i.charCodeAt(N)===45?(D=d,N++):(D=s,Le===0&&Ie(we)),D===s&&(i.charCodeAt(N)===42?(D=R,N++):(D=s,Le===0&&Ie(at)),D===s&&(i.charCodeAt(N)===47?(D=w,N++):(D=s,Le===0&&Ie(ze)),D===s&&(i.charCodeAt(N)===37?(D=k,N++):(D=s,Le===0&&Ie(Mr)),D===s&&(i.charCodeAt(N)===94?(D=L,N++):(D=s,Le===0&&Ie(Ht)),D===s&&(i.charCodeAt(N)===124?(D=_,N++):(D=s,Le===0&&Ie(Qe)),D===s&&(i.charCodeAt(N)===38?(D=F,N++):(D=s,Le===0&&Ie(Sr)),D===s&&(i.substr(N,2)===J?(D=J,N+=2):(D=s,Le===0&&Ie(z)),D===s&&(i.substr(N,2)===re?(D=re,N+=2):(D=s,Le===0&&Ie(me))))))))))),De[$]={nextPos:N,result:D},D)}function Ri(){var D,$,W=N*34+21,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,$=pr(),$===s&&($=na(),$===s&&($=ai(),$===s&&($=Pa(),$===s&&($=Ji(),$===s&&($=ii(),$===s&&($=Ii(),$===s&&($=Ba(),$===s&&($=ti(),$===s&&($=Ai(),$===s&&($=ys())))))))))),$!==s&&(_e=D,$=Ei($)),D=$,De[W]={nextPos:N,result:D},D)}function ys(){var D,$,W=N*34+22,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,i.charCodeAt(N)===124?($=_,N++):($=s,Le===0&&Ie(Qe)),$!==s&&(_e=D,$=ji()),D=$,De[W]={nextPos:N,result:D},D)}function ri(){var D,$,W,ue,Se=N*34+23,Ye=De[Se];return Ye?(N=Ye.nextPos,Ye.result):(D=N,i.charCodeAt(N)===60?($=te,N++):($=s,Le===0&&Ie(Ne)),$!==s?(W=kn(),W!==s?(i.charCodeAt(N)===62?(ue=ee,N++):(ue=s,Le===0&&Ie(Re)),ue!==s?(_e=D,D=an(W)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Se]={nextPos:N,result:D},D)}function Pa(){var D,$,W=N*34+24,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,$=ni(),$!==s&&(_e=D,$=Jn($)),D=$,De[W]={nextPos:N,result:D},D)}function ni(){var D,$,W,ue=N*34+25,Se=De[ue];if(Se)return N=Se.nextPos,Se.result;if(D=N,$=[],i.charCodeAt(N)===94?(W=L,N++):(W=s,Le===0&&Ie(Ht)),W===s&&(i.charCodeAt(N)===95?(W=M,N++):(W=s,Le===0&&Ie(je))),W!==s)for(;W!==s;)$.push(W),i.charCodeAt(N)===94?(W=L,N++):(W=s,Le===0&&Ie(Ht)),W===s&&(i.charCodeAt(N)===95?(W=M,N++):(W=s,Le===0&&Ie(je)));else $=s;return $!==s&&(_e=D,$=Sn()),D=$,De[ue]={nextPos:N,result:D},D}function Ii(){var D,$,W=N*34+26,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,i.charCodeAt(N)===63?($=G,N++):($=s,Le===0&&Ie(ve)),$!==s&&(_e=D,$=zt()),D=$,De[W]={nextPos:N,result:D},D)}function Ba(){var D,$,W,ue,Se,Ye,Ct=N*34+27,Vr=De[Ct];return Vr?(N=Vr.nextPos,Vr.result):(D=N,i.charCodeAt(N)===40?($=b,N++):($=s,Le===0&&Ie(rt)),$!==s?(W=ei(),W!==s?(i.charCodeAt(N)===44?(ue=m,N++):(ue=s,Le===0&&Ie(Xe)),ue!==s?(Se=ei(),Se!==s?(i.charCodeAt(N)===41?(Ye=A,N++):(Ye=s,Le===0&&Ie(vt)),Ye!==s?(_e=D,D=bi(W,Se)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Ct]={nextPos:N,result:D},D)}function Ni(){var D,$,W,ue,Se,Ye,Ct=N*34+28,Vr=De[Ct];return Vr?(N=Vr.nextPos,Vr.result):(D=N,$=Ri(),$!==s?(i.charCodeAt(N)===58?(W=y,N++):(W=s,Le===0&&Ie(dt)),W!==s?(ue=Mn(),ue!==s?(Se=N,Le++,i.charCodeAt(N)===41?(Ye=A,N++):(Ye=s,Le===0&&Ie(vt)),Ye===s&&(i.charCodeAt(N)===93?(Ye=U,N++):(Ye=s,Le===0&&Ie(yt))),Le--,Ye===s?Se=void 0:(N=Se,Se=s),Se!==s?(_e=D,D=Ti($,ue)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s)):(N=D,D=s),De[Ct]={nextPos:N,result:D},D)}function ii(){var D,$,W=N*34+29,ue=De[W];return ue?(N=ue.nextPos,ue.result):(D=N,$=ea(),$!==s&&(_e=D,$=Q($)),D=$,De[W]={nextPos:N,result:D},D)}function pr(){var D,$,W,ue=N*34+30,Se=De[ue];return Se?(N=Se.nextPos,Se.result):(D=N,$=ea(),$===s&&($=null),i.charCodeAt(N)===114?(W=K,N++):(W=s,Le===0&&Ie($t)),W!==s?(_e=D,D=ne($)):(N=D,D=s),De[ue]={nextPos:N,result:D},D)}function ai(){var D,$,W,ue,Se,Ye=N*34+31,Ct=De[Ye];return Ct?(N=Ct.nextPos,Ct.result):(D=N,$=ni(),$===s&&($=null),W=ea(),W===s&&(W=null),ue=qr(),ue===s&&(ue=null),Se=ei(),Se!==s?(_e=D,D=le($,W,ue,Se)):(N=D,D=s),De[Ye]={nextPos:N,result:D},D)}function qr(){var D,$,W,ue=N*34+32,Se=De[ue];if(Se)return N=Se.nextPos,Se.result;if(D=N,$=[],i.charCodeAt(N)===35?(W=X,N++):(W=s,Le===0&&Ie(st)),W===s&&(i.charCodeAt(N)===98?(W=oe,N++):(W=s,Le===0&&Ie(bt))),W!==s)for(;W!==s;)$.push(W),i.charCodeAt(N)===35?(W=X,N++):(W=s,Le===0&&Ie(st)),W===s&&(i.charCodeAt(N)===98?(W=oe,N++):(W=s,Le===0&&Ie(bt)));else $=s;return $!==s&&(_e=D,$=he($)),D=$,De[ue]={nextPos:N,result:D},D}function na(){var D,$,W,ue,Se=N*34+33,Ye=De[Se];if(Ye)return N=Ye.nextPos,Ye.result;if(D=N,$=ai(),$!==s){if(W=[],ue=ai(),ue!==s)for(;ue!==s;)W.push(ue),ue=ai();else W=s;W!==s?(_e=D,D=Te($,W)):(N=D,D=s)}else N=D,D=s;return De[Se]={nextPos:N,result:D},D}var As=a.nodeOptions||{};function jt(D,$,W=void 0){$.text=W||Kt(),$.location=Ts();for(var ue in As)($[ue]===void 0||$[ue]===null)&&($[ue]=As[ue]);return new D($)}if(Ci=c(),Ci!==s&&N===i.length)return Ci;throw Ci!==s&&Ne.collect("pitch"))}notes(){return this.evaluated.map(e=>e.collect("note"))}freqs(){return this.evaluated.map(e=>e.collect("freq"))}durations(){return this.evaluated.map(e=>e.collect("duration"))}retrograde(){return this.evaluated=this.evaluated.reverse(),this}scale(e){return this.applyOptions({scale:e}),this}key(e){return this.applyOptions({key:e}),this}octave(e){return this.applyOptions({octave:e}),this}isInOptions(e,t){return this.options.nodeOptions&&this.options.nodeOptions[e]===t}atLast(){return this.index+1>=this.evaluated.length*this.redo}clone(){return bo(this)}notStarted(){return this.index<0}peek(){return this.evaluated[this.index-1||0]}hasStarted(){return this.index>=0}next(){this.index<0&&(this.index=0);const e=this.evaluated[this.index%this.evaluated.length];return this.index++,this.counter++,this.redo>0&&this.index>=this.evaluated.length*this.redo&&(this.index=0,this.evaluated=this.evaluate(this.values)),e}applyOptions(e={}){this.evaluated=this.evaluate(this.evaluated,e),this.applyTransformations()}applyTransformations(){var e;(e=this.globalOptions)!=null&&e.retrograde&&(this.evaluated=this.evaluated.reverse())}evaluate(e,t={}){let r=e.map(i=>i.evaluate(t)).flat(1/0).filter(i=>i!==void 0);if(t.subdivisions){const i=t.duration?t.duration:vO.duration;r=LA(r,i)}return r}totalDuration(){return this.evaluated.reduce((t,r)=>t+r.collect("duration"),0)}}const LA=(n,e)=>{const t=n.length,r=e/t;return n.map(a=>a instanceof DA?LA(a.items,r):(a.duration=r,a)).flat(1/0)},aP=n=>{let e={};return KM.forEach(t=>{if(n[t]!==void 0){const r=n[t];e[t]=r,delete n[t]}}),e};class sP{constructor(){v(this,"midiAccess",null);v(this,"midiOutputs",[]);v(this,"currentOutputIndex",0);v(this,"scheduledNotes",{});this.initializeMidiAccess()}async initializeMidiAccess(){try{this.midiAccess=await navigator.requestMIDIAccess(),this.midiOutputs=Array.from(this.midiAccess.outputs.values()),this.midiOutputs.length===0&&(console.warn("No MIDI outputs available."),this.currentOutputIndex=-1)}catch(e){console.error("Failed to initialize MIDI:",e)}}getCurrentMidiPort(){return this.midiOutputs.length>0&&this.currentOutputIndex>=0&&this.currentOutputIndex0&&this.currentOutputIndex>=0&&this.currentOutputIndex=this.midiOutputs.length?(console.error(`Invalid MIDI output index. Index must be in the range 0-${this.midiOutputs.length-1}.`),this.currentOutputIndex):e;{const t=this.midiOutputs.findIndex(r=>r.name===e);return t!==-1?t:(console.error(`MIDI output "${e}" not found.`),this.currentOutputIndex)}}listMidiOutputs(){let e="Available MIDI Outputs: ";return this.midiOutputs.forEach((t,r)=>{e+=`(${r+1}) ${t.name} `}),e}sendMidiNote(e,t,r,i,a=this.currentOutputIndex,s=void 0){typeof a=="string"&&(a=this.getMidiOutputIndex(a));const o=this.midiOutputs[a];if(e=Math.min(Math.max(e,0),127),o){const l=[144+t,e,r],c=[128+t,e,0];o.send(l),s&&this.sendPitchBend(s,t,a);const d=setTimeout(()=>{o.send(c),s&&this.sendPitchBend(8192,t,a),delete this.scheduledNotes[e]},(i-.02)*1e3);this.scheduledNotes[e]=d}else console.error("MIDI output not available.")}sendSysExMessage(e){const t=this.midiOutputs[this.currentOutputIndex];t?t.send(e):console.error("MIDI output not available.")}sendPitchBend(e,t,r=this.currentOutputIndex){(e<0||e>16383)&&console.error("Invalid pitch bend value. Value must be in the range 0-16383."),(t<0||t>15)&&console.error("Invalid MIDI channel. Channel must be in the range 0-15."),typeof r=="string"&&(r=this.getMidiOutputIndex(r));const i=this.midiOutputs[r];if(i){const a=e&127,s=e>>7&127;i.send([224|t,a,s])}else console.error("MIDI output not available.")}sendProgramChange(e,t){const r=this.midiOutputs[this.currentOutputIndex];r?r.send([192+t,e]):console.error("MIDI output not available.")}sendMidiControlChange(e,t,r){const i=this.midiOutputs[this.currentOutputIndex];i?i.send([176+r,e,t]):console.error("MIDI output not available.")}panic(){const e=this.midiOutputs[this.currentOutputIndex];if(e){for(const t in this.scheduledNotes){const r=this.scheduledNotes[t];clearTimeout(r),e.send([128,parseInt(t),0])}this.scheduledNotes={}}else console.error("MIDI output not available.")}}class oP{constructor(e,t,r){v(this,"min");v(this,"max");v(this,"wrap");v(this,"position");this.min=e,this.max=t,this.wrap=r,this.position=0}step(){const e=Math.floor(Math.random()*3)-1;this.position+=e,this.wrap?this.position>this.max?this.position=this.min:this.positionthis.max&&(this.position=this.max)}getPosition(){return this.position}toggleWrap(e){this.wrap=e}}const lP={major:[0,2,4,5,7,9,11],naturalMinor:[0,2,3,5,7,8,10],harmonicMinor:[0,2,3,5,7,8,11],melodicMinor:[0,2,3,5,7,9,11],dorian:[0,2,3,5,7,9,10],phrygian:[0,1,3,5,7,8,10],lydian:[0,2,4,6,7,9,11],mixolydian:[0,2,4,5,7,9,10],aeolian:[0,2,3,5,7,8,10],locrian:[0,1,3,5,6,8,10],wholeTone:[0,2,4,6,8,10],majorPentatonic:[0,2,4,7,9],minorPentatonic:[0,3,5,7,10],chromatic:[0,1,2,3,4,5,6,7,8,9,10,11],blues:[0,3,5,6,7,10],diminished:[0,2,3,5,6,8,9,11],neapolitanMinor:[0,1,3,5,7,8,11],neapolitanMajor:[0,1,3,5,7,9,11],enigmatic:[0,1,4,6,8,10,11],doubleHarmonic:[0,1,4,5,7,8,11],octatonic:[0,2,3,5,6,8,9,11],bebopDominant:[0,2,4,5,7,9,10,11],bebopMajor:[0,2,4,5,7,8,9,11],bebopMinor:[0,2,3,5,7,8,9,11],bebopDorian:[0,2,3,4,5,7,9,10],harmonicMajor:[0,2,4,5,7,8,11],hungarianMinor:[0,2,3,6,7,8,11],hungarianMajor:[0,3,4,6,7,9,10],oriental:[0,1,4,5,6,9,10],romanianMinor:[0,2,3,6,7,9,10],spanishGypsy:[0,1,4,5,7,8,10],jewish:[0,1,4,5,7,8,10],hindu:[0,2,4,5,7,8,10],japanese:[0,1,5,7,8],hirajoshi:[0,2,3,7,8],kumoi:[0,2,3,7,9],inSen:[0,1,5,7,10],iwato:[0,1,5,6,10],yo:[0,2,5,7,9],minorBlues:[0,3,5,6,7,10],algerian:[0,2,3,5,6,7,8,11],augmented:[0,3,4,7,8,11],balinese:[0,1,3,7,8],byzantine:[0,1,4,5,7,8,11],chinese:[0,4,6,7,11],egyptian:[0,2,5,7,10],eightToneSpanish:[0,1,3,4,5,6,8,10],hawaiian:[0,2,3,5,7,9,10],hindustan:[0,2,4,5,7,8,10],persian:[0,1,4,5,6,8,11],eastIndianPurvi:[0,1,4,6,7,8,11],orientalA:[0,1,4,5,6,9,10]};function cP(n,e="major",t=4){const r=lP[e];if(!r)throw new Error(`Unknown scale ${e}`);let i=n%r.length;i<0&&(i+=r.length);let a=Math.floor(n/r.length);return 60+(t+a)*12+r[i]}class Eg{constructor(e){v(this,"seedValue");v(this,"randomGen",Math.random);v(this,"app");v(this,"values",{});v(this,"odds",(e,t)=>this.randomGen()this.odds(.025,e));v(this,"rarely",e=>this.odds(.1,e));v(this,"scarcely",e=>this.odds(.25,e));v(this,"sometimes",e=>this.odds(.5,e));v(this,"often",e=>this.odds(.75,e));v(this,"frequently",e=>this.odds(.9,e));v(this,"almostAlways",e=>this.odds(.985,e));v(this,"modify",e=>e(this));v(this,"seed",e=>(this.seedValue=e.toString(),this.randomGen=this.app.api.localSeededRandom(this.seedValue),this));v(this,"clear",()=>(this.app.api.clearLocalSeed(this.seedValue),this));v(this,"apply",e=>this.modify(e));v(this,"length",e=>(this.values.length=e,this));this.app=e,this.app.api.currentSeed&&(this.randomGen=this.app.api.randomGen)}}class kA extends Eg{constructor(t){super(t);v(this,"octave",t=>(this.values.octave=t,this.update(),this));v(this,"key",t=>(this.values.key=t,this.update(),this));v(this,"scale",t=>(gg(t)?(this.values.scaleName=t,this.values.parsedScale=ya(t)):this.values.parsedScale=_g(t),this.update(),this));v(this,"freq",t=>{this.values.freq=t;const r=$M(t);return r%1!==0?(this.values.note=Math.floor(r),this.values.bend=NA(r)[1]):this.values.note=r,this});v(this,"update",()=>{})}}let Ir=[],uP=(n,e)=>{let t,r=[],i={lc:0,l:e||0,value:n,set(a){i.value=a,i.notify()},get(){return i.lc||i.listen(()=>{})(),i.value},notify(a){t=r;let s=!Ir.length;for(let o=0;o{r===t&&(r=r.slice());let o=r.indexOf(a);~o&&(r.splice(o,2),i.lc--,i.lc||i.off())}},subscribe(a,s){let o=i.listen(a,s);return a(i.value),o},off(){}};return i},dP=(n={})=>{let e=uP(n);return e.setKey=function(t,r){typeof r>"u"?t in e.value&&(e.value={...e.value},delete e.value[t],e.notify(t)):e.value[t]!==r&&(e.value={...e.value,[t]:r},e.notify(t))},e};if(typeof DelayNode<"u"){class n extends DelayNode{constructor(t,r,i,a){super(t),r=Math.abs(r),this.delayTime.value=i;const s=t.createGain();s.gain.value=Math.min(Math.abs(a),.995),this.feedback=s.gain;const o=t.createGain();return o.gain.value=r,this.delayGain=o,this.connect(s),this.connect(o),s.connect(this),this.connect=l=>o.connect(l),this}start(t){this.delayGain.gain.setValueAtTime(this.delayGain.gain.value,t+this.delayTime.value)}}AudioContext.prototype.createFeedbackDelay=function(e,t,r){return new n(this,e,t,r)}}typeof AudioContext<"u"&&(AudioContext.prototype.impulseResponse=function(n,e=1){const t=this.sampleRate*n,r=this.createBuffer(e,t,this.sampleRate),i=r.getChannelData(0);for(let a=0;a(e.buffer=this.impulseResponse(t),e.duration=n,e),e.setDuration(n),e});var IO={a:{freqs:[660,1120,2750,3e3,3350],gains:[1,.5012,.0708,.0631,.0126],qs:[80,90,120,130,140]},e:{freqs:[440,1800,2700,3e3,3300],gains:[1,.1995,.1259,.1,.1],qs:[70,80,100,120,120]},i:{freqs:[270,1850,2900,3350,3590],gains:[1,.0631,.0631,.0158,.0158],qs:[40,90,100,120,120]},o:{freqs:[430,820,2700,3e3,3300],gains:[1,.3162,.0501,.0794,.01995],qs:[40,80,100,120,120]},u:{freqs:[370,630,2750,3e3,3400],gains:[1,.1,.0708,.0316,.01995],qs:[40,60,100,120,120]}};if(typeof GainNode<"u"){class n extends GainNode{constructor(t,r){if(super(t),!IO[r])throw new Error("vowel: unknown vowel "+r);const{gains:i,qs:a,freqs:s}=IO[r],o=t.createGain();for(let l=0;l<5;l++){const c=t.createGain();c.gain.value=i[l];const d=t.createBiquadFilter();d.type="bandpass",d.Q.value=a[l],d.frequency.value=s[l],this.connect(d),d.connect(c),c.connect(o)}return o.gain.value=8,this.connect=l=>o.connect(l),this}}AudioContext.prototype.createVowelFilter=function(e){return new n(this,e)}}const pP=n=>{var i;if(typeof n!="string")return[];const[e,t="",r]=((i=n.match(/^([a-gA-G])([#bsf]*)([0-9]*)$/))==null?void 0:i.slice(1))||[];return e?[e,t,r?Number(r):void 0]:[]},fP={c:0,d:2,e:4,f:5,g:7,a:9,b:11},hP={"#":1,b:-1,s:1,f:-1},yc=(n,e=3)=>{const[t,r,i=e]=pP(n);if(!t)throw new Error('not a note: "'+n+'"');const a=fP[t.toLowerCase()],s=(r==null?void 0:r.split("").reduce((o,l)=>o+hP[l],0))||0;return(Number(i)+1)*12+a+s},MA=n=>Math.pow(2,(n-69)/12)*440,mP=(n,e,t)=>Math.min(Math.max(n,e),t),gP=n=>12*Math.log(n/440)/Math.LN2+69,_P=(n,e)=>{if(typeof n!="object")throw new Error("valueToMidi: expected object value");let{freq:t,note:r}=n;if(typeof t=="number")return gP(t);if(typeof r=="string")return yc(r);if(typeof r=="number")return r;if(!e)throw new Error("valueToMidi: expected freq or note to be set");return e},SP="data:application/javascript;base64,Ly8gTElDRU5TRSBHTlUgR2VuZXJhbCBQdWJsaWMgTGljZW5zZSB2My4wIHNlZSBodHRwczovL2dpdGh1Yi5jb20vZGt0cjAvV2ViRGlydC9ibG9iL21haW4vTElDRU5TRQovLyBhbGwgdGhlIGNyZWRpdCBnb2VzIHRvIGRrdHIwJ3Mgd2ViZGlydDogaHR0cHM6Ly9naXRodWIuY29tL2RrdHIwL1dlYkRpcnQvYmxvYi81Y2UzZDY5ODM2MmM1NGQ2ZTFiNjhhY2M0N2ViMjk1NWFjNjJjNzkzL2Rpc3QvQXVkaW9Xb3JrbGV0cy5qcwovLyA8MwoKY2xhc3MgQ29hcnNlUHJvY2Vzc29yIGV4dGVuZHMgQXVkaW9Xb3JrbGV0UHJvY2Vzc29yIHsKICBzdGF0aWMgZ2V0IHBhcmFtZXRlckRlc2NyaXB0b3JzKCkgewogICAgcmV0dXJuIFt7IG5hbWU6ICdjb2Fyc2UnLCBkZWZhdWx0VmFsdWU6IDEgfV07CiAgfQoKICBjb25zdHJ1Y3RvcigpIHsKICAgIHN1cGVyKCk7CiAgICB0aGlzLm5vdFN0YXJ0ZWQgPSB0cnVlOwogIH0KCiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgY29uc3Qgb3V0cHV0ID0gb3V0cHV0c1swXTsKICAgIGNvbnN0IGNvYXJzZSA9IHBhcmFtZXRlcnMuY29hcnNlOwogICAgY29uc3QgYmxvY2tTaXplID0gMTI4OwogICAgY29uc3QgaGFzSW5wdXQgPSAhKGlucHV0WzBdID09PSB1bmRlZmluZWQpOwogICAgaWYgKGhhc0lucHV0KSB7CiAgICAgIHRoaXMubm90U3RhcnRlZCA9IGZhbHNlOwogICAgICBvdXRwdXRbMF1bMF0gPSBpbnB1dFswXVswXTsKICAgICAgZm9yIChsZXQgbiA9IDE7IG4gPCBibG9ja1NpemU7IG4rKykgewogICAgICAgIGZvciAobGV0IG8gPSAwOyBvIDwgb3V0cHV0Lmxlbmd0aDsgbysrKSB7CiAgICAgICAgICBvdXRwdXRbb11bbl0gPSBuICUgY29hcnNlID09IDAgPyBpbnB1dFswXVtuXSA6IG91dHB1dFtvXVtuIC0gMV07CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICByZXR1cm4gdGhpcy5ub3RTdGFydGVkIHx8IGhhc0lucHV0OwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoJ2NvYXJzZS1wcm9jZXNzb3InLCBDb2Fyc2VQcm9jZXNzb3IpOwoKY2xhc3MgQ3J1c2hQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogIHN0YXRpYyBnZXQgcGFyYW1ldGVyRGVzY3JpcHRvcnMoKSB7CiAgICByZXR1cm4gW3sgbmFtZTogJ2NydXNoJywgZGVmYXVsdFZhbHVlOiAwIH1dOwogIH0KCiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5ub3RTdGFydGVkID0gdHJ1ZTsKICB9CgogIHByb2Nlc3MoaW5wdXRzLCBvdXRwdXRzLCBwYXJhbWV0ZXJzKSB7CiAgICBjb25zdCBpbnB1dCA9IGlucHV0c1swXTsKICAgIGNvbnN0IG91dHB1dCA9IG91dHB1dHNbMF07CiAgICBjb25zdCBjcnVzaCA9IHBhcmFtZXRlcnMuY3J1c2g7CiAgICBjb25zdCBibG9ja1NpemUgPSAxMjg7CiAgICBjb25zdCBoYXNJbnB1dCA9ICEoaW5wdXRbMF0gPT09IHVuZGVmaW5lZCk7CiAgICBpZiAoaGFzSW5wdXQpIHsKICAgICAgdGhpcy5ub3RTdGFydGVkID0gZmFsc2U7CiAgICAgIGlmIChjcnVzaC5sZW5ndGggPT09IDEpIHsKICAgICAgICBjb25zdCB4ID0gTWF0aC5wb3coMiwgY3J1c2hbMF0gLSAxKTsKICAgICAgICBmb3IgKGxldCBuID0gMDsgbiA8IGJsb2NrU2l6ZTsgbisrKSB7CiAgICAgICAgICBjb25zdCB2YWx1ZSA9IE1hdGgucm91bmQoaW5wdXRbMF1bbl0gKiB4KSAvIHg7CiAgICAgICAgICBmb3IgKGxldCBvID0gMDsgbyA8IG91dHB1dC5sZW5ndGg7IG8rKykgewogICAgICAgICAgICBvdXRwdXRbb11bbl0gPSB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yIChsZXQgbiA9IDA7IG4gPCBibG9ja1NpemU7IG4rKykgewogICAgICAgICAgbGV0IHggPSBNYXRoLnBvdygyLCBjcnVzaFtuXSAtIDEpOwogICAgICAgICAgY29uc3QgdmFsdWUgPSBNYXRoLnJvdW5kKGlucHV0WzBdW25dICogeCkgLyB4OwogICAgICAgICAgZm9yIChsZXQgbyA9IDA7IG8gPCBvdXRwdXQubGVuZ3RoOyBvKyspIHsKICAgICAgICAgICAgb3V0cHV0W29dW25dID0gdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICByZXR1cm4gdGhpcy5ub3RTdGFydGVkIHx8IGhhc0lucHV0OwogIH0KfQpyZWdpc3RlclByb2Nlc3NvcignY3J1c2gtcHJvY2Vzc29yJywgQ3J1c2hQcm9jZXNzb3IpOwoKY2xhc3MgU2hhcGVQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogIHN0YXRpYyBnZXQgcGFyYW1ldGVyRGVzY3JpcHRvcnMoKSB7CiAgICByZXR1cm4gW3sgbmFtZTogJ3NoYXBlJywgZGVmYXVsdFZhbHVlOiAwIH1dOwogIH0KCiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5ub3RTdGFydGVkID0gdHJ1ZTsKICB9CgogIHByb2Nlc3MoaW5wdXRzLCBvdXRwdXRzLCBwYXJhbWV0ZXJzKSB7CiAgICBjb25zdCBpbnB1dCA9IGlucHV0c1swXTsKICAgIGNvbnN0IG91dHB1dCA9IG91dHB1dHNbMF07CiAgICBjb25zdCBzaGFwZTAgPSBwYXJhbWV0ZXJzLnNoYXBlWzBdOwogICAgY29uc3Qgc2hhcGUxID0gc2hhcGUwIDwgMSA/IHNoYXBlMCA6IDEuMCAtIDRlLTEwOwogICAgY29uc3Qgc2hhcGUgPSAoMi4wICogc2hhcGUxKSAvICgxLjAgLSBzaGFwZTEpOwogICAgY29uc3QgYmxvY2tTaXplID0gMTI4OwogICAgY29uc3QgaGFzSW5wdXQgPSAhKGlucHV0WzBdID09PSB1bmRlZmluZWQpOwogICAgaWYgKGhhc0lucHV0KSB7CiAgICAgIHRoaXMubm90U3RhcnRlZCA9IGZhbHNlOwogICAgICBmb3IgKGxldCBuID0gMDsgbiA8IGJsb2NrU2l6ZTsgbisrKSB7CiAgICAgICAgY29uc3QgdmFsdWUgPSAoKDEgKyBzaGFwZSkgKiBpbnB1dFswXVtuXSkgLyAoMSArIHNoYXBlICogTWF0aC5hYnMoaW5wdXRbMF1bbl0pKTsKICAgICAgICBmb3IgKGxldCBvID0gMDsgbyA8IG91dHB1dC5sZW5ndGg7IG8rKykgewogICAgICAgICAgb3V0cHV0W29dW25dID0gdmFsdWU7CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICByZXR1cm4gdGhpcy5ub3RTdGFydGVkIHx8IGhhc0lucHV0OwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoJ3NoYXBlLXByb2Nlc3NvcicsIFNoYXBlUHJvY2Vzc29yKTsK";function sc(n){const e=Xt().createGain();return e.gain.value=n,e}const cm=(n,e,t,r,i,a)=>{const s=Xt().createGain();return s.gain.setValueAtTime(0,a),s.gain.linearRampToValueAtTime(i,a+n),s.gain.linearRampToValueAtTime(t*i,a+n+e),{node:s,stop:o=>{s.gain.setValueAtTime(t*i,o),s.gain.linearRampToValueAtTime(0,o+r)}}},OP=(n,e,t,r,i,a)=>{t=Math.max(.001,t),i=Math.max(.001,i);const s=Xt().createGain();return s.gain.setValueAtTime(1e-4,a),s.gain.exponentialRampToValueAtTime(i,a+n),s.gain.exponentialRampToValueAtTime(t*i,a+n+e),{node:s,stop:o=>{s.gain.exponentialRampToValueAtTime(1e-4,o+r)}}},fu=(n,e,t)=>{const r=Xt().createBiquadFilter();return r.type=n,r.frequency.value=e,r.Q.value=t,r};let EP=n=>console.log(n);const _s=(...n)=>EP(...n),bg=dP();function Tg(n,e,t={}){bg.setKey(n,{onTrigger:e,data:t})}function NO(n){return bg.get()[n]}let hu;const Xt=()=>(hu||(hu=new AudioContext),hu);let cl;const Cg=()=>{const n=Xt();return cl||(cl=n.createGain(),cl.connect(n.destination)),cl};let mu;function bP(){return mu||(mu=Xt().audioWorklet.addModule(SP),mu)}function gu(n,e,t){const r=new AudioWorkletNode(n,e);return Object.entries(t).forEach(([i,a])=>{r.parameters.get(i).value=a}),r}async function TP(n={}){const{disableWorklets:e=!1}=n;typeof window<"u"&&(await Xt().resume(),e?console.log("disableWorklets: AudioWorklet effects coarse, crush and shape are skipped!"):await bP().catch(t=>{console.warn("could not load AudioWorklet effects coarse, crush and shape",t)}))}async function CP(n){return new Promise(e=>{document.addEventListener("click",async function t(){await TP(n),e(),document.removeEventListener("click",t)})})}let sa={};function vP(n,e,t,r){var i;if(t=mP(t,0,.98),!sa[n]){const a=Xt().createFeedbackDelay(1,e,t);(i=a.start)==null||i.call(a,r),a.connect(Cg()),sa[n]=a}return sa[n].delayTime.value!==e&&sa[n].delayTime.setValueAtTime(e,r),sa[n].feedback.value!==t&&sa[n].feedback.setValueAtTime(t,r),sa[n]}let oa={};function yP(n,e=2){if(!oa[n]){const t=Xt().createReverb(e);t.connect(Cg()),oa[n]=t}return oa[n].duration!==e&&(oa[n]=oa[n].setDuration(e),oa[n].duration=e),oa[n]}let la;function AP(n=2048){if(!la){const e=Xt().createAnalyser();e.fftSize=n,la=e,new Float32Array(la.frequencyBinCount)}return la.fftSize!==n&&(la.fftSize=n,new Float32Array(la.frequencyBinCount)),la}function _u(n,e,t){const r=sc(t);return n.connect(r),r.connect(e),r}const RP=async(n,e,t)=>{const r=Xt();if(typeof n!="object")throw new Error(`expected hap.value to be an object, but got "${n}". Hint: append .note() or .s() to the end`,"error");n.duration=t;let i=r.currentTime+e,{s:a="triangle",bank:s,source:o,gain:l=.8,cutoff:c,resonance:d=1,hcutoff:p,hresonance:m=1,bandf:_,bandq:b=1,coarse:y,crush:A,shape:x,pan:U,vowel:Z,delay:f=0,delayfeedback:E=.5,delaytime:S=.25,orbit:R=1,room:w,size:k=2,velocity:L=1,analyze:F,fft:J=8}=n;l*=L;let re=[];const te=()=>{re.forEach(ie=>ie==null?void 0:ie.disconnect())};s&&a&&(a=`${s}_${a}`);let ee;if(o)ee=o(i,n,t);else if(NO(a)){const{onTrigger:ie}=NO(a),Oe=await ie(i,n,te);Oe&&(ee=Oe.node,Oe.stop(i+t))}else throw new Error(`sound ${a} not found! Is it loaded?`);if(!ee)return;if(r.currentTime>i){_s("[webaudio] skip hap: still loading",r.currentTime-i);return}const M=[];if(M.push(ee),M.push(sc(l)),c!==void 0&&M.push(fu("lowpass",c,d)),p!==void 0&&M.push(fu("highpass",p,m)),_!==void 0&&M.push(fu("bandpass",_,b)),Z!==void 0&&M.push(r.createVowelFilter(Z)),y!==void 0&&M.push(gu(r,"coarse-processor",{coarse:y})),A!==void 0&&M.push(gu(r,"crush-processor",{crush:A})),x!==void 0&&M.push(gu(r,"shape-processor",{shape:x})),U!==void 0){const ie=r.createStereoPanner();ie.pan.value=2*U-1,M.push(ie)}const G=sc(1);M.push(G),G.connect(Cg());let K;if(f>0&&S>0&&E>0){const ie=vP(R,S,E,i);K=_u(G,ie,f)}let X;if(w>0&&k>0){const ie=yP(R,k);X=_u(G,ie,w)}let oe;if(F){const ie=AP(2**(J+5));oe=_u(G,ie,F)}M.slice(1).reduce((ie,Oe)=>ie.connect(Oe),M[0]),re=M.concat([K,X,oe])},Su={};function IP(n,e){var t=e?1e3:1024;if(n=t);return n.toFixed(1)+" "+r[i]}const NP=async(n,e,t,r,i,a,s)=>{let o=0;i!==void 0&&t!==void 0&&_s("[sampler] hap has note and freq. ignoring note","warning");let l=_P({freq:i,note:t},36);o=l-36;const c=Xt();let d;if(Array.isArray(a))d=a[e%a.length];else{const b=A=>yc(A)-l,y=Object.keys(a).filter(A=>!A.startsWith("_")).reduce((A,x,U)=>!A||Math.abs(b(x)){const i=t?`sound "${t}:${r}"`:"sample";if(!Su[n]){_s(`[sampler] load ${i}..`,"load-sample",{url:n});const a=Date.now();Su[n]=fetch(n).then(s=>s.arrayBuffer()).then(async s=>{const o=Date.now()-a,l=IP(s.byteLength);return _s(`[sampler] load ${i}... done! loaded ${l} in ${o}ms`,"loaded-sample",{url:n}),await e.decodeAudioData(s)})}return Su[n]};function DP(n){const e=Xt(),t=e.createBuffer(n.numberOfChannels,n.length,e.sampleRate);for(let r=0;rObject.entries(n).forEach(([r,i])=>{if(typeof i=="string"&&(i=[i]),typeof i!="object")throw new Error("wrong sample map format for "+r);t=i._base||t;const a=s=>(t+s).replace("github:","https://raw.githubusercontent.com/");Array.isArray(i)?i=i.map(a):i=Object.fromEntries(Object.entries(i).map(([s,o])=>[s,(typeof o=="string"?[o]:o).map(a)])),e(r,i)});let LP={};function kP(n){const e=Object.entries(LP).find(([t])=>n.startsWith(t));if(e)return e[1]}const Js=async(n,e=n._base||"",t={})=>{if(typeof n=="string"){const a=kP(n);if(a)return a(n);if(n.startsWith("github:")){let[o,l]=n.split("github:");l=l.endsWith("/")?l.slice(0,-1):l,n=`https://raw.githubusercontent.com/${l}/strudel.json`}if(typeof fetch!="function")return;const s=n.split("/").slice(0,-1).join("/");return typeof fetch>"u"?void 0:fetch(n).then(o=>o.json()).then(o=>Js(o,e||o._base||s,t)).catch(o=>{throw console.error(o),new Error(`error loading "${n}"`)})}const{prebake:r,tag:i}=t;xP(n,(a,s)=>Tg(a,(o,l,c)=>MP(o,l,c,s),{type:"sample",samples:s,baseUrl:e,prebake:r,tag:i}),e)},wO=[];async function MP(n,e,t,r,i){const{s:a,freq:s,unit:o,nudge:l=0,cut:c,loop:d,clip:p=void 0,n:m=0,note:_,speed:b=1,begin:y=0,end:A=1}=e;if(b===0)return;const x=Xt(),{attack:U=.001,decay:Z=.001,sustain:f=1,release:E=.001}=e,S=n+l,R=await NP(a,m,_,b,s,r,i);if(x.currentTime>n){_s(`[sampler] still loading sound "${a}:${m}"`,"highlight");return}if(!R){_s(`[sampler] could not load "${a}:${m}"`,"error");return}R.playbackRate.value=Math.abs(b)*R.playbackRate.value,o==="c"&&(R.playbackRate.value=R.playbackRate.value*R.buffer.duration*1);const w=y*R.buffer.duration;R.start(S,w);const k=R.buffer.duration/R.playbackRate.value,{node:L,stop:F}=cm(U,Z,f,E,1,n);R.connect(L);const J=x.createGain();L.connect(J),R.onended=function(){R.disconnect(),L.disconnect(),J.disconnect(),t()};const re={node:J,bufferSource:R,stop:(te,ee=p===void 0)=>{let M=te;ee&&(M=n+(A-y)*k),R.stop(M+E),F(M)}};if(c!==void 0){const te=wO[c];te&&(te.node.gain.setValueAtTime(1,S),te.node.gain.linearRampToValueAtTime(0,S+.01)),wO[c]=re}return re}const PP=(n,e=1,t="sine")=>{const r=Xt(),i=r.createOscillator();i.type=t,i.frequency.value=n,i.start();const a=new GainNode(r,{gain:e});return i.connect(a),{node:a,stop:s=>i.stop(s)}},BP=(n,e,t,r="sine")=>{const i=n.frequency.value*e,a=i*t;return PP(i,a,r)};function UP(){["sine","square","triangle","sawtooth"].forEach(n=>{Tg(n,(e,t,r)=>{let{attack:i=.001,decay:a=.05,sustain:s=.6,release:o=.01,fmh:l=1,fmi:c,fmenv:d="lin",fmattack:p,fmdecay:m,fmsustain:_,fmrelease:b,fmvelocity:y,fmwave:A="sine"}=t,{n:x,note:U,freq:Z}=t;U=U||36,typeof U=="string"&&(U=yc(U)),!Z&&typeof U=="number"&&(Z=MA(U));const{node:f,stop:E}=YP({t:e,s:n,freq:Z,partials:x});let S,R;if(c){const{node:F,stop:J}=BP(f,l,c,A);[p,m,_,b,y].find(re=>re!==void 0)?(p=p??.001,m=m??.001,_=_??1,b=b??.001,y=y??1,R=cm(p,m,_,b,y,e),d==="exp"&&(R=OP(p,m,_,b,y,e),R.node.maxValue=c*2,R.node.minValue=1e-5),F.connect(R.node),R.node.connect(f.frequency)):F.connect(f.frequency),S=J}const w=sc(.3),{node:k,stop:L}=cm(i,a,s,o,1,e);return f.onended=()=>{f.disconnect(),w.disconnect(),r()},{node:f.connect(w).connect(k),stop:F=>{L(F),R==null||R.stop(F);let J=F+o;E(J),S==null||S(J)}}},{type:"synth",prebake:!0})})}function FP(n,e){const t=new Float32Array(n+1),r=new Float32Array(n+1),i=Xt(),a=i.createOscillator(),s={sawtooth:c=>1/c,square:c=>c%2===0?0:1/c,triangle:c=>c%2===0?0:1/(c*c)};if(!s[e])throw new Error(`unknown wave type ${e}`);t[0]=0,r[0]=0;let o=1;for(;o<=n;)t[o]=s[e](o),r[o]=0,o++;const l=i.createPeriodicWave(t,r);return a.setPeriodicWave(l),a}function YP({s:n,freq:e,t,partials:r}){let i;return!r||n==="sine"?(i=Xt().createOscillator(),i.type=n||"triangle"):i=FP(r,n),i.frequency.value=Number(e),i.start(t),{node:i,stop:a=>i.stop(a)}}function GP(n=1,e=.05,t=220,r=0,i=0,a=.1,s=0,o=1,l=0,c=0,d=0,p=0,m=0,_=0,b=0,y=0,A=0,x=1,U=0,Z=0){let f=Math.PI*2,E=Xt().sampleRate,S=X=>X>0?1:-1,R=l*=500*f/E/E,w=t*=(1+e*2*Math.random()-e)*f/E,k=[],L=0,F=0,J=0,re=1,te=0,ee=0,M=0,G,K;for(r=r*E+9,U*=E,i*=E,a*=E,A*=E,c*=500*f/E**3,b*=f/E,d*=f/E,p*=E,m=m*E|0,K=r+U+i+a+A|0;J1?s>2?s>3?Math.sin((L%f)**3):Math.max(Math.min(Math.tan(L),1),-1):1-(2*L/f%2+2)%2:1-4*Math.abs(Math.round(L/f)-L/f):Math.sin(L),M=(m?1-Z+Z*Math.sin(f*J/m):1)*S(M)*Math.abs(M)**o*n*1*(JJ?0:(Jp&&(t+=d,w+=d,re=0),m&&!(++te%m)&&(t=w,l=R,re||(re=1));return k}const $P=(n,e)=>{let{s:t,note:r=36,freq:i,zrand:a=0,attack:s=0,decay:o=0,sustain:l=.8,release:c=.1,curve:d=1,slide:p=0,deltaSlide:m=0,pitchJump:_=0,pitchJumpTime:b=0,lfo:y=0,noise:A=0,zmod:x=0,zcrush:U=0,zdelay:Z=0,tremolo:f=0,duration:E=.2,zzfx:S}=n;const R=Math.max(E-s-o,0);typeof r=="string"&&(r=yc(r)),!i&&typeof r=="number"&&(i=MA(r)),t=t.replace("z_","");const w=["sine","triangle","sawtooth","tan","noise"].indexOf(t)||0;d=t==="square"?0:d;const k=GP(...S||[.25,a,i,s,R,c,w,d,p,m,_,b,y,A,x,U,Z,l,o,f]),L=Xt(),F=L.createBuffer(1,k.length,L.sampleRate);F.getChannelData(0).set(k);const J=Xt().createBufferSource();return J.buffer=F,J.start(e),{node:J}};function QP(){["zzfx","z_sine","z_sawtooth","z_triangle","z_square","z_tan","z_noise"].forEach(n=>{Tg(n,(e,t,r)=>{const{node:i}=$P({s:n,...t},e);return i.onended=()=>{i.disconnect(),r()},{node:i,stop:()=>{}}},{type:"synth",prebake:!0})})}class PA extends kA{constructor(t,r){super(r);v(this,"volume",t=>this.updateValue("volume",t));v(this,"vol",this.volume);v(this,"zrand",t=>this.updateValue("zrand",t));v(this,"curve",t=>this.updateValue("curve",t));v(this,"slide",t=>this.updateValue("slide",t));v(this,"sld",this.slide);v(this,"deltaSlide",t=>this.updateValue("deltaSlide",t));v(this,"dslide",this.deltaSlide);v(this,"pitchJump",t=>this.updateValue("pitchJump",t));v(this,"pj",this.pitchJump);v(this,"pitchJumpTime",t=>this.updateValue("pitchJumpTime",t));v(this,"pjt",this.pitchJumpTime);v(this,"lfo",t=>this.updateValue("lfo",t));v(this,"noise",t=>this.updateValue("noise",t));v(this,"zmod",t=>this.updateValue("zmod",t));v(this,"zcrush",t=>this.updateValue("zcrush",t));v(this,"zdelay",t=>this.updateValue("zdelay",t));v(this,"sustainVolume",t=>this.updateValue("sustainVolume",t));v(this,"decay",t=>this.updateValue("decay",t));v(this,"dec",this.decay);v(this,"tremolo",t=>this.updateValue("tremolo",t));v(this,"duration",t=>this.updateValue("duration",t));v(this,"zzfx",t=>this.updateValue("zzfx",t));v(this,"fmi",t=>this.updateValue("fmi",t));v(this,"fmh",t=>this.updateValue("fmh",t));v(this,"fmenv",t=>this.updateValue("fmenv",t));v(this,"fmattack",t=>this.updateValue("fmattack",t));v(this,"fmatk",this.fmattack);v(this,"fmdecay",t=>this.updateValue("fmdecay",t));v(this,"fmdec",this.fmdecay);v(this,"fmsustain",t=>this.updateValue("fmsustain",t));v(this,"fmsus",this.fmsustain);v(this,"fmrelease",t=>this.updateValue("fmrelease",t));v(this,"fmrel",this.fmrelease);v(this,"fmvelocity",t=>this.updateValue("fmvelocity",t));v(this,"fmvel",this.fmvelocity);v(this,"fmwave",t=>this.updateValue("fmwave",t));v(this,"fmw",this.fmwave);v(this,"attack",t=>this.updateValue("attack",t));v(this,"atk",this.attack);v(this,"release",t=>this.updateValue("release",t));v(this,"rel",this.release);v(this,"sustain",t=>this.updateValue("sustain",t));v(this,"sus",this.sustain);v(this,"unit",t=>this.updateValue("unit",t));v(this,"u",this.unit);v(this,"freq",t=>this.updateValue("freq",t));v(this,"f",this.freq);v(this,"fm",t=>{if(typeof t=="number")this.values.fmi=t;else{let r=t.split(":");this.values.fmi=parseFloat(r[0]),r.length>1&&(this.values.fmh=parseFloat(r[1]))}return this});v(this,"sound",t=>this.updateValue("s",t));v(this,"snd",this.sound);v(this,"nudge",t=>this.updateValue("nudge",t));v(this,"cut",t=>this.updateValue("cut",t));v(this,"loop",t=>this.updateValue("loop",t));v(this,"clip",t=>this.updateValue("clip",t));v(this,"n",t=>this.updateValue("n",t));v(this,"note",t=>this.updateValue("note",t));v(this,"speed",t=>this.updateValue("speed",t));v(this,"spd",this.speed);v(this,"begin",t=>this.updateValue("begin",t));v(this,"end",t=>this.updateValue("end",t));v(this,"gain",t=>this.updateValue("gain",t));v(this,"cutoff",t=>this.updateValue("cutoff",t));v(this,"lpf",this.cutoff);v(this,"resonance",t=>this.updateValue("resonance",t));v(this,"lpq",this.resonance);v(this,"hcutoff",t=>this.updateValue("hcutoff",t));v(this,"hpf",this.hcutoff);v(this,"hresonance",t=>this.updateValue("hresonance",t));v(this,"hpq",this.hresonance);v(this,"bandf",t=>this.updateValue("bandf",t));v(this,"bpf",this.bandf);v(this,"bandq",t=>this.updateValue("bandq",t));v(this,"bpq",this.bandq);v(this,"coarse",t=>this.updateValue("coarse",t));v(this,"crush",t=>this.updateValue("crush",t));v(this,"shape",t=>this.updateValue("shape",t));v(this,"pan",t=>this.updateValue("pan",t));v(this,"vowel",t=>this.updateValue("vowel",t));v(this,"vow",this.vowel);v(this,"delay",t=>this.updateValue("delay",t));v(this,"del",this.delay);v(this,"delayfeedback",t=>this.updateValue("delayfeedback",t));v(this,"delayfb",this.delayfeedback);v(this,"delaytime",t=>this.updateValue("delaytime",t));v(this,"delayt",this.delaytime);v(this,"orbit",t=>this.updateValue("orbit",t));v(this,"o",this.orbit);v(this,"room",t=>this.updateValue("room",t));v(this,"rm",this.room);v(this,"size",t=>this.updateValue("size",t));v(this,"sz",this.size);v(this,"velocity",t=>this.updateValue("velocity",t));v(this,"vel",this.velocity);v(this,"modify",t=>{const r=t(this);return r instanceof Object?r:(t(this.values),this.update(),this)});v(this,"update",()=>{const[t,r]=Sg(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.freq=To(t)});v(this,"out",()=>RP(this.values,this.app.clock.pulse_duration,this.values.dur||.5));this.app=r,typeof t=="string"?this.values={s:t,dur:.5}:this.values=t}updateValue(t,r){return this.values[t]=r,this}}class BA extends kA{constructor(t,r){super(r);v(this,"midiConnection");v(this,"note",t=>(this.values.note=t,this));v(this,"sustain",t=>(this.values.sustain=t,this));v(this,"channel",t=>(this.values.channel=t,this));v(this,"port",t=>(this.values.port=this.midiConnection.getMidiOutputIndex(t),this));v(this,"add",t=>(this.values.note+=t,this));v(this,"modify",t=>{const r=t(this);return r instanceof Object?r:(t(this.values),this.update(),this)});v(this,"bend",t=>(this.values.bend=t,this));v(this,"random",(t=0,r=127)=>(t=Math.min(Math.max(t,0),127),r=Math.min(Math.max(r,0),127),this.values.note=Math.floor(this.randomGen()*(r-t+1))+t,this));v(this,"update",()=>{const[t,r]=Sg(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.note=t,this.values.freq=To(t),r&&(this.values.bend=r)});v(this,"out",()=>{const t=this.values.note?this.values.note:60,r=this.values.channel?this.values.channel:0,i=this.values.velocity?this.values.velocity:100,a=this.values.sustain?this.values.sustain*this.app.clock.pulse_duration*this.app.api.ppqn():this.app.clock.pulse_duration*this.app.api.ppqn(),s=this.values.bend?this.values.bend:void 0,o=this.values.port?this.midiConnection.getMidiOutputIndex(this.values.port):this.midiConnection.getCurrentMidiPortIndex();this.midiConnection.sendMidiNote(t,r,i,a,o,s)});this.app=r,typeof t=="number"?this.values.note=t:this.values=t,this.midiConnection=r.api.MidiConnection}}const Bs=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,UA=new Set,um=typeof process=="object"&&process?process:{},FA=(n,e,t,r)=>{typeof um.emitWarning=="function"?um.emitWarning(n,e,t,r):console.error(`[${t}] ${e}: ${n}`)};let oc=globalThis.AbortController,DO=globalThis.AbortSignal;var b1;if(typeof oc>"u"){DO=class{constructor(){v(this,"onabort");v(this,"_onabort",[]);v(this,"reason");v(this,"aborted",!1)}addEventListener(r,i){this._onabort.push(i)}},oc=class{constructor(){v(this,"signal",new DO);e()}abort(r){var i,a;if(!this.signal.aborted){this.signal.reason=r,this.signal.aborted=!0;for(const s of this.signal._onabort)s(r);(a=(i=this.signal).onabort)==null||a.call(i,r)}}};let n=((b1=um.env)==null?void 0:b1.LRU_CACHE_IGNORE_AC_WARNING)!=="1";const e=()=>{n&&(n=!1,FA("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}const qP=n=>!UA.has(n),Li=n=>n&&n===Math.floor(n)&&n>0&&isFinite(n),YA=n=>Li(n)?n<=Math.pow(2,8)?Uint8Array:n<=Math.pow(2,16)?Uint16Array:n<=Math.pow(2,32)?Uint32Array:n<=Number.MAX_SAFE_INTEGER?Al:null:null;class Al extends Array{constructor(e){super(e),this.fill(0)}}var es;const da=class da{constructor(e,t){v(this,"heap");v(this,"length");if(!q(da,es))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}static create(e){const t=YA(e);if(!t)return[];He(da,es,!0);const r=new da(e,t);return He(da,es,!1),r}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};es=new WeakMap,tt(da,es,!1);let dm=da;var Tn,Wr,Cn,vn,ts,tr,yn,rr,Dt,et,Nr,Xr,Er,cr,An,ur,li,ci,Rn,In,Fi,wr,Ao,fm,ga,ui,Ro,Zr,pc,GA,_a,rs,Io,Yn,ki,Gn,Mi,No,hm,ns,Rl,is,Il,Rt,Mt,wo,mm,Sa,zs;const xg=class xg{constructor(e){tt(this,Ao);tt(this,pc);tt(this,Yn);tt(this,Gn);tt(this,No);tt(this,ns);tt(this,is);tt(this,Rt);tt(this,wo);tt(this,Sa);tt(this,Tn,void 0);tt(this,Wr,void 0);tt(this,Cn,void 0);tt(this,vn,void 0);tt(this,ts,void 0);v(this,"ttl");v(this,"ttlResolution");v(this,"ttlAutopurge");v(this,"updateAgeOnGet");v(this,"updateAgeOnHas");v(this,"allowStale");v(this,"noDisposeOnSet");v(this,"noUpdateTTL");v(this,"maxEntrySize");v(this,"sizeCalculation");v(this,"noDeleteOnFetchRejection");v(this,"noDeleteOnStaleGet");v(this,"allowStaleOnFetchAbort");v(this,"allowStaleOnFetchRejection");v(this,"ignoreFetchAbort");tt(this,tr,void 0);tt(this,yn,void 0);tt(this,rr,void 0);tt(this,Dt,void 0);tt(this,et,void 0);tt(this,Nr,void 0);tt(this,Xr,void 0);tt(this,Er,void 0);tt(this,cr,void 0);tt(this,An,void 0);tt(this,ur,void 0);tt(this,li,void 0);tt(this,ci,void 0);tt(this,Rn,void 0);tt(this,In,void 0);tt(this,Fi,void 0);tt(this,wr,void 0);tt(this,ga,()=>{});tt(this,ui,()=>{});tt(this,Ro,()=>{});tt(this,Zr,()=>!1);tt(this,_a,e=>{});tt(this,rs,(e,t,r)=>{});tt(this,Io,(e,t,r,i)=>{if(r||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});const{max:t=0,ttl:r,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:s,updateAgeOnHas:o,allowStale:l,dispose:c,disposeAfter:d,noDisposeOnSet:p,noUpdateTTL:m,maxSize:_=0,maxEntrySize:b=0,sizeCalculation:y,fetchMethod:A,noDeleteOnFetchRejection:x,noDeleteOnStaleGet:U,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:f,ignoreFetchAbort:E}=e;if(t!==0&&!Li(t))throw new TypeError("max option must be a nonnegative integer");const S=t?YA(t):Array;if(!S)throw new Error("invalid max value: "+t);if(He(this,Tn,t),He(this,Wr,_),this.maxEntrySize=b||q(this,Wr),this.sizeCalculation=y,this.sizeCalculation){if(!q(this,Wr)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(A!==void 0&&typeof A!="function")throw new TypeError("fetchMethod must be a function if specified");if(He(this,ts,A),He(this,Fi,!!A),He(this,rr,new Map),He(this,Dt,new Array(t).fill(void 0)),He(this,et,new Array(t).fill(void 0)),He(this,Nr,new S(t)),He(this,Xr,new S(t)),He(this,Er,0),He(this,cr,0),He(this,An,dm.create(t)),He(this,tr,0),He(this,yn,0),typeof c=="function"&&He(this,Cn,c),typeof d=="function"?(He(this,vn,d),He(this,ur,[])):(He(this,vn,void 0),He(this,ur,void 0)),He(this,In,!!q(this,Cn)),He(this,wr,!!q(this,vn)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!x,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!f,this.ignoreFetchAbort=!!E,this.maxEntrySize!==0){if(q(this,Wr)!==0&&!Li(q(this,Wr)))throw new TypeError("maxSize must be a positive integer if specified");if(!Li(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");$e(this,pc,GA).call(this)}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!U,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!o,this.ttlResolution=Li(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=r||0,this.ttl){if(!Li(this.ttl))throw new TypeError("ttl must be a positive integer if specified");$e(this,Ao,fm).call(this)}if(q(this,Tn)===0&&this.ttl===0&&q(this,Wr)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!q(this,Tn)&&!q(this,Wr)){const R="LRU_CACHE_UNBOUNDED";qP(R)&&(UA.add(R),FA("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",R,xg))}}static unsafeExposeInternals(e){return{starts:q(e,ci),ttls:q(e,Rn),sizes:q(e,li),keyMap:q(e,rr),keyList:q(e,Dt),valList:q(e,et),next:q(e,Nr),prev:q(e,Xr),get head(){return q(e,Er)},get tail(){return q(e,cr)},free:q(e,An),isBackgroundFetch:t=>{var r;return $e(r=e,Rt,Mt).call(r,t)},backgroundFetch:(t,r,i,a)=>{var s;return $e(s=e,is,Il).call(s,t,r,i,a)},moveToTail:t=>{var r;return $e(r=e,Sa,zs).call(r,t)},indexes:t=>{var r;return $e(r=e,Yn,ki).call(r,t)},rindexes:t=>{var r;return $e(r=e,Gn,Mi).call(r,t)},isStale:t=>{var r;return q(r=e,Zr).call(r,t)}}}get max(){return q(this,Tn)}get maxSize(){return q(this,Wr)}get calculatedSize(){return q(this,yn)}get size(){return q(this,tr)}get fetchMethod(){return q(this,ts)}get dispose(){return q(this,Cn)}get disposeAfter(){return q(this,vn)}getRemainingTTL(e){return q(this,rr).has(e)?1/0:0}*entries(){for(const e of $e(this,Yn,ki).call(this))q(this,et)[e]!==void 0&&q(this,Dt)[e]!==void 0&&!$e(this,Rt,Mt).call(this,q(this,et)[e])&&(yield[q(this,Dt)[e],q(this,et)[e]])}*rentries(){for(const e of $e(this,Gn,Mi).call(this))q(this,et)[e]!==void 0&&q(this,Dt)[e]!==void 0&&!$e(this,Rt,Mt).call(this,q(this,et)[e])&&(yield[q(this,Dt)[e],q(this,et)[e]])}*keys(){for(const e of $e(this,Yn,ki).call(this)){const t=q(this,Dt)[e];t!==void 0&&!$e(this,Rt,Mt).call(this,q(this,et)[e])&&(yield t)}}*rkeys(){for(const e of $e(this,Gn,Mi).call(this)){const t=q(this,Dt)[e];t!==void 0&&!$e(this,Rt,Mt).call(this,q(this,et)[e])&&(yield t)}}*values(){for(const e of $e(this,Yn,ki).call(this))q(this,et)[e]!==void 0&&!$e(this,Rt,Mt).call(this,q(this,et)[e])&&(yield q(this,et)[e])}*rvalues(){for(const e of $e(this,Gn,Mi).call(this))q(this,et)[e]!==void 0&&!$e(this,Rt,Mt).call(this,q(this,et)[e])&&(yield q(this,et)[e])}[Symbol.iterator](){return this.entries()}find(e,t={}){for(const r of $e(this,Yn,ki).call(this)){const i=q(this,et)[r],a=$e(this,Rt,Mt).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,q(this,Dt)[r],this))return this.get(q(this,Dt)[r],t)}}forEach(e,t=this){for(const r of $e(this,Yn,ki).call(this)){const i=q(this,et)[r],a=$e(this,Rt,Mt).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,q(this,Dt)[r],this)}}rforEach(e,t=this){for(const r of $e(this,Gn,Mi).call(this)){const i=q(this,et)[r],a=$e(this,Rt,Mt).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,q(this,Dt)[r],this)}}purgeStale(){let e=!1;for(const t of $e(this,Gn,Mi).call(this,{allowStale:!0}))q(this,Zr).call(this,t)&&(this.delete(q(this,Dt)[t]),e=!0);return e}dump(){const e=[];for(const t of $e(this,Yn,ki).call(this,{allowStale:!0})){const r=q(this,Dt)[t],i=q(this,et)[t],a=$e(this,Rt,Mt).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||r===void 0)continue;const s={value:a};if(q(this,Rn)&&q(this,ci)){s.ttl=q(this,Rn)[t];const o=Bs.now()-q(this,ci)[t];s.start=Math.floor(Date.now()-o)}q(this,li)&&(s.size=q(this,li)[t]),e.unshift([r,s])}return e}load(e){this.clear();for(const[t,r]of e){if(r.start){const i=Date.now()-r.start;r.start=Bs.now()-i}this.set(t,r.value,r)}}set(e,t,r={}){var m,_,b,y,A;if(t===void 0)return this.delete(e),this;const{ttl:i=this.ttl,start:a,noDisposeOnSet:s=this.noDisposeOnSet,sizeCalculation:o=this.sizeCalculation,status:l}=r;let{noUpdateTTL:c=this.noUpdateTTL}=r;const d=q(this,Io).call(this,e,t,r.size||0,o);if(this.maxEntrySize&&d>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=!0),this.delete(e),this;let p=q(this,tr)===0?void 0:q(this,rr).get(e);if(p===void 0)p=q(this,tr)===0?q(this,cr):q(this,An).length!==0?q(this,An).pop():q(this,tr)===q(this,Tn)?$e(this,ns,Rl).call(this,!1):q(this,tr),q(this,Dt)[p]=e,q(this,et)[p]=t,q(this,rr).set(e,p),q(this,Nr)[q(this,cr)]=p,q(this,Xr)[p]=q(this,cr),He(this,cr,p),Yo(this,tr)._++,q(this,rs).call(this,p,d,l),l&&(l.set="add"),c=!1;else{$e(this,Sa,zs).call(this,p);const x=q(this,et)[p];if(t!==x){if(q(this,Fi)&&$e(this,Rt,Mt).call(this,x)){x.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:U}=x;U!==void 0&&!s&&(q(this,In)&&((m=q(this,Cn))==null||m.call(this,U,e,"set")),q(this,wr)&&((_=q(this,ur))==null||_.push([U,e,"set"])))}else s||(q(this,In)&&((b=q(this,Cn))==null||b.call(this,x,e,"set")),q(this,wr)&&((y=q(this,ur))==null||y.push([x,e,"set"])));if(q(this,_a).call(this,p),q(this,rs).call(this,p,d,l),q(this,et)[p]=t,l){l.set="replace";const U=x&&$e(this,Rt,Mt).call(this,x)?x.__staleWhileFetching:x;U!==void 0&&(l.oldValue=U)}}else l&&(l.set="update")}if(i!==0&&!q(this,Rn)&&$e(this,Ao,fm).call(this),q(this,Rn)&&(c||q(this,Ro).call(this,p,i,a),l&&q(this,ui).call(this,l,p)),!s&&q(this,wr)&&q(this,ur)){const x=q(this,ur);let U;for(;U=x==null?void 0:x.shift();)(A=q(this,vn))==null||A.call(this,...U)}return this}pop(){var e;try{for(;q(this,tr);){const t=q(this,et)[q(this,Er)];if($e(this,ns,Rl).call(this,!0),$e(this,Rt,Mt).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(q(this,wr)&&q(this,ur)){const t=q(this,ur);let r;for(;r=t==null?void 0:t.shift();)(e=q(this,vn))==null||e.call(this,...r)}}}has(e,t={}){const{updateAgeOnHas:r=this.updateAgeOnHas,status:i}=t,a=q(this,rr).get(e);if(a!==void 0){const s=q(this,et)[a];if($e(this,Rt,Mt).call(this,s)&&s.__staleWhileFetching===void 0)return!1;if(q(this,Zr).call(this,a))i&&(i.has="stale",q(this,ui).call(this,i,a));else return r&&q(this,ga).call(this,a),i&&(i.has="hit",q(this,ui).call(this,i,a)),!0}else i&&(i.has="miss");return!1}peek(e,t={}){const{allowStale:r=this.allowStale}=t,i=q(this,rr).get(e);if(i!==void 0&&(r||!q(this,Zr).call(this,i))){const a=q(this,et)[i];return $e(this,Rt,Mt).call(this,a)?a.__staleWhileFetching:a}}async fetch(e,t={}){const{allowStale:r=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,ttl:s=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:l=0,sizeCalculation:c=this.sizeCalculation,noUpdateTTL:d=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:m=this.allowStaleOnFetchRejection,ignoreFetchAbort:_=this.ignoreFetchAbort,allowStaleOnFetchAbort:b=this.allowStaleOnFetchAbort,context:y,forceRefresh:A=!1,status:x,signal:U}=t;if(!q(this,Fi))return x&&(x.fetch="get"),this.get(e,{allowStale:r,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:x});const Z={allowStale:r,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:s,noDisposeOnSet:o,size:l,sizeCalculation:c,noUpdateTTL:d,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:b,ignoreFetchAbort:_,status:x,signal:U};let f=q(this,rr).get(e);if(f===void 0){x&&(x.fetch="miss");const E=$e(this,is,Il).call(this,e,f,Z,y);return E.__returned=E}else{const E=q(this,et)[f];if($e(this,Rt,Mt).call(this,E)){const L=r&&E.__staleWhileFetching!==void 0;return x&&(x.fetch="inflight",L&&(x.returnedStale=!0)),L?E.__staleWhileFetching:E.__returned=E}const S=q(this,Zr).call(this,f);if(!A&&!S)return x&&(x.fetch="hit"),$e(this,Sa,zs).call(this,f),i&&q(this,ga).call(this,f),x&&q(this,ui).call(this,x,f),E;const R=$e(this,is,Il).call(this,e,f,Z,y),k=R.__staleWhileFetching!==void 0&&r;return x&&(x.fetch=S?"stale":"refresh",k&&S&&(x.returnedStale=!0)),k?R.__staleWhileFetching:R.__returned=R}}get(e,t={}){const{allowStale:r=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:s}=t,o=q(this,rr).get(e);if(o!==void 0){const l=q(this,et)[o],c=$e(this,Rt,Mt).call(this,l);return s&&q(this,ui).call(this,s,o),q(this,Zr).call(this,o)?(s&&(s.get="stale"),c?(s&&r&&l.__staleWhileFetching!==void 0&&(s.returnedStale=!0),r?l.__staleWhileFetching:void 0):(a||this.delete(e),s&&r&&(s.returnedStale=!0),r?l:void 0)):(s&&(s.get="hit"),c?l.__staleWhileFetching:($e(this,Sa,zs).call(this,o),i&&q(this,ga).call(this,o),l))}else s&&(s.get="miss")}delete(e){var r,i,a,s;let t=!1;if(q(this,tr)!==0){const o=q(this,rr).get(e);if(o!==void 0)if(t=!0,q(this,tr)===1)this.clear();else{q(this,_a).call(this,o);const l=q(this,et)[o];$e(this,Rt,Mt).call(this,l)?l.__abortController.abort(new Error("deleted")):(q(this,In)||q(this,wr))&&(q(this,In)&&((r=q(this,Cn))==null||r.call(this,l,e,"delete")),q(this,wr)&&((i=q(this,ur))==null||i.push([l,e,"delete"]))),q(this,rr).delete(e),q(this,Dt)[o]=void 0,q(this,et)[o]=void 0,o===q(this,cr)?He(this,cr,q(this,Xr)[o]):o===q(this,Er)?He(this,Er,q(this,Nr)[o]):(q(this,Nr)[q(this,Xr)[o]]=q(this,Nr)[o],q(this,Xr)[q(this,Nr)[o]]=q(this,Xr)[o]),Yo(this,tr)._--,q(this,An).push(o)}}if(q(this,wr)&&((a=q(this,ur))!=null&&a.length)){const o=q(this,ur);let l;for(;l=o==null?void 0:o.shift();)(s=q(this,vn))==null||s.call(this,...l)}return t}clear(){var e,t,r;for(const i of $e(this,Gn,Mi).call(this,{allowStale:!0})){const a=q(this,et)[i];if($e(this,Rt,Mt).call(this,a))a.__abortController.abort(new Error("deleted"));else{const s=q(this,Dt)[i];q(this,In)&&((e=q(this,Cn))==null||e.call(this,a,s,"delete")),q(this,wr)&&((t=q(this,ur))==null||t.push([a,s,"delete"]))}}if(q(this,rr).clear(),q(this,et).fill(void 0),q(this,Dt).fill(void 0),q(this,Rn)&&q(this,ci)&&(q(this,Rn).fill(0),q(this,ci).fill(0)),q(this,li)&&q(this,li).fill(0),He(this,Er,0),He(this,cr,0),q(this,An).length=0,He(this,yn,0),He(this,tr,0),q(this,wr)&&q(this,ur)){const i=q(this,ur);let a;for(;a=i==null?void 0:i.shift();)(r=q(this,vn))==null||r.call(this,...a)}}};Tn=new WeakMap,Wr=new WeakMap,Cn=new WeakMap,vn=new WeakMap,ts=new WeakMap,tr=new WeakMap,yn=new WeakMap,rr=new WeakMap,Dt=new WeakMap,et=new WeakMap,Nr=new WeakMap,Xr=new WeakMap,Er=new WeakMap,cr=new WeakMap,An=new WeakMap,ur=new WeakMap,li=new WeakMap,ci=new WeakMap,Rn=new WeakMap,In=new WeakMap,Fi=new WeakMap,wr=new WeakMap,Ao=new WeakSet,fm=function(){const e=new Al(q(this,Tn)),t=new Al(q(this,Tn));He(this,Rn,e),He(this,ci,t),He(this,Ro,(a,s,o=Bs.now())=>{if(t[a]=s!==0?o:0,e[a]=s,s!==0&&this.ttlAutopurge){const l=setTimeout(()=>{q(this,Zr).call(this,a)&&this.delete(q(this,Dt)[a])},s+1);l.unref&&l.unref()}}),He(this,ga,a=>{t[a]=e[a]!==0?Bs.now():0}),He(this,ui,(a,s)=>{if(e[s]){const o=e[s],l=t[s];a.ttl=o,a.start=l,a.now=r||i();const c=a.now-l;a.remainingTTL=o-c}});let r=0;const i=()=>{const a=Bs.now();if(this.ttlResolution>0){r=a;const s=setTimeout(()=>r=0,this.ttlResolution);s.unref&&s.unref()}return a};this.getRemainingTTL=a=>{const s=q(this,rr).get(a);if(s===void 0)return 0;const o=e[s],l=t[s];if(o===0||l===0)return 1/0;const c=(r||i())-l;return o-c},He(this,Zr,a=>e[a]!==0&&t[a]!==0&&(r||i())-t[a]>e[a])},ga=new WeakMap,ui=new WeakMap,Ro=new WeakMap,Zr=new WeakMap,pc=new WeakSet,GA=function(){const e=new Al(q(this,Tn));He(this,yn,0),He(this,li,e),He(this,_a,t=>{He(this,yn,q(this,yn)-e[t]),e[t]=0}),He(this,Io,(t,r,i,a)=>{if($e(this,Rt,Mt).call(this,r))return 0;if(!Li(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(r,t),!Li(i))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return i}),He(this,rs,(t,r,i)=>{if(e[t]=r,q(this,Wr)){const a=q(this,Wr)-e[t];for(;q(this,yn)>a;)$e(this,ns,Rl).call(this,!0)}He(this,yn,q(this,yn)+e[t]),i&&(i.entrySize=r,i.totalCalculatedSize=q(this,yn))})},_a=new WeakMap,rs=new WeakMap,Io=new WeakMap,Yn=new WeakSet,ki=function*({allowStale:e=this.allowStale}={}){if(q(this,tr))for(let t=q(this,cr);!(!$e(this,No,hm).call(this,t)||((e||!q(this,Zr).call(this,t))&&(yield t),t===q(this,Er)));)t=q(this,Xr)[t]},Gn=new WeakSet,Mi=function*({allowStale:e=this.allowStale}={}){if(q(this,tr))for(let t=q(this,Er);!(!$e(this,No,hm).call(this,t)||((e||!q(this,Zr).call(this,t))&&(yield t),t===q(this,cr)));)t=q(this,Nr)[t]},No=new WeakSet,hm=function(e){return e!==void 0&&q(this,rr).get(q(this,Dt)[e])===e},ns=new WeakSet,Rl=function(e){var a,s;const t=q(this,Er),r=q(this,Dt)[t],i=q(this,et)[t];return q(this,Fi)&&$e(this,Rt,Mt).call(this,i)?i.__abortController.abort(new Error("evicted")):(q(this,In)||q(this,wr))&&(q(this,In)&&((a=q(this,Cn))==null||a.call(this,i,r,"evict")),q(this,wr)&&((s=q(this,ur))==null||s.push([i,r,"evict"]))),q(this,_a).call(this,t),e&&(q(this,Dt)[t]=void 0,q(this,et)[t]=void 0,q(this,An).push(t)),q(this,tr)===1?(He(this,Er,He(this,cr,0)),q(this,An).length=0):He(this,Er,q(this,Nr)[t]),q(this,rr).delete(r),Yo(this,tr)._--,t},is=new WeakSet,Il=function(e,t,r,i){const a=t===void 0?void 0:q(this,et)[t];if($e(this,Rt,Mt).call(this,a))return a;const s=new oc,{signal:o}=r;o==null||o.addEventListener("abort",()=>s.abort(o.reason),{signal:s.signal});const l={signal:s.signal,options:r,context:i},c=(y,A=!1)=>{const{aborted:x}=s.signal,U=r.ignoreFetchAbort&&y!==void 0;if(r.status&&(x&&!A?(r.status.fetchAborted=!0,r.status.fetchError=s.signal.reason,U&&(r.status.fetchAbortIgnored=!0)):r.status.fetchResolved=!0),x&&!U&&!A)return p(s.signal.reason);const Z=_;return q(this,et)[t]===_&&(y===void 0?Z.__staleWhileFetching?q(this,et)[t]=Z.__staleWhileFetching:this.delete(e):(r.status&&(r.status.fetchUpdated=!0),this.set(e,y,l.options))),y},d=y=>(r.status&&(r.status.fetchRejected=!0,r.status.fetchError=y),p(y)),p=y=>{const{aborted:A}=s.signal,x=A&&r.allowStaleOnFetchAbort,U=x||r.allowStaleOnFetchRejection,Z=U||r.noDeleteOnFetchRejection,f=_;if(q(this,et)[t]===_&&(!Z||f.__staleWhileFetching===void 0?this.delete(e):x||(q(this,et)[t]=f.__staleWhileFetching)),U)return r.status&&f.__staleWhileFetching!==void 0&&(r.status.returnedStale=!0),f.__staleWhileFetching;if(f.__returned===f)throw y},m=(y,A)=>{var U;const x=(U=q(this,ts))==null?void 0:U.call(this,e,a,l);x&&x instanceof Promise&&x.then(Z=>y(Z===void 0?void 0:Z),A),s.signal.addEventListener("abort",()=>{(!r.ignoreFetchAbort||r.allowStaleOnFetchAbort)&&(y(void 0),r.allowStaleOnFetchAbort&&(y=Z=>c(Z,!0)))})};r.status&&(r.status.fetchDispatched=!0);const _=new Promise(m).then(c,d),b=Object.assign(_,{__abortController:s,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,b,{...l.options,status:void 0}),t=q(this,rr).get(e)):q(this,et)[t]=b,b},Rt=new WeakSet,Mt=function(e){if(!q(this,Fi))return!1;const t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof oc},wo=new WeakSet,mm=function(e,t){q(this,Xr)[t]=e,q(this,Nr)[e]=t},Sa=new WeakSet,zs=function(e){e!==q(this,cr)&&(e===q(this,Er)?He(this,Er,q(this,Nr)[e]):$e(this,wo,mm).call(this,q(this,Xr)[e],q(this,Nr)[e]),$e(this,wo,mm).call(this,q(this,cr),e),He(this,cr,e))};let pm=xg;const eo=class eo{constructor(){v(this,"_fallbackMethod",()=>eo.createSkipProxy());v(this,"out",()=>{})}};v(eo,"createSkipProxy",()=>{const e=new eo;return new Proxy(e,{get(t,r,i){return typeof t[r]>"u"?t._fallbackMethod:t[r]},set(t,r,i,a){return!1}})});let lc=eo;const to=class to extends Eg{constructor(t,r){super(r);v(this,"_fallbackMethod",()=>to.createRestProxy(this.values.length,this.app));v(this,"out",()=>{});this.values.length=t}};v(to,"createRestProxy",(t,r)=>{const i=new to(t,r);return new Proxy(i,{get(a,s,o){return typeof a[s]>"u"?a._fallbackMethod:a[s]},set(a,s,o,l){return!1}})});let cc=to;class VP extends Eg{constructor(t,r,i){super(i);v(this,"input");v(this,"ziffers");v(this,"initCallTime",0);v(this,"startCallTime",0);v(this,"lastCallTime",0);v(this,"waitTime",0);v(this,"startBeat",0);v(this,"played",!1);v(this,"current");v(this,"retro",!1);v(this,"index",-1);v(this,"zid","");v(this,"options",{});v(this,"skipIndex",0);v(this,"endTime",0);v(this,"next",()=>(this.current=this.ziffers.next(),this.played=!0,this.current));v(this,"pulseToSecond",t=>this.app.clock.convertPulseToSecond(t));v(this,"firstRun",()=>this.notStarted());v(this,"atTheBeginning",()=>this.skipIndex===0&&this.ziffers.index<=0);v(this,"origin",()=>this.app.clock.pulses_since_origin+1);v(this,"pulse",()=>this.app.clock.time_position.pulse);v(this,"beat",()=>this.app.clock.time_position.beat);v(this,"nextBeat",()=>this.app.clock.next_beat_in_ticks);v(this,"nextBeatInTicks",()=>this.app.clock.next_beat_in_ticks);v(this,"areWeThereYet",()=>{this.app.clock.pulses_since_origin=this.nextBeatInTicks())&&this.origin()>=this.waitTime||this.current&&this.pulseToSecond(this.origin())>=this.pulseToSecond(this.lastCallTime)+this.current.duration*4*this.pulseToSecond(this.app.api.ppqn())&&this.origin()>=this.waitTime;return this.skipIndex=t?0:this.skipIndex+1,this.index=t?this.index+1:this.index,t&&this.notStarted()&&(this.initCallTime=this.app.clock.pulses_since_origin),this.atTheBeginning()&&(this.startCallTime=this.app.clock.pulses_since_origin),t});v(this,"out",()=>{});this.app=i,this.input=t,this.options=r,this.ziffers=new iP(t,r)}get ticks(){return this.ziffers.duration*4*this.app.clock.ppqn}nextEndTime(){return this.startCallTime+this.ticks}updateLastCallTime(){(this.notStarted()||this.played)&&(this.lastCallTime=this.app.clock.pulses_since_origin,this.played=!1)}notStarted(){return this.ziffers.notStarted()}sound(t){if(this.areWeThereYet()){const r=this.next();if(r instanceof gs){const i=r.getExisting("freq","pitch","key","scale","octave","parsedScale");return new PA(i,this.app).sound(t)}else if(r instanceof lm)return cc.createRestProxy(r.duration,this.app)}else return lc.createSkipProxy()}midi(t=void 0){if(this.areWeThereYet()){const r=this.next();if(r instanceof gs){const i=r.getExisting("note","pitch","bend","key","scale","octave","parsedScale"),a=new BA(i,this.app);return t?a.note(t):a}else if(r instanceof lm)return cc.createRestProxy(r.duration,this.app)}else return lc.createSkipProxy()}scale(t){return this.atTheBeginning()&&this.ziffers.scale(t),this}key(t){return this.atTheBeginning()&&this.ziffers.key(t),this}octave(t){return this.atTheBeginning()&&this.ziffers.octave(t),this}retrograde(){return this.atTheBeginning()&&this.ziffers.retrograde(),this}wait(t){if(this.atTheBeginning()){if(typeof t=="function"){const r=this.app.api.patternCache.get(t.name);return r&&(this.waitTime=r.nextEndTime()),this}this.waitTime=this.origin()+Math.ceil(t*4*this.app.clock.ppqn)}return this}sync(t){if(this.atTheBeginning()&&this.notStarted()){const r=this.app.clock.pulses_since_origin,i=typeof t=="function"?t.name:t;if(r>0){const a=this.app.api.patternCache.get(i);if(a){const s=a.ziffers.duration,o=a.startCallTime,l=s*4*this.app.clock.ppqn;this.waitTime=o+l}}}return this}}const HP=n=>n[0]==="{"&&n[n.length-1]==="}",Us=(n,e)=>{if(HP(n)){const t=JSON.parse(n);return JSON.stringify({...t,...e})}else return JSON.stringify({...e,text:n})},zP=n=>{String.prototype.speak=function(){const e=JSON.parse(this.valueOf());new $A({...e,text:e.text}).speak().then(()=>{}).catch(t=>{console.log("Error speaking:",t)})},String.prototype.rate=function(e){return Us(this.valueOf(),{rate:e})},String.prototype.pitch=function(e){return Us(this.valueOf(),{pitch:e})},String.prototype.lang=function(e){return Us(this.valueOf(),{lang:e})},String.prototype.volume=function(e){return Us(this.valueOf(),{volume:e})},String.prototype.voice=function(e){return Us(this.valueOf(),{voice:e})},String.prototype.z=function(){return n.z(this.valueOf())}};let Ou;class $A{constructor(e){v(this,"speak",()=>new Promise((e,t)=>{if(this.options.text){const r=window.speechSynthesis;r.speaking&&r.cancel();const i=new SpeechSynthesisUtterance(this.options.text);i.rate=this.options.rate||1,i.pitch=this.options.pitch||1,i.volume=this.options.volume||1,this.options.voice&&(i.voice=r.getVoices()[this.options.voice]),this.options.lang&&(this.options.lang.length===2?i.lang=`${this.options.lang}-${this.options.lang.toUpperCase()}`:this.options.lang.length===5?i.lang=this.options.lang:i.lang="en-US"),i.onend=()=>{e()},i.onerror=a=>{t(a)},r.speaking?(r.cancel(),Ou&&clearTimeout(Ou),Ou=setTimeout(()=>{r.speak(i)},200)):r.speak(i)}else t("No text provided")}));this.options=e}}async function xO(){return Promise.all([CP(),Js("github:tidalcycles/Dirt-Samples/master").then(()=>UP()),QP(),Js("github:Bubobubobubobubo/Topos-Samples/main"),Js("github:Bubobubobubobubo/Topos-Atari/main")])}class WP{constructor(e){v(this,"variables",{});v(this,"codeExamples",{});v(this,"counters",{});v(this,"_drunk",new oP(-100,100,!1));v(this,"randomGen",Math.random);v(this,"currentSeed");v(this,"localSeeds",new Map);v(this,"patternCache",new pm({max:1e3,ttl:1e3*60*5}));v(this,"errorTimeoutID",0);v(this,"printTimeoutID",0);v(this,"MidiConnection",new sP);v(this,"load");v(this,"_loadUniverseFromInterface",e=>{this.app.loadUniverse(e),this.app.openBuffersModal()});v(this,"_deleteUniverseFromInterface",e=>{delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});v(this,"_playDocExample",e=>{let t=this.app.universes[this.app.selected_universe];this.app.exampleIsPlaying=!0,t.example?t.example.candidate=e||this.app.selectedExample:(t.example={candidate:"",committed:"",evaluations:0},t.example.candidate=e||this.app.selectedExample),this.play()});v(this,"_stopDocExample",()=>{let e=this.app.universes[this.app.selected_universe];(e==null?void 0:e.example)!==void 0&&(this.app.exampleIsPlaying=!1,e.example.candidate="",e.example.committed="")});v(this,"_playDocExampleOnce",e=>{let t=this.app.universes[this.app.selected_universe];(t==null?void 0:t.example)!==void 0&&(t.example.candidate="",t.example.committed=""),this.play(),this.app.exampleIsPlaying=!0,DM(this.app,e)});v(this,"_all_samples",()=>bg.get());v(this,"_reportError",e=>{console.log(e),clearTimeout(this.errorTimeoutID),clearTimeout(this.printTimeoutID),this.app.error_line.innerHTML=e,this.app.error_line.style.color="color-red-800",this.app.error_line.classList.remove("hidden"),this.errorTimeoutID=setTimeout(()=>this.app.error_line.classList.add("hidden"),2e3)});v(this,"_logMessage",e=>{console.log(e),clearTimeout(this.printTimeoutID),clearTimeout(this.errorTimeoutID),this.app.error_line.innerHTML=e,this.app.error_line.style.color="white",this.app.error_line.classList.remove("hidden"),this.printTimeoutID=setTimeout(()=>this.app.error_line.classList.add("hidden"),4e3)});v(this,"time",()=>this.app.audioContext.currentTime);v(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.app.clock.start()});v(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.app.clock.pause()});v(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.app.clock.stop()});v(this,"silence",this.stop);v(this,"hush",this.stop);v(this,"warp",e=>{this.app.clock.tick=e,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e)});v(this,"beat_warp",e=>{this.app.clock.tick=e*this.app.clock.ppqn,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e*this.app.clock.ppqn)});v(this,"onmousemove",e=>{this.app._mouseX=e.clientX,this.app._mouseY=e.clientY});v(this,"mouseX",()=>this.app._mouseX);v(this,"mouseY",()=>this.app._mouseY);v(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));v(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));v(this,"script",(...e)=>{e.forEach(t=>{Eo(this.app,this.app.universes[this.app.selected_universe].locals[t])})});v(this,"s",this.script);v(this,"clear_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});v(this,"cs",this.clear_script);v(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]=this.app.universes[this.app.selected_universe].locals[e]});v(this,"cps",this.copy_script);v(this,"midi_outputs",()=>{this._logMessage(this.MidiConnection.listMidiOutputs())});v(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});v(this,"midi",(e=60,t,r)=>(t!==void 0&&(typeof e=="number"&&(e={note:e}),e.velocity=t),r!==void 0&&(typeof e=="number"&&(e={note:e}),e.channel=r),new BA(e,this.app)));v(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});v(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});v(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});v(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});v(this,"control_change",({control:e=20,value:t=0,channel:r=0})=>{this.MidiConnection.sendMidiControlChange(e,t,r)});v(this,"midi_panic",()=>{this.MidiConnection.panic()});v(this,"generateCacheKey",(...e)=>e.map(t=>JSON.stringify(t)).join(","));v(this,"z",(e,t={},r="")=>{const i="z"+r.toString(),a=r===""?this.generateCacheKey(e,t):i;let s;return this.app.api.patternCache.has(a)&&(s=this.app.api.patternCache.get(a),s.input!==e&&(s=void 0)),s||(s=new VP(e,t,this.app),this.app.api.patternCache.set(a,s)),typeof r=="number"&&(s.zid=i),s.updateLastCallTime(),r!==""&&s.sync("z0"),s});v(this,"z0",(e,t={})=>this.z(e,t,0));v(this,"z1",(e,t={})=>this.z(e,t,1));v(this,"z2",(e,t={})=>this.z(e,t,2));v(this,"z3",(e,t={})=>this.z(e,t,3));v(this,"z4",(e,t={})=>this.z(e,t,4));v(this,"z5",(e,t={})=>this.z(e,t,5));v(this,"z6",(e,t={})=>this.z(e,t,6));v(this,"z7",(e,t={})=>this.z(e,t,7));v(this,"z8",(e,t={})=>this.z(e,t,8));v(this,"z9",(e,t={})=>this.z(e,t,9));v(this,"z10",(e,t={})=>this.z(e,t,10));v(this,"z11",(e,t={})=>this.z(e,t,11));v(this,"z12",(e,t={})=>this.z(e,t,12));v(this,"z13",(e,t={})=>this.z(e,t,13));v(this,"z14",(e,t={})=>this.z(e,t,14));v(this,"z15",(e,t={})=>this.z(e,t,15));v(this,"z16",(e,t={})=>this.z(e,t,16));v(this,"counter",(e,t,r)=>(e in this.counters?(this.counters[e].limit!==t&&(this.counters[e].value=0,this.counters[e].limit=t),this.counters[e].step!==r&&(this.counters[e].step=r??this.counters[e].step),this.counters[e].value+=this.counters[e].step,this.counters[e].limit!==void 0&&this.counters[e].value>this.counters[e].limit&&(this.counters[e].value=0)):this.counters[e]={value:0,step:r??1,limit:t},this.counters[e].value));v(this,"$",this.counter);v(this,"i",e=>e!==void 0?(this.app.universes[this.app.selected_universe].global.evaluations=e,this.app.universes[this.app.selected_universe]):this.app.universes[this.app.selected_universe].global.evaluations);v(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));v(this,"drunk_max",e=>{this._drunk.max=e});v(this,"drunk_min",e=>{this._drunk.min=e});v(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});v(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));v(this,"v",this.variable);v(this,"delete_variable",e=>{delete this.variables[e]});v(this,"dv",this.delete_variable);v(this,"clear_variables",()=>{this.variables={}});v(this,"cv",this.clear_variables);v(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);v(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);v(this,"irand",this.randI);v(this,"rI",this.randI);v(this,"r",this.rand);v(this,"ir",this.randI);v(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=om(e))});v(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=om(e);return this.localSeeds.set(e,t),t});v(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});v(this,"quantize",(e,t)=>{if(t.length===0)return e;let r=t[0];return t.forEach(i=>{Math.abs(i-e)Math.min(Math.max(e,t),r));v(this,"cmp",this.clamp);v(this,"bpm",e=>e===void 0?this.app.clock.bpm:((e<1||e>500)&&console.log(`Setting bpm to ${e}`),this.app.clock.bpm=e,e));v(this,"tempo",this.bpm);v(this,"bpb",e=>e===void 0?this.app.clock.time_signature[0]:(e<1&&console.log(`Setting bpb to ${e}`),this.app.clock.time_signature[0]=e,e));v(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));v(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});v(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);v(this,"odds",(e,t=15)=>this.randomGen()this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));v(this,"rarely",(e=15)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));v(this,"scarcely",(e=15)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));v(this,"sometimes",(e=15)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));v(this,"often",(e=15)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));v(this,"frequently",(e=15)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));v(this,"almostAlways",(e=15)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));v(this,"dice",e=>Math.floor(this.randomGen()*e)+1);v(this,"bar",()=>this.app.clock.time_position.bar+1);v(this,"tick",()=>this.app.clock.tick+1);v(this,"pulse",()=>this.app.clock.time_position.pulse+1);v(this,"beat",()=>this.app.clock.time_position.beat+1);v(this,"ebeat",()=>this.app.clock.beats_since_origin+1);v(this,"epulse",()=>this.app.clock.pulses_since_origin+1);v(this,"nominator",()=>this.app.clock.time_signature[0]);v(this,"meter",()=>this.app.clock.time_signature[1]);v(this,"denominator",this.meter);v(this,"mod",(...e)=>e.map(r=>this.app.clock.pulses_since_origin%Math.floor(r*this.ppqn())===0).some(r=>r===!0));v(this,"modpulse",(...e)=>e.map(r=>this.app.clock.pulses_since_origin%r===0).some(r=>r===!0));v(this,"modp",this.modpulse);v(this,"modbar",(...e)=>e.map(r=>this.app.clock.time_position.bar%Math.floor(r*this.ppqn())===0).some(r=>r===!0));v(this,"modb",this.modbar);v(this,"div",e=>{const t=this.app.clock.pulses_since_origin;return Math.floor(t/Math.floor(e*this.ppqn()))%2===0});v(this,"divbar",e=>{const t=this.app.clock.time_position.bar-1;return Math.floor(t/e)%2===0});v(this,"onbar",(e,t=this.app.clock.time_signature[0])=>{let r=this.app.clock.time_position.bar%t+1;return typeof e=="number"?e===r:e.some(i=>i==r)});v(this,"onbeat",(...e)=>{let t=[];return e.forEach(r=>{const i=r%this.nominator()||this.nominator(),a=Math.floor(i),s=(i-a)*this.ppqn()+1;t.push(a===this.beat()&&this.pulse()===s)}),t.some(r=>r==!0)});v(this,"oncount",(e,t)=>{typeof e=="number"&&(e=[e]);const r=this.app.clock.pulses_since_origin;let i=[];return e.forEach(a=>{a=a<1?0:a-1;const s=Math.ceil(a*this.ppqn()),o=r%(this.ppqn()*t);return i.push(o===s)}),i.some(a=>a==!0)});v(this,"oneuclid",(e,t,r=0)=>{const a=this._euclidean_cycle(e,t,r).reduce((s,o,l)=>(o&&s.push(l+1),s),[]);return this.oncount(a,t)});v(this,"delay",(e,t)=>{setTimeout(t,e)});v(this,"delayr",(e,t,r)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(r,a)})});v(this,"euclid",(e,t,r,i=0)=>this._euclidean_cycle(t,r,i)[e%r]);v(this,"ec",this.euclid);v(this,"rhythm",(e,t,r,i=0)=>this.mod(e)&&this._euclidean_cycle(t,r,i).div(e));v(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});v(this,"line",(e,t,r=1)=>{const i=[];if(t>e&&r>0||tMath.sin(this.app.clock.ctx.currentTime*Math.PI*2*e)+t);v(this,"usine",(e=1,t=0)=>(this.sine(e,t)+1)/2);v(this,"saw",(e=1,t=0)=>this.app.clock.ctx.currentTime*e%1*2-1+t);v(this,"usaw",(e=1,t=0)=>(this.saw(e,t)+1)/2);v(this,"triangle",(e=1,t=0)=>Math.abs(this.saw(e,t))*2-1);v(this,"utriangle",(e=1,t=0)=>(this.triangle(e,t)+1)/2);v(this,"square",(e=1,t=0,r=.5)=>{const i=1/e;return(Date.now()/1e3+t)%i/i(this.square(e,t,r)+1)/2);v(this,"noise",()=>this.randomGen()*2-1);v(this,"min",(...e)=>Math.min(...e));v(this,"max",(...e)=>Math.max(...e));v(this,"mean",(...e)=>e.reduce((r,i)=>r+i,0)/e.length);v(this,"limit",(e,t,r)=>Math.min(Math.max(e,t),r));v(this,"abs",Math.abs);v(this,"speak",(e,t="en-US",r=0,i=1,a=1)=>{new $A({text:e,lang:t,voice:r,rate:i,pitch:a}).speak().then(()=>{}).catch(o=>{console.log(o)})});v(this,"sound",e=>new PA(e,this.app));v(this,"snd",this.sound);v(this,"samples",Js);v(this,"log",e=>{console.log(e),this._logMessage(e)});v(this,"scale",cP);v(this,"rate",e=>{});v(this,"divseq",(...e)=>{const t=e[0],r=e.slice(1),i=this.app.clock.pulses_since_origin,a=Math.floor(i/Math.floor(t*this.ppqn()));return r[a%r.length]});v(this,"seqbeat",(...e)=>e[this.app.clock.time_position.beat%e.length]);v(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);this.app=e}_euclidean_cycle(e,t,r=0){if(e==t)return Array.from({length:t},()=>!0);function i(o,l){const c=o.length,d=(l+1)%c;return o[l]>o[d]}if(e>=t)return[!0];const a=Array.from({length:t},(o,l)=>(e*(l-1)%t+t)%t);let s=a.map((o,l)=>i(a,l));return r!=0&&(s=s.slice(r).concat(s.slice(0,r))),s}}const XP=n=>{Array.prototype.in=function(e){return this.includes(e)},Array.prototype.square=function(){return this.map(e=>e*e)},Array.prototype.sqrt=function(){if(this.some(e=>e<0))throw new Error("Cannot take square root of negative number");return this.map(e=>Math.sqrt(e))},Array.prototype.add=function(e){return this.map(t=>t+e)},Array.prototype.sub=function(e){return this.map(t=>t-e)},Array.prototype.mult=function(e){return this.map(t=>t*e)},Array.prototype.division=function(e){if(e===0)throw new Error("Division by zero");return this.map(t=>t/e)},Array.prototype.pick=function(){return this[Math.floor(n.randomGen()*this.length)]},Array.prototype.beat=function(e=1){return this[n.app.clock.beats_since_origin/e%this.length]},Array.prototype.bar=function(){return this[n.app.clock.time_position.bar%this.length]},Array.prototype.pulse=function(){return this[n.app.clock.time_position.pulse%this.length]},Array.prototype.div=function(e){const t=e,r=n.app.clock.pulses_since_origin,i=Math.floor(r/Math.floor(t*n.ppqn()));return this[i%this.length]},Array.prototype.shuffle=function(){let e=this.length,t;for(;e!==0;)t=Math.floor(Math.random()*e),e--,[this[e],this[t]]=[this[t],this[e]];return this},Array.prototype.rotate=function(e){const t=this.length;if(e<0)e=t+e%t;else if(e>0)e=e%t;else return this;const r=this.splice(-e,e);return this.unshift(...r),this},Array.prototype.unique=function(){const e=new Set;let t=0;for(let r=0;r100)throw new Error("Amount should be between 0 and 100");if(this.length<=1)return this;for(let t=0;t1)this.splice(t,1);else return this;else t++;return this},Array.prototype.repeatAll=function(e=1){if(e<1)throw new Error("Amount should be at least 1");let t=[];for(let r=0;r>1|(Lt&21845)<<1;xi=(xi&52428)>>2|(xi&13107)<<2,xi=(xi&61680)>>4|(xi&3855)<<4,Sm[Lt]=((xi&65280)>>8|(xi&255)<<8)>>1}var Wn=function(n,e,t){for(var r=n.length,i=0,a=new rn(e);i>l]=c}else for(o=new rn(r),i=0;i>15-n[i]);return o},Wi=new gr(288);for(var Lt=0;Lt<144;++Lt)Wi[Lt]=8;for(var Lt=144;Lt<256;++Lt)Wi[Lt]=9;for(var Lt=256;Lt<280;++Lt)Wi[Lt]=7;for(var Lt=280;Lt<288;++Lt)Wi[Lt]=8;var Co=new gr(32);for(var Lt=0;Lt<32;++Lt)Co[Lt]=5;var KP=Wn(Wi,9,0),jP=Wn(Wi,9,1),JP=Wn(Co,5,0),e3=Wn(Co,5,1),Eu=function(n){for(var e=n[0],t=1;te&&(e=n[t]);return e},bn=function(n,e,t){var r=e/8|0;return(n[r]|n[r+1]<<8)>>(e&7)&t},bu=function(n,e){var t=e/8|0;return(n[t]|n[t+1]<<8|n[t+2]<<16)>>(e&7)},yg=function(n){return(n+7)/8|0},Ag=function(n,e,t){(e==null||e<0)&&(e=0),(t==null||t>n.length)&&(t=n.length);var r=new gr(t-e);return r.set(n.subarray(e,t)),r},t3=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Br=function(n,e,t){var r=new Error(e||t3[n]);if(r.code=n,Error.captureStackTrace&&Error.captureStackTrace(r,Br),!t)throw r;return r},Rg=function(n,e,t,r){var i=n.length,a=r?r.length:0;if(!i||e.f&&!e.l)return t||new gr(0);var s=!t||e.i!=2,o=e.i;t||(t=new gr(i*3));var l=function(Qe){var Je=t.length;if(Qe>Je){var rt=new gr(Math.max(Je*2,Qe));rt.set(t),t=rt}},c=e.f||0,d=e.p||0,p=e.b||0,m=e.l,_=e.d,b=e.m,y=e.n,A=i*8;do{if(!m){c=bn(n,d,1);var x=bn(n,d+1,3);if(d+=3,x)if(x==1)m=jP,_=e3,b=9,y=5;else if(x==2){var E=bn(n,d,31)+257,S=bn(n,d+10,15)+4,R=E+bn(n,d+5,31)+1;d+=14;for(var w=new gr(R),k=new gr(19),L=0;L>4;if(U<16)w[L++]=U;else{var ee=0,M=0;for(U==16?(M=3+bn(n,d,3),d+=2,ee=w[L-1]):U==17?(M=3+bn(n,d,7),d+=3):U==18&&(M=11+bn(n,d,127),d+=7);M--;)w[L++]=ee}}var G=w.subarray(0,E),K=w.subarray(E);b=Eu(G),y=Eu(K),m=Wn(G,b,1),_=Wn(K,y,1)}else Br(1);else{var U=yg(d)+4,Z=n[U-4]|n[U-3]<<8,f=U+Z;if(f>i){o&&Br(0);break}s&&l(p+Z),t.set(n.subarray(U,f),p),e.b=p+=Z,e.p=d=f*8,e.f=c;continue}if(d>A){o&&Br(0);break}}s&&l(p+131072);for(var X=(1<>4;if(d+=ee&15,d>A){o&&Br(0);break}if(ee||Br(2),Oe<256)t[p++]=Oe;else if(Oe==256){ie=d,m=null;break}else{var xe=Oe-254;if(Oe>264){var L=Oe-257,we=Ac[L];xe=bn(n,d,(1<>4;Ee||Br(3),d+=Ee&15;var K=ZP[Ae];if(Ae>3){var we=Rc[Ae];K+=bu(n,d)&(1<A){o&&Br(0);break}s&&l(p+131072);var ce=p+xe;if(p>8},Fs=function(n,e,t){t<<=e&7;var r=e/8|0;n[r]|=t,n[r+1]|=t>>8,n[r+2]|=t>>16},Tu=function(n,e){for(var t=[],r=0;rm&&(m=a[r].s);var _=new rn(m+1),b=Om(t[d-1],_,0);if(b>e){var r=0,y=0,A=b-e,x=1<e)y+=x-(1<>=A;y>0;){var Z=a[r].s;_[Z]=0&&y;--r){var f=a[r].s;_[f]==e&&(--_[f],++y)}b=e}return{t:new gr(_),l:b}},Om=function(n,e,t){return n.s==-1?Math.max(Om(n.l,e,t+1),Om(n.r,e,t+1)):e[n.s]=t},kO=function(n){for(var e=n.length;e&&!n[--e];);for(var t=new rn(++e),r=0,i=n[0],a=1,s=function(l){t[r++]=l},o=1;o<=e;++o)if(n[o]==i&&o!=e)++a;else{if(!i&&a>2){for(;a>138;a-=138)s(32754);a>2&&(s(a>10?a-11<<5|28690:a-3<<5|12305),a=0)}else if(a>3){for(s(i),--a;a>6;a-=6)s(8304);a>2&&(s(a-3<<5|8208),a=0)}for(;a--;)s(i);a=1,i=n[o]}return{c:t.subarray(0,r),n:e}},Ys=function(n,e){for(var t=0,r=0;r>8,n[i+2]=n[i]^255,n[i+3]=n[i+1]^255;for(var a=0;a4&&!L[gm[J-1]];--J);var re=c+5<<3,te=Ys(i,Wi)+Ys(a,Co)+s,ee=Ys(i,m)+Ys(a,y)+s+14+3*J+Ys(R,L)+2*R[16]+3*R[17]+7*R[18];if(l>=0&&re<=te&&re<=ee)return zA(e,d,n.subarray(l,l+c));var M,G,K,X;if(si(e,d,1+(ee15&&(si(e,d,xe[w]>>5&127),d+=xe[w]>>12)}}else M=KP,G=Wi,K=JP,X=Co;for(var w=0;w255){var we=Ee>>18&31;Fs(e,d,M[we+257]),d+=G[we+257],we>7&&(si(e,d,Ee>>23&31),d+=Ac[we]);var Ae=Ee&31;Fs(e,d,K[Ae]),d+=X[Ae],Ae>3&&(Fs(e,d,Ee>>5&8191),d+=Rc[Ae])}else Fs(e,d,M[Ee]),d+=G[Ee]}return Fs(e,d,M[256]),d+G[256]},r3=new vg([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),WA=new gr(0),n3=function(n,e,t,r,i,a){var s=a.z||n.length,o=new gr(r+s+5*(1+Math.ceil(s/7e3))+i),l=o.subarray(r,o.length-i),c=a.l,d=(a.r||0)&7;if(e){d&&(l[0]=a.r>>3);for(var p=r3[e-1],m=p>>13,_=p&8191,b=(1<7e3||L>24576)&&(M>423||!c)){d=MO(n,l,0,f,E,S,w,L,J,k-J,d),L=R=w=0,J=k;for(var G=0;G<286;++G)E[G]=0;for(var G=0;G<30;++G)S[G]=0}var K=2,X=0,oe=_,ie=te-ee&32767;if(M>2&&re==Z(k-ie))for(var Oe=Math.min(m,M)-1,xe=Math.min(32767,k),we=Math.min(258,M);ie<=xe&&--oe&&te!=ee;){if(n[k+K]==n[k+K-ie]){for(var Ee=0;EeK){if(K=Ee,X=ie,Ee>Oe)break;for(var Ae=Math.min(ie,Ee-2),ce=0,G=0;Gce&&(ce=Qe,ee=ke)}}}te=ee,ee=y[te],ie+=te-ee&32767}if(X){f[L++]=268435456|_m[K]<<18|LO[X];var Je=_m[K]&31,rt=LO[X]&31;w+=Ac[Je]+Rc[rt],++E[257+Je],++S[rt],F=k+K,++R}else f[L++]=n[k],++E[n[k]]}}for(k=Math.max(k,F);k=s&&(l[d/8|0]=c,dt=s),d=zA(l,d+1,n.subarray(k,dt))}a.i=s}return Ag(o,0,r+yg(d)+i)},i3=function(){for(var n=new Int32Array(256),e=0;e<256;++e){for(var t=e,r=9;--r;)t=(t&1&&-306674912)^t>>>1;n[e]=t}return n}(),a3=function(){var n=-1;return{p:function(e){for(var t=n,r=0;r>>8;n=t},d:function(){return~n}}},s3=function(n,e,t,r,i){if(!i&&(i={l:1},e.dictionary)){var a=e.dictionary.subarray(-32768),s=new gr(a.length+n.length);s.set(a),s.set(n,a.length),n=s,i.w=a.length}return n3(n,e.level==null?6:e.level,e.mem==null?Math.ceil(Math.max(8,Math.min(13,Math.log(n.length)))*1.5):12+e.mem,t,r,i)},Em=function(n,e,t){for(;t;++e)n[e]=t,t>>>=8},o3=function(n,e){var t=e.filename;if(n[0]=31,n[1]=139,n[2]=8,n[8]=e.level<2?4:e.level==9?2:0,n[9]=3,e.mtime!=0&&Em(n,4,Math.floor(new Date(e.mtime||Date.now())/1e3)),t){n[3]=8;for(var r=0;r<=t.length;++r)n[r+10]=t.charCodeAt(r)}},l3=function(n){(n[0]!=31||n[1]!=139||n[2]!=8)&&Br(6,"invalid gzip data");var e=n[3],t=10;e&4&&(t+=(n[10]|n[11]<<8)+2);for(var r=(e>>3&1)+(e>>4&1);r>0;r-=!n[t++]);return t+(e&2)},c3=function(n){var e=n.length;return(n[e-4]|n[e-3]<<8|n[e-2]<<16|n[e-1]<<24)>>>0},u3=function(n){return 10+(n.filename?n.filename.length+1:0)},d3=function(n,e){return((n[0]&15)!=8||n[0]>>4>7||(n[0]<<8|n[1])%31)&&Br(6,"invalid zlib data"),(n[1]>>5&1)==+!e&&Br(6,"invalid zlib data: "+(n[1]&32?"need":"unexpected")+" dictionary"),(n[1]>>3&4)+2};function p3(n,e){return Rg(n,{i:2},e&&e.out,e&&e.dictionary)}function f3(n,e){e||(e={});var t=a3(),r=n.length;t.p(n);var i=s3(n,e,u3(e),8),a=i.length;return o3(i,e),Em(i,a-8,t.d()),Em(i,a-4,r),i}function h3(n,e){var t=l3(n);return t+8>n.length&&Br(6,"invalid gzip data"),Rg(n.subarray(t,-8),{i:2},e&&e.out||new gr(c3(n)),e&&e.dictionary)}function m3(n,e){return Rg(n.subarray(d3(n,e&&e.dictionary),-4),{i:2},e&&e.out,e&&e.dictionary)}function g3(n,e){return n[0]==31&&n[1]==139&&n[2]==8?h3(n,e):(n[0]&15)!=8||n[0]>>4>7||(n[0]<<8|n[1])%31?p3(n,e):m3(n,e)}var bm=typeof TextDecoder<"u"&&new TextDecoder,_3=0;try{bm.decode(WA,{stream:!0}),_3=1}catch{}var S3=function(n){for(var e="",t=0;;){var r=n[t++],i=(r>127)+(r>223)+(r>239);if(t+i>n.length)return{s:e,r:Ag(n,t-1)};i?i==3?(r=((r&15)<<18|(n[t++]&63)<<12|(n[t++]&63)<<6|n[t++]&63)-65536,e+=String.fromCharCode(55296|r>>10,56320|r&1023)):i&1?e+=String.fromCharCode((r&31)<<6|n[t++]&63):e+=String.fromCharCode((r&15)<<12|(n[t++]&63)<<6|n[t++]&63):e+=String.fromCharCode(r)}};function O3(n,e){if(e){for(var t="",r=0;r (GFM Style)",type:"boolean"},requireSpaceBeforeHeadingText:{defaultValue:!1,describe:"Makes adding a space between `#` and the header text mandatory (GFM Style)",type:"boolean"},ghMentions:{defaultValue:!1,describe:"Enables github @mentions",type:"boolean"},ghMentionsLink:{defaultValue:"https://github.com/{u}",describe:"Changes the link generated by @mentions. Only applies if ghMentions option is enabled.",type:"string"},encodeEmails:{defaultValue:!0,describe:"Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities",type:"boolean"},openLinksInNewWindow:{defaultValue:!1,describe:"Open all links in new windows",type:"boolean"},backslashEscapesHTMLTags:{defaultValue:!1,describe:"Support for HTML Tag escaping. ex: