From 7401e35f1300eb8b381b34d1a0199741e9406306 Mon Sep 17 00:00:00 2001 From: Bubobubobubobubo Date: Tue, 24 Oct 2023 21:04:19 +0000 Subject: [PATCH] deploy: bb8701a8652a79f183430bbb8452f449df028c44 --- assets/{index-3213dcac.js => index-b9f2e5a8.js} | 7 +++++-- index.html | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) rename assets/{index-3213dcac.js => index-b9f2e5a8.js} (97%) diff --git a/assets/index-3213dcac.js b/assets/index-b9f2e5a8.js similarity index 97% rename from assets/index-3213dcac.js rename to assets/index-b9f2e5a8.js index a7d71f4..1b839a5 100644 --- a/assets/index-3213dcac.js +++ b/assets/index-b9f2e5a8.js @@ -290,7 +290,7 @@ z3('can can:2').sound().gain(1).cutoff(osci).out() z4('1/4 kick kick snare kick').sound().gain(1).cutoff(osci).out()`],ab=r=>{r=1831565813+(r|=0)|0;let e=Math.imul(r^r>>>15,1|r);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296};class pM{constructor(e){this.dictionaries=void 0,this.length=void 0,this.separator=void 0,this.style=void 0,this.seed=void 0;const{length:t,separator:n,dictionaries:i,style:a,seed:s}=e;this.dictionaries=i,this.separator=n,this.length=t,this.style=a,this.seed=s}generate(){if(!this.dictionaries)throw new Error('Cannot find any dictionary. Please provide at least one, or leave the "dictionary" field empty in the config object');if(this.length<=0)throw new Error("Invalid length provided");if(this.length>this.dictionaries.length)throw new Error(`The length cannot be bigger than the number of dictionaries. Length provided: ${this.length}. Number of dictionaries provided: ${this.dictionaries.length}`);let e=this.seed;return this.dictionaries.slice(0,this.length).reduce((t,n)=>{let i;e?(i=(s=>{if(typeof s=="string"){const o=s.split("").map(c=>c.charCodeAt(0)).reduce((c,u)=>c+u,1),l=Math.floor(Number(o));return ab(l)}return ab(s)})(e),e=4294967296*i):i=Math.random();let a=n[Math.floor(i*n.length)]||"";if(this.style==="lowerCase")a=a.toLowerCase();else if(this.style==="capital"){const[s,...o]=a.split("");a=s.toUpperCase()+o.join("")}else this.style==="upperCase"&&(a=a.toUpperCase());return t?`${t}${this.separator}${a}`:`${a}`},"")}}const sb={separator:"_",dictionaries:[]},fM=r=>{const e=[...r&&r.dictionaries||sb.dictionaries],t={...sb,...r,length:r&&r.length||e.length,dictionaries:e};if(!r||!r.dictionaries||!r.dictionaries.length)throw new Error('A "dictionaries" array must be provided. This is a breaking change introduced starting from Unique Name Generator v4. Read more about the breaking change here: https://github.com/andreasonny83/unique-names-generator#migration-guide');return new pM(t).generate()};var hM=["aardvark","aardwolf","albatross","alligator","alpaca","amphibian","anaconda","angelfish","anglerfish","ant","anteater","antelope","antlion","ape","aphid","armadillo","asp","baboon","badger","bandicoot","barnacle","barracuda","basilisk","bass","bat","bear","beaver","bedbug","bee","beetle","bird","bison","blackbird","boa","boar","bobcat","bobolink","bonobo","booby","bovid","bug","butterfly","buzzard","camel","canid","canidae","capybara","cardinal","caribou","carp","cat","caterpillar","catfish","catshark","cattle","centipede","cephalopod","chameleon","cheetah","chickadee","chicken","chimpanzee","chinchilla","chipmunk","cicada","clam","clownfish","cobra","cockroach","cod","condor","constrictor","coral","cougar","cow","coyote","crab","crane","crawdad","crayfish","cricket","crocodile","crow","cuckoo","damselfly","deer","dingo","dinosaur","dog","dolphin","donkey","dormouse","dove","dragon","dragonfly","duck","eagle","earthworm","earwig","echidna","eel","egret","elephant","elk","emu","ermine","falcon","felidae","ferret","finch","firefly","fish","flamingo","flea","fly","flyingfish","fowl","fox","frog","galliform","gamefowl","gayal","gazelle","gecko","gerbil","gibbon","giraffe","goat","goldfish","goose","gopher","gorilla","grasshopper","grouse","guan","guanaco","guineafowl","gull","guppy","haddock","halibut","hamster","hare","harrier","hawk","hedgehog","heron","herring","hippopotamus","hookworm","hornet","horse","hoverfly","hummingbird","hyena","iguana","impala","jackal","jaguar","jay","jellyfish","junglefowl","kangaroo","kingfisher","kite","kiwi","koala","koi","krill","ladybug","lamprey","landfowl","lark","leech","lemming","lemur","leopard","leopon","limpet","lion","lizard","llama","lobster","locust","loon","louse","lungfish","lynx","macaw","mackerel","magpie","mammal","manatee","mandrill","marlin","marmoset","marmot","marsupial","marten","mastodon","meadowlark","meerkat","mink","minnow","mite","mockingbird","mole","mollusk","mongoose","monkey","moose","mosquito","moth","mouse","mule","muskox","narwhal","newt","nightingale","ocelot","octopus","opossum","orangutan","orca","ostrich","otter","owl","ox","panda","panther","parakeet","parrot","parrotfish","partridge","peacock","peafowl","pelican","penguin","perch","pheasant","pig","pigeon","pike","pinniped","piranha","planarian","platypus","pony","porcupine","porpoise","possum","prawn","primate","ptarmigan","puffin","puma","python","quail","quelea","quokka","rabbit","raccoon","rat","rattlesnake","raven","reindeer","reptile","rhinoceros","roadrunner","rodent","rook","rooster","roundworm","sailfish","salamander","salmon","sawfish","scallop","scorpion","seahorse","shark","sheep","shrew","shrimp","silkworm","silverfish","skink","skunk","sloth","slug","smelt","snail","snake","snipe","sole","sparrow","spider","spoonbill","squid","squirrel","starfish","stingray","stoat","stork","sturgeon","swallow","swan","swift","swordfish","swordtail","tahr","takin","tapir","tarantula","tarsier","termite","tern","thrush","tick","tiger","tiglon","toad","tortoise","toucan","trout","tuna","turkey","turtle","tyrannosaurus","unicorn","urial","vicuna","viper","vole","vulture","wallaby","walrus","warbler","wasp","weasel","whale","whippet","whitefish","wildcat","wildebeest","wildfowl","wolf","wolverine","wombat","woodpecker","worm","wren","xerinae","yak","zebra"],mM=["amaranth","amber","amethyst","apricot","aqua","aquamarine","azure","beige","black","blue","blush","bronze","brown","chocolate","coffee","copper","coral","crimson","cyan","emerald","fuchsia","gold","gray","green","harlequin","indigo","ivory","jade","lavender","lime","magenta","maroon","moccasin","olive","orange","peach","pink","plum","purple","red","rose","salmon","sapphire","scarlet","silver","tan","teal","tomato","turquoise","violet","white","yellow"];const BA=r=>new Promise((e,t)=>setTimeout(()=>t(new Error("Operation took too long")),r)),UA=r=>r.replace(/->/g,"&&").replace(/::/g,"&&"),e_=(r,e)=>new Promise((t,n)=>{try{Function(`"use strict";try{ ${UA(e)}; /* break block comments */; - } catch (e) {console.log(e); _reportError(e);};`).call(r.api),t(!0)}catch(i){r.interface.error_line.innerHTML=i,console.log(i),t(!1)}}),es=new Map,gM=20,_M=(r,e)=>{es.size>=gM&&es.delete(es.keys().next().value),es.set(r,e)},Ra=async(r,e,t=5e3)=>{try{e.evaluations++;const n=e.candidate;if(es.has(n))es.get(n).call(r.api);else{const i=`let i = ${e.evaluations};`+n;if(await Promise.race([e_(r,i),BA(t)])){e.committed=e.candidate;const s=new Function(`"use strict";try{${UA(i)}} catch (e) {console.log(e); _reportError(e);};`);_M(n,s)}else await SM(r,e,t)}}catch(n){r.interface.error_line.innerHTML=n,console.log(n)}},SM=async(r,e,t=1e3)=>{try{await Promise.race([e_(r,e.committed),BA(t)]),e.evaluations&&e.evaluations++}catch(n){r.interface.error_line.innerHTML=n,console.log(n)}},OM=async(r,e)=>{await e_(r,e)},t_={global:{candidate:"",committed:"",evaluations:0},locals:{1:{candidate:"",committed:"",evaluations:0},2:{candidate:"",committed:"",evaluations:0},3:{candidate:"",committed:"",evaluations:0},4:{candidate:"",committed:"",evaluations:0},5:{candidate:"",committed:"",evaluations:0},6:{candidate:"",committed:"",evaluations:0},7:{candidate:"",committed:"",evaluations:0},8:{candidate:"",committed:"",evaluations:0},9:{candidate:"",committed:"",evaluations:0}},init:{candidate:"",committed:"",evaluations:0},example:{candidate:"",committed:"",evaluations:0},notes:{candidate:""}},Xo={Welcome:{global:{candidate:"",committed:"",evaluations:0},locals:{1:{candidate:"",committed:"",evaluations:0},2:{candidate:"",committed:"",evaluations:0},3:{candidate:"",committed:"",evaluations:0},4:{candidate:"",committed:"",evaluations:0},5:{candidate:"",committed:"",evaluations:0},6:{candidate:"",committed:"",evaluations:0},7:{candidate:"",committed:"",evaluations:0},8:{candidate:"",committed:"",evaluations:0},9:{candidate:"",committed:"",evaluations:0}},init:{candidate:"",committed:"",evaluations:0},example:{candidate:"",committed:"",evaluations:0},notes:{candidate:""}},Help:$L};class bM{constructor(){E(this,"vimMode",!1);E(this,"theme","toposTheme");E(this,"font","IBM Plex Mono");E(this,"font_size",24);E(this,"universes");E(this,"selected_universe","Default");E(this,"line_numbers",!0);E(this,"time_position",!0);E(this,"tips",!0);E(this,"send_clock",!1);E(this,"midi_channels_scripts",!0);E(this,"midi_clock_input");E(this,"default_midi_input");E(this,"midi_clock_ppqn",24);E(this,"load_demo_songs",!0);const e=JSON.parse(localStorage.getItem("topos")||"{}");e&&Object.keys(e).length!==0?(this.vimMode=e.vimMode,this.theme=e.theme,this.font=e.font,this.font_size=e.font_size,this.universes=e.universes,this.selected_universe=e.selected_universe,this.line_numbers=e.line_numbers,this.time_position=e.time_position,this.tips=e.tips,this.send_clock=e.send_clock,this.midi_channels_scripts=e.midi_channels_scripts,this.midi_clock_input=e.midi_clock_input,this.midi_clock_ppqn=e.midi_clock_ppqn||24,this.default_midi_input=e.default_midi_input,this.load_demo_songs=e.load_demo_songs):this.universes=Xo}get_universe(){this.universes.universe_name}get data(){return{vimMode:this.vimMode,theme:this.theme,font:this.font,font_size:this.font_size,universes:this.universes,selected_universe:this.selected_universe,line_numbers:this.line_numbers,time_position:this.time_position,tips:this.tips,send_clock:this.send_clock,midi_channels_scripts:this.midi_channels_scripts,midi_clock_input:this.midi_clock_input,midi_clock_ppqn:this.midi_clock_ppqn,default_midi_input:this.default_midi_input,load_demo_songs:this.load_demo_songs}}saveApplicationToLocalStorage(e,t){this.universes=e,this.vimMode=t.vimMode,this.font=t.font,this.font_size=t.font_size,this.selected_universe=t.selected_universe,this.line_numbers=t.line_numbers,this.time_position=t.time_position,this.tips=t.tips,this.send_clock=t.send_clock,this.midi_channels_scripts=t.midi_channels_scripts,this.midi_clock_input=t.midi_clock_input,this.midi_clock_ppqn=t.midi_clock_ppqn,this.default_midi_input=t.default_midi_input,this.load_demo_songs=t.load_demo_songs,localStorage.setItem("topos",JSON.stringify(this.data))}}const EM=r=>{if(r.settings.load_demo_songs){let e=wc[Math.floor(Math.random()*wc.length)];r.selected_universe="Welcome",r.universes[r.selected_universe].global.committed=e,r.universes[r.selected_universe].global.candidate=e}else r.selected_universe=r.settings.selected_universe,r.universes[r.selected_universe]===void 0&&(r.universes[r.selected_universe]=structuredClone(t_));r.interface.universe_viewer.innerHTML=`Topos: ${r.selected_universe}`},FA=()=>{window.history.replaceState({},document.title,"/")},vM=async r=>{async function e(s){const o=await new Promise(l=>{const c=new FileReader;c.onload=()=>l(c.result),c.readAsDataURL(new Blob([s]))});return o.slice(o.indexOf(",")+1)}let t=JSON.stringify({universe:r.settings.universes[r.selected_universe]}),n=aM(new TextEncoder().encode(t),{level:9});const i=await e(n),a=new URL(window.location.href);a.searchParams.set("universe",i),window.history.replaceState({},"",a.toString()),navigator.clipboard.writeText(a.toString())},TM=r=>{let e=new URLSearchParams(window.location.search);if(e!==void 0){let t;if(e!==null){const n=e.get("universe");if(n!==null){let i=Uint8Array.from(atob(n),s=>s.charCodeAt(0));t=JSON.parse(dM(lM(i)));const a=fM({length:2,separator:"_",dictionaries:[mM,hM]});Dc(r,a,t.universe),FA()}}}},Dc=(r,e,t=t_)=>{console.log(e,t),r.currentFile().candidate=r.view.state.doc.toString();let n=e.trim();r.universes[n]===void 0&&(r.settings.universes[n]=t,r.universes[n]=t),r.selected_universe=n,r.settings.selected_universe=r.selected_universe,r.interface.universe_viewer.innerHTML=`Topos: ${n}`,r.updateEditorView(),Ra(r,r.universes[r.selected_universe.toString()].init)},xc=()=>{document.getElementById("modal-buffers").classList.contains("invisible")?(document.getElementById("editor").classList.add("invisible"),document.getElementById("modal-buffers").classList.remove("invisible"),document.getElementById("buffer-search").focus()):Vm()},Vm=()=>{document.getElementById("buffer-search").value="",document.getElementById("editor").classList.remove("invisible"),document.getElementById("modal-buffers").classList.add("invisible")},CM=()=>{document.getElementById("modal-settings").classList.contains("invisible")?(document.getElementById("editor").classList.add("invisible"),document.getElementById("modal-settings").classList.remove("invisible")):yM()},yM=()=>{document.getElementById("editor").classList.remove("invisible"),document.getElementById("modal-settings").classList.add("invisible")},AM={topos_logo:"topos-logo",fill_viewer:"fillviewer",load_universe_button:"load-universe-button",download_universe_button:"download-universes",upload_universe_button:"upload-universes",destroy_universes_button:"destroy-universes",documentation_button:"doc-button-1",eval_button:"eval-button-1",local_button:"local-button",global_button:"global-button",init_button:"init-button",note_button:"note-button",settings_button:"settings-button",close_settings_button:"close-settings-button",close_universes_button:"close-universes-button",universe_viewer:"universe-viewer",buffer_modal:"modal-buffers",buffer_search:"buffer-search",universe_creator:"universe-creator",local_script_tabs:"local-script-tabs",font_size_input:"font-size-input",font_family_selector:"font-family",vim_mode_checkbox:"vim-mode",line_numbers_checkbox:"show-line-numbers",time_position_checkbox:"show-time-position",tips_checkbox:"show-tips",midi_clock_checkbox:"send-midi-clock",midi_channels_scripts:"midi-channels-scripts",midi_clock_ppqn:"midi-clock-ppqn-input",load_demo_songs:"load-demo-songs",normal_mode_button:"normal-mode",vim_mode_button:"vim-mode",share_button:"share-button",audio_nudge_range:"audio_nudge",dough_nudge_range:"dough_nudge",error_line:"error_line",hydra_canvas:"hydra-bg",feedback:"feedback",scope:"scope"},IM={play_buttons:["play-button-1"],stop_buttons:["stop-button-1"],clear_buttons:["clear-button-1"]},ob={h1:"text-white lg:text-4xl text-xl lg:ml-4 lg:mx-4 mx-2 lg:my-4 my-2 lg:mb-4 mb-4 bg-neutral-900 rounded-lg py-2 px-2",h2:"text-white lg:text-3xl text-xl lg:ml-4 lg:mx-4 mx-2 lg:my-4 my-2 lg:mb-4 mb-4 bg-neutral-900 rounded-lg py-2 px-2",h3:"text-white lg:text-2xl text-xl lg:ml-4 lg:mx-4 mx-2 lg:my-4 my-2 lg:mb-4 mb-4 bg-neutral-700 rounded-lg py-2 px-2 lg:mt-16",ul:"text-underline pl-6",li:"list-disc lg:text-2xl text-base text-white lg:mx-4 mx-2 my-4 my-2 leading-normal",p:"lg:text-2xl text-base text-white lg:mx-6 mx-2 my-4 leading-normal",warning:"animate-pulse lg:text-2xl font-bold text-rose-600 lg:mx-6 mx-2 my-4 leading-normal",a:"lg:text-2xl text-base text-orange-300",code:"lg:my-4 sm:my-1 text-base lg:text-xl block whitespace-pre overflow-x-hidden",icode:"lg:my-1 my-1 lg:text-xl sm:text-xs text-white font-mono bg-neutral-600",ic:"lg:my-1 my-1 lg:text-xl sm:text-xs text-white font-mono bg-neutral-600",blockquote:"text-neutral-200 border-l-4 border-neutral-500 pl-4 my-4 mx-4",details:"lg:mx-12 py-2 px-6 lg:text-2xl text-white rounded-lg bg-neutral-600",summary:"font-semibold text-xl",table:"justify-center lg:my-12 my-2 lg:mx-12 mx-2 lg:text-2xl text-base w-full text-left text-white border-collapse",thead:"text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400",th:"",td:"",tr:""};function Xr(){var r=arguments[0];typeof r=="string"&&(r=document.createElement(r));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var i=t[n];typeof i=="string"?r.setAttribute(n,i):i!=null&&(r[n]=i)}e++}for(;er.normalize("NFKD"):r=>r;class n_{constructor(e,t,n=0,i=e.length,a,s){this.test=s,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=a?o=>a(lb(o)):lb,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return On(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=Sg(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=mr(e);let i=this.normalize(t);for(let a=0,s=n;;a++){let o=i.charCodeAt(a),l=this.match(o,s);if(a==i.length-1){if(l)return this.value=l,this;break}s==n&&athis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,i=n+t[0].length;if(this.matchPos=kc(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(nthis.value.to)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length=n||i.to<=t){let o=new os(t,e.sliceString(t,n));return id.set(e,o),o}if(i.from==t&&i.to==n)return i;let{text:a,from:s}=i;return s>t&&(a=e.sliceString(t,s)+a,s=t),i.to=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let n=this.flat.from+t.index,i=n+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this.matchPos=kc(this.text,i+(n==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=os.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(i_.prototype[Symbol.iterator]=GA.prototype[Symbol.iterator]=function(){return this});function RM(r){try{return new RegExp(r,r_),!0}catch{return!1}}function kc(r,e){if(e>=r.length)return e;let t=r.lineAt(e),n;for(;e=56320&&n<57344;)e++;return e}const NM={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},QA=$e.define({combine(r){return yi(r,NM,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function wM(r){let e=[MM,LM];return r&&e.push(QA.of(r)),e}const DM=Ke.mark({class:"cm-selectionMatch"}),xM=Ke.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function cb(r,e,t,n){return(t==0||r(e.sliceDoc(t-1,t))!=Yt.Word)&&(n==e.doc.length||r(e.sliceDoc(n,n+1))!=Yt.Word)}function kM(r,e,t,n){return r(e.sliceDoc(t,t+1))==Yt.Word&&r(e.sliceDoc(n-1,n))==Yt.Word}const LM=vn.fromClass(class{constructor(r){this.decorations=this.getDeco(r)}update(r){(r.selectionSet||r.docChanged||r.viewportChanged)&&(this.decorations=this.getDeco(r.view))}getDeco(r){let e=r.state.facet(QA),{state:t}=r,n=t.selection;if(n.ranges.length>1)return Ke.none;let i=n.main,a,s=null;if(i.empty){if(!e.highlightWordAroundCursor)return Ke.none;let l=t.wordAt(i.head);if(!l)return Ke.none;s=t.charCategorizer(i.head),a=t.sliceDoc(l.from,l.to)}else{let l=i.to-i.from;if(l200)return Ke.none;if(e.wholeWords){if(a=t.sliceDoc(i.from,i.to),s=t.charCategorizer(i.head),!(cb(s,t,i.from,i.to)&&kM(s,t,i.from,i.to)))return Ke.none}else if(a=t.sliceDoc(i.from,i.to).trim(),!a)return Ke.none}let o=[];for(let l of r.visibleRanges){let c=new n_(t.doc,a,l.from,l.to);for(;!c.next().done;){let{from:u,to:p}=c.value;if((!s||cb(s,t,u,p))&&(i.empty&&u<=i.from&&p>=i.to?o.push(xM.range(u,p)):(u>=i.to||p<=i.from)&&o.push(DM.range(u,p)),o.length>e.maxMatches))return Ke.none}}return Ke.set(o)}},{decorations:r=>r.decorations}),MM=Me.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});class PM{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||RM(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,n)=>n=="n"?` + } catch (e) {console.log(e); _reportError(e);};`).call(r.api),t(!0)}catch(i){r.interface.error_line.innerHTML=i,r.api._reportError(i),t(!1)}}),es=new Map,gM=20,_M=(r,e)=>{es.size>=gM&&es.delete(es.keys().next().value),es.set(r,e)},Ra=async(r,e,t=5e3)=>{try{e.evaluations++;const n=e.candidate;if(es.has(n))es.get(n).call(r.api);else{const i=`let i = ${e.evaluations};`+n;if(await Promise.race([e_(r,i),BA(t)])){e.committed=e.candidate;const s=new Function(`"use strict";try{${UA(i)}} catch (e) {console.log(e); _reportError(e);};`);_M(n,s)}else await SM(r,e,t)}}catch(n){r.interface.error_line.innerHTML=n,r.api._reportError(n)}},SM=async(r,e,t=1e3)=>{try{await Promise.race([e_(r,e.committed),BA(t)]),e.evaluations&&e.evaluations++}catch(n){r.interface.error_line.innerHTML=n,console.log(n)}},OM=async(r,e)=>{await e_(r,e)},t_={global:{candidate:"",committed:"",evaluations:0},locals:{1:{candidate:"",committed:"",evaluations:0},2:{candidate:"",committed:"",evaluations:0},3:{candidate:"",committed:"",evaluations:0},4:{candidate:"",committed:"",evaluations:0},5:{candidate:"",committed:"",evaluations:0},6:{candidate:"",committed:"",evaluations:0},7:{candidate:"",committed:"",evaluations:0},8:{candidate:"",committed:"",evaluations:0},9:{candidate:"",committed:"",evaluations:0}},init:{candidate:"",committed:"",evaluations:0},example:{candidate:"",committed:"",evaluations:0},notes:{candidate:""}},Xo={Welcome:{global:{candidate:"",committed:"",evaluations:0},locals:{1:{candidate:"",committed:"",evaluations:0},2:{candidate:"",committed:"",evaluations:0},3:{candidate:"",committed:"",evaluations:0},4:{candidate:"",committed:"",evaluations:0},5:{candidate:"",committed:"",evaluations:0},6:{candidate:"",committed:"",evaluations:0},7:{candidate:"",committed:"",evaluations:0},8:{candidate:"",committed:"",evaluations:0},9:{candidate:"",committed:"",evaluations:0}},init:{candidate:"",committed:"",evaluations:0},example:{candidate:"",committed:"",evaluations:0},notes:{candidate:""}},Help:$L};class bM{constructor(){E(this,"vimMode",!1);E(this,"theme","toposTheme");E(this,"font","IBM Plex Mono");E(this,"font_size",24);E(this,"universes");E(this,"selected_universe","Default");E(this,"line_numbers",!0);E(this,"time_position",!0);E(this,"tips",!0);E(this,"send_clock",!1);E(this,"midi_channels_scripts",!0);E(this,"midi_clock_input");E(this,"default_midi_input");E(this,"midi_clock_ppqn",24);E(this,"load_demo_songs",!0);const e=JSON.parse(localStorage.getItem("topos")||"{}");e&&Object.keys(e).length!==0?(this.vimMode=e.vimMode,this.theme=e.theme,this.font=e.font,this.font_size=e.font_size,this.universes=e.universes,this.selected_universe=e.selected_universe,this.line_numbers=e.line_numbers,this.time_position=e.time_position,this.tips=e.tips,this.send_clock=e.send_clock,this.midi_channels_scripts=e.midi_channels_scripts,this.midi_clock_input=e.midi_clock_input,this.midi_clock_ppqn=e.midi_clock_ppqn||24,this.default_midi_input=e.default_midi_input,this.load_demo_songs=e.load_demo_songs):this.universes=Xo}get_universe(){this.universes.universe_name}get data(){return{vimMode:this.vimMode,theme:this.theme,font:this.font,font_size:this.font_size,universes:this.universes,selected_universe:this.selected_universe,line_numbers:this.line_numbers,time_position:this.time_position,tips:this.tips,send_clock:this.send_clock,midi_channels_scripts:this.midi_channels_scripts,midi_clock_input:this.midi_clock_input,midi_clock_ppqn:this.midi_clock_ppqn,default_midi_input:this.default_midi_input,load_demo_songs:this.load_demo_songs}}saveApplicationToLocalStorage(e,t){this.universes=e,this.vimMode=t.vimMode,this.font=t.font,this.font_size=t.font_size,this.selected_universe=t.selected_universe,this.line_numbers=t.line_numbers,this.time_position=t.time_position,this.tips=t.tips,this.send_clock=t.send_clock,this.midi_channels_scripts=t.midi_channels_scripts,this.midi_clock_input=t.midi_clock_input,this.midi_clock_ppqn=t.midi_clock_ppqn,this.default_midi_input=t.default_midi_input,this.load_demo_songs=t.load_demo_songs,localStorage.setItem("topos",JSON.stringify(this.data))}}const EM=r=>{if(r.settings.load_demo_songs){let e=wc[Math.floor(Math.random()*wc.length)];r.selected_universe="Welcome",r.universes[r.selected_universe].global.committed=e,r.universes[r.selected_universe].global.candidate=e}else r.selected_universe=r.settings.selected_universe,r.universes[r.selected_universe]===void 0&&(r.universes[r.selected_universe]=structuredClone(t_));r.interface.universe_viewer.innerHTML=`Topos: ${r.selected_universe}`},FA=()=>{window.history.replaceState({},document.title,"/")},vM=async r=>{async function e(s){const o=await new Promise(l=>{const c=new FileReader;c.onload=()=>l(c.result),c.readAsDataURL(new Blob([s]))});return o.slice(o.indexOf(",")+1)}let t=JSON.stringify({universe:r.settings.universes[r.selected_universe]}),n=aM(new TextEncoder().encode(t),{level:9});const i=await e(n),a=new URL(window.location.href);a.searchParams.set("universe",i),window.history.replaceState({},"",a.toString()),navigator.clipboard.writeText(a.toString())},TM=r=>{let e=new URLSearchParams(window.location.search);if(e!==void 0){let t;if(e!==null){const n=e.get("universe");if(n!==null){let i=Uint8Array.from(atob(n),s=>s.charCodeAt(0));t=JSON.parse(dM(lM(i)));const a=fM({length:2,separator:"_",dictionaries:[mM,hM]});Dc(r,a,t.universe),FA()}}}},Dc=(r,e,t=t_)=>{console.log(e,t),r.currentFile().candidate=r.view.state.doc.toString();let n=e.trim();r.universes[n]===void 0&&(r.settings.universes[n]=t,r.universes[n]=t),r.selected_universe=n,r.settings.selected_universe=r.selected_universe,r.interface.universe_viewer.innerHTML=`Topos: ${n}`,r.updateEditorView(),Ra(r,r.universes[r.selected_universe.toString()].init)},xc=()=>{document.getElementById("modal-buffers").classList.contains("invisible")?(document.getElementById("editor").classList.add("invisible"),document.getElementById("modal-buffers").classList.remove("invisible"),document.getElementById("buffer-search").focus()):Vm()},Vm=()=>{document.getElementById("buffer-search").value="",document.getElementById("editor").classList.remove("invisible"),document.getElementById("modal-buffers").classList.add("invisible")},CM=()=>{document.getElementById("modal-settings").classList.contains("invisible")?(document.getElementById("editor").classList.add("invisible"),document.getElementById("modal-settings").classList.remove("invisible")):yM()},yM=()=>{document.getElementById("editor").classList.remove("invisible"),document.getElementById("modal-settings").classList.add("invisible")},AM={topos_logo:"topos-logo",fill_viewer:"fillviewer",load_universe_button:"load-universe-button",download_universe_button:"download-universes",upload_universe_button:"upload-universes",destroy_universes_button:"destroy-universes",documentation_button:"doc-button-1",eval_button:"eval-button-1",local_button:"local-button",global_button:"global-button",init_button:"init-button",note_button:"note-button",settings_button:"settings-button",close_settings_button:"close-settings-button",close_universes_button:"close-universes-button",universe_viewer:"universe-viewer",buffer_modal:"modal-buffers",buffer_search:"buffer-search",universe_creator:"universe-creator",local_script_tabs:"local-script-tabs",font_size_input:"font-size-input",font_family_selector:"font-family",vim_mode_checkbox:"vim-mode",line_numbers_checkbox:"show-line-numbers",time_position_checkbox:"show-time-position",tips_checkbox:"show-tips",midi_clock_checkbox:"send-midi-clock",midi_channels_scripts:"midi-channels-scripts",midi_clock_ppqn:"midi-clock-ppqn-input",load_demo_songs:"load-demo-songs",normal_mode_button:"normal-mode",vim_mode_button:"vim-mode",share_button:"share-button",audio_nudge_range:"audio_nudge",dough_nudge_range:"dough_nudge",error_line:"error_line",hydra_canvas:"hydra-bg",feedback:"feedback",scope:"scope"},IM={play_buttons:["play-button-1"],stop_buttons:["stop-button-1"],clear_buttons:["clear-button-1"]},ob={h1:"text-white lg:text-4xl text-xl lg:ml-4 lg:mx-4 mx-2 lg:my-4 my-2 lg:mb-4 mb-4 bg-neutral-900 rounded-lg py-2 px-2",h2:"text-white lg:text-3xl text-xl lg:ml-4 lg:mx-4 mx-2 lg:my-4 my-2 lg:mb-4 mb-4 bg-neutral-900 rounded-lg py-2 px-2",h3:"text-white lg:text-2xl text-xl lg:ml-4 lg:mx-4 mx-2 lg:my-4 my-2 lg:mb-4 mb-4 bg-neutral-700 rounded-lg py-2 px-2 lg:mt-16",ul:"text-underline pl-6",li:"list-disc lg:text-2xl text-base text-white lg:mx-4 mx-2 my-4 my-2 leading-normal",p:"lg:text-2xl text-base text-white lg:mx-6 mx-2 my-4 leading-normal",warning:"animate-pulse lg:text-2xl font-bold text-rose-600 lg:mx-6 mx-2 my-4 leading-normal",a:"lg:text-2xl text-base text-orange-300",code:"lg:my-4 sm:my-1 text-base lg:text-xl block whitespace-pre overflow-x-hidden",icode:"lg:my-1 my-1 lg:text-xl sm:text-xs text-white font-mono bg-neutral-600",ic:"lg:my-1 my-1 lg:text-xl sm:text-xs text-white font-mono bg-neutral-600",blockquote:"text-neutral-200 border-l-4 border-neutral-500 pl-4 my-4 mx-4",details:"lg:mx-12 py-2 px-6 lg:text-2xl text-white rounded-lg bg-neutral-600",summary:"font-semibold text-xl",table:"justify-center lg:my-12 my-2 lg:mx-12 mx-2 lg:text-2xl text-base w-full text-left text-white border-collapse",thead:"text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400",th:"",td:"",tr:""};function Xr(){var r=arguments[0];typeof r=="string"&&(r=document.createElement(r));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var i=t[n];typeof i=="string"?r.setAttribute(n,i):i!=null&&(r[n]=i)}e++}for(;er.normalize("NFKD"):r=>r;class n_{constructor(e,t,n=0,i=e.length,a,s){this.test=s,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=a?o=>a(lb(o)):lb,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return On(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=Sg(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=mr(e);let i=this.normalize(t);for(let a=0,s=n;;a++){let o=i.charCodeAt(a),l=this.match(o,s);if(a==i.length-1){if(l)return this.value=l,this;break}s==n&&athis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,i=n+t[0].length;if(this.matchPos=kc(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(nthis.value.to)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length=n||i.to<=t){let o=new os(t,e.sliceString(t,n));return id.set(e,o),o}if(i.from==t&&i.to==n)return i;let{text:a,from:s}=i;return s>t&&(a=e.sliceString(t,s)+a,s=t),i.to=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let n=this.flat.from+t.index,i=n+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,t)))return this.value={from:n,to:i,match:t},this.matchPos=kc(this.text,i+(n==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=os.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(i_.prototype[Symbol.iterator]=GA.prototype[Symbol.iterator]=function(){return this});function RM(r){try{return new RegExp(r,r_),!0}catch{return!1}}function kc(r,e){if(e>=r.length)return e;let t=r.lineAt(e),n;for(;e=56320&&n<57344;)e++;return e}const NM={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},QA=$e.define({combine(r){return yi(r,NM,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function wM(r){let e=[MM,LM];return r&&e.push(QA.of(r)),e}const DM=Ke.mark({class:"cm-selectionMatch"}),xM=Ke.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function cb(r,e,t,n){return(t==0||r(e.sliceDoc(t-1,t))!=Yt.Word)&&(n==e.doc.length||r(e.sliceDoc(n,n+1))!=Yt.Word)}function kM(r,e,t,n){return r(e.sliceDoc(t,t+1))==Yt.Word&&r(e.sliceDoc(n-1,n))==Yt.Word}const LM=vn.fromClass(class{constructor(r){this.decorations=this.getDeco(r)}update(r){(r.selectionSet||r.docChanged||r.viewportChanged)&&(this.decorations=this.getDeco(r.view))}getDeco(r){let e=r.state.facet(QA),{state:t}=r,n=t.selection;if(n.ranges.length>1)return Ke.none;let i=n.main,a,s=null;if(i.empty){if(!e.highlightWordAroundCursor)return Ke.none;let l=t.wordAt(i.head);if(!l)return Ke.none;s=t.charCategorizer(i.head),a=t.sliceDoc(l.from,l.to)}else{let l=i.to-i.from;if(l200)return Ke.none;if(e.wholeWords){if(a=t.sliceDoc(i.from,i.to),s=t.charCategorizer(i.head),!(cb(s,t,i.from,i.to)&&kM(s,t,i.from,i.to)))return Ke.none}else if(a=t.sliceDoc(i.from,i.to).trim(),!a)return Ke.none}let o=[];for(let l of r.visibleRanges){let c=new n_(t.doc,a,l.from,l.to);for(;!c.next().done;){let{from:u,to:p}=c.value;if((!s||cb(s,t,u,p))&&(i.empty&&u<=i.from&&p>=i.to?o.push(xM.range(u,p)):(u>=i.to||p<=i.from)&&o.push(DM.range(u,p)),o.length>e.maxMatches))return Ke.none}}return Ke.set(o)}},{decorations:r=>r.decorations}),MM=Me.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});class PM{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||RM(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,n)=>n=="n"?` `:n=="r"?"\r":n=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new YM(this):new UM(this)}getCursor(e,t=0,n){let i=e.doc?e:_t.create({doc:e});return n==null&&(n=i.doc.length),this.regexp?Za(this,i,t,n):Xa(this,i,t,n)}}class qA{constructor(e){this.spec=e}}function Xa(r,e,t,n){return new n_(e.doc,r.unquoted,t,n,r.caseSensitive?void 0:i=>i.toLowerCase(),r.wholeWord?BM(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function BM(r,e){return(t,n,i,a)=>((a>t||a+i.length=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let a=Xa(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!a.next().done;)i(a.value.from,a.value.to)}}function Za(r,e,t,n){return new i_(e.doc,r.search,{ignoreCase:!r.caseSensitive,test:r.wholeWord?FM(e.charCategorizer(e.selection.main.head)):void 0},t,n)}function Lc(r,e){return r.slice(An(r,e,!1),e)}function Mc(r,e){return r.slice(e,An(r,e))}function FM(r){return(e,t,n)=>!n[0].length||(r(Lc(n.input,n.index))!=Yt.Word||r(Mc(n.input,n.index))!=Yt.Word)&&(r(Mc(n.input,n.index+n[0].length))!=Yt.Word||r(Lc(n.input,n.index+n[0].length))!=Yt.Word)}class YM extends qA{nextMatch(e,t,n){let i=Za(this.spec,e,n,e.doc.length).next();return i.done&&(i=Za(this.spec,e,0,t).next()),i.done?null:i.value}prevMatchInRange(e,t,n){for(let i=1;;i++){let a=Math.max(t,n-i*1e4),s=Za(this.spec,e,a,n),o=null;for(;!s.next().done;)o=s.value;if(o&&(a==t||o.from>a+10))return o;if(a==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g,(t,n)=>n=="$"?"$":n=="&"?e.match[0]:n!="0"&&+n=t)return null;i.push(n.value)}return i}highlight(e,t,n,i){let a=Za(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!a.next().done;)i(a.value.from,a.value.to)}}const zm=ot.define(),$M=r=>{let{state:e}=r,t=e.doc.lineAt(e.selection.main.from),n=s_(r.state,t.from);return n.line?GM(r):n.block?qM(r):!1};function a_(r,e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let i=r(e,t);return i?(n(t.update(i)),!0):!1}}const GM=a_(HM,0),QM=a_(VA,0),qM=a_((r,e)=>VA(r,e,zM(e)),0);function s_(r,e){let t=r.languageDataAt("commentTokens",e);return t.length?t[0]:{}}const lo=50;function VM(r,{open:e,close:t},n,i){let a=r.sliceDoc(n-lo,n),s=r.sliceDoc(i,i+lo),o=/\s*$/.exec(a)[0].length,l=/^\s*/.exec(s)[0].length,c=a.length-o;if(a.slice(c-e.length,c)==e&&s.slice(l,l+t.length)==t)return{open:{pos:n-o,margin:o&&1},close:{pos:i+l,margin:l&&1}};let u,p;i-n<=2*lo?u=p=r.sliceDoc(n,i):(u=r.sliceDoc(n,n+lo),p=r.sliceDoc(i-lo,i));let m=/^\s*/.exec(u)[0].length,_=/\s*$/.exec(p)[0].length,v=p.length-_-t.length;return u.slice(m,m+e.length)==e&&p.slice(v,v+t.length)==t?{open:{pos:n+m+e.length,margin:/\s/.test(u.charAt(m+e.length))?1:0},close:{pos:i-_-t.length,margin:/\s/.test(p.charAt(v-1))?1:0}}:null}function zM(r){let e=[];for(let t of r.selection.ranges){let n=r.doc.lineAt(t.from),i=t.to<=n.to?n:r.doc.lineAt(t.to),a=e.length-1;a>=0&&e[a].to>n.from?e[a].to=i.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:i.to})}return e}function VA(r,e,t=e.selection.ranges){let n=t.map(a=>s_(e,a.from).block);if(!n.every(a=>a))return null;let i=t.map((a,s)=>VM(e,n[s],a.from,a.to));if(r!=2&&!i.every(a=>a))return{changes:e.changes(t.map((a,s)=>i[s]?[]:[{from:a.from,insert:n[s].open+" "},{from:a.to,insert:" "+n[s].close}]))};if(r!=1&&i.some(a=>a)){let a=[];for(let s=0,o;si&&(a==s||s>p.from)){i=p.from;let m=/^\s*/.exec(p.text)[0].length,_=m==p.length,v=p.text.slice(m,m+c.length)==c?m:-1;ma.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:o,token:l,indent:c,empty:u,single:p}of n)(p||!u)&&a.push({from:o.from+c,insert:l+" "});let s=e.changes(a);return{changes:s,selection:e.selection.map(s,1)}}else if(r!=1&&n.some(a=>a.comment>=0)){let a=[];for(let{line:s,comment:o,token:l}of n)if(o>=0){let c=s.from+o,u=c+l.length;s.text[u-s.from]==" "&&u++,a.push({from:c,to:u})}return{changes:a}}return null}const Hm=Ci.define(),WM=Ci.define(),XM=$e.define(),zA=$e.define({combine(r){return yi(r,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,i)=>e(n,i)||t(n,i)})}});function ZM(r){let e=0;return r.iterChangedRanges((t,n)=>e=n),e}const HA=Tn.define({create(){return jr.empty},update(r,e){let t=e.state.facet(zA),n=e.annotation(Hm);if(n){let l=e.docChanged?me.single(ZM(e.changes)):void 0,c=Vn.fromTransaction(e,l),u=n.side,p=u==0?r.undone:r.done;return c?p=Bc(p,p.length,t.minDepth,c):p=XA(p,e.startState.selection),new jr(u==0?n.rest:p,u==0?p:n.rest)}let i=e.annotation(WM);if((i=="full"||i=="before")&&(r=r.isolate()),e.annotation(dn.addToHistory)===!1)return e.changes.empty?r:r.addMapping(e.changes.desc);let a=Vn.fromTransaction(e),s=e.annotation(dn.time),o=e.annotation(dn.userEvent);return a?r=r.addChanges(a,s,o,t,e):e.selection&&(r=r.addSelection(e.startState.selection,s,o,t.newGroupDelay)),(i=="full"||i=="after")&&(r=r.isolate()),r},toJSON(r){return{done:r.done.map(e=>e.toJSON()),undone:r.undone.map(e=>e.toJSON())}},fromJSON(r){return new jr(r.done.map(Vn.fromJSON),r.undone.map(Vn.fromJSON))}});function KM(r={}){return[HA,zA.of(r),Me.domEventHandlers({beforeinput(e,t){let n=e.inputType=="historyUndo"?o_:e.inputType=="historyRedo"?Pc:null;return n?(e.preventDefault(),n(t)):!1}})]}function nu(r,e){return function({state:t,dispatch:n}){if(!e&&t.readOnly)return!1;let i=t.field(HA,!1);if(!i)return!1;let a=i.pop(r,t,e);return a?(n(a),!0):!1}}const o_=nu(0,!1),Pc=nu(1,!1),jM=nu(0,!0),JM=nu(1,!0);class Vn{constructor(e,t,n,i,a){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=i,this.selectionsAfter=a}setSelAfter(e){return new Vn(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,n;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(e){return new Vn(e.changes&&cn.fromJSON(e.changes),[],e.mapped&&Jr.fromJSON(e.mapped),e.startSelection&&me.fromJSON(e.startSelection),e.selectionsAfter.map(me.fromJSON))}static fromTransaction(e,t){let n=Sr;for(let i of e.startState.facet(XM)){let a=i(e);a.length&&(n=n.concat(a))}return!n.length&&e.changes.empty?null:new Vn(e.changes.invert(e.startState.doc),n,void 0,t||e.startState.selection,Sr)}static selection(e){return new Vn(void 0,Sr,void 0,void 0,e)}}function Bc(r,e,t,n){let i=e+1>t+20?e-t-1:0,a=r.slice(i,e);return a.push(n),a}function eP(r,e){let t=[],n=!1;return r.iterChangedRanges((i,a)=>t.push(i,a)),e.iterChangedRanges((i,a,s,o)=>{for(let l=0;l=c&&s<=u&&(n=!0)}}),n}function tP(r,e){return r.ranges.length==e.ranges.length&&r.ranges.filter((t,n)=>t.empty!=e.ranges[n].empty).length===0}function WA(r,e){return r.length?e.length?r.concat(e):r:e}const Sr=[],nP=200;function XA(r,e){if(r.length){let t=r[r.length-1],n=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-nP));return n.length&&n[n.length-1].eq(e)?r:(n.push(e),Bc(r,r.length-1,1e9,t.setSelAfter(n)))}else return[Vn.selection([e])]}function rP(r){let e=r[r.length-1],t=r.slice();return t[r.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function ad(r,e){if(!r.length)return r;let t=r.length,n=Sr;for(;t;){let i=iP(r[t-1],e,n);if(i.changes&&!i.changes.empty||i.effects.length){let a=r.slice(0,t);return a[t-1]=i,a}else e=i.mapped,t--,n=i.selectionsAfter}return n.length?[Vn.selection(n)]:Sr}function iP(r,e,t){let n=WA(r.selectionsAfter.length?r.selectionsAfter.map(o=>o.map(e)):Sr,t);if(!r.changes)return Vn.selection(n);let i=r.changes.map(e),a=e.mapDesc(r.changes,!0),s=r.mapped?r.mapped.composeDesc(a):a;return new Vn(i,ot.mapEffects(r.effects,e),s,r.startSelection.map(a),n)}const aP=/^(input\.type|delete)($|\.)/;class jr{constructor(e,t,n=0,i=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=i}isolate(){return this.prevTime?new jr(this.done,this.undone):this}addChanges(e,t,n,i,a){let s=this.done,o=s[s.length-1];return o&&o.changes&&!o.changes.empty&&e.changes&&(!n||aP.test(n))&&(!o.selectionsAfter.length&&t-this.prevTime0&&t-this.prevTimet.empty?r.moveByChar(t,e):ru(t,e))}function In(r){return r.textDirectionAt(r.state.selection.main.head)==$t.LTR}const c_=r=>l_(r,!In(r)),ZA=r=>l_(r,In(r)),oP=r=>l_(r,!1);function KA(r,e){return Br(r,t=>t.empty?r.moveByGroup(t,e):ru(t,e))}const lP=r=>KA(r,!In(r)),cP=r=>KA(r,In(r));function uP(r,e,t){if(e.type.prop(t))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(r.sliceDoc(e.from,e.to)))||e.firstChild}function iu(r,e,t){let n=Gt(r).resolveInner(e.head),i=t?et.closedBy:et.openedBy;for(let l=e.head;;){let c=t?n.childAfter(l):n.childBefore(l);if(!c)break;uP(r,c,i)?n=c:l=t?c.to:c.from}let a=n.type.prop(i),s,o;return a&&(s=t?_r(r,n.from,1):_r(r,n.to,-1))&&s.matched?o=t?s.end.to:s.end.from:o=t?n.to:n.from,me.cursor(o,t?-1:1)}const dP=r=>Br(r,e=>iu(r.state,e,!In(r))),pP=r=>Br(r,e=>iu(r.state,e,In(r)));function jA(r,e){return Br(r,t=>{if(!t.empty)return ru(t,e);let n=r.moveVertically(t,e);return n.head!=t.head?n:r.moveToLineBoundary(t,e)})}const JA=r=>jA(r,!1),eI=r=>jA(r,!0);function tI(r){let e=r.scrollDOM.clientHeights.empty?r.moveVertically(s,e,t.height):ru(s,e));if(i.eq(n.selection))return!1;let a;if(t.selfScroll){let s=r.coordsAtPos(n.selection.main.head),o=r.scrollDOM.getBoundingClientRect(),l=o.top+t.marginTop,c=o.bottom-t.marginBottom;s&&s.top>l&&s.bottomnI(r,!1),Wm=r=>nI(r,!0);function ea(r,e,t){let n=r.lineBlockAt(e.head),i=r.moveToLineBoundary(e,t);if(i.head==e.head&&i.head!=(t?n.to:n.from)&&(i=r.moveToLineBoundary(e,t,!1)),!t&&i.head==n.from&&n.length){let a=/^\s*/.exec(r.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;a&&e.head!=n.from+a&&(i=me.cursor(n.from+a))}return i}const rI=r=>Br(r,e=>ea(r,e,!0)),iI=r=>Br(r,e=>ea(r,e,!1)),fP=r=>Br(r,e=>ea(r,e,!In(r))),hP=r=>Br(r,e=>ea(r,e,In(r))),mP=r=>Br(r,e=>me.cursor(r.lineBlockAt(e.head).from,1)),gP=r=>Br(r,e=>me.cursor(r.lineBlockAt(e.head).to,-1));function _P(r,e,t){let n=!1,i=Ns(r.selection,a=>{let s=_r(r,a.head,-1)||_r(r,a.head,1)||a.head>0&&_r(r,a.head-1,1)||a.head_P(r,e,!1);function Tr(r,e){let t=Ns(r.state.selection,n=>{let i=e(n);return me.range(n.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)});return t.eq(r.state.selection)?!1:(r.dispatch(si(r.state,t)),!0)}function aI(r,e){return Tr(r,t=>r.moveByChar(t,e))}const sI=r=>aI(r,!In(r)),oI=r=>aI(r,In(r));function lI(r,e){return Tr(r,t=>r.moveByGroup(t,e))}const OP=r=>lI(r,!In(r)),bP=r=>lI(r,In(r)),EP=r=>Tr(r,e=>iu(r.state,e,!In(r))),vP=r=>Tr(r,e=>iu(r.state,e,In(r)));function cI(r,e){return Tr(r,t=>r.moveVertically(t,e))}const uI=r=>cI(r,!1),dI=r=>cI(r,!0);function pI(r,e){return Tr(r,t=>r.moveVertically(t,e,tI(r).height))}const db=r=>pI(r,!1),pb=r=>pI(r,!0),TP=r=>Tr(r,e=>ea(r,e,!0)),CP=r=>Tr(r,e=>ea(r,e,!1)),yP=r=>Tr(r,e=>ea(r,e,!In(r))),AP=r=>Tr(r,e=>ea(r,e,In(r))),IP=r=>Tr(r,e=>me.cursor(r.lineBlockAt(e.head).from)),RP=r=>Tr(r,e=>me.cursor(r.lineBlockAt(e.head).to)),fb=({state:r,dispatch:e})=>(e(si(r,{anchor:0})),!0),hb=({state:r,dispatch:e})=>(e(si(r,{anchor:r.doc.length})),!0),mb=({state:r,dispatch:e})=>(e(si(r,{anchor:r.selection.main.anchor,head:0})),!0),gb=({state:r,dispatch:e})=>(e(si(r,{anchor:r.selection.main.anchor,head:r.doc.length})),!0),NP=({state:r,dispatch:e})=>(e(r.update({selection:{anchor:0,head:r.doc.length},userEvent:"select"})),!0),wP=({state:r,dispatch:e})=>{let t=su(r).map(({from:n,to:i})=>me.range(n,Math.min(i+1,r.doc.length)));return e(r.update({selection:me.create(t),userEvent:"select"})),!0},DP=({state:r,dispatch:e})=>{let t=Ns(r.selection,n=>{var i;let a=Gt(r).resolveInner(n.head,1);for(;!(a.from=n.to||a.to>n.to&&a.from<=n.from||!(!((i=a.parent)===null||i===void 0)&&i.parent));)a=a.parent;return me.range(a.to,a.from)});return e(si(r,t)),!0},xP=({state:r,dispatch:e})=>{let t=r.selection,n=null;return t.ranges.length>1?n=me.create([t.main]):t.main.empty||(n=me.create([me.cursor(t.main.head)])),n?(e(si(r,n)),!0):!1};function au(r,e){if(r.state.readOnly)return!1;let t="delete.selection",{state:n}=r,i=n.changeByRange(a=>{let{from:s,to:o}=a;if(s==o){let l=e(s);ls&&(t="delete.forward",l=Fl(r,l,!0)),s=Math.min(s,l),o=Math.max(o,l)}else s=Fl(r,s,!1),o=Fl(r,o,!0);return s==o?{range:a}:{changes:{from:s,to:o},range:me.cursor(s)}});return i.changes.empty?!1:(r.dispatch(n.update(i,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?Me.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function Fl(r,e,t){if(r instanceof Me)for(let n of r.state.facet(Me.atomicRanges).map(i=>i(r)))n.between(e,e,(i,a)=>{ie&&(e=t?a:i)});return e}const fI=(r,e)=>au(r,t=>{let{state:n}=r,i=n.doc.lineAt(t),a,s;if(!e&&t>i.from&&tfI(r,!1),hI=r=>fI(r,!0),mI=(r,e)=>au(r,t=>{let n=t,{state:i}=r,a=i.doc.lineAt(n),s=i.charCategorizer(n);for(let o=null;;){if(n==(e?a.to:a.from)){n==t&&a.number!=(e?i.doc.lines:1)&&(n+=e?1:-1);break}let l=An(a.text,n-a.from,e)+a.from,c=a.text.slice(Math.min(n,l)-a.from,Math.max(n,l)-a.from),u=s(c);if(o!=null&&u!=o)break;(c!=" "||n!=t)&&(o=u),n=l}return n}),gI=r=>mI(r,!1),kP=r=>mI(r,!0),_I=r=>au(r,e=>{let t=r.lineBlockAt(e).to;return eau(r,e=>{let t=r.lineBlockAt(e).from;return e>t?t:Math.max(0,e-1)}),MP=({state:r,dispatch:e})=>{if(r.readOnly)return!1;let t=r.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:St.of(["",""])},range:me.cursor(n.from)}));return e(r.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},PP=({state:r,dispatch:e})=>{if(r.readOnly)return!1;let t=r.changeByRange(n=>{if(!n.empty||n.from==0||n.from==r.doc.length)return{range:n};let i=n.from,a=r.doc.lineAt(i),s=i==a.from?i-1:An(a.text,i-a.from,!1)+a.from,o=i==a.to?i+1:An(a.text,i-a.from,!0)+a.from;return{changes:{from:s,to:o,insert:r.doc.slice(i,o).append(r.doc.slice(s,i))},range:me.cursor(o)}});return t.changes.empty?!1:(e(r.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function su(r){let e=[],t=-1;for(let n of r.selection.ranges){let i=r.doc.lineAt(n.from),a=r.doc.lineAt(n.to);if(!n.empty&&n.to==a.from&&(a=r.doc.lineAt(n.to-1)),t>=i.number){let s=e[e.length-1];s.to=a.to,s.ranges.push(n)}else e.push({from:i.from,to:a.to,ranges:[n]});t=a.number+1}return e}function SI(r,e,t){if(r.readOnly)return!1;let n=[],i=[];for(let a of su(r)){if(t?a.to==r.doc.length:a.from==0)continue;let s=r.doc.lineAt(t?a.to+1:a.from-1),o=s.length+1;if(t){n.push({from:a.to,to:s.to},{from:a.from,insert:s.text+r.lineBreak});for(let l of a.ranges)i.push(me.range(Math.min(r.doc.length,l.anchor+o),Math.min(r.doc.length,l.head+o)))}else{n.push({from:s.from,to:a.from},{from:a.to,insert:r.lineBreak+s.text});for(let l of a.ranges)i.push(me.range(l.anchor-o,l.head-o))}}return n.length?(e(r.update({changes:n,scrollIntoView:!0,selection:me.create(i,r.selection.mainIndex),userEvent:"move.line"})),!0):!1}const BP=({state:r,dispatch:e})=>SI(r,e,!1),UP=({state:r,dispatch:e})=>SI(r,e,!0);function OI(r,e,t){if(r.readOnly)return!1;let n=[];for(let i of su(r))t?n.push({from:i.from,insert:r.doc.slice(i.from,i.to)+r.lineBreak}):n.push({from:i.to,insert:r.lineBreak+r.doc.slice(i.from,i.to)});return e(r.update({changes:n,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const FP=({state:r,dispatch:e})=>OI(r,e,!1),YP=({state:r,dispatch:e})=>OI(r,e,!0),$P=r=>{if(r.state.readOnly)return!1;let{state:e}=r,t=e.changes(su(e).map(({from:i,to:a})=>(i>0?i--:ar.moveVertically(i,!0)).map(t);return r.dispatch({changes:t,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function GP(r,e){if(/\(\)|\[\]|\{\}/.test(r.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Gt(r).resolveInner(e),n=t.childBefore(e),i=t.childAfter(e),a;return n&&i&&n.to<=e&&i.from>=e&&(a=n.type.prop(et.closedBy))&&a.indexOf(i.name)>-1&&r.doc.lineAt(n.to).from==r.doc.lineAt(i.from).from?{from:n.to,to:i.from}:null}const bI=EI(!1),QP=EI(!0);function EI(r){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:a,to:s}=i,o=e.doc.lineAt(a),l=!r&&a==s&&GP(e,a);r&&(a=s=(s<=o.to?o:e.doc.lineAt(s)).to);let c=new Kc(e,{simulateBreak:a,simulateDoubleBreak:!!l}),u=xg(c,a);for(u==null&&(u=/^\s*/.exec(e.doc.lineAt(a).text)[0].length);so.from&&a{let i=[];for(let s=n.from;s<=n.to;){let o=r.doc.lineAt(s);o.number>t&&(n.empty||n.to>o.from)&&(e(o,i,n),t=o.number),s=o.to+1}let a=r.changes(i);return{changes:i,range:me.range(a.mapPos(n.anchor,1),a.mapPos(n.head,1))}})}const vI=({state:r,dispatch:e})=>{if(r.readOnly)return!1;let t=Object.create(null),n=new Kc(r,{overrideIndentation:a=>{let s=t[a];return s??-1}}),i=u_(r,(a,s,o)=>{let l=xg(n,a.from);if(l==null)return;/\S/.test(a.text)||(l=0);let c=/^\s*/.exec(a.text)[0],u=$o(r,l);(c!=u||o.fromr.readOnly?!1:(e(r.update(u_(r,(t,n)=>{n.push({from:t.from,insert:r.facet(Es)})}),{userEvent:"input.indent"})),!0),p_=({state:r,dispatch:e})=>r.readOnly?!1:(e(r.update(u_(r,(t,n)=>{let i=/^\s*/.exec(t.text)[0];if(!i)return;let a=Wc(i,r.tabSize),s=0,o=$o(r,Math.max(0,a-Tc(r)));for(;s({mac:r.key,run:r.run,shift:r.shift}))),zP=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:dP,shift:EP},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:pP,shift:vP},{key:"Alt-ArrowUp",run:BP},{key:"Shift-Alt-ArrowUp",run:FP},{key:"Alt-ArrowDown",run:UP},{key:"Shift-Alt-ArrowDown",run:YP},{key:"Escape",run:xP},{key:"Mod-Enter",run:QP},{key:"Alt-l",mac:"Ctrl-l",run:wP},{key:"Mod-i",run:DP,preventDefault:!0},{key:"Mod-[",run:p_},{key:"Mod-]",run:d_},{key:"Mod-Alt-\\",run:vI},{key:"Shift-Mod-k",run:$P},{key:"Shift-Mod-\\",run:SP},{key:"Mod-/",run:$M},{key:"Alt-A",run:QM}].concat(VP),HP={key:"Tab",run:d_,shift:p_};function WP(r){var e=r.Pos;function t(d,f){var g=d.state.vim;if(!g||g.insertMode)return f.head;var O=g.sel.head;if(!O)return f.head;if(!(g.visualBlock&&f.head.line!=O.line))return f.from()==f.anchor&&!f.empty()&&f.head.line==O.line&&f.head.ch!=O.ch?new e(f.head.line,f.head.ch-1):f.head}function n(d,f,g){if(f.line===g.line&&f.ch>=g.ch-1){var O=d.getLine(f.line),C=O.charCodeAt(f.ch);55296<=C&&C<=55551&&(g.ch+=1)}return{start:f,end:g}}var i=[{keys:"",type:"keyToKey",toKeys:"h"},{keys:"",type:"keyToKey",toKeys:"l"},{keys:"",type:"keyToKey",toKeys:"k"},{keys:"",type:"keyToKey",toKeys:"j"},{keys:"g",type:"keyToKey",toKeys:"gk"},{keys:"g",type:"keyToKey",toKeys:"gj"},{keys:"",type:"keyToKey",toKeys:"l"},{keys:"",type:"keyToKey",toKeys:"h",context:"normal"},{keys:"",type:"keyToKey",toKeys:"x",context:"normal"},{keys:"",type:"keyToKey",toKeys:"W"},{keys:"",type:"keyToKey",toKeys:"B",context:"normal"},{keys:"",type:"keyToKey",toKeys:"w"},{keys:"",type:"keyToKey",toKeys:"b",context:"normal"},{keys:"",type:"keyToKey",toKeys:"j"},{keys:"",type:"keyToKey",toKeys:"k"},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:"",context:"insert"},{keys:"",type:"keyToKey",toKeys:"",context:"insert"},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:"",context:"insert"},{keys:"s",type:"keyToKey",toKeys:"cl",context:"normal"},{keys:"s",type:"keyToKey",toKeys:"c",context:"visual"},{keys:"S",type:"keyToKey",toKeys:"cc",context:"normal"},{keys:"S",type:"keyToKey",toKeys:"VdO",context:"visual"},{keys:"",type:"keyToKey",toKeys:"0"},{keys:"",type:"keyToKey",toKeys:"$"},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:"j^",context:"normal"},{keys:"",type:"keyToKey",toKeys:"i",context:"normal"},{keys:"",type:"action",action:"toggleOverwrite",context:"insert"},{keys:"H",type:"motion",motion:"moveToTopLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"M",type:"motion",motion:"moveToMiddleLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"L",type:"motion",motion:"moveToBottomLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:"h",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!1}},{keys:"l",type:"motion",motion:"moveByCharacters",motionArgs:{forward:!0}},{keys:"j",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,linewise:!0}},{keys:"k",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,linewise:!0}},{keys:"gj",type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!0}},{keys:"gk",type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!1}},{keys:"w",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1}},{keys:"W",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1,bigWord:!0}},{keys:"e",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,inclusive:!0}},{keys:"E",type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:"b",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1}},{keys:"B",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1,bigWord:!0}},{keys:"ge",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,inclusive:!0}},{keys:"gE",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:"{",type:"motion",motion:"moveByParagraph",motionArgs:{forward:!1,toJumplist:!0}},{keys:"}",type:"motion",motion:"moveByParagraph",motionArgs:{forward:!0,toJumplist:!0}},{keys:"(",type:"motion",motion:"moveBySentence",motionArgs:{forward:!1}},{keys:")",type:"motion",motion:"moveBySentence",motionArgs:{forward:!0}},{keys:"",type:"motion",motion:"moveByPage",motionArgs:{forward:!0}},{keys:"",type:"motion",motion:"moveByPage",motionArgs:{forward:!1}},{keys:"",type:"motion",motion:"moveByScroll",motionArgs:{forward:!0,explicitRepeat:!0}},{keys:"",type:"motion",motion:"moveByScroll",motionArgs:{forward:!1,explicitRepeat:!0}},{keys:"gg",type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0,toJumplist:!0}},{keys:"G",type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!0,explicitRepeat:!0,linewise:!0,toJumplist:!0}},{keys:"g$",type:"motion",motion:"moveToEndOfDisplayLine"},{keys:"g^",type:"motion",motion:"moveToStartOfDisplayLine"},{keys:"g0",type:"motion",motion:"moveToStartOfDisplayLine"},{keys:"0",type:"motion",motion:"moveToStartOfLine"},{keys:"^",type:"motion",motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"+",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,toFirstChar:!0}},{keys:"-",type:"motion",motion:"moveByLines",motionArgs:{forward:!1,toFirstChar:!0}},{keys:"_",type:"motion",motion:"moveByLines",motionArgs:{forward:!0,toFirstChar:!0,repeatOffset:-1}},{keys:"$",type:"motion",motion:"moveToEol",motionArgs:{inclusive:!0}},{keys:"%",type:"motion",motion:"moveToMatchedSymbol",motionArgs:{inclusive:!0,toJumplist:!0}},{keys:"f",type:"motion",motion:"moveToCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"F",type:"motion",motion:"moveToCharacter",motionArgs:{forward:!1}},{keys:"t",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"T",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!1}},{keys:";",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!0}},{keys:",",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!1}},{keys:"'",type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0,linewise:!0}},{keys:"`",type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0}},{keys:"]`",type:"motion",motion:"jumpToMark",motionArgs:{forward:!0}},{keys:"[`",type:"motion",motion:"jumpToMark",motionArgs:{forward:!1}},{keys:"]'",type:"motion",motion:"jumpToMark",motionArgs:{forward:!0,linewise:!0}},{keys:"['",type:"motion",motion:"jumpToMark",motionArgs:{forward:!1,linewise:!0}},{keys:"]p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0,matchIndent:!0}},{keys:"[p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!1,isEdit:!0,matchIndent:!0}},{keys:"]",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!0,toJumplist:!0}},{keys:"[",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!1,toJumplist:!0}},{keys:"|",type:"motion",motion:"moveToColumn"},{keys:"o",type:"motion",motion:"moveToOtherHighlightedEnd",context:"visual"},{keys:"O",type:"motion",motion:"moveToOtherHighlightedEnd",motionArgs:{sameLine:!0},context:"visual"},{keys:"d",type:"operator",operator:"delete"},{keys:"y",type:"operator",operator:"yank"},{keys:"c",type:"operator",operator:"change"},{keys:"=",type:"operator",operator:"indentAuto"},{keys:">",type:"operator",operator:"indent",operatorArgs:{indentRight:!0}},{keys:"<",type:"operator",operator:"indent",operatorArgs:{indentRight:!1}},{keys:"g~",type:"operator",operator:"changeCase"},{keys:"gu",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},isEdit:!0},{keys:"gU",type:"operator",operator:"changeCase",operatorArgs:{toLower:!1},isEdit:!0},{keys:"n",type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:!0}},{keys:"N",type:"motion",motion:"findNext",motionArgs:{forward:!1,toJumplist:!0}},{keys:"gn",type:"motion",motion:"findAndSelectNextInclusive",motionArgs:{forward:!0}},{keys:"gN",type:"motion",motion:"findAndSelectNextInclusive",motionArgs:{forward:!1}},{keys:"x",type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!0},operatorMotionArgs:{visualLine:!1}},{keys:"X",type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!1},operatorMotionArgs:{visualLine:!0}},{keys:"D",type:"operatorMotion",operator:"delete",motion:"moveToEol",motionArgs:{inclusive:!0},context:"normal"},{keys:"D",type:"operator",operator:"delete",operatorArgs:{linewise:!0},context:"visual"},{keys:"Y",type:"operatorMotion",operator:"yank",motion:"expandToLine",motionArgs:{linewise:!0},context:"normal"},{keys:"Y",type:"operator",operator:"yank",operatorArgs:{linewise:!0},context:"visual"},{keys:"C",type:"operatorMotion",operator:"change",motion:"moveToEol",motionArgs:{inclusive:!0},context:"normal"},{keys:"C",type:"operator",operator:"change",operatorArgs:{linewise:!0},context:"visual"},{keys:"~",type:"operatorMotion",operator:"changeCase",motion:"moveByCharacters",motionArgs:{forward:!0},operatorArgs:{shouldMoveCursor:!0},context:"normal"},{keys:"~",type:"operator",operator:"changeCase",context:"visual"},{keys:"",type:"operatorMotion",operator:"delete",motion:"moveToStartOfLine",context:"insert"},{keys:"",type:"operatorMotion",operator:"delete",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1},context:"insert"},{keys:"",type:"idle",context:"normal"},{keys:"",type:"action",action:"jumpListWalk",actionArgs:{forward:!0}},{keys:"",type:"action",action:"jumpListWalk",actionArgs:{forward:!1}},{keys:"",type:"action",action:"scroll",actionArgs:{forward:!0,linewise:!0}},{keys:"",type:"action",action:"scroll",actionArgs:{forward:!1,linewise:!0}},{keys:"a",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"charAfter"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"eol"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"endOfSelectedArea"},context:"visual"},{keys:"i",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"inplace"},context:"normal"},{keys:"gi",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"lastEdit"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"firstNonBlank"},context:"normal"},{keys:"gI",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"bol"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"startOfSelectedArea"},context:"visual"},{keys:"o",type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!0},context:"normal"},{keys:"O",type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!1},context:"normal"},{keys:"v",type:"action",action:"toggleVisualMode"},{keys:"V",type:"action",action:"toggleVisualMode",actionArgs:{linewise:!0}},{keys:"",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"gv",type:"action",action:"reselectLastSelection"},{keys:"J",type:"action",action:"joinLines",isEdit:!0},{keys:"gJ",type:"action",action:"joinLines",actionArgs:{keepSpaces:!0},isEdit:!0},{keys:"p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0}},{keys:"P",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!1,isEdit:!0}},{keys:"r",type:"action",action:"replace",isEdit:!0},{keys:"@",type:"action",action:"replayMacro"},{keys:"q",type:"action",action:"enterMacroRecordMode"},{keys:"R",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{replace:!0},context:"normal"},{keys:"R",type:"operator",operator:"change",operatorArgs:{linewise:!0,fullLine:!0},context:"visual",exitVisualBlock:!0},{keys:"u",type:"action",action:"undo",context:"normal"},{keys:"u",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},context:"visual",isEdit:!0},{keys:"U",type:"operator",operator:"changeCase",operatorArgs:{toLower:!1},context:"visual",isEdit:!0},{keys:"",type:"action",action:"redo"},{keys:"m",type:"action",action:"setMark"},{keys:'"',type:"action",action:"setRegister"},{keys:"",type:"action",action:"insertRegister",context:"insert",isEdit:!0},{keys:"",type:"action",action:"oneNormalCommand",context:"insert"},{keys:"zz",type:"action",action:"scrollToCursor",actionArgs:{position:"center"}},{keys:"z.",type:"action",action:"scrollToCursor",actionArgs:{position:"center"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"zt",type:"action",action:"scrollToCursor",actionArgs:{position:"top"}},{keys:"z",type:"action",action:"scrollToCursor",actionArgs:{position:"top"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"zb",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"}},{keys:"z-",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:".",type:"action",action:"repeatLastEdit"},{keys:"",type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!0,backtrack:!1}},{keys:"",type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!1,backtrack:!1}},{keys:"",type:"action",action:"indent",actionArgs:{indentRight:!0},context:"insert"},{keys:"",type:"action",action:"indent",actionArgs:{indentRight:!1},context:"insert"},{keys:"a",type:"motion",motion:"textObjectManipulation"},{keys:"i",type:"motion",motion:"textObjectManipulation",motionArgs:{textObjectInner:!0}},{keys:"/",type:"search",searchArgs:{forward:!0,querySrc:"prompt",toJumplist:!0}},{keys:"?",type:"search",searchArgs:{forward:!1,querySrc:"prompt",toJumplist:!0}},{keys:"*",type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",wholeWordOnly:!0,toJumplist:!0}},{keys:"#",type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",wholeWordOnly:!0,toJumplist:!0}},{keys:"g*",type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:"g#",type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:":",type:"ex"}],a=i.length,s=[{name:"colorscheme",shortName:"colo"},{name:"map"},{name:"imap",shortName:"im"},{name:"nmap",shortName:"nm"},{name:"vmap",shortName:"vm"},{name:"omap",shortName:"om"},{name:"noremap",shortName:"no"},{name:"nnoremap",shortName:"nn"},{name:"vnoremap",shortName:"vn"},{name:"inoremap",shortName:"ino"},{name:"onoremap",shortName:"ono"},{name:"unmap"},{name:"mapclear",shortName:"mapc"},{name:"nmapclear",shortName:"nmapc"},{name:"vmapclear",shortName:"vmapc"},{name:"imapclear",shortName:"imapc"},{name:"omapclear",shortName:"omapc"},{name:"write",shortName:"w"},{name:"undo",shortName:"u"},{name:"redo",shortName:"red"},{name:"set",shortName:"se"},{name:"setlocal",shortName:"setl"},{name:"setglobal",shortName:"setg"},{name:"sort",shortName:"sor"},{name:"substitute",shortName:"s",possiblyAsync:!0},{name:"nohlsearch",shortName:"noh"},{name:"yank",shortName:"y"},{name:"delmarks",shortName:"delm"},{name:"registers",shortName:"reg",excludeFromCommandHistory:!0},{name:"vglobal",shortName:"v"},{name:"delete",shortName:"d"},{name:"join",shortName:"j"},{name:"normal",shortName:"norm"},{name:"global",shortName:"g"}];function o(d){d.setOption("disableInput",!0),d.setOption("showCursorWhenSelecting",!1),r.signal(d,"vim-mode-change",{mode:"normal"}),d.on("cursorActivity",ge),Ne(d),r.on(d.getInputField(),"paste",R(d))}function l(d){d.setOption("disableInput",!1),d.off("cursorActivity",ge),r.off(d.getInputField(),"paste",R(d)),d.state.vim=null,Ni&&clearTimeout(Ni)}function c(d,f){this==r.keyMap.vim&&(d.options.$customCursor=null,r.rmClass(d.getWrapperElement(),"cm-fat-cursor")),(!f||f.attach!=u)&&l(d)}function u(d,f){this==r.keyMap.vim&&(d.curOp&&(d.curOp.selectionChanged=!0),d.options.$customCursor=t,r.addClass(d.getWrapperElement(),"cm-fat-cursor")),(!f||f.attach!=u)&&o(d)}r.defineOption("vimMode",!1,function(d,f,g){f&&d.getOption("keyMap")!="vim"?d.setOption("keyMap","vim"):!f&&g!=r.Init&&/^vim/.test(d.getOption("keyMap"))&&d.setOption("keyMap","default")});function p(d,f){if(f){if(this[d])return this[d];var g=I(d);if(!g)return!1;var O=Be.findKey(f,g);return typeof O=="function"&&r.signal(f,"vim-keypress",g),O}}var m={Shift:"S",Ctrl:"C",Alt:"A",Cmd:"D",Mod:"A",CapsLock:""},_={Enter:"CR",Backspace:"BS",Delete:"Del",Insert:"Ins"},v={};"Left|Right|Up|Down|End|Home".split("|").concat(Object.keys(_)).forEach(function(d){v[(_[d]||"").toLowerCase()]=v[d.toLowerCase()]=d});function I(d){if(d.charAt(0)=="'")return d.charAt(1);var f=d.split(/-(?!$)/),g=f[f.length-1];if(f.length==1&&f[0].length==1)return!1;if(f.length==2&&f[0]=="Shift"&&g.length==1)return!1;for(var O=!1,C=0;C"):!1}function R(d){var f=d.state.vim;return f.onPasteFn||(f.onPasteFn=function(){f.insertMode||(d.setCursor(ye(d.getCursor(),0,1)),fe.enterInsertMode(d,{},f))}),f.onPasteFn}var x=/[\d]/,$=[r.isWordChar,function(d){return d&&!r.isWordChar(d)&&!/\s/.test(d)}],Z=[function(d){return/\S/.test(d)}];function h(d,f){for(var g=[],O=d;O"]),L=[].concat(b,S,N,["-",'"',".",":","_","/","+"]),M;try{M=new RegExp("^[\\p{Lu}]$","u")}catch{M=/^[A-Z]$/}function G(d,f){return f>=d.firstLine()&&f<=d.lastLine()}function te(d){return/^[a-z]$/.test(d)}function re(d){return"()[]{}".indexOf(d)!=-1}function ne(d){return x.test(d)}function ee(d){return M.test(d)}function B(d){return/^\s*$/.test(d)}function Q(d){return".?!".indexOf(d)!=-1}function j(d,f){for(var g=0;gg?f=g:f0?1:-1,he,se=U.getCursor();do if(f+=pe,z=C[(d+f)%d],z&&(he=z.find())&&!Kt(se,he))break;while(fO)}return z}function F(U,W){var z=f,pe=D(U,W);return f=z,pe&&pe.find()}return{cachedCursor:void 0,add:y,find:F,move:D}},xe=function(d){return d?{changes:d.changes,expectCursorActivityForChange:d.expectCursorActivityForChange}:{changes:[],expectCursorActivityForChange:!1}};function Ee(){this.latestRegister=void 0,this.isPlaying=!1,this.isRecording=!1,this.replaySearchQueries=[],this.onRecordingDone=void 0,this.lastInsertModeChanges=xe()}Ee.prototype={exitMacroRecordMode:function(){var d=ce.macroModeState;d.onRecordingDone&&d.onRecordingDone(),d.onRecordingDone=void 0,d.isRecording=!1},enterMacroRecordMode:function(d,f){var g=ce.registerController.getRegister(f);if(g){if(g.clear(),this.latestRegister=f,d.openDialog){var O=ur("span",{class:"cm-vim-message"},"recording @"+f);this.onRecordingDone=d.openDialog(O,null,{bottom:!0})}this.isRecording=!0}}};function Ne(d){return d.state.vim||(d.state.vim={inputState:new vt,lastEditInputState:void 0,lastEditActionCommand:void 0,lastHPos:-1,lastHSPos:-1,lastMotion:null,marks:{},insertMode:!1,insertModeReturn:!1,insertModeRepeat:void 0,visualMode:!1,visualLine:!1,visualBlock:!1,lastSelection:null,lastPastedText:null,sel:{},options:{}}),d.state.vim}var ce;function Le(){ce={searchQuery:null,searchIsReversed:!1,lastSubstituteReplacePart:void 0,jumpList:De(),macroModeState:new Ee,lastCharacterSearch:{increment:0,forward:!0,selectedCharacter:""},registerController:new qe({}),searchHistoryController:new rn,exCommandHistoryController:new rn};for(var d in K){var f=K[d];f.value=f.defaultValue}}var Xe,Be={enterVimMode:o,leaveVimMode:l,buildKeyMap:function(){},getRegisterController:function(){return ce.registerController},resetVimGlobalState_:Le,getVimGlobalState_:function(){return ce},maybeInitVimState_:Ne,suppressErrorLogging:!1,InsertModeKey:$n,map:function(d,f,g){_n.map(d,f,g)},unmap:function(d,f){return _n.unmap(d,f)},noremap:function(d,f,g){_n.map(d,f,g,!0)},mapclear:function(d){var f=i.length,g=a,O=i.slice(0,f-g);if(i=i.slice(f-g),d)for(var C=O.length-1;C>=0;C--){var y=O[C];if(d!==y.context)if(y.context)this._mapCommand(y);else{var D=["normal","insert","visual"];for(var F in D)if(D[F]!==d){var U={};for(var W in y)U[W]=y[W];U.context=D[F],this._mapCommand(U)}}}},setOption:le,getOption:be,defineOption:ue,defineEx:function(d,f,g){if(!f)f=d;else if(d.indexOf(f)!==0)throw new Error('(Vim.defineEx) "'+f+'" is not a prefix of "'+d+'", command not registered');pi[d]=g,_n.commandMap_[f]={name:d,shortName:f,type:"api"}},handleKey:function(d,f,g){var O=this.findKey(d,f,g);if(typeof O=="function")return O()},multiSelectHandleKey:fl,findKey:function(d,f,g){var O=Ne(d);function C(){var W=ce.macroModeState;if(W.isRecording){if(f=="q")return W.exitMacroRecordMode(),mt(d),!0;g!="mapping"&&za(W,f)}}function y(){if(f==""){if(O.visualMode)jt(d);else if(O.insertMode)Zn(d);else return;return mt(d),!0}}function D(){if(y())return!0;O.inputState.keyBuffer.push(f);var W=O.inputState.keyBuffer.join(""),z=f.length==1,pe=Ze.matchCommand(W,i,O.inputState,"insert"),he=O.inputState.changeQueue;if(pe.type=="none")return mt(d),!1;if(pe.type=="partial"){if(Xe&&window.clearTimeout(Xe),Xe=z&&window.setTimeout(function(){O.insertMode&&O.inputState.keyBuffer.length&&mt(d)},be("insertModeEscKeysTimeout")),z){var se=d.listSelections();(!he||he.removed.length!=se.length)&&(he=O.inputState.changeQueue=new At),he.inserted+=f;for(var ae=0;ae|./gi,y;y=C.exec(f);){var D=y[0],F=O.insertMode,U=Be.handleKey(d,D,"mapping");if(!U&&F&&O.insertMode){if(D[0]=="<"){var z=D.toLowerCase().slice(1,-1),W=z.split("-"),z=W.pop();if(z=="lt")D="<";else if(z=="space")D=" ";else if(z=="cr")D=` `;else if(v.hasOwnProperty(z)){D=v[z],Kn(d,D);continue}else D=D[0],C.lastIndex=y.index+1}d.replaceSelection(D)}}}finally{rt=!1,tt.length=0}}function vt(){this.prefixRepeat=[],this.motionRepeat=[],this.operator=null,this.operatorArgs=null,this.motion=null,this.motionArgs=null,this.keyBuffer=[],this.registerName=null,this.changeQueue=null}vt.prototype.pushRepeatDigit=function(d){this.operator?this.motionRepeat=this.motionRepeat.concat(d):this.prefixRepeat=this.prefixRepeat.concat(d)},vt.prototype.getRepeat=function(){var d=0;return(this.prefixRepeat.length>0||this.motionRepeat.length>0)&&(d=1,this.prefixRepeat.length>0&&(d*=parseInt(this.prefixRepeat.join(""),10)),this.motionRepeat.length>0&&(d*=parseInt(this.motionRepeat.join(""),10))),d};function mt(d,f){d.state.vim.inputState=new vt,r.signal(d,"vim-command-done",f)}function At(){this.removed=[],this.inserted=""}function Nt(d,f,g){this.clear(),this.keyBuffer=[d||""],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!!f,this.blockwise=!!g}Nt.prototype={setText:function(d,f,g){this.keyBuffer=[d||""],this.linewise=!!f,this.blockwise=!!g},pushText:function(d,f){f&&(this.linewise||this.keyBuffer.push(` `),this.linewise=!0),this.keyBuffer.push(d)},pushInsertModeChanges:function(d){this.insertModeChanges.push(xe(d))},pushSearchQuery:function(d){this.searchQueries.push(d)},clear:function(){this.keyBuffer=[],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!1},toString:function(){return this.keyBuffer.join("")}};function Rn(d,f){var g=ce.registerController.registers;if(!d||d.length!=1)throw Error("Register name must be 1 character");if(g[d])throw Error("Register already defined "+d);g[d]=f,L.push(d)}function qe(d){this.registers=d,this.unnamedRegister=d['"']=new Nt,d["."]=new Nt,d[":"]=new Nt,d["/"]=new Nt,d["+"]=new Nt}qe.prototype={pushText:function(d,f,g,O,C){if(d!=="_"){O&&g.charAt(g.length-1)!==` @@ -2913,4 +2913,7 @@ https://github.com/highlightjs/highlight.js/issues/2277`),le=Q,ue=j),K===void 0& `+c.line+" | "+_+` `+m+" | "+t("",l.column-1," ")+t("",I,"^")}else a+=` at `+u}return a},e.buildMessage=function(i,a){var s={literal:function(_){return'"'+l(_.text)+'"'},class:function(_){var v=_.parts.map(function(I){return Array.isArray(I)?c(I[0])+"-"+c(I[1]):c(I)});return"["+(_.inverted?"^":"")+v.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(v){return"\\x0"+o(v)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(v){return"\\x"+o(v)})}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(v){return"\\x0"+o(v)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(v){return"\\x"+o(v)})}function u(_){return s[_.type](_)}function p(_){var v=_.map(u),I,R;if(v.sort(),v.length>0){for(I=1,R=1;I",R="@",x=":",$="/",Z="(",h=")",b="[:",S="]",N="[",k="{",L="}",M="+",G="*",te="%",re="^",ne="&",ee=">>",B="<<",Q="_",j="?",K="!",ue="r",le="#",be="b",De="iii",xe="ii",Ee="iv",Ne="i",ce="vii",Le="vi",Xe="v",Be=/^[0-9]/,tt=/^[ \n\r\t]/,rt=/^[a-z]/,ht=/^[a-z_]/,vt=/^[a-z_0-9]/,mt=/^[mklpdcwyhnqaefsxtgujzo]/,At=/^[a-zA-Z0-9]/,Nt=/^[a-zA-Z0-9\-*+]/,Rn=/^[A-G]/,qe=/^[bs]/,rn=st("-",!1),Ze=Kn([["0","9"]],!1,!1),ke=st(".",!1),en=Hs("whitespace"),Zt=Kn([" ",` -`,"\r"," "],!1,!1),an=st(",",!1),H=st("|",!1),fe=Kn([["a","z"]],!1,!1),Ie=Kn([["a","z"],"_"],!1,!1),we=Kn([["a","z"],"_",["0","9"]],!1,!1),Je=st("<",!1),ye=st(">",!1),Ht=st("@",!1),lt=st(":",!1),yt=Kn(["m","k","l","p","d","c","w","y","h","n","q","a","e","f","s","x","t","g","u","j","z","o"],!1,!1),zn=st("/",!1),dt=st("(",!1),Kt=st(")",!1),Tt=st("[:",!1),Ue=st("]",!1),Fn=st("[",!1),Fr=st("{",!1),ct=st("}",!1),Hn=st("+",!1),Nn=st("*",!1),Ii=st("%",!1),wn=st("^",!1),Wt=st("&",!1),Cr=st(">>",!1),ta=st("<<",!1),oi=st("_",!1),na=st("?",!1),cr=st("!",!1),li=st("r",!1),yr=Kn([["a","z"],["A","Z"],["0","9"]],!1,!1),jt=st("#",!1),ci=st("b",!1),ui=Kn([["a","z"],["A","Z"],["0","9"],"-","*","+"],!1,!1),q=Kn([["A","G"]],!1,!1),ie=Kn(["b","s"],!1,!1),de=st("iii",!1),_e=st("ii",!1),Ae=st("iv",!1),Qe=st("i",!1),Pe=st("vii",!1),Ct=st("vi",!1),Dn=st("v",!1),Wn=function(T){return T.filter(w=>w)},xa=function(){return parseFloat($n())},ra=function(){return parseInt($n())},xs=function(){return parseInt($n())},Xn=function(){},ks=function(T){return Ut(pG,{sound:T})},ka=function(){return $n()},La=function(T){return Ut(Io,{items:T})},Ls=function(T){return T},Ma=function(T,w){return Ut(fG,{item:T,sound:w})},Ms=function(T,w){return Ut(hG,{item:T,soundIndex:w})},Pa=function(T){return T},Yn=function(){return tG[$n()]},Ps=function(T,w){return T/w},Bs=function(T){return T.filter(w=>w)},Ba=function(T){return Ut(Io,{items:T})},Ua=function(T,w){return w?Ut(mT,{item:T,times:w}):Ut(gT,{items:T})},Us=function(T){return T},Fa=function(T,w,P){return Ut(OG,{left:T,operation:w,right:P})},Fs=function(T,w){return Ut(SG,{items:T,times:w})},Ya=function(T){return Ut(sR,{items:T})},Ys=function(T){return T.map(w=>typeof w=="number"?w:void 0)},$s=function(){return Math.ceil(iR($n()))},ur=function(T){var w=T.filter(P=>P).map(P=>Ut(ni,{pitch:P[0]},P.toString()));return Ut(gT,{items:w})},Ot=function(T){return T},Gs=function(T){return T},Ri=function(){},Qs=function(T){return Ut(Io,{items:T})},di=function(T){return Ut(gG,{octave:T})},qs=function(){return $n().split("").reduce((T,w)=>T+(w==="^"?1:-1),0)},Ni=function(){return Ut(Gc,{seededRandom:a.seededRandom})},$a=function(T,w){return Ut(Gc,{min:T,max:w,seededRandom:a.seededRandom})},Ga=function(T,w){return Ut(mT,{item:T,times:w})},Vs=function(T){return Ut(_G,{duration:T})},wi=function(T){return T},Qa=function(T){return Ut(Jm,{duration:T})},Di=function(T,w,P,X){const oe=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(ni,{duration:w,pitch:X,pitchOctave:oe,add:P})},xi=function(T){return T.reduce((w,P)=>w+(P==="#"?1:-1),0)},qa=function(T,w,P){return Ut(Na,{pitches:[T].concat(w),inversion:P})},ia=function(){return $n()},pi=function(T){return T},_n=function(){return $n()},Va=function(T,w,P,X,oe){const ve=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",ft=a.nodeOptions.key?a.nodeOptions.key:"C",fr=RG(X,P,ve,T,w),Ks=w||a.nodeOptions.duration,DR=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(Na,{duration:Ks,chordOctave:DR,pitches:fr,chordName:X,inversion:oe,scaleName:ve,key:ft})},Zn=function(T,w,P){const X=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",oe=a.nodeOptions.key?a.nodeOptions.key:"C";return Ut(mG,{roman:T,chordName:w,inversion:P,scaleName:X,key:oe})},aa=function(T){const w=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",P=a.nodeOptions.key?a.nodeOptions.key:"C",X=BG(T,P,w);return Ut(ni,{pitch:X.pc,add:X.add,scaleName:w,key:P})},A=0,He=0,za=[{line:1,column:1}],dr=0,zs=[],Oe=0,ge={},sa;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 $n(){return i.substring(He,A)}function dl(){return d(He,A)}function st(T,w){return{type:"literal",text:T,ignoreCase:w}}function Kn(T,w,P){return{type:"class",parts:T,inverted:w,ignoreCase:P}}function pl(){return{type:"end"}}function Hs(T){return{type:"other",description:T}}function fl(T){var w=za[T],P;if(w)return w;for(P=T-1;!za[P];)P--;for(w=za[P],w={line:w.line,column:w.column};Pdr&&(dr=A,zs=[]),zs.push(T))}function g(T,w,P){return new e(e.buildMessage(T,w),T,w,P)}function O(){var T,w,P=A*56+0,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Xt(),w!==s&&(He=T,w=Wn(w)),T=w,ge[P]={nextPos:A,result:T},T)}function C(){var T,w,P,X,oe,ve,ft,fr=A*56+1,Ks=ge[fr];if(Ks)return A=Ks.nextPos,Ks.result;for(T=A,w=A,i.charCodeAt(A)===45?(P=u,A++):(P=s,Oe===0&&f(rn)),P===s&&(P=null),X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));if(i.charCodeAt(A)===46?(oe=p,A++):(oe=s,Oe===0&&f(ke)),oe!==s){if(ve=[],Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze)),ft!==s)for(;ft!==s;)ve.push(ft),Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze));else ve=s;ve!==s?(P=[P,X,oe,ve],w=P):(A=w,w=s)}else A=w,w=s;if(w===s)if(w=A,i.charCodeAt(A)===46?(P=p,A++):(P=s,Oe===0&&f(ke)),P!==s){if(X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze)),oe!==s)for(;oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));else X=s;X!==s?(P=[P,X],w=P):(A=w,w=s)}else A=w,w=s;return w!==s&&(He=T,w=xa()),T=w,ge[fr]={nextPos:A,result:T},T}function y(){var T,w,P=A*56+2,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),Be.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Ze)),w!==s?(He=T,T=ra()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function D(){var T,w,P,X=A*56+3,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),w=[],Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze)),P!==s)for(;P!==s;)w.push(P),Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze));else w=s;return w!==s?(He=T,T=xs()):(A=T,T=s),ge[X]={nextPos:A,result:T},T}function F(){var T,w,P=A*56+4,X=ge[P];return X?(A=X.nextPos,X.result):(Oe++,T=A,tt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Zt)),w!==s&&(He=T,w=Xn()),T=w,Oe--,T===s&&(w=s,Oe===0&&f(en)),ge[P]={nextPos:A,result:T},T)}function U(){var T,w,P=A*56+8,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=W(),w!==s&&(He=T,w=ks(w)),T=w,ge[P]={nextPos:A,result:T},T)}function W(){var T,w,P,X,oe,ve=A*56+10,ft=ge[ve];if(ft)return A=ft.nextPos,ft.result;if(T=A,rt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(fe)),w!==s){if(P=[],ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie)),X!==s)for(;X!==s;)P.push(X),ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie));else P=s;if(P!==s){for(X=[],vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));oe!==s;)X.push(oe),vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));He=T,T=ka()}else A=T,T=s}else A=T,T=s;return ge[ve]={nextPos:A,result:T},T}function z(){var T,w=A*56+11,P=ge[w];return P?(A=P.nextPos,P.result):(T=pe(),T===s&&(T=he()),ge[w]={nextPos:A,result:T},T)}function pe(){var T,w,P,X,oe=A*56+12,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=z(),X!==s)for(;X!==s;)P.push(X),X=z();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=La(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function he(){var T,w=A*56+13,P=ge[w];return P?(A=P.nextPos,P.result):(T=W(),T===s&&(T=pe(),T===s&&(T=F())),ge[w]={nextPos:A,result:T},T)}function se(){var T,w,P,X=A*56+14,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===64?(w=R,A++):(w=s,Oe===0&&f(Ht)),w!==s?(P=z(),P!==s?(He=T,T=Ls(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function ae(){var T,w=A*56+15,P=ge[w];return P?(A=P.nextPos,P.result):(T=sn(),T===s&&(T=it(),T===s&&(T=qt(),T===s&&(T=du(),T===s&&(T=Qt())))),ge[w]={nextPos:A,result:T},T)}function Ce(){var T,w,P,X=A*56+16,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=ae(),w===s&&(w=Zs()),w!==s?(P=se(),P!==s?(He=T,T=Ma(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Se(){var T,w,P,X=A*56+17,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs())),w!==s?(P=Ve(),P!==s?(He=T,T=Ms(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Ve(){var T,w,P,X=A*56+18,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=wt(),P!==s?(He=T,T=Pa(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function je(){var T,w,P=A*56+19,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,mt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(yt)),w!==s&&(He=T,w=Yn()),T=w,ge[P]={nextPos:A,result:T},T)}function Fe(){var T,w=A*56+20,P=ge[w];return P?(A=P.nextPos,P.result):(T=It(),T===s&&(T=C(),T===s&&(T=je())),ge[w]={nextPos:A,result:T},T)}function It(){var T,w,P,X,oe=A*56+21,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=D(),w!==s?(i.charCodeAt(A)===47?(P=$,A++):(P=s,Oe===0&&f(zn)),P!==s?(X=D(),X!==s?(He=T,T=Ps(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xt(){var T,w,P,X=A*56+22,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du())))))))),P!==s)for(;P!==s;)w.push(P),P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du()))))))));else w=s;return w!==s&&(He=T,w=Bs(w)),T=w,ge[X]={nextPos:A,result:T},T}function wt(){var T,w=A*56+23,P=ge[w];return P?(A=P.nextPos,P.result):(T=F(),T===s&&(T=D(),T===s&&(T=R_(),T===s&&(T=fu(),T===s&&(T=tn(),T===s&&(T=A_()))))),ge[w]={nextPos:A,result:T},T)}function tn(){var T,w,P,X,oe=A*56+24,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=wt(),X!==s)for(;X!==s;)P.push(X),X=wt();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Ba(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function it(){var T,w,P,X,oe,ve=A*56+25,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(i.charCodeAt(A)===58?A++:Oe===0&&f(lt),P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===41?(oe=h,A++):(oe=s,Oe===0&&f(Kt)),oe!==s?(He=T,T=Ua(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function pt(){var T,w,P,X=A*56+26,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=D(),P!==s?(He=T,T=Us(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function sn(){var T,w,P,X,oe=A*56+27,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=it(),w!==s?(P=I_(),P!==s?(X=it(),X!==s?(He=T,T=Fa(w,P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Qt(){var T,w,P,X,oe,ve=A*56+28,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.substr(A,2)===b?(w=b,A+=2):(w=s,Oe===0&&f(Tt)),w!==s?(P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===93?(oe=S,A++):(oe=s,Oe===0&&f(Ue)),oe!==s?(He=T,T=Fs(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function qt(){var T,w,P,X,oe=A*56+29,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===91?(w=N,A++):(w=s,Oe===0&&f(Fn)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===93?(X=S,A++):(X=s,Oe===0&&f(Ue)),X!==s?(He=T,T=Ya(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function pr(){var T,w=A*56+30,P=ge[w];return P?(A=P.nextPos,P.result):(T=D(),T===s&&(T=y()),ge[w]={nextPos:A,result:T},T)}function Ws(){var T,w,P,X=A*56+31,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=hl(),P===s&&(P=pr()),P!==s)for(;P!==s;)w.push(P),P=hl(),P===s&&(P=pr());else w=s;return w!==s&&(He=T,w=Ys(w)),T=w,ge[X]={nextPos:A,result:T},T}function hl(){var T,w,P,X,oe=A*56+32,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===40?A++:Oe===0&&f(dt),w=pr(),w!==s?(P=I_(),P!==s?(X=Ws(),X!==s?(i.charCodeAt(A)===41?A++:Oe===0&&f(Kt),He=T,T=$s()):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xs(){var T,w,P,X,oe=A*56+33,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s){if(P=[],X=Ws(),X===s&&(X=F()),X!==s)for(;X!==s;)P.push(X),X=Ws(),X===s&&(X=F());else P=s;P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=ur(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function A_(){var T,w,P,X,oe=A*56+34,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s?(P=D(),P===s&&(P=fu()),P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=Ot(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function I_(){var T,w=A*56+35,P=ge[w];return P?(A=P.nextPos,P.result):(i.charCodeAt(A)===43?(T=M,A++):(T=s,Oe===0&&f(Hn)),T===s&&(i.charCodeAt(A)===45?(T=u,A++):(T=s,Oe===0&&f(rn)),T===s&&(i.charCodeAt(A)===42?(T=G,A++):(T=s,Oe===0&&f(Nn)),T===s&&(i.charCodeAt(A)===47?(T=$,A++):(T=s,Oe===0&&f(zn)),T===s&&(i.charCodeAt(A)===37?(T=te,A++):(T=s,Oe===0&&f(Ii)),T===s&&(i.charCodeAt(A)===94?(T=re,A++):(T=s,Oe===0&&f(wn)),T===s&&(i.charCodeAt(A)===124?(T=_,A++):(T=s,Oe===0&&f(H)),T===s&&(i.charCodeAt(A)===38?(T=ne,A++):(T=s,Oe===0&&f(Wt)),T===s&&(i.substr(A,2)===ee?(T=ee,A+=2):(T=s,Oe===0&&f(Cr)),T===s&&(i.substr(A,2)===B?(T=B,A+=2):(T=s,Oe===0&&f(ta))))))))))),ge[w]={nextPos:A,result:T},T)}function Zs(){var T,w,P=A*56+36,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=yR(),w===s&&(w=NR(),w===s&&(w=RR(),w===s&&(w=wR(),w===s&&(w=U(),w===s&&(w=IR(),w===s&&(w=ml(),w===s&&(w=vR(),w===s&&(w=F(),w===s&&(w=TR(),w===s&&(w=it(),w===s&&(w=Xs(),w===s&&(w=ER())))))))))))),w!==s&&(He=T,w=Gs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function ER(){var T,w,P=A*56+37,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===124?(w=_,A++):(w=s,Oe===0&&f(H)),w!==s&&(He=T,w=Ri()),T=w,ge[P]={nextPos:A,result:T},T)}function du(){var T,w,P,X,oe=A*56+38,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Qs(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function vR(){var T,w,P=A*56+39,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=pu(),w!==s&&(He=T,w=di(w)),T=w,ge[P]={nextPos:A,result:T},T)}function pu(){var T,w,P,X=A*56+40,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi)));else w=s;return w!==s&&(He=T,w=qs()),T=w,ge[X]={nextPos:A,result:T},T}function R_(){var T,w,P=A*56+41,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===63?(w=j,A++):(w=s,Oe===0&&f(na)),w!==s&&(He=T,w=Ni()),T=w,ge[P]={nextPos:A,result:T},T)}function fu(){var T,w,P,X,oe,ve,ft=A*56+42,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(P=D(),P!==s?(i.charCodeAt(A)===44?(X=m,A++):(X=s,Oe===0&&f(an)),X!==s?(oe=D(),oe!==s?(i.charCodeAt(A)===41?(ve=h,A++):(ve=s,Oe===0&&f(Kt)),ve!==s?(He=T,T=$a(P,oe)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function N_(){var T,w,P,X,oe=A*56+43,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=Se(),w===s&&(w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs()))),w!==s?(i.charCodeAt(A)===33?(P=K,A++):(P=s,Oe===0&&f(cr)),P!==s?(X=D(),X!==s?(He=T,T=Ga(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function TR(){var T,w,P=A*56+44,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Fe(),w!==s&&(He=T,w=Vs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function CR(){var T,w,P,X=A*56+45,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Fe(),w!==s?(i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P!==s?(He=T,T=wi(w)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function yR(){var T,w,P,X,oe,ve=A*56+46,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=CR(),w===s&&(w=null),i.charCodeAt(A)===114?(P=ue,A++):(P=s,Oe===0&&f(li)),P!==s?(X=A,Oe++,At.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(yr)),Oe--,oe===s?X=void 0:(A=X,X=s),X!==s?(He=T,T=Qa(w)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function ml(){var T,w,P,X,oe,ve=A*56+47,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=AR(),X===s&&(X=null),oe=y(),oe===s&&(oe=R_(),oe===s&&(oe=fu(),oe===s&&(oe=A_()))),oe!==s?(He=T,T=Di(w,P,X,oe)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function AR(){var T,w,P,X=A*56+48,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci)));else w=s;return w!==s&&(He=T,w=xi(w)),T=w,ge[X]={nextPos:A,result:T},T}function IR(){var T,w,P,X,oe=A*56+49,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,w=ml(),w!==s){if(P=[],X=ml(),X!==s)for(;X!==s;)P.push(X),X=ml();else P=s;P!==s?(X=hu(),X===s&&(X=null),He=T,T=qa(w,P,X)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function w_(){var T,w,P,X=A*56+50,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui)),P!==s)for(;P!==s;)w.push(P),Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui));else w=s;return w!==s&&(He=T,w=ia()),T=w,ge[X]={nextPos:A,result:T},T}function hu(){var T,w,P,X=A*56+51,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===37?(w=te,A++):(w=s,Oe===0&&f(Ii)),w!==s?(P=D(),P!==s?(He=T,T=pi(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function D_(){var T,w,P=A*56+52,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,Rn.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(q)),w!==s?(qe.test(i.charAt(A))?(i.charAt(A),A++):Oe===0&&f(ie),He=T,T=_n()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function RR(){var T,w,P,X,oe,ve,ft=A*56+53,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=D_(),X!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),oe=w_(),oe!==s?(ve=hu(),ve===s&&(ve=null),He=T,T=Va(w,P,X,oe,ve)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function NR(){var T,w,P,X,oe=A*56+54,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.substr(A,3)===De?(w=De,A+=3):(w=s,Oe===0&&f(de)),w===s&&(i.substr(A,2)===xe?(w=xe,A+=2):(w=s,Oe===0&&f(_e)),w===s&&(i.substr(A,2)===Ee?(w=Ee,A+=2):(w=s,Oe===0&&f(Ae)),w===s&&(i.charCodeAt(A)===105?(w=Ne,A++):(w=s,Oe===0&&f(Qe)),w===s&&(i.substr(A,3)===ce?(w=ce,A+=3):(w=s,Oe===0&&f(Pe)),w===s&&(i.substr(A,2)===Le?(w=Le,A+=2):(w=s,Oe===0&&f(Ct)),w===s&&(i.charCodeAt(A)===118?(w=Xe,A++):(w=s,Oe===0&&f(Dn)))))))),w!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),P=w_(),P===s&&(P=null),X=hu(),X===s&&(X=null),He=T,T=Zn(w,P,X)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function wR(){var T,w,P=A*56+55,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=D_(),w!==s&&(He=T,w=aa(w)),T=w,ge[P]={nextPos:A,result:T},T)}var x_=a.nodeOptions||{};function Ut(T,w,P=void 0){w.text=P||$n(),w.location=dl();for(var X in x_)(w[X]===void 0||w[X]===null)&&(w[X]=x_[X]);return new T(w)}if(sa=c(),sa!==s&&A===i.length)return sa;throw sa!==s&&Ae.collect("pitch"))}notes(){return this.evaluated.map(e=>e.collect("note"))}sounds(){return this.evaluated.map(e=>e.collect("sound"))}indices(){return this.evaluated.map(e=>e.collect("soundIndex"))}freqs(){return this.evaluated.map(e=>e.collect("freq"))}durations(){return this.evaluated.map(e=>e.collect("duration"))}octaves(){return this.evaluated.map(e=>e.collect("octave"))}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}invert(e){return this.applyOptions({inversion: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 ti(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())}update(){return this.evaluated=this.evaluate(this.values),this.applyTransformations(),this}evaluate(e,t={}){let n=e.map(i=>i.evaluate(t)).flat(1/0).filter(i=>i!==void 0);return t.subdivisions&&(n=fR(n)),n}totalDuration(){return this.evaluated.reduce((t,n)=>t+n.collect("duration"),0)}lead(){let e=this.evaluated.findIndex(t=>t instanceof Na);if(e>=0){for(let t=e+1;t<=this.evaluated.length;t++)if(this.evaluated[t]instanceof Na){const n=this.evaluated[e],i=this.evaluated[t],a=FG(n.notes(),i.notes()),s=ti(i);s.voiceLeadFromNotes(a,this.options.nodeOptions),this.evaluated[t]=s,e=t}}return this}}const fR=(r,e=void 0)=>r.map(n=>{if(n instanceof sR){const i=n.evaluated.length,a=(e||n.duration)/i;return fR(n.evaluated,a)}else return n.duration=e||n.duration,n}).flat(1/0),GG=r=>{let e={};return dG.forEach(t=>{if(r[t]!==void 0){const n=r[t];e[t]=n,delete r[t]}}),e};class QG{constructor(e,t){E(this,"api");E(this,"settings");E(this,"midiAccess",null);E(this,"midiOutputs",[]);E(this,"currentOutputIndex",0);E(this,"scheduledNotes",{});E(this,"midiInputs",[]);E(this,"currentInputIndex");E(this,"bufferLength",512);E(this,"noteInputBuffer",[]);E(this,"ccInputBuffer",[]);E(this,"activeNotes",[]);E(this,"stickyNotes",[]);E(this,"lastNote");E(this,"lastCC",{});E(this,"lastNoteInChannel",{});E(this,"lastCCInChannel",{});E(this,"midiClockInputIndex");E(this,"midiClockInput");E(this,"lastTimestamp",0);E(this,"midiClockDelta",0);E(this,"lastBPM");E(this,"roundedBPM",0);E(this,"clockBuffer",[]);E(this,"clockBufferLength",24);E(this,"clockTicks",0);E(this,"clockErrorCount",0);E(this,"skipOnError",0);this.api=e,this.settings=t,this.lastBPM=e.bpm(),this.roundedBPM=this.lastBPM,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),this.midiInputs=Array.from(this.midiAccess.inputs.values()),this.midiInputs.length===0?console.warn("No MIDI inputs available."):this.updateInputSelects()}catch(e){console.error("Failed to initialize MIDI:",e)}}getCurrentMidiPort(){return this.midiOutputs.length>0&&this.currentOutputIndex>=0&&this.currentOutputIndex0&&this.currentOutputIndex>=0&&this.currentOutputIndex0){const e=document.getElementById("midi-clock-input"),t=document.getElementById("default-midi-input");e.innerHTML="",t.innerHTML="";const n=document.createElement("option");n.value="-1",n.text="Internal",e.appendChild(n);const i=document.createElement("option");if(i.value="-1",i.text="None",t.appendChild(i),this.midiInputs.forEach((a,s)=>{const o=document.createElement("option");o.value=s.toString(),o.text=a.name||s.toString(),e.appendChild(o),t.appendChild(o.cloneNode(!0))}),this.settings.midi_clock_input){const a=this.getMidiInputIndex(this.settings.midi_clock_input);e.value=a.toString(),a>0&&(this.midiClockInput=this.midiInputs[a],this.registerMidiInputListener(a))}else e.value="-1";if(this.settings.default_midi_input){const a=this.getMidiInputIndex(this.settings.default_midi_input);t.value=a.toString(),a>0&&(this.currentInputIndex=a,this.registerMidiInputListener(a))}else t.value="-1";e.addEventListener("change",a=>{const s=a.target.value;if(s==="-1")this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=void 0,this.settings.midi_clock_input=void 0;else{const o=parseInt(s);this.midiClockInputIndex=o,this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=this.midiInputs[o],this.registerMidiInputListener(o),this.settings.midi_clock_input=this.midiClockInput.name||void 0}}),t.addEventListener("change",a=>{const s=a.target.value;s==="-1"?(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=void 0,this.settings.default_midi_input=void 0):(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=parseInt(s),this.registerMidiInputListener(this.currentInputIndex),this.settings.default_midi_input=this.midiInputs[this.currentInputIndex].name||void 0)})}}registerMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&!t.onmidimessage&&(t.onmidimessage=n=>{const i=n;if(t.name===this.settings.midi_clock_input&&(i.data[0]===248?this.skipOnError>0?this.skipOnError-=1:this.onMidiClock(n.timeStamp):i.data[0]===250?(console.log("MIDI start received"),this.api.stop(),this.api.play()):i.data[0]===252?(console.log("MIDI stop received"),this.api.pause()):i.data[0]===251?(console.log("MIDI continue received"),this.api.play()):i.data[0]===254&&console.log("MIDI active sensing received")),t.name===this.settings.default_midi_input){if(i.data[0]>=144&&i.data[0]<=159){const a=i.data[0]-144+1,s=i.data[1],o=i.data[2];this.lastNote={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.lastNoteInChannel[a]={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.settings.midi_channels_scripts&&this.api.script(a),this.pushToMidiInputBuffer({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.activeNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.removeFromStickyNotes(s,a)||this.stickyNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp})}if(i.data[0]>=128&&i.data[0]<=143){const a=i.data[0]-128+1,s=i.data[1];this.removeFromActiveNotes(s,a)}if(i.data[0]>=176&&i.data[0]<=191){const a=i.data[0]-176+1,s=i.data[1],o=i.data[2];this.lastCC[s]=o,this.lastCCInChannel[a]?this.lastCCInChannel[a][s]=o:(this.lastCCInChannel[a]={},this.lastCCInChannel[a][s]=o),this.pushToMidiCCBuffer({control:s,value:o,channel:a,timestamp:n.timeStamp})}}})}}removeFromActiveNotes(e,t){const n=this.activeNotes.findIndex(i=>i.note===e&&i.channel===t);n>=0&&this.activeNotes.splice(n,1)}removeFromStickyNotes(e,t){const n=this.stickyNotes.findIndex(i=>i.note===e&&i.channel===t);return n>=0?(this.stickyNotes.splice(n,1),!0):!1}stickyNotesFromChannel(e){return this.stickyNotes.filter(t=>t.channel===e)}activeNotesFromChannel(e){return this.activeNotes.filter(t=>t.channel===e)}killActiveNotes(){this.activeNotes=[]}killActiveNotesFromChannel(e){this.activeNotes=this.activeNotes.filter(t=>t.channel!==e)}pushToMidiInputBuffer(e){this.noteInputBuffer.push(e),this.noteInputBuffer.length>this.bufferLength&&this.noteInputBuffer.shift()}pushToMidiCCBuffer(e){this.ccInputBuffer.push(e),this.ccInputBuffer.length>this.bufferLength&&this.ccInputBuffer.shift()}findNoteFromBufferInChannel(e){const t=this.noteInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.noteInputBuffer[t];return this.noteInputBuffer.splice(t,1),n}else return}findCCFromBufferInChannel(e){const t=this.ccInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.ccInputBuffer[t];return this.ccInputBuffer.splice(t,1),n}else return}unregisterMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&(t.onmidimessage=null)}}onMidiClock(e){if(this.clockTicks+=1,this.lastTimestamp>0)if(this.lastTimestamp===e)this.clockErrorCount+=1;else if(this.clockErrorCount>0)console.log("Timestamp error count: ",this.clockErrorCount),console.log("Current timestamp: ",e),console.log("Last timestamp: ",this.lastTimestamp),console.log("Last delta: ",this.midiClockDelta),console.log("Current delta: ",e-this.lastTimestamp),console.log("BPMs",this.clockBuffer),this.clockErrorCount=0,this.skipOnError=this.settings.midi_clock_ppqn/4,e=0;else{this.midiClockDelta=e-this.lastTimestamp,this.lastBPM=60*(1e3/this.midiClockDelta/this.settings.midi_clock_ppqn),this.clockBuffer.push(this.lastBPM),this.clockBuffer.length>this.clockBufferLength&&this.clockBuffer.shift();const t=this.estimatedBPM();t!==this.roundedBPM&&(console.log("Estimated BPM: ",t),this.api.bpm(t),this.roundedBPM=t)}this.lastTimestamp=e}estimatedBPM(){const e=this.clockBuffer.reduce((t,n)=>t+n);return Math.round(e/this.clockBuffer.length)}sendMidiClock(){if(!this.midiClockInput){const e=this.midiOutputs[this.currentOutputIndex];e&&e.send([248])}}switchMidiOutput(e){const t=this.getMidiOutputIndex(e);return t!==-1?(this.currentOutputIndex=t,!0):!1}getMidiOutputIndex(e){if(typeof e=="number")return e<0||e>=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(n=>n.name===e);return t!==-1?t:(console.error(`MIDI output "${e}" not found.`),this.currentOutputIndex)}}getMidiInputIndex(e){if(typeof e=="number")return e<0||e>=this.midiInputs.length?(console.error(`Invalid MIDI input index. Index must be in the range 0-${this.midiInputs.length-1}.`),-1):e;{const t=this.midiInputs.findIndex(n=>n.name===e);return t!==-1?t:(console.error(`MIDI input "${e}" not found.`),-1)}}listMidiOutputs(){let e="Available MIDI Outputs: ";return this.midiOutputs.forEach((t,n)=>{e+=`(${n+1}) ${t.name} `}),e}sendMidiNote(e,t,n,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,n],c=[128+t,e,0];o.send(l),s&&this.sendPitchBend(s,t,a);const u=setTimeout(()=>{o.send(c),s&&this.sendPitchBend(8192,t,a),delete this.scheduledNotes[e]},(i-.02)*1e3);this.scheduledNotes[e]=u}else console.error("MIDI output not available.")}sendMidiOn(e,t,n,i=this.currentOutputIndex){typeof i=="string"&&(i=this.getMidiOutputIndex(i));const a=this.midiOutputs[i];if(e=Math.min(Math.max(e,0),127),a){const s=[144+t,e,n];a.send(s)}else console.error("MIDI output not available.")}sendMidiOff(e,t,n=this.currentOutputIndex){typeof n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];if(e=Math.min(Math.max(e,0),127),i){const a=[128+t,e,0];i.send(a)}else console.error("MIDI output not available.")}sendAllNotesOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,123,0];n.send(i)}else console.error("MIDI output not available.")}sendAllSoundOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,120,0];n.send(i)}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,n=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 n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];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 n=this.midiOutputs[this.currentOutputIndex];n?n.send([192+t,e]):console.error("MIDI output not available.")}sendMidiControlChange(e,t,n){const i=this.midiOutputs[this.currentOutputIndex];i?i.send([176+n,e,t]):console.error("MIDI output not available.")}panic(){const e=this.midiOutputs[this.currentOutputIndex];if(e){for(const t in this.scheduledNotes){const n=this.scheduledNotes[t];clearTimeout(n),e.send([128,parseInt(t),0])}this.scheduledNotes={}}else console.error("MIDI output not available.")}}class qG{constructor(e,t,n){E(this,"min");E(this,"max");E(this,"wrap");E(this,"position");this.min=e,this.max=t,this.wrap=n,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}}class C_{constructor(e){E(this,"seedValue");E(this,"randomGen",Math.random);E(this,"app");E(this,"values",{});E(this,"evenbar",e=>this.app.clock.time_position.bar%2===0?this.modify(e):this);E(this,"even",e=>this.app.clock.time_position.beat%2===0?this.modify(e):this);E(this,"odd",e=>this.app.clock.time_position.beat%2!==0?this.modify(e):this);E(this,"odds",(e,t)=>this.randomGen()this);E(this,"almostNever",e=>this.odds(.025,e));E(this,"rarely",e=>this.odds(.1,e));E(this,"scarcely",e=>this.odds(.25,e));E(this,"sometimes",e=>this.odds(.5,e));E(this,"often",e=>this.odds(.75,e));E(this,"frequently",e=>this.odds(.9,e));E(this,"almostAlways",e=>this.odds(.985,e));E(this,"always",e=>this.modify(e));E(this,"modify",e=>e(this));E(this,"seed",e=>(this.seedValue=e.toString(),this.randomGen=this.app.api.localSeededRandom(this.seedValue),this));E(this,"clear",()=>(this.app.api.clearLocalSeed(this.seedValue),this));E(this,"apply",e=>this.modify(e));E(this,"length",e=>(this.values.length=e,this));this.app=e,this.app.api.currentSeed&&(this.randomGen=this.app.api.randomGen)}}class hR extends C_{constructor(t){super(t);E(this,"octave",t=>(this.values.octave=t,this.update(),this));E(this,"key",t=>(this.values.key=t,this.update(),this));E(this,"scale",t=>(b_(t)?(this.values.scaleName=t,this.values.parsedScale=vi(t)):this.values.parsedScale=E_(t),this.update(),this));E(this,"freq",t=>{this.values.freq=t;const n=bG(t);return n%1!==0?(this.values.note=Math.floor(n),this.values.bend=oR(n)[1]):this.values.note=n,this});E(this,"update",()=>{})}}class tg extends hR{constructor(t,n){super(n);E(this,"nudge");E(this,"volume",t=>this.updateValue("volume",t));E(this,"vol",this.volume);E(this,"zrand",t=>this.updateValue("zrand",t));E(this,"curve",t=>this.updateValue("curve",t));E(this,"slide",t=>this.updateValue("slide",t));E(this,"sld",this.slide);E(this,"deltaSlide",t=>this.updateValue("deltaSlide",t));E(this,"dslide",this.deltaSlide);E(this,"pitchJump",t=>this.updateValue("pitchJump",t));E(this,"pj",this.pitchJump);E(this,"pitchJumpTime",t=>this.updateValue("pitchJumpTime",t));E(this,"pjt",this.pitchJumpTime);E(this,"lfo",t=>this.updateValue("lfo",t));E(this,"znoise",t=>this.updateValue("znoise",t));E(this,"noise",t=>this.updateValue("noise",t));E(this,"zmod",t=>this.updateValue("zmod",t));E(this,"zcrush",t=>this.updateValue("zcrush",t));E(this,"zdelay",t=>this.updateValue("zdelay",t));E(this,"sustainVolume",t=>this.updateValue("sustainVolume",t));E(this,"tremolo",t=>this.updateValue("tremolo",t));E(this,"dur",t=>this.updateValue("dur",t));E(this,"zzfx",t=>this.updateValue("zzfx",t));E(this,"fmi",t=>this.updateValue("fmi",t));E(this,"fmh",t=>this.updateValue("fmh",t));E(this,"fmenv",t=>this.updateValue("fmenv",t));E(this,"fmattack",t=>this.updateValue("fmattack",t));E(this,"fmatk",this.fmattack);E(this,"fmdecay",t=>this.updateValue("fmdecay",t));E(this,"fmdec",this.fmdecay);E(this,"fmsustain",t=>this.updateValue("fmsustain",t));E(this,"fmsus",this.fmsustain);E(this,"fmrelease",t=>this.updateValue("fmrelease",t));E(this,"fmrel",this.fmrelease);E(this,"fmvelocity",t=>this.updateValue("fmvelocity",t));E(this,"fmvel",this.fmvelocity);E(this,"fmwave",t=>this.updateValue("fmwave",t));E(this,"fmw",this.fmwave);E(this,"ftype",t=>this.updateValue("ftype",t));E(this,"fanchor",t=>this.updateValue("fanchor",t));E(this,"attack",t=>this.updateValue("attack",t));E(this,"atk",this.attack);E(this,"decay",t=>this.updateValue("decay",t));E(this,"dec",this.decay);E(this,"sustain",t=>this.updateValue("sustain",t));E(this,"sus",this.sustain);E(this,"release",t=>this.updateValue("release",t));E(this,"rel",this.release);E(this,"adsr",(t,n,i,a)=>(this.attack(t),this.decay(n),this.sustain(i),this.release(a),this));E(this,"ad",(t,n)=>(this.attack(t),this.decay(n),this.sustain(0),this.release(0),this));E(this,"lpenv",t=>this.updateValue("lpenv",t));E(this,"lpe",t=>this.updateValue("lpenv",t));E(this,"lpattack",t=>this.updateValue("lpattack",t));E(this,"lpa",this.lpattack);E(this,"lpdecay",t=>this.updateValue("lpdecay",t));E(this,"lpd",this.lpdecay);E(this,"lpsustain",t=>this.updateValue("lpsustain",t));E(this,"lps",this.lpsustain);E(this,"lprelease",t=>this.updateValue("lprelease",t));E(this,"lpr",this.lprelease);E(this,"cutoff",(t,n)=>(this.updateValue("cutoff",t),n&&this.resonance(n),this));E(this,"lpf",this.cutoff);E(this,"resonance",t=>(t>=0&&t<=1&&this.updateValue("resonance",50*t),this));E(this,"lpq",this.resonance);E(this,"lpadsr",(t,n,i,a,s)=>(this.lpenv(t),this.lpattack(n),this.lpdecay(i),this.lpsustain(a),this.lprelease(s),this));E(this,"lpad",(t,n,i)=>(this.lpenv(t),this.lpattack(n),this.lpdecay(i),this.lpsustain(0),this.lprelease(0),this));E(this,"hpenv",t=>this.updateValue("hpenv",t));E(this,"hpe",t=>this.updateValue("hpe",t));E(this,"hpattack",t=>this.updateValue("hpattack",t));E(this,"hpa",this.hpattack);E(this,"hpdecay",t=>this.updateValue("hpdecay",t));E(this,"hpd",this.hpdecay);E(this,"hpsustain",t=>this.updateValue("hpsustain",t));E(this,"hpsus",this.hpsustain);E(this,"hprelease",t=>this.updateValue("hprelease",t));E(this,"hpr",this.hprelease);E(this,"hcutoff",t=>this.updateValue("hcutoff",t));E(this,"hpf",this.hcutoff);E(this,"hresonance",(t,n)=>(this.updateValue("hresonance",t),n&&this.resonance(n),this));E(this,"hpq",this.hresonance);E(this,"hpadsr",(t,n,i,a,s)=>(this.hpenv(t),this.hpattack(n),this.hpdecay(i),this.hpsustain(a),this.hprelease(s),this));E(this,"hpad",(t,n,i)=>(this.hpenv(t),this.hpattack(n),this.hpdecay(i),this.hpsustain(0),this.hprelease(0),this));E(this,"bpenv",t=>this.updateValue("bpenv",t));E(this,"bpe",t=>this.updateValue("bpe",t));E(this,"bpattack",t=>this.updateValue("bpattack",t));E(this,"bpa",this.bpattack);E(this,"bpdecay",t=>this.updateValue("bpdecay",t));E(this,"bpd",this.bpdecay);E(this,"bpsustain",t=>this.updateValue("bpsustain",t));E(this,"bps",this.bpsustain);E(this,"bprelease",t=>this.updateValue("bprelease",t));E(this,"bpr",this.bprelease);E(this,"bandf",(t,n)=>(this.updateValue("bandf",t),n&&this.resonance(n),this));E(this,"bpf",this.bandf);E(this,"bandq",t=>this.updateValue("bandq",t));E(this,"bpq",this.bandq);E(this,"bpadsr",(t,n,i,a,s)=>(this.bpenv(t),this.bpattack(n),this.bpdecay(i),this.bpsustain(a),this.bprelease(s),this));E(this,"bpad",(t,n,i)=>(this.bpenv(t),this.bpattack(n),this.bpdecay(i),this.bpsustain(0),this.bprelease(0),this));E(this,"freq",t=>this.updateValue("freq",t));E(this,"f",this.freq);E(this,"vib",t=>this.updateValue("vib",t));E(this,"vibmod",t=>this.updateValue("vibmod",t));E(this,"fm",t=>{if(typeof t=="number")this.values.fmi=t;else{let n=t.split(":");this.values.fmi=parseFloat(n[0]),n.length>1&&(this.values.fmh=parseFloat(n[1]))}return this});E(this,"loop",t=>this.updateValue("loop",t));E(this,"loopBegin",t=>this.updateValue("loopBegin",t));E(this,"loopEnd",t=>this.updateValue("loopEnd",t));E(this,"begin",t=>this.updateValue("begin",t));E(this,"end",t=>this.updateValue("end",t));E(this,"gain",t=>this.updateValue("gain",t));E(this,"dbgain",t=>this.updateValue("gain",Math.min(Math.pow(10,t/20),10)));E(this,"db",this.dbgain);E(this,"velocity",t=>this.updateValue("velocity",t));E(this,"vel",this.velocity);E(this,"pan",t=>this.updateValue("pan",t));E(this,"sound",t=>this.updateValue("s",t));E(this,"chord",(t,...n)=>(typeof t=="string"?t=xG(t).map(a=>({note:a,freq:Zr(a)})):t instanceof Array&&typeof t[0]=="number"?t=t.map(i=>({note:i,freq:Zr(i)})):typeof t=="number"&&n.length>0&&(t=[t,...n].map(i=>({note:i,freq:Zr(i)}))),this.updateValue("chord",t)));E(this,"invert",(t=0)=>{if(this.values.chord){let n=this.values.chord.map(a=>a.note);n=t<0?[...n].reverse():n;for(let a=0;a({note:a,freq:Zr(a)}));return this.updateValue("chord",i)}else return this});E(this,"snd",this.sound);E(this,"cut",t=>this.updateValue("cut",t));E(this,"clip",t=>this.updateValue("clip",t));E(this,"n",t=>this.updateValue("n",t));E(this,"note",t=>typeof t=="string"?this.updateValue("note",Ur(t)):typeof t==null||t==null?this.updateValue("note",0).updateValue("gain",0):this.updateValue("note",t));E(this,"speed",t=>this.updateValue("speed",t));E(this,"spd",this.speed);E(this,"coarse",t=>this.updateValue("coarse",t));E(this,"crush",t=>this.updateValue("crush",t));E(this,"shape",t=>this.updateValue("shape",t));E(this,"vowel",t=>this.updateValue("vowel",t));E(this,"vow",this.vowel);E(this,"delay",t=>this.updateValue("delay",t));E(this,"del",this.delay);E(this,"delayfeedback",t=>this.updateValue("delayfeedback",t));E(this,"delayfb",this.delayfeedback);E(this,"delaytime",t=>this.updateValue("delaytime",t));E(this,"delayt",this.delaytime);E(this,"orbit",t=>this.updateValue("orbit",t));E(this,"o",this.orbit);E(this,"room",t=>this.updateValue("room",t));E(this,"rm",this.room);E(this,"roomfade",t=>this.updateValue("roomfade",t));E(this,"rfade",this.roomfade);E(this,"roomlp",t=>this.updateValue("roomlp",t));E(this,"rlp",this.roomlp);E(this,"roomdim",t=>this.updateValue("roomdim",t));E(this,"rdim",this.roomdim);E(this,"size",t=>this.updateValue("roomsize",t));E(this,"sz",this.size);E(this,"rev",(t,n,i,a,s)=>(this.updateValue("room",t),this.updateValue("roomsize",n),i&&this.updateValue("roomfade",i),a&&this.updateValue("roomlp",a),s&&this.updateValue("roomdim",s),this));E(this,"comp",t=>this.updateValue("compressor",t));E(this,"cmp",this.comp);E(this,"ratio",t=>this.updateValue("compressorRatio",t));E(this,"rt",this.ratio);E(this,"knee",t=>this.updateValue("compressorKnee",t));E(this,"kn",this.knee);E(this,"compAttack",t=>this.updateValue("compressorAttack",t));E(this,"cmpa",this.compAttack);E(this,"compRelease",t=>this.updateValue("compressorRelease",t));E(this,"cmpr",this.compRelease);E(this,"stretch",t=>(this.updateValue("unit","c"),this.updateValue("speed",1/t),this.updateValue("cut",t),this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.freq=Zr(t)});E(this,"out",()=>{this.values.chord?this.values.chord.forEach(t=>{const n={...this.values};n.freq=t.freq,P_(n,this.nudge,this.values.dur)}):P_(this.values,this.nudge,this.values.dur)});this.app=n,this.nudge=n.dough_nudge/100,typeof t=="string"?t.includes(":")?this.values={s:t.split(":")[0],n:t.split(":")[1],dur:n.clock.convertPulseToSecond(n.clock.ppqn),analyze:!0}:this.values={s:t,dur:.5,analyze:!0}:this.values=t}updateValue(t,n){return this.values[t]=n,this}}class ng extends hR{constructor(t,n){super(n);E(this,"midiConnection");E(this,"chord",t=>(this.values.chord=t,this));E(this,"note",t=>(this.values.note=t,this));E(this,"sustain",t=>(this.values.sustain=t,this));E(this,"channel",t=>(this.values.channel=t,this));E(this,"port",t=>(this.values.port=this.midiConnection.getMidiOutputIndex(t),this));E(this,"add",t=>(this.values.note+=t,this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"bend",t=>(this.values.bend=t,this));E(this,"random",(t=0,n=127)=>(t=Math.min(Math.max(t,0),127),n=Math.min(Math.max(n,0),127),this.values.note=Math.floor(this.randomGen()*(n-t+1))+t,this));E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.note=t,this.values.freq=Zr(t),n&&(this.values.bend=n)});E(this,"out",()=>{function t(n,i){const a=i&&i.channel?i.channel:0,s=n.values.channel?n.values.channel:a,o=n.values.velocity?n.values.velocity:100,l=i&&i.note?i.note:60,c=n.values.note?n.values.note:l,u=n.values.sustain?n.values.sustain*n.app.clock.pulse_duration*n.app.api.ppqn():n.app.clock.pulse_duration*n.app.api.ppqn(),p=n.values.bend?n.values.bend:void 0,m=n.values.port?n.midiConnection.getMidiOutputIndex(n.values.port):n.midiConnection.getCurrentMidiPortIndex();n.midiConnection.sendMidiNote(c,s,o,u,m,p)}this.values.chord?this.values.chord.forEach(n=>{t(this,n)}):t(this)});this.app=n,typeof t=="number"?this.values.note=t:this.values=t,this.midiConnection=n.api.MidiConnection}}const po=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,mR=new Set,rg=typeof process=="object"&&process?process:{},gR=(r,e,t,n)=>{typeof rg.emitWarning=="function"?rg.emitWarning(r,e,t,n):console.error(`[${t}] ${e}: ${r}`)};let Qc=globalThis.AbortController,_T=globalThis.AbortSignal;var OT;if(typeof Qc>"u"){_T=class{constructor(){E(this,"onabort");E(this,"_onabort",[]);E(this,"reason");E(this,"aborted",!1)}addEventListener(n,i){this._onabort.push(i)}},Qc=class{constructor(){E(this,"signal",new _T);e()}abort(n){var i,a;if(!this.signal.aborted){this.signal.reason=n,this.signal.aborted=!0;for(const s of this.signal._onabort)s(n);(a=(i=this.signal).onabort)==null||a.call(i,n)}}};let r=((OT=rg.env)==null?void 0:OT.LRU_CACHE_IGNORE_AC_WARNING)!=="1";const e=()=>{r&&(r=!1,gR("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 VG=r=>!mR.has(r),Bi=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),_R=r=>Bi(r)?r<=Math.pow(2,8)?Uint8Array:r<=Math.pow(2,16)?Uint16Array:r<=Math.pow(2,32)?Uint32Array:r<=Number.MAX_SAFE_INTEGER?rc:null:null;class rc extends Array{constructor(e){super(e),this.fill(0)}}var cs;const fa=class fa{constructor(e,t){E(this,"heap");E(this,"length");if(!V(fa,cs))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}static create(e){const t=_R(e);if(!t)return[];We(fa,cs,!0);const n=new fa(e,t);return We(fa,cs,!1),n}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};cs=new WeakMap,at(fa,cs,!1);let ig=fa;var Rr,er,Nr,wr,us,on,Dr,ln,Lt,nt,Ln,tr,Cn,hn,xr,mn,gi,_i,kr,Lr,qi,Mn,jo,sg,Oa,Si,Jo,nr,zc,SR,ba,ds,el,qr,Ui,Vr,Fi,tl,og,ps,ic,fs,ac,Dt,Ft,nl,lg,Ea,bo;const y_=class y_{constructor(e){at(this,jo);at(this,zc);at(this,qr);at(this,Vr);at(this,tl);at(this,ps);at(this,fs);at(this,Dt);at(this,nl);at(this,Ea);at(this,Rr,void 0);at(this,er,void 0);at(this,Nr,void 0);at(this,wr,void 0);at(this,us,void 0);E(this,"ttl");E(this,"ttlResolution");E(this,"ttlAutopurge");E(this,"updateAgeOnGet");E(this,"updateAgeOnHas");E(this,"allowStale");E(this,"noDisposeOnSet");E(this,"noUpdateTTL");E(this,"maxEntrySize");E(this,"sizeCalculation");E(this,"noDeleteOnFetchRejection");E(this,"noDeleteOnStaleGet");E(this,"allowStaleOnFetchAbort");E(this,"allowStaleOnFetchRejection");E(this,"ignoreFetchAbort");at(this,on,void 0);at(this,Dr,void 0);at(this,ln,void 0);at(this,Lt,void 0);at(this,nt,void 0);at(this,Ln,void 0);at(this,tr,void 0);at(this,Cn,void 0);at(this,hn,void 0);at(this,xr,void 0);at(this,mn,void 0);at(this,gi,void 0);at(this,_i,void 0);at(this,kr,void 0);at(this,Lr,void 0);at(this,qi,void 0);at(this,Mn,void 0);at(this,Oa,()=>{});at(this,Si,()=>{});at(this,Jo,()=>{});at(this,nr,()=>!1);at(this,ba,e=>{});at(this,ds,(e,t,n)=>{});at(this,el,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});const{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:s,updateAgeOnHas:o,allowStale:l,dispose:c,disposeAfter:u,noDisposeOnSet:p,noUpdateTTL:m,maxSize:_=0,maxEntrySize:v=0,sizeCalculation:I,fetchMethod:R,noDeleteOnFetchRejection:x,noDeleteOnStaleGet:$,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:h,ignoreFetchAbort:b}=e;if(t!==0&&!Bi(t))throw new TypeError("max option must be a nonnegative integer");const S=t?_R(t):Array;if(!S)throw new Error("invalid max value: "+t);if(We(this,Rr,t),We(this,er,_),this.maxEntrySize=v||V(this,er),this.sizeCalculation=I,this.sizeCalculation){if(!V(this,er)&&!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(R!==void 0&&typeof R!="function")throw new TypeError("fetchMethod must be a function if specified");if(We(this,us,R),We(this,qi,!!R),We(this,ln,new Map),We(this,Lt,new Array(t).fill(void 0)),We(this,nt,new Array(t).fill(void 0)),We(this,Ln,new S(t)),We(this,tr,new S(t)),We(this,Cn,0),We(this,hn,0),We(this,xr,ig.create(t)),We(this,on,0),We(this,Dr,0),typeof c=="function"&&We(this,Nr,c),typeof u=="function"?(We(this,wr,u),We(this,mn,[])):(We(this,wr,void 0),We(this,mn,void 0)),We(this,Lr,!!V(this,Nr)),We(this,Mn,!!V(this,wr)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!x,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!h,this.ignoreFetchAbort=!!b,this.maxEntrySize!==0){if(V(this,er)!==0&&!Bi(V(this,er)))throw new TypeError("maxSize must be a positive integer if specified");if(!Bi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");ze(this,zc,SR).call(this)}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!$,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!o,this.ttlResolution=Bi(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!Bi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");ze(this,jo,sg).call(this)}if(V(this,Rr)===0&&this.ttl===0&&V(this,er)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!V(this,Rr)&&!V(this,er)){const N="LRU_CACHE_UNBOUNDED";VG(N)&&(mR.add(N),gR("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",N,y_))}}static unsafeExposeInternals(e){return{starts:V(e,_i),ttls:V(e,kr),sizes:V(e,gi),keyMap:V(e,ln),keyList:V(e,Lt),valList:V(e,nt),next:V(e,Ln),prev:V(e,tr),get head(){return V(e,Cn)},get tail(){return V(e,hn)},free:V(e,xr),isBackgroundFetch:t=>{var n;return ze(n=e,Dt,Ft).call(n,t)},backgroundFetch:(t,n,i,a)=>{var s;return ze(s=e,fs,ac).call(s,t,n,i,a)},moveToTail:t=>{var n;return ze(n=e,Ea,bo).call(n,t)},indexes:t=>{var n;return ze(n=e,qr,Ui).call(n,t)},rindexes:t=>{var n;return ze(n=e,Vr,Fi).call(n,t)},isStale:t=>{var n;return V(n=e,nr).call(n,t)}}}get max(){return V(this,Rr)}get maxSize(){return V(this,er)}get calculatedSize(){return V(this,Dr)}get size(){return V(this,on)}get fetchMethod(){return V(this,us)}get dispose(){return V(this,Nr)}get disposeAfter(){return V(this,wr)}getRemainingTTL(e){return V(this,ln).has(e)?1/0:0}*entries(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*rentries(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*keys(){for(const e of ze(this,qr,Ui).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*rkeys(){for(const e of ze(this,Vr,Fi).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*values(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}*rvalues(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}[Symbol.iterator](){return this.entries()}find(e,t={}){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,V(this,Lt)[n],this))return this.get(V(this,Lt)[n],t)}}forEach(e,t=this){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}rforEach(e,t=this){for(const n of ze(this,Vr,Fi).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}purgeStale(){let e=!1;for(const t of ze(this,Vr,Fi).call(this,{allowStale:!0}))V(this,nr).call(this,t)&&(this.delete(V(this,Lt)[t]),e=!0);return e}dump(){const e=[];for(const t of ze(this,qr,Ui).call(this,{allowStale:!0})){const n=V(this,Lt)[t],i=V(this,nt)[t],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;const s={value:a};if(V(this,kr)&&V(this,_i)){s.ttl=V(this,kr)[t];const o=po.now()-V(this,_i)[t];s.start=Math.floor(Date.now()-o)}V(this,gi)&&(s.size=V(this,gi)[t]),e.unshift([n,s])}return e}load(e){this.clear();for(const[t,n]of e){if(n.start){const i=Date.now()-n.start;n.start=po.now()-i}this.set(t,n.value,n)}}set(e,t,n={}){var m,_,v,I,R;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}=n;let{noUpdateTTL:c=this.noUpdateTTL}=n;const u=V(this,el).call(this,e,t,n.size||0,o);if(this.maxEntrySize&&u>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=!0),this.delete(e),this;let p=V(this,on)===0?void 0:V(this,ln).get(e);if(p===void 0)p=V(this,on)===0?V(this,hn):V(this,xr).length!==0?V(this,xr).pop():V(this,on)===V(this,Rr)?ze(this,ps,ic).call(this,!1):V(this,on),V(this,Lt)[p]=e,V(this,nt)[p]=t,V(this,ln).set(e,p),V(this,Ln)[V(this,hn)]=p,V(this,tr)[p]=V(this,hn),We(this,hn,p),gl(this,on)._++,V(this,ds).call(this,p,u,l),l&&(l.set="add"),c=!1;else{ze(this,Ea,bo).call(this,p);const x=V(this,nt)[p];if(t!==x){if(V(this,qi)&&ze(this,Dt,Ft).call(this,x)){x.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:$}=x;$!==void 0&&!s&&(V(this,Lr)&&((m=V(this,Nr))==null||m.call(this,$,e,"set")),V(this,Mn)&&((_=V(this,mn))==null||_.push([$,e,"set"])))}else s||(V(this,Lr)&&((v=V(this,Nr))==null||v.call(this,x,e,"set")),V(this,Mn)&&((I=V(this,mn))==null||I.push([x,e,"set"])));if(V(this,ba).call(this,p),V(this,ds).call(this,p,u,l),V(this,nt)[p]=t,l){l.set="replace";const $=x&&ze(this,Dt,Ft).call(this,x)?x.__staleWhileFetching:x;$!==void 0&&(l.oldValue=$)}}else l&&(l.set="update")}if(i!==0&&!V(this,kr)&&ze(this,jo,sg).call(this),V(this,kr)&&(c||V(this,Jo).call(this,p,i,a),l&&V(this,Si).call(this,l,p)),!s&&V(this,Mn)&&V(this,mn)){const x=V(this,mn);let $;for(;$=x==null?void 0:x.shift();)(R=V(this,wr))==null||R.call(this,...$)}return this}pop(){var e;try{for(;V(this,on);){const t=V(this,nt)[V(this,Cn)];if(ze(this,ps,ic).call(this,!0),ze(this,Dt,Ft).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(V(this,Mn)&&V(this,mn)){const t=V(this,mn);let n;for(;n=t==null?void 0:t.shift();)(e=V(this,wr))==null||e.call(this,...n)}}}has(e,t={}){const{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=V(this,ln).get(e);if(a!==void 0){const s=V(this,nt)[a];if(ze(this,Dt,Ft).call(this,s)&&s.__staleWhileFetching===void 0)return!1;if(V(this,nr).call(this,a))i&&(i.has="stale",V(this,Si).call(this,i,a));else return n&&V(this,Oa).call(this,a),i&&(i.has="hit",V(this,Si).call(this,i,a)),!0}else i&&(i.has="miss");return!1}peek(e,t={}){const{allowStale:n=this.allowStale}=t,i=V(this,ln).get(e);if(i!==void 0&&(n||!V(this,nr).call(this,i))){const a=V(this,nt)[i];return ze(this,Dt,Ft).call(this,a)?a.__staleWhileFetching:a}}async fetch(e,t={}){const{allowStale:n=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:u=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:m=this.allowStaleOnFetchRejection,ignoreFetchAbort:_=this.ignoreFetchAbort,allowStaleOnFetchAbort:v=this.allowStaleOnFetchAbort,context:I,forceRefresh:R=!1,status:x,signal:$}=t;if(!V(this,qi))return x&&(x.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:x});const Z={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:s,noDisposeOnSet:o,size:l,sizeCalculation:c,noUpdateTTL:u,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:v,ignoreFetchAbort:_,status:x,signal:$};let h=V(this,ln).get(e);if(h===void 0){x&&(x.fetch="miss");const b=ze(this,fs,ac).call(this,e,h,Z,I);return b.__returned=b}else{const b=V(this,nt)[h];if(ze(this,Dt,Ft).call(this,b)){const M=n&&b.__staleWhileFetching!==void 0;return x&&(x.fetch="inflight",M&&(x.returnedStale=!0)),M?b.__staleWhileFetching:b.__returned=b}const S=V(this,nr).call(this,h);if(!R&&!S)return x&&(x.fetch="hit"),ze(this,Ea,bo).call(this,h),i&&V(this,Oa).call(this,h),x&&V(this,Si).call(this,x,h),b;const N=ze(this,fs,ac).call(this,e,h,Z,I),L=N.__staleWhileFetching!==void 0&&n;return x&&(x.fetch=S?"stale":"refresh",L&&S&&(x.returnedStale=!0)),L?N.__staleWhileFetching:N.__returned=N}}get(e,t={}){const{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:s}=t,o=V(this,ln).get(e);if(o!==void 0){const l=V(this,nt)[o],c=ze(this,Dt,Ft).call(this,l);return s&&V(this,Si).call(this,s,o),V(this,nr).call(this,o)?(s&&(s.get="stale"),c?(s&&n&&l.__staleWhileFetching!==void 0&&(s.returnedStale=!0),n?l.__staleWhileFetching:void 0):(a||this.delete(e),s&&n&&(s.returnedStale=!0),n?l:void 0)):(s&&(s.get="hit"),c?l.__staleWhileFetching:(ze(this,Ea,bo).call(this,o),i&&V(this,Oa).call(this,o),l))}else s&&(s.get="miss")}delete(e){var n,i,a,s;let t=!1;if(V(this,on)!==0){const o=V(this,ln).get(e);if(o!==void 0)if(t=!0,V(this,on)===1)this.clear();else{V(this,ba).call(this,o);const l=V(this,nt)[o];ze(this,Dt,Ft).call(this,l)?l.__abortController.abort(new Error("deleted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((n=V(this,Nr))==null||n.call(this,l,e,"delete")),V(this,Mn)&&((i=V(this,mn))==null||i.push([l,e,"delete"]))),V(this,ln).delete(e),V(this,Lt)[o]=void 0,V(this,nt)[o]=void 0,o===V(this,hn)?We(this,hn,V(this,tr)[o]):o===V(this,Cn)?We(this,Cn,V(this,Ln)[o]):(V(this,Ln)[V(this,tr)[o]]=V(this,Ln)[o],V(this,tr)[V(this,Ln)[o]]=V(this,tr)[o]),gl(this,on)._--,V(this,xr).push(o)}}if(V(this,Mn)&&((a=V(this,mn))!=null&&a.length)){const o=V(this,mn);let l;for(;l=o==null?void 0:o.shift();)(s=V(this,wr))==null||s.call(this,...l)}return t}clear(){var e,t,n;for(const i of ze(this,Vr,Fi).call(this,{allowStale:!0})){const a=V(this,nt)[i];if(ze(this,Dt,Ft).call(this,a))a.__abortController.abort(new Error("deleted"));else{const s=V(this,Lt)[i];V(this,Lr)&&((e=V(this,Nr))==null||e.call(this,a,s,"delete")),V(this,Mn)&&((t=V(this,mn))==null||t.push([a,s,"delete"]))}}if(V(this,ln).clear(),V(this,nt).fill(void 0),V(this,Lt).fill(void 0),V(this,kr)&&V(this,_i)&&(V(this,kr).fill(0),V(this,_i).fill(0)),V(this,gi)&&V(this,gi).fill(0),We(this,Cn,0),We(this,hn,0),V(this,xr).length=0,We(this,Dr,0),We(this,on,0),V(this,Mn)&&V(this,mn)){const i=V(this,mn);let a;for(;a=i==null?void 0:i.shift();)(n=V(this,wr))==null||n.call(this,...a)}}};Rr=new WeakMap,er=new WeakMap,Nr=new WeakMap,wr=new WeakMap,us=new WeakMap,on=new WeakMap,Dr=new WeakMap,ln=new WeakMap,Lt=new WeakMap,nt=new WeakMap,Ln=new WeakMap,tr=new WeakMap,Cn=new WeakMap,hn=new WeakMap,xr=new WeakMap,mn=new WeakMap,gi=new WeakMap,_i=new WeakMap,kr=new WeakMap,Lr=new WeakMap,qi=new WeakMap,Mn=new WeakMap,jo=new WeakSet,sg=function(){const e=new rc(V(this,Rr)),t=new rc(V(this,Rr));We(this,kr,e),We(this,_i,t),We(this,Jo,(a,s,o=po.now())=>{if(t[a]=s!==0?o:0,e[a]=s,s!==0&&this.ttlAutopurge){const l=setTimeout(()=>{V(this,nr).call(this,a)&&this.delete(V(this,Lt)[a])},s+1);l.unref&&l.unref()}}),We(this,Oa,a=>{t[a]=e[a]!==0?po.now():0}),We(this,Si,(a,s)=>{if(e[s]){const o=e[s],l=t[s];a.ttl=o,a.start=l,a.now=n||i();const c=a.now-l;a.remainingTTL=o-c}});let n=0;const i=()=>{const a=po.now();if(this.ttlResolution>0){n=a;const s=setTimeout(()=>n=0,this.ttlResolution);s.unref&&s.unref()}return a};this.getRemainingTTL=a=>{const s=V(this,ln).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=(n||i())-l;return o-c},We(this,nr,a=>e[a]!==0&&t[a]!==0&&(n||i())-t[a]>e[a])},Oa=new WeakMap,Si=new WeakMap,Jo=new WeakMap,nr=new WeakMap,zc=new WeakSet,SR=function(){const e=new rc(V(this,Rr));We(this,Dr,0),We(this,gi,e),We(this,ba,t=>{We(this,Dr,V(this,Dr)-e[t]),e[t]=0}),We(this,el,(t,n,i,a)=>{if(ze(this,Dt,Ft).call(this,n))return 0;if(!Bi(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!Bi(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}),We(this,ds,(t,n,i)=>{if(e[t]=n,V(this,er)){const a=V(this,er)-e[t];for(;V(this,Dr)>a;)ze(this,ps,ic).call(this,!0)}We(this,Dr,V(this,Dr)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=V(this,Dr))})},ba=new WeakMap,ds=new WeakMap,el=new WeakMap,qr=new WeakSet,Ui=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,hn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,Cn)));)t=V(this,tr)[t]},Vr=new WeakSet,Fi=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,Cn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,hn)));)t=V(this,Ln)[t]},tl=new WeakSet,og=function(e){return e!==void 0&&V(this,ln).get(V(this,Lt)[e])===e},ps=new WeakSet,ic=function(e){var a,s;const t=V(this,Cn),n=V(this,Lt)[t],i=V(this,nt)[t];return V(this,qi)&&ze(this,Dt,Ft).call(this,i)?i.__abortController.abort(new Error("evicted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((a=V(this,Nr))==null||a.call(this,i,n,"evict")),V(this,Mn)&&((s=V(this,mn))==null||s.push([i,n,"evict"]))),V(this,ba).call(this,t),e&&(V(this,Lt)[t]=void 0,V(this,nt)[t]=void 0,V(this,xr).push(t)),V(this,on)===1?(We(this,Cn,We(this,hn,0)),V(this,xr).length=0):We(this,Cn,V(this,Ln)[t]),V(this,ln).delete(n),gl(this,on)._--,t},fs=new WeakSet,ac=function(e,t,n,i){const a=t===void 0?void 0:V(this,nt)[t];if(ze(this,Dt,Ft).call(this,a))return a;const s=new Qc,{signal:o}=n;o==null||o.addEventListener("abort",()=>s.abort(o.reason),{signal:s.signal});const l={signal:s.signal,options:n,context:i},c=(I,R=!1)=>{const{aborted:x}=s.signal,$=n.ignoreFetchAbort&&I!==void 0;if(n.status&&(x&&!R?(n.status.fetchAborted=!0,n.status.fetchError=s.signal.reason,$&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),x&&!$&&!R)return p(s.signal.reason);const Z=_;return V(this,nt)[t]===_&&(I===void 0?Z.__staleWhileFetching?V(this,nt)[t]=Z.__staleWhileFetching:this.delete(e):(n.status&&(n.status.fetchUpdated=!0),this.set(e,I,l.options))),I},u=I=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=I),p(I)),p=I=>{const{aborted:R}=s.signal,x=R&&n.allowStaleOnFetchAbort,$=x||n.allowStaleOnFetchRejection,Z=$||n.noDeleteOnFetchRejection,h=_;if(V(this,nt)[t]===_&&(!Z||h.__staleWhileFetching===void 0?this.delete(e):x||(V(this,nt)[t]=h.__staleWhileFetching)),$)return n.status&&h.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw I},m=(I,R)=>{var $;const x=($=V(this,us))==null?void 0:$.call(this,e,a,l);x&&x instanceof Promise&&x.then(Z=>I(Z===void 0?void 0:Z),R),s.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(I(void 0),n.allowStaleOnFetchAbort&&(I=Z=>c(Z,!0)))})};n.status&&(n.status.fetchDispatched=!0);const _=new Promise(m).then(c,u),v=Object.assign(_,{__abortController:s,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,v,{...l.options,status:void 0}),t=V(this,ln).get(e)):V(this,nt)[t]=v,v},Dt=new WeakSet,Ft=function(e){if(!V(this,qi))return!1;const t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Qc},nl=new WeakSet,lg=function(e,t){V(this,tr)[t]=e,V(this,Ln)[e]=t},Ea=new WeakSet,bo=function(e){e!==V(this,hn)&&(e===V(this,Cn)?We(this,Cn,V(this,Ln)[e]):ze(this,nl,lg).call(this,V(this,tr)[e],V(this,Ln)[e]),ze(this,nl,lg).call(this,V(this,hn),e),We(this,hn,e))};let ag=y_;const Ro=class Ro{constructor(){E(this,"_fallbackMethod",()=>Ro.createSkipProxy());E(this,"out",()=>{})}};E(Ro,"createSkipProxy",()=>{const e=new Ro;return new Proxy(e,{get(t,n,i){return typeof t[n]>"u"?t._fallbackMethod:t[n]},set(t,n,i,a){return!1}})});let qc=Ro;const No=class No extends C_{constructor(t,n){super(n);E(this,"_fallbackMethod",()=>No.createRestProxy(this.values.length,this.app));E(this,"out",()=>{});this.values.length=t}};E(No,"createRestProxy",(t,n)=>{const i=new No(t,n);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 Vc=No;class zG extends C_{constructor(t,n,i){super(i);E(this,"input");E(this,"ziffers");E(this,"initCallTime",0);E(this,"startCallTime",0);E(this,"lastCallTime",0);E(this,"waitTime",0);E(this,"startBeat",0);E(this,"played",!1);E(this,"current");E(this,"retro",!1);E(this,"index",-1);E(this,"zid","");E(this,"options",{});E(this,"skipIndex",0);E(this,"endTime",0);E(this,"next",()=>(this.current=this.ziffers.next(),this.played=!0,this.current));E(this,"pulseToSecond",t=>this.app.clock.convertPulseToSecond(t));E(this,"firstRun",()=>this.notStarted());E(this,"atTheBeginning",()=>this.skipIndex===0&&this.ziffers.index<=0);E(this,"origin",()=>this.app.clock.pulses_since_origin+1);E(this,"pulse",()=>this.app.clock.time_position.pulse);E(this,"beat",()=>this.app.clock.time_position.beat);E(this,"nextBeat",()=>this.app.clock.next_beat_in_ticks);E(this,"nextBeatInTicks",()=>this.app.clock.next_beat_in_ticks);E(this,"areWeThereYet",()=>{this.app.clock.pulses_since_origin=this.nextBeatInTicks())&&this.origin()>=this.waitTime,n=this.current&&this.pulseToSecond(this.origin())>=this.pulseToSecond(this.lastCallTime)+this.pulseToSecond(this.current.duration*4*this.app.clock.ppqn)&&this.origin()>=this.waitTime,i=t||n;return this.skipIndex=i?0:this.skipIndex+1,this.index=i?this.index+1:this.index,i&&this.notStarted()&&(this.initCallTime=this.app.clock.pulses_since_origin),this.atTheBeginning()&&(this.startCallTime=this.app.clock.pulses_since_origin),i});E(this,"lead",()=>this.voiceleading());E(this,"invert",t=>(this.atTheBeginning()&&this.ziffers.invert(t),this));E(this,"out",()=>{});this.app=i,this.input=t,this.options=n,this.ziffers=new $G(t,n)}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 n=this.next(),i=this.app.clock.convertPulseToSecond(n.duration*4*this.app.clock.ppqn);if(n instanceof ni){const a=n.getExisting("freq","pitch","key","scale","octave","parsedScale");return n.sound&&(t=n.sound),n.soundIndex&&(a.n=n.soundIndex),a.dur=i,new tg(a,this.app).sound(t||"sine")}else if(n instanceof Na){const a=n.pitches.map(o=>o.getExisting("freq","pitch","key","scale","octave","parsedScale")),s={dur:i};return t&&(s.s=t),new tg(s,this.app).chord(a)}else if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app)}else return qc.createSkipProxy()}midi(t=void 0){if(this.areWeThereYet()){const n=this.next(),i=n.getExisting("note","pitch","bend","key","scale","octave","parsedScale");if(n instanceof ni){n.soundIndex&&(i.channel=n.soundIndex);const a=new ng(i,this.app);return t?a.note(t):a}else{if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app);if(n instanceof Na){const a=n.midiChord();return new ng(i,this.app).chord(a)}}}else return qc.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}voiceleading(){return this.atTheBeginning()&&this.ziffers.lead(),this}retrograde(){return this.atTheBeginning()&&this.ziffers.retrograde(),this}wait(t){if(this.atTheBeginning()){if(typeof t=="function"){const n=this.app.api.patternCache.get(t.name);return n&&(this.waitTime=n.nextEndTime()),this}this.waitTime=this.origin()+Math.ceil(t*4*this.app.clock.ppqn)}return this}sync(t){if(this.atTheBeginning()&&this.notStarted()){const n=this.app.clock.pulses_since_origin,i=typeof t=="function"?t.name:t;if(n>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 HG=r=>r[0]==="{"&&r[r.length-1]==="}",fo=(r,e)=>{if(HG(r)){const t=JSON.parse(r);return JSON.stringify({...t,...e})}else return JSON.stringify({...e,text:r})},WG=r=>{String.prototype.speak=function(){const e=JSON.parse(this.valueOf());new OR({...e,text:e.text}).speak().then(()=>{}).catch(t=>{console.log("Error speaking:",t)})},String.prototype.rate=function(e){return fo(this.valueOf(),{rate:e})},String.prototype.pitch=function(e){return fo(this.valueOf(),{pitch:e})},String.prototype.lang=function(e){return fo(this.valueOf(),{lang:e})},String.prototype.volume=function(e){return fo(this.valueOf(),{volume:e})},String.prototype.voice=function(e){return fo(this.valueOf(),{voice:e})},String.prototype.z=function(e={}){return r.z(this.valueOf(),e)},String.prototype.z0=function(e={}){return r.z0(this.valueOf(),e)},String.prototype.z1=function(e={}){return r.z1(this.valueOf(),e)},String.prototype.z2=function(e={}){return r.z2(this.valueOf(),e)},String.prototype.z3=function(e={}){return r.z3(this.valueOf(),e)},String.prototype.z4=function(e={}){return r.z4(this.valueOf(),e)},String.prototype.z5=function(e={}){return r.z5(this.valueOf(),e)},String.prototype.z6=function(e={}){return r.z6(this.valueOf(),e)},String.prototype.z7=function(e={}){return r.z7(this.valueOf(),e)},String.prototype.z8=function(e={}){return r.z8(this.valueOf(),e)},String.prototype.z9=function(e={}){return r.z9(this.valueOf(),e)},String.prototype.z10=function(e={}){return r.z10(this.valueOf(),e)},String.prototype.z11=function(e={}){return r.z11(this.valueOf(),e)},String.prototype.z12=function(e={}){return r.z12(this.valueOf(),e)},String.prototype.z13=function(e={}){return r.z13(this.valueOf(),e)},String.prototype.z14=function(e={}){return r.z14(this.valueOf(),e)},String.prototype.z15=function(e={}){return r.z15(this.valueOf(),e)},String.prototype.z16=function(e={}){return r.z16(this.valueOf(),e)},String.prototype.note=function(){try{return parseInt(this.valueOf())}catch{return Ur(this.valueOf())}}};let qh;class OR{constructor(e){E(this,"speak",()=>new Promise((e,t)=>{if(this.options.text){const n=window.speechSynthesis;n.speaking&&n.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=n.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)},n.speaking?(n.cancel(),qh&&clearTimeout(qh),qh=setTimeout(()=>{n.speak(i)},200)):n.speak(i)}else t("No text provided")}));this.options=e}}async function bR(){return Promise.all([jR(),Yi("github:tidalcycles/Dirt-Samples/master").then(()=>h2()),O2(),Yi("github:Bubobubobubobubo/Dough-Fox/main"),Yi("github:Bubobubobubobubo/Dough-Samples/main"),Yi("github:Bubobubobubobubo/Dough-Amiga/main"),Yi("github:Bubobubobubobubo/Dough-Amen/main"),Yi("github:Bubobubobubobubo/Dough-Waveforms/main")])}class XG{constructor(e){E(this,"variables",{});E(this,"codeExamples",{});E(this,"counters",{});E(this,"_drunk",new qG(-100,100,!1));E(this,"randomGen",Math.random);E(this,"currentSeed");E(this,"localSeeds",new Map);E(this,"patternCache",new ag({max:1e3,ttl:1e3*60*5}));E(this,"errorTimeoutID",0);E(this,"printTimeoutID",0);E(this,"MidiConnection");E(this,"scale_aid");E(this,"load");E(this,"_loadUniverseFromInterface",e=>{Dc(this.app,e),xc()});E(this,"_deleteUniverseFromInterface",e=>{delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(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()});E(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=""),this.pause()});E(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,OM(this.app,e)});E(this,"_all_samples",()=>dg.get());E(this,"_reportError",e=>{console.log(e),clearTimeout(this.errorTimeoutID),clearTimeout(this.printTimeoutID),this.app.interface.error_line.innerHTML=e,this.app.interface.error_line.style.color="color-red-800",this.app.interface.error_line.classList.remove("hidden"),this.errorTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),2e3)});E(this,"_logMessage",e=>{console.log(e),clearTimeout(this.printTimeoutID),clearTimeout(this.errorTimeoutID),this.app.interface.error_line.innerHTML=e,this.app.interface.error_line.style.color="white",this.app.interface.error_line.classList.remove("hidden"),this.printTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),4e3)});E(this,"time",()=>this.app.audioContext.currentTime);E(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.MidiConnection.sendStartMessage(),this.app.clock.start()});E(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.MidiConnection.sendStopMessage(),this.app.clock.pause()});E(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.MidiConnection.sendStopMessage(),this.app.clock.stop()});E(this,"silence",this.stop);E(this,"hush",this.stop);E(this,"warp",e=>{this.app.clock.tick=e,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e)});E(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)});E(this,"onmousemove",e=>{this.app._mouseX=e.pageX,this.app._mouseY=e.pageY});E(this,"mouseX",()=>this.app._mouseX);E(this,"mouseY",()=>this.app._mouseY);E(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));E(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));E(this,"script",(...e)=>{e.forEach(t=>{t>=1&&t<=9&&(E2(this.app,"local",t),Ra(this.app,this.app.universes[this.app.selected_universe].locals[t]))})});E(this,"s",this.script);E(this,"delete_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});E(this,"cs",this.delete_script);E(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]={...this.app.universes[this.app.selected_universe].locals[e]}});E(this,"cps",this.copy_script);E(this,"copy_universe",(e,t)=>{this.app.universes[t]={...this.app.universes[e]}});E(this,"delete_universe",e=>{this.app.selected_universe===e&&(this.app.selected_universe="Default"),delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(this,"big_bang",()=>{confirm("Are you sure you want to delete all universes?")&&(this.app.universes={...Xo},this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings)),this.app.selected_universe="Default",this.app.updateKnownUniversesView()});E(this,"midi_outputs",()=>{this._logMessage(this.MidiConnection.listMidiOutputs())});E(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});E(this,"midi",(e=60,t,n)=>(t!==void 0&&(typeof e=="number"&&(e={note:e}),e.velocity=t),n!==void 0&&(typeof e=="number"&&(e={note:e}),e.channel=n),new ng(e,this.app)));E(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});E(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});E(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});E(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});E(this,"control_change",({control:e=20,value:t=0,channel:n=0})=>{this.MidiConnection.sendMidiControlChange(e,t,n)});E(this,"midi_panic",()=>{this.MidiConnection.panic()});E(this,"active_note_events",e=>{let t;if(e?t=this.MidiConnection.activeNotesFromChannel(e):t=this.MidiConnection.activeNotes,t.length>0)return t});E(this,"active_notes",e=>{const t=this.active_note_events(e);if(t&&t.length>0)return t.map(n=>n.note)});E(this,"kill_active_notes",()=>{this.MidiConnection.activeNotes=[]});E(this,"sticky_notes",e=>{let t;if(e?t=this.MidiConnection.stickyNotesFromChannel(e):t=this.MidiConnection.stickyNotes,t.length>0)return t.map(n=>n.note)});E(this,"kill_sticky_notes",()=>{this.MidiConnection.stickyNotes=[]});E(this,"buffer",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e)!==void 0:this.MidiConnection.noteInputBuffer.length>0);E(this,"buffer_event",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e):this.MidiConnection.noteInputBuffer.shift());E(this,"buffer_note",e=>{const t=this.buffer_event(e);return t?t.note:void 0});E(this,"last_note_event",e=>e?this.MidiConnection.lastNoteInChannel[e]:this.MidiConnection.lastNote);E(this,"last_note",e=>{const t=this.last_note_event(e);return t?t.note:60});E(this,"last_cc",(e,t)=>t?this.MidiConnection.lastCCInChannel[t]?this.MidiConnection.lastCCInChannel[t][e]:0:this.MidiConnection.lastCC[e]||0);E(this,"has_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e)!==void 0:this.MidiConnection.ccInputBuffer.length>0);E(this,"buffer_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e):this.MidiConnection.ccInputBuffer.shift());E(this,"show_scale",(e,t,n=0,i=this.MidiConnection.currentOutputIndex||0,a=!1)=>{(!this.scale_aid||t!==this.scale_aid)&&(this.hide_scale(e,t,n,i),NG(t,e).forEach(o=>{this.MidiConnection.sendMidiOn(o,n,1,i),a&&this.MidiConnection.sendAllSoundOff(n,i)}),this.scale_aid=t)});E(this,"hide_scale",(e=0,t=0,n=0,i=this.MidiConnection.currentOutputIndex||0)=>{Array.from(Array(128).keys()).forEach(s=>{this.MidiConnection.sendMidiOff(s,n,i)}),this.scale_aid=void 0});E(this,"midi_notes_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllNotesOff(e,t)});E(this,"midi_sound_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllSoundOff(e,t)});E(this,"generateCacheKey",(...e)=>e.map(t=>JSON.stringify(t)).join(","));E(this,"z",(e,t={},n="")=>{const i="z"+n.toString(),a=n===""?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 zG(e,t,this.app),this.app.api.patternCache.set(a,s)),typeof n=="number"&&(s.zid=i),s.updateLastCallTime(),n!==""&&s.sync("z0"),s});E(this,"z0",(e,t={})=>this.z(e,t,0));E(this,"z1",(e,t={})=>this.z(e,t,1));E(this,"z2",(e,t={})=>this.z(e,t,2));E(this,"z3",(e,t={})=>this.z(e,t,3));E(this,"z4",(e,t={})=>this.z(e,t,4));E(this,"z5",(e,t={})=>this.z(e,t,5));E(this,"z6",(e,t={})=>this.z(e,t,6));E(this,"z7",(e,t={})=>this.z(e,t,7));E(this,"z8",(e,t={})=>this.z(e,t,8));E(this,"z9",(e,t={})=>this.z(e,t,9));E(this,"z10",(e,t={})=>this.z(e,t,10));E(this,"z11",(e,t={})=>this.z(e,t,11));E(this,"z12",(e,t={})=>this.z(e,t,12));E(this,"z13",(e,t={})=>this.z(e,t,13));E(this,"z14",(e,t={})=>this.z(e,t,14));E(this,"z15",(e,t={})=>this.z(e,t,15));E(this,"z16",(e,t={})=>this.z(e,t,16));E(this,"counter",(e,t,n)=>(e in this.counters?(this.counters[e].limit!==t&&(this.counters[e].value=0,this.counters[e].limit=t),this.counters[e].step!==n&&(this.counters[e].step=n??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:n??1,limit:t},this.counters[e].value));E(this,"$",this.counter);E(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);E(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));E(this,"drunk_max",e=>{this._drunk.max=e});E(this,"drunk_min",e=>{this._drunk.min=e});E(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});E(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));E(this,"v",this.variable);E(this,"delete_variable",e=>{delete this.variables[e]});E(this,"dv",this.delete_variable);E(this,"clear_variables",()=>{this.variables={}});E(this,"cv",this.clear_variables);E(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);E(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);E(this,"irand",this.randI);E(this,"rI",this.randI);E(this,"r",this.rand);E(this,"ir",this.randI);E(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=jm(e))});E(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=jm(e);return this.localSeeds.set(e,t),t});E(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});E(this,"quantize",(e,t)=>{if(t.length===0)return e;let n=t[0];return t.forEach(i=>{Math.abs(i-e)Math.min(Math.max(e,t),n));E(this,"cmp",this.clamp);E(this,"nudge",e=>(e&&(this.app.clock.nudge=e),this.app.clock.nudge));E(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));E(this,"tempo",this.bpm);E(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));E(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));E(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});E(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);E(this,"odds",(e,t=1)=>this.randomGen()!1);E(this,"almostNever",(e=1)=>this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));E(this,"rarely",(e=1)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));E(this,"scarcely",(e=1)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));E(this,"sometimes",(e=1)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));E(this,"often",(e=1)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));E(this,"frequently",(e=1)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));E(this,"almostAlways",(e=1)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));E(this,"always",(e=1)=>!0);E(this,"dice",e=>Math.floor(this.randomGen()*e)+1);E(this,"cbar",()=>this.app.clock.time_position.bar+1);E(this,"ctick",()=>this.app.clock.tick+1);E(this,"cpulse",()=>this.app.clock.time_position.pulse+1);E(this,"cbeat",()=>this.app.clock.time_position.beat+1);E(this,"ebeat",()=>this.app.clock.beats_since_origin+1);E(this,"epulse",()=>this.app.clock.pulses_since_origin+1);E(this,"nominator",()=>this.app.clock.time_signature[0]);E(this,"meter",()=>this.app.clock.time_signature[1]);E(this,"denominator",this.meter);E(this,"fill",()=>this.app.fill);E(this,"fullseq",(e,t)=>e.split("").every(n=>n==="x"||n==="o")?[...e].map(n=>n==="x").beat(t):!1);E(this,"seq",(e,t=.5)=>{let n=e.length*t,i=[];for(let a=1;a<=n+1;a+=t)i.push(Math.floor(a*10)/10);return i.pop(),i=i.filter((a,s)=>{const o=s%e.length;return e[o]==="x"}),this.oncount(i,n)});E(this,"beat",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-Math.floor(t*this.ppqn()))%Math.floor(a*this.ppqn())===0).some(a=>a===!0));E(this,"b",this.beat);E(this,"bar",(e=1,t=0)=>{const n=Array.isArray(e)?e:[e],i=this.app.clock.time_signature[1]*this.ppqn(),a=Math.floor(t*i);return n.map(o=>(this.app.clock.pulses_since_origin-a)%Math.floor(o*i)===0).some(o=>o===!0)});E(this,"B",this.bar);E(this,"pulse",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-t)%a===0).some(a=>a===!0));E(this,"p",this.pulse);E(this,"tick",(e,t=0)=>(Array.isArray(e)?e:[e]).map(a=>this.app.clock.time_position.pulse===a+t).some(a=>a===!0));E(this,"flip",(e,t=50)=>{let n=e*2;const i=this.app.clock.pulses_since_origin,a=Math.floor(n*this.ppqn()),s=Math.floor(t/100*a);return i%a{let t=e*2;const n=this.app.clock.time_position.bar;return Math.floor(n/t)%2===0});E(this,"onbar",(e,t=this.app.clock.time_signature[0])=>{let n=this.app.clock.time_position.bar%t+1;return typeof e=="number"?e===n:e.some(i=>i==n)});E(this,"onbeat",(...e)=>{let t=[];return e.forEach(n=>{let i=n%this.nominator()||this.nominator(),a=Math.floor(i);a=a==0?this.nominator():a;let s=Math.floor((i-a)*this.ppqn()+1);s<=0&&(s=s+this.ppqn()*this.nominator()),t.push(a===this.cbeat()&&this.cpulse()===s)}),t.some(n=>n==!0)});E(this,"oncount",(e,t)=>{typeof e=="number"&&(e=[e]);const n=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=n%(this.ppqn()*t);return i.push(o===s)}),i.some(a=>a==!0)});E(this,"oneuclid",(e,t,n=0)=>{const a=this._euclidean_cycle(e,t,n).reduce((s,o,l)=>(o&&s.push(l+1),s),[]);return this.oncount(a,t)});E(this,"delay",(e,t)=>{setTimeout(t,e)});E(this,"delayr",(e,t,n)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(n,a)})});E(this,"euclid",(e,t,n,i=0)=>this._euclidean_cycle(t,n,i)[e%n]);E(this,"ec",this.euclid);E(this,"rhythm",(e,t,n,i=0)=>this.beat(e)&&this._euclidean_cycle(t,n,i).beat(e));E(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});E(this,"binrhythm",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return this.beat(e)&&i.beat(e)});E(this,"line",(e,t,n=1)=>{const i=[];if(t>e&&n>0||t(Math.sin(this.app.clock.ctx.currentTime*Math.PI*2*e)+n)*t);E(this,"usine",(e=1,t=1,n=0)=>(this.sine(e,t,n)+1)/2*t);E(this,"saw",(e=1,t=1,n=0)=>(this.app.clock.ctx.currentTime*e%1*2-1+n)*t);E(this,"usaw",(e=1,t=1,n=0)=>(this.saw(e,t,n)+1)/2*t);E(this,"triangle",(e=1,t=1,n=0)=>(Math.abs(this.saw(e,t,n))*2-1)*t);E(this,"utriangle",(e=1,t=1,n=0)=>(this.triangle(e,t,n)+1)/2*t);E(this,"square",(e=1,t=1,n=0,i=.5)=>{const a=1/e;return((Date.now()/1e3+n)%a/a(this.square(e,t,n,i)+1)/2*t);E(this,"noise",(e=1)=>(this.randomGen()*2-1)*e);E(this,"min",(...e)=>Math.min(...e));E(this,"max",(...e)=>Math.max(...e));E(this,"mean",(...e)=>e.reduce((n,i)=>n+i,0)/e.length);E(this,"range",(e,t,n,i,a)=>(e-t)/(n-t)*(a-i)+i);E(this,"limit",(e,t,n)=>Math.min(Math.max(e,t),n));E(this,"abs",Math.abs);E(this,"speak",(e,t="en-US",n=0,i=1,a=1)=>{new OR({text:e,lang:t,voice:n,rate:i,pitch:a}).speak().then(()=>{}).catch(o=>{console.log(o)})});E(this,"stop_hydra",()=>{this.app.hydra.hush()});E(this,"sound",e=>new tg(e,this.app));E(this,"snd",this.sound);E(this,"samples",Yi);E(this,"log",e=>{console.log(e),this._logMessage(e)});E(this,"scale",T_);E(this,"rate",e=>{});E(this,"divseq",(...e)=>{const t=e[0],n=e.slice(1),i=this.app.clock.pulses_since_origin,a=Math.floor(i/Math.floor(t*this.ppqn()));return n[a%n.length]});E(this,"seqbeat",(...e)=>e[this.app.clock.time_position.beat%e.length]);E(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);E(this,"shuffle",e=>e.sort(()=>this.randomGen()-.5));E(this,"reverse",e=>e.reverse());E(this,"rotate",e=>t=>t.slice(e,t.length).concat(t.slice(0,e)));E(this,"repeat",e=>t=>t.flatMap(n=>Array(e).fill(n)));E(this,"repeatOdd",e=>t=>t.flatMap((n,i)=>i%2===0?Array(e).fill(n):n));E(this,"repeatEven",e=>t=>t.flatMap((n,i)=>i%2!==0?Array(e).fill(n):n));E(this,"palindrome",e=>e.concat(e.slice(0,e.length-1).reverse()));E(this,"scope",e=>{this.app.osc={...this.app.osc,...e}});this.app=e,this.MidiConnection=new QG(this,e.settings)}transmission(){return this.MidiConnection.activeNotes.length>0}_euclidean_cycle(e,t,n=0){if(e==t)return Array.from({length:t},()=>!0);function i(o,l){const c=o.length,u=(l+1)%c;return o[l]>o[u]}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 n!=0&&(s=s.slice(n).concat(s.slice(0,n))),s}}const ZG=r=>{Array.prototype.mouseX=function(){const e=r.mouseX(),n=window.innerWidth/this.length,i=Math.floor(e/n);return this[i]},Array.prototype.mouseY=function(){const e=r.mouseY(),n=window.innerHeight/this.length,i=Math.floor(e/n);return this[i]},Array.prototype.square=function(){return this.map(e=>e*e)},Array.prototype.sometimes=function(e){return r.randomGen()<.5?e(this):this},Array.prototype.apply=function(e){return e(this)},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.div=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(r.randomGen()*this.length)]},Array.prototype.gen=function(e,t,n){return n<1?[]:Array.from({length:n},()=>Math.floor(r.randomGen()*(t-e+1))+e)},Array.prototype.bar=function(e=1){return e===1?this[r.app.clock.time_position.bar%this.length]:this[Math.floor(r.app.clock.time_position.bar/e)%this.length]},Array.prototype.beat=function(e=1){const t=e,n=r.app.clock.pulses_since_origin,i=Math.floor(n/Math.floor(t*r.ppqn()));return this[i%this.length]},Array.prototype.b=Array.prototype.beat,Array.prototype.shuffle=function(){let e=this.length,t;for(;e!==0;)t=Math.floor(r.randomGen()*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 n=this.splice(-e,e);return this.unshift(...n),this},Array.prototype.unique=function(){const e=new Set;let t=0;for(let n=0;n100)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.repeat=function(e=1){if(e<1)throw new Error("Amount should be at least 1");let t=[];for(let n=0;n(i%a+a)%a,n=cR(Ds(r));return this.map(i=>{const a=Math.floor(i/n.length)*12;return n[t(i,n.length)]+e+a})};Array.prototype.scaleArp=function(r="major",e=0){const t=cR(Ds(r));let n=[];e=e>t.length?t.length:e,e=e==0?t.length:e;for(let i=0;i{r.interface.line_numbers_checkbox.checked=r.settings.line_numbers,r.interface.time_position_checkbox.checked=r.settings.time_position,r.interface.tips_checkbox.checked=r.settings.tips,r.interface.midi_clock_checkbox.checked=r.settings.send_clock,r.interface.midi_channels_scripts.checked=r.settings.midi_channels_scripts,r.interface.midi_clock_ppqn.value=r.settings.midi_clock_ppqn.toString(),r.settings.time_position||r.interface.timeviewer.classList.add("hidden"),r.interface.load_demo_songs.checked=r.settings.load_demo_songs;const e=document.querySelectorAll('[id^="tab-"]');for(let t=0;t{e[t].classList.add("bg-orange-300");for(let s=0;s{hi(),r.updateKnownUniversesView(),xc()}),r.buttonElements.play_buttons.forEach(t=>{t.addEventListener("click",()=>{r.isPlaying?(r.setButtonHighlighting("pause",!0),r.isPlaying=!r.isPlaying,r.clock.pause(),r.api.MidiConnection.sendStopMessage()):(r.setButtonHighlighting("play",!0),r.isPlaying=!r.isPlaying,r.clock.start(),r.api.MidiConnection.sendStartMessage())})}),r.buttonElements.clear_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("clear",!0),confirm("Do you want to reset the current universe?")&&(r.universes[r.selected_universe]=structuredClone(t_),r.updateEditorView())})}),r.interface.documentation_button.addEventListener("click",()=>{XI(r)}),r.interface.destroy_universes_button.addEventListener("click",()=>{confirm("Do you want to destroy all universes?")&&(r.universes={...Xo},r.updateKnownUniversesView())}),r.interface.audio_nudge_range.addEventListener("input",()=>{r.clock.nudge=parseInt(r.interface.audio_nudge_range.value)}),r.interface.dough_nudge_range.addEventListener("input",()=>{r.dough_nudge=parseInt(r.interface.dough_nudge_range.value)}),r.interface.upload_universe_button.addEventListener("click",()=>{const t=document.createElement("input");t.type="file",t.accept=".json",t.addEventListener("change",n=>{var s;const a=(s=n.target.files)==null?void 0:s[0];if(a){const o=new FileReader;o.readAsText(a,"UTF-8"),o.onload=l=>{const c=JSON.parse(l.target.result);for(const[u,p]of Object.entries(c))r.universes[u]=p},o.onerror=l=>{console.error("An error occurred reading the file:",l)}}}),document.body.appendChild(t),t.click(),document.body.removeChild(t)}),r.interface.download_universe_button.addEventListener("click",()=>{r.settings.saveApplicationToLocalStorage(r.universes,r.settings);let t=`topos-universes-${Date.now()}.json`;const n=new Blob([JSON.stringify(r.settings.universes)],{type:"application/json"}),i=URL.createObjectURL(n),a=document.createElement("a");a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}),r.interface.load_universe_button.addEventListener("click",()=>{let t=r.interface.buffer_search.value;t.length>2&&t.length<20&&!t.includes(" ")&&(Dc(r,t),r.settings.selected_universe=t,r.interface.buffer_search.value="",Vm(),r.view.focus(),FA())}),r.interface.eval_button.addEventListener("click",()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.flashBackground("#404040",200)}),r.buttonElements.stop_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("stop",!0),r.isPlaying=!1,r.clock.stop()})}),r.interface.local_button.addEventListener("click",()=>r.changeModeFromInterface("local")),r.interface.global_button.addEventListener("click",()=>r.changeModeFromInterface("global")),r.interface.init_button.addEventListener("click",()=>r.changeModeFromInterface("init")),r.interface.note_button.addEventListener("click",()=>r.changeModeFromInterface("notes")),r.interface.font_family_selector.addEventListener("change",()=>{let t=r.interface.font_family_selector.value;console.log("Picking new font : "+t),r.settings.font=t,r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:t,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.font_size_input.addEventListener("input",()=>{let t=r.interface.font_size_input.value;r.settings.font_size=parseInt(t),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.settings_button.addEventListener("click",()=>{const t=document.getElementById("font-family");t&&(t.value=r.settings.font);const n=r.interface.dough_nudge_range;n.value=r.dough_nudge.toString();const i=document.getElementById("doughnumber");i.value=r.dough_nudge.toString(),r.settings.font_size===null&&(r.settings.font_size=12);const a=r.interface.font_size_input;a.value=r.settings.font_size.toString();const s=r.interface.line_numbers_checkbox;s.checked=r.settings.line_numbers;const o=r.interface.time_position_checkbox;o.checked=r.settings.time_position;const l=r.interface.tips_checkbox;l.checked=r.settings.tips;const c=r.interface.midi_clock_checkbox;c.checked=r.settings.send_clock;const u=r.interface.midi_channels_scripts;u.checked=r.settings.midi_channels_scripts;const p=r.interface.midi_clock_ppqn;p.value=r.settings.midi_clock_ppqn.toString();const m=r.interface.load_demo_songs;m.checked=r.settings.load_demo_songs;const _=r.interface.vim_mode_checkbox;_.checked=r.settings.vimMode;let v=document.getElementById("modal-settings"),I=document.getElementById("editor");v==null||v.classList.remove("invisible"),I==null||I.classList.add("invisible")}),r.interface.close_settings_button.addEventListener("click",()=>{let t=document.getElementById("modal-settings"),n=document.getElementById("editor");t==null||t.classList.add("invisible"),n==null||n.classList.remove("invisible");let i=r.interface.font_size_input.value;r.settings.font_size=parseInt(i),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.close_universes_button.addEventListener("click",()=>{xc()}),r.interface.share_button.addEventListener("click",async()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),await vM(r)}),r.interface.vim_mode_checkbox.addEventListener("change",()=>{let t=!!r.interface.vim_mode_checkbox.checked;r.settings.vimMode=t,r.view.dispatch({effects:r.vimModeCompartment.reconfigure(t?f_():[])})}),r.interface.line_numbers_checkbox.addEventListener("change",()=>{let n=!!r.interface.line_numbers_checkbox.checked;r.settings.line_numbers=n,r.view.dispatch({effects:r.withLineNumbers.reconfigure(n?[ey()]:[])})}),r.interface.time_position_checkbox.addEventListener("change",()=>{let t=document.getElementById("timeviewer"),n=!!r.interface.time_position_checkbox.checked;r.settings.time_position=n,n?t.classList.remove("hidden"):t.classList.add("hidden")}),r.interface.tips_checkbox.addEventListener("change",()=>{let t=!!r.interface.tips_checkbox.checked;r.settings.tips=t,r.view.dispatch({effects:r.hoveringCompartment.reconfigure(t?rR:[])})}),r.interface.midi_clock_checkbox.addEventListener("change",()=>{let t=!!r.interface.midi_clock_checkbox.checked;r.settings.send_clock=t}),r.interface.midi_channels_scripts.addEventListener("change",()=>{let t=!!r.interface.midi_channels_scripts.checked;r.settings.midi_channels_scripts=t}),r.interface.midi_clock_ppqn.addEventListener("change",()=>{let t=parseInt(r.interface.midi_clock_ppqn.value);r.settings.midi_clock_ppqn=t}),r.interface.load_demo_songs.addEventListener("change",()=>{let t=!!r.interface.load_demo_songs.checked;r.settings.load_demo_songs=t}),r.interface.universe_creator.addEventListener("submit",t=>{t.preventDefault();let i=new FormData(r.interface.universe_creator).get("universe");i&&i.length>2&&i.length<20&&(Dc(r,i),r.settings.selected_universe=i,r.interface.buffer_search.value="",Vm(),r.view.focus())}),Ra(r,r.universes[r.selected_universe.toString()].init),["introduction","interface","interaction","code","time","sound","samples","synths","chaining","patterns","ziffers","midi","functions","lfos","probabilities","variables","shortcuts","about","bonus","oscilloscope"].forEach(t=>{let n="docs_"+t;document.getElementById(n).addEventListener("click",async()=>{n!=="docs_samples"?(r.currentDocumentationPane=t,Km(r)):(console.log("Loading samples!"),await bR().then(()=>{r.docs=WI(r),r.currentDocumentationPane=t,Km(r)}))})})},ST=r=>{if(!r)return;r.width=window.innerWidth,r.height=window.innerHeight;const e=r.getContext("2d"),t=window.devicePixelRatio||1;r.width=window.innerWidth*t,r.height=window.innerHeight*t,e&&e.scale(t,t)},jG=(r,e,t=!1)=>{e.addEventListener("resize",()=>ST(r.interface.scope)),e.addEventListener("resize",()=>ST(r.interface.feedback)),e.addEventListener("beforeunload",()=>(event.preventDefault(),r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),r.clock.stop(),null)),t&&(localStorage.openpages=Date.now(),e.addEventListener("storage",function(n){n.key=="openpages"&&(localStorage.page_available=Date.now()),n.key=="page_available"&&(document.getElementById("all").classList.add("invisible"),alert("Topos is already opened in another tab. Close this tab now to prevent data loss."))},!1))};class JG{constructor(){E(this,"settings",new bM);E(this,"universes",Xo);E(this,"selected_universe","Welcome");E(this,"fill",!1);E(this,"local_index",1);E(this,"editor_mode","global");E(this,"fontSize");E(this,"withLineNumbers");E(this,"vimModeCompartment");E(this,"hoveringCompartment");E(this,"chosenLanguage");E(this,"dynamicPlugins");E(this,"currentDocumentationPane","introduction");E(this,"exampleCounter",0);E(this,"exampleIsPlaying",!1);E(this,"editorExtensions",[]);E(this,"userPlugins",[]);E(this,"state");E(this,"view");E(this,"selectedExample","");E(this,"docs",{});E(this,"_mouseX",0);E(this,"_mouseY",0);E(this,"show_error",!1);E(this,"buttonElements",{});E(this,"interface",{});E(this,"blinkTimeouts",{});E(this,"osc",{enabled:!1,color:"#fdba74",thickness:4,refresh:1,fftSize:256,orientation:"horizontal",is3D:!1,size:1});E(this,"api");E(this,"audioContext");E(this,"clock");E(this,"dough_nudge",20);E(this,"manualPlay",!1);E(this,"isPlaying",!1);E(this,"hydra_backend");E(this,"hydra");E(this,"updateKnownUniversesView",()=>{let e=document.getElementById("ui-known-universe-item-template");if(!e){console.warn("Missing template #ui-known-universe-item-template");return}let t=document.getElementById("existing-universes");if(!t){console.warn("Missing element #existing-universes");return}let n=document.createElement("ul");n.className="lg:h-80 lg:text-normal text-sm h-auto lg:w-80 w-auto lg:pb-2 lg:pt-2 overflow-y-scroll text-white lg:mb-4 border rounded-lg bg-neutral-800",n.append(...Object.keys(this.universes).map(i=>{var o,l;let a=e.content.cloneNode(!0),s=window;return a.querySelector(".universe-name").textContent=i,(o=a.querySelector(".load-universe"))==null||o.addEventListener("click",()=>s._loadUniverseFromInterface(i)),(l=a.querySelector(".delete-universe"))==null||l.addEventListener("click",()=>s._deleteUniverseFromInterface(i)),a})),t.innerHTML="",t.append(n)});this.initializeElements(),this.initializeButtonGroups(),this.initializeHydra(),this.setCanvas(this.interface.feedback),this.setCanvas(this.interface.scope),this.universes={...this.settings.universes,...Xo},EM(this),this.audioContext=new AudioContext({latencyHint:"playback"}),this.clock=new j$(this,this.audioContext),this.api=new XG(this),ZG(this.api),WG(this.api),Object.entries(this.api).forEach(([t,n])=>{globalThis[t]=n}),(async()=>{await bR()})(),this.docs=WI(this),T$(this),C$(this),KG(this),TT(this),X$(this),v2(this.interface.scope,this),Ra(this,this.universes[this.selected_universe.toString()].init),this.changeModeFromInterface("global"),TM(this)}getBuffer(e){const t=this.universes[this.selected_universe.toString()];return e==="locals"?t[e][this.local_index]:t[e]}get note_buffer(){return this.getBuffer("notes")}get example_buffer(){return this.getBuffer("example")}get global_buffer(){return this.getBuffer("global")}get init_buffer(){return this.getBuffer("init")}get local_buffer(){return this.getBuffer("locals")}changeToLocalBuffer(e){const t=document.querySelectorAll('[id^="tab-"]'),n=t[e];n.classList.add("bg-orange-300");for(let a=0;a{t.forEach(a=>{let s=a.children[0];s.classList.contains("text-orange-300")&&(s.classList.remove("text-orange-300"),a.classList.remove("text-orange-300"))}),i.children[0].classList.remove("text-white"),i.children[0].classList.add("text-orange-300"),i.classList.add("text-orange-300"),i.classList.add("fill-orange-300")};switch(e){case"local":this.interface.local_script_tabs.classList.contains("hidden")&&this.interface.local_script_tabs.classList.remove("hidden"),this.editor_mode="local",this.local_index=0,document.getElementById("editor").style.height="calc(100% - 100px)",this.changeToLocalBuffer(this.local_index),n(this.interface.local_button);break;case"global":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="global",document.getElementById("editor").style.height="100%",n(this.interface.global_button);break;case"init":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="init",n(this.interface.init_button);break;case"notes":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="notes",n(this.interface.note_button);break}this.view.dispatch({effects:this.chosenLanguage.reconfigure(this.editor_mode=="notes"?[BL()]:[Gg()])}),this.updateEditorView()}setButtonHighlighting(e,t){document.getElementById("play-label").textContent=e!=="pause"?"Pause":"Play",e!=="pause"?(document.getElementById("pause-icon").classList.remove("hidden"),document.getElementById("play-icon").classList.add("hidden")):(document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),e==="stop"&&(this.isPlaying==!1,document.getElementById("play-label").textContent="Play",document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),this.flashBackground("#404040",200);const n=['[id^="play-button-"]','[id^="clear-button-"]','[id^="stop-button-"]'];let i;switch(e){case"play":i=0;break;case"pause":i=1;break;case"clear":i=2;break;case"stop":i=3;break}document.querySelectorAll(n[i]).forEach(a=>{t&&a.children[0].classList.add("animate-pulse")}),document.querySelectorAll(n.filter((a,s)=>s!=i).join(",")).forEach(a=>{a.children[0].classList.remove("animate-pulse"),a.children[1].classList.remove("animate-pulse")})}unfocusPlayButtons(){document.querySelectorAll('[id^="play-button-"]').forEach(e=>{e.children[0].classList.remove("fill-orange-300"),e.children[0].classList.remove("animate-pulse")})}updateEditorView(){this.view.dispatch({changes:{from:0,to:this.view.state.doc.toString().length,insert:this.currentFile().candidate}})}currentFile(){switch(this.editor_mode){case"global":return this.global_buffer;case"local":return this.local_buffer;case"init":return this.init_buffer;case"notes":return this.note_buffer}}flashBackground(e,t){const n=this.view.dom,i=n.getElementsByClassName("cm-gutter");n.classList.add("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.add("fluid-bg-transition")),n.style.backgroundColor=e,Array.from(i).forEach(a=>a.style.backgroundColor=e),setTimeout(()=>{n.style.backgroundColor="",Array.from(i).forEach(a=>a.style.backgroundColor=""),n.classList.remove("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.remove("fluid-bg-transition"))},t)}initializeElements(){for(const[e,t]of Object.entries(AM))this.interface[e]=document.getElementById(t)}initializeButtonGroups(){for(const[e,t]of Object.entries(IM))this.buttonElements[e]=t.map(n=>document.getElementById(n))}initializeHydra(){this.hydra_backend=new Hydra({canvas:this.interface.hydra_canvas,detectAudio:!1,enableStreamCapture:!1}),this.hydra=this.hydra_backend.synth}setCanvas(e){if(!e)return;const t=e.getContext("2d"),n=window.devicePixelRatio||1;e.width=window.innerWidth*n,e.height=window.innerHeight*n,t&&t.scale(n,n)}}let e5=new JG;jG(e5,window,!1); +`,"\r"," "],!1,!1),an=st(",",!1),H=st("|",!1),fe=Kn([["a","z"]],!1,!1),Ie=Kn([["a","z"],"_"],!1,!1),we=Kn([["a","z"],"_",["0","9"]],!1,!1),Je=st("<",!1),ye=st(">",!1),Ht=st("@",!1),lt=st(":",!1),yt=Kn(["m","k","l","p","d","c","w","y","h","n","q","a","e","f","s","x","t","g","u","j","z","o"],!1,!1),zn=st("/",!1),dt=st("(",!1),Kt=st(")",!1),Tt=st("[:",!1),Ue=st("]",!1),Fn=st("[",!1),Fr=st("{",!1),ct=st("}",!1),Hn=st("+",!1),Nn=st("*",!1),Ii=st("%",!1),wn=st("^",!1),Wt=st("&",!1),Cr=st(">>",!1),ta=st("<<",!1),oi=st("_",!1),na=st("?",!1),cr=st("!",!1),li=st("r",!1),yr=Kn([["a","z"],["A","Z"],["0","9"]],!1,!1),jt=st("#",!1),ci=st("b",!1),ui=Kn([["a","z"],["A","Z"],["0","9"],"-","*","+"],!1,!1),q=Kn([["A","G"]],!1,!1),ie=Kn(["b","s"],!1,!1),de=st("iii",!1),_e=st("ii",!1),Ae=st("iv",!1),Qe=st("i",!1),Pe=st("vii",!1),Ct=st("vi",!1),Dn=st("v",!1),Wn=function(T){return T.filter(w=>w)},xa=function(){return parseFloat($n())},ra=function(){return parseInt($n())},xs=function(){return parseInt($n())},Xn=function(){},ks=function(T){return Ut(pG,{sound:T})},ka=function(){return $n()},La=function(T){return Ut(Io,{items:T})},Ls=function(T){return T},Ma=function(T,w){return Ut(fG,{item:T,sound:w})},Ms=function(T,w){return Ut(hG,{item:T,soundIndex:w})},Pa=function(T){return T},Yn=function(){return tG[$n()]},Ps=function(T,w){return T/w},Bs=function(T){return T.filter(w=>w)},Ba=function(T){return Ut(Io,{items:T})},Ua=function(T,w){return w?Ut(mT,{item:T,times:w}):Ut(gT,{items:T})},Us=function(T){return T},Fa=function(T,w,P){return Ut(OG,{left:T,operation:w,right:P})},Fs=function(T,w){return Ut(SG,{items:T,times:w})},Ya=function(T){return Ut(sR,{items:T})},Ys=function(T){return T.map(w=>typeof w=="number"?w:void 0)},$s=function(){return Math.ceil(iR($n()))},ur=function(T){var w=T.filter(P=>P).map(P=>Ut(ni,{pitch:P[0]},P.toString()));return Ut(gT,{items:w})},Ot=function(T){return T},Gs=function(T){return T},Ri=function(){},Qs=function(T){return Ut(Io,{items:T})},di=function(T){return Ut(gG,{octave:T})},qs=function(){return $n().split("").reduce((T,w)=>T+(w==="^"?1:-1),0)},Ni=function(){return Ut(Gc,{seededRandom:a.seededRandom})},$a=function(T,w){return Ut(Gc,{min:T,max:w,seededRandom:a.seededRandom})},Ga=function(T,w){return Ut(mT,{item:T,times:w})},Vs=function(T){return Ut(_G,{duration:T})},wi=function(T){return T},Qa=function(T){return Ut(Jm,{duration:T})},Di=function(T,w,P,X){const oe=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(ni,{duration:w,pitch:X,pitchOctave:oe,add:P})},xi=function(T){return T.reduce((w,P)=>w+(P==="#"?1:-1),0)},qa=function(T,w,P){return Ut(Na,{pitches:[T].concat(w),inversion:P})},ia=function(){return $n()},pi=function(T){return T},_n=function(){return $n()},Va=function(T,w,P,X,oe){const ve=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",ft=a.nodeOptions.key?a.nodeOptions.key:"C",fr=RG(X,P,ve,T,w),Ks=w||a.nodeOptions.duration,DR=T?a.nodeOptions.octave+T:a.nodeOptions.octave;return Ut(Na,{duration:Ks,chordOctave:DR,pitches:fr,chordName:X,inversion:oe,scaleName:ve,key:ft})},Zn=function(T,w,P){const X=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",oe=a.nodeOptions.key?a.nodeOptions.key:"C";return Ut(mG,{roman:T,chordName:w,inversion:P,scaleName:X,key:oe})},aa=function(T){const w=a.nodeOptions.scaleName?a.nodeOptions.scaleName:"MAJOR",P=a.nodeOptions.key?a.nodeOptions.key:"C",X=BG(T,P,w);return Ut(ni,{pitch:X.pc,add:X.add,scaleName:w,key:P})},A=0,He=0,za=[{line:1,column:1}],dr=0,zs=[],Oe=0,ge={},sa;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 $n(){return i.substring(He,A)}function dl(){return d(He,A)}function st(T,w){return{type:"literal",text:T,ignoreCase:w}}function Kn(T,w,P){return{type:"class",parts:T,inverted:w,ignoreCase:P}}function pl(){return{type:"end"}}function Hs(T){return{type:"other",description:T}}function fl(T){var w=za[T],P;if(w)return w;for(P=T-1;!za[P];)P--;for(w=za[P],w={line:w.line,column:w.column};Pdr&&(dr=A,zs=[]),zs.push(T))}function g(T,w,P){return new e(e.buildMessage(T,w),T,w,P)}function O(){var T,w,P=A*56+0,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Xt(),w!==s&&(He=T,w=Wn(w)),T=w,ge[P]={nextPos:A,result:T},T)}function C(){var T,w,P,X,oe,ve,ft,fr=A*56+1,Ks=ge[fr];if(Ks)return A=Ks.nextPos,Ks.result;for(T=A,w=A,i.charCodeAt(A)===45?(P=u,A++):(P=s,Oe===0&&f(rn)),P===s&&(P=null),X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));if(i.charCodeAt(A)===46?(oe=p,A++):(oe=s,Oe===0&&f(ke)),oe!==s){if(ve=[],Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze)),ft!==s)for(;ft!==s;)ve.push(ft),Be.test(i.charAt(A))?(ft=i.charAt(A),A++):(ft=s,Oe===0&&f(Ze));else ve=s;ve!==s?(P=[P,X,oe,ve],w=P):(A=w,w=s)}else A=w,w=s;if(w===s)if(w=A,i.charCodeAt(A)===46?(P=p,A++):(P=s,Oe===0&&f(ke)),P!==s){if(X=[],Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze)),oe!==s)for(;oe!==s;)X.push(oe),Be.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(Ze));else X=s;X!==s?(P=[P,X],w=P):(A=w,w=s)}else A=w,w=s;return w!==s&&(He=T,w=xa()),T=w,ge[fr]={nextPos:A,result:T},T}function y(){var T,w,P=A*56+2,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),Be.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Ze)),w!==s?(He=T,T=ra()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function D(){var T,w,P,X=A*56+3,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,i.charCodeAt(A)===45?A++:Oe===0&&f(rn),w=[],Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze)),P!==s)for(;P!==s;)w.push(P),Be.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(Ze));else w=s;return w!==s?(He=T,T=xs()):(A=T,T=s),ge[X]={nextPos:A,result:T},T}function F(){var T,w,P=A*56+4,X=ge[P];return X?(A=X.nextPos,X.result):(Oe++,T=A,tt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(Zt)),w!==s&&(He=T,w=Xn()),T=w,Oe--,T===s&&(w=s,Oe===0&&f(en)),ge[P]={nextPos:A,result:T},T)}function U(){var T,w,P=A*56+8,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=W(),w!==s&&(He=T,w=ks(w)),T=w,ge[P]={nextPos:A,result:T},T)}function W(){var T,w,P,X,oe,ve=A*56+10,ft=ge[ve];if(ft)return A=ft.nextPos,ft.result;if(T=A,rt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(fe)),w!==s){if(P=[],ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie)),X!==s)for(;X!==s;)P.push(X),ht.test(i.charAt(A))?(X=i.charAt(A),A++):(X=s,Oe===0&&f(Ie));else P=s;if(P!==s){for(X=[],vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));oe!==s;)X.push(oe),vt.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(we));He=T,T=ka()}else A=T,T=s}else A=T,T=s;return ge[ve]={nextPos:A,result:T},T}function z(){var T,w=A*56+11,P=ge[w];return P?(A=P.nextPos,P.result):(T=pe(),T===s&&(T=he()),ge[w]={nextPos:A,result:T},T)}function pe(){var T,w,P,X,oe=A*56+12,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=z(),X!==s)for(;X!==s;)P.push(X),X=z();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=La(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function he(){var T,w=A*56+13,P=ge[w];return P?(A=P.nextPos,P.result):(T=W(),T===s&&(T=pe(),T===s&&(T=F())),ge[w]={nextPos:A,result:T},T)}function se(){var T,w,P,X=A*56+14,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===64?(w=R,A++):(w=s,Oe===0&&f(Ht)),w!==s?(P=z(),P!==s?(He=T,T=Ls(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function ae(){var T,w=A*56+15,P=ge[w];return P?(A=P.nextPos,P.result):(T=sn(),T===s&&(T=it(),T===s&&(T=qt(),T===s&&(T=du(),T===s&&(T=Qt())))),ge[w]={nextPos:A,result:T},T)}function Ce(){var T,w,P,X=A*56+16,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=ae(),w===s&&(w=Zs()),w!==s?(P=se(),P!==s?(He=T,T=Ma(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Se(){var T,w,P,X=A*56+17,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs())),w!==s?(P=Ve(),P!==s?(He=T,T=Ms(w,P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function Ve(){var T,w,P,X=A*56+18,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=wt(),P!==s?(He=T,T=Pa(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function je(){var T,w,P=A*56+19,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,mt.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(yt)),w!==s&&(He=T,w=Yn()),T=w,ge[P]={nextPos:A,result:T},T)}function Fe(){var T,w=A*56+20,P=ge[w];return P?(A=P.nextPos,P.result):(T=It(),T===s&&(T=C(),T===s&&(T=je())),ge[w]={nextPos:A,result:T},T)}function It(){var T,w,P,X,oe=A*56+21,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=D(),w!==s?(i.charCodeAt(A)===47?(P=$,A++):(P=s,Oe===0&&f(zn)),P!==s?(X=D(),X!==s?(He=T,T=Ps(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xt(){var T,w,P,X=A*56+22,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du())))))))),P!==s)for(;P!==s;)w.push(P),P=N_(),P===s&&(P=Se(),P===s&&(P=Ce(),P===s&&(P=sn(),P===s&&(P=qt(),P===s&&(P=it(),P===s&&(P=Qt(),P===s&&(P=Zs(),P===s&&(P=du()))))))));else w=s;return w!==s&&(He=T,w=Bs(w)),T=w,ge[X]={nextPos:A,result:T},T}function wt(){var T,w=A*56+23,P=ge[w];return P?(A=P.nextPos,P.result):(T=F(),T===s&&(T=D(),T===s&&(T=R_(),T===s&&(T=fu(),T===s&&(T=tn(),T===s&&(T=A_()))))),ge[w]={nextPos:A,result:T},T)}function tn(){var T,w,P,X,oe=A*56+24,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s){if(P=[],X=wt(),X!==s)for(;X!==s;)P.push(X),X=wt();else P=s;P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Ba(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function it(){var T,w,P,X,oe,ve=A*56+25,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(i.charCodeAt(A)===58?A++:Oe===0&&f(lt),P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===41?(oe=h,A++):(oe=s,Oe===0&&f(Kt)),oe!==s?(He=T,T=Ua(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function pt(){var T,w,P,X=A*56+26,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===58?(w=x,A++):(w=s,Oe===0&&f(lt)),w!==s?(P=D(),P!==s?(He=T,T=Us(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function sn(){var T,w,P,X,oe=A*56+27,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=it(),w!==s?(P=I_(),P!==s?(X=it(),X!==s?(He=T,T=Fa(w,P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Qt(){var T,w,P,X,oe,ve=A*56+28,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,i.substr(A,2)===b?(w=b,A+=2):(w=s,Oe===0&&f(Tt)),w!==s?(P=Xt(),P!==s?(X=pt(),X===s&&(X=null),i.charCodeAt(A)===93?(oe=S,A++):(oe=s,Oe===0&&f(Ue)),oe!==s?(He=T,T=Fs(P,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function qt(){var T,w,P,X,oe=A*56+29,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===91?(w=N,A++):(w=s,Oe===0&&f(Fn)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===93?(X=S,A++):(X=s,Oe===0&&f(Ue)),X!==s?(He=T,T=Ya(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function pr(){var T,w=A*56+30,P=ge[w];return P?(A=P.nextPos,P.result):(T=D(),T===s&&(T=y()),ge[w]={nextPos:A,result:T},T)}function Ws(){var T,w,P,X=A*56+31,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],P=hl(),P===s&&(P=pr()),P!==s)for(;P!==s;)w.push(P),P=hl(),P===s&&(P=pr());else w=s;return w!==s&&(He=T,w=Ys(w)),T=w,ge[X]={nextPos:A,result:T},T}function hl(){var T,w,P,X,oe=A*56+32,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===40?A++:Oe===0&&f(dt),w=pr(),w!==s?(P=I_(),P!==s?(X=Ws(),X!==s?(i.charCodeAt(A)===41?A++:Oe===0&&f(Kt),He=T,T=$s()):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function Xs(){var T,w,P,X,oe=A*56+33,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s){if(P=[],X=Ws(),X===s&&(X=F()),X!==s)for(;X!==s;)P.push(X),X=Ws(),X===s&&(X=F());else P=s;P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=ur(P)):(A=T,T=s)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function A_(){var T,w,P,X,oe=A*56+34,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===123?(w=k,A++):(w=s,Oe===0&&f(Fr)),w!==s?(P=D(),P===s&&(P=fu()),P!==s?(i.charCodeAt(A)===125?(X=L,A++):(X=s,Oe===0&&f(ct)),X!==s?(He=T,T=Ot(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function I_(){var T,w=A*56+35,P=ge[w];return P?(A=P.nextPos,P.result):(i.charCodeAt(A)===43?(T=M,A++):(T=s,Oe===0&&f(Hn)),T===s&&(i.charCodeAt(A)===45?(T=u,A++):(T=s,Oe===0&&f(rn)),T===s&&(i.charCodeAt(A)===42?(T=G,A++):(T=s,Oe===0&&f(Nn)),T===s&&(i.charCodeAt(A)===47?(T=$,A++):(T=s,Oe===0&&f(zn)),T===s&&(i.charCodeAt(A)===37?(T=te,A++):(T=s,Oe===0&&f(Ii)),T===s&&(i.charCodeAt(A)===94?(T=re,A++):(T=s,Oe===0&&f(wn)),T===s&&(i.charCodeAt(A)===124?(T=_,A++):(T=s,Oe===0&&f(H)),T===s&&(i.charCodeAt(A)===38?(T=ne,A++):(T=s,Oe===0&&f(Wt)),T===s&&(i.substr(A,2)===ee?(T=ee,A+=2):(T=s,Oe===0&&f(Cr)),T===s&&(i.substr(A,2)===B?(T=B,A+=2):(T=s,Oe===0&&f(ta))))))))))),ge[w]={nextPos:A,result:T},T)}function Zs(){var T,w,P=A*56+36,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=yR(),w===s&&(w=NR(),w===s&&(w=RR(),w===s&&(w=wR(),w===s&&(w=U(),w===s&&(w=IR(),w===s&&(w=ml(),w===s&&(w=vR(),w===s&&(w=F(),w===s&&(w=TR(),w===s&&(w=it(),w===s&&(w=Xs(),w===s&&(w=ER())))))))))))),w!==s&&(He=T,w=Gs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function ER(){var T,w,P=A*56+37,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===124?(w=_,A++):(w=s,Oe===0&&f(H)),w!==s&&(He=T,w=Ri()),T=w,ge[P]={nextPos:A,result:T},T)}function du(){var T,w,P,X,oe=A*56+38,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.charCodeAt(A)===60?(w=v,A++):(w=s,Oe===0&&f(Je)),w!==s?(P=Xt(),P!==s?(i.charCodeAt(A)===62?(X=I,A++):(X=s,Oe===0&&f(ye)),X!==s?(He=T,T=Qs(P)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function vR(){var T,w,P=A*56+39,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=pu(),w!==s&&(He=T,w=di(w)),T=w,ge[P]={nextPos:A,result:T},T)}function pu(){var T,w,P,X=A*56+40,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P===s&&(i.charCodeAt(A)===95?(P=Q,A++):(P=s,Oe===0&&f(oi)));else w=s;return w!==s&&(He=T,w=qs()),T=w,ge[X]={nextPos:A,result:T},T}function R_(){var T,w,P=A*56+41,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,i.charCodeAt(A)===63?(w=j,A++):(w=s,Oe===0&&f(na)),w!==s&&(He=T,w=Ni()),T=w,ge[P]={nextPos:A,result:T},T)}function fu(){var T,w,P,X,oe,ve,ft=A*56+42,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,i.charCodeAt(A)===40?(w=Z,A++):(w=s,Oe===0&&f(dt)),w!==s?(P=D(),P!==s?(i.charCodeAt(A)===44?(X=m,A++):(X=s,Oe===0&&f(an)),X!==s?(oe=D(),oe!==s?(i.charCodeAt(A)===41?(ve=h,A++):(ve=s,Oe===0&&f(Kt)),ve!==s?(He=T,T=$a(P,oe)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function N_(){var T,w,P,X,oe=A*56+43,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,w=Se(),w===s&&(w=Ce(),w===s&&(w=ae(),w===s&&(w=Zs()))),w!==s?(i.charCodeAt(A)===33?(P=K,A++):(P=s,Oe===0&&f(cr)),P!==s?(X=D(),X!==s?(He=T,T=Ga(w,X)):(A=T,T=s)):(A=T,T=s)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function TR(){var T,w,P=A*56+44,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=Fe(),w!==s&&(He=T,w=Vs(w)),T=w,ge[P]={nextPos:A,result:T},T)}function CR(){var T,w,P,X=A*56+45,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,w=Fe(),w!==s?(i.charCodeAt(A)===94?(P=re,A++):(P=s,Oe===0&&f(wn)),P!==s?(He=T,T=wi(w)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function yR(){var T,w,P,X,oe,ve=A*56+46,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=CR(),w===s&&(w=null),i.charCodeAt(A)===114?(P=ue,A++):(P=s,Oe===0&&f(li)),P!==s?(X=A,Oe++,At.test(i.charAt(A))?(oe=i.charAt(A),A++):(oe=s,Oe===0&&f(yr)),Oe--,oe===s?X=void 0:(A=X,X=s),X!==s?(He=T,T=Qa(w)):(A=T,T=s)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function ml(){var T,w,P,X,oe,ve=A*56+47,ft=ge[ve];return ft?(A=ft.nextPos,ft.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=AR(),X===s&&(X=null),oe=y(),oe===s&&(oe=R_(),oe===s&&(oe=fu(),oe===s&&(oe=A_()))),oe!==s?(He=T,T=Di(w,P,X,oe)):(A=T,T=s),ge[ve]={nextPos:A,result:T},T)}function AR(){var T,w,P,X=A*56+48,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci))),P!==s)for(;P!==s;)w.push(P),i.charCodeAt(A)===35?(P=le,A++):(P=s,Oe===0&&f(jt)),P===s&&(i.charCodeAt(A)===98?(P=be,A++):(P=s,Oe===0&&f(ci)));else w=s;return w!==s&&(He=T,w=xi(w)),T=w,ge[X]={nextPos:A,result:T},T}function IR(){var T,w,P,X,oe=A*56+49,ve=ge[oe];if(ve)return A=ve.nextPos,ve.result;if(T=A,w=ml(),w!==s){if(P=[],X=ml(),X!==s)for(;X!==s;)P.push(X),X=ml();else P=s;P!==s?(X=hu(),X===s&&(X=null),He=T,T=qa(w,P,X)):(A=T,T=s)}else A=T,T=s;return ge[oe]={nextPos:A,result:T},T}function w_(){var T,w,P,X=A*56+50,oe=ge[X];if(oe)return A=oe.nextPos,oe.result;if(T=A,w=[],Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui)),P!==s)for(;P!==s;)w.push(P),Nt.test(i.charAt(A))?(P=i.charAt(A),A++):(P=s,Oe===0&&f(ui));else w=s;return w!==s&&(He=T,w=ia()),T=w,ge[X]={nextPos:A,result:T},T}function hu(){var T,w,P,X=A*56+51,oe=ge[X];return oe?(A=oe.nextPos,oe.result):(T=A,i.charCodeAt(A)===37?(w=te,A++):(w=s,Oe===0&&f(Ii)),w!==s?(P=D(),P!==s?(He=T,T=pi(P)):(A=T,T=s)):(A=T,T=s),ge[X]={nextPos:A,result:T},T)}function D_(){var T,w,P=A*56+52,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,Rn.test(i.charAt(A))?(w=i.charAt(A),A++):(w=s,Oe===0&&f(q)),w!==s?(qe.test(i.charAt(A))?(i.charAt(A),A++):Oe===0&&f(ie),He=T,T=_n()):(A=T,T=s),ge[P]={nextPos:A,result:T},T)}function RR(){var T,w,P,X,oe,ve,ft=A*56+53,fr=ge[ft];return fr?(A=fr.nextPos,fr.result):(T=A,w=pu(),w===s&&(w=null),P=Fe(),P===s&&(P=null),X=D_(),X!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),oe=w_(),oe!==s?(ve=hu(),ve===s&&(ve=null),He=T,T=Va(w,P,X,oe,ve)):(A=T,T=s)):(A=T,T=s),ge[ft]={nextPos:A,result:T},T)}function NR(){var T,w,P,X,oe=A*56+54,ve=ge[oe];return ve?(A=ve.nextPos,ve.result):(T=A,i.substr(A,3)===De?(w=De,A+=3):(w=s,Oe===0&&f(de)),w===s&&(i.substr(A,2)===xe?(w=xe,A+=2):(w=s,Oe===0&&f(_e)),w===s&&(i.substr(A,2)===Ee?(w=Ee,A+=2):(w=s,Oe===0&&f(Ae)),w===s&&(i.charCodeAt(A)===105?(w=Ne,A++):(w=s,Oe===0&&f(Qe)),w===s&&(i.substr(A,3)===ce?(w=ce,A+=3):(w=s,Oe===0&&f(Pe)),w===s&&(i.substr(A,2)===Le?(w=Le,A+=2):(w=s,Oe===0&&f(Ct)),w===s&&(i.charCodeAt(A)===118?(w=Xe,A++):(w=s,Oe===0&&f(Dn)))))))),w!==s?(i.charCodeAt(A)===94?A++:Oe===0&&f(wn),P=w_(),P===s&&(P=null),X=hu(),X===s&&(X=null),He=T,T=Zn(w,P,X)):(A=T,T=s),ge[oe]={nextPos:A,result:T},T)}function wR(){var T,w,P=A*56+55,X=ge[P];return X?(A=X.nextPos,X.result):(T=A,w=D_(),w!==s&&(He=T,w=aa(w)),T=w,ge[P]={nextPos:A,result:T},T)}var x_=a.nodeOptions||{};function Ut(T,w,P=void 0){w.text=P||$n(),w.location=dl();for(var X in x_)(w[X]===void 0||w[X]===null)&&(w[X]=x_[X]);return new T(w)}if(sa=c(),sa!==s&&A===i.length)return sa;throw sa!==s&&Ae.collect("pitch"))}notes(){return this.evaluated.map(e=>e.collect("note"))}sounds(){return this.evaluated.map(e=>e.collect("sound"))}indices(){return this.evaluated.map(e=>e.collect("soundIndex"))}freqs(){return this.evaluated.map(e=>e.collect("freq"))}durations(){return this.evaluated.map(e=>e.collect("duration"))}octaves(){return this.evaluated.map(e=>e.collect("octave"))}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}invert(e){return this.applyOptions({inversion: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 ti(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())}update(){return this.evaluated=this.evaluate(this.values),this.applyTransformations(),this}evaluate(e,t={}){let n=e.map(i=>i.evaluate(t)).flat(1/0).filter(i=>i!==void 0);return t.subdivisions&&(n=fR(n)),n}totalDuration(){return this.evaluated.reduce((t,n)=>t+n.collect("duration"),0)}lead(){let e=this.evaluated.findIndex(t=>t instanceof Na);if(e>=0){for(let t=e+1;t<=this.evaluated.length;t++)if(this.evaluated[t]instanceof Na){const n=this.evaluated[e],i=this.evaluated[t],a=FG(n.notes(),i.notes()),s=ti(i);s.voiceLeadFromNotes(a,this.options.nodeOptions),this.evaluated[t]=s,e=t}}return this}}const fR=(r,e=void 0)=>r.map(n=>{if(n instanceof sR){const i=n.evaluated.length,a=(e||n.duration)/i;return fR(n.evaluated,a)}else return n.duration=e||n.duration,n}).flat(1/0),GG=r=>{let e={};return dG.forEach(t=>{if(r[t]!==void 0){const n=r[t];e[t]=n,delete r[t]}}),e};class QG{constructor(e,t){E(this,"api");E(this,"settings");E(this,"midiAccess",null);E(this,"midiOutputs",[]);E(this,"currentOutputIndex",0);E(this,"scheduledNotes",{});E(this,"midiInputs",[]);E(this,"currentInputIndex");E(this,"bufferLength",512);E(this,"noteInputBuffer",[]);E(this,"ccInputBuffer",[]);E(this,"activeNotes",[]);E(this,"stickyNotes",[]);E(this,"lastNote");E(this,"lastCC",{});E(this,"lastNoteInChannel",{});E(this,"lastCCInChannel",{});E(this,"midiClockInputIndex");E(this,"midiClockInput");E(this,"lastTimestamp",0);E(this,"midiClockDelta",0);E(this,"lastBPM");E(this,"roundedBPM",0);E(this,"clockBuffer",[]);E(this,"clockBufferLength",24);E(this,"clockTicks",0);E(this,"clockErrorCount",0);E(this,"skipOnError",0);this.api=e,this.settings=t,this.lastBPM=e.bpm(),this.roundedBPM=this.lastBPM,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),this.midiInputs=Array.from(this.midiAccess.inputs.values()),this.midiInputs.length===0?console.warn("No MIDI inputs available."):this.updateInputSelects()}catch(e){console.error("Failed to initialize MIDI:",e)}}getCurrentMidiPort(){return this.midiOutputs.length>0&&this.currentOutputIndex>=0&&this.currentOutputIndex0&&this.currentOutputIndex>=0&&this.currentOutputIndex0){const e=document.getElementById("midi-clock-input"),t=document.getElementById("default-midi-input");e.innerHTML="",t.innerHTML="";const n=document.createElement("option");n.value="-1",n.text="Internal",e.appendChild(n);const i=document.createElement("option");if(i.value="-1",i.text="None",t.appendChild(i),this.midiInputs.forEach((a,s)=>{const o=document.createElement("option");o.value=s.toString(),o.text=a.name||s.toString(),e.appendChild(o),t.appendChild(o.cloneNode(!0))}),this.settings.midi_clock_input){const a=this.getMidiInputIndex(this.settings.midi_clock_input);e.value=a.toString(),a>0&&(this.midiClockInput=this.midiInputs[a],this.registerMidiInputListener(a))}else e.value="-1";if(this.settings.default_midi_input){const a=this.getMidiInputIndex(this.settings.default_midi_input);t.value=a.toString(),a>0&&(this.currentInputIndex=a,this.registerMidiInputListener(a))}else t.value="-1";e.addEventListener("change",a=>{const s=a.target.value;if(s==="-1")this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=void 0,this.settings.midi_clock_input=void 0;else{const o=parseInt(s);this.midiClockInputIndex=o,this.midiClockInput&&this.midiClockInputIndex!=this.currentInputIndex&&(this.midiClockInput.onmidimessage=null),this.midiClockInput=this.midiInputs[o],this.registerMidiInputListener(o),this.settings.midi_clock_input=this.midiClockInput.name||void 0}}),t.addEventListener("change",a=>{const s=a.target.value;s==="-1"?(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=void 0,this.settings.default_midi_input=void 0):(this.currentInputIndex&&this.currentInputIndex!=this.midiClockInputIndex&&this.unregisterMidiInputListener(this.currentInputIndex),this.currentInputIndex=parseInt(s),this.registerMidiInputListener(this.currentInputIndex),this.settings.default_midi_input=this.midiInputs[this.currentInputIndex].name||void 0)})}}registerMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&!t.onmidimessage&&(t.onmidimessage=n=>{const i=n;if(t.name===this.settings.midi_clock_input&&(i.data[0]===248?this.skipOnError>0?this.skipOnError-=1:this.onMidiClock(n.timeStamp):i.data[0]===250?(console.log("MIDI start received"),this.api.stop(),this.api.play()):i.data[0]===252?(console.log("MIDI stop received"),this.api.pause()):i.data[0]===251?(console.log("MIDI continue received"),this.api.play()):i.data[0]===254&&console.log("MIDI active sensing received")),t.name===this.settings.default_midi_input){if(i.data[0]>=144&&i.data[0]<=159){const a=i.data[0]-144+1,s=i.data[1],o=i.data[2];this.lastNote={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.lastNoteInChannel[a]={note:s,velocity:o,channel:a,timestamp:n.timeStamp},this.settings.midi_channels_scripts&&this.api.script(a),this.pushToMidiInputBuffer({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.activeNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp}),this.removeFromStickyNotes(s,a)||this.stickyNotes.push({note:s,velocity:o,channel:a,timestamp:n.timeStamp})}if(i.data[0]>=128&&i.data[0]<=143){const a=i.data[0]-128+1,s=i.data[1];this.removeFromActiveNotes(s,a)}if(i.data[0]>=176&&i.data[0]<=191){const a=i.data[0]-176+1,s=i.data[1],o=i.data[2];this.lastCC[s]=o,this.lastCCInChannel[a]?this.lastCCInChannel[a][s]=o:(this.lastCCInChannel[a]={},this.lastCCInChannel[a][s]=o),this.pushToMidiCCBuffer({control:s,value:o,channel:a,timestamp:n.timeStamp})}}})}}removeFromActiveNotes(e,t){const n=this.activeNotes.findIndex(i=>i.note===e&&i.channel===t);n>=0&&this.activeNotes.splice(n,1)}removeFromStickyNotes(e,t){const n=this.stickyNotes.findIndex(i=>i.note===e&&i.channel===t);return n>=0?(this.stickyNotes.splice(n,1),!0):!1}stickyNotesFromChannel(e){return this.stickyNotes.filter(t=>t.channel===e)}activeNotesFromChannel(e){return this.activeNotes.filter(t=>t.channel===e)}killActiveNotes(){this.activeNotes=[]}killActiveNotesFromChannel(e){this.activeNotes=this.activeNotes.filter(t=>t.channel!==e)}pushToMidiInputBuffer(e){this.noteInputBuffer.push(e),this.noteInputBuffer.length>this.bufferLength&&this.noteInputBuffer.shift()}pushToMidiCCBuffer(e){this.ccInputBuffer.push(e),this.ccInputBuffer.length>this.bufferLength&&this.ccInputBuffer.shift()}findNoteFromBufferInChannel(e){const t=this.noteInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.noteInputBuffer[t];return this.noteInputBuffer.splice(t,1),n}else return}findCCFromBufferInChannel(e){const t=this.ccInputBuffer.findIndex(n=>n.channel===e);if(t>=0){const n=this.ccInputBuffer[t];return this.ccInputBuffer.splice(t,1),n}else return}unregisterMidiInputListener(e){if(e!==void 0){const t=this.midiInputs[e];t&&(t.onmidimessage=null)}}onMidiClock(e){if(this.clockTicks+=1,this.lastTimestamp>0)if(this.lastTimestamp===e)this.clockErrorCount+=1;else if(this.clockErrorCount>0)console.log("Timestamp error count: ",this.clockErrorCount),console.log("Current timestamp: ",e),console.log("Last timestamp: ",this.lastTimestamp),console.log("Last delta: ",this.midiClockDelta),console.log("Current delta: ",e-this.lastTimestamp),console.log("BPMs",this.clockBuffer),this.clockErrorCount=0,this.skipOnError=this.settings.midi_clock_ppqn/4,e=0;else{this.midiClockDelta=e-this.lastTimestamp,this.lastBPM=60*(1e3/this.midiClockDelta/this.settings.midi_clock_ppqn),this.clockBuffer.push(this.lastBPM),this.clockBuffer.length>this.clockBufferLength&&this.clockBuffer.shift();const t=this.estimatedBPM();t!==this.roundedBPM&&(console.log("Estimated BPM: ",t),this.api.bpm(t),this.roundedBPM=t)}this.lastTimestamp=e}estimatedBPM(){const e=this.clockBuffer.reduce((t,n)=>t+n);return Math.round(e/this.clockBuffer.length)}sendMidiClock(){if(!this.midiClockInput){const e=this.midiOutputs[this.currentOutputIndex];e&&e.send([248])}}switchMidiOutput(e){const t=this.getMidiOutputIndex(e);return t!==-1?(this.currentOutputIndex=t,!0):!1}getMidiOutputIndex(e){if(typeof e=="number")return e<0||e>=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(n=>n.name===e);return t!==-1?t:(console.error(`MIDI output "${e}" not found.`),this.currentOutputIndex)}}getMidiInputIndex(e){if(typeof e=="number")return e<0||e>=this.midiInputs.length?(console.error(`Invalid MIDI input index. Index must be in the range 0-${this.midiInputs.length-1}.`),-1):e;{const t=this.midiInputs.findIndex(n=>n.name===e);return t!==-1?t:(console.error(`MIDI input "${e}" not found.`),-1)}}listMidiOutputs(){let e="Available MIDI Outputs: ";return this.midiOutputs.forEach((t,n)=>{e+=`(${n+1}) ${t.name} `}),e}sendMidiNote(e,t,n,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,n],c=[128+t,e,0];o.send(l),s&&this.sendPitchBend(s,t,a);const u=setTimeout(()=>{o.send(c),s&&this.sendPitchBend(8192,t,a),delete this.scheduledNotes[e]},(i-.02)*1e3);this.scheduledNotes[e]=u}else console.error("MIDI output not available.")}sendMidiOn(e,t,n,i=this.currentOutputIndex){typeof i=="string"&&(i=this.getMidiOutputIndex(i));const a=this.midiOutputs[i];if(e=Math.min(Math.max(e,0),127),a){const s=[144+t,e,n];a.send(s)}else console.error("MIDI output not available.")}sendMidiOff(e,t,n=this.currentOutputIndex){typeof n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];if(e=Math.min(Math.max(e,0),127),i){const a=[128+t,e,0];i.send(a)}else console.error("MIDI output not available.")}sendAllNotesOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,123,0];n.send(i)}else console.error("MIDI output not available.")}sendAllSoundOff(e,t=this.currentOutputIndex){typeof t=="string"&&(t=this.getMidiOutputIndex(t));const n=this.midiOutputs[t];if(n){const i=[176+e,120,0];n.send(i)}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,n=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 n=="string"&&(n=this.getMidiOutputIndex(n));const i=this.midiOutputs[n];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 n=this.midiOutputs[this.currentOutputIndex];n?n.send([192+t,e]):console.error("MIDI output not available.")}sendMidiControlChange(e,t,n){const i=this.midiOutputs[this.currentOutputIndex];i?i.send([176+n,e,t]):console.error("MIDI output not available.")}panic(){const e=this.midiOutputs[this.currentOutputIndex];if(e){for(const t in this.scheduledNotes){const n=this.scheduledNotes[t];clearTimeout(n),e.send([128,parseInt(t),0])}this.scheduledNotes={}}else console.error("MIDI output not available.")}}class qG{constructor(e,t,n){E(this,"min");E(this,"max");E(this,"wrap");E(this,"position");this.min=e,this.max=t,this.wrap=n,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}}class C_{constructor(e){E(this,"seedValue");E(this,"randomGen",Math.random);E(this,"app");E(this,"values",{});E(this,"evenbar",e=>this.app.clock.time_position.bar%2===0?this.modify(e):this);E(this,"even",e=>this.app.clock.time_position.beat%2===0?this.modify(e):this);E(this,"odd",e=>this.app.clock.time_position.beat%2!==0?this.modify(e):this);E(this,"odds",(e,t)=>this.randomGen()this);E(this,"almostNever",e=>this.odds(.025,e));E(this,"rarely",e=>this.odds(.1,e));E(this,"scarcely",e=>this.odds(.25,e));E(this,"sometimes",e=>this.odds(.5,e));E(this,"often",e=>this.odds(.75,e));E(this,"frequently",e=>this.odds(.9,e));E(this,"almostAlways",e=>this.odds(.985,e));E(this,"always",e=>this.modify(e));E(this,"modify",e=>e(this));E(this,"seed",e=>(this.seedValue=e.toString(),this.randomGen=this.app.api.localSeededRandom(this.seedValue),this));E(this,"clear",()=>(this.app.api.clearLocalSeed(this.seedValue),this));E(this,"apply",e=>this.modify(e));E(this,"length",e=>(this.values.length=e,this));this.app=e,this.app.api.currentSeed&&(this.randomGen=this.app.api.randomGen)}}class hR extends C_{constructor(t){super(t);E(this,"octave",t=>(this.values.octave=t,this.update(),this));E(this,"key",t=>(this.values.key=t,this.update(),this));E(this,"scale",t=>(b_(t)?(this.values.scaleName=t,this.values.parsedScale=vi(t)):this.values.parsedScale=E_(t),this.update(),this));E(this,"freq",t=>{this.values.freq=t;const n=bG(t);return n%1!==0?(this.values.note=Math.floor(n),this.values.bend=oR(n)[1]):this.values.note=n,this});E(this,"update",()=>{})}}class tg extends hR{constructor(t,n){super(n);E(this,"nudge");E(this,"volume",t=>this.updateValue("volume",t));E(this,"vol",this.volume);E(this,"zrand",t=>this.updateValue("zrand",t));E(this,"curve",t=>this.updateValue("curve",t));E(this,"slide",t=>this.updateValue("slide",t));E(this,"sld",this.slide);E(this,"deltaSlide",t=>this.updateValue("deltaSlide",t));E(this,"dslide",this.deltaSlide);E(this,"pitchJump",t=>this.updateValue("pitchJump",t));E(this,"pj",this.pitchJump);E(this,"pitchJumpTime",t=>this.updateValue("pitchJumpTime",t));E(this,"pjt",this.pitchJumpTime);E(this,"lfo",t=>this.updateValue("lfo",t));E(this,"znoise",t=>this.updateValue("znoise",t));E(this,"noise",t=>this.updateValue("noise",t));E(this,"zmod",t=>this.updateValue("zmod",t));E(this,"zcrush",t=>this.updateValue("zcrush",t));E(this,"zdelay",t=>this.updateValue("zdelay",t));E(this,"sustainVolume",t=>this.updateValue("sustainVolume",t));E(this,"tremolo",t=>this.updateValue("tremolo",t));E(this,"dur",t=>this.updateValue("dur",t));E(this,"zzfx",t=>this.updateValue("zzfx",t));E(this,"fmi",t=>this.updateValue("fmi",t));E(this,"fmh",t=>this.updateValue("fmh",t));E(this,"fmenv",t=>this.updateValue("fmenv",t));E(this,"fmattack",t=>this.updateValue("fmattack",t));E(this,"fmatk",this.fmattack);E(this,"fmdecay",t=>this.updateValue("fmdecay",t));E(this,"fmdec",this.fmdecay);E(this,"fmsustain",t=>this.updateValue("fmsustain",t));E(this,"fmsus",this.fmsustain);E(this,"fmrelease",t=>this.updateValue("fmrelease",t));E(this,"fmrel",this.fmrelease);E(this,"fmvelocity",t=>this.updateValue("fmvelocity",t));E(this,"fmvel",this.fmvelocity);E(this,"fmwave",t=>this.updateValue("fmwave",t));E(this,"fmw",this.fmwave);E(this,"ftype",t=>this.updateValue("ftype",t));E(this,"fanchor",t=>this.updateValue("fanchor",t));E(this,"attack",t=>this.updateValue("attack",t));E(this,"atk",this.attack);E(this,"decay",t=>this.updateValue("decay",t));E(this,"dec",this.decay);E(this,"sustain",t=>this.updateValue("sustain",t));E(this,"sus",this.sustain);E(this,"release",t=>this.updateValue("release",t));E(this,"rel",this.release);E(this,"adsr",(t,n,i,a)=>(this.attack(t),this.decay(n),this.sustain(i),this.release(a),this));E(this,"ad",(t,n)=>(this.attack(t),this.decay(n),this.sustain(0),this.release(0),this));E(this,"lpenv",t=>this.updateValue("lpenv",t));E(this,"lpe",t=>this.updateValue("lpenv",t));E(this,"lpattack",t=>this.updateValue("lpattack",t));E(this,"lpa",this.lpattack);E(this,"lpdecay",t=>this.updateValue("lpdecay",t));E(this,"lpd",this.lpdecay);E(this,"lpsustain",t=>this.updateValue("lpsustain",t));E(this,"lps",this.lpsustain);E(this,"lprelease",t=>this.updateValue("lprelease",t));E(this,"lpr",this.lprelease);E(this,"cutoff",(t,n)=>(this.updateValue("cutoff",t),n&&this.resonance(n),this));E(this,"lpf",this.cutoff);E(this,"resonance",t=>(t>=0&&t<=1&&this.updateValue("resonance",50*t),this));E(this,"lpq",this.resonance);E(this,"lpadsr",(t,n,i,a,s)=>(this.lpenv(t),this.lpattack(n),this.lpdecay(i),this.lpsustain(a),this.lprelease(s),this));E(this,"lpad",(t,n,i)=>(this.lpenv(t),this.lpattack(n),this.lpdecay(i),this.lpsustain(0),this.lprelease(0),this));E(this,"hpenv",t=>this.updateValue("hpenv",t));E(this,"hpe",t=>this.updateValue("hpe",t));E(this,"hpattack",t=>this.updateValue("hpattack",t));E(this,"hpa",this.hpattack);E(this,"hpdecay",t=>this.updateValue("hpdecay",t));E(this,"hpd",this.hpdecay);E(this,"hpsustain",t=>this.updateValue("hpsustain",t));E(this,"hpsus",this.hpsustain);E(this,"hprelease",t=>this.updateValue("hprelease",t));E(this,"hpr",this.hprelease);E(this,"hcutoff",t=>this.updateValue("hcutoff",t));E(this,"hpf",this.hcutoff);E(this,"hresonance",(t,n)=>(this.updateValue("hresonance",t),n&&this.resonance(n),this));E(this,"hpq",this.hresonance);E(this,"hpadsr",(t,n,i,a,s)=>(this.hpenv(t),this.hpattack(n),this.hpdecay(i),this.hpsustain(a),this.hprelease(s),this));E(this,"hpad",(t,n,i)=>(this.hpenv(t),this.hpattack(n),this.hpdecay(i),this.hpsustain(0),this.hprelease(0),this));E(this,"bpenv",t=>this.updateValue("bpenv",t));E(this,"bpe",t=>this.updateValue("bpe",t));E(this,"bpattack",t=>this.updateValue("bpattack",t));E(this,"bpa",this.bpattack);E(this,"bpdecay",t=>this.updateValue("bpdecay",t));E(this,"bpd",this.bpdecay);E(this,"bpsustain",t=>this.updateValue("bpsustain",t));E(this,"bps",this.bpsustain);E(this,"bprelease",t=>this.updateValue("bprelease",t));E(this,"bpr",this.bprelease);E(this,"bandf",(t,n)=>(this.updateValue("bandf",t),n&&this.resonance(n),this));E(this,"bpf",this.bandf);E(this,"bandq",t=>this.updateValue("bandq",t));E(this,"bpq",this.bandq);E(this,"bpadsr",(t,n,i,a,s)=>(this.bpenv(t),this.bpattack(n),this.bpdecay(i),this.bpsustain(a),this.bprelease(s),this));E(this,"bpad",(t,n,i)=>(this.bpenv(t),this.bpattack(n),this.bpdecay(i),this.bpsustain(0),this.bprelease(0),this));E(this,"freq",t=>this.updateValue("freq",t));E(this,"f",this.freq);E(this,"vib",t=>this.updateValue("vib",t));E(this,"vibmod",t=>this.updateValue("vibmod",t));E(this,"fm",t=>{if(typeof t=="number")this.values.fmi=t;else{let n=t.split(":");this.values.fmi=parseFloat(n[0]),n.length>1&&(this.values.fmh=parseFloat(n[1]))}return this});E(this,"loop",t=>this.updateValue("loop",t));E(this,"loopBegin",t=>this.updateValue("loopBegin",t));E(this,"loopEnd",t=>this.updateValue("loopEnd",t));E(this,"begin",t=>this.updateValue("begin",t));E(this,"end",t=>this.updateValue("end",t));E(this,"gain",t=>this.updateValue("gain",t));E(this,"dbgain",t=>this.updateValue("gain",Math.min(Math.pow(10,t/20),10)));E(this,"db",this.dbgain);E(this,"velocity",t=>this.updateValue("velocity",t));E(this,"vel",this.velocity);E(this,"pan",t=>this.updateValue("pan",t));E(this,"sound",t=>this.updateValue("s",t));E(this,"chord",(t,...n)=>(typeof t=="string"?t=xG(t).map(a=>({note:a,freq:Zr(a)})):t instanceof Array&&typeof t[0]=="number"?t=t.map(i=>({note:i,freq:Zr(i)})):typeof t=="number"&&n.length>0&&(t=[t,...n].map(i=>({note:i,freq:Zr(i)}))),this.updateValue("chord",t)));E(this,"invert",(t=0)=>{if(this.values.chord){let n=this.values.chord.map(a=>a.note);n=t<0?[...n].reverse():n;for(let a=0;a({note:a,freq:Zr(a)}));return this.updateValue("chord",i)}else return this});E(this,"snd",this.sound);E(this,"cut",t=>this.updateValue("cut",t));E(this,"clip",t=>this.updateValue("clip",t));E(this,"n",t=>this.updateValue("n",t));E(this,"note",t=>typeof t=="string"?this.updateValue("note",Ur(t)):typeof t==null||t==null?this.updateValue("note",0).updateValue("gain",0):this.updateValue("note",t));E(this,"speed",t=>this.updateValue("speed",t));E(this,"spd",this.speed);E(this,"coarse",t=>this.updateValue("coarse",t));E(this,"crush",t=>this.updateValue("crush",t));E(this,"shape",t=>this.updateValue("shape",t));E(this,"vowel",t=>this.updateValue("vowel",t));E(this,"vow",this.vowel);E(this,"delay",t=>this.updateValue("delay",t));E(this,"del",this.delay);E(this,"delayfeedback",t=>this.updateValue("delayfeedback",t));E(this,"delayfb",this.delayfeedback);E(this,"delaytime",t=>this.updateValue("delaytime",t));E(this,"delayt",this.delaytime);E(this,"orbit",t=>this.updateValue("orbit",t));E(this,"o",this.orbit);E(this,"room",t=>this.updateValue("room",t));E(this,"rm",this.room);E(this,"roomfade",t=>this.updateValue("roomfade",t));E(this,"rfade",this.roomfade);E(this,"roomlp",t=>this.updateValue("roomlp",t));E(this,"rlp",this.roomlp);E(this,"roomdim",t=>this.updateValue("roomdim",t));E(this,"rdim",this.roomdim);E(this,"size",t=>this.updateValue("roomsize",t));E(this,"sz",this.size);E(this,"rev",(t,n,i,a,s)=>(this.updateValue("room",t),this.updateValue("roomsize",n),i&&this.updateValue("roomfade",i),a&&this.updateValue("roomlp",a),s&&this.updateValue("roomdim",s),this));E(this,"comp",t=>this.updateValue("compressor",t));E(this,"cmp",this.comp);E(this,"ratio",t=>this.updateValue("compressorRatio",t));E(this,"rt",this.ratio);E(this,"knee",t=>this.updateValue("compressorKnee",t));E(this,"kn",this.knee);E(this,"compAttack",t=>this.updateValue("compressorAttack",t));E(this,"cmpa",this.compAttack);E(this,"compRelease",t=>this.updateValue("compressorRelease",t));E(this,"cmpr",this.compRelease);E(this,"stretch",t=>(this.updateValue("unit","c"),this.updateValue("speed",1/t),this.updateValue("cut",t),this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.freq=Zr(t)});E(this,"out",()=>{this.values.chord?this.values.chord.forEach(t=>{const n={...this.values};n.freq=t.freq,P_(n,this.nudge,this.values.dur)}):P_(this.values,this.nudge,this.values.dur)});this.app=n,this.nudge=n.dough_nudge/100,typeof t=="string"?t.includes(":")?this.values={s:t.split(":")[0],n:t.split(":")[1],dur:n.clock.convertPulseToSecond(n.clock.ppqn),analyze:!0}:this.values={s:t,dur:.5,analyze:!0}:this.values=t}updateValue(t,n){return this.values[t]=n,this}}class ng extends hR{constructor(t,n){super(n);E(this,"midiConnection");E(this,"chord",t=>(this.values.chord=t,this));E(this,"note",t=>(this.values.note=t,this));E(this,"sustain",t=>(this.values.sustain=t,this));E(this,"channel",t=>(this.values.channel=t,this));E(this,"port",t=>(this.values.port=this.midiConnection.getMidiOutputIndex(t),this));E(this,"add",t=>(this.values.note+=t,this));E(this,"modify",t=>{const n=t(this);return n instanceof Object?n:(t(this.values),this.update(),this)});E(this,"bend",t=>(this.values.bend=t,this));E(this,"random",(t=0,n=127)=>(t=Math.min(Math.max(t,0),127),n=Math.min(Math.max(n,0),127),this.values.note=Math.floor(this.randomGen()*(n-t+1))+t,this));E(this,"update",()=>{const[t,n]=v_(this.values.key||"C4",this.values.pitch||0,this.values.parsedScale||"MAJOR",this.values.octave||0);this.values.note=t,this.values.freq=Zr(t),n&&(this.values.bend=n)});E(this,"out",()=>{function t(n,i){const a=i&&i.channel?i.channel:0,s=n.values.channel?n.values.channel:a,o=n.values.velocity?n.values.velocity:100,l=i&&i.note?i.note:60,c=n.values.note?n.values.note:l,u=n.values.sustain?n.values.sustain*n.app.clock.pulse_duration*n.app.api.ppqn():n.app.clock.pulse_duration*n.app.api.ppqn(),p=n.values.bend?n.values.bend:void 0,m=n.values.port?n.midiConnection.getMidiOutputIndex(n.values.port):n.midiConnection.getCurrentMidiPortIndex();n.midiConnection.sendMidiNote(c,s,o,u,m,p)}this.values.chord?this.values.chord.forEach(n=>{t(this,n)}):t(this)});this.app=n,typeof t=="number"?this.values.note=t:this.values=t,this.midiConnection=n.api.MidiConnection}}const po=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,mR=new Set,rg=typeof process=="object"&&process?process:{},gR=(r,e,t,n)=>{typeof rg.emitWarning=="function"?rg.emitWarning(r,e,t,n):console.error(`[${t}] ${e}: ${r}`)};let Qc=globalThis.AbortController,_T=globalThis.AbortSignal;var OT;if(typeof Qc>"u"){_T=class{constructor(){E(this,"onabort");E(this,"_onabort",[]);E(this,"reason");E(this,"aborted",!1)}addEventListener(n,i){this._onabort.push(i)}},Qc=class{constructor(){E(this,"signal",new _T);e()}abort(n){var i,a;if(!this.signal.aborted){this.signal.reason=n,this.signal.aborted=!0;for(const s of this.signal._onabort)s(n);(a=(i=this.signal).onabort)==null||a.call(i,n)}}};let r=((OT=rg.env)==null?void 0:OT.LRU_CACHE_IGNORE_AC_WARNING)!=="1";const e=()=>{r&&(r=!1,gR("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 VG=r=>!mR.has(r),Bi=r=>r&&r===Math.floor(r)&&r>0&&isFinite(r),_R=r=>Bi(r)?r<=Math.pow(2,8)?Uint8Array:r<=Math.pow(2,16)?Uint16Array:r<=Math.pow(2,32)?Uint32Array:r<=Number.MAX_SAFE_INTEGER?rc:null:null;class rc extends Array{constructor(e){super(e),this.fill(0)}}var cs;const fa=class fa{constructor(e,t){E(this,"heap");E(this,"length");if(!V(fa,cs))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}static create(e){const t=_R(e);if(!t)return[];We(fa,cs,!0);const n=new fa(e,t);return We(fa,cs,!1),n}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}};cs=new WeakMap,at(fa,cs,!1);let ig=fa;var Rr,er,Nr,wr,us,on,Dr,ln,Lt,nt,Ln,tr,Cn,hn,xr,mn,gi,_i,kr,Lr,qi,Mn,jo,sg,Oa,Si,Jo,nr,zc,SR,ba,ds,el,qr,Ui,Vr,Fi,tl,og,ps,ic,fs,ac,Dt,Ft,nl,lg,Ea,bo;const y_=class y_{constructor(e){at(this,jo);at(this,zc);at(this,qr);at(this,Vr);at(this,tl);at(this,ps);at(this,fs);at(this,Dt);at(this,nl);at(this,Ea);at(this,Rr,void 0);at(this,er,void 0);at(this,Nr,void 0);at(this,wr,void 0);at(this,us,void 0);E(this,"ttl");E(this,"ttlResolution");E(this,"ttlAutopurge");E(this,"updateAgeOnGet");E(this,"updateAgeOnHas");E(this,"allowStale");E(this,"noDisposeOnSet");E(this,"noUpdateTTL");E(this,"maxEntrySize");E(this,"sizeCalculation");E(this,"noDeleteOnFetchRejection");E(this,"noDeleteOnStaleGet");E(this,"allowStaleOnFetchAbort");E(this,"allowStaleOnFetchRejection");E(this,"ignoreFetchAbort");at(this,on,void 0);at(this,Dr,void 0);at(this,ln,void 0);at(this,Lt,void 0);at(this,nt,void 0);at(this,Ln,void 0);at(this,tr,void 0);at(this,Cn,void 0);at(this,hn,void 0);at(this,xr,void 0);at(this,mn,void 0);at(this,gi,void 0);at(this,_i,void 0);at(this,kr,void 0);at(this,Lr,void 0);at(this,qi,void 0);at(this,Mn,void 0);at(this,Oa,()=>{});at(this,Si,()=>{});at(this,Jo,()=>{});at(this,nr,()=>!1);at(this,ba,e=>{});at(this,ds,(e,t,n)=>{});at(this,el,(e,t,n,i)=>{if(n||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0});const{max:t=0,ttl:n,ttlResolution:i=1,ttlAutopurge:a,updateAgeOnGet:s,updateAgeOnHas:o,allowStale:l,dispose:c,disposeAfter:u,noDisposeOnSet:p,noUpdateTTL:m,maxSize:_=0,maxEntrySize:v=0,sizeCalculation:I,fetchMethod:R,noDeleteOnFetchRejection:x,noDeleteOnStaleGet:$,allowStaleOnFetchRejection:Z,allowStaleOnFetchAbort:h,ignoreFetchAbort:b}=e;if(t!==0&&!Bi(t))throw new TypeError("max option must be a nonnegative integer");const S=t?_R(t):Array;if(!S)throw new Error("invalid max value: "+t);if(We(this,Rr,t),We(this,er,_),this.maxEntrySize=v||V(this,er),this.sizeCalculation=I,this.sizeCalculation){if(!V(this,er)&&!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(R!==void 0&&typeof R!="function")throw new TypeError("fetchMethod must be a function if specified");if(We(this,us,R),We(this,qi,!!R),We(this,ln,new Map),We(this,Lt,new Array(t).fill(void 0)),We(this,nt,new Array(t).fill(void 0)),We(this,Ln,new S(t)),We(this,tr,new S(t)),We(this,Cn,0),We(this,hn,0),We(this,xr,ig.create(t)),We(this,on,0),We(this,Dr,0),typeof c=="function"&&We(this,Nr,c),typeof u=="function"?(We(this,wr,u),We(this,mn,[])):(We(this,wr,void 0),We(this,mn,void 0)),We(this,Lr,!!V(this,Nr)),We(this,Mn,!!V(this,wr)),this.noDisposeOnSet=!!p,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!x,this.allowStaleOnFetchRejection=!!Z,this.allowStaleOnFetchAbort=!!h,this.ignoreFetchAbort=!!b,this.maxEntrySize!==0){if(V(this,er)!==0&&!Bi(V(this,er)))throw new TypeError("maxSize must be a positive integer if specified");if(!Bi(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");ze(this,zc,SR).call(this)}if(this.allowStale=!!l,this.noDeleteOnStaleGet=!!$,this.updateAgeOnGet=!!s,this.updateAgeOnHas=!!o,this.ttlResolution=Bi(i)||i===0?i:1,this.ttlAutopurge=!!a,this.ttl=n||0,this.ttl){if(!Bi(this.ttl))throw new TypeError("ttl must be a positive integer if specified");ze(this,jo,sg).call(this)}if(V(this,Rr)===0&&this.ttl===0&&V(this,er)===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!V(this,Rr)&&!V(this,er)){const N="LRU_CACHE_UNBOUNDED";VG(N)&&(mR.add(N),gR("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",N,y_))}}static unsafeExposeInternals(e){return{starts:V(e,_i),ttls:V(e,kr),sizes:V(e,gi),keyMap:V(e,ln),keyList:V(e,Lt),valList:V(e,nt),next:V(e,Ln),prev:V(e,tr),get head(){return V(e,Cn)},get tail(){return V(e,hn)},free:V(e,xr),isBackgroundFetch:t=>{var n;return ze(n=e,Dt,Ft).call(n,t)},backgroundFetch:(t,n,i,a)=>{var s;return ze(s=e,fs,ac).call(s,t,n,i,a)},moveToTail:t=>{var n;return ze(n=e,Ea,bo).call(n,t)},indexes:t=>{var n;return ze(n=e,qr,Ui).call(n,t)},rindexes:t=>{var n;return ze(n=e,Vr,Fi).call(n,t)},isStale:t=>{var n;return V(n=e,nr).call(n,t)}}}get max(){return V(this,Rr)}get maxSize(){return V(this,er)}get calculatedSize(){return V(this,Dr)}get size(){return V(this,on)}get fetchMethod(){return V(this,us)}get dispose(){return V(this,Nr)}get disposeAfter(){return V(this,wr)}getRemainingTTL(e){return V(this,ln).has(e)?1/0:0}*entries(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*rentries(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&V(this,Lt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield[V(this,Lt)[e],V(this,nt)[e]])}*keys(){for(const e of ze(this,qr,Ui).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*rkeys(){for(const e of ze(this,Vr,Fi).call(this)){const t=V(this,Lt)[e];t!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield t)}}*values(){for(const e of ze(this,qr,Ui).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}*rvalues(){for(const e of ze(this,Vr,Fi).call(this))V(this,nt)[e]!==void 0&&!ze(this,Dt,Ft).call(this,V(this,nt)[e])&&(yield V(this,nt)[e])}[Symbol.iterator](){return this.entries()}find(e,t={}){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a!==void 0&&e(a,V(this,Lt)[n],this))return this.get(V(this,Lt)[n],t)}}forEach(e,t=this){for(const n of ze(this,qr,Ui).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}rforEach(e,t=this){for(const n of ze(this,Vr,Fi).call(this)){const i=V(this,nt)[n],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;a!==void 0&&e.call(t,a,V(this,Lt)[n],this)}}purgeStale(){let e=!1;for(const t of ze(this,Vr,Fi).call(this,{allowStale:!0}))V(this,nr).call(this,t)&&(this.delete(V(this,Lt)[t]),e=!0);return e}dump(){const e=[];for(const t of ze(this,qr,Ui).call(this,{allowStale:!0})){const n=V(this,Lt)[t],i=V(this,nt)[t],a=ze(this,Dt,Ft).call(this,i)?i.__staleWhileFetching:i;if(a===void 0||n===void 0)continue;const s={value:a};if(V(this,kr)&&V(this,_i)){s.ttl=V(this,kr)[t];const o=po.now()-V(this,_i)[t];s.start=Math.floor(Date.now()-o)}V(this,gi)&&(s.size=V(this,gi)[t]),e.unshift([n,s])}return e}load(e){this.clear();for(const[t,n]of e){if(n.start){const i=Date.now()-n.start;n.start=po.now()-i}this.set(t,n.value,n)}}set(e,t,n={}){var m,_,v,I,R;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}=n;let{noUpdateTTL:c=this.noUpdateTTL}=n;const u=V(this,el).call(this,e,t,n.size||0,o);if(this.maxEntrySize&&u>this.maxEntrySize)return l&&(l.set="miss",l.maxEntrySizeExceeded=!0),this.delete(e),this;let p=V(this,on)===0?void 0:V(this,ln).get(e);if(p===void 0)p=V(this,on)===0?V(this,hn):V(this,xr).length!==0?V(this,xr).pop():V(this,on)===V(this,Rr)?ze(this,ps,ic).call(this,!1):V(this,on),V(this,Lt)[p]=e,V(this,nt)[p]=t,V(this,ln).set(e,p),V(this,Ln)[V(this,hn)]=p,V(this,tr)[p]=V(this,hn),We(this,hn,p),gl(this,on)._++,V(this,ds).call(this,p,u,l),l&&(l.set="add"),c=!1;else{ze(this,Ea,bo).call(this,p);const x=V(this,nt)[p];if(t!==x){if(V(this,qi)&&ze(this,Dt,Ft).call(this,x)){x.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:$}=x;$!==void 0&&!s&&(V(this,Lr)&&((m=V(this,Nr))==null||m.call(this,$,e,"set")),V(this,Mn)&&((_=V(this,mn))==null||_.push([$,e,"set"])))}else s||(V(this,Lr)&&((v=V(this,Nr))==null||v.call(this,x,e,"set")),V(this,Mn)&&((I=V(this,mn))==null||I.push([x,e,"set"])));if(V(this,ba).call(this,p),V(this,ds).call(this,p,u,l),V(this,nt)[p]=t,l){l.set="replace";const $=x&&ze(this,Dt,Ft).call(this,x)?x.__staleWhileFetching:x;$!==void 0&&(l.oldValue=$)}}else l&&(l.set="update")}if(i!==0&&!V(this,kr)&&ze(this,jo,sg).call(this),V(this,kr)&&(c||V(this,Jo).call(this,p,i,a),l&&V(this,Si).call(this,l,p)),!s&&V(this,Mn)&&V(this,mn)){const x=V(this,mn);let $;for(;$=x==null?void 0:x.shift();)(R=V(this,wr))==null||R.call(this,...$)}return this}pop(){var e;try{for(;V(this,on);){const t=V(this,nt)[V(this,Cn)];if(ze(this,ps,ic).call(this,!0),ze(this,Dt,Ft).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(t!==void 0)return t}}finally{if(V(this,Mn)&&V(this,mn)){const t=V(this,mn);let n;for(;n=t==null?void 0:t.shift();)(e=V(this,wr))==null||e.call(this,...n)}}}has(e,t={}){const{updateAgeOnHas:n=this.updateAgeOnHas,status:i}=t,a=V(this,ln).get(e);if(a!==void 0){const s=V(this,nt)[a];if(ze(this,Dt,Ft).call(this,s)&&s.__staleWhileFetching===void 0)return!1;if(V(this,nr).call(this,a))i&&(i.has="stale",V(this,Si).call(this,i,a));else return n&&V(this,Oa).call(this,a),i&&(i.has="hit",V(this,Si).call(this,i,a)),!0}else i&&(i.has="miss");return!1}peek(e,t={}){const{allowStale:n=this.allowStale}=t,i=V(this,ln).get(e);if(i!==void 0&&(n||!V(this,nr).call(this,i))){const a=V(this,nt)[i];return ze(this,Dt,Ft).call(this,a)?a.__staleWhileFetching:a}}async fetch(e,t={}){const{allowStale:n=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:u=this.noUpdateTTL,noDeleteOnFetchRejection:p=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:m=this.allowStaleOnFetchRejection,ignoreFetchAbort:_=this.ignoreFetchAbort,allowStaleOnFetchAbort:v=this.allowStaleOnFetchAbort,context:I,forceRefresh:R=!1,status:x,signal:$}=t;if(!V(this,qi))return x&&(x.fetch="get"),this.get(e,{allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,status:x});const Z={allowStale:n,updateAgeOnGet:i,noDeleteOnStaleGet:a,ttl:s,noDisposeOnSet:o,size:l,sizeCalculation:c,noUpdateTTL:u,noDeleteOnFetchRejection:p,allowStaleOnFetchRejection:m,allowStaleOnFetchAbort:v,ignoreFetchAbort:_,status:x,signal:$};let h=V(this,ln).get(e);if(h===void 0){x&&(x.fetch="miss");const b=ze(this,fs,ac).call(this,e,h,Z,I);return b.__returned=b}else{const b=V(this,nt)[h];if(ze(this,Dt,Ft).call(this,b)){const M=n&&b.__staleWhileFetching!==void 0;return x&&(x.fetch="inflight",M&&(x.returnedStale=!0)),M?b.__staleWhileFetching:b.__returned=b}const S=V(this,nr).call(this,h);if(!R&&!S)return x&&(x.fetch="hit"),ze(this,Ea,bo).call(this,h),i&&V(this,Oa).call(this,h),x&&V(this,Si).call(this,x,h),b;const N=ze(this,fs,ac).call(this,e,h,Z,I),L=N.__staleWhileFetching!==void 0&&n;return x&&(x.fetch=S?"stale":"refresh",L&&S&&(x.returnedStale=!0)),L?N.__staleWhileFetching:N.__returned=N}}get(e,t={}){const{allowStale:n=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:a=this.noDeleteOnStaleGet,status:s}=t,o=V(this,ln).get(e);if(o!==void 0){const l=V(this,nt)[o],c=ze(this,Dt,Ft).call(this,l);return s&&V(this,Si).call(this,s,o),V(this,nr).call(this,o)?(s&&(s.get="stale"),c?(s&&n&&l.__staleWhileFetching!==void 0&&(s.returnedStale=!0),n?l.__staleWhileFetching:void 0):(a||this.delete(e),s&&n&&(s.returnedStale=!0),n?l:void 0)):(s&&(s.get="hit"),c?l.__staleWhileFetching:(ze(this,Ea,bo).call(this,o),i&&V(this,Oa).call(this,o),l))}else s&&(s.get="miss")}delete(e){var n,i,a,s;let t=!1;if(V(this,on)!==0){const o=V(this,ln).get(e);if(o!==void 0)if(t=!0,V(this,on)===1)this.clear();else{V(this,ba).call(this,o);const l=V(this,nt)[o];ze(this,Dt,Ft).call(this,l)?l.__abortController.abort(new Error("deleted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((n=V(this,Nr))==null||n.call(this,l,e,"delete")),V(this,Mn)&&((i=V(this,mn))==null||i.push([l,e,"delete"]))),V(this,ln).delete(e),V(this,Lt)[o]=void 0,V(this,nt)[o]=void 0,o===V(this,hn)?We(this,hn,V(this,tr)[o]):o===V(this,Cn)?We(this,Cn,V(this,Ln)[o]):(V(this,Ln)[V(this,tr)[o]]=V(this,Ln)[o],V(this,tr)[V(this,Ln)[o]]=V(this,tr)[o]),gl(this,on)._--,V(this,xr).push(o)}}if(V(this,Mn)&&((a=V(this,mn))!=null&&a.length)){const o=V(this,mn);let l;for(;l=o==null?void 0:o.shift();)(s=V(this,wr))==null||s.call(this,...l)}return t}clear(){var e,t,n;for(const i of ze(this,Vr,Fi).call(this,{allowStale:!0})){const a=V(this,nt)[i];if(ze(this,Dt,Ft).call(this,a))a.__abortController.abort(new Error("deleted"));else{const s=V(this,Lt)[i];V(this,Lr)&&((e=V(this,Nr))==null||e.call(this,a,s,"delete")),V(this,Mn)&&((t=V(this,mn))==null||t.push([a,s,"delete"]))}}if(V(this,ln).clear(),V(this,nt).fill(void 0),V(this,Lt).fill(void 0),V(this,kr)&&V(this,_i)&&(V(this,kr).fill(0),V(this,_i).fill(0)),V(this,gi)&&V(this,gi).fill(0),We(this,Cn,0),We(this,hn,0),V(this,xr).length=0,We(this,Dr,0),We(this,on,0),V(this,Mn)&&V(this,mn)){const i=V(this,mn);let a;for(;a=i==null?void 0:i.shift();)(n=V(this,wr))==null||n.call(this,...a)}}};Rr=new WeakMap,er=new WeakMap,Nr=new WeakMap,wr=new WeakMap,us=new WeakMap,on=new WeakMap,Dr=new WeakMap,ln=new WeakMap,Lt=new WeakMap,nt=new WeakMap,Ln=new WeakMap,tr=new WeakMap,Cn=new WeakMap,hn=new WeakMap,xr=new WeakMap,mn=new WeakMap,gi=new WeakMap,_i=new WeakMap,kr=new WeakMap,Lr=new WeakMap,qi=new WeakMap,Mn=new WeakMap,jo=new WeakSet,sg=function(){const e=new rc(V(this,Rr)),t=new rc(V(this,Rr));We(this,kr,e),We(this,_i,t),We(this,Jo,(a,s,o=po.now())=>{if(t[a]=s!==0?o:0,e[a]=s,s!==0&&this.ttlAutopurge){const l=setTimeout(()=>{V(this,nr).call(this,a)&&this.delete(V(this,Lt)[a])},s+1);l.unref&&l.unref()}}),We(this,Oa,a=>{t[a]=e[a]!==0?po.now():0}),We(this,Si,(a,s)=>{if(e[s]){const o=e[s],l=t[s];a.ttl=o,a.start=l,a.now=n||i();const c=a.now-l;a.remainingTTL=o-c}});let n=0;const i=()=>{const a=po.now();if(this.ttlResolution>0){n=a;const s=setTimeout(()=>n=0,this.ttlResolution);s.unref&&s.unref()}return a};this.getRemainingTTL=a=>{const s=V(this,ln).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=(n||i())-l;return o-c},We(this,nr,a=>e[a]!==0&&t[a]!==0&&(n||i())-t[a]>e[a])},Oa=new WeakMap,Si=new WeakMap,Jo=new WeakMap,nr=new WeakMap,zc=new WeakSet,SR=function(){const e=new rc(V(this,Rr));We(this,Dr,0),We(this,gi,e),We(this,ba,t=>{We(this,Dr,V(this,Dr)-e[t]),e[t]=0}),We(this,el,(t,n,i,a)=>{if(ze(this,Dt,Ft).call(this,n))return 0;if(!Bi(i))if(a){if(typeof a!="function")throw new TypeError("sizeCalculation must be a function");if(i=a(n,t),!Bi(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}),We(this,ds,(t,n,i)=>{if(e[t]=n,V(this,er)){const a=V(this,er)-e[t];for(;V(this,Dr)>a;)ze(this,ps,ic).call(this,!0)}We(this,Dr,V(this,Dr)+e[t]),i&&(i.entrySize=n,i.totalCalculatedSize=V(this,Dr))})},ba=new WeakMap,ds=new WeakMap,el=new WeakMap,qr=new WeakSet,Ui=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,hn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,Cn)));)t=V(this,tr)[t]},Vr=new WeakSet,Fi=function*({allowStale:e=this.allowStale}={}){if(V(this,on))for(let t=V(this,Cn);!(!ze(this,tl,og).call(this,t)||((e||!V(this,nr).call(this,t))&&(yield t),t===V(this,hn)));)t=V(this,Ln)[t]},tl=new WeakSet,og=function(e){return e!==void 0&&V(this,ln).get(V(this,Lt)[e])===e},ps=new WeakSet,ic=function(e){var a,s;const t=V(this,Cn),n=V(this,Lt)[t],i=V(this,nt)[t];return V(this,qi)&&ze(this,Dt,Ft).call(this,i)?i.__abortController.abort(new Error("evicted")):(V(this,Lr)||V(this,Mn))&&(V(this,Lr)&&((a=V(this,Nr))==null||a.call(this,i,n,"evict")),V(this,Mn)&&((s=V(this,mn))==null||s.push([i,n,"evict"]))),V(this,ba).call(this,t),e&&(V(this,Lt)[t]=void 0,V(this,nt)[t]=void 0,V(this,xr).push(t)),V(this,on)===1?(We(this,Cn,We(this,hn,0)),V(this,xr).length=0):We(this,Cn,V(this,Ln)[t]),V(this,ln).delete(n),gl(this,on)._--,t},fs=new WeakSet,ac=function(e,t,n,i){const a=t===void 0?void 0:V(this,nt)[t];if(ze(this,Dt,Ft).call(this,a))return a;const s=new Qc,{signal:o}=n;o==null||o.addEventListener("abort",()=>s.abort(o.reason),{signal:s.signal});const l={signal:s.signal,options:n,context:i},c=(I,R=!1)=>{const{aborted:x}=s.signal,$=n.ignoreFetchAbort&&I!==void 0;if(n.status&&(x&&!R?(n.status.fetchAborted=!0,n.status.fetchError=s.signal.reason,$&&(n.status.fetchAbortIgnored=!0)):n.status.fetchResolved=!0),x&&!$&&!R)return p(s.signal.reason);const Z=_;return V(this,nt)[t]===_&&(I===void 0?Z.__staleWhileFetching?V(this,nt)[t]=Z.__staleWhileFetching:this.delete(e):(n.status&&(n.status.fetchUpdated=!0),this.set(e,I,l.options))),I},u=I=>(n.status&&(n.status.fetchRejected=!0,n.status.fetchError=I),p(I)),p=I=>{const{aborted:R}=s.signal,x=R&&n.allowStaleOnFetchAbort,$=x||n.allowStaleOnFetchRejection,Z=$||n.noDeleteOnFetchRejection,h=_;if(V(this,nt)[t]===_&&(!Z||h.__staleWhileFetching===void 0?this.delete(e):x||(V(this,nt)[t]=h.__staleWhileFetching)),$)return n.status&&h.__staleWhileFetching!==void 0&&(n.status.returnedStale=!0),h.__staleWhileFetching;if(h.__returned===h)throw I},m=(I,R)=>{var $;const x=($=V(this,us))==null?void 0:$.call(this,e,a,l);x&&x instanceof Promise&&x.then(Z=>I(Z===void 0?void 0:Z),R),s.signal.addEventListener("abort",()=>{(!n.ignoreFetchAbort||n.allowStaleOnFetchAbort)&&(I(void 0),n.allowStaleOnFetchAbort&&(I=Z=>c(Z,!0)))})};n.status&&(n.status.fetchDispatched=!0);const _=new Promise(m).then(c,u),v=Object.assign(_,{__abortController:s,__staleWhileFetching:a,__returned:void 0});return t===void 0?(this.set(e,v,{...l.options,status:void 0}),t=V(this,ln).get(e)):V(this,nt)[t]=v,v},Dt=new WeakSet,Ft=function(e){if(!V(this,qi))return!1;const t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof Qc},nl=new WeakSet,lg=function(e,t){V(this,tr)[t]=e,V(this,Ln)[e]=t},Ea=new WeakSet,bo=function(e){e!==V(this,hn)&&(e===V(this,Cn)?We(this,Cn,V(this,Ln)[e]):ze(this,nl,lg).call(this,V(this,tr)[e],V(this,Ln)[e]),ze(this,nl,lg).call(this,V(this,hn),e),We(this,hn,e))};let ag=y_;const Ro=class Ro{constructor(){E(this,"_fallbackMethod",()=>Ro.createSkipProxy());E(this,"out",()=>{})}};E(Ro,"createSkipProxy",()=>{const e=new Ro;return new Proxy(e,{get(t,n,i){return typeof t[n]>"u"?t._fallbackMethod:t[n]},set(t,n,i,a){return!1}})});let qc=Ro;const No=class No extends C_{constructor(t,n){super(n);E(this,"_fallbackMethod",()=>No.createRestProxy(this.values.length,this.app));E(this,"out",()=>{});this.values.length=t}};E(No,"createRestProxy",(t,n)=>{const i=new No(t,n);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 Vc=No;class zG extends C_{constructor(t,n,i){super(i);E(this,"input");E(this,"ziffers");E(this,"initCallTime",0);E(this,"startCallTime",0);E(this,"lastCallTime",0);E(this,"waitTime",0);E(this,"startBeat",0);E(this,"played",!1);E(this,"current");E(this,"retro",!1);E(this,"index",-1);E(this,"zid","");E(this,"options",{});E(this,"skipIndex",0);E(this,"endTime",0);E(this,"next",()=>(this.current=this.ziffers.next(),this.played=!0,this.current));E(this,"pulseToSecond",t=>this.app.clock.convertPulseToSecond(t));E(this,"firstRun",()=>this.notStarted());E(this,"atTheBeginning",()=>this.skipIndex===0&&this.ziffers.index<=0);E(this,"origin",()=>this.app.clock.pulses_since_origin+1);E(this,"pulse",()=>this.app.clock.time_position.pulse);E(this,"beat",()=>this.app.clock.time_position.beat);E(this,"nextBeat",()=>this.app.clock.next_beat_in_ticks);E(this,"nextBeatInTicks",()=>this.app.clock.next_beat_in_ticks);E(this,"areWeThereYet",()=>{this.app.clock.pulses_since_origin=this.nextBeatInTicks())&&this.origin()>=this.waitTime,n=this.current&&this.pulseToSecond(this.origin())>=this.pulseToSecond(this.lastCallTime)+this.pulseToSecond(this.current.duration*4*this.app.clock.ppqn)&&this.origin()>=this.waitTime,i=t||n;return this.skipIndex=i?0:this.skipIndex+1,this.index=i?this.index+1:this.index,i&&this.notStarted()&&(this.initCallTime=this.app.clock.pulses_since_origin),this.atTheBeginning()&&(this.startCallTime=this.app.clock.pulses_since_origin),i});E(this,"lead",()=>this.voiceleading());E(this,"invert",t=>(this.atTheBeginning()&&this.ziffers.invert(t),this));E(this,"out",()=>{});this.app=i,this.input=t,this.options=n,this.ziffers=new $G(t,n)}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 n=this.next(),i=this.app.clock.convertPulseToSecond(n.duration*4*this.app.clock.ppqn);if(n instanceof ni){const a=n.getExisting("freq","pitch","key","scale","octave","parsedScale");return n.sound&&(t=n.sound),n.soundIndex&&(a.n=n.soundIndex),a.dur=i,new tg(a,this.app).sound(t||"sine")}else if(n instanceof Na){const a=n.pitches.map(o=>o.getExisting("freq","pitch","key","scale","octave","parsedScale")),s={dur:i};return t&&(s.s=t),new tg(s,this.app).chord(a)}else if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app)}else return qc.createSkipProxy()}midi(t=void 0){if(this.areWeThereYet()){const n=this.next(),i=n.getExisting("note","pitch","bend","key","scale","octave","parsedScale");if(n instanceof ni){n.soundIndex&&(i.channel=n.soundIndex);const a=new ng(i,this.app);return t?a.note(t):a}else{if(n instanceof Jm)return Vc.createRestProxy(n.duration,this.app);if(n instanceof Na){const a=n.midiChord();return new ng(i,this.app).chord(a)}}}else return qc.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}voiceleading(){return this.atTheBeginning()&&this.ziffers.lead(),this}retrograde(){return this.atTheBeginning()&&this.ziffers.retrograde(),this}wait(t){if(this.atTheBeginning()){if(typeof t=="function"){const n=this.app.api.patternCache.get(t.name);return n&&(this.waitTime=n.nextEndTime()),this}this.waitTime=this.origin()+Math.ceil(t*4*this.app.clock.ppqn)}return this}sync(t){if(this.atTheBeginning()&&this.notStarted()){const n=this.app.clock.pulses_since_origin,i=typeof t=="function"?t.name:t;if(n>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 HG=r=>r[0]==="{"&&r[r.length-1]==="}",fo=(r,e)=>{if(HG(r)){const t=JSON.parse(r);return JSON.stringify({...t,...e})}else return JSON.stringify({...e,text:r})},WG=r=>{String.prototype.speak=function(){const e=JSON.parse(this.valueOf());new OR({...e,text:e.text}).speak().then(()=>{}).catch(t=>{console.log("Error speaking:",t)})},String.prototype.rate=function(e){return fo(this.valueOf(),{rate:e})},String.prototype.pitch=function(e){return fo(this.valueOf(),{pitch:e})},String.prototype.lang=function(e){return fo(this.valueOf(),{lang:e})},String.prototype.volume=function(e){return fo(this.valueOf(),{volume:e})},String.prototype.voice=function(e){return fo(this.valueOf(),{voice:e})},String.prototype.z=function(e={}){return r.z(this.valueOf(),e)},String.prototype.z0=function(e={}){return r.z0(this.valueOf(),e)},String.prototype.z1=function(e={}){return r.z1(this.valueOf(),e)},String.prototype.z2=function(e={}){return r.z2(this.valueOf(),e)},String.prototype.z3=function(e={}){return r.z3(this.valueOf(),e)},String.prototype.z4=function(e={}){return r.z4(this.valueOf(),e)},String.prototype.z5=function(e={}){return r.z5(this.valueOf(),e)},String.prototype.z6=function(e={}){return r.z6(this.valueOf(),e)},String.prototype.z7=function(e={}){return r.z7(this.valueOf(),e)},String.prototype.z8=function(e={}){return r.z8(this.valueOf(),e)},String.prototype.z9=function(e={}){return r.z9(this.valueOf(),e)},String.prototype.z10=function(e={}){return r.z10(this.valueOf(),e)},String.prototype.z11=function(e={}){return r.z11(this.valueOf(),e)},String.prototype.z12=function(e={}){return r.z12(this.valueOf(),e)},String.prototype.z13=function(e={}){return r.z13(this.valueOf(),e)},String.prototype.z14=function(e={}){return r.z14(this.valueOf(),e)},String.prototype.z15=function(e={}){return r.z15(this.valueOf(),e)},String.prototype.z16=function(e={}){return r.z16(this.valueOf(),e)},String.prototype.note=function(){try{return parseInt(this.valueOf())}catch{return Ur(this.valueOf())}}};let qh;class OR{constructor(e){E(this,"speak",()=>new Promise((e,t)=>{if(this.options.text){const n=window.speechSynthesis;n.speaking&&n.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=n.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)},n.speaking?(n.cancel(),qh&&clearTimeout(qh),qh=setTimeout(()=>{n.speak(i)},200)):n.speak(i)}else t("No text provided")}));this.options=e}}async function bR(){return Promise.all([jR(),Yi("github:tidalcycles/Dirt-Samples/master").then(()=>h2()),O2(),Yi("github:Bubobubobubobubo/Dough-Fox/main"),Yi("github:Bubobubobubobubo/Dough-Samples/main"),Yi("github:Bubobubobubobubo/Dough-Amiga/main"),Yi("github:Bubobubobubobubo/Dough-Amen/main"),Yi("github:Bubobubobubobubo/Dough-Waveforms/main")])}class XG{constructor(e){E(this,"variables",{});E(this,"codeExamples",{});E(this,"counters",{});E(this,"_drunk",new qG(-100,100,!1));E(this,"randomGen",Math.random);E(this,"currentSeed");E(this,"localSeeds",new Map);E(this,"patternCache",new ag({max:1e3,ttl:1e3*60*5}));E(this,"errorTimeoutID",0);E(this,"printTimeoutID",0);E(this,"MidiConnection");E(this,"scale_aid");E(this,"load");E(this,"_loadUniverseFromInterface",e=>{Dc(this.app,e),xc()});E(this,"_deleteUniverseFromInterface",e=>{delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(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()});E(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=""),this.pause()});E(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,OM(this.app,e)});E(this,"_all_samples",()=>dg.get());E(this,"_reportError",e=>{const n=(a=>{var o;const s=(o=a.stack)==null?void 0:o.split(` +`);if(s&&s.length>1){const l=s[1].match(/:(\d+):/);if(l)return parseInt(l[1],10)}return null})(e),i=n?`${e.message} (Line: ${n})`:e.message;clearTimeout(this.errorTimeoutID),clearTimeout(this.printTimeoutID),this.app.interface.error_line.innerHTML=i,this.app.interface.error_line.style.color="color-red-800",this.app.interface.error_line.classList.remove("hidden"),this.errorTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),2e3)});E(this,"_logMessage",e=>{console.log(e),clearTimeout(this.printTimeoutID),clearTimeout(this.errorTimeoutID),this.app.interface.error_line.innerHTML=e,this.app.interface.error_line.style.color="white",this.app.interface.error_line.classList.remove("hidden"),this.printTimeoutID=setTimeout(()=>this.app.interface.error_line.classList.add("hidden"),4e3)});E(this,"time",()=>this.app.audioContext.currentTime);E(this,"play",()=>{this.app.setButtonHighlighting("play",!0),this.MidiConnection.sendStartMessage(),this.app.clock.start()});E(this,"pause",()=>{this.app.setButtonHighlighting("pause",!0),this.MidiConnection.sendStopMessage(),this.app.clock.pause()});E(this,"stop",()=>{this.app.setButtonHighlighting("stop",!0),this.MidiConnection.sendStopMessage(),this.app.clock.stop()});E(this,"silence",this.stop);E(this,"hush",this.stop);E(this,"warp",e=>{this.app.clock.tick=e,this.app.clock.time_position=this.app.clock.convertTicksToTimeposition(e)});E(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)});E(this,"onmousemove",e=>{this.app._mouseX=e.pageX,this.app._mouseY=e.pageY});E(this,"mouseX",()=>this.app._mouseX);E(this,"mouseY",()=>this.app._mouseY);E(this,"noteX",()=>Math.floor(this.app._mouseX/document.body.clientWidth*127));E(this,"noteY",()=>Math.floor(this.app._mouseY/document.body.clientHeight*127));E(this,"script",(...e)=>{e.forEach(t=>{t>=1&&t<=9&&(E2(this.app,"local",t),Ra(this.app,this.app.universes[this.app.selected_universe].locals[t]))})});E(this,"s",this.script);E(this,"delete_script",e=>{this.app.universes[this.app.selected_universe].locals[e]={candidate:"",committed:"",evaluations:0}});E(this,"cs",this.delete_script);E(this,"copy_script",(e,t)=>{this.app.universes[this.app.selected_universe].locals[t]={...this.app.universes[this.app.selected_universe].locals[e]}});E(this,"cps",this.copy_script);E(this,"copy_universe",(e,t)=>{this.app.universes[t]={...this.app.universes[e]}});E(this,"delete_universe",e=>{this.app.selected_universe===e&&(this.app.selected_universe="Default"),delete this.app.universes[e],this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings),this.app.updateKnownUniversesView()});E(this,"big_bang",()=>{confirm("Are you sure you want to delete all universes?")&&(this.app.universes={...Xo},this.app.settings.saveApplicationToLocalStorage(this.app.universes,this.app.settings)),this.app.selected_universe="Default",this.app.updateKnownUniversesView()});E(this,"midi_outputs",()=>{this._logMessage(this.MidiConnection.listMidiOutputs())});E(this,"midi_output",e=>{e?this.MidiConnection.switchMidiOutput(e):console.log(this.MidiConnection.getCurrentMidiPort())});E(this,"midi",(e=60,t,n)=>(t!==void 0&&(typeof e=="number"&&(e={note:e}),e.velocity=t),n!==void 0&&(typeof e=="number"&&(e={note:e}),e.channel=n),new ng(e,this.app)));E(this,"sysex",e=>{this.MidiConnection.sendSysExMessage(e)});E(this,"pitch_bend",(e,t)=>{this.MidiConnection.sendPitchBend(e,t)});E(this,"program_change",(e,t)=>{this.MidiConnection.sendProgramChange(e,t)});E(this,"midi_clock",()=>{this.MidiConnection.sendMidiClock()});E(this,"control_change",({control:e=20,value:t=0,channel:n=0})=>{this.MidiConnection.sendMidiControlChange(e,t,n)});E(this,"midi_panic",()=>{this.MidiConnection.panic()});E(this,"active_note_events",e=>{let t;if(e?t=this.MidiConnection.activeNotesFromChannel(e):t=this.MidiConnection.activeNotes,t.length>0)return t});E(this,"active_notes",e=>{const t=this.active_note_events(e);if(t&&t.length>0)return t.map(n=>n.note)});E(this,"kill_active_notes",()=>{this.MidiConnection.activeNotes=[]});E(this,"sticky_notes",e=>{let t;if(e?t=this.MidiConnection.stickyNotesFromChannel(e):t=this.MidiConnection.stickyNotes,t.length>0)return t.map(n=>n.note)});E(this,"kill_sticky_notes",()=>{this.MidiConnection.stickyNotes=[]});E(this,"buffer",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e)!==void 0:this.MidiConnection.noteInputBuffer.length>0);E(this,"buffer_event",e=>e?this.MidiConnection.findNoteFromBufferInChannel(e):this.MidiConnection.noteInputBuffer.shift());E(this,"buffer_note",e=>{const t=this.buffer_event(e);return t?t.note:void 0});E(this,"last_note_event",e=>e?this.MidiConnection.lastNoteInChannel[e]:this.MidiConnection.lastNote);E(this,"last_note",e=>{const t=this.last_note_event(e);return t?t.note:60});E(this,"last_cc",(e,t)=>t?this.MidiConnection.lastCCInChannel[t]?this.MidiConnection.lastCCInChannel[t][e]:0:this.MidiConnection.lastCC[e]||0);E(this,"has_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e)!==void 0:this.MidiConnection.ccInputBuffer.length>0);E(this,"buffer_cc",e=>e?this.MidiConnection.findCCFromBufferInChannel(e):this.MidiConnection.ccInputBuffer.shift());E(this,"show_scale",(e,t,n=0,i=this.MidiConnection.currentOutputIndex||0,a=!1)=>{(!this.scale_aid||t!==this.scale_aid)&&(this.hide_scale(e,t,n,i),NG(t,e).forEach(o=>{this.MidiConnection.sendMidiOn(o,n,1,i),a&&this.MidiConnection.sendAllSoundOff(n,i)}),this.scale_aid=t)});E(this,"hide_scale",(e=0,t=0,n=0,i=this.MidiConnection.currentOutputIndex||0)=>{Array.from(Array(128).keys()).forEach(s=>{this.MidiConnection.sendMidiOff(s,n,i)}),this.scale_aid=void 0});E(this,"midi_notes_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllNotesOff(e,t)});E(this,"midi_sound_off",(e=0,t=this.MidiConnection.currentOutputIndex||0)=>{this.MidiConnection.sendAllSoundOff(e,t)});E(this,"generateCacheKey",(...e)=>e.map(t=>JSON.stringify(t)).join(","));E(this,"z",(e,t={},n="")=>{const i="z"+n.toString(),a=n===""?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 zG(e,t,this.app),this.app.api.patternCache.set(a,s)),typeof n=="number"&&(s.zid=i),s.updateLastCallTime(),n!==""&&s.sync("z0"),s});E(this,"z0",(e,t={})=>this.z(e,t,0));E(this,"z1",(e,t={})=>this.z(e,t,1));E(this,"z2",(e,t={})=>this.z(e,t,2));E(this,"z3",(e,t={})=>this.z(e,t,3));E(this,"z4",(e,t={})=>this.z(e,t,4));E(this,"z5",(e,t={})=>this.z(e,t,5));E(this,"z6",(e,t={})=>this.z(e,t,6));E(this,"z7",(e,t={})=>this.z(e,t,7));E(this,"z8",(e,t={})=>this.z(e,t,8));E(this,"z9",(e,t={})=>this.z(e,t,9));E(this,"z10",(e,t={})=>this.z(e,t,10));E(this,"z11",(e,t={})=>this.z(e,t,11));E(this,"z12",(e,t={})=>this.z(e,t,12));E(this,"z13",(e,t={})=>this.z(e,t,13));E(this,"z14",(e,t={})=>this.z(e,t,14));E(this,"z15",(e,t={})=>this.z(e,t,15));E(this,"z16",(e,t={})=>this.z(e,t,16));E(this,"counter",(e,t,n)=>(e in this.counters?(this.counters[e].limit!==t&&(this.counters[e].value=0,this.counters[e].limit=t),this.counters[e].step!==n&&(this.counters[e].step=n??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:n??1,limit:t},this.counters[e].value));E(this,"$",this.counter);E(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);E(this,"drunk",e=>e!==void 0?(this._drunk.position=e,this._drunk.getPosition()):(this._drunk.step(),this._drunk.getPosition()));E(this,"drunk_max",e=>{this._drunk.max=e});E(this,"drunk_min",e=>{this._drunk.min=e});E(this,"drunk_wrap",e=>{this._drunk.toggleWrap(e)});E(this,"variable",(e,t)=>typeof e=="string"&&t===void 0?this.variables[e]:(this.variables[e]=t,this.variables[e]));E(this,"v",this.variable);E(this,"delete_variable",e=>{delete this.variables[e]});E(this,"dv",this.delete_variable);E(this,"clear_variables",()=>{this.variables={}});E(this,"cv",this.clear_variables);E(this,"randI",(e,t)=>Math.floor(this.randomGen()*(t-e+1))+e);E(this,"rand",(e,t)=>this.randomGen()*(t-e)+e);E(this,"irand",this.randI);E(this,"rI",this.randI);E(this,"r",this.rand);E(this,"ir",this.randI);E(this,"seed",e=>{typeof e=="number"&&(e=e.toString()),this.currentSeed!==e&&(this.currentSeed=e,this.randomGen=jm(e))});E(this,"localSeededRandom",e=>{if(typeof e=="number"&&(e=e.toString()),this.localSeeds.has(e))return this.localSeeds.get(e);const t=jm(e);return this.localSeeds.set(e,t),t});E(this,"clearLocalSeed",(e=void 0)=>{e&&this.localSeeds.delete(e.toString()),this.localSeeds.clear()});E(this,"quantize",(e,t)=>{if(t.length===0)return e;let n=t[0];return t.forEach(i=>{Math.abs(i-e)Math.min(Math.max(e,t),n));E(this,"cmp",this.clamp);E(this,"nudge",e=>(e&&(this.app.clock.nudge=e),this.app.clock.nudge));E(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));E(this,"tempo",this.bpm);E(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));E(this,"ppqn",e=>e===void 0?this.app.clock.ppqn:(e<1&&console.log(`Setting ppqn to ${e}`),this.app.clock.ppqn=e,e));E(this,"time_signature",(e,t)=>{this.app.clock.time_signature=[e,t]});E(this,"prob",e=>this.randomGen()*100this.randomGen()>.5);E(this,"odds",(e,t=1)=>this.randomGen()!1);E(this,"almostNever",(e=1)=>this.randomGen()<.025*this.ppqn()/(this.ppqn()*e));E(this,"rarely",(e=1)=>this.randomGen()<.1*this.ppqn()/(this.ppqn()*e));E(this,"scarcely",(e=1)=>this.randomGen()<.25*this.ppqn()/(this.ppqn()*e));E(this,"sometimes",(e=1)=>this.randomGen()<.5*this.ppqn()/(this.ppqn()*e));E(this,"often",(e=1)=>this.randomGen()<.75*this.ppqn()/(this.ppqn()*e));E(this,"frequently",(e=1)=>this.randomGen()<.9*this.ppqn()/(this.ppqn()*e));E(this,"almostAlways",(e=1)=>this.randomGen()<.985*this.ppqn()/(this.ppqn()*e));E(this,"always",(e=1)=>!0);E(this,"dice",e=>Math.floor(this.randomGen()*e)+1);E(this,"cbar",()=>this.app.clock.time_position.bar+1);E(this,"ctick",()=>this.app.clock.tick+1);E(this,"cpulse",()=>this.app.clock.time_position.pulse+1);E(this,"cbeat",()=>this.app.clock.time_position.beat+1);E(this,"ebeat",()=>this.app.clock.beats_since_origin+1);E(this,"epulse",()=>this.app.clock.pulses_since_origin+1);E(this,"nominator",()=>this.app.clock.time_signature[0]);E(this,"meter",()=>this.app.clock.time_signature[1]);E(this,"denominator",this.meter);E(this,"fill",()=>this.app.fill);E(this,"fullseq",(e,t)=>e.split("").every(n=>n==="x"||n==="o")?[...e].map(n=>n==="x").beat(t):!1);E(this,"seq",(e,t=.5)=>{let n=e.length*t,i=[];for(let a=1;a<=n+1;a+=t)i.push(Math.floor(a*10)/10);return i.pop(),i=i.filter((a,s)=>{const o=s%e.length;return e[o]==="x"}),this.oncount(i,n)});E(this,"beat",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-Math.floor(t*this.ppqn()))%Math.floor(a*this.ppqn())===0).some(a=>a===!0));E(this,"b",this.beat);E(this,"bar",(e=1,t=0)=>{const n=Array.isArray(e)?e:[e],i=this.app.clock.time_signature[1]*this.ppqn(),a=Math.floor(t*i);return n.map(o=>(this.app.clock.pulses_since_origin-a)%Math.floor(o*i)===0).some(o=>o===!0)});E(this,"B",this.bar);E(this,"pulse",(e=1,t=0)=>(Array.isArray(e)?e:[e]).map(a=>(this.app.clock.pulses_since_origin-t)%a===0).some(a=>a===!0));E(this,"p",this.pulse);E(this,"tick",(e,t=0)=>(Array.isArray(e)?e:[e]).map(a=>this.app.clock.time_position.pulse===a+t).some(a=>a===!0));E(this,"flip",(e,t=50)=>{let n=e*2;const i=this.app.clock.pulses_since_origin,a=Math.floor(n*this.ppqn()),s=Math.floor(t/100*a);return i%a{let t=e*2;const n=this.app.clock.time_position.bar;return Math.floor(n/t)%2===0});E(this,"onbar",(e,t=this.app.clock.time_signature[0])=>{let n=this.app.clock.time_position.bar%t+1;return typeof e=="number"?e===n:e.some(i=>i==n)});E(this,"onbeat",(...e)=>{let t=[];return e.forEach(n=>{let i=n%this.nominator()||this.nominator(),a=Math.floor(i);a=a==0?this.nominator():a;let s=Math.floor((i-a)*this.ppqn()+1);s<=0&&(s=s+this.ppqn()*this.nominator()),t.push(a===this.cbeat()&&this.cpulse()===s)}),t.some(n=>n==!0)});E(this,"oncount",(e,t)=>{typeof e=="number"&&(e=[e]);const n=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=n%(this.ppqn()*t);return i.push(o===s)}),i.some(a=>a==!0)});E(this,"oneuclid",(e,t,n=0)=>{const a=this._euclidean_cycle(e,t,n).reduce((s,o,l)=>(o&&s.push(l+1),s),[]);return this.oncount(a,t)});E(this,"delay",(e,t)=>{setTimeout(t,e)});E(this,"delayr",(e,t,n)=>{[...Array(t).keys()].map(a=>e*a).forEach((a,s)=>{setTimeout(n,a)})});E(this,"euclid",(e,t,n,i=0)=>this._euclidean_cycle(t,n,i)[e%n]);E(this,"ec",this.euclid);E(this,"rhythm",(e,t,n,i=0)=>this.beat(e)&&this._euclidean_cycle(t,n,i).beat(e));E(this,"bin",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return i[e%i.length]});E(this,"binrhythm",(e,t)=>{let i=t.toString(2).split("").map(a=>a==="1");return this.beat(e)&&i.beat(e)});E(this,"line",(e,t,n=1)=>{const i=[];if(t>e&&n>0||t(Math.sin(this.app.clock.ctx.currentTime*Math.PI*2*e)+n)*t);E(this,"usine",(e=1,t=1,n=0)=>(this.sine(e,t,n)+1)/2*t);E(this,"saw",(e=1,t=1,n=0)=>(this.app.clock.ctx.currentTime*e%1*2-1+n)*t);E(this,"usaw",(e=1,t=1,n=0)=>(this.saw(e,t,n)+1)/2*t);E(this,"triangle",(e=1,t=1,n=0)=>(Math.abs(this.saw(e,t,n))*2-1)*t);E(this,"utriangle",(e=1,t=1,n=0)=>(this.triangle(e,t,n)+1)/2*t);E(this,"square",(e=1,t=1,n=0,i=.5)=>{const a=1/e;return((Date.now()/1e3+n)%a/a(this.square(e,t,n,i)+1)/2*t);E(this,"noise",(e=1)=>(this.randomGen()*2-1)*e);E(this,"min",(...e)=>Math.min(...e));E(this,"max",(...e)=>Math.max(...e));E(this,"mean",(...e)=>e.reduce((n,i)=>n+i,0)/e.length);E(this,"range",(e,t,n,i,a)=>(e-t)/(n-t)*(a-i)+i);E(this,"limit",(e,t,n)=>Math.min(Math.max(e,t),n));E(this,"abs",Math.abs);E(this,"speak",(e,t="en-US",n=0,i=1,a=1)=>{new OR({text:e,lang:t,voice:n,rate:i,pitch:a}).speak().then(()=>{}).catch(o=>{console.log(o)})});E(this,"stop_hydra",()=>{this.app.hydra.hush()});E(this,"sound",e=>new tg(e,this.app));E(this,"snd",this.sound);E(this,"samples",Yi);E(this,"log",e=>{console.log(e),this._logMessage(e)});E(this,"scale",T_);E(this,"rate",e=>{});E(this,"divseq",(...e)=>{const t=e[0],n=e.slice(1),i=this.app.clock.pulses_since_origin,a=Math.floor(i/Math.floor(t*this.ppqn()));return n[a%n.length]});E(this,"seqbeat",(...e)=>e[this.app.clock.time_position.beat%e.length]);E(this,"seqbar",(...e)=>e[(this.app.clock.time_position.bar+1)%e.length]);E(this,"shuffle",e=>e.sort(()=>this.randomGen()-.5));E(this,"reverse",e=>e.reverse());E(this,"rotate",e=>t=>t.slice(e,t.length).concat(t.slice(0,e)));E(this,"repeat",e=>t=>t.flatMap(n=>Array(e).fill(n)));E(this,"repeatOdd",e=>t=>t.flatMap((n,i)=>i%2===0?Array(e).fill(n):n));E(this,"repeatEven",e=>t=>t.flatMap((n,i)=>i%2!==0?Array(e).fill(n):n));E(this,"palindrome",e=>e.concat(e.slice(0,e.length-1).reverse()));E(this,"scope",e=>{this.app.osc={...this.app.osc,...e}});this.app=e,this.MidiConnection=new QG(this,e.settings)}transmission(){return this.MidiConnection.activeNotes.length>0}_euclidean_cycle(e,t,n=0){if(e==t)return Array.from({length:t},()=>!0);function i(o,l){const c=o.length,u=(l+1)%c;return o[l]>o[u]}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 n!=0&&(s=s.slice(n).concat(s.slice(0,n))),s}}const ZG=r=>{Array.prototype.mouseX=function(){const e=r.mouseX(),n=window.innerWidth/this.length,i=Math.floor(e/n);return this[i]},Array.prototype.mouseY=function(){const e=r.mouseY(),n=window.innerHeight/this.length,i=Math.floor(e/n);return this[i]},Array.prototype.square=function(){return this.map(e=>e*e)},Array.prototype.sometimes=function(e){return r.randomGen()<.5?e(this):this},Array.prototype.apply=function(e){return e(this)},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.div=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(r.randomGen()*this.length)]},Array.prototype.gen=function(e,t,n){return n<1?[]:Array.from({length:n},()=>Math.floor(r.randomGen()*(t-e+1))+e)},Array.prototype.bar=function(e=1){return e===1?this[r.app.clock.time_position.bar%this.length]:this[Math.floor(r.app.clock.time_position.bar/e)%this.length]},Array.prototype.beat=function(e=1){const t=e,n=r.app.clock.pulses_since_origin,i=Math.floor(n/Math.floor(t*r.ppqn()));return this[i%this.length]},Array.prototype.b=Array.prototype.beat,Array.prototype.shuffle=function(){let e=this.length,t;for(;e!==0;)t=Math.floor(r.randomGen()*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 n=this.splice(-e,e);return this.unshift(...n),this},Array.prototype.unique=function(){const e=new Set;let t=0;for(let n=0;n100)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.repeat=function(e=1){if(e<1)throw new Error("Amount should be at least 1");let t=[];for(let n=0;n(i%a+a)%a,n=cR(Ds(r));return this.map(i=>{const a=Math.floor(i/n.length)*12;return n[t(i,n.length)]+e+a})};Array.prototype.scaleArp=function(r="major",e=0){const t=cR(Ds(r));let n=[];e=e>t.length?t.length:e,e=e==0?t.length:e;for(let i=0;i{r.interface.line_numbers_checkbox.checked=r.settings.line_numbers,r.interface.time_position_checkbox.checked=r.settings.time_position,r.interface.tips_checkbox.checked=r.settings.tips,r.interface.midi_clock_checkbox.checked=r.settings.send_clock,r.interface.midi_channels_scripts.checked=r.settings.midi_channels_scripts,r.interface.midi_clock_ppqn.value=r.settings.midi_clock_ppqn.toString(),r.settings.time_position||r.interface.timeviewer.classList.add("hidden"),r.interface.load_demo_songs.checked=r.settings.load_demo_songs;const e=document.querySelectorAll('[id^="tab-"]');for(let t=0;t{e[t].classList.add("bg-orange-300");for(let s=0;s{hi(),r.updateKnownUniversesView(),xc()}),r.buttonElements.play_buttons.forEach(t=>{t.addEventListener("click",()=>{r.isPlaying?(r.setButtonHighlighting("pause",!0),r.isPlaying=!r.isPlaying,r.clock.pause(),r.api.MidiConnection.sendStopMessage()):(r.setButtonHighlighting("play",!0),r.isPlaying=!r.isPlaying,r.clock.start(),r.api.MidiConnection.sendStartMessage())})}),r.buttonElements.clear_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("clear",!0),confirm("Do you want to reset the current universe?")&&(r.universes[r.selected_universe]=structuredClone(t_),r.updateEditorView())})}),r.interface.documentation_button.addEventListener("click",()=>{XI(r)}),r.interface.destroy_universes_button.addEventListener("click",()=>{confirm("Do you want to destroy all universes?")&&(r.universes={...Xo},r.updateKnownUniversesView())}),r.interface.audio_nudge_range.addEventListener("input",()=>{r.clock.nudge=parseInt(r.interface.audio_nudge_range.value)}),r.interface.dough_nudge_range.addEventListener("input",()=>{r.dough_nudge=parseInt(r.interface.dough_nudge_range.value)}),r.interface.upload_universe_button.addEventListener("click",()=>{const t=document.createElement("input");t.type="file",t.accept=".json",t.addEventListener("change",n=>{var s;const a=(s=n.target.files)==null?void 0:s[0];if(a){const o=new FileReader;o.readAsText(a,"UTF-8"),o.onload=l=>{const c=JSON.parse(l.target.result);for(const[u,p]of Object.entries(c))r.universes[u]=p},o.onerror=l=>{console.error("An error occurred reading the file:",l)}}}),document.body.appendChild(t),t.click(),document.body.removeChild(t)}),r.interface.download_universe_button.addEventListener("click",()=>{r.settings.saveApplicationToLocalStorage(r.universes,r.settings);let t=`topos-universes-${Date.now()}.json`;const n=new Blob([JSON.stringify(r.settings.universes)],{type:"application/json"}),i=URL.createObjectURL(n),a=document.createElement("a");a.href=i,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}),r.interface.load_universe_button.addEventListener("click",()=>{let t=r.interface.buffer_search.value;t.length>2&&t.length<20&&!t.includes(" ")&&(Dc(r,t),r.settings.selected_universe=t,r.interface.buffer_search.value="",Vm(),r.view.focus(),FA())}),r.interface.eval_button.addEventListener("click",()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.flashBackground("#404040",200)}),r.buttonElements.stop_buttons.forEach(t=>{t.addEventListener("click",()=>{r.setButtonHighlighting("stop",!0),r.isPlaying=!1,r.clock.stop()})}),r.interface.local_button.addEventListener("click",()=>r.changeModeFromInterface("local")),r.interface.global_button.addEventListener("click",()=>r.changeModeFromInterface("global")),r.interface.init_button.addEventListener("click",()=>r.changeModeFromInterface("init")),r.interface.note_button.addEventListener("click",()=>r.changeModeFromInterface("notes")),r.interface.font_family_selector.addEventListener("change",()=>{let t=r.interface.font_family_selector.value;console.log("Picking new font : "+t),r.settings.font=t,r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:t,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.font_size_input.addEventListener("input",()=>{let t=r.interface.font_size_input.value;r.settings.font_size=parseInt(t),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.settings_button.addEventListener("click",()=>{const t=document.getElementById("font-family");t&&(t.value=r.settings.font);const n=r.interface.dough_nudge_range;n.value=r.dough_nudge.toString();const i=document.getElementById("doughnumber");i.value=r.dough_nudge.toString(),r.settings.font_size===null&&(r.settings.font_size=12);const a=r.interface.font_size_input;a.value=r.settings.font_size.toString();const s=r.interface.line_numbers_checkbox;s.checked=r.settings.line_numbers;const o=r.interface.time_position_checkbox;o.checked=r.settings.time_position;const l=r.interface.tips_checkbox;l.checked=r.settings.tips;const c=r.interface.midi_clock_checkbox;c.checked=r.settings.send_clock;const u=r.interface.midi_channels_scripts;u.checked=r.settings.midi_channels_scripts;const p=r.interface.midi_clock_ppqn;p.value=r.settings.midi_clock_ppqn.toString();const m=r.interface.load_demo_songs;m.checked=r.settings.load_demo_songs;const _=r.interface.vim_mode_checkbox;_.checked=r.settings.vimMode;let v=document.getElementById("modal-settings"),I=document.getElementById("editor");v==null||v.classList.remove("invisible"),I==null||I.classList.add("invisible")}),r.interface.close_settings_button.addEventListener("click",()=>{let t=document.getElementById("modal-settings"),n=document.getElementById("editor");t==null||t.classList.add("invisible"),n==null||n.classList.remove("invisible");let i=r.interface.font_size_input.value;r.settings.font_size=parseInt(i),r.view.dispatch({effects:r.fontSize.reconfigure(Me.theme({"&":{fontSize:r.settings.font_size+"px"},".cm-content":{fontFamily:r.settings.font,fontSize:r.settings.font_size+"px"},".cm-gutters":{fontSize:r.settings.font_size+"px"}}))})}),r.interface.close_universes_button.addEventListener("click",()=>{xc()}),r.interface.share_button.addEventListener("click",async()=>{r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),await vM(r)}),r.interface.vim_mode_checkbox.addEventListener("change",()=>{let t=!!r.interface.vim_mode_checkbox.checked;r.settings.vimMode=t,r.view.dispatch({effects:r.vimModeCompartment.reconfigure(t?f_():[])})}),r.interface.line_numbers_checkbox.addEventListener("change",()=>{let n=!!r.interface.line_numbers_checkbox.checked;r.settings.line_numbers=n,r.view.dispatch({effects:r.withLineNumbers.reconfigure(n?[ey()]:[])})}),r.interface.time_position_checkbox.addEventListener("change",()=>{let t=document.getElementById("timeviewer"),n=!!r.interface.time_position_checkbox.checked;r.settings.time_position=n,n?t.classList.remove("hidden"):t.classList.add("hidden")}),r.interface.tips_checkbox.addEventListener("change",()=>{let t=!!r.interface.tips_checkbox.checked;r.settings.tips=t,r.view.dispatch({effects:r.hoveringCompartment.reconfigure(t?rR:[])})}),r.interface.midi_clock_checkbox.addEventListener("change",()=>{let t=!!r.interface.midi_clock_checkbox.checked;r.settings.send_clock=t}),r.interface.midi_channels_scripts.addEventListener("change",()=>{let t=!!r.interface.midi_channels_scripts.checked;r.settings.midi_channels_scripts=t}),r.interface.midi_clock_ppqn.addEventListener("change",()=>{let t=parseInt(r.interface.midi_clock_ppqn.value);r.settings.midi_clock_ppqn=t}),r.interface.load_demo_songs.addEventListener("change",()=>{let t=!!r.interface.load_demo_songs.checked;r.settings.load_demo_songs=t}),r.interface.universe_creator.addEventListener("submit",t=>{t.preventDefault();let i=new FormData(r.interface.universe_creator).get("universe");i&&i.length>2&&i.length<20&&(Dc(r,i),r.settings.selected_universe=i,r.interface.buffer_search.value="",Vm(),r.view.focus())}),Ra(r,r.universes[r.selected_universe.toString()].init),["introduction","interface","interaction","code","time","sound","samples","synths","chaining","patterns","ziffers","midi","functions","lfos","probabilities","variables","shortcuts","about","bonus","oscilloscope"].forEach(t=>{let n="docs_"+t;document.getElementById(n).addEventListener("click",async()=>{n!=="docs_samples"?(r.currentDocumentationPane=t,Km(r)):(console.log("Loading samples!"),await bR().then(()=>{r.docs=WI(r),r.currentDocumentationPane=t,Km(r)}))})})},ST=r=>{if(!r)return;r.width=window.innerWidth,r.height=window.innerHeight;const e=r.getContext("2d"),t=window.devicePixelRatio||1;r.width=window.innerWidth*t,r.height=window.innerHeight*t,e&&e.scale(t,t)},jG=(r,e,t=!1)=>{e.addEventListener("resize",()=>ST(r.interface.scope)),e.addEventListener("resize",()=>ST(r.interface.feedback)),e.addEventListener("beforeunload",()=>(event.preventDefault(),r.currentFile().candidate=r.view.state.doc.toString(),r.currentFile().committed=r.view.state.doc.toString(),r.settings.saveApplicationToLocalStorage(r.universes,r.settings),r.clock.stop(),null)),t&&(localStorage.openpages=Date.now(),e.addEventListener("storage",function(n){n.key=="openpages"&&(localStorage.page_available=Date.now()),n.key=="page_available"&&(document.getElementById("all").classList.add("invisible"),alert("Topos is already opened in another tab. Close this tab now to prevent data loss."))},!1)),e.addEventListener("error",n=>{console.log("Je suis bien installé !"),console.log(n.message,` +`,n.filename,":",n.lineno,n.colno?":"+n.colno:"",n.error&&n.error.stack?` +`:"",n.error?n.error.stack:void 0)},!1)};class JG{constructor(){E(this,"settings",new bM);E(this,"universes",Xo);E(this,"selected_universe","Welcome");E(this,"fill",!1);E(this,"local_index",1);E(this,"editor_mode","global");E(this,"fontSize");E(this,"withLineNumbers");E(this,"vimModeCompartment");E(this,"hoveringCompartment");E(this,"chosenLanguage");E(this,"dynamicPlugins");E(this,"currentDocumentationPane","introduction");E(this,"exampleCounter",0);E(this,"exampleIsPlaying",!1);E(this,"editorExtensions",[]);E(this,"userPlugins",[]);E(this,"state");E(this,"view");E(this,"selectedExample","");E(this,"docs",{});E(this,"_mouseX",0);E(this,"_mouseY",0);E(this,"show_error",!1);E(this,"buttonElements",{});E(this,"interface",{});E(this,"blinkTimeouts",{});E(this,"osc",{enabled:!1,color:"#fdba74",thickness:4,refresh:1,fftSize:256,orientation:"horizontal",is3D:!1,size:1});E(this,"api");E(this,"audioContext");E(this,"clock");E(this,"dough_nudge",20);E(this,"manualPlay",!1);E(this,"isPlaying",!1);E(this,"hydra_backend");E(this,"hydra");E(this,"updateKnownUniversesView",()=>{let e=document.getElementById("ui-known-universe-item-template");if(!e){console.warn("Missing template #ui-known-universe-item-template");return}let t=document.getElementById("existing-universes");if(!t){console.warn("Missing element #existing-universes");return}let n=document.createElement("ul");n.className="lg:h-80 lg:text-normal text-sm h-auto lg:w-80 w-auto lg:pb-2 lg:pt-2 overflow-y-scroll text-white lg:mb-4 border rounded-lg bg-neutral-800",n.append(...Object.keys(this.universes).map(i=>{var o,l;let a=e.content.cloneNode(!0),s=window;return a.querySelector(".universe-name").textContent=i,(o=a.querySelector(".load-universe"))==null||o.addEventListener("click",()=>s._loadUniverseFromInterface(i)),(l=a.querySelector(".delete-universe"))==null||l.addEventListener("click",()=>s._deleteUniverseFromInterface(i)),a})),t.innerHTML="",t.append(n)});this.initializeElements(),this.initializeButtonGroups(),this.initializeHydra(),this.setCanvas(this.interface.feedback),this.setCanvas(this.interface.scope),this.universes={...this.settings.universes,...Xo},EM(this),this.audioContext=new AudioContext({latencyHint:"playback"}),this.clock=new j$(this,this.audioContext),this.api=new XG(this),ZG(this.api),WG(this.api),Object.entries(this.api).forEach(([t,n])=>{globalThis[t]=n}),(async()=>{await bR()})(),this.docs=WI(this),T$(this),C$(this),KG(this),TT(this),X$(this),v2(this.interface.scope,this),Ra(this,this.universes[this.selected_universe.toString()].init),this.changeModeFromInterface("global"),TM(this)}getBuffer(e){const t=this.universes[this.selected_universe.toString()];return e==="locals"?t[e][this.local_index]:t[e]}get note_buffer(){return this.getBuffer("notes")}get example_buffer(){return this.getBuffer("example")}get global_buffer(){return this.getBuffer("global")}get init_buffer(){return this.getBuffer("init")}get local_buffer(){return this.getBuffer("locals")}changeToLocalBuffer(e){const t=document.querySelectorAll('[id^="tab-"]'),n=t[e];n.classList.add("bg-orange-300");for(let a=0;a{t.forEach(a=>{let s=a.children[0];s.classList.contains("text-orange-300")&&(s.classList.remove("text-orange-300"),a.classList.remove("text-orange-300"))}),i.children[0].classList.remove("text-white"),i.children[0].classList.add("text-orange-300"),i.classList.add("text-orange-300"),i.classList.add("fill-orange-300")};switch(e){case"local":this.interface.local_script_tabs.classList.contains("hidden")&&this.interface.local_script_tabs.classList.remove("hidden"),this.editor_mode="local",this.local_index=0,document.getElementById("editor").style.height="calc(100% - 100px)",this.changeToLocalBuffer(this.local_index),n(this.interface.local_button);break;case"global":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="global",document.getElementById("editor").style.height="100%",n(this.interface.global_button);break;case"init":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="init",n(this.interface.init_button);break;case"notes":this.interface.local_script_tabs.classList.contains("hidden")||this.interface.local_script_tabs.classList.add("hidden"),this.editor_mode="notes",n(this.interface.note_button);break}this.view.dispatch({effects:this.chosenLanguage.reconfigure(this.editor_mode=="notes"?[BL()]:[Gg()])}),this.updateEditorView()}setButtonHighlighting(e,t){document.getElementById("play-label").textContent=e!=="pause"?"Pause":"Play",e!=="pause"?(document.getElementById("pause-icon").classList.remove("hidden"),document.getElementById("play-icon").classList.add("hidden")):(document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),e==="stop"&&(this.isPlaying==!1,document.getElementById("play-label").textContent="Play",document.getElementById("pause-icon").classList.add("hidden"),document.getElementById("play-icon").classList.remove("hidden")),this.flashBackground("#404040",200);const n=['[id^="play-button-"]','[id^="clear-button-"]','[id^="stop-button-"]'];let i;switch(e){case"play":i=0;break;case"pause":i=1;break;case"clear":i=2;break;case"stop":i=3;break}document.querySelectorAll(n[i]).forEach(a=>{t&&a.children[0].classList.add("animate-pulse")}),document.querySelectorAll(n.filter((a,s)=>s!=i).join(",")).forEach(a=>{a.children[0].classList.remove("animate-pulse"),a.children[1].classList.remove("animate-pulse")})}unfocusPlayButtons(){document.querySelectorAll('[id^="play-button-"]').forEach(e=>{e.children[0].classList.remove("fill-orange-300"),e.children[0].classList.remove("animate-pulse")})}updateEditorView(){this.view.dispatch({changes:{from:0,to:this.view.state.doc.toString().length,insert:this.currentFile().candidate}})}currentFile(){switch(this.editor_mode){case"global":return this.global_buffer;case"local":return this.local_buffer;case"init":return this.init_buffer;case"notes":return this.note_buffer}}flashBackground(e,t){const n=this.view.dom,i=n.getElementsByClassName("cm-gutter");n.classList.add("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.add("fluid-bg-transition")),n.style.backgroundColor=e,Array.from(i).forEach(a=>a.style.backgroundColor=e),setTimeout(()=>{n.style.backgroundColor="",Array.from(i).forEach(a=>a.style.backgroundColor=""),n.classList.remove("fluid-bg-transition"),Array.from(i).forEach(a=>a.classList.remove("fluid-bg-transition"))},t)}initializeElements(){for(const[e,t]of Object.entries(AM))this.interface[e]=document.getElementById(t)}initializeButtonGroups(){for(const[e,t]of Object.entries(IM))this.buttonElements[e]=t.map(n=>document.getElementById(n))}initializeHydra(){this.hydra_backend=new Hydra({canvas:this.interface.hydra_canvas,detectAudio:!1,enableStreamCapture:!1}),this.hydra=this.hydra_backend.synth}setCanvas(e){if(!e)return;const t=e.getContext("2d"),n=window.devicePixelRatio||1;e.width=window.innerWidth*n,e.height=window.innerHeight*n,t&&t.scale(n,n)}}let e5=new JG;jG(e5,window,!1); diff --git a/index.html b/index.html index dabd377..97ae981 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - +