@opendaw/studio-core 0.0.59 → 0.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/AudioOfflineRenderer.d.ts +2 -2
  2. package/dist/AudioOfflineRenderer.d.ts.map +1 -1
  3. package/dist/AudioOfflineRenderer.js +9 -9
  4. package/dist/AudioUtils.d.ts +4 -0
  5. package/dist/AudioUtils.d.ts.map +1 -0
  6. package/dist/AudioUtils.js +20 -0
  7. package/dist/EffectBox.d.ts +2 -2
  8. package/dist/EffectBox.d.ts.map +1 -1
  9. package/dist/EffectFactories.d.ts +3 -0
  10. package/dist/EffectFactories.d.ts.map +1 -1
  11. package/dist/EffectFactories.js +17 -3
  12. package/dist/Engine.d.ts +1 -1
  13. package/dist/Engine.d.ts.map +1 -1
  14. package/dist/EngineFacade.d.ts +1 -1
  15. package/dist/EngineFacade.d.ts.map +1 -1
  16. package/dist/EngineFacade.js +1 -1
  17. package/dist/EngineWorklet.d.ts.map +1 -1
  18. package/dist/EngineWorklet.js +7 -8
  19. package/dist/FilePickerAcceptTypes.d.ts.map +1 -1
  20. package/dist/Preferences.d.ts +4 -0
  21. package/dist/Preferences.d.ts.map +1 -1
  22. package/dist/Preferences.js +2 -0
  23. package/dist/RecordingWorklet.d.ts +2 -1
  24. package/dist/RecordingWorklet.d.ts.map +1 -1
  25. package/dist/WavFile.d.ts +4 -7
  26. package/dist/WavFile.d.ts.map +1 -1
  27. package/dist/WavFile.js +22 -21
  28. package/dist/Workers.d.ts +2 -0
  29. package/dist/Workers.d.ts.map +1 -1
  30. package/dist/Workers.js +11 -0
  31. package/dist/capture/CaptureAudio.d.ts.map +1 -1
  32. package/dist/capture/CaptureAudio.js +0 -2
  33. package/dist/capture/RecordAudio.d.ts.map +1 -1
  34. package/dist/capture/RecordAudio.js +3 -1
  35. package/dist/cloud/CloudBackupProjects.js +4 -4
  36. package/dist/cloud/CloudBackupSamples.d.ts.map +1 -1
  37. package/dist/cloud/CloudBackupSamples.js +3 -9
  38. package/dist/cloud/CloudBackupSoundfonts.js +1 -1
  39. package/dist/dawproject/DawProjectExporter.d.ts.map +1 -1
  40. package/dist/dawproject/DawProjectExporter.js +2 -12
  41. package/dist/dawproject/DawProjectImporter.d.ts.map +1 -1
  42. package/dist/dawproject/DawProjectImporter.js +5 -3
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1 -0
  46. package/dist/midi/MIDIReceiver.d.ts +12 -0
  47. package/dist/midi/MIDIReceiver.d.ts.map +1 -0
  48. package/dist/midi/MIDIReceiver.js +65 -0
  49. package/dist/midi/MidiDevices.d.ts +4 -1
  50. package/dist/midi/MidiDevices.d.ts.map +1 -1
  51. package/dist/midi/MidiDevices.js +40 -1
  52. package/dist/processors.js +17 -19
  53. package/dist/processors.js.map +4 -4
  54. package/dist/project/Project.d.ts.map +1 -1
  55. package/dist/project/Project.js +14 -2
  56. package/dist/project/ProjectApi.d.ts +13 -4
  57. package/dist/project/ProjectApi.d.ts.map +1 -1
  58. package/dist/project/ProjectApi.js +71 -29
  59. package/dist/project/ProjectBundle.d.ts +2 -2
  60. package/dist/project/ProjectBundle.d.ts.map +1 -1
  61. package/dist/project/ProjectBundle.js +3 -3
  62. package/dist/project/ProjectMeta.d.ts +2 -0
  63. package/dist/project/ProjectMeta.d.ts.map +1 -1
  64. package/dist/project/ProjectMeta.js +1 -0
  65. package/dist/project/ProjectMigration.d.ts.map +1 -1
  66. package/dist/project/ProjectMigration.js +47 -5
  67. package/dist/project/ProjectProfile.d.ts +1 -0
  68. package/dist/project/ProjectProfile.d.ts.map +1 -1
  69. package/dist/project/ProjectProfile.js +5 -0
  70. package/dist/project/audio/AudioContentFactory.d.ts +34 -0
  71. package/dist/project/audio/AudioContentFactory.d.ts.map +1 -0
  72. package/dist/project/audio/AudioContentFactory.js +107 -0
  73. package/dist/project/audio/AudioContentHelpers.d.ts +7 -0
  74. package/dist/project/audio/AudioContentHelpers.d.ts.map +1 -0
  75. package/dist/project/audio/AudioContentHelpers.js +17 -0
  76. package/dist/project/audio/AudioContentModifier.d.ts +10 -0
  77. package/dist/project/audio/AudioContentModifier.d.ts.map +1 -0
  78. package/dist/project/audio/AudioContentModifier.js +127 -0
  79. package/dist/project/audio/AudioFileBoxFactory.d.ts +8 -0
  80. package/dist/project/audio/AudioFileBoxFactory.d.ts.map +1 -0
  81. package/dist/project/audio/AudioFileBoxFactory.js +36 -0
  82. package/dist/project/audio/index.d.ts +4 -0
  83. package/dist/project/audio/index.d.ts.map +1 -0
  84. package/dist/project/audio/index.js +3 -0
  85. package/dist/project/index.d.ts +1 -0
  86. package/dist/project/index.d.ts.map +1 -1
  87. package/dist/project/index.js +1 -0
  88. package/dist/samples/DefaultSampleLoader.d.ts +2 -1
  89. package/dist/samples/DefaultSampleLoader.d.ts.map +1 -1
  90. package/dist/samples/DefaultSampleLoader.js +1 -1
  91. package/dist/samples/DefaultSampleLoaderManager.d.ts +3 -1
  92. package/dist/samples/DefaultSampleLoaderManager.d.ts.map +1 -1
  93. package/dist/samples/DefaultSampleLoaderManager.js +13 -0
  94. package/dist/samples/OpenSampleAPI.d.ts +2 -1
  95. package/dist/samples/OpenSampleAPI.d.ts.map +1 -1
  96. package/dist/samples/OpenSampleAPI.js +2 -2
  97. package/dist/samples/SampleAPI.d.ts +2 -1
  98. package/dist/samples/SampleAPI.d.ts.map +1 -1
  99. package/dist/samples/SampleProvider.d.ts +2 -1
  100. package/dist/samples/SampleProvider.d.ts.map +1 -1
  101. package/dist/samples/SampleService.d.ts.map +1 -1
  102. package/dist/samples/SampleStorage.d.ts +2 -1
  103. package/dist/samples/SampleStorage.d.ts.map +1 -1
  104. package/dist/samples/SampleStorage.js +6 -5
  105. package/dist/soundfont/OpenSoundfontAPI.d.ts.map +1 -1
  106. package/dist/soundfont/OpenSoundfontAPI.js +3 -3
  107. package/dist/workers-main.js +1 -5
  108. package/dist/workers-main.js.map +4 -4
  109. package/package.json +15 -15
@@ -1,6 +1,2 @@
1
- var f=s=>s!=null,xt=s=>s===null;var Ne=s=>s===void 0,Me=s=>s!==void 0,Be=s=>s==null;var x=(s,t="asDefined failed")=>s??u(rt(t)),Zt=(s,t)=>s instanceof t,Fe=(s,t)=>s instanceof t?s:u(`${s} is not instance of ${t}`);var rt=s=>s instanceof Function?s():s;var B=(s,...t)=>s?.apply(null,t),st=s=>f(s)&&typeof s=="object",te=(s,t,e)=>{if(!(t in s))return!1;let r=s[t];return e==="null"?r===null:typeof r===e},Oe=(s,...t)=>{let e=s;for(let r of t){if(!st(e)||!(r in e))return;e=e[r]}return e},K=s=>{throw new Error(`Unhandled ${s}`)},u=s=>{throw typeof s=="string"?new Error(s):s},y=(s,t)=>s?void 0:u(rt(t));var bt=s=>new Proxy({},{get(){return u(s)}});var Xt=class{value;status="success";constructor(t){this.value=t}error=bt("Cannot access error when succeeded")},Qt=class{error;status="failure";constructor(t){this.error=t}value=bt("Cannot access value when failed")},nt=s=>{try{return new Xt(s())}catch(t){return new Qt(t)}};var Et=()=>{};var $e=s=>{};var ee;(function(s){s[s.Ascending=1]="Ascending",s[s.Descending=-1]="Descending"})(ee||(ee={}));var g=class{static#t=Object.freeze(new Array(0));static empty=()=>this.#t;static clear=t=>{t.length=0};static replace=(t,e)=>{t.length=0,t.push(...e)};static consume=(t,e)=>{for(let r=0;r<t.length;)e(t[r])?t.splice(r,1):r++};static peekFirst=t=>t.at(0)??null;static peekLast=t=>t.at(-1)??null;static getFirst=(t,e)=>x(t.at(0),e);static getLast=(t,e)=>x(t.at(-1),e);static getPrev=(t,e)=>{let r=t.indexOf(e);return r===-1?u(`${e} not found in ${t}`):x(t.at((r-1)%t.length),"Internal Error")};static getNext=(t,e)=>{let r=t.indexOf(e);return r===-1?u(`${e} not found in ${t}`):x(t.at((r+1)%t.length),"Internal Error")};static removeLast=(t,e)=>x(t.pop(),e);static create=(t,e)=>{let r=new Array(e);for(let n=0;n<e;n++)r[n]=t(n);return r};static equals=(t,e)=>{if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0};static satisfy=(t,e)=>{if(t.length<2)return!0;let r=t[0];for(let n=1;n<t.length;n++)if(!e(r,t[n]))return!1;return!0};static remove=(t,e)=>{let r=t.indexOf(e);if(r===-1)return u(`${e} not found in ${t}`);t.splice(r,1)};static removeIf=(t,e)=>{for(let r=t.length-1;r>=0;r--)e(t[r])&&t.splice(r,1)};static removeOpt=(t,e)=>{let r=t.indexOf(e);return r===-1?!1:(t.splice(r,1),!0)};static hasDuplicates=t=>new Set(t).size<t.length;static removeDuplicates=t=>{let e=0,r=new Set;for(let n of t)r.has(n)||(r.add(n),t[e++]=n);return t.length=e,t};static removeDuplicateKeys=(t,e)=>{let r=0,n=new Set;for(let i of t){let o=i[e];n.has(o)||(n.add(o),t[r++]=i)}return t.length=r,t};static subtract(t,e,r){return t.filter(n=>!e.some(i=>r(n,i)))}static intersect(t,e,r){return t.filter(n=>e.some(i=>r(n,i)))}static merge(t,e,r){return[...t.filter(n=>!e.some(i=>r(n,i))),...e]}static*iterate(t){for(let e=0;e<t.length;e++)yield t[e]}static*iterateReverse(t){for(let e=t.length-1;e>=0;e--)yield t[e]}static*iterateStateFull(t){let e=t.length-1;for(let r=0;r<=e;r++)yield{value:t[r],isFirst:r===0,isLast:r===e}}static*iterateAdjacent(t){if(!(t.length<=1))for(let e=1,r=t[0];e<t.length;e++){let n=t[e];yield[r,n],r=n}}static isSorted(t,e=ee.Ascending){if(t.length<2)return!0;let r=t[0];for(let n=1;n<t.length;n++){let i=t[n];if(Math.sign(r-i)===e)return!1;r=i}return!0}static toRecord(t,e){return t.reduce((r,n)=>(r[e(n)]=n,r),{})}static concatArrayBuffers(t,e){let r=new ArrayBuffer(t.byteLength+e.byteLength),n=new Uint8Array(r);return n.set(new Uint8Array(t),0),n.set(new Uint8Array(e),t.byteLength),r}};var p;(function(s){s.wrap=e=>f(e)?new t(e):s.None,s.from=e=>s.wrap(e()),s.tryFrom=e=>{try{return s.wrap(e())}catch{return s.None}},s.execute=(e,...r)=>s.wrap(e?.apply(null,r)),s.async=e=>e.then(r=>s.wrap(r),()=>s.None);class t{#t;constructor(r){this.#t=x(r)}unwrap(){return this.#t}unwrapOrElse(r){return this.#t}unwrapOrNull(){return this.#t}unwrapOrUndefined(){return this.#t}contains(r){return r===this.#t}match(r){return r.some(this.#t)}ifSome(r){return r(this.#t)}ifAbsent(r){}isEmpty(){return!1}nonEmpty(){return!0}map(r){return s.wrap(r(this.#t))}mapOr(r,n){return r(this.#t)}flatMap(r){return r(this.#t)}equals(r){return this.unwrapOrNull()===r.unwrapOrNull()}assert(r){return this}toString(){return`{Option.Some(${this.#t})}`}get[Symbol.toStringTag](){return this.toString()}}s.Some=t,s.None=new class{unwrap=e=>u(f(e)?rt(e):"unwrap failed");unwrapOrElse=e=>rt(e);unwrapOrNull=()=>null;unwrapOrUndefined=()=>{};contains=e=>!1;match=e=>e.none();ifSome=e=>{};ifAbsent=e=>e(void 0);isEmpty=()=>!0;nonEmpty=()=>!1;map=e=>s.None;mapOr=(e,r)=>rt(r);flatMap=e=>s.None;equals=e=>e.isEmpty();assert=e=>u(rt(e)??"assert failed");toString=()=>"{Option.None}";get[Symbol.toStringTag](){return this.toString()}}})(p||(p={}));var Re;(function(s){s.async=t=>t.then(e=>s.ok(e),e=>s.err(e)),s.tryGet=t=>{try{return s.ok(t())}catch(e){return s.err(e)}},s.ok=t=>new class{value;constructor(e){this.value=e}asOption=()=>p.wrap(this.value);failureReason=()=>{throw new Error("Attempt was successful.")};isFailure=()=>!1;isSuccess=()=>!0;result=()=>this.value;map=e=>{try{return s.ok(e(this.value))}catch(r){return s.err(r)}};flatMap=e=>e(this.value);match=e=>e.ok(this.value);toVoid=()=>s.ok(void 0);failure=()=>{throw new Error("Attempt was successful.")};toString=()=>`{Success: ${this.value}`;get[Symbol.toStringTag](){return"Success"}}(t),s.Ok=new class{constructor(){}asOption=()=>p.None;failureReason=()=>{throw new Error("Attempt was successful.")};isFailure=()=>!1;isSuccess=()=>!0;result=()=>{};map=t=>s.ok(t());flatMap=t=>t();match=t=>t.ok();toVoid=()=>s.ok(void 0);failure=()=>{throw new Error("Attempt was successful.")};toString=()=>"{Success: Ok";get[Symbol.toStringTag](){return"Success"}},s.err=t=>new class{reason;constructor(e){this.reason=e}asOption=()=>p.None;failureReason=()=>this.reason;isFailure=()=>!0;isSuccess=()=>!1;result=()=>u(`'${this.reason}'`);map=()=>this;flatMap=()=>this;match=e=>e.err(this.reason);toVoid=()=>s.err(this.reason);failure=()=>this;toString=()=>`{Failure: ${this.reason}`;get[Symbol.toStringTag](){return"Failure"}}(t)})(Re||(Re={}));var v;(function(s){s.exact=(t,e,r)=>{let n=0,i=t.length-1;for(;n<=i;){let o=n+i>>>1,a=r(t[o],e);if(a===0)return o;a<0?n=o+1:i=o-1}return-1},s.exactMapped=(t,e,r,n)=>{let i=0,o=t.length-1;for(;i<=o;){let a=i+o>>>1,c=r(n(t[a]),e);if(c===0)return a;c<0?i=a+1:o=a-1}return-1},s.leftMost=(t,e,r)=>{let n=0,i=t.length;for(;n<i;){let o=n+i>>>1;r(t[o],e)<0?n=o+1:i=o}return n},s.rightMost=(t,e,r)=>{let n=0,i=t.length;for(;n<i;){let o=n+i>>>1;r(t[o],e)<=0?n=o+1:i=o}return i-1},s.stableInsert=(t,e,r)=>{let n=0,i=t.length;for(;n<i;){let o=n+i>>>1;r(t[o],e)<0?n=o+1:i=o}for(;n<t.length&&r(t[n],e)===0;)n++;return n},s.leftMostMapped=(t,e,r,n)=>{let i=0,o=t.length;for(;i<o;){let a=i+o>>>1;r(n(t[a]),e)<0?i=a+1:o=a}return i},s.rightMostMapped=(t,e,r,n)=>{let i=0,o=t.length;for(;i<o;){let a=i+o>>>1;r(n(t[a]),e)<=0?i=a+1:o=a}return o-1},s.rangeMapped=(t,e,r,n)=>[s.leftMostMapped(t,e,r,n),s.rightMostMapped(t,e,r,n)]})(v||(v={}));var Nt;(function(s){s.parseCssRgbOrRgba=t=>{let e=t.match(/\(([^)]+)\)/)?.at(1)?.split(",")?.map(Number);if(f(e)&&e.every(r=>!isNaN(r))){if(e.length===3)return[e[0]/255,e[1]/255,e[2]/255,1];if(e.length===4)return[e[0]/255,e[1]/255,e[2]/255,e[3]]}throw new Error(`${t} is not proper formatted. Example: 'rgb(255, 255, 255)' or 'rgba(255, 255, 255, 1)'`)},s.hslToHex=(t,e,r)=>{let n=c=>(c+t/30)%12,i=e*Math.min(r,1-r),o=c=>r-i*Math.max(-1,Math.min(n(c)-3,Math.min(9-n(c),1))),a=c=>Math.round(c*255).toString(16).padStart(2,"0");return`#${a(o(0))}${a(o(8))}${a(o(4))}`},s.hexToHsl=t=>{let e=t.startsWith("#")?t.slice(1):t,r=parseInt(e.slice(0,2),16)/255,n=parseInt(e.slice(2,4),16)/255,i=parseInt(e.slice(4,6),16)/255,o=Math.max(r,n,i),a=Math.min(r,n,i),c=(o+a)/2,h=0,l=0;if(o!==a){let d=o-a;switch(l=c>.5?d/(2-o-a):d/(o+a),o){case r:h=((n-i)/d+(n<i?6:0))*60;break;case n:h=((i-r)/d+2)*60;break;case i:h=((r-n)/d+4)*60;break}}return{h,s:l,l:c}},s.hslStringToHex=t=>{let[e,r,n]=t.match(/\d+(\.\d+)?/g).map(Number);return s.hslToHex(e,r/100,n/100)}})(Nt||(Nt={}));var re=(s,t)=>s-t;var qr=Math.PI*2,Wr=Math.PI/2,Yr=Math.PI/4,Hr=1/Math.sqrt(2),b=(s,t,e)=>Math.max(t,Math.min(s,e));var se=s=>Math.pow(2,Math.ceil(Math.log(s)/Math.log(2)));var Ve;(function(s){s.valueAt=({slope:n,steps:i,y0:o,y1:a},c)=>s.normalizedAt(c/i,n)*(a-o)+o,s.normalizedAt=(n,i)=>{if(i>.499999&&i<.500001)return n;{let o=b(i,1e-15,.999999999999999);return o*o/(1-o*2)*(Math.pow((1-o)/o,2*n)-1)}},s.inverseAt=(n,i)=>{let o=b(i,1e-15,.999999999999999);return Math.log(n*(1-2*o)/(o*o)+1)/(2*Math.log((1-o)/o))},s.coefficients=n=>{let i=s.valueAt(n,1),a=(s.valueAt(n,2)-i)/(i-n.y0),c=i-a*n.y0;return{m:a,q:c}};function*e(n,i,o,a){let{m:c,q:h}=s.coefficients({slope:n,steps:i,y0:o,y1:a});for(let l=0,d=o;l<i;l++)yield d=c*d+h}s.walk=e;function*r(n,i){let o=1/i,a=s.normalizedAt(o,n),h=(s.normalizedAt(2*o,n)-a)/a;for(let l=0,d=0;l<i;l++)yield d=h*d+a}s.walkNormalized=r,s.byHalf=(n,i,o,a)=>({slope:s.slopeByHalf(i,o,a),steps:n,y0:i,y1:a}),s.slopeByHalf=(n,i,o)=>Math.abs(o-n)<1e-6?.5:(i-n)/(o-n)})(Ve||(Ve={}));var C=new DataView(new ArrayBuffer(8)),V;(function(s){s.MIN_VALUE=-2147483648,s.MAX_VALUE=2147483647,s.toByte=t=>(C.setInt8(0,t),C.getInt8(0)),s.toShort=t=>(C.setInt16(0,t),C.getInt16(0)),s.toInt=t=>(C.setInt32(0,t),C.getInt32(0))})(V||(V={}));var it;(function(s){let r=new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT),n=new Float32Array(r),i=new Int32Array(r);s.floatToIntBits=o=>{let a=s.floatToRawIntBits(o);return(a&2139095040)===2139095040&&(a&8388607)!==0?2143289344:a},s.intBitsToFloat=o=>(i[0]=o,n[0]),s.floatToRawIntBits=o=>(n[0]=o,i[0]),s.toFloat32=o=>(C.setFloat32(0,o),C.getFloat32(0))})(it||(it={}));var H;(function(s){s.floatToIntBits=t=>{let e=it.floatToIntBits(t),r=e>>>16&32768,n=(e&2147483647)+4096;return n>=1199570944?(e&2147483647)>=1199570944?n<2139095040?r|31744:r|31744|(e&8388607)>>>13:r|31743:n>=947912704?r|n-939524096>>>13:n<855638016?r:(n=(e&2147483647)>>>23,r|(e&8388607|8388608)+(8388608>>>n-102)>>>126-n)},s.intBitsToFloat=t=>{let e=t&1023,r=t&31744;if(r===31744)r=261120;else if(r!==0){if(r+=114688,e===0&&r>115712)return it.intBitsToFloat((t&32768)<<16|r<<13|1023)}else if(e!==0){r=115712;do e<<=1,r-=1024;while((e&1024)===0);e&=1023}return it.intBitsToFloat((t&32768)<<16|(r|e)<<13)}})(H||(H={}));var ne;(function(s){let t=9218868437227405312n,e=4503599627370495n,r=new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT),n=new Float64Array(r),i=new BigInt64Array(r);s.float64ToLongBits=o=>{let a=s.float64ToRawLongBits(o);return(a&t)===t&&(a&e)!==0n?0x7ff8000000000000n:a},s.longBitsToFloat64=o=>(i[0]=o,n[0]),s.float64ToRawLongBits=o=>(n[0]=o,i[0]),s.clamp=o=>(C.setFloat64(0,o),C.getFloat64(0))})(ne||(ne={}));var k=class{static*empty(){}static one(t){return[t]}static count(t){let e=0;for(let r of t)e++;return e}static some(t,e){for(let r of t)if(e(r))return!0;return!1}static every(t,e){for(let r of t)if(!e(r))return!1;return!0}static reduce(t,e,r){let n=r,i=0;for(let o of t)n=e(n,o,i++);return n}static includes(t,e){for(let r of t)if(r===e)return!0;return!1}static forEach(t,e){for(let r of t)e(r)}static*map(t,e){let r=0;for(let n of t)yield e(n,r++)}static*take(t,e){let r=0;for(let n of t){if(r++>=e)return;yield n}}static filter(t,e){let r=[];for(let n of t)e(n)&&r.push(n);return r}static filterMap(t,e){let r=[];for(let n of t){let i=e(n);f(i)&&r.push(i)}return r}static reverse(t){let e=[];for(let r of t)e.push(r);return e.reverse()}static*pairWise(t){let e=t[Symbol.iterator](),{done:r,value:n}=e.next(),i=n;if(r!==!0)for(;;){let{done:o,value:a}=e.next();if(o===!0){yield[i,null];return}yield[i,a],i=a}}};var N=class s{static create(t=1024){return this.use(new ArrayBuffer(t))}static use(t,e=0){return new s(new DataView(t,e))}littleEndian=!1;#t;#e=0;constructor(t){this.#t=t}get remaining(){return this.#t.byteLength-this.#e}get position(){return this.#e}set position(t){t<0?u(`position(${t}) cannot be negative.`):t>this.#t.byteLength?u(`position(${t}) is outside range (${this.#t.byteLength}).`):this.#e=t}writeBoolean(t){this.writeByte(t?1:0)}writeByte(t){this.#r(1),this.#t.setInt8(this.#e++,t)}writeShort(t){this.#r(Int16Array.BYTES_PER_ELEMENT),this.#t.setInt16(this.#e,t,this.littleEndian),this.#e+=Int16Array.BYTES_PER_ELEMENT}writeInt(t){this.#r(Int32Array.BYTES_PER_ELEMENT),this.#t.setInt32(this.#e,t,this.littleEndian),this.#e+=Int32Array.BYTES_PER_ELEMENT}writeLong(t){this.#r(BigInt64Array.BYTES_PER_ELEMENT),this.#t.setBigInt64(this.#e,t,this.littleEndian),this.#e+=BigInt64Array.BYTES_PER_ELEMENT}writeFloat(t){this.#r(Float32Array.BYTES_PER_ELEMENT),this.#t.setFloat32(this.#e,t,this.littleEndian),this.#e+=Float32Array.BYTES_PER_ELEMENT}writeDouble(t){this.#r(Float64Array.BYTES_PER_ELEMENT),this.#t.setFloat64(this.#e,t,this.littleEndian),this.#e+=Float64Array.BYTES_PER_ELEMENT}writeBytes(t){this.#r(t.length);for(let e=0;e<t.length;++e)this.#t.setInt8(this.#e++,t[e])}writeString(t){let e=t.length;this.#r(Int32Array.BYTES_PER_ELEMENT+e*Int16Array.BYTES_PER_ELEMENT),this.writeInt(e);for(let r=0;r<e;r++)this.writeShort(t.charCodeAt(r))}toArrayBuffer(){return this.#t.buffer.slice(0,this.#e)}#r(t){let e=this.#t.byteLength;if(this.#e+t>e){let r=this.#t;this.#t=new DataView(new ArrayBuffer(se(e+t)));for(let n=0;n<this.#e;n++)this.#t.setInt8(n,r.getInt8(n))}}},lt=class{#t=0;writeByte(t){this.#t++}writeShort(t){this.#t+=2}writeInt(t){this.#t+=4}writeLong(t){this.#t+=8}writeFloat(t){this.#t+=4}writeDouble(t){this.#t+=8}writeBoolean(t){this.#t++}writeBytes(t){this.#t+=t.length}writeString(t){this.#t+=t.length+4}get count(){return this.#t}};var R=class{littleEndian=!1;#t;#e=0;constructor(t,e=0){this.#t=new DataView(t,e)}get position(){return this.#e}set position(t){t<0?u(`position(${t}) cannot be negative.`):t>this.#t.byteLength?u(`position(${t}) is outside range (${this.#t.byteLength}).`):this.#e=t}readByte(){return this.#t.getInt8(this.#e++)}readShort(){let t=this.#t.getInt16(this.#e,this.littleEndian);return this.#e+=Int16Array.BYTES_PER_ELEMENT,t}readInt(){let t=this.#t.getInt32(this.#e,this.littleEndian);return this.#e+=Int32Array.BYTES_PER_ELEMENT,t}readLong(){let t=this.#t.getBigInt64(this.#e,this.littleEndian);return this.#e+=BigInt64Array.BYTES_PER_ELEMENT,t}readFloat(){let t=this.#t.getFloat32(this.#e,this.littleEndian);return this.#e+=Float32Array.BYTES_PER_ELEMENT,t}readDouble(){let t=this.#t.getFloat64(this.#e,this.littleEndian);return this.#e+=Float64Array.BYTES_PER_ELEMENT,t}readBoolean(){return this.readByte()===1}readBytes(t){for(let e=0;e<t.length;e++)t[e]=this.readByte()}readString(){let t=this.readInt(),e="";for(let r=0;r<t;r++)e+=String.fromCharCode(this.readShort());return e}available(t){return this.#e+t<=this.#t.byteLength}remaining(){return this.#t.byteLength-this.#e}skip(t){this.position+=t}};var Ir=s=>f(s)?s.value!==void 0?"value":s.get!==void 0?"get":u(`Cannot resolve method key of ${s}`):u("Cannot resolve method key of undefined descriptor"),ut=(s,t,e)=>{if(!f(e))return function(i,o){if(o&&o.kind==="getter")return function(){let a=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this),t);if(!f(a?.get))return u(`Cannot find getter for property '${t}'`);let c=a.get.apply(this);return Object.defineProperty(this,t,{value:c,configurable:!1,writable:!1,enumerable:!1}),c}};let r=Ir(e),n=x(e[r]);return{[r]:function(...i){if(i.length>0)return u("lazy accessory must not have any construction parameters");let o=n.apply(this);return Object.defineProperty(this,t,{value:r==="get"?o:()=>o,configurable:!1,writable:!1,enumerable:!1}),o}}};var Le;(function(s){s.Transient=Object.freeze({modify:(t,e)=>p.wrap(t()),mark:()=>{}})})(Le||(Le={}));var Pe;(function(s){function*t(){}s.empty=t,s.next=r=>{let{value:n,done:i}=r.next();return i?null:n};function*e(...r){for(let n of r)for(let i of n)yield i}s.flatten=e})(Pe||(Pe={}));var ft;(function(s){s[s.T=0]="T",s[s.R=1]="R",s[s.B=2]="B",s[s.L=3]="L"})(ft||(ft={}));var dt;(function(s){s[s.TL=0]="TL",s[s.TR=1]="TR",s[s.BR=2]="BR",s[s.BL=3]="BL"})(dt||(dt={}));var De;(function(s){s.outerTangentPoints=(t,e)=>{let r=e.x-t.x,n=e.y-t.y,i=Math.atan2(n,r)+Math.acos((t.r-e.r)/Math.sqrt(r*r+n*n)),o=Math.cos(i),a=Math.sin(i);return[{x:t.x+t.r*o,y:t.y+t.r*a},{x:e.x+e.r*o,y:e.y+e.r*a}]}})(De||(De={}));var Ce;(function(s){s.zero=()=>({x:0,y:0}),s.create=(t,e)=>({x:t,y:e}),s.clone=t=>({...t}),s.floor=t=>({x:Math.floor(t.x),y:Math.floor(t.y)}),s.length=t=>Math.sqrt(t.x*t.x+t.y*t.y),s.distance=(t,e)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2),s.add=(t,e)=>({x:t.x+e.x,y:t.y+e.y}),s.subtract=(t,e)=>({x:t.x-e.x,y:t.y-e.y}),s.scaleBy=(t,e)=>({x:t.x*e,y:t.y*e}),s.scaleTo=(t,e)=>{let r=e/s.length(t);return{x:t.x*r,y:t.y*r}},s.fromClient=t=>({x:t.clientX,y:t.clientY})})(Ce||(Ce={}));var At;(function(s){s.Empty=Object.freeze({x:0,y:0,width:0,height:0}),s.corners=t=>{let e=t.x,r=t.y,n=e+t.width,i=r+t.height;return[{x:e,y:r},{x:n,y:r},{x:n,y:i},{x:e,y:i}]},s.inflate=(t,e)=>({x:t.x-e,y:t.y-e,width:t.width+e*2,height:t.height+e*2}),s.contains=(t,e)=>{let r=e.x>=t.x&&e.y>=t.y,n=e.x+e.width<=t.x+t.width&&e.y+e.height<=t.y+t.height;return r&&n},s.isPointInside=(t,e)=>t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height,s.intersect=(t,e)=>{let r=Math.max(t.x,e.x),n=Math.min(t.x+t.width,e.x+e.width),i=Math.min(t.y+t.height,e.y+e.height),o=Math.max(t.y,e.y);return n>r&&i>o},s.axis=(t,e)=>{switch(e){case ft.T:return t.y;case ft.R:return t.x+t.width;case ft.B:return t.y+t.height;case ft.L:return t.x;default:return K(e)}},s.corner=(t,e)=>{switch(e){case dt.TL:return{x:t.x,y:t.y};case dt.TR:return{x:t.x+t.width,y:t.y};case dt.BR:return{x:t.x+t.width,y:t.y+t.height};case dt.BL:return{x:t.x,y:t.y+t.height};default:return K(e)}},s.center=t=>({x:t.x+t.width*.5,y:t.y+t.height*.5}),s.isEmpty=t=>t.width===0||t.height===0,s.union=(t,e)=>{if(s.isEmpty(t))s.isEmpty(e)||(t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height);else if(!s.isEmpty(e)){let r=e.x,n=e.y,i=Math.min(t.x,r),o=Math.min(t.y,n);t.width=Math.max(t.x+t.width,r+e.width)-i,t.height=Math.max(t.y+t.height,n+e.height)-o,t.x=i,t.y=o}}})(At||(At={}));var ke;(function(s){s.width=t=>t.xMax-t.xMin,s.height=t=>t.yMax-t.yMin,s.from=(t,e)=>{t.xMin=e.xMin,t.xMax=e.xMax,t.yMin=e.yMin,t.yMax=e.yMax},s.extend=(t,e)=>{t.xMin-=e,t.yMin-=e,t.xMax+=e,t.yMax+=e},s.padding=(t,[e,r,n,i])=>(t.xMin+=i,t.yMin+=e,t.xMax-=r,t.yMax-=n,t),s.intersectPoint=(t,e)=>t.xMin<=e.x&&e.x<t.xMax&&t.yMin<=e.y&&e.y<t.yMax,s.intersectThat=(t,e)=>e.xMin<t.xMax&&e.xMax>t.xMin&&e.yMin<t.yMax&&e.yMax>t.yMin,s.center=t=>({x:(t.xMin+t.xMax)*.5,y:(t.yMin+t.yMax)*.5})})(ke||(ke={}));var _e;(function(s){s.Identity=Object.freeze([0,0,0,0])})(_e||(_e={}));var Ue;(function(s){s.intersects=(r,n,i,o,a,c,h,l)=>{let d=t(r,n,i,o,a,c),E=t(r,n,i,o,h,l);if((d|E)===0||(d&E)!==0)return!1;let S=e(a,c,h,l,r,i);return S!==e(a,c,h,l,n,i)||S!==e(a,c,h,l,n,o)||S!==e(a,c,h,l,r,o)};let t=(r,n,i,o,a,c)=>{let h=0;return a<=r?h|=1:a>=n&&(h|=2),c<=i?h|=8:c>=o&&(h|=4),h},e=(r,n,i,o,a,c)=>(i-r)*(c-n)-(a-r)*(o-n)>=0})(Ue||(Ue={}));var je;(function(s){s.Identity={valueToAxis:t=>t,axisToValue:t=>t},s.toClamped=(t,e,r)=>({valueToAxis:n=>t.valueToAxis(b(n,e,r)),axisToValue:n=>b(t.axisToValue(n),e,r)}),s.createClamped=(t,e)=>({valueToAxis:r=>b(r,t,e),axisToValue:r=>b(r,t,e)})})(je||(je={}));var Ke;(function(s){s.fromBuffers=async(...t)=>{let e=t.reduce((i,o)=>i+o.byteLength,0),r=new Uint8Array(e),n=0;for(let i of t)r.set(new Uint8Array(i),n),n+=i.byteLength;return await crypto.subtle.digest("SHA-256",r)},s.equals=(t,e)=>{y(t.byteLength===32,"First hash has invalid length"),y(e.byteLength===32,"Second hash has invalid length");let r=new Uint8Array(t),n=new Uint8Array(e);for(let i=0;i<32;i++)if(r[i]!==n[i])return!1;return!0},s.toString=t=>Array.from(new Uint8Array(t)).map(e=>e.toString(16).padStart(2,"0")).join("")})(Ke||(Ke={}));var ze;(function(s){s.intersect1D=(t,e,r,n)=>Math.max(t,r)<=Math.min(e,n)})(ze||(ze={}));var It=class{#t=new Set;#e;constructor(){this.#e=new Proxy({},{get:(t,e)=>(...r)=>this.#t.forEach(n=>Object.getPrototypeOf(n)===Object.getPrototypeOf({})?B(n[e],...r):n[e]?.apply(n,r))})}get proxy(){return this.#e}get size(){return this.#t.size}subscribe(t){return this.#t.add(t),{terminate:()=>this.#t.delete(t)}}forEach(t){this.#t.forEach(t)}terminate(){this.#t.clear()}};var ie=class s{static#t=Object.freeze(new Set);static empty=()=>s.#t};var F=Object.freeze({Empty:{terminate:Et},create:s=>({terminate:s}),many:(...s)=>({terminate:()=>{for(;s.length>0;)s.pop().terminate()}})}),ot=class s{#t=[];isEmpty(){return this.#t.length===0}nonEmpty(){return this.#t.length>0}own(t){return this.#t.push(t),t}ownAll(...t){for(let e of t)this.#t.push(e)}spawn(){let t=new s;return t.own({terminate:()=>g.removeOpt(this.#t,t)}),this.own(t)}terminate(){for(;this.#t.length>0;)this.#t.pop().terminate()}};var L=class{static subscribeMany(t,...e){return F.many(...e.map(r=>r.subscribe(()=>t(r))))}#t=new Set;subscribe(t){return this.#t.add(t),{terminate:()=>this.#t.delete(t)}}isEmpty(){return this.#t.size===0}notify(t){this.#t.forEach(e=>e(t))}observers(){return this.#t}terminate(){this.#t.clear()}};var Mt;(function(s){let t=Object.freeze({});s.empty=()=>t,s.mergeNoOverlap=(e,r)=>{let n=new Set(Object.keys(e));for(let i of Object.keys(r))if(n.has(i))return u(`'${i}' is an overlapping key`);return{...e,...r}},s.include=(e,...r)=>{let n={};for(let i of r)n[i]=e[i];return n},s.exclude=(e,...r)=>{let n=new Set(r);return Object.entries(e).reduce((i,[o,a])=>(n.has(o)||(i[o]=a),i),{})},s.overwrite=(e,r)=>Object.assign(e,r)})(Mt||(Mt={}));var qe;(function(s){s.seal=t=>new class{getValue(){return t}subscribe(e){return F.Empty}catchupAndSubscribe(e){return e(this),F.Empty}}})(qe||(qe={}));var We;(function(s){s.False=new class{getValue(){return!1}setValue(t){}subscribe(t){return F.Empty}catchupAndSubscribe(t){return t(this),F.Empty}},s.inverseBoolean=t=>new class{getValue(){return!t.getValue()}setValue(e){t.setValue(!e)}subscribe(e){return t.subscribe(e)}catchupAndSubscribe(e){return e(this),this.subscribe(e)}}})(We||(We={}));var Bt=class{#t;#e=p.None;#r;constructor(t,e){this.#t=new L,this.#r=e?.guard(t)??t,this.#e=p.wrap(e)}setValue(t){this.#e.nonEmpty()&&(t=this.#e.unwrap().guard(t)),this.#r!==t&&(this.#r=t,this.#t.notify(this))}getValue(){return this.#r}subscribe(t){return this.#t.subscribe(t)}catchupAndSubscribe(t){return t(this),this.#t.subscribe(t)}terminate(){this.#t.terminate()}toString(){return`{DefaultObservableValue value: ${this.#r}`}};var oe=class{#t;#e;#r;constructor(t,e){this.#t=t,this.#e=e,this.#r=e-t}x(t){return(this.clamp(t)-this.#t)/this.#r}y(t){return this.#t+b(t,0,1)*this.#r}clamp(t){return b(t,this.#t,this.#e)}floating(){return!0}},ae=class{#t;#e;#r;constructor(t,e){this.#t=b(Math.round(t),V.MIN_VALUE,V.MAX_VALUE),this.#e=b(Math.round(e),V.MIN_VALUE,V.MAX_VALUE),this.#r=this.#e-this.#t}x(t){return(this.clamp(t)-this.#t)/this.#r}y(t){return this.#t+Math.round(b(t,0,1)*this.#r)}clamp(t){return b(Math.round(t),this.#t,this.#e)}floating(){return!1}},ce=class{#t;#e;#r;constructor(t,e){this.#t=t,this.#e=e,this.#r=Math.log(e/t)}x(t){return Math.log(b(t,this.#t,this.#e)/this.#t)/this.#r}y(t){return this.#t*Math.exp(b(t,0,1)*this.#r)}clamp(t){return Math.min(this.#e,Math.max(this.#t,t))}floating(){return!0}},he=class{#t;constructor(t){this.#t=t}x(t){let e=this.#t.findIndex(r=>r===t);return e===-1?u(`Could not find index for ${t}`):e/(this.#t.length-1)}y(t){let e=Math.round(b(t,0,1)*(this.#t.length-1));return e>-1?x(this.#t.at(e),`Could not find value for ${t}`):u(`Index ${e} is out of box.`)}clamp(t){return t}floating(){return!1}},le=class{#t;#e;#r;#s;#n;constructor(t,e,r){this.#t=t,this.#e=r;let n=t*t,i=r*r,o=e*e,a=t+r-2*e,c=r-e;this.#r=((2*r-e)*t-e*r)/a,this.#s=(c*n+(o-i)*t+e*i-o*r)/(n+(2*r-4*e)*t+i-4*e*r+4*o),this.#n=-c/a}y(t){return t<=0?Number.NEGATIVE_INFINITY:t>=1?this.#e:this.#r-this.#s/(t+this.#n)}x(t){return this.#t>=t?0:this.#e<=t?1:-this.#s/(t-this.#r)-this.#n}clamp(t){return Math.min(this.#e,t)}floating(){return!0}},ue;(function(s){s.linear=(i,o)=>new oe(i,o),s.linearInteger=(i,o)=>new ae(i,o),s.exponential=(i,o)=>new ce(i,o),s.values=i=>new he(i),s.decibel=(i,o,a)=>new le(i,o,a);let t=new class{x(i){return i?1:0}y(i){return i>=.5}clamp(i){return i}floating(){return!1}},e=s.linear(0,1),r=s.linear(-1,1);s.bool=t;let n=s.decibel(-72,-12,0);s.unipolar=()=>e,s.bipolar=()=>r,s.DefaultDecibel=n})(ue||(ue={}));var fe;(function(s){s.percent=({bipolar:i,fractionDigits:o}={})=>new t("%",o,!1,i),s.numeric=({unit:i,fractionDigits:o,unitPrefix:a,bipolar:c}={})=>new t(i,o,a,c),s.indices=(i,o)=>new class{x(a){return{unit:i,value:o[a]}}y(a){let c=o.indexOf(a);return c===-1?{type:"unknown",value:"\u{1F4A3}"}:{type:"explicit",value:c}}},s.values=(i,o,a)=>new class{x(c){return{unit:i,value:a.at(o.indexOf(c))??"N/A"}}y(c){let h=a.indexOf(c);return h===-1?{type:"unknown",value:"\u{1F4A3}"}:{type:"explicit",value:o[h]}}},s.bool=new class{y(i){switch(i.trim()){case"on":case"yes":case"true":return{type:"explicit",value:!0};default:return{type:"explicit",value:!1}}}x(i){return{value:i?"On":"Off",unit:""}}},s.boolValues=(i,o)=>new class{y(a){switch(a.trim()){case o:case"on":case"yes":case"true":return{type:"explicit",value:!0};case i:default:return{type:"explicit",value:!1}}}x(a){return{value:a?"On":"Off",unit:""}}};class t{#t;#e;#r;#s;constructor(o,a,c,h){this.#t=o??"",this.#e=a??0,this.#r=c??!1,this.#s=h??!1}y(o){let a=o.trim(),c=parseFloat(a);if(isNaN(c))return{type:"unknown",value:a};if(this.#t==="%")return{type:"explicit",value:c/100};if(a.endsWith("%"))return{type:"unitValue",value:this.#s?b(c/200+.5,0,1):b(c/100,0,1)};{a.endsWith(this.#t)&&this.#t.length>0&&(a=a.slice(0,-this.#t.length));let d=/(\d+)(\D+)/.exec(a)?.at(2)?.at(0);if(f(d)){let E=e.indexOf(d);if(E>-1)return{type:"explicit",value:c*Math.pow(10,(E-4)*3)}}return{type:"explicit",value:c}}}x(o){if(Number.isNaN(o))return{value:"\u{1F4A3}",unit:this.#t};if(Number.isFinite(o)){if(this.#t==="%")return this.#s?{value:(o*200-100).toFixed(this.#e),unit:this.#t}:{value:(o*100).toFixed(this.#e),unit:this.#t};if(this.#r){let{value:a,prefix:c}=n(o);return{value:a.toFixed(this.#e),unit:`${c}${this.#t}`}}else return{value:o.toFixed(this.#e),unit:this.#t}}else return{value:o===Number.POSITIVE_INFINITY?"\u221E":"-\u221E",unit:this.#t}}}let e=Object.freeze(["p","n","\u03BC","m","","k","M","G","T"]),r=i=>Math.log(i)/Math.log(9.999999999999998),n=i=>{let o=Math.floor(r(i)/3),a=e[o+4];return f(a)?{value:i*Math.pow(10,o*-3),prefix:a}:{value:i,prefix:""}};s.decible=s.numeric({unit:"db",fractionDigits:1}),s.panning=s.percent({unit:"%",fractionDigits:0})})(fe||(fe={}));var de;(function(s){s.alwaysTrue=()=>!0,s.alwaysFalse=()=>!1,s.definedPredicate=t=>t!=null})(de||(de={}));var Ye;(function(s){s.Empty=Object.freeze(t=>{}),s.split=(t,e)=>{let r=new Float32Array(e);return g.create(n=>i=>{r[n]=i,t(r.reduce((o,a)=>o+a,0)/e)},e)},s.splitWithWeights=(t,e)=>{let r=e.length,n=new Float32Array(r);if(e.length===0)return u("Weights must not be empty");if(e.some(a=>a<=0))return u("Weights must be greater than zero");let i=e.reduce((a,c)=>a+c,0),o=i>0?e.map(a=>a/i):g.create(()=>1/r,r);return g.create(a=>c=>{n[a]=c,t(n.reduce((h,l,d)=>h+l*o[d],0))},r)}})(Ye||(Ye={}));var He;(function(s){s.create=(t=252854082)=>new pe(t),s.monotoneAscending=(t,e=128,r=s.create())=>{let n=t.length;if(n<2)return u("Array must have at least 2 elements");let i=0;for(let a=1;a<n;a++){let c=Math.floor(r.uniform()*(1+e))+1;t[a]=c,i+=c}let o=0;t[0]=0;for(let a=1;a<n;a++)o+=t[a],t[a]=o/i;return t}})(He||(He={}));var pe=class{#t=0;constructor(t){this.setSeed(t)}setSeed(t){this.#t=t&4294967295}nextDouble(t,e){return t+this.uniform()*(e-t)}nextInt(t,e){return t+Math.floor(this.uniform()*(e-t))}nextElement(t){return t[Math.floor(this.uniform()*t.length)]}nextBoolean(){return this.uniform()<.5}uniform(){let t=this.#t+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}};var Ge;(function(s){class t{}s.createBuilder=r=>{let n=i=>{let o=i instanceof Array?[]:{};return Object.entries(i).forEach(([a,c])=>{c instanceof t?o[a]=c.initialValue():typeof c=="object"&&(o[a]=n(c))}),o};return()=>new e(r,Object.seal(n(r)))},s.bool=new class extends t{read(r){return r.readByte()===1}write(r,n){r.writeByte(n?1:0)}initialValue(){return!1}},s.int8=new class extends t{read(r){return r.readByte()}write(r,n){r.writeByte(n)}initialValue(){return 0}},s.int16=new class extends t{read(r){return r.readShort()}write(r,n){r.writeShort(n)}initialValue(){return 0}},s.int32=new class extends t{read(r){return r.readInt()}write(r,n){r.writeInt(n)}initialValue(){return 0}},s.float=new class extends t{read(r){return r.readFloat()}write(r,n){r.writeFloat(n)}initialValue(){return 0}},s.double=new class extends t{read(r){return r.readDouble()}write(r,n){r.writeDouble(n)}initialValue(){return 0}},s.int64=new class extends t{read(r){return r.readLong()}write(r,n){r.writeLong(n)}initialValue(){return 0n}},s.floats=r=>new class extends t{read(n,i){for(let o=0;o<i.length;o++)i[o]=n.readFloat();return i}write(n,i){for(let o=0;o<i.length;o++)n.writeFloat(i[o])}initialValue(){return new Float32Array(r)}},s.doubles=r=>new class extends t{read(n,i){for(let o=0;o<i.length;o++)i[o]=n.readDouble();return i}write(n,i){for(let o=0;o<i.length;o++)n.writeDouble(i[o])}initialValue(){return new Float64Array(r)}};class e{#t;#e;#r;constructor(n,i){this.#t=n,this.#e=i,this.#r=this.#s()}get object(){return this.#e}get bytesTotal(){return this.#r}read(n){let i=(o,a)=>{Object.entries(o).forEach(([c,h])=>{let l=a;h instanceof t?l[c]=h.read(n,l[c]):typeof h=="object"&&i(h,l[c])})};i(this.#t,this.#e)}write(n){let i=(o,a)=>{Object.entries(o).forEach(([c,h])=>{let l=a;h instanceof t?h.write(n,l[c]):typeof h=="object"&&i(h,l[c])})};i(this.#t,this.#e)}#s(){let n=new lt;return this.write(n),n.count}}})(Ge||(Ge={}));var pt=class{#t;#e;#r;constructor(t,e){this.#t=t,this.#e=e,this.#r=[]}add(t,e=!1){let r=this.#t(t),n=v.leftMostMapped(this.#r,r,this.#e,this.#t),i=this.#r[n];return f(i)&&this.#e(this.#t(i),r)===0?e?(this.#r.splice(n,1,t),!0):!1:(this.#r.splice(n,0,t),!0)}getOrCreate(t,e){let r=v.leftMostMapped(this.#r,t,this.#e,this.#t),n=this.#r[r];if(f(n)&&this.#e(this.#t(n),t)===0)return n;let i=e(t);return this.#r.splice(r,0,i),i}addMany(t){for(let e of t)this.#r.push(e);try{return this.#r.sort((e,r)=>{let n=this.#e(this.#t(e),this.#t(r));if(n===0)throw"cancel";return n}),!0}catch(e){if(e==="cancel"){let r=new Map(this.entries());return this.#r.splice(0,this.#r.length,...r.values()),this.#r.sort((n,i)=>this.#e(this.#t(n),this.#t(i))),!1}return u(e)}}removeByValue(t){return this.removeByKey(this.#t(t))}removeByKey(t){let e=v.leftMostMapped(this.#r,t,this.#e,this.#t),r=this.#r[e];return f(r)&&this.#e(this.#t(r),t)===0?(this.#r.splice(e,1),r):u(`Could not remove ${t}`)}removeByKeyIfExist(t){let e=v.leftMostMapped(this.#r,t,this.#e,this.#t),r=this.#r[e];return f(r)&&this.#e(this.#t(r),t)===0?(this.#r.splice(e,1),r):null}removeRange(t,e){this.#r.splice(t,(e??this.#r.length)-t)}removeByPredicate(t){let e=0,r=this.#r.length;for(;--r>=0;)t(this.#r[r])&&(this.#r.splice(r,1),e++);return e}get(t){return x(this.#s(t),`Unknown key: ${t}`)}getOrThrow(t,e){let r=this.#s(t);if(f(r))return r;throw e()}opt(t){return p.wrap(this.#s(t))}getOrNull(t){return this.#s(t)??null}getByIndex(t){return this.#r[t]}hasKey(t){return f(this.#s(t))}hasValue(t){return f(this.#s(this.#t(t)))}size(){return this.#r.length}isEmpty(){return this.#r.length===0}forEach(t){this.values().forEach(t)}values(){return this.#r}entries(){return this.#r.map(t=>[this.#t(t),t])}clear(){g.clear(this.#r)}[Symbol.iterator](){return this.#r.values()}#s(t){let e=v.leftMostMapped(this.#r,t,this.#e,this.#t),r=this.#r[e];return f(r)&&this.#e(this.#t(r),t)===0?r:void 0}};var Je;(function(s){s.hyphenToCamelCase=t=>t.replace(/-([a-z])/g,e=>e[1].toUpperCase()),s.fallback=(t,e)=>f(t)&&t.length>0?t:e,s.endsWithDigit=t=>/\d$/.test(t),s.nonEmpty=(t,e)=>f(t)&&t.trim().length>0?t:e,s.toArrayBuffer=t=>{let e=new ArrayBuffer(t.length),r=new Uint8Array(e);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return e},s.getUniqueName=(t,e)=>{let r=new Set(t),n=e,i=1;if(r.has(e)||r.has(`${e} 1`))i=2;else return e;for(;r.has(n=`${e} ${i++}`););return n}})(Je||(Je={}));var Xe=(()=>{let s=p.None;return{info:t=>s.match({none:()=>Promise.resolve(),some:e=>e.info(t)}),approve:t=>s.match({none:()=>Promise.resolve(!0),some:e=>e.approve(t)}),progress:t=>s.match({none:()=>({message:"",terminate:Et}),some:e=>e.progress(t)}),install:t=>{y(s.isEmpty(),"RuntimeNotification already installed"),s=p.wrap(t)}}})();var Qe;(function(s){let t=new L;s.subscribe=e=>t.subscribe(e),s.dispatch=e=>t.notify(e)})(Qe||(Qe={}));var G=class s{static POSITIVE_INFINITY=new s(Number.POSITIVE_INFINITY);static millis=t=>new s(t);static seconds=t=>new s(t*s.#t);static minutes=t=>new s(t*s.#e);static hours=t=>new s(t*s.#r);static days=t=>new s(t*s.#s);static#t=1e3;static#e=6e4;static#r=36e5;static#s=864e5;#n;constructor(t){this.#n=t}millis(){return this.#n}absSeconds(){return Math.abs(this.#n)/s.#t}absMinutes(){return Math.abs(this.#n)/s.#e}absHours(){return Math.abs(this.#n)/s.#r}absDays(){return Math.abs(this.#n)/s.#s}split(){return{d:Math.floor(this.absDays()),h:Math.floor(this.absHours())%24,m:Math.floor(this.absMinutes())%60,s:Math.floor(this.absSeconds())%60}}isNow(){return this.#n===0}isPast(){return this.#n<0}isFuture(){return this.#n>0}toUnitString(){let t,e,r=Math.floor(Math.abs(this.#n)/1e3),n=Math.floor(r/60),i=Math.floor(n/60),o=Math.floor(i/24);return r<60?(t=r,e="second"):n<60?(t=n,e="minute"):i<24?(t=i,e="hour"):(t=o,e="day"),new Intl.RelativeTimeFormat("en",{numeric:"auto",style:"long"}).format(t*Math.sign(this.#n),e)}toString(){if(isNaN(this.#n))return"NaN";if(!isFinite(this.#n))return"\u221E";let{d:t,h:e,m:r,s:n}=this.split();return t>0?[s.#i("d",t),s.#i("h",e),s.#i("m",r),s.#i("s",n)].join(", "):e>0?[s.#i("h",e),s.#i("m",r),s.#i("s",n)].join(", "):r>0?[s.#i("m",r),s.#i("s",n)].join(", "):n>0?s.#i("s",n):"now"}static#i=(t,e)=>{switch(t){case"d":return`${e} ${e<2?"day":"days"}`;case"h":return`${e} ${e<2?"hour":"hours"}`;case"m":return`${e} ${e<2?"minute":"minutes"}`;case"s":return`${e} ${e<2?"second":"seconds"}`;default:return K(t)}}};var Ze;(function(s){let t;(function(e){e[e.READING=0]="READING",e[e.READ=1]="READ",e[e.WRITING=2]="WRITING",e[e.WRITTEN=3]="WRITTEN"})(t||(t={})),s.writer=(e,r,n)=>{if(e.bytesTotal+1>r.byteLength)return u("Insufficient memory allocated.");let i=new Uint8Array(r),o=N.use(r,1);return Atomics.store(i,0,t.READ),{tryWrite:()=>Atomics.compareExchange(i,0,t.READ,t.WRITING)===t.WRITING?(n(e.object),o.position=0,e.write(o),Atomics.store(i,0,t.WRITTEN),!0):!1}},s.reader=(e,r)=>{let n=new SharedArrayBuffer(e.bytesTotal+1),i=new Uint8Array(n),o=new R(n,1);return{buffer:n,tryRead:()=>Atomics.compareExchange(i,0,t.WRITTEN,t.READING)===t.READING?(o.position=0,e.read(o),r(e.object),Atomics.store(i,0,t.READ),!0):!1}}})(Ze||(Ze={}));var A;(function(s){s.length=16,s.generate=()=>t(crypto.getRandomValues(new Uint8Array(s.length))),s.sha256=async e=>{let r=typeof process<"u"&&process.env?.VITEST==="true";return crypto.subtle.digest("SHA-256",r?new Uint8Array(e.slice(0)):e).then(n=>t(new Uint8Array(n.slice(0,s.length))))},s.validateBytes=e=>s.parse(s.toString(e)),s.validateString=e=>/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e),s.asString=e=>s.validateString(e)?e:u(`Invalid UUID format: ${e}`),s.fromDataInput=e=>{let r=new Uint8Array(s.length);return e.readBytes(new Int8Array(r.buffer)),r},s.toDataOutput=(e,r)=>e.writeBytes(new Int8Array(r.buffer)),s.toString=e=>{let r=g.create(n=>(n+256).toString(16).substring(1),256);return r[e[0]]+r[e[1]]+r[e[2]]+r[e[3]]+"-"+r[e[4]]+r[e[5]]+"-"+r[e[6]]+r[e[7]]+"-"+r[e[8]]+r[e[9]]+"-"+r[e[10]]+r[e[11]]+r[e[12]]+r[e[13]]+r[e[14]]+r[e[15]]},s.parse=e=>{let r=e.replace(/-/g,"").toLowerCase();if(r.length!==32)return u("Invalid UUID format");let n=new Uint8Array(s.length);for(let i=0,o=0;i<32;i+=2,o++)n[o]=parseInt(r.slice(i,i+2),16);return n},s.Comparator=(e,r)=>{if(e.length!==s.length||r.length!==s.length)return u("Unexpected array length for uuid(v4)");for(let n=0;n<s.length;n++){let i=e[n]-r[n];if(i!==0)return i}return 0},s.equals=(e,r)=>s.Comparator(e,r)===0,s.newSet=e=>new pt(e,s.Comparator),s.Lowest=s.parse("00000000-0000-4000-8000-000000000000"),s.Highest=s.parse("FFFFFFFF-FFFF-4FFF-BFFF-FFFFFFFFFFFF"),s.fromInt=e=>{let r=new Uint8Array(s.Lowest),n=new Uint8Array(new Uint32Array([e]).buffer);for(let i=0;i<4;i++)r[i]=n[i];return r},s.zType=e=>e.string().refine(r=>s.validateString(r),{message:"Invalid UUID format"}).transform(r=>r);let t=e=>(y(e.length===s.length,"UUID must be 16 bytes long"),e[6]=e[6]&15|64,e[8]=e[8]&63|128,e)})(A||(A={}));var tr;(function(s){s.create=i=>f(i)?f(i?.snap)?s.snap(i?.trackLength,i?.snap?.snapLength,Array.isArray(i?.snap?.threshold)?i?.snap.threshold:[i?.snap?.threshold]):s.identity(i?.trackLength):s.identity(),s.snap=(i=t,o=e,a)=>new n(i,o/i,a),s.identity=(i=t)=>new r(i);let t=128,e=24;class r{length;#t=NaN;#e=NaN;#r=1;constructor(o){this.length=o}begin(o){this.#e=this.#t=o}moveBy(o){y(!isNaN(this.#e),()=>"value has never been set"),this.#t+=o/this.length*this.#r,this.#e=b(this.#t,0,1)}ratio(o){this.#r=o}value(){return y(!isNaN(this.#e),()=>"value has never been set"),this.#e}disable(){}enable(){}}class n{#t;#e;#r;#s;#n=NaN;#i=NaN;#a=1;#o=!0;constructor(o,a,c){y(a>0,()=>`margin(${a}) must be greater then 0`),y(g.isSorted(c),()=>"thresholds are not sorted"),y(a<o,()=>`margin(${a}) must be lower then length(${o})`),this.#t=o,this.#e=a,this.#r=c,this.#s=c.map((h,l)=>h+l*this.#e)}begin(o){this.#n=this.#o?this.valueToX(o):o,this.#i=o}moveBy(o){y(isFinite(this.#i)&&isFinite(this.#n),()=>"value has never been set (moveBy)"),this.#n+=o/this.#t*this.#a,this.#i=this.#o?this.xToValue(this.#n):b(this.#n,0,1)}ratio(o){this.#a=o}value(){return y(isFinite(this.#i),()=>"value has never been set (value)"),this.#i}disable(){this.#o&&(this.#o=!1,this.#n=this.xToValue(this.#n))}enable(){this.#o||(this.#o=!0,this.#n=this.valueToX(this.#n))}valueToX(o){let a=v.rightMost(this.#r,o,re);if(a<0)return o;{let c=this.#s[a],h=this.#r[a];return o===h?c+this.#e/2:c+this.#e+(o-h)}}xToValue(o){let a=b(o,0,1+this.#e*this.#r.length),c=v.rightMost(this.#s,a,re);if(c<0)return a;{let h=this.#s[c],l=this.#r[c];return a>h+this.#e?a-(h+this.#e)+l:l}}get margin(){return this.#e}}})(tr||(tr={}));var Ft;(function(s){class t extends Error{}s.Warning=t,s.warn=r=>{throw new t(r)};class e extends Error{constructor(n){super(`${n} not found`)}}s.FileNotFound=e,s.AbortError=typeof DOMException>"u"?{name:"AbortError",message:""}:Object.freeze(new DOMException("AbortError")),s.isAbort=r=>r===s.AbortError||s.isDOMException(r)&&r.name==="AbortError",s.CatchAbort=r=>r===s.AbortError?void 0:u(r),s.isOverconstrained=r=>st(r)&&"constraint"in r,s.isDOMException=r=>st(r)&&te(r,"name","string")&&te(r,"message","string"),s.toString=r=>{let n=i=>i.split(`
2
- `).slice(0,4).join(`
3
- `);if(r instanceof Error)return n(r.stack||r.message);if(typeof r=="string")return r;if(r&&typeof r=="object"){let i=r;if(i.stack)return n(i.stack);if(i.message)return i.message;try{return JSON.stringify(r,null,2)}catch{}}return String(r)}})(Ft||(Ft={}));var Ot=Symbol.for("@openDAW/lib-std");globalThis[Ot]?console.debug(`%c${Ot.description}%c is already available in ${globalThis.constructor.name}.`,"color: hsl(10, 83%, 60%)","color: inherit"):(globalThis[Ot]=!0,console.debug(`%c${Ot.description}%c is now available in ${globalThis.constructor.name}.`,"color: hsl(200, 83%, 60%)","color: inherit"));var _;(function(s){s.sender=(r,n)=>n(new t(r)),s.executor=(r,n)=>new e(r,n);class t{#t;#e=new Map;#r;#s=0;constructor(n){this.#t=n,this.#r=n.subscribe(this.#n)}terminate(){this.#r.terminate()}dispatchAndForget=(n,...i)=>this.#t.send({type:"send",returnId:!1,func:n.name,args:Array.from(k.map(i,o=>({value:o})))});dispatchAndReturn=(n,...i)=>new Promise((o,a)=>{let c=k.reduce(i,(h,l,d)=>(typeof l=="function"&&h.push([d,l]),h),[]);this.#e.set(this.#s,{executorTuple:{resolve:o,reject:a},callbacks:new Map(c)}),this.#t.send({type:"send",returnId:this.#s,func:n.name,args:Array.from(k.map(i,(h,l)=>typeof h=="function"?{callback:l}:{value:h}))}),this.#s++});#n=n=>{let i=this.#e.get(n.returnId);f(i)?n.type==="resolve"?(i.executorTuple.resolve(n.resolve),this.#e.delete(n.returnId)):n.type==="reject"?(i.executorTuple.reject(n.reject),this.#e.delete(n.returnId)):n.type==="callback"&&i.callbacks?.get(n.funcAt).apply(this,n.args):u(`Promise has already been resolved. ${JSON.stringify(n)}`)}}class e{#t;#e;#r;constructor(n,i){this.#t=n,this.#e=i,this.#r=n.subscribe(this.#s)}terminate(){this.#r.terminate()}#s=n=>{y(n.type==="send",()=>"Message type must be 'send'");let i=Object.getPrototypeOf(this.#e)===Object.getPrototypeOf({})?this.#e:Object.getPrototypeOf(this.#e),o=x(i[n.func],`${n.func.toString()} does not exists on ${this.#e}`),a=n.returnId;if(a===!1)o.apply(this.#e,n.args.map(c=>"value"in c?c.value:u(`${n.func.toString()} has no promise.`)));else try{o.apply(this.#e,n.args.map(h=>"callback"in h?(...l)=>this.#a(a,h.callback,l):h.value)).then(h=>{try{this.#n(a,h)}catch(l){this.#i(a,l)}},h=>this.#i(a,h))}catch(c){this.#i(a,c)}};#n=(n,i)=>this.#t.send({type:"resolve",returnId:n,resolve:i});#i=(n,i)=>this.#t.send({type:"reject",returnId:n,reject:i});#a=(n,i,o)=>this.#t.send({type:"callback",returnId:n,funcAt:i,args:o})}s.Executor=e})(_||(_={}));var er;(function(s){s.ProgressArrayBuffer=t=>async e=>{if(!e.headers.has("Content-Length"))return console.debug("No Content-Length"),e.arrayBuffer();let r=parseInt(e.headers.get("Content-Length"));if(console.debug(`Content-Length: ${r}b`),isNaN(r)||r<4096)return e.arrayBuffer();t(0);let n=N.create(r),i=x(e.body,"response.body is empty").getReader();for(;;){let{done:o,value:a}=await i.read();if(o)break;a.forEach(c=>n.writeByte(c)),t(n.position/r)}return t(1),n.toArrayBuffer()}})(er||(er={}));var rr;(function(s){s.debounce=(()=>{let t;return(e,r=1e3)=>{clearTimeout(t),t=setTimeout(e,r)}})(),s.scheduleInterval=(t,e,...r)=>{let n=setInterval(t,e,...r);return{terminate:()=>clearInterval(n)}},s.scheduleTimeout=(t,e,...r)=>{let n=setTimeout(t,e,...r);return{terminate:()=>clearTimeout(n)}}})(rr||(rr={}));var sr={for:s=>new me(s)},me=class{#t;#e=new L;constructor(t){if(this.#t=t,f(t.onmessage)||f(t.onmessageerror))throw console.error(t),new Error(`${t} is already wrapped.`);t.onmessage=e=>this.#e.notify(e.data),t.onmessageerror=e=>{throw new Error(e.type)}}send(t){this.#t.postMessage(t)}channel(t){return new ge(this,t)}subscribe(t){return this.#e.subscribe(t)}terminate(){this.#e.terminate(),this.#t.onmessage=null,this.#t.onmessageerror=null}},ge=class s{#t;#e;#r=new L;#s;constructor(t,e){this.#t=t,this.#e=e,this.#s=t.subscribe(r=>{"__id__"in r&&r.__id__==="42"&&"message"in r&&"channel"in r&&r.channel===e&&this.#r.notify(r.message)})}send(t){this.#t.send({__id__:"42",channel:this.#e,message:t})}channel(t){return new s(this,t)}subscribe(t){return this.#r.subscribe(t)}terminate(){this.#s.terminate(),this.#r.terminate()}};var $t;(function(s){s.frame=()=>new Promise(t=>requestAnimationFrame(()=>t())),s.frames=t=>new Promise(e=>{let r=t,n=()=>{--r<=0?e():requestAnimationFrame(n)};requestAnimationFrame(n)}),s.timeSpan=(t,...e)=>new Promise(r=>setTimeout(r,t.millis(),...e)),s.event=(t,e)=>new Promise(r=>t.addEventListener(e,r,{once:!0})),s.observable=t=>new Promise(e=>{let r=t.subscribe(()=>{r.terminate(),e()})}),s.complete=t=>new Promise((e,r)=>{let n=setInterval(()=>{let{status:i,value:o,error:a}=nt(()=>t.next());if(i==="success"){let{done:c,value:h}=o;c&&(clearInterval(n),e(h))}else clearInterval(n),r(a)},0)})})($t||($t={}));var ye=class{maxRetry;timeSpan;#t=0;constructor(t,e){this.maxRetry=t,this.timeSpan=e}retry(t,e){return++this.#t===this.maxRetry?!1:(console.debug(`${t} > will retry in ${this.timeSpan.toString()}`),setTimeout(e,this.timeSpan.millis()),!0)}},J;(function(s){class t{value;status="resolved";constructor(a){this.value=a}error=bt("Cannot access error when promise is resolved")}s.ResolveResult=t;class e{error;status="rejected";constructor(a){this.error=a}value=bt("Cannot access value when promise is rejected")}s.RejectedResult=e,s.makeAbortable=async(o,a)=>{let c=!0;return o.own(F.create(()=>c=!1)),new Promise((h,l)=>a.then(d=>{c&&h(d)},d=>{c&&l(d)}))},s.tryCatch=o=>o.then(a=>new t(a),a=>new e(a));let r=new ye(3,G.seconds(3));s.retry=(o,a=r)=>o().catch(c=>new Promise((h,l)=>{let d=E=>{a.retry(E,()=>o().then(S=>h(S),d))||l(E)};d(c)})),s.guardedRetry=(o,a)=>{let c=async(h=0)=>{try{return await o()}catch(l){if(a(l,++h))return console.debug("retrying after failure:",l),await $t.timeSpan(G.seconds(1)),c(h);throw new Error(`Failed after ${h} retries: ${l}`)}};return c()},s.approvedRetry=(o,a)=>{let c=async()=>{try{return await o()}catch(h){if(await Xe.approve(a(h)))return c();throw h}};return c()},s.fail=(o,a)=>{let c=()=>new Promise((h,l)=>setTimeout(()=>l("fails first"),o.millis()));return()=>{let h=c();return c=a,h}},s.timeout=(o,a,c)=>new Promise((h,l)=>{let d=!0,E=setTimeout(()=>{d=!1,l(new Error(c??"timeout"))},a.millis());o.then(S=>{d&&h(S)},S=>{d&&l(S)}).finally(()=>clearTimeout(E))}),s.sequentialAll=o=>o.reduce((a,c)=>a.then(async h=>[...h,await c()]),Promise.resolve([])),s.sequentialize=o=>{let a=Promise.resolve();return c=>{let h=()=>o(c),l=a.then(h,h);return a=l.catch(()=>{}),l}},s.memoizeAsync=(o,a)=>{let c=null,h=Date.now();return()=>{let l=Date.now();return(xt(c)||f(a)&&l-h>a.millis())&&(h=l,c=o(),c.catch(d=>(c=null,d))),c}},s.allWithLimit=async(o,a=1)=>{let c=new Array(o.length),h=0,l=!1,d=async()=>{for(;h<o.length&&!l;){let E=h++;try{let S=await o[E]();l||(c[E]=S)}catch(S){throw l=!0,S}}};return await Promise.all(Array.from({length:Math.min(a,o.length)},d)),c},s.allSettledWithLimit=async(o,a=1)=>{let c=new Array(o.length),h=0,l=async()=>{for(;h<o.length;){let d=h++;try{let E=await o[d]();c[d]={status:"fulfilled",value:E}}catch(E){c[d]={status:"rejected",reason:E}}}};return await Promise.all(Array.from({length:Math.min(a,o.length)},l)),c};class n{max;#t;#e=0;constructor(a=1){this.max=a,this.#t=[]}async add(a){if(this.#e<this.max)return this.#e++,a().finally(()=>this.#r());{let c=Promise.withResolvers();return this.#t.push([a,c]),c.promise.finally(()=>this.#r())}}#r(){if(y(this.#e>0,"Internal Error in Promises.Limit"),--this.#e<this.max&&this.#t.length>0){let[a,{resolve:c,reject:h}]=this.#t.shift();this.#e++,a().then(c,h)}}}s.Limit=n;class i{#t;#e;#r;#s=p.None;constructor(a,c,h){this.#t=a,this.#e=c,this.#r=h}update(a){this.#s=p.wrap(a),a.then(c=>{this.#s.contains(a)&&this.#t(c)}).catch(c=>{this.#s.contains(a)&&this.#e(c)}).finally(()=>{this.#s.contains(a)&&(this.terminate(),B(this.#r))})}terminate(){this.#s=p.None}}s.Latest=i})(J||(J={}));var nr;(function(s){let t=new J.Limit(4);s.limitFetch=(e,r)=>t.add(()=>fetch(e,r)),s.DefaultRetry=(e,r)=>!Zt(e,Ft.FileNotFound)||r<=100})(nr||(nr={}));var ir=(s="debug")=>{let t=performance.now();return{lab:e=>console[s].call(console,`${e} in ${(performance.now()-t).toFixed(1)}ms`)}};var or;(function(s){s.startEstimator=()=>{let t=performance.now();return e=>{if(e===0)return G.POSITIVE_INFINITY;let r=performance.now()-t;return G.millis(r/e-r)}}})(or||(or={}));var Rt=Symbol.for("@openDAW/lib-runtime");globalThis[Rt]?console.debug(`%c${Rt.description}%c is already available in ${globalThis.constructor.name}.`,"color: hsl(10, 83%, 60%)","color: inherit"):(globalThis[Rt]=!0,console.debug(`%c${Rt.description}%c is now available in ${globalThis.constructor.name}.`,"color: hsl(200, 83%, 60%)","color: inherit"));var I=class s{static newSet(t){return new pt(t,s.Comparator)}static compose=(t,...e)=>{let r=e.length===0?this.#t:new Int16Array(e);return y(r.every((n,i)=>n===e[i]),`fieldKeys (${r.join(",")}) only allows i16`),new s(t,r)};static decode(t){let e=t.split("/");return y(e.length>0,"Unable to parse Address"),s.compose(A.parse(e[0]),...e.slice(1).map(r=>parseInt(r)))}static reconstruct(t){return this.compose(t[0],...t[1])}static boxRange(t,e,r){let n=t.values(),i=v.leftMostMapped(n,e,A.Comparator,r),o=n.length;if(i<0||i>=o)return null;for(let a=i;a<o;a++)if(A.Comparator(r(n[a]),e)!==0)return i<a?[i,a]:null;return[i,o]}static Comparator=(t,e)=>{let r=A.Comparator(t.#e,e.#e);if(r!==0)return r;let n=Math.min(t.#r.length,e.#r.length);for(let i=0;i<n;i++){let o=t.#r[i]-e.#r[i];if(o!==0)return o}return t.#r.length-e.#r.length};static MinimalComparator=(t,e)=>{let r=A.Comparator(t.#e,e.#e);if(r!==0)return r;let n=Math.min(t.#r.length,e.#r.length);for(let i=0;i<n;i++){let o=t.#r[i]-e.#r[i];if(o!==0)return o}return 0};static LengthComparator=(t,e)=>{let r=A.Comparator(t.#e,e.#e);return r!==0?r:e.#r.length-t.#r.length};static#t=new Int16Array(0);#e;#r;constructor(t,e){this.#e=t,this.#r=e}get uuid(){return this.#e}get fieldKeys(){return this.#r}isBox(){return this.#r.length===0}isContent(){return!this.isBox()}equals(t){return s.Comparator(this,t)===0}compareTo(t){return s.Comparator(this,t)}append(t){return new s(this.#e,new Int16Array([...this.#r,t]))}startsWith(t){return A.Comparator(t.#e,this.#e)===0&&t.#r.length<=this.#r.length&&t.#r.every((e,r)=>this.#r[r]===e)}write(t){t.writeBytes(new Int8Array(this.#e.buffer)),t.writeByte(this.#r.length),this.#r.forEach(e=>t.writeShort(e))}moveTo(t){return new s(t,this.#r)}decompose(){return[this.#e,this.#r]}toJSON(){return{uuid:Array.from(this.#e.values()),fields:Array.from(this.#r.values())}}toArrayBuffer(){let t=new Uint8Array(A.length+this.#r.length);return t.set(this.#e,0),t.set(this.#r,A.length),t.buffer}toString(){return[A.toString(this.#e),...this.#r].join("/")}static read(t){let e=A.fromDataInput(t),r=t.readByte();return s.compose(e,...g.create(()=>t.readShort(),r))}},at;(function(s){s.AddressReader=t=>t.address,s.Comparator=({address:t},{address:e})=>I.Comparator(t,e),s.equals=(t,e)=>{let[r,n]=v.rangeMapped(e,t,I.Comparator,s.AddressReader);return e.slice(r,n+1)},s.startsWith=(t,e)=>{let[r,n]=v.rangeMapped(e,t,I.MinimalComparator,s.AddressReader);return e.slice(r,n+1).filter(i=>i.address.startsWith(t))},s.endsWith=(t,e)=>{let r=v.leftMostMapped(e,t,I.LengthComparator,s.AddressReader),n=v.rightMostMapped(e,t,I.MinimalComparator,s.AddressReader);return e.slice(r,n+1).filter(i=>t.startsWith(i.address))}})(at||(at={}));var U=class s{static validate(t,e){if(t.address.equals(e.address))return p.wrap(`PointerField cannot point to itself: ${t}`);if(!e.pointerRules.accepts.some(r=>r===t.pointerType)){let r=e.pointerRules.accepts.join(", ");return p.wrap(`${String(t.pointerType)} does not satisfy any of the allowed types (${r}).`)}return p.None}#t;#e;constructor(t){this.#t=t,this.#e=new It}subscribe(t,...e){return this.#r(this.#e,t,e)}catchupAndSubscribe(t,...e){let r=I.newSet(n=>n.address);return r.addMany(this.filter(...e)),r.forEach(n=>t.onAdded(n)),this.subscribe({onAdded:n=>{r.add(n)&&t.onAdded(n)},onRemoved:n=>{r.removeByKey(n.address),t.onRemoved(n)}},...e)}filter(...t){return t.length===0?this.incoming():k.filter(this.incoming().values(),e=>t.some(r=>r===e.pointerType))}size(){return this.incoming().length}isEmpty(){return this.size()===0}nonEmpty(){return this.size()>0}contains(t){return this.incoming().some(e=>t.address.equals(e.address))}incoming(){return this.#t.graph.edges().incomingEdgesOf(this.#t).slice()}onAdded(t){let e=s.validate(t,this.#t);if(e.nonEmpty())return u(e.unwrap());this.#e.proxy.onAdded(t)}onRemoved(t){this.#e.proxy.onRemoved(t)}toString(){return`{Pointers ${this.#t.address}, pointers: ${this.incoming().values().map(t=>t.toString())}}`}#r(t,e,r){return t.subscribe({onAdded:n=>{(r.length===0||r.some(i=>i===n.pointerType))&&e.onAdded(n)},onRemoved:n=>{(r.length===0||r.some(i=>i===n.pointerType))&&e.onRemoved(n)}})}};var we=function(s,t,e,r){var n=arguments.length,i=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(s,t,e,r);else for(var a=s.length-1;a>=0;a--)(o=s[a])&&(i=(n<3?o(i):n>3?o(t,e,i):o(t,e))||i);return n>3&&i&&Object.defineProperty(t,e,i),i},mt=function(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)},P=class s{static hook(t){return new s(t)}#t;#e;#r;#s;#n;constructor({parent:t,fieldKey:e,fieldName:r,pointerRules:n,deprecated:i}){this.#t=t,this.#e=e,this.#r=r,this.#s=n,this.#n=i,n.mandatory&&this.graph.edges().watchVertex(this)}accept(t){return B(t.visitField,this)}get box(){return this.#t.box}get graph(){return this.#t.graph}get parent(){return this.#t}get fieldKey(){return this.#e}get fieldName(){return this.#r}get pointerRules(){return this.#s}get deprecated(){return this.#n}get pointerHub(){return new U(this)}get address(){return this.#t.address.append(this.#e)}get debugPath(){return`${this.box.name}:${this.box.mapFields(t=>t.fieldName,...this.address.fieldKeys).join("/")}`}isBox(){return!1}isField(){return!0}isAttached(){return this.graph.findBox(this.address.uuid).nonEmpty()}fields(){return g.empty()}record(){return Mt.empty()}getField(t){return u()}optField(t){return p.None}read(t){}write(t){}toJSON(){}fromJSON(t){return u("fromJSON should never be called on a field")}disconnect(){if(this.pointerHub.isEmpty())return;let t=this.pointerHub.incoming();t.forEach(e=>{e.defer(),(e.mandatory||this.pointerRules.mandatory&&t.length===1)&&e.box.delete()})}toString(){return`{${this.box.constructor.name}:${this.constructor.name} (${this.fieldName}) ${this.address.toString()}`}};we([ut,mt("design:type",U),mt("design:paramtypes",[])],P.prototype,"pointerHub",null);we([ut,mt("design:type",I),mt("design:paramtypes",[])],P.prototype,"address",null);we([ut,mt("design:type",String),mt("design:paramtypes",[])],P.prototype,"debugPath",null);var Sr=Object.freeze({mandatory:!1,accepts:[]});var gt;(function(s){s.writeFields=(e,r)=>{let n=Object.entries(r).filter(([i,o])=>!o.deprecated);e.writeInt(1179403347),e.writeShort(n.length),n.forEach(([i,o])=>{let a=N.create();o.write(a);let c=new Int8Array(a.toArrayBuffer());e.writeShort(Number(i)),e.writeInt(c.length),e.writeBytes(c)})},s.readFields=(e,r)=>{y(e.readInt()===1179403347,"Serializer header is corrupt");let n=e.readShort();for(let i=0;i<n;i++){let o=e.readShort();if(Ne(r[o]))continue;let a=e.readInt(),c=new Int8Array(a);e.readBytes(c);let{status:h,error:l}=nt(()=>r[o]?.read(new R(c.buffer)));h==="failure"&&console.warn(r,l)}}})(gt||(gt={}));var vr=function(s,t,e,r){var n=arguments.length,i=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(s,t,e,r);else for(var a=s.length-1;a>=0;a--)(o=s[a])&&(i=(n<3?o(i):n>3?o(t,e,i):o(t,e))||i);return n>3&&i&&Object.defineProperty(t,e,i),i},ar=function(s,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(s,t)},xe=class s{static DEBUG_DELETION=!1;static Index=0;#t;#e;#r;#s;#n;#i=s.Index++;constructor({uuid:t,graph:e,name:r,pointerRules:n}){this.#t=I.compose(t),this.#e=e,this.#r=r,this.#s=n,this.#n=this.initializeFields(),n.mandatory&&this.graph.edges().watchVertex(this)}fields(){return Object.values(this.#n)}record(){return this.#n}getField(t){return x(this.#n[t],`Field ${String(t)} not found in ${this.toString()}`)}optField(t){return p.wrap(this.#n[t])}subscribe(t,e){return this.graph.subscribeVertexUpdates(t,this.address,e)}get box(){return this}get name(){return this.#r}get graph(){return this.#e}get parent(){return this}get address(){return this.#t}get pointerRules(){return this.#s}get creationIndex(){return this.#i}get pointerHub(){return new U(this)}estimateMemory(){let t=new lt;return this.write(t),t.count}isBox(){return!0}asBox(t){return Fe(this,t)}isField(){return!1}isAttached(){return this.#e.findBox(this.address.uuid).nonEmpty()}read(t){gt.readFields(t,this.#n)}write(t){gt.writeFields(t,this.#n)}serialize(){let t=N.create();return t.writeInt(this.#i),t.writeString(this.name),t.writeBytes(new Int8Array(this.address.uuid.buffer)),this.write(t),t.toArrayBuffer()}toArrayBuffer(){let t=N.create();return this.write(t),t.toArrayBuffer()}toJSON(){return Object.entries(this.#n).reduce((t,[e,r])=>{let n=r.toJSON();return f(n)&&(t[e]=n),t},{})}fromJSON(t){if(st(t))Object.entries(t).forEach(([e,r])=>{let n=this.#n[parseInt(e)];f(r)&&n.fromJSON(r)});else return u("Type mismatch")}incomingEdges(){return this.graph.edges().incomingEdgesOf(this)}outgoingEdges(){return this.graph.edges().outgoingEdgesOf(this)}mapFields(t,...e){if(e.length===0)return g.empty();let r=this.getField(e[0]),n=[t(r)];for(let i=1;i<e.length;i++)r=r.getField(e[i]),n.push(t(r));return n}searchVertex(t){if(t.length===0)return p.wrap(this);let e=this.optField(t[0]);if(e.isEmpty())return p.None;for(let r=1;r<t.length;r++)if(e=e.unwrap().optField(t[r]),e.isEmpty())return p.None;return e}delete(){if(!this.isAttached())return;let{boxes:t,pointers:e}=this.graph.dependenciesOf(this);s.DEBUG_DELETION&&(console.debug(`Delete ${this.toString()}`),console.debug(" unplugs",[...e].map(r=>r.toString()).join(`
4
- `)),console.debug(" unstages",[...t].map(r=>r.toString()).join(`
5
- `),this));for(let r of e)r.defer();for(let r of t)r.unstage();this.unstage()}unstage(){this.graph.unstageBox(this)}isValid(){if(this.#s.mandatory&&this.pointerHub.incoming().length===0)return!1;let t=e=>e.every(r=>r.accept({visitPointerField:n=>!n.mandatory||n.nonEmpty(),visitArrayField:n=>t(n.fields()),visitObjectField:n=>t(n.fields()),visitPrimitiveField:n=>!0,visitField:n=>!0})??!0);return t(this.fields())}toString(){return`${this.constructor.name} ${this.address.toString()}`}};vr([ut,ar("design:type",U),ar("design:paramtypes",[])],xe.prototype,"pointerHub",null);var D;(function(s){s[s.This=0]="This",s[s.Parent=1]="Parent",s[s.Children=2]="Children"})(D||(D={}));var be;(function(s){s.create=()=>new Ee})(be||(be={}));var Ee=class{#t=new St(at.equals);#e=new St(at.startsWith);#r=new St(at.endsWith);#s=[];#n=0;#i=!1;subscribe(t,e,r){let n=new Ae(e,t,this.#n++,r);if(this.#i){let i=new Ie(n,t);return this.#s.push(i),i}else return this.subscribeMonitor(n,t)}dispatch(t){this.#i=!0,[...this.#t.filter(t),...this.#e.filter(t),...this.#r.filter(t)].sort(({order:r},{order:n})=>r-n).forEach(r=>r.procedure(t)),this.#i=!1,this.#s.forEach(r=>r.subscribe(this)),this.#s.length=0}subscribeMonitor(t,e){switch(e){case D.This:return this.#t.subscribe(t);case D.Parent:return this.#e.subscribe(t);case D.Children:return this.#r.subscribe(t);default:return K(e)}}countStations(){return this.#t.count()+this.#e.count()+this.#r.count()}},Ae=class{address;propagation;order;procedure;constructor(t,e,r,n){this.address=t,this.propagation=e,this.order=r,this.procedure=n}toString(){return`{ Monitor address: ${this.address}, propagation: ${D[this.propagation]}, order: ${this.order} }`}},St=class{filterStrategy;#t=[];#e=!0;constructor(t){this.filterStrategy=t}subscribe(t){return this.#t.push(t),this.#e=this.#t.length<2,{terminate:()=>{let e=this.#t.length;for(;--e>=0;)this.#t[e]===t&&this.#t.splice(e,1)}}}stations(){return this.#e||(this.#t.sort(at.Comparator),this.#e=!0),this.#t}filter(t){return this.filterStrategy(t.address,this.stations())}count(){return this.#t.length}},Ie=class{monitor;propagation;#t=new ot;#e=!1;constructor(t,e){this.monitor=t,this.propagation=e}subscribe(t){this.#e||(this.#t.terminate(),this.#t.own(t.subscribeMonitor(this.monitor,this.propagation)))}terminate(){this.#e=!0,this.#t.terminate()}};var T;(function(s){s.Boolean="boolean",s.Float32="float32",s.Int32="int32",s.String="string",s.Bytes="bytes"})(T||(T={}));var Pt={[T.Boolean]:{type:T.Boolean,encode:(s,t)=>s.writeBoolean(t),decode:s=>s.readBoolean()},[T.Float32]:{type:T.Float32,encode:(s,t)=>s.writeFloat(t),decode:s=>s.readFloat()},[T.Int32]:{type:T.Int32,encode:(s,t)=>s.writeInt(t),decode:s=>s.readInt()},[T.String]:{type:T.String,encode:(s,t)=>s.writeString(t),decode:s=>s.readString()},[T.Bytes]:{type:T.Bytes,encode:(s,t)=>{s.writeInt(t.length),s.writeBytes(t)},decode:s=>{let t=new Int8Array(s.readInt());return s.readBytes(t),t}}},Vt=class extends P{#t;#e;#r;constructor(t,e,r){super(t),this.#t=e,this.#e=this.clamp(r),this.#r=this.#e}accept(t){return B(t.visitPrimitiveField,this)}subscribe(t){return this.graph.subscribeVertexUpdates(D.This,this.address,()=>t(this))}catchupAndSubscribe(t){return t(this),this.subscribe(t)}get type(){return this.#t}get initValue(){return this.#e}setInitValue(t){y(this.graph.constructingBox(),"Cannot change initial value at runtime"),this.setValue(this.#e=this.clamp(t))}getValue(){return this.#r}setValue(t){let e=this.#r,r=this.clamp(t);this.equals(r)||(this.#r=r,this.graph.onPrimitiveValueUpdate(this,e,r))}writeValue(t,e){y(!this.deprecated,"PrimitiveField.write: deprecated field"),this.serialization().encode(t,e)}readValue(t){return this.serialization().decode(t)}toJSON(){if(this.deprecated)return;let t=this.getValue();return ArrayBuffer.isView(t)?u("not implemented"):t}fromJSON(t){return u("Type mismatch")}reset(){this.setValue(this.#e)}};var Lt=class s extends Vt{static create(t,e=0){return new s(t,e)}constructor(t,e){super(t,T.Int32,e)}serialization(){return Pt[T.Int32]}equals(t){return this.getValue()===t}clamp(t){return V.toInt(t)}read(t){this.setValue(t.readInt())}write(t){y(!this.deprecated,"Int32Field.write: deprecated field"),t.writeInt(this.getValue())}fromJSON(t){this.deprecated||(typeof t=="number"&&t===Math.floor(t)&&t>=V.MIN_VALUE&&t<=V.MAX_VALUE?this.setValue(t):console.warn("Int32Field Type mismatch",t,this.address.toString()))}};var cr=class s extends Vt{static create(t,e=this.#t){return new s(t,e)}static#t=Object.freeze(new Int8Array(0));constructor(t,e){super(t,T.Bytes,e)}serialization(){return Pt[T.Bytes]}equals(t){return this.getValue().length===t.length&&this.getValue().every((e,r)=>t[r]===e)}clamp(t){return t}read(t){let e=new Int8Array(t.readInt());t.readBytes(e),this.setValue(e)}write(t){y(!this.deprecated,"ByteArrayField.write: deprecated field");let e=this.getValue();t.writeInt(e.length),t.writeBytes(e)}toJSON(){if(!this.deprecated)return Array.from(this.getValue().values())}fromJSON(t){this.deprecated||(Array.isArray(t)&&t.every(e=>typeof e=="number")?this.setValue(new Int8Array(t)):console.warn("ByteArrayField Type mismatch",t,this.address.toString()))}};var hr;(function(s){s.decode=t=>{let e=t.readInt();return g.create(()=>{switch(t.readString()){case"new":{let n=A.fromDataInput(t),i=t.readString(),o=new Int8Array(t.readInt());return t.readBytes(o),new Dt(n,i,o.buffer)}case"pointer":{let n=I.read(t),i=t.readBoolean()?p.wrap(I.read(t)):p.None,o=t.readBoolean()?p.wrap(I.read(t)):p.None;return new kt(n,i,o)}case"primitive":{let n=I.read(t),i=t.readString(),o=Pt[i],a=o.decode(t),c=o.decode(t);return new Ct(n,o,a,c)}case"delete":{let n=A.fromDataInput(t),i=t.readString(),o=new Int8Array(t.readInt());return t.readBytes(o),new _t(n,i,o.buffer)}}},e)}})(hr||(hr={}));var Dt=class{type="new";#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}get uuid(){return this.#t}get name(){return this.#e}get settings(){return this.#r}forward(t){t.createBox(this.#e,this.#t,e=>e.read(new R(this.#r)))}inverse(t){t.findBox(this.#t).unwrap(()=>`Could not find ${this.#e}`).unstage()}write(t){t.writeString(this.type),A.toDataOutput(t,this.#t),t.writeString(this.#e),t.writeInt(this.#r.byteLength),t.writeBytes(new Int8Array(this.#r))}toString(){return`{NewUpdate uuid: ${A.toString(this.#t)}, attachment: ${this.settings.byteLength}b`}toDebugString(t){return this.toString()}},Ct=class{type="primitive";#t;#e;#r;#s;constructor(t,e,r,n){this.#t=t,this.#e=e,this.#r=r,this.#s=n}get address(){return this.#t}get oldValue(){return this.#r}get newValue(){return this.#s}matches(t){return t.address.equals(this.address)}inverse(t){this.field(t).setValue(this.#r)}forward(t){this.field(t).setValue(this.#s)}field(t){return t.findVertex(this.#t).unwrap(()=>`Could not find PrimitiveField at ${this.#t}`)}write(t){t.writeString(this.type),this.#t.write(t),t.writeString(this.#e.type),this.#e.encode(t,this.#r),this.#e.encode(t,this.#s)}toString(){return`{PrimitiveUpdate oldValue: ${this.#r}, newValue: ${this.#s}`}},kt=class{type="pointer";#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}get address(){return this.#t}get oldAddress(){return this.#e}get newAddress(){return this.#r}matches(t){return t.address.equals(this.address)}inverse(t){this.field(t).targetAddress=this.#e}forward(t){this.field(t).targetAddress=this.#r}field(t){return t.findVertex(this.#t).unwrap(()=>`Could not find PointerField at ${this.#t}`)}write(t){t.writeString(this.type),this.#t.write(t),this.#e.match({none:()=>t.writeBoolean(!1),some:e=>{t.writeBoolean(!0),e.write(t)}}),this.#r.match({none:()=>t.writeBoolean(!1),some:e=>{t.writeBoolean(!0),e.write(t)}})}toString(){return`{PointerUpdate oldValue: ${this.#e.unwrapOrNull()}, newValue: ${this.#r.unwrapOrNull()}`}},_t=class{type="delete";#t;#e;#r;constructor(t,e,r){this.#t=t,this.#e=e,this.#r=r}get uuid(){return this.#t}get name(){return this.#e}get settings(){return this.#r}forward(t){t.findBox(this.#t).unwrap(()=>`Could not find ${this.#e}`).unstage()}inverse(t){t.createBox(this.#e,this.#t,e=>e.read(new R(this.#r)))}write(t){t.writeString(this.type),A.toDataOutput(t,this.#t),t.writeString(this.#e),t.writeInt(this.#r.byteLength),t.writeBytes(new Int8Array(this.#r))}toString(){return`{DeleteUpdate uuid: ${A.toString(this.#t)}, attachment: ${this.settings.byteLength}b`}};var pa=Symbol("Unreferenceable"),Se=class s extends P{static create(t,e,r){return new s(t,e,r)}static encodeWith(t,e){y(this.#t.isEmpty(),"SerializationEncoder already in use"),this.#t=p.wrap(t);let r=nt(e);if(this.#t=p.None,r.status==="failure")throw r.error;return r.value}static decodeWith(t,e){y(this.#e.isEmpty(),"SerializationDecoder already in use"),this.#e=p.wrap(t);let r=nt(e);if(this.#e=p.None,r.status==="failure")throw r.error;return r.value}static#t=p.None;static#e=p.None;#r;#s;#n=p.None;#i=p.None;constructor(t,e,r){super(t),this.#r=e,this.#s=r,r&&this.graph.edges().watchVertex(this)}get pointerHub(){return u(`${this} cannot be pointed to`)}get pointerType(){return this.#r}get mandatory(){return this.#s}accept(t){return B(t.visitPointerField,this)}subscribe(t){return this.graph.subscribeVertexUpdates(D.This,this.address,()=>this.graph.subscribeEndTransaction(()=>t(this)))}catchupAndSubscribe(t){return t(this),this.subscribe(t)}refer(t){this.targetVertex=p.wrap(t)}defer(){this.targetVertex=p.None}get targetVertex(){return this.graph.inTransaction()?this.#i.flatMap(t=>this.graph.findVertex(t)):this.#n}set targetVertex(t){if(t.nonEmpty()){let e=U.validate(this,t.unwrap());e.nonEmpty()&&u(e.unwrap())}this.targetAddress=t.map(e=>e.address)}get targetAddress(){return this.#i}set targetAddress(t){let e=this.#i;e.isEmpty()&&t.isEmpty()||(t.nonEmpty()&&e.unwrapOrNull()?.equals(t.unwrap()))===!0||(this.#i=t,this.graph.onPointerAddressUpdated(this,e,t))}isEmpty(){return this.targetAddress.isEmpty()}nonEmpty(){return this.targetAddress.nonEmpty()}resolvedTo(t){this.#n=t}read(t){let e=t.readBoolean()?p.wrap(I.read(t)):p.None;this.targetAddress=s.#e.match({none:()=>e,some:r=>r.map(this,e)})}write(t){y(!this.deprecated,"PointerField.write: deprecated field"),s.#t.match({none:()=>this.#i,some:e=>e.map(this)}).match({none:()=>t.writeBoolean(!1),some:e=>{t.writeBoolean(!0),e.write(t)}})}toJSON(){if(!this.deprecated)return s.#t.match({none:()=>this.#i,some:t=>t.map(this)}).match({none:()=>null,some:t=>t.toString()})}fromJSON(t){if(!this.deprecated)if(xt(t)||typeof t=="string"){let e=p.wrap(xt(t)?null:I.decode(t));this.targetAddress=s.#e.match({none:()=>e,some:r=>r.map(this,e)})}else return u(`Pointer: Type mismatch. value (${typeof t}) must be a string.`)}};var lr;(function(s){s.insertOrder=(t,e=Number.MAX_SAFE_INTEGER)=>{let r=s.collectIndexedBoxes(t),n=b(e,0,r.length);if(n<r.length)for(let i=n;i<r.length;i++)r[i].index.setValue(i+1);return n},s.removeOrder=(t,e)=>{let r=s.collectIndexedBoxes(t);if(e<r.length)for(let n=e+1;n<r.length;n++)r[n].index.setValue(n-1)},s.moveIndex=(t,e,r)=>{let n=s.collectIndexedBoxes(t),i=n[e];if(r<0){let o=b(e+r,0,n.length-1);for(let a=o;a<e;a++)n[a].index.setValue(a+1);i.index.setValue(o)}else if(r>1){let o=b(e+(r-1),0,n.length-1);for(let a=e;a<o;a++)n[a+1].index.setValue(a);i.index.setValue(o)}else console.warn(`moveIndex had no effect: startIndex: ${e}, delta: ${r}`)},s.isIndexedBox=t=>"index"in t&&t.index instanceof Lt,s.collectIndexedBoxes=(t,e)=>t.pointerHub.incoming().map(({box:r})=>s.isIndexedBox(r)&&(e===void 0||r instanceof e)?r:u(`${r} has no index field`)).sort((r,n)=>r.index.getValue()-n.index.getValue())})(lr||(lr={}));var Ut=Symbol.for("@openDAW/lib-box");globalThis[Ut]?console.debug(`%c${Ut.description}%c is already available in ${globalThis.constructor.name}.`,"color: hsl(10, 83%, 60%)","color: inherit"):(globalThis[Ut]=!0,console.debug(`%c${Ut.description}%c is now available in ${globalThis.constructor.name}.`,"color: hsl(200, 83%, 60%)","color: inherit"));var X;(function(s){let t=typeof self<"u"&&"location"in self&&typeof self.location!==void 0,e=typeof self<"u"&&"navigator"in self&&typeof self.navigator!==void 0;s.isLocalHost=()=>t&&location.host.includes("localhost"),s.isMacOS=()=>e&&navigator.userAgent.includes("Mac OS X"),s.isWindows=()=>e&&navigator.userAgent.includes("Windows"),s.isChrome=()=>e&&/chrome|chromium|crios/.test(navigator.userAgent.toLowerCase())&&!/edg|opera|opr/.test(navigator.userAgent.toLowerCase()),s.isFirefox=()=>e&&navigator.userAgent.toLowerCase().includes("firefox"),s.isWeb=()=>!s.isTauriApp(),s.isVitest=typeof process<"u"&&process.env?.VITEST==="true",s.isTauriApp=()=>"__TAURI__"in window,s.userAgent=e?navigator.userAgent.replace(/^Mozilla\/[\d.]+\s*/,"").replace(/\bAppleWebKit\/[\d.]+\s*/g,"").replace(/\(KHTML, like Gecko\)\s*/g,"").replace(/\bSafari\/[\d.]+\s*/g,"").replace(/\s+/g," ").trim():"N/A",s.id=()=>{if(!t)return"";let r="__id__",n=localStorage.getItem(r);if(f(n))return n;let i=A.toString(A.generate());return localStorage.setItem(r,i),i}})(X||(X={}));var ur;(function(s){s.encode=async(t,e="gzip")=>{let r=new CompressionStream(e),n=r.writable.getWriter();return n.write(new Uint8Array(t)),n.close(),new Response(r.readable).arrayBuffer()},s.decode=async(t,e="gzip")=>{let r=new DecompressionStream(e),n=r.writable.getWriter();return n.write(new Uint8Array(t)),n.close(),new Response(r.readable).arrayBuffer()}})(ur||(ur={}));var fr;(function(s){s.exportMethod=(n,i)=>r(n,{value:i}),s.exportBoolean=(n,i=!1)=>{let o=new Bt(i);return s.exportAccessor(n,()=>o.getValue(),a=>{let c=!!a;console.debug(`set to ${c}`),o.setValue(c)}),o},s.exportAccessor=(n,i,o=$e)=>r(n,{get:()=>{try{return console.debug(i()),0}catch(a){return console.error(a),1}},set:a=>{try{return o(a),i()}catch(c){return console.error(c),1}},enumerable:!1,configurable:!1});let t=(()=>{try{return self}catch{return{}}})(),e=t.opendaw??={},r=(n,i)=>{let o=n.split("."),a=o.splice(-1)[0],c=e;for(let h of o)c=c[h]??={};Object.defineProperty(c,a,i),console.debug(`Console command 'opendaw.${n}' exported`)}})(fr||(fr={}));var dr;(function(s){s.resolveString=t=>{if(!Be(t)){if(typeof t=="string")return t;if(Array.isArray(t))return t.join(",");if(typeof t=="object"){if(typeof t.exact=="string")return t.exact;if(Array.isArray(t.exact))return t.exact.join(",");if(typeof t.ideal=="string")return t.ideal;if(Array.isArray(t.ideal))return t.ideal.join(",")}}}})(dr||(dr={}));var pr;(function(s){s.truncateText=(t,e,r)=>{if(e.length===0)return{text:"",width:0};let n=t.measureText(e).width;if(n<=r)return{text:e,width:n};let i=t.measureText("\u2026").width,o=0,a=e.length|0;for(;o<a;){let h=a+o>>>1;n=t.measureText(e.substring(0,h+1)).width+i,n<=r?o=h+1:a=h}if(o===0)return{text:"",width:0};let c=e.substring(0,o);return{text:c+"\u2026",width:t.measureText(c).width+i}}})(pr||(pr={}));var mr;(function(s){s.calc=(e,r,n)=>{let i=/([0-9]*\.?[0-9]+)([a-zA-Z%]*)/g,o=e;return o.split(/\+|(?<!\d)-/).flatMap(a=>Array.from(a.matchAll(i))).forEach(([a,c,h])=>{let l=parseFloat(c);if(isNaN(l))return u(`${a} does not contain a number`);if(h==="em")o=o.replaceAll(a,`${l*n}`);else if(h==="%")o=o.replaceAll(a,`${l/100*r}`);else if(h==="px")o=o.replaceAll(a,`${l}`);else return u(`Unknown unit '${h}'`)}),Function(`return ${o}`)()};let t=new Map;s.registerCustomCursor=(e,r)=>t.set(e,r),s.setCursor=(e,r=document)=>{r.documentElement.style.cursor=typeof e=="number"?t.get(e)??"auto":e}})(mr||(mr={}));var vt;(function(s){let t=new Set,e=new Set,r=new Array,n=-1,i=null;s.add=a=>(e.add(a),{terminate:()=>e.delete(a)}),s.once=a=>{t.add(a)},s.start=a=>{i!==a&&(i?.cancelAnimationFrame(n),i=a,n=a.requestAnimationFrame(o))},s.stop=()=>{i?.cancelAnimationFrame(n),i=null,n=-1},s.terminate=()=>{s.stop(),r.length=0,e.clear(),t.clear()};let o=()=>{(e.size>0||t.size>0)&&(e.forEach(a=>r.push(a)),t.forEach(a=>r.push(a)),t.clear(),r.forEach(a=>a()),r.length=0),n=i?.requestAnimationFrame(o)??-1}})(vt||(vt={}));var M=class{static subscribe(t,e,r,n){return t.addEventListener(e,r,n),{terminate:()=>t.removeEventListener(e,r,n)}}static subscribeAny(t,e,r,n){return t.addEventListener(e,r,n),{terminate:()=>t.removeEventListener(e,r,n)}}static DOUBLE_DOWN_THRESHOLD=200;static subscribeDblDwn=(t,e)=>{let r=0;return this.subscribe(t,"pointerdown",n=>{let i=performance.now();i-r<this.DOUBLE_DOWN_THRESHOLD&&e(n),r=i},{capture:!0})};static PreventDefault=t=>t.preventDefault();static isTextInput=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLElement&&f(t.getAttribute("contenteditable"))};var Q;(function(s){s.isControlKey=({ctrlKey:t,metaKey:e})=>X.isMacOS()?e:t,s.isCopyKey=({altKey:t})=>t,s.GlobalShortcut=Object.freeze({isDelete:t=>!M.isTextInput(t.target)&&(t.code==="Delete"||t.code==="Backspace"),isSelectAll:t=>s.isControlKey(t)&&!t.shiftKey&&t.code==="KeyA",isDeselectAll:t=>s.isControlKey(t)&&t.shiftKey&&t.code==="KeyA"})})(Q||(Q={}));var gr;(function(s){s.usePointerLock=!1,s.attach=(t,e,r)=>{let n=new ot;return F.many(n,M.subscribe(t,"pointerdown",i=>{if(r?.multiTouch!==!0&&!i.isPrimary||i.buttons!==1||X.isMacOS()&&i.ctrlKey)return;let o=e(i);if(o.isEmpty())return;let a=o.unwrap(),c=i.pointerId;i.stopPropagation(),i.stopImmediatePropagation(),t.setPointerCapture(c);let h=r?.pointerLock!==!1&&s.usePointerLock,l=r?.pointerLockThreshold??16,d=t instanceof Element?t:null,E=!1,S=(m,W)=>{if(!h||d===null||E)return;let tt=m<l,j=m>window.innerWidth-l,O=W<l,Y=W>window.innerHeight-l;(tt||j||O||Y)&&(d.requestPointerLock?.(),E=!0)},w={clientX:i.clientX,clientY:i.clientY,altKey:i.altKey,shiftKey:i.shiftKey,ctrlKey:Q.isControlKey(i)};r?.immediate===!0&&a.update(w),r?.permanentUpdates===!0?(n.own(vt.add(()=>a.update(w))),n.own(M.subscribe(t,"pointermove",m=>{m.pointerId===c&&(d!==null&&document.pointerLockElement===d?(w.clientX+=m.movementX,w.clientY+=m.movementY):(w.clientX=m.clientX,w.clientY=m.clientY,S(m.clientX,m.clientY)),w.altKey=m.altKey,w.shiftKey=m.shiftKey,w.ctrlKey=Q.isControlKey(m))}))):n.own(M.subscribe(t,"pointermove",m=>{m.pointerId===c&&(d!==null&&document.pointerLockElement===d?(w.clientX+=m.movementX,w.clientY+=m.movementY):(w.clientX=m.clientX,w.clientY=m.clientY,S(m.clientX,m.clientY)),w.altKey=m.altKey,w.shiftKey=m.shiftKey,w.ctrlKey=Q.isControlKey(m),a.update(w))}));let z=()=>{E&&d!==null&&document.pointerLockElement===d&&document.exitPointerLock(),a.cancel?.call(a),a.finally?.call(a),n.terminate()},q=Oe(t,"ownerDocument","defaultView")??self;n.ownAll(M.subscribe(t,"pointerup",m=>{m.pointerId===c&&(E&&d!==null&&document.pointerLockElement===d&&document.exitPointerLock(),a.approve?.call(a),a.finally?.call(a),n.terminate())},{capture:!0}),M.subscribe(t,"pointercancel",m=>{console.debug(m.type),m.pointerId===c&&(t.releasePointerCapture(c),z())},{capture:!0}),M.subscribe(q,"beforeunload",m=>{t.releasePointerCapture(c),z()},{capture:!0}),M.subscribe(q,"keydown",m=>{w.altKey=m.altKey,w.shiftKey=m.shiftKey,w.ctrlKey=Q.isControlKey(m),m.key==="Escape"?z():a.update(w)}),M.subscribe(q,"keyup",m=>{w.altKey=m.altKey,w.shiftKey=m.shiftKey,w.ctrlKey=Q.isControlKey(m),a.update(w)})),f(a.abortSignal)&&n.own(M.subscribe(a.abortSignal,"abort",()=>{t.releasePointerCapture(c),z()}))}))}})(gr||(gr={}));var yr;(function(s){s.save=async(t,e)=>{if(f(window.showSaveFilePicker)){let r=await window.showSaveFilePicker(e),n=await r.createWritable();return await n.truncate(0),await n.write(t),await n.close(),r.name??"unknown"}else{let r=new Blob([t]),n=URL.createObjectURL(r),i=document.createElement("a");return i.href=n,i.download=e?.suggestedName??"unknown",i.click(),URL.revokeObjectURL(n),e?.suggestedName??"Unknown"}},s.open=async t=>{if(f(window.showOpenFilePicker)){let{status:e,value:r,error:n}=await J.tryCatch(window.showOpenFilePicker(t));return e==="rejected"?Promise.reject(n):Promise.all(r.map(i=>i.getFile()))}else return new Promise((e,r)=>{f(t)&&console.warn("FileApi.showOpenFilePicker is emulated in this browser. OpenFilePickerOptions are ignored.");let n=document.createElement("input");n.type="file",n.multiple=t?.multiple??!1,n.style.display="none",n.addEventListener("cancel",async()=>{n.remove(),r(new DOMException("cancel","AbortError"))}),n.addEventListener("change",async i=>{let a=i.target.files;f(a)?e(g.create(c=>x(a.item(c),`No file at index ${c}`),a.length)):r(new DOMException("cancel","AbortError")),n.remove()}),document.body.appendChild(n),n.click()})}})(yr||(yr={}));var wr;(function(s){s.parse=t=>{let e=document.createElement("div");if(e.innerHTML=t,e.childElementCount!==1)return u(`Source html has more than one root elements: '${t}'`);let r=e.firstChild;return r instanceof HTMLElement||r instanceof SVGSVGElement?r:u(`Cannot parse to HTMLOrSVGElement from '${t}'`)},s.empty=t=>{for(;t.firstChild!==null;)t.firstChild.remove()},s.query=(t,e=document)=>x(e.querySelector(t)),s.queryAll=(t,e=document)=>Array.from(e.querySelectorAll(t)),s.sanitize=t=>{t.querySelectorAll("script").forEach(e=>e.remove()),t.querySelectorAll("*").forEach(e=>{[...e.attributes].forEach(r=>{r.name.toLowerCase().startsWith("on")&&e.removeAttribute(r.name)})})},s.nextID=(()=>{let t=0;return()=>(++t).toString(16).padStart(4,"0")})(),s.adoptStyleSheet=(t,e)=>{y(t.includes("component"),`No 'component' found in: ${t}`);let r=`${e??"C"}${s.nextID()}`,n=new CSSStyleSheet;return n.replaceSync(t.replaceAll("component",`.${r}`)),n.cssRules.length===0?u(`No cssRules found in: ${t}`):(document.adoptedStyleSheets.push(n),r)},s.buildClassList=(...t)=>t.filter(e=>e!==!1&&e!==void 0).join(" "),s.readCssVarColor=(...t)=>{let e=document.createElement("div");document.body.appendChild(e);let r=t.map(n=>(e.style.color=n,Nt.parseCssRgbOrRgba(getComputedStyle(e).color)));return e.remove(),r},s.watchResize=(t,e,r)=>{let n=new ResizeObserver(([i],o)=>e(i,o));return n.observe(t,r),{terminate:()=>n.disconnect()}},s.watchIntersection=(t,e,r)=>{let n=new IntersectionObserver(e,r);return n.observe(t),{terminate:()=>n.disconnect()}},s.secureBoundingBox=t=>{let e=t.getBoundingClientRect();if(!At.isEmpty(e))return e;for(let r of t.children)At.union(e,s.secureBoundingBox(r));return e},s.unfocus=(t=self)=>{let e=t.document.activeElement;e!==null&&"blur"in e&&typeof e.blur=="function"&&e.blur()},s.selectContent=t=>{let e=document.createRange(),r=window.getSelection();f(r)&&(e.selectNodeContents(t),r.removeAllRanges(),r.addRange(e))},s.unselectContent=t=>{let e=window.getSelection();!f(e)||e.rangeCount===0||t.contains(e.getRangeAt(0).commonAncestorContainer)&&e.removeAllRanges()},s.limitChars=(t,e,r)=>{if(!(e in t))return u(`${e} not found in ${t}`);if(typeof t[e]!="string")return u(`${e} in ${t} is not a string`);if(t[e].length>r)if(t[e]=t[e].substring(0,r),t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)t.setSelectionRange(r,r);else{let n=t.ownerDocument,i=n.createRange(),o=n.defaultView?.getSelection();if(!f(o))return;i.selectNodeContents(t),i.collapse(!1),o.removeAllRanges(),o.addRange(i)}},s.EmptyGif="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="})(wr||(wr={}));var Dc=(()=>{let s={Cmd:"\u2318",Opt:"\u2325",Shift:"\u21E7"},t={Cmd:"Ctrl",Opt:"Alt",Shift:"\u21E7"};return Object.freeze({Mac:s,Win:t,System:X.isMacOS()?s:t})})();var xr;(function(s){s.read=async t=>{let e=[];for(;;){let{done:o,value:a}=await t.read();if(o)break;e.push(a)}let r=e.reduce((o,a)=>o+a.length,0),n=new Uint8Array(r),i=0;for(let o of e)n.set(o,i),i+=o.length;return n.buffer}})(xr||(xr={}));var br;(function(s){s.pathBuilder=()=>new class{#t="";moveTo(t,e){return this.#t+=`M${t.toFixed(3)} ${e.toFixed(3)}`,this}lineTo(t,e){return this.#t+=`L${t.toFixed(3)} ${e.toFixed(3)}`,this}quadratic(t,e,r,n){return this.#t+=`Q${t.toFixed(3)} ${e.toFixed(3)} ${r.toFixed(3)} ${n.toFixed(3)}`,this}quadraticTo(t,e){return this.#t+=`T${t.toFixed(3)} ${e.toFixed(3)}`,this}cubic(t,e,r,n,i,o){return this.#t+=`Q${t.toFixed(3)} ${e.toFixed(3)} ${r.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)} ${o.toFixed(3)}`,this}arc(t,e,r,n,i,o,a){return this.#t+=`A${t} ${e} ${r} ${n?1:0} ${i?1:0} ${o.toFixed(3)} ${a.toFixed(3)}`,this}circleSegment(t,e,r,n,i){let o=t+Math.cos(n)*r,a=e+Math.sin(n)*r,c=t+Math.cos(i)*r,h=e+Math.sin(i)*r,l=i-n;for(;l<0;)l+=Math.PI*2;return this.moveTo(o,a).arc(r,r,0,l>Math.PI,!0,c,h)}close(){return this.#t+="Z",this}get(){return this.#t}}})(br||(br={}));var Er;(function(s){let t=new Array;s.watchWeak=(r,n)=>{let i=new WeakRef(r),o=n(i);return t.push([i,o]),t.length===1&&e(),r};let e=()=>{console.debug("start weak watching");let r=setInterval(()=>{let n=t.length;for(;--n>=0;){let i=t[n];i[0].deref()===void 0&&(i[1].terminate(),t.splice(n,1),t.length===0&&clearInterval(r))}},1e3)}})(Er||(Er={}));var jt=Symbol.for("@openDAW/lib-dom");globalThis[jt]?console.debug(`%c${jt.description}%c is already available in ${globalThis.constructor.name}.`,"color: hsl(10, 83%, 60%)","color: inherit"):(globalThis[jt]=!0,console.debug(`%c${jt.description}%c is now available in ${globalThis.constructor.name}.`,"color: hsl(200, 83%, 60%)","color: inherit"));var Kt;(function(s){s[s.Float=0]="Float",s[s.FloatArray=1]="FloatArray",s[s.Integer=2]="Integer",s[s.IntegerArray=3]="IntegerArray",s[s.ByteArray=4]="ByteArray"})(Kt||(Kt={}));var zt;(function(s){s[s.WRITE=0]="WRITE",s[s.READ=1]="READ"})(zt||(zt={}));var qt;(function(s){s[s.ID=15793935]="ID",s[s.START=15790320]="START",s[s.END=986895]="END"})(qt||(qt={}));var Z;(function(s){class t{shift;numPeaks;dataOffset;constructor(r,n,i){this.shift=r,this.numPeaks=n,this.dataOffset=i}unitsEachPeak(){return 1<<this.shift}}s.Stage=t,s.unpack=(e,r)=>{switch(r){case 0:return H.intBitsToFloat(e);case 1:return H.intBitsToFloat(e>>16);default:return K(r)}}})(Z||(Z={}));var Wt=class s{stages;data;numFrames;numChannels;static from(t){y(t.readString()==="PEAKS","Wrong header");let e=t.readInt(),r=[];for(let c=0;c<e;c++){let h=t.readInt(),l=t.readInt(),d=t.readInt();t.readInt(),r[c]=new Z.Stage(d,l,h)}let n=t.readInt(),i=[];for(let c=0;c<n;c++){let h=new Int8Array(t.readInt());t.readBytes(h),i[c]=new Int32Array(h.buffer)}let o=t.readInt(),a=t.readInt();return new s(r,i,o,a)}static None=new s([],[],0,0);static findBestFit=(t,e=1200)=>{let r=t/e;if(r<=1)return new Uint8Array(0);let n=3,i=Math.floor(Math.log(r)/Math.LN2),o=Math.max(1,Math.floor(i/n));return new Uint8Array(g.create(a=>n*(a+1),o))};constructor(t,e,r,n){this.stages=t,this.data=e,this.numFrames=r,this.numChannels=n}nearest(t){if(this.stages.length===0)return null;let e=Math.floor(Math.log(Math.abs(t))/Math.LN2),r=this.stages.length;for(;--r>-1;)if(e>=this.stages[r].shift)return this.stages[r];return this.stages[0]}toArrayBuffer(){let t=N.create();t.writeString("PEAKS"),t.writeInt(this.stages.length);for(let e=0;e<this.stages.length;e++){let{dataOffset:r,numPeaks:n,shift:i}=this.stages[e];t.writeInt(r),t.writeInt(n),t.writeInt(i),t.writeInt((1<<i)-1)}t.writeInt(this.data.length);for(let e=0;e<this.data.length;e++){let r=new Int8Array(this.data[e].buffer);t.writeInt(r.length),t.writeBytes(r)}return t.writeInt(this.numFrames),t.writeInt(this.numChannels),t.toArrayBuffer()}toString(){return`{SamplePeaks num-stages: ${this.stages.length}}`}};var Yt;(function(s){s.install=r=>_.executor(r.channel("peaks"),new class{async generateAsync(n,i,o,a,c){return t(n,i,o,a,c).toArrayBuffer()}});let t=(r,n,i,o,a)=>{if(i.length!==a)return u(`Invalid numberOfChannels. Expected: ${a}. Got ${i.length}`);class c{min=Number.POSITIVE_INFINITY;max=Number.NEGATIVE_INFINITY;index=0}let h=ir(),l=n.length,[d,E]=e(n,o),S=g.create(()=>new Int32Array(E),a),w=(1<<d[0].shift)-1,z=a*o,q=0;for(let m=0;m<a;++m){let W=S[m],tt=i[m],j=g.create(()=>new c,l),O=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY,ct=0;for(let ht=0;ht<o;++ht){let yt=tt[ht];if(O=Math.min(yt,O),Y=Math.max(yt,Y),(++ct&w)===0){for(let et=0;et<l;++et){let wt=d[et],$=j[et];$.min=Math.min($.min,O),$.max=Math.max($.max,Y),((1<<wt.shift)-1&ct)===0&&(W[wt.dataOffset+$.index++]=s.pack($.min,$.max),$.min=Number.POSITIVE_INFINITY,$.max=Number.NEGATIVE_INFINITY)}O=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY}(++q&65535)===0&&r(q/z)}}return r(1),h.lab(`SamplePeaks '${self.constructor.name}'`),new Wt(d,S,o,a)},e=(r,n)=>{let i=0;return[g.create(a=>{let c=r[a],h=Math.ceil(n/(1<<c)),l=new Z.Stage(c,h,i);return i+=h,l},r.length),i]};s.pack=(r,n)=>{let i=H.floatToIntBits(r),o=H.floatToIntBits(n);return i|o<<16}})(Yt||(Yt={}));var Ar;(function(s){s.renderBlocks=(t,e,r,{u0:n,u1:i,v0:o,v1:a,x0:c,x1:h,y0:l,y1:d})=>{let E=(i-n)/(h-c),S=e.nearest(E);if(S===null)return;let w=(d-l-1)/(a-o),z=S.unitsEachPeak(),q=c-Math.floor(c),m=E/z,W=(n-q*E)/E*m,tt=Math.floor(W),j=0,O=0,Y=e.data[r];for(let ct=Math.floor(c);ct<Math.floor(h);ct++){let ht=W+m,yt=Math.floor(ht),et=!1;for(;tt<yt;){let Tt=Y[S.dataOffset+tt++];j=Math.min(Z.unpack(Tt,0),j),O=Math.max(Z.unpack(Tt,1),O),et=!0}let wt=l+Math.floor((j-o)*w),$=l+Math.floor((O-o)*w),Jt=Math.max(l,Math.min(wt,$)),Te=Math.min(d,Math.max(wt,$));if(t.fillRect(ct,Jt,1,Te===Jt?1:Te-Jt),et){let Tt=O;O=j,j=Tt}W=ht,tt=yt}}})(Ar||(Ar={}));var Ht;(function(s){s.init=r=>_.executor(r.channel("opfs"),new class{#t=new Map;async write(n,i){await this.#e(n,async()=>{let o=await this.#r(n,{create:!0});try{o.truncate(i.length),o.write(i.buffer,{at:0}),o.flush()}finally{o.close()}})}async read(n){return await this.#e(n,async()=>{let i=await this.#r(n);try{let o=i.getSize(),a=new Uint8Array(o);return i.read(a),a}finally{i.close()}})}async delete(n){await this.#e(n,async()=>{let i=e(n);return i.length===0?this.clear():this.#s(i.slice(0,-1)).then(o=>o.removeEntry(x(i.at(-1)),{recursive:!0}))})}async list(n){let i=e(n),{status:o,value:a}=await J.tryCatch(this.#s(i));if(o==="rejected")return g.empty();let c=[];for await(let{name:h,kind:l}of a.values())c.push({name:h,kind:l});return c}async clear(){let n=await navigator.storage.getDirectory();for await(let[i,o]of n.entries())o.kind==="file"?await n.removeEntry(i):o.kind==="directory"&&await n.removeEntry(i,{recursive:!0})}async#e(n,i){for(;;){let o=this.#t.get(n);if(Me(o)){await o;continue}let a=()=>u("Lock not acquired"),c=new Promise(h=>a=h);this.#t.set(n,c);try{return await i()}finally{this.#t.get(n)===c&&this.#t.delete(n),a()}}}async#r(n,i){let o=e(n);return await(await(await this.#s(o.slice(0,-1),i)).getFileHandle(x(o.at(-1)),i)).createSyncAccessHandle()}async#s(n,i){let o=await navigator.storage.getDirectory();for(let a of n)o=await o.getDirectoryHandle(a,i);return o}});let e=r=>{let n=r.replace(/^\/+|\/+$/g,"");return n===""?[]:n.split("/")}})(Ht||(Ht={}));var Gt=Symbol.for("@openDAW/lib-fusion");globalThis[Gt]?console.debug(`%c${Gt.description}%c is already available in ${globalThis.constructor.name}.`,"color: hsl(10, 83%, 60%)","color: inherit"):(globalThis[Gt]=!0,console.debug(`%c${Gt.description}%c is now available in ${globalThis.constructor.name}.`,"color: hsl(200, 83%, 60%)","color: inherit"));var ve=sr.for(self);Ht.init(ve);Yt.install(ve);ve.channel("initialize").send("ready");
1
+ var y=o=>o!=null,ut=o=>o===null;var mt=o=>o!==void 0;var x=(o,t="asDefined failed")=>o??p(R(t));var R=o=>o instanceof Function?o():o;var dt=(o,...t)=>o?.apply(null,t);var V=o=>{throw new Error(`Unhandled ${o}`)},p=o=>{throw typeof o=="string"?new Error(o):o},M=(o,t)=>o?void 0:p(R(t));var v=o=>new Proxy({},{get(){return p(o)}});var nt=class{value;status="success";constructor(t){this.value=t}error=v("Cannot access error when succeeded")},rt=class{error;status="failure";constructor(t){this.error=t}value=v("Cannot access value when failed")},pt=o=>{try{return new nt(o())}catch(t){return new rt(t)}};var H=()=>{};var it;(function(o){o[o.Ascending=1]="Ascending",o[o.Descending=-1]="Descending"})(it||(it={}));var b=class{static#t=Object.freeze(new Array(0));static empty=()=>this.#t;static clear=t=>{t.length=0};static replace=(t,e)=>{t.length=0,t.push(...e)};static consume=(t,e)=>{for(let s=0;s<t.length;)e(t[s])?t.splice(s,1):s++};static peekFirst=t=>t.at(0)??null;static peekLast=t=>t.at(-1)??null;static getFirst=(t,e)=>x(t.at(0),e);static getLast=(t,e)=>x(t.at(-1),e);static getPrev=(t,e)=>{let s=t.indexOf(e);return s===-1?p(`${e} not found in ${t}`):x(t.at((s-1)%t.length),"Internal Error")};static getNext=(t,e)=>{let s=t.indexOf(e);return s===-1?p(`${e} not found in ${t}`):x(t.at((s+1)%t.length),"Internal Error")};static removeLast=(t,e)=>x(t.pop(),e);static create=(t,e)=>{let s=new Array(e);for(let n=0;n<e;n++)s[n]=t(n);return s};static equals=(t,e)=>{if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0};static satisfy=(t,e)=>{if(t.length<2)return!0;let s=t[0];for(let n=1;n<t.length;n++)if(!e(s,t[n]))return!1;return!0};static remove=(t,e)=>{let s=t.indexOf(e);if(s===-1)return p(`${e} not found in ${t}`);t.splice(s,1)};static removeIf=(t,e)=>{for(let s=t.length-1;s>=0;s--)e(t[s])&&t.splice(s,1)};static removeOpt=(t,e)=>{let s=t.indexOf(e);return s===-1?!1:(t.splice(s,1),!0)};static hasDuplicates=t=>new Set(t).size<t.length;static removeDuplicates=t=>{let e=0,s=new Set;for(let n of t)s.has(n)||(s.add(n),t[e++]=n);return t.length=e,t};static removeDuplicateKeys=(t,e)=>{let s=0,n=new Set;for(let r of t){let i=r[e];n.has(i)||(n.add(i),t[s++]=r)}return t.length=s,t};static subtract(t,e,s){return t.filter(n=>!e.some(r=>s(n,r)))}static intersect(t,e,s){return t.filter(n=>e.some(r=>s(n,r)))}static merge(t,e,s){return[...t.filter(n=>!e.some(r=>s(n,r))),...e]}static*iterate(t){for(let e=0;e<t.length;e++)yield t[e]}static*iterateReverse(t){for(let e=t.length-1;e>=0;e--)yield t[e]}static*iterateStateFull(t){let e=t.length-1;for(let s=0;s<=e;s++)yield{value:t[s],isFirst:s===0,isLast:s===e}}static*iterateAdjacent(t){if(!(t.length<=1))for(let e=1,s=t[0];e<t.length;e++){let n=t[e];yield[s,n],s=n}}static isSorted(t,e=it.Ascending){if(t.length<2)return!0;let s=t[0];for(let n=1;n<t.length;n++){let r=t[n];if(Math.sign(s-r)===e)return!1;s=r}return!0}static toRecord(t,e){return t.reduce((s,n)=>(s[e(n)]=n,s),{})}static concatArrayBuffers(t,e){let s=new ArrayBuffer(t.byteLength+e.byteLength),n=new Uint8Array(s);return n.set(new Uint8Array(t),0),n.set(new Uint8Array(e),t.byteLength),s}};var T;(function(o){o.wrap=e=>y(e)?new t(e):o.None,o.from=e=>o.wrap(e()),o.tryFrom=e=>{try{return o.wrap(e())}catch{return o.None}},o.execute=(e,...s)=>o.wrap(e?.apply(null,s)),o.async=e=>e.then(s=>o.wrap(s),()=>o.None);class t{#t;constructor(s){this.#t=x(s)}unwrap(){return this.#t}unwrapOrElse(s){return this.#t}unwrapOrNull(){return this.#t}unwrapOrUndefined(){return this.#t}contains(s){return s===this.#t}match(s){return s.some(this.#t)}ifSome(s){return s(this.#t)}ifAbsent(s){}isEmpty(){return!1}nonEmpty(){return!0}map(s){return o.wrap(s(this.#t))}mapOr(s,n){return s(this.#t)}flatMap(s){return s(this.#t)}equals(s){return this.unwrapOrNull()===s.unwrapOrNull()}assert(s){return this}toString(){return`{Option.Some(${this.#t})}`}get[Symbol.toStringTag](){return this.toString()}}o.Some=t,o.None=new class{unwrap=e=>p(y(e)?R(e):"unwrap failed");unwrapOrElse=e=>R(e);unwrapOrNull=()=>null;unwrapOrUndefined=()=>{};contains=e=>!1;match=e=>e.none();ifSome=e=>{};ifAbsent=e=>e(void 0);isEmpty=()=>!0;nonEmpty=()=>!1;map=e=>o.None;mapOr=(e,s)=>R(s);flatMap=e=>o.None;equals=e=>e.isEmpty();assert=e=>p(R(e)??"assert failed");toString=()=>"{Option.None}";get[Symbol.toStringTag](){return this.toString()}}})(T||(T={}));var A=Math.PI*2,Ut=Math.PI/2,Vt=Math.PI/4,Ht=1/Math.sqrt(2),_=(o,t,e)=>Math.max(t,Math.min(o,e));var wt=o=>Math.pow(2,Math.ceil(Math.log(o)/Math.log(2)));var S=new DataView(new ArrayBuffer(8)),gt;(function(o){o.MIN_VALUE=-2147483648,o.MAX_VALUE=2147483647,o.toByte=t=>(S.setInt8(0,t),S.getInt8(0)),o.toShort=t=>(S.setInt16(0,t),S.getInt16(0)),o.toInt=t=>(S.setInt32(0,t),S.getInt32(0))})(gt||(gt={}));var O;(function(o){let s=new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT),n=new Float32Array(s),r=new Int32Array(s);o.floatToIntBits=i=>{let a=o.floatToRawIntBits(i);return(a&2139095040)===2139095040&&(a&8388607)!==0?2143289344:a},o.intBitsToFloat=i=>(r[0]=i,n[0]),o.floatToRawIntBits=i=>(n[0]=i,r[0]),o.toFloat32=i=>(S.setFloat32(0,i),S.getFloat32(0))})(O||(O={}));var B;(function(o){o.floatToIntBits=t=>{let e=O.floatToIntBits(t),s=e>>>16&32768,n=(e&2147483647)+4096;return n>=1199570944?(e&2147483647)>=1199570944?n<2139095040?s|31744:s|31744|(e&8388607)>>>13:s|31743:n>=947912704?s|n-939524096>>>13:n<855638016?s:(n=(e&2147483647)>>>23,s|(e&8388607|8388608)+(8388608>>>n-102)>>>126-n)},o.intBitsToFloat=t=>{let e=t&1023,s=t&31744;if(s===31744)s=261120;else if(s!==0){if(s+=114688,e===0&&s>115712)return O.intBitsToFloat((t&32768)<<16|s<<13|1023)}else if(e!==0){s=115712;do e<<=1,s-=1024;while((e&1024)===0);e&=1023}return O.intBitsToFloat((t&32768)<<16|(s|e)<<13)}})(B||(B={}));var xt;(function(o){let t=9218868437227405312n,e=4503599627370495n,s=new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT),n=new Float64Array(s),r=new BigInt64Array(s);o.float64ToLongBits=i=>{let a=o.float64ToRawLongBits(i);return(a&t)===t&&(a&e)!==0n?0x7ff8000000000000n:a},o.longBitsToFloat64=i=>(r[0]=i,n[0]),o.float64ToRawLongBits=i=>(n[0]=i,r[0]),o.clamp=i=>(S.setFloat64(0,i),S.getFloat64(0))})(xt||(xt={}));var F=class{static*empty(){}static one(t){return[t]}static count(t){let e=0;for(let s of t)e++;return e}static some(t,e){for(let s of t)if(e(s))return!0;return!1}static every(t,e){for(let s of t)if(!e(s))return!1;return!0}static reduce(t,e,s){let n=s,r=0;for(let i of t)n=e(n,i,r++);return n}static includes(t,e){for(let s of t)if(s===e)return!0;return!1}static forEach(t,e){for(let s of t)e(s)}static*map(t,e){let s=0;for(let n of t)yield e(n,s++)}static*take(t,e){let s=0;for(let n of t){if(s++>=e)return;yield n}}static filter(t,e){let s=[];for(let n of t)e(n)&&s.push(n);return s}static filterMap(t,e){let s=[];for(let n of t){let r=e(n);y(r)&&s.push(r)}return s}static reverse(t){let e=[];for(let s of t)e.push(s);return e.reverse()}static*pairWise(t){let e=t[Symbol.iterator](),{done:s,value:n}=e.next(),r=n;if(s!==!0)for(;;){let{done:i,value:a}=e.next();if(i===!0){yield[r,null];return}yield[r,a],r=a}}};var j=class o{static create(t=1024){return this.use(new ArrayBuffer(t))}static use(t,e=0){return new o(new DataView(t,e))}littleEndian=!1;#t;#e=0;constructor(t){this.#t=t}get remaining(){return this.#t.byteLength-this.#e}get position(){return this.#e}set position(t){t<0?p(`position(${t}) cannot be negative.`):t>this.#t.byteLength?p(`position(${t}) is outside range (${this.#t.byteLength}).`):this.#e=t}writeBoolean(t){this.writeByte(t?1:0)}writeByte(t){this.#s(1),this.#t.setInt8(this.#e++,t)}writeShort(t){this.#s(Int16Array.BYTES_PER_ELEMENT),this.#t.setInt16(this.#e,t,this.littleEndian),this.#e+=Int16Array.BYTES_PER_ELEMENT}writeInt(t){this.#s(Int32Array.BYTES_PER_ELEMENT),this.#t.setInt32(this.#e,t,this.littleEndian),this.#e+=Int32Array.BYTES_PER_ELEMENT}writeLong(t){this.#s(BigInt64Array.BYTES_PER_ELEMENT),this.#t.setBigInt64(this.#e,t,this.littleEndian),this.#e+=BigInt64Array.BYTES_PER_ELEMENT}writeFloat(t){this.#s(Float32Array.BYTES_PER_ELEMENT),this.#t.setFloat32(this.#e,t,this.littleEndian),this.#e+=Float32Array.BYTES_PER_ELEMENT}writeDouble(t){this.#s(Float64Array.BYTES_PER_ELEMENT),this.#t.setFloat64(this.#e,t,this.littleEndian),this.#e+=Float64Array.BYTES_PER_ELEMENT}writeBytes(t){this.#s(t.length);for(let e=0;e<t.length;++e)this.#t.setInt8(this.#e++,t[e])}writeString(t){let e=t.length;this.#s(Int32Array.BYTES_PER_ELEMENT+e*Int16Array.BYTES_PER_ELEMENT),this.writeInt(e);for(let s=0;s<e;s++)this.writeShort(t.charCodeAt(s))}toArrayBuffer(){return this.#t.buffer.slice(0,this.#e)}#s(t){let e=this.#t.byteLength;if(this.#e+t>e){let s=this.#t;this.#t=new DataView(new ArrayBuffer(wt(e+t)));for(let n=0;n<this.#e;n++)this.#t.setInt8(n,s.getInt8(n))}}};var G=Object.freeze({Empty:{terminate:H},create:o=>({terminate:o}),many:(...o)=>({terminate:()=>{for(;o.length>0;)o.pop().terminate()}})});var C=class{static subscribeMany(t,...e){return G.many(...e.map(s=>s.subscribe(()=>t(s))))}#t=new Set;subscribe(t){return this.#t.add(t),{terminate:()=>this.#t.delete(t)}}isEmpty(){return this.#t.size===0}notify(t){this.#t.forEach(e=>e(t))}observers(){return this.#t}terminate(){this.#t.clear()}};var Et=(()=>{let o=T.None;return{info:t=>o.match({none:()=>Promise.resolve(),some:e=>e.info(t)}),approve:t=>o.match({none:()=>Promise.resolve(!0),some:e=>e.approve(t)}),progress:t=>o.match({none:()=>({message:"",terminate:H}),some:e=>e.progress(t)}),install:t=>{M(o.isEmpty(),"RuntimeNotification already installed"),o=T.wrap(t)}}})();var D=class o{static POSITIVE_INFINITY=new o(Number.POSITIVE_INFINITY);static millis=t=>new o(t);static seconds=t=>new o(t*o.#t);static minutes=t=>new o(t*o.#e);static hours=t=>new o(t*o.#s);static days=t=>new o(t*o.#n);static#t=1e3;static#e=6e4;static#s=36e5;static#n=864e5;#r;constructor(t){this.#r=t}millis(){return this.#r}absSeconds(){return Math.abs(this.#r)/o.#t}absMinutes(){return Math.abs(this.#r)/o.#e}absHours(){return Math.abs(this.#r)/o.#s}absDays(){return Math.abs(this.#r)/o.#n}split(){return{d:Math.floor(this.absDays()),h:Math.floor(this.absHours())%24,m:Math.floor(this.absMinutes())%60,s:Math.floor(this.absSeconds())%60}}isNow(){return this.#r===0}isPast(){return this.#r<0}isFuture(){return this.#r>0}toUnitString(){let t,e,s=Math.floor(Math.abs(this.#r)/1e3),n=Math.floor(s/60),r=Math.floor(n/60),i=Math.floor(r/24);return s<60?(t=s,e="second"):n<60?(t=n,e="minute"):r<24?(t=r,e="hour"):(t=i,e="day"),new Intl.RelativeTimeFormat("en",{numeric:"auto",style:"long"}).format(t*Math.sign(this.#r),e)}toString(){if(isNaN(this.#r))return"NaN";if(!isFinite(this.#r))return"\u221E";let{d:t,h:e,m:s,s:n}=this.split();return t>0?[o.#i("d",t),o.#i("h",e),o.#i("m",s),o.#i("s",n)].join(", "):e>0?[o.#i("h",e),o.#i("m",s),o.#i("s",n)].join(", "):s>0?[o.#i("m",s),o.#i("s",n)].join(", "):n>0?o.#i("s",n):"now"}static#i=(t,e)=>{switch(t){case"d":return`${e} ${e<2?"day":"days"}`;case"h":return`${e} ${e<2?"hour":"hours"}`;case"m":return`${e} ${e<2?"minute":"minutes"}`;case"s":return`${e} ${e<2?"second":"seconds"}`;default:return V(t)}}};var P;(function(o){o.sender=(n,r)=>r(new e(n)),o.executor=(n,r)=>new s(n,r);let t=n=>{let r=[];for(let i of n)i instanceof MessagePort&&r.push(i),typeof ImageBitmap<"u"&&i instanceof ImageBitmap&&r.push(i),typeof OffscreenCanvas<"u"&&i instanceof OffscreenCanvas&&r.push(i);return r};class e{#t;#e=new Map;#s;#n=0;constructor(r){this.#t=r,this.#s=r.subscribe(this.#r)}terminate(){this.#s.terminate()}dispatchAndForget=(r,...i)=>{let a=t(i);this.#t.send({type:"send",returnId:!1,func:r.name,args:Array.from(F.map(i,c=>({value:c})))},a)};dispatchAndReturn=(r,...i)=>new Promise((a,c)=>{let l=F.reduce(i,(f,u,m)=>(typeof u=="function"&&f.push([m,u]),f),[]);this.#e.set(this.#n,{executorTuple:{resolve:a,reject:c},callbacks:new Map(l)});let h=t(i);this.#t.send({type:"send",returnId:this.#n,func:r.name,args:Array.from(F.map(i,(f,u)=>typeof f=="function"?{callback:u}:{value:f}))},h),this.#n++});#r=r=>{let i=this.#e.get(r.returnId);y(i)?r.type==="resolve"?(i.executorTuple.resolve(r.resolve),this.#e.delete(r.returnId)):r.type==="reject"?(i.executorTuple.reject(r.reject),this.#e.delete(r.returnId)):r.type==="callback"&&i.callbacks?.get(r.funcAt).apply(this,r.args):p(`Promise has already been resolved. ${JSON.stringify(r)}`)}}class s{#t;#e;#s;constructor(r,i){this.#t=r,this.#e=i,this.#s=r.subscribe(this.#n)}terminate(){this.#s.terminate()}#n=r=>{M(r.type==="send",()=>"Message type must be 'send'");let i=Object.getPrototypeOf(this.#e)===Object.getPrototypeOf({})?this.#e:Object.getPrototypeOf(this.#e),a=x(i[r.func],`${r.func.toString()} does not exists on ${this.#e}`),c=r.returnId;if(c===!1)a.apply(this.#e,r.args.map(l=>"value"in l?l.value:p(`${r.func.toString()} has no promise.`)));else try{a.apply(this.#e,r.args.map(h=>"callback"in h?(...f)=>this.#a(c,h.callback,f):h.value)).then(h=>{try{this.#r(c,h)}catch(f){this.#i(c,f)}},h=>this.#i(c,h))}catch(l){this.#i(c,l)}};#r=(r,i)=>this.#t.send({type:"resolve",returnId:r,resolve:i});#i=(r,i)=>this.#t.send({type:"reject",returnId:r,reject:i});#a=(r,i,a)=>this.#t.send({type:"callback",returnId:r,funcAt:i,args:a})}o.Executor=s})(P||(P={}));var yt={for:o=>new ot(o)},Nt=[],ot=class{#t;#e=new C;constructor(t){if(this.#t=t,y(t.onmessage)||y(t.onmessageerror))throw console.error(t),new Error(`${t} is already wrapped.`);t.onmessage=e=>this.#e.notify(e.data),t.onmessageerror=e=>{throw new Error(e.type)}}send(t,e){this.#t.postMessage(t,e??Nt)}channel(t){return new at(this,t)}subscribe(t){return this.#e.subscribe(t)}terminate(){this.#e.terminate(),this.#t.onmessage=null,this.#t.onmessageerror=null}},at=class o{#t;#e;#s=new C;#n;constructor(t,e){this.#t=t,this.#e=e,this.#n=t.subscribe(s=>{"__id__"in s&&s.__id__==="42"&&"message"in s&&"channel"in s&&s.channel===e&&this.#s.notify(s.message)})}send(t,e){this.#t.send({__id__:"42",channel:this.#e,message:t},e)}channel(t){return new o(this,t)}subscribe(t){return this.#s.subscribe(t)}terminate(){this.#n.terminate(),this.#s.terminate()}};var W;(function(o){o.frame=()=>new Promise(t=>requestAnimationFrame(()=>t())),o.frames=t=>new Promise(e=>{let s=t,n=()=>{--s<=0?e():requestAnimationFrame(n)};requestAnimationFrame(n)}),o.timeSpan=(t,...e)=>new Promise(s=>setTimeout(s,t.millis(),...e)),o.event=(t,e)=>new Promise(s=>t.addEventListener(e,s,{once:!0})),o.observable=t=>new Promise(e=>{let s=t.subscribe(()=>{s.terminate(),e()})}),o.complete=t=>new Promise((e,s)=>{let n=setInterval(()=>{let{status:r,value:i,error:a}=pt(()=>t.next());if(r==="success"){let{done:c,value:l}=i;c&&(clearInterval(n),e(l))}else clearInterval(n),s(a)},0)})})(W||(W={}));var ct=class{maxRetry;timeSpan;#t=0;constructor(t,e){this.maxRetry=t,this.timeSpan=e}retry(t,e){return++this.#t===this.maxRetry?!1:(console.debug(`${t} > will retry in ${this.timeSpan.toString()}`),setTimeout(e,this.timeSpan.millis()),!0)}},K;(function(o){class t{value;status="resolved";constructor(a){this.value=a}error=v("Cannot access error when promise is resolved")}o.ResolveResult=t;class e{error;status="rejected";constructor(a){this.error=a}value=v("Cannot access value when promise is rejected")}o.RejectedResult=e,o.makeAbortable=async(i,a)=>{let c=!0;return i.own(G.create(()=>c=!1)),new Promise((l,h)=>a.then(f=>{c&&l(f)},f=>{c&&h(f)}))},o.tryCatch=i=>i.then(a=>new t(a),a=>new e(a));let s=new ct(3,D.seconds(3));o.retry=(i,a=s)=>i().catch(c=>new Promise((l,h)=>{let f=u=>{a.retry(u,()=>i().then(m=>l(m),f))||h(u)};f(c)})),o.guardedRetry=(i,a)=>{let c=async(l=0)=>{try{return await i()}catch(h){if(a(h,++l))return console.debug("retrying after failure:",h),await W.timeSpan(D.seconds(1)),c(l);throw new Error(`Failed after ${l} retries: ${h}`)}};return c()},o.approvedRetry=(i,a)=>{let c=async()=>{try{return await i()}catch(l){if(await Et.approve(a(l)))return c();throw l}};return c()},o.fail=(i,a)=>{let c=()=>new Promise((l,h)=>setTimeout(()=>h("fails first"),i.millis()));return()=>{let l=c();return c=a,l}},o.timeout=(i,a,c)=>new Promise((l,h)=>{let f=!0,u=setTimeout(()=>{f=!1,h(new Error(c??"timeout"))},a.millis());i.then(m=>{f&&l(m)},m=>{f&&h(m)}).finally(()=>clearTimeout(u))}),o.sequentialAll=i=>i.reduce((a,c)=>a.then(async l=>[...l,await c()]),Promise.resolve([])),o.sequentialize=i=>{let a=Promise.resolve();return c=>{let l=()=>i(c),h=a.then(l,l);return a=h.catch(()=>{}),h}},o.memoizeAsync=(i,a)=>{let c=null,l=Date.now();return()=>{let h=Date.now();return(ut(c)||y(a)&&h-l>a.millis())&&(l=h,c=i(),c.catch(f=>(c=null,f))),c}},o.allWithLimit=async(i,a=1)=>{let c=new Array(i.length),l=0,h=!1,f=async()=>{for(;l<i.length&&!h;){let u=l++;try{let m=await i[u]();h||(c[u]=m)}catch(m){throw h=!0,m}}};return await Promise.all(Array.from({length:Math.min(a,i.length)},f)),c},o.allSettledWithLimit=async(i,a=1)=>{let c=new Array(i.length),l=0,h=async()=>{for(;l<i.length;){let f=l++;try{let u=await i[f]();c[f]={status:"fulfilled",value:u}}catch(u){c[f]={status:"rejected",reason:u}}}};return await Promise.all(Array.from({length:Math.min(a,i.length)},h)),c};class n{max;#t;#e=0;constructor(a=1){this.max=a,this.#t=[]}async add(a){if(this.#e<this.max)return this.#e++,a().finally(()=>this.#s());{let c=Promise.withResolvers();return this.#t.push([a,c]),c.promise.finally(()=>this.#s())}}#s(){if(M(this.#e>0,"Internal Error in Promises.Limit"),--this.#e<this.max&&this.#t.length>0){let[a,{resolve:c,reject:l}]=this.#t.shift();this.#e++,a().then(c,l)}}}o.Limit=n;class r{#t;#e;#s;#n=T.None;constructor(a,c,l){this.#t=a,this.#e=c,this.#s=l}update(a){this.#n=T.wrap(a),a.then(c=>{this.#n.contains(a)&&this.#t(c)}).catch(c=>{this.#n.contains(a)&&this.#e(c)}).finally(()=>{this.#n.contains(a)&&(this.terminate(),dt(this.#s))})}terminate(){this.#n=T.None}}o.Latest=r})(K||(K={}));var It=(o="debug")=>{let t=performance.now();return{lab:e=>console[o].call(console,`${e} in ${(performance.now()-t).toFixed(1)}ms`)}};var $;(function(o){class t{shift;numPeaks;dataOffset;constructor(s,n,r){this.shift=s,this.numPeaks=n,this.dataOffset=r}unitsEachPeak(){return 1<<this.shift}}o.Stage=t,o.unpack=(e,s)=>{switch(s){case 0:return B.intBitsToFloat(e);case 1:return B.intBitsToFloat(e>>16);default:return V(s)}}})($||($={}));var X=class o{stages;data;numFrames;numChannels;static from(t){M(t.readString()==="PEAKS","Wrong header");let e=t.readInt(),s=[];for(let c=0;c<e;c++){let l=t.readInt(),h=t.readInt(),f=t.readInt();t.readInt(),s[c]=new $.Stage(f,h,l)}let n=t.readInt(),r=[];for(let c=0;c<n;c++){let l=new Int8Array(t.readInt());t.readBytes(l),r[c]=new Int32Array(l.buffer)}let i=t.readInt(),a=t.readInt();return new o(s,r,i,a)}static None=new o([],[],0,0);static findBestFit=(t,e=1200)=>{let s=t/e;if(s<=1)return new Uint8Array(0);let n=3,r=Math.floor(Math.log(s)/Math.LN2),i=Math.max(1,Math.floor(r/n));return new Uint8Array(b.create(a=>n*(a+1),i))};constructor(t,e,s,n){this.stages=t,this.data=e,this.numFrames=s,this.numChannels=n}nearest(t){if(this.stages.length===0)return null;let e=Math.floor(Math.log(Math.abs(t))/Math.LN2),s=this.stages.length;for(;--s>-1;)if(e>=this.stages[s].shift)return this.stages[s];return this.stages[0]}toArrayBuffer(){let t=j.create();t.writeString("PEAKS"),t.writeInt(this.stages.length);for(let e=0;e<this.stages.length;e++){let{dataOffset:s,numPeaks:n,shift:r}=this.stages[e];t.writeInt(s),t.writeInt(n),t.writeInt(r),t.writeInt((1<<r)-1)}t.writeInt(this.data.length);for(let e=0;e<this.data.length;e++){let s=new Int8Array(this.data[e].buffer);t.writeInt(s.length),t.writeBytes(s)}return t.writeInt(this.numFrames),t.writeInt(this.numChannels),t.toArrayBuffer()}toString(){return`{SamplePeaks num-stages: ${this.stages.length}}`}};var Q;(function(o){o.install=s=>P.executor(s.channel("peaks"),new class{async generateAsync(n,r,i,a,c){return t(n,r,i,a,c).toArrayBuffer()}});let t=(s,n,r,i,a)=>{if(r.length!==a)return p(`Invalid numberOfChannels. Expected: ${a}. Got ${r.length}`);class c{min=Number.POSITIVE_INFINITY;max=Number.NEGATIVE_INFINITY;index=0}let l=It(),h=n.length,[f,u]=e(n,i),m=b.create(()=>new Int32Array(u),a),w=(1<<f[0].shift)-1,d=a*i,g=0;for(let E=0;E<a;++E){let I=m[E],L=r[E],St=b.create(()=>new c,h),z=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY,lt=0;for(let st=0;st<i;++st){let ht=L[st];if(z=Math.min(ht,z),Y=Math.max(ht,Y),(++lt&w)===0){for(let U=0;U<h;++U){let ft=f[U],N=St[U];N.min=Math.min(N.min,z),N.max=Math.max(N.max,Y),((1<<ft.shift)-1&lt)===0&&(I[ft.dataOffset+N.index++]=o.pack(N.min,N.max),N.min=Number.POSITIVE_INFINITY,N.max=Number.NEGATIVE_INFINITY)}z=Number.POSITIVE_INFINITY,Y=Number.NEGATIVE_INFINITY}(++g&65535)===0&&s(g/d)}}return s(1),l.lab(`SamplePeaks '${self.constructor.name}'`),new X(f,m,i,a)},e=(s,n)=>{let r=0;return[b.create(a=>{let c=s[a],l=Math.ceil(n/(1<<c)),h=new $.Stage(c,l,r);return r+=l,h},s.length),r]};o.pack=(s,n)=>{let r=B.floatToIntBits(s),i=B.floatToIntBits(n);return r|i<<16}})(Q||(Q={}));var Z;(function(o){o.init=s=>P.executor(s.channel("opfs"),new class{#t=new Map;async write(n,r){await this.#e(n,async()=>{let i=await this.#s(n,{create:!0});try{i.truncate(r.length),i.write(r.buffer,{at:0}),i.flush()}finally{i.close()}})}async read(n){return await this.#e(n,async()=>{let r=await this.#s(n);try{let i=r.getSize(),a=new Uint8Array(i);return r.read(a),a}finally{r.close()}})}async delete(n){await this.#e(n,async()=>{let r=e(n);return r.length===0?this.clear():this.#n(r.slice(0,-1)).then(i=>i.removeEntry(x(r.at(-1)),{recursive:!0}))})}async list(n){let r=e(n),{status:i,value:a}=await K.tryCatch(this.#n(r));if(i==="rejected")return b.empty();let c=[];for await(let{name:l,kind:h}of a.values())c.push({name:l,kind:h});return c}async clear(){let n=await navigator.storage.getDirectory();for await(let[r,i]of n.entries())i.kind==="file"?await n.removeEntry(r):i.kind==="directory"&&await n.removeEntry(r,{recursive:!0})}async#e(n,r){for(;;){let i=this.#t.get(n);if(mt(i)){await i;continue}let a=()=>p("Lock not acquired"),c=new Promise(l=>a=l);this.#t.set(n,c);try{return await r()}finally{this.#t.get(n)===c&&this.#t.delete(n),a()}}}async#s(n,r){let i=e(n);return await(await(await this.#n(i.slice(0,-1),r)).getFileHandle(x(i.at(-1)),r)).createSyncAccessHandle()}async#n(n,r){let i=await navigator.storage.getDirectory();for(let a of n)i=await i.getDirectoryHandle(a,r);return i}});let e=s=>{let n=s.replace(/^\/+|\/+$/g,"");return n===""?[]:n.split("/")}})(Z||(Z={}));var J=class{a1=0;a2=0;b0=0;b1=0;b2=0;constructor(){this.identity()}identity(){this.setNormalizedCoefficients(1,0,0,1,0,0)}setLowpassParams(t,e=Math.SQRT1_2){if(t=_(t,0,1),t>=.5)this.setNormalizedCoefficients(1,0,0,1,0,0);else if(t>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=(1-r)/2,a=i,c=2*i,l=i,h=1+n,f=-2*r,u=1-n;this.setNormalizedCoefficients(a,c,l,h,f,u)}else this.setNormalizedCoefficients(0,0,0,1,0,0);return this}setHighpassParams(t,e=Math.SQRT1_2){if(t=_(t,0,1),t===1)this.setNormalizedCoefficients(0,0,0,1,0,0);else if(t>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=(1+r)/2,a=i,c=-2*i,l=i,h=1+n,f=-2*r,u=1-n;this.setNormalizedCoefficients(a,c,l,h,f,u)}else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setNormalizedCoefficients(t,e,s,n,r,i){let a=1/n;return this.b0=t*a,this.b1=e*a,this.b2=s*a,this.a1=r*a,this.a2=i*a,this}setLowShelfParams(t,e){t=_(t,0,1);let s=Math.pow(10,e/40);if(t===1)this.setNormalizedCoefficients(s*s,0,0,1,0,0);else if(t>0){let n=A*t,i=.5*Math.sin(n)*Math.sqrt((s+1/s)*(1/1-1)+2),a=Math.cos(n),c=2*Math.sqrt(s)*i,l=s+1,h=s-1,f=s*(l-h*a+c),u=2*s*(h-l*a),m=s*(l-h*a-c),w=l+h*a+c,d=-2*(h+l*a),g=l+h*a-c;this.setNormalizedCoefficients(f,u,m,w,d,g)}else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setHighShelfParams(t,e){t=_(t,0,1);let s=Math.pow(10,e/40);if(t===1)this.setNormalizedCoefficients(1,0,0,1,0,0);else if(t>0){let n=A*t,i=.5*Math.sin(n)*Math.sqrt((s+1/s)*(1/1-1)+2),a=Math.cos(n),c=2*Math.sqrt(s)*i,l=s+1,h=s-1,f=s*(l+h*a+c),u=-2*s*(h+l*a),m=s*(l+h*a-c),w=l-h*a+c,d=2*(h-l*a),g=l-h*a-c;this.setNormalizedCoefficients(f,u,m,w,d,g)}else this.setNormalizedCoefficients(s*s,0,0,1,0,0);return this}setPeakingParams(t,e,s){t=_(t,0,1),e=Math.max(0,e);let n=Math.pow(10,s/40);if(t>0&&t<1)if(e>0){let r=A*t,i=Math.sin(r)/(2*e),a=Math.cos(r),c=1+i*n,l=-2*a,h=1-i*n,f=1+i/n,u=-2*a,m=1-i/n;this.setNormalizedCoefficients(c,l,h,f,u,m)}else this.setNormalizedCoefficients(n*n,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setAllpassParams(t,e){if(t=_(t,0,1),e=Math.max(0,e),t>0&&t<1)if(e>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=1-n,a=-2*r,c=1+n,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(-1,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setNotchParams(t,e){if(t=_(t,0,1),e=Math.max(0,e),t>0&&t<1)if(e>0){let s=A*t,n=Math.sin(s)/(2*e),r=Math.cos(s),i=1,a=-2*r,c=1,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(0,0,0,1,0,0);else this.setNormalizedCoefficients(1,0,0,1,0,0);return this}setBandpassParams(t,e){if(t=Math.max(0,t),e=Math.max(0,e),t>0&&t<1){let s=A*t;if(e>0){let n=Math.sin(s)/(2*e),r=Math.cos(s),i=n,a=0,c=-n,l=1+n,h=-2*r,f=1-n;this.setNormalizedCoefficients(i,a,c,l,h,f)}else this.setNormalizedCoefficients(1,0,0,1,0,0)}else this.setNormalizedCoefficients(0,0,0,1,0,0);return this}getFrequencyResponse(t,e,s){M(t.length===e.length&&t.length===s.length,"Array lengths do not match");let n=this.b0,r=this.b1,i=this.b2,a=this.a1,c=this.a2;for(let l=0;l<t.length;++l){let h=-Math.PI*2*t[l],f=Math.cos(h),u=Math.sin(h),m=n+((r+i*f)*f-i*u*u),w=(r+i*f)*u+i*u*f,d=1+((a+c*f)*f-c*u*u),g=(a+c*f)*u+c*u*f,E=d*d+g*g,I=(m*d+w*g)/E,L=(w*d-m*g)/E;e[l]=Math.sqrt(I*I+L*L),s[l]=Math.atan2(L,I)}}};var k=class{#t=0;#e=0;#s=0;#n=0;reset(){this.#t=0,this.#e=0,this.#s=0,this.#n=0}process({a1:t,a2:e,b0:s,b1:n,b2:r},i,a,c,l){let h=this.#t,f=this.#e,u=this.#s,m=this.#n;for(let w=c;w<l;w++){let d=i[w],g=a[w]=s*d+n*h+r*f-t*u-e*m+1e-18-1e-18;f=h,h=d,m=u,u=g}this.#t=h,this.#e=f,this.#s=u,this.#n=m}processFrame({a1:t,a2:e,b0:s,b1:n,b2:r},i){let a=s*i+n*this.#t+r*this.#e-t*this.#s-e*this.#n+1e-18-1e-18;return this.#e=this.#t,this.#t=i,this.#n=this.#s,this.#s=a,a}};var q=48,Mt=200,bt=2e3,Tt=20,At=2,_t=3e-4,Bt=40,Pt=120,Rt=.2,Ft=20,Lt=.66,vt=.006,Ot={low:1,mid:4,high:8},tt=class o{static detect(t){let e=performance.now(),s=t.numberOfFrames/t.sampleRate,n=new o(t).#h(),r=((performance.now()-e)/1e3/s*100).toFixed(2);return console.debug(`realtime factor: ${r}%`),n}#t;#e;#s;#n;#r;#i;#a;#o;constructor(t){this.#t=t.sampleRate,this.#e=t.numberOfFrames,this.#s=Math.floor(Ft/1e3*this.#t),this.#n=Math.floor(Pt/1e3*this.#t),this.#r=Math.floor(Tt/1e3*this.#t),this.#i=Math.floor(this.#r/2);let e=this.#e/this.#t;this.#a=Math.floor(e*Bt),this.#o=this.#m(t)}#h(){let t=this.#f();return this.#u(t).map(s=>s/this.#t)}#f(){let t=this.#d(),e=[];for(let r of["low","mid","high"]){let i=t[r],a=this.#p(i),c=this.#w(a),l=Ot[r];for(let h of c)e.push({position:h.position,energy:h.energy*l})}let s=[0,this.#e],n=[...e].sort((r,i)=>i.energy-r.energy);for(let r of n){if(s.length>=this.#a+2&&s.length>=At+2)break;this.#g(s,r.position)||this.#x(s,r.position)}return s}#u(t){if(t.length<2)return t;let e=[t[0]],s=Math.floor(this.#t*vt);for(let n=1;n<t.length-1;n++){let r=t[n-1],i=t[n];if(r===0){e.push(i);continue}let a=i-r,c=r+Math.floor(a*Rt),l=i-this.#s,h=Math.max(c,l),f=0;for(let d=0;d<s&&i+d<this.#e;d++)f+=this.#o[i+d]*this.#o[i+d];f=Math.sqrt(f/s);let u=f*Lt,m=1/0,w=i;for(let d=i-1;d>=h;d--){let g=0;for(let I=0;I<s&&d+I<this.#e;I++)g+=this.#o[d+I]*this.#o[d+I];let E=Math.sqrt(g/s);if(E<m&&(m=E,w=d),E<u)break}e.push(w)}return e.push(t[t.length-1]),e}#m(t){let{numberOfFrames:e,numberOfChannels:s,frames:n}=t;if(s===0)return p("Invalid sample. No channels found.");if(s===1)return new Float32Array(n[0]);let r=new Float32Array(e);for(let a=0;a<s;a++){let c=n[a];for(let l=0;l<e;l++)r[l]+=c[l]}let i=1/s;for(let a=0;a<e;a++)r[a]*=i;return r}#c(t,e,s,n){let r=n/12,i=new J,a=e/this.#t;s==="lowpass"?i.setLowpassParams(a,Math.SQRT1_2):i.setHighpassParams(a,Math.SQRT1_2);let c=t;for(let l=0;l<r;l++){let h=new k,f=new k,u=new Float32Array(c.length),m=new Float32Array(c.length);h.process(i,c,u,0,c.length),f.process(i,u,m,0,c.length),c=m}return c}#d(){let t=this.#c(this.#o,Mt,"lowpass",q),e=this.#c(this.#o,Mt,"highpass",q),s=this.#c(e,bt,"lowpass",q),n=this.#c(e,bt,"highpass",q);return{low:t,mid:s,high:n}}#p(t){let e=new Float32Array(t.length),s=0;for(let n=0;n<this.#r&&n<t.length;n++)s+=t[n]*t[n];for(let n=0;n<t.length;n++){let r=n-this.#i,i=n+this.#i;if(r>0&&r-1<t.length){let c=t[r-1];s-=c*c}if(i<t.length){let c=t[i];s+=c*c}let a=Math.min(i,t.length-1)-Math.max(r,0)+1;e[n]=Math.sqrt(Math.max(0,s)/a)}return e}#w(t){let e=0;for(let r=0;r<t.length;r++)t[r]>e&&(e=t[r]);let s=e*_t,n=[];for(let r=1;r<t.length-1;r++){let i=t[r]-t[r-1],a=t[r+1]-t[r];i>s&&i>a&&n.push({position:r,energy:t[r]})}return n}#g(t,e){let s=this.#l(t,e);return s>0&&e-t[s-1]<this.#n?!0:s<t.length&&t[s]-e<this.#n}#x(t,e){let s=this.#l(t,e);t.splice(s,0,e)}#l(t,e){let s=0,n=t.length;for(;s<n;){let r=s+n>>>1;t[r]<e?s=r+1:n=r}return s}};var et=yt.for(self);Z.init(et);Q.install(et);P.executor(et.channel("transients"),new class{async detect(o){return tt.detect(o)}});et.channel("initialize").send("ready");
6
2
  //# sourceMappingURL=workers-main.js.map