@waveform-playlist/browser 9.0.2 → 9.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var vf=Object.create;var zi=Object.defineProperty;var yf=Object.getOwnPropertyDescriptor;var bf=Object.getOwnPropertyNames;var wf=Object.getPrototypeOf,_f=Object.prototype.hasOwnProperty;var xf=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of bf(t))!_f.call(e,s)&&s!==n&&zi(e,s,{get:()=>t[s],enumerable:!(r=yf(t,s))||r.enumerable});return e};var Cf=(e,t,n)=>(n=e!=null?vf(wf(e)):{},xf(t||!e||!e.__esModule?zi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("tone"),C=require("react/jsx-runtime"),f=require("react"),R=require("styled-components"),ro=require("react-dom");function Ll(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 zl=Ll(j),D=Ll(f);var Ye=1e3;function ma(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c}=e,u=t?.sampleRate??e.sampleRate??c?.sample_rate,d=t?.length??e.sourceDurationSamples??(c&&u?Math.ceil(c.duration*u):void 0);if(u===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(d===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 p=e.durationSamples??d;return{id:Hl(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:r,sampleRate:u,sourceDurationSamples:d,gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c}}function jl(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c}=e,u=t?.sampleRate??e.sampleRate??c?.sample_rate;if(u===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const d=t?.duration??e.sourceDuration??c?.duration;if(d===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 p=e.duration??d;return ma({audioBuffer:t,startSample:Math.round(n*u),durationSamples:Math.round(p*u),offsetSamples:Math.round(r*u),sampleRate:u,sourceDurationSamples:Math.ceil(d*u),gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c})}function Zl(e){const{name:t,clips:n=[],muted:r=!1,soloed:s=!1,volume:a=1,pan:o=0,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}=e;return{id:Hl(),name:t,clips:n,muted:r,soloed:s,volume:a,pan:o,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}}function Hl(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function ji(e){return[...e].sort((t,n)=>t.startSample-n.startSample)}function Zi(e){return e.startSample/e.sampleRate}function kf(e){return(e.startSample+e.durationSamples)/e.sampleRate}function Sf(e){return e.offsetSamples/e.sampleRate}function Ef(e){return e.durationSamples/e.sampleRate}var Hi=!1;function ga(e){const t=e._param;return!t&&!Hi&&(Hi=!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 Ni(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r;n[s]=t?a:1-a}return n}function If(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r,o=t?s:e-1-s;n[o]=Math.exp(2*a-1)/Math.E}return n}function Af(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 Mf(e,t,n=10){const r=new Float32Array(e);for(let s=0;s<e;s++){const a=t?s:e-1-s,o=s/e;r[a]=Math.log(1+n*o)/Math.log(1+n)}return r}function Nl(e,t,n){switch(e){case"linear":return Ni(t,n);case"exponential":return If(t,n);case"sCurve":return Af(t,n);case"logarithmic":return Mf(t,n);default:return Ni(t,n)}}function Xi(e,t,n,r="linear",s=0,a=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=Nl(r,1e4,!0),i=new Float32Array(o.length),l=a-s;for(let c=0;c<o.length;c++)i[c]=s+o[c]*l;e.setValueCurveAtTime(i,t,n)}}function Gi(e,t,n,r="linear",s=1,a=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=Nl(r,1e4,!1),i=new Float32Array(o.length),l=s-a;for(let c=0;c<o.length;c++)i[c]=a+o[c]*l;e.setValueCurveAtTime(i,t,n)}}var $f=class{constructor(e){this.activeSources=new Set,this._scheduleGuardOffset=0,this.track=e.track,this.volumeNode=new j.Volume(this.gainToDb(e.track.gain)),this.panNode=new j.Panner(e.track.stereoPan),this.muteGain=new j.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const t=e.destination||j.getDestination();if(e.effects){const o=e.effects(this.muteGain,t,!1);o&&(this.effectsCleanup=o)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]),r=j.getTransport(),s=j.getContext().rawContext,a=this.volumeNode.input.input;this.scheduledClips=n.map(o=>{const i=s.createGain();i.gain.value=o.gain,i.connect(a);const l=this.track.startTime+o.startTime,c=r.schedule(u=>{l<this._scheduleGuardOffset||this.startClipSource(o,i,u)},l);return{clipInfo:o,fadeGainNode:i,scheduleId:c}})}startClipSource(e,t,n,r,s){const o=j.getContext().rawContext.createBufferSource();o.buffer=e.buffer,o.connect(t);const i=r??e.offset,l=s??e.duration;try{o.start(n,i,l)}catch(c){console.warn(`[waveform-playlist] Failed to start source on track "${this.id}" (time=${n}, offset=${i}, duration=${l}):`,c),o.disconnect();return}this.activeSources.add(o),o.onended=()=>{this.activeSources.delete(o)}}setScheduleGuardOffset(e){this._scheduleGuardOffset=e}startMidClipSources(e,t){for(const{clipInfo:n,fadeGainNode:r}of this.scheduledClips){const s=this.track.startTime+n.startTime,a=s+n.duration;if(s<e&&a>e){const o=e-s,i=n.offset+o,l=n.duration-o;this.startClipSource(n,r,t,i,l)}}}stopAllSources(){this.activeSources.forEach(e=>{try{e.stop()}catch(t){console.warn(`[waveform-playlist] Error stopping source on track "${this.id}":`,t)}}),this.activeSources.clear()}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGainNode:s}=e,a=s.gain;a.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const i=r.fadeIn.duration;if(o<=0)Xi(a,t,i,r.fadeIn.type||"linear",0,r.gain);else{const l=i-o,c=o/i,u=r.gain*c;Xi(a,t,l,r.fadeIn.type||"linear",u,r.gain)}}else a.setValueAtTime(r.gain,t);if(r.fadeOut){const l=r.duration-r.fadeOut.duration-o;if(l>0){const c=t+l;Gi(a,c,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(l>-r.fadeOut.duration){const c=-l,u=r.fadeOut.duration-c,d=c/r.fadeOut.duration,p=r.gain*(1-d);Gi(a,t,u,r.fadeOut.type||"linear",p,0)}}}prepareFades(e,t){this.scheduledClips.forEach(n=>{const r=this.track.startTime+n.clipInfo.startTime,s=r+n.clipInfo.duration;if(!(t>=s))if(t>=r){const a=t-r+n.clipInfo.offset;this.scheduleFades(n,e,a)}else{const a=r-t;this.scheduleFades(n,e+a,n.clipInfo.offset)}})}cancelFades(){this.scheduledClips.forEach(({fadeGainNode:e,clipInfo:t})=>{const n=e.gain;n.cancelScheduledValues(0),n.setValueAtTime(t.gain,0)})}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;ga(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){const e=j.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}},Tf=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 j.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,j.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{j.getTransport().clear(this._completionEventId)}catch(e){console.warn("[waveform-playlist] Error clearing Transport completion event:",e)}this._completionEventId=null}}async init(){this.isInitialized||(await j.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new $f(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??j.now(),s=j.getTransport();this.clearCompletionEvent();const a=t??0;this.tracks.forEach(o=>{o.cancelFades(),o.prepareFades(r,a)}),n!==void 0&&(this._completionEventId=s.scheduleOnce(()=>{this._completionEventId=null;try{this.onPlaybackCompleteCallback?.()}catch(o){console.warn("[waveform-playlist] Error in playback completion callback:",o)}},a+n));try{s.state!=="stopped"&&s.stop(),this.tracks.forEach(o=>o.stopAllSources()),s.loopStart=this._loopStart,s.loopEnd=this._loopEnd,s.loop=this._loopEnabled,this.tracks.forEach(o=>o.setScheduleGuardOffset(a)),t!==void 0?s.start(r,t):s.start(r),s._clock._lastUpdate=r,this.tracks.forEach(o=>{o.startMidClipSources(a,r)})}catch(o){throw this.clearCompletionEvent(),this.tracks.forEach(i=>i.cancelFades()),console.warn("[waveform-playlist] Transport.start() failed. Audio playback could not begin.",o),o}}pause(){const e=j.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=j.getTransport();try{e.stop()}catch(t){console.warn("[waveform-playlist] Transport.stop() failed:",t)}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=j.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=j.now();this.tracks.forEach(a=>{try{a.stopAllSources(),a.cancelFades(),a.setScheduleGuardOffset(this._loopStart),a.startMidClipSources(this._loopStart,s),a.prepareFades(s,this._loopStart)}catch(o){console.warn(`[waveform-playlist] Error re-scheduling track "${a.id}" on loop:`,o)}})},r.on("loop",this._loopHandler)):!e&&this._loopHandler&&(r.off("loop",this._loopHandler),this._loopHandler=null)}getCurrentTime(){return j.getTransport().seconds}seekTo(e){j.getTransport().seconds=e}dispose(){if(this.clearCompletionEvent(),this._loopHandler){try{j.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 j.getContext()}get sampleRate(){return j.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Ur=null;function Df(){return Ur||(Ur=new j.Context,j.setContext(Ur)),Ur}function Rf(){return Df().rawContext}function Pf(e){let t=null,n=!1,r=0,s=!1,a=0,o=0,i=!1;function l(c){if(t){try{t.dispose()}catch(d){console.warn("[waveform-playlist] Error disposing previous playout during rebuild:",d)}t=null}r++;const u=r;t=new Tf({effects:e?.effects}),i&&t.init().catch(d=>{console.warn("[waveform-playlist] Failed to re-initialize playout after rebuild. Audio playback will require another user gesture.",d),i=!1});for(const d of c){const p=d.clips.filter(m=>m.audioBuffer);if(p.length===0)continue;const h=Math.min(...p.map(Zi)),g=Math.max(...p.map(kf)),b={id:d.id,name:d.name,gain:d.volume,muted:d.muted,soloed:d.soloed,stereoPan:d.pan,startTime:h,endTime:g},y=p.map(m=>({buffer:m.audioBuffer,startTime:Zi(m)-h,duration:Ef(m),offset:Sf(m),fadeIn:m.fadeIn,fadeOut:m.fadeOut,gain:m.gain}));t.addTrack({clips:y,track:b,effects:d.effects})}t.applyInitialSoloState(),t.setLoop(s,a,o),t.setOnPlaybackComplete(()=>{u===r&&(n=!1)})}return{async init(){t&&(await t.init(),i=!0)},setTracks(c){l(c)},play(c,u){if(!t){console.warn("[waveform-playlist] adapter.play() called but no playout is available. Tracks may not have been set, or the adapter was disposed.");return}const d=u!==void 0?u-c:void 0;t.play(j.now(),c,d),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,d){s=c,a=u,o=d,t?.setLoop(c,u,d)},dispose(){try{t?.dispose()}catch(c){console.warn("[waveform-playlist] Error disposing playout:",c)}t=null,n=!1}}}function Xl(e,t,n,r){let s=t;const a=-e.startSample;if(s=Math.max(s,a),r>0){const o=n[r-1],l=o.startSample+o.durationSamples-e.startSample;s=Math.max(s,l)}if(r<n.length-1){const i=n[r+1].startSample-(e.startSample+e.durationSamples);s=Math.min(s,i)}return s}function va(e,t,n,r,s,a){let o=t;if(n==="left"){if(o=Math.max(o,-e.startSample),o=Math.max(o,-e.offsetSamples),s>0){const i=r[s-1],l=i.startSample+i.durationSamples;o=Math.max(o,l-e.startSample)}o=Math.min(o,e.durationSamples-a)}else if(o=Math.max(o,a-e.durationSamples),o=Math.min(o,e.sourceDurationSamples-e.offsetSamples-e.durationSamples),s<r.length-1){const i=r[s+1];o=Math.min(o,i.startSample-e.startSample-e.durationSamples)}return o}function Wf(e,t){return Math.floor(e/t)*t}function Ff(e,t){const n=t-e.startSample,r=e.durationSamples-n,s=e.name?`${e.name} (1)`:void 0,a=e.name?`${e.name} (2)`:void 0,o=ma({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=ma({startSample:t,durationSamples:r,offsetSamples:e.offsetSamples+n,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:a,color:e.color,fadeOut:e.fadeOut,audioBuffer:e.audioBuffer,waveformData:e.waveformData});return{left:o,right:i}}function Gl(e,t,n){const r=e.startSample+e.durationSamples;if(t<=e.startSample||t>=r)return!1;const s=t-e.startSample,a=r-t;return s>=n&&a>=n}function Qs(e){let t=0;for(const n of e)for(const r of n.clips){const a=(r.startSample+r.durationSamples)/r.sampleRate;t=Math.max(t,a)}return t}function Yi(e,t){if(t.length===0)return 0;let n=0,r=Math.abs(t[0]-e);for(let s=1;s<t.length;s++){const a=Math.abs(t[s]-e);a<r&&(r=a,n=s)}return n}function Ui(e,t){return Math.max(0,Math.min(e,t))}var Of=44100,Bf=1e3,Vf=[256,512,1024,2048,4096,8192],Ki=.1,Lf=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??Of,this._zoomLevels=[...e.zoomLevels??Vf],this._adapter=e.adapter??null,this._zoomLevels.length===0)throw new Error("PlaylistEngine: zoomLevels must not be empty");const t=e.samplesPerPixel??Bf;this._zoomIndex=Yi(t,this._zoomLevels)}getState(){return{tracks:this._tracks.map(e=>({...e,clips:[...e.clips]})),tracksVersion:this._tracksVersion,duration:Qs(this._tracks),currentTime:this._currentTime,isPlaying:this._isPlaying,samplesPerPixel:this._zoomLevels[this._zoomIndex],sampleRate:this._sampleRate,selectedTrackId:this._selectedTrackId,zoomIndex:this._zoomIndex,canZoomIn:this._zoomIndex>0,canZoomOut:this._zoomIndex<this._zoomLevels.length-1,selectionStart:this._selectionStart,selectionEnd:this._selectionEnd,masterVolume:this._masterVolume,loopStart:this._loopStart,loopEnd:this._loopEnd,isLoopEnabled:this._isLoopEnabled}}setTracks(e){this._tracks=[...e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}addTrack(e){this._tracks=[...this._tracks,e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}removeTrack(e){this._tracks.some(t=>t.id===e)&&(this._tracks=this._tracks.filter(t=>t.id!==e),this._tracksVersion++,this._selectedTrackId===e&&(this._selectedTrackId=null),this._adapter?.setTracks(this._tracks),this._emitStateChange())}selectTrack(e){e!==this._selectedTrackId&&(this._selectedTrackId=e,this._emitStateChange())}moveClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] moveClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] moveClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=ji(r.clips),i=o.findIndex(c=>c.id===t),l=Xl(a,n,o,i);l!==0&&(this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=c.clips.map((d,p)=>p===s?{...d,startSample:Math.floor(d.startSample+l)}:d);return{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}splitClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] splitClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] splitClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=Math.floor(Ki*this._sampleRate);if(!Gl(a,n,o)){console.warn(`[waveform-playlist/engine] splitClip: cannot split clip "${t}" at sample ${n} (clip range: ${a.startSample}–${a.startSample+a.durationSamples}, minDuration: ${o})`);return}const{left:i,right:l}=Ff(a,n);this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=[...c.clips];return u.splice(s,1,i,l),{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}trimClip(e,t,n,r){const s=this._tracks.find(d=>d.id===e);if(!s){console.warn(`[waveform-playlist/engine] trimClip: track "${e}" not found`);return}const a=s.clips.findIndex(d=>d.id===t);if(a===-1){console.warn(`[waveform-playlist/engine] trimClip: clip "${t}" not found in track "${e}"`);return}const o=s.clips[a],i=ji(s.clips),l=i.findIndex(d=>d.id===t),c=Math.floor(Ki*this._sampleRate),u=va(o,r,n,i,l,c);u!==0&&(this._tracks=this._tracks.map(d=>{if(d.id!==e)return d;const p=d.clips.map((h,g)=>g!==a?h:n==="left"?{...h,startSample:h.startSample+u,offsetSamples:h.offsetSamples+u,durationSamples:h.durationSamples-u}:{...h,durationSamples:h.durationSamples+u});return{...d,clips:p}}),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=Qs(this._tracks);this._currentTime=Ui(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._loopStart&&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=Qs(this._tracks);this._currentTime=Ui(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._shouldActivateTransportLoop(),this._loopStart,this._loopEnd),this._emitStateChange())}setLoopEnabled(e){e!==this._isLoopEnabled&&(this._isLoopEnabled=e,this._adapter?.setLoop(e&&this._shouldActivateTransportLoop(),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=Yi(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)}}_emitStateChange(){this._emit("statechange",this.getState())}_shouldActivateTransportLoop(){if(!this._isPlaying)return!0;const e=this._adapter?.getCurrentTime()??this._currentTime;return e>=this._loopStart&&e<this._loopEnd}_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)}},zf=Symbol.for("preact-signals");function Rs(){if(Ut>1)Ut--;else{for(var e,t=!1;hr!==void 0;){var n=hr;for(hr=void 0,ya++;n!==void 0;){var r=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Ul(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ya=0,Ut--,t)throw e}}function Kt(e){if(Ut>0)return e();Ut++;try{return e()}finally{Rs()}}var pe=void 0;function _e(e){var t=pe;pe=void 0;try{return e()}finally{pe=t}}var hr=void 0,Ut=0,ya=0,ms=0;function Yl(e){if(pe!==void 0){var t=e.n;if(t===void 0||t.t!==pe)return t={i:0,S:e,p:pe.s,n:void 0,t:pe,e:void 0,x:void 0,r:t},pe.s!==void 0&&(pe.s.n=t),pe.s=t,e.n=t,32&pe.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=pe.s,t.n=void 0,pe.s.n=t,pe.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=zf;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:_e(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&&_e(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=pe;pe=void 0;try{e(n)}finally{pe=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=pe;pe=void 0;try{return this.value}finally{pe=e}};Object.defineProperty(st.prototype,"value",{get:function(){var e=Yl(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ya>100)throw new Error("Cycle detected");this.v=e,this.i++,ms++,Ut++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Rs()}}}});function Mr(e,t){return new st(e,t)}function Ul(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 Kl(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 ql(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 gn(e,t){st.call(this,void 0),this.x=e,this.s=void 0,this.g=ms-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}gn.prototype=new st;gn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ms))return!0;if(this.g=ms,this.f|=1,this.i>0&&!Ul(this))return this.f&=-2,!0;var e=pe;try{Kl(this),pe=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 pe=e,ql(this),this.f&=-2,!0};gn.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)};gn.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)}};gn.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(gn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Yl(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function qi(e,t){return new gn(e,t)}function Jl(e){var t=e.u;if(e.u=void 0,typeof t=="function"){Ut++;var n=pe;pe=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,so(e),r}finally{pe=n,Rs()}}}function so(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Jl(e)}function jf(e){if(pe!==this)throw new Error("Out-of-order effect");ql(this),pe=e,this.f&=-2,8&this.f&&so(this),Rs()}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,Jl(this),Kl(this),Ut++;var e=pe;return pe=this,jf.bind(this,e)};jn.prototype.N=function(){2&this.f||(this.f|=2,this.o=hr,hr=this)};jn.prototype.d=function(){this.f|=8,1&this.f||so(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 Zf=Object.create,ao=Object.defineProperty,Hf=Object.defineProperties,Nf=Object.getOwnPropertyDescriptor,Xf=Object.getOwnPropertyDescriptors,Ji=Object.getOwnPropertySymbols,Gf=Object.prototype.hasOwnProperty,Yf=Object.prototype.propertyIsEnumerable,Uf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zn=e=>{throw TypeError(e)},ba=(e,t,n)=>t in e?ao(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Kf=(e,t)=>{for(var n in t||(t={}))Gf.call(t,n)&&ba(e,n,t[n]);if(Ji)for(var n of Ji(t))Yf.call(t,n)&&ba(e,n,t[n]);return e},qf=(e,t)=>Hf(e,Xf(t)),Qi=(e,t)=>ao(e,"name",{value:t,configurable:!0}),Jf=e=>{var t;return[,,,Zf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],nr=e=>e!==void 0&&typeof e!="function"?Zn("Function expected"):e,Qf=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:a=>n._?Zn("Already initialized"):s.push(nr(a||null))}),ec=(e,t)=>ba(t,Uf("metadata"),e[3]),sn=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},Hn=(e,t,n,r,s,a)=>{var o,i,l,c,u,d=t&7,p=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?p?1:2:0,b=Ql[d+5],y=d>3&&(e[g-1]=[]),m=e[g]||(e[g]=[]),w=d&&(!h&&!p&&(s=s.prototype),d<5&&(d>3||!h)&&Nf(d<4?s:{get[n](){return fn(this,a)},set[n](v){return Xt(this,a,v)}},n));d?h&&d<4&&Qi(a,(d>2?"set ":d>1?"get ":"")+n):Qi(s,n);for(var _=r.length-1;_>=0;_--)c=Qf(d,n,l={},e[3],m),d&&(c.static=p,c.private=h,u=c.access={has:h?v=>eh(s,v):v=>n in v},d^3&&(u.get=h?v=>(d^1?fn:th)(v,s,d^4?a:w.get):v=>v[n]),d>2&&(u.set=h?(v,x)=>Xt(v,s,x,d^4?a:w.set):(v,x)=>v[n]=x)),i=(0,r[_])(d?d<4?h?a:w[b]:d>4?void 0:{get:w.get,set:w.set}:s,c),l._=1,d^4||i===void 0?nr(i)&&(d>4?y.unshift(i):d?h?a=i:w[b]=i:s=i):typeof i!="object"||i===null?Zn("Object expected"):(nr(o=i.get)&&(w.get=o),nr(o=i.set)&&(w.set=o),nr(o=i.init)&&y.unshift(o));return d||ec(e,s),w&&ao(s,n,w),h?d^4?a:w:s},oo=(e,t,n)=>t.has(e)||Zn("Cannot "+n),eh=(e,t)=>Object(t)!==t?Zn('Cannot use the "in" operator on this value'):e.has(t),fn=(e,t,n)=>(oo(e,t,"read from private field"),n?n.call(e):t.get(e)),Kr=(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),Xt=(e,t,n,r)=>(oo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),th=(e,t,n)=>(oo(e,t,"access private method"),n);function gs(e,t){if(t){let n;return qi(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return qi(e)}function br(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)=>!br(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(a=>!br(e[a],t[a]))}return!1}function ue({get:e},t){return{init(n){return Mr(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ae(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=gs(e.bind(this)),n.set(this,r)),r.value}}function ea(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,qf(Kf({},s),{enumerable:e}))})}}function $r(...e){const t=e.map(n=>Ct(n));return()=>t.forEach(n=>n())}var tc,nc,rc,sc,ac,oc,tt,io,ta,wa,_a,qe,lo,na,ic,xa,co,ra,Ca,ka;oc=[ue],ac=[ue],sc=[ue],rc=[ea()],nc=[ea()],tc=[ea()];var Jt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,sn(tt,5,this),Kr(this,qe),Kr(this,io,sn(tt,8,this)),sn(tt,11,this),Kr(this,lo,sn(tt,12,this)),sn(tt,15,this),Kr(this,co,sn(tt,16,this)),sn(tt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return fn(this,qe,Ca)}get initial(){return fn(this,qe,wa)}get previous(){return fn(this,qe,ic)}set current(e){const t=_e(()=>fn(this,qe,Ca));e&&t&&this.equals(t,e)||Kt(()=>{fn(this,qe,wa)||Xt(this,qe,e,_a),Xt(this,qe,t,xa),Xt(this,qe,e,ka)})}reset(e=this.defaultValue){Kt(()=>{Xt(this,qe,void 0,xa),Xt(this,qe,e,_a),Xt(this,qe,e,ka)})}};tt=Jf();io=new WeakMap;qe=new WeakSet;lo=new WeakMap;co=new WeakMap;ta=Hn(tt,20,"#initial",oc,qe,io),wa=ta.get,_a=ta.set;na=Hn(tt,20,"#previous",ac,qe,lo),ic=na.get,xa=na.set;ra=Hn(tt,20,"#current",sc,qe,co),Ca=ra.get,ka=ra.set;Hn(tt,2,"current",rc,Jt);Hn(tt,2,"initial",nc,Jt);Hn(tt,2,"previous",tc,Jt);ec(tt,Jt);function sa(e){return _e(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var nh=Object.create,lc=Object.defineProperty,rh=Object.getOwnPropertyDescriptor,el=Object.getOwnPropertySymbols,sh=Object.prototype.hasOwnProperty,ah=Object.prototype.propertyIsEnumerable,cc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ps=e=>{throw TypeError(e)},tl=Math.pow,Sa=(e,t,n)=>t in e?lc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oh=(e,t)=>{for(var n in t||(t={}))sh.call(t,n)&&Sa(e,n,t[n]);if(el)for(var n of el(t))ah.call(t,n)&&Sa(e,n,t[n]);return e},ih=e=>{var t;return[,,,nh((t=e?.[cc("metadata")])!=null?t:null)]},uc=["class","method","getter","setter","accessor","field","value","get","set"],dc=e=>e!==void 0&&typeof e!="function"?Ps("Function expected"):e,lh=(e,t,n,r,s)=>({kind:uc[e],name:t,metadata:r,addInitializer:a=>n._?Ps("Already initialized"):s.push(dc(a||null))}),ch=(e,t)=>Sa(t,cc("metadata"),e[3]),uh=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)a[s].call(n);return r},fc=(e,t,n,r,s,a)=>{for(var o,i,l,c,u=t&7,d=!1,p=!1,h=2,g=uc[u+5],b=e[h]||(e[h]=[]),y=(s=s.prototype,rh(s,n)),m=r.length-1;m>=0;m--)l=lh(u,n,i={},e[3],b),l.static=d,l.private=p,c=l.access={has:w=>n in w},c.get=w=>w[n],o=(0,r[m])(y[g],l),i._=1,dc(o)&&(y[g]=o);return y&&lc(s,n,y),s},hc=(e,t,n)=>t.has(e)||Ps("Cannot "+n),dh=(e,t,n)=>(hc(e,t,"read from private field"),t.get(e)),fh=(e,t,n)=>t.has(e)?Ps("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),hh=(e,t,n,r)=>(hc(e,t,"write to private field"),t.set(e,n),n),Tt=class Ea{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ea(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 Ea(t,n)}},Tr=class on{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:a,height:o,scale:i}=this,l=new on(s+t,r+n,a,o);return l.scale=oh({},i),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:a,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:a,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Tt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof on))return!1;const{left:n,top:r,width:s,height:a}=this;return n===t.left&&r===t.top&&s===t.width&&a===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:a}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=a}intersectionArea(t){return t instanceof on?ph(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 on(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(a,o)=>{const i=r[o],l=o==="x"?a.left:a.top,c=o==="x"?a.width:a.height;return i=="start"?l:i=="end"?l+c:l+c/2};return Tt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return on.from(t).intersectionRatio(on.from(n))}};function ph(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=s-r,i=a-n;return r<s&&n<a?o*i:0}var pc,mc,Ia,rs,Dr,Ws=class extends(Ia=Jt,mc=[Ae],pc=[Ae],Ia){constructor(t){const n=Tt.from(t);super(n,(r,s)=>Tt.equals(r,s)),uh(Dr,5,this),fh(this,rs,0),this.velocity={x:0,y:0}}get delta(){return Tt.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Tt.from(t),s={x:r.x-n.x,y:r.y-n.y},a=Date.now(),o=a-dh(this,rs),i=l=>Math.round(l/o*100);Kt(()=>{hh(this,rs,a),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Tt.from(t)),this.velocity={x:0,y:0}}};Dr=ih(Ia);rs=new WeakMap;fc(Dr,2,"delta",mc,Ws);fc(Dr,2,"direction",pc,Ws);ch(Dr,Ws);function Aa({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(tl(r,2)+tl(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 gc=(e=>(e.Horizontal="x",e.Vertical="y",e))(gc||{}),vc=Object.values(gc),mh=Object.create,uo=Object.defineProperty,gh=Object.defineProperties,vh=Object.getOwnPropertyDescriptor,yh=Object.getOwnPropertyDescriptors,vs=Object.getOwnPropertySymbols,yc=Object.prototype.hasOwnProperty,bc=Object.prototype.propertyIsEnumerable,wc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Nn=e=>{throw TypeError(e)},Ma=(e,t,n)=>t in e?uo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_c=(e,t)=>{for(var n in t||(t={}))yc.call(t,n)&&Ma(e,n,t[n]);if(vs)for(var n of vs(t))bc.call(t,n)&&Ma(e,n,t[n]);return e},xc=(e,t)=>gh(e,yh(t)),nl=(e,t)=>uo(e,"name",{value:t,configurable:!0}),Cc=(e,t)=>{var n={};for(var r in e)yc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&vs)for(var r of vs(e))t.indexOf(r)<0&&bc.call(e,r)&&(n[r]=e[r]);return n},Xn=e=>{var t;return[,,,mh((t=e?.[wc("metadata")])!=null?t:null)]},kc=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Nn("Function expected"):e,bh=(e,t,n,r,s)=>({kind:kc[e],name:t,metadata:r,addInitializer:a=>n._?Nn("Already initialized"):s.push(rr(a||null))}),vn=(e,t)=>Ma(t,wc("metadata"),e[3]),J=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},ce=(e,t,n,r,s,a)=>{var o,i,l,c,u,d=t&7,p=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?p?1:2:0,b=kc[d+5],y=d>3&&(e[g-1]=[]),m=e[g]||(e[g]=[]),w=d&&(!h&&!p&&(s=s.prototype),d<5&&(d>3||!h)&&vh(d<4?s:{get[n](){return He(this,a)},set[n](v){return wt(this,a,v)}},n));d?h&&d<4&&nl(a,(d>2?"set ":d>1?"get ":"")+n):nl(s,n);for(var _=r.length-1;_>=0;_--)c=bh(d,n,l={},e[3],m),d&&(c.static=p,c.private=h,u=c.access={has:h?v=>wh(s,v):v=>n in v},d^3&&(u.get=h?v=>(d^1?He:_h)(v,s,d^4?a:w.get):v=>v[n]),d>2&&(u.set=h?(v,x)=>wt(v,s,x,d^4?a:w.set):(v,x)=>v[n]=x)),i=(0,r[_])(d?d<4?h?a:w[b]:d>4?void 0:{get:w.get,set:w.set}:s,c),l._=1,d^4||i===void 0?rr(i)&&(d>4?y.unshift(i):d?h?a=i:w[b]=i:s=i):typeof i!="object"||i===null?Nn("Object expected"):(rr(o=i.get)&&(w.get=o),rr(o=i.set)&&(w.set=o),rr(o=i.init)&&y.unshift(o));return d||vn(e,s),w&&uo(s,n,w),h?d^4?a:w:s},fo=(e,t,n)=>t.has(e)||Nn("Cannot "+n),wh=(e,t)=>Object(t)!==t?Nn('Cannot use the "in" operator on this value'):e.has(t),He=(e,t,n)=>(fo(e,t,"read from private field"),n?n.call(e):t.get(e)),we=(e,t,n)=>t.has(e)?Nn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),wt=(e,t,n,r)=>(fo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),_h=(e,t,n)=>(fo(e,t,"access private method"),n);function Sc(e,t){return{plugin:e,options:t}}function Gn(e){return t=>Sc(e,t)}function ho(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Ec,wr,po,ss;Ec=[ue];var lt=class{constructor(e,t){this.manager=e,this.options=t,we(this,po,J(wr,8,this,!1)),J(wr,11,this),we(this,ss,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return _e(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=Ct(e.bind(this));return He(this,ss).add(t),t}destroy(){He(this,ss).forEach(e=>e())}static configure(e){return Sc(this,e)}};wr=Xn(null);po=new WeakMap;ss=new WeakMap;ce(wr,4,"disabled",Ec,lt,po);vn(wr,lt);var Rr=class extends lt{},as,aa=class{constructor(e){this.manager=e,this.instances=new Map,we(this,as,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(ho).reduceRight((r,s)=>r.some(({plugin:a})=>a===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 Rr)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 xh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var qr=[],Mn,$n,Ch=class extends lt{constructor(e){super(e),we(this,Mn),we(this,$n),this.computeCollisions=this.computeCollisions.bind(this),wt(this,$n,Mr(qr)),this.destroy=$r(()=>{const t=this.computeCollisions(),n=_e(()=>this.manager.dragOperation.position.current);if(t!==qr){const r=He(this,Mn);if(wt(this,Mn,n),r&&n.x==r.x&&n.y==r.y)return}else wt(this,Mn,void 0);He(this,$n).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){_e(()=>{e?He(this,$n).value=this.computeCollisions():wt(this,Mn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:a,status:o}=r;if(!o.initialized||!a)return qr;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 d=_e(()=>u({droppable:c,dragOperation:r}));d&&(c.collisionPriority!=null&&(d.priority=c.collisionPriority),i.push(d))}return l.length===0?qr:(i.sort(xh),i)}get collisions(){return He(this,$n).value}};Mn=new WeakMap;$n=new WeakMap;var kh=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)}},Sh=class extends kh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function os(e,t=!0){let n=!1;return xc(_c({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var Eh=class extends Rr{constructor(e){super(e);const t=(r,s)=>r.map(({id:a})=>a).join("")===s.map(({id:a})=>a).join("");let n=[];this.destroy=$r(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:a}=r;if(r.isDisabled())return;const o=os({collisions:a});if(s.dispatch("collision",o),o.defaultPrevented||t(a,n))return;n=a;const[i]=a;_e(()=>{var l;i?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(i?.id).then(()=>{r.enable()}))})})}},mo=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(mo||{}),go=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(go||{}),Ic,Ac,Mc,$c,Tc,Dc,Rc,xt,vo;Rc=[ue],Dc=[Ae],Tc=[Ae],$c=[Ae],Mc=[Ae],Ac=[Ae],Ic=[Ae];var zt=class{constructor(){J(xt,5,this),we(this,vo,J(xt,8,this,"idle")),J(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=Xn(null);vo=new WeakMap;ce(xt,4,"value",Rc,zt,vo);ce(xt,2,"current",Dc,zt);ce(xt,2,"idle",Tc,zt);ce(xt,2,"initializing",$c,zt);ce(xt,2,"initialized",Mc,zt);ce(xt,2,"dragging",Ac,zt);ce(xt,2,"dropped",Ic,zt);vn(xt,zt);var Ih=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return _e(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=os({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return _e(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:a}=e;Kt(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(a)});const o=os({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:i}=t;i.current==="initializing"&&(t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1}))}),r)})}move(e){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:a}=r;if(!s.dragging||!a||a.signal.aborted)return;const o=os({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var i,l,c,u,d;if(o.defaultPrevented)return;const p=(d=e.to)!=null?d:{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=p})})}stop(e={}){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let a;const o=()=>{const l={resume:()=>{},abort:()=>{}};return a=new Promise((c,u)=>{l.resume=c,l.abort=u}),l};s.abort();const i=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=_e(()=>{var u;return((u=r.source)==null?void 0:u.status)==="dropping"}),c=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:u}=r,d=Ct(()=>{u?.status==="idle"&&(d(),c())})}else this.manager.renderer.rendering.then(c)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),a?a.then(i).catch(()=>r.reset()):i()})}},Pc,Wc,Fc,Oc,it,yo,bo,wo,_o;Oc=[ue],Fc=[ue],Wc=[ue],Pc=[ue];var Qt=class{constructor(e,t){we(this,yo,J(it,8,this)),J(it,11,this),we(this,bo,J(it,12,this)),J(it,15,this),we(this,wo,J(it,16,this)),J(it,19,this),we(this,_o,J(it,20,this)),J(it,23,this);const{effects:n,id:r,data:s={},disabled:a=!1,register:o=!0}=e;let i=r;this.manager=t,this.id=r,this.data=s,this.disabled=a,this.effects=()=>{var l;return[()=>{const{id:c,manager:u}=this;if(c!==i)return u?.registry.register(this),()=>u?.registry.unregister(this)},...(l=n?.())!=null?l:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),t&&o&&queueMicrotask(this.register)}register(){var e;return(e=this.manager)==null?void 0:e.registry.register(this)}unregister(){var e;(e=this.manager)==null||e.registry.unregister(this)}destroy(){var e;(e=this.manager)==null||e.registry.unregister(this)}};it=Xn(null);yo=new WeakMap;bo=new WeakMap;wo=new WeakMap;_o=new WeakMap;ce(it,4,"manager",Oc,Qt,yo);ce(it,4,"id",Fc,Qt,bo);ce(it,4,"data",Wc,Qt,wo);ce(it,4,"disabled",Pc,Qt,_o);vn(it,Qt);var rl=class{constructor(){this.map=Mr(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r){const i=this.cleanupFunctions.get(r);i?.(),this.cleanupFunctions.delete(r)}const a=new Map(n);a.set(e,t),this.map.value=a;const o=$r(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Bc,Vc,Lc,zc,jc,Zc,$a,nt,xo,Co,ko,Dt=class extends($a=Qt,Zc=[ue],jc=[ue],zc=[ue],Lc=[Ae],Vc=[Ae],Bc=[Ae],$a){constructor(t,n){var r=t,{modifiers:s,type:a,sensors:o}=r,i=Cc(r,["modifiers","type","sensors"]);super(i,n),J(nt,5,this),we(this,xo,J(nt,8,this)),J(nt,11,this),we(this,Co,J(nt,12,this)),J(nt,15,this),we(this,ko,J(nt,16,this,this.isDragSource?"dragging":"idle")),J(nt,19,this),this.type=a,this.sensors=o,this.modifiers=s,this.alignment=i.alignment}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};nt=Xn($a);xo=new WeakMap;Co=new WeakMap;ko=new WeakMap;ce(nt,4,"type",Zc,Dt,xo);ce(nt,4,"modifiers",jc,Dt,Co);ce(nt,4,"status",zc,Dt,ko);ce(nt,2,"isDropping",Lc,Dt);ce(nt,2,"isDragging",Vc,Dt);ce(nt,2,"isDragSource",Bc,Dt);vn(nt,Dt);var Hc,Nc,Xc,Gc,Yc,Uc,Ta,Ve,So,Eo,Io,Ao,Mo,Rt=class extends(Ta=Qt,Uc=[ue],Yc=[ue],Gc=[ue],Xc=[ue],Nc=[ue],Hc=[Ae],Ta){constructor(t,n){var r=t,{accept:s,collisionDetector:a,collisionPriority:o,type:i}=r,l=Cc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),J(Ve,5,this),we(this,So,J(Ve,8,this)),J(Ve,11,this),we(this,Eo,J(Ve,12,this)),J(Ve,15,this),we(this,Io,J(Ve,16,this)),J(Ve,19,this),we(this,Ao,J(Ve,20,this)),J(Ve,23,this),we(this,Mo,J(Ve,24,this)),J(Ve,27,this),this.accept=s,this.collisionDetector=a,this.collisionPriority=o,this.type=i}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Ve=Xn(Ta);So=new WeakMap;Eo=new WeakMap;Io=new WeakMap;Ao=new WeakMap;Mo=new WeakMap;ce(Ve,4,"accept",Uc,Rt,So);ce(Ve,4,"type",Yc,Rt,Eo);ce(Ve,4,"collisionDetector",Gc,Rt,Io);ce(Ve,4,"collisionPriority",Xc,Rt,Ao);ce(Ve,4,"shape",Nc,Rt,Mo);ce(Ve,2,"isDropTarget",Hc,Rt);vn(Ve,Rt);var On=class extends lt{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Ah=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)}},is,Kc=class{constructor(e){this.options=e,we(this,is)}set controller(e){wt(this,is,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=He(this,is))==null||t.activate(e)}};is=new WeakMap;var _r=class extends lt{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Mh=class{constructor(e){this.draggables=new rl,this.droppables=new rl,this.plugins=new aa(e),this.sensors=new aa(e),this.modifiers=new aa(e)}register(e,t){if(e instanceof Dt)return this.draggables.register(e.id,e);if(e instanceof Rt)return this.droppables.register(e.id,e);if(e.prototype instanceof _r)return this.modifiers.register(e,t);if(e.prototype instanceof On)return this.sensors.register(e,t);if(e.prototype instanceof lt)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Qt)return e instanceof Dt?this.draggables.unregister(e.id,e):e instanceof Rt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof _r)return this.modifiers.unregister(e);if(e.prototype instanceof On)return this.sensors.unregister(e);if(e.prototype instanceof lt)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()}},qc,Jc,Qc,eu,tu,nu,ru,su,au,sr,ls,Tn,Me,$o,To,Do,Ro,Po,ar;au=[Ae],su=[ue],ru=[ue],nu=[ue],tu=[ue],eu=[ue],Qc=[Ae],Jc=[Ae],qc=[Ae];var It=class{constructor(e){J(Me,5,this),we(this,sr),we(this,ls),we(this,Tn,new Jt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new zt,we(this,$o,J(Me,8,this,!1)),J(Me,11,this),we(this,To,J(Me,12,this,null)),J(Me,15,this),we(this,Do,J(Me,16,this,null)),J(Me,19,this),we(this,Ro,J(Me,20,this,null)),J(Me,23,this),we(this,Po,J(Me,24,this,[])),J(Me,27,this),this.position=new Ws({x:0,y:0}),we(this,ar,{x:0,y:0}),wt(this,sr,e)}get shape(){const{current:e,initial:t,previous:n}=He(this,Tn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?He(this,Tn).current=e:He(this,Tn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=He(this,sr).registry.draggables.get(t);return n&&wt(this,ls,n),(e=n??He(this,ls))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=He(this,sr).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(xc(_c({},this.snapshot()),{transform:n}));return wt(this,ar,n),n}snapshot(){return _e(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:He(this,ar),shape:this.shape?sa(this.shape):null,position:sa(this.position),status:sa(this.status),canceled:this.canceled}))}reset(){Kt(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,He(this,Tn).reset(),this.position.reset({x:0,y:0}),wt(this,ar,{x:0,y:0}),this.modifiers=[]})}};Me=Xn(null);sr=new WeakMap;ls=new WeakMap;Tn=new WeakMap;$o=new WeakMap;To=new WeakMap;Do=new WeakMap;Ro=new WeakMap;Po=new WeakMap;ar=new WeakMap;ce(Me,2,"shape",au,It);ce(Me,4,"canceled",su,It,$o);ce(Me,4,"activatorEvent",ru,It,To);ce(Me,4,"sourceIdentifier",nu,It,Do);ce(Me,4,"targetIdentifier",tu,It,Ro);ce(Me,4,"modifiers",eu,It,Po);ce(Me,2,"source",Qc,It);ce(Me,2,"target",Jc,It);ce(Me,2,"transform",qc,It);vn(Me,It);var $h={get rendering(){return Promise.resolve()}};function Bt(e,t){return typeof e=="function"?e(t):e??t}var Th=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(p=>p.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=Bt(r.plugins,[]),a=Bt(r.sensors,[]),o=Bt(r.modifiers,[]),i=(n=r.renderer)!=null?n:$h,l=new Sh(this),c=new Mh(this);this.registry=c,this.monitor=l,this.renderer=i,this.actions=new Ih(this),this.dragOperation=new It(this),this.collisionObserver=new Ch(this),this.plugins=[Eh,...s],this.modifiers=o,this.sensors=a;const{destroy:u}=this,d=$r(()=>{var p,h,g;const b=_e(()=>this.dragOperation.modifiers),y=this.modifiers;for(const m of b)y.includes(m)||m.destroy();this.dragOperation.modifiers=(g=(h=(p=this.dragOperation.source)==null?void 0:p.modifiers)==null?void 0:h.map(m=>{const{plugin:w,options:_}=ho(m);return new w(this,_)}))!=null?g:y});this.destroy=()=>{d(),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}},ou=e=>{throw TypeError(e)},Wo=(e,t,n)=>t.has(e)||ou("Cannot "+n),te=(e,t,n)=>(Wo(e,t,"read from private field"),t.get(e)),ot=(e,t,n)=>t.has(e)?ou("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),pt=(e,t,n,r)=>(Wo(e,t,"write to private field"),t.set(e,n),n),iu=(e,t,n)=>(Wo(e,t,"access private method"),n);function Fs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Dh(e,t){const n=e.getAnimations();if(n.length>0)for(const r of n){if(r.playState!=="running")continue;const{effect:s}=r,o=(Fs(s)?s.getKeyframes():[]).filter(t);if(o.length>0)return[o[o.length-1],r]}return null}function Os(e){const{width:t,height:n,top:r,left:s,bottom:a,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:a,right:o}}function Fo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Pr(e){return"nodeType"in e}function kt(e){var t,n,r;return e?Fo(e)?e:Pr(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 Oo(e){const{Document:t}=kt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function hn(e){return!e||Fo(e)?!1:e instanceof kt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function lu(e){return e instanceof kt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function yn(e){return e?Fo(e)?e.document:Pr(e)?Oo(e)?e:hn(e)||lu(e)?e.ownerDocument:document:document:document}function Rh(e){var t,n,r,s;const{documentElement:a}=yn(e),o=kt(e).visualViewport,i=(t=o?.width)!=null?t:a.clientWidth,l=(n=o?.height)!=null?n:a.clientHeight,c=(r=o?.offsetTop)!=null?r:0,u=(s=o?.offsetLeft)!=null?s:0;return{top:c,left:u,right:u+i,bottom:c+l,width:i,height:l}}function Ph(e,t){if(Wh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Wh(e){return e.tagName==="DETAILS"}function ys(e,t=e.getBoundingClientRect(),n=0){var r,s,a,o,i;let l=t;const{ownerDocument:c}=e,u=(r=c.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==c.documentElement;){if(!Ph(d)){const _=d.getBoundingClientRect(),v=n*(_.bottom-_.top),x=n*(_.right-_.left),k=n*(_.bottom-_.top),S=n*(_.right-_.left);l={top:Math.max(l.top,_.top-v),right:Math.min(l.right,_.right+x),bottom:Math.min(l.bottom,_.bottom+k),left:Math.max(l.left,_.left-S),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}d=d.parentElement}const p=u.visualViewport,h=(s=p?.offsetTop)!=null?s:0,g=(a=p?.offsetLeft)!=null?a:0,b=(o=p?.width)!=null?o:u.innerWidth,y=(i=p?.height)!=null?i:u.innerHeight,m=n*y,w=n*b;return l={top:Math.max(l.top,h-m),right:Math.min(l.right,g+b+w),bottom:Math.min(l.bottom,h+y+m),left:Math.max(l.left,g-w),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 cu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Da(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(...Da(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(...Da(s.document,t))}}catch{}return n}function Bo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function uu(){var e,t;const n=Bo()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Vo(e){return!e||!Pr(e)?!1:e instanceof kt(e).ShadowRoot}function bs(e){if(e&&Pr(e)){let t=e.getRootNode();if(Vo(t))return t;if(t instanceof Document)return t}return yn(e)}function du(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Fh(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((a,o)=>{const i=r[o];if(sl(a)&&sl(i)&&(a.type!=="file"&&(a.value=i.value),a.type==="radio"&&a.name&&(a.name=`Cloned__${a.name}`)),al(a)&&al(i)&&i.width>0&&i.height>0){const l=a.getContext("2d");l?.drawImage(i,0,0)}}),n}function sl(e){return"value"in e}function al(e){return e.tagName==="CANVAS"}function fu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Oh(r)){const{contentDocument:s}=r;if(s){const{left:a,top:o}=r.getBoundingClientRect();return fu(s,{x:t-a,y:n-o})}}return r}function Oh(e){return e?.tagName==="IFRAME"}var ol=new WeakMap;function Bh(e){return!!e.closest(`
1
+ "use strict";var vf=Object.create;var zi=Object.defineProperty;var yf=Object.getOwnPropertyDescriptor;var bf=Object.getOwnPropertyNames;var wf=Object.getPrototypeOf,_f=Object.prototype.hasOwnProperty;var xf=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of bf(t))!_f.call(e,s)&&s!==n&&zi(e,s,{get:()=>t[s],enumerable:!(r=yf(t,s))||r.enumerable});return e};var Cf=(e,t,n)=>(n=e!=null?vf(wf(e)):{},xf(t||!e||!e.__esModule?zi(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("tone"),C=require("react/jsx-runtime"),f=require("react"),R=require("styled-components"),ro=require("react-dom");function Ll(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 zl=Ll(j),D=Ll(f);var Ye=1e3;function ma(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c}=e,u=t?.sampleRate??e.sampleRate??c?.sample_rate,d=t?.length??e.sourceDurationSamples??(c&&u?Math.ceil(c.duration*u):void 0);if(u===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(d===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 p=e.durationSamples??d;return{id:Hl(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:r,sampleRate:u,sourceDurationSamples:d,gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c}}function jl(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:s=1,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c}=e,u=t?.sampleRate??e.sampleRate??c?.sample_rate;if(u===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const d=t?.duration??e.sourceDuration??c?.duration;if(d===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 p=e.duration??d;return ma({audioBuffer:t,startSample:Math.round(n*u),durationSamples:Math.round(p*u),offsetSamples:Math.round(r*u),sampleRate:u,sourceDurationSamples:Math.ceil(d*u),gain:s,name:a,color:o,fadeIn:i,fadeOut:l,waveformData:c})}function Zl(e){const{name:t,clips:n=[],muted:r=!1,soloed:s=!1,volume:a=1,pan:o=0,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}=e;return{id:Hl(),name:t,clips:n,muted:r,soloed:s,volume:a,pan:o,color:i,height:l,spectrogramConfig:c,spectrogramColorMap:u}}function Hl(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function ji(e){return[...e].sort((t,n)=>t.startSample-n.startSample)}function Zi(e){return e.startSample/e.sampleRate}function kf(e){return(e.startSample+e.durationSamples)/e.sampleRate}function Sf(e){return e.offsetSamples/e.sampleRate}function Ef(e){return e.durationSamples/e.sampleRate}var Hi=!1;function ga(e){const t=e._param;return!t&&!Hi&&(Hi=!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 Ni(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r;n[s]=t?a:1-a}return n}function If(e,t){const n=new Float32Array(e),r=e-1;for(let s=0;s<e;s++){const a=s/r,o=t?s:e-1-s;n[o]=Math.exp(2*a-1)/Math.E}return n}function Af(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 Mf(e,t,n=10){const r=new Float32Array(e);for(let s=0;s<e;s++){const a=t?s:e-1-s,o=s/e;r[a]=Math.log(1+n*o)/Math.log(1+n)}return r}function Nl(e,t,n){switch(e){case"linear":return Ni(t,n);case"exponential":return If(t,n);case"sCurve":return Af(t,n);case"logarithmic":return Mf(t,n);default:return Ni(t,n)}}function Xi(e,t,n,r="linear",s=0,a=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=Nl(r,1e4,!0),i=new Float32Array(o.length),l=a-s;for(let c=0;c<o.length;c++)i[c]=s+o[c]*l;e.setValueCurveAtTime(i,t,n)}}function Gi(e,t,n,r="linear",s=1,a=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(s,t),e.linearRampToValueAtTime(a,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(s,.001),t),e.exponentialRampToValueAtTime(Math.max(a,.001),t+n);else{const o=Nl(r,1e4,!1),i=new Float32Array(o.length),l=s-a;for(let c=0;c<o.length;c++)i[c]=a+o[c]*l;e.setValueCurveAtTime(i,t,n)}}var $f=class{constructor(e){this.activeSources=new Set,this._scheduleGuardOffset=0,this.track=e.track,this.volumeNode=new j.Volume(this.gainToDb(e.track.gain)),this.panNode=new j.Panner(e.track.stereoPan),this.muteGain=new j.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const t=e.destination||j.getDestination();if(e.effects){const o=e.effects(this.muteGain,t,!1);o&&(this.effectsCleanup=o)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]),r=j.getTransport(),s=j.getContext().rawContext,a=this.volumeNode.input.input;this.scheduledClips=n.map(o=>{const i=s.createGain();i.gain.value=o.gain,i.connect(a);const l=this.track.startTime+o.startTime,c=r.schedule(u=>{l<this._scheduleGuardOffset||this.startClipSource(o,i,u)},l);return{clipInfo:o,fadeGainNode:i,scheduleId:c}})}startClipSource(e,t,n,r,s){const o=j.getContext().rawContext.createBufferSource();o.buffer=e.buffer,o.connect(t);const i=r??e.offset,l=s??e.duration;try{o.start(n,i,l)}catch(c){console.warn(`[waveform-playlist] Failed to start source on track "${this.id}" (time=${n}, offset=${i}, duration=${l}):`,c),o.disconnect();return}this.activeSources.add(o),o.onended=()=>{this.activeSources.delete(o)}}setScheduleGuardOffset(e){this._scheduleGuardOffset=e}startMidClipSources(e,t){for(const{clipInfo:n,fadeGainNode:r}of this.scheduledClips){const s=this.track.startTime+n.startTime,a=s+n.duration;if(s<e&&a>e){const o=e-s,i=n.offset+o,l=n.duration-o;this.startClipSource(n,r,t,i,l)}}}stopAllSources(){this.activeSources.forEach(e=>{try{e.stop()}catch(t){console.warn(`[waveform-playlist] Error stopping source on track "${this.id}":`,t)}}),this.activeSources.clear()}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGainNode:s}=e,a=s.gain;a.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const i=r.fadeIn.duration;if(o<=0)Xi(a,t,i,r.fadeIn.type||"linear",0,r.gain);else{const l=i-o,c=o/i,u=r.gain*c;Xi(a,t,l,r.fadeIn.type||"linear",u,r.gain)}}else a.setValueAtTime(r.gain,t);if(r.fadeOut){const l=r.duration-r.fadeOut.duration-o;if(l>0){const c=t+l;Gi(a,c,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(l>-r.fadeOut.duration){const c=-l,u=r.fadeOut.duration-c,d=c/r.fadeOut.duration,p=r.gain*(1-d);Gi(a,t,u,r.fadeOut.type||"linear",p,0)}}}prepareFades(e,t){this.scheduledClips.forEach(n=>{const r=this.track.startTime+n.clipInfo.startTime,s=r+n.clipInfo.duration;if(!(t>=s))if(t>=r){const a=t-r+n.clipInfo.offset;this.scheduleFades(n,e,a)}else{const a=r-t;this.scheduleFades(n,e+a,n.clipInfo.offset)}})}cancelFades(){this.scheduledClips.forEach(({fadeGainNode:e,clipInfo:t})=>{const n=e.gain;n.cancelScheduledValues(0),n.setValueAtTime(t.gain,0)})}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;ga(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){const e=j.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}},Tf=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 j.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,j.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{j.getTransport().clear(this._completionEventId)}catch(e){console.warn("[waveform-playlist] Error clearing Transport completion event:",e)}this._completionEventId=null}}async init(){this.isInitialized||(await j.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new $f(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??j.now(),s=j.getTransport();this.clearCompletionEvent();const a=t??0;this.tracks.forEach(o=>{o.cancelFades(),o.prepareFades(r,a)}),n!==void 0&&(this._completionEventId=s.scheduleOnce(()=>{this._completionEventId=null;try{this.onPlaybackCompleteCallback?.()}catch(o){console.warn("[waveform-playlist] Error in playback completion callback:",o)}},a+n));try{s.state!=="stopped"&&s.stop(),this.tracks.forEach(o=>o.stopAllSources()),s.loopStart=this._loopStart,s.loopEnd=this._loopEnd,s.loop=this._loopEnabled,this.tracks.forEach(o=>o.setScheduleGuardOffset(a)),t!==void 0?s.start(r,t):s.start(r),s._clock._lastUpdate=r,this.tracks.forEach(o=>{o.startMidClipSources(a,r)})}catch(o){throw this.clearCompletionEvent(),this.tracks.forEach(i=>i.cancelFades()),console.warn("[waveform-playlist] Transport.start() failed. Audio playback could not begin.",o),o}}pause(){const e=j.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=j.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=j.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=j.now();this.tracks.forEach(a=>{try{a.stopAllSources(),a.cancelFades(),a.setScheduleGuardOffset(this._loopStart),a.startMidClipSources(this._loopStart,s),a.prepareFades(s,this._loopStart)}catch(o){console.warn(`[waveform-playlist] Error re-scheduling track "${a.id}" on loop:`,o)}})},r.on("loop",this._loopHandler)):!e&&this._loopHandler&&(r.off("loop",this._loopHandler),this._loopHandler=null)}getCurrentTime(){return j.getTransport().seconds}seekTo(e){j.getTransport().seconds=e}dispose(){if(this.clearCompletionEvent(),this._loopHandler){try{j.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 j.getContext()}get sampleRate(){return j.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Ur=null;function Df(){return Ur||(Ur=new j.Context,j.setContext(Ur)),Ur}function Rf(){return Df().rawContext}function Pf(e){let t=null,n=!1,r=0,s=!1,a=0,o=0,i=!1;function l(c){if(t){try{t.dispose()}catch(d){console.warn("[waveform-playlist] Error disposing previous playout during rebuild:",d)}t=null}r++;const u=r;t=new Tf({effects:e?.effects}),i&&t.init().catch(d=>{console.warn("[waveform-playlist] Failed to re-initialize playout after rebuild. Audio playback will require another user gesture.",d),i=!1});for(const d of c){const p=d.clips.filter(m=>m.audioBuffer);if(p.length===0)continue;const h=Math.min(...p.map(Zi)),g=Math.max(...p.map(kf)),b={id:d.id,name:d.name,gain:d.volume,muted:d.muted,soloed:d.soloed,stereoPan:d.pan,startTime:h,endTime:g},y=p.map(m=>({buffer:m.audioBuffer,startTime:Zi(m)-h,duration:Ef(m),offset:Sf(m),fadeIn:m.fadeIn,fadeOut:m.fadeOut,gain:m.gain}));t.addTrack({clips:y,track:b,effects:d.effects})}t.applyInitialSoloState(),t.setLoop(s,a,o),t.setOnPlaybackComplete(()=>{u===r&&(n=!1)})}return{async init(){t&&(await t.init(),i=!0)},setTracks(c){l(c)},play(c,u){if(!t){console.warn("[waveform-playlist] adapter.play() called but no playout is available. Tracks may not have been set, or the adapter was disposed.");return}const d=u!==void 0?u-c:void 0;t.play(j.now(),c,d),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,d){s=c,a=u,o=d,t?.setLoop(c,u,d)},dispose(){try{t?.dispose()}catch(c){console.warn("[waveform-playlist] Error disposing playout:",c)}t=null,n=!1}}}function Xl(e,t,n,r){let s=t;const a=-e.startSample;if(s=Math.max(s,a),r>0){const o=n[r-1],l=o.startSample+o.durationSamples-e.startSample;s=Math.max(s,l)}if(r<n.length-1){const i=n[r+1].startSample-(e.startSample+e.durationSamples);s=Math.min(s,i)}return s}function va(e,t,n,r,s,a){let o=t;if(n==="left"){if(o=Math.max(o,-e.startSample),o=Math.max(o,-e.offsetSamples),s>0){const i=r[s-1],l=i.startSample+i.durationSamples;o=Math.max(o,l-e.startSample)}o=Math.min(o,e.durationSamples-a)}else if(o=Math.max(o,a-e.durationSamples),o=Math.min(o,e.sourceDurationSamples-e.offsetSamples-e.durationSamples),s<r.length-1){const i=r[s+1];o=Math.min(o,i.startSample-e.startSample-e.durationSamples)}return o}function Wf(e,t){return Math.floor(e/t)*t}function Ff(e,t){const n=t-e.startSample,r=e.durationSamples-n,s=e.name?`${e.name} (1)`:void 0,a=e.name?`${e.name} (2)`:void 0,o=ma({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=ma({startSample:t,durationSamples:r,offsetSamples:e.offsetSamples+n,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:a,color:e.color,fadeOut:e.fadeOut,audioBuffer:e.audioBuffer,waveformData:e.waveformData});return{left:o,right:i}}function Gl(e,t,n){const r=e.startSample+e.durationSamples;if(t<=e.startSample||t>=r)return!1;const s=t-e.startSample,a=r-t;return s>=n&&a>=n}function Qs(e){let t=0;for(const n of e)for(const r of n.clips){const a=(r.startSample+r.durationSamples)/r.sampleRate;t=Math.max(t,a)}return t}function Yi(e,t){if(t.length===0)return 0;let n=0,r=Math.abs(t[0]-e);for(let s=1;s<t.length;s++){const a=Math.abs(t[s]-e);a<r&&(r=a,n=s)}return n}function Ui(e,t){return Math.max(0,Math.min(e,t))}var Of=44100,Bf=1e3,Vf=[256,512,1024,2048,4096,8192],Ki=.1,Lf=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??Of,this._zoomLevels=[...e.zoomLevels??Vf],this._adapter=e.adapter??null,this._zoomLevels.length===0)throw new Error("PlaylistEngine: zoomLevels must not be empty");const t=e.samplesPerPixel??Bf;this._zoomIndex=Yi(t,this._zoomLevels)}getState(){return{tracks:this._tracks.map(e=>({...e,clips:[...e.clips]})),tracksVersion:this._tracksVersion,duration:Qs(this._tracks),currentTime:this._currentTime,isPlaying:this._isPlaying,samplesPerPixel:this._zoomLevels[this._zoomIndex],sampleRate:this._sampleRate,selectedTrackId:this._selectedTrackId,zoomIndex:this._zoomIndex,canZoomIn:this._zoomIndex>0,canZoomOut:this._zoomIndex<this._zoomLevels.length-1,selectionStart:this._selectionStart,selectionEnd:this._selectionEnd,masterVolume:this._masterVolume,loopStart:this._loopStart,loopEnd:this._loopEnd,isLoopEnabled:this._isLoopEnabled}}setTracks(e){this._tracks=[...e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}addTrack(e){this._tracks=[...this._tracks,e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}removeTrack(e){this._tracks.some(t=>t.id===e)&&(this._tracks=this._tracks.filter(t=>t.id!==e),this._tracksVersion++,this._selectedTrackId===e&&(this._selectedTrackId=null),this._adapter?.setTracks(this._tracks),this._emitStateChange())}selectTrack(e){e!==this._selectedTrackId&&(this._selectedTrackId=e,this._emitStateChange())}moveClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] moveClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] moveClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=ji(r.clips),i=o.findIndex(c=>c.id===t),l=Xl(a,n,o,i);l!==0&&(this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=c.clips.map((d,p)=>p===s?{...d,startSample:Math.floor(d.startSample+l)}:d);return{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}splitClip(e,t,n){const r=this._tracks.find(c=>c.id===e);if(!r){console.warn(`[waveform-playlist/engine] splitClip: track "${e}" not found`);return}const s=r.clips.findIndex(c=>c.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] splitClip: clip "${t}" not found in track "${e}"`);return}const a=r.clips[s],o=Math.floor(Ki*this._sampleRate);if(!Gl(a,n,o)){console.warn(`[waveform-playlist/engine] splitClip: cannot split clip "${t}" at sample ${n} (clip range: ${a.startSample}–${a.startSample+a.durationSamples}, minDuration: ${o})`);return}const{left:i,right:l}=Ff(a,n);this._tracks=this._tracks.map(c=>{if(c.id!==e)return c;const u=[...c.clips];return u.splice(s,1,i,l),{...c,clips:u}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}trimClip(e,t,n,r){const s=this._tracks.find(d=>d.id===e);if(!s){console.warn(`[waveform-playlist/engine] trimClip: track "${e}" not found`);return}const a=s.clips.findIndex(d=>d.id===t);if(a===-1){console.warn(`[waveform-playlist/engine] trimClip: clip "${t}" not found in track "${e}"`);return}const o=s.clips[a],i=ji(s.clips),l=i.findIndex(d=>d.id===t),c=Math.floor(Ki*this._sampleRate),u=va(o,r,n,i,l,c);u!==0&&(this._tracks=this._tracks.map(d=>{if(d.id!==e)return d;const p=d.clips.map((h,g)=>g!==a?h:n==="left"?{...h,startSample:h.startSample+u,offsetSamples:h.offsetSamples+u,durationSamples:h.durationSamples-u}:{...h,durationSamples:h.durationSamples+u});return{...d,clips:p}}),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=Qs(this._tracks);this._currentTime=Ui(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=Qs(this._tracks);this._currentTime=Ui(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=Yi(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)}},zf=Symbol.for("preact-signals");function Rs(){if(Ut>1)Ut--;else{for(var e,t=!1;hr!==void 0;){var n=hr;for(hr=void 0,ya++;n!==void 0;){var r=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Ul(n))try{n.c()}catch(s){t||(e=s,t=!0)}n=r}}if(ya=0,Ut--,t)throw e}}function Kt(e){if(Ut>0)return e();Ut++;try{return e()}finally{Rs()}}var pe=void 0;function _e(e){var t=pe;pe=void 0;try{return e()}finally{pe=t}}var hr=void 0,Ut=0,ya=0,ms=0;function Yl(e){if(pe!==void 0){var t=e.n;if(t===void 0||t.t!==pe)return t={i:0,S:e,p:pe.s,n:void 0,t:pe,e:void 0,x:void 0,r:t},pe.s!==void 0&&(pe.s.n=t),pe.s=t,e.n=t,32&pe.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=pe.s,t.n=void 0,pe.s.n=t,pe.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=zf;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:_e(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&&_e(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=pe;pe=void 0;try{e(n)}finally{pe=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=pe;pe=void 0;try{return this.value}finally{pe=e}};Object.defineProperty(st.prototype,"value",{get:function(){var e=Yl(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(ya>100)throw new Error("Cycle detected");this.v=e,this.i++,ms++,Ut++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Rs()}}}});function Mr(e,t){return new st(e,t)}function Ul(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 Kl(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 ql(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 gn(e,t){st.call(this,void 0),this.x=e,this.s=void 0,this.g=ms-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}gn.prototype=new st;gn.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ms))return!0;if(this.g=ms,this.f|=1,this.i>0&&!Ul(this))return this.f&=-2,!0;var e=pe;try{Kl(this),pe=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 pe=e,ql(this),this.f&=-2,!0};gn.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)};gn.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)}};gn.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(gn.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Yl(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function qi(e,t){return new gn(e,t)}function Jl(e){var t=e.u;if(e.u=void 0,typeof t=="function"){Ut++;var n=pe;pe=void 0;try{t()}catch(r){throw e.f&=-2,e.f|=8,so(e),r}finally{pe=n,Rs()}}}function so(e){for(var t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,Jl(e)}function jf(e){if(pe!==this)throw new Error("Out-of-order effect");ql(this),pe=e,this.f&=-2,8&this.f&&so(this),Rs()}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,Jl(this),Kl(this),Ut++;var e=pe;return pe=this,jf.bind(this,e)};jn.prototype.N=function(){2&this.f||(this.f|=2,this.o=hr,hr=this)};jn.prototype.d=function(){this.f|=8,1&this.f||so(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 Zf=Object.create,ao=Object.defineProperty,Hf=Object.defineProperties,Nf=Object.getOwnPropertyDescriptor,Xf=Object.getOwnPropertyDescriptors,Ji=Object.getOwnPropertySymbols,Gf=Object.prototype.hasOwnProperty,Yf=Object.prototype.propertyIsEnumerable,Uf=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Zn=e=>{throw TypeError(e)},ba=(e,t,n)=>t in e?ao(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Kf=(e,t)=>{for(var n in t||(t={}))Gf.call(t,n)&&ba(e,n,t[n]);if(Ji)for(var n of Ji(t))Yf.call(t,n)&&ba(e,n,t[n]);return e},qf=(e,t)=>Hf(e,Xf(t)),Qi=(e,t)=>ao(e,"name",{value:t,configurable:!0}),Jf=e=>{var t;return[,,,Zf((t=void 0)!=null?t:null)]},Ql=["class","method","getter","setter","accessor","field","value","get","set"],nr=e=>e!==void 0&&typeof e!="function"?Zn("Function expected"):e,Qf=(e,t,n,r,s)=>({kind:Ql[e],name:t,metadata:r,addInitializer:a=>n._?Zn("Already initialized"):s.push(nr(a||null))}),ec=(e,t)=>ba(t,Uf("metadata"),e[3]),sn=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},Hn=(e,t,n,r,s,a)=>{var o,i,l,c,u,d=t&7,p=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?p?1:2:0,b=Ql[d+5],y=d>3&&(e[g-1]=[]),m=e[g]||(e[g]=[]),w=d&&(!h&&!p&&(s=s.prototype),d<5&&(d>3||!h)&&Nf(d<4?s:{get[n](){return fn(this,a)},set[n](v){return Xt(this,a,v)}},n));d?h&&d<4&&Qi(a,(d>2?"set ":d>1?"get ":"")+n):Qi(s,n);for(var _=r.length-1;_>=0;_--)c=Qf(d,n,l={},e[3],m),d&&(c.static=p,c.private=h,u=c.access={has:h?v=>eh(s,v):v=>n in v},d^3&&(u.get=h?v=>(d^1?fn:th)(v,s,d^4?a:w.get):v=>v[n]),d>2&&(u.set=h?(v,x)=>Xt(v,s,x,d^4?a:w.set):(v,x)=>v[n]=x)),i=(0,r[_])(d?d<4?h?a:w[b]:d>4?void 0:{get:w.get,set:w.set}:s,c),l._=1,d^4||i===void 0?nr(i)&&(d>4?y.unshift(i):d?h?a=i:w[b]=i:s=i):typeof i!="object"||i===null?Zn("Object expected"):(nr(o=i.get)&&(w.get=o),nr(o=i.set)&&(w.set=o),nr(o=i.init)&&y.unshift(o));return d||ec(e,s),w&&ao(s,n,w),h?d^4?a:w:s},oo=(e,t,n)=>t.has(e)||Zn("Cannot "+n),eh=(e,t)=>Object(t)!==t?Zn('Cannot use the "in" operator on this value'):e.has(t),fn=(e,t,n)=>(oo(e,t,"read from private field"),n?n.call(e):t.get(e)),Kr=(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),Xt=(e,t,n,r)=>(oo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),th=(e,t,n)=>(oo(e,t,"access private method"),n);function gs(e,t){if(t){let n;return qi(()=>{const r=e();return r&&n&&t(n,r)?n:(n=r,r)})}return qi(e)}function br(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)=>!br(r,t[s]));if(typeof e=="object"&&typeof t=="object"){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:!n.some(a=>!br(e[a],t[a]))}return!1}function ue({get:e},t){return{init(n){return Mr(n)},get(){return e.call(this).value},set(n){const r=e.call(this);r.peek()!==n&&(r.value=n)}}}function Ae(e,t){const n=new WeakMap;return function(){let r=n.get(this);return r||(r=gs(e.bind(this)),n.set(this,r)),r.value}}function ea(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,qf(Kf({},s),{enumerable:e}))})}}function $r(...e){const t=e.map(n=>Ct(n));return()=>t.forEach(n=>n())}var tc,nc,rc,sc,ac,oc,tt,io,ta,wa,_a,qe,lo,na,ic,xa,co,ra,Ca,ka;oc=[ue],ac=[ue],sc=[ue],rc=[ea()],nc=[ea()],tc=[ea()];var Jt=class{constructor(e,t=Object.is){this.defaultValue=e,this.equals=t,sn(tt,5,this),Kr(this,qe),Kr(this,io,sn(tt,8,this)),sn(tt,11,this),Kr(this,lo,sn(tt,12,this)),sn(tt,15,this),Kr(this,co,sn(tt,16,this)),sn(tt,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return fn(this,qe,Ca)}get initial(){return fn(this,qe,wa)}get previous(){return fn(this,qe,ic)}set current(e){const t=_e(()=>fn(this,qe,Ca));e&&t&&this.equals(t,e)||Kt(()=>{fn(this,qe,wa)||Xt(this,qe,e,_a),Xt(this,qe,t,xa),Xt(this,qe,e,ka)})}reset(e=this.defaultValue){Kt(()=>{Xt(this,qe,void 0,xa),Xt(this,qe,e,_a),Xt(this,qe,e,ka)})}};tt=Jf();io=new WeakMap;qe=new WeakSet;lo=new WeakMap;co=new WeakMap;ta=Hn(tt,20,"#initial",oc,qe,io),wa=ta.get,_a=ta.set;na=Hn(tt,20,"#previous",ac,qe,lo),ic=na.get,xa=na.set;ra=Hn(tt,20,"#current",sc,qe,co),Ca=ra.get,ka=ra.set;Hn(tt,2,"current",rc,Jt);Hn(tt,2,"initial",nc,Jt);Hn(tt,2,"previous",tc,Jt);ec(tt,Jt);function sa(e){return _e(()=>{const t={};for(const n in e)t[n]=e[n];return t})}var nh=Object.create,lc=Object.defineProperty,rh=Object.getOwnPropertyDescriptor,el=Object.getOwnPropertySymbols,sh=Object.prototype.hasOwnProperty,ah=Object.prototype.propertyIsEnumerable,cc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ps=e=>{throw TypeError(e)},tl=Math.pow,Sa=(e,t,n)=>t in e?lc(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,oh=(e,t)=>{for(var n in t||(t={}))sh.call(t,n)&&Sa(e,n,t[n]);if(el)for(var n of el(t))ah.call(t,n)&&Sa(e,n,t[n]);return e},ih=e=>{var t;return[,,,nh((t=e?.[cc("metadata")])!=null?t:null)]},uc=["class","method","getter","setter","accessor","field","value","get","set"],dc=e=>e!==void 0&&typeof e!="function"?Ps("Function expected"):e,lh=(e,t,n,r,s)=>({kind:uc[e],name:t,metadata:r,addInitializer:a=>n._?Ps("Already initialized"):s.push(dc(a||null))}),ch=(e,t)=>Sa(t,cc("metadata"),e[3]),uh=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)a[s].call(n);return r},fc=(e,t,n,r,s,a)=>{for(var o,i,l,c,u=t&7,d=!1,p=!1,h=2,g=uc[u+5],b=e[h]||(e[h]=[]),y=(s=s.prototype,rh(s,n)),m=r.length-1;m>=0;m--)l=lh(u,n,i={},e[3],b),l.static=d,l.private=p,c=l.access={has:w=>n in w},c.get=w=>w[n],o=(0,r[m])(y[g],l),i._=1,dc(o)&&(y[g]=o);return y&&lc(s,n,y),s},hc=(e,t,n)=>t.has(e)||Ps("Cannot "+n),dh=(e,t,n)=>(hc(e,t,"read from private field"),t.get(e)),fh=(e,t,n)=>t.has(e)?Ps("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),hh=(e,t,n,r)=>(hc(e,t,"write to private field"),t.set(e,n),n),Tt=class Ea{constructor(t,n){this.x=t,this.y=n}static delta(t,n){return new Ea(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 Ea(t,n)}},Tr=class on{constructor(t,n,r,s){this.left=t,this.top=n,this.width=r,this.height=s,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(t,n){const{top:r,left:s,width:a,height:o,scale:i}=this,l=new on(s+t,r+n,a,o);return l.scale=oh({},i),l}get boundingRectangle(){const{width:t,height:n,left:r,top:s,right:a,bottom:o}=this;return{width:t,height:n,left:r,top:s,right:a,bottom:o}}get center(){const{left:t,top:n,right:r,bottom:s}=this;return new Tt((t+r)/2,(n+s)/2)}get area(){const{width:t,height:n}=this;return t*n}equals(t){if(!(t instanceof on))return!1;const{left:n,top:r,width:s,height:a}=this;return n===t.left&&r===t.top&&s===t.width&&a===t.height}containsPoint(t){const{top:n,left:r,bottom:s,right:a}=this;return n<=t.y&&t.y<=s&&r<=t.x&&t.x<=a}intersectionArea(t){return t instanceof on?ph(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 on(n,t,r,s)}static delta(t,n,r={x:"center",y:"center"}){const s=(a,o)=>{const i=r[o],l=o==="x"?a.left:a.top,c=o==="x"?a.width:a.height;return i=="start"?l:i=="end"?l+c:l+c/2};return Tt.delta({x:s(t,"x"),y:s(t,"y")},{x:s(n,"x"),y:s(n,"y")})}static intersectionRatio(t,n){return on.from(t).intersectionRatio(on.from(n))}};function ph(e,t){const n=Math.max(t.top,e.top),r=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),a=Math.min(t.top+t.height,e.top+e.height),o=s-r,i=a-n;return r<s&&n<a?o*i:0}var pc,mc,Ia,rs,Dr,Ws=class extends(Ia=Jt,mc=[Ae],pc=[Ae],Ia){constructor(t){const n=Tt.from(t);super(n,(r,s)=>Tt.equals(r,s)),uh(Dr,5,this),fh(this,rs,0),this.velocity={x:0,y:0}}get delta(){return Tt.delta(this.current,this.initial)}get direction(){const{current:t,previous:n}=this;if(!n)return null;const r={x:t.x-n.x,y:t.y-n.y};return!r.x&&!r.y?null:Math.abs(r.x)>Math.abs(r.y)?r.x>0?"right":"left":r.y>0?"down":"up"}get current(){return super.current}set current(t){const{current:n}=this,r=Tt.from(t),s={x:r.x-n.x,y:r.y-n.y},a=Date.now(),o=a-dh(this,rs),i=l=>Math.round(l/o*100);Kt(()=>{hh(this,rs,a),this.velocity={x:i(s.x),y:i(s.y)},super.current=r})}reset(t=this.defaultValue){super.reset(Tt.from(t)),this.velocity={x:0,y:0}}};Dr=ih(Ia);rs=new WeakMap;fc(Dr,2,"delta",mc,Ws);fc(Dr,2,"direction",pc,Ws);ch(Dr,Ws);function Aa({x:e,y:t},n){const r=Math.abs(e),s=Math.abs(t);return typeof n=="number"?Math.sqrt(tl(r,2)+tl(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 gc=(e=>(e.Horizontal="x",e.Vertical="y",e))(gc||{}),vc=Object.values(gc),mh=Object.create,uo=Object.defineProperty,gh=Object.defineProperties,vh=Object.getOwnPropertyDescriptor,yh=Object.getOwnPropertyDescriptors,vs=Object.getOwnPropertySymbols,yc=Object.prototype.hasOwnProperty,bc=Object.prototype.propertyIsEnumerable,wc=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Nn=e=>{throw TypeError(e)},Ma=(e,t,n)=>t in e?uo(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_c=(e,t)=>{for(var n in t||(t={}))yc.call(t,n)&&Ma(e,n,t[n]);if(vs)for(var n of vs(t))bc.call(t,n)&&Ma(e,n,t[n]);return e},xc=(e,t)=>gh(e,yh(t)),nl=(e,t)=>uo(e,"name",{value:t,configurable:!0}),Cc=(e,t)=>{var n={};for(var r in e)yc.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&vs)for(var r of vs(e))t.indexOf(r)<0&&bc.call(e,r)&&(n[r]=e[r]);return n},Xn=e=>{var t;return[,,,mh((t=e?.[wc("metadata")])!=null?t:null)]},kc=["class","method","getter","setter","accessor","field","value","get","set"],rr=e=>e!==void 0&&typeof e!="function"?Nn("Function expected"):e,bh=(e,t,n,r,s)=>({kind:kc[e],name:t,metadata:r,addInitializer:a=>n._?Nn("Already initialized"):s.push(rr(a||null))}),vn=(e,t)=>Ma(t,wc("metadata"),e[3]),J=(e,t,n,r)=>{for(var s=0,a=e[t>>1],o=a&&a.length;s<o;s++)t&1?a[s].call(n):r=a[s].call(n,r);return r},ce=(e,t,n,r,s,a)=>{var o,i,l,c,u,d=t&7,p=!!(t&8),h=!!(t&16),g=d>3?e.length+1:d?p?1:2:0,b=kc[d+5],y=d>3&&(e[g-1]=[]),m=e[g]||(e[g]=[]),w=d&&(!h&&!p&&(s=s.prototype),d<5&&(d>3||!h)&&vh(d<4?s:{get[n](){return He(this,a)},set[n](v){return wt(this,a,v)}},n));d?h&&d<4&&nl(a,(d>2?"set ":d>1?"get ":"")+n):nl(s,n);for(var _=r.length-1;_>=0;_--)c=bh(d,n,l={},e[3],m),d&&(c.static=p,c.private=h,u=c.access={has:h?v=>wh(s,v):v=>n in v},d^3&&(u.get=h?v=>(d^1?He:_h)(v,s,d^4?a:w.get):v=>v[n]),d>2&&(u.set=h?(v,x)=>wt(v,s,x,d^4?a:w.set):(v,x)=>v[n]=x)),i=(0,r[_])(d?d<4?h?a:w[b]:d>4?void 0:{get:w.get,set:w.set}:s,c),l._=1,d^4||i===void 0?rr(i)&&(d>4?y.unshift(i):d?h?a=i:w[b]=i:s=i):typeof i!="object"||i===null?Nn("Object expected"):(rr(o=i.get)&&(w.get=o),rr(o=i.set)&&(w.set=o),rr(o=i.init)&&y.unshift(o));return d||vn(e,s),w&&uo(s,n,w),h?d^4?a:w:s},fo=(e,t,n)=>t.has(e)||Nn("Cannot "+n),wh=(e,t)=>Object(t)!==t?Nn('Cannot use the "in" operator on this value'):e.has(t),He=(e,t,n)=>(fo(e,t,"read from private field"),n?n.call(e):t.get(e)),we=(e,t,n)=>t.has(e)?Nn("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),wt=(e,t,n,r)=>(fo(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),_h=(e,t,n)=>(fo(e,t,"access private method"),n);function Sc(e,t){return{plugin:e,options:t}}function Gn(e){return t=>Sc(e,t)}function ho(e){return typeof e=="function"?{plugin:e,options:void 0}:e}var Ec,wr,po,ss;Ec=[ue];var lt=class{constructor(e,t){this.manager=e,this.options=t,we(this,po,J(wr,8,this,!1)),J(wr,11,this),we(this,ss,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return _e(()=>this.disabled)}configure(e){this.options=e}registerEffect(e){const t=Ct(e.bind(this));return He(this,ss).add(t),t}destroy(){He(this,ss).forEach(e=>e())}static configure(e){return Sc(this,e)}};wr=Xn(null);po=new WeakMap;ss=new WeakMap;ce(wr,4,"disabled",Ec,lt,po);vn(wr,lt);var Rr=class extends lt{},as,aa=class{constructor(e){this.manager=e,this.instances=new Map,we(this,as,[])}get values(){return Array.from(this.instances.values())}set values(e){const t=e.map(ho).reduceRight((r,s)=>r.some(({plugin:a})=>a===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 Rr)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 xh(e,t){return e.priority===t.priority?e.type===t.type?t.value-e.value:t.type-e.type:t.priority-e.priority}var qr=[],Mn,$n,Ch=class extends lt{constructor(e){super(e),we(this,Mn),we(this,$n),this.computeCollisions=this.computeCollisions.bind(this),wt(this,$n,Mr(qr)),this.destroy=$r(()=>{const t=this.computeCollisions(),n=_e(()=>this.manager.dragOperation.position.current);if(t!==qr){const r=He(this,Mn);if(wt(this,Mn,n),r&&n.x==r.x&&n.y==r.y)return}else wt(this,Mn,void 0);He(this,$n).value=t},()=>{const{dragOperation:t}=this.manager;t.status.initialized&&this.forceUpdate()})}forceUpdate(e=!0){_e(()=>{e?He(this,$n).value=this.computeCollisions():wt(this,Mn,void 0)})}computeCollisions(e,t){const{registry:n,dragOperation:r}=this.manager,{source:s,shape:a,status:o}=r;if(!o.initialized||!a)return qr;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 d=_e(()=>u({droppable:c,dragOperation:r}));d&&(c.collisionPriority!=null&&(d.priority=c.collisionPriority),i.push(d))}return l.length===0?qr:(i.sort(xh),i)}get collisions(){return He(this,$n).value}};Mn=new WeakMap;$n=new WeakMap;var kh=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)}},Sh=class extends kh{constructor(e){super(),this.manager=e}dispatch(e,t){const n=[t,this.manager];super.dispatch(e,...n)}};function os(e,t=!0){let n=!1;return xc(_c({},e),{cancelable:t,get defaultPrevented(){return n},preventDefault(){t&&(n=!0)}})}var Eh=class extends Rr{constructor(e){super(e);const t=(r,s)=>r.map(({id:a})=>a).join("")===s.map(({id:a})=>a).join("");let n=[];this.destroy=$r(()=>{const{dragOperation:r,collisionObserver:s}=e;r.status.initializing&&(n=[],s.enable())},()=>{const{collisionObserver:r,monitor:s}=e,{collisions:a}=r;if(r.isDisabled())return;const o=os({collisions:a});if(s.dispatch("collision",o),o.defaultPrevented||t(a,n))return;n=a;const[i]=a;_e(()=>{var l;i?.id!==((l=e.dragOperation.target)==null?void 0:l.id)&&(r.disable(),e.actions.setDropTarget(i?.id).then(()=>{r.enable()}))})})}},mo=(e=>(e[e.Lowest=0]="Lowest",e[e.Low=1]="Low",e[e.Normal=2]="Normal",e[e.High=3]="High",e[e.Highest=4]="Highest",e))(mo||{}),go=(e=>(e[e.Collision=0]="Collision",e[e.ShapeIntersection=1]="ShapeIntersection",e[e.PointerIntersection=2]="PointerIntersection",e))(go||{}),Ic,Ac,Mc,$c,Tc,Dc,Rc,xt,vo;Rc=[ue],Dc=[Ae],Tc=[Ae],$c=[Ae],Mc=[Ae],Ac=[Ae],Ic=[Ae];var zt=class{constructor(){J(xt,5,this),we(this,vo,J(xt,8,this,"idle")),J(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=Xn(null);vo=new WeakMap;ce(xt,4,"value",Rc,zt,vo);ce(xt,2,"current",Dc,zt);ce(xt,2,"idle",Tc,zt);ce(xt,2,"initializing",$c,zt);ce(xt,2,"initialized",Mc,zt);ce(xt,2,"dragging",Ac,zt);ce(xt,2,"dropped",Ic,zt);vn(xt,zt);var Ih=class{constructor(e){this.manager=e}setDragSource(e){const{dragOperation:t}=this.manager;t.sourceIdentifier=typeof e=="string"||typeof e=="number"?e:e.id}setDropTarget(e){return _e(()=>{const{dragOperation:t}=this.manager,n=e??null;if(t.targetIdentifier===n)return Promise.resolve(!1);t.targetIdentifier=n;const r=os({operation:t.snapshot()});return t.status.dragging&&this.manager.monitor.dispatch("dragover",r),this.manager.renderer.rendering.then(()=>r.defaultPrevented)})}start(e){return _e(()=>{const{dragOperation:t}=this.manager;if(e.source!=null&&this.setDragSource(e.source),!t.source)throw new Error("Cannot start a drag operation without a drag source");if(!t.status.idle)throw new Error("Cannot start a drag operation while another is active");const r=new AbortController,{event:s,coordinates:a}=e;Kt(()=>{t.status.set("initialization-pending"),t.shape=null,t.canceled=!1,t.activatorEvent=s??null,t.position.reset(a)});const o=os({operation:t.snapshot()});return this.manager.monitor.dispatch("beforedragstart",o),o.defaultPrevented?(t.reset(),r.abort(),r):(t.status.set("initializing"),t.controller=r,this.manager.renderer.rendering.then(()=>{if(r.signal.aborted)return;const{status:i}=t;i.current==="initializing"&&(t.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:s,operation:t.snapshot(),cancelable:!1}))}),r)})}move(e){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{status:s,controller:a}=r;if(!s.dragging||!a||a.signal.aborted)return;const o=os({nativeEvent:e.event,operation:r.snapshot(),by:e.by,to:e.to},(t=e.cancelable)!=null?t:!0);((n=e.propagate)==null||n)&&this.manager.monitor.dispatch("dragmove",o),queueMicrotask(()=>{var i,l,c,u,d;if(o.defaultPrevented)return;const p=(d=e.to)!=null?d:{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=p})})}stop(e={}){return _e(()=>{var t,n;const{dragOperation:r}=this.manager,{controller:s}=r;if(!s||s.signal.aborted)return;let a;const o=()=>{const l={resume:()=>{},abort:()=>{}};return a=new Promise((c,u)=>{l.resume=c,l.abort=u}),l};s.abort();const i=()=>{this.manager.renderer.rendering.then(()=>{r.status.set("dropped");const l=_e(()=>{var u;return((u=r.source)==null?void 0:u.status)==="dropping"}),c=()=>{r.controller===s&&(r.controller=void 0),r.reset()};if(l){const{source:u}=r,d=Ct(()=>{u?.status==="idle"&&(d(),c())})}else this.manager.renderer.rendering.then(c)})};r.canceled=(t=e.canceled)!=null?t:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:e.event,operation:r.snapshot(),canceled:(n=e.canceled)!=null?n:!1,suspend:o}),a?a.then(i).catch(()=>r.reset()):i()})}},Pc,Wc,Fc,Oc,it,yo,bo,wo,_o;Oc=[ue],Fc=[ue],Wc=[ue],Pc=[ue];var Qt=class{constructor(e,t){we(this,yo,J(it,8,this)),J(it,11,this),we(this,bo,J(it,12,this)),J(it,15,this),we(this,wo,J(it,16,this)),J(it,19,this),we(this,_o,J(it,20,this)),J(it,23,this);const{effects:n,id:r,data:s={},disabled:a=!1,register:o=!0}=e;let i=r;this.manager=t,this.id=r,this.data=s,this.disabled=a,this.effects=()=>{var l;return[()=>{const{id:c,manager:u}=this;if(c!==i)return u?.registry.register(this),()=>u?.registry.unregister(this)},...(l=n?.())!=null?l:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),t&&o&&queueMicrotask(this.register)}register(){var e;return(e=this.manager)==null?void 0:e.registry.register(this)}unregister(){var e;(e=this.manager)==null||e.registry.unregister(this)}destroy(){var e;(e=this.manager)==null||e.registry.unregister(this)}};it=Xn(null);yo=new WeakMap;bo=new WeakMap;wo=new WeakMap;_o=new WeakMap;ce(it,4,"manager",Oc,Qt,yo);ce(it,4,"id",Fc,Qt,bo);ce(it,4,"data",Wc,Qt,wo);ce(it,4,"disabled",Pc,Qt,_o);vn(it,Qt);var rl=class{constructor(){this.map=Mr(new Map),this.cleanupFunctions=new WeakMap,this.register=(e,t)=>{const n=this.map.peek(),r=n.get(e),s=()=>this.unregister(e,t);if(r===t)return s;if(r){const i=this.cleanupFunctions.get(r);i?.(),this.cleanupFunctions.delete(r)}const a=new Map(n);a.set(e,t),this.map.value=a;const o=$r(...t.effects());return this.cleanupFunctions.set(t,o),s},this.unregister=(e,t)=>{const n=this.map.peek();if(n.get(e)!==t)return;const r=this.cleanupFunctions.get(t);r?.(),this.cleanupFunctions.delete(t);const s=new Map(n);s.delete(e),this.map.value=s}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(e){return this.map.value.has(e)}get(e){return this.map.value.get(e)}destroy(){for(const e of this){const t=this.cleanupFunctions.get(e);t?.(),e.destroy()}this.map.value=new Map}},Bc,Vc,Lc,zc,jc,Zc,$a,nt,xo,Co,ko,Dt=class extends($a=Qt,Zc=[ue],jc=[ue],zc=[ue],Lc=[Ae],Vc=[Ae],Bc=[Ae],$a){constructor(t,n){var r=t,{modifiers:s,type:a,sensors:o}=r,i=Cc(r,["modifiers","type","sensors"]);super(i,n),J(nt,5,this),we(this,xo,J(nt,8,this)),J(nt,11,this),we(this,Co,J(nt,12,this)),J(nt,15,this),we(this,ko,J(nt,16,this,this.isDragSource?"dragging":"idle")),J(nt,19,this),this.type=a,this.sensors=o,this.modifiers=s,this.alignment=i.alignment}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.source)==null?void 0:n.id)===this.id}};nt=Xn($a);xo=new WeakMap;Co=new WeakMap;ko=new WeakMap;ce(nt,4,"type",Zc,Dt,xo);ce(nt,4,"modifiers",jc,Dt,Co);ce(nt,4,"status",zc,Dt,ko);ce(nt,2,"isDropping",Lc,Dt);ce(nt,2,"isDragging",Vc,Dt);ce(nt,2,"isDragSource",Bc,Dt);vn(nt,Dt);var Hc,Nc,Xc,Gc,Yc,Uc,Ta,Ve,So,Eo,Io,Ao,Mo,Rt=class extends(Ta=Qt,Uc=[ue],Yc=[ue],Gc=[ue],Xc=[ue],Nc=[ue],Hc=[Ae],Ta){constructor(t,n){var r=t,{accept:s,collisionDetector:a,collisionPriority:o,type:i}=r,l=Cc(r,["accept","collisionDetector","collisionPriority","type"]);super(l,n),J(Ve,5,this),we(this,So,J(Ve,8,this)),J(Ve,11,this),we(this,Eo,J(Ve,12,this)),J(Ve,15,this),we(this,Io,J(Ve,16,this)),J(Ve,19,this),we(this,Ao,J(Ve,20,this)),J(Ve,23,this),we(this,Mo,J(Ve,24,this)),J(Ve,27,this),this.accept=s,this.collisionDetector=a,this.collisionPriority=o,this.type=i}accepts(t){const{accept:n}=this;return n?typeof n=="function"?n(t):t.type?Array.isArray(n)?n.includes(t.type):t.type===n:!1:!0}get isDropTarget(){var t,n;return((n=(t=this.manager)==null?void 0:t.dragOperation.target)==null?void 0:n.id)===this.id}};Ve=Xn(Ta);So=new WeakMap;Eo=new WeakMap;Io=new WeakMap;Ao=new WeakMap;Mo=new WeakMap;ce(Ve,4,"accept",Uc,Rt,So);ce(Ve,4,"type",Yc,Rt,Eo);ce(Ve,4,"collisionDetector",Gc,Rt,Io);ce(Ve,4,"collisionPriority",Xc,Rt,Ao);ce(Ve,4,"shape",Nc,Rt,Mo);ce(Ve,2,"isDropTarget",Hc,Rt);vn(Ve,Rt);var On=class extends lt{constructor(e,t){super(e,t),this.manager=e,this.options=t}},Ah=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)}},is,Kc=class{constructor(e){this.options=e,we(this,is)}set controller(e){wt(this,is,e),e.signal.addEventListener("abort",()=>this.abort())}activate(e){var t;(t=He(this,is))==null||t.activate(e)}};is=new WeakMap;var _r=class extends lt{constructor(e,t){super(e,t),this.manager=e,this.options=t}apply(e){return e.transform}},Mh=class{constructor(e){this.draggables=new rl,this.droppables=new rl,this.plugins=new aa(e),this.sensors=new aa(e),this.modifiers=new aa(e)}register(e,t){if(e instanceof Dt)return this.draggables.register(e.id,e);if(e instanceof Rt)return this.droppables.register(e.id,e);if(e.prototype instanceof _r)return this.modifiers.register(e,t);if(e.prototype instanceof On)return this.sensors.register(e,t);if(e.prototype instanceof lt)return this.plugins.register(e,t);throw new Error("Invalid instance type")}unregister(e){if(e instanceof Qt)return e instanceof Dt?this.draggables.unregister(e.id,e):e instanceof Rt?this.droppables.unregister(e.id,e):()=>{};if(e.prototype instanceof _r)return this.modifiers.unregister(e);if(e.prototype instanceof On)return this.sensors.unregister(e);if(e.prototype instanceof lt)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()}},qc,Jc,Qc,eu,tu,nu,ru,su,au,sr,ls,Tn,Me,$o,To,Do,Ro,Po,ar;au=[Ae],su=[ue],ru=[ue],nu=[ue],tu=[ue],eu=[ue],Qc=[Ae],Jc=[Ae],qc=[Ae];var It=class{constructor(e){J(Me,5,this),we(this,sr),we(this,ls),we(this,Tn,new Jt(void 0,(t,n)=>t&&n?t.equals(n):t===n)),this.status=new zt,we(this,$o,J(Me,8,this,!1)),J(Me,11,this),we(this,To,J(Me,12,this,null)),J(Me,15,this),we(this,Do,J(Me,16,this,null)),J(Me,19,this),we(this,Ro,J(Me,20,this,null)),J(Me,23,this),we(this,Po,J(Me,24,this,[])),J(Me,27,this),this.position=new Ws({x:0,y:0}),we(this,ar,{x:0,y:0}),wt(this,sr,e)}get shape(){const{current:e,initial:t,previous:n}=He(this,Tn);return!e||!t?null:{current:e,initial:t,previous:n}}set shape(e){e?He(this,Tn).current=e:He(this,Tn).reset()}get source(){var e;const t=this.sourceIdentifier;if(t==null)return null;const n=He(this,sr).registry.draggables.get(t);return n&&wt(this,ls,n),(e=n??He(this,ls))!=null?e:null}get target(){var e;const t=this.targetIdentifier;return t!=null&&(e=He(this,sr).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(xc(_c({},this.snapshot()),{transform:n}));return wt(this,ar,n),n}snapshot(){return _e(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:He(this,ar),shape:this.shape?sa(this.shape):null,position:sa(this.position),status:sa(this.status),canceled:this.canceled}))}reset(){Kt(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,He(this,Tn).reset(),this.position.reset({x:0,y:0}),wt(this,ar,{x:0,y:0}),this.modifiers=[]})}};Me=Xn(null);sr=new WeakMap;ls=new WeakMap;Tn=new WeakMap;$o=new WeakMap;To=new WeakMap;Do=new WeakMap;Ro=new WeakMap;Po=new WeakMap;ar=new WeakMap;ce(Me,2,"shape",au,It);ce(Me,4,"canceled",su,It,$o);ce(Me,4,"activatorEvent",ru,It,To);ce(Me,4,"sourceIdentifier",nu,It,Do);ce(Me,4,"targetIdentifier",tu,It,Ro);ce(Me,4,"modifiers",eu,It,Po);ce(Me,2,"source",Qc,It);ce(Me,2,"target",Jc,It);ce(Me,2,"transform",qc,It);vn(Me,It);var $h={get rendering(){return Promise.resolve()}};function Bt(e,t){return typeof e=="function"?e(t):e??t}var Th=class{constructor(t){this.destroy=()=>{this.dragOperation.status.idle||this.actions.stop({canceled:!0}),this.dragOperation.modifiers.forEach(p=>p.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var n;const r=t??{},s=Bt(r.plugins,[]),a=Bt(r.sensors,[]),o=Bt(r.modifiers,[]),i=(n=r.renderer)!=null?n:$h,l=new Sh(this),c=new Mh(this);this.registry=c,this.monitor=l,this.renderer=i,this.actions=new Ih(this),this.dragOperation=new It(this),this.collisionObserver=new Ch(this),this.plugins=[Eh,...s],this.modifiers=o,this.sensors=a;const{destroy:u}=this,d=$r(()=>{var p,h,g;const b=_e(()=>this.dragOperation.modifiers),y=this.modifiers;for(const m of b)y.includes(m)||m.destroy();this.dragOperation.modifiers=(g=(h=(p=this.dragOperation.source)==null?void 0:p.modifiers)==null?void 0:h.map(m=>{const{plugin:w,options:_}=ho(m);return new w(this,_)}))!=null?g:y});this.destroy=()=>{d(),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}},ou=e=>{throw TypeError(e)},Wo=(e,t,n)=>t.has(e)||ou("Cannot "+n),te=(e,t,n)=>(Wo(e,t,"read from private field"),t.get(e)),ot=(e,t,n)=>t.has(e)?ou("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),pt=(e,t,n,r)=>(Wo(e,t,"write to private field"),t.set(e,n),n),iu=(e,t,n)=>(Wo(e,t,"access private method"),n);function Fs(e){return e?e instanceof KeyframeEffect?!0:"getKeyframes"in e&&typeof e.getKeyframes=="function":!1}function Dh(e,t){const n=e.getAnimations();if(n.length>0)for(const r of n){if(r.playState!=="running")continue;const{effect:s}=r,o=(Fs(s)?s.getKeyframes():[]).filter(t);if(o.length>0)return[o[o.length-1],r]}return null}function Os(e){const{width:t,height:n,top:r,left:s,bottom:a,right:o}=e.getBoundingClientRect();return{width:t,height:n,top:r,left:s,bottom:a,right:o}}function Fo(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Pr(e){return"nodeType"in e}function kt(e){var t,n,r;return e?Fo(e)?e:Pr(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 Oo(e){const{Document:t}=kt(e);return e instanceof t||"nodeType"in e&&e.nodeType===Node.DOCUMENT_NODE}function hn(e){return!e||Fo(e)?!1:e instanceof kt(e).HTMLElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("html")}function lu(e){return e instanceof kt(e).SVGElement||"namespaceURI"in e&&typeof e.namespaceURI=="string"&&e.namespaceURI.endsWith("svg")}function yn(e){return e?Fo(e)?e.document:Pr(e)?Oo(e)?e:hn(e)||lu(e)?e.ownerDocument:document:document:document}function Rh(e){var t,n,r,s;const{documentElement:a}=yn(e),o=kt(e).visualViewport,i=(t=o?.width)!=null?t:a.clientWidth,l=(n=o?.height)!=null?n:a.clientHeight,c=(r=o?.offsetTop)!=null?r:0,u=(s=o?.offsetLeft)!=null?s:0;return{top:c,left:u,right:u+i,bottom:c+l,width:i,height:l}}function Ph(e,t){if(Wh(e)&&e.open===!1)return!1;const{overflow:n,overflowX:r,overflowY:s}=getComputedStyle(e);return n==="visible"&&r==="visible"&&s==="visible"}function Wh(e){return e.tagName==="DETAILS"}function ys(e,t=e.getBoundingClientRect(),n=0){var r,s,a,o,i;let l=t;const{ownerDocument:c}=e,u=(r=c.defaultView)!=null?r:window;let d=e.parentElement;for(;d&&d!==c.documentElement;){if(!Ph(d)){const _=d.getBoundingClientRect(),v=n*(_.bottom-_.top),x=n*(_.right-_.left),k=n*(_.bottom-_.top),S=n*(_.right-_.left);l={top:Math.max(l.top,_.top-v),right:Math.min(l.right,_.right+x),bottom:Math.min(l.bottom,_.bottom+k),left:Math.max(l.left,_.left-S),width:0,height:0},l.width=l.right-l.left,l.height=l.bottom-l.top}d=d.parentElement}const p=u.visualViewport,h=(s=p?.offsetTop)!=null?s:0,g=(a=p?.offsetLeft)!=null?a:0,b=(o=p?.width)!=null?o:u.innerWidth,y=(i=p?.height)!=null?i:u.innerHeight,m=n*y,w=n*b;return l={top:Math.max(l.top,h-m),right:Math.min(l.right,g+b+w),bottom:Math.min(l.bottom,h+y+m),left:Math.max(l.left,g-w),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 cu=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Da(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(...Da(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(...Da(s.document,t))}}catch{}return n}function Bo(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function uu(){var e,t;const n=Bo()?window.visualViewport:null;return{x:(e=n?.offsetLeft)!=null?e:0,y:(t=n?.offsetTop)!=null?t:0}}function Vo(e){return!e||!Pr(e)?!1:e instanceof kt(e).ShadowRoot}function bs(e){if(e&&Pr(e)){let t=e.getRootNode();if(Vo(t))return t;if(t instanceof Document)return t}return yn(e)}function du(e){return e.matchMedia("(prefers-reduced-motion: reduce)").matches}function Fh(e){const t="input, textarea, select, canvas, [contenteditable]",n=e.cloneNode(!0),r=Array.from(e.querySelectorAll(t));return Array.from(n.querySelectorAll(t)).forEach((a,o)=>{const i=r[o];if(sl(a)&&sl(i)&&(a.type!=="file"&&(a.value=i.value),a.type==="radio"&&a.name&&(a.name=`Cloned__${a.name}`)),al(a)&&al(i)&&i.width>0&&i.height>0){const l=a.getContext("2d");l?.drawImage(i,0,0)}}),n}function sl(e){return"value"in e}function al(e){return e.tagName==="CANVAS"}function fu(e,{x:t,y:n}){const r=e.elementFromPoint(t,n);if(Oh(r)){const{contentDocument:s}=r;if(s){const{left:a,top:o}=r.getBoundingClientRect();return fu(s,{x:t-a,y:n-o})}}return r}function Oh(e){return e?.tagName==="IFRAME"}var ol=new WeakMap;function Bh(e){return!!e.closest(`
2
2
  input:not([disabled]),
3
3
  select:not([disabled]),
4
4
  textarea:not([disabled]),