@waveform-playlist/browser 9.1.0 → 9.1.2

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,11 +1,11 @@
1
- "use strict";var If=Object.create;var Yi=Object.defineProperty;var Mf=Object.getOwnPropertyDescriptor;var Af=Object.getOwnPropertyNames;var Tf=Object.getPrototypeOf,$f=Object.prototype.hasOwnProperty;var Rf=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Af(t))!$f.call(e,s)&&s!==n&&Yi(e,s,{get:()=>t[s],enumerable:!(r=Mf(t,s))||r.enumerable});return e};var Df=(e,t,n)=>(n=e!=null?If(Tf(e)):{},Rf(t||!e||!e.__esModule?Yi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("tone"),C=require("react/jsx-runtime"),g=require("react"),P=require("styled-components"),da=require("react-dom");function Kl(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 ql=Kl(F),D=Kl(g);var oo={exports:{}},Ki;function Pf(){return Ki||(Ki=1,(function(e,t){(function(n,r){e.exports=r()})(window,(function(){return(function(n){var r={};function s(o){if(r[o])return r[o].exports;var a=r[o]={i:o,l:!1,exports:{}};return n[o].call(a.exports,a,a.exports,s),a.l=!0,a.exports}return s.m=n,s.c=r,s.d=function(o,a,i){s.o(o,a)||Object.defineProperty(o,a,{enumerable:!0,get:i})},s.r=function(o){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})},s.t=function(o,a){if(1&a&&(o=s(o)),8&a||4&a&&typeof o=="object"&&o&&o.__esModule)return o;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:o}),2&a&&typeof o!="string")for(var l in o)s.d(i,l,(function(c){return o[c]}).bind(null,l));return i},s.n=function(o){var a=o&&o.__esModule?function(){return o.default}:function(){return o};return s.d(a,"a",a),a},s.o=function(o,a){return Object.prototype.hasOwnProperty.call(o,a)},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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=s("./src/chunks/index.ts");function l(p){return(l=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(v){return typeof v}:function(v){return v&&typeof Symbol=="function"&&v.constructor===Symbol&&v!==Symbol.prototype?"symbol":typeof v})(p)}function c(p,v){for(var y=0;y<v.length;y++){var m=v[y];m.enumerable=m.enumerable||!1,m.configurable=!0,"value"in m&&(m.writable=!0),Object.defineProperty(p,m.key,m)}}function u(p){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(v){return v.__proto__||Object.getPrototypeOf(v)})(p)}function f(p,v){return(f=Object.setPrototypeOf||function(y,m){return y.__proto__=m,y})(p,v)}function h(p){if(p===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return p}var d=(function(p){function v(b){var _,w,x,S,k,E;return(function(T,I){if(!(T instanceof I))throw new TypeError("Cannot call a class as a function")})(this,v),w=this,_=!(x=u(v).call(this,b.id,b.length,b.buffer,b.subChunks))||l(x)!=="object"&&typeof x!="function"?h(w):x,S=h(h(_)),E=void 0,(k="subChunks")in S?Object.defineProperty(S,k,{value:E,enumerable:!0,configurable:!0,writable:!0}):S[k]=E,_.subChunks=b.subChunks.map((function(T){return new v(T)})),_}var y,m;return(function(b,_){if(typeof _!="function"&&_!==null)throw new TypeError("Super expression must either be null or a function");b.prototype=Object.create(_&&_.prototype,{constructor:{value:b,writable:!0,configurable:!0}}),_&&f(b,_)})(v,p),y=v,(m=[{key:"getMetaData",value:function(){if(this.id!=="LIST")throw new o.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks.reduce((function(_,w){if(w.id==="ifil"||w.id==="iver"){if(w.length!==a.SF_VERSION_LENGTH)throw new o.ParseError("Invalid size for the '".concat(w.id,"' sub-chunk"));_[w.id]="".concat(w.getInt16(),".").concat(w.getInt16(2))}else _[w.id]=w.getString();return _}),{});if(!b.ifil)throw new o.ParseError("Missing required 'ifil' sub-chunk");if(!b.INAM)throw new o.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 o.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks[0];if(b.id!=="smpl")throw new o.ParseError("Invalid chunk signature","'smpl'","'".concat(b.id,"'"));return b.buffer}},{key:"getPresetData",value:function(){if(this.id!=="LIST")throw new o.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(y.prototype,m),v})(o.RIFFChunk)},"./src/chunks/generators.ts":function(n,r,s){s.r(r),s.d(r,"getGenerators",(function(){return f}));var o=s("./src/riff/index.ts"),a=s("./src/types/index.ts"),i=s("./src/constants.ts"),l=[a.GeneratorType.StartAddrsOffset,a.GeneratorType.EndAddrsOffset,a.GeneratorType.StartLoopAddrsOffset,a.GeneratorType.EndLoopAddrsOffset,a.GeneratorType.StartAddrsCoarseOffset,a.GeneratorType.EndAddrsCoarseOffset,a.GeneratorType.StartLoopAddrsCoarseOffset,a.GeneratorType.KeyNum,a.GeneratorType.Velocity,a.GeneratorType.EndLoopAddrsCoarseOffset,a.GeneratorType.SampleModes,a.GeneratorType.ExclusiveClass,a.GeneratorType.OverridingRootKey],c=[a.GeneratorType.Unused1,a.GeneratorType.Unused2,a.GeneratorType.Unused3,a.GeneratorType.Unused4,a.GeneratorType.Reserved1,a.GeneratorType.Reserved2,a.GeneratorType.Reserved3],u=[a.GeneratorType.KeyRange,a.GeneratorType.VelRange],f=function(h,d){if(h.id!==d)throw new o.ParseError("Unexpected chunk ID","'".concat(d,"'"),"'".concat(h.id,"'"));if(h.length%i.SF_GENERATOR_SIZE)throw new o.ParseError("Invalid size for the '".concat(d,"' sub-chunk"));return h.iterate((function(p){var v=p.getInt16();return a.GeneratorType[v]?d==="pgen"&&l.includes(v)||d==="igen"&&c.includes(v)?null:u.includes(v)?{id:v,range:{lo:p.getByte(),hi:p.getByte()}}:{id:v,value:p.getInt16BE()}:null}))}},"./src/chunks/index.ts":function(n,r,s){s.r(r);var o=s("./src/chunks/instruments/index.ts");s.d(r,"getInstrumentHeaders",(function(){return o.getInstrumentHeaders}));var a=s("./src/chunks/presets/index.ts");s.d(r,"getPresetHeaders",(function(){return a.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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=function(l){if(l.id!=="inst")throw new o.ParseError("Unexpected chunk ID","'inst'","'".concat(l.id,"'"));if(l.length%a.SF_INSTRUMENT_HEADER_SIZE)throw new o.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 o=s("./src/chunks/instruments/headers.ts");s.d(r,"getInstrumentHeaders",(function(){return o.getInstrumentHeaders}))},"./src/chunks/modulators.ts":function(n,r,s){s.r(r),s.d(r,"getModulators",(function(){return l}));var o=s("./src/riff/index.ts"),a=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 o.ParseError("Unexpected chunk ID","'".concat(u,"'"),"'".concat(c.id,"'"));if(c.length%a.SF_MODULATOR_SIZE)throw new o.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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=function(l){if(l.id!=="phdr")throw new o.ParseError("Invalid chunk ID","'phdr'","'".concat(l.id,"'"));if(l.length%a.SF_PRESET_HEADER_SIZE)throw new o.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 o=s("./src/chunks/presets/headers.ts");s.d(r,"getPresetHeaders",(function(){return o.getPresetHeaders}))},"./src/chunks/samples/headers.ts":function(n,r,s){s.r(r),s.d(r,"getSampleHeaders",(function(){return i}));var o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=function(l){if(l.id!=="shdr")throw new o.ParseError("Unexpected chunk ID","'shdr'","'".concat(l.id,"'"));if(l.length%a.SF_SAMPLE_HEADER_SIZE)throw new o.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 o=s("./src/chunks/samples/headers.ts");s.d(r,"getSampleHeaders",(function(){return o.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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=s("./src/types/index.ts"),l=function(d,p){if(d.id!==p)throw new o.ParseError("Unexpected chunk ID","'".concat(p,"'"),"'".concat(d.id,"'"));if(d.length%a.SF_BAG_SIZE)throw new o.ParseError("Invalid size for the '".concat(p,"' sub-chunk"));return d.iterate((function(v){return{generatorIndex:v.getInt16(),modulatorIndex:v.getInt16()}}))},c=function(d,p,v,y,m,b){for(var _=[],w=0;w<d.length;w++){for(var x=d[w],S=d[w+1],k=x.bagIndex,E=S?S.bagIndex:p.length,T=[],I=void 0,M=k;M<E;M++){var $=u(M,p,v),A=f(M,p,y),R=A[i.GeneratorType.KeyRange]&&A[i.GeneratorType.KeyRange].range,W=A[b];if(W){var q=m[W.value];q&&T.push({keyRange:R,modulators:$,generators:A,reference:q})}else M-k==0&&(I={keyRange:R,modulators:$,generators:A})}_.push({header:x,globalZone:I,zones:T})}return _},u=function(d,p,v){var y=p[d],m=p[d+1],b=y.modulatorIndex,_=m?m.modulatorIndex:p.length;return h(b,_,v)},f=function(d,p,v){var y=p[d],m=p[d+1],b=y.generatorIndex,_=m?m.generatorIndex:p.length;return h(b,_,v)},h=function(d,p,v){for(var y={},m=d;m<p;m++){var b=v[m];b&&(y[b.id]=b)}return y}},"./src/constants.ts":function(n,r,s){s.r(r),s.d(r,"SF_VERSION_LENGTH",(function(){return o})),s.d(r,"SF_PRESET_HEADER_SIZE",(function(){return a})),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 h}));var o=4,a=38,i=4,l=10,c=4,u=22,f=46,h=22050},"./src/index.ts":function(n,r,s){s.r(r);var o=s("./src/types/index.ts");for(var a in o)["default"].indexOf(a)<0&&(function(u){s.d(r,u,(function(){return o[u]}))})(a);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 o=s("./src/utils/index.ts");function a(u,f){if(!(u instanceof f))throw new TypeError("Cannot call a class as a function")}function i(u,f){for(var h=0;h<f.length;h++){var d=f[h];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,h){return f in u?Object.defineProperty(u,f,{value:h,enumerable:!0,configurable:!0,writable:!0}):u[f]=h,u}var c=(function(){function u(d){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;a(this,u),l(this,"target",[]),l(this,"chunk",void 0),l(this,"position",0),this.chunk=d,this.position=p}var f,h;return f=u,(h=[{key:"iterate",value:function(d){for(;this.position<this.chunk.length;){var p=d(this);p&&this.target.push(p)}}},{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:20,p=Object(o.getStringFromBuffer)(this.getBuffer(this.position,d));return this.position+=d,p}},{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,p){return this.chunk.buffer.subarray(d,d+p)}},{key:"currentPosition",get:function(){return this.position}}])&&i(f.prototype,h),u})()},"./src/riff/index.ts":function(n,r,s){s.r(r);var o=s("./src/riff/chunkIterator.ts");s.d(r,"ChunkIterator",(function(){return o.ChunkIterator}));var a=s("./src/riff/parseError.ts");s.d(r,"ParseError",(function(){return a.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 o(d){return(o=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(p){return typeof p}:function(p){return p&&typeof Symbol=="function"&&p.constructor===Symbol&&p!==Symbol.prototype?"symbol":typeof p})(d)}function a(d,p){return!p||o(p)!=="object"&&typeof p!="function"?(function(v){if(v===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return v})(d):p}function i(d){var p=typeof Map=="function"?new Map:void 0;return(i=function(v){if(v===null||(y=v,Function.toString.call(y).indexOf("[native code]")===-1))return v;var y;if(typeof v!="function")throw new TypeError("Super expression must either be null or a function");if(p!==void 0){if(p.has(v))return p.get(v);p.set(v,m)}function m(){return c(v,arguments,f(this).constructor)}return m.prototype=Object.create(v.prototype,{constructor:{value:m,enumerable:!1,writable:!0,configurable:!0}}),u(m,v)})(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,p,v){return(c=l()?Reflect.construct:function(y,m,b){var _=[null];_.push.apply(_,m);var w=new(Function.bind.apply(y,_));return b&&u(w,b.prototype),w}).apply(null,arguments)}function u(d,p){return(u=Object.setPrototypeOf||function(v,y){return v.__proto__=y,v})(d,p)}function f(d){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(p){return p.__proto__||Object.getPrototypeOf(p)})(d)}s.r(r),s.d(r,"ParseError",(function(){return h}));var h=(function(d){function p(v,y,m){return(function(b,_){if(!(b instanceof _))throw new TypeError("Cannot call a class as a function")})(this,p),a(this,f(p).call(this,"".concat(v).concat(y&&m?", expected ".concat(y,", received ").concat(m):"")))}return(function(v,y){if(typeof y!="function"&&y!==null)throw new TypeError("Super expression must either be null or a function");v.prototype=Object.create(y&&y.prototype,{constructor:{value:v,writable:!0,configurable:!0}}),y&&u(v,y)})(p,d),p})(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 h}));var o=s("./src/riff/parseError.ts"),a=s("./src/utils/buffer.ts"),i=s("./src/riff/riffChunk.ts"),l=function(d){var p=h(d);if(p!=="RIFF")throw new o.ParseError("Invalid file format","RIFF",p);var v=h(d,8);if(v!=="sfbk")throw new o.ParseError("Invalid signature","sfbk",v);var y=d.subarray(8),m=f(y.subarray(4));return new i.RIFFChunk(p,y.length,y,m)},c=function(d,p){var v=h(d,p),y=u(d,p+4),m=[];return v!=="RIFF"&&v!=="LIST"||(m=f(d.subarray(p+12))),new i.RIFFChunk(v,y,d.subarray(p+8),m)},u=function(d,p){return((d=d.subarray(p,p+4))[0]|d[1]<<8|d[2]<<16|d[3]<<24)>>>0},f=function(d){for(var p=[],v=0;v<=d.length-8;){var y=c(d,v);p.push(y),v=(v+=8+y.length)%2?v+1:v}return p},h=function(d){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;return Object(a.getStringFromBuffer)(d.subarray(p,p+4))}},"./src/riff/riffChunk.ts":function(n,r,s){s.r(r),s.d(r,"RIFFChunk",(function(){return c}));var o=s("./src/riff/chunkIterator.ts"),a=s("./src/utils/index.ts");function i(u,f){for(var h=0;h<f.length;h++){var d=f[h];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,h){return f in u?Object.defineProperty(u,f,{value:h,enumerable:!0,configurable:!0,writable:!0}):u[f]=h,u}var c=(function(){function u(d,p,v,y){(function(m,b){if(!(m 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=p,this.buffer=v,this.subChunks=y}var f,h;return f=u,(h=[{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,p=arguments.length>1?arguments[1]:void 0;return Object(a.getStringFromBuffer)(this.getBuffer(d,p||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 o.ChunkIterator(this,d)}},{key:"iterate",value:function(d){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,v=new o.ChunkIterator(this,p);return v.iterate(d),v.target}},{key:"getBuffer",value:function(d,p){return this.buffer.subarray(d,d+p)}}])&&i(f.prototype,h),u})()},"./src/soundFont2.ts":function(n,r,s){s.r(r),s.d(r,"SoundFont2",(function(){return p}));var o=s("./src/types/index.ts"),a=s("./src/chunk.ts"),i=s("./src/riff/index.ts"),l=s("./src/chunks/index.ts"),c=s("./src/utils/index.ts");function u(v){for(var y=1;y<arguments.length;y++){var m=arguments[y]!=null?arguments[y]:{},b=Object.keys(m);typeof Object.getOwnPropertySymbols=="function"&&(b=b.concat(Object.getOwnPropertySymbols(m).filter((function(_){return Object.getOwnPropertyDescriptor(m,_).enumerable})))),b.forEach((function(_){d(v,_,m[_])}))}return v}function f(v,y){for(var m=0;m<y.length;m++){var b=y[m];b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(v,b.key,b)}}function h(v,y,m){return y&&f(v.prototype,y),m&&f(v,m),v}function d(v,y,m){return y in v?Object.defineProperty(v,y,{value:m,enumerable:!0,configurable:!0,writable:!0}):v[y]=m,v}var p=(function(){function v(y){if((function(b,_){if(!(b instanceof _))throw new TypeError("Cannot call a class as a function")})(this,v),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),!(y instanceof a.SF2Chunk)){var m=Object(i.parseBuffer)(y);y=new a.SF2Chunk(m)}if(y.subChunks.length!==3)throw new i.ParseError("Invalid sfbk structure","3 chunks","".concat(y.subChunks.length," chunks"));this.chunk=y,this.metaData=y.subChunks[0].getMetaData(),this.sampleData=y.subChunks[1].getSampleData(),this.presetData=y.subChunks[2].getPresetData(),this.samples=this.getSamples(),this.instruments=this.getInstruments(),this.presets=this.getPresets(),this.banks=this.getBanks()}return h(v,null,[{key:"from",value:function(y){return new v(y)}}]),h(v,[{key:"getKeyData",value:function(y){var m=this,b=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,_=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;return Object(c.memoize)((function(w,x,S){var k=m.banks[x];if(k){var E=k.presets[S];if(E){var T=E.zones.filter((function(N){return m.isKeyInRange(N,w)}));if(T.length>0){var I=!0,M=!1,$=void 0;try{for(var A,R=T[Symbol.iterator]();!(I=(A=R.next()).done);I=!0){var W=A.value,q=W.instrument,z=q.zones.filter((function(N){return m.isKeyInRange(N,w)}));if(z.length>0){var J=!0,ee=!1,j=void 0;try{for(var se,U=z[Symbol.iterator]();!(J=(se=U.next()).done);J=!0){var ie=se.value,le=ie.sample,ge=u({},W.generators,ie.generators),Se=u({},W.modulators,ie.modulators);return{keyNumber:w,preset:E,instrument:q,sample:le,generators:ge,modulators:Se}}}catch(N){ee=!0,j=N}finally{try{J||U.return==null||U.return()}finally{if(ee)throw j}}}}}catch(N){M=!0,$=N}finally{try{I||R.return==null||R.return()}finally{if(M)throw $}}}}}return null}))(y,b,_)}},{key:"isKeyInRange",value:function(y,m){return y.keyRange===void 0||y.keyRange.lo<=m&&y.keyRange.hi>=m}},{key:"getBanks",value:function(){return this.presets.reduce((function(y,m){var b=m.header.bank;return y[b]||(y[b]={presets:[]}),y[b].presets[m.header.preset]=m,y}),[])}},{key:"getPresets",value:function(){var y=this.presetData,m=y.presetHeaders,b=y.presetZones,_=y.presetGenerators,w=y.presetModulators;return Object(l.getItemsInZone)(m,b,w,_,this.instruments,o.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 y=this.presetData,m=y.instrumentHeaders,b=y.instrumentZones,_=y.instrumentModulators,w=y.instrumentGenerators;return Object(l.getItemsInZone)(m,b,_,w,this.samples,o.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 y=this;return this.presetData.sampleHeaders.filter((function(m){return m.name!=="EOS"})).map((function(m){if(m.name!=="EOS"&&m.sampleRate<=0)throw new Error("Illegal sample rate of ".concat(m.sampleRate," hz in sample '").concat(m.name,"'"));return m.originalPitch>=128&&m.originalPitch<=254&&(m.originalPitch=60),m.startLoop-=m.start,m.endLoop-=m.start,{header:m,data:new Int16Array(new Uint8Array(y.sampleData.subarray(2*m.start,2*m.end)).buffer)}}))}}]),v})()},"./src/types/bank.ts":function(n,r){},"./src/types/generator.ts":function(n,r,s){var o,a;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 a})),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"})(a||(a={}));var l=(i(o={},a.StartAddrsOffset,0),i(o,a.EndAddrsOffset,0),i(o,a.StartLoopAddrsOffset,0),i(o,a.EndLoopAddrsOffset,0),i(o,a.StartAddrsCoarseOffset,0),i(o,a.ModLFOToPitch,0),i(o,a.VibLFOToPitch,0),i(o,a.ModEnvToPitch,0),i(o,a.InitialFilterFc,13500),i(o,a.InitialFilterQ,0),i(o,a.ModLFOToFilterFc,0),i(o,a.ModEnvToFilterFc,0),i(o,a.EndAddrsCoarseOffset,0),i(o,a.ModLFOToVolume,0),i(o,a.ChorusEffectsSend,0),i(o,a.ReverbEffectsSend,0),i(o,a.Pan,0),i(o,a.DelayModLFO,-12e3),i(o,a.FreqModLFO,0),i(o,a.DelayVibLFO,-12e3),i(o,a.FreqVibLFO,0),i(o,a.DelayModEnv,-12e3),i(o,a.AttackModEnv,-12e3),i(o,a.HoldModEnv,-12e3),i(o,a.DecayModEnv,-12e3),i(o,a.SustainModEnv,0),i(o,a.ReleaseModEnv,-12e3),i(o,a.KeyNumToModEnvHold,0),i(o,a.KeyNumToModEnvDecay,0),i(o,a.DelayVolEnv,-12e3),i(o,a.AttackVolEnv,-12e3),i(o,a.HoldVolEnv,-12e3),i(o,a.DecayVolEnv,-12e3),i(o,a.SustainVolEnv,0),i(o,a.ReleaseVolEnv,-12e3),i(o,a.KeyNumToVolEnvHold,0),i(o,a.KeyNumToVolEnvDecay,0),i(o,a.StartLoopAddrsCoarseOffset,0),i(o,a.KeyNum,-1),i(o,a.Velocity,-1),i(o,a.InitialAttenuation,0),i(o,a.EndLoopAddrsCoarseOffset,0),i(o,a.CoarseTune,0),i(o,a.FineTune,0),i(o,a.SampleModes,0),i(o,a.ScaleTuning,100),i(o,a.ExclusiveClass,0),i(o,a.OverridingRootKey,-1),o)},"./src/types/index.ts":function(n,r,s){s.r(r);var o=s("./src/types/bank.ts");for(var a in o)["default"].indexOf(a)<0&&(function(y){s.d(r,y,(function(){return o[y]}))})(a);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 a in l)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return l[m]}))})(a);var c=s("./src/types/key.ts");for(var a in c)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return c[m]}))})(a);var u=s("./src/types/metaData.ts");for(var a in u)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return u[m]}))})(a);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 h=s("./src/types/preset.ts");for(var a in h)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return h[m]}))})(a);var d=s("./src/types/presetData.ts");for(var a in d)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return d[m]}))})(a);var p=s("./src/types/sample.ts");s.d(r,"SampleType",(function(){return p.SampleType}));var v=s("./src/types/zone.ts");for(var a in v)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS","SampleType"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return v[m]}))})(a)},"./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 o})),s.d(r,"ControllerPolarity",(function(){return a})),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 h}));var o,a,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"})(o||(o={})),(function(d){d[d.Unipolar=0]="Unipolar",d[d.Bipolar=1]="Bipolar"})(a||(a={})),(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 h=[{id:f.GeneratorType.InitialAttenuation,source:{type:o.Concave,polarity:a.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:960,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialFilterFc,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:-2400,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.ChannelPressure},value:50,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.MidiController,index:1},value:50,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:o.Concave,polarity:a.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:7},value:960,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:o.Linear,polarity:a.Bipolar,direction:i.Increasing,palette:l.MidiController,index:10},value:1e3,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:o.Concave,polarity:a.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:11},value:960,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ReverbEffectsSend,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.MidiController,index:91},value:200,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ChorusEffectsSend,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.MidiController,index:93},value:200,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.CoarseTune,source:{type:o.Linear,polarity:a.Bipolar,direction:i.Increasing,palette:l.GeneralController,index:c.PitchWheel},value:12700,valueSource:{type:o.Linear,polarity:a.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 o;s.r(r),s.d(r,"SampleType",(function(){return o})),(function(a){a[a.EOS=0]="EOS",a[a.Mono=1]="Mono",a[a.Right=2]="Right",a[a.Left=4]="Left",a[a.Linked=8]="Linked",a[a.RomMono=32769]="RomMono",a[a.RomRight=32770]="RomRight",a[a.RomLeft=32772]="RomLeft",a[a.RomLinked=32776]="RomLinked"})(o||(o={}))},"./src/types/zone.ts":function(n,r){},"./src/utils/buffer.ts":function(n,r,s){s.r(r),s.d(r,"getStringFromBuffer",(function(){return o}));var o=function(a){var i=new TextDecoder("utf8").decode(a),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 o=s("./src/utils/buffer.ts");s.d(r,"getStringFromBuffer",(function(){return o.getStringFromBuffer}));var a=s("./src/utils/memoize.ts");s.d(r,"memoize",(function(){return a.memoize}))},"./src/utils/memoize.ts":function(n,r,s){s.r(r),s.d(r,"memoize",(function(){return o}));var o=function(a){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 h=a.apply(void 0,c);return i[f]=h,h}}}})}))})(oo)),oo.exports}Pf();var Le=1e3;function Co(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:s=1,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h}=e,d=t?.sampleRate??e.sampleRate??c?.sample_rate,p=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(p===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 v=e.durationSamples??p;return{id:ec(),audioBuffer:t,startSample:n,durationSamples:v,offsetSamples:r,sampleRate:d,sourceDurationSamples:p,gain:s,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h}}function Jl(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:s=1,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h}=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 p=t?.duration??e.sourceDuration??c?.duration;if(p===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 v=e.duration??p;return Co({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(v*d),offsetSamples:Math.round(r*d),sampleRate:d,sourceDurationSamples:Math.ceil(p*d),gain:s,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h})}function Ql(e){const{name:t,clips:n=[],muted:r=!1,soloed:s=!1,volume:o=1,pan:a=0,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}=e;return{id:ec(),name:t,clips:n,muted:r,soloed:s,volume:o,pan:a,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}}function ec(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function qi(e){return[...e].sort((t,n)=>t.startSample-n.startSample)}function Yr(e){return e.startSample/e.sampleRate}function Ji(e){return(e.startSample+e.durationSamples)/e.sampleRate}function Qi(e){return e.offsetSamples/e.sampleRate}function el(e){return e.durationSamples/e.sampleRate}var tl=!1;function wr(e){const t=e._param;return!t&&!tl&&(tl=!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 nl(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const o=s/r;n[s]=t?o:1-o}return n}function Ff(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const o=s/r,a=t?s:e-1-s;n[a]=Math.exp(2*o-1)/Math.E}return n}function Of(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 Lf(e,t,n=10){const r=new Float32Array(e);for(let s=0;s<e;s++){const o=t?s:e-1-s,a=s/e;r[o]=Math.log(1+n*a)/Math.log(1+n)}return r}function tc(e,t,n){switch(e){case"linear":return nl(t,n);case"exponential":return Ff(t,n);case"sCurve":return Of(t,n);case"logarithmic":return Lf(t,n);default:return nl(t,n)}}function rl(e,t,n,r="linear",s=0,o=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(o,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(o,.001),t+n);else{const a=tc(r,1e4,!0),i=new Float32Array(a.length),l=o-s;for(let c=0;c<a.length;c++)i[c]=s+a[c]*l;e.setValueCurveAtTime(i,t,n)}}function sl(e,t,n,r="linear",s=1,o=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(o,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(o,.001),t+n);else{const a=tc(r,1e4,!1),i=new Float32Array(a.length),l=s-o;for(let c=0;c<a.length;c++)i[c]=o+a[c]*l;e.setValueCurveAtTime(i,t,n)}}var Wf=class{constructor(e){this.activeSources=new Set,this._scheduleGuardOffset=0,this.track=e.track,this.volumeNode=new F.Volume(this.gainToDb(e.track.gain)),this.panNode=new F.Panner(e.track.stereoPan),this.muteGain=new F.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const t=e.destination||F.getDestination();if(e.effects){const a=e.effects(this.muteGain,t,!1);a&&(this.effectsCleanup=a)}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=F.getTransport(),s=F.getContext().rawContext,o=this.volumeNode.input.input;this.scheduledClips=n.map(a=>{const i=s.createGain();i.gain.value=a.gain,i.connect(o);const l=this.track.startTime+a.startTime,c=r.schedule(u=>{l<this._scheduleGuardOffset||this.startClipSource(a,i,u)},l);return{clipInfo:a,fadeGainNode:i,scheduleId:c}})}startClipSource(e,t,n,r,s){const a=F.getContext().rawContext.createBufferSource();a.buffer=e.buffer,a.connect(t);const i=r??e.offset,l=s??e.duration;try{a.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),a.disconnect();return}this.activeSources.add(a),a.onended=()=>{this.activeSources.delete(a)}}setScheduleGuardOffset(e){this._scheduleGuardOffset=e}startMidClipSources(e,t){for(const{clipInfo:n,fadeGainNode:r}of this.scheduledClips){const s=this.track.startTime+n.startTime,o=s+n.duration;if(s<e&&o>e){const a=e-s,i=n.offset+a,l=n.duration-a;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,o=s.gain;o.cancelScheduledValues(0);const a=n-r.offset;if(r.fadeIn&&a<r.fadeIn.duration){const i=r.fadeIn.duration;if(a<=0)rl(o,t,i,r.fadeIn.type||"linear",0,r.gain);else{const l=i-a,c=a/i,u=r.gain*c;rl(o,t,l,r.fadeIn.type||"linear",u,r.gain)}}else o.setValueAtTime(r.gain,t);if(r.fadeOut){const l=r.duration-r.fadeOut.duration-a;if(l>0){const c=t+l;sl(o,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,h=r.gain*(1-f);sl(o,t,u,r.fadeOut.type||"linear",h,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 o=t-r+n.clipInfo.offset;this.scheduleFades(n,e,o)}else{const o=r-t;this.scheduleFades(n,e+o,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;wr(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){const e=F.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 Bf(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 Vf=class{constructor(e){this.track=e.track,this.volumeNode=new F.Volume(this.gainToDb(e.track.gain)),this.panNode=new F.Panner(e.track.stereoPan),this.muteGain=new F.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain),this.synth=new F.PolySynth(F.Synth,e.synthOptions),this.synth.connect(this.volumeNode),this.kickSynth=new F.PolySynth(F.MembraneSynth,{voice:F.MembraneSynth,options:{pitchDecay:.05,octaves:6,envelope:{attack:.001,decay:.4,sustain:0,release:.1}}}),this.snareSynth=new F.NoiseSynth({noise:{type:"white"},envelope:{attack:.001,decay:.15,sustain:0,release:.05}}),this.cymbalSynth=new F.PolySynth(F.MetalSynth,{voice:F.MetalSynth,options:{envelope:{attack:.001,decay:.3,release:.1},harmonicity:5.1,modulationIndex:32,resonance:4e3,octaves:1.5}}),this.tomSynth=new F.PolySynth(F.MembraneSynth,{voice:F.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||F.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,o=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}}),a=new F.Part((i,l)=>{l.duration>0&&this.triggerNote(l.midi,l.note,l.duration,i,l.velocity,l.channel)},o);return a.start(0),{clipInfo:n,part:a}})}triggerNote(e,t,n,r,s,o){if(o===9)switch(Bf(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 o of n.notes){const a=o.time-n.offset,i=r+Math.max(0,a),l=i+o.duration;if(i<e&&l>e){const c=l-e;try{this.triggerNote(o.midi,o.name,c,t,o.velocity,o.channel)}catch(u){console.warn(`[waveform-playlist] Failed to start mid-clip MIDI note "${o.name}" on track "${this.id}":`,u)}}}}}stopAllSources(){const e=F.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;wr(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}},nc=class So{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 F.Volume(this.gainToDb(t.track.gain)),this.panNode=new F.Panner(t.track.stereoPan),this.muteGain=new F.Gain(t.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const n=t.destination||F.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}),o=this.track.startTime+r.startTime,a=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:o+u,note:l.name,midi:l.midi,duration:Math.max(0,f),velocity:l.velocity,channel:l.channel}}),i=new F.Part((l,c)=>{c.duration>0&&this.triggerNote(c.midi,c.duration,l,c.velocity,c.channel)},a);return i.start(0),{clipInfo:r,part:i}})}triggerNote(t,n,r,s,o){const a=o===9?128:this.bankNumber,i=o===9?0:this.programNumber,l=this.soundFontCache.getAudioBuffer(t,a,i);if(!l){So._missingSampleWarned||(console.warn(`[waveform-playlist] SoundFont sample not found for MIDI note ${t} (bank ${a}, preset ${i}). Subsequent missing samples will be silent.`),So._missingSampleWarned=!0);return}const c=F.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,h=l.loopMode===0?Math.max(n,f):n,d=s*s,p=c.createGain(),{attackVolEnv:v,holdVolEnv:y,decayVolEnv:m,sustainVolEnv:b,releaseVolEnv:_}=l,w=d*b;p.gain.setValueAtTime(0,r),p.gain.linearRampToValueAtTime(d,r+v),y>.001&&p.gain.setValueAtTime(d,r+v+y);const x=r+v+y;p.gain.linearRampToValueAtTime(w,x+m),p.gain.setValueAtTime(w,r+h),p.gain.linearRampToValueAtTime(0,r+h+_),u.connect(p),p.connect(this.volumeNode.input.input),this.activeSources.add(u),u.onended=()=>{this.activeSources.delete(u);try{p.disconnect()}catch(S){console.warn("[waveform-playlist] GainNode already disconnected:",S)}},u.start(r),u.stop(r+h+_)}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,o=s+r.duration;if(s<t&&o>t)for(const a of r.notes){const i=a.time-r.offset,l=s+Math.max(0,i),c=l+a.duration;if(l<t&&c>t){const u=c-t;try{this.triggerNote(a.midi,u,n,a.velocity,a.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;wr(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}};nc._missingSampleWarned=!1;var Nf=nc,zf=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 F.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,F.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{F.getTransport().clear(this._completionEventId)}catch(e){console.warn("[waveform-playlist] Error clearing Transport completion event:",e)}this._completionEventId=null}}async init(){this.isInitialized||(await F.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new Wf(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 Vf(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 Nf(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??F.now(),s=F.getTransport();this.clearCompletionEvent();const o=t??0;this.tracks.forEach(a=>{a.cancelFades(),a.prepareFades(r,o)}),n!==void 0&&(this._completionEventId=s.scheduleOnce(()=>{this._completionEventId=null;try{this.onPlaybackCompleteCallback?.()}catch(a){console.warn("[waveform-playlist] Error in playback completion callback:",a)}},o+n));try{s.state!=="stopped"&&s.stop(),this.tracks.forEach(a=>a.stopAllSources()),s.loopStart=this._loopStart,s.loopEnd=this._loopEnd,s.loop=this._loopEnabled,this.tracks.forEach(a=>a.setScheduleGuardOffset(o)),t!==void 0?s.start(r,t):s.start(r),s._clock._lastUpdate=r,this.tracks.forEach(a=>{a.startMidClipSources(o,r)})}catch(a){throw this.clearCompletionEvent(),this.tracks.forEach(i=>i.cancelFades()),console.warn("[waveform-playlist] Transport.start() failed. Audio playback could not begin.",a),a}}pause(){const e=F.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=F.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=F.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=F.now();this.tracks.forEach(o=>{try{o.stopAllSources(),o.cancelFades(),o.setScheduleGuardOffset(this._loopStart),o.startMidClipSources(this._loopStart,s),o.prepareFades(s,this._loopStart)}catch(a){console.warn(`[waveform-playlist] Error re-scheduling track "${o.id}" on loop:`,a)}})},r.on("loop",this._loopHandler)):!e&&this._loopHandler&&(r.off("loop",this._loopHandler),this._loopHandler=null)}getCurrentTime(){return F.getTransport().seconds}seekTo(e){F.getTransport().seconds=e}dispose(){if(this.clearCompletionEvent(),this._loopHandler){try{F.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 F.getContext()}get sampleRate(){return F.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Kr=null;function jf(){return Kr||(Kr=new F.Context,F.setContext(Kr)),Kr}function Zf(){return jf().rawContext}function Hf(e){let t=null,n=!1,r=0,s=!1,o=0,a=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 zf({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 h=f.clips.filter(p=>p.audioBuffer&&!p.midiNotes),d=f.clips.filter(p=>p.midiNotes&&p.midiNotes.length>0);if(h.length>0){const p=Math.min(...h.map(Yr)),v=Math.max(...h.map(Ji)),y={id:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:p,endTime:v},m=h.map(b=>({buffer:b.audioBuffer,startTime:Yr(b)-p,duration:el(b),offset:Qi(b),fadeIn:b.fadeIn,fadeOut:b.fadeOut,gain:b.gain}));t.addTrack({clips:m,track:y,effects:f.effects})}if(d.length>0){const p=Math.min(...d.map(Yr)),v=Math.max(...d.map(Ji)),m={id:h.length>0?`${f.id}:midi`:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:p,endTime:v},b=d.map(_=>({notes:_.midiNotes,startTime:Yr(_)-p,duration:el(_),offset:Qi(_)}));if(e?.soundFontCache?.isLoaded){const _=d[0],x=_.midiChannel===9,S=_.midiProgram??0;t.addSoundFontTrack({clips:b,track:m,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:m,effects:f.effects})}}t.applyInitialSoloState(),t.setLoop(s,o,a),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(F.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,o=u,a=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 rc(e,t,n,r){let s=t;const o=-e.startSample;if(s=Math.max(s,o),r>0){const a=n[r-1],l=a.startSample+a.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 ko(e,t,n,r,s,o){let a=t;if(n==="left"){if(a=Math.max(a,-e.startSample),a=Math.max(a,-e.offsetSamples),s>0){const i=r[s-1],l=i.startSample+i.durationSamples;a=Math.max(a,l-e.startSample)}a=Math.min(a,e.durationSamples-o)}else if(a=Math.max(a,o-e.durationSamples),a=Math.min(a,e.sourceDurationSamples-e.offsetSamples-e.durationSamples),s<r.length-1){const i=r[s+1];a=Math.min(a,i.startSample-e.startSample-e.durationSamples)}return a}function Gf(e,t){return Math.floor(e/t)*t}function Uf(e,t){const n=t-e.startSample,r=e.durationSamples-n,s=e.name?`${e.name} (1)`:void 0,o=e.name?`${e.name} (2)`:void 0,a=Co({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=Co({startSample:t,durationSamples:r,offsetSamples:e.offsetSamples+n,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:o,color:e.color,fadeOut:e.fadeOut,audioBuffer:e.audioBuffer,waveformData:e.waveformData});return{left:a,right:i}}function sc(e,t,n){const r=e.startSample+e.durationSamples;if(t<=e.startSample||t>=r)return!1;const s=t-e.startSample,o=r-t;return s>=n&&o>=n}function ao(e){let t=0;for(const n of e)for(const r of n.clips){const o=(r.startSample+r.durationSamples)/r.sampleRate;t=Math.max(t,o)}return t}function Xf(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 o=Math.abs(t[s]-e);o<r&&(r=o,n=s)}return n}function ol(e,t){return Math.max(0,Math.min(e,t))}var Yf=44100,Kf=1024,qf=[256,512,1024,2048,4096,8192],al=.1,Jf=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??Yf,this._zoomLevels=[...e.zoomLevels??qf],this._adapter=e.adapter??null,this._zoomLevels.length===0)throw new Error("PlaylistEngine: zoomLevels must not be empty");const t=e.samplesPerPixel??Kf,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:ao(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 o=r.clips[s],a=qi(r.clips),i=a.findIndex(c=>c.id===t),l=rc(o,n,a,i);l!==0&&(this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=c.clips.map((f,h)=>h===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 o=r.clips[s],a=Math.floor(al*this._sampleRate);if(!sc(o,n,a)){console.warn(`[waveform-playlist/engine] splitClip: cannot split clip "${t}" at sample ${n} (clip range: ${o.startSample}–${o.startSample+o.durationSamples}, minDuration: ${a})`);return}const{left:i,right:l}=Uf(o,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 o=s.clips.findIndex(f=>f.id===t);if(o===-1){console.warn(`[waveform-playlist/engine] trimClip: clip "${t}" not found in track "${e}"`);return}const a=s.clips[o],i=qi(s.clips),l=i.findIndex(f=>f.id===t),c=Math.floor(al*this._sampleRate),u=ko(a,r,n,i,l,c);u!==0&&(this._tracks=this._tracks.map(f=>{if(f.id!==e)return f;const h=f.clips.map((d,p)=>p!==o?d:n==="left"?{...d,startSample:d.startSample+u,offsetSamples:d.offsetSamples+u,durationSamples:d.durationSamples-u}:{...d,durationSamples:d.durationSamples+u});return{...f,clips:h}}),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=ao(this._tracks);this._currentTime=ol(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=ao(this._tracks);this._currentTime=ol(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=Xf(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)}},Qf=Symbol.for("preact-signals");function Fs(){if(Jt>1)Jt--;else{for(var e,t=!1;pr!==void 0;){var n=pr;for(pr=void 0,Eo++;n!==void 0;){var r=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&ac(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(Eo=0,Jt--,t)throw e}}function Qt(e){if(Jt>0)return e();Jt++;try{return e()}finally{Fs()}}var me=void 0;function we(e){var t=me;me=void 0;try{return e()}finally{me=t}}var pr=void 0,Jt=0,Eo=0,vs=0;function oc(e){if(me!==void 0){var t=e.n;if(t===void 0||t.t!==me)return t={i:0,S:e,p:me.s,n:void 0,t:me,e:void 0,x:void 0,r:t},me.s!==void 0&&(me.s.n=t),me.s=t,e.n=t,32&me.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=me.s,t.n=void 0,me.s.n=t,me.s=t),t}}function st(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}st.prototype.brand=Qf;st.prototype.h=function(){return!0};st.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:we(function(){var r;(r=t.W)==null||r.call(t)}))};st.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&&we(function(){var s;(s=t.Z)==null||s.call(t)}))}};st.prototype.subscribe=function(e){var t=this;return Ct(function(){var n=t.value,r=me;me=void 0;try{e(n)}finally{me=r}},{name:"sub"})};st.prototype.valueOf=function(){return this.value};st.prototype.toString=function(){return this.value+""};st.prototype.toJSON=function(){return this.value};st.prototype.peek=function(){var e=me;me=void 0;try{return this.value}finally{me=e}};Object.defineProperty(st.prototype,"value",{get:function(){var e=oc(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Eo>100)throw new Error("Cycle detected");this.v=e,this.i++,vs++,Jt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Fs()}}}});function $r(e,t){return new st(e,t)}function ac(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 ic(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 lc(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 yn(e,t){st.call(this,void 0),this.x=e,this.s=void 0,this.g=vs-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}yn.prototype=new st;yn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===vs))return!0;if(this.g=vs,this.f|=1,this.i>0&&!ac(this))return this.f&=-2,!0;var e=me;try{ic(this),me=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 me=e,lc(this),this.f&=-2,!0};yn.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)}st.prototype.S.call(this,e)};yn.prototype.U=function(e){if(this.t!==void 0&&(st.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)}};yn.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(yn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=oc(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function il(e,t){return new yn(e,t)}function cc(e){var t=e.u;if(e.u=void 0,typeof t=="function"){Jt++;var n=me;me=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,fa(e),r}finally{me=n,Fs()}}}function fa(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,cc(e)}function eh(e){if(me!==this)throw new Error("Out-of-order effect");lc(this),me=e,this.f&=-2,8&this.f&&fa(this),Fs()}function jn(e,t){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}jn.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()}};jn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,cc(this),ic(this),Jt++;var e=me;return me=this,eh.bind(this,e)};jn.prototype.N=function(){2&this.f||(this.f|=2,this.o=pr,pr=this)};jn.prototype.d=function(){this.f|=8,1&this.f||fa(this)};jn.prototype.dispose=function(){this.d()};function Ct(e,t){var n=new jn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var th=Object.create,ha=Object.defineProperty,nh=Object.defineProperties,rh=Object.getOwnPropertyDescriptor,sh=Object.getOwnPropertyDescriptors,ll=Object.getOwnPropertySymbols,oh=Object.prototype.hasOwnProperty,ah=Object.prototype.propertyIsEnumerable,ih=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zn=e=>{throw TypeError(e)},Io=(e,t,n)=>t in e?ha(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,lh=(e,t)=>{for(var n in t||(t={}))oh.call(t,n)&&Io(e,n,t[n]);if(ll)for(var n of ll(t))ah.call(t,n)&&Io(e,n,t[n]);return e},ch=(e,t)=>nh(e,sh(t)),cl=(e,t)=>ha(e,"name",{value:t,configurable:!0}),uh=e=>{var t;return[,,,th((t=void 0)!=null?t:null)]},uc=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Zn("Function expected"):e,dh=(e,t,n,r,s)=>({kind:uc[e],name:t,metadata:r,addInitializer:o=>n._?Zn("Already initialized"):s.push(rr(o||null))}),dc=(e,t)=>Io(t,ih("metadata"),e[3]),an=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Hn=(e,t,n,r,s,o)=>{var a,i,l,c,u,f=t&7,h=!!(t&8),d=!!(t&16),p=f>3?e.length+1:f?h?1:2:0,v=uc[f+5],y=f>3&&(e[p-1]=[]),m=e[p]||(e[p]=[]),b=f&&(!d&&!h&&(s=s.prototype),f<5&&(f>3||!d)&&rh(f<4?s:{get[n](){return pn(this,o)},set[n](w){return Yt(this,o,w)}},n));f?d&&f<4&&cl(o,(f>2?"set ":f>1?"get ":"")+n):cl(s,n);for(var _=r.length-1;_>=0;_--)c=dh(f,n,l={},e[3],m),f&&(c.static=h,c.private=d,u=c.access={has:d?w=>fh(s,w):w=>n in w},f^3&&(u.get=d?w=>(f^1?pn:hh)(w,s,f^4?o:b.get):w=>w[n]),f>2&&(u.set=d?(w,x)=>Yt(w,s,x,f^4?o:b.set):(w,x)=>w[n]=x)),i=(0,r[_])(f?f<4?d?o:b[v]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?rr(i)&&(f>4?y.unshift(i):f?d?o=i:b[v]=i:s=i):typeof i!="object"||i===null?Zn("Object expected"):(rr(a=i.get)&&(b.get=a),rr(a=i.set)&&(b.set=a),rr(a=i.init)&&y.unshift(a));return f||dc(e,s),b&&ha(s,n,b),d?f^4?o:b:s},pa=(e,t,n)=>t.has(e)||Zn("Cannot "+n),fh=(e,t)=>Object(t)!==t?Zn('Cannot use the "in" operator on this value'):e.has(t),pn=(e,t,n)=>(pa(e,t,"read from private field"),n?n.call(e):t.get(e)),qr=(e,t,n)=>t.has(e)?Zn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Yt=(e,t,n,r)=>(pa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),hh=(e,t,n)=>(pa(e,t,"access private method"),n);function ys(e,t){if(t){let n;return il(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return il(e)}function _r(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)=>!_r(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(o=>!_r(e[o],t[o]))}return!1}function de({get:e},t){return{init(n){return $r(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ie(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ys(e.bind(this)),n.set(this,r)),r.value}}function io(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,ch(lh({},s),{enumerable:e}))})}}function Rr(...e){const t=e.map(n=>Ct(n));return()=>t.forEach(n=>n())}var fc,hc,pc,mc,gc,vc,tt,ma,lo,Mo,Ao,qe,ga,co,yc,To,va,uo,$o,Ro;vc=[de],gc=[de],mc=[de],pc=[io()],hc=[io()],fc=[io()];var tn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,an(tt,5,this),qr(this,qe),qr(this,ma,an(tt,8,this)),an(tt,11,this),qr(this,ga,an(tt,12,this)),an(tt,15,this),qr(this,va,an(tt,16,this)),an(tt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return pn(this,qe,$o)}get initial(){return pn(this,qe,Mo)}get previous(){return pn(this,qe,yc)}set current(e){const t=we(()=>pn(this,qe,$o));e&&t&&this.equals(t,e)||Qt(()=>{pn(this,qe,Mo)||Yt(this,qe,e,Ao),Yt(this,qe,t,To),Yt(this,qe,e,Ro)})}reset(e=this.defaultValue){Qt(()=>{Yt(this,qe,void 0,To),Yt(this,qe,e,Ao),Yt(this,qe,e,Ro)})}};tt=uh();ma=new WeakMap;qe=new WeakSet;ga=new WeakMap;va=new WeakMap;lo=Hn(tt,20,"#initial",vc,qe,ma),Mo=lo.get,Ao=lo.set;co=Hn(tt,20,"#previous",gc,qe,ga),yc=co.get,To=co.set;uo=Hn(tt,20,"#current",mc,qe,va),$o=uo.get,Ro=uo.set;Hn(tt,2,"current",pc,tn);Hn(tt,2,"initial",hc,tn);Hn(tt,2,"previous",fc,tn);dc(tt,tn);function fo(e){return we(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var ph=Object.create,bc=Object.defineProperty,mh=Object.getOwnPropertyDescriptor,ul=Object.getOwnPropertySymbols,gh=Object.prototype.hasOwnProperty,vh=Object.prototype.propertyIsEnumerable,wc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Os=e=>{throw TypeError(e)},dl=Math.pow,Do=(e,t,n)=>t in e?bc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yh=(e,t)=>{for(var n in t||(t={}))gh.call(t,n)&&Do(e,n,t[n]);if(ul)for(var n of ul(t))vh.call(t,n)&&Do(e,n,t[n]);return e},bh=e=>{var t;return[,,,ph((t=e?.[wc("metadata")])!=null?t:null)]},_c=["class","method","getter","setter","accessor","field","value","get","set"],xc=e=>e!==void 0&&typeof e!="function"?Os("Function expected"):e,wh=(e,t,n,r,s)=>({kind:_c[e],name:t,metadata:r,addInitializer:o=>n._?Os("Already initialized"):s.push(xc(o||null))}),_h=(e,t)=>Do(t,wc("metadata"),e[3]),xh=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)o[s].call(n);return r},Cc=(e,t,n,r,s,o)=>{for(var a,i,l,c,u=t&7,f=!1,h=!1,d=2,p=_c[u+5],v=e[d]||(e[d]=[]),y=(s=s.prototype,mh(s,n)),m=r.length-1;m>=0;m--)l=wh(u,n,i={},e[3],v),l.static=f,l.private=h,c=l.access={has:b=>n in b},c.get=b=>b[n],a=(0,r[m])(y[p],l),i._=1,xc(a)&&(y[p]=a);return y&&bc(s,n,y),s},Sc=(e,t,n)=>t.has(e)||Os("Cannot "+n),Ch=(e,t,n)=>(Sc(e,t,"read from private field"),t.get(e)),Sh=(e,t,n)=>t.has(e)?Os("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),kh=(e,t,n,r)=>(Sc(e,t,"write to private field"),t.set(e,n),n),Pt=class Po{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Po(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 Po(t,n)}},Dr=class cn{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:o,height:a,scale:i}=this,l=new cn(s+t,r+n,o,a);return l.scale=yh({},i),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:o,bottom:a}=this;return{width:t,height:n,left:r,top:s,right:o,bottom:a}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Pt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof cn))return!1;const{left:n,top:r,width:s,height:o}=this;return n===t.left&&r===t.top&&s===t.width&&o===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:o}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=o}intersectionArea(t){return t instanceof cn?Eh(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 cn(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(o,a)=>{const i=r[a],l=a==="x"?o.left:o.top,c=a==="x"?o.width:o.height;return i=="start"?l:i=="end"?l+c:l+c/2};return Pt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return cn.from(t).intersectionRatio(cn.from(n))}};function Eh(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),o=Math.min(t.top+t.height,e.top+e.height),a=s-r,i=o-n;return r<s&&n<o?a*i:0}var kc,Ec,Fo,ss,Pr,Ls=class extends(Fo=tn,Ec=[Ie],kc=[Ie],Fo){constructor(t){const n=Pt.from(t);super(n,(r,s)=>Pt.equals(r,s)),xh(Pr,5,this),Sh(this,ss,0),this.velocity={x:0,y:0}}get delta(){return Pt.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=Pt.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),a=o-Ch(this,ss),i=l=>Math.round(l/a*100);Qt(()=>{kh(this,ss,o),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Pt.from(t)),this.velocity={x:0,y:0}}};Pr=bh(Fo);ss=new WeakMap;Cc(Pr,2,"delta",Ec,Ls);Cc(Pr,2,"direction",kc,Ls);_h(Pr,Ls);function Oo({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(dl(r,2)+dl(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 Ic=(e=>(e.Horizontal="x",e.Vertical="y",e))(Ic||{}),Mc=Object.values(Ic),Ih=Object.create,ya=Object.defineProperty,Mh=Object.defineProperties,Ah=Object.getOwnPropertyDescriptor,Th=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,Ac=Object.prototype.hasOwnProperty,Tc=Object.prototype.propertyIsEnumerable,$c=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Gn=e=>{throw TypeError(e)},Lo=(e,t,n)=>t in e?ya(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Rc=(e,t)=>{for(var n in t||(t={}))Ac.call(t,n)&&Lo(e,n,t[n]);if(bs)for(var n of bs(t))Tc.call(t,n)&&Lo(e,n,t[n]);return e},Dc=(e,t)=>Mh(e,Th(t)),fl=(e,t)=>ya(e,"name",{value:t,configurable:!0}),Pc=(e,t)=>{var n={};for(var r in e)Ac.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&bs)for(var r of bs(e))t.indexOf(r)<0&&Tc.call(e,r)&&(n[r]=e[r]);return n},Un=e=>{var t;return[,,,Ih((t=e?.[$c("metadata")])!=null?t:null)]},Fc=["class","method","getter","setter","accessor","field","value","get","set"],sr=e=>e!==void 0&&typeof e!="function"?Gn("Function expected"):e,$h=(e,t,n,r,s)=>({kind:Fc[e],name:t,metadata:r,addInitializer:o=>n._?Gn("Already initialized"):s.push(sr(o||null))}),bn=(e,t)=>Lo(t,$c("metadata"),e[3]),re=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},ue=(e,t,n,r,s,o)=>{var a,i,l,c,u,f=t&7,h=!!(t&8),d=!!(t&16),p=f>3?e.length+1:f?h?1:2:0,v=Fc[f+5],y=f>3&&(e[p-1]=[]),m=e[p]||(e[p]=[]),b=f&&(!d&&!h&&(s=s.prototype),f<5&&(f>3||!d)&&Ah(f<4?s:{get[n](){return He(this,o)},set[n](w){return wt(this,o,w)}},n));f?d&&f<4&&fl(o,(f>2?"set ":f>1?"get ":"")+n):fl(s,n);for(var _=r.length-1;_>=0;_--)c=$h(f,n,l={},e[3],m),f&&(c.static=h,c.private=d,u=c.access={has:d?w=>Rh(s,w):w=>n in w},f^3&&(u.get=d?w=>(f^1?He:Dh)(w,s,f^4?o:b.get):w=>w[n]),f>2&&(u.set=d?(w,x)=>wt(w,s,x,f^4?o:b.set):(w,x)=>w[n]=x)),i=(0,r[_])(f?f<4?d?o:b[v]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?sr(i)&&(f>4?y.unshift(i):f?d?o=i:b[v]=i:s=i):typeof i!="object"||i===null?Gn("Object expected"):(sr(a=i.get)&&(b.get=a),sr(a=i.set)&&(b.set=a),sr(a=i.init)&&y.unshift(a));return f||bn(e,s),b&&ya(s,n,b),d?f^4?o:b:s},ba=(e,t,n)=>t.has(e)||Gn("Cannot "+n),Rh=(e,t)=>Object(t)!==t?Gn('Cannot use the "in" operator on this value'):e.has(t),He=(e,t,n)=>(ba(e,t,"read from private field"),n?n.call(e):t.get(e)),be=(e,t,n)=>t.has(e)?Gn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),wt=(e,t,n,r)=>(ba(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Dh=(e,t,n)=>(ba(e,t,"access private method"),n);function Oc(e,t){return{plugin:e,options:t}}function Xn(e){return t=>Oc(e,t)}function wa(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Lc,xr,_a,os;Lc=[de];var it=class{constructor(e,t){this.manager=e,this.options=t,be(this,_a,re(xr,8,this,!1)),re(xr,11,this),be(this,os,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return we(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=Ct(e.bind(this));return He(this,os).add(t),t}destroy(){He(this,os).forEach(e=>e())}static configure(e){return Oc(this,e)}};xr=Un(null);_a=new WeakMap;os=new WeakMap;ue(xr,4,"disabled",Lc,it,_a);bn(xr,it);var Fr=class extends it{},as,ho=class{constructor(e){this.manager=e,this.instances=new Map,be(this,as,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(wa).reduceRight((r,s)=>r.some(({plugin:o})=>o===s.plugin)?r:[s,...r],[]),n=t.map(({plugin:r})=>r);for(const r of He(this,as))if(!n.includes(r)){if(r.prototype instanceof Fr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);wt(this,as,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()}};as=new WeakMap;function Ph(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Jr=[],Tn,$n,Fh=class extends it{constructor(e){super(e),be(this,Tn),be(this,$n),this.computeCollisions=this.computeCollisions.bind(this),wt(this,$n,$r(Jr)),this.destroy=Rr(()=>{const t=this.computeCollisions(),n=we(()=>this.manager.dragOperation.position.current);if(t!==Jr){const r=He(this,Tn);if(wt(this,Tn,n),r&&n.x==r.x&&n.y==r.y)return}else wt(this,Tn,void 0);He(this,$n).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){we(()=>{e?He(this,$n).value=this.computeCollisions():wt(this,Tn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:o,status:a}=r;if(!a.initialized||!o)return Jr;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=we(()=>u({droppable:c,dragOperation:r}));f&&(c.collisionPriority!=null&&(f.priority=c.collisionPriority),i.push(f))}return l.length===0?Jr:(i.sort(Ph),i)}get collisions(){return He(this,$n).value}};Tn=new WeakMap;$n=new WeakMap;var Oh=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)}},Lh=class extends Oh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function is(e,t=!0){let n=!1;return Dc(Rc({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var Wh=class extends Fr{constructor(e){super(e);const t=(r,s)=>r.map(({id:o})=>o).join("")===s.map(({id:o})=>o).join("");let n=[];this.destroy=Rr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:o}=r;if(r.isDisabled())return;const a=is({collisions:o});if(s.dispatch("collision",a),a.defaultPrevented||t(o,n))return;n=o;const[i]=o;we(()=>{var l;i?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(i?.id).then(()=>{r.enable()}))})})}},xa=(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))(xa||{}),Ca=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(Ca||{}),Wc,Bc,Vc,Nc,zc,jc,Zc,xt,Sa;Zc=[de],jc=[Ie],zc=[Ie],Nc=[Ie],Vc=[Ie],Bc=[Ie],Wc=[Ie];var jt=class{constructor(){re(xt,5,this),be(this,Sa,re(xt,8,this,"idle")),re(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=Un(null);Sa=new WeakMap;ue(xt,4,"value",Zc,jt,Sa);ue(xt,2,"current",jc,jt);ue(xt,2,"idle",zc,jt);ue(xt,2,"initializing",Nc,jt);ue(xt,2,"initialized",Vc,jt);ue(xt,2,"dragging",Bc,jt);ue(xt,2,"dropped",Wc,jt);bn(xt,jt);var Bh=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 we(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=is({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return we(()=>{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:o}=e;Qt(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(o)});const a=is({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",a),a.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 we(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:o}=r;if(!s.dragging||!o||o.signal.aborted)return;const a=is({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",a),queueMicrotask(()=>{var i,l,c,u,f;if(a.defaultPrevented)return;const h=(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=h})})}stop(e={}){return we(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let o;const a=()=>{const l={resume:()=>{},abort:()=>{}};return o=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=we(()=>{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:a}),o?o.then(i).catch(()=>r.reset()):i()})}},Hc,Gc,Uc,Xc,at,ka,Ea,Ia,Ma;Xc=[de],Uc=[de],Gc=[de],Hc=[de];var nn=class{constructor(e,t){be(this,ka,re(at,8,this)),re(at,11,this),be(this,Ea,re(at,12,this)),re(at,15,this),be(this,Ia,re(at,16,this)),re(at,19,this),be(this,Ma,re(at,20,this)),re(at,23,this);const{effects:n,id:r,data:s={},disabled:o=!1,register:a=!0}=e;let i=r;this.manager=t,this.id=r,this.data=s,this.disabled=o,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&&a&&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)}};at=Un(null);ka=new WeakMap;Ea=new WeakMap;Ia=new WeakMap;Ma=new WeakMap;ue(at,4,"manager",Xc,nn,ka);ue(at,4,"id",Uc,nn,Ea);ue(at,4,"data",Gc,nn,Ia);ue(at,4,"disabled",Hc,nn,Ma);bn(at,nn);var hl=class{constructor(){this.map=$r(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 o=new Map(n);o.set(e,t),this.map.value=o;const a=Rr(...t.effects());return this.cleanupFunctions.set(t,a),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}},Yc,Kc,qc,Jc,Qc,eu,Wo,nt,Aa,Ta,$a,Ft=class extends(Wo=nn,eu=[de],Qc=[de],Jc=[de],qc=[Ie],Kc=[Ie],Yc=[Ie],Wo){constructor(t,n){var r=t,{modifiers:s,type:o,sensors:a}=r,i=Pc(r,["modifiers","type","sensors"]);super(i,n),re(nt,5,this),be(this,Aa,re(nt,8,this)),re(nt,11,this),be(this,Ta,re(nt,12,this)),re(nt,15,this),be(this,$a,re(nt,16,this,this.isDragSource?"dragging":"idle")),re(nt,19,this),this.type=o,this.sensors=a,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}};nt=Un(Wo);Aa=new WeakMap;Ta=new WeakMap;$a=new WeakMap;ue(nt,4,"type",eu,Ft,Aa);ue(nt,4,"modifiers",Qc,Ft,Ta);ue(nt,4,"status",Jc,Ft,$a);ue(nt,2,"isDropping",qc,Ft);ue(nt,2,"isDragging",Kc,Ft);ue(nt,2,"isDragSource",Yc,Ft);bn(nt,Ft);var tu,nu,ru,su,ou,au,Bo,ze,Ra,Da,Pa,Fa,Oa,Ot=class extends(Bo=nn,au=[de],ou=[de],su=[de],ru=[de],nu=[de],tu=[Ie],Bo){constructor(t,n){var r=t,{accept:s,collisionDetector:o,collisionPriority:a,type:i}=r,l=Pc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),re(ze,5,this),be(this,Ra,re(ze,8,this)),re(ze,11,this),be(this,Da,re(ze,12,this)),re(ze,15,this),be(this,Pa,re(ze,16,this)),re(ze,19,this),be(this,Fa,re(ze,20,this)),re(ze,23,this),be(this,Oa,re(ze,24,this)),re(ze,27,this),this.accept=s,this.collisionDetector=o,this.collisionPriority=a,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}};ze=Un(Bo);Ra=new WeakMap;Da=new WeakMap;Pa=new WeakMap;Fa=new WeakMap;Oa=new WeakMap;ue(ze,4,"accept",au,Ot,Ra);ue(ze,4,"type",ou,Ot,Da);ue(ze,4,"collisionDetector",su,Ot,Pa);ue(ze,4,"collisionPriority",ru,Ot,Fa);ue(ze,4,"shape",nu,Ot,Oa);ue(ze,2,"isDropTarget",tu,Ot);bn(ze,Ot);var Wn=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Vh=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)}},ls,iu=class{constructor(e){this.options=e,be(this,ls)}set controller(e){wt(this,ls,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=He(this,ls))==null||t.activate(e)}};ls=new WeakMap;var Cr=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Nh=class{constructor(e){this.draggables=new hl,this.droppables=new hl,this.plugins=new ho(e),this.sensors=new ho(e),this.modifiers=new ho(e)}register(e,t){if(e instanceof Ft)return this.draggables.register(e.id,e);if(e instanceof Ot)return this.droppables.register(e.id,e);if(e.prototype instanceof Cr)return this.modifiers.register(e,t);if(e.prototype instanceof Wn)return this.sensors.register(e,t);if(e.prototype instanceof it)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof nn)return e instanceof Ft?this.draggables.unregister(e.id,e):e instanceof Ot?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Cr)return this.modifiers.unregister(e);if(e.prototype instanceof Wn)return this.sensors.unregister(e);if(e.prototype instanceof it)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()}},lu,cu,uu,du,fu,hu,pu,mu,gu,or,cs,Rn,Re,La,Wa,Ba,Va,Na,ar;gu=[Ie],mu=[de],pu=[de],hu=[de],fu=[de],du=[de],uu=[Ie],cu=[Ie],lu=[Ie];var Rt=class{constructor(e){re(Re,5,this),be(this,or),be(this,cs),be(this,Rn,new tn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new jt,be(this,La,re(Re,8,this,!1)),re(Re,11,this),be(this,Wa,re(Re,12,this,null)),re(Re,15,this),be(this,Ba,re(Re,16,this,null)),re(Re,19,this),be(this,Va,re(Re,20,this,null)),re(Re,23,this),be(this,Na,re(Re,24,this,[])),re(Re,27,this),this.position=new Ls({x:0,y:0}),be(this,ar,{x:0,y:0}),wt(this,or,e)}get shape(){const{current:e,initial:t,previous:n}=He(this,Rn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?He(this,Rn).current=e:He(this,Rn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=He(this,or).registry.draggables.get(t);return n&&wt(this,cs,n),(e=n??He(this,cs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=He(this,or).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(Dc(Rc({},this.snapshot()),{transform:n}));return wt(this,ar,n),n}snapshot(){return we(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:He(this,ar),shape:this.shape?fo(this.shape):null,position:fo(this.position),status:fo(this.status),canceled:this.canceled}))}reset(){Qt(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,He(this,Rn).reset(),this.position.reset({x:0,y:0}),wt(this,ar,{x:0,y:0}),this.modifiers=[]})}};Re=Un(null);or=new WeakMap;cs=new WeakMap;Rn=new WeakMap;La=new WeakMap;Wa=new WeakMap;Ba=new WeakMap;Va=new WeakMap;Na=new WeakMap;ar=new WeakMap;ue(Re,2,"shape",gu,Rt);ue(Re,4,"canceled",mu,Rt,La);ue(Re,4,"activatorEvent",pu,Rt,Wa);ue(Re,4,"sourceIdentifier",hu,Rt,Ba);ue(Re,4,"targetIdentifier",fu,Rt,Va);ue(Re,4,"modifiers",du,Rt,Na);ue(Re,2,"source",uu,Rt);ue(Re,2,"target",cu,Rt);ue(Re,2,"transform",lu,Rt);bn(Re,Rt);var zh={get rendering(){return Promise.resolve()}};function Vt(e,t){return typeof e=="function"?e(t):e??t}var jh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(h=>h.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=Vt(r.plugins,[]),o=Vt(r.sensors,[]),a=Vt(r.modifiers,[]),i=(n=r.renderer)!=null?n:zh,l=new Lh(this),c=new Nh(this);this.registry=c,this.monitor=l,this.renderer=i,this.actions=new Bh(this),this.dragOperation=new Rt(this),this.collisionObserver=new Fh(this),this.plugins=[Wh,...s],this.modifiers=a,this.sensors=o;const{destroy:u}=this,f=Rr(()=>{var h,d,p;const v=we(()=>this.dragOperation.modifiers),y=this.modifiers;for(const m of v)y.includes(m)||m.destroy();this.dragOperation.modifiers=(p=(d=(h=this.dragOperation.source)==null?void 0:h.modifiers)==null?void 0:d.map(m=>{const{plugin:b,options:_}=wa(m);return new b(this,_)}))!=null?p:y});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}},vu=e=>{throw TypeError(e)},za=(e,t,n)=>t.has(e)||vu("Cannot "+n),ae=(e,t,n)=>(za(e,t,"read from private field"),t.get(e)),ot=(e,t,n)=>t.has(e)?vu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),pt=(e,t,n,r)=>(za(e,t,"write to private field"),t.set(e,n),n),yu=(e,t,n)=>(za(e,t,"access private method"),n);function Ws(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Zh(e,t){const n=e.getAnimations();if(n.length>0)for(const r of n){if(r.playState!=="running")continue;const{effect:s}=r,a=(Ws(s)?s.getKeyframes():[]).filter(t);if(a.length>0)return[a[a.length-1],r]}return null}function Bs(e){const{width:t,height:n,top:r,left:s,bottom:o,right:a}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:o,right:a}}function ja(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Or(e){return"nodeType"in e}function St(e){var t,n,r;return e?ja(e)?e:Or(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 Za(e){const{Document:t}=St(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function mn(e){return!e||ja(e)?!1:e instanceof St(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function bu(e){return e instanceof St(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function wn(e){return e?ja(e)?e.document:Or(e)?Za(e)?e:mn(e)||bu(e)?e.ownerDocument:document:document:document}function Hh(e){var t,n,r,s;const{documentElement:o}=wn(e),a=St(e).visualViewport,i=(t=a?.width)!=null?t:o.clientWidth,l=(n=a?.height)!=null?n:o.clientHeight,c=(r=a?.offsetTop)!=null?r:0,u=(s=a?.offsetLeft)!=null?s:0;return{top:c,left:u,right:u+i,bottom:c+l,width:i,height:l}}function Gh(e,t){if(Uh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Uh(e){return e.tagName==="DETAILS"}function ws(e,t=e.getBoundingClientRect(),n=0){var r,s,o,a,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(!Gh(f)){const _=f.getBoundingClientRect(),w=n*(_.bottom-_.top),x=n*(_.right-_.left),S=n*(_.bottom-_.top),k=n*(_.right-_.left);l={top:Math.max(l.top,_.top-w),right:Math.min(l.right,_.right+x),bottom:Math.min(l.bottom,_.bottom+S),left:Math.max(l.left,_.left-k),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}f=f.parentElement}const h=u.visualViewport,d=(s=h?.offsetTop)!=null?s:0,p=(o=h?.offsetLeft)!=null?o:0,v=(a=h?.width)!=null?a:u.innerWidth,y=(i=h?.height)!=null?i:u.innerHeight,m=n*y,b=n*v;return l={top:Math.max(l.top,d-m),right:Math.min(l.right,p+v+b),bottom:Math.min(l.bottom,d+y+m),left:Math.max(l.left,p-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 Bn(e){return{x:e.clientX,y:e.clientY}}var wu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Vo(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(...Vo(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(...Vo(s.document,t))}}catch{}return n}function Ha(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function _u(){var e,t;const n=Ha()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Ga(e){return!e||!Or(e)?!1:e instanceof St(e).ShadowRoot}function _s(e){if(e&&Or(e)){let t=e.getRootNode();if(Ga(t))return t;if(t instanceof Document)return t}return wn(e)}function xu(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Xh(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((o,a)=>{const i=r[a];if(pl(o)&&pl(i)&&(o.type!=="file"&&(o.value=i.value),o.type==="radio"&&o.name&&(o.name=`Cloned__${o.name}`)),ml(o)&&ml(i)&&i.width>0&&i.height>0){const l=o.getContext("2d");l?.drawImage(i,0,0)}}),n}function pl(e){return"value"in e}function ml(e){return e.tagName==="CANVAS"}function Cu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Yh(r)){const{contentDocument:s}=r;if(s){const{left:o,top:a}=r.getBoundingClientRect();return Cu(s,{x:t-o,y:n-a})}}return r}function Yh(e){return e?.tagName==="IFRAME"}var gl=new WeakMap;function Kh(e){return!!e.closest(`
1
+ "use strict";var Mf=Object.create;var Xi=Object.defineProperty;var Af=Object.getOwnPropertyDescriptor;var Tf=Object.getOwnPropertyNames;var $f=Object.getPrototypeOf,Rf=Object.prototype.hasOwnProperty;var Df=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Tf(t))!Rf.call(e,s)&&s!==n&&Xi(e,s,{get:()=>t[s],enumerable:!(r=Af(t,s))||r.enumerable});return e};var Pf=(e,t,n)=>(n=e!=null?Mf($f(e)):{},Df(t||!e||!e.__esModule?Xi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("tone"),C=require("react/jsx-runtime"),g=require("react"),D=require("styled-components"),ua=require("react-dom");function Yl(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 Kl=Yl(F),R=Yl(g);var oo={exports:{}},Yi;function Ff(){return Yi||(Yi=1,(function(e,t){(function(n,r){e.exports=r()})(window,(function(){return(function(n){var r={};function s(o){if(r[o])return r[o].exports;var a=r[o]={i:o,l:!1,exports:{}};return n[o].call(a.exports,a,a.exports,s),a.l=!0,a.exports}return s.m=n,s.c=r,s.d=function(o,a,i){s.o(o,a)||Object.defineProperty(o,a,{enumerable:!0,get:i})},s.r=function(o){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})},s.t=function(o,a){if(1&a&&(o=s(o)),8&a||4&a&&typeof o=="object"&&o&&o.__esModule)return o;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:o}),2&a&&typeof o!="string")for(var l in o)s.d(i,l,(function(c){return o[c]}).bind(null,l));return i},s.n=function(o){var a=o&&o.__esModule?function(){return o.default}:function(){return o};return s.d(a,"a",a),a},s.o=function(o,a){return Object.prototype.hasOwnProperty.call(o,a)},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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=s("./src/chunks/index.ts");function l(p){return(l=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(v){return typeof v}:function(v){return v&&typeof Symbol=="function"&&v.constructor===Symbol&&v!==Symbol.prototype?"symbol":typeof v})(p)}function c(p,v){for(var y=0;y<v.length;y++){var m=v[y];m.enumerable=m.enumerable||!1,m.configurable=!0,"value"in m&&(m.writable=!0),Object.defineProperty(p,m.key,m)}}function u(p){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(v){return v.__proto__||Object.getPrototypeOf(v)})(p)}function f(p,v){return(f=Object.setPrototypeOf||function(y,m){return y.__proto__=m,y})(p,v)}function h(p){if(p===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return p}var d=(function(p){function v(b){var _,w,x,S,k,E;return(function(M,I){if(!(M instanceof I))throw new TypeError("Cannot call a class as a function")})(this,v),w=this,_=!(x=u(v).call(this,b.id,b.length,b.buffer,b.subChunks))||l(x)!=="object"&&typeof x!="function"?h(w):x,S=h(h(_)),E=void 0,(k="subChunks")in S?Object.defineProperty(S,k,{value:E,enumerable:!0,configurable:!0,writable:!0}):S[k]=E,_.subChunks=b.subChunks.map((function(M){return new v(M)})),_}var y,m;return(function(b,_){if(typeof _!="function"&&_!==null)throw new TypeError("Super expression must either be null or a function");b.prototype=Object.create(_&&_.prototype,{constructor:{value:b,writable:!0,configurable:!0}}),_&&f(b,_)})(v,p),y=v,(m=[{key:"getMetaData",value:function(){if(this.id!=="LIST")throw new o.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks.reduce((function(_,w){if(w.id==="ifil"||w.id==="iver"){if(w.length!==a.SF_VERSION_LENGTH)throw new o.ParseError("Invalid size for the '".concat(w.id,"' sub-chunk"));_[w.id]="".concat(w.getInt16(),".").concat(w.getInt16(2))}else _[w.id]=w.getString();return _}),{});if(!b.ifil)throw new o.ParseError("Missing required 'ifil' sub-chunk");if(!b.INAM)throw new o.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 o.ParseError("Unexpected chunk ID","'LIST'","'".concat(this.id,"'"));var b=this.subChunks[0];if(b.id!=="smpl")throw new o.ParseError("Invalid chunk signature","'smpl'","'".concat(b.id,"'"));return b.buffer}},{key:"getPresetData",value:function(){if(this.id!=="LIST")throw new o.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(y.prototype,m),v})(o.RIFFChunk)},"./src/chunks/generators.ts":function(n,r,s){s.r(r),s.d(r,"getGenerators",(function(){return f}));var o=s("./src/riff/index.ts"),a=s("./src/types/index.ts"),i=s("./src/constants.ts"),l=[a.GeneratorType.StartAddrsOffset,a.GeneratorType.EndAddrsOffset,a.GeneratorType.StartLoopAddrsOffset,a.GeneratorType.EndLoopAddrsOffset,a.GeneratorType.StartAddrsCoarseOffset,a.GeneratorType.EndAddrsCoarseOffset,a.GeneratorType.StartLoopAddrsCoarseOffset,a.GeneratorType.KeyNum,a.GeneratorType.Velocity,a.GeneratorType.EndLoopAddrsCoarseOffset,a.GeneratorType.SampleModes,a.GeneratorType.ExclusiveClass,a.GeneratorType.OverridingRootKey],c=[a.GeneratorType.Unused1,a.GeneratorType.Unused2,a.GeneratorType.Unused3,a.GeneratorType.Unused4,a.GeneratorType.Reserved1,a.GeneratorType.Reserved2,a.GeneratorType.Reserved3],u=[a.GeneratorType.KeyRange,a.GeneratorType.VelRange],f=function(h,d){if(h.id!==d)throw new o.ParseError("Unexpected chunk ID","'".concat(d,"'"),"'".concat(h.id,"'"));if(h.length%i.SF_GENERATOR_SIZE)throw new o.ParseError("Invalid size for the '".concat(d,"' sub-chunk"));return h.iterate((function(p){var v=p.getInt16();return a.GeneratorType[v]?d==="pgen"&&l.includes(v)||d==="igen"&&c.includes(v)?null:u.includes(v)?{id:v,range:{lo:p.getByte(),hi:p.getByte()}}:{id:v,value:p.getInt16BE()}:null}))}},"./src/chunks/index.ts":function(n,r,s){s.r(r);var o=s("./src/chunks/instruments/index.ts");s.d(r,"getInstrumentHeaders",(function(){return o.getInstrumentHeaders}));var a=s("./src/chunks/presets/index.ts");s.d(r,"getPresetHeaders",(function(){return a.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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=function(l){if(l.id!=="inst")throw new o.ParseError("Unexpected chunk ID","'inst'","'".concat(l.id,"'"));if(l.length%a.SF_INSTRUMENT_HEADER_SIZE)throw new o.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 o=s("./src/chunks/instruments/headers.ts");s.d(r,"getInstrumentHeaders",(function(){return o.getInstrumentHeaders}))},"./src/chunks/modulators.ts":function(n,r,s){s.r(r),s.d(r,"getModulators",(function(){return l}));var o=s("./src/riff/index.ts"),a=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 o.ParseError("Unexpected chunk ID","'".concat(u,"'"),"'".concat(c.id,"'"));if(c.length%a.SF_MODULATOR_SIZE)throw new o.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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=function(l){if(l.id!=="phdr")throw new o.ParseError("Invalid chunk ID","'phdr'","'".concat(l.id,"'"));if(l.length%a.SF_PRESET_HEADER_SIZE)throw new o.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 o=s("./src/chunks/presets/headers.ts");s.d(r,"getPresetHeaders",(function(){return o.getPresetHeaders}))},"./src/chunks/samples/headers.ts":function(n,r,s){s.r(r),s.d(r,"getSampleHeaders",(function(){return i}));var o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=function(l){if(l.id!=="shdr")throw new o.ParseError("Unexpected chunk ID","'shdr'","'".concat(l.id,"'"));if(l.length%a.SF_SAMPLE_HEADER_SIZE)throw new o.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 o=s("./src/chunks/samples/headers.ts");s.d(r,"getSampleHeaders",(function(){return o.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 o=s("./src/riff/index.ts"),a=s("./src/constants.ts"),i=s("./src/types/index.ts"),l=function(d,p){if(d.id!==p)throw new o.ParseError("Unexpected chunk ID","'".concat(p,"'"),"'".concat(d.id,"'"));if(d.length%a.SF_BAG_SIZE)throw new o.ParseError("Invalid size for the '".concat(p,"' sub-chunk"));return d.iterate((function(v){return{generatorIndex:v.getInt16(),modulatorIndex:v.getInt16()}}))},c=function(d,p,v,y,m,b){for(var _=[],w=0;w<d.length;w++){for(var x=d[w],S=d[w+1],k=x.bagIndex,E=S?S.bagIndex:p.length,M=[],I=void 0,T=k;T<E;T++){var $=u(T,p,v),A=f(T,p,y),P=A[i.GeneratorType.KeyRange]&&A[i.GeneratorType.KeyRange].range,W=A[b];if(W){var J=m[W.value];J&&M.push({keyRange:P,modulators:$,generators:A,reference:J})}else T-k==0&&(I={keyRange:P,modulators:$,generators:A})}_.push({header:x,globalZone:I,zones:M})}return _},u=function(d,p,v){var y=p[d],m=p[d+1],b=y.modulatorIndex,_=m?m.modulatorIndex:p.length;return h(b,_,v)},f=function(d,p,v){var y=p[d],m=p[d+1],b=y.generatorIndex,_=m?m.generatorIndex:p.length;return h(b,_,v)},h=function(d,p,v){for(var y={},m=d;m<p;m++){var b=v[m];b&&(y[b.id]=b)}return y}},"./src/constants.ts":function(n,r,s){s.r(r),s.d(r,"SF_VERSION_LENGTH",(function(){return o})),s.d(r,"SF_PRESET_HEADER_SIZE",(function(){return a})),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 h}));var o=4,a=38,i=4,l=10,c=4,u=22,f=46,h=22050},"./src/index.ts":function(n,r,s){s.r(r);var o=s("./src/types/index.ts");for(var a in o)["default"].indexOf(a)<0&&(function(u){s.d(r,u,(function(){return o[u]}))})(a);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 o=s("./src/utils/index.ts");function a(u,f){if(!(u instanceof f))throw new TypeError("Cannot call a class as a function")}function i(u,f){for(var h=0;h<f.length;h++){var d=f[h];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,h){return f in u?Object.defineProperty(u,f,{value:h,enumerable:!0,configurable:!0,writable:!0}):u[f]=h,u}var c=(function(){function u(d){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;a(this,u),l(this,"target",[]),l(this,"chunk",void 0),l(this,"position",0),this.chunk=d,this.position=p}var f,h;return f=u,(h=[{key:"iterate",value:function(d){for(;this.position<this.chunk.length;){var p=d(this);p&&this.target.push(p)}}},{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:20,p=Object(o.getStringFromBuffer)(this.getBuffer(this.position,d));return this.position+=d,p}},{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,p){return this.chunk.buffer.subarray(d,d+p)}},{key:"currentPosition",get:function(){return this.position}}])&&i(f.prototype,h),u})()},"./src/riff/index.ts":function(n,r,s){s.r(r);var o=s("./src/riff/chunkIterator.ts");s.d(r,"ChunkIterator",(function(){return o.ChunkIterator}));var a=s("./src/riff/parseError.ts");s.d(r,"ParseError",(function(){return a.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 o(d){return(o=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(p){return typeof p}:function(p){return p&&typeof Symbol=="function"&&p.constructor===Symbol&&p!==Symbol.prototype?"symbol":typeof p})(d)}function a(d,p){return!p||o(p)!=="object"&&typeof p!="function"?(function(v){if(v===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return v})(d):p}function i(d){var p=typeof Map=="function"?new Map:void 0;return(i=function(v){if(v===null||(y=v,Function.toString.call(y).indexOf("[native code]")===-1))return v;var y;if(typeof v!="function")throw new TypeError("Super expression must either be null or a function");if(p!==void 0){if(p.has(v))return p.get(v);p.set(v,m)}function m(){return c(v,arguments,f(this).constructor)}return m.prototype=Object.create(v.prototype,{constructor:{value:m,enumerable:!1,writable:!0,configurable:!0}}),u(m,v)})(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,p,v){return(c=l()?Reflect.construct:function(y,m,b){var _=[null];_.push.apply(_,m);var w=new(Function.bind.apply(y,_));return b&&u(w,b.prototype),w}).apply(null,arguments)}function u(d,p){return(u=Object.setPrototypeOf||function(v,y){return v.__proto__=y,v})(d,p)}function f(d){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(p){return p.__proto__||Object.getPrototypeOf(p)})(d)}s.r(r),s.d(r,"ParseError",(function(){return h}));var h=(function(d){function p(v,y,m){return(function(b,_){if(!(b instanceof _))throw new TypeError("Cannot call a class as a function")})(this,p),a(this,f(p).call(this,"".concat(v).concat(y&&m?", expected ".concat(y,", received ").concat(m):"")))}return(function(v,y){if(typeof y!="function"&&y!==null)throw new TypeError("Super expression must either be null or a function");v.prototype=Object.create(y&&y.prototype,{constructor:{value:v,writable:!0,configurable:!0}}),y&&u(v,y)})(p,d),p})(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 h}));var o=s("./src/riff/parseError.ts"),a=s("./src/utils/buffer.ts"),i=s("./src/riff/riffChunk.ts"),l=function(d){var p=h(d);if(p!=="RIFF")throw new o.ParseError("Invalid file format","RIFF",p);var v=h(d,8);if(v!=="sfbk")throw new o.ParseError("Invalid signature","sfbk",v);var y=d.subarray(8),m=f(y.subarray(4));return new i.RIFFChunk(p,y.length,y,m)},c=function(d,p){var v=h(d,p),y=u(d,p+4),m=[];return v!=="RIFF"&&v!=="LIST"||(m=f(d.subarray(p+12))),new i.RIFFChunk(v,y,d.subarray(p+8),m)},u=function(d,p){return((d=d.subarray(p,p+4))[0]|d[1]<<8|d[2]<<16|d[3]<<24)>>>0},f=function(d){for(var p=[],v=0;v<=d.length-8;){var y=c(d,v);p.push(y),v=(v+=8+y.length)%2?v+1:v}return p},h=function(d){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;return Object(a.getStringFromBuffer)(d.subarray(p,p+4))}},"./src/riff/riffChunk.ts":function(n,r,s){s.r(r),s.d(r,"RIFFChunk",(function(){return c}));var o=s("./src/riff/chunkIterator.ts"),a=s("./src/utils/index.ts");function i(u,f){for(var h=0;h<f.length;h++){var d=f[h];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(u,d.key,d)}}function l(u,f,h){return f in u?Object.defineProperty(u,f,{value:h,enumerable:!0,configurable:!0,writable:!0}):u[f]=h,u}var c=(function(){function u(d,p,v,y){(function(m,b){if(!(m 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=p,this.buffer=v,this.subChunks=y}var f,h;return f=u,(h=[{key:"getString",value:function(){var d=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,p=arguments.length>1?arguments[1]:void 0;return Object(a.getStringFromBuffer)(this.getBuffer(d,p||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 o.ChunkIterator(this,d)}},{key:"iterate",value:function(d){var p=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,v=new o.ChunkIterator(this,p);return v.iterate(d),v.target}},{key:"getBuffer",value:function(d,p){return this.buffer.subarray(d,d+p)}}])&&i(f.prototype,h),u})()},"./src/soundFont2.ts":function(n,r,s){s.r(r),s.d(r,"SoundFont2",(function(){return p}));var o=s("./src/types/index.ts"),a=s("./src/chunk.ts"),i=s("./src/riff/index.ts"),l=s("./src/chunks/index.ts"),c=s("./src/utils/index.ts");function u(v){for(var y=1;y<arguments.length;y++){var m=arguments[y]!=null?arguments[y]:{},b=Object.keys(m);typeof Object.getOwnPropertySymbols=="function"&&(b=b.concat(Object.getOwnPropertySymbols(m).filter((function(_){return Object.getOwnPropertyDescriptor(m,_).enumerable})))),b.forEach((function(_){d(v,_,m[_])}))}return v}function f(v,y){for(var m=0;m<y.length;m++){var b=y[m];b.enumerable=b.enumerable||!1,b.configurable=!0,"value"in b&&(b.writable=!0),Object.defineProperty(v,b.key,b)}}function h(v,y,m){return y&&f(v.prototype,y),m&&f(v,m),v}function d(v,y,m){return y in v?Object.defineProperty(v,y,{value:m,enumerable:!0,configurable:!0,writable:!0}):v[y]=m,v}var p=(function(){function v(y){if((function(b,_){if(!(b instanceof _))throw new TypeError("Cannot call a class as a function")})(this,v),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),!(y instanceof a.SF2Chunk)){var m=Object(i.parseBuffer)(y);y=new a.SF2Chunk(m)}if(y.subChunks.length!==3)throw new i.ParseError("Invalid sfbk structure","3 chunks","".concat(y.subChunks.length," chunks"));this.chunk=y,this.metaData=y.subChunks[0].getMetaData(),this.sampleData=y.subChunks[1].getSampleData(),this.presetData=y.subChunks[2].getPresetData(),this.samples=this.getSamples(),this.instruments=this.getInstruments(),this.presets=this.getPresets(),this.banks=this.getBanks()}return h(v,null,[{key:"from",value:function(y){return new v(y)}}]),h(v,[{key:"getKeyData",value:function(y){var m=this,b=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,_=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;return Object(c.memoize)((function(w,x,S){var k=m.banks[x];if(k){var E=k.presets[S];if(E){var M=E.zones.filter((function(N){return m.isKeyInRange(N,w)}));if(M.length>0){var I=!0,T=!1,$=void 0;try{for(var A,P=M[Symbol.iterator]();!(I=(A=P.next()).done);I=!0){var W=A.value,J=W.instrument,G=J.zones.filter((function(N){return m.isKeyInRange(N,w)}));if(G.length>0){var Q=!0,ee=!1,z=void 0;try{for(var se,U=G[Symbol.iterator]();!(Q=(se=U.next()).done);Q=!0){var ie=se.value,le=ie.sample,ge=u({},W.generators,ie.generators),Se=u({},W.modulators,ie.modulators);return{keyNumber:w,preset:E,instrument:J,sample:le,generators:ge,modulators:Se}}}catch(N){ee=!0,z=N}finally{try{Q||U.return==null||U.return()}finally{if(ee)throw z}}}}}catch(N){T=!0,$=N}finally{try{I||P.return==null||P.return()}finally{if(T)throw $}}}}}return null}))(y,b,_)}},{key:"isKeyInRange",value:function(y,m){return y.keyRange===void 0||y.keyRange.lo<=m&&y.keyRange.hi>=m}},{key:"getBanks",value:function(){return this.presets.reduce((function(y,m){var b=m.header.bank;return y[b]||(y[b]={presets:[]}),y[b].presets[m.header.preset]=m,y}),[])}},{key:"getPresets",value:function(){var y=this.presetData,m=y.presetHeaders,b=y.presetZones,_=y.presetGenerators,w=y.presetModulators;return Object(l.getItemsInZone)(m,b,w,_,this.instruments,o.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 y=this.presetData,m=y.instrumentHeaders,b=y.instrumentZones,_=y.instrumentModulators,w=y.instrumentGenerators;return Object(l.getItemsInZone)(m,b,_,w,this.samples,o.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 y=this;return this.presetData.sampleHeaders.filter((function(m){return m.name!=="EOS"})).map((function(m){if(m.name!=="EOS"&&m.sampleRate<=0)throw new Error("Illegal sample rate of ".concat(m.sampleRate," hz in sample '").concat(m.name,"'"));return m.originalPitch>=128&&m.originalPitch<=254&&(m.originalPitch=60),m.startLoop-=m.start,m.endLoop-=m.start,{header:m,data:new Int16Array(new Uint8Array(y.sampleData.subarray(2*m.start,2*m.end)).buffer)}}))}}]),v})()},"./src/types/bank.ts":function(n,r){},"./src/types/generator.ts":function(n,r,s){var o,a;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 a})),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"})(a||(a={}));var l=(i(o={},a.StartAddrsOffset,0),i(o,a.EndAddrsOffset,0),i(o,a.StartLoopAddrsOffset,0),i(o,a.EndLoopAddrsOffset,0),i(o,a.StartAddrsCoarseOffset,0),i(o,a.ModLFOToPitch,0),i(o,a.VibLFOToPitch,0),i(o,a.ModEnvToPitch,0),i(o,a.InitialFilterFc,13500),i(o,a.InitialFilterQ,0),i(o,a.ModLFOToFilterFc,0),i(o,a.ModEnvToFilterFc,0),i(o,a.EndAddrsCoarseOffset,0),i(o,a.ModLFOToVolume,0),i(o,a.ChorusEffectsSend,0),i(o,a.ReverbEffectsSend,0),i(o,a.Pan,0),i(o,a.DelayModLFO,-12e3),i(o,a.FreqModLFO,0),i(o,a.DelayVibLFO,-12e3),i(o,a.FreqVibLFO,0),i(o,a.DelayModEnv,-12e3),i(o,a.AttackModEnv,-12e3),i(o,a.HoldModEnv,-12e3),i(o,a.DecayModEnv,-12e3),i(o,a.SustainModEnv,0),i(o,a.ReleaseModEnv,-12e3),i(o,a.KeyNumToModEnvHold,0),i(o,a.KeyNumToModEnvDecay,0),i(o,a.DelayVolEnv,-12e3),i(o,a.AttackVolEnv,-12e3),i(o,a.HoldVolEnv,-12e3),i(o,a.DecayVolEnv,-12e3),i(o,a.SustainVolEnv,0),i(o,a.ReleaseVolEnv,-12e3),i(o,a.KeyNumToVolEnvHold,0),i(o,a.KeyNumToVolEnvDecay,0),i(o,a.StartLoopAddrsCoarseOffset,0),i(o,a.KeyNum,-1),i(o,a.Velocity,-1),i(o,a.InitialAttenuation,0),i(o,a.EndLoopAddrsCoarseOffset,0),i(o,a.CoarseTune,0),i(o,a.FineTune,0),i(o,a.SampleModes,0),i(o,a.ScaleTuning,100),i(o,a.ExclusiveClass,0),i(o,a.OverridingRootKey,-1),o)},"./src/types/index.ts":function(n,r,s){s.r(r);var o=s("./src/types/bank.ts");for(var a in o)["default"].indexOf(a)<0&&(function(y){s.d(r,y,(function(){return o[y]}))})(a);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 a in l)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return l[m]}))})(a);var c=s("./src/types/key.ts");for(var a in c)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return c[m]}))})(a);var u=s("./src/types/metaData.ts");for(var a in u)["default","GeneratorType","DEFAULT_GENERATOR_VALUES"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return u[m]}))})(a);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 h=s("./src/types/preset.ts");for(var a in h)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return h[m]}))})(a);var d=s("./src/types/presetData.ts");for(var a in d)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return d[m]}))})(a);var p=s("./src/types/sample.ts");s.d(r,"SampleType",(function(){return p.SampleType}));var v=s("./src/types/zone.ts");for(var a in v)["default","GeneratorType","DEFAULT_GENERATOR_VALUES","ControllerType","ControllerPolarity","ControllerDirection","ControllerPalette","Controller","TransformType","DEFAULT_INSTRUMENT_MODULATORS","SampleType"].indexOf(a)<0&&(function(m){s.d(r,m,(function(){return v[m]}))})(a)},"./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 o})),s.d(r,"ControllerPolarity",(function(){return a})),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 h}));var o,a,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"})(o||(o={})),(function(d){d[d.Unipolar=0]="Unipolar",d[d.Bipolar=1]="Bipolar"})(a||(a={})),(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 h=[{id:f.GeneratorType.InitialAttenuation,source:{type:o.Concave,polarity:a.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:960,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialFilterFc,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Decreasing,palette:l.GeneralController,index:c.NoteOnVelocity},value:-2400,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.ChannelPressure},value:50,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.VibLFOToPitch,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.MidiController,index:1},value:50,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:o.Concave,polarity:a.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:7},value:960,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:o.Linear,polarity:a.Bipolar,direction:i.Increasing,palette:l.MidiController,index:10},value:1e3,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.InitialAttenuation,source:{type:o.Concave,polarity:a.Unipolar,direction:i.Decreasing,palette:l.MidiController,index:11},value:960,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ReverbEffectsSend,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.MidiController,index:91},value:200,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.ChorusEffectsSend,source:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.MidiController,index:93},value:200,valueSource:{type:o.Linear,polarity:a.Unipolar,direction:i.Increasing,palette:l.GeneralController,index:c.NoController},transform:u.Linear},{id:f.GeneratorType.CoarseTune,source:{type:o.Linear,polarity:a.Bipolar,direction:i.Increasing,palette:l.GeneralController,index:c.PitchWheel},value:12700,valueSource:{type:o.Linear,polarity:a.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 o;s.r(r),s.d(r,"SampleType",(function(){return o})),(function(a){a[a.EOS=0]="EOS",a[a.Mono=1]="Mono",a[a.Right=2]="Right",a[a.Left=4]="Left",a[a.Linked=8]="Linked",a[a.RomMono=32769]="RomMono",a[a.RomRight=32770]="RomRight",a[a.RomLeft=32772]="RomLeft",a[a.RomLinked=32776]="RomLinked"})(o||(o={}))},"./src/types/zone.ts":function(n,r){},"./src/utils/buffer.ts":function(n,r,s){s.r(r),s.d(r,"getStringFromBuffer",(function(){return o}));var o=function(a){var i=new TextDecoder("utf8").decode(a),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 o=s("./src/utils/buffer.ts");s.d(r,"getStringFromBuffer",(function(){return o.getStringFromBuffer}));var a=s("./src/utils/memoize.ts");s.d(r,"memoize",(function(){return a.memoize}))},"./src/utils/memoize.ts":function(n,r,s){s.r(r),s.d(r,"memoize",(function(){return o}));var o=function(a){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 h=a.apply(void 0,c);return i[f]=h,h}}}})}))})(oo)),oo.exports}Ff();var Le=1e3;function Co(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:s=1,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h}=e,d=t?.sampleRate??e.sampleRate??c?.sample_rate,p=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(p===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 v=e.durationSamples??p;return{id:Ql(),audioBuffer:t,startSample:n,durationSamples:v,offsetSamples:r,sampleRate:d,sourceDurationSamples:p,gain:s,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h}}function ql(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:s=1,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h}=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 p=t?.duration??e.sourceDuration??c?.duration;if(p===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 v=e.duration??p;return Co({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(v*d),offsetSamples:Math.round(r*d),sampleRate:d,sourceDurationSamples:Math.ceil(p*d),gain:s,name:o,color:a,fadeIn:i,fadeOut:l,waveformData:c,midiNotes:u,midiChannel:f,midiProgram:h})}function Jl(e){const{name:t,clips:n=[],muted:r=!1,soloed:s=!1,volume:o=1,pan:a=0,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}=e;return{id:Ql(),name:t,clips:n,muted:r,soloed:s,volume:o,pan:a,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}}function Ql(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Ki(e){return[...e].sort((t,n)=>t.startSample-n.startSample)}function Yr(e){return e.startSample/e.sampleRate}function qi(e){return(e.startSample+e.durationSamples)/e.sampleRate}function Ji(e){return e.offsetSamples/e.sampleRate}function Qi(e){return e.durationSamples/e.sampleRate}function ec(e,t,n){return Math.floor((e+t)/n)-Math.floor(e/n)}var el=!1;function wr(e){const t=e._param;return!t&&!el&&(el=!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 tl(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const o=s/r;n[s]=t?o:1-o}return n}function Of(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const o=s/r,a=t?s:e-1-s;n[a]=Math.exp(2*o-1)/Math.E}return n}function Lf(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 Wf(e,t,n=10){const r=new Float32Array(e);for(let s=0;s<e;s++){const o=t?s:e-1-s,a=s/e;r[o]=Math.log(1+n*a)/Math.log(1+n)}return r}function tc(e,t,n){switch(e){case"linear":return tl(t,n);case"exponential":return Of(t,n);case"sCurve":return Lf(t,n);case"logarithmic":return Wf(t,n);default:return tl(t,n)}}function nl(e,t,n,r="linear",s=0,o=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(o,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(o,.001),t+n);else{const a=tc(r,1e4,!0),i=new Float32Array(a.length),l=o-s;for(let c=0;c<a.length;c++)i[c]=s+a[c]*l;e.setValueCurveAtTime(i,t,n)}}function rl(e,t,n,r="linear",s=1,o=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(o,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(o,.001),t+n);else{const a=tc(r,1e4,!1),i=new Float32Array(a.length),l=s-o;for(let c=0;c<a.length;c++)i[c]=o+a[c]*l;e.setValueCurveAtTime(i,t,n)}}var Bf=class{constructor(e){this.activeSources=new Set,this._scheduleGuardOffset=0,this.track=e.track,this.volumeNode=new F.Volume(this.gainToDb(e.track.gain)),this.panNode=new F.Panner(e.track.stereoPan),this.muteGain=new F.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const t=e.destination||F.getDestination();if(e.effects){const a=e.effects(this.muteGain,t,!1);a&&(this.effectsCleanup=a)}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=F.getTransport(),s=F.getContext().rawContext,o=this.volumeNode.input.input;this.scheduledClips=n.map(a=>{const i=s.createGain();i.gain.value=a.gain,i.connect(o);const l=this.track.startTime+a.startTime,c=r.schedule(u=>{l<this._scheduleGuardOffset||this.startClipSource(a,i,u)},l);return{clipInfo:a,fadeGainNode:i,scheduleId:c}})}startClipSource(e,t,n,r,s){const a=F.getContext().rawContext.createBufferSource();a.buffer=e.buffer,a.connect(t);const i=r??e.offset,l=s??e.duration;try{a.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),a.disconnect();return}this.activeSources.add(a),a.onended=()=>{this.activeSources.delete(a)}}setScheduleGuardOffset(e){this._scheduleGuardOffset=e}startMidClipSources(e,t){for(const{clipInfo:n,fadeGainNode:r}of this.scheduledClips){const s=this.track.startTime+n.startTime,o=s+n.duration;if(s<e&&o>e){const a=e-s,i=n.offset+a,l=n.duration-a;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,o=s.gain;o.cancelScheduledValues(0);const a=n-r.offset;if(r.fadeIn&&a<r.fadeIn.duration){const i=r.fadeIn.duration;if(a<=0)nl(o,t,i,r.fadeIn.type||"linear",0,r.gain);else{const l=i-a,c=a/i,u=r.gain*c;nl(o,t,l,r.fadeIn.type||"linear",u,r.gain)}}else o.setValueAtTime(r.gain,t);if(r.fadeOut){const l=r.duration-r.fadeOut.duration-a;if(l>0){const c=t+l;rl(o,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,h=r.gain*(1-f);rl(o,t,u,r.fadeOut.type||"linear",h,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 o=t-r+n.clipInfo.offset;this.scheduleFades(n,e,o)}else{const o=r-t;this.scheduleFades(n,e+o,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;wr(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){const e=F.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 Vf(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 Nf=class{constructor(e){this.track=e.track,this.volumeNode=new F.Volume(this.gainToDb(e.track.gain)),this.panNode=new F.Panner(e.track.stereoPan),this.muteGain=new F.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain),this.synth=new F.PolySynth(F.Synth,e.synthOptions),this.synth.connect(this.volumeNode),this.kickSynth=new F.PolySynth(F.MembraneSynth,{voice:F.MembraneSynth,options:{pitchDecay:.05,octaves:6,envelope:{attack:.001,decay:.4,sustain:0,release:.1}}}),this.snareSynth=new F.NoiseSynth({noise:{type:"white"},envelope:{attack:.001,decay:.15,sustain:0,release:.05}}),this.cymbalSynth=new F.PolySynth(F.MetalSynth,{voice:F.MetalSynth,options:{envelope:{attack:.001,decay:.3,release:.1},harmonicity:5.1,modulationIndex:32,resonance:4e3,octaves:1.5}}),this.tomSynth=new F.PolySynth(F.MembraneSynth,{voice:F.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||F.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,o=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}}),a=new F.Part((i,l)=>{l.duration>0&&this.triggerNote(l.midi,l.note,l.duration,i,l.velocity,l.channel)},o);return a.start(0),{clipInfo:n,part:a}})}triggerNote(e,t,n,r,s,o){if(o===9)switch(Vf(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 o of n.notes){const a=o.time-n.offset,i=r+Math.max(0,a),l=i+o.duration;if(i<e&&l>e){const c=l-e;try{this.triggerNote(o.midi,o.name,c,t,o.velocity,o.channel)}catch(u){console.warn(`[waveform-playlist] Failed to start mid-clip MIDI note "${o.name}" on track "${this.id}":`,u)}}}}}stopAllSources(){const e=F.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;wr(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}},nc=class So{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 F.Volume(this.gainToDb(t.track.gain)),this.panNode=new F.Panner(t.track.stereoPan),this.muteGain=new F.Gain(t.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const n=t.destination||F.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}),o=this.track.startTime+r.startTime,a=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:o+u,note:l.name,midi:l.midi,duration:Math.max(0,f),velocity:l.velocity,channel:l.channel}}),i=new F.Part((l,c)=>{c.duration>0&&this.triggerNote(c.midi,c.duration,l,c.velocity,c.channel)},a);return i.start(0),{clipInfo:r,part:i}})}triggerNote(t,n,r,s,o){const a=o===9?128:this.bankNumber,i=o===9?0:this.programNumber,l=this.soundFontCache.getAudioBuffer(t,a,i);if(!l){So._missingSampleWarned||(console.warn(`[waveform-playlist] SoundFont sample not found for MIDI note ${t} (bank ${a}, preset ${i}). Subsequent missing samples will be silent.`),So._missingSampleWarned=!0);return}const c=F.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,h=l.loopMode===0?Math.max(n,f):n,d=s*s,p=c.createGain(),{attackVolEnv:v,holdVolEnv:y,decayVolEnv:m,sustainVolEnv:b,releaseVolEnv:_}=l,w=d*b;p.gain.setValueAtTime(0,r),p.gain.linearRampToValueAtTime(d,r+v),y>.001&&p.gain.setValueAtTime(d,r+v+y);const x=r+v+y;p.gain.linearRampToValueAtTime(w,x+m),p.gain.setValueAtTime(w,r+h),p.gain.linearRampToValueAtTime(0,r+h+_),u.connect(p),p.connect(this.volumeNode.input.input),this.activeSources.add(u),u.onended=()=>{this.activeSources.delete(u);try{p.disconnect()}catch(S){console.warn("[waveform-playlist] GainNode already disconnected:",S)}},u.start(r),u.stop(r+h+_)}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,o=s+r.duration;if(s<t&&o>t)for(const a of r.notes){const i=a.time-r.offset,l=s+Math.max(0,i),c=l+a.duration;if(l<t&&c>t){const u=c-t;try{this.triggerNote(a.midi,u,n,a.velocity,a.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;wr(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}};nc._missingSampleWarned=!1;var zf=nc,jf=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 F.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,F.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{F.getTransport().clear(this._completionEventId)}catch(e){console.warn("[waveform-playlist] Error clearing Transport completion event:",e)}this._completionEventId=null}}async init(){this.isInitialized||(await F.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new Bf(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 Nf(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 zf(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??F.now(),s=F.getTransport();this.clearCompletionEvent();const o=t??0;this.tracks.forEach(a=>{a.cancelFades(),a.prepareFades(r,o)}),n!==void 0&&(this._completionEventId=s.scheduleOnce(()=>{this._completionEventId=null;try{this.onPlaybackCompleteCallback?.()}catch(a){console.warn("[waveform-playlist] Error in playback completion callback:",a)}},o+n));try{s.state!=="stopped"&&s.stop(),this.tracks.forEach(a=>a.stopAllSources()),s.loopStart=this._loopStart,s.loopEnd=this._loopEnd,s.loop=this._loopEnabled,this.tracks.forEach(a=>a.setScheduleGuardOffset(o)),t!==void 0?s.start(r,t):s.start(r),s._clock._lastUpdate=r,this.tracks.forEach(a=>{a.startMidClipSources(o,r)})}catch(a){throw this.clearCompletionEvent(),this.tracks.forEach(i=>i.cancelFades()),console.warn("[waveform-playlist] Transport.start() failed. Audio playback could not begin.",a),a}}pause(){const e=F.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=F.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=F.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=F.now();this.tracks.forEach(o=>{try{o.stopAllSources(),o.cancelFades(),o.setScheduleGuardOffset(this._loopStart),o.startMidClipSources(this._loopStart,s),o.prepareFades(s,this._loopStart)}catch(a){console.warn(`[waveform-playlist] Error re-scheduling track "${o.id}" on loop:`,a)}})},r.on("loop",this._loopHandler)):!e&&this._loopHandler&&(r.off("loop",this._loopHandler),this._loopHandler=null)}getCurrentTime(){return F.getTransport().seconds}seekTo(e){F.getTransport().seconds=e}dispose(){if(this.clearCompletionEvent(),this._loopHandler){try{F.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 F.getContext()}get sampleRate(){return F.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Kr=null;function Zf(){return Kr||(Kr=new F.Context,F.setContext(Kr)),Kr}function Hf(){return Zf().rawContext}function Gf(e){let t=null,n=!1,r=0,s=!1,o=0,a=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 jf({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 h=f.clips.filter(p=>p.audioBuffer&&!p.midiNotes),d=f.clips.filter(p=>p.midiNotes&&p.midiNotes.length>0);if(h.length>0){const p=Math.min(...h.map(Yr)),v=Math.max(...h.map(qi)),y={id:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:p,endTime:v},m=h.map(b=>({buffer:b.audioBuffer,startTime:Yr(b)-p,duration:Qi(b),offset:Ji(b),fadeIn:b.fadeIn,fadeOut:b.fadeOut,gain:b.gain}));t.addTrack({clips:m,track:y,effects:f.effects})}if(d.length>0){const p=Math.min(...d.map(Yr)),v=Math.max(...d.map(qi)),m={id:h.length>0?`${f.id}:midi`:f.id,name:f.name,gain:f.volume,muted:f.muted,soloed:f.soloed,stereoPan:f.pan,startTime:p,endTime:v},b=d.map(_=>({notes:_.midiNotes,startTime:Yr(_)-p,duration:Qi(_),offset:Ji(_)}));if(e?.soundFontCache?.isLoaded){const _=d[0],x=_.midiChannel===9,S=_.midiProgram??0;t.addSoundFontTrack({clips:b,track:m,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:m,effects:f.effects})}}t.applyInitialSoloState(),t.setLoop(s,o,a),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(F.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,o=u,a=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 rc(e,t,n,r){let s=t;const o=-e.startSample;if(s=Math.max(s,o),r>0){const a=n[r-1],l=a.startSample+a.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 sc(e,t,n,r,s,o){let a=t;if(n==="left"){if(a=Math.max(a,-e.startSample),a=Math.max(a,-e.offsetSamples),s>0){const i=r[s-1],l=i.startSample+i.durationSamples;a=Math.max(a,l-e.startSample)}a=Math.min(a,e.durationSamples-o)}else if(a=Math.max(a,o-e.durationSamples),a=Math.min(a,e.sourceDurationSamples-e.offsetSamples-e.durationSamples),s<r.length-1){const i=r[s+1];a=Math.min(a,i.startSample-e.startSample-e.durationSamples)}return a}function Uf(e,t){return Math.floor(e/t)*t}function Xf(e,t){const n=t-e.startSample,r=e.durationSamples-n,s=e.name?`${e.name} (1)`:void 0,o=e.name?`${e.name} (2)`:void 0,a=Co({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=Co({startSample:t,durationSamples:r,offsetSamples:e.offsetSamples+n,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:o,color:e.color,fadeOut:e.fadeOut,audioBuffer:e.audioBuffer,waveformData:e.waveformData});return{left:a,right:i}}function oc(e,t,n){const r=e.startSample+e.durationSamples;if(t<=e.startSample||t>=r)return!1;const s=t-e.startSample,o=r-t;return s>=n&&o>=n}function ao(e){let t=0;for(const n of e)for(const r of n.clips){const o=(r.startSample+r.durationSamples)/r.sampleRate;t=Math.max(t,o)}return t}function Yf(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 o=Math.abs(t[s]-e);o<r&&(r=o,n=s)}return n}function sl(e,t){return Math.max(0,Math.min(e,t))}var Kf=44100,qf=1024,Jf=[256,512,1024,2048,4096,8192],ol=.1,Qf=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??Kf,this._zoomLevels=[...e.zoomLevels??Jf],this._adapter=e.adapter??null,this._zoomLevels.length===0)throw new Error("PlaylistEngine: zoomLevels must not be empty");const t=e.samplesPerPixel??qf,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:ao(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 o=r.clips[s],a=Ki(r.clips),i=a.findIndex(c=>c.id===t),l=rc(o,n,a,i);l!==0&&(this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=c.clips.map((f,h)=>h===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 o=r.clips[s],a=Math.floor(ol*this._sampleRate);if(!oc(o,n,a)){console.warn(`[waveform-playlist/engine] splitClip: cannot split clip "${t}" at sample ${n} (clip range: ${o.startSample}–${o.startSample+o.durationSamples}, minDuration: ${a})`);return}const{left:i,right:l}=Xf(o,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 o=s.clips.findIndex(f=>f.id===t);if(o===-1){console.warn(`[waveform-playlist/engine] trimClip: clip "${t}" not found in track "${e}"`);return}const a=s.clips[o],i=Ki(s.clips),l=i.findIndex(f=>f.id===t),c=Math.floor(ol*this._sampleRate),u=sc(a,r,n,i,l,c);u!==0&&(this._tracks=this._tracks.map(f=>{if(f.id!==e)return f;const h=f.clips.map((d,p)=>p!==o?d:n==="left"?{...d,startSample:d.startSample+u,offsetSamples:d.offsetSamples+u,durationSamples:d.durationSamples-u}:{...d,durationSamples:d.durationSamples+u});return{...f,clips:h}}),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=ao(this._tracks);this._currentTime=sl(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=ao(this._tracks);this._currentTime=sl(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=Yf(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)}},eh=Symbol.for("preact-signals");function Fs(){if(Jt>1)Jt--;else{for(var e,t=!1;pr!==void 0;){var n=pr;for(pr=void 0,ko++;n!==void 0;){var r=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&ic(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ko=0,Jt--,t)throw e}}function Qt(e){if(Jt>0)return e();Jt++;try{return e()}finally{Fs()}}var me=void 0;function we(e){var t=me;me=void 0;try{return e()}finally{me=t}}var pr=void 0,Jt=0,ko=0,vs=0;function ac(e){if(me!==void 0){var t=e.n;if(t===void 0||t.t!==me)return t={i:0,S:e,p:me.s,n:void 0,t:me,e:void 0,x:void 0,r:t},me.s!==void 0&&(me.s.n=t),me.s=t,e.n=t,32&me.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=me.s,t.n=void 0,me.s.n=t,me.s=t),t}}function st(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}st.prototype.brand=eh;st.prototype.h=function(){return!0};st.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:we(function(){var r;(r=t.W)==null||r.call(t)}))};st.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&&we(function(){var s;(s=t.Z)==null||s.call(t)}))}};st.prototype.subscribe=function(e){var t=this;return Ct(function(){var n=t.value,r=me;me=void 0;try{e(n)}finally{me=r}},{name:"sub"})};st.prototype.valueOf=function(){return this.value};st.prototype.toString=function(){return this.value+""};st.prototype.toJSON=function(){return this.value};st.prototype.peek=function(){var e=me;me=void 0;try{return this.value}finally{me=e}};Object.defineProperty(st.prototype,"value",{get:function(){var e=ac(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ko>100)throw new Error("Cycle detected");this.v=e,this.i++,vs++,Jt++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Fs()}}}});function $r(e,t){return new st(e,t)}function ic(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 lc(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 cc(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 yn(e,t){st.call(this,void 0),this.x=e,this.s=void 0,this.g=vs-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}yn.prototype=new st;yn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===vs))return!0;if(this.g=vs,this.f|=1,this.i>0&&!ic(this))return this.f&=-2,!0;var e=me;try{lc(this),me=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 me=e,cc(this),this.f&=-2,!0};yn.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)}st.prototype.S.call(this,e)};yn.prototype.U=function(e){if(this.t!==void 0&&(st.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)}};yn.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(yn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=ac(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function al(e,t){return new yn(e,t)}function uc(e){var t=e.u;if(e.u=void 0,typeof t=="function"){Jt++;var n=me;me=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,da(e),r}finally{me=n,Fs()}}}function da(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,uc(e)}function th(e){if(me!==this)throw new Error("Out-of-order effect");cc(this),me=e,this.f&=-2,8&this.f&&da(this),Fs()}function jn(e,t){this.x=e,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}jn.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()}};jn.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,uc(this),lc(this),Jt++;var e=me;return me=this,th.bind(this,e)};jn.prototype.N=function(){2&this.f||(this.f|=2,this.o=pr,pr=this)};jn.prototype.d=function(){this.f|=8,1&this.f||da(this)};jn.prototype.dispose=function(){this.d()};function Ct(e,t){var n=new jn(e,t);try{n.c()}catch(s){throw n.d(),s}var r=n.d.bind(n);return r[Symbol.dispose]=r,r}var nh=Object.create,fa=Object.defineProperty,rh=Object.defineProperties,sh=Object.getOwnPropertyDescriptor,oh=Object.getOwnPropertyDescriptors,il=Object.getOwnPropertySymbols,ah=Object.prototype.hasOwnProperty,ih=Object.prototype.propertyIsEnumerable,lh=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zn=e=>{throw TypeError(e)},Eo=(e,t,n)=>t in e?fa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ch=(e,t)=>{for(var n in t||(t={}))ah.call(t,n)&&Eo(e,n,t[n]);if(il)for(var n of il(t))ih.call(t,n)&&Eo(e,n,t[n]);return e},uh=(e,t)=>rh(e,oh(t)),ll=(e,t)=>fa(e,"name",{value:t,configurable:!0}),dh=e=>{var t;return[,,,nh((t=void 0)!=null?t:null)]},dc=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Zn("Function expected"):e,fh=(e,t,n,r,s)=>({kind:dc[e],name:t,metadata:r,addInitializer:o=>n._?Zn("Already initialized"):s.push(rr(o||null))}),fc=(e,t)=>Eo(t,lh("metadata"),e[3]),an=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},Hn=(e,t,n,r,s,o)=>{var a,i,l,c,u,f=t&7,h=!!(t&8),d=!!(t&16),p=f>3?e.length+1:f?h?1:2:0,v=dc[f+5],y=f>3&&(e[p-1]=[]),m=e[p]||(e[p]=[]),b=f&&(!d&&!h&&(s=s.prototype),f<5&&(f>3||!d)&&sh(f<4?s:{get[n](){return pn(this,o)},set[n](w){return Yt(this,o,w)}},n));f?d&&f<4&&ll(o,(f>2?"set ":f>1?"get ":"")+n):ll(s,n);for(var _=r.length-1;_>=0;_--)c=fh(f,n,l={},e[3],m),f&&(c.static=h,c.private=d,u=c.access={has:d?w=>hh(s,w):w=>n in w},f^3&&(u.get=d?w=>(f^1?pn:ph)(w,s,f^4?o:b.get):w=>w[n]),f>2&&(u.set=d?(w,x)=>Yt(w,s,x,f^4?o:b.set):(w,x)=>w[n]=x)),i=(0,r[_])(f?f<4?d?o:b[v]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?rr(i)&&(f>4?y.unshift(i):f?d?o=i:b[v]=i:s=i):typeof i!="object"||i===null?Zn("Object expected"):(rr(a=i.get)&&(b.get=a),rr(a=i.set)&&(b.set=a),rr(a=i.init)&&y.unshift(a));return f||fc(e,s),b&&fa(s,n,b),d?f^4?o:b:s},ha=(e,t,n)=>t.has(e)||Zn("Cannot "+n),hh=(e,t)=>Object(t)!==t?Zn('Cannot use the "in" operator on this value'):e.has(t),pn=(e,t,n)=>(ha(e,t,"read from private field"),n?n.call(e):t.get(e)),qr=(e,t,n)=>t.has(e)?Zn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Yt=(e,t,n,r)=>(ha(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),ph=(e,t,n)=>(ha(e,t,"access private method"),n);function ys(e,t){if(t){let n;return al(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return al(e)}function _r(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)=>!_r(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(o=>!_r(e[o],t[o]))}return!1}function de({get:e},t){return{init(n){return $r(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ie(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=ys(e.bind(this)),n.set(this,r)),r.value}}function io(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,uh(ch({},s),{enumerable:e}))})}}function Rr(...e){const t=e.map(n=>Ct(n));return()=>t.forEach(n=>n())}var hc,pc,mc,gc,vc,yc,tt,pa,lo,Io,Mo,qe,ma,co,bc,Ao,ga,uo,To,$o;yc=[de],vc=[de],gc=[de],mc=[io()],pc=[io()],hc=[io()];var tn=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,an(tt,5,this),qr(this,qe),qr(this,pa,an(tt,8,this)),an(tt,11,this),qr(this,ma,an(tt,12,this)),an(tt,15,this),qr(this,ga,an(tt,16,this)),an(tt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return pn(this,qe,To)}get initial(){return pn(this,qe,Io)}get previous(){return pn(this,qe,bc)}set current(e){const t=we(()=>pn(this,qe,To));e&&t&&this.equals(t,e)||Qt(()=>{pn(this,qe,Io)||Yt(this,qe,e,Mo),Yt(this,qe,t,Ao),Yt(this,qe,e,$o)})}reset(e=this.defaultValue){Qt(()=>{Yt(this,qe,void 0,Ao),Yt(this,qe,e,Mo),Yt(this,qe,e,$o)})}};tt=dh();pa=new WeakMap;qe=new WeakSet;ma=new WeakMap;ga=new WeakMap;lo=Hn(tt,20,"#initial",yc,qe,pa),Io=lo.get,Mo=lo.set;co=Hn(tt,20,"#previous",vc,qe,ma),bc=co.get,Ao=co.set;uo=Hn(tt,20,"#current",gc,qe,ga),To=uo.get,$o=uo.set;Hn(tt,2,"current",mc,tn);Hn(tt,2,"initial",pc,tn);Hn(tt,2,"previous",hc,tn);fc(tt,tn);function fo(e){return we(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var mh=Object.create,wc=Object.defineProperty,gh=Object.getOwnPropertyDescriptor,cl=Object.getOwnPropertySymbols,vh=Object.prototype.hasOwnProperty,yh=Object.prototype.propertyIsEnumerable,_c=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Os=e=>{throw TypeError(e)},ul=Math.pow,Ro=(e,t,n)=>t in e?wc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,bh=(e,t)=>{for(var n in t||(t={}))vh.call(t,n)&&Ro(e,n,t[n]);if(cl)for(var n of cl(t))yh.call(t,n)&&Ro(e,n,t[n]);return e},wh=e=>{var t;return[,,,mh((t=e?.[_c("metadata")])!=null?t:null)]},xc=["class","method","getter","setter","accessor","field","value","get","set"],Cc=e=>e!==void 0&&typeof e!="function"?Os("Function expected"):e,_h=(e,t,n,r,s)=>({kind:xc[e],name:t,metadata:r,addInitializer:o=>n._?Os("Already initialized"):s.push(Cc(o||null))}),xh=(e,t)=>Ro(t,_c("metadata"),e[3]),Ch=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)o[s].call(n);return r},Sc=(e,t,n,r,s,o)=>{for(var a,i,l,c,u=t&7,f=!1,h=!1,d=2,p=xc[u+5],v=e[d]||(e[d]=[]),y=(s=s.prototype,gh(s,n)),m=r.length-1;m>=0;m--)l=_h(u,n,i={},e[3],v),l.static=f,l.private=h,c=l.access={has:b=>n in b},c.get=b=>b[n],a=(0,r[m])(y[p],l),i._=1,Cc(a)&&(y[p]=a);return y&&wc(s,n,y),s},kc=(e,t,n)=>t.has(e)||Os("Cannot "+n),Sh=(e,t,n)=>(kc(e,t,"read from private field"),t.get(e)),kh=(e,t,n)=>t.has(e)?Os("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Eh=(e,t,n,r)=>(kc(e,t,"write to private field"),t.set(e,n),n),Pt=class Do{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Do(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 Do(t,n)}},Dr=class cn{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:o,height:a,scale:i}=this,l=new cn(s+t,r+n,o,a);return l.scale=bh({},i),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:o,bottom:a}=this;return{width:t,height:n,left:r,top:s,right:o,bottom:a}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Pt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof cn))return!1;const{left:n,top:r,width:s,height:o}=this;return n===t.left&&r===t.top&&s===t.width&&o===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:o}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=o}intersectionArea(t){return t instanceof cn?Ih(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 cn(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(o,a)=>{const i=r[a],l=a==="x"?o.left:o.top,c=a==="x"?o.width:o.height;return i=="start"?l:i=="end"?l+c:l+c/2};return Pt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return cn.from(t).intersectionRatio(cn.from(n))}};function Ih(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),o=Math.min(t.top+t.height,e.top+e.height),a=s-r,i=o-n;return r<s&&n<o?a*i:0}var Ec,Ic,Po,ss,Pr,Ls=class extends(Po=tn,Ic=[Ie],Ec=[Ie],Po){constructor(t){const n=Pt.from(t);super(n,(r,s)=>Pt.equals(r,s)),Ch(Pr,5,this),kh(this,ss,0),this.velocity={x:0,y:0}}get delta(){return Pt.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=Pt.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),a=o-Sh(this,ss),i=l=>Math.round(l/a*100);Qt(()=>{Eh(this,ss,o),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Pt.from(t)),this.velocity={x:0,y:0}}};Pr=wh(Po);ss=new WeakMap;Sc(Pr,2,"delta",Ic,Ls);Sc(Pr,2,"direction",Ec,Ls);xh(Pr,Ls);function Fo({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(ul(r,2)+ul(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 Mc=(e=>(e.Horizontal="x",e.Vertical="y",e))(Mc||{}),Ac=Object.values(Mc),Mh=Object.create,va=Object.defineProperty,Ah=Object.defineProperties,Th=Object.getOwnPropertyDescriptor,$h=Object.getOwnPropertyDescriptors,bs=Object.getOwnPropertySymbols,Tc=Object.prototype.hasOwnProperty,$c=Object.prototype.propertyIsEnumerable,Rc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Gn=e=>{throw TypeError(e)},Oo=(e,t,n)=>t in e?va(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Dc=(e,t)=>{for(var n in t||(t={}))Tc.call(t,n)&&Oo(e,n,t[n]);if(bs)for(var n of bs(t))$c.call(t,n)&&Oo(e,n,t[n]);return e},Pc=(e,t)=>Ah(e,$h(t)),dl=(e,t)=>va(e,"name",{value:t,configurable:!0}),Fc=(e,t)=>{var n={};for(var r in e)Tc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&bs)for(var r of bs(e))t.indexOf(r)<0&&$c.call(e,r)&&(n[r]=e[r]);return n},Un=e=>{var t;return[,,,Mh((t=e?.[Rc("metadata")])!=null?t:null)]},Oc=["class","method","getter","setter","accessor","field","value","get","set"],sr=e=>e!==void 0&&typeof e!="function"?Gn("Function expected"):e,Rh=(e,t,n,r,s)=>({kind:Oc[e],name:t,metadata:r,addInitializer:o=>n._?Gn("Already initialized"):s.push(sr(o||null))}),bn=(e,t)=>Oo(t,Rc("metadata"),e[3]),re=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},ue=(e,t,n,r,s,o)=>{var a,i,l,c,u,f=t&7,h=!!(t&8),d=!!(t&16),p=f>3?e.length+1:f?h?1:2:0,v=Oc[f+5],y=f>3&&(e[p-1]=[]),m=e[p]||(e[p]=[]),b=f&&(!d&&!h&&(s=s.prototype),f<5&&(f>3||!d)&&Th(f<4?s:{get[n](){return He(this,o)},set[n](w){return wt(this,o,w)}},n));f?d&&f<4&&dl(o,(f>2?"set ":f>1?"get ":"")+n):dl(s,n);for(var _=r.length-1;_>=0;_--)c=Rh(f,n,l={},e[3],m),f&&(c.static=h,c.private=d,u=c.access={has:d?w=>Dh(s,w):w=>n in w},f^3&&(u.get=d?w=>(f^1?He:Ph)(w,s,f^4?o:b.get):w=>w[n]),f>2&&(u.set=d?(w,x)=>wt(w,s,x,f^4?o:b.set):(w,x)=>w[n]=x)),i=(0,r[_])(f?f<4?d?o:b[v]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?sr(i)&&(f>4?y.unshift(i):f?d?o=i:b[v]=i:s=i):typeof i!="object"||i===null?Gn("Object expected"):(sr(a=i.get)&&(b.get=a),sr(a=i.set)&&(b.set=a),sr(a=i.init)&&y.unshift(a));return f||bn(e,s),b&&va(s,n,b),d?f^4?o:b:s},ya=(e,t,n)=>t.has(e)||Gn("Cannot "+n),Dh=(e,t)=>Object(t)!==t?Gn('Cannot use the "in" operator on this value'):e.has(t),He=(e,t,n)=>(ya(e,t,"read from private field"),n?n.call(e):t.get(e)),be=(e,t,n)=>t.has(e)?Gn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),wt=(e,t,n,r)=>(ya(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Ph=(e,t,n)=>(ya(e,t,"access private method"),n);function Lc(e,t){return{plugin:e,options:t}}function Xn(e){return t=>Lc(e,t)}function ba(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Wc,xr,wa,os;Wc=[de];var it=class{constructor(e,t){this.manager=e,this.options=t,be(this,wa,re(xr,8,this,!1)),re(xr,11,this),be(this,os,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return we(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=Ct(e.bind(this));return He(this,os).add(t),t}destroy(){He(this,os).forEach(e=>e())}static configure(e){return Lc(this,e)}};xr=Un(null);wa=new WeakMap;os=new WeakMap;ue(xr,4,"disabled",Wc,it,wa);bn(xr,it);var Fr=class extends it{},as,ho=class{constructor(e){this.manager=e,this.instances=new Map,be(this,as,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(ba).reduceRight((r,s)=>r.some(({plugin:o})=>o===s.plugin)?r:[s,...r],[]),n=t.map(({plugin:r})=>r);for(const r of He(this,as))if(!n.includes(r)){if(r.prototype instanceof Fr)continue;this.unregister(r)}for(const{plugin:r,options:s}of t)this.register(r,s);wt(this,as,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()}};as=new WeakMap;function Fh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var Jr=[],Tn,$n,Oh=class extends it{constructor(e){super(e),be(this,Tn),be(this,$n),this.computeCollisions=this.computeCollisions.bind(this),wt(this,$n,$r(Jr)),this.destroy=Rr(()=>{const t=this.computeCollisions(),n=we(()=>this.manager.dragOperation.position.current);if(t!==Jr){const r=He(this,Tn);if(wt(this,Tn,n),r&&n.x==r.x&&n.y==r.y)return}else wt(this,Tn,void 0);He(this,$n).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){we(()=>{e?He(this,$n).value=this.computeCollisions():wt(this,Tn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:o,status:a}=r;if(!a.initialized||!o)return Jr;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=we(()=>u({droppable:c,dragOperation:r}));f&&(c.collisionPriority!=null&&(f.priority=c.collisionPriority),i.push(f))}return l.length===0?Jr:(i.sort(Fh),i)}get collisions(){return He(this,$n).value}};Tn=new WeakMap;$n=new WeakMap;var Lh=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)}},Wh=class extends Lh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function is(e,t=!0){let n=!1;return Pc(Dc({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var Bh=class extends Fr{constructor(e){super(e);const t=(r,s)=>r.map(({id:o})=>o).join("")===s.map(({id:o})=>o).join("");let n=[];this.destroy=Rr(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:o}=r;if(r.isDisabled())return;const a=is({collisions:o});if(s.dispatch("collision",a),a.defaultPrevented||t(o,n))return;n=o;const[i]=o;we(()=>{var l;i?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(i?.id).then(()=>{r.enable()}))})})}},_a=(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))(_a||{}),xa=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(xa||{}),Bc,Vc,Nc,zc,jc,Zc,Hc,xt,Ca;Hc=[de],Zc=[Ie],jc=[Ie],zc=[Ie],Nc=[Ie],Vc=[Ie],Bc=[Ie];var jt=class{constructor(){re(xt,5,this),be(this,Ca,re(xt,8,this,"idle")),re(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=Un(null);Ca=new WeakMap;ue(xt,4,"value",Hc,jt,Ca);ue(xt,2,"current",Zc,jt);ue(xt,2,"idle",jc,jt);ue(xt,2,"initializing",zc,jt);ue(xt,2,"initialized",Nc,jt);ue(xt,2,"dragging",Vc,jt);ue(xt,2,"dropped",Bc,jt);bn(xt,jt);var Vh=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 we(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=is({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return we(()=>{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:o}=e;Qt(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(o)});const a=is({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",a),a.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 we(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:o}=r;if(!s.dragging||!o||o.signal.aborted)return;const a=is({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",a),queueMicrotask(()=>{var i,l,c,u,f;if(a.defaultPrevented)return;const h=(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=h})})}stop(e={}){return we(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let o;const a=()=>{const l={resume:()=>{},abort:()=>{}};return o=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=we(()=>{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:a}),o?o.then(i).catch(()=>r.reset()):i()})}},Gc,Uc,Xc,Yc,at,Sa,ka,Ea,Ia;Yc=[de],Xc=[de],Uc=[de],Gc=[de];var nn=class{constructor(e,t){be(this,Sa,re(at,8,this)),re(at,11,this),be(this,ka,re(at,12,this)),re(at,15,this),be(this,Ea,re(at,16,this)),re(at,19,this),be(this,Ia,re(at,20,this)),re(at,23,this);const{effects:n,id:r,data:s={},disabled:o=!1,register:a=!0}=e;let i=r;this.manager=t,this.id=r,this.data=s,this.disabled=o,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&&a&&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)}};at=Un(null);Sa=new WeakMap;ka=new WeakMap;Ea=new WeakMap;Ia=new WeakMap;ue(at,4,"manager",Yc,nn,Sa);ue(at,4,"id",Xc,nn,ka);ue(at,4,"data",Uc,nn,Ea);ue(at,4,"disabled",Gc,nn,Ia);bn(at,nn);var fl=class{constructor(){this.map=$r(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 o=new Map(n);o.set(e,t),this.map.value=o;const a=Rr(...t.effects());return this.cleanupFunctions.set(t,a),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}},Kc,qc,Jc,Qc,eu,tu,Lo,nt,Ma,Aa,Ta,Ft=class extends(Lo=nn,tu=[de],eu=[de],Qc=[de],Jc=[Ie],qc=[Ie],Kc=[Ie],Lo){constructor(t,n){var r=t,{modifiers:s,type:o,sensors:a}=r,i=Fc(r,["modifiers","type","sensors"]);super(i,n),re(nt,5,this),be(this,Ma,re(nt,8,this)),re(nt,11,this),be(this,Aa,re(nt,12,this)),re(nt,15,this),be(this,Ta,re(nt,16,this,this.isDragSource?"dragging":"idle")),re(nt,19,this),this.type=o,this.sensors=a,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}};nt=Un(Lo);Ma=new WeakMap;Aa=new WeakMap;Ta=new WeakMap;ue(nt,4,"type",tu,Ft,Ma);ue(nt,4,"modifiers",eu,Ft,Aa);ue(nt,4,"status",Qc,Ft,Ta);ue(nt,2,"isDropping",Jc,Ft);ue(nt,2,"isDragging",qc,Ft);ue(nt,2,"isDragSource",Kc,Ft);bn(nt,Ft);var nu,ru,su,ou,au,iu,Wo,ze,$a,Ra,Da,Pa,Fa,Ot=class extends(Wo=nn,iu=[de],au=[de],ou=[de],su=[de],ru=[de],nu=[Ie],Wo){constructor(t,n){var r=t,{accept:s,collisionDetector:o,collisionPriority:a,type:i}=r,l=Fc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),re(ze,5,this),be(this,$a,re(ze,8,this)),re(ze,11,this),be(this,Ra,re(ze,12,this)),re(ze,15,this),be(this,Da,re(ze,16,this)),re(ze,19,this),be(this,Pa,re(ze,20,this)),re(ze,23,this),be(this,Fa,re(ze,24,this)),re(ze,27,this),this.accept=s,this.collisionDetector=o,this.collisionPriority=a,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}};ze=Un(Wo);$a=new WeakMap;Ra=new WeakMap;Da=new WeakMap;Pa=new WeakMap;Fa=new WeakMap;ue(ze,4,"accept",iu,Ot,$a);ue(ze,4,"type",au,Ot,Ra);ue(ze,4,"collisionDetector",ou,Ot,Da);ue(ze,4,"collisionPriority",su,Ot,Pa);ue(ze,4,"shape",ru,Ot,Fa);ue(ze,2,"isDropTarget",nu,Ot);bn(ze,Ot);var Wn=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Nh=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)}},ls,lu=class{constructor(e){this.options=e,be(this,ls)}set controller(e){wt(this,ls,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=He(this,ls))==null||t.activate(e)}};ls=new WeakMap;var Cr=class extends it{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},zh=class{constructor(e){this.draggables=new fl,this.droppables=new fl,this.plugins=new ho(e),this.sensors=new ho(e),this.modifiers=new ho(e)}register(e,t){if(e instanceof Ft)return this.draggables.register(e.id,e);if(e instanceof Ot)return this.droppables.register(e.id,e);if(e.prototype instanceof Cr)return this.modifiers.register(e,t);if(e.prototype instanceof Wn)return this.sensors.register(e,t);if(e.prototype instanceof it)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof nn)return e instanceof Ft?this.draggables.unregister(e.id,e):e instanceof Ot?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof Cr)return this.modifiers.unregister(e);if(e.prototype instanceof Wn)return this.sensors.unregister(e);if(e.prototype instanceof it)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()}},cu,uu,du,fu,hu,pu,mu,gu,vu,or,cs,Rn,Re,Oa,La,Wa,Ba,Va,ar;vu=[Ie],gu=[de],mu=[de],pu=[de],hu=[de],fu=[de],du=[Ie],uu=[Ie],cu=[Ie];var Rt=class{constructor(e){re(Re,5,this),be(this,or),be(this,cs),be(this,Rn,new tn(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new jt,be(this,Oa,re(Re,8,this,!1)),re(Re,11,this),be(this,La,re(Re,12,this,null)),re(Re,15,this),be(this,Wa,re(Re,16,this,null)),re(Re,19,this),be(this,Ba,re(Re,20,this,null)),re(Re,23,this),be(this,Va,re(Re,24,this,[])),re(Re,27,this),this.position=new Ls({x:0,y:0}),be(this,ar,{x:0,y:0}),wt(this,or,e)}get shape(){const{current:e,initial:t,previous:n}=He(this,Rn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?He(this,Rn).current=e:He(this,Rn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=He(this,or).registry.draggables.get(t);return n&&wt(this,cs,n),(e=n??He(this,cs))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=He(this,or).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(Pc(Dc({},this.snapshot()),{transform:n}));return wt(this,ar,n),n}snapshot(){return we(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:He(this,ar),shape:this.shape?fo(this.shape):null,position:fo(this.position),status:fo(this.status),canceled:this.canceled}))}reset(){Qt(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,He(this,Rn).reset(),this.position.reset({x:0,y:0}),wt(this,ar,{x:0,y:0}),this.modifiers=[]})}};Re=Un(null);or=new WeakMap;cs=new WeakMap;Rn=new WeakMap;Oa=new WeakMap;La=new WeakMap;Wa=new WeakMap;Ba=new WeakMap;Va=new WeakMap;ar=new WeakMap;ue(Re,2,"shape",vu,Rt);ue(Re,4,"canceled",gu,Rt,Oa);ue(Re,4,"activatorEvent",mu,Rt,La);ue(Re,4,"sourceIdentifier",pu,Rt,Wa);ue(Re,4,"targetIdentifier",hu,Rt,Ba);ue(Re,4,"modifiers",fu,Rt,Va);ue(Re,2,"source",du,Rt);ue(Re,2,"target",uu,Rt);ue(Re,2,"transform",cu,Rt);bn(Re,Rt);var jh={get rendering(){return Promise.resolve()}};function Vt(e,t){return typeof e=="function"?e(t):e??t}var Zh=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(h=>h.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=Vt(r.plugins,[]),o=Vt(r.sensors,[]),a=Vt(r.modifiers,[]),i=(n=r.renderer)!=null?n:jh,l=new Wh(this),c=new zh(this);this.registry=c,this.monitor=l,this.renderer=i,this.actions=new Vh(this),this.dragOperation=new Rt(this),this.collisionObserver=new Oh(this),this.plugins=[Bh,...s],this.modifiers=a,this.sensors=o;const{destroy:u}=this,f=Rr(()=>{var h,d,p;const v=we(()=>this.dragOperation.modifiers),y=this.modifiers;for(const m of v)y.includes(m)||m.destroy();this.dragOperation.modifiers=(p=(d=(h=this.dragOperation.source)==null?void 0:h.modifiers)==null?void 0:d.map(m=>{const{plugin:b,options:_}=ba(m);return new b(this,_)}))!=null?p:y});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}},yu=e=>{throw TypeError(e)},Na=(e,t,n)=>t.has(e)||yu("Cannot "+n),ae=(e,t,n)=>(Na(e,t,"read from private field"),t.get(e)),ot=(e,t,n)=>t.has(e)?yu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),pt=(e,t,n,r)=>(Na(e,t,"write to private field"),t.set(e,n),n),bu=(e,t,n)=>(Na(e,t,"access private method"),n);function Ws(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Hh(e,t){const n=e.getAnimations();if(n.length>0)for(const r of n){if(r.playState!=="running")continue;const{effect:s}=r,a=(Ws(s)?s.getKeyframes():[]).filter(t);if(a.length>0)return[a[a.length-1],r]}return null}function Bs(e){const{width:t,height:n,top:r,left:s,bottom:o,right:a}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:o,right:a}}function za(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Or(e){return"nodeType"in e}function St(e){var t,n,r;return e?za(e)?e:Or(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 ja(e){const{Document:t}=St(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function mn(e){return!e||za(e)?!1:e instanceof St(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function wu(e){return e instanceof St(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function wn(e){return e?za(e)?e.document:Or(e)?ja(e)?e:mn(e)||wu(e)?e.ownerDocument:document:document:document}function Gh(e){var t,n,r,s;const{documentElement:o}=wn(e),a=St(e).visualViewport,i=(t=a?.width)!=null?t:o.clientWidth,l=(n=a?.height)!=null?n:o.clientHeight,c=(r=a?.offsetTop)!=null?r:0,u=(s=a?.offsetLeft)!=null?s:0;return{top:c,left:u,right:u+i,bottom:c+l,width:i,height:l}}function Uh(e,t){if(Xh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Xh(e){return e.tagName==="DETAILS"}function ws(e,t=e.getBoundingClientRect(),n=0){var r,s,o,a,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(!Uh(f)){const _=f.getBoundingClientRect(),w=n*(_.bottom-_.top),x=n*(_.right-_.left),S=n*(_.bottom-_.top),k=n*(_.right-_.left);l={top:Math.max(l.top,_.top-w),right:Math.min(l.right,_.right+x),bottom:Math.min(l.bottom,_.bottom+S),left:Math.max(l.left,_.left-k),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}f=f.parentElement}const h=u.visualViewport,d=(s=h?.offsetTop)!=null?s:0,p=(o=h?.offsetLeft)!=null?o:0,v=(a=h?.width)!=null?a:u.innerWidth,y=(i=h?.height)!=null?i:u.innerHeight,m=n*y,b=n*v;return l={top:Math.max(l.top,d-m),right:Math.min(l.right,p+v+b),bottom:Math.min(l.bottom,d+y+m),left:Math.max(l.left,p-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 Bn(e){return{x:e.clientX,y:e.clientY}}var _u=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Bo(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(...Bo(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(...Bo(s.document,t))}}catch{}return n}function Za(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function xu(){var e,t;const n=Za()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Ha(e){return!e||!Or(e)?!1:e instanceof St(e).ShadowRoot}function _s(e){if(e&&Or(e)){let t=e.getRootNode();if(Ha(t))return t;if(t instanceof Document)return t}return wn(e)}function Cu(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Yh(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((o,a)=>{const i=r[a];if(hl(o)&&hl(i)&&(o.type!=="file"&&(o.value=i.value),o.type==="radio"&&o.name&&(o.name=`Cloned__${o.name}`)),pl(o)&&pl(i)&&i.width>0&&i.height>0){const l=o.getContext("2d");l?.drawImage(i,0,0)}}),n}function hl(e){return"value"in e}function pl(e){return e.tagName==="CANVAS"}function Su(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Kh(r)){const{contentDocument:s}=r;if(s){const{left:o,top:a}=r.getBoundingClientRect();return Su(s,{x:t-o,y:n-a})}}return r}function Kh(e){return e?.tagName==="IFRAME"}var ml=new WeakMap;function qh(e){return!!e.closest(`
2
2
  input:not([disabled]),
3
3
  select:not([disabled]),
4
4
  textarea:not([disabled]),
5
5
  button:not([disabled]),
6
6
  a[href],
7
7
  [contenteditable]:not([contenteditable="false"])
8
- `)}var Su=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:i,listener:l,options:c}=a,u=[o,a];o.addEventListener(i,l,c),this.entries.add(u),s.push(u)}return function(){for(const[a,{type:i,listener:l,options:c}]of s)a.removeEventListener(i,l,c)}}};function Vn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function qh(e){const t=new Set;let n=Vn(e);for(;n;)t.add(n),n=Vn(n);return t}function Jh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function ku(e,t){const n=()=>performance.now();let r,s;return function(...o){const a=this;s?(r?.(),r=Jh(()=>{e.apply(a,o),s=n()},t-(n()-s))):(e.apply(a,o),s=n())}}function Qh(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function ep(e,t=e.getBoundingClientRect()){const{width:n,height:r}=ws(e,t);return n>0&&r>0}var tp=wu?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},us,np=class extends tp{constructor(e){super(t=>{if(!ae(this,us)){pt(this,us,!0);return}e(t,this)}),ot(this,us,!1)}};us=new WeakMap;var vl=Array.from({length:100},(e,t)=>t/100),Eu=75,un,xs,Ut,dn,ir,Ye,mr,lr,Cs,Iu,Mu,Au=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,ot(this,Cs),this.disconnect=()=>{var o,a,i;pt(this,mr,!0),(o=ae(this,Ut))==null||o.disconnect(),(a=ae(this,dn))==null||a.disconnect(),ae(this,ir).disconnect(),(i=ae(this,Ye))==null||i.remove()},ot(this,un,!0),ot(this,xs),ot(this,Ut),ot(this,dn),ot(this,ir),ot(this,Ye),ot(this,mr,!1),ot(this,lr,ku(()=>{var o,a,i;const{element:l}=this;if((o=ae(this,dn))==null||o.disconnect(),ae(this,mr)||!ae(this,un)||!l.isConnected)return;const c=(a=l.ownerDocument)!=null?a:document,{innerHeight:u,innerWidth:f}=(i=c.defaultView)!=null?i:window,h=l.getBoundingClientRect(),d=ws(l,h),{top:p,left:v,bottom:y,right:m}=d,b=-Math.floor(p),_=-Math.floor(v),w=-Math.floor(f-m),x=-Math.floor(u-y),S=`${b}px ${w}px ${x}px ${_}px`;this.boundingClientRect=h,pt(this,dn,new IntersectionObserver(k=>{const[E]=k,{intersectionRect:T}=E;(E.intersectionRatio!==1?E.intersectionRatio:Dr.intersectionRatio(T,ws(l)))!==1&&ae(this,lr).call(this)},{threshold:vl,rootMargin:S,root:c})),ae(this,dn).observe(l),yu(this,Cs,Iu).call(this)},Eu)),this.boundingClientRect=e.getBoundingClientRect(),pt(this,un,ep(e,this.boundingClientRect));let r=!0;this.callback=o=>{r&&(r=!1,n.skipInitial)||t(o)};const s=e.ownerDocument;n?.debug&&(pt(this,Ye,document.createElement("div")),ae(this,Ye).style.background="rgba(0,0,0,0.15)",ae(this,Ye).style.position="fixed",ae(this,Ye).style.pointerEvents="none",s.body.appendChild(ae(this,Ye))),pt(this,ir,new IntersectionObserver(o=>{var a,i;const l=o[o.length-1],{boundingClientRect:c,isIntersecting:u}=l,{width:f,height:h}=c,d=ae(this,un);pt(this,un,u),!(!f&&!h)&&(d&&!u?((a=ae(this,dn))==null||a.disconnect(),this.callback(null),(i=ae(this,Ut))==null||i.disconnect(),pt(this,Ut,void 0),ae(this,Ye)&&(ae(this,Ye).style.visibility="hidden")):ae(this,lr).call(this),u&&!ae(this,Ut)&&(pt(this,Ut,new np(ae(this,lr))),ae(this,Ut).observe(e)))},{threshold:vl,root:s})),ae(this,un)&&!n.skipInitial&&this.callback(this.boundingClientRect),ae(this,ir).observe(e)}};un=new WeakMap;xs=new WeakMap;Ut=new WeakMap;dn=new WeakMap;ir=new WeakMap;Ye=new WeakMap;mr=new WeakMap;lr=new WeakMap;Cs=new WeakSet;Iu=function(){ae(this,mr)||(yu(this,Cs,Mu).call(this),!Qh(this.boundingClientRect,ae(this,xs))&&(this.callback(this.boundingClientRect),pt(this,xs,this.boundingClientRect)))};Mu=function(){if(ae(this,Ye)){const{top:e,left:t,width:n,height:r}=ws(this.element);ae(this,Ye).style.overflow="hidden",ae(this,Ye).style.visibility="visible",ae(this,Ye).style.top=`${Math.floor(e)}px`,ae(this,Ye).style.left=`${Math.floor(t)}px`,ae(this,Ye).style.width=`${Math.floor(n)}px`,ae(this,Ye).style.height=`${Math.floor(r)}px`}};var Qr=new WeakMap,es=new WeakMap;function rp(e,t){let n=Qr.get(e);return n||(n={disconnect:new Au(e,s=>{const o=Qr.get(e);o&&o.callbacks.forEach(a=>a(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Qr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Qr.delete(e),n.disconnect())}}function sp(e,t){const n=new Set;for(const r of e){const s=rp(r,t);n.add(s)}return()=>n.forEach(r=>r())}function op(e,t){var n;const r=e.ownerDocument;if(!es.has(r)){const a=new AbortController,i=new Set;document.addEventListener("scroll",l=>i.forEach(c=>c(l)),{capture:!0,passive:!0,signal:a.signal}),es.set(r,{disconnect:()=>a.abort(),listeners:i})}const{listeners:s,disconnect:o}=(n=es.get(r))!=null?n:{};return!s||!o?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(o(),es.delete(r))})}var cr,ur,ds,No,ap=class{constructor(e,t,n){this.callback=t,ot(this,cr),ot(this,ur,!1),ot(this,ds),ot(this,No,ku(a=>{if(!ae(this,ur)&&a.target&&"contains"in a.target&&typeof a.target.contains=="function"){for(const i of ae(this,ds))if(a.target.contains(i)){this.callback(ae(this,cr).boundingClientRect);break}}},Eu));const r=qh(e),s=sp(r,t),o=op(e,ae(this,No));pt(this,ds,r),pt(this,cr,new Au(e,t,n)),this.disconnect=()=>{ae(this,ur)||(pt(this,ur,!0),s(),o(),ae(this,cr).disconnect())}}};cr=new WeakMap;ur=new WeakMap;ds=new WeakMap;No=new WeakMap;function zo(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Sr(e){try{zo(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function yl(e){return!wu||!e?!1:e===wn(e).scrollingElement}function Tu(e){var t,n;const r=St(e),s=yl(e)?Hh(e):Bs(e),o=r.visualViewport,a=yl(e)?{height:(t=o?.height)!=null?t:r.innerHeight,width:(n=o?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},i={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-a.width,y:e.scrollHeight-a.height}},l=i.current.y<=0,c=i.current.x<=0,u=i.current.y>=i.max.y,f=i.current.x>=i.max.x;return{rect:s,position:i,isTop:l,isLeft:c,isBottom:u,isRight:f}}function ip(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:o,position:a}=Tu(e),{x:i,y:l}=t??{x:0,y:0},c=!n&&a.current.y+l>0,u=!r&&a.current.y+l<a.max.y,f=!s&&a.current.x+i>0,h=!o&&a.current.x+i<a.max.x;return{top:c,bottom:u,left:f,right:h,x:f||h,y:c||u}}var Ua=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Ss=new Ua(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),lp=new Ua(e=>setTimeout(e,50)),ks=new Map,cp=ks.clear.bind(ks);function Zt(e,t=!1){if(!t)return bl(e);let n=ks.get(e);return n||(n=bl(e),ks.set(e,n),lp.schedule(cp),n)}function bl(e){return St(e).getComputedStyle(e)}function up(e,t=Zt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function dp(e,t=Zt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const o=t[s];return typeof o=="string"?n.test(o):!1})}var fp={excludeElement:!0,escapeShadowDOM:!0};function jo(e,t=fp){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,o=new Set;function a(i){if(n!=null&&o.size>=n||!i)return o;if(Za(i)&&i.scrollingElement!=null&&!o.has(i.scrollingElement))return o.add(i.scrollingElement),o;if(s&&Ga(i))return a(i.host);if(!mn(i))return bu(i)?a(i.parentElement):o;if(o.has(i))return o;const l=Zt(i,!0);if(r&&i===e||dp(i,l)&&o.add(i),up(i,l)){const{scrollingElement:c}=i.ownerDocument;return c&&o.add(c),o}return a(i.parentNode)}return e?a(e):o}function hp(e){const[t]=jo(e,{limit:1});return t??null}function Nn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Vn(e);for(;r;){if(r===t)return n;const s=Bs(r),{x:o,y:a}=pp(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*o,n.scaleY=n.scaleY*a,r=Vn(r)}return n}function pp(e,t=Bs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(mn(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=Zt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function mp(e){if(e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function Xa(e){if(e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function Ya(e){var t,n,r,s,o,a,i,l,c;const{scale:u,transform:f,translate:h}=e,d=mp(u),p=Xa(h),v=gp(f);if(!v&&!d&&!p)return null;const y={x:(t=d?.x)!=null?t:1,y:(n=d?.y)!=null?n:1},m={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},b={x:(o=v?.x)!=null?o:0,y:(a=v?.y)!=null?a:0,scaleX:(i=v?.scaleX)!=null?i:1,scaleY:(l=v?.scaleY)!=null?l:1};return{x:m.x+b.x,y:m.y+b.y,z:(c=p?.z)!=null?c:0,scaleX:y.x*b.scaleX,scaleY:y.y*b.scaleY}}function gp(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var _t=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(_t||{}),vp={x:.2,y:.2},yp={x:10,y:10};function bp(e,t,n,r=25,s=vp,o=yp){const{x:a,y:i}=t,{rect:l,isTop:c,isBottom:u,isLeft:f,isRight:h}=Tu(e),d=Nn(e),p=Zt(e,!0),v=Ya(p),y=v!==null?v?.scaleX<0:!1,m=v!==null?v?.scaleY<0:!1,b=new Dr(l.left*d.scaleX+d.x,l.top*d.scaleY+d.y,l.width*d.scaleX,l.height*d.scaleY),_={x:0,y:0},w={x:0,y:0},x={height:b.height*s.y,width:b.width*s.x};return(!c||m&&!u)&&i<=b.top+x.height&&n?.y!==1&&a>=b.left-o.x&&a<=b.right+o.x?(_.y=m?1:-1,w.y=r*Math.abs((b.top+x.height-i)/x.height)):(!u||m&&!c)&&i>=b.bottom-x.height&&n?.y!==-1&&a>=b.left-o.x&&a<=b.right+o.x&&(_.y=m?-1:1,w.y=r*Math.abs((b.bottom-x.height-i)/x.height)),(!h||y&&!f)&&a>=b.right-x.width&&n?.x!==-1&&i>=b.top-o.y&&i<=b.bottom+o.y?(_.x=y?-1:1,w.x=r*Math.abs((b.right-x.width-a)/x.width)):(!f||y&&!h)&&a<=b.left+x.width&&n?.x!==1&&i>=b.top-o.y&&i<=b.bottom+o.y&&(_.x=y?1:-1,w.x=r*Math.abs((b.left+x.width-a)/x.width)),{direction:_,speed:w}}function wp(e){return"scrollIntoViewIfNeeded"in e&&typeof e.scrollIntoViewIfNeeded=="function"}function _p(e,t=!1){if(wp(e)){e.scrollIntoViewIfNeeded(t);return}if(!mn(e))return e.scrollIntoView();var n=hp(e);if(!mn(n))return;const r=Zt(n,!0),s=parseInt(r.getPropertyValue("border-top-width")),o=parseInt(r.getPropertyValue("border-left-width")),a=e.offsetTop-n.offsetTop<n.scrollTop,i=e.offsetTop-n.offsetTop+e.clientHeight-s>n.scrollTop+n.clientHeight,l=e.offsetLeft-n.offsetLeft<n.scrollLeft,c=e.offsetLeft-n.offsetLeft+e.clientWidth-o>n.scrollLeft+n.clientWidth,u=a&&!i;(a||i)&&t&&(n.scrollTop=e.offsetTop-n.offsetTop-n.clientHeight/2-s+e.clientHeight/2),(l||c)&&t&&(n.scrollLeft=e.offsetLeft-n.offsetLeft-n.clientWidth/2-o+e.clientWidth/2),(a||i||l||c)&&!t&&e.scrollIntoView(u)}function xp(e,t,n){const{scaleX:r,scaleY:s,x:o,y:a}=t,i=e.left+o+(1-r)*parseFloat(n),l=e.top+a+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),c=r?e.width*r:e.width,u=s?e.height*s:e.height;return{width:c,height:u,top:l,right:i+c,bottom:l+u,left:i}}function Cp(e,t,n){const{scaleX:r,scaleY:s,x:o,y:a}=t,i=e.left-o-(1-r)*parseFloat(n),l=e.top-a-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),c=r?e.width/r:e.width,u=s?e.height/s:e.height;return{width:c,height:u,top:l,right:i+c,bottom:l+u,left:i}}function Sp({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}var kp=new Ua(e=>setTimeout(e,0)),gr=new Map,Ep=gr.clear.bind(gr);function Ip(e){const t=e.ownerDocument;let n=gr.get(t);if(n)return n;n=t.getAnimations(),gr.set(t,n),kp.schedule(Ep);const r=n.filter(s=>Ws(s.effect)&&s.effect.target===e);return gr.set(e,r),n}function Mp(e,t){const n=Ip(e).filter(r=>{var s,o;if(Ws(r.effect)){const{target:a}=r.effect;if((o=a&&((s=t.isValidTarget)==null?void 0:s.call(t,a)))!=null?o:!0)return r.effect.getKeyframes().some(l=>{for(const c of t.properties)if(l[c])return!0})}}).map(r=>{const{effect:s,currentTime:o}=r,a=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof a=="number"&&typeof o=="number"&&o<a)return r.currentTime=a,()=>{r.currentTime=o}});if(n.length>0)return()=>n.forEach(r=>r?.())}var Nt=class extends Dr{constructor(e,t={}){var n,r,s,o;const{frameTransform:a=Nn(e),ignoreTransforms:i,getBoundingClientRect:l=Bs}=t,c=Mp(e,{properties:["transform","translate","scale","width","height"],isValidTarget:x=>(x!==e||Ha())&&x.contains(e)}),u=l(e);let{top:f,left:h,width:d,height:p}=u,v;const y=Zt(e),m=Ya(y),b={x:(n=m?.scaleX)!=null?n:1,y:(r=m?.scaleY)!=null?r:1},_=Ap(e,y);c?.(),m&&(v=Cp(u,m,y.transformOrigin),(i||_)&&(f=v.top,h=v.left,d=v.width,p=v.height));const w={width:(s=v?.width)!=null?s:d,height:(o=v?.height)!=null?o:p};if(_&&!i&&v){const x=xp(v,_,y.transformOrigin);f=x.top,h=x.left,d=x.width,p=x.height,b.x=_.scaleX,b.y=_.scaleY}a&&(i||(h*=a.scaleX,d*=a.scaleX,f*=a.scaleY,p*=a.scaleY),h+=a.x,f+=a.y),super(h,f,d,p),this.scale=b,this.intrinsicWidth=w.width,this.intrinsicHeight=w.height}};function Ap(e,t){var n;const r=e.getAnimations();let s=null;if(!r.length)return null;for(const o of r){if(o.playState!=="running")continue;const a=Ws(o.effect)?o.effect.getKeyframes():[],i=a[a.length-1];if(!i)continue;const{transform:l,translate:c,scale:u}=i;if(l||c||u){const f=Ya({transform:typeof l=="string"&&l?l:t.transform,translate:typeof c=="string"&&c?c:t.translate,scale:typeof u=="string"&&u?u:t.scale});f&&(s=s?{x:s.x+f.x,y:s.y+f.y,z:(n=s.z)!=null?n:f.z,scaleX:s.scaleX*f.scaleX,scaleY:s.scaleY*f.scaleY}:f)}}return s}function vr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var Tp=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(vr(n))for(const[r,s]of Object.entries(e)){const o=`${t}${r}`;this.initial.has(o)||this.initial.set(o,n.style.getPropertyValue(o)),n.style.setProperty(o,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(vr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(vr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function gn(e){return e?e instanceof St(e).Element||Or(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Ka(e){if(!e)return!1;const{KeyboardEvent:t}=St(e.target);return e instanceof t}function $p(e){if(!e)return!1;const{PointerEvent:t}=St(e.target);return e instanceof t}function Rp(e){if(!gn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||Dp(e)}function Dp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var po={};function Zo(e){const t=po[e]==null?0:po[e]+1;return po[e]=t,`${e}-${t}`}var Pp=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=Pt.distance(t.shape.center,n);return{id:r,value:1/s,type:Ca.PointerIntersection,priority:xa.High}}return null},Fp=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,o=Pt.distance(t.shape.center,s.current),i=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:i,type:Ca.ShapeIntersection,priority:xa.Normal}}return null},Op=e=>{var t;return(t=Pp(e))!=null?t:Fp(e)},Lp=Object.create,qa=Object.defineProperty,Wp=Object.defineProperties,Bp=Object.getOwnPropertyDescriptor,Vp=Object.getOwnPropertyDescriptors,Es=Object.getOwnPropertySymbols,$u=Object.prototype.hasOwnProperty,Ru=Object.prototype.propertyIsEnumerable,Du=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Yn=e=>{throw TypeError(e)},Ho=(e,t,n)=>t in e?qa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,kr=(e,t)=>{for(var n in t||(t={}))$u.call(t,n)&&Ho(e,n,t[n]);if(Es)for(var n of Es(t))Ru.call(t,n)&&Ho(e,n,t[n]);return e},Ja=(e,t)=>Wp(e,Vp(t)),wl=(e,t)=>qa(e,"name",{value:t,configurable:!0}),Pu=(e,t)=>{var n={};for(var r in e)$u.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Es)for(var r of Es(e))t.indexOf(r)<0&&Ru.call(e,r)&&(n[r]=e[r]);return n},Kn=e=>{var t;return[,,,Lp((t=e?.[Du("metadata")])!=null?t:null)]},Fu=["class","method","getter","setter","accessor","field","value","get","set"],dr=e=>e!==void 0&&typeof e!="function"?Yn("Function expected"):e,Np=(e,t,n,r,s)=>({kind:Fu[e],name:t,metadata:r,addInitializer:o=>n._?Yn("Already initialized"):s.push(dr(o||null))}),_n=(e,t)=>Ho(t,Du("metadata"),e[3]),We=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},gt=(e,t,n,r,s,o)=>{var a,i,l,c,u,f=t&7,h=!!(t&8),d=!!(t&16),p=f>3?e.length+1:f?h?1:2:0,v=Fu[f+5],y=f>3&&(e[p-1]=[]),m=e[p]||(e[p]=[]),b=f&&(!d&&!h&&(s=s.prototype),f<5&&(f>3||!d)&&Bp(f<4?s:{get[n](){return Ce(this,o)},set[n](w){return rt(this,o,w)}},n));f?d&&f<4&&wl(o,(f>2?"set ":f>1?"get ":"")+n):wl(s,n);for(var _=r.length-1;_>=0;_--)c=Np(f,n,l={},e[3],m),f&&(c.static=h,c.private=d,u=c.access={has:d?w=>zp(s,w):w=>n in w},f^3&&(u.get=d?w=>(f^1?Ce:vn)(w,s,f^4?o:b.get):w=>w[n]),f>2&&(u.set=d?(w,x)=>rt(w,s,x,f^4?o:b.set):(w,x)=>w[n]=x)),i=(0,r[_])(f?f<4?d?o:b[v]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?dr(i)&&(f>4?y.unshift(i):f?d?o=i:b[v]=i:s=i):typeof i!="object"||i===null?Yn("Object expected"):(dr(a=i.get)&&(b.get=a),dr(a=i.set)&&(b.set=a),dr(a=i.init)&&y.unshift(a));return f||_n(e,s),b&&qa(s,n,b),d?f^4?o:b:s},Qa=(e,t,n)=>t.has(e)||Yn("Cannot "+n),zp=(e,t)=>Object(t)!==t?Yn('Cannot use the "in" operator on this value'):e.has(t),Ce=(e,t,n)=>(Qa(e,t,"read from private field"),n?n.call(e):t.get(e)),De=(e,t,n)=>t.has(e)?Yn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rt=(e,t,n,r)=>(Qa(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),vn=(e,t,n)=>(Qa(e,t,"access private method"),n),_l={role:"button",roleDescription:"draggable"},jp="dnd-kit-description",Zp="dnd-kit-announcement",Hp={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Gp={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function Up(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Xp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Yp(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var Kp=["dragover","dragmove"],qp=class extends it{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=jp,announcement:s=Zp}={},announcements:o=Gp,screenReaderInstructions:a=Hp,debounce:i=500}=t??{},l=n?`${r}-${n}`:Zo(r),c=n?`${s}-${n}`:Zo(s);let u,f,h,d;const p=(x=d)=>{!h||!x||h?.nodeValue!==x&&(h.nodeValue=x)},v=()=>Ss.schedule(p),y=Jp(v,i),m=Object.entries(o).map(([x,S])=>this.manager.monitor.addEventListener(x,(k,E)=>{const T=h;if(!T)return;const I=S?.(k,E);I&&T.nodeValue!==I&&(d=I,Kp.includes(x)?y():(v(),y.cancel()))})),b=()=>{let x=[];u?.isConnected||(u=Xp(l,a.draggable),x.push(u)),f?.isConnected||(f=Yp(c),h=document.createTextNode(""),f.appendChild(h),x.push(f)),x.length>0&&document.body.append(...x)},_=new Set;function w(){for(const x of _)x()}this.registerEffect(()=>{var x;_.clear();for(const S of this.manager.registry.draggables.value){const k=(x=S.handle)!=null?x:S.element;if(k){(!u||!f)&&_.add(b),(!Up(k)||Ha())&&!k.hasAttribute("tabindex")&&_.add(()=>k.setAttribute("tabindex","0")),!k.hasAttribute("role")&&k.tagName.toLowerCase()!=="button"&&_.add(()=>k.setAttribute("role",_l.role)),k.hasAttribute("aria-roledescription")||_.add(()=>k.setAttribute("aria-roledescription",_l.roleDescription)),k.hasAttribute("aria-describedby")||_.add(()=>k.setAttribute("aria-describedby",l));for(const T of["aria-pressed","aria-grabbed"]){const I=String(S.isDragging);k.getAttribute(T)!==I&&_.add(()=>k.setAttribute(T,I))}const E=String(S.disabled);k.getAttribute("aria-disabled")!==E&&_.add(()=>k.setAttribute("aria-disabled",E))}}_.size>0&&Ss.schedule(w)}),this.destroy=()=>{super.destroy(),u?.remove(),f?.remove(),m.forEach(x=>x())}}};function Jp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var Qp=class extends it{constructor(e,t){super(e,t),this.manager=e;const n=ys(()=>{var r;return wn((r=this.manager.dragOperation.source)==null?void 0:r.element)});this.destroy=Ct(()=>{var r;const{dragOperation:s}=this.manager,{cursor:o="grabbing",nonce:a}=(r=this.options)!=null?r:{};if(s.status.initialized){const i=n.value,l=i.createElement("style");return a&&l.setAttribute("nonce",a),l.textContent=`* { cursor: ${o} !important; }`,i.head.appendChild(l),()=>l.remove()}})}},Is=new Map,Ou,Lu,Wu,Bu,Go,yr,zt,ei,zn,Vu,Nu,zu,ju,xn=class extends(Go=Fr,Bu=[de],Wu=[Ie],Lu=[Ie],Ou=[Ie],Go){constructor(e){super(e),We(zt,5,this),De(this,zn),De(this,yr,new Set),De(this,ei,We(zt,8,this,new Set)),We(zt,11,this),this.registerEffect(vn(this,zn,Vu))}register(e){return Ce(this,yr).add(e),()=>{Ce(this,yr).delete(e)}}addRoot(e){return we(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{we(()=>{const t=new Set(this.additionalRoots);t.delete(e),this.additionalRoots=t})}}get sourceRoot(){var e;const{source:t}=this.manager.dragOperation;return _s((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return _s((e=t?.element)!=null?e:null)}get roots(){const{status:e}=this.manager.dragOperation;if(e.initializing||e.initialized){const t=[this.sourceRoot,this.targetRoot].filter(n=>n!=null);return new Set([...t,...this.additionalRoots])}return new Set}};zt=Kn(Go);yr=new WeakMap;ei=new WeakMap;zn=new WeakSet;Vu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of Ce(this,yr))t.push(vn(this,zn,Nu).call(this,n,r));return()=>{for(const n of t)n()}};Nu=function(e,t){let n=Is.get(e);n||(n=new Map,Is.set(e,n));let r=n.get(t);if(!r){const o=Za(e)?vn(this,zn,zu).call(this,e,n,t):vn(this,zn,ju).call(this,e,n,t);if(!o)return()=>{};r=o,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};zu=function(e,t,n){const r=e.createElement("style");r.textContent=n,e.head.prepend(r);const s=new MutationObserver(o=>{for(const a of o)for(const i of Array.from(a.removedNodes))if(i===r){e.head.prepend(r);return}});return s.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{s.disconnect(),r.remove(),t.delete(n),t.size===0&&Is.delete(e)}}};ju=function(e,t,n){!("adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets))&&process.env.NODE_ENV!=="production"&&console.error("Cannot inject styles: This browser doesn't support adoptedStyleSheets");const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return process.env.NODE_ENV!=="production"&&console.error("Cannot inject styles: CSSStyleSheet constructor not available"),null;const o=new s;return o.replaceSync(n),e.adoptedStyleSheets.push(o),{refCount:0,cleanup:()=>{var a;if(Ga(e)&&((a=e.host)!=null&&a.isConnected)){const i=e.adoptedStyleSheets.indexOf(o);i!==-1&&e.adoptedStyleSheets.splice(i,1)}t.delete(n),t.size===0&&Is.delete(e)}}};gt(zt,4,"additionalRoots",Bu,xn,ei);gt(zt,2,"sourceRoot",Wu,xn);gt(zt,2,"targetRoot",Lu,xn);gt(zt,2,"roots",Ou,xn);_n(zt,xn);var Lr="data-dnd-",Uo=`${Lr}dropping`,Je="--dnd-",Dt=`${Lr}dragging`,Ms=`${Lr}placeholder`,em=[Dt,Ms,"popover","aria-pressed","aria-grabbing"],tm=["view-transition-name"],nm=`
8
+ `)}var ku=class{constructor(){this.entries=new Set,this.clear=()=>{for(const e of this.entries){const[t,{type:n,listener:r,options:s}]=e;t.removeEventListener(n,r,s)}this.entries.clear()}}bind(e,t){const n=Array.isArray(e)?e:[e],r=Array.isArray(t)?t:[t],s=[];for(const o of n)for(const a of r){const{type:i,listener:l,options:c}=a,u=[o,a];o.addEventListener(i,l,c),this.entries.add(u),s.push(u)}return function(){for(const[a,{type:i,listener:l,options:c}]of s)a.removeEventListener(i,l,c)}}};function Vn(e){const t=e?.ownerDocument.defaultView;if(t&&t.self!==t.parent)return t.frameElement}function Jh(e){const t=new Set;let n=Vn(e);for(;n;)t.add(n),n=Vn(n);return t}function Qh(e,t){const n=setTimeout(e,t);return()=>clearTimeout(n)}function Eu(e,t){const n=()=>performance.now();let r,s;return function(...o){const a=this;s?(r?.(),r=Qh(()=>{e.apply(a,o),s=n()},t-(n()-s))):(e.apply(a,o),s=n())}}function ep(e,t){return e===t?!0:!e||!t?!1:e.top==t.top&&e.left==t.left&&e.right==t.right&&e.bottom==t.bottom}function tp(e,t=e.getBoundingClientRect()){const{width:n,height:r}=ws(e,t);return n>0&&r>0}var np=_u?ResizeObserver:class{observe(){}unobserve(){}disconnect(){}},us,rp=class extends np{constructor(e){super(t=>{if(!ae(this,us)){pt(this,us,!0);return}e(t,this)}),ot(this,us,!1)}};us=new WeakMap;var gl=Array.from({length:100},(e,t)=>t/100),Iu=75,un,xs,Ut,dn,ir,Ye,mr,lr,Cs,Mu,Au,Tu=class{constructor(e,t,n={debug:!1,skipInitial:!1}){this.element=e,this.callback=t,ot(this,Cs),this.disconnect=()=>{var o,a,i;pt(this,mr,!0),(o=ae(this,Ut))==null||o.disconnect(),(a=ae(this,dn))==null||a.disconnect(),ae(this,ir).disconnect(),(i=ae(this,Ye))==null||i.remove()},ot(this,un,!0),ot(this,xs),ot(this,Ut),ot(this,dn),ot(this,ir),ot(this,Ye),ot(this,mr,!1),ot(this,lr,Eu(()=>{var o,a,i;const{element:l}=this;if((o=ae(this,dn))==null||o.disconnect(),ae(this,mr)||!ae(this,un)||!l.isConnected)return;const c=(a=l.ownerDocument)!=null?a:document,{innerHeight:u,innerWidth:f}=(i=c.defaultView)!=null?i:window,h=l.getBoundingClientRect(),d=ws(l,h),{top:p,left:v,bottom:y,right:m}=d,b=-Math.floor(p),_=-Math.floor(v),w=-Math.floor(f-m),x=-Math.floor(u-y),S=`${b}px ${w}px ${x}px ${_}px`;this.boundingClientRect=h,pt(this,dn,new IntersectionObserver(k=>{const[E]=k,{intersectionRect:M}=E;(E.intersectionRatio!==1?E.intersectionRatio:Dr.intersectionRatio(M,ws(l)))!==1&&ae(this,lr).call(this)},{threshold:gl,rootMargin:S,root:c})),ae(this,dn).observe(l),bu(this,Cs,Mu).call(this)},Iu)),this.boundingClientRect=e.getBoundingClientRect(),pt(this,un,tp(e,this.boundingClientRect));let r=!0;this.callback=o=>{r&&(r=!1,n.skipInitial)||t(o)};const s=e.ownerDocument;n?.debug&&(pt(this,Ye,document.createElement("div")),ae(this,Ye).style.background="rgba(0,0,0,0.15)",ae(this,Ye).style.position="fixed",ae(this,Ye).style.pointerEvents="none",s.body.appendChild(ae(this,Ye))),pt(this,ir,new IntersectionObserver(o=>{var a,i;const l=o[o.length-1],{boundingClientRect:c,isIntersecting:u}=l,{width:f,height:h}=c,d=ae(this,un);pt(this,un,u),!(!f&&!h)&&(d&&!u?((a=ae(this,dn))==null||a.disconnect(),this.callback(null),(i=ae(this,Ut))==null||i.disconnect(),pt(this,Ut,void 0),ae(this,Ye)&&(ae(this,Ye).style.visibility="hidden")):ae(this,lr).call(this),u&&!ae(this,Ut)&&(pt(this,Ut,new rp(ae(this,lr))),ae(this,Ut).observe(e)))},{threshold:gl,root:s})),ae(this,un)&&!n.skipInitial&&this.callback(this.boundingClientRect),ae(this,ir).observe(e)}};un=new WeakMap;xs=new WeakMap;Ut=new WeakMap;dn=new WeakMap;ir=new WeakMap;Ye=new WeakMap;mr=new WeakMap;lr=new WeakMap;Cs=new WeakSet;Mu=function(){ae(this,mr)||(bu(this,Cs,Au).call(this),!ep(this.boundingClientRect,ae(this,xs))&&(this.callback(this.boundingClientRect),pt(this,xs,this.boundingClientRect)))};Au=function(){if(ae(this,Ye)){const{top:e,left:t,width:n,height:r}=ws(this.element);ae(this,Ye).style.overflow="hidden",ae(this,Ye).style.visibility="visible",ae(this,Ye).style.top=`${Math.floor(e)}px`,ae(this,Ye).style.left=`${Math.floor(t)}px`,ae(this,Ye).style.width=`${Math.floor(n)}px`,ae(this,Ye).style.height=`${Math.floor(r)}px`}};var Qr=new WeakMap,es=new WeakMap;function sp(e,t){let n=Qr.get(e);return n||(n={disconnect:new Tu(e,s=>{const o=Qr.get(e);o&&o.callbacks.forEach(a=>a(s))},{skipInitial:!0}).disconnect,callbacks:new Set}),n.callbacks.add(t),Qr.set(e,n),()=>{n.callbacks.delete(t),n.callbacks.size===0&&(Qr.delete(e),n.disconnect())}}function op(e,t){const n=new Set;for(const r of e){const s=sp(r,t);n.add(s)}return()=>n.forEach(r=>r())}function ap(e,t){var n;const r=e.ownerDocument;if(!es.has(r)){const a=new AbortController,i=new Set;document.addEventListener("scroll",l=>i.forEach(c=>c(l)),{capture:!0,passive:!0,signal:a.signal}),es.set(r,{disconnect:()=>a.abort(),listeners:i})}const{listeners:s,disconnect:o}=(n=es.get(r))!=null?n:{};return!s||!o?()=>{}:(s.add(t),()=>{s.delete(t),s.size===0&&(o(),es.delete(r))})}var cr,ur,ds,Vo,ip=class{constructor(e,t,n){this.callback=t,ot(this,cr),ot(this,ur,!1),ot(this,ds),ot(this,Vo,Eu(a=>{if(!ae(this,ur)&&a.target&&"contains"in a.target&&typeof a.target.contains=="function"){for(const i of ae(this,ds))if(a.target.contains(i)){this.callback(ae(this,cr).boundingClientRect);break}}},Iu));const r=Jh(e),s=op(r,t),o=ap(e,ae(this,Vo));pt(this,ds,r),pt(this,cr,new Tu(e,t,n)),this.disconnect=()=>{ae(this,ur)||(pt(this,ur,!0),s(),o(),ae(this,cr).disconnect())}}};cr=new WeakMap;ur=new WeakMap;ds=new WeakMap;Vo=new WeakMap;function No(e){return"showPopover"in e&&"hidePopover"in e&&typeof e.showPopover=="function"&&typeof e.hidePopover=="function"}function Sr(e){try{No(e)&&e.isConnected&&e.hasAttribute("popover")&&!e.matches(":popover-open")&&e.showPopover()}catch{}}function vl(e){return!_u||!e?!1:e===wn(e).scrollingElement}function $u(e){var t,n;const r=St(e),s=vl(e)?Gh(e):Bs(e),o=r.visualViewport,a=vl(e)?{height:(t=o?.height)!=null?t:r.innerHeight,width:(n=o?.width)!=null?n:r.innerWidth}:{height:e.clientHeight,width:e.clientWidth},i={current:{x:e.scrollLeft,y:e.scrollTop},max:{x:e.scrollWidth-a.width,y:e.scrollHeight-a.height}},l=i.current.y<=0,c=i.current.x<=0,u=i.current.y>=i.max.y,f=i.current.x>=i.max.x;return{rect:s,position:i,isTop:l,isLeft:c,isBottom:u,isRight:f}}function lp(e,t){const{isTop:n,isBottom:r,isLeft:s,isRight:o,position:a}=$u(e),{x:i,y:l}=t??{x:0,y:0},c=!n&&a.current.y+l>0,u=!r&&a.current.y+l<a.max.y,f=!s&&a.current.x+i>0,h=!o&&a.current.x+i<a.max.x;return{top:c,bottom:u,left:f,right:h,x:f||h,y:c||u}}var Ga=class{constructor(t){this.scheduler=t,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:n,resolvers:r}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const s of n)s();for(const s of r)s()}}schedule(t){return this.tasks.add(t),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(n=>this.resolvers.add(n))}},Ss=new Ga(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),cp=new Ga(e=>setTimeout(e,50)),ks=new Map,up=ks.clear.bind(ks);function Zt(e,t=!1){if(!t)return yl(e);let n=ks.get(e);return n||(n=yl(e),ks.set(e,n),cp.schedule(up),n)}function yl(e){return St(e).getComputedStyle(e)}function dp(e,t=Zt(e,!0)){return t.position==="fixed"||t.position==="sticky"}function fp(e,t=Zt(e,!0)){const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const o=t[s];return typeof o=="string"?n.test(o):!1})}var hp={excludeElement:!0,escapeShadowDOM:!0};function zo(e,t=hp){const{limit:n,excludeElement:r,escapeShadowDOM:s}=t,o=new Set;function a(i){if(n!=null&&o.size>=n||!i)return o;if(ja(i)&&i.scrollingElement!=null&&!o.has(i.scrollingElement))return o.add(i.scrollingElement),o;if(s&&Ha(i))return a(i.host);if(!mn(i))return wu(i)?a(i.parentElement):o;if(o.has(i))return o;const l=Zt(i,!0);if(r&&i===e||fp(i,l)&&o.add(i),dp(i,l)){const{scrollingElement:c}=i.ownerDocument;return c&&o.add(c),o}return a(i.parentNode)}return e?a(e):o}function pp(e){const[t]=zo(e,{limit:1});return t??null}function Nn(e,t=window.frameElement){const n={x:0,y:0,scaleX:1,scaleY:1};if(!e)return n;let r=Vn(e);for(;r;){if(r===t)return n;const s=Bs(r),{x:o,y:a}=mp(r,s);n.x=n.x+s.left,n.y=n.y+s.top,n.scaleX=n.scaleX*o,n.scaleY=n.scaleY*a,r=Vn(r)}return n}function mp(e,t=Bs(e)){const n=Math.round(t.width),r=Math.round(t.height);if(mn(e))return{x:n/e.offsetWidth,y:r/e.offsetHeight};const s=Zt(e,!0);return{x:(parseFloat(s.width)||n)/n,y:(parseFloat(s.height)||r)/r}}function gp(e){if(e==="none")return null;const t=e.split(" "),n=parseFloat(t[0]),r=parseFloat(t[1]);return isNaN(n)&&isNaN(r)?null:{x:isNaN(n)?r:n,y:isNaN(r)?n:r}}function Ua(e){if(e==="none")return null;const[t,n,r="0"]=e.split(" "),s={x:parseFloat(t),y:parseFloat(n),z:parseInt(r,10)};return isNaN(s.x)&&isNaN(s.y)?null:{x:isNaN(s.x)?0:s.x,y:isNaN(s.y)?0:s.y,z:isNaN(s.z)?0:s.z}}function Xa(e){var t,n,r,s,o,a,i,l,c;const{scale:u,transform:f,translate:h}=e,d=gp(u),p=Ua(h),v=vp(f);if(!v&&!d&&!p)return null;const y={x:(t=d?.x)!=null?t:1,y:(n=d?.y)!=null?n:1},m={x:(r=p?.x)!=null?r:0,y:(s=p?.y)!=null?s:0},b={x:(o=v?.x)!=null?o:0,y:(a=v?.y)!=null?a:0,scaleX:(i=v?.scaleX)!=null?i:1,scaleY:(l=v?.scaleY)!=null?l:1};return{x:m.x+b.x,y:m.y+b.y,z:(c=p?.z)!=null?c:0,scaleX:y.x*b.scaleX,scaleY:y.y*b.scaleY}}function vp(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}var _t=(e=>(e[e.Idle=0]="Idle",e[e.Forward=1]="Forward",e[e.Reverse=-1]="Reverse",e))(_t||{}),yp={x:.2,y:.2},bp={x:10,y:10};function wp(e,t,n,r=25,s=yp,o=bp){const{x:a,y:i}=t,{rect:l,isTop:c,isBottom:u,isLeft:f,isRight:h}=$u(e),d=Nn(e),p=Zt(e,!0),v=Xa(p),y=v!==null?v?.scaleX<0:!1,m=v!==null?v?.scaleY<0:!1,b=new Dr(l.left*d.scaleX+d.x,l.top*d.scaleY+d.y,l.width*d.scaleX,l.height*d.scaleY),_={x:0,y:0},w={x:0,y:0},x={height:b.height*s.y,width:b.width*s.x};return(!c||m&&!u)&&i<=b.top+x.height&&n?.y!==1&&a>=b.left-o.x&&a<=b.right+o.x?(_.y=m?1:-1,w.y=r*Math.abs((b.top+x.height-i)/x.height)):(!u||m&&!c)&&i>=b.bottom-x.height&&n?.y!==-1&&a>=b.left-o.x&&a<=b.right+o.x&&(_.y=m?-1:1,w.y=r*Math.abs((b.bottom-x.height-i)/x.height)),(!h||y&&!f)&&a>=b.right-x.width&&n?.x!==-1&&i>=b.top-o.y&&i<=b.bottom+o.y?(_.x=y?-1:1,w.x=r*Math.abs((b.right-x.width-a)/x.width)):(!f||y&&!h)&&a<=b.left+x.width&&n?.x!==1&&i>=b.top-o.y&&i<=b.bottom+o.y&&(_.x=y?1:-1,w.x=r*Math.abs((b.left+x.width-a)/x.width)),{direction:_,speed:w}}function _p(e){return"scrollIntoViewIfNeeded"in e&&typeof e.scrollIntoViewIfNeeded=="function"}function xp(e,t=!1){if(_p(e)){e.scrollIntoViewIfNeeded(t);return}if(!mn(e))return e.scrollIntoView();var n=pp(e);if(!mn(n))return;const r=Zt(n,!0),s=parseInt(r.getPropertyValue("border-top-width")),o=parseInt(r.getPropertyValue("border-left-width")),a=e.offsetTop-n.offsetTop<n.scrollTop,i=e.offsetTop-n.offsetTop+e.clientHeight-s>n.scrollTop+n.clientHeight,l=e.offsetLeft-n.offsetLeft<n.scrollLeft,c=e.offsetLeft-n.offsetLeft+e.clientWidth-o>n.scrollLeft+n.clientWidth,u=a&&!i;(a||i)&&t&&(n.scrollTop=e.offsetTop-n.offsetTop-n.clientHeight/2-s+e.clientHeight/2),(l||c)&&t&&(n.scrollLeft=e.offsetLeft-n.offsetLeft-n.clientWidth/2-o+e.clientWidth/2),(a||i||l||c)&&!t&&e.scrollIntoView(u)}function Cp(e,t,n){const{scaleX:r,scaleY:s,x:o,y:a}=t,i=e.left+o+(1-r)*parseFloat(n),l=e.top+a+(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),c=r?e.width*r:e.width,u=s?e.height*s:e.height;return{width:c,height:u,top:l,right:i+c,bottom:l+u,left:i}}function Sp(e,t,n){const{scaleX:r,scaleY:s,x:o,y:a}=t,i=e.left-o-(1-r)*parseFloat(n),l=e.top-a-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),c=r?e.width/r:e.width,u=s?e.height/s:e.height;return{width:c,height:u,top:l,right:i+c,bottom:l+u,left:i}}function kp({element:e,keyframes:t,options:n}){return e.animate(t,n).finished}var Ep=new Ga(e=>setTimeout(e,0)),gr=new Map,Ip=gr.clear.bind(gr);function Mp(e){const t=e.ownerDocument;let n=gr.get(t);if(n)return n;n=t.getAnimations(),gr.set(t,n),Ep.schedule(Ip);const r=n.filter(s=>Ws(s.effect)&&s.effect.target===e);return gr.set(e,r),n}function Ap(e,t){const n=Mp(e).filter(r=>{var s,o;if(Ws(r.effect)){const{target:a}=r.effect;if((o=a&&((s=t.isValidTarget)==null?void 0:s.call(t,a)))!=null?o:!0)return r.effect.getKeyframes().some(l=>{for(const c of t.properties)if(l[c])return!0})}}).map(r=>{const{effect:s,currentTime:o}=r,a=s?.getComputedTiming().duration;if(!(r.pending||r.playState==="finished")&&typeof a=="number"&&typeof o=="number"&&o<a)return r.currentTime=a,()=>{r.currentTime=o}});if(n.length>0)return()=>n.forEach(r=>r?.())}var Nt=class extends Dr{constructor(e,t={}){var n,r,s,o;const{frameTransform:a=Nn(e),ignoreTransforms:i,getBoundingClientRect:l=Bs}=t,c=Ap(e,{properties:["transform","translate","scale","width","height"],isValidTarget:x=>(x!==e||Za())&&x.contains(e)}),u=l(e);let{top:f,left:h,width:d,height:p}=u,v;const y=Zt(e),m=Xa(y),b={x:(n=m?.scaleX)!=null?n:1,y:(r=m?.scaleY)!=null?r:1},_=Tp(e,y);c?.(),m&&(v=Sp(u,m,y.transformOrigin),(i||_)&&(f=v.top,h=v.left,d=v.width,p=v.height));const w={width:(s=v?.width)!=null?s:d,height:(o=v?.height)!=null?o:p};if(_&&!i&&v){const x=Cp(v,_,y.transformOrigin);f=x.top,h=x.left,d=x.width,p=x.height,b.x=_.scaleX,b.y=_.scaleY}a&&(i||(h*=a.scaleX,d*=a.scaleX,f*=a.scaleY,p*=a.scaleY),h+=a.x,f+=a.y),super(h,f,d,p),this.scale=b,this.intrinsicWidth=w.width,this.intrinsicHeight=w.height}};function Tp(e,t){var n;const r=e.getAnimations();let s=null;if(!r.length)return null;for(const o of r){if(o.playState!=="running")continue;const a=Ws(o.effect)?o.effect.getKeyframes():[],i=a[a.length-1];if(!i)continue;const{transform:l,translate:c,scale:u}=i;if(l||c||u){const f=Xa({transform:typeof l=="string"&&l?l:t.transform,translate:typeof c=="string"&&c?c:t.translate,scale:typeof u=="string"&&u?u:t.scale});f&&(s=s?{x:s.x+f.x,y:s.y+f.y,z:(n=s.z)!=null?n:f.z,scaleX:s.scaleX*f.scaleX,scaleY:s.scaleY*f.scaleY}:f)}}return s}function vr(e){return"style"in e&&typeof e.style=="object"&&e.style!==null&&"setProperty"in e.style&&"removeProperty"in e.style&&typeof e.style.setProperty=="function"&&typeof e.style.removeProperty=="function"}var $p=class{constructor(e){this.element=e,this.initial=new Map}set(e,t=""){const{element:n}=this;if(vr(n))for(const[r,s]of Object.entries(e)){const o=`${t}${r}`;this.initial.has(o)||this.initial.set(o,n.style.getPropertyValue(o)),n.style.setProperty(o,typeof s=="string"?s:`${s}px`)}}remove(e,t=""){const{element:n}=this;if(vr(n))for(const r of e){const s=`${t}${r}`;n.style.removeProperty(s)}}reset(){const{element:e}=this;if(vr(e)){for(const[t,n]of this.initial)e.style.setProperty(t,n);e.getAttribute("style")===""&&e.removeAttribute("style")}}};function gn(e){return e?e instanceof St(e).Element||Or(e)&&e.nodeType===Node.ELEMENT_NODE:!1}function Ya(e){if(!e)return!1;const{KeyboardEvent:t}=St(e.target);return e instanceof t}function Rp(e){if(!e)return!1;const{PointerEvent:t}=St(e.target);return e instanceof t}function Dp(e){if(!gn(e))return!1;const{tagName:t}=e;return t==="INPUT"||t==="TEXTAREA"||Pp(e)}function Pp(e){return e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")!=="false"}var po={};function jo(e){const t=po[e]==null?0:po[e]+1;return po[e]=t,`${e}-${t}`}var Fp=({dragOperation:e,droppable:t})=>{const n=e.position.current;if(!n)return null;const{id:r}=t;if(!t.shape)return null;if(t.shape.containsPoint(n)){const s=Pt.distance(t.shape.center,n);return{id:r,value:1/s,type:xa.PointerIntersection,priority:_a.High}}return null},Op=({dragOperation:e,droppable:t})=>{const{shape:n}=e;if(!t.shape||!n?.current)return null;const r=n.current.intersectionArea(t.shape);if(r){const{position:s}=e,o=Pt.distance(t.shape.center,s.current),i=r/(n.current.area+t.shape.area-r)/o;return{id:t.id,value:i,type:xa.ShapeIntersection,priority:_a.Normal}}return null},Lp=e=>{var t;return(t=Fp(e))!=null?t:Op(e)},Wp=Object.create,Ka=Object.defineProperty,Bp=Object.defineProperties,Vp=Object.getOwnPropertyDescriptor,Np=Object.getOwnPropertyDescriptors,Es=Object.getOwnPropertySymbols,Ru=Object.prototype.hasOwnProperty,Du=Object.prototype.propertyIsEnumerable,Pu=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Yn=e=>{throw TypeError(e)},Zo=(e,t,n)=>t in e?Ka(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,kr=(e,t)=>{for(var n in t||(t={}))Ru.call(t,n)&&Zo(e,n,t[n]);if(Es)for(var n of Es(t))Du.call(t,n)&&Zo(e,n,t[n]);return e},qa=(e,t)=>Bp(e,Np(t)),bl=(e,t)=>Ka(e,"name",{value:t,configurable:!0}),Fu=(e,t)=>{var n={};for(var r in e)Ru.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Es)for(var r of Es(e))t.indexOf(r)<0&&Du.call(e,r)&&(n[r]=e[r]);return n},Kn=e=>{var t;return[,,,Wp((t=e?.[Pu("metadata")])!=null?t:null)]},Ou=["class","method","getter","setter","accessor","field","value","get","set"],dr=e=>e!==void 0&&typeof e!="function"?Yn("Function expected"):e,zp=(e,t,n,r,s)=>({kind:Ou[e],name:t,metadata:r,addInitializer:o=>n._?Yn("Already initialized"):s.push(dr(o||null))}),_n=(e,t)=>Zo(t,Pu("metadata"),e[3]),We=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)t&1?o[s].call(n):r=o[s].call(n,r);return r},gt=(e,t,n,r,s,o)=>{var a,i,l,c,u,f=t&7,h=!!(t&8),d=!!(t&16),p=f>3?e.length+1:f?h?1:2:0,v=Ou[f+5],y=f>3&&(e[p-1]=[]),m=e[p]||(e[p]=[]),b=f&&(!d&&!h&&(s=s.prototype),f<5&&(f>3||!d)&&Vp(f<4?s:{get[n](){return Ce(this,o)},set[n](w){return rt(this,o,w)}},n));f?d&&f<4&&bl(o,(f>2?"set ":f>1?"get ":"")+n):bl(s,n);for(var _=r.length-1;_>=0;_--)c=zp(f,n,l={},e[3],m),f&&(c.static=h,c.private=d,u=c.access={has:d?w=>jp(s,w):w=>n in w},f^3&&(u.get=d?w=>(f^1?Ce:vn)(w,s,f^4?o:b.get):w=>w[n]),f>2&&(u.set=d?(w,x)=>rt(w,s,x,f^4?o:b.set):(w,x)=>w[n]=x)),i=(0,r[_])(f?f<4?d?o:b[v]:f>4?void 0:{get:b.get,set:b.set}:s,c),l._=1,f^4||i===void 0?dr(i)&&(f>4?y.unshift(i):f?d?o=i:b[v]=i:s=i):typeof i!="object"||i===null?Yn("Object expected"):(dr(a=i.get)&&(b.get=a),dr(a=i.set)&&(b.set=a),dr(a=i.init)&&y.unshift(a));return f||_n(e,s),b&&Ka(s,n,b),d?f^4?o:b:s},Ja=(e,t,n)=>t.has(e)||Yn("Cannot "+n),jp=(e,t)=>Object(t)!==t?Yn('Cannot use the "in" operator on this value'):e.has(t),Ce=(e,t,n)=>(Ja(e,t,"read from private field"),n?n.call(e):t.get(e)),De=(e,t,n)=>t.has(e)?Yn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),rt=(e,t,n,r)=>(Ja(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),vn=(e,t,n)=>(Ja(e,t,"access private method"),n),wl={role:"button",roleDescription:"draggable"},Zp="dnd-kit-description",Hp="dnd-kit-announcement",Gp={draggable:"To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item in a given direction. Press space again to drop the item in its new position, or press escape to cancel."},Up={dragstart({operation:{source:e}}){if(e)return`Picked up draggable item ${e.id}.`},dragover({operation:{source:e,target:t}}){if(!(!e||e.id===t?.id))return t?`Draggable item ${e.id} was moved over droppable target ${t.id}.`:`Draggable item ${e.id} is no longer over a droppable target.`},dragend({operation:{source:e,target:t},canceled:n}){if(e)return n?`Dragging was cancelled. Draggable item ${e.id} was dropped.`:t?`Draggable item ${e.id} was dropped over droppable target ${t.id}`:`Draggable item ${e.id} was dropped.`}};function Xp(e){const t=e.tagName.toLowerCase();return["input","select","textarea","a","button"].includes(t)}function Yp(e,t){const n=document.createElement("div");return n.id=e,n.style.setProperty("display","none"),n.textContent=t,n}function Kp(e){const t=document.createElement("div");return t.id=e,t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.setProperty("position","fixed"),t.style.setProperty("width","1px"),t.style.setProperty("height","1px"),t.style.setProperty("margin","-1px"),t.style.setProperty("border","0"),t.style.setProperty("padding","0"),t.style.setProperty("overflow","hidden"),t.style.setProperty("clip","rect(0 0 0 0)"),t.style.setProperty("clip-path","inset(100%)"),t.style.setProperty("white-space","nowrap"),t}var qp=["dragover","dragmove"],Jp=class extends it{constructor(e,t){super(e);const{id:n,idPrefix:{description:r=Zp,announcement:s=Hp}={},announcements:o=Up,screenReaderInstructions:a=Gp,debounce:i=500}=t??{},l=n?`${r}-${n}`:jo(r),c=n?`${s}-${n}`:jo(s);let u,f,h,d;const p=(x=d)=>{!h||!x||h?.nodeValue!==x&&(h.nodeValue=x)},v=()=>Ss.schedule(p),y=Qp(v,i),m=Object.entries(o).map(([x,S])=>this.manager.monitor.addEventListener(x,(k,E)=>{const M=h;if(!M)return;const I=S?.(k,E);I&&M.nodeValue!==I&&(d=I,qp.includes(x)?y():(v(),y.cancel()))})),b=()=>{let x=[];u?.isConnected||(u=Yp(l,a.draggable),x.push(u)),f?.isConnected||(f=Kp(c),h=document.createTextNode(""),f.appendChild(h),x.push(f)),x.length>0&&document.body.append(...x)},_=new Set;function w(){for(const x of _)x()}this.registerEffect(()=>{var x;_.clear();for(const S of this.manager.registry.draggables.value){const k=(x=S.handle)!=null?x:S.element;if(k){(!u||!f)&&_.add(b),(!Xp(k)||Za())&&!k.hasAttribute("tabindex")&&_.add(()=>k.setAttribute("tabindex","0")),!k.hasAttribute("role")&&k.tagName.toLowerCase()!=="button"&&_.add(()=>k.setAttribute("role",wl.role)),k.hasAttribute("aria-roledescription")||_.add(()=>k.setAttribute("aria-roledescription",wl.roleDescription)),k.hasAttribute("aria-describedby")||_.add(()=>k.setAttribute("aria-describedby",l));for(const M of["aria-pressed","aria-grabbed"]){const I=String(S.isDragging);k.getAttribute(M)!==I&&_.add(()=>k.setAttribute(M,I))}const E=String(S.disabled);k.getAttribute("aria-disabled")!==E&&_.add(()=>k.setAttribute("aria-disabled",E))}}_.size>0&&Ss.schedule(w)}),this.destroy=()=>{super.destroy(),u?.remove(),f?.remove(),m.forEach(x=>x())}}};function Qp(e,t){let n;const r=()=>{clearTimeout(n),n=setTimeout(e,t)};return r.cancel=()=>clearTimeout(n),r}var em=class extends it{constructor(e,t){super(e,t),this.manager=e;const n=ys(()=>{var r;return wn((r=this.manager.dragOperation.source)==null?void 0:r.element)});this.destroy=Ct(()=>{var r;const{dragOperation:s}=this.manager,{cursor:o="grabbing",nonce:a}=(r=this.options)!=null?r:{};if(s.status.initialized){const i=n.value,l=i.createElement("style");return a&&l.setAttribute("nonce",a),l.textContent=`* { cursor: ${o} !important; }`,i.head.appendChild(l),()=>l.remove()}})}},Is=new Map,Lu,Wu,Bu,Vu,Ho,yr,zt,Qa,zn,Nu,zu,ju,Zu,xn=class extends(Ho=Fr,Vu=[de],Bu=[Ie],Wu=[Ie],Lu=[Ie],Ho){constructor(e){super(e),We(zt,5,this),De(this,zn),De(this,yr,new Set),De(this,Qa,We(zt,8,this,new Set)),We(zt,11,this),this.registerEffect(vn(this,zn,Nu))}register(e){return Ce(this,yr).add(e),()=>{Ce(this,yr).delete(e)}}addRoot(e){return we(()=>{const t=new Set(this.additionalRoots);t.add(e),this.additionalRoots=t}),()=>{we(()=>{const t=new Set(this.additionalRoots);t.delete(e),this.additionalRoots=t})}}get sourceRoot(){var e;const{source:t}=this.manager.dragOperation;return _s((e=t?.element)!=null?e:null)}get targetRoot(){var e;const{target:t}=this.manager.dragOperation;return _s((e=t?.element)!=null?e:null)}get roots(){const{status:e}=this.manager.dragOperation;if(e.initializing||e.initialized){const t=[this.sourceRoot,this.targetRoot].filter(n=>n!=null);return new Set([...t,...this.additionalRoots])}return new Set}};zt=Kn(Ho);yr=new WeakMap;Qa=new WeakMap;zn=new WeakSet;Nu=function(){const{roots:e}=this,t=[];for(const n of e)for(const r of Ce(this,yr))t.push(vn(this,zn,zu).call(this,n,r));return()=>{for(const n of t)n()}};zu=function(e,t){let n=Is.get(e);n||(n=new Map,Is.set(e,n));let r=n.get(t);if(!r){const o=ja(e)?vn(this,zn,ju).call(this,e,n,t):vn(this,zn,Zu).call(this,e,n,t);if(!o)return()=>{};r=o,n.set(t,r)}r.refCount++;let s=!1;return()=>{s||(s=!0,r.refCount--,r.refCount===0&&r.cleanup())}};ju=function(e,t,n){const r=e.createElement("style");r.textContent=n,e.head.prepend(r);const s=new MutationObserver(o=>{for(const a of o)for(const i of Array.from(a.removedNodes))if(i===r){e.head.prepend(r);return}});return s.observe(e.head,{childList:!0}),{refCount:0,cleanup:()=>{s.disconnect(),r.remove(),t.delete(n),t.size===0&&Is.delete(e)}}};Zu=function(e,t,n){!("adoptedStyleSheets"in e&&Array.isArray(e.adoptedStyleSheets))&&process.env.NODE_ENV!=="production"&&console.error("Cannot inject styles: This browser doesn't support adoptedStyleSheets");const r=e.ownerDocument.defaultView,{CSSStyleSheet:s}=r??{};if(!s)return process.env.NODE_ENV!=="production"&&console.error("Cannot inject styles: CSSStyleSheet constructor not available"),null;const o=new s;return o.replaceSync(n),e.adoptedStyleSheets.push(o),{refCount:0,cleanup:()=>{var a;if(Ha(e)&&((a=e.host)!=null&&a.isConnected)){const i=e.adoptedStyleSheets.indexOf(o);i!==-1&&e.adoptedStyleSheets.splice(i,1)}t.delete(n),t.size===0&&Is.delete(e)}}};gt(zt,4,"additionalRoots",Vu,xn,Qa);gt(zt,2,"sourceRoot",Bu,xn);gt(zt,2,"targetRoot",Wu,xn);gt(zt,2,"roots",Lu,xn);_n(zt,xn);var Lr="data-dnd-",Go=`${Lr}dropping`,Je="--dnd-",Dt=`${Lr}dragging`,Ms=`${Lr}placeholder`,tm=[Dt,Ms,"popover","aria-pressed","aria-grabbing"],nm=["view-transition-name"],rm=`
9
9
  :is(:root,:host) [${Dt}] {
10
10
  position: fixed !important;
11
11
  pointer-events: none !important;
@@ -35,7 +35,7 @@
35
35
  pointer-events: none !important;
36
36
  }
37
37
 
38
- [${Dt}]:not([${Uo}]) {
38
+ [${Dt}]:not([${Go}]) {
39
39
  translate: var(${Je}translate) !important;
40
40
  }
41
41
 
@@ -63,13 +63,13 @@
63
63
  display: none;
64
64
  visibility: hidden;
65
65
  }
66
- `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function rm(e,t="hidden"){return we(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=sm(n,r.registry.droppables),o=[],a=Xh(n),{remove:i}=a;return om(s,a,o),am(a,t),a.remove=()=>{o.forEach(l=>l()),i.call(a)},a})}function sm(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Lr}${Zo("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function om(e,t,n){for(const[r,s]of e){if(!r.element)continue;const o=`[${s}]`,a=t.matches(o)?t:t.querySelector(o);if(r.element.removeAttribute(s),!a)continue;const i=r.element;r.proxy=a,a.removeAttribute(s),gl.set(i,a),n.push(()=>{gl.delete(i),r.proxy=void 0})}}function am(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Ms,t)}function Zu(e,t){return e===t?!0:Vn(e)===Vn(t)}function xl(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&gn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Sr(t))}function Xo(e){return e.tagName==="TR"}function im(e,t,n){const r=new MutationObserver(s=>{let o=!1;for(const a of s){if(a.target!==e){o=!0;continue}if(a.type!=="attributes")continue;const i=a.attributeName;if(i.startsWith("aria-")||em.includes(i))continue;const l=e.getAttribute(i);if(i==="style"){if(vr(e)&&vr(t)){const c=e.style;for(const u of Array.from(t.style))c.getPropertyValue(u)===""&&t.style.removeProperty(u);for(const u of Array.from(c)){if(tm.includes(u)||u.startsWith(Je))continue;const f=c.getPropertyValue(u);t.style.setProperty(u,f)}}}else l!==null?t.setAttribute(i,l):t.removeAttribute(i)}o&&n&&(t.innerHTML=e.innerHTML)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function lm(e,t,n){const r=new MutationObserver(s=>{for(const o of s)if(o.addedNodes.length!==0)for(const a of Array.from(o.addedNodes)){if(a.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),Sr(n);return}if(a.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Sr(n);return}}});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function cm(e){return new ResizeObserver(()=>{var t,n;const r=new Nt(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-r.width)*s.x+e.delta.x,a=(e.height-r.height)*s.y+e.delta.y,i=_u();if(e.styles.set({width:r.width-e.widthOffset,height:r.height-e.heightOffset,top:e.top+a+i.y,left:e.left+o+i.x},Je),(n=e.getElementMutationObserver())==null||n.takeRecords(),Xo(e.element)&&Xo(e.placeholder)){const l=Array.from(e.element.cells),c=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(l.map(u=>u.style.width));for(const[u,f]of l.entries()){const h=c[u];f.style.width=`${h.getBoundingClientRect().width}px`}}e.dragOperation.shape=new Nt(e.feedbackElement)})}var um=250,dm="ease";function fm(e){var t,n,r,s;const{animation:o}=e;if(typeof o=="function"){const b=o({element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(b).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:a=um,easing:i=dm}=o??{};Sr(e.feedbackElement);const[,l]=(t=Zh(e.feedbackElement,b=>"translate"in b))!=null?t:[];l?.pause();const c=(n=e.placeholder)!=null?n:e.element,u={frameTransform:Zu(e.feedbackElement,c)?null:void 0},f=new Nt(e.feedbackElement,u),h=(r=Xa(Zt(e.feedbackElement).translate))!=null?r:e.translate,d=new Nt(c,u),p=Dr.delta(f,d,e.alignment),v={x:h.x-p.x,y:h.y-p.y},y=Math.round(f.intrinsicHeight)!==Math.round(d.intrinsicHeight)?{minHeight:[`${f.intrinsicHeight}px`,`${d.intrinsicHeight}px`],maxHeight:[`${f.intrinsicHeight}px`,`${d.intrinsicHeight}px`]}:{},m=Math.round(f.intrinsicWidth)!==Math.round(d.intrinsicWidth)?{minWidth:[`${f.intrinsicWidth}px`,`${d.intrinsicWidth}px`],maxWidth:[`${f.intrinsicWidth}px`,`${d.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Je),e.feedbackElement.setAttribute(Uo,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),Sp({element:e.feedbackElement,keyframes:Ja(kr(kr({},y),m),{translate:[`${h.x}px ${h.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:xu(St(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?a:0,easing:i}}).then(()=>{e.feedbackElement.removeAttribute(Uo),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Hu,Yo,Er,ti,fs,Gu,Uu,Ir=class extends(Yo=it,Hu=[de],Yo){constructor(t,n){super(t,n),De(this,fs),De(this,ti,We(Er,8,this)),We(Er,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(xn),s=r?.register(nm);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}this.registerEffect(vn(this,fs,Gu).bind(this,r)),this.registerEffect(vn(this,fs,Uu))}};Er=Kn(Yo);ti=new WeakMap;fs=new WeakSet;Gu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=_s(t);if(n)return e.addRoot(n)};Uu=function(){var e,t,n;const{state:r,manager:s,options:o}=this,{dragOperation:a}=s,{position:i,source:l,status:c}=a;if(c.idle){r.current={},r.initial={};return}if(!l)return;const{element:u,feedback:f}=l;if(!u||f==="none"||!c.initialized||c.initializing)return;const{initial:h}=r,d=(e=this.overlay)!=null?e:u,p=Nn(d),v=Nn(u),y=!Zu(u,d),m=new Nt(u,{frameTransform:y?v:null,ignoreTransforms:!y}),b={x:v.scaleX/p.scaleX,y:v.scaleY/p.scaleY};let{width:_,height:w,top:x,left:S}=m;y&&(_=_/b.x,w=w/b.y);const k=new Tp(d),{transition:E,translate:T,boxSizing:I,paddingBlockStart:M,paddingBlockEnd:$,paddingInlineStart:A,paddingInlineEnd:R,borderInlineStartWidth:W,borderInlineEndWidth:q,borderBlockStartWidth:z,borderBlockEndWidth:J}=Zt(u),ee=f==="clone",j=I==="content-box",se=j?parseInt(A)+parseInt(R)+parseInt(W)+parseInt(q):0,U=j?parseInt(M)+parseInt($)+parseInt(z)+parseInt(J):0,ie=f!=="move"&&!this.overlay?rm(l,ee?"clone":"hidden"):null,le=we(()=>Ka(s.dragOperation.activatorEvent));if(T!=="none"){const oe=Xa(T);oe&&!h.translate&&(h.translate=oe)}if(!h.transformOrigin){const oe=we(()=>i.current);h.transformOrigin={x:(oe.x-S*p.scaleX-p.x)/(_*p.scaleX),y:(oe.y-x*p.scaleY-p.y)/(w*p.scaleY)}}const{transformOrigin:ge}=h,Se=x*p.scaleY+p.y,N=S*p.scaleX+p.x;if(!h.coordinates&&(h.coordinates={x:N,y:Se},b.x!==1||b.y!==1)){const{scaleX:oe,scaleY:he}=v,{x:Xe,y:At}=ge;h.coordinates.x+=(_*oe-_)*Xe,h.coordinates.y+=(w*he-w)*At}h.dimensions||(h.dimensions={width:_,height:w}),h.frameTransform||(h.frameTransform=p);const G={x:h.coordinates.x-N,y:h.coordinates.y-Se},ye={width:(h.dimensions.width*h.frameTransform.scaleX-_*p.scaleX)*ge.x,height:(h.dimensions.height*h.frameTransform.scaleY-w*p.scaleY)*ge.y},Z={x:G.x/p.scaleX+ye.width,y:G.y/p.scaleY+ye.height},Q={left:S+Z.x,top:x+Z.y};d.setAttribute(Dt,"true");const O=we(()=>a.transform),_e=(t=h.translate)!=null?t:{x:0,y:0},Ne=O.x*p.scaleX+_e.x,Be=O.y*p.scaleY+_e.y,ve=_u();k.set({width:_-se,height:w-U,top:Q.top+ve.y,left:Q.left+ve.x,translate:`${Ne}px ${Be}px 0`,transition:E?`${E}, translate 0ms linear`:"",scale:y?`${b.x} ${b.y}`:"","transform-origin":`${ge.x*100}% ${ge.y*100}%`},Je),ie&&(u.insertAdjacentElement("afterend",ie),o?.rootElement&&(typeof o.rootElement=="function"?o.rootElement(l):o.rootElement).appendChild(u)),zo(d)&&(d.hasAttribute("popover")||d.setAttribute("popover","manual"),Sr(d),d.addEventListener("beforetoggle",xl));let Ve,ne,Ge;const je=cm({placeholder:ie,element:u,feedbackElement:d,frameTransform:p,transformOrigin:ge,width:_,height:w,top:x,left:S,widthOffset:se,heightOffset:U,delta:Z,styles:k,dragOperation:a,getElementMutationObserver:()=>Ve,getSavedCellWidths:()=>Ge,setSavedCellWidths:oe=>{Ge=oe}}),xe=new Nt(d);we(()=>a.shape=xe);const Fe=St(d),Oe=oe=>{this.manager.actions.stop({event:oe})},Et=xu(Fe);le&&Fe.addEventListener("resize",Oe),we(()=>l.status)==="idle"&&requestAnimationFrame(()=>l.status="dragging"),ie&&(je.observe(ie),Ve=im(u,ie,ee),ne=lm(u,ie,d));const It=(n=s.dragOperation.source)==null?void 0:n.id,Mt=()=>{var oe;if(!le||It==null)return;const he=s.registry.draggables.get(It),Xe=(oe=he?.handle)!=null?oe:he?.element;mn(Xe)&&Xe.focus()},X=()=>{var oe;if(Ve?.disconnect(),ne?.disconnect(),je.disconnect(),Fe.removeEventListener("resize",Oe),zo(d)&&(d.removeEventListener("beforetoggle",xl),d.removeAttribute("popover")),d.removeAttribute(Dt),k.reset(),Ge&&Xo(u)){const Xe=Array.from(u.cells);for(const[At,Tt]of Xe.entries())Tt.style.width=(oe=Ge[At])!=null?oe:""}l.status="idle";const he=r.current.translate!=null;ie&&(he||ie.parentElement!==d.parentElement)&&d.isConnected&&ie.replaceWith(d),ie?.remove()},fe=o?.dropAnimation,Ue=this,Me=Rr(()=>{var oe;const{transform:he,status:Xe}=a;if(!(!he.x&&!he.y&&!r.current.translate)&&Xe.dragging){const At=(oe=h.translate)!=null?oe:{x:0,y:0},Tt={x:he.x/p.scaleX+At.x,y:he.y/p.scaleY+At.y},ut=r.current.translate,yt=we(()=>a.modifiers),V=we(()=>{var K;return(K=a.shape)==null?void 0:K.current}),Y=le&&!Et?"250ms cubic-bezier(0.25, 1, 0.5, 1)":"0ms linear";if(k.set({transition:`${E}, translate ${Y}`,translate:`${Tt.x}px ${Tt.y}px 0`},Je),Ve?.takeRecords(),V&&V!==xe&&ut&&!yt.length){const K=Pt.delta(Tt,ut);a.shape=Dr.from(V.boundingRectangle).translate(K.x*p.scaleX,K.y*p.scaleY)}else a.shape=new Nt(d);r.current.translate=Tt}},function(){if(a.status.dropped){this.dispose(),l.status="dropping";const oe=Ue.dropAnimation!==void 0?Ue.dropAnimation:fe;let he=r.current.translate;const Xe=he!=null;if(!he&&u!==d&&(he={x:0,y:0}),!he||oe===null){X();return}s.renderer.rendering.then(()=>{fm({element:u,feedbackElement:d,placeholder:ie,translate:he,moved:Xe,transition:E,alignment:l.alignment,styles:k,animation:oe??void 0,getElementMutationObserver:()=>Ve,cleanup:X,restoreFocus:Mt})})}});return()=>{X(),Me()}};gt(Er,4,"overlay",Hu,Ir,ti);_n(Er,Ir);Ir.configure=Xn(Ir);var Ko=Ir,Jn=!0,hm=!1,Xu,Yu,Ku,qu,Kt,ni,ri;qu=(Ku=[de],_t.Forward),Yu=(Xu=[de],_t.Reverse);var Mr=class{constructor(){De(this,ni,We(Kt,8,this,Jn)),We(Kt,11,this),De(this,ri,We(Kt,12,this,Jn)),We(Kt,15,this)}isLocked(e){return e===_t.Idle?!1:e==null?this[_t.Forward]===Jn&&this[_t.Reverse]===Jn:this[e]===Jn}unlock(e){e!==_t.Idle&&(this[e]=hm)}};Kt=Kn(null);ni=new WeakMap;ri=new WeakMap;gt(Kt,4,qu,Ku,Mr,ni);gt(Kt,4,Yu,Xu,Mr,ri);_n(Kt,Mr);var pm=[_t.Forward,_t.Reverse],Cl=class{constructor(){this.x=new Mr,this.y=new Mr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},mm=class extends it{constructor(e){super(e);const t=$r(new Cl);let n=null;this.signal=t,Ct(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new Cl;return}const{delta:s}=e.dragOperation.position;if(n){const o={x:Sl(s.x,n.x),y:Sl(s.y,n.y)},a=t.peek();Qt(()=>{for(const i of Mc)for(const l of pm)o[i]===l&&a[i].unlock(l);t.value=a})}n=s})}get current(){return this.signal.peek()}};function Sl(e,t){return Math.sign(e-t)}var Ju,qo,Ar,si,Xt,Jo,Vs=class extends(qo=Fr,Ju=[de],qo){constructor(e){super(e),De(this,si,We(Ar,8,this,!1)),We(Ar,11,this),De(this,Xt),De(this,Jo,()=>{if(!Ce(this,Xt))return;const{element:o,by:a}=Ce(this,Xt);a.y&&(o.scrollTop+=a.y),a.x&&(o.scrollLeft+=a.x)}),this.scroll=o=>{var a;if(this.disabled)return!1;const i=this.getScrollableElements();if(!i)return rt(this,Xt,void 0),!1;const{position:l}=this.manager.dragOperation,c=l?.current;if(c){const{by:u}=o??{},f=u?{x:kl(u.x),y:kl(u.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const d of i){const p=ip(d,u);if(p.x||p.y){const{speed:v,direction:y}=bp(d,c,f);if(h)for(const m of Mc)h[m].isLocked(y[m])&&(v[m]=0,y[m]=0);if(y.x||y.y){const{x:m,y:b}=u??y,_=m*v.x,w=b*v.y;if(_||w){const x=(a=Ce(this,Xt))==null?void 0:a.by;if(this.autoScrolling&&x&&(x.x&&!_||x.y&&!w))continue;return rt(this,Xt,{element:d,by:{x:_,y:w}}),Ss.schedule(Ce(this,Jo)),!0}}}}}return rt(this,Xt,void 0),!1};let t=null,n=null;const r=ys(()=>{const{position:o,source:a}=e.dragOperation;if(!o)return null;const i=Cu(_s(a?.element),o.current);return i&&(t=i),i??t}),s=ys(()=>{const o=r.value,{documentElement:a}=wn(o);if(!o||o===a){const{target:i}=e.dragOperation,l=i?.element;if(l){const c=jo(l,{excludeElement:!1});return n=c,c}}if(o){const i=jo(o,{excludeElement:!1});return this.autoScrolling&&n&&i.size<n?.size?n:(n=i,i)}return n=null,null},_r);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new mm(e),this.destroy=e.monitor.addEventListener("dragmove",o=>{this.disabled||o.defaultPrevented||!Ka(e.dragOperation.activatorEvent)||!o.by||this.scroll({by:o.by})&&o.preventDefault()})}};Ar=Kn(qo);si=new WeakMap;Xt=new WeakMap;Jo=new WeakMap;gt(Ar,4,"autoScrolling",Ju,Vs,si);_n(Ar,Vs);function kl(e){return e>0?_t.Forward:e<0?_t.Reverse:_t.Idle}var gm=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},vm=new gm(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),ym=10,Qu=class extends it{constructor(e,t){super(e);const n=e.registry.plugins.get(Vs);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=Ct(()=>{if(this.disabled)return;const{position:r,status:s}=e.dragOperation;if(s.dragging)if(n.scroll()){n.autoScrolling=!0;const a=setInterval(()=>vm.schedule(n.scroll),ym);return()=>{clearInterval(a)}}else n.autoScrolling=!1})}},El={capture:!0,passive:!0},fr,bm=class extends Fr{constructor(e){super(e),De(this,fr),this.handleScroll=()=>{Ce(this,fr)==null&&rt(this,fr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),rt(this,fr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=Ct(()=>{var n,r,s;if(t.status.dragging){const a=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return a.addEventListener("scroll",this.handleScroll,El),()=>{a.removeEventListener("scroll",this.handleScroll,El)}}})}};fr=new WeakMap;var wm=class extends it{constructor(e,t){super(e,t),this.manager=e,this.destroy=Ct(()=>{var n;const{dragOperation:r}=this.manager,{nonce:s}=(n=this.options)!=null?n:{};if(r.status.initialized){const o=document.createElement("style");return s&&o.setAttribute("nonce",s),o.textContent="* { user-select: none !important; -webkit-user-select: none !important; }",document.head.appendChild(o),mo(),document.addEventListener("selectionchange",mo,{capture:!0}),()=>{document.removeEventListener("selectionchange",mo,{capture:!0}),o.remove()}}})}};function mo(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var hr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),Dn,As=class extends Wn{constructor(t,n){super(t),this.manager=t,this.options=n,De(this,Dn,[]),this.listeners=new Su,this.handleSourceKeyDown=(r,s,o)=>{if(this.disabled||r.defaultPrevented||!gn(r.target)||s.disabled)return;const{keyboardCodes:a=hr.keyboardCodes,preventActivation:i=hr.preventActivation}=o??{};a.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(i?.(r,s)||this.handleStart(r,s,o))}}bind(t,n=this.options){return Ct(()=>{var s;const o=(s=t.handle)!=null?s:t.element,a=i=>{Ka(i)&&this.handleSourceKeyDown(i,t,n)};if(o)return o.addEventListener("keydown",a),()=>{o.removeEventListener("keydown",a)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),_p(s);const{center:o}=new Nt(s);if(this.manager.actions.start({event:t,coordinates:{x:o.x,y:o.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const i=wn(s),l=[this.listeners.bind(i,[{type:"keydown",listener:c=>this.handleKeyDown(c,n,r),options:{capture:!0}}])];Ce(this,Dn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=hr.keyboardCodes}=r??{};if(In(t,[...s.end,...s.cancel])){t.preventDefault();const o=In(t,s.cancel);this.handleEnd(t,o);return}In(t,s.up)?this.handleMove("up",t):In(t,s.down)&&this.handleMove("down",t),In(t,s.left)?this.handleMove("left",t):In(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:o}=this.manager.dragOperation,a=n.shiftKey?5:1;let i={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:hr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!o){switch(t){case"up":i={x:0,y:-l.y*a};break;case"down":i={x:0,y:l.y*a};break;case"left":i={x:-l.x*a,y:0};break;case"right":i={x:l.x*a,y:0};break}(i.x||i.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:i}))}}sideEffects(){const t=this.manager.registry.plugins.get(Qu);t?.disabled===!1&&(t.disable(),Ce(this,Dn).push(()=>{t.enable()}))}cleanup(){Ce(this,Dn).forEach(t=>t()),rt(this,Dn,[])}destroy(){this.cleanup(),this.listeners.clear()}};Dn=new WeakMap;As.configure=Xn(As);As.defaults=hr;var _m=As;function In(e,t){return t.includes(e.code)}var fn,xm=class extends iu{constructor(){super(...arguments),De(this,fn)}onEvent(e){switch(e.type){case"pointerdown":rt(this,fn,Bn(e));break;case"pointermove":if(!Ce(this,fn))return;const{x:t,y:n}=Bn(e),r={x:t-Ce(this,fn).x,y:n-Ce(this,fn).y},{tolerance:s}=this.options;if(s&&Oo(r,s)){this.abort();return}Oo(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){rt(this,fn,void 0)}};fn=new WeakMap;var Pn,hn,Cm=class extends iu{constructor(){super(...arguments),De(this,Pn),De(this,hn)}onEvent(e){switch(e.type){case"pointerdown":rt(this,hn,Bn(e)),rt(this,Pn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!Ce(this,hn))return;const{x:t,y:n}=Bn(e),r={x:t-Ce(this,hn).x,y:n-Ce(this,hn).y};Oo(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){Ce(this,Pn)&&(clearTimeout(Ce(this,Pn)),rt(this,hn,void 0),rt(this,Pn,void 0))}};Pn=new WeakMap;hn=new WeakMap;var Bt=class{};Bt.Delay=Cm;Bt.Distance=xm;var Qo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&gn(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new Bt.Delay({value:250,tolerance:5})]:Rp(s)&&!e.defaultPrevented?[new Bt.Delay({value:200,tolerance:0})]:[new Bt.Delay({value:200,tolerance:10}),new Bt.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;return r===t.element||r===t.handle||!gn(r)||(n=t.handle)!=null&&n.contains(r)?!1:Kh(r)}}),Fn,Ts=class extends Wn{constructor(t,n){super(t),this.manager=t,this.options=n,De(this,Fn,new Set),this.listeners=new Su,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=Qo.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return Ct(()=>{var s;const o=new AbortController,{signal:a}=o,i=c=>{$p(c)&&this.handlePointerDown(c,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const c of l)c&&(Em(c.ownerDocument.defaultView),c.addEventListener("pointerdown",i,{signal:a}));return()=>o.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!gn(t.target)||n.disabled||Sm(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=Qo.preventActivation}=r??{};if(s?.(t,n))return;const{target:o}=t,a=mn(o)&&o.draggable&&o.getAttribute("draggable")==="true",i=Nn(n.element),{x:l,y:c}=Bn(t);this.initialCoordinates={x:l*i.scaleX+i.x,y:c*i.scaleY+i.y};const u=this.activationConstraints(t,n,r);t.sensor=this;const f=new Vh(u,v=>this.handleStart(n,v));f.signal.onabort=()=>this.handleCancel(t),f.onEvent(t),this.controller=f;const h=Vo(),d=this.listeners.bind(h,[{type:"pointermove",listener:v=>this.handlePointerMove(v,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:a?this.handleCancel:ts,options:{capture:!0}}]),p=()=>{d(),this.initialCoordinates=void 0};Ce(this,Fn).add(p)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const o=Bn(t),a=Nn(n.element);o.x=o.x*a.scaleX+a.x,o.y=o.y*a.scaleY+a.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=o,Ss.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const i=wn(n.target).body;i.setPointerCapture(n.pointerId);const l=gn(n.target)?[n.target,i]:i,c=this.listeners.bind(l,[{type:"touchmove",listener:ts,options:{passive:!1}},{type:"click",listener:ts},{type:"contextmenu",listener:ts},{type:"keydown",listener:this.handleKeyDown}]);Ce(this,Fn).add(c)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){this.latest={event:void 0,coordinates:void 0},Ce(this,Fn).forEach(t=>t()),Ce(this,Fn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Fn=new WeakMap;Ts.configure=Xn(Ts);Ts.defaults=Qo;var ea=Ts;function Sm(e){return"sensor"in e}function ts(e){e.preventDefault()}function km(){}var Il=new WeakSet;function Em(e){!e||Il.has(e)||(e.addEventListener("touchmove",km,{capture:!1,passive:!1}),Il.add(e))}var On={modifiers:[],plugins:[qp,Qu,Qp,Ko,wm],sensors:[ea,_m]},oi=class extends jh{constructor(e={}){const t=Vt(e.plugins,On.plugins),n=Vt(e.sensors,On.sensors),r=Vt(e.modifiers,On.modifiers);super(Ja(kr({},e),{plugins:[bm,Vs,xn,...t],sensors:n,modifiers:r}))}},ed,td,nd,ta,$t,ai,ii,li,Wr=class extends(ta=Ft,nd=[de],td=[de],ed=[de],ta){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:o,feedback:a="default"}=n,i=Pu(n,["element","effects","handle","feedback"]);super(kr({effects:()=>[...s(),()=>{var l,c;const{manager:u}=this;if(!u)return;const h=((c=(l=this.sensors)==null?void 0:l.map(wa))!=null?c:[...u.sensors]).map(d=>{const p=d instanceof Wn?d:u.registry.register(d.plugin),v=d instanceof Wn?void 0:d.options;return p.bind(this,v)});return function(){h.forEach(p=>p())}}]},i),t),De(this,ai,We($t,8,this)),We($t,11,this),De(this,ii,We($t,12,this)),We($t,15,this),De(this,li,We($t,16,this)),We($t,19,this),this.element=r,this.handle=o,this.feedback=a}};$t=Kn(ta);ai=new WeakMap;ii=new WeakMap;li=new WeakMap;gt($t,4,"handle",nd,Wr,ai);gt($t,4,"element",td,Wr,ii);gt($t,4,"feedback",ed,Wr,li);_n($t,Wr);var rd,sd,na,qt,ci,go,od,ad,br,ui,id=class extends(na=Ot,sd=[de],rd=[de],na){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,o=Pu(n,["element","effects"]);const{collisionDetector:a=Op}=o,i=c=>{const{manager:u,element:f}=this;if(!f||c===null){this.shape=void 0;return}if(!u)return;const h=new Nt(f),d=we(()=>this.shape);return h&&d?.equals(h)?d:(this.shape=h,h)},l=$r(!1);super(Ja(kr({},o),{collisionDetector:a,effects:()=>[...s(),()=>{const{element:c,manager:u}=this;if(!u)return;const{dragOperation:f}=u,{source:h}=f;l.value=!!(h&&f.status.initialized&&c&&!this.disabled&&this.accepts(h))},()=>{const{element:c}=this;if(l.value&&c){const u=new ap(c,i);return()=>{u.disconnect(),this.shape=void 0}}},()=>{var c;if((c=this.manager)!=null&&c.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),De(this,br),De(this,ci,We(qt,8,this)),We(qt,11,this),De(this,ui,We(qt,12,this)),We(qt,15,this),this.element=r,this.refreshShape=()=>i()}set element(e){rt(this,br,e,ad)}get element(){var e;return(e=this.proxy)!=null?e:Ce(this,br,od)}};qt=Kn(na);ci=new WeakMap;br=new WeakSet;ui=new WeakMap;go=gt(qt,20,"#element",sd,br,ci),od=go.get,ad=go.set;gt(qt,4,"proxy",rd,id,ui);_n(qt,id);function Im(e){return e!=null&&typeof e=="object"&&"current"in e}function $s(e){var t;if(e!=null)return Im(e)?(t=e.current)!=null?t:void 0:e}var Mm=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ns=Mm?g.useLayoutEffect:g.useEffect;function Am(){const e=g.useState(0)[1];return g.useCallback(()=>{e(t=>t+1)},[e])}function Tm(e,t){const n=g.useRef(new Map),r=Am();return Ns(()=>{if(!e){n.current.clear();return}return Ct(()=>{var s;let o=!1,a=!1;for(const i of n.current){const[l]=i,c=we(()=>i[1]),u=e[l];c!==u&&(o=!0,n.current.set(l,u),a=(s=t?.(l,c,u))!=null?s:!1)}o&&(a?da.flushSync(r):r())})},[e]),g.useMemo(()=>e&&new Proxy(e,{get(s,o){const a=s[o];return n.current.set(o,a),a}}),[e])}function ln(e,t,n=g.useEffect,r=Object.is){const s=g.useRef(e);n(()=>{const o=s.current;r(e,o)||(s.current=e,t(e,o))},[t,e])}function Ml(e,t){const n=g.useRef($s(e));Ns(()=>{const r=$s(e);r!==n.current&&(n.current=r,t(r))})}var $m=Object.defineProperty,Rm=Object.defineProperties,Dm=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,Pm=Object.prototype.hasOwnProperty,Fm=Object.prototype.propertyIsEnumerable,Tl=(e,t,n)=>t in e?$m(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Om=(e,t)=>{for(var n in t||(t={}))Pm.call(t,n)&&Tl(e,n,t[n]);if(Al)for(var n of Al(t))Fm.call(t,n)&&Tl(e,n,t[n]);return e},Lm=(e,t)=>Rm(e,Dm(t)),Wm=new oi,Bm=g.createContext(Wm);g.memo(g.forwardRef(({children:e},t)=>{const[n,r]=g.useState(0),s=g.useRef(null),o=g.useRef(null),a=g.useMemo(()=>({renderer:{get rendering(){var i;return(i=s.current)!=null?i:Promise.resolve()}},trackRendering(i){s.current||(s.current=new Promise(l=>{o.current=l})),g.startTransition(()=>{i(),r(l=>l+1)})}}),[]);return Ns(()=>{var i;(i=o.current)==null||i.call(o),s.current=null},[e,n]),g.useImperativeHandle(t,()=>a),null}));function Vm(){return g.useContext(Bm)}function Nm(e){var t;const n=(t=Vm())!=null?t:void 0,[r]=g.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Ns(r.register,[n,r]),r}function vo(e){const{disabled:t,data:n,element:r,handle:s,id:o,modifiers:a,sensors:i}=e,l=Nm(u=>new Wr(Lm(Om({},e),{register:!1,handle:$s(s),element:$s(r)}),u)),c=Tm(l,zm);return ln(o,()=>l.id=o),Ml(s,u=>l.handle=u),Ml(r,u=>l.element=u),ln(n,()=>n&&(l.data=n)),ln(t,()=>l.disabled=t===!0),ln(i,()=>l.sensors=i),ln(a,()=>l.modifiers=a,void 0,_r),ln(e.feedback,()=>{var u;return l.feedback=(u=e.feedback)!=null?u:"default"}),ln(e.alignment,()=>l.alignment=e.alignment),{draggable:c,get isDragging(){return c.isDragging},get isDropping(){return c.isDropping},get isDragSource(){return c.isDragSource},handleRef:g.useCallback(u=>{l.handle=u??void 0},[l]),ref:g.useCallback(u=>{var f,h;!u&&((f=l.element)!=null&&f.isConnected)&&!((h=l.manager)!=null&&h.dragOperation.status.idle)||(l.element=u??void 0)},[l])}}function zm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}var jm=Object.create,ld=Object.defineProperty,Zm=Object.getOwnPropertyDescriptor,cd=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),zs=e=>{throw TypeError(e)},Hm=(e,t,n)=>t in e?ld(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Gm=e=>{var t;return[,,,jm((t=e?.[cd("metadata")])!=null?t:null)]},ud=["class","method","getter","setter","accessor","field","value","get","set"],dd=e=>e!==void 0&&typeof e!="function"?zs("Function expected"):e,Um=(e,t,n,r,s)=>({kind:ud[e],name:t,metadata:r,addInitializer:o=>n._?zs("Already initialized"):s.push(dd(o||null))}),Xm=(e,t)=>Hm(t,cd("metadata"),e[3]),Ym=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)o[s].call(n);return r},fd=(e,t,n,r,s,o)=>{for(var a,i,l,c,u=t&7,f=!1,h=!1,d=2,p=ud[u+5],v=e[d]||(e[d]=[]),y=(s=s.prototype,Zm(s,n)),m=r.length-1;m>=0;m--)l=Um(u,n,i={},e[3],v),l.static=f,l.private=h,c=l.access={has:b=>n in b},c.get=b=>b[n],a=(0,r[m])(y[p],l),i._=1,dd(a)&&(y[p]=a);return y&&ld(s,n,y),s},hd=(e,t,n)=>t.has(e)||zs("Cannot "+n),Km=(e,t,n)=>(hd(e,t,"read from private field"),t.get(e)),qm=(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),Jm=(e,t,n,r)=>(hd(e,t,"write to private field"),t.set(e,n),n),Qn=class ra{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ra(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 ra(t,n)}},pd,md,sa,hs,Br,di=class extends(sa=tn,md=[Ie],pd=[Ie],sa){constructor(t){const n=Qn.from(t);super(n,(r,s)=>Qn.equals(r,s)),Ym(Br,5,this),qm(this,hs,0),this.velocity={x:0,y:0}}get delta(){return Qn.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=Qn.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),a=o-Km(this,hs),i=l=>Math.round(l/a*100);Qt(()=>{Jm(this,hs,o),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Qn.from(t)),this.velocity={x:0,y:0}}};Br=Gm(sa);hs=new WeakMap;fd(Br,2,"delta",md,di);fd(Br,2,"direction",pd,di);Xm(Br,di);var gd=(e=>(e.Horizontal="x",e.Vertical="y",e))(gd||{});Object.values(gd);const Qm=new Map([["bold",D.createElement(D.Fragment,null,D.createElement("path",{d:"M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128ZM60,112a16,16,0,1,0,16,16A16,16,0,0,0,60,112Zm136,0a16,16,0,1,0,16,16A16,16,0,0,0,196,112Z"}))],["duotone",D.createElement(D.Fragment,null,D.createElement("path",{d:"M240,96v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V96A16,16,0,0,1,32,80H224A16,16,0,0,1,240,96Z",opacity:"0.2"}),D.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["fill",D.createElement(D.Fragment,null,D.createElement("path",{d:"M224,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V96A16,16,0,0,0,224,80ZM60,140a12,12,0,1,1,12-12A12,12,0,0,1,60,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,128,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,196,140Z"}))],["light",D.createElement(D.Fragment,null,D.createElement("path",{d:"M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128ZM60,118a10,10,0,1,0,10,10A10,10,0,0,0,60,118Zm136,0a10,10,0,1,0,10,10A10,10,0,0,0,196,118Z"}))],["regular",D.createElement(D.Fragment,null,D.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["thin",D.createElement(D.Fragment,null,D.createElement("path",{d:"M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Zm-76-8a8,8,0,1,0,8,8A8,8,0,0,0,60,120Zm136,0a8,8,0,1,0,8,8A8,8,0,0,0,196,120Z"}))]]),eg=new Map([["bold",D.createElement(D.Fragment,null,D.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",D.createElement(D.Fragment,null,D.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),D.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",D.createElement(D.Fragment,null,D.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",D.createElement(D.Fragment,null,D.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",D.createElement(D.Fragment,null,D.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",D.createElement(D.Fragment,null,D.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),tg=new Map([["bold",D.createElement(D.Fragment,null,D.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",D.createElement(D.Fragment,null,D.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),D.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",D.createElement(D.Fragment,null,D.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",D.createElement(D.Fragment,null,D.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",D.createElement(D.Fragment,null,D.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",D.createElement(D.Fragment,null,D.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),ng=new Map([["bold",D.createElement(D.Fragment,null,D.createElement("path",{d:"M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"}))],["duotone",D.createElement(D.Fragment,null,D.createElement("path",{d:"M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z",opacity:"0.2"}),D.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["fill",D.createElement(D.Fragment,null,D.createElement("path",{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["light",D.createElement(D.Fragment,null,D.createElement("path",{d:"M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z"}))],["regular",D.createElement(D.Fragment,null,D.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["thin",D.createElement(D.Fragment,null,D.createElement("path",{d:"M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z"}))]]),rg=g.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),Vr=D.forwardRef((e,t)=>{const{alt:n,color:r,size:s,weight:o,mirrored:a,children:i,weights:l,...c}=e,{color:u="currentColor",size:f,weight:h="regular",mirrored:d=!1,...p}=D.useContext(rg);return D.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:s??f,height:s??f,fill:r??u,viewBox:"0 0 256 256",transform:a||d?"scale(-1, 1)":void 0,...p,...c},!!n&&D.createElement("title",null,n),i,l.get(o??h))});Vr.displayName="IconBase";const vd=D.forwardRef((e,t)=>D.createElement(Vr,{ref:t,...e,weights:Qm}));vd.displayName="DotsThreeIcon";const yd=D.forwardRef((e,t)=>D.createElement(Vr,{ref:t,...e,weights:eg}));yd.displayName="SpeakerHighIcon";const bd=D.forwardRef((e,t)=>D.createElement(Vr,{ref:t,...e,weights:tg}));bd.displayName="SpeakerLowIcon";const wd=D.forwardRef((e,t)=>D.createElement(Vr,{ref:t,...e,weights:ng}));wd.displayName="XIcon";const sg=wd;P.span`
66
+ `.replace(/\n+/g," ").replace(/\s+/g," ").trim();function sm(e,t="hidden"){return we(()=>{const{element:n,manager:r}=e;if(!n||!r)return;const s=om(n,r.registry.droppables),o=[],a=Yh(n),{remove:i}=a;return am(s,a,o),im(a,t),a.remove=()=>{o.forEach(l=>l()),i.call(a)},a})}function om(e,t){const n=new Map;for(const r of t)if(r.element&&(e===r.element||e.contains(r.element))){const s=`${Lr}${jo("dom-id")}`;r.element.setAttribute(s,""),n.set(r,s)}return n}function am(e,t,n){for(const[r,s]of e){if(!r.element)continue;const o=`[${s}]`,a=t.matches(o)?t:t.querySelector(o);if(r.element.removeAttribute(s),!a)continue;const i=r.element;r.proxy=a,a.removeAttribute(s),ml.set(i,a),n.push(()=>{ml.delete(i),r.proxy=void 0})}}function im(e,t="hidden"){e.setAttribute("inert","true"),e.setAttribute("tab-index","-1"),e.setAttribute("aria-hidden","true"),e.setAttribute(Ms,t)}function Hu(e,t){return e===t?!0:Vn(e)===Vn(t)}function _l(e){const{target:t}=e;"newState"in e&&e.newState==="closed"&&gn(t)&&t.hasAttribute("popover")&&requestAnimationFrame(()=>Sr(t))}function Uo(e){return e.tagName==="TR"}function lm(e,t,n){const r=new MutationObserver(s=>{let o=!1;for(const a of s){if(a.target!==e){o=!0;continue}if(a.type!=="attributes")continue;const i=a.attributeName;if(i.startsWith("aria-")||tm.includes(i))continue;const l=e.getAttribute(i);if(i==="style"){if(vr(e)&&vr(t)){const c=e.style;for(const u of Array.from(t.style))c.getPropertyValue(u)===""&&t.style.removeProperty(u);for(const u of Array.from(c)){if(nm.includes(u)||u.startsWith(Je))continue;const f=c.getPropertyValue(u);t.style.setProperty(u,f)}}}else l!==null?t.setAttribute(i,l):t.removeAttribute(i)}o&&n&&(t.innerHTML=e.innerHTML)});return r.observe(e,{attributes:!0,subtree:!0,childList:!0}),r}function cm(e,t,n){const r=new MutationObserver(s=>{for(const o of s)if(o.addedNodes.length!==0)for(const a of Array.from(o.addedNodes)){if(a.contains(e)&&e.nextElementSibling!==t){e.insertAdjacentElement("afterend",t),Sr(n);return}if(a.contains(t)&&t.previousElementSibling!==e){t.insertAdjacentElement("beforebegin",e),Sr(n);return}}});return r.observe(e.ownerDocument.body,{childList:!0,subtree:!0}),r}function um(e){return new ResizeObserver(()=>{var t,n;const r=new Nt(e.placeholder,{frameTransform:e.frameTransform,ignoreTransforms:!0}),s=(t=e.transformOrigin)!=null?t:{x:1,y:1},o=(e.width-r.width)*s.x+e.delta.x,a=(e.height-r.height)*s.y+e.delta.y,i=xu();if(e.styles.set({width:r.width-e.widthOffset,height:r.height-e.heightOffset,top:e.top+a+i.y,left:e.left+o+i.x},Je),(n=e.getElementMutationObserver())==null||n.takeRecords(),Uo(e.element)&&Uo(e.placeholder)){const l=Array.from(e.element.cells),c=Array.from(e.placeholder.cells);e.getSavedCellWidths()||e.setSavedCellWidths(l.map(u=>u.style.width));for(const[u,f]of l.entries()){const h=c[u];f.style.width=`${h.getBoundingClientRect().width}px`}}e.dragOperation.shape=new Nt(e.feedbackElement)})}var dm=250,fm="ease";function hm(e){var t,n,r,s;const{animation:o}=e;if(typeof o=="function"){const b=o({element:e.element,feedbackElement:e.feedbackElement,placeholder:e.placeholder,translate:e.translate,moved:e.moved});Promise.resolve(b).then(()=>{e.cleanup(),requestAnimationFrame(e.restoreFocus)});return}const{duration:a=dm,easing:i=fm}=o??{};Sr(e.feedbackElement);const[,l]=(t=Hh(e.feedbackElement,b=>"translate"in b))!=null?t:[];l?.pause();const c=(n=e.placeholder)!=null?n:e.element,u={frameTransform:Hu(e.feedbackElement,c)?null:void 0},f=new Nt(e.feedbackElement,u),h=(r=Ua(Zt(e.feedbackElement).translate))!=null?r:e.translate,d=new Nt(c,u),p=Dr.delta(f,d,e.alignment),v={x:h.x-p.x,y:h.y-p.y},y=Math.round(f.intrinsicHeight)!==Math.round(d.intrinsicHeight)?{minHeight:[`${f.intrinsicHeight}px`,`${d.intrinsicHeight}px`],maxHeight:[`${f.intrinsicHeight}px`,`${d.intrinsicHeight}px`]}:{},m=Math.round(f.intrinsicWidth)!==Math.round(d.intrinsicWidth)?{minWidth:[`${f.intrinsicWidth}px`,`${d.intrinsicWidth}px`],maxWidth:[`${f.intrinsicWidth}px`,`${d.intrinsicWidth}px`]}:{};e.styles.set({transition:e.transition},Je),e.feedbackElement.setAttribute(Go,""),(s=e.getElementMutationObserver())==null||s.takeRecords(),kp({element:e.feedbackElement,keyframes:qa(kr(kr({},y),m),{translate:[`${h.x}px ${h.y}px 0`,`${v.x}px ${v.y}px 0`]}),options:{duration:Cu(St(e.feedbackElement))?0:e.moved||e.feedbackElement!==e.element?a:0,easing:i}}).then(()=>{e.feedbackElement.removeAttribute(Go),l?.finish(),e.cleanup(),requestAnimationFrame(e.restoreFocus)})}var Gu,Xo,Er,ei,fs,Uu,Xu,Ir=class extends(Xo=it,Gu=[de],Xo){constructor(t,n){super(t,n),De(this,fs),De(this,ei,We(Er,8,this)),We(Er,11,this),this.state={initial:{},current:{}};const r=t.registry.plugins.get(xn),s=r?.register(rm);if(s){const o=this.destroy.bind(this);this.destroy=()=>{s(),o()}}this.registerEffect(vn(this,fs,Uu).bind(this,r)),this.registerEffect(vn(this,fs,Xu))}};Er=Kn(Xo);ei=new WeakMap;fs=new WeakSet;Uu=function(e){const{overlay:t}=this;if(!t||!e)return;const n=_s(t);if(n)return e.addRoot(n)};Xu=function(){var e,t,n;const{state:r,manager:s,options:o}=this,{dragOperation:a}=s,{position:i,source:l,status:c}=a;if(c.idle){r.current={},r.initial={};return}if(!l)return;const{element:u,feedback:f}=l;if(!u||f==="none"||!c.initialized||c.initializing)return;const{initial:h}=r,d=(e=this.overlay)!=null?e:u,p=Nn(d),v=Nn(u),y=!Hu(u,d),m=new Nt(u,{frameTransform:y?v:null,ignoreTransforms:!y}),b={x:v.scaleX/p.scaleX,y:v.scaleY/p.scaleY};let{width:_,height:w,top:x,left:S}=m;y&&(_=_/b.x,w=w/b.y);const k=new $p(d),{transition:E,translate:M,boxSizing:I,paddingBlockStart:T,paddingBlockEnd:$,paddingInlineStart:A,paddingInlineEnd:P,borderInlineStartWidth:W,borderInlineEndWidth:J,borderBlockStartWidth:G,borderBlockEndWidth:Q}=Zt(u),ee=f==="clone",z=I==="content-box",se=z?parseInt(A)+parseInt(P)+parseInt(W)+parseInt(J):0,U=z?parseInt(T)+parseInt($)+parseInt(G)+parseInt(Q):0,ie=f!=="move"&&!this.overlay?sm(l,ee?"clone":"hidden"):null,le=we(()=>Ya(s.dragOperation.activatorEvent));if(M!=="none"){const oe=Ua(M);oe&&!h.translate&&(h.translate=oe)}if(!h.transformOrigin){const oe=we(()=>i.current);h.transformOrigin={x:(oe.x-S*p.scaleX-p.x)/(_*p.scaleX),y:(oe.y-x*p.scaleY-p.y)/(w*p.scaleY)}}const{transformOrigin:ge}=h,Se=x*p.scaleY+p.y,N=S*p.scaleX+p.x;if(!h.coordinates&&(h.coordinates={x:N,y:Se},b.x!==1||b.y!==1)){const{scaleX:oe,scaleY:he}=v,{x:Xe,y:At}=ge;h.coordinates.x+=(_*oe-_)*Xe,h.coordinates.y+=(w*he-w)*At}h.dimensions||(h.dimensions={width:_,height:w}),h.frameTransform||(h.frameTransform=p);const H={x:h.coordinates.x-N,y:h.coordinates.y-Se},ye={width:(h.dimensions.width*h.frameTransform.scaleX-_*p.scaleX)*ge.x,height:(h.dimensions.height*h.frameTransform.scaleY-w*p.scaleY)*ge.y},j={x:H.x/p.scaleX+ye.width,y:H.y/p.scaleY+ye.height},q={left:S+j.x,top:x+j.y};d.setAttribute(Dt,"true");const O=we(()=>a.transform),_e=(t=h.translate)!=null?t:{x:0,y:0},Ne=O.x*p.scaleX+_e.x,Be=O.y*p.scaleY+_e.y,ve=xu();k.set({width:_-se,height:w-U,top:q.top+ve.y,left:q.left+ve.x,translate:`${Ne}px ${Be}px 0`,transition:E?`${E}, translate 0ms linear`:"",scale:y?`${b.x} ${b.y}`:"","transform-origin":`${ge.x*100}% ${ge.y*100}%`},Je),ie&&(u.insertAdjacentElement("afterend",ie),o?.rootElement&&(typeof o.rootElement=="function"?o.rootElement(l):o.rootElement).appendChild(u)),No(d)&&(d.hasAttribute("popover")||d.setAttribute("popover","manual"),Sr(d),d.addEventListener("beforetoggle",_l));let Ve,ne,Ge;const je=um({placeholder:ie,element:u,feedbackElement:d,frameTransform:p,transformOrigin:ge,width:_,height:w,top:x,left:S,widthOffset:se,heightOffset:U,delta:j,styles:k,dragOperation:a,getElementMutationObserver:()=>Ve,getSavedCellWidths:()=>Ge,setSavedCellWidths:oe=>{Ge=oe}}),xe=new Nt(d);we(()=>a.shape=xe);const Fe=St(d),Oe=oe=>{this.manager.actions.stop({event:oe})},Et=Cu(Fe);le&&Fe.addEventListener("resize",Oe),we(()=>l.status)==="idle"&&requestAnimationFrame(()=>l.status="dragging"),ie&&(je.observe(ie),Ve=lm(u,ie,ee),ne=cm(u,ie,d));const It=(n=s.dragOperation.source)==null?void 0:n.id,Mt=()=>{var oe;if(!le||It==null)return;const he=s.registry.draggables.get(It),Xe=(oe=he?.handle)!=null?oe:he?.element;mn(Xe)&&Xe.focus()},X=()=>{var oe;if(Ve?.disconnect(),ne?.disconnect(),je.disconnect(),Fe.removeEventListener("resize",Oe),No(d)&&(d.removeEventListener("beforetoggle",_l),d.removeAttribute("popover")),d.removeAttribute(Dt),k.reset(),Ge&&Uo(u)){const Xe=Array.from(u.cells);for(const[At,Tt]of Xe.entries())Tt.style.width=(oe=Ge[At])!=null?oe:""}l.status="idle";const he=r.current.translate!=null;ie&&(he||ie.parentElement!==d.parentElement)&&d.isConnected&&ie.replaceWith(d),ie?.remove()},fe=o?.dropAnimation,Ue=this,Me=Rr(()=>{var oe;const{transform:he,status:Xe}=a;if(!(!he.x&&!he.y&&!r.current.translate)&&Xe.dragging){const At=(oe=h.translate)!=null?oe:{x:0,y:0},Tt={x:he.x/p.scaleX+At.x,y:he.y/p.scaleY+At.y},ut=r.current.translate,yt=we(()=>a.modifiers),V=we(()=>{var K;return(K=a.shape)==null?void 0:K.current}),Y=le&&!Et?"250ms cubic-bezier(0.25, 1, 0.5, 1)":"0ms linear";if(k.set({transition:`${E}, translate ${Y}`,translate:`${Tt.x}px ${Tt.y}px 0`},Je),Ve?.takeRecords(),V&&V!==xe&&ut&&!yt.length){const K=Pt.delta(Tt,ut);a.shape=Dr.from(V.boundingRectangle).translate(K.x*p.scaleX,K.y*p.scaleY)}else a.shape=new Nt(d);r.current.translate=Tt}},function(){if(a.status.dropped){this.dispose(),l.status="dropping";const oe=Ue.dropAnimation!==void 0?Ue.dropAnimation:fe;let he=r.current.translate;const Xe=he!=null;if(!he&&u!==d&&(he={x:0,y:0}),!he||oe===null){X();return}s.renderer.rendering.then(()=>{hm({element:u,feedbackElement:d,placeholder:ie,translate:he,moved:Xe,transition:E,alignment:l.alignment,styles:k,animation:oe??void 0,getElementMutationObserver:()=>Ve,cleanup:X,restoreFocus:Mt})})}});return()=>{X(),Me()}};gt(Er,4,"overlay",Gu,Ir,ei);_n(Er,Ir);Ir.configure=Xn(Ir);var Yo=Ir,Jn=!0,pm=!1,Yu,Ku,qu,Ju,Kt,ti,ni;Ju=(qu=[de],_t.Forward),Ku=(Yu=[de],_t.Reverse);var Mr=class{constructor(){De(this,ti,We(Kt,8,this,Jn)),We(Kt,11,this),De(this,ni,We(Kt,12,this,Jn)),We(Kt,15,this)}isLocked(e){return e===_t.Idle?!1:e==null?this[_t.Forward]===Jn&&this[_t.Reverse]===Jn:this[e]===Jn}unlock(e){e!==_t.Idle&&(this[e]=pm)}};Kt=Kn(null);ti=new WeakMap;ni=new WeakMap;gt(Kt,4,Ju,qu,Mr,ti);gt(Kt,4,Ku,Yu,Mr,ni);_n(Kt,Mr);var mm=[_t.Forward,_t.Reverse],xl=class{constructor(){this.x=new Mr,this.y=new Mr}isLocked(){return this.x.isLocked()&&this.y.isLocked()}},gm=class extends it{constructor(e){super(e);const t=$r(new xl);let n=null;this.signal=t,Ct(()=>{const{status:r}=e.dragOperation;if(!r.initialized){n=null,t.value=new xl;return}const{delta:s}=e.dragOperation.position;if(n){const o={x:Cl(s.x,n.x),y:Cl(s.y,n.y)},a=t.peek();Qt(()=>{for(const i of Ac)for(const l of mm)o[i]===l&&a[i].unlock(l);t.value=a})}n=s})}get current(){return this.signal.peek()}};function Cl(e,t){return Math.sign(e-t)}var Qu,Ko,Ar,ri,Xt,qo,Vs=class extends(Ko=Fr,Qu=[de],Ko){constructor(e){super(e),De(this,ri,We(Ar,8,this,!1)),We(Ar,11,this),De(this,Xt),De(this,qo,()=>{if(!Ce(this,Xt))return;const{element:o,by:a}=Ce(this,Xt);a.y&&(o.scrollTop+=a.y),a.x&&(o.scrollLeft+=a.x)}),this.scroll=o=>{var a;if(this.disabled)return!1;const i=this.getScrollableElements();if(!i)return rt(this,Xt,void 0),!1;const{position:l}=this.manager.dragOperation,c=l?.current;if(c){const{by:u}=o??{},f=u?{x:Sl(u.x),y:Sl(u.y)}:void 0,h=f?void 0:this.scrollIntentTracker.current;if(h?.isLocked())return!1;for(const d of i){const p=lp(d,u);if(p.x||p.y){const{speed:v,direction:y}=wp(d,c,f);if(h)for(const m of Ac)h[m].isLocked(y[m])&&(v[m]=0,y[m]=0);if(y.x||y.y){const{x:m,y:b}=u??y,_=m*v.x,w=b*v.y;if(_||w){const x=(a=Ce(this,Xt))==null?void 0:a.by;if(this.autoScrolling&&x&&(x.x&&!_||x.y&&!w))continue;return rt(this,Xt,{element:d,by:{x:_,y:w}}),Ss.schedule(Ce(this,qo)),!0}}}}}return rt(this,Xt,void 0),!1};let t=null,n=null;const r=ys(()=>{const{position:o,source:a}=e.dragOperation;if(!o)return null;const i=Su(_s(a?.element),o.current);return i&&(t=i),i??t}),s=ys(()=>{const o=r.value,{documentElement:a}=wn(o);if(!o||o===a){const{target:i}=e.dragOperation,l=i?.element;if(l){const c=zo(l,{excludeElement:!1});return n=c,c}}if(o){const i=zo(o,{excludeElement:!1});return this.autoScrolling&&n&&i.size<n?.size?n:(n=i,i)}return n=null,null},_r);this.getScrollableElements=()=>s.value,this.scrollIntentTracker=new gm(e),this.destroy=e.monitor.addEventListener("dragmove",o=>{this.disabled||o.defaultPrevented||!Ya(e.dragOperation.activatorEvent)||!o.by||this.scroll({by:o.by})&&o.preventDefault()})}};Ar=Kn(Ko);ri=new WeakMap;Xt=new WeakMap;qo=new WeakMap;gt(Ar,4,"autoScrolling",Qu,Vs,ri);_n(Ar,Vs);function Sl(e){return e>0?_t.Forward:e<0?_t.Reverse:_t.Idle}var vm=class{constructor(e){this.scheduler=e,this.pending=!1,this.tasks=new Set,this.resolvers=new Set,this.flush=()=>{const{tasks:t,resolvers:n}=this;this.pending=!1,this.tasks=new Set,this.resolvers=new Set;for(const r of t)r();for(const r of n)r()}}schedule(e){return this.tasks.add(e),this.pending||(this.pending=!0,this.scheduler(this.flush)),new Promise(t=>this.resolvers.add(t))}},ym=new vm(e=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(e):e()}),bm=10,ed=class extends it{constructor(e,t){super(e);const n=e.registry.plugins.get(Vs);if(!n)throw new Error("AutoScroller plugin depends on Scroller plugin");this.destroy=Ct(()=>{if(this.disabled)return;const{position:r,status:s}=e.dragOperation;if(s.dragging)if(n.scroll()){n.autoScrolling=!0;const a=setInterval(()=>ym.schedule(n.scroll),bm);return()=>{clearInterval(a)}}else n.autoScrolling=!1})}},kl={capture:!0,passive:!0},fr,wm=class extends Fr{constructor(e){super(e),De(this,fr),this.handleScroll=()=>{Ce(this,fr)==null&&rt(this,fr,setTimeout(()=>{this.manager.collisionObserver.forceUpdate(!1),rt(this,fr,void 0)},50))};const{dragOperation:t}=this.manager;this.destroy=Ct(()=>{var n,r,s;if(t.status.dragging){const a=(s=(r=(n=t.source)==null?void 0:n.element)==null?void 0:r.ownerDocument)!=null?s:document;return a.addEventListener("scroll",this.handleScroll,kl),()=>{a.removeEventListener("scroll",this.handleScroll,kl)}}})}};fr=new WeakMap;var _m=class extends it{constructor(e,t){super(e,t),this.manager=e,this.destroy=Ct(()=>{var n;const{dragOperation:r}=this.manager,{nonce:s}=(n=this.options)!=null?n:{};if(r.status.initialized){const o=document.createElement("style");return s&&o.setAttribute("nonce",s),o.textContent="* { user-select: none !important; -webkit-user-select: none !important; }",document.head.appendChild(o),mo(),document.addEventListener("selectionchange",mo,{capture:!0}),()=>{document.removeEventListener("selectionchange",mo,{capture:!0}),o.remove()}}})}};function mo(){var e;(e=document.getSelection())==null||e.removeAllRanges()}var hr=Object.freeze({offset:10,keyboardCodes:{start:["Space","Enter"],cancel:["Escape"],end:["Space","Enter","Tab"],up:["ArrowUp"],down:["ArrowDown"],left:["ArrowLeft"],right:["ArrowRight"]},preventActivation(e,t){var n;const r=(n=t.handle)!=null?n:t.element;return e.target!==r}}),Dn,As=class extends Wn{constructor(t,n){super(t),this.manager=t,this.options=n,De(this,Dn,[]),this.listeners=new ku,this.handleSourceKeyDown=(r,s,o)=>{if(this.disabled||r.defaultPrevented||!gn(r.target)||s.disabled)return;const{keyboardCodes:a=hr.keyboardCodes,preventActivation:i=hr.preventActivation}=o??{};a.start.includes(r.code)&&this.manager.dragOperation.status.idle&&(i?.(r,s)||this.handleStart(r,s,o))}}bind(t,n=this.options){return Ct(()=>{var s;const o=(s=t.handle)!=null?s:t.element,a=i=>{Ya(i)&&this.handleSourceKeyDown(i,t,n)};if(o)return o.addEventListener("keydown",a),()=>{o.removeEventListener("keydown",a)}})}handleStart(t,n,r){const{element:s}=n;if(!s)throw new Error("Source draggable does not have an associated element");t.preventDefault(),t.stopImmediatePropagation(),xp(s);const{center:o}=new Nt(s);if(this.manager.actions.start({event:t,coordinates:{x:o.x,y:o.y},source:n}).signal.aborted)return this.cleanup();this.sideEffects();const i=wn(s),l=[this.listeners.bind(i,[{type:"keydown",listener:c=>this.handleKeyDown(c,n,r),options:{capture:!0}}])];Ce(this,Dn).push(...l)}handleKeyDown(t,n,r){const{keyboardCodes:s=hr.keyboardCodes}=r??{};if(In(t,[...s.end,...s.cancel])){t.preventDefault();const o=In(t,s.cancel);this.handleEnd(t,o);return}In(t,s.up)?this.handleMove("up",t):In(t,s.down)&&this.handleMove("down",t),In(t,s.left)?this.handleMove("left",t):In(t,s.right)&&this.handleMove("right",t)}handleEnd(t,n){this.manager.actions.stop({event:t,canceled:n}),this.cleanup()}handleMove(t,n){var r,s;const{shape:o}=this.manager.dragOperation,a=n.shiftKey?5:1;let i={x:0,y:0},l=(s=(r=this.options)==null?void 0:r.offset)!=null?s:hr.offset;if(typeof l=="number"&&(l={x:l,y:l}),!!o){switch(t){case"up":i={x:0,y:-l.y*a};break;case"down":i={x:0,y:l.y*a};break;case"left":i={x:-l.x*a,y:0};break;case"right":i={x:l.x*a,y:0};break}(i.x||i.y)&&(n.preventDefault(),this.manager.actions.move({event:n,by:i}))}}sideEffects(){const t=this.manager.registry.plugins.get(ed);t?.disabled===!1&&(t.disable(),Ce(this,Dn).push(()=>{t.enable()}))}cleanup(){Ce(this,Dn).forEach(t=>t()),rt(this,Dn,[])}destroy(){this.cleanup(),this.listeners.clear()}};Dn=new WeakMap;As.configure=Xn(As);As.defaults=hr;var xm=As;function In(e,t){return t.includes(e.code)}var fn,Cm=class extends lu{constructor(){super(...arguments),De(this,fn)}onEvent(e){switch(e.type){case"pointerdown":rt(this,fn,Bn(e));break;case"pointermove":if(!Ce(this,fn))return;const{x:t,y:n}=Bn(e),r={x:t-Ce(this,fn).x,y:n-Ce(this,fn).y},{tolerance:s}=this.options;if(s&&Fo(r,s)){this.abort();return}Fo(r,this.options.value)&&this.activate(e);break;case"pointerup":this.abort();break}}abort(){rt(this,fn,void 0)}};fn=new WeakMap;var Pn,hn,Sm=class extends lu{constructor(){super(...arguments),De(this,Pn),De(this,hn)}onEvent(e){switch(e.type){case"pointerdown":rt(this,hn,Bn(e)),rt(this,Pn,setTimeout(()=>this.activate(e),this.options.value));break;case"pointermove":if(!Ce(this,hn))return;const{x:t,y:n}=Bn(e),r={x:t-Ce(this,hn).x,y:n-Ce(this,hn).y};Fo(r,this.options.tolerance)&&this.abort();break;case"pointerup":this.abort();break}}abort(){Ce(this,Pn)&&(clearTimeout(Ce(this,Pn)),rt(this,hn,void 0),rt(this,Pn,void 0))}};Pn=new WeakMap;hn=new WeakMap;var Bt=class{};Bt.Delay=Sm;Bt.Distance=Cm;var Jo=Object.freeze({activationConstraints(e,t){var n;const{pointerType:r,target:s}=e;if(!(r==="mouse"&&gn(s)&&(t.handle===s||(n=t.handle)!=null&&n.contains(s))))return r==="touch"?[new Bt.Delay({value:250,tolerance:5})]:Dp(s)&&!e.defaultPrevented?[new Bt.Delay({value:200,tolerance:0})]:[new Bt.Delay({value:200,tolerance:10}),new Bt.Distance({value:5})]},preventActivation(e,t){var n;const{target:r}=e;return r===t.element||r===t.handle||!gn(r)||(n=t.handle)!=null&&n.contains(r)?!1:qh(r)}}),Fn,Ts=class extends Wn{constructor(t,n){super(t),this.manager=t,this.options=n,De(this,Fn,new Set),this.listeners=new ku,this.latest={event:void 0,coordinates:void 0},this.handleMove=()=>{const{event:r,coordinates:s}=this.latest;!r||!s||this.manager.actions.move({event:r,to:s})},this.handleCancel=this.handleCancel.bind(this),this.handlePointerUp=this.handlePointerUp.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activationConstraints(t,n,r=this.options){const{activationConstraints:s=Jo.activationConstraints}=r??{};return typeof s=="function"?s(t,n):s}bind(t,n=this.options){return Ct(()=>{var s;const o=new AbortController,{signal:a}=o,i=c=>{Rp(c)&&this.handlePointerDown(c,t,n)};let l=[(s=t.handle)!=null?s:t.element];n?.activatorElements&&(Array.isArray(n.activatorElements)?l=n.activatorElements:l=n.activatorElements(t));for(const c of l)c&&(Im(c.ownerDocument.defaultView),c.addEventListener("pointerdown",i,{signal:a}));return()=>o.abort()})}handlePointerDown(t,n,r){if(this.disabled||!t.isPrimary||t.button!==0||!gn(t.target)||n.disabled||km(t)||!this.manager.dragOperation.status.idle)return;const{preventActivation:s=Jo.preventActivation}=r??{};if(s?.(t,n))return;const{target:o}=t,a=mn(o)&&o.draggable&&o.getAttribute("draggable")==="true",i=Nn(n.element),{x:l,y:c}=Bn(t);this.initialCoordinates={x:l*i.scaleX+i.x,y:c*i.scaleY+i.y};const u=this.activationConstraints(t,n,r);t.sensor=this;const f=new Nh(u,v=>this.handleStart(n,v));f.signal.onabort=()=>this.handleCancel(t),f.onEvent(t),this.controller=f;const h=Bo(),d=this.listeners.bind(h,[{type:"pointermove",listener:v=>this.handlePointerMove(v,n)},{type:"pointerup",listener:this.handlePointerUp,options:{capture:!0}},{type:"pointercancel",listener:this.handleCancel},{type:"dragstart",listener:a?this.handleCancel:ts,options:{capture:!0}}]),p=()=>{d(),this.initialCoordinates=void 0};Ce(this,Fn).add(p)}handlePointerMove(t,n){var r,s;if(((r=this.controller)==null?void 0:r.activated)===!1){(s=this.controller)==null||s.onEvent(t);return}if(this.manager.dragOperation.status.dragging){const o=Bn(t),a=Nn(n.element);o.x=o.x*a.scaleX+a.x,o.y=o.y*a.scaleY+a.y,t.preventDefault(),t.stopPropagation(),this.latest.event=t,this.latest.coordinates=o,Ss.schedule(this.handleMove)}}handlePointerUp(t){const{status:n}=this.manager.dragOperation;if(!n.idle){t.preventDefault(),t.stopPropagation();const r=!n.initialized;this.manager.actions.stop({event:t,canceled:r})}this.cleanup()}handleKeyDown(t){t.key==="Escape"&&(t.preventDefault(),this.handleCancel(t))}handleStart(t,n){const{manager:r,initialCoordinates:s}=this;if(!s||!r.dragOperation.status.idle||n.defaultPrevented)return;if(r.actions.start({coordinates:s,event:n,source:t}).signal.aborted)return this.cleanup();n.preventDefault();const i=wn(n.target).body;i.setPointerCapture(n.pointerId);const l=gn(n.target)?[n.target,i]:i,c=this.listeners.bind(l,[{type:"touchmove",listener:ts,options:{passive:!1}},{type:"click",listener:ts},{type:"contextmenu",listener:ts},{type:"keydown",listener:this.handleKeyDown}]);Ce(this,Fn).add(c)}handleCancel(t){const{dragOperation:n}=this.manager;n.status.initialized&&this.manager.actions.stop({event:t,canceled:!0}),this.cleanup()}cleanup(){this.latest={event:void 0,coordinates:void 0},Ce(this,Fn).forEach(t=>t()),Ce(this,Fn).clear()}destroy(){this.cleanup(),this.listeners.clear()}};Fn=new WeakMap;Ts.configure=Xn(Ts);Ts.defaults=Jo;var Qo=Ts;function km(e){return"sensor"in e}function ts(e){e.preventDefault()}function Em(){}var El=new WeakSet;function Im(e){!e||El.has(e)||(e.addEventListener("touchmove",Em,{capture:!1,passive:!1}),El.add(e))}var On={modifiers:[],plugins:[Jp,ed,em,Yo,_m],sensors:[Qo,xm]},si=class extends Zh{constructor(e={}){const t=Vt(e.plugins,On.plugins),n=Vt(e.sensors,On.sensors),r=Vt(e.modifiers,On.modifiers);super(qa(kr({},e),{plugins:[wm,Vs,xn,...t],sensors:n,modifiers:r}))}},td,nd,rd,ea,$t,oi,ai,ii,Wr=class extends(ea=Ft,rd=[de],nd=[de],td=[de],ea){constructor(e,t){var n=e,{element:r,effects:s=()=>[],handle:o,feedback:a="default"}=n,i=Fu(n,["element","effects","handle","feedback"]);super(kr({effects:()=>[...s(),()=>{var l,c;const{manager:u}=this;if(!u)return;const h=((c=(l=this.sensors)==null?void 0:l.map(ba))!=null?c:[...u.sensors]).map(d=>{const p=d instanceof Wn?d:u.registry.register(d.plugin),v=d instanceof Wn?void 0:d.options;return p.bind(this,v)});return function(){h.forEach(p=>p())}}]},i),t),De(this,oi,We($t,8,this)),We($t,11,this),De(this,ai,We($t,12,this)),We($t,15,this),De(this,ii,We($t,16,this)),We($t,19,this),this.element=r,this.handle=o,this.feedback=a}};$t=Kn(ea);oi=new WeakMap;ai=new WeakMap;ii=new WeakMap;gt($t,4,"handle",rd,Wr,oi);gt($t,4,"element",nd,Wr,ai);gt($t,4,"feedback",td,Wr,ii);_n($t,Wr);var sd,od,ta,qt,li,go,ad,id,br,ci,ld=class extends(ta=Ot,od=[de],sd=[de],ta){constructor(e,t){var n=e,{element:r,effects:s=()=>[]}=n,o=Fu(n,["element","effects"]);const{collisionDetector:a=Lp}=o,i=c=>{const{manager:u,element:f}=this;if(!f||c===null){this.shape=void 0;return}if(!u)return;const h=new Nt(f),d=we(()=>this.shape);return h&&d?.equals(h)?d:(this.shape=h,h)},l=$r(!1);super(qa(kr({},o),{collisionDetector:a,effects:()=>[...s(),()=>{const{element:c,manager:u}=this;if(!u)return;const{dragOperation:f}=u,{source:h}=f;l.value=!!(h&&f.status.initialized&&c&&!this.disabled&&this.accepts(h))},()=>{const{element:c}=this;if(l.value&&c){const u=new ip(c,i);return()=>{u.disconnect(),this.shape=void 0}}},()=>{var c;if((c=this.manager)!=null&&c.dragOperation.status.initialized)return()=>{this.shape=void 0}}]}),t),De(this,br),De(this,li,We(qt,8,this)),We(qt,11,this),De(this,ci,We(qt,12,this)),We(qt,15,this),this.element=r,this.refreshShape=()=>i()}set element(e){rt(this,br,e,id)}get element(){var e;return(e=this.proxy)!=null?e:Ce(this,br,ad)}};qt=Kn(ta);li=new WeakMap;br=new WeakSet;ci=new WeakMap;go=gt(qt,20,"#element",od,br,li),ad=go.get,id=go.set;gt(qt,4,"proxy",sd,ld,ci);_n(qt,ld);function Mm(e){return e!=null&&typeof e=="object"&&"current"in e}function $s(e){var t;if(e!=null)return Mm(e)?(t=e.current)!=null?t:void 0:e}var Am=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ns=Am?g.useLayoutEffect:g.useEffect;function Tm(){const e=g.useState(0)[1];return g.useCallback(()=>{e(t=>t+1)},[e])}function $m(e,t){const n=g.useRef(new Map),r=Tm();return Ns(()=>{if(!e){n.current.clear();return}return Ct(()=>{var s;let o=!1,a=!1;for(const i of n.current){const[l]=i,c=we(()=>i[1]),u=e[l];c!==u&&(o=!0,n.current.set(l,u),a=(s=t?.(l,c,u))!=null?s:!1)}o&&(a?ua.flushSync(r):r())})},[e]),g.useMemo(()=>e&&new Proxy(e,{get(s,o){const a=s[o];return n.current.set(o,a),a}}),[e])}function ln(e,t,n=g.useEffect,r=Object.is){const s=g.useRef(e);n(()=>{const o=s.current;r(e,o)||(s.current=e,t(e,o))},[t,e])}function Il(e,t){const n=g.useRef($s(e));Ns(()=>{const r=$s(e);r!==n.current&&(n.current=r,t(r))})}var Rm=Object.defineProperty,Dm=Object.defineProperties,Pm=Object.getOwnPropertyDescriptors,Ml=Object.getOwnPropertySymbols,Fm=Object.prototype.hasOwnProperty,Om=Object.prototype.propertyIsEnumerable,Al=(e,t,n)=>t in e?Rm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lm=(e,t)=>{for(var n in t||(t={}))Fm.call(t,n)&&Al(e,n,t[n]);if(Ml)for(var n of Ml(t))Om.call(t,n)&&Al(e,n,t[n]);return e},Wm=(e,t)=>Dm(e,Pm(t)),Bm=new si,Vm=g.createContext(Bm);g.memo(g.forwardRef(({children:e},t)=>{const[n,r]=g.useState(0),s=g.useRef(null),o=g.useRef(null),a=g.useMemo(()=>({renderer:{get rendering(){var i;return(i=s.current)!=null?i:Promise.resolve()}},trackRendering(i){s.current||(s.current=new Promise(l=>{o.current=l})),g.startTransition(()=>{i(),r(l=>l+1)})}}),[]);return Ns(()=>{var i;(i=o.current)==null||i.call(o),s.current=null},[e,n]),g.useImperativeHandle(t,()=>a),null}));function Nm(){return g.useContext(Vm)}function zm(e){var t;const n=(t=Nm())!=null?t:void 0,[r]=g.useState(()=>e(n));return r.manager!==n&&(r.manager=n),Ns(r.register,[n,r]),r}function vo(e){const{disabled:t,data:n,element:r,handle:s,id:o,modifiers:a,sensors:i}=e,l=zm(u=>new Wr(Wm(Lm({},e),{register:!1,handle:$s(s),element:$s(r)}),u)),c=$m(l,jm);return ln(o,()=>l.id=o),Il(s,u=>l.handle=u),Il(r,u=>l.element=u),ln(n,()=>n&&(l.data=n)),ln(t,()=>l.disabled=t===!0),ln(i,()=>l.sensors=i),ln(a,()=>l.modifiers=a,void 0,_r),ln(e.feedback,()=>{var u;return l.feedback=(u=e.feedback)!=null?u:"default"}),ln(e.alignment,()=>l.alignment=e.alignment),{draggable:c,get isDragging(){return c.isDragging},get isDropping(){return c.isDropping},get isDragSource(){return c.isDragSource},handleRef:g.useCallback(u=>{l.handle=u??void 0},[l]),ref:g.useCallback(u=>{var f,h;!u&&((f=l.element)!=null&&f.isConnected)&&!((h=l.manager)!=null&&h.dragOperation.status.idle)||(l.element=u??void 0)},[l])}}function jm(e,t,n){return!!(e==="isDragSource"&&!n&&t)}var Zm=Object.create,cd=Object.defineProperty,Hm=Object.getOwnPropertyDescriptor,ud=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),zs=e=>{throw TypeError(e)},Gm=(e,t,n)=>t in e?cd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Um=e=>{var t;return[,,,Zm((t=e?.[ud("metadata")])!=null?t:null)]},dd=["class","method","getter","setter","accessor","field","value","get","set"],fd=e=>e!==void 0&&typeof e!="function"?zs("Function expected"):e,Xm=(e,t,n,r,s)=>({kind:dd[e],name:t,metadata:r,addInitializer:o=>n._?zs("Already initialized"):s.push(fd(o||null))}),Ym=(e,t)=>Gm(t,ud("metadata"),e[3]),Km=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)o[s].call(n);return r},hd=(e,t,n,r,s,o)=>{for(var a,i,l,c,u=t&7,f=!1,h=!1,d=2,p=dd[u+5],v=e[d]||(e[d]=[]),y=(s=s.prototype,Hm(s,n)),m=r.length-1;m>=0;m--)l=Xm(u,n,i={},e[3],v),l.static=f,l.private=h,c=l.access={has:b=>n in b},c.get=b=>b[n],a=(0,r[m])(y[p],l),i._=1,fd(a)&&(y[p]=a);return y&&cd(s,n,y),s},pd=(e,t,n)=>t.has(e)||zs("Cannot "+n),qm=(e,t,n)=>(pd(e,t,"read from private field"),t.get(e)),Jm=(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),Qm=(e,t,n,r)=>(pd(e,t,"write to private field"),t.set(e,n),n),Qn=class na{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new na(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 na(t,n)}},md,gd,ra,hs,Br,ui=class extends(ra=tn,gd=[Ie],md=[Ie],ra){constructor(t){const n=Qn.from(t);super(n,(r,s)=>Qn.equals(r,s)),Km(Br,5,this),Jm(this,hs,0),this.velocity={x:0,y:0}}get delta(){return Qn.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=Qn.from(t),s={x:r.x-n.x,y:r.y-n.y},o=Date.now(),a=o-qm(this,hs),i=l=>Math.round(l/a*100);Qt(()=>{Qm(this,hs,o),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Qn.from(t)),this.velocity={x:0,y:0}}};Br=Um(ra);hs=new WeakMap;hd(Br,2,"delta",gd,ui);hd(Br,2,"direction",md,ui);Ym(Br,ui);var vd=(e=>(e.Horizontal="x",e.Vertical="y",e))(vd||{});Object.values(vd);const eg=new Map([["bold",R.createElement(R.Fragment,null,R.createElement("path",{d:"M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128ZM60,112a16,16,0,1,0,16,16A16,16,0,0,0,60,112Zm136,0a16,16,0,1,0,16,16A16,16,0,0,0,196,112Z"}))],["duotone",R.createElement(R.Fragment,null,R.createElement("path",{d:"M240,96v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V96A16,16,0,0,1,32,80H224A16,16,0,0,1,240,96Z",opacity:"0.2"}),R.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["fill",R.createElement(R.Fragment,null,R.createElement("path",{d:"M224,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V96A16,16,0,0,0,224,80ZM60,140a12,12,0,1,1,12-12A12,12,0,0,1,60,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,128,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,196,140Z"}))],["light",R.createElement(R.Fragment,null,R.createElement("path",{d:"M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128ZM60,118a10,10,0,1,0,10,10A10,10,0,0,0,60,118Zm136,0a10,10,0,1,0,10,10A10,10,0,0,0,196,118Z"}))],["regular",R.createElement(R.Fragment,null,R.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["thin",R.createElement(R.Fragment,null,R.createElement("path",{d:"M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Zm-76-8a8,8,0,1,0,8,8A8,8,0,0,0,60,120Zm136,0a8,8,0,1,0,8,8A8,8,0,0,0,196,120Z"}))]]),tg=new Map([["bold",R.createElement(R.Fragment,null,R.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",R.createElement(R.Fragment,null,R.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),R.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",R.createElement(R.Fragment,null,R.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",R.createElement(R.Fragment,null,R.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",R.createElement(R.Fragment,null,R.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",R.createElement(R.Fragment,null,R.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),ng=new Map([["bold",R.createElement(R.Fragment,null,R.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",R.createElement(R.Fragment,null,R.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),R.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",R.createElement(R.Fragment,null,R.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",R.createElement(R.Fragment,null,R.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",R.createElement(R.Fragment,null,R.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",R.createElement(R.Fragment,null,R.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),rg=new Map([["bold",R.createElement(R.Fragment,null,R.createElement("path",{d:"M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"}))],["duotone",R.createElement(R.Fragment,null,R.createElement("path",{d:"M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z",opacity:"0.2"}),R.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["fill",R.createElement(R.Fragment,null,R.createElement("path",{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["light",R.createElement(R.Fragment,null,R.createElement("path",{d:"M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z"}))],["regular",R.createElement(R.Fragment,null,R.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["thin",R.createElement(R.Fragment,null,R.createElement("path",{d:"M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z"}))]]),sg=g.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),Vr=R.forwardRef((e,t)=>{const{alt:n,color:r,size:s,weight:o,mirrored:a,children:i,weights:l,...c}=e,{color:u="currentColor",size:f,weight:h="regular",mirrored:d=!1,...p}=R.useContext(sg);return R.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:s??f,height:s??f,fill:r??u,viewBox:"0 0 256 256",transform:a||d?"scale(-1, 1)":void 0,...p,...c},!!n&&R.createElement("title",null,n),i,l.get(o??h))});Vr.displayName="IconBase";const yd=R.forwardRef((e,t)=>R.createElement(Vr,{ref:t,...e,weights:eg}));yd.displayName="DotsThreeIcon";const bd=R.forwardRef((e,t)=>R.createElement(Vr,{ref:t,...e,weights:tg}));bd.displayName="SpeakerHighIcon";const wd=R.forwardRef((e,t)=>R.createElement(Vr,{ref:t,...e,weights:ng}));wd.displayName="SpeakerLowIcon";const _d=R.forwardRef((e,t)=>R.createElement(Vr,{ref:t,...e,weights:rg}));_d.displayName="XIcon";const og=_d;D.span`
67
67
  font-family: 'Courier New', Monaco, monospace;
68
68
  font-size: 1rem;
69
69
  font-weight: 600;
70
70
  color: ${e=>e.theme?.textColor||"#333"};
71
71
  user-select: none;
72
- `;var fi=P.button`
72
+ `;var di=D.button`
73
73
  display: inline-flex;
74
74
  align-items: center;
75
75
  justify-content: center;
@@ -100,37 +100,37 @@
100
100
  opacity: 0.6;
101
101
  cursor: not-allowed;
102
102
  }
103
- `;P(fi)`
103
+ `;D(di)`
104
104
  padding: 0.25rem 0.5rem;
105
105
  font-size: ${e=>e.theme.fontSizeSmall};
106
- `;P(fi)`
106
+ `;D(di)`
107
107
  padding: 0.5rem;
108
108
  min-width: 2.25rem;
109
109
  min-height: 2.25rem;
110
- `;P(fi)`
110
+ `;D(di)`
111
111
  padding: 0.25rem;
112
112
  min-width: 1.75rem;
113
113
  min-height: 1.75rem;
114
114
  font-size: ${e=>e.theme.fontSizeSmall};
115
- `;var og=P.div`
115
+ `;var ag=D.div`
116
116
  display: inline-flex;
117
117
  align-items: center;
118
118
  gap: 0.5rem;
119
- `,ag=P.input`
119
+ `,ig=D.input`
120
120
  cursor: pointer;
121
121
  accent-color: ${e=>e.theme.inputFocusBorder};
122
122
 
123
123
  &:disabled {
124
124
  cursor: not-allowed;
125
125
  }
126
- `,ig=P.label`
126
+ `,lg=D.label`
127
127
  margin: 0;
128
128
  cursor: pointer;
129
129
  user-select: none;
130
130
  font-family: ${e=>e.theme.fontFamily};
131
131
  font-size: ${e=>e.theme.fontSize};
132
132
  color: ${e=>e.theme.textColor};
133
- `,kt=P.button`
133
+ `,kt=D.button`
134
134
  padding: 0.5rem 1rem;
135
135
  background: ${e=>e.theme.buttonBackground||"#007bff"};
136
136
  color: ${e=>e.theme.buttonText||"white"};
@@ -156,7 +156,7 @@
156
156
  cursor: not-allowed;
157
157
  opacity: 0.6;
158
158
  }
159
- `,_d=P.input`
159
+ `,xd=D.input`
160
160
  padding: 0.5rem 0.75rem;
161
161
  font-family: ${e=>e.theme.fontFamily};
162
162
  font-size: ${e=>e.theme.fontSize};
@@ -182,17 +182,17 @@
182
182
  opacity: 0.6;
183
183
  cursor: not-allowed;
184
184
  }
185
- `;P(_d)`
185
+ `;D(xd)`
186
186
  padding: 0.25rem 0.5rem;
187
187
  font-size: ${e=>e.theme.fontSizeSmall};
188
- `;var lg=P.label`
188
+ `;var cg=D.label`
189
189
  font-family: ${e=>e.theme.fontFamily};
190
190
  font-size: ${e=>e.theme.fontSizeSmall};
191
191
  font-weight: 500;
192
192
  color: ${e=>e.theme.textColorMuted};
193
193
  margin-bottom: 0.25rem;
194
194
  display: block;
195
- `;P.label`
195
+ `;D.label`
196
196
  font-family: ${e=>e.theme.fontFamily};
197
197
  font-size: ${e=>e.theme.fontSize};
198
198
  color: ${e=>e.theme.textColor};
@@ -200,7 +200,7 @@
200
200
  align-items: center;
201
201
  gap: 0.5rem;
202
202
  cursor: pointer;
203
- `;var cg=P.span`
203
+ `;var ug=D.span`
204
204
  position: absolute;
205
205
  width: 1px;
206
206
  height: 1px;
@@ -210,7 +210,7 @@
210
210
  clip: rect(0, 0, 0, 0);
211
211
  white-space: nowrap;
212
212
  border: 0;
213
- `,xd=P.select`
213
+ `,Cd=D.select`
214
214
  padding: 0.5rem 2rem 0.5rem 0.75rem;
215
215
  font-family: ${e=>e.theme.fontFamily};
216
216
  font-size: ${e=>e.theme.fontSize};
@@ -243,10 +243,10 @@
243
243
  color: ${e=>e.theme.inputText};
244
244
  background-color: ${e=>e.theme.inputBackground};
245
245
  }
246
- `;P(xd)`
246
+ `;D(Cd)`
247
247
  padding: 0.25rem 1.75rem 0.25rem 0.5rem;
248
248
  font-size: ${e=>e.theme.fontSizeSmall};
249
- `;var Cd=P.input.attrs({type:"range"})`
249
+ `;var Sd=D.input.attrs({type:"range"})`
250
250
  -webkit-appearance: none;
251
251
  appearance: none;
252
252
  width: 100%;
@@ -326,21 +326,21 @@
326
326
  &:disabled::-moz-range-thumb {
327
327
  cursor: not-allowed;
328
328
  }
329
- `,ug=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const s=o=>{t(o.target.checked)};return C.jsxs(og,{className:r,children:[C.jsx(ag,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:s,disabled:n}),C.jsx(ig,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function Sd(e){return typeof e=="object"&&e!==null&&"type"in e}function en(e){if(!Sd(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(r=>`${r.color} ${r.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var kd={waveformDrawMode:"inverted",waveOutlineColor:"#ffffff",waveFillColor:"#1a7f8e",waveProgressColor:"rgba(0, 0, 0, 0.10)",selectedWaveOutlineColor:"#ffffff",selectedWaveFillColor:"#00b4d8",selectedTrackControlsBackground:"#d9e9ff",timeColor:"#000",timescaleBackgroundColor:"#fff",playheadColor:"#f00",selectionColor:"rgba(255, 105, 180, 0.7)",loopRegionColor:"rgba(59, 130, 246, 0.3)",loopMarkerColor:"#3b82f6",clipHeaderBackgroundColor:"rgba(0, 0, 0, 0.1)",clipHeaderBorderColor:"rgba(0, 0, 0, 0.2)",clipHeaderTextColor:"#333",clipHeaderFontFamily:"inherit",selectedClipHeaderBackgroundColor:"#b3d9ff",fadeOverlayColor:"rgba(0, 0, 0, 0.4)",backgroundColor:"#ffffff",surfaceColor:"#f5f5f5",borderColor:"#ddd",textColor:"#333",textColorMuted:"#666",inputBackground:"#ffffff",inputBorder:"#ccc",inputText:"#333",inputPlaceholder:"#999",inputFocusBorder:"#0066cc",buttonBackground:"#0091ff",buttonText:"#ffffff",buttonBorder:"#0081e6",buttonHoverBackground:"#0081e6",sliderTrackColor:"#ddd",sliderThumbColor:"#daa520",annotationBoxBackground:"rgba(255, 255, 255, 0.85)",annotationBoxActiveBackground:"rgba(255, 255, 255, 0.95)",annotationBoxHoverBackground:"rgba(255, 255, 255, 0.98)",annotationBoxBorder:"#ff9800",annotationBoxActiveBorder:"#d67600",annotationLabelColor:"#2a2a2a",annotationResizeHandleColor:"rgba(0, 0, 0, 0.4)",annotationResizeHandleActiveColor:"rgba(0, 0, 0, 0.8)",annotationTextItemHoverBackground:"rgba(0, 0, 0, 0.03)",pianoRollNoteColor:"#2a7070",pianoRollSelectedNoteColor:"#3d9e9e",pianoRollBackgroundColor:"#1a1a2e",borderRadius:"4px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif',fontSize:"14px",fontSizeSmall:"12px"},dg=class{constructor(e){this._listeners=new Set,this._notifyRafId=null,this.subscribe=r=>(this._listeners.add(r),()=>this._listeners.delete(r)),this.getSnapshot=()=>this._state;const t=e?.clientWidth??(typeof window<"u"?window.innerWidth:1024),n=t*1.5;this._state={scrollLeft:0,containerWidth:t,visibleStart:0,visibleEnd:t+n}}update(e,t){const n=t*1.5,r=Math.max(0,e-n),s=e+t+n;this._state&&this._state.containerWidth===t&&Math.abs(this._state.scrollLeft-e)<100||(this._state={scrollLeft:e,containerWidth:t,visibleStart:r,visibleEnd:s},this._notifyRafId===null&&(this._notifyRafId=requestAnimationFrame(()=>{this._notifyRafId=null;for(const o of this._listeners)o()})))}cancelPendingNotification(){this._notifyRafId!==null&&(cancelAnimationFrame(this._notifyRafId),this._notifyRafId=null)}},Ed=g.createContext(null),fg=()=>()=>{},hg=({containerRef:e,children:t})=>{const n=g.useRef(null);n.current===null&&(n.current=new dg(e.current));const r=n.current,s=g.useRef(null),o=g.useCallback(()=>{const i=e.current;i&&r.update(i.scrollLeft,i.clientWidth)},[e,r]),a=g.useCallback(()=>{s.current===null&&(s.current=requestAnimationFrame(()=>{s.current=null,o()}))},[o]);return g.useLayoutEffect(()=>{o()},[o]),g.useEffect(()=>{const i=e.current;if(!i)return;i.addEventListener("scroll",a,{passive:!0});const l=new ResizeObserver(()=>{a()});return l.observe(i),()=>{i.removeEventListener("scroll",a),l.disconnect(),s.current!==null&&(cancelAnimationFrame(s.current),s.current=null),r.cancelPendingNotification()}},[e,a,r]),C.jsx(Ed.Provider,{value:r,children:t})};function pg(e){const t=g.useContext(Ed);return g.useSyncExternalStore(t?t.subscribe:fg,()=>e(t?t.getSnapshot():null),()=>e(null))}function js(e,t,n=0){const r=pg(s=>{const o=Math.ceil(e/t),a=[];for(let i=0;i<o;i++){const l=i*t,c=Math.min(e-l,t);if(s){const u=n+l;if(u+c<=s.visibleStart||u>=s.visibleEnd)continue}a.push(i)}return a.join(",")});return g.useMemo(()=>r?r.split(",").map(Number):[],[r])}var Id=g.createContext(0),mg=({originX:e,children:t})=>C.jsx(Id.Provider,{value:e,children:t}),hi=()=>g.useContext(Id);function Zs(){const e=g.useRef(new Map),t=g.useCallback(n=>{if(n!==null){const r=parseInt(n.dataset.index,10);e.current.set(r,n)}},[]);return g.useEffect(()=>{const n=e.current;for(const[r,s]of n.entries())s.isConnected||n.delete(r)}),{canvasRef:t,canvasMapRef:e}}function gg(e,t,n,r){if(n*2+1>=e.length)return null;const s=2**(t-1);let o=e[n*2]/s,a=e[n*2+1]/s;for(let i=n+1;i<r&&!(i*2+1>=e.length);i++){const l=e[i*2]/s,c=e[i*2+1]/s;l<o&&(o=l),c>a&&(a=c)}return{min:o,max:a}}function vg(e,t,n,r,s,o){const a=Math.abs(r*n),i=Math.abs(s*n);return o==="normal"?[{x:e,y:n-i,width:t,height:i+a}]:[{x:e,y:0,width:t,height:n-i},{x:e,y:n+a,width:t,height:n-a}]}function yg(e,t,n){return Math.floor((e-t+n)/n)*n}function bg(e,t,n,r){if(!Sd(t))return t;let s;t.direction==="vertical"?s=e.createLinearGradient(0,0,0,r):s=e.createLinearGradient(0,0,n,0);for(const o of t.stops)s.addColorStop(o.offset,o.color);return s}var wg=P.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
329
+ `,dg=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const s=o=>{t(o.target.checked)};return C.jsxs(ag,{className:r,children:[C.jsx(ig,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:s,disabled:n}),C.jsx(lg,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function kd(e){return typeof e=="object"&&e!==null&&"type"in e}function en(e){if(!kd(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(r=>`${r.color} ${r.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var Ed={waveformDrawMode:"inverted",waveOutlineColor:"#ffffff",waveFillColor:"#1a7f8e",waveProgressColor:"rgba(0, 0, 0, 0.10)",selectedWaveOutlineColor:"#ffffff",selectedWaveFillColor:"#00b4d8",selectedTrackControlsBackground:"#d9e9ff",timeColor:"#000",timescaleBackgroundColor:"#fff",playheadColor:"#f00",selectionColor:"rgba(255, 105, 180, 0.7)",loopRegionColor:"rgba(59, 130, 246, 0.3)",loopMarkerColor:"#3b82f6",clipHeaderBackgroundColor:"rgba(0, 0, 0, 0.1)",clipHeaderBorderColor:"rgba(0, 0, 0, 0.2)",clipHeaderTextColor:"#333",clipHeaderFontFamily:"inherit",selectedClipHeaderBackgroundColor:"#b3d9ff",fadeOverlayColor:"rgba(0, 0, 0, 0.4)",backgroundColor:"#ffffff",surfaceColor:"#f5f5f5",borderColor:"#ddd",textColor:"#333",textColorMuted:"#666",inputBackground:"#ffffff",inputBorder:"#ccc",inputText:"#333",inputPlaceholder:"#999",inputFocusBorder:"#0066cc",buttonBackground:"#0091ff",buttonText:"#ffffff",buttonBorder:"#0081e6",buttonHoverBackground:"#0081e6",sliderTrackColor:"#ddd",sliderThumbColor:"#daa520",annotationBoxBackground:"rgba(255, 255, 255, 0.85)",annotationBoxActiveBackground:"rgba(255, 255, 255, 0.95)",annotationBoxHoverBackground:"rgba(255, 255, 255, 0.98)",annotationBoxBorder:"#ff9800",annotationBoxActiveBorder:"#d67600",annotationLabelColor:"#2a2a2a",annotationResizeHandleColor:"rgba(0, 0, 0, 0.4)",annotationResizeHandleActiveColor:"rgba(0, 0, 0, 0.8)",annotationTextItemHoverBackground:"rgba(0, 0, 0, 0.03)",pianoRollNoteColor:"#2a7070",pianoRollSelectedNoteColor:"#3d9e9e",pianoRollBackgroundColor:"#1a1a2e",borderRadius:"4px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif',fontSize:"14px",fontSizeSmall:"12px"},fg=class{constructor(e){this._listeners=new Set,this._notifyRafId=null,this.subscribe=r=>(this._listeners.add(r),()=>this._listeners.delete(r)),this.getSnapshot=()=>this._state;const t=e?.clientWidth??(typeof window<"u"?window.innerWidth:1024),n=t*1.5;this._state={scrollLeft:0,containerWidth:t,visibleStart:0,visibleEnd:t+n}}update(e,t){const n=t*1.5,r=Math.max(0,e-n),s=e+t+n;this._state&&this._state.containerWidth===t&&Math.abs(this._state.scrollLeft-e)<100||(this._state={scrollLeft:e,containerWidth:t,visibleStart:r,visibleEnd:s},this._notifyRafId===null&&(this._notifyRafId=requestAnimationFrame(()=>{this._notifyRafId=null;for(const o of this._listeners)o()})))}cancelPendingNotification(){this._notifyRafId!==null&&(cancelAnimationFrame(this._notifyRafId),this._notifyRafId=null)}},Id=g.createContext(null),hg=()=>()=>{},pg=({containerRef:e,children:t})=>{const n=g.useRef(null);n.current===null&&(n.current=new fg(e.current));const r=n.current,s=g.useRef(null),o=g.useCallback(()=>{const i=e.current;i&&r.update(i.scrollLeft,i.clientWidth)},[e,r]),a=g.useCallback(()=>{s.current===null&&(s.current=requestAnimationFrame(()=>{s.current=null,o()}))},[o]);return g.useLayoutEffect(()=>{o()},[o]),g.useEffect(()=>{const i=e.current;if(!i)return;i.addEventListener("scroll",a,{passive:!0});const l=new ResizeObserver(()=>{a()});return l.observe(i),()=>{i.removeEventListener("scroll",a),l.disconnect(),s.current!==null&&(cancelAnimationFrame(s.current),s.current=null),r.cancelPendingNotification()}},[e,a,r]),C.jsx(Id.Provider,{value:r,children:t})};function mg(e){const t=g.useContext(Id);return g.useSyncExternalStore(t?t.subscribe:hg,()=>e(t?t.getSnapshot():null),()=>e(null))}function js(e,t,n=0){const r=mg(s=>{const o=Math.ceil(e/t),a=[];for(let i=0;i<o;i++){const l=i*t,c=Math.min(e-l,t);if(s){const u=n+l;if(u+c<=s.visibleStart||u>=s.visibleEnd)continue}a.push(i)}return a.join(",")});return g.useMemo(()=>r?r.split(",").map(Number):[],[r])}var Md=g.createContext(0),gg=({originX:e,children:t})=>C.jsx(Md.Provider,{value:e,children:t}),fi=()=>g.useContext(Md);function Zs(){const e=g.useRef(new Map),t=g.useCallback(n=>{if(n!==null){const r=parseInt(n.dataset.index,10);e.current.set(r,n)}},[]);return g.useEffect(()=>{const n=e.current;for(const[r,s]of n.entries())s.isConnected||n.delete(r)}),{canvasRef:t,canvasMapRef:e}}function vg(e,t,n,r){if(n*2+1>=e.length)return null;const s=2**(t-1);let o=e[n*2]/s,a=e[n*2+1]/s;for(let i=n+1;i<r&&!(i*2+1>=e.length);i++){const l=e[i*2]/s,c=e[i*2+1]/s;l<o&&(o=l),c>a&&(a=c)}return{min:o,max:a}}function yg(e,t,n,r,s,o){const a=Math.abs(r*n),i=Math.abs(s*n);return o==="normal"?[{x:e,y:n-i,width:t,height:i+a}]:[{x:e,y:0,width:t,height:n-i},{x:e,y:n+a,width:t,height:n-a}]}function bg(e,t,n){return Math.floor((e-t+n)/n)*n}function wg(e,t,n,r){if(!kd(t))return t;let s;t.direction==="vertical"?s=e.createLinearGradient(0,0,0,r):s=e.createLinearGradient(0,0,n,0);for(const o of t.stops)s.addColorStop(o.offset,o.color);return s}var _g=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
330
330
  position: absolute;
331
331
  top: 0;
332
332
  /* Disable image rendering interpolation */
333
333
  image-rendering: pixelated;
334
334
  image-rendering: crisp-edges;
335
- `,_g=P.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
335
+ `,xg=D.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
336
336
  position: absolute;
337
337
  background: ${e=>e.$waveFillColor};
338
338
  /* Force GPU compositing layer to reduce scroll flickering */
339
339
  transform: translateZ(0);
340
340
  backface-visibility: hidden;
341
- `,$l=e=>{const{data:t,bits:n,length:r,index:s,className:o,devicePixelRatio:a=1,waveHeight:i=80,waveOutlineColor:l="#E0EFF1",waveFillColor:c="grey",barWidth:u=1,barGap:f=0,transparentBackground:h=!1,drawMode:d="inverted"}=e,{canvasRef:p,canvasMapRef:v}=Zs(),y=hi(),m=js(r,Le,y);g.useEffect(()=>{const x=performance.now(),S=u+f;for(const[k,E]of v.current.entries()){const T=k*Le,I=E.getContext("2d"),M=Math.floor(i/2);if(I){I.resetTransform(),I.clearRect(0,0,E.width,E.height),I.imageSmoothingEnabled=!1,I.scale(a,a);const $=E.width/a;let A;d==="normal"?A=c:A=l,I.fillStyle=bg(I,A,$,i);const R=T,W=T+$,q=yg(R,u,S);for(let z=Math.max(0,q);z<W;z+=S){const J=z-R;if(J+u<=0)continue;const ee=Math.min(z+S,r),j=gg(t,n,z,ee);if(j){const se=vg(J,u,M,j.min,j.max,d);for(const U of se)I.fillRect(U.x,U.y,U.width,U.height)}}}}console.log(`[waveform] draw ch${s}: ${v.current.size} chunks, ${(performance.now()-x).toFixed(1)}ms`)},[v,t,n,i,l,c,a,r,u,f,d,m,s]);const b=m.map(x=>{const S=x*Le,k=Math.min(r-S,Le);return C.jsx(wg,{$cssWidth:k,$left:S,width:k*a,height:i*a,$waveHeight:i,"data-index":x,ref:p},`${r}-${x}`)}),w=h?"transparent":en(c);return C.jsx(_g,{$index:s,$cssWidth:r,className:o,$waveHeight:i,$waveFillColor:w,children:b})},xg={padding:"16px",background:"#1a1a2e",color:"#e0e0e0",border:"1px solid #d08070",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px",minHeight:"60px",display:"flex",alignItems:"center",justifyContent:"center"};(class extends g.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[waveform-playlist] Render error:",e,t.componentStack)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:C.jsx("div",{style:xg,children:"Waveform playlist encountered an error. Check console for details."}):this.props.children}});var pi=22,Md=P.div`
341
+ `,Tl=e=>{const{data:t,bits:n,length:r,index:s,className:o,devicePixelRatio:a=1,waveHeight:i=80,waveOutlineColor:l="#E0EFF1",waveFillColor:c="grey",barWidth:u=1,barGap:f=0,transparentBackground:h=!1,drawMode:d="inverted"}=e,{canvasRef:p,canvasMapRef:v}=Zs(),y=fi(),m=js(r,Le,y);g.useEffect(()=>{const x=performance.now(),S=u+f;for(const[k,E]of v.current.entries()){const M=k*Le,I=E.getContext("2d"),T=Math.floor(i/2);if(I){I.resetTransform(),I.clearRect(0,0,E.width,E.height),I.imageSmoothingEnabled=!1,I.scale(a,a);const $=E.width/a;let A;d==="normal"?A=c:A=l,I.fillStyle=wg(I,A,$,i);const P=M,W=M+$,J=bg(P,u,S);for(let G=Math.max(0,J);G<W;G+=S){const Q=G-P;if(Q+u<=0)continue;const ee=Math.min(G+S,r),z=vg(t,n,G,ee);if(z){const se=yg(Q,u,T,z.min,z.max,d);for(const U of se)I.fillRect(U.x,U.y,U.width,U.height)}}}}console.log(`[waveform] draw ch${s}: ${v.current.size} chunks, ${(performance.now()-x).toFixed(1)}ms`)},[v,t,n,i,l,c,a,r,u,f,d,m,s]);const b=m.map(x=>{const S=x*Le,k=Math.min(r-S,Le);return C.jsx(_g,{$cssWidth:k,$left:S,width:k*a,height:i*a,$waveHeight:i,"data-index":x,ref:p},`${r}-${x}`)}),w=h?"transparent":en(c);return C.jsx(xg,{$index:s,$cssWidth:r,className:o,$waveHeight:i,$waveFillColor:w,children:b})},Cg={padding:"16px",background:"#1a1a2e",color:"#e0e0e0",border:"1px solid #d08070",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px",minHeight:"60px",display:"flex",alignItems:"center",justifyContent:"center"};(class extends g.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[waveform-playlist] Render error:",e,t.componentStack)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:C.jsx("div",{style:Cg,children:"Waveform playlist encountered an error. Check console for details."}):this.props.children}});var hi=22,Ad=D.div`
342
342
  position: relative;
343
- height: ${pi}px;
343
+ height: ${hi}px;
344
344
  background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
345
345
  border-bottom: 1px solid ${e=>e.theme.clipHeaderBorderColor};
346
346
  display: flex;
@@ -362,7 +362,7 @@
362
362
  cursor: grabbing;
363
363
  }
364
364
  `}
365
- `,Ad=P.span`
365
+ `,Td=D.span`
366
366
  font-size: 11px;
367
367
  font-weight: 600;
368
368
  font-family: ${e=>e.theme.clipHeaderFontFamily};
@@ -370,12 +370,12 @@
370
370
  white-space: nowrap;
371
371
  overflow: hidden;
372
372
  text-overflow: ellipsis;
373
- `,Cg=({trackName:e,isSelected:t=!1})=>C.jsx(Md,{$interactive:!1,$isSelected:t,children:C.jsx(Ad,{title:e,children:e})}),Sg=({clipId:e,trackIndex:t,clipIndex:n,trackName:r,isSelected:s=!1,disableDrag:o=!1,dragHandleProps:a})=>{if(o||!a)return C.jsx(Cg,{trackName:r,isSelected:s});const{handleRef:i}=a;return C.jsx(Md,{ref:i,"data-clip-id":e,$interactive:!0,$isSelected:s,children:C.jsx(Ad,{title:r,children:r})})},kg=8,Eg=24,Ig=P.div`
373
+ `,Sg=({trackName:e,isSelected:t=!1})=>C.jsx(Ad,{$interactive:!1,$isSelected:t,children:C.jsx(Td,{title:e,children:e})}),kg=({clipId:e,trackIndex:t,clipIndex:n,trackName:r,isSelected:s=!1,disableDrag:o=!1,dragHandleProps:a})=>{if(o||!a)return C.jsx(Sg,{trackName:r,isSelected:s});const{handleRef:i}=a;return C.jsx(Ad,{ref:i,"data-clip-id":e,$interactive:!0,$isSelected:s,children:C.jsx(Td,{title:r,children:r})})},Eg=8,Ig=24,Mg=D.div`
374
374
  position: absolute;
375
375
  ${e=>e.$edge==="left"?"left: 0;":"right: 0;"}
376
376
  top: 0;
377
377
  bottom: 0;
378
- width: ${e=>e.$touchOptimized?Eg:kg}px;
378
+ width: ${e=>e.$touchOptimized?Ig:Eg}px;
379
379
  cursor: col-resize;
380
380
  user-select: none;
381
381
  z-index: 105; /* Above waveform, below header */
@@ -398,56 +398,51 @@
398
398
  background: rgba(255, 255, 255, 0.4);
399
399
  ${e=>e.$edge==="left"?"border-left: 2px solid rgba(255, 255, 255, 0.8);":"border-right: 2px solid rgba(255, 255, 255, 0.8);"}
400
400
  }
401
- `,Rl=({clipId:e,trackIndex:t,clipIndex:n,edge:r,dragHandleProps:s,touchOptimized:o=!1})=>{const[a,i]=g.useState(!1);if(!s)return null;const{ref:l,isDragging:c}=s;return C.jsx(Ig,{ref:l,"data-clip-id":e,"data-boundary-edge":r,$edge:r,$isDragging:c,$isHovered:a,$touchOptimized:o,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1)})},Mg=P.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
401
+ `,$l=({clipId:e,trackIndex:t,clipIndex:n,edge:r,dragHandleProps:s,touchOptimized:o=!1})=>{const[a,i]=g.useState(!1);if(!s)return null;const{ref:l,isDragging:c}=s;return C.jsx(Mg,{ref:l,"data-clip-id":e,"data-boundary-edge":r,$edge:r,$isDragging:c,$isHovered:a,$touchOptimized:o,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1)})},Ag=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
402
402
  position: absolute;
403
403
  top: 0;
404
404
  bottom: 0;
405
405
  pointer-events: none;
406
406
  z-index: 50;
407
- `,Ag=P.svg`
407
+ `,Tg=D.svg`
408
408
  width: 100%;
409
409
  height: 100%;
410
410
  display: block;
411
411
  /* Flip horizontally for fadeOut - makes it mirror of fadeIn */
412
412
  transform: ${e=>e.$type==="fadeOut"?"scaleX(-1)":"none"};
413
- `;function Tg(e,t,n="logarithmic"){const r=[],s=Math.max(20,Math.min(e,100));for(let o=0;o<=s;o++){const a=o/s*e,i=o/s;let l;switch(n){case"linear":l=i;break;case"exponential":l=i*i;break;case"sCurve":l=(1-Math.cos(i*Math.PI))/2;break;case"logarithmic":default:l=Math.log10(1+i*9)/Math.log10(10);break}const c=(1-l)*t;r.push(`${a},${c}`)}return`M 0,${t} L ${r.join(" L ")} L ${e},0 L 0,0 Z`}var Dl=({left:e,width:t,type:n,curveType:r="logarithmic",color:s})=>{const o=P.useTheme();if(t<1)return null;const a=s||o?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return C.jsx(Mg,{$left:e,$width:t,$type:n,children:C.jsx(Ag,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:C.jsx("path",{d:Tg(t,100,r),fill:a})})})},$g=P.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
413
+ `;function $g(e,t,n="logarithmic"){const r=[],s=Math.max(20,Math.min(e,100));for(let o=0;o<=s;o++){const a=o/s*e,i=o/s;let l;switch(n){case"linear":l=i;break;case"exponential":l=i*i;break;case"sCurve":l=(1-Math.cos(i*Math.PI))/2;break;case"logarithmic":default:l=Math.log10(1+i*9)/Math.log10(10);break}const c=(1-l)*t;r.push(`${a},${c}`)}return`M 0,${t} L ${r.join(" L ")} L ${e},0 L 0,0 Z`}var Rl=({left:e,width:t,type:n,curveType:r="logarithmic",color:s})=>{const o=D.useTheme();if(t<1)return null;const a=s||o?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return C.jsx(Ag,{$left:e,$width:t,$type:n,children:C.jsx(Tg,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:C.jsx("path",{d:$g(t,100,r),fill:a})})})},Rg=D.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
414
414
  position: ${e=>e.$isOverlay?"relative":"absolute"};
415
415
  top: 0;
416
416
  height: ${e=>e.$isOverlay?"auto":"100%"};
417
417
  width: ${e=>e.$isOverlay?`${e.$width}px`:"auto"};
418
418
  display: flex;
419
419
  flex-direction: column;
420
- background: rgba(255, 255, 255, 0.05);
421
420
  z-index: 10; /* Above progress overlay (z-index: 2) but below controls/playhead */
422
421
  pointer-events: none; /* Let clicks pass through to ClickOverlay for playhead positioning */
423
-
424
- &:hover {
425
- background: rgba(255, 255, 255, 0.08);
426
- }
427
- `,Rg=P.div`
422
+ `,Dg=D.div`
428
423
  flex: 1;
429
424
  position: relative;
430
425
  overflow: ${e=>e.$isOverlay?"visible":"hidden"};
431
- `,oa=({children:e,className:t,clipId:n,trackIndex:r,clipIndex:s,trackName:o,startSample:a,durationSamples:i,samplesPerPixel:l,showHeader:c=!1,disableHeaderDrag:u=!1,isOverlay:f=!1,isSelected:h=!1,onMouseDown:d,trackId:p,fadeIn:v,fadeOut:y,sampleRate:m=44100,showFades:b=!1,touchOptimized:_=!1})=>{const w=Math.floor(a/l),S=Math.floor((a+i)/l)-w,k=c&&!u&&!f,E=`clip-${r}-${s}`,{ref:T,handleRef:I,isDragSource:M}=vo({id:E,data:{clipId:n,trackIndex:r,clipIndex:s},disabled:!k}),$=`clip-boundary-left-${r}-${s}`,{ref:A,isDragSource:R}=vo({id:$,data:{clipId:n,trackIndex:r,clipIndex:s,boundary:"left"},disabled:!k,feedback:"none"}),W=`clip-boundary-right-${r}-${s}`,{ref:q,isDragSource:z}=vo({id:W,data:{clipId:n,trackIndex:r,clipIndex:s,boundary:"right"},disabled:!k,feedback:"none"}),J=M?{zIndex:100}:void 0;return C.jsxs($g,{ref:T,style:J,className:t,$left:w,$width:S,$isOverlay:f,"data-clip-container":"true","data-track-id":p,onMouseDown:d,tabIndex:-1,children:[c&&C.jsx(Sg,{clipId:n,trackIndex:r,clipIndex:s,trackName:o,isSelected:h,disableDrag:u,dragHandleProps:k?{handleRef:I}:void 0}),C.jsx(mg,{originX:w,children:C.jsxs(Rg,{$isOverlay:f,children:[e,b&&v&&v.duration>0&&C.jsx(Dl,{left:0,width:Math.floor(v.duration*m/l),type:"fadeIn",curveType:v.type}),b&&y&&y.duration>0&&C.jsx(Dl,{left:S-Math.floor(y.duration*m/l),width:Math.floor(y.duration*m/l),type:"fadeOut",curveType:y.type})]})}),c&&!u&&!f&&C.jsxs(C.Fragment,{children:[C.jsx(Rl,{clipId:n,trackIndex:r,clipIndex:s,edge:"left",touchOptimized:_,dragHandleProps:{ref:A,isDragging:R}}),C.jsx(Rl,{clipId:n,trackIndex:r,clipIndex:s,edge:"right",touchOptimized:_,dragHandleProps:{ref:q,isDragging:z}})]})]})},Dg=P.div`
426
+ `,sa=({children:e,className:t,clipId:n,trackIndex:r,clipIndex:s,trackName:o,startSample:a,durationSamples:i,samplesPerPixel:l,showHeader:c=!1,disableHeaderDrag:u=!1,isOverlay:f=!1,isSelected:h=!1,onMouseDown:d,trackId:p,fadeIn:v,fadeOut:y,sampleRate:m=44100,showFades:b=!1,touchOptimized:_=!1})=>{const w=Math.floor(a/l),x=ec(a,i,l),S=c&&!u&&!f,k=`clip-${r}-${s}`,{ref:E,handleRef:M,isDragSource:I}=vo({id:k,data:{clipId:n,trackIndex:r,clipIndex:s},disabled:!S}),T=`clip-boundary-left-${r}-${s}`,{ref:$,isDragSource:A}=vo({id:T,data:{clipId:n,trackIndex:r,clipIndex:s,boundary:"left"},disabled:!S,feedback:"none"}),P=`clip-boundary-right-${r}-${s}`,{ref:W,isDragSource:J}=vo({id:P,data:{clipId:n,trackIndex:r,clipIndex:s,boundary:"right"},disabled:!S,feedback:"none"}),G=I?{zIndex:100}:void 0;return C.jsxs(Rg,{ref:E,style:G,className:t,$left:w,$width:x,$isOverlay:f,"data-clip-container":"true","data-track-id":p,onMouseDown:d,tabIndex:-1,children:[c&&C.jsx(kg,{clipId:n,trackIndex:r,clipIndex:s,trackName:o,isSelected:h,disableDrag:u,dragHandleProps:S?{handleRef:M}:void 0}),C.jsx(gg,{originX:w,children:C.jsxs(Dg,{$isOverlay:f,children:[e,b&&v&&v.duration>0&&C.jsx(Rl,{left:0,width:Math.floor(v.duration*m/l),type:"fadeIn",curveType:v.type}),b&&y&&y.duration>0&&C.jsx(Rl,{left:x-Math.floor(y.duration*m/l),width:Math.floor(y.duration*m/l),type:"fadeOut",curveType:y.type})]})}),c&&!u&&!f&&C.jsxs(C.Fragment,{children:[C.jsx($l,{clipId:n,trackIndex:r,clipIndex:s,edge:"left",touchOptimized:_,dragHandleProps:{ref:$,isDragging:A}}),C.jsx($l,{clipId:n,trackIndex:r,clipIndex:s,edge:"right",touchOptimized:_,dragHandleProps:{ref:W,isDragging:J}})]})]})},Pg=D.div`
432
427
  display: inline-flex;
433
428
  align-items: center;
434
429
  gap: 0.5rem;
435
- `,Pg=P(lg)`
430
+ `,Fg=D(cg)`
436
431
  margin: 0;
437
432
  white-space: nowrap;
438
- `,Fg=P(Cd)`
433
+ `,Og=D(Sd)`
439
434
  width: 120px;
440
- `,Og=({volume:e,onChange:t,disabled:n=!1,className:r})=>{const s=o=>{t(parseFloat(o.target.value)/100)};return C.jsxs(Dg,{className:r,children:[C.jsx(Pg,{htmlFor:"master-gain",children:"Master Volume"}),C.jsx(Fg,{min:"0",max:"100",value:e*100,onChange:s,disabled:n,id:"master-gain"})]})},Lg=P.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
435
+ `,Lg=({volume:e,onChange:t,disabled:n=!1,className:r})=>{const s=o=>{t(parseFloat(o.target.value)/100)};return C.jsxs(Pg,{className:r,children:[C.jsx(Fg,{htmlFor:"master-gain",children:"Master Volume"}),C.jsx(Og,{min:"0",max:"100",value:e*100,onChange:s,disabled:n,id:"master-gain"})]})},Wg=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
441
436
  position: absolute;
442
437
  top: 0;
443
438
  image-rendering: pixelated;
444
439
  image-rendering: crisp-edges;
445
- `,Wg=P.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
440
+ `,Bg=D.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
446
441
  position: absolute;
447
442
  background: ${e=>e.$backgroundColor};
448
443
  transform: translateZ(0);
449
444
  backface-visibility: hidden;
450
- `,Bg=({index:e,midiNotes:t,length:n,waveHeight:r,devicePixelRatio:s,samplesPerPixel:o,sampleRate:a,clipOffsetSeconds:i,noteColor:l="#2a7070",selectedNoteColor:c="#3d9e9e",isSelected:u=!1,transparentBackground:f=!1,backgroundColor:h="#1a1a2e"})=>{const{canvasRef:d,canvasMapRef:p}=Zs(),v=hi(),y=js(n,Le,v),{minMidi:m,maxMidi:b}=g.useMemo(()=>{if(t.length===0)return{minMidi:0,maxMidi:127};let S=127,k=0;for(const E of t)E.midi<S&&(S=E.midi),E.midi>k&&(k=E.midi);return{minMidi:Math.max(0,S-1),maxMidi:Math.min(127,k+1)}},[t]),_=u?c:l;g.useEffect(()=>{const S=performance.now(),k=b-m+1,E=Math.max(2,r/k),T=a/o;for(const[I,M]of p.current.entries()){const $=I*Le,A=M.width/s,R=M.getContext("2d");if(!R)continue;R.resetTransform(),R.clearRect(0,0,M.width,M.height),R.imageSmoothingEnabled=!1,R.scale(s,s);const W=$*o/a,q=($+A)*o/a;for(const z of t){const J=z.time-i;if(J+z.duration<=W||J>=q)continue;const j=J*T-$,se=Math.max(2,z.duration*T),U=(b-z.midi)/k*r,ie=.3+z.velocity*.7;R.fillStyle=_,R.globalAlpha=ie;const le=1;R.beginPath(),R.roundRect(j,U,se,E,le),R.fill()}R.globalAlpha=1}console.log(`[piano-roll] draw ch${e}: ${p.current.size} chunks, ${t.length} notes, ${(performance.now()-S).toFixed(1)}ms`)},[p,t,r,s,o,a,i,_,m,b,n,y,e]);const w=y.map(S=>{const k=S*Le,E=Math.min(n-k,Le);return C.jsx(Lg,{$cssWidth:E,$left:k,width:E*s,height:r*s,$waveHeight:r,"data-index":S,ref:d},`${n}-${S}`)}),x=f?"transparent":h;return C.jsx(Wg,{$index:e,$cssWidth:n,$waveHeight:r,$backgroundColor:x,children:w})};P.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
445
+ `,Vg=({index:e,midiNotes:t,length:n,waveHeight:r,devicePixelRatio:s,samplesPerPixel:o,sampleRate:a,clipOffsetSeconds:i,noteColor:l="#2a7070",selectedNoteColor:c="#3d9e9e",isSelected:u=!1,transparentBackground:f=!1,backgroundColor:h="#1a1a2e"})=>{const{canvasRef:d,canvasMapRef:p}=Zs(),v=fi(),y=js(n,Le,v),{minMidi:m,maxMidi:b}=g.useMemo(()=>{if(t.length===0)return{minMidi:0,maxMidi:127};let S=127,k=0;for(const E of t)E.midi<S&&(S=E.midi),E.midi>k&&(k=E.midi);return{minMidi:Math.max(0,S-1),maxMidi:Math.min(127,k+1)}},[t]),_=u?c:l;g.useEffect(()=>{const S=performance.now(),k=b-m+1,E=Math.max(2,r/k),M=a/o;for(const[I,T]of p.current.entries()){const $=I*Le,A=T.width/s,P=T.getContext("2d");if(!P)continue;P.resetTransform(),P.clearRect(0,0,T.width,T.height),P.imageSmoothingEnabled=!1,P.scale(s,s);const W=$*o/a,J=($+A)*o/a;for(const G of t){const Q=G.time-i;if(Q+G.duration<=W||Q>=J)continue;const z=Q*M-$,se=Math.max(2,G.duration*M),U=(b-G.midi)/k*r,ie=.3+G.velocity*.7;P.fillStyle=_,P.globalAlpha=ie;const le=1;P.beginPath(),P.roundRect(z,U,se,E,le),P.fill()}P.globalAlpha=1}console.log(`[piano-roll] draw ch${e}: ${p.current.size} chunks, ${t.length} notes, ${(performance.now()-S).toFixed(1)}ms`)},[p,t,r,s,o,a,i,_,m,b,n,y,e]);const w=y.map(S=>{const k=S*Le,E=Math.min(n-k,Le);return C.jsx(Wg,{$cssWidth:E,$left:k,width:E*s,height:r*s,$waveHeight:r,"data-index":S,ref:d},`${n}-${S}`)}),x=f?"transparent":h;return C.jsx(Bg,{$index:e,$cssWidth:n,$waveHeight:r,$backgroundColor:x,children:w})};D.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
451
446
  position: absolute;
452
447
  top: 0;
453
448
  left: 0;
@@ -457,7 +452,7 @@
457
452
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
458
453
  pointer-events: none;
459
454
  will-change: transform;
460
- `;P.div`
455
+ `;D.div`
461
456
  position: absolute;
462
457
  top: 0;
463
458
  left: 0;
@@ -465,7 +460,7 @@
465
460
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
466
461
  pointer-events: none;
467
462
  will-change: transform;
468
- `;P.div`
463
+ `;D.div`
469
464
  position: absolute;
470
465
  top: -10px;
471
466
  left: -6px;
@@ -474,39 +469,39 @@
474
469
  border-left: 7px solid transparent;
475
470
  border-right: 7px solid transparent;
476
471
  border-top: 10px solid ${e=>e.$color};
477
- `;P.div`
472
+ `;D.div`
478
473
  position: absolute;
479
474
  top: 0;
480
475
  left: 0;
481
476
  width: 2px;
482
477
  height: 100%;
483
478
  background: ${e=>e.$color};
484
- `;var Vg=P.div`
479
+ `;var Ng=D.div`
485
480
  display: flex;
486
481
  overflow-y: hidden;
487
482
  position: relative;
488
- `,Ng=P.div.attrs(e=>({style:{width:`${e.$width}px`}}))`
483
+ `,zg=D.div.attrs(e=>({style:{width:`${e.$width}px`}}))`
489
484
  flex-shrink: 0;
490
485
  overflow: hidden;
491
- `,zg=P.div.attrs(e=>({style:{height:`${e.$height}px`}}))``,jg=P.div`
486
+ `,jg=D.div.attrs(e=>({style:{height:`${e.$height}px`}}))``,Zg=D.div`
492
487
  overflow-x: auto;
493
488
  overflow-y: hidden;
494
489
  overflow-anchor: none;
495
490
  flex: 1;
496
491
  position: relative;
497
- `,Zg=P.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
492
+ `,Hg=D.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
498
493
  position: relative;
499
494
  background: ${e=>e.$backgroundColor||"transparent"};
500
- `,Hg=P.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
495
+ `,Gg=D.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
501
496
  background: ${e=>e.$backgroundColor||"white"};
502
497
  width: 100%;
503
498
  position: relative;
504
499
  overflow: hidden; /* Constrain loop region to timescale area */
505
- `,Gg=P.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
500
+ `,Ug=D.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
506
501
  position: relative;
507
502
  background: ${e=>e.$backgroundColor||"transparent"};
508
503
  width: 100%;
509
- `,Ug=P.div`
504
+ `,Xg=D.div`
510
505
  position: absolute;
511
506
  top: 0;
512
507
  left: 0;
@@ -515,7 +510,7 @@
515
510
  cursor: crosshair;
516
511
  /* When selecting, raise z-index above clip boundaries (z-index: 105) to prevent interference */
517
512
  z-index: ${e=>e.$isSelecting?110:1};
518
- `,mi=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:r,timescaleWidth:s,tracksWidth:o,controlsWidth:a,onTracksClick:i,onTracksMouseDown:l,onTracksMouseMove:c,onTracksMouseUp:u,scrollContainerRef:f,isSelecting:h,"data-playlist-state":d,trackControlsSlots:p,timescaleGapHeight:v=0})=>{const y=g.useRef(null),m=g.useCallback(_=>{y.current=_,f?.(_)},[f]),b=a!==void 0&&a>0;return C.jsxs(Vg,{"data-playlist-state":d,children:[b&&C.jsxs(Ng,{$width:a,children:[v>0&&C.jsx(zg,{$height:v}),p]}),C.jsx(jg,{"data-scroll-container":"true",ref:m,children:C.jsx(hg,{containerRef:y,children:C.jsxs(Zg,{$backgroundColor:t,$width:o,children:[r&&C.jsx(Hg,{$width:s,$backgroundColor:n,children:r}),C.jsxs(Gg,{$width:o,$backgroundColor:t,children:[e,(i||l)&&C.jsx(Ug,{$isSelecting:h,onClick:i,onMouseDown:l,onMouseMove:c,onMouseUp:u})]})]})})})]})};P.withTheme(mi);var Xg=P.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
513
+ `,pi=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:r,timescaleWidth:s,tracksWidth:o,controlsWidth:a,onTracksClick:i,onTracksMouseDown:l,onTracksMouseMove:c,onTracksMouseUp:u,scrollContainerRef:f,isSelecting:h,"data-playlist-state":d,trackControlsSlots:p,timescaleGapHeight:v=0})=>{const y=g.useRef(null),m=g.useCallback(_=>{y.current=_,f?.(_)},[f]),b=a!==void 0&&a>0;return C.jsxs(Ng,{"data-playlist-state":d,children:[b&&C.jsxs(zg,{$width:a,children:[v>0&&C.jsx(jg,{$height:v}),p]}),C.jsx(Zg,{"data-scroll-container":"true",ref:m,children:C.jsx(pg,{containerRef:y,children:C.jsxs(Hg,{$backgroundColor:t,$width:o,children:[r&&C.jsx(Gg,{$width:s,$backgroundColor:n,children:r}),C.jsxs(Ug,{$width:o,$backgroundColor:t,children:[e,(i||l)&&C.jsx(Xg,{$isSelecting:h,onClick:i,onMouseDown:l,onMouseMove:c,onMouseUp:u})]})]})})})]})};D.withTheme(pi);var Yg=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
519
514
  position: absolute;
520
515
  top: 0;
521
516
  background: ${e=>e.$color};
@@ -523,14 +518,14 @@
523
518
  z-index: 60; /* Above clips (z-index: 10) and fades (z-index: 50), below playhead (z-index: 100) */
524
519
  pointer-events: none;
525
520
  opacity: 0.3;
526
- `,Td=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const r=Math.max(0,t-e);return r<=0?null:C.jsx(Xg,{$left:e,$width:r,$color:n,"data-selection":!0})};P.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
521
+ `,$d=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const r=Math.max(0,t-e);return r<=0?null:C.jsx(Yg,{$left:e,$width:r,$color:n,"data-selection":!0})};D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
527
522
  position: absolute;
528
523
  top: 0;
529
524
  background: ${e=>e.$color};
530
525
  height: 100%;
531
526
  z-index: 55; /* Between clips (z-index: 50) and selection (z-index: 60) */
532
527
  pointer-events: none;
533
- `;P.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
528
+ `;D.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
534
529
  position: absolute;
535
530
  top: 0;
536
531
  width: 2px;
@@ -550,7 +545,7 @@
550
545
  border-top: 8px solid ${e=>e.$color};
551
546
  ${e=>e.$isStart?"border-right: 8px solid transparent;":"border-left: 8px solid transparent;"}
552
547
  }
553
- `;var Pl=P.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
548
+ `;var Dl=D.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
554
549
  position: absolute;
555
550
  top: 0;
556
551
  width: 12px;
@@ -587,7 +582,7 @@
587
582
  &:hover::before {
588
583
  opacity: 1;
589
584
  }
590
- `,Yg=P.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
585
+ `,Kg=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
591
586
  position: absolute;
592
587
  top: 0;
593
588
  height: 100%;
@@ -598,7 +593,7 @@
598
593
  &:active {
599
594
  cursor: grabbing;
600
595
  }
601
- `,Kg=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopStartChange:s,onLoopEndChange:o,onLoopRegionMove:a,minPosition:i=0,maxPosition:l=1/0})=>{const[c,u]=g.useState(null),f=g.useRef(0),h=g.useRef(0),d=g.useRef(0),p=Math.max(0,t-e),v=g.useCallback((m,b)=>{m.preventDefault(),m.stopPropagation(),u(b),f.current=m.clientX,h.current=b==="start"?e:t;const _=x=>{const S=x.clientX-f.current,k=h.current+S;if(b==="start"){const E=Math.max(i,Math.min(t-10,k));s?.(E)}else{const E=Math.max(e+10,Math.min(l,k));o?.(E)}},w=()=>{u(null),document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",_),document.addEventListener("mouseup",w)},[e,t,i,l,s,o]),y=g.useCallback(m=>{m.preventDefault(),m.stopPropagation(),u("region"),f.current=m.clientX,h.current=e,d.current=t;const b=t-e,_=x=>{const S=x.clientX-f.current;let k=h.current+S,E=d.current+S;k<i&&(k=i,E=i+b),E>l&&(E=l,k=l-b),a?.(k,E)},w=()=>{u(null),document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",_),document.addEventListener("mouseup",w)},[e,t,i,l,a]);return p<=0?null:C.jsxs(C.Fragment,{children:[C.jsx(Yg,{$left:e,$width:p,$color:r,$isDragging:c==="region",onMouseDown:y,"data-loop-region-timescale":!0}),C.jsx(Pl,{$left:e,$color:n,$isStart:!0,$isDragging:c==="start",onMouseDown:m=>v(m,"start"),"data-loop-marker-handle":"start"}),C.jsx(Pl,{$left:t,$color:n,$isStart:!1,$isDragging:c==="end",onMouseDown:m=>v(m,"end"),"data-loop-marker-handle":"end"})]})},qg=P.div`
596
+ `,qg=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopStartChange:s,onLoopEndChange:o,onLoopRegionMove:a,minPosition:i=0,maxPosition:l=1/0})=>{const[c,u]=g.useState(null),f=g.useRef(0),h=g.useRef(0),d=g.useRef(0),p=Math.max(0,t-e),v=g.useCallback((m,b)=>{m.preventDefault(),m.stopPropagation(),u(b),f.current=m.clientX,h.current=b==="start"?e:t;const _=x=>{const S=x.clientX-f.current,k=h.current+S;if(b==="start"){const E=Math.max(i,Math.min(t-10,k));s?.(E)}else{const E=Math.max(e+10,Math.min(l,k));o?.(E)}},w=()=>{u(null),document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",_),document.addEventListener("mouseup",w)},[e,t,i,l,s,o]),y=g.useCallback(m=>{m.preventDefault(),m.stopPropagation(),u("region"),f.current=m.clientX,h.current=e,d.current=t;const b=t-e,_=x=>{const S=x.clientX-f.current;let k=h.current+S,E=d.current+S;k<i&&(k=i,E=i+b),E>l&&(E=l,k=l-b),a?.(k,E)},w=()=>{u(null),document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",_),document.addEventListener("mouseup",w)},[e,t,i,l,a]);return p<=0?null:C.jsxs(C.Fragment,{children:[C.jsx(Kg,{$left:e,$width:p,$color:r,$isDragging:c==="region",onMouseDown:y,"data-loop-region-timescale":!0}),C.jsx(Dl,{$left:e,$color:n,$isStart:!0,$isDragging:c==="start",onMouseDown:m=>v(m,"start"),"data-loop-marker-handle":"start"}),C.jsx(Dl,{$left:t,$color:n,$isStart:!1,$isDragging:c==="end",onMouseDown:m=>v(m,"end"),"data-loop-marker-handle":"end"})]})},Jg=D.div`
602
597
  position: absolute;
603
598
  top: 0;
604
599
  left: 0;
@@ -606,17 +601,17 @@
606
601
  height: 100%; /* Stay within timescale bounds, don't extend into tracks */
607
602
  cursor: crosshair;
608
603
  z-index: 40; /* Below markers and shading */
609
- `,Jg=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopRegionChange:s,minPosition:o=0,maxPosition:a=1/0})=>{const[,i]=g.useState(!1),l=g.useRef(0),c=g.useRef(null),u=t>e,f=g.useCallback(h=>{const d=h.target;if(d.closest("[data-loop-marker-handle]")||d.closest("[data-loop-region-timescale]"))return;h.preventDefault(),i(!0);const p=c.current?.getBoundingClientRect();if(!p)return;const v=h.clientX-p.left,y=Math.max(o,Math.min(a,v));l.current=y,s?.(y,y);const m=_=>{const w=_.clientX-p.left,x=Math.max(o,Math.min(a,w)),S=Math.min(l.current,x),k=Math.max(l.current,x);s?.(S,k)},b=()=>{i(!1),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",b)};document.addEventListener("mousemove",m),document.addEventListener("mouseup",b)},[o,a,s]);return C.jsx(qg,{ref:c,onMouseDown:f,"data-timescale-loop-creator":!0,children:u&&C.jsx(Kg,{startPosition:e,endPosition:t,markerColor:n,regionColor:r,minPosition:o,maxPosition:a,onLoopStartChange:h=>s?.(h,t),onLoopEndChange:h=>s?.(e,h),onLoopRegionMove:(h,d)=>s?.(h,d)})})};function er(e,t){const n=Math.floor(e/3600)%24,r=Math.floor(e/60)%60,s=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(r).padStart(2,"0")+":"+s.padStart(t+3,"0")}function Ln(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return er(e,0);case"hh:mm:ss.u":return er(e,1);case"hh:mm:ss.uu":return er(e,2);case"hh:mm:ss.uuu":return er(e,3);default:return er(e,3)}}function $d(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const r=parseInt(n[0],10)||0,s=parseInt(n[1],10)||0,o=parseFloat(n[2])||0;return r*3600+s*60+o}default:return 0}}var Fl=({id:e,label:t,value:n,format:r,className:s,onChange:o,readOnly:a=!1})=>{const[i,l]=g.useState("");g.useEffect(()=>{const h=Ln(n,r);l(h)},[n,r,e]);const c=h=>{const d=h.target.value;l(d)},u=()=>{if(o){const h=$d(i,r);o(h)}l(Ln(n,r))},f=h=>{h.key==="Enter"&&h.currentTarget.blur()};return C.jsxs(C.Fragment,{children:[C.jsx(cg,{as:"label",htmlFor:e,children:t}),C.jsx(_d,{type:"text",className:s,id:e,value:i,onChange:c,onBlur:u,onKeyDown:f,readOnly:a})]})},Qg=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:r})=>{const[s,o]=g.useState("hh:mm:ss.uuu");g.useEffect(()=>{const l=document.querySelector(".time-format"),c=()=>{l&&o(l.value)};return l&&(o(l.value),l.addEventListener("change",c)),()=>{l?.removeEventListener("change",c)}},[]);const a=l=>{n&&n(l,t)},i=l=>{n&&n(e,l)};return C.jsxs("div",{className:r,children:[C.jsx(Fl,{id:"audio_start",label:"Start of audio selection",value:e,format:s,className:"audio-start form-control mr-sm-2",onChange:a}),C.jsx(Fl,{id:"audio_end",label:"End of audio selection",value:t,format:s,className:"audio-end form-control mr-sm-2",onChange:i})]})};function ps(){return window.devicePixelRatio}var Rd=g.createContext(ps()),Dd=({children:e})=>{const[t,n]=g.useState(ps());return matchMedia(`(resolution: ${ps()}dppx)`).addEventListener("change",()=>{n(ps())},{once:!0}),C.jsx(Rd.Provider,{value:Math.ceil(t),children:e})},gi=()=>g.useContext(Rd),Nr=g.createContext({sampleRate:48e3,samplesPerPixel:1e3,zoomLevels:[1e3,1500,2e3,2500],waveHeight:80,timeScaleHeight:15,controls:{show:!1,width:150},duration:3e4,barWidth:1,barGap:0}),Hs=()=>g.useContext(Nr),zr=()=>g.useContext(P.ThemeContext);g.createContext(C.jsx(g.Fragment,{}));var ev=0,tv=!1,nv=0,rv=0,sv={progress:ev,isPlaying:tv,selectionStart:nv,selectionEnd:rv};g.createContext(sv);g.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var ov=(e,t,n)=>(e-t)/(n-t),av=P.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
604
+ `,Qg=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopRegionChange:s,minPosition:o=0,maxPosition:a=1/0})=>{const[,i]=g.useState(!1),l=g.useRef(0),c=g.useRef(null),u=t>e,f=g.useCallback(h=>{const d=h.target;if(d.closest("[data-loop-marker-handle]")||d.closest("[data-loop-region-timescale]"))return;h.preventDefault(),i(!0);const p=c.current?.getBoundingClientRect();if(!p)return;const v=h.clientX-p.left,y=Math.max(o,Math.min(a,v));l.current=y,s?.(y,y);const m=_=>{const w=_.clientX-p.left,x=Math.max(o,Math.min(a,w)),S=Math.min(l.current,x),k=Math.max(l.current,x);s?.(S,k)},b=()=>{i(!1),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",b)};document.addEventListener("mousemove",m),document.addEventListener("mouseup",b)},[o,a,s]);return C.jsx(Jg,{ref:c,onMouseDown:f,"data-timescale-loop-creator":!0,children:u&&C.jsx(qg,{startPosition:e,endPosition:t,markerColor:n,regionColor:r,minPosition:o,maxPosition:a,onLoopStartChange:h=>s?.(h,t),onLoopEndChange:h=>s?.(e,h),onLoopRegionMove:(h,d)=>s?.(h,d)})})};function er(e,t){const n=Math.floor(e/3600)%24,r=Math.floor(e/60)%60,s=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(r).padStart(2,"0")+":"+s.padStart(t>0?t+3:2,"0")}function Ln(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return er(e,0);case"hh:mm:ss.u":return er(e,1);case"hh:mm:ss.uu":return er(e,2);case"hh:mm:ss.uuu":return er(e,3);default:return er(e,3)}}function Rd(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const r=parseInt(n[0],10)||0,s=parseInt(n[1],10)||0,o=parseFloat(n[2])||0;return r*3600+s*60+o}default:return 0}}var Pl=({id:e,label:t,value:n,format:r,className:s,onChange:o,readOnly:a=!1})=>{const[i,l]=g.useState("");g.useEffect(()=>{const h=Ln(n,r);l(h)},[n,r,e]);const c=h=>{const d=h.target.value;l(d)},u=()=>{if(o){const h=Rd(i,r);o(h)}l(Ln(n,r))},f=h=>{h.key==="Enter"&&h.currentTarget.blur()};return C.jsxs(C.Fragment,{children:[C.jsx(ug,{as:"label",htmlFor:e,children:t}),C.jsx(xd,{type:"text",className:s,id:e,value:i,onChange:c,onBlur:u,onKeyDown:f,readOnly:a})]})},ev=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:r})=>{const[s,o]=g.useState("hh:mm:ss.uuu");g.useEffect(()=>{const l=document.querySelector(".time-format"),c=()=>{l&&o(l.value)};return l&&(o(l.value),l.addEventListener("change",c)),()=>{l?.removeEventListener("change",c)}},[]);const a=l=>{n&&n(l,t)},i=l=>{n&&n(e,l)};return C.jsxs("div",{className:r,children:[C.jsx(Pl,{id:"audio_start",label:"Start of audio selection",value:e,format:s,className:"audio-start form-control mr-sm-2",onChange:a}),C.jsx(Pl,{id:"audio_end",label:"End of audio selection",value:t,format:s,className:"audio-end form-control mr-sm-2",onChange:i})]})};function ps(){return window.devicePixelRatio}var Dd=g.createContext(ps()),Pd=({children:e})=>{const[t,n]=g.useState(ps());return matchMedia(`(resolution: ${ps()}dppx)`).addEventListener("change",()=>{n(ps())},{once:!0}),C.jsx(Dd.Provider,{value:Math.ceil(t),children:e})},mi=()=>g.useContext(Dd),Nr=g.createContext({sampleRate:48e3,samplesPerPixel:1e3,zoomLevels:[1e3,1500,2e3,2500],waveHeight:80,timeScaleHeight:15,controls:{show:!1,width:150},duration:3e4,barWidth:1,barGap:0}),Hs=()=>g.useContext(Nr),zr=()=>g.useContext(D.ThemeContext);g.createContext(C.jsx(g.Fragment,{}));var tv=0,nv=!1,rv=0,sv=0,ov={progress:tv,isPlaying:nv,selectionStart:rv,selectionEnd:sv};g.createContext(ov);g.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var av=(e,t,n)=>(e-t)/(n-t),iv=D.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
610
605
  position: absolute;
611
606
  background: #000;
612
607
  transform: translateZ(0);
613
608
  backface-visibility: hidden;
614
- `,iv=P.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
609
+ `,lv=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
615
610
  position: absolute;
616
611
  top: 0;
617
612
  image-rendering: pixelated;
618
613
  image-rendering: crisp-edges;
619
- `;function lv(){const e=new Uint8Array(768);for(let t=0;t<256;t++)e[t*3]=e[t*3+1]=e[t*3+2]=t;return e}var cv=lv(),Ol=({index:e,channelIndex:t,data:n,length:r,waveHeight:s,devicePixelRatio:o=1,samplesPerPixel:a,colorLUT:i,frequencyScaleFn:l,minFrequency:c=0,maxFrequency:u,workerApi:f,clipId:h,onCanvasesReady:d})=>{const p=t??e,{canvasRef:v,canvasMapRef:y}=Zs(),m=g.useRef([]),b=g.useRef(new WeakSet),_=g.useRef(f),w=g.useRef(d),x=!!(f&&h),S=hi(),k=js(r,Le,S),E=i??cv,T=u??(n?n.sampleRate/2:22050),I=l??ov,M=!!l;g.useEffect(()=>{_.current=f},[f]),g.useEffect(()=>{w.current=d},[d]),g.useEffect(()=>{if(!x)return;const A=_.current;if(!A||!h)return;const R=m.current.length,W=[];for(const J of m.current){const ee=J.match(/chunk(\d+)$/);if(!ee){W.push(J);continue}const j=parseInt(ee[1],10),se=y.current.get(j);if(se&&se.isConnected)W.push(J);else try{A.unregisterCanvas(J)}catch(U){console.warn(`[spectrogram] unregisterCanvas failed for ${J}:`,U)}}m.current=W;const q=[];for(const[J,ee]of y.current.entries()){if(b.current.has(ee))continue;const j=`${h}-ch${p}-chunk${J}`;let se;try{se=ee.transferControlToOffscreen()}catch(U){console.warn(`[spectrogram] transferControlToOffscreen failed for ${j}:`,U);continue}b.current.add(ee);try{A.registerCanvas(j,se),q.push(j)}catch(U){console.warn(`[spectrogram] registerCanvas failed for ${j}:`,U);continue}}if(q.length>0&&(m.current=[...m.current,...q]),q.length>0||W.length<R){const J=m.current,ee=J.map(j=>{const se=j.match(/chunk(\d+)$/);if(!se)return console.warn(`[spectrogram] Unexpected canvas ID format: ${j}`),Le;const U=parseInt(se[1],10);return Math.min(r-U*Le,Le)});w.current?.(J,ee)}},[y,x,h,p,r,k]),g.useEffect(()=>()=>{const A=_.current;if(A){for(const R of m.current)try{A.unregisterCanvas(R)}catch(W){console.warn(`[spectrogram] unregisterCanvas failed for ${R}:`,W)}m.current=[]}},[]),g.useEffect(()=>{if(x||!n)return;const{frequencyBinCount:A,frameCount:R,hopSize:W,sampleRate:q,gainDb:z,rangeDb:J}=n,ee=J===0?1:J,j=se=>se/A*(q/2);for(const[se,U]of y.current.entries()){const ie=se*Le,le=U.getContext("2d");if(!le)continue;const ge=U.width/o,Se=s;le.resetTransform(),le.clearRect(0,0,U.width,U.height),le.imageSmoothingEnabled=!1,le.scale(o,o);const N=le.createImageData(ge,Se),G=N.data;for(let ye=0;ye<ge;ye++){const Q=(ie+ye)*a,O=Math.floor(Q/W);if(O<0||O>=R)continue;const _e=O*A;for(let Ne=0;Ne<Se;Ne++){const Be=1-Ne/Se;let ve=Math.floor(Be*A);if(M){let xe=0,Fe=A-1;for(;xe<Fe;){const Oe=xe+Fe>>1,Et=j(Oe);I(Et,c,T)<Be?xe=Oe+1:Fe=Oe}ve=xe}if(ve<0||ve>=A)continue;const Ve=n.data[_e+ve],ne=Math.max(0,Math.min(1,(Ve+ee+z)/ee)),Ge=Math.floor(ne*255),je=(Ne*ge+ye)*4;G[je]=E[Ge*3],G[je+1]=E[Ge*3+1],G[je+2]=E[Ge*3+2],G[je+3]=255}}if(le.resetTransform(),le.putImageData(N,0,0),o!==1){const ye=document.createElement("canvas");ye.width=ge,ye.height=Se;const Z=ye.getContext("2d");if(!Z)continue;Z.putImageData(N,0,0),le.clearRect(0,0,U.width,U.height),le.imageSmoothingEnabled=!1,le.drawImage(ye,0,0,U.width,U.height)}}},[y,x,n,r,s,o,a,E,c,T,I,M,k]);const $=k.map(A=>{const R=A*Le,W=Math.min(r-R,Le);return C.jsx(iv,{$cssWidth:W,$left:R,width:W*o,height:s*o,$waveHeight:s,"data-index":A,ref:v},`${r}-${A}`)});return C.jsx(av,{$index:e,$cssWidth:r,$waveHeight:s,children:$})},Pd=({isSelected:e,transparentBackground:t,renderMode:n="waveform",spectrogramData:r,spectrogramColorLUT:s,samplesPerPixel:o,spectrogramFrequencyScaleFn:a,spectrogramMinFrequency:i,spectrogramMaxFrequency:l,spectrogramWorkerApi:c,spectrogramClipId:u,spectrogramOnCanvasesReady:f,midiNotes:h,sampleRate:d,clipOffsetSeconds:p,...v})=>{const y=zr(),{waveHeight:m,barWidth:b,barGap:_,samplesPerPixel:w,sampleRate:x}=Hs(),S=gi(),k=o??w,E=e&&y?y.selectedWaveOutlineColor:y?.waveOutlineColor,T=e&&y?y.selectedWaveFillColor:y?.waveFillColor,I=y?.waveformDrawMode||"inverted",M=r||c;if(n==="spectrogram"&&M)return C.jsx(Ol,{index:v.index,data:r,length:v.length,waveHeight:m,devicePixelRatio:S,samplesPerPixel:k,colorLUT:s,frequencyScaleFn:a,minFrequency:i,maxFrequency:l,workerApi:c,clipId:u,onCanvasesReady:f});if(n==="both"&&M){const $=Math.floor(m/2);return C.jsxs(C.Fragment,{children:[C.jsx(Ol,{index:v.index*2,channelIndex:v.index,data:r,length:v.length,waveHeight:$,devicePixelRatio:S,samplesPerPixel:k,colorLUT:s,frequencyScaleFn:a,minFrequency:i,maxFrequency:l,workerApi:c,clipId:u,onCanvasesReady:f}),C.jsx("div",{style:{position:"absolute",top:(v.index*2+1)*$,width:v.length,height:$},children:C.jsx($l,{...v,index:0,waveOutlineColor:E,waveFillColor:T,waveHeight:$,devicePixelRatio:S,barWidth:b,barGap:_,transparentBackground:t,drawMode:I})})]})}return n==="piano-roll"?C.jsx(Bg,{index:v.index,midiNotes:h??[],length:v.length,waveHeight:m,devicePixelRatio:S,samplesPerPixel:k,sampleRate:d??x,clipOffsetSeconds:p??0,noteColor:y?.pianoRollNoteColor,selectedNoteColor:y?.pianoRollSelectedNoteColor,isSelected:e,transparentBackground:t,backgroundColor:y?.pianoRollBackgroundColor}):C.jsx($l,{...v,waveOutlineColor:E,waveFillColor:T,waveHeight:m,devicePixelRatio:S,barWidth:b,barGap:_,transparentBackground:t,drawMode:I})},Ll=72,uv=P.div`
614
+ `;function cv(){const e=new Uint8Array(768);for(let t=0;t<256;t++)e[t*3]=e[t*3+1]=e[t*3+2]=t;return e}var uv=cv(),Fl=({index:e,channelIndex:t,data:n,length:r,waveHeight:s,devicePixelRatio:o=1,samplesPerPixel:a,colorLUT:i,frequencyScaleFn:l,minFrequency:c=0,maxFrequency:u,workerApi:f,clipId:h,onCanvasesReady:d})=>{const p=t??e,{canvasRef:v,canvasMapRef:y}=Zs(),m=g.useRef([]),b=g.useRef(new WeakSet),_=g.useRef(f),w=g.useRef(d),x=!!(f&&h),S=fi(),k=js(r,Le,S),E=i??uv,M=u??(n?n.sampleRate/2:22050),I=l??av,T=!!l;g.useEffect(()=>{_.current=f},[f]),g.useEffect(()=>{w.current=d},[d]),g.useEffect(()=>{if(!x)return;const A=_.current;if(!A||!h)return;const P=m.current.length,W=[];for(const Q of m.current){const ee=Q.match(/chunk(\d+)$/);if(!ee){W.push(Q);continue}const z=parseInt(ee[1],10),se=y.current.get(z);if(se&&se.isConnected)W.push(Q);else try{A.unregisterCanvas(Q)}catch(U){console.warn(`[spectrogram] unregisterCanvas failed for ${Q}:`,U)}}m.current=W;const J=[];for(const[Q,ee]of y.current.entries()){if(b.current.has(ee))continue;const z=`${h}-ch${p}-chunk${Q}`;let se;try{se=ee.transferControlToOffscreen()}catch(U){console.warn(`[spectrogram] transferControlToOffscreen failed for ${z}:`,U);continue}b.current.add(ee);try{A.registerCanvas(z,se),J.push(z)}catch(U){console.warn(`[spectrogram] registerCanvas failed for ${z}:`,U);continue}}if(J.length>0&&(m.current=[...m.current,...J]),J.length>0||W.length<P){const Q=m.current,ee=Q.map(z=>{const se=z.match(/chunk(\d+)$/);if(!se)return console.warn(`[spectrogram] Unexpected canvas ID format: ${z}`),Le;const U=parseInt(se[1],10);return Math.min(r-U*Le,Le)});w.current?.(Q,ee)}},[y,x,h,p,r,k]),g.useEffect(()=>()=>{const A=_.current;if(A){for(const P of m.current)try{A.unregisterCanvas(P)}catch(W){console.warn(`[spectrogram] unregisterCanvas failed for ${P}:`,W)}m.current=[]}},[]),g.useEffect(()=>{if(x||!n)return;const{frequencyBinCount:A,frameCount:P,hopSize:W,sampleRate:J,gainDb:G,rangeDb:Q}=n,ee=Q===0?1:Q,z=se=>se/A*(J/2);for(const[se,U]of y.current.entries()){const ie=se*Le,le=U.getContext("2d");if(!le)continue;const ge=U.width/o,Se=s;le.resetTransform(),le.clearRect(0,0,U.width,U.height),le.imageSmoothingEnabled=!1,le.scale(o,o);const N=le.createImageData(ge,Se),H=N.data;for(let ye=0;ye<ge;ye++){const q=(ie+ye)*a,O=Math.floor(q/W);if(O<0||O>=P)continue;const _e=O*A;for(let Ne=0;Ne<Se;Ne++){const Be=1-Ne/Se;let ve=Math.floor(Be*A);if(T){let xe=0,Fe=A-1;for(;xe<Fe;){const Oe=xe+Fe>>1,Et=z(Oe);I(Et,c,M)<Be?xe=Oe+1:Fe=Oe}ve=xe}if(ve<0||ve>=A)continue;const Ve=n.data[_e+ve],ne=Math.max(0,Math.min(1,(Ve+ee+G)/ee)),Ge=Math.floor(ne*255),je=(Ne*ge+ye)*4;H[je]=E[Ge*3],H[je+1]=E[Ge*3+1],H[je+2]=E[Ge*3+2],H[je+3]=255}}if(le.resetTransform(),le.putImageData(N,0,0),o!==1){const ye=document.createElement("canvas");ye.width=ge,ye.height=Se;const j=ye.getContext("2d");if(!j)continue;j.putImageData(N,0,0),le.clearRect(0,0,U.width,U.height),le.imageSmoothingEnabled=!1,le.drawImage(ye,0,0,U.width,U.height)}}},[y,x,n,r,s,o,a,E,c,M,I,T,k]);const $=k.map(A=>{const P=A*Le,W=Math.min(r-P,Le);return C.jsx(lv,{$cssWidth:W,$left:P,width:W*o,height:s*o,$waveHeight:s,"data-index":A,ref:v},`${r}-${A}`)});return C.jsx(iv,{$index:e,$cssWidth:r,$waveHeight:s,children:$})},Fd=({isSelected:e,transparentBackground:t,renderMode:n="waveform",spectrogramData:r,spectrogramColorLUT:s,samplesPerPixel:o,spectrogramFrequencyScaleFn:a,spectrogramMinFrequency:i,spectrogramMaxFrequency:l,spectrogramWorkerApi:c,spectrogramClipId:u,spectrogramOnCanvasesReady:f,midiNotes:h,sampleRate:d,clipOffsetSeconds:p,...v})=>{const y=zr(),{waveHeight:m,barWidth:b,barGap:_,samplesPerPixel:w,sampleRate:x}=Hs(),S=mi(),k=o??w,E=e&&y?y.selectedWaveOutlineColor:y?.waveOutlineColor,M=e&&y?y.selectedWaveFillColor:y?.waveFillColor,I=y?.waveformDrawMode||"inverted",T=r||c;if(n==="spectrogram"&&T)return C.jsx(Fl,{index:v.index,data:r,length:v.length,waveHeight:m,devicePixelRatio:S,samplesPerPixel:k,colorLUT:s,frequencyScaleFn:a,minFrequency:i,maxFrequency:l,workerApi:c,clipId:u,onCanvasesReady:f});if(n==="both"&&T){const $=Math.floor(m/2);return C.jsxs(C.Fragment,{children:[C.jsx(Fl,{index:v.index*2,channelIndex:v.index,data:r,length:v.length,waveHeight:$,devicePixelRatio:S,samplesPerPixel:k,colorLUT:s,frequencyScaleFn:a,minFrequency:i,maxFrequency:l,workerApi:c,clipId:u,onCanvasesReady:f}),C.jsx("div",{style:{position:"absolute",top:(v.index*2+1)*$,width:v.length,height:$},children:C.jsx(Tl,{...v,index:0,waveOutlineColor:E,waveFillColor:M,waveHeight:$,devicePixelRatio:S,barWidth:b,barGap:_,transparentBackground:t,drawMode:I})})]})}return n==="piano-roll"?C.jsx(Vg,{index:v.index,midiNotes:h??[],length:v.length,waveHeight:m,devicePixelRatio:S,samplesPerPixel:k,sampleRate:d??x,clipOffsetSeconds:p??0,noteColor:y?.pianoRollNoteColor,selectedNoteColor:y?.pianoRollSelectedNoteColor,isSelected:e,transparentBackground:t,backgroundColor:y?.pianoRollBackgroundColor}):C.jsx(Tl,{...v,waveOutlineColor:E,waveFillColor:M,waveHeight:m,devicePixelRatio:S,barWidth:b,barGap:_,transparentBackground:t,drawMode:I})},Ol=72,dv=D.div`
620
615
  position: sticky;
621
616
  left: 0;
622
617
  z-index: 101;
@@ -624,31 +619,31 @@
624
619
  height: 0;
625
620
  width: 0;
626
621
  overflow: visible;
627
- `;function dv(e,t,n){const s=[20,50,100,200,500,1e3,2e3,3e3,4e3,5e3,8e3,1e4,12e3,16e3,2e4].filter(l=>l>=e&&l<=t),o=Math.max(2,Math.floor(n/20));if(s.length<=o)return s;const a=(s.length-1)/(o-1),i=[];for(let l=0;l<o;l++)i.push(s[Math.round(l*a)]);return i}var fv=({waveHeight:e,numChannels:t,frequencyScaleFn:n,minFrequency:r,maxFrequency:s,labelsColor:o="#ccc",labelsBackground:a="rgba(0,0,0,0.6)",renderMode:i="spectrogram",hasClipHeaders:l=!1})=>{const c=g.useRef(null),u=gi(),f=i==="both"?Math.floor(e/2):e,h=t*e,d=l?22:0;return g.useLayoutEffect(()=>{const p=c.current;if(!p)return;const v=p.getContext("2d");if(!v)return;v.resetTransform(),v.clearRect(0,0,p.width,p.height),v.scale(u,u);const y=dv(r,s,f);for(let m=0;m<t;m++){const b=m*e+d;v.font="11px monospace",v.textBaseline="middle";for(const _ of y){const w=n(_,r,s);if(w<0||w>1)continue;const x=b+f*(1-w),S=_>=1e3?`${(_/1e3).toFixed(1)}k`:`${_} Hz`,k=v.measureText(S),E=3;v.fillStyle=a,v.fillRect(0,x-7,k.width+E*2,14),v.fillStyle=o,v.fillText(S,E,x)}}},[e,t,n,r,s,o,a,u,f,d]),C.jsx(uv,{$height:h+d,children:C.jsx("canvas",{ref:c,width:Ll*u,height:(h+d)*u,style:{width:Ll,height:h+d,pointerEvents:"none"}})})};function hv(e,t,n){return Math.ceil(e*n/t)}function pv(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var mv=P.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
622
+ `;function fv(e,t,n){const s=[20,50,100,200,500,1e3,2e3,3e3,4e3,5e3,8e3,1e4,12e3,16e3,2e4].filter(l=>l>=e&&l<=t),o=Math.max(2,Math.floor(n/20));if(s.length<=o)return s;const a=(s.length-1)/(o-1),i=[];for(let l=0;l<o;l++)i.push(s[Math.round(l*a)]);return i}var hv=({waveHeight:e,numChannels:t,frequencyScaleFn:n,minFrequency:r,maxFrequency:s,labelsColor:o="#ccc",labelsBackground:a="rgba(0,0,0,0.6)",renderMode:i="spectrogram",hasClipHeaders:l=!1})=>{const c=g.useRef(null),u=mi(),f=i==="both"?Math.floor(e/2):e,h=t*e,d=l?22:0;return g.useLayoutEffect(()=>{const p=c.current;if(!p)return;const v=p.getContext("2d");if(!v)return;v.resetTransform(),v.clearRect(0,0,p.width,p.height),v.scale(u,u);const y=fv(r,s,f);for(let m=0;m<t;m++){const b=m*e+d;v.font="11px monospace",v.textBaseline="middle";for(const _ of y){const w=n(_,r,s);if(w<0||w>1)continue;const x=b+f*(1-w),S=_>=1e3?`${(_/1e3).toFixed(1)}k`:`${_} Hz`,k=v.measureText(S),E=3;v.fillStyle=a,v.fillRect(0,x-7,k.width+E*2,14),v.fillStyle=o,v.fillText(S,E,x)}}},[e,t,n,r,s,o,a,u,f,d]),C.jsx(dv,{$height:h+d,children:C.jsx("canvas",{ref:c,width:Ol*u,height:(h+d)*u,style:{width:Ol,height:h+d,pointerEvents:"none"}})})};function pv(e,t,n){return Math.ceil(e*n/t)}function mv(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var gv=D.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
628
623
  position: relative;
629
624
  overflow: visible; /* Allow time labels to render above the container */
630
625
  border-bottom: 1px solid ${e=>e.theme.timeColor};
631
626
  box-sizing: border-box;
632
- `,gv=P.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`,left:`${e.$left}px`}}))`
627
+ `,vv=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`,left:`${e.$left}px`}}))`
633
628
  position: absolute;
634
629
  bottom: 0;
635
- `,vv=P.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
630
+ `,yv=D.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
636
631
  position: absolute;
637
632
  font-size: 0.75rem; /* Smaller font to prevent overflow */
638
633
  white-space: nowrap; /* Prevent text wrapping */
639
634
  color: ${e=>e.theme.timeColor}; /* Use theme color instead of inheriting */
640
- `,yv=e=>{const{theme:{timeColor:t},duration:n,marker:r,bigStep:s,secondStep:o,renderTimestamp:a}=e,{canvasRef:i,canvasMapRef:l}=Zs(),{sampleRate:c,samplesPerPixel:u,timeScaleHeight:f}=g.useContext(Nr),h=gi(),{widthX:d,canvasInfo:p,timeMarkersWithPositions:v}=g.useMemo(()=>{const x=new Map,S=[],k=hv(n/1e3,u,c),E=c/u;let T=0;for(let I=0;I<k;I+=E*o/1e3){const M=Math.floor(I);if(T%r===0){const $=T,A=pv($),R=a?C.jsx(g.Fragment,{children:a($,M)},`timestamp-${T}`):C.jsx(vv,{$left:M,children:A},A);S.push({pix:M,element:R}),x.set(M,f)}else T%s===0?x.set(M,Math.floor(f/2)):T%o===0&&x.set(M,Math.floor(f/5));T+=o}return{widthX:k,canvasInfo:x,timeMarkersWithPositions:S}},[n,u,c,r,s,o,a,f]),y=js(d,Le),m=y.map(x=>{const S=x*Le,k=Math.min(d-S,Le);return C.jsx(gv,{$cssWidth:k,$left:S,$timeScaleHeight:f,width:k*h,height:f*h,"data-index":x,ref:i},`timescale-${x}`)}),b=y.length>0?y[0]*Le:0,_=y.length>0?(y[y.length-1]+1)*Le:1/0,w=y.length>0?v.filter(({pix:x})=>x>=b&&x<_).map(({element:x})=>x):v.map(({element:x})=>x);return g.useLayoutEffect(()=>{for(const[x,S]of l.current.entries()){const k=S.getContext("2d");if(!k)continue;const E=x*Le,T=S.width/h;k.resetTransform(),k.clearRect(0,0,S.width,S.height),k.imageSmoothingEnabled=!1,k.fillStyle=t,k.scale(h,h);for(const[I,M]of p.entries()){if(I<E||I>=E+T)continue;const $=I-E,A=f-M;k.fillRect($,A,1,M)}}},[l,n,h,t,f,p,y]),C.jsxs(mv,{$cssWidth:d,$timeScaleHeight:f,children:[w,m]})},bv=P.withTheme(yv),Wl=new Map([[700,{marker:1e3,bigStep:500,smallStep:100}],[1500,{marker:2e3,bigStep:1e3,smallStep:200}],[2500,{marker:2e3,bigStep:1e3,smallStep:500}],[5e3,{marker:5e3,bigStep:1e3,smallStep:500}],[1e4,{marker:1e4,bigStep:5e3,smallStep:1e3}],[12e3,{marker:15e3,bigStep:5e3,smallStep:1e3}],[1/0,{marker:3e4,bigStep:1e4,smallStep:5e3}]]);function wv(e){const t=Wl.keys();let n;for(const r of t)if(e<r){n=Wl.get(r);break}return n===void 0&&(n={marker:3e4,bigStep:1e4,smallStep:5e3}),n}var Fd=({renderTimestamp:e})=>{const{samplesPerPixel:t,duration:n}=g.useContext(Nr);let r=wv(t);return C.jsx(bv,{marker:r.marker,bigStep:r.bigStep,secondStep:r.smallStep,duration:n,renderTimestamp:e})},_v=P.div`
635
+ `,bv=e=>{const{theme:{timeColor:t},duration:n,marker:r,bigStep:s,secondStep:o,renderTimestamp:a}=e,{canvasRef:i,canvasMapRef:l}=Zs(),{sampleRate:c,samplesPerPixel:u,timeScaleHeight:f}=g.useContext(Nr),h=mi(),{widthX:d,canvasInfo:p,timeMarkersWithPositions:v}=g.useMemo(()=>{const x=new Map,S=[],k=pv(n/1e3,u,c),E=c/u;let M=0;for(let I=0;I<k;I+=E*o/1e3){const T=Math.floor(I);if(M%r===0){const $=M,A=mv($),P=a?C.jsx(g.Fragment,{children:a($,T)},`timestamp-${M}`):C.jsx(yv,{$left:T,children:A},A);S.push({pix:T,element:P}),x.set(T,f)}else M%s===0?x.set(T,Math.floor(f/2)):M%o===0&&x.set(T,Math.floor(f/5));M+=o}return{widthX:k,canvasInfo:x,timeMarkersWithPositions:S}},[n,u,c,r,s,o,a,f]),y=js(d,Le),m=y.map(x=>{const S=x*Le,k=Math.min(d-S,Le);return C.jsx(vv,{$cssWidth:k,$left:S,$timeScaleHeight:f,width:k*h,height:f*h,"data-index":x,ref:i},`timescale-${x}`)}),b=y.length>0?y[0]*Le:0,_=y.length>0?(y[y.length-1]+1)*Le:1/0,w=y.length>0?v.filter(({pix:x})=>x>=b&&x<_).map(({element:x})=>x):v.map(({element:x})=>x);return g.useLayoutEffect(()=>{for(const[x,S]of l.current.entries()){const k=S.getContext("2d");if(!k)continue;const E=x*Le,M=S.width/h;k.resetTransform(),k.clearRect(0,0,S.width,S.height),k.imageSmoothingEnabled=!1,k.fillStyle=t,k.scale(h,h);for(const[I,T]of p.entries()){if(I<E||I>=E+M)continue;const $=I-E,A=f-T;k.fillRect($,A,1,T)}}},[l,n,h,t,f,p,y]),C.jsxs(gv,{$cssWidth:d,$timeScaleHeight:f,children:[w,m]})},wv=D.withTheme(bv),Ll=new Map([[700,{marker:1e3,bigStep:500,smallStep:100}],[1500,{marker:2e3,bigStep:1e3,smallStep:200}],[2500,{marker:2e3,bigStep:1e3,smallStep:500}],[5e3,{marker:5e3,bigStep:1e3,smallStep:500}],[1e4,{marker:1e4,bigStep:5e3,smallStep:1e3}],[12e3,{marker:15e3,bigStep:5e3,smallStep:1e3}],[1/0,{marker:3e4,bigStep:1e4,smallStep:5e3}]]);function _v(e){const t=Ll.keys();let n;for(const r of t)if(e<r){n=Ll.get(r);break}return n===void 0&&(n={marker:3e4,bigStep:1e4,smallStep:5e3}),n}var Od=({renderTimestamp:e})=>{const{samplesPerPixel:t,duration:n}=g.useContext(Nr);let r=_v(t);return C.jsx(wv,{marker:r.marker,bigStep:r.bigStep,secondStep:r.smallStep,duration:n,renderTimestamp:e})},xv=D.div`
641
636
  display: inline-flex;
642
637
  align-items: center;
643
638
  gap: 0.5rem;
644
- `,xv=[{value:"seconds",label:"seconds"},{value:"thousandths",label:"thousandths"},{value:"hh:mm:ss",label:"hh:mm:ss"},{value:"hh:mm:ss.u",label:"hh:mm:ss + tenths"},{value:"hh:mm:ss.uu",label:"hh:mm:ss + hundredths"},{value:"hh:mm:ss.uuu",label:"hh:mm:ss + milliseconds"}],Cv=({value:e,onChange:t,disabled:n=!1,className:r})=>{const s=o=>{t(o.target.value)};return C.jsx(_v,{className:r,children:C.jsx(xd,{className:"time-format",value:e,onChange:s,disabled:n,"aria-label":"Time format selection",children:xv.map(o=>C.jsx("option",{value:o.value,children:o.label},o.value))})})},Sv=P.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?pi:0)}px`}}))`
639
+ `,Cv=[{value:"seconds",label:"seconds"},{value:"thousandths",label:"thousandths"},{value:"hh:mm:ss",label:"hh:mm:ss"},{value:"hh:mm:ss.u",label:"hh:mm:ss + tenths"},{value:"hh:mm:ss.uu",label:"hh:mm:ss + hundredths"},{value:"hh:mm:ss.uuu",label:"hh:mm:ss + milliseconds"}],Sv=({value:e,onChange:t,disabled:n=!1,className:r})=>{const s=o=>{t(o.target.value)};return C.jsx(xv,{className:r,children:C.jsx(Cd,{className:"time-format",value:e,onChange:s,disabled:n,"aria-label":"Time format selection",children:Cv.map(o=>C.jsx("option",{value:o.value,children:o.label},o.value))})})},kv=D.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?hi:0)}px`}}))`
645
640
  position: relative;
646
641
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
647
- `,kv=P.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
642
+ `,Ev=D.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
648
643
  position: relative;
649
644
  background: ${e=>e.$backgroundColor||"transparent"};
650
645
  height: 100%;
651
- `,Od=({numChannels:e,children:t,className:n,backgroundColor:r,offset:s=0,width:o,hasClipHeaders:a=!1,onClick:i,trackId:l,isSelected:c=!1})=>{const{waveHeight:u}=Hs();return C.jsx(Sv,{$numChannels:e,className:n,$waveHeight:u,$width:o,$hasClipHeaders:a,children:C.jsx(kv,{$backgroundColor:r,$offset:s,onClick:i,"data-track-id":l,children:t})})},Bl=P.button.attrs({type:"button"})`
646
+ `,Ld=({numChannels:e,children:t,className:n,backgroundColor:r,offset:s=0,width:o,hasClipHeaders:a=!1,onClick:i,trackId:l,isSelected:c=!1})=>{const{waveHeight:u}=Hs();return C.jsx(kv,{$numChannels:e,className:n,$waveHeight:u,$width:o,$hasClipHeaders:a,children:C.jsx(Ev,{$backgroundColor:r,$offset:s,onClick:i,"data-track-id":l,children:t})})},Wl=D.button.attrs({type:"button"})`
652
647
  display: inline-block;
653
648
  font-family: ${e=>e.theme.fontFamily};
654
649
  font-weight: 500;
@@ -710,7 +705,7 @@
710
705
  box-shadow: 0 0 0 0.2rem ${e.theme.inputFocusBorder}33;
711
706
  }
712
707
  `}
713
- `,Ev=P.div`
708
+ `,Iv=D.div`
714
709
  margin-bottom: 0.3rem;
715
710
 
716
711
  button:not(:first-child) {
@@ -722,7 +717,7 @@
722
717
  border-top-right-radius: 0;
723
718
  border-bottom-right-radius: 0;
724
719
  }
725
- `,Iv=P.button`
720
+ `,Mv=D.button`
726
721
  position: absolute;
727
722
  left: 0;
728
723
  top: 0;
@@ -744,7 +739,7 @@
744
739
  opacity: 1;
745
740
  color: #dc3545;
746
741
  }
747
- `,Mv=({onClick:e,title:t="Remove track"})=>C.jsx(Iv,{onClick:e,title:t,children:C.jsx(sg,{size:12,weight:"bold"})}),Av=P.div`
742
+ `,Av=({onClick:e,title:t="Remove track"})=>C.jsx(Mv,{onClick:e,title:t,children:C.jsx(og,{size:12,weight:"bold"})}),Tv=D.div`
748
743
  background: transparent;
749
744
  width: 100%;
750
745
  height: 100%;
@@ -757,7 +752,7 @@
757
752
  text-align: center;
758
753
  border: 1px solid ${e=>e.theme.borderColor};
759
754
  border-radius: ${e=>e.theme.borderRadius};
760
- `,Tv=P.header`
755
+ `,$v=D.header`
761
756
  overflow: hidden;
762
757
  height: 26px;
763
758
  width: 100%;
@@ -768,7 +763,7 @@
768
763
  font-size: ${e=>e.theme.fontSizeSmall};
769
764
  color: ${e=>e.theme.textColor};
770
765
  background-color: transparent;
771
- `,$v=e=>C.jsx(bd,{weight:"light",...e}),Rv=e=>C.jsx(yd,{weight:"light",...e}),Dv=e=>C.jsx(vd,{weight:"bold",...e}),Vl=P(Cd)`
766
+ `,Rv=e=>C.jsx(wd,{weight:"light",...e}),Dv=e=>C.jsx(bd,{weight:"light",...e}),Pv=e=>C.jsx(yd,{weight:"bold",...e}),Bl=D(Sd)`
772
767
  width: 75%;
773
768
  height: 5px;
774
769
  background: ${e=>e.theme.sliderTrackColor};
@@ -817,7 +812,7 @@
817
812
  &:focus::-moz-range-thumb {
818
813
  border: 2px solid ${e=>e.theme.textColor};
819
814
  }
820
- `,Nl=P.label`
815
+ `,Vl=D.label`
821
816
  width: 100%;
822
817
  display: flex;
823
818
  justify-content: space-between;
@@ -825,10 +820,10 @@
825
820
  padding: 0 1rem;
826
821
  margin-bottom: 0.2rem;
827
822
  font-size: 14px;
828
- `,Pv=P.div`
823
+ `,Fv=D.div`
829
824
  position: relative;
830
825
  display: inline-block;
831
- `,Fv=P.button`
826
+ `,Ov=D.button`
832
827
  background: none;
833
828
  border: none;
834
829
  cursor: pointer;
@@ -842,7 +837,7 @@
842
837
  &:hover {
843
838
  opacity: 1;
844
839
  }
845
- `,ms=180,Ov=P.div`
840
+ `,ms=180,Lv=D.div`
846
841
  position: fixed;
847
842
  top: ${e=>e.$top}px;
848
843
  left: ${e=>e.$left}px;
@@ -854,12 +849,12 @@
854
849
  padding: 0.5rem 0;
855
850
  min-width: ${ms}px;
856
851
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
857
- `,Lv=P.hr`
852
+ `,Wv=D.hr`
858
853
  border: none;
859
854
  border-top: 1px solid rgba(128, 128, 128, 0.3);
860
855
  margin: 0.35rem 0;
861
- `,Wv=({items:e})=>{const[t,n]=g.useState(!1),r=g.useCallback(()=>n(!1),[]),s=typeof e=="function"?e(r):e,[o,a]=g.useState({top:0,left:0}),i=g.useRef(null),l=g.useRef(null),c=g.useCallback(()=>{if(!i.current)return;const u=i.current.getBoundingClientRect(),f=window.innerWidth,h=window.innerHeight,d=l.current?.offsetHeight??160;let p=u.right+4;p+ms>f&&(p=u.left-ms-4),p=Math.max(4,Math.min(p,f-ms-4));let v=u.top;v+d>h-4&&(v=Math.max(4,u.bottom-d)),a({top:v,left:p})},[]);return g.useEffect(()=>{if(!t)return;c();const u=requestAnimationFrame(()=>c()),f=()=>c(),h=()=>c();return window.addEventListener("scroll",f,!0),window.addEventListener("resize",h),()=>{cancelAnimationFrame(u),window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",h)}},[t,c]),g.useEffect(()=>{if(!t)return;const u=h=>{const d=h.target;i.current&&!i.current.contains(d)&&l.current&&!l.current.contains(d)&&n(!1)},f=h=>{h.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",u),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",f)}},[t]),C.jsxs(Pv,{children:[C.jsx(Fv,{ref:i,onClick:u=>{u.stopPropagation(),n(f=>!f)},onMouseDown:u=>u.stopPropagation(),title:"Track menu","aria-label":"Track menu",children:C.jsx(Dv,{size:16})}),t&&typeof document<"u"&&da.createPortal(C.jsx(Ov,{ref:l,$top:o.top,$left:o.left,onMouseDown:u=>u.stopPropagation(),children:s.map((u,f)=>C.jsxs(g.Fragment,{children:[f>0&&C.jsx(Lv,{}),u.content]},u.id))}),document.body)]})};function Cn(e,t){this._waveformData=e,this._channelIndex=t}Cn.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};Cn.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};Cn.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};Cn.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};Cn.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};Cn.prototype.max_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.max_sample(n));return t};var Bv=127,Vv=-128,Nv=32767,zv=-32768;function jv(e,t){var n=Math.floor(e/t),r=e-n*t;return r>0&&n++,n}function Zv(e){for(var t=e.scale,n=e.amplitude_scale,r=e.split_channels,s=e.length,o=e.sample_rate,a=e.channels.map(function(M){return new Float32Array(M)}),i=r?a.length:1,l=24,c=jv(s,t),u=e.bits===8?1:2,f=l+c*2*u*i,h=new ArrayBuffer(f),d=new DataView(h),p=0,v=l,y=new Array(i),m=new Array(i),b=0;b<i;b++)y[b]=1/0,m[b]=-1/0;var _=e.bits===8?Vv:zv,w=e.bits===8?Bv:Nv;d.setInt32(0,2,!0),d.setUint32(4,e.bits===8,!0),d.setInt32(8,o,!0),d.setInt32(12,t,!0),d.setInt32(16,c,!0),d.setInt32(20,i,!0);for(var x=0;x<s;x++){var S=0;if(i===1){for(var k=0;k<a.length;++k)S+=a[k][x];S=Math.floor(w*S*n/a.length),S<y[0]&&(y[0]=S,y[0]<_&&(y[0]=_)),S>m[0]&&(m[0]=S,m[0]>w&&(m[0]=w))}else for(var E=0;E<i;++E)S=Math.floor(w*a[E][x]*n),S<y[E]&&(y[E]=S,y[E]<_&&(y[E]=_)),S>m[E]&&(m[E]=S,m[E]>w&&(m[E]=w));if(++p===t){for(var T=0;T<i;T++)e.bits===8?(d.setInt8(v++,y[T]),d.setInt8(v++,m[T])):(d.setInt16(v,y[T],!0),d.setInt16(v+2,m[T],!0),v+=4),y[T]=1/0,m[T]=-1/0;p=0}}if(p>0)for(var I=0;I<i;I++)e.bits===8?(d.setInt8(v++,y[I]),d.setInt8(v++,m[I])):(d.setInt16(v,y[I],!0),d.setInt16(v+2,m[I],!0));return h}function Rs(e){"@babel/helpers - typeof";return Rs=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Rs(e)}function Hv(e){return e&&Rs(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Gv(e){var t=e&&Rs(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),r=n.getInt32(0,!0);if(r!==1&&r!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function Uv(e){var t=e.data,n=e.channels||1,r=24,s=e.bits===8?1:2,o=e.length*2*n;if(t.length!==o)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var a=r+t.length*s,i=new ArrayBuffer(a),l=new DataView(i);l.setInt32(0,2,!0),l.setUint32(4,e.bits===8,!0),l.setInt32(8,e.sample_rate,!0),l.setInt32(12,e.samples_per_pixel,!0),l.setInt32(16,e.length,!0),l.setInt32(20,n,!0);var c=r;if(e.bits===8)for(var u=0;u<t.length;u++)l.setInt8(c++,t[u],!0);else for(var f=0;f<t.length;f++)l.setInt16(c,t[f],!0),c+=2;return i}function Mn(e){return e==null}function Xv(e,t){var n=atob(e);return n}function Yv(e,t,n){var r=Xv(e),s=r.indexOf(`
862
- `,10)+1,o=r.substring(s)+"",a=new Blob([o],{type:"application/javascript"});return URL.createObjectURL(a)}function Kv(e,t,n){var r;return function(o){return r=r||Yv(e),new Worker(r,o)}}var qv=Kv("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function mt(e){if(Hv(e)&&(e=Uv(e)),Gv(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new Cn(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var tr={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function Jv(e){var t={scale:e.scale||tr.scale,bits:e.bits||tr.bits,amplitude_scale:e.amplitude_scale||tr.amplitude_scale,split_channels:e.split_channels||tr.split_channels,disable_worker:e.disable_worker||tr.disable_worker};return t}function Qv(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Ld(e,t,n){var r=Qv(e);if(t.disable_worker){var s=Zv({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r});n(void 0,new mt(s),e)}else{var o=new qv;o.onmessage=function(a){n(void 0,new mt(a.data),e)},o.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r},r)}}function e0(e,t,n,r){function s(a){a||(a=new DOMException("EncodingError")),r(a),r=function(){}}var o=e.decodeAudioData(t,function(a){Ld(a,n,r)},s);o&&o.catch(s)}mt.create=function(t){return new mt(t)};mt.createFromAudio=function(e,t){var n=Jv(e);if(e.audio_context&&e.array_buffer)return e0(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Ld(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Gs(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),r=24,s=this._inputData.bits===8?1:2,o=r+n*2*this._inputData.channels*s;this._output_data=new ArrayBuffer(o),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new mt(this._output_data),this._input_index=0,this._output_index=0;var a=this._inputData.channels;this._min=new Array(a),this._max=new Array(a);for(var i=0;i<a;++i)this._input_buffer_size>0?(this._min[i]=this._inputData.channel(i).min_sample(this._input_index),this._max[i]=this._inputData.channel(i).max_sample(this._input_index)):(this._min[i]=0,this._max[i]=0);this._min_value=this._inputData.bits===8?-128:-32768,this._max_value=this._inputData.bits===8?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}Gs.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Gs.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,r;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var s=0;s<n;++s)r=this._outputWaveformData.channel(s),r.set_min_sample(this._output_index-1,this._min[s]),r.set_max_sample(this._output_index-1,this._max[s]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var o=0;o<n;++o)this._min[o]=this._max_value,this._max[o]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var a=0;a<n;++a){r=this._inputData.channel(a);var i=r.min_sample(this._input_index);i<this._min[a]&&(this._min[a]=i),i=r.max_sample(this._input_index),i>this._max[a]&&(this._max[a]=i)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var l=0;l<n;++l)r=this._outputWaveformData.channel(l),r.set_min_sample(this._output_index-1,this._min[l]),r.set_max_sample(this._output_index-1,this._max[l]);return!0};Gs.prototype.getOutputData=function(){return this._output_data};mt.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!Mn(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!Mn(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new Gs(t);!n.next(););return new mt(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(s){if(t.channels!==s.channels||t.sample_rate!==s.sample_rate||t.bits!==s.bits||t.scale!==s.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var r=this._concatBuffers.apply(this,n);return mt.create(r)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,r=n,s=0,o=[this].concat(t).map(function(m){return m._data.buffer}),a=0;a<o.length;a++){var i=o[a],l=new DataView(i).getInt32(16,!0);r+=i.byteLength-n,s+=l}for(var c=new ArrayBuffer(r),u=new DataView(o[0]),f=new DataView(c),h=0;h<n;h++)f.setUint8(h,u.getUint8(h));f.setInt32(16,s,!0);for(var d=0,p=new Uint8Array(c,n),v=0;v<o.length;v++){var y=o[v];p.set(new Uint8Array(y,n),d),d+=y.byteLength-n}return c},slice:function(t){var n=0,r=0;if(!Mn(t.startIndex)&&!Mn(t.endIndex)?(n=t.startIndex,r=t.endIndex):!Mn(t.startTime)&&!Mn(t.endTime)&&(n=this.at_time(t.startTime),r=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(r<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),r>this.length&&(r=this.length),n>r&&(n=r);var s=r-n,o=24,a=this.bits===8?1:2,i=o+s*2*this.channels*a,l=new ArrayBuffer(i),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,this.bits===8,!0),c.setInt32(8,this.sample_rate,!0),c.setInt32(12,this.scale,!0),c.setInt32(16,s,!0),c.setInt32(20,this.channels,!0);for(var u=0;u<s*this.channels*2;u++){var f=this._at(n*this.channels*2+u);this.bits===8?c.setInt8(o+u,f):c.setInt16(o+u*2,f,!0)}return new mt(l)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var r=0;r<this.channels;r++)t.data.push(this.channel(r).min_sample(n)),t.data.push(this.channel(r).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function vi(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const r=await t.arrayBuffer();return mt.create(r)}else{const r=await t.json();return mt.create(r)}}function Wd(e,t=0){const n=e.channel(t),r=e.bits,s=n.min_array(),o=n.max_array(),a=s.length,i=r===8?new Int8Array(a*2):new Int16Array(a*2);for(let l=0;l<a;l++)i[l*2]=s[l],i[l*2+1]=o[l];return{data:i,bits:r,length:a,sampleRate:e.sample_rate}}async function t0(e,t=0){const n=await vi(e);return Wd(n,t)}async function n0(e){const t=await vi(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Bd(e,t,n,r){let s=e;if(n!==void 0&&r!==void 0)if(s.scale!==t){const o=e.scale,a=t/o,i=Math.floor(n/t),l=Math.ceil((n+r)/t),c=Math.floor(i*a),u=Math.min(e.length,Math.ceil(l*a));if(c>=u)return null;s=s.slice({startIndex:c,endIndex:u}),s=s.resample({scale:t})}else{const o=Math.floor(n/t),a=Math.ceil((n+r)/t);s=s.slice({startIndex:o,endIndex:a})}else s.scale!==t&&(s=s.resample({scale:t}));return s}function r0(e,t,n=0,r,s){const o=Bd(e,t,r,s);if(o===null){const h=e.bits;return{data:h===8?new Int8Array(0):new Int16Array(0),bits:h,length:0}}const a=o.channel(n),i=o.bits,l=a.min_array(),c=a.max_array(),u=l.length,f=i===8?new Int8Array(u*2):new Int16Array(u*2);for(let h=0;h<u;h++)f[h*2]=l[h],f[h*2+1]=c[h];return{data:f,bits:i,length:u}}function zl(e,t,n,r,s){const o=Bd(e,t,r,s);if(o===null){const u=e.bits;return{length:0,data:[],bits:u}}const a=o.channels,i=o.bits,l=[];for(let u=0;u<a;u++){const f=o.channel(u),h=f.min_array(),d=f.max_array(),p=h.length,v=i===8?new Int8Array(p*2):new Int16Array(p*2);for(let y=0;y<p;y++)v[y*2]=h[y],v[y*2+1]=d[y];l.push(v)}if(n&&l.length>1){const u=1/l.length,f=l[0].length/2,h=i===8?new Int8Array(f*2):new Int16Array(f*2);for(let d=0;d<f;d++){let p=0,v=0;for(let y=0;y<l.length;y++)p+=u*l[y][d*2],v+=u*l[y][d*2+1];h[d*2]=p,h[d*2+1]=v}return{length:f,data:[h],bits:i}}return{length:l.length>0?l[0].length/2:0,data:l,bits:i}}function Vd(){const[e,t]=g.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:s=>Ln(s,e),parseTime:s=>$d(s,e)}}function Nd({engineRef:e,initialSamplesPerPixel:t}){const[n,r]=g.useState(t),[s,o]=g.useState(!0),[a,i]=g.useState(!0),l=g.useRef(!0),c=g.useRef(!0),u=g.useRef(t),f=g.useCallback(()=>{e.current?.zoomIn()},[e]),h=g.useCallback(()=>{e.current?.zoomOut()},[e]),d=g.useCallback(p=>{p.samplesPerPixel!==u.current&&(u.current=p.samplesPerPixel,g.startTransition(()=>{r(p.samplesPerPixel)})),p.canZoomIn!==l.current&&(l.current=p.canZoomIn,o(p.canZoomIn)),p.canZoomOut!==c.current&&(c.current=p.canZoomOut,i(p.canZoomOut))},[]);return{samplesPerPixel:n,zoomIn:f,zoomOut:h,canZoomIn:s,canZoomOut:a,onEngineState:d}}function zd({engineRef:e,initialVolume:t=1}){const[n,r]=g.useState(t),s=g.useRef(t),o=g.useCallback(i=>{e.current?e.current.setMasterVolume(i):(s.current=i,r(i))},[e]),a=g.useCallback(i=>{i.masterVolume!==s.current&&(s.current=i.masterVolume,r(i.masterVolume))},[]);return{masterVolume:n,setMasterVolume:o,masterVolumeRef:s,onEngineState:a}}function s0({engineRef:e}){const[t,n]=g.useState(0),[r,s]=g.useState(0),o=g.useRef(0),a=g.useRef(0),i=g.useCallback((c,u)=>{e.current?.setSelection(c,u)},[e]),l=g.useCallback(c=>{c.selectionStart!==o.current&&(o.current=c.selectionStart,n(c.selectionStart)),c.selectionEnd!==a.current&&(a.current=c.selectionEnd,s(c.selectionEnd))},[]);return{selectionStart:t,selectionEnd:r,setSelection:i,selectionStartRef:o,selectionEndRef:a,onEngineState:l}}function o0({engineRef:e}){const[t,n]=g.useState(!1),[r,s]=g.useState(0),[o,a]=g.useState(0),i=g.useRef(!1),l=g.useRef(0),c=g.useRef(0),u=g.useCallback(p=>{e.current?.setLoopEnabled(p)},[e]),f=g.useCallback((p,v)=>{e.current?.setLoopRegion(p,v)},[e]),h=g.useCallback(()=>{e.current?.setLoopRegion(0,0)},[e]),d=g.useCallback(p=>{p.isLoopEnabled!==i.current&&(i.current=p.isLoopEnabled,n(p.isLoopEnabled)),p.loopStart!==l.current&&(l.current=p.loopStart,s(p.loopStart)),p.loopEnd!==c.current&&(c.current=p.loopEnd,a(p.loopEnd))},[]);return{isLoopEnabled:t,loopStart:r,loopEnd:o,setLoopEnabled:u,setLoopRegion:f,clearLoopRegion:h,isLoopEnabledRef:i,loopStartRef:l,loopEndRef:c,onEngineState:d}}function a0({engineRef:e}){const[t,n]=g.useState(null),r=g.useRef(null),s=g.useCallback(a=>{e.current?.selectTrack(a)},[e]),o=g.useCallback(a=>{a.selectedTrackId!==r.current&&(r.current=a.selectedTrackId,n(a.selectedTrackId))},[]);return{selectedTrackId:t,setSelectedTrackId:s,onEngineState:o,selectedTrackIdRef:r}}const i0=(e=256)=>{const t=g.useRef(null),n=g.useCallback((r,s,o)=>{const a=new F.Analyser("fft",e);return r.connect(a),r.connect(s),t.current=a,function(){a.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function l0(e,t={}){const{progressive:n=!1}=t,[r,s]=g.useState([]),[o,a]=g.useState(!0),[i,l]=g.useState(null),[c,u]=g.useState(0),f=e.length;return g.useEffect(()=>{if(e.length===0){s([]),a(!1),u(0);return}let h=!1;const d=new AbortController,p=new Map,v=(m,b,_)=>{const w=_??m.audioBuffer;if(!w&&!m.waveformData)throw new Error(`Track ${b+1}: Must provide src, audioBuffer, or waveformData`);const x=w?.duration??m.waveformData?.duration,S=Jl({audioBuffer:w,startTime:m.startTime??0,duration:m.duration??x,offset:m.offset??0,name:m.name||`Track ${b+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${b+1}`);return{...Ql({name:m.name||`Track ${b+1}`,clips:[S],muted:m.muted??!1,soloed:m.soloed??!1,volume:m.volume??1,pan:m.pan??0,color:m.color}),effects:m.effects,renderMode:m.renderMode,spectrogramConfig:m.spectrogramConfig,spectrogramColorMap:m.spectrogramColorMap}};return(async()=>{try{a(!0),l(null),u(0);const m=ql.getContext().rawContext,b=e.map(async(w,x)=>{if(w.audioBuffer){const I=v(w,x,w.audioBuffer);return n&&!h&&(p.set(x,I),u(M=>M+1),s(Array.from({length:e.length},(M,$)=>p.get($)).filter(M=>M!==void 0))),I}if(!w.src&&w.waveformData){const I=v(w,x);return n&&!h&&(p.set(x,I),u(M=>M+1),s(Array.from({length:e.length},(M,$)=>p.get($)).filter(M=>M!==void 0))),I}if(!w.src)throw new Error(`Track ${x+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(w.src,{signal:d.signal});if(!S.ok)throw new Error(`Failed to fetch ${w.src}: ${S.statusText}`);const k=await S.arrayBuffer(),E=await m.decodeAudioData(k);if(!E||!E.sampleRate||!E.duration)throw new Error(`Invalid audio buffer for ${w.src}`);const T=v(w,x,E);return n&&!h&&(p.set(x,T),u(I=>I+1),s(Array.from({length:e.length},(I,M)=>p.get(M)).filter(I=>I!==void 0))),T}),_=await Promise.all(b);h||(n||(s(_),u(_.length)),a(!1))}catch(m){if(!h){const b=m instanceof Error?m.message:"Unknown error loading audio";l(b),a(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{h=!0,d.abort()}},[e,n]),{tracks:r,loading:o,error:i,loadedCount:c,totalCount:f}}function c0({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:r,engineRef:s,isDraggingRef:o}){const a=g.useRef(null),i=g.useRef(0),l=g.useCallback(f=>{const h=f.operation.source?.data;if(!h)return;if(!h.boundary){a.current=null;return}const p=e[h.trackIndex]?.clips[h.clipIndex];p&&(a.current={offsetSamples:p.offsetSamples,durationSamples:p.durationSamples,startSample:p.startSample},o.current=!0)},[e,o]),c=g.useCallback(f=>{const h=f.operation.source?.data;if(!h||!h.boundary||!a.current)return;const{boundary:d,trackIndex:p,clipIndex:v}=h,b=((f.to?.x??f.operation.position.current.x)-f.operation.position.initial.x)*n,_=Math.floor(.1*r),w=a.current,x=e.map((S,k)=>{if(k!==p)return S;const E=[...S.clips].sort((M,$)=>M.startSample-$.startSample),T=E.findIndex(M=>M===S.clips[v]),I=S.clips.map((M,$)=>{if($!==v)return M;if(d==="left"){const A={...M,startSample:w.startSample,offsetSamples:w.offsetSamples,durationSamples:w.durationSamples},R=ko(A,Math.floor(b),"left",E,T,_),W=w.offsetSamples+R,q=w.durationSamples-R,z=w.startSample+R;return{...M,offsetSamples:W,durationSamples:q,startSample:z}}else{const A={...M,startSample:w.startSample,offsetSamples:w.offsetSamples,durationSamples:w.durationSamples},R=ko(A,Math.floor(b),"right",E,T,_),W=w.durationSamples+R;return{...M,durationSamples:W}}});return{...S,clips:I}});i.current=b,t(x)},[e,t,n,r]),u=g.useCallback(f=>{if(f.canceled){if(a.current){const b=f.operation.source?.data;if(b){const{trackIndex:_,clipIndex:w}=b,x=a.current,S=e.map((k,E)=>{if(E!==_)return k;const T=k.clips.map((I,M)=>M!==w?I:{...I,offsetSamples:x.offsetSamples,durationSamples:x.durationSamples,startSample:x.startSample});return{...k,clips:T}});t(S)}}o.current=!1,a.current=null,i.current=0;return}const h=f.operation.source?.data;if(!h)return;const{trackIndex:d,clipId:p,boundary:v}=h,y=v?i.current:f.operation.transform.x*n,m=e[d]?.id;if(v){o.current=!1,m?s.current?s.current.trimClip(m,p,v,Math.floor(y)):console.warn("[waveform-playlist] engineRef is null — trim not synced to adapter"):console.warn(`[waveform-playlist] onDragEnd: track at index ${d} not found — trim not synced to adapter`),a.current=null,i.current=0;return}m?s.current?s.current.moveClip(m,p,Math.floor(y)):console.warn("[waveform-playlist] engineRef is null — move not synced to adapter"):console.warn(`[waveform-playlist] onDragEnd: track at index ${d} not found — move not synced to adapter`)},[e,t,n,s,o]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}const yo=.01;function jd({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:r,duration:s,linkEndpoints:o}){const a=g.useRef(null),i=g.useCallback(u=>{const f=u.operation.source?.data;if(!f||f.annotationIndex===void 0){a.current=null;return}const h=e[f.annotationIndex];h&&(a.current={start:h.start,end:h.end,annotationIndex:f.annotationIndex})},[e]),l=g.useCallback(u=>{if(!a.current)return;const f=u.operation.source?.data;if(!f)return;const{edge:h,annotationIndex:d}=f,p=a.current,m=((u.to?.x??u.operation.position.current.x)-u.operation.position.initial.x)*n/r,b=h==="start"?p.start+m:p.end+m,_=u0({annotationIndex:d,newTime:b,isDraggingStart:h==="start",annotations:e,duration:s,linkEndpoints:o});t(_)},[e,t,n,r,s,o]),c=g.useCallback(u=>{if(u.canceled&&a.current){const{annotationIndex:f,start:h,end:d}=a.current,p=e.map((v,y)=>y!==f?v:{...v,start:h,end:d});t(p)}a.current=null},[e,t]);return{onDragStart:i,onDragMove:l,onDragEnd:c}}function u0({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:r,duration:s,linkEndpoints:o}){const a=[...r],i=r[e];if(n){const l=Math.min(i.end-.1,Math.max(0,t)),c=l-i.start;if(a[e]={...i,start:l},o&&e>0){const u=a[e-1];Math.abs(u.end-i.start)<yo?a[e-1]={...u,end:Math.max(u.start+.1,u.end+c)}:l<=u.end&&(a[e]={...a[e],start:u.end})}else!o&&e>0&&l<a[e-1].end&&(a[e-1]={...a[e-1],end:l})}else{const l=Math.max(i.start+.1,Math.min(t,s)),c=l-i.end;if(a[e]={...i,end:l},o&&e<a.length-1){const u=a[e+1];if(Math.abs(u.start-i.end)<yo){const f=u.start+c;a[e+1]={...u,start:Math.min(u.end-.1,f)};let h=e+1;for(;h<a.length-1;){const d=a[h],p=a[h+1];if(Math.abs(p.start-d.end)<yo){const v=d.end-r[h].end;a[h+1]={...p,start:Math.min(p.end-.1,p.start+v)},h++}else break}}else l>=u.start&&(a[e]={...a[e],end:u.start})}else if(!o&&e<a.length-1&&l>a[e+1].start){const u=a[e+1];a[e+1]={...u,start:l};let f=e+1;for(;f<a.length-1;){const h=a[f],d=a[f+1];if(h.end>d.start)a[f+1]={...d,start:h.end},f++;else break}}}return a}function d0(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:r=5,mouseDistance:s=1}=e;return g.useMemo(()=>t?[ea.configure({activationConstraints(o){return o.pointerType==="touch"?[new Bt.Delay({value:n,tolerance:r})]:[new Bt.Distance({value:s})]}})]:[ea.configure({activationConstraints:[new Bt.Distance({value:s})]})],[t,n,r,s])}const f0=e=>{const{tracks:t,sampleRate:n,engineRef:r}=e,{currentTimeRef:s}=lt(),{selectedTrackId:o}=ct(),a=g.useCallback((l,c,u)=>{const{samplesPerPixel:f}=e,h=t[l];if(!h)return!1;const d=h.clips[c];if(!d)return!1;const p=Math.round(u*n),v=Gf(p,f),y=Math.floor(.1*n);if(!sc(d,v,y))return console.warn("Split point is invalid (outside bounds or too close to edge)"),!1;const m=r.current;return m?(m.splitClip(h.id,d.id,v),!0):(console.warn("[waveform-playlist] engineRef is null — split not synced to adapter"),!1)},[t,e,n,r]);return{splitClipAtPlayhead:g.useCallback(()=>{if(!o)return console.warn("[waveform-playlist] No track selected — click a clip to select a track first"),!1;const l=t.findIndex(f=>f.id===o);if(l===-1)return console.warn("Selected track not found"),!1;const c=t[l],u=s.current??0;for(let f=0;f<c.clips.length;f++){const h=c.clips[f],d=h.startSample/n,p=(h.startSample+h.durationSamples)/n;if(u>d&&u<p)return a(l,f,u)}return console.warn(`[waveform-playlist] No clip found at playhead position on track "${c.name}"`),!1},[t,s,o,a,n]),splitClipAt:a}},Ds=e=>{const{shortcuts:t,enabled:n=!0}=e,r=g.useCallback(s=>{if(!n)return;const o=s.target;if(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable)return;const a=t.find(i=>{const l=s.key.toLowerCase()===i.key.toLowerCase()||s.key===i.key,c=i.ctrlKey===void 0||s.ctrlKey===i.ctrlKey,u=i.shiftKey===void 0||s.shiftKey===i.shiftKey,f=i.metaKey===void 0||s.metaKey===i.metaKey,h=i.altKey===void 0||s.altKey===i.altKey;return l&&c&&u&&f&&h});a&&(a.preventDefault!==!1&&s.preventDefault(),a.action())},[t,n]);g.useEffect(()=>{if(n)return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}},[r,n])},h0=e=>{const t=[],n=typeof navigator<"u"&&navigator.platform.includes("Mac");return e.metaKey&&t.push(n?"Cmd":"Ctrl"),e.ctrlKey&&!e.metaKey&&t.push("Ctrl"),e.altKey&&t.push(n?"Option":"Alt"),e.shiftKey&&t.push("Shift"),t.push(e.key.toUpperCase()),t.join("+")},p0=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:r}=e,{isPlaying:s}=lt(),{setCurrentTime:o,play:a,pause:i,stop:l}=Pe(),c=g.useCallback(()=>{s?i():a()},[s,a,i]),u=g.useCallback(()=>{l()},[l]),f=g.useCallback(()=>{o(0),s&&a(0)},[s,o,a]),d=r??[...[{key:" ",action:c,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:u,description:"Stop",preventDefault:!0},{key:"0",action:f,description:"Rewind to start",preventDefault:!0}],...n];return Ds({shortcuts:d,enabled:t}),{rewindToStart:f,togglePlayPause:c,stopPlayback:u,shortcuts:d}},bo=.01,ns=.01;function m0({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:r,duration:s,linkEndpoints:o,continuousPlay:a=!1,enabled:i=!0,scrollContainerRef:l,samplesPerPixel:c,sampleRate:u,onPlay:f}){const h=g.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),d=g.useCallback(E=>{if(!l?.current||!c||!u)return;const T=e.find(J=>J.id===E);if(!T)return;const I=l.current,M=I.clientWidth,$=T.start*u/c,A=T.end*u/c,R=($+A)/2,W=I.scrollLeft,q=W,z=W+M;if($<q||A>z){const J=Math.max(0,R-M/2);I.scrollTo({left:J,behavior:"smooth"})}},[e,l,c,u]);g.useEffect(()=>{t&&l?.current&&c&&u&&d(t)},[t,d,l,c,u]);const p=g.useCallback(E=>{if(h<0)return;const T=e[h],I=Math.max(0,Math.min(T.end-.1,T.start+E)),M=I-T.start,$=[...e];if($[h]={...T,start:I},o&&h>0){const A=$[h-1];Math.abs(A.end-T.start)<bo&&($[h-1]={...A,end:Math.max(A.start+.1,A.end+M)})}else if(!o&&h>0){const A=$[h-1];I<A.end&&($[h-1]={...A,end:I})}n($)},[e,h,o,n]),v=g.useCallback(E=>{if(h<0)return;const T=e[h],I=Math.max(T.start+.1,Math.min(s,T.end+E)),M=I-T.end,$=[...e];if($[h]={...T,end:I},o&&h<e.length-1){const A=$[h+1];if(Math.abs(A.start-T.end)<bo){const R=Math.min(A.end-.1,A.start+M);$[h+1]={...A,start:R};let W=h+1;for(;W<$.length-1;){const q=$[W],z=$[W+1];if(Math.abs(z.start-e[W].end)<bo){const J=q.end-e[W].end;$[W+1]={...z,start:Math.min(z.end-.1,z.start+J)},W++}else break}}}else if(!o&&h<e.length-1){const A=$[h+1];if(I>A.start){$[h+1]={...A,start:I};let R=h+1;for(;R<$.length-1;){const W=$[R],q=$[R+1];if(W.end>q.start)$[R+1]={...q,start:W.end},R++;else break}}}n($)},[e,h,s,o,n]),y=g.useCallback(()=>{!r||e.length===0||(h<=0?r(e[e.length-1].id):r(e[h-1].id))},[e,h,r]),m=g.useCallback(()=>{!r||e.length===0||(h<0||h>=e.length-1?r(e[0].id):r(e[h+1].id))},[e,h,r]),b=g.useCallback(()=>{!r||e.length===0||r(e[0].id)},[e,r]),_=g.useCallback(()=>{!r||e.length===0||r(e[e.length-1].id)},[e,r]),w=g.useCallback(()=>{r&&r(null)},[r]),x=g.useCallback(()=>{if(h<0||!f)return;const E=e[h],T=a?void 0:E.end-E.start;f(E.start,T)},[e,h,a,f]),S=g.useMemo(()=>[{key:"[",action:()=>p(-ns),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>p(ns),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>v(-ns),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>v(ns),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:x,description:"Play selected annotation",preventDefault:!0}],[p,v,x]),k=g.useMemo(()=>[{key:"ArrowUp",action:y,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:y,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:m,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:m,description:"Select next annotation",preventDefault:!0},{key:"Home",action:b,description:"Select first annotation",preventDefault:!0},{key:"End",action:_,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:w,description:"Deselect annotation",preventDefault:!0}],[y,m,b,_,w]);return Ds({shortcuts:S,enabled:i&&h>=0}),Ds({shortcuts:k,enabled:i&&e.length>0&&!!r}),{moveStartBoundary:p,moveEndBoundary:v,selectPrevious:y,selectNext:m,selectFirst:b,selectLast:_,clearSelection:w,scrollToAnnotation:d,playActiveAnnotation:x}}const jr=[{id:"reverb",name:"Reverb",category:"reverb",description:"Simple convolution reverb with adjustable decay time",parameters:[{name:"decay",label:"Decay",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"s"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"freeverb",name:"Freeverb",category:"reverb",description:"Classic Schroeder/Moorer reverb with room size and dampening",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.7},{name:"dampening",label:"Dampening",type:"number",min:0,max:1e4,step:100,default:3e3,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"jcReverb",name:"JC Reverb",category:"reverb",description:"Attempt at Roland JC-120 chorus reverb emulation",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"feedbackDelay",name:"Feedback Delay",category:"delay",description:"Delay line with feedback for echo effects",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"pingPongDelay",name:"Ping Pong Delay",category:"delay",description:"Stereo delay bouncing between left and right channels",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"chorus",name:"Chorus",category:"modulation",description:"Creates thickness by layering detuned copies of the signal",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"Hz"},{name:"delayTime",label:"Delay",type:"number",min:0,max:20,step:.5,default:3.5,unit:"ms"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.7},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"phaser",name:"Phaser",category:"modulation",description:"Classic phaser effect using allpass filters",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:.5,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:6,step:1,default:3},{name:"baseFrequency",label:"Base Freq",type:"number",min:100,max:2e3,step:10,default:350,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"tremolo",name:"Tremolo",category:"modulation",description:"Rhythmic volume modulation",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:4,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"vibrato",name:"Vibrato",category:"modulation",description:"Pitch modulation effect",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:5,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoPanner",name:"Auto Panner",category:"modulation",description:"Automatic left-right panning",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoFilter",name:"Auto Filter",category:"filter",description:"Automated filter sweep with LFO",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:2e3,step:10,default:200,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:.5,max:8,step:.5,default:2.6},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoWah",name:"Auto Wah",category:"filter",description:"Envelope follower filter effect",parameters:[{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:500,step:10,default:100,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:8,step:1,default:6},{name:"sensitivity",label:"Sensitivity",type:"number",min:-40,max:0,step:1,default:0,unit:"dB"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"eq3",name:"3-Band EQ",category:"filter",description:"Three band equalizer with low, mid, and high controls",parameters:[{name:"low",label:"Low",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"mid",label:"Mid",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"high",label:"High",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"lowFrequency",label:"Low Freq",type:"number",min:20,max:500,step:10,default:400,unit:"Hz"},{name:"highFrequency",label:"High Freq",type:"number",min:1e3,max:1e4,step:100,default:2500,unit:"Hz"}]},{id:"distortion",name:"Distortion",category:"distortion",description:"Wave shaping distortion effect",parameters:[{name:"distortion",label:"Drive",type:"number",min:0,max:1,step:.01,default:.4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"bitCrusher",name:"Bit Crusher",category:"distortion",description:"Reduces bit depth for lo-fi digital texture",parameters:[{name:"bits",label:"Bits",type:"number",min:1,max:16,step:1,default:4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"chebyshev",name:"Chebyshev",category:"distortion",description:"Waveshaping distortion using Chebyshev polynomials",parameters:[{name:"order",label:"Order",type:"number",min:1,max:100,step:1,default:50},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"compressor",name:"Compressor",category:"dynamics",description:"Dynamic range compressor",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-60,max:0,step:1,default:-24,unit:"dB"},{name:"ratio",label:"Ratio",type:"number",min:1,max:20,step:.5,default:4},{name:"attack",label:"Attack",type:"number",min:0,max:1,step:.001,default:.003,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"knee",label:"Knee",type:"number",min:0,max:40,step:1,default:30,unit:"dB"}]},{id:"limiter",name:"Limiter",category:"dynamics",description:"Hard limiter to prevent clipping",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-12,max:0,step:.5,default:-6,unit:"dB"}]},{id:"gate",name:"Gate",category:"dynamics",description:"Noise gate to silence signal below threshold",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-100,max:0,step:1,default:-40,unit:"dB"},{name:"attack",label:"Attack",type:"number",min:0,max:.3,step:.001,default:.001,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:.5,step:.01,default:.1,unit:"s"}]},{id:"stereoWidener",name:"Stereo Widener",category:"spatial",description:"Expands or narrows the stereo image",parameters:[{name:"width",label:"Width",type:"number",min:0,max:1,step:.01,default:.5}]}],yi=e=>jr.find(t=>t.id===e),g0=e=>jr.filter(t=>t.category===e),v0=[{id:"reverb",name:"Reverb"},{id:"delay",name:"Delay"},{id:"modulation",name:"Modulation"},{id:"filter",name:"Filter"},{id:"distortion",name:"Distortion"},{id:"dynamics",name:"Dynamics"},{id:"spatial",name:"Spatial"}];const y0={reverb:F.Reverb,freeverb:F.Freeverb,jcReverb:F.JCReverb,feedbackDelay:F.FeedbackDelay,pingPongDelay:F.PingPongDelay,chorus:F.Chorus,phaser:F.Phaser,tremolo:F.Tremolo,vibrato:F.Vibrato,autoPanner:F.AutoPanner,autoFilter:F.AutoFilter,autoWah:F.AutoWah,eq3:F.EQ3,distortion:F.Distortion,bitCrusher:F.BitCrusher,chebyshev:F.Chebyshev,compressor:F.Compressor,limiter:F.Limiter,gate:F.Gate,stereoWidener:F.StereoWidener};let b0=0;const w0=()=>`effect_${Date.now()}_${++b0}`;function Tr(e,t){const n=y0[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const r={};e.parameters.forEach(i=>{const l=t?.[i.name]??i.default;r[i.name]=l});const s=new n(r),o=w0(),a=s;return{effect:s,id:e.id,instanceId:o,dispose(){try{s.disconnect(),s.dispose()}catch(i){console.warn(`[waveform-playlist] Error disposing effect "${e.id}" (${o}):`,i)}},setParameter(i,l){const c=a[i];if(i==="wet"){const u=a.wet;if(u&&typeof u=="object"&&"value"in u){u.value=l;return}}c!==void 0&&(c&&typeof c=="object"&&"value"in c?c.value=l:a[i]=l)},getParameter(i){if(i==="wet"){const c=a.wet;if(c&&typeof c=="object"&&"value"in c)return c.value}const l=a[i];if(l!==void 0)return l&&typeof l=="object"&&"value"in l?l.value:l},connect(i){s.connect(i)},disconnect(){try{s.disconnect()}catch(i){console.warn(`[waveform-playlist] Error disconnecting effect "${e.id}" (${o}):`,i)}}}}function _0(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function x0(e=256){const[t,n]=g.useState([]),r=g.useRef(t);r.current=t;const s=g.useRef(new Map),o=g.useRef(null),a=g.useRef(null),i=g.useCallback(y=>{const m=a.current;if(!m)return;const{masterGainNode:b,destination:_,analyserNode:w}=m;try{b.disconnect()}catch(S){console.warn("[waveform-playlist] Error disconnecting master effects chain:",S)}const x=y.map(S=>s.current.get(S.instanceId)).filter(S=>S!==void 0);if(x.length===0)b.connect(w),w.connect(_);else{let S=b;x.forEach(k=>{try{k.disconnect()}catch(E){console.warn(`[waveform-playlist] Error disconnecting effect "${k.id}":`,E)}S.connect(k.effect),S=k.effect}),S.connect(w),w.connect(_)}},[]),l=g.useCallback(y=>{const m=yi(y);if(!m){console.error(`Unknown effect: ${y}`);return}const b={};m.parameters.forEach(x=>{b[x.name]=x.default});const _=Tr(m,b);s.current.set(_.instanceId,_);const w={instanceId:_.instanceId,effectId:m.id,definition:m,params:b,bypassed:!1};n(x=>[...x,w])},[]),c=g.useCallback(y=>{const m=s.current.get(y);m&&(m.dispose(),s.current.delete(y)),n(b=>b.filter(_=>_.instanceId!==y))},[]),u=g.useCallback((y,m,b)=>{const _=s.current.get(y);_&&_.setParameter(m,b),n(w=>w.map(x=>x.instanceId===y?{...x,params:{...x.params,[m]:b}}:x))},[]),f=g.useCallback(y=>{const m=r.current.find(w=>w.instanceId===y);if(!m)return;const b=!m.bypassed,_=s.current.get(y);if(_){const w=m.params.wet??1;_.setParameter("wet",b?0:w)}n(w=>w.map(x=>x.instanceId===y?{...x,bypassed:b}:x))},[]),h=g.useCallback((y,m)=>{n(b=>{const _=[...b],[w]=_.splice(y,1);return _.splice(m,0,w),_})},[]),d=g.useCallback(()=>{s.current.forEach(y=>y.dispose()),s.current.clear(),n([])},[]);g.useEffect(()=>{i(t)},[t,i]);const p=g.useCallback((y,m,b)=>{const _=new F.Analyser("fft",e);o.current=_,a.current={masterGainNode:y,destination:m,analyserNode:_};const x=r.current.map(S=>s.current.get(S.instanceId)).filter(S=>S!==void 0);if(x.length===0)y.connect(_),_.connect(m);else{let S=y;x.forEach(k=>{S.connect(k.effect),S=k.effect}),S.connect(_),_.connect(m)}return function(){_.dispose(),o.current=null,a.current=null}},[e]);g.useEffect(()=>{const y=s.current;return()=>{y.forEach(m=>m.dispose()),y.clear()}},[]);const v=g.useCallback(()=>{const y=t.filter(m=>!m.bypassed);if(y.length!==0)return(m,b,_)=>{const w=[];for(const x of y){const S=Tr(x.definition,x.params);w.push(S)}if(w.length===0)m.connect(b);else{let x=m;w.forEach(S=>{x.connect(S.effect),x=S.effect}),x.connect(b)}return function(){w.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:jr,addEffect:l,removeEffect:c,updateParameter:u,toggleBypass:f,reorderEffects:h,clearAllEffects:d,masterEffects:p,createOfflineEffectsFunction:v,analyserRef:o}}function C0(){const[e,t]=g.useState(new Map),n=g.useRef(new Map),r=g.useRef(new Map),s=g.useCallback((d,p)=>{const v=r.current.get(d);if(!v)return;const{graphEnd:y,masterGainNode:m}=v,b=n.current.get(d);try{y.disconnect()}catch(w){console.warn(`[waveform-playlist] Error disconnecting track "${d}" effect chain:`,w)}const _=p.map(w=>b?.get(w.instanceId)).filter(w=>w!==void 0);if(_.length===0)y.connect(m);else{let w=y;_.forEach(x=>{try{x.disconnect()}catch(S){console.warn(`[waveform-playlist] Error disconnecting effect "${x.id}" on track "${d}":`,S)}w.connect(x.effect),w=x.effect}),w.connect(m)}},[]),o=g.useCallback((d,p)=>{const v=yi(p);if(!v){console.error(`Unknown effect: ${p}`);return}const y={};v.parameters.forEach(_=>{y[_.name]=_.default});const m=Tr(v,y);n.current.has(d)||n.current.set(d,new Map),n.current.get(d).set(m.instanceId,m);const b={instanceId:m.instanceId,effectId:v.id,definition:v,params:y,bypassed:!1};t(_=>{const w=new Map(_),x=w.get(d)||[];return w.set(d,[...x,b]),w})},[]),a=g.useCallback((d,p)=>{const v=n.current.get(d),y=v?.get(p);y&&(y.dispose(),v?.delete(p)),t(m=>{const b=new Map(m),_=b.get(d)||[];return b.set(d,_.filter(w=>w.instanceId!==p)),b})},[]),i=g.useCallback((d,p,v,y)=>{const b=n.current.get(d)?.get(p);b&&b.setParameter(v,y),t(_=>{const w=new Map(_),x=w.get(d)||[];return w.set(d,x.map(S=>S.instanceId===p?{...S,params:{...S.params,[v]:y}}:S)),w})},[]),l=g.useCallback((d,p)=>{const y=(u.current.get(d)||[]).find(w=>w.instanceId===p);if(!y)return;const m=!y.bypassed,_=n.current.get(d)?.get(p);if(_){const w=y.params.wet??1;_.setParameter("wet",m?0:w)}t(w=>{const x=new Map(w),S=x.get(d)||[];return x.set(d,S.map(k=>k.instanceId===p?{...k,bypassed:m}:k)),x})},[]),c=g.useCallback(d=>{const p=n.current.get(d);p&&(p.forEach(v=>v.dispose()),p.clear()),t(v=>{const y=new Map(v);return y.set(d,[]),y})},[]),u=g.useRef(e);u.current=e;const f=g.useCallback(d=>(p,v,y)=>{r.current.set(d,{graphEnd:p,masterGainNode:v});const m=u.current.get(d)||[],b=n.current.get(d),_=m.map(w=>b?.get(w.instanceId)).filter(w=>w!==void 0);if(_.length===0)p.connect(v);else{let w=p;_.forEach(x=>{w.connect(x.effect),w=x.effect}),w.connect(v)}return function(){r.current.delete(d)}},[]);g.useEffect(()=>{e.forEach((d,p)=>{s(p,d)})},[e,s]),g.useEffect(()=>{const d=n.current;return()=>{d.forEach(p=>{p.forEach(v=>v.dispose()),p.clear()}),d.clear()}},[]);const h=g.useCallback(d=>{const v=(e.get(d)||[]).filter(y=>!y.bypassed);if(v.length!==0)return(y,m,b)=>{const _=[];for(const w of v){const x=Tr(w.definition,w.params);_.push(x)}if(_.length===0)y.connect(m);else{let w=y;_.forEach(x=>{w.connect(x.effect),w=x.effect}),w.connect(m)}return function(){_.forEach(x=>x.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:o,removeEffectFromTrack:a,updateTrackEffectParameter:i,toggleBypass:l,clearTrackEffects:c,getTrackEffectsFunction:f,createOfflineTrackEffectsFunction:h,availableEffects:jr}}function S0(e,t={}){const{bitDepth:n=16}=t,r=e.numberOfChannels,s=e.sampleRate,o=e.length,a=n/8,i=r*a,l=s*i,c=o*i,u=44,f=u+c,h=new ArrayBuffer(f),d=new DataView(h);rs(d,0,"RIFF"),d.setUint32(4,f-8,!0),rs(d,8,"WAVE"),rs(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,n===32?3:1,!0),d.setUint16(22,r,!0),d.setUint32(24,s,!0),d.setUint32(28,l,!0),d.setUint16(32,i,!0),d.setUint16(34,n,!0),rs(d,36,"data"),d.setUint32(40,c,!0);const p=[];for(let y=0;y<r;y++)p.push(e.getChannelData(y));let v=u;if(n===16)for(let y=0;y<o;y++)for(let m=0;m<r;m++){const b=p[m][y],_=Math.max(-1,Math.min(1,b)),w=_<0?_*32768:_*32767;d.setInt16(v,w,!0),v+=2}else for(let y=0;y<o;y++)for(let m=0;m<r;m++)d.setFloat32(v,p[m][y],!0),v+=4;return new Blob([h],{type:"audio/wav"})}function rs(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}function k0(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function Zd(){const[e,t]=g.useState(!1),[n,r]=g.useState(0),[s,o]=g.useState(null);return{exportWav:g.useCallback(async(i,l,c={})=>{const{filename:u="export",mode:f="master",trackIndex:h,autoDownload:d=!0,applyEffects:p=!0,effectsFunction:v,createOfflineTrackEffects:y,bitDepth:m=16,onProgress:b}=c;t(!0),r(0),o(null);try{if(i.length===0)throw new Error("No tracks to export");if(f==="individual"&&(h===void 0||h<0||h>=i.length))throw new Error("Invalid track index for individual export");const _=i[0].clips[0]?.sampleRate||44100;let w=0;for(const M of i)for(const $ of M.clips){const A=$.startSample+$.durationSamples;w=Math.max(w,A)}w+=Math.round(_*.1);const x=w/_,S=f==="individual"?[{track:i[h],state:l[h],index:h}]:i.map((M,$)=>({track:M,state:l[$],index:$})),k=l.some(M=>M.soloed),E=!!y;let T;if((v||E)&&p)T=await E0(S,l,k,x,_,v,y,M=>{r(M),b?.(M)});else{const M=new OfflineAudioContext(2,w,_);let $=0;const A=S.reduce((R,{track:W})=>R+W.clips.length,0);for(const{track:R,state:W}of S)if(!(W.muted&&!W.soloed)&&!(k&&!W.soloed))for(const q of R.clips){await M0(M,q,W,_,p),$++;const z=$/A*.5;r(z),b?.(z)}r(.5),b?.(.5),T=await M.startRendering()}r(.9),b?.(.9);const I=S0(T,{bitDepth:m});if(r(1),b?.(1),d){const M=f==="individual"?`${u}_${i[h].name}`:u;k0(I,`${M}.wav`)}return{audioBuffer:T,blob:I,duration:x}}catch(_){const w=_ instanceof Error?_.message:"Export failed";throw o(w),_}finally{t(!1)}},[]),isExporting:e,progress:n,error:s}}async function E0(e,t,n,r,s,o,a,i){const{Offline:l,Volume:c,Gain:u,Panner:f,Player:h,ToneAudioBuffer:d}=await import("tone");i(.1);let p;try{p=await l(async({transport:v,destination:y})=>{const m=new c(0);let b;o?b=o(m,y,!0):m.connect(y);for(const{track:_,state:w}of e){if(w.muted&&!w.soloed||n&&!w.soloed)continue;const x=new c(I0(w.volume)),S=new f(w.pan),k=new u(w.muted?0:1),E=a?.(_.id);E?E(k,m,!0):k.connect(m),S.connect(k),x.connect(S);for(const T of _.clips){const{audioBuffer:I,startSample:M,durationSamples:$,offsetSamples:A,gain:R,fadeIn:W,fadeOut:q}=T,z=M/s,J=$/s,ee=A/s,j=new d(I),se=new h(j),U=new u(R);if(se.connect(U),U.connect(x),W){const ie=z,le=z+W.duration,ge=wr(U.gain);ge&&(ge.setValueAtTime(0,ie),ge.linearRampToValueAtTime(R,le))}if(q){const ie=z+J-q.duration,le=z+J,ge=wr(U.gain);ge&&(ge.setValueAtTime(R,ie),ge.linearRampToValueAtTime(0,le))}se.start(z,ee,J)}}v.start(0)},r,2,s)}catch(v){throw v instanceof Error?v:new Error(`Tone.Offline rendering failed: ${String(v)}`)}return i(.9),p.get()}function I0(e){return 20*Math.log10(Math.max(e,1e-4))}async function M0(e,t,n,r,s){const{audioBuffer:o,startSample:a,durationSamples:i,offsetSamples:l,gain:c,fadeIn:u,fadeOut:f}=t;if(!o){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const h=a/r,d=i/r,p=l/r,v=e.createBufferSource();v.buffer=o;const y=e.createGain(),m=c*n.volume,b=e.createStereoPanner();if(b.pan.value=n.pan,v.connect(y),y.connect(b),b.connect(e.destination),s){if(u?y.gain.setValueAtTime(0,h):y.gain.setValueAtTime(m,h),u){const _=h,w=h+u.duration;jl(y.gain,_,w,0,m,u.type||"linear")}if(f){const _=h+d-f.duration,w=h+d;(!u||u.duration<d-f.duration)&&y.gain.setValueAtTime(m,_),jl(y.gain,_,w,m,0,f.type||"linear")}}else y.gain.setValueAtTime(m,h);v.start(h,p,d)}function jl(e,t,n,r,s,o){const a=n-t;if(!(a<=0))switch(o){case"linear":e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,n);break;case"exponential":{const i=Math.max(r,1e-4),l=Math.max(s,1e-4);e.setValueAtTime(i,t),e.exponentialRampToValueAtTime(l,n),s===0&&e.setValueAtTime(0,n);break}case"logarithmic":{const i=Zl(r,s,256,"logarithmic");e.setValueCurveAtTime(i,t,a);break}case"sCurve":{const i=Zl(r,s,256,"sCurve");e.setValueCurveAtTime(i,t,a);break}default:e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,n)}}function Zl(e,t,n,r){const s=new Float32Array(n),o=t-e;for(let a=0;a<n;a++){const i=a/(n-1);let l;r==="logarithmic"?o>0?l=Math.log10(1+i*9)/Math.log10(10):l=1-Math.log10(1+(1-i)*9)/Math.log10(10):l=i*i*(3-2*i),s[a]=e+o*l}return s}const Hd=()=>{const e=g.useRef(null),t=g.useCallback(()=>{e.current!==null&&(cancelAnimationFrame(e.current),e.current=null)},[]),n=g.useCallback(r=>{t(),e.current=requestAnimationFrame(r)},[t]);return g.useEffect(()=>()=>{t()},[t]),{animationFrameRef:e,startAnimationFrameLoop:n,stopAnimationFrameLoop:t}},A0=`
856
+ `,Bv=({items:e})=>{const[t,n]=g.useState(!1),r=g.useCallback(()=>n(!1),[]),s=typeof e=="function"?e(r):e,[o,a]=g.useState({top:0,left:0}),i=g.useRef(null),l=g.useRef(null),c=g.useCallback(()=>{if(!i.current)return;const u=i.current.getBoundingClientRect(),f=window.innerWidth,h=window.innerHeight,d=l.current?.offsetHeight??160;let p=u.right+4;p+ms>f&&(p=u.left-ms-4),p=Math.max(4,Math.min(p,f-ms-4));let v=u.top;v+d>h-4&&(v=Math.max(4,u.bottom-d)),a({top:v,left:p})},[]);return g.useEffect(()=>{if(!t)return;c();const u=requestAnimationFrame(()=>c()),f=()=>c(),h=()=>c();return window.addEventListener("scroll",f,!0),window.addEventListener("resize",h),()=>{cancelAnimationFrame(u),window.removeEventListener("scroll",f,!0),window.removeEventListener("resize",h)}},[t,c]),g.useEffect(()=>{if(!t)return;const u=h=>{const d=h.target;i.current&&!i.current.contains(d)&&l.current&&!l.current.contains(d)&&n(!1)},f=h=>{h.key==="Escape"&&n(!1)};return document.addEventListener("mousedown",u),document.addEventListener("keydown",f),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",f)}},[t]),C.jsxs(Fv,{children:[C.jsx(Ov,{ref:i,onClick:u=>{u.stopPropagation(),n(f=>!f)},onMouseDown:u=>u.stopPropagation(),title:"Track menu","aria-label":"Track menu",children:C.jsx(Pv,{size:16})}),t&&typeof document<"u"&&ua.createPortal(C.jsx(Lv,{ref:l,$top:o.top,$left:o.left,onMouseDown:u=>u.stopPropagation(),children:s.map((u,f)=>C.jsxs(g.Fragment,{children:[f>0&&C.jsx(Wv,{}),u.content]},u.id))}),document.body)]})};function Cn(e,t){this._waveformData=e,this._channelIndex=t}Cn.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};Cn.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};Cn.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};Cn.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};Cn.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};Cn.prototype.max_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.max_sample(n));return t};var Vv=127,Nv=-128,zv=32767,jv=-32768;function Zv(e,t){var n=Math.floor(e/t),r=e-n*t;return r>0&&n++,n}function Hv(e){for(var t=e.scale,n=e.amplitude_scale,r=e.split_channels,s=e.length,o=e.sample_rate,a=e.channels.map(function(T){return new Float32Array(T)}),i=r?a.length:1,l=24,c=Zv(s,t),u=e.bits===8?1:2,f=l+c*2*u*i,h=new ArrayBuffer(f),d=new DataView(h),p=0,v=l,y=new Array(i),m=new Array(i),b=0;b<i;b++)y[b]=1/0,m[b]=-1/0;var _=e.bits===8?Nv:jv,w=e.bits===8?Vv:zv;d.setInt32(0,2,!0),d.setUint32(4,e.bits===8,!0),d.setInt32(8,o,!0),d.setInt32(12,t,!0),d.setInt32(16,c,!0),d.setInt32(20,i,!0);for(var x=0;x<s;x++){var S=0;if(i===1){for(var k=0;k<a.length;++k)S+=a[k][x];S=Math.floor(w*S*n/a.length),S<y[0]&&(y[0]=S,y[0]<_&&(y[0]=_)),S>m[0]&&(m[0]=S,m[0]>w&&(m[0]=w))}else for(var E=0;E<i;++E)S=Math.floor(w*a[E][x]*n),S<y[E]&&(y[E]=S,y[E]<_&&(y[E]=_)),S>m[E]&&(m[E]=S,m[E]>w&&(m[E]=w));if(++p===t){for(var M=0;M<i;M++)e.bits===8?(d.setInt8(v++,y[M]),d.setInt8(v++,m[M])):(d.setInt16(v,y[M],!0),d.setInt16(v+2,m[M],!0),v+=4),y[M]=1/0,m[M]=-1/0;p=0}}if(p>0)for(var I=0;I<i;I++)e.bits===8?(d.setInt8(v++,y[I]),d.setInt8(v++,m[I])):(d.setInt16(v,y[I],!0),d.setInt16(v+2,m[I],!0));return h}function Rs(e){"@babel/helpers - typeof";return Rs=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Rs(e)}function Gv(e){return e&&Rs(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Uv(e){var t=e&&Rs(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),r=n.getInt32(0,!0);if(r!==1&&r!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function Xv(e){var t=e.data,n=e.channels||1,r=24,s=e.bits===8?1:2,o=e.length*2*n;if(t.length!==o)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var a=r+t.length*s,i=new ArrayBuffer(a),l=new DataView(i);l.setInt32(0,2,!0),l.setUint32(4,e.bits===8,!0),l.setInt32(8,e.sample_rate,!0),l.setInt32(12,e.samples_per_pixel,!0),l.setInt32(16,e.length,!0),l.setInt32(20,n,!0);var c=r;if(e.bits===8)for(var u=0;u<t.length;u++)l.setInt8(c++,t[u],!0);else for(var f=0;f<t.length;f++)l.setInt16(c,t[f],!0),c+=2;return i}function Mn(e){return e==null}function Yv(e,t){var n=atob(e);return n}function Kv(e,t,n){var r=Yv(e),s=r.indexOf(`
857
+ `,10)+1,o=r.substring(s)+"",a=new Blob([o],{type:"application/javascript"});return URL.createObjectURL(a)}function qv(e,t,n){var r;return function(o){return r=r||Kv(e),new Worker(r,o)}}var Jv=qv("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function mt(e){if(Gv(e)&&(e=Xv(e)),Uv(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new Cn(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var tr={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function Qv(e){var t={scale:e.scale||tr.scale,bits:e.bits||tr.bits,amplitude_scale:e.amplitude_scale||tr.amplitude_scale,split_channels:e.split_channels||tr.split_channels,disable_worker:e.disable_worker||tr.disable_worker};return t}function e0(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Wd(e,t,n){var r=e0(e);if(t.disable_worker){var s=Hv({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r});n(void 0,new mt(s),e)}else{var o=new Jv;o.onmessage=function(a){n(void 0,new mt(a.data),e)},o.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r},r)}}function t0(e,t,n,r){function s(a){a||(a=new DOMException("EncodingError")),r(a),r=function(){}}var o=e.decodeAudioData(t,function(a){Wd(a,n,r)},s);o&&o.catch(s)}mt.create=function(t){return new mt(t)};mt.createFromAudio=function(e,t){var n=Qv(e);if(e.audio_context&&e.array_buffer)return t0(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Wd(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Gs(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),r=24,s=this._inputData.bits===8?1:2,o=r+n*2*this._inputData.channels*s;this._output_data=new ArrayBuffer(o),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new mt(this._output_data),this._input_index=0,this._output_index=0;var a=this._inputData.channels;this._min=new Array(a),this._max=new Array(a);for(var i=0;i<a;++i)this._input_buffer_size>0?(this._min[i]=this._inputData.channel(i).min_sample(this._input_index),this._max[i]=this._inputData.channel(i).max_sample(this._input_index)):(this._min[i]=0,this._max[i]=0);this._min_value=this._inputData.bits===8?-128:-32768,this._max_value=this._inputData.bits===8?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}Gs.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Gs.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,r;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var s=0;s<n;++s)r=this._outputWaveformData.channel(s),r.set_min_sample(this._output_index-1,this._min[s]),r.set_max_sample(this._output_index-1,this._max[s]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var o=0;o<n;++o)this._min[o]=this._max_value,this._max[o]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var a=0;a<n;++a){r=this._inputData.channel(a);var i=r.min_sample(this._input_index);i<this._min[a]&&(this._min[a]=i),i=r.max_sample(this._input_index),i>this._max[a]&&(this._max[a]=i)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var l=0;l<n;++l)r=this._outputWaveformData.channel(l),r.set_min_sample(this._output_index-1,this._min[l]),r.set_max_sample(this._output_index-1,this._max[l]);return!0};Gs.prototype.getOutputData=function(){return this._output_data};mt.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!Mn(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!Mn(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new Gs(t);!n.next(););return new mt(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(s){if(t.channels!==s.channels||t.sample_rate!==s.sample_rate||t.bits!==s.bits||t.scale!==s.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var r=this._concatBuffers.apply(this,n);return mt.create(r)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,r=n,s=0,o=[this].concat(t).map(function(m){return m._data.buffer}),a=0;a<o.length;a++){var i=o[a],l=new DataView(i).getInt32(16,!0);r+=i.byteLength-n,s+=l}for(var c=new ArrayBuffer(r),u=new DataView(o[0]),f=new DataView(c),h=0;h<n;h++)f.setUint8(h,u.getUint8(h));f.setInt32(16,s,!0);for(var d=0,p=new Uint8Array(c,n),v=0;v<o.length;v++){var y=o[v];p.set(new Uint8Array(y,n),d),d+=y.byteLength-n}return c},slice:function(t){var n=0,r=0;if(!Mn(t.startIndex)&&!Mn(t.endIndex)?(n=t.startIndex,r=t.endIndex):!Mn(t.startTime)&&!Mn(t.endTime)&&(n=this.at_time(t.startTime),r=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(r<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),r>this.length&&(r=this.length),n>r&&(n=r);var s=r-n,o=24,a=this.bits===8?1:2,i=o+s*2*this.channels*a,l=new ArrayBuffer(i),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,this.bits===8,!0),c.setInt32(8,this.sample_rate,!0),c.setInt32(12,this.scale,!0),c.setInt32(16,s,!0),c.setInt32(20,this.channels,!0);for(var u=0;u<s*this.channels*2;u++){var f=this._at(n*this.channels*2+u);this.bits===8?c.setInt8(o+u,f):c.setInt16(o+u*2,f,!0)}return new mt(l)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var r=0;r<this.channels;r++)t.data.push(this.channel(r).min_sample(n)),t.data.push(this.channel(r).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function gi(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const r=await t.arrayBuffer();return mt.create(r)}else{const r=await t.json();return mt.create(r)}}function Bd(e,t=0){const n=e.channel(t),r=e.bits,s=n.min_array(),o=n.max_array(),a=s.length,i=r===8?new Int8Array(a*2):new Int16Array(a*2);for(let l=0;l<a;l++)i[l*2]=s[l],i[l*2+1]=o[l];return{data:i,bits:r,length:a,sampleRate:e.sample_rate}}async function n0(e,t=0){const n=await gi(e);return Bd(n,t)}async function r0(e){const t=await gi(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Vd(e,t,n,r){let s=e;if(n!==void 0&&r!==void 0)if(s.scale!==t){const o=e.scale,a=t/o,i=Math.floor(n/t),l=Math.ceil((n+r)/t),c=Math.floor(i*a),u=Math.min(e.length,Math.ceil(l*a));if(c>=u)return null;s=s.slice({startIndex:c,endIndex:u}),s=s.resample({scale:t})}else{const o=Math.floor(n/t),a=Math.ceil((n+r)/t);s=s.slice({startIndex:o,endIndex:a})}else s.scale!==t&&(s=s.resample({scale:t}));return s}function s0(e,t,n=0,r,s){const o=Vd(e,t,r,s);if(o===null){const h=e.bits;return{data:h===8?new Int8Array(0):new Int16Array(0),bits:h,length:0}}const a=o.channel(n),i=o.bits,l=a.min_array(),c=a.max_array(),u=l.length,f=i===8?new Int8Array(u*2):new Int16Array(u*2);for(let h=0;h<u;h++)f[h*2]=l[h],f[h*2+1]=c[h];return{data:f,bits:i,length:u}}function Nl(e,t,n,r,s){const o=Vd(e,t,r,s);if(o===null){const u=e.bits;return{length:0,data:[],bits:u}}const a=o.channels,i=o.bits,l=[];for(let u=0;u<a;u++){const f=o.channel(u),h=f.min_array(),d=f.max_array(),p=h.length,v=i===8?new Int8Array(p*2):new Int16Array(p*2);for(let y=0;y<p;y++)v[y*2]=h[y],v[y*2+1]=d[y];l.push(v)}if(n&&l.length>1){const u=1/l.length,f=l[0].length/2,h=i===8?new Int8Array(f*2):new Int16Array(f*2);for(let d=0;d<f;d++){let p=0,v=0;for(let y=0;y<l.length;y++)p+=u*l[y][d*2],v+=u*l[y][d*2+1];h[d*2]=p,h[d*2+1]=v}return{length:f,data:[h],bits:i}}return{length:l.length>0?l[0].length/2:0,data:l,bits:i}}function Nd(){const[e,t]=g.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:s=>Ln(s,e),parseTime:s=>Rd(s,e)}}function zd({engineRef:e,initialSamplesPerPixel:t}){const[n,r]=g.useState(t),[s,o]=g.useState(!0),[a,i]=g.useState(!0),l=g.useRef(!0),c=g.useRef(!0),u=g.useRef(t),f=g.useCallback(()=>{e.current?.zoomIn()},[e]),h=g.useCallback(()=>{e.current?.zoomOut()},[e]),d=g.useCallback(p=>{p.samplesPerPixel!==u.current&&(u.current=p.samplesPerPixel,g.startTransition(()=>{r(p.samplesPerPixel)})),p.canZoomIn!==l.current&&(l.current=p.canZoomIn,o(p.canZoomIn)),p.canZoomOut!==c.current&&(c.current=p.canZoomOut,i(p.canZoomOut))},[]);return{samplesPerPixel:n,zoomIn:f,zoomOut:h,canZoomIn:s,canZoomOut:a,onEngineState:d}}function jd({engineRef:e,initialVolume:t=1}){const[n,r]=g.useState(t),s=g.useRef(t),o=g.useCallback(i=>{e.current?e.current.setMasterVolume(i):(s.current=i,r(i))},[e]),a=g.useCallback(i=>{i.masterVolume!==s.current&&(s.current=i.masterVolume,r(i.masterVolume))},[]);return{masterVolume:n,setMasterVolume:o,masterVolumeRef:s,onEngineState:a}}function o0({engineRef:e}){const[t,n]=g.useState(0),[r,s]=g.useState(0),o=g.useRef(0),a=g.useRef(0),i=g.useCallback((c,u)=>{e.current?.setSelection(c,u)},[e]),l=g.useCallback(c=>{c.selectionStart!==o.current&&(o.current=c.selectionStart,n(c.selectionStart)),c.selectionEnd!==a.current&&(a.current=c.selectionEnd,s(c.selectionEnd))},[]);return{selectionStart:t,selectionEnd:r,setSelection:i,selectionStartRef:o,selectionEndRef:a,onEngineState:l}}function a0({engineRef:e}){const[t,n]=g.useState(!1),[r,s]=g.useState(0),[o,a]=g.useState(0),i=g.useRef(!1),l=g.useRef(0),c=g.useRef(0),u=g.useCallback(p=>{e.current?.setLoopEnabled(p)},[e]),f=g.useCallback((p,v)=>{e.current?.setLoopRegion(p,v)},[e]),h=g.useCallback(()=>{e.current?.setLoopRegion(0,0)},[e]),d=g.useCallback(p=>{p.isLoopEnabled!==i.current&&(i.current=p.isLoopEnabled,n(p.isLoopEnabled)),p.loopStart!==l.current&&(l.current=p.loopStart,s(p.loopStart)),p.loopEnd!==c.current&&(c.current=p.loopEnd,a(p.loopEnd))},[]);return{isLoopEnabled:t,loopStart:r,loopEnd:o,setLoopEnabled:u,setLoopRegion:f,clearLoopRegion:h,isLoopEnabledRef:i,loopStartRef:l,loopEndRef:c,onEngineState:d}}function i0({engineRef:e}){const[t,n]=g.useState(null),r=g.useRef(null),s=g.useCallback(a=>{e.current?.selectTrack(a)},[e]),o=g.useCallback(a=>{a.selectedTrackId!==r.current&&(r.current=a.selectedTrackId,n(a.selectedTrackId))},[]);return{selectedTrackId:t,setSelectedTrackId:s,onEngineState:o,selectedTrackIdRef:r}}const l0=(e=256)=>{const t=g.useRef(null),n=g.useCallback((r,s,o)=>{const a=new F.Analyser("fft",e);return r.connect(a),r.connect(s),t.current=a,function(){a.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function c0(e,t={}){const{progressive:n=!1}=t,[r,s]=g.useState([]),[o,a]=g.useState(!0),[i,l]=g.useState(null),[c,u]=g.useState(0),f=e.length;return g.useEffect(()=>{if(e.length===0){s([]),a(!1),u(0);return}let h=!1;const d=new AbortController,p=new Map,v=(m,b,_)=>{const w=_??m.audioBuffer;if(!w&&!m.waveformData)throw new Error(`Track ${b+1}: Must provide src, audioBuffer, or waveformData`);const x=w?.duration??m.waveformData?.duration,S=ql({audioBuffer:w,startTime:m.startTime??0,duration:m.duration??x,offset:m.offset??0,name:m.name||`Track ${b+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${b+1}`);return{...Jl({name:m.name||`Track ${b+1}`,clips:[S],muted:m.muted??!1,soloed:m.soloed??!1,volume:m.volume??1,pan:m.pan??0,color:m.color}),effects:m.effects,renderMode:m.renderMode,spectrogramConfig:m.spectrogramConfig,spectrogramColorMap:m.spectrogramColorMap}};return(async()=>{try{a(!0),l(null),u(0);const m=Kl.getContext().rawContext,b=e.map(async(w,x)=>{if(w.audioBuffer){const I=v(w,x,w.audioBuffer);return n&&!h&&(p.set(x,I),u(T=>T+1),s(Array.from({length:e.length},(T,$)=>p.get($)).filter(T=>T!==void 0))),I}if(!w.src&&w.waveformData){const I=v(w,x);return n&&!h&&(p.set(x,I),u(T=>T+1),s(Array.from({length:e.length},(T,$)=>p.get($)).filter(T=>T!==void 0))),I}if(!w.src)throw new Error(`Track ${x+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(w.src,{signal:d.signal});if(!S.ok)throw new Error(`Failed to fetch ${w.src}: ${S.statusText}`);const k=await S.arrayBuffer(),E=await m.decodeAudioData(k);if(!E||!E.sampleRate||!E.duration)throw new Error(`Invalid audio buffer for ${w.src}`);const M=v(w,x,E);return n&&!h&&(p.set(x,M),u(I=>I+1),s(Array.from({length:e.length},(I,T)=>p.get(T)).filter(I=>I!==void 0))),M}),_=await Promise.all(b);h||(n||(s(_),u(_.length)),a(!1))}catch(m){if(!h){const b=m instanceof Error?m.message:"Unknown error loading audio";l(b),a(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{h=!0,d.abort()}},[e,n]),{tracks:r,loading:o,error:i,loadedCount:c,totalCount:f}}function u0({originalClip:e,clip:t,pixelDelta:n,samplesPerPixel:r,sampleRate:s,boundary:o,sortedClips:a,sortedIndex:i}){const l=n*r,c=Math.floor(.1*s),u={...t,startSample:e.startSample,offsetSamples:e.offsetSamples,durationSamples:e.durationSamples},f=sc(u,Math.floor(l),o,a,i,c);return o==="left"?{startSample:e.startSample+f,durationSamples:e.durationSamples-f,offsetSamples:e.offsetSamples+f}:{startSample:e.startSample,durationSamples:e.durationSamples+f,offsetSamples:e.offsetSamples}}function d0({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:r,engineRef:s,isDraggingRef:o}){const a=g.useRef(null),i=g.useRef(0),l=g.useCallback(f=>{const h=f.operation.source?.data;if(!h)return;if(!h.boundary){a.current=null;return}const p=e[h.trackIndex]?.clips[h.clipIndex];p&&(a.current={offsetSamples:p.offsetSamples,durationSamples:p.durationSamples,startSample:p.startSample},o.current=!0)},[e,o]),c=g.useCallback(f=>{const h=f.operation.source?.data;if(!h||!h.boundary||!a.current)return;const{boundary:d,trackIndex:p,clipIndex:v}=h,m=(f.to?.x??f.operation.position.current.x)-f.operation.position.initial.x,b=m*n,_=a.current,w=e.map((x,S)=>{if(S!==p)return x;const k=[...x.clips].sort((I,T)=>I.startSample-T.startSample),E=k.findIndex(I=>I===x.clips[v]),M=x.clips.map((I,T)=>{if(T!==v)return I;const $=u0({originalClip:_,clip:I,pixelDelta:m,samplesPerPixel:n,sampleRate:r,boundary:d,sortedClips:k,sortedIndex:E});return{...I,startSample:$.startSample,durationSamples:$.durationSamples,offsetSamples:$.offsetSamples}});return{...x,clips:M}});i.current=b,t(w)},[e,t,n,r]),u=g.useCallback(f=>{if(f.canceled){if(a.current){const b=f.operation.source?.data;if(b){const{trackIndex:_,clipIndex:w}=b,x=a.current,S=e.map((k,E)=>{if(E!==_)return k;const M=k.clips.map((I,T)=>T!==w?I:{...I,offsetSamples:x.offsetSamples,durationSamples:x.durationSamples,startSample:x.startSample});return{...k,clips:M}});t(S)}}o.current=!1,a.current=null,i.current=0;return}const h=f.operation.source?.data;if(!h)return;const{trackIndex:d,clipId:p,boundary:v}=h,y=v?i.current:f.operation.transform.x*n,m=e[d]?.id;if(v){o.current=!1,m?s.current?s.current.trimClip(m,p,v,Math.floor(y)):console.warn("[waveform-playlist] engineRef is null — trim not synced to adapter"):console.warn(`[waveform-playlist] onDragEnd: track at index ${d} not found — trim not synced to adapter`),a.current=null,i.current=0;return}m?s.current?s.current.moveClip(m,p,Math.floor(y)):console.warn("[waveform-playlist] engineRef is null — move not synced to adapter"):console.warn(`[waveform-playlist] onDragEnd: track at index ${d} not found — move not synced to adapter`)},[e,t,n,s,o]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}const yo=.01;function Zd({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:r,duration:s,linkEndpoints:o}){const a=g.useRef(null),i=g.useCallback(u=>{const f=u.operation.source?.data;if(!f||f.annotationIndex===void 0){a.current=null;return}const h=e[f.annotationIndex];h&&(a.current={start:h.start,end:h.end,annotationIndex:f.annotationIndex})},[e]),l=g.useCallback(u=>{if(!a.current)return;const f=u.operation.source?.data;if(!f)return;const{edge:h,annotationIndex:d}=f,p=a.current,m=((u.to?.x??u.operation.position.current.x)-u.operation.position.initial.x)*n/r,b=h==="start"?p.start+m:p.end+m,_=f0({annotationIndex:d,newTime:b,isDraggingStart:h==="start",annotations:e,duration:s,linkEndpoints:o});t(_)},[e,t,n,r,s,o]),c=g.useCallback(u=>{if(u.canceled&&a.current){const{annotationIndex:f,start:h,end:d}=a.current,p=e.map((v,y)=>y!==f?v:{...v,start:h,end:d});t(p)}a.current=null},[e,t]);return{onDragStart:i,onDragMove:l,onDragEnd:c}}function f0({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:r,duration:s,linkEndpoints:o}){const a=[...r],i=r[e];if(n){const l=Math.min(i.end-.1,Math.max(0,t)),c=l-i.start;if(a[e]={...i,start:l},o&&e>0){const u=a[e-1];Math.abs(u.end-i.start)<yo?a[e-1]={...u,end:Math.max(u.start+.1,u.end+c)}:l<=u.end&&(a[e]={...a[e],start:u.end})}else!o&&e>0&&l<a[e-1].end&&(a[e-1]={...a[e-1],end:l})}else{const l=Math.max(i.start+.1,Math.min(t,s)),c=l-i.end;if(a[e]={...i,end:l},o&&e<a.length-1){const u=a[e+1];if(Math.abs(u.start-i.end)<yo){const f=u.start+c;a[e+1]={...u,start:Math.min(u.end-.1,f)};let h=e+1;for(;h<a.length-1;){const d=a[h],p=a[h+1];if(Math.abs(p.start-d.end)<yo){const v=d.end-r[h].end;a[h+1]={...p,start:Math.min(p.end-.1,p.start+v)},h++}else break}}else l>=u.start&&(a[e]={...a[e],end:u.start})}else if(!o&&e<a.length-1&&l>a[e+1].start){const u=a[e+1];a[e+1]={...u,start:l};let f=e+1;for(;f<a.length-1;){const h=a[f],d=a[f+1];if(h.end>d.start)a[f+1]={...d,start:h.end},f++;else break}}}return a}function h0(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:r=5,mouseDistance:s=1}=e;return g.useMemo(()=>t?[Qo.configure({activationConstraints(o){return o.pointerType==="touch"?[new Bt.Delay({value:n,tolerance:r})]:[new Bt.Distance({value:s})]}})]:[Qo.configure({activationConstraints:[new Bt.Distance({value:s})]})],[t,n,r,s])}const p0=e=>{const{tracks:t,sampleRate:n,engineRef:r}=e,{currentTimeRef:s}=lt(),{selectedTrackId:o}=ct(),a=g.useCallback((l,c,u)=>{const{samplesPerPixel:f}=e,h=t[l];if(!h)return!1;const d=h.clips[c];if(!d)return!1;const p=Math.round(u*n),v=Uf(p,f),y=Math.floor(.1*n);if(!oc(d,v,y))return console.warn("Split point is invalid (outside bounds or too close to edge)"),!1;const m=r.current;return m?(m.splitClip(h.id,d.id,v),!0):(console.warn("[waveform-playlist] engineRef is null — split not synced to adapter"),!1)},[t,e,n,r]);return{splitClipAtPlayhead:g.useCallback(()=>{if(!o)return console.warn("[waveform-playlist] No track selected — click a clip to select a track first"),!1;const l=t.findIndex(f=>f.id===o);if(l===-1)return console.warn("Selected track not found"),!1;const c=t[l],u=s.current??0;for(let f=0;f<c.clips.length;f++){const h=c.clips[f],d=h.startSample/n,p=(h.startSample+h.durationSamples)/n;if(u>d&&u<p)return a(l,f,u)}return console.warn(`[waveform-playlist] No clip found at playhead position on track "${c.name}"`),!1},[t,s,o,a,n]),splitClipAt:a}},Ds=e=>{const{shortcuts:t,enabled:n=!0}=e,r=g.useCallback(s=>{if(!n)return;const o=s.target;if(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable)return;const a=t.find(i=>{const l=s.key.toLowerCase()===i.key.toLowerCase()||s.key===i.key,c=i.ctrlKey===void 0||s.ctrlKey===i.ctrlKey,u=i.shiftKey===void 0||s.shiftKey===i.shiftKey,f=i.metaKey===void 0||s.metaKey===i.metaKey,h=i.altKey===void 0||s.altKey===i.altKey;return l&&c&&u&&f&&h});a&&(a.preventDefault!==!1&&s.preventDefault(),a.action())},[t,n]);g.useEffect(()=>{if(n)return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}},[r,n])},m0=e=>{const t=[],n=typeof navigator<"u"&&navigator.platform.includes("Mac");return e.metaKey&&t.push(n?"Cmd":"Ctrl"),e.ctrlKey&&!e.metaKey&&t.push("Ctrl"),e.altKey&&t.push(n?"Option":"Alt"),e.shiftKey&&t.push("Shift"),t.push(e.key.toUpperCase()),t.join("+")},g0=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:r}=e,{isPlaying:s}=lt(),{setCurrentTime:o,play:a,pause:i,stop:l}=Pe(),c=g.useCallback(()=>{s?i():a()},[s,a,i]),u=g.useCallback(()=>{l()},[l]),f=g.useCallback(()=>{o(0),s&&a(0)},[s,o,a]),d=r??[...[{key:" ",action:c,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:u,description:"Stop",preventDefault:!0},{key:"0",action:f,description:"Rewind to start",preventDefault:!0}],...n];return Ds({shortcuts:d,enabled:t}),{rewindToStart:f,togglePlayPause:c,stopPlayback:u,shortcuts:d}},bo=.01,ns=.01;function v0({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:r,duration:s,linkEndpoints:o,continuousPlay:a=!1,enabled:i=!0,scrollContainerRef:l,samplesPerPixel:c,sampleRate:u,onPlay:f}){const h=g.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),d=g.useCallback(E=>{if(!l?.current||!c||!u)return;const M=e.find(Q=>Q.id===E);if(!M)return;const I=l.current,T=I.clientWidth,$=M.start*u/c,A=M.end*u/c,P=($+A)/2,W=I.scrollLeft,J=W,G=W+T;if($<J||A>G){const Q=Math.max(0,P-T/2);I.scrollTo({left:Q,behavior:"smooth"})}},[e,l,c,u]);g.useEffect(()=>{t&&l?.current&&c&&u&&d(t)},[t,d,l,c,u]);const p=g.useCallback(E=>{if(h<0)return;const M=e[h],I=Math.max(0,Math.min(M.end-.1,M.start+E)),T=I-M.start,$=[...e];if($[h]={...M,start:I},o&&h>0){const A=$[h-1];Math.abs(A.end-M.start)<bo&&($[h-1]={...A,end:Math.max(A.start+.1,A.end+T)})}else if(!o&&h>0){const A=$[h-1];I<A.end&&($[h-1]={...A,end:I})}n($)},[e,h,o,n]),v=g.useCallback(E=>{if(h<0)return;const M=e[h],I=Math.max(M.start+.1,Math.min(s,M.end+E)),T=I-M.end,$=[...e];if($[h]={...M,end:I},o&&h<e.length-1){const A=$[h+1];if(Math.abs(A.start-M.end)<bo){const P=Math.min(A.end-.1,A.start+T);$[h+1]={...A,start:P};let W=h+1;for(;W<$.length-1;){const J=$[W],G=$[W+1];if(Math.abs(G.start-e[W].end)<bo){const Q=J.end-e[W].end;$[W+1]={...G,start:Math.min(G.end-.1,G.start+Q)},W++}else break}}}else if(!o&&h<e.length-1){const A=$[h+1];if(I>A.start){$[h+1]={...A,start:I};let P=h+1;for(;P<$.length-1;){const W=$[P],J=$[P+1];if(W.end>J.start)$[P+1]={...J,start:W.end},P++;else break}}}n($)},[e,h,s,o,n]),y=g.useCallback(()=>{!r||e.length===0||(h<=0?r(e[e.length-1].id):r(e[h-1].id))},[e,h,r]),m=g.useCallback(()=>{!r||e.length===0||(h<0||h>=e.length-1?r(e[0].id):r(e[h+1].id))},[e,h,r]),b=g.useCallback(()=>{!r||e.length===0||r(e[0].id)},[e,r]),_=g.useCallback(()=>{!r||e.length===0||r(e[e.length-1].id)},[e,r]),w=g.useCallback(()=>{r&&r(null)},[r]),x=g.useCallback(()=>{if(h<0||!f)return;const E=e[h],M=a?void 0:E.end-E.start;f(E.start,M)},[e,h,a,f]),S=g.useMemo(()=>[{key:"[",action:()=>p(-ns),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>p(ns),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>v(-ns),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>v(ns),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:x,description:"Play selected annotation",preventDefault:!0}],[p,v,x]),k=g.useMemo(()=>[{key:"ArrowUp",action:y,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:y,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:m,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:m,description:"Select next annotation",preventDefault:!0},{key:"Home",action:b,description:"Select first annotation",preventDefault:!0},{key:"End",action:_,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:w,description:"Deselect annotation",preventDefault:!0}],[y,m,b,_,w]);return Ds({shortcuts:S,enabled:i&&h>=0}),Ds({shortcuts:k,enabled:i&&e.length>0&&!!r}),{moveStartBoundary:p,moveEndBoundary:v,selectPrevious:y,selectNext:m,selectFirst:b,selectLast:_,clearSelection:w,scrollToAnnotation:d,playActiveAnnotation:x}}const jr=[{id:"reverb",name:"Reverb",category:"reverb",description:"Simple convolution reverb with adjustable decay time",parameters:[{name:"decay",label:"Decay",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"s"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"freeverb",name:"Freeverb",category:"reverb",description:"Classic Schroeder/Moorer reverb with room size and dampening",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.7},{name:"dampening",label:"Dampening",type:"number",min:0,max:1e4,step:100,default:3e3,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"jcReverb",name:"JC Reverb",category:"reverb",description:"Attempt at Roland JC-120 chorus reverb emulation",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"feedbackDelay",name:"Feedback Delay",category:"delay",description:"Delay line with feedback for echo effects",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"pingPongDelay",name:"Ping Pong Delay",category:"delay",description:"Stereo delay bouncing between left and right channels",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"chorus",name:"Chorus",category:"modulation",description:"Creates thickness by layering detuned copies of the signal",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"Hz"},{name:"delayTime",label:"Delay",type:"number",min:0,max:20,step:.5,default:3.5,unit:"ms"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.7},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"phaser",name:"Phaser",category:"modulation",description:"Classic phaser effect using allpass filters",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:.5,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:6,step:1,default:3},{name:"baseFrequency",label:"Base Freq",type:"number",min:100,max:2e3,step:10,default:350,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"tremolo",name:"Tremolo",category:"modulation",description:"Rhythmic volume modulation",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:4,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"vibrato",name:"Vibrato",category:"modulation",description:"Pitch modulation effect",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:5,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoPanner",name:"Auto Panner",category:"modulation",description:"Automatic left-right panning",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoFilter",name:"Auto Filter",category:"filter",description:"Automated filter sweep with LFO",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:2e3,step:10,default:200,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:.5,max:8,step:.5,default:2.6},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoWah",name:"Auto Wah",category:"filter",description:"Envelope follower filter effect",parameters:[{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:500,step:10,default:100,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:8,step:1,default:6},{name:"sensitivity",label:"Sensitivity",type:"number",min:-40,max:0,step:1,default:0,unit:"dB"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"eq3",name:"3-Band EQ",category:"filter",description:"Three band equalizer with low, mid, and high controls",parameters:[{name:"low",label:"Low",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"mid",label:"Mid",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"high",label:"High",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"lowFrequency",label:"Low Freq",type:"number",min:20,max:500,step:10,default:400,unit:"Hz"},{name:"highFrequency",label:"High Freq",type:"number",min:1e3,max:1e4,step:100,default:2500,unit:"Hz"}]},{id:"distortion",name:"Distortion",category:"distortion",description:"Wave shaping distortion effect",parameters:[{name:"distortion",label:"Drive",type:"number",min:0,max:1,step:.01,default:.4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"bitCrusher",name:"Bit Crusher",category:"distortion",description:"Reduces bit depth for lo-fi digital texture",parameters:[{name:"bits",label:"Bits",type:"number",min:1,max:16,step:1,default:4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"chebyshev",name:"Chebyshev",category:"distortion",description:"Waveshaping distortion using Chebyshev polynomials",parameters:[{name:"order",label:"Order",type:"number",min:1,max:100,step:1,default:50},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"compressor",name:"Compressor",category:"dynamics",description:"Dynamic range compressor",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-60,max:0,step:1,default:-24,unit:"dB"},{name:"ratio",label:"Ratio",type:"number",min:1,max:20,step:.5,default:4},{name:"attack",label:"Attack",type:"number",min:0,max:1,step:.001,default:.003,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"knee",label:"Knee",type:"number",min:0,max:40,step:1,default:30,unit:"dB"}]},{id:"limiter",name:"Limiter",category:"dynamics",description:"Hard limiter to prevent clipping",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-12,max:0,step:.5,default:-6,unit:"dB"}]},{id:"gate",name:"Gate",category:"dynamics",description:"Noise gate to silence signal below threshold",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-100,max:0,step:1,default:-40,unit:"dB"},{name:"attack",label:"Attack",type:"number",min:0,max:.3,step:.001,default:.001,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:.5,step:.01,default:.1,unit:"s"}]},{id:"stereoWidener",name:"Stereo Widener",category:"spatial",description:"Expands or narrows the stereo image",parameters:[{name:"width",label:"Width",type:"number",min:0,max:1,step:.01,default:.5}]}],vi=e=>jr.find(t=>t.id===e),y0=e=>jr.filter(t=>t.category===e),b0=[{id:"reverb",name:"Reverb"},{id:"delay",name:"Delay"},{id:"modulation",name:"Modulation"},{id:"filter",name:"Filter"},{id:"distortion",name:"Distortion"},{id:"dynamics",name:"Dynamics"},{id:"spatial",name:"Spatial"}];const w0={reverb:F.Reverb,freeverb:F.Freeverb,jcReverb:F.JCReverb,feedbackDelay:F.FeedbackDelay,pingPongDelay:F.PingPongDelay,chorus:F.Chorus,phaser:F.Phaser,tremolo:F.Tremolo,vibrato:F.Vibrato,autoPanner:F.AutoPanner,autoFilter:F.AutoFilter,autoWah:F.AutoWah,eq3:F.EQ3,distortion:F.Distortion,bitCrusher:F.BitCrusher,chebyshev:F.Chebyshev,compressor:F.Compressor,limiter:F.Limiter,gate:F.Gate,stereoWidener:F.StereoWidener};let _0=0;const x0=()=>`effect_${Date.now()}_${++_0}`;function Tr(e,t){const n=w0[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const r={};e.parameters.forEach(i=>{const l=t?.[i.name]??i.default;r[i.name]=l});const s=new n(r),o=x0(),a=s;return{effect:s,id:e.id,instanceId:o,dispose(){try{s.disconnect(),s.dispose()}catch(i){console.warn(`[waveform-playlist] Error disposing effect "${e.id}" (${o}):`,i)}},setParameter(i,l){const c=a[i];if(i==="wet"){const u=a.wet;if(u&&typeof u=="object"&&"value"in u){u.value=l;return}}c!==void 0&&(c&&typeof c=="object"&&"value"in c?c.value=l:a[i]=l)},getParameter(i){if(i==="wet"){const c=a.wet;if(c&&typeof c=="object"&&"value"in c)return c.value}const l=a[i];if(l!==void 0)return l&&typeof l=="object"&&"value"in l?l.value:l},connect(i){s.connect(i)},disconnect(){try{s.disconnect()}catch(i){console.warn(`[waveform-playlist] Error disconnecting effect "${e.id}" (${o}):`,i)}}}}function C0(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function S0(e=256){const[t,n]=g.useState([]),r=g.useRef(t);r.current=t;const s=g.useRef(new Map),o=g.useRef(null),a=g.useRef(null),i=g.useCallback(y=>{const m=a.current;if(!m)return;const{masterGainNode:b,destination:_,analyserNode:w}=m;try{b.disconnect()}catch(S){console.warn("[waveform-playlist] Error disconnecting master effects chain:",S)}const x=y.map(S=>s.current.get(S.instanceId)).filter(S=>S!==void 0);if(x.length===0)b.connect(w),w.connect(_);else{let S=b;x.forEach(k=>{try{k.disconnect()}catch(E){console.warn(`[waveform-playlist] Error disconnecting effect "${k.id}":`,E)}S.connect(k.effect),S=k.effect}),S.connect(w),w.connect(_)}},[]),l=g.useCallback(y=>{const m=vi(y);if(!m){console.error(`Unknown effect: ${y}`);return}const b={};m.parameters.forEach(x=>{b[x.name]=x.default});const _=Tr(m,b);s.current.set(_.instanceId,_);const w={instanceId:_.instanceId,effectId:m.id,definition:m,params:b,bypassed:!1};n(x=>[...x,w])},[]),c=g.useCallback(y=>{const m=s.current.get(y);m&&(m.dispose(),s.current.delete(y)),n(b=>b.filter(_=>_.instanceId!==y))},[]),u=g.useCallback((y,m,b)=>{const _=s.current.get(y);_&&_.setParameter(m,b),n(w=>w.map(x=>x.instanceId===y?{...x,params:{...x.params,[m]:b}}:x))},[]),f=g.useCallback(y=>{const m=r.current.find(w=>w.instanceId===y);if(!m)return;const b=!m.bypassed,_=s.current.get(y);if(_){const w=m.params.wet??1;_.setParameter("wet",b?0:w)}n(w=>w.map(x=>x.instanceId===y?{...x,bypassed:b}:x))},[]),h=g.useCallback((y,m)=>{n(b=>{const _=[...b],[w]=_.splice(y,1);return _.splice(m,0,w),_})},[]),d=g.useCallback(()=>{s.current.forEach(y=>y.dispose()),s.current.clear(),n([])},[]);g.useEffect(()=>{i(t)},[t,i]);const p=g.useCallback((y,m,b)=>{const _=new F.Analyser("fft",e);o.current=_,a.current={masterGainNode:y,destination:m,analyserNode:_};const x=r.current.map(S=>s.current.get(S.instanceId)).filter(S=>S!==void 0);if(x.length===0)y.connect(_),_.connect(m);else{let S=y;x.forEach(k=>{S.connect(k.effect),S=k.effect}),S.connect(_),_.connect(m)}return function(){_.dispose(),o.current=null,a.current=null}},[e]);g.useEffect(()=>{const y=s.current;return()=>{y.forEach(m=>m.dispose()),y.clear()}},[]);const v=g.useCallback(()=>{const y=t.filter(m=>!m.bypassed);if(y.length!==0)return(m,b,_)=>{const w=[];for(const x of y){const S=Tr(x.definition,x.params);w.push(S)}if(w.length===0)m.connect(b);else{let x=m;w.forEach(S=>{x.connect(S.effect),x=S.effect}),x.connect(b)}return function(){w.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:jr,addEffect:l,removeEffect:c,updateParameter:u,toggleBypass:f,reorderEffects:h,clearAllEffects:d,masterEffects:p,createOfflineEffectsFunction:v,analyserRef:o}}function k0(){const[e,t]=g.useState(new Map),n=g.useRef(new Map),r=g.useRef(new Map),s=g.useCallback((d,p)=>{const v=r.current.get(d);if(!v)return;const{graphEnd:y,masterGainNode:m}=v,b=n.current.get(d);try{y.disconnect()}catch(w){console.warn(`[waveform-playlist] Error disconnecting track "${d}" effect chain:`,w)}const _=p.map(w=>b?.get(w.instanceId)).filter(w=>w!==void 0);if(_.length===0)y.connect(m);else{let w=y;_.forEach(x=>{try{x.disconnect()}catch(S){console.warn(`[waveform-playlist] Error disconnecting effect "${x.id}" on track "${d}":`,S)}w.connect(x.effect),w=x.effect}),w.connect(m)}},[]),o=g.useCallback((d,p)=>{const v=vi(p);if(!v){console.error(`Unknown effect: ${p}`);return}const y={};v.parameters.forEach(_=>{y[_.name]=_.default});const m=Tr(v,y);n.current.has(d)||n.current.set(d,new Map),n.current.get(d).set(m.instanceId,m);const b={instanceId:m.instanceId,effectId:v.id,definition:v,params:y,bypassed:!1};t(_=>{const w=new Map(_),x=w.get(d)||[];return w.set(d,[...x,b]),w})},[]),a=g.useCallback((d,p)=>{const v=n.current.get(d),y=v?.get(p);y&&(y.dispose(),v?.delete(p)),t(m=>{const b=new Map(m),_=b.get(d)||[];return b.set(d,_.filter(w=>w.instanceId!==p)),b})},[]),i=g.useCallback((d,p,v,y)=>{const b=n.current.get(d)?.get(p);b&&b.setParameter(v,y),t(_=>{const w=new Map(_),x=w.get(d)||[];return w.set(d,x.map(S=>S.instanceId===p?{...S,params:{...S.params,[v]:y}}:S)),w})},[]),l=g.useCallback((d,p)=>{const y=(u.current.get(d)||[]).find(w=>w.instanceId===p);if(!y)return;const m=!y.bypassed,_=n.current.get(d)?.get(p);if(_){const w=y.params.wet??1;_.setParameter("wet",m?0:w)}t(w=>{const x=new Map(w),S=x.get(d)||[];return x.set(d,S.map(k=>k.instanceId===p?{...k,bypassed:m}:k)),x})},[]),c=g.useCallback(d=>{const p=n.current.get(d);p&&(p.forEach(v=>v.dispose()),p.clear()),t(v=>{const y=new Map(v);return y.set(d,[]),y})},[]),u=g.useRef(e);u.current=e;const f=g.useCallback(d=>(p,v,y)=>{r.current.set(d,{graphEnd:p,masterGainNode:v});const m=u.current.get(d)||[],b=n.current.get(d),_=m.map(w=>b?.get(w.instanceId)).filter(w=>w!==void 0);if(_.length===0)p.connect(v);else{let w=p;_.forEach(x=>{w.connect(x.effect),w=x.effect}),w.connect(v)}return function(){r.current.delete(d)}},[]);g.useEffect(()=>{e.forEach((d,p)=>{s(p,d)})},[e,s]),g.useEffect(()=>{const d=n.current;return()=>{d.forEach(p=>{p.forEach(v=>v.dispose()),p.clear()}),d.clear()}},[]);const h=g.useCallback(d=>{const v=(e.get(d)||[]).filter(y=>!y.bypassed);if(v.length!==0)return(y,m,b)=>{const _=[];for(const w of v){const x=Tr(w.definition,w.params);_.push(x)}if(_.length===0)y.connect(m);else{let w=y;_.forEach(x=>{w.connect(x.effect),w=x.effect}),w.connect(m)}return function(){_.forEach(x=>x.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:o,removeEffectFromTrack:a,updateTrackEffectParameter:i,toggleBypass:l,clearTrackEffects:c,getTrackEffectsFunction:f,createOfflineTrackEffectsFunction:h,availableEffects:jr}}function E0(e,t={}){const{bitDepth:n=16}=t,r=e.numberOfChannels,s=e.sampleRate,o=e.length,a=n/8,i=r*a,l=s*i,c=o*i,u=44,f=u+c,h=new ArrayBuffer(f),d=new DataView(h);rs(d,0,"RIFF"),d.setUint32(4,f-8,!0),rs(d,8,"WAVE"),rs(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,n===32?3:1,!0),d.setUint16(22,r,!0),d.setUint32(24,s,!0),d.setUint32(28,l,!0),d.setUint16(32,i,!0),d.setUint16(34,n,!0),rs(d,36,"data"),d.setUint32(40,c,!0);const p=[];for(let y=0;y<r;y++)p.push(e.getChannelData(y));let v=u;if(n===16)for(let y=0;y<o;y++)for(let m=0;m<r;m++){const b=p[m][y],_=Math.max(-1,Math.min(1,b)),w=_<0?_*32768:_*32767;d.setInt16(v,w,!0),v+=2}else for(let y=0;y<o;y++)for(let m=0;m<r;m++)d.setFloat32(v,p[m][y],!0),v+=4;return new Blob([h],{type:"audio/wav"})}function rs(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}function I0(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function Hd(){const[e,t]=g.useState(!1),[n,r]=g.useState(0),[s,o]=g.useState(null);return{exportWav:g.useCallback(async(i,l,c={})=>{const{filename:u="export",mode:f="master",trackIndex:h,autoDownload:d=!0,applyEffects:p=!0,effectsFunction:v,createOfflineTrackEffects:y,bitDepth:m=16,onProgress:b}=c;t(!0),r(0),o(null);try{if(i.length===0)throw new Error("No tracks to export");if(f==="individual"&&(h===void 0||h<0||h>=i.length))throw new Error("Invalid track index for individual export");const _=i[0].clips[0]?.sampleRate||44100;let w=0;for(const T of i)for(const $ of T.clips){const A=$.startSample+$.durationSamples;w=Math.max(w,A)}w+=Math.round(_*.1);const x=w/_,S=f==="individual"?[{track:i[h],state:l[h],index:h}]:i.map((T,$)=>({track:T,state:l[$],index:$})),k=l.some(T=>T.soloed),E=!!y;let M;if((v||E)&&p)M=await M0(S,l,k,x,_,v,y,T=>{r(T),b?.(T)});else{const T=new OfflineAudioContext(2,w,_);let $=0;const A=S.reduce((P,{track:W})=>P+W.clips.length,0);for(const{track:P,state:W}of S)if(!(W.muted&&!W.soloed)&&!(k&&!W.soloed))for(const J of P.clips){await T0(T,J,W,_,p),$++;const G=$/A*.5;r(G),b?.(G)}r(.5),b?.(.5),M=await T.startRendering()}r(.9),b?.(.9);const I=E0(M,{bitDepth:m});if(r(1),b?.(1),d){const T=f==="individual"?`${u}_${i[h].name}`:u;I0(I,`${T}.wav`)}return{audioBuffer:M,blob:I,duration:x}}catch(_){const w=_ instanceof Error?_.message:"Export failed";throw o(w),_}finally{t(!1)}},[]),isExporting:e,progress:n,error:s}}async function M0(e,t,n,r,s,o,a,i){const{Offline:l,Volume:c,Gain:u,Panner:f,Player:h,ToneAudioBuffer:d}=await import("tone");i(.1);let p;try{p=await l(async({transport:v,destination:y})=>{const m=new c(0);let b;o?b=o(m,y,!0):m.connect(y);for(const{track:_,state:w}of e){if(w.muted&&!w.soloed||n&&!w.soloed)continue;const x=new c(A0(w.volume)),S=new f(w.pan),k=new u(w.muted?0:1),E=a?.(_.id);E?E(k,m,!0):k.connect(m),S.connect(k),x.connect(S);for(const M of _.clips){const{audioBuffer:I,startSample:T,durationSamples:$,offsetSamples:A,gain:P,fadeIn:W,fadeOut:J}=M,G=T/s,Q=$/s,ee=A/s,z=new d(I),se=new h(z),U=new u(P);if(se.connect(U),U.connect(x),W){const ie=G,le=G+W.duration,ge=wr(U.gain);ge&&(ge.setValueAtTime(0,ie),ge.linearRampToValueAtTime(P,le))}if(J){const ie=G+Q-J.duration,le=G+Q,ge=wr(U.gain);ge&&(ge.setValueAtTime(P,ie),ge.linearRampToValueAtTime(0,le))}se.start(G,ee,Q)}}v.start(0)},r,2,s)}catch(v){throw v instanceof Error?v:new Error(`Tone.Offline rendering failed: ${String(v)}`)}return i(.9),p.get()}function A0(e){return 20*Math.log10(Math.max(e,1e-4))}async function T0(e,t,n,r,s){const{audioBuffer:o,startSample:a,durationSamples:i,offsetSamples:l,gain:c,fadeIn:u,fadeOut:f}=t;if(!o){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const h=a/r,d=i/r,p=l/r,v=e.createBufferSource();v.buffer=o;const y=e.createGain(),m=c*n.volume,b=e.createStereoPanner();if(b.pan.value=n.pan,v.connect(y),y.connect(b),b.connect(e.destination),s){if(u?y.gain.setValueAtTime(0,h):y.gain.setValueAtTime(m,h),u){const _=h,w=h+u.duration;zl(y.gain,_,w,0,m,u.type||"linear")}if(f){const _=h+d-f.duration,w=h+d;(!u||u.duration<d-f.duration)&&y.gain.setValueAtTime(m,_),zl(y.gain,_,w,m,0,f.type||"linear")}}else y.gain.setValueAtTime(m,h);v.start(h,p,d)}function zl(e,t,n,r,s,o){const a=n-t;if(!(a<=0))switch(o){case"linear":e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,n);break;case"exponential":{const i=Math.max(r,1e-4),l=Math.max(s,1e-4);e.setValueAtTime(i,t),e.exponentialRampToValueAtTime(l,n),s===0&&e.setValueAtTime(0,n);break}case"logarithmic":{const i=jl(r,s,256,"logarithmic");e.setValueCurveAtTime(i,t,a);break}case"sCurve":{const i=jl(r,s,256,"sCurve");e.setValueCurveAtTime(i,t,a);break}default:e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,n)}}function jl(e,t,n,r){const s=new Float32Array(n),o=t-e;for(let a=0;a<n;a++){const i=a/(n-1);let l;r==="logarithmic"?o>0?l=Math.log10(1+i*9)/Math.log10(10):l=1-Math.log10(1+(1-i)*9)/Math.log10(10):l=i*i*(3-2*i),s[a]=e+o*l}return s}const Gd=()=>{const e=g.useRef(null),t=g.useCallback(()=>{e.current!==null&&(cancelAnimationFrame(e.current),e.current=null)},[]),n=g.useCallback(r=>{t(),e.current=requestAnimationFrame(r)},[t]);return g.useEffect(()=>()=>{t()},[t]),{animationFrameRef:e,startAnimationFrameLoop:n,stopAnimationFrameLoop:t}},$0=`
863
858
  "use strict";
864
859
 
865
860
  var INT8_MAX = 127;
@@ -1006,13 +1001,13 @@ self.onmessage = function(e) {
1006
1001
  self.postMessage({ id: msg.id, error: err.message || String(err) });
1007
1002
  }
1008
1003
  };
1009
- `;let T0=0;function $0(){let e;try{const r=new Blob([A0],{type:"application/javascript"}),s=URL.createObjectURL(r);e=new Worker(s),URL.revokeObjectURL(s)}catch(r){return console.warn("[waveform-playlist] Failed to create peaks worker (CSP restriction?):",r),{generate(){return Promise.reject(new Error("Worker creation failed"))},terminate(){}}}const t=new Map;let n=!1;return e.onmessage=r=>{const s=r.data,o=t.get(s.id);if(o)if(t.delete(s.id),s.error)o.reject(new Error(s.error));else try{const a=mt.create(s.buffer);o.resolve(a)}catch(a){o.reject(a)}},e.onerror=r=>{n=!0,e.terminate();for(const[,s]of t)s.reject(r.error??new Error(r.message));t.clear()},{generate(r){if(n)return Promise.reject(new Error("Worker terminated"));const s=String(++T0);return new Promise((o,a)=>{t.set(s,{resolve:o,reject:a}),e.postMessage({id:s,scale:r.scale,bits:r.bits,amplitude_scale:1,split_channels:r.splitChannels,length:r.length,sample_rate:r.sampleRate,channels:r.channels},r.channels)})},terminate(){n=!0,e.terminate();for(const[,r]of t)r.reject(new Error("Worker terminated"));t.clear()}}}function R0(e,t){const[n,r]=g.useState(()=>new Map),[s,o]=g.useState(!1),a=g.useRef(null),i=g.useRef(new WeakMap),l=g.useRef(new WeakMap),c=g.useRef(new WeakMap),u=g.useRef(0),f=g.useCallback(()=>(a.current||(a.current=$0()),a.current),[]);return g.useEffect(()=>{let h=!1;const d=i.current,p=l.current,v=c.current,y=[],m=new Map;for(const _ of e)for(const w of _.clips){if(!w.audioBuffer||w.waveformData)continue;const x=d.get(w.audioBuffer);if(x){y.push({clipId:w.id,waveformData:x});continue}if(p.get(w.audioBuffer)){const k=v.get(w.audioBuffer);k?k.add(w.id):v.set(w.audioBuffer,new Set([w.id]));continue}const S=m.get(w.audioBuffer);S?S.add(w.id):m.set(w.audioBuffer,new Set([w.id]))}if(y.length>0&&r(_=>{const w=new Map(_);for(const x of y)w.set(x.clipId,x.waveformData);return w}),m.size===0)return;u.current+=m.size,o(!0);const b=f();for(const[_,w]of m){v.set(_,new Set(w));const x=[];for(let E=0;E<_.numberOfChannels;E++)x.push(_.getChannelData(E).slice().buffer);const S=`buffer-${Math.random().toString(36).slice(2,11)}`,k=b.generate({id:S,channels:x,length:_.length,sampleRate:_.sampleRate,scale:t,bits:16,splitChannels:!0}).then(E=>{d.set(_,E);const T=v.get(_)??new Set;v.delete(_),p.delete(_),!h&&(r(I=>{const M=new Map(I);for(const $ of T)M.set($,E);return M}),u.current--,u.current<=0&&(u.current=0,o(!1)))}).catch(E=>{v.delete(_),p.delete(_),!h&&(console.warn("[waveform-playlist] Worker peak generation failed:",E),u.current--,u.current<=0&&(u.current=0,o(!1)))});p.set(_,k)}return()=>{h=!0,l.current=new WeakMap,c.current=new WeakMap,u.current=0,o(!1)}},[e,t,f]),g.useEffect(()=>()=>{a.current?.terminate(),a.current=null},[]),{cache:n,isGenerating:s}}function aa(e){return e instanceof File?e.name.replace(/\.[^/.]+$/,""):e instanceof Blob?"Untitled":typeof e=="string"?e.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled":e.name??e.src.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled"}async function D0(e,t,n){const r=aa(e);if(e instanceof Blob){const l=await e.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(l),name:r}}const s=typeof e=="string"?e:e.src,o=await fetch(s,{signal:n});if(!o.ok)throw new Error(`Failed to fetch ${s}: ${o.statusText}`);const a=await o.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(a),name:r}}function P0(){const[e,t]=g.useState([]),[n,r]=g.useState(0),[s,o]=g.useState([]),a=g.useRef(!1),i=g.useRef(new Set),l=g.useRef(new Map);g.useEffect(()=>{const f=l.current;return()=>{a.current=!0;for(const h of f.values())h.abort();f.clear()}},[]);const c=g.useCallback(f=>{if(f.length===0)return;const h=Zf(),d=f.map(p=>({track:Ql({name:`${aa(p)} (loading...)`,clips:[]}),source:p}));t(p=>[...p,...d.map(v=>v.track)]),r(p=>p+f.length);for(const{track:p,source:v}of d){i.current.add(p.id);const y=new AbortController;l.current.set(p.id,y),(async()=>{try{const{audioBuffer:m,name:b}=await D0(v,h,y.signal),_=Jl({audioBuffer:m,startTime:0,duration:m.duration,offset:0,name:b});!a.current&&i.current.has(p.id)&&t(w=>w.map(x=>x.id===p.id?{...x,name:b,clips:[_]}:x))}catch(m){if(m instanceof DOMException&&m.name==="AbortError")return;console.warn("[waveform-playlist] Error loading audio:",m),!a.current&&i.current.has(p.id)&&(t(b=>b.filter(_=>_.id!==p.id)),o(b=>[...b,{name:aa(v),error:m instanceof Error?m:new Error(String(m))}]))}finally{l.current.delete(p.id),!a.current&&i.current.delete(p.id)&&r(m=>m-1)}})()}},[]),u=g.useCallback(f=>{t(d=>d.filter(p=>p.id!==f));const h=l.current.get(f);h&&(h.abort(),l.current.delete(f)),i.current.delete(f)&&r(d=>d-1)},[]);return{tracks:e,addTracks:c,removeTrack:u,loadingCount:n,isLoading:n>0,errors:s}}const Gd=g.createContext(null),Ud=g.createContext(null),Xd=g.createContext(null),Yd=g.createContext(null),F0=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:r=80,samplesPerPixel:s=1024,zoomLevels:o,automaticScroll:a=!1,theme:i,controls:l={show:!1,width:0},annotationList:c,effects:u,onReady:f,onAnnotationUpdate:h,onAnnotationsChange:d,barWidth:p=1,barGap:v=0,progressBarWidth:y,onTracksChange:m,soundFontCache:b,children:_})=>{const w=y??p+v,x=g.useMemo(()=>o,[o?.join(",")]),S=g.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const L=c.annotations[0];if(typeof L.start!="number"||typeof L.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof L.start),[]}return c.annotations},[c?.annotations]),k=g.useRef(S);k.current=S;const[E,T]=g.useState(null),[I,M]=g.useState(!1),[$,A]=g.useState(0),[R,W]=g.useState(0),[q,z]=g.useState([]),[J,ee]=g.useState([]),[j,se]=g.useState([]),[U,ie]=g.useState(a),[le,ge]=g.useState(c?.isContinuousPlay??!1),[Se,N]=g.useState(c?.linkEndpoints??!1),[G,ye]=g.useState(c?.editable??!1),[Z,Q]=g.useState(!1),O=g.useRef(null),_e=g.useRef(!1),Ne=g.useRef(!1);Ne.current=I;const Be=g.useRef(0),ve=g.useRef(0),Ve=g.useRef(e),ne=g.useRef(b);ne.current=b;const Ge=g.useRef(j),je=g.useRef(0),xe=g.useRef(0),Fe=g.useRef(null),Oe=g.useRef(null),Et=g.useRef(!1),It=g.useRef(c?.isContinuousPlay??!1),Mt=g.useRef(null),X=g.useRef(null),fe=g.useRef(0),Ue=g.useRef(!1),Me=g.useRef(!1),oe=g.useRef(s),he=g.useRef(44100),{timeFormat:Xe,setTimeFormat:At,formatTime:Tt}=Vd(),ut=Nd({engineRef:O,initialSamplesPerPixel:s}),{samplesPerPixel:yt,onEngineState:V}=ut,Y=zd({engineRef:O,initialVolume:1}),{masterVolume:K,setMasterVolume:ce,masterVolumeRef:Ae,onEngineState:Ze}=Y,{selectionStart:te,selectionEnd:Ke,setSelection:Qe,selectionStartRef:Te,selectionEndRef:dt,onEngineState:Lt}=s0({engineRef:O}),{isLoopEnabled:rn,loopStart:sn,loopEnd:Ht,setLoopEnabled:qn,setLoopRegion:kn,clearLoopRegion:Hr,isLoopEnabledRef:xi,loopStartRef:Ci,loopEndRef:Si,onEngineState:ki}=o0({engineRef:O}),{selectedTrackId:Ei,setSelectedTrackId:Ii,onEngineState:Mi,selectedTrackIdRef:Ai}=a0({engineRef:O}),{animationFrameRef:Ti,startAnimationFrameLoop:Js,stopAnimationFrameLoop:Gr}=Hd(),bf=g.useMemo(()=>Math.min(...x??[256,512,1024,2048,4096,8192]),[x]),{cache:$i}=R0(e,bf),Ri=g.useCallback(L=>{It.current=L,ge(L)},[]),Wt=g.useCallback(L=>{Mt.current=L,T(L)},[]),Di=g.useCallback(()=>{const L=Te.current??0,H=dt.current??0;L!==H&&H>L&&kn(L,H)},[kn,Te,dt]);g.useEffect(()=>{Et.current=U},[U]),g.useEffect(()=>{Ge.current=j},[j]),Ve.current=e;const Qs=e===X.current;Ue.current=Qs||Me.current,g.useEffect(()=>{if(!Oe.current||R===0)return;const L=Oe.current,H=oe.current,pe=yt;if(H===pe)return;const B=L.clientWidth,Ee=L.scrollLeft+B/2,et=he.current,ro=Ee*H/et*et/pe,so=Math.max(0,ro-B/2);L.scrollLeft=so,oe.current=pe},[yt,R]);const Ur=g.useRef(null);g.useEffect(()=>{if(Qs||Me.current){Qs&&(X.current=null);let B=0;e.forEach($e=>{$e.clips.forEach(Ee=>{const et=(Ee.startSample+Ee.durationSamples)/Ee.sampleRate;B=Math.max(B,et)})}),W(B);return}if(Q(!1),e.length===0){z([]),W(0),se([]),ee([]),O.current&&(O.current.dispose(),O.current=null);return}const L=Ne.current,H=ve.current;return O.current&&L&&(O.current.stop(),Gr(),Ur.current={position:H}),(async()=>{try{const B=performance.now(),$e=[];e.forEach(ke=>{ke.clips.length>0&&ke.clips[0].audioBuffer&&$e.push(ke.clips[0].audioBuffer)});let Ee=0;e.forEach(ke=>{ke.clips.forEach(ht=>{const Gt=ht.sampleRate,Ef=(ht.startSample+ht.durationSamples)/Gt;Ee=Math.max(Ee,Ef)})}),z($e),W(Ee),se(ke=>ke.length===e.length?ke.map((ht,Gt)=>({...ht,name:e[Gt].name})):e.map(ht=>({name:ht.name,muted:ht.muted,soloed:ht.soloed,volume:ht.volume,pan:ht.pan}))),O.current&&O.current.dispose(),fe.current=0,X.current=null,_e.current=!1;const et=Hf({effects:u,soundFontCache:ne.current}),bt=new Jf({adapter:et,samplesPerPixel:oe.current,zoomLevels:x});bt.setSelection(Te.current??0,dt.current??0),bt.setLoopRegion(Ci.current??0,Si.current??0),xi.current&&bt.setLoopEnabled(!0),bt.setMasterVolume(Ae.current??1),Ai.current&&bt.selectTrack(Ai.current);const ro=Ge.current,so=e.map((ke,ht)=>{const Gt=ro[ht];return{...ke,volume:Gt?.volume??ke.volume,muted:Gt?.muted??ke.muted,soloed:Gt?.soloed??ke.soloed,pan:Gt?.pan??ke.pan}});let Xi=!0;bt.on("statechange",ke=>{Lt(ke),ki(ke),Mi(ke),V(ke),Ze(ke),!Xi&&ke.tracksVersion!==fe.current&&(fe.current=ke.tracksVersion,X.current=ke.tracks,m?m(ke.tracks):console.warn("[waveform-playlist] Engine tracks changed but onTracksChange prop is not set — UI will revert on next render. Pass onTracksChange to WaveformPlaylistProvider."))}),bt.setTracks(so),Xi=!1,fe.current=bt.getState().tracksVersion,O.current=bt,Q(!0),console.log(`[engine] rebuild: ${e.length} tracks, ${(performance.now()-B).toFixed(1)}ms`);const kf=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:Ee}});window.dispatchEvent(kf),f?.()}catch(B){console.error("Error loading audio:",B)}})(),()=>{if(Ue.current){Ue.current=!1;return}Gr(),O.current&&O.current.dispose()}},[e,f,u,Gr,Lt,ki,Mi,V,Ze,m,Ae,Te,dt,Ci,Si,xi,x,b]),g.useEffect(()=>{if(e.length===0)return;const L=e.map(H=>H.clips.map(B=>{let $e;if(B.waveformData)try{$e=zl(B.waveformData,yt,n,B.offsetSamples,B.durationSamples)}catch(Ee){console.warn("[waveform-playlist] Failed to extract peaks from waveformData:",Ee)}if(!$e){const Ee=$i.get(B.id);if(Ee)try{$e=zl(Ee,yt,n,B.offsetSamples,B.durationSamples)}catch(et){console.warn("[waveform-playlist] Failed to extract peaks from cache:",et)}}if(!$e){!B.audioBuffer&&!B.waveformData&&!B.midiNotes&&console.warn(`[waveform-playlist] Clip "${B.id}" has no audio data or waveform data`);const Ee=n?1:B.audioBuffer?.numberOfChannels??1,et=B.midiNotes?Math.ceil(B.durationSamples/yt):0;$e={length:et,data:Array.from({length:Ee},()=>new Int16Array(et*2)),bits:16}}return{clipId:B.id,trackName:H.name,peaks:$e,startSample:B.startSample,durationSamples:B.durationSamples,fadeIn:B.fadeIn,fadeOut:B.fadeOut,midiNotes:B.midiNotes,sampleRate:B.sampleRate,offsetSamples:B.offsetSamples}}));ee(L)},[e,yt,n,$i]);const Pi=g.useRef(!1),En=g.useCallback(()=>{if(O.current)return O.current.getCurrentTime();Pi.current||(Pi.current=!0,console.warn("[waveform-playlist] getPlaybackTime called without engine. Falling back to manual elapsed time (loop wrapping will not work)."));const L=F.getContext().currentTime-(je.current??0);return(xe.current??0)+L},[]),on=g.useCallback(()=>{const L=()=>{const H=En();ve.current=H;const pe=k.current;if(pe.length>0){const B=pe.find($e=>H>=$e.start&&H<$e.end);if(It.current)B&&B.id!==Mt.current?Wt(B.id):!B&&Mt.current!==null&&Wt(null);else if(Mt.current){const $e=pe.find(Ee=>Ee.id===Mt.current);if($e&&H>=$e.end){O.current&&O.current.stop(),M(!1),ve.current=Be.current,A(Be.current);return}}else B&&Wt(B.id)}if(Et.current&&Oe.current&&R>0){const B=Oe.current,$e=he.current,Ee=H*$e/oe.current,et=B.clientWidth,bt=Math.max(0,Ee-et/2);B.scrollLeft=bt}if(Fe.current!==null&&H>=Fe.current){O.current&&O.current.stop(),M(!1),ve.current=Fe.current,A(Fe.current),Fe.current=null;return}if(H>=R){O.current&&O.current.stop(),M(!1),ve.current=Be.current,A(Be.current),Wt(null);return}Js(L)};Js(L)},[R,Wt,Js,En]),ft=Gr;g.useEffect(()=>{(async()=>{if(I&&Ti.current&&O.current)if(le){const H=ve.current;O.current.stop(),ft();const B=F.getContext().currentTime;je.current=B,xe.current=H,O.current.play(H),on()}else ft(),on()})().catch(H=>{console.warn("[waveform-playlist] Failed to reschedule playback:",H),M(!1),ft()})},[le,I,on,ft,Ti]),g.useEffect(()=>{(async()=>{if(Ur.current&&O.current){const{position:H}=Ur.current;Ur.current=null;const B=F.getContext().currentTime;je.current=B,xe.current=H,_e.current||(await O.current.init(),_e.current=!0),O.current.play(H),M(!0),on()}})().catch(H=>{console.warn("[waveform-playlist] Failed to resume playback after track change:",H),M(!1),ft()})},[e,on,ft]);const Xr=g.useCallback(async(L,H)=>{if(!O.current||R===0)return;const pe=L??ve.current;Be.current=pe,ve.current=pe,O.current.stop(),O.current.seek(pe),ft();const $e=F.getContext().currentTime;je.current=$e,xe.current=pe,Fe.current=H!==void 0?pe+H:null,_e.current||(await O.current.init(),_e.current=!0);const Ee=H!==void 0?pe+H:void 0;try{O.current.play(pe,Ee)}catch(et){console.warn("[waveform-playlist] Playback failed to start:",et),ft();return}M(!0),on()},[R,on,ft]),Fi=g.useCallback(()=>{if(!O.current)return;const L=En();O.current.pause(),M(!1),ft(),ve.current=L,A(L)},[ft,En]),Oi=g.useCallback(()=>{O.current&&(O.current.stop(),M(!1),ft(),ve.current=Be.current,A(Be.current),Wt(null))},[ft,Wt]),Li=g.useCallback(L=>{const H=Math.max(0,Math.min(L,R));ve.current=H,A(H),I&&O.current&&Xr(H)},[R,I,Xr]),Wi=g.useCallback((L,H)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...j];B[L]={...B[L],muted:H},se(B),O.current&&O.current.setTrackMute(pe,H)},[j]),Bi=g.useCallback((L,H)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...j];B[L]={...B[L],soloed:H},se(B),O.current&&O.current.setTrackSolo(pe,H)},[j]),Vi=g.useCallback((L,H)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...j];B[L]={...B[L],volume:H},se(B),O.current&&O.current.setTrackVolume(pe,H)},[j]),Ni=g.useCallback((L,H)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...j];B[L]={...B[L],pan:H},se(B),O.current&&O.current.setTrackPan(pe,H)},[j]),zi=g.useCallback((L,H)=>{Qe(L,H),ve.current=L,A(L),I&&O.current&&(O.current.stop(),O.current.seek(L),O.current.play(L))},[I,Qe]),ji=g.useCallback(L=>{Oe.current=L},[]),eo=g.useRef(d);eo.current=d;const Zi=g.useCallback(L=>{const H=typeof L=="function"?L(k.current):L;if(!eo.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}eo.current(H)},[]),to=q[0]?.sampleRate||e[0]?.clips[0]?.sampleRate||44100;he.current=to;const no=t?30:0,Hi=e.length*r+no,wf=g.useMemo(()=>({isPlaying:I,currentTime:$,currentTimeRef:ve,playbackStartTimeRef:je,audioStartPositionRef:xe,getPlaybackTime:En}),[I,$,ve,je,xe,En]),_f=g.useMemo(()=>({continuousPlay:le,linkEndpoints:Se,annotationsEditable:G,isAutomaticScroll:U,isLoopEnabled:rn,annotations:S,activeAnnotationId:E,selectionStart:te,selectionEnd:Ke,selectedTrackId:Ei,loopStart:sn,loopEnd:Ht}),[le,Se,G,U,rn,S,E,te,Ke,Ei,sn,Ht]),Gi=g.useCallback(L=>{ve.current=L,A(L)},[ve]),Ui=g.useCallback(L=>{ie(L)},[]),xf=g.useMemo(()=>({play:Xr,pause:Fi,stop:Oi,seekTo:Li,setCurrentTime:Gi,setTrackMute:Wi,setTrackSolo:Bi,setTrackVolume:Vi,setTrackPan:Ni,setSelection:zi,setSelectedTrackId:Ii,setTimeFormat:At,formatTime:Tt,zoomIn:ut.zoomIn,zoomOut:ut.zoomOut,setMasterVolume:ce,setAutomaticScroll:Ui,setScrollContainer:ji,scrollContainerRef:Oe,setContinuousPlay:Ri,setLinkEndpoints:N,setAnnotationsEditable:ye,setAnnotations:Zi,setActiveAnnotationId:Wt,setLoopEnabled:qn,setLoopRegion:kn,setLoopRegionFromSelection:Di,clearLoopRegion:Hr}),[Xr,Fi,Oi,Li,Gi,Wi,Bi,Vi,Ni,zi,Ii,At,Tt,ut.zoomIn,ut.zoomOut,ce,Ui,ji,Oe,Ri,N,ye,Zi,Wt,qn,kn,Di,Hr]),Cf=g.useMemo(()=>({duration:R,audioBuffers:q,peaksDataArray:J,trackStates:j,tracks:e,sampleRate:to,waveHeight:r,timeScaleHeight:no,minimumPlaylistHeight:Hi,controls:l,playoutRef:O,samplesPerPixel:yt,timeFormat:Xe,masterVolume:K,canZoomIn:ut.canZoomIn,canZoomOut:ut.canZoomOut,barWidth:p,barGap:v,progressBarWidth:w,isReady:Z,mono:n,isDraggingRef:Me}),[R,q,J,j,e,to,r,no,Hi,l,O,yt,Xe,K,ut.canZoomIn,ut.canZoomOut,p,v,w,Z,n,Me]),Sf={...kd,...i};return C.jsx(P.ThemeProvider,{theme:Sf,children:C.jsx(Gd.Provider,{value:wf,children:C.jsx(Ud.Provider,{value:_f,children:C.jsx(Xd.Provider,{value:xf,children:C.jsx(Yd.Provider,{value:Cf,children:_})})})})})},lt=()=>{const e=g.useContext(Gd);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},ct=()=>{const e=g.useContext(Ud);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},Pe=()=>{const e=g.useContext(Xd);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},vt=()=>{const e=g.useContext(Yd);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e};var O0=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate;const t=this.audioElement;"preservesPitch"in this.audioElement?t.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?t.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(t.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},L0=class{constructor(e={}){this.track=null,this._isPlaying=!1,this._masterVolume=e.masterVolume??1,this._playbackRate=e.playbackRate??1}async init(){}addTrack(e){return this.track&&(console.warn("MediaElementPlayout: Only one track is supported. Disposing previous track. For multi-track, use TonePlayout."),this.track.dispose()),this.track=new O0({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const r=t??0;if(this._isPlaying=!0,this.track.play(r),n!==void 0){const s=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},s*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const Kd=g.createContext(null),qd=g.createContext(null),Jd=g.createContext(null),Qd=g.createContext(null),W0=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:r=!1,playbackRate:s=1,automaticScroll:o=!1,theme:a,controls:i={show:!1,width:0},annotationList:l,barWidth:c=1,barGap:u=0,progressBarWidth:f,onAnnotationsChange:h,onReady:d,children:p})=>{const v=f??c+u,[y,m]=g.useState(!1),[b,_]=g.useState(0),[w,x]=g.useState(0),[S,k]=g.useState([]),[E,T]=g.useState(s),I=g.useMemo(()=>{if(!l?.annotations)return[];if(process.env.NODE_ENV!=="production"&&l.annotations.length>0){const X=l.annotations[0];if(typeof X.start!="number"||typeof X.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof X.start),[]}return l.annotations},[l?.annotations]),M=g.useRef(I);M.current=I;const[$,A]=g.useState(null),[R,W]=g.useState(l?.isContinuousPlay??!1),[q]=g.useState(t),[z,J]=g.useState(o),ee=g.useRef(null),j=g.useRef(0),se=g.useRef(R),U=g.useRef(null),ie=g.useRef(null),le=g.useRef(o),ge=g.useRef(t),{startAnimationFrameLoop:Se,stopAnimationFrameLoop:N}=Hd();g.useEffect(()=>{se.current=R},[R]),g.useEffect(()=>{le.current=z},[z]);const G=g.useCallback(X=>{U.current=X,A(X)},[]),ye=g.useCallback(X=>{se.current=X,W(X)},[]),Z=g.useCallback(X=>{ie.current=X},[]),Q=e.waveformData.sample_rate;g.useEffect(()=>{const X=new L0({playbackRate:s});X.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const fe=X.getTrack(X.track?.id??"");return fe&&fe.setOnTimeUpdateCallback(Ue=>{j.current=Ue}),X.setOnPlaybackComplete(()=>{N(),m(!1),G(null),j.current=0,_(0)}),ee.current=X,x(e.waveformData.duration),d?.(),()=>{N(),X.dispose()}},[e.source,e.waveformData,e.name,s,d,N,G]),g.useEffect(()=>{try{const X=r0(e.waveformData,q,0,0,Math.ceil(e.waveformData.duration*Q)),fe={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:X.length,data:[X.data],bits:X.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*Q)};k([[fe]])}catch(X){console.warn("[waveform-playlist] Failed to extract peaks from waveform data:",X)}},[e.waveformData,e.name,q,Q]);const O=g.useCallback(()=>{const X=()=>{const fe=ee.current?.getCurrentTime()??0;j.current=fe;const Ue=M.current;if(Ue.length>0){const Me=Ue.find(oe=>fe>=oe.start&&fe<oe.end);if(se.current)Me&&Me.id!==U.current?G(Me.id):!Me&&U.current!==null&&G(null);else if(U.current){const oe=Ue.find(he=>he.id===U.current);if(oe&&fe>=oe.end){ee.current?.stop(),m(!1);return}}else Me&&G(Me.id)}if(le.current&&ie.current){const Me=ie.current,oe=fe*Q/ge.current,he=Me.clientWidth,Xe=Math.max(0,oe-he/2);Me.scrollLeft=Xe}Se(X)};Se(X)},[G,Q,Se]),_e=N,Ne=g.useCallback(X=>{if(!ee.current)return;const fe=X??j.current;ee.current.play(void 0,fe),m(!0),O()},[O]),Be=g.useCallback(()=>{ee.current&&(ee.current.pause(),m(!1),_e(),_(ee.current.getCurrentTime()))},[_e]),ve=g.useCallback(()=>{ee.current&&(ee.current.stop(),m(!1),_e(),j.current=0,_(0),G(null))},[_e,G]),Ve=g.useCallback(X=>{const fe=Math.max(0,Math.min(X,w));j.current=fe,_(fe),ee.current&&ee.current.seekTo(fe)},[w]),ne=g.useCallback(X=>{const fe=Math.max(.5,Math.min(2,X));T(fe),ee.current&&ee.current.setPlaybackRate(fe)},[]),Ge=r?30:0,je=g.useMemo(()=>({isPlaying:y,currentTime:b,currentTimeRef:j}),[y,b]),xe=g.useMemo(()=>({continuousPlay:R,annotations:I,activeAnnotationId:$,playbackRate:E,isAutomaticScroll:z}),[R,I,$,E,z]),Fe=g.useRef(h);Fe.current=h;const Oe=g.useCallback(X=>{const fe=typeof X=="function"?X(M.current):X;if(!Fe.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to MediaElementPlaylistProvider to handle annotation updates.");return}Fe.current(fe)},[]),Et=g.useMemo(()=>({play:Ne,pause:Be,stop:ve,seekTo:Ve,setPlaybackRate:ne,setContinuousPlay:ye,setAnnotations:Oe,setActiveAnnotationId:G,setAutomaticScroll:X=>{J(X)},setScrollContainer:Z,scrollContainerRef:ie}),[Ne,Be,ve,Ve,ne,ye,Oe,G,Z]),It=g.useMemo(()=>({duration:w,peaksDataArray:S,sampleRate:Q,waveHeight:n,timeScaleHeight:Ge,samplesPerPixel:q,playoutRef:ee,controls:i,barWidth:c,barGap:u,progressBarWidth:v}),[w,S,Q,n,Ge,q,i,c,u,v]),Mt={...kd,...a};return C.jsx(P.ThemeProvider,{theme:Mt,children:C.jsx(Kd.Provider,{value:je,children:C.jsx(qd.Provider,{value:xe,children:C.jsx(Jd.Provider,{value:Et,children:C.jsx(Qd.Provider,{value:It,children:p})})})})})},Us=()=>{const e=g.useContext(Kd);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Xs=()=>{const e=g.useContext(qd);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},bi=()=>{const e=g.useContext(Jd);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Ys=()=>{const e=g.useContext(Qd);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},B0=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=lt(),{selectionStart:r,selectionEnd:s,isLoopEnabled:o}=ct(),{play:a}=Pe(),i=async()=>{if(r!==s&&s>r&&!o){const c=s-r;await a(r,c)}else await a(n.current??0)};return C.jsx(kt,{onClick:i,disabled:t,className:e,children:"Play"})},V0=({className:e})=>{const{isPlaying:t}=lt(),{pause:n}=Pe();return C.jsx(kt,{onClick:n,disabled:!t,className:e,children:"Pause"})},N0=({className:e})=>{const{isPlaying:t}=lt(),{stop:n}=Pe();return C.jsx(kt,{onClick:n,disabled:!t,className:e,children:"Stop"})},z0=({className:e})=>{const{isPlaying:t}=lt(),{play:n,setCurrentTime:r}=Pe(),s=()=>{r(0),t&&n(0)};return C.jsx(kt,{onClick:s,className:e,children:"Rewind"})},j0=({className:e})=>{const{isPlaying:t}=lt(),{play:n,setCurrentTime:r}=Pe(),{duration:s}=vt(),o=()=>{r(s),t&&n(s)};return C.jsx(kt,{onClick:o,className:e,children:"Fast Forward"})},Z0=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=lt(),{play:s,setCurrentTime:o}=Pe(),a=()=>{const i=Math.max(0,(n.current??0)-e);o(i),r&&s(i)};return C.jsx(kt,{onClick:a,className:t,children:"Skip Backward"})},H0=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=lt(),{play:s,setCurrentTime:o}=Pe(),{duration:a}=vt(),i=()=>{const l=Math.min(a,(n.current??0)+e);o(l),r&&s(l)};return C.jsx(kt,{onClick:i,className:t,children:"Skip Forward"})},G0=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:r}=ct(),{setLoopEnabled:s,setLoopRegion:o}=Pe(),{duration:a}=vt(),i=n!==r&&r>n,l=()=>{if(!t&&!i){const c=Math.min(10,a*.25);o(0,Math.max(1,c))}s(!t)};return C.jsx(kt,{onClick:l,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},U0=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:r,loopEnd:s}=ct(),{setLoopRegionFromSelection:o,clearLoopRegion:a}=Pe(),i=t!==n&&n>t,l=r!==s&&s>r,c=()=>{l?a():o()};return C.jsx(kt,{onClick:c,disabled:!i&&!l,className:e,title:l?"Clear loop region":i?"Set loop region from selection":"Create a selection first",children:l?"Clear Loop":"Set Loop"})},X0=({className:e,disabled:t})=>{const{zoomIn:n}=Pe(),{canZoomIn:r}=vt();return C.jsx(kt,{onClick:n,disabled:t||!r,className:e,children:"Zoom In"})},Y0=({className:e,disabled:t})=>{const{zoomOut:n}=Pe(),{canZoomOut:r}=vt();return C.jsx(kt,{onClick:n,disabled:t||!r,className:e,children:"Zoom Out"})},K0=({className:e})=>{const{masterVolume:t}=vt(),{setMasterVolume:n}=Pe();return C.jsx(Og,{volume:t,onChange:n,className:e})},q0=({className:e})=>{const{timeFormat:t}=vt(),{setTimeFormat:n}=Pe();return C.jsx(Cv,{value:t,onChange:n,className:e})},J0=P.span`
1004
+ `;let R0=0;function D0(){let e;try{const r=new Blob([$0],{type:"application/javascript"}),s=URL.createObjectURL(r);e=new Worker(s),URL.revokeObjectURL(s)}catch(r){return console.warn("[waveform-playlist] Failed to create peaks worker (CSP restriction?):",r),{generate(){return Promise.reject(new Error("Worker creation failed"))},terminate(){}}}const t=new Map;let n=!1;return e.onmessage=r=>{const s=r.data,o=t.get(s.id);if(o)if(t.delete(s.id),s.error)o.reject(new Error(s.error));else try{const a=mt.create(s.buffer);o.resolve(a)}catch(a){o.reject(a)}},e.onerror=r=>{n=!0,e.terminate();for(const[,s]of t)s.reject(r.error??new Error(r.message));t.clear()},{generate(r){if(n)return Promise.reject(new Error("Worker terminated"));const s=String(++R0);return new Promise((o,a)=>{t.set(s,{resolve:o,reject:a}),e.postMessage({id:s,scale:r.scale,bits:r.bits,amplitude_scale:1,split_channels:r.splitChannels,length:r.length,sample_rate:r.sampleRate,channels:r.channels},r.channels)})},terminate(){n=!0,e.terminate();for(const[,r]of t)r.reject(new Error("Worker terminated"));t.clear()}}}function P0(e,t){const[n,r]=g.useState(()=>new Map),[s,o]=g.useState(!1),a=g.useRef(null),i=g.useRef(new WeakMap),l=g.useRef(new WeakMap),c=g.useRef(new WeakMap),u=g.useRef(0),f=g.useCallback(()=>(a.current||(a.current=D0()),a.current),[]);return g.useEffect(()=>{let h=!1;const d=i.current,p=l.current,v=c.current,y=[],m=new Map;for(const _ of e)for(const w of _.clips){if(!w.audioBuffer||w.waveformData)continue;const x=d.get(w.audioBuffer);if(x){y.push({clipId:w.id,waveformData:x});continue}if(p.get(w.audioBuffer)){const k=v.get(w.audioBuffer);k?k.add(w.id):v.set(w.audioBuffer,new Set([w.id]));continue}const S=m.get(w.audioBuffer);S?S.add(w.id):m.set(w.audioBuffer,new Set([w.id]))}if(y.length>0&&r(_=>{const w=new Map(_);for(const x of y)w.set(x.clipId,x.waveformData);return w}),m.size===0)return;u.current+=m.size,o(!0);const b=f();for(const[_,w]of m){v.set(_,new Set(w));const x=[];for(let E=0;E<_.numberOfChannels;E++)x.push(_.getChannelData(E).slice().buffer);const S=`buffer-${Math.random().toString(36).slice(2,11)}`,k=b.generate({id:S,channels:x,length:_.length,sampleRate:_.sampleRate,scale:t,bits:16,splitChannels:!0}).then(E=>{d.set(_,E);const M=v.get(_)??new Set;v.delete(_),p.delete(_),!h&&(r(I=>{const T=new Map(I);for(const $ of M)T.set($,E);return T}),u.current--,u.current<=0&&(u.current=0,o(!1)))}).catch(E=>{v.delete(_),p.delete(_),!h&&(console.warn("[waveform-playlist] Worker peak generation failed:",E),u.current--,u.current<=0&&(u.current=0,o(!1)))});p.set(_,k)}return()=>{h=!0,l.current=new WeakMap,c.current=new WeakMap,u.current=0,o(!1)}},[e,t,f]),g.useEffect(()=>()=>{a.current?.terminate(),a.current=null},[]),{cache:n,isGenerating:s}}function oa(e){return e instanceof File?e.name.replace(/\.[^/.]+$/,""):e instanceof Blob?"Untitled":typeof e=="string"?e.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled":e.name??e.src.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled"}async function F0(e,t,n){const r=oa(e);if(e instanceof Blob){const l=await e.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(l),name:r}}const s=typeof e=="string"?e:e.src,o=await fetch(s,{signal:n});if(!o.ok)throw new Error(`Failed to fetch ${s}: ${o.statusText}`);const a=await o.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(a),name:r}}function O0(){const[e,t]=g.useState([]),[n,r]=g.useState(0),[s,o]=g.useState([]),a=g.useRef(!1),i=g.useRef(new Set),l=g.useRef(new Map);g.useEffect(()=>{const f=l.current;return()=>{a.current=!0;for(const h of f.values())h.abort();f.clear()}},[]);const c=g.useCallback(f=>{if(f.length===0)return;const h=Hf(),d=f.map(p=>({track:Jl({name:`${oa(p)} (loading...)`,clips:[]}),source:p}));t(p=>[...p,...d.map(v=>v.track)]),r(p=>p+f.length);for(const{track:p,source:v}of d){i.current.add(p.id);const y=new AbortController;l.current.set(p.id,y),(async()=>{try{const{audioBuffer:m,name:b}=await F0(v,h,y.signal),_=ql({audioBuffer:m,startTime:0,duration:m.duration,offset:0,name:b});!a.current&&i.current.has(p.id)&&t(w=>w.map(x=>x.id===p.id?{...x,name:b,clips:[_]}:x))}catch(m){if(m instanceof DOMException&&m.name==="AbortError")return;console.warn("[waveform-playlist] Error loading audio:",m),!a.current&&i.current.has(p.id)&&(t(b=>b.filter(_=>_.id!==p.id)),o(b=>[...b,{name:oa(v),error:m instanceof Error?m:new Error(String(m))}]))}finally{l.current.delete(p.id),!a.current&&i.current.delete(p.id)&&r(m=>m-1)}})()}},[]),u=g.useCallback(f=>{t(d=>d.filter(p=>p.id!==f));const h=l.current.get(f);h&&(h.abort(),l.current.delete(f)),i.current.delete(f)&&r(d=>d-1)},[]);return{tracks:e,addTracks:c,removeTrack:u,loadingCount:n,isLoading:n>0,errors:s}}const Ud=g.createContext(null),Xd=g.createContext(null),Yd=g.createContext(null),Kd=g.createContext(null),L0=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:r=80,samplesPerPixel:s=1024,zoomLevels:o,automaticScroll:a=!1,theme:i,controls:l={show:!1,width:0},annotationList:c,effects:u,onReady:f,onAnnotationUpdate:h,onAnnotationsChange:d,barWidth:p=1,barGap:v=0,progressBarWidth:y,onTracksChange:m,soundFontCache:b,children:_})=>{const w=y??p+v,x=g.useMemo(()=>o,[o?.join(",")]),S=g.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const L=c.annotations[0];if(typeof L.start!="number"||typeof L.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof L.start),[]}return c.annotations},[c?.annotations]),k=g.useRef(S);k.current=S;const[E,M]=g.useState(null),[I,T]=g.useState(!1),[$,A]=g.useState(0),[P,W]=g.useState(0),[J,G]=g.useState([]),[Q,ee]=g.useState([]),[z,se]=g.useState([]),[U,ie]=g.useState(a),[le,ge]=g.useState(c?.isContinuousPlay??!1),[Se,N]=g.useState(c?.linkEndpoints??!1),[H,ye]=g.useState(c?.editable??!1),[j,q]=g.useState(!1),O=g.useRef(null),_e=g.useRef(!1),Ne=g.useRef(!1);Ne.current=I;const Be=g.useRef(0),ve=g.useRef(0),Ve=g.useRef(e),ne=g.useRef(b);ne.current=b;const Ge=g.useRef(z),je=g.useRef(0),xe=g.useRef(0),Fe=g.useRef(null),Oe=g.useRef(null),Et=g.useRef(!1),It=g.useRef(c?.isContinuousPlay??!1),Mt=g.useRef(null),X=g.useRef(null),fe=g.useRef(0),Ue=g.useRef(!1),Me=g.useRef(!1),oe=g.useRef(s),he=g.useRef(44100),{timeFormat:Xe,setTimeFormat:At,formatTime:Tt}=Nd(),ut=zd({engineRef:O,initialSamplesPerPixel:s}),{samplesPerPixel:yt,onEngineState:V}=ut,Y=jd({engineRef:O,initialVolume:1}),{masterVolume:K,setMasterVolume:ce,masterVolumeRef:Ae,onEngineState:Ze}=Y,{selectionStart:te,selectionEnd:Ke,setSelection:Qe,selectionStartRef:Te,selectionEndRef:dt,onEngineState:Lt}=o0({engineRef:O}),{isLoopEnabled:rn,loopStart:sn,loopEnd:Ht,setLoopEnabled:qn,setLoopRegion:kn,clearLoopRegion:Hr,isLoopEnabledRef:_i,loopStartRef:xi,loopEndRef:Ci,onEngineState:Si}=a0({engineRef:O}),{selectedTrackId:ki,setSelectedTrackId:Ei,onEngineState:Ii,selectedTrackIdRef:Mi}=i0({engineRef:O}),{animationFrameRef:Ai,startAnimationFrameLoop:Js,stopAnimationFrameLoop:Gr}=Gd(),wf=g.useMemo(()=>Math.min(...x??[256,512,1024,2048,4096,8192]),[x]),{cache:Ti}=P0(e,wf),$i=g.useCallback(L=>{It.current=L,ge(L)},[]),Wt=g.useCallback(L=>{Mt.current=L,M(L)},[]),Ri=g.useCallback(()=>{const L=Te.current??0,Z=dt.current??0;L!==Z&&Z>L&&kn(L,Z)},[kn,Te,dt]);g.useEffect(()=>{Et.current=U},[U]),g.useEffect(()=>{Ge.current=z},[z]),Ve.current=e;const Qs=e===X.current;Ue.current=Qs||Me.current,g.useEffect(()=>{if(!Oe.current||P===0)return;const L=Oe.current,Z=oe.current,pe=yt;if(Z===pe)return;const B=L.clientWidth,Ee=L.scrollLeft+B/2,et=he.current,ro=Ee*Z/et*et/pe,so=Math.max(0,ro-B/2);L.scrollLeft=so,oe.current=pe},[yt,P]);const Ur=g.useRef(null);g.useEffect(()=>{if(Qs||Me.current){Qs&&(X.current=null);let B=0;e.forEach($e=>{$e.clips.forEach(Ee=>{const et=(Ee.startSample+Ee.durationSamples)/Ee.sampleRate;B=Math.max(B,et)})}),W(B);return}if(q(!1),e.length===0){G([]),W(0),se([]),ee([]),O.current&&(O.current.dispose(),O.current=null);return}const L=Ne.current,Z=ve.current;return O.current&&L&&(O.current.stop(),Gr(),Ur.current={position:Z}),(async()=>{try{const B=performance.now(),$e=[];e.forEach(ke=>{ke.clips.length>0&&ke.clips[0].audioBuffer&&$e.push(ke.clips[0].audioBuffer)});let Ee=0;e.forEach(ke=>{ke.clips.forEach(ht=>{const Gt=ht.sampleRate,If=(ht.startSample+ht.durationSamples)/Gt;Ee=Math.max(Ee,If)})}),G($e),W(Ee),se(ke=>ke.length===e.length?ke.map((ht,Gt)=>({...ht,name:e[Gt].name})):e.map(ht=>({name:ht.name,muted:ht.muted,soloed:ht.soloed,volume:ht.volume,pan:ht.pan}))),O.current&&O.current.dispose(),fe.current=0,X.current=null,_e.current=!1;const et=Gf({effects:u,soundFontCache:ne.current}),bt=new Qf({adapter:et,samplesPerPixel:oe.current,zoomLevels:x});bt.setSelection(Te.current??0,dt.current??0),bt.setLoopRegion(xi.current??0,Ci.current??0),_i.current&&bt.setLoopEnabled(!0),bt.setMasterVolume(Ae.current??1),Mi.current&&bt.selectTrack(Mi.current);const ro=Ge.current,so=e.map((ke,ht)=>{const Gt=ro[ht];return{...ke,volume:Gt?.volume??ke.volume,muted:Gt?.muted??ke.muted,soloed:Gt?.soloed??ke.soloed,pan:Gt?.pan??ke.pan}});let Ui=!0;bt.on("statechange",ke=>{Lt(ke),Si(ke),Ii(ke),V(ke),Ze(ke),!Ui&&ke.tracksVersion!==fe.current&&(fe.current=ke.tracksVersion,X.current=ke.tracks,m?m(ke.tracks):console.warn("[waveform-playlist] Engine tracks changed but onTracksChange prop is not set — UI will revert on next render. Pass onTracksChange to WaveformPlaylistProvider."))}),bt.setTracks(so),Ui=!1,fe.current=bt.getState().tracksVersion,O.current=bt,q(!0),console.log(`[engine] rebuild: ${e.length} tracks, ${(performance.now()-B).toFixed(1)}ms`);const Ef=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:Ee}});window.dispatchEvent(Ef),f?.()}catch(B){console.error("Error loading audio:",B)}})(),()=>{if(Ue.current){Ue.current=!1;return}Gr(),O.current&&O.current.dispose()}},[e,f,u,Gr,Lt,Si,Ii,V,Ze,m,Ae,Te,dt,xi,Ci,_i,x,b]),g.useEffect(()=>{if(e.length===0)return;const L=e.map(Z=>Z.clips.map(B=>{let $e;if(B.waveformData)try{$e=Nl(B.waveformData,yt,n,B.offsetSamples,B.durationSamples)}catch(Ee){console.warn("[waveform-playlist] Failed to extract peaks from waveformData:",Ee)}if(!$e){const Ee=Ti.get(B.id);if(Ee)try{$e=Nl(Ee,yt,n,B.offsetSamples,B.durationSamples)}catch(et){console.warn("[waveform-playlist] Failed to extract peaks from cache:",et)}}if(!$e){!B.audioBuffer&&!B.waveformData&&!B.midiNotes&&console.warn(`[waveform-playlist] Clip "${B.id}" has no audio data or waveform data`);const Ee=n?1:B.audioBuffer?.numberOfChannels??1,et=B.midiNotes?Math.ceil(B.durationSamples/yt):0;$e={length:et,data:Array.from({length:Ee},()=>new Int16Array(et*2)),bits:16}}return{clipId:B.id,trackName:Z.name,peaks:$e,startSample:B.startSample,durationSamples:B.durationSamples,fadeIn:B.fadeIn,fadeOut:B.fadeOut,midiNotes:B.midiNotes,sampleRate:B.sampleRate,offsetSamples:B.offsetSamples}}));ee(L)},[e,yt,n,Ti]);const Di=g.useRef(!1),En=g.useCallback(()=>{if(O.current)return O.current.getCurrentTime();Di.current||(Di.current=!0,console.warn("[waveform-playlist] getPlaybackTime called without engine. Falling back to manual elapsed time (loop wrapping will not work)."));const L=F.getContext().currentTime-(je.current??0);return(xe.current??0)+L},[]),on=g.useCallback(()=>{const L=()=>{const Z=En();ve.current=Z;const pe=k.current;if(pe.length>0){const B=pe.find($e=>Z>=$e.start&&Z<$e.end);if(It.current)B&&B.id!==Mt.current?Wt(B.id):!B&&Mt.current!==null&&Wt(null);else if(Mt.current){const $e=pe.find(Ee=>Ee.id===Mt.current);if($e&&Z>=$e.end){O.current&&O.current.stop(),T(!1),ve.current=Be.current,A(Be.current);return}}else B&&Wt(B.id)}if(Et.current&&Oe.current&&P>0){const B=Oe.current,$e=he.current,Ee=Z*$e/oe.current,et=B.clientWidth,bt=Math.max(0,Ee-et/2);B.scrollLeft=bt}if(Fe.current!==null&&Z>=Fe.current){O.current&&O.current.stop(),T(!1),ve.current=Fe.current,A(Fe.current),Fe.current=null;return}if(Z>=P){O.current&&O.current.stop(),T(!1),ve.current=Be.current,A(Be.current),Wt(null);return}Js(L)};Js(L)},[P,Wt,Js,En]),ft=Gr;g.useEffect(()=>{(async()=>{if(I&&Ai.current&&O.current)if(le){const Z=ve.current;O.current.stop(),ft();const B=F.getContext().currentTime;je.current=B,xe.current=Z,O.current.play(Z),on()}else ft(),on()})().catch(Z=>{console.warn("[waveform-playlist] Failed to reschedule playback:",Z),T(!1),ft()})},[le,I,on,ft,Ai]),g.useEffect(()=>{(async()=>{if(Ur.current&&O.current){const{position:Z}=Ur.current;Ur.current=null;const B=F.getContext().currentTime;je.current=B,xe.current=Z,_e.current||(await O.current.init(),_e.current=!0),O.current.play(Z),T(!0),on()}})().catch(Z=>{console.warn("[waveform-playlist] Failed to resume playback after track change:",Z),T(!1),ft()})},[e,on,ft]);const Xr=g.useCallback(async(L,Z)=>{if(!O.current||P===0)return;const pe=L??ve.current;Be.current=pe,ve.current=pe,O.current.stop(),O.current.seek(pe),ft();const $e=F.getContext().currentTime;je.current=$e,xe.current=pe,Fe.current=Z!==void 0?pe+Z:null,_e.current||(await O.current.init(),_e.current=!0);const Ee=Z!==void 0?pe+Z:void 0;try{O.current.play(pe,Ee)}catch(et){console.warn("[waveform-playlist] Playback failed to start:",et),ft();return}T(!0),on()},[P,on,ft]),Pi=g.useCallback(()=>{if(!O.current)return;const L=En();O.current.pause(),T(!1),ft(),ve.current=L,A(L)},[ft,En]),Fi=g.useCallback(()=>{O.current&&(O.current.stop(),T(!1),ft(),ve.current=Be.current,A(Be.current),Wt(null))},[ft,Wt]),Oi=g.useCallback(L=>{const Z=Math.max(0,Math.min(L,P));ve.current=Z,A(Z),I&&O.current&&Xr(Z)},[P,I,Xr]),Li=g.useCallback((L,Z)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...z];B[L]={...B[L],muted:Z},se(B),O.current&&O.current.setTrackMute(pe,Z)},[z]),Wi=g.useCallback((L,Z)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...z];B[L]={...B[L],soloed:Z},se(B),O.current&&O.current.setTrackSolo(pe,Z)},[z]),Bi=g.useCallback((L,Z)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...z];B[L]={...B[L],volume:Z},se(B),O.current&&O.current.setTrackVolume(pe,Z)},[z]),Vi=g.useCallback((L,Z)=>{const pe=Ve.current[L]?.id;if(!pe)return;const B=[...z];B[L]={...B[L],pan:Z},se(B),O.current&&O.current.setTrackPan(pe,Z)},[z]),Ni=g.useCallback((L,Z)=>{Qe(L,Z),ve.current=L,A(L),I&&O.current&&(O.current.stop(),O.current.seek(L),O.current.play(L))},[I,Qe]),zi=g.useCallback(L=>{Oe.current=L},[]),eo=g.useRef(d);eo.current=d;const ji=g.useCallback(L=>{const Z=typeof L=="function"?L(k.current):L;if(!eo.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}eo.current(Z)},[]),to=J[0]?.sampleRate||e[0]?.clips[0]?.sampleRate||44100;he.current=to;const no=t?30:0,Zi=e.length*r+no,_f=g.useMemo(()=>({isPlaying:I,currentTime:$,currentTimeRef:ve,playbackStartTimeRef:je,audioStartPositionRef:xe,getPlaybackTime:En}),[I,$,ve,je,xe,En]),xf=g.useMemo(()=>({continuousPlay:le,linkEndpoints:Se,annotationsEditable:H,isAutomaticScroll:U,isLoopEnabled:rn,annotations:S,activeAnnotationId:E,selectionStart:te,selectionEnd:Ke,selectedTrackId:ki,loopStart:sn,loopEnd:Ht}),[le,Se,H,U,rn,S,E,te,Ke,ki,sn,Ht]),Hi=g.useCallback(L=>{ve.current=L,A(L)},[ve]),Gi=g.useCallback(L=>{ie(L)},[]),Cf=g.useMemo(()=>({play:Xr,pause:Pi,stop:Fi,seekTo:Oi,setCurrentTime:Hi,setTrackMute:Li,setTrackSolo:Wi,setTrackVolume:Bi,setTrackPan:Vi,setSelection:Ni,setSelectedTrackId:Ei,setTimeFormat:At,formatTime:Tt,zoomIn:ut.zoomIn,zoomOut:ut.zoomOut,setMasterVolume:ce,setAutomaticScroll:Gi,setScrollContainer:zi,scrollContainerRef:Oe,setContinuousPlay:$i,setLinkEndpoints:N,setAnnotationsEditable:ye,setAnnotations:ji,setActiveAnnotationId:Wt,setLoopEnabled:qn,setLoopRegion:kn,setLoopRegionFromSelection:Ri,clearLoopRegion:Hr}),[Xr,Pi,Fi,Oi,Hi,Li,Wi,Bi,Vi,Ni,Ei,At,Tt,ut.zoomIn,ut.zoomOut,ce,Gi,zi,Oe,$i,N,ye,ji,Wt,qn,kn,Ri,Hr]),Sf=g.useMemo(()=>({duration:P,audioBuffers:J,peaksDataArray:Q,trackStates:z,tracks:e,sampleRate:to,waveHeight:r,timeScaleHeight:no,minimumPlaylistHeight:Zi,controls:l,playoutRef:O,samplesPerPixel:yt,timeFormat:Xe,masterVolume:K,canZoomIn:ut.canZoomIn,canZoomOut:ut.canZoomOut,barWidth:p,barGap:v,progressBarWidth:w,isReady:j,mono:n,isDraggingRef:Me}),[P,J,Q,z,e,to,r,no,Zi,l,O,yt,Xe,K,ut.canZoomIn,ut.canZoomOut,p,v,w,j,n,Me]),kf={...Ed,...i};return C.jsx(D.ThemeProvider,{theme:kf,children:C.jsx(Ud.Provider,{value:_f,children:C.jsx(Xd.Provider,{value:xf,children:C.jsx(Yd.Provider,{value:Cf,children:C.jsx(Kd.Provider,{value:Sf,children:_})})})})})},lt=()=>{const e=g.useContext(Ud);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},ct=()=>{const e=g.useContext(Xd);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},Pe=()=>{const e=g.useContext(Yd);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},vt=()=>{const e=g.useContext(Kd);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e};var W0=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate;const t=this.audioElement;"preservesPitch"in this.audioElement?t.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?t.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(t.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},B0=class{constructor(e={}){this.track=null,this._isPlaying=!1,this._masterVolume=e.masterVolume??1,this._playbackRate=e.playbackRate??1}async init(){}addTrack(e){return this.track&&(console.warn("MediaElementPlayout: Only one track is supported. Disposing previous track. For multi-track, use TonePlayout."),this.track.dispose()),this.track=new W0({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const r=t??0;if(this._isPlaying=!0,this.track.play(r),n!==void 0){const s=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},s*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const qd=g.createContext(null),Jd=g.createContext(null),Qd=g.createContext(null),ef=g.createContext(null),V0=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:r=!1,playbackRate:s=1,automaticScroll:o=!1,theme:a,controls:i={show:!1,width:0},annotationList:l,barWidth:c=1,barGap:u=0,progressBarWidth:f,onAnnotationsChange:h,onReady:d,children:p})=>{const v=f??c+u,[y,m]=g.useState(!1),[b,_]=g.useState(0),[w,x]=g.useState(0),[S,k]=g.useState([]),[E,M]=g.useState(s),I=g.useMemo(()=>{if(!l?.annotations)return[];if(process.env.NODE_ENV!=="production"&&l.annotations.length>0){const X=l.annotations[0];if(typeof X.start!="number"||typeof X.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof X.start),[]}return l.annotations},[l?.annotations]),T=g.useRef(I);T.current=I;const[$,A]=g.useState(null),[P,W]=g.useState(l?.isContinuousPlay??!1),[J]=g.useState(t),[G,Q]=g.useState(o),ee=g.useRef(null),z=g.useRef(0),se=g.useRef(P),U=g.useRef(null),ie=g.useRef(null),le=g.useRef(o),ge=g.useRef(t),{startAnimationFrameLoop:Se,stopAnimationFrameLoop:N}=Gd();g.useEffect(()=>{se.current=P},[P]),g.useEffect(()=>{le.current=G},[G]);const H=g.useCallback(X=>{U.current=X,A(X)},[]),ye=g.useCallback(X=>{se.current=X,W(X)},[]),j=g.useCallback(X=>{ie.current=X},[]),q=e.waveformData.sample_rate;g.useEffect(()=>{const X=new B0({playbackRate:s});X.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const fe=X.getTrack(X.track?.id??"");return fe&&fe.setOnTimeUpdateCallback(Ue=>{z.current=Ue}),X.setOnPlaybackComplete(()=>{N(),m(!1),H(null),z.current=0,_(0)}),ee.current=X,x(e.waveformData.duration),d?.(),()=>{N(),X.dispose()}},[e.source,e.waveformData,e.name,s,d,N,H]),g.useEffect(()=>{try{const X=s0(e.waveformData,J,0,0,Math.ceil(e.waveformData.duration*q)),fe={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:X.length,data:[X.data],bits:X.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*q)};k([[fe]])}catch(X){console.warn("[waveform-playlist] Failed to extract peaks from waveform data:",X)}},[e.waveformData,e.name,J,q]);const O=g.useCallback(()=>{const X=()=>{const fe=ee.current?.getCurrentTime()??0;z.current=fe;const Ue=T.current;if(Ue.length>0){const Me=Ue.find(oe=>fe>=oe.start&&fe<oe.end);if(se.current)Me&&Me.id!==U.current?H(Me.id):!Me&&U.current!==null&&H(null);else if(U.current){const oe=Ue.find(he=>he.id===U.current);if(oe&&fe>=oe.end){ee.current?.stop(),m(!1);return}}else Me&&H(Me.id)}if(le.current&&ie.current){const Me=ie.current,oe=fe*q/ge.current,he=Me.clientWidth,Xe=Math.max(0,oe-he/2);Me.scrollLeft=Xe}Se(X)};Se(X)},[H,q,Se]),_e=N,Ne=g.useCallback(X=>{if(!ee.current)return;const fe=X??z.current;ee.current.play(void 0,fe),m(!0),O()},[O]),Be=g.useCallback(()=>{ee.current&&(ee.current.pause(),m(!1),_e(),_(ee.current.getCurrentTime()))},[_e]),ve=g.useCallback(()=>{ee.current&&(ee.current.stop(),m(!1),_e(),z.current=0,_(0),H(null))},[_e,H]),Ve=g.useCallback(X=>{const fe=Math.max(0,Math.min(X,w));z.current=fe,_(fe),ee.current&&ee.current.seekTo(fe)},[w]),ne=g.useCallback(X=>{const fe=Math.max(.5,Math.min(2,X));M(fe),ee.current&&ee.current.setPlaybackRate(fe)},[]),Ge=r?30:0,je=g.useMemo(()=>({isPlaying:y,currentTime:b,currentTimeRef:z}),[y,b]),xe=g.useMemo(()=>({continuousPlay:P,annotations:I,activeAnnotationId:$,playbackRate:E,isAutomaticScroll:G}),[P,I,$,E,G]),Fe=g.useRef(h);Fe.current=h;const Oe=g.useCallback(X=>{const fe=typeof X=="function"?X(T.current):X;if(!Fe.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to MediaElementPlaylistProvider to handle annotation updates.");return}Fe.current(fe)},[]),Et=g.useMemo(()=>({play:Ne,pause:Be,stop:ve,seekTo:Ve,setPlaybackRate:ne,setContinuousPlay:ye,setAnnotations:Oe,setActiveAnnotationId:H,setAutomaticScroll:X=>{Q(X)},setScrollContainer:j,scrollContainerRef:ie}),[Ne,Be,ve,Ve,ne,ye,Oe,H,j]),It=g.useMemo(()=>({duration:w,peaksDataArray:S,sampleRate:q,waveHeight:n,timeScaleHeight:Ge,samplesPerPixel:J,playoutRef:ee,controls:i,barWidth:c,barGap:u,progressBarWidth:v}),[w,S,q,n,Ge,J,i,c,u,v]),Mt={...Ed,...a};return C.jsx(D.ThemeProvider,{theme:Mt,children:C.jsx(qd.Provider,{value:je,children:C.jsx(Jd.Provider,{value:xe,children:C.jsx(Qd.Provider,{value:Et,children:C.jsx(ef.Provider,{value:It,children:p})})})})})},Us=()=>{const e=g.useContext(qd);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Xs=()=>{const e=g.useContext(Jd);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},yi=()=>{const e=g.useContext(Qd);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Ys=()=>{const e=g.useContext(ef);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},N0=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=lt(),{selectionStart:r,selectionEnd:s,isLoopEnabled:o}=ct(),{play:a}=Pe(),i=async()=>{if(r!==s&&s>r&&!o){const c=s-r;await a(r,c)}else await a(n.current??0)};return C.jsx(kt,{onClick:i,disabled:t,className:e,children:"Play"})},z0=({className:e})=>{const{isPlaying:t}=lt(),{pause:n}=Pe();return C.jsx(kt,{onClick:n,disabled:!t,className:e,children:"Pause"})},j0=({className:e})=>{const{isPlaying:t}=lt(),{stop:n}=Pe();return C.jsx(kt,{onClick:n,disabled:!t,className:e,children:"Stop"})},Z0=({className:e})=>{const{isPlaying:t}=lt(),{play:n,setCurrentTime:r}=Pe(),s=()=>{r(0),t&&n(0)};return C.jsx(kt,{onClick:s,className:e,children:"Rewind"})},H0=({className:e})=>{const{isPlaying:t}=lt(),{play:n,setCurrentTime:r}=Pe(),{duration:s}=vt(),o=()=>{r(s),t&&n(s)};return C.jsx(kt,{onClick:o,className:e,children:"Fast Forward"})},G0=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=lt(),{play:s,setCurrentTime:o}=Pe(),a=()=>{const i=Math.max(0,(n.current??0)-e);o(i),r&&s(i)};return C.jsx(kt,{onClick:a,className:t,children:"Skip Backward"})},U0=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=lt(),{play:s,setCurrentTime:o}=Pe(),{duration:a}=vt(),i=()=>{const l=Math.min(a,(n.current??0)+e);o(l),r&&s(l)};return C.jsx(kt,{onClick:i,className:t,children:"Skip Forward"})},X0=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:r}=ct(),{setLoopEnabled:s,setLoopRegion:o}=Pe(),{duration:a}=vt(),i=n!==r&&r>n,l=()=>{if(!t&&!i){const c=Math.min(10,a*.25);o(0,Math.max(1,c))}s(!t)};return C.jsx(kt,{onClick:l,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Y0=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:r,loopEnd:s}=ct(),{setLoopRegionFromSelection:o,clearLoopRegion:a}=Pe(),i=t!==n&&n>t,l=r!==s&&s>r,c=()=>{l?a():o()};return C.jsx(kt,{onClick:c,disabled:!i&&!l,className:e,title:l?"Clear loop region":i?"Set loop region from selection":"Create a selection first",children:l?"Clear Loop":"Set Loop"})},K0=({className:e,disabled:t})=>{const{zoomIn:n}=Pe(),{canZoomIn:r}=vt();return C.jsx(kt,{onClick:n,disabled:t||!r,className:e,children:"Zoom In"})},q0=({className:e,disabled:t})=>{const{zoomOut:n}=Pe(),{canZoomOut:r}=vt();return C.jsx(kt,{onClick:n,disabled:t||!r,className:e,children:"Zoom Out"})},J0=({className:e})=>{const{masterVolume:t}=vt(),{setMasterVolume:n}=Pe();return C.jsx(Lg,{volume:t,onChange:n,className:e})},Q0=({className:e})=>{const{timeFormat:t}=vt(),{setTimeFormat:n}=Pe();return C.jsx(Sv,{value:t,onChange:n,className:e})},ey=D.span`
1010
1005
  font-family: 'Courier New', Monaco, monospace;
1011
1006
  font-size: 1rem;
1012
1007
  font-weight: 600;
1013
1008
  color: ${e=>e.theme?.textColor||"#333"};
1014
1009
  user-select: none;
1015
- `,Q0=({className:e})=>{const t=g.useRef(null),n=g.useRef(null),{isPlaying:r,currentTimeRef:s,getPlaybackTime:o}=lt(),{timeFormat:a}=vt();return g.useEffect(()=>{const i=()=>{if(t.current){const l=r?o():s.current??0;t.current.textContent=Ln(l,a)}r&&(n.current=requestAnimationFrame(i))};return r?n.current=requestAnimationFrame(i):i(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,a,s,o]),g.useEffect(()=>{!r&&t.current&&(t.current.textContent=Ln(s.current??0,a))}),C.jsx(J0,{ref:t,className:e,"aria-label":"Audio position",children:Ln(s.current??0,a)})},ey=({className:e})=>{const{selectionStart:t,selectionEnd:n}=ct(),{setSelection:r}=Pe();return C.jsx(Qg,{selectionStart:t,selectionEnd:n,onSelectionChange:r,className:e})},ty=({className:e})=>{const{isAutomaticScroll:t}=ct(),{setAutomaticScroll:n}=Pe();return C.jsx(ug,{checked:t,onChange:n,className:e})},Ks=g.createContext(null),ny=Ks.Provider;function Sn(){const e=g.useContext(Ks);if(!e)throw new Error("useAnnotationIntegration must be used within <AnnotationProvider>. Install @waveform-playlist/annotations and wrap your app with <AnnotationProvider>. See: https://waveform-playlist.naomiaro.com/docs/guides/annotations");return e}const ry=({className:e})=>{const{ContinuousPlayCheckbox:t}=Sn(),{continuousPlay:n}=ct(),{setContinuousPlay:r}=Pe();return C.jsx(t,{checked:n,onChange:r,className:e})},sy=({className:e})=>{const{LinkEndpointsCheckbox:t}=Sn(),{linkEndpoints:n}=ct(),{setLinkEndpoints:r}=Pe();return C.jsx(t,{checked:n,onChange:r,className:e})},oy=({className:e})=>{const{EditableCheckbox:t}=Sn(),{annotationsEditable:n}=ct(),{setAnnotationsEditable:r}=Pe();return C.jsx(t,{checked:n,onChange:r,className:e})},ay=({filename:e,className:t})=>{const{DownloadAnnotationsButton:n}=Sn(),{annotations:r}=ct();return C.jsx(n,{annotations:r,filename:e,className:t})},iy=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:r,bitDepth:s=16,applyEffects:o=!0,effectsFunction:a,createOfflineTrackEffects:i,className:l,onExportComplete:c,onExportError:u})=>{const{tracks:f,trackStates:h}=vt(),{exportWav:d,isExporting:p,progress:v}=Zd(),y=async()=>{try{const b=await d(f,h,{filename:t,mode:n,trackIndex:r,bitDepth:s,applyEffects:o,effectsFunction:a,createOfflineTrackEffects:i,autoDownload:!0});c?.(b.blob)}catch(b){u?.(b instanceof Error?b:new Error("Export failed"))}},m=p?`Exporting ${Math.round(v*100)}%`:e;return C.jsx(kt,{onClick:y,disabled:p||f.length===0,className:l,children:m})},ly=P.div.attrs(e=>({style:{width:`${e.$width}px`,background:e.$color}}))`
1010
+ `,ty=({className:e})=>{const t=g.useRef(null),n=g.useRef(null),{isPlaying:r,currentTimeRef:s,getPlaybackTime:o}=lt(),{timeFormat:a}=vt();return g.useEffect(()=>{const i=()=>{if(t.current){const l=r?o():s.current??0;t.current.textContent=Ln(l,a)}r&&(n.current=requestAnimationFrame(i))};return r?n.current=requestAnimationFrame(i):i(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,a,s,o]),g.useEffect(()=>{!r&&t.current&&(t.current.textContent=Ln(s.current??0,a))}),C.jsx(ey,{ref:t,className:e,"aria-label":"Audio position",children:Ln(s.current??0,a)})},ny=({className:e})=>{const{selectionStart:t,selectionEnd:n}=ct(),{setSelection:r}=Pe();return C.jsx(ev,{selectionStart:t,selectionEnd:n,onSelectionChange:r,className:e})},ry=({className:e})=>{const{isAutomaticScroll:t}=ct(),{setAutomaticScroll:n}=Pe();return C.jsx(dg,{checked:t,onChange:n,className:e})},Ks=g.createContext(null),sy=Ks.Provider;function Sn(){const e=g.useContext(Ks);if(!e)throw new Error("useAnnotationIntegration must be used within <AnnotationProvider>. Install @waveform-playlist/annotations and wrap your app with <AnnotationProvider>. See: https://waveform-playlist.naomiaro.com/docs/guides/annotations");return e}const oy=({className:e})=>{const{ContinuousPlayCheckbox:t}=Sn(),{continuousPlay:n}=ct(),{setContinuousPlay:r}=Pe();return C.jsx(t,{checked:n,onChange:r,className:e})},ay=({className:e})=>{const{LinkEndpointsCheckbox:t}=Sn(),{linkEndpoints:n}=ct(),{setLinkEndpoints:r}=Pe();return C.jsx(t,{checked:n,onChange:r,className:e})},iy=({className:e})=>{const{EditableCheckbox:t}=Sn(),{annotationsEditable:n}=ct(),{setAnnotationsEditable:r}=Pe();return C.jsx(t,{checked:n,onChange:r,className:e})},ly=({filename:e,className:t})=>{const{DownloadAnnotationsButton:n}=Sn(),{annotations:r}=ct();return C.jsx(n,{annotations:r,filename:e,className:t})},cy=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:r,bitDepth:s=16,applyEffects:o=!0,effectsFunction:a,createOfflineTrackEffects:i,className:l,onExportComplete:c,onExportError:u})=>{const{tracks:f,trackStates:h}=vt(),{exportWav:d,isExporting:p,progress:v}=Hd(),y=async()=>{try{const b=await d(f,h,{filename:t,mode:n,trackIndex:r,bitDepth:s,applyEffects:o,effectsFunction:a,createOfflineTrackEffects:i,autoDownload:!0});c?.(b.blob)}catch(b){u?.(b instanceof Error?b:new Error("Export failed"))}},m=p?`Exporting ${Math.round(v*100)}%`:e;return C.jsx(kt,{onClick:y,disabled:p||f.length===0,className:l,children:m})},uy=D.div.attrs(e=>({style:{width:`${e.$width}px`,background:e.$color}}))`
1016
1011
  position: absolute;
1017
1012
  top: 0;
1018
1013
  left: 0;
@@ -1020,16 +1015,16 @@ self.onmessage = function(e) {
1020
1015
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
1021
1016
  pointer-events: none;
1022
1017
  will-change: transform;
1023
- `,cy=({color:e="#ff0000"})=>{const t=g.useRef(null),n=g.useRef(null),{isPlaying:r,currentTimeRef:s,getPlaybackTime:o}=lt(),{samplesPerPixel:a,sampleRate:i,progressBarWidth:l}=vt();return g.useEffect(()=>{const c=()=>{if(t.current){const f=(r?o():s.current??0)*i/a;t.current.style.transform=`translate3d(${f}px, 0, 0)`}r&&(n.current=requestAnimationFrame(c))};return r?n.current=requestAnimationFrame(c):c(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,i,a,s,o]),g.useEffect(()=>{if(!r&&t.current){const u=(s.current??0)*i/a;t.current.style.transform=`translate3d(${u}px, 0, 0)`}}),C.jsx(ly,{ref:t,$color:e,$width:l,"data-playhead":!0})},uy=P.div`
1018
+ `,dy=({color:e="#ff0000"})=>{const t=g.useRef(null),n=g.useRef(null),{isPlaying:r,currentTimeRef:s,getPlaybackTime:o}=lt(),{samplesPerPixel:a,sampleRate:i,progressBarWidth:l}=vt();return g.useEffect(()=>{const c=()=>{if(t.current){const f=(r?o():s.current??0)*i/a;t.current.style.transform=`translate3d(${f}px, 0, 0)`}r&&(n.current=requestAnimationFrame(c))};return r?n.current=requestAnimationFrame(c):c(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,i,a,s,o]),g.useEffect(()=>{if(!r&&t.current){const u=(s.current??0)*i/a;t.current.style.transform=`translate3d(${u}px, 0, 0)`}}),C.jsx(uy,{ref:t,$color:e,$width:l,"data-playhead":!0})},fy=D.div`
1024
1019
  position: relative;
1025
- `,wo=P.div.attrs(e=>({style:{top:`${e.$top}px`,width:`${e.$width}px`,height:`${e.$height}px`,background:e.$color}}))`
1020
+ `,wo=D.div.attrs(e=>({style:{top:`${e.$top}px`,width:`${e.$width}px`,height:`${e.$height}px`,background:e.$color}}))`
1026
1021
  position: absolute;
1027
1022
  left: 0;
1028
1023
  z-index: 0;
1029
1024
  /* Force GPU compositing layer to prevent gradient flickering during scroll */
1030
1025
  transform: translateZ(0);
1031
1026
  backface-visibility: hidden;
1032
- `,dy=P.div.attrs(e=>({style:{top:`${e.$top}px`,height:`${e.$height}px`,width:`${e.$width}px`,background:e.$color,transform:"scaleX(0)"}}))`
1027
+ `,hy=D.div.attrs(e=>({style:{top:`${e.$top}px`,height:`${e.$height}px`,width:`${e.$width}px`,background:e.$color,transform:"scaleX(0)"}}))`
1033
1028
  position: absolute;
1034
1029
  left: 0;
1035
1030
  pointer-events: none;
@@ -1037,16 +1032,16 @@ self.onmessage = function(e) {
1037
1032
  transform-origin: left;
1038
1033
  /* scaleX changes are composite-only (GPU) — no layout reflow per frame */
1039
1034
  will-change: transform;
1040
- `,fy=P.div`
1035
+ `,py=D.div`
1041
1036
  position: relative;
1042
1037
  z-index: 2;
1043
- `,Hl=({clipStartSample:e,clipDurationSamples:t,midiNotes:n,clipSampleRate:r,clipOffsetSeconds:s,...o})=>{const a=g.useRef(null),i=g.useRef(null),l=zr(),{waveHeight:c}=Hs(),{isPlaying:u,currentTimeRef:f,getPlaybackTime:h}=lt(),{samplesPerPixel:d,sampleRate:p}=vt(),v=l?.waveProgressColor||"rgba(0, 0, 0, 0.1)";g.useEffect(()=>{const I=()=>{if(a.current){const $=(u?h():f.current??0)*p,A=e+t;let R=0;$<=e?R=0:$>=A?R=1:R=($-e)/t,a.current.style.transform=`scaleX(${R})`}u&&(i.current=requestAnimationFrame(I))};return u?i.current=requestAnimationFrame(I):I(),()=>{i.current&&(cancelAnimationFrame(i.current),i.current=null)}},[u,p,d,e,t,o.length,f,h]),g.useEffect(()=>{if(!u&&a.current){const M=(f.current??0)*p,$=e+t;let A=0;M<=e?A=0:M>=$?A=1:A=(M-e)/t,a.current.style.transform=`scaleX(${A})`}});const y=l?.waveformDrawMode||"inverted";let m;y==="inverted"?m=o.isSelected&&l?l.selectedWaveFillColor:l?.waveFillColor||"white":m=o.isSelected&&l?l.selectedWaveOutlineColor:l?.waveOutlineColor||"grey";const b=o.renderMode==="spectrogram"||o.renderMode==="both",_=o.renderMode==="piano-roll",w=o.renderMode==="both",x=b?"#000":_?l?.pianoRollBackgroundColor||"#1a1a2e":en(m),S=Math.floor(c/2),k=c,E=o.index*c,T=en(m);return C.jsxs(uy,{children:[w?C.jsxs(C.Fragment,{children:[C.jsx(wo,{$color:"#000",$height:S,$top:E,$width:o.length}),C.jsx(wo,{$color:T,$height:S,$top:E+S,$width:o.length})]}):C.jsx(wo,{$color:x,$height:k,$top:E,$width:o.length}),!_&&C.jsx(dy,{ref:a,$color:v,$height:k,$top:E,$width:o.length}),C.jsx(fy,{children:C.jsx(Pd,{...o,transparentBackground:!0,midiNotes:n,sampleRate:r,clipOffsetSeconds:s})})]})},wi=g.createContext(null),hy=wi.Provider;function py(){const e=g.useContext(wi);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const my=60,gy=P.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
1038
+ `,Zl=({clipStartSample:e,clipDurationSamples:t,midiNotes:n,clipSampleRate:r,clipOffsetSeconds:s,...o})=>{const a=g.useRef(null),i=g.useRef(null),l=zr(),{waveHeight:c}=Hs(),{isPlaying:u,currentTimeRef:f,getPlaybackTime:h}=lt(),{samplesPerPixel:d,sampleRate:p}=vt(),v=l?.waveProgressColor||"rgba(0, 0, 0, 0.1)",y=ec(e,t,d);g.useEffect(()=>{const T=()=>{if(a.current){const A=(u?h():f.current??0)*p,P=e+t;let W=0;A<=e?W=0:A>=P?W=1:W=(A-e)/t,a.current.style.transform=`scaleX(${W})`}u&&(i.current=requestAnimationFrame(T))};return u?i.current=requestAnimationFrame(T):T(),()=>{i.current&&(cancelAnimationFrame(i.current),i.current=null)}},[u,p,e,t,y,f,h]),g.useEffect(()=>{if(!u&&a.current){const $=(f.current??0)*p,A=e+t;let P=0;$<=e?P=0:$>=A?P=1:P=($-e)/t,a.current.style.transform=`scaleX(${P})`}});const m=l?.waveformDrawMode||"inverted";let b;m==="inverted"?b=o.isSelected&&l?l.selectedWaveFillColor:l?.waveFillColor||"white":b=o.isSelected&&l?l.selectedWaveOutlineColor:l?.waveOutlineColor||"grey";const _=o.renderMode==="spectrogram"||o.renderMode==="both",w=o.renderMode==="piano-roll",x=o.renderMode==="both",S=_?"#000":w?l?.pianoRollBackgroundColor||"#1a1a2e":en(b),k=Math.floor(c/2),E=c,M=o.index*c,I=en(b);return C.jsxs(fy,{children:[x?C.jsxs(C.Fragment,{children:[C.jsx(wo,{$color:"#000",$height:k,$top:M,$width:o.length}),C.jsx(wo,{$color:I,$height:k,$top:M+k,$width:o.length})]}):C.jsx(wo,{$color:S,$height:E,$top:M,$width:o.length}),!w&&C.jsx(hy,{ref:a,$color:v,$height:E,$top:M,$width:y}),C.jsx(py,{children:C.jsx(Fd,{...o,transparentBackground:!0,midiNotes:n,sampleRate:r,clipOffsetSeconds:s})})]})},bi=g.createContext(null),my=bi.Provider;function gy(){const e=g.useContext(bi);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const vy=60,yy=D.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
1044
1039
  overflow: hidden;
1045
1040
  pointer-events: auto;
1046
1041
  background: ${e=>e.theme.surfaceColor};
1047
1042
  transition: background 0.15s ease-in-out;
1048
1043
  ${e=>e.$isSelected&&`background: ${e.theme.selectedTrackControlsBackground};`}
1049
- `,ef=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,getAnnotationBoxLabel:s,className:o,showClipHeaders:a=!1,interactiveClips:i=!1,showFades:l=!1,touchOptimized:c=!1,onRemoveTrack:u,recordingState:f})=>{const h=zr(),{isPlaying:d,currentTimeRef:p,playbackStartTimeRef:v,audioStartPositionRef:y,getPlaybackTime:m}=lt(),{selectionStart:b,selectionEnd:_,annotations:w,activeAnnotationId:x,annotationsEditable:S,linkEndpoints:k,continuousPlay:E,selectedTrackId:T,loopStart:I,loopEnd:M,isLoopEnabled:$}=ct(),A=g.useContext(Ks),{setAnnotations:R,setActiveAnnotationId:W,setTrackMute:q,setTrackSolo:z,setTrackVolume:J,setTrackPan:ee,setSelection:j,play:se,setScrollContainer:U,setSelectedTrackId:ie,setCurrentTime:le,setLoopRegion:ge}=Pe(),{peaksDataArray:Se,trackStates:N,tracks:G,duration:ye,samplesPerPixel:Z,sampleRate:Q,waveHeight:O,timeScaleHeight:_e,controls:Ne,barWidth:Be,barGap:ve,isReady:Ve}=vt(),ne=g.useContext(wi),Ge=g.useMemo(()=>{if(!ne)return new Map;const V=new Map;return G.forEach(Y=>{if((ne.trackSpectrogramOverrides.get(Y.id)?.renderMode??Y.renderMode??"waveform")==="waveform")return;const ce=ne.trackSpectrogramOverrides.get(Y.id),Ae=ce?.colorMap??Y.spectrogramColorMap??ne.spectrogramColorMap??"viridis",Ze=ce?.config??Y.spectrogramConfig??ne.spectrogramConfig;V.set(Y.id,{colorLUT:ne.getColorMap(Ae),frequencyScaleFn:ne.getFrequencyScale(Ze?.frequencyScale??"mel"),config:Ze})}),V},[G,ne]),je=g.useMemo(()=>{if(ne?.spectrogramWorkerApi)return{registerCanvas:ne.spectrogramWorkerApi.registerCanvas.bind(ne.spectrogramWorkerApi),unregisterCanvas:ne.spectrogramWorkerApi.unregisterCanvas.bind(ne.spectrogramWorkerApi)}},[ne?.spectrogramWorkerApi]),[xe,Fe]=g.useState(null),[Oe,Et]=g.useState(!1),It=g.useRef(0),Mt=g.useRef(null),X=g.useCallback(V=>{Mt.current=V,U(V)},[U]),fe=G.reduce((V,Y)=>Y.clips.reduce((K,ce)=>{const Ae=(ce.startSample+ce.durationSamples)/ce.sampleRate;return Math.max(K,Ae)},V),0);let Ue=fe>0?fe:ye>0?ye:my;if(f?.isRecording){const Y=(f.startSample+f.durationSamples)/Q;Ue=Math.max(Ue,Y+10)}const Me=Math.floor(Ue*Q/Z),oe=async V=>{W(V.id);const Y=E?void 0:V.end-V.start;try{await se(V.start,Y)}catch(K){console.error("waveform-playlist: Failed to start playback for annotation",V.id,K)}},he=g.useCallback(V=>{if(V>=0&&V<G.length){const Y=G[V];ie(Y.id)}},[G,ie]),Xe=V=>{const Y=V.currentTarget.getBoundingClientRect(),ce=(V.clientX-Y.left)*Z/Q,Ze=V.clientY-Y.top;let te=0,Ke=-1;for(let Qe=0;Qe<Se.length;Qe++){const Te=Se[Qe],dt=Te.length>0?Math.max(1,...Te.map(Ht=>Ht.peaks.data.length)):1,sn=((ne?.trackSpectrogramOverrides.get(G[Qe]?.id)?.renderMode??G[Qe]?.renderMode??"waveform")==="both"?dt*2:dt)*O+(a?22:0);if(Ze>=te&&Ze<te+sn){Ke=Qe;break}te+=sn}Ke!==-1&&he(Ke),It.current=ce,Et(!0),le(ce),j(ce,ce)},At=V=>{if(!Oe||d)return;const Y=V.currentTarget.getBoundingClientRect(),ce=(V.clientX-Y.left)*Z/Q,Ae=Math.min(b,ce),Ze=Math.max(b,ce);j(Ae,Ze)},Tt=V=>{if(!Oe)return;if(Et(!1),d){const te=Math.max(0,It.current);le(te),j(te,te),se(te);return}const Y=V.currentTarget.getBoundingClientRect(),ce=(V.clientX-Y.left)*Z/Q,Ae=Math.min(b,ce),Ze=Math.max(b,ce);Math.abs(Ze-Ae)<.1?le(Ae):j(Ae,Ze)};if(G.some(V=>V.clips.length>0)&&Se.length===0)return C.jsx("div",{className:o,children:"Loading waveform..."});const yt=Ne.show?Se.map((V,Y)=>{const K=G[Y];if(!K)return null;const ce=N[Y]||{name:`Track ${Y+1}`,muted:!1,soloed:!1,volume:1,pan:0},Ae=K.clips.some(Te=>Te.midiNotes&&Te.midiNotes.length>0),Ze=ne?.trackSpectrogramOverrides.get(K.id)?.renderMode??K.renderMode??(Ae?"piano-roll":"waveform"),te=V.length>0?Math.max(1,...V.map(Te=>Te.peaks.data.length)):1,Ke=O*te+(a?pi:0),Qe=e?e(Y):C.jsxs(Av,{onClick:()=>he(Y),children:[C.jsxs(Tv,{style:{justifyContent:"center",position:"relative"},children:[u&&C.jsx(Mv,{onClick:Te=>{Te.stopPropagation(),u(Y)}}),C.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:ce.name||`Track ${Y+1}`}),ne?.renderMenuItems&&C.jsx("span",{style:{position:"absolute",right:0,top:0},children:C.jsx(Wv,{items:Te=>ne.renderMenuItems({renderMode:Ze,onRenderModeChange:dt=>ne.setTrackRenderMode(K.id,dt),onOpenSettings:()=>Fe(K.id),onClose:Te})})})]}),C.jsxs(Ev,{children:[C.jsx(Bl,{$variant:ce.muted?"danger":"outline",onClick:()=>q(Y,!ce.muted),children:"Mute"}),C.jsx(Bl,{$variant:ce.soloed?"info":"outline",onClick:()=>z(Y,!ce.soloed),children:"Solo"})]}),C.jsxs(Nl,{children:[C.jsx($v,{}),C.jsx(Vl,{min:"0",max:"1",step:"0.01",value:ce.volume,onChange:Te=>J(Y,parseFloat(Te.target.value))}),C.jsx(Rv,{})]}),C.jsxs(Nl,{children:[C.jsx("span",{children:"L"}),C.jsx(Vl,{min:"-1",max:"1",step:"0.01",value:ce.pan,onChange:Te=>ee(Y,parseFloat(Te.target.value))}),C.jsx("span",{children:"R"})]})]});return C.jsx(gy,{$height:Ke,$isSelected:K.id===T,children:Qe},K.id)}):void 0;return C.jsxs(Dd,{children:[C.jsx(Nr.Provider,{value:{samplesPerPixel:Z,sampleRate:Q,zoomLevels:[Z],waveHeight:O,timeScaleHeight:_e,duration:Ue*1e3,controls:Ne,barWidth:Be,barGap:ve},children:C.jsx(mi,{theme:h,backgroundColor:h.playlistBackgroundColor||en(h.waveOutlineColor),timescaleBackgroundColor:h.timescaleBackgroundColor,timescaleWidth:Me,tracksWidth:Me,controlsWidth:Ne.show?Ne.width:0,onTracksMouseDown:Xe,onTracksMouseMove:At,onTracksMouseUp:Tt,scrollContainerRef:X,isSelecting:Oe,"data-playlist-state":Ve?"ready":"loading",trackControlsSlots:yt,timescaleGapHeight:_e>0?_e+1:0,timescale:_e>0?C.jsxs(C.Fragment,{children:[C.jsx(Fd,{renderTimestamp:t}),$&&C.jsx(Jg,{startPosition:Math.min(I,M)*Q/Z,endPosition:Math.max(I,M)*Q/Z,markerColor:h.loopMarkerColor,regionColor:h.loopRegionColor,minPosition:0,maxPosition:Me,onLoopRegionChange:(V,Y)=>{const K=V*Z/Q,ce=Y*Z/Q;ge(K,ce)}})]}):void 0,children:C.jsxs(C.Fragment,{children:[Se.map((V,Y)=>{const K=G[Y];if(!K)return null;const ce=K.clips.some(te=>te.midiNotes&&te.midiNotes.length>0),Ae=ne?.trackSpectrogramOverrides.get(K.id)?.renderMode??K.renderMode??(ce?"piano-roll":"waveform"),Ze=V.length>0?Math.max(1,...V.map(te=>te.peaks.data.length)):1;return C.jsxs(Od,{numChannels:Ze,backgroundColor:Ae==="piano-roll"?h.pianoRollBackgroundColor||"#1a1a2e":en(h.waveOutlineColor),offset:0,width:Me,hasClipHeaders:a,trackId:K.id,isSelected:K.id===T,children:[Ae!=="waveform"&&(()=>{const te=Ge.get(K.id),Ke=te?.config;return!Ke?.labels||!te?null:C.jsx(fv,{waveHeight:O,numChannels:Ze,frequencyScaleFn:te.frequencyScaleFn,minFrequency:Ke.minFrequency??0,maxFrequency:Ke.maxFrequency??Q/2,labelsColor:Ke.labelsColor,labelsBackground:Ke.labelsBackground,renderMode:Ae,hasClipHeaders:a})})(),V.map((te,Ke)=>{const Qe=te.peaks,Te=Qe.length;return C.jsx(oa,{clipId:te.clipId,trackIndex:Y,clipIndex:Ke,trackName:te.trackName,startSample:te.startSample,durationSamples:te.durationSamples,samplesPerPixel:Z,showHeader:a,disableHeaderDrag:!i,isSelected:K.id===T,trackId:K.id,fadeIn:te.fadeIn,fadeOut:te.fadeOut,sampleRate:Q,showFades:l,touchOptimized:c,onMouseDown:dt=>{dt.target.closest('[role="button"][aria-roledescription="draggable"]')||he(Y)},children:Qe.data.map((dt,Lt)=>{const rn=ne?.spectrogramDataMap.get(te.clipId),sn=rn?.[Lt]??rn?.[0],Ht=Ge.get(K.id),qn=Ht?.config;return C.jsx(Hl,{index:Lt,data:dt,bits:Qe.bits,length:Te,isSelected:K.id===T,clipStartSample:te.startSample,clipDurationSamples:te.durationSamples,renderMode:te.midiNotes?"piano-roll":Ae,midiNotes:te.midiNotes,clipSampleRate:te.sampleRate,clipOffsetSeconds:te.offsetSamples!=null?te.offsetSamples/(te.sampleRate||Q):0,spectrogramData:sn,samplesPerPixel:Z,spectrogramColorLUT:Ht?.colorLUT,spectrogramFrequencyScaleFn:Ht?.frequencyScaleFn,spectrogramMinFrequency:qn?.minFrequency,spectrogramMaxFrequency:qn?.maxFrequency,spectrogramWorkerApi:je,spectrogramClipId:te.clipId,spectrogramOnCanvasesReady:ne?(kn,Hr)=>{ne.registerSpectrogramCanvases(te.clipId,Lt,kn,Hr)}:void 0},`${te.clipId}-${Lt}`)})},te.clipId)}),f?.isRecording&&f.trackId===K.id&&f.peaks.length>0&&C.jsx(oa,{clipId:"recording-preview",trackIndex:Y,clipIndex:V.length,trackName:"Recording...",startSample:f.startSample,durationSamples:f.durationSamples,samplesPerPixel:Z,showHeader:a,disableHeaderDrag:!0,isSelected:K.id===T,trackId:K.id,children:C.jsx(Hl,{index:0,data:f.peaks,bits:16,length:Math.floor(f.peaks.length/2),isSelected:K.id===T,clipStartSample:f.startSample,clipDurationSamples:f.durationSamples},`${K.id}-recording-0`)},`${K.id}-recording`)]},K.id)}),w.length>0&&A&&C.jsx(A.AnnotationBoxesWrapper,{height:30,width:Me,children:w.map((V,Y)=>{const K=V.start*Q/Z,ce=V.end*Q/Z,Ae=s?s(V,Y):V.id;return C.jsx(A.AnnotationBox,{annotationId:V.id,annotationIndex:Y,startPosition:K,endPosition:ce,label:Ae,color:"#ff9800",isActive:V.id===x,onClick:()=>oe(V),editable:S},V.id)})}),b!==_&&C.jsx(Td,{startPosition:Math.min(b,_)*Q/Z,endPosition:Math.max(b,_)*Q/Z,color:h.selectionColor}),(d||b===_)&&(n?n({position:(p.current??0)*Q/Z,color:h.playheadColor,isPlaying:d,currentTimeRef:p,playbackStartTimeRef:v,audioStartPositionRef:y,samplesPerPixel:Z,sampleRate:Q,controlsOffset:0,getAudioContextTime:()=>F.getContext().currentTime,getPlaybackTime:m}):C.jsx(cy,{color:h.playheadColor}))]})})}),ne?.SettingsModal&&typeof document<"u"&&da.createPortal(C.jsx(ne.SettingsModal,{open:xe!==null,onClose:()=>Fe(null),config:xe!==null?ne.trackSpectrogramOverrides.get(xe)?.config??G.find(V=>V.id===xe)?.spectrogramConfig??ne.spectrogramConfig??{}:{},colorMap:xe!==null?ne.trackSpectrogramOverrides.get(xe)?.colorMap??G.find(V=>V.id===xe)?.spectrogramColorMap??ne.spectrogramColorMap??"viridis":"viridis",onApply:(V,Y)=>{xe!==null&&ne.setTrackSpectrogramConfig(xe,V,Y)}}),document.body)]})},tf=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:r,annotationListConfig:s,scrollActivePosition:o="center",scrollActiveContainer:a="nearest"})=>{const{annotations:i,activeAnnotationId:l,annotationsEditable:c,linkEndpoints:u,continuousPlay:f}=ct(),h=Sn(),{setAnnotations:d}=Pe(),p=s??{linkEndpoints:u,continuousPlay:f},v=g.useCallback(m=>{d(m),n?.(m)},[d,n]),{AnnotationText:y}=h;return C.jsx(y,{annotations:i,activeAnnotationId:l??void 0,shouldScrollToActive:!0,scrollActivePosition:o,scrollActiveContainer:a,editable:c,controls:c?r:void 0,annotationListConfig:p,height:e,onAnnotationUpdate:v,renderAnnotationItem:t})},vy=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,annotationListConfig:s,annotationTextHeight:o,renderAnnotationItem:a,getAnnotationBoxLabel:i,scrollActivePosition:l="center",scrollActiveContainer:c="nearest",className:u,showClipHeaders:f=!1,interactiveClips:h=!1,showFades:d=!1,touchOptimized:p=!1,onRemoveTrack:v,recordingState:y})=>{const{annotations:m}=ct();return C.jsxs(C.Fragment,{children:[C.jsx(ef,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,getAnnotationBoxLabel:i,className:u,showClipHeaders:f,interactiveClips:h,showFades:d,touchOptimized:p,onRemoveTrack:v,recordingState:y}),m.length>0&&C.jsx(tf,{height:o,renderAnnotationItem:a,controls:r,annotationListConfig:s,scrollActivePosition:l,scrollActiveContainer:c})]})};var yy=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",nf=yy?g.useLayoutEffect:g.useEffect;function An(e){const t=g.useRef(e);return nf(()=>{t.current=e},[e]),t}function _o(e,t,n=g.useEffect,r=Object.is){const s=g.useRef(e);n(()=>{const o=s.current;r(e,o)||(s.current=e,t(e,o))},[t,e])}var Gl=Object.getOwnPropertySymbols,by=Object.prototype.hasOwnProperty,wy=Object.prototype.propertyIsEnumerable,_y=(e,t)=>{var n={};for(var r in e)by.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Gl)for(var r of Gl(e))t.indexOf(r)<0&&wy.call(e,r)&&(n[r]=e[r]);return n},xy=new oi,Cy=g.createContext(xy),Sy=g.memo(g.forwardRef(({children:e},t)=>{const[n,r]=g.useState(0),s=g.useRef(null),o=g.useRef(null),a=g.useMemo(()=>({renderer:{get rendering(){var i;return(i=s.current)!=null?i:Promise.resolve()}},trackRendering(i){s.current||(s.current=new Promise(l=>{o.current=l})),g.startTransition(()=>{i(),r(l=>l+1)})}}),[]);return nf(()=>{var i;(i=o.current)==null||i.call(o),s.current=null},[e,n]),g.useImperativeHandle(t,()=>a),null})),xo=[void 0,_r];function ky(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:o,onDragMove:a,onDragOver:i,onDragEnd:l}=t,c=_y(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const u=g.useRef(null),{plugins:f,modifiers:h,sensors:d}=c,p=Vt(f,On.plugins),v=Vt(d,On.sensors),y=Vt(h,On.modifiers),m=An(s),b=An(o),_=An(i),w=An(a),x=An(l),S=An(r),k=Ey(()=>{var E;return(E=c.manager)!=null?E:new oi(c)});return g.useEffect(()=>{if(!u.current)throw new Error("Renderer not found");const{renderer:E,trackRendering:T}=u.current,{monitor:I}=k;k.renderer=E;const M=[I.addEventListener("beforedragstart",$=>{const A=m.current;A&&T(()=>A($,k))}),I.addEventListener("dragstart",$=>{var A;return(A=b.current)==null?void 0:A.call(b,$,k)}),I.addEventListener("dragover",$=>{const A=_.current;A&&T(()=>A($,k))}),I.addEventListener("dragmove",$=>{const A=w.current;A&&T(()=>A($,k))}),I.addEventListener("dragend",$=>{const A=x.current;A&&T(()=>A($,k))}),I.addEventListener("collision",$=>{var A;return(A=S.current)==null?void 0:A.call(S,$,k)})];return()=>M.forEach($=>$())},[k]),_o(p,()=>k&&(k.plugins=p),...xo),_o(v,()=>k&&(k.sensors=v),...xo),_o(y,()=>k&&(k.modifiers=y),...xo),C.jsxs(Cy.Provider,{value:k,children:[C.jsx(Sy,{ref:u,children:n}),n]})}function Ey(e){const t=g.useRef(null);return t.current||(t.current=e()),g.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}var Iy=Object.create,rf=Object.defineProperty,My=Object.getOwnPropertyDescriptor,sf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),qs=e=>{throw TypeError(e)},Ay=(e,t,n)=>t in e?rf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ty=e=>{var t;return[,,,Iy((t=e?.[sf("metadata")])!=null?t:null)]},of=["class","method","getter","setter","accessor","field","value","get","set"],af=e=>e!==void 0&&typeof e!="function"?qs("Function expected"):e,$y=(e,t,n,r,s)=>({kind:of[e],name:t,metadata:r,addInitializer:o=>n._?qs("Already initialized"):s.push(af(o||null))}),Ry=(e,t)=>Ay(t,sf("metadata"),e[3]),Dy=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)o[s].call(n);return r},lf=(e,t,n,r,s,o)=>{for(var a,i,l,c,u=t&7,f=!1,h=!1,d=2,p=of[u+5],v=e[d]||(e[d]=[]),y=(s=s.prototype,My(s,n)),m=r.length-1;m>=0;m--)l=$y(u,n,i={},e[3],v),l.static=f,l.private=h,c=l.access={has:b=>n in b},c.get=b=>b[n],a=(0,r[m])(y[p],l),i._=1,af(a)&&(y[p]=a);return y&&rf(s,n,y),s},cf=(e,t,n)=>t.has(e)||qs("Cannot "+n),Py=(e,t,n)=>(cf(e,t,"read from private field"),t.get(e)),Fy=(e,t,n)=>t.has(e)?qs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Oy=(e,t,n,r)=>(cf(e,t,"write to private field"),t.set(e,n),n),nr=class ia{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new ia(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 ia(t,n)}},uf,df,la,gs,Zr,_i=class extends(la=tn,df=[Ie],uf=[Ie],la){constructor(e){const t=nr.from(e);super(t,(n,r)=>nr.equals(n,r)),Dy(Zr,5,this),Fy(this,gs,0),this.velocity={x:0,y:0}}get delta(){return nr.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=nr.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),o=s-Py(this,gs),a=i=>Math.round(i/o*100);Qt(()=>{Oy(this,gs,s),this.velocity={x:a(r.x),y:a(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(nr.from(e)),this.velocity={x:0,y:0}}};Zr=Ty(la);gs=new WeakMap;lf(Zr,2,"delta",df,_i);lf(Zr,2,"direction",uf,_i);Ry(Zr,_i);var ff=(e=>(e.Horizontal="x",e.Vertical="y",e))(ff||{});Object.values(ff);var Ly=Object.defineProperty,Wy=Object.defineProperties,By=Object.getOwnPropertyDescriptors,Ul=Object.getOwnPropertySymbols,Vy=Object.prototype.hasOwnProperty,Ny=Object.prototype.propertyIsEnumerable,Xl=(e,t,n)=>t in e?Ly(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hf=(e,t)=>{for(var n in t||(t={}))Vy.call(t,n)&&Xl(e,n,t[n]);if(Ul)for(var n of Ul(t))Ny.call(t,n)&&Xl(e,n,t[n]);return e},pf=(e,t)=>Wy(e,By(t)),ca=class extends Cr{apply({transform:t}){if(!this.options)return t;const{axis:n,value:r}=this.options;return pf(hf({},t),{[n]:r})}};ca.configure=Xn(ca);var mf=ca;mf.configure({axis:"x",value:0});var zy=mf.configure({axis:"y",value:0}),Yl=class extends Cr{apply({transform:t}){var n;const{size:r=20}=(n=this.options)!=null?n:{},s=typeof r=="number"?r:r.x,o=typeof r=="number"?r:r.y;return pf(hf({},t),{x:Math.ceil(t.x/s)*s,y:Math.ceil(t.y/o)*o})}};Yl.configure=Xn(Yl);const gf=e=>{let t=!1;const n=e.map(r=>r===Ko?(t=!0,Ko.configure({dropAnimation:null})):r);return t||console.warn("[waveform-playlist] noDropAnimationPlugins: Feedback plugin not found in defaults — drop animation may not be disabled. Check @dnd-kit/dom version."),n},jy=P.div`
1044
+ `,tf=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,getAnnotationBoxLabel:s,className:o,showClipHeaders:a=!1,interactiveClips:i=!1,showFades:l=!1,touchOptimized:c=!1,onRemoveTrack:u,recordingState:f})=>{const h=zr(),{isPlaying:d,currentTimeRef:p,playbackStartTimeRef:v,audioStartPositionRef:y,getPlaybackTime:m}=lt(),{selectionStart:b,selectionEnd:_,annotations:w,activeAnnotationId:x,annotationsEditable:S,linkEndpoints:k,continuousPlay:E,selectedTrackId:M,loopStart:I,loopEnd:T,isLoopEnabled:$}=ct(),A=g.useContext(Ks),{setAnnotations:P,setActiveAnnotationId:W,setTrackMute:J,setTrackSolo:G,setTrackVolume:Q,setTrackPan:ee,setSelection:z,play:se,setScrollContainer:U,setSelectedTrackId:ie,setCurrentTime:le,setLoopRegion:ge}=Pe(),{peaksDataArray:Se,trackStates:N,tracks:H,duration:ye,samplesPerPixel:j,sampleRate:q,waveHeight:O,timeScaleHeight:_e,controls:Ne,barWidth:Be,barGap:ve,isReady:Ve}=vt(),ne=g.useContext(bi),Ge=g.useMemo(()=>{if(!ne)return new Map;const V=new Map;return H.forEach(Y=>{if((ne.trackSpectrogramOverrides.get(Y.id)?.renderMode??Y.renderMode??"waveform")==="waveform")return;const ce=ne.trackSpectrogramOverrides.get(Y.id),Ae=ce?.colorMap??Y.spectrogramColorMap??ne.spectrogramColorMap??"viridis",Ze=ce?.config??Y.spectrogramConfig??ne.spectrogramConfig;V.set(Y.id,{colorLUT:ne.getColorMap(Ae),frequencyScaleFn:ne.getFrequencyScale(Ze?.frequencyScale??"mel"),config:Ze})}),V},[H,ne]),je=g.useMemo(()=>{if(ne?.spectrogramWorkerApi)return{registerCanvas:ne.spectrogramWorkerApi.registerCanvas.bind(ne.spectrogramWorkerApi),unregisterCanvas:ne.spectrogramWorkerApi.unregisterCanvas.bind(ne.spectrogramWorkerApi)}},[ne?.spectrogramWorkerApi]),[xe,Fe]=g.useState(null),[Oe,Et]=g.useState(!1),It=g.useRef(0),Mt=g.useRef(null),X=g.useCallback(V=>{Mt.current=V,U(V)},[U]),fe=H.reduce((V,Y)=>Y.clips.reduce((K,ce)=>{const Ae=(ce.startSample+ce.durationSamples)/ce.sampleRate;return Math.max(K,Ae)},V),0);let Ue=fe>0?fe:ye>0?ye:vy;if(f?.isRecording){const Y=(f.startSample+f.durationSamples)/q;Ue=Math.max(Ue,Y+10)}const Me=Math.floor(Ue*q/j),oe=async V=>{W(V.id);const Y=E?void 0:V.end-V.start;try{await se(V.start,Y)}catch(K){console.error("waveform-playlist: Failed to start playback for annotation",V.id,K)}},he=g.useCallback(V=>{if(V>=0&&V<H.length){const Y=H[V];ie(Y.id)}},[H,ie]),Xe=V=>{const Y=V.currentTarget.getBoundingClientRect(),ce=(V.clientX-Y.left)*j/q,Ze=V.clientY-Y.top;let te=0,Ke=-1;for(let Qe=0;Qe<Se.length;Qe++){const Te=Se[Qe],dt=Te.length>0?Math.max(1,...Te.map(Ht=>Ht.peaks.data.length)):1,sn=((ne?.trackSpectrogramOverrides.get(H[Qe]?.id)?.renderMode??H[Qe]?.renderMode??"waveform")==="both"?dt*2:dt)*O+(a?22:0);if(Ze>=te&&Ze<te+sn){Ke=Qe;break}te+=sn}Ke!==-1&&he(Ke),It.current=ce,Et(!0),le(ce),z(ce,ce)},At=V=>{if(!Oe||d)return;const Y=V.currentTarget.getBoundingClientRect(),ce=(V.clientX-Y.left)*j/q,Ae=Math.min(b,ce),Ze=Math.max(b,ce);z(Ae,Ze)},Tt=V=>{if(!Oe)return;if(Et(!1),d){const te=Math.max(0,It.current);le(te),z(te,te),se(te);return}const Y=V.currentTarget.getBoundingClientRect(),ce=(V.clientX-Y.left)*j/q,Ae=Math.min(b,ce),Ze=Math.max(b,ce);Math.abs(Ze-Ae)<.1?le(Ae):z(Ae,Ze)};if(H.some(V=>V.clips.length>0)&&Se.length===0)return C.jsx("div",{className:o,children:"Loading waveform..."});const yt=Ne.show?Se.map((V,Y)=>{const K=H[Y];if(!K)return null;const ce=N[Y]||{name:`Track ${Y+1}`,muted:!1,soloed:!1,volume:1,pan:0},Ae=K.clips.some(Te=>Te.midiNotes&&Te.midiNotes.length>0),Ze=ne?.trackSpectrogramOverrides.get(K.id)?.renderMode??K.renderMode??(Ae?"piano-roll":"waveform"),te=V.length>0?Math.max(1,...V.map(Te=>Te.peaks.data.length)):1,Ke=O*te+(a?hi:0),Qe=e?e(Y):C.jsxs(Tv,{onClick:()=>he(Y),children:[C.jsxs($v,{style:{justifyContent:"center",position:"relative"},children:[u&&C.jsx(Av,{onClick:Te=>{Te.stopPropagation(),u(Y)}}),C.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:ce.name||`Track ${Y+1}`}),ne?.renderMenuItems&&C.jsx("span",{style:{position:"absolute",right:0,top:0},children:C.jsx(Bv,{items:Te=>ne.renderMenuItems({renderMode:Ze,onRenderModeChange:dt=>ne.setTrackRenderMode(K.id,dt),onOpenSettings:()=>Fe(K.id),onClose:Te})})})]}),C.jsxs(Iv,{children:[C.jsx(Wl,{$variant:ce.muted?"danger":"outline",onClick:()=>J(Y,!ce.muted),children:"Mute"}),C.jsx(Wl,{$variant:ce.soloed?"info":"outline",onClick:()=>G(Y,!ce.soloed),children:"Solo"})]}),C.jsxs(Vl,{children:[C.jsx(Rv,{}),C.jsx(Bl,{min:"0",max:"1",step:"0.01",value:ce.volume,onChange:Te=>Q(Y,parseFloat(Te.target.value))}),C.jsx(Dv,{})]}),C.jsxs(Vl,{children:[C.jsx("span",{children:"L"}),C.jsx(Bl,{min:"-1",max:"1",step:"0.01",value:ce.pan,onChange:Te=>ee(Y,parseFloat(Te.target.value))}),C.jsx("span",{children:"R"})]})]});return C.jsx(yy,{$height:Ke,$isSelected:K.id===M,children:Qe},K.id)}):void 0;return C.jsxs(Pd,{children:[C.jsx(Nr.Provider,{value:{samplesPerPixel:j,sampleRate:q,zoomLevels:[j],waveHeight:O,timeScaleHeight:_e,duration:Ue*1e3,controls:Ne,barWidth:Be,barGap:ve},children:C.jsx(pi,{theme:h,backgroundColor:h.playlistBackgroundColor||en(h.waveOutlineColor),timescaleBackgroundColor:h.timescaleBackgroundColor,timescaleWidth:Me,tracksWidth:Me,controlsWidth:Ne.show?Ne.width:0,onTracksMouseDown:Xe,onTracksMouseMove:At,onTracksMouseUp:Tt,scrollContainerRef:X,isSelecting:Oe,"data-playlist-state":Ve?"ready":"loading",trackControlsSlots:yt,timescaleGapHeight:_e>0?_e+1:0,timescale:_e>0?C.jsxs(C.Fragment,{children:[C.jsx(Od,{renderTimestamp:t}),$&&C.jsx(Qg,{startPosition:Math.min(I,T)*q/j,endPosition:Math.max(I,T)*q/j,markerColor:h.loopMarkerColor,regionColor:h.loopRegionColor,minPosition:0,maxPosition:Me,onLoopRegionChange:(V,Y)=>{const K=V*j/q,ce=Y*j/q;ge(K,ce)}})]}):void 0,children:C.jsxs(C.Fragment,{children:[Se.map((V,Y)=>{const K=H[Y];if(!K)return null;const ce=K.clips.some(te=>te.midiNotes&&te.midiNotes.length>0),Ae=ne?.trackSpectrogramOverrides.get(K.id)?.renderMode??K.renderMode??(ce?"piano-roll":"waveform"),Ze=V.length>0?Math.max(1,...V.map(te=>te.peaks.data.length)):1;return C.jsxs(Ld,{numChannels:Ze,backgroundColor:Ae==="piano-roll"?h.pianoRollBackgroundColor||"#1a1a2e":en(h.waveOutlineColor),offset:0,width:Me,hasClipHeaders:a,trackId:K.id,isSelected:K.id===M,children:[Ae!=="waveform"&&(()=>{const te=Ge.get(K.id),Ke=te?.config;return!Ke?.labels||!te?null:C.jsx(hv,{waveHeight:O,numChannels:Ze,frequencyScaleFn:te.frequencyScaleFn,minFrequency:Ke.minFrequency??0,maxFrequency:Ke.maxFrequency??q/2,labelsColor:Ke.labelsColor,labelsBackground:Ke.labelsBackground,renderMode:Ae,hasClipHeaders:a})})(),V.map((te,Ke)=>{const Qe=te.peaks,Te=Qe.length;return C.jsx(sa,{clipId:te.clipId,trackIndex:Y,clipIndex:Ke,trackName:te.trackName,startSample:te.startSample,durationSamples:te.durationSamples,samplesPerPixel:j,showHeader:a,disableHeaderDrag:!i,isSelected:K.id===M,trackId:K.id,fadeIn:te.fadeIn,fadeOut:te.fadeOut,sampleRate:q,showFades:l,touchOptimized:c,onMouseDown:dt=>{dt.target.closest('[role="button"][aria-roledescription="draggable"]')||he(Y)},children:Qe.data.map((dt,Lt)=>{const rn=ne?.spectrogramDataMap.get(te.clipId),sn=rn?.[Lt]??rn?.[0],Ht=Ge.get(K.id),qn=Ht?.config;return C.jsx(Zl,{index:Lt,data:dt,bits:Qe.bits,length:Te,isSelected:K.id===M,clipStartSample:te.startSample,clipDurationSamples:te.durationSamples,renderMode:te.midiNotes?"piano-roll":Ae,midiNotes:te.midiNotes,clipSampleRate:te.sampleRate,clipOffsetSeconds:te.offsetSamples!=null?te.offsetSamples/(te.sampleRate||q):0,spectrogramData:sn,samplesPerPixel:j,spectrogramColorLUT:Ht?.colorLUT,spectrogramFrequencyScaleFn:Ht?.frequencyScaleFn,spectrogramMinFrequency:qn?.minFrequency,spectrogramMaxFrequency:qn?.maxFrequency,spectrogramWorkerApi:je,spectrogramClipId:te.clipId,spectrogramOnCanvasesReady:ne?(kn,Hr)=>{ne.registerSpectrogramCanvases(te.clipId,Lt,kn,Hr)}:void 0},`${te.clipId}-${Lt}`)})},te.clipId)}),f?.isRecording&&f.trackId===K.id&&f.peaks.length>0&&C.jsx(sa,{clipId:"recording-preview",trackIndex:Y,clipIndex:V.length,trackName:"Recording...",startSample:f.startSample,durationSamples:f.durationSamples,samplesPerPixel:j,showHeader:a,disableHeaderDrag:!0,isSelected:K.id===M,trackId:K.id,children:C.jsx(Zl,{index:0,data:f.peaks,bits:16,length:Math.floor(f.peaks.length/2),isSelected:K.id===M,clipStartSample:f.startSample,clipDurationSamples:f.durationSamples},`${K.id}-recording-0`)},`${K.id}-recording`)]},K.id)}),w.length>0&&A&&C.jsx(A.AnnotationBoxesWrapper,{height:30,width:Me,children:w.map((V,Y)=>{const K=V.start*q/j,ce=V.end*q/j,Ae=s?s(V,Y):V.id;return C.jsx(A.AnnotationBox,{annotationId:V.id,annotationIndex:Y,startPosition:K,endPosition:ce,label:Ae,color:"#ff9800",isActive:V.id===x,onClick:()=>oe(V),editable:S},V.id)})}),b!==_&&C.jsx($d,{startPosition:Math.min(b,_)*q/j,endPosition:Math.max(b,_)*q/j,color:h.selectionColor}),(d||b===_)&&(n?n({position:(p.current??0)*q/j,color:h.playheadColor,isPlaying:d,currentTimeRef:p,playbackStartTimeRef:v,audioStartPositionRef:y,samplesPerPixel:j,sampleRate:q,controlsOffset:0,getAudioContextTime:()=>F.getContext().currentTime,getPlaybackTime:m}):C.jsx(dy,{color:h.playheadColor}))]})})}),ne?.SettingsModal&&typeof document<"u"&&ua.createPortal(C.jsx(ne.SettingsModal,{open:xe!==null,onClose:()=>Fe(null),config:xe!==null?ne.trackSpectrogramOverrides.get(xe)?.config??H.find(V=>V.id===xe)?.spectrogramConfig??ne.spectrogramConfig??{}:{},colorMap:xe!==null?ne.trackSpectrogramOverrides.get(xe)?.colorMap??H.find(V=>V.id===xe)?.spectrogramColorMap??ne.spectrogramColorMap??"viridis":"viridis",onApply:(V,Y)=>{xe!==null&&ne.setTrackSpectrogramConfig(xe,V,Y)}}),document.body)]})},nf=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:r,annotationListConfig:s,scrollActivePosition:o="center",scrollActiveContainer:a="nearest"})=>{const{annotations:i,activeAnnotationId:l,annotationsEditable:c,linkEndpoints:u,continuousPlay:f}=ct(),h=Sn(),{setAnnotations:d}=Pe(),p=s??{linkEndpoints:u,continuousPlay:f},v=g.useCallback(m=>{d(m),n?.(m)},[d,n]),{AnnotationText:y}=h;return C.jsx(y,{annotations:i,activeAnnotationId:l??void 0,shouldScrollToActive:!0,scrollActivePosition:o,scrollActiveContainer:a,editable:c,controls:c?r:void 0,annotationListConfig:p,height:e,onAnnotationUpdate:v,renderAnnotationItem:t})},by=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,annotationListConfig:s,annotationTextHeight:o,renderAnnotationItem:a,getAnnotationBoxLabel:i,scrollActivePosition:l="center",scrollActiveContainer:c="nearest",className:u,showClipHeaders:f=!1,interactiveClips:h=!1,showFades:d=!1,touchOptimized:p=!1,onRemoveTrack:v,recordingState:y})=>{const{annotations:m}=ct();return C.jsxs(C.Fragment,{children:[C.jsx(tf,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,getAnnotationBoxLabel:i,className:u,showClipHeaders:f,interactiveClips:h,showFades:d,touchOptimized:p,onRemoveTrack:v,recordingState:y}),m.length>0&&C.jsx(nf,{height:o,renderAnnotationItem:a,controls:r,annotationListConfig:s,scrollActivePosition:l,scrollActiveContainer:c})]})};var wy=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",rf=wy?g.useLayoutEffect:g.useEffect;function An(e){const t=g.useRef(e);return rf(()=>{t.current=e},[e]),t}function _o(e,t,n=g.useEffect,r=Object.is){const s=g.useRef(e);n(()=>{const o=s.current;r(e,o)||(s.current=e,t(e,o))},[t,e])}var Hl=Object.getOwnPropertySymbols,_y=Object.prototype.hasOwnProperty,xy=Object.prototype.propertyIsEnumerable,Cy=(e,t)=>{var n={};for(var r in e)_y.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Hl)for(var r of Hl(e))t.indexOf(r)<0&&xy.call(e,r)&&(n[r]=e[r]);return n},Sy=new si,ky=g.createContext(Sy),Ey=g.memo(g.forwardRef(({children:e},t)=>{const[n,r]=g.useState(0),s=g.useRef(null),o=g.useRef(null),a=g.useMemo(()=>({renderer:{get rendering(){var i;return(i=s.current)!=null?i:Promise.resolve()}},trackRendering(i){s.current||(s.current=new Promise(l=>{o.current=l})),g.startTransition(()=>{i(),r(l=>l+1)})}}),[]);return rf(()=>{var i;(i=o.current)==null||i.call(o),s.current=null},[e,n]),g.useImperativeHandle(t,()=>a),null})),xo=[void 0,_r];function Iy(e){var t=e,{children:n,onCollision:r,onBeforeDragStart:s,onDragStart:o,onDragMove:a,onDragOver:i,onDragEnd:l}=t,c=Cy(t,["children","onCollision","onBeforeDragStart","onDragStart","onDragMove","onDragOver","onDragEnd"]);const u=g.useRef(null),{plugins:f,modifiers:h,sensors:d}=c,p=Vt(f,On.plugins),v=Vt(d,On.sensors),y=Vt(h,On.modifiers),m=An(s),b=An(o),_=An(i),w=An(a),x=An(l),S=An(r),k=My(()=>{var E;return(E=c.manager)!=null?E:new si(c)});return g.useEffect(()=>{if(!u.current)throw new Error("Renderer not found");const{renderer:E,trackRendering:M}=u.current,{monitor:I}=k;k.renderer=E;const T=[I.addEventListener("beforedragstart",$=>{const A=m.current;A&&M(()=>A($,k))}),I.addEventListener("dragstart",$=>{var A;return(A=b.current)==null?void 0:A.call(b,$,k)}),I.addEventListener("dragover",$=>{const A=_.current;A&&M(()=>A($,k))}),I.addEventListener("dragmove",$=>{const A=w.current;A&&M(()=>A($,k))}),I.addEventListener("dragend",$=>{const A=x.current;A&&M(()=>A($,k))}),I.addEventListener("collision",$=>{var A;return(A=S.current)==null?void 0:A.call(S,$,k)})];return()=>T.forEach($=>$())},[k]),_o(p,()=>k&&(k.plugins=p),...xo),_o(v,()=>k&&(k.sensors=v),...xo),_o(y,()=>k&&(k.modifiers=y),...xo),C.jsxs(ky.Provider,{value:k,children:[C.jsx(Ey,{ref:u,children:n}),n]})}function My(e){const t=g.useRef(null);return t.current||(t.current=e()),g.useInsertionEffect(()=>()=>{var n;return(n=t.current)==null?void 0:n.destroy()},[]),t.current}var Ay=Object.create,sf=Object.defineProperty,Ty=Object.getOwnPropertyDescriptor,of=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),qs=e=>{throw TypeError(e)},$y=(e,t,n)=>t in e?sf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ry=e=>{var t;return[,,,Ay((t=e?.[of("metadata")])!=null?t:null)]},af=["class","method","getter","setter","accessor","field","value","get","set"],lf=e=>e!==void 0&&typeof e!="function"?qs("Function expected"):e,Dy=(e,t,n,r,s)=>({kind:af[e],name:t,metadata:r,addInitializer:o=>n._?qs("Already initialized"):s.push(lf(o||null))}),Py=(e,t)=>$y(t,of("metadata"),e[3]),Fy=(e,t,n,r)=>{for(var s=0,o=e[t>>1],a=o&&o.length;s<a;s++)o[s].call(n);return r},cf=(e,t,n,r,s,o)=>{for(var a,i,l,c,u=t&7,f=!1,h=!1,d=2,p=af[u+5],v=e[d]||(e[d]=[]),y=(s=s.prototype,Ty(s,n)),m=r.length-1;m>=0;m--)l=Dy(u,n,i={},e[3],v),l.static=f,l.private=h,c=l.access={has:b=>n in b},c.get=b=>b[n],a=(0,r[m])(y[p],l),i._=1,lf(a)&&(y[p]=a);return y&&sf(s,n,y),s},uf=(e,t,n)=>t.has(e)||qs("Cannot "+n),Oy=(e,t,n)=>(uf(e,t,"read from private field"),t.get(e)),Ly=(e,t,n)=>t.has(e)?qs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Wy=(e,t,n,r)=>(uf(e,t,"write to private field"),t.set(e,n),n),nr=class aa{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new aa(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 aa(t,n)}},df,ff,ia,gs,Zr,wi=class extends(ia=tn,ff=[Ie],df=[Ie],ia){constructor(e){const t=nr.from(e);super(t,(n,r)=>nr.equals(n,r)),Fy(Zr,5,this),Ly(this,gs,0),this.velocity={x:0,y:0}}get delta(){return nr.delta(this.current,this.initial)}get direction(){const{current:e,previous:t}=this;if(!t)return null;const n={x:e.x-t.x,y:e.y-t.y};return!n.x&&!n.y?null:Math.abs(n.x)>Math.abs(n.y)?n.x>0?"right":"left":n.y>0?"down":"up"}get current(){return super.current}set current(e){const{current:t}=this,n=nr.from(e),r={x:n.x-t.x,y:n.y-t.y},s=Date.now(),o=s-Oy(this,gs),a=i=>Math.round(i/o*100);Qt(()=>{Wy(this,gs,s),this.velocity={x:a(r.x),y:a(r.y)},super.current=n})}reset(e=this.defaultValue){super.reset(nr.from(e)),this.velocity={x:0,y:0}}};Zr=Ry(ia);gs=new WeakMap;cf(Zr,2,"delta",ff,wi);cf(Zr,2,"direction",df,wi);Py(Zr,wi);var hf=(e=>(e.Horizontal="x",e.Vertical="y",e))(hf||{});Object.values(hf);var By=Object.defineProperty,Vy=Object.defineProperties,Ny=Object.getOwnPropertyDescriptors,Gl=Object.getOwnPropertySymbols,zy=Object.prototype.hasOwnProperty,jy=Object.prototype.propertyIsEnumerable,Ul=(e,t,n)=>t in e?By(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pf=(e,t)=>{for(var n in t||(t={}))zy.call(t,n)&&Ul(e,n,t[n]);if(Gl)for(var n of Gl(t))jy.call(t,n)&&Ul(e,n,t[n]);return e},mf=(e,t)=>Vy(e,Ny(t)),la=class extends Cr{apply({transform:t}){if(!this.options)return t;const{axis:n,value:r}=this.options;return mf(pf({},t),{[n]:r})}};la.configure=Xn(la);var gf=la;gf.configure({axis:"x",value:0});var Zy=gf.configure({axis:"y",value:0}),Xl=class extends Cr{apply({transform:t}){var n;const{size:r=20}=(n=this.options)!=null?n:{},s=typeof r=="number"?r:r.x,o=typeof r=="number"?r:r.y;return mf(pf({},t),{x:Math.ceil(t.x/s)*s,y:Math.ceil(t.y/o)*o})}};Xl.configure=Xn(Xl);const vf=e=>{let t=!1;const n=e.map(r=>r===Yo?(t=!0,Yo.configure({dropAnimation:null})):r);return t||console.warn("[waveform-playlist] noDropAnimationPlugins: Feedback plugin not found in defaults — drop animation may not be disabled. Check @dnd-kit/dom version."),n},Hy=D.div`
1050
1045
  position: absolute;
1051
1046
  top: 0;
1052
1047
  left: 0;
@@ -1056,9 +1051,9 @@ self.onmessage = function(e) {
1056
1051
  z-index: 100;
1057
1052
  pointer-events: none;
1058
1053
  will-change: transform;
1059
- `,Zy=({color:e="#ff0000"})=>{const t=g.useRef(null),n=g.useRef(null),{isPlaying:r,currentTimeRef:s}=Us(),{samplesPerPixel:o,sampleRate:a,progressBarWidth:i}=Ys();return g.useEffect(()=>{const l=()=>{if(t.current){const u=(s.current??0)*a/o;t.current.style.transform=`translate3d(${u}px, 0, 0)`}r&&(n.current=requestAnimationFrame(l))};return r?n.current=requestAnimationFrame(l):l(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,a,o,s]),g.useEffect(()=>{if(!r&&t.current){const c=(s.current??0)*a/o;t.current.style.transform=`translate3d(${c}px, 0, 0)`}}),C.jsx(jy,{ref:t,$color:e,$width:i,"data-playhead":!0})},Hy=P.div`
1054
+ `,Gy=({color:e="#ff0000"})=>{const t=g.useRef(null),n=g.useRef(null),{isPlaying:r,currentTimeRef:s}=Us(),{samplesPerPixel:o,sampleRate:a,progressBarWidth:i}=Ys();return g.useEffect(()=>{const l=()=>{if(t.current){const u=(s.current??0)*a/o;t.current.style.transform=`translate3d(${u}px, 0, 0)`}r&&(n.current=requestAnimationFrame(l))};return r?n.current=requestAnimationFrame(l):l(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,a,o,s]),g.useEffect(()=>{if(!r&&t.current){const c=(s.current??0)*a/o;t.current.style.transform=`translate3d(${c}px, 0, 0)`}}),C.jsx(Hy,{ref:t,$color:e,$width:i,"data-playhead":!0})},Uy=D.div`
1060
1055
  position: relative;
1061
- `,Gy=P.div`
1056
+ `,Xy=D.div`
1062
1057
  position: absolute;
1063
1058
  top: ${e=>e.$top}px;
1064
1059
  left: 0;
@@ -1068,7 +1063,7 @@ self.onmessage = function(e) {
1068
1063
  z-index: 0;
1069
1064
  transform: translateZ(0);
1070
1065
  backface-visibility: hidden;
1071
- `,Uy=P.div`
1066
+ `,Yy=D.div`
1072
1067
  position: absolute;
1073
1068
  top: ${e=>e.$top}px;
1074
1069
  left: 0;
@@ -1077,8 +1072,8 @@ self.onmessage = function(e) {
1077
1072
  pointer-events: none;
1078
1073
  z-index: 1;
1079
1074
  will-change: width;
1080
- `,Xy=P.div`
1075
+ `,Ky=D.div`
1081
1076
  position: relative;
1082
1077
  z-index: 2;
1083
- `,Yy=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=g.useRef(null),s=g.useRef(null),o=zr(),{waveHeight:a}=Hs(),{isPlaying:i,currentTimeRef:l}=Us(),{samplesPerPixel:c,sampleRate:u}=Ys(),f=o?.waveProgressColor||"rgba(0, 0, 0, 0.1)";g.useEffect(()=>{const v=()=>{if(r.current){const m=(l.current??0)*u,b=e+t;let _=0;if(m<=e)_=0;else if(m>=b)_=n.length;else{const w=m-e;_=Math.floor(w/c)}r.current.style.width=`${_}px`}i&&(s.current=requestAnimationFrame(v))};return i?s.current=requestAnimationFrame(v):v(),()=>{s.current&&(cancelAnimationFrame(s.current),s.current=null)}},[i,u,c,e,t,n.length,l]),g.useEffect(()=>{if(!i&&r.current){const y=(l.current??0)*u,m=e+t;let b=0;if(y<=e)b=0;else if(y>=m)b=n.length;else{const _=y-e;b=Math.floor(_/c)}r.current.style.width=`${b}px`}});const h=o?.waveformDrawMode||"inverted";let d;h==="inverted"?d=o?.selectedWaveFillColor||o?.waveFillColor||"white":d=o?.selectedWaveOutlineColor||o?.waveOutlineColor||"grey";const p=en(d);return C.jsxs(Hy,{children:[C.jsx(Gy,{$color:p,$height:a,$top:n.index*a,$width:n.length}),C.jsx(Uy,{ref:r,$color:f,$height:a,$top:n.index*a}),C.jsx(Xy,{children:C.jsx(Pd,{...n,isSelected:!0,transparentBackground:!0})})]})},vf=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:r,className:s})=>{const o=zr(),{isPlaying:a}=Us(),{annotations:i,activeAnnotationId:l}=Xs(),c=g.useContext(Ks),{play:u,seekTo:f,setActiveAnnotationId:h,setAnnotations:d,setScrollContainer:p}=bi(),{duration:v,peaksDataArray:y,sampleRate:m,waveHeight:b,timeScaleHeight:_,samplesPerPixel:w,controls:x,playoutRef:S,barWidth:k,barGap:E}=Ys(),[T,I]=g.useState(0),[M,$]=g.useState(0),[A,R]=g.useState(!1),W=g.useRef(null),q=g.useCallback(N=>{W.current=N,p(N)},[p]),z=Math.floor(v*m/w),J=g.useCallback(async N=>{h(N.id);try{await u(N.start)}catch(G){console.error("waveform-playlist: Failed to start playback for annotation",N.id,G)}},[h,u]),ee=g.useCallback(N=>{d(N),r?.(N)},[d,r]),{onDragStart:j,onDragMove:se,onDragEnd:U}=jd({annotations:i,onAnnotationsChange:ee,samplesPerPixel:w,sampleRate:m,duration:v,linkEndpoints:n}),ie=g.useRef(0),le=g.useCallback(N=>{const G=N.currentTarget.getBoundingClientRect(),Z=(N.clientX-G.left)*w/m;ie.current=Z,R(!0),I(Z),$(Z)},[w,m]),ge=g.useCallback(N=>{if(!A)return;const G=N.currentTarget.getBoundingClientRect(),Z=(N.clientX-G.left)*w/m;$(Z)},[A,w,m]),Se=g.useCallback(N=>{if(!A)return;if(R(!1),a&&S.current){const _e=Math.max(0,ie.current);f(_e),I(_e),$(_e),S.current.stop(),u(_e);return}const G=N.currentTarget.getBoundingClientRect(),Z=(N.clientX-G.left)*w/m,Q=Math.min(T,Z),O=Math.max(T,Z);Math.abs(O-Q)<.1?(f(Q),I(Q),$(Q)):(I(Q),$(O))},[A,T,w,m,f,a,S,u]);return y.length===0?C.jsx("div",{className:s,children:"Loading waveform..."}):C.jsx(Dd,{children:C.jsx(Nr.Provider,{value:{samplesPerPixel:w,sampleRate:m,zoomLevels:[w],waveHeight:b,timeScaleHeight:_,duration:v*1e3,controls:x,barWidth:k,barGap:E},children:C.jsx(mi,{theme:o,backgroundColor:en(o.waveOutlineColor),timescaleBackgroundColor:o.timescaleBackgroundColor,timescaleWidth:z,tracksWidth:z,controlsWidth:x.show?x.width:0,onTracksMouseDown:le,onTracksMouseMove:ge,onTracksMouseUp:Se,scrollContainerRef:q,isSelecting:A,timescale:_>0?C.jsx(Fd,{}):void 0,children:C.jsxs(C.Fragment,{children:[y.map((N,G)=>{const ye=N.length>0?Math.max(...N.map(Z=>Z.peaks.data.length)):1;return C.jsx(Od,{numChannels:ye,backgroundColor:en(o.waveOutlineColor),offset:0,width:z,hasClipHeaders:!1,trackId:`media-element-track-${G}`,isSelected:!0,children:N.map((Z,Q)=>{const O=Z.peaks,_e=O.length;return C.jsx(oa,{clipId:Z.clipId,trackIndex:G,clipIndex:Q,trackName:Z.trackName,startSample:Z.startSample,durationSamples:Z.durationSamples,samplesPerPixel:w,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${G}`,children:O.data.map((Ne,Be)=>C.jsx(Yy,{index:Be,data:Ne,bits:O.bits,length:_e,clipStartSample:Z.startSample,clipDurationSamples:Z.durationSamples},`${G}-${Q}-${Be}`))},`${G}-${Q}`)})},G)}),i.length>0&&c&&C.jsx(ky,{onDragStart:j,onDragMove:se,onDragEnd:U,modifiers:t?[zy]:[],plugins:gf,children:C.jsx(c.AnnotationBoxesWrapper,{height:30,width:z,children:i.map((N,G)=>{const ye=N.start*m/w,Z=N.end*m/w,Q=e?e(N,G):N.id;return C.jsx(c.AnnotationBox,{annotationId:N.id,annotationIndex:G,startPosition:ye,endPosition:Z,label:Q,color:"#ff9800",isActive:N.id===l,onClick:()=>J(N),editable:t},N.id)})})}),T!==M&&C.jsx(Td,{startPosition:Math.min(T,M)*m/w,endPosition:Math.max(T,M)*m/w,color:o.selectionColor}),C.jsx(Zy,{color:o.playheadColor})]})})})})},yf=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,editable:r=!1,controls:s,annotationListConfig:o,scrollActivePosition:a="center",scrollActiveContainer:i="nearest"})=>{const{annotations:l,activeAnnotationId:c,continuousPlay:u}=Xs(),f=Sn(),{setAnnotations:h}=bi(),d=o??{linkEndpoints:!1,continuousPlay:u},p=g.useCallback(y=>{h(y),n?.(y)},[h,n]),{AnnotationText:v}=f;return C.jsx(v,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:a,scrollActiveContainer:i,editable:r,controls:r?s:void 0,annotationListConfig:d,height:e,onAnnotationUpdate:p,renderAnnotationItem:t})},Ky=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:r=!1,linkEndpoints:s=!1,onAnnotationUpdate:o,scrollActivePosition:a="center",scrollActiveContainer:i="nearest",className:l})=>{const{annotations:c}=Xs();return C.jsxs(C.Fragment,{children:[C.jsx(vf,{getAnnotationBoxLabel:t,editable:r,linkEndpoints:s,onAnnotationUpdate:o,className:l}),c.length>0&&C.jsx(yf,{height:e,renderAnnotationItem:n,onAnnotationUpdate:o,editable:r,annotationListConfig:{linkEndpoints:s,continuousPlay:!1},scrollActivePosition:a,scrollActiveContainer:i})]})},Ps=class Ps extends Cr{apply(t){const{transform:n,source:r}=t;if(!r?.data||!this.options)return n;const{boundary:s,trackIndex:o,clipIndex:a}=r.data;if(s)return{x:0,y:0};const{tracks:i,samplesPerPixel:l}=this.options,c=i[o];if(!c)return n;const u=c.clips[a];if(!u)return n;const f=n.x*l,h=[...c.clips].sort((v,y)=>v.startSample-y.startSample),d=h.findIndex(v=>v.id===u.id);return{x:rc(u,f,h,d)/l,y:0}}};Ps.configure=Xn(Ps);let ua=Ps;exports.Tone=ql;exports.AnnotationIntegrationProvider=ny;exports.AudioPosition=Q0;exports.AutomaticScrollCheckbox=ty;exports.ClipCollisionModifier=ua;exports.ContinuousPlayCheckbox=ry;exports.DownloadAnnotationsButton=ay;exports.EditableCheckbox=oy;exports.ExportWavButton=iy;exports.FastForwardButton=j0;exports.LinkEndpointsCheckbox=sy;exports.LoopButton=G0;exports.MasterVolumeControl=K0;exports.MediaElementAnnotationList=yf;exports.MediaElementPlaylist=vf;exports.MediaElementPlaylistProvider=W0;exports.MediaElementWaveform=Ky;exports.PauseButton=V0;exports.PlayButton=B0;exports.PlaylistAnnotationList=tf;exports.PlaylistVisualization=ef;exports.RewindButton=z0;exports.SelectionTimeInputs=ey;exports.SetLoopRegionButton=U0;exports.SkipBackwardButton=Z0;exports.SkipForwardButton=H0;exports.SpectrogramIntegrationProvider=hy;exports.StopButton=N0;exports.TimeFormatSelect=q0;exports.Waveform=vy;exports.WaveformPlaylistProvider=F0;exports.ZoomInButton=X0;exports.ZoomOutButton=Y0;exports.createEffectChain=_0;exports.createEffectInstance=Tr;exports.effectCategories=v0;exports.effectDefinitions=jr;exports.getEffectDefinition=yi;exports.getEffectsByCategory=g0;exports.getShortcutLabel=h0;exports.getWaveformDataMetadata=n0;exports.loadPeaksFromWaveformData=t0;exports.loadWaveformData=vi;exports.noDropAnimationPlugins=gf;exports.useAnnotationDragHandlers=jd;exports.useAnnotationIntegration=Sn;exports.useAnnotationKeyboardControls=m0;exports.useAudioTracks=l0;exports.useClipDragHandlers=c0;exports.useClipSplitting=f0;exports.useDragSensors=d0;exports.useDynamicEffects=x0;exports.useDynamicTracks=P0;exports.useExportWav=Zd;exports.useKeyboardShortcuts=Ds;exports.useMasterAnalyser=i0;exports.useMasterVolume=zd;exports.useMediaElementAnimation=Us;exports.useMediaElementControls=bi;exports.useMediaElementData=Ys;exports.useMediaElementState=Xs;exports.usePlaybackAnimation=lt;exports.usePlaybackShortcuts=p0;exports.usePlaylistControls=Pe;exports.usePlaylistData=vt;exports.usePlaylistState=ct;exports.useSpectrogramIntegration=py;exports.useTimeFormat=Vd;exports.useTrackDynamicEffects=C0;exports.useZoomControls=Nd;exports.waveformDataToPeaks=Wd;
1078
+ `,qy=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=g.useRef(null),s=g.useRef(null),o=zr(),{waveHeight:a}=Hs(),{isPlaying:i,currentTimeRef:l}=Us(),{samplesPerPixel:c,sampleRate:u}=Ys(),f=o?.waveProgressColor||"rgba(0, 0, 0, 0.1)";g.useEffect(()=>{const v=()=>{if(r.current){const m=(l.current??0)*u,b=e+t;let _=0;if(m<=e)_=0;else if(m>=b)_=n.length;else{const w=m-e;_=Math.floor(w/c)}r.current.style.width=`${_}px`}i&&(s.current=requestAnimationFrame(v))};return i?s.current=requestAnimationFrame(v):v(),()=>{s.current&&(cancelAnimationFrame(s.current),s.current=null)}},[i,u,c,e,t,n.length,l]),g.useEffect(()=>{if(!i&&r.current){const y=(l.current??0)*u,m=e+t;let b=0;if(y<=e)b=0;else if(y>=m)b=n.length;else{const _=y-e;b=Math.floor(_/c)}r.current.style.width=`${b}px`}});const h=o?.waveformDrawMode||"inverted";let d;h==="inverted"?d=o?.selectedWaveFillColor||o?.waveFillColor||"white":d=o?.selectedWaveOutlineColor||o?.waveOutlineColor||"grey";const p=en(d);return C.jsxs(Uy,{children:[C.jsx(Xy,{$color:p,$height:a,$top:n.index*a,$width:n.length}),C.jsx(Yy,{ref:r,$color:f,$height:a,$top:n.index*a}),C.jsx(Ky,{children:C.jsx(Fd,{...n,isSelected:!0,transparentBackground:!0})})]})},yf=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:r,className:s})=>{const o=zr(),{isPlaying:a}=Us(),{annotations:i,activeAnnotationId:l}=Xs(),c=g.useContext(Ks),{play:u,seekTo:f,setActiveAnnotationId:h,setAnnotations:d,setScrollContainer:p}=yi(),{duration:v,peaksDataArray:y,sampleRate:m,waveHeight:b,timeScaleHeight:_,samplesPerPixel:w,controls:x,playoutRef:S,barWidth:k,barGap:E}=Ys(),[M,I]=g.useState(0),[T,$]=g.useState(0),[A,P]=g.useState(!1),W=g.useRef(null),J=g.useCallback(N=>{W.current=N,p(N)},[p]),G=Math.floor(v*m/w),Q=g.useCallback(async N=>{h(N.id);try{await u(N.start)}catch(H){console.error("waveform-playlist: Failed to start playback for annotation",N.id,H)}},[h,u]),ee=g.useCallback(N=>{d(N),r?.(N)},[d,r]),{onDragStart:z,onDragMove:se,onDragEnd:U}=Zd({annotations:i,onAnnotationsChange:ee,samplesPerPixel:w,sampleRate:m,duration:v,linkEndpoints:n}),ie=g.useRef(0),le=g.useCallback(N=>{const H=N.currentTarget.getBoundingClientRect(),j=(N.clientX-H.left)*w/m;ie.current=j,P(!0),I(j),$(j)},[w,m]),ge=g.useCallback(N=>{if(!A)return;const H=N.currentTarget.getBoundingClientRect(),j=(N.clientX-H.left)*w/m;$(j)},[A,w,m]),Se=g.useCallback(N=>{if(!A)return;if(P(!1),a&&S.current){const _e=Math.max(0,ie.current);f(_e),I(_e),$(_e),S.current.stop(),u(_e);return}const H=N.currentTarget.getBoundingClientRect(),j=(N.clientX-H.left)*w/m,q=Math.min(M,j),O=Math.max(M,j);Math.abs(O-q)<.1?(f(q),I(q),$(q)):(I(q),$(O))},[A,M,w,m,f,a,S,u]);return y.length===0?C.jsx("div",{className:s,children:"Loading waveform..."}):C.jsx(Pd,{children:C.jsx(Nr.Provider,{value:{samplesPerPixel:w,sampleRate:m,zoomLevels:[w],waveHeight:b,timeScaleHeight:_,duration:v*1e3,controls:x,barWidth:k,barGap:E},children:C.jsx(pi,{theme:o,backgroundColor:en(o.waveOutlineColor),timescaleBackgroundColor:o.timescaleBackgroundColor,timescaleWidth:G,tracksWidth:G,controlsWidth:x.show?x.width:0,onTracksMouseDown:le,onTracksMouseMove:ge,onTracksMouseUp:Se,scrollContainerRef:J,isSelecting:A,timescale:_>0?C.jsx(Od,{}):void 0,children:C.jsxs(C.Fragment,{children:[y.map((N,H)=>{const ye=N.length>0?Math.max(...N.map(j=>j.peaks.data.length)):1;return C.jsx(Ld,{numChannels:ye,backgroundColor:en(o.waveOutlineColor),offset:0,width:G,hasClipHeaders:!1,trackId:`media-element-track-${H}`,isSelected:!0,children:N.map((j,q)=>{const O=j.peaks,_e=O.length;return C.jsx(sa,{clipId:j.clipId,trackIndex:H,clipIndex:q,trackName:j.trackName,startSample:j.startSample,durationSamples:j.durationSamples,samplesPerPixel:w,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${H}`,children:O.data.map((Ne,Be)=>C.jsx(qy,{index:Be,data:Ne,bits:O.bits,length:_e,clipStartSample:j.startSample,clipDurationSamples:j.durationSamples},`${H}-${q}-${Be}`))},`${H}-${q}`)})},H)}),i.length>0&&c&&C.jsx(Iy,{onDragStart:z,onDragMove:se,onDragEnd:U,modifiers:t?[Zy]:[],plugins:vf,children:C.jsx(c.AnnotationBoxesWrapper,{height:30,width:G,children:i.map((N,H)=>{const ye=N.start*m/w,j=N.end*m/w,q=e?e(N,H):N.id;return C.jsx(c.AnnotationBox,{annotationId:N.id,annotationIndex:H,startPosition:ye,endPosition:j,label:q,color:"#ff9800",isActive:N.id===l,onClick:()=>Q(N),editable:t},N.id)})})}),M!==T&&C.jsx($d,{startPosition:Math.min(M,T)*m/w,endPosition:Math.max(M,T)*m/w,color:o.selectionColor}),C.jsx(Gy,{color:o.playheadColor})]})})})})},bf=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,editable:r=!1,controls:s,annotationListConfig:o,scrollActivePosition:a="center",scrollActiveContainer:i="nearest"})=>{const{annotations:l,activeAnnotationId:c,continuousPlay:u}=Xs(),f=Sn(),{setAnnotations:h}=yi(),d=o??{linkEndpoints:!1,continuousPlay:u},p=g.useCallback(y=>{h(y),n?.(y)},[h,n]),{AnnotationText:v}=f;return C.jsx(v,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:a,scrollActiveContainer:i,editable:r,controls:r?s:void 0,annotationListConfig:d,height:e,onAnnotationUpdate:p,renderAnnotationItem:t})},Jy=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:r=!1,linkEndpoints:s=!1,onAnnotationUpdate:o,scrollActivePosition:a="center",scrollActiveContainer:i="nearest",className:l})=>{const{annotations:c}=Xs();return C.jsxs(C.Fragment,{children:[C.jsx(yf,{getAnnotationBoxLabel:t,editable:r,linkEndpoints:s,onAnnotationUpdate:o,className:l}),c.length>0&&C.jsx(bf,{height:e,renderAnnotationItem:n,onAnnotationUpdate:o,editable:r,annotationListConfig:{linkEndpoints:s,continuousPlay:!1},scrollActivePosition:a,scrollActiveContainer:i})]})},Ps=class Ps extends Cr{apply(t){const{transform:n,source:r}=t;if(!r?.data||!this.options)return n;const{boundary:s,trackIndex:o,clipIndex:a}=r.data;if(s)return{x:0,y:0};const{tracks:i,samplesPerPixel:l}=this.options,c=i[o];if(!c)return n;const u=c.clips[a];if(!u)return n;const f=n.x*l,h=[...c.clips].sort((v,y)=>v.startSample-y.startSample),d=h.findIndex(v=>v.id===u.id);return{x:rc(u,f,h,d)/l,y:0}}};Ps.configure=Xn(Ps);let ca=Ps;exports.Tone=Kl;exports.AnnotationIntegrationProvider=sy;exports.AudioPosition=ty;exports.AutomaticScrollCheckbox=ry;exports.ClipCollisionModifier=ca;exports.ContinuousPlayCheckbox=oy;exports.DownloadAnnotationsButton=ly;exports.EditableCheckbox=iy;exports.ExportWavButton=cy;exports.FastForwardButton=H0;exports.LinkEndpointsCheckbox=ay;exports.LoopButton=X0;exports.MasterVolumeControl=J0;exports.MediaElementAnnotationList=bf;exports.MediaElementPlaylist=yf;exports.MediaElementPlaylistProvider=V0;exports.MediaElementWaveform=Jy;exports.PauseButton=z0;exports.PlayButton=N0;exports.PlaylistAnnotationList=nf;exports.PlaylistVisualization=tf;exports.RewindButton=Z0;exports.SelectionTimeInputs=ny;exports.SetLoopRegionButton=Y0;exports.SkipBackwardButton=G0;exports.SkipForwardButton=U0;exports.SpectrogramIntegrationProvider=my;exports.StopButton=j0;exports.TimeFormatSelect=Q0;exports.Waveform=by;exports.WaveformPlaylistProvider=L0;exports.ZoomInButton=K0;exports.ZoomOutButton=q0;exports.createEffectChain=C0;exports.createEffectInstance=Tr;exports.effectCategories=b0;exports.effectDefinitions=jr;exports.getEffectDefinition=vi;exports.getEffectsByCategory=y0;exports.getShortcutLabel=m0;exports.getWaveformDataMetadata=r0;exports.loadPeaksFromWaveformData=n0;exports.loadWaveformData=gi;exports.noDropAnimationPlugins=vf;exports.useAnnotationDragHandlers=Zd;exports.useAnnotationIntegration=Sn;exports.useAnnotationKeyboardControls=v0;exports.useAudioTracks=c0;exports.useClipDragHandlers=d0;exports.useClipSplitting=p0;exports.useDragSensors=h0;exports.useDynamicEffects=S0;exports.useDynamicTracks=O0;exports.useExportWav=Hd;exports.useKeyboardShortcuts=Ds;exports.useMasterAnalyser=l0;exports.useMasterVolume=jd;exports.useMediaElementAnimation=Us;exports.useMediaElementControls=yi;exports.useMediaElementData=Ys;exports.useMediaElementState=Xs;exports.usePlaybackAnimation=lt;exports.usePlaybackShortcuts=g0;exports.usePlaylistControls=Pe;exports.usePlaylistData=vt;exports.usePlaylistState=ct;exports.useSpectrogramIntegration=gy;exports.useTimeFormat=Nd;exports.useTrackDynamicEffects=k0;exports.useZoomControls=zd;exports.waveformDataToPeaks=Bd;
1084
1079
  //# sourceMappingURL=index.js.map