@waveform-playlist/browser 7.1.1 → 7.1.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,10 +1,10 @@
1
- "use strict";var Za=Object.create;var yn=Object.defineProperty;var Va=Object.getOwnPropertyDescriptor;var ja=Object.getOwnPropertyNames;var La=Object.getPrototypeOf,za=Object.prototype.hasOwnProperty;var Ha=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ja(t))!za.call(e,r)&&r!==n&&yn(e,r,{get:()=>t[r],enumerable:!(a=Va(t,r))||a.enumerable});return e};var Xa=(e,t,n)=>(n=e!=null?Za(La(e)):{},Ha(t||!e||!e.__esModule?yn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("tone"),g=require("react/jsx-runtime"),s=require("react"),D=require("styled-components"),Ge=require("@dnd-kit/core"),Vn=require("react-dom"),Oa=require("@dnd-kit/modifiers");function jn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Ln=jn(j),T=jn(s);var Cn=!1;function Tt(e){const t=e._param;return!t&&!Cn&&(Cn=!0,console.warn("[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Fades and mute scheduling may not work correctly.")),t}function wn(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const o=r/a;n[r]=t?o:1-o}return n}function Na(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const o=r/a,i=t?r:e-1-r;n[i]=Math.exp(2*o-1)/Math.E}return n}function Ga(e,t){const n=new Float32Array(e),a=t?Math.PI/2:-Math.PI/2;for(let r=0;r<e;r++)n[r]=Math.sin(Math.PI*r/e-a)/2+.5;return n}function Ya(e,t,n=10){const a=new Float32Array(e);for(let r=0;r<e;r++){const o=t?r:e-1-r,i=r/e;a[o]=Math.log(1+n*i)/Math.log(1+n)}return a}function zn(e,t,n){switch(e){case"linear":return wn(t,n);case"exponential":return Na(t,n);case"sCurve":return Ga(t,n);case"logarithmic":return Ya(t,n);default:return wn(t,n)}}function xn(e,t,n,a="linear",r=0,o=1){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(o,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(o,.001),t+n);else{const i=zn(a,1e4,!0),l=new Float32Array(i.length),c=o-r;for(let u=0;u<i.length;u++)l[u]=r+i[u]*c;e.setValueCurveAtTime(l,t,n)}}function kn(e,t,n,a="linear",r=1,o=0){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(o,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(o,.001),t+n);else{const i=zn(a,1e4,!1),l=new Float32Array(i.length),c=r-o;for(let u=0;u<i.length;u++)l[u]=o+i[u]*c;e.setValueCurveAtTime(l,t,n)}}var Ka=class{constructor(e){this.activePlayers=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);const t=e.destination||j.getDestination();if(e.effects){const a=e.effects(this.muteGain,t,!1);a&&(this.effectsCleanup=a)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]);this.clips=n.map(a=>{const r=new j.Player({url:a.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),o=new j.Gain(a.gain);return r.connect(o),o.chain(this.volumeNode,this.panNode,this.muteGain),{player:r,clipInfo:a,fadeGain:o,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:a,fadeGain:r}=e,o=Tt(r.gain);if(!o)return;o.cancelScheduledValues(0);const i=n-a.offset;if(a.fadeIn&&i<a.fadeIn.duration){const l=a.fadeIn.duration;if(i<=0)xn(o,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-i,u=i/l,f=a.gain*u;xn(o,t,c,a.fadeIn.type||"linear",f,a.gain)}}else o.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-i;if(c>0){const u=t+c;kn(o,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,f=a.fadeOut.duration-u,v=u/a.fadeOut.duration,h=a.gain*(1-v);kn(o,t,f,a.fadeOut.type||"linear",h,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;Tt(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(a=>{a.player.stop(),a.player.disconnect(),a.player.dispose();const r=new j.Player({url:a.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});r.connect(a.fadeGain),a.player=r,a.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(a=>{const{player:r,clipInfo:o}=a,i=t,l=o.startTime,c=o.startTime+o.duration;if(i<c){this.activePlayers++;const u=e??j.now();if(a.playStartTime=u,i>=l){const f=i-l+o.offset,v=o.duration-(i-l),h=n?Math.min(n,v):v;a.pausedPosition=f,this.scheduleFades(a,u,f),r.start(u,f,h)}else{const f=l-i,v=n?Math.min(n-f,o.duration):o.duration;f<(n??1/0)?(a.pausedPosition=o.offset,this.scheduleFades(a,u+f,o.offset),r.start(u+f,o.offset,v)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(j.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??j.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},Ua=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this.activeTracks=new Map,this.playbackSessionId=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)}async init(){this.isInitialized||(await j.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new Ka(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){console.warn("TonePlayout not initialized. Call init() first.");return}const a=e??j.now(),r=t??0;this.playbackSessionId++;const o=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(i=>{const l=i.startTime;if(r>=l){const c=r-l;n!==void 0&&(this.activeTracks.set(i.id,o),i.setOnStopCallback(()=>{this.activeTracks.get(i.id)===o&&(this.activeTracks.delete(i.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),i.play(a,c,n)}else{const c=l-r;n!==void 0&&(this.activeTracks.set(i.id,o),i.setOnStopCallback(()=>{this.activeTracks.get(i.id)===o&&(this.activeTracks.delete(i.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),i.play(a+c,0,n)}}),t!==void 0?j.getTransport().start(a,t):j.getTransport().start(a)}pause(){j.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){j.getTransport().stop(),this.tracks.forEach(e=>{e.stop()})}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 a=this.manualMuteState.get(n)??!1;t.setMute(a)}else{const a=this.manualMuteState.get(n)??!1;t.setMute(a)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return j.getTransport().seconds}seekTo(e){j.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return j.getContext()}get sampleRate(){return j.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}};const Nt=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[Nt.Translate.toString(e),Nt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),qa=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128ZM60,112a16,16,0,1,0,16,16A16,16,0,0,0,60,112Zm136,0a16,16,0,1,0,16,16A16,16,0,0,0,196,112Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M240,96v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V96A16,16,0,0,1,32,80H224A16,16,0,0,1,240,96Z",opacity:"0.2"}),T.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M224,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V96A16,16,0,0,0,224,80ZM60,140a12,12,0,1,1,12-12A12,12,0,0,1,60,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,128,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,196,140Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128ZM60,118a10,10,0,1,0,10,10A10,10,0,0,0,60,118Zm136,0a10,10,0,1,0,10,10A10,10,0,0,0,196,118Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Zm-76-8a8,8,0,1,0,8,8A8,8,0,0,0,60,120Zm136,0a8,8,0,1,0,8,8A8,8,0,0,0,196,120Z"}))]]),Ja=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),Qa=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),er=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z",opacity:"0.2"}),T.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z"}))]]),tr=s.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),vt=T.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:o,mirrored:i,children:l,weights:c,...u}=e,{color:f="currentColor",size:v,weight:h="regular",mirrored:d=!1,...C}=T.useContext(tr);return T.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??v,height:r??v,fill:a??f,viewBox:"0 0 256 256",transform:i||d?"scale(-1, 1)":void 0,...C,...u},!!n&&T.createElement("title",null,n),l,c.get(o??h))});vt.displayName="IconBase";const Hn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:qa}));Hn.displayName="DotsThreeIcon";const Xn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:Ja}));Xn.displayName="SpeakerHighIcon";const On=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:Qa}));On.displayName="SpeakerLowIcon";const Nn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:er}));Nn.displayName="XIcon";const nr=Nn;D.span`
1
+ "use strict";var Ga=Object.create;var kn=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ya=Object.getOwnPropertyNames;var Ua=Object.getPrototypeOf,Ka=Object.prototype.hasOwnProperty;var qa=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ya(t))!Ka.call(e,r)&&r!==n&&kn(e,r,{get:()=>t[r],enumerable:!(a=Na(t,r))||a.enumerable});return e};var Ja=(e,t,n)=>(n=e!=null?Ga(Ua(e)):{},qa(t||!e||!e.__esModule?kn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("tone"),v=require("react/jsx-runtime"),o=require("react"),R=require("styled-components"),Ke=require("@dnd-kit/core"),Hn=require("react-dom"),Qa=require("@dnd-kit/modifiers");function Xn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const On=Xn(Z),T=Xn(o);var ke=1e3;function Gt(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u}=e,m=t?.sampleRate??e.sampleRate??u?.sample_rate,h=t?.length??e.sourceDurationSamples??(u&&m?Math.ceil(u.duration*m):void 0);if(m===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(h===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.durationSamples??h;return{id:Yn(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:a,sampleRate:m,sourceDurationSamples:h,gain:r,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u}}function Gn(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u}=e,m=t?.sampleRate??e.sampleRate??u?.sample_rate;if(m===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const h=t?.duration??e.sourceDuration??u?.duration;if(h===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.duration??h;return Gt({audioBuffer:t,startSample:Math.round(n*m),durationSamples:Math.round(p*m),offsetSamples:Math.round(a*m),sampleRate:m,sourceDurationSamples:Math.ceil(h*m),gain:r,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u})}function Nn(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:i=0,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:m}=e;return{id:Yn(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:i,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:m}}function Yn(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}var Sn=!1;function Tt(e){const t=e._param;return!t&&!Sn&&(Sn=!0,console.warn("[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Fades and mute scheduling may not work correctly.")),t}function In(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const s=r/a;n[r]=t?s:1-s}return n}function er(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const s=r/a,i=t?r:e-1-r;n[i]=Math.exp(2*s-1)/Math.E}return n}function tr(e,t){const n=new Float32Array(e),a=t?Math.PI/2:-Math.PI/2;for(let r=0;r<e;r++)n[r]=Math.sin(Math.PI*r/e-a)/2+.5;return n}function nr(e,t,n=10){const a=new Float32Array(e);for(let r=0;r<e;r++){const s=t?r:e-1-r,i=r/e;a[s]=Math.log(1+n*i)/Math.log(1+n)}return a}function Un(e,t,n){switch(e){case"linear":return In(t,n);case"exponential":return er(t,n);case"sCurve":return tr(t,n);case"logarithmic":return nr(t,n);default:return In(t,n)}}function An(e,t,n,a="linear",r=0,s=1){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const i=Un(a,1e4,!0),l=new Float32Array(i.length),c=s-r;for(let u=0;u<i.length;u++)l[u]=r+i[u]*c;e.setValueCurveAtTime(l,t,n)}}function Mn(e,t,n,a="linear",r=1,s=0){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const i=Un(a,1e4,!1),l=new Float32Array(i.length),c=r-s;for(let u=0;u<i.length;u++)l[u]=s+i[u]*c;e.setValueCurveAtTime(l,t,n)}}var ar=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new Z.Volume(this.gainToDb(e.track.gain)),this.panNode=new Z.Panner(e.track.stereoPan),this.muteGain=new Z.Gain(e.track.muted?0:1);const t=e.destination||Z.getDestination();if(e.effects){const a=e.effects(this.muteGain,t,!1);a&&(this.effectsCleanup=a)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]);this.clips=n.map(a=>{const r=new Z.Player({url:a.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new Z.Gain(a.gain);return r.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:r,clipInfo:a,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:a,fadeGain:r}=e,s=Tt(r.gain);if(!s)return;s.cancelScheduledValues(0);const i=n-a.offset;if(a.fadeIn&&i<a.fadeIn.duration){const l=a.fadeIn.duration;if(i<=0)An(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-i,u=i/l,m=a.gain*u;An(s,t,c,a.fadeIn.type||"linear",m,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-i;if(c>0){const u=t+c;Mn(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,m=a.fadeOut.duration-u,h=u/a.fadeOut.duration,p=a.gain*(1-h);Mn(s,t,m,a.fadeOut.type||"linear",p,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;Tt(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(a=>{a.player.stop(),a.player.disconnect(),a.player.dispose();const r=new Z.Player({url:a.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});r.connect(a.fadeGain),a.player=r,a.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(a=>{const{player:r,clipInfo:s}=a,i=t,l=s.startTime,c=s.startTime+s.duration;if(i<c){this.activePlayers++;const u=e??Z.now();if(a.playStartTime=u,i>=l){const m=i-l+s.offset,h=s.duration-(i-l),p=n?Math.min(n,h):h;a.pausedPosition=m,this.scheduleFades(a,u,m),r.start(u,m,p)}else{const m=l-i,h=n?Math.min(n-m,s.duration):s.duration;m<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+m,s.offset),r.start(u+m,s.offset,h)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(Z.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??Z.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},rr=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this.activeTracks=new Map,this.playbackSessionId=0,this.masterVolume=new Z.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,Z.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)}async init(){this.isInitialized||(await Z.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new ar(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){console.warn("TonePlayout not initialized. Call init() first.");return}const a=e??Z.now(),r=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(i=>{const l=i.startTime;if(r>=l){const c=r-l;n!==void 0&&(this.activeTracks.set(i.id,s),i.setOnStopCallback(()=>{this.activeTracks.get(i.id)===s&&(this.activeTracks.delete(i.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),i.play(a,c,n)}else{const c=l-r;n!==void 0&&(this.activeTracks.set(i.id,s),i.setOnStopCallback(()=>{this.activeTracks.get(i.id)===s&&(this.activeTracks.delete(i.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),i.play(a+c,0,n)}}),t!==void 0?Z.getTransport().start(a,t):Z.getTransport().start(a)}pause(){Z.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){Z.getTransport().stop(),this.tracks.forEach(e=>{e.stop()})}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 a=this.manualMuteState.get(n)??!1;t.setMute(a)}else{const a=this.manualMuteState.get(n)??!1;t.setMute(a)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return Z.getTransport().seconds}seekTo(e){Z.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return Z.getContext()}get sampleRate(){return Z.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Mt=null;function or(){return Mt||(Mt=new Z.Context,Z.setContext(Mt)),Mt}function sr(){return or().rawContext}const Nt=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[Nt.Translate.toString(e),Nt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),ir=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128ZM60,112a16,16,0,1,0,16,16A16,16,0,0,0,60,112Zm136,0a16,16,0,1,0,16,16A16,16,0,0,0,196,112Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M240,96v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V96A16,16,0,0,1,32,80H224A16,16,0,0,1,240,96Z",opacity:"0.2"}),T.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M224,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V96A16,16,0,0,0,224,80ZM60,140a12,12,0,1,1,12-12A12,12,0,0,1,60,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,128,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,196,140Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128ZM60,118a10,10,0,1,0,10,10A10,10,0,0,0,60,118Zm136,0a10,10,0,1,0,10,10A10,10,0,0,0,196,118Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Zm-76-8a8,8,0,1,0,8,8A8,8,0,0,0,60,120Zm136,0a8,8,0,1,0,8,8A8,8,0,0,0,196,120Z"}))]]),lr=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),cr=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),ur=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z",opacity:"0.2"}),T.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z"}))]]),dr=o.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),vt=T.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:i,children:l,weights:c,...u}=e,{color:m="currentColor",size:h,weight:p="regular",mirrored:f=!1,...b}=T.useContext(dr);return T.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??h,height:r??h,fill:a??m,viewBox:"0 0 256 256",transform:i||f?"scale(-1, 1)":void 0,...b,...u},!!n&&T.createElement("title",null,n),l,c.get(s??p))});vt.displayName="IconBase";const Kn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:ir}));Kn.displayName="DotsThreeIcon";const qn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:lr}));qn.displayName="SpeakerHighIcon";const Jn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:cr}));Jn.displayName="SpeakerLowIcon";const Qn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:ur}));Qn.displayName="XIcon";const fr=Qn;R.span`
2
2
  font-family: 'Courier New', Monaco, monospace;
3
3
  font-size: 1rem;
4
4
  font-weight: 600;
5
5
  color: ${e=>e.theme?.textColor||"#333"};
6
6
  user-select: none;
7
- `;var Kt=D.button`
7
+ `;var Kt=R.button`
8
8
  display: inline-flex;
9
9
  align-items: center;
10
10
  justify-content: center;
@@ -18,7 +18,9 @@
18
18
  border-radius: ${e=>e.theme.borderRadius};
19
19
  cursor: pointer;
20
20
  outline: none;
21
- transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out,
21
+ transition:
22
+ background-color 0.15s ease-in-out,
23
+ border-color 0.15s ease-in-out,
22
24
  box-shadow 0.15s ease-in-out;
23
25
 
24
26
  &:hover:not(:disabled) {
@@ -33,37 +35,37 @@
33
35
  opacity: 0.6;
34
36
  cursor: not-allowed;
35
37
  }
36
- `;D(Kt)`
38
+ `;R(Kt)`
37
39
  padding: 0.25rem 0.5rem;
38
40
  font-size: ${e=>e.theme.fontSizeSmall};
39
- `;D(Kt)`
41
+ `;R(Kt)`
40
42
  padding: 0.5rem;
41
43
  min-width: 2.25rem;
42
44
  min-height: 2.25rem;
43
- `;D(Kt)`
45
+ `;R(Kt)`
44
46
  padding: 0.25rem;
45
47
  min-width: 1.75rem;
46
48
  min-height: 1.75rem;
47
49
  font-size: ${e=>e.theme.fontSizeSmall};
48
- `;var ar=D.div`
50
+ `;var mr=R.div`
49
51
  display: inline-flex;
50
52
  align-items: center;
51
53
  gap: 0.5rem;
52
- `,rr=D.input`
54
+ `,hr=R.input`
53
55
  cursor: pointer;
54
56
  accent-color: ${e=>e.theme.inputFocusBorder};
55
57
 
56
58
  &:disabled {
57
59
  cursor: not-allowed;
58
60
  }
59
- `,sr=D.label`
61
+ `,pr=R.label`
60
62
  margin: 0;
61
63
  cursor: pointer;
62
64
  user-select: none;
63
65
  font-family: ${e=>e.theme.fontFamily};
64
66
  font-size: ${e=>e.theme.fontSize};
65
67
  color: ${e=>e.theme.textColor};
66
- `,ze=D.button`
68
+ `,He=R.button`
67
69
  padding: 0.5rem 1rem;
68
70
  background: ${e=>e.theme.buttonBackground||"#007bff"};
69
71
  color: ${e=>e.theme.buttonText||"white"};
@@ -89,7 +91,7 @@
89
91
  cursor: not-allowed;
90
92
  opacity: 0.6;
91
93
  }
92
- `,Gn=D.input`
94
+ `,ea=R.input`
93
95
  padding: 0.5rem 0.75rem;
94
96
  font-family: ${e=>e.theme.fontFamily};
95
97
  font-size: ${e=>e.theme.fontSize};
@@ -98,7 +100,9 @@
98
100
  border: 1px solid ${e=>e.theme.inputBorder};
99
101
  border-radius: ${e=>e.theme.borderRadius};
100
102
  outline: none;
101
- transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
103
+ transition:
104
+ border-color 0.15s ease-in-out,
105
+ box-shadow 0.15s ease-in-out;
102
106
 
103
107
  &::placeholder {
104
108
  color: ${e=>e.theme.inputPlaceholder};
@@ -113,17 +117,17 @@
113
117
  opacity: 0.6;
114
118
  cursor: not-allowed;
115
119
  }
116
- `;D(Gn)`
120
+ `;R(ea)`
117
121
  padding: 0.25rem 0.5rem;
118
122
  font-size: ${e=>e.theme.fontSizeSmall};
119
- `;var or=D.label`
123
+ `;var gr=R.label`
120
124
  font-family: ${e=>e.theme.fontFamily};
121
125
  font-size: ${e=>e.theme.fontSizeSmall};
122
126
  font-weight: 500;
123
127
  color: ${e=>e.theme.textColorMuted};
124
128
  margin-bottom: 0.25rem;
125
129
  display: block;
126
- `;D.label`
130
+ `;R.label`
127
131
  font-family: ${e=>e.theme.fontFamily};
128
132
  font-size: ${e=>e.theme.fontSize};
129
133
  color: ${e=>e.theme.textColor};
@@ -131,7 +135,7 @@
131
135
  align-items: center;
132
136
  gap: 0.5rem;
133
137
  cursor: pointer;
134
- `;var ir=D.span`
138
+ `;var br=R.span`
135
139
  position: absolute;
136
140
  width: 1px;
137
141
  height: 1px;
@@ -141,7 +145,7 @@
141
145
  clip: rect(0, 0, 0, 0);
142
146
  white-space: nowrap;
143
147
  border: 0;
144
- `,Yn=D.select`
148
+ `,ta=R.select`
145
149
  padding: 0.5rem 2rem 0.5rem 0.75rem;
146
150
  font-family: ${e=>e.theme.fontFamily};
147
151
  font-size: ${e=>e.theme.fontSize};
@@ -155,7 +159,9 @@
155
159
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
156
160
  background-repeat: no-repeat;
157
161
  background-position: right 0.75rem center;
158
- transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
162
+ transition:
163
+ border-color 0.15s ease-in-out,
164
+ box-shadow 0.15s ease-in-out;
159
165
 
160
166
  &:focus {
161
167
  border-color: ${e=>e.theme.inputFocusBorder};
@@ -172,10 +178,10 @@
172
178
  color: ${e=>e.theme.inputText};
173
179
  background-color: ${e=>e.theme.inputBackground};
174
180
  }
175
- `;D(Yn)`
181
+ `;R(ta)`
176
182
  padding: 0.25rem 1.75rem 0.25rem 0.5rem;
177
183
  font-size: ${e=>e.theme.fontSizeSmall};
178
- `;var Kn=D.input.attrs({type:"range"})`
184
+ `;var na=R.input.attrs({type:"range"})`
179
185
  -webkit-appearance: none;
180
186
  appearance: none;
181
187
  width: 100%;
@@ -196,7 +202,9 @@
196
202
  border-radius: 50%;
197
203
  cursor: pointer;
198
204
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
199
- transition: transform 0.15s ease, box-shadow 0.15s ease;
205
+ transition:
206
+ transform 0.15s ease,
207
+ box-shadow 0.15s ease;
200
208
  }
201
209
 
202
210
  &::-webkit-slider-thumb:hover {
@@ -213,7 +221,9 @@
213
221
  border-radius: 50%;
214
222
  cursor: pointer;
215
223
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
216
- transition: transform 0.15s ease, box-shadow 0.15s ease;
224
+ transition:
225
+ transform 0.15s ease,
226
+ box-shadow 0.15s ease;
217
227
  }
218
228
 
219
229
  &::-moz-range-thumb:hover {
@@ -251,7 +261,7 @@
251
261
  &:disabled::-moz-range-thumb {
252
262
  cursor: not-allowed;
253
263
  }
254
- `,lr=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=o=>{t(o.target.checked)};return g.jsxs(ar,{className:a,children:[g.jsx(rr,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:r,disabled:n}),g.jsx(sr,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function Un(e){return typeof e=="object"&&e!==null&&"type"in e}function at(e){if(!Un(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(a=>`${a.color} ${a.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var qn={waveformDrawMode:"inverted",waveOutlineColor:"#ffffff",waveFillColor:"#1a7f8e",waveProgressColor:"rgba(0, 0, 0, 0.10)",selectedWaveOutlineColor:"#ffffff",selectedWaveFillColor:"#00b4d8",selectedTrackControlsBackground:"#d9e9ff",timeColor:"#000",timescaleBackgroundColor:"#fff",playheadColor:"#f00",selectionColor:"rgba(255, 105, 180, 0.7)",loopRegionColor:"rgba(59, 130, 246, 0.3)",loopMarkerColor:"#3b82f6",clipHeaderBackgroundColor:"rgba(0, 0, 0, 0.1)",clipHeaderBorderColor:"rgba(0, 0, 0, 0.2)",clipHeaderTextColor:"#333",clipHeaderFontFamily:"inherit",selectedClipHeaderBackgroundColor:"#b3d9ff",fadeOverlayColor:"rgba(0, 0, 0, 0.4)",backgroundColor:"#ffffff",surfaceColor:"#f5f5f5",borderColor:"#ddd",textColor:"#333",textColorMuted:"#666",inputBackground:"#ffffff",inputBorder:"#ccc",inputText:"#333",inputPlaceholder:"#999",inputFocusBorder:"#0066cc",buttonBackground:"#0091ff",buttonText:"#ffffff",buttonBorder:"#0081e6",buttonHoverBackground:"#0081e6",sliderTrackColor:"#ddd",sliderThumbColor:"#daa520",annotationBoxBackground:"rgba(255, 255, 255, 0.85)",annotationBoxActiveBackground:"rgba(255, 255, 255, 0.95)",annotationBoxHoverBackground:"rgba(255, 255, 255, 0.98)",annotationBoxBorder:"#ff9800",annotationBoxActiveBorder:"#d67600",annotationLabelColor:"#2a2a2a",annotationResizeHandleColor:"rgba(0, 0, 0, 0.4)",annotationResizeHandleActiveColor:"rgba(0, 0, 0, 0.8)",annotationTextItemHoverBackground:"rgba(0, 0, 0, 0.03)",borderRadius:"4px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif',fontSize:"14px",fontSizeSmall:"12px"},cr=class{constructor(){this._state=null,this._listeners=new Set,this.subscribe=e=>(this._listeners.add(e),()=>this._listeners.delete(e)),this.getSnapshot=()=>this._state}update(e,t){const n=t*1.5,a=Math.max(0,e-n),r=e+t+n;if(!(this._state&&this._state.containerWidth===t&&Math.abs(this._state.scrollLeft-e)<100)){this._state={scrollLeft:e,containerWidth:t,visibleStart:a,visibleEnd:r};for(const o of this._listeners)o()}}},Jn=s.createContext(null),ur=()=>()=>{},dr=({containerRef:e,children:t})=>{const n=s.useRef(null);n.current===null&&(n.current=new cr);const a=n.current,r=s.useRef(null),o=s.useCallback(()=>{const l=e.current;l&&a.update(l.scrollLeft,l.clientWidth)},[e,a]),i=s.useCallback(()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null,o()}))},[o]);return s.useEffect(()=>{const l=e.current;if(!l)return;o(),l.addEventListener("scroll",i,{passive:!0});const c=new ResizeObserver(()=>{i()});return c.observe(l),()=>{l.removeEventListener("scroll",i),c.disconnect(),r.current!==null&&(cancelAnimationFrame(r.current),r.current=null)}},[e,o,i]),g.jsx(Jn.Provider,{value:a,children:t})};function Ut(e){const t=s.useContext(Jn);return s.useSyncExternalStore(t?t.subscribe:ur,()=>e(t?t.getSnapshot():null),()=>e(null))}var pe=1e3;function fr(e,t,n,a){if(!Un(t))return t;let r;t.direction==="vertical"?r=e.createLinearGradient(0,0,0,a):r=e.createLinearGradient(0,0,n,0);for(const o of t.stops)r.addColorStop(o.offset,o.color);return r}var mr=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
264
+ `,vr=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return v.jsxs(mr,{className:a,children:[v.jsx(hr,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:r,disabled:n}),v.jsx(pr,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function aa(e){return typeof e=="object"&&e!==null&&"type"in e}function tt(e){if(!aa(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(a=>`${a.color} ${a.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var ra={waveformDrawMode:"inverted",waveOutlineColor:"#ffffff",waveFillColor:"#1a7f8e",waveProgressColor:"rgba(0, 0, 0, 0.10)",selectedWaveOutlineColor:"#ffffff",selectedWaveFillColor:"#00b4d8",selectedTrackControlsBackground:"#d9e9ff",timeColor:"#000",timescaleBackgroundColor:"#fff",playheadColor:"#f00",selectionColor:"rgba(255, 105, 180, 0.7)",loopRegionColor:"rgba(59, 130, 246, 0.3)",loopMarkerColor:"#3b82f6",clipHeaderBackgroundColor:"rgba(0, 0, 0, 0.1)",clipHeaderBorderColor:"rgba(0, 0, 0, 0.2)",clipHeaderTextColor:"#333",clipHeaderFontFamily:"inherit",selectedClipHeaderBackgroundColor:"#b3d9ff",fadeOverlayColor:"rgba(0, 0, 0, 0.4)",backgroundColor:"#ffffff",surfaceColor:"#f5f5f5",borderColor:"#ddd",textColor:"#333",textColorMuted:"#666",inputBackground:"#ffffff",inputBorder:"#ccc",inputText:"#333",inputPlaceholder:"#999",inputFocusBorder:"#0066cc",buttonBackground:"#0091ff",buttonText:"#ffffff",buttonBorder:"#0081e6",buttonHoverBackground:"#0081e6",sliderTrackColor:"#ddd",sliderThumbColor:"#daa520",annotationBoxBackground:"rgba(255, 255, 255, 0.85)",annotationBoxActiveBackground:"rgba(255, 255, 255, 0.95)",annotationBoxHoverBackground:"rgba(255, 255, 255, 0.98)",annotationBoxBorder:"#ff9800",annotationBoxActiveBorder:"#d67600",annotationLabelColor:"#2a2a2a",annotationResizeHandleColor:"rgba(0, 0, 0, 0.4)",annotationResizeHandleActiveColor:"rgba(0, 0, 0, 0.8)",annotationTextItemHoverBackground:"rgba(0, 0, 0, 0.03)",borderRadius:"4px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif',fontSize:"14px",fontSizeSmall:"12px"},Cr=class{constructor(){this._state=null,this._listeners=new Set,this.subscribe=e=>(this._listeners.add(e),()=>this._listeners.delete(e)),this.getSnapshot=()=>this._state}update(e,t){const n=t*1.5,a=Math.max(0,e-n),r=e+t+n;if(!(this._state&&this._state.containerWidth===t&&Math.abs(this._state.scrollLeft-e)<100)){this._state={scrollLeft:e,containerWidth:t,visibleStart:a,visibleEnd:r};for(const s of this._listeners)s()}}},oa=o.createContext(null),wr=()=>()=>{},yr=({containerRef:e,children:t})=>{const n=o.useRef(null);n.current===null&&(n.current=new Cr);const a=n.current,r=o.useRef(null),s=o.useCallback(()=>{const l=e.current;l&&a.update(l.scrollLeft,l.clientWidth)},[e,a]),i=o.useCallback(()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null,s()}))},[s]);return o.useEffect(()=>{const l=e.current;if(!l)return;s(),l.addEventListener("scroll",i,{passive:!0});const c=new ResizeObserver(()=>{i()});return c.observe(l),()=>{l.removeEventListener("scroll",i),c.disconnect(),r.current!==null&&(cancelAnimationFrame(r.current),r.current=null)}},[e,s,i]),v.jsx(oa.Provider,{value:a,children:t})};function xr(e){const t=o.useContext(oa);return o.useSyncExternalStore(t?t.subscribe:wr,()=>e(t?t.getSnapshot():null),()=>e(null))}function qt(e,t,n=0){const a=xr(r=>{const s=Math.ceil(e/t),i=[];for(let l=0;l<s;l++){const c=l*t,u=Math.min(e-c,t);if(r){const m=n+c;if(m+u<=r.visibleStart||m>=r.visibleEnd)continue}i.push(l)}return i.join(",")});return o.useMemo(()=>a?a.split(",").map(Number):[],[a])}var sa=o.createContext(0),kr=({originX:e,children:t})=>v.jsx(sa.Provider,{value:e,children:t}),ia=()=>o.useContext(sa);function Jt(){const e=o.useRef(new Map),t=o.useCallback(n=>{if(n!==null){const a=parseInt(n.dataset.index,10);e.current.set(a,n)}},[]);return o.useEffect(()=>{const n=e.current;for(const[a,r]of n.entries())r.isConnected||n.delete(a)}),{canvasRef:t,canvasMapRef:e}}function Sr(e,t,n,a){if(!aa(t))return t;let r;t.direction==="vertical"?r=e.createLinearGradient(0,0,0,a):r=e.createLinearGradient(0,0,n,0);for(const s of t.stops)r.addColorStop(s.offset,s.color);return r}var Ir=R.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
255
265
  position: absolute;
256
266
  top: 0;
257
267
  /* Promote to own compositing layer for smoother scrolling */
@@ -259,15 +269,15 @@
259
269
  /* Disable image rendering interpolation */
260
270
  image-rendering: pixelated;
261
271
  image-rendering: crisp-edges;
262
- `,hr=D.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
272
+ `,Ar=R.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
263
273
  position: absolute;
264
274
  background: ${e=>e.$waveFillColor};
265
275
  /* Force GPU compositing layer to reduce scroll flickering */
266
276
  transform: translateZ(0);
267
277
  backface-visibility: hidden;
268
- `,Sn=e=>{const{data:t,bits:n,length:a,index:r,className:o,devicePixelRatio:i=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:f=1,barGap:v=0,transparentBackground:h=!1,drawMode:d="inverted"}=e,C=s.useRef([]),y=Ut(x=>{const S=Math.ceil(a/pe),E=[];for(let I=0;I<S;I++){const $=I*pe,M=Math.min(a-$,pe);x&&($+M<=x.visibleStart||$>=x.visibleEnd)||E.push(I)}return E.join(",")}),p=y?y.split(",").map(Number):[],m=s.useCallback(x=>{if(x!==null){const S=parseInt(x.dataset.index,10);C.current[S]=x}},[]);s.useEffect(()=>{const x=C.current;for(let S=x.length-1;S>=0;S--)x[S]&&!x[S].isConnected&&delete x[S]}),s.useLayoutEffect(()=>{const x=C.current,S=f+v;for(let E=0;E<x.length;E++){const I=x[E];if(!I)continue;const M=parseInt(I.dataset.index,10)*pe,A=I.getContext("2d"),B=Math.floor(l/2),_=2**(n-1);if(A){A.resetTransform(),A.clearRect(0,0,I.width,I.height),A.imageSmoothingEnabled=!1,A.scale(i,i);const R=I.width/i;let W;d==="normal"?W=u:W=c,A.fillStyle=fr(A,W,R,l);const L=M,P=M+R,U=Math.floor((L-f+S)/S)*S;for(let H=Math.max(0,U);H<P;H+=S){const ne=H-L;if(ne+f<=0)continue;const le=H;if(le*2+1<t.length){const se=t[le*2]/_,oe=t[le*2+1]/_,ye=Math.abs(se*B),ce=Math.abs(oe*B);d==="normal"?A.fillRect(ne,B-ce,f,ce+ye):(A.fillRect(ne,0,f,B-ce),A.fillRect(ne,B+ye,f,B-ye))}}}}},[t,n,l,c,u,i,a,f,v,d,y]);const k=p.map(x=>{const S=x*pe,E=Math.min(a-S,pe);return g.jsx(mr,{$cssWidth:E,$left:S,width:E*i,height:l*i,$waveHeight:l,"data-index":x,ref:m},`${a}-${x}`)}),b=h?"transparent":at(u);return g.jsx(hr,{$index:r,$cssWidth:a,className:o,$waveHeight:l,$waveFillColor:b,children:k})},pr={padding:"16px",background:"#1a1a2e",color:"#e0e0e0",border:"1px solid #d08070",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px",minHeight:"60px",display:"flex",alignItems:"center",justifyContent:"center"};(class extends s.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[waveform-playlist] Render error:",e,t.componentStack)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:g.jsx("div",{style:pr,children:"Waveform playlist encountered an error. Check console for details."}):this.props.children}});var Qn=22,ea=D.div`
278
+ `,_n=e=>{const{data:t,bits:n,length:a,index:r,className:s,devicePixelRatio:i=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:m=1,barGap:h=0,transparentBackground:p=!1,drawMode:f="inverted"}=e,{canvasRef:b,canvasMapRef:w}=Jt(),g=ia(),d=qt(a,ke,g);o.useLayoutEffect(()=>{const k=m+h;for(const[S,M]of w.current.entries()){const A=S*ke,E=M.getContext("2d"),_=Math.floor(l/2),I=2**(n-1);if(E){E.resetTransform(),E.clearRect(0,0,M.width,M.height),E.imageSmoothingEnabled=!1,E.scale(i,i);const B=M.width/i;let $;f==="normal"?$=u:$=c,E.fillStyle=Sr(E,$,B,l);const W=A,z=A+B,Y=Math.floor((W-m+k)/k)*k;for(let j=Math.max(0,Y);j<z;j+=k){const N=j-W;if(N+m<=0)continue;const L=j;if(L*2+1<t.length){const ae=t[L*2]/I,oe=t[L*2+1]/I,q=Math.abs(ae*_),fe=Math.abs(oe*_);f==="normal"?E.fillRect(N,_-fe,m,fe+q):(E.fillRect(N,0,m,_-fe),E.fillRect(N,_+q,m,_-q))}}}}},[w,t,n,l,c,u,i,a,m,h,f,d]);const x=d.map(k=>{const S=k*ke,M=Math.min(a-S,ke);return v.jsx(Ir,{$cssWidth:M,$left:S,width:M*i,height:l*i,$waveHeight:l,"data-index":k,ref:b},`${a}-${k}`)}),C=p?"transparent":tt(u);return v.jsx(Ar,{$index:r,$cssWidth:a,className:s,$waveHeight:l,$waveFillColor:C,children:x})},Mr={padding:"16px",background:"#1a1a2e",color:"#e0e0e0",border:"1px solid #d08070",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px",minHeight:"60px",display:"flex",alignItems:"center",justifyContent:"center"};(class extends o.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[waveform-playlist] Render error:",e,t.componentStack)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:v.jsx("div",{style:Mr,children:"Waveform playlist encountered an error. Check console for details."}):this.props.children}});var la=22,ca=R.div`
269
279
  position: relative;
270
- height: ${Qn}px;
280
+ height: ${la}px;
271
281
  background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
272
282
  border-bottom: 1px solid ${e=>e.theme.clipHeaderBorderColor};
273
283
  display: flex;
@@ -289,7 +299,7 @@
289
299
  cursor: grabbing;
290
300
  }
291
301
  `}
292
- `,ta=D.span`
302
+ `,ua=R.span`
293
303
  font-size: 11px;
294
304
  font-weight: 600;
295
305
  font-family: ${e=>e.theme.clipHeaderFontFamily};
@@ -297,12 +307,12 @@
297
307
  white-space: nowrap;
298
308
  overflow: hidden;
299
309
  text-overflow: ellipsis;
300
- `,gr=({trackName:e,isSelected:t=!1})=>g.jsx(ea,{$isDragging:!1,$interactive:!1,$isSelected:t,children:g.jsx(ta,{children:e})}),br=({clipId:e,trackIndex:t,clipIndex:n,trackName:a,isSelected:r=!1,disableDrag:o=!1,dragHandleProps:i})=>{if(o||!i)return g.jsx(gr,{trackName:a,isSelected:r});const{attributes:l,listeners:c,setActivatorNodeRef:u}=i;return g.jsx(ea,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:r,...c,...l,children:g.jsx(ta,{children:a})})},vr=8,yr=24,Cr=D.div`
310
+ `,_r=({trackName:e,isSelected:t=!1})=>v.jsx(ca,{$isDragging:!1,$interactive:!1,$isSelected:t,children:v.jsx(ua,{children:e})}),Er=({clipId:e,trackIndex:t,clipIndex:n,trackName:a,isSelected:r=!1,disableDrag:s=!1,dragHandleProps:i})=>{if(s||!i)return v.jsx(_r,{trackName:a,isSelected:r});const{attributes:l,listeners:c,setActivatorNodeRef:u}=i;return v.jsx(ca,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:r,...c,...l,children:v.jsx(ua,{children:a})})},$r=8,Tr=24,Rr=R.div`
301
311
  position: absolute;
302
312
  ${e=>e.$edge==="left"?"left: 0;":"right: 0;"}
303
313
  top: 0;
304
314
  bottom: 0;
305
- width: ${e=>e.$touchOptimized?yr:vr}px;
315
+ width: ${e=>e.$touchOptimized?Tr:$r}px;
306
316
  cursor: col-resize;
307
317
  user-select: none;
308
318
  z-index: 105; /* Above waveform, below header */
@@ -325,19 +335,19 @@
325
335
  background: rgba(255, 255, 255, 0.4);
326
336
  ${e=>e.$edge==="left"?"border-left: 2px solid rgba(255, 255, 255, 0.8);":"border-right: 2px solid rgba(255, 255, 255, 0.8);"}
327
337
  }
328
- `,In=({clipId:e,trackIndex:t,clipIndex:n,edge:a,dragHandleProps:r,touchOptimized:o=!1})=>{const[i,l]=s.useState(!1);if(!r)return null;const{attributes:c,listeners:u,setActivatorNodeRef:f,isDragging:v}=r;return g.jsx(Cr,{ref:f,"data-clip-id":e,"data-boundary-edge":a,$edge:a,$isDragging:v,$isHovered:i,$touchOptimized:o,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},wr=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
338
+ `,En=({clipId:e,trackIndex:t,clipIndex:n,edge:a,dragHandleProps:r,touchOptimized:s=!1})=>{const[i,l]=o.useState(!1);if(!r)return null;const{attributes:c,listeners:u,setActivatorNodeRef:m,isDragging:h}=r;return v.jsx(Rr,{ref:m,"data-clip-id":e,"data-boundary-edge":a,$edge:a,$isDragging:h,$isHovered:i,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},Dr=R.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
329
339
  position: absolute;
330
340
  top: 0;
331
341
  bottom: 0;
332
342
  pointer-events: none;
333
343
  z-index: 50;
334
- `,xr=D.svg`
344
+ `,Br=R.svg`
335
345
  width: 100%;
336
346
  height: 100%;
337
347
  display: block;
338
348
  /* Flip horizontally for fadeOut - makes it mirror of fadeIn */
339
349
  transform: ${e=>e.$type==="fadeOut"?"scaleX(-1)":"none"};
340
- `;function kr(e,t,n="logarithmic"){const a=[],r=Math.max(20,Math.min(e,100));for(let o=0;o<=r;o++){const i=o/r*e,l=o/r;let c;switch(n){case"linear":c=l;break;case"exponential":c=l*l;break;case"sCurve":c=(1-Math.cos(l*Math.PI))/2;break;case"logarithmic":default:c=Math.log10(1+l*9)/Math.log10(10);break}const u=(1-c)*t;a.push(`${i},${u}`)}return`M 0,${t} L ${a.join(" L ")} L ${e},0 L 0,0 Z`}var An=({left:e,width:t,type:n,curveType:a="logarithmic",color:r})=>{const o=D.useTheme();if(t<1)return null;const i=r||o?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return g.jsx(wr,{$left:e,$width:t,$type:n,children:g.jsx(xr,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:g.jsx("path",{d:kr(t,100,a),fill:i})})})},Sr=D.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
350
+ `;function Fr(e,t,n="logarithmic"){const a=[],r=Math.max(20,Math.min(e,100));for(let s=0;s<=r;s++){const i=s/r*e,l=s/r;let c;switch(n){case"linear":c=l;break;case"exponential":c=l*l;break;case"sCurve":c=(1-Math.cos(l*Math.PI))/2;break;case"logarithmic":default:c=Math.log10(1+l*9)/Math.log10(10);break}const u=(1-c)*t;a.push(`${i},${u}`)}return`M 0,${t} L ${a.join(" L ")} L ${e},0 L 0,0 Z`}var $n=({left:e,width:t,type:n,curveType:a="logarithmic",color:r})=>{const s=R.useTheme();if(t<1)return null;const i=r||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return v.jsx(Dr,{$left:e,$width:t,$type:n,children:v.jsx(Br,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:v.jsx("path",{d:Fr(t,100,a),fill:i})})})},Wr=R.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
341
351
  position: ${e=>e.$isOverlay?"relative":"absolute"};
342
352
  top: 0;
343
353
  height: ${e=>e.$isOverlay?"auto":"100%"};
@@ -351,20 +361,20 @@
351
361
  &:hover {
352
362
  background: rgba(255, 255, 255, 0.08);
353
363
  }
354
- `,Ir=D.div`
364
+ `,Pr=R.div`
355
365
  flex: 1;
356
366
  position: relative;
357
367
  overflow: ${e=>e.$isOverlay?"visible":"hidden"};
358
- `,Gt=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:o,startSample:i,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:f=!1,isOverlay:v=!1,isSelected:h=!1,onMouseDown:d,trackId:C,fadeIn:y,fadeOut:p,sampleRate:m=44100,showFades:k=!1,touchOptimized:w=!1})=>{const b=Math.floor(i/c),S=Math.floor((i+l)/c)-b,E=u&&!f&&!v,I=`clip-${a}-${r}`,{attributes:$,listeners:M,setNodeRef:A,setActivatorNodeRef:B,transform:_,isDragging:R}=Ge.useDraggable({id:I,data:{clipId:n,trackIndex:a,clipIndex:r},disabled:!E}),W=`clip-boundary-left-${a}-${r}`,{attributes:L,listeners:P,setActivatorNodeRef:U,isDragging:H}=Ge.useDraggable({id:W,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"left"},disabled:!E}),ne=`clip-boundary-right-${a}-${r}`,{attributes:le,listeners:se,setActivatorNodeRef:oe,isDragging:ye}=Ge.useDraggable({id:ne,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"right"},disabled:!E}),ce=_?{transform:Nt.Translate.toString(_),zIndex:R?100:void 0}:void 0;return g.jsxs(Sr,{ref:A,style:ce,className:t,$left:b,$width:S,$isOverlay:v,"data-clip-container":"true","data-track-id":C,onMouseDown:d,children:[u&&g.jsx(br,{clipId:n,trackIndex:a,clipIndex:r,trackName:o,isSelected:h,disableDrag:f,dragHandleProps:E?{attributes:$,listeners:M,setActivatorNodeRef:B}:void 0}),g.jsxs(Ir,{$isOverlay:v,children:[e,k&&y&&y.duration>0&&g.jsx(An,{left:0,width:Math.floor(y.duration*m/c),type:"fadeIn",curveType:y.type}),k&&p&&p.duration>0&&g.jsx(An,{left:S-Math.floor(p.duration*m/c),width:Math.floor(p.duration*m/c),type:"fadeOut",curveType:p.type})]}),u&&!f&&!v&&g.jsxs(g.Fragment,{children:[g.jsx(In,{clipId:n,trackIndex:a,clipIndex:r,edge:"left",touchOptimized:w,dragHandleProps:{attributes:L,listeners:P,setActivatorNodeRef:U,isDragging:H}}),g.jsx(In,{clipId:n,trackIndex:a,clipIndex:r,edge:"right",touchOptimized:w,dragHandleProps:{attributes:le,listeners:se,setActivatorNodeRef:oe,isDragging:ye}})]})]})},Ar=D.div`
368
+ `,Yt=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:s,startSample:i,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:m=!1,isOverlay:h=!1,isSelected:p=!1,onMouseDown:f,trackId:b,fadeIn:w,fadeOut:g,sampleRate:d=44100,showFades:x=!1,touchOptimized:y=!1})=>{const C=Math.floor(i/c),S=Math.floor((i+l)/c)-C,M=u&&!m&&!h,A=`clip-${a}-${r}`,{attributes:E,listeners:_,setNodeRef:I,setActivatorNodeRef:B,transform:$,isDragging:W}=Ke.useDraggable({id:A,data:{clipId:n,trackIndex:a,clipIndex:r},disabled:!M}),z=`clip-boundary-left-${a}-${r}`,{attributes:Y,listeners:j,setActivatorNodeRef:N,isDragging:L}=Ke.useDraggable({id:z,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"left"},disabled:!M}),ae=`clip-boundary-right-${a}-${r}`,{attributes:oe,listeners:q,setActivatorNodeRef:fe,isDragging:ue}=Ke.useDraggable({id:ae,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"right"},disabled:!M}),le=$?{transform:Nt.Translate.toString($),zIndex:W?100:void 0}:void 0;return v.jsxs(Wr,{ref:I,style:le,className:t,$left:C,$width:S,$isOverlay:h,"data-clip-container":"true","data-track-id":b,onMouseDown:f,children:[u&&v.jsx(Er,{clipId:n,trackIndex:a,clipIndex:r,trackName:s,isSelected:p,disableDrag:m,dragHandleProps:M?{attributes:E,listeners:_,setActivatorNodeRef:B}:void 0}),v.jsx(kr,{originX:C,children:v.jsxs(Pr,{$isOverlay:h,children:[e,x&&w&&w.duration>0&&v.jsx($n,{left:0,width:Math.floor(w.duration*d/c),type:"fadeIn",curveType:w.type}),x&&g&&g.duration>0&&v.jsx($n,{left:S-Math.floor(g.duration*d/c),width:Math.floor(g.duration*d/c),type:"fadeOut",curveType:g.type})]})}),u&&!m&&!h&&v.jsxs(v.Fragment,{children:[v.jsx(En,{clipId:n,trackIndex:a,clipIndex:r,edge:"left",touchOptimized:y,dragHandleProps:{attributes:Y,listeners:j,setActivatorNodeRef:N,isDragging:L}}),v.jsx(En,{clipId:n,trackIndex:a,clipIndex:r,edge:"right",touchOptimized:y,dragHandleProps:{attributes:oe,listeners:q,setActivatorNodeRef:fe,isDragging:ue}})]})]})},Zr=R.div`
359
369
  display: inline-flex;
360
370
  align-items: center;
361
371
  gap: 0.5rem;
362
- `,Mr=D(or)`
372
+ `,Vr=R(gr)`
363
373
  margin: 0;
364
374
  white-space: nowrap;
365
- `,_r=D(Kn)`
375
+ `,jr=R(na)`
366
376
  width: 120px;
367
- `,Er=({volume:e,onChange:t,disabled:n=!1,className:a})=>{const r=o=>{t(parseFloat(o.target.value)/100)};return g.jsxs(Ar,{className:a,children:[g.jsx(Mr,{htmlFor:"master-gain",children:"Master Volume"}),g.jsx(_r,{min:"0",max:"100",value:e*100,onChange:r,disabled:n,id:"master-gain"})]})};D.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
377
+ `,Lr=({volume:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(parseFloat(s.target.value)/100)};return v.jsxs(Zr,{className:a,children:[v.jsx(Vr,{htmlFor:"master-gain",children:"Master Volume"}),v.jsx(jr,{min:"0",max:"100",value:e*100,onChange:r,disabled:n,id:"master-gain"})]})};R.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
368
378
  position: absolute;
369
379
  top: 0;
370
380
  left: 0;
@@ -374,7 +384,7 @@
374
384
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
375
385
  pointer-events: none;
376
386
  will-change: transform;
377
- `;D.div`
387
+ `;R.div`
378
388
  position: absolute;
379
389
  top: 0;
380
390
  left: 0;
@@ -382,7 +392,7 @@
382
392
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
383
393
  pointer-events: none;
384
394
  will-change: transform;
385
- `;D.div`
395
+ `;R.div`
386
396
  position: absolute;
387
397
  top: -10px;
388
398
  left: -6px;
@@ -391,30 +401,30 @@
391
401
  border-left: 7px solid transparent;
392
402
  border-right: 7px solid transparent;
393
403
  border-top: 10px solid ${e=>e.$color};
394
- `;D.div`
404
+ `;R.div`
395
405
  position: absolute;
396
406
  top: 0;
397
407
  left: 0;
398
408
  width: 2px;
399
409
  height: 100%;
400
410
  background: ${e=>e.$color};
401
- `;var $r=D.div`
411
+ `;var zr=R.div`
402
412
  overflow-y: hidden;
403
413
  overflow-x: auto;
404
414
  position: relative;
405
- `,Tr=D.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
415
+ `,Hr=R.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
406
416
  position: relative;
407
417
  background: ${e=>e.$backgroundColor||"transparent"};
408
- `,Rr=D.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
418
+ `,Xr=R.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
409
419
  background: ${e=>e.$backgroundColor||"white"};
410
420
  width: 100%;
411
421
  position: relative;
412
422
  overflow: hidden; /* Constrain loop region to timescale area */
413
- `,Dr=D.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
423
+ `,Or=R.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
414
424
  position: relative;
415
425
  background: ${e=>e.$backgroundColor||"transparent"};
416
426
  width: 100%;
417
- `,Br=D.div`
427
+ `,Gr=R.div`
418
428
  position: absolute;
419
429
  top: 0;
420
430
  left: 0;
@@ -423,7 +433,7 @@
423
433
  cursor: crosshair;
424
434
  /* When selecting, raise z-index above clip boundaries (z-index: 105) to prevent interference */
425
435
  z-index: ${e=>e.$isSelecting?110:1};
426
- `,qt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:o,scrollContainerWidth:i,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:f,onTracksMouseUp:v,scrollContainerRef:h,isSelecting:d,"data-playlist-state":C})=>{const y=s.useRef(null),p=s.useCallback(m=>{y.current=m,h?.(m)},[h]);return g.jsx($r,{"data-scroll-container":"true","data-playlist-state":C,ref:p,children:g.jsx(dr,{containerRef:y,children:g.jsxs(Tr,{$backgroundColor:t,$width:i,children:[a&&g.jsx(Rr,{$width:r,$backgroundColor:n,children:a}),g.jsxs(Dr,{$width:o,$backgroundColor:t,children:[e,(c||u)&&g.jsx(Br,{$controlsWidth:l,$isSelecting:d,onClick:c,onMouseDown:u,onMouseMove:f,onMouseUp:v})]})]})})})};D.withTheme(qt);var Fr=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
436
+ `,Qt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:s,scrollContainerWidth:i,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:m,onTracksMouseUp:h,scrollContainerRef:p,isSelecting:f,"data-playlist-state":b})=>{const w=o.useRef(null),g=o.useCallback(d=>{w.current=d,p?.(d)},[p]);return v.jsx(zr,{"data-scroll-container":"true","data-playlist-state":b,ref:g,children:v.jsx(yr,{containerRef:w,children:v.jsxs(Hr,{$backgroundColor:t,$width:i,children:[a&&v.jsx(Xr,{$width:r,$backgroundColor:n,children:a}),v.jsxs(Or,{$width:s,$backgroundColor:t,children:[e,(c||u)&&v.jsx(Gr,{$controlsWidth:l,$isSelecting:f,onClick:c,onMouseDown:u,onMouseMove:m,onMouseUp:h})]})]})})})};R.withTheme(Qt);var Nr=R.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
427
437
  position: absolute;
428
438
  top: 0;
429
439
  background: ${e=>e.$color};
@@ -431,14 +441,14 @@
431
441
  z-index: 60; /* Above clips (z-index: 10) and fades (z-index: 50), below playhead (z-index: 100) */
432
442
  pointer-events: none;
433
443
  opacity: 0.3;
434
- `,na=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const a=Math.max(0,t-e);return a<=0?null:g.jsx(Fr,{$left:e,$width:a,$color:n,"data-selection":!0})};D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
444
+ `,da=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const a=Math.max(0,t-e);return a<=0?null:v.jsx(Nr,{$left:e,$width:a,$color:n,"data-selection":!0})};R.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
435
445
  position: absolute;
436
446
  top: 0;
437
447
  background: ${e=>e.$color};
438
448
  height: 100%;
439
449
  z-index: 55; /* Between clips (z-index: 50) and selection (z-index: 60) */
440
450
  pointer-events: none;
441
- `;D.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
451
+ `;R.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
442
452
  position: absolute;
443
453
  top: 0;
444
454
  width: 2px;
@@ -458,7 +468,7 @@
458
468
  border-top: 8px solid ${e=>e.$color};
459
469
  ${e=>e.$isStart?"border-right: 8px solid transparent;":"border-left: 8px solid transparent;"}
460
470
  }
461
- `;var Mn=D.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
471
+ `;var Tn=R.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
462
472
  position: absolute;
463
473
  top: 0;
464
474
  width: 12px;
@@ -495,7 +505,7 @@
495
505
  &:hover::before {
496
506
  opacity: 1;
497
507
  }
498
- `,Wr=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
508
+ `,Yr=R.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
499
509
  position: absolute;
500
510
  top: 0;
501
511
  height: 100%;
@@ -506,26 +516,26 @@
506
516
  &:active {
507
517
  cursor: grabbing;
508
518
  }
509
- `,Pr=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:o,onLoopRegionMove:i,minPosition:l=0,maxPosition:c=1/0})=>{const[u,f]=s.useState(null),v=s.useRef(0),h=s.useRef(0),d=s.useRef(0),C=Math.max(0,t-e),y=s.useCallback((m,k)=>{m.preventDefault(),m.stopPropagation(),f(k),v.current=m.clientX,h.current=k==="start"?e:t;const w=x=>{const S=x.clientX-v.current,E=h.current+S;if(k==="start"){const I=Math.max(l,Math.min(t-10,E));r?.(I)}else{const I=Math.max(e+10,Math.min(c,E));o?.(I)}},b=()=>{f(null),document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",b)};document.addEventListener("mousemove",w),document.addEventListener("mouseup",b)},[e,t,l,c,r,o]),p=s.useCallback(m=>{m.preventDefault(),m.stopPropagation(),f("region"),v.current=m.clientX,h.current=e,d.current=t;const k=t-e,w=x=>{const S=x.clientX-v.current;let E=h.current+S,I=d.current+S;E<l&&(E=l,I=l+k),I>c&&(I=c,E=c-k),i?.(E,I)},b=()=>{f(null),document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",b)};document.addEventListener("mousemove",w),document.addEventListener("mouseup",b)},[e,t,l,c,i]);return C<=0?null:g.jsxs(g.Fragment,{children:[g.jsx(Wr,{$left:e,$width:C,$color:a,$isDragging:u==="region",onMouseDown:p,"data-loop-region-timescale":!0}),g.jsx(Mn,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:m=>y(m,"start"),"data-loop-marker-handle":"start"}),g.jsx(Mn,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:m=>y(m,"end"),"data-loop-marker-handle":"end"})]})},Zr=D.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
519
+ `,Ur=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:s,onLoopRegionMove:i,minPosition:l=0,maxPosition:c=1/0})=>{const[u,m]=o.useState(null),h=o.useRef(0),p=o.useRef(0),f=o.useRef(0),b=Math.max(0,t-e),w=o.useCallback((d,x)=>{d.preventDefault(),d.stopPropagation(),m(x),h.current=d.clientX,p.current=x==="start"?e:t;const y=k=>{const S=k.clientX-h.current,M=p.current+S;if(x==="start"){const A=Math.max(l,Math.min(t-10,M));r?.(A)}else{const A=Math.max(e+10,Math.min(c,M));s?.(A)}},C=()=>{m(null),document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",C)};document.addEventListener("mousemove",y),document.addEventListener("mouseup",C)},[e,t,l,c,r,s]),g=o.useCallback(d=>{d.preventDefault(),d.stopPropagation(),m("region"),h.current=d.clientX,p.current=e,f.current=t;const x=t-e,y=k=>{const S=k.clientX-h.current;let M=p.current+S,A=f.current+S;M<l&&(M=l,A=l+x),A>c&&(A=c,M=c-x),i?.(M,A)},C=()=>{m(null),document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",C)};document.addEventListener("mousemove",y),document.addEventListener("mouseup",C)},[e,t,l,c,i]);return b<=0?null:v.jsxs(v.Fragment,{children:[v.jsx(Yr,{$left:e,$width:b,$color:a,$isDragging:u==="region",onMouseDown:g,"data-loop-region-timescale":!0}),v.jsx(Tn,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:d=>w(d,"start"),"data-loop-marker-handle":"start"}),v.jsx(Tn,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:d=>w(d,"end"),"data-loop-marker-handle":"end"})]})},Kr=R.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
510
520
  position: absolute;
511
521
  top: 0;
512
522
  right: 0;
513
523
  height: 100%; /* Stay within timescale bounds, don't extend into tracks */
514
524
  cursor: crosshair;
515
525
  z-index: 40; /* Below markers and shading */
516
- `,Vr=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:o=0,maxPosition:i=1/0,controlsOffset:l=0})=>{const[,c]=s.useState(!1),u=s.useRef(0),f=s.useRef(null),v=t>e,h=s.useCallback(d=>{const C=d.target;if(C.closest("[data-loop-marker-handle]")||C.closest("[data-loop-region-timescale]"))return;d.preventDefault(),c(!0);const y=f.current?.getBoundingClientRect();if(!y)return;const p=d.clientX-y.left,m=Math.max(o,Math.min(i,p));u.current=m,r?.(m,m);const k=b=>{const x=b.clientX-y.left,S=Math.max(o,Math.min(i,x)),E=Math.min(u.current,S),I=Math.max(u.current,S);r?.(E,I)},w=()=>{c(!1),document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",k),document.addEventListener("mouseup",w)},[o,i,r]);return g.jsx(Zr,{ref:f,$leftOffset:l,onMouseDown:h,"data-timescale-loop-creator":!0,children:v&&g.jsx(Pr,{startPosition:e,endPosition:t,markerColor:n,regionColor:a,minPosition:o,maxPosition:i,onLoopStartChange:d=>r?.(d,t),onLoopEndChange:d=>r?.(e,d),onLoopRegionMove:(d,C)=>r?.(d,C)})})};function pt(e,t){const n=Math.floor(e/3600)%24,a=Math.floor(e/60)%60,r=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(a).padStart(2,"0")+":"+r.padStart(t+3,"0")}function mt(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return pt(e,0);case"hh:mm:ss.u":return pt(e,1);case"hh:mm:ss.uu":return pt(e,2);case"hh:mm:ss.uuu":return pt(e,3);default:return pt(e,3)}}function aa(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const a=parseInt(n[0],10)||0,r=parseInt(n[1],10)||0,o=parseFloat(n[2])||0;return a*3600+r*60+o}default:return 0}}var _n=({id:e,label:t,value:n,format:a,className:r,onChange:o,readOnly:i=!1})=>{const[l,c]=s.useState("");s.useEffect(()=>{const h=mt(n,a);c(h)},[n,a,e]);const u=h=>{const d=h.target.value;c(d)},f=()=>{if(o){const h=aa(l,a);o(h)}c(mt(n,a))},v=h=>{h.key==="Enter"&&h.currentTarget.blur()};return g.jsxs(g.Fragment,{children:[g.jsx(ir,{as:"label",htmlFor:e,children:t}),g.jsx(Gn,{type:"text",className:r,id:e,value:l,onChange:u,onBlur:f,onKeyDown:v,readOnly:i})]})},jr=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:a})=>{const[r,o]=s.useState("hh:mm:ss.uuu");s.useEffect(()=>{const c=document.querySelector(".time-format"),u=()=>{c&&o(c.value)};return c&&(o(c.value),c.addEventListener("change",u)),()=>{c?.removeEventListener("change",u)}},[]);const i=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return g.jsxs("div",{className:a,children:[g.jsx(_n,{id:"audio_start",label:"Start of audio selection",value:e,format:r,className:"audio-start form-control mr-sm-2",onChange:i}),g.jsx(_n,{id:"audio_end",label:"End of audio selection",value:t,format:r,className:"audio-end form-control mr-sm-2",onChange:l})]})};function $t(){return window.devicePixelRatio}var ra=s.createContext($t()),sa=({children:e})=>{const[t,n]=s.useState($t());return matchMedia(`(resolution: ${$t()}dppx)`).addEventListener("change",()=>{n($t())},{once:!0}),g.jsx(ra.Provider,{value:Math.ceil(t),children:e})},Jt=()=>s.useContext(ra),yt=s.createContext({sampleRate:48e3,samplesPerPixel:1e3,zoomLevels:[1e3,1500,2e3,2500],waveHeight:80,timeScaleHeight:15,controls:{show:!1,width:150},duration:3e4,barWidth:1,barGap:0}),Bt=()=>s.useContext(yt),Ct=()=>s.useContext(D.ThemeContext),Qt=s.createContext(g.jsx(s.Fragment,{})),Lr=()=>s.useContext(Qt),zr=0,Hr=!1,Xr=0,Or=0,Nr={progress:zr,isPlaying:Hr,selectionStart:Xr,selectionEnd:Or};s.createContext(Nr);s.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var Gr=(e,t,n)=>(e-t)/(n-t),Yr=D.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
526
+ `,qr=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:s=0,maxPosition:i=1/0,controlsOffset:l=0})=>{const[,c]=o.useState(!1),u=o.useRef(0),m=o.useRef(null),h=t>e,p=o.useCallback(f=>{const b=f.target;if(b.closest("[data-loop-marker-handle]")||b.closest("[data-loop-region-timescale]"))return;f.preventDefault(),c(!0);const w=m.current?.getBoundingClientRect();if(!w)return;const g=f.clientX-w.left,d=Math.max(s,Math.min(i,g));u.current=d,r?.(d,d);const x=C=>{const k=C.clientX-w.left,S=Math.max(s,Math.min(i,k)),M=Math.min(u.current,S),A=Math.max(u.current,S);r?.(M,A)},y=()=>{c(!1),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",y)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",y)},[s,i,r]);return v.jsx(Kr,{ref:m,$leftOffset:l,onMouseDown:p,"data-timescale-loop-creator":!0,children:h&&v.jsx(Ur,{startPosition:e,endPosition:t,markerColor:n,regionColor:a,minPosition:s,maxPosition:i,onLoopStartChange:f=>r?.(f,t),onLoopEndChange:f=>r?.(e,f),onLoopRegionMove:(f,b)=>r?.(f,b)})})};function pt(e,t){const n=Math.floor(e/3600)%24,a=Math.floor(e/60)%60,r=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(a).padStart(2,"0")+":"+r.padStart(t+3,"0")}function mt(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return pt(e,0);case"hh:mm:ss.u":return pt(e,1);case"hh:mm:ss.uu":return pt(e,2);case"hh:mm:ss.uuu":return pt(e,3);default:return pt(e,3)}}function fa(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const a=parseInt(n[0],10)||0,r=parseInt(n[1],10)||0,s=parseFloat(n[2])||0;return a*3600+r*60+s}default:return 0}}var Rn=({id:e,label:t,value:n,format:a,className:r,onChange:s,readOnly:i=!1})=>{const[l,c]=o.useState("");o.useEffect(()=>{const p=mt(n,a);c(p)},[n,a,e]);const u=p=>{const f=p.target.value;c(f)},m=()=>{if(s){const p=fa(l,a);s(p)}c(mt(n,a))},h=p=>{p.key==="Enter"&&p.currentTarget.blur()};return v.jsxs(v.Fragment,{children:[v.jsx(br,{as:"label",htmlFor:e,children:t}),v.jsx(ea,{type:"text",className:r,id:e,value:l,onChange:u,onBlur:m,onKeyDown:h,readOnly:i})]})},Jr=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:a})=>{const[r,s]=o.useState("hh:mm:ss.uuu");o.useEffect(()=>{const c=document.querySelector(".time-format"),u=()=>{c&&s(c.value)};return c&&(s(c.value),c.addEventListener("change",u)),()=>{c?.removeEventListener("change",u)}},[]);const i=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return v.jsxs("div",{className:a,children:[v.jsx(Rn,{id:"audio_start",label:"Start of audio selection",value:e,format:r,className:"audio-start form-control mr-sm-2",onChange:i}),v.jsx(Rn,{id:"audio_end",label:"End of audio selection",value:t,format:r,className:"audio-end form-control mr-sm-2",onChange:l})]})};function $t(){return window.devicePixelRatio}var ma=o.createContext($t()),ha=({children:e})=>{const[t,n]=o.useState($t());return matchMedia(`(resolution: ${$t()}dppx)`).addEventListener("change",()=>{n($t())},{once:!0}),v.jsx(ma.Provider,{value:Math.ceil(t),children:e})},en=()=>o.useContext(ma),Ct=o.createContext({sampleRate:48e3,samplesPerPixel:1e3,zoomLevels:[1e3,1500,2e3,2500],waveHeight:80,timeScaleHeight:15,controls:{show:!1,width:150},duration:3e4,barWidth:1,barGap:0}),Bt=()=>o.useContext(Ct),wt=()=>o.useContext(R.ThemeContext),tn=o.createContext(v.jsx(o.Fragment,{})),Qr=()=>o.useContext(tn),eo=0,to=!1,no=0,ao=0,ro={progress:eo,isPlaying:to,selectionStart:no,selectionEnd:ao};o.createContext(ro);o.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var oo=(e,t,n)=>(e-t)/(n-t),so=R.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
517
527
  position: absolute;
518
528
  background: #000;
519
529
  transform: translateZ(0);
520
530
  backface-visibility: hidden;
521
- `,Kr=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
531
+ `,io=R.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
522
532
  position: absolute;
523
533
  top: 0;
524
534
  /* Promote to own compositing layer for smoother scrolling */
525
535
  will-change: transform;
526
536
  image-rendering: pixelated;
527
537
  image-rendering: crisp-edges;
528
- `;function Ur(){const e=new Uint8Array(768);for(let t=0;t<256;t++)e[t*3]=e[t*3+1]=e[t*3+2]=t;return e}var qr=Ur(),En=({index:e,channelIndex:t,data:n,length:a,waveHeight:r,devicePixelRatio:o=1,samplesPerPixel:i,colorLUT:l,frequencyScaleFn:c,minFrequency:u=0,maxFrequency:f,workerApi:v,clipId:h,onCanvasesReady:d})=>{const C=t??e,y=s.useRef([]),p=s.useRef([]),m=s.useRef(new WeakSet),k=s.useRef(v),w=s.useRef(d),b=!!(v&&h),x=Ut(_=>{const R=Math.ceil(a/pe),W=[];for(let L=0;L<R;L++){const P=L*pe,U=Math.min(a-P,pe);_&&(P+U<=_.visibleStart||P>=_.visibleEnd)||W.push(L)}return W.join(",")}),S=x?x.split(",").map(Number):[],E=s.useCallback(_=>{if(_!==null){const R=parseInt(_.dataset.index,10);y.current[R]=_}},[]),I=l??qr,$=f??(n?n.sampleRate/2:22050),M=c??Gr,A=!!c;s.useEffect(()=>{k.current=v},[v]),s.useEffect(()=>{w.current=d},[d]),s.useEffect(()=>{if(!b)return;const _=k.current;if(!_||!h)return;const R=y.current,W=[],L=[];for(let P=0;P<R.length;P++){const U=R[P];if(!U||m.current.has(U))continue;const H=parseInt(U.dataset.index,10),ne=`${h}-ch${C}-chunk${H}`;let le;try{le=U.transferControlToOffscreen()}catch(se){console.warn(`[spectrogram] transferControlToOffscreen failed for ${ne}:`,se);continue}m.current.add(U);try{_.registerCanvas(ne,le),W.push(ne),L.push(Math.min(a-H*pe,pe))}catch(se){console.warn(`[spectrogram] registerCanvas failed for ${ne}:`,se);continue}}W.length>0&&(p.current=[...p.current,...W],w.current?.(W,L))},[b,h,C,a,x]),s.useEffect(()=>{if(!b)return;const _=k.current;if(!_)return;const R=[];for(const W of p.current){const L=W.match(/chunk(\d+)$/);if(!L){R.push(W);continue}const P=parseInt(L[1],10),U=y.current[P];if(U&&U.isConnected)R.push(W);else try{_.unregisterCanvas(W)}catch(H){console.warn(`[spectrogram] unregisterCanvas failed for ${W}:`,H)}}p.current=R}),s.useEffect(()=>()=>{const _=k.current;if(_){for(const R of p.current)try{_.unregisterCanvas(R)}catch(W){console.warn(`[spectrogram] unregisterCanvas failed for ${R}:`,W)}p.current=[]}},[]),s.useLayoutEffect(()=>{if(b||!n)return;const _=y.current,{frequencyBinCount:R,frameCount:W,hopSize:L,sampleRate:P,gainDb:U,rangeDb:H}=n,ne=H===0?1:H,le=se=>se/R*(P/2);for(let se=0;se<_.length;se++){const oe=_[se];if(!oe)continue;const ce=parseInt(oe.dataset.index,10)*pe,fe=oe.getContext("2d");if(!fe)continue;const O=oe.width/o,N=r;fe.resetTransform(),fe.clearRect(0,0,oe.width,oe.height),fe.imageSmoothingEnabled=!1,fe.scale(o,o);const be=fe.createImageData(O,N),K=be.data;for(let z=0;z<O;z++){const Ie=(ce+z)*i,ae=Math.floor(Ie/L);if(ae<0||ae>=W)continue;const Te=ae*R;for(let He=0;He<N;He++){const Ye=1-He/N;let Xe=Math.floor(Ye*R);if(A){let ie=0,Le=R-1;for(;ie<Le;){const Ae=ie+Le>>1,De=le(Ae);M(De,u,$)<Ye?ie=Ae+1:Le=Ae}Xe=ie}if(Xe<0||Xe>=R)continue;const Q=n.data[Te+Xe],Ke=Math.max(0,Math.min(1,(Q+ne+U)/ne)),Z=Math.floor(Ke*255),ue=(He*O+z)*4;K[ue]=I[Z*3],K[ue+1]=I[Z*3+1],K[ue+2]=I[Z*3+2],K[ue+3]=255}}if(fe.resetTransform(),fe.putImageData(be,0,0),o!==1){const z=document.createElement("canvas");z.width=O,z.height=N;const me=z.getContext("2d");if(!me)continue;me.putImageData(be,0,0),fe.clearRect(0,0,oe.width,oe.height),fe.imageSmoothingEnabled=!1,fe.drawImage(z,0,0,oe.width,oe.height)}}},[b,n,a,r,o,i,I,u,$,M,A,x]);const B=S.map(_=>{const R=_*pe,W=Math.min(a-R,pe);return g.jsx(Kr,{$cssWidth:W,$left:R,width:W*o,height:r*o,$waveHeight:r,"data-index":_,ref:E},`${a}-${_}`)});return g.jsx(Yr,{$index:e,$cssWidth:a,$waveHeight:r,children:B})},oa=({isSelected:e,transparentBackground:t,renderMode:n="waveform",spectrogramData:a,spectrogramColorLUT:r,samplesPerPixel:o,spectrogramFrequencyScaleFn:i,spectrogramMinFrequency:l,spectrogramMaxFrequency:c,spectrogramWorkerApi:u,spectrogramClipId:f,spectrogramOnCanvasesReady:v,...h})=>{const d=Ct(),{waveHeight:C,barWidth:y,barGap:p,samplesPerPixel:m}=Bt(),k=Jt(),w=o??m,b=e&&d?d.selectedWaveOutlineColor:d?.waveOutlineColor,x=e&&d?d.selectedWaveFillColor:d?.waveFillColor,S=d?.waveformDrawMode||"inverted",E=a||u;if(n==="spectrogram"&&E)return g.jsx(En,{index:h.index,data:a,length:h.length,waveHeight:C,devicePixelRatio:k,samplesPerPixel:w,colorLUT:r,frequencyScaleFn:i,minFrequency:l,maxFrequency:c,workerApi:u,clipId:f,onCanvasesReady:v});if(n==="both"&&E){const I=Math.floor(C/2);return g.jsxs(g.Fragment,{children:[g.jsx(En,{index:h.index*2,channelIndex:h.index,data:a,length:h.length,waveHeight:I,devicePixelRatio:k,samplesPerPixel:w,colorLUT:r,frequencyScaleFn:i,minFrequency:l,maxFrequency:c,workerApi:u,clipId:f,onCanvasesReady:v}),g.jsx("div",{style:{position:"absolute",top:(h.index*2+1)*I,width:h.length,height:I},children:g.jsx(Sn,{...h,index:0,waveOutlineColor:b,waveFillColor:x,waveHeight:I,devicePixelRatio:k,barWidth:y,barGap:p,transparentBackground:t,drawMode:S})})]})}return g.jsx(Sn,{...h,waveOutlineColor:b,waveFillColor:x,waveHeight:C,devicePixelRatio:k,barWidth:y,barGap:p,transparentBackground:t,drawMode:S})},$n=72,Jr=D.div`
538
+ `;function lo(){const e=new Uint8Array(768);for(let t=0;t<256;t++)e[t*3]=e[t*3+1]=e[t*3+2]=t;return e}var co=lo(),Dn=({index:e,channelIndex:t,data:n,length:a,waveHeight:r,devicePixelRatio:s=1,samplesPerPixel:i,colorLUT:l,frequencyScaleFn:c,minFrequency:u=0,maxFrequency:m,workerApi:h,clipId:p,onCanvasesReady:f})=>{const b=t??e,{canvasRef:w,canvasMapRef:g}=Jt(),d=o.useRef([]),x=o.useRef(new WeakSet),y=o.useRef(h),C=o.useRef(f),k=!!(h&&p),S=ia(),M=qt(a,ke,S),A=l??co,E=m??(n?n.sampleRate/2:22050),_=c??oo,I=!!c;o.useEffect(()=>{y.current=h},[h]),o.useEffect(()=>{C.current=f},[f]),o.useEffect(()=>{if(!k)return;const $=y.current;if(!$||!p)return;const W=d.current.length,z=[];for(const N of d.current){const L=N.match(/chunk(\d+)$/);if(!L){z.push(N);continue}const ae=parseInt(L[1],10),oe=g.current.get(ae);if(oe&&oe.isConnected)z.push(N);else try{$.unregisterCanvas(N)}catch(q){console.warn(`[spectrogram] unregisterCanvas failed for ${N}:`,q)}}d.current=z;const Y=[];for(const[N,L]of g.current.entries()){if(x.current.has(L))continue;const ae=`${p}-ch${b}-chunk${N}`;let oe;try{oe=L.transferControlToOffscreen()}catch(q){console.warn(`[spectrogram] transferControlToOffscreen failed for ${ae}:`,q);continue}x.current.add(L);try{$.registerCanvas(ae,oe),Y.push(ae)}catch(q){console.warn(`[spectrogram] registerCanvas failed for ${ae}:`,q);continue}}if(Y.length>0&&(d.current=[...d.current,...Y]),Y.length>0||z.length<W){const N=d.current,L=N.map(ae=>{const oe=ae.match(/chunk(\d+)$/);if(!oe)return console.warn(`[spectrogram] Unexpected canvas ID format: ${ae}`),ke;const q=parseInt(oe[1],10);return Math.min(a-q*ke,ke)});C.current?.(N,L)}},[g,k,p,b,a,M]),o.useEffect(()=>()=>{const $=y.current;if($){for(const W of d.current)try{$.unregisterCanvas(W)}catch(z){console.warn(`[spectrogram] unregisterCanvas failed for ${W}:`,z)}d.current=[]}},[]),o.useLayoutEffect(()=>{if(k||!n)return;const{frequencyBinCount:$,frameCount:W,hopSize:z,sampleRate:Y,gainDb:j,rangeDb:N}=n,L=N===0?1:N,ae=oe=>oe/$*(Y/2);for(const[oe,q]of g.current.entries()){const fe=oe*ke,ue=q.getContext("2d");if(!ue)continue;const le=q.width/s,Ee=r;ue.resetTransform(),ue.clearRect(0,0,q.width,q.height),ue.imageSmoothingEnabled=!1,ue.scale(s,s);const P=ue.createImageData(le,Ee),ee=P.data;for(let U=0;U<le;U++){const ie=(fe+U)*i,he=Math.floor(ie/z);if(he<0||he>=W)continue;const te=he*$;for(let Se=0;Se<Ee;Se++){const Be=1-Se/Ee;let Xe=Math.floor(Be*$);if(I){let F=0,ye=$-1;for(;F<ye;){const ce=F+ye>>1,je=ae(ce);_(je,u,E)<Be?F=ce+1:ye=ce}Xe=F}if(Xe<0||Xe>=$)continue;const qe=n.data[te+Xe],ne=Math.max(0,Math.min(1,(qe+L+j)/L)),Ve=Math.floor(ne*255),Oe=(Se*le+U)*4;ee[Oe]=A[Ve*3],ee[Oe+1]=A[Ve*3+1],ee[Oe+2]=A[Ve*3+2],ee[Oe+3]=255}}if(ue.resetTransform(),ue.putImageData(P,0,0),s!==1){const U=document.createElement("canvas");U.width=le,U.height=Ee;const K=U.getContext("2d");if(!K)continue;K.putImageData(P,0,0),ue.clearRect(0,0,q.width,q.height),ue.imageSmoothingEnabled=!1,ue.drawImage(U,0,0,q.width,q.height)}}},[g,k,n,a,r,s,i,A,u,E,_,I,M]);const B=M.map($=>{const W=$*ke,z=Math.min(a-W,ke);return v.jsx(io,{$cssWidth:z,$left:W,width:z*s,height:r*s,$waveHeight:r,"data-index":$,ref:w},`${a}-${$}`)});return v.jsx(so,{$index:e,$cssWidth:a,$waveHeight:r,children:B})},pa=({isSelected:e,transparentBackground:t,renderMode:n="waveform",spectrogramData:a,spectrogramColorLUT:r,samplesPerPixel:s,spectrogramFrequencyScaleFn:i,spectrogramMinFrequency:l,spectrogramMaxFrequency:c,spectrogramWorkerApi:u,spectrogramClipId:m,spectrogramOnCanvasesReady:h,...p})=>{const f=wt(),{waveHeight:b,barWidth:w,barGap:g,samplesPerPixel:d}=Bt(),x=en(),y=s??d,C=e&&f?f.selectedWaveOutlineColor:f?.waveOutlineColor,k=e&&f?f.selectedWaveFillColor:f?.waveFillColor,S=f?.waveformDrawMode||"inverted",M=a||u;if(n==="spectrogram"&&M)return v.jsx(Dn,{index:p.index,data:a,length:p.length,waveHeight:b,devicePixelRatio:x,samplesPerPixel:y,colorLUT:r,frequencyScaleFn:i,minFrequency:l,maxFrequency:c,workerApi:u,clipId:m,onCanvasesReady:h});if(n==="both"&&M){const A=Math.floor(b/2);return v.jsxs(v.Fragment,{children:[v.jsx(Dn,{index:p.index*2,channelIndex:p.index,data:a,length:p.length,waveHeight:A,devicePixelRatio:x,samplesPerPixel:y,colorLUT:r,frequencyScaleFn:i,minFrequency:l,maxFrequency:c,workerApi:u,clipId:m,onCanvasesReady:h}),v.jsx("div",{style:{position:"absolute",top:(p.index*2+1)*A,width:p.length,height:A},children:v.jsx(_n,{...p,index:0,waveOutlineColor:C,waveFillColor:k,waveHeight:A,devicePixelRatio:x,barWidth:w,barGap:g,transparentBackground:t,drawMode:S})})]})}return v.jsx(_n,{...p,waveOutlineColor:C,waveFillColor:k,waveHeight:b,devicePixelRatio:x,barWidth:w,barGap:g,transparentBackground:t,drawMode:S})},Bn=72,uo=R.div`
529
539
  position: sticky;
530
540
  left: 0;
531
541
  z-index: 101;
@@ -533,34 +543,34 @@
533
543
  height: 0;
534
544
  width: 0;
535
545
  overflow: visible;
536
- `;function Qr(e,t,n){const r=[20,50,100,200,500,1e3,2e3,3e3,4e3,5e3,8e3,1e4,12e3,16e3,2e4].filter(c=>c>=e&&c<=t),o=Math.max(2,Math.floor(n/20));if(r.length<=o)return r;const i=(r.length-1)/(o-1),l=[];for(let c=0;c<o;c++)l.push(r[Math.round(c*i)]);return l}var es=({waveHeight:e,numChannels:t,frequencyScaleFn:n,minFrequency:a,maxFrequency:r,labelsColor:o="#ccc",labelsBackground:i="rgba(0,0,0,0.6)",renderMode:l="spectrogram",hasClipHeaders:c=!1})=>{const u=s.useRef(null),f=Jt(),v=l==="both"?Math.floor(e/2):e,h=t*e,d=c?22:0;return s.useLayoutEffect(()=>{const C=u.current;if(!C)return;const y=C.getContext("2d");if(!y)return;y.resetTransform(),y.clearRect(0,0,C.width,C.height),y.scale(f,f);const p=Qr(a,r,v);for(let m=0;m<t;m++){const k=m*e+d;y.font="11px monospace",y.textBaseline="middle";for(const w of p){const b=n(w,a,r);if(b<0||b>1)continue;const x=k+v*(1-b),S=w>=1e3?`${(w/1e3).toFixed(1)}k`:`${w} Hz`,E=y.measureText(S),I=3;y.fillStyle=i,y.fillRect(0,x-7,E.width+I*2,14),y.fillStyle=o,y.fillText(S,I,x)}}},[e,t,n,a,r,o,i,f,v,d]),g.jsx(Jr,{$height:h+d,children:g.jsx("canvas",{ref:u,width:$n*f,height:(h+d)*f,style:{width:$n,height:h+d,pointerEvents:"none"}})})};function ts(e,t,n){return Math.ceil(e*n/t)}function ns(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var as=D.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
546
+ `;function fo(e,t,n){const r=[20,50,100,200,500,1e3,2e3,3e3,4e3,5e3,8e3,1e4,12e3,16e3,2e4].filter(c=>c>=e&&c<=t),s=Math.max(2,Math.floor(n/20));if(r.length<=s)return r;const i=(r.length-1)/(s-1),l=[];for(let c=0;c<s;c++)l.push(r[Math.round(c*i)]);return l}var mo=({waveHeight:e,numChannels:t,frequencyScaleFn:n,minFrequency:a,maxFrequency:r,labelsColor:s="#ccc",labelsBackground:i="rgba(0,0,0,0.6)",renderMode:l="spectrogram",hasClipHeaders:c=!1})=>{const u=o.useRef(null),m=en(),h=l==="both"?Math.floor(e/2):e,p=t*e,f=c?22:0;return o.useLayoutEffect(()=>{const b=u.current;if(!b)return;const w=b.getContext("2d");if(!w)return;w.resetTransform(),w.clearRect(0,0,b.width,b.height),w.scale(m,m);const g=fo(a,r,h);for(let d=0;d<t;d++){const x=d*e+f;w.font="11px monospace",w.textBaseline="middle";for(const y of g){const C=n(y,a,r);if(C<0||C>1)continue;const k=x+h*(1-C),S=y>=1e3?`${(y/1e3).toFixed(1)}k`:`${y} Hz`,M=w.measureText(S),A=3;w.fillStyle=i,w.fillRect(0,k-7,M.width+A*2,14),w.fillStyle=s,w.fillText(S,A,k)}}},[e,t,n,a,r,s,i,m,h,f]),v.jsx(uo,{$height:p+f,children:v.jsx("canvas",{ref:u,width:Bn*m,height:(p+f)*m,style:{width:Bn,height:p+f,pointerEvents:"none"}})})};function ho(e,t,n){return Math.ceil(e*n/t)}function po(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var go=R.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
537
547
  position: relative;
538
548
  overflow: visible; /* Allow time labels to render above the container */
539
549
  border-bottom: 1px solid ${e=>e.theme.timeColor};
540
550
  box-sizing: border-box;
541
- `,rs=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`,left:`${e.$left}px`}}))`
551
+ `,bo=R.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`,left:`${e.$left}px`}}))`
542
552
  position: absolute;
543
553
  bottom: 0;
544
554
  /* Promote to own compositing layer for smoother scrolling */
545
555
  will-change: transform;
546
- `,ss=D.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
556
+ `,vo=R.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
547
557
  position: absolute;
548
558
  font-size: 0.75rem; /* Smaller font to prevent overflow */
549
559
  white-space: nowrap; /* Prevent text wrapping */
550
560
  color: ${e=>e.theme.timeColor}; /* Use theme color instead of inheriting */
551
- `,os=e=>{const{theme:{timeColor:t},duration:n,marker:a,bigStep:r,secondStep:o,renderTimestamp:i}=e,l=s.useRef(new Map),{sampleRate:c,samplesPerPixel:u,timeScaleHeight:f,controls:{show:v,width:h}}=s.useContext(yt),d=Jt(),C=s.useCallback(I=>{if(I!==null){const $=parseInt(I.dataset.index,10);l.current.set($,I)}},[]),{widthX:y,canvasInfo:p,timeMarkersWithPositions:m}=s.useMemo(()=>{const I=new Map,$=[],M=ts(n/1e3,u,c),A=c/u;let B=0;for(let _=0;_<M;_+=A*o/1e3){const R=Math.floor(_);if(B%a===0){const W=B,L=ns(W),P=i?g.jsx(s.Fragment,{children:i(W,R)},`timestamp-${B}`):g.jsx(ss,{$left:R,children:L},L);$.push({pix:R,element:P}),I.set(R,f)}else B%r===0?I.set(R,Math.floor(f/2)):B%o===0&&I.set(R,Math.floor(f/5));B+=o}return{widthX:M,canvasInfo:I,timeMarkersWithPositions:$}},[n,u,c,a,r,o,i,f]),k=Ut(I=>{const $=Math.ceil(y/pe),M=[];for(let A=0;A<$;A++){const B=A*pe,_=Math.min(y-B,pe);I&&(B+_<=I.visibleStart||B>=I.visibleEnd)||M.push(A)}return M.join(",")}),w=k?k.split(",").map(Number):[],b=w.map(I=>{const $=I*pe,M=Math.min(y-$,pe);return g.jsx(rs,{$cssWidth:M,$left:$,$timeScaleHeight:f,width:M*d,height:f*d,"data-index":I,ref:C},`timescale-${I}`)}),x=w.length>0?w[0]*pe:0,S=w.length>0?(w[w.length-1]+1)*pe:1/0,E=w.length>0?m.filter(({pix:I})=>I>=x&&I<S).map(({element:I})=>I):m.map(({element:I})=>I);return s.useEffect(()=>{const I=l.current;for(const[$,M]of I.entries())M.isConnected||I.delete($)}),s.useLayoutEffect(()=>{for(const[I,$]of l.current.entries()){const M=$.getContext("2d");if(!M)continue;const A=I*pe,B=$.width/d;M.resetTransform(),M.clearRect(0,0,$.width,$.height),M.imageSmoothingEnabled=!1,M.fillStyle=t,M.scale(d,d);for(const[_,R]of p.entries()){if(_<A||_>=A+B)continue;const W=_-A,L=f-R;M.fillRect(W,L,1,R)}}},[n,d,t,f,p,k]),g.jsxs(as,{$cssWidth:y,$controlWidth:v?h:0,$timeScaleHeight:f,children:[E,b]})},is=D.withTheme(os),Tn=new Map([[700,{marker:1e3,bigStep:500,smallStep:100}],[1500,{marker:2e3,bigStep:1e3,smallStep:200}],[2500,{marker:2e3,bigStep:1e3,smallStep:500}],[5e3,{marker:5e3,bigStep:1e3,smallStep:500}],[1e4,{marker:1e4,bigStep:5e3,smallStep:1e3}],[12e3,{marker:15e3,bigStep:5e3,smallStep:1e3}],[1/0,{marker:3e4,bigStep:1e4,smallStep:5e3}]]);function ls(e){const t=Tn.keys();let n;for(const a of t)if(e<a){n=Tn.get(a);break}return n===void 0&&(n={marker:3e4,bigStep:1e4,smallStep:5e3}),n}var ia=({renderTimestamp:e})=>{const{samplesPerPixel:t,duration:n}=s.useContext(yt);let a=ls(t);return g.jsx(is,{marker:a.marker,bigStep:a.bigStep,secondStep:a.smallStep,duration:n,renderTimestamp:e})},cs=D.div`
561
+ `,Co=e=>{const{theme:{timeColor:t},duration:n,marker:a,bigStep:r,secondStep:s,renderTimestamp:i}=e,{canvasRef:l,canvasMapRef:c}=Jt(),{sampleRate:u,samplesPerPixel:m,timeScaleHeight:h,controls:{show:p,width:f}}=o.useContext(Ct),b=en(),{widthX:w,canvasInfo:g,timeMarkersWithPositions:d}=o.useMemo(()=>{const M=new Map,A=[],E=ho(n/1e3,m,u),_=u/m;let I=0;for(let B=0;B<E;B+=_*s/1e3){const $=Math.floor(B);if(I%a===0){const W=I,z=po(W),Y=i?v.jsx(o.Fragment,{children:i(W,$)},`timestamp-${I}`):v.jsx(vo,{$left:$,children:z},z);A.push({pix:$,element:Y}),M.set($,h)}else I%r===0?M.set($,Math.floor(h/2)):I%s===0&&M.set($,Math.floor(h/5));I+=s}return{widthX:E,canvasInfo:M,timeMarkersWithPositions:A}},[n,m,u,a,r,s,i,h]),x=qt(w,ke),y=x.map(M=>{const A=M*ke,E=Math.min(w-A,ke);return v.jsx(bo,{$cssWidth:E,$left:A,$timeScaleHeight:h,width:E*b,height:h*b,"data-index":M,ref:l},`timescale-${M}`)}),C=x.length>0?x[0]*ke:0,k=x.length>0?(x[x.length-1]+1)*ke:1/0,S=x.length>0?d.filter(({pix:M})=>M>=C&&M<k).map(({element:M})=>M):d.map(({element:M})=>M);return o.useLayoutEffect(()=>{for(const[M,A]of c.current.entries()){const E=A.getContext("2d");if(!E)continue;const _=M*ke,I=A.width/b;E.resetTransform(),E.clearRect(0,0,A.width,A.height),E.imageSmoothingEnabled=!1,E.fillStyle=t,E.scale(b,b);for(const[B,$]of g.entries()){if(B<_||B>=_+I)continue;const W=B-_,z=h-$;E.fillRect(W,z,1,$)}}},[c,n,b,t,h,g,x]),v.jsxs(go,{$cssWidth:w,$controlWidth:p?f:0,$timeScaleHeight:h,children:[S,y]})},wo=R.withTheme(Co),Fn=new Map([[700,{marker:1e3,bigStep:500,smallStep:100}],[1500,{marker:2e3,bigStep:1e3,smallStep:200}],[2500,{marker:2e3,bigStep:1e3,smallStep:500}],[5e3,{marker:5e3,bigStep:1e3,smallStep:500}],[1e4,{marker:1e4,bigStep:5e3,smallStep:1e3}],[12e3,{marker:15e3,bigStep:5e3,smallStep:1e3}],[1/0,{marker:3e4,bigStep:1e4,smallStep:5e3}]]);function yo(e){const t=Fn.keys();let n;for(const a of t)if(e<a){n=Fn.get(a);break}return n===void 0&&(n={marker:3e4,bigStep:1e4,smallStep:5e3}),n}var ga=({renderTimestamp:e})=>{const{samplesPerPixel:t,duration:n}=o.useContext(Ct);let a=yo(t);return v.jsx(wo,{marker:a.marker,bigStep:a.bigStep,secondStep:a.smallStep,duration:n,renderTimestamp:e})},xo=R.div`
552
562
  display: inline-flex;
553
563
  align-items: center;
554
564
  gap: 0.5rem;
555
- `,us=[{value:"seconds",label:"seconds"},{value:"thousandths",label:"thousandths"},{value:"hh:mm:ss",label:"hh:mm:ss"},{value:"hh:mm:ss.u",label:"hh:mm:ss + tenths"},{value:"hh:mm:ss.uu",label:"hh:mm:ss + hundredths"},{value:"hh:mm:ss.uuu",label:"hh:mm:ss + milliseconds"}],ds=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=o=>{t(o.target.value)};return g.jsx(cs,{className:a,children:g.jsx(Yn,{className:"time-format",value:e,onChange:r,disabled:n,"aria-label":"Time format selection",children:us.map(o=>g.jsx("option",{value:o.value,children:o.label},o.value))})})},fs=D.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?Qn:0)}px`}}))`
565
+ `,ko=[{value:"seconds",label:"seconds"},{value:"thousandths",label:"thousandths"},{value:"hh:mm:ss",label:"hh:mm:ss"},{value:"hh:mm:ss.u",label:"hh:mm:ss + tenths"},{value:"hh:mm:ss.uu",label:"hh:mm:ss + hundredths"},{value:"hh:mm:ss.uuu",label:"hh:mm:ss + milliseconds"}],So=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return v.jsx(xo,{className:a,children:v.jsx(ta,{className:"time-format",value:e,onChange:r,disabled:n,"aria-label":"Time format selection",children:ko.map(s=>v.jsx("option",{value:s.value,children:s.label},s.value))})})},Io=R.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?la:0)}px`}}))`
556
566
  position: relative;
557
567
  display: flex;
558
568
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
559
- `,ms=D.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
569
+ `,Ao=R.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
560
570
  position: relative;
561
571
  background: ${e=>e.$backgroundColor||"transparent"};
562
572
  flex: 1;
563
- `,hs=D.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
573
+ `,Mo=R.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
564
574
  position: sticky;
565
575
  z-index: 102; /* Above waveform content and spectrogram labels (101), below Docusaurus navbar (200) */
566
576
  left: 0;
@@ -574,7 +584,7 @@
574
584
  ${e=>e.$isSelected&&`
575
585
  background: ${e.theme.selectedTrackControlsBackground};
576
586
  `}
577
- `,la=({numChannels:e,children:t,className:n,backgroundColor:a,offset:r=0,width:o,hasClipHeaders:i=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:f,controls:{show:v,width:h}}=Bt(),d=Lr();return g.jsxs(fs,{$numChannels:e,className:n,$waveHeight:f,$controlWidth:v?h:0,$width:o,$hasClipHeaders:i,$isSelected:u,children:[g.jsx(hs,{$controlWidth:v?h:0,$isSelected:u,children:d}),g.jsx(ms,{$controlWidth:v?h:0,$backgroundColor:a,$offset:r,onClick:l,"data-track-id":c,children:t})]})},Rn=D.button.attrs({type:"button"})`
587
+ `,ba=({numChannels:e,children:t,className:n,backgroundColor:a,offset:r=0,width:s,hasClipHeaders:i=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:m,controls:{show:h,width:p}}=Bt(),f=Qr();return v.jsxs(Io,{$numChannels:e,className:n,$waveHeight:m,$controlWidth:h?p:0,$width:s,$hasClipHeaders:i,$isSelected:u,children:[v.jsx(Mo,{$controlWidth:h?p:0,$isSelected:u,children:f}),v.jsx(Ao,{$controlWidth:h?p:0,$backgroundColor:a,$offset:r,onClick:l,"data-track-id":c,children:t})]})},Wn=R.button.attrs({type:"button"})`
578
588
  display: inline-block;
579
589
  font-family: ${e=>e.theme.fontFamily};
580
590
  font-weight: 500;
@@ -585,8 +595,11 @@
585
595
  font-size: ${e=>e.theme.fontSizeSmall};
586
596
  line-height: 1;
587
597
  border-radius: ${e=>e.theme.borderRadius};
588
- transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
589
- border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
598
+ transition:
599
+ color 0.15s ease-in-out,
600
+ background-color 0.15s ease-in-out,
601
+ border-color 0.15s ease-in-out,
602
+ box-shadow 0.15s ease-in-out;
590
603
  cursor: pointer;
591
604
 
592
605
  ${e=>e.$variant==="danger"?`
@@ -633,7 +646,7 @@
633
646
  box-shadow: 0 0 0 0.2rem ${e.theme.inputFocusBorder}33;
634
647
  }
635
648
  `}
636
- `,ps=D.div`
649
+ `,_o=R.div`
637
650
  margin-bottom: 0.3rem;
638
651
 
639
652
  button:not(:first-child) {
@@ -645,7 +658,7 @@
645
658
  border-top-right-radius: 0;
646
659
  border-bottom-right-radius: 0;
647
660
  }
648
- `,gs=D.button`
661
+ `,Eo=R.button`
649
662
  position: absolute;
650
663
  left: 0;
651
664
  top: 0;
@@ -659,13 +672,15 @@
659
672
  align-items: center;
660
673
  justify-content: center;
661
674
  opacity: 0.7;
662
- transition: opacity 0.15s, color 0.15s;
675
+ transition:
676
+ opacity 0.15s,
677
+ color 0.15s;
663
678
 
664
679
  &:hover {
665
680
  opacity: 1;
666
681
  color: #dc3545;
667
682
  }
668
- `,bs=({onClick:e,title:t="Remove track"})=>g.jsx(gs,{onClick:e,title:t,children:g.jsx(nr,{size:12,weight:"bold"})}),vs=D.div`
683
+ `,$o=({onClick:e,title:t="Remove track"})=>v.jsx(Eo,{onClick:e,title:t,children:v.jsx(fr,{size:12,weight:"bold"})}),To=R.div`
669
684
  background: transparent;
670
685
  width: 100%;
671
686
  height: 100%;
@@ -678,7 +693,7 @@
678
693
  text-align: center;
679
694
  border: 1px solid ${e=>e.theme.borderColor};
680
695
  border-radius: ${e=>e.theme.borderRadius};
681
- `,ys=D.header`
696
+ `,Ro=R.header`
682
697
  overflow: hidden;
683
698
  height: 26px;
684
699
  width: 100%;
@@ -689,7 +704,7 @@
689
704
  font-size: ${e=>e.theme.fontSizeSmall};
690
705
  color: ${e=>e.theme.textColor};
691
706
  background-color: transparent;
692
- `,Cs=e=>g.jsx(On,{weight:"light",...e}),ws=e=>g.jsx(Xn,{weight:"light",...e}),xs=e=>g.jsx(Hn,{weight:"bold",...e}),Dn=D(Kn)`
707
+ `,Do=e=>v.jsx(Jn,{weight:"light",...e}),Bo=e=>v.jsx(qn,{weight:"light",...e}),Fo=e=>v.jsx(Kn,{weight:"bold",...e}),Pn=R(na)`
693
708
  width: 75%;
694
709
  height: 5px;
695
710
  background: ${e=>e.theme.sliderTrackColor};
@@ -738,7 +753,7 @@
738
753
  &:focus::-moz-range-thumb {
739
754
  border: 2px solid ${e=>e.theme.textColor};
740
755
  }
741
- `,Bn=D.label`
756
+ `,Zn=R.label`
742
757
  width: 100%;
743
758
  display: flex;
744
759
  justify-content: space-between;
@@ -746,10 +761,10 @@
746
761
  padding: 0 1rem;
747
762
  margin-bottom: 0.2rem;
748
763
  font-size: 14px;
749
- `,ks=D.div`
764
+ `,Wo=R.div`
750
765
  position: relative;
751
766
  display: inline-block;
752
- `,Ss=D.button`
767
+ `,Po=R.button`
753
768
  background: none;
754
769
  border: none;
755
770
  cursor: pointer;
@@ -763,7 +778,7 @@
763
778
  &:hover {
764
779
  opacity: 1;
765
780
  }
766
- `,Is=D.div`
781
+ `,Zo=R.div`
767
782
  position: fixed;
768
783
  top: ${e=>e.$top}px;
769
784
  left: ${e=>e.$left}px;
@@ -775,12 +790,12 @@
775
790
  padding: 0.5rem 0;
776
791
  min-width: 180px;
777
792
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
778
- `,As=D.hr`
793
+ `,Vo=R.hr`
779
794
  border: none;
780
795
  border-top: 1px solid rgba(128, 128, 128, 0.3);
781
796
  margin: 0.35rem 0;
782
- `,Ms=({items:e})=>{const[t,n]=s.useState(!1),r=typeof e=="function"?e(()=>n(!1)):e,[o,i]=s.useState({top:0,left:0}),l=s.useRef(null),c=s.useRef(null);return s.useEffect(()=>{if(t&&l.current){const u=l.current.getBoundingClientRect();i({top:u.bottom+2,left:Math.max(0,u.right-180)})}},[t]),s.useEffect(()=>{if(!t)return;const u=f=>{const v=f.target;l.current&&!l.current.contains(v)&&c.current&&!c.current.contains(v)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[t]),g.jsxs(ks,{children:[g.jsx(Ss,{ref:l,onClick:u=>{u.stopPropagation(),n(f=>!f)},onMouseDown:u=>u.stopPropagation(),title:"Track menu","aria-label":"Track menu",children:g.jsx(xs,{size:16})}),t&&typeof document<"u"&&Vn.createPortal(g.jsx(Is,{ref:c,$top:o.top,$left:o.left,onMouseDown:u=>u.stopPropagation(),children:r.map((u,f)=>g.jsxs(s.Fragment,{children:[f>0&&g.jsx(As,{}),u.content]},u.id))}),document.body)]})};function ot(e,t){this._waveformData=e,this._channelIndex=t}ot.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};ot.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};ot.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};ot.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};ot.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};ot.prototype.max_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.max_sample(n));return t};var _s=127,Es=-128,$s=32767,Ts=-32768;function Rs(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function Ds(e){for(var t=e.scale,n=e.amplitude_scale,a=e.split_channels,r=e.length,o=e.sample_rate,i=e.channels.map(function(A){return new Float32Array(A)}),l=a?i.length:1,c=24,u=Rs(r,t),f=e.bits===8?1:2,v=c+u*2*f*l,h=new ArrayBuffer(v),d=new DataView(h),C=0,y=c,p=new Array(l),m=new Array(l),k=0;k<l;k++)p[k]=1/0,m[k]=-1/0;var w=e.bits===8?Es:Ts,b=e.bits===8?_s:$s;d.setInt32(0,2,!0),d.setUint32(4,e.bits===8,!0),d.setInt32(8,o,!0),d.setInt32(12,t,!0),d.setInt32(16,u,!0),d.setInt32(20,l,!0);for(var x=0;x<r;x++){var S=0;if(l===1){for(var E=0;E<i.length;++E)S+=i[E][x];S=Math.floor(b*S*n/i.length),S<p[0]&&(p[0]=S,p[0]<w&&(p[0]=w)),S>m[0]&&(m[0]=S,m[0]>b&&(m[0]=b))}else for(var I=0;I<l;++I)S=Math.floor(b*i[I][x]*n),S<p[I]&&(p[I]=S,p[I]<w&&(p[I]=w)),S>m[I]&&(m[I]=S,m[I]>b&&(m[I]=b));if(++C===t){for(var $=0;$<l;$++)e.bits===8?(d.setInt8(y++,p[$]),d.setInt8(y++,m[$])):(d.setInt16(y,p[$],!0),d.setInt16(y+2,m[$],!0),y+=4),p[$]=1/0,m[$]=-1/0;C=0}}if(C>0)for(var M=0;M<l;M++)e.bits===8?(d.setInt8(y++,p[M]),d.setInt8(y++,m[M])):(d.setInt16(y,p[M],!0),d.setInt16(y+2,m[M],!0));return h}function Rt(e){"@babel/helpers - typeof";return Rt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Rt(e)}function Bs(e){return e&&Rt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Fs(e){var t=e&&Rt(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),a=n.getInt32(0,!0);if(a!==1&&a!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function Ws(e){var t=e.data,n=e.channels||1,a=24,r=e.bits===8?1:2,o=e.length*2*n;if(t.length!==o)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var i=a+t.length*r,l=new ArrayBuffer(i),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=a;if(e.bits===8)for(var f=0;f<t.length;f++)c.setInt8(u++,t[f],!0);else for(var v=0;v<t.length;v++)c.setInt16(u,t[v],!0),u+=2;return l}function ft(e){return e==null}function Ps(e,t){var n=atob(e);return n}function Zs(e,t,n){var a=Ps(e),r=a.indexOf(`
783
- `,10)+1,o=a.substring(r)+"",i=new Blob([o],{type:"application/javascript"});return URL.createObjectURL(i)}function Vs(e,t,n){var a;return function(o){return a=a||Zs(e),new Worker(a,o)}}var js=Vs("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function je(e){if(Bs(e)&&(e=Ws(e)),Fs(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new ot(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var gt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function Ls(e){var t={scale:e.scale||gt.scale,bits:e.bits||gt.bits,amplitude_scale:e.amplitude_scale||gt.amplitude_scale,split_channels:e.split_channels||gt.split_channels,disable_worker:e.disable_worker||gt.disable_worker};return t}function zs(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function ca(e,t,n){var a=zs(e);if(t.disable_worker){var r=Ds({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a});n(void 0,new je(r),e)}else{var o=new js;o.onmessage=function(i){n(void 0,new je(i.data),e)},o.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a},a)}}function Hs(e,t,n,a){function r(i){i||(i=new DOMException("EncodingError")),a(i),a=function(){}}var o=e.decodeAudioData(t,function(i){ca(i,n,a)},r);o&&o.catch(r)}je.create=function(t){return new je(t)};je.createFromAudio=function(e,t){var n=Ls(e);if(e.audio_context&&e.array_buffer)return Hs(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return ca(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Ft(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),a=24,r=this._inputData.bits===8?1:2,o=a+n*2*this._inputData.channels*r;this._output_data=new ArrayBuffer(o),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new je(this._output_data),this._input_index=0,this._output_index=0;var i=this._inputData.channels;this._min=new Array(i),this._max=new Array(i);for(var l=0;l<i;++l)this._input_buffer_size>0?(this._min[l]=this._inputData.channel(l).min_sample(this._input_index),this._max[l]=this._inputData.channel(l).max_sample(this._input_index)):(this._min[l]=0,this._max[l]=0);this._min_value=this._inputData.bits===8?-128:-32768,this._max_value=this._inputData.bits===8?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}Ft.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Ft.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,a;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var r=0;r<n;++r)a=this._outputWaveformData.channel(r),a.set_min_sample(this._output_index-1,this._min[r]),a.set_max_sample(this._output_index-1,this._max[r]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var o=0;o<n;++o)this._min[o]=this._max_value,this._max[o]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var i=0;i<n;++i){a=this._inputData.channel(i);var l=a.min_sample(this._input_index);l<this._min[i]&&(this._min[i]=l),l=a.max_sample(this._input_index),l>this._max[i]&&(this._max[i]=l)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var c=0;c<n;++c)a=this._outputWaveformData.channel(c),a.set_min_sample(this._output_index-1,this._min[c]),a.set_max_sample(this._output_index-1,this._max[c]);return!0};Ft.prototype.getOutputData=function(){return this._output_data};je.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!ft(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!ft(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new Ft(t);!n.next(););return new je(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(r){if(t.channels!==r.channels||t.sample_rate!==r.sample_rate||t.bits!==r.bits||t.scale!==r.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var a=this._concatBuffers.apply(this,n);return je.create(a)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,a=n,r=0,o=[this].concat(t).map(function(m){return m._data.buffer}),i=0;i<o.length;i++){var l=o[i],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),f=new DataView(o[0]),v=new DataView(u),h=0;h<n;h++)v.setUint8(h,f.getUint8(h));v.setInt32(16,r,!0);for(var d=0,C=new Uint8Array(u,n),y=0;y<o.length;y++){var p=o[y];C.set(new Uint8Array(p,n),d),d+=p.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!ft(t.startIndex)&&!ft(t.endIndex)?(n=t.startIndex,a=t.endIndex):!ft(t.startTime)&&!ft(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,o=24,i=this.bits===8?1:2,l=o+r*2*this.channels*i,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var f=0;f<r*this.channels*2;f++){var v=this._at(n*this.channels*2+f);this.bits===8?u.setInt8(o+f,v):u.setInt16(o+f*2,v,!0)}return new je(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var a=0;a<this.channels;a++)t.data.push(this.channel(a).min_sample(n)),t.data.push(this.channel(a).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function en(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const a=await t.arrayBuffer();return je.create(a)}else{const a=await t.json();return je.create(a)}}function ua(e,t=0){const n=e.channel(t),a=e.bits,r=n.min_array(),o=n.max_array(),i=r.length,l=a===8?new Int8Array(i*2):new Int16Array(i*2);for(let c=0;c<i;c++)l[c*2]=r[c],l[c*2+1]=o[c];return{data:l,bits:a,length:i,sampleRate:e.sample_rate}}async function Xs(e,t=0){const n=await en(e);return ua(n,t)}async function Os(e){const t=await en(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Ns(e,t,n=0,a,r){let o=e;if(r!==void 0){const h=e.scale,d=Math.floor(a/h),C=Math.ceil((a+r)/h);o=o.slice({startIndex:d,endIndex:C})}o.scale!==t&&(o=o.resample({scale:t}));const i=o.channel(n),l=o.bits,c=i.min_array(),u=i.max_array(),f=c.length,v=l===8?new Int8Array(f*2):new Int16Array(f*2);for(let h=0;h<f;h++)v[h*2]=c[h],v[h*2+1]=u[h];return{data:v,bits:l,length:f}}function Fn(e,t,n,a,r){let o=e;if(a!==void 0&&r!==void 0){const f=e.scale,v=Math.floor(a/f),h=Math.ceil((a+r)/f);o=o.slice({startIndex:v,endIndex:h})}o.scale!==t&&(o=o.resample({scale:t}));const i=o.channels,l=o.bits,c=[];for(let f=0;f<i;f++){const v=o.channel(f),h=v.min_array(),d=v.max_array(),C=h.length,y=l===8?new Int8Array(C*2):new Int16Array(C*2);for(let p=0;p<C;p++)y[p*2]=h[p],y[p*2+1]=d[p];c.push(y)}if(n&&c.length>1){const f=1/c.length,v=c[0].length/2,h=l===8?new Int8Array(v*2):new Int16Array(v*2);for(let d=0;d<v;d++){let C=0,y=0;for(let p=0;p<c.length;p++)C+=f*c[p][d*2],y+=f*c[p][d*2+1];h[d*2]=C,h[d*2+1]=y}return{length:v,data:[h],bits:l}}return{length:c.length>0?c[0].length/2:0,data:c,bits:l}}function da(){const[e,t]=s.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>mt(r,e),parseTime:r=>aa(r,e)}}const Gs=[256,512,1024,2048,4096,8192];function fa({initialSamplesPerPixel:e,zoomLevels:t=Gs}){const[n,a]=s.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),r=t[n],o=n>0,i=n<t.length-1,l=s.useCallback(()=>{s.startTransition(()=>{a(u=>Math.max(0,u-1))})},[]),c=s.useCallback(()=>{s.startTransition(()=>{a(u=>Math.min(t.length-1,u+1))})},[t.length]);return{samplesPerPixel:r,zoomIn:l,zoomOut:c,canZoomIn:o,canZoomOut:i}}function ma({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[a,r]=s.useState(t),o=s.useCallback(i=>{r(i),e.current&&e.current.setMasterGain(i),n?.(i)},[e,n]);return{masterVolume:a,setMasterVolume:o}}const Ys=(e=256)=>{const t=s.useRef(null),n=s.useCallback((a,r,o)=>{const i=new j.Analyser("fft",e);return a.connect(i),a.connect(r),t.current=i,function(){i.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function Yt(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:o,color:i,fadeIn:l,fadeOut:c,waveformData:u}=e,f=t?.sampleRate??e.sampleRate??u?.sample_rate,v=t?.length??e.sourceDurationSamples??(u&&f?Math.ceil(u.duration*f):void 0);if(f===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(v===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const h=e.durationSamples??v;return{id:ha(),audioBuffer:t,startSample:n,durationSamples:h,offsetSamples:a,sampleRate:f,sourceDurationSamples:v,gain:r,name:o,color:i,fadeIn:l,fadeOut:c,waveformData:u}}function Ks(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:o,color:i,fadeIn:l,fadeOut:c,waveformData:u}=e,f=t?.sampleRate??e.sampleRate??u?.sample_rate;if(f===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const v=t?.duration??e.sourceDuration??u?.duration;if(v===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const h=e.duration??v;return Yt({audioBuffer:t,startSample:Math.round(n*f),durationSamples:Math.round(h*f),offsetSamples:Math.round(a*f),sampleRate:f,sourceDurationSamples:Math.ceil(v*f),gain:r,name:o,color:i,fadeIn:l,fadeOut:c,waveformData:u})}function Us(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:o=1,pan:i=0,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:f}=e;return{id:ha(),name:t,clips:n,muted:a,soloed:r,volume:o,pan:i,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:f}}function ha(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function qs(e,t={}){const{progressive:n=!1}=t,[a,r]=s.useState([]),[o,i]=s.useState(!0),[l,c]=s.useState(null),[u,f]=s.useState(0),v=e.length;return s.useEffect(()=>{if(e.length===0){r([]),i(!1),f(0);return}let h=!1;const d=new AbortController,C=new Map,y=(m,k,w)=>{const b=w??m.audioBuffer;if(!b&&!m.waveformData)throw new Error(`Track ${k+1}: Must provide src, audioBuffer, or waveformData`);const x=b?.duration??m.waveformData?.duration,S=Ks({audioBuffer:b,startTime:m.startTime??0,duration:m.duration??x,offset:m.offset??0,name:m.name||`Track ${k+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${k+1}`);return{...Us({name:m.name||`Track ${k+1}`,clips:[S],muted:m.muted??!1,soloed:m.soloed??!1,volume:m.volume??1,pan:m.pan??0,color:m.color}),effects:m.effects,renderMode:m.renderMode,spectrogramConfig:m.spectrogramConfig,spectrogramColorMap:m.spectrogramColorMap}};return(async()=>{try{i(!0),c(null),f(0);const m=Ln.getContext().rawContext,k=e.map(async(b,x)=>{if(b.audioBuffer){const M=y(b,x,b.audioBuffer);return n&&!h&&(C.set(x,M),f(A=>A+1),r(Array.from({length:e.length},(A,B)=>C.get(B)).filter(A=>A!==void 0))),M}if(!b.src&&b.waveformData){const M=y(b,x);return n&&!h&&(C.set(x,M),f(A=>A+1),r(Array.from({length:e.length},(A,B)=>C.get(B)).filter(A=>A!==void 0))),M}if(!b.src)throw new Error(`Track ${x+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(b.src,{signal:d.signal});if(!S.ok)throw new Error(`Failed to fetch ${b.src}: ${S.statusText}`);const E=await S.arrayBuffer(),I=await m.decodeAudioData(E);if(!I||!I.sampleRate||!I.duration)throw new Error(`Invalid audio buffer for ${b.src}`);const $=y(b,x,I);return n&&!h&&(C.set(x,$),f(M=>M+1),r(Array.from({length:e.length},(M,A)=>C.get(A)).filter(M=>M!==void 0))),$}),w=await Promise.all(k);h||(n||(r(w),f(w.length)),i(!1))}catch(m){if(!h){const k=m instanceof Error?m.message:"Unknown error loading audio";c(k),i(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{h=!0,d.abort()}},[e,n]),{tracks:a,loading:o,error:l,loadedCount:u,totalCount:v}}function Js({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=s.useRef(null),o=s.useCallback(u=>{const{transform:f,active:v}=u;if(!v?.data?.current)return{...f,scaleX:1,scaleY:1};const{trackIndex:h,clipIndex:d,boundary:C}=v.data.current;if(C)return{...f,scaleX:1,scaleY:1};const y=e[h];if(!y)return{...f,scaleX:1,scaleY:1};const p=y.clips[d];if(!p)return{...f,scaleX:1,scaleY:1};const m=p.startSample/a,k=p.durationSamples/a,w=f.x*n/a;let b=m+w;const x=[...y.clips].sort((A,B)=>A.startSample-B.startSample),S=x.findIndex(A=>A===p);b=Math.max(0,b);const E=S>0?x[S-1]:null;if(E){const A=(E.startSample+E.durationSamples)/a;b=Math.max(b,A)}const I=S<x.length-1?x[S+1]:null;if(I){const A=b+k,B=I.startSample/a;A>B&&(b=B-k)}const M=(b-m)*a/n;return{...f,x:M,scaleX:1,scaleY:1}},[e,n,a]),i=s.useCallback(u=>{const{active:f}=u,{boundary:v}=f.data.current;if(!v){r.current=null;return}const{trackIndex:h,clipIndex:d}=f.data.current,y=e[h]?.clips[d];y&&(r.current={offsetSamples:y.offsetSamples,durationSamples:y.durationSamples,startSample:y.startSample})},[e]),l=s.useCallback(u=>{const{active:f,delta:v}=u,{boundary:h}=f.data.current;if(!h||!r.current)return;const{trackIndex:d,clipIndex:C}=f.data.current,y=v.x*n,p=Math.floor(.1*a),m=r.current,k=e.map((w,b)=>{if(b!==d)return w;const x=[...w.clips].sort((I,$)=>I.startSample-$.startSample),S=x.findIndex(I=>I===w.clips[C]),E=w.clips.map((I,$)=>{if($!==C)return I;const M=I.sourceDurationSamples;if(h==="left"){let A=Math.floor(y);const B=-m.startSample;A<B&&(A=B);const _=-m.offsetSamples;A<_&&(A=_);const R=S>0?x[S-1]:null;if(R){const ne=R.startSample+R.durationSamples-m.startSample;A<ne&&(A=ne)}const W=m.durationSamples-p;A>W&&(A=W);const L=m.offsetSamples+A,P=m.durationSamples-A,U=m.startSample+A;return{...I,offsetSamples:L,durationSamples:P,startSample:U}}else{let A=Math.floor(m.durationSamples+y);A=Math.max(p,A),m.offsetSamples+A>M&&(A=M-m.offsetSamples);const B=S<x.length-1?x[S+1]:null;return B&&m.startSample+A>B.startSample&&(A=B.startSample-m.startSample,A=Math.max(p,A)),{...I,durationSamples:A}}});return{...w,clips:E}});t(k)},[e,t,n,a]),c=s.useCallback(u=>{const{active:f,delta:v}=u,{trackIndex:h,clipIndex:d,boundary:C}=f.data.current,y=v.x*n;if(C){r.current=null;return}const p=e.map((m,k)=>{if(k!==h)return m;const w=[...m.clips].sort((S,E)=>S.startSample-E.startSample),b=w.findIndex(S=>S===m.clips[d]),x=m.clips.map((S,E)=>{if(E!==d)return S;let I=Math.floor(S.startSample+y);I=Math.max(0,I);const $=b>0?w[b-1]:null;if($){const A=$.startSample+$.durationSamples;I=Math.max(I,A)}const M=b<w.length-1?w[b+1]:null;return M&&I+S.durationSamples>M.startSample&&(I=M.startSample-S.durationSamples),{...S,startSample:I}});return{...m,clips:x}});t(p)},[e,t,n]);return{onDragStart:i,onDragMove:l,onDragEnd:c,collisionModifier:o}}const Ht=.01;function pa({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:o}){const i=s.useRef(null),l=s.useCallback(f=>{const{active:v}=f,h=v.data.current;if(!h||h.annotationIndex===void 0){i.current=null;return}const d=e[h.annotationIndex];d&&(i.current={start:d.start,end:d.end,annotationIndex:h.annotationIndex})},[e]),c=s.useCallback(f=>{const{active:v,delta:h}=f;if(!i.current)return;const d=v.data.current;if(!d)return;const{edge:C,annotationIndex:y}=d,p=i.current,m=h.x*n/a,k=C==="start"?p.start+m:p.end+m,w=Qs({annotationIndex:y,newTime:k,isDraggingStart:C==="start",annotations:e,duration:r,linkEndpoints:o});t(w)},[e,t,n,a,r,o]),u=s.useCallback(()=>{i.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Qs({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:o}){const i=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(i[e]={...l,start:c},o&&e>0){const f=i[e-1];Math.abs(f.end-l.start)<Ht?i[e-1]={...f,end:Math.max(f.start+.1,f.end+u)}:c<=f.end&&(i[e]={...i[e],start:f.end})}else!o&&e>0&&c<i[e-1].end&&(i[e-1]={...i[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(i[e]={...l,end:c},o&&e<i.length-1){const f=i[e+1];if(Math.abs(f.start-l.end)<Ht){const v=f.start+u;i[e+1]={...f,start:Math.min(f.end-.1,v)};let h=e+1;for(;h<i.length-1;){const d=i[h],C=i[h+1];if(Math.abs(C.start-d.end)<Ht){const y=d.end-a[h].end;i[h+1]={...C,start:Math.min(C.end-.1,C.start+y)},h++}else break}}else c>=f.start&&(i[e]={...i[e],end:f.start})}else if(!o&&e<i.length-1&&c>i[e+1].start){const f=i[e+1];i[e+1]={...f,start:c};let v=e+1;for(;v<i.length-1;){const h=i[v],d=i[v+1];if(h.end>d.start)i[v+1]={...d,start:h.end},v++;else break}}}return i}function eo(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,o=Ge.useSensor(Ge.MouseSensor,{activationConstraint:{distance:r}}),i=Ge.useSensor(Ge.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Ge.useSensor(Ge.PointerSensor,{activationConstraint:{distance:r}});return Ge.useSensors(...t?[o,i]:[l])}const to=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Fe(),{selectedTrackId:o}=We(),i=s.useCallback((c,u,f)=>{const{sampleRate:v,samplesPerPixel:h}=e,d=t[c];if(!d)return!1;const C=d.clips[u];if(!C)return!1;const y=C.startSample/v,p=(C.startSample+C.durationSamples)/v;if(f<=y||f>=p)return console.warn("Split time is outside clip bounds"),!1;const m=Math.round(f*v),k=Math.floor(m/h),w=C.startSample+C.durationSamples,b=k*h,x=C.startSample,S=b-x,E=b,I=w-E,$=b-C.startSample,M=Yt({audioBuffer:C.audioBuffer,startSample:x,durationSamples:S,offsetSamples:C.offsetSamples,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (1)`:void 0,color:C.color,fadeIn:C.fadeIn,waveformData:C.waveformData}),A=Yt({audioBuffer:C.audioBuffer,startSample:E,durationSamples:I,offsetSamples:C.offsetSamples+$,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (2)`:void 0,color:C.color,waveformData:C.waveformData,fadeOut:C.fadeOut}),B=[...d.clips];B.splice(u,1,M,A);const _=[...t];return _[c]={...d,clips:B},n(_),!0},[t,n,e]);return{splitClipAtPlayhead:s.useCallback(()=>{if(!o)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(v=>v.id===o);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],f=r.current??0;for(let v=0;v<u.clips.length;v++){const h=u.clips[v],d=h.startSample/a,C=(h.startSample+h.durationSamples)/a;if(f>d&&f<C)return console.log(`Splitting clip on track "${u.name}" at ${f}s`),i(c,v,f)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,o,i,a]),splitClipAt:i}},Dt=e=>{const{shortcuts:t,enabled:n=!0}=e,a=s.useCallback(r=>{if(!n)return;const o=r.target;if(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable)return;const i=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,f=l.shiftKey===void 0||r.shiftKey===l.shiftKey,v=l.metaKey===void 0||r.metaKey===l.metaKey,h=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&f&&v&&h});i&&(i.preventDefault!==!1&&r.preventDefault(),i.action())},[t,n]);s.useEffect(()=>{if(n)return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[a,n])},no=e=>{const t=[],n=typeof navigator<"u"&&navigator.platform.includes("Mac");return e.metaKey&&t.push(n?"Cmd":"Ctrl"),e.ctrlKey&&!e.metaKey&&t.push("Ctrl"),e.altKey&&t.push(n?"Option":"Alt"),e.shiftKey&&t.push("Shift"),t.push(e.key.toUpperCase()),t.join("+")},ao=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Fe(),{setCurrentTime:o,play:i,pause:l,stop:c}=ge(),{playoutRef:u}=$e(),f=s.useCallback(()=>{r?l():i()},[r,i,l]),v=s.useCallback(()=>{c()},[c]),h=s.useCallback(()=>{r&&u.current?(u.current.stop(),o(0),i(0)):o(0)},[r,u,o,i]),C=a??[...[{key:" ",action:f,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:v,description:"Stop",preventDefault:!0},{key:"0",action:h,description:"Rewind to start",preventDefault:!0}],...n];return Dt({shortcuts:C,enabled:t}),{rewindToStart:h,togglePlayPause:f,stopPlayback:v,shortcuts:C}},Xt=.01,_t=.01;function ro({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:o,continuousPlay:i=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:f,controlsWidth:v=0,onPlay:h}){const d=s.useMemo(()=>t?e.findIndex($=>$.id===t):-1,[e,t]),C=s.useCallback($=>{if(!c?.current||!u||!f)return;const M=e.find(H=>H.id===$);if(!M)return;const A=c.current,B=A.clientWidth,_=M.start*f/u+v,R=M.end*f/u+v,W=(_+R)/2,L=A.scrollLeft,P=L,U=L+B;if(_<P||R>U){const H=Math.max(0,W-B/2);A.scrollTo({left:H,behavior:"smooth"})}},[e,c,u,f,v]);s.useEffect(()=>{t&&c?.current&&u&&f&&C(t)},[t,C,c,u,f]);const y=s.useCallback($=>{if(d<0)return;const M=e[d],A=Math.max(0,Math.min(M.end-.1,M.start+$)),B=A-M.start,_=[...e];if(_[d]={...M,start:A},o&&d>0){const R=_[d-1];Math.abs(R.end-M.start)<Xt&&(_[d-1]={...R,end:Math.max(R.start+.1,R.end+B)})}else if(!o&&d>0){const R=_[d-1];A<R.end&&(_[d-1]={...R,end:A})}n(_)},[e,d,o,n]),p=s.useCallback($=>{if(d<0)return;const M=e[d],A=Math.max(M.start+.1,Math.min(r,M.end+$)),B=A-M.end,_=[...e];if(_[d]={...M,end:A},o&&d<e.length-1){const R=_[d+1];if(Math.abs(R.start-M.end)<Xt){const W=Math.min(R.end-.1,R.start+B);_[d+1]={...R,start:W};let L=d+1;for(;L<_.length-1;){const P=_[L],U=_[L+1];if(Math.abs(U.start-e[L].end)<Xt){const H=P.end-e[L].end;_[L+1]={...U,start:Math.min(U.end-.1,U.start+H)},L++}else break}}}else if(!o&&d<e.length-1){const R=_[d+1];if(A>R.start){_[d+1]={...R,start:A};let W=d+1;for(;W<_.length-1;){const L=_[W],P=_[W+1];if(L.end>P.start)_[W+1]={...P,start:L.end},W++;else break}}}n(_)},[e,d,r,o,n]),m=s.useCallback(()=>{!a||e.length===0||(d<=0?a(e[e.length-1].id):a(e[d-1].id))},[e,d,a]),k=s.useCallback(()=>{!a||e.length===0||(d<0||d>=e.length-1?a(e[0].id):a(e[d+1].id))},[e,d,a]),w=s.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),b=s.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),x=s.useCallback(()=>{a&&a(null)},[a]),S=s.useCallback(()=>{if(d<0||!h)return;const $=e[d],M=i?void 0:$.end-$.start;h($.start,M)},[e,d,i,h]),E=s.useMemo(()=>[{key:"[",action:()=>y(-_t),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>y(_t),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>p(-_t),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>p(_t),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:S,description:"Play selected annotation",preventDefault:!0}],[y,p,S]),I=s.useMemo(()=>[{key:"ArrowUp",action:m,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:m,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:k,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:k,description:"Select next annotation",preventDefault:!0},{key:"Home",action:w,description:"Select first annotation",preventDefault:!0},{key:"End",action:b,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:x,description:"Deselect annotation",preventDefault:!0}],[m,k,w,b,x]);return Dt({shortcuts:E,enabled:l&&d>=0}),Dt({shortcuts:I,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:y,moveEndBoundary:p,selectPrevious:m,selectNext:k,selectFirst:w,selectLast:b,clearSelection:x,scrollToAnnotation:C,playActiveAnnotation:S}}const wt=[{id:"reverb",name:"Reverb",category:"reverb",description:"Simple convolution reverb with adjustable decay time",parameters:[{name:"decay",label:"Decay",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"s"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"freeverb",name:"Freeverb",category:"reverb",description:"Classic Schroeder/Moorer reverb with room size and dampening",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.7},{name:"dampening",label:"Dampening",type:"number",min:0,max:1e4,step:100,default:3e3,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"jcReverb",name:"JC Reverb",category:"reverb",description:"Attempt at Roland JC-120 chorus reverb emulation",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"feedbackDelay",name:"Feedback Delay",category:"delay",description:"Delay line with feedback for echo effects",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"pingPongDelay",name:"Ping Pong Delay",category:"delay",description:"Stereo delay bouncing between left and right channels",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"chorus",name:"Chorus",category:"modulation",description:"Creates thickness by layering detuned copies of the signal",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"Hz"},{name:"delayTime",label:"Delay",type:"number",min:0,max:20,step:.5,default:3.5,unit:"ms"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.7},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"phaser",name:"Phaser",category:"modulation",description:"Classic phaser effect using allpass filters",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:.5,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:6,step:1,default:3},{name:"baseFrequency",label:"Base Freq",type:"number",min:100,max:2e3,step:10,default:350,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"tremolo",name:"Tremolo",category:"modulation",description:"Rhythmic volume modulation",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:4,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"vibrato",name:"Vibrato",category:"modulation",description:"Pitch modulation effect",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:5,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoPanner",name:"Auto Panner",category:"modulation",description:"Automatic left-right panning",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoFilter",name:"Auto Filter",category:"filter",description:"Automated filter sweep with LFO",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:2e3,step:10,default:200,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:.5,max:8,step:.5,default:2.6},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoWah",name:"Auto Wah",category:"filter",description:"Envelope follower filter effect",parameters:[{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:500,step:10,default:100,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:8,step:1,default:6},{name:"sensitivity",label:"Sensitivity",type:"number",min:-40,max:0,step:1,default:0,unit:"dB"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"eq3",name:"3-Band EQ",category:"filter",description:"Three band equalizer with low, mid, and high controls",parameters:[{name:"low",label:"Low",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"mid",label:"Mid",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"high",label:"High",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"lowFrequency",label:"Low Freq",type:"number",min:20,max:500,step:10,default:400,unit:"Hz"},{name:"highFrequency",label:"High Freq",type:"number",min:1e3,max:1e4,step:100,default:2500,unit:"Hz"}]},{id:"distortion",name:"Distortion",category:"distortion",description:"Wave shaping distortion effect",parameters:[{name:"distortion",label:"Drive",type:"number",min:0,max:1,step:.01,default:.4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"bitCrusher",name:"Bit Crusher",category:"distortion",description:"Reduces bit depth for lo-fi digital texture",parameters:[{name:"bits",label:"Bits",type:"number",min:1,max:16,step:1,default:4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"chebyshev",name:"Chebyshev",category:"distortion",description:"Waveshaping distortion using Chebyshev polynomials",parameters:[{name:"order",label:"Order",type:"number",min:1,max:100,step:1,default:50},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"compressor",name:"Compressor",category:"dynamics",description:"Dynamic range compressor",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-60,max:0,step:1,default:-24,unit:"dB"},{name:"ratio",label:"Ratio",type:"number",min:1,max:20,step:.5,default:4},{name:"attack",label:"Attack",type:"number",min:0,max:1,step:.001,default:.003,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"knee",label:"Knee",type:"number",min:0,max:40,step:1,default:30,unit:"dB"}]},{id:"limiter",name:"Limiter",category:"dynamics",description:"Hard limiter to prevent clipping",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-12,max:0,step:.5,default:-6,unit:"dB"}]},{id:"gate",name:"Gate",category:"dynamics",description:"Noise gate to silence signal below threshold",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-100,max:0,step:1,default:-40,unit:"dB"},{name:"attack",label:"Attack",type:"number",min:0,max:.3,step:.001,default:.001,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:.5,step:.01,default:.1,unit:"s"}]},{id:"stereoWidener",name:"Stereo Widener",category:"spatial",description:"Expands or narrows the stereo image",parameters:[{name:"width",label:"Width",type:"number",min:0,max:1,step:.01,default:.5}]}],tn=e=>wt.find(t=>t.id===e),so=e=>wt.filter(t=>t.category===e),oo=[{id:"reverb",name:"Reverb"},{id:"delay",name:"Delay"},{id:"modulation",name:"Modulation"},{id:"filter",name:"Filter"},{id:"distortion",name:"Distortion"},{id:"dynamics",name:"Dynamics"},{id:"spatial",name:"Spatial"}];const io={reverb:j.Reverb,freeverb:j.Freeverb,jcReverb:j.JCReverb,feedbackDelay:j.FeedbackDelay,pingPongDelay:j.PingPongDelay,chorus:j.Chorus,phaser:j.Phaser,tremolo:j.Tremolo,vibrato:j.Vibrato,autoPanner:j.AutoPanner,autoFilter:j.AutoFilter,autoWah:j.AutoWah,eq3:j.EQ3,distortion:j.Distortion,bitCrusher:j.BitCrusher,chebyshev:j.Chebyshev,compressor:j.Compressor,limiter:j.Limiter,gate:j.Gate,stereoWidener:j.StereoWidener};let lo=0;const co=()=>`effect_${Date.now()}_${++lo}`;function bt(e,t){const n=io[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(l=>{const c=t?.[l.name]??l.default;a[l.name]=c});const r=new n(a),o=co(),i=r;return{effect:r,id:e.id,instanceId:o,dispose(){try{r.disconnect(),r.dispose()}catch(l){console.warn(`[waveform-playlist] Error disposing effect "${e.id}" (${o}):`,l)}},setParameter(l,c){const u=i[l];if(l==="wet"){const f=i.wet;if(f&&typeof f=="object"&&"value"in f){f.value=c;return}}u!==void 0&&(u&&typeof u=="object"&&"value"in u?u.value=c:i[l]=c)},getParameter(l){if(l==="wet"){const u=i.wet;if(u&&typeof u=="object"&&"value"in u)return u.value}const c=i[l];if(c!==void 0)return c&&typeof c=="object"&&"value"in c?c.value:c},connect(l){r.connect(l)},disconnect(){try{r.disconnect()}catch(l){console.warn(`[waveform-playlist] Error disconnecting effect "${e.id}" (${o}):`,l)}}}}function uo(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function fo(e=256){const[t,n]=s.useState([]),a=s.useRef(t);a.current=t;const r=s.useRef(new Map),o=s.useRef(null),i=s.useRef(null),l=s.useCallback(p=>{const m=i.current;if(!m)return;const{masterGainNode:k,destination:w,analyserNode:b}=m;try{k.disconnect()}catch(S){console.warn("[waveform-playlist] Error disconnecting master effects chain:",S)}const x=p.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(x.length===0)k.connect(b),b.connect(w);else{let S=k;x.forEach(E=>{try{E.disconnect()}catch(I){console.warn(`[waveform-playlist] Error disconnecting effect "${E.id}":`,I)}S.connect(E.effect),S=E.effect}),S.connect(b),b.connect(w)}},[]),c=s.useCallback(p=>{const m=tn(p);if(!m){console.error(`Unknown effect: ${p}`);return}const k={};m.parameters.forEach(x=>{k[x.name]=x.default});const w=bt(m,k);r.current.set(w.instanceId,w);const b={instanceId:w.instanceId,effectId:m.id,definition:m,params:k,bypassed:!1};n(x=>[...x,b])},[]),u=s.useCallback(p=>{const m=r.current.get(p);m&&(m.dispose(),r.current.delete(p)),n(k=>k.filter(w=>w.instanceId!==p))},[]),f=s.useCallback((p,m,k)=>{const w=r.current.get(p);w&&w.setParameter(m,k),n(b=>b.map(x=>x.instanceId===p?{...x,params:{...x.params,[m]:k}}:x))},[]),v=s.useCallback(p=>{const m=a.current.find(b=>b.instanceId===p);if(!m)return;const k=!m.bypassed,w=r.current.get(p);if(w){const b=m.params.wet??1;w.setParameter("wet",k?0:b)}n(b=>b.map(x=>x.instanceId===p?{...x,bypassed:k}:x))},[]),h=s.useCallback((p,m)=>{n(k=>{const w=[...k],[b]=w.splice(p,1);return w.splice(m,0,b),w})},[]),d=s.useCallback(()=>{r.current.forEach(p=>p.dispose()),r.current.clear(),n([])},[]);s.useEffect(()=>{l(t)},[t,l]);const C=s.useCallback((p,m,k)=>{const w=new j.Analyser("fft",e);o.current=w,i.current={masterGainNode:p,destination:m,analyserNode:w};const x=a.current.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(x.length===0)p.connect(w),w.connect(m);else{let S=p;x.forEach(E=>{S.connect(E.effect),S=E.effect}),S.connect(w),w.connect(m)}return function(){w.dispose(),o.current=null,i.current=null}},[e]);s.useEffect(()=>{const p=r.current;return()=>{p.forEach(m=>m.dispose()),p.clear()}},[]);const y=s.useCallback(()=>{const p=t.filter(m=>!m.bypassed);if(p.length!==0)return(m,k,w)=>{const b=[];for(const x of p){const S=bt(x.definition,x.params);b.push(S)}if(b.length===0)m.connect(k);else{let x=m;b.forEach(S=>{x.connect(S.effect),x=S.effect}),x.connect(k)}return function(){b.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:wt,addEffect:c,removeEffect:u,updateParameter:f,toggleBypass:v,reorderEffects:h,clearAllEffects:d,masterEffects:C,createOfflineEffectsFunction:y,analyserRef:o}}function mo(){const[e,t]=s.useState(new Map),n=s.useRef(new Map),a=s.useRef(new Map),r=s.useCallback((d,C)=>{const y=a.current.get(d);if(!y)return;const{graphEnd:p,masterGainNode:m}=y,k=n.current.get(d);try{p.disconnect()}catch(b){console.warn(`[waveform-playlist] Error disconnecting track "${d}" effect chain:`,b)}const w=C.map(b=>k?.get(b.instanceId)).filter(b=>b!==void 0);if(w.length===0)p.connect(m);else{let b=p;w.forEach(x=>{try{x.disconnect()}catch(S){console.warn(`[waveform-playlist] Error disconnecting effect "${x.id}" on track "${d}":`,S)}b.connect(x.effect),b=x.effect}),b.connect(m)}},[]),o=s.useCallback((d,C)=>{const y=tn(C);if(!y){console.error(`Unknown effect: ${C}`);return}const p={};y.parameters.forEach(w=>{p[w.name]=w.default});const m=bt(y,p);n.current.has(d)||n.current.set(d,new Map),n.current.get(d).set(m.instanceId,m);const k={instanceId:m.instanceId,effectId:y.id,definition:y,params:p,bypassed:!1};t(w=>{const b=new Map(w),x=b.get(d)||[];return b.set(d,[...x,k]),b})},[]),i=s.useCallback((d,C)=>{const y=n.current.get(d),p=y?.get(C);p&&(p.dispose(),y?.delete(C)),t(m=>{const k=new Map(m),w=k.get(d)||[];return k.set(d,w.filter(b=>b.instanceId!==C)),k})},[]),l=s.useCallback((d,C,y,p)=>{const k=n.current.get(d)?.get(C);k&&k.setParameter(y,p),t(w=>{const b=new Map(w),x=b.get(d)||[];return b.set(d,x.map(S=>S.instanceId===C?{...S,params:{...S.params,[y]:p}}:S)),b})},[]),c=s.useCallback((d,C)=>{const p=(f.current.get(d)||[]).find(b=>b.instanceId===C);if(!p)return;const m=!p.bypassed,w=n.current.get(d)?.get(C);if(w){const b=p.params.wet??1;w.setParameter("wet",m?0:b)}t(b=>{const x=new Map(b),S=x.get(d)||[];return x.set(d,S.map(E=>E.instanceId===C?{...E,bypassed:m}:E)),x})},[]),u=s.useCallback(d=>{const C=n.current.get(d);C&&(C.forEach(y=>y.dispose()),C.clear()),t(y=>{const p=new Map(y);return p.set(d,[]),p})},[]),f=s.useRef(e);f.current=e;const v=s.useCallback(d=>(C,y,p)=>{a.current.set(d,{graphEnd:C,masterGainNode:y});const m=f.current.get(d)||[],k=n.current.get(d),w=m.map(b=>k?.get(b.instanceId)).filter(b=>b!==void 0);if(w.length===0)C.connect(y);else{let b=C;w.forEach(x=>{b.connect(x.effect),b=x.effect}),b.connect(y)}return function(){a.current.delete(d)}},[]);s.useEffect(()=>{e.forEach((d,C)=>{r(C,d)})},[e,r]),s.useEffect(()=>{const d=n.current;return()=>{d.forEach(C=>{C.forEach(y=>y.dispose()),C.clear()}),d.clear()}},[]);const h=s.useCallback(d=>{const y=(e.get(d)||[]).filter(p=>!p.bypassed);if(y.length!==0)return(p,m,k)=>{const w=[];for(const b of y){const x=bt(b.definition,b.params);w.push(x)}if(w.length===0)p.connect(m);else{let b=p;w.forEach(x=>{b.connect(x.effect),b=x.effect}),b.connect(m)}return function(){w.forEach(x=>x.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:o,removeEffectFromTrack:i,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:v,createOfflineTrackEffectsFunction:h,availableEffects:wt}}function ho(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,o=e.length,i=n/8,l=a*i,c=r*l,u=o*l,f=44,v=f+u,h=new ArrayBuffer(v),d=new DataView(h);Et(d,0,"RIFF"),d.setUint32(4,v-8,!0),Et(d,8,"WAVE"),Et(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,n===32?3:1,!0),d.setUint16(22,a,!0),d.setUint32(24,r,!0),d.setUint32(28,c,!0),d.setUint16(32,l,!0),d.setUint16(34,n,!0),Et(d,36,"data"),d.setUint32(40,u,!0);const C=[];for(let p=0;p<a;p++)C.push(e.getChannelData(p));let y=f;if(n===16)for(let p=0;p<o;p++)for(let m=0;m<a;m++){const k=C[m][p],w=Math.max(-1,Math.min(1,k)),b=w<0?w*32768:w*32767;d.setInt16(y,b,!0),y+=2}else for(let p=0;p<o;p++)for(let m=0;m<a;m++)d.setFloat32(y,C[m][p],!0),y+=4;return new Blob([h],{type:"audio/wav"})}function Et(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function po(e,t){const n=URL.createObjectURL(e),a=document.createElement("a");a.href=n,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}function ga(){const[e,t]=s.useState(!1),[n,a]=s.useState(0),[r,o]=s.useState(null);return{exportWav:s.useCallback(async(l,c,u={})=>{const{filename:f="export",mode:v="master",trackIndex:h,autoDownload:d=!0,applyEffects:C=!0,effectsFunction:y,createOfflineTrackEffects:p,bitDepth:m=16,onProgress:k}=u;t(!0),a(0),o(null);try{if(l.length===0)throw new Error("No tracks to export");if(v==="individual"&&(h===void 0||h<0||h>=l.length))throw new Error("Invalid track index for individual export");const w=l[0].clips[0]?.sampleRate||44100;let b=0;for(const A of l)for(const B of A.clips){const _=B.startSample+B.durationSamples;b=Math.max(b,_)}b+=Math.round(w*.1);const x=b/w,S=v==="individual"?[{track:l[h],state:c[h],index:h}]:l.map((A,B)=>({track:A,state:c[B],index:B})),E=c.some(A=>A.soloed),I=!!p;let $;if((y||I)&&C)$=await go(S,c,E,x,w,y,p,A=>{a(A),k?.(A)});else{const A=new OfflineAudioContext(2,b,w);let B=0;const _=S.reduce((R,{track:W})=>R+W.clips.length,0);for(const{track:R,state:W}of S)if(!(W.muted&&!W.soloed)&&!(E&&!W.soloed))for(const L of R.clips){await vo(A,L,W,w,C),B++;const P=B/_*.5;a(P),k?.(P)}a(.5),k?.(.5),$=await A.startRendering()}a(.9),k?.(.9);const M=ho($,{bitDepth:m});if(a(1),k?.(1),d){const A=v==="individual"?`${f}_${l[h].name}`:f;po(M,`${A}.wav`)}return{audioBuffer:$,blob:M,duration:x}}catch(w){const b=w instanceof Error?w.message:"Export failed";throw o(b),w}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function go(e,t,n,a,r,o,i,l){const{Offline:c,Volume:u,Gain:f,Panner:v,Player:h,ToneAudioBuffer:d}=await import("tone");l(.1);let C;try{C=await c(async({transport:y,destination:p})=>{const m=new u(0);let k;o?k=o(m,p,!0):m.connect(p);for(const{track:w,state:b}of e){if(b.muted&&!b.soloed||n&&!b.soloed)continue;const x=new u(bo(b.volume)),S=new v(b.pan),E=new f(b.muted?0:1),I=i?.(w.id);I?I(E,m,!0):E.connect(m),S.connect(E),x.connect(S);for(const $ of w.clips){const{audioBuffer:M,startSample:A,durationSamples:B,offsetSamples:_,gain:R,fadeIn:W,fadeOut:L}=$,P=A/r,U=B/r,H=_/r,ne=new d(M),le=new h(ne),se=new f(R);if(le.connect(se),se.connect(x),W){const oe=P,ye=P+W.duration,ce=Tt(se.gain);ce&&(ce.setValueAtTime(0,oe),ce.linearRampToValueAtTime(R,ye))}if(L){const oe=P+U-L.duration,ye=P+U,ce=Tt(se.gain);ce&&(ce.setValueAtTime(R,oe),ce.linearRampToValueAtTime(0,ye))}le.start(P,H,U)}}y.start(0)},a,2,r)}catch(y){throw y instanceof Error?y:new Error(`Tone.Offline rendering failed: ${String(y)}`)}return l(.9),C.get()}function bo(e){return 20*Math.log10(Math.max(e,1e-4))}async function vo(e,t,n,a,r){const{audioBuffer:o,startSample:i,durationSamples:l,offsetSamples:c,gain:u,fadeIn:f,fadeOut:v}=t;if(!o){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const h=i/a,d=l/a,C=c/a,y=e.createBufferSource();y.buffer=o;const p=e.createGain(),m=u*n.volume,k=e.createStereoPanner();if(k.pan.value=n.pan,y.connect(p),p.connect(k),k.connect(e.destination),r){if(f?p.gain.setValueAtTime(0,h):p.gain.setValueAtTime(m,h),f){const w=h,b=h+f.duration;Wn(p.gain,w,b,0,m,f.type||"linear")}if(v){const w=h+d-v.duration,b=h+d;(!f||f.duration<d-v.duration)&&p.gain.setValueAtTime(m,w),Wn(p.gain,w,b,m,0,v.type||"linear")}}else p.gain.setValueAtTime(m,h);y.start(h,C,d)}function Wn(e,t,n,a,r,o){const i=n-t;if(!(i<=0))switch(o){case"linear":e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n);break;case"exponential":{const l=Math.max(a,1e-4),c=Math.max(r,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),r===0&&e.setValueAtTime(0,n);break}case"logarithmic":{const l=Pn(a,r,256,"logarithmic");e.setValueCurveAtTime(l,t,i);break}case"sCurve":{const l=Pn(a,r,256,"sCurve");e.setValueCurveAtTime(l,t,i);break}default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function Pn(e,t,n,a){const r=new Float32Array(n),o=t-e;for(let i=0;i<n;i++){const l=i/(n-1);let c;a==="logarithmic"?o>0?c=Math.log10(1+l*9)/Math.log10(10):c=1-Math.log10(1+(1-l)*9)/Math.log10(10):c=l*l*(3-2*l),r[i]=e+o*c}return r}const ba=()=>{const e=s.useRef(null),t=s.useCallback(()=>{e.current!==null&&(cancelAnimationFrame(e.current),e.current=null)},[]),n=s.useCallback(a=>{t(),e.current=requestAnimationFrame(a)},[t]);return s.useEffect(()=>()=>{t()},[t]),{animationFrameRef:e,startAnimationFrameLoop:n,stopAnimationFrameLoop:t}},yo=`
797
+ `,jo=({items:e})=>{const[t,n]=o.useState(!1),r=typeof e=="function"?e(()=>n(!1)):e,[s,i]=o.useState({top:0,left:0}),l=o.useRef(null),c=o.useRef(null);return o.useEffect(()=>{if(t&&l.current){const u=l.current.getBoundingClientRect();i({top:u.bottom+2,left:Math.max(0,u.right-180)})}},[t]),o.useEffect(()=>{if(!t)return;const u=m=>{const h=m.target;l.current&&!l.current.contains(h)&&c.current&&!c.current.contains(h)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[t]),v.jsxs(Wo,{children:[v.jsx(Po,{ref:l,onClick:u=>{u.stopPropagation(),n(m=>!m)},onMouseDown:u=>u.stopPropagation(),title:"Track menu","aria-label":"Track menu",children:v.jsx(Fo,{size:16})}),t&&typeof document<"u"&&Hn.createPortal(v.jsx(Zo,{ref:c,$top:s.top,$left:s.left,onMouseDown:u=>u.stopPropagation(),children:r.map((u,m)=>v.jsxs(o.Fragment,{children:[m>0&&v.jsx(Vo,{}),u.content]},u.id))}),document.body)]})};function lt(e,t){this._waveformData=e,this._channelIndex=t}lt.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};lt.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};lt.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};lt.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};lt.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};lt.prototype.max_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.max_sample(n));return t};var Lo=127,zo=-128,Ho=32767,Xo=-32768;function Oo(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function Go(e){for(var t=e.scale,n=e.amplitude_scale,a=e.split_channels,r=e.length,s=e.sample_rate,i=e.channels.map(function(I){return new Float32Array(I)}),l=a?i.length:1,c=24,u=Oo(r,t),m=e.bits===8?1:2,h=c+u*2*m*l,p=new ArrayBuffer(h),f=new DataView(p),b=0,w=c,g=new Array(l),d=new Array(l),x=0;x<l;x++)g[x]=1/0,d[x]=-1/0;var y=e.bits===8?zo:Xo,C=e.bits===8?Lo:Ho;f.setInt32(0,2,!0),f.setUint32(4,e.bits===8,!0),f.setInt32(8,s,!0),f.setInt32(12,t,!0),f.setInt32(16,u,!0),f.setInt32(20,l,!0);for(var k=0;k<r;k++){var S=0;if(l===1){for(var M=0;M<i.length;++M)S+=i[M][k];S=Math.floor(C*S*n/i.length),S<g[0]&&(g[0]=S,g[0]<y&&(g[0]=y)),S>d[0]&&(d[0]=S,d[0]>C&&(d[0]=C))}else for(var A=0;A<l;++A)S=Math.floor(C*i[A][k]*n),S<g[A]&&(g[A]=S,g[A]<y&&(g[A]=y)),S>d[A]&&(d[A]=S,d[A]>C&&(d[A]=C));if(++b===t){for(var E=0;E<l;E++)e.bits===8?(f.setInt8(w++,g[E]),f.setInt8(w++,d[E])):(f.setInt16(w,g[E],!0),f.setInt16(w+2,d[E],!0),w+=4),g[E]=1/0,d[E]=-1/0;b=0}}if(b>0)for(var _=0;_<l;_++)e.bits===8?(f.setInt8(w++,g[_]),f.setInt8(w++,d[_])):(f.setInt16(w,g[_],!0),f.setInt16(w+2,d[_],!0));return p}function Rt(e){"@babel/helpers - typeof";return Rt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Rt(e)}function No(e){return e&&Rt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Yo(e){var t=e&&Rt(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),a=n.getInt32(0,!0);if(a!==1&&a!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function Uo(e){var t=e.data,n=e.channels||1,a=24,r=e.bits===8?1:2,s=e.length*2*n;if(t.length!==s)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var i=a+t.length*r,l=new ArrayBuffer(i),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=a;if(e.bits===8)for(var m=0;m<t.length;m++)c.setInt8(u++,t[m],!0);else for(var h=0;h<t.length;h++)c.setInt16(u,t[h],!0),u+=2;return l}function ft(e){return e==null}function Ko(e,t){var n=atob(e);return n}function qo(e,t,n){var a=Ko(e),r=a.indexOf(`
798
+ `,10)+1,s=a.substring(r)+"",i=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(i)}function Jo(e,t,n){var a;return function(s){return a=a||qo(e),new Worker(a,s)}}var Qo=Jo("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function Ze(e){if(No(e)&&(e=Uo(e)),Yo(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new lt(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var gt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function es(e){var t={scale:e.scale||gt.scale,bits:e.bits||gt.bits,amplitude_scale:e.amplitude_scale||gt.amplitude_scale,split_channels:e.split_channels||gt.split_channels,disable_worker:e.disable_worker||gt.disable_worker};return t}function ts(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function va(e,t,n){var a=ts(e);if(t.disable_worker){var r=Go({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a});n(void 0,new Ze(r),e)}else{var s=new Qo;s.onmessage=function(i){n(void 0,new Ze(i.data),e)},s.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a},a)}}function ns(e,t,n,a){function r(i){i||(i=new DOMException("EncodingError")),a(i),a=function(){}}var s=e.decodeAudioData(t,function(i){va(i,n,a)},r);s&&s.catch(r)}Ze.create=function(t){return new Ze(t)};Ze.createFromAudio=function(e,t){var n=es(e);if(e.audio_context&&e.array_buffer)return ns(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return va(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Ft(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),a=24,r=this._inputData.bits===8?1:2,s=a+n*2*this._inputData.channels*r;this._output_data=new ArrayBuffer(s),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new Ze(this._output_data),this._input_index=0,this._output_index=0;var i=this._inputData.channels;this._min=new Array(i),this._max=new Array(i);for(var l=0;l<i;++l)this._input_buffer_size>0?(this._min[l]=this._inputData.channel(l).min_sample(this._input_index),this._max[l]=this._inputData.channel(l).max_sample(this._input_index)):(this._min[l]=0,this._max[l]=0);this._min_value=this._inputData.bits===8?-128:-32768,this._max_value=this._inputData.bits===8?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}Ft.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Ft.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,a;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var r=0;r<n;++r)a=this._outputWaveformData.channel(r),a.set_min_sample(this._output_index-1,this._min[r]),a.set_max_sample(this._output_index-1,this._max[r]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var s=0;s<n;++s)this._min[s]=this._max_value,this._max[s]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var i=0;i<n;++i){a=this._inputData.channel(i);var l=a.min_sample(this._input_index);l<this._min[i]&&(this._min[i]=l),l=a.max_sample(this._input_index),l>this._max[i]&&(this._max[i]=l)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var c=0;c<n;++c)a=this._outputWaveformData.channel(c),a.set_min_sample(this._output_index-1,this._min[c]),a.set_max_sample(this._output_index-1,this._max[c]);return!0};Ft.prototype.getOutputData=function(){return this._output_data};Ze.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!ft(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!ft(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new Ft(t);!n.next(););return new Ze(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(r){if(t.channels!==r.channels||t.sample_rate!==r.sample_rate||t.bits!==r.bits||t.scale!==r.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var a=this._concatBuffers.apply(this,n);return Ze.create(a)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,a=n,r=0,s=[this].concat(t).map(function(d){return d._data.buffer}),i=0;i<s.length;i++){var l=s[i],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),m=new DataView(s[0]),h=new DataView(u),p=0;p<n;p++)h.setUint8(p,m.getUint8(p));h.setInt32(16,r,!0);for(var f=0,b=new Uint8Array(u,n),w=0;w<s.length;w++){var g=s[w];b.set(new Uint8Array(g,n),f),f+=g.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!ft(t.startIndex)&&!ft(t.endIndex)?(n=t.startIndex,a=t.endIndex):!ft(t.startTime)&&!ft(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,s=24,i=this.bits===8?1:2,l=s+r*2*this.channels*i,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var m=0;m<r*this.channels*2;m++){var h=this._at(n*this.channels*2+m);this.bits===8?u.setInt8(s+m,h):u.setInt16(s+m*2,h,!0)}return new Ze(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var a=0;a<this.channels;a++)t.data.push(this.channel(a).min_sample(n)),t.data.push(this.channel(a).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function nn(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const a=await t.arrayBuffer();return Ze.create(a)}else{const a=await t.json();return Ze.create(a)}}function Ca(e,t=0){const n=e.channel(t),a=e.bits,r=n.min_array(),s=n.max_array(),i=r.length,l=a===8?new Int8Array(i*2):new Int16Array(i*2);for(let c=0;c<i;c++)l[c*2]=r[c],l[c*2+1]=s[c];return{data:l,bits:a,length:i,sampleRate:e.sample_rate}}async function as(e,t=0){const n=await nn(e);return Ca(n,t)}async function rs(e){const t=await nn(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function os(e,t,n=0,a,r){let s=e;if(r!==void 0){const p=e.scale,f=Math.floor(a/p),b=Math.ceil((a+r)/p);s=s.slice({startIndex:f,endIndex:b})}s.scale!==t&&(s=s.resample({scale:t}));const i=s.channel(n),l=s.bits,c=i.min_array(),u=i.max_array(),m=c.length,h=l===8?new Int8Array(m*2):new Int16Array(m*2);for(let p=0;p<m;p++)h[p*2]=c[p],h[p*2+1]=u[p];return{data:h,bits:l,length:m}}function Vn(e,t,n,a,r){let s=e;if(a!==void 0&&r!==void 0){const m=e.scale,h=Math.floor(a/m),p=Math.ceil((a+r)/m);s=s.slice({startIndex:h,endIndex:p})}s.scale!==t&&(s=s.resample({scale:t}));const i=s.channels,l=s.bits,c=[];for(let m=0;m<i;m++){const h=s.channel(m),p=h.min_array(),f=h.max_array(),b=p.length,w=l===8?new Int8Array(b*2):new Int16Array(b*2);for(let g=0;g<b;g++)w[g*2]=p[g],w[g*2+1]=f[g];c.push(w)}if(n&&c.length>1){const m=1/c.length,h=c[0].length/2,p=l===8?new Int8Array(h*2):new Int16Array(h*2);for(let f=0;f<h;f++){let b=0,w=0;for(let g=0;g<c.length;g++)b+=m*c[g][f*2],w+=m*c[g][f*2+1];p[f*2]=b,p[f*2+1]=w}return{length:h,data:[p],bits:l}}return{length:c.length>0?c[0].length/2:0,data:c,bits:l}}function wa(){const[e,t]=o.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>mt(r,e),parseTime:r=>fa(r,e)}}const ss=[256,512,1024,2048,4096,8192];function ya({initialSamplesPerPixel:e,zoomLevels:t=ss}){const[n,a]=o.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),r=t[n],s=n>0,i=n<t.length-1,l=o.useCallback(()=>{o.startTransition(()=>{a(u=>Math.max(0,u-1))})},[]),c=o.useCallback(()=>{o.startTransition(()=>{a(u=>Math.min(t.length-1,u+1))})},[t.length]);return{samplesPerPixel:r,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:i}}function xa({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[a,r]=o.useState(t),s=o.useCallback(i=>{r(i),e.current&&e.current.setMasterGain(i),n?.(i)},[e,n]);return{masterVolume:a,setMasterVolume:s}}const is=(e=256)=>{const t=o.useRef(null),n=o.useCallback((a,r,s)=>{const i=new Z.Analyser("fft",e);return a.connect(i),a.connect(r),t.current=i,function(){i.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function ls(e,t={}){const{progressive:n=!1}=t,[a,r]=o.useState([]),[s,i]=o.useState(!0),[l,c]=o.useState(null),[u,m]=o.useState(0),h=e.length;return o.useEffect(()=>{if(e.length===0){r([]),i(!1),m(0);return}let p=!1;const f=new AbortController,b=new Map,w=(d,x,y)=>{const C=y??d.audioBuffer;if(!C&&!d.waveformData)throw new Error(`Track ${x+1}: Must provide src, audioBuffer, or waveformData`);const k=C?.duration??d.waveformData?.duration,S=Gn({audioBuffer:C,startTime:d.startTime??0,duration:d.duration??k,offset:d.offset??0,name:d.name||`Track ${x+1}`,fadeIn:d.fadeIn,fadeOut:d.fadeOut,waveformData:d.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${x+1}`);return{...Nn({name:d.name||`Track ${x+1}`,clips:[S],muted:d.muted??!1,soloed:d.soloed??!1,volume:d.volume??1,pan:d.pan??0,color:d.color}),effects:d.effects,renderMode:d.renderMode,spectrogramConfig:d.spectrogramConfig,spectrogramColorMap:d.spectrogramColorMap}};return(async()=>{try{i(!0),c(null),m(0);const d=On.getContext().rawContext,x=e.map(async(C,k)=>{if(C.audioBuffer){const _=w(C,k,C.audioBuffer);return n&&!p&&(b.set(k,_),m(I=>I+1),r(Array.from({length:e.length},(I,B)=>b.get(B)).filter(I=>I!==void 0))),_}if(!C.src&&C.waveformData){const _=w(C,k);return n&&!p&&(b.set(k,_),m(I=>I+1),r(Array.from({length:e.length},(I,B)=>b.get(B)).filter(I=>I!==void 0))),_}if(!C.src)throw new Error(`Track ${k+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(C.src,{signal:f.signal});if(!S.ok)throw new Error(`Failed to fetch ${C.src}: ${S.statusText}`);const M=await S.arrayBuffer(),A=await d.decodeAudioData(M);if(!A||!A.sampleRate||!A.duration)throw new Error(`Invalid audio buffer for ${C.src}`);const E=w(C,k,A);return n&&!p&&(b.set(k,E),m(_=>_+1),r(Array.from({length:e.length},(_,I)=>b.get(I)).filter(_=>_!==void 0))),E}),y=await Promise.all(x);p||(n||(r(y),m(y.length)),i(!1))}catch(d){if(!p){const x=d instanceof Error?d.message:"Unknown error loading audio";c(x),i(!1),console.error("Error loading audio tracks:",d)}}})(),()=>{p=!0,f.abort()}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:h}}function cs({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=o.useRef(null),s=o.useCallback(u=>{const{transform:m,active:h}=u;if(!h?.data?.current)return{...m,scaleX:1,scaleY:1};const{trackIndex:p,clipIndex:f,boundary:b}=h.data.current;if(b)return{...m,scaleX:1,scaleY:1};const w=e[p];if(!w)return{...m,scaleX:1,scaleY:1};const g=w.clips[f];if(!g)return{...m,scaleX:1,scaleY:1};const d=g.startSample/a,x=g.durationSamples/a,y=m.x*n/a;let C=d+y;const k=[...w.clips].sort((I,B)=>I.startSample-B.startSample),S=k.findIndex(I=>I===g);C=Math.max(0,C);const M=S>0?k[S-1]:null;if(M){const I=(M.startSample+M.durationSamples)/a;C=Math.max(C,I)}const A=S<k.length-1?k[S+1]:null;if(A){const I=C+x,B=A.startSample/a;I>B&&(C=B-x)}const _=(C-d)*a/n;return{...m,x:_,scaleX:1,scaleY:1}},[e,n,a]),i=o.useCallback(u=>{const{active:m}=u,{boundary:h}=m.data.current;if(!h){r.current=null;return}const{trackIndex:p,clipIndex:f}=m.data.current,w=e[p]?.clips[f];w&&(r.current={offsetSamples:w.offsetSamples,durationSamples:w.durationSamples,startSample:w.startSample})},[e]),l=o.useCallback(u=>{const{active:m,delta:h}=u,{boundary:p}=m.data.current;if(!p||!r.current)return;const{trackIndex:f,clipIndex:b}=m.data.current,w=h.x*n,g=Math.floor(.1*a),d=r.current,x=e.map((y,C)=>{if(C!==f)return y;const k=[...y.clips].sort((A,E)=>A.startSample-E.startSample),S=k.findIndex(A=>A===y.clips[b]),M=y.clips.map((A,E)=>{if(E!==b)return A;const _=A.sourceDurationSamples;if(p==="left"){let I=Math.floor(w);const B=-d.startSample;I<B&&(I=B);const $=-d.offsetSamples;I<$&&(I=$);const W=S>0?k[S-1]:null;if(W){const ae=W.startSample+W.durationSamples-d.startSample;I<ae&&(I=ae)}const z=d.durationSamples-g;I>z&&(I=z);const Y=d.offsetSamples+I,j=d.durationSamples-I,N=d.startSample+I;return{...A,offsetSamples:Y,durationSamples:j,startSample:N}}else{let I=Math.floor(d.durationSamples+w);I=Math.max(g,I),d.offsetSamples+I>_&&(I=_-d.offsetSamples);const B=S<k.length-1?k[S+1]:null;return B&&d.startSample+I>B.startSample&&(I=B.startSample-d.startSample,I=Math.max(g,I)),{...A,durationSamples:I}}});return{...y,clips:M}});t(x)},[e,t,n,a]),c=o.useCallback(u=>{const{active:m,delta:h}=u,{trackIndex:p,clipIndex:f,boundary:b}=m.data.current,w=h.x*n;if(b){r.current=null;return}const g=e.map((d,x)=>{if(x!==p)return d;const y=[...d.clips].sort((S,M)=>S.startSample-M.startSample),C=y.findIndex(S=>S===d.clips[f]),k=d.clips.map((S,M)=>{if(M!==f)return S;let A=Math.floor(S.startSample+w);A=Math.max(0,A);const E=C>0?y[C-1]:null;if(E){const I=E.startSample+E.durationSamples;A=Math.max(A,I)}const _=C<y.length-1?y[C+1]:null;return _&&A+S.durationSamples>_.startSample&&(A=_.startSample-S.durationSamples),{...S,startSample:A}});return{...d,clips:k}});t(g)},[e,t,n]);return{onDragStart:i,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Ht=.01;function ka({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const i=o.useRef(null),l=o.useCallback(m=>{const{active:h}=m,p=h.data.current;if(!p||p.annotationIndex===void 0){i.current=null;return}const f=e[p.annotationIndex];f&&(i.current={start:f.start,end:f.end,annotationIndex:p.annotationIndex})},[e]),c=o.useCallback(m=>{const{active:h,delta:p}=m;if(!i.current)return;const f=h.data.current;if(!f)return;const{edge:b,annotationIndex:w}=f,g=i.current,d=p.x*n/a,x=b==="start"?g.start+d:g.end+d,y=us({annotationIndex:w,newTime:x,isDraggingStart:b==="start",annotations:e,duration:r,linkEndpoints:s});t(y)},[e,t,n,a,r,s]),u=o.useCallback(()=>{i.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function us({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const i=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(i[e]={...l,start:c},s&&e>0){const m=i[e-1];Math.abs(m.end-l.start)<Ht?i[e-1]={...m,end:Math.max(m.start+.1,m.end+u)}:c<=m.end&&(i[e]={...i[e],start:m.end})}else!s&&e>0&&c<i[e-1].end&&(i[e-1]={...i[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(i[e]={...l,end:c},s&&e<i.length-1){const m=i[e+1];if(Math.abs(m.start-l.end)<Ht){const h=m.start+u;i[e+1]={...m,start:Math.min(m.end-.1,h)};let p=e+1;for(;p<i.length-1;){const f=i[p],b=i[p+1];if(Math.abs(b.start-f.end)<Ht){const w=f.end-a[p].end;i[p+1]={...b,start:Math.min(b.end-.1,b.start+w)},p++}else break}}else c>=m.start&&(i[e]={...i[e],end:m.start})}else if(!s&&e<i.length-1&&c>i[e+1].start){const m=i[e+1];i[e+1]={...m,start:c};let h=e+1;for(;h<i.length-1;){const p=i[h],f=i[h+1];if(p.end>f.start)i[h+1]={...f,start:p.end},h++;else break}}}return i}function ds(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Ke.useSensor(Ke.MouseSensor,{activationConstraint:{distance:r}}),i=Ke.useSensor(Ke.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Ke.useSensor(Ke.PointerSensor,{activationConstraint:{distance:r}});return Ke.useSensors(...t?[s,i]:[l])}const fs=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Re(),{selectedTrackId:s}=De(),i=o.useCallback((c,u,m)=>{const{sampleRate:h,samplesPerPixel:p}=e,f=t[c];if(!f)return!1;const b=f.clips[u];if(!b)return!1;const w=b.startSample/h,g=(b.startSample+b.durationSamples)/h;if(m<=w||m>=g)return console.warn("Split time is outside clip bounds"),!1;const d=Math.round(m*h),x=Math.floor(d/p),y=b.startSample+b.durationSamples,C=x*p,k=b.startSample,S=C-k,M=C,A=y-M,E=C-b.startSample,_=Gt({audioBuffer:b.audioBuffer,startSample:k,durationSamples:S,offsetSamples:b.offsetSamples,sampleRate:b.sampleRate,sourceDurationSamples:b.sourceDurationSamples,gain:b.gain,name:b.name?`${b.name} (1)`:void 0,color:b.color,fadeIn:b.fadeIn,waveformData:b.waveformData}),I=Gt({audioBuffer:b.audioBuffer,startSample:M,durationSamples:A,offsetSamples:b.offsetSamples+E,sampleRate:b.sampleRate,sourceDurationSamples:b.sourceDurationSamples,gain:b.gain,name:b.name?`${b.name} (2)`:void 0,color:b.color,waveformData:b.waveformData,fadeOut:b.fadeOut}),B=[...f.clips];B.splice(u,1,_,I);const $=[...t];return $[c]={...f,clips:B},n($),!0},[t,n,e]);return{splitClipAtPlayhead:o.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(h=>h.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],m=r.current??0;for(let h=0;h<u.clips.length;h++){const p=u.clips[h],f=p.startSample/a,b=(p.startSample+p.durationSamples)/a;if(m>f&&m<b)return console.log(`Splitting clip on track "${u.name}" at ${m}s`),i(c,h,m)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,i,a]),splitClipAt:i}},Dt=e=>{const{shortcuts:t,enabled:n=!0}=e,a=o.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const i=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,m=l.shiftKey===void 0||r.shiftKey===l.shiftKey,h=l.metaKey===void 0||r.metaKey===l.metaKey,p=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&m&&h&&p});i&&(i.preventDefault!==!1&&r.preventDefault(),i.action())},[t,n]);o.useEffect(()=>{if(n)return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[a,n])},ms=e=>{const t=[],n=typeof navigator<"u"&&navigator.platform.includes("Mac");return e.metaKey&&t.push(n?"Cmd":"Ctrl"),e.ctrlKey&&!e.metaKey&&t.push("Ctrl"),e.altKey&&t.push(n?"Option":"Alt"),e.shiftKey&&t.push("Shift"),t.push(e.key.toUpperCase()),t.join("+")},hs=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Re(),{setCurrentTime:s,play:i,pause:l,stop:c}=be(),{playoutRef:u}=Me(),m=o.useCallback(()=>{r?l():i()},[r,i,l]),h=o.useCallback(()=>{c()},[c]),p=o.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),i(0)):s(0)},[r,u,s,i]),b=a??[...[{key:" ",action:m,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:h,description:"Stop",preventDefault:!0},{key:"0",action:p,description:"Rewind to start",preventDefault:!0}],...n];return Dt({shortcuts:b,enabled:t}),{rewindToStart:p,togglePlayPause:m,stopPlayback:h,shortcuts:b}},Xt=.01,_t=.01;function ps({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:i=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:m,controlsWidth:h=0,onPlay:p}){const f=o.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),b=o.useCallback(E=>{if(!c?.current||!u||!m)return;const _=e.find(L=>L.id===E);if(!_)return;const I=c.current,B=I.clientWidth,$=_.start*m/u+h,W=_.end*m/u+h,z=($+W)/2,Y=I.scrollLeft,j=Y,N=Y+B;if($<j||W>N){const L=Math.max(0,z-B/2);I.scrollTo({left:L,behavior:"smooth"})}},[e,c,u,m,h]);o.useEffect(()=>{t&&c?.current&&u&&m&&b(t)},[t,b,c,u,m]);const w=o.useCallback(E=>{if(f<0)return;const _=e[f],I=Math.max(0,Math.min(_.end-.1,_.start+E)),B=I-_.start,$=[...e];if($[f]={..._,start:I},s&&f>0){const W=$[f-1];Math.abs(W.end-_.start)<Xt&&($[f-1]={...W,end:Math.max(W.start+.1,W.end+B)})}else if(!s&&f>0){const W=$[f-1];I<W.end&&($[f-1]={...W,end:I})}n($)},[e,f,s,n]),g=o.useCallback(E=>{if(f<0)return;const _=e[f],I=Math.max(_.start+.1,Math.min(r,_.end+E)),B=I-_.end,$=[...e];if($[f]={..._,end:I},s&&f<e.length-1){const W=$[f+1];if(Math.abs(W.start-_.end)<Xt){const z=Math.min(W.end-.1,W.start+B);$[f+1]={...W,start:z};let Y=f+1;for(;Y<$.length-1;){const j=$[Y],N=$[Y+1];if(Math.abs(N.start-e[Y].end)<Xt){const L=j.end-e[Y].end;$[Y+1]={...N,start:Math.min(N.end-.1,N.start+L)},Y++}else break}}}else if(!s&&f<e.length-1){const W=$[f+1];if(I>W.start){$[f+1]={...W,start:I};let z=f+1;for(;z<$.length-1;){const Y=$[z],j=$[z+1];if(Y.end>j.start)$[z+1]={...j,start:Y.end},z++;else break}}}n($)},[e,f,r,s,n]),d=o.useCallback(()=>{!a||e.length===0||(f<=0?a(e[e.length-1].id):a(e[f-1].id))},[e,f,a]),x=o.useCallback(()=>{!a||e.length===0||(f<0||f>=e.length-1?a(e[0].id):a(e[f+1].id))},[e,f,a]),y=o.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),C=o.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),k=o.useCallback(()=>{a&&a(null)},[a]),S=o.useCallback(()=>{if(f<0||!p)return;const E=e[f],_=i?void 0:E.end-E.start;p(E.start,_)},[e,f,i,p]),M=o.useMemo(()=>[{key:"[",action:()=>w(-_t),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>w(_t),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>g(-_t),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>g(_t),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:S,description:"Play selected annotation",preventDefault:!0}],[w,g,S]),A=o.useMemo(()=>[{key:"ArrowUp",action:d,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:d,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:x,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:x,description:"Select next annotation",preventDefault:!0},{key:"Home",action:y,description:"Select first annotation",preventDefault:!0},{key:"End",action:C,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:k,description:"Deselect annotation",preventDefault:!0}],[d,x,y,C,k]);return Dt({shortcuts:M,enabled:l&&f>=0}),Dt({shortcuts:A,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:w,moveEndBoundary:g,selectPrevious:d,selectNext:x,selectFirst:y,selectLast:C,clearSelection:k,scrollToAnnotation:b,playActiveAnnotation:S}}const yt=[{id:"reverb",name:"Reverb",category:"reverb",description:"Simple convolution reverb with adjustable decay time",parameters:[{name:"decay",label:"Decay",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"s"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"freeverb",name:"Freeverb",category:"reverb",description:"Classic Schroeder/Moorer reverb with room size and dampening",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.7},{name:"dampening",label:"Dampening",type:"number",min:0,max:1e4,step:100,default:3e3,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"jcReverb",name:"JC Reverb",category:"reverb",description:"Attempt at Roland JC-120 chorus reverb emulation",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"feedbackDelay",name:"Feedback Delay",category:"delay",description:"Delay line with feedback for echo effects",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"pingPongDelay",name:"Ping Pong Delay",category:"delay",description:"Stereo delay bouncing between left and right channels",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"chorus",name:"Chorus",category:"modulation",description:"Creates thickness by layering detuned copies of the signal",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"Hz"},{name:"delayTime",label:"Delay",type:"number",min:0,max:20,step:.5,default:3.5,unit:"ms"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.7},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"phaser",name:"Phaser",category:"modulation",description:"Classic phaser effect using allpass filters",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:.5,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:6,step:1,default:3},{name:"baseFrequency",label:"Base Freq",type:"number",min:100,max:2e3,step:10,default:350,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"tremolo",name:"Tremolo",category:"modulation",description:"Rhythmic volume modulation",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:4,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"vibrato",name:"Vibrato",category:"modulation",description:"Pitch modulation effect",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:5,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoPanner",name:"Auto Panner",category:"modulation",description:"Automatic left-right panning",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoFilter",name:"Auto Filter",category:"filter",description:"Automated filter sweep with LFO",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:2e3,step:10,default:200,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:.5,max:8,step:.5,default:2.6},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoWah",name:"Auto Wah",category:"filter",description:"Envelope follower filter effect",parameters:[{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:500,step:10,default:100,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:8,step:1,default:6},{name:"sensitivity",label:"Sensitivity",type:"number",min:-40,max:0,step:1,default:0,unit:"dB"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"eq3",name:"3-Band EQ",category:"filter",description:"Three band equalizer with low, mid, and high controls",parameters:[{name:"low",label:"Low",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"mid",label:"Mid",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"high",label:"High",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"lowFrequency",label:"Low Freq",type:"number",min:20,max:500,step:10,default:400,unit:"Hz"},{name:"highFrequency",label:"High Freq",type:"number",min:1e3,max:1e4,step:100,default:2500,unit:"Hz"}]},{id:"distortion",name:"Distortion",category:"distortion",description:"Wave shaping distortion effect",parameters:[{name:"distortion",label:"Drive",type:"number",min:0,max:1,step:.01,default:.4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"bitCrusher",name:"Bit Crusher",category:"distortion",description:"Reduces bit depth for lo-fi digital texture",parameters:[{name:"bits",label:"Bits",type:"number",min:1,max:16,step:1,default:4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"chebyshev",name:"Chebyshev",category:"distortion",description:"Waveshaping distortion using Chebyshev polynomials",parameters:[{name:"order",label:"Order",type:"number",min:1,max:100,step:1,default:50},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"compressor",name:"Compressor",category:"dynamics",description:"Dynamic range compressor",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-60,max:0,step:1,default:-24,unit:"dB"},{name:"ratio",label:"Ratio",type:"number",min:1,max:20,step:.5,default:4},{name:"attack",label:"Attack",type:"number",min:0,max:1,step:.001,default:.003,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"knee",label:"Knee",type:"number",min:0,max:40,step:1,default:30,unit:"dB"}]},{id:"limiter",name:"Limiter",category:"dynamics",description:"Hard limiter to prevent clipping",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-12,max:0,step:.5,default:-6,unit:"dB"}]},{id:"gate",name:"Gate",category:"dynamics",description:"Noise gate to silence signal below threshold",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-100,max:0,step:1,default:-40,unit:"dB"},{name:"attack",label:"Attack",type:"number",min:0,max:.3,step:.001,default:.001,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:.5,step:.01,default:.1,unit:"s"}]},{id:"stereoWidener",name:"Stereo Widener",category:"spatial",description:"Expands or narrows the stereo image",parameters:[{name:"width",label:"Width",type:"number",min:0,max:1,step:.01,default:.5}]}],an=e=>yt.find(t=>t.id===e),gs=e=>yt.filter(t=>t.category===e),bs=[{id:"reverb",name:"Reverb"},{id:"delay",name:"Delay"},{id:"modulation",name:"Modulation"},{id:"filter",name:"Filter"},{id:"distortion",name:"Distortion"},{id:"dynamics",name:"Dynamics"},{id:"spatial",name:"Spatial"}];const vs={reverb:Z.Reverb,freeverb:Z.Freeverb,jcReverb:Z.JCReverb,feedbackDelay:Z.FeedbackDelay,pingPongDelay:Z.PingPongDelay,chorus:Z.Chorus,phaser:Z.Phaser,tremolo:Z.Tremolo,vibrato:Z.Vibrato,autoPanner:Z.AutoPanner,autoFilter:Z.AutoFilter,autoWah:Z.AutoWah,eq3:Z.EQ3,distortion:Z.Distortion,bitCrusher:Z.BitCrusher,chebyshev:Z.Chebyshev,compressor:Z.Compressor,limiter:Z.Limiter,gate:Z.Gate,stereoWidener:Z.StereoWidener};let Cs=0;const ws=()=>`effect_${Date.now()}_${++Cs}`;function bt(e,t){const n=vs[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(l=>{const c=t?.[l.name]??l.default;a[l.name]=c});const r=new n(a),s=ws(),i=r;return{effect:r,id:e.id,instanceId:s,dispose(){try{r.disconnect(),r.dispose()}catch(l){console.warn(`[waveform-playlist] Error disposing effect "${e.id}" (${s}):`,l)}},setParameter(l,c){const u=i[l];if(l==="wet"){const m=i.wet;if(m&&typeof m=="object"&&"value"in m){m.value=c;return}}u!==void 0&&(u&&typeof u=="object"&&"value"in u?u.value=c:i[l]=c)},getParameter(l){if(l==="wet"){const u=i.wet;if(u&&typeof u=="object"&&"value"in u)return u.value}const c=i[l];if(c!==void 0)return c&&typeof c=="object"&&"value"in c?c.value:c},connect(l){r.connect(l)},disconnect(){try{r.disconnect()}catch(l){console.warn(`[waveform-playlist] Error disconnecting effect "${e.id}" (${s}):`,l)}}}}function ys(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function xs(e=256){const[t,n]=o.useState([]),a=o.useRef(t);a.current=t;const r=o.useRef(new Map),s=o.useRef(null),i=o.useRef(null),l=o.useCallback(g=>{const d=i.current;if(!d)return;const{masterGainNode:x,destination:y,analyserNode:C}=d;try{x.disconnect()}catch(S){console.warn("[waveform-playlist] Error disconnecting master effects chain:",S)}const k=g.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)x.connect(C),C.connect(y);else{let S=x;k.forEach(M=>{try{M.disconnect()}catch(A){console.warn(`[waveform-playlist] Error disconnecting effect "${M.id}":`,A)}S.connect(M.effect),S=M.effect}),S.connect(C),C.connect(y)}},[]),c=o.useCallback(g=>{const d=an(g);if(!d){console.error(`Unknown effect: ${g}`);return}const x={};d.parameters.forEach(k=>{x[k.name]=k.default});const y=bt(d,x);r.current.set(y.instanceId,y);const C={instanceId:y.instanceId,effectId:d.id,definition:d,params:x,bypassed:!1};n(k=>[...k,C])},[]),u=o.useCallback(g=>{const d=r.current.get(g);d&&(d.dispose(),r.current.delete(g)),n(x=>x.filter(y=>y.instanceId!==g))},[]),m=o.useCallback((g,d,x)=>{const y=r.current.get(g);y&&y.setParameter(d,x),n(C=>C.map(k=>k.instanceId===g?{...k,params:{...k.params,[d]:x}}:k))},[]),h=o.useCallback(g=>{const d=a.current.find(C=>C.instanceId===g);if(!d)return;const x=!d.bypassed,y=r.current.get(g);if(y){const C=d.params.wet??1;y.setParameter("wet",x?0:C)}n(C=>C.map(k=>k.instanceId===g?{...k,bypassed:x}:k))},[]),p=o.useCallback((g,d)=>{n(x=>{const y=[...x],[C]=y.splice(g,1);return y.splice(d,0,C),y})},[]),f=o.useCallback(()=>{r.current.forEach(g=>g.dispose()),r.current.clear(),n([])},[]);o.useEffect(()=>{l(t)},[t,l]);const b=o.useCallback((g,d,x)=>{const y=new Z.Analyser("fft",e);s.current=y,i.current={masterGainNode:g,destination:d,analyserNode:y};const k=a.current.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)g.connect(y),y.connect(d);else{let S=g;k.forEach(M=>{S.connect(M.effect),S=M.effect}),S.connect(y),y.connect(d)}return function(){y.dispose(),s.current=null,i.current=null}},[e]);o.useEffect(()=>{const g=r.current;return()=>{g.forEach(d=>d.dispose()),g.clear()}},[]);const w=o.useCallback(()=>{const g=t.filter(d=>!d.bypassed);if(g.length!==0)return(d,x,y)=>{const C=[];for(const k of g){const S=bt(k.definition,k.params);C.push(S)}if(C.length===0)d.connect(x);else{let k=d;C.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(x)}return function(){C.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:yt,addEffect:c,removeEffect:u,updateParameter:m,toggleBypass:h,reorderEffects:p,clearAllEffects:f,masterEffects:b,createOfflineEffectsFunction:w,analyserRef:s}}function ks(){const[e,t]=o.useState(new Map),n=o.useRef(new Map),a=o.useRef(new Map),r=o.useCallback((f,b)=>{const w=a.current.get(f);if(!w)return;const{graphEnd:g,masterGainNode:d}=w,x=n.current.get(f);try{g.disconnect()}catch(C){console.warn(`[waveform-playlist] Error disconnecting track "${f}" effect chain:`,C)}const y=b.map(C=>x?.get(C.instanceId)).filter(C=>C!==void 0);if(y.length===0)g.connect(d);else{let C=g;y.forEach(k=>{try{k.disconnect()}catch(S){console.warn(`[waveform-playlist] Error disconnecting effect "${k.id}" on track "${f}":`,S)}C.connect(k.effect),C=k.effect}),C.connect(d)}},[]),s=o.useCallback((f,b)=>{const w=an(b);if(!w){console.error(`Unknown effect: ${b}`);return}const g={};w.parameters.forEach(y=>{g[y.name]=y.default});const d=bt(w,g);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(d.instanceId,d);const x={instanceId:d.instanceId,effectId:w.id,definition:w,params:g,bypassed:!1};t(y=>{const C=new Map(y),k=C.get(f)||[];return C.set(f,[...k,x]),C})},[]),i=o.useCallback((f,b)=>{const w=n.current.get(f),g=w?.get(b);g&&(g.dispose(),w?.delete(b)),t(d=>{const x=new Map(d),y=x.get(f)||[];return x.set(f,y.filter(C=>C.instanceId!==b)),x})},[]),l=o.useCallback((f,b,w,g)=>{const x=n.current.get(f)?.get(b);x&&x.setParameter(w,g),t(y=>{const C=new Map(y),k=C.get(f)||[];return C.set(f,k.map(S=>S.instanceId===b?{...S,params:{...S.params,[w]:g}}:S)),C})},[]),c=o.useCallback((f,b)=>{const g=(m.current.get(f)||[]).find(C=>C.instanceId===b);if(!g)return;const d=!g.bypassed,y=n.current.get(f)?.get(b);if(y){const C=g.params.wet??1;y.setParameter("wet",d?0:C)}t(C=>{const k=new Map(C),S=k.get(f)||[];return k.set(f,S.map(M=>M.instanceId===b?{...M,bypassed:d}:M)),k})},[]),u=o.useCallback(f=>{const b=n.current.get(f);b&&(b.forEach(w=>w.dispose()),b.clear()),t(w=>{const g=new Map(w);return g.set(f,[]),g})},[]),m=o.useRef(e);m.current=e;const h=o.useCallback(f=>(b,w,g)=>{a.current.set(f,{graphEnd:b,masterGainNode:w});const d=m.current.get(f)||[],x=n.current.get(f),y=d.map(C=>x?.get(C.instanceId)).filter(C=>C!==void 0);if(y.length===0)b.connect(w);else{let C=b;y.forEach(k=>{C.connect(k.effect),C=k.effect}),C.connect(w)}return function(){a.current.delete(f)}},[]);o.useEffect(()=>{e.forEach((f,b)=>{r(b,f)})},[e,r]),o.useEffect(()=>{const f=n.current;return()=>{f.forEach(b=>{b.forEach(w=>w.dispose()),b.clear()}),f.clear()}},[]);const p=o.useCallback(f=>{const w=(e.get(f)||[]).filter(g=>!g.bypassed);if(w.length!==0)return(g,d,x)=>{const y=[];for(const C of w){const k=bt(C.definition,C.params);y.push(k)}if(y.length===0)g.connect(d);else{let C=g;y.forEach(k=>{C.connect(k.effect),C=k.effect}),C.connect(d)}return function(){y.forEach(k=>k.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:i,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:h,createOfflineTrackEffectsFunction:p,availableEffects:yt}}function Ss(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,i=n/8,l=a*i,c=r*l,u=s*l,m=44,h=m+u,p=new ArrayBuffer(h),f=new DataView(p);Et(f,0,"RIFF"),f.setUint32(4,h-8,!0),Et(f,8,"WAVE"),Et(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,n===32?3:1,!0),f.setUint16(22,a,!0),f.setUint32(24,r,!0),f.setUint32(28,c,!0),f.setUint16(32,l,!0),f.setUint16(34,n,!0),Et(f,36,"data"),f.setUint32(40,u,!0);const b=[];for(let g=0;g<a;g++)b.push(e.getChannelData(g));let w=m;if(n===16)for(let g=0;g<s;g++)for(let d=0;d<a;d++){const x=b[d][g],y=Math.max(-1,Math.min(1,x)),C=y<0?y*32768:y*32767;f.setInt16(w,C,!0),w+=2}else for(let g=0;g<s;g++)for(let d=0;d<a;d++)f.setFloat32(w,b[d][g],!0),w+=4;return new Blob([p],{type:"audio/wav"})}function Et(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function Is(e,t){const n=URL.createObjectURL(e),a=document.createElement("a");a.href=n,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}function Sa(){const[e,t]=o.useState(!1),[n,a]=o.useState(0),[r,s]=o.useState(null);return{exportWav:o.useCallback(async(l,c,u={})=>{const{filename:m="export",mode:h="master",trackIndex:p,autoDownload:f=!0,applyEffects:b=!0,effectsFunction:w,createOfflineTrackEffects:g,bitDepth:d=16,onProgress:x}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(h==="individual"&&(p===void 0||p<0||p>=l.length))throw new Error("Invalid track index for individual export");const y=l[0].clips[0]?.sampleRate||44100;let C=0;for(const I of l)for(const B of I.clips){const $=B.startSample+B.durationSamples;C=Math.max(C,$)}C+=Math.round(y*.1);const k=C/y,S=h==="individual"?[{track:l[p],state:c[p],index:p}]:l.map((I,B)=>({track:I,state:c[B],index:B})),M=c.some(I=>I.soloed),A=!!g;let E;if((w||A)&&b)E=await As(S,c,M,k,y,w,g,I=>{a(I),x?.(I)});else{const I=new OfflineAudioContext(2,C,y);let B=0;const $=S.reduce((W,{track:z})=>W+z.clips.length,0);for(const{track:W,state:z}of S)if(!(z.muted&&!z.soloed)&&!(M&&!z.soloed))for(const Y of W.clips){await _s(I,Y,z,y,b),B++;const j=B/$*.5;a(j),x?.(j)}a(.5),x?.(.5),E=await I.startRendering()}a(.9),x?.(.9);const _=Ss(E,{bitDepth:d});if(a(1),x?.(1),f){const I=h==="individual"?`${m}_${l[p].name}`:m;Is(_,`${I}.wav`)}return{audioBuffer:E,blob:_,duration:k}}catch(y){const C=y instanceof Error?y.message:"Export failed";throw s(C),y}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function As(e,t,n,a,r,s,i,l){const{Offline:c,Volume:u,Gain:m,Panner:h,Player:p,ToneAudioBuffer:f}=await import("tone");l(.1);let b;try{b=await c(async({transport:w,destination:g})=>{const d=new u(0);let x;s?x=s(d,g,!0):d.connect(g);for(const{track:y,state:C}of e){if(C.muted&&!C.soloed||n&&!C.soloed)continue;const k=new u(Ms(C.volume)),S=new h(C.pan),M=new m(C.muted?0:1),A=i?.(y.id);A?A(M,d,!0):M.connect(d),S.connect(M),k.connect(S);for(const E of y.clips){const{audioBuffer:_,startSample:I,durationSamples:B,offsetSamples:$,gain:W,fadeIn:z,fadeOut:Y}=E,j=I/r,N=B/r,L=$/r,ae=new f(_),oe=new p(ae),q=new m(W);if(oe.connect(q),q.connect(k),z){const fe=j,ue=j+z.duration,le=Tt(q.gain);le&&(le.setValueAtTime(0,fe),le.linearRampToValueAtTime(W,ue))}if(Y){const fe=j+N-Y.duration,ue=j+N,le=Tt(q.gain);le&&(le.setValueAtTime(W,fe),le.linearRampToValueAtTime(0,ue))}oe.start(j,L,N)}}w.start(0)},a,2,r)}catch(w){throw w instanceof Error?w:new Error(`Tone.Offline rendering failed: ${String(w)}`)}return l(.9),b.get()}function Ms(e){return 20*Math.log10(Math.max(e,1e-4))}async function _s(e,t,n,a,r){const{audioBuffer:s,startSample:i,durationSamples:l,offsetSamples:c,gain:u,fadeIn:m,fadeOut:h}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const p=i/a,f=l/a,b=c/a,w=e.createBufferSource();w.buffer=s;const g=e.createGain(),d=u*n.volume,x=e.createStereoPanner();if(x.pan.value=n.pan,w.connect(g),g.connect(x),x.connect(e.destination),r){if(m?g.gain.setValueAtTime(0,p):g.gain.setValueAtTime(d,p),m){const y=p,C=p+m.duration;jn(g.gain,y,C,0,d,m.type||"linear")}if(h){const y=p+f-h.duration,C=p+f;(!m||m.duration<f-h.duration)&&g.gain.setValueAtTime(d,y),jn(g.gain,y,C,d,0,h.type||"linear")}}else g.gain.setValueAtTime(d,p);w.start(p,b,f)}function jn(e,t,n,a,r,s){const i=n-t;if(!(i<=0))switch(s){case"linear":e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n);break;case"exponential":{const l=Math.max(a,1e-4),c=Math.max(r,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),r===0&&e.setValueAtTime(0,n);break}case"logarithmic":{const l=Ln(a,r,256,"logarithmic");e.setValueCurveAtTime(l,t,i);break}case"sCurve":{const l=Ln(a,r,256,"sCurve");e.setValueCurveAtTime(l,t,i);break}default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function Ln(e,t,n,a){const r=new Float32Array(n),s=t-e;for(let i=0;i<n;i++){const l=i/(n-1);let c;a==="logarithmic"?s>0?c=Math.log10(1+l*9)/Math.log10(10):c=1-Math.log10(1+(1-l)*9)/Math.log10(10):c=l*l*(3-2*l),r[i]=e+s*c}return r}const Ia=()=>{const e=o.useRef(null),t=o.useCallback(()=>{e.current!==null&&(cancelAnimationFrame(e.current),e.current=null)},[]),n=o.useCallback(a=>{t(),e.current=requestAnimationFrame(a)},[t]);return o.useEffect(()=>()=>{t()},[t]),{animationFrameRef:e,startAnimationFrameLoop:n,stopAnimationFrameLoop:t}},Es=`
784
799
  "use strict";
785
800
 
786
801
  var INT8_MAX = 127;
@@ -927,13 +942,13 @@ self.onmessage = function(e) {
927
942
  self.postMessage({ id: msg.id, error: err.message || String(err) });
928
943
  }
929
944
  };
930
- `;let Co=0;function wo(){let e;try{const a=new Blob([yo],{type:"application/javascript"}),r=URL.createObjectURL(a);e=new Worker(r),URL.revokeObjectURL(r)}catch(a){return console.warn("[waveform-playlist] Failed to create peaks worker (CSP restriction?):",a),{generate(){return Promise.reject(new Error("Worker creation failed"))},terminate(){}}}const t=new Map;let n=!1;return e.onmessage=a=>{const r=a.data,o=t.get(r.id);if(o)if(t.delete(r.id),r.error)o.reject(new Error(r.error));else try{const i=je.create(r.buffer);o.resolve(i)}catch(i){o.reject(i)}},e.onerror=a=>{n=!0,e.terminate();for(const[,r]of t)r.reject(a.error??new Error(a.message));t.clear()},{generate(a){if(n)return Promise.reject(new Error("Worker terminated"));const r=String(++Co);return new Promise((o,i)=>{t.set(r,{resolve:o,reject:i}),e.postMessage({id:r,scale:a.scale,bits:a.bits,amplitude_scale:1,split_channels:a.splitChannels,length:a.length,sample_rate:a.sampleRate,channels:a.channels},a.channels)})},terminate(){n=!0,e.terminate();for(const[,a]of t)a.reject(new Error("Worker terminated"));t.clear()}}}function xo(e,t){const[n,a]=s.useState(()=>new Map),[r,o]=s.useState(!1),i=s.useRef(null),l=s.useRef(new Set),c=s.useRef(0),u=s.useCallback(()=>(i.current||(i.current=wo()),i.current),[]);return s.useEffect(()=>{let f=!1;const v=l.current,h=[];for(const y of e)for(const p of y.clips)p.audioBuffer&&!p.waveformData&&!v.has(p.id)&&h.push({clipId:p.id,audioBuffer:p.audioBuffer});if(h.length===0)return;const d=new Set;for(const{clipId:y}of h)v.add(y),d.add(y);c.current+=h.length,o(!0);const C=u();for(const{clipId:y,audioBuffer:p}of h){const m=[];for(let k=0;k<p.numberOfChannels;k++)m.push(p.getChannelData(k).slice().buffer);C.generate({id:y,channels:m,length:p.length,sampleRate:p.sampleRate,scale:t,bits:16,splitChannels:!0}).then(k=>{f||(a(w=>{const b=new Map(w);return b.set(y,k),b}),c.current--,c.current<=0&&(c.current=0,o(!1)))}).catch(k=>{f||(console.warn("[waveform-playlist] Worker peak generation failed:",k),v.delete(y),c.current--,c.current<=0&&(c.current=0,o(!1)))})}return()=>{f=!0;for(const y of d)v.delete(y)}},[e,t,u]),s.useEffect(()=>()=>{i.current?.terminate(),i.current=null},[]),{cache:n,isGenerating:r}}const va=s.createContext(null),ya=s.createContext(null),Ca=s.createContext(null),wa=s.createContext(null),ko=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:o,automaticScroll:i=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:f,onReady:v,onAnnotationUpdate:h,onAnnotationsChange:d,barWidth:C=1,barGap:y=0,progressBarWidth:p,children:m})=>{const k=p??C+y,w=s.useMemo(()=>{if(!u?.annotations)return[];if(process.env.NODE_ENV!=="production"&&u.annotations.length>0){const F=u.annotations[0];if(typeof F.start!="number"||typeof F.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof F.start),[]}return u.annotations},[u?.annotations]),b=s.useRef(w);b.current=w;const[x,S]=s.useState(null),[E,I]=s.useState(!1),[$,M]=s.useState(0),[A,B]=s.useState(0),[_,R]=s.useState([]),[W,L]=s.useState([]),[P,U]=s.useState([]),[H,ne]=s.useState(0),[le,se]=s.useState(0),[oe,ye]=s.useState(null),[ce,fe]=s.useState(i),[O,N]=s.useState(u?.isContinuousPlay??!1),[be,K]=s.useState(u?.linkEndpoints??!1),[z,me]=s.useState(u?.editable??!1),[Ie,ae]=s.useState(!1),[Te,He]=s.useState(0),[Ye,Xe]=s.useState(0),[Q,Ke]=s.useState(!1),Z=s.useRef(null),ue=s.useRef(0),ie=s.useRef(0),Le=s.useRef(P),Ae=s.useRef(0),De=s.useRef(0),G=s.useRef(null),re=s.useRef(null),Re=s.useRef(!1),Be=s.useRef(u?.isContinuousPlay??!1),Me=s.useRef(null),Ue=s.useRef(r),lt=s.useRef(!1),ct=s.useRef(0),ht=s.useRef(0),V=s.useRef(0),Y=s.useRef(0),{timeFormat:ee,setTimeFormat:Ce,formatTime:ve}=da(),he=fa({initialSamplesPerPixel:r,zoomLevels:o}),_e=he.samplesPerPixel,{masterVolume:qe,setMasterVolume:te}=ma({playoutRef:Z,initialVolume:1}),{animationFrameRef:xe,startAnimationFrameLoop:Oe,stopAnimationFrameLoop:Je}=ba(),ut=s.useMemo(()=>Math.min(...o??[256,512,1024,2048,4096,8192]),[o]),{cache:Qe}=xo(e,ut),et=s.useCallback(F=>{Be.current=F,N(F)},[]),Pe=s.useCallback(F=>{Me.current=F,S(F)},[]),dt=s.useCallback(F=>{lt.current=F,ae(F)},[]),tt=s.useCallback((F,X)=>{V.current=F,Y.current=X,He(F),Xe(X)},[]),xt=s.useCallback(()=>{const F=ct.current,X=ht.current;F!==X&&X>F&&tt(F,X)},[tt]),kt=s.useCallback(()=>{tt(0,0)},[tt]);s.useEffect(()=>{Re.current=ce},[ce]),s.useEffect(()=>{Le.current=P},[P]),s.useEffect(()=>{ct.current=H,ht.current=le},[H,le]),s.useEffect(()=>{if(!re.current||!_.length)return;const F=re.current,X=Ue.current,J=_e;if(X===J)return;const q=c.show?c.width:0,de=F.clientWidth,Ee=F.scrollLeft+de/2-q,nt=_[0].sampleRate,Se=Ee*X/nt*nt/J,Ze=Math.max(0,Se+q-de/2);F.scrollLeft=Ze,Ue.current=J},[_e,_,c]);const St=s.useRef(null);s.useEffect(()=>{if(Ke(!1),e.length===0){R([]),B(0),U([]),L([]),Z.current&&(Z.current.dispose(),Z.current=null);return}const F=E,X=ie.current;return Z.current&&F&&(Z.current.stop(),Je(),St.current={position:X}),(async()=>{try{const q=[];e.forEach(ke=>{ke.clips.length>0&&ke.clips[0].audioBuffer&&q.push(ke.clips[0].audioBuffer)});let de=0;e.forEach(ke=>{ke.clips.forEach(Se=>{const Ze=Se.sampleRate,At=(Se.startSample+Se.durationSamples)/Ze;de=Math.max(de,At)})}),R(q),B(de),U(ke=>ke.length===e.length?ke.map((Se,Ze)=>({...Se,name:e[Ze].name})):e.map(Se=>({name:Se.name,muted:Se.muted,soloed:Se.soloed,volume:Se.volume,pan:Se.pan}))),Z.current&&Z.current.dispose();const we=new Ua({effects:f}),Ee=Le.current;e.forEach((ke,Se)=>{const Ze=ke.clips.filter(st=>st.audioBuffer);if(Ze.length>0){const st=Ze[0].sampleRate,At=Math.min(...Ze.map(Ve=>Ve.startSample/st)),Fa=Math.max(...Ze.map(Ve=>(Ve.startSample+Ve.durationSamples)/st)),Mt=Ee[Se],Wa={id:`track-${Se}`,name:ke.name,gain:Mt?.volume??ke.volume,muted:Mt?.muted??ke.muted,soloed:Mt?.soloed??ke.soloed,stereoPan:Mt?.pan??ke.pan,startTime:At,endTime:Fa},Pa=Ze.map(Ve=>{const zt=Ve.sampleRate;return{buffer:Ve.audioBuffer,startTime:Ve.startSample/zt-At,duration:Ve.durationSamples/zt,offset:Ve.offsetSamples/zt,fadeIn:Ve.fadeIn,fadeOut:Ve.fadeOut,gain:Ve.gain}});we.addTrack({clips:Pa,track:Wa,effects:ke.effects})}}),we.applyInitialSoloState(),Z.current=we,Ke(!0);const nt=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:de}});window.dispatchEvent(nt),v?.()}catch(q){console.error("Error loading audio:",q)}})(),()=>{Je(),Z.current&&Z.current.dispose()}},[e,v,E,f,Je]),s.useEffect(()=>{if(e.length===0)return;const F=e.map(X=>X.clips.map(q=>{let de;if(q.waveformData)try{de=Fn(q.waveformData,_e,n,q.offsetSamples,q.durationSamples)}catch(we){console.warn("[waveform-playlist] Failed to extract peaks from waveformData:",we)}if(!de){const we=Qe.get(q.id);if(we)try{de=Fn(we,_e,n,q.offsetSamples,q.durationSamples)}catch(Ee){console.warn("[waveform-playlist] Failed to extract peaks from cache:",Ee)}}return de||(!q.audioBuffer&&!q.waveformData&&console.warn(`[waveform-playlist] Clip "${q.id}" has no audio data or waveform data`),de={length:0,data:[],bits:16}),{clipId:q.id,trackName:X.name,peaks:de,startSample:q.startSample,durationSamples:q.durationSamples,fadeIn:q.fadeIn,fadeOut:q.fadeOut}}));L(F)},[e,_e,n,Qe]);const rt=s.useCallback(()=>{const F=()=>{const X=j.getContext().currentTime-Ae.current,J=De.current+X;ie.current=J;const q=b.current;if(q.length>0){const we=q.find(Ee=>J>=Ee.start&&J<Ee.end);if(Be.current)we&&we.id!==Me.current?Pe(we.id):!we&&Me.current!==null&&Pe(null);else if(Me.current){const Ee=q.find(nt=>nt.id===Me.current);if(Ee&&J>=Ee.end){Z.current&&Z.current.stop(),I(!1),ie.current=ue.current,M(ue.current);return}}else we&&Pe(we.id)}if(Re.current&&re.current&&_.length>0){const we=re.current,Ee=_[0].sampleRate,nt=J*Ee/Ue.current,ke=we.clientWidth,Se=c.show?c.width:0,Ze=nt+Se,st=Math.max(0,Ze-ke/2);we.scrollLeft=st}if(G.current!==null&&J>=G.current){Z.current&&Z.current.stop(),I(!1),ie.current=G.current,M(G.current),G.current=null;return}const de=V.current!==Y.current&&Y.current>V.current;if(lt.current&&de&&J>=Y.current){Z.current?.stop();const Ee=j.getContext().currentTime;Ae.current=Ee,De.current=V.current,ie.current=V.current,Z.current?.play(Ee,V.current),Oe(F);return}if(J>=A){Z.current&&Z.current.stop(),I(!1),ie.current=ue.current,M(ue.current),Pe(null);return}Oe(F)};Oe(F)},[A,_,c.show,c.width,Pe,Oe]),Ne=Je;s.useEffect(()=>{(async()=>{if(E&&xe.current&&Z.current)if(O){const X=ie.current;Z.current.stop(),Ne(),await Z.current.init(),Z.current.setOnPlaybackComplete(()=>{});const q=j.getContext().currentTime;Ae.current=q,De.current=X,Z.current.play(q,X),rt()}else Ne(),rt()})()},[O,E,rt,Ne,xe]),s.useEffect(()=>{(async()=>{if(St.current&&Z.current){const{position:X}=St.current;St.current=null,await Z.current.init(),Z.current.setOnPlaybackComplete(()=>{});const q=j.getContext().currentTime;Ae.current=q,De.current=X,Z.current.play(q,X),I(!0),rt()}})()},[e,rt]);const It=s.useCallback(async(F,X)=>{if(!Z.current||_.length===0)return;await Z.current.init();const J=F??ie.current;ue.current=J,ie.current=J,Z.current.setOnPlaybackComplete(()=>{}),Z.current.stop(),Ne();const de=j.getContext().currentTime;Ae.current=de,De.current=J,G.current=X!==void 0?J+X:null,Z.current.play(de,J,X),I(!0),rt()},[_.length,rt,Ne]),rn=s.useCallback(()=>{if(!Z.current)return;const F=j.getContext().currentTime-Ae.current,X=De.current+F;Z.current.pause(),I(!1),Ne(),ie.current=X,M(X)},[Ne]),sn=s.useCallback(()=>{Z.current&&(Z.current.stop(),I(!1),Ne(),ie.current=ue.current,M(ue.current),Pe(null))},[Ne,Pe]),on=s.useCallback(F=>{const X=Math.max(0,Math.min(F,A));ie.current=X,M(X),E&&Z.current&&(Z.current.stop(),Ne(),It(X))},[A,E,It,Ne]),ln=s.useCallback((F,X)=>{const J=[...P];if(J[F]={...J[F],muted:X},U(J),Z.current){const q=`track-${F}`;Z.current.setMute(q,X)}},[P]),cn=s.useCallback((F,X)=>{const J=[...P];if(J[F]={...J[F],soloed:X},U(J),Z.current){const q=`track-${F}`;Z.current.setSolo(q,X)}},[P]),un=s.useCallback((F,X)=>{const J=[...P];if(J[F]={...J[F],volume:X},U(J),Z.current){const q=`track-${F}`,de=Z.current.getTrack(q);de&&de.setVolume(X)}},[P]),dn=s.useCallback((F,X)=>{const J=[...P];if(J[F]={...J[F],pan:X},U(J),Z.current){const q=`track-${F}`,de=Z.current.getTrack(q);de&&de.setPan(X)}},[P]),fn=s.useCallback((F,X)=>{ne(F),se(X),ie.current=F,M(F),E&&Z.current&&(Z.current.stop(),Z.current.play(j.getContext().currentTime,F))},[E]),mn=s.useCallback(F=>{re.current=F},[]),jt=s.useRef(d);jt.current=d;const hn=s.useCallback(F=>{const X=typeof F=="function"?F(b.current):F;if(!jt.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}jt.current(X)},[]),pn=_[0]?.sampleRate||44100,Lt=t?30:0,gn=e.length*a+Lt,$a=s.useMemo(()=>({isPlaying:E,currentTime:$,currentTimeRef:ie,playbackStartTimeRef:Ae,audioStartPositionRef:De}),[E,$,ie,Ae,De]),Ta=s.useMemo(()=>({continuousPlay:O,linkEndpoints:be,annotationsEditable:z,isAutomaticScroll:ce,isLoopEnabled:Ie,annotations:w,activeAnnotationId:x,selectionStart:H,selectionEnd:le,selectedTrackId:oe,loopStart:Te,loopEnd:Ye}),[O,be,z,ce,Ie,w,x,H,le,oe,Te,Ye]),bn=s.useCallback(F=>{ie.current=F,M(F)},[ie]),vn=s.useCallback(F=>{fe(F)},[]),Ra=s.useMemo(()=>({play:It,pause:rn,stop:sn,seekTo:on,setCurrentTime:bn,setTrackMute:ln,setTrackSolo:cn,setTrackVolume:un,setTrackPan:dn,setSelection:fn,setSelectedTrackId:ye,setTimeFormat:Ce,formatTime:ve,zoomIn:he.zoomIn,zoomOut:he.zoomOut,setMasterVolume:te,setAutomaticScroll:vn,setScrollContainer:mn,scrollContainerRef:re,setContinuousPlay:et,setLinkEndpoints:K,setAnnotationsEditable:me,setAnnotations:hn,setActiveAnnotationId:Pe,setLoopEnabled:dt,setLoopRegion:tt,setLoopRegionFromSelection:xt,clearLoopRegion:kt}),[It,rn,sn,on,bn,ln,cn,un,dn,fn,ye,Ce,ve,he.zoomIn,he.zoomOut,te,vn,mn,re,et,K,me,hn,Pe,dt,tt,xt,kt]),Da=s.useMemo(()=>({duration:A,audioBuffers:_,peaksDataArray:W,trackStates:P,tracks:e,sampleRate:pn,waveHeight:a,timeScaleHeight:Lt,minimumPlaylistHeight:gn,controls:c,playoutRef:Z,samplesPerPixel:_e,timeFormat:ee,masterVolume:qe,canZoomIn:he.canZoomIn,canZoomOut:he.canZoomOut,barWidth:C,barGap:y,progressBarWidth:k,isReady:Q,mono:n}),[A,_,W,P,e,pn,a,Lt,gn,c,Z,_e,ee,qe,he.canZoomIn,he.canZoomOut,C,y,k,Q,n]),Ba={...qn,...l};return g.jsx(D.ThemeProvider,{theme:Ba,children:g.jsx(va.Provider,{value:$a,children:g.jsx(ya.Provider,{value:Ta,children:g.jsx(Ca.Provider,{value:Ra,children:g.jsx(wa.Provider,{value:Da,children:m})})})})})},Fe=()=>{const e=s.useContext(va);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},We=()=>{const e=s.useContext(ya);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},ge=()=>{const e=s.useContext(Ca);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},$e=()=>{const e=s.useContext(wa);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e};var So=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate;const t=this.audioElement;"preservesPitch"in this.audioElement?t.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?t.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(t.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},Io=class{constructor(e={}){this.track=null,this._isPlaying=!1,this._masterVolume=e.masterVolume??1,this._playbackRate=e.playbackRate??1}async init(){}addTrack(e){return this.track&&(console.warn("MediaElementPlayout: Only one track is supported. Disposing previous track. For multi-track, use TonePlayout."),this.track.dispose()),this.track=new So({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const a=t??0;if(this._isPlaying=!0,this.track.play(a),n!==void 0){const r=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},r*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const xa=s.createContext(null),ka=s.createContext(null),Sa=s.createContext(null),Ia=s.createContext(null),Ao=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:o=!1,theme:i,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:f=0,progressBarWidth:v,onAnnotationsChange:h,onReady:d,children:C})=>{const y=v??u+f,[p,m]=s.useState(!1),[k,w]=s.useState(0),[b,x]=s.useState(0),[S,E]=s.useState([]),[I,$]=s.useState(r),M=s.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const G=c.annotations[0];if(typeof G.start!="number"||typeof G.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof G.start),[]}return c.annotations},[c?.annotations]),A=s.useRef(M);A.current=M;const[B,_]=s.useState(null),[R,W]=s.useState(c?.isContinuousPlay??!1),[L]=s.useState(t),[P,U]=s.useState(o),H=s.useRef(null),ne=s.useRef(0),le=s.useRef(R),se=s.useRef(null),oe=s.useRef(null),ye=s.useRef(o),ce=s.useRef(t),{startAnimationFrameLoop:fe,stopAnimationFrameLoop:O}=ba();s.useEffect(()=>{le.current=R},[R]),s.useEffect(()=>{ye.current=P},[P]);const N=s.useCallback(G=>{se.current=G,_(G)},[]),be=s.useCallback(G=>{le.current=G,W(G)},[]),K=s.useCallback(G=>{oe.current=G},[]),z=e.waveformData.sample_rate;s.useEffect(()=>{const G=new Io({playbackRate:r});G.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const re=G.getTrack(G.track?.id??"");return re&&re.setOnTimeUpdateCallback(Re=>{ne.current=Re}),G.setOnPlaybackComplete(()=>{O(),m(!1),N(null),ne.current=0,w(0)}),H.current=G,x(e.waveformData.duration),d?.(),()=>{O(),G.dispose()}},[e.source,e.waveformData,e.name,r,d,O,N]),s.useEffect(()=>{const G=Ns(e.waveformData,L,0,0,Math.ceil(e.waveformData.duration*z)),re={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:G.length,data:[G.data],bits:G.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*z)};E([[re]])},[e.waveformData,e.name,L,z]);const me=s.useCallback(()=>{const G=()=>{const re=H.current?.getCurrentTime()??0;ne.current=re;const Re=A.current;if(Re.length>0){const Be=Re.find(Me=>re>=Me.start&&re<Me.end);if(le.current)Be&&Be.id!==se.current?N(Be.id):!Be&&se.current!==null&&N(null);else if(se.current){const Me=Re.find(Ue=>Ue.id===se.current);if(Me&&re>=Me.end){H.current?.stop(),m(!1);return}}else Be&&N(Be.id)}if(ye.current&&oe.current){const Be=oe.current,Me=re*z/ce.current,Ue=Be.clientWidth,lt=l.show?l.width:0,ct=Me+lt,ht=Math.max(0,ct-Ue/2);Be.scrollLeft=ht}fe(G)};fe(G)},[N,z,l,fe]),Ie=O,ae=s.useCallback(G=>{if(!H.current)return;const re=G??ne.current;H.current.play(void 0,re),m(!0),me()},[me]),Te=s.useCallback(()=>{H.current&&(H.current.pause(),m(!1),Ie(),w(H.current.getCurrentTime()))},[Ie]),He=s.useCallback(()=>{H.current&&(H.current.stop(),m(!1),Ie(),ne.current=0,w(0),N(null))},[Ie,N]),Ye=s.useCallback(G=>{const re=Math.max(0,Math.min(G,b));ne.current=re,w(re),H.current&&H.current.seekTo(re)},[b]),Xe=s.useCallback(G=>{const re=Math.max(.5,Math.min(2,G));$(re),H.current&&H.current.setPlaybackRate(re)},[]),Q=a?30:0,Ke=s.useMemo(()=>({isPlaying:p,currentTime:k,currentTimeRef:ne}),[p,k]),Z=s.useMemo(()=>({continuousPlay:R,annotations:M,activeAnnotationId:B,playbackRate:I,isAutomaticScroll:P}),[R,M,B,I,P]),ue=s.useRef(h);ue.current=h;const ie=s.useCallback(G=>{const re=typeof G=="function"?G(A.current):G;if(!ue.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to MediaElementPlaylistProvider to handle annotation updates.");return}ue.current(re)},[]),Le=s.useMemo(()=>({play:ae,pause:Te,stop:He,seekTo:Ye,setPlaybackRate:Xe,setContinuousPlay:be,setAnnotations:ie,setActiveAnnotationId:N,setAutomaticScroll:G=>{U(G)},setScrollContainer:K,scrollContainerRef:oe}),[ae,Te,He,Ye,Xe,be,ie,N,K]),Ae=s.useMemo(()=>({duration:b,peaksDataArray:S,sampleRate:z,waveHeight:n,timeScaleHeight:Q,samplesPerPixel:L,playoutRef:H,controls:l,barWidth:u,barGap:f,progressBarWidth:y}),[b,S,z,n,Q,L,l,u,f,y]),De={...qn,...i};return g.jsx(D.ThemeProvider,{theme:De,children:g.jsx(xa.Provider,{value:Ke,children:g.jsx(ka.Provider,{value:Z,children:g.jsx(Sa.Provider,{value:Le,children:g.jsx(Ia.Provider,{value:Ae,children:C})})})})})},Wt=()=>{const e=s.useContext(xa);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Pt=()=>{const e=s.useContext(ka);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},nn=()=>{const e=s.useContext(Sa);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Zt=()=>{const e=s.useContext(Ia);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},Mo=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Fe(),{selectionStart:a,selectionEnd:r,isLoopEnabled:o}=We(),{play:i}=ge(),l=async()=>{if(a!==r&&r>a)if(o)await i(a);else{const u=r-a;await i(a,u)}else await i(n.current??0)};return g.jsx(ze,{onClick:l,disabled:t,className:e,children:"Play"})},_o=({className:e})=>{const{isPlaying:t}=Fe(),{pause:n}=ge();return g.jsx(ze,{onClick:n,disabled:!t,className:e,children:"Pause"})},Eo=({className:e})=>{const{isPlaying:t}=Fe(),{stop:n}=ge();return g.jsx(ze,{onClick:n,disabled:!t,className:e,children:"Stop"})},$o=({className:e})=>{const{isPlaying:t}=Fe(),{play:n,setCurrentTime:a}=ge(),{playoutRef:r}=$e(),o=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return g.jsx(ze,{onClick:o,className:e,children:"Rewind"})},To=({className:e})=>{const{isPlaying:t}=Fe(),{play:n,setCurrentTime:a}=ge(),{duration:r,playoutRef:o}=$e(),i=()=>{a(r),t&&o.current&&(o.current.stop(),n(r))};return g.jsx(ze,{onClick:i,className:e,children:"Fast Forward"})},Ro=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Fe(),{play:r,setCurrentTime:o}=ge(),{playoutRef:i}=$e(),l=()=>{const c=Math.max(0,(n.current??0)-e);o(c),a&&i.current&&(i.current.stop(),r(c))};return g.jsx(ze,{onClick:l,className:t,children:"Skip Backward"})},Do=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Fe(),{play:r,setCurrentTime:o}=ge(),{duration:i,playoutRef:l}=$e(),c=()=>{const u=Math.min(i,(n.current??0)+e);o(u),a&&l.current&&(l.current.stop(),r(u))};return g.jsx(ze,{onClick:c,className:t,children:"Skip Forward"})},Bo=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=We(),{setLoopEnabled:r,setLoopRegion:o}=ge(),{duration:i}=$e(),l=n!==a&&a>n,c=()=>{if(!t&&!l){const u=Math.min(10,i*.25);o(0,Math.max(1,u))}r(!t)};return g.jsx(ze,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Fo=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=We(),{setLoopRegionFromSelection:o,clearLoopRegion:i}=ge(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?i():o()};return g.jsx(ze,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},Wo=({className:e,disabled:t})=>{const{zoomIn:n}=ge(),{canZoomIn:a}=$e();return g.jsx(ze,{onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Po=({className:e,disabled:t})=>{const{zoomOut:n}=ge(),{canZoomOut:a}=$e();return g.jsx(ze,{onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Zo=({className:e})=>{const{masterVolume:t}=$e(),{setMasterVolume:n}=ge();return g.jsx(Er,{volume:t,onChange:n,className:e})},Vo=({className:e})=>{const{timeFormat:t}=$e(),{setTimeFormat:n}=ge();return g.jsx(ds,{value:t,onChange:n,className:e})},jo=D.span`
945
+ `;let $s=0;function Ts(){let e;try{const a=new Blob([Es],{type:"application/javascript"}),r=URL.createObjectURL(a);e=new Worker(r),URL.revokeObjectURL(r)}catch(a){return console.warn("[waveform-playlist] Failed to create peaks worker (CSP restriction?):",a),{generate(){return Promise.reject(new Error("Worker creation failed"))},terminate(){}}}const t=new Map;let n=!1;return e.onmessage=a=>{const r=a.data,s=t.get(r.id);if(s)if(t.delete(r.id),r.error)s.reject(new Error(r.error));else try{const i=Ze.create(r.buffer);s.resolve(i)}catch(i){s.reject(i)}},e.onerror=a=>{n=!0,e.terminate();for(const[,r]of t)r.reject(a.error??new Error(a.message));t.clear()},{generate(a){if(n)return Promise.reject(new Error("Worker terminated"));const r=String(++$s);return new Promise((s,i)=>{t.set(r,{resolve:s,reject:i}),e.postMessage({id:r,scale:a.scale,bits:a.bits,amplitude_scale:1,split_channels:a.splitChannels,length:a.length,sample_rate:a.sampleRate,channels:a.channels},a.channels)})},terminate(){n=!0,e.terminate();for(const[,a]of t)a.reject(new Error("Worker terminated"));t.clear()}}}function Rs(e,t){const[n,a]=o.useState(()=>new Map),[r,s]=o.useState(!1),i=o.useRef(null),l=o.useRef(new Set),c=o.useRef(0),u=o.useCallback(()=>(i.current||(i.current=Ts()),i.current),[]);return o.useEffect(()=>{let m=!1;const h=l.current,p=[];for(const w of e)for(const g of w.clips)g.audioBuffer&&!g.waveformData&&!h.has(g.id)&&p.push({clipId:g.id,audioBuffer:g.audioBuffer});if(p.length===0)return;const f=new Set;for(const{clipId:w}of p)h.add(w),f.add(w);c.current+=p.length,s(!0);const b=u();for(const{clipId:w,audioBuffer:g}of p){const d=[];for(let x=0;x<g.numberOfChannels;x++)d.push(g.getChannelData(x).slice().buffer);b.generate({id:w,channels:d,length:g.length,sampleRate:g.sampleRate,scale:t,bits:16,splitChannels:!0}).then(x=>{m||(a(y=>{const C=new Map(y);return C.set(w,x),C}),c.current--,c.current<=0&&(c.current=0,s(!1)))}).catch(x=>{m||(console.warn("[waveform-playlist] Worker peak generation failed:",x),h.delete(w),c.current--,c.current<=0&&(c.current=0,s(!1)))})}return()=>{m=!0;for(const w of f)h.delete(w)}},[e,t,u]),o.useEffect(()=>()=>{i.current?.terminate(),i.current=null},[]),{cache:n,isGenerating:r}}function Ut(e){return e instanceof File?e.name.replace(/\.[^/.]+$/,""):e instanceof Blob?"Untitled":typeof e=="string"?e.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled":e.name??e.src.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled"}async function Ds(e,t,n){const a=Ut(e);if(e instanceof Blob){const c=await e.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(c),name:a}}const r=typeof e=="string"?e:e.src,s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Failed to fetch ${r}: ${s.statusText}`);const i=await s.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(i),name:a}}function Bs(){const[e,t]=o.useState([]),[n,a]=o.useState(0),[r,s]=o.useState([]),i=o.useRef(!1),l=o.useRef(new Set),c=o.useRef(new Map);o.useEffect(()=>{const h=c.current;return()=>{i.current=!0;for(const p of h.values())p.abort();h.clear()}},[]);const u=o.useCallback(h=>{if(h.length===0)return;const p=sr(),f=h.map(b=>({track:Nn({name:`${Ut(b)} (loading...)`,clips:[]}),source:b}));t(b=>[...b,...f.map(w=>w.track)]),a(b=>b+h.length);for(const{track:b,source:w}of f){l.current.add(b.id);const g=new AbortController;c.current.set(b.id,g),(async()=>{try{const{audioBuffer:d,name:x}=await Ds(w,p,g.signal),y=Gn({audioBuffer:d,startTime:0,duration:d.duration,offset:0,name:x});!i.current&&l.current.has(b.id)&&t(C=>C.map(k=>k.id===b.id?{...k,name:x,clips:[y]}:k))}catch(d){if(d instanceof DOMException&&d.name==="AbortError")return;console.warn("[waveform-playlist] Error loading audio:",d),!i.current&&l.current.has(b.id)&&(t(x=>x.filter(y=>y.id!==b.id)),s(x=>[...x,{name:Ut(w),error:d instanceof Error?d:new Error(String(d))}]))}finally{c.current.delete(b.id),!i.current&&l.current.delete(b.id)&&a(d=>d-1)}})()}},[]),m=o.useCallback(h=>{t(f=>f.filter(b=>b.id!==h));const p=c.current.get(h);p&&(p.abort(),c.current.delete(h)),l.current.delete(h)&&a(f=>f-1)},[]);return{tracks:e,addTracks:u,removeTrack:m,loadingCount:n,isLoading:n>0,errors:r}}const Aa=o.createContext(null),Ma=o.createContext(null),_a=o.createContext(null),Ea=o.createContext(null),Fs=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:i=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:m,onReady:h,onAnnotationUpdate:p,onAnnotationsChange:f,barWidth:b=1,barGap:w=0,progressBarWidth:g,children:d})=>{const x=g??b+w,y=o.useMemo(()=>{if(!u?.annotations)return[];if(process.env.NODE_ENV!=="production"&&u.annotations.length>0){const D=u.annotations[0];if(typeof D.start!="number"||typeof D.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof D.start),[]}return u.annotations},[u?.annotations]),C=o.useRef(y);C.current=y;const[k,S]=o.useState(null),[M,A]=o.useState(!1),[E,_]=o.useState(0),[I,B]=o.useState(0),[$,W]=o.useState([]),[z,Y]=o.useState([]),[j,N]=o.useState([]),[L,ae]=o.useState(0),[oe,q]=o.useState(0),[fe,ue]=o.useState(null),[le,Ee]=o.useState(i),[P,ee]=o.useState(u?.isContinuousPlay??!1),[U,K]=o.useState(u?.linkEndpoints??!1),[ie,he]=o.useState(u?.editable??!1),[te,Se]=o.useState(!1),[Be,Xe]=o.useState(0),[qe,ne]=o.useState(0),[Ve,Oe]=o.useState(!1),F=o.useRef(null),ye=o.useRef(0),ce=o.useRef(0),je=o.useRef(e),nt=o.useRef(j),Le=o.useRef(0),O=o.useRef(0),se=o.useRef(null),ve=o.useRef(null),$e=o.useRef(!1),Te=o.useRef(u?.isContinuousPlay??!1),Ge=o.useRef(null),at=o.useRef(r),ut=o.useRef(!1),ht=o.useRef(0),V=o.useRef(0),X=o.useRef(0),Q=o.useRef(0),{timeFormat:me,setTimeFormat:pe,formatTime:_e}=wa(),Ce=ya({initialSamplesPerPixel:r,zoomLevels:s}),J=Ce.samplesPerPixel,{masterVolume:Ie,setMasterVolume:Fe}=xa({playoutRef:F,initialVolume:1}),{animationFrameRef:rt,startAnimationFrameLoop:Ne,stopAnimationFrameLoop:Ye}=Ia(),dt=o.useMemo(()=>Math.min(...s??[256,512,1024,2048,4096,8192]),[s]),{cache:ot}=Rs(e,dt),Je=o.useCallback(D=>{Te.current=D,ee(D)},[]),ze=o.useCallback(D=>{Ge.current=D,S(D)},[]),xt=o.useCallback(D=>{ut.current=D,Se(D)},[]),Qe=o.useCallback((D,G)=>{X.current=D,Q.current=G,Xe(D),ne(G)},[]),sn=o.useCallback(()=>{const D=ht.current,G=V.current;D!==G&&G>D&&Qe(D,G)},[Qe]),ln=o.useCallback(()=>{Qe(0,0)},[Qe]);o.useEffect(()=>{$e.current=le},[le]),o.useEffect(()=>{nt.current=j},[j]),je.current=e,o.useEffect(()=>{ht.current=L,V.current=oe},[L,oe]),o.useEffect(()=>{if(!ve.current||!$.length)return;const D=ve.current,G=at.current,re=J;if(G===re)return;const H=c.show?c.width:0,de=D.clientWidth,Ae=D.scrollLeft+de/2-H,et=$[0].sampleRate,xe=Ae*G/et*et/re,We=Math.max(0,xe+H-de/2);D.scrollLeft=We,at.current=re},[J,$,c]);const kt=o.useRef(null);o.useEffect(()=>{if(Oe(!1),e.length===0){W([]),B(0),N([]),Y([]),F.current&&(F.current.dispose(),F.current=null);return}const D=M,G=ce.current;return F.current&&D&&(F.current.stop(),Ye(),kt.current={position:G}),(async()=>{try{const H=[];e.forEach(we=>{we.clips.length>0&&we.clips[0].audioBuffer&&H.push(we.clips[0].audioBuffer)});let de=0;e.forEach(we=>{we.clips.forEach(xe=>{const We=xe.sampleRate,It=(xe.startSample+xe.durationSamples)/We;de=Math.max(de,It)})}),W(H),B(de),N(we=>we.length===e.length?we.map((xe,We)=>({...xe,name:e[We].name})):e.map(xe=>({name:xe.name,muted:xe.muted,soloed:xe.soloed,volume:xe.volume,pan:xe.pan}))),F.current&&F.current.dispose();const ge=new rr({effects:m}),Ae=nt.current;e.forEach((we,xe)=>{const We=we.clips.filter(it=>it.audioBuffer);if(We.length>0){const it=We[0].sampleRate,It=Math.min(...We.map(Pe=>Pe.startSample/it)),Ha=Math.max(...We.map(Pe=>(Pe.startSample+Pe.durationSamples)/it)),At=Ae[xe],Xa={id:we.id,name:we.name,gain:At?.volume??we.volume,muted:At?.muted??we.muted,soloed:At?.soloed??we.soloed,stereoPan:At?.pan??we.pan,startTime:It,endTime:Ha},Oa=We.map(Pe=>{const zt=Pe.sampleRate;return{buffer:Pe.audioBuffer,startTime:Pe.startSample/zt-It,duration:Pe.durationSamples/zt,offset:Pe.offsetSamples/zt,fadeIn:Pe.fadeIn,fadeOut:Pe.fadeOut,gain:Pe.gain}});ge.addTrack({clips:Oa,track:Xa,effects:we.effects})}}),ge.applyInitialSoloState(),F.current=ge,Oe(!0);const et=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:de}});window.dispatchEvent(et),h?.()}catch(H){console.error("Error loading audio:",H)}})(),()=>{Ye(),F.current&&F.current.dispose()}},[e,h,M,m,Ye]),o.useEffect(()=>{if(e.length===0)return;const D=e.map(G=>G.clips.map(H=>{let de;if(H.waveformData)try{de=Vn(H.waveformData,J,n,H.offsetSamples,H.durationSamples)}catch(ge){console.warn("[waveform-playlist] Failed to extract peaks from waveformData:",ge)}if(!de){const ge=ot.get(H.id);if(ge)try{de=Vn(ge,J,n,H.offsetSamples,H.durationSamples)}catch(Ae){console.warn("[waveform-playlist] Failed to extract peaks from cache:",Ae)}}if(!de){!H.audioBuffer&&!H.waveformData&&console.warn(`[waveform-playlist] Clip "${H.id}" has no audio data or waveform data`);const ge=n?1:H.audioBuffer?.numberOfChannels??1;de={length:0,data:Array.from({length:ge},()=>new Int16Array(0)),bits:16}}return{clipId:H.id,trackName:G.name,peaks:de,startSample:H.startSample,durationSamples:H.durationSamples,fadeIn:H.fadeIn,fadeOut:H.fadeOut}}));Y(D)},[e,J,n,ot]);const st=o.useCallback(()=>{const D=()=>{const G=Z.getContext().currentTime-Le.current,re=O.current+G;ce.current=re;const H=C.current;if(H.length>0){const ge=H.find(Ae=>re>=Ae.start&&re<Ae.end);if(Te.current)ge&&ge.id!==Ge.current?ze(ge.id):!ge&&Ge.current!==null&&ze(null);else if(Ge.current){const Ae=H.find(et=>et.id===Ge.current);if(Ae&&re>=Ae.end){F.current&&F.current.stop(),A(!1),ce.current=ye.current,_(ye.current);return}}else ge&&ze(ge.id)}if($e.current&&ve.current&&$.length>0){const ge=ve.current,Ae=$[0].sampleRate,et=re*Ae/at.current,we=ge.clientWidth,xe=c.show?c.width:0,We=et+xe,it=Math.max(0,We-we/2);ge.scrollLeft=it}if(se.current!==null&&re>=se.current){F.current&&F.current.stop(),A(!1),ce.current=se.current,_(se.current),se.current=null;return}const de=X.current!==Q.current&&Q.current>X.current;if(ut.current&&de&&re>=Q.current){F.current?.stop();const Ae=Z.getContext().currentTime;Le.current=Ae,O.current=X.current,ce.current=X.current,F.current?.play(Ae,X.current),Ne(D);return}if(re>=I){F.current&&F.current.stop(),A(!1),ce.current=ye.current,_(ye.current),ze(null);return}Ne(D)};Ne(D)},[I,$,c.show,c.width,ze,Ne]),Ue=Ye;o.useEffect(()=>{(async()=>{if(M&&rt.current&&F.current)if(P){const G=ce.current;F.current.stop(),Ue(),await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const H=Z.getContext().currentTime;Le.current=H,O.current=G,F.current.play(H,G),st()}else Ue(),st()})()},[P,M,st,Ue,rt]),o.useEffect(()=>{(async()=>{if(kt.current&&F.current){const{position:G}=kt.current;kt.current=null,await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const H=Z.getContext().currentTime;Le.current=H,O.current=G,F.current.play(H,G),A(!0),st()}})()},[e,st]);const St=o.useCallback(async(D,G)=>{if(!F.current||$.length===0)return;await F.current.init();const re=D??ce.current;ye.current=re,ce.current=re,F.current.setOnPlaybackComplete(()=>{}),F.current.stop(),Ue();const de=Z.getContext().currentTime;Le.current=de,O.current=re,se.current=G!==void 0?re+G:null,F.current.play(de,re,G),A(!0),st()},[$.length,st,Ue]),cn=o.useCallback(()=>{if(!F.current)return;const D=Z.getContext().currentTime-Le.current,G=O.current+D;F.current.pause(),A(!1),Ue(),ce.current=G,_(G)},[Ue]),un=o.useCallback(()=>{F.current&&(F.current.stop(),A(!1),Ue(),ce.current=ye.current,_(ye.current),ze(null))},[Ue,ze]),dn=o.useCallback(D=>{const G=Math.max(0,Math.min(D,I));ce.current=G,_(G),M&&F.current&&(F.current.stop(),Ue(),St(G))},[I,M,St,Ue]),fn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];H[D]={...H[D],muted:G},N(H),F.current&&F.current.setMute(re,G)},[j]),mn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];H[D]={...H[D],soloed:G},N(H),F.current&&F.current.setSolo(re,G)},[j]),hn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];if(H[D]={...H[D],volume:G},N(H),F.current){const de=F.current.getTrack(re);de&&de.setVolume(G)}},[j]),pn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];if(H[D]={...H[D],pan:G},N(H),F.current){const de=F.current.getTrack(re);de&&de.setPan(G)}},[j]),gn=o.useCallback((D,G)=>{ae(D),q(G),ce.current=D,_(D),M&&F.current&&(F.current.stop(),F.current.play(Z.getContext().currentTime,D))},[M]),bn=o.useCallback(D=>{ve.current=D},[]),jt=o.useRef(f);jt.current=f;const vn=o.useCallback(D=>{const G=typeof D=="function"?D(C.current):D;if(!jt.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}jt.current(G)},[]),Cn=$[0]?.sampleRate||44100,Lt=t?30:0,wn=e.length*a+Lt,Za=o.useMemo(()=>({isPlaying:M,currentTime:E,currentTimeRef:ce,playbackStartTimeRef:Le,audioStartPositionRef:O}),[M,E,ce,Le,O]),Va=o.useMemo(()=>({continuousPlay:P,linkEndpoints:U,annotationsEditable:ie,isAutomaticScroll:le,isLoopEnabled:te,annotations:y,activeAnnotationId:k,selectionStart:L,selectionEnd:oe,selectedTrackId:fe,loopStart:Be,loopEnd:qe}),[P,U,ie,le,te,y,k,L,oe,fe,Be,qe]),yn=o.useCallback(D=>{ce.current=D,_(D)},[ce]),xn=o.useCallback(D=>{Ee(D)},[]),ja=o.useMemo(()=>({play:St,pause:cn,stop:un,seekTo:dn,setCurrentTime:yn,setTrackMute:fn,setTrackSolo:mn,setTrackVolume:hn,setTrackPan:pn,setSelection:gn,setSelectedTrackId:ue,setTimeFormat:pe,formatTime:_e,zoomIn:Ce.zoomIn,zoomOut:Ce.zoomOut,setMasterVolume:Fe,setAutomaticScroll:xn,setScrollContainer:bn,scrollContainerRef:ve,setContinuousPlay:Je,setLinkEndpoints:K,setAnnotationsEditable:he,setAnnotations:vn,setActiveAnnotationId:ze,setLoopEnabled:xt,setLoopRegion:Qe,setLoopRegionFromSelection:sn,clearLoopRegion:ln}),[St,cn,un,dn,yn,fn,mn,hn,pn,gn,ue,pe,_e,Ce.zoomIn,Ce.zoomOut,Fe,xn,bn,ve,Je,K,he,vn,ze,xt,Qe,sn,ln]),La=o.useMemo(()=>({duration:I,audioBuffers:$,peaksDataArray:z,trackStates:j,tracks:e,sampleRate:Cn,waveHeight:a,timeScaleHeight:Lt,minimumPlaylistHeight:wn,controls:c,playoutRef:F,samplesPerPixel:J,timeFormat:me,masterVolume:Ie,canZoomIn:Ce.canZoomIn,canZoomOut:Ce.canZoomOut,barWidth:b,barGap:w,progressBarWidth:x,isReady:Ve,mono:n}),[I,$,z,j,e,Cn,a,Lt,wn,c,F,J,me,Ie,Ce.canZoomIn,Ce.canZoomOut,b,w,x,Ve,n]),za={...ra,...l};return v.jsx(R.ThemeProvider,{theme:za,children:v.jsx(Aa.Provider,{value:Za,children:v.jsx(Ma.Provider,{value:Va,children:v.jsx(_a.Provider,{value:ja,children:v.jsx(Ea.Provider,{value:La,children:d})})})})})},Re=()=>{const e=o.useContext(Aa);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},De=()=>{const e=o.useContext(Ma);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},be=()=>{const e=o.useContext(_a);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},Me=()=>{const e=o.useContext(Ea);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e};var Ws=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate;const t=this.audioElement;"preservesPitch"in this.audioElement?t.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?t.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(t.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},Ps=class{constructor(e={}){this.track=null,this._isPlaying=!1,this._masterVolume=e.masterVolume??1,this._playbackRate=e.playbackRate??1}async init(){}addTrack(e){return this.track&&(console.warn("MediaElementPlayout: Only one track is supported. Disposing previous track. For multi-track, use TonePlayout."),this.track.dispose()),this.track=new Ws({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const a=t??0;if(this._isPlaying=!0,this.track.play(a),n!==void 0){const r=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},r*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const $a=o.createContext(null),Ta=o.createContext(null),Ra=o.createContext(null),Da=o.createContext(null),Zs=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:s=!1,theme:i,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:m=0,progressBarWidth:h,onAnnotationsChange:p,onReady:f,children:b})=>{const w=h??u+m,[g,d]=o.useState(!1),[x,y]=o.useState(0),[C,k]=o.useState(0),[S,M]=o.useState([]),[A,E]=o.useState(r),_=o.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const O=c.annotations[0];if(typeof O.start!="number"||typeof O.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof O.start),[]}return c.annotations},[c?.annotations]),I=o.useRef(_);I.current=_;const[B,$]=o.useState(null),[W,z]=o.useState(c?.isContinuousPlay??!1),[Y]=o.useState(t),[j,N]=o.useState(s),L=o.useRef(null),ae=o.useRef(0),oe=o.useRef(W),q=o.useRef(null),fe=o.useRef(null),ue=o.useRef(s),le=o.useRef(t),{startAnimationFrameLoop:Ee,stopAnimationFrameLoop:P}=Ia();o.useEffect(()=>{oe.current=W},[W]),o.useEffect(()=>{ue.current=j},[j]);const ee=o.useCallback(O=>{q.current=O,$(O)},[]),U=o.useCallback(O=>{oe.current=O,z(O)},[]),K=o.useCallback(O=>{fe.current=O},[]),ie=e.waveformData.sample_rate;o.useEffect(()=>{const O=new Ps({playbackRate:r});O.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const se=O.getTrack(O.track?.id??"");return se&&se.setOnTimeUpdateCallback(ve=>{ae.current=ve}),O.setOnPlaybackComplete(()=>{P(),d(!1),ee(null),ae.current=0,y(0)}),L.current=O,k(e.waveformData.duration),f?.(),()=>{P(),O.dispose()}},[e.source,e.waveformData,e.name,r,f,P,ee]),o.useEffect(()=>{const O=os(e.waveformData,Y,0,0,Math.ceil(e.waveformData.duration*ie)),se={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:O.length,data:[O.data],bits:O.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*ie)};M([[se]])},[e.waveformData,e.name,Y,ie]);const he=o.useCallback(()=>{const O=()=>{const se=L.current?.getCurrentTime()??0;ae.current=se;const ve=I.current;if(ve.length>0){const $e=ve.find(Te=>se>=Te.start&&se<Te.end);if(oe.current)$e&&$e.id!==q.current?ee($e.id):!$e&&q.current!==null&&ee(null);else if(q.current){const Te=ve.find(Ge=>Ge.id===q.current);if(Te&&se>=Te.end){L.current?.stop(),d(!1);return}}else $e&&ee($e.id)}if(ue.current&&fe.current){const $e=fe.current,Te=se*ie/le.current,Ge=$e.clientWidth,at=l.show?l.width:0,ut=Te+at,ht=Math.max(0,ut-Ge/2);$e.scrollLeft=ht}Ee(O)};Ee(O)},[ee,ie,l,Ee]),te=P,Se=o.useCallback(O=>{if(!L.current)return;const se=O??ae.current;L.current.play(void 0,se),d(!0),he()},[he]),Be=o.useCallback(()=>{L.current&&(L.current.pause(),d(!1),te(),y(L.current.getCurrentTime()))},[te]),Xe=o.useCallback(()=>{L.current&&(L.current.stop(),d(!1),te(),ae.current=0,y(0),ee(null))},[te,ee]),qe=o.useCallback(O=>{const se=Math.max(0,Math.min(O,C));ae.current=se,y(se),L.current&&L.current.seekTo(se)},[C]),ne=o.useCallback(O=>{const se=Math.max(.5,Math.min(2,O));E(se),L.current&&L.current.setPlaybackRate(se)},[]),Ve=a?30:0,Oe=o.useMemo(()=>({isPlaying:g,currentTime:x,currentTimeRef:ae}),[g,x]),F=o.useMemo(()=>({continuousPlay:W,annotations:_,activeAnnotationId:B,playbackRate:A,isAutomaticScroll:j}),[W,_,B,A,j]),ye=o.useRef(p);ye.current=p;const ce=o.useCallback(O=>{const se=typeof O=="function"?O(I.current):O;if(!ye.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to MediaElementPlaylistProvider to handle annotation updates.");return}ye.current(se)},[]),je=o.useMemo(()=>({play:Se,pause:Be,stop:Xe,seekTo:qe,setPlaybackRate:ne,setContinuousPlay:U,setAnnotations:ce,setActiveAnnotationId:ee,setAutomaticScroll:O=>{N(O)},setScrollContainer:K,scrollContainerRef:fe}),[Se,Be,Xe,qe,ne,U,ce,ee,K]),nt=o.useMemo(()=>({duration:C,peaksDataArray:S,sampleRate:ie,waveHeight:n,timeScaleHeight:Ve,samplesPerPixel:Y,playoutRef:L,controls:l,barWidth:u,barGap:m,progressBarWidth:w}),[C,S,ie,n,Ve,Y,l,u,m,w]),Le={...ra,...i};return v.jsx(R.ThemeProvider,{theme:Le,children:v.jsx($a.Provider,{value:Oe,children:v.jsx(Ta.Provider,{value:F,children:v.jsx(Ra.Provider,{value:je,children:v.jsx(Da.Provider,{value:nt,children:b})})})})})},Wt=()=>{const e=o.useContext($a);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Pt=()=>{const e=o.useContext(Ta);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},rn=()=>{const e=o.useContext(Ra);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Zt=()=>{const e=o.useContext(Da);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},Vs=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Re(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=De(),{play:i}=be(),l=async()=>{if(a!==r&&r>a)if(s)await i(a);else{const u=r-a;await i(a,u)}else await i(n.current??0)};return v.jsx(He,{onClick:l,disabled:t,className:e,children:"Play"})},js=({className:e})=>{const{isPlaying:t}=Re(),{pause:n}=be();return v.jsx(He,{onClick:n,disabled:!t,className:e,children:"Pause"})},Ls=({className:e})=>{const{isPlaying:t}=Re(),{stop:n}=be();return v.jsx(He,{onClick:n,disabled:!t,className:e,children:"Stop"})},zs=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=be(),{playoutRef:r}=Me(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return v.jsx(He,{onClick:s,className:e,children:"Rewind"})},Hs=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=be(),{duration:r,playoutRef:s}=Me(),i=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return v.jsx(He,{onClick:i,className:e,children:"Fast Forward"})},Xs=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=be(),{playoutRef:i}=Me(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&i.current&&(i.current.stop(),r(c))};return v.jsx(He,{onClick:l,className:t,children:"Skip Backward"})},Os=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=be(),{duration:i,playoutRef:l}=Me(),c=()=>{const u=Math.min(i,(n.current??0)+e);s(u),a&&l.current&&(l.current.stop(),r(u))};return v.jsx(He,{onClick:c,className:t,children:"Skip Forward"})},Gs=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=De(),{setLoopEnabled:r,setLoopRegion:s}=be(),{duration:i}=Me(),l=n!==a&&a>n,c=()=>{if(!t&&!l){const u=Math.min(10,i*.25);s(0,Math.max(1,u))}r(!t)};return v.jsx(He,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Ns=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=De(),{setLoopRegionFromSelection:s,clearLoopRegion:i}=be(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?i():s()};return v.jsx(He,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},Ys=({className:e,disabled:t})=>{const{zoomIn:n}=be(),{canZoomIn:a}=Me();return v.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Us=({className:e,disabled:t})=>{const{zoomOut:n}=be(),{canZoomOut:a}=Me();return v.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Ks=({className:e})=>{const{masterVolume:t}=Me(),{setMasterVolume:n}=be();return v.jsx(Lr,{volume:t,onChange:n,className:e})},qs=({className:e})=>{const{timeFormat:t}=Me(),{setTimeFormat:n}=be();return v.jsx(So,{value:t,onChange:n,className:e})},Js=R.span`
931
946
  font-family: 'Courier New', Monaco, monospace;
932
947
  font-size: 1rem;
933
948
  font-weight: 600;
934
949
  color: ${e=>e.theme?.textColor||"#333"};
935
950
  user-select: none;
936
- `,Lo=({className:e})=>{const t=s.useRef(null),n=s.useRef(null),{isPlaying:a,currentTimeRef:r,playbackStartTimeRef:o,audioStartPositionRef:i}=Fe(),{timeFormat:l}=$e();return s.useEffect(()=>{const c=()=>{if(t.current){let u;if(a){const f=j.getContext().currentTime-(o.current??0);u=(i.current??0)+f}else u=r.current??0;t.current.textContent=mt(u,l)}a&&(n.current=requestAnimationFrame(c))};return a?n.current=requestAnimationFrame(c):c(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[a,l,r,o,i]),s.useEffect(()=>{!a&&t.current&&(t.current.textContent=mt(r.current??0,l))}),g.jsx(jo,{ref:t,className:e,"aria-label":"Audio position",children:mt(r.current??0,l)})},zo=({className:e})=>{const{selectionStart:t,selectionEnd:n}=We(),{setSelection:a}=ge();return g.jsx(jr,{selectionStart:t,selectionEnd:n,onSelectionChange:a,className:e})},Ho=({className:e})=>{const{isAutomaticScroll:t}=We(),{setAutomaticScroll:n}=ge();return g.jsx(lr,{checked:t,onChange:n,className:e})},Vt=s.createContext(null),Xo=Vt.Provider;function it(){const e=s.useContext(Vt);if(!e)throw new Error("useAnnotationIntegration must be used within <AnnotationProvider>. Install @waveform-playlist/annotations and wrap your app with <AnnotationProvider>. See: https://waveform-playlist.naomiaro.com/docs/guides/annotations");return e}const Oo=({className:e})=>{const{ContinuousPlayCheckbox:t}=it(),{continuousPlay:n}=We(),{setContinuousPlay:a}=ge();return g.jsx(t,{checked:n,onChange:a,className:e})},No=({className:e})=>{const{LinkEndpointsCheckbox:t}=it(),{linkEndpoints:n}=We(),{setLinkEndpoints:a}=ge();return g.jsx(t,{checked:n,onChange:a,className:e})},Go=({className:e})=>{const{EditableCheckbox:t}=it(),{annotationsEditable:n}=We(),{setAnnotationsEditable:a}=ge();return g.jsx(t,{checked:n,onChange:a,className:e})},Yo=({filename:e,className:t})=>{const{DownloadAnnotationsButton:n}=it(),{annotations:a}=We();return g.jsx(n,{annotations:a,filename:e,className:t})},Ko=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:a,bitDepth:r=16,applyEffects:o=!0,effectsFunction:i,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:f})=>{const{tracks:v,trackStates:h}=$e(),{exportWav:d,isExporting:C,progress:y}=ga(),p=async()=>{try{const k=await d(v,h,{filename:t,mode:n,trackIndex:a,bitDepth:r,applyEffects:o,effectsFunction:i,createOfflineTrackEffects:l,autoDownload:!0});u?.(k.blob)}catch(k){f?.(k instanceof Error?k:new Error("Export failed"))}},m=C?`Exporting ${Math.round(y*100)}%`:e;return g.jsx(ze,{onClick:p,disabled:C||v.length===0,className:c,children:m})},Uo=D.div.attrs(e=>({style:{width:`${e.$width}px`,background:e.$color}}))`
951
+ `,Qs=({className:e})=>{const t=o.useRef(null),n=o.useRef(null),{isPlaying:a,currentTimeRef:r,playbackStartTimeRef:s,audioStartPositionRef:i}=Re(),{timeFormat:l}=Me();return o.useEffect(()=>{const c=()=>{if(t.current){let u;if(a){const m=Z.getContext().currentTime-(s.current??0);u=(i.current??0)+m}else u=r.current??0;t.current.textContent=mt(u,l)}a&&(n.current=requestAnimationFrame(c))};return a?n.current=requestAnimationFrame(c):c(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[a,l,r,s,i]),o.useEffect(()=>{!a&&t.current&&(t.current.textContent=mt(r.current??0,l))}),v.jsx(Js,{ref:t,className:e,"aria-label":"Audio position",children:mt(r.current??0,l)})},ei=({className:e})=>{const{selectionStart:t,selectionEnd:n}=De(),{setSelection:a}=be();return v.jsx(Jr,{selectionStart:t,selectionEnd:n,onSelectionChange:a,className:e})},ti=({className:e})=>{const{isAutomaticScroll:t}=De(),{setAutomaticScroll:n}=be();return v.jsx(vr,{checked:t,onChange:n,className:e})},Vt=o.createContext(null),ni=Vt.Provider;function ct(){const e=o.useContext(Vt);if(!e)throw new Error("useAnnotationIntegration must be used within <AnnotationProvider>. Install @waveform-playlist/annotations and wrap your app with <AnnotationProvider>. See: https://waveform-playlist.naomiaro.com/docs/guides/annotations");return e}const ai=({className:e})=>{const{ContinuousPlayCheckbox:t}=ct(),{continuousPlay:n}=De(),{setContinuousPlay:a}=be();return v.jsx(t,{checked:n,onChange:a,className:e})},ri=({className:e})=>{const{LinkEndpointsCheckbox:t}=ct(),{linkEndpoints:n}=De(),{setLinkEndpoints:a}=be();return v.jsx(t,{checked:n,onChange:a,className:e})},oi=({className:e})=>{const{EditableCheckbox:t}=ct(),{annotationsEditable:n}=De(),{setAnnotationsEditable:a}=be();return v.jsx(t,{checked:n,onChange:a,className:e})},si=({filename:e,className:t})=>{const{DownloadAnnotationsButton:n}=ct(),{annotations:a}=De();return v.jsx(n,{annotations:a,filename:e,className:t})},ii=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:a,bitDepth:r=16,applyEffects:s=!0,effectsFunction:i,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:m})=>{const{tracks:h,trackStates:p}=Me(),{exportWav:f,isExporting:b,progress:w}=Sa(),g=async()=>{try{const x=await f(h,p,{filename:t,mode:n,trackIndex:a,bitDepth:r,applyEffects:s,effectsFunction:i,createOfflineTrackEffects:l,autoDownload:!0});u?.(x.blob)}catch(x){m?.(x instanceof Error?x:new Error("Export failed"))}},d=b?`Exporting ${Math.round(w*100)}%`:e;return v.jsx(He,{onClick:g,disabled:b||h.length===0,className:c,children:d})},li=R.div.attrs(e=>({style:{width:`${e.$width}px`,background:e.$color}}))`
937
952
  position: absolute;
938
953
  top: 0;
939
954
  left: 0;
@@ -941,9 +956,9 @@ self.onmessage = function(e) {
941
956
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
942
957
  pointer-events: none;
943
958
  will-change: transform;
944
- `,qo=({color:e="#ff0000",controlsOffset:t=0})=>{const n=s.useRef(null),a=s.useRef(null),{isPlaying:r,currentTimeRef:o,playbackStartTimeRef:i,audioStartPositionRef:l}=Fe(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:f}=$e();return s.useEffect(()=>{const v=()=>{if(n.current){let h;if(r){const C=j.getContext().currentTime-(i.current??0);h=(l.current??0)+C}else h=o.current??0;const d=h*u/c+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}r&&(a.current=requestAnimationFrame(v))};return r?a.current=requestAnimationFrame(v):v(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,u,c,t,o,i,l]),s.useEffect(()=>{if(!r&&n.current){const h=(o.current??0)*u/c+t;n.current.style.transform=`translate3d(${h}px, 0, 0)`}}),g.jsx(Uo,{ref:n,$color:e,$width:f,"data-playhead":!0})},Jo=D.div`
959
+ `,ci=({color:e="#ff0000",controlsOffset:t=0})=>{const n=o.useRef(null),a=o.useRef(null),{isPlaying:r,currentTimeRef:s,playbackStartTimeRef:i,audioStartPositionRef:l}=Re(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:m}=Me();return o.useEffect(()=>{const h=()=>{if(n.current){let p;if(r){const b=Z.getContext().currentTime-(i.current??0);p=(l.current??0)+b}else p=s.current??0;const f=p*u/c+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}r&&(a.current=requestAnimationFrame(h))};return r?a.current=requestAnimationFrame(h):h(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,u,c,t,s,i,l]),o.useEffect(()=>{if(!r&&n.current){const p=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${p}px, 0, 0)`}}),v.jsx(li,{ref:n,$color:e,$width:m,"data-playhead":!0})},ui=R.div`
945
960
  position: relative;
946
- `,Ot=D.div.attrs(e=>({style:{top:`${e.$top}px`,width:`${e.$width}px`,height:`${e.$height}px`,background:e.$color}}))`
961
+ `,Ot=R.div.attrs(e=>({style:{top:`${e.$top}px`,width:`${e.$width}px`,height:`${e.$height}px`,background:e.$color}}))`
947
962
  position: absolute;
948
963
  left: 0;
949
964
  z-index: 0;
@@ -951,7 +966,7 @@ self.onmessage = function(e) {
951
966
  transform: translateZ(0);
952
967
  backface-visibility: hidden;
953
968
  will-change: transform;
954
- `,Qo=D.div.attrs(e=>({style:{top:`${e.$top}px`,height:`${e.$height}px`,width:`${e.$width}px`,background:e.$color,transform:"scaleX(0)"}}))`
969
+ `,di=R.div.attrs(e=>({style:{top:`${e.$top}px`,height:`${e.$height}px`,width:`${e.$width}px`,background:e.$color,transform:"scaleX(0)"}}))`
955
970
  position: absolute;
956
971
  left: 0;
957
972
  pointer-events: none;
@@ -959,10 +974,10 @@ self.onmessage = function(e) {
959
974
  transform-origin: left;
960
975
  /* scaleX changes are composite-only (GPU) — no layout reflow per frame */
961
976
  will-change: transform;
962
- `,ei=D.div`
977
+ `,fi=R.div`
963
978
  position: relative;
964
979
  z-index: 2;
965
- `,Zn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=s.useRef(null),r=s.useRef(null),o=Ct(),{waveHeight:i}=Bt(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:f}=Fe(),{samplesPerPixel:v,sampleRate:h}=$e(),d=o?.waveProgressColor||"rgba(0, 0, 0, 0.1)";s.useEffect(()=>{const E=()=>{if(a.current){let I;if(l){const B=j.getContext().currentTime-(u.current??0);I=(f.current??0)+B}else I=c.current??0;const $=I*h,M=e+t;let A=0;$<=e?A=0:$>=M?A=1:A=($-e)/t,a.current.style.transform=`scaleX(${A})`}l&&(r.current=requestAnimationFrame(E))};return l?r.current=requestAnimationFrame(E):E(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,h,v,e,t,n.length,c,u,f]),s.useEffect(()=>{if(!l&&a.current){const I=(c.current??0)*h,$=e+t;let M=0;I<=e?M=0:I>=$?M=1:M=(I-e)/t,a.current.style.transform=`scaleX(${M})`}});const C=o?.waveformDrawMode||"inverted";let y;C==="inverted"?y=n.isSelected&&o?o.selectedWaveFillColor:o?.waveFillColor||"white":y=n.isSelected&&o?o.selectedWaveOutlineColor:o?.waveOutlineColor||"grey";const p=n.renderMode==="spectrogram"||n.renderMode==="both",m=n.renderMode==="both",k=p?"#000":at(y),w=Math.floor(i/2),b=i,x=n.index*i,S=at(y);return g.jsxs(Jo,{children:[m?g.jsxs(g.Fragment,{children:[g.jsx(Ot,{$color:"#000",$height:w,$top:x,$width:n.length}),g.jsx(Ot,{$color:S,$height:w,$top:x+w,$width:n.length})]}):g.jsx(Ot,{$color:k,$height:b,$top:x,$width:n.length}),g.jsx(Qo,{ref:a,$color:d,$height:b,$top:x,$width:n.length}),g.jsx(ei,{children:g.jsx(oa,{...n,transparentBackground:!0})})]})},an=s.createContext(null),ti=an.Provider;function ni(){const e=s.useContext(an);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const ai=60,Aa=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:r,className:o,showClipHeaders:i=!1,interactiveClips:l=!1,showFades:c=!1,touchOptimized:u=!1,onRemoveTrack:f,recordingState:v})=>{const h=Ct(),{isPlaying:d,currentTimeRef:C,playbackStartTimeRef:y,audioStartPositionRef:p}=Fe(),{selectionStart:m,selectionEnd:k,annotations:w,activeAnnotationId:b,annotationsEditable:x,linkEndpoints:S,continuousPlay:E,selectedTrackId:I,loopStart:$,loopEnd:M,isLoopEnabled:A}=We(),B=s.useContext(Vt),{setAnnotations:_,setActiveAnnotationId:R,setTrackMute:W,setTrackSolo:L,setTrackVolume:P,setTrackPan:U,setSelection:H,play:ne,setScrollContainer:le,setSelectedTrackId:se,setCurrentTime:oe,setLoopRegion:ye}=ge(),{audioBuffers:ce,peaksDataArray:fe,trackStates:O,tracks:N,duration:be,samplesPerPixel:K,sampleRate:z,waveHeight:me,timeScaleHeight:Ie,controls:ae,playoutRef:Te,barWidth:He,barGap:Ye,isReady:Xe}=$e(),Q=s.useContext(an),Ke=s.useMemo(()=>{if(!Q)return new Map;const V=new Map;return N.forEach(Y=>{if((Q.trackSpectrogramOverrides.get(Y.id)?.renderMode??Y.renderMode??"waveform")==="waveform")return;const Ce=Q.trackSpectrogramOverrides.get(Y.id),ve=Ce?.colorMap??Y.spectrogramColorMap??Q.spectrogramColorMap??"viridis",he=Ce?.config??Y.spectrogramConfig??Q.spectrogramConfig;V.set(Y.id,{colorLUT:Q.getColorMap(ve),frequencyScaleFn:Q.getFrequencyScale(he?.frequencyScale??"mel"),config:he})}),V},[N,Q]),Z=s.useMemo(()=>{if(Q?.spectrogramWorkerApi)return{registerCanvas:Q.spectrogramWorkerApi.registerCanvas.bind(Q.spectrogramWorkerApi),unregisterCanvas:Q.spectrogramWorkerApi.unregisterCanvas.bind(Q.spectrogramWorkerApi)}},[Q?.spectrogramWorkerApi]),[ue,ie]=s.useState(null),[Le,Ae]=s.useState(!1),De=s.useRef(null),G=s.useCallback(V=>{De.current=V,le(V)},[le]);let re=ce.length>0?be:ai;if(v?.isRecording){const Y=(v.startSample+v.durationSamples)/z;re=Math.max(re,Y+10)}const Re=Math.floor(re*z/K),Be=async V=>{R(V.id);const Y=E?void 0:V.end-V.start;try{await ne(V.start,Y)}catch(ee){console.error("waveform-playlist: Failed to start playback for annotation",V.id,ee)}},Me=s.useCallback(V=>{if(V>=0&&V<N.length){const Y=N[V];se(Y.id)}},[N,se]),Ue=V=>{const Y=V.currentTarget.getBoundingClientRect(),ee=ae.show?ae.width:0,ve=(V.clientX-Y.left-ee)*K/z,_e=V.clientY-Y.top;let qe=0,te=-1;for(let xe=0;xe<fe.length;xe++){const Oe=fe[xe],Je=Oe.length>0?Math.max(...Oe.map(Pe=>Pe.peaks.data.length)):1,et=((Q?.trackSpectrogramOverrides.get(N[xe]?.id)?.renderMode??N[xe]?.renderMode??"waveform")==="both"?Je*2:Je)*me+(i?22:0);if(_e>=qe&&_e<qe+et){te=xe;break}qe+=et}te!==-1&&Me(te),Ae(!0),oe(ve),H(ve,ve)},lt=V=>{if(!Le)return;const Y=V.currentTarget.getBoundingClientRect(),ee=ae.show?ae.width:0,ve=(V.clientX-Y.left-ee)*K/z,he=Math.min(m,ve),_e=Math.max(m,ve);H(he,_e)},ct=V=>{if(!Le)return;Ae(!1);const Y=V.currentTarget.getBoundingClientRect(),ee=ae.show?ae.width:0,ve=(V.clientX-Y.left-ee)*K/z,he=Math.min(m,ve),_e=Math.max(m,ve);Math.abs(_e-he)<.1?(oe(he),d&&Te.current?(Te.current.stop(),ne(he)):Te.current&&Te.current.stop()):H(he,_e)};return N.some(V=>V.clips.length>0)&&(ce.length===0||fe.length===0)?g.jsx("div",{className:o,children:"Loading waveform..."}):g.jsxs(sa,{children:[g.jsx(yt.Provider,{value:{samplesPerPixel:K,sampleRate:z,zoomLevels:[K],waveHeight:me,timeScaleHeight:Ie,duration:re*1e3,controls:ae,barWidth:He,barGap:Ye},children:g.jsx(qt,{theme:h,backgroundColor:at(h.waveOutlineColor),timescaleBackgroundColor:h.timescaleBackgroundColor,scrollContainerWidth:Re+(ae.show?ae.width:0),timescaleWidth:Re,tracksWidth:Re,controlsWidth:ae.show?ae.width:0,onTracksMouseDown:Ue,onTracksMouseMove:lt,onTracksMouseUp:ct,scrollContainerRef:G,isSelecting:Le,"data-playlist-state":Xe?"ready":"loading",timescale:Ie>0?g.jsxs(g.Fragment,{children:[g.jsx(ia,{renderTimestamp:t}),A&&g.jsx(Vr,{startPosition:Math.min($,M)*z/K,endPosition:Math.max($,M)*z/K,markerColor:h.loopMarkerColor,regionColor:h.loopRegionColor,minPosition:0,maxPosition:Re,controlsOffset:ae.show?ae.width:0,onLoopRegionChange:(V,Y)=>{const ee=V*K/z,Ce=Y*K/z;ye(ee,Ce)}})]}):void 0,children:g.jsxs(g.Fragment,{children:[fe.map((V,Y)=>{const ee=N[Y];if(!ee)return null;const Ce=O[Y]||{name:`Track ${Y+1}`,muted:!1,soloed:!1,volume:1,pan:0},ve=Q?.trackSpectrogramOverrides.get(ee.id)?.renderMode??ee.renderMode??"waveform",he=e?e(Y):g.jsxs(vs,{onClick:()=>Me(Y),children:[g.jsxs(ys,{style:{justifyContent:"center",position:"relative"},children:[f&&g.jsx(bs,{onClick:te=>{te.stopPropagation(),f(Y)}}),g.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:Ce.name||`Track ${Y+1}`}),Q?.renderMenuItems&&g.jsx("span",{style:{position:"absolute",right:0,top:0},children:g.jsx(Ms,{items:te=>Q.renderMenuItems({renderMode:ve,onRenderModeChange:xe=>Q.setTrackRenderMode(ee.id,xe),onOpenSettings:()=>ie(ee.id),onClose:te})})})]}),g.jsxs(ps,{children:[g.jsx(Rn,{$variant:Ce.muted?"danger":"outline",onClick:()=>W(Y,!Ce.muted),children:"Mute"}),g.jsx(Rn,{$variant:Ce.soloed?"info":"outline",onClick:()=>L(Y,!Ce.soloed),children:"Solo"})]}),g.jsxs(Bn,{children:[g.jsx(Cs,{}),g.jsx(Dn,{min:"0",max:"1",step:"0.01",value:Ce.volume,onChange:te=>P(Y,parseFloat(te.target.value))}),g.jsx(ws,{})]}),g.jsxs(Bn,{children:[g.jsx("span",{children:"L"}),g.jsx(Dn,{min:"-1",max:"1",step:"0.01",value:Ce.pan,onChange:te=>U(Y,parseFloat(te.target.value))}),g.jsx("span",{children:"R"})]})]}),qe=V.length>0?Math.max(...V.map(te=>te.peaks.data.length)):1;return g.jsx(Qt.Provider,{value:he,children:g.jsxs(la,{numChannels:qe,backgroundColor:at(h.waveOutlineColor),offset:0,width:Re,hasClipHeaders:i,trackId:ee.id,isSelected:ee.id===I,children:[ve!=="waveform"&&(()=>{const te=Ke.get(ee.id),xe=te?.config;return!xe?.labels||!te?null:g.jsx(es,{waveHeight:me,numChannels:qe,frequencyScaleFn:te.frequencyScaleFn,minFrequency:xe.minFrequency??0,maxFrequency:xe.maxFrequency??z/2,labelsColor:xe.labelsColor,labelsBackground:xe.labelsBackground,renderMode:ve,hasClipHeaders:i})})(),V.map((te,xe)=>{const Oe=te.peaks,Je=Oe.length;return g.jsx(Gt,{clipId:te.clipId,trackIndex:Y,clipIndex:xe,trackName:te.trackName,startSample:te.startSample,durationSamples:te.durationSamples,samplesPerPixel:K,showHeader:i,disableHeaderDrag:!l,isSelected:ee.id===I,trackId:ee.id,fadeIn:te.fadeIn,fadeOut:te.fadeOut,sampleRate:z,showFades:c,touchOptimized:u,onMouseDown:ut=>{ut.target.closest('[role="button"][aria-roledescription="draggable"]')||Me(Y)},children:Oe.data.map((ut,Qe)=>{const et=Q?.spectrogramDataMap.get(te.clipId),Pe=et?.[Qe]??et?.[0],dt=Ke.get(ee.id),tt=dt?.config;return g.jsx(Zn,{index:Qe,data:ut,bits:Oe.bits,length:Je,isSelected:ee.id===I,clipStartSample:te.startSample,clipDurationSamples:te.durationSamples,renderMode:ve,spectrogramData:Pe,samplesPerPixel:K,spectrogramColorLUT:dt?.colorLUT,spectrogramFrequencyScaleFn:dt?.frequencyScaleFn,spectrogramMinFrequency:tt?.minFrequency,spectrogramMaxFrequency:tt?.maxFrequency,spectrogramWorkerApi:Z,spectrogramClipId:te.clipId,spectrogramOnCanvasesReady:Q?(xt,kt)=>{Q.registerSpectrogramCanvases(te.clipId,Qe,xt,kt)}:void 0},`${te.clipId}-${Qe}`)})},te.clipId)}),v?.isRecording&&v.trackId===ee.id&&v.peaks.length>0&&g.jsx(Gt,{clipId:"recording-preview",trackIndex:Y,clipIndex:V.length,trackName:"Recording...",startSample:v.startSample,durationSamples:v.durationSamples,samplesPerPixel:K,showHeader:i,disableHeaderDrag:!0,isSelected:ee.id===I,trackId:ee.id,children:g.jsx(Zn,{index:0,data:v.peaks,bits:16,length:Math.floor(v.peaks.length/2),isSelected:ee.id===I,clipStartSample:v.startSample,clipDurationSamples:v.durationSamples},`${ee.id}-recording-0`)},`${ee.id}-recording`)]})},ee.id)}),w.length>0&&B&&g.jsx(B.AnnotationBoxesWrapper,{height:30,width:Re,children:w.map((V,Y)=>{const ee=V.start*z/K,Ce=V.end*z/K,ve=r?r(V,Y):V.id;return g.jsx(B.AnnotationBox,{annotationId:V.id,annotationIndex:Y,startPosition:ee,endPosition:Ce,label:ve,color:"#ff9800",isActive:V.id===b,onClick:()=>Be(V),editable:x},V.id)})}),m!==k&&g.jsx(na,{startPosition:Math.min(m,k)*z/K+(ae.show?ae.width:0),endPosition:Math.max(m,k)*z/K+(ae.show?ae.width:0),color:h.selectionColor}),(d||m===k)&&(n?n({position:(C.current??0)*z/K+(ae.show?ae.width:0),color:h.playheadColor,isPlaying:d,currentTimeRef:C,playbackStartTimeRef:y,audioStartPositionRef:p,samplesPerPixel:K,sampleRate:z,controlsOffset:ae.show?ae.width:0,getAudioContextTime:()=>j.getContext().currentTime}):g.jsx(qo,{color:h.playheadColor,controlsOffset:ae.show?ae.width:0}))]})})}),Q?.SettingsModal&&typeof document<"u"&&Vn.createPortal(g.jsx(Q.SettingsModal,{open:ue!==null,onClose:()=>ie(null),config:ue!==null?Q.trackSpectrogramOverrides.get(ue)?.config??N.find(V=>V.id===ue)?.spectrogramConfig??Q.spectrogramConfig??{}:{},colorMap:ue!==null?Q.trackSpectrogramOverrides.get(ue)?.colorMap??N.find(V=>V.id===ue)?.spectrogramColorMap??Q.spectrogramColorMap??"viridis":"viridis",onApply:(V,Y)=>{ue!==null&&Q.setTrackSpectrogramConfig(ue,V,Y)}}),document.body)]})},Ma=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:a,annotationListConfig:r,scrollActivePosition:o="center",scrollActiveContainer:i="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:f,continuousPlay:v}=We(),h=it(),{setAnnotations:d}=ge(),C=r??{linkEndpoints:f,continuousPlay:v},y=s.useCallback(m=>{d(m),n?.(m)},[d,n]),{AnnotationText:p}=h;return g.jsx(p,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:o,scrollActiveContainer:i,editable:u,controls:u?a:void 0,annotationListConfig:C,height:e,onAnnotationUpdate:y,renderAnnotationItem:t})},ri=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:o,renderAnnotationItem:i,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:f,showClipHeaders:v=!1,interactiveClips:h=!1,showFades:d=!1,touchOptimized:C=!1,onRemoveTrack:y,recordingState:p})=>{const{annotations:m}=We();return g.jsxs(g.Fragment,{children:[g.jsx(Aa,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:l,className:f,showClipHeaders:v,interactiveClips:h,showFades:d,touchOptimized:C,onRemoveTrack:y,recordingState:p}),m.length>0&&g.jsx(Ma,{height:o,renderAnnotationItem:i,controls:a,annotationListConfig:r,scrollActivePosition:c,scrollActiveContainer:u})]})},si=D.div`
980
+ `,zn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=o.useRef(null),r=o.useRef(null),s=wt(),{waveHeight:i}=Bt(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:m}=Re(),{samplesPerPixel:h,sampleRate:p}=Me(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";o.useEffect(()=>{const M=()=>{if(a.current){let A;if(l){const B=Z.getContext().currentTime-(u.current??0);A=(m.current??0)+B}else A=c.current??0;const E=A*p,_=e+t;let I=0;E<=e?I=0:E>=_?I=1:I=(E-e)/t,a.current.style.transform=`scaleX(${I})`}l&&(r.current=requestAnimationFrame(M))};return l?r.current=requestAnimationFrame(M):M(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,p,h,e,t,n.length,c,u,m]),o.useEffect(()=>{if(!l&&a.current){const A=(c.current??0)*p,E=e+t;let _=0;A<=e?_=0:A>=E?_=1:_=(A-e)/t,a.current.style.transform=`scaleX(${_})`}});const b=s?.waveformDrawMode||"inverted";let w;b==="inverted"?w=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":w=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const g=n.renderMode==="spectrogram"||n.renderMode==="both",d=n.renderMode==="both",x=g?"#000":tt(w),y=Math.floor(i/2),C=i,k=n.index*i,S=tt(w);return v.jsxs(ui,{children:[d?v.jsxs(v.Fragment,{children:[v.jsx(Ot,{$color:"#000",$height:y,$top:k,$width:n.length}),v.jsx(Ot,{$color:S,$height:y,$top:k+y,$width:n.length})]}):v.jsx(Ot,{$color:x,$height:C,$top:k,$width:n.length}),v.jsx(di,{ref:a,$color:f,$height:C,$top:k,$width:n.length}),v.jsx(fi,{children:v.jsx(pa,{...n,transparentBackground:!0})})]})},on=o.createContext(null),mi=on.Provider;function hi(){const e=o.useContext(on);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const pi=60,Ba=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:r,className:s,showClipHeaders:i=!1,interactiveClips:l=!1,showFades:c=!1,touchOptimized:u=!1,onRemoveTrack:m,recordingState:h})=>{const p=wt(),{isPlaying:f,currentTimeRef:b,playbackStartTimeRef:w,audioStartPositionRef:g}=Re(),{selectionStart:d,selectionEnd:x,annotations:y,activeAnnotationId:C,annotationsEditable:k,linkEndpoints:S,continuousPlay:M,selectedTrackId:A,loopStart:E,loopEnd:_,isLoopEnabled:I}=De(),B=o.useContext(Vt),{setAnnotations:$,setActiveAnnotationId:W,setTrackMute:z,setTrackSolo:Y,setTrackVolume:j,setTrackPan:N,setSelection:L,play:ae,setScrollContainer:oe,setSelectedTrackId:q,setCurrentTime:fe,setLoopRegion:ue}=be(),{peaksDataArray:le,trackStates:Ee,tracks:P,duration:ee,samplesPerPixel:U,sampleRate:K,waveHeight:ie,timeScaleHeight:he,controls:te,playoutRef:Se,barWidth:Be,barGap:Xe,isReady:qe}=Me(),ne=o.useContext(on),Ve=o.useMemo(()=>{if(!ne)return new Map;const V=new Map;return P.forEach(X=>{if((ne.trackSpectrogramOverrides.get(X.id)?.renderMode??X.renderMode??"waveform")==="waveform")return;const me=ne.trackSpectrogramOverrides.get(X.id),pe=me?.colorMap??X.spectrogramColorMap??ne.spectrogramColorMap??"viridis",_e=me?.config??X.spectrogramConfig??ne.spectrogramConfig;V.set(X.id,{colorLUT:ne.getColorMap(pe),frequencyScaleFn:ne.getFrequencyScale(_e?.frequencyScale??"mel"),config:_e})}),V},[P,ne]),Oe=o.useMemo(()=>{if(ne?.spectrogramWorkerApi)return{registerCanvas:ne.spectrogramWorkerApi.registerCanvas.bind(ne.spectrogramWorkerApi),unregisterCanvas:ne.spectrogramWorkerApi.unregisterCanvas.bind(ne.spectrogramWorkerApi)}},[ne?.spectrogramWorkerApi]),[F,ye]=o.useState(null),[ce,je]=o.useState(!1),nt=o.useRef(null),Le=o.useCallback(V=>{nt.current=V,oe(V)},[oe]),O=P.reduce((V,X)=>X.clips.reduce((Q,me)=>{const pe=(me.startSample+me.durationSamples)/me.sampleRate;return Math.max(Q,pe)},V),0);let se=O>0?O:ee>0?ee:pi;if(h?.isRecording){const X=(h.startSample+h.durationSamples)/K;se=Math.max(se,X+10)}const ve=Math.floor(se*K/U),$e=async V=>{W(V.id);const X=M?void 0:V.end-V.start;try{await ae(V.start,X)}catch(Q){console.error("waveform-playlist: Failed to start playback for annotation",V.id,Q)}},Te=o.useCallback(V=>{if(V>=0&&V<P.length){const X=P[V];q(X.id)}},[P,q]),Ge=V=>{const X=V.currentTarget.getBoundingClientRect(),Q=te.show?te.width:0,pe=(V.clientX-X.left-Q)*U/K,Ce=V.clientY-X.top;let J=0,Ie=-1;for(let Fe=0;Fe<le.length;Fe++){const rt=le[Fe],Ne=rt.length>0?Math.max(1,...rt.map(Je=>Je.peaks.data.length)):1,ot=((ne?.trackSpectrogramOverrides.get(P[Fe]?.id)?.renderMode??P[Fe]?.renderMode??"waveform")==="both"?Ne*2:Ne)*ie+(i?22:0);if(Ce>=J&&Ce<J+ot){Ie=Fe;break}J+=ot}Ie!==-1&&Te(Ie),je(!0),fe(pe),L(pe,pe)},at=V=>{if(!ce)return;const X=V.currentTarget.getBoundingClientRect(),Q=te.show?te.width:0,pe=(V.clientX-X.left-Q)*U/K,_e=Math.min(d,pe),Ce=Math.max(d,pe);L(_e,Ce)},ut=V=>{if(!ce)return;je(!1);const X=V.currentTarget.getBoundingClientRect(),Q=te.show?te.width:0,pe=(V.clientX-X.left-Q)*U/K,_e=Math.min(d,pe),Ce=Math.max(d,pe);Math.abs(Ce-_e)<.1?(fe(_e),f&&Se.current?(Se.current.stop(),ae(_e)):Se.current&&Se.current.stop()):L(_e,Ce)};return P.some(V=>V.clips.length>0)&&le.length===0?v.jsx("div",{className:s,children:"Loading waveform..."}):v.jsxs(ha,{children:[v.jsx(Ct.Provider,{value:{samplesPerPixel:U,sampleRate:K,zoomLevels:[U],waveHeight:ie,timeScaleHeight:he,duration:se*1e3,controls:te,barWidth:Be,barGap:Xe},children:v.jsx(Qt,{theme:p,backgroundColor:tt(p.waveOutlineColor),timescaleBackgroundColor:p.timescaleBackgroundColor,scrollContainerWidth:ve+(te.show?te.width:0),timescaleWidth:ve,tracksWidth:ve,controlsWidth:te.show?te.width:0,onTracksMouseDown:Ge,onTracksMouseMove:at,onTracksMouseUp:ut,scrollContainerRef:Le,isSelecting:ce,"data-playlist-state":qe?"ready":"loading",timescale:he>0?v.jsxs(v.Fragment,{children:[v.jsx(ga,{renderTimestamp:t}),I&&v.jsx(qr,{startPosition:Math.min(E,_)*K/U,endPosition:Math.max(E,_)*K/U,markerColor:p.loopMarkerColor,regionColor:p.loopRegionColor,minPosition:0,maxPosition:ve,controlsOffset:te.show?te.width:0,onLoopRegionChange:(V,X)=>{const Q=V*U/K,me=X*U/K;ue(Q,me)}})]}):void 0,children:v.jsxs(v.Fragment,{children:[le.map((V,X)=>{const Q=P[X];if(!Q)return null;const me=Ee[X]||{name:`Track ${X+1}`,muted:!1,soloed:!1,volume:1,pan:0},pe=ne?.trackSpectrogramOverrides.get(Q.id)?.renderMode??Q.renderMode??"waveform",_e=e?e(X):v.jsxs(To,{onClick:()=>Te(X),children:[v.jsxs(Ro,{style:{justifyContent:"center",position:"relative"},children:[m&&v.jsx($o,{onClick:J=>{J.stopPropagation(),m(X)}}),v.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:me.name||`Track ${X+1}`}),ne?.renderMenuItems&&v.jsx("span",{style:{position:"absolute",right:0,top:0},children:v.jsx(jo,{items:J=>ne.renderMenuItems({renderMode:pe,onRenderModeChange:Ie=>ne.setTrackRenderMode(Q.id,Ie),onOpenSettings:()=>ye(Q.id),onClose:J})})})]}),v.jsxs(_o,{children:[v.jsx(Wn,{$variant:me.muted?"danger":"outline",onClick:()=>z(X,!me.muted),children:"Mute"}),v.jsx(Wn,{$variant:me.soloed?"info":"outline",onClick:()=>Y(X,!me.soloed),children:"Solo"})]}),v.jsxs(Zn,{children:[v.jsx(Do,{}),v.jsx(Pn,{min:"0",max:"1",step:"0.01",value:me.volume,onChange:J=>j(X,parseFloat(J.target.value))}),v.jsx(Bo,{})]}),v.jsxs(Zn,{children:[v.jsx("span",{children:"L"}),v.jsx(Pn,{min:"-1",max:"1",step:"0.01",value:me.pan,onChange:J=>N(X,parseFloat(J.target.value))}),v.jsx("span",{children:"R"})]})]}),Ce=V.length>0?Math.max(1,...V.map(J=>J.peaks.data.length)):1;return v.jsx(tn.Provider,{value:_e,children:v.jsxs(ba,{numChannels:Ce,backgroundColor:tt(p.waveOutlineColor),offset:0,width:ve,hasClipHeaders:i,trackId:Q.id,isSelected:Q.id===A,children:[pe!=="waveform"&&(()=>{const J=Ve.get(Q.id),Ie=J?.config;return!Ie?.labels||!J?null:v.jsx(mo,{waveHeight:ie,numChannels:Ce,frequencyScaleFn:J.frequencyScaleFn,minFrequency:Ie.minFrequency??0,maxFrequency:Ie.maxFrequency??K/2,labelsColor:Ie.labelsColor,labelsBackground:Ie.labelsBackground,renderMode:pe,hasClipHeaders:i})})(),V.map((J,Ie)=>{const Fe=J.peaks,rt=Fe.length;return v.jsx(Yt,{clipId:J.clipId,trackIndex:X,clipIndex:Ie,trackName:J.trackName,startSample:J.startSample,durationSamples:J.durationSamples,samplesPerPixel:U,showHeader:i,disableHeaderDrag:!l,isSelected:Q.id===A,trackId:Q.id,fadeIn:J.fadeIn,fadeOut:J.fadeOut,sampleRate:K,showFades:c,touchOptimized:u,onMouseDown:Ne=>{Ne.target.closest('[role="button"][aria-roledescription="draggable"]')||Te(X)},children:Fe.data.map((Ne,Ye)=>{const dt=ne?.spectrogramDataMap.get(J.clipId),ot=dt?.[Ye]??dt?.[0],Je=Ve.get(Q.id),ze=Je?.config;return v.jsx(zn,{index:Ye,data:Ne,bits:Fe.bits,length:rt,isSelected:Q.id===A,clipStartSample:J.startSample,clipDurationSamples:J.durationSamples,renderMode:pe,spectrogramData:ot,samplesPerPixel:U,spectrogramColorLUT:Je?.colorLUT,spectrogramFrequencyScaleFn:Je?.frequencyScaleFn,spectrogramMinFrequency:ze?.minFrequency,spectrogramMaxFrequency:ze?.maxFrequency,spectrogramWorkerApi:Oe,spectrogramClipId:J.clipId,spectrogramOnCanvasesReady:ne?(xt,Qe)=>{ne.registerSpectrogramCanvases(J.clipId,Ye,xt,Qe)}:void 0},`${J.clipId}-${Ye}`)})},J.clipId)}),h?.isRecording&&h.trackId===Q.id&&h.peaks.length>0&&v.jsx(Yt,{clipId:"recording-preview",trackIndex:X,clipIndex:V.length,trackName:"Recording...",startSample:h.startSample,durationSamples:h.durationSamples,samplesPerPixel:U,showHeader:i,disableHeaderDrag:!0,isSelected:Q.id===A,trackId:Q.id,children:v.jsx(zn,{index:0,data:h.peaks,bits:16,length:Math.floor(h.peaks.length/2),isSelected:Q.id===A,clipStartSample:h.startSample,clipDurationSamples:h.durationSamples},`${Q.id}-recording-0`)},`${Q.id}-recording`)]})},Q.id)}),y.length>0&&B&&v.jsx(B.AnnotationBoxesWrapper,{height:30,width:ve,children:y.map((V,X)=>{const Q=V.start*K/U,me=V.end*K/U,pe=r?r(V,X):V.id;return v.jsx(B.AnnotationBox,{annotationId:V.id,annotationIndex:X,startPosition:Q,endPosition:me,label:pe,color:"#ff9800",isActive:V.id===C,onClick:()=>$e(V),editable:k},V.id)})}),d!==x&&v.jsx(da,{startPosition:Math.min(d,x)*K/U+(te.show?te.width:0),endPosition:Math.max(d,x)*K/U+(te.show?te.width:0),color:p.selectionColor}),(f||d===x)&&(n?n({position:(b.current??0)*K/U+(te.show?te.width:0),color:p.playheadColor,isPlaying:f,currentTimeRef:b,playbackStartTimeRef:w,audioStartPositionRef:g,samplesPerPixel:U,sampleRate:K,controlsOffset:te.show?te.width:0,getAudioContextTime:()=>Z.getContext().currentTime}):v.jsx(ci,{color:p.playheadColor,controlsOffset:te.show?te.width:0}))]})})}),ne?.SettingsModal&&typeof document<"u"&&Hn.createPortal(v.jsx(ne.SettingsModal,{open:F!==null,onClose:()=>ye(null),config:F!==null?ne.trackSpectrogramOverrides.get(F)?.config??P.find(V=>V.id===F)?.spectrogramConfig??ne.spectrogramConfig??{}:{},colorMap:F!==null?ne.trackSpectrogramOverrides.get(F)?.colorMap??P.find(V=>V.id===F)?.spectrogramColorMap??ne.spectrogramColorMap??"viridis":"viridis",onApply:(V,X)=>{F!==null&&ne.setTrackSpectrogramConfig(F,V,X)}}),document.body)]})},Fa=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:a,annotationListConfig:r,scrollActivePosition:s="center",scrollActiveContainer:i="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:m,continuousPlay:h}=De(),p=ct(),{setAnnotations:f}=be(),b=r??{linkEndpoints:m,continuousPlay:h},w=o.useCallback(d=>{f(d),n?.(d)},[f,n]),{AnnotationText:g}=p;return v.jsx(g,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:i,editable:u,controls:u?a:void 0,annotationListConfig:b,height:e,onAnnotationUpdate:w,renderAnnotationItem:t})},gi=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:i,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:m,showClipHeaders:h=!1,interactiveClips:p=!1,showFades:f=!1,touchOptimized:b=!1,onRemoveTrack:w,recordingState:g})=>{const{annotations:d}=De();return v.jsxs(v.Fragment,{children:[v.jsx(Ba,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:l,className:m,showClipHeaders:h,interactiveClips:p,showFades:f,touchOptimized:b,onRemoveTrack:w,recordingState:g}),d.length>0&&v.jsx(Fa,{height:s,renderAnnotationItem:i,controls:a,annotationListConfig:r,scrollActivePosition:c,scrollActiveContainer:u})]})},bi=R.div`
966
981
  position: absolute;
967
982
  top: 0;
968
983
  left: 0;
@@ -972,9 +987,9 @@ self.onmessage = function(e) {
972
987
  z-index: 100;
973
988
  pointer-events: none;
974
989
  will-change: transform;
975
- `,oi=({color:e="#ff0000",controlsOffset:t=0})=>{const n=s.useRef(null),a=s.useRef(null),{isPlaying:r,currentTimeRef:o}=Wt(),{samplesPerPixel:i,sampleRate:l,progressBarWidth:c}=Zt();return s.useEffect(()=>{const u=()=>{if(n.current){const v=(o.current??0)*l/i+t;n.current.style.transform=`translate3d(${v}px, 0, 0)`}r&&(a.current=requestAnimationFrame(u))};return r?a.current=requestAnimationFrame(u):u(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,l,i,t,o]),s.useEffect(()=>{if(!r&&n.current){const f=(o.current??0)*l/i+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}}),g.jsx(si,{ref:n,$color:e,$width:c,"data-playhead":!0})},ii=D.div`
990
+ `,vi=({color:e="#ff0000",controlsOffset:t=0})=>{const n=o.useRef(null),a=o.useRef(null),{isPlaying:r,currentTimeRef:s}=Wt(),{samplesPerPixel:i,sampleRate:l,progressBarWidth:c}=Zt();return o.useEffect(()=>{const u=()=>{if(n.current){const h=(s.current??0)*l/i+t;n.current.style.transform=`translate3d(${h}px, 0, 0)`}r&&(a.current=requestAnimationFrame(u))};return r?a.current=requestAnimationFrame(u):u(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,l,i,t,s]),o.useEffect(()=>{if(!r&&n.current){const m=(s.current??0)*l/i+t;n.current.style.transform=`translate3d(${m}px, 0, 0)`}}),v.jsx(bi,{ref:n,$color:e,$width:c,"data-playhead":!0})},Ci=R.div`
976
991
  position: relative;
977
- `,li=D.div`
992
+ `,wi=R.div`
978
993
  position: absolute;
979
994
  top: ${e=>e.$top}px;
980
995
  left: 0;
@@ -985,7 +1000,7 @@ self.onmessage = function(e) {
985
1000
  transform: translateZ(0);
986
1001
  backface-visibility: hidden;
987
1002
  will-change: transform;
988
- `,ci=D.div`
1003
+ `,yi=R.div`
989
1004
  position: absolute;
990
1005
  top: ${e=>e.$top}px;
991
1006
  left: 0;
@@ -994,8 +1009,8 @@ self.onmessage = function(e) {
994
1009
  pointer-events: none;
995
1010
  z-index: 1;
996
1011
  will-change: width;
997
- `,ui=D.div`
1012
+ `,xi=R.div`
998
1013
  position: relative;
999
1014
  z-index: 2;
1000
- `,di=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=s.useRef(null),r=s.useRef(null),o=Ct(),{waveHeight:i}=Bt(),{isPlaying:l,currentTimeRef:c}=Wt(),{samplesPerPixel:u,sampleRate:f}=Zt(),v=o?.waveProgressColor||"rgba(0, 0, 0, 0.1)";s.useEffect(()=>{const y=()=>{if(a.current){const m=(c.current??0)*f,k=e+t;let w=0;if(m<=e)w=0;else if(m>=k)w=n.length;else{const b=m-e;w=Math.floor(b/u)}a.current.style.width=`${w}px`}l&&(r.current=requestAnimationFrame(y))};return l?r.current=requestAnimationFrame(y):y(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,f,u,e,t,n.length,c]),s.useEffect(()=>{if(!l&&a.current){const p=(c.current??0)*f,m=e+t;let k=0;if(p<=e)k=0;else if(p>=m)k=n.length;else{const w=p-e;k=Math.floor(w/u)}a.current.style.width=`${k}px`}});const h=o?.waveformDrawMode||"inverted";let d;h==="inverted"?d=o?.selectedWaveFillColor||o?.waveFillColor||"white":d=o?.selectedWaveOutlineColor||o?.waveOutlineColor||"grey";const C=at(d);return g.jsxs(ii,{children:[g.jsx(li,{$color:C,$height:i,$top:n.index*i,$width:n.length}),g.jsx(ci,{ref:a,$color:v,$height:i,$top:n.index*i}),g.jsx(ui,{children:g.jsx(oa,{...n,isSelected:!0,transparentBackground:!0})})]})},_a=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:a,className:r})=>{const o=Ct(),{isPlaying:i}=Wt(),{annotations:l,activeAnnotationId:c}=Pt(),u=s.useContext(Vt),{play:f,seekTo:v,setActiveAnnotationId:h,setAnnotations:d,setScrollContainer:C}=nn(),{duration:y,peaksDataArray:p,sampleRate:m,waveHeight:k,timeScaleHeight:w,samplesPerPixel:b,controls:x,playoutRef:S,barWidth:E,barGap:I}=Zt(),[$,M]=s.useState(0),[A,B]=s.useState(0),[_,R]=s.useState(!1),W=s.useRef(null),L=s.useCallback(O=>{W.current=O,C(O)},[C]),P=Math.floor(y*m/b),U=s.useCallback(async O=>{h(O.id);try{await f(O.start)}catch(N){console.error("waveform-playlist: Failed to start playback for annotation",O.id,N)}},[h,f]),H=s.useCallback(O=>{d(O),a?.(O)},[d,a]),{onDragStart:ne,onDragMove:le,onDragEnd:se}=pa({annotations:l,onAnnotationsChange:H,samplesPerPixel:b,sampleRate:m,duration:y,linkEndpoints:n}),oe=s.useCallback(O=>{const N=O.currentTarget.getBoundingClientRect(),be=x.show?x.width:0,z=(O.clientX-N.left-be)*b/m;R(!0),M(z),B(z)},[x,b,m]),ye=s.useCallback(O=>{if(!_)return;const N=O.currentTarget.getBoundingClientRect(),be=x.show?x.width:0,z=(O.clientX-N.left-be)*b/m;B(z)},[_,x,b,m]),ce=s.useCallback(O=>{if(!_)return;R(!1);const N=O.currentTarget.getBoundingClientRect(),be=x.show?x.width:0,z=(O.clientX-N.left-be)*b/m,me=Math.min($,z),Ie=Math.max($,z);Math.abs(Ie-me)<.1?(v(me),M(me),B(me),i&&S.current&&(S.current.stop(),f(me))):(M(me),B(Ie))},[_,$,b,m,x,v,i,S,f]);if(p.length===0)return g.jsx("div",{className:r,children:"Loading waveform..."});const fe=null;return g.jsx(sa,{children:g.jsx(yt.Provider,{value:{samplesPerPixel:b,sampleRate:m,zoomLevels:[b],waveHeight:k,timeScaleHeight:w,duration:y*1e3,controls:x,barWidth:E,barGap:I},children:g.jsx(qt,{theme:o,backgroundColor:at(o.waveOutlineColor),timescaleBackgroundColor:o.timescaleBackgroundColor,scrollContainerWidth:P+(x.show?x.width:0),timescaleWidth:P,tracksWidth:P,controlsWidth:x.show?x.width:0,onTracksMouseDown:oe,onTracksMouseMove:ye,onTracksMouseUp:ce,scrollContainerRef:L,isSelecting:_,timescale:w>0?g.jsx(ia,{}):void 0,children:g.jsxs(g.Fragment,{children:[p.map((O,N)=>{const be=O.length>0?Math.max(...O.map(K=>K.peaks.data.length)):1;return g.jsx(Qt.Provider,{value:fe,children:g.jsx(la,{numChannels:be,backgroundColor:at(o.waveOutlineColor),offset:0,width:P,hasClipHeaders:!1,trackId:`media-element-track-${N}`,isSelected:!0,children:O.map((K,z)=>{const me=K.peaks,Ie=me.length;return g.jsx(Gt,{clipId:K.clipId,trackIndex:N,clipIndex:z,trackName:K.trackName,startSample:K.startSample,durationSamples:K.durationSamples,samplesPerPixel:b,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${N}`,children:me.data.map((ae,Te)=>g.jsx(di,{index:Te,data:ae,bits:me.bits,length:Ie,clipStartSample:K.startSample,clipDurationSamples:K.durationSamples},`${N}-${z}-${Te}`))},`${N}-${z}`)})})},N)}),l.length>0&&u&&g.jsx(Ge.DndContext,{onDragStart:ne,onDragMove:le,onDragEnd:se,modifiers:t?[Oa.restrictToHorizontalAxis]:[],children:g.jsx(u.AnnotationBoxesWrapper,{height:30,width:P,children:l.map((O,N)=>{const be=O.start*m/b,K=O.end*m/b,z=e?e(O,N):O.id;return g.jsx(u.AnnotationBox,{annotationId:O.id,annotationIndex:N,startPosition:be,endPosition:K,label:z,color:"#ff9800",isActive:O.id===c,onClick:()=>U(O),editable:t},O.id)})})}),$!==A&&g.jsx(na,{startPosition:Math.min($,A)*m/b+(x.show?x.width:0),endPosition:Math.max($,A)*m/b+(x.show?x.width:0),color:o.selectionColor}),g.jsx(oi,{color:o.playheadColor,controlsOffset:x.show?x.width:0})]})})})})},Ea=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,editable:a=!1,controls:r,annotationListConfig:o,scrollActivePosition:i="center",scrollActiveContainer:l="nearest"})=>{const{annotations:c,activeAnnotationId:u,continuousPlay:f}=Pt(),v=it(),{setAnnotations:h}=nn(),d=o??{linkEndpoints:!1,continuousPlay:f},C=s.useCallback(p=>{h(p),n?.(p)},[h,n]),{AnnotationText:y}=v;return g.jsx(y,{annotations:c,activeAnnotationId:u??void 0,shouldScrollToActive:!0,scrollActivePosition:i,scrollActiveContainer:l,editable:a,controls:a?r:void 0,annotationListConfig:d,height:e,onAnnotationUpdate:C,renderAnnotationItem:t})},fi=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:a=!1,linkEndpoints:r=!1,onAnnotationUpdate:o,scrollActivePosition:i="center",scrollActiveContainer:l="nearest",className:c})=>{const{annotations:u}=Pt();return g.jsxs(g.Fragment,{children:[g.jsx(_a,{getAnnotationBoxLabel:t,editable:a,linkEndpoints:r,onAnnotationUpdate:o,className:c}),u.length>0&&g.jsx(Ea,{height:e,renderAnnotationItem:n,onAnnotationUpdate:o,editable:a,annotationListConfig:{linkEndpoints:r,continuousPlay:!1},scrollActivePosition:i,scrollActiveContainer:l})]})};exports.Tone=Ln;exports.AnnotationIntegrationProvider=Xo;exports.AudioPosition=Lo;exports.AutomaticScrollCheckbox=Ho;exports.ContinuousPlayCheckbox=Oo;exports.DownloadAnnotationsButton=Yo;exports.EditableCheckbox=Go;exports.ExportWavButton=Ko;exports.FastForwardButton=To;exports.LinkEndpointsCheckbox=No;exports.LoopButton=Bo;exports.MasterVolumeControl=Zo;exports.MediaElementAnnotationList=Ea;exports.MediaElementPlaylist=_a;exports.MediaElementPlaylistProvider=Ao;exports.MediaElementWaveform=fi;exports.PauseButton=_o;exports.PlayButton=Mo;exports.PlaylistAnnotationList=Ma;exports.PlaylistVisualization=Aa;exports.RewindButton=$o;exports.SelectionTimeInputs=zo;exports.SetLoopRegionButton=Fo;exports.SkipBackwardButton=Ro;exports.SkipForwardButton=Do;exports.SpectrogramIntegrationProvider=ti;exports.StopButton=Eo;exports.TimeFormatSelect=Vo;exports.Waveform=ri;exports.WaveformPlaylistProvider=ko;exports.ZoomInButton=Wo;exports.ZoomOutButton=Po;exports.createEffectChain=uo;exports.createEffectInstance=bt;exports.effectCategories=oo;exports.effectDefinitions=wt;exports.getEffectDefinition=tn;exports.getEffectsByCategory=so;exports.getShortcutLabel=no;exports.getWaveformDataMetadata=Os;exports.loadPeaksFromWaveformData=Xs;exports.loadWaveformData=en;exports.useAnnotationDragHandlers=pa;exports.useAnnotationIntegration=it;exports.useAnnotationKeyboardControls=ro;exports.useAudioTracks=qs;exports.useClipDragHandlers=Js;exports.useClipSplitting=to;exports.useDragSensors=eo;exports.useDynamicEffects=fo;exports.useExportWav=ga;exports.useKeyboardShortcuts=Dt;exports.useMasterAnalyser=Ys;exports.useMasterVolume=ma;exports.useMediaElementAnimation=Wt;exports.useMediaElementControls=nn;exports.useMediaElementData=Zt;exports.useMediaElementState=Pt;exports.usePlaybackAnimation=Fe;exports.usePlaybackShortcuts=ao;exports.usePlaylistControls=ge;exports.usePlaylistData=$e;exports.usePlaylistState=We;exports.useSpectrogramIntegration=ni;exports.useTimeFormat=da;exports.useTrackDynamicEffects=mo;exports.useZoomControls=fa;exports.waveformDataToPeaks=ua;
1015
+ `,ki=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=o.useRef(null),r=o.useRef(null),s=wt(),{waveHeight:i}=Bt(),{isPlaying:l,currentTimeRef:c}=Wt(),{samplesPerPixel:u,sampleRate:m}=Zt(),h=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";o.useEffect(()=>{const w=()=>{if(a.current){const d=(c.current??0)*m,x=e+t;let y=0;if(d<=e)y=0;else if(d>=x)y=n.length;else{const C=d-e;y=Math.floor(C/u)}a.current.style.width=`${y}px`}l&&(r.current=requestAnimationFrame(w))};return l?r.current=requestAnimationFrame(w):w(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,m,u,e,t,n.length,c]),o.useEffect(()=>{if(!l&&a.current){const g=(c.current??0)*m,d=e+t;let x=0;if(g<=e)x=0;else if(g>=d)x=n.length;else{const y=g-e;x=Math.floor(y/u)}a.current.style.width=`${x}px`}});const p=s?.waveformDrawMode||"inverted";let f;p==="inverted"?f=s?.selectedWaveFillColor||s?.waveFillColor||"white":f=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const b=tt(f);return v.jsxs(Ci,{children:[v.jsx(wi,{$color:b,$height:i,$top:n.index*i,$width:n.length}),v.jsx(yi,{ref:a,$color:h,$height:i,$top:n.index*i}),v.jsx(xi,{children:v.jsx(pa,{...n,isSelected:!0,transparentBackground:!0})})]})},Wa=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:a,className:r})=>{const s=wt(),{isPlaying:i}=Wt(),{annotations:l,activeAnnotationId:c}=Pt(),u=o.useContext(Vt),{play:m,seekTo:h,setActiveAnnotationId:p,setAnnotations:f,setScrollContainer:b}=rn(),{duration:w,peaksDataArray:g,sampleRate:d,waveHeight:x,timeScaleHeight:y,samplesPerPixel:C,controls:k,playoutRef:S,barWidth:M,barGap:A}=Zt(),[E,_]=o.useState(0),[I,B]=o.useState(0),[$,W]=o.useState(!1),z=o.useRef(null),Y=o.useCallback(P=>{z.current=P,b(P)},[b]),j=Math.floor(w*d/C),N=o.useCallback(async P=>{p(P.id);try{await m(P.start)}catch(ee){console.error("waveform-playlist: Failed to start playback for annotation",P.id,ee)}},[p,m]),L=o.useCallback(P=>{f(P),a?.(P)},[f,a]),{onDragStart:ae,onDragMove:oe,onDragEnd:q}=ka({annotations:l,onAnnotationsChange:L,samplesPerPixel:C,sampleRate:d,duration:w,linkEndpoints:n}),fe=o.useCallback(P=>{const ee=P.currentTarget.getBoundingClientRect(),U=k.show?k.width:0,ie=(P.clientX-ee.left-U)*C/d;W(!0),_(ie),B(ie)},[k,C,d]),ue=o.useCallback(P=>{if(!$)return;const ee=P.currentTarget.getBoundingClientRect(),U=k.show?k.width:0,ie=(P.clientX-ee.left-U)*C/d;B(ie)},[$,k,C,d]),le=o.useCallback(P=>{if(!$)return;W(!1);const ee=P.currentTarget.getBoundingClientRect(),U=k.show?k.width:0,ie=(P.clientX-ee.left-U)*C/d,he=Math.min(E,ie),te=Math.max(E,ie);Math.abs(te-he)<.1?(h(he),_(he),B(he),i&&S.current&&(S.current.stop(),m(he))):(_(he),B(te))},[$,E,C,d,k,h,i,S,m]);if(g.length===0)return v.jsx("div",{className:r,children:"Loading waveform..."});const Ee=null;return v.jsx(ha,{children:v.jsx(Ct.Provider,{value:{samplesPerPixel:C,sampleRate:d,zoomLevels:[C],waveHeight:x,timeScaleHeight:y,duration:w*1e3,controls:k,barWidth:M,barGap:A},children:v.jsx(Qt,{theme:s,backgroundColor:tt(s.waveOutlineColor),timescaleBackgroundColor:s.timescaleBackgroundColor,scrollContainerWidth:j+(k.show?k.width:0),timescaleWidth:j,tracksWidth:j,controlsWidth:k.show?k.width:0,onTracksMouseDown:fe,onTracksMouseMove:ue,onTracksMouseUp:le,scrollContainerRef:Y,isSelecting:$,timescale:y>0?v.jsx(ga,{}):void 0,children:v.jsxs(v.Fragment,{children:[g.map((P,ee)=>{const U=P.length>0?Math.max(...P.map(K=>K.peaks.data.length)):1;return v.jsx(tn.Provider,{value:Ee,children:v.jsx(ba,{numChannels:U,backgroundColor:tt(s.waveOutlineColor),offset:0,width:j,hasClipHeaders:!1,trackId:`media-element-track-${ee}`,isSelected:!0,children:P.map((K,ie)=>{const he=K.peaks,te=he.length;return v.jsx(Yt,{clipId:K.clipId,trackIndex:ee,clipIndex:ie,trackName:K.trackName,startSample:K.startSample,durationSamples:K.durationSamples,samplesPerPixel:C,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${ee}`,children:he.data.map((Se,Be)=>v.jsx(ki,{index:Be,data:Se,bits:he.bits,length:te,clipStartSample:K.startSample,clipDurationSamples:K.durationSamples},`${ee}-${ie}-${Be}`))},`${ee}-${ie}`)})})},ee)}),l.length>0&&u&&v.jsx(Ke.DndContext,{onDragStart:ae,onDragMove:oe,onDragEnd:q,modifiers:t?[Qa.restrictToHorizontalAxis]:[],children:v.jsx(u.AnnotationBoxesWrapper,{height:30,width:j,children:l.map((P,ee)=>{const U=P.start*d/C,K=P.end*d/C,ie=e?e(P,ee):P.id;return v.jsx(u.AnnotationBox,{annotationId:P.id,annotationIndex:ee,startPosition:U,endPosition:K,label:ie,color:"#ff9800",isActive:P.id===c,onClick:()=>N(P),editable:t},P.id)})})}),E!==I&&v.jsx(da,{startPosition:Math.min(E,I)*d/C+(k.show?k.width:0),endPosition:Math.max(E,I)*d/C+(k.show?k.width:0),color:s.selectionColor}),v.jsx(vi,{color:s.playheadColor,controlsOffset:k.show?k.width:0})]})})})})},Pa=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,editable:a=!1,controls:r,annotationListConfig:s,scrollActivePosition:i="center",scrollActiveContainer:l="nearest"})=>{const{annotations:c,activeAnnotationId:u,continuousPlay:m}=Pt(),h=ct(),{setAnnotations:p}=rn(),f=s??{linkEndpoints:!1,continuousPlay:m},b=o.useCallback(g=>{p(g),n?.(g)},[p,n]),{AnnotationText:w}=h;return v.jsx(w,{annotations:c,activeAnnotationId:u??void 0,shouldScrollToActive:!0,scrollActivePosition:i,scrollActiveContainer:l,editable:a,controls:a?r:void 0,annotationListConfig:f,height:e,onAnnotationUpdate:b,renderAnnotationItem:t})},Si=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:a=!1,linkEndpoints:r=!1,onAnnotationUpdate:s,scrollActivePosition:i="center",scrollActiveContainer:l="nearest",className:c})=>{const{annotations:u}=Pt();return v.jsxs(v.Fragment,{children:[v.jsx(Wa,{getAnnotationBoxLabel:t,editable:a,linkEndpoints:r,onAnnotationUpdate:s,className:c}),u.length>0&&v.jsx(Pa,{height:e,renderAnnotationItem:n,onAnnotationUpdate:s,editable:a,annotationListConfig:{linkEndpoints:r,continuousPlay:!1},scrollActivePosition:i,scrollActiveContainer:l})]})};exports.Tone=On;exports.AnnotationIntegrationProvider=ni;exports.AudioPosition=Qs;exports.AutomaticScrollCheckbox=ti;exports.ContinuousPlayCheckbox=ai;exports.DownloadAnnotationsButton=si;exports.EditableCheckbox=oi;exports.ExportWavButton=ii;exports.FastForwardButton=Hs;exports.LinkEndpointsCheckbox=ri;exports.LoopButton=Gs;exports.MasterVolumeControl=Ks;exports.MediaElementAnnotationList=Pa;exports.MediaElementPlaylist=Wa;exports.MediaElementPlaylistProvider=Zs;exports.MediaElementWaveform=Si;exports.PauseButton=js;exports.PlayButton=Vs;exports.PlaylistAnnotationList=Fa;exports.PlaylistVisualization=Ba;exports.RewindButton=zs;exports.SelectionTimeInputs=ei;exports.SetLoopRegionButton=Ns;exports.SkipBackwardButton=Xs;exports.SkipForwardButton=Os;exports.SpectrogramIntegrationProvider=mi;exports.StopButton=Ls;exports.TimeFormatSelect=qs;exports.Waveform=gi;exports.WaveformPlaylistProvider=Fs;exports.ZoomInButton=Ys;exports.ZoomOutButton=Us;exports.createEffectChain=ys;exports.createEffectInstance=bt;exports.effectCategories=bs;exports.effectDefinitions=yt;exports.getEffectDefinition=an;exports.getEffectsByCategory=gs;exports.getShortcutLabel=ms;exports.getWaveformDataMetadata=rs;exports.loadPeaksFromWaveformData=as;exports.loadWaveformData=nn;exports.useAnnotationDragHandlers=ka;exports.useAnnotationIntegration=ct;exports.useAnnotationKeyboardControls=ps;exports.useAudioTracks=ls;exports.useClipDragHandlers=cs;exports.useClipSplitting=fs;exports.useDragSensors=ds;exports.useDynamicEffects=xs;exports.useDynamicTracks=Bs;exports.useExportWav=Sa;exports.useKeyboardShortcuts=Dt;exports.useMasterAnalyser=is;exports.useMasterVolume=xa;exports.useMediaElementAnimation=Wt;exports.useMediaElementControls=rn;exports.useMediaElementData=Zt;exports.useMediaElementState=Pt;exports.usePlaybackAnimation=Re;exports.usePlaybackShortcuts=hs;exports.usePlaylistControls=be;exports.usePlaylistData=Me;exports.usePlaylistState=De;exports.useSpectrogramIntegration=hi;exports.useTimeFormat=wa;exports.useTrackDynamicEffects=ks;exports.useZoomControls=ya;exports.waveformDataToPeaks=Ca;
1001
1016
  //# sourceMappingURL=index.js.map