@waveform-playlist/browser 7.1.3 → 8.1.0
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.d.ts +73 -121
- package/dist/index.js +81 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4110 -3409
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var Ga=Object.create;var kn=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ya=Object.getOwnPropertyNames;var Ua=Object.getPrototypeOf,Ka=Object.prototype.hasOwnProperty;var qa=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ya(t))!Ka.call(e,r)&&r!==n&&kn(e,r,{get:()=>t[r],enumerable:!(a=Na(t,r))||a.enumerable});return e};var Ja=(e,t,n)=>(n=e!=null?Ga(Ua(e)):{},qa(t||!e||!e.__esModule?kn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("tone"),v=require("react/jsx-runtime"),o=require("react"),R=require("styled-components"),Ke=require("@dnd-kit/core"),Hn=require("react-dom"),Qa=require("@dnd-kit/modifiers");function Xn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const On=Xn(Z),T=Xn(o);var ke=1e3;function Gt(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u}=e,m=t?.sampleRate??e.sampleRate??u?.sample_rate,h=t?.length??e.sourceDurationSamples??(u&&m?Math.ceil(u.duration*m):void 0);if(m===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(h===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.durationSamples??h;return{id:Yn(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:a,sampleRate:m,sourceDurationSamples:h,gain:r,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u}}function Gn(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u}=e,m=t?.sampleRate??e.sampleRate??u?.sample_rate;if(m===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const h=t?.duration??e.sourceDuration??u?.duration;if(h===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.duration??h;return Gt({audioBuffer:t,startSample:Math.round(n*m),durationSamples:Math.round(p*m),offsetSamples:Math.round(a*m),sampleRate:m,sourceDurationSamples:Math.ceil(h*m),gain:r,name:s,color:i,fadeIn:l,fadeOut:c,waveformData:u})}function Nn(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:i=0,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:m}=e;return{id:Yn(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:i,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:m}}function Yn(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}var Sn=!1;function Tt(e){const t=e._param;return!t&&!Sn&&(Sn=!0,console.warn("[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Fades and mute scheduling may not work correctly.")),t}function In(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const s=r/a;n[r]=t?s:1-s}return n}function er(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const s=r/a,i=t?r:e-1-r;n[i]=Math.exp(2*s-1)/Math.E}return n}function tr(e,t){const n=new Float32Array(e),a=t?Math.PI/2:-Math.PI/2;for(let r=0;r<e;r++)n[r]=Math.sin(Math.PI*r/e-a)/2+.5;return n}function nr(e,t,n=10){const a=new Float32Array(e);for(let r=0;r<e;r++){const s=t?r:e-1-r,i=r/e;a[s]=Math.log(1+n*i)/Math.log(1+n)}return a}function Un(e,t,n){switch(e){case"linear":return In(t,n);case"exponential":return er(t,n);case"sCurve":return tr(t,n);case"logarithmic":return nr(t,n);default:return In(t,n)}}function An(e,t,n,a="linear",r=0,s=1){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const i=Un(a,1e4,!0),l=new Float32Array(i.length),c=s-r;for(let u=0;u<i.length;u++)l[u]=r+i[u]*c;e.setValueCurveAtTime(l,t,n)}}function Mn(e,t,n,a="linear",r=1,s=0){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const i=Un(a,1e4,!1),l=new Float32Array(i.length),c=r-s;for(let u=0;u<i.length;u++)l[u]=s+i[u]*c;e.setValueCurveAtTime(l,t,n)}}var ar=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new Z.Volume(this.gainToDb(e.track.gain)),this.panNode=new Z.Panner(e.track.stereoPan),this.muteGain=new Z.Gain(e.track.muted?0:1);const t=e.destination||Z.getDestination();if(e.effects){const a=e.effects(this.muteGain,t,!1);a&&(this.effectsCleanup=a)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]);this.clips=n.map(a=>{const r=new Z.Player({url:a.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new Z.Gain(a.gain);return r.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:r,clipInfo:a,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:a,fadeGain:r}=e,s=Tt(r.gain);if(!s)return;s.cancelScheduledValues(0);const i=n-a.offset;if(a.fadeIn&&i<a.fadeIn.duration){const l=a.fadeIn.duration;if(i<=0)An(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-i,u=i/l,m=a.gain*u;An(s,t,c,a.fadeIn.type||"linear",m,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-i;if(c>0){const u=t+c;Mn(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,m=a.fadeOut.duration-u,h=u/a.fadeOut.duration,p=a.gain*(1-h);Mn(s,t,m,a.fadeOut.type||"linear",p,0)}}}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;Tt(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(a=>{a.player.stop(),a.player.disconnect(),a.player.dispose();const r=new Z.Player({url:a.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});r.connect(a.fadeGain),a.player=r,a.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(a=>{const{player:r,clipInfo:s}=a,i=t,l=s.startTime,c=s.startTime+s.duration;if(i<c){this.activePlayers++;const u=e??Z.now();if(a.playStartTime=u,i>=l){const m=i-l+s.offset,h=s.duration-(i-l),p=n?Math.min(n,h):h;a.pausedPosition=m,this.scheduleFades(a,u,m),r.start(u,m,p)}else{const m=l-i,h=n?Math.min(n-m,s.duration):s.duration;m<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+m,s.offset),r.start(u+m,s.offset,h)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(Z.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??Z.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},rr=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this.activeTracks=new Map,this.playbackSessionId=0,this.masterVolume=new Z.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,Z.getDestination(),!1);t&&(this.effectsCleanup=t)}else this.masterVolume.toDestination();e.tracks&&e.tracks.forEach(t=>{this.tracks.set(t.id,t),this.manualMuteState.set(t.id,t.muted)})}gainToDb(e){return 20*Math.log10(e)}async init(){this.isInitialized||(await Z.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new ar(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}applyInitialSoloState(){this.updateSoloMuting()}removeTrack(e){const t=this.tracks.get(e);t&&(t.dispose(),this.tracks.delete(e),this.manualMuteState.delete(e),this.soloedTracks.delete(e))}getTrack(e){return this.tracks.get(e)}play(e,t,n){if(!this.isInitialized){console.warn("TonePlayout not initialized. Call init() first.");return}const a=e??Z.now(),r=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(i=>{const l=i.startTime;if(r>=l){const c=r-l;n!==void 0&&(this.activeTracks.set(i.id,s),i.setOnStopCallback(()=>{this.activeTracks.get(i.id)===s&&(this.activeTracks.delete(i.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),i.play(a,c,n)}else{const c=l-r;n!==void 0&&(this.activeTracks.set(i.id,s),i.setOnStopCallback(()=>{this.activeTracks.get(i.id)===s&&(this.activeTracks.delete(i.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),i.play(a+c,0,n)}}),t!==void 0?Z.getTransport().start(a,t):Z.getTransport().start(a)}pause(){Z.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){Z.getTransport().stop(),this.tracks.forEach(e=>{e.stop()})}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const a=this.manualMuteState.get(n)??!1;t.setMute(a)}else{const a=this.manualMuteState.get(n)??!1;t.setMute(a)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return Z.getTransport().seconds}seekTo(e){Z.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return Z.getContext()}get sampleRate(){return Z.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Mt=null;function or(){return Mt||(Mt=new Z.Context,Z.setContext(Mt)),Mt}function sr(){return or().rawContext}const Nt=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[Nt.Translate.toString(e),Nt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),ir=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128ZM60,112a16,16,0,1,0,16,16A16,16,0,0,0,60,112Zm136,0a16,16,0,1,0,16,16A16,16,0,0,0,196,112Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M240,96v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V96A16,16,0,0,1,32,80H224A16,16,0,0,1,240,96Z",opacity:"0.2"}),T.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M224,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V96A16,16,0,0,0,224,80ZM60,140a12,12,0,1,1,12-12A12,12,0,0,1,60,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,128,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,196,140Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128ZM60,118a10,10,0,1,0,10,10A10,10,0,0,0,60,118Zm136,0a10,10,0,1,0,10,10A10,10,0,0,0,196,118Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Zm-76-8a8,8,0,1,0,8,8A8,8,0,0,0,60,120Zm136,0a8,8,0,1,0,8,8A8,8,0,0,0,196,120Z"}))]]),lr=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),cr=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),ur=new Map([["bold",T.createElement(T.Fragment,null,T.createElement("path",{d:"M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"}))],["duotone",T.createElement(T.Fragment,null,T.createElement("path",{d:"M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z",opacity:"0.2"}),T.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["fill",T.createElement(T.Fragment,null,T.createElement("path",{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["light",T.createElement(T.Fragment,null,T.createElement("path",{d:"M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z"}))],["regular",T.createElement(T.Fragment,null,T.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["thin",T.createElement(T.Fragment,null,T.createElement("path",{d:"M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z"}))]]),dr=o.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),vt=T.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:i,children:l,weights:c,...u}=e,{color:m="currentColor",size:h,weight:p="regular",mirrored:f=!1,...b}=T.useContext(dr);return T.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??h,height:r??h,fill:a??m,viewBox:"0 0 256 256",transform:i||f?"scale(-1, 1)":void 0,...b,...u},!!n&&T.createElement("title",null,n),l,c.get(s??p))});vt.displayName="IconBase";const Kn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:ir}));Kn.displayName="DotsThreeIcon";const qn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:lr}));qn.displayName="SpeakerHighIcon";const Jn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:cr}));Jn.displayName="SpeakerLowIcon";const Qn=T.forwardRef((e,t)=>T.createElement(vt,{ref:t,...e,weights:ur}));Qn.displayName="XIcon";const fr=Qn;R.span`
|
|
1
|
+
"use strict";var fr=Object.create;var Vn=Object.defineProperty;var mr=Object.getOwnPropertyDescriptor;var hr=Object.getOwnPropertyNames;var pr=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var br=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of hr(t))!gr.call(e,r)&&r!==n&&Vn(e,r,{get:()=>t[r],enumerable:!(a=mr(t,r))||a.enumerable});return e};var vr=(e,t,n)=>(n=e!=null?fr(pr(e)):{},br(t||!e||!e.__esModule?Vn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("tone"),v=require("react/jsx-runtime"),i=require("react"),D=require("styled-components"),Oe=require("@dnd-kit/core"),la=require("react-dom"),wr=require("@dnd-kit/modifiers");function ca(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 ua=ca(z),M=ca(i);var Se=1e3;function Ut(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,f=t?.sampleRate??e.sampleRate??u?.sample_rate,h=t?.length??e.sourceDurationSamples??(u&&f?Math.ceil(u.duration*f):void 0);if(f===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(h===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.durationSamples??h;return{id:ma(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:a,sampleRate:f,sourceDurationSamples:h,gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function da(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,f=t?.sampleRate??e.sampleRate??u?.sample_rate;if(f===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const h=t?.duration??e.sourceDuration??u?.duration;if(h===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.duration??h;return Ut({audioBuffer:t,startSample:Math.round(n*f),durationSamples:Math.round(p*f),offsetSamples:Math.round(a*f),sampleRate:f,sourceDurationSamples:Math.ceil(h*f),gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function fa(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:o=0,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:f}=e;return{id:ma(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:o,color:l,height:c,spectrogramConfig:u,spectrogramColorMap:f}}function ma(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Kt(e){return[...e].sort((t,n)=>t.startSample-n.startSample)}function Zn(e){return e.startSample/e.sampleRate}function yr(e){return(e.startSample+e.durationSamples)/e.sampleRate}function Cr(e){return e.offsetSamples/e.sampleRate}function xr(e){return e.durationSamples/e.sampleRate}var Ln=!1;function qt(e){const t=e._param;return!t&&!Ln&&(Ln=!0,console.warn("[waveform-playlist] Unable to access Tone.js internal _param. This likely means the Tone.js version is incompatible. Mute scheduling may not work correctly.")),t}function jn(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 kr(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 Sr(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 _r(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 ha(e,t,n){switch(e){case"linear":return jn(t,n);case"exponential":return kr(t,n);case"sCurve":return Sr(t,n);case"logarithmic":return _r(t,n);default:return jn(t,n)}}function zn(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=ha(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 Hn(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=ha(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 Ir=class{constructor(e){this.activeSources=new Set,this._scheduleGuardOffset=0,this.track=e.track,this.volumeNode=new z.Volume(this.gainToDb(e.track.gain)),this.panNode=new z.Panner(e.track.stereoPan),this.muteGain=new z.Gain(e.track.muted?0:1),this.volumeNode.chain(this.panNode,this.muteGain);const t=e.destination||z.getDestination();if(e.effects){const o=e.effects(this.muteGain,t,!1);o&&(this.effectsCleanup=o)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]),a=z.getTransport(),r=z.getContext().rawContext,s=this.volumeNode.input.input;this.scheduledClips=n.map(o=>{const l=r.createGain();l.gain.value=o.gain,l.connect(s);const c=this.track.startTime+o.startTime,u=a.schedule(f=>{c<this._scheduleGuardOffset||this.startClipSource(o,l,f)},c);return{clipInfo:o,fadeGainNode:l,scheduleId:u}})}startClipSource(e,t,n,a,r){const o=z.getContext().rawContext.createBufferSource();o.buffer=e.buffer,o.connect(t);const l=a??e.offset,c=r??e.duration;try{o.start(n,l,c)}catch(u){console.warn(`[waveform-playlist] Failed to start source on track "${this.id}" (time=${n}, offset=${l}, duration=${c}):`,u),o.disconnect();return}this.activeSources.add(o),o.onended=()=>{this.activeSources.delete(o)}}setScheduleGuardOffset(e){this._scheduleGuardOffset=e}startMidClipSources(e,t){for(const{clipInfo:n,fadeGainNode:a}of this.scheduledClips){const r=this.track.startTime+n.startTime,s=r+n.duration;if(r<e&&s>e){const o=e-r,l=n.offset+o,c=n.duration-o;this.startClipSource(n,a,t,l,c)}}}stopAllSources(){this.activeSources.forEach(e=>{try{e.stop()}catch(t){console.warn(`[waveform-playlist] Error stopping source on track "${this.id}":`,t)}}),this.activeSources.clear()}scheduleFades(e,t,n=0){const{clipInfo:a,fadeGainNode:r}=e,s=r.gain;s.cancelScheduledValues(0);const o=n-a.offset;if(a.fadeIn&&o<a.fadeIn.duration){const l=a.fadeIn.duration;if(o<=0)zn(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-o,u=o/l,f=a.gain*u;zn(s,t,c,a.fadeIn.type||"linear",f,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;Hn(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,f=a.fadeOut.duration-u,h=u/a.fadeOut.duration,p=a.gain*(1-h);Hn(s,t,f,a.fadeOut.type||"linear",p,0)}}}prepareFades(e,t){this.scheduledClips.forEach(n=>{const a=this.track.startTime+n.clipInfo.startTime,r=a+n.clipInfo.duration;if(!(t>=r))if(t>=a){const s=t-a+n.clipInfo.offset;this.scheduleFades(n,e,s)}else{const s=a-t;this.scheduleFades(n,e+s,n.clipInfo.offset)}})}cancelFades(){this.scheduledClips.forEach(({fadeGainNode:e,clipInfo:t})=>{const n=e.gain;n.cancelScheduledValues(0),n.setValueAtTime(t.gain,0)})}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;qt(this.muteGain.gain)?.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}dispose(){const e=z.getTransport();if(this.effectsCleanup)try{this.effectsCleanup()}catch(t){console.warn(`[waveform-playlist] Error during track "${this.id}" effects cleanup:`,t)}this.stopAllSources(),this.scheduledClips.forEach((t,n)=>{try{e.clear(t.scheduleId)}catch(a){console.warn(`[waveform-playlist] Error clearing schedule ${n} on track "${this.id}":`,a)}try{t.fadeGainNode.disconnect()}catch(a){console.warn(`[waveform-playlist] Error disconnecting fadeGain ${n} on track "${this.id}":`,a)}});try{this.volumeNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing volumeNode on track "${this.id}":`,t)}try{this.panNode.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing panNode on track "${this.id}":`,t)}try{this.muteGain.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing muteGain on track "${this.id}":`,t)}}get id(){return this.track.id}get duration(){if(this.scheduledClips.length===0)return 0;const e=this.scheduledClips[this.scheduledClips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.scheduledClips[0]?.clipInfo.buffer}get muted(){return this.track.muted}get startTime(){return this.track.startTime}},Ar=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this._completionEventId=null,this._loopHandler=null,this._loopEnabled=!1,this._loopStart=0,this._loopEnd=0,this.masterVolume=new z.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,z.getDestination(),!1);t&&(this.effectsCleanup=t)}else this.masterVolume.toDestination();e.tracks&&e.tracks.forEach(t=>{this.tracks.set(t.id,t),this.manualMuteState.set(t.id,t.muted)})}gainToDb(e){return 20*Math.log10(e)}clearCompletionEvent(){if(this._completionEventId!==null){try{z.getTransport().clear(this._completionEventId)}catch(e){console.warn("[waveform-playlist] Error clearing Transport completion event:",e)}this._completionEventId=null}}async init(){this.isInitialized||(await z.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new Ir(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}applyInitialSoloState(){this.updateSoloMuting()}removeTrack(e){const t=this.tracks.get(e);t&&(t.dispose(),this.tracks.delete(e),this.manualMuteState.delete(e),this.soloedTracks.delete(e))}getTrack(e){return this.tracks.get(e)}play(e,t,n){if(!this.isInitialized)throw new Error("[waveform-playlist] TonePlayout not initialized. Call init() first.");const a=e??z.now(),r=z.getTransport();this.clearCompletionEvent();const s=t??0;this.tracks.forEach(o=>{o.cancelFades(),o.prepareFades(a,s)}),n!==void 0&&(this._completionEventId=r.scheduleOnce(()=>{this._completionEventId=null;try{this.onPlaybackCompleteCallback?.()}catch(o){console.warn("[waveform-playlist] Error in playback completion callback:",o)}},s+n));try{r.state!=="stopped"&&r.stop(),this.tracks.forEach(o=>o.stopAllSources()),r.loopStart=this._loopStart,r.loopEnd=this._loopEnd,r.loop=this._loopEnabled,this.tracks.forEach(o=>o.setScheduleGuardOffset(s)),t!==void 0?r.start(a,t):r.start(a),r._clock._lastUpdate=a,this.tracks.forEach(o=>{o.startMidClipSources(s,a)})}catch(o){throw this.clearCompletionEvent(),this.tracks.forEach(l=>l.cancelFades()),console.warn("[waveform-playlist] Transport.start() failed. Audio playback could not begin.",o),o}}pause(){const e=z.getTransport();try{e.pause()}catch(t){console.warn("[waveform-playlist] Transport.pause() failed:",t)}this.tracks.forEach(t=>t.stopAllSources()),this.tracks.forEach(t=>t.cancelFades()),this.clearCompletionEvent()}stop(){const e=z.getTransport();try{e.stop()}catch(t){console.warn("[waveform-playlist] Transport.stop() failed:",t)}this.tracks.forEach(t=>t.stopAllSources()),this.tracks.forEach(t=>t.cancelFades()),this.clearCompletionEvent()}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const 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))}setLoop(e,t,n){this._loopEnabled=e,this._loopStart=t,this._loopEnd=n;const a=z.getTransport();try{a.loopStart=t,a.loopEnd=n,a.loop=e}catch(r){console.warn("[waveform-playlist] Error configuring Transport loop:",r);return}e&&!this._loopHandler?(this._loopHandler=()=>{const r=z.now();this.tracks.forEach(s=>{try{s.stopAllSources(),s.cancelFades(),s.setScheduleGuardOffset(this._loopStart),s.startMidClipSources(this._loopStart,r),s.prepareFades(r,this._loopStart)}catch(o){console.warn(`[waveform-playlist] Error re-scheduling track "${s.id}" on loop:`,o)}})},a.on("loop",this._loopHandler)):!e&&this._loopHandler&&(a.off("loop",this._loopHandler),this._loopHandler=null)}getCurrentTime(){return z.getTransport().seconds}seekTo(e){z.getTransport().seconds=e}dispose(){if(this.clearCompletionEvent(),this._loopHandler){try{z.getTransport().off("loop",this._loopHandler)}catch(e){console.warn("[waveform-playlist] Error removing Transport loop handler:",e)}this._loopHandler=null}if(this.tracks.forEach(e=>{try{e.dispose()}catch(t){console.warn(`[waveform-playlist] Error disposing track "${e.id}":`,t)}}),this.tracks.clear(),this.effectsCleanup)try{this.effectsCleanup()}catch(e){console.warn("[waveform-playlist] Error during master effects cleanup:",e)}try{this.masterVolume.dispose()}catch(e){console.warn("[waveform-playlist] Error disposing master volume:",e)}}get context(){return z.getContext()}get sampleRate(){return z.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},Et=null;function Er(){return Et||(Et=new z.Context,z.setContext(Et)),Et}function Mr(){return Er().rawContext}function Tr(e){let t=null,n=!1,a=0,r=!1,s=0,o=0,l=!1;function c(u){if(t){try{t.dispose()}catch(h){console.warn("[waveform-playlist] Error disposing previous playout during rebuild:",h)}t=null}a++;const f=a;t=new Ar({effects:e?.effects}),l&&t.init().catch(h=>{console.warn("[waveform-playlist] Failed to re-initialize playout after rebuild. Audio playback will require another user gesture.",h),l=!1});for(const h of u){const p=h.clips.filter(m=>m.audioBuffer);if(p.length===0)continue;const d=Math.min(...p.map(Zn)),b=Math.max(...p.map(yr)),y={id:h.id,name:h.name,gain:h.volume,muted:h.muted,soloed:h.soloed,stereoPan:h.pan,startTime:d,endTime:b},g=p.map(m=>({buffer:m.audioBuffer,startTime:Zn(m)-d,duration:xr(m),offset:Cr(m),fadeIn:m.fadeIn,fadeOut:m.fadeOut,gain:m.gain}));t.addTrack({clips:g,track:y,effects:h.effects})}t.applyInitialSoloState(),t.setLoop(r,s,o),t.setOnPlaybackComplete(()=>{f===a&&(n=!1)})}return{async init(){t&&(await t.init(),l=!0)},setTracks(u){c(u)},play(u,f){if(!t){console.warn("[waveform-playlist] adapter.play() called but no playout is available. Tracks may not have been set, or the adapter was disposed.");return}const h=f!==void 0?f-u:void 0;t.play(z.now(),u,h),n=!0},pause(){t?.pause(),n=!1},stop(){t?.stop(),n=!1},seek(u){t?.seekTo(u)},getCurrentTime(){return t?.getCurrentTime()??0},isPlaying(){return n},setMasterVolume(u){t?.setMasterGain(u)},setTrackVolume(u,f){t?.getTrack(u)?.setVolume(f)},setTrackMute(u,f){t?.setMute(u,f)},setTrackSolo(u,f){t?.setSolo(u,f)},setTrackPan(u,f){t?.getTrack(u)?.setPan(f)},setLoop(u,f,h){r=u,s=f,o=h,t?.setLoop(u,f,h)},dispose(){try{t?.dispose()}catch(u){console.warn("[waveform-playlist] Error disposing playout:",u)}t=null,n=!1}}}function pa(e,t,n,a){let r=t;const s=-e.startSample;if(r=Math.max(r,s),a>0){const o=n[a-1],c=o.startSample+o.durationSamples-e.startSample;r=Math.max(r,c)}if(a<n.length-1){const l=n[a+1].startSample-(e.startSample+e.durationSamples);r=Math.min(r,l)}return r}function Jt(e,t,n,a,r,s){let o=t;if(n==="left"){if(o=Math.max(o,-e.startSample),o=Math.max(o,-e.offsetSamples),r>0){const l=a[r-1],c=l.startSample+l.durationSamples;o=Math.max(o,c-e.startSample)}o=Math.min(o,e.durationSamples-s)}else if(o=Math.max(o,s-e.durationSamples),o=Math.min(o,e.sourceDurationSamples-e.offsetSamples-e.durationSamples),r<a.length-1){const l=a[r+1];o=Math.min(o,l.startSample-e.startSample-e.durationSamples)}return o}function $r(e,t){return Math.floor(e/t)*t}function Rr(e,t){const n=t-e.startSample,a=e.durationSamples-n,r=e.name?`${e.name} (1)`:void 0,s=e.name?`${e.name} (2)`:void 0,o=Ut({startSample:e.startSample,durationSamples:n,offsetSamples:e.offsetSamples,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:r,color:e.color,fadeIn:e.fadeIn,audioBuffer:e.audioBuffer,waveformData:e.waveformData}),l=Ut({startSample:t,durationSamples:a,offsetSamples:e.offsetSamples+n,sampleRate:e.sampleRate,sourceDurationSamples:e.sourceDurationSamples,gain:e.gain,name:s,color:e.color,fadeOut:e.fadeOut,audioBuffer:e.audioBuffer,waveformData:e.waveformData});return{left:o,right:l}}function ga(e,t,n){const a=e.startSample+e.durationSamples;if(t<=e.startSample||t>=a)return!1;const r=t-e.startSample,s=a-t;return r>=n&&s>=n}function Ot(e){let t=0;for(const n of e)for(const a of n.clips){const s=(a.startSample+a.durationSamples)/a.sampleRate;t=Math.max(t,s)}return t}function Xn(e,t){if(t.length===0)return 0;let n=0,a=Math.abs(t[0]-e);for(let r=1;r<t.length;r++){const s=Math.abs(t[r]-e);s<a&&(a=s,n=r)}return n}function On(e,t){return Math.max(0,Math.min(e,t))}var Dr=44100,Br=1e3,Fr=[256,512,1024,2048,4096,8192],Nn=.1,Pr=class{constructor(e={}){if(this._tracks=[],this._currentTime=0,this._playStartPosition=0,this._isPlaying=!1,this._selectedTrackId=null,this._selectionStart=0,this._selectionEnd=0,this._masterVolume=1,this._loopStart=0,this._loopEnd=0,this._isLoopEnabled=!1,this._tracksVersion=0,this._animFrameId=null,this._disposed=!1,this._listeners=new Map,this._sampleRate=e.sampleRate??Dr,this._zoomLevels=[...e.zoomLevels??Fr],this._adapter=e.adapter??null,this._zoomLevels.length===0)throw new Error("PlaylistEngine: zoomLevels must not be empty");const t=e.samplesPerPixel??Br;this._zoomIndex=Xn(t,this._zoomLevels)}getState(){return{tracks:this._tracks.map(e=>({...e,clips:[...e.clips]})),tracksVersion:this._tracksVersion,duration:Ot(this._tracks),currentTime:this._currentTime,isPlaying:this._isPlaying,samplesPerPixel:this._zoomLevels[this._zoomIndex],sampleRate:this._sampleRate,selectedTrackId:this._selectedTrackId,zoomIndex:this._zoomIndex,canZoomIn:this._zoomIndex>0,canZoomOut:this._zoomIndex<this._zoomLevels.length-1,selectionStart:this._selectionStart,selectionEnd:this._selectionEnd,masterVolume:this._masterVolume,loopStart:this._loopStart,loopEnd:this._loopEnd,isLoopEnabled:this._isLoopEnabled}}setTracks(e){this._tracks=[...e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}addTrack(e){this._tracks=[...this._tracks,e],this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}removeTrack(e){this._tracks.some(t=>t.id===e)&&(this._tracks=this._tracks.filter(t=>t.id!==e),this._tracksVersion++,this._selectedTrackId===e&&(this._selectedTrackId=null),this._adapter?.setTracks(this._tracks),this._emitStateChange())}selectTrack(e){e!==this._selectedTrackId&&(this._selectedTrackId=e,this._emitStateChange())}moveClip(e,t,n){const a=this._tracks.find(u=>u.id===e);if(!a){console.warn(`[waveform-playlist/engine] moveClip: track "${e}" not found`);return}const r=a.clips.findIndex(u=>u.id===t);if(r===-1){console.warn(`[waveform-playlist/engine] moveClip: clip "${t}" not found in track "${e}"`);return}const s=a.clips[r],o=Kt(a.clips),l=o.findIndex(u=>u.id===t),c=pa(s,n,o,l);c!==0&&(this._tracks=this._tracks.map(u=>{if(u.id!==e)return u;const f=u.clips.map((h,p)=>p===r?{...h,startSample:Math.floor(h.startSample+c)}:h);return{...u,clips:f}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}splitClip(e,t,n){const a=this._tracks.find(u=>u.id===e);if(!a){console.warn(`[waveform-playlist/engine] splitClip: track "${e}" not found`);return}const r=a.clips.findIndex(u=>u.id===t);if(r===-1){console.warn(`[waveform-playlist/engine] splitClip: clip "${t}" not found in track "${e}"`);return}const s=a.clips[r],o=Math.floor(Nn*this._sampleRate);if(!ga(s,n,o)){console.warn(`[waveform-playlist/engine] splitClip: cannot split clip "${t}" at sample ${n} (clip range: ${s.startSample}–${s.startSample+s.durationSamples}, minDuration: ${o})`);return}const{left:l,right:c}=Rr(s,n);this._tracks=this._tracks.map(u=>{if(u.id!==e)return u;const f=[...u.clips];return f.splice(r,1,l,c),{...u,clips:f}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange()}trimClip(e,t,n,a){const r=this._tracks.find(h=>h.id===e);if(!r){console.warn(`[waveform-playlist/engine] trimClip: track "${e}" not found`);return}const s=r.clips.findIndex(h=>h.id===t);if(s===-1){console.warn(`[waveform-playlist/engine] trimClip: clip "${t}" not found in track "${e}"`);return}const o=r.clips[s],l=Kt(r.clips),c=l.findIndex(h=>h.id===t),u=Math.floor(Nn*this._sampleRate),f=Jt(o,a,n,l,c,u);f!==0&&(this._tracks=this._tracks.map(h=>{if(h.id!==e)return h;const p=h.clips.map((d,b)=>b!==s?d:n==="left"?{...d,startSample:d.startSample+f,offsetSamples:d.offsetSamples+f,durationSamples:d.durationSamples-f}:{...d,durationSamples:d.durationSamples+f});return{...h,clips:p}}),this._tracksVersion++,this._adapter?.setTracks(this._tracks),this._emitStateChange())}async init(){this._adapter&&await this._adapter.init()}play(e,t){const n=this._currentTime,a=this._playStartPosition;if(e!==void 0){const r=Ot(this._tracks);this._currentTime=On(e,r)}if(this._playStartPosition=this._currentTime,this._adapter){if(t!==void 0)this._adapter.setLoop(!1,this._loopStart,this._loopEnd);else if(this._isLoopEnabled){const r=this._currentTime>=this._loopStart&&this._currentTime<this._loopEnd;this._adapter.setLoop(r,this._loopStart,this._loopEnd)}try{this._adapter.play(this._currentTime,t)}catch(r){throw this._currentTime=n,this._playStartPosition=a,r}}this._isPlaying=!0,this._startTimeUpdateLoop(),this._emit("play"),this._emitStateChange()}pause(){this._isPlaying=!1,this._stopTimeUpdateLoop(),this._adapter?.pause(),this._adapter&&(this._currentTime=this._adapter.getCurrentTime()),this._emit("pause"),this._emitStateChange()}stop(){this._isPlaying=!1,this._currentTime=this._playStartPosition,this._stopTimeUpdateLoop(),this._adapter?.setLoop(!1,this._loopStart,this._loopEnd),this._adapter?.stop(),this._emit("stop"),this._emitStateChange()}seek(e){const t=Ot(this._tracks);this._currentTime=On(e,t),this._adapter?.seek(this._currentTime),this._emitStateChange()}setMasterVolume(e){e!==this._masterVolume&&(this._masterVolume=e,this._adapter?.setMasterVolume(e),this._emitStateChange())}getCurrentTime(){return this._isPlaying&&this._adapter?this._adapter.getCurrentTime():this._currentTime}setSelection(e,t){const n=Math.min(e,t),a=Math.max(e,t);n===this._selectionStart&&a===this._selectionEnd||(this._selectionStart=n,this._selectionEnd=a,this._emitStateChange())}setLoopRegion(e,t){const n=Math.min(e,t),a=Math.max(e,t);n===this._loopStart&&a===this._loopEnd||(this._loopStart=n,this._loopEnd=a,this._adapter?.setLoop(this._isLoopEnabled&&this._shouldActivateTransportLoop(),this._loopStart,this._loopEnd),this._emitStateChange())}setLoopEnabled(e){e!==this._isLoopEnabled&&(this._isLoopEnabled=e,this._adapter?.setLoop(e&&this._shouldActivateTransportLoop(),this._loopStart,this._loopEnd),this._emitStateChange())}setTrackVolume(e,t){const n=this._tracks.find(a=>a.id===e);n&&(n.volume=t),this._adapter?.setTrackVolume(e,t)}setTrackMute(e,t){const n=this._tracks.find(a=>a.id===e);n&&(n.muted=t),this._adapter?.setTrackMute(e,t)}setTrackSolo(e,t){const n=this._tracks.find(a=>a.id===e);n&&(n.soloed=t),this._adapter?.setTrackSolo(e,t)}setTrackPan(e,t){const n=this._tracks.find(a=>a.id===e);n&&(n.pan=t),this._adapter?.setTrackPan(e,t)}zoomIn(){this._zoomIndex>0&&(this._zoomIndex--,this._emitStateChange())}zoomOut(){this._zoomIndex<this._zoomLevels.length-1&&(this._zoomIndex++,this._emitStateChange())}setZoomLevel(e){const t=Xn(e,this._zoomLevels);t!==this._zoomIndex&&(this._zoomIndex=t,this._emitStateChange())}on(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}off(e,t){this._listeners.get(e)?.delete(t)}dispose(){if(!this._disposed){this._disposed=!0,this._stopTimeUpdateLoop();try{this._adapter?.dispose()}catch(e){console.warn("[waveform-playlist/engine] Error disposing adapter:",e)}this._listeners.clear()}}_emit(e,...t){const n=this._listeners.get(e);if(n)for(const a of n)try{a(...t)}catch(r){console.warn("[waveform-playlist/engine] Error in event listener:",r)}}_emitStateChange(){this._emit("statechange",this.getState())}_shouldActivateTransportLoop(){if(!this._isPlaying)return!0;const e=this._adapter?.getCurrentTime()??this._currentTime;return e>=this._loopStart&&e<this._loopEnd}_startTimeUpdateLoop(){if(typeof requestAnimationFrame>"u")return;this._stopTimeUpdateLoop();const e=()=>{this._disposed||!this._isPlaying||(this._adapter&&(this._currentTime=this._adapter.getCurrentTime(),this._emit("timeupdate",this._currentTime)),this._animFrameId=requestAnimationFrame(e))};this._animFrameId=requestAnimationFrame(e)}_stopTimeUpdateLoop(){this._animFrameId!==null&&typeof cancelAnimationFrame<"u"&&(cancelAnimationFrame(this._animFrameId),this._animFrameId=null)}};const Qt=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[Qt.Translate.toString(e),Qt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),Wr=new Map([["bold",M.createElement(M.Fragment,null,M.createElement("path",{d:"M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128ZM60,112a16,16,0,1,0,16,16A16,16,0,0,0,60,112Zm136,0a16,16,0,1,0,16,16A16,16,0,0,0,196,112Z"}))],["duotone",M.createElement(M.Fragment,null,M.createElement("path",{d:"M240,96v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V96A16,16,0,0,1,32,80H224A16,16,0,0,1,240,96Z",opacity:"0.2"}),M.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["fill",M.createElement(M.Fragment,null,M.createElement("path",{d:"M224,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V96A16,16,0,0,0,224,80ZM60,140a12,12,0,1,1,12-12A12,12,0,0,1,60,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,128,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,196,140Z"}))],["light",M.createElement(M.Fragment,null,M.createElement("path",{d:"M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128ZM60,118a10,10,0,1,0,10,10A10,10,0,0,0,60,118Zm136,0a10,10,0,1,0,10,10A10,10,0,0,0,196,118Z"}))],["regular",M.createElement(M.Fragment,null,M.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["thin",M.createElement(M.Fragment,null,M.createElement("path",{d:"M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Zm-76-8a8,8,0,1,0,8,8A8,8,0,0,0,60,120Zm136,0a8,8,0,1,0,8,8A8,8,0,0,0,196,120Z"}))]]),Vr=new Map([["bold",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),M.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",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.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"}))]]),Zr=new Map([["bold",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),M.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",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.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",M.createElement(M.Fragment,null,M.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"}))]]),Lr=new Map([["bold",M.createElement(M.Fragment,null,M.createElement("path",{d:"M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"}))],["duotone",M.createElement(M.Fragment,null,M.createElement("path",{d:"M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z",opacity:"0.2"}),M.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["fill",M.createElement(M.Fragment,null,M.createElement("path",{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["light",M.createElement(M.Fragment,null,M.createElement("path",{d:"M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z"}))],["regular",M.createElement(M.Fragment,null,M.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["thin",M.createElement(M.Fragment,null,M.createElement("path",{d:"M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z"}))]]),jr=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),vt=M.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:f="currentColor",size:h,weight:p="regular",mirrored:d=!1,...b}=M.useContext(jr);return M.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??h,height:r??h,fill:a??f,viewBox:"0 0 256 256",transform:o||d?"scale(-1, 1)":void 0,...b,...u},!!n&&M.createElement("title",null,n),l,c.get(s??p))});vt.displayName="IconBase";const ba=M.forwardRef((e,t)=>M.createElement(vt,{ref:t,...e,weights:Wr}));ba.displayName="DotsThreeIcon";const va=M.forwardRef((e,t)=>M.createElement(vt,{ref:t,...e,weights:Vr}));va.displayName="SpeakerHighIcon";const wa=M.forwardRef((e,t)=>M.createElement(vt,{ref:t,...e,weights:Zr}));wa.displayName="SpeakerLowIcon";const ya=M.forwardRef((e,t)=>M.createElement(vt,{ref:t,...e,weights:Lr}));ya.displayName="XIcon";const zr=ya;D.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
|
|
7
|
+
`;var nn=D.button`
|
|
8
8
|
display: inline-flex;
|
|
9
9
|
align-items: center;
|
|
10
10
|
justify-content: center;
|
|
@@ -35,37 +35,37 @@
|
|
|
35
35
|
opacity: 0.6;
|
|
36
36
|
cursor: not-allowed;
|
|
37
37
|
}
|
|
38
|
-
`;
|
|
38
|
+
`;D(nn)`
|
|
39
39
|
padding: 0.25rem 0.5rem;
|
|
40
40
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
41
|
-
`;
|
|
41
|
+
`;D(nn)`
|
|
42
42
|
padding: 0.5rem;
|
|
43
43
|
min-width: 2.25rem;
|
|
44
44
|
min-height: 2.25rem;
|
|
45
|
-
`;
|
|
45
|
+
`;D(nn)`
|
|
46
46
|
padding: 0.25rem;
|
|
47
47
|
min-width: 1.75rem;
|
|
48
48
|
min-height: 1.75rem;
|
|
49
49
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
50
|
-
`;var
|
|
50
|
+
`;var Hr=D.div`
|
|
51
51
|
display: inline-flex;
|
|
52
52
|
align-items: center;
|
|
53
53
|
gap: 0.5rem;
|
|
54
|
-
`,
|
|
54
|
+
`,Xr=D.input`
|
|
55
55
|
cursor: pointer;
|
|
56
56
|
accent-color: ${e=>e.theme.inputFocusBorder};
|
|
57
57
|
|
|
58
58
|
&:disabled {
|
|
59
59
|
cursor: not-allowed;
|
|
60
60
|
}
|
|
61
|
-
`,
|
|
61
|
+
`,Or=D.label`
|
|
62
62
|
margin: 0;
|
|
63
63
|
cursor: pointer;
|
|
64
64
|
user-select: none;
|
|
65
65
|
font-family: ${e=>e.theme.fontFamily};
|
|
66
66
|
font-size: ${e=>e.theme.fontSize};
|
|
67
67
|
color: ${e=>e.theme.textColor};
|
|
68
|
-
`,He=
|
|
68
|
+
`,He=D.button`
|
|
69
69
|
padding: 0.5rem 1rem;
|
|
70
70
|
background: ${e=>e.theme.buttonBackground||"#007bff"};
|
|
71
71
|
color: ${e=>e.theme.buttonText||"white"};
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
cursor: not-allowed;
|
|
92
92
|
opacity: 0.6;
|
|
93
93
|
}
|
|
94
|
-
`,
|
|
94
|
+
`,Ca=D.input`
|
|
95
95
|
padding: 0.5rem 0.75rem;
|
|
96
96
|
font-family: ${e=>e.theme.fontFamily};
|
|
97
97
|
font-size: ${e=>e.theme.fontSize};
|
|
@@ -117,17 +117,17 @@
|
|
|
117
117
|
opacity: 0.6;
|
|
118
118
|
cursor: not-allowed;
|
|
119
119
|
}
|
|
120
|
-
`;
|
|
120
|
+
`;D(Ca)`
|
|
121
121
|
padding: 0.25rem 0.5rem;
|
|
122
122
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
123
|
-
`;var
|
|
123
|
+
`;var Nr=D.label`
|
|
124
124
|
font-family: ${e=>e.theme.fontFamily};
|
|
125
125
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
126
126
|
font-weight: 500;
|
|
127
127
|
color: ${e=>e.theme.textColorMuted};
|
|
128
128
|
margin-bottom: 0.25rem;
|
|
129
129
|
display: block;
|
|
130
|
-
`;
|
|
130
|
+
`;D.label`
|
|
131
131
|
font-family: ${e=>e.theme.fontFamily};
|
|
132
132
|
font-size: ${e=>e.theme.fontSize};
|
|
133
133
|
color: ${e=>e.theme.textColor};
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
align-items: center;
|
|
136
136
|
gap: 0.5rem;
|
|
137
137
|
cursor: pointer;
|
|
138
|
-
`;var
|
|
138
|
+
`;var Gr=D.span`
|
|
139
139
|
position: absolute;
|
|
140
140
|
width: 1px;
|
|
141
141
|
height: 1px;
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
clip: rect(0, 0, 0, 0);
|
|
146
146
|
white-space: nowrap;
|
|
147
147
|
border: 0;
|
|
148
|
-
`,
|
|
148
|
+
`,xa=D.select`
|
|
149
149
|
padding: 0.5rem 2rem 0.5rem 0.75rem;
|
|
150
150
|
font-family: ${e=>e.theme.fontFamily};
|
|
151
151
|
font-size: ${e=>e.theme.fontSize};
|
|
@@ -178,10 +178,10 @@
|
|
|
178
178
|
color: ${e=>e.theme.inputText};
|
|
179
179
|
background-color: ${e=>e.theme.inputBackground};
|
|
180
180
|
}
|
|
181
|
-
`;
|
|
181
|
+
`;D(xa)`
|
|
182
182
|
padding: 0.25rem 1.75rem 0.25rem 0.5rem;
|
|
183
183
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
184
|
-
`;var
|
|
184
|
+
`;var ka=D.input.attrs({type:"range"})`
|
|
185
185
|
-webkit-appearance: none;
|
|
186
186
|
appearance: none;
|
|
187
187
|
width: 100%;
|
|
@@ -261,7 +261,7 @@
|
|
|
261
261
|
&:disabled::-moz-range-thumb {
|
|
262
262
|
cursor: not-allowed;
|
|
263
263
|
}
|
|
264
|
-
`,
|
|
264
|
+
`,Yr=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return v.jsxs(Hr,{className:a,children:[v.jsx(Xr,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:r,disabled:n}),v.jsx(Or,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function Sa(e){return typeof e=="object"&&e!==null&&"type"in e}function tt(e){if(!Sa(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 _a={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"},Ur=class{constructor(){this._state=null,this._listeners=new Set,this.subscribe=e=>(this._listeners.add(e),()=>this._listeners.delete(e)),this.getSnapshot=()=>this._state}update(e,t){const n=t*1.5,a=Math.max(0,e-n),r=e+t+n;if(!(this._state&&this._state.containerWidth===t&&Math.abs(this._state.scrollLeft-e)<100)){this._state={scrollLeft:e,containerWidth:t,visibleStart:a,visibleEnd:r};for(const s of this._listeners)s()}}},Ia=i.createContext(null),Kr=()=>()=>{},qr=({containerRef:e,children:t})=>{const n=i.useRef(null);n.current===null&&(n.current=new Ur);const a=n.current,r=i.useRef(null),s=i.useCallback(()=>{const l=e.current;l&&a.update(l.scrollLeft,l.clientWidth)},[e,a]),o=i.useCallback(()=>{r.current===null&&(r.current=requestAnimationFrame(()=>{r.current=null,s()}))},[s]);return i.useEffect(()=>{const l=e.current;if(!l)return;s(),l.addEventListener("scroll",o,{passive:!0});const c=new ResizeObserver(()=>{o()});return c.observe(l),()=>{l.removeEventListener("scroll",o),c.disconnect(),r.current!==null&&(cancelAnimationFrame(r.current),r.current=null)}},[e,s,o]),v.jsx(Ia.Provider,{value:a,children:t})};function Jr(e){const t=i.useContext(Ia);return i.useSyncExternalStore(t?t.subscribe:Kr,()=>e(t?t.getSnapshot():null),()=>e(null))}function an(e,t,n=0){const a=Jr(r=>{const s=Math.ceil(e/t),o=[];for(let l=0;l<s;l++){const c=l*t,u=Math.min(e-c,t);if(r){const f=n+c;if(f+u<=r.visibleStart||f>=r.visibleEnd)continue}o.push(l)}return o.join(",")});return i.useMemo(()=>a?a.split(",").map(Number):[],[a])}var Aa=i.createContext(0),Qr=({originX:e,children:t})=>v.jsx(Aa.Provider,{value:e,children:t}),Ea=()=>i.useContext(Aa);function rn(){const e=i.useRef(new Map),t=i.useCallback(n=>{if(n!==null){const a=parseInt(n.dataset.index,10);e.current.set(a,n)}},[]);return i.useEffect(()=>{const n=e.current;for(const[a,r]of n.entries())r.isConnected||n.delete(a)}),{canvasRef:t,canvasMapRef:e}}function eo(e,t,n,a){if(!Sa(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 to=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
|
|
265
265
|
position: absolute;
|
|
266
266
|
top: 0;
|
|
267
267
|
/* Promote to own compositing layer for smoother scrolling */
|
|
@@ -269,15 +269,15 @@
|
|
|
269
269
|
/* Disable image rendering interpolation */
|
|
270
270
|
image-rendering: pixelated;
|
|
271
271
|
image-rendering: crisp-edges;
|
|
272
|
-
`,
|
|
272
|
+
`,no=D.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
273
273
|
position: absolute;
|
|
274
274
|
background: ${e=>e.$waveFillColor};
|
|
275
275
|
/* Force GPU compositing layer to reduce scroll flickering */
|
|
276
276
|
transform: translateZ(0);
|
|
277
277
|
backface-visibility: hidden;
|
|
278
|
-
`,
|
|
278
|
+
`,Gn=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:f=1,barGap:h=0,transparentBackground:p=!1,drawMode:d="inverted"}=e,{canvasRef:b,canvasMapRef:y}=rn(),g=Ea(),m=an(a,Se,g);i.useLayoutEffect(()=>{const k=f+h;for(const[S,A]of y.current.entries()){const $=S*Se,_=A.getContext("2d"),E=Math.floor(l/2),R=2**(n-1);if(_){_.resetTransform(),_.clearRect(0,0,A.width,A.height),_.imageSmoothingEnabled=!1,_.scale(o,o);const W=A.width/o;let T;d==="normal"?T=u:T=c,_.fillStyle=eo(_,T,W,l);const F=$,P=$+W,O=Math.floor((F-f+k)/k)*k;for(let U=Math.max(0,O);U<P;U+=k){const J=U-F;if(J+f<=0)continue;const V=U;if(V*2+1<t.length){const ee=t[V*2]/R,ae=t[V*2+1]/R,Q=Math.abs(ee*E),ue=Math.abs(ae*E);d==="normal"?_.fillRect(J,E-ue,f,ue+Q):(_.fillRect(J,0,f,E-ue),_.fillRect(J,E+Q,f,E-Q))}}}}},[y,t,n,l,c,u,o,a,f,h,d,m]);const C=m.map(k=>{const S=k*Se,A=Math.min(a-S,Se);return v.jsx(to,{$cssWidth:A,$left:S,width:A*o,height:l*o,$waveHeight:l,"data-index":k,ref:b},`${a}-${k}`)}),w=p?"transparent":tt(u);return v.jsx(no,{$index:r,$cssWidth:a,className:s,$waveHeight:l,$waveFillColor:w,children:C})},ao={padding:"16px",background:"#1a1a2e",color:"#e0e0e0",border:"1px solid #d08070",borderRadius:"4px",fontFamily:"monospace",fontSize:"13px",minHeight:"60px",display:"flex",alignItems:"center",justifyContent:"center"};(class extends i.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error("[waveform-playlist] Render error:",e,t.componentStack)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:v.jsx("div",{style:ao,children:"Waveform playlist encountered an error. Check console for details."}):this.props.children}});var Ma=22,Ta=D.div`
|
|
279
279
|
position: relative;
|
|
280
|
-
height: ${
|
|
280
|
+
height: ${Ma}px;
|
|
281
281
|
background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
|
|
282
282
|
border-bottom: 1px solid ${e=>e.theme.clipHeaderBorderColor};
|
|
283
283
|
display: flex;
|
|
@@ -299,7 +299,7 @@
|
|
|
299
299
|
cursor: grabbing;
|
|
300
300
|
}
|
|
301
301
|
`}
|
|
302
|
-
|
|
302
|
+
`,$a=D.span`
|
|
303
303
|
font-size: 11px;
|
|
304
304
|
font-weight: 600;
|
|
305
305
|
font-family: ${e=>e.theme.clipHeaderFontFamily};
|
|
@@ -307,12 +307,12 @@
|
|
|
307
307
|
white-space: nowrap;
|
|
308
308
|
overflow: hidden;
|
|
309
309
|
text-overflow: ellipsis;
|
|
310
|
-
`,
|
|
310
|
+
`,ro=({trackName:e,isSelected:t=!1})=>v.jsx(Ta,{$isDragging:!1,$interactive:!1,$isSelected:t,children:v.jsx($a,{children:e})}),oo=({clipId:e,trackIndex:t,clipIndex:n,trackName:a,isSelected:r=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return v.jsx(ro,{trackName:a,isSelected:r});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return v.jsx(Ta,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:r,...c,...l,children:v.jsx($a,{children:a})})},so=8,io=24,lo=D.div`
|
|
311
311
|
position: absolute;
|
|
312
312
|
${e=>e.$edge==="left"?"left: 0;":"right: 0;"}
|
|
313
313
|
top: 0;
|
|
314
314
|
bottom: 0;
|
|
315
|
-
width: ${e=>e.$touchOptimized?
|
|
315
|
+
width: ${e=>e.$touchOptimized?io:so}px;
|
|
316
316
|
cursor: col-resize;
|
|
317
317
|
user-select: none;
|
|
318
318
|
z-index: 105; /* Above waveform, below header */
|
|
@@ -335,19 +335,19 @@
|
|
|
335
335
|
background: rgba(255, 255, 255, 0.4);
|
|
336
336
|
${e=>e.$edge==="left"?"border-left: 2px solid rgba(255, 255, 255, 0.8);":"border-right: 2px solid rgba(255, 255, 255, 0.8);"}
|
|
337
337
|
}
|
|
338
|
-
`,
|
|
338
|
+
`,Yn=({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:f,isDragging:h}=r;return v.jsx(lo,{ref:f,"data-clip-id":e,"data-boundary-edge":a,$edge:a,$isDragging:h,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},co=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
339
339
|
position: absolute;
|
|
340
340
|
top: 0;
|
|
341
341
|
bottom: 0;
|
|
342
342
|
pointer-events: none;
|
|
343
343
|
z-index: 50;
|
|
344
|
-
`,
|
|
344
|
+
`,uo=D.svg`
|
|
345
345
|
width: 100%;
|
|
346
346
|
height: 100%;
|
|
347
347
|
display: block;
|
|
348
348
|
/* Flip horizontally for fadeOut - makes it mirror of fadeIn */
|
|
349
349
|
transform: ${e=>e.$type==="fadeOut"?"scaleX(-1)":"none"};
|
|
350
|
-
`;function
|
|
350
|
+
`;function fo(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 Un=({left:e,width:t,type:n,curveType:a="logarithmic",color:r})=>{const s=D.useTheme();if(t<1)return null;const o=r||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return v.jsx(co,{$left:e,$width:t,$type:n,children:v.jsx(uo,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:v.jsx("path",{d:fo(t,100,a),fill:o})})})},mo=D.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
351
351
|
position: ${e=>e.$isOverlay?"relative":"absolute"};
|
|
352
352
|
top: 0;
|
|
353
353
|
height: ${e=>e.$isOverlay?"auto":"100%"};
|
|
@@ -361,20 +361,20 @@
|
|
|
361
361
|
&:hover {
|
|
362
362
|
background: rgba(255, 255, 255, 0.08);
|
|
363
363
|
}
|
|
364
|
-
`,
|
|
364
|
+
`,ho=D.div`
|
|
365
365
|
flex: 1;
|
|
366
366
|
position: relative;
|
|
367
367
|
overflow: ${e=>e.$isOverlay?"visible":"hidden"};
|
|
368
|
-
`,
|
|
368
|
+
`,en=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:f=!1,isOverlay:h=!1,isSelected:p=!1,onMouseDown:d,trackId:b,fadeIn:y,fadeOut:g,sampleRate:m=44100,showFades:C=!1,touchOptimized:x=!1})=>{const w=Math.floor(o/c),S=Math.floor((o+l)/c)-w,A=u&&!f&&!h,$=`clip-${a}-${r}`,{attributes:_,listeners:E,setNodeRef:R,setActivatorNodeRef:W,transform:T,isDragging:F}=Oe.useDraggable({id:$,data:{clipId:n,trackIndex:a,clipIndex:r},disabled:!A}),P=`clip-boundary-left-${a}-${r}`,{attributes:O,listeners:U,setActivatorNodeRef:J,isDragging:V}=Oe.useDraggable({id:P,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"left"},disabled:!A}),ee=`clip-boundary-right-${a}-${r}`,{attributes:ae,listeners:Q,setActivatorNodeRef:ue,isDragging:ie}=Oe.useDraggable({id:ee,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"right"},disabled:!A}),pe=T?{transform:Qt.Translate.toString(T),zIndex:F?100:void 0}:void 0;return v.jsxs(mo,{ref:R,style:pe,className:t,$left:w,$width:S,$isOverlay:h,"data-clip-container":"true","data-track-id":b,onMouseDown:d,children:[u&&v.jsx(oo,{clipId:n,trackIndex:a,clipIndex:r,trackName:s,isSelected:p,disableDrag:f,dragHandleProps:A?{attributes:_,listeners:E,setActivatorNodeRef:W}:void 0}),v.jsx(Qr,{originX:w,children:v.jsxs(ho,{$isOverlay:h,children:[e,C&&y&&y.duration>0&&v.jsx(Un,{left:0,width:Math.floor(y.duration*m/c),type:"fadeIn",curveType:y.type}),C&&g&&g.duration>0&&v.jsx(Un,{left:S-Math.floor(g.duration*m/c),width:Math.floor(g.duration*m/c),type:"fadeOut",curveType:g.type})]})}),u&&!f&&!h&&v.jsxs(v.Fragment,{children:[v.jsx(Yn,{clipId:n,trackIndex:a,clipIndex:r,edge:"left",touchOptimized:x,dragHandleProps:{attributes:O,listeners:U,setActivatorNodeRef:J,isDragging:V}}),v.jsx(Yn,{clipId:n,trackIndex:a,clipIndex:r,edge:"right",touchOptimized:x,dragHandleProps:{attributes:ae,listeners:Q,setActivatorNodeRef:ue,isDragging:ie}})]})]})},po=D.div`
|
|
369
369
|
display: inline-flex;
|
|
370
370
|
align-items: center;
|
|
371
371
|
gap: 0.5rem;
|
|
372
|
-
`,
|
|
372
|
+
`,go=D(Nr)`
|
|
373
373
|
margin: 0;
|
|
374
374
|
white-space: nowrap;
|
|
375
|
-
`,
|
|
375
|
+
`,bo=D(ka)`
|
|
376
376
|
width: 120px;
|
|
377
|
-
`,
|
|
377
|
+
`,vo=({volume:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(parseFloat(s.target.value)/100)};return v.jsxs(po,{className:a,children:[v.jsx(go,{htmlFor:"master-gain",children:"Master Volume"}),v.jsx(bo,{min:"0",max:"100",value:e*100,onChange:r,disabled:n,id:"master-gain"})]})};D.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
|
|
378
378
|
position: absolute;
|
|
379
379
|
top: 0;
|
|
380
380
|
left: 0;
|
|
@@ -384,7 +384,7 @@
|
|
|
384
384
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
385
385
|
pointer-events: none;
|
|
386
386
|
will-change: transform;
|
|
387
|
-
`;
|
|
387
|
+
`;D.div`
|
|
388
388
|
position: absolute;
|
|
389
389
|
top: 0;
|
|
390
390
|
left: 0;
|
|
@@ -392,7 +392,7 @@
|
|
|
392
392
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
393
393
|
pointer-events: none;
|
|
394
394
|
will-change: transform;
|
|
395
|
-
`;
|
|
395
|
+
`;D.div`
|
|
396
396
|
position: absolute;
|
|
397
397
|
top: -10px;
|
|
398
398
|
left: -6px;
|
|
@@ -401,30 +401,30 @@
|
|
|
401
401
|
border-left: 7px solid transparent;
|
|
402
402
|
border-right: 7px solid transparent;
|
|
403
403
|
border-top: 10px solid ${e=>e.$color};
|
|
404
|
-
`;
|
|
404
|
+
`;D.div`
|
|
405
405
|
position: absolute;
|
|
406
406
|
top: 0;
|
|
407
407
|
left: 0;
|
|
408
408
|
width: 2px;
|
|
409
409
|
height: 100%;
|
|
410
410
|
background: ${e=>e.$color};
|
|
411
|
-
`;var
|
|
411
|
+
`;var wo=D.div`
|
|
412
412
|
overflow-y: hidden;
|
|
413
413
|
overflow-x: auto;
|
|
414
414
|
position: relative;
|
|
415
|
-
`,
|
|
415
|
+
`,yo=D.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
|
|
416
416
|
position: relative;
|
|
417
417
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
418
|
-
`,
|
|
418
|
+
`,Co=D.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
|
|
419
419
|
background: ${e=>e.$backgroundColor||"white"};
|
|
420
420
|
width: 100%;
|
|
421
421
|
position: relative;
|
|
422
422
|
overflow: hidden; /* Constrain loop region to timescale area */
|
|
423
|
-
`,
|
|
423
|
+
`,xo=D.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
|
|
424
424
|
position: relative;
|
|
425
425
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
426
426
|
width: 100%;
|
|
427
|
-
`,
|
|
427
|
+
`,ko=D.div`
|
|
428
428
|
position: absolute;
|
|
429
429
|
top: 0;
|
|
430
430
|
left: 0;
|
|
@@ -433,7 +433,7 @@
|
|
|
433
433
|
cursor: crosshair;
|
|
434
434
|
/* When selecting, raise z-index above clip boundaries (z-index: 105) to prevent interference */
|
|
435
435
|
z-index: ${e=>e.$isSelecting?110:1};
|
|
436
|
-
`,
|
|
436
|
+
`,on=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:f,onTracksMouseUp:h,scrollContainerRef:p,isSelecting:d,"data-playlist-state":b})=>{const y=i.useRef(null),g=i.useCallback(m=>{y.current=m,p?.(m)},[p]);return v.jsx(wo,{"data-scroll-container":"true","data-playlist-state":b,ref:g,children:v.jsx(qr,{containerRef:y,children:v.jsxs(yo,{$backgroundColor:t,$width:o,children:[a&&v.jsx(Co,{$width:r,$backgroundColor:n,children:a}),v.jsxs(xo,{$width:s,$backgroundColor:t,children:[e,(c||u)&&v.jsx(ko,{$controlsWidth:l,$isSelecting:d,onClick:c,onMouseDown:u,onMouseMove:f,onMouseUp:h})]})]})})})};D.withTheme(on);var So=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
437
437
|
position: absolute;
|
|
438
438
|
top: 0;
|
|
439
439
|
background: ${e=>e.$color};
|
|
@@ -441,14 +441,14 @@
|
|
|
441
441
|
z-index: 60; /* Above clips (z-index: 10) and fades (z-index: 50), below playhead (z-index: 100) */
|
|
442
442
|
pointer-events: none;
|
|
443
443
|
opacity: 0.3;
|
|
444
|
-
`,
|
|
444
|
+
`,Ra=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const a=Math.max(0,t-e);return a<=0?null:v.jsx(So,{$left:e,$width:a,$color:n,"data-selection":!0})};D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
445
445
|
position: absolute;
|
|
446
446
|
top: 0;
|
|
447
447
|
background: ${e=>e.$color};
|
|
448
448
|
height: 100%;
|
|
449
449
|
z-index: 55; /* Between clips (z-index: 50) and selection (z-index: 60) */
|
|
450
450
|
pointer-events: none;
|
|
451
|
-
`;
|
|
451
|
+
`;D.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
|
|
452
452
|
position: absolute;
|
|
453
453
|
top: 0;
|
|
454
454
|
width: 2px;
|
|
@@ -468,7 +468,7 @@
|
|
|
468
468
|
border-top: 8px solid ${e=>e.$color};
|
|
469
469
|
${e=>e.$isStart?"border-right: 8px solid transparent;":"border-left: 8px solid transparent;"}
|
|
470
470
|
}
|
|
471
|
-
`;var
|
|
471
|
+
`;var Kn=D.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
|
|
472
472
|
position: absolute;
|
|
473
473
|
top: 0;
|
|
474
474
|
width: 12px;
|
|
@@ -505,7 +505,7 @@
|
|
|
505
505
|
&:hover::before {
|
|
506
506
|
opacity: 1;
|
|
507
507
|
}
|
|
508
|
-
`,
|
|
508
|
+
`,_o=D.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
509
509
|
position: absolute;
|
|
510
510
|
top: 0;
|
|
511
511
|
height: 100%;
|
|
@@ -516,26 +516,26 @@
|
|
|
516
516
|
&:active {
|
|
517
517
|
cursor: grabbing;
|
|
518
518
|
}
|
|
519
|
-
`,
|
|
519
|
+
`,Io=({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,f]=i.useState(null),h=i.useRef(0),p=i.useRef(0),d=i.useRef(0),b=Math.max(0,t-e),y=i.useCallback((m,C)=>{m.preventDefault(),m.stopPropagation(),f(C),h.current=m.clientX,p.current=C==="start"?e:t;const x=k=>{const S=k.clientX-h.current,A=p.current+S;if(C==="start"){const $=Math.max(l,Math.min(t-10,A));r?.($)}else{const $=Math.max(e+10,Math.min(c,A));s?.($)}},w=()=>{f(null),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",w)},[e,t,l,c,r,s]),g=i.useCallback(m=>{m.preventDefault(),m.stopPropagation(),f("region"),h.current=m.clientX,p.current=e,d.current=t;const C=t-e,x=k=>{const S=k.clientX-h.current;let A=p.current+S,$=d.current+S;A<l&&(A=l,$=l+C),$>c&&($=c,A=c-C),o?.(A,$)},w=()=>{f(null),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",w)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",w)},[e,t,l,c,o]);return b<=0?null:v.jsxs(v.Fragment,{children:[v.jsx(_o,{$left:e,$width:b,$color:a,$isDragging:u==="region",onMouseDown:g,"data-loop-region-timescale":!0}),v.jsx(Kn,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:m=>y(m,"start"),"data-loop-marker-handle":"start"}),v.jsx(Kn,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:m=>y(m,"end"),"data-loop-marker-handle":"end"})]})},Ao=D.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
|
|
520
520
|
position: absolute;
|
|
521
521
|
top: 0;
|
|
522
522
|
right: 0;
|
|
523
523
|
height: 100%; /* Stay within timescale bounds, don't extend into tracks */
|
|
524
524
|
cursor: crosshair;
|
|
525
525
|
z-index: 40; /* Below markers and shading */
|
|
526
|
-
`,
|
|
526
|
+
`,Eo=({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]=i.useState(!1),u=i.useRef(0),f=i.useRef(null),h=t>e,p=i.useCallback(d=>{const b=d.target;if(b.closest("[data-loop-marker-handle]")||b.closest("[data-loop-region-timescale]"))return;d.preventDefault(),c(!0);const y=f.current?.getBoundingClientRect();if(!y)return;const g=d.clientX-y.left,m=Math.max(s,Math.min(o,g));u.current=m,r?.(m,m);const C=w=>{const k=w.clientX-y.left,S=Math.max(s,Math.min(o,k)),A=Math.min(u.current,S),$=Math.max(u.current,S);r?.(A,$)},x=()=>{c(!1),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",x)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",x)},[s,o,r]);return v.jsx(Ao,{ref:f,$leftOffset:l,onMouseDown:p,"data-timescale-loop-creator":!0,children:h&&v.jsx(Io,{startPosition:e,endPosition:t,markerColor:n,regionColor:a,minPosition:s,maxPosition:o,onLoopStartChange:d=>r?.(d,t),onLoopEndChange:d=>r?.(e,d),onLoopRegionMove:(d,b)=>r?.(d,b)})})};function pt(e,t){const n=Math.floor(e/3600)%24,a=Math.floor(e/60)%60,r=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(a).padStart(2,"0")+":"+r.padStart(t+3,"0")}function ft(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return pt(e,0);case"hh:mm:ss.u":return pt(e,1);case"hh:mm:ss.uu":return pt(e,2);case"hh:mm:ss.uuu":return pt(e,3);default:return pt(e,3)}}function Da(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 qn=({id:e,label:t,value:n,format:a,className:r,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const p=ft(n,a);c(p)},[n,a,e]);const u=p=>{const d=p.target.value;c(d)},f=()=>{if(s){const p=Da(l,a);s(p)}c(ft(n,a))},h=p=>{p.key==="Enter"&&p.currentTarget.blur()};return v.jsxs(v.Fragment,{children:[v.jsx(Gr,{as:"label",htmlFor:e,children:t}),v.jsx(Ca,{type:"text",className:r,id:e,value:l,onChange:u,onBlur:f,onKeyDown:h,readOnly:o})]})},Mo=({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 v.jsxs("div",{className:a,children:[v.jsx(qn,{id:"audio_start",label:"Start of audio selection",value:e,format:r,className:"audio-start form-control mr-sm-2",onChange:o}),v.jsx(qn,{id:"audio_end",label:"End of audio selection",value:t,format:r,className:"audio-end form-control mr-sm-2",onChange:l})]})};function $t(){return window.devicePixelRatio}var Ba=i.createContext($t()),Fa=({children:e})=>{const[t,n]=i.useState($t());return matchMedia(`(resolution: ${$t()}dppx)`).addEventListener("change",()=>{n($t())},{once:!0}),v.jsx(Ba.Provider,{value:Math.ceil(t),children:e})},sn=()=>i.useContext(Ba),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}),Bt=()=>i.useContext(wt),yt=()=>i.useContext(D.ThemeContext),ln=i.createContext(v.jsx(i.Fragment,{})),To=()=>i.useContext(ln),$o=0,Ro=!1,Do=0,Bo=0,Fo={progress:$o,isPlaying:Ro,selectionStart:Do,selectionEnd:Bo};i.createContext(Fo);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var Po=(e,t,n)=>(e-t)/(n-t),Wo=D.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
527
527
|
position: absolute;
|
|
528
528
|
background: #000;
|
|
529
529
|
transform: translateZ(0);
|
|
530
530
|
backface-visibility: hidden;
|
|
531
|
-
`,
|
|
531
|
+
`,Vo=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`,left:`${e.$left}px`}}))`
|
|
532
532
|
position: absolute;
|
|
533
533
|
top: 0;
|
|
534
534
|
/* Promote to own compositing layer for smoother scrolling */
|
|
535
535
|
will-change: transform;
|
|
536
536
|
image-rendering: pixelated;
|
|
537
537
|
image-rendering: crisp-edges;
|
|
538
|
-
`;function
|
|
538
|
+
`;function Zo(){const e=new Uint8Array(768);for(let t=0;t<256;t++)e[t*3]=e[t*3+1]=e[t*3+2]=t;return e}var Lo=Zo(),Jn=({index:e,channelIndex:t,data:n,length:a,waveHeight:r,devicePixelRatio:s=1,samplesPerPixel:o,colorLUT:l,frequencyScaleFn:c,minFrequency:u=0,maxFrequency:f,workerApi:h,clipId:p,onCanvasesReady:d})=>{const b=t??e,{canvasRef:y,canvasMapRef:g}=rn(),m=i.useRef([]),C=i.useRef(new WeakSet),x=i.useRef(h),w=i.useRef(d),k=!!(h&&p),S=Ea(),A=an(a,Se,S),$=l??Lo,_=f??(n?n.sampleRate/2:22050),E=c??Po,R=!!c;i.useEffect(()=>{x.current=h},[h]),i.useEffect(()=>{w.current=d},[d]),i.useEffect(()=>{if(!k)return;const T=x.current;if(!T||!p)return;const F=m.current.length,P=[];for(const J of m.current){const V=J.match(/chunk(\d+)$/);if(!V){P.push(J);continue}const ee=parseInt(V[1],10),ae=g.current.get(ee);if(ae&&ae.isConnected)P.push(J);else try{T.unregisterCanvas(J)}catch(Q){console.warn(`[spectrogram] unregisterCanvas failed for ${J}:`,Q)}}m.current=P;const O=[];for(const[J,V]of g.current.entries()){if(C.current.has(V))continue;const ee=`${p}-ch${b}-chunk${J}`;let ae;try{ae=V.transferControlToOffscreen()}catch(Q){console.warn(`[spectrogram] transferControlToOffscreen failed for ${ee}:`,Q);continue}C.current.add(V);try{T.registerCanvas(ee,ae),O.push(ee)}catch(Q){console.warn(`[spectrogram] registerCanvas failed for ${ee}:`,Q);continue}}if(O.length>0&&(m.current=[...m.current,...O]),O.length>0||P.length<F){const J=m.current,V=J.map(ee=>{const ae=ee.match(/chunk(\d+)$/);if(!ae)return console.warn(`[spectrogram] Unexpected canvas ID format: ${ee}`),Se;const Q=parseInt(ae[1],10);return Math.min(a-Q*Se,Se)});w.current?.(J,V)}},[g,k,p,b,a,A]),i.useEffect(()=>()=>{const T=x.current;if(T){for(const F of m.current)try{T.unregisterCanvas(F)}catch(P){console.warn(`[spectrogram] unregisterCanvas failed for ${F}:`,P)}m.current=[]}},[]),i.useLayoutEffect(()=>{if(k||!n)return;const{frequencyBinCount:T,frameCount:F,hopSize:P,sampleRate:O,gainDb:U,rangeDb:J}=n,V=J===0?1:J,ee=ae=>ae/T*(O/2);for(const[ae,Q]of g.current.entries()){const ue=ae*Se,ie=Q.getContext("2d");if(!ie)continue;const pe=Q.width/s,ye=r;ie.resetTransform(),ie.clearRect(0,0,Q.width,Q.height),ie.imageSmoothingEnabled=!1,ie.scale(s,s);const N=ie.createImageData(pe,ye),H=N.data;for(let se=0;se<pe;se++){const I=(ue+se)*o,le=Math.floor(I/P);if(le<0||le>=F)continue;const xe=le*T;for(let K=0;K<ye;K++){const ce=1-K/ye;let Ie=Math.floor(ce*T);if(R){let fe=0,Be=T-1;for(;fe<Be;){const Fe=fe+Be>>1,ze=ee(Fe);E(ze,u,_)<ce?fe=Fe+1:Be=Fe}Ie=fe}if(Ie<0||Ie>=T)continue;const Ge=n.data[xe+Ie],q=Math.max(0,Math.min(1,(Ge+V+U)/V)),_e=Math.floor(q*255),Ae=(K*pe+se)*4;H[Ae]=$[_e*3],H[Ae+1]=$[_e*3+1],H[Ae+2]=$[_e*3+2],H[Ae+3]=255}}if(ie.resetTransform(),ie.putImageData(N,0,0),s!==1){const se=document.createElement("canvas");se.width=pe,se.height=ye;const G=se.getContext("2d");if(!G)continue;G.putImageData(N,0,0),ie.clearRect(0,0,Q.width,Q.height),ie.imageSmoothingEnabled=!1,ie.drawImage(se,0,0,Q.width,Q.height)}}},[g,k,n,a,r,s,o,$,u,_,E,R,A]);const W=A.map(T=>{const F=T*Se,P=Math.min(a-F,Se);return v.jsx(Vo,{$cssWidth:P,$left:F,width:P*s,height:r*s,$waveHeight:r,"data-index":T,ref:y},`${a}-${T}`)});return v.jsx(Wo,{$index:e,$cssWidth:a,$waveHeight:r,children:W})},Pa=({isSelected:e,transparentBackground:t,renderMode:n="waveform",spectrogramData:a,spectrogramColorLUT:r,samplesPerPixel:s,spectrogramFrequencyScaleFn:o,spectrogramMinFrequency:l,spectrogramMaxFrequency:c,spectrogramWorkerApi:u,spectrogramClipId:f,spectrogramOnCanvasesReady:h,...p})=>{const d=yt(),{waveHeight:b,barWidth:y,barGap:g,samplesPerPixel:m}=Bt(),C=sn(),x=s??m,w=e&&d?d.selectedWaveOutlineColor:d?.waveOutlineColor,k=e&&d?d.selectedWaveFillColor:d?.waveFillColor,S=d?.waveformDrawMode||"inverted",A=a||u;if(n==="spectrogram"&&A)return v.jsx(Jn,{index:p.index,data:a,length:p.length,waveHeight:b,devicePixelRatio:C,samplesPerPixel:x,colorLUT:r,frequencyScaleFn:o,minFrequency:l,maxFrequency:c,workerApi:u,clipId:f,onCanvasesReady:h});if(n==="both"&&A){const $=Math.floor(b/2);return v.jsxs(v.Fragment,{children:[v.jsx(Jn,{index:p.index*2,channelIndex:p.index,data:a,length:p.length,waveHeight:$,devicePixelRatio:C,samplesPerPixel:x,colorLUT:r,frequencyScaleFn:o,minFrequency:l,maxFrequency:c,workerApi:u,clipId:f,onCanvasesReady:h}),v.jsx("div",{style:{position:"absolute",top:(p.index*2+1)*$,width:p.length,height:$},children:v.jsx(Gn,{...p,index:0,waveOutlineColor:w,waveFillColor:k,waveHeight:$,devicePixelRatio:C,barWidth:y,barGap:g,transparentBackground:t,drawMode:S})})]})}return v.jsx(Gn,{...p,waveOutlineColor:w,waveFillColor:k,waveHeight:b,devicePixelRatio:C,barWidth:y,barGap:g,transparentBackground:t,drawMode:S})},Qn=72,jo=D.div`
|
|
539
539
|
position: sticky;
|
|
540
540
|
left: 0;
|
|
541
541
|
z-index: 101;
|
|
@@ -543,34 +543,34 @@
|
|
|
543
543
|
height: 0;
|
|
544
544
|
width: 0;
|
|
545
545
|
overflow: visible;
|
|
546
|
-
`;function
|
|
546
|
+
`;function zo(e,t,n){const r=[20,50,100,200,500,1e3,2e3,3e3,4e3,5e3,8e3,1e4,12e3,16e3,2e4].filter(c=>c>=e&&c<=t),s=Math.max(2,Math.floor(n/20));if(r.length<=s)return r;const o=(r.length-1)/(s-1),l=[];for(let c=0;c<s;c++)l.push(r[Math.round(c*o)]);return l}var Ho=({waveHeight:e,numChannels:t,frequencyScaleFn:n,minFrequency:a,maxFrequency:r,labelsColor:s="#ccc",labelsBackground:o="rgba(0,0,0,0.6)",renderMode:l="spectrogram",hasClipHeaders:c=!1})=>{const u=i.useRef(null),f=sn(),h=l==="both"?Math.floor(e/2):e,p=t*e,d=c?22:0;return i.useLayoutEffect(()=>{const b=u.current;if(!b)return;const y=b.getContext("2d");if(!y)return;y.resetTransform(),y.clearRect(0,0,b.width,b.height),y.scale(f,f);const g=zo(a,r,h);for(let m=0;m<t;m++){const C=m*e+d;y.font="11px monospace",y.textBaseline="middle";for(const x of g){const w=n(x,a,r);if(w<0||w>1)continue;const k=C+h*(1-w),S=x>=1e3?`${(x/1e3).toFixed(1)}k`:`${x} Hz`,A=y.measureText(S),$=3;y.fillStyle=o,y.fillRect(0,k-7,A.width+$*2,14),y.fillStyle=s,y.fillText(S,$,k)}}},[e,t,n,a,r,s,o,f,h,d]),v.jsx(jo,{$height:p+d,children:v.jsx("canvas",{ref:u,width:Qn*f,height:(p+d)*f,style:{width:Qn,height:p+d,pointerEvents:"none"}})})};function Xo(e,t,n){return Math.ceil(e*n/t)}function Oo(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var No=D.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
|
|
547
547
|
position: relative;
|
|
548
548
|
overflow: visible; /* Allow time labels to render above the container */
|
|
549
549
|
border-bottom: 1px solid ${e=>e.theme.timeColor};
|
|
550
550
|
box-sizing: border-box;
|
|
551
|
-
`,
|
|
551
|
+
`,Go=D.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`,left:`${e.$left}px`}}))`
|
|
552
552
|
position: absolute;
|
|
553
553
|
bottom: 0;
|
|
554
554
|
/* Promote to own compositing layer for smoother scrolling */
|
|
555
555
|
will-change: transform;
|
|
556
|
-
`,
|
|
556
|
+
`,Yo=D.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
|
|
557
557
|
position: absolute;
|
|
558
558
|
font-size: 0.75rem; /* Smaller font to prevent overflow */
|
|
559
559
|
white-space: nowrap; /* Prevent text wrapping */
|
|
560
560
|
color: ${e=>e.theme.timeColor}; /* Use theme color instead of inheriting */
|
|
561
|
-
`,
|
|
561
|
+
`,Uo=e=>{const{theme:{timeColor:t},duration:n,marker:a,bigStep:r,secondStep:s,renderTimestamp:o}=e,{canvasRef:l,canvasMapRef:c}=rn(),{sampleRate:u,samplesPerPixel:f,timeScaleHeight:h,controls:{show:p,width:d}}=i.useContext(wt),b=sn(),{widthX:y,canvasInfo:g,timeMarkersWithPositions:m}=i.useMemo(()=>{const A=new Map,$=[],_=Xo(n/1e3,f,u),E=u/f;let R=0;for(let W=0;W<_;W+=E*s/1e3){const T=Math.floor(W);if(R%a===0){const F=R,P=Oo(F),O=o?v.jsx(i.Fragment,{children:o(F,T)},`timestamp-${R}`):v.jsx(Yo,{$left:T,children:P},P);$.push({pix:T,element:O}),A.set(T,h)}else R%r===0?A.set(T,Math.floor(h/2)):R%s===0&&A.set(T,Math.floor(h/5));R+=s}return{widthX:_,canvasInfo:A,timeMarkersWithPositions:$}},[n,f,u,a,r,s,o,h]),C=an(y,Se),x=C.map(A=>{const $=A*Se,_=Math.min(y-$,Se);return v.jsx(Go,{$cssWidth:_,$left:$,$timeScaleHeight:h,width:_*b,height:h*b,"data-index":A,ref:l},`timescale-${A}`)}),w=C.length>0?C[0]*Se:0,k=C.length>0?(C[C.length-1]+1)*Se:1/0,S=C.length>0?m.filter(({pix:A})=>A>=w&&A<k).map(({element:A})=>A):m.map(({element:A})=>A);return i.useLayoutEffect(()=>{for(const[A,$]of c.current.entries()){const _=$.getContext("2d");if(!_)continue;const E=A*Se,R=$.width/b;_.resetTransform(),_.clearRect(0,0,$.width,$.height),_.imageSmoothingEnabled=!1,_.fillStyle=t,_.scale(b,b);for(const[W,T]of g.entries()){if(W<E||W>=E+R)continue;const F=W-E,P=h-T;_.fillRect(F,P,1,T)}}},[c,n,b,t,h,g,C]),v.jsxs(No,{$cssWidth:y,$controlWidth:p?d:0,$timeScaleHeight:h,children:[S,x]})},Ko=D.withTheme(Uo),ea=new Map([[700,{marker:1e3,bigStep:500,smallStep:100}],[1500,{marker:2e3,bigStep:1e3,smallStep:200}],[2500,{marker:2e3,bigStep:1e3,smallStep:500}],[5e3,{marker:5e3,bigStep:1e3,smallStep:500}],[1e4,{marker:1e4,bigStep:5e3,smallStep:1e3}],[12e3,{marker:15e3,bigStep:5e3,smallStep:1e3}],[1/0,{marker:3e4,bigStep:1e4,smallStep:5e3}]]);function qo(e){const t=ea.keys();let n;for(const a of t)if(e<a){n=ea.get(a);break}return n===void 0&&(n={marker:3e4,bigStep:1e4,smallStep:5e3}),n}var Wa=({renderTimestamp:e})=>{const{samplesPerPixel:t,duration:n}=i.useContext(wt);let a=qo(t);return v.jsx(Ko,{marker:a.marker,bigStep:a.bigStep,secondStep:a.smallStep,duration:n,renderTimestamp:e})},Jo=D.div`
|
|
562
562
|
display: inline-flex;
|
|
563
563
|
align-items: center;
|
|
564
564
|
gap: 0.5rem;
|
|
565
|
-
`,
|
|
565
|
+
`,Qo=[{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"}],es=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return v.jsx(Jo,{className:a,children:v.jsx(xa,{className:"time-format",value:e,onChange:r,disabled:n,"aria-label":"Time format selection",children:Qo.map(s=>v.jsx("option",{value:s.value,children:s.label},s.value))})})},ts=D.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?Ma:0)}px`}}))`
|
|
566
566
|
position: relative;
|
|
567
567
|
display: flex;
|
|
568
568
|
${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
|
|
569
|
-
`,
|
|
569
|
+
`,ns=D.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
|
|
570
570
|
position: relative;
|
|
571
571
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
572
572
|
flex: 1;
|
|
573
|
-
`,
|
|
573
|
+
`,as=D.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
|
|
574
574
|
position: sticky;
|
|
575
575
|
z-index: 102; /* Above waveform content and spectrogram labels (101), below Docusaurus navbar (200) */
|
|
576
576
|
left: 0;
|
|
@@ -584,7 +584,7 @@
|
|
|
584
584
|
${e=>e.$isSelected&&`
|
|
585
585
|
background: ${e.theme.selectedTrackControlsBackground};
|
|
586
586
|
`}
|
|
587
|
-
`,
|
|
587
|
+
`,Va=({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:f,controls:{show:h,width:p}}=Bt(),d=To();return v.jsxs(ts,{$numChannels:e,className:n,$waveHeight:f,$controlWidth:h?p:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[v.jsx(as,{$controlWidth:h?p:0,$isSelected:u,children:d}),v.jsx(ns,{$controlWidth:h?p:0,$backgroundColor:a,$offset:r,onClick:l,"data-track-id":c,children:t})]})},ta=D.button.attrs({type:"button"})`
|
|
588
588
|
display: inline-block;
|
|
589
589
|
font-family: ${e=>e.theme.fontFamily};
|
|
590
590
|
font-weight: 500;
|
|
@@ -646,7 +646,7 @@
|
|
|
646
646
|
box-shadow: 0 0 0 0.2rem ${e.theme.inputFocusBorder}33;
|
|
647
647
|
}
|
|
648
648
|
`}
|
|
649
|
-
`,
|
|
649
|
+
`,rs=D.div`
|
|
650
650
|
margin-bottom: 0.3rem;
|
|
651
651
|
|
|
652
652
|
button:not(:first-child) {
|
|
@@ -658,7 +658,7 @@
|
|
|
658
658
|
border-top-right-radius: 0;
|
|
659
659
|
border-bottom-right-radius: 0;
|
|
660
660
|
}
|
|
661
|
-
`,
|
|
661
|
+
`,os=D.button`
|
|
662
662
|
position: absolute;
|
|
663
663
|
left: 0;
|
|
664
664
|
top: 0;
|
|
@@ -680,7 +680,7 @@
|
|
|
680
680
|
opacity: 1;
|
|
681
681
|
color: #dc3545;
|
|
682
682
|
}
|
|
683
|
-
|
|
683
|
+
`,ss=({onClick:e,title:t="Remove track"})=>v.jsx(os,{onClick:e,title:t,children:v.jsx(zr,{size:12,weight:"bold"})}),is=D.div`
|
|
684
684
|
background: transparent;
|
|
685
685
|
width: 100%;
|
|
686
686
|
height: 100%;
|
|
@@ -693,7 +693,7 @@
|
|
|
693
693
|
text-align: center;
|
|
694
694
|
border: 1px solid ${e=>e.theme.borderColor};
|
|
695
695
|
border-radius: ${e=>e.theme.borderRadius};
|
|
696
|
-
`,
|
|
696
|
+
`,ls=D.header`
|
|
697
697
|
overflow: hidden;
|
|
698
698
|
height: 26px;
|
|
699
699
|
width: 100%;
|
|
@@ -704,7 +704,7 @@
|
|
|
704
704
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
705
705
|
color: ${e=>e.theme.textColor};
|
|
706
706
|
background-color: transparent;
|
|
707
|
-
`,
|
|
707
|
+
`,cs=e=>v.jsx(wa,{weight:"light",...e}),us=e=>v.jsx(va,{weight:"light",...e}),ds=e=>v.jsx(ba,{weight:"bold",...e}),na=D(ka)`
|
|
708
708
|
width: 75%;
|
|
709
709
|
height: 5px;
|
|
710
710
|
background: ${e=>e.theme.sliderTrackColor};
|
|
@@ -753,7 +753,7 @@
|
|
|
753
753
|
&:focus::-moz-range-thumb {
|
|
754
754
|
border: 2px solid ${e=>e.theme.textColor};
|
|
755
755
|
}
|
|
756
|
-
`,
|
|
756
|
+
`,aa=D.label`
|
|
757
757
|
width: 100%;
|
|
758
758
|
display: flex;
|
|
759
759
|
justify-content: space-between;
|
|
@@ -761,10 +761,10 @@
|
|
|
761
761
|
padding: 0 1rem;
|
|
762
762
|
margin-bottom: 0.2rem;
|
|
763
763
|
font-size: 14px;
|
|
764
|
-
`,
|
|
764
|
+
`,fs=D.div`
|
|
765
765
|
position: relative;
|
|
766
766
|
display: inline-block;
|
|
767
|
-
`,
|
|
767
|
+
`,ms=D.button`
|
|
768
768
|
background: none;
|
|
769
769
|
border: none;
|
|
770
770
|
cursor: pointer;
|
|
@@ -778,7 +778,7 @@
|
|
|
778
778
|
&:hover {
|
|
779
779
|
opacity: 1;
|
|
780
780
|
}
|
|
781
|
-
`,
|
|
781
|
+
`,hs=D.div`
|
|
782
782
|
position: fixed;
|
|
783
783
|
top: ${e=>e.$top}px;
|
|
784
784
|
left: ${e=>e.$left}px;
|
|
@@ -790,12 +790,12 @@
|
|
|
790
790
|
padding: 0.5rem 0;
|
|
791
791
|
min-width: 180px;
|
|
792
792
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
793
|
-
`,
|
|
793
|
+
`,ps=D.hr`
|
|
794
794
|
border: none;
|
|
795
795
|
border-top: 1px solid rgba(128, 128, 128, 0.3);
|
|
796
796
|
margin: 0.35rem 0;
|
|
797
|
-
`,
|
|
798
|
-
`,10)+1,s=a.substring(r)+"",i=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(i)}function Jo(e,t,n){var a;return function(s){return a=a||qo(e),new Worker(a,s)}}var Qo=Jo("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function Ze(e){if(No(e)&&(e=Uo(e)),Yo(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new lt(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var gt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function es(e){var t={scale:e.scale||gt.scale,bits:e.bits||gt.bits,amplitude_scale:e.amplitude_scale||gt.amplitude_scale,split_channels:e.split_channels||gt.split_channels,disable_worker:e.disable_worker||gt.disable_worker};return t}function ts(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function va(e,t,n){var a=ts(e);if(t.disable_worker){var r=Go({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a});n(void 0,new Ze(r),e)}else{var s=new Qo;s.onmessage=function(i){n(void 0,new Ze(i.data),e)},s.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a},a)}}function ns(e,t,n,a){function r(i){i||(i=new DOMException("EncodingError")),a(i),a=function(){}}var s=e.decodeAudioData(t,function(i){va(i,n,a)},r);s&&s.catch(r)}Ze.create=function(t){return new Ze(t)};Ze.createFromAudio=function(e,t){var n=es(e);if(e.audio_context&&e.array_buffer)return ns(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return va(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Ft(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),a=24,r=this._inputData.bits===8?1:2,s=a+n*2*this._inputData.channels*r;this._output_data=new ArrayBuffer(s),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new Ze(this._output_data),this._input_index=0,this._output_index=0;var i=this._inputData.channels;this._min=new Array(i),this._max=new Array(i);for(var l=0;l<i;++l)this._input_buffer_size>0?(this._min[l]=this._inputData.channel(l).min_sample(this._input_index),this._max[l]=this._inputData.channel(l).max_sample(this._input_index)):(this._min[l]=0,this._max[l]=0);this._min_value=this._inputData.bits===8?-128:-32768,this._max_value=this._inputData.bits===8?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}Ft.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Ft.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,a;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var r=0;r<n;++r)a=this._outputWaveformData.channel(r),a.set_min_sample(this._output_index-1,this._min[r]),a.set_max_sample(this._output_index-1,this._max[r]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var s=0;s<n;++s)this._min[s]=this._max_value,this._max[s]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var i=0;i<n;++i){a=this._inputData.channel(i);var l=a.min_sample(this._input_index);l<this._min[i]&&(this._min[i]=l),l=a.max_sample(this._input_index),l>this._max[i]&&(this._max[i]=l)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var c=0;c<n;++c)a=this._outputWaveformData.channel(c),a.set_min_sample(this._output_index-1,this._min[c]),a.set_max_sample(this._output_index-1,this._max[c]);return!0};Ft.prototype.getOutputData=function(){return this._output_data};Ze.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!ft(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!ft(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new Ft(t);!n.next(););return new Ze(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(r){if(t.channels!==r.channels||t.sample_rate!==r.sample_rate||t.bits!==r.bits||t.scale!==r.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var a=this._concatBuffers.apply(this,n);return Ze.create(a)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,a=n,r=0,s=[this].concat(t).map(function(d){return d._data.buffer}),i=0;i<s.length;i++){var l=s[i],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),m=new DataView(s[0]),h=new DataView(u),p=0;p<n;p++)h.setUint8(p,m.getUint8(p));h.setInt32(16,r,!0);for(var f=0,b=new Uint8Array(u,n),w=0;w<s.length;w++){var g=s[w];b.set(new Uint8Array(g,n),f),f+=g.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!ft(t.startIndex)&&!ft(t.endIndex)?(n=t.startIndex,a=t.endIndex):!ft(t.startTime)&&!ft(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,s=24,i=this.bits===8?1:2,l=s+r*2*this.channels*i,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var m=0;m<r*this.channels*2;m++){var h=this._at(n*this.channels*2+m);this.bits===8?u.setInt8(s+m,h):u.setInt16(s+m*2,h,!0)}return new Ze(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var a=0;a<this.channels;a++)t.data.push(this.channel(a).min_sample(n)),t.data.push(this.channel(a).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function nn(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const a=await t.arrayBuffer();return Ze.create(a)}else{const a=await t.json();return Ze.create(a)}}function Ca(e,t=0){const n=e.channel(t),a=e.bits,r=n.min_array(),s=n.max_array(),i=r.length,l=a===8?new Int8Array(i*2):new Int16Array(i*2);for(let c=0;c<i;c++)l[c*2]=r[c],l[c*2+1]=s[c];return{data:l,bits:a,length:i,sampleRate:e.sample_rate}}async function as(e,t=0){const n=await nn(e);return Ca(n,t)}async function rs(e){const t=await nn(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function os(e,t,n=0,a,r){let s=e;if(r!==void 0){const p=e.scale,f=Math.floor(a/p),b=Math.ceil((a+r)/p);s=s.slice({startIndex:f,endIndex:b})}s.scale!==t&&(s=s.resample({scale:t}));const i=s.channel(n),l=s.bits,c=i.min_array(),u=i.max_array(),m=c.length,h=l===8?new Int8Array(m*2):new Int16Array(m*2);for(let p=0;p<m;p++)h[p*2]=c[p],h[p*2+1]=u[p];return{data:h,bits:l,length:m}}function Vn(e,t,n,a,r){let s=e;if(a!==void 0&&r!==void 0){const m=e.scale,h=Math.floor(a/m),p=Math.ceil((a+r)/m);s=s.slice({startIndex:h,endIndex:p})}s.scale!==t&&(s=s.resample({scale:t}));const i=s.channels,l=s.bits,c=[];for(let m=0;m<i;m++){const h=s.channel(m),p=h.min_array(),f=h.max_array(),b=p.length,w=l===8?new Int8Array(b*2):new Int16Array(b*2);for(let g=0;g<b;g++)w[g*2]=p[g],w[g*2+1]=f[g];c.push(w)}if(n&&c.length>1){const m=1/c.length,h=c[0].length/2,p=l===8?new Int8Array(h*2):new Int16Array(h*2);for(let f=0;f<h;f++){let b=0,w=0;for(let g=0;g<c.length;g++)b+=m*c[g][f*2],w+=m*c[g][f*2+1];p[f*2]=b,p[f*2+1]=w}return{length:h,data:[p],bits:l}}return{length:c.length>0?c[0].length/2:0,data:c,bits:l}}function wa(){const[e,t]=o.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>mt(r,e),parseTime:r=>fa(r,e)}}const ss=[256,512,1024,2048,4096,8192];function ya({initialSamplesPerPixel:e,zoomLevels:t=ss}){const[n,a]=o.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),r=t[n],s=n>0,i=n<t.length-1,l=o.useCallback(()=>{o.startTransition(()=>{a(u=>Math.max(0,u-1))})},[]),c=o.useCallback(()=>{o.startTransition(()=>{a(u=>Math.min(t.length-1,u+1))})},[t.length]);return{samplesPerPixel:r,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:i}}function xa({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[a,r]=o.useState(t),s=o.useCallback(i=>{r(i),e.current&&e.current.setMasterGain(i),n?.(i)},[e,n]);return{masterVolume:a,setMasterVolume:s}}const is=(e=256)=>{const t=o.useRef(null),n=o.useCallback((a,r,s)=>{const i=new Z.Analyser("fft",e);return a.connect(i),a.connect(r),t.current=i,function(){i.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function ls(e,t={}){const{progressive:n=!1}=t,[a,r]=o.useState([]),[s,i]=o.useState(!0),[l,c]=o.useState(null),[u,m]=o.useState(0),h=e.length;return o.useEffect(()=>{if(e.length===0){r([]),i(!1),m(0);return}let p=!1;const f=new AbortController,b=new Map,w=(d,x,y)=>{const C=y??d.audioBuffer;if(!C&&!d.waveformData)throw new Error(`Track ${x+1}: Must provide src, audioBuffer, or waveformData`);const k=C?.duration??d.waveformData?.duration,S=Gn({audioBuffer:C,startTime:d.startTime??0,duration:d.duration??k,offset:d.offset??0,name:d.name||`Track ${x+1}`,fadeIn:d.fadeIn,fadeOut:d.fadeOut,waveformData:d.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${x+1}`);return{...Nn({name:d.name||`Track ${x+1}`,clips:[S],muted:d.muted??!1,soloed:d.soloed??!1,volume:d.volume??1,pan:d.pan??0,color:d.color}),effects:d.effects,renderMode:d.renderMode,spectrogramConfig:d.spectrogramConfig,spectrogramColorMap:d.spectrogramColorMap}};return(async()=>{try{i(!0),c(null),m(0);const d=On.getContext().rawContext,x=e.map(async(C,k)=>{if(C.audioBuffer){const _=w(C,k,C.audioBuffer);return n&&!p&&(b.set(k,_),m(I=>I+1),r(Array.from({length:e.length},(I,B)=>b.get(B)).filter(I=>I!==void 0))),_}if(!C.src&&C.waveformData){const _=w(C,k);return n&&!p&&(b.set(k,_),m(I=>I+1),r(Array.from({length:e.length},(I,B)=>b.get(B)).filter(I=>I!==void 0))),_}if(!C.src)throw new Error(`Track ${k+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(C.src,{signal:f.signal});if(!S.ok)throw new Error(`Failed to fetch ${C.src}: ${S.statusText}`);const M=await S.arrayBuffer(),A=await d.decodeAudioData(M);if(!A||!A.sampleRate||!A.duration)throw new Error(`Invalid audio buffer for ${C.src}`);const E=w(C,k,A);return n&&!p&&(b.set(k,E),m(_=>_+1),r(Array.from({length:e.length},(_,I)=>b.get(I)).filter(_=>_!==void 0))),E}),y=await Promise.all(x);p||(n||(r(y),m(y.length)),i(!1))}catch(d){if(!p){const x=d instanceof Error?d.message:"Unknown error loading audio";c(x),i(!1),console.error("Error loading audio tracks:",d)}}})(),()=>{p=!0,f.abort()}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:h}}function cs({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=o.useRef(null),s=o.useCallback(u=>{const{transform:m,active:h}=u;if(!h?.data?.current)return{...m,scaleX:1,scaleY:1};const{trackIndex:p,clipIndex:f,boundary:b}=h.data.current;if(b)return{...m,scaleX:1,scaleY:1};const w=e[p];if(!w)return{...m,scaleX:1,scaleY:1};const g=w.clips[f];if(!g)return{...m,scaleX:1,scaleY:1};const d=g.startSample/a,x=g.durationSamples/a,y=m.x*n/a;let C=d+y;const k=[...w.clips].sort((I,B)=>I.startSample-B.startSample),S=k.findIndex(I=>I===g);C=Math.max(0,C);const M=S>0?k[S-1]:null;if(M){const I=(M.startSample+M.durationSamples)/a;C=Math.max(C,I)}const A=S<k.length-1?k[S+1]:null;if(A){const I=C+x,B=A.startSample/a;I>B&&(C=B-x)}const _=(C-d)*a/n;return{...m,x:_,scaleX:1,scaleY:1}},[e,n,a]),i=o.useCallback(u=>{const{active:m}=u,{boundary:h}=m.data.current;if(!h){r.current=null;return}const{trackIndex:p,clipIndex:f}=m.data.current,w=e[p]?.clips[f];w&&(r.current={offsetSamples:w.offsetSamples,durationSamples:w.durationSamples,startSample:w.startSample})},[e]),l=o.useCallback(u=>{const{active:m,delta:h}=u,{boundary:p}=m.data.current;if(!p||!r.current)return;const{trackIndex:f,clipIndex:b}=m.data.current,w=h.x*n,g=Math.floor(.1*a),d=r.current,x=e.map((y,C)=>{if(C!==f)return y;const k=[...y.clips].sort((A,E)=>A.startSample-E.startSample),S=k.findIndex(A=>A===y.clips[b]),M=y.clips.map((A,E)=>{if(E!==b)return A;const _=A.sourceDurationSamples;if(p==="left"){let I=Math.floor(w);const B=-d.startSample;I<B&&(I=B);const $=-d.offsetSamples;I<$&&(I=$);const W=S>0?k[S-1]:null;if(W){const ae=W.startSample+W.durationSamples-d.startSample;I<ae&&(I=ae)}const z=d.durationSamples-g;I>z&&(I=z);const Y=d.offsetSamples+I,j=d.durationSamples-I,N=d.startSample+I;return{...A,offsetSamples:Y,durationSamples:j,startSample:N}}else{let I=Math.floor(d.durationSamples+w);I=Math.max(g,I),d.offsetSamples+I>_&&(I=_-d.offsetSamples);const B=S<k.length-1?k[S+1]:null;return B&&d.startSample+I>B.startSample&&(I=B.startSample-d.startSample,I=Math.max(g,I)),{...A,durationSamples:I}}});return{...y,clips:M}});t(x)},[e,t,n,a]),c=o.useCallback(u=>{const{active:m,delta:h}=u,{trackIndex:p,clipIndex:f,boundary:b}=m.data.current,w=h.x*n;if(b){r.current=null;return}const g=e.map((d,x)=>{if(x!==p)return d;const y=[...d.clips].sort((S,M)=>S.startSample-M.startSample),C=y.findIndex(S=>S===d.clips[f]),k=d.clips.map((S,M)=>{if(M!==f)return S;let A=Math.floor(S.startSample+w);A=Math.max(0,A);const E=C>0?y[C-1]:null;if(E){const I=E.startSample+E.durationSamples;A=Math.max(A,I)}const _=C<y.length-1?y[C+1]:null;return _&&A+S.durationSamples>_.startSample&&(A=_.startSample-S.durationSamples),{...S,startSample:A}});return{...d,clips:k}});t(g)},[e,t,n]);return{onDragStart:i,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Ht=.01;function ka({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const i=o.useRef(null),l=o.useCallback(m=>{const{active:h}=m,p=h.data.current;if(!p||p.annotationIndex===void 0){i.current=null;return}const f=e[p.annotationIndex];f&&(i.current={start:f.start,end:f.end,annotationIndex:p.annotationIndex})},[e]),c=o.useCallback(m=>{const{active:h,delta:p}=m;if(!i.current)return;const f=h.data.current;if(!f)return;const{edge:b,annotationIndex:w}=f,g=i.current,d=p.x*n/a,x=b==="start"?g.start+d:g.end+d,y=us({annotationIndex:w,newTime:x,isDraggingStart:b==="start",annotations:e,duration:r,linkEndpoints:s});t(y)},[e,t,n,a,r,s]),u=o.useCallback(()=>{i.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function us({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const i=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(i[e]={...l,start:c},s&&e>0){const m=i[e-1];Math.abs(m.end-l.start)<Ht?i[e-1]={...m,end:Math.max(m.start+.1,m.end+u)}:c<=m.end&&(i[e]={...i[e],start:m.end})}else!s&&e>0&&c<i[e-1].end&&(i[e-1]={...i[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(i[e]={...l,end:c},s&&e<i.length-1){const m=i[e+1];if(Math.abs(m.start-l.end)<Ht){const h=m.start+u;i[e+1]={...m,start:Math.min(m.end-.1,h)};let p=e+1;for(;p<i.length-1;){const f=i[p],b=i[p+1];if(Math.abs(b.start-f.end)<Ht){const w=f.end-a[p].end;i[p+1]={...b,start:Math.min(b.end-.1,b.start+w)},p++}else break}}else c>=m.start&&(i[e]={...i[e],end:m.start})}else if(!s&&e<i.length-1&&c>i[e+1].start){const m=i[e+1];i[e+1]={...m,start:c};let h=e+1;for(;h<i.length-1;){const p=i[h],f=i[h+1];if(p.end>f.start)i[h+1]={...f,start:p.end},h++;else break}}}return i}function ds(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Ke.useSensor(Ke.MouseSensor,{activationConstraint:{distance:r}}),i=Ke.useSensor(Ke.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Ke.useSensor(Ke.PointerSensor,{activationConstraint:{distance:r}});return Ke.useSensors(...t?[s,i]:[l])}const fs=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Re(),{selectedTrackId:s}=De(),i=o.useCallback((c,u,m)=>{const{sampleRate:h,samplesPerPixel:p}=e,f=t[c];if(!f)return!1;const b=f.clips[u];if(!b)return!1;const w=b.startSample/h,g=(b.startSample+b.durationSamples)/h;if(m<=w||m>=g)return console.warn("Split time is outside clip bounds"),!1;const d=Math.round(m*h),x=Math.floor(d/p),y=b.startSample+b.durationSamples,C=x*p,k=b.startSample,S=C-k,M=C,A=y-M,E=C-b.startSample,_=Gt({audioBuffer:b.audioBuffer,startSample:k,durationSamples:S,offsetSamples:b.offsetSamples,sampleRate:b.sampleRate,sourceDurationSamples:b.sourceDurationSamples,gain:b.gain,name:b.name?`${b.name} (1)`:void 0,color:b.color,fadeIn:b.fadeIn,waveformData:b.waveformData}),I=Gt({audioBuffer:b.audioBuffer,startSample:M,durationSamples:A,offsetSamples:b.offsetSamples+E,sampleRate:b.sampleRate,sourceDurationSamples:b.sourceDurationSamples,gain:b.gain,name:b.name?`${b.name} (2)`:void 0,color:b.color,waveformData:b.waveformData,fadeOut:b.fadeOut}),B=[...f.clips];B.splice(u,1,_,I);const $=[...t];return $[c]={...f,clips:B},n($),!0},[t,n,e]);return{splitClipAtPlayhead:o.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(h=>h.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],m=r.current??0;for(let h=0;h<u.clips.length;h++){const p=u.clips[h],f=p.startSample/a,b=(p.startSample+p.durationSamples)/a;if(m>f&&m<b)return console.log(`Splitting clip on track "${u.name}" at ${m}s`),i(c,h,m)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,i,a]),splitClipAt:i}},Dt=e=>{const{shortcuts:t,enabled:n=!0}=e,a=o.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const i=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,m=l.shiftKey===void 0||r.shiftKey===l.shiftKey,h=l.metaKey===void 0||r.metaKey===l.metaKey,p=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&m&&h&&p});i&&(i.preventDefault!==!1&&r.preventDefault(),i.action())},[t,n]);o.useEffect(()=>{if(n)return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[a,n])},ms=e=>{const t=[],n=typeof navigator<"u"&&navigator.platform.includes("Mac");return e.metaKey&&t.push(n?"Cmd":"Ctrl"),e.ctrlKey&&!e.metaKey&&t.push("Ctrl"),e.altKey&&t.push(n?"Option":"Alt"),e.shiftKey&&t.push("Shift"),t.push(e.key.toUpperCase()),t.join("+")},hs=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Re(),{setCurrentTime:s,play:i,pause:l,stop:c}=be(),{playoutRef:u}=Me(),m=o.useCallback(()=>{r?l():i()},[r,i,l]),h=o.useCallback(()=>{c()},[c]),p=o.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),i(0)):s(0)},[r,u,s,i]),b=a??[...[{key:" ",action:m,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:h,description:"Stop",preventDefault:!0},{key:"0",action:p,description:"Rewind to start",preventDefault:!0}],...n];return Dt({shortcuts:b,enabled:t}),{rewindToStart:p,togglePlayPause:m,stopPlayback:h,shortcuts:b}},Xt=.01,_t=.01;function ps({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:i=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:m,controlsWidth:h=0,onPlay:p}){const f=o.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),b=o.useCallback(E=>{if(!c?.current||!u||!m)return;const _=e.find(L=>L.id===E);if(!_)return;const I=c.current,B=I.clientWidth,$=_.start*m/u+h,W=_.end*m/u+h,z=($+W)/2,Y=I.scrollLeft,j=Y,N=Y+B;if($<j||W>N){const L=Math.max(0,z-B/2);I.scrollTo({left:L,behavior:"smooth"})}},[e,c,u,m,h]);o.useEffect(()=>{t&&c?.current&&u&&m&&b(t)},[t,b,c,u,m]);const w=o.useCallback(E=>{if(f<0)return;const _=e[f],I=Math.max(0,Math.min(_.end-.1,_.start+E)),B=I-_.start,$=[...e];if($[f]={..._,start:I},s&&f>0){const W=$[f-1];Math.abs(W.end-_.start)<Xt&&($[f-1]={...W,end:Math.max(W.start+.1,W.end+B)})}else if(!s&&f>0){const W=$[f-1];I<W.end&&($[f-1]={...W,end:I})}n($)},[e,f,s,n]),g=o.useCallback(E=>{if(f<0)return;const _=e[f],I=Math.max(_.start+.1,Math.min(r,_.end+E)),B=I-_.end,$=[...e];if($[f]={..._,end:I},s&&f<e.length-1){const W=$[f+1];if(Math.abs(W.start-_.end)<Xt){const z=Math.min(W.end-.1,W.start+B);$[f+1]={...W,start:z};let Y=f+1;for(;Y<$.length-1;){const j=$[Y],N=$[Y+1];if(Math.abs(N.start-e[Y].end)<Xt){const L=j.end-e[Y].end;$[Y+1]={...N,start:Math.min(N.end-.1,N.start+L)},Y++}else break}}}else if(!s&&f<e.length-1){const W=$[f+1];if(I>W.start){$[f+1]={...W,start:I};let z=f+1;for(;z<$.length-1;){const Y=$[z],j=$[z+1];if(Y.end>j.start)$[z+1]={...j,start:Y.end},z++;else break}}}n($)},[e,f,r,s,n]),d=o.useCallback(()=>{!a||e.length===0||(f<=0?a(e[e.length-1].id):a(e[f-1].id))},[e,f,a]),x=o.useCallback(()=>{!a||e.length===0||(f<0||f>=e.length-1?a(e[0].id):a(e[f+1].id))},[e,f,a]),y=o.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),C=o.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),k=o.useCallback(()=>{a&&a(null)},[a]),S=o.useCallback(()=>{if(f<0||!p)return;const E=e[f],_=i?void 0:E.end-E.start;p(E.start,_)},[e,f,i,p]),M=o.useMemo(()=>[{key:"[",action:()=>w(-_t),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>w(_t),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>g(-_t),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>g(_t),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:S,description:"Play selected annotation",preventDefault:!0}],[w,g,S]),A=o.useMemo(()=>[{key:"ArrowUp",action:d,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:d,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:x,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:x,description:"Select next annotation",preventDefault:!0},{key:"Home",action:y,description:"Select first annotation",preventDefault:!0},{key:"End",action:C,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:k,description:"Deselect annotation",preventDefault:!0}],[d,x,y,C,k]);return Dt({shortcuts:M,enabled:l&&f>=0}),Dt({shortcuts:A,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:w,moveEndBoundary:g,selectPrevious:d,selectNext:x,selectFirst:y,selectLast:C,clearSelection:k,scrollToAnnotation:b,playActiveAnnotation:S}}const yt=[{id:"reverb",name:"Reverb",category:"reverb",description:"Simple convolution reverb with adjustable decay time",parameters:[{name:"decay",label:"Decay",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"s"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"freeverb",name:"Freeverb",category:"reverb",description:"Classic Schroeder/Moorer reverb with room size and dampening",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.7},{name:"dampening",label:"Dampening",type:"number",min:0,max:1e4,step:100,default:3e3,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"jcReverb",name:"JC Reverb",category:"reverb",description:"Attempt at Roland JC-120 chorus reverb emulation",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"feedbackDelay",name:"Feedback Delay",category:"delay",description:"Delay line with feedback for echo effects",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"pingPongDelay",name:"Ping Pong Delay",category:"delay",description:"Stereo delay bouncing between left and right channels",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"chorus",name:"Chorus",category:"modulation",description:"Creates thickness by layering detuned copies of the signal",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"Hz"},{name:"delayTime",label:"Delay",type:"number",min:0,max:20,step:.5,default:3.5,unit:"ms"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.7},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"phaser",name:"Phaser",category:"modulation",description:"Classic phaser effect using allpass filters",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:.5,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:6,step:1,default:3},{name:"baseFrequency",label:"Base Freq",type:"number",min:100,max:2e3,step:10,default:350,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"tremolo",name:"Tremolo",category:"modulation",description:"Rhythmic volume modulation",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:4,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"vibrato",name:"Vibrato",category:"modulation",description:"Pitch modulation effect",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:5,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoPanner",name:"Auto Panner",category:"modulation",description:"Automatic left-right panning",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoFilter",name:"Auto Filter",category:"filter",description:"Automated filter sweep with LFO",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:2e3,step:10,default:200,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:.5,max:8,step:.5,default:2.6},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoWah",name:"Auto Wah",category:"filter",description:"Envelope follower filter effect",parameters:[{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:500,step:10,default:100,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:8,step:1,default:6},{name:"sensitivity",label:"Sensitivity",type:"number",min:-40,max:0,step:1,default:0,unit:"dB"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"eq3",name:"3-Band EQ",category:"filter",description:"Three band equalizer with low, mid, and high controls",parameters:[{name:"low",label:"Low",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"mid",label:"Mid",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"high",label:"High",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"lowFrequency",label:"Low Freq",type:"number",min:20,max:500,step:10,default:400,unit:"Hz"},{name:"highFrequency",label:"High Freq",type:"number",min:1e3,max:1e4,step:100,default:2500,unit:"Hz"}]},{id:"distortion",name:"Distortion",category:"distortion",description:"Wave shaping distortion effect",parameters:[{name:"distortion",label:"Drive",type:"number",min:0,max:1,step:.01,default:.4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"bitCrusher",name:"Bit Crusher",category:"distortion",description:"Reduces bit depth for lo-fi digital texture",parameters:[{name:"bits",label:"Bits",type:"number",min:1,max:16,step:1,default:4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"chebyshev",name:"Chebyshev",category:"distortion",description:"Waveshaping distortion using Chebyshev polynomials",parameters:[{name:"order",label:"Order",type:"number",min:1,max:100,step:1,default:50},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"compressor",name:"Compressor",category:"dynamics",description:"Dynamic range compressor",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-60,max:0,step:1,default:-24,unit:"dB"},{name:"ratio",label:"Ratio",type:"number",min:1,max:20,step:.5,default:4},{name:"attack",label:"Attack",type:"number",min:0,max:1,step:.001,default:.003,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"knee",label:"Knee",type:"number",min:0,max:40,step:1,default:30,unit:"dB"}]},{id:"limiter",name:"Limiter",category:"dynamics",description:"Hard limiter to prevent clipping",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-12,max:0,step:.5,default:-6,unit:"dB"}]},{id:"gate",name:"Gate",category:"dynamics",description:"Noise gate to silence signal below threshold",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-100,max:0,step:1,default:-40,unit:"dB"},{name:"attack",label:"Attack",type:"number",min:0,max:.3,step:.001,default:.001,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:.5,step:.01,default:.1,unit:"s"}]},{id:"stereoWidener",name:"Stereo Widener",category:"spatial",description:"Expands or narrows the stereo image",parameters:[{name:"width",label:"Width",type:"number",min:0,max:1,step:.01,default:.5}]}],an=e=>yt.find(t=>t.id===e),gs=e=>yt.filter(t=>t.category===e),bs=[{id:"reverb",name:"Reverb"},{id:"delay",name:"Delay"},{id:"modulation",name:"Modulation"},{id:"filter",name:"Filter"},{id:"distortion",name:"Distortion"},{id:"dynamics",name:"Dynamics"},{id:"spatial",name:"Spatial"}];const vs={reverb:Z.Reverb,freeverb:Z.Freeverb,jcReverb:Z.JCReverb,feedbackDelay:Z.FeedbackDelay,pingPongDelay:Z.PingPongDelay,chorus:Z.Chorus,phaser:Z.Phaser,tremolo:Z.Tremolo,vibrato:Z.Vibrato,autoPanner:Z.AutoPanner,autoFilter:Z.AutoFilter,autoWah:Z.AutoWah,eq3:Z.EQ3,distortion:Z.Distortion,bitCrusher:Z.BitCrusher,chebyshev:Z.Chebyshev,compressor:Z.Compressor,limiter:Z.Limiter,gate:Z.Gate,stereoWidener:Z.StereoWidener};let Cs=0;const ws=()=>`effect_${Date.now()}_${++Cs}`;function bt(e,t){const n=vs[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(l=>{const c=t?.[l.name]??l.default;a[l.name]=c});const r=new n(a),s=ws(),i=r;return{effect:r,id:e.id,instanceId:s,dispose(){try{r.disconnect(),r.dispose()}catch(l){console.warn(`[waveform-playlist] Error disposing effect "${e.id}" (${s}):`,l)}},setParameter(l,c){const u=i[l];if(l==="wet"){const m=i.wet;if(m&&typeof m=="object"&&"value"in m){m.value=c;return}}u!==void 0&&(u&&typeof u=="object"&&"value"in u?u.value=c:i[l]=c)},getParameter(l){if(l==="wet"){const u=i.wet;if(u&&typeof u=="object"&&"value"in u)return u.value}const c=i[l];if(c!==void 0)return c&&typeof c=="object"&&"value"in c?c.value:c},connect(l){r.connect(l)},disconnect(){try{r.disconnect()}catch(l){console.warn(`[waveform-playlist] Error disconnecting effect "${e.id}" (${s}):`,l)}}}}function ys(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function xs(e=256){const[t,n]=o.useState([]),a=o.useRef(t);a.current=t;const r=o.useRef(new Map),s=o.useRef(null),i=o.useRef(null),l=o.useCallback(g=>{const d=i.current;if(!d)return;const{masterGainNode:x,destination:y,analyserNode:C}=d;try{x.disconnect()}catch(S){console.warn("[waveform-playlist] Error disconnecting master effects chain:",S)}const k=g.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)x.connect(C),C.connect(y);else{let S=x;k.forEach(M=>{try{M.disconnect()}catch(A){console.warn(`[waveform-playlist] Error disconnecting effect "${M.id}":`,A)}S.connect(M.effect),S=M.effect}),S.connect(C),C.connect(y)}},[]),c=o.useCallback(g=>{const d=an(g);if(!d){console.error(`Unknown effect: ${g}`);return}const x={};d.parameters.forEach(k=>{x[k.name]=k.default});const y=bt(d,x);r.current.set(y.instanceId,y);const C={instanceId:y.instanceId,effectId:d.id,definition:d,params:x,bypassed:!1};n(k=>[...k,C])},[]),u=o.useCallback(g=>{const d=r.current.get(g);d&&(d.dispose(),r.current.delete(g)),n(x=>x.filter(y=>y.instanceId!==g))},[]),m=o.useCallback((g,d,x)=>{const y=r.current.get(g);y&&y.setParameter(d,x),n(C=>C.map(k=>k.instanceId===g?{...k,params:{...k.params,[d]:x}}:k))},[]),h=o.useCallback(g=>{const d=a.current.find(C=>C.instanceId===g);if(!d)return;const x=!d.bypassed,y=r.current.get(g);if(y){const C=d.params.wet??1;y.setParameter("wet",x?0:C)}n(C=>C.map(k=>k.instanceId===g?{...k,bypassed:x}:k))},[]),p=o.useCallback((g,d)=>{n(x=>{const y=[...x],[C]=y.splice(g,1);return y.splice(d,0,C),y})},[]),f=o.useCallback(()=>{r.current.forEach(g=>g.dispose()),r.current.clear(),n([])},[]);o.useEffect(()=>{l(t)},[t,l]);const b=o.useCallback((g,d,x)=>{const y=new Z.Analyser("fft",e);s.current=y,i.current={masterGainNode:g,destination:d,analyserNode:y};const k=a.current.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)g.connect(y),y.connect(d);else{let S=g;k.forEach(M=>{S.connect(M.effect),S=M.effect}),S.connect(y),y.connect(d)}return function(){y.dispose(),s.current=null,i.current=null}},[e]);o.useEffect(()=>{const g=r.current;return()=>{g.forEach(d=>d.dispose()),g.clear()}},[]);const w=o.useCallback(()=>{const g=t.filter(d=>!d.bypassed);if(g.length!==0)return(d,x,y)=>{const C=[];for(const k of g){const S=bt(k.definition,k.params);C.push(S)}if(C.length===0)d.connect(x);else{let k=d;C.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(x)}return function(){C.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:yt,addEffect:c,removeEffect:u,updateParameter:m,toggleBypass:h,reorderEffects:p,clearAllEffects:f,masterEffects:b,createOfflineEffectsFunction:w,analyserRef:s}}function ks(){const[e,t]=o.useState(new Map),n=o.useRef(new Map),a=o.useRef(new Map),r=o.useCallback((f,b)=>{const w=a.current.get(f);if(!w)return;const{graphEnd:g,masterGainNode:d}=w,x=n.current.get(f);try{g.disconnect()}catch(C){console.warn(`[waveform-playlist] Error disconnecting track "${f}" effect chain:`,C)}const y=b.map(C=>x?.get(C.instanceId)).filter(C=>C!==void 0);if(y.length===0)g.connect(d);else{let C=g;y.forEach(k=>{try{k.disconnect()}catch(S){console.warn(`[waveform-playlist] Error disconnecting effect "${k.id}" on track "${f}":`,S)}C.connect(k.effect),C=k.effect}),C.connect(d)}},[]),s=o.useCallback((f,b)=>{const w=an(b);if(!w){console.error(`Unknown effect: ${b}`);return}const g={};w.parameters.forEach(y=>{g[y.name]=y.default});const d=bt(w,g);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(d.instanceId,d);const x={instanceId:d.instanceId,effectId:w.id,definition:w,params:g,bypassed:!1};t(y=>{const C=new Map(y),k=C.get(f)||[];return C.set(f,[...k,x]),C})},[]),i=o.useCallback((f,b)=>{const w=n.current.get(f),g=w?.get(b);g&&(g.dispose(),w?.delete(b)),t(d=>{const x=new Map(d),y=x.get(f)||[];return x.set(f,y.filter(C=>C.instanceId!==b)),x})},[]),l=o.useCallback((f,b,w,g)=>{const x=n.current.get(f)?.get(b);x&&x.setParameter(w,g),t(y=>{const C=new Map(y),k=C.get(f)||[];return C.set(f,k.map(S=>S.instanceId===b?{...S,params:{...S.params,[w]:g}}:S)),C})},[]),c=o.useCallback((f,b)=>{const g=(m.current.get(f)||[]).find(C=>C.instanceId===b);if(!g)return;const d=!g.bypassed,y=n.current.get(f)?.get(b);if(y){const C=g.params.wet??1;y.setParameter("wet",d?0:C)}t(C=>{const k=new Map(C),S=k.get(f)||[];return k.set(f,S.map(M=>M.instanceId===b?{...M,bypassed:d}:M)),k})},[]),u=o.useCallback(f=>{const b=n.current.get(f);b&&(b.forEach(w=>w.dispose()),b.clear()),t(w=>{const g=new Map(w);return g.set(f,[]),g})},[]),m=o.useRef(e);m.current=e;const h=o.useCallback(f=>(b,w,g)=>{a.current.set(f,{graphEnd:b,masterGainNode:w});const d=m.current.get(f)||[],x=n.current.get(f),y=d.map(C=>x?.get(C.instanceId)).filter(C=>C!==void 0);if(y.length===0)b.connect(w);else{let C=b;y.forEach(k=>{C.connect(k.effect),C=k.effect}),C.connect(w)}return function(){a.current.delete(f)}},[]);o.useEffect(()=>{e.forEach((f,b)=>{r(b,f)})},[e,r]),o.useEffect(()=>{const f=n.current;return()=>{f.forEach(b=>{b.forEach(w=>w.dispose()),b.clear()}),f.clear()}},[]);const p=o.useCallback(f=>{const w=(e.get(f)||[]).filter(g=>!g.bypassed);if(w.length!==0)return(g,d,x)=>{const y=[];for(const C of w){const k=bt(C.definition,C.params);y.push(k)}if(y.length===0)g.connect(d);else{let C=g;y.forEach(k=>{C.connect(k.effect),C=k.effect}),C.connect(d)}return function(){y.forEach(k=>k.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:i,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:h,createOfflineTrackEffectsFunction:p,availableEffects:yt}}function Ss(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,i=n/8,l=a*i,c=r*l,u=s*l,m=44,h=m+u,p=new ArrayBuffer(h),f=new DataView(p);Et(f,0,"RIFF"),f.setUint32(4,h-8,!0),Et(f,8,"WAVE"),Et(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,n===32?3:1,!0),f.setUint16(22,a,!0),f.setUint32(24,r,!0),f.setUint32(28,c,!0),f.setUint16(32,l,!0),f.setUint16(34,n,!0),Et(f,36,"data"),f.setUint32(40,u,!0);const b=[];for(let g=0;g<a;g++)b.push(e.getChannelData(g));let w=m;if(n===16)for(let g=0;g<s;g++)for(let d=0;d<a;d++){const x=b[d][g],y=Math.max(-1,Math.min(1,x)),C=y<0?y*32768:y*32767;f.setInt16(w,C,!0),w+=2}else for(let g=0;g<s;g++)for(let d=0;d<a;d++)f.setFloat32(w,b[d][g],!0),w+=4;return new Blob([p],{type:"audio/wav"})}function Et(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function Is(e,t){const n=URL.createObjectURL(e),a=document.createElement("a");a.href=n,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}function Sa(){const[e,t]=o.useState(!1),[n,a]=o.useState(0),[r,s]=o.useState(null);return{exportWav:o.useCallback(async(l,c,u={})=>{const{filename:m="export",mode:h="master",trackIndex:p,autoDownload:f=!0,applyEffects:b=!0,effectsFunction:w,createOfflineTrackEffects:g,bitDepth:d=16,onProgress:x}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(h==="individual"&&(p===void 0||p<0||p>=l.length))throw new Error("Invalid track index for individual export");const y=l[0].clips[0]?.sampleRate||44100;let C=0;for(const I of l)for(const B of I.clips){const $=B.startSample+B.durationSamples;C=Math.max(C,$)}C+=Math.round(y*.1);const k=C/y,S=h==="individual"?[{track:l[p],state:c[p],index:p}]:l.map((I,B)=>({track:I,state:c[B],index:B})),M=c.some(I=>I.soloed),A=!!g;let E;if((w||A)&&b)E=await As(S,c,M,k,y,w,g,I=>{a(I),x?.(I)});else{const I=new OfflineAudioContext(2,C,y);let B=0;const $=S.reduce((W,{track:z})=>W+z.clips.length,0);for(const{track:W,state:z}of S)if(!(z.muted&&!z.soloed)&&!(M&&!z.soloed))for(const Y of W.clips){await _s(I,Y,z,y,b),B++;const j=B/$*.5;a(j),x?.(j)}a(.5),x?.(.5),E=await I.startRendering()}a(.9),x?.(.9);const _=Ss(E,{bitDepth:d});if(a(1),x?.(1),f){const I=h==="individual"?`${m}_${l[p].name}`:m;Is(_,`${I}.wav`)}return{audioBuffer:E,blob:_,duration:k}}catch(y){const C=y instanceof Error?y.message:"Export failed";throw s(C),y}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function As(e,t,n,a,r,s,i,l){const{Offline:c,Volume:u,Gain:m,Panner:h,Player:p,ToneAudioBuffer:f}=await import("tone");l(.1);let b;try{b=await c(async({transport:w,destination:g})=>{const d=new u(0);let x;s?x=s(d,g,!0):d.connect(g);for(const{track:y,state:C}of e){if(C.muted&&!C.soloed||n&&!C.soloed)continue;const k=new u(Ms(C.volume)),S=new h(C.pan),M=new m(C.muted?0:1),A=i?.(y.id);A?A(M,d,!0):M.connect(d),S.connect(M),k.connect(S);for(const E of y.clips){const{audioBuffer:_,startSample:I,durationSamples:B,offsetSamples:$,gain:W,fadeIn:z,fadeOut:Y}=E,j=I/r,N=B/r,L=$/r,ae=new f(_),oe=new p(ae),q=new m(W);if(oe.connect(q),q.connect(k),z){const fe=j,ue=j+z.duration,le=Tt(q.gain);le&&(le.setValueAtTime(0,fe),le.linearRampToValueAtTime(W,ue))}if(Y){const fe=j+N-Y.duration,ue=j+N,le=Tt(q.gain);le&&(le.setValueAtTime(W,fe),le.linearRampToValueAtTime(0,ue))}oe.start(j,L,N)}}w.start(0)},a,2,r)}catch(w){throw w instanceof Error?w:new Error(`Tone.Offline rendering failed: ${String(w)}`)}return l(.9),b.get()}function Ms(e){return 20*Math.log10(Math.max(e,1e-4))}async function _s(e,t,n,a,r){const{audioBuffer:s,startSample:i,durationSamples:l,offsetSamples:c,gain:u,fadeIn:m,fadeOut:h}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const p=i/a,f=l/a,b=c/a,w=e.createBufferSource();w.buffer=s;const g=e.createGain(),d=u*n.volume,x=e.createStereoPanner();if(x.pan.value=n.pan,w.connect(g),g.connect(x),x.connect(e.destination),r){if(m?g.gain.setValueAtTime(0,p):g.gain.setValueAtTime(d,p),m){const y=p,C=p+m.duration;jn(g.gain,y,C,0,d,m.type||"linear")}if(h){const y=p+f-h.duration,C=p+f;(!m||m.duration<f-h.duration)&&g.gain.setValueAtTime(d,y),jn(g.gain,y,C,d,0,h.type||"linear")}}else g.gain.setValueAtTime(d,p);w.start(p,b,f)}function jn(e,t,n,a,r,s){const i=n-t;if(!(i<=0))switch(s){case"linear":e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n);break;case"exponential":{const l=Math.max(a,1e-4),c=Math.max(r,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),r===0&&e.setValueAtTime(0,n);break}case"logarithmic":{const l=Ln(a,r,256,"logarithmic");e.setValueCurveAtTime(l,t,i);break}case"sCurve":{const l=Ln(a,r,256,"sCurve");e.setValueCurveAtTime(l,t,i);break}default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function Ln(e,t,n,a){const r=new Float32Array(n),s=t-e;for(let i=0;i<n;i++){const l=i/(n-1);let c;a==="logarithmic"?s>0?c=Math.log10(1+l*9)/Math.log10(10):c=1-Math.log10(1+(1-l)*9)/Math.log10(10):c=l*l*(3-2*l),r[i]=e+s*c}return r}const Ia=()=>{const e=o.useRef(null),t=o.useCallback(()=>{e.current!==null&&(cancelAnimationFrame(e.current),e.current=null)},[]),n=o.useCallback(a=>{t(),e.current=requestAnimationFrame(a)},[t]);return o.useEffect(()=>()=>{t()},[t]),{animationFrameRef:e,startAnimationFrameLoop:n,stopAnimationFrameLoop:t}},Es=`
|
|
797
|
+
`,gs=({items:e})=>{const[t,n]=i.useState(!1),r=typeof e=="function"?e(()=>n(!1)):e,[s,o]=i.useState({top:0,left:0}),l=i.useRef(null),c=i.useRef(null);return i.useEffect(()=>{if(t&&l.current){const u=l.current.getBoundingClientRect();o({top:u.bottom+2,left:Math.max(0,u.right-180)})}},[t]),i.useEffect(()=>{if(!t)return;const u=f=>{const h=f.target;l.current&&!l.current.contains(h)&&c.current&&!c.current.contains(h)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[t]),v.jsxs(fs,{children:[v.jsx(ms,{ref:l,onClick:u=>{u.stopPropagation(),n(f=>!f)},onMouseDown:u=>u.stopPropagation(),title:"Track menu","aria-label":"Track menu",children:v.jsx(ds,{size:16})}),t&&typeof document<"u"&&la.createPortal(v.jsx(hs,{ref:c,$top:s.top,$left:s.left,onMouseDown:u=>u.stopPropagation(),children:r.map((u,f)=>v.jsxs(i.Fragment,{children:[f>0&&v.jsx(ps,{}),u.content]},u.id))}),document.body)]})};function st(e,t){this._waveformData=e,this._channelIndex=t}st.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};st.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};st.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};st.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};st.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};st.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 bs=127,vs=-128,ws=32767,ys=-32768;function Cs(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function xs(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=Cs(r,t),f=e.bits===8?1:2,h=c+u*2*f*l,p=new ArrayBuffer(h),d=new DataView(p),b=0,y=c,g=new Array(l),m=new Array(l),C=0;C<l;C++)g[C]=1/0,m[C]=-1/0;var x=e.bits===8?vs:ys,w=e.bits===8?bs:ws;d.setInt32(0,2,!0),d.setUint32(4,e.bits===8,!0),d.setInt32(8,s,!0),d.setInt32(12,t,!0),d.setInt32(16,u,!0),d.setInt32(20,l,!0);for(var k=0;k<r;k++){var S=0;if(l===1){for(var A=0;A<o.length;++A)S+=o[A][k];S=Math.floor(w*S*n/o.length),S<g[0]&&(g[0]=S,g[0]<x&&(g[0]=x)),S>m[0]&&(m[0]=S,m[0]>w&&(m[0]=w))}else for(var $=0;$<l;++$)S=Math.floor(w*o[$][k]*n),S<g[$]&&(g[$]=S,g[$]<x&&(g[$]=x)),S>m[$]&&(m[$]=S,m[$]>w&&(m[$]=w));if(++b===t){for(var _=0;_<l;_++)e.bits===8?(d.setInt8(y++,g[_]),d.setInt8(y++,m[_])):(d.setInt16(y,g[_],!0),d.setInt16(y+2,m[_],!0),y+=4),g[_]=1/0,m[_]=-1/0;b=0}}if(b>0)for(var E=0;E<l;E++)e.bits===8?(d.setInt8(y++,g[E]),d.setInt8(y++,m[E])):(d.setInt16(y,g[E],!0),d.setInt16(y+2,m[E],!0));return p}function Rt(e){"@babel/helpers - typeof";return Rt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Rt(e)}function ks(e){return e&&Rt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Ss(e){var t=e&&Rt(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),a=n.getInt32(0,!0);if(a!==1&&a!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function _s(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 f=0;f<t.length;f++)c.setInt8(u++,t[f],!0);else for(var h=0;h<t.length;h++)c.setInt16(u,t[h],!0),u+=2;return l}function dt(e){return e==null}function Is(e,t){var n=atob(e);return n}function As(e,t,n){var a=Is(e),r=a.indexOf(`
|
|
798
|
+
`,10)+1,s=a.substring(r)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function Es(e,t,n){var a;return function(s){return a=a||As(e),new Worker(a,s)}}var Ms=Es("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function Le(e){if(ks(e)&&(e=_s(e)),Ss(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 st(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var gt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function Ts(e){var t={scale:e.scale||gt.scale,bits:e.bits||gt.bits,amplitude_scale:e.amplitude_scale||gt.amplitude_scale,split_channels:e.split_channels||gt.split_channels,disable_worker:e.disable_worker||gt.disable_worker};return t}function $s(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Za(e,t,n){var a=$s(e);if(t.disable_worker){var r=xs({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 Le(r),e)}else{var s=new Ms;s.onmessage=function(o){n(void 0,new Le(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 Rs(e,t,n,a){function r(o){o||(o=new DOMException("EncodingError")),a(o),a=function(){}}var s=e.decodeAudioData(t,function(o){Za(o,n,a)},r);s&&s.catch(r)}Le.create=function(t){return new Le(t)};Le.createFromAudio=function(e,t){var n=Ts(e);if(e.audio_context&&e.array_buffer)return Rs(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Za(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Ft(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),a=24,r=this._inputData.bits===8?1:2,s=a+n*2*this._inputData.channels*r;this._output_data=new ArrayBuffer(s),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new Le(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}Ft.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Ft.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,a;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var r=0;r<n;++r)a=this._outputWaveformData.channel(r),a.set_min_sample(this._output_index-1,this._min[r]),a.set_max_sample(this._output_index-1,this._max[r]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var s=0;s<n;++s)this._min[s]=this._max_value,this._max[s]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var 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};Ft.prototype.getOutputData=function(){return this._output_data};Le.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!dt(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!dt(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new Ft(t);!n.next(););return new Le(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 Le.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(m){return m._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),f=new DataView(s[0]),h=new DataView(u),p=0;p<n;p++)h.setUint8(p,f.getUint8(p));h.setInt32(16,r,!0);for(var d=0,b=new Uint8Array(u,n),y=0;y<s.length;y++){var g=s[y];b.set(new Uint8Array(g,n),d),d+=g.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!dt(t.startIndex)&&!dt(t.endIndex)?(n=t.startIndex,a=t.endIndex):!dt(t.startTime)&&!dt(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 f=0;f<r*this.channels*2;f++){var h=this._at(n*this.channels*2+f);this.bits===8?u.setInt8(s+f,h):u.setInt16(s+f*2,h,!0)}return new Le(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 cn(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 Le.create(a)}else{const a=await t.json();return Le.create(a)}}function La(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 Ds(e,t=0){const n=await cn(e);return La(n,t)}async function Bs(e){const t=await cn(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Fs(e,t,n=0,a,r){let s=e;if(r!==void 0){const p=e.scale,d=Math.floor(a/p),b=Math.ceil((a+r)/p);s=s.slice({startIndex:d,endIndex:b})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),f=c.length,h=l===8?new Int8Array(f*2):new Int16Array(f*2);for(let p=0;p<f;p++)h[p*2]=c[p],h[p*2+1]=u[p];return{data:h,bits:l,length:f}}function ra(e,t,n,a,r){let s=e;if(a!==void 0&&r!==void 0){const f=e.scale,h=Math.floor(a/f),p=Math.ceil((a+r)/f);s=s.slice({startIndex:h,endIndex:p})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channels,l=s.bits,c=[];for(let f=0;f<o;f++){const h=s.channel(f),p=h.min_array(),d=h.max_array(),b=p.length,y=l===8?new Int8Array(b*2):new Int16Array(b*2);for(let g=0;g<b;g++)y[g*2]=p[g],y[g*2+1]=d[g];c.push(y)}if(n&&c.length>1){const f=1/c.length,h=c[0].length/2,p=l===8?new Int8Array(h*2):new Int16Array(h*2);for(let d=0;d<h;d++){let b=0,y=0;for(let g=0;g<c.length;g++)b+=f*c[g][d*2],y+=f*c[g][d*2+1];p[d*2]=b,p[d*2+1]=y}return{length:h,data:[p],bits:l}}return{length:c.length>0?c[0].length/2:0,data:c,bits:l}}function ja(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>ft(r,e),parseTime:r=>Da(r,e)}}function za({engineRef:e,initialSamplesPerPixel:t}){const[n,a]=i.useState(t),[r,s]=i.useState(!0),[o,l]=i.useState(!0),c=i.useRef(!0),u=i.useRef(!0),f=i.useRef(t),h=i.useCallback(()=>{e.current?.zoomIn()},[e]),p=i.useCallback(()=>{e.current?.zoomOut()},[e]),d=i.useCallback(b=>{b.samplesPerPixel!==f.current&&(f.current=b.samplesPerPixel,i.startTransition(()=>{a(b.samplesPerPixel)})),b.canZoomIn!==c.current&&(c.current=b.canZoomIn,s(b.canZoomIn)),b.canZoomOut!==u.current&&(u.current=b.canZoomOut,l(b.canZoomOut))},[]);return{samplesPerPixel:n,zoomIn:h,zoomOut:p,canZoomIn:r,canZoomOut:o,onEngineState:d}}function Ha({engineRef:e,initialVolume:t=1}){const[n,a]=i.useState(t),r=i.useRef(t),s=i.useCallback(l=>{e.current?e.current.setMasterVolume(l):(r.current=l,a(l))},[e]),o=i.useCallback(l=>{l.masterVolume!==r.current&&(r.current=l.masterVolume,a(l.masterVolume))},[]);return{masterVolume:n,setMasterVolume:s,masterVolumeRef:r,onEngineState:o}}function Ps({engineRef:e}){const[t,n]=i.useState(0),[a,r]=i.useState(0),s=i.useRef(0),o=i.useRef(0),l=i.useCallback((u,f)=>{e.current?.setSelection(u,f)},[e]),c=i.useCallback(u=>{u.selectionStart!==s.current&&(s.current=u.selectionStart,n(u.selectionStart)),u.selectionEnd!==o.current&&(o.current=u.selectionEnd,r(u.selectionEnd))},[]);return{selectionStart:t,selectionEnd:a,setSelection:l,selectionStartRef:s,selectionEndRef:o,onEngineState:c}}function Ws({engineRef:e}){const[t,n]=i.useState(!1),[a,r]=i.useState(0),[s,o]=i.useState(0),l=i.useRef(!1),c=i.useRef(0),u=i.useRef(0),f=i.useCallback(b=>{e.current?.setLoopEnabled(b)},[e]),h=i.useCallback((b,y)=>{e.current?.setLoopRegion(b,y)},[e]),p=i.useCallback(()=>{e.current?.setLoopRegion(0,0)},[e]),d=i.useCallback(b=>{b.isLoopEnabled!==l.current&&(l.current=b.isLoopEnabled,n(b.isLoopEnabled)),b.loopStart!==c.current&&(c.current=b.loopStart,r(b.loopStart)),b.loopEnd!==u.current&&(u.current=b.loopEnd,o(b.loopEnd))},[]);return{isLoopEnabled:t,loopStart:a,loopEnd:s,setLoopEnabled:f,setLoopRegion:h,clearLoopRegion:p,isLoopEnabledRef:l,loopStartRef:c,loopEndRef:u,onEngineState:d}}function Vs({engineRef:e}){const[t,n]=i.useState(null),a=i.useRef(null),r=i.useCallback(o=>{e.current?.selectTrack(o)},[e]),s=i.useCallback(o=>{o.selectedTrackId!==a.current&&(a.current=o.selectedTrackId,n(o.selectedTrackId))},[]);return{selectedTrackId:t,setSelectedTrackId:r,onEngineState:s,selectedTrackIdRef:a}}const Zs=(e=256)=>{const t=i.useRef(null),n=i.useCallback((a,r,s)=>{const o=new z.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 Ls(e,t={}){const{progressive:n=!1}=t,[a,r]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,f]=i.useState(0),h=e.length;return i.useEffect(()=>{if(e.length===0){r([]),o(!1),f(0);return}let p=!1;const d=new AbortController,b=new Map,y=(m,C,x)=>{const w=x??m.audioBuffer;if(!w&&!m.waveformData)throw new Error(`Track ${C+1}: Must provide src, audioBuffer, or waveformData`);const k=w?.duration??m.waveformData?.duration,S=da({audioBuffer:w,startTime:m.startTime??0,duration:m.duration??k,offset:m.offset??0,name:m.name||`Track ${C+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${C+1}`);return{...fa({name:m.name||`Track ${C+1}`,clips:[S],muted:m.muted??!1,soloed:m.soloed??!1,volume:m.volume??1,pan:m.pan??0,color:m.color}),effects:m.effects,renderMode:m.renderMode,spectrogramConfig:m.spectrogramConfig,spectrogramColorMap:m.spectrogramColorMap}};return(async()=>{try{o(!0),c(null),f(0);const m=ua.getContext().rawContext,C=e.map(async(w,k)=>{if(w.audioBuffer){const E=y(w,k,w.audioBuffer);return n&&!p&&(b.set(k,E),f(R=>R+1),r(Array.from({length:e.length},(R,W)=>b.get(W)).filter(R=>R!==void 0))),E}if(!w.src&&w.waveformData){const E=y(w,k);return n&&!p&&(b.set(k,E),f(R=>R+1),r(Array.from({length:e.length},(R,W)=>b.get(W)).filter(R=>R!==void 0))),E}if(!w.src)throw new Error(`Track ${k+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(w.src,{signal:d.signal});if(!S.ok)throw new Error(`Failed to fetch ${w.src}: ${S.statusText}`);const A=await S.arrayBuffer(),$=await m.decodeAudioData(A);if(!$||!$.sampleRate||!$.duration)throw new Error(`Invalid audio buffer for ${w.src}`);const _=y(w,k,$);return n&&!p&&(b.set(k,_),f(E=>E+1),r(Array.from({length:e.length},(E,R)=>b.get(R)).filter(E=>E!==void 0))),_}),x=await Promise.all(C);p||(n||(r(x),f(x.length)),o(!1))}catch(m){if(!p){const C=m instanceof Error?m.message:"Unknown error loading audio";c(C),o(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{p=!0,d.abort()}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:h}}function js({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a,engineRef:r,isDraggingRef:s}){const o=i.useRef(null),l=i.useCallback(p=>{const{transform:d,active:b}=p;if(!b?.data?.current)return{...d,scaleX:1,scaleY:1};const{trackIndex:y,clipIndex:g,boundary:m}=b.data.current;if(m)return{...d,scaleX:1,scaleY:1};const C=e[y];if(!C)return{...d,scaleX:1,scaleY:1};const x=C.clips[g];if(!x)return{...d,scaleX:1,scaleY:1};const w=d.x*n,k=Kt(C.clips),S=k.findIndex(_=>_.id===x.id),$=pa(x,w,k,S)/n;return{...d,x:$,scaleX:1,scaleY:1}},[e,n]),c=i.useCallback(p=>{const{active:d}=p,{boundary:b}=d.data.current;if(!b){o.current=null;return}const{trackIndex:y,clipIndex:g}=d.data.current,C=e[y]?.clips[g];C&&(o.current={offsetSamples:C.offsetSamples,durationSamples:C.durationSamples,startSample:C.startSample},s.current=!0)},[e,s]),u=i.useCallback(p=>{const{active:d,delta:b}=p,{boundary:y}=d.data.current;if(!y||!o.current)return;const{trackIndex:g,clipIndex:m}=d.data.current,C=b.x*n,x=Math.floor(.1*a),w=o.current,k=e.map((S,A)=>{if(A!==g)return S;const $=[...S.clips].sort((R,W)=>R.startSample-W.startSample),_=$.findIndex(R=>R===S.clips[m]),E=S.clips.map((R,W)=>{if(W!==m)return R;if(y==="left"){const T={...R,startSample:w.startSample,offsetSamples:w.offsetSamples,durationSamples:w.durationSamples},F=Jt(T,Math.floor(C),"left",$,_,x),P=w.offsetSamples+F,O=w.durationSamples-F,U=w.startSample+F;return{...R,offsetSamples:P,durationSamples:O,startSample:U}}else{const T={...R,startSample:w.startSample,offsetSamples:w.offsetSamples,durationSamples:w.durationSamples},F=Jt(T,Math.floor(C),"right",$,_,x),P=w.durationSamples+F;return{...R,durationSamples:P}}});return{...S,clips:E}});t(k)},[e,t,n,a]),f=i.useCallback(p=>{const{active:d,delta:b}=p,{trackIndex:y,clipId:g,boundary:m}=d.data.current,C=b.x*n,x=e[y]?.id;if(m){s.current=!1,x?r.current?r.current.trimClip(x,g,m,Math.floor(C)):console.warn("[waveform-playlist] engineRef is null — trim not synced to adapter"):console.warn(`[waveform-playlist] onDragEnd: track at index ${y} not found — trim not synced to adapter`),o.current=null;return}x?r.current?r.current.moveClip(x,g,Math.floor(C)):console.warn("[waveform-playlist] engineRef is null — move not synced to adapter"):console.warn(`[waveform-playlist] onDragEnd: track at index ${y} not found — move not synced to adapter`)},[e,n,r,s]),h=i.useCallback(p=>{s.current=!1,o.current=null},[s]);return{onDragStart:c,onDragMove:u,onDragEnd:f,onDragCancel:h,collisionModifier:l}}const Nt=.01;function Xa({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(f=>{const{active:h}=f,p=h.data.current;if(!p||p.annotationIndex===void 0){o.current=null;return}const d=e[p.annotationIndex];d&&(o.current={start:d.start,end:d.end,annotationIndex:p.annotationIndex})},[e]),c=i.useCallback(f=>{const{active:h,delta:p}=f;if(!o.current)return;const d=h.data.current;if(!d)return;const{edge:b,annotationIndex:y}=d,g=o.current,m=p.x*n/a,C=b==="start"?g.start+m:g.end+m,x=zs({annotationIndex:y,newTime:C,isDraggingStart:b==="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 zs({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 f=o[e-1];Math.abs(f.end-l.start)<Nt?o[e-1]={...f,end:Math.max(f.start+.1,f.end+u)}:c<=f.end&&(o[e]={...o[e],start:f.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 f=o[e+1];if(Math.abs(f.start-l.end)<Nt){const h=f.start+u;o[e+1]={...f,start:Math.min(f.end-.1,h)};let p=e+1;for(;p<o.length-1;){const d=o[p],b=o[p+1];if(Math.abs(b.start-d.end)<Nt){const y=d.end-a[p].end;o[p+1]={...b,start:Math.min(b.end-.1,b.start+y)},p++}else break}}else c>=f.start&&(o[e]={...o[e],end:f.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const f=o[e+1];o[e+1]={...f,start:c};let h=e+1;for(;h<o.length-1;){const p=o[h],d=o[h+1];if(p.end>d.start)o[h+1]={...d,start:p.end},h++;else break}}}return o}function Hs(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Oe.useSensor(Oe.MouseSensor,{activationConstraint:{distance:r}}),o=Oe.useSensor(Oe.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Oe.useSensor(Oe.PointerSensor,{activationConstraint:{distance:r}});return Oe.useSensors(...t?[s,o]:[l])}const Xs=e=>{const{tracks:t,sampleRate:n,engineRef:a}=e,{currentTimeRef:r}=Re(),{selectedTrackId:s}=De(),o=i.useCallback((c,u,f)=>{const{samplesPerPixel:h}=e,p=t[c];if(!p)return!1;const d=p.clips[u];if(!d)return!1;const b=Math.round(f*n),y=$r(b,h),g=Math.floor(.1*n);if(!ga(d,y,g))return console.warn("Split point is invalid (outside bounds or too close to edge)"),!1;const m=a.current;return m?(m.splitClip(p.id,d.id,y),!0):(console.warn("[waveform-playlist] engineRef is null — split not synced to adapter"),!1)},[t,e,n,a]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.warn("[waveform-playlist] No track selected — click a clip to select a track first"),!1;const c=t.findIndex(h=>h.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],f=r.current??0;for(let h=0;h<u.clips.length;h++){const p=u.clips[h],d=p.startSample/n,b=(p.startSample+p.durationSamples)/n;if(f>d&&f<b)return o(c,h,f)}return console.warn(`[waveform-playlist] No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,o,n]),splitClipAt:o}},Dt=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,f=l.shiftKey===void 0||r.shiftKey===l.shiftKey,h=l.metaKey===void 0||r.metaKey===l.metaKey,p=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&f&&h&&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])},Os=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("+")},Ns=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Re(),{setCurrentTime:s,play:o,pause:l,stop:c}=be(),u=i.useCallback(()=>{r?l():o()},[r,o,l]),f=i.useCallback(()=>{c()},[c]),h=i.useCallback(()=>{s(0),r&&o(0)},[r,s,o]),d=a??[...[{key:" ",action:u,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:f,description:"Stop",preventDefault:!0},{key:"0",action:h,description:"Rewind to start",preventDefault:!0}],...n];return Dt({shortcuts:d,enabled:t}),{rewindToStart:h,togglePlayPause:u,stopPlayback:f,shortcuts:d}},Gt=.01,Mt=.01;function Gs({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:f,controlsWidth:h=0,onPlay:p}){const d=i.useMemo(()=>t?e.findIndex(_=>_.id===t):-1,[e,t]),b=i.useCallback(_=>{if(!c?.current||!u||!f)return;const E=e.find(V=>V.id===_);if(!E)return;const R=c.current,W=R.clientWidth,T=E.start*f/u+h,F=E.end*f/u+h,P=(T+F)/2,O=R.scrollLeft,U=O,J=O+W;if(T<U||F>J){const V=Math.max(0,P-W/2);R.scrollTo({left:V,behavior:"smooth"})}},[e,c,u,f,h]);i.useEffect(()=>{t&&c?.current&&u&&f&&b(t)},[t,b,c,u,f]);const y=i.useCallback(_=>{if(d<0)return;const E=e[d],R=Math.max(0,Math.min(E.end-.1,E.start+_)),W=R-E.start,T=[...e];if(T[d]={...E,start:R},s&&d>0){const F=T[d-1];Math.abs(F.end-E.start)<Gt&&(T[d-1]={...F,end:Math.max(F.start+.1,F.end+W)})}else if(!s&&d>0){const F=T[d-1];R<F.end&&(T[d-1]={...F,end:R})}n(T)},[e,d,s,n]),g=i.useCallback(_=>{if(d<0)return;const E=e[d],R=Math.max(E.start+.1,Math.min(r,E.end+_)),W=R-E.end,T=[...e];if(T[d]={...E,end:R},s&&d<e.length-1){const F=T[d+1];if(Math.abs(F.start-E.end)<Gt){const P=Math.min(F.end-.1,F.start+W);T[d+1]={...F,start:P};let O=d+1;for(;O<T.length-1;){const U=T[O],J=T[O+1];if(Math.abs(J.start-e[O].end)<Gt){const V=U.end-e[O].end;T[O+1]={...J,start:Math.min(J.end-.1,J.start+V)},O++}else break}}}else if(!s&&d<e.length-1){const F=T[d+1];if(R>F.start){T[d+1]={...F,start:R};let P=d+1;for(;P<T.length-1;){const O=T[P],U=T[P+1];if(O.end>U.start)T[P+1]={...U,start:O.end},P++;else break}}}n(T)},[e,d,r,s,n]),m=i.useCallback(()=>{!a||e.length===0||(d<=0?a(e[e.length-1].id):a(e[d-1].id))},[e,d,a]),C=i.useCallback(()=>{!a||e.length===0||(d<0||d>=e.length-1?a(e[0].id):a(e[d+1].id))},[e,d,a]),x=i.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),w=i.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),k=i.useCallback(()=>{a&&a(null)},[a]),S=i.useCallback(()=>{if(d<0||!p)return;const _=e[d],E=o?void 0:_.end-_.start;p(_.start,E)},[e,d,o,p]),A=i.useMemo(()=>[{key:"[",action:()=>y(-Mt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>y(Mt),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>g(-Mt),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>g(Mt),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:S,description:"Play selected annotation",preventDefault:!0}],[y,g,S]),$=i.useMemo(()=>[{key:"ArrowUp",action:m,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:m,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:C,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:C,description:"Select next annotation",preventDefault:!0},{key:"Home",action:x,description:"Select first annotation",preventDefault:!0},{key:"End",action:w,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:k,description:"Deselect annotation",preventDefault:!0}],[m,C,x,w,k]);return Dt({shortcuts:A,enabled:l&&d>=0}),Dt({shortcuts:$,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:y,moveEndBoundary:g,selectPrevious:m,selectNext:C,selectFirst:x,selectLast:w,clearSelection:k,scrollToAnnotation:b,playActiveAnnotation:S}}const Ct=[{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}]}],un=e=>Ct.find(t=>t.id===e),Ys=e=>Ct.filter(t=>t.category===e),Us=[{id:"reverb",name:"Reverb"},{id:"delay",name:"Delay"},{id:"modulation",name:"Modulation"},{id:"filter",name:"Filter"},{id:"distortion",name:"Distortion"},{id:"dynamics",name:"Dynamics"},{id:"spatial",name:"Spatial"}];const Ks={reverb:z.Reverb,freeverb:z.Freeverb,jcReverb:z.JCReverb,feedbackDelay:z.FeedbackDelay,pingPongDelay:z.PingPongDelay,chorus:z.Chorus,phaser:z.Phaser,tremolo:z.Tremolo,vibrato:z.Vibrato,autoPanner:z.AutoPanner,autoFilter:z.AutoFilter,autoWah:z.AutoWah,eq3:z.EQ3,distortion:z.Distortion,bitCrusher:z.BitCrusher,chebyshev:z.Chebyshev,compressor:z.Compressor,limiter:z.Limiter,gate:z.Gate,stereoWidener:z.StereoWidener};let qs=0;const Js=()=>`effect_${Date.now()}_${++qs}`;function bt(e,t){const n=Ks[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(l=>{const c=t?.[l.name]??l.default;a[l.name]=c});const r=new n(a),s=Js(),o=r;return{effect:r,id:e.id,instanceId:s,dispose(){try{r.disconnect(),r.dispose()}catch(l){console.warn(`[waveform-playlist] Error disposing effect "${e.id}" (${s}):`,l)}},setParameter(l,c){const u=o[l];if(l==="wet"){const f=o.wet;if(f&&typeof f=="object"&&"value"in f){f.value=c;return}}u!==void 0&&(u&&typeof u=="object"&&"value"in u?u.value=c:o[l]=c)},getParameter(l){if(l==="wet"){const u=o.wet;if(u&&typeof u=="object"&&"value"in u)return u.value}const c=o[l];if(c!==void 0)return c&&typeof c=="object"&&"value"in c?c.value:c},connect(l){r.connect(l)},disconnect(){try{r.disconnect()}catch(l){console.warn(`[waveform-playlist] Error disconnecting effect "${e.id}" (${s}):`,l)}}}}function Qs(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 ei(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(g=>{const m=o.current;if(!m)return;const{masterGainNode:C,destination:x,analyserNode:w}=m;try{C.disconnect()}catch(S){console.warn("[waveform-playlist] Error disconnecting master effects chain:",S)}const k=g.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)C.connect(w),w.connect(x);else{let S=C;k.forEach(A=>{try{A.disconnect()}catch($){console.warn(`[waveform-playlist] Error disconnecting effect "${A.id}":`,$)}S.connect(A.effect),S=A.effect}),S.connect(w),w.connect(x)}},[]),c=i.useCallback(g=>{const m=un(g);if(!m){console.error(`Unknown effect: ${g}`);return}const C={};m.parameters.forEach(k=>{C[k.name]=k.default});const x=bt(m,C);r.current.set(x.instanceId,x);const w={instanceId:x.instanceId,effectId:m.id,definition:m,params:C,bypassed:!1};n(k=>[...k,w])},[]),u=i.useCallback(g=>{const m=r.current.get(g);m&&(m.dispose(),r.current.delete(g)),n(C=>C.filter(x=>x.instanceId!==g))},[]),f=i.useCallback((g,m,C)=>{const x=r.current.get(g);x&&x.setParameter(m,C),n(w=>w.map(k=>k.instanceId===g?{...k,params:{...k.params,[m]:C}}:k))},[]),h=i.useCallback(g=>{const m=a.current.find(w=>w.instanceId===g);if(!m)return;const C=!m.bypassed,x=r.current.get(g);if(x){const w=m.params.wet??1;x.setParameter("wet",C?0:w)}n(w=>w.map(k=>k.instanceId===g?{...k,bypassed:C}:k))},[]),p=i.useCallback((g,m)=>{n(C=>{const x=[...C],[w]=x.splice(g,1);return x.splice(m,0,w),x})},[]),d=i.useCallback(()=>{r.current.forEach(g=>g.dispose()),r.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const b=i.useCallback((g,m,C)=>{const x=new z.Analyser("fft",e);s.current=x,o.current={masterGainNode:g,destination:m,analyserNode:x};const k=a.current.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)g.connect(x),x.connect(m);else{let S=g;k.forEach(A=>{S.connect(A.effect),S=A.effect}),S.connect(x),x.connect(m)}return function(){x.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>{const g=r.current;return()=>{g.forEach(m=>m.dispose()),g.clear()}},[]);const y=i.useCallback(()=>{const g=t.filter(m=>!m.bypassed);if(g.length!==0)return(m,C,x)=>{const w=[];for(const k of g){const S=bt(k.definition,k.params);w.push(S)}if(w.length===0)m.connect(C);else{let k=m;w.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(C)}return function(){w.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:Ct,addEffect:c,removeEffect:u,updateParameter:f,toggleBypass:h,reorderEffects:p,clearAllEffects:d,masterEffects:b,createOfflineEffectsFunction:y,analyserRef:s}}function ti(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),a=i.useRef(new Map),r=i.useCallback((d,b)=>{const y=a.current.get(d);if(!y)return;const{graphEnd:g,masterGainNode:m}=y,C=n.current.get(d);try{g.disconnect()}catch(w){console.warn(`[waveform-playlist] Error disconnecting track "${d}" effect chain:`,w)}const x=b.map(w=>C?.get(w.instanceId)).filter(w=>w!==void 0);if(x.length===0)g.connect(m);else{let w=g;x.forEach(k=>{try{k.disconnect()}catch(S){console.warn(`[waveform-playlist] Error disconnecting effect "${k.id}" on track "${d}":`,S)}w.connect(k.effect),w=k.effect}),w.connect(m)}},[]),s=i.useCallback((d,b)=>{const y=un(b);if(!y){console.error(`Unknown effect: ${b}`);return}const g={};y.parameters.forEach(x=>{g[x.name]=x.default});const m=bt(y,g);n.current.has(d)||n.current.set(d,new Map),n.current.get(d).set(m.instanceId,m);const C={instanceId:m.instanceId,effectId:y.id,definition:y,params:g,bypassed:!1};t(x=>{const w=new Map(x),k=w.get(d)||[];return w.set(d,[...k,C]),w})},[]),o=i.useCallback((d,b)=>{const y=n.current.get(d),g=y?.get(b);g&&(g.dispose(),y?.delete(b)),t(m=>{const C=new Map(m),x=C.get(d)||[];return C.set(d,x.filter(w=>w.instanceId!==b)),C})},[]),l=i.useCallback((d,b,y,g)=>{const C=n.current.get(d)?.get(b);C&&C.setParameter(y,g),t(x=>{const w=new Map(x),k=w.get(d)||[];return w.set(d,k.map(S=>S.instanceId===b?{...S,params:{...S.params,[y]:g}}:S)),w})},[]),c=i.useCallback((d,b)=>{const g=(f.current.get(d)||[]).find(w=>w.instanceId===b);if(!g)return;const m=!g.bypassed,x=n.current.get(d)?.get(b);if(x){const w=g.params.wet??1;x.setParameter("wet",m?0:w)}t(w=>{const k=new Map(w),S=k.get(d)||[];return k.set(d,S.map(A=>A.instanceId===b?{...A,bypassed:m}:A)),k})},[]),u=i.useCallback(d=>{const b=n.current.get(d);b&&(b.forEach(y=>y.dispose()),b.clear()),t(y=>{const g=new Map(y);return g.set(d,[]),g})},[]),f=i.useRef(e);f.current=e;const h=i.useCallback(d=>(b,y,g)=>{a.current.set(d,{graphEnd:b,masterGainNode:y});const m=f.current.get(d)||[],C=n.current.get(d),x=m.map(w=>C?.get(w.instanceId)).filter(w=>w!==void 0);if(x.length===0)b.connect(y);else{let w=b;x.forEach(k=>{w.connect(k.effect),w=k.effect}),w.connect(y)}return function(){a.current.delete(d)}},[]);i.useEffect(()=>{e.forEach((d,b)=>{r(b,d)})},[e,r]),i.useEffect(()=>{const d=n.current;return()=>{d.forEach(b=>{b.forEach(y=>y.dispose()),b.clear()}),d.clear()}},[]);const p=i.useCallback(d=>{const y=(e.get(d)||[]).filter(g=>!g.bypassed);if(y.length!==0)return(g,m,C)=>{const x=[];for(const w of y){const k=bt(w.definition,w.params);x.push(k)}if(x.length===0)g.connect(m);else{let w=g;x.forEach(k=>{w.connect(k.effect),w=k.effect}),w.connect(m)}return function(){x.forEach(k=>k.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:h,createOfflineTrackEffectsFunction:p,availableEffects:Ct}}function ni(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,f=44,h=f+u,p=new ArrayBuffer(h),d=new DataView(p);Tt(d,0,"RIFF"),d.setUint32(4,h-8,!0),Tt(d,8,"WAVE"),Tt(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,n===32?3:1,!0),d.setUint16(22,a,!0),d.setUint32(24,r,!0),d.setUint32(28,c,!0),d.setUint16(32,l,!0),d.setUint16(34,n,!0),Tt(d,36,"data"),d.setUint32(40,u,!0);const b=[];for(let g=0;g<a;g++)b.push(e.getChannelData(g));let y=f;if(n===16)for(let g=0;g<s;g++)for(let m=0;m<a;m++){const C=b[m][g],x=Math.max(-1,Math.min(1,C)),w=x<0?x*32768:x*32767;d.setInt16(y,w,!0),y+=2}else for(let g=0;g<s;g++)for(let m=0;m<a;m++)d.setFloat32(y,b[m][g],!0),y+=4;return new Blob([p],{type:"audio/wav"})}function Tt(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function ai(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 Oa(){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:f="export",mode:h="master",trackIndex:p,autoDownload:d=!0,applyEffects:b=!0,effectsFunction:y,createOfflineTrackEffects:g,bitDepth:m=16,onProgress:C}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(h==="individual"&&(p===void 0||p<0||p>=l.length))throw new Error("Invalid track index for individual export");const x=l[0].clips[0]?.sampleRate||44100;let w=0;for(const R of l)for(const W of R.clips){const T=W.startSample+W.durationSamples;w=Math.max(w,T)}w+=Math.round(x*.1);const k=w/x,S=h==="individual"?[{track:l[p],state:c[p],index:p}]:l.map((R,W)=>({track:R,state:c[W],index:W})),A=c.some(R=>R.soloed),$=!!g;let _;if((y||$)&&b)_=await ri(S,c,A,k,x,y,g,R=>{a(R),C?.(R)});else{const R=new OfflineAudioContext(2,w,x);let W=0;const T=S.reduce((F,{track:P})=>F+P.clips.length,0);for(const{track:F,state:P}of S)if(!(P.muted&&!P.soloed)&&!(A&&!P.soloed))for(const O of F.clips){await si(R,O,P,x,b),W++;const U=W/T*.5;a(U),C?.(U)}a(.5),C?.(.5),_=await R.startRendering()}a(.9),C?.(.9);const E=ni(_,{bitDepth:m});if(a(1),C?.(1),d){const R=h==="individual"?`${f}_${l[p].name}`:f;ai(E,`${R}.wav`)}return{audioBuffer:_,blob:E,duration:k}}catch(x){const w=x instanceof Error?x.message:"Export failed";throw s(w),x}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function ri(e,t,n,a,r,s,o,l){const{Offline:c,Volume:u,Gain:f,Panner:h,Player:p,ToneAudioBuffer:d}=await import("tone");l(.1);let b;try{b=await c(async({transport:y,destination:g})=>{const m=new u(0);let C;s?C=s(m,g,!0):m.connect(g);for(const{track:x,state:w}of e){if(w.muted&&!w.soloed||n&&!w.soloed)continue;const k=new u(oi(w.volume)),S=new h(w.pan),A=new f(w.muted?0:1),$=o?.(x.id);$?$(A,m,!0):A.connect(m),S.connect(A),k.connect(S);for(const _ of x.clips){const{audioBuffer:E,startSample:R,durationSamples:W,offsetSamples:T,gain:F,fadeIn:P,fadeOut:O}=_,U=R/r,J=W/r,V=T/r,ee=new d(E),ae=new p(ee),Q=new f(F);if(ae.connect(Q),Q.connect(k),P){const ue=U,ie=U+P.duration,pe=qt(Q.gain);pe&&(pe.setValueAtTime(0,ue),pe.linearRampToValueAtTime(F,ie))}if(O){const ue=U+J-O.duration,ie=U+J,pe=qt(Q.gain);pe&&(pe.setValueAtTime(F,ue),pe.linearRampToValueAtTime(0,ie))}ae.start(U,V,J)}}y.start(0)},a,2,r)}catch(y){throw y instanceof Error?y:new Error(`Tone.Offline rendering failed: ${String(y)}`)}return l(.9),b.get()}function oi(e){return 20*Math.log10(Math.max(e,1e-4))}async function si(e,t,n,a,r){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:f,fadeOut:h}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const p=o/a,d=l/a,b=c/a,y=e.createBufferSource();y.buffer=s;const g=e.createGain(),m=u*n.volume,C=e.createStereoPanner();if(C.pan.value=n.pan,y.connect(g),g.connect(C),C.connect(e.destination),r){if(f?g.gain.setValueAtTime(0,p):g.gain.setValueAtTime(m,p),f){const x=p,w=p+f.duration;oa(g.gain,x,w,0,m,f.type||"linear")}if(h){const x=p+d-h.duration,w=p+d;(!f||f.duration<d-h.duration)&&g.gain.setValueAtTime(m,x),oa(g.gain,x,w,m,0,h.type||"linear")}}else g.gain.setValueAtTime(m,p);y.start(p,b,d)}function oa(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 l=sa(a,r,256,"logarithmic");e.setValueCurveAtTime(l,t,o);break}case"sCurve":{const l=sa(a,r,256,"sCurve");e.setValueCurveAtTime(l,t,o);break}default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function sa(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 Na=()=>{const e=i.useRef(null),t=i.useCallback(()=>{e.current!==null&&(cancelAnimationFrame(e.current),e.current=null)},[]),n=i.useCallback(a=>{t(),e.current=requestAnimationFrame(a)},[t]);return i.useEffect(()=>()=>{t()},[t]),{animationFrameRef:e,startAnimationFrameLoop:n,stopAnimationFrameLoop:t}},ii=`
|
|
799
799
|
"use strict";
|
|
800
800
|
|
|
801
801
|
var INT8_MAX = 127;
|
|
@@ -942,13 +942,13 @@ self.onmessage = function(e) {
|
|
|
942
942
|
self.postMessage({ id: msg.id, error: err.message || String(err) });
|
|
943
943
|
}
|
|
944
944
|
};
|
|
945
|
-
`;let $s=0;function Ts(){let e;try{const a=new Blob([Es],{type:"application/javascript"}),r=URL.createObjectURL(a);e=new Worker(r),URL.revokeObjectURL(r)}catch(a){return console.warn("[waveform-playlist] Failed to create peaks worker (CSP restriction?):",a),{generate(){return Promise.reject(new Error("Worker creation failed"))},terminate(){}}}const t=new Map;let n=!1;return e.onmessage=a=>{const r=a.data,s=t.get(r.id);if(s)if(t.delete(r.id),r.error)s.reject(new Error(r.error));else try{const i=Ze.create(r.buffer);s.resolve(i)}catch(i){s.reject(i)}},e.onerror=a=>{n=!0,e.terminate();for(const[,r]of t)r.reject(a.error??new Error(a.message));t.clear()},{generate(a){if(n)return Promise.reject(new Error("Worker terminated"));const r=String(++$s);return new Promise((s,i)=>{t.set(r,{resolve:s,reject:i}),e.postMessage({id:r,scale:a.scale,bits:a.bits,amplitude_scale:1,split_channels:a.splitChannels,length:a.length,sample_rate:a.sampleRate,channels:a.channels},a.channels)})},terminate(){n=!0,e.terminate();for(const[,a]of t)a.reject(new Error("Worker terminated"));t.clear()}}}function Rs(e,t){const[n,a]=o.useState(()=>new Map),[r,s]=o.useState(!1),i=o.useRef(null),l=o.useRef(new Set),c=o.useRef(0),u=o.useCallback(()=>(i.current||(i.current=Ts()),i.current),[]);return o.useEffect(()=>{let m=!1;const h=l.current,p=[];for(const w of e)for(const g of w.clips)g.audioBuffer&&!g.waveformData&&!h.has(g.id)&&p.push({clipId:g.id,audioBuffer:g.audioBuffer});if(p.length===0)return;const f=new Set;for(const{clipId:w}of p)h.add(w),f.add(w);c.current+=p.length,s(!0);const b=u();for(const{clipId:w,audioBuffer:g}of p){const d=[];for(let x=0;x<g.numberOfChannels;x++)d.push(g.getChannelData(x).slice().buffer);b.generate({id:w,channels:d,length:g.length,sampleRate:g.sampleRate,scale:t,bits:16,splitChannels:!0}).then(x=>{m||(a(y=>{const C=new Map(y);return C.set(w,x),C}),c.current--,c.current<=0&&(c.current=0,s(!1)))}).catch(x=>{m||(console.warn("[waveform-playlist] Worker peak generation failed:",x),h.delete(w),c.current--,c.current<=0&&(c.current=0,s(!1)))})}return()=>{m=!0;for(const w of f)h.delete(w)}},[e,t,u]),o.useEffect(()=>()=>{i.current?.terminate(),i.current=null},[]),{cache:n,isGenerating:r}}function Ut(e){return e instanceof File?e.name.replace(/\.[^/.]+$/,""):e instanceof Blob?"Untitled":typeof e=="string"?e.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled":e.name??e.src.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled"}async function Ds(e,t,n){const a=Ut(e);if(e instanceof Blob){const c=await e.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(c),name:a}}const r=typeof e=="string"?e:e.src,s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Failed to fetch ${r}: ${s.statusText}`);const i=await s.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(i),name:a}}function Bs(){const[e,t]=o.useState([]),[n,a]=o.useState(0),[r,s]=o.useState([]),i=o.useRef(!1),l=o.useRef(new Set),c=o.useRef(new Map);o.useEffect(()=>{const h=c.current;return()=>{i.current=!0;for(const p of h.values())p.abort();h.clear()}},[]);const u=o.useCallback(h=>{if(h.length===0)return;const p=sr(),f=h.map(b=>({track:Nn({name:`${Ut(b)} (loading...)`,clips:[]}),source:b}));t(b=>[...b,...f.map(w=>w.track)]),a(b=>b+h.length);for(const{track:b,source:w}of f){l.current.add(b.id);const g=new AbortController;c.current.set(b.id,g),(async()=>{try{const{audioBuffer:d,name:x}=await Ds(w,p,g.signal),y=Gn({audioBuffer:d,startTime:0,duration:d.duration,offset:0,name:x});!i.current&&l.current.has(b.id)&&t(C=>C.map(k=>k.id===b.id?{...k,name:x,clips:[y]}:k))}catch(d){if(d instanceof DOMException&&d.name==="AbortError")return;console.warn("[waveform-playlist] Error loading audio:",d),!i.current&&l.current.has(b.id)&&(t(x=>x.filter(y=>y.id!==b.id)),s(x=>[...x,{name:Ut(w),error:d instanceof Error?d:new Error(String(d))}]))}finally{c.current.delete(b.id),!i.current&&l.current.delete(b.id)&&a(d=>d-1)}})()}},[]),m=o.useCallback(h=>{t(f=>f.filter(b=>b.id!==h));const p=c.current.get(h);p&&(p.abort(),c.current.delete(h)),l.current.delete(h)&&a(f=>f-1)},[]);return{tracks:e,addTracks:u,removeTrack:m,loadingCount:n,isLoading:n>0,errors:r}}const Aa=o.createContext(null),Ma=o.createContext(null),_a=o.createContext(null),Ea=o.createContext(null),Fs=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:i=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:m,onReady:h,onAnnotationUpdate:p,onAnnotationsChange:f,barWidth:b=1,barGap:w=0,progressBarWidth:g,children:d})=>{const x=g??b+w,y=o.useMemo(()=>{if(!u?.annotations)return[];if(process.env.NODE_ENV!=="production"&&u.annotations.length>0){const D=u.annotations[0];if(typeof D.start!="number"||typeof D.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof D.start),[]}return u.annotations},[u?.annotations]),C=o.useRef(y);C.current=y;const[k,S]=o.useState(null),[M,A]=o.useState(!1),[E,_]=o.useState(0),[I,B]=o.useState(0),[$,W]=o.useState([]),[z,Y]=o.useState([]),[j,N]=o.useState([]),[L,ae]=o.useState(0),[oe,q]=o.useState(0),[fe,ue]=o.useState(null),[le,Ee]=o.useState(i),[P,ee]=o.useState(u?.isContinuousPlay??!1),[U,K]=o.useState(u?.linkEndpoints??!1),[ie,he]=o.useState(u?.editable??!1),[te,Se]=o.useState(!1),[Be,Xe]=o.useState(0),[qe,ne]=o.useState(0),[Ve,Oe]=o.useState(!1),F=o.useRef(null),ye=o.useRef(0),ce=o.useRef(0),je=o.useRef(e),nt=o.useRef(j),Le=o.useRef(0),O=o.useRef(0),se=o.useRef(null),ve=o.useRef(null),$e=o.useRef(!1),Te=o.useRef(u?.isContinuousPlay??!1),Ge=o.useRef(null),at=o.useRef(r),ut=o.useRef(!1),ht=o.useRef(0),V=o.useRef(0),X=o.useRef(0),Q=o.useRef(0),{timeFormat:me,setTimeFormat:pe,formatTime:_e}=wa(),Ce=ya({initialSamplesPerPixel:r,zoomLevels:s}),J=Ce.samplesPerPixel,{masterVolume:Ie,setMasterVolume:Fe}=xa({playoutRef:F,initialVolume:1}),{animationFrameRef:rt,startAnimationFrameLoop:Ne,stopAnimationFrameLoop:Ye}=Ia(),dt=o.useMemo(()=>Math.min(...s??[256,512,1024,2048,4096,8192]),[s]),{cache:ot}=Rs(e,dt),Je=o.useCallback(D=>{Te.current=D,ee(D)},[]),ze=o.useCallback(D=>{Ge.current=D,S(D)},[]),xt=o.useCallback(D=>{ut.current=D,Se(D)},[]),Qe=o.useCallback((D,G)=>{X.current=D,Q.current=G,Xe(D),ne(G)},[]),sn=o.useCallback(()=>{const D=ht.current,G=V.current;D!==G&&G>D&&Qe(D,G)},[Qe]),ln=o.useCallback(()=>{Qe(0,0)},[Qe]);o.useEffect(()=>{$e.current=le},[le]),o.useEffect(()=>{nt.current=j},[j]),je.current=e,o.useEffect(()=>{ht.current=L,V.current=oe},[L,oe]),o.useEffect(()=>{if(!ve.current||!$.length)return;const D=ve.current,G=at.current,re=J;if(G===re)return;const H=c.show?c.width:0,de=D.clientWidth,Ae=D.scrollLeft+de/2-H,et=$[0].sampleRate,xe=Ae*G/et*et/re,We=Math.max(0,xe+H-de/2);D.scrollLeft=We,at.current=re},[J,$,c]);const kt=o.useRef(null);o.useEffect(()=>{if(Oe(!1),e.length===0){W([]),B(0),N([]),Y([]),F.current&&(F.current.dispose(),F.current=null);return}const D=M,G=ce.current;return F.current&&D&&(F.current.stop(),Ye(),kt.current={position:G}),(async()=>{try{const H=[];e.forEach(we=>{we.clips.length>0&&we.clips[0].audioBuffer&&H.push(we.clips[0].audioBuffer)});let de=0;e.forEach(we=>{we.clips.forEach(xe=>{const We=xe.sampleRate,It=(xe.startSample+xe.durationSamples)/We;de=Math.max(de,It)})}),W(H),B(de),N(we=>we.length===e.length?we.map((xe,We)=>({...xe,name:e[We].name})):e.map(xe=>({name:xe.name,muted:xe.muted,soloed:xe.soloed,volume:xe.volume,pan:xe.pan}))),F.current&&F.current.dispose();const ge=new rr({effects:m}),Ae=nt.current;e.forEach((we,xe)=>{const We=we.clips.filter(it=>it.audioBuffer);if(We.length>0){const it=We[0].sampleRate,It=Math.min(...We.map(Pe=>Pe.startSample/it)),Ha=Math.max(...We.map(Pe=>(Pe.startSample+Pe.durationSamples)/it)),At=Ae[xe],Xa={id:we.id,name:we.name,gain:At?.volume??we.volume,muted:At?.muted??we.muted,soloed:At?.soloed??we.soloed,stereoPan:At?.pan??we.pan,startTime:It,endTime:Ha},Oa=We.map(Pe=>{const zt=Pe.sampleRate;return{buffer:Pe.audioBuffer,startTime:Pe.startSample/zt-It,duration:Pe.durationSamples/zt,offset:Pe.offsetSamples/zt,fadeIn:Pe.fadeIn,fadeOut:Pe.fadeOut,gain:Pe.gain}});ge.addTrack({clips:Oa,track:Xa,effects:we.effects})}}),ge.applyInitialSoloState(),F.current=ge,Oe(!0);const et=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:de}});window.dispatchEvent(et),h?.()}catch(H){console.error("Error loading audio:",H)}})(),()=>{Ye(),F.current&&F.current.dispose()}},[e,h,M,m,Ye]),o.useEffect(()=>{if(e.length===0)return;const D=e.map(G=>G.clips.map(H=>{let de;if(H.waveformData)try{de=Vn(H.waveformData,J,n,H.offsetSamples,H.durationSamples)}catch(ge){console.warn("[waveform-playlist] Failed to extract peaks from waveformData:",ge)}if(!de){const ge=ot.get(H.id);if(ge)try{de=Vn(ge,J,n,H.offsetSamples,H.durationSamples)}catch(Ae){console.warn("[waveform-playlist] Failed to extract peaks from cache:",Ae)}}if(!de){!H.audioBuffer&&!H.waveformData&&console.warn(`[waveform-playlist] Clip "${H.id}" has no audio data or waveform data`);const ge=n?1:H.audioBuffer?.numberOfChannels??1;de={length:0,data:Array.from({length:ge},()=>new Int16Array(0)),bits:16}}return{clipId:H.id,trackName:G.name,peaks:de,startSample:H.startSample,durationSamples:H.durationSamples,fadeIn:H.fadeIn,fadeOut:H.fadeOut}}));Y(D)},[e,J,n,ot]);const st=o.useCallback(()=>{const D=()=>{const G=Z.getContext().currentTime-Le.current,re=O.current+G;ce.current=re;const H=C.current;if(H.length>0){const ge=H.find(Ae=>re>=Ae.start&&re<Ae.end);if(Te.current)ge&&ge.id!==Ge.current?ze(ge.id):!ge&&Ge.current!==null&&ze(null);else if(Ge.current){const Ae=H.find(et=>et.id===Ge.current);if(Ae&&re>=Ae.end){F.current&&F.current.stop(),A(!1),ce.current=ye.current,_(ye.current);return}}else ge&&ze(ge.id)}if($e.current&&ve.current&&$.length>0){const ge=ve.current,Ae=$[0].sampleRate,et=re*Ae/at.current,we=ge.clientWidth,xe=c.show?c.width:0,We=et+xe,it=Math.max(0,We-we/2);ge.scrollLeft=it}if(se.current!==null&&re>=se.current){F.current&&F.current.stop(),A(!1),ce.current=se.current,_(se.current),se.current=null;return}const de=X.current!==Q.current&&Q.current>X.current;if(ut.current&&de&&re>=Q.current){F.current?.stop();const Ae=Z.getContext().currentTime;Le.current=Ae,O.current=X.current,ce.current=X.current,F.current?.play(Ae,X.current),Ne(D);return}if(re>=I){F.current&&F.current.stop(),A(!1),ce.current=ye.current,_(ye.current),ze(null);return}Ne(D)};Ne(D)},[I,$,c.show,c.width,ze,Ne]),Ue=Ye;o.useEffect(()=>{(async()=>{if(M&&rt.current&&F.current)if(P){const G=ce.current;F.current.stop(),Ue(),await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const H=Z.getContext().currentTime;Le.current=H,O.current=G,F.current.play(H,G),st()}else Ue(),st()})()},[P,M,st,Ue,rt]),o.useEffect(()=>{(async()=>{if(kt.current&&F.current){const{position:G}=kt.current;kt.current=null,await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const H=Z.getContext().currentTime;Le.current=H,O.current=G,F.current.play(H,G),A(!0),st()}})()},[e,st]);const St=o.useCallback(async(D,G)=>{if(!F.current||$.length===0)return;await F.current.init();const re=D??ce.current;ye.current=re,ce.current=re,F.current.setOnPlaybackComplete(()=>{}),F.current.stop(),Ue();const de=Z.getContext().currentTime;Le.current=de,O.current=re,se.current=G!==void 0?re+G:null,F.current.play(de,re,G),A(!0),st()},[$.length,st,Ue]),cn=o.useCallback(()=>{if(!F.current)return;const D=Z.getContext().currentTime-Le.current,G=O.current+D;F.current.pause(),A(!1),Ue(),ce.current=G,_(G)},[Ue]),un=o.useCallback(()=>{F.current&&(F.current.stop(),A(!1),Ue(),ce.current=ye.current,_(ye.current),ze(null))},[Ue,ze]),dn=o.useCallback(D=>{const G=Math.max(0,Math.min(D,I));ce.current=G,_(G),M&&F.current&&(F.current.stop(),Ue(),St(G))},[I,M,St,Ue]),fn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];H[D]={...H[D],muted:G},N(H),F.current&&F.current.setMute(re,G)},[j]),mn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];H[D]={...H[D],soloed:G},N(H),F.current&&F.current.setSolo(re,G)},[j]),hn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];if(H[D]={...H[D],volume:G},N(H),F.current){const de=F.current.getTrack(re);de&&de.setVolume(G)}},[j]),pn=o.useCallback((D,G)=>{const re=je.current[D]?.id;if(!re)return;const H=[...j];if(H[D]={...H[D],pan:G},N(H),F.current){const de=F.current.getTrack(re);de&&de.setPan(G)}},[j]),gn=o.useCallback((D,G)=>{ae(D),q(G),ce.current=D,_(D),M&&F.current&&(F.current.stop(),F.current.play(Z.getContext().currentTime,D))},[M]),bn=o.useCallback(D=>{ve.current=D},[]),jt=o.useRef(f);jt.current=f;const vn=o.useCallback(D=>{const G=typeof D=="function"?D(C.current):D;if(!jt.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}jt.current(G)},[]),Cn=$[0]?.sampleRate||44100,Lt=t?30:0,wn=e.length*a+Lt,Za=o.useMemo(()=>({isPlaying:M,currentTime:E,currentTimeRef:ce,playbackStartTimeRef:Le,audioStartPositionRef:O}),[M,E,ce,Le,O]),Va=o.useMemo(()=>({continuousPlay:P,linkEndpoints:U,annotationsEditable:ie,isAutomaticScroll:le,isLoopEnabled:te,annotations:y,activeAnnotationId:k,selectionStart:L,selectionEnd:oe,selectedTrackId:fe,loopStart:Be,loopEnd:qe}),[P,U,ie,le,te,y,k,L,oe,fe,Be,qe]),yn=o.useCallback(D=>{ce.current=D,_(D)},[ce]),xn=o.useCallback(D=>{Ee(D)},[]),ja=o.useMemo(()=>({play:St,pause:cn,stop:un,seekTo:dn,setCurrentTime:yn,setTrackMute:fn,setTrackSolo:mn,setTrackVolume:hn,setTrackPan:pn,setSelection:gn,setSelectedTrackId:ue,setTimeFormat:pe,formatTime:_e,zoomIn:Ce.zoomIn,zoomOut:Ce.zoomOut,setMasterVolume:Fe,setAutomaticScroll:xn,setScrollContainer:bn,scrollContainerRef:ve,setContinuousPlay:Je,setLinkEndpoints:K,setAnnotationsEditable:he,setAnnotations:vn,setActiveAnnotationId:ze,setLoopEnabled:xt,setLoopRegion:Qe,setLoopRegionFromSelection:sn,clearLoopRegion:ln}),[St,cn,un,dn,yn,fn,mn,hn,pn,gn,ue,pe,_e,Ce.zoomIn,Ce.zoomOut,Fe,xn,bn,ve,Je,K,he,vn,ze,xt,Qe,sn,ln]),La=o.useMemo(()=>({duration:I,audioBuffers:$,peaksDataArray:z,trackStates:j,tracks:e,sampleRate:Cn,waveHeight:a,timeScaleHeight:Lt,minimumPlaylistHeight:wn,controls:c,playoutRef:F,samplesPerPixel:J,timeFormat:me,masterVolume:Ie,canZoomIn:Ce.canZoomIn,canZoomOut:Ce.canZoomOut,barWidth:b,barGap:w,progressBarWidth:x,isReady:Ve,mono:n}),[I,$,z,j,e,Cn,a,Lt,wn,c,F,J,me,Ie,Ce.canZoomIn,Ce.canZoomOut,b,w,x,Ve,n]),za={...ra,...l};return v.jsx(R.ThemeProvider,{theme:za,children:v.jsx(Aa.Provider,{value:Za,children:v.jsx(Ma.Provider,{value:Va,children:v.jsx(_a.Provider,{value:ja,children:v.jsx(Ea.Provider,{value:La,children:d})})})})})},Re=()=>{const e=o.useContext(Aa);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},De=()=>{const e=o.useContext(Ma);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},be=()=>{const e=o.useContext(_a);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},Me=()=>{const e=o.useContext(Ea);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e};var Ws=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate;const t=this.audioElement;"preservesPitch"in this.audioElement?t.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?t.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(t.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},Ps=class{constructor(e={}){this.track=null,this._isPlaying=!1,this._masterVolume=e.masterVolume??1,this._playbackRate=e.playbackRate??1}async init(){}addTrack(e){return this.track&&(console.warn("MediaElementPlayout: Only one track is supported. Disposing previous track. For multi-track, use TonePlayout."),this.track.dispose()),this.track=new Ws({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const a=t??0;if(this._isPlaying=!0,this.track.play(a),n!==void 0){const r=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},r*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const $a=o.createContext(null),Ta=o.createContext(null),Ra=o.createContext(null),Da=o.createContext(null),Zs=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:s=!1,theme:i,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:m=0,progressBarWidth:h,onAnnotationsChange:p,onReady:f,children:b})=>{const w=h??u+m,[g,d]=o.useState(!1),[x,y]=o.useState(0),[C,k]=o.useState(0),[S,M]=o.useState([]),[A,E]=o.useState(r),_=o.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const O=c.annotations[0];if(typeof O.start!="number"||typeof O.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof O.start),[]}return c.annotations},[c?.annotations]),I=o.useRef(_);I.current=_;const[B,$]=o.useState(null),[W,z]=o.useState(c?.isContinuousPlay??!1),[Y]=o.useState(t),[j,N]=o.useState(s),L=o.useRef(null),ae=o.useRef(0),oe=o.useRef(W),q=o.useRef(null),fe=o.useRef(null),ue=o.useRef(s),le=o.useRef(t),{startAnimationFrameLoop:Ee,stopAnimationFrameLoop:P}=Ia();o.useEffect(()=>{oe.current=W},[W]),o.useEffect(()=>{ue.current=j},[j]);const ee=o.useCallback(O=>{q.current=O,$(O)},[]),U=o.useCallback(O=>{oe.current=O,z(O)},[]),K=o.useCallback(O=>{fe.current=O},[]),ie=e.waveformData.sample_rate;o.useEffect(()=>{const O=new Ps({playbackRate:r});O.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const se=O.getTrack(O.track?.id??"");return se&&se.setOnTimeUpdateCallback(ve=>{ae.current=ve}),O.setOnPlaybackComplete(()=>{P(),d(!1),ee(null),ae.current=0,y(0)}),L.current=O,k(e.waveformData.duration),f?.(),()=>{P(),O.dispose()}},[e.source,e.waveformData,e.name,r,f,P,ee]),o.useEffect(()=>{const O=os(e.waveformData,Y,0,0,Math.ceil(e.waveformData.duration*ie)),se={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:O.length,data:[O.data],bits:O.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*ie)};M([[se]])},[e.waveformData,e.name,Y,ie]);const he=o.useCallback(()=>{const O=()=>{const se=L.current?.getCurrentTime()??0;ae.current=se;const ve=I.current;if(ve.length>0){const $e=ve.find(Te=>se>=Te.start&&se<Te.end);if(oe.current)$e&&$e.id!==q.current?ee($e.id):!$e&&q.current!==null&&ee(null);else if(q.current){const Te=ve.find(Ge=>Ge.id===q.current);if(Te&&se>=Te.end){L.current?.stop(),d(!1);return}}else $e&&ee($e.id)}if(ue.current&&fe.current){const $e=fe.current,Te=se*ie/le.current,Ge=$e.clientWidth,at=l.show?l.width:0,ut=Te+at,ht=Math.max(0,ut-Ge/2);$e.scrollLeft=ht}Ee(O)};Ee(O)},[ee,ie,l,Ee]),te=P,Se=o.useCallback(O=>{if(!L.current)return;const se=O??ae.current;L.current.play(void 0,se),d(!0),he()},[he]),Be=o.useCallback(()=>{L.current&&(L.current.pause(),d(!1),te(),y(L.current.getCurrentTime()))},[te]),Xe=o.useCallback(()=>{L.current&&(L.current.stop(),d(!1),te(),ae.current=0,y(0),ee(null))},[te,ee]),qe=o.useCallback(O=>{const se=Math.max(0,Math.min(O,C));ae.current=se,y(se),L.current&&L.current.seekTo(se)},[C]),ne=o.useCallback(O=>{const se=Math.max(.5,Math.min(2,O));E(se),L.current&&L.current.setPlaybackRate(se)},[]),Ve=a?30:0,Oe=o.useMemo(()=>({isPlaying:g,currentTime:x,currentTimeRef:ae}),[g,x]),F=o.useMemo(()=>({continuousPlay:W,annotations:_,activeAnnotationId:B,playbackRate:A,isAutomaticScroll:j}),[W,_,B,A,j]),ye=o.useRef(p);ye.current=p;const ce=o.useCallback(O=>{const se=typeof O=="function"?O(I.current):O;if(!ye.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to MediaElementPlaylistProvider to handle annotation updates.");return}ye.current(se)},[]),je=o.useMemo(()=>({play:Se,pause:Be,stop:Xe,seekTo:qe,setPlaybackRate:ne,setContinuousPlay:U,setAnnotations:ce,setActiveAnnotationId:ee,setAutomaticScroll:O=>{N(O)},setScrollContainer:K,scrollContainerRef:fe}),[Se,Be,Xe,qe,ne,U,ce,ee,K]),nt=o.useMemo(()=>({duration:C,peaksDataArray:S,sampleRate:ie,waveHeight:n,timeScaleHeight:Ve,samplesPerPixel:Y,playoutRef:L,controls:l,barWidth:u,barGap:m,progressBarWidth:w}),[C,S,ie,n,Ve,Y,l,u,m,w]),Le={...ra,...i};return v.jsx(R.ThemeProvider,{theme:Le,children:v.jsx($a.Provider,{value:Oe,children:v.jsx(Ta.Provider,{value:F,children:v.jsx(Ra.Provider,{value:je,children:v.jsx(Da.Provider,{value:nt,children:b})})})})})},Wt=()=>{const e=o.useContext($a);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Pt=()=>{const e=o.useContext(Ta);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},rn=()=>{const e=o.useContext(Ra);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Zt=()=>{const e=o.useContext(Da);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},Vs=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Re(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=De(),{play:i}=be(),l=async()=>{if(a!==r&&r>a)if(s)await i(a);else{const u=r-a;await i(a,u)}else await i(n.current??0)};return v.jsx(He,{onClick:l,disabled:t,className:e,children:"Play"})},js=({className:e})=>{const{isPlaying:t}=Re(),{pause:n}=be();return v.jsx(He,{onClick:n,disabled:!t,className:e,children:"Pause"})},Ls=({className:e})=>{const{isPlaying:t}=Re(),{stop:n}=be();return v.jsx(He,{onClick:n,disabled:!t,className:e,children:"Stop"})},zs=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=be(),{playoutRef:r}=Me(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return v.jsx(He,{onClick:s,className:e,children:"Rewind"})},Hs=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=be(),{duration:r,playoutRef:s}=Me(),i=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return v.jsx(He,{onClick:i,className:e,children:"Fast Forward"})},Xs=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=be(),{playoutRef:i}=Me(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&i.current&&(i.current.stop(),r(c))};return v.jsx(He,{onClick:l,className:t,children:"Skip Backward"})},Os=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=be(),{duration:i,playoutRef:l}=Me(),c=()=>{const u=Math.min(i,(n.current??0)+e);s(u),a&&l.current&&(l.current.stop(),r(u))};return v.jsx(He,{onClick:c,className:t,children:"Skip Forward"})},Gs=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=De(),{setLoopEnabled:r,setLoopRegion:s}=be(),{duration:i}=Me(),l=n!==a&&a>n,c=()=>{if(!t&&!l){const u=Math.min(10,i*.25);s(0,Math.max(1,u))}r(!t)};return v.jsx(He,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Ns=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=De(),{setLoopRegionFromSelection:s,clearLoopRegion:i}=be(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?i():s()};return v.jsx(He,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},Ys=({className:e,disabled:t})=>{const{zoomIn:n}=be(),{canZoomIn:a}=Me();return v.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Us=({className:e,disabled:t})=>{const{zoomOut:n}=be(),{canZoomOut:a}=Me();return v.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Ks=({className:e})=>{const{masterVolume:t}=Me(),{setMasterVolume:n}=be();return v.jsx(Lr,{volume:t,onChange:n,className:e})},qs=({className:e})=>{const{timeFormat:t}=Me(),{setTimeFormat:n}=be();return v.jsx(So,{value:t,onChange:n,className:e})},Js=R.span`
|
|
945
|
+
`;let li=0;function ci(){let e;try{const a=new Blob([ii],{type:"application/javascript"}),r=URL.createObjectURL(a);e=new Worker(r),URL.revokeObjectURL(r)}catch(a){return console.warn("[waveform-playlist] Failed to create peaks worker (CSP restriction?):",a),{generate(){return Promise.reject(new Error("Worker creation failed"))},terminate(){}}}const t=new Map;let n=!1;return e.onmessage=a=>{const r=a.data,s=t.get(r.id);if(s)if(t.delete(r.id),r.error)s.reject(new Error(r.error));else try{const o=Le.create(r.buffer);s.resolve(o)}catch(o){s.reject(o)}},e.onerror=a=>{n=!0,e.terminate();for(const[,r]of t)r.reject(a.error??new Error(a.message));t.clear()},{generate(a){if(n)return Promise.reject(new Error("Worker terminated"));const r=String(++li);return new Promise((s,o)=>{t.set(r,{resolve:s,reject:o}),e.postMessage({id:r,scale:a.scale,bits:a.bits,amplitude_scale:1,split_channels:a.splitChannels,length:a.length,sample_rate:a.sampleRate,channels:a.channels},a.channels)})},terminate(){n=!0,e.terminate();for(const[,a]of t)a.reject(new Error("Worker terminated"));t.clear()}}}function ui(e,t){const[n,a]=i.useState(()=>new Map),[r,s]=i.useState(!1),o=i.useRef(null),l=i.useRef(new Set),c=i.useRef(0),u=i.useCallback(()=>(o.current||(o.current=ci()),o.current),[]);return i.useEffect(()=>{let f=!1;const h=l.current,p=[];for(const y of e)for(const g of y.clips)g.audioBuffer&&!g.waveformData&&!h.has(g.id)&&p.push({clipId:g.id,audioBuffer:g.audioBuffer});if(p.length===0)return;const d=new Set;for(const{clipId:y}of p)h.add(y),d.add(y);c.current+=p.length,s(!0);const b=u();for(const{clipId:y,audioBuffer:g}of p){const m=[];for(let C=0;C<g.numberOfChannels;C++)m.push(g.getChannelData(C).slice().buffer);b.generate({id:y,channels:m,length:g.length,sampleRate:g.sampleRate,scale:t,bits:16,splitChannels:!0}).then(C=>{f||(a(x=>{const w=new Map(x);return w.set(y,C),w}),c.current--,c.current<=0&&(c.current=0,s(!1)))}).catch(C=>{f||(console.warn("[waveform-playlist] Worker peak generation failed:",C),h.delete(y),c.current--,c.current<=0&&(c.current=0,s(!1)))})}return()=>{f=!0;for(const y of d)h.delete(y)}},[e,t,u]),i.useEffect(()=>()=>{o.current?.terminate(),o.current=null},[]),{cache:n,isGenerating:r}}function tn(e){return e instanceof File?e.name.replace(/\.[^/.]+$/,""):e instanceof Blob?"Untitled":typeof e=="string"?e.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled":e.name??e.src.split("/").pop()?.replace(/\.[^/.]+$/,"")??"Untitled"}async function di(e,t,n){const a=tn(e);if(e instanceof Blob){const c=await e.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(c),name:a}}const r=typeof e=="string"?e:e.src,s=await fetch(r,{signal:n});if(!s.ok)throw new Error(`Failed to fetch ${r}: ${s.statusText}`);const o=await s.arrayBuffer();return n?.throwIfAborted(),{audioBuffer:await t.decodeAudioData(o),name:a}}function fi(){const[e,t]=i.useState([]),[n,a]=i.useState(0),[r,s]=i.useState([]),o=i.useRef(!1),l=i.useRef(new Set),c=i.useRef(new Map);i.useEffect(()=>{const h=c.current;return()=>{o.current=!0;for(const p of h.values())p.abort();h.clear()}},[]);const u=i.useCallback(h=>{if(h.length===0)return;const p=Mr(),d=h.map(b=>({track:fa({name:`${tn(b)} (loading...)`,clips:[]}),source:b}));t(b=>[...b,...d.map(y=>y.track)]),a(b=>b+h.length);for(const{track:b,source:y}of d){l.current.add(b.id);const g=new AbortController;c.current.set(b.id,g),(async()=>{try{const{audioBuffer:m,name:C}=await di(y,p,g.signal),x=da({audioBuffer:m,startTime:0,duration:m.duration,offset:0,name:C});!o.current&&l.current.has(b.id)&&t(w=>w.map(k=>k.id===b.id?{...k,name:C,clips:[x]}:k))}catch(m){if(m instanceof DOMException&&m.name==="AbortError")return;console.warn("[waveform-playlist] Error loading audio:",m),!o.current&&l.current.has(b.id)&&(t(C=>C.filter(x=>x.id!==b.id)),s(C=>[...C,{name:tn(y),error:m instanceof Error?m:new Error(String(m))}]))}finally{c.current.delete(b.id),!o.current&&l.current.delete(b.id)&&a(m=>m-1)}})()}},[]),f=i.useCallback(h=>{t(d=>d.filter(b=>b.id!==h));const p=c.current.get(h);p&&(p.abort(),c.current.delete(h)),l.current.delete(h)&&a(d=>d-1)},[]);return{tracks:e,addTracks:u,removeTrack:f,loadingCount:n,isLoading:n>0,errors:r}}const Ga=i.createContext(null),Ya=i.createContext(null),Ua=i.createContext(null),Ka=i.createContext(null),mi=({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:f,onReady:h,onAnnotationUpdate:p,onAnnotationsChange:d,barWidth:b=1,barGap:y=0,progressBarWidth:g,onTracksChange:m,children:C})=>{const x=g??b+y,w=i.useMemo(()=>s,[s?.join(",")]),k=i.useMemo(()=>{if(!u?.annotations)return[];if(process.env.NODE_ENV!=="production"&&u.annotations.length>0){const B=u.annotations[0];if(typeof B.start!="number"||typeof B.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof B.start),[]}return u.annotations},[u?.annotations]),S=i.useRef(k);S.current=k;const[A,$]=i.useState(null),[_,E]=i.useState(!1),[R,W]=i.useState(0),[T,F]=i.useState(0),[P,O]=i.useState([]),[U,J]=i.useState([]),[V,ee]=i.useState([]),[ae,Q]=i.useState(o),[ue,ie]=i.useState(u?.isContinuousPlay??!1),[pe,ye]=i.useState(u?.linkEndpoints??!1),[N,H]=i.useState(u?.editable??!1),[se,G]=i.useState(!1),I=i.useRef(null),le=i.useRef(!1),xe=i.useRef(!1);xe.current=_;const K=i.useRef(0),ce=i.useRef(0),Ie=i.useRef(e),Ge=i.useRef(V),q=i.useRef(0),_e=i.useRef(0),Ae=i.useRef(null),fe=i.useRef(null),Be=i.useRef(!1),Fe=i.useRef(u?.isContinuousPlay??!1),ze=i.useRef(null),Ye=i.useRef(null),Je=i.useRef(0),Y=i.useRef(!1),re=i.useRef(!1),ke=i.useRef(r),{timeFormat:Te,setTimeFormat:$e,formatTime:Qe}=ja(),Pe=za({engineRef:I,initialSamplesPerPixel:r}),{samplesPerPixel:Xe,onEngineState:mt}=Pe,L=Ha({engineRef:I,initialVolume:1}),{masterVolume:X,setMasterVolume:te,masterVolumeRef:me,onEngineState:ge}=L,{selectionStart:Ee,selectionEnd:We,setSelection:ne,selectionStartRef:Ce,selectionEndRef:Me,onEngineState:nt}=Ps({engineRef:I}),{isLoopEnabled:Ue,loopStart:Ke,loopEnd:at,setLoopEnabled:rt,setLoopRegion:Ne,clearLoopRegion:ht,isLoopEnabledRef:xt,loopStartRef:kt,loopEndRef:mn,onEngineState:hn}=Ws({engineRef:I}),{selectedTrackId:pn,setSelectedTrackId:gn,onEngineState:bn,selectedTrackIdRef:vn}=Vs({engineRef:I}),{animationFrameRef:wn,startAnimationFrameLoop:Lt,stopAnimationFrameLoop:St}=Na(),or=i.useMemo(()=>Math.min(...w??[256,512,1024,2048,4096,8192]),[w]),{cache:yn}=ui(e,or),Cn=i.useCallback(B=>{Fe.current=B,ie(B)},[]),qe=i.useCallback(B=>{ze.current=B,$(B)},[]),xn=i.useCallback(()=>{const B=Ce.current??0,j=Me.current??0;B!==j&&j>B&&Ne(B,j)},[Ne,Ce,Me]);i.useEffect(()=>{Be.current=ae},[ae]),i.useEffect(()=>{Ge.current=V},[V]),Ie.current=e;const jt=e===Ye.current;Y.current=jt||re.current,i.useEffect(()=>{if(!fe.current||!P.length)return;const B=fe.current,j=ke.current,oe=Xe;if(j===oe)return;const Z=c.show?c.width:0,de=B.clientWidth,we=B.scrollLeft+de/2-Z,ct=P[0].sampleRate,ut=we*j/ct*ct/oe,Xt=Math.max(0,ut+Z-de/2);B.scrollLeft=Xt,ke.current=oe},[Xe,P,c]);const _t=i.useRef(null);i.useEffect(()=>{if(jt||re.current){jt&&(Ye.current=null);let Z=0;e.forEach(de=>{de.clips.forEach(ve=>{const we=(ve.startSample+ve.durationSamples)/ve.sampleRate;Z=Math.max(Z,we)})}),F(Z);return}if(G(!1),e.length===0){O([]),F(0),ee([]),J([]),I.current&&(I.current.dispose(),I.current=null);return}const B=xe.current,j=ce.current;return I.current&&B&&(I.current.stop(),St(),_t.current={position:j}),(async()=>{try{const Z=[];e.forEach(he=>{he.clips.length>0&&he.clips[0].audioBuffer&&Z.push(he.clips[0].audioBuffer)});let de=0;e.forEach(he=>{he.clips.forEach(Ze=>{const et=Ze.sampleRate,dr=(Ze.startSample+Ze.durationSamples)/et;de=Math.max(de,dr)})}),O(Z),F(de),ee(he=>he.length===e.length?he.map((Ze,et)=>({...Ze,name:e[et].name})):e.map(Ze=>({name:Ze.name,muted:Ze.muted,soloed:Ze.soloed,volume:Ze.volume,pan:Ze.pan}))),I.current&&I.current.dispose(),Je.current=0,Ye.current=null,le.current=!1;const ve=Tr({effects:f}),we=new Pr({adapter:ve,samplesPerPixel:ke.current,zoomLevels:w});we.setSelection(Ce.current??0,Me.current??0),we.setLoopRegion(kt.current??0,mn.current??0),xt.current&&we.setLoopEnabled(!0),we.setMasterVolume(me.current??1),vn.current&&we.selectTrack(vn.current);const ct=Ge.current,At=e.map((he,Ze)=>{const et=ct[Ze];return{...he,volume:et?.volume??he.volume,muted:et?.muted??he.muted,soloed:et?.soloed??he.soloed,pan:et?.pan??he.pan}});let ut=!0;we.on("statechange",he=>{nt(he),hn(he),bn(he),mt(he),ge(he),!ut&&he.tracksVersion!==Je.current&&(Je.current=he.tracksVersion,Ye.current=he.tracks,m?m(he.tracks):console.warn("[waveform-playlist] Engine tracks changed but onTracksChange prop is not set — UI will revert on next render. Pass onTracksChange to WaveformPlaylistProvider."))}),we.setTracks(At),ut=!1,Je.current=we.getState().tracksVersion,I.current=we,G(!0);const Xt=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:de}});window.dispatchEvent(Xt),h?.()}catch(Z){console.error("Error loading audio:",Z)}})(),()=>{if(Y.current){Y.current=!1;return}St(),I.current&&I.current.dispose()}},[e,h,f,St,nt,hn,bn,mt,ge,m,me,Ce,Me,kt,mn,xt,w]),i.useEffect(()=>{if(e.length===0)return;const B=e.map(j=>j.clips.map(Z=>{let de;if(Z.waveformData)try{de=ra(Z.waveformData,Xe,n,Z.offsetSamples,Z.durationSamples)}catch(ve){console.warn("[waveform-playlist] Failed to extract peaks from waveformData:",ve)}if(!de){const ve=yn.get(Z.id);if(ve)try{de=ra(ve,Xe,n,Z.offsetSamples,Z.durationSamples)}catch(we){console.warn("[waveform-playlist] Failed to extract peaks from cache:",we)}}if(!de){!Z.audioBuffer&&!Z.waveformData&&console.warn(`[waveform-playlist] Clip "${Z.id}" has no audio data or waveform data`);const ve=n?1:Z.audioBuffer?.numberOfChannels??1;de={length:0,data:Array.from({length:ve},()=>new Int16Array(0)),bits:16}}return{clipId:Z.id,trackName:j.name,peaks:de,startSample:Z.startSample,durationSamples:Z.durationSamples,fadeIn:Z.fadeIn,fadeOut:Z.fadeOut}}));J(B)},[e,Xe,n,yn]);const kn=i.useRef(!1),lt=i.useCallback(()=>{if(I.current)return I.current.getCurrentTime();kn.current||(kn.current=!0,console.warn("[waveform-playlist] getPlaybackTime called without engine. Falling back to manual elapsed time (loop wrapping will not work)."));const B=z.getContext().currentTime-(q.current??0);return(_e.current??0)+B},[]),ot=i.useCallback(()=>{const B=()=>{const j=lt();ce.current=j;const oe=S.current;if(oe.length>0){const Z=oe.find(de=>j>=de.start&&j<de.end);if(Fe.current)Z&&Z.id!==ze.current?qe(Z.id):!Z&&ze.current!==null&&qe(null);else if(ze.current){const de=oe.find(ve=>ve.id===ze.current);if(de&&j>=de.end){I.current&&I.current.stop(),E(!1),ce.current=K.current,W(K.current);return}}else Z&&qe(Z.id)}if(Be.current&&fe.current&&P.length>0){const Z=fe.current,de=P[0].sampleRate,ve=j*de/ke.current,we=Z.clientWidth,ct=c.show?c.width:0,At=ve+ct,ut=Math.max(0,At-we/2);Z.scrollLeft=ut}if(Ae.current!==null&&j>=Ae.current){I.current&&I.current.stop(),E(!1),ce.current=Ae.current,W(Ae.current),Ae.current=null;return}if(j>=T){I.current&&I.current.stop(),E(!1),ce.current=K.current,W(K.current),qe(null);return}Lt(B)};Lt(B)},[T,P,c.show,c.width,qe,Lt,lt]),Ve=St;i.useEffect(()=>{(async()=>{if(_&&wn.current&&I.current)if(ue){const j=ce.current;I.current.stop(),Ve();const Z=z.getContext().currentTime;q.current=Z,_e.current=j,I.current.play(j),ot()}else Ve(),ot()})().catch(j=>{console.warn("[waveform-playlist] Failed to reschedule playback:",j),E(!1),Ve()})},[ue,_,ot,Ve,wn]),i.useEffect(()=>{(async()=>{if(_t.current&&I.current){const{position:j}=_t.current;_t.current=null;const Z=z.getContext().currentTime;q.current=Z,_e.current=j,le.current||(await I.current.init(),le.current=!0),I.current.play(j),E(!0),ot()}})().catch(j=>{console.warn("[waveform-playlist] Failed to resume playback after track change:",j),E(!1),Ve()})},[e,ot,Ve]);const It=i.useCallback(async(B,j)=>{if(!I.current||P.length===0)return;const oe=B??ce.current;K.current=oe,ce.current=oe,I.current.stop(),I.current.seek(oe),Ve();const de=z.getContext().currentTime;q.current=de,_e.current=oe,Ae.current=j!==void 0?oe+j:null,le.current||(await I.current.init(),le.current=!0);const ve=j!==void 0?oe+j:void 0;try{I.current.play(oe,ve)}catch(we){console.warn("[waveform-playlist] Playback failed to start:",we),Ve();return}E(!0),ot()},[P.length,ot,Ve]),Sn=i.useCallback(()=>{if(!I.current)return;const B=lt();I.current.pause(),E(!1),Ve(),ce.current=B,W(B)},[Ve,lt]),_n=i.useCallback(()=>{I.current&&(I.current.stop(),E(!1),Ve(),ce.current=K.current,W(K.current),qe(null))},[Ve,qe]),In=i.useCallback(B=>{const j=Math.max(0,Math.min(B,T));ce.current=j,W(j),_&&I.current&&It(j)},[T,_,It]),An=i.useCallback((B,j)=>{const oe=Ie.current[B]?.id;if(!oe)return;const Z=[...V];Z[B]={...Z[B],muted:j},ee(Z),I.current&&I.current.setTrackMute(oe,j)},[V]),En=i.useCallback((B,j)=>{const oe=Ie.current[B]?.id;if(!oe)return;const Z=[...V];Z[B]={...Z[B],soloed:j},ee(Z),I.current&&I.current.setTrackSolo(oe,j)},[V]),Mn=i.useCallback((B,j)=>{const oe=Ie.current[B]?.id;if(!oe)return;const Z=[...V];Z[B]={...Z[B],volume:j},ee(Z),I.current&&I.current.setTrackVolume(oe,j)},[V]),Tn=i.useCallback((B,j)=>{const oe=Ie.current[B]?.id;if(!oe)return;const Z=[...V];Z[B]={...Z[B],pan:j},ee(Z),I.current&&I.current.setTrackPan(oe,j)},[V]),$n=i.useCallback((B,j)=>{ne(B,j),ce.current=B,W(B),_&&I.current&&(I.current.stop(),I.current.seek(B),I.current.play(B))},[_,ne]),Rn=i.useCallback(B=>{fe.current=B},[]),zt=i.useRef(d);zt.current=d;const Dn=i.useCallback(B=>{const j=typeof B=="function"?B(S.current):B;if(!zt.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}zt.current(j)},[]),Bn=P[0]?.sampleRate||44100,Ht=t?30:0,Fn=e.length*a+Ht,sr=i.useMemo(()=>({isPlaying:_,currentTime:R,currentTimeRef:ce,playbackStartTimeRef:q,audioStartPositionRef:_e,getPlaybackTime:lt}),[_,R,ce,q,_e,lt]),ir=i.useMemo(()=>({continuousPlay:ue,linkEndpoints:pe,annotationsEditable:N,isAutomaticScroll:ae,isLoopEnabled:Ue,annotations:k,activeAnnotationId:A,selectionStart:Ee,selectionEnd:We,selectedTrackId:pn,loopStart:Ke,loopEnd:at}),[ue,pe,N,ae,Ue,k,A,Ee,We,pn,Ke,at]),Pn=i.useCallback(B=>{ce.current=B,W(B)},[ce]),Wn=i.useCallback(B=>{Q(B)},[]),lr=i.useMemo(()=>({play:It,pause:Sn,stop:_n,seekTo:In,setCurrentTime:Pn,setTrackMute:An,setTrackSolo:En,setTrackVolume:Mn,setTrackPan:Tn,setSelection:$n,setSelectedTrackId:gn,setTimeFormat:$e,formatTime:Qe,zoomIn:Pe.zoomIn,zoomOut:Pe.zoomOut,setMasterVolume:te,setAutomaticScroll:Wn,setScrollContainer:Rn,scrollContainerRef:fe,setContinuousPlay:Cn,setLinkEndpoints:ye,setAnnotationsEditable:H,setAnnotations:Dn,setActiveAnnotationId:qe,setLoopEnabled:rt,setLoopRegion:Ne,setLoopRegionFromSelection:xn,clearLoopRegion:ht}),[It,Sn,_n,In,Pn,An,En,Mn,Tn,$n,gn,$e,Qe,Pe.zoomIn,Pe.zoomOut,te,Wn,Rn,fe,Cn,ye,H,Dn,qe,rt,Ne,xn,ht]),cr=i.useMemo(()=>({duration:T,audioBuffers:P,peaksDataArray:U,trackStates:V,tracks:e,sampleRate:Bn,waveHeight:a,timeScaleHeight:Ht,minimumPlaylistHeight:Fn,controls:c,playoutRef:I,samplesPerPixel:Xe,timeFormat:Te,masterVolume:X,canZoomIn:Pe.canZoomIn,canZoomOut:Pe.canZoomOut,barWidth:b,barGap:y,progressBarWidth:x,isReady:se,mono:n,isDraggingRef:re}),[T,P,U,V,e,Bn,a,Ht,Fn,c,I,Xe,Te,X,Pe.canZoomIn,Pe.canZoomOut,b,y,x,se,n,re]),ur={..._a,...l};return v.jsx(D.ThemeProvider,{theme:ur,children:v.jsx(Ga.Provider,{value:sr,children:v.jsx(Ya.Provider,{value:ir,children:v.jsx(Ua.Provider,{value:lr,children:v.jsx(Ka.Provider,{value:cr,children:C})})})})})},Re=()=>{const e=i.useContext(Ga);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},De=()=>{const e=i.useContext(Ya);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},be=()=>{const e=i.useContext(Ua);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},je=()=>{const e=i.useContext(Ka);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e};var hi=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate;const t=this.audioElement;"preservesPitch"in this.audioElement?t.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?t.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(t.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},pi=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 hi({...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 qa=i.createContext(null),Ja=i.createContext(null),Qa=i.createContext(null),er=i.createContext(null),gi=({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:f=0,progressBarWidth:h,onAnnotationsChange:p,onReady:d,children:b})=>{const y=h??u+f,[g,m]=i.useState(!1),[C,x]=i.useState(0),[w,k]=i.useState(0),[S,A]=i.useState([]),[$,_]=i.useState(r),E=i.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const Y=c.annotations[0];if(typeof Y.start!="number"||typeof Y.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof Y.start),[]}return c.annotations},[c?.annotations]),R=i.useRef(E);R.current=E;const[W,T]=i.useState(null),[F,P]=i.useState(c?.isContinuousPlay??!1),[O]=i.useState(t),[U,J]=i.useState(s),V=i.useRef(null),ee=i.useRef(0),ae=i.useRef(F),Q=i.useRef(null),ue=i.useRef(null),ie=i.useRef(s),pe=i.useRef(t),{startAnimationFrameLoop:ye,stopAnimationFrameLoop:N}=Na();i.useEffect(()=>{ae.current=F},[F]),i.useEffect(()=>{ie.current=U},[U]);const H=i.useCallback(Y=>{Q.current=Y,T(Y)},[]),se=i.useCallback(Y=>{ae.current=Y,P(Y)},[]),G=i.useCallback(Y=>{ue.current=Y},[]),I=e.waveformData.sample_rate;i.useEffect(()=>{const Y=new pi({playbackRate:r});Y.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const re=Y.getTrack(Y.track?.id??"");return re&&re.setOnTimeUpdateCallback(ke=>{ee.current=ke}),Y.setOnPlaybackComplete(()=>{N(),m(!1),H(null),ee.current=0,x(0)}),V.current=Y,k(e.waveformData.duration),d?.(),()=>{N(),Y.dispose()}},[e.source,e.waveformData,e.name,r,d,N,H]),i.useEffect(()=>{const Y=Fs(e.waveformData,O,0,0,Math.ceil(e.waveformData.duration*I)),re={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:Y.length,data:[Y.data],bits:Y.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*I)};A([[re]])},[e.waveformData,e.name,O,I]);const le=i.useCallback(()=>{const Y=()=>{const re=V.current?.getCurrentTime()??0;ee.current=re;const ke=R.current;if(ke.length>0){const Te=ke.find($e=>re>=$e.start&&re<$e.end);if(ae.current)Te&&Te.id!==Q.current?H(Te.id):!Te&&Q.current!==null&&H(null);else if(Q.current){const $e=ke.find(Qe=>Qe.id===Q.current);if($e&&re>=$e.end){V.current?.stop(),m(!1);return}}else Te&&H(Te.id)}if(ie.current&&ue.current){const Te=ue.current,$e=re*I/pe.current,Qe=Te.clientWidth,Pe=l.show?l.width:0,Xe=$e+Pe,mt=Math.max(0,Xe-Qe/2);Te.scrollLeft=mt}ye(Y)};ye(Y)},[H,I,l,ye]),xe=N,K=i.useCallback(Y=>{if(!V.current)return;const re=Y??ee.current;V.current.play(void 0,re),m(!0),le()},[le]),ce=i.useCallback(()=>{V.current&&(V.current.pause(),m(!1),xe(),x(V.current.getCurrentTime()))},[xe]),Ie=i.useCallback(()=>{V.current&&(V.current.stop(),m(!1),xe(),ee.current=0,x(0),H(null))},[xe,H]),Ge=i.useCallback(Y=>{const re=Math.max(0,Math.min(Y,w));ee.current=re,x(re),V.current&&V.current.seekTo(re)},[w]),q=i.useCallback(Y=>{const re=Math.max(.5,Math.min(2,Y));_(re),V.current&&V.current.setPlaybackRate(re)},[]),_e=a?30:0,Ae=i.useMemo(()=>({isPlaying:g,currentTime:C,currentTimeRef:ee}),[g,C]),fe=i.useMemo(()=>({continuousPlay:F,annotations:E,activeAnnotationId:W,playbackRate:$,isAutomaticScroll:U}),[F,E,W,$,U]),Be=i.useRef(p);Be.current=p;const Fe=i.useCallback(Y=>{const re=typeof Y=="function"?Y(R.current):Y;if(!Be.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to MediaElementPlaylistProvider to handle annotation updates.");return}Be.current(re)},[]),ze=i.useMemo(()=>({play:K,pause:ce,stop:Ie,seekTo:Ge,setPlaybackRate:q,setContinuousPlay:se,setAnnotations:Fe,setActiveAnnotationId:H,setAutomaticScroll:Y=>{J(Y)},setScrollContainer:G,scrollContainerRef:ue}),[K,ce,Ie,Ge,q,se,Fe,H,G]),Ye=i.useMemo(()=>({duration:w,peaksDataArray:S,sampleRate:I,waveHeight:n,timeScaleHeight:_e,samplesPerPixel:O,playoutRef:V,controls:l,barWidth:u,barGap:f,progressBarWidth:y}),[w,S,I,n,_e,O,l,u,f,y]),Je={..._a,...o};return v.jsx(D.ThemeProvider,{theme:Je,children:v.jsx(qa.Provider,{value:Ae,children:v.jsx(Ja.Provider,{value:fe,children:v.jsx(Qa.Provider,{value:ze,children:v.jsx(er.Provider,{value:Ye,children:b})})})})})},Pt=()=>{const e=i.useContext(qa);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Wt=()=>{const e=i.useContext(Ja);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},dn=()=>{const e=i.useContext(Qa);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Vt=()=>{const e=i.useContext(er);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},bi=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Re(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=De(),{play:o}=be(),l=async()=>{if(a!==r&&r>a&&!s){const u=r-a;await o(a,u)}else await o(n.current??0)};return v.jsx(He,{onClick:l,disabled:t,className:e,children:"Play"})},vi=({className:e})=>{const{isPlaying:t}=Re(),{pause:n}=be();return v.jsx(He,{onClick:n,disabled:!t,className:e,children:"Pause"})},wi=({className:e})=>{const{isPlaying:t}=Re(),{stop:n}=be();return v.jsx(He,{onClick:n,disabled:!t,className:e,children:"Stop"})},yi=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=be(),r=()=>{a(0),t&&n(0)};return v.jsx(He,{onClick:r,className:e,children:"Rewind"})},Ci=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=be(),{duration:r}=je(),s=()=>{a(r),t&&n(r)};return v.jsx(He,{onClick:s,className:e,children:"Fast Forward"})},xi=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=be(),o=()=>{const l=Math.max(0,(n.current??0)-e);s(l),a&&r(l)};return v.jsx(He,{onClick:o,className:t,children:"Skip Backward"})},ki=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=be(),{duration:o}=je(),l=()=>{const c=Math.min(o,(n.current??0)+e);s(c),a&&r(c)};return v.jsx(He,{onClick:l,className:t,children:"Skip Forward"})},Si=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=De(),{setLoopEnabled:r,setLoopRegion:s}=be(),{duration:o}=je(),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 v.jsx(He,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},_i=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=De(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=be(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?o():s()};return v.jsx(He,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},Ii=({className:e,disabled:t})=>{const{zoomIn:n}=be(),{canZoomIn:a}=je();return v.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Ai=({className:e,disabled:t})=>{const{zoomOut:n}=be(),{canZoomOut:a}=je();return v.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Ei=({className:e})=>{const{masterVolume:t}=je(),{setMasterVolume:n}=be();return v.jsx(vo,{volume:t,onChange:n,className:e})},Mi=({className:e})=>{const{timeFormat:t}=je(),{setTimeFormat:n}=be();return v.jsx(es,{value:t,onChange:n,className:e})},Ti=D.span`
|
|
946
946
|
font-family: 'Courier New', Monaco, monospace;
|
|
947
947
|
font-size: 1rem;
|
|
948
948
|
font-weight: 600;
|
|
949
949
|
color: ${e=>e.theme?.textColor||"#333"};
|
|
950
950
|
user-select: none;
|
|
951
|
-
|
|
951
|
+
`,$i=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:a,currentTimeRef:r,getPlaybackTime:s}=Re(),{timeFormat:o}=je();return i.useEffect(()=>{const l=()=>{if(t.current){const c=a?s():r.current??0;t.current.textContent=ft(c,o)}a&&(n.current=requestAnimationFrame(l))};return a?n.current=requestAnimationFrame(l):l(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[a,o,r,s]),i.useEffect(()=>{!a&&t.current&&(t.current.textContent=ft(r.current??0,o))}),v.jsx(Ti,{ref:t,className:e,"aria-label":"Audio position",children:ft(r.current??0,o)})},Ri=({className:e})=>{const{selectionStart:t,selectionEnd:n}=De(),{setSelection:a}=be();return v.jsx(Mo,{selectionStart:t,selectionEnd:n,onSelectionChange:a,className:e})},Di=({className:e})=>{const{isAutomaticScroll:t}=De(),{setAutomaticScroll:n}=be();return v.jsx(Yr,{checked:t,onChange:n,className:e})},Zt=i.createContext(null),Bi=Zt.Provider;function it(){const e=i.useContext(Zt);if(!e)throw new Error("useAnnotationIntegration must be used within <AnnotationProvider>. Install @waveform-playlist/annotations and wrap your app with <AnnotationProvider>. See: https://waveform-playlist.naomiaro.com/docs/guides/annotations");return e}const Fi=({className:e})=>{const{ContinuousPlayCheckbox:t}=it(),{continuousPlay:n}=De(),{setContinuousPlay:a}=be();return v.jsx(t,{checked:n,onChange:a,className:e})},Pi=({className:e})=>{const{LinkEndpointsCheckbox:t}=it(),{linkEndpoints:n}=De(),{setLinkEndpoints:a}=be();return v.jsx(t,{checked:n,onChange:a,className:e})},Wi=({className:e})=>{const{EditableCheckbox:t}=it(),{annotationsEditable:n}=De(),{setAnnotationsEditable:a}=be();return v.jsx(t,{checked:n,onChange:a,className:e})},Vi=({filename:e,className:t})=>{const{DownloadAnnotationsButton:n}=it(),{annotations:a}=De();return v.jsx(n,{annotations:a,filename:e,className:t})},Zi=({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:f})=>{const{tracks:h,trackStates:p}=je(),{exportWav:d,isExporting:b,progress:y}=Oa(),g=async()=>{try{const C=await d(h,p,{filename:t,mode:n,trackIndex:a,bitDepth:r,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(C.blob)}catch(C){f?.(C instanceof Error?C:new Error("Export failed"))}},m=b?`Exporting ${Math.round(y*100)}%`:e;return v.jsx(He,{onClick:g,disabled:b||h.length===0,className:c,children:m})},Li=D.div.attrs(e=>({style:{width:`${e.$width}px`,background:e.$color}}))`
|
|
952
952
|
position: absolute;
|
|
953
953
|
top: 0;
|
|
954
954
|
left: 0;
|
|
@@ -956,9 +956,9 @@ self.onmessage = function(e) {
|
|
|
956
956
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
957
957
|
pointer-events: none;
|
|
958
958
|
will-change: transform;
|
|
959
|
-
`,
|
|
959
|
+
`,ji=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s,getPlaybackTime:o}=Re(),{samplesPerPixel:l,sampleRate:c,progressBarWidth:u}=je();return i.useEffect(()=>{const f=()=>{if(n.current){const p=(r?o():s.current??0)*c/l+t;n.current.style.transform=`translate3d(${p}px, 0, 0)`}r&&(a.current=requestAnimationFrame(f))};return r?a.current=requestAnimationFrame(f):f(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,c,l,t,s,o]),i.useEffect(()=>{if(!r&&n.current){const h=(s.current??0)*c/l+t;n.current.style.transform=`translate3d(${h}px, 0, 0)`}}),v.jsx(Li,{ref:n,$color:e,$width:u,"data-playhead":!0})},zi=D.div`
|
|
960
960
|
position: relative;
|
|
961
|
-
`,
|
|
961
|
+
`,Yt=D.div.attrs(e=>({style:{top:`${e.$top}px`,width:`${e.$width}px`,height:`${e.$height}px`,background:e.$color}}))`
|
|
962
962
|
position: absolute;
|
|
963
963
|
left: 0;
|
|
964
964
|
z-index: 0;
|
|
@@ -966,7 +966,7 @@ self.onmessage = function(e) {
|
|
|
966
966
|
transform: translateZ(0);
|
|
967
967
|
backface-visibility: hidden;
|
|
968
968
|
will-change: transform;
|
|
969
|
-
`,
|
|
969
|
+
`,Hi=D.div.attrs(e=>({style:{top:`${e.$top}px`,height:`${e.$height}px`,width:`${e.$width}px`,background:e.$color,transform:"scaleX(0)"}}))`
|
|
970
970
|
position: absolute;
|
|
971
971
|
left: 0;
|
|
972
972
|
pointer-events: none;
|
|
@@ -974,10 +974,10 @@ self.onmessage = function(e) {
|
|
|
974
974
|
transform-origin: left;
|
|
975
975
|
/* scaleX changes are composite-only (GPU) — no layout reflow per frame */
|
|
976
976
|
will-change: transform;
|
|
977
|
-
`,
|
|
977
|
+
`,Xi=D.div`
|
|
978
978
|
position: relative;
|
|
979
979
|
z-index: 2;
|
|
980
|
-
`,zn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=o.useRef(null),r=o.useRef(null),s=wt(),{waveHeight:i}=Bt(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:m}=Re(),{samplesPerPixel:h,sampleRate:p}=Me(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";o.useEffect(()=>{const M=()=>{if(a.current){let A;if(l){const B=Z.getContext().currentTime-(u.current??0);A=(m.current??0)+B}else A=c.current??0;const E=A*p,_=e+t;let I=0;E<=e?I=0:E>=_?I=1:I=(E-e)/t,a.current.style.transform=`scaleX(${I})`}l&&(r.current=requestAnimationFrame(M))};return l?r.current=requestAnimationFrame(M):M(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,p,h,e,t,n.length,c,u,m]),o.useEffect(()=>{if(!l&&a.current){const A=(c.current??0)*p,E=e+t;let _=0;A<=e?_=0:A>=E?_=1:_=(A-e)/t,a.current.style.transform=`scaleX(${_})`}});const b=s?.waveformDrawMode||"inverted";let w;b==="inverted"?w=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":w=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const g=n.renderMode==="spectrogram"||n.renderMode==="both",d=n.renderMode==="both",x=g?"#000":tt(w),y=Math.floor(i/2),C=i,k=n.index*i,S=tt(w);return v.jsxs(ui,{children:[d?v.jsxs(v.Fragment,{children:[v.jsx(Ot,{$color:"#000",$height:y,$top:k,$width:n.length}),v.jsx(Ot,{$color:S,$height:y,$top:k+y,$width:n.length})]}):v.jsx(Ot,{$color:x,$height:C,$top:k,$width:n.length}),v.jsx(di,{ref:a,$color:f,$height:C,$top:k,$width:n.length}),v.jsx(fi,{children:v.jsx(pa,{...n,transparentBackground:!0})})]})},on=o.createContext(null),mi=on.Provider;function hi(){const e=o.useContext(on);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const pi=60,Ba=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:r,className:s,showClipHeaders:i=!1,interactiveClips:l=!1,showFades:c=!1,touchOptimized:u=!1,onRemoveTrack:m,recordingState:h})=>{const p=wt(),{isPlaying:f,currentTimeRef:b,playbackStartTimeRef:w,audioStartPositionRef:g}=Re(),{selectionStart:d,selectionEnd:x,annotations:y,activeAnnotationId:C,annotationsEditable:k,linkEndpoints:S,continuousPlay:M,selectedTrackId:A,loopStart:E,loopEnd:_,isLoopEnabled:I}=De(),B=o.useContext(Vt),{setAnnotations:$,setActiveAnnotationId:W,setTrackMute:z,setTrackSolo:Y,setTrackVolume:j,setTrackPan:N,setSelection:L,play:ae,setScrollContainer:oe,setSelectedTrackId:q,setCurrentTime:fe,setLoopRegion:ue}=be(),{peaksDataArray:le,trackStates:Ee,tracks:P,duration:ee,samplesPerPixel:U,sampleRate:K,waveHeight:ie,timeScaleHeight:he,controls:te,playoutRef:Se,barWidth:Be,barGap:Xe,isReady:qe}=Me(),ne=o.useContext(on),Ve=o.useMemo(()=>{if(!ne)return new Map;const V=new Map;return P.forEach(X=>{if((ne.trackSpectrogramOverrides.get(X.id)?.renderMode??X.renderMode??"waveform")==="waveform")return;const me=ne.trackSpectrogramOverrides.get(X.id),pe=me?.colorMap??X.spectrogramColorMap??ne.spectrogramColorMap??"viridis",_e=me?.config??X.spectrogramConfig??ne.spectrogramConfig;V.set(X.id,{colorLUT:ne.getColorMap(pe),frequencyScaleFn:ne.getFrequencyScale(_e?.frequencyScale??"mel"),config:_e})}),V},[P,ne]),Oe=o.useMemo(()=>{if(ne?.spectrogramWorkerApi)return{registerCanvas:ne.spectrogramWorkerApi.registerCanvas.bind(ne.spectrogramWorkerApi),unregisterCanvas:ne.spectrogramWorkerApi.unregisterCanvas.bind(ne.spectrogramWorkerApi)}},[ne?.spectrogramWorkerApi]),[F,ye]=o.useState(null),[ce,je]=o.useState(!1),nt=o.useRef(null),Le=o.useCallback(V=>{nt.current=V,oe(V)},[oe]),O=P.reduce((V,X)=>X.clips.reduce((Q,me)=>{const pe=(me.startSample+me.durationSamples)/me.sampleRate;return Math.max(Q,pe)},V),0);let se=O>0?O:ee>0?ee:pi;if(h?.isRecording){const X=(h.startSample+h.durationSamples)/K;se=Math.max(se,X+10)}const ve=Math.floor(se*K/U),$e=async V=>{W(V.id);const X=M?void 0:V.end-V.start;try{await ae(V.start,X)}catch(Q){console.error("waveform-playlist: Failed to start playback for annotation",V.id,Q)}},Te=o.useCallback(V=>{if(V>=0&&V<P.length){const X=P[V];q(X.id)}},[P,q]),Ge=V=>{const X=V.currentTarget.getBoundingClientRect(),Q=te.show?te.width:0,pe=(V.clientX-X.left-Q)*U/K,Ce=V.clientY-X.top;let J=0,Ie=-1;for(let Fe=0;Fe<le.length;Fe++){const rt=le[Fe],Ne=rt.length>0?Math.max(1,...rt.map(Je=>Je.peaks.data.length)):1,ot=((ne?.trackSpectrogramOverrides.get(P[Fe]?.id)?.renderMode??P[Fe]?.renderMode??"waveform")==="both"?Ne*2:Ne)*ie+(i?22:0);if(Ce>=J&&Ce<J+ot){Ie=Fe;break}J+=ot}Ie!==-1&&Te(Ie),je(!0),fe(pe),L(pe,pe)},at=V=>{if(!ce)return;const X=V.currentTarget.getBoundingClientRect(),Q=te.show?te.width:0,pe=(V.clientX-X.left-Q)*U/K,_e=Math.min(d,pe),Ce=Math.max(d,pe);L(_e,Ce)},ut=V=>{if(!ce)return;je(!1);const X=V.currentTarget.getBoundingClientRect(),Q=te.show?te.width:0,pe=(V.clientX-X.left-Q)*U/K,_e=Math.min(d,pe),Ce=Math.max(d,pe);Math.abs(Ce-_e)<.1?(fe(_e),f&&Se.current?(Se.current.stop(),ae(_e)):Se.current&&Se.current.stop()):L(_e,Ce)};return P.some(V=>V.clips.length>0)&&le.length===0?v.jsx("div",{className:s,children:"Loading waveform..."}):v.jsxs(ha,{children:[v.jsx(Ct.Provider,{value:{samplesPerPixel:U,sampleRate:K,zoomLevels:[U],waveHeight:ie,timeScaleHeight:he,duration:se*1e3,controls:te,barWidth:Be,barGap:Xe},children:v.jsx(Qt,{theme:p,backgroundColor:tt(p.waveOutlineColor),timescaleBackgroundColor:p.timescaleBackgroundColor,scrollContainerWidth:ve+(te.show?te.width:0),timescaleWidth:ve,tracksWidth:ve,controlsWidth:te.show?te.width:0,onTracksMouseDown:Ge,onTracksMouseMove:at,onTracksMouseUp:ut,scrollContainerRef:Le,isSelecting:ce,"data-playlist-state":qe?"ready":"loading",timescale:he>0?v.jsxs(v.Fragment,{children:[v.jsx(ga,{renderTimestamp:t}),I&&v.jsx(qr,{startPosition:Math.min(E,_)*K/U,endPosition:Math.max(E,_)*K/U,markerColor:p.loopMarkerColor,regionColor:p.loopRegionColor,minPosition:0,maxPosition:ve,controlsOffset:te.show?te.width:0,onLoopRegionChange:(V,X)=>{const Q=V*U/K,me=X*U/K;ue(Q,me)}})]}):void 0,children:v.jsxs(v.Fragment,{children:[le.map((V,X)=>{const Q=P[X];if(!Q)return null;const me=Ee[X]||{name:`Track ${X+1}`,muted:!1,soloed:!1,volume:1,pan:0},pe=ne?.trackSpectrogramOverrides.get(Q.id)?.renderMode??Q.renderMode??"waveform",_e=e?e(X):v.jsxs(To,{onClick:()=>Te(X),children:[v.jsxs(Ro,{style:{justifyContent:"center",position:"relative"},children:[m&&v.jsx($o,{onClick:J=>{J.stopPropagation(),m(X)}}),v.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:me.name||`Track ${X+1}`}),ne?.renderMenuItems&&v.jsx("span",{style:{position:"absolute",right:0,top:0},children:v.jsx(jo,{items:J=>ne.renderMenuItems({renderMode:pe,onRenderModeChange:Ie=>ne.setTrackRenderMode(Q.id,Ie),onOpenSettings:()=>ye(Q.id),onClose:J})})})]}),v.jsxs(_o,{children:[v.jsx(Wn,{$variant:me.muted?"danger":"outline",onClick:()=>z(X,!me.muted),children:"Mute"}),v.jsx(Wn,{$variant:me.soloed?"info":"outline",onClick:()=>Y(X,!me.soloed),children:"Solo"})]}),v.jsxs(Zn,{children:[v.jsx(Do,{}),v.jsx(Pn,{min:"0",max:"1",step:"0.01",value:me.volume,onChange:J=>j(X,parseFloat(J.target.value))}),v.jsx(Bo,{})]}),v.jsxs(Zn,{children:[v.jsx("span",{children:"L"}),v.jsx(Pn,{min:"-1",max:"1",step:"0.01",value:me.pan,onChange:J=>N(X,parseFloat(J.target.value))}),v.jsx("span",{children:"R"})]})]}),Ce=V.length>0?Math.max(1,...V.map(J=>J.peaks.data.length)):1;return v.jsx(tn.Provider,{value:_e,children:v.jsxs(ba,{numChannels:Ce,backgroundColor:tt(p.waveOutlineColor),offset:0,width:ve,hasClipHeaders:i,trackId:Q.id,isSelected:Q.id===A,children:[pe!=="waveform"&&(()=>{const J=Ve.get(Q.id),Ie=J?.config;return!Ie?.labels||!J?null:v.jsx(mo,{waveHeight:ie,numChannels:Ce,frequencyScaleFn:J.frequencyScaleFn,minFrequency:Ie.minFrequency??0,maxFrequency:Ie.maxFrequency??K/2,labelsColor:Ie.labelsColor,labelsBackground:Ie.labelsBackground,renderMode:pe,hasClipHeaders:i})})(),V.map((J,Ie)=>{const Fe=J.peaks,rt=Fe.length;return v.jsx(Yt,{clipId:J.clipId,trackIndex:X,clipIndex:Ie,trackName:J.trackName,startSample:J.startSample,durationSamples:J.durationSamples,samplesPerPixel:U,showHeader:i,disableHeaderDrag:!l,isSelected:Q.id===A,trackId:Q.id,fadeIn:J.fadeIn,fadeOut:J.fadeOut,sampleRate:K,showFades:c,touchOptimized:u,onMouseDown:Ne=>{Ne.target.closest('[role="button"][aria-roledescription="draggable"]')||Te(X)},children:Fe.data.map((Ne,Ye)=>{const dt=ne?.spectrogramDataMap.get(J.clipId),ot=dt?.[Ye]??dt?.[0],Je=Ve.get(Q.id),ze=Je?.config;return v.jsx(zn,{index:Ye,data:Ne,bits:Fe.bits,length:rt,isSelected:Q.id===A,clipStartSample:J.startSample,clipDurationSamples:J.durationSamples,renderMode:pe,spectrogramData:ot,samplesPerPixel:U,spectrogramColorLUT:Je?.colorLUT,spectrogramFrequencyScaleFn:Je?.frequencyScaleFn,spectrogramMinFrequency:ze?.minFrequency,spectrogramMaxFrequency:ze?.maxFrequency,spectrogramWorkerApi:Oe,spectrogramClipId:J.clipId,spectrogramOnCanvasesReady:ne?(xt,Qe)=>{ne.registerSpectrogramCanvases(J.clipId,Ye,xt,Qe)}:void 0},`${J.clipId}-${Ye}`)})},J.clipId)}),h?.isRecording&&h.trackId===Q.id&&h.peaks.length>0&&v.jsx(Yt,{clipId:"recording-preview",trackIndex:X,clipIndex:V.length,trackName:"Recording...",startSample:h.startSample,durationSamples:h.durationSamples,samplesPerPixel:U,showHeader:i,disableHeaderDrag:!0,isSelected:Q.id===A,trackId:Q.id,children:v.jsx(zn,{index:0,data:h.peaks,bits:16,length:Math.floor(h.peaks.length/2),isSelected:Q.id===A,clipStartSample:h.startSample,clipDurationSamples:h.durationSamples},`${Q.id}-recording-0`)},`${Q.id}-recording`)]})},Q.id)}),y.length>0&&B&&v.jsx(B.AnnotationBoxesWrapper,{height:30,width:ve,children:y.map((V,X)=>{const Q=V.start*K/U,me=V.end*K/U,pe=r?r(V,X):V.id;return v.jsx(B.AnnotationBox,{annotationId:V.id,annotationIndex:X,startPosition:Q,endPosition:me,label:pe,color:"#ff9800",isActive:V.id===C,onClick:()=>$e(V),editable:k},V.id)})}),d!==x&&v.jsx(da,{startPosition:Math.min(d,x)*K/U+(te.show?te.width:0),endPosition:Math.max(d,x)*K/U+(te.show?te.width:0),color:p.selectionColor}),(f||d===x)&&(n?n({position:(b.current??0)*K/U+(te.show?te.width:0),color:p.playheadColor,isPlaying:f,currentTimeRef:b,playbackStartTimeRef:w,audioStartPositionRef:g,samplesPerPixel:U,sampleRate:K,controlsOffset:te.show?te.width:0,getAudioContextTime:()=>Z.getContext().currentTime}):v.jsx(ci,{color:p.playheadColor,controlsOffset:te.show?te.width:0}))]})})}),ne?.SettingsModal&&typeof document<"u"&&Hn.createPortal(v.jsx(ne.SettingsModal,{open:F!==null,onClose:()=>ye(null),config:F!==null?ne.trackSpectrogramOverrides.get(F)?.config??P.find(V=>V.id===F)?.spectrogramConfig??ne.spectrogramConfig??{}:{},colorMap:F!==null?ne.trackSpectrogramOverrides.get(F)?.colorMap??P.find(V=>V.id===F)?.spectrogramColorMap??ne.spectrogramColorMap??"viridis":"viridis",onApply:(V,X)=>{F!==null&&ne.setTrackSpectrogramConfig(F,V,X)}}),document.body)]})},Fa=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:a,annotationListConfig:r,scrollActivePosition:s="center",scrollActiveContainer:i="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:m,continuousPlay:h}=De(),p=ct(),{setAnnotations:f}=be(),b=r??{linkEndpoints:m,continuousPlay:h},w=o.useCallback(d=>{f(d),n?.(d)},[f,n]),{AnnotationText:g}=p;return v.jsx(g,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:i,editable:u,controls:u?a:void 0,annotationListConfig:b,height:e,onAnnotationUpdate:w,renderAnnotationItem:t})},gi=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:i,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:m,showClipHeaders:h=!1,interactiveClips:p=!1,showFades:f=!1,touchOptimized:b=!1,onRemoveTrack:w,recordingState:g})=>{const{annotations:d}=De();return v.jsxs(v.Fragment,{children:[v.jsx(Ba,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:l,className:m,showClipHeaders:h,interactiveClips:p,showFades:f,touchOptimized:b,onRemoveTrack:w,recordingState:g}),d.length>0&&v.jsx(Fa,{height:s,renderAnnotationItem:i,controls:a,annotationListConfig:r,scrollActivePosition:c,scrollActiveContainer:u})]})},bi=R.div`
|
|
980
|
+
`,ia=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=yt(),{waveHeight:o}=Bt(),{isPlaying:l,currentTimeRef:c,getPlaybackTime:u}=Re(),{samplesPerPixel:f,sampleRate:h}=je(),p=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const S=()=>{if(a.current){const $=(l?u():c.current??0)*h,_=e+t;let E=0;$<=e?E=0:$>=_?E=1:E=($-e)/t,a.current.style.transform=`scaleX(${E})`}l&&(r.current=requestAnimationFrame(S))};return l?r.current=requestAnimationFrame(S):S(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,h,f,e,t,n.length,c,u]),i.useEffect(()=>{if(!l&&a.current){const A=(c.current??0)*h,$=e+t;let _=0;A<=e?_=0:A>=$?_=1:_=(A-e)/t,a.current.style.transform=`scaleX(${_})`}});const d=s?.waveformDrawMode||"inverted";let b;d==="inverted"?b=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":b=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const y=n.renderMode==="spectrogram"||n.renderMode==="both",g=n.renderMode==="both",m=y?"#000":tt(b),C=Math.floor(o/2),x=o,w=n.index*o,k=tt(b);return v.jsxs(zi,{children:[g?v.jsxs(v.Fragment,{children:[v.jsx(Yt,{$color:"#000",$height:C,$top:w,$width:n.length}),v.jsx(Yt,{$color:k,$height:C,$top:w+C,$width:n.length})]}):v.jsx(Yt,{$color:m,$height:x,$top:w,$width:n.length}),v.jsx(Hi,{ref:a,$color:p,$height:x,$top:w,$width:n.length}),v.jsx(Xi,{children:v.jsx(Pa,{...n,transparentBackground:!0})})]})},fn=i.createContext(null),Oi=fn.Provider;function Ni(){const e=i.useContext(fn);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const Gi=60,tr=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:r,className:s,showClipHeaders:o=!1,interactiveClips:l=!1,showFades:c=!1,touchOptimized:u=!1,onRemoveTrack:f,recordingState:h})=>{const p=yt(),{isPlaying:d,currentTimeRef:b,playbackStartTimeRef:y,audioStartPositionRef:g,getPlaybackTime:m}=Re(),{selectionStart:C,selectionEnd:x,annotations:w,activeAnnotationId:k,annotationsEditable:S,linkEndpoints:A,continuousPlay:$,selectedTrackId:_,loopStart:E,loopEnd:R,isLoopEnabled:W}=De(),T=i.useContext(Zt),{setAnnotations:F,setActiveAnnotationId:P,setTrackMute:O,setTrackSolo:U,setTrackVolume:J,setTrackPan:V,setSelection:ee,play:ae,setScrollContainer:Q,setSelectedTrackId:ue,setCurrentTime:ie,setLoopRegion:pe}=be(),{peaksDataArray:ye,trackStates:N,tracks:H,duration:se,samplesPerPixel:G,sampleRate:I,waveHeight:le,timeScaleHeight:xe,controls:K,barWidth:ce,barGap:Ie,isReady:Ge}=je(),q=i.useContext(fn),_e=i.useMemo(()=>{if(!q)return new Map;const L=new Map;return H.forEach(X=>{if((q.trackSpectrogramOverrides.get(X.id)?.renderMode??X.renderMode??"waveform")==="waveform")return;const me=q.trackSpectrogramOverrides.get(X.id),ge=me?.colorMap??X.spectrogramColorMap??q.spectrogramColorMap??"viridis",Ee=me?.config??X.spectrogramConfig??q.spectrogramConfig;L.set(X.id,{colorLUT:q.getColorMap(ge),frequencyScaleFn:q.getFrequencyScale(Ee?.frequencyScale??"mel"),config:Ee})}),L},[H,q]),Ae=i.useMemo(()=>{if(q?.spectrogramWorkerApi)return{registerCanvas:q.spectrogramWorkerApi.registerCanvas.bind(q.spectrogramWorkerApi),unregisterCanvas:q.spectrogramWorkerApi.unregisterCanvas.bind(q.spectrogramWorkerApi)}},[q?.spectrogramWorkerApi]),[fe,Be]=i.useState(null),[Fe,ze]=i.useState(!1),Ye=i.useRef(null),Je=i.useCallback(L=>{Ye.current=L,Q(L)},[Q]),Y=H.reduce((L,X)=>X.clips.reduce((te,me)=>{const ge=(me.startSample+me.durationSamples)/me.sampleRate;return Math.max(te,ge)},L),0);let re=Y>0?Y:se>0?se:Gi;if(h?.isRecording){const X=(h.startSample+h.durationSamples)/I;re=Math.max(re,X+10)}const ke=Math.floor(re*I/G),Te=async L=>{P(L.id);const X=$?void 0:L.end-L.start;try{await ae(L.start,X)}catch(te){console.error("waveform-playlist: Failed to start playback for annotation",L.id,te)}},$e=i.useCallback(L=>{if(L>=0&&L<H.length){const X=H[L];ue(X.id)}},[H,ue]),Qe=L=>{const X=L.currentTarget.getBoundingClientRect(),te=K.show?K.width:0,ge=(L.clientX-X.left-te)*G/I,We=L.clientY-X.top;let ne=0,Ce=-1;for(let Me=0;Me<ye.length;Me++){const nt=ye[Me],Ue=nt.length>0?Math.max(1,...nt.map(Ne=>Ne.peaks.data.length)):1,rt=((q?.trackSpectrogramOverrides.get(H[Me]?.id)?.renderMode??H[Me]?.renderMode??"waveform")==="both"?Ue*2:Ue)*le+(o?22:0);if(We>=ne&&We<ne+rt){Ce=Me;break}ne+=rt}Ce!==-1&&$e(Ce),ze(!0),ie(ge),ee(ge,ge)},Pe=L=>{if(!Fe)return;const X=L.currentTarget.getBoundingClientRect(),te=K.show?K.width:0,ge=(L.clientX-X.left-te)*G/I,Ee=Math.min(C,ge),We=Math.max(C,ge);ee(Ee,We)},Xe=L=>{if(!Fe)return;ze(!1);const X=L.currentTarget.getBoundingClientRect(),te=K.show?K.width:0,ge=(L.clientX-X.left-te)*G/I,Ee=Math.min(C,ge),We=Math.max(C,ge);Math.abs(We-Ee)<.1?(ie(Ee),d&&ae(Ee)):ee(Ee,We)};return H.some(L=>L.clips.length>0)&&ye.length===0?v.jsx("div",{className:s,children:"Loading waveform..."}):v.jsxs(Fa,{children:[v.jsx(wt.Provider,{value:{samplesPerPixel:G,sampleRate:I,zoomLevels:[G],waveHeight:le,timeScaleHeight:xe,duration:re*1e3,controls:K,barWidth:ce,barGap:Ie},children:v.jsx(on,{theme:p,backgroundColor:tt(p.waveOutlineColor),timescaleBackgroundColor:p.timescaleBackgroundColor,scrollContainerWidth:ke+(K.show?K.width:0),timescaleWidth:ke,tracksWidth:ke,controlsWidth:K.show?K.width:0,onTracksMouseDown:Qe,onTracksMouseMove:Pe,onTracksMouseUp:Xe,scrollContainerRef:Je,isSelecting:Fe,"data-playlist-state":Ge?"ready":"loading",timescale:xe>0?v.jsxs(v.Fragment,{children:[v.jsx(Wa,{renderTimestamp:t}),W&&v.jsx(Eo,{startPosition:Math.min(E,R)*I/G,endPosition:Math.max(E,R)*I/G,markerColor:p.loopMarkerColor,regionColor:p.loopRegionColor,minPosition:0,maxPosition:ke,controlsOffset:K.show?K.width:0,onLoopRegionChange:(L,X)=>{const te=L*G/I,me=X*G/I;pe(te,me)}})]}):void 0,children:v.jsxs(v.Fragment,{children:[ye.map((L,X)=>{const te=H[X];if(!te)return null;const me=N[X]||{name:`Track ${X+1}`,muted:!1,soloed:!1,volume:1,pan:0},ge=q?.trackSpectrogramOverrides.get(te.id)?.renderMode??te.renderMode??"waveform",Ee=e?e(X):v.jsxs(is,{onClick:()=>$e(X),children:[v.jsxs(ls,{style:{justifyContent:"center",position:"relative"},children:[f&&v.jsx(ss,{onClick:ne=>{ne.stopPropagation(),f(X)}}),v.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:me.name||`Track ${X+1}`}),q?.renderMenuItems&&v.jsx("span",{style:{position:"absolute",right:0,top:0},children:v.jsx(gs,{items:ne=>q.renderMenuItems({renderMode:ge,onRenderModeChange:Ce=>q.setTrackRenderMode(te.id,Ce),onOpenSettings:()=>Be(te.id),onClose:ne})})})]}),v.jsxs(rs,{children:[v.jsx(ta,{$variant:me.muted?"danger":"outline",onClick:()=>O(X,!me.muted),children:"Mute"}),v.jsx(ta,{$variant:me.soloed?"info":"outline",onClick:()=>U(X,!me.soloed),children:"Solo"})]}),v.jsxs(aa,{children:[v.jsx(cs,{}),v.jsx(na,{min:"0",max:"1",step:"0.01",value:me.volume,onChange:ne=>J(X,parseFloat(ne.target.value))}),v.jsx(us,{})]}),v.jsxs(aa,{children:[v.jsx("span",{children:"L"}),v.jsx(na,{min:"-1",max:"1",step:"0.01",value:me.pan,onChange:ne=>V(X,parseFloat(ne.target.value))}),v.jsx("span",{children:"R"})]})]}),We=L.length>0?Math.max(1,...L.map(ne=>ne.peaks.data.length)):1;return v.jsx(ln.Provider,{value:Ee,children:v.jsxs(Va,{numChannels:We,backgroundColor:tt(p.waveOutlineColor),offset:0,width:ke,hasClipHeaders:o,trackId:te.id,isSelected:te.id===_,children:[ge!=="waveform"&&(()=>{const ne=_e.get(te.id),Ce=ne?.config;return!Ce?.labels||!ne?null:v.jsx(Ho,{waveHeight:le,numChannels:We,frequencyScaleFn:ne.frequencyScaleFn,minFrequency:Ce.minFrequency??0,maxFrequency:Ce.maxFrequency??I/2,labelsColor:Ce.labelsColor,labelsBackground:Ce.labelsBackground,renderMode:ge,hasClipHeaders:o})})(),L.map((ne,Ce)=>{const Me=ne.peaks,nt=Me.length;return v.jsx(en,{clipId:ne.clipId,trackIndex:X,clipIndex:Ce,trackName:ne.trackName,startSample:ne.startSample,durationSamples:ne.durationSamples,samplesPerPixel:G,showHeader:o,disableHeaderDrag:!l,isSelected:te.id===_,trackId:te.id,fadeIn:ne.fadeIn,fadeOut:ne.fadeOut,sampleRate:I,showFades:c,touchOptimized:u,onMouseDown:Ue=>{Ue.target.closest('[role="button"][aria-roledescription="draggable"]')||$e(X)},children:Me.data.map((Ue,Ke)=>{const at=q?.spectrogramDataMap.get(ne.clipId),rt=at?.[Ke]??at?.[0],Ne=_e.get(te.id),ht=Ne?.config;return v.jsx(ia,{index:Ke,data:Ue,bits:Me.bits,length:nt,isSelected:te.id===_,clipStartSample:ne.startSample,clipDurationSamples:ne.durationSamples,renderMode:ge,spectrogramData:rt,samplesPerPixel:G,spectrogramColorLUT:Ne?.colorLUT,spectrogramFrequencyScaleFn:Ne?.frequencyScaleFn,spectrogramMinFrequency:ht?.minFrequency,spectrogramMaxFrequency:ht?.maxFrequency,spectrogramWorkerApi:Ae,spectrogramClipId:ne.clipId,spectrogramOnCanvasesReady:q?(xt,kt)=>{q.registerSpectrogramCanvases(ne.clipId,Ke,xt,kt)}:void 0},`${ne.clipId}-${Ke}`)})},ne.clipId)}),h?.isRecording&&h.trackId===te.id&&h.peaks.length>0&&v.jsx(en,{clipId:"recording-preview",trackIndex:X,clipIndex:L.length,trackName:"Recording...",startSample:h.startSample,durationSamples:h.durationSamples,samplesPerPixel:G,showHeader:o,disableHeaderDrag:!0,isSelected:te.id===_,trackId:te.id,children:v.jsx(ia,{index:0,data:h.peaks,bits:16,length:Math.floor(h.peaks.length/2),isSelected:te.id===_,clipStartSample:h.startSample,clipDurationSamples:h.durationSamples},`${te.id}-recording-0`)},`${te.id}-recording`)]})},te.id)}),w.length>0&&T&&v.jsx(T.AnnotationBoxesWrapper,{height:30,width:ke,children:w.map((L,X)=>{const te=L.start*I/G,me=L.end*I/G,ge=r?r(L,X):L.id;return v.jsx(T.AnnotationBox,{annotationId:L.id,annotationIndex:X,startPosition:te,endPosition:me,label:ge,color:"#ff9800",isActive:L.id===k,onClick:()=>Te(L),editable:S},L.id)})}),C!==x&&v.jsx(Ra,{startPosition:Math.min(C,x)*I/G+(K.show?K.width:0),endPosition:Math.max(C,x)*I/G+(K.show?K.width:0),color:p.selectionColor}),(d||C===x)&&(n?n({position:(b.current??0)*I/G+(K.show?K.width:0),color:p.playheadColor,isPlaying:d,currentTimeRef:b,playbackStartTimeRef:y,audioStartPositionRef:g,samplesPerPixel:G,sampleRate:I,controlsOffset:K.show?K.width:0,getAudioContextTime:()=>z.getContext().currentTime,getPlaybackTime:m}):v.jsx(ji,{color:p.playheadColor,controlsOffset:K.show?K.width:0}))]})})}),q?.SettingsModal&&typeof document<"u"&&la.createPortal(v.jsx(q.SettingsModal,{open:fe!==null,onClose:()=>Be(null),config:fe!==null?q.trackSpectrogramOverrides.get(fe)?.config??H.find(L=>L.id===fe)?.spectrogramConfig??q.spectrogramConfig??{}:{},colorMap:fe!==null?q.trackSpectrogramOverrides.get(fe)?.colorMap??H.find(L=>L.id===fe)?.spectrogramColorMap??q.spectrogramColorMap??"viridis":"viridis",onApply:(L,X)=>{fe!==null&&q.setTrackSpectrogramConfig(fe,L,X)}}),document.body)]})},nr=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:a,annotationListConfig:r,scrollActivePosition:s="center",scrollActiveContainer:o="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:f,continuousPlay:h}=De(),p=it(),{setAnnotations:d}=be(),b=r??{linkEndpoints:f,continuousPlay:h},y=i.useCallback(m=>{d(m),n?.(m)},[d,n]),{AnnotationText:g}=p;return v.jsx(g,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:o,editable:u,controls:u?a:void 0,annotationListConfig:b,height:e,onAnnotationUpdate:y,renderAnnotationItem:t})},Yi=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:f,showClipHeaders:h=!1,interactiveClips:p=!1,showFades:d=!1,touchOptimized:b=!1,onRemoveTrack:y,recordingState:g})=>{const{annotations:m}=De();return v.jsxs(v.Fragment,{children:[v.jsx(tr,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:l,className:f,showClipHeaders:h,interactiveClips:p,showFades:d,touchOptimized:b,onRemoveTrack:y,recordingState:g}),m.length>0&&v.jsx(nr,{height:s,renderAnnotationItem:o,controls:a,annotationListConfig:r,scrollActivePosition:c,scrollActiveContainer:u})]})},Ui=D.div`
|
|
981
981
|
position: absolute;
|
|
982
982
|
top: 0;
|
|
983
983
|
left: 0;
|
|
@@ -987,9 +987,9 @@ self.onmessage = function(e) {
|
|
|
987
987
|
z-index: 100;
|
|
988
988
|
pointer-events: none;
|
|
989
989
|
will-change: transform;
|
|
990
|
-
`,
|
|
990
|
+
`,Ki=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s}=Pt(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=Vt();return i.useEffect(()=>{const u=()=>{if(n.current){const h=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${h}px, 0, 0)`}r&&(a.current=requestAnimationFrame(u))};return r?a.current=requestAnimationFrame(u):u(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,l,o,t,s]),i.useEffect(()=>{if(!r&&n.current){const f=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}}),v.jsx(Ui,{ref:n,$color:e,$width:c,"data-playhead":!0})},qi=D.div`
|
|
991
991
|
position: relative;
|
|
992
|
-
`,
|
|
992
|
+
`,Ji=D.div`
|
|
993
993
|
position: absolute;
|
|
994
994
|
top: ${e=>e.$top}px;
|
|
995
995
|
left: 0;
|
|
@@ -1000,7 +1000,7 @@ self.onmessage = function(e) {
|
|
|
1000
1000
|
transform: translateZ(0);
|
|
1001
1001
|
backface-visibility: hidden;
|
|
1002
1002
|
will-change: transform;
|
|
1003
|
-
`,
|
|
1003
|
+
`,Qi=D.div`
|
|
1004
1004
|
position: absolute;
|
|
1005
1005
|
top: ${e=>e.$top}px;
|
|
1006
1006
|
left: 0;
|
|
@@ -1009,8 +1009,8 @@ self.onmessage = function(e) {
|
|
|
1009
1009
|
pointer-events: none;
|
|
1010
1010
|
z-index: 1;
|
|
1011
1011
|
will-change: width;
|
|
1012
|
-
`,
|
|
1012
|
+
`,el=D.div`
|
|
1013
1013
|
position: relative;
|
|
1014
1014
|
z-index: 2;
|
|
1015
|
-
`,
|
|
1015
|
+
`,tl=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=yt(),{waveHeight:o}=Bt(),{isPlaying:l,currentTimeRef:c}=Pt(),{samplesPerPixel:u,sampleRate:f}=Vt(),h=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const y=()=>{if(a.current){const m=(c.current??0)*f,C=e+t;let x=0;if(m<=e)x=0;else if(m>=C)x=n.length;else{const w=m-e;x=Math.floor(w/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,f,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&a.current){const g=(c.current??0)*f,m=e+t;let C=0;if(g<=e)C=0;else if(g>=m)C=n.length;else{const x=g-e;C=Math.floor(x/u)}a.current.style.width=`${C}px`}});const p=s?.waveformDrawMode||"inverted";let d;p==="inverted"?d=s?.selectedWaveFillColor||s?.waveFillColor||"white":d=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const b=tt(d);return v.jsxs(qi,{children:[v.jsx(Ji,{$color:b,$height:o,$top:n.index*o,$width:n.length}),v.jsx(Qi,{ref:a,$color:h,$height:o,$top:n.index*o}),v.jsx(el,{children:v.jsx(Pa,{...n,isSelected:!0,transparentBackground:!0})})]})},ar=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:a,className:r})=>{const s=yt(),{isPlaying:o}=Pt(),{annotations:l,activeAnnotationId:c}=Wt(),u=i.useContext(Zt),{play:f,seekTo:h,setActiveAnnotationId:p,setAnnotations:d,setScrollContainer:b}=dn(),{duration:y,peaksDataArray:g,sampleRate:m,waveHeight:C,timeScaleHeight:x,samplesPerPixel:w,controls:k,playoutRef:S,barWidth:A,barGap:$}=Vt(),[_,E]=i.useState(0),[R,W]=i.useState(0),[T,F]=i.useState(!1),P=i.useRef(null),O=i.useCallback(N=>{P.current=N,b(N)},[b]),U=Math.floor(y*m/w),J=i.useCallback(async N=>{p(N.id);try{await f(N.start)}catch(H){console.error("waveform-playlist: Failed to start playback for annotation",N.id,H)}},[p,f]),V=i.useCallback(N=>{d(N),a?.(N)},[d,a]),{onDragStart:ee,onDragMove:ae,onDragEnd:Q}=Xa({annotations:l,onAnnotationsChange:V,samplesPerPixel:w,sampleRate:m,duration:y,linkEndpoints:n}),ue=i.useCallback(N=>{const H=N.currentTarget.getBoundingClientRect(),se=k.show?k.width:0,I=(N.clientX-H.left-se)*w/m;F(!0),E(I),W(I)},[k,w,m]),ie=i.useCallback(N=>{if(!T)return;const H=N.currentTarget.getBoundingClientRect(),se=k.show?k.width:0,I=(N.clientX-H.left-se)*w/m;W(I)},[T,k,w,m]),pe=i.useCallback(N=>{if(!T)return;F(!1);const H=N.currentTarget.getBoundingClientRect(),se=k.show?k.width:0,I=(N.clientX-H.left-se)*w/m,le=Math.min(_,I),xe=Math.max(_,I);Math.abs(xe-le)<.1?(h(le),E(le),W(le),o&&S.current&&(S.current.stop(),f(le))):(E(le),W(xe))},[T,_,w,m,k,h,o,S,f]);if(g.length===0)return v.jsx("div",{className:r,children:"Loading waveform..."});const ye=null;return v.jsx(Fa,{children:v.jsx(wt.Provider,{value:{samplesPerPixel:w,sampleRate:m,zoomLevels:[w],waveHeight:C,timeScaleHeight:x,duration:y*1e3,controls:k,barWidth:A,barGap:$},children:v.jsx(on,{theme:s,backgroundColor:tt(s.waveOutlineColor),timescaleBackgroundColor:s.timescaleBackgroundColor,scrollContainerWidth:U+(k.show?k.width:0),timescaleWidth:U,tracksWidth:U,controlsWidth:k.show?k.width:0,onTracksMouseDown:ue,onTracksMouseMove:ie,onTracksMouseUp:pe,scrollContainerRef:O,isSelecting:T,timescale:x>0?v.jsx(Wa,{}):void 0,children:v.jsxs(v.Fragment,{children:[g.map((N,H)=>{const se=N.length>0?Math.max(...N.map(G=>G.peaks.data.length)):1;return v.jsx(ln.Provider,{value:ye,children:v.jsx(Va,{numChannels:se,backgroundColor:tt(s.waveOutlineColor),offset:0,width:U,hasClipHeaders:!1,trackId:`media-element-track-${H}`,isSelected:!0,children:N.map((G,I)=>{const le=G.peaks,xe=le.length;return v.jsx(en,{clipId:G.clipId,trackIndex:H,clipIndex:I,trackName:G.trackName,startSample:G.startSample,durationSamples:G.durationSamples,samplesPerPixel:w,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${H}`,children:le.data.map((K,ce)=>v.jsx(tl,{index:ce,data:K,bits:le.bits,length:xe,clipStartSample:G.startSample,clipDurationSamples:G.durationSamples},`${H}-${I}-${ce}`))},`${H}-${I}`)})})},H)}),l.length>0&&u&&v.jsx(Oe.DndContext,{onDragStart:ee,onDragMove:ae,onDragEnd:Q,modifiers:t?[wr.restrictToHorizontalAxis]:[],children:v.jsx(u.AnnotationBoxesWrapper,{height:30,width:U,children:l.map((N,H)=>{const se=N.start*m/w,G=N.end*m/w,I=e?e(N,H):N.id;return v.jsx(u.AnnotationBox,{annotationId:N.id,annotationIndex:H,startPosition:se,endPosition:G,label:I,color:"#ff9800",isActive:N.id===c,onClick:()=>J(N),editable:t},N.id)})})}),_!==R&&v.jsx(Ra,{startPosition:Math.min(_,R)*m/w+(k.show?k.width:0),endPosition:Math.max(_,R)*m/w+(k.show?k.width:0),color:s.selectionColor}),v.jsx(Ki,{color:s.playheadColor,controlsOffset:k.show?k.width:0})]})})})})},rr=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,editable:a=!1,controls:r,annotationListConfig:s,scrollActivePosition:o="center",scrollActiveContainer:l="nearest"})=>{const{annotations:c,activeAnnotationId:u,continuousPlay:f}=Wt(),h=it(),{setAnnotations:p}=dn(),d=s??{linkEndpoints:!1,continuousPlay:f},b=i.useCallback(g=>{p(g),n?.(g)},[p,n]),{AnnotationText:y}=h;return v.jsx(y,{annotations:c,activeAnnotationId:u??void 0,shouldScrollToActive:!0,scrollActivePosition:o,scrollActiveContainer:l,editable:a,controls:a?r:void 0,annotationListConfig:d,height:e,onAnnotationUpdate:b,renderAnnotationItem:t})},nl=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:a=!1,linkEndpoints:r=!1,onAnnotationUpdate:s,scrollActivePosition:o="center",scrollActiveContainer:l="nearest",className:c})=>{const{annotations:u}=Wt();return v.jsxs(v.Fragment,{children:[v.jsx(ar,{getAnnotationBoxLabel:t,editable:a,linkEndpoints:r,onAnnotationUpdate:s,className:c}),u.length>0&&v.jsx(rr,{height:e,renderAnnotationItem:n,onAnnotationUpdate:s,editable:a,annotationListConfig:{linkEndpoints:r,continuousPlay:!1},scrollActivePosition:o,scrollActiveContainer:l})]})};exports.Tone=ua;exports.AnnotationIntegrationProvider=Bi;exports.AudioPosition=$i;exports.AutomaticScrollCheckbox=Di;exports.ContinuousPlayCheckbox=Fi;exports.DownloadAnnotationsButton=Vi;exports.EditableCheckbox=Wi;exports.ExportWavButton=Zi;exports.FastForwardButton=Ci;exports.LinkEndpointsCheckbox=Pi;exports.LoopButton=Si;exports.MasterVolumeControl=Ei;exports.MediaElementAnnotationList=rr;exports.MediaElementPlaylist=ar;exports.MediaElementPlaylistProvider=gi;exports.MediaElementWaveform=nl;exports.PauseButton=vi;exports.PlayButton=bi;exports.PlaylistAnnotationList=nr;exports.PlaylistVisualization=tr;exports.RewindButton=yi;exports.SelectionTimeInputs=Ri;exports.SetLoopRegionButton=_i;exports.SkipBackwardButton=xi;exports.SkipForwardButton=ki;exports.SpectrogramIntegrationProvider=Oi;exports.StopButton=wi;exports.TimeFormatSelect=Mi;exports.Waveform=Yi;exports.WaveformPlaylistProvider=mi;exports.ZoomInButton=Ii;exports.ZoomOutButton=Ai;exports.createEffectChain=Qs;exports.createEffectInstance=bt;exports.effectCategories=Us;exports.effectDefinitions=Ct;exports.getEffectDefinition=un;exports.getEffectsByCategory=Ys;exports.getShortcutLabel=Os;exports.getWaveformDataMetadata=Bs;exports.loadPeaksFromWaveformData=Ds;exports.loadWaveformData=cn;exports.useAnnotationDragHandlers=Xa;exports.useAnnotationIntegration=it;exports.useAnnotationKeyboardControls=Gs;exports.useAudioTracks=Ls;exports.useClipDragHandlers=js;exports.useClipSplitting=Xs;exports.useDragSensors=Hs;exports.useDynamicEffects=ei;exports.useDynamicTracks=fi;exports.useExportWav=Oa;exports.useKeyboardShortcuts=Dt;exports.useMasterAnalyser=Zs;exports.useMasterVolume=Ha;exports.useMediaElementAnimation=Pt;exports.useMediaElementControls=dn;exports.useMediaElementData=Vt;exports.useMediaElementState=Wt;exports.usePlaybackAnimation=Re;exports.usePlaybackShortcuts=Ns;exports.usePlaylistControls=be;exports.usePlaylistData=je;exports.usePlaylistState=De;exports.useSpectrogramIntegration=Ni;exports.useTimeFormat=ja;exports.useTrackDynamicEffects=ti;exports.useZoomControls=za;exports.waveformDataToPeaks=La;
|
|
1016
1016
|
//# sourceMappingURL=index.js.map
|