@waveform-playlist/browser 9.4.0 → 9.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Yf=Object.create;var al=Object.defineProperty;var Kf=Object.getOwnPropertyDescriptor;var qf=Object.getOwnPropertyNames;var Jf=Object.getPrototypeOf,Qf=Object.prototype.hasOwnProperty;var eh=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of qf(t))!Qf.call(e,s)&&s!==n&&al(e,s,{get:()=>t[s],enumerable:!(r=Kf(t,s))||r.enumerable});return e};var th=(e,t,n)=>(n=e!=null?Yf(Jf(e)):{},eh(t||!e||!e.__esModule?al(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("tone"),C=require("react/jsx-runtime"),p=require("react"),F=require("styled-components"),go=require("react-dom");function ic(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const lc=ic(L),D=ic(p);var ca={exports:{}},ol;function nh(){return ol||(ol=1,(function(e,t){(function(n,r){e.exports=r()})(window,(function(){return(function(n){var r={};function s(a){if(r[a])return r[a].exports;var o=r[a]={i:a,l:!1,exports:{}};return n[a].call(o.exports,o,o.exports,s),o.l=!0,o.exports}return s.m=n,s.c=r,s.d=function(a,o,i){s.o(a,o)||Object.defineProperty(a,o,{enumerable:!0,get:i})},s.r=function(a){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})},s.t=function(a,o){if(1&o&&(a=s(a)),8&o||4&o&&typeof a=="object"&&a&&a.__esModule)return a;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:a}),2&o&&typeof a!="string")for(var l in a)s.d(i,l,(function(c){return a[c]}).bind(null,l));return i},s.n=function(a){var o=a&&a.__esModule?function(){return a.default}:function(){return a};return s.d(o,"a",o),o},s.o=function(a,o){return Object.prototype.hasOwnProperty.call(a,o)},s.p="",s(s.s="./src/index.ts")})({"./src/chunk.ts":function(n,r,s){s.r(r),s.d(r,"SF2Chunk",(function(){return d}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=s("./src/chunks/index.ts");function l(h){return(l=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(g){return typeof g}:function(g){return g&&typeof Symbol=="function"&&g.constructor===Symbol&&g!==Symbol.prototype?"symbol":typeof g})(h)}function c(h,g){for(var v=0;v<g.length;v++){var y=g[v];y.enumerable=y.enumerable||!1,y.configurable=!0,"value"in y&&(y.writable=!0),Object.defineProperty(h,y.key,y)}}function u(h){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(g){return g.__proto__||Object.getPrototypeOf(g)})(h)}function f(h,g){return(f=Object.setPrototypeOf||function(v,y){return v.__proto__=y,v})(h,g)}function m(h){if(h===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return h}var d=(function(h){function g(b){var w,_,x,S,k,E;return(function(I,T){if(!(I instanceof T))throw new TypeError("Cannot call a class as a function")})(this,g),_=this,w=!(x=u(g).call(this,b.id,b.length,b.buffer,b.subChunks))||l(x)!=="object"&&typeof x!="function"?m(_):x,S=m(m(w)),E=void 0,(k="subChunks")in S?Object.defineProperty(S,k,{value:E,enumerable:!0,configurable:!0,writable:!0}):S[k]=E,w.subChunks=b.subChunks.map((function(I){return new g(I)})),w}var v,y;return(function(b,w){if(typeof w!="function"&&w!==null)throw new TypeError("Super expression must either be null or a function");b.prototype=Object.create(w&&w.prototype,{constructor:{value:b,writable:!0,configurable:!0}}),w&&f(b,w)})(g,h),v=g,(y=[{key:"getMetaData",value:function(){if(this.id!=="LIST")throw new a.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks.reduce((function(w,_){if(_.id==="ifil"||_.id==="iver"){if(_.length!==o.SF_VERSION_LENGTH)throw new a.ParseError("Invalid size for the '".concat(_.id,"' sub-chunk"));w[_.id]="".concat(_.getInt16(),".").concat(_.getInt16(2))}else w[_.id]=_.getString();return w}),{});if(!b.ifil)throw new a.ParseError("Missing required 'ifil' sub-chunk");if(!b.INAM)throw new a.ParseError("Missing required 'INAM' sub-chunk");return{version:b.ifil,soundEngine:b.isng||"EMU8000",name:b.INAM,rom:b.irom,romVersion:b.iver,creationDate:b.ICRD,author:b.IENG,product:b.IPRD,copyright:b.ICOP,comments:b.ICMT,createdBy:b.ISFT}}},{key:"getSampleData",value:function(){if(this.id!=="LIST")throw new a.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks[0];if(b.id!=="smpl")throw new a.ParseError("Invalid chunk signature","'smpl'","'".concat(b.id,"'"));return b.buffer}},{key:"getPresetData",value:function(){if(this.id!=="LIST")throw new a.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));return{presetHeaders:Object(i.getPresetHeaders)(this.subChunks[0]),presetZones:Object(i.getZones)(this.subChunks[1],"pbag"),presetModulators:Object(i.getModulators)(this.subChunks[2],"pmod"),presetGenerators:Object(i.getGenerators)(this.subChunks[3],"pgen"),instrumentHeaders:Object(i.getInstrumentHeaders)(this.subChunks[4]),instrumentZones:Object(i.getZones)(this.subChunks[5],"ibag"),instrumentModulators:Object(i.getModulators)(this.subChunks[6],"imod"),instrumentGenerators:Object(i.getGenerators)(this.subChunks[7],"igen"),sampleHeaders:Object(i.getSampleHeaders)(this.subChunks[8])}}}])&&c(v.prototype,y),g})(a.RIFFChunk)},"./src/chunks/generators.ts":function(n,r,s){s.r(r),s.d(r,"getGenerators",(function(){return f}));var a=s("./src/riff/index.ts"),o=s("./src/types/index.ts"),i=s("./src/constants.ts"),l=[o.GeneratorType.StartAddrsOffset,o.GeneratorType.EndAddrsOffset,o.GeneratorType.StartLoopAddrsOffset,o.GeneratorType.EndLoopAddrsOffset,o.GeneratorType.StartAddrsCoarseOffset,o.GeneratorType.EndAddrsCoarseOffset,o.GeneratorType.StartLoopAddrsCoarseOffset,o.GeneratorType.KeyNum,o.GeneratorType.Velocity,o.GeneratorType.EndLoopAddrsCoarseOffset,o.GeneratorType.SampleModes,o.GeneratorType.ExclusiveClass,o.GeneratorType.OverridingRootKey],c=[o.GeneratorType.Unused1,o.GeneratorType.Unused2,o.GeneratorType.Unused3,o.GeneratorType.Unused4,o.GeneratorType.Reserved1,o.GeneratorType.Reserved2,o.GeneratorType.Reserved3],u=[o.GeneratorType.KeyRange,o.GeneratorType.VelRange],f=function(m,d){if(m.id!==d)throw new a.ParseError("Unexpected chunk ID","'".concat(d,"'"),"'".concat(m.id,"'"));if(m.length%i.SF_GENERATOR_SIZE)throw new a.ParseError("Invalid size for the '".concat(d,"' sub-chunk"));return m.iterate((function(h){var g=h.getInt16();return o.GeneratorType[g]?d==="pgen"&&l.includes(g)||d==="igen"&&c.includes(g)?null:u.includes(g)?{id:g,range:{lo:h.getByte(),hi:h.getByte()}}:{id:g,value:h.getInt16BE()}:null}))}},"./src/chunks/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/instruments/index.ts");s.d(r,"getInstrumentHeaders",(function(){return a.getInstrumentHeaders}));var o=s("./src/chunks/presets/index.ts");s.d(r,"getPresetHeaders",(function(){return o.getPresetHeaders}));var i=s("./src/chunks/samples/index.ts");s.d(r,"getSampleHeaders",(function(){return i.getSampleHeaders}));var l=s("./src/chunks/generators.ts");s.d(r,"getGenerators",(function(){return l.getGenerators}));var c=s("./src/chunks/modulators.ts");s.d(r,"getModulators",(function(){return c.getModulators}));var u=s("./src/chunks/zones.ts");s.d(r,"getZones",(function(){return u.getZones})),s.d(r,"getItemsInZone",(function(){return u.getItemsInZone}))},"./src/chunks/instruments/headers.ts":function(n,r,s){s.r(r),s.d(r,"getInstrumentHeaders",(function(){return i}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(l){if(l.id!=="inst")throw new a.ParseError("Unexpected chunk ID","'inst'","'".concat(l.id,"'"));if(l.length%o.SF_INSTRUMENT_HEADER_SIZE)throw new a.ParseError("Invalid size for the 'inst' sub-chunk");return l.iterate((function(c){return{name:c.getString(),bagIndex:c.getInt16()}}))}},"./src/chunks/instruments/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/instruments/headers.ts");s.d(r,"getInstrumentHeaders",(function(){return a.getInstrumentHeaders}))},"./src/chunks/modulators.ts":function(n,r,s){s.r(r),s.d(r,"getModulators",(function(){return l}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(c){return{type:c>>10&63,polarity:c>>9&1,direction:c>>8&1,palette:c>>7&1,index:127&c}},l=function(c,u){if(c.id!==u)throw new a.ParseError("Unexpected chunk ID","'".concat(u,"'"),"'".concat(c.id,"'"));if(c.length%o.SF_MODULATOR_SIZE)throw new a.ParseError("Invalid size for the '".concat(u,"' sub-chunk"));return c.iterate((function(f){return{source:i(f.getInt16BE()),id:f.getInt16BE(),value:f.getInt16BE(),valueSource:i(f.getInt16BE()),transform:f.getInt16BE()}}))}},"./src/chunks/presets/headers.ts":function(n,r,s){s.r(r),s.d(r,"getPresetHeaders",(function(){return i}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(l){if(l.id!=="phdr")throw new a.ParseError("Invalid chunk ID","'phdr'","'".concat(l.id,"'"));if(l.length%o.SF_PRESET_HEADER_SIZE)throw new a.ParseError("Invalid size for the 'phdr' sub-chunk");return l.iterate((function(c){return{name:c.getString(),preset:c.getInt16(),bank:c.getInt16(),bagIndex:c.getInt16(),library:c.getUInt32(),genre:c.getUInt32(),morphology:c.getUInt32()}}))}},"./src/chunks/presets/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/presets/headers.ts");s.d(r,"getPresetHeaders",(function(){return a.getPresetHeaders}))},"./src/chunks/samples/headers.ts":function(n,r,s){s.r(r),s.d(r,"getSampleHeaders",(function(){return i}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(l){if(l.id!=="shdr")throw new a.ParseError("Unexpected chunk ID","'shdr'","'".concat(l.id,"'"));if(l.length%o.SF_SAMPLE_HEADER_SIZE)throw new a.ParseError("Invalid size for the 'shdr' sub-chunk");return l.iterate((function(c){return{name:c.getString(),start:c.getUInt32(),end:c.getUInt32(),startLoop:c.getUInt32(),endLoop:c.getUInt32(),sampleRate:c.getUInt32(),originalPitch:c.getByte(),pitchCorrection:c.getChar(),link:c.getInt16(),type:c.getInt16()}}))}},"./src/chunks/samples/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/samples/headers.ts");s.d(r,"getSampleHeaders",(function(){return a.getSampleHeaders}))},"./src/chunks/zones.ts":function(n,r,s){s.r(r),s.d(r,"getZones",(function(){return l})),s.d(r,"getItemsInZone",(function(){return c}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=s("./src/types/index.ts"),l=function(d,h){if(d.id!==h)throw new a.ParseError("Unexpected chunk ID","'".concat(h,"'"),"'".concat(d.id,"'"));if(d.length%o.SF_BAG_SIZE)throw new a.ParseError("Invalid size for the '".concat(h,"' sub-chunk"));return d.iterate((function(g){return{generatorIndex:g.getInt16(),modulatorIndex:g.getInt16()}}))},c=function(d,h,g,v,y,b){for(var w=[],_=0;_<d.length;_++){for(var x=d[_],S=d[_+1],k=x.bagIndex,E=S?S.bagIndex:h.length,I=[],T=void 0,R=k;R<E;R++){var A=u(R,h,g),M=f(R,h,v),$=M[i.GeneratorType.KeyRange]&&M[i.GeneratorType.KeyRange].range,P=M[b];if(P){var O=y[P.value];O&&I.push({keyRange:$,modulators:A,generators:M,reference:O})}else R-k==0&&(T={keyRange:$,modulators:A,generators:M})}w.push({header:x,globalZone:T,zones:I})}return w},u=function(d,h,g){var v=h[d],y=h[d+1],b=v.modulatorIndex,w=y?y.modulatorIndex:h.length;return m(b,w,g)},f=function(d,h,g){var v=h[d],y=h[d+1],b=v.generatorIndex,w=y?y.generatorIndex:h.length;return m(b,w,g)},m=function(d,h,g){for(var v={},y=d;y<h;y++){var b=g[y];b&&(v[b.id]=b)}return v}},"./src/constants.ts":function(n,r,s){s.r(r),s.d(r,"SF_VERSION_LENGTH",(function(){return a})),s.d(r,"SF_PRESET_HEADER_SIZE",(function(){return o})),s.d(r,"SF_BAG_SIZE",(function(){return i})),s.d(r,"SF_MODULATOR_SIZE",(function(){return l})),s.d(r,"SF_GENERATOR_SIZE",(function(){return c})),s.d(r,"SF_INSTRUMENT_HEADER_SIZE",(function(){return u})),s.d(r,"SF_SAMPLE_HEADER_SIZE",(function(){return f})),s.d(r,"DEFAULT_SAMPLE_RATE",(function(){return m}));var a=4,o=38,i=4,l=10,c=4,u=22,f=46,m=22050},"./src/index.ts":function(n,r,s){s.r(r);var a=s("./src/types/index.ts");for(var o in a)["default"].indexOf(o)<0&&(function(u){s.d(r,u,(function(){return a[u]}))})(o);var i=s("./src/chunk.ts");s.d(r,"SF2Chunk",(function(){return i.SF2Chunk}));var l=s("./src/constants.ts");s.d(r,"SF_VERSION_LENGTH",(function(){return l.SF_VERSION_LENGTH})),s.d(r,"SF_PRESET_HEADER_SIZE",(function(){return l.SF_PRESET_HEADER_SIZE})),s.d(r,"SF_BAG_SIZE",(function(){return l.SF_BAG_SIZE})),s.d(r,"SF_MODULATOR_SIZE",(function(){return l.SF_MODULATOR_SIZE})),s.d(r,"SF_GENERATOR_SIZE",(function(){return l.SF_GENERATOR_SIZE})),s.d(r,"SF_INSTRUMENT_HEADER_SIZE",(function(){return l.SF_INSTRUMENT_HEADER_SIZE})),s.d(r,"SF_SAMPLE_HEADER_SIZE",(function(){return l.SF_SAMPLE_HEADER_SIZE})),s.d(r,"DEFAULT_SAMPLE_RATE",(function(){return l.DEFAULT_SAMPLE_RATE}));var c=s("./src/soundFont2.ts");s.d(r,"SoundFont2",(function(){return c.SoundFont2}))},"./src/riff/chunkIterator.ts":function(n,r,s){s.r(r),s.d(r,"ChunkIterator",(function(){return c}));var a=s("./src/utils/index.ts");function o(u,f){if(!(u instanceof f))throw new TypeError("Cannot call a class as a function")}function i(u,f){for(var m=0;m<f.length;m++){var d=f[m];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,m){return f in u?Object.defineProperty(u,f,{value:m,enumerable:!0,configurable:!0,writable:!0}):u[f]=m,u}var c=(function(){function u(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;o(this,u),l(this,"target",[]),l(this,"chunk",void 0),l(this,"position",0),this.chunk=d,this.position=h}var f,m;return f=u,(m=[{key:"iterate",value:function(d){for(;this.position<this.chunk.length;){var h=d(this);h&&this.target.push(h)}}},{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:20,h=Object(a.getStringFromBuffer)(this.getBuffer(this.position,d));return this.position+=d,h}},{key:"getInt16",value:function(){return this.chunk.buffer[this.position++]|this.chunk.buffer[this.position++]<<8}},{key:"getInt16BE",value:function(){return this.getInt16()<<16>>16}},{key:"getUInt32",value:function(){return(this.chunk.buffer[this.position++]|this.chunk.buffer[this.position++]<<8|this.chunk.buffer[this.position++]<<16|this.chunk.buffer[this.position++]<<24)>>>0}},{key:"getByte",value:function(){return this.chunk.buffer[this.position++]}},{key:"getChar",value:function(){return this.chunk.buffer[this.position++]<<24>>24}},{key:"skip",value:function(d){this.position+=d}},{key:"getBuffer",value:function(d,h){return this.chunk.buffer.subarray(d,d+h)}},{key:"currentPosition",get:function(){return this.position}}])&&i(f.prototype,m),u})()},"./src/riff/index.ts":function(n,r,s){s.r(r);var a=s("./src/riff/chunkIterator.ts");s.d(r,"ChunkIterator",(function(){return a.ChunkIterator}));var o=s("./src/riff/parseError.ts");s.d(r,"ParseError",(function(){return o.ParseError}));var i=s("./src/riff/parser.ts");s.d(r,"parseBuffer",(function(){return i.parseBuffer})),s.d(r,"getChunk",(function(){return i.getChunk})),s.d(r,"getChunkLength",(function(){return i.getChunkLength})),s.d(r,"getSubChunks",(function(){return i.getSubChunks})),s.d(r,"getChunkId",(function(){return i.getChunkId}));var l=s("./src/riff/riffChunk.ts");s.d(r,"RIFFChunk",(function(){return l.RIFFChunk}))},"./src/riff/parseError.ts":function(n,r,s){function a(d){return(a=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(h){return typeof h}:function(h){return h&&typeof Symbol=="function"&&h.constructor===Symbol&&h!==Symbol.prototype?"symbol":typeof h})(d)}function o(d,h){return!h||a(h)!=="object"&&typeof h!="function"?(function(g){if(g===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g})(d):h}function i(d){var h=typeof Map=="function"?new Map:void 0;return(i=function(g){if(g===null||(v=g,Function.toString.call(v).indexOf("[native code]")===-1))return g;var v;if(typeof g!="function")throw new TypeError("Super expression must either be null or a function");if(h!==void 0){if(h.has(g))return h.get(g);h.set(g,y)}function y(){return c(g,arguments,f(this).constructor)}return y.prototype=Object.create(g.prototype,{constructor:{value:y,enumerable:!1,writable:!0,configurable:!0}}),u(y,g)})(d)}function l(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch{return!1}}function c(d,h,g){return(c=l()?Reflect.construct:function(v,y,b){var w=[null];w.push.apply(w,y);var _=new(Function.bind.apply(v,w));return b&&u(_,b.prototype),_}).apply(null,arguments)}function u(d,h){return(u=Object.setPrototypeOf||function(g,v){return g.__proto__=v,g})(d,h)}function f(d){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(h){return h.__proto__||Object.getPrototypeOf(h)})(d)}s.r(r),s.d(r,"ParseError",(function(){return m}));var m=(function(d){function h(g,v,y){return(function(b,w){if(!(b instanceof w))throw new TypeError("Cannot call a class as a function")})(this,h),o(this,f(h).call(this,"".concat(g).concat(v&&y?", expected ".concat(v,", received ").concat(y):"")))}return(function(g,v){if(typeof v!="function"&&v!==null)throw new TypeError("Super expression must either be null or a function");g.prototype=Object.create(v&&v.prototype,{constructor:{value:g,writable:!0,configurable:!0}}),v&&u(g,v)})(h,d),h})(i(Error))},"./src/riff/parser.ts":function(n,r,s){s.r(r),s.d(r,"parseBuffer",(function(){return l})),s.d(r,"getChunk",(function(){return c})),s.d(r,"getChunkLength",(function(){return u})),s.d(r,"getSubChunks",(function(){return f})),s.d(r,"getChunkId",(function(){return m}));var a=s("./src/riff/parseError.ts"),o=s("./src/utils/buffer.ts"),i=s("./src/riff/riffChunk.ts"),l=function(d){var h=m(d);if(h!=="RIFF")throw new a.ParseError("Invalid file format","RIFF",h);var g=m(d,8);if(g!=="sfbk")throw new a.ParseError("Invalid signature","sfbk",g);var v=d.subarray(8),y=f(v.subarray(4));return new i.RIFFChunk(h,v.length,v,y)},c=function(d,h){var g=m(d,h),v=u(d,h+4),y=[];return g!=="RIFF"&&g!=="LIST"||(y=f(d.subarray(h+12))),new i.RIFFChunk(g,v,d.subarray(h+8),y)},u=function(d,h){return((d=d.subarray(h,h+4))[0]|d[1]<<8|d[2]<<16|d[3]<<24)>>>0},f=function(d){for(var h=[],g=0;g<=d.length-8;){var v=c(d,g);h.push(v),g=(g+=8+v.length)%2?g+1:g}return h},m=function(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;return Object(o.getStringFromBuffer)(d.subarray(h,h+4))}},"./src/riff/riffChunk.ts":function(n,r,s){s.r(r),s.d(r,"RIFFChunk",(function(){return c}));var a=s("./src/riff/chunkIterator.ts"),o=s("./src/utils/index.ts");function i(u,f){for(var m=0;m<f.length;m++){var d=f[m];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,m){return f in u?Object.defineProperty(u,f,{value:m,enumerable:!0,configurable:!0,writable:!0}):u[f]=m,u}var c=(function(){function u(d,h,g,v){(function(y,b){if(!(y instanceof b))throw new TypeError("Cannot call a class as a function")})(this,u),l(this,"id",void 0),l(this,"length",void 0),l(this,"buffer",void 0),l(this,"subChunks",void 0),this.id=d,this.length=h,this.buffer=g,this.subChunks=v}var f,m;return f=u,(m=[{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,h=arguments.length>1?arguments[1]:void 0;return Object(o.getStringFromBuffer)(this.getBuffer(d,h||this.length-d))}},{key:"getInt16",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return this.buffer[d++]|this.buffer[d]<<8}},{key:"getUInt32",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return(this.buffer[d++]|this.buffer[d++]<<8|this.buffer[d++]<<16|this.buffer[d]<<24)>>>0}},{key:"getByte",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return this.buffer[d]}},{key:"getChar",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return this.buffer[d]<<24>>24}},{key:"iterator",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return new a.ChunkIterator(this,d)}},{key:"iterate",value:function(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,g=new a.ChunkIterator(this,h);return g.iterate(d),g.target}},{key:"getBuffer",value:function(d,h){return this.buffer.subarray(d,d+h)}}])&&i(f.prototype,m),u})()},"./src/soundFont2.ts":function(n,r,s){s.r(r),s.d(r,"SoundFont2",(function(){return h}));var a=s("./src/types/index.ts"),o=s("./src/chunk.ts"),i=s("./src/riff/index.ts"),l=s("./src/chunks/index.ts"),c=s("./src/utils/index.ts");function u(g){for(var v=1;v<arguments.length;v++){var y=arguments[v]!=null?arguments[v]:{},b=Object.keys(y);typeof Object.getOwnPropertySymbols=="function"&&(b=b.concat(Object.getOwnPropertySymbols(y).filter((function(w){return Object.getOwnPropertyDescriptor(y,w).enumerable})))),b.forEach((function(w){d(g,w,y[w])}))}return g}function f(g,v){for(var y=0;y<v.length;y++){var b=v[y];b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(g,b.key,b)}}function m(g,v,y){return v&&f(g.prototype,v),y&&f(g,y),g}function d(g,v,y){return v in g?Object.defineProperty(g,v,{value:y,enumerable:!0,configurable:!0,writable:!0}):g[v]=y,g}var h=(function(){function g(v){if((function(b,w){if(!(b instanceof w))throw new TypeError("Cannot call a class as a function")})(this,g),d(this,"chunk",void 0),d(this,"metaData",void 0),d(this,"sampleData",void 0),d(this,"samples",void 0),d(this,"presetData",void 0),d(this,"instruments",void 0),d(this,"presets",void 0),d(this,"banks",void 0),!(v instanceof o.SF2Chunk)){var y=Object(i.parseBuffer)(v);v=new o.SF2Chunk(y)}if(v.subChunks.length!==3)throw new i.ParseError("Invalid sfbk structure","3 chunks","".concat(v.subChunks.length," chunks"));this.chunk=v,this.metaData=v.subChunks[0].getMetaData(),this.sampleData=v.subChunks[1].getSampleData(),this.presetData=v.subChunks[2].getPresetData(),this.samples=this.getSamples(),this.instruments=this.getInstruments(),this.presets=this.getPresets(),this.banks=this.getBanks()}return m(g,null,[{key:"from",value:function(v){return new g(v)}}]),m(g,[{key:"getKeyData",value:function(v){var y=this,b=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,w=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;return Object(c.memoize)((function(_,x,S){var k=y.banks[x];if(k){var E=k.presets[S];if(E){var I=E.zones.filter((function(ne){return y.isKeyInRange(ne,_)}));if(I.length>0){var T=!0,R=!1,A=void 0;try{for(var M,$=I[Symbol.iterator]();!(T=(M=$.next()).done);T=!0){var P=M.value,O=P.instrument,Z=O.zones.filter((function(ne){return y.isKeyInRange(ne,_)}));if(Z.length>0){var G=!0,Y=!1,ee=void 0;try{for(var X,K=Z[Symbol.iterator]();!(G=(X=K.next()).done);G=!0){var le=X.value,te=le.sample,fe=u({},P.generators,le.generators),de=u({},P.modulators,le.modulators);return{keyNumber:_,preset:E,instrument:O,sample:te,generators:fe,modulators:de}}}catch(ne){Y=!0,ee=ne}finally{try{G||K.return==null||K.return()}finally{if(Y)throw ee}}}}}catch(ne){R=!0,A=ne}finally{try{T||$.return==null||$.return()}finally{if(R)throw A}}}}}return null}))(v,b,w)}},{key:"isKeyInRange",value:function(v,y){return v.keyRange===void 0||v.keyRange.lo<=y&&v.keyRange.hi>=y}},{key:"getBanks",value:function(){return this.presets.reduce((function(v,y){var b=y.header.bank;return v[b]||(v[b]={presets:[]}),v[b].presets[y.header.preset]=y,v}),[])}},{key:"getPresets",value:function(){var v=this.presetData,y=v.presetHeaders,b=v.presetZones,w=v.presetGenerators,_=v.presetModulators;return Object(l.getItemsInZone)(y,b,_,w,this.instruments,a.GeneratorType.Instrument).filter((function(x){return x.header.name!=="EOP"})).map((function(x){return{header:x.header,globalZone:x.globalZone,zones:x.zones.map((function(S){return{keyRange:S.keyRange,generators:S.generators,modulators:S.modulators,instrument:S.reference}}))}}))}},{key:"getInstruments",value:function(){var v=this.presetData,y=v.instrumentHeaders,b=v.instrumentZones,w=v.instrumentModulators,_=v.instrumentGenerators;return Object(l.getItemsInZone)(y,b,w,_,this.samples,a.GeneratorType.SampleId).filter((function(x){return x.header.name!=="EOI"})).map((function(x){return{header:x.header,globalZone:x.globalZone,zones:x.zones.map((function(S){return{keyRange:S.keyRange,generators:S.generators,modulators:S.modulators,sample:S.reference}}))}}))}},{key:"getSamples",value:function(){var v=this;return this.presetData.sampleHeaders.filter((function(y){return y.name!=="EOS"})).map((function(y){if(y.name!=="EOS"&&y.sampleRate<=0)throw new Error("Illegal sample rate of ".concat(y.sampleRate," hz in sample '").concat(y.name,"'"));return y.originalPitch>=128&&y.originalPitch<=254&&(y.originalPitch=60),y.startLoop-=y.start,y.endLoop-=y.start,{header:y,data:new Int16Array(new Uint8Array(v.sampleData.subarray(2*y.start,2*y.end)).buffer)}}))}}]),g})()},"./src/types/bank.ts":function(n,r){},"./src/types/generator.ts":function(n,r,s){var a,o;function i(c,u,f){return u in c?Object.defineProperty(c,u,{value:f,enumerable:!0,configurable:!0,writable:!0}):c[u]=f,c}s.r(r),s.d(r,"GeneratorType",(function(){return o})),s.d(r,"DEFAULT_GENERATOR_VALUES",(function(){return l})),(function(c){c[c.StartAddrsOffset=0]="StartAddrsOffset",c[c.EndAddrsOffset=1]="EndAddrsOffset",c[c.StartLoopAddrsOffset=2]="StartLoopAddrsOffset",c[c.EndLoopAddrsOffset=3]="EndLoopAddrsOffset",c[c.StartAddrsCoarseOffset=4]="StartAddrsCoarseOffset",c[c.ModLFOToPitch=5]="ModLFOToPitch",c[c.VibLFOToPitch=6]="VibLFOToPitch",c[c.ModEnvToPitch=7]="ModEnvToPitch",c[c.InitialFilterFc=8]="InitialFilterFc",c[c.InitialFilterQ=9]="InitialFilterQ",c[c.ModLFOToFilterFc=10]="ModLFOToFilterFc",c[c.ModEnvToFilterFc=11]="ModEnvToFilterFc",c[c.EndAddrsCoarseOffset=12]="EndAddrsCoarseOffset",c[c.ModLFOToVolume=13]="ModLFOToVolume",c[c.Unused1=14]="Unused1",c[c.ChorusEffectsSend=15]="ChorusEffectsSend",c[c.ReverbEffectsSend=16]="ReverbEffectsSend",c[c.Pan=17]="Pan",c[c.Unused2=18]="Unused2",c[c.Unused3=19]="Unused3",c[c.Unused4=20]="Unused4",c[c.DelayModLFO=21]="DelayModLFO",c[c.FreqModLFO=22]="FreqModLFO",c[c.DelayVibLFO=23]="DelayVibLFO",c[c.FreqVibLFO=24]="FreqVibLFO",c[c.DelayModEnv=25]="DelayModEnv",c[c.AttackModEnv=26]="AttackModEnv",c[c.HoldModEnv=27]="HoldModEnv",c[c.DecayModEnv=28]="DecayModEnv",c[c.SustainModEnv=29]="SustainModEnv",c[c.ReleaseModEnv=30]="ReleaseModEnv",c[c.KeyNumToModEnvHold=31]="KeyNumToModEnvHold",c[c.KeyNumToModEnvDecay=32]="KeyNumToModEnvDecay",c[c.DelayVolEnv=33]="DelayVolEnv",c[c.AttackVolEnv=34]="AttackVolEnv",c[c.HoldVolEnv=35]="HoldVolEnv",c[c.DecayVolEnv=36]="DecayVolEnv",c[c.SustainVolEnv=37]="SustainVolEnv",c[c.ReleaseVolEnv=38]="ReleaseVolEnv",c[c.KeyNumToVolEnvHold=39]="KeyNumToVolEnvHold",c[c.KeyNumToVolEnvDecay=40]="KeyNumToVolEnvDecay",c[c.Instrument=41]="Instrument",c[c.Reserved1=42]="Reserved1",c[c.KeyRange=43]="KeyRange",c[c.VelRange=44]="VelRange",c[c.StartLoopAddrsCoarseOffset=45]="StartLoopAddrsCoarseOffset",c[c.KeyNum=46]="KeyNum",c[c.Velocity=47]="Velocity",c[c.InitialAttenuation=48]="InitialAttenuation",c[c.Reserved2=49]="Reserved2",c[c.EndLoopAddrsCoarseOffset=50]="EndLoopAddrsCoarseOffset",c[c.CoarseTune=51]="CoarseTune",c[c.FineTune=52]="FineTune",c[c.SampleId=53]="SampleId",c[c.SampleModes=54]="SampleModes",c[c.Reserved3=55]="Reserved3",c[c.ScaleTuning=56]="ScaleTuning",c[c.ExclusiveClass=57]="ExclusiveClass",c[c.OverridingRootKey=58]="OverridingRootKey",c[c.Unused5=59]="Unused5",c[c.EndOper=60]="EndOper"})(o||(o={}));var l=(i(a={},o.StartAddrsOffset,0),i(a,o.EndAddrsOffset,0),i(a,o.StartLoopAddrsOffset,0),i(a,o.EndLoopAddrsOffset,0),i(a,o.StartAddrsCoarseOffset,0),i(a,o.ModLFOToPitch,0),i(a,o.VibLFOToPitch,0),i(a,o.ModEnvToPitch,0),i(a,o.InitialFilterFc,13500),i(a,o.InitialFilterQ,0),i(a,o.ModLFOToFilterFc,0),i(a,o.ModEnvToFilterFc,0),i(a,o.EndAddrsCoarseOffset,0),i(a,o.ModLFOToVolume,0),i(a,o.ChorusEffectsSend,0),i(a,o.ReverbEffectsSend,0),i(a,o.Pan,0),i(a,o.DelayModLFO,-12e3),i(a,o.FreqModLFO,0),i(a,o.DelayVibLFO,-12e3),i(a,o.FreqVibLFO,0),i(a,o.DelayModEnv,-12e3),i(a,o.AttackModEnv,-12e3),i(a,o.HoldModEnv,-12e3),i(a,o.DecayModEnv,-12e3),i(a,o.SustainModEnv,0),i(a,o.ReleaseModEnv,-12e3),i(a,o.KeyNumToModEnvHold,0),i(a,o.KeyNumToModEnvDecay,0),i(a,o.DelayVolEnv,-12e3),i(a,o.AttackVolEnv,-12e3),i(a,o.HoldVolEnv,-12e3),i(a,o.DecayVolEnv,-12e3),i(a,o.SustainVolEnv,0),i(a,o.ReleaseVolEnv,-12e3),i(a,o.KeyNumToVolEnvHold,0),i(a,o.KeyNumToVolEnvDecay,0),i(a,o.StartLoopAddrsCoarseOffset,0),i(a,o.KeyNum,-1),i(a,o.Velocity,-1),i(a,o.InitialAttenuation,0),i(a,o.EndLoopAddrsCoarseOffset,0),i(a,o.CoarseTune,0),i(a,o.FineTune,0),i(a,o.SampleModes,0),i(a,o.ScaleTuning,100),i(a,o.ExclusiveClass,0),i(a,o.OverridingRootKey,-1),a)},"./src/types/index.ts":function(n,r,s){s.r(r);var a=s("./src/types/bank.ts");for(var o in a)["default"].indexOf(o)<0&&(function(v){s.d(r,v,(function(){return a[v]}))})(o);var i=s("./src/types/generator.ts");s.d(r,"GeneratorType",(function(){return i.GeneratorType})),s.d(r,"DEFAULT_GENERATOR_VALUES",(function(){return i.DEFAULT_GENERATOR_VALUES}));var l=s("./src/types/instrument.ts");for(var o in l)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return l[y]}))})(o);var c=s("./src/types/key.ts");for(var o in c)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return c[y]}))})(o);var u=s("./src/types/metaData.ts");for(var o in u)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return u[y]}))})(o);var f=s("./src/types/modulator.ts");s.d(r,"ControllerType",(function(){return f.ControllerType})),s.d(r,"ControllerPolarity",(function(){return f.ControllerPolarity})),s.d(r,"ControllerDirection",(function(){return f.ControllerDirection})),s.d(r,"ControllerPalette",(function(){return f.ControllerPalette})),s.d(r,"Controller",(function(){return f.Controller})),s.d(r,"TransformType",(function(){return f.TransformType})),s.d(r,"DEFAULT_INSTRUMENT_MODULATORS",(function(){return f.DEFAULT_INSTRUMENT_MODULATORS}));var m=s("./src/types/preset.ts");for(var o in m)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return m[y]}))})(o);var d=s("./src/types/presetData.ts");for(var o in d)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return d[y]}))})(o);var h=s("./src/types/sample.ts");s.d(r,"SampleType",(function(){return h.SampleType}));var g=s("./src/types/zone.ts");for(var o in g)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS","SampleType"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return g[y]}))})(o)},"./src/types/instrument.ts":function(n,r){},"./src/types/key.ts":function(n,r){},"./src/types/metaData.ts":function(n,r){},"./src/types/modulator.ts":function(n,r,s){s.r(r),s.d(r,"ControllerType",(function(){return a})),s.d(r,"ControllerPolarity",(function(){return o})),s.d(r,"ControllerDirection",(function(){return i})),s.d(r,"ControllerPalette",(function(){return l})),s.d(r,"Controller",(function(){return c})),s.d(r,"TransformType",(function(){return u})),s.d(r,"DEFAULT_INSTRUMENT_MODULATORS",(function(){return m}));var a,o,i,l,c,u,f=s("./src/types/generator.ts");(function(d){d[d.Linear=0]="Linear",d[d.Concave=1]="Concave",d[d.Convex=2]="Convex",d[d.Switch=3]="Switch"})(a||(a={})),(function(d){d[d.Unipolar=0]="Unipolar",d[d.Bipolar=1]="Bipolar"})(o||(o={})),(function(d){d[d.Increasing=0]="Increasing",d[d.Decreasing=1]="Decreasing"})(i||(i={})),(function(d){d[d.GeneralController=0]="GeneralController",d[d.MidiController=1]="MidiController"})(l||(l={})),(function(d){d[d.NoController=0]="NoController",d[d.NoteOnVelocity=2]="NoteOnVelocity",d[d.NoteOnKeyNumber=3]="NoteOnKeyNumber",d[d.PolyPressure=10]="PolyPressure",d[d.ChannelPressure=13]="ChannelPressure",d[d.PitchWheel=14]="PitchWheel",d[d.PitchWheelSensitivity=16]="PitchWheelSensitivity",d[d.Link=127]="Link"})(c||(c={})),(function(d){d[d.Linear=0]="Linear",d[d.Absolute=2]="Absolute"})(u||(u={}));var m=[{id:f.GeneratorType.InitialAttenuation,source:{type:a.Concave,polarity:o.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:960,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialFilterFc,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:-2400,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.ChannelPressure},value:50,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.MidiController,index:1},value:50,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:a.Concave,polarity:o.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:7},value:960,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:a.Linear,polarity:o.Bipolar,direction:i.Increasing,palette:l.MidiController,index:10},value:1e3,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:a.Concave,polarity:o.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:11},value:960,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ReverbEffectsSend,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.MidiController,index:91},value:200,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ChorusEffectsSend,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.MidiController,index:93},value:200,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.CoarseTune,source:{type:a.Linear,polarity:o.Bipolar,direction:i.Increasing,palette:l.GeneralController,index:c.PitchWheel},value:12700,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.PitchWheelSensitivity},transform:u.Linear}]},"./src/types/preset.ts":function(n,r){},"./src/types/presetData.ts":function(n,r){},"./src/types/sample.ts":function(n,r,s){var a;s.r(r),s.d(r,"SampleType",(function(){return a})),(function(o){o[o.EOS=0]="EOS",o[o.Mono=1]="Mono",o[o.Right=2]="Right",o[o.Left=4]="Left",o[o.Linked=8]="Linked",o[o.RomMono=32769]="RomMono",o[o.RomRight=32770]="RomRight",o[o.RomLeft=32772]="RomLeft",o[o.RomLinked=32776]="RomLinked"})(a||(a={}))},"./src/types/zone.ts":function(n,r){},"./src/utils/buffer.ts":function(n,r,s){s.r(r),s.d(r,"getStringFromBuffer",(function(){return a}));var a=function(o){var i=new TextDecoder("utf8").decode(o),l=i.indexOf("\0");return(l===-1?i:i.slice(0,l)).trim()}},"./src/utils/index.ts":function(n,r,s){s.r(r);var a=s("./src/utils/buffer.ts");s.d(r,"getStringFromBuffer",(function(){return a.getStringFromBuffer}));var o=s("./src/utils/memoize.ts");s.d(r,"memoize",(function(){return o.memoize}))},"./src/utils/memoize.ts":function(n,r,s){s.r(r),s.d(r,"memoize",(function(){return a}));var a=function(o){var i={};return function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];var f=JSON.stringify(c);if(f in i)return i[f];var m=o.apply(void 0,c);return i[f]=m,m}}}})}))})(ca)),ca.exports}nh();var Pe=1e3;function Ea(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m}=e,d=t?.sampleRate??e.sampleRate??c?.sample_rate,h=t?.length??e.sourceDurationSamples??(c&&d?Math.ceil(c.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(h===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&c&&t.sampleRate!==c.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${c.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.durationSamples??h;return{id:dc(),audioBuffer:t,startSample:n,durationSamples:g,offsetSamples:r,sampleRate:d,sourceDurationSamples:h,gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m}}function cc(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m}=e,d=t?.sampleRate??e.sampleRate??c?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const h=t?.duration??e.sourceDuration??c?.duration;if(h===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&c&&t.sampleRate!==c.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${c.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.duration??h;return Ea({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(g*d),offsetSamples:Math.round(r*d),sampleRate:d,sourceDurationSamples:Math.ceil(h*d),gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m})}function uc(e){const{name:t,clips:n=[],muted:r=!1,soloed:s=!1,volume:a=1,pan:o=0,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}=e;return{id:dc(),name:t,clips:n,muted:r,soloed:s,volume:a,pan:o,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}}function dc(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function il(e){return[...e].sort((t,n)=>t.startSample-n.startSample)}function rh(e,t){return Math.floor(e/t)}function sh(e,t,n){return Math.ceil(e*n/t)}var Nn=192;function Vs(e,t=Nn){const[,n]=e;return t*(4/n)}function vo(e,t=Nn){const[n]=e;return n*Vs(e,t)}function Rn(e,t,n,r=Nn){return Math.round(e*60*n/(t*r))}function Ia(e,t,n,r=Nn){return Math.round(e*r*t/(60*n))}function Ma(e,t){return Math.round(e/t)*t}function ah(e,t,n=Nn){const r=vo(t,n),s=Vs(t,n),a=Math.floor(e/r)+1,o=Math.floor(e%r/s)+1;return o===1?`${a}`:`${a}.${o}`}function qr(e){return e.startSample/e.sampleRate}function ll(e){return(e.startSample+e.durationSamples)/e.sampleRate}function cl(e){return e.offsetSamples/e.sampleRate}function ul(e){return e.durationSamples/e.sampleRate}function fc(e,t,n){return Math.floor((e+t)/n)-Math.floor(e/n)}var dl=!1;function vr(e){const t=e._param;return!t&&!dl&&(dl=!0,console.warn("[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Mute scheduling may not work correctly.")),t}function fl(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r;n[s]=t?a:1-a}return n}function oh(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r,o=t?s:e-1-s;n[o]=Math.exp(2*a-1)/Math.E}return n}function ih(e,t){const n=new Float32Array(e),r=t?Math.PI/2:-Math.PI/2;for(let s=0;s<e;s++)n[s]=Math.sin(Math.PI*s/e-r)/2+.5;return n}function lh(e,t,n=10){const r=new Float32Array(e);for(let s=0;s<e;s++){const a=t?s:e-1-s,o=s/e;r[a]=Math.log(1+n*o)/Math.log(1+n)}return r}function hc(e,t,n){switch(e){case"linear":return fl(t,n);case"exponential":return oh(t,n);case"sCurve":return ih(t,n);case"logarithmic":return lh(t,n);default:return fl(t,n)}}function hl(e,t,n,r="linear",s=0,a=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=hc(r,1e4,!0),i=new Float32Array(o.length),l=a-s;for(let c=0;c<o.length;c++)i[c]=s+o[c]*l;e.setValueCurveAtTime(i,t,n)}}function pl(e,t,n,r="linear",s=1,a=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=hc(r,1e4,!1),i=new Float32Array(o.length),l=s-a;for(let c=0;c<o.length;c++)i[c]=a+o[c]*l;e.setValueCurveAtTime(i,t,n)}}var ch=class{constructor(e){this.activeSources=new Set,this._scheduleGuardOffset=0,this.track=e.track,this.volumeNode=new L.Volume(this.gainToDb(e.track.gain)),this.panNode=new L.Panner(e.track.stereoPan),this.muteGain=new L.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const t=e.destination||L.getDestination();if(e.effects){const o=e.effects(this.muteGain,t,!1);o&&(this.effectsCleanup=o)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]),r=L.getTransport(),s=L.getContext().rawContext,a=this.volumeNode.input.input;this.scheduledClips=n.map(o=>{const i=s.createGain();i.gain.value=o.gain,i.connect(a);const l=this.track.startTime+o.startTime,c=r.schedule(u=>{l<this._scheduleGuardOffset||this.startClipSource(o,i,u)},l);return{clipInfo:o,fadeGainNode:i,scheduleId:c}})}startClipSource(e,t,n,r,s){const o=L.getContext().rawContext.createBufferSource();o.buffer=e.buffer,o.connect(t);const i=r??e.offset,l=s??e.duration;try{o.start(n,i,l)}catch(c){console.warn(`[waveform-playlist] Failed to start source on track "${this.id}" (time=${n}, offset=${i}, duration=${l}):`,c),o.disconnect();return}this.activeSources.add(o),o.onended=()=>{this.activeSources.delete(o)}}setScheduleGuardOffset(e){this._scheduleGuardOffset=e}startMidClipSources(e,t){for(const{clipInfo:n,fadeGainNode:r}of this.scheduledClips){const s=this.track.startTime+n.startTime,a=s+n.duration;if(s<e&&a>e){const o=e-s,i=n.offset+o,l=n.duration-o;this.startClipSource(n,r,t,i,l)}}}stopAllSources(){this.activeSources.forEach(e=>{try{e.stop()}catch(t){console.warn(`[waveform-playlist] Error stopping source on track "${this.id}":`,t)}}),this.activeSources.clear()}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGainNode:s}=e,a=s.gain;a.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const i=r.fadeIn.duration;if(o<=0)hl(a,t,i,r.fadeIn.type||"linear",0,r.gain);else{const l=i-o,c=o/i,u=r.gain*c;hl(a,t,l,r.fadeIn.type||"linear",u,r.gain)}}else a.setValueAtTime(r.gain,t);if(r.fadeOut){const l=r.duration-r.fadeOut.duration-o;if(l>0){const c=t+l;pl(a,c,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(l>-r.fadeOut.duration){const c=-l,u=r.fadeOut.duration-c,f=c/r.fadeOut.duration,m=r.gain*(1-f);pl(a,t,u,r.fadeOut.type||"linear",m,0)}}}prepareFades(e,t){this.scheduledClips.forEach(n=>{const r=this.track.startTime+n.clipInfo.startTime,s=r+n.clipInfo.duration;if(!(t>=s))if(t>=r){const a=t-r+n.clipInfo.offset;this.scheduleFades(n,e,a)}else{const a=r-t;this.scheduleFades(n,e+a,n.clipInfo.offset)}})}cancelFades(){this.scheduledClips.forEach(({fadeGainNode:e,clipInfo:t})=>{const n=e.gain;n.cancelScheduledValues(0),n.setValueAtTime(t.gain,0)})}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;vr(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){const e=L.getTransport();if(this.effectsCleanup)try{this.effectsCleanup()}catch(t){console.warn(`[waveform-playlist] Error during track "${this.id}" effects cleanup:`,t)}this.stopAllSources(),this.scheduledClips.forEach((t,n)=>{try{e.clear(t.scheduleId)}catch(r){console.warn(`[waveform-playlist] Error clearing schedule ${n} on track "${this.id}":`,r)}try{t.fadeGainNode.disconnect()}catch(r){console.warn(`[waveform-playlist] Error disconnecting fadeGain ${n} on track "${this.id}":`,r)}});try{this.volumeNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing volumeNode on track "${this.id}":`,t)}try{this.panNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing panNode on track "${this.id}":`,t)}try{this.muteGain.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing muteGain on track "${this.id}":`,t)}}get id(){return this.track.id}get duration(){if(this.scheduledClips.length===0)return 0;const e=this.scheduledClips[this.scheduledClips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.scheduledClips[0]?.clipInfo.buffer}get muted(){return this.track.muted}get startTime(){return this.track.startTime}};function uh(e){return e===35||e===36?"kick":e>=37&&e<=40?"snare":e===41||e===43||e===45||e===47||e===48||e===50?"tom":"cymbal"}var dh=class{constructor(e){this.track=e.track,this.volumeNode=new L.Volume(this.gainToDb(e.track.gain)),this.panNode=new L.Panner(e.track.stereoPan),this.muteGain=new L.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain),this.synth=new L.PolySynth(L.Synth,e.synthOptions),this.synth.connect(this.volumeNode),this.kickSynth=new L.PolySynth(L.MembraneSynth,{voice:L.MembraneSynth,options:{pitchDecay:.05,octaves:6,envelope:{attack:.001,decay:.4,sustain:0,release:.1}}}),this.snareSynth=new L.NoiseSynth({noise:{type:"white"},envelope:{attack:.001,decay:.15,sustain:0,release:.05}}),this.cymbalSynth=new L.PolySynth(L.MetalSynth,{voice:L.MetalSynth,options:{envelope:{attack:.001,decay:.3,release:.1},harmonicity:5.1,modulationIndex:32,resonance:4e3,octaves:1.5}}),this.tomSynth=new L.PolySynth(L.MembraneSynth,{voice:L.MembraneSynth,options:{pitchDecay:.08,octaves:4,envelope:{attack:.001,decay:.3,sustain:0,release:.1}}}),this.kickSynth.connect(this.volumeNode),this.snareSynth.connect(this.volumeNode),this.cymbalSynth.connect(this.volumeNode),this.tomSynth.connect(this.volumeNode);const t=e.destination||L.getDestination();if(e.effects){const n=e.effects(this.muteGain,t,!1);n&&(this.effectsCleanup=n)}else this.muteGain.connect(t);this.scheduledClips=e.clips.map(n=>{const r=n.notes.filter(i=>{const l=i.time+i.duration;return i.time<n.offset+n.duration&&l>n.offset}),s=this.track.startTime+n.startTime,a=r.map(i=>{const l=i.time-n.offset,c=Math.max(0,l),u=Math.min(i.duration-Math.max(0,n.offset-i.time),n.duration-c);return{time:s+c,note:i.name,midi:i.midi,duration:Math.max(0,u),velocity:i.velocity,channel:i.channel}}),o=new L.Part((i,l)=>{l.duration>0&&this.triggerNote(l.midi,l.note,l.duration,i,l.velocity,l.channel)},a);return o.start(0),{clipInfo:n,part:o}})}triggerNote(e,t,n,r,s,a){if(a===9)switch(uh(e)){case"kick":this.kickSynth.triggerAttackRelease("C1",n,r,s);break;case"snare":try{this.snareSynth.triggerAttackRelease(n,r,s)}catch(i){console.warn("[waveform-playlist] Snare overlap — previous hit still decaying, skipped:",i)}break;case"tom":{const i={41:"G1",43:"A1",45:"C2",47:"D2",48:"E2",50:"G2"};this.tomSynth.triggerAttackRelease(i[e]||"C2",n,r,s);break}case"cymbal":this.cymbalSynth.triggerAttackRelease("C4",n,r,s);break}else this.synth.triggerAttackRelease(t,n,r,s)}gainToDb(e){return 20*Math.log10(e)}setScheduleGuardOffset(e){}startMidClipSources(e,t){for(const{clipInfo:n}of this.scheduledClips){const r=this.track.startTime+n.startTime,s=r+n.duration;if(r<e&&s>e)for(const a of n.notes){const o=a.time-n.offset,i=r+Math.max(0,o),l=i+a.duration;if(i<e&&l>e){const c=l-e;try{this.triggerNote(a.midi,a.name,c,t,a.velocity,a.channel)}catch(u){console.warn(`[waveform-playlist] Failed to start mid-clip MIDI note "${a.name}" on track "${this.id}":`,u)}}}}}stopAllSources(){const e=L.getContext().rawContext.currentTime;try{this.synth.releaseAll(e),this.kickSynth.releaseAll(e),this.cymbalSynth.releaseAll(e),this.tomSynth.releaseAll(e)}catch(t){console.warn(`[waveform-playlist] Error releasing synth on track "${this.id}":`,t)}}prepareFades(e,t){}cancelFades(){}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;vr(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){if(this.effectsCleanup)try{this.effectsCleanup()}catch(t){console.warn(`[waveform-playlist] Error during MIDI track "${this.id}" effects cleanup:`,t)}this.stopAllSources(),this.scheduledClips.forEach(({part:t},n)=>{try{t.dispose()}catch(r){console.warn(`[waveform-playlist] Error disposing Part ${n} on MIDI track "${this.id}":`,r)}});const e=[this.synth,this.kickSynth,this.snareSynth,this.cymbalSynth,this.tomSynth];for(const t of e)try{t?.dispose()}catch(n){console.warn(`[waveform-playlist] Error disposing synth on MIDI track "${this.id}":`,n)}try{this.volumeNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing volumeNode on MIDI track "${this.id}":`,t)}try{this.panNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing panNode on MIDI track "${this.id}":`,t)}try{this.muteGain.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing muteGain on MIDI track "${this.id}":`,t)}}get id(){return this.track.id}get duration(){if(this.scheduledClips.length===0)return 0;const e=this.scheduledClips[this.scheduledClips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get muted(){return this.track.muted}get startTime(){return this.track.startTime}},pc=class Aa{constructor(t){this.activeSources=new Set,this.track=t.track,this.soundFontCache=t.soundFontCache,this.programNumber=t.programNumber??0,this.bankNumber=t.isPercussion?128:0,this.volumeNode=new L.Volume(this.gainToDb(t.track.gain)),this.panNode=new L.Panner(t.track.stereoPan),this.muteGain=new L.Gain(t.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const n=t.destination||L.getDestination();if(t.effects){const r=t.effects(this.muteGain,n,!1);r&&(this.effectsCleanup=r)}else this.muteGain.connect(n);this.scheduledClips=t.clips.map(r=>{const s=r.notes.filter(l=>{const c=l.time+l.duration;return l.time<r.offset+r.duration&&c>r.offset}),a=this.track.startTime+r.startTime,o=s.map(l=>{const c=l.time-r.offset,u=Math.max(0,c),f=Math.min(l.duration-Math.max(0,r.offset-l.time),r.duration-u);return{time:a+u,note:l.name,midi:l.midi,duration:Math.max(0,f),velocity:l.velocity,channel:l.channel}}),i=new L.Part((l,c)=>{c.duration>0&&this.triggerNote(c.midi,c.duration,l,c.velocity,c.channel)},o);return i.start(0),{clipInfo:r,part:i}})}triggerNote(t,n,r,s,a){const o=a===9?128:this.bankNumber,i=a===9?0:this.programNumber,l=this.soundFontCache.getAudioBuffer(t,o,i);if(!l){Aa._missingSampleWarned||(console.warn(`[waveform-playlist] SoundFont sample not found for MIDI note ${t} (bank ${o}, preset ${i}). Subsequent missing samples will be silent.`),Aa._missingSampleWarned=!0);return}const c=L.getContext().rawContext,u=c.createBufferSource();u.buffer=l.buffer,u.playbackRate.value=l.playbackRate,(l.loopMode===1||l.loopMode===3)&&(u.loop=!0,u.loopStart=l.loopStart,u.loopEnd=l.loopEnd);const f=l.buffer.duration/l.playbackRate,m=l.loopMode===0?Math.max(n,f):n,d=s*s,h=c.createGain(),{attackVolEnv:g,holdVolEnv:v,decayVolEnv:y,sustainVolEnv:b,releaseVolEnv:w}=l,_=d*b;h.gain.setValueAtTime(0,r),h.gain.linearRampToValueAtTime(d,r+g),v>.001&&h.gain.setValueAtTime(d,r+g+v);const x=r+g+v;h.gain.linearRampToValueAtTime(_,x+y),h.gain.setValueAtTime(_,r+m),h.gain.linearRampToValueAtTime(0,r+m+w),u.connect(h),h.connect(this.volumeNode.input.input),this.activeSources.add(u),u.onended=()=>{this.activeSources.delete(u);try{h.disconnect()}catch(S){console.warn("[waveform-playlist] GainNode already disconnected:",S)}},u.start(r),u.stop(r+m+w)}gainToDb(t){return 20*Math.log10(t)}setScheduleGuardOffset(t){}startMidClipSources(t,n){for(const{clipInfo:r}of this.scheduledClips){const s=this.track.startTime+r.startTime,a=s+r.duration;if(s<t&&a>t)for(const o of r.notes){const i=o.time-r.offset,l=s+Math.max(0,i),c=l+o.duration;if(l<t&&c>t){const u=c-t;try{this.triggerNote(o.midi,u,n,o.velocity,o.channel)}catch(f){console.warn(`[waveform-playlist] Failed to start mid-clip SoundFont note on track "${this.id}":`,f)}}}}}stopAllSources(){for(const t of this.activeSources)try{t.stop()}catch(n){console.warn("[waveform-playlist] Error stopping AudioBufferSourceNode:",n)}this.activeSources.clear()}prepareFades(t,n){}cancelFades(){}setVolume(t){this.track.gain=t,this.volumeNode.volume.value=this.gainToDb(t)}setPan(t){this.track.stereoPan=t,this.panNode.pan.value=t}setMute(t){this.track.muted=t;const n=t?0:1;vr(this.muteGain.gain)?.setValueAtTime(n,0),this.muteGain.gain.value=n}setSolo(t){this.track.soloed=t}dispose(){if(this.effectsCleanup)try{this.effectsCleanup()}catch(t){console.warn(`[waveform-playlist] Error during SoundFont track "${this.id}" effects cleanup:`,t)}this.stopAllSources(),this.scheduledClips.forEach(({part:t},n)=>{try{t.dispose()}catch(r){console.warn(`[waveform-playlist] Error disposing Part ${n} on SoundFont track "${this.id}":`,r)}});try{this.volumeNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing volumeNode on SoundFont track "${this.id}":`,t)}try{this.panNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing panNode on SoundFont track "${this.id}":`,t)}try{this.muteGain.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing muteGain on SoundFont track "${this.id}":`,t)}}get id(){return this.track.id}get duration(){if(this.scheduledClips.length===0)return 0;const t=this.scheduledClips[this.scheduledClips.length-1];return t.clipInfo.startTime+t.clipInfo.duration}get muted(){return this.track.muted}get startTime(){return this.track.startTime}};pc._missingSampleWarned=!1;var fh=pc,hh=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this._completionEventId=null,this._loopHandler=null,this._loopEnabled=!1,this._loopStart=0,this._loopEnd=0,this.masterVolume=new L.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,L.getDestination(),!1);t&&(this.effectsCleanup=t)}else this.masterVolume.toDestination();e.tracks&&e.tracks.forEach(t=>{this.tracks.set(t.id,t),this.manualMuteState.set(t.id,t.muted)})}gainToDb(e){return 20*Math.log10(e)}clearCompletionEvent(){if(this._completionEventId!==null){try{L.getTransport().clear(this._completionEventId)}catch(e){console.warn("[waveform-playlist] Error clearing Transport completion event:",e)}this._completionEventId=null}}async init(){this.isInitialized||(await L.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new ch(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}addMidiTrack(e){const t={...e,destination:this.masterVolume},n=new dh(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}addSoundFontTrack(e){const t={...e,destination:this.masterVolume},n=new fh(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}applyInitialSoloState(){this.updateSoloMuting()}removeTrack(e){const t=this.tracks.get(e);t&&(t.dispose(),this.tracks.delete(e),this.manualMuteState.delete(e),this.soloedTracks.delete(e))}getTrack(e){return this.tracks.get(e)}play(e,t,n){if(!this.isInitialized)throw new Error("[waveform-playlist] TonePlayout not initialized. Call init() first.");const r=e??L.now(),s=L.getTransport();this.clearCompletionEvent();const a=t??0;this.tracks.forEach(o=>{o.cancelFades(),o.prepareFades(r,a)}),n!==void 0&&(this._completionEventId=s.scheduleOnce(()=>{this._completionEventId=null;try{this.onPlaybackCompleteCallback?.()}catch(o){console.warn("[waveform-playlist] Error in playback completion callback:",o)}},a+n));try{s.state!=="stopped"&&s.stop(),this.tracks.forEach(o=>o.stopAllSources()),s.loopStart=this._loopStart,s.loopEnd=this._loopEnd,s.loop=this._loopEnabled,this.tracks.forEach(o=>o.setScheduleGuardOffset(a)),t!==void 0?s.start(r,t):s.start(r),s._clock._lastUpdate=r,this.tracks.forEach(o=>{o.startMidClipSources(a,r)})}catch(o){throw this.clearCompletionEvent(),this.tracks.forEach(i=>i.cancelFades()),console.warn("[waveform-playlist] Transport.start() failed. Audio playback could not begin.",o),o}}pause(){const e=L.getTransport();try{e.pause()}catch(t){console.warn("[waveform-playlist] Transport.pause() failed:",t)}this.tracks.forEach(t=>t.stopAllSources()),this.tracks.forEach(t=>t.cancelFades()),this.clearCompletionEvent()}stop(){const e=L.getTransport();try{e.stop()}catch(t){console.warn("[waveform-playlist] Transport.stop() failed:",t)}if(this._loopHandler){try{e.off("loop",this._loopHandler)}catch(t){console.warn("[waveform-playlist] Error removing loop handler:",t)}this._loopHandler=null}this.tracks.forEach(t=>t.stopAllSources()),this.tracks.forEach(t=>t.cancelFades()),this.clearCompletionEvent()}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}setLoop(e,t,n){this._loopEnabled=e,this._loopStart=t,this._loopEnd=n;const r=L.getTransport();try{r.loopStart=t,r.loopEnd=n,r.loop=e}catch(s){console.warn("[waveform-playlist] Error configuring Transport loop:",s);return}e&&!this._loopHandler?(this._loopHandler=()=>{const s=L.now();this.tracks.forEach(a=>{try{a.stopAllSources(),a.cancelFades(),a.setScheduleGuardOffset(this._loopStart),a.startMidClipSources(this._loopStart,s),a.prepareFades(s,this._loopStart)}catch(o){console.warn(`[waveform-playlist] Error re-scheduling track "${a.id}" on loop:`,o)}})},r.on("loop",this._loopHandler)):!e&&this._loopHandler&&(r.off("loop",this._loopHandler),this._loopHandler=null)}getCurrentTime(){return L.getTransport().seconds}seekTo(e){L.getTransport().seconds=e}dispose(){if(this.clearCompletionEvent(),this._loopHandler){try{L.getTransport().off("loop",this._loopHandler)}catch(e){console.warn("[waveform-playlist] Error removing Transport loop handler:",e)}this._loopHandler=null}if(this.tracks.forEach(e=>{try{e.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing track "${e.id}":`,t)}}),this.tracks.clear(),this.effectsCleanup)try{this.effectsCleanup()}catch(e){console.warn("[waveform-playlist] Error during master effects cleanup:",e)}try{this.masterVolume.dispose()}catch(e){console.warn("[waveform-playlist] Error disposing master volume:",e)}}get context(){return L.getContext()}get sampleRate(){return L.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Jr=null;function ph(){return Jr||(Jr=new L.Context,L.setContext(Jr)),Jr}function mh(){return ph().rawContext}function gh(e){let t=null,n=!1,r=0,s=!1,a=0,o=0,i=!1;function l(c){if(t){try{t.dispose()}catch(f){console.warn("[waveform-playlist] Error disposing previous playout during rebuild:",f)}t=null}r++;const u=r;t=new hh({effects:e?.effects}),i&&t.init().catch(f=>{console.warn("[waveform-playlist] Failed to re-initialize playout after rebuild. Audio playback will require another user gesture.",f),i=!1});for(const f of c){const m=f.clips.filter(h=>h.audioBuffer&&!h.midiNotes),d=f.clips.filter(h=>h.midiNotes&&h.midiNotes.length>0);if(m.length>0){const h=Math.min(...m.map(qr)),g=Math.max(...m.map(ll)),v={id:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:h,endTime:g},y=m.map(b=>({buffer:b.audioBuffer,startTime:qr(b)-h,duration:ul(b),offset:cl(b),fadeIn:b.fadeIn,fadeOut:b.fadeOut,gain:b.gain}));t.addTrack({clips:y,track:v,effects:f.effects})}if(d.length>0){const h=Math.min(...d.map(qr)),g=Math.max(...d.map(ll)),y={id:m.length>0?`${f.id}:midi`:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:h,endTime:g},b=d.map(w=>({notes:w.midiNotes,startTime:qr(w)-h,duration:ul(w),offset:cl(w)}));if(e?.soundFontCache?.isLoaded){const w=d[0],x=w.midiChannel===9,S=w.midiProgram??0;t.addSoundFontTrack({clips:b,track:y,soundFontCache:e.soundFontCache,programNumber:S,isPercussion:x,effects:f.effects})}else e?.soundFontCache&&console.warn(`[waveform-playlist] SoundFont not loaded for track "${f.name}" — falling back to PolySynth.`),t.addMidiTrack({clips:b,track:y,effects:f.effects})}}t.applyInitialSoloState(),t.setLoop(s,a,o),t.setOnPlaybackComplete(()=>{u===r&&(n=!1)})}return{async init(){t&&(await t.init(),i=!0)},setTracks(c){l(c)},play(c,u){if(!t){console.warn("[waveform-playlist] adapter.play() called but no playout is available. Tracks may not have been set, or the adapter was disposed.");return}const f=u!==void 0?u-c:void 0;t.play(L.now(),c,f),n=!0},pause(){t?.pause(),n=!1},stop(){t?.stop(),n=!1},seek(c){t?.seekTo(c)},getCurrentTime(){return t?.getCurrentTime()??0},isPlaying(){return n},setMasterVolume(c){t?.setMasterGain(c)},setTrackVolume(c,u){t?.getTrack(c)?.setVolume(u)},setTrackMute(c,u){t?.setMute(c,u)},setTrackSolo(c,u){t?.setSolo(c,u)},setTrackPan(c,u){t?.getTrack(c)?.setPan(u)},setLoop(c,u,f){s=c,a=u,o=f,t?.setLoop(c,u,f)},dispose(){try{t?.dispose()}catch(c){console.warn("[waveform-playlist] Error disposing playout:",c)}t=null,n=!1}}}function mc(e,t,n,r){let s=t;const a=-e.startSample;if(s=Math.max(s,a),r>0){const o=n[r-1],l=o.startSample+o.durationSamples-e.startSample;s=Math.max(s,l)}if(r<n.length-1){const i=n[r+1].startSample-(e.startSample+e.durationSamples);s=Math.min(s,i)}return s}function gc(e,t,n,r,s,a){let o=t;if(n==="left"){if(o=Math.max(o,-e.startSample),o=Math.max(o,-e.offsetSamples),s>0){const i=r[s-1],l=i.startSample+i.durationSamples;o=Math.max(o,l-e.startSample)}o=Math.min(o,e.durationSamples-a)}else if(o=Math.max(o,a-e.durationSamples),o=Math.min(o,e.sourceDurationSamples-e.offsetSamples-e.durationSamples),s<r.length-1){const i=r[s+1];o=Math.min(o,i.startSample-e.startSample-e.durationSamples)}return o}function vh(e,t){return Math.floor(e/t)*t}function yh(e,t){const n=t-e.startSample,r=e.durationSamples-n,s=e.name?`${e.name} (1)`:void 0,a=e.name?`${e.name} (2)`:void 0,o=Ea({startSample:e.startSample,durationSamples:n,offsetSamples:e.offsetSamples,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:s,color:e.color,fadeIn:e.fadeIn,audioBuffer:e.audioBuffer,waveformData:e.waveformData}),i=Ea({startSample:t,durationSamples:r,offsetSamples:e.offsetSamples+n,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:a,color:e.color,fadeOut:e.fadeOut,audioBuffer:e.audioBuffer,waveformData:e.waveformData});return{left:o,right:i}}function vc(e,t,n){const r=e.startSample+e.durationSamples;if(t<=e.startSample||t>=r)return!1;const s=t-e.startSample,a=r-t;return s>=n&&a>=n}function ua(e){let t=0;for(const n of e)for(const r of n.clips){const a=(r.startSample+r.durationSamples)/r.sampleRate;t=Math.max(t,a)}return t}function bh(e,t){if(t.length===0)return 0;let n=0,r=Math.abs(t[0]-e);for(let s=1;s<t.length;s++){const a=Math.abs(t[s]-e);a<r&&(r=a,n=s)}return n}function ml(e,t){return Math.max(0,Math.min(e,t))}var wh=44100,_h=1024,xh=[256,512,1024,2048,4096,8192],gl=.1,Ch=class{constructor(e={}){if(this._tracks=[],this._currentTime=0,this._playStartPosition=0,this._isPlaying=!1,this._selectedTrackId=null,this._selectionStart=0,this._selectionEnd=0,this._masterVolume=1,this._loopStart=0,this._loopEnd=0,this._isLoopEnabled=!1,this._tracksVersion=0,this._animFrameId=null,this._disposed=!1,this._listeners=new Map,this._sampleRate=e.sampleRate??wh,this._zoomLevels=[...e.zoomLevels??xh],this._adapter=e.adapter??null,this._zoomLevels.length===0)throw new Error("PlaylistEngine: zoomLevels must not be empty");const t=e.samplesPerPixel??_h,n=this._zoomLevels.indexOf(t);if(n===-1)throw new Error(`PlaylistEngine: samplesPerPixel ${t} is not in zoomLevels [${this._zoomLevels.join(", ")}]. Either pass a samplesPerPixel value that exists in zoomLevels, or include ${t} in your zoomLevels array.`);this._zoomIndex=n}getState(){return{tracks:this._tracks.map(e=>({...e,clips:[...e.clips]})),tracksVersion:this._tracksVersion,duration:ua(this._tracks),currentTime:this._currentTime,isPlaying:this._isPlaying,samplesPerPixel:this._zoomLevels[this._zoomIndex],sampleRate:this._sampleRate,selectedTrackId:this._selectedTrackId,zoomIndex:this._zoomIndex,canZoomIn:this._zoomIndex>0,canZoomOut:this._zoomIndex<this._zoomLevels.length-1,selectionStart:this._selectionStart,selectionEnd:this._selectionEnd,masterVolume:this._masterVolume,loopStart:this._loopStart,loopEnd:this._loopEnd,isLoopEnabled:this._isLoopEnabled}}setTracks(e){this._tracks=[...e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}addTrack(e){this._tracks=[...this._tracks,e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}removeTrack(e){this._tracks.some(t=>t.id===e)&&(this._tracks=this._tracks.filter(t=>t.id!==e),this._tracksVersion++,this._selectedTrackId===e&&(this._selectedTrackId=null),this._adapter?.setTracks(this._tracks),this._emitStateChange())}selectTrack(e){e!==this._selectedTrackId&&(this._selectedTrackId=e,this._emitStateChange())}moveClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] moveClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] moveClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=il(r.clips),i=o.findIndex(c=>c.id===t),l=mc(a,n,o,i);l!==0&&(this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=c.clips.map((f,m)=>m===s?{...f,startSample:Math.floor(f.startSample+l)}:f);return{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}splitClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] splitClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] splitClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=Math.floor(gl*this._sampleRate);if(!vc(a,n,o)){console.warn(`[waveform-playlist/engine] splitClip: cannot split clip "${t}" at sample ${n} (clip range: ${a.startSample}–${a.startSample+a.durationSamples}, minDuration: ${o})`);return}const{left:i,right:l}=yh(a,n);this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=[...c.clips];return u.splice(s,1,i,l),{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}trimClip(e,t,n,r){const s=this._tracks.find(f=>f.id===e);if(!s){console.warn(`[waveform-playlist/engine] trimClip: track "${e}" not found`);return}const a=s.clips.findIndex(f=>f.id===t);if(a===-1){console.warn(`[waveform-playlist/engine] trimClip: clip "${t}" not found in track "${e}"`);return}const o=s.clips[a],i=il(s.clips),l=i.findIndex(f=>f.id===t),c=Math.floor(gl*this._sampleRate),u=gc(o,r,n,i,l,c);u!==0&&(this._tracks=this._tracks.map(f=>{if(f.id!==e)return f;const m=f.clips.map((d,h)=>h!==a?d:n==="left"?{...d,startSample:d.startSample+u,offsetSamples:d.offsetSamples+u,durationSamples:d.durationSamples-u}:{...d,durationSamples:d.durationSamples+u});return{...f,clips:m}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}async init(){this._adapter&&await this._adapter.init()}play(e,t){const n=this._currentTime,r=this._playStartPosition;if(e!==void 0){const s=ua(this._tracks);this._currentTime=ml(e,s)}if(this._playStartPosition=this._currentTime,this._adapter){if(t!==void 0)this._adapter.setLoop(!1,this._loopStart,this._loopEnd);else if(this._isLoopEnabled){const s=this._currentTime<this._loopEnd;this._adapter.setLoop(s,this._loopStart,this._loopEnd)}try{this._adapter.play(this._currentTime,t)}catch(s){throw this._currentTime=n,this._playStartPosition=r,s}}this._isPlaying=!0,this._startTimeUpdateLoop(),this._emit("play"),this._emitStateChange()}pause(){this._isPlaying=!1,this._stopTimeUpdateLoop(),this._adapter?.pause(),this._adapter&&(this._currentTime=this._adapter.getCurrentTime()),this._emit("pause"),this._emitStateChange()}stop(){this._isPlaying=!1,this._currentTime=this._playStartPosition,this._stopTimeUpdateLoop(),this._adapter?.setLoop(!1,this._loopStart,this._loopEnd),this._adapter?.stop(),this._emit("stop"),this._emitStateChange()}seek(e){const t=ua(this._tracks);this._currentTime=ml(e,t),this._adapter?.seek(this._currentTime),this._emitStateChange()}setMasterVolume(e){e!==this._masterVolume&&(this._masterVolume=e,this._adapter?.setMasterVolume(e),this._emitStateChange())}getCurrentTime(){return this._isPlaying&&this._adapter?this._adapter.getCurrentTime():this._currentTime}setSelection(e,t){const n=Math.min(e,t),r=Math.max(e,t);n===this._selectionStart&&r===this._selectionEnd||(this._selectionStart=n,this._selectionEnd=r,this._emitStateChange())}setLoopRegion(e,t){const n=Math.min(e,t),r=Math.max(e,t);n===this._loopStart&&r===this._loopEnd||(this._loopStart=n,this._loopEnd=r,this._adapter?.setLoop(this._isLoopEnabled&&this._isBeforeLoopEnd(),this._loopStart,this._loopEnd),this._emitStateChange())}setLoopEnabled(e){e!==this._isLoopEnabled&&(this._isLoopEnabled=e,this._adapter?.setLoop(e&&this._isBeforeLoopEnd(),this._loopStart,this._loopEnd),this._emitStateChange())}setTrackVolume(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.volume=t),this._adapter?.setTrackVolume(e,t)}setTrackMute(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.muted=t),this._adapter?.setTrackMute(e,t)}setTrackSolo(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.soloed=t),this._adapter?.setTrackSolo(e,t)}setTrackPan(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.pan=t),this._adapter?.setTrackPan(e,t)}zoomIn(){this._zoomIndex>0&&(this._zoomIndex--,this._emitStateChange())}zoomOut(){this._zoomIndex<this._zoomLevels.length-1&&(this._zoomIndex++,this._emitStateChange())}setZoomLevel(e){const t=bh(e,this._zoomLevels);t!==this._zoomIndex&&(this._zoomIndex=t,this._emitStateChange())}on(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}off(e,t){this._listeners.get(e)?.delete(t)}dispose(){if(!this._disposed){this._disposed=!0,this._stopTimeUpdateLoop();try{this._adapter?.dispose()}catch(e){console.warn("[waveform-playlist/engine] Error disposing adapter:",e)}this._listeners.clear()}}_emit(e,...t){const n=this._listeners.get(e);if(n)for(const r of n)try{r(...t)}catch(s){console.warn("[waveform-playlist/engine] Error in event listener:",s)}}_isBeforeLoopEnd(){return this._isPlaying?(this._adapter?.getCurrentTime()??this._currentTime)<this._loopEnd:!0}_emitStateChange(){this._emit("statechange",this.getState())}_startTimeUpdateLoop(){if(typeof requestAnimationFrame>"u")return;this._stopTimeUpdateLoop();const e=()=>{this._disposed||!this._isPlaying||(this._adapter&&(this._currentTime=this._adapter.getCurrentTime(),this._emit("timeupdate",this._currentTime)),this._animFrameId=requestAnimationFrame(e))};this._animFrameId=requestAnimationFrame(e)}_stopTimeUpdateLoop(){this._animFrameId!==null&&typeof cancelAnimationFrame<"u"&&(cancelAnimationFrame(this._animFrameId),this._animFrameId=null)}},Sh=Symbol.for("preact-signals");function Ns(){if(Ut>1)Ut--;else{for(var e,t=!1;dr!==void 0;){var n=dr;for(dr=void 0,Ta++;n!==void 0;){var r=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&bc(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Ta=0,Ut--,t)throw e}}function Xt(e){if(Ut>0)return e();Ut++;try{return e()}finally{Ns()}}var ye=void 0;function _e(e){var t=ye;ye=void 0;try{return e()}finally{ye=t}}var dr=void 0,Ut=0,Ta=0,ws=0;function yc(e){if(ye!==void 0){var t=e.n;if(t===void 0||t.t!==ye)return t={i:0,S:e,p:ye.s,n:void 0,t:ye,e:void 0,x:void 0,r:t},ye.s!==void 0&&(ye.s.n=t),ye.s=t,e.n=t,32&ye.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=ye.s,t.n=void 0,ye.s.n=t,ye.s=t),t}}function at(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}at.prototype.brand=Sh;at.prototype.h=function(){return!0};at.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:_e(function(){var r;(r=t.W)==null||r.call(t)}))};at.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&_e(function(){var s;(s=t.Z)==null||s.call(t)}))}};at.prototype.subscribe=function(e){var t=this;return Ct(function(){var n=t.value,r=ye;ye=void 0;try{e(n)}finally{ye=r}},{name:"sub"})};at.prototype.valueOf=function(){return this.value};at.prototype.toString=function(){return this.value+""};at.prototype.toJSON=function(){return this.value};at.prototype.peek=function(){var e=ye;ye=void 0;try{return this.value}finally{ye=e}};Object.defineProperty(at.prototype,"value",{get:function(){var e=yc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ta>100)throw new Error("Cycle detected");this.v=e,this.i++,ws++,Ut++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Ns()}}}});function Mr(e,t){return new at(e,t)}function bc(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function wc(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function _c(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function pn(e,t){at.call(this,void 0),this.x=e,this.s=void 0,this.g=ws-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}pn.prototype=new at;pn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ws))return!0;if(this.g=ws,this.f|=1,this.i>0&&!bc(this))return this.f&=-2,!0;var e=ye;try{wc(this),ye=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return ye=e,_c(this),this.f&=-2,!0};pn.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}at.prototype.S.call(this,e)};pn.prototype.U=function(e){if(this.t!==void 0&&(at.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};pn.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(pn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=yc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function vl(e,t){return new pn(e,t)}function xc(e){var t=e.u;if(e.u=void 0,typeof t=="function"){Ut++;var n=ye;ye=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,yo(e),r}finally{ye=n,Ns()}}}function yo(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,xc(e)}function kh(e){if(ye!==this)throw new Error("Out-of-order effect");_c(this),ye=e,this.f&=-2,8&this.f&&yo(this),Ns()}function zn(e,t){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}zn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{e()}};zn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,xc(this),wc(this),Ut++;var e=ye;return ye=this,kh.bind(this,e)};zn.prototype.N=function(){2&this.f||(this.f|=2,this.o=dr,dr=this)};zn.prototype.d=function(){this.f|=8,1&this.f||yo(this)};zn.prototype.dispose=function(){this.d()};function Ct(e,t){var n=new zn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Eh=Object.create,bo=Object.defineProperty,Ih=Object.defineProperties,Mh=Object.getOwnPropertyDescriptor,Ah=Object.getOwnPropertyDescriptors,yl=Object.getOwnPropertySymbols,Th=Object.prototype.hasOwnProperty,$h=Object.prototype.propertyIsEnumerable,Rh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),jn=e=>{throw TypeError(e)},$a=(e,t,n)=>t in e?bo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dh=(e,t)=>{for(var n in t||(t={}))Th.call(t,n)&&$a(e,n,t[n]);if(yl)for(var n of yl(t))$h.call(t,n)&&$a(e,n,t[n]);return e},Ph=(e,t)=>Ih(e,Ah(t)),bl=(e,t)=>bo(e,"name",{value:t,configurable:!0}),Fh=e=>{var t;return[,,,Eh((t=void 0)!=null?t:null)]},Cc=["class","method","getter","setter","accessor","field","value","get","set"],er=e=>e!==void 0&&typeof e!="function"?jn("Function expected"):e,Oh=(e,t,n,r,s)=>({kind:Cc[e],name:t,metadata:r,addInitializer:a=>n._?jn("Already initialized"):s.push(er(a||null))}),Sc=(e,t)=>$a(t,Rh("metadata"),e[3]),nn=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},Zn=(e,t,n,r,s,a)=>{var o,i,l,c,u,f=t&7,m=!!(t&8),d=!!(t&16),h=f>3?e.length+1:f?m?1:2:0,g=Cc[f+5],v=f>3&&(e[h-1]=[]),y=e[h]||(e[h]=[]),b=f&&(!d&&!m&&(s=s.prototype),f<5&&(f>3||!d)&&Mh(f<4?s:{get[n](){return un(this,a)},set[n](_){return Zt(this,a,_)}},n));f?d&&f<4&&bl(a,(f>2?"set ":f>1?"get ":"")+n):bl(s,n);for(var w=r.length-1;w>=0;w--)c=Oh(f,n,l={},e[3],y),f&&(c.static=m,c.private=d,u=c.access={has:d?_=>Lh(s,_):_=>n in _},f^3&&(u.get=d?_=>(f^1?un:Bh)(_,s,f^4?a:b.get):_=>_[n]),f>2&&(u.set=d?(_,x)=>Zt(_,s,x,f^4?a:b.set):(_,x)=>_[n]=x)),i=(0,r[w])(f?f<4?d?a:b[g]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?er(i)&&(f>4?v.unshift(i):f?d?a=i:b[g]=i:s=i):typeof i!="object"||i===null?jn("Object expected"):(er(o=i.get)&&(b.get=o),er(o=i.set)&&(b.set=o),er(o=i.init)&&v.unshift(o));return f||Sc(e,s),b&&bo(s,n,b),d?f^4?a:b:s},wo=(e,t,n)=>t.has(e)||jn("Cannot "+n),Lh=(e,t)=>Object(t)!==t?jn('Cannot use the "in" operator on this value'):e.has(t),un=(e,t,n)=>(wo(e,t,"read from private field"),n?n.call(e):t.get(e)),Qr=(e,t,n)=>t.has(e)?jn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Zt=(e,t,n,r)=>(wo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Bh=(e,t,n)=>(wo(e,t,"access private method"),n);function _s(e,t){if(t){let n;return vl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return vl(e)}function yr(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,s)=>!yr(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(a=>!yr(e[a],t[a]))}return!1}function ge({get:e},t){return{init(n){return Mr(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function $e(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=_s(e.bind(this)),n.set(this,r)),r.value}}function da(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Ph(Dh({},s),{enumerable:e}))})}}function Ar(...e){const t=e.map(n=>Ct(n));return()=>t.forEach(n=>n())}var kc,Ec,Ic,Mc,Ac,Tc,nt,_o,fa,Ra,Da,Ke,xo,ha,$c,Pa,Co,pa,Fa,Oa;Tc=[ge],Ac=[ge],Mc=[ge],Ic=[da()],Ec=[da()],kc=[da()];var Kt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,nn(nt,5,this),Qr(this,Ke),Qr(this,_o,nn(nt,8,this)),nn(nt,11,this),Qr(this,xo,nn(nt,12,this)),nn(nt,15,this),Qr(this,Co,nn(nt,16,this)),nn(nt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return un(this,Ke,Fa)}get initial(){return un(this,Ke,Ra)}get previous(){return un(this,Ke,$c)}set current(e){const t=_e(()=>un(this,Ke,Fa));e&&t&&this.equals(t,e)||Xt(()=>{un(this,Ke,Ra)||Zt(this,Ke,e,Da),Zt(this,Ke,t,Pa),Zt(this,Ke,e,Oa)})}reset(e=this.defaultValue){Xt(()=>{Zt(this,Ke,void 0,Pa),Zt(this,Ke,e,Da),Zt(this,Ke,e,Oa)})}};nt=Fh();_o=new WeakMap;Ke=new WeakSet;xo=new WeakMap;Co=new WeakMap;fa=Zn(nt,20,"#initial",Tc,Ke,_o),Ra=fa.get,Da=fa.set;ha=Zn(nt,20,"#previous",Ac,Ke,xo),$c=ha.get,Pa=ha.set;pa=Zn(nt,20,"#current",Mc,Ke,Co),Fa=pa.get,Oa=pa.set;Zn(nt,2,"current",Ic,Kt);Zn(nt,2,"initial",Ec,Kt);Zn(nt,2,"previous",kc,Kt);Sc(nt,Kt);function ma(e){return _e(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Wh=Object.create,Rc=Object.defineProperty,Vh=Object.getOwnPropertyDescriptor,wl=Object.getOwnPropertySymbols,Nh=Object.prototype.hasOwnProperty,zh=Object.prototype.propertyIsEnumerable,Dc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),zs=e=>{throw TypeError(e)},_l=Math.pow,La=(e,t,n)=>t in e?Rc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jh=(e,t)=>{for(var n in t||(t={}))Nh.call(t,n)&&La(e,n,t[n]);if(wl)for(var n of wl(t))zh.call(t,n)&&La(e,n,t[n]);return e},Zh=e=>{var t;return[,,,Wh((t=e?.[Dc("metadata")])!=null?t:null)]},Pc=["class","method","getter","setter","accessor","field","value","get","set"],Fc=e=>e!==void 0&&typeof e!="function"?zs("Function expected"):e,Hh=(e,t,n,r,s)=>({kind:Pc[e],name:t,metadata:r,addInitializer:a=>n._?zs("Already initialized"):s.push(Fc(a||null))}),Gh=(e,t)=>La(t,Dc("metadata"),e[3]),Uh=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)a[s].call(n);return r},Oc=(e,t,n,r,s,a)=>{for(var o,i,l,c,u=t&7,f=!1,m=!1,d=2,h=Pc[u+5],g=e[d]||(e[d]=[]),v=(s=s.prototype,Vh(s,n)),y=r.length-1;y>=0;y--)l=Hh(u,n,i={},e[3],g),l.static=f,l.private=m,c=l.access={has:b=>n in b},c.get=b=>b[n],o=(0,r[y])(v[h],l),i._=1,Fc(o)&&(v[h]=o);return v&&Rc(s,n,v),s},Lc=(e,t,n)=>t.has(e)||zs("Cannot "+n),Xh=(e,t,n)=>(Lc(e,t,"read from private field"),t.get(e)),Yh=(e,t,n)=>t.has(e)?zs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Kh=(e,t,n,r)=>(Lc(e,t,"write to private field"),t.set(e,n),n),Tt=class Ba{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ba(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Ba(t,n)}},Tr=class sn{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:a,height:o,scale:i}=this,l=new sn(s+t,r+n,a,o);return l.scale=jh({},i),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:a,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:a,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Tt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof sn))return!1;const{left:n,top:r,width:s,height:a}=this;return n===t.left&&r===t.top&&s===t.width&&a===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:a}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=a}intersectionArea(t){return t instanceof sn?qh(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:s}){return new sn(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(a,o)=>{const i=r[o],l=o==="x"?a.left:a.top,c=o==="x"?a.width:a.height;return i=="start"?l:i=="end"?l+c:l+c/2};return Tt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return sn.from(t).intersectionRatio(sn.from(n))}};function qh(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=s-r,i=a-n;return r<s&&n<a?o*i:0}var Bc,Wc,Wa,is,$r,js=class extends(Wa=Kt,Wc=[$e],Bc=[$e],Wa){constructor(t){const n=Tt.from(t);super(n,(r,s)=>Tt.equals(r,s)),Uh($r,5,this),Yh(this,is,0),this.velocity={x:0,y:0}}get delta(){return Tt.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Tt.from(t),s={x:r.x-n.x,y:r.y-n.y},a=Date.now(),o=a-Xh(this,is),i=l=>Math.round(l/o*100);Xt(()=>{Kh(this,is,a),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Tt.from(t)),this.velocity={x:0,y:0}}};$r=Zh(Wa);is=new WeakMap;Oc($r,2,"delta",Wc,js);Oc($r,2,"direction",Bc,js);Gh($r,js);function Va({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(_l(r,2)+_l(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var Vc=(e=>(e.Horizontal="x",e.Vertical="y",e))(Vc||{}),Nc=Object.values(Vc),Jh=Object.create,So=Object.defineProperty,Qh=Object.defineProperties,ep=Object.getOwnPropertyDescriptor,tp=Object.getOwnPropertyDescriptors,xs=Object.getOwnPropertySymbols,zc=Object.prototype.hasOwnProperty,jc=Object.prototype.propertyIsEnumerable,Zc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Hn=e=>{throw TypeError(e)},Na=(e,t,n)=>t in e?So(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hc=(e,t)=>{for(var n in t||(t={}))zc.call(t,n)&&Na(e,n,t[n]);if(xs)for(var n of xs(t))jc.call(t,n)&&Na(e,n,t[n]);return e},Gc=(e,t)=>Qh(e,tp(t)),xl=(e,t)=>So(e,"name",{value:t,configurable:!0}),Uc=(e,t)=>{var n={};for(var r in e)zc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&xs)for(var r of xs(e))t.indexOf(r)<0&&jc.call(e,r)&&(n[r]=e[r]);return n},Gn=e=>{var t;return[,,,Jh((t=e?.[Zc("metadata")])!=null?t:null)]},Xc=["class","method","getter","setter","accessor","field","value","get","set"],tr=e=>e!==void 0&&typeof e!="function"?Hn("Function expected"):e,np=(e,t,n,r,s)=>({kind:Xc[e],name:t,metadata:r,addInitializer:a=>n._?Hn("Already initialized"):s.push(tr(a||null))}),mn=(e,t)=>Na(t,Zc("metadata"),e[3]),se=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},he=(e,t,n,r,s,a)=>{var o,i,l,c,u,f=t&7,m=!!(t&8),d=!!(t&16),h=f>3?e.length+1:f?m?1:2:0,g=Xc[f+5],v=f>3&&(e[h-1]=[]),y=e[h]||(e[h]=[]),b=f&&(!d&&!m&&(s=s.prototype),f<5&&(f>3||!d)&&ep(f<4?s:{get[n](){return Ze(this,a)},set[n](_){return wt(this,a,_)}},n));f?d&&f<4&&xl(a,(f>2?"set ":f>1?"get ":"")+n):xl(s,n);for(var w=r.length-1;w>=0;w--)c=np(f,n,l={},e[3],y),f&&(c.static=m,c.private=d,u=c.access={has:d?_=>rp(s,_):_=>n in _},f^3&&(u.get=d?_=>(f^1?Ze:sp)(_,s,f^4?a:b.get):_=>_[n]),f>2&&(u.set=d?(_,x)=>wt(_,s,x,f^4?a:b.set):(_,x)=>_[n]=x)),i=(0,r[w])(f?f<4?d?a:b[g]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?tr(i)&&(f>4?v.unshift(i):f?d?a=i:b[g]=i:s=i):typeof i!="object"||i===null?Hn("Object expected"):(tr(o=i.get)&&(b.get=o),tr(o=i.set)&&(b.set=o),tr(o=i.init)&&v.unshift(o));return f||mn(e,s),b&&So(s,n,b),d?f^4?a:b:s},ko=(e,t,n)=>t.has(e)||Hn("Cannot "+n),rp=(e,t)=>Object(t)!==t?Hn('Cannot use the "in" operator on this value'):e.has(t),Ze=(e,t,n)=>(ko(e,t,"read from private field"),n?n.call(e):t.get(e)),we=(e,t,n)=>t.has(e)?Hn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),wt=(e,t,n,r)=>(ko(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),sp=(e,t,n)=>(ko(e,t,"access private method"),n);function Yc(e,t){return{plugin:e,options:t}}function gn(e){return t=>Yc(e,t)}function Eo(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Kc,br,Io,ls;Kc=[ge];var dt=class{constructor(e,t){this.manager=e,this.options=t,we(this,Io,se(br,8,this,!1)),se(br,11,this),we(this,ls,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return _e(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=Ct(e.bind(this));return Ze(this,ls).add(t),t}destroy(){Ze(this,ls).forEach(e=>e())}static configure(e){return Yc(this,e)}};br=Gn(null);Io=new WeakMap;ls=new WeakMap;he(br,4,"disabled",Kc,dt,Io);mn(br,dt);var Rr=class extends dt{},cs,ga=class{constructor(e){this.manager=e,this.instances=new Map,we(this,cs,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Eo).reduceRight((r,s)=>r.some(({plugin:a})=>a===s.plugin)?r:[s,...r],[]),n=t.map(({plugin:r})=>r);for(const r of Ze(this,cs))if(!n.includes(r)){if(r.prototype instanceof Rr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);wt(this,cs,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};cs=new WeakMap;function ap(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var es=[],En,In,op=class extends dt{constructor(e){super(e),we(this,En),we(this,In),this.computeCollisions=this.computeCollisions.bind(this),wt(this,In,Mr(es)),this.destroy=Ar(()=>{const t=this.computeCollisions(),n=_e(()=>this.manager.dragOperation.position.current);if(t!==es){const r=Ze(this,En);if(wt(this,En,n),r&&n.x==r.x&&n.y==r.y)return}else wt(this,En,void 0);Ze(this,In).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){_e(()=>{e?Ze(this,In).value=this.computeCollisions():wt(this,En,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:a,status:o}=r;if(!o.initialized||!a)return es;const i=[],l=[];for(const c of e??n.droppables){if(c.disabled||s&&!c.accepts(s))continue;const u=t??c.collisionDetector;if(!u)continue;l.push(c),c.shape;const f=_e(()=>u({droppable:c,dragOperation:r}));f&&(c.collisionPriority!=null&&(f.priority=c.collisionPriority),i.push(f))}return l.length===0?es:(i.sort(ap),i)}get collisions(){return Ze(this,In).value}};En=new WeakMap;In=new WeakMap;var ip=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const s of r)s(...t)}},lp=class extends ip{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function us(e,t=!0){let n=!1;return Gc(Hc({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var cp=class extends Rr{constructor(e){super(e);const t=(r,s)=>r.map(({id:a})=>a).join("")===s.map(({id:a})=>a).join("");let n=[];this.destroy=Ar(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:a}=r;if(r.isDisabled())return;const o=us({collisions:a});if(s.dispatch("collision",o),o.defaultPrevented||t(a,n))return;n=a;const[i]=a;_e(()=>{var l;i?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(i?.id).then(()=>{r.enable()}))})})}},Mo=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Mo||{}),Ao=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Ao||{}),qc,Jc,Qc,eu,tu,nu,ru,xt,To;ru=[ge],nu=[$e],tu=[$e],eu=[$e],Qc=[$e],Jc=[$e],qc=[$e];var Wt=class{constructor(){se(xt,5,this),we(this,To,se(xt,8,this,"idle")),se(xt,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};xt=Gn(null);To=new WeakMap;he(xt,4,"value",ru,Wt,To);he(xt,2,"current",nu,Wt);he(xt,2,"idle",tu,Wt);he(xt,2,"initializing",eu,Wt);he(xt,2,"initialized",Qc,Wt);he(xt,2,"dragging",Jc,Wt);he(xt,2,"dropped",qc,Wt);mn(xt,Wt);var up=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return _e(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=us({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return _e(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:a}=e;Xt(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(a)});const o=us({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:i}=t;i.current==="initializing"&&(t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1}))}),r)})}move(e){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:a}=r;if(!s.dragging||!a||a.signal.aborted)return;const o=us({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var i,l,c,u,f;if(o.defaultPrevented)return;const m=(f=e.to)!=null?f:{x:r.position.current.x+((l=(i=e.by)==null?void 0:i.x)!=null?l:0),y:r.position.current.y+((u=(c=e.by)==null?void 0:c.y)!=null?u:0)};r.position.current=m})})}stop(e={}){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let a;const o=()=>{const l={resume:()=>{},abort:()=>{}};return a=new Promise((c,u)=>{l.resume=c,l.abort=u}),l};s.abort();const i=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=_e(()=>{var u;return((u=r.source)==null?void 0:u.status)==="dropping"}),c=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:u}=r,f=Ct(()=>{u?.status==="idle"&&(f(),c())})}else this.manager.renderer.rendering.then(c)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),a?a.then(i).catch(()=>r.reset()):i()})}},su,au,ou,iu,ut,$o,Ro,Do,Po;iu=[ge],ou=[ge],au=[ge],su=[ge];var qt=class{constructor(e,t){we(this,$o,se(ut,8,this)),se(ut,11,this),we(this,Ro,se(ut,12,this)),se(ut,15,this),we(this,Do,se(ut,16,this)),se(ut,19,this),we(this,Po,se(ut,20,this)),se(ut,23,this);const{effects:n,id:r,data:s={},disabled:a=!1,register:o=!0}=e;let i=r;this.manager=t,this.id=r,this.data=s,this.disabled=a,this.effects=()=>{var l;return[()=>{const{id:c,manager:u}=this;if(c!==i)return u?.registry.register(this),()=>u?.registry.unregister(this)},...(l=n?.())!=null?l:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),t&&o&&queueMicrotask(this.register)}register(){var e;return(e=this.manager)==null?void 0:e.registry.register(this)}unregister(){var e;(e=this.manager)==null||e.registry.unregister(this)}destroy(){var e;(e=this.manager)==null||e.registry.unregister(this)}};ut=Gn(null);$o=new WeakMap;Ro=new WeakMap;Do=new WeakMap;Po=new WeakMap;he(ut,4,"manager",iu,qt,$o);he(ut,4,"id",ou,qt,Ro);he(ut,4,"data",au,qt,Do);he(ut,4,"disabled",su,qt,Po);mn(ut,qt);var Cl=class{constructor(){this.map=Mr(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r){const i=this.cleanupFunctions.get(r);i?.(),this.cleanupFunctions.delete(r)}const a=new Map(n);a.set(e,t),this.map.value=a;const o=Ar(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},lu,cu,uu,du,fu,hu,za,rt,Fo,Oo,Lo,$t=class extends(za=qt,hu=[ge],fu=[ge],du=[ge],uu=[$e],cu=[$e],lu=[$e],za){constructor(t,n){var r=t,{modifiers:s,type:a,sensors:o}=r,i=Uc(r,["modifiers","type","sensors"]);super(i,n),se(rt,5,this),we(this,Fo,se(rt,8,this)),se(rt,11,this),we(this,Oo,se(rt,12,this)),se(rt,15,this),we(this,Lo,se(rt,16,this,this.isDragSource?"dragging":"idle")),se(rt,19,this),this.type=a,this.sensors=o,this.modifiers=s,this.alignment=i.alignment}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};rt=Gn(za);Fo=new WeakMap;Oo=new WeakMap;Lo=new WeakMap;he(rt,4,"type",hu,$t,Fo);he(rt,4,"modifiers",fu,$t,Oo);he(rt,4,"status",du,$t,Lo);he(rt,2,"isDropping",uu,$t);he(rt,2,"isDragging",cu,$t);he(rt,2,"isDragSource",lu,$t);mn(rt,$t);var pu,mu,gu,vu,yu,bu,ja,Ve,Bo,Wo,Vo,No,zo,Rt=class extends(ja=qt,bu=[ge],yu=[ge],vu=[ge],gu=[ge],mu=[ge],pu=[$e],ja){constructor(t,n){var r=t,{accept:s,collisionDetector:a,collisionPriority:o,type:i}=r,l=Uc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),se(Ve,5,this),we(this,Bo,se(Ve,8,this)),se(Ve,11,this),we(this,Wo,se(Ve,12,this)),se(Ve,15,this),we(this,Vo,se(Ve,16,this)),se(Ve,19,this),we(this,No,se(Ve,20,this)),se(Ve,23,this),we(this,zo,se(Ve,24,this)),se(Ve,27,this),this.accept=s,this.collisionDetector=a,this.collisionPriority=o,this.type=i}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Ve=Gn(ja);Bo=new WeakMap;Wo=new WeakMap;Vo=new WeakMap;No=new WeakMap;zo=new WeakMap;he(Ve,4,"accept",bu,Rt,Bo);he(Ve,4,"type",yu,Rt,Wo);he(Ve,4,"collisionDetector",vu,Rt,Vo);he(Ve,4,"collisionPriority",gu,Rt,No);he(Ve,4,"shape",mu,Rt,zo);he(Ve,2,"isDropTarget",pu,Rt);mn(Ve,Rt);var Fn=class extends dt{constructor(e,t){super(e,t),this.manager=e,this.options=t}},dp=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},ds,wu=class{constructor(e){this.options=e,we(this,ds)}set controller(e){wt(this,ds,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ze(this,ds))==null||t.activate(e)}};ds=new WeakMap;var On=class extends dt{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},fp=class{constructor(e){this.draggables=new Cl,this.droppables=new Cl,this.plugins=new ga(e),this.sensors=new ga(e),this.modifiers=new ga(e)}register(e,t){if(e instanceof $t)return this.draggables.register(e.id,e);if(e instanceof Rt)return this.droppables.register(e.id,e);if(e.prototype instanceof On)return this.modifiers.register(e,t);if(e.prototype instanceof Fn)return this.sensors.register(e,t);if(e.prototype instanceof dt)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof qt)return e instanceof $t?this.draggables.unregister(e.id,e):e instanceof Rt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof On)return this.modifiers.unregister(e);if(e.prototype instanceof Fn)return this.sensors.unregister(e);if(e.prototype instanceof dt)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},_u,xu,Cu,Su,ku,Eu,Iu,Mu,Au,nr,fs,Mn,Re,jo,Zo,Ho,Go,Uo,rr;Au=[$e],Mu=[ge],Iu=[ge],Eu=[ge],ku=[ge],Su=[ge],Cu=[$e],xu=[$e],_u=[$e];var It=class{constructor(e){se(Re,5,this),we(this,nr),we(this,fs),we(this,Mn,new Kt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Wt,we(this,jo,se(Re,8,this,!1)),se(Re,11,this),we(this,Zo,se(Re,12,this,null)),se(Re,15,this),we(this,Ho,se(Re,16,this,null)),se(Re,19,this),we(this,Go,se(Re,20,this,null)),se(Re,23,this),we(this,Uo,se(Re,24,this,[])),se(Re,27,this),this.position=new js({x:0,y:0}),we(this,rr,{x:0,y:0}),wt(this,nr,e)}get shape(){const{current:e,initial:t,previous:n}=Ze(this,Mn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ze(this,Mn).current=e:Ze(this,Mn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ze(this,nr).registry.draggables.get(t);return n&&wt(this,fs,n),(e=n??Ze(this,fs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ze(this,nr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Gc(Hc({},this.snapshot()),{transform:n}));return wt(this,rr,n),n}snapshot(){return _e(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ze(this,rr),shape:this.shape?ma(this.shape):null,position:ma(this.position),status:ma(this.status),canceled:this.canceled}))}reset(){Xt(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Ze(this,Mn).reset(),this.position.reset({x:0,y:0}),wt(this,rr,{x:0,y:0}),this.modifiers=[]})}};Re=Gn(null);nr=new WeakMap;fs=new WeakMap;Mn=new WeakMap;jo=new WeakMap;Zo=new WeakMap;Ho=new WeakMap;Go=new WeakMap;Uo=new WeakMap;rr=new WeakMap;he(Re,2,"shape",Au,It);he(Re,4,"canceled",Mu,It,jo);he(Re,4,"activatorEvent",Iu,It,Zo);he(Re,4,"sourceIdentifier",Eu,It,Ho);he(Re,4,"targetIdentifier",ku,It,Go);he(Re,4,"modifiers",Su,It,Uo);he(Re,2,"source",Cu,It);he(Re,2,"target",xu,It);he(Re,2,"transform",_u,It);mn(Re,It);var hp={get rendering(){return Promise.resolve()}};function Ot(e,t){return typeof e=="function"?e(t):e??t}var pp=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(m=>m.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=Ot(r.plugins,[]),a=Ot(r.sensors,[]),o=Ot(r.modifiers,[]),i=(n=r.renderer)!=null?n:hp,l=new lp(this),c=new fp(this);this.registry=c,this.monitor=l,this.renderer=i,this.actions=new up(this),this.dragOperation=new It(this),this.collisionObserver=new op(this),this.plugins=[cp,...s],this.modifiers=o,this.sensors=a;const{destroy:u}=this,f=Ar(()=>{var m,d,h;const g=_e(()=>this.dragOperation.modifiers),v=this.modifiers;for(const y of g)v.includes(y)||y.destroy();this.dragOperation.modifiers=(h=(d=(m=this.dragOperation.source)==null?void 0:m.modifiers)==null?void 0:d.map(y=>{const{plugin:b,options:w}=Eo(y);return new b(this,w)}))!=null?h:v});this.destroy=()=>{f(),u()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},Tu=e=>{throw TypeError(e)},Xo=(e,t,n)=>t.has(e)||Tu("Cannot "+n),ie=(e,t,n)=>(Xo(e,t,"read from private field"),t.get(e)),ct=(e,t,n)=>t.has(e)?Tu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),mt=(e,t,n,r)=>(Xo(e,t,"write to private field"),t.set(e,n),n),$u=(e,t,n)=>(Xo(e,t,"access private method"),n);function Zs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function mp(e,t){const n=e.getAnimations();if(n.length>0)for(const r of n){if(r.playState!=="running")continue;const{effect:s}=r,o=(Zs(s)?s.getKeyframes():[]).filter(t);if(o.length>0)return[o[o.length-1],r]}return null}function Hs(e){const{width:t,height:n,top:r,left:s,bottom:a,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:a,right:o}}function Yo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Dr(e){return"nodeType"in e}function St(e){var t,n,r;return e?Yo(e)?e:Dr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function Ko(e){const{Document:t}=St(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function dn(e){return!e||Yo(e)?!1:e instanceof St(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Ru(e){return e instanceof St(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function vn(e){return e?Yo(e)?e.document:Dr(e)?Ko(e)?e:dn(e)||Ru(e)?e.ownerDocument:document:document:document}function gp(e){var t,n,r,s;const{documentElement:a}=vn(e),o=St(e).visualViewport,i=(t=o?.width)!=null?t:a.clientWidth,l=(n=o?.height)!=null?n:a.clientHeight,c=(r=o?.offsetTop)!=null?r:0,u=(s=o?.offsetLeft)!=null?s:0;return{top:c,left:u,right:u+i,bottom:c+l,width:i,height:l}}function vp(e,t){if(yp(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function yp(e){return e.tagName==="DETAILS"}function Cs(e,t=e.getBoundingClientRect(),n=0){var r,s,a,o,i;let l=t;const{ownerDocument:c}=e,u=(r=c.defaultView)!=null?r:window;let f=e.parentElement;for(;f&&f!==c.documentElement;){if(!vp(f)){const w=f.getBoundingClientRect(),_=n*(w.bottom-w.top),x=n*(w.right-w.left),S=n*(w.bottom-w.top),k=n*(w.right-w.left);l={top:Math.max(l.top,w.top-_),right:Math.min(l.right,w.right+x),bottom:Math.min(l.bottom,w.bottom+S),left:Math.max(l.left,w.left-k),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}f=f.parentElement}const m=u.visualViewport,d=(s=m?.offsetTop)!=null?s:0,h=(a=m?.offsetLeft)!=null?a:0,g=(o=m?.width)!=null?o:u.innerWidth,v=(i=m?.height)!=null?i:u.innerHeight,y=n*v,b=n*g;return l={top:Math.max(l.top,d-y),right:Math.min(l.right,h+g+b),bottom:Math.min(l.bottom,d+v+y),left:Math.max(l.left,h-b),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function Ln(e){return{x:e.clientX,y:e.clientY}}var Du=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Za(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...Za(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...Za(s.document,t))}}catch{}return n}function qo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Pu(){var e,t;const n=qo()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Jo(e){return!e||!Dr(e)?!1:e instanceof St(e).ShadowRoot}function Ss(e){if(e&&Dr(e)){let t=e.getRootNode();if(Jo(t))return t;if(t instanceof Document)return t}return vn(e)}function Fu(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function bp(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((a,o)=>{const i=r[o];if(Sl(a)&&Sl(i)&&(a.type!=="file"&&(a.value=i.value),a.type==="radio"&&a.name&&(a.name=`Cloned__${a.name}`)),kl(a)&&kl(i)&&i.width>0&&i.height>0){const l=a.getContext("2d");l?.drawImage(i,0,0)}}),n}function Sl(e){return"value"in e}function kl(e){return e.tagName==="CANVAS"}function Ou(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(wp(r)){const{contentDocument:s}=r;if(s){const{left:a,top:o}=r.getBoundingClientRect();return Ou(s,{x:t-a,y:n-o})}}return r}function wp(e){return e?.tagName==="IFRAME"}var El=new WeakMap;function _p(e){return!!e.closest(`
1
+ "use strict";var Yf=Object.create;var al=Object.defineProperty;var Kf=Object.getOwnPropertyDescriptor;var qf=Object.getOwnPropertyNames;var Jf=Object.getPrototypeOf,Qf=Object.prototype.hasOwnProperty;var eh=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of qf(t))!Qf.call(e,s)&&s!==n&&al(e,s,{get:()=>t[s],enumerable:!(r=Kf(t,s))||r.enumerable});return e};var th=(e,t,n)=>(n=e!=null?Yf(Jf(e)):{},eh(t||!e||!e.__esModule?al(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("tone"),C=require("react/jsx-runtime"),p=require("react"),F=require("styled-components"),go=require("react-dom");function ic(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const lc=ic(L),D=ic(p);var ca={exports:{}},ol;function nh(){return ol||(ol=1,(function(e,t){(function(n,r){e.exports=r()})(window,(function(){return(function(n){var r={};function s(a){if(r[a])return r[a].exports;var o=r[a]={i:a,l:!1,exports:{}};return n[a].call(o.exports,o,o.exports,s),o.l=!0,o.exports}return s.m=n,s.c=r,s.d=function(a,o,i){s.o(a,o)||Object.defineProperty(a,o,{enumerable:!0,get:i})},s.r=function(a){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(a,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(a,"__esModule",{value:!0})},s.t=function(a,o){if(1&o&&(a=s(a)),8&o||4&o&&typeof a=="object"&&a&&a.__esModule)return a;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:a}),2&o&&typeof a!="string")for(var l in a)s.d(i,l,(function(c){return a[c]}).bind(null,l));return i},s.n=function(a){var o=a&&a.__esModule?function(){return a.default}:function(){return a};return s.d(o,"a",o),o},s.o=function(a,o){return Object.prototype.hasOwnProperty.call(a,o)},s.p="",s(s.s="./src/index.ts")})({"./src/chunk.ts":function(n,r,s){s.r(r),s.d(r,"SF2Chunk",(function(){return d}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=s("./src/chunks/index.ts");function l(h){return(l=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(g){return typeof g}:function(g){return g&&typeof Symbol=="function"&&g.constructor===Symbol&&g!==Symbol.prototype?"symbol":typeof g})(h)}function c(h,g){for(var v=0;v<g.length;v++){var y=g[v];y.enumerable=y.enumerable||!1,y.configurable=!0,"value"in y&&(y.writable=!0),Object.defineProperty(h,y.key,y)}}function u(h){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(g){return g.__proto__||Object.getPrototypeOf(g)})(h)}function f(h,g){return(f=Object.setPrototypeOf||function(v,y){return v.__proto__=y,v})(h,g)}function m(h){if(h===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return h}var d=(function(h){function g(b){var w,_,x,S,k,E;return(function(I,T){if(!(I instanceof T))throw new TypeError("Cannot call a class as a function")})(this,g),_=this,w=!(x=u(g).call(this,b.id,b.length,b.buffer,b.subChunks))||l(x)!=="object"&&typeof x!="function"?m(_):x,S=m(m(w)),E=void 0,(k="subChunks")in S?Object.defineProperty(S,k,{value:E,enumerable:!0,configurable:!0,writable:!0}):S[k]=E,w.subChunks=b.subChunks.map((function(I){return new g(I)})),w}var v,y;return(function(b,w){if(typeof w!="function"&&w!==null)throw new TypeError("Super expression must either be null or a function");b.prototype=Object.create(w&&w.prototype,{constructor:{value:b,writable:!0,configurable:!0}}),w&&f(b,w)})(g,h),v=g,(y=[{key:"getMetaData",value:function(){if(this.id!=="LIST")throw new a.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks.reduce((function(w,_){if(_.id==="ifil"||_.id==="iver"){if(_.length!==o.SF_VERSION_LENGTH)throw new a.ParseError("Invalid size for the '".concat(_.id,"' sub-chunk"));w[_.id]="".concat(_.getInt16(),".").concat(_.getInt16(2))}else w[_.id]=_.getString();return w}),{});if(!b.ifil)throw new a.ParseError("Missing required 'ifil' sub-chunk");if(!b.INAM)throw new a.ParseError("Missing required 'INAM' sub-chunk");return{version:b.ifil,soundEngine:b.isng||"EMU8000",name:b.INAM,rom:b.irom,romVersion:b.iver,creationDate:b.ICRD,author:b.IENG,product:b.IPRD,copyright:b.ICOP,comments:b.ICMT,createdBy:b.ISFT}}},{key:"getSampleData",value:function(){if(this.id!=="LIST")throw new a.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks[0];if(b.id!=="smpl")throw new a.ParseError("Invalid chunk signature","'smpl'","'".concat(b.id,"'"));return b.buffer}},{key:"getPresetData",value:function(){if(this.id!=="LIST")throw new a.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));return{presetHeaders:Object(i.getPresetHeaders)(this.subChunks[0]),presetZones:Object(i.getZones)(this.subChunks[1],"pbag"),presetModulators:Object(i.getModulators)(this.subChunks[2],"pmod"),presetGenerators:Object(i.getGenerators)(this.subChunks[3],"pgen"),instrumentHeaders:Object(i.getInstrumentHeaders)(this.subChunks[4]),instrumentZones:Object(i.getZones)(this.subChunks[5],"ibag"),instrumentModulators:Object(i.getModulators)(this.subChunks[6],"imod"),instrumentGenerators:Object(i.getGenerators)(this.subChunks[7],"igen"),sampleHeaders:Object(i.getSampleHeaders)(this.subChunks[8])}}}])&&c(v.prototype,y),g})(a.RIFFChunk)},"./src/chunks/generators.ts":function(n,r,s){s.r(r),s.d(r,"getGenerators",(function(){return f}));var a=s("./src/riff/index.ts"),o=s("./src/types/index.ts"),i=s("./src/constants.ts"),l=[o.GeneratorType.StartAddrsOffset,o.GeneratorType.EndAddrsOffset,o.GeneratorType.StartLoopAddrsOffset,o.GeneratorType.EndLoopAddrsOffset,o.GeneratorType.StartAddrsCoarseOffset,o.GeneratorType.EndAddrsCoarseOffset,o.GeneratorType.StartLoopAddrsCoarseOffset,o.GeneratorType.KeyNum,o.GeneratorType.Velocity,o.GeneratorType.EndLoopAddrsCoarseOffset,o.GeneratorType.SampleModes,o.GeneratorType.ExclusiveClass,o.GeneratorType.OverridingRootKey],c=[o.GeneratorType.Unused1,o.GeneratorType.Unused2,o.GeneratorType.Unused3,o.GeneratorType.Unused4,o.GeneratorType.Reserved1,o.GeneratorType.Reserved2,o.GeneratorType.Reserved3],u=[o.GeneratorType.KeyRange,o.GeneratorType.VelRange],f=function(m,d){if(m.id!==d)throw new a.ParseError("Unexpected chunk ID","'".concat(d,"'"),"'".concat(m.id,"'"));if(m.length%i.SF_GENERATOR_SIZE)throw new a.ParseError("Invalid size for the '".concat(d,"' sub-chunk"));return m.iterate((function(h){var g=h.getInt16();return o.GeneratorType[g]?d==="pgen"&&l.includes(g)||d==="igen"&&c.includes(g)?null:u.includes(g)?{id:g,range:{lo:h.getByte(),hi:h.getByte()}}:{id:g,value:h.getInt16BE()}:null}))}},"./src/chunks/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/instruments/index.ts");s.d(r,"getInstrumentHeaders",(function(){return a.getInstrumentHeaders}));var o=s("./src/chunks/presets/index.ts");s.d(r,"getPresetHeaders",(function(){return o.getPresetHeaders}));var i=s("./src/chunks/samples/index.ts");s.d(r,"getSampleHeaders",(function(){return i.getSampleHeaders}));var l=s("./src/chunks/generators.ts");s.d(r,"getGenerators",(function(){return l.getGenerators}));var c=s("./src/chunks/modulators.ts");s.d(r,"getModulators",(function(){return c.getModulators}));var u=s("./src/chunks/zones.ts");s.d(r,"getZones",(function(){return u.getZones})),s.d(r,"getItemsInZone",(function(){return u.getItemsInZone}))},"./src/chunks/instruments/headers.ts":function(n,r,s){s.r(r),s.d(r,"getInstrumentHeaders",(function(){return i}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(l){if(l.id!=="inst")throw new a.ParseError("Unexpected chunk ID","'inst'","'".concat(l.id,"'"));if(l.length%o.SF_INSTRUMENT_HEADER_SIZE)throw new a.ParseError("Invalid size for the 'inst' sub-chunk");return l.iterate((function(c){return{name:c.getString(),bagIndex:c.getInt16()}}))}},"./src/chunks/instruments/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/instruments/headers.ts");s.d(r,"getInstrumentHeaders",(function(){return a.getInstrumentHeaders}))},"./src/chunks/modulators.ts":function(n,r,s){s.r(r),s.d(r,"getModulators",(function(){return l}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(c){return{type:c>>10&63,polarity:c>>9&1,direction:c>>8&1,palette:c>>7&1,index:127&c}},l=function(c,u){if(c.id!==u)throw new a.ParseError("Unexpected chunk ID","'".concat(u,"'"),"'".concat(c.id,"'"));if(c.length%o.SF_MODULATOR_SIZE)throw new a.ParseError("Invalid size for the '".concat(u,"' sub-chunk"));return c.iterate((function(f){return{source:i(f.getInt16BE()),id:f.getInt16BE(),value:f.getInt16BE(),valueSource:i(f.getInt16BE()),transform:f.getInt16BE()}}))}},"./src/chunks/presets/headers.ts":function(n,r,s){s.r(r),s.d(r,"getPresetHeaders",(function(){return i}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(l){if(l.id!=="phdr")throw new a.ParseError("Invalid chunk ID","'phdr'","'".concat(l.id,"'"));if(l.length%o.SF_PRESET_HEADER_SIZE)throw new a.ParseError("Invalid size for the 'phdr' sub-chunk");return l.iterate((function(c){return{name:c.getString(),preset:c.getInt16(),bank:c.getInt16(),bagIndex:c.getInt16(),library:c.getUInt32(),genre:c.getUInt32(),morphology:c.getUInt32()}}))}},"./src/chunks/presets/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/presets/headers.ts");s.d(r,"getPresetHeaders",(function(){return a.getPresetHeaders}))},"./src/chunks/samples/headers.ts":function(n,r,s){s.r(r),s.d(r,"getSampleHeaders",(function(){return i}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=function(l){if(l.id!=="shdr")throw new a.ParseError("Unexpected chunk ID","'shdr'","'".concat(l.id,"'"));if(l.length%o.SF_SAMPLE_HEADER_SIZE)throw new a.ParseError("Invalid size for the 'shdr' sub-chunk");return l.iterate((function(c){return{name:c.getString(),start:c.getUInt32(),end:c.getUInt32(),startLoop:c.getUInt32(),endLoop:c.getUInt32(),sampleRate:c.getUInt32(),originalPitch:c.getByte(),pitchCorrection:c.getChar(),link:c.getInt16(),type:c.getInt16()}}))}},"./src/chunks/samples/index.ts":function(n,r,s){s.r(r);var a=s("./src/chunks/samples/headers.ts");s.d(r,"getSampleHeaders",(function(){return a.getSampleHeaders}))},"./src/chunks/zones.ts":function(n,r,s){s.r(r),s.d(r,"getZones",(function(){return l})),s.d(r,"getItemsInZone",(function(){return c}));var a=s("./src/riff/index.ts"),o=s("./src/constants.ts"),i=s("./src/types/index.ts"),l=function(d,h){if(d.id!==h)throw new a.ParseError("Unexpected chunk ID","'".concat(h,"'"),"'".concat(d.id,"'"));if(d.length%o.SF_BAG_SIZE)throw new a.ParseError("Invalid size for the '".concat(h,"' sub-chunk"));return d.iterate((function(g){return{generatorIndex:g.getInt16(),modulatorIndex:g.getInt16()}}))},c=function(d,h,g,v,y,b){for(var w=[],_=0;_<d.length;_++){for(var x=d[_],S=d[_+1],k=x.bagIndex,E=S?S.bagIndex:h.length,I=[],T=void 0,R=k;R<E;R++){var A=u(R,h,g),M=f(R,h,v),$=M[i.GeneratorType.KeyRange]&&M[i.GeneratorType.KeyRange].range,P=M[b];if(P){var O=y[P.value];O&&I.push({keyRange:$,modulators:A,generators:M,reference:O})}else R-k==0&&(T={keyRange:$,modulators:A,generators:M})}w.push({header:x,globalZone:T,zones:I})}return w},u=function(d,h,g){var v=h[d],y=h[d+1],b=v.modulatorIndex,w=y?y.modulatorIndex:h.length;return m(b,w,g)},f=function(d,h,g){var v=h[d],y=h[d+1],b=v.generatorIndex,w=y?y.generatorIndex:h.length;return m(b,w,g)},m=function(d,h,g){for(var v={},y=d;y<h;y++){var b=g[y];b&&(v[b.id]=b)}return v}},"./src/constants.ts":function(n,r,s){s.r(r),s.d(r,"SF_VERSION_LENGTH",(function(){return a})),s.d(r,"SF_PRESET_HEADER_SIZE",(function(){return o})),s.d(r,"SF_BAG_SIZE",(function(){return i})),s.d(r,"SF_MODULATOR_SIZE",(function(){return l})),s.d(r,"SF_GENERATOR_SIZE",(function(){return c})),s.d(r,"SF_INSTRUMENT_HEADER_SIZE",(function(){return u})),s.d(r,"SF_SAMPLE_HEADER_SIZE",(function(){return f})),s.d(r,"DEFAULT_SAMPLE_RATE",(function(){return m}));var a=4,o=38,i=4,l=10,c=4,u=22,f=46,m=22050},"./src/index.ts":function(n,r,s){s.r(r);var a=s("./src/types/index.ts");for(var o in a)["default"].indexOf(o)<0&&(function(u){s.d(r,u,(function(){return a[u]}))})(o);var i=s("./src/chunk.ts");s.d(r,"SF2Chunk",(function(){return i.SF2Chunk}));var l=s("./src/constants.ts");s.d(r,"SF_VERSION_LENGTH",(function(){return l.SF_VERSION_LENGTH})),s.d(r,"SF_PRESET_HEADER_SIZE",(function(){return l.SF_PRESET_HEADER_SIZE})),s.d(r,"SF_BAG_SIZE",(function(){return l.SF_BAG_SIZE})),s.d(r,"SF_MODULATOR_SIZE",(function(){return l.SF_MODULATOR_SIZE})),s.d(r,"SF_GENERATOR_SIZE",(function(){return l.SF_GENERATOR_SIZE})),s.d(r,"SF_INSTRUMENT_HEADER_SIZE",(function(){return l.SF_INSTRUMENT_HEADER_SIZE})),s.d(r,"SF_SAMPLE_HEADER_SIZE",(function(){return l.SF_SAMPLE_HEADER_SIZE})),s.d(r,"DEFAULT_SAMPLE_RATE",(function(){return l.DEFAULT_SAMPLE_RATE}));var c=s("./src/soundFont2.ts");s.d(r,"SoundFont2",(function(){return c.SoundFont2}))},"./src/riff/chunkIterator.ts":function(n,r,s){s.r(r),s.d(r,"ChunkIterator",(function(){return c}));var a=s("./src/utils/index.ts");function o(u,f){if(!(u instanceof f))throw new TypeError("Cannot call a class as a function")}function i(u,f){for(var m=0;m<f.length;m++){var d=f[m];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,m){return f in u?Object.defineProperty(u,f,{value:m,enumerable:!0,configurable:!0,writable:!0}):u[f]=m,u}var c=(function(){function u(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;o(this,u),l(this,"target",[]),l(this,"chunk",void 0),l(this,"position",0),this.chunk=d,this.position=h}var f,m;return f=u,(m=[{key:"iterate",value:function(d){for(;this.position<this.chunk.length;){var h=d(this);h&&this.target.push(h)}}},{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:20,h=Object(a.getStringFromBuffer)(this.getBuffer(this.position,d));return this.position+=d,h}},{key:"getInt16",value:function(){return this.chunk.buffer[this.position++]|this.chunk.buffer[this.position++]<<8}},{key:"getInt16BE",value:function(){return this.getInt16()<<16>>16}},{key:"getUInt32",value:function(){return(this.chunk.buffer[this.position++]|this.chunk.buffer[this.position++]<<8|this.chunk.buffer[this.position++]<<16|this.chunk.buffer[this.position++]<<24)>>>0}},{key:"getByte",value:function(){return this.chunk.buffer[this.position++]}},{key:"getChar",value:function(){return this.chunk.buffer[this.position++]<<24>>24}},{key:"skip",value:function(d){this.position+=d}},{key:"getBuffer",value:function(d,h){return this.chunk.buffer.subarray(d,d+h)}},{key:"currentPosition",get:function(){return this.position}}])&&i(f.prototype,m),u})()},"./src/riff/index.ts":function(n,r,s){s.r(r);var a=s("./src/riff/chunkIterator.ts");s.d(r,"ChunkIterator",(function(){return a.ChunkIterator}));var o=s("./src/riff/parseError.ts");s.d(r,"ParseError",(function(){return o.ParseError}));var i=s("./src/riff/parser.ts");s.d(r,"parseBuffer",(function(){return i.parseBuffer})),s.d(r,"getChunk",(function(){return i.getChunk})),s.d(r,"getChunkLength",(function(){return i.getChunkLength})),s.d(r,"getSubChunks",(function(){return i.getSubChunks})),s.d(r,"getChunkId",(function(){return i.getChunkId}));var l=s("./src/riff/riffChunk.ts");s.d(r,"RIFFChunk",(function(){return l.RIFFChunk}))},"./src/riff/parseError.ts":function(n,r,s){function a(d){return(a=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(h){return typeof h}:function(h){return h&&typeof Symbol=="function"&&h.constructor===Symbol&&h!==Symbol.prototype?"symbol":typeof h})(d)}function o(d,h){return!h||a(h)!=="object"&&typeof h!="function"?(function(g){if(g===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return g})(d):h}function i(d){var h=typeof Map=="function"?new Map:void 0;return(i=function(g){if(g===null||(v=g,Function.toString.call(v).indexOf("[native code]")===-1))return g;var v;if(typeof g!="function")throw new TypeError("Super expression must either be null or a function");if(h!==void 0){if(h.has(g))return h.get(g);h.set(g,y)}function y(){return c(g,arguments,f(this).constructor)}return y.prototype=Object.create(g.prototype,{constructor:{value:y,enumerable:!1,writable:!0,configurable:!0}}),u(y,g)})(d)}function l(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch{return!1}}function c(d,h,g){return(c=l()?Reflect.construct:function(v,y,b){var w=[null];w.push.apply(w,y);var _=new(Function.bind.apply(v,w));return b&&u(_,b.prototype),_}).apply(null,arguments)}function u(d,h){return(u=Object.setPrototypeOf||function(g,v){return g.__proto__=v,g})(d,h)}function f(d){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(h){return h.__proto__||Object.getPrototypeOf(h)})(d)}s.r(r),s.d(r,"ParseError",(function(){return m}));var m=(function(d){function h(g,v,y){return(function(b,w){if(!(b instanceof w))throw new TypeError("Cannot call a class as a function")})(this,h),o(this,f(h).call(this,"".concat(g).concat(v&&y?", expected ".concat(v,", received ").concat(y):"")))}return(function(g,v){if(typeof v!="function"&&v!==null)throw new TypeError("Super expression must either be null or a function");g.prototype=Object.create(v&&v.prototype,{constructor:{value:g,writable:!0,configurable:!0}}),v&&u(g,v)})(h,d),h})(i(Error))},"./src/riff/parser.ts":function(n,r,s){s.r(r),s.d(r,"parseBuffer",(function(){return l})),s.d(r,"getChunk",(function(){return c})),s.d(r,"getChunkLength",(function(){return u})),s.d(r,"getSubChunks",(function(){return f})),s.d(r,"getChunkId",(function(){return m}));var a=s("./src/riff/parseError.ts"),o=s("./src/utils/buffer.ts"),i=s("./src/riff/riffChunk.ts"),l=function(d){var h=m(d);if(h!=="RIFF")throw new a.ParseError("Invalid file format","RIFF",h);var g=m(d,8);if(g!=="sfbk")throw new a.ParseError("Invalid signature","sfbk",g);var v=d.subarray(8),y=f(v.subarray(4));return new i.RIFFChunk(h,v.length,v,y)},c=function(d,h){var g=m(d,h),v=u(d,h+4),y=[];return g!=="RIFF"&&g!=="LIST"||(y=f(d.subarray(h+12))),new i.RIFFChunk(g,v,d.subarray(h+8),y)},u=function(d,h){return((d=d.subarray(h,h+4))[0]|d[1]<<8|d[2]<<16|d[3]<<24)>>>0},f=function(d){for(var h=[],g=0;g<=d.length-8;){var v=c(d,g);h.push(v),g=(g+=8+v.length)%2?g+1:g}return h},m=function(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;return Object(o.getStringFromBuffer)(d.subarray(h,h+4))}},"./src/riff/riffChunk.ts":function(n,r,s){s.r(r),s.d(r,"RIFFChunk",(function(){return c}));var a=s("./src/riff/chunkIterator.ts"),o=s("./src/utils/index.ts");function i(u,f){for(var m=0;m<f.length;m++){var d=f[m];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,m){return f in u?Object.defineProperty(u,f,{value:m,enumerable:!0,configurable:!0,writable:!0}):u[f]=m,u}var c=(function(){function u(d,h,g,v){(function(y,b){if(!(y instanceof b))throw new TypeError("Cannot call a class as a function")})(this,u),l(this,"id",void 0),l(this,"length",void 0),l(this,"buffer",void 0),l(this,"subChunks",void 0),this.id=d,this.length=h,this.buffer=g,this.subChunks=v}var f,m;return f=u,(m=[{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,h=arguments.length>1?arguments[1]:void 0;return Object(o.getStringFromBuffer)(this.getBuffer(d,h||this.length-d))}},{key:"getInt16",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return this.buffer[d++]|this.buffer[d]<<8}},{key:"getUInt32",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return(this.buffer[d++]|this.buffer[d++]<<8|this.buffer[d++]<<16|this.buffer[d]<<24)>>>0}},{key:"getByte",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return this.buffer[d]}},{key:"getChar",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return this.buffer[d]<<24>>24}},{key:"iterator",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return new a.ChunkIterator(this,d)}},{key:"iterate",value:function(d){var h=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,g=new a.ChunkIterator(this,h);return g.iterate(d),g.target}},{key:"getBuffer",value:function(d,h){return this.buffer.subarray(d,d+h)}}])&&i(f.prototype,m),u})()},"./src/soundFont2.ts":function(n,r,s){s.r(r),s.d(r,"SoundFont2",(function(){return h}));var a=s("./src/types/index.ts"),o=s("./src/chunk.ts"),i=s("./src/riff/index.ts"),l=s("./src/chunks/index.ts"),c=s("./src/utils/index.ts");function u(g){for(var v=1;v<arguments.length;v++){var y=arguments[v]!=null?arguments[v]:{},b=Object.keys(y);typeof Object.getOwnPropertySymbols=="function"&&(b=b.concat(Object.getOwnPropertySymbols(y).filter((function(w){return Object.getOwnPropertyDescriptor(y,w).enumerable})))),b.forEach((function(w){d(g,w,y[w])}))}return g}function f(g,v){for(var y=0;y<v.length;y++){var b=v[y];b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(g,b.key,b)}}function m(g,v,y){return v&&f(g.prototype,v),y&&f(g,y),g}function d(g,v,y){return v in g?Object.defineProperty(g,v,{value:y,enumerable:!0,configurable:!0,writable:!0}):g[v]=y,g}var h=(function(){function g(v){if((function(b,w){if(!(b instanceof w))throw new TypeError("Cannot call a class as a function")})(this,g),d(this,"chunk",void 0),d(this,"metaData",void 0),d(this,"sampleData",void 0),d(this,"samples",void 0),d(this,"presetData",void 0),d(this,"instruments",void 0),d(this,"presets",void 0),d(this,"banks",void 0),!(v instanceof o.SF2Chunk)){var y=Object(i.parseBuffer)(v);v=new o.SF2Chunk(y)}if(v.subChunks.length!==3)throw new i.ParseError("Invalid sfbk structure","3 chunks","".concat(v.subChunks.length," chunks"));this.chunk=v,this.metaData=v.subChunks[0].getMetaData(),this.sampleData=v.subChunks[1].getSampleData(),this.presetData=v.subChunks[2].getPresetData(),this.samples=this.getSamples(),this.instruments=this.getInstruments(),this.presets=this.getPresets(),this.banks=this.getBanks()}return m(g,null,[{key:"from",value:function(v){return new g(v)}}]),m(g,[{key:"getKeyData",value:function(v){var y=this,b=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,w=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;return Object(c.memoize)((function(_,x,S){var k=y.banks[x];if(k){var E=k.presets[S];if(E){var I=E.zones.filter((function(ne){return y.isKeyInRange(ne,_)}));if(I.length>0){var T=!0,R=!1,A=void 0;try{for(var M,$=I[Symbol.iterator]();!(T=(M=$.next()).done);T=!0){var P=M.value,O=P.instrument,Z=O.zones.filter((function(ne){return y.isKeyInRange(ne,_)}));if(Z.length>0){var G=!0,Y=!1,ee=void 0;try{for(var X,K=Z[Symbol.iterator]();!(G=(X=K.next()).done);G=!0){var le=X.value,te=le.sample,fe=u({},P.generators,le.generators),de=u({},P.modulators,le.modulators);return{keyNumber:_,preset:E,instrument:O,sample:te,generators:fe,modulators:de}}}catch(ne){Y=!0,ee=ne}finally{try{G||K.return==null||K.return()}finally{if(Y)throw ee}}}}}catch(ne){R=!0,A=ne}finally{try{T||$.return==null||$.return()}finally{if(R)throw A}}}}}return null}))(v,b,w)}},{key:"isKeyInRange",value:function(v,y){return v.keyRange===void 0||v.keyRange.lo<=y&&v.keyRange.hi>=y}},{key:"getBanks",value:function(){return this.presets.reduce((function(v,y){var b=y.header.bank;return v[b]||(v[b]={presets:[]}),v[b].presets[y.header.preset]=y,v}),[])}},{key:"getPresets",value:function(){var v=this.presetData,y=v.presetHeaders,b=v.presetZones,w=v.presetGenerators,_=v.presetModulators;return Object(l.getItemsInZone)(y,b,_,w,this.instruments,a.GeneratorType.Instrument).filter((function(x){return x.header.name!=="EOP"})).map((function(x){return{header:x.header,globalZone:x.globalZone,zones:x.zones.map((function(S){return{keyRange:S.keyRange,generators:S.generators,modulators:S.modulators,instrument:S.reference}}))}}))}},{key:"getInstruments",value:function(){var v=this.presetData,y=v.instrumentHeaders,b=v.instrumentZones,w=v.instrumentModulators,_=v.instrumentGenerators;return Object(l.getItemsInZone)(y,b,w,_,this.samples,a.GeneratorType.SampleId).filter((function(x){return x.header.name!=="EOI"})).map((function(x){return{header:x.header,globalZone:x.globalZone,zones:x.zones.map((function(S){return{keyRange:S.keyRange,generators:S.generators,modulators:S.modulators,sample:S.reference}}))}}))}},{key:"getSamples",value:function(){var v=this;return this.presetData.sampleHeaders.filter((function(y){return y.name!=="EOS"})).map((function(y){if(y.name!=="EOS"&&y.sampleRate<=0)throw new Error("Illegal sample rate of ".concat(y.sampleRate," hz in sample '").concat(y.name,"'"));return y.originalPitch>=128&&y.originalPitch<=254&&(y.originalPitch=60),y.startLoop-=y.start,y.endLoop-=y.start,{header:y,data:new Int16Array(new Uint8Array(v.sampleData.subarray(2*y.start,2*y.end)).buffer)}}))}}]),g})()},"./src/types/bank.ts":function(n,r){},"./src/types/generator.ts":function(n,r,s){var a,o;function i(c,u,f){return u in c?Object.defineProperty(c,u,{value:f,enumerable:!0,configurable:!0,writable:!0}):c[u]=f,c}s.r(r),s.d(r,"GeneratorType",(function(){return o})),s.d(r,"DEFAULT_GENERATOR_VALUES",(function(){return l})),(function(c){c[c.StartAddrsOffset=0]="StartAddrsOffset",c[c.EndAddrsOffset=1]="EndAddrsOffset",c[c.StartLoopAddrsOffset=2]="StartLoopAddrsOffset",c[c.EndLoopAddrsOffset=3]="EndLoopAddrsOffset",c[c.StartAddrsCoarseOffset=4]="StartAddrsCoarseOffset",c[c.ModLFOToPitch=5]="ModLFOToPitch",c[c.VibLFOToPitch=6]="VibLFOToPitch",c[c.ModEnvToPitch=7]="ModEnvToPitch",c[c.InitialFilterFc=8]="InitialFilterFc",c[c.InitialFilterQ=9]="InitialFilterQ",c[c.ModLFOToFilterFc=10]="ModLFOToFilterFc",c[c.ModEnvToFilterFc=11]="ModEnvToFilterFc",c[c.EndAddrsCoarseOffset=12]="EndAddrsCoarseOffset",c[c.ModLFOToVolume=13]="ModLFOToVolume",c[c.Unused1=14]="Unused1",c[c.ChorusEffectsSend=15]="ChorusEffectsSend",c[c.ReverbEffectsSend=16]="ReverbEffectsSend",c[c.Pan=17]="Pan",c[c.Unused2=18]="Unused2",c[c.Unused3=19]="Unused3",c[c.Unused4=20]="Unused4",c[c.DelayModLFO=21]="DelayModLFO",c[c.FreqModLFO=22]="FreqModLFO",c[c.DelayVibLFO=23]="DelayVibLFO",c[c.FreqVibLFO=24]="FreqVibLFO",c[c.DelayModEnv=25]="DelayModEnv",c[c.AttackModEnv=26]="AttackModEnv",c[c.HoldModEnv=27]="HoldModEnv",c[c.DecayModEnv=28]="DecayModEnv",c[c.SustainModEnv=29]="SustainModEnv",c[c.ReleaseModEnv=30]="ReleaseModEnv",c[c.KeyNumToModEnvHold=31]="KeyNumToModEnvHold",c[c.KeyNumToModEnvDecay=32]="KeyNumToModEnvDecay",c[c.DelayVolEnv=33]="DelayVolEnv",c[c.AttackVolEnv=34]="AttackVolEnv",c[c.HoldVolEnv=35]="HoldVolEnv",c[c.DecayVolEnv=36]="DecayVolEnv",c[c.SustainVolEnv=37]="SustainVolEnv",c[c.ReleaseVolEnv=38]="ReleaseVolEnv",c[c.KeyNumToVolEnvHold=39]="KeyNumToVolEnvHold",c[c.KeyNumToVolEnvDecay=40]="KeyNumToVolEnvDecay",c[c.Instrument=41]="Instrument",c[c.Reserved1=42]="Reserved1",c[c.KeyRange=43]="KeyRange",c[c.VelRange=44]="VelRange",c[c.StartLoopAddrsCoarseOffset=45]="StartLoopAddrsCoarseOffset",c[c.KeyNum=46]="KeyNum",c[c.Velocity=47]="Velocity",c[c.InitialAttenuation=48]="InitialAttenuation",c[c.Reserved2=49]="Reserved2",c[c.EndLoopAddrsCoarseOffset=50]="EndLoopAddrsCoarseOffset",c[c.CoarseTune=51]="CoarseTune",c[c.FineTune=52]="FineTune",c[c.SampleId=53]="SampleId",c[c.SampleModes=54]="SampleModes",c[c.Reserved3=55]="Reserved3",c[c.ScaleTuning=56]="ScaleTuning",c[c.ExclusiveClass=57]="ExclusiveClass",c[c.OverridingRootKey=58]="OverridingRootKey",c[c.Unused5=59]="Unused5",c[c.EndOper=60]="EndOper"})(o||(o={}));var l=(i(a={},o.StartAddrsOffset,0),i(a,o.EndAddrsOffset,0),i(a,o.StartLoopAddrsOffset,0),i(a,o.EndLoopAddrsOffset,0),i(a,o.StartAddrsCoarseOffset,0),i(a,o.ModLFOToPitch,0),i(a,o.VibLFOToPitch,0),i(a,o.ModEnvToPitch,0),i(a,o.InitialFilterFc,13500),i(a,o.InitialFilterQ,0),i(a,o.ModLFOToFilterFc,0),i(a,o.ModEnvToFilterFc,0),i(a,o.EndAddrsCoarseOffset,0),i(a,o.ModLFOToVolume,0),i(a,o.ChorusEffectsSend,0),i(a,o.ReverbEffectsSend,0),i(a,o.Pan,0),i(a,o.DelayModLFO,-12e3),i(a,o.FreqModLFO,0),i(a,o.DelayVibLFO,-12e3),i(a,o.FreqVibLFO,0),i(a,o.DelayModEnv,-12e3),i(a,o.AttackModEnv,-12e3),i(a,o.HoldModEnv,-12e3),i(a,o.DecayModEnv,-12e3),i(a,o.SustainModEnv,0),i(a,o.ReleaseModEnv,-12e3),i(a,o.KeyNumToModEnvHold,0),i(a,o.KeyNumToModEnvDecay,0),i(a,o.DelayVolEnv,-12e3),i(a,o.AttackVolEnv,-12e3),i(a,o.HoldVolEnv,-12e3),i(a,o.DecayVolEnv,-12e3),i(a,o.SustainVolEnv,0),i(a,o.ReleaseVolEnv,-12e3),i(a,o.KeyNumToVolEnvHold,0),i(a,o.KeyNumToVolEnvDecay,0),i(a,o.StartLoopAddrsCoarseOffset,0),i(a,o.KeyNum,-1),i(a,o.Velocity,-1),i(a,o.InitialAttenuation,0),i(a,o.EndLoopAddrsCoarseOffset,0),i(a,o.CoarseTune,0),i(a,o.FineTune,0),i(a,o.SampleModes,0),i(a,o.ScaleTuning,100),i(a,o.ExclusiveClass,0),i(a,o.OverridingRootKey,-1),a)},"./src/types/index.ts":function(n,r,s){s.r(r);var a=s("./src/types/bank.ts");for(var o in a)["default"].indexOf(o)<0&&(function(v){s.d(r,v,(function(){return a[v]}))})(o);var i=s("./src/types/generator.ts");s.d(r,"GeneratorType",(function(){return i.GeneratorType})),s.d(r,"DEFAULT_GENERATOR_VALUES",(function(){return i.DEFAULT_GENERATOR_VALUES}));var l=s("./src/types/instrument.ts");for(var o in l)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return l[y]}))})(o);var c=s("./src/types/key.ts");for(var o in c)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return c[y]}))})(o);var u=s("./src/types/metaData.ts");for(var o in u)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return u[y]}))})(o);var f=s("./src/types/modulator.ts");s.d(r,"ControllerType",(function(){return f.ControllerType})),s.d(r,"ControllerPolarity",(function(){return f.ControllerPolarity})),s.d(r,"ControllerDirection",(function(){return f.ControllerDirection})),s.d(r,"ControllerPalette",(function(){return f.ControllerPalette})),s.d(r,"Controller",(function(){return f.Controller})),s.d(r,"TransformType",(function(){return f.TransformType})),s.d(r,"DEFAULT_INSTRUMENT_MODULATORS",(function(){return f.DEFAULT_INSTRUMENT_MODULATORS}));var m=s("./src/types/preset.ts");for(var o in m)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return m[y]}))})(o);var d=s("./src/types/presetData.ts");for(var o in d)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return d[y]}))})(o);var h=s("./src/types/sample.ts");s.d(r,"SampleType",(function(){return h.SampleType}));var g=s("./src/types/zone.ts");for(var o in g)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS","SampleType"].indexOf(o)<0&&(function(y){s.d(r,y,(function(){return g[y]}))})(o)},"./src/types/instrument.ts":function(n,r){},"./src/types/key.ts":function(n,r){},"./src/types/metaData.ts":function(n,r){},"./src/types/modulator.ts":function(n,r,s){s.r(r),s.d(r,"ControllerType",(function(){return a})),s.d(r,"ControllerPolarity",(function(){return o})),s.d(r,"ControllerDirection",(function(){return i})),s.d(r,"ControllerPalette",(function(){return l})),s.d(r,"Controller",(function(){return c})),s.d(r,"TransformType",(function(){return u})),s.d(r,"DEFAULT_INSTRUMENT_MODULATORS",(function(){return m}));var a,o,i,l,c,u,f=s("./src/types/generator.ts");(function(d){d[d.Linear=0]="Linear",d[d.Concave=1]="Concave",d[d.Convex=2]="Convex",d[d.Switch=3]="Switch"})(a||(a={})),(function(d){d[d.Unipolar=0]="Unipolar",d[d.Bipolar=1]="Bipolar"})(o||(o={})),(function(d){d[d.Increasing=0]="Increasing",d[d.Decreasing=1]="Decreasing"})(i||(i={})),(function(d){d[d.GeneralController=0]="GeneralController",d[d.MidiController=1]="MidiController"})(l||(l={})),(function(d){d[d.NoController=0]="NoController",d[d.NoteOnVelocity=2]="NoteOnVelocity",d[d.NoteOnKeyNumber=3]="NoteOnKeyNumber",d[d.PolyPressure=10]="PolyPressure",d[d.ChannelPressure=13]="ChannelPressure",d[d.PitchWheel=14]="PitchWheel",d[d.PitchWheelSensitivity=16]="PitchWheelSensitivity",d[d.Link=127]="Link"})(c||(c={})),(function(d){d[d.Linear=0]="Linear",d[d.Absolute=2]="Absolute"})(u||(u={}));var m=[{id:f.GeneratorType.InitialAttenuation,source:{type:a.Concave,polarity:o.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:960,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialFilterFc,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:-2400,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.ChannelPressure},value:50,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.MidiController,index:1},value:50,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:a.Concave,polarity:o.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:7},value:960,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:a.Linear,polarity:o.Bipolar,direction:i.Increasing,palette:l.MidiController,index:10},value:1e3,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:a.Concave,polarity:o.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:11},value:960,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ReverbEffectsSend,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.MidiController,index:91},value:200,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ChorusEffectsSend,source:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.MidiController,index:93},value:200,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.CoarseTune,source:{type:a.Linear,polarity:o.Bipolar,direction:i.Increasing,palette:l.GeneralController,index:c.PitchWheel},value:12700,valueSource:{type:a.Linear,polarity:o.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.PitchWheelSensitivity},transform:u.Linear}]},"./src/types/preset.ts":function(n,r){},"./src/types/presetData.ts":function(n,r){},"./src/types/sample.ts":function(n,r,s){var a;s.r(r),s.d(r,"SampleType",(function(){return a})),(function(o){o[o.EOS=0]="EOS",o[o.Mono=1]="Mono",o[o.Right=2]="Right",o[o.Left=4]="Left",o[o.Linked=8]="Linked",o[o.RomMono=32769]="RomMono",o[o.RomRight=32770]="RomRight",o[o.RomLeft=32772]="RomLeft",o[o.RomLinked=32776]="RomLinked"})(a||(a={}))},"./src/types/zone.ts":function(n,r){},"./src/utils/buffer.ts":function(n,r,s){s.r(r),s.d(r,"getStringFromBuffer",(function(){return a}));var a=function(o){var i=new TextDecoder("utf8").decode(o),l=i.indexOf("\0");return(l===-1?i:i.slice(0,l)).trim()}},"./src/utils/index.ts":function(n,r,s){s.r(r);var a=s("./src/utils/buffer.ts");s.d(r,"getStringFromBuffer",(function(){return a.getStringFromBuffer}));var o=s("./src/utils/memoize.ts");s.d(r,"memoize",(function(){return o.memoize}))},"./src/utils/memoize.ts":function(n,r,s){s.r(r),s.d(r,"memoize",(function(){return a}));var a=function(o){var i={};return function(){for(var l=arguments.length,c=new Array(l),u=0;u<l;u++)c[u]=arguments[u];var f=JSON.stringify(c);if(f in i)return i[f];var m=o.apply(void 0,c);return i[f]=m,m}}}})}))})(ca)),ca.exports}nh();var Pe=1e3;function Ea(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m}=e,d=t?.sampleRate??e.sampleRate??c?.sample_rate,h=t?.length??e.sourceDurationSamples??(c&&d?Math.ceil(c.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(h===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&c&&t.sampleRate!==c.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${c.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.durationSamples??h;return{id:dc(),audioBuffer:t,startSample:n,durationSamples:g,offsetSamples:r,sampleRate:d,sourceDurationSamples:h,gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m}}function cc(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m}=e,d=t?.sampleRate??e.sampleRate??c?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const h=t?.duration??e.sourceDuration??c?.duration;if(h===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&c&&t.sampleRate!==c.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${c.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.duration??h;return Ea({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(g*d),offsetSamples:Math.round(r*d),sampleRate:d,sourceDurationSamples:Math.ceil(h*d),gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:m})}function uc(e){const{name:t,clips:n=[],muted:r=!1,soloed:s=!1,volume:a=1,pan:o=0,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}=e;return{id:dc(),name:t,clips:n,muted:r,soloed:s,volume:a,pan:o,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}}function dc(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function il(e){return[...e].sort((t,n)=>t.startSample-n.startSample)}function rh(e,t){return Math.floor(e/t)}function sh(e,t,n){return Math.ceil(e*n/t)}var Nn=192;function Vs(e,t=Nn){const[,n]=e;return t*(4/n)}function vo(e,t=Nn){const[n]=e;return n*Vs(e,t)}function Rn(e,t,n,r=Nn){return Math.round(e*60*n/(t*r))}function Ia(e,t,n,r=Nn){return Math.round(e*r*t/(60*n))}function Ma(e,t){return Math.round(e/t)*t}function ah(e,t,n=Nn){const r=vo(t,n),s=Vs(t,n),a=Math.floor(e/r)+1,o=Math.floor(e%r/s)+1;return o===1?`${a}`:`${a}.${o}`}function qr(e){return e.startSample/e.sampleRate}function ll(e){return(e.startSample+e.durationSamples)/e.sampleRate}function cl(e){return e.offsetSamples/e.sampleRate}function ul(e){return e.durationSamples/e.sampleRate}function fc(e,t,n){return Math.floor((e+t)/n)-Math.floor(e/n)}var dl=!1;function vr(e){const t=e._param;return!t&&!dl&&(dl=!0,console.warn("[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Mute scheduling may not work correctly.")),t}function fl(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r;n[s]=t?a:1-a}return n}function oh(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r,o=t?s:e-1-s;n[o]=Math.exp(2*a-1)/Math.E}return n}function ih(e,t){const n=new Float32Array(e),r=t?Math.PI/2:-Math.PI/2;for(let s=0;s<e;s++)n[s]=Math.sin(Math.PI*s/e-r)/2+.5;return n}function lh(e,t,n=10){const r=new Float32Array(e);for(let s=0;s<e;s++){const a=t?s:e-1-s,o=s/e;r[a]=Math.log(1+n*o)/Math.log(1+n)}return r}function hc(e,t,n){switch(e){case"linear":return fl(t,n);case"exponential":return oh(t,n);case"sCurve":return ih(t,n);case"logarithmic":return lh(t,n);default:return fl(t,n)}}function hl(e,t,n,r="linear",s=0,a=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=hc(r,1e4,!0),i=new Float32Array(o.length),l=a-s;for(let c=0;c<o.length;c++)i[c]=s+o[c]*l;e.setValueCurveAtTime(i,t,n)}}function pl(e,t,n,r="linear",s=1,a=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=hc(r,1e4,!1),i=new Float32Array(o.length),l=s-a;for(let c=0;c<o.length;c++)i[c]=a+o[c]*l;e.setValueCurveAtTime(i,t,n)}}var ch=class{constructor(e){this.activeSources=new Set,this._scheduleGuardOffset=0,this.track=e.track,this.volumeNode=new L.Volume(this.gainToDb(e.track.gain)),this.panNode=new L.Panner(e.track.stereoPan),this.muteGain=new L.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const t=e.destination||L.getDestination();if(e.effects){const o=e.effects(this.muteGain,t,!1);o&&(this.effectsCleanup=o)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]),r=L.getTransport(),s=L.getContext().rawContext,a=this.volumeNode.input.input;this.scheduledClips=n.map(o=>{const i=s.createGain();i.gain.value=o.gain,i.connect(a);const l=this.track.startTime+o.startTime,c=r.schedule(u=>{l<this._scheduleGuardOffset||this.startClipSource(o,i,u)},l);return{clipInfo:o,fadeGainNode:i,scheduleId:c}})}startClipSource(e,t,n,r,s){const o=L.getContext().rawContext.createBufferSource();o.buffer=e.buffer,o.connect(t);const i=r??e.offset,l=s??e.duration;try{o.start(n,i,l)}catch(c){console.warn(`[waveform-playlist] Failed to start source on track "${this.id}" (time=${n}, offset=${i}, duration=${l}):`,c),o.disconnect();return}this.activeSources.add(o),o.onended=()=>{this.activeSources.delete(o)}}setScheduleGuardOffset(e){this._scheduleGuardOffset=e}startMidClipSources(e,t){for(const{clipInfo:n,fadeGainNode:r}of this.scheduledClips){const s=this.track.startTime+n.startTime,a=s+n.duration;if(s<e&&a>e){const o=e-s,i=n.offset+o,l=n.duration-o;this.startClipSource(n,r,t,i,l)}}}stopAllSources(){this.activeSources.forEach(e=>{try{e.stop()}catch(t){console.warn(`[waveform-playlist] Error stopping source on track "${this.id}":`,t)}}),this.activeSources.clear()}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGainNode:s}=e,a=s.gain;a.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const i=r.fadeIn.duration;if(o<=0)hl(a,t,i,r.fadeIn.type||"linear",0,r.gain);else{const l=i-o,c=o/i,u=r.gain*c;hl(a,t,l,r.fadeIn.type||"linear",u,r.gain)}}else a.setValueAtTime(r.gain,t);if(r.fadeOut){const l=r.duration-r.fadeOut.duration-o;if(l>0){const c=t+l;pl(a,c,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(l>-r.fadeOut.duration){const c=-l,u=r.fadeOut.duration-c,f=c/r.fadeOut.duration,m=r.gain*(1-f);pl(a,t,u,r.fadeOut.type||"linear",m,0)}}}prepareFades(e,t){this.scheduledClips.forEach(n=>{const r=this.track.startTime+n.clipInfo.startTime,s=r+n.clipInfo.duration;if(!(t>=s))if(t>=r){const a=t-r+n.clipInfo.offset;this.scheduleFades(n,e,a)}else{const a=r-t;this.scheduleFades(n,e+a,n.clipInfo.offset)}})}cancelFades(){this.scheduledClips.forEach(({fadeGainNode:e,clipInfo:t})=>{const n=e.gain;n.cancelScheduledValues(0),n.setValueAtTime(t.gain,0)})}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;vr(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){const e=L.getTransport();if(this.effectsCleanup)try{this.effectsCleanup()}catch(t){console.warn(`[waveform-playlist] Error during track "${this.id}" effects cleanup:`,t)}this.stopAllSources(),this.scheduledClips.forEach((t,n)=>{try{e.clear(t.scheduleId)}catch(r){console.warn(`[waveform-playlist] Error clearing schedule ${n} on track "${this.id}":`,r)}try{t.fadeGainNode.disconnect()}catch(r){console.warn(`[waveform-playlist] Error disconnecting fadeGain ${n} on track "${this.id}":`,r)}});try{this.volumeNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing volumeNode on track "${this.id}":`,t)}try{this.panNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing panNode on track "${this.id}":`,t)}try{this.muteGain.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing muteGain on track "${this.id}":`,t)}}get id(){return this.track.id}get duration(){if(this.scheduledClips.length===0)return 0;const e=this.scheduledClips[this.scheduledClips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.scheduledClips[0]?.clipInfo.buffer}get muted(){return this.track.muted}get startTime(){return this.track.startTime}};function uh(e){return e===35||e===36?"kick":e>=37&&e<=40?"snare":e===41||e===43||e===45||e===47||e===48||e===50?"tom":"cymbal"}var dh=class{constructor(e){this.track=e.track,this.volumeNode=new L.Volume(this.gainToDb(e.track.gain)),this.panNode=new L.Panner(e.track.stereoPan),this.muteGain=new L.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain),this.synth=new L.PolySynth(L.Synth,e.synthOptions),this.synth.connect(this.volumeNode),this.kickSynth=new L.PolySynth(L.MembraneSynth,{voice:L.MembraneSynth,options:{pitchDecay:.05,octaves:6,envelope:{attack:.001,decay:.4,sustain:0,release:.1}}}),this.snareSynth=new L.NoiseSynth({noise:{type:"white"},envelope:{attack:.001,decay:.15,sustain:0,release:.05}}),this.cymbalSynth=new L.PolySynth(L.MetalSynth,{voice:L.MetalSynth,options:{envelope:{attack:.001,decay:.3,release:.1},harmonicity:5.1,modulationIndex:32,resonance:4e3,octaves:1.5}}),this.tomSynth=new L.PolySynth(L.MembraneSynth,{voice:L.MembraneSynth,options:{pitchDecay:.08,octaves:4,envelope:{attack:.001,decay:.3,sustain:0,release:.1}}}),this.kickSynth.connect(this.volumeNode),this.snareSynth.connect(this.volumeNode),this.cymbalSynth.connect(this.volumeNode),this.tomSynth.connect(this.volumeNode);const t=e.destination||L.getDestination();if(e.effects){const n=e.effects(this.muteGain,t,!1);n&&(this.effectsCleanup=n)}else this.muteGain.connect(t);this.scheduledClips=e.clips.map(n=>{const r=n.notes.filter(i=>{const l=i.time+i.duration;return i.time<n.offset+n.duration&&l>n.offset}),s=this.track.startTime+n.startTime,a=r.map(i=>{const l=i.time-n.offset,c=Math.max(0,l),u=Math.min(i.duration-Math.max(0,n.offset-i.time),n.duration-c);return{time:s+c,note:i.name,midi:i.midi,duration:Math.max(0,u),velocity:i.velocity,channel:i.channel}}),o=new L.Part((i,l)=>{l.duration>0&&this.triggerNote(l.midi,l.note,l.duration,i,l.velocity,l.channel)},a);return o.start(0),{clipInfo:n,part:o}})}triggerNote(e,t,n,r,s,a){if(a===9)switch(uh(e)){case"kick":this.kickSynth.triggerAttackRelease("C1",n,r,s);break;case"snare":try{this.snareSynth.triggerAttackRelease(n,r,s)}catch(i){console.warn("[waveform-playlist] Snare overlap — previous hit still decaying, skipped:",i)}break;case"tom":{const i={41:"G1",43:"A1",45:"C2",47:"D2",48:"E2",50:"G2"};this.tomSynth.triggerAttackRelease(i[e]||"C2",n,r,s);break}case"cymbal":this.cymbalSynth.triggerAttackRelease("C4",n,r,s);break}else this.synth.triggerAttackRelease(t,n,r,s)}gainToDb(e){return 20*Math.log10(e)}setScheduleGuardOffset(e){}startMidClipSources(e,t){for(const{clipInfo:n}of this.scheduledClips){const r=this.track.startTime+n.startTime,s=r+n.duration;if(r<e&&s>e)for(const a of n.notes){const o=a.time-n.offset,i=r+Math.max(0,o),l=i+a.duration;if(i<e&&l>e){const c=l-e;try{this.triggerNote(a.midi,a.name,c,t,a.velocity,a.channel)}catch(u){console.warn(`[waveform-playlist] Failed to start mid-clip MIDI note "${a.name}" on track "${this.id}":`,u)}}}}}stopAllSources(){const e=L.getContext().rawContext.currentTime;try{this.synth.releaseAll(e),this.kickSynth.releaseAll(e),this.cymbalSynth.releaseAll(e),this.tomSynth.releaseAll(e)}catch(t){console.warn(`[waveform-playlist] Error releasing synth on track "${this.id}":`,t)}}prepareFades(e,t){}cancelFades(){}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;vr(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){if(this.effectsCleanup)try{this.effectsCleanup()}catch(t){console.warn(`[waveform-playlist] Error during MIDI track "${this.id}" effects cleanup:`,t)}this.stopAllSources(),this.scheduledClips.forEach(({part:t},n)=>{try{t.dispose()}catch(r){console.warn(`[waveform-playlist] Error disposing Part ${n} on MIDI track "${this.id}":`,r)}});const e=[this.synth,this.kickSynth,this.snareSynth,this.cymbalSynth,this.tomSynth];for(const t of e)try{t?.dispose()}catch(n){console.warn(`[waveform-playlist] Error disposing synth on MIDI track "${this.id}":`,n)}try{this.volumeNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing volumeNode on MIDI track "${this.id}":`,t)}try{this.panNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing panNode on MIDI track "${this.id}":`,t)}try{this.muteGain.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing muteGain on MIDI track "${this.id}":`,t)}}get id(){return this.track.id}get duration(){if(this.scheduledClips.length===0)return 0;const e=this.scheduledClips[this.scheduledClips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get muted(){return this.track.muted}get startTime(){return this.track.startTime}},pc=class Aa{constructor(t){this.activeSources=new Set,this.track=t.track,this.soundFontCache=t.soundFontCache,this.programNumber=t.programNumber??0,this.bankNumber=t.isPercussion?128:0,this.volumeNode=new L.Volume(this.gainToDb(t.track.gain)),this.panNode=new L.Panner(t.track.stereoPan),this.muteGain=new L.Gain(t.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const n=t.destination||L.getDestination();if(t.effects){const r=t.effects(this.muteGain,n,!1);r&&(this.effectsCleanup=r)}else this.muteGain.connect(n);this.scheduledClips=t.clips.map(r=>{const s=r.notes.filter(l=>{const c=l.time+l.duration;return l.time<r.offset+r.duration&&c>r.offset}),a=this.track.startTime+r.startTime,o=s.map(l=>{const c=l.time-r.offset,u=Math.max(0,c),f=Math.min(l.duration-Math.max(0,r.offset-l.time),r.duration-u);return{time:a+u,note:l.name,midi:l.midi,duration:Math.max(0,f),velocity:l.velocity,channel:l.channel}}),i=new L.Part((l,c)=>{c.duration>0&&this.triggerNote(c.midi,c.duration,l,c.velocity,c.channel)},o);return i.start(0),{clipInfo:r,part:i}})}triggerNote(t,n,r,s,a){const o=a===9?128:this.bankNumber,i=a===9?0:this.programNumber,l=this.soundFontCache.getAudioBuffer(t,o,i);if(!l){Aa._missingSampleWarned||(console.warn(`[waveform-playlist] SoundFont sample not found for MIDI note ${t} (bank ${o}, preset ${i}). Subsequent missing samples will be silent.`),Aa._missingSampleWarned=!0);return}const c=L.getContext().rawContext,u=c.createBufferSource();u.buffer=l.buffer,u.playbackRate.value=l.playbackRate,(l.loopMode===1||l.loopMode===3)&&(u.loop=!0,u.loopStart=l.loopStart,u.loopEnd=l.loopEnd);const f=l.buffer.duration/l.playbackRate,m=l.loopMode===0?Math.max(n,f):n,d=s*s,h=c.createGain(),{attackVolEnv:g,holdVolEnv:v,decayVolEnv:y,sustainVolEnv:b,releaseVolEnv:w}=l,_=d*b;h.gain.setValueAtTime(0,r),h.gain.linearRampToValueAtTime(d,r+g),v>.001&&h.gain.setValueAtTime(d,r+g+v);const x=r+g+v;h.gain.linearRampToValueAtTime(_,x+y),h.gain.setValueAtTime(_,r+m),h.gain.linearRampToValueAtTime(0,r+m+w),u.connect(h),h.connect(this.volumeNode.input.input),this.activeSources.add(u),u.onended=()=>{this.activeSources.delete(u);try{h.disconnect()}catch(S){console.warn("[waveform-playlist] GainNode already disconnected:",S)}},u.start(r),u.stop(r+m+w)}gainToDb(t){return 20*Math.log10(t)}setScheduleGuardOffset(t){}startMidClipSources(t,n){for(const{clipInfo:r}of this.scheduledClips){const s=this.track.startTime+r.startTime,a=s+r.duration;if(s<t&&a>t)for(const o of r.notes){const i=o.time-r.offset,l=s+Math.max(0,i),c=l+o.duration;if(l<t&&c>t){const u=c-t;try{this.triggerNote(o.midi,u,n,o.velocity,o.channel)}catch(f){console.warn(`[waveform-playlist] Failed to start mid-clip SoundFont note on track "${this.id}":`,f)}}}}}stopAllSources(){for(const t of this.activeSources)try{t.stop()}catch(n){console.warn("[waveform-playlist] Error stopping AudioBufferSourceNode:",n)}this.activeSources.clear()}prepareFades(t,n){}cancelFades(){}setVolume(t){this.track.gain=t,this.volumeNode.volume.value=this.gainToDb(t)}setPan(t){this.track.stereoPan=t,this.panNode.pan.value=t}setMute(t){this.track.muted=t;const n=t?0:1;vr(this.muteGain.gain)?.setValueAtTime(n,0),this.muteGain.gain.value=n}setSolo(t){this.track.soloed=t}dispose(){if(this.effectsCleanup)try{this.effectsCleanup()}catch(t){console.warn(`[waveform-playlist] Error during SoundFont track "${this.id}" effects cleanup:`,t)}this.stopAllSources(),this.scheduledClips.forEach(({part:t},n)=>{try{t.dispose()}catch(r){console.warn(`[waveform-playlist] Error disposing Part ${n} on SoundFont track "${this.id}":`,r)}});try{this.volumeNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing volumeNode on SoundFont track "${this.id}":`,t)}try{this.panNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing panNode on SoundFont track "${this.id}":`,t)}try{this.muteGain.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing muteGain on SoundFont track "${this.id}":`,t)}}get id(){return this.track.id}get duration(){if(this.scheduledClips.length===0)return 0;const t=this.scheduledClips[this.scheduledClips.length-1];return t.clipInfo.startTime+t.clipInfo.duration}get muted(){return this.track.muted}get startTime(){return this.track.startTime}};pc._missingSampleWarned=!1;var fh=pc,hh=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this._completionEventId=null,this._loopHandler=null,this._loopEnabled=!1,this._loopStart=0,this._loopEnd=0,this.masterVolume=new L.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,L.getDestination(),!1);t&&(this.effectsCleanup=t)}else this.masterVolume.toDestination();e.tracks&&e.tracks.forEach(t=>{this.tracks.set(t.id,t),this.manualMuteState.set(t.id,t.muted)})}gainToDb(e){return 20*Math.log10(e)}clearCompletionEvent(){if(this._completionEventId!==null){try{L.getTransport().clear(this._completionEventId)}catch(e){console.warn("[waveform-playlist] Error clearing Transport completion event:",e)}this._completionEventId=null}}async init(){this.isInitialized||(await L.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new ch(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}addMidiTrack(e){const t={...e,destination:this.masterVolume},n=new dh(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}addSoundFontTrack(e){const t={...e,destination:this.masterVolume},n=new fh(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}applyInitialSoloState(){this.updateSoloMuting()}removeTrack(e){const t=this.tracks.get(e);t&&(t.dispose(),this.tracks.delete(e),this.manualMuteState.delete(e),this.soloedTracks.delete(e))}getTrack(e){return this.tracks.get(e)}play(e,t,n){if(!this.isInitialized)throw new Error("[waveform-playlist] TonePlayout not initialized. Call init() first.");const r=e??L.now(),s=L.getTransport();this.clearCompletionEvent();const a=t??0;this.tracks.forEach(o=>{o.cancelFades(),o.prepareFades(r,a)}),n!==void 0&&(this._completionEventId=s.scheduleOnce(()=>{this._completionEventId=null;try{this.onPlaybackCompleteCallback?.()}catch(o){console.warn("[waveform-playlist] Error in playback completion callback:",o)}},a+n));try{s.state!=="stopped"&&s.stop(),this.tracks.forEach(o=>o.stopAllSources()),s.loopStart=this._loopStart,s.loopEnd=this._loopEnd,s.loop=this._loopEnabled,this.tracks.forEach(o=>o.setScheduleGuardOffset(a)),t!==void 0?s.start(r,t):s.start(r),s._clock._lastUpdate=r,this.tracks.forEach(o=>{o.startMidClipSources(a,r)})}catch(o){throw this.clearCompletionEvent(),this.tracks.forEach(i=>i.cancelFades()),console.warn("[waveform-playlist] Transport.start() failed. Audio playback could not begin.",o),o}}pause(){const e=L.getTransport();try{e.pause()}catch(t){console.warn("[waveform-playlist] Transport.pause() failed:",t)}this.tracks.forEach(t=>t.stopAllSources()),this.tracks.forEach(t=>t.cancelFades()),this.clearCompletionEvent()}stop(){const e=L.getTransport();try{e.stop()}catch(t){console.warn("[waveform-playlist] Transport.stop() failed:",t)}if(this._loopHandler){try{e.off("loop",this._loopHandler)}catch(t){console.warn("[waveform-playlist] Error removing loop handler:",t)}this._loopHandler=null}this.tracks.forEach(t=>{try{t.stopAllSources()}catch(n){console.warn(`[waveform-playlist] Error stopping sources for track "${t.id}":`,n)}}),this.tracks.forEach(t=>{try{t.cancelFades()}catch(n){console.warn(`[waveform-playlist] Error canceling fades for track "${t.id}":`,n)}}),this.clearCompletionEvent()}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}setLoop(e,t,n){this._loopEnabled=e,this._loopStart=t,this._loopEnd=n;const r=L.getTransport();try{r.loopStart=t,r.loopEnd=n,r.loop=e}catch(s){console.warn("[waveform-playlist] Error configuring Transport loop:",s);return}e&&!this._loopHandler?(this._loopHandler=()=>{const s=L.now();this.tracks.forEach(a=>{try{a.stopAllSources(),a.cancelFades(),a.setScheduleGuardOffset(this._loopStart),a.startMidClipSources(this._loopStart,s),a.prepareFades(s,this._loopStart)}catch(o){console.warn(`[waveform-playlist] Error re-scheduling track "${a.id}" on loop:`,o)}})},r.on("loop",this._loopHandler)):!e&&this._loopHandler&&(r.off("loop",this._loopHandler),this._loopHandler=null)}getCurrentTime(){return L.getTransport().seconds}seekTo(e){L.getTransport().seconds=e}dispose(){try{this.stop()}catch(e){console.warn("[waveform-playlist] Error stopping Transport during dispose:",e)}if(this.tracks.forEach(e=>{try{e.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing track "${e.id}":`,t)}}),this.tracks.clear(),this.effectsCleanup)try{this.effectsCleanup()}catch(e){console.warn("[waveform-playlist] Error during master effects cleanup:",e)}try{this.masterVolume.dispose()}catch(e){console.warn("[waveform-playlist] Error disposing master volume:",e)}}get context(){return L.getContext()}get sampleRate(){return L.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Jr=null;function ph(){return Jr||(Jr=new L.Context,L.setContext(Jr)),Jr}function mh(){return ph().rawContext}function gh(e){let t=null,n=!1,r=0,s=!1,a=0,o=0,i=!1;function l(c){if(t){try{t.dispose()}catch(f){console.warn("[waveform-playlist] Error disposing previous playout during rebuild:",f)}t=null}r++;const u=r;t=new hh({effects:e?.effects}),i&&t.init().catch(f=>{console.warn("[waveform-playlist] Failed to re-initialize playout after rebuild. Audio playback will require another user gesture.",f),i=!1});for(const f of c){const m=f.clips.filter(h=>h.audioBuffer&&!h.midiNotes),d=f.clips.filter(h=>h.midiNotes&&h.midiNotes.length>0);if(m.length>0){const h=Math.min(...m.map(qr)),g=Math.max(...m.map(ll)),v={id:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:h,endTime:g},y=m.map(b=>({buffer:b.audioBuffer,startTime:qr(b)-h,duration:ul(b),offset:cl(b),fadeIn:b.fadeIn,fadeOut:b.fadeOut,gain:b.gain}));t.addTrack({clips:y,track:v,effects:f.effects})}if(d.length>0){const h=Math.min(...d.map(qr)),g=Math.max(...d.map(ll)),y={id:m.length>0?`${f.id}:midi`:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:h,endTime:g},b=d.map(w=>({notes:w.midiNotes,startTime:qr(w)-h,duration:ul(w),offset:cl(w)}));if(e?.soundFontCache?.isLoaded){const w=d[0],x=w.midiChannel===9,S=w.midiProgram??0;t.addSoundFontTrack({clips:b,track:y,soundFontCache:e.soundFontCache,programNumber:S,isPercussion:x,effects:f.effects})}else e?.soundFontCache&&console.warn(`[waveform-playlist] SoundFont not loaded for track "${f.name}" — falling back to PolySynth.`),t.addMidiTrack({clips:b,track:y,effects:f.effects})}}t.applyInitialSoloState(),t.setLoop(s,a,o),t.setOnPlaybackComplete(()=>{u===r&&(n=!1)})}return{async init(){t&&(await t.init(),i=!0)},setTracks(c){l(c)},play(c,u){if(!t){console.warn("[waveform-playlist] adapter.play() called but no playout is available. Tracks may not have been set, or the adapter was disposed.");return}const f=u!==void 0?u-c:void 0;t.play(L.now(),c,f),n=!0},pause(){t?.pause(),n=!1},stop(){t?.stop(),n=!1},seek(c){t?.seekTo(c)},getCurrentTime(){return t?.getCurrentTime()??0},isPlaying(){return n},setMasterVolume(c){t?.setMasterGain(c)},setTrackVolume(c,u){t?.getTrack(c)?.setVolume(u)},setTrackMute(c,u){t?.setMute(c,u)},setTrackSolo(c,u){t?.setSolo(c,u)},setTrackPan(c,u){t?.getTrack(c)?.setPan(u)},setLoop(c,u,f){s=c,a=u,o=f,t?.setLoop(c,u,f)},dispose(){try{t?.dispose()}catch(c){console.warn("[waveform-playlist] Error disposing playout:",c)}t=null,n=!1}}}function mc(e,t,n,r){let s=t;const a=-e.startSample;if(s=Math.max(s,a),r>0){const o=n[r-1],l=o.startSample+o.durationSamples-e.startSample;s=Math.max(s,l)}if(r<n.length-1){const i=n[r+1].startSample-(e.startSample+e.durationSamples);s=Math.min(s,i)}return s}function gc(e,t,n,r,s,a){let o=t;if(n==="left"){if(o=Math.max(o,-e.startSample),o=Math.max(o,-e.offsetSamples),s>0){const i=r[s-1],l=i.startSample+i.durationSamples;o=Math.max(o,l-e.startSample)}o=Math.min(o,e.durationSamples-a)}else if(o=Math.max(o,a-e.durationSamples),o=Math.min(o,e.sourceDurationSamples-e.offsetSamples-e.durationSamples),s<r.length-1){const i=r[s+1];o=Math.min(o,i.startSample-e.startSample-e.durationSamples)}return o}function vh(e,t){return Math.floor(e/t)*t}function yh(e,t){const n=t-e.startSample,r=e.durationSamples-n,s=e.name?`${e.name} (1)`:void 0,a=e.name?`${e.name} (2)`:void 0,o=Ea({startSample:e.startSample,durationSamples:n,offsetSamples:e.offsetSamples,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:s,color:e.color,fadeIn:e.fadeIn,audioBuffer:e.audioBuffer,waveformData:e.waveformData}),i=Ea({startSample:t,durationSamples:r,offsetSamples:e.offsetSamples+n,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:a,color:e.color,fadeOut:e.fadeOut,audioBuffer:e.audioBuffer,waveformData:e.waveformData});return{left:o,right:i}}function vc(e,t,n){const r=e.startSample+e.durationSamples;if(t<=e.startSample||t>=r)return!1;const s=t-e.startSample,a=r-t;return s>=n&&a>=n}function ua(e){let t=0;for(const n of e)for(const r of n.clips){const a=(r.startSample+r.durationSamples)/r.sampleRate;t=Math.max(t,a)}return t}function bh(e,t){if(t.length===0)return 0;let n=0,r=Math.abs(t[0]-e);for(let s=1;s<t.length;s++){const a=Math.abs(t[s]-e);a<r&&(r=a,n=s)}return n}function ml(e,t){return Math.max(0,Math.min(e,t))}var wh=44100,_h=1024,xh=[256,512,1024,2048,4096,8192],gl=.1,Ch=class{constructor(e={}){if(this._tracks=[],this._currentTime=0,this._playStartPosition=0,this._isPlaying=!1,this._selectedTrackId=null,this._selectionStart=0,this._selectionEnd=0,this._masterVolume=1,this._loopStart=0,this._loopEnd=0,this._isLoopEnabled=!1,this._tracksVersion=0,this._animFrameId=null,this._disposed=!1,this._listeners=new Map,this._sampleRate=e.sampleRate??wh,this._zoomLevels=[...e.zoomLevels??xh],this._adapter=e.adapter??null,this._zoomLevels.length===0)throw new Error("PlaylistEngine: zoomLevels must not be empty");const t=e.samplesPerPixel??_h,n=this._zoomLevels.indexOf(t);if(n===-1)throw new Error(`PlaylistEngine: samplesPerPixel ${t} is not in zoomLevels [${this._zoomLevels.join(", ")}]. Either pass a samplesPerPixel value that exists in zoomLevels, or include ${t} in your zoomLevels array.`);this._zoomIndex=n}getState(){return{tracks:this._tracks.map(e=>({...e,clips:[...e.clips]})),tracksVersion:this._tracksVersion,duration:ua(this._tracks),currentTime:this._currentTime,isPlaying:this._isPlaying,samplesPerPixel:this._zoomLevels[this._zoomIndex],sampleRate:this._sampleRate,selectedTrackId:this._selectedTrackId,zoomIndex:this._zoomIndex,canZoomIn:this._zoomIndex>0,canZoomOut:this._zoomIndex<this._zoomLevels.length-1,selectionStart:this._selectionStart,selectionEnd:this._selectionEnd,masterVolume:this._masterVolume,loopStart:this._loopStart,loopEnd:this._loopEnd,isLoopEnabled:this._isLoopEnabled}}setTracks(e){this._tracks=[...e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}addTrack(e){this._tracks=[...this._tracks,e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}removeTrack(e){this._tracks.some(t=>t.id===e)&&(this._tracks=this._tracks.filter(t=>t.id!==e),this._tracksVersion++,this._selectedTrackId===e&&(this._selectedTrackId=null),this._adapter?.setTracks(this._tracks),this._emitStateChange())}selectTrack(e){e!==this._selectedTrackId&&(this._selectedTrackId=e,this._emitStateChange())}moveClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] moveClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] moveClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=il(r.clips),i=o.findIndex(c=>c.id===t),l=mc(a,n,o,i);l!==0&&(this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=c.clips.map((f,m)=>m===s?{...f,startSample:Math.floor(f.startSample+l)}:f);return{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}splitClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] splitClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] splitClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=Math.floor(gl*this._sampleRate);if(!vc(a,n,o)){console.warn(`[waveform-playlist/engine] splitClip: cannot split clip "${t}" at sample ${n} (clip range: ${a.startSample}–${a.startSample+a.durationSamples}, minDuration: ${o})`);return}const{left:i,right:l}=yh(a,n);this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=[...c.clips];return u.splice(s,1,i,l),{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}trimClip(e,t,n,r){const s=this._tracks.find(f=>f.id===e);if(!s){console.warn(`[waveform-playlist/engine] trimClip: track "${e}" not found`);return}const a=s.clips.findIndex(f=>f.id===t);if(a===-1){console.warn(`[waveform-playlist/engine] trimClip: clip "${t}" not found in track "${e}"`);return}const o=s.clips[a],i=il(s.clips),l=i.findIndex(f=>f.id===t),c=Math.floor(gl*this._sampleRate),u=gc(o,r,n,i,l,c);u!==0&&(this._tracks=this._tracks.map(f=>{if(f.id!==e)return f;const m=f.clips.map((d,h)=>h!==a?d:n==="left"?{...d,startSample:d.startSample+u,offsetSamples:d.offsetSamples+u,durationSamples:d.durationSamples-u}:{...d,durationSamples:d.durationSamples+u});return{...f,clips:m}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}async init(){this._adapter&&await this._adapter.init()}play(e,t){const n=this._currentTime,r=this._playStartPosition;if(e!==void 0){const s=ua(this._tracks);this._currentTime=ml(e,s)}if(this._playStartPosition=this._currentTime,this._adapter){if(t!==void 0)this._adapter.setLoop(!1,this._loopStart,this._loopEnd);else if(this._isLoopEnabled){const s=this._currentTime<this._loopEnd;this._adapter.setLoop(s,this._loopStart,this._loopEnd)}try{this._adapter.play(this._currentTime,t)}catch(s){throw this._currentTime=n,this._playStartPosition=r,s}}this._isPlaying=!0,this._startTimeUpdateLoop(),this._emit("play"),this._emitStateChange()}pause(){this._isPlaying=!1,this._stopTimeUpdateLoop(),this._adapter?.pause(),this._adapter&&(this._currentTime=this._adapter.getCurrentTime()),this._emit("pause"),this._emitStateChange()}stop(){this._isPlaying=!1,this._currentTime=this._playStartPosition,this._stopTimeUpdateLoop(),this._adapter?.setLoop(!1,this._loopStart,this._loopEnd),this._adapter?.stop(),this._emit("stop"),this._emitStateChange()}seek(e){const t=ua(this._tracks);this._currentTime=ml(e,t),this._adapter?.seek(this._currentTime),this._emitStateChange()}setMasterVolume(e){e!==this._masterVolume&&(this._masterVolume=e,this._adapter?.setMasterVolume(e),this._emitStateChange())}getCurrentTime(){return this._isPlaying&&this._adapter?this._adapter.getCurrentTime():this._currentTime}setSelection(e,t){const n=Math.min(e,t),r=Math.max(e,t);n===this._selectionStart&&r===this._selectionEnd||(this._selectionStart=n,this._selectionEnd=r,this._emitStateChange())}setLoopRegion(e,t){const n=Math.min(e,t),r=Math.max(e,t);n===this._loopStart&&r===this._loopEnd||(this._loopStart=n,this._loopEnd=r,this._adapter?.setLoop(this._isLoopEnabled&&this._isBeforeLoopEnd(),this._loopStart,this._loopEnd),this._emitStateChange())}setLoopEnabled(e){e!==this._isLoopEnabled&&(this._isLoopEnabled=e,this._adapter?.setLoop(e&&this._isBeforeLoopEnd(),this._loopStart,this._loopEnd),this._emitStateChange())}setTrackVolume(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.volume=t),this._adapter?.setTrackVolume(e,t)}setTrackMute(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.muted=t),this._adapter?.setTrackMute(e,t)}setTrackSolo(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.soloed=t),this._adapter?.setTrackSolo(e,t)}setTrackPan(e,t){const n=this._tracks.find(r=>r.id===e);n&&(n.pan=t),this._adapter?.setTrackPan(e,t)}zoomIn(){this._zoomIndex>0&&(this._zoomIndex--,this._emitStateChange())}zoomOut(){this._zoomIndex<this._zoomLevels.length-1&&(this._zoomIndex++,this._emitStateChange())}setZoomLevel(e){const t=bh(e,this._zoomLevels);t!==this._zoomIndex&&(this._zoomIndex=t,this._emitStateChange())}on(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}off(e,t){this._listeners.get(e)?.delete(t)}dispose(){if(!this._disposed){this._disposed=!0,this._stopTimeUpdateLoop();try{this._adapter?.dispose()}catch(e){console.warn("[waveform-playlist/engine] Error disposing adapter:",e)}this._listeners.clear()}}_emit(e,...t){const n=this._listeners.get(e);if(n)for(const r of n)try{r(...t)}catch(s){console.warn("[waveform-playlist/engine] Error in event listener:",s)}}_isBeforeLoopEnd(){return this._isPlaying?(this._adapter?.getCurrentTime()??this._currentTime)<this._loopEnd:!0}_emitStateChange(){this._emit("statechange",this.getState())}_startTimeUpdateLoop(){if(typeof requestAnimationFrame>"u")return;this._stopTimeUpdateLoop();const e=()=>{this._disposed||!this._isPlaying||(this._adapter&&(this._currentTime=this._adapter.getCurrentTime(),this._emit("timeupdate",this._currentTime)),this._animFrameId=requestAnimationFrame(e))};this._animFrameId=requestAnimationFrame(e)}_stopTimeUpdateLoop(){this._animFrameId!==null&&typeof cancelAnimationFrame<"u"&&(cancelAnimationFrame(this._animFrameId),this._animFrameId=null)}},Sh=Symbol.for("preact-signals");function Ns(){if(Ut>1)Ut--;else{for(var e,t=!1;dr!==void 0;){var n=dr;for(dr=void 0,Ta++;n!==void 0;){var r=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&bc(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Ta=0,Ut--,t)throw e}}function Xt(e){if(Ut>0)return e();Ut++;try{return e()}finally{Ns()}}var ye=void 0;function _e(e){var t=ye;ye=void 0;try{return e()}finally{ye=t}}var dr=void 0,Ut=0,Ta=0,ws=0;function yc(e){if(ye!==void 0){var t=e.n;if(t===void 0||t.t!==ye)return t={i:0,S:e,p:ye.s,n:void 0,t:ye,e:void 0,x:void 0,r:t},ye.s!==void 0&&(ye.s.n=t),ye.s=t,e.n=t,32&ye.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=ye.s,t.n=void 0,ye.s.n=t,ye.s=t),t}}function at(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}at.prototype.brand=Sh;at.prototype.h=function(){return!0};at.prototype.S=function(e){var t=this,n=this.t;n!==e&&e.e===void 0&&(e.x=n,this.t=e,n!==void 0?n.e=e:_e(function(){var r;(r=t.W)==null||r.call(t)}))};at.prototype.U=function(e){var t=this;if(this.t!==void 0){var n=e.e,r=e.x;n!==void 0&&(n.x=r,e.e=void 0),r!==void 0&&(r.e=n,e.x=void 0),e===this.t&&(this.t=r,r===void 0&&_e(function(){var s;(s=t.Z)==null||s.call(t)}))}};at.prototype.subscribe=function(e){var t=this;return Ct(function(){var n=t.value,r=ye;ye=void 0;try{e(n)}finally{ye=r}},{name:"sub"})};at.prototype.valueOf=function(){return this.value};at.prototype.toString=function(){return this.value+""};at.prototype.toJSON=function(){return this.value};at.prototype.peek=function(){var e=ye;ye=void 0;try{return this.value}finally{ye=e}};Object.defineProperty(at.prototype,"value",{get:function(){var e=yc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ta>100)throw new Error("Cycle detected");this.v=e,this.i++,ws++,Ut++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Ns()}}}});function Mr(e,t){return new at(e,t)}function bc(e){for(var t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function wc(e){for(var t=e.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function _c(e){for(var t=e.s,n=void 0;t!==void 0;){var r=t.p;t.i===-1?(t.S.U(t),r!==void 0&&(r.n=t.n),t.n!==void 0&&(t.n.p=r)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=r}e.s=n}function pn(e,t){at.call(this,void 0),this.x=e,this.s=void 0,this.g=ws-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}pn.prototype=new at;pn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ws))return!0;if(this.g=ws,this.f|=1,this.i>0&&!bc(this))return this.f&=-2,!0;var e=ye;try{wc(this),ye=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return ye=e,_c(this),this.f&=-2,!0};pn.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}at.prototype.S.call(this,e)};pn.prototype.U=function(e){if(this.t!==void 0&&(at.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};pn.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(pn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=yc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function vl(e,t){return new pn(e,t)}function xc(e){var t=e.u;if(e.u=void 0,typeof t=="function"){Ut++;var n=ye;ye=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,yo(e),r}finally{ye=n,Ns()}}}function yo(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,xc(e)}function kh(e){if(ye!==this)throw new Error("Out-of-order effect");_c(this),ye=e,this.f&=-2,8&this.f&&yo(this),Ns()}function zn(e,t){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}zn.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{e()}};zn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,xc(this),wc(this),Ut++;var e=ye;return ye=this,kh.bind(this,e)};zn.prototype.N=function(){2&this.f||(this.f|=2,this.o=dr,dr=this)};zn.prototype.d=function(){this.f|=8,1&this.f||yo(this)};zn.prototype.dispose=function(){this.d()};function Ct(e,t){var n=new zn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var Eh=Object.create,bo=Object.defineProperty,Ih=Object.defineProperties,Mh=Object.getOwnPropertyDescriptor,Ah=Object.getOwnPropertyDescriptors,yl=Object.getOwnPropertySymbols,Th=Object.prototype.hasOwnProperty,$h=Object.prototype.propertyIsEnumerable,Rh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),jn=e=>{throw TypeError(e)},$a=(e,t,n)=>t in e?bo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dh=(e,t)=>{for(var n in t||(t={}))Th.call(t,n)&&$a(e,n,t[n]);if(yl)for(var n of yl(t))$h.call(t,n)&&$a(e,n,t[n]);return e},Ph=(e,t)=>Ih(e,Ah(t)),bl=(e,t)=>bo(e,"name",{value:t,configurable:!0}),Fh=e=>{var t;return[,,,Eh((t=void 0)!=null?t:null)]},Cc=["class","method","getter","setter","accessor","field","value","get","set"],er=e=>e!==void 0&&typeof e!="function"?jn("Function expected"):e,Oh=(e,t,n,r,s)=>({kind:Cc[e],name:t,metadata:r,addInitializer:a=>n._?jn("Already initialized"):s.push(er(a||null))}),Sc=(e,t)=>$a(t,Rh("metadata"),e[3]),nn=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},Zn=(e,t,n,r,s,a)=>{var o,i,l,c,u,f=t&7,m=!!(t&8),d=!!(t&16),h=f>3?e.length+1:f?m?1:2:0,g=Cc[f+5],v=f>3&&(e[h-1]=[]),y=e[h]||(e[h]=[]),b=f&&(!d&&!m&&(s=s.prototype),f<5&&(f>3||!d)&&Mh(f<4?s:{get[n](){return un(this,a)},set[n](_){return Zt(this,a,_)}},n));f?d&&f<4&&bl(a,(f>2?"set ":f>1?"get ":"")+n):bl(s,n);for(var w=r.length-1;w>=0;w--)c=Oh(f,n,l={},e[3],y),f&&(c.static=m,c.private=d,u=c.access={has:d?_=>Lh(s,_):_=>n in _},f^3&&(u.get=d?_=>(f^1?un:Bh)(_,s,f^4?a:b.get):_=>_[n]),f>2&&(u.set=d?(_,x)=>Zt(_,s,x,f^4?a:b.set):(_,x)=>_[n]=x)),i=(0,r[w])(f?f<4?d?a:b[g]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?er(i)&&(f>4?v.unshift(i):f?d?a=i:b[g]=i:s=i):typeof i!="object"||i===null?jn("Object expected"):(er(o=i.get)&&(b.get=o),er(o=i.set)&&(b.set=o),er(o=i.init)&&v.unshift(o));return f||Sc(e,s),b&&bo(s,n,b),d?f^4?a:b:s},wo=(e,t,n)=>t.has(e)||jn("Cannot "+n),Lh=(e,t)=>Object(t)!==t?jn('Cannot use the "in" operator on this value'):e.has(t),un=(e,t,n)=>(wo(e,t,"read from private field"),n?n.call(e):t.get(e)),Qr=(e,t,n)=>t.has(e)?jn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Zt=(e,t,n,r)=>(wo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Bh=(e,t,n)=>(wo(e,t,"access private method"),n);function _s(e,t){if(t){let n;return vl(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return vl(e)}function yr(e,t){if(Object.is(e,t))return!0;if(e===null||t===null)return!1;if(typeof e=="function"&&typeof t=="function")return e===t;if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:!e.some((r,s)=>!yr(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(a=>!yr(e[a],t[a]))}return!1}function ge({get:e},t){return{init(n){return Mr(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function $e(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=_s(e.bind(this)),n.set(this,r)),r.value}}function da(e=!0){return function(t,n){n.addInitializer(function(){const r=n.kind==="field"?this:n.static?this:Object.getPrototypeOf(this),s=Object.getOwnPropertyDescriptor(r,n.name);s&&Object.defineProperty(r,n.name,Ph(Dh({},s),{enumerable:e}))})}}function Ar(...e){const t=e.map(n=>Ct(n));return()=>t.forEach(n=>n())}var kc,Ec,Ic,Mc,Ac,Tc,nt,_o,fa,Ra,Da,Ke,xo,ha,$c,Pa,Co,pa,Fa,Oa;Tc=[ge],Ac=[ge],Mc=[ge],Ic=[da()],Ec=[da()],kc=[da()];var Kt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,nn(nt,5,this),Qr(this,Ke),Qr(this,_o,nn(nt,8,this)),nn(nt,11,this),Qr(this,xo,nn(nt,12,this)),nn(nt,15,this),Qr(this,Co,nn(nt,16,this)),nn(nt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return un(this,Ke,Fa)}get initial(){return un(this,Ke,Ra)}get previous(){return un(this,Ke,$c)}set current(e){const t=_e(()=>un(this,Ke,Fa));e&&t&&this.equals(t,e)||Xt(()=>{un(this,Ke,Ra)||Zt(this,Ke,e,Da),Zt(this,Ke,t,Pa),Zt(this,Ke,e,Oa)})}reset(e=this.defaultValue){Xt(()=>{Zt(this,Ke,void 0,Pa),Zt(this,Ke,e,Da),Zt(this,Ke,e,Oa)})}};nt=Fh();_o=new WeakMap;Ke=new WeakSet;xo=new WeakMap;Co=new WeakMap;fa=Zn(nt,20,"#initial",Tc,Ke,_o),Ra=fa.get,Da=fa.set;ha=Zn(nt,20,"#previous",Ac,Ke,xo),$c=ha.get,Pa=ha.set;pa=Zn(nt,20,"#current",Mc,Ke,Co),Fa=pa.get,Oa=pa.set;Zn(nt,2,"current",Ic,Kt);Zn(nt,2,"initial",Ec,Kt);Zn(nt,2,"previous",kc,Kt);Sc(nt,Kt);function ma(e){return _e(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var Wh=Object.create,Rc=Object.defineProperty,Vh=Object.getOwnPropertyDescriptor,wl=Object.getOwnPropertySymbols,Nh=Object.prototype.hasOwnProperty,zh=Object.prototype.propertyIsEnumerable,Dc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),zs=e=>{throw TypeError(e)},_l=Math.pow,La=(e,t,n)=>t in e?Rc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jh=(e,t)=>{for(var n in t||(t={}))Nh.call(t,n)&&La(e,n,t[n]);if(wl)for(var n of wl(t))zh.call(t,n)&&La(e,n,t[n]);return e},Zh=e=>{var t;return[,,,Wh((t=e?.[Dc("metadata")])!=null?t:null)]},Pc=["class","method","getter","setter","accessor","field","value","get","set"],Fc=e=>e!==void 0&&typeof e!="function"?zs("Function expected"):e,Hh=(e,t,n,r,s)=>({kind:Pc[e],name:t,metadata:r,addInitializer:a=>n._?zs("Already initialized"):s.push(Fc(a||null))}),Gh=(e,t)=>La(t,Dc("metadata"),e[3]),Uh=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)a[s].call(n);return r},Oc=(e,t,n,r,s,a)=>{for(var o,i,l,c,u=t&7,f=!1,m=!1,d=2,h=Pc[u+5],g=e[d]||(e[d]=[]),v=(s=s.prototype,Vh(s,n)),y=r.length-1;y>=0;y--)l=Hh(u,n,i={},e[3],g),l.static=f,l.private=m,c=l.access={has:b=>n in b},c.get=b=>b[n],o=(0,r[y])(v[h],l),i._=1,Fc(o)&&(v[h]=o);return v&&Rc(s,n,v),s},Lc=(e,t,n)=>t.has(e)||zs("Cannot "+n),Xh=(e,t,n)=>(Lc(e,t,"read from private field"),t.get(e)),Yh=(e,t,n)=>t.has(e)?zs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Kh=(e,t,n,r)=>(Lc(e,t,"write to private field"),t.set(e,n),n),Tt=class Ba{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ba(t.x-n.x,t.y-n.y)}static distance(t,n){return Math.hypot(t.x-n.x,t.y-n.y)}static equals(t,n){return t.x===n.x&&t.y===n.y}static from({x:t,y:n}){return new Ba(t,n)}},Tr=class sn{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:a,height:o,scale:i}=this,l=new sn(s+t,r+n,a,o);return l.scale=jh({},i),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:a,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:a,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Tt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof sn))return!1;const{left:n,top:r,width:s,height:a}=this;return n===t.left&&r===t.top&&s===t.width&&a===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:a}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=a}intersectionArea(t){return t instanceof sn?qh(this,t):0}intersectionRatio(t){const{area:n}=this,r=this.intersectionArea(t);return r/(t.area+n-r)}get bottom(){const{top:t,height:n}=this;return t+n}get right(){const{left:t,width:n}=this;return t+n}get aspectRatio(){const{width:t,height:n}=this;return t/n}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:t,left:n,width:r,height:s}){return new sn(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(a,o)=>{const i=r[o],l=o==="x"?a.left:a.top,c=o==="x"?a.width:a.height;return i=="start"?l:i=="end"?l+c:l+c/2};return Tt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return sn.from(t).intersectionRatio(sn.from(n))}};function qh(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=s-r,i=a-n;return r<s&&n<a?o*i:0}var Bc,Wc,Wa,is,$r,js=class extends(Wa=Kt,Wc=[$e],Bc=[$e],Wa){constructor(t){const n=Tt.from(t);super(n,(r,s)=>Tt.equals(r,s)),Uh($r,5,this),Yh(this,is,0),this.velocity={x:0,y:0}}get delta(){return Tt.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Tt.from(t),s={x:r.x-n.x,y:r.y-n.y},a=Date.now(),o=a-Xh(this,is),i=l=>Math.round(l/o*100);Xt(()=>{Kh(this,is,a),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Tt.from(t)),this.velocity={x:0,y:0}}};$r=Zh(Wa);is=new WeakMap;Oc($r,2,"delta",Wc,js);Oc($r,2,"direction",Bc,js);Gh($r,js);function Va({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(_l(r,2)+_l(s,2))>n:"x"in n&&"y"in n?r>n.x&&s>n.y:"x"in n?r>n.x:"y"in n?s>n.y:!1}var Vc=(e=>(e.Horizontal="x",e.Vertical="y",e))(Vc||{}),Nc=Object.values(Vc),Jh=Object.create,So=Object.defineProperty,Qh=Object.defineProperties,ep=Object.getOwnPropertyDescriptor,tp=Object.getOwnPropertyDescriptors,xs=Object.getOwnPropertySymbols,zc=Object.prototype.hasOwnProperty,jc=Object.prototype.propertyIsEnumerable,Zc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Hn=e=>{throw TypeError(e)},Na=(e,t,n)=>t in e?So(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Hc=(e,t)=>{for(var n in t||(t={}))zc.call(t,n)&&Na(e,n,t[n]);if(xs)for(var n of xs(t))jc.call(t,n)&&Na(e,n,t[n]);return e},Gc=(e,t)=>Qh(e,tp(t)),xl=(e,t)=>So(e,"name",{value:t,configurable:!0}),Uc=(e,t)=>{var n={};for(var r in e)zc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&xs)for(var r of xs(e))t.indexOf(r)<0&&jc.call(e,r)&&(n[r]=e[r]);return n},Gn=e=>{var t;return[,,,Jh((t=e?.[Zc("metadata")])!=null?t:null)]},Xc=["class","method","getter","setter","accessor","field","value","get","set"],tr=e=>e!==void 0&&typeof e!="function"?Hn("Function expected"):e,np=(e,t,n,r,s)=>({kind:Xc[e],name:t,metadata:r,addInitializer:a=>n._?Hn("Already initialized"):s.push(tr(a||null))}),mn=(e,t)=>Na(t,Zc("metadata"),e[3]),se=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},he=(e,t,n,r,s,a)=>{var o,i,l,c,u,f=t&7,m=!!(t&8),d=!!(t&16),h=f>3?e.length+1:f?m?1:2:0,g=Xc[f+5],v=f>3&&(e[h-1]=[]),y=e[h]||(e[h]=[]),b=f&&(!d&&!m&&(s=s.prototype),f<5&&(f>3||!d)&&ep(f<4?s:{get[n](){return Ze(this,a)},set[n](_){return wt(this,a,_)}},n));f?d&&f<4&&xl(a,(f>2?"set ":f>1?"get ":"")+n):xl(s,n);for(var w=r.length-1;w>=0;w--)c=np(f,n,l={},e[3],y),f&&(c.static=m,c.private=d,u=c.access={has:d?_=>rp(s,_):_=>n in _},f^3&&(u.get=d?_=>(f^1?Ze:sp)(_,s,f^4?a:b.get):_=>_[n]),f>2&&(u.set=d?(_,x)=>wt(_,s,x,f^4?a:b.set):(_,x)=>_[n]=x)),i=(0,r[w])(f?f<4?d?a:b[g]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?tr(i)&&(f>4?v.unshift(i):f?d?a=i:b[g]=i:s=i):typeof i!="object"||i===null?Hn("Object expected"):(tr(o=i.get)&&(b.get=o),tr(o=i.set)&&(b.set=o),tr(o=i.init)&&v.unshift(o));return f||mn(e,s),b&&So(s,n,b),d?f^4?a:b:s},ko=(e,t,n)=>t.has(e)||Hn("Cannot "+n),rp=(e,t)=>Object(t)!==t?Hn('Cannot use the "in" operator on this value'):e.has(t),Ze=(e,t,n)=>(ko(e,t,"read from private field"),n?n.call(e):t.get(e)),we=(e,t,n)=>t.has(e)?Hn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),wt=(e,t,n,r)=>(ko(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),sp=(e,t,n)=>(ko(e,t,"access private method"),n);function Yc(e,t){return{plugin:e,options:t}}function gn(e){return t=>Yc(e,t)}function Eo(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Kc,br,Io,ls;Kc=[ge];var dt=class{constructor(e,t){this.manager=e,this.options=t,we(this,Io,se(br,8,this,!1)),se(br,11,this),we(this,ls,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return _e(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=Ct(e.bind(this));return Ze(this,ls).add(t),t}destroy(){Ze(this,ls).forEach(e=>e())}static configure(e){return Yc(this,e)}};br=Gn(null);Io=new WeakMap;ls=new WeakMap;he(br,4,"disabled",Kc,dt,Io);mn(br,dt);var Rr=class extends dt{},cs,ga=class{constructor(e){this.manager=e,this.instances=new Map,we(this,cs,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(Eo).reduceRight((r,s)=>r.some(({plugin:a})=>a===s.plugin)?r:[s,...r],[]),n=t.map(({plugin:r})=>r);for(const r of Ze(this,cs))if(!n.includes(r)){if(r.prototype instanceof Rr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);wt(this,cs,n)}get(e){return this.instances.get(e)}register(e,t){const n=this.instances.get(e);if(n)return n.options!==t&&(n.options=t),n;const r=new e(this.manager,t);return this.instances.set(e,r),r}unregister(e){const t=this.instances.get(e);t&&(t.destroy(),this.instances.delete(e))}destroy(){for(const e of this.instances.values())e.destroy();this.instances.clear()}};cs=new WeakMap;function ap(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var es=[],En,In,op=class extends dt{constructor(e){super(e),we(this,En),we(this,In),this.computeCollisions=this.computeCollisions.bind(this),wt(this,In,Mr(es)),this.destroy=Ar(()=>{const t=this.computeCollisions(),n=_e(()=>this.manager.dragOperation.position.current);if(t!==es){const r=Ze(this,En);if(wt(this,En,n),r&&n.x==r.x&&n.y==r.y)return}else wt(this,En,void 0);Ze(this,In).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){_e(()=>{e?Ze(this,In).value=this.computeCollisions():wt(this,En,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:a,status:o}=r;if(!o.initialized||!a)return es;const i=[],l=[];for(const c of e??n.droppables){if(c.disabled||s&&!c.accepts(s))continue;const u=t??c.collisionDetector;if(!u)continue;l.push(c),c.shape;const f=_e(()=>u({droppable:c,dragOperation:r}));f&&(c.collisionPriority!=null&&(f.priority=c.collisionPriority),i.push(f))}return l.length===0?es:(i.sort(ap),i)}get collisions(){return Ze(this,In).value}};En=new WeakMap;In=new WeakMap;var ip=class{constructor(){this.registry=new Map}addEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));return r.add(t),n.set(e,r),()=>this.removeEventListener(e,t)}removeEventListener(e,t){const{registry:n}=this,r=new Set(n.get(e));r.delete(t),n.set(e,r)}dispatch(e,...t){const{registry:n}=this,r=n.get(e);if(r)for(const s of r)s(...t)}},lp=class extends ip{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function us(e,t=!0){let n=!1;return Gc(Hc({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var cp=class extends Rr{constructor(e){super(e);const t=(r,s)=>r.map(({id:a})=>a).join("")===s.map(({id:a})=>a).join("");let n=[];this.destroy=Ar(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:a}=r;if(r.isDisabled())return;const o=us({collisions:a});if(s.dispatch("collision",o),o.defaultPrevented||t(a,n))return;n=a;const[i]=a;_e(()=>{var l;i?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(i?.id).then(()=>{r.enable()}))})})}},Mo=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(Mo||{}),Ao=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Ao||{}),qc,Jc,Qc,eu,tu,nu,ru,xt,To;ru=[ge],nu=[$e],tu=[$e],eu=[$e],Qc=[$e],Jc=[$e],qc=[$e];var Wt=class{constructor(){se(xt,5,this),we(this,To,se(xt,8,this,"idle")),se(xt,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){const{value:e}=this;return e!=="idle"&&e!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(e){this.value=e}};xt=Gn(null);To=new WeakMap;he(xt,4,"value",ru,Wt,To);he(xt,2,"current",nu,Wt);he(xt,2,"idle",tu,Wt);he(xt,2,"initializing",eu,Wt);he(xt,2,"initialized",Qc,Wt);he(xt,2,"dragging",Jc,Wt);he(xt,2,"dropped",qc,Wt);mn(xt,Wt);var up=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return _e(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=us({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return _e(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:a}=e;Xt(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(a)});const o=us({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:i}=t;i.current==="initializing"&&(t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1}))}),r)})}move(e){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:a}=r;if(!s.dragging||!a||a.signal.aborted)return;const o=us({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var i,l,c,u,f;if(o.defaultPrevented)return;const m=(f=e.to)!=null?f:{x:r.position.current.x+((l=(i=e.by)==null?void 0:i.x)!=null?l:0),y:r.position.current.y+((u=(c=e.by)==null?void 0:c.y)!=null?u:0)};r.position.current=m})})}stop(e={}){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let a;const o=()=>{const l={resume:()=>{},abort:()=>{}};return a=new Promise((c,u)=>{l.resume=c,l.abort=u}),l};s.abort();const i=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=_e(()=>{var u;return((u=r.source)==null?void 0:u.status)==="dropping"}),c=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:u}=r,f=Ct(()=>{u?.status==="idle"&&(f(),c())})}else this.manager.renderer.rendering.then(c)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),a?a.then(i).catch(()=>r.reset()):i()})}},su,au,ou,iu,ut,$o,Ro,Do,Po;iu=[ge],ou=[ge],au=[ge],su=[ge];var qt=class{constructor(e,t){we(this,$o,se(ut,8,this)),se(ut,11,this),we(this,Ro,se(ut,12,this)),se(ut,15,this),we(this,Do,se(ut,16,this)),se(ut,19,this),we(this,Po,se(ut,20,this)),se(ut,23,this);const{effects:n,id:r,data:s={},disabled:a=!1,register:o=!0}=e;let i=r;this.manager=t,this.id=r,this.data=s,this.disabled=a,this.effects=()=>{var l;return[()=>{const{id:c,manager:u}=this;if(c!==i)return u?.registry.register(this),()=>u?.registry.unregister(this)},...(l=n?.())!=null?l:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),t&&o&&queueMicrotask(this.register)}register(){var e;return(e=this.manager)==null?void 0:e.registry.register(this)}unregister(){var e;(e=this.manager)==null||e.registry.unregister(this)}destroy(){var e;(e=this.manager)==null||e.registry.unregister(this)}};ut=Gn(null);$o=new WeakMap;Ro=new WeakMap;Do=new WeakMap;Po=new WeakMap;he(ut,4,"manager",iu,qt,$o);he(ut,4,"id",ou,qt,Ro);he(ut,4,"data",au,qt,Do);he(ut,4,"disabled",su,qt,Po);mn(ut,qt);var Cl=class{constructor(){this.map=Mr(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r){const i=this.cleanupFunctions.get(r);i?.(),this.cleanupFunctions.delete(r)}const a=new Map(n);a.set(e,t),this.map.value=a;const o=Ar(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},lu,cu,uu,du,fu,hu,za,rt,Fo,Oo,Lo,$t=class extends(za=qt,hu=[ge],fu=[ge],du=[ge],uu=[$e],cu=[$e],lu=[$e],za){constructor(t,n){var r=t,{modifiers:s,type:a,sensors:o}=r,i=Uc(r,["modifiers","type","sensors"]);super(i,n),se(rt,5,this),we(this,Fo,se(rt,8,this)),se(rt,11,this),we(this,Oo,se(rt,12,this)),se(rt,15,this),we(this,Lo,se(rt,16,this,this.isDragSource?"dragging":"idle")),se(rt,19,this),this.type=a,this.sensors=o,this.modifiers=s,this.alignment=i.alignment}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};rt=Gn(za);Fo=new WeakMap;Oo=new WeakMap;Lo=new WeakMap;he(rt,4,"type",hu,$t,Fo);he(rt,4,"modifiers",fu,$t,Oo);he(rt,4,"status",du,$t,Lo);he(rt,2,"isDropping",uu,$t);he(rt,2,"isDragging",cu,$t);he(rt,2,"isDragSource",lu,$t);mn(rt,$t);var pu,mu,gu,vu,yu,bu,ja,Ve,Bo,Wo,Vo,No,zo,Rt=class extends(ja=qt,bu=[ge],yu=[ge],vu=[ge],gu=[ge],mu=[ge],pu=[$e],ja){constructor(t,n){var r=t,{accept:s,collisionDetector:a,collisionPriority:o,type:i}=r,l=Uc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),se(Ve,5,this),we(this,Bo,se(Ve,8,this)),se(Ve,11,this),we(this,Wo,se(Ve,12,this)),se(Ve,15,this),we(this,Vo,se(Ve,16,this)),se(Ve,19,this),we(this,No,se(Ve,20,this)),se(Ve,23,this),we(this,zo,se(Ve,24,this)),se(Ve,27,this),this.accept=s,this.collisionDetector=a,this.collisionPriority=o,this.type=i}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Ve=Gn(ja);Bo=new WeakMap;Wo=new WeakMap;Vo=new WeakMap;No=new WeakMap;zo=new WeakMap;he(Ve,4,"accept",bu,Rt,Bo);he(Ve,4,"type",yu,Rt,Wo);he(Ve,4,"collisionDetector",vu,Rt,Vo);he(Ve,4,"collisionPriority",gu,Rt,No);he(Ve,4,"shape",mu,Rt,zo);he(Ve,2,"isDropTarget",pu,Rt);mn(Ve,Rt);var Fn=class extends dt{constructor(e,t){super(e,t),this.manager=e,this.options=t}},dp=class extends AbortController{constructor(e,t){super(),this.constraints=e,this.onActivate=t,this.activated=!1;for(const n of e??[])n.controller=this}onEvent(e){var t;if(!this.activated)if((t=this.constraints)!=null&&t.length)for(const n of this.constraints)n.onEvent(e);else this.activate(e)}activate(e){this.activated||(this.activated=!0,this.onActivate(e))}abort(e){this.activated=!1,super.abort(e)}},ds,wu=class{constructor(e){this.options=e,we(this,ds)}set controller(e){wt(this,ds,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=Ze(this,ds))==null||t.activate(e)}};ds=new WeakMap;var On=class extends dt{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},fp=class{constructor(e){this.draggables=new Cl,this.droppables=new Cl,this.plugins=new ga(e),this.sensors=new ga(e),this.modifiers=new ga(e)}register(e,t){if(e instanceof $t)return this.draggables.register(e.id,e);if(e instanceof Rt)return this.droppables.register(e.id,e);if(e.prototype instanceof On)return this.modifiers.register(e,t);if(e.prototype instanceof Fn)return this.sensors.register(e,t);if(e.prototype instanceof dt)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof qt)return e instanceof $t?this.draggables.unregister(e.id,e):e instanceof Rt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof On)return this.modifiers.unregister(e);if(e.prototype instanceof Fn)return this.sensors.unregister(e);if(e.prototype instanceof dt)return this.plugins.unregister(e);throw new Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},_u,xu,Cu,Su,ku,Eu,Iu,Mu,Au,nr,fs,Mn,Re,jo,Zo,Ho,Go,Uo,rr;Au=[$e],Mu=[ge],Iu=[ge],Eu=[ge],ku=[ge],Su=[ge],Cu=[$e],xu=[$e],_u=[$e];var It=class{constructor(e){se(Re,5,this),we(this,nr),we(this,fs),we(this,Mn,new Kt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new Wt,we(this,jo,se(Re,8,this,!1)),se(Re,11,this),we(this,Zo,se(Re,12,this,null)),se(Re,15,this),we(this,Ho,se(Re,16,this,null)),se(Re,19,this),we(this,Go,se(Re,20,this,null)),se(Re,23,this),we(this,Uo,se(Re,24,this,[])),se(Re,27,this),this.position=new js({x:0,y:0}),we(this,rr,{x:0,y:0}),wt(this,nr,e)}get shape(){const{current:e,initial:t,previous:n}=Ze(this,Mn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?Ze(this,Mn).current=e:Ze(this,Mn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=Ze(this,nr).registry.draggables.get(t);return n&&wt(this,fs,n),(e=n??Ze(this,fs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=Ze(this,nr).registry.droppables.get(t))!=null?e:null}get transform(){const{x:e,y:t}=this.position.delta;let n={x:e,y:t};for(const r of this.modifiers)n=r.apply(Gc(Hc({},this.snapshot()),{transform:n}));return wt(this,rr,n),n}snapshot(){return _e(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:Ze(this,rr),shape:this.shape?ma(this.shape):null,position:ma(this.position),status:ma(this.status),canceled:this.canceled}))}reset(){Xt(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,Ze(this,Mn).reset(),this.position.reset({x:0,y:0}),wt(this,rr,{x:0,y:0}),this.modifiers=[]})}};Re=Gn(null);nr=new WeakMap;fs=new WeakMap;Mn=new WeakMap;jo=new WeakMap;Zo=new WeakMap;Ho=new WeakMap;Go=new WeakMap;Uo=new WeakMap;rr=new WeakMap;he(Re,2,"shape",Au,It);he(Re,4,"canceled",Mu,It,jo);he(Re,4,"activatorEvent",Iu,It,Zo);he(Re,4,"sourceIdentifier",Eu,It,Ho);he(Re,4,"targetIdentifier",ku,It,Go);he(Re,4,"modifiers",Su,It,Uo);he(Re,2,"source",Cu,It);he(Re,2,"target",xu,It);he(Re,2,"transform",_u,It);mn(Re,It);var hp={get rendering(){return Promise.resolve()}};function Ot(e,t){return typeof e=="function"?e(t):e??t}var pp=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(m=>m.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=Ot(r.plugins,[]),a=Ot(r.sensors,[]),o=Ot(r.modifiers,[]),i=(n=r.renderer)!=null?n:hp,l=new lp(this),c=new fp(this);this.registry=c,this.monitor=l,this.renderer=i,this.actions=new up(this),this.dragOperation=new It(this),this.collisionObserver=new op(this),this.plugins=[cp,...s],this.modifiers=o,this.sensors=a;const{destroy:u}=this,f=Ar(()=>{var m,d,h;const g=_e(()=>this.dragOperation.modifiers),v=this.modifiers;for(const y of g)v.includes(y)||y.destroy();this.dragOperation.modifiers=(h=(d=(m=this.dragOperation.source)==null?void 0:m.modifiers)==null?void 0:d.map(y=>{const{plugin:b,options:w}=Eo(y);return new b(this,w)}))!=null?h:v});this.destroy=()=>{f(),u()}}get plugins(){return this.registry.plugins.values}set plugins(t){this.registry.plugins.values=t}get modifiers(){return this.registry.modifiers.values}set modifiers(t){this.registry.modifiers.values=t}get sensors(){return this.registry.sensors.values}set sensors(t){this.registry.sensors.values=t}},Tu=e=>{throw TypeError(e)},Xo=(e,t,n)=>t.has(e)||Tu("Cannot "+n),ie=(e,t,n)=>(Xo(e,t,"read from private field"),t.get(e)),ct=(e,t,n)=>t.has(e)?Tu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),mt=(e,t,n,r)=>(Xo(e,t,"write to private field"),t.set(e,n),n),$u=(e,t,n)=>(Xo(e,t,"access private method"),n);function Zs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function mp(e,t){const n=e.getAnimations();if(n.length>0)for(const r of n){if(r.playState!=="running")continue;const{effect:s}=r,o=(Zs(s)?s.getKeyframes():[]).filter(t);if(o.length>0)return[o[o.length-1],r]}return null}function Hs(e){const{width:t,height:n,top:r,left:s,bottom:a,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:a,right:o}}function Yo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Dr(e){return"nodeType"in e}function St(e){var t,n,r;return e?Yo(e)?e:Dr(e)?"defaultView"in e?(t=e.defaultView)!=null?t:window:(r=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?r:window:window:window}function Ko(e){const{Document:t}=St(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function dn(e){return!e||Yo(e)?!1:e instanceof St(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function Ru(e){return e instanceof St(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function vn(e){return e?Yo(e)?e.document:Dr(e)?Ko(e)?e:dn(e)||Ru(e)?e.ownerDocument:document:document:document}function gp(e){var t,n,r,s;const{documentElement:a}=vn(e),o=St(e).visualViewport,i=(t=o?.width)!=null?t:a.clientWidth,l=(n=o?.height)!=null?n:a.clientHeight,c=(r=o?.offsetTop)!=null?r:0,u=(s=o?.offsetLeft)!=null?s:0;return{top:c,left:u,right:u+i,bottom:c+l,width:i,height:l}}function vp(e,t){if(yp(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function yp(e){return e.tagName==="DETAILS"}function Cs(e,t=e.getBoundingClientRect(),n=0){var r,s,a,o,i;let l=t;const{ownerDocument:c}=e,u=(r=c.defaultView)!=null?r:window;let f=e.parentElement;for(;f&&f!==c.documentElement;){if(!vp(f)){const w=f.getBoundingClientRect(),_=n*(w.bottom-w.top),x=n*(w.right-w.left),S=n*(w.bottom-w.top),k=n*(w.right-w.left);l={top:Math.max(l.top,w.top-_),right:Math.min(l.right,w.right+x),bottom:Math.min(l.bottom,w.bottom+S),left:Math.max(l.left,w.left-k),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}f=f.parentElement}const m=u.visualViewport,d=(s=m?.offsetTop)!=null?s:0,h=(a=m?.offsetLeft)!=null?a:0,g=(o=m?.width)!=null?o:u.innerWidth,v=(i=m?.height)!=null?i:u.innerHeight,y=n*v,b=n*g;return l={top:Math.max(l.top,d-y),right:Math.min(l.right,h+g+b),bottom:Math.min(l.bottom,d+v+y),left:Math.max(l.left,h-b),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top,l.width<0&&(l.width=0),l.height<0&&(l.height=0),l}function Ln(e){return{x:e.clientX,y:e.clientY}}var Du=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Za(e=document,t=new Set){if(t.has(e))return[];t.add(e);const n=[e];for(const r of Array.from(e.querySelectorAll("iframe, frame")))try{const s=r.contentDocument;s&&!t.has(s)&&n.push(...Za(s,t))}catch{}try{const r=e.defaultView;if(r&&r!==window.top){const s=r.parent;s&&s.document&&s.document!==e&&n.push(...Za(s.document,t))}}catch{}return n}function qo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function Pu(){var e,t;const n=qo()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Jo(e){return!e||!Dr(e)?!1:e instanceof St(e).ShadowRoot}function Ss(e){if(e&&Dr(e)){let t=e.getRootNode();if(Jo(t))return t;if(t instanceof Document)return t}return vn(e)}function Fu(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function bp(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((a,o)=>{const i=r[o];if(Sl(a)&&Sl(i)&&(a.type!=="file"&&(a.value=i.value),a.type==="radio"&&a.name&&(a.name=`Cloned__${a.name}`)),kl(a)&&kl(i)&&i.width>0&&i.height>0){const l=a.getContext("2d");l?.drawImage(i,0,0)}}),n}function Sl(e){return"value"in e}function kl(e){return e.tagName==="CANVAS"}function Ou(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(wp(r)){const{contentDocument:s}=r;if(s){const{left:a,top:o}=r.getBoundingClientRect();return Ou(s,{x:t-a,y:n-o})}}return r}function wp(e){return e?.tagName==="IFRAME"}var El=new WeakMap;function _p(e){return!!e.closest(`
2
2
  input:not([disabled]),
3
3
  select:not([disabled]),
4
4
  textarea:not([disabled]),