@waveform-playlist/browser 5.0.0-alpha.17 → 5.0.0-alpha.19

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 Ir=Object.create;var Ot=Object.defineProperty;var Sr=Object.getOwnPropertyDescriptor;var Ar=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Mr=Object.prototype.hasOwnProperty;var Rr=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Ar(t))!Mr.call(e,a)&&a!==n&&Ot(e,a,{get:()=>t[a],enumerable:!(r=Sr(t,a))||r.enumerable});return e};var Er=(e,t,n)=>(n=e!=null?Ir($r(e)):{},Rr(t||!e||!e.__esModule?Ot(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("tone"),v=require("react/jsx-runtime"),i=require("react"),A=require("styled-components"),De=require("@dnd-kit/core"),Dr=require("@dnd-kit/modifiers");var Rt=typeof document<"u"?document.currentScript:null;function hn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const pn=hn(W),G=hn(i);function Kt(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r;n[a]=t?s:1-s}return n}function Br(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r,o=t?a:e-1-a;n[o]=Math.exp(2*s-1)/Math.E}return n}function Tr(e,t){const n=new Float32Array(e),r=t?Math.PI/2:-Math.PI/2;for(let a=0;a<e;a++)n[a]=Math.sin(Math.PI*a/e-r)/2+.5;return n}function Wr(e,t,n=10){const r=new Float32Array(e);for(let a=0;a<e;a++){const s=t?a:e-1-a,o=a/e;r[s]=Math.log(1+n*o)/Math.log(1+n)}return r}function gn(e,t,n){switch(e){case"linear":return Kt(t,n);case"exponential":return Br(t,n);case"sCurve":return Tr(t,n);case"logarithmic":return Wr(t,n);default:return Kt(t,n)}}function Ut(e,t,n,r="linear",a=0,s=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=gn(r,1e4,!0),l=new Float32Array(o.length),c=s-a;for(let u=0;u<o.length;u++)l[u]=a+o[u]*c;e.setValueCurveAtTime(l,t,n)}}function Jt(e,t,n,r="linear",a=1,s=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=gn(r,1e4,!1),l=new Float32Array(o.length),c=a-s;for(let u=0;u<o.length;u++)l[u]=s+o[u]*c;e.setValueCurveAtTime(l,t,n)}}var _r=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new W.Volume(this.gainToDb(e.track.gain)),this.panNode=new W.Panner(e.track.stereoPan),this.muteGain=new W.Gain(e.track.muted?0:1);const t=e.destination||W.getDestination();if(e.effects){const r=e.effects(this.muteGain,t,!1);r&&(this.effectsCleanup=r)}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(r=>{const a=new W.Player({url:r.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new W.Gain(r.gain);return a.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:a,clipInfo:r,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGain:a}=e,s=a.gain._param;s.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const l=r.fadeIn.duration;if(o<=0)Ut(s,t,l,r.fadeIn.type||"linear",0,r.gain);else{const c=l-o,u=o/l,d=r.gain*u;Ut(s,t,c,r.fadeIn.type||"linear",d,r.gain)}}else s.setValueAtTime(r.gain,t);if(r.fadeOut){const c=r.duration-r.fadeOut.duration-o;if(c>0){const u=t+c;Jt(s,u,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(c>-r.fadeOut.duration){const u=-c,d=r.fadeOut.duration-u,x=u/r.fadeOut.duration,g=r.gain*(1-x);Jt(s,t,d,r.fadeOut.type||"linear",g,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,this.muteGain.gain.value=e?0:1}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(r=>{r.player.stop(),r.player.disconnect(),r.player.dispose();const a=new W.Player({url:r.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});a.connect(r.fadeGain),r.player=a,r.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(r=>{const{player:a,clipInfo:s}=r,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??W.now();if(r.playStartTime=u,o>=l){const d=o-l+s.offset,x=s.duration-(o-l),g=n?Math.min(n,x):x;r.pausedPosition=d,this.scheduleFades(r,u,d),a.start(u,d,g)}else{const d=l-o,x=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(r.pausedPosition=s.offset,this.scheduleFades(r,u+d,s.offset),a.start(u+d,s.offset,x)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(W.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??W.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}},Fr=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 W.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,W.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 W.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new _r(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 r=e??W.now(),a=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(a>=l){const c=a-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r,c,n)}else{const c=l-a;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r+c,0,n)}}),t!==void 0?W.getTransport().start(r,t):W.getTransport().start(r)}pause(){W.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){W.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 r=this.manualMuteState.get(n)??!1;t.setMute(r)}else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return W.getTransport().seconds}seekTo(e){W.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return W.getContext()}get sampleRate(){return W.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},ft=null;function Zr(){return ft||(ft=new W.Context,W.setContext(ft)),ft}async function Et(){const e=Zr();e.state!=="running"&&await e.resume()}const Tt=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[Tt.Translate.toString(e),Tt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),Vr=new Map([["bold",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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"}))]]),Pr=new Map([["bold",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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"}))]]),zr=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),Ft=G.forwardRef((e,t)=>{const{alt:n,color:r,size:a,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:x,weight:g="regular",mirrored:f=!1,...C}=G.useContext(zr);return G.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:a??x,height:a??x,fill:r??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...C,...u},!!n&&G.createElement("title",null,n),l,c.get(s??g))});Ft.displayName="IconBase";const bn=G.forwardRef((e,t)=>G.createElement(Ft,{ref:t,...e,weights:Vr}));bn.displayName="SpeakerHighIcon";const vn=G.forwardRef((e,t)=>G.createElement(Ft,{ref:t,...e,weights:Pr}));vn.displayName="SpeakerLowIcon";A.span`
1
+ "use strict";var Ia=Object.create;var Ot=Object.defineProperty;var Sa=Object.getOwnPropertyDescriptor;var Aa=Object.getOwnPropertyNames;var $a=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var Ra=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Aa(t))!Ma.call(e,r)&&r!==n&&Ot(e,r,{get:()=>t[r],enumerable:!(a=Sa(t,r))||a.enumerable});return e};var Ea=(e,t,n)=>(n=e!=null?Ia($a(e)):{},Ra(t||!e||!e.__esModule?Ot(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("tone"),b=require("react/jsx-runtime"),i=require("react"),S=require("styled-components"),Ee=require("@dnd-kit/core"),Da=require("@dnd-kit/modifiers");var Rt=typeof document<"u"?document.currentScript:null;function hn(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 pn=hn(W),G=hn(i);function Kt(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 Ba(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const s=r/a,o=t?r:e-1-r;n[o]=Math.exp(2*s-1)/Math.E}return n}function Ta(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 Wa(e,t,n=10){const a=new Float32Array(e);for(let r=0;r<e;r++){const s=t?r:e-1-r,o=r/e;a[s]=Math.log(1+n*o)/Math.log(1+n)}return a}function gn(e,t,n){switch(e){case"linear":return Kt(t,n);case"exponential":return Ba(t,n);case"sCurve":return Ta(t,n);case"logarithmic":return Wa(t,n);default:return Kt(t,n)}}function Ut(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 o=gn(a,1e4,!0),l=new Float32Array(o.length),c=s-r;for(let u=0;u<o.length;u++)l[u]=r+o[u]*c;e.setValueCurveAtTime(l,t,n)}}function Jt(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 o=gn(a,1e4,!1),l=new Float32Array(o.length),c=r-s;for(let u=0;u<o.length;u++)l[u]=s+o[u]*c;e.setValueCurveAtTime(l,t,n)}}var _a=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new W.Volume(this.gainToDb(e.track.gain)),this.panNode=new W.Panner(e.track.stereoPan),this.muteGain=new W.Gain(e.track.muted?0:1);const t=e.destination||W.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 W.Player({url:a.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new W.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=r.gain._param;s.cancelScheduledValues(0);const o=n-a.offset;if(a.fadeIn&&o<a.fadeIn.duration){const l=a.fadeIn.duration;if(o<=0)Ut(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-o,u=o/l,d=a.gain*u;Ut(s,t,c,a.fadeIn.type||"linear",d,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-o;if(c>0){const u=t+c;Jt(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,d=a.fadeOut.duration-u,v=u/a.fadeOut.duration,p=a.gain*(1-v);Jt(s,t,d,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,this.muteGain.gain.value=e?0:1}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 W.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,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??W.now();if(a.playStartTime=u,o>=l){const d=o-l+s.offset,v=s.duration-(o-l),p=n?Math.min(n,v):v;a.pausedPosition=d,this.scheduleFades(a,u,d),r.start(u,d,p)}else{const d=l-o,v=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+d,s.offset),r.start(u+d,s.offset,v)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(W.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??W.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}},Fa=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 W.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,W.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 W.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new _a(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??W.now(),r=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(r>=l){const c=r-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a,c,n)}else{const c=l-r;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a+c,0,n)}}),t!==void 0?W.getTransport().start(a,t):W.getTransport().start(a)}pause(){W.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){W.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 W.getTransport().seconds}seekTo(e){W.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return W.getContext()}get sampleRate(){return W.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},mt=null;function Za(){return mt||(mt=new W.Context,W.setContext(mt)),mt}async function Et(){const e=Za();e.state!=="running"&&await e.resume()}const Tt=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[Tt.Translate.toString(e),Tt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),Va=new Map([["bold",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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"}))]]),Pa=new Map([["bold",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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",G.createElement(G.Fragment,null,G.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"}))]]),za=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),Ft=G.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:v,weight:p="regular",mirrored:f=!1,...C}=G.useContext(za);return G.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??v,height:r??v,fill:a??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...C,...u},!!n&&G.createElement("title",null,n),l,c.get(s??p))});Ft.displayName="IconBase";const bn=G.forwardRef((e,t)=>G.createElement(Ft,{ref:t,...e,weights:Va}));bn.displayName="SpeakerHighIcon";const vn=G.forwardRef((e,t)=>G.createElement(Ft,{ref:t,...e,weights:Pa}));vn.displayName="SpeakerLowIcon";S.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 Zt=A.button`
7
+ `;var Zt=S.button`
8
8
  display: inline-flex;
9
9
  align-items: center;
10
10
  justify-content: center;
@@ -33,37 +33,37 @@
33
33
  opacity: 0.6;
34
34
  cursor: not-allowed;
35
35
  }
36
- `;A(Zt)`
36
+ `;S(Zt)`
37
37
  padding: 0.25rem 0.5rem;
38
38
  font-size: ${e=>e.theme.fontSizeSmall};
39
- `;A(Zt)`
39
+ `;S(Zt)`
40
40
  padding: 0.5rem;
41
41
  min-width: 2.25rem;
42
42
  min-height: 2.25rem;
43
- `;A(Zt)`
43
+ `;S(Zt)`
44
44
  padding: 0.25rem;
45
45
  min-width: 1.75rem;
46
46
  min-height: 1.75rem;
47
47
  font-size: ${e=>e.theme.fontSizeSmall};
48
- `;var vt=A.div`
48
+ `;var Ct=S.div`
49
49
  display: inline-flex;
50
50
  align-items: center;
51
51
  gap: 0.5rem;
52
- `,Ct=A.input`
52
+ `,xt=S.input`
53
53
  cursor: pointer;
54
54
  accent-color: ${e=>e.theme.inputFocusBorder};
55
55
 
56
56
  &:disabled {
57
57
  cursor: not-allowed;
58
58
  }
59
- `,xt=A.label`
59
+ `,wt=S.label`
60
60
  margin: 0;
61
61
  cursor: pointer;
62
62
  user-select: none;
63
63
  font-family: ${e=>e.theme.fontFamily};
64
64
  font-size: ${e=>e.theme.fontSize};
65
65
  color: ${e=>e.theme.textColor};
66
- `,Te=A.button`
66
+ `,Be=S.button`
67
67
  padding: 0.5rem 1rem;
68
68
  background: ${e=>e.theme.buttonBackground||"#007bff"};
69
69
  color: ${e=>e.theme.buttonText||"white"};
@@ -89,7 +89,7 @@
89
89
  cursor: not-allowed;
90
90
  opacity: 0.6;
91
91
  }
92
- `,Cn=A.input`
92
+ `,Cn=S.input`
93
93
  padding: 0.5rem 0.75rem;
94
94
  font-family: ${e=>e.theme.fontFamily};
95
95
  font-size: ${e=>e.theme.fontSize};
@@ -113,17 +113,17 @@
113
113
  opacity: 0.6;
114
114
  cursor: not-allowed;
115
115
  }
116
- `;A(Cn)`
116
+ `;S(Cn)`
117
117
  padding: 0.25rem 0.5rem;
118
118
  font-size: ${e=>e.theme.fontSizeSmall};
119
- `;var xn=A.label`
119
+ `;var xn=S.label`
120
120
  font-family: ${e=>e.theme.fontFamily};
121
121
  font-size: ${e=>e.theme.fontSizeSmall};
122
122
  font-weight: 500;
123
123
  color: ${e=>e.theme.textColorMuted};
124
124
  margin-bottom: 0.25rem;
125
125
  display: block;
126
- `;A.label`
126
+ `;S.label`
127
127
  font-family: ${e=>e.theme.fontFamily};
128
128
  font-size: ${e=>e.theme.fontSize};
129
129
  color: ${e=>e.theme.textColor};
@@ -131,7 +131,7 @@
131
131
  align-items: center;
132
132
  gap: 0.5rem;
133
133
  cursor: pointer;
134
- `;var jr=A.span`
134
+ `;var ja=S.span`
135
135
  position: absolute;
136
136
  width: 1px;
137
137
  height: 1px;
@@ -141,7 +141,7 @@
141
141
  clip: rect(0, 0, 0, 0);
142
142
  white-space: nowrap;
143
143
  border: 0;
144
- `,Vt=A.select`
144
+ `,Vt=S.select`
145
145
  padding: 0.5rem 2rem 0.5rem 0.75rem;
146
146
  font-family: ${e=>e.theme.fontFamily};
147
147
  font-size: ${e=>e.theme.fontSize};
@@ -172,10 +172,10 @@
172
172
  color: ${e=>e.theme.inputText};
173
173
  background-color: ${e=>e.theme.inputBackground};
174
174
  }
175
- `;A(Vt)`
175
+ `;S(Vt)`
176
176
  padding: 0.25rem 1.75rem 0.25rem 0.5rem;
177
177
  font-size: ${e=>e.theme.fontSizeSmall};
178
- `;var wn=A.input.attrs({type:"range"})`
178
+ `;var wn=S.input.attrs({type:"range"})`
179
179
  -webkit-appearance: none;
180
180
  appearance: none;
181
181
  width: 100%;
@@ -251,7 +251,7 @@
251
251
  &:disabled::-moz-range-thumb {
252
252
  cursor: not-allowed;
253
253
  }
254
- `,Hr=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return v.jsxs(vt,{className:r,children:[v.jsx(Ct,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:a,disabled:n}),v.jsx(xt,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function yn(e){return typeof e=="object"&&e!==null&&"type"in e}function Ke(e){if(!yn(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(r=>`${r.color} ${r.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var kn={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"},Xr=1e3;function Gr(e,t,n,r){if(!yn(t))return t;let a;t.direction==="vertical"?a=e.createLinearGradient(0,0,0,r):a=e.createLinearGradient(0,0,n,0);for(const s of t.stops)a.addColorStop(s.offset,s.color);return a}var Nr=A.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
254
+ `,Ha=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return b.jsxs(Ct,{className:a,children:[b.jsx(xt,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:r,disabled:n}),b.jsx(wt,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function yn(e){return typeof e=="object"&&e!==null&&"type"in e}function qe(e){if(!yn(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 kn={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"},Xa=1e3;function Ga(e,t,n,a){if(!yn(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 Na=S.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
255
255
  float: left;
256
256
  position: relative;
257
257
  /* Promote to own compositing layer for smoother scrolling */
@@ -259,13 +259,13 @@
259
259
  /* Disable image rendering interpolation */
260
260
  image-rendering: pixelated;
261
261
  image-rendering: crisp-edges;
262
- `,Lr=A.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
262
+ `,La=S.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
263
263
  position: absolute;
264
264
  background: ${e=>e.$waveFillColor};
265
265
  /* Force GPU compositing layer to reduce scroll flickering */
266
266
  transform: translateZ(0);
267
267
  backface-visibility: hidden;
268
- `,Yr=e=>{const{data:t,bits:n,length:r,index:a,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:x=0,transparentBackground:g=!1,drawMode:f="inverted"}=e,C=i.useRef([]),w=i.useCallback(y=>{if(y!==null){const k=parseInt(y.dataset.index,10);C.current[k]=y}},[]);i.useLayoutEffect(()=>{const y=C.current,k=d+x;let S=0;for(let $=0;$<y.length;$++){const E=y[$],R=E.getContext("2d"),M=Math.floor(l/2),B=2**(n-1);if(R){R.resetTransform(),R.clearRect(0,0,E.width,E.height),R.imageSmoothingEnabled=!1,R.scale(o,o);const D=E.width/o;let z;f==="normal"?z=u:z=c,R.fillStyle=Gr(R,z,D,l);const V=S,F=S+D,K=Math.floor((V-d+k)/k)*k;for(let H=Math.max(0,K);H<F;H+=k){const Z=H-V;if(Z+d<=0)continue;const L=H;if(L*2+1<t.length){const ae=t[L*2]/B,ne=t[L*2+1]/B,Q=Math.abs(ae*M),re=Math.abs(ne*M);f==="normal"?R.fillRect(Z,M-re,d,re+Q):(R.fillRect(Z,0,d,M-re),R.fillRect(Z,M+Q,d,M-Q))}}}S+=E.width/o}},[t,n,l,c,u,o,r,d,x,f]);let h=r,b=0;const I=[];for(;h>0;){const y=Math.min(h,Xr),k=v.jsx(Nr,{$cssWidth:y,width:y*o,height:l*o,$waveHeight:l,"data-index":b,ref:w},`${r}-${b}`);I.push(k),h-=y,b+=1}const m=g?"transparent":Ke(u);return v.jsx(Lr,{$index:a,$cssWidth:r,className:s,$waveHeight:l,$waveFillColor:m,children:I})},In=22,Sn=A.div`
268
+ `,Ya=e=>{const{data:t,bits:n,length:a,index:r,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:v=0,transparentBackground:p=!1,drawMode:f="inverted"}=e,C=i.useRef([]),y=i.useCallback(w=>{if(w!==null){const k=parseInt(w.dataset.index,10);C.current[k]=w}},[]);i.useLayoutEffect(()=>{const w=C.current,k=d+v;let A=0;for(let M=0;M<w.length;M++){const $=w[M],E=$.getContext("2d"),R=Math.floor(l/2),T=2**(n-1);if(E){E.resetTransform(),E.clearRect(0,0,$.width,$.height),E.imageSmoothingEnabled=!1,E.scale(o,o);const D=$.width/o;let P;f==="normal"?P=u:P=c,E.fillStyle=Ga(E,P,D,l);const V=A,F=A+D,N=Math.floor((V-d+k)/k)*k;for(let H=Math.max(0,N);H<F;H+=k){const Z=H-V;if(Z+d<=0)continue;const U=H;if(U*2+1<t.length){const re=t[U*2]/T,ne=t[U*2+1]/T,q=Math.abs(re*R),ae=Math.abs(ne*R);f==="normal"?E.fillRect(Z,R-ae,d,ae+q):(E.fillRect(Z,0,d,R-ae),E.fillRect(Z,R+q,d,R-q))}}}A+=$.width/o}},[t,n,l,c,u,o,a,d,v,f]);let m=a,g=0;const I=[];for(;m>0;){const w=Math.min(m,Xa),k=b.jsx(Na,{$cssWidth:w,width:w*o,height:l*o,$waveHeight:l,"data-index":g,ref:y},`${a}-${g}`);I.push(k),m-=w,g+=1}const h=p?"transparent":qe(u);return b.jsx(La,{$index:r,$cssWidth:a,className:s,$waveHeight:l,$waveFillColor:h,children:I})},In=22,Sn=S.div`
269
269
  position: relative;
270
270
  height: ${In}px;
271
271
  background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
@@ -289,7 +289,7 @@
289
289
  cursor: grabbing;
290
290
  }
291
291
  `}
292
- `,An=A.span`
292
+ `,An=S.span`
293
293
  font-size: 11px;
294
294
  font-weight: 600;
295
295
  font-family: ${e=>e.theme.clipHeaderFontFamily};
@@ -297,12 +297,12 @@
297
297
  white-space: nowrap;
298
298
  overflow: hidden;
299
299
  text-overflow: ellipsis;
300
- `,Or=({trackName:e,isSelected:t=!1})=>v.jsx(Sn,{$isDragging:!1,$interactive:!1,$isSelected:t,children:v.jsx(An,{children:e})}),Kr=({clipId:e,trackIndex:t,clipIndex:n,trackName:r,isSelected:a=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return v.jsx(Or,{trackName:r,isSelected:a});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return v.jsx(Sn,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:a,...c,...l,children:v.jsx(An,{children:r})})},Ur=8,Jr=24,qr=A.div`
300
+ `,Oa=({trackName:e,isSelected:t=!1})=>b.jsx(Sn,{$isDragging:!1,$interactive:!1,$isSelected:t,children:b.jsx(An,{children:e})}),Ka=({clipId:e,trackIndex:t,clipIndex:n,trackName:a,isSelected:r=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return b.jsx(Oa,{trackName:a,isSelected:r});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return b.jsx(Sn,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:r,...c,...l,children:b.jsx(An,{children:a})})},Ua=8,Ja=24,qa=S.div`
301
301
  position: absolute;
302
302
  ${e=>e.$edge==="left"?"left: 0;":"right: 0;"}
303
303
  top: 0;
304
304
  bottom: 0;
305
- width: ${e=>e.$touchOptimized?Jr:Ur}px;
305
+ width: ${e=>e.$touchOptimized?Ja:Ua}px;
306
306
  cursor: col-resize;
307
307
  user-select: none;
308
308
  z-index: 105; /* Above waveform, below header */
@@ -325,19 +325,19 @@
325
325
  background: rgba(255, 255, 255, 0.4);
326
326
  ${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
327
  }
328
- `,qt=({clipId:e,trackIndex:t,clipIndex:n,edge:r,dragHandleProps:a,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!a)return null;const{attributes:c,listeners:u,setActivatorNodeRef:d,isDragging:x}=a;return v.jsx(qr,{ref:d,"data-clip-id":e,"data-boundary-edge":r,$edge:r,$isDragging:x,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},Qr=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
328
+ `,qt=({clipId:e,trackIndex:t,clipIndex:n,edge:a,dragHandleProps:r,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!r)return null;const{attributes:c,listeners:u,setActivatorNodeRef:d,isDragging:v}=r;return b.jsx(qa,{ref:d,"data-clip-id":e,"data-boundary-edge":a,$edge:a,$isDragging:v,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},Qa=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
329
329
  position: absolute;
330
330
  top: 0;
331
331
  bottom: 0;
332
332
  pointer-events: none;
333
333
  z-index: 50;
334
- `,ea=A.svg`
334
+ `,er=S.svg`
335
335
  width: 100%;
336
336
  height: 100%;
337
337
  display: block;
338
338
  /* Flip horizontally for fadeOut - makes it mirror of fadeIn */
339
339
  transform: ${e=>e.$type==="fadeOut"?"scaleX(-1)":"none"};
340
- `;function ta(e,t,n="logarithmic"){const r=[],a=Math.max(20,Math.min(e,100));for(let s=0;s<=a;s++){const o=s/a*e,l=s/a;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;r.push(`${o},${u}`)}return`M 0,${t} L ${r.join(" L ")} L ${e},0 L 0,0 Z`}var Qt=({left:e,width:t,type:n,curveType:r="logarithmic",color:a})=>{const s=A.useTheme();if(t<1)return null;const o=a||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return v.jsx(Qr,{$left:e,$width:t,$type:n,children:v.jsx(ea,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:v.jsx("path",{d:ta(t,100,r),fill:o})})})},na=A.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
340
+ `;function tr(e,t,n="logarithmic"){const a=[],r=Math.max(20,Math.min(e,100));for(let s=0;s<=r;s++){const o=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(`${o},${u}`)}return`M 0,${t} L ${a.join(" L ")} L ${e},0 L 0,0 Z`}var Qt=({left:e,width:t,type:n,curveType:a="logarithmic",color:r})=>{const s=S.useTheme();if(t<1)return null;const o=r||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return b.jsx(Qa,{$left:e,$width:t,$type:n,children:b.jsx(er,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:b.jsx("path",{d:tr(t,100,a),fill:o})})})},nr=S.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
341
341
  position: ${e=>e.$isOverlay?"relative":"absolute"};
342
342
  top: 0;
343
343
  height: ${e=>e.$isOverlay?"auto":"100%"};
@@ -351,20 +351,20 @@
351
351
  &:hover {
352
352
  background: rgba(255, 255, 255, 0.08);
353
353
  }
354
- `,ra=A.div`
354
+ `,ar=S.div`
355
355
  flex: 1;
356
356
  position: relative;
357
357
  overflow: ${e=>e.$isOverlay?"visible":"hidden"};
358
- `,Wt=({children:e,className:t,clipId:n,trackIndex:r,clipIndex:a,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:d=!1,isOverlay:x=!1,isSelected:g=!1,onMouseDown:f,trackId:C,fadeIn:w,fadeOut:h,sampleRate:b=44100,showFades:I=!1,touchOptimized:p=!1})=>{const m=Math.floor(o/c),k=Math.floor((o+l)/c)-m,S=u&&!d&&!x,$=`clip-${r}-${a}`,{attributes:E,listeners:R,setNodeRef:M,setActivatorNodeRef:B,transform:D,isDragging:z}=De.useDraggable({id:$,data:{clipId:n,trackIndex:r,clipIndex:a},disabled:!S}),V=`clip-boundary-left-${r}-${a}`,{attributes:F,listeners:K,setActivatorNodeRef:H,isDragging:Z}=De.useDraggable({id:V,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"left"},disabled:!S}),L=`clip-boundary-right-${r}-${a}`,{attributes:ae,listeners:ne,setActivatorNodeRef:Q,isDragging:re}=De.useDraggable({id:L,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"right"},disabled:!S}),be=D?{transform:Tt.Translate.toString(D),zIndex:z?100:void 0}:void 0;return v.jsxs(na,{ref:M,style:be,className:t,$left:m,$width:k,$isOverlay:x,"data-clip-container":"true","data-track-id":C,onMouseDown:f,children:[u&&v.jsx(Kr,{clipId:n,trackIndex:r,clipIndex:a,trackName:s,isSelected:g,disableDrag:d,dragHandleProps:S?{attributes:E,listeners:R,setActivatorNodeRef:B}:void 0}),v.jsxs(ra,{$isOverlay:x,children:[e,I&&w&&w.duration>0&&v.jsx(Qt,{left:0,width:Math.floor(w.duration*b/c),type:"fadeIn",curveType:w.type}),I&&h&&h.duration>0&&v.jsx(Qt,{left:k-Math.floor(h.duration*b/c),width:Math.floor(h.duration*b/c),type:"fadeOut",curveType:h.type})]}),u&&!d&&!x&&v.jsxs(v.Fragment,{children:[v.jsx(qt,{clipId:n,trackIndex:r,clipIndex:a,edge:"left",touchOptimized:p,dragHandleProps:{attributes:F,listeners:K,setActivatorNodeRef:H,isDragging:Z}}),v.jsx(qt,{clipId:n,trackIndex:r,clipIndex:a,edge:"right",touchOptimized:p,dragHandleProps:{attributes:ae,listeners:ne,setActivatorNodeRef:Q,isDragging:re}})]})]})},aa=A.div`
358
+ `,Wt=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:d=!1,isOverlay:v=!1,isSelected:p=!1,onMouseDown:f,trackId:C,fadeIn:y,fadeOut:m,sampleRate:g=44100,showFades:I=!1,touchOptimized:x=!1})=>{const h=Math.floor(o/c),k=Math.floor((o+l)/c)-h,A=u&&!d&&!v,M=`clip-${a}-${r}`,{attributes:$,listeners:E,setNodeRef:R,setActivatorNodeRef:T,transform:D,isDragging:P}=Ee.useDraggable({id:M,data:{clipId:n,trackIndex:a,clipIndex:r},disabled:!A}),V=`clip-boundary-left-${a}-${r}`,{attributes:F,listeners:N,setActivatorNodeRef:H,isDragging:Z}=Ee.useDraggable({id:V,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"left"},disabled:!A}),U=`clip-boundary-right-${a}-${r}`,{attributes:re,listeners:ne,setActivatorNodeRef:q,isDragging:ae}=Ee.useDraggable({id:U,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"right"},disabled:!A}),be=D?{transform:Tt.Translate.toString(D),zIndex:P?100:void 0}:void 0;return b.jsxs(nr,{ref:R,style:be,className:t,$left:h,$width:k,$isOverlay:v,"data-clip-container":"true","data-track-id":C,onMouseDown:f,children:[u&&b.jsx(Ka,{clipId:n,trackIndex:a,clipIndex:r,trackName:s,isSelected:p,disableDrag:d,dragHandleProps:A?{attributes:$,listeners:E,setActivatorNodeRef:T}:void 0}),b.jsxs(ar,{$isOverlay:v,children:[e,I&&y&&y.duration>0&&b.jsx(Qt,{left:0,width:Math.floor(y.duration*g/c),type:"fadeIn",curveType:y.type}),I&&m&&m.duration>0&&b.jsx(Qt,{left:k-Math.floor(m.duration*g/c),width:Math.floor(m.duration*g/c),type:"fadeOut",curveType:m.type})]}),u&&!d&&!v&&b.jsxs(b.Fragment,{children:[b.jsx(qt,{clipId:n,trackIndex:a,clipIndex:r,edge:"left",touchOptimized:x,dragHandleProps:{attributes:F,listeners:N,setActivatorNodeRef:H,isDragging:Z}}),b.jsx(qt,{clipId:n,trackIndex:a,clipIndex:r,edge:"right",touchOptimized:x,dragHandleProps:{attributes:re,listeners:ne,setActivatorNodeRef:q,isDragging:ae}})]})]})},rr=S.div`
359
359
  display: inline-flex;
360
360
  align-items: center;
361
361
  gap: 0.5rem;
362
- `,oa=A(xn)`
362
+ `,or=S(xn)`
363
363
  margin: 0;
364
364
  white-space: nowrap;
365
- `,sa=A(wn)`
365
+ `,sr=S(wn)`
366
366
  width: 120px;
367
- `,ia=({volume:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(parseFloat(s.target.value)/100)};return v.jsxs(aa,{className:r,children:[v.jsx(oa,{htmlFor:"master-gain",children:"Master Volume"}),v.jsx(sa,{min:"0",max:"100",value:e*100,onChange:a,disabled:n,id:"master-gain"})]})};A.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
367
+ `,ir=({volume:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(parseFloat(s.target.value)/100)};return b.jsxs(rr,{className:a,children:[b.jsx(or,{htmlFor:"master-gain",children:"Master Volume"}),b.jsx(sr,{min:"0",max:"100",value:e*100,onChange:r,disabled:n,id:"master-gain"})]})};S.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
368
368
  position: absolute;
369
369
  top: 0;
370
370
  left: 0;
@@ -374,7 +374,7 @@
374
374
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
375
375
  pointer-events: none;
376
376
  will-change: transform;
377
- `;A.div`
377
+ `;S.div`
378
378
  position: absolute;
379
379
  top: 0;
380
380
  left: 0;
@@ -382,7 +382,7 @@
382
382
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
383
383
  pointer-events: none;
384
384
  will-change: transform;
385
- `;A.div`
385
+ `;S.div`
386
386
  position: absolute;
387
387
  top: -10px;
388
388
  left: -6px;
@@ -391,30 +391,30 @@
391
391
  border-left: 7px solid transparent;
392
392
  border-right: 7px solid transparent;
393
393
  border-top: 10px solid ${e=>e.$color};
394
- `;A.div`
394
+ `;S.div`
395
395
  position: absolute;
396
396
  top: 0;
397
397
  left: 0;
398
398
  width: 2px;
399
399
  height: 100%;
400
400
  background: ${e=>e.$color};
401
- `;var la=A.div`
401
+ `;var lr=S.div`
402
402
  overflow-y: hidden;
403
403
  overflow-x: auto;
404
404
  position: relative;
405
- `,ca=A.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
405
+ `,cr=S.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
406
406
  position: relative;
407
407
  background: ${e=>e.$backgroundColor||"transparent"};
408
- `,ua=A.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
408
+ `,ur=S.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
409
409
  background: ${e=>e.$backgroundColor||"white"};
410
410
  width: 100%;
411
411
  position: relative;
412
412
  overflow: hidden; /* Constrain loop region to timescale area */
413
- `,da=A.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
413
+ `,dr=S.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
414
414
  position: relative;
415
415
  background: ${e=>e.$backgroundColor||"transparent"};
416
416
  width: 100%;
417
- `,fa=A.div`
417
+ `,fr=S.div`
418
418
  position: absolute;
419
419
  top: 0;
420
420
  left: 0;
@@ -423,7 +423,7 @@
423
423
  cursor: crosshair;
424
424
  /* When selecting, raise z-index above clip boundaries (z-index: 105) to prevent interference */
425
425
  z-index: ${e=>e.$isSelecting?110:1};
426
- `,Pt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:r,timescaleWidth:a,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:d,onTracksMouseUp:x,scrollContainerRef:g,isSelecting:f})=>v.jsx(la,{"data-scroll-container":"true",ref:g,children:v.jsxs(ca,{$backgroundColor:t,$width:o,children:[r&&v.jsx(ua,{$width:a,$backgroundColor:n,children:r}),v.jsxs(da,{$width:s,$backgroundColor:t,children:[e,(c||u)&&v.jsx(fa,{$controlsWidth:l,$isSelecting:f,onClick:c,onMouseDown:u,onMouseMove:d,onMouseUp:x})]})]})});A.withTheme(Pt);var ma=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
426
+ `,Pt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:d,onTracksMouseUp:v,scrollContainerRef:p,isSelecting:f})=>b.jsx(lr,{"data-scroll-container":"true",ref:p,children:b.jsxs(cr,{$backgroundColor:t,$width:o,children:[a&&b.jsx(ur,{$width:r,$backgroundColor:n,children:a}),b.jsxs(dr,{$width:s,$backgroundColor:t,children:[e,(c||u)&&b.jsx(fr,{$controlsWidth:l,$isSelecting:f,onClick:c,onMouseDown:u,onMouseMove:d,onMouseUp:v})]})]})});S.withTheme(Pt);var mr=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
427
427
  position: absolute;
428
428
  top: 0;
429
429
  background: ${e=>e.$color};
@@ -431,14 +431,14 @@
431
431
  z-index: 60; /* Above clips (z-index: 10) and fades (z-index: 50), below playhead (z-index: 100) */
432
432
  pointer-events: none;
433
433
  opacity: 0.3;
434
- `,$n=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const r=Math.max(0,t-e);return r<=0?null:v.jsx(ma,{$left:e,$width:r,$color:n,"data-selection":!0})};A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
434
+ `,$n=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const a=Math.max(0,t-e);return a<=0?null:b.jsx(mr,{$left:e,$width:a,$color:n,"data-selection":!0})};S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
435
435
  position: absolute;
436
436
  top: 0;
437
437
  background: ${e=>e.$color};
438
438
  height: 100%;
439
439
  z-index: 55; /* Between clips (z-index: 50) and selection (z-index: 60) */
440
440
  pointer-events: none;
441
- `;A.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
441
+ `;S.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
442
442
  position: absolute;
443
443
  top: 0;
444
444
  width: 2px;
@@ -458,7 +458,7 @@
458
458
  border-top: 8px solid ${e=>e.$color};
459
459
  ${e=>e.$isStart?"border-right: 8px solid transparent;":"border-left: 8px solid transparent;"}
460
460
  }
461
- `;var en=A.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
461
+ `;var en=S.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
462
462
  position: absolute;
463
463
  top: 0;
464
464
  width: 12px;
@@ -495,7 +495,7 @@
495
495
  &:hover::before {
496
496
  opacity: 1;
497
497
  }
498
- `,ha=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
498
+ `,hr=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
499
499
  position: absolute;
500
500
  top: 0;
501
501
  height: 100%;
@@ -506,41 +506,41 @@
506
506
  &:active {
507
507
  cursor: grabbing;
508
508
  }
509
- `,pa=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopStartChange:a,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),x=i.useRef(0),g=i.useRef(0),f=i.useRef(0),C=Math.max(0,t-e),w=i.useCallback((b,I)=>{b.preventDefault(),b.stopPropagation(),d(I),x.current=b.clientX,g.current=I==="start"?e:t;const p=y=>{const k=y.clientX-x.current,S=g.current+k;if(I==="start"){const $=Math.max(l,Math.min(t-10,S));a?.($)}else{const $=Math.max(e+10,Math.min(c,S));s?.($)}},m=()=>{d(null),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",p),document.addEventListener("mouseup",m)},[e,t,l,c,a,s]),h=i.useCallback(b=>{b.preventDefault(),b.stopPropagation(),d("region"),x.current=b.clientX,g.current=e,f.current=t;const I=t-e,p=y=>{const k=y.clientX-x.current;let S=g.current+k,$=f.current+k;S<l&&(S=l,$=l+I),$>c&&($=c,S=c-I),o?.(S,$)},m=()=>{d(null),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",p),document.addEventListener("mouseup",m)},[e,t,l,c,o]);return C<=0?null:v.jsxs(v.Fragment,{children:[v.jsx(ha,{$left:e,$width:C,$color:r,$isDragging:u==="region",onMouseDown:h,"data-loop-region-timescale":!0}),v.jsx(en,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:b=>w(b,"start"),"data-loop-marker-handle":"start"}),v.jsx(en,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:b=>w(b,"end"),"data-loop-marker-handle":"end"})]})},ga=A.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
509
+ `,pr=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),v=i.useRef(0),p=i.useRef(0),f=i.useRef(0),C=Math.max(0,t-e),y=i.useCallback((g,I)=>{g.preventDefault(),g.stopPropagation(),d(I),v.current=g.clientX,p.current=I==="start"?e:t;const x=w=>{const k=w.clientX-v.current,A=p.current+k;if(I==="start"){const M=Math.max(l,Math.min(t-10,A));r?.(M)}else{const M=Math.max(e+10,Math.min(c,A));s?.(M)}},h=()=>{d(null),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",h)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",h)},[e,t,l,c,r,s]),m=i.useCallback(g=>{g.preventDefault(),g.stopPropagation(),d("region"),v.current=g.clientX,p.current=e,f.current=t;const I=t-e,x=w=>{const k=w.clientX-v.current;let A=p.current+k,M=f.current+k;A<l&&(A=l,M=l+I),M>c&&(M=c,A=c-I),o?.(A,M)},h=()=>{d(null),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",h)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",h)},[e,t,l,c,o]);return C<=0?null:b.jsxs(b.Fragment,{children:[b.jsx(hr,{$left:e,$width:C,$color:a,$isDragging:u==="region",onMouseDown:m,"data-loop-region-timescale":!0}),b.jsx(en,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:g=>y(g,"start"),"data-loop-marker-handle":"start"}),b.jsx(en,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:g=>y(g,"end"),"data-loop-marker-handle":"end"})]})},gr=S.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
510
510
  position: absolute;
511
511
  top: 0;
512
512
  right: 0;
513
513
  height: 100%; /* Stay within timescale bounds, don't extend into tracks */
514
514
  cursor: crosshair;
515
515
  z-index: 40; /* Below markers and shading */
516
- `,ba=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopRegionChange:a,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),x=i.useRef(null),g=t>e,f=i.useCallback(C=>{const w=C.target;if(w.closest("[data-loop-marker-handle]")||w.closest("[data-loop-region-timescale]"))return;C.preventDefault(),u(!0);const h=x.current?.getBoundingClientRect();if(!h)return;const b=C.clientX-h.left,I=Math.max(s,Math.min(o,b));d.current=I,a?.(I,I);const p=y=>{const k=y.clientX-h.left,S=Math.max(s,Math.min(o,k)),$=Math.min(d.current,S),E=Math.max(d.current,S);a?.($,E)},m=()=>{u(!1),document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",p),document.addEventListener("mouseup",m)},[s,o,a]);return v.jsx(ga,{ref:x,$leftOffset:l,onMouseDown:f,"data-timescale-loop-creator":!0,children:g&&v.jsx(pa,{startPosition:e,endPosition:t,markerColor:n,regionColor:r,minPosition:s,maxPosition:o,onLoopStartChange:C=>a?.(C,t),onLoopEndChange:C=>a?.(e,C),onLoopRegionMove:(C,w)=>a?.(C,w)})})};function rt(e,t){const n=Math.floor(e/3600)%24,r=Math.floor(e/60)%60,a=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(r).padStart(2,"0")+":"+a.padStart(t+3,"0")}function tt(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return rt(e,0);case"hh:mm:ss.u":return rt(e,1);case"hh:mm:ss.uu":return rt(e,2);case"hh:mm:ss.uuu":return rt(e,3);default:return rt(e,3)}}function Mn(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const r=parseInt(n[0],10)||0,a=parseInt(n[1],10)||0,s=parseFloat(n[2])||0;return r*3600+a*60+s}default:return 0}}var tn=({id:e,label:t,value:n,format:r,className:a,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const g=tt(n,r);c(g)},[n,r,e]);const u=g=>{const f=g.target.value;c(f)},d=()=>{if(s){const g=Mn(l,r);s(g)}c(tt(n,r))},x=g=>{g.key==="Enter"&&g.currentTarget.blur()};return v.jsxs(v.Fragment,{children:[v.jsx(jr,{as:"label",htmlFor:e,children:t}),v.jsx(Cn,{type:"text",className:a,id:e,value:l,onChange:u,onBlur:d,onKeyDown:x,readOnly:o})]})},va=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:r})=>{const[a,s]=i.useState("hh:mm:ss.uuu");i.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 o=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return v.jsxs(v.Fragment,{children:[v.jsx(tn,{id:"audio_start",label:"Start of audio selection",value:e,format:a,className:"audio-start form-control mr-sm-2",onChange:o}),v.jsx(tn,{id:"audio_end",label:"End of audio selection",value:t,format:a,className:"audio-end form-control mr-sm-2",onChange:l})]})};function pt(){return window.devicePixelRatio}var Rn=i.createContext(pt()),En=({children:e})=>{const[t,n]=i.useState(pt());return matchMedia(`(resolution: ${pt()}dppx)`).addEventListener("change",()=>{n(pt())},{once:!0}),v.jsx(Rn.Provider,{value:Math.ceil(t),children:e})},Dn=()=>i.useContext(Rn),wt=i.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}),st=()=>i.useContext(wt),it=()=>i.useContext(A.ThemeContext),zt=i.createContext(v.jsx(i.Fragment,{})),Ca=()=>i.useContext(zt),xa=0,wa=!1,ya=0,ka=0,Ia={progress:xa,isPlaying:wa,selectionStart:ya,selectionEnd:ka};i.createContext(Ia);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var Bn=({isSelected:e,transparentBackground:t,...n})=>{const r=it(),{waveHeight:a,barWidth:s,barGap:o}=st(),l=Dn(),c=e&&r?r.selectedWaveOutlineColor:r?.waveOutlineColor,u=e&&r?r.selectedWaveFillColor:r?.waveFillColor,d=r?.waveformDrawMode||"inverted";return v.jsx(Yr,{...n,...r,waveOutlineColor:c,waveFillColor:u,waveHeight:a,devicePixelRatio:l,barWidth:s,barGap:o,transparentBackground:t,drawMode:d})};function Sa(e,t,n){return Math.ceil(e*n/t)}function Aa(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var $a=A.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
516
+ `,br=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),v=i.useRef(null),p=t>e,f=i.useCallback(C=>{const y=C.target;if(y.closest("[data-loop-marker-handle]")||y.closest("[data-loop-region-timescale]"))return;C.preventDefault(),u(!0);const m=v.current?.getBoundingClientRect();if(!m)return;const g=C.clientX-m.left,I=Math.max(s,Math.min(o,g));d.current=I,r?.(I,I);const x=w=>{const k=w.clientX-m.left,A=Math.max(s,Math.min(o,k)),M=Math.min(d.current,A),$=Math.max(d.current,A);r?.(M,$)},h=()=>{u(!1),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",h)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",h)},[s,o,r]);return b.jsx(gr,{ref:v,$leftOffset:l,onMouseDown:f,"data-timescale-loop-creator":!0,children:p&&b.jsx(pr,{startPosition:e,endPosition:t,markerColor:n,regionColor:a,minPosition:s,maxPosition:o,onLoopStartChange:C=>r?.(C,t),onLoopEndChange:C=>r?.(e,C),onLoopRegionMove:(C,y)=>r?.(C,y)})})};function at(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 tt(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return at(e,0);case"hh:mm:ss.u":return at(e,1);case"hh:mm:ss.uu":return at(e,2);case"hh:mm:ss.uuu":return at(e,3);default:return at(e,3)}}function Mn(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 tn=({id:e,label:t,value:n,format:a,className:r,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const p=tt(n,a);c(p)},[n,a,e]);const u=p=>{const f=p.target.value;c(f)},d=()=>{if(s){const p=Mn(l,a);s(p)}c(tt(n,a))},v=p=>{p.key==="Enter"&&p.currentTarget.blur()};return b.jsxs(b.Fragment,{children:[b.jsx(ja,{as:"label",htmlFor:e,children:t}),b.jsx(Cn,{type:"text",className:r,id:e,value:l,onChange:u,onBlur:d,onKeyDown:v,readOnly:o})]})},vr=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:a})=>{const[r,s]=i.useState("hh:mm:ss.uuu");i.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 o=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return b.jsxs(b.Fragment,{children:[b.jsx(tn,{id:"audio_start",label:"Start of audio selection",value:e,format:r,className:"audio-start form-control mr-sm-2",onChange:o}),b.jsx(tn,{id:"audio_end",label:"End of audio selection",value:t,format:r,className:"audio-end form-control mr-sm-2",onChange:l})]})};function gt(){return window.devicePixelRatio}var Rn=i.createContext(gt()),En=({children:e})=>{const[t,n]=i.useState(gt());return matchMedia(`(resolution: ${gt()}dppx)`).addEventListener("change",()=>{n(gt())},{once:!0}),b.jsx(Rn.Provider,{value:Math.ceil(t),children:e})},Dn=()=>i.useContext(Rn),yt=i.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}),st=()=>i.useContext(yt),it=()=>i.useContext(S.ThemeContext),zt=i.createContext(b.jsx(i.Fragment,{})),Cr=()=>i.useContext(zt),xr=0,wr=!1,yr=0,kr=0,Ir={progress:xr,isPlaying:wr,selectionStart:yr,selectionEnd:kr};i.createContext(Ir);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var Bn=({isSelected:e,transparentBackground:t,...n})=>{const a=it(),{waveHeight:r,barWidth:s,barGap:o}=st(),l=Dn(),c=e&&a?a.selectedWaveOutlineColor:a?.waveOutlineColor,u=e&&a?a.selectedWaveFillColor:a?.waveFillColor,d=a?.waveformDrawMode||"inverted";return b.jsx(Ya,{...n,...a,waveOutlineColor:c,waveFillColor:u,waveHeight:r,devicePixelRatio:l,barWidth:s,barGap:o,transparentBackground:t,drawMode:d})};function Sr(e,t,n){return Math.ceil(e*n/t)}function Ar(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var $r=S.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
517
517
  position: relative;
518
518
  overflow: visible; /* Allow time labels to render above the container */
519
519
  border-bottom: 1px solid ${e=>e.theme.timeColor};
520
520
  box-sizing: border-box;
521
- `,Ma=A.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
521
+ `,Mr=S.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
522
522
  position: absolute;
523
523
  left: 0;
524
524
  right: 0;
525
525
  bottom: 0;
526
- `,Ra=A.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
526
+ `,Rr=S.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
527
527
  position: absolute;
528
528
  font-size: 0.75rem; /* Smaller font to prevent overflow */
529
529
  white-space: nowrap; /* Prevent text wrapping */
530
530
  color: ${e=>e.theme.timeColor}; /* Use theme color instead of inheriting */
531
- `,Ea=e=>{const{theme:{timeColor:t},duration:n,marker:r,bigStep:a,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:d,samplesPerPixel:x,timeScaleHeight:g,controls:{show:f,width:C}}=i.useContext(wt),w=Dn();i.useEffect(()=>{if(u.current!==null){const p=u.current,m=p.getContext("2d");if(m){m.resetTransform(),m.clearRect(0,0,p.width,p.height),m.imageSmoothingEnabled=!1,m.fillStyle=t,m.scale(w,w);for(const[y,k]of l.entries()){const S=g-k;m.fillRect(y,S,1,k)}}}},[n,w,t,g,a,s,r,l]);const h=Sa(n/1e3,x,d),b=d/x;let I=0;for(let p=0;p<h;p+=b*s/1e3){const m=Math.floor(p);if(I%r===0){const y=I,k=Aa(y),S=o?v.jsx(i.Fragment,{children:o(y,m)},`timestamp-${I}`):v.jsx(Ra,{$left:m,children:k},k);c.push(S),l.set(m,g)}else I%a===0?l.set(m,Math.floor(g/2)):I%s===0&&l.set(m,Math.floor(g/5));I+=s}return v.jsxs($a,{$cssWidth:h,$controlWidth:f?C:0,$timeScaleHeight:g,children:[c,v.jsx(Ma,{$cssWidth:h,$timeScaleHeight:g,width:h*w,height:g*w,ref:u})]})},Tn=A.withTheme(Ea),Da=A.div`
531
+ `,Er=e=>{const{theme:{timeColor:t},duration:n,marker:a,bigStep:r,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:d,samplesPerPixel:v,timeScaleHeight:p,controls:{show:f,width:C}}=i.useContext(yt),y=Dn();i.useEffect(()=>{if(u.current!==null){const x=u.current,h=x.getContext("2d");if(h){h.resetTransform(),h.clearRect(0,0,x.width,x.height),h.imageSmoothingEnabled=!1,h.fillStyle=t,h.scale(y,y);for(const[w,k]of l.entries()){const A=p-k;h.fillRect(w,A,1,k)}}}},[n,y,t,p,r,s,a,l]);const m=Sr(n/1e3,v,d),g=d/v;let I=0;for(let x=0;x<m;x+=g*s/1e3){const h=Math.floor(x);if(I%a===0){const w=I,k=Ar(w),A=o?b.jsx(i.Fragment,{children:o(w,h)},`timestamp-${I}`):b.jsx(Rr,{$left:h,children:k},k);c.push(A),l.set(h,p)}else I%r===0?l.set(h,Math.floor(p/2)):I%s===0&&l.set(h,Math.floor(p/5));I+=s}return b.jsxs($r,{$cssWidth:m,$controlWidth:f?C:0,$timeScaleHeight:p,children:[c,b.jsx(Mr,{$cssWidth:m,$timeScaleHeight:p,width:m*y,height:p*y,ref:u})]})},Tn=S.withTheme(Er),Dr=S.div`
532
532
  display: inline-flex;
533
533
  align-items: center;
534
534
  gap: 0.5rem;
535
- `,Ba=[{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"}],Ta=({value:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.value)};return v.jsx(Da,{className:r,children:v.jsx(Vt,{className:"time-format",value:e,onChange:a,disabled:n,"aria-label":"Time format selection",children:Ba.map(s=>v.jsx("option",{value:s.value,children:s.label},s.value))})})},Wa=A.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?In:0)}px`}}))`
535
+ `,Br=[{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"}],Tr=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return b.jsx(Dr,{className:a,children:b.jsx(Vt,{className:"time-format",value:e,onChange:r,disabled:n,"aria-label":"Time format selection",children:Br.map(s=>b.jsx("option",{value:s.value,children:s.label},s.value))})})},Wr=S.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?In:0)}px`}}))`
536
536
  position: relative;
537
537
  display: flex;
538
538
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
539
- `,_a=A.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
539
+ `,_r=S.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
540
540
  position: relative;
541
541
  background: ${e=>e.$backgroundColor||"transparent"};
542
542
  flex: 1;
543
- `,Fa=A.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
543
+ `,Fr=S.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
544
544
  position: sticky;
545
545
  z-index: 101; /* Above waveform content, below Docusaurus navbar (z-index: 200) */
546
546
  left: 0;
@@ -554,7 +554,7 @@
554
554
  ${e=>e.$isSelected&&`
555
555
  background: ${e.theme.selectedTrackControlsBackground};
556
556
  `}
557
- `,Wn=({numChannels:e,children:t,className:n,backgroundColor:r,offset:a=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:d,controls:{show:x,width:g}}=st(),f=Ca();return v.jsxs(Wa,{$numChannels:e,className:n,$waveHeight:d,$controlWidth:x?g:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[v.jsx(Fa,{$controlWidth:x?g:0,$isSelected:u,children:f}),v.jsx(_a,{$controlWidth:x?g:0,$backgroundColor:r,$offset:a,onClick:l,"data-track-id":c,children:t})]})},nn=A.button.attrs({type:"button"})`
557
+ `,Wn=({numChannels:e,children:t,className:n,backgroundColor:a,offset:r=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:d,controls:{show:v,width:p}}=st(),f=Cr();return b.jsxs(Wr,{$numChannels:e,className:n,$waveHeight:d,$controlWidth:v?p:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[b.jsx(Fr,{$controlWidth:v?p:0,$isSelected:u,children:f}),b.jsx(_r,{$controlWidth:v?p:0,$backgroundColor:a,$offset:r,onClick:l,"data-track-id":c,children:t})]})},nn=S.button.attrs({type:"button"})`
558
558
  display: inline-block;
559
559
  font-family: ${e=>e.theme.fontFamily};
560
560
  font-weight: 500;
@@ -613,7 +613,7 @@
613
613
  box-shadow: 0 0 0 0.2rem ${e.theme.inputFocusBorder}33;
614
614
  }
615
615
  `}
616
- `,Za=A.div`
616
+ `,Zr=S.div`
617
617
  margin-bottom: 0.3rem;
618
618
 
619
619
  button:not(:first-child) {
@@ -625,7 +625,7 @@
625
625
  border-top-right-radius: 0;
626
626
  border-bottom-right-radius: 0;
627
627
  }
628
- `,Va=A.div`
628
+ `,Vr=S.div`
629
629
  background: transparent;
630
630
  width: 100%;
631
631
  height: 100%;
@@ -638,7 +638,7 @@
638
638
  text-align: center;
639
639
  border: 1px solid ${e=>e.theme.borderColor};
640
640
  border-radius: ${e=>e.theme.borderRadius};
641
- `,Pa=A.header`
641
+ `,Pr=S.header`
642
642
  overflow: hidden;
643
643
  height: 26px;
644
644
  width: 100%;
@@ -649,7 +649,7 @@
649
649
  font-size: ${e=>e.theme.fontSizeSmall};
650
650
  color: ${e=>e.theme.textColor};
651
651
  background-color: transparent;
652
- `,za=e=>v.jsx(vn,{weight:"light",...e}),ja=e=>v.jsx(bn,{weight:"light",...e}),rn=A(wn)`
652
+ `,zr=e=>b.jsx(vn,{weight:"light",...e}),jr=e=>b.jsx(bn,{weight:"light",...e}),an=S(wn)`
653
653
  width: 75%;
654
654
  height: 5px;
655
655
  background: ${e=>e.theme.sliderTrackColor};
@@ -698,7 +698,7 @@
698
698
  &:focus::-moz-range-thumb {
699
699
  border: 2px solid ${e=>e.theme.textColor};
700
700
  }
701
- `,an=A.label`
701
+ `,rn=S.label`
702
702
  width: 100%;
703
703
  display: flex;
704
704
  justify-content: space-between;
@@ -706,12 +706,12 @@
706
706
  padding: 0 1rem;
707
707
  margin-bottom: 0.2rem;
708
708
  font-size: 14px;
709
- `;A.div`
709
+ `;S.div`
710
710
  display: flex;
711
711
  align-items: center;
712
712
  gap: 0.25rem;
713
713
  padding: 0.5rem 0.5rem 0.25rem 0.5rem;
714
- `;A.span`
714
+ `;S.span`
715
715
  flex: 1;
716
716
  font-weight: 600;
717
717
  font-size: 0.875rem;
@@ -719,7 +719,7 @@
719
719
  text-overflow: ellipsis;
720
720
  white-space: nowrap;
721
721
  margin: 0 0.25rem;
722
- `;A.button`
722
+ `;S.button`
723
723
  display: flex;
724
724
  align-items: center;
725
725
  justify-content: center;
@@ -744,8 +744,8 @@
744
744
  &:active {
745
745
  transform: scale(0.9);
746
746
  }
747
- `;function Ha(e){let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){const a=e[r];t>a&&(t=a),n<a&&(n=a)}return{min:t,max:n}}function on(e,t){const n=Math.pow(2,t-1),r=e<0?e*n:e*(n-1);return Math.max(-n,Math.min(n-1,r))}function _n(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function sn(e,t,n){const r=e.length,a=Math.ceil(r/t),s=_n(n,a*2);for(let o=0;o<a;o++){const l=o*t,c=Math.min((o+1)*t,r),u=e.subarray(l,c),d=Ha(u),x=on(d.min,n),g=on(d.max,n);s[o*2]=x,s[o*2+1]=g}return s}function Xa(e,t){const n=e.length,r=1/n,a=e[0].length/2,s=_n(t,a*2);for(let o=0;o<a;o++){let l=0,c=0;for(let u=0;u<n;u++)l+=r*e[u][o*2],c+=r*e[u][o*2+1];s[o*2]=l,s[o*2+1]=c}return[s]}function Ga(e,t=1e3,n=!0,r=0,a,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=a??e.length;for(let d=0;d<c;d++){const g=e.getChannelData(d).subarray(r,u);o.push(sn(g,t,s))}}else{const c=a??e.length,u=e.subarray(r,c);o.push(sn(u,t,s))}return n&&o.length>1&&(o=Xa(o,s)),{length:o[0].length/2,data:o,bits:s}}function Na(e,t=1e3,n=!0,r=8,a=0,s){const o=s!==void 0?a+s:void 0;return Ga(e,t,n,a,o,r)}function Ue(e,t){this._waveformData=e,this._channelIndex=t}Ue.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};Ue.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};Ue.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};Ue.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};Ue.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};Ue.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 La=127,Ya=-128,Oa=32767,Ka=-32768;function Ua(e,t){var n=Math.floor(e/t),r=e-n*t;return r>0&&n++,n}function Ja(e){for(var t=e.scale,n=e.amplitude_scale,r=e.split_channels,a=e.length,s=e.sample_rate,o=e.channels.map(function(M){return new Float32Array(M)}),l=r?o.length:1,c=24,u=Ua(a,t),d=e.bits===8?1:2,x=c+u*2*d*l,g=new ArrayBuffer(x),f=new DataView(g),C=0,w=c,h=new Array(l),b=new Array(l),I=0;I<l;I++)h[I]=1/0,b[I]=-1/0;var p=e.bits===8?Ya:Ka,m=e.bits===8?La:Oa;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 y=0;y<a;y++){var k=0;if(l===1){for(var S=0;S<o.length;++S)k+=o[S][y];k=Math.floor(m*k*n/o.length),k<h[0]&&(h[0]=k,h[0]<p&&(h[0]=p)),k>b[0]&&(b[0]=k,b[0]>m&&(b[0]=m))}else for(var $=0;$<l;++$)k=Math.floor(m*o[$][y]*n),k<h[$]&&(h[$]=k,h[$]<p&&(h[$]=p)),k>b[$]&&(b[$]=k,b[$]>m&&(b[$]=m));if(++C===t){for(var E=0;E<l;E++)e.bits===8?(f.setInt8(w++,h[E]),f.setInt8(w++,b[E])):(f.setInt16(w,h[E],!0),f.setInt16(w+2,b[E],!0),w+=4),h[E]=1/0,b[E]=-1/0;C=0}}if(C>0)for(var R=0;R<l;R++)e.bits===8?(f.setInt8(w++,h[R]),f.setInt8(w++,b[R])):(f.setInt16(w,h[R],!0),f.setInt16(w+2,b[R],!0));return g}function gt(e){"@babel/helpers - typeof";return gt=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},gt(e)}function qa(e){return e&&gt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Qa(e){var t=e&&gt(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),r=n.getInt32(0,!0);if(r!==1&&r!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function eo(e){var t=e.data,n=e.channels||1,r=24,a=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 o=r+t.length*a,l=new ArrayBuffer(o),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=r;if(e.bits===8)for(var d=0;d<t.length;d++)c.setInt8(u++,t[d],!0);else for(var x=0;x<t.length;x++)c.setInt16(u,t[x],!0),u+=2;return l}function et(e){return e==null}function to(e,t){var n=atob(e);return n}function no(e,t,n){var r=to(e),a=r.indexOf(`
748
- `,10)+1,s=r.substring(a)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function ro(e,t,n){var r;return function(s){return r=r||no(e),new Worker(r,s)}}var ao=ro("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function Be(e){if(qa(e)&&(e=eo(e)),Qa(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 Ue(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var at={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function oo(e){var t={scale:e.scale||at.scale,bits:e.bits||at.bits,amplitude_scale:e.amplitude_scale||at.amplitude_scale,split_channels:e.split_channels||at.split_channels,disable_worker:e.disable_worker||at.disable_worker};return t}function so(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Fn(e,t,n){var r=so(e);if(t.disable_worker){var a=Ja({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r});n(void 0,new Be(a),e)}else{var s=new ao;s.onmessage=function(o){n(void 0,new Be(o.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:r},r)}}function io(e,t,n,r){function a(o){o||(o=new DOMException("EncodingError")),r(o),r=function(){}}var s=e.decodeAudioData(t,function(o){Fn(o,n,r)},a);s&&s.catch(a)}Be.create=function(t){return new Be(t)};Be.createFromAudio=function(e,t){var n=oo(e);if(e.audio_context&&e.array_buffer)return io(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Fn(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function yt(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),r=24,a=this._inputData.bits===8?1:2,s=r+n*2*this._inputData.channels*a;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 Be(this._output_data),this._input_index=0,this._output_index=0;var o=this._inputData.channels;this._min=new Array(o),this._max=new Array(o);for(var l=0;l<o;++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}yt.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};yt.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,r;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var a=0;a<n;++a)r=this._outputWaveformData.channel(a),r.set_min_sample(this._output_index-1,this._min[a]),r.set_max_sample(this._output_index-1,this._max[a]);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 o=0;o<n;++o){r=this._inputData.channel(o);var l=r.min_sample(this._input_index);l<this._min[o]&&(this._min[o]=l),l=r.max_sample(this._input_index),l>this._max[o]&&(this._max[o]=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)r=this._outputWaveformData.channel(c),r.set_min_sample(this._output_index-1,this._min[c]),r.set_max_sample(this._output_index-1,this._max[c]);return!0};yt.prototype.getOutputData=function(){return this._output_data};Be.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!et(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!et(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 yt(t);!n.next(););return new Be(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(a){if(t.channels!==a.channels||t.sample_rate!==a.sample_rate||t.bits!==a.bits||t.scale!==a.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var r=this._concatBuffers.apply(this,n);return Be.create(r)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,r=n,a=0,s=[this].concat(t).map(function(b){return b._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);r+=l.byteLength-n,a+=c}for(var u=new ArrayBuffer(r),d=new DataView(s[0]),x=new DataView(u),g=0;g<n;g++)x.setUint8(g,d.getUint8(g));x.setInt32(16,a,!0);for(var f=0,C=new Uint8Array(u,n),w=0;w<s.length;w++){var h=s[w];C.set(new Uint8Array(h,n),f),f+=h.byteLength-n}return u},slice:function(t){var n=0,r=0;if(!et(t.startIndex)&&!et(t.endIndex)?(n=t.startIndex,r=t.endIndex):!et(t.startTime)&&!et(t.endTime)&&(n=this.at_time(t.startTime),r=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(r<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),r>this.length&&(r=this.length),n>r&&(n=r);var a=r-n,s=24,o=this.bits===8?1:2,l=s+a*2*this.channels*o,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,a,!0),u.setInt32(20,this.channels,!0);for(var d=0;d<a*this.channels*2;d++){var x=this._at(n*this.channels*2+d);this.bits===8?u.setInt8(s+d,x):u.setInt16(s+d*2,x,!0)}return new Be(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 r=0;r<this.channels;r++)t.data.push(this.channel(r).min_sample(n)),t.data.push(this.channel(r).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function jt(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const r=await t.arrayBuffer();return Be.create(r)}else{const r=await t.json();return Be.create(r)}}function Zn(e,t=0){const n=e.channel(t),r=e.bits,a=n.min_array(),s=n.max_array(),o=a.length,l=r===8?new Int8Array(o*2):new Int16Array(o*2);for(let c=0;c<o;c++)l[c*2]=a[c],l[c*2+1]=s[c];return{data:l,bits:r,length:o,sampleRate:e.sample_rate}}async function lo(e,t=0){const n=await jt(e);return Zn(n,t)}async function co(e){const t=await jt(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Vn(e,t,n=0,r,a){let s=e;if(r!==void 0&&a!==void 0){const g=e.scale,f=Math.floor(r/g),C=Math.ceil((r+a)/g);s=s.slice({startIndex:f,endIndex:C})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),d=c.length,x=l===8?new Int8Array(d*2):new Int16Array(d*2);for(let g=0;g<d;g++)x[g*2]=c[g],x[g*2+1]=u[g];return{data:x,bits:l,length:d}}function Pn(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function uo(e){return{id:e.id,begin:e.start.toFixed(3),end:e.end.toFixed(3),lines:e.lines,language:e.lang||"en"}}A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
747
+ `;function Hr(e){let t=1/0,n=-1/0;for(let a=0;a<e.length;a++){const r=e[a];t>r&&(t=r),n<r&&(n=r)}return{min:t,max:n}}function on(e,t){const n=Math.pow(2,t-1),a=e<0?e*n:e*(n-1);return Math.max(-n,Math.min(n-1,a))}function _n(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function sn(e,t,n){const a=e.length,r=Math.ceil(a/t),s=_n(n,r*2);for(let o=0;o<r;o++){const l=o*t,c=Math.min((o+1)*t,a),u=e.subarray(l,c),d=Hr(u),v=on(d.min,n),p=on(d.max,n);s[o*2]=v,s[o*2+1]=p}return s}function Xr(e,t){const n=e.length,a=1/n,r=e[0].length/2,s=_n(t,r*2);for(let o=0;o<r;o++){let l=0,c=0;for(let u=0;u<n;u++)l+=a*e[u][o*2],c+=a*e[u][o*2+1];s[o*2]=l,s[o*2+1]=c}return[s]}function Gr(e,t=1e3,n=!0,a=0,r,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=r??e.length;for(let d=0;d<c;d++){const p=e.getChannelData(d).subarray(a,u);o.push(sn(p,t,s))}}else{const c=r??e.length,u=e.subarray(a,c);o.push(sn(u,t,s))}return n&&o.length>1&&(o=Xr(o,s)),{length:o[0].length/2,data:o,bits:s}}function Nr(e,t=1e3,n=!0,a=8,r=0,s){const o=s!==void 0?r+s:void 0;return Gr(e,t,n,r,o,a)}function Qe(e,t){this._waveformData=e,this._channelIndex=t}Qe.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};Qe.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};Qe.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};Qe.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};Qe.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};Qe.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 Lr=127,Yr=-128,Or=32767,Kr=-32768;function Ur(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function Jr(e){for(var t=e.scale,n=e.amplitude_scale,a=e.split_channels,r=e.length,s=e.sample_rate,o=e.channels.map(function(R){return new Float32Array(R)}),l=a?o.length:1,c=24,u=Ur(r,t),d=e.bits===8?1:2,v=c+u*2*d*l,p=new ArrayBuffer(v),f=new DataView(p),C=0,y=c,m=new Array(l),g=new Array(l),I=0;I<l;I++)m[I]=1/0,g[I]=-1/0;var x=e.bits===8?Yr:Kr,h=e.bits===8?Lr:Or;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 w=0;w<r;w++){var k=0;if(l===1){for(var A=0;A<o.length;++A)k+=o[A][w];k=Math.floor(h*k*n/o.length),k<m[0]&&(m[0]=k,m[0]<x&&(m[0]=x)),k>g[0]&&(g[0]=k,g[0]>h&&(g[0]=h))}else for(var M=0;M<l;++M)k=Math.floor(h*o[M][w]*n),k<m[M]&&(m[M]=k,m[M]<x&&(m[M]=x)),k>g[M]&&(g[M]=k,g[M]>h&&(g[M]=h));if(++C===t){for(var $=0;$<l;$++)e.bits===8?(f.setInt8(y++,m[$]),f.setInt8(y++,g[$])):(f.setInt16(y,m[$],!0),f.setInt16(y+2,g[$],!0),y+=4),m[$]=1/0,g[$]=-1/0;C=0}}if(C>0)for(var E=0;E<l;E++)e.bits===8?(f.setInt8(y++,m[E]),f.setInt8(y++,g[E])):(f.setInt16(y,m[E],!0),f.setInt16(y+2,g[E],!0));return p}function bt(e){"@babel/helpers - typeof";return bt=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},bt(e)}function qr(e){return e&&bt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Qr(e){var t=e&&bt(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 eo(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 o=a+t.length*r,l=new ArrayBuffer(o),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 d=0;d<t.length;d++)c.setInt8(u++,t[d],!0);else for(var v=0;v<t.length;v++)c.setInt16(u,t[v],!0),u+=2;return l}function et(e){return e==null}function to(e,t){var n=atob(e);return n}function no(e,t,n){var a=to(e),r=a.indexOf(`
748
+ `,10)+1,s=a.substring(r)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function ao(e,t,n){var a;return function(s){return a=a||no(e),new Worker(a,s)}}var ro=ao("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function De(e){if(qr(e)&&(e=eo(e)),Qr(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 Qe(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var rt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function oo(e){var t={scale:e.scale||rt.scale,bits:e.bits||rt.bits,amplitude_scale:e.amplitude_scale||rt.amplitude_scale,split_channels:e.split_channels||rt.split_channels,disable_worker:e.disable_worker||rt.disable_worker};return t}function so(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Fn(e,t,n){var a=so(e);if(t.disable_worker){var r=Jr({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 De(r),e)}else{var s=new ro;s.onmessage=function(o){n(void 0,new De(o.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 io(e,t,n,a){function r(o){o||(o=new DOMException("EncodingError")),a(o),a=function(){}}var s=e.decodeAudioData(t,function(o){Fn(o,n,a)},r);s&&s.catch(r)}De.create=function(t){return new De(t)};De.createFromAudio=function(e,t){var n=oo(e);if(e.audio_context&&e.array_buffer)return io(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Fn(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function kt(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 De(this._output_data),this._input_index=0,this._output_index=0;var o=this._inputData.channels;this._min=new Array(o),this._max=new Array(o);for(var l=0;l<o;++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}kt.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};kt.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 o=0;o<n;++o){a=this._inputData.channel(o);var l=a.min_sample(this._input_index);l<this._min[o]&&(this._min[o]=l),l=a.max_sample(this._input_index),l>this._max[o]&&(this._max[o]=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};kt.prototype.getOutputData=function(){return this._output_data};De.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!et(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!et(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 kt(t);!n.next(););return new De(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 De.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(g){return g._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),d=new DataView(s[0]),v=new DataView(u),p=0;p<n;p++)v.setUint8(p,d.getUint8(p));v.setInt32(16,r,!0);for(var f=0,C=new Uint8Array(u,n),y=0;y<s.length;y++){var m=s[y];C.set(new Uint8Array(m,n),f),f+=m.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!et(t.startIndex)&&!et(t.endIndex)?(n=t.startIndex,a=t.endIndex):!et(t.startTime)&&!et(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,o=this.bits===8?1:2,l=s+r*2*this.channels*o,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 d=0;d<r*this.channels*2;d++){var v=this._at(n*this.channels*2+d);this.bits===8?u.setInt8(s+d,v):u.setInt16(s+d*2,v,!0)}return new De(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 jt(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 De.create(a)}else{const a=await t.json();return De.create(a)}}function Zn(e,t=0){const n=e.channel(t),a=e.bits,r=n.min_array(),s=n.max_array(),o=r.length,l=a===8?new Int8Array(o*2):new Int16Array(o*2);for(let c=0;c<o;c++)l[c*2]=r[c],l[c*2+1]=s[c];return{data:l,bits:a,length:o,sampleRate:e.sample_rate}}async function lo(e,t=0){const n=await jt(e);return Zn(n,t)}async function co(e){const t=await jt(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Vn(e,t,n=0,a,r){let s=e;if(a!==void 0&&r!==void 0){const p=e.scale,f=Math.floor(a/p),C=Math.ceil((a+r)/p);s=s.slice({startIndex:f,endIndex:C})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),d=c.length,v=l===8?new Int8Array(d*2):new Int16Array(d*2);for(let p=0;p<d;p++)v[p*2]=c[p],v[p*2+1]=u[p];return{data:v,bits:l,length:d}}function Pn(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function uo(e){return{id:e.id,begin:e.start.toFixed(3),end:e.end.toFixed(3),lines:e.lines,language:e.lang||"en"}}S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
749
749
  position: absolute;
750
750
  top: 0;
751
751
  background: ${e=>e.$color};
@@ -761,7 +761,7 @@
761
761
  opacity: 0.5;
762
762
  border-color: ${e=>e.$color};
763
763
  }
764
- `;A.div`
764
+ `;S.div`
765
765
  position: absolute;
766
766
  bottom: 0;
767
767
  left: 0;
@@ -777,7 +777,7 @@
777
777
  pointer-events: none;
778
778
  white-space: pre-wrap;
779
779
  word-break: break-word;
780
- `;A.textarea`
780
+ `;S.textarea`
781
781
  position: absolute;
782
782
  bottom: 0;
783
783
  left: 0;
@@ -797,7 +797,7 @@
797
797
  outline: none;
798
798
  border-color: #4CAF50;
799
799
  }
800
- `;A.div`
800
+ `;S.div`
801
801
  position: absolute;
802
802
  top: 0;
803
803
  left: 0;
@@ -808,7 +808,7 @@
808
808
  padding: 4px;
809
809
  justify-content: flex-start;
810
810
  align-items: center;
811
- `;A.button`
811
+ `;S.button`
812
812
  background: transparent;
813
813
  border: 1px solid rgba(255, 255, 255, 0.5);
814
814
  color: white;
@@ -830,12 +830,12 @@
830
830
  &:active {
831
831
  background: rgba(255, 255, 255, 0.3);
832
832
  }
833
- `;var fo=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
833
+ `;var fo=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
834
834
  position: absolute;
835
835
  top: 0;
836
836
  height: 100%;
837
837
  pointer-events: none; /* Let events pass through to children */
838
- `,mo=A.div`
838
+ `,mo=S.div`
839
839
  position: absolute;
840
840
  top: 0;
841
841
  left: 0;
@@ -859,7 +859,7 @@
859
859
  border-width: 3px;
860
860
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
861
861
  }
862
- `,ho=A.span`
862
+ `,ho=S.span`
863
863
  font-size: 12px;
864
864
  font-weight: 600;
865
865
  color: ${e=>e.theme?.annotationLabelColor||"#2a2a2a"};
@@ -869,7 +869,7 @@
869
869
  padding: 0 6px;
870
870
  letter-spacing: 0.3px;
871
871
  user-select: none;
872
- `,ln=A.div`
872
+ `,ln=S.div`
873
873
  position: absolute;
874
874
  top: 0;
875
875
  ${e=>e.$position==="left"?"left: -8px":"right: -8px"};
@@ -904,13 +904,13 @@
904
904
  opacity: 1;
905
905
  background: ${e=>e.theme?.annotationResizeHandleActiveColor||"rgba(0, 0, 0, 0.7)"};
906
906
  }
907
- `,zn=({annotationId:e,annotationIndex:t,startPosition:n,endPosition:r,label:a,color:s="#ff9800",isActive:o=!1,onClick:l,editable:c=!0})=>{const u=Math.max(0,r-n),d=`annotation-boundary-start-${t}`,{attributes:x,listeners:g,setActivatorNodeRef:f,isDragging:C}=De.useDraggable({id:d,data:{annotationId:e,annotationIndex:t,edge:"start"},disabled:!c}),w=`annotation-boundary-end-${t}`,{attributes:h,listeners:b,setActivatorNodeRef:I,isDragging:p}=De.useDraggable({id:w,data:{annotationId:e,annotationIndex:t,edge:"end"},disabled:!c});if(u<=0)return null;const m=k=>S=>{S.stopPropagation(),k?.(S)},y=k=>{k.stopPropagation()};return v.jsxs(fo,{$left:n,$width:u,children:[v.jsx(mo,{$color:s,$isActive:o,onClick:l,children:a&&v.jsx(ho,{children:a})}),c&&v.jsx(ln,{ref:f,$position:"left",$isDragging:C,onClick:y,...g,onPointerDown:m(g?.onPointerDown),...x}),c&&v.jsx(ln,{ref:I,$position:"right",$isDragging:p,onClick:y,...b,onPointerDown:m(b?.onPointerDown),...h})]})},po=A.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
907
+ `,zn=({annotationId:e,annotationIndex:t,startPosition:n,endPosition:a,label:r,color:s="#ff9800",isActive:o=!1,onClick:l,editable:c=!0})=>{const u=Math.max(0,a-n),d=`annotation-boundary-start-${t}`,{attributes:v,listeners:p,setActivatorNodeRef:f,isDragging:C}=Ee.useDraggable({id:d,data:{annotationId:e,annotationIndex:t,edge:"start"},disabled:!c}),y=`annotation-boundary-end-${t}`,{attributes:m,listeners:g,setActivatorNodeRef:I,isDragging:x}=Ee.useDraggable({id:y,data:{annotationId:e,annotationIndex:t,edge:"end"},disabled:!c});if(u<=0)return null;const h=k=>A=>{A.stopPropagation(),k?.(A)},w=k=>{k.stopPropagation()};return b.jsxs(fo,{$left:n,$width:u,children:[b.jsx(mo,{$color:s,$isActive:o,onClick:l,children:r&&b.jsx(ho,{children:r})}),c&&b.jsx(ln,{ref:f,$position:"left",$isDragging:C,onClick:w,...p,onPointerDown:h(p?.onPointerDown),...v}),c&&b.jsx(ln,{ref:I,$position:"right",$isDragging:x,onClick:w,...g,onPointerDown:h(g?.onPointerDown),...m})]})},po=S.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
908
908
  position: relative;
909
909
  display: flex;
910
910
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
911
911
  background: transparent;
912
912
  z-index: 110;
913
- `,go=A.div`
913
+ `,go=S.div`
914
914
  position: sticky;
915
915
  z-index: 200;
916
916
  left: 0;
@@ -918,16 +918,16 @@
918
918
  width: ${e=>e.$controlWidth}px;
919
919
  flex-shrink: 0;
920
920
  background: transparent;
921
- `,bo=A.div`
921
+ `,bo=S.div`
922
922
  position: relative;
923
923
  flex: 1;
924
924
  padding-left: ${e=>e.$offset||0}px;
925
- `,jn=({children:e,className:t,height:n=30,offset:r=0,width:a})=>{const{controls:{show:s,width:o}}=st();return v.jsxs(po,{className:t,$height:n,$controlWidth:s?o:0,$width:a,children:[v.jsx(go,{$controlWidth:s?o:0}),v.jsx(bo,{$offset:r,children:e})]})};A.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
925
+ `,jn=({children:e,className:t,height:n=30,offset:a=0,width:r})=>{const{controls:{show:s,width:o}}=st();return b.jsxs(po,{className:t,$height:n,$controlWidth:s?o:0,$width:r,children:[b.jsx(go,{$controlWidth:s?o:0}),b.jsx(bo,{$offset:a,children:e})]})};S.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
926
926
  position: relative;
927
927
  display: flex;
928
928
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
929
929
  background: transparent;
930
- `;A.div`
930
+ `;S.div`
931
931
  position: sticky;
932
932
  z-index: 200;
933
933
  left: 0;
@@ -941,16 +941,16 @@
941
941
  font-size: 12px;
942
942
  color: ${e=>e.theme?.textColorMuted||"#666"};
943
943
  font-weight: bold;
944
- `;A.div`
944
+ `;S.div`
945
945
  position: relative;
946
946
  flex: 1;
947
947
  padding-left: ${e=>e.$offset||0}px;
948
- `;var vo=A.div`
948
+ `;var vo=S.div`
949
949
  background: ${e=>e.theme?.backgroundColor||"#fff"};
950
950
  ${e=>e.$height?`height: ${e.$height}px;`:"max-height: 200px;"}
951
951
  overflow-y: auto;
952
952
  padding: 8px;
953
- `,Co=A.div`
953
+ `,Co=S.div`
954
954
  padding: 12px;
955
955
  margin-bottom: 6px;
956
956
  border-left: 4px solid ${e=>e.$isActive?"#ff9800":"transparent"};
@@ -969,16 +969,16 @@
969
969
  outline: 2px solid #ff9800;
970
970
  outline-offset: 2px;
971
971
  }
972
- `,xo=A.div`
972
+ `,xo=S.div`
973
973
  display: flex;
974
974
  justify-content: space-between;
975
975
  align-items: center;
976
976
  margin-bottom: 6px;
977
- `,wo=A.div`
977
+ `,wo=S.div`
978
978
  display: flex;
979
979
  align-items: center;
980
980
  gap: 8px;
981
- `,yo=A.span`
981
+ `,yo=S.span`
982
982
  font-size: 11px;
983
983
  font-weight: 600;
984
984
  color: ${e=>e.theme?.textColorMuted||"#666"};
@@ -992,16 +992,16 @@
992
992
  outline: 2px solid #ff9800;
993
993
  background: rgba(255, 152, 0, 0.1);
994
994
  }
995
- `,ko=A.span`
995
+ `,ko=S.span`
996
996
  font-size: 12px;
997
997
  font-weight: 500;
998
998
  color: ${e=>e.theme?.textColorMuted||"#555"};
999
999
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
1000
1000
  letter-spacing: 0.5px;
1001
- `,Io=A.div`
1001
+ `,Io=S.div`
1002
1002
  display: flex;
1003
1003
  gap: 6px;
1004
- `,So=A.button`
1004
+ `,So=S.button`
1005
1005
  background: ${e=>e.theme?.surfaceColor||"#f5f5f5"};
1006
1006
  border: 1px solid ${e=>e.theme?.borderColor||"#ccc"};
1007
1007
  color: ${e=>e.theme?.textColor||"#333"};
@@ -1020,7 +1020,7 @@
1020
1020
  &:active {
1021
1021
  transform: scale(0.95);
1022
1022
  }
1023
- `,Ao=A.div`
1023
+ `,Ao=S.div`
1024
1024
  font-size: 14px;
1025
1025
  line-height: 1.6;
1026
1026
  color: ${e=>e.theme?.textColor||"#2a2a2a"};
@@ -1035,9 +1035,9 @@
1035
1035
  outline: 2px solid #ff9800;
1036
1036
  background: rgba(255, 152, 0, 0.1);
1037
1037
  }
1038
- `,$o=({annotations:e,activeAnnotationId:t,shouldScrollToActive:n=!1,scrollActivePosition:r="center",editable:a=!1,controls:s=[],annotationListConfig:o,height:l,onAnnotationClick:c,onAnnotationUpdate:u,renderAnnotationItem:d})=>{const x=i.useRef(null),g=i.useRef(null),f=i.useRef(void 0);i.useEffect(()=>{}),i.useEffect(()=>{const p=g.current;if(!p)return;const m=()=>{};return p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)},[]),i.useEffect(()=>{t&&x.current&&n&&x.current.scrollIntoView({behavior:"smooth",block:r}),f.current=t},[t,n,r]);const C=p=>{if(isNaN(p)||!isFinite(p))return"0:00.000";const m=Math.floor(p/60),y=(p%60).toFixed(3);return`${m}:${y.padStart(6,"0")}`},w=(p,m)=>{if(!a||!u)return;const y=[...e];y[p]={...y[p],lines:m.split(`
1039
- `)},u(y)},h=(p,m)=>{if(!a||!u)return;const y=m.trim();if(!y)return;const k=[...e];k[p]={...k[p],id:y},u(k)},b=(p,m,y)=>{if(!u)return;const k=[...e];p.action(k[y],y,k,o||{}),u(k)},I=p=>p.replace(/\./g," ");return v.jsx(vo,{ref:g,$height:l,children:e.map((p,m)=>{const y=p.id===t,k=()=>c?.(p);return d?v.jsx("div",{ref:y?x:null,children:d({annotation:p,index:m,isActive:y,onClick:k,formatTime:C})},p.id):v.jsxs(Co,{ref:y?x:null,$isActive:y,onClick:k,children:[v.jsxs(xo,{children:[v.jsxs(wo,{children:[v.jsx(yo,{$isEditable:a,contentEditable:a,suppressContentEditableWarning:!0,onBlur:S=>h(m,S.currentTarget.textContent||""),children:p.id}),v.jsxs(ko,{children:[C(p.start)," - ",C(p.end)]})]}),s.length>0&&v.jsx(Io,{onClick:S=>S.stopPropagation(),children:s.map((S,$)=>v.jsx(So,{title:S.title,onClick:()=>b(S,p,m),children:S.text?S.text:v.jsx("i",{className:I(S.class||"")})},$))})]}),v.jsx(Ao,{$isEditable:a,contentEditable:a,suppressContentEditableWarning:!0,onBlur:S=>w(m,S.currentTarget.textContent||""),children:p.lines.join(`
1040
- `)})]},p.id)})})},Hn=i.memo($o),Mo=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return v.jsxs(vt,{className:r,children:[v.jsx(Ct,{type:"checkbox",id:"continuous-play",className:"continuous-play",checked:e,onChange:a,disabled:n}),v.jsx(xt,{htmlFor:"continuous-play",children:"Continuous Play"})]})},Ro=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return v.jsxs(vt,{className:r,children:[v.jsx(Ct,{type:"checkbox",id:"link-endpoints",className:"link-endpoints",checked:e,onChange:a,disabled:n}),v.jsx(xt,{htmlFor:"link-endpoints",children:"Link Endpoints"})]})},Eo=({checked:e,onChange:t,className:n})=>v.jsxs(vt,{className:n,children:[v.jsx(Ct,{type:"checkbox",id:"editable-annotations",checked:e,onChange:r=>t(r.target.checked)}),v.jsx(xt,{htmlFor:"editable-annotations",children:"Editable Annotations"})]}),Do=A.button`
1038
+ `,$o=({annotations:e,activeAnnotationId:t,shouldScrollToActive:n=!1,scrollActivePosition:a="center",scrollActiveContainer:r="nearest",editable:s=!1,controls:o=[],annotationListConfig:l,height:c,onAnnotationClick:u,onAnnotationUpdate:d,renderAnnotationItem:v})=>{const p=i.useRef(null),f=i.useRef(null),C=i.useRef(void 0);i.useEffect(()=>{}),i.useEffect(()=>{const h=f.current;if(!h)return;const w=()=>{};return h.addEventListener("scroll",w),()=>h.removeEventListener("scroll",w)},[]),i.useEffect(()=>{t&&p.current&&n&&p.current.scrollIntoView({behavior:"smooth",block:a,container:r}),C.current=t},[t,n,a,r]);const y=h=>{if(isNaN(h)||!isFinite(h))return"0:00.000";const w=Math.floor(h/60),k=(h%60).toFixed(3);return`${w}:${k.padStart(6,"0")}`},m=(h,w)=>{if(!s||!d)return;const k=[...e];k[h]={...k[h],lines:w.split(`
1039
+ `)},d(k)},g=(h,w)=>{if(!s||!d)return;const k=w.trim();if(!k)return;const A=[...e];A[h]={...A[h],id:k},d(A)},I=(h,w,k)=>{if(!d)return;const A=[...e];h.action(A[k],k,A,l||{}),d(A)},x=h=>h.replace(/\./g," ");return b.jsx(vo,{ref:f,$height:c,children:e.map((h,w)=>{const k=h.id===t,A=()=>u?.(h);return v?b.jsx("div",{ref:k?p:null,children:v({annotation:h,index:w,isActive:k,onClick:A,formatTime:y})},h.id):b.jsxs(Co,{ref:k?p:null,$isActive:k,onClick:A,children:[b.jsxs(xo,{children:[b.jsxs(wo,{children:[b.jsx(yo,{$isEditable:s,contentEditable:s,suppressContentEditableWarning:!0,onBlur:M=>g(w,M.currentTarget.textContent||""),children:h.id}),b.jsxs(ko,{children:[y(h.start)," - ",y(h.end)]})]}),o.length>0&&b.jsx(Io,{onClick:M=>M.stopPropagation(),children:o.map((M,$)=>b.jsx(So,{title:M.title,onClick:()=>I(M,h,w),children:M.text?M.text:b.jsx("i",{className:x(M.class||"")})},$))})]}),b.jsx(Ao,{$isEditable:s,contentEditable:s,suppressContentEditableWarning:!0,onBlur:M=>m(w,M.currentTarget.textContent||""),children:h.lines.join(`
1040
+ `)})]},h.id)})})},Hn=i.memo($o),Mo=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return b.jsxs(Ct,{className:a,children:[b.jsx(xt,{type:"checkbox",id:"continuous-play",className:"continuous-play",checked:e,onChange:r,disabled:n}),b.jsx(wt,{htmlFor:"continuous-play",children:"Continuous Play"})]})},Ro=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return b.jsxs(Ct,{className:a,children:[b.jsx(xt,{type:"checkbox",id:"link-endpoints",className:"link-endpoints",checked:e,onChange:r,disabled:n}),b.jsx(wt,{htmlFor:"link-endpoints",children:"Link Endpoints"})]})},Eo=({checked:e,onChange:t,className:n})=>b.jsxs(Ct,{className:n,children:[b.jsx(xt,{type:"checkbox",id:"editable-annotations",checked:e,onChange:a=>t(a.target.checked)}),b.jsx(wt,{htmlFor:"editable-annotations",children:"Editable Annotations"})]}),Do=S.button`
1041
1041
  padding: 0.5rem 1rem;
1042
1042
  background: ${e=>e.theme?.surfaceColor||"#f5f5f5"};
1043
1043
  color: ${e=>e.theme?.textColor||"#333"};
@@ -1063,7 +1063,7 @@
1063
1063
  opacity: 0.6;
1064
1064
  cursor: not-allowed;
1065
1065
  }
1066
- `,Bo=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:r,children:a="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(x=>uo(x)),l=JSON.stringify(o,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),d=document.createElement("a");d.href=u,d.download=t,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(u)};return v.jsx(Do,{onClick:s,disabled:n||e.length===0,className:r,title:e.length===0?"No annotations to download":"Download the annotations as JSON",children:a})};function Xn(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:a=>tt(a,e),parseTime:a=>Mn(a,e)}}const To=[256,512,1024,2048,4096,8192];function Gn({initialSamplesPerPixel:e,zoomLevels:t=To}){const[n,r]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),a=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{r(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{r(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:a,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function Nn({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[r,a]=i.useState(t),s=i.useCallback(o=>{a(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:r,setMasterVolume:s}}const Wo=(e=256)=>{const t=i.useRef(null),n=i.useCallback((r,a,s)=>{const o=new W.Analyser("fft",e);return r.connect(o),r.connect(a),t.current=o,function(){o.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function _t(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,x=t?.length??e.sourceDurationSamples??(u&&d?Math.ceil(u.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(x===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 g=e.durationSamples??x;return{id:Ln(),audioBuffer:t,startSample:n,durationSamples:g,offsetSamples:r,sampleRate:d,sourceDurationSamples:x,gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function _o(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const x=t?.duration??e.sourceDuration??u?.duration;if(x===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 g=e.duration??x;return _t({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(g*d),offsetSamples:Math.round(r*d),sampleRate:d,sourceDurationSamples:Math.ceil(x*d),gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Fo(e){const{name:t,clips:n=[],muted:r=!1,soloed:a=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Ln(),name:t,clips:n,muted:r,soloed:a,volume:s,pan:o,color:l,height:c}}function Ln(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Zo(e,t={}){const{progressive:n=!1}=t,[r,a]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),x=e.length;return i.useEffect(()=>{if(e.length===0){a([]),o(!1),d(0);return}let g=!1;const f=new Map,C=(h,b,I)=>{const p=I??h.audioBuffer;if(!p&&!h.waveformData)throw new Error(`Track ${b+1}: Must provide src, audioBuffer, or waveformData`);const m=p?.duration??h.waveformData?.duration,y=_o({audioBuffer:p,startTime:h.startTime??0,duration:h.duration??m,offset:h.offset??0,name:h.name||`Track ${b+1}`,fadeIn:h.fadeIn,fadeOut:h.fadeOut,waveformData:h.waveformData});if(isNaN(y.startSample)||isNaN(y.durationSamples)||isNaN(y.offsetSamples))throw console.error("Invalid clip values:",y),new Error(`Invalid clip values for track ${b+1}`);return{...Fo({name:h.name||`Track ${b+1}`,clips:[y],muted:h.muted??!1,soloed:h.soloed??!1,volume:h.volume??1,pan:h.pan??0,color:h.color}),effects:h.effects}};return(async()=>{try{o(!0),c(null),d(0);const h=pn.getContext().rawContext,b=e.map(async(p,m)=>{if(p.audioBuffer){const E=C(p,m,p.audioBuffer);return n&&!g&&(f.set(m,E),d(R=>R+1),a(Array.from({length:e.length},(R,M)=>f.get(M)).filter(R=>R!==void 0))),E}if(!p.src&&p.waveformData){const E=C(p,m);return n&&!g&&(f.set(m,E),d(R=>R+1),a(Array.from({length:e.length},(R,M)=>f.get(M)).filter(R=>R!==void 0))),E}if(!p.src)throw new Error(`Track ${m+1}: Must provide src, audioBuffer, or waveformData`);const y=await fetch(p.src);if(!y.ok)throw new Error(`Failed to fetch ${p.src}: ${y.statusText}`);const k=await y.arrayBuffer(),S=await h.decodeAudioData(k);if(!S||!S.sampleRate||!S.duration)throw new Error(`Invalid audio buffer for ${p.src}`);const $=C(p,m,S);return n&&!g&&(f.set(m,$),d(E=>E+1),a(Array.from({length:e.length},(E,R)=>f.get(R)).filter(E=>E!==void 0))),$}),I=await Promise.all(b);g||(n||(a(I),d(I.length)),o(!1))}catch(h){if(!g){const b=h instanceof Error?h.message:"Unknown error loading audio";c(b),o(!1),console.error("Error loading audio tracks:",h)}}})(),()=>{g=!0}},[e,n]),{tracks:r,loading:s,error:l,loadedCount:u,totalCount:x}}function Vo({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:r}){const a=i.useRef(null),s=i.useCallback(u=>{const{transform:d,active:x}=u;if(!x?.data?.current)return{...d,scaleX:1,scaleY:1};const{trackIndex:g,clipIndex:f,boundary:C}=x.data.current;if(C)return{...d,scaleX:1,scaleY:1};const w=e[g];if(!w)return{...d,scaleX:1,scaleY:1};const h=w.clips[f];if(!h)return{...d,scaleX:1,scaleY:1};const b=h.startSample/r,I=h.durationSamples/r,p=d.x*n/r;let m=b+p;const y=[...w.clips].sort((M,B)=>M.startSample-B.startSample),k=y.findIndex(M=>M===h);m=Math.max(0,m);const S=k>0?y[k-1]:null;if(S){const M=(S.startSample+S.durationSamples)/r;m=Math.max(m,M)}const $=k<y.length-1?y[k+1]:null;if($){const M=m+I,B=$.startSample/r;M>B&&(m=B-I)}const R=(m-b)*r/n;return{...d,x:R,scaleX:1,scaleY:1}},[e,n,r]),o=i.useCallback(u=>{const{active:d}=u,{boundary:x}=d.data.current;if(!x){a.current=null;return}const{trackIndex:g,clipIndex:f}=d.data.current,w=e[g]?.clips[f];w&&(a.current={offsetSamples:w.offsetSamples,durationSamples:w.durationSamples,startSample:w.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:x}=u,{boundary:g}=d.data.current;if(!g||!a.current)return;const{trackIndex:f,clipIndex:C}=d.data.current,w=x.x*n,h=Math.floor(.1*r),b=a.current,I=e.map((p,m)=>{if(m!==f)return p;const y=[...p.clips].sort(($,E)=>$.startSample-E.startSample),k=y.findIndex($=>$===p.clips[C]),S=p.clips.map(($,E)=>{if(E!==C)return $;const R=$.sourceDurationSamples;if(g==="left"){let M=Math.floor(w);const B=-b.startSample;M<B&&(M=B);const D=-b.offsetSamples;M<D&&(M=D);const z=k>0?y[k-1]:null;if(z){const L=z.startSample+z.durationSamples-b.startSample;M<L&&(M=L)}const V=b.durationSamples-h;M>V&&(M=V);const F=b.offsetSamples+M,K=b.durationSamples-M,H=b.startSample+M;return{...$,offsetSamples:F,durationSamples:K,startSample:H}}else{let M=Math.floor(b.durationSamples+w);M=Math.max(h,M),b.offsetSamples+M>R&&(M=R-b.offsetSamples);const B=k<y.length-1?y[k+1]:null;return B&&b.startSample+M>B.startSample&&(M=B.startSample-b.startSample,M=Math.max(h,M)),{...$,durationSamples:M}}});return{...p,clips:S}});t(I)},[e,t,n,r]),c=i.useCallback(u=>{const{active:d,delta:x}=u,{trackIndex:g,clipIndex:f,boundary:C}=d.data.current,w=x.x*n;if(C){a.current=null;return}const h=e.map((b,I)=>{if(I!==g)return b;const p=[...b.clips].sort((k,S)=>k.startSample-S.startSample),m=p.findIndex(k=>k===b.clips[f]),y=b.clips.map((k,S)=>{if(S!==f)return k;let $=Math.floor(k.startSample+w);$=Math.max(0,$);const E=m>0?p[m-1]:null;if(E){const M=E.startSample+E.durationSamples;$=Math.max($,M)}const R=m<p.length-1?p[m+1]:null;return R&&$+k.durationSamples>R.startSample&&($=R.startSample-k.durationSamples),{...k,startSample:$}});return{...b,clips:y}});t(h)},[e,t,n,r]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Dt=.01;function Yn({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:r,duration:a,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:x}=d,g=x.data.current;if(!g||g.annotationIndex===void 0){o.current=null;return}const f=e[g.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:g.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:x,delta:g}=d;if(!o.current)return;const f=x.data.current;if(!f)return;const{edge:C,annotationIndex:w}=f,h=o.current,b=g.x*n/r,I=C==="start"?h.start+b:h.end+b,p=Po({annotationIndex:w,newTime:I,isDraggingStart:C==="start",annotations:e,duration:a,linkEndpoints:s});t(p)},[e,t,n,r,a,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Po({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:r,duration:a,linkEndpoints:s}){const o=[...r],l=r[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<Dt?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,a)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<Dt){const x=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,x)};let g=e+1;for(;g<o.length-1;){const f=o[g],C=o[g+1];if(Math.abs(C.start-f.end)<Dt){const w=f.end-r[g].end;o[g+1]={...C,start:Math.min(C.end-.1,C.start+w)},g++}else break}}else c>=d.start&&(o[e]={...o[e],end:d.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const d=o[e+1];o[e+1]={...d,start:c};let x=e+1;for(;x<o.length-1;){const g=o[x],f=o[x+1];if(g.end>f.start)o[x+1]={...f,start:g.end},x++;else break}}}return o}function zo(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:r=5,mouseDistance:a=1}=e,s=De.useSensor(De.MouseSensor,{activationConstraint:{distance:a}}),o=De.useSensor(De.TouchSensor,{activationConstraint:t?{delay:n,tolerance:r}:{distance:a}}),l=De.useSensor(De.PointerSensor,{activationConstraint:{distance:a}});return De.useSensors(...t?[s,o]:[l])}const jo=e=>{const{tracks:t,onTracksChange:n,sampleRate:r}=e,{currentTimeRef:a}=Se(),{selectedTrackId:s}=We(),o=i.useCallback((c,u,d)=>{const{sampleRate:x,samplesPerPixel:g}=e,f=t[c];if(!f)return!1;const C=f.clips[u];if(!C)return!1;const w=C.startSample/x,h=(C.startSample+C.durationSamples)/x;if(d<=w||d>=h)return console.warn("Split time is outside clip bounds"),!1;const b=Math.round(d*x),I=Math.floor(b/g),p=C.startSample+C.durationSamples,m=I*g,y=C.startSample,k=m-y,S=m,$=p-S,E=m-C.startSample,R=_t({audioBuffer:C.audioBuffer,startSample:y,durationSamples:k,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}),M=_t({audioBuffer:C.audioBuffer,startSample:S,durationSamples:$,offsetSamples:C.offsetSamples+E,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=[...f.clips];B.splice(u,1,R,M);const D=[...t];return D[c]={...f,clips:B},n(D),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(x=>x.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],d=a.current??0;for(let x=0;x<u.clips.length;x++){const g=u.clips[x],f=g.startSample/r,C=(g.startSample+g.durationSamples)/r;if(d>f&&d<C)return console.log(`Splitting clip on track "${u.name}" at ${d}s`),o(c,x,d)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,a,s,o,r]),splitClipAt:o}},bt=e=>{const{shortcuts:t,enabled:n=!0}=e,r=i.useCallback(a=>{if(!n)return;const s=a.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=a.key.toLowerCase()===l.key.toLowerCase()||a.key===l.key,u=l.ctrlKey===void 0||a.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||a.shiftKey===l.shiftKey,x=l.metaKey===void 0||a.metaKey===l.metaKey,g=l.altKey===void 0||a.altKey===l.altKey;return c&&u&&d&&x&&g});o&&(o.preventDefault!==!1&&a.preventDefault(),o.action())},[t,n]);i.useEffect(()=>{if(n)return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}},[r,n])},Ho=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("+")},Xo=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:r}=e,{isPlaying:a}=Se(),{setCurrentTime:s,play:o,pause:l,stop:c}=me(),{playoutRef:u}=ye(),d=i.useCallback(()=>{a?l():o()},[a,o,l]),x=i.useCallback(()=>{c()},[c]),g=i.useCallback(()=>{a&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[a,u,s,o]),C=r??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:x,description:"Stop",preventDefault:!0},{key:"0",action:g,description:"Rewind to start",preventDefault:!0}],...n];return bt({shortcuts:C,enabled:t}),{rewindToStart:g,togglePlayPause:d,stopPlayback:x,shortcuts:C}},Bt=.01,mt=.01;function Go({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:r,duration:a,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:x=0,onPlay:g}){const f=i.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),C=i.useCallback(E=>{if(!c?.current||!u||!d)return;const R=e.find(Z=>Z.id===E);if(!R)return;const M=c.current,B=M.clientWidth,D=R.start*d/u+x,z=R.end*d/u+x,V=(D+z)/2,F=M.scrollLeft,K=F,H=F+B;if(D<K||z>H){const Z=Math.max(0,V-B/2);M.scrollTo({left:Z,behavior:"smooth"})}},[e,c,u,d,x]);i.useEffect(()=>{t&&c?.current&&u&&d&&C(t)},[t,C,c,u,d]);const w=i.useCallback(E=>{if(f<0)return;const R=e[f],M=Math.max(0,Math.min(R.end-.1,R.start+E)),B=M-R.start,D=[...e];if(D[f]={...R,start:M},s&&f>0){const z=D[f-1];Math.abs(z.end-R.start)<Bt&&(D[f-1]={...z,end:Math.max(z.start+.1,z.end+B)})}else if(!s&&f>0){const z=D[f-1];M<z.end&&(D[f-1]={...z,end:M})}n(D)},[e,f,s,n]),h=i.useCallback(E=>{if(f<0)return;const R=e[f],M=Math.max(R.start+.1,Math.min(a,R.end+E)),B=M-R.end,D=[...e];if(D[f]={...R,end:M},s&&f<e.length-1){const z=D[f+1];if(Math.abs(z.start-R.end)<Bt){const V=Math.min(z.end-.1,z.start+B);D[f+1]={...z,start:V};let F=f+1;for(;F<D.length-1;){const K=D[F],H=D[F+1];if(Math.abs(H.start-e[F].end)<Bt){const Z=K.end-e[F].end;D[F+1]={...H,start:Math.min(H.end-.1,H.start+Z)},F++}else break}}}else if(!s&&f<e.length-1){const z=D[f+1];if(M>z.start){D[f+1]={...z,start:M};let V=f+1;for(;V<D.length-1;){const F=D[V],K=D[V+1];if(F.end>K.start)D[V+1]={...K,start:F.end},V++;else break}}}n(D)},[e,f,a,s,n]),b=i.useCallback(()=>{!r||e.length===0||(f<=0?r(e[e.length-1].id):r(e[f-1].id))},[e,f,r]),I=i.useCallback(()=>{!r||e.length===0||(f<0||f>=e.length-1?r(e[0].id):r(e[f+1].id))},[e,f,r]),p=i.useCallback(()=>{!r||e.length===0||r(e[0].id)},[e,r]),m=i.useCallback(()=>{!r||e.length===0||r(e[e.length-1].id)},[e,r]),y=i.useCallback(()=>{r&&r(null)},[r]),k=i.useCallback(()=>{if(f<0||!g)return;const E=e[f],R=o?void 0:E.end-E.start;g(E.start,R)},[e,f,o,g]),S=i.useMemo(()=>[{key:"[",action:()=>w(-mt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>w(mt),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>h(-mt),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>h(mt),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:k,description:"Play selected annotation",preventDefault:!0}],[w,h,k]),$=i.useMemo(()=>[{key:"ArrowUp",action:b,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:b,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:I,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:I,description:"Select next annotation",preventDefault:!0},{key:"Home",action:p,description:"Select first annotation",preventDefault:!0},{key:"End",action:m,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:y,description:"Deselect annotation",preventDefault:!0}],[b,I,p,m,y]);return bt({shortcuts:S,enabled:l&&f>=0}),bt({shortcuts:$,enabled:l&&e.length>0&&!!r}),{moveStartBoundary:w,moveEndBoundary:h,selectPrevious:b,selectNext:I,selectFirst:p,selectLast:m,clearSelection:y,scrollToAnnotation:C,playActiveAnnotation:k}}function No(e){const t=e.reduce((a,s)=>a+s.length,0),n=new Float32Array(t);let r=0;for(const a of e)n.set(a,r),r+=a.length;return n}function Lo(e,t,n,r=1){const a=e.createBuffer(r,t.length,n),s=new Float32Array(t);return a.copyToChannel(s,0),a}function cn(e,t,n=16){const r=Math.ceil(e.length/t),a=n===8?new Int8Array(r*2):new Int16Array(r*2),s=2**(n-1);for(let o=0;o<r;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,d=0;for(let x=l;x<c;x++){const g=e[x];g<u&&(u=g),g>d&&(d=g)}a[o*2]=Math.floor(u*s),a[o*2+1]=Math.floor(d*s)}return a}function Yo(e,t,n,r,a=16){const s=2**(a-1),o=r%n;let l=0;if(o>0&&e.length>0){const d=n-o,x=Math.min(d,t.length);let g=e[e.length-2]/s,f=e[e.length-1]/s;for(let b=0;b<x;b++){const I=t[b];I<g&&(g=I),I>f&&(f=I)}const C=new(a===8?Int8Array:Int16Array)(e.length);C.set(e),C[e.length-2]=Math.floor(g*s),C[e.length-1]=Math.floor(f*s),l=x;const w=cn(t.slice(l),n,a),h=new(a===8?Int8Array:Int16Array)(C.length+w.length);return h.set(C),h.set(w,C.length),h}const c=cn(t.slice(l),n,a),u=new(a===8?Int8Array:Int16Array)(e.length+c.length);return u.set(e),u.set(c,e.length),u}function Oo(e,t={}){const{channelCount:n=1,samplesPerPixel:r=1024}=t,[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[d,x]=i.useState(new Int16Array(0)),[g,f]=i.useState(null),[C,w]=i.useState(null),[h,b]=i.useState(0),[I,p]=i.useState(0),m=16,y=i.useRef(!1),k=i.useRef(null),S=i.useRef(null),$=i.useRef([]),E=i.useRef(0),R=i.useRef(null),M=i.useRef(0),B=i.useRef(!1),D=i.useRef(!1),z=i.useCallback(async()=>{if(!y.current)try{const Z=W.getContext(),L=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Rt&&Rt.tagName.toUpperCase()==="SCRIPT"&&Rt.src||new URL("index.js",document.baseURI).href).href;await Z.addAudioWorkletModule(L),y.current=!0}catch(Z){throw console.error("Failed to load AudioWorklet module:",Z),new Error("Failed to load recording processor")}},[]),V=i.useCallback(async()=>{if(!e){w(new Error("No microphone stream available"));return}try{w(null);const Z=W.getContext();Z.state==="suspended"&&await Z.resume(),await z();const L=Z.createMediaStreamSource(e);S.current=L;const ae=Z.createAudioWorkletNode("recording-processor");k.current=ae,L.connect(ae),ae.port.onmessage=Q=>{const{samples:re}=Q.data;$.current.push(re),E.current+=re.length,x(be=>Yo(be,re,r,E.current-re.length,m))},ae.port.postMessage({command:"start",sampleRate:Z.sampleRate,channelCount:n}),$.current=[],E.current=0,x(new Int16Array(0)),f(null),b(0),p(0),B.current=!0,D.current=!1,s(!0),l(!1),M.current=performance.now();const ne=()=>{if(B.current&&!D.current){const Q=(performance.now()-M.current)/1e3;u(Q),R.current=requestAnimationFrame(ne)}};ne()}catch(Z){console.error("Failed to start recording:",Z),w(Z instanceof Error?Z:new Error("Failed to start recording"))}},[e,n,r,z,a,o]),F=i.useCallback(async()=>{if(!a)return null;try{if(k.current){if(k.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(k.current)}catch{}k.current.disconnect()}R.current!==null&&(cancelAnimationFrame(R.current),R.current=null);const Z=No($.current),ae=W.getContext().rawContext,ne=Lo(ae,Z,ae.sampleRate,n);return f(ne),u(ne.duration),B.current=!1,D.current=!1,s(!1),l(!1),b(0),ne}catch(Z){return console.error("Failed to stop recording:",Z),w(Z instanceof Error?Z:new Error("Failed to stop recording")),null}},[a,n]),K=i.useCallback(()=>{a&&!o&&(R.current!==null&&(cancelAnimationFrame(R.current),R.current=null),D.current=!0,l(!0))},[a,o]),H=i.useCallback(()=>{if(a&&o){D.current=!1,l(!1),M.current=performance.now()-c*1e3;const Z=()=>{if(B.current&&!D.current){const L=(performance.now()-M.current)/1e3;u(L),R.current=requestAnimationFrame(Z)}};Z()}},[a,o,c]);return i.useEffect(()=>()=>{if(k.current){if(k.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(k.current)}catch{}k.current.disconnect()}R.current!==null&&cancelAnimationFrame(R.current)},[]),{isRecording:a,isPaused:o,duration:c,peaks:d,audioBuffer:g,level:h,peakLevel:I,startRecording:V,stopRecording:F,pauseRecording:K,resumeRecording:H,error:C}}function Ko(){const[e,t]=i.useState(null),[n,r]=i.useState([]),[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),d=i.useCallback(async()=>{try{const C=(await navigator.mediaDevices.enumerateDevices()).filter(w=>w.kind==="audioinput").map(w=>({deviceId:w.deviceId,label:w.label||`Microphone ${w.deviceId.slice(0,8)}`,groupId:w.groupId}));r(C)}catch(f){console.error("Failed to enumerate devices:",f),u(f instanceof Error?f:new Error("Failed to enumerate devices"))}},[]),x=i.useCallback(async(f,C)=>{l(!0),u(null);try{e&&e.getTracks().forEach(I=>I.stop());const h={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...C,...f&&{deviceId:{exact:f}}},video:!1},b=await navigator.mediaDevices.getUserMedia(h);t(b),s(!0),await d()}catch(w){console.error("Failed to access microphone:",w),u(w instanceof Error?w:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,d]),g=i.useCallback(()=>{e&&(e.getTracks().forEach(f=>f.stop()),t(null),s(!1))},[e]);return i.useEffect(()=>(d(),()=>{e&&e.getTracks().forEach(f=>f.stop())}),[]),{stream:e,devices:n,hasPermission:a,isLoading:o,requestAccess:x,stopStream:g,error:c}}function Uo(e,t={}){const{updateRate:n=60,smoothingTimeConstant:r=.8}=t,[a,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),d=i.useRef(null),x=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let g=!0;return(async()=>{if(!g)return;const C=W.getContext();if(C.state==="suspended"&&await C.resume(),!g)return;const w=new W.Meter({smoothing:r,context:C});c.current=w;const h=C.createMediaStreamSource(e);u.current=h,W.connect(h,w);const b=1e3/n;let I=0;const p=m=>{if(!(!g||!c.current)){if(m-I>=b){I=m;const y=c.current.getValue(),k=typeof y=="number"?y:y[0],S=Math.max(0,Math.min(1,(k+100)/100));s(S),l($=>Math.max($,S))}d.current=requestAnimationFrame(p)}};d.current=requestAnimationFrame(p)})(),()=>{if(g=!1,d.current&&(cancelAnimationFrame(d.current),d.current=null),u.current){try{u.current.disconnect()}catch{}u.current=null}c.current&&(c.current.dispose(),c.current=null)}},[e,r,n]),{level:a,peakLevel:o,resetPeak:x}}A.button`
1066
+ `,Bo=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:a,children:r="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(v=>uo(v)),l=JSON.stringify(o,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),d=document.createElement("a");d.href=u,d.download=t,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(u)};return b.jsx(Do,{onClick:s,disabled:n||e.length===0,className:a,title:e.length===0?"No annotations to download":"Download the annotations as JSON",children:r})};function Xn(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>tt(r,e),parseTime:r=>Mn(r,e)}}const To=[256,512,1024,2048,4096,8192];function Gn({initialSamplesPerPixel:e,zoomLevels:t=To}){const[n,a]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),r=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{a(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{a(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:r,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function Nn({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[a,r]=i.useState(t),s=i.useCallback(o=>{r(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:a,setMasterVolume:s}}const Wo=(e=256)=>{const t=i.useRef(null),n=i.useCallback((a,r,s)=>{const o=new W.Analyser("fft",e);return a.connect(o),a.connect(r),t.current=o,function(){o.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function _t(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,v=t?.length??e.sourceDurationSamples??(u&&d?Math.ceil(u.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(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 p=e.durationSamples??v;return{id:Ln(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:a,sampleRate:d,sourceDurationSamples:v,gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function _o(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===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 p=e.duration??v;return _t({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(p*d),offsetSamples:Math.round(a*d),sampleRate:d,sourceDurationSamples:Math.ceil(v*d),gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Fo(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Ln(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:o,color:l,height:c}}function Ln(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Zo(e,t={}){const{progressive:n=!1}=t,[a,r]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),v=e.length;return i.useEffect(()=>{if(e.length===0){r([]),o(!1),d(0);return}let p=!1;const f=new Map,C=(m,g,I)=>{const x=I??m.audioBuffer;if(!x&&!m.waveformData)throw new Error(`Track ${g+1}: Must provide src, audioBuffer, or waveformData`);const h=x?.duration??m.waveformData?.duration,w=_o({audioBuffer:x,startTime:m.startTime??0,duration:m.duration??h,offset:m.offset??0,name:m.name||`Track ${g+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(w.startSample)||isNaN(w.durationSamples)||isNaN(w.offsetSamples))throw console.error("Invalid clip values:",w),new Error(`Invalid clip values for track ${g+1}`);return{...Fo({name:m.name||`Track ${g+1}`,clips:[w],muted:m.muted??!1,soloed:m.soloed??!1,volume:m.volume??1,pan:m.pan??0,color:m.color}),effects:m.effects}};return(async()=>{try{o(!0),c(null),d(0);const m=pn.getContext().rawContext,g=e.map(async(x,h)=>{if(x.audioBuffer){const $=C(x,h,x.audioBuffer);return n&&!p&&(f.set(h,$),d(E=>E+1),r(Array.from({length:e.length},(E,R)=>f.get(R)).filter(E=>E!==void 0))),$}if(!x.src&&x.waveformData){const $=C(x,h);return n&&!p&&(f.set(h,$),d(E=>E+1),r(Array.from({length:e.length},(E,R)=>f.get(R)).filter(E=>E!==void 0))),$}if(!x.src)throw new Error(`Track ${h+1}: Must provide src, audioBuffer, or waveformData`);const w=await fetch(x.src);if(!w.ok)throw new Error(`Failed to fetch ${x.src}: ${w.statusText}`);const k=await w.arrayBuffer(),A=await m.decodeAudioData(k);if(!A||!A.sampleRate||!A.duration)throw new Error(`Invalid audio buffer for ${x.src}`);const M=C(x,h,A);return n&&!p&&(f.set(h,M),d($=>$+1),r(Array.from({length:e.length},($,E)=>f.get(E)).filter($=>$!==void 0))),M}),I=await Promise.all(g);p||(n||(r(I),d(I.length)),o(!1))}catch(m){if(!p){const g=m instanceof Error?m.message:"Unknown error loading audio";c(g),o(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{p=!0}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:v}}function Vo({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=i.useRef(null),s=i.useCallback(u=>{const{transform:d,active:v}=u;if(!v?.data?.current)return{...d,scaleX:1,scaleY:1};const{trackIndex:p,clipIndex:f,boundary:C}=v.data.current;if(C)return{...d,scaleX:1,scaleY:1};const y=e[p];if(!y)return{...d,scaleX:1,scaleY:1};const m=y.clips[f];if(!m)return{...d,scaleX:1,scaleY:1};const g=m.startSample/a,I=m.durationSamples/a,x=d.x*n/a;let h=g+x;const w=[...y.clips].sort((R,T)=>R.startSample-T.startSample),k=w.findIndex(R=>R===m);h=Math.max(0,h);const A=k>0?w[k-1]:null;if(A){const R=(A.startSample+A.durationSamples)/a;h=Math.max(h,R)}const M=k<w.length-1?w[k+1]:null;if(M){const R=h+I,T=M.startSample/a;R>T&&(h=T-I)}const E=(h-g)*a/n;return{...d,x:E,scaleX:1,scaleY:1}},[e,n,a]),o=i.useCallback(u=>{const{active:d}=u,{boundary:v}=d.data.current;if(!v){r.current=null;return}const{trackIndex:p,clipIndex:f}=d.data.current,y=e[p]?.clips[f];y&&(r.current={offsetSamples:y.offsetSamples,durationSamples:y.durationSamples,startSample:y.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:v}=u,{boundary:p}=d.data.current;if(!p||!r.current)return;const{trackIndex:f,clipIndex:C}=d.data.current,y=v.x*n,m=Math.floor(.1*a),g=r.current,I=e.map((x,h)=>{if(h!==f)return x;const w=[...x.clips].sort((M,$)=>M.startSample-$.startSample),k=w.findIndex(M=>M===x.clips[C]),A=x.clips.map((M,$)=>{if($!==C)return M;const E=M.sourceDurationSamples;if(p==="left"){let R=Math.floor(y);const T=-g.startSample;R<T&&(R=T);const D=-g.offsetSamples;R<D&&(R=D);const P=k>0?w[k-1]:null;if(P){const U=P.startSample+P.durationSamples-g.startSample;R<U&&(R=U)}const V=g.durationSamples-m;R>V&&(R=V);const F=g.offsetSamples+R,N=g.durationSamples-R,H=g.startSample+R;return{...M,offsetSamples:F,durationSamples:N,startSample:H}}else{let R=Math.floor(g.durationSamples+y);R=Math.max(m,R),g.offsetSamples+R>E&&(R=E-g.offsetSamples);const T=k<w.length-1?w[k+1]:null;return T&&g.startSample+R>T.startSample&&(R=T.startSample-g.startSample,R=Math.max(m,R)),{...M,durationSamples:R}}});return{...x,clips:A}});t(I)},[e,t,n,a]),c=i.useCallback(u=>{const{active:d,delta:v}=u,{trackIndex:p,clipIndex:f,boundary:C}=d.data.current,y=v.x*n;if(C){r.current=null;return}const m=e.map((g,I)=>{if(I!==p)return g;const x=[...g.clips].sort((k,A)=>k.startSample-A.startSample),h=x.findIndex(k=>k===g.clips[f]),w=g.clips.map((k,A)=>{if(A!==f)return k;let M=Math.floor(k.startSample+y);M=Math.max(0,M);const $=h>0?x[h-1]:null;if($){const R=$.startSample+$.durationSamples;M=Math.max(M,R)}const E=h<x.length-1?x[h+1]:null;return E&&M+k.durationSamples>E.startSample&&(M=E.startSample-k.durationSamples),{...k,startSample:M}});return{...g,clips:w}});t(m)},[e,t,n,a]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Dt=.01;function Yn({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:v}=d,p=v.data.current;if(!p||p.annotationIndex===void 0){o.current=null;return}const f=e[p.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:p.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:v,delta:p}=d;if(!o.current)return;const f=v.data.current;if(!f)return;const{edge:C,annotationIndex:y}=f,m=o.current,g=p.x*n/a,I=C==="start"?m.start+g:m.end+g,x=Po({annotationIndex:y,newTime:I,isDraggingStart:C==="start",annotations:e,duration:r,linkEndpoints:s});t(x)},[e,t,n,a,r,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Po({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const o=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<Dt?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<Dt){const v=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,v)};let p=e+1;for(;p<o.length-1;){const f=o[p],C=o[p+1];if(Math.abs(C.start-f.end)<Dt){const y=f.end-a[p].end;o[p+1]={...C,start:Math.min(C.end-.1,C.start+y)},p++}else break}}else c>=d.start&&(o[e]={...o[e],end:d.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const d=o[e+1];o[e+1]={...d,start:c};let v=e+1;for(;v<o.length-1;){const p=o[v],f=o[v+1];if(p.end>f.start)o[v+1]={...f,start:p.end},v++;else break}}}return o}function zo(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Ee.useSensor(Ee.MouseSensor,{activationConstraint:{distance:r}}),o=Ee.useSensor(Ee.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Ee.useSensor(Ee.PointerSensor,{activationConstraint:{distance:r}});return Ee.useSensors(...t?[s,o]:[l])}const jo=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=$e(),{selectedTrackId:s}=Te(),o=i.useCallback((c,u,d)=>{const{sampleRate:v,samplesPerPixel:p}=e,f=t[c];if(!f)return!1;const C=f.clips[u];if(!C)return!1;const y=C.startSample/v,m=(C.startSample+C.durationSamples)/v;if(d<=y||d>=m)return console.warn("Split time is outside clip bounds"),!1;const g=Math.round(d*v),I=Math.floor(g/p),x=C.startSample+C.durationSamples,h=I*p,w=C.startSample,k=h-w,A=h,M=x-A,$=h-C.startSample,E=_t({audioBuffer:C.audioBuffer,startSample:w,durationSamples:k,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}),R=_t({audioBuffer:C.audioBuffer,startSample:A,durationSamples:M,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}),T=[...f.clips];T.splice(u,1,E,R);const D=[...t];return D[c]={...f,clips:T},n(D),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(v=>v.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],d=r.current??0;for(let v=0;v<u.clips.length;v++){const p=u.clips[v],f=p.startSample/a,C=(p.startSample+p.durationSamples)/a;if(d>f&&d<C)return console.log(`Splitting clip on track "${u.name}" at ${d}s`),o(c,v,d)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,o,a]),splitClipAt:o}},vt=e=>{const{shortcuts:t,enabled:n=!0}=e,a=i.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||r.shiftKey===l.shiftKey,v=l.metaKey===void 0||r.metaKey===l.metaKey,p=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&d&&v&&p});o&&(o.preventDefault!==!1&&r.preventDefault(),o.action())},[t,n]);i.useEffect(()=>{if(n)return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[a,n])},Ho=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("+")},Xo=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=$e(),{setCurrentTime:s,play:o,pause:l,stop:c}=he(),{playoutRef:u}=ke(),d=i.useCallback(()=>{r?l():o()},[r,o,l]),v=i.useCallback(()=>{c()},[c]),p=i.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[r,u,s,o]),C=a??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:v,description:"Stop",preventDefault:!0},{key:"0",action:p,description:"Rewind to start",preventDefault:!0}],...n];return vt({shortcuts:C,enabled:t}),{rewindToStart:p,togglePlayPause:d,stopPlayback:v,shortcuts:C}},Bt=.01,ht=.01;function Go({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:v=0,onPlay:p}){const f=i.useMemo(()=>t?e.findIndex($=>$.id===t):-1,[e,t]),C=i.useCallback($=>{if(!c?.current||!u||!d)return;const E=e.find(Z=>Z.id===$);if(!E)return;const R=c.current,T=R.clientWidth,D=E.start*d/u+v,P=E.end*d/u+v,V=(D+P)/2,F=R.scrollLeft,N=F,H=F+T;if(D<N||P>H){const Z=Math.max(0,V-T/2);R.scrollTo({left:Z,behavior:"smooth"})}},[e,c,u,d,v]);i.useEffect(()=>{t&&c?.current&&u&&d&&C(t)},[t,C,c,u,d]);const y=i.useCallback($=>{if(f<0)return;const E=e[f],R=Math.max(0,Math.min(E.end-.1,E.start+$)),T=R-E.start,D=[...e];if(D[f]={...E,start:R},s&&f>0){const P=D[f-1];Math.abs(P.end-E.start)<Bt&&(D[f-1]={...P,end:Math.max(P.start+.1,P.end+T)})}else if(!s&&f>0){const P=D[f-1];R<P.end&&(D[f-1]={...P,end:R})}n(D)},[e,f,s,n]),m=i.useCallback($=>{if(f<0)return;const E=e[f],R=Math.max(E.start+.1,Math.min(r,E.end+$)),T=R-E.end,D=[...e];if(D[f]={...E,end:R},s&&f<e.length-1){const P=D[f+1];if(Math.abs(P.start-E.end)<Bt){const V=Math.min(P.end-.1,P.start+T);D[f+1]={...P,start:V};let F=f+1;for(;F<D.length-1;){const N=D[F],H=D[F+1];if(Math.abs(H.start-e[F].end)<Bt){const Z=N.end-e[F].end;D[F+1]={...H,start:Math.min(H.end-.1,H.start+Z)},F++}else break}}}else if(!s&&f<e.length-1){const P=D[f+1];if(R>P.start){D[f+1]={...P,start:R};let V=f+1;for(;V<D.length-1;){const F=D[V],N=D[V+1];if(F.end>N.start)D[V+1]={...N,start:F.end},V++;else break}}}n(D)},[e,f,r,s,n]),g=i.useCallback(()=>{!a||e.length===0||(f<=0?a(e[e.length-1].id):a(e[f-1].id))},[e,f,a]),I=i.useCallback(()=>{!a||e.length===0||(f<0||f>=e.length-1?a(e[0].id):a(e[f+1].id))},[e,f,a]),x=i.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),h=i.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),w=i.useCallback(()=>{a&&a(null)},[a]),k=i.useCallback(()=>{if(f<0||!p)return;const $=e[f],E=o?void 0:$.end-$.start;p($.start,E)},[e,f,o,p]),A=i.useMemo(()=>[{key:"[",action:()=>y(-ht),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>y(ht),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>m(-ht),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>m(ht),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:k,description:"Play selected annotation",preventDefault:!0}],[y,m,k]),M=i.useMemo(()=>[{key:"ArrowUp",action:g,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:g,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:I,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:I,description:"Select next annotation",preventDefault:!0},{key:"Home",action:x,description:"Select first annotation",preventDefault:!0},{key:"End",action:h,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:w,description:"Deselect annotation",preventDefault:!0}],[g,I,x,h,w]);return vt({shortcuts:A,enabled:l&&f>=0}),vt({shortcuts:M,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:y,moveEndBoundary:m,selectPrevious:g,selectNext:I,selectFirst:x,selectLast:h,clearSelection:w,scrollToAnnotation:C,playActiveAnnotation:k}}function No(e){const t=e.reduce((r,s)=>r+s.length,0),n=new Float32Array(t);let a=0;for(const r of e)n.set(r,a),a+=r.length;return n}function Lo(e,t,n,a=1){const r=e.createBuffer(a,t.length,n),s=new Float32Array(t);return r.copyToChannel(s,0),r}function cn(e,t,n=16){const a=Math.ceil(e.length/t),r=n===8?new Int8Array(a*2):new Int16Array(a*2),s=2**(n-1);for(let o=0;o<a;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,d=0;for(let v=l;v<c;v++){const p=e[v];p<u&&(u=p),p>d&&(d=p)}r[o*2]=Math.floor(u*s),r[o*2+1]=Math.floor(d*s)}return r}function Yo(e,t,n,a,r=16){const s=2**(r-1),o=a%n;let l=0;if(o>0&&e.length>0){const d=n-o,v=Math.min(d,t.length);let p=e[e.length-2]/s,f=e[e.length-1]/s;for(let g=0;g<v;g++){const I=t[g];I<p&&(p=I),I>f&&(f=I)}const C=new(r===8?Int8Array:Int16Array)(e.length);C.set(e),C[e.length-2]=Math.floor(p*s),C[e.length-1]=Math.floor(f*s),l=v;const y=cn(t.slice(l),n,r),m=new(r===8?Int8Array:Int16Array)(C.length+y.length);return m.set(C),m.set(y,C.length),m}const c=cn(t.slice(l),n,r),u=new(r===8?Int8Array:Int16Array)(e.length+c.length);return u.set(e),u.set(c,e.length),u}function Oo(e,t={}){const{channelCount:n=1,samplesPerPixel:a=1024}=t,[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[d,v]=i.useState(new Int16Array(0)),[p,f]=i.useState(null),[C,y]=i.useState(null),[m,g]=i.useState(0),[I,x]=i.useState(0),h=16,w=i.useRef(!1),k=i.useRef(null),A=i.useRef(null),M=i.useRef([]),$=i.useRef(0),E=i.useRef(null),R=i.useRef(0),T=i.useRef(!1),D=i.useRef(!1),P=i.useCallback(async()=>{if(!w.current)try{const Z=W.getContext(),U=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Rt&&Rt.tagName.toUpperCase()==="SCRIPT"&&Rt.src||new URL("index.js",document.baseURI).href).href;await Z.addAudioWorkletModule(U),w.current=!0}catch(Z){throw console.error("Failed to load AudioWorklet module:",Z),new Error("Failed to load recording processor")}},[]),V=i.useCallback(async()=>{if(!e){y(new Error("No microphone stream available"));return}try{y(null);const Z=W.getContext();Z.state==="suspended"&&await Z.resume(),await P();const U=Z.createMediaStreamSource(e);A.current=U;const re=Z.createAudioWorkletNode("recording-processor");k.current=re,U.connect(re),re.port.onmessage=q=>{const{samples:ae}=q.data;M.current.push(ae),$.current+=ae.length,v(be=>Yo(be,ae,a,$.current-ae.length,h))},re.port.postMessage({command:"start",sampleRate:Z.sampleRate,channelCount:n}),M.current=[],$.current=0,v(new Int16Array(0)),f(null),g(0),x(0),T.current=!0,D.current=!1,s(!0),l(!1),R.current=performance.now();const ne=()=>{if(T.current&&!D.current){const q=(performance.now()-R.current)/1e3;u(q),E.current=requestAnimationFrame(ne)}};ne()}catch(Z){console.error("Failed to start recording:",Z),y(Z instanceof Error?Z:new Error("Failed to start recording"))}},[e,n,a,P,r,o]),F=i.useCallback(async()=>{if(!r)return null;try{if(k.current){if(k.current.port.postMessage({command:"stop"}),A.current)try{A.current.disconnect(k.current)}catch{}k.current.disconnect()}E.current!==null&&(cancelAnimationFrame(E.current),E.current=null);const Z=No(M.current),re=W.getContext().rawContext,ne=Lo(re,Z,re.sampleRate,n);return f(ne),u(ne.duration),T.current=!1,D.current=!1,s(!1),l(!1),g(0),ne}catch(Z){return console.error("Failed to stop recording:",Z),y(Z instanceof Error?Z:new Error("Failed to stop recording")),null}},[r,n]),N=i.useCallback(()=>{r&&!o&&(E.current!==null&&(cancelAnimationFrame(E.current),E.current=null),D.current=!0,l(!0))},[r,o]),H=i.useCallback(()=>{if(r&&o){D.current=!1,l(!1),R.current=performance.now()-c*1e3;const Z=()=>{if(T.current&&!D.current){const U=(performance.now()-R.current)/1e3;u(U),E.current=requestAnimationFrame(Z)}};Z()}},[r,o,c]);return i.useEffect(()=>()=>{if(k.current){if(k.current.port.postMessage({command:"stop"}),A.current)try{A.current.disconnect(k.current)}catch{}k.current.disconnect()}E.current!==null&&cancelAnimationFrame(E.current)},[]),{isRecording:r,isPaused:o,duration:c,peaks:d,audioBuffer:p,level:m,peakLevel:I,startRecording:V,stopRecording:F,pauseRecording:N,resumeRecording:H,error:C}}function Ko(){const[e,t]=i.useState(null),[n,a]=i.useState([]),[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),d=i.useCallback(async()=>{try{const C=(await navigator.mediaDevices.enumerateDevices()).filter(y=>y.kind==="audioinput").map(y=>({deviceId:y.deviceId,label:y.label||`Microphone ${y.deviceId.slice(0,8)}`,groupId:y.groupId}));a(C)}catch(f){console.error("Failed to enumerate devices:",f),u(f instanceof Error?f:new Error("Failed to enumerate devices"))}},[]),v=i.useCallback(async(f,C)=>{l(!0),u(null);try{e&&e.getTracks().forEach(I=>I.stop());const m={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...C,...f&&{deviceId:{exact:f}}},video:!1},g=await navigator.mediaDevices.getUserMedia(m);t(g),s(!0),await d()}catch(y){console.error("Failed to access microphone:",y),u(y instanceof Error?y:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,d]),p=i.useCallback(()=>{e&&(e.getTracks().forEach(f=>f.stop()),t(null),s(!1))},[e]);return i.useEffect(()=>(d(),()=>{e&&e.getTracks().forEach(f=>f.stop())}),[]),{stream:e,devices:n,hasPermission:r,isLoading:o,requestAccess:v,stopStream:p,error:c}}function Uo(e,t={}){const{updateRate:n=60,smoothingTimeConstant:a=.8}=t,[r,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),d=i.useRef(null),v=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let p=!0;return(async()=>{if(!p)return;const C=W.getContext();if(C.state==="suspended"&&await C.resume(),!p)return;const y=new W.Meter({smoothing:a,context:C});c.current=y;const m=C.createMediaStreamSource(e);u.current=m,W.connect(m,y);const g=1e3/n;let I=0;const x=h=>{if(!(!p||!c.current)){if(h-I>=g){I=h;const w=c.current.getValue(),k=typeof w=="number"?w:w[0],A=Math.max(0,Math.min(1,(k+100)/100));s(A),l(M=>Math.max(M,A))}d.current=requestAnimationFrame(x)}};d.current=requestAnimationFrame(x)})(),()=>{if(p=!1,d.current&&(cancelAnimationFrame(d.current),d.current=null),u.current){try{u.current.disconnect()}catch{}u.current=null}c.current&&(c.current.dispose(),c.current=null)}},[e,a,n]),{level:r,peakLevel:o,resetPeak:v}}S.button`
1067
1067
  padding: 0.5rem 1rem;
1068
1068
  font-size: 0.875rem;
1069
1069
  font-weight: 500;
@@ -1093,7 +1093,7 @@
1093
1093
  outline: none;
1094
1094
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.3);
1095
1095
  }
1096
- `;A.span`
1096
+ `;S.span`
1097
1097
  display: inline-block;
1098
1098
  width: 8px;
1099
1099
  height: 8px;
@@ -1111,13 +1111,13 @@
1111
1111
  opacity: 0.3;
1112
1112
  }
1113
1113
  }
1114
- `;A(Vt)`
1114
+ `;S(Vt)`
1115
1115
  min-width: 200px;
1116
- `;A(xn)`
1116
+ `;S(xn)`
1117
1117
  display: flex;
1118
1118
  flex-direction: column;
1119
1119
  gap: 0.25rem;
1120
- `;A.div`
1120
+ `;S.div`
1121
1121
  display: flex;
1122
1122
  align-items: center;
1123
1123
  gap: 0.75rem;
@@ -1125,7 +1125,7 @@
1125
1125
  background: ${e=>e.$isRecording?"#fff3cd":"transparent"};
1126
1126
  border-radius: 0.25rem;
1127
1127
  transition: background 0.2s ease-in-out;
1128
- `;A.div`
1128
+ `;S.div`
1129
1129
  width: 12px;
1130
1130
  height: 12px;
1131
1131
  border-radius: 50%;
@@ -1145,18 +1145,18 @@
1145
1145
  }
1146
1146
  }
1147
1147
  `}
1148
- `;A.span`
1148
+ `;S.span`
1149
1149
  font-family: 'Courier New', Monaco, monospace;
1150
1150
  font-size: 1rem;
1151
1151
  font-weight: 600;
1152
1152
  color: #495057;
1153
1153
  min-width: 70px;
1154
- `;A.span`
1154
+ `;S.span`
1155
1155
  font-size: 0.75rem;
1156
1156
  font-weight: 500;
1157
1157
  color: ${e=>e.$isPaused?"#ffc107":"#dc3545"};
1158
1158
  text-transform: uppercase;
1159
- `;var Jo=A.div`
1159
+ `;var Jo=S.div`
1160
1160
  position: relative;
1161
1161
  width: ${e=>e.$width}px;
1162
1162
  height: ${e=>e.$height}px;
@@ -1164,39 +1164,39 @@
1164
1164
  border-radius: 4px;
1165
1165
  overflow: hidden;
1166
1166
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
1167
- `,qo=e=>e<.6?"linear-gradient(90deg, #27ae60, #2ecc71)":e<.85?"linear-gradient(90deg, #f39c12, #f1c40f)":"linear-gradient(90deg, #c0392b, #e74c3c)",Qo=A.div.attrs(e=>({style:{width:`${e.$level*100}%`,height:`${e.$height}px`,background:qo(e.$level),boxShadow:e.$level>.01?"0 0 8px rgba(255, 255, 255, 0.3)":"none"}}))`
1167
+ `,qo=e=>e<.6?"linear-gradient(90deg, #27ae60, #2ecc71)":e<.85?"linear-gradient(90deg, #f39c12, #f1c40f)":"linear-gradient(90deg, #c0392b, #e74c3c)",Qo=S.div.attrs(e=>({style:{width:`${e.$level*100}%`,height:`${e.$height}px`,background:qo(e.$level),boxShadow:e.$level>.01?"0 0 8px rgba(255, 255, 255, 0.3)":"none"}}))`
1168
1168
  position: absolute;
1169
1169
  left: 0;
1170
1170
  top: 0;
1171
1171
  transition: width 0.05s ease-out, background 0.1s ease-out;
1172
- `,es=A.div.attrs(e=>({style:{left:`${e.$peakLevel*100}%`,height:`${e.$height}px`}}))`
1172
+ `,es=S.div.attrs(e=>({style:{left:`${e.$peakLevel*100}%`,height:`${e.$height}px`}}))`
1173
1173
  position: absolute;
1174
1174
  top: 0;
1175
1175
  width: 2px;
1176
1176
  background: #ecf0f1;
1177
1177
  box-shadow: 0 0 4px rgba(236, 240, 241, 0.8);
1178
1178
  transition: left 0.1s ease-out;
1179
- `,ts=A.div`
1179
+ `,ts=S.div`
1180
1180
  position: absolute;
1181
1181
  top: 0;
1182
1182
  left: 0;
1183
1183
  width: 100%;
1184
1184
  height: ${e=>e.$height}px;
1185
1185
  pointer-events: none;
1186
- `,un=A.div`
1186
+ `,un=S.div`
1187
1187
  position: absolute;
1188
1188
  left: ${e=>e.$position}%;
1189
1189
  top: 0;
1190
1190
  width: 1px;
1191
1191
  height: ${e=>e.$height}px;
1192
1192
  background: rgba(255, 255, 255, 0.2);
1193
- `,ns=({level:e,peakLevel:t,width:n=200,height:r=20,className:a})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return v.jsxs(Jo,{$width:n,$height:r,className:a,children:[v.jsx(Qo,{$level:s,$height:r}),t!==void 0&&o>0&&v.jsx(es,{$peakLevel:o,$height:r}),v.jsxs(ts,{$height:r,children:[v.jsx(un,{$position:60,$height:r}),v.jsx(un,{$position:85,$height:r})]})]})};i.memo(ns);function rs(e,t,n,r={}){const{currentTime:a=0,audioConstraints:s,...o}=r,[l,c]=i.useState(!1),[u,d]=i.useState(null),{stream:x,devices:g,hasPermission:f,requestAccess:C,error:w}=Ko(),{level:h,peakLevel:b}=Uo(x),{isRecording:I,isPaused:p,duration:m,peaks:y,startRecording:k,stopRecording:S,pauseRecording:$,resumeRecording:E,error:R}=Oo(x,o),M=i.useCallback(async()=>{n&&(l||(await Et(),c(!0)),await k())},[n,l,k]),B=i.useCallback(async()=>{const V=await S();if(V&&n){const F=e.findIndex(Q=>Q.id===n);if(F===-1)return;const K=e[F],H=Math.floor(a*V.sampleRate);let Z=0;if(K.clips.length>0){const Q=K.clips.map(re=>re.startSample+re.durationSamples);Z=Math.max(...Q)}const L=Math.max(H,Z),ae={id:`clip-${Date.now()}`,audioBuffer:V,startSample:L,durationSamples:V.length,offsetSamples:0,sampleRate:V.sampleRate,sourceDurationSamples:V.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},ne=e.map((Q,re)=>re===F?{...Q,clips:[...Q.clips,ae]}:Q);t(ne)}},[n,e,t,a,S]);i.useEffect(()=>{f&&g.length>0&&u===null&&d(g[0].deviceId)},[f,g.length]);const D=i.useCallback(async()=>{await C(void 0,s),await Et(),c(!0)},[C,s]),z=i.useCallback(async V=>{d(V),await C(V,s),await Et(),c(!0)},[C,s]);return{isRecording:I,isPaused:p,duration:m,level:h,peakLevel:b,error:w||R,stream:x,devices:g,hasPermission:f,selectedDevice:u,startRecording:M,stopRecording:B,pauseRecording:$,resumeRecording:E,requestMicAccess:D,changeDevice:z,recordingPeaks:y}}const lt=[{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}]}],Ht=e=>lt.find(t=>t.id===e),as=e=>lt.filter(t=>t.category===e),os=[{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"}],ss={reverb:W.Reverb,freeverb:W.Freeverb,jcReverb:W.JCReverb,feedbackDelay:W.FeedbackDelay,pingPongDelay:W.PingPongDelay,chorus:W.Chorus,phaser:W.Phaser,tremolo:W.Tremolo,vibrato:W.Vibrato,autoPanner:W.AutoPanner,autoFilter:W.AutoFilter,autoWah:W.AutoWah,eq3:W.EQ3,distortion:W.Distortion,bitCrusher:W.BitCrusher,chebyshev:W.Chebyshev,compressor:W.Compressor,limiter:W.Limiter,gate:W.Gate,stereoWidener:W.StereoWidener};let is=0;const ls=()=>`effect_${Date.now()}_${++is}`;function ot(e,t){const n=ss[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const r={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;r[o.name]=l});const a=new n(r),s=ls();return{effect:a,id:e.id,instanceId:s,dispose(){try{a.disconnect(),a.dispose()}catch{}},setParameter(o,l){o==="wet"&&a.wet?a.wet.value=l:a[o]!==void 0&&(a[o]?.value!==void 0?a[o].value=l:a[o]=l)},getParameter(o){if(o==="wet"&&a.wet)return a.wet.value;if(a[o]!==void 0)return a[o]?.value!==void 0?a[o].value:a[o]},connect(o){a.connect(o)},disconnect(){try{a.disconnect()}catch{}}}}function cs(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 us(e=256){const[t,n]=i.useState([]),r=i.useRef(t);r.current=t;const a=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(h=>{const b=o.current;if(!b)return;const{masterGainNode:I,destination:p,analyserNode:m}=b;try{I.disconnect()}catch{}const y=h.map(k=>a.current.get(k.instanceId)).filter(k=>k!==void 0);if(y.length===0)I.connect(m),m.connect(p);else{let k=I;y.forEach(S=>{try{S.disconnect()}catch{}k.connect(S.effect),k=S.effect}),k.connect(m),m.connect(p)}},[]),c=i.useCallback(h=>{const b=Ht(h);if(!b){console.error(`Unknown effect: ${h}`);return}const I={};b.parameters.forEach(y=>{I[y.name]=y.default});const p=ot(b,I);a.current.set(p.instanceId,p);const m={instanceId:p.instanceId,effectId:b.id,definition:b,params:I,bypassed:!1};n(y=>[...y,m])},[]),u=i.useCallback(h=>{const b=a.current.get(h);b&&(b.dispose(),a.current.delete(h)),n(I=>I.filter(p=>p.instanceId!==h))},[]),d=i.useCallback((h,b,I)=>{const p=a.current.get(h);p&&p.setParameter(b,I),n(m=>m.map(y=>y.instanceId===h?{...y,params:{...y.params,[b]:I}}:y))},[]),x=i.useCallback(h=>{const b=r.current.find(m=>m.instanceId===h);if(!b)return;const I=!b.bypassed,p=a.current.get(h);if(p){const m=b.params.wet??1;p.setParameter("wet",I?0:m)}n(m=>m.map(y=>y.instanceId===h?{...y,bypassed:I}:y))},[]),g=i.useCallback((h,b)=>{n(I=>{const p=[...I],[m]=p.splice(h,1);return p.splice(b,0,m),p})},[]),f=i.useCallback(()=>{a.current.forEach(h=>h.dispose()),a.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const C=i.useCallback((h,b,I)=>{const p=new W.Analyser("fft",e);s.current=p,o.current={masterGainNode:h,destination:b,analyserNode:p};const y=r.current.map(k=>a.current.get(k.instanceId)).filter(k=>k!==void 0);if(y.length===0)h.connect(p),p.connect(b);else{let k=h;y.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(p),p.connect(b)}return function(){p.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{a.current.forEach(h=>h.dispose()),a.current.clear()},[]);const w=i.useCallback(()=>{const h=t.filter(b=>!b.bypassed);if(h.length!==0)return(b,I,p)=>{const m=[];for(const y of h){const k=ot(y.definition,y.params);m.push(k)}if(m.length===0)b.connect(I);else{let y=b;m.forEach(k=>{y.connect(k.effect),y=k.effect}),y.connect(I)}return function(){m.forEach(k=>k.dispose())}}},[t]);return{activeEffects:t,availableEffects:lt,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:x,reorderEffects:g,clearAllEffects:f,masterEffects:C,createOfflineEffectsFunction:w,analyserRef:s}}function ds(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),r=i.useRef(new Map),a=i.useCallback((f,C)=>{const w=r.current.get(f);if(!w)return;const{graphEnd:h,masterGainNode:b}=w,I=n.current.get(f);try{h.disconnect()}catch{}const p=C.map(m=>I?.get(m.instanceId)).filter(m=>m!==void 0);if(p.length===0)h.connect(b);else{let m=h;p.forEach(y=>{try{y.disconnect()}catch{}m.connect(y.effect),m=y.effect}),m.connect(b)}},[]),s=i.useCallback((f,C)=>{const w=Ht(C);if(!w){console.error(`Unknown effect: ${C}`);return}const h={};w.parameters.forEach(p=>{h[p.name]=p.default});const b=ot(w,h);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(b.instanceId,b);const I={instanceId:b.instanceId,effectId:w.id,definition:w,params:h,bypassed:!1};t(p=>{const m=new Map(p),y=m.get(f)||[];return m.set(f,[...y,I]),m})},[]),o=i.useCallback((f,C)=>{const w=n.current.get(f),h=w?.get(C);h&&(h.dispose(),w?.delete(C)),t(b=>{const I=new Map(b),p=I.get(f)||[];return I.set(f,p.filter(m=>m.instanceId!==C)),I})},[]),l=i.useCallback((f,C,w,h)=>{const I=n.current.get(f)?.get(C);I&&I.setParameter(w,h),t(p=>{const m=new Map(p),y=m.get(f)||[];return m.set(f,y.map(k=>k.instanceId===C?{...k,params:{...k.params,[w]:h}}:k)),m})},[]),c=i.useCallback((f,C)=>{const h=(d.current.get(f)||[]).find(m=>m.instanceId===C);if(!h)return;const b=!h.bypassed,p=n.current.get(f)?.get(C);if(p){const m=h.params.wet??1;p.setParameter("wet",b?0:m)}t(m=>{const y=new Map(m),k=y.get(f)||[];return y.set(f,k.map(S=>S.instanceId===C?{...S,bypassed:b}:S)),y})},[]),u=i.useCallback(f=>{const C=n.current.get(f);C&&(C.forEach(w=>w.dispose()),C.clear()),t(w=>{const h=new Map(w);return h.set(f,[]),h})},[]),d=i.useRef(e);d.current=e;const x=i.useCallback(f=>(C,w,h)=>{r.current.set(f,{graphEnd:C,masterGainNode:w});const b=d.current.get(f)||[],I=n.current.get(f),p=b.map(m=>I?.get(m.instanceId)).filter(m=>m!==void 0);if(p.length===0)C.connect(w);else{let m=C;p.forEach(y=>{m.connect(y.effect),m=y.effect}),m.connect(w)}return function(){r.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,C)=>{a(C,f)})},[e,a]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(C=>C.dispose()),f.clear()}),n.current.clear()},[]);const g=i.useCallback(f=>{const w=(e.get(f)||[]).filter(h=>!h.bypassed);if(w.length!==0)return(h,b,I)=>{const p=[];for(const m of w){const y=ot(m.definition,m.params);p.push(y)}if(p.length===0)h.connect(b);else{let m=h;p.forEach(y=>{m.connect(y.effect),m=y.effect}),m.connect(b)}return function(){p.forEach(y=>y.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:x,createOfflineTrackEffectsFunction:g,availableEffects:lt}}function fs(e,t={}){const{bitDepth:n=16}=t,r=e.numberOfChannels,a=e.sampleRate,s=e.length,o=n/8,l=r*o,c=a*l,u=s*l,d=44,x=d+u,g=new ArrayBuffer(x),f=new DataView(g);ht(f,0,"RIFF"),f.setUint32(4,x-8,!0),ht(f,8,"WAVE"),ht(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,n===32?3:1,!0),f.setUint16(22,r,!0),f.setUint32(24,a,!0),f.setUint32(28,c,!0),f.setUint16(32,l,!0),f.setUint16(34,n,!0),ht(f,36,"data"),f.setUint32(40,u,!0);const C=[];for(let h=0;h<r;h++)C.push(e.getChannelData(h));let w=d;if(n===16)for(let h=0;h<s;h++)for(let b=0;b<r;b++){const I=C[b][h],p=Math.max(-1,Math.min(1,I)),m=p<0?p*32768:p*32767;f.setInt16(w,m,!0),w+=2}else for(let h=0;h<s;h++)for(let b=0;b<r;b++)f.setFloat32(w,C[b][h],!0),w+=4;return new Blob([g],{type:"audio/wav"})}function ht(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}function ms(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function On(){const[e,t]=i.useState(!1),[n,r]=i.useState(0),[a,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:x="master",trackIndex:g,autoDownload:f=!0,applyEffects:C=!0,effectsFunction:w,createOfflineTrackEffects:h,bitDepth:b=16,onProgress:I}=u;t(!0),r(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(x==="individual"&&(g===void 0||g<0||g>=l.length))throw new Error("Invalid track index for individual export");const p=l[0].clips[0]?.sampleRate||44100;let m=0;for(const M of l)for(const B of M.clips){const D=B.startSample+B.durationSamples;m=Math.max(m,D)}m+=Math.round(p*.1);const y=m/p,k=x==="individual"?[{track:l[g],state:c[g],index:g}]:l.map((M,B)=>({track:M,state:c[B],index:B})),S=c.some(M=>M.soloed),$=!!h;let E;if((w||$)&&C)E=await hs(k,c,S,y,p,w,h,M=>{r(M),I?.(M)});else{const M=new OfflineAudioContext(2,m,p);let B=0;const D=k.reduce((z,{track:V})=>z+V.clips.length,0);for(const{track:z,state:V}of k)if(!(V.muted&&!V.soloed)&&!(S&&!V.soloed))for(const F of z.clips){await gs(M,F,V,p,C),B++;const K=B/D*.5;r(K),I?.(K)}r(.5),I?.(.5),E=await M.startRendering()}r(.9),I?.(.9);const R=fs(E,{bitDepth:b});if(r(1),I?.(1),f){const M=x==="individual"?`${d}_${l[g].name}`:d;ms(R,`${M}.wav`)}return{audioBuffer:E,blob:R,duration:y}}catch(p){const m=p instanceof Error?p.message:"Export failed";throw s(m),p}finally{t(!1)}},[]),isExporting:e,progress:n,error:a}}async function hs(e,t,n,r,a,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:x,Player:g,ToneAudioBuffer:f}=await import("tone");l(.1);let C;try{C=await c(async({transport:w,destination:h})=>{const b=new u(0);let I;s?I=s(b,h,!0):b.connect(h);for(const{track:p,state:m}of e){if(m.muted&&!m.soloed||n&&!m.soloed)continue;const y=new u(ps(m.volume)),k=new x(m.pan),S=new d(m.muted?0:1),$=o?.(p.id);$?$(S,b,!0):S.connect(b),k.connect(S),y.connect(k);for(const E of p.clips){const{audioBuffer:R,startSample:M,durationSamples:B,offsetSamples:D,gain:z,fadeIn:V,fadeOut:F}=E,K=M/a,H=B/a,Z=D/a,L=new f(R),ae=new g(L),ne=new d(z);if(ae.connect(ne),ne.connect(y),V){const Q=K,re=K+V.duration,be=ne.gain._param;be.setValueAtTime(0,Q),be.linearRampToValueAtTime(z,re)}if(F){const Q=K+H-F.duration,re=K+H,be=ne.gain._param;be.setValueAtTime(z,Q),be.linearRampToValueAtTime(0,re)}ae.start(K,Z,H)}}w.start(0)},r,2,a)}catch(w){throw w instanceof Error?w:new Error(`Tone.Offline rendering failed: ${String(w)}`)}return l(.9),C.get()}function ps(e){return 20*Math.log10(Math.max(e,1e-4))}async function gs(e,t,n,r,a){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:d,fadeOut:x}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const g=o/r,f=l/r,C=c/r,w=e.createBufferSource();w.buffer=s;const h=e.createGain(),b=u*n.volume,I=e.createStereoPanner();if(I.pan.value=n.pan,w.connect(h),h.connect(I),I.connect(e.destination),a){if(d?h.gain.setValueAtTime(0,g):h.gain.setValueAtTime(b,g),d){const p=g,m=g+d.duration;dn(h.gain,p,m,0,b,d.type||"linear")}if(x){const p=g+f-x.duration,m=g+f;(!d||d.duration<f-x.duration)&&h.gain.setValueAtTime(b,p),dn(h.gain,p,m,b,0,x.type||"linear")}}else h.gain.setValueAtTime(b,g);w.start(g,C,f)}function dn(e,t,n,r,a,s){const o=n-t;if(!(o<=0))switch(s){case"linear":e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n);break;case"exponential":const l=Math.max(r,1e-4),c=Math.max(a,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),a===0&&e.setValueAtTime(0,n);break;case"logarithmic":const u=fn(r,a,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=fn(r,a,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n)}}function fn(e,t,n,r){const a=new Float32Array(n),s=t-e;for(let o=0;o<n;o++){const l=o/(n-1);let c;r==="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),a[o]=e+s*c}return a}const Kn=i.createContext(null),Un=i.createContext(null),Jn=i.createContext(null),qn=i.createContext(null),Qn=i.createContext(null),bs=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:r=80,samplesPerPixel:a=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:x,onAnnotationUpdate:g,barWidth:f=1,barGap:C=0,progressBarWidth:w,children:h})=>{const b=w??f+C,[I,p]=i.useState([]),[m,y]=i.useState(null),[k,S]=i.useState(!1),[$,E]=i.useState(0),[R,M]=i.useState(0),[B,D]=i.useState([]),[z,V]=i.useState([]),[F,K]=i.useState([]),[H,Z]=i.useState(0),[L,ae]=i.useState(0),[ne,Q]=i.useState(null),[re,be]=i.useState(o),[ve,He]=i.useState(u?.isContinuousPlay??!1),[_e,Ae]=i.useState(u?.linkEndpoints??!0),[Y,ce]=i.useState(u?.editable??!1),[ee,q]=i.useState(!1),[de,Ce]=i.useState(0),[te,Fe]=i.useState(0),_=i.useRef(null),$e=i.useRef(0),ue=i.useRef(0),he=i.useRef(null),Je=i.useRef(F),O=i.useRef(0),U=i.useRef(0),se=i.useRef(null),xe=i.useRef(null),ze=i.useRef(!1),qe=i.useRef(u?.isContinuousPlay??!1),Xe=i.useRef(null),Ye=i.useRef(a),St=i.useRef(!1),X=i.useRef(0),J=i.useRef(0),oe=i.useRef(0),pe=i.useRef(0),{timeFormat:ke,setTimeFormat:Ze,formatTime:ie}=Xn(),Me=Gn({initialSamplesPerPixel:a,zoomLevels:s}),Ie=Me.samplesPerPixel,{masterVolume:Ne,setMasterVolume:Le}=Nn({playoutRef:_,initialVolume:1}),Qe=i.useCallback(T=>{qe.current=T,He(T)},[]),je=i.useCallback(T=>{Xe.current=T,y(T)},[]),At=i.useCallback(T=>{St.current=T,q(T)},[]),nt=i.useCallback((T,j)=>{oe.current=T,pe.current=j,Ce(T),Fe(j)},[]),sr=i.useCallback(()=>{const T=X.current,j=J.current;T!==j&&j>T&&nt(T,j)},[nt]),ir=i.useCallback(()=>{nt(0,0)},[nt]);i.useEffect(()=>{ze.current=re},[re]),i.useEffect(()=>{Je.current=F},[F]),i.useEffect(()=>{X.current=H,J.current=L},[H,L]),i.useEffect(()=>{if(!xe.current||!B.length)return;const T=xe.current,j=Ye.current,N=Ie;if(j===N)return;const le=c.show?c.width:0,P=T.clientWidth,Pe=T.scrollLeft+P/2-le,fe=B[0].sampleRate,Re=Pe*j/fe*fe/N,Ge=Math.max(0,Re+le-P/2);T.scrollLeft=Ge,Ye.current=N},[Ie,B,c]);const ct=i.useRef(null);i.useEffect(()=>{if(e.length===0){D([]),M(0),K([]),V([]),_.current&&(_.current.dispose(),_.current=null);return}const T=k,j=ue.current;return _.current&&T&&(_.current.stop(),he.current&&(cancelAnimationFrame(he.current),he.current=null),ct.current={position:j}),(async()=>{try{const le=[];e.forEach(fe=>{fe.clips.length>0&&fe.clips[0].audioBuffer&&le.push(fe.clips[0].audioBuffer)});let P=0;e.forEach(fe=>{fe.clips.forEach(we=>{const Re=we.sampleRate,ut=(we.startSample+we.durationSamples)/Re;P=Math.max(P,ut)})}),D(le),M(P),K(fe=>fe.length===e.length?fe.map((we,Re)=>({...we,name:e[Re].name})):e.map(we=>({name:we.name,muted:we.muted,soloed:we.soloed,volume:we.volume,pan:we.pan}))),_.current&&_.current.dispose();const ge=new Fr({effects:d}),Pe=Je.current;e.forEach((fe,we)=>{const Re=fe.clips.filter(Ge=>Ge.audioBuffer);if(Re.length>0){const Ge=Re[0].sampleRate,ut=Math.min(...Re.map(Ee=>Ee.startSample/Ge)),wr=Math.max(...Re.map(Ee=>(Ee.startSample+Ee.durationSamples)/Ge)),dt=Pe[we],yr={id:`track-${we}`,name:fe.name,gain:dt?.volume??fe.volume,muted:dt?.muted??fe.muted,soloed:dt?.soloed??fe.soloed,stereoPan:dt?.pan??fe.pan,startTime:ut,endTime:wr},kr=Re.map(Ee=>{const Mt=Ee.sampleRate;return{buffer:Ee.audioBuffer,startTime:Ee.startSample/Mt-ut,duration:Ee.durationSamples/Mt,offset:Ee.offsetSamples/Mt,fadeIn:Ee.fadeIn,fadeOut:Ee.fadeOut,gain:Ee.gain}});ge.addTrack({clips:kr,track:yr,effects:fe.effects})}}),ge.applyInitialSoloState(),_.current=ge,x?.()}catch(le){console.error("Error loading audio:",le)}})(),()=>{he.current&&cancelAnimationFrame(he.current),_.current&&_.current.dispose()}},[e,x,k]),i.useEffect(()=>{if(e.length===0)return;const T=16,j=e.map(N=>N.clips.map(P=>{if(P.waveformData){const Pe=Vn(P.waveformData,Ie,0,P.offsetSamples,P.durationSamples);return{clipId:P.id,trackName:N.name,peaks:{length:Pe.length,data:[Pe.data],bits:Pe.bits},startSample:P.startSample,durationSamples:P.durationSamples,fadeIn:P.fadeIn,fadeOut:P.fadeOut}}if(!P.audioBuffer)return console.warn(`Clip "${P.name||P.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:P.id,trackName:N.name,peaks:{length:0,data:[],bits:T},startSample:P.startSample,durationSamples:P.durationSamples,fadeIn:P.fadeIn,fadeOut:P.fadeOut};const ge=Na(P.audioBuffer,Ie,n,T,P.offsetSamples,P.durationSamples);return{clipId:P.id,trackName:N.name,peaks:ge,startSample:P.startSample,durationSamples:P.durationSamples,fadeIn:P.fadeIn,fadeOut:P.fadeOut}}));V(j)},[e,Ie,n]),i.useEffect(()=>{if(u?.annotations){const T=u.annotations.map(j=>typeof j.start=="number"?j:Pn(j));p(T)}},[u]);const Oe=i.useCallback(()=>{he.current&&(cancelAnimationFrame(he.current),he.current=null);const T=()=>{const j=W.getContext().currentTime-O.current,N=U.current+j;if(ue.current=N,E(N),I.length>0){const P=I.find(ge=>N>=ge.start&&N<ge.end);if(qe.current){if(P&&P.id!==Xe.current)je(P.id);else if(!P&&Xe.current!==null){const ge=I[I.length-1];if(N>=ge.end){_.current&&_.current.stop(),S(!1),ue.current=$e.current,E($e.current),je(null);return}}}else if(Xe.current){const ge=I.find(Pe=>Pe.id===Xe.current);if(ge&&N>=ge.end){_.current&&_.current.stop(),S(!1),ue.current=$e.current,E($e.current);return}}else P&&je(P.id)}if(ze.current&&xe.current&&B.length>0){const P=xe.current,ge=B[0].sampleRate,Pe=N*ge/Ye.current,fe=P.clientWidth,we=c.show?c.width:0,Re=Pe+we,Ge=Math.max(0,Re-fe/2);P.scrollLeft=Ge}if(se.current!==null&&N>=se.current){_.current&&_.current.stop(),S(!1),ue.current=se.current,E(se.current),se.current=null;return}const le=oe.current!==pe.current&&pe.current>oe.current;if(St.current&&le&&N>=pe.current){_.current?.stop();const ge=W.getContext().currentTime;O.current=ge,U.current=oe.current,ue.current=oe.current,_.current?.play(ge,oe.current),he.current=requestAnimationFrame(T);return}if(N>=R){_.current&&_.current.stop(),S(!1),ue.current=$e.current,E($e.current),je(null);return}he.current=requestAnimationFrame(T)};he.current=requestAnimationFrame(T)},[R,B,Ie,I,ve]),Ve=i.useCallback(()=>{he.current&&(cancelAnimationFrame(he.current),he.current=null)},[]);i.useEffect(()=>{(async()=>{if(k&&he.current&&_.current)if(ve){const j=ue.current;_.current.stop(),Ve(),await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const le=W.getContext().currentTime;O.current=le,U.current=j,_.current.play(le,j),Oe()}else Ve(),Oe()})()},[ve,k,Oe,Ve]),i.useEffect(()=>{(async()=>{if(ct.current&&_.current){const{position:j}=ct.current;ct.current=null,await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const le=W.getContext().currentTime;O.current=le,U.current=j,_.current.play(le,j),S(!0),Oe()}})()},[e,Oe]);const $t=i.useCallback(async(T,j)=>{if(!_.current||B.length===0)return;await _.current.init(),await W.start();const N=T??ue.current;$e.current=N,ue.current=N,_.current.setOnPlaybackComplete(()=>{}),_.current.stop(),Ve();const P=W.getContext().currentTime;O.current=P,U.current=N,se.current=j!==void 0?N+j:null,_.current.play(P,N,j),S(!0),Oe()},[B.length,Oe,Ve]),lr=i.useCallback(()=>{if(!_.current)return;const T=W.getContext().currentTime-O.current,j=U.current+T;_.current.pause(),S(!1),Ve(),ue.current=j,E(j)},[Ve]),cr=i.useCallback(()=>{_.current&&(_.current.stop(),S(!1),Ve(),ue.current=$e.current,E($e.current),je(null))},[Ve]),ur=i.useCallback(T=>{const j=Math.max(0,Math.min(T,R));ue.current=j,E(j),k&&_.current&&(_.current.stop(),Ve(),$t(j))},[R,k,$t,Ve]),dr=i.useCallback((T,j)=>{const N=[...F];if(N[T]={...N[T],muted:j},K(N),_.current){const le=`track-${T}`;_.current.setMute(le,j)}},[F]),fr=i.useCallback((T,j)=>{const N=[...F];if(N[T]={...N[T],soloed:j},K(N),_.current){const le=`track-${T}`;_.current.setSolo(le,j)}},[F]),mr=i.useCallback((T,j)=>{const N=[...F];if(N[T]={...N[T],volume:j},K(N),_.current){const le=`track-${T}`,P=_.current.getTrack(le);P&&P.setVolume(j)}},[F]),hr=i.useCallback((T,j)=>{const N=[...F];if(N[T]={...N[T],pan:j},K(N),_.current){const le=`track-${T}`,P=_.current.getTrack(le);P&&P.setPan(j)}},[F]),pr=i.useCallback((T,j)=>{Z(T),ae(j),ue.current=T,E(T),k&&_.current&&(_.current.stop(),_.current.play(W.getContext().currentTime,T))},[k]),gr=i.useCallback(T=>{xe.current=T},[]),br=B[0]?.sampleRate||44100,Xt=t?30:0,vr=e.length*r+Xt,Gt={isPlaying:k,currentTime:$,currentTimeRef:ue,playbackStartTimeRef:O,audioStartPositionRef:U},Nt={continuousPlay:ve,linkEndpoints:_e,annotationsEditable:Y,isAutomaticScroll:re,isLoopEnabled:ee,annotations:I,activeAnnotationId:m,selectionStart:H,selectionEnd:L,selectedTrackId:ne,loopStart:de,loopEnd:te},Lt={play:$t,pause:lr,stop:cr,seekTo:ur,setCurrentTime:T=>{ue.current=T,E(T)},setTrackMute:dr,setTrackSolo:fr,setTrackVolume:mr,setTrackPan:hr,setSelection:pr,setSelectedTrackId:Q,setTimeFormat:Ze,formatTime:ie,zoomIn:Me.zoomIn,zoomOut:Me.zoomOut,setMasterVolume:Le,setAutomaticScroll:T=>{be(T)},setScrollContainer:gr,scrollContainerRef:xe,setContinuousPlay:Qe,setLinkEndpoints:Ae,setAnnotationsEditable:ce,setAnnotations:p,setActiveAnnotationId:je,setLoopEnabled:At,setLoopRegion:nt,setLoopRegionFromSelection:sr,clearLoopRegion:ir},Yt={duration:R,audioBuffers:B,peaksDataArray:z,trackStates:F,tracks:e,sampleRate:br,waveHeight:r,timeScaleHeight:Xt,minimumPlaylistHeight:vr,controls:c,playoutRef:_,samplesPerPixel:Ie,timeFormat:ke,masterVolume:Ne,canZoomIn:Me.canZoomIn,canZoomOut:Me.canZoomOut,barWidth:f,barGap:C,progressBarWidth:b},Cr={...Gt,...Nt,...Lt,...Yt},xr={...kn,...l};return v.jsx(A.ThemeProvider,{theme:xr,children:v.jsx(Kn.Provider,{value:Gt,children:v.jsx(Un.Provider,{value:Nt,children:v.jsx(Jn.Provider,{value:Lt,children:v.jsx(qn.Provider,{value:Yt,children:v.jsx(Qn.Provider,{value:Cr,children:h})})})})})})},Se=()=>{const e=i.useContext(Kn);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},We=()=>{const e=i.useContext(Un);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},me=()=>{const e=i.useContext(Jn);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},ye=()=>{const e=i.useContext(qn);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},vs=()=>{const e=i.useContext(Qn);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var Cs=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,"preservesPitch"in this.audioElement?this.audioElement.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?this.audioElement.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(this.audioElement.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}},xs=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 Cs({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const r=t??0;if(this._isPlaying=!0,this.track.play(r),n!==void 0){const a=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},a*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 er=i.createContext(null),tr=i.createContext(null),nr=i.createContext(null),rr=i.createContext(null),ws=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:r=!1,playbackRate:a=1,automaticScroll:s=!1,theme:o,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:d=0,progressBarWidth:x,onReady:g,children:f})=>{const C=x??u+d,[w,h]=i.useState(!1),[b,I]=i.useState(0),[p,m]=i.useState(0),[y,k]=i.useState([]),[S,$]=i.useState(a),[E,R]=i.useState([]),[M,B]=i.useState(null),[D,z]=i.useState(c?.isContinuousPlay??!1),[V]=i.useState(t),[F,K]=i.useState(s),H=i.useRef(null),Z=i.useRef(0),L=i.useRef(null),ae=i.useRef(D),ne=i.useRef(null),Q=i.useRef(null),re=i.useRef(s),be=i.useRef(t);i.useEffect(()=>{ae.current=D},[D]),i.useEffect(()=>{re.current=F},[F]);const ve=i.useCallback(O=>{ne.current=O,B(O)},[]),He=i.useCallback(O=>{ae.current=O,z(O)},[]),_e=i.useCallback(O=>{Q.current=O},[]),Ae=e.waveformData.sample_rate;i.useEffect(()=>{const O=new xs({playbackRate:a});O.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const U=O.getTrack(O.track?.id??"");return U&&U.setOnTimeUpdateCallback(se=>{Z.current=se}),O.setOnPlaybackComplete(()=>{h(!1)}),H.current=O,m(e.waveformData.duration),g?.(),()=>{L.current&&cancelAnimationFrame(L.current),O.dispose()}},[e.source,e.waveformData,e.name,a,g]),i.useEffect(()=>{const O=Vn(e.waveformData,V,0,0,Math.ceil(e.waveformData.duration*Ae)),U={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*Ae)};k([[U]])},[e.waveformData,e.name,V,Ae]),i.useEffect(()=>{if(c?.annotations){const O=c.annotations.map(U=>typeof U.start=="number"?U:Pn(U));R(O)}},[c]);const Y=i.useCallback(()=>{L.current&&cancelAnimationFrame(L.current);const O=()=>{const U=H.current?.getCurrentTime()??0;if(Z.current=U,I(U),E.length>0){const se=E.find(xe=>U>=xe.start&&U<xe.end);if(ae.current){if(se&&se.id!==ne.current)ve(se.id);else if(!se&&ne.current!==null){const xe=E[E.length-1];if(U>=xe.end){H.current?.stop(),h(!1),ve(null);return}}}else if(ne.current){const xe=E.find(ze=>ze.id===ne.current);if(xe&&U>=xe.end){H.current?.stop(),h(!1);return}}else se&&ve(se.id)}if(re.current&&Q.current){const se=Q.current,xe=U*Ae/be.current,ze=se.clientWidth,qe=l.show?l.width:0,Xe=xe+qe,Ye=Math.max(0,Xe-ze/2);se.scrollLeft=Ye}if(U>=p){H.current?.stop(),h(!1),ve(null);return}L.current=requestAnimationFrame(O)};L.current=requestAnimationFrame(O)},[p,E,ve,Ae,l]),ce=i.useCallback(()=>{L.current&&(cancelAnimationFrame(L.current),L.current=null)},[]),ee=i.useCallback(O=>{if(!H.current)return;const U=O??Z.current;H.current.play(void 0,U),h(!0),Y()},[Y]),q=i.useCallback(()=>{H.current&&(H.current.pause(),h(!1),ce(),I(H.current.getCurrentTime()))},[ce]),de=i.useCallback(()=>{H.current&&(H.current.stop(),h(!1),ce(),Z.current=0,I(0),ve(null))},[ce,ve]),Ce=i.useCallback(O=>{const U=Math.max(0,Math.min(O,p));Z.current=U,I(U),H.current&&H.current.seekTo(U)},[p]),te=i.useCallback(O=>{const U=Math.max(.5,Math.min(2,O));$(U),H.current&&H.current.setPlaybackRate(U)},[]),Fe=r?30:0,_=i.useMemo(()=>({isPlaying:w,currentTime:b,currentTimeRef:Z}),[w,b]),$e=i.useMemo(()=>({continuousPlay:D,annotations:E,activeAnnotationId:M,playbackRate:S,isAutomaticScroll:F}),[D,E,M,S,F]),ue=i.useMemo(()=>({play:ee,pause:q,stop:de,seekTo:Ce,setPlaybackRate:te,setContinuousPlay:He,setAnnotations:R,setActiveAnnotationId:ve,setAutomaticScroll:O=>{K(O)},setScrollContainer:_e,scrollContainerRef:Q}),[ee,q,de,Ce,te,He,ve,_e]),he=i.useMemo(()=>({duration:p,peaksDataArray:y,sampleRate:Ae,waveHeight:n,timeScaleHeight:Fe,samplesPerPixel:V,playoutRef:H,controls:l,barWidth:u,barGap:d,progressBarWidth:C}),[p,y,Ae,n,Fe,V,l,u,d,C]),Je={...kn,...o};return v.jsx(A.ThemeProvider,{theme:Je,children:v.jsx(er.Provider,{value:_,children:v.jsx(tr.Provider,{value:$e,children:v.jsx(nr.Provider,{value:ue,children:v.jsx(rr.Provider,{value:he,children:f})})})})})},kt=()=>{const e=i.useContext(er);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},ar=()=>{const e=i.useContext(tr);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},or=()=>{const e=i.useContext(nr);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},It=()=>{const e=i.useContext(rr);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},ys=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Se(),{selectionStart:r,selectionEnd:a,isLoopEnabled:s}=We(),{play:o}=me(),l=async()=>{if(r!==a&&a>r)if(s)await o(r);else{const u=a-r;await o(r,u)}else await o(n.current??0)};return v.jsx(Te,{onClick:l,disabled:t,className:e,children:"Play"})},ks=({className:e})=>{const{isPlaying:t}=Se(),{pause:n}=me();return v.jsx(Te,{onClick:n,disabled:!t,className:e,children:"Pause"})},Is=({className:e})=>{const{isPlaying:t}=Se(),{stop:n}=me();return v.jsx(Te,{onClick:n,disabled:!t,className:e,children:"Stop"})},Ss=({className:e})=>{const{isPlaying:t}=Se(),{play:n,setCurrentTime:r}=me(),{playoutRef:a}=ye(),s=()=>{r(0),t&&a.current&&(a.current.stop(),n(0))};return v.jsx(Te,{onClick:s,className:e,children:"Rewind"})},As=({className:e})=>{const{isPlaying:t}=Se(),{play:n,setCurrentTime:r}=me(),{duration:a,playoutRef:s}=ye(),o=()=>{r(a),t&&s.current&&(s.current.stop(),n(a))};return v.jsx(Te,{onClick:o,className:e,children:"Fast Forward"})},$s=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=Se(),{play:a,setCurrentTime:s}=me(),{playoutRef:o}=ye(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),r&&o.current&&(o.current.stop(),a(c))};return v.jsx(Te,{onClick:l,className:t,children:"Skip Backward"})},Ms=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=Se(),{play:a,setCurrentTime:s}=me(),{duration:o,playoutRef:l}=ye(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),r&&l.current&&(l.current.stop(),a(u))};return v.jsx(Te,{onClick:c,className:t,children:"Skip Forward"})},Rs=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:r}=We(),{setLoopEnabled:a,setLoopRegion:s}=me(),{duration:o}=ye(),l=n!==r&&r>n,c=()=>{if(!t&&!l){const u=Math.min(10,o*.25);s(0,Math.max(1,u))}a(!t)};return v.jsx(Te,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Es=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:r,loopEnd:a}=We(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=me(),l=t!==n&&n>t,c=r!==a&&a>r,u=()=>{c?o():s()};return v.jsx(Te,{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"})},Ds=({className:e,disabled:t})=>{const{zoomIn:n}=me(),{canZoomIn:r}=ye();return v.jsx(Te,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom In"})},Bs=({className:e,disabled:t})=>{const{zoomOut:n}=me(),{canZoomOut:r}=ye();return v.jsx(Te,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom Out"})},Ts=({className:e})=>{const{masterVolume:t}=ye(),{setMasterVolume:n}=me();return v.jsx(ia,{volume:t,onChange:n,className:e})},Ws=({className:e})=>{const{timeFormat:t}=ye(),{setTimeFormat:n}=me();return v.jsx(Ta,{value:t,onChange:n,className:e})},_s=A.span`
1193
+ `,ns=({level:e,peakLevel:t,width:n=200,height:a=20,className:r})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return b.jsxs(Jo,{$width:n,$height:a,className:r,children:[b.jsx(Qo,{$level:s,$height:a}),t!==void 0&&o>0&&b.jsx(es,{$peakLevel:o,$height:a}),b.jsxs(ts,{$height:a,children:[b.jsx(un,{$position:60,$height:a}),b.jsx(un,{$position:85,$height:a})]})]})};i.memo(ns);function as(e,t,n,a={}){const{currentTime:r=0,audioConstraints:s,...o}=a,[l,c]=i.useState(!1),[u,d]=i.useState(null),{stream:v,devices:p,hasPermission:f,requestAccess:C,error:y}=Ko(),{level:m,peakLevel:g}=Uo(v),{isRecording:I,isPaused:x,duration:h,peaks:w,startRecording:k,stopRecording:A,pauseRecording:M,resumeRecording:$,error:E}=Oo(v,o),R=i.useCallback(async()=>{n&&(l||(await Et(),c(!0)),await k())},[n,l,k]),T=i.useCallback(async()=>{const V=await A();if(V&&n){const F=e.findIndex(q=>q.id===n);if(F===-1)return;const N=e[F],H=Math.floor(r*V.sampleRate);let Z=0;if(N.clips.length>0){const q=N.clips.map(ae=>ae.startSample+ae.durationSamples);Z=Math.max(...q)}const U=Math.max(H,Z),re={id:`clip-${Date.now()}`,audioBuffer:V,startSample:U,durationSamples:V.length,offsetSamples:0,sampleRate:V.sampleRate,sourceDurationSamples:V.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},ne=e.map((q,ae)=>ae===F?{...q,clips:[...q.clips,re]}:q);t(ne)}},[n,e,t,r,A]);i.useEffect(()=>{f&&p.length>0&&u===null&&d(p[0].deviceId)},[f,p.length]);const D=i.useCallback(async()=>{await C(void 0,s),await Et(),c(!0)},[C,s]),P=i.useCallback(async V=>{d(V),await C(V,s),await Et(),c(!0)},[C,s]);return{isRecording:I,isPaused:x,duration:h,level:m,peakLevel:g,error:y||E,stream:v,devices:p,hasPermission:f,selectedDevice:u,startRecording:R,stopRecording:T,pauseRecording:M,resumeRecording:$,requestMicAccess:D,changeDevice:P,recordingPeaks:w}}const lt=[{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}]}],Ht=e=>lt.find(t=>t.id===e),rs=e=>lt.filter(t=>t.category===e),os=[{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"}],ss={reverb:W.Reverb,freeverb:W.Freeverb,jcReverb:W.JCReverb,feedbackDelay:W.FeedbackDelay,pingPongDelay:W.PingPongDelay,chorus:W.Chorus,phaser:W.Phaser,tremolo:W.Tremolo,vibrato:W.Vibrato,autoPanner:W.AutoPanner,autoFilter:W.AutoFilter,autoWah:W.AutoWah,eq3:W.EQ3,distortion:W.Distortion,bitCrusher:W.BitCrusher,chebyshev:W.Chebyshev,compressor:W.Compressor,limiter:W.Limiter,gate:W.Gate,stereoWidener:W.StereoWidener};let is=0;const ls=()=>`effect_${Date.now()}_${++is}`;function ot(e,t){const n=ss[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;a[o.name]=l});const r=new n(a),s=ls();return{effect:r,id:e.id,instanceId:s,dispose(){try{r.disconnect(),r.dispose()}catch{}},setParameter(o,l){o==="wet"&&r.wet?r.wet.value=l:r[o]!==void 0&&(r[o]?.value!==void 0?r[o].value=l:r[o]=l)},getParameter(o){if(o==="wet"&&r.wet)return r.wet.value;if(r[o]!==void 0)return r[o]?.value!==void 0?r[o].value:r[o]},connect(o){r.connect(o)},disconnect(){try{r.disconnect()}catch{}}}}function cs(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 us(e=256){const[t,n]=i.useState([]),a=i.useRef(t);a.current=t;const r=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(m=>{const g=o.current;if(!g)return;const{masterGainNode:I,destination:x,analyserNode:h}=g;try{I.disconnect()}catch{}const w=m.map(k=>r.current.get(k.instanceId)).filter(k=>k!==void 0);if(w.length===0)I.connect(h),h.connect(x);else{let k=I;w.forEach(A=>{try{A.disconnect()}catch{}k.connect(A.effect),k=A.effect}),k.connect(h),h.connect(x)}},[]),c=i.useCallback(m=>{const g=Ht(m);if(!g){console.error(`Unknown effect: ${m}`);return}const I={};g.parameters.forEach(w=>{I[w.name]=w.default});const x=ot(g,I);r.current.set(x.instanceId,x);const h={instanceId:x.instanceId,effectId:g.id,definition:g,params:I,bypassed:!1};n(w=>[...w,h])},[]),u=i.useCallback(m=>{const g=r.current.get(m);g&&(g.dispose(),r.current.delete(m)),n(I=>I.filter(x=>x.instanceId!==m))},[]),d=i.useCallback((m,g,I)=>{const x=r.current.get(m);x&&x.setParameter(g,I),n(h=>h.map(w=>w.instanceId===m?{...w,params:{...w.params,[g]:I}}:w))},[]),v=i.useCallback(m=>{const g=a.current.find(h=>h.instanceId===m);if(!g)return;const I=!g.bypassed,x=r.current.get(m);if(x){const h=g.params.wet??1;x.setParameter("wet",I?0:h)}n(h=>h.map(w=>w.instanceId===m?{...w,bypassed:I}:w))},[]),p=i.useCallback((m,g)=>{n(I=>{const x=[...I],[h]=x.splice(m,1);return x.splice(g,0,h),x})},[]),f=i.useCallback(()=>{r.current.forEach(m=>m.dispose()),r.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const C=i.useCallback((m,g,I)=>{const x=new W.Analyser("fft",e);s.current=x,o.current={masterGainNode:m,destination:g,analyserNode:x};const w=a.current.map(k=>r.current.get(k.instanceId)).filter(k=>k!==void 0);if(w.length===0)m.connect(x),x.connect(g);else{let k=m;w.forEach(A=>{k.connect(A.effect),k=A.effect}),k.connect(x),x.connect(g)}return function(){x.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{r.current.forEach(m=>m.dispose()),r.current.clear()},[]);const y=i.useCallback(()=>{const m=t.filter(g=>!g.bypassed);if(m.length!==0)return(g,I,x)=>{const h=[];for(const w of m){const k=ot(w.definition,w.params);h.push(k)}if(h.length===0)g.connect(I);else{let w=g;h.forEach(k=>{w.connect(k.effect),w=k.effect}),w.connect(I)}return function(){h.forEach(k=>k.dispose())}}},[t]);return{activeEffects:t,availableEffects:lt,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:v,reorderEffects:p,clearAllEffects:f,masterEffects:C,createOfflineEffectsFunction:y,analyserRef:s}}function ds(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),a=i.useRef(new Map),r=i.useCallback((f,C)=>{const y=a.current.get(f);if(!y)return;const{graphEnd:m,masterGainNode:g}=y,I=n.current.get(f);try{m.disconnect()}catch{}const x=C.map(h=>I?.get(h.instanceId)).filter(h=>h!==void 0);if(x.length===0)m.connect(g);else{let h=m;x.forEach(w=>{try{w.disconnect()}catch{}h.connect(w.effect),h=w.effect}),h.connect(g)}},[]),s=i.useCallback((f,C)=>{const y=Ht(C);if(!y){console.error(`Unknown effect: ${C}`);return}const m={};y.parameters.forEach(x=>{m[x.name]=x.default});const g=ot(y,m);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(g.instanceId,g);const I={instanceId:g.instanceId,effectId:y.id,definition:y,params:m,bypassed:!1};t(x=>{const h=new Map(x),w=h.get(f)||[];return h.set(f,[...w,I]),h})},[]),o=i.useCallback((f,C)=>{const y=n.current.get(f),m=y?.get(C);m&&(m.dispose(),y?.delete(C)),t(g=>{const I=new Map(g),x=I.get(f)||[];return I.set(f,x.filter(h=>h.instanceId!==C)),I})},[]),l=i.useCallback((f,C,y,m)=>{const I=n.current.get(f)?.get(C);I&&I.setParameter(y,m),t(x=>{const h=new Map(x),w=h.get(f)||[];return h.set(f,w.map(k=>k.instanceId===C?{...k,params:{...k.params,[y]:m}}:k)),h})},[]),c=i.useCallback((f,C)=>{const m=(d.current.get(f)||[]).find(h=>h.instanceId===C);if(!m)return;const g=!m.bypassed,x=n.current.get(f)?.get(C);if(x){const h=m.params.wet??1;x.setParameter("wet",g?0:h)}t(h=>{const w=new Map(h),k=w.get(f)||[];return w.set(f,k.map(A=>A.instanceId===C?{...A,bypassed:g}:A)),w})},[]),u=i.useCallback(f=>{const C=n.current.get(f);C&&(C.forEach(y=>y.dispose()),C.clear()),t(y=>{const m=new Map(y);return m.set(f,[]),m})},[]),d=i.useRef(e);d.current=e;const v=i.useCallback(f=>(C,y,m)=>{a.current.set(f,{graphEnd:C,masterGainNode:y});const g=d.current.get(f)||[],I=n.current.get(f),x=g.map(h=>I?.get(h.instanceId)).filter(h=>h!==void 0);if(x.length===0)C.connect(y);else{let h=C;x.forEach(w=>{h.connect(w.effect),h=w.effect}),h.connect(y)}return function(){a.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,C)=>{r(C,f)})},[e,r]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(C=>C.dispose()),f.clear()}),n.current.clear()},[]);const p=i.useCallback(f=>{const y=(e.get(f)||[]).filter(m=>!m.bypassed);if(y.length!==0)return(m,g,I)=>{const x=[];for(const h of y){const w=ot(h.definition,h.params);x.push(w)}if(x.length===0)m.connect(g);else{let h=m;x.forEach(w=>{h.connect(w.effect),h=w.effect}),h.connect(g)}return function(){x.forEach(w=>w.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:v,createOfflineTrackEffectsFunction:p,availableEffects:lt}}function fs(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,o=n/8,l=a*o,c=r*l,u=s*l,d=44,v=d+u,p=new ArrayBuffer(v),f=new DataView(p);pt(f,0,"RIFF"),f.setUint32(4,v-8,!0),pt(f,8,"WAVE"),pt(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),pt(f,36,"data"),f.setUint32(40,u,!0);const C=[];for(let m=0;m<a;m++)C.push(e.getChannelData(m));let y=d;if(n===16)for(let m=0;m<s;m++)for(let g=0;g<a;g++){const I=C[g][m],x=Math.max(-1,Math.min(1,I)),h=x<0?x*32768:x*32767;f.setInt16(y,h,!0),y+=2}else for(let m=0;m<s;m++)for(let g=0;g<a;g++)f.setFloat32(y,C[g][m],!0),y+=4;return new Blob([p],{type:"audio/wav"})}function pt(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function ms(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 On(){const[e,t]=i.useState(!1),[n,a]=i.useState(0),[r,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:v="master",trackIndex:p,autoDownload:f=!0,applyEffects:C=!0,effectsFunction:y,createOfflineTrackEffects:m,bitDepth:g=16,onProgress:I}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(v==="individual"&&(p===void 0||p<0||p>=l.length))throw new Error("Invalid track index for individual export");const x=l[0].clips[0]?.sampleRate||44100;let h=0;for(const R of l)for(const T of R.clips){const D=T.startSample+T.durationSamples;h=Math.max(h,D)}h+=Math.round(x*.1);const w=h/x,k=v==="individual"?[{track:l[p],state:c[p],index:p}]:l.map((R,T)=>({track:R,state:c[T],index:T})),A=c.some(R=>R.soloed),M=!!m;let $;if((y||M)&&C)$=await hs(k,c,A,w,x,y,m,R=>{a(R),I?.(R)});else{const R=new OfflineAudioContext(2,h,x);let T=0;const D=k.reduce((P,{track:V})=>P+V.clips.length,0);for(const{track:P,state:V}of k)if(!(V.muted&&!V.soloed)&&!(A&&!V.soloed))for(const F of P.clips){await gs(R,F,V,x,C),T++;const N=T/D*.5;a(N),I?.(N)}a(.5),I?.(.5),$=await R.startRendering()}a(.9),I?.(.9);const E=fs($,{bitDepth:g});if(a(1),I?.(1),f){const R=v==="individual"?`${d}_${l[p].name}`:d;ms(E,`${R}.wav`)}return{audioBuffer:$,blob:E,duration:w}}catch(x){const h=x instanceof Error?x.message:"Export failed";throw s(h),x}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function hs(e,t,n,a,r,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:v,Player:p,ToneAudioBuffer:f}=await import("tone");l(.1);let C;try{C=await c(async({transport:y,destination:m})=>{const g=new u(0);let I;s?I=s(g,m,!0):g.connect(m);for(const{track:x,state:h}of e){if(h.muted&&!h.soloed||n&&!h.soloed)continue;const w=new u(ps(h.volume)),k=new v(h.pan),A=new d(h.muted?0:1),M=o?.(x.id);M?M(A,g,!0):A.connect(g),k.connect(A),w.connect(k);for(const $ of x.clips){const{audioBuffer:E,startSample:R,durationSamples:T,offsetSamples:D,gain:P,fadeIn:V,fadeOut:F}=$,N=R/r,H=T/r,Z=D/r,U=new f(E),re=new p(U),ne=new d(P);if(re.connect(ne),ne.connect(w),V){const q=N,ae=N+V.duration,be=ne.gain._param;be.setValueAtTime(0,q),be.linearRampToValueAtTime(P,ae)}if(F){const q=N+H-F.duration,ae=N+H,be=ne.gain._param;be.setValueAtTime(P,q),be.linearRampToValueAtTime(0,ae)}re.start(N,Z,H)}}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 ps(e){return 20*Math.log10(Math.max(e,1e-4))}async function gs(e,t,n,a,r){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:d,fadeOut:v}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const p=o/a,f=l/a,C=c/a,y=e.createBufferSource();y.buffer=s;const m=e.createGain(),g=u*n.volume,I=e.createStereoPanner();if(I.pan.value=n.pan,y.connect(m),m.connect(I),I.connect(e.destination),r){if(d?m.gain.setValueAtTime(0,p):m.gain.setValueAtTime(g,p),d){const x=p,h=p+d.duration;dn(m.gain,x,h,0,g,d.type||"linear")}if(v){const x=p+f-v.duration,h=p+f;(!d||d.duration<f-v.duration)&&m.gain.setValueAtTime(g,x),dn(m.gain,x,h,g,0,v.type||"linear")}}else m.gain.setValueAtTime(g,p);y.start(p,C,f)}function dn(e,t,n,a,r,s){const o=n-t;if(!(o<=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 u=fn(a,r,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=fn(a,r,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function fn(e,t,n,a){const r=new Float32Array(n),s=t-e;for(let o=0;o<n;o++){const l=o/(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[o]=e+s*c}return r}const Kn=i.createContext(null),Un=i.createContext(null),Jn=i.createContext(null),qn=i.createContext(null),Qn=i.createContext(null),bs=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:v,onAnnotationUpdate:p,barWidth:f=1,barGap:C=0,progressBarWidth:y,children:m})=>{const g=y??f+C,[I,x]=i.useState([]),[h,w]=i.useState(null),[k,A]=i.useState(!1),[M,$]=i.useState(0),[E,R]=i.useState(0),[T,D]=i.useState([]),[P,V]=i.useState([]),[F,N]=i.useState([]),[H,Z]=i.useState(0),[U,re]=i.useState(0),[ne,q]=i.useState(null),[ae,be]=i.useState(o),[pe,He]=i.useState(u?.isContinuousPlay??!1),[Ve,we]=i.useState(u?.linkEndpoints??!0),[Xe,L]=i.useState(u?.editable??!1),[ce,ee]=i.useState(!1),[J,ue]=i.useState(0),[ve,te]=i.useState(0),_=i.useRef(null),Ae=i.useRef(0),ge=i.useRef(0),de=i.useRef(null),Oe=i.useRef(F),K=i.useRef(0),Q=i.useRef(0),le=i.useRef(null),fe=i.useRef(null),Ge=i.useRef(!1),Ne=i.useRef(u?.isContinuousPlay??!1),Pe=i.useRef(null),Ke=i.useRef(r),ct=i.useRef(!1),At=i.useRef(0),X=i.useRef(0),O=i.useRef(0),se=i.useRef(0),{timeFormat:ye,setTimeFormat:Ie,formatTime:We}=Xn(),oe=Gn({initialSamplesPerPixel:r,zoomLevels:s}),Se=oe.samplesPerPixel,{masterVolume:ze,setMasterVolume:Le}=Nn({playoutRef:_,initialVolume:1}),Ye=i.useCallback(B=>{Ne.current=B,He(B)},[]),_e=i.useCallback(B=>{Pe.current=B,w(B)},[]),nt=i.useCallback(B=>{ct.current=B,ee(B)},[]),Ue=i.useCallback((B,j)=>{O.current=B,se.current=j,ue(B),te(j)},[]),sa=i.useCallback(()=>{const B=At.current,j=X.current;B!==j&&j>B&&Ue(B,j)},[Ue]),ia=i.useCallback(()=>{Ue(0,0)},[Ue]);i.useEffect(()=>{Ge.current=ae},[ae]),i.useEffect(()=>{Oe.current=F},[F]),i.useEffect(()=>{At.current=H,X.current=U},[H,U]),i.useEffect(()=>{if(!fe.current||!T.length)return;const B=fe.current,j=Ke.current,Y=Se;if(j===Y)return;const ie=c.show?c.width:0,z=B.clientWidth,Ze=B.scrollLeft+z/2-ie,me=T[0].sampleRate,Me=Ze*j/me*me/Y,je=Math.max(0,Me+ie-z/2);B.scrollLeft=je,Ke.current=Y},[Se,T,c]);const ut=i.useRef(null);i.useEffect(()=>{if(e.length===0){D([]),R(0),N([]),V([]),_.current&&(_.current.dispose(),_.current=null);return}const B=k,j=ge.current;return _.current&&B&&(_.current.stop(),de.current&&(cancelAnimationFrame(de.current),de.current=null),ut.current={position:j}),(async()=>{try{const ie=[];e.forEach(me=>{me.clips.length>0&&me.clips[0].audioBuffer&&ie.push(me.clips[0].audioBuffer)});let z=0;e.forEach(me=>{me.clips.forEach(xe=>{const Me=xe.sampleRate,dt=(xe.startSample+xe.durationSamples)/Me;z=Math.max(z,dt)})}),D(ie),R(z),N(me=>me.length===e.length?me.map((xe,Me)=>({...xe,name:e[Me].name})):e.map(xe=>({name:xe.name,muted:xe.muted,soloed:xe.soloed,volume:xe.volume,pan:xe.pan}))),_.current&&_.current.dispose();const Ce=new Fa({effects:d}),Ze=Oe.current;e.forEach((me,xe)=>{const Me=me.clips.filter(je=>je.audioBuffer);if(Me.length>0){const je=Me[0].sampleRate,dt=Math.min(...Me.map(Re=>Re.startSample/je)),wa=Math.max(...Me.map(Re=>(Re.startSample+Re.durationSamples)/je)),ft=Ze[xe],ya={id:`track-${xe}`,name:me.name,gain:ft?.volume??me.volume,muted:ft?.muted??me.muted,soloed:ft?.soloed??me.soloed,stereoPan:ft?.pan??me.pan,startTime:dt,endTime:wa},ka=Me.map(Re=>{const Mt=Re.sampleRate;return{buffer:Re.audioBuffer,startTime:Re.startSample/Mt-dt,duration:Re.durationSamples/Mt,offset:Re.offsetSamples/Mt,fadeIn:Re.fadeIn,fadeOut:Re.fadeOut,gain:Re.gain}});Ce.addTrack({clips:ka,track:ya,effects:me.effects})}}),Ce.applyInitialSoloState(),_.current=Ce,v?.()}catch(ie){console.error("Error loading audio:",ie)}})(),()=>{de.current&&cancelAnimationFrame(de.current),_.current&&_.current.dispose()}},[e,v,k]),i.useEffect(()=>{if(e.length===0)return;const B=16,j=e.map(Y=>Y.clips.map(z=>{if(z.waveformData){const Ze=Vn(z.waveformData,Se,0,z.offsetSamples,z.durationSamples);return{clipId:z.id,trackName:Y.name,peaks:{length:Ze.length,data:[Ze.data],bits:Ze.bits},startSample:z.startSample,durationSamples:z.durationSamples,fadeIn:z.fadeIn,fadeOut:z.fadeOut}}if(!z.audioBuffer)return console.warn(`Clip "${z.name||z.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:z.id,trackName:Y.name,peaks:{length:0,data:[],bits:B},startSample:z.startSample,durationSamples:z.durationSamples,fadeIn:z.fadeIn,fadeOut:z.fadeOut};const Ce=Nr(z.audioBuffer,Se,n,B,z.offsetSamples,z.durationSamples);return{clipId:z.id,trackName:Y.name,peaks:Ce,startSample:z.startSample,durationSamples:z.durationSamples,fadeIn:z.fadeIn,fadeOut:z.fadeOut}}));V(j)},[e,Se,n]),i.useEffect(()=>{if(u?.annotations){const B=u.annotations.map(j=>typeof j.start=="number"?j:Pn(j));x(B)}},[u]);const Je=i.useCallback(()=>{de.current&&(cancelAnimationFrame(de.current),de.current=null);const B=()=>{const j=W.getContext().currentTime-K.current,Y=Q.current+j;if(ge.current=Y,$(Y),I.length>0){const z=I.find(Ce=>Y>=Ce.start&&Y<Ce.end);if(Ne.current)z&&z.id!==Pe.current?_e(z.id):!z&&Pe.current!==null&&_e(null);else if(Pe.current){const Ce=I.find(Ze=>Ze.id===Pe.current);if(Ce&&Y>=Ce.end){_.current&&_.current.stop(),A(!1),ge.current=Ae.current,$(Ae.current);return}}else z&&_e(z.id)}if(Ge.current&&fe.current&&T.length>0){const z=fe.current,Ce=T[0].sampleRate,Ze=Y*Ce/Ke.current,me=z.clientWidth,xe=c.show?c.width:0,Me=Ze+xe,je=Math.max(0,Me-me/2);z.scrollLeft=je}if(le.current!==null&&Y>=le.current){_.current&&_.current.stop(),A(!1),ge.current=le.current,$(le.current),le.current=null;return}const ie=O.current!==se.current&&se.current>O.current;if(ct.current&&ie&&Y>=se.current){_.current?.stop();const Ce=W.getContext().currentTime;K.current=Ce,Q.current=O.current,ge.current=O.current,_.current?.play(Ce,O.current),de.current=requestAnimationFrame(B);return}if(Y>=E){_.current&&_.current.stop(),A(!1),ge.current=Ae.current,$(Ae.current),_e(null);return}de.current=requestAnimationFrame(B)};de.current=requestAnimationFrame(B)},[E,T,Se,I,pe]),Fe=i.useCallback(()=>{de.current&&(cancelAnimationFrame(de.current),de.current=null)},[]);i.useEffect(()=>{(async()=>{if(k&&de.current&&_.current)if(pe){const j=ge.current;_.current.stop(),Fe(),await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const ie=W.getContext().currentTime;K.current=ie,Q.current=j,_.current.play(ie,j),Je()}else Fe(),Je()})()},[pe,k,Je,Fe]),i.useEffect(()=>{(async()=>{if(ut.current&&_.current){const{position:j}=ut.current;ut.current=null,await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const ie=W.getContext().currentTime;K.current=ie,Q.current=j,_.current.play(ie,j),A(!0),Je()}})()},[e,Je]);const $t=i.useCallback(async(B,j)=>{if(!_.current||T.length===0)return;await _.current.init(),await W.start();const Y=B??ge.current;Ae.current=Y,ge.current=Y,_.current.setOnPlaybackComplete(()=>{}),_.current.stop(),Fe();const z=W.getContext().currentTime;K.current=z,Q.current=Y,le.current=j!==void 0?Y+j:null,_.current.play(z,Y,j),A(!0),Je()},[T.length,Je,Fe]),la=i.useCallback(()=>{if(!_.current)return;const B=W.getContext().currentTime-K.current,j=Q.current+B;_.current.pause(),A(!1),Fe(),ge.current=j,$(j)},[Fe]),ca=i.useCallback(()=>{_.current&&(_.current.stop(),A(!1),Fe(),ge.current=Ae.current,$(Ae.current),_e(null))},[Fe]),ua=i.useCallback(B=>{const j=Math.max(0,Math.min(B,E));ge.current=j,$(j),k&&_.current&&(_.current.stop(),Fe(),$t(j))},[E,k,$t,Fe]),da=i.useCallback((B,j)=>{const Y=[...F];if(Y[B]={...Y[B],muted:j},N(Y),_.current){const ie=`track-${B}`;_.current.setMute(ie,j)}},[F]),fa=i.useCallback((B,j)=>{const Y=[...F];if(Y[B]={...Y[B],soloed:j},N(Y),_.current){const ie=`track-${B}`;_.current.setSolo(ie,j)}},[F]),ma=i.useCallback((B,j)=>{const Y=[...F];if(Y[B]={...Y[B],volume:j},N(Y),_.current){const ie=`track-${B}`,z=_.current.getTrack(ie);z&&z.setVolume(j)}},[F]),ha=i.useCallback((B,j)=>{const Y=[...F];if(Y[B]={...Y[B],pan:j},N(Y),_.current){const ie=`track-${B}`,z=_.current.getTrack(ie);z&&z.setPan(j)}},[F]),pa=i.useCallback((B,j)=>{Z(B),re(j),ge.current=B,$(B),k&&_.current&&(_.current.stop(),_.current.play(W.getContext().currentTime,B))},[k]),ga=i.useCallback(B=>{fe.current=B},[]),ba=T[0]?.sampleRate||44100,Xt=t?30:0,va=e.length*a+Xt,Gt={isPlaying:k,currentTime:M,currentTimeRef:ge,playbackStartTimeRef:K,audioStartPositionRef:Q},Nt={continuousPlay:pe,linkEndpoints:Ve,annotationsEditable:Xe,isAutomaticScroll:ae,isLoopEnabled:ce,annotations:I,activeAnnotationId:h,selectionStart:H,selectionEnd:U,selectedTrackId:ne,loopStart:J,loopEnd:ve},Lt={play:$t,pause:la,stop:ca,seekTo:ua,setCurrentTime:B=>{ge.current=B,$(B)},setTrackMute:da,setTrackSolo:fa,setTrackVolume:ma,setTrackPan:ha,setSelection:pa,setSelectedTrackId:q,setTimeFormat:Ie,formatTime:We,zoomIn:oe.zoomIn,zoomOut:oe.zoomOut,setMasterVolume:Le,setAutomaticScroll:B=>{be(B)},setScrollContainer:ga,scrollContainerRef:fe,setContinuousPlay:Ye,setLinkEndpoints:we,setAnnotationsEditable:L,setAnnotations:x,setActiveAnnotationId:_e,setLoopEnabled:nt,setLoopRegion:Ue,setLoopRegionFromSelection:sa,clearLoopRegion:ia},Yt={duration:E,audioBuffers:T,peaksDataArray:P,trackStates:F,tracks:e,sampleRate:ba,waveHeight:a,timeScaleHeight:Xt,minimumPlaylistHeight:va,controls:c,playoutRef:_,samplesPerPixel:Se,timeFormat:ye,masterVolume:ze,canZoomIn:oe.canZoomIn,canZoomOut:oe.canZoomOut,barWidth:f,barGap:C,progressBarWidth:g},Ca={...Gt,...Nt,...Lt,...Yt},xa={...kn,...l};return b.jsx(S.ThemeProvider,{theme:xa,children:b.jsx(Kn.Provider,{value:Gt,children:b.jsx(Un.Provider,{value:Nt,children:b.jsx(Jn.Provider,{value:Lt,children:b.jsx(qn.Provider,{value:Yt,children:b.jsx(Qn.Provider,{value:Ca,children:m})})})})})})},$e=()=>{const e=i.useContext(Kn);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Te=()=>{const e=i.useContext(Un);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},he=()=>{const e=i.useContext(Jn);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},ke=()=>{const e=i.useContext(qn);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},vs=()=>{const e=i.useContext(Qn);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var Cs=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,"preservesPitch"in this.audioElement?this.audioElement.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?this.audioElement.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(this.audioElement.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}},xs=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 Cs({...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 ea=i.createContext(null),ta=i.createContext(null),na=i.createContext(null),aa=i.createContext(null),ws=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:s=!1,theme:o,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:d=0,progressBarWidth:v,onReady:p,children:f})=>{const C=v??u+d,[y,m]=i.useState(!1),[g,I]=i.useState(0),[x,h]=i.useState(0),[w,k]=i.useState([]),[A,M]=i.useState(r),[$,E]=i.useState([]),[R,T]=i.useState(null),[D,P]=i.useState(c?.isContinuousPlay??!1),[V]=i.useState(t),[F,N]=i.useState(s),H=i.useRef(null),Z=i.useRef(0),U=i.useRef(null),re=i.useRef(D),ne=i.useRef(null),q=i.useRef(null),ae=i.useRef(s),be=i.useRef(t);i.useEffect(()=>{re.current=D},[D]),i.useEffect(()=>{ae.current=F},[F]);const pe=i.useCallback(K=>{ne.current=K,T(K)},[]),He=i.useCallback(K=>{re.current=K,P(K)},[]),Ve=i.useCallback(K=>{q.current=K},[]),we=e.waveformData.sample_rate;i.useEffect(()=>{const K=new xs({playbackRate:r});K.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const Q=K.getTrack(K.track?.id??"");return Q&&Q.setOnTimeUpdateCallback(le=>{Z.current=le}),K.setOnPlaybackComplete(()=>{m(!1)}),H.current=K,h(e.waveformData.duration),p?.(),()=>{U.current&&cancelAnimationFrame(U.current),K.dispose()}},[e.source,e.waveformData,e.name,r,p]),i.useEffect(()=>{const K=Vn(e.waveformData,V,0,0,Math.ceil(e.waveformData.duration*we)),Q={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:K.length,data:[K.data],bits:K.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*we)};k([[Q]])},[e.waveformData,e.name,V,we]),i.useEffect(()=>{if(c?.annotations){const K=c.annotations.map(Q=>typeof Q.start=="number"?Q:Pn(Q));E(K)}},[c]);const Xe=i.useCallback(()=>{U.current&&cancelAnimationFrame(U.current);const K=()=>{const Q=H.current?.getCurrentTime()??0;if(Z.current=Q,I(Q),$.length>0){const le=$.find(fe=>Q>=fe.start&&Q<fe.end);if(re.current)le&&le.id!==ne.current?pe(le.id):!le&&ne.current!==null&&pe(null);else if(ne.current){const fe=$.find(Ge=>Ge.id===ne.current);if(fe&&Q>=fe.end){H.current?.stop(),m(!1);return}}else le&&pe(le.id)}if(ae.current&&q.current){const le=q.current,fe=Q*we/be.current,Ge=le.clientWidth,Ne=l.show?l.width:0,Pe=fe+Ne,Ke=Math.max(0,Pe-Ge/2);le.scrollLeft=Ke}if(Q>=x){H.current?.stop(),m(!1),pe(null);return}U.current=requestAnimationFrame(K)};U.current=requestAnimationFrame(K)},[x,$,pe,we,l]),L=i.useCallback(()=>{U.current&&(cancelAnimationFrame(U.current),U.current=null)},[]),ce=i.useCallback(K=>{if(!H.current)return;const Q=K??Z.current;H.current.play(void 0,Q),m(!0),Xe()},[Xe]),ee=i.useCallback(()=>{H.current&&(H.current.pause(),m(!1),L(),I(H.current.getCurrentTime()))},[L]),J=i.useCallback(()=>{H.current&&(H.current.stop(),m(!1),L(),Z.current=0,I(0),pe(null))},[L,pe]),ue=i.useCallback(K=>{const Q=Math.max(0,Math.min(K,x));Z.current=Q,I(Q),H.current&&H.current.seekTo(Q)},[x]),ve=i.useCallback(K=>{const Q=Math.max(.5,Math.min(2,K));M(Q),H.current&&H.current.setPlaybackRate(Q)},[]),te=a?30:0,_=i.useMemo(()=>({isPlaying:y,currentTime:g,currentTimeRef:Z}),[y,g]),Ae=i.useMemo(()=>({continuousPlay:D,annotations:$,activeAnnotationId:R,playbackRate:A,isAutomaticScroll:F}),[D,$,R,A,F]),ge=i.useMemo(()=>({play:ce,pause:ee,stop:J,seekTo:ue,setPlaybackRate:ve,setContinuousPlay:He,setAnnotations:E,setActiveAnnotationId:pe,setAutomaticScroll:K=>{N(K)},setScrollContainer:Ve,scrollContainerRef:q}),[ce,ee,J,ue,ve,He,pe,Ve]),de=i.useMemo(()=>({duration:x,peaksDataArray:w,sampleRate:we,waveHeight:n,timeScaleHeight:te,samplesPerPixel:V,playoutRef:H,controls:l,barWidth:u,barGap:d,progressBarWidth:C}),[x,w,we,n,te,V,l,u,d,C]),Oe={...kn,...o};return b.jsx(S.ThemeProvider,{theme:Oe,children:b.jsx(ea.Provider,{value:_,children:b.jsx(ta.Provider,{value:Ae,children:b.jsx(na.Provider,{value:ge,children:b.jsx(aa.Provider,{value:de,children:f})})})})})},It=()=>{const e=i.useContext(ea);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},ra=()=>{const e=i.useContext(ta);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},oa=()=>{const e=i.useContext(na);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},St=()=>{const e=i.useContext(aa);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},ys=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=$e(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=Te(),{play:o}=he(),l=async()=>{if(a!==r&&r>a)if(s)await o(a);else{const u=r-a;await o(a,u)}else await o(n.current??0)};return b.jsx(Be,{onClick:l,disabled:t,className:e,children:"Play"})},ks=({className:e})=>{const{isPlaying:t}=$e(),{pause:n}=he();return b.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Pause"})},Is=({className:e})=>{const{isPlaying:t}=$e(),{stop:n}=he();return b.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Stop"})},Ss=({className:e})=>{const{isPlaying:t}=$e(),{play:n,setCurrentTime:a}=he(),{playoutRef:r}=ke(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return b.jsx(Be,{onClick:s,className:e,children:"Rewind"})},As=({className:e})=>{const{isPlaying:t}=$e(),{play:n,setCurrentTime:a}=he(),{duration:r,playoutRef:s}=ke(),o=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return b.jsx(Be,{onClick:o,className:e,children:"Fast Forward"})},$s=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=$e(),{play:r,setCurrentTime:s}=he(),{playoutRef:o}=ke(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&o.current&&(o.current.stop(),r(c))};return b.jsx(Be,{onClick:l,className:t,children:"Skip Backward"})},Ms=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=$e(),{play:r,setCurrentTime:s}=he(),{duration:o,playoutRef:l}=ke(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),a&&l.current&&(l.current.stop(),r(u))};return b.jsx(Be,{onClick:c,className:t,children:"Skip Forward"})},Rs=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=Te(),{setLoopEnabled:r,setLoopRegion:s}=he(),{duration:o}=ke(),l=n!==a&&a>n,c=()=>{if(!t&&!l){const u=Math.min(10,o*.25);s(0,Math.max(1,u))}r(!t)};return b.jsx(Be,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Es=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=Te(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=he(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?o():s()};return b.jsx(Be,{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"})},Ds=({className:e,disabled:t})=>{const{zoomIn:n}=he(),{canZoomIn:a}=ke();return b.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Bs=({className:e,disabled:t})=>{const{zoomOut:n}=he(),{canZoomOut:a}=ke();return b.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Ts=({className:e})=>{const{masterVolume:t}=ke(),{setMasterVolume:n}=he();return b.jsx(ir,{volume:t,onChange:n,className:e})},Ws=({className:e})=>{const{timeFormat:t}=ke(),{setTimeFormat:n}=he();return b.jsx(Tr,{value:t,onChange:n,className:e})},_s=S.span`
1194
1194
  font-family: 'Courier New', Monaco, monospace;
1195
1195
  font-size: 1rem;
1196
1196
  font-weight: 600;
1197
1197
  color: ${e=>e.theme?.textColor||"#333"};
1198
1198
  user-select: none;
1199
- `,Fs=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:r,currentTimeRef:a,playbackStartTimeRef:s,audioStartPositionRef:o}=Se(),{timeFormat:l}=ye(),c=l;return i.useEffect(()=>{const u=()=>{if(t.current){let d;if(r){const x=W.getContext().currentTime-(s.current??0);d=(o.current??0)+x}else d=a.current??0;t.current.textContent=tt(d,c)}r&&(n.current=requestAnimationFrame(u))};return r?n.current=requestAnimationFrame(u):u(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,c,a,s,o]),i.useEffect(()=>{!r&&t.current&&(t.current.textContent=tt(a.current??0,c))}),v.jsx(_s,{ref:t,className:e,"aria-label":"Audio position",children:tt(a.current??0,c)})},Zs=({className:e})=>{const{selectionStart:t,selectionEnd:n}=We(),{setSelection:r}=me();return v.jsx(va,{selectionStart:t,selectionEnd:n,onSelectionChange:r,className:e})},Vs=({className:e})=>{const{isAutomaticScroll:t}=We(),{setAutomaticScroll:n}=me();return v.jsx(Hr,{checked:t,onChange:n,className:e})},Ps=({className:e})=>{const{continuousPlay:t}=We(),{setContinuousPlay:n}=me();return v.jsx(Mo,{checked:t,onChange:n,className:e})},zs=({className:e})=>{const{linkEndpoints:t}=We(),{setLinkEndpoints:n}=me();return v.jsx(Ro,{checked:t,onChange:n,className:e})},js=({className:e})=>{const{annotationsEditable:t}=We(),{setAnnotationsEditable:n}=me();return v.jsx(Eo,{checked:t,onChange:n,className:e})},Hs=({filename:e,className:t})=>{const{annotations:n}=We();return v.jsx(Bo,{annotations:n,filename:e,className:t})},Xs=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:r,bitDepth:a=16,applyEffects:s=!0,effectsFunction:o,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:d})=>{const{tracks:x,trackStates:g}=ye(),{exportWav:f,isExporting:C,progress:w}=On(),h=async()=>{try{const I=await f(x,g,{filename:t,mode:n,trackIndex:r,bitDepth:a,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(I.blob)}catch(I){d?.(I instanceof Error?I:new Error("Export failed"))}},b=C?`Exporting ${Math.round(w*100)}%`:e;return v.jsx(Te,{onClick:h,disabled:C||x.length===0,className:c,children:b})},Gs=A.div`
1199
+ `,Fs=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:a,currentTimeRef:r,playbackStartTimeRef:s,audioStartPositionRef:o}=$e(),{timeFormat:l}=ke(),c=l;return i.useEffect(()=>{const u=()=>{if(t.current){let d;if(a){const v=W.getContext().currentTime-(s.current??0);d=(o.current??0)+v}else d=r.current??0;t.current.textContent=tt(d,c)}a&&(n.current=requestAnimationFrame(u))};return a?n.current=requestAnimationFrame(u):u(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[a,c,r,s,o]),i.useEffect(()=>{!a&&t.current&&(t.current.textContent=tt(r.current??0,c))}),b.jsx(_s,{ref:t,className:e,"aria-label":"Audio position",children:tt(r.current??0,c)})},Zs=({className:e})=>{const{selectionStart:t,selectionEnd:n}=Te(),{setSelection:a}=he();return b.jsx(vr,{selectionStart:t,selectionEnd:n,onSelectionChange:a,className:e})},Vs=({className:e})=>{const{isAutomaticScroll:t}=Te(),{setAutomaticScroll:n}=he();return b.jsx(Ha,{checked:t,onChange:n,className:e})},Ps=({className:e})=>{const{continuousPlay:t}=Te(),{setContinuousPlay:n}=he();return b.jsx(Mo,{checked:t,onChange:n,className:e})},zs=({className:e})=>{const{linkEndpoints:t}=Te(),{setLinkEndpoints:n}=he();return b.jsx(Ro,{checked:t,onChange:n,className:e})},js=({className:e})=>{const{annotationsEditable:t}=Te(),{setAnnotationsEditable:n}=he();return b.jsx(Eo,{checked:t,onChange:n,className:e})},Hs=({filename:e,className:t})=>{const{annotations:n}=Te();return b.jsx(Bo,{annotations:n,filename:e,className:t})},Xs=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:a,bitDepth:r=16,applyEffects:s=!0,effectsFunction:o,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:d})=>{const{tracks:v,trackStates:p}=ke(),{exportWav:f,isExporting:C,progress:y}=On(),m=async()=>{try{const I=await f(v,p,{filename:t,mode:n,trackIndex:a,bitDepth:r,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(I.blob)}catch(I){d?.(I instanceof Error?I:new Error("Export failed"))}},g=C?`Exporting ${Math.round(y*100)}%`:e;return b.jsx(Be,{onClick:m,disabled:C||v.length===0,className:c,children:g})},Gs=S.div`
1200
1200
  position: absolute;
1201
1201
  top: 0;
1202
1202
  left: 0;
@@ -1206,9 +1206,9 @@
1206
1206
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
1207
1207
  pointer-events: none;
1208
1208
  will-change: transform;
1209
- `,Ns=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),r=i.useRef(null),{isPlaying:a,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=Se(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:d}=ye();return i.useEffect(()=>{const x=()=>{if(n.current){let g;if(a){const C=W.getContext().currentTime-(o.current??0);g=(l.current??0)+C}else g=s.current??0;const f=g*u/c+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}a&&(r.current=requestAnimationFrame(x))};return a?r.current=requestAnimationFrame(x):x(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[a,u,c,t,s,o,l]),i.useEffect(()=>{if(!a&&n.current){const g=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${g}px, 0, 0)`}}),v.jsx(Gs,{ref:n,$color:e,$width:d,"data-playhead":!0})},Ls=A.div`
1209
+ `,Ns=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=$e(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:d}=ke();return i.useEffect(()=>{const v=()=>{if(n.current){let p;if(r){const C=W.getContext().currentTime-(o.current??0);p=(l.current??0)+C}else p=s.current??0;const f=p*u/c+t;n.current.style.transform=`translate3d(${f}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,s,o,l]),i.useEffect(()=>{if(!r&&n.current){const p=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${p}px, 0, 0)`}}),b.jsx(Gs,{ref:n,$color:e,$width:d,"data-playhead":!0})},Ls=S.div`
1210
1210
  position: relative;
1211
- `,Ys=A.div`
1211
+ `,Ys=S.div`
1212
1212
  position: absolute;
1213
1213
  top: ${e=>e.$top}px;
1214
1214
  left: 0;
@@ -1220,7 +1220,7 @@
1220
1220
  transform: translateZ(0);
1221
1221
  backface-visibility: hidden;
1222
1222
  will-change: transform;
1223
- `,Os=A.div`
1223
+ `,Os=S.div`
1224
1224
  position: absolute;
1225
1225
  top: ${e=>e.$top}px;
1226
1226
  left: 0;
@@ -1229,10 +1229,10 @@
1229
1229
  pointer-events: none;
1230
1230
  z-index: 1;
1231
1231
  will-change: width;
1232
- `,Ks=A.div`
1232
+ `,Ks=S.div`
1233
1233
  position: relative;
1234
1234
  z-index: 2;
1235
- `,mn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=i.useRef(null),a=i.useRef(null),s=it(),{waveHeight:o}=st(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=Se(),{samplesPerPixel:x,sampleRate:g}=ye(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const b=()=>{if(r.current){let I;if(l){const k=W.getContext().currentTime-(u.current??0);I=(d.current??0)+k}else I=c.current??0;const p=I*g,m=e+t;let y=0;if(p<=e)y=0;else if(p>=m)y=n.length;else{const k=p-e;y=Math.floor(k/x)}r.current.style.width=`${y}px`}l&&(a.current=requestAnimationFrame(b))};return l?a.current=requestAnimationFrame(b):b(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[l,g,x,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&r.current){const I=(c.current??0)*g,p=e+t;let m=0;if(I<=e)m=0;else if(I>=p)m=n.length;else{const y=I-e;m=Math.floor(y/x)}r.current.style.width=`${m}px`}});const C=s?.waveformDrawMode||"inverted";let w;C==="inverted"?w=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":w=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const h=Ke(w);return v.jsxs(Ls,{children:[v.jsx(Ys,{$color:h,$height:o,$top:n.index*o,$width:n.length}),v.jsx(Os,{ref:r,$color:f,$height:o,$top:n.index*o}),v.jsx(Ks,{children:v.jsx(Bn,{...n,transparentBackground:!0})})]})},Us=60,Js=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,annotationListConfig:a,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,scrollActivePosition:c="center",className:u,showClipHeaders:d=!1,interactiveClips:x=!1,showFades:g=!1,touchOptimized:f=!1,recordingState:C})=>{const w=it(),{isPlaying:h,currentTimeRef:b,playbackStartTimeRef:I,audioStartPositionRef:p}=Se(),{selectionStart:m,selectionEnd:y,annotations:k,activeAnnotationId:S,annotationsEditable:$,linkEndpoints:E,continuousPlay:R,selectedTrackId:M,loopStart:B,loopEnd:D,isLoopEnabled:z}=We(),{setAnnotations:V,setActiveAnnotationId:F,setTrackMute:K,setTrackSolo:H,setTrackVolume:Z,setTrackPan:L,setSelection:ae,play:ne,setScrollContainer:Q,setSelectedTrackId:re,setCurrentTime:be,setLoopRegion:ve}=me(),{audioBuffers:He,peaksDataArray:_e,trackStates:Ae,tracks:Y,duration:ce,samplesPerPixel:ee,sampleRate:q,waveHeight:de,timeScaleHeight:Ce,controls:te,playoutRef:Fe,barWidth:_,barGap:$e}=ye(),[ue,he]=i.useState(!1),Je=i.useRef(null),O=i.useCallback(X=>{Je.current=X,Q(X)},[Q]);let U=He.length>0?ce:Us;if(C?.isRecording){const J=(C.startSample+C.durationSamples)/q;U=Math.max(U,J+10)}const se=Math.floor(U*q/ee),xe=async X=>{console.log("Annotation clicked:",X.id),F(X.id);const J=R?void 0:X.end-X.start;await ne(X.start,J)},ze=i.useCallback(X=>{if(X>=0&&X<Y.length){const J=Y[X];re(J.id)}},[Y,re]),qe=X=>{const J=X.currentTarget.getBoundingClientRect(),oe=te.show?te.width:0,ke=(X.clientX-J.left-oe)*ee/q,ie=X.clientY-J.top;let Me=0,Ie=-1;for(let Ne=0;Ne<_e.length;Ne++){const Le=_e[Ne],je=(Le.length>0?Math.max(...Le.map(At=>At.peaks.data.length)):1)*de+(d?22:0);if(ie>=Me&&ie<Me+je){Ie=Ne;break}Me+=je}Ie!==-1&&ze(Ie),he(!0),be(ke),ae(ke,ke)},Xe=X=>{if(!ue)return;const J=X.currentTarget.getBoundingClientRect(),oe=te.show?te.width:0,ke=(X.clientX-J.left-oe)*ee/q,Ze=Math.min(m,ke),ie=Math.max(m,ke);ae(Ze,ie)},Ye=X=>{if(!ue)return;he(!1);const J=X.currentTarget.getBoundingClientRect(),oe=te.show?te.width:0,ke=(X.clientX-J.left-oe)*ee/q,Ze=Math.min(m,ke),ie=Math.max(m,ke);Math.abs(ie-Ze)<.1?(be(Ze),h&&Fe.current?(Fe.current.stop(),ne(Ze)):Fe.current&&Fe.current.stop()):ae(Ze,ie)};return Y.some(X=>X.clips.length>0)&&(He.length===0||_e.length===0)?v.jsx("div",{className:u,children:"Loading waveform..."}):v.jsx(En,{children:v.jsxs(wt.Provider,{value:{samplesPerPixel:ee,sampleRate:q,zoomLevels:[ee],waveHeight:de,timeScaleHeight:Ce,duration:U,controls:te,barWidth:_,barGap:$e},children:[v.jsx(Pt,{theme:w,backgroundColor:Ke(w.waveOutlineColor),timescaleBackgroundColor:w.timescaleBackgroundColor,scrollContainerWidth:se+(te.show?te.width:0),timescaleWidth:se,tracksWidth:se,controlsWidth:te.show?te.width:0,onTracksMouseDown:qe,onTracksMouseMove:Xe,onTracksMouseUp:Ye,scrollContainerRef:O,isSelecting:ue,timescale:Ce>0?v.jsxs(v.Fragment,{children:[v.jsx(Tn,{duration:U*1e3,marker:1e4,bigStep:5e3,secondStep:1e3,renderTimestamp:t}),z&&v.jsx(ba,{startPosition:Math.min(B,D)*q/ee,endPosition:Math.max(B,D)*q/ee,markerColor:w.loopMarkerColor,regionColor:w.loopRegionColor,minPosition:0,maxPosition:se,controlsOffset:te.show?te.width:0,onLoopRegionChange:(X,J)=>{const oe=X*ee/q,pe=J*ee/q;ve(oe,pe)}})]}):void 0,children:v.jsxs(v.Fragment,{children:[_e.map((X,J)=>{const oe=Y[J];if(!oe)return null;const pe=Ae[J]||{name:`Track ${J+1}`,muted:!1,soloed:!1,volume:1,pan:0},ke=e?e(J):v.jsxs(Va,{onClick:()=>ze(J),children:[v.jsx(Pa,{style:{justifyContent:"center"},children:pe.name||`Track ${J+1}`}),v.jsxs(Za,{children:[v.jsx(nn,{$variant:pe.muted?"danger":"outline",onClick:()=>K(J,!pe.muted),children:"Mute"}),v.jsx(nn,{$variant:pe.soloed?"info":"outline",onClick:()=>H(J,!pe.soloed),children:"Solo"})]}),v.jsxs(an,{children:[v.jsx(za,{}),v.jsx(rn,{min:"0",max:"1",step:"0.01",value:pe.volume,onChange:ie=>Z(J,parseFloat(ie.target.value))}),v.jsx(ja,{})]}),v.jsxs(an,{children:[v.jsx("span",{children:"L"}),v.jsx(rn,{min:"-1",max:"1",step:"0.01",value:pe.pan,onChange:ie=>L(J,parseFloat(ie.target.value))}),v.jsx("span",{children:"R"})]})]}),Ze=X.length>0?Math.max(...X.map(ie=>ie.peaks.data.length)):1;return v.jsx(zt.Provider,{value:ke,children:v.jsxs(Wn,{numChannels:Ze,backgroundColor:Ke(w.waveOutlineColor),offset:0,width:se,hasClipHeaders:d,trackId:oe.id,isSelected:oe.id===M,children:[X.map((ie,Me)=>{const Ie=ie.peaks,Ne=Ie.length;return v.jsx(Wt,{clipId:ie.clipId,trackIndex:J,clipIndex:Me,trackName:ie.trackName,startSample:ie.startSample,durationSamples:ie.durationSamples,samplesPerPixel:ee,showHeader:d,disableHeaderDrag:!x,isSelected:oe.id===M,trackId:oe.id,fadeIn:ie.fadeIn,fadeOut:ie.fadeOut,sampleRate:q,showFades:g,touchOptimized:f,onMouseDown:Le=>{Le.target.closest('[role="button"][aria-roledescription="draggable"]')||ze(J)},children:Ie.data.map((Le,Qe)=>v.jsx(mn,{index:Qe,data:Le,bits:Ie.bits,length:Ne,isSelected:oe.id===M,clipStartSample:ie.startSample,clipDurationSamples:ie.durationSamples},`${J}-${Me}-${Qe}`))},`${J}-${Me}`)}),C?.isRecording&&C.trackId===oe.id&&C.peaks.length>0&&v.jsx(Wt,{clipId:"recording-preview",trackIndex:J,clipIndex:X.length,trackName:"Recording...",startSample:C.startSample,durationSamples:C.durationSamples,samplesPerPixel:ee,showHeader:d,disableHeaderDrag:!0,isSelected:oe.id===M,trackId:oe.id,children:v.jsx(mn,{index:0,data:C.peaks,bits:16,length:Math.floor(C.peaks.length/2),isSelected:oe.id===M,clipStartSample:C.startSample,clipDurationSamples:C.durationSamples},`${J}-recording-0`)},`${J}-recording`)]})},oe.id)}),k.length>0&&v.jsx(jn,{height:30,width:se,children:k.map((X,J)=>{const oe=X.start*q/ee,pe=X.end*q/ee,ke=l?l(X,J):X.id;return v.jsx(zn,{annotationId:X.id,annotationIndex:J,startPosition:oe,endPosition:pe,label:ke,color:"#ff9800",isActive:X.id===S,onClick:()=>xe(X),editable:$},X.id)})}),m!==y&&v.jsx($n,{startPosition:Math.min(m,y)*q/ee+(te.show?te.width:0),endPosition:Math.max(m,y)*q/ee+(te.show?te.width:0),color:w.selectionColor}),(h||m===y)&&(n?n({position:(b.current??0)*q/ee+(te.show?te.width:0),color:w.playheadColor,isPlaying:h,currentTimeRef:b,playbackStartTimeRef:I,audioStartPositionRef:p,samplesPerPixel:ee,sampleRate:q,controlsOffset:te.show?te.width:0,getAudioContextTime:()=>W.getContext().currentTime}):v.jsx(Ns,{color:w.playheadColor,controlsOffset:te.show?te.width:0}))]})}),k.length>0&&v.jsx(Hn,{annotations:k,activeAnnotationId:S??void 0,shouldScrollToActive:!0,scrollActivePosition:c,editable:$,controls:$?r:void 0,annotationListConfig:{linkEndpoints:E,continuousPlay:R},height:s,renderAnnotationItem:o,onAnnotationUpdate:X=>{V(X)}})]})})},qs=A.div`
1235
+ `,mn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=it(),{waveHeight:o}=st(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=$e(),{samplesPerPixel:v,sampleRate:p}=ke(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const g=()=>{if(a.current){let I;if(l){const k=W.getContext().currentTime-(u.current??0);I=(d.current??0)+k}else I=c.current??0;const x=I*p,h=e+t;let w=0;if(x<=e)w=0;else if(x>=h)w=n.length;else{const k=x-e;w=Math.floor(k/v)}a.current.style.width=`${w}px`}l&&(r.current=requestAnimationFrame(g))};return l?r.current=requestAnimationFrame(g):g(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,p,v,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&a.current){const I=(c.current??0)*p,x=e+t;let h=0;if(I<=e)h=0;else if(I>=x)h=n.length;else{const w=I-e;h=Math.floor(w/v)}a.current.style.width=`${h}px`}});const C=s?.waveformDrawMode||"inverted";let y;C==="inverted"?y=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":y=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const m=qe(y);return b.jsxs(Ls,{children:[b.jsx(Ys,{$color:m,$height:o,$top:n.index*o,$width:n.length}),b.jsx(Os,{ref:a,$color:f,$height:o,$top:n.index*o}),b.jsx(Ks,{children:b.jsx(Bn,{...n,transparentBackground:!0})})]})},Us=60,Js=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:d,showClipHeaders:v=!1,interactiveClips:p=!1,showFades:f=!1,touchOptimized:C=!1,recordingState:y})=>{const m=it(),{isPlaying:g,currentTimeRef:I,playbackStartTimeRef:x,audioStartPositionRef:h}=$e(),{selectionStart:w,selectionEnd:k,annotations:A,activeAnnotationId:M,annotationsEditable:$,linkEndpoints:E,continuousPlay:R,selectedTrackId:T,loopStart:D,loopEnd:P,isLoopEnabled:V}=Te(),{setAnnotations:F,setActiveAnnotationId:N,setTrackMute:H,setTrackSolo:Z,setTrackVolume:U,setTrackPan:re,setSelection:ne,play:q,setScrollContainer:ae,setSelectedTrackId:be,setCurrentTime:pe,setLoopRegion:He}=he(),{audioBuffers:Ve,peaksDataArray:we,trackStates:Xe,tracks:L,duration:ce,samplesPerPixel:ee,sampleRate:J,waveHeight:ue,timeScaleHeight:ve,controls:te,playoutRef:_,barWidth:Ae,barGap:ge}=ke(),[de,Oe]=i.useState(!1),K=i.useRef(null),Q=i.useCallback(X=>{K.current=X,ae(X)},[ae]);let le=Ve.length>0?ce:Us;if(y?.isRecording){const O=(y.startSample+y.durationSamples)/J;le=Math.max(le,O+10)}const fe=Math.floor(le*J/ee),Ge=async X=>{console.log("Annotation clicked:",X.id),N(X.id);const O=R?void 0:X.end-X.start;await q(X.start,O)},Ne=i.useCallback(X=>{if(X>=0&&X<L.length){const O=L[X];be(O.id)}},[L,be]),Pe=X=>{const O=X.currentTarget.getBoundingClientRect(),se=te.show?te.width:0,Ie=(X.clientX-O.left-se)*ee/J,oe=X.clientY-O.top;let Se=0,ze=-1;for(let Le=0;Le<we.length;Le++){const Ye=we[Le],nt=(Ye.length>0?Math.max(...Ye.map(Ue=>Ue.peaks.data.length)):1)*ue+(v?22:0);if(oe>=Se&&oe<Se+nt){ze=Le;break}Se+=nt}ze!==-1&&Ne(ze),Oe(!0),pe(Ie),ne(Ie,Ie)},Ke=X=>{if(!de)return;const O=X.currentTarget.getBoundingClientRect(),se=te.show?te.width:0,Ie=(X.clientX-O.left-se)*ee/J,We=Math.min(w,Ie),oe=Math.max(w,Ie);ne(We,oe)},ct=X=>{if(!de)return;Oe(!1);const O=X.currentTarget.getBoundingClientRect(),se=te.show?te.width:0,Ie=(X.clientX-O.left-se)*ee/J,We=Math.min(w,Ie),oe=Math.max(w,Ie);Math.abs(oe-We)<.1?(pe(We),g&&_.current?(_.current.stop(),q(We)):_.current&&_.current.stop()):ne(We,oe)};return L.some(X=>X.clips.length>0)&&(Ve.length===0||we.length===0)?b.jsx("div",{className:d,children:"Loading waveform..."}):b.jsx(En,{children:b.jsxs(yt.Provider,{value:{samplesPerPixel:ee,sampleRate:J,zoomLevels:[ee],waveHeight:ue,timeScaleHeight:ve,duration:le,controls:te,barWidth:Ae,barGap:ge},children:[b.jsx(Pt,{theme:m,backgroundColor:qe(m.waveOutlineColor),timescaleBackgroundColor:m.timescaleBackgroundColor,scrollContainerWidth:fe+(te.show?te.width:0),timescaleWidth:fe,tracksWidth:fe,controlsWidth:te.show?te.width:0,onTracksMouseDown:Pe,onTracksMouseMove:Ke,onTracksMouseUp:ct,scrollContainerRef:Q,isSelecting:de,timescale:ve>0?b.jsxs(b.Fragment,{children:[b.jsx(Tn,{duration:le*1e3,marker:1e4,bigStep:5e3,secondStep:1e3,renderTimestamp:t}),V&&b.jsx(br,{startPosition:Math.min(D,P)*J/ee,endPosition:Math.max(D,P)*J/ee,markerColor:m.loopMarkerColor,regionColor:m.loopRegionColor,minPosition:0,maxPosition:fe,controlsOffset:te.show?te.width:0,onLoopRegionChange:(X,O)=>{const se=X*ee/J,ye=O*ee/J;He(se,ye)}})]}):void 0,children:b.jsxs(b.Fragment,{children:[we.map((X,O)=>{const se=L[O];if(!se)return null;const ye=Xe[O]||{name:`Track ${O+1}`,muted:!1,soloed:!1,volume:1,pan:0},Ie=e?e(O):b.jsxs(Vr,{onClick:()=>Ne(O),children:[b.jsx(Pr,{style:{justifyContent:"center"},children:ye.name||`Track ${O+1}`}),b.jsxs(Zr,{children:[b.jsx(nn,{$variant:ye.muted?"danger":"outline",onClick:()=>H(O,!ye.muted),children:"Mute"}),b.jsx(nn,{$variant:ye.soloed?"info":"outline",onClick:()=>Z(O,!ye.soloed),children:"Solo"})]}),b.jsxs(rn,{children:[b.jsx(zr,{}),b.jsx(an,{min:"0",max:"1",step:"0.01",value:ye.volume,onChange:oe=>U(O,parseFloat(oe.target.value))}),b.jsx(jr,{})]}),b.jsxs(rn,{children:[b.jsx("span",{children:"L"}),b.jsx(an,{min:"-1",max:"1",step:"0.01",value:ye.pan,onChange:oe=>re(O,parseFloat(oe.target.value))}),b.jsx("span",{children:"R"})]})]}),We=X.length>0?Math.max(...X.map(oe=>oe.peaks.data.length)):1;return b.jsx(zt.Provider,{value:Ie,children:b.jsxs(Wn,{numChannels:We,backgroundColor:qe(m.waveOutlineColor),offset:0,width:fe,hasClipHeaders:v,trackId:se.id,isSelected:se.id===T,children:[X.map((oe,Se)=>{const ze=oe.peaks,Le=ze.length;return b.jsx(Wt,{clipId:oe.clipId,trackIndex:O,clipIndex:Se,trackName:oe.trackName,startSample:oe.startSample,durationSamples:oe.durationSamples,samplesPerPixel:ee,showHeader:v,disableHeaderDrag:!p,isSelected:se.id===T,trackId:se.id,fadeIn:oe.fadeIn,fadeOut:oe.fadeOut,sampleRate:J,showFades:f,touchOptimized:C,onMouseDown:Ye=>{Ye.target.closest('[role="button"][aria-roledescription="draggable"]')||Ne(O)},children:ze.data.map((Ye,_e)=>b.jsx(mn,{index:_e,data:Ye,bits:ze.bits,length:Le,isSelected:se.id===T,clipStartSample:oe.startSample,clipDurationSamples:oe.durationSamples},`${O}-${Se}-${_e}`))},`${O}-${Se}`)}),y?.isRecording&&y.trackId===se.id&&y.peaks.length>0&&b.jsx(Wt,{clipId:"recording-preview",trackIndex:O,clipIndex:X.length,trackName:"Recording...",startSample:y.startSample,durationSamples:y.durationSamples,samplesPerPixel:ee,showHeader:v,disableHeaderDrag:!0,isSelected:se.id===T,trackId:se.id,children:b.jsx(mn,{index:0,data:y.peaks,bits:16,length:Math.floor(y.peaks.length/2),isSelected:se.id===T,clipStartSample:y.startSample,clipDurationSamples:y.durationSamples},`${O}-recording-0`)},`${O}-recording`)]})},se.id)}),A.length>0&&b.jsx(jn,{height:30,width:fe,children:A.map((X,O)=>{const se=X.start*J/ee,ye=X.end*J/ee,Ie=l?l(X,O):X.id;return b.jsx(zn,{annotationId:X.id,annotationIndex:O,startPosition:se,endPosition:ye,label:Ie,color:"#ff9800",isActive:X.id===M,onClick:()=>Ge(X),editable:$},X.id)})}),w!==k&&b.jsx($n,{startPosition:Math.min(w,k)*J/ee+(te.show?te.width:0),endPosition:Math.max(w,k)*J/ee+(te.show?te.width:0),color:m.selectionColor}),(g||w===k)&&(n?n({position:(I.current??0)*J/ee+(te.show?te.width:0),color:m.playheadColor,isPlaying:g,currentTimeRef:I,playbackStartTimeRef:x,audioStartPositionRef:h,samplesPerPixel:ee,sampleRate:J,controlsOffset:te.show?te.width:0,getAudioContextTime:()=>W.getContext().currentTime}):b.jsx(Ns,{color:m.playheadColor,controlsOffset:te.show?te.width:0}))]})}),A.length>0&&b.jsx(Hn,{annotations:A,activeAnnotationId:M??void 0,shouldScrollToActive:!0,scrollActivePosition:c,scrollActiveContainer:u,editable:$,controls:$?a:void 0,annotationListConfig:{linkEndpoints:E,continuousPlay:R},height:s,renderAnnotationItem:o,onAnnotationUpdate:X=>{F(X)}})]})})},qs=S.div`
1236
1236
  position: absolute;
1237
1237
  top: 0;
1238
1238
  left: 0;
@@ -1242,9 +1242,9 @@
1242
1242
  z-index: 100;
1243
1243
  pointer-events: none;
1244
1244
  will-change: transform;
1245
- `,Qs=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),r=i.useRef(null),{isPlaying:a,currentTimeRef:s}=kt(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=It();return i.useEffect(()=>{const u=()=>{if(n.current){const x=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${x}px, 0, 0)`}a&&(r.current=requestAnimationFrame(u))};return a?r.current=requestAnimationFrame(u):u(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[a,l,o,t,s]),i.useEffect(()=>{if(!a&&n.current){const d=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}}),v.jsx(qs,{ref:n,$color:e,$width:c,"data-playhead":!0})},ei=A.div`
1245
+ `,Qs=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s}=It(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=St();return i.useEffect(()=>{const u=()=>{if(n.current){const v=(s.current??0)*l/o+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,o,t,s]),i.useEffect(()=>{if(!r&&n.current){const d=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}}),b.jsx(qs,{ref:n,$color:e,$width:c,"data-playhead":!0})},ei=S.div`
1246
1246
  position: relative;
1247
- `,ti=A.div`
1247
+ `,ti=S.div`
1248
1248
  position: absolute;
1249
1249
  top: ${e=>e.$top}px;
1250
1250
  left: 0;
@@ -1255,7 +1255,7 @@
1255
1255
  transform: translateZ(0);
1256
1256
  backface-visibility: hidden;
1257
1257
  will-change: transform;
1258
- `,ni=A.div`
1258
+ `,ni=S.div`
1259
1259
  position: absolute;
1260
1260
  top: ${e=>e.$top}px;
1261
1261
  left: 0;
@@ -1264,8 +1264,8 @@
1264
1264
  pointer-events: none;
1265
1265
  z-index: 1;
1266
1266
  will-change: width;
1267
- `,ri=A.div`
1267
+ `,ai=S.div`
1268
1268
  position: relative;
1269
1269
  z-index: 2;
1270
- `,ai=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=i.useRef(null),a=i.useRef(null),s=it(),{waveHeight:o}=st(),{isPlaying:l,currentTimeRef:c}=kt(),{samplesPerPixel:u,sampleRate:d}=It(),x=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const w=()=>{if(r.current){const b=(c.current??0)*d,I=e+t;let p=0;if(b<=e)p=0;else if(b>=I)p=n.length;else{const m=b-e;p=Math.floor(m/u)}r.current.style.width=`${p}px`}l&&(a.current=requestAnimationFrame(w))};return l?a.current=requestAnimationFrame(w):w(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[l,d,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&r.current){const h=(c.current??0)*d,b=e+t;let I=0;if(h<=e)I=0;else if(h>=b)I=n.length;else{const p=h-e;I=Math.floor(p/u)}r.current.style.width=`${I}px`}});const g=s?.waveformDrawMode||"inverted";let f;g==="inverted"?f=s?.selectedWaveFillColor||s?.waveFillColor||"white":f=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const C=Ke(f);return v.jsxs(ei,{children:[v.jsx(ti,{$color:C,$height:o,$top:n.index*o,$width:n.length}),v.jsx(ni,{ref:r,$color:x,$height:o,$top:n.index*o}),v.jsx(ri,{children:v.jsx(Bn,{...n,isSelected:!0,transparentBackground:!0})})]})},oi=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:r=!1,onAnnotationUpdate:a,scrollActivePosition:s="center",className:o})=>{const l=it(),{isPlaying:c,currentTimeRef:u}=kt(),{annotations:d,activeAnnotationId:x,continuousPlay:g}=ar(),{play:f,seekTo:C,setActiveAnnotationId:w,setAnnotations:h,setScrollContainer:b}=or(),{duration:I,peaksDataArray:p,sampleRate:m,waveHeight:y,timeScaleHeight:k,samplesPerPixel:S,controls:$,playoutRef:E,barWidth:R,barGap:M}=It(),[B,D]=i.useState(0),[z,V]=i.useState(0),[F,K]=i.useState(!1),H=i.useRef(null),Z=i.useCallback(Y=>{H.current=Y,b(Y)},[b]),L=Math.floor(I*m/S),ae=i.useCallback(async Y=>{w(Y.id),f(Y.start)},[w,f]),ne=i.useCallback(Y=>{h(Y),a?.(Y)},[h,a]),{onDragStart:Q,onDragMove:re,onDragEnd:be}=Yn({annotations:d,onAnnotationsChange:ne,samplesPerPixel:S,sampleRate:m,duration:I,linkEndpoints:!0}),ve=i.useCallback(Y=>{const ce=Y.currentTarget.getBoundingClientRect(),ee=$.show?$.width:0,de=(Y.clientX-ce.left-ee)*S/m;K(!0),D(de),V(de)},[$,S,m]),He=i.useCallback(Y=>{if(!F)return;const ce=Y.currentTarget.getBoundingClientRect(),ee=$.show?$.width:0,de=(Y.clientX-ce.left-ee)*S/m;V(de)},[F,$,S,m]),_e=i.useCallback(Y=>{if(!F)return;K(!1);const ce=Y.currentTarget.getBoundingClientRect(),ee=$.show?$.width:0,de=(Y.clientX-ce.left-ee)*S/m,Ce=Math.min(B,de),te=Math.max(B,de);Math.abs(te-Ce)<.1?(C(Ce),D(Ce),V(Ce),c&&E.current&&(E.current.stop(),f(Ce))):(D(Ce),V(te))},[F,B,S,m,$,C,c,E,f]);if(p.length===0)return v.jsx("div",{className:o,children:"Loading waveform..."});const Ae=null;return v.jsx(En,{children:v.jsxs(wt.Provider,{value:{samplesPerPixel:S,sampleRate:m,zoomLevels:[S],waveHeight:y,timeScaleHeight:k,duration:I,controls:$,barWidth:R,barGap:M},children:[v.jsx(Pt,{theme:l,backgroundColor:Ke(l.waveOutlineColor),timescaleBackgroundColor:l.timescaleBackgroundColor,scrollContainerWidth:L+($.show?$.width:0),timescaleWidth:L,tracksWidth:L,controlsWidth:$.show?$.width:0,onTracksMouseDown:ve,onTracksMouseMove:He,onTracksMouseUp:_e,scrollContainerRef:Z,isSelecting:F,timescale:k>0?v.jsx(Tn,{duration:I*1e3,marker:1e4,bigStep:5e3,secondStep:1e3}):void 0,children:v.jsxs(v.Fragment,{children:[p.map((Y,ce)=>{const ee=Y.length>0?Math.max(...Y.map(q=>q.peaks.data.length)):1;return v.jsx(zt.Provider,{value:Ae,children:v.jsx(Wn,{numChannels:ee,backgroundColor:Ke(l.waveOutlineColor),offset:0,width:L,hasClipHeaders:!1,trackId:`media-element-track-${ce}`,isSelected:!0,children:Y.map((q,de)=>{const Ce=q.peaks,te=Ce.length;return v.jsx(Wt,{clipId:q.clipId,trackIndex:ce,clipIndex:de,trackName:q.trackName,startSample:q.startSample,durationSamples:q.durationSamples,samplesPerPixel:S,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${ce}`,children:Ce.data.map((Fe,_)=>v.jsx(ai,{index:_,data:Fe,bits:Ce.bits,length:te,clipStartSample:q.startSample,clipDurationSamples:q.durationSamples},`${ce}-${de}-${_}`))},`${ce}-${de}`)})})},ce)}),d.length>0&&v.jsx(De.DndContext,{onDragStart:Q,onDragMove:re,onDragEnd:be,modifiers:r?[Dr.restrictToHorizontalAxis]:[],children:v.jsx(jn,{height:30,width:L,children:d.map((Y,ce)=>{const ee=Y.start*m/S,q=Y.end*m/S,de=t?t(Y,ce):Y.id;return v.jsx(zn,{annotationId:Y.id,annotationIndex:ce,startPosition:ee,endPosition:q,label:de,color:"#ff9800",isActive:Y.id===x,onClick:()=>ae(Y),editable:r},Y.id)})})}),B!==z&&v.jsx($n,{startPosition:Math.min(B,z)*m/S+($.show?$.width:0),endPosition:Math.max(B,z)*m/S+($.show?$.width:0),color:l.selectionColor}),v.jsx(Qs,{color:l.playheadColor,controlsOffset:$.show?$.width:0})]})}),d.length>0&&v.jsx(Hn,{annotations:d,activeAnnotationId:x??void 0,shouldScrollToActive:!0,scrollActivePosition:s,editable:r,annotationListConfig:{linkEndpoints:!0,continuousPlay:g},height:e,onAnnotationUpdate:ne,renderAnnotationItem:n})]})})};exports.Tone=pn;exports.AudioPosition=Fs;exports.AutomaticScrollCheckbox=Vs;exports.ContinuousPlayCheckbox=Ps;exports.DownloadAnnotationsButton=Hs;exports.EditableCheckbox=js;exports.ExportWavButton=Xs;exports.FastForwardButton=As;exports.LinkEndpointsCheckbox=zs;exports.LoopButton=Rs;exports.MasterVolumeControl=Ts;exports.MediaElementPlaylistProvider=ws;exports.MediaElementWaveform=oi;exports.PauseButton=ks;exports.PlayButton=ys;exports.RewindButton=Ss;exports.SelectionTimeInputs=Zs;exports.SetLoopRegionButton=Es;exports.SkipBackwardButton=$s;exports.SkipForwardButton=Ms;exports.StopButton=Is;exports.TimeFormatSelect=Ws;exports.Waveform=Js;exports.WaveformPlaylistProvider=bs;exports.ZoomInButton=Ds;exports.ZoomOutButton=Bs;exports.createEffectChain=cs;exports.createEffectInstance=ot;exports.effectCategories=os;exports.effectDefinitions=lt;exports.getEffectDefinition=Ht;exports.getEffectsByCategory=as;exports.getShortcutLabel=Ho;exports.getWaveformDataMetadata=co;exports.loadPeaksFromWaveformData=lo;exports.loadWaveformData=jt;exports.useAnnotationDragHandlers=Yn;exports.useAnnotationKeyboardControls=Go;exports.useAudioTracks=Zo;exports.useClipDragHandlers=Vo;exports.useClipSplitting=jo;exports.useDragSensors=zo;exports.useDynamicEffects=us;exports.useExportWav=On;exports.useIntegratedRecording=rs;exports.useKeyboardShortcuts=bt;exports.useMasterAnalyser=Wo;exports.useMasterVolume=Nn;exports.useMediaElementAnimation=kt;exports.useMediaElementControls=or;exports.useMediaElementData=It;exports.useMediaElementState=ar;exports.usePlaybackAnimation=Se;exports.usePlaybackShortcuts=Xo;exports.usePlaylistControls=me;exports.usePlaylistData=ye;exports.usePlaylistState=We;exports.useTimeFormat=Xn;exports.useTrackDynamicEffects=ds;exports.useWaveformPlaylist=vs;exports.useZoomControls=Gn;exports.waveformDataToPeaks=Zn;
1270
+ `,ri=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=it(),{waveHeight:o}=st(),{isPlaying:l,currentTimeRef:c}=It(),{samplesPerPixel:u,sampleRate:d}=St(),v=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const y=()=>{if(a.current){const g=(c.current??0)*d,I=e+t;let x=0;if(g<=e)x=0;else if(g>=I)x=n.length;else{const h=g-e;x=Math.floor(h/u)}a.current.style.width=`${x}px`}l&&(r.current=requestAnimationFrame(y))};return l?r.current=requestAnimationFrame(y):y(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,d,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&a.current){const m=(c.current??0)*d,g=e+t;let I=0;if(m<=e)I=0;else if(m>=g)I=n.length;else{const x=m-e;I=Math.floor(x/u)}a.current.style.width=`${I}px`}});const p=s?.waveformDrawMode||"inverted";let f;p==="inverted"?f=s?.selectedWaveFillColor||s?.waveFillColor||"white":f=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const C=qe(f);return b.jsxs(ei,{children:[b.jsx(ti,{$color:C,$height:o,$top:n.index*o,$width:n.length}),b.jsx(ni,{ref:a,$color:v,$height:o,$top:n.index*o}),b.jsx(ai,{children:b.jsx(Bn,{...n,isSelected:!0,transparentBackground:!0})})]})},oi=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:a=!1,onAnnotationUpdate:r,scrollActivePosition:s="center",scrollActiveContainer:o="nearest",className:l})=>{const c=it(),{isPlaying:u,currentTimeRef:d}=It(),{annotations:v,activeAnnotationId:p,continuousPlay:f}=ra(),{play:C,seekTo:y,setActiveAnnotationId:m,setAnnotations:g,setScrollContainer:I}=oa(),{duration:x,peaksDataArray:h,sampleRate:w,waveHeight:k,timeScaleHeight:A,samplesPerPixel:M,controls:$,playoutRef:E,barWidth:R,barGap:T}=St(),[D,P]=i.useState(0),[V,F]=i.useState(0),[N,H]=i.useState(!1),Z=i.useRef(null),U=i.useCallback(L=>{Z.current=L,I(L)},[I]),re=Math.floor(x*w/M),ne=i.useCallback(async L=>{m(L.id),C(L.start)},[m,C]),q=i.useCallback(L=>{g(L),r?.(L)},[g,r]),{onDragStart:ae,onDragMove:be,onDragEnd:pe}=Yn({annotations:v,onAnnotationsChange:q,samplesPerPixel:M,sampleRate:w,duration:x,linkEndpoints:!0}),He=i.useCallback(L=>{const ce=L.currentTarget.getBoundingClientRect(),ee=$.show?$.width:0,ue=(L.clientX-ce.left-ee)*M/w;H(!0),P(ue),F(ue)},[$,M,w]),Ve=i.useCallback(L=>{if(!N)return;const ce=L.currentTarget.getBoundingClientRect(),ee=$.show?$.width:0,ue=(L.clientX-ce.left-ee)*M/w;F(ue)},[N,$,M,w]),we=i.useCallback(L=>{if(!N)return;H(!1);const ce=L.currentTarget.getBoundingClientRect(),ee=$.show?$.width:0,ue=(L.clientX-ce.left-ee)*M/w,ve=Math.min(D,ue),te=Math.max(D,ue);Math.abs(te-ve)<.1?(y(ve),P(ve),F(ve),u&&E.current&&(E.current.stop(),C(ve))):(P(ve),F(te))},[N,D,M,w,$,y,u,E,C]);if(h.length===0)return b.jsx("div",{className:l,children:"Loading waveform..."});const Xe=null;return b.jsx(En,{children:b.jsxs(yt.Provider,{value:{samplesPerPixel:M,sampleRate:w,zoomLevels:[M],waveHeight:k,timeScaleHeight:A,duration:x,controls:$,barWidth:R,barGap:T},children:[b.jsx(Pt,{theme:c,backgroundColor:qe(c.waveOutlineColor),timescaleBackgroundColor:c.timescaleBackgroundColor,scrollContainerWidth:re+($.show?$.width:0),timescaleWidth:re,tracksWidth:re,controlsWidth:$.show?$.width:0,onTracksMouseDown:He,onTracksMouseMove:Ve,onTracksMouseUp:we,scrollContainerRef:U,isSelecting:N,timescale:A>0?b.jsx(Tn,{duration:x*1e3,marker:1e4,bigStep:5e3,secondStep:1e3}):void 0,children:b.jsxs(b.Fragment,{children:[h.map((L,ce)=>{const ee=L.length>0?Math.max(...L.map(J=>J.peaks.data.length)):1;return b.jsx(zt.Provider,{value:Xe,children:b.jsx(Wn,{numChannels:ee,backgroundColor:qe(c.waveOutlineColor),offset:0,width:re,hasClipHeaders:!1,trackId:`media-element-track-${ce}`,isSelected:!0,children:L.map((J,ue)=>{const ve=J.peaks,te=ve.length;return b.jsx(Wt,{clipId:J.clipId,trackIndex:ce,clipIndex:ue,trackName:J.trackName,startSample:J.startSample,durationSamples:J.durationSamples,samplesPerPixel:M,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${ce}`,children:ve.data.map((_,Ae)=>b.jsx(ri,{index:Ae,data:_,bits:ve.bits,length:te,clipStartSample:J.startSample,clipDurationSamples:J.durationSamples},`${ce}-${ue}-${Ae}`))},`${ce}-${ue}`)})})},ce)}),v.length>0&&b.jsx(Ee.DndContext,{onDragStart:ae,onDragMove:be,onDragEnd:pe,modifiers:a?[Da.restrictToHorizontalAxis]:[],children:b.jsx(jn,{height:30,width:re,children:v.map((L,ce)=>{const ee=L.start*w/M,J=L.end*w/M,ue=t?t(L,ce):L.id;return b.jsx(zn,{annotationId:L.id,annotationIndex:ce,startPosition:ee,endPosition:J,label:ue,color:"#ff9800",isActive:L.id===p,onClick:()=>ne(L),editable:a},L.id)})})}),D!==V&&b.jsx($n,{startPosition:Math.min(D,V)*w/M+($.show?$.width:0),endPosition:Math.max(D,V)*w/M+($.show?$.width:0),color:c.selectionColor}),b.jsx(Qs,{color:c.playheadColor,controlsOffset:$.show?$.width:0})]})}),v.length>0&&b.jsx(Hn,{annotations:v,activeAnnotationId:p??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:o,editable:a,annotationListConfig:{linkEndpoints:!0,continuousPlay:f},height:e,onAnnotationUpdate:q,renderAnnotationItem:n})]})})};exports.Tone=pn;exports.AudioPosition=Fs;exports.AutomaticScrollCheckbox=Vs;exports.ContinuousPlayCheckbox=Ps;exports.DownloadAnnotationsButton=Hs;exports.EditableCheckbox=js;exports.ExportWavButton=Xs;exports.FastForwardButton=As;exports.LinkEndpointsCheckbox=zs;exports.LoopButton=Rs;exports.MasterVolumeControl=Ts;exports.MediaElementPlaylistProvider=ws;exports.MediaElementWaveform=oi;exports.PauseButton=ks;exports.PlayButton=ys;exports.RewindButton=Ss;exports.SelectionTimeInputs=Zs;exports.SetLoopRegionButton=Es;exports.SkipBackwardButton=$s;exports.SkipForwardButton=Ms;exports.StopButton=Is;exports.TimeFormatSelect=Ws;exports.Waveform=Js;exports.WaveformPlaylistProvider=bs;exports.ZoomInButton=Ds;exports.ZoomOutButton=Bs;exports.createEffectChain=cs;exports.createEffectInstance=ot;exports.effectCategories=os;exports.effectDefinitions=lt;exports.getEffectDefinition=Ht;exports.getEffectsByCategory=rs;exports.getShortcutLabel=Ho;exports.getWaveformDataMetadata=co;exports.loadPeaksFromWaveformData=lo;exports.loadWaveformData=jt;exports.useAnnotationDragHandlers=Yn;exports.useAnnotationKeyboardControls=Go;exports.useAudioTracks=Zo;exports.useClipDragHandlers=Vo;exports.useClipSplitting=jo;exports.useDragSensors=zo;exports.useDynamicEffects=us;exports.useExportWav=On;exports.useIntegratedRecording=as;exports.useKeyboardShortcuts=vt;exports.useMasterAnalyser=Wo;exports.useMasterVolume=Nn;exports.useMediaElementAnimation=It;exports.useMediaElementControls=oa;exports.useMediaElementData=St;exports.useMediaElementState=ra;exports.usePlaybackAnimation=$e;exports.usePlaybackShortcuts=Xo;exports.usePlaylistControls=he;exports.usePlaylistData=ke;exports.usePlaylistState=Te;exports.useTimeFormat=Xn;exports.useTrackDynamicEffects=ds;exports.useWaveformPlaylist=vs;exports.useZoomControls=Gn;exports.waveformDataToPeaks=Zn;
1271
1271
  //# sourceMappingURL=index.js.map