@waveform-playlist/browser 6.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +78 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +998 -996
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var Ra=Object.create;var nn=Object.defineProperty;var _a=Object.getOwnPropertyDescriptor;var Ba=Object.getOwnPropertyNames;var Fa=Object.getPrototypeOf,Wa=Object.prototype.hasOwnProperty;var Pa=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ba(t))!Wa.call(e,r)&&r!==n&&nn(e,r,{get:()=>t[r],enumerable:!(a=_a(t,r))||a.enumerable});return e};var Za=(e,t,n)=>(n=e!=null?Ra(Fa(e)):{},Pa(t||!e||!e.__esModule?nn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("tone"),p=require("react/jsx-runtime"),i=require("react"),D=require("styled-components"),Oe=require("@dnd-kit/core"),kn=require("react-dom"),Va=require("@dnd-kit/modifiers");function Sn(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 An=Sn(P),T=Sn(i);function an(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 ja(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 Ha(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 za(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 In(e,t,n){switch(e){case"linear":return an(t,n);case"exponential":return ja(t,n);case"sCurve":return Ha(t,n);case"logarithmic":return za(t,n);default:return an(t,n)}}function rn(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=In(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 on(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=In(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 La=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new P.Volume(this.gainToDb(e.track.gain)),this.panNode=new P.Panner(e.track.stereoPan),this.muteGain=new P.Gain(e.track.muted?0:1);const t=e.destination||P.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 P.Player({url:a.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new P.Gain(a.gain);return r.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:r,clipInfo:a,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:a,fadeGain:r}=e,s=r.gain._param;s.cancelScheduledValues(0);const o=n-a.offset;if(a.fadeIn&&o<a.fadeIn.duration){const l=a.fadeIn.duration;if(o<=0)rn(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-o,u=o/l,d=a.gain*u;rn(s,t,c,a.fadeIn.type||"linear",d,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-o;if(c>0){const u=t+c;on(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,d=a.fadeOut.duration-u,b=u/a.fadeOut.duration,h=a.gain*(1-b);on(s,t,d,a.fadeOut.type||"linear",h,0)}}}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;this.muteGain.gain._param.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 P.Player({url:a.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});r.connect(a.fadeGain),a.player=r,a.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(a=>{const{player:r,clipInfo:s}=a,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??P.now();if(a.playStartTime=u,o>=l){const d=o-l+s.offset,b=s.duration-(o-l),h=n?Math.min(n,b):b;a.pausedPosition=d,this.scheduleFades(a,u,d),r.start(u,d,h)}else{const d=l-o,b=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+d,s.offset),r.start(u+d,s.offset,b)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(P.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??P.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}},Xa=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 P.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,P.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 P.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new La(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??P.now(),r=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(r>=l){const c=r-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a,c,n)}else{const c=l-r;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a+c,0,n)}}),t!==void 0?P.getTransport().start(a,t):P.getTransport().start(a)}pause(){P.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){P.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 P.getTransport().seconds}seekTo(e){P.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return P.getContext()}get sampleRate(){return P.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}};const jt=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[jt.Translate.toString(e),jt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),Oa=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"}))]]),Ga=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"}))]]),Na=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"}))]]),Ya=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"}))]]),Ka=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),gt=T.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:b,weight:h="regular",mirrored:f=!1,...y}=T.useContext(Ka);return T.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??b,height:r??b,fill:a??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...y,...u},!!n&&T.createElement("title",null,n),l,c.get(s??h))});gt.displayName="IconBase";const Mn=T.forwardRef((e,t)=>T.createElement(gt,{ref:t,...e,weights:Oa}));Mn.displayName="DotsThreeIcon";const $n=T.forwardRef((e,t)=>T.createElement(gt,{ref:t,...e,weights:Ga}));$n.displayName="SpeakerHighIcon";const En=T.forwardRef((e,t)=>T.createElement(gt,{ref:t,...e,weights:Na}));En.displayName="SpeakerLowIcon";const Tn=T.forwardRef((e,t)=>T.createElement(gt,{ref:t,...e,weights:Ya}));Tn.displayName="XIcon";const Ua=Tn;D.span`
|
|
1
|
+
"use strict";var Ra=Object.create;var nn=Object.defineProperty;var _a=Object.getOwnPropertyDescriptor;var Ba=Object.getOwnPropertyNames;var Fa=Object.getPrototypeOf,Wa=Object.prototype.hasOwnProperty;var Pa=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ba(t))!Wa.call(e,r)&&r!==n&&nn(e,r,{get:()=>t[r],enumerable:!(a=_a(t,r))||a.enumerable});return e};var Za=(e,t,n)=>(n=e!=null?Ra(Fa(e)):{},Pa(t||!e||!e.__esModule?nn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("tone"),g=require("react/jsx-runtime"),i=require("react"),T=require("styled-components"),Ge=require("@dnd-kit/core"),kn=require("react-dom"),Va=require("@dnd-kit/modifiers");function Sn(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 An=Sn(P),E=Sn(i);function an(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 ja(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 Ha(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 za(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 In(e,t,n){switch(e){case"linear":return an(t,n);case"exponential":return ja(t,n);case"sCurve":return Ha(t,n);case"logarithmic":return za(t,n);default:return an(t,n)}}function rn(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=In(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 on(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=In(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 La=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new P.Volume(this.gainToDb(e.track.gain)),this.panNode=new P.Panner(e.track.stereoPan),this.muteGain=new P.Gain(e.track.muted?0:1);const t=e.destination||P.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 P.Player({url:a.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new P.Gain(a.gain);return r.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:r,clipInfo:a,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:a,fadeGain:r}=e,s=r.gain._param;s.cancelScheduledValues(0);const o=n-a.offset;if(a.fadeIn&&o<a.fadeIn.duration){const l=a.fadeIn.duration;if(o<=0)rn(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-o,u=o/l,d=a.gain*u;rn(s,t,c,a.fadeIn.type||"linear",d,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-o;if(c>0){const u=t+c;on(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,d=a.fadeOut.duration-u,b=u/a.fadeOut.duration,h=a.gain*(1-b);on(s,t,d,a.fadeOut.type||"linear",h,0)}}}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;this.muteGain.gain._param.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 P.Player({url:a.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});r.connect(a.fadeGain),a.player=r,a.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(a=>{const{player:r,clipInfo:s}=a,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??P.now();if(a.playStartTime=u,o>=l){const d=o-l+s.offset,b=s.duration-(o-l),h=n?Math.min(n,b):b;a.pausedPosition=d,this.scheduleFades(a,u,d),r.start(u,d,h)}else{const d=l-o,b=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+d,s.offset),r.start(u+d,s.offset,b)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(P.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??P.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}},Xa=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 P.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,P.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 P.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new La(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??P.now(),r=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(r>=l){const c=r-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a,c,n)}else{const c=l-r;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a+c,0,n)}}),t!==void 0?P.getTransport().start(a,t):P.getTransport().start(a)}pause(){P.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){P.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 P.getTransport().seconds}seekTo(e){P.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return P.getContext()}get sampleRate(){return P.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}};const jt=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[jt.Translate.toString(e),jt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),Oa=new Map([["bold",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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"}),E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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"}))]]),Ga=new Map([["bold",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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"}))]]),Na=new Map([["bold",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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"}))]]),Ya=new Map([["bold",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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"}),E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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",E.createElement(E.Fragment,null,E.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"}))]]),Ka=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),gt=E.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:b,weight:h="regular",mirrored:f=!1,...y}=E.useContext(Ka);return E.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??b,height:r??b,fill:a??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...y,...u},!!n&&E.createElement("title",null,n),l,c.get(s??h))});gt.displayName="IconBase";const Mn=E.forwardRef((e,t)=>E.createElement(gt,{ref:t,...e,weights:Oa}));Mn.displayName="DotsThreeIcon";const $n=E.forwardRef((e,t)=>E.createElement(gt,{ref:t,...e,weights:Ga}));$n.displayName="SpeakerHighIcon";const En=E.forwardRef((e,t)=>E.createElement(gt,{ref:t,...e,weights:Na}));En.displayName="SpeakerLowIcon";const Tn=E.forwardRef((e,t)=>E.createElement(gt,{ref:t,...e,weights:Ya}));Tn.displayName="XIcon";const Ua=Tn;T.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 Lt=
|
|
7
|
+
`;var Lt=T.button`
|
|
8
8
|
display: inline-flex;
|
|
9
9
|
align-items: center;
|
|
10
10
|
justify-content: center;
|
|
@@ -33,37 +33,37 @@
|
|
|
33
33
|
opacity: 0.6;
|
|
34
34
|
cursor: not-allowed;
|
|
35
35
|
}
|
|
36
|
-
`;
|
|
36
|
+
`;T(Lt)`
|
|
37
37
|
padding: 0.25rem 0.5rem;
|
|
38
38
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
39
|
-
`;
|
|
39
|
+
`;T(Lt)`
|
|
40
40
|
padding: 0.5rem;
|
|
41
41
|
min-width: 2.25rem;
|
|
42
42
|
min-height: 2.25rem;
|
|
43
|
-
`;
|
|
43
|
+
`;T(Lt)`
|
|
44
44
|
padding: 0.25rem;
|
|
45
45
|
min-width: 1.75rem;
|
|
46
46
|
min-height: 1.75rem;
|
|
47
47
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
48
|
-
`;var qa=
|
|
48
|
+
`;var qa=T.div`
|
|
49
49
|
display: inline-flex;
|
|
50
50
|
align-items: center;
|
|
51
51
|
gap: 0.5rem;
|
|
52
|
-
`,Ja=
|
|
52
|
+
`,Ja=T.input`
|
|
53
53
|
cursor: pointer;
|
|
54
54
|
accent-color: ${e=>e.theme.inputFocusBorder};
|
|
55
55
|
|
|
56
56
|
&:disabled {
|
|
57
57
|
cursor: not-allowed;
|
|
58
58
|
}
|
|
59
|
-
`,Qa=
|
|
59
|
+
`,Qa=T.label`
|
|
60
60
|
margin: 0;
|
|
61
61
|
cursor: pointer;
|
|
62
62
|
user-select: none;
|
|
63
63
|
font-family: ${e=>e.theme.fontFamily};
|
|
64
64
|
font-size: ${e=>e.theme.fontSize};
|
|
65
65
|
color: ${e=>e.theme.textColor};
|
|
66
|
-
`,
|
|
66
|
+
`,He=T.button`
|
|
67
67
|
padding: 0.5rem 1rem;
|
|
68
68
|
background: ${e=>e.theme.buttonBackground||"#007bff"};
|
|
69
69
|
color: ${e=>e.theme.buttonText||"white"};
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
cursor: not-allowed;
|
|
90
90
|
opacity: 0.6;
|
|
91
91
|
}
|
|
92
|
-
`,Dn=
|
|
92
|
+
`,Dn=T.input`
|
|
93
93
|
padding: 0.5rem 0.75rem;
|
|
94
94
|
font-family: ${e=>e.theme.fontFamily};
|
|
95
95
|
font-size: ${e=>e.theme.fontSize};
|
|
@@ -113,17 +113,17 @@
|
|
|
113
113
|
opacity: 0.6;
|
|
114
114
|
cursor: not-allowed;
|
|
115
115
|
}
|
|
116
|
-
`;
|
|
116
|
+
`;T(Dn)`
|
|
117
117
|
padding: 0.25rem 0.5rem;
|
|
118
118
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
119
|
-
`;var er=
|
|
119
|
+
`;var er=T.label`
|
|
120
120
|
font-family: ${e=>e.theme.fontFamily};
|
|
121
121
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
122
122
|
font-weight: 500;
|
|
123
123
|
color: ${e=>e.theme.textColorMuted};
|
|
124
124
|
margin-bottom: 0.25rem;
|
|
125
125
|
display: block;
|
|
126
|
-
`;
|
|
126
|
+
`;T.label`
|
|
127
127
|
font-family: ${e=>e.theme.fontFamily};
|
|
128
128
|
font-size: ${e=>e.theme.fontSize};
|
|
129
129
|
color: ${e=>e.theme.textColor};
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
align-items: center;
|
|
132
132
|
gap: 0.5rem;
|
|
133
133
|
cursor: pointer;
|
|
134
|
-
`;var tr=
|
|
134
|
+
`;var tr=T.span`
|
|
135
135
|
position: absolute;
|
|
136
136
|
width: 1px;
|
|
137
137
|
height: 1px;
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
clip: rect(0, 0, 0, 0);
|
|
142
142
|
white-space: nowrap;
|
|
143
143
|
border: 0;
|
|
144
|
-
`,Rn=
|
|
144
|
+
`,Rn=T.select`
|
|
145
145
|
padding: 0.5rem 2rem 0.5rem 0.75rem;
|
|
146
146
|
font-family: ${e=>e.theme.fontFamily};
|
|
147
147
|
font-size: ${e=>e.theme.fontSize};
|
|
@@ -172,10 +172,10 @@
|
|
|
172
172
|
color: ${e=>e.theme.inputText};
|
|
173
173
|
background-color: ${e=>e.theme.inputBackground};
|
|
174
174
|
}
|
|
175
|
-
`;
|
|
175
|
+
`;T(Rn)`
|
|
176
176
|
padding: 0.25rem 1.75rem 0.25rem 0.5rem;
|
|
177
177
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
178
|
-
`;var _n=
|
|
178
|
+
`;var _n=T.input.attrs({type:"range"})`
|
|
179
179
|
-webkit-appearance: none;
|
|
180
180
|
appearance: none;
|
|
181
181
|
width: 100%;
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
&:disabled::-moz-range-thumb {
|
|
252
252
|
cursor: not-allowed;
|
|
253
253
|
}
|
|
254
|
-
`,nr=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return
|
|
254
|
+
`,nr=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return g.jsxs(qa,{className:a,children:[g.jsx(Ja,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:r,disabled:n}),g.jsx(Qa,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function Bn(e){return typeof e=="object"&&e!==null&&"type"in e}function tt(e){if(!Bn(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 Fn={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"},ar=1e3;function rr(e,t,n,a){if(!Bn(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 or=T.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
255
255
|
float: left;
|
|
256
256
|
position: relative;
|
|
257
257
|
/* Promote to own compositing layer for smoother scrolling */
|
|
@@ -259,13 +259,13 @@
|
|
|
259
259
|
/* Disable image rendering interpolation */
|
|
260
260
|
image-rendering: pixelated;
|
|
261
261
|
image-rendering: crisp-edges;
|
|
262
|
-
`,sr=
|
|
262
|
+
`,sr=T.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
263
263
|
position: absolute;
|
|
264
264
|
background: ${e=>e.$waveFillColor};
|
|
265
265
|
/* Force GPU compositing layer to reduce scroll flickering */
|
|
266
266
|
transform: translateZ(0);
|
|
267
267
|
backface-visibility: hidden;
|
|
268
|
-
`,sn=e=>{const{data:t,bits:n,length:a,index:r,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:b=0,transparentBackground:h=!1,drawMode:f="inverted"}=e,y=i.useRef([]),x=i.useCallback(k=>{if(k!==null){const S=parseInt(k.dataset.index,10);y.current[S]=k}},[]);i.useLayoutEffect(()=>{const k=y.current,S=d+b;let $=0;for(let
|
|
268
|
+
`,sn=e=>{const{data:t,bits:n,length:a,index:r,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:b=0,transparentBackground:h=!1,drawMode:f="inverted"}=e,y=i.useRef([]),x=i.useCallback(k=>{if(k!==null){const S=parseInt(k.dataset.index,10);y.current[S]=k}},[]);i.useLayoutEffect(()=>{const k=y.current,S=d+b;let $=0;for(let M=0;M<k.length;M++){const D=k[M],I=D.getContext("2d"),A=Math.floor(l/2),B=2**(n-1);if(I){I.resetTransform(),I.clearRect(0,0,D.width,D.height),I.imageSmoothingEnabled=!1,I.scale(o,o);const _=D.width/o;let F;f==="normal"?F=u:F=c,I.fillStyle=rr(I,F,_,l);const O=$,G=$+_,j=Math.floor((O-d+S)/S)*S;for(let q=Math.max(0,j);q<G;q+=S){const N=q-O;if(N+d<=0)continue;const re=q;if(re*2+1<t.length){const J=t[re*2]/B,oe=t[re*2+1]/B,ie=Math.abs(J*A),de=Math.abs(oe*A);f==="normal"?I.fillRect(N,A-de,d,de+ie):(I.fillRect(N,0,d,A-de),I.fillRect(N,A+ie,d,A-ie))}}}$+=D.width/o}},[t,n,l,c,u,o,a,d,b,f]);let m=a,p=0;const w=[];for(;m>0;){const k=Math.min(m,ar),S=g.jsx(or,{$cssWidth:k,width:k*o,height:l*o,$waveHeight:l,"data-index":p,ref:x},`${a}-${p}`);w.push(S),m-=k,p+=1}const v=h?"transparent":tt(u);return g.jsx(sr,{$index:r,$cssWidth:a,className:s,$waveHeight:l,$waveFillColor:v,children:w})},Wn=22,Pn=T.div`
|
|
269
269
|
position: relative;
|
|
270
270
|
height: ${Wn}px;
|
|
271
271
|
background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
|
|
@@ -289,7 +289,7 @@
|
|
|
289
289
|
cursor: grabbing;
|
|
290
290
|
}
|
|
291
291
|
`}
|
|
292
|
-
`,Zn=
|
|
292
|
+
`,Zn=T.span`
|
|
293
293
|
font-size: 11px;
|
|
294
294
|
font-weight: 600;
|
|
295
295
|
font-family: ${e=>e.theme.clipHeaderFontFamily};
|
|
@@ -297,7 +297,7 @@
|
|
|
297
297
|
white-space: nowrap;
|
|
298
298
|
overflow: hidden;
|
|
299
299
|
text-overflow: ellipsis;
|
|
300
|
-
`,ir=({trackName:e,isSelected:t=!1})=>
|
|
300
|
+
`,ir=({trackName:e,isSelected:t=!1})=>g.jsx(Pn,{$isDragging:!1,$interactive:!1,$isSelected:t,children:g.jsx(Zn,{children:e})}),lr=({clipId:e,trackIndex:t,clipIndex:n,trackName:a,isSelected:r=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return g.jsx(ir,{trackName:a,isSelected:r});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return g.jsx(Pn,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:r,...c,...l,children:g.jsx(Zn,{children:a})})},cr=8,ur=24,dr=T.div`
|
|
301
301
|
position: absolute;
|
|
302
302
|
${e=>e.$edge==="left"?"left: 0;":"right: 0;"}
|
|
303
303
|
top: 0;
|
|
@@ -325,19 +325,19 @@
|
|
|
325
325
|
background: rgba(255, 255, 255, 0.4);
|
|
326
326
|
${e=>e.$edge==="left"?"border-left: 2px solid rgba(255, 255, 255, 0.8);":"border-right: 2px solid rgba(255, 255, 255, 0.8);"}
|
|
327
327
|
}
|
|
328
|
-
`,ln=({clipId:e,trackIndex:t,clipIndex:n,edge:a,dragHandleProps:r,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!r)return null;const{attributes:c,listeners:u,setActivatorNodeRef:d,isDragging:b}=r;return
|
|
328
|
+
`,ln=({clipId:e,trackIndex:t,clipIndex:n,edge:a,dragHandleProps:r,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!r)return null;const{attributes:c,listeners:u,setActivatorNodeRef:d,isDragging:b}=r;return g.jsx(dr,{ref:d,"data-clip-id":e,"data-boundary-edge":a,$edge:a,$isDragging:b,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},fr=T.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
329
329
|
position: absolute;
|
|
330
330
|
top: 0;
|
|
331
331
|
bottom: 0;
|
|
332
332
|
pointer-events: none;
|
|
333
333
|
z-index: 50;
|
|
334
|
-
`,mr=
|
|
334
|
+
`,mr=T.svg`
|
|
335
335
|
width: 100%;
|
|
336
336
|
height: 100%;
|
|
337
337
|
display: block;
|
|
338
338
|
/* Flip horizontally for fadeOut - makes it mirror of fadeIn */
|
|
339
339
|
transform: ${e=>e.$type==="fadeOut"?"scaleX(-1)":"none"};
|
|
340
|
-
`;function hr(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 cn=({left:e,width:t,type:n,curveType:a="logarithmic",color:r})=>{const s=
|
|
340
|
+
`;function hr(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 cn=({left:e,width:t,type:n,curveType:a="logarithmic",color:r})=>{const s=T.useTheme();if(t<1)return null;const o=r||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return g.jsx(fr,{$left:e,$width:t,$type:n,children:g.jsx(mr,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:g.jsx("path",{d:hr(t,100,a),fill:o})})})},pr=T.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
341
341
|
position: ${e=>e.$isOverlay?"relative":"absolute"};
|
|
342
342
|
top: 0;
|
|
343
343
|
height: ${e=>e.$isOverlay?"auto":"100%"};
|
|
@@ -351,20 +351,20 @@
|
|
|
351
351
|
&:hover {
|
|
352
352
|
background: rgba(255, 255, 255, 0.08);
|
|
353
353
|
}
|
|
354
|
-
`,gr=
|
|
354
|
+
`,gr=T.div`
|
|
355
355
|
flex: 1;
|
|
356
356
|
position: relative;
|
|
357
357
|
overflow: ${e=>e.$isOverlay?"visible":"hidden"};
|
|
358
|
-
`,Ht=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:d=!1,isOverlay:b=!1,isSelected:h=!1,onMouseDown:f,trackId:y,fadeIn:x,fadeOut:m,sampleRate:
|
|
358
|
+
`,Ht=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:d=!1,isOverlay:b=!1,isSelected:h=!1,onMouseDown:f,trackId:y,fadeIn:x,fadeOut:m,sampleRate:p=44100,showFades:w=!1,touchOptimized:C=!1})=>{const v=Math.floor(o/c),S=Math.floor((o+l)/c)-v,$=u&&!d&&!b,M=`clip-${a}-${r}`,{attributes:D,listeners:I,setNodeRef:A,setActivatorNodeRef:B,transform:_,isDragging:F}=Ge.useDraggable({id:M,data:{clipId:n,trackIndex:a,clipIndex:r},disabled:!$}),O=`clip-boundary-left-${a}-${r}`,{attributes:G,listeners:j,setActivatorNodeRef:q,isDragging:N}=Ge.useDraggable({id:O,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"left"},disabled:!$}),re=`clip-boundary-right-${a}-${r}`,{attributes:J,listeners:oe,setActivatorNodeRef:ie,isDragging:de}=Ge.useDraggable({id:re,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"right"},disabled:!$}),fe=_?{transform:jt.Translate.toString(_),zIndex:F?100:void 0}:void 0;return g.jsxs(pr,{ref:A,style:fe,className:t,$left:v,$width:S,$isOverlay:b,"data-clip-container":"true","data-track-id":y,onMouseDown:f,children:[u&&g.jsx(lr,{clipId:n,trackIndex:a,clipIndex:r,trackName:s,isSelected:h,disableDrag:d,dragHandleProps:$?{attributes:D,listeners:I,setActivatorNodeRef:B}:void 0}),g.jsxs(gr,{$isOverlay:b,children:[e,w&&x&&x.duration>0&&g.jsx(cn,{left:0,width:Math.floor(x.duration*p/c),type:"fadeIn",curveType:x.type}),w&&m&&m.duration>0&&g.jsx(cn,{left:S-Math.floor(m.duration*p/c),width:Math.floor(m.duration*p/c),type:"fadeOut",curveType:m.type})]}),u&&!d&&!b&&g.jsxs(g.Fragment,{children:[g.jsx(ln,{clipId:n,trackIndex:a,clipIndex:r,edge:"left",touchOptimized:C,dragHandleProps:{attributes:G,listeners:j,setActivatorNodeRef:q,isDragging:N}}),g.jsx(ln,{clipId:n,trackIndex:a,clipIndex:r,edge:"right",touchOptimized:C,dragHandleProps:{attributes:J,listeners:oe,setActivatorNodeRef:ie,isDragging:de}})]})]})},br=T.div`
|
|
359
359
|
display: inline-flex;
|
|
360
360
|
align-items: center;
|
|
361
361
|
gap: 0.5rem;
|
|
362
|
-
`,vr=
|
|
362
|
+
`,vr=T(er)`
|
|
363
363
|
margin: 0;
|
|
364
364
|
white-space: nowrap;
|
|
365
|
-
`,Cr=
|
|
365
|
+
`,Cr=T(_n)`
|
|
366
366
|
width: 120px;
|
|
367
|
-
`,yr=({volume:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(parseFloat(s.target.value)/100)};return
|
|
367
|
+
`,yr=({volume:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(parseFloat(s.target.value)/100)};return g.jsxs(br,{className:a,children:[g.jsx(vr,{htmlFor:"master-gain",children:"Master Volume"}),g.jsx(Cr,{min:"0",max:"100",value:e*100,onChange:r,disabled:n,id:"master-gain"})]})};T.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
|
|
368
368
|
position: absolute;
|
|
369
369
|
top: 0;
|
|
370
370
|
left: 0;
|
|
@@ -374,7 +374,7 @@
|
|
|
374
374
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
375
375
|
pointer-events: none;
|
|
376
376
|
will-change: transform;
|
|
377
|
-
`;
|
|
377
|
+
`;T.div`
|
|
378
378
|
position: absolute;
|
|
379
379
|
top: 0;
|
|
380
380
|
left: 0;
|
|
@@ -382,7 +382,7 @@
|
|
|
382
382
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
383
383
|
pointer-events: none;
|
|
384
384
|
will-change: transform;
|
|
385
|
-
`;
|
|
385
|
+
`;T.div`
|
|
386
386
|
position: absolute;
|
|
387
387
|
top: -10px;
|
|
388
388
|
left: -6px;
|
|
@@ -391,30 +391,30 @@
|
|
|
391
391
|
border-left: 7px solid transparent;
|
|
392
392
|
border-right: 7px solid transparent;
|
|
393
393
|
border-top: 10px solid ${e=>e.$color};
|
|
394
|
-
`;
|
|
394
|
+
`;T.div`
|
|
395
395
|
position: absolute;
|
|
396
396
|
top: 0;
|
|
397
397
|
left: 0;
|
|
398
398
|
width: 2px;
|
|
399
399
|
height: 100%;
|
|
400
400
|
background: ${e=>e.$color};
|
|
401
|
-
`;var xr=
|
|
401
|
+
`;var xr=T.div`
|
|
402
402
|
overflow-y: hidden;
|
|
403
403
|
overflow-x: auto;
|
|
404
404
|
position: relative;
|
|
405
|
-
`,wr=
|
|
405
|
+
`,wr=T.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
|
|
406
406
|
position: relative;
|
|
407
407
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
408
|
-
`,kr=
|
|
408
|
+
`,kr=T.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
|
|
409
409
|
background: ${e=>e.$backgroundColor||"white"};
|
|
410
410
|
width: 100%;
|
|
411
411
|
position: relative;
|
|
412
412
|
overflow: hidden; /* Constrain loop region to timescale area */
|
|
413
|
-
`,Sr=
|
|
413
|
+
`,Sr=T.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
|
|
414
414
|
position: relative;
|
|
415
415
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
416
416
|
width: 100%;
|
|
417
|
-
`,Ar=
|
|
417
|
+
`,Ar=T.div`
|
|
418
418
|
position: absolute;
|
|
419
419
|
top: 0;
|
|
420
420
|
left: 0;
|
|
@@ -423,7 +423,7 @@
|
|
|
423
423
|
cursor: crosshair;
|
|
424
424
|
/* When selecting, raise z-index above clip boundaries (z-index: 105) to prevent interference */
|
|
425
425
|
z-index: ${e=>e.$isSelecting?110:1};
|
|
426
|
-
`,Xt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:d,onTracksMouseUp:b,scrollContainerRef:h,isSelecting:f,"data-playlist-state":y})=>
|
|
426
|
+
`,Xt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:d,onTracksMouseUp:b,scrollContainerRef:h,isSelecting:f,"data-playlist-state":y})=>g.jsx(xr,{"data-scroll-container":"true","data-playlist-state":y,ref:h,children:g.jsxs(wr,{$backgroundColor:t,$width:o,children:[a&&g.jsx(kr,{$width:r,$backgroundColor:n,children:a}),g.jsxs(Sr,{$width:s,$backgroundColor:t,children:[e,(c||u)&&g.jsx(Ar,{$controlsWidth:l,$isSelecting:f,onClick:c,onMouseDown:u,onMouseMove:d,onMouseUp:b})]})]})});T.withTheme(Xt);var Ir=T.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
427
427
|
position: absolute;
|
|
428
428
|
top: 0;
|
|
429
429
|
background: ${e=>e.$color};
|
|
@@ -431,14 +431,14 @@
|
|
|
431
431
|
z-index: 60; /* Above clips (z-index: 10) and fades (z-index: 50), below playhead (z-index: 100) */
|
|
432
432
|
pointer-events: none;
|
|
433
433
|
opacity: 0.3;
|
|
434
|
-
`,Vn=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const a=Math.max(0,t-e);return a<=0?null:
|
|
434
|
+
`,Vn=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const a=Math.max(0,t-e);return a<=0?null:g.jsx(Ir,{$left:e,$width:a,$color:n,"data-selection":!0})};T.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
435
435
|
position: absolute;
|
|
436
436
|
top: 0;
|
|
437
437
|
background: ${e=>e.$color};
|
|
438
438
|
height: 100%;
|
|
439
439
|
z-index: 55; /* Between clips (z-index: 50) and selection (z-index: 60) */
|
|
440
440
|
pointer-events: none;
|
|
441
|
-
`;
|
|
441
|
+
`;T.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
|
|
442
442
|
position: absolute;
|
|
443
443
|
top: 0;
|
|
444
444
|
width: 2px;
|
|
@@ -458,7 +458,7 @@
|
|
|
458
458
|
border-top: 8px solid ${e=>e.$color};
|
|
459
459
|
${e=>e.$isStart?"border-right: 8px solid transparent;":"border-left: 8px solid transparent;"}
|
|
460
460
|
}
|
|
461
|
-
`;var un=
|
|
461
|
+
`;var un=T.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
|
|
462
462
|
position: absolute;
|
|
463
463
|
top: 0;
|
|
464
464
|
width: 12px;
|
|
@@ -495,7 +495,7 @@
|
|
|
495
495
|
&:hover::before {
|
|
496
496
|
opacity: 1;
|
|
497
497
|
}
|
|
498
|
-
`,Mr=
|
|
498
|
+
`,Mr=T.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
499
499
|
position: absolute;
|
|
500
500
|
top: 0;
|
|
501
501
|
height: 100%;
|
|
@@ -506,25 +506,25 @@
|
|
|
506
506
|
&:active {
|
|
507
507
|
cursor: grabbing;
|
|
508
508
|
}
|
|
509
|
-
`,$r=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),b=i.useRef(0),h=i.useRef(0),f=i.useRef(0),y=Math.max(0,t-e),x=i.useCallback((
|
|
509
|
+
`,$r=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),b=i.useRef(0),h=i.useRef(0),f=i.useRef(0),y=Math.max(0,t-e),x=i.useCallback((p,w)=>{p.preventDefault(),p.stopPropagation(),d(w),b.current=p.clientX,h.current=w==="start"?e:t;const C=k=>{const S=k.clientX-b.current,$=h.current+S;if(w==="start"){const M=Math.max(l,Math.min(t-10,$));r?.(M)}else{const M=Math.max(e+10,Math.min(c,$));s?.(M)}},v=()=>{d(null),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",v)},[e,t,l,c,r,s]),m=i.useCallback(p=>{p.preventDefault(),p.stopPropagation(),d("region"),b.current=p.clientX,h.current=e,f.current=t;const w=t-e,C=k=>{const S=k.clientX-b.current;let $=h.current+S,M=f.current+S;$<l&&($=l,M=l+w),M>c&&(M=c,$=c-w),o?.($,M)},v=()=>{d(null),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",v)},[e,t,l,c,o]);return y<=0?null:g.jsxs(g.Fragment,{children:[g.jsx(Mr,{$left:e,$width:y,$color:a,$isDragging:u==="region",onMouseDown:m,"data-loop-region-timescale":!0}),g.jsx(un,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:p=>x(p,"start"),"data-loop-marker-handle":"start"}),g.jsx(un,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:p=>x(p,"end"),"data-loop-marker-handle":"end"})]})},Er=T.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
|
|
510
510
|
position: absolute;
|
|
511
511
|
top: 0;
|
|
512
512
|
right: 0;
|
|
513
513
|
height: 100%; /* Stay within timescale bounds, don't extend into tracks */
|
|
514
514
|
cursor: crosshair;
|
|
515
515
|
z-index: 40; /* Below markers and shading */
|
|
516
|
-
`,Tr=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),b=i.useRef(null),h=t>e,f=i.useCallback(y=>{const x=y.target;if(x.closest("[data-loop-marker-handle]")||x.closest("[data-loop-region-timescale]"))return;y.preventDefault(),u(!0);const m=b.current?.getBoundingClientRect();if(!m)return;const
|
|
516
|
+
`,Tr=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),b=i.useRef(null),h=t>e,f=i.useCallback(y=>{const x=y.target;if(x.closest("[data-loop-marker-handle]")||x.closest("[data-loop-region-timescale]"))return;y.preventDefault(),u(!0);const m=b.current?.getBoundingClientRect();if(!m)return;const p=y.clientX-m.left,w=Math.max(s,Math.min(o,p));d.current=w,r?.(w,w);const C=k=>{const S=k.clientX-m.left,$=Math.max(s,Math.min(o,S)),M=Math.min(d.current,$),D=Math.max(d.current,$);r?.(M,D)},v=()=>{u(!1),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",v)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",v)},[s,o,r]);return g.jsx(Er,{ref:b,$leftOffset:l,onMouseDown:f,"data-timescale-loop-creator":!0,children:h&&g.jsx($r,{startPosition:e,endPosition:t,markerColor:n,regionColor:a,minPosition:s,maxPosition:o,onLoopStartChange:y=>r?.(y,t),onLoopEndChange:y=>r?.(e,y),onLoopRegionMove:(y,x)=>r?.(y,x)})})};function mt(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 ut(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return mt(e,0);case"hh:mm:ss.u":return mt(e,1);case"hh:mm:ss.uu":return mt(e,2);case"hh:mm:ss.uuu":return mt(e,3);default:return mt(e,3)}}function jn(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 dn=({id:e,label:t,value:n,format:a,className:r,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const h=ut(n,a);c(h)},[n,a,e]);const u=h=>{const f=h.target.value;c(f)},d=()=>{if(s){const h=jn(l,a);s(h)}c(ut(n,a))},b=h=>{h.key==="Enter"&&h.currentTarget.blur()};return g.jsxs(g.Fragment,{children:[g.jsx(tr,{as:"label",htmlFor:e,children:t}),g.jsx(Dn,{type:"text",className:r,id:e,value:l,onChange:u,onBlur:d,onKeyDown:b,readOnly:o})]})},Dr=({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 g.jsxs(g.Fragment,{children:[g.jsx(dn,{id:"audio_start",label:"Start of audio selection",value:e,format:r,className:"audio-start form-control mr-sm-2",onChange:o}),g.jsx(dn,{id:"audio_end",label:"End of audio selection",value:t,format:r,className:"audio-end form-control mr-sm-2",onChange:l})]})};function At(){return window.devicePixelRatio}var Hn=i.createContext(At()),zn=({children:e})=>{const[t,n]=i.useState(At());return matchMedia(`(resolution: ${At()}dppx)`).addEventListener("change",()=>{n(At())},{once:!0}),g.jsx(Hn.Provider,{value:Math.ceil(t),children:e})},Ot=()=>i.useContext(Hn),bt=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}),$t=()=>i.useContext(bt),vt=()=>i.useContext(T.ThemeContext),Gt=i.createContext(g.jsx(i.Fragment,{})),Rr=()=>i.useContext(Gt),_r=0,Br=!1,Fr=0,Wr=0,Pr={progress:_r,isPlaying:Br,selectionStart:Fr,selectionEnd:Wr};i.createContext(Pr);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var wt=1e3,Zr=T.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
517
517
|
position: absolute;
|
|
518
518
|
background: #000;
|
|
519
519
|
transform: translateZ(0);
|
|
520
520
|
backface-visibility: hidden;
|
|
521
|
-
`,Vr=
|
|
521
|
+
`,Vr=T.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
522
522
|
float: left;
|
|
523
523
|
position: relative;
|
|
524
524
|
will-change: transform;
|
|
525
525
|
image-rendering: pixelated;
|
|
526
526
|
image-rendering: crisp-edges;
|
|
527
|
-
`;function jr(){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 fn=({index:e,
|
|
527
|
+
`;function jr(){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 fn=({index:e,channelIndex:t,data:n,length:a,waveHeight:r,devicePixelRatio:s=1,samplesPerPixel:o,colorLUT:l,frequencyScaleFn:c,minFrequency:u=0,maxFrequency:d,workerApi:b,clipId:h,onCanvasesReady:f})=>{const y=t??e,x=i.useRef([]),m=i.useRef([]),p=i.useRef(new WeakSet),w=!!(b&&h),C=i.useCallback(I=>{if(I!==null){const A=parseInt(I.dataset.index,10);x.current[A]=I}},[]);i.useEffect(()=>{if(!w)return;const I=Math.ceil(a/wt);x.current.length=I;const A=x.current,B=[],_=[];for(let F=0;F<A.length;F++){const O=A[F];if(!O||p.current.has(O))continue;const G=`${h}-ch${y}-chunk${F}`;try{const j=O.transferControlToOffscreen();b.registerCanvas(G,j),p.current.add(O),B.push(G),_.push(Math.min(a-F*wt,wt))}catch(j){console.warn(`[spectrogram] transferControlToOffscreen failed for ${G}:`,j);continue}}return m.current=B,B.length>0&&f&&f(B,_),()=>{for(const F of m.current)b.unregisterCanvas(F);m.current=[]}},[w,h,y,a]);const v=l??jr(),k=d??(n?n.sampleRate/2:22050),S=c??((I,A,B)=>(I-A)/(B-A));i.useLayoutEffect(()=>{if(w||!n)return;const I=x.current,{frequencyBinCount:A,frameCount:B,hopSize:_,sampleRate:F,gainDb:O,rangeDb:G}=n,j=G===0?1:G;let q=0;const N=re=>re/A*(F/2);for(let re=0;re<I.length;re++){const J=I[re];if(!J)continue;const oe=J.getContext("2d");if(!oe)continue;const ie=J.width/s,de=r;oe.resetTransform(),oe.clearRect(0,0,J.width,J.height),oe.imageSmoothingEnabled=!1,oe.scale(s,s);const fe=oe.createImageData(ie,de),$e=fe.data;for(let le=0;le<ie;le++){const ue=(q+le)*o,Y=Math.floor(ue/_);if(Y<0||Y>=B)continue;const U=Y*A;for(let se=0;se<de;se++){const ge=1-se/de;let Q=Math.floor(ge*A);if(c){let ee=0,Xe=A-1;for(;ee<Xe;){const W=ee+Xe>>1,he=N(W);S(he,u,k)<ge?ee=W+1:Xe=W}Q=ee}if(Q<0||Q>=A)continue;const Be=n.data[U+Q],ze=Math.max(0,Math.min(1,(Be+j+O)/j)),Ne=Math.floor(ze*255),Le=(se*ie+le)*4;$e[Le]=v[Ne*3],$e[Le+1]=v[Ne*3+1],$e[Le+2]=v[Ne*3+2],$e[Le+3]=255}}if(oe.resetTransform(),oe.putImageData(fe,0,0),s!==1){const le=document.createElement("canvas");le.width=ie,le.height=de;const V=le.getContext("2d");if(!V)continue;V.putImageData(fe,0,0),oe.clearRect(0,0,J.width,J.height),oe.imageSmoothingEnabled=!1,oe.drawImage(le,0,0,J.width,J.height)}q+=ie}},[w,n,a,r,s,o,v,c,u,k,S]);let $=a,M=0;const D=[];for(;$>0;){const I=Math.min($,wt);D.push(g.jsx(Vr,{$cssWidth:I,width:I*s,height:r*s,$waveHeight:r,"data-index":M,ref:C},`${a}-${M}`)),$-=I,M++}return g.jsx(Zr,{$index:e,$cssWidth:a,$waveHeight:r,children:D})},Ln=({isSelected:e,transparentBackground:t,renderMode:n="waveform",spectrogramData:a,spectrogramColorLUT:r,samplesPerPixel:s,spectrogramFrequencyScaleFn:o,spectrogramMinFrequency:l,spectrogramMaxFrequency:c,spectrogramWorkerApi:u,spectrogramClipId:d,spectrogramOnCanvasesReady:b,...h})=>{const f=vt(),{waveHeight:y,barWidth:x,barGap:m,samplesPerPixel:p}=$t(),w=Ot(),C=s??p,v=e&&f?f.selectedWaveOutlineColor:f?.waveOutlineColor,k=e&&f?f.selectedWaveFillColor:f?.waveFillColor,S=f?.waveformDrawMode||"inverted",$=a||u;if(n==="spectrogram"&&$)return g.jsx(fn,{index:h.index,data:a,length:h.length,waveHeight:y,devicePixelRatio:w,samplesPerPixel:C,colorLUT:r,frequencyScaleFn:o,minFrequency:l,maxFrequency:c,workerApi:u,clipId:d,onCanvasesReady:b});if(n==="both"&&$){const M=Math.floor(y/2);return g.jsxs(g.Fragment,{children:[g.jsx(fn,{index:h.index*2,channelIndex:h.index,data:a,length:h.length,waveHeight:M,devicePixelRatio:w,samplesPerPixel:C,colorLUT:r,frequencyScaleFn:o,minFrequency:l,maxFrequency:c,workerApi:u,clipId:d,onCanvasesReady:b}),g.jsx("div",{style:{position:"absolute",top:(h.index*2+1)*M,width:h.length,height:M},children:g.jsx(sn,{...h,...f,index:0,waveOutlineColor:v,waveFillColor:k,waveHeight:M,devicePixelRatio:w,barWidth:x,barGap:m,transparentBackground:t,drawMode:S})})]})}return g.jsx(sn,{...h,...f,waveOutlineColor:v,waveFillColor:k,waveHeight:y,devicePixelRatio:w,barWidth:x,barGap:m,transparentBackground:t,drawMode:S})},mn=72,Hr=T.div`
|
|
528
528
|
position: sticky;
|
|
529
529
|
left: 0;
|
|
530
530
|
z-index: 101;
|
|
@@ -532,34 +532,34 @@
|
|
|
532
532
|
height: 0;
|
|
533
533
|
width: 0;
|
|
534
534
|
overflow: visible;
|
|
535
|
-
`;function zr(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 Lr=({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),d=Ot(),b=l==="both"?Math.floor(e/2):e,h=t*e,f=c?22:0;return i.useLayoutEffect(()=>{const y=u.current;if(!y)return;const x=y.getContext("2d");if(!x)return;x.resetTransform(),x.clearRect(0,0,y.width,y.height),x.scale(d,d);const m=zr(a,r,b);for(let
|
|
535
|
+
`;function zr(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 Lr=({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),d=Ot(),b=l==="both"?Math.floor(e/2):e,h=t*e,f=c?22:0;return i.useLayoutEffect(()=>{const y=u.current;if(!y)return;const x=y.getContext("2d");if(!x)return;x.resetTransform(),x.clearRect(0,0,y.width,y.height),x.scale(d,d);const m=zr(a,r,b);for(let p=0;p<t;p++){const w=p*e+f;x.font="11px monospace",x.textBaseline="middle";for(const C of m){const v=n(C,a,r);if(v<0||v>1)continue;const k=w+b*(1-v),S=C>=1e3?`${(C/1e3).toFixed(1)}k`:`${C} Hz`,$=x.measureText(S),M=3;x.fillStyle=o,x.fillRect(0,k-7,$.width+M*2,14),x.fillStyle=s,x.fillText(S,M,k)}}},[e,t,n,a,r,s,o,d,b,f]),g.jsx(Hr,{$height:h+f,children:g.jsx("canvas",{ref:u,width:mn*d,height:(h+f)*d,style:{width:mn,height:h+f,pointerEvents:"none"}})})};function Xr(e,t,n){return Math.ceil(e*n/t)}function Or(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var Gr=T.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
|
|
536
536
|
position: relative;
|
|
537
537
|
overflow: visible; /* Allow time labels to render above the container */
|
|
538
538
|
border-bottom: 1px solid ${e=>e.theme.timeColor};
|
|
539
539
|
box-sizing: border-box;
|
|
540
|
-
`,Nr=
|
|
540
|
+
`,Nr=T.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
|
|
541
541
|
position: absolute;
|
|
542
542
|
left: 0;
|
|
543
543
|
right: 0;
|
|
544
544
|
bottom: 0;
|
|
545
|
-
`,Yr=
|
|
545
|
+
`,Yr=T.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
|
|
546
546
|
position: absolute;
|
|
547
547
|
font-size: 0.75rem; /* Smaller font to prevent overflow */
|
|
548
548
|
white-space: nowrap; /* Prevent text wrapping */
|
|
549
549
|
color: ${e=>e.theme.timeColor}; /* Use theme color instead of inheriting */
|
|
550
|
-
`,Kr=e=>{const{theme:{timeColor:t},duration:n,marker:a,bigStep:r,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:d,samplesPerPixel:b,timeScaleHeight:h,controls:{show:f,width:y}}=i.useContext(bt),x=Ot();i.useEffect(()=>{if(u.current!==null){const C=u.current,v=C.getContext("2d");if(v){v.resetTransform(),v.clearRect(0,0,C.width,C.height),v.imageSmoothingEnabled=!1,v.fillStyle=t,v.scale(x,x);for(const[k,S]of l.entries()){const $=h-S;v.fillRect(k,$,1,S)}}}},[n,x,t,h,r,s,a,l]);const m=Xr(n/1e3,b,d),
|
|
550
|
+
`,Kr=e=>{const{theme:{timeColor:t},duration:n,marker:a,bigStep:r,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:d,samplesPerPixel:b,timeScaleHeight:h,controls:{show:f,width:y}}=i.useContext(bt),x=Ot();i.useEffect(()=>{if(u.current!==null){const C=u.current,v=C.getContext("2d");if(v){v.resetTransform(),v.clearRect(0,0,C.width,C.height),v.imageSmoothingEnabled=!1,v.fillStyle=t,v.scale(x,x);for(const[k,S]of l.entries()){const $=h-S;v.fillRect(k,$,1,S)}}}},[n,x,t,h,r,s,a,l]);const m=Xr(n/1e3,b,d),p=d/b;let w=0;for(let C=0;C<m;C+=p*s/1e3){const v=Math.floor(C);if(w%a===0){const k=w,S=Or(k),$=o?g.jsx(i.Fragment,{children:o(k,v)},`timestamp-${w}`):g.jsx(Yr,{$left:v,children:S},S);c.push($),l.set(v,h)}else w%r===0?l.set(v,Math.floor(h/2)):w%s===0&&l.set(v,Math.floor(h/5));w+=s}return g.jsxs(Gr,{$cssWidth:m,$controlWidth:f?y:0,$timeScaleHeight:h,children:[c,g.jsx(Nr,{$cssWidth:m,$timeScaleHeight:h,width:m*x,height:h*x,ref:u})]})},Ur=T.withTheme(Kr),hn=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 qr(e){const t=hn.keys();let n;for(const a of t)if(e<a){n=hn.get(a);break}return n===void 0&&(n={marker:3e4,bigStep:1e4,smallStep:5e3}),n}var Xn=({renderTimestamp:e})=>{const{samplesPerPixel:t,duration:n}=i.useContext(bt);let a=qr(t);return g.jsx(Ur,{marker:a.marker,bigStep:a.bigStep,secondStep:a.smallStep,duration:n,renderTimestamp:e})},Jr=T.div`
|
|
551
551
|
display: inline-flex;
|
|
552
552
|
align-items: center;
|
|
553
553
|
gap: 0.5rem;
|
|
554
|
-
`,Qr=[{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"}],eo=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return
|
|
554
|
+
`,Qr=[{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"}],eo=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return g.jsx(Jr,{className:a,children:g.jsx(Rn,{className:"time-format",value:e,onChange:r,disabled:n,"aria-label":"Time format selection",children:Qr.map(s=>g.jsx("option",{value:s.value,children:s.label},s.value))})})},to=T.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?Wn:0)}px`}}))`
|
|
555
555
|
position: relative;
|
|
556
556
|
display: flex;
|
|
557
557
|
${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
|
|
558
|
-
`,no=
|
|
558
|
+
`,no=T.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
|
|
559
559
|
position: relative;
|
|
560
560
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
561
561
|
flex: 1;
|
|
562
|
-
`,ao=
|
|
562
|
+
`,ao=T.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
|
|
563
563
|
position: sticky;
|
|
564
564
|
z-index: 102; /* Above waveform content and spectrogram labels (101), below Docusaurus navbar (200) */
|
|
565
565
|
left: 0;
|
|
@@ -573,7 +573,7 @@
|
|
|
573
573
|
${e=>e.$isSelected&&`
|
|
574
574
|
background: ${e.theme.selectedTrackControlsBackground};
|
|
575
575
|
`}
|
|
576
|
-
`,On=({numChannels:e,children:t,className:n,backgroundColor:a,offset:r=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:d,controls:{show:b,width:h}}=$t(),f=Rr();return
|
|
576
|
+
`,On=({numChannels:e,children:t,className:n,backgroundColor:a,offset:r=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:d,controls:{show:b,width:h}}=$t(),f=Rr();return g.jsxs(to,{$numChannels:e,className:n,$waveHeight:d,$controlWidth:b?h:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[g.jsx(ao,{$controlWidth:b?h:0,$isSelected:u,children:f}),g.jsx(no,{$controlWidth:b?h:0,$backgroundColor:a,$offset:r,onClick:l,"data-track-id":c,children:t})]})},pn=T.button.attrs({type:"button"})`
|
|
577
577
|
display: inline-block;
|
|
578
578
|
font-family: ${e=>e.theme.fontFamily};
|
|
579
579
|
font-weight: 500;
|
|
@@ -632,7 +632,7 @@
|
|
|
632
632
|
box-shadow: 0 0 0 0.2rem ${e.theme.inputFocusBorder}33;
|
|
633
633
|
}
|
|
634
634
|
`}
|
|
635
|
-
`,ro=
|
|
635
|
+
`,ro=T.div`
|
|
636
636
|
margin-bottom: 0.3rem;
|
|
637
637
|
|
|
638
638
|
button:not(:first-child) {
|
|
@@ -644,7 +644,7 @@
|
|
|
644
644
|
border-top-right-radius: 0;
|
|
645
645
|
border-bottom-right-radius: 0;
|
|
646
646
|
}
|
|
647
|
-
`,oo=
|
|
647
|
+
`,oo=T.button`
|
|
648
648
|
position: absolute;
|
|
649
649
|
left: 0;
|
|
650
650
|
top: 0;
|
|
@@ -664,7 +664,7 @@
|
|
|
664
664
|
opacity: 1;
|
|
665
665
|
color: #dc3545;
|
|
666
666
|
}
|
|
667
|
-
`,so=({onClick:e,title:t="Remove track"})=>
|
|
667
|
+
`,so=({onClick:e,title:t="Remove track"})=>g.jsx(oo,{onClick:e,title:t,children:g.jsx(Ua,{size:12,weight:"bold"})}),io=T.div`
|
|
668
668
|
background: transparent;
|
|
669
669
|
width: 100%;
|
|
670
670
|
height: 100%;
|
|
@@ -677,7 +677,7 @@
|
|
|
677
677
|
text-align: center;
|
|
678
678
|
border: 1px solid ${e=>e.theme.borderColor};
|
|
679
679
|
border-radius: ${e=>e.theme.borderRadius};
|
|
680
|
-
`,lo=
|
|
680
|
+
`,lo=T.header`
|
|
681
681
|
overflow: hidden;
|
|
682
682
|
height: 26px;
|
|
683
683
|
width: 100%;
|
|
@@ -688,7 +688,7 @@
|
|
|
688
688
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
689
689
|
color: ${e=>e.theme.textColor};
|
|
690
690
|
background-color: transparent;
|
|
691
|
-
`,co=e=>
|
|
691
|
+
`,co=e=>g.jsx(En,{weight:"light",...e}),uo=e=>g.jsx($n,{weight:"light",...e}),fo=e=>g.jsx(Mn,{weight:"bold",...e}),gn=T(_n)`
|
|
692
692
|
width: 75%;
|
|
693
693
|
height: 5px;
|
|
694
694
|
background: ${e=>e.theme.sliderTrackColor};
|
|
@@ -737,7 +737,7 @@
|
|
|
737
737
|
&:focus::-moz-range-thumb {
|
|
738
738
|
border: 2px solid ${e=>e.theme.textColor};
|
|
739
739
|
}
|
|
740
|
-
`,bn=
|
|
740
|
+
`,bn=T.label`
|
|
741
741
|
width: 100%;
|
|
742
742
|
display: flex;
|
|
743
743
|
justify-content: space-between;
|
|
@@ -745,10 +745,10 @@
|
|
|
745
745
|
padding: 0 1rem;
|
|
746
746
|
margin-bottom: 0.2rem;
|
|
747
747
|
font-size: 14px;
|
|
748
|
-
`,mo=
|
|
748
|
+
`,mo=T.div`
|
|
749
749
|
position: relative;
|
|
750
750
|
display: inline-block;
|
|
751
|
-
`,ho=
|
|
751
|
+
`,ho=T.button`
|
|
752
752
|
background: none;
|
|
753
753
|
border: none;
|
|
754
754
|
cursor: pointer;
|
|
@@ -762,7 +762,7 @@
|
|
|
762
762
|
&:hover {
|
|
763
763
|
opacity: 1;
|
|
764
764
|
}
|
|
765
|
-
`,po=
|
|
765
|
+
`,po=T.div`
|
|
766
766
|
position: fixed;
|
|
767
767
|
top: ${e=>e.$top}px;
|
|
768
768
|
left: ${e=>e.$left}px;
|
|
@@ -774,18 +774,18 @@
|
|
|
774
774
|
padding: 0.5rem 0;
|
|
775
775
|
min-width: 180px;
|
|
776
776
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
777
|
-
`,go=
|
|
777
|
+
`,go=T.hr`
|
|
778
778
|
border: none;
|
|
779
779
|
border-top: 1px solid rgba(128, 128, 128, 0.3);
|
|
780
780
|
margin: 0.35rem 0;
|
|
781
|
-
`,bo=({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=d=>{const b=d.target;l.current&&!l.current.contains(b)&&c.current&&!c.current.contains(b)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[t]),
|
|
782
|
-
`,10)+1,s=a.substring(r)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function _o(e,t,n){var a;return function(s){return a=a||Ro(e),new Worker(a,s)}}var Bo=_o("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function He(e){if($o(e)&&(e=To(e)),Eo(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new ot(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var ht={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function Fo(e){var t={scale:e.scale||ht.scale,bits:e.bits||ht.bits,amplitude_scale:e.amplitude_scale||ht.amplitude_scale,split_channels:e.split_channels||ht.split_channels,disable_worker:e.disable_worker||ht.disable_worker};return t}function Wo(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Nn(e,t,n){var a=Wo(e);if(t.disable_worker){var r=Mo({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 He(r),e)}else{var s=new Bo;s.onmessage=function(o){n(void 0,new He(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 Po(e,t,n,a){function r(o){o||(o=new DOMException("EncodingError")),a(o),a=function(){}}var s=e.decodeAudioData(t,function(o){Nn(o,n,a)},r);s&&s.catch(r)}He.create=function(t){return new He(t)};He.createFromAudio=function(e,t){var n=Fo(e);if(e.audio_context&&e.array_buffer)return Po(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Nn(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Et(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 He(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}Et.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Et.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};Et.prototype.getOutputData=function(){return this._output_data};He.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!ct(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!ct(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 Et(t);!n.next(););return new He(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 He.create(a)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,a=n,r=0,s=[this].concat(t).map(function(g){return g._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),d=new DataView(s[0]),b=new DataView(u),h=0;h<n;h++)b.setUint8(h,d.getUint8(h));b.setInt32(16,r,!0);for(var f=0,y=new Uint8Array(u,n),x=0;x<s.length;x++){var m=s[x];y.set(new Uint8Array(m,n),f),f+=m.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!ct(t.startIndex)&&!ct(t.endIndex)?(n=t.startIndex,a=t.endIndex):!ct(t.startTime)&&!ct(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,s=24,o=this.bits===8?1:2,l=s+r*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var d=0;d<r*this.channels*2;d++){var b=this._at(n*this.channels*2+d);this.bits===8?u.setInt8(s+d,b):u.setInt16(s+d*2,b,!0)}return new He(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 Nt(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 He.create(a)}else{const a=await t.json();return He.create(a)}}function Yn(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 Zo(e,t=0){const n=await Nt(e);return Yn(n,t)}async function Vo(e){const t=await Nt(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Kn(e,t,n=0,a,r){let s=e;if(a!==void 0&&r!==void 0){const h=e.scale,f=Math.floor(a/h),y=Math.ceil((a+r)/h);s=s.slice({startIndex:f,endIndex:y})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),d=c.length,b=l===8?new Int8Array(d*2):new Int16Array(d*2);for(let h=0;h<d;h++)b[h*2]=c[h],b[h*2+1]=u[h];return{data:b,bits:l,length:d}}function Un(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>ut(r,e),parseTime:r=>jn(r,e)}}const jo=[256,512,1024,2048,4096,8192];function qn({initialSamplesPerPixel:e,zoomLevels:t=jo}){const[n,a]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),r=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{a(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{a(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:r,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function Jn({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[a,r]=i.useState(t),s=i.useCallback(o=>{r(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:a,setMasterVolume:s}}const Ho=(e=256)=>{const t=i.useRef(null),n=i.useCallback((a,r,s)=>{const o=new P.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 zt(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,b=t?.length??e.sourceDurationSamples??(u&&d?Math.ceil(u.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(b===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const h=e.durationSamples??b;return{id:Qn(),audioBuffer:t,startSample:n,durationSamples:h,offsetSamples:a,sampleRate:d,sourceDurationSamples:b,gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function zo(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const b=t?.duration??e.sourceDuration??u?.duration;if(b===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const h=e.duration??b;return zt({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(h*d),offsetSamples:Math.round(a*d),sampleRate:d,sourceDurationSamples:Math.ceil(b*d),gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Lo(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Qn(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:o,color:l,height:c}}function Qn(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Xo(e,t={}){const{progressive:n=!1}=t,[a,r]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),b=e.length;return i.useEffect(()=>{if(e.length===0){r([]),o(!1),d(0);return}let h=!1;const f=new Map,y=(m,g,w)=>{const C=w??m.audioBuffer;if(!C&&!m.waveformData)throw new Error(`Track ${g+1}: Must provide src, audioBuffer, or waveformData`);const v=C?.duration??m.waveformData?.duration,k=zo({audioBuffer:C,startTime:m.startTime??0,duration:m.duration??v,offset:m.offset??0,name:m.name||`Track ${g+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(k.startSample)||isNaN(k.durationSamples)||isNaN(k.offsetSamples))throw console.error("Invalid clip values:",k),new Error(`Invalid clip values for track ${g+1}`);return{...Lo({name:m.name||`Track ${g+1}`,clips:[k],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),d(0);const m=An.getContext().rawContext,g=e.map(async(C,v)=>{if(C.audioBuffer){const E=y(C,v,C.audioBuffer);return n&&!h&&(f.set(v,E),d(M=>M+1),r(Array.from({length:e.length},(M,I)=>f.get(I)).filter(M=>M!==void 0))),E}if(!C.src&&C.waveformData){const E=y(C,v);return n&&!h&&(f.set(v,E),d(M=>M+1),r(Array.from({length:e.length},(M,I)=>f.get(I)).filter(M=>M!==void 0))),E}if(!C.src)throw new Error(`Track ${v+1}: Must provide src, audioBuffer, or waveformData`);const k=await fetch(C.src);if(!k.ok)throw new Error(`Failed to fetch ${C.src}: ${k.statusText}`);const S=await k.arrayBuffer(),$=await m.decodeAudioData(S);if(!$||!$.sampleRate||!$.duration)throw new Error(`Invalid audio buffer for ${C.src}`);const A=y(C,v,$);return n&&!h&&(f.set(v,A),d(E=>E+1),r(Array.from({length:e.length},(E,M)=>f.get(M)).filter(E=>E!==void 0))),A}),w=await Promise.all(g);h||(n||(r(w),d(w.length)),o(!1))}catch(m){if(!h){const g=m instanceof Error?m.message:"Unknown error loading audio";c(g),o(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{h=!0}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:b}}function Oo({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=i.useRef(null),s=i.useCallback(u=>{const{transform:d,active:b}=u;if(!b?.data?.current)return{...d,scaleX:1,scaleY:1};const{trackIndex:h,clipIndex:f,boundary:y}=b.data.current;if(y)return{...d,scaleX:1,scaleY:1};const x=e[h];if(!x)return{...d,scaleX:1,scaleY:1};const m=x.clips[f];if(!m)return{...d,scaleX:1,scaleY:1};const g=m.startSample/a,w=m.durationSamples/a,C=d.x*n/a;let v=g+C;const k=[...x.clips].sort((I,B)=>I.startSample-B.startSample),S=k.findIndex(I=>I===m);v=Math.max(0,v);const $=S>0?k[S-1]:null;if($){const I=($.startSample+$.durationSamples)/a;v=Math.max(v,I)}const A=S<k.length-1?k[S+1]:null;if(A){const I=v+w,B=A.startSample/a;I>B&&(v=B-w)}const M=(v-g)*a/n;return{...d,x:M,scaleX:1,scaleY:1}},[e,n,a]),o=i.useCallback(u=>{const{active:d}=u,{boundary:b}=d.data.current;if(!b){r.current=null;return}const{trackIndex:h,clipIndex:f}=d.data.current,x=e[h]?.clips[f];x&&(r.current={offsetSamples:x.offsetSamples,durationSamples:x.durationSamples,startSample:x.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:b}=u,{boundary:h}=d.data.current;if(!h||!r.current)return;const{trackIndex:f,clipIndex:y}=d.data.current,x=b.x*n,m=Math.floor(.1*a),g=r.current,w=e.map((C,v)=>{if(v!==f)return C;const k=[...C.clips].sort((A,E)=>A.startSample-E.startSample),S=k.findIndex(A=>A===C.clips[y]),$=C.clips.map((A,E)=>{if(E!==y)return A;const M=A.sourceDurationSamples;if(h==="left"){let I=Math.floor(x);const B=-g.startSample;I<B&&(I=B);const _=-g.offsetSamples;I<_&&(I=_);const F=S>0?k[S-1]:null;if(F){const J=F.startSample+F.durationSamples-g.startSample;I<J&&(I=J)}const N=g.durationSamples-m;I>N&&(I=N);const q=g.offsetSamples+I,X=g.durationSamples-I,K=g.startSample+I;return{...A,offsetSamples:q,durationSamples:X,startSample:K}}else{let I=Math.floor(g.durationSamples+x);I=Math.max(m,I),g.offsetSamples+I>M&&(I=M-g.offsetSamples);const B=S<k.length-1?k[S+1]:null;return B&&g.startSample+I>B.startSample&&(I=B.startSample-g.startSample,I=Math.max(m,I)),{...A,durationSamples:I}}});return{...C,clips:$}});t(w)},[e,t,n,a]),c=i.useCallback(u=>{const{active:d,delta:b}=u,{trackIndex:h,clipIndex:f,boundary:y}=d.data.current,x=b.x*n;if(y){r.current=null;return}const m=e.map((g,w)=>{if(w!==h)return g;const C=[...g.clips].sort((S,$)=>S.startSample-$.startSample),v=C.findIndex(S=>S===g.clips[f]),k=g.clips.map((S,$)=>{if($!==f)return S;let A=Math.floor(S.startSample+x);A=Math.max(0,A);const E=v>0?C[v-1]:null;if(E){const I=E.startSample+E.durationSamples;A=Math.max(A,I)}const M=v<C.length-1?C[v+1]:null;return M&&A+S.durationSamples>M.startSample&&(A=M.startSample-S.durationSamples),{...S,startSample:A}});return{...g,clips:k}});t(m)},[e,t,n,a]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Pt=.01;function ea({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:b}=d,h=b.data.current;if(!h||h.annotationIndex===void 0){o.current=null;return}const f=e[h.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:h.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:b,delta:h}=d;if(!o.current)return;const f=b.data.current;if(!f)return;const{edge:y,annotationIndex:x}=f,m=o.current,g=h.x*n/a,w=y==="start"?m.start+g:m.end+g,C=Go({annotationIndex:x,newTime:w,isDraggingStart:y==="start",annotations:e,duration:r,linkEndpoints:s});t(C)},[e,t,n,a,r,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Go({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const o=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<Pt?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<Pt){const b=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,b)};let h=e+1;for(;h<o.length-1;){const f=o[h],y=o[h+1];if(Math.abs(y.start-f.end)<Pt){const x=f.end-a[h].end;o[h+1]={...y,start:Math.min(y.end-.1,y.start+x)},h++}else break}}else c>=d.start&&(o[e]={...o[e],end:d.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const d=o[e+1];o[e+1]={...d,start:c};let b=e+1;for(;b<o.length-1;){const h=o[b],f=o[b+1];if(h.end>f.start)o[b+1]={...f,start:h.end},b++;else break}}}return o}function No(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 Yo=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Be(),{selectedTrackId:s}=Fe(),o=i.useCallback((c,u,d)=>{const{sampleRate:b,samplesPerPixel:h}=e,f=t[c];if(!f)return!1;const y=f.clips[u];if(!y)return!1;const x=y.startSample/b,m=(y.startSample+y.durationSamples)/b;if(d<=x||d>=m)return console.warn("Split time is outside clip bounds"),!1;const g=Math.round(d*b),w=Math.floor(g/h),C=y.startSample+y.durationSamples,v=w*h,k=y.startSample,S=v-k,$=v,A=C-$,E=v-y.startSample,M=zt({audioBuffer:y.audioBuffer,startSample:k,durationSamples:S,offsetSamples:y.offsetSamples,sampleRate:y.sampleRate,sourceDurationSamples:y.sourceDurationSamples,gain:y.gain,name:y.name?`${y.name} (1)`:void 0,color:y.color,fadeIn:y.fadeIn,waveformData:y.waveformData}),I=zt({audioBuffer:y.audioBuffer,startSample:$,durationSamples:A,offsetSamples:y.offsetSamples+E,sampleRate:y.sampleRate,sourceDurationSamples:y.sourceDurationSamples,gain:y.gain,name:y.name?`${y.name} (2)`:void 0,color:y.color,waveformData:y.waveformData,fadeOut:y.fadeOut}),B=[...f.clips];B.splice(u,1,M,I);const _=[...t];return _[c]={...f,clips:B},n(_),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(b=>b.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],d=r.current??0;for(let b=0;b<u.clips.length;b++){const h=u.clips[b],f=h.startSample/a,y=(h.startSample+h.durationSamples)/a;if(d>f&&d<y)return console.log(`Splitting clip on track "${u.name}" at ${d}s`),o(c,b,d)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,o,a]),splitClipAt:o}},Mt=e=>{const{shortcuts:t,enabled:n=!0}=e,a=i.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||r.shiftKey===l.shiftKey,b=l.metaKey===void 0||r.metaKey===l.metaKey,h=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&d&&b&&h});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])},Ko=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("+")},Uo=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Be(),{setCurrentTime:s,play:o,pause:l,stop:c}=me(),{playoutRef:u}=Me(),d=i.useCallback(()=>{r?l():o()},[r,o,l]),b=i.useCallback(()=>{c()},[c]),h=i.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[r,u,s,o]),y=a??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:b,description:"Stop",preventDefault:!0},{key:"0",action:h,description:"Rewind to start",preventDefault:!0}],...n];return Mt({shortcuts:y,enabled:t}),{rewindToStart:h,togglePlayPause:d,stopPlayback:b,shortcuts:y}},Zt=.01,kt=.01;function qo({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:b=0,onPlay:h}){const f=i.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),y=i.useCallback(E=>{if(!c?.current||!u||!d)return;const M=e.find(j=>j.id===E);if(!M)return;const I=c.current,B=I.clientWidth,_=M.start*d/u+b,F=M.end*d/u+b,N=(_+F)/2,q=I.scrollLeft,X=q,K=q+B;if(_<X||F>K){const j=Math.max(0,N-B/2);I.scrollTo({left:j,behavior:"smooth"})}},[e,c,u,d,b]);i.useEffect(()=>{t&&c?.current&&u&&d&&y(t)},[t,y,c,u,d]);const x=i.useCallback(E=>{if(f<0)return;const M=e[f],I=Math.max(0,Math.min(M.end-.1,M.start+E)),B=I-M.start,_=[...e];if(_[f]={...M,start:I},s&&f>0){const F=_[f-1];Math.abs(F.end-M.start)<Zt&&(_[f-1]={...F,end:Math.max(F.start+.1,F.end+B)})}else if(!s&&f>0){const F=_[f-1];I<F.end&&(_[f-1]={...F,end:I})}n(_)},[e,f,s,n]),m=i.useCallback(E=>{if(f<0)return;const M=e[f],I=Math.max(M.start+.1,Math.min(r,M.end+E)),B=I-M.end,_=[...e];if(_[f]={...M,end:I},s&&f<e.length-1){const F=_[f+1];if(Math.abs(F.start-M.end)<Zt){const N=Math.min(F.end-.1,F.start+B);_[f+1]={...F,start:N};let q=f+1;for(;q<_.length-1;){const X=_[q],K=_[q+1];if(Math.abs(K.start-e[q].end)<Zt){const j=X.end-e[q].end;_[q+1]={...K,start:Math.min(K.end-.1,K.start+j)},q++}else break}}}else if(!s&&f<e.length-1){const F=_[f+1];if(I>F.start){_[f+1]={...F,start:I};let N=f+1;for(;N<_.length-1;){const q=_[N],X=_[N+1];if(q.end>X.start)_[N+1]={...X,start:q.end},N++;else break}}}n(_)},[e,f,r,s,n]),g=i.useCallback(()=>{!a||e.length===0||(f<=0?a(e[e.length-1].id):a(e[f-1].id))},[e,f,a]),w=i.useCallback(()=>{!a||e.length===0||(f<0||f>=e.length-1?a(e[0].id):a(e[f+1].id))},[e,f,a]),C=i.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),v=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(f<0||!h)return;const E=e[f],M=o?void 0:E.end-E.start;h(E.start,M)},[e,f,o,h]),$=i.useMemo(()=>[{key:"[",action:()=>x(-kt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>x(kt),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>m(-kt),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>m(kt),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:S,description:"Play selected annotation",preventDefault:!0}],[x,m,S]),A=i.useMemo(()=>[{key:"ArrowUp",action:g,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:g,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:w,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:w,description:"Select next annotation",preventDefault:!0},{key:"Home",action:C,description:"Select first annotation",preventDefault:!0},{key:"End",action:v,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:k,description:"Deselect annotation",preventDefault:!0}],[g,w,C,v,k]);return Mt({shortcuts:$,enabled:l&&f>=0}),Mt({shortcuts:A,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:x,moveEndBoundary:m,selectPrevious:g,selectNext:w,selectFirst:C,selectLast:v,clearSelection:k,scrollToAnnotation:y,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}]}],Yt=e=>Ct.find(t=>t.id===e),Jo=e=>Ct.filter(t=>t.category===e),Qo=[{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"}],es={reverb:P.Reverb,freeverb:P.Freeverb,jcReverb:P.JCReverb,feedbackDelay:P.FeedbackDelay,pingPongDelay:P.PingPongDelay,chorus:P.Chorus,phaser:P.Phaser,tremolo:P.Tremolo,vibrato:P.Vibrato,autoPanner:P.AutoPanner,autoFilter:P.AutoFilter,autoWah:P.AutoWah,eq3:P.EQ3,distortion:P.Distortion,bitCrusher:P.BitCrusher,chebyshev:P.Chebyshev,compressor:P.Compressor,limiter:P.Limiter,gate:P.Gate,stereoWidener:P.StereoWidener};let ts=0;const ns=()=>`effect_${Date.now()}_${++ts}`;function pt(e,t){const n=es[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;a[o.name]=l});const r=new n(a),s=ns();return{effect:r,id:e.id,instanceId:s,dispose(){try{r.disconnect(),r.dispose()}catch{}},setParameter(o,l){o==="wet"&&r.wet?r.wet.value=l:r[o]!==void 0&&(r[o]?.value!==void 0?r[o].value=l:r[o]=l)},getParameter(o){if(o==="wet"&&r.wet)return r.wet.value;if(r[o]!==void 0)return r[o]?.value!==void 0?r[o].value:r[o]},connect(o){r.connect(o)},disconnect(){try{r.disconnect()}catch{}}}}function as(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 rs(e=256){const[t,n]=i.useState([]),a=i.useRef(t);a.current=t;const r=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(m=>{const g=o.current;if(!g)return;const{masterGainNode:w,destination:C,analyserNode:v}=g;try{w.disconnect()}catch{}const k=m.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)w.connect(v),v.connect(C);else{let S=w;k.forEach($=>{try{$.disconnect()}catch{}S.connect($.effect),S=$.effect}),S.connect(v),v.connect(C)}},[]),c=i.useCallback(m=>{const g=Yt(m);if(!g){console.error(`Unknown effect: ${m}`);return}const w={};g.parameters.forEach(k=>{w[k.name]=k.default});const C=pt(g,w);r.current.set(C.instanceId,C);const v={instanceId:C.instanceId,effectId:g.id,definition:g,params:w,bypassed:!1};n(k=>[...k,v])},[]),u=i.useCallback(m=>{const g=r.current.get(m);g&&(g.dispose(),r.current.delete(m)),n(w=>w.filter(C=>C.instanceId!==m))},[]),d=i.useCallback((m,g,w)=>{const C=r.current.get(m);C&&C.setParameter(g,w),n(v=>v.map(k=>k.instanceId===m?{...k,params:{...k.params,[g]:w}}:k))},[]),b=i.useCallback(m=>{const g=a.current.find(v=>v.instanceId===m);if(!g)return;const w=!g.bypassed,C=r.current.get(m);if(C){const v=g.params.wet??1;C.setParameter("wet",w?0:v)}n(v=>v.map(k=>k.instanceId===m?{...k,bypassed:w}:k))},[]),h=i.useCallback((m,g)=>{n(w=>{const C=[...w],[v]=C.splice(m,1);return C.splice(g,0,v),C})},[]),f=i.useCallback(()=>{r.current.forEach(m=>m.dispose()),r.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const y=i.useCallback((m,g,w)=>{const C=new P.Analyser("fft",e);s.current=C,o.current={masterGainNode:m,destination:g,analyserNode:C};const k=a.current.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)m.connect(C),C.connect(g);else{let S=m;k.forEach($=>{S.connect($.effect),S=$.effect}),S.connect(C),C.connect(g)}return function(){C.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{r.current.forEach(m=>m.dispose()),r.current.clear()},[]);const x=i.useCallback(()=>{const m=t.filter(g=>!g.bypassed);if(m.length!==0)return(g,w,C)=>{const v=[];for(const k of m){const S=pt(k.definition,k.params);v.push(S)}if(v.length===0)g.connect(w);else{let k=g;v.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(w)}return function(){v.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:Ct,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:b,reorderEffects:h,clearAllEffects:f,masterEffects:y,createOfflineEffectsFunction:x,analyserRef:s}}function os(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),a=i.useRef(new Map),r=i.useCallback((f,y)=>{const x=a.current.get(f);if(!x)return;const{graphEnd:m,masterGainNode:g}=x,w=n.current.get(f);try{m.disconnect()}catch{}const C=y.map(v=>w?.get(v.instanceId)).filter(v=>v!==void 0);if(C.length===0)m.connect(g);else{let v=m;C.forEach(k=>{try{k.disconnect()}catch{}v.connect(k.effect),v=k.effect}),v.connect(g)}},[]),s=i.useCallback((f,y)=>{const x=Yt(y);if(!x){console.error(`Unknown effect: ${y}`);return}const m={};x.parameters.forEach(C=>{m[C.name]=C.default});const g=pt(x,m);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(g.instanceId,g);const w={instanceId:g.instanceId,effectId:x.id,definition:x,params:m,bypassed:!1};t(C=>{const v=new Map(C),k=v.get(f)||[];return v.set(f,[...k,w]),v})},[]),o=i.useCallback((f,y)=>{const x=n.current.get(f),m=x?.get(y);m&&(m.dispose(),x?.delete(y)),t(g=>{const w=new Map(g),C=w.get(f)||[];return w.set(f,C.filter(v=>v.instanceId!==y)),w})},[]),l=i.useCallback((f,y,x,m)=>{const w=n.current.get(f)?.get(y);w&&w.setParameter(x,m),t(C=>{const v=new Map(C),k=v.get(f)||[];return v.set(f,k.map(S=>S.instanceId===y?{...S,params:{...S.params,[x]:m}}:S)),v})},[]),c=i.useCallback((f,y)=>{const m=(d.current.get(f)||[]).find(v=>v.instanceId===y);if(!m)return;const g=!m.bypassed,C=n.current.get(f)?.get(y);if(C){const v=m.params.wet??1;C.setParameter("wet",g?0:v)}t(v=>{const k=new Map(v),S=k.get(f)||[];return k.set(f,S.map($=>$.instanceId===y?{...$,bypassed:g}:$)),k})},[]),u=i.useCallback(f=>{const y=n.current.get(f);y&&(y.forEach(x=>x.dispose()),y.clear()),t(x=>{const m=new Map(x);return m.set(f,[]),m})},[]),d=i.useRef(e);d.current=e;const b=i.useCallback(f=>(y,x,m)=>{a.current.set(f,{graphEnd:y,masterGainNode:x});const g=d.current.get(f)||[],w=n.current.get(f),C=g.map(v=>w?.get(v.instanceId)).filter(v=>v!==void 0);if(C.length===0)y.connect(x);else{let v=y;C.forEach(k=>{v.connect(k.effect),v=k.effect}),v.connect(x)}return function(){a.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,y)=>{r(y,f)})},[e,r]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(y=>y.dispose()),f.clear()}),n.current.clear()},[]);const h=i.useCallback(f=>{const x=(e.get(f)||[]).filter(m=>!m.bypassed);if(x.length!==0)return(m,g,w)=>{const C=[];for(const v of x){const k=pt(v.definition,v.params);C.push(k)}if(C.length===0)m.connect(g);else{let v=m;C.forEach(k=>{v.connect(k.effect),v=k.effect}),v.connect(g)}return function(){C.forEach(k=>k.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:b,createOfflineTrackEffectsFunction:h,availableEffects:Ct}}function ss(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,o=n/8,l=a*o,c=r*l,u=s*l,d=44,b=d+u,h=new ArrayBuffer(b),f=new DataView(h);St(f,0,"RIFF"),f.setUint32(4,b-8,!0),St(f,8,"WAVE"),St(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),St(f,36,"data"),f.setUint32(40,u,!0);const y=[];for(let m=0;m<a;m++)y.push(e.getChannelData(m));let x=d;if(n===16)for(let m=0;m<s;m++)for(let g=0;g<a;g++){const w=y[g][m],C=Math.max(-1,Math.min(1,w)),v=C<0?C*32768:C*32767;f.setInt16(x,v,!0),x+=2}else for(let m=0;m<s;m++)for(let g=0;g<a;g++)f.setFloat32(x,y[g][m],!0),x+=4;return new Blob([h],{type:"audio/wav"})}function St(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 ta(){const[e,t]=i.useState(!1),[n,a]=i.useState(0),[r,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:b="master",trackIndex:h,autoDownload:f=!0,applyEffects:y=!0,effectsFunction:x,createOfflineTrackEffects:m,bitDepth:g=16,onProgress:w}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(b==="individual"&&(h===void 0||h<0||h>=l.length))throw new Error("Invalid track index for individual export");const C=l[0].clips[0]?.sampleRate||44100;let v=0;for(const I of l)for(const B of I.clips){const _=B.startSample+B.durationSamples;v=Math.max(v,_)}v+=Math.round(C*.1);const k=v/C,S=b==="individual"?[{track:l[h],state:c[h],index:h}]:l.map((I,B)=>({track:I,state:c[B],index:B})),$=c.some(I=>I.soloed),A=!!m;let E;if((x||A)&&y)E=await ls(S,c,$,k,C,x,m,I=>{a(I),w?.(I)});else{const I=new OfflineAudioContext(2,v,C);let B=0;const _=S.reduce((F,{track:N})=>F+N.clips.length,0);for(const{track:F,state:N}of S)if(!(N.muted&&!N.soloed)&&!($&&!N.soloed))for(const q of F.clips){await us(I,q,N,C,y),B++;const X=B/_*.5;a(X),w?.(X)}a(.5),w?.(.5),E=await I.startRendering()}a(.9),w?.(.9);const M=ss(E,{bitDepth:g});if(a(1),w?.(1),f){const I=b==="individual"?`${d}_${l[h].name}`:d;is(M,`${I}.wav`)}return{audioBuffer:E,blob:M,duration:k}}catch(C){const v=C instanceof Error?C.message:"Export failed";throw s(v),C}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function ls(e,t,n,a,r,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:b,Player:h,ToneAudioBuffer:f}=await import("tone");l(.1);let y;try{y=await c(async({transport:x,destination:m})=>{const g=new u(0);let w;s?w=s(g,m,!0):g.connect(m);for(const{track:C,state:v}of e){if(v.muted&&!v.soloed||n&&!v.soloed)continue;const k=new u(cs(v.volume)),S=new b(v.pan),$=new d(v.muted?0:1),A=o?.(C.id);A?A($,g,!0):$.connect(g),S.connect($),k.connect(S);for(const E of C.clips){const{audioBuffer:M,startSample:I,durationSamples:B,offsetSamples:_,gain:F,fadeIn:N,fadeOut:q}=E,X=I/r,K=B/r,j=_/r,J=new f(M),ne=new h(J),de=new d(F);if(ne.connect(de),de.connect(k),N){const le=X,ue=X+N.duration,oe=de.gain._param;oe.setValueAtTime(0,le),oe.linearRampToValueAtTime(F,ue)}if(q){const le=X+K-q.duration,ue=X+K,oe=de.gain._param;oe.setValueAtTime(F,le),oe.linearRampToValueAtTime(0,ue)}ne.start(X,j,K)}}x.start(0)},a,2,r)}catch(x){throw x instanceof Error?x:new Error(`Tone.Offline rendering failed: ${String(x)}`)}return l(.9),y.get()}function cs(e){return 20*Math.log10(Math.max(e,1e-4))}async function us(e,t,n,a,r){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:d,fadeOut:b}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const h=o/a,f=l/a,y=c/a,x=e.createBufferSource();x.buffer=s;const m=e.createGain(),g=u*n.volume,w=e.createStereoPanner();if(w.pan.value=n.pan,x.connect(m),m.connect(w),w.connect(e.destination),r){if(d?m.gain.setValueAtTime(0,h):m.gain.setValueAtTime(g,h),d){const C=h,v=h+d.duration;yn(m.gain,C,v,0,g,d.type||"linear")}if(b){const C=h+f-b.duration,v=h+f;(!d||d.duration<f-b.duration)&&m.gain.setValueAtTime(g,C),yn(m.gain,C,v,g,0,b.type||"linear")}}else m.gain.setValueAtTime(g,h);x.start(h,y,f)}function yn(e,t,n,a,r,s){const o=n-t;if(!(o<=0))switch(s){case"linear":e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n);break;case"exponential":const l=Math.max(a,1e-4),c=Math.max(r,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),r===0&&e.setValueAtTime(0,n);break;case"logarithmic":const u=xn(a,r,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=xn(a,r,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function xn(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=i.createContext(null),aa=i.createContext(null),ra=i.createContext(null),oa=i.createContext(null),sa=i.createContext(null),ds=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:b,onAnnotationUpdate:h,onAnnotationsChange:f,barWidth:y=1,barGap:x=0,progressBarWidth:m,children:g})=>{const w=m??y+x,C=i.useMemo(()=>{if(!u?.annotations)return[];if(process.env.NODE_ENV!=="production"&&u.annotations.length>0){const R=u.annotations[0];if(typeof R.start!="number"||typeof R.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 R.start),[]}return u.annotations},[u?.annotations]),v=i.useRef(C);v.current=C;const[k,S]=i.useState(null),[$,A]=i.useState(!1),[E,M]=i.useState(0),[I,B]=i.useState(0),[_,F]=i.useState([]),[N,q]=i.useState([]),[X,K]=i.useState([]),[j,J]=i.useState(0),[ne,de]=i.useState(0),[le,ue]=i.useState(null),[oe,Ee]=i.useState(o),[pe,V]=i.useState(u?.isContinuousPlay??!1),[ce,O]=i.useState(u?.linkEndpoints??!1),[U,se]=i.useState(u?.editable??!1),[ge,te]=i.useState(!1),[$e,Te]=i.useState(0),[Le,Ge]=i.useState(0),[Q,Ke]=i.useState(!1),W=i.useRef(null),be=i.useRef(0),ve=i.useRef(0),he=i.useRef(null),nt=i.useRef(X),L=i.useRef(0),re=i.useRef(0),Ae=i.useRef(null),fe=i.useRef(null),Ve=i.useRef(!1),Ne=i.useRef(u?.isContinuousPlay??!1),Ue=i.useRef(null),at=i.useRef(r),it=i.useRef(!1),Bt=i.useRef(0),Z=i.useRef(0),H=i.useRef(0),ee=i.useRef(0),{timeFormat:ye,setTimeFormat:Ce,formatTime:De}=Un(),Re=qn({initialSamplesPerPixel:r,zoomLevels:s}),_e=Re.samplesPerPixel,{masterVolume:ae,setMasterVolume:we}=Jn({playoutRef:W,initialVolume:1}),qe=i.useCallback(R=>{Ne.current=R,V(R)},[]),Xe=i.useCallback(R=>{Ue.current=R,S(R)},[]),lt=i.useCallback(R=>{it.current=R,te(R)},[]),je=i.useCallback((R,z)=>{H.current=R,ee.current=z,Te(R),Ge(z)},[]),Je=i.useCallback(()=>{const R=Bt.current,z=Z.current;R!==z&&z>R&&je(R,z)},[je]),dt=i.useCallback(()=>{je(0,0)},[je]);i.useEffect(()=>{Ve.current=oe},[oe]),i.useEffect(()=>{nt.current=X},[X]),i.useEffect(()=>{Bt.current=j,Z.current=ne},[j,ne]),i.useEffect(()=>{if(!fe.current||!_.length)return;const R=fe.current,z=at.current,Y=_e;if(z===Y)return;const ie=c.show?c.width:0,G=R.clientWidth,ke=R.scrollLeft+G/2-ie,et=_[0].sampleRate,Se=ke*z/et*et/Y,Pe=Math.max(0,Se+ie-G/2);R.scrollLeft=Pe,at.current=Y},[_e,_,c]);const Qe=i.useRef(null);i.useEffect(()=>{if(Ke(!1),e.length===0){F([]),B(0),K([]),q([]),W.current&&(W.current.dispose(),W.current=null);return}const R=$,z=ve.current;return W.current&&R&&(W.current.stop(),he.current&&(cancelAnimationFrame(he.current),he.current=null),Qe.current={position:z}),(async()=>{try{const ie=[];e.forEach(xe=>{xe.clips.length>0&&xe.clips[0].audioBuffer&&ie.push(xe.clips[0].audioBuffer)});let G=0;e.forEach(xe=>{xe.clips.forEach(Se=>{const Pe=Se.sampleRate,yt=(Se.startSample+Se.durationSamples)/Pe;G=Math.max(G,yt)})}),F(ie),B(G),K(xe=>xe.length===e.length?xe.map((Se,Pe)=>({...Se,name:e[Pe].name})):e.map(Se=>({name:Se.name,muted:Se.muted,soloed:Se.soloed,volume:Se.volume,pan:Se.pan}))),W.current&&W.current.dispose();const Ie=new Xa({effects:d}),ke=nt.current;e.forEach((xe,Se)=>{const Pe=xe.clips.filter(rt=>rt.audioBuffer);if(Pe.length>0){const rt=Pe[0].sampleRate,yt=Math.min(...Pe.map(Ze=>Ze.startSample/rt)),Ea=Math.max(...Pe.map(Ze=>(Ze.startSample+Ze.durationSamples)/rt)),xt=ke[Se],Ta={id:`track-${Se}`,name:xe.name,gain:xt?.volume??xe.volume,muted:xt?.muted??xe.muted,soloed:xt?.soloed??xe.soloed,stereoPan:xt?.pan??xe.pan,startTime:yt,endTime:Ea},Da=Pe.map(Ze=>{const Wt=Ze.sampleRate;return{buffer:Ze.audioBuffer,startTime:Ze.startSample/Wt-yt,duration:Ze.durationSamples/Wt,offset:Ze.offsetSamples/Wt,fadeIn:Ze.fadeIn,fadeOut:Ze.fadeOut,gain:Ze.gain}});Ie.addTrack({clips:Da,track:Ta,effects:xe.effects})}}),Ie.applyInitialSoloState(),W.current=Ie,Ke(!0);const et=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:G}});window.dispatchEvent(et),b?.()}catch(ie){console.error("Error loading audio:",ie)}})(),()=>{he.current&&cancelAnimationFrame(he.current),W.current&&W.current.dispose()}},[e,b,$]),i.useEffect(()=>{if(e.length===0)return;const R=16,z=e.map(Y=>Y.clips.map(G=>{if(G.waveformData){const ke=Kn(G.waveformData,_e,0,G.offsetSamples,G.durationSamples);return{clipId:G.id,trackName:Y.name,peaks:{length:ke.length,data:[ke.data],bits:ke.bits},startSample:G.startSample,durationSamples:G.durationSamples,fadeIn:G.fadeIn,fadeOut:G.fadeOut}}if(!G.audioBuffer)return console.warn(`Clip "${G.name||G.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:G.id,trackName:Y.name,peaks:{length:0,data:[],bits:R},startSample:G.startSample,durationSamples:G.durationSamples,fadeIn:G.fadeIn,fadeOut:G.fadeOut};const Ie=xo(G.audioBuffer,_e,n,R,G.offsetSamples,G.durationSamples);return{clipId:G.id,trackName:Y.name,peaks:Ie,startSample:G.startSample,durationSamples:G.durationSamples,fadeIn:G.fadeIn,fadeOut:G.fadeOut}}));q(z)},[e,_e,n]);const Ye=i.useCallback(()=>{he.current&&(cancelAnimationFrame(he.current),he.current=null);const R=()=>{const z=P.getContext().currentTime-L.current,Y=re.current+z;ve.current=Y,M(Y);const ie=v.current;if(ie.length>0){const Ie=ie.find(ke=>Y>=ke.start&&Y<ke.end);if(Ne.current)Ie&&Ie.id!==Ue.current?Xe(Ie.id):!Ie&&Ue.current!==null&&Xe(null);else if(Ue.current){const ke=ie.find(et=>et.id===Ue.current);if(ke&&Y>=ke.end){W.current&&W.current.stop(),A(!1),ve.current=be.current,M(be.current);return}}else Ie&&Xe(Ie.id)}if(Ve.current&&fe.current&&_.length>0){const Ie=fe.current,ke=_[0].sampleRate,et=Y*ke/at.current,xe=Ie.clientWidth,Se=c.show?c.width:0,Pe=et+Se,rt=Math.max(0,Pe-xe/2);Ie.scrollLeft=rt}if(Ae.current!==null&&Y>=Ae.current){W.current&&W.current.stop(),A(!1),ve.current=Ae.current,M(Ae.current),Ae.current=null;return}const G=H.current!==ee.current&&ee.current>H.current;if(it.current&&G&&Y>=ee.current){W.current?.stop();const ke=P.getContext().currentTime;L.current=ke,re.current=H.current,ve.current=H.current,W.current?.play(ke,H.current),he.current=requestAnimationFrame(R);return}if(Y>=I){W.current&&W.current.stop(),A(!1),ve.current=be.current,M(be.current),Xe(null);return}he.current=requestAnimationFrame(R)};he.current=requestAnimationFrame(R)},[I,_,_e,pe]),We=i.useCallback(()=>{he.current&&(cancelAnimationFrame(he.current),he.current=null)},[]);i.useEffect(()=>{(async()=>{if($&&he.current&&W.current)if(pe){const z=ve.current;W.current.stop(),We(),await W.current.init(),W.current.setOnPlaybackComplete(()=>{});const ie=P.getContext().currentTime;L.current=ie,re.current=z,W.current.play(ie,z),Ye()}else We(),Ye()})()},[pe,$,Ye,We]),i.useEffect(()=>{(async()=>{if(Qe.current&&W.current){const{position:z}=Qe.current;Qe.current=null,await W.current.init(),W.current.setOnPlaybackComplete(()=>{});const ie=P.getContext().currentTime;L.current=ie,re.current=z,W.current.play(ie,z),A(!0),Ye()}})()},[e,Ye]);const ft=i.useCallback(async(R,z)=>{if(!W.current||_.length===0)return;await W.current.init();const Y=R??ve.current;be.current=Y,ve.current=Y,W.current.setOnPlaybackComplete(()=>{}),W.current.stop(),We();const G=P.getContext().currentTime;L.current=G,re.current=Y,Ae.current=z!==void 0?Y+z:null,W.current.play(G,Y,z),A(!0),Ye()},[_.length,Ye,We]),pa=i.useCallback(()=>{if(!W.current)return;const R=P.getContext().currentTime-L.current,z=re.current+R;W.current.pause(),A(!1),We(),ve.current=z,M(z)},[We]),ga=i.useCallback(()=>{W.current&&(W.current.stop(),A(!1),We(),ve.current=be.current,M(be.current),Xe(null))},[We]),ba=i.useCallback(R=>{const z=Math.max(0,Math.min(R,I));ve.current=z,M(z),$&&W.current&&(W.current.stop(),We(),ft(z))},[I,$,ft,We]),va=i.useCallback((R,z)=>{const Y=[...X];if(Y[R]={...Y[R],muted:z},K(Y),W.current){const ie=`track-${R}`;W.current.setMute(ie,z)}},[X]),Ca=i.useCallback((R,z)=>{const Y=[...X];if(Y[R]={...Y[R],soloed:z},K(Y),W.current){const ie=`track-${R}`;W.current.setSolo(ie,z)}},[X]),ya=i.useCallback((R,z)=>{const Y=[...X];if(Y[R]={...Y[R],volume:z},K(Y),W.current){const ie=`track-${R}`,G=W.current.getTrack(ie);G&&G.setVolume(z)}},[X]),xa=i.useCallback((R,z)=>{const Y=[...X];if(Y[R]={...Y[R],pan:z},K(Y),W.current){const ie=`track-${R}`,G=W.current.getTrack(ie);G&&G.setPan(z)}},[X]),wa=i.useCallback((R,z)=>{J(R),de(z),ve.current=R,M(R),$&&W.current&&(W.current.stop(),W.current.play(P.getContext().currentTime,R))},[$]),ka=i.useCallback(R=>{fe.current=R},[]),Ft=i.useRef(f);Ft.current=f;const Sa=i.useCallback(R=>{const z=typeof R=="function"?R(v.current):R;if(!Ft.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}Ft.current(z)},[]),Aa=_[0]?.sampleRate||44100,qt=t?30:0,Ia=e.length*a+qt,Jt={isPlaying:$,currentTime:E,currentTimeRef:ve,playbackStartTimeRef:L,audioStartPositionRef:re},Qt={continuousPlay:pe,linkEndpoints:ce,annotationsEditable:U,isAutomaticScroll:oe,isLoopEnabled:ge,annotations:C,activeAnnotationId:k,selectionStart:j,selectionEnd:ne,selectedTrackId:le,loopStart:$e,loopEnd:Le},en={play:ft,pause:pa,stop:ga,seekTo:ba,setCurrentTime:R=>{ve.current=R,M(R)},setTrackMute:va,setTrackSolo:Ca,setTrackVolume:ya,setTrackPan:xa,setSelection:wa,setSelectedTrackId:ue,setTimeFormat:Ce,formatTime:De,zoomIn:Re.zoomIn,zoomOut:Re.zoomOut,setMasterVolume:we,setAutomaticScroll:R=>{Ee(R)},setScrollContainer:ka,scrollContainerRef:fe,setContinuousPlay:qe,setLinkEndpoints:O,setAnnotationsEditable:se,setAnnotations:Sa,setActiveAnnotationId:Xe,setLoopEnabled:lt,setLoopRegion:je,setLoopRegionFromSelection:Je,clearLoopRegion:dt},tn={duration:I,audioBuffers:_,peaksDataArray:N,trackStates:X,tracks:e,sampleRate:Aa,waveHeight:a,timeScaleHeight:qt,minimumPlaylistHeight:Ia,controls:c,playoutRef:W,samplesPerPixel:_e,timeFormat:ye,masterVolume:ae,canZoomIn:Re.canZoomIn,canZoomOut:Re.canZoomOut,barWidth:y,barGap:x,progressBarWidth:w,isReady:Q,mono:n},Ma={...Jt,...Qt,...en,...tn},$a={...Fn,...l};return p.jsx(D.ThemeProvider,{theme:$a,children:p.jsx(na.Provider,{value:Jt,children:p.jsx(aa.Provider,{value:Qt,children:p.jsx(ra.Provider,{value:en,children:p.jsx(oa.Provider,{value:tn,children:p.jsx(sa.Provider,{value:Ma,children:g})})})})})})},Be=()=>{const e=i.useContext(na);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Fe=()=>{const e=i.useContext(aa);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},me=()=>{const e=i.useContext(ra);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},Me=()=>{const e=i.useContext(oa);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},fs=()=>{const e=i.useContext(sa);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var ms=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate,"preservesPitch"in this.audioElement?this.audioElement.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?this.audioElement.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(this.audioElement.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},hs=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 ms({...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 ia=i.createContext(null),la=i.createContext(null),ca=i.createContext(null),ua=i.createContext(null),ps=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:s=!1,theme:o,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:d=0,progressBarWidth:b,onAnnotationsChange:h,onReady:f,children:y})=>{const x=b??u+d,[m,g]=i.useState(!1),[w,C]=i.useState(0),[v,k]=i.useState(0),[S,$]=i.useState([]),[A,E]=i.useState(r),M=i.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const L=c.annotations[0];if(typeof L.start!="number"||typeof L.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof L.start),[]}return c.annotations},[c?.annotations]),I=i.useRef(M);I.current=M;const[B,_]=i.useState(null),[F,N]=i.useState(c?.isContinuousPlay??!1),[q]=i.useState(t),[X,K]=i.useState(s),j=i.useRef(null),J=i.useRef(0),ne=i.useRef(null),de=i.useRef(F),le=i.useRef(null),ue=i.useRef(null),oe=i.useRef(s),Ee=i.useRef(t);i.useEffect(()=>{de.current=F},[F]),i.useEffect(()=>{oe.current=X},[X]);const pe=i.useCallback(L=>{le.current=L,_(L)},[]),V=i.useCallback(L=>{de.current=L,N(L)},[]),ce=i.useCallback(L=>{ue.current=L},[]),O=e.waveformData.sample_rate;i.useEffect(()=>{const L=new hs({playbackRate:r});L.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const re=L.getTrack(L.track?.id??"");return re&&re.setOnTimeUpdateCallback(Ae=>{J.current=Ae}),L.setOnPlaybackComplete(()=>{ne.current&&(cancelAnimationFrame(ne.current),ne.current=null),g(!1),pe(null),J.current=0,C(0)}),j.current=L,k(e.waveformData.duration),f?.(),()=>{ne.current&&cancelAnimationFrame(ne.current),L.dispose()}},[e.source,e.waveformData,e.name,r,f]),i.useEffect(()=>{const L=Kn(e.waveformData,q,0,0,Math.ceil(e.waveformData.duration*O)),re={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:L.length,data:[L.data],bits:L.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*O)};$([[re]])},[e.waveformData,e.name,q,O]);const U=i.useCallback(()=>{ne.current&&cancelAnimationFrame(ne.current);const L=()=>{const re=j.current?.getCurrentTime()??0;J.current=re,C(re);const Ae=I.current;if(Ae.length>0){const fe=Ae.find(Ve=>re>=Ve.start&&re<Ve.end);if(de.current)fe&&fe.id!==le.current?pe(fe.id):!fe&&le.current!==null&&pe(null);else if(le.current){const Ve=Ae.find(Ne=>Ne.id===le.current);if(Ve&&re>=Ve.end){j.current?.stop(),g(!1);return}}else fe&&pe(fe.id)}if(oe.current&&ue.current){const fe=ue.current,Ve=re*O/Ee.current,Ne=fe.clientWidth,Ue=l.show?l.width:0,at=Ve+Ue,it=Math.max(0,at-Ne/2);fe.scrollLeft=it}ne.current=requestAnimationFrame(L)};ne.current=requestAnimationFrame(L)},[pe,O,l]),se=i.useCallback(()=>{ne.current&&(cancelAnimationFrame(ne.current),ne.current=null)},[]),ge=i.useCallback(L=>{if(!j.current)return;const re=L??J.current;j.current.play(void 0,re),g(!0),U()},[U]),te=i.useCallback(()=>{j.current&&(j.current.pause(),g(!1),se(),C(j.current.getCurrentTime()))},[se]),$e=i.useCallback(()=>{j.current&&(j.current.stop(),g(!1),se(),J.current=0,C(0),pe(null))},[se,pe]),Te=i.useCallback(L=>{const re=Math.max(0,Math.min(L,v));J.current=re,C(re),j.current&&j.current.seekTo(re)},[v]),Le=i.useCallback(L=>{const re=Math.max(.5,Math.min(2,L));E(re),j.current&&j.current.setPlaybackRate(re)},[]),Ge=a?30:0,Q=i.useMemo(()=>({isPlaying:m,currentTime:w,currentTimeRef:J}),[m,w]),Ke=i.useMemo(()=>({continuousPlay:F,annotations:M,activeAnnotationId:B,playbackRate:A,isAutomaticScroll:X}),[F,M,B,A,X]),W=i.useRef(h);W.current=h;const be=i.useCallback(L=>{const re=typeof L=="function"?L(I.current):L;if(!W.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}W.current(re)},[]),ve=i.useMemo(()=>({play:ge,pause:te,stop:$e,seekTo:Te,setPlaybackRate:Le,setContinuousPlay:V,setAnnotations:be,setActiveAnnotationId:pe,setAutomaticScroll:L=>{K(L)},setScrollContainer:ce,scrollContainerRef:ue}),[ge,te,$e,Te,Le,V,be,pe,ce]),he=i.useMemo(()=>({duration:v,peaksDataArray:S,sampleRate:O,waveHeight:n,timeScaleHeight:Ge,samplesPerPixel:q,playoutRef:j,controls:l,barWidth:u,barGap:d,progressBarWidth:x}),[v,S,O,n,Ge,q,l,u,d,x]),nt={...Fn,...o};return p.jsx(D.ThemeProvider,{theme:nt,children:p.jsx(ia.Provider,{value:Q,children:p.jsx(la.Provider,{value:Ke,children:p.jsx(ca.Provider,{value:ve,children:p.jsx(ua.Provider,{value:he,children:y})})})})})},Tt=()=>{const e=i.useContext(ia);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Dt=()=>{const e=i.useContext(la);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},Kt=()=>{const e=i.useContext(ca);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Rt=()=>{const e=i.useContext(ua);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},gs=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Be(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=Fe(),{play:o}=me(),l=async()=>{if(a!==r&&r>a)if(s)await o(a);else{const u=r-a;await o(a,u)}else await o(n.current??0)};return p.jsx(ze,{onClick:l,disabled:t,className:e,children:"Play"})},bs=({className:e})=>{const{isPlaying:t}=Be(),{pause:n}=me();return p.jsx(ze,{onClick:n,disabled:!t,className:e,children:"Pause"})},vs=({className:e})=>{const{isPlaying:t}=Be(),{stop:n}=me();return p.jsx(ze,{onClick:n,disabled:!t,className:e,children:"Stop"})},Cs=({className:e})=>{const{isPlaying:t}=Be(),{play:n,setCurrentTime:a}=me(),{playoutRef:r}=Me(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return p.jsx(ze,{onClick:s,className:e,children:"Rewind"})},ys=({className:e})=>{const{isPlaying:t}=Be(),{play:n,setCurrentTime:a}=me(),{duration:r,playoutRef:s}=Me(),o=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return p.jsx(ze,{onClick:o,className:e,children:"Fast Forward"})},xs=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Be(),{play:r,setCurrentTime:s}=me(),{playoutRef:o}=Me(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&o.current&&(o.current.stop(),r(c))};return p.jsx(ze,{onClick:l,className:t,children:"Skip Backward"})},ws=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Be(),{play:r,setCurrentTime:s}=me(),{duration:o,playoutRef:l}=Me(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),a&&l.current&&(l.current.stop(),r(u))};return p.jsx(ze,{onClick:c,className:t,children:"Skip Forward"})},ks=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=Fe(),{setLoopEnabled:r,setLoopRegion:s}=me(),{duration:o}=Me(),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 p.jsx(ze,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Ss=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=Fe(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=me(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?o():s()};return p.jsx(ze,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},As=({className:e,disabled:t})=>{const{zoomIn:n}=me(),{canZoomIn:a}=Me();return p.jsx(ze,{onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Is=({className:e,disabled:t})=>{const{zoomOut:n}=me(),{canZoomOut:a}=Me();return p.jsx(ze,{onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Ms=({className:e})=>{const{masterVolume:t}=Me(),{setMasterVolume:n}=me();return p.jsx(yr,{volume:t,onChange:n,className:e})},$s=({className:e})=>{const{timeFormat:t}=Me(),{setTimeFormat:n}=me();return p.jsx(eo,{value:t,onChange:n,className:e})},Es=D.span`
|
|
781
|
+
`,bo=({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=d=>{const b=d.target;l.current&&!l.current.contains(b)&&c.current&&!c.current.contains(b)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[t]),g.jsxs(mo,{children:[g.jsx(ho,{ref:l,onClick:u=>{u.stopPropagation(),n(d=>!d)},onMouseDown:u=>u.stopPropagation(),title:"Track menu","aria-label":"Track menu",children:g.jsx(fo,{size:16})}),t&&typeof document<"u"&&kn.createPortal(g.jsx(po,{ref:c,$top:s.top,$left:s.left,onMouseDown:u=>u.stopPropagation(),children:r.map((u,d)=>g.jsxs(i.Fragment,{children:[d>0&&g.jsx(go,{}),u.content]},u.id))}),document.body)]})};function vo(e){let t=1/0,n=-1/0;for(let a=0;a<e.length;a++){const r=e[a];t>r&&(t=r),n<r&&(n=r)}return{min:t,max:n}}function vn(e,t){const n=Math.pow(2,t-1),a=e<0?e*n:e*(n-1);return Math.max(-n,Math.min(n-1,a))}function Gn(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function Cn(e,t,n){const a=e.length,r=Math.ceil(a/t),s=Gn(n,r*2);for(let o=0;o<r;o++){const l=o*t,c=Math.min((o+1)*t,a),u=e.subarray(l,c),d=vo(u),b=vn(d.min,n),h=vn(d.max,n);s[o*2]=b,s[o*2+1]=h}return s}function Co(e,t){const n=e.length,a=1/n,r=e[0].length/2,s=Gn(t,r*2);for(let o=0;o<r;o++){let l=0,c=0;for(let u=0;u<n;u++)l+=a*e[u][o*2],c+=a*e[u][o*2+1];s[o*2]=l,s[o*2+1]=c}return[s]}function yo(e,t=1e3,n=!0,a=0,r,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=r??e.length;for(let d=0;d<c;d++){const h=e.getChannelData(d).subarray(a,u);o.push(Cn(h,t,s))}}else{const c=r??e.length,u=e.subarray(a,c);o.push(Cn(u,t,s))}return n&&o.length>1&&(o=Co(o,s)),{length:o[0].length/2,data:o,bits:s}}function xo(e,t=1e3,n=!0,a=8,r=0,s){const o=s!==void 0?r+s:void 0;return yo(e,t,n,r,o,a)}function ot(e,t){this._waveformData=e,this._channelIndex=t}ot.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};ot.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};ot.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};ot.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};ot.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};ot.prototype.max_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.max_sample(n));return t};var wo=127,ko=-128,So=32767,Ao=-32768;function Io(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function Mo(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(A){return new Float32Array(A)}),l=a?o.length:1,c=24,u=Io(r,t),d=e.bits===8?1:2,b=c+u*2*d*l,h=new ArrayBuffer(b),f=new DataView(h),y=0,x=c,m=new Array(l),p=new Array(l),w=0;w<l;w++)m[w]=1/0,p[w]=-1/0;var C=e.bits===8?ko:Ao,v=e.bits===8?wo:So;f.setInt32(0,2,!0),f.setUint32(4,e.bits===8,!0),f.setInt32(8,s,!0),f.setInt32(12,t,!0),f.setInt32(16,u,!0),f.setInt32(20,l,!0);for(var k=0;k<r;k++){var S=0;if(l===1){for(var $=0;$<o.length;++$)S+=o[$][k];S=Math.floor(v*S*n/o.length),S<m[0]&&(m[0]=S,m[0]<C&&(m[0]=C)),S>p[0]&&(p[0]=S,p[0]>v&&(p[0]=v))}else for(var M=0;M<l;++M)S=Math.floor(v*o[M][k]*n),S<m[M]&&(m[M]=S,m[M]<C&&(m[M]=C)),S>p[M]&&(p[M]=S,p[M]>v&&(p[M]=v));if(++y===t){for(var D=0;D<l;D++)e.bits===8?(f.setInt8(x++,m[D]),f.setInt8(x++,p[D])):(f.setInt16(x,m[D],!0),f.setInt16(x+2,p[D],!0),x+=4),m[D]=1/0,p[D]=-1/0;y=0}}if(y>0)for(var I=0;I<l;I++)e.bits===8?(f.setInt8(x++,m[I]),f.setInt8(x++,p[I])):(f.setInt16(x,m[I],!0),f.setInt16(x+2,p[I],!0));return h}function It(e){"@babel/helpers - typeof";return It=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},It(e)}function $o(e){return e&&It(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Eo(e){var t=e&&It(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 To(e){var t=e.data,n=e.channels||1,a=24,r=e.bits===8?1:2,s=e.length*2*n;if(t.length!==s)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var o=a+t.length*r,l=new ArrayBuffer(o),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=a;if(e.bits===8)for(var d=0;d<t.length;d++)c.setInt8(u++,t[d],!0);else for(var b=0;b<t.length;b++)c.setInt16(u,t[b],!0),u+=2;return l}function ct(e){return e==null}function Do(e,t){var n=atob(e);return n}function Ro(e,t,n){var a=Do(e),r=a.indexOf(`
|
|
782
|
+
`,10)+1,s=a.substring(r)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function _o(e,t,n){var a;return function(s){return a=a||Ro(e),new Worker(a,s)}}var Bo=_o("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function je(e){if($o(e)&&(e=To(e)),Eo(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new ot(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var ht={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function Fo(e){var t={scale:e.scale||ht.scale,bits:e.bits||ht.bits,amplitude_scale:e.amplitude_scale||ht.amplitude_scale,split_channels:e.split_channels||ht.split_channels,disable_worker:e.disable_worker||ht.disable_worker};return t}function Wo(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Nn(e,t,n){var a=Wo(e);if(t.disable_worker){var r=Mo({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a});n(void 0,new je(r),e)}else{var s=new Bo;s.onmessage=function(o){n(void 0,new je(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 Po(e,t,n,a){function r(o){o||(o=new DOMException("EncodingError")),a(o),a=function(){}}var s=e.decodeAudioData(t,function(o){Nn(o,n,a)},r);s&&s.catch(r)}je.create=function(t){return new je(t)};je.createFromAudio=function(e,t){var n=Fo(e);if(e.audio_context&&e.array_buffer)return Po(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Nn(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Et(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 je(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}Et.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Et.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};Et.prototype.getOutputData=function(){return this._output_data};je.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!ct(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!ct(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 Et(t);!n.next(););return new je(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(r){if(t.channels!==r.channels||t.sample_rate!==r.sample_rate||t.bits!==r.bits||t.scale!==r.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var a=this._concatBuffers.apply(this,n);return je.create(a)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,a=n,r=0,s=[this].concat(t).map(function(p){return p._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),d=new DataView(s[0]),b=new DataView(u),h=0;h<n;h++)b.setUint8(h,d.getUint8(h));b.setInt32(16,r,!0);for(var f=0,y=new Uint8Array(u,n),x=0;x<s.length;x++){var m=s[x];y.set(new Uint8Array(m,n),f),f+=m.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!ct(t.startIndex)&&!ct(t.endIndex)?(n=t.startIndex,a=t.endIndex):!ct(t.startTime)&&!ct(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,s=24,o=this.bits===8?1:2,l=s+r*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var d=0;d<r*this.channels*2;d++){var b=this._at(n*this.channels*2+d);this.bits===8?u.setInt8(s+d,b):u.setInt16(s+d*2,b,!0)}return new je(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var a=0;a<this.channels;a++)t.data.push(this.channel(a).min_sample(n)),t.data.push(this.channel(a).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function Nt(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const a=await t.arrayBuffer();return je.create(a)}else{const a=await t.json();return je.create(a)}}function Yn(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 Zo(e,t=0){const n=await Nt(e);return Yn(n,t)}async function Vo(e){const t=await Nt(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Kn(e,t,n=0,a,r){let s=e;if(a!==void 0&&r!==void 0){const h=e.scale,f=Math.floor(a/h),y=Math.ceil((a+r)/h);s=s.slice({startIndex:f,endIndex:y})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),d=c.length,b=l===8?new Int8Array(d*2):new Int16Array(d*2);for(let h=0;h<d;h++)b[h*2]=c[h],b[h*2+1]=u[h];return{data:b,bits:l,length:d}}function Un(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>ut(r,e),parseTime:r=>jn(r,e)}}const jo=[256,512,1024,2048,4096,8192];function qn({initialSamplesPerPixel:e,zoomLevels:t=jo}){const[n,a]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),r=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{a(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{a(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:r,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function Jn({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[a,r]=i.useState(t),s=i.useCallback(o=>{r(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:a,setMasterVolume:s}}const Ho=(e=256)=>{const t=i.useRef(null),n=i.useCallback((a,r,s)=>{const o=new P.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 zt(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,b=t?.length??e.sourceDurationSamples??(u&&d?Math.ceil(u.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(b===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const h=e.durationSamples??b;return{id:Qn(),audioBuffer:t,startSample:n,durationSamples:h,offsetSamples:a,sampleRate:d,sourceDurationSamples:b,gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function zo(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const b=t?.duration??e.sourceDuration??u?.duration;if(b===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const h=e.duration??b;return zt({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(h*d),offsetSamples:Math.round(a*d),sampleRate:d,sourceDurationSamples:Math.ceil(b*d),gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Lo(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Qn(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:o,color:l,height:c}}function Qn(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Xo(e,t={}){const{progressive:n=!1}=t,[a,r]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),b=e.length;return i.useEffect(()=>{if(e.length===0){r([]),o(!1),d(0);return}let h=!1;const f=new Map,y=(m,p,w)=>{const C=w??m.audioBuffer;if(!C&&!m.waveformData)throw new Error(`Track ${p+1}: Must provide src, audioBuffer, or waveformData`);const v=C?.duration??m.waveformData?.duration,k=zo({audioBuffer:C,startTime:m.startTime??0,duration:m.duration??v,offset:m.offset??0,name:m.name||`Track ${p+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(k.startSample)||isNaN(k.durationSamples)||isNaN(k.offsetSamples))throw console.error("Invalid clip values:",k),new Error(`Invalid clip values for track ${p+1}`);return{...Lo({name:m.name||`Track ${p+1}`,clips:[k],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),d(0);const m=An.getContext().rawContext,p=e.map(async(C,v)=>{if(C.audioBuffer){const D=y(C,v,C.audioBuffer);return n&&!h&&(f.set(v,D),d(I=>I+1),r(Array.from({length:e.length},(I,A)=>f.get(A)).filter(I=>I!==void 0))),D}if(!C.src&&C.waveformData){const D=y(C,v);return n&&!h&&(f.set(v,D),d(I=>I+1),r(Array.from({length:e.length},(I,A)=>f.get(A)).filter(I=>I!==void 0))),D}if(!C.src)throw new Error(`Track ${v+1}: Must provide src, audioBuffer, or waveformData`);const k=await fetch(C.src);if(!k.ok)throw new Error(`Failed to fetch ${C.src}: ${k.statusText}`);const S=await k.arrayBuffer(),$=await m.decodeAudioData(S);if(!$||!$.sampleRate||!$.duration)throw new Error(`Invalid audio buffer for ${C.src}`);const M=y(C,v,$);return n&&!h&&(f.set(v,M),d(D=>D+1),r(Array.from({length:e.length},(D,I)=>f.get(I)).filter(D=>D!==void 0))),M}),w=await Promise.all(p);h||(n||(r(w),d(w.length)),o(!1))}catch(m){if(!h){const p=m instanceof Error?m.message:"Unknown error loading audio";c(p),o(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{h=!0}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:b}}function Oo({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=i.useRef(null),s=i.useCallback(u=>{const{transform:d,active:b}=u;if(!b?.data?.current)return{...d,scaleX:1,scaleY:1};const{trackIndex:h,clipIndex:f,boundary:y}=b.data.current;if(y)return{...d,scaleX:1,scaleY:1};const x=e[h];if(!x)return{...d,scaleX:1,scaleY:1};const m=x.clips[f];if(!m)return{...d,scaleX:1,scaleY:1};const p=m.startSample/a,w=m.durationSamples/a,C=d.x*n/a;let v=p+C;const k=[...x.clips].sort((A,B)=>A.startSample-B.startSample),S=k.findIndex(A=>A===m);v=Math.max(0,v);const $=S>0?k[S-1]:null;if($){const A=($.startSample+$.durationSamples)/a;v=Math.max(v,A)}const M=S<k.length-1?k[S+1]:null;if(M){const A=v+w,B=M.startSample/a;A>B&&(v=B-w)}const I=(v-p)*a/n;return{...d,x:I,scaleX:1,scaleY:1}},[e,n,a]),o=i.useCallback(u=>{const{active:d}=u,{boundary:b}=d.data.current;if(!b){r.current=null;return}const{trackIndex:h,clipIndex:f}=d.data.current,x=e[h]?.clips[f];x&&(r.current={offsetSamples:x.offsetSamples,durationSamples:x.durationSamples,startSample:x.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:b}=u,{boundary:h}=d.data.current;if(!h||!r.current)return;const{trackIndex:f,clipIndex:y}=d.data.current,x=b.x*n,m=Math.floor(.1*a),p=r.current,w=e.map((C,v)=>{if(v!==f)return C;const k=[...C.clips].sort((M,D)=>M.startSample-D.startSample),S=k.findIndex(M=>M===C.clips[y]),$=C.clips.map((M,D)=>{if(D!==y)return M;const I=M.sourceDurationSamples;if(h==="left"){let A=Math.floor(x);const B=-p.startSample;A<B&&(A=B);const _=-p.offsetSamples;A<_&&(A=_);const F=S>0?k[S-1]:null;if(F){const re=F.startSample+F.durationSamples-p.startSample;A<re&&(A=re)}const O=p.durationSamples-m;A>O&&(A=O);const G=p.offsetSamples+A,j=p.durationSamples-A,q=p.startSample+A;return{...M,offsetSamples:G,durationSamples:j,startSample:q}}else{let A=Math.floor(p.durationSamples+x);A=Math.max(m,A),p.offsetSamples+A>I&&(A=I-p.offsetSamples);const B=S<k.length-1?k[S+1]:null;return B&&p.startSample+A>B.startSample&&(A=B.startSample-p.startSample,A=Math.max(m,A)),{...M,durationSamples:A}}});return{...C,clips:$}});t(w)},[e,t,n,a]),c=i.useCallback(u=>{const{active:d,delta:b}=u,{trackIndex:h,clipIndex:f,boundary:y}=d.data.current,x=b.x*n;if(y){r.current=null;return}const m=e.map((p,w)=>{if(w!==h)return p;const C=[...p.clips].sort((S,$)=>S.startSample-$.startSample),v=C.findIndex(S=>S===p.clips[f]),k=p.clips.map((S,$)=>{if($!==f)return S;let M=Math.floor(S.startSample+x);M=Math.max(0,M);const D=v>0?C[v-1]:null;if(D){const A=D.startSample+D.durationSamples;M=Math.max(M,A)}const I=v<C.length-1?C[v+1]:null;return I&&M+S.durationSamples>I.startSample&&(M=I.startSample-S.durationSamples),{...S,startSample:M}});return{...p,clips:k}});t(m)},[e,t,n,a]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Pt=.01;function ea({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:b}=d,h=b.data.current;if(!h||h.annotationIndex===void 0){o.current=null;return}const f=e[h.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:h.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:b,delta:h}=d;if(!o.current)return;const f=b.data.current;if(!f)return;const{edge:y,annotationIndex:x}=f,m=o.current,p=h.x*n/a,w=y==="start"?m.start+p:m.end+p,C=Go({annotationIndex:x,newTime:w,isDraggingStart:y==="start",annotations:e,duration:r,linkEndpoints:s});t(C)},[e,t,n,a,r,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Go({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const o=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<Pt?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<Pt){const b=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,b)};let h=e+1;for(;h<o.length-1;){const f=o[h],y=o[h+1];if(Math.abs(y.start-f.end)<Pt){const x=f.end-a[h].end;o[h+1]={...y,start:Math.min(y.end-.1,y.start+x)},h++}else break}}else c>=d.start&&(o[e]={...o[e],end:d.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const d=o[e+1];o[e+1]={...d,start:c};let b=e+1;for(;b<o.length-1;){const h=o[b],f=o[b+1];if(h.end>f.start)o[b+1]={...f,start:h.end},b++;else break}}}return o}function No(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Ge.useSensor(Ge.MouseSensor,{activationConstraint:{distance:r}}),o=Ge.useSensor(Ge.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Ge.useSensor(Ge.PointerSensor,{activationConstraint:{distance:r}});return Ge.useSensors(...t?[s,o]:[l])}const Yo=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Re(),{selectedTrackId:s}=_e(),o=i.useCallback((c,u,d)=>{const{sampleRate:b,samplesPerPixel:h}=e,f=t[c];if(!f)return!1;const y=f.clips[u];if(!y)return!1;const x=y.startSample/b,m=(y.startSample+y.durationSamples)/b;if(d<=x||d>=m)return console.warn("Split time is outside clip bounds"),!1;const p=Math.round(d*b),w=Math.floor(p/h),C=y.startSample+y.durationSamples,v=w*h,k=y.startSample,S=v-k,$=v,M=C-$,D=v-y.startSample,I=zt({audioBuffer:y.audioBuffer,startSample:k,durationSamples:S,offsetSamples:y.offsetSamples,sampleRate:y.sampleRate,sourceDurationSamples:y.sourceDurationSamples,gain:y.gain,name:y.name?`${y.name} (1)`:void 0,color:y.color,fadeIn:y.fadeIn,waveformData:y.waveformData}),A=zt({audioBuffer:y.audioBuffer,startSample:$,durationSamples:M,offsetSamples:y.offsetSamples+D,sampleRate:y.sampleRate,sourceDurationSamples:y.sourceDurationSamples,gain:y.gain,name:y.name?`${y.name} (2)`:void 0,color:y.color,waveformData:y.waveformData,fadeOut:y.fadeOut}),B=[...f.clips];B.splice(u,1,I,A);const _=[...t];return _[c]={...f,clips:B},n(_),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(b=>b.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],d=r.current??0;for(let b=0;b<u.clips.length;b++){const h=u.clips[b],f=h.startSample/a,y=(h.startSample+h.durationSamples)/a;if(d>f&&d<y)return console.log(`Splitting clip on track "${u.name}" at ${d}s`),o(c,b,d)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,o,a]),splitClipAt:o}},Mt=e=>{const{shortcuts:t,enabled:n=!0}=e,a=i.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||r.shiftKey===l.shiftKey,b=l.metaKey===void 0||r.metaKey===l.metaKey,h=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&d&&b&&h});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])},Ko=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("+")},Uo=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Re(),{setCurrentTime:s,play:o,pause:l,stop:c}=pe(),{playoutRef:u}=Me(),d=i.useCallback(()=>{r?l():o()},[r,o,l]),b=i.useCallback(()=>{c()},[c]),h=i.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[r,u,s,o]),y=a??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:b,description:"Stop",preventDefault:!0},{key:"0",action:h,description:"Rewind to start",preventDefault:!0}],...n];return Mt({shortcuts:y,enabled:t}),{rewindToStart:h,togglePlayPause:d,stopPlayback:b,shortcuts:y}},Zt=.01,kt=.01;function qo({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:b=0,onPlay:h}){const f=i.useMemo(()=>t?e.findIndex(D=>D.id===t):-1,[e,t]),y=i.useCallback(D=>{if(!c?.current||!u||!d)return;const I=e.find(N=>N.id===D);if(!I)return;const A=c.current,B=A.clientWidth,_=I.start*d/u+b,F=I.end*d/u+b,O=(_+F)/2,G=A.scrollLeft,j=G,q=G+B;if(_<j||F>q){const N=Math.max(0,O-B/2);A.scrollTo({left:N,behavior:"smooth"})}},[e,c,u,d,b]);i.useEffect(()=>{t&&c?.current&&u&&d&&y(t)},[t,y,c,u,d]);const x=i.useCallback(D=>{if(f<0)return;const I=e[f],A=Math.max(0,Math.min(I.end-.1,I.start+D)),B=A-I.start,_=[...e];if(_[f]={...I,start:A},s&&f>0){const F=_[f-1];Math.abs(F.end-I.start)<Zt&&(_[f-1]={...F,end:Math.max(F.start+.1,F.end+B)})}else if(!s&&f>0){const F=_[f-1];A<F.end&&(_[f-1]={...F,end:A})}n(_)},[e,f,s,n]),m=i.useCallback(D=>{if(f<0)return;const I=e[f],A=Math.max(I.start+.1,Math.min(r,I.end+D)),B=A-I.end,_=[...e];if(_[f]={...I,end:A},s&&f<e.length-1){const F=_[f+1];if(Math.abs(F.start-I.end)<Zt){const O=Math.min(F.end-.1,F.start+B);_[f+1]={...F,start:O};let G=f+1;for(;G<_.length-1;){const j=_[G],q=_[G+1];if(Math.abs(q.start-e[G].end)<Zt){const N=j.end-e[G].end;_[G+1]={...q,start:Math.min(q.end-.1,q.start+N)},G++}else break}}}else if(!s&&f<e.length-1){const F=_[f+1];if(A>F.start){_[f+1]={...F,start:A};let O=f+1;for(;O<_.length-1;){const G=_[O],j=_[O+1];if(G.end>j.start)_[O+1]={...j,start:G.end},O++;else break}}}n(_)},[e,f,r,s,n]),p=i.useCallback(()=>{!a||e.length===0||(f<=0?a(e[e.length-1].id):a(e[f-1].id))},[e,f,a]),w=i.useCallback(()=>{!a||e.length===0||(f<0||f>=e.length-1?a(e[0].id):a(e[f+1].id))},[e,f,a]),C=i.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),v=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(f<0||!h)return;const D=e[f],I=o?void 0:D.end-D.start;h(D.start,I)},[e,f,o,h]),$=i.useMemo(()=>[{key:"[",action:()=>x(-kt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>x(kt),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>m(-kt),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>m(kt),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:S,description:"Play selected annotation",preventDefault:!0}],[x,m,S]),M=i.useMemo(()=>[{key:"ArrowUp",action:p,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:p,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:w,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:w,description:"Select next annotation",preventDefault:!0},{key:"Home",action:C,description:"Select first annotation",preventDefault:!0},{key:"End",action:v,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:k,description:"Deselect annotation",preventDefault:!0}],[p,w,C,v,k]);return Mt({shortcuts:$,enabled:l&&f>=0}),Mt({shortcuts:M,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:x,moveEndBoundary:m,selectPrevious:p,selectNext:w,selectFirst:C,selectLast:v,clearSelection:k,scrollToAnnotation:y,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}]}],Yt=e=>Ct.find(t=>t.id===e),Jo=e=>Ct.filter(t=>t.category===e),Qo=[{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"}],es={reverb:P.Reverb,freeverb:P.Freeverb,jcReverb:P.JCReverb,feedbackDelay:P.FeedbackDelay,pingPongDelay:P.PingPongDelay,chorus:P.Chorus,phaser:P.Phaser,tremolo:P.Tremolo,vibrato:P.Vibrato,autoPanner:P.AutoPanner,autoFilter:P.AutoFilter,autoWah:P.AutoWah,eq3:P.EQ3,distortion:P.Distortion,bitCrusher:P.BitCrusher,chebyshev:P.Chebyshev,compressor:P.Compressor,limiter:P.Limiter,gate:P.Gate,stereoWidener:P.StereoWidener};let ts=0;const ns=()=>`effect_${Date.now()}_${++ts}`;function pt(e,t){const n=es[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;a[o.name]=l});const r=new n(a),s=ns();return{effect:r,id:e.id,instanceId:s,dispose(){try{r.disconnect(),r.dispose()}catch{}},setParameter(o,l){o==="wet"&&r.wet?r.wet.value=l:r[o]!==void 0&&(r[o]?.value!==void 0?r[o].value=l:r[o]=l)},getParameter(o){if(o==="wet"&&r.wet)return r.wet.value;if(r[o]!==void 0)return r[o]?.value!==void 0?r[o].value:r[o]},connect(o){r.connect(o)},disconnect(){try{r.disconnect()}catch{}}}}function as(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 rs(e=256){const[t,n]=i.useState([]),a=i.useRef(t);a.current=t;const r=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(m=>{const p=o.current;if(!p)return;const{masterGainNode:w,destination:C,analyserNode:v}=p;try{w.disconnect()}catch{}const k=m.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)w.connect(v),v.connect(C);else{let S=w;k.forEach($=>{try{$.disconnect()}catch{}S.connect($.effect),S=$.effect}),S.connect(v),v.connect(C)}},[]),c=i.useCallback(m=>{const p=Yt(m);if(!p){console.error(`Unknown effect: ${m}`);return}const w={};p.parameters.forEach(k=>{w[k.name]=k.default});const C=pt(p,w);r.current.set(C.instanceId,C);const v={instanceId:C.instanceId,effectId:p.id,definition:p,params:w,bypassed:!1};n(k=>[...k,v])},[]),u=i.useCallback(m=>{const p=r.current.get(m);p&&(p.dispose(),r.current.delete(m)),n(w=>w.filter(C=>C.instanceId!==m))},[]),d=i.useCallback((m,p,w)=>{const C=r.current.get(m);C&&C.setParameter(p,w),n(v=>v.map(k=>k.instanceId===m?{...k,params:{...k.params,[p]:w}}:k))},[]),b=i.useCallback(m=>{const p=a.current.find(v=>v.instanceId===m);if(!p)return;const w=!p.bypassed,C=r.current.get(m);if(C){const v=p.params.wet??1;C.setParameter("wet",w?0:v)}n(v=>v.map(k=>k.instanceId===m?{...k,bypassed:w}:k))},[]),h=i.useCallback((m,p)=>{n(w=>{const C=[...w],[v]=C.splice(m,1);return C.splice(p,0,v),C})},[]),f=i.useCallback(()=>{r.current.forEach(m=>m.dispose()),r.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const y=i.useCallback((m,p,w)=>{const C=new P.Analyser("fft",e);s.current=C,o.current={masterGainNode:m,destination:p,analyserNode:C};const k=a.current.map(S=>r.current.get(S.instanceId)).filter(S=>S!==void 0);if(k.length===0)m.connect(C),C.connect(p);else{let S=m;k.forEach($=>{S.connect($.effect),S=$.effect}),S.connect(C),C.connect(p)}return function(){C.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{r.current.forEach(m=>m.dispose()),r.current.clear()},[]);const x=i.useCallback(()=>{const m=t.filter(p=>!p.bypassed);if(m.length!==0)return(p,w,C)=>{const v=[];for(const k of m){const S=pt(k.definition,k.params);v.push(S)}if(v.length===0)p.connect(w);else{let k=p;v.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(w)}return function(){v.forEach(S=>S.dispose())}}},[t]);return{activeEffects:t,availableEffects:Ct,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:b,reorderEffects:h,clearAllEffects:f,masterEffects:y,createOfflineEffectsFunction:x,analyserRef:s}}function os(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),a=i.useRef(new Map),r=i.useCallback((f,y)=>{const x=a.current.get(f);if(!x)return;const{graphEnd:m,masterGainNode:p}=x,w=n.current.get(f);try{m.disconnect()}catch{}const C=y.map(v=>w?.get(v.instanceId)).filter(v=>v!==void 0);if(C.length===0)m.connect(p);else{let v=m;C.forEach(k=>{try{k.disconnect()}catch{}v.connect(k.effect),v=k.effect}),v.connect(p)}},[]),s=i.useCallback((f,y)=>{const x=Yt(y);if(!x){console.error(`Unknown effect: ${y}`);return}const m={};x.parameters.forEach(C=>{m[C.name]=C.default});const p=pt(x,m);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(p.instanceId,p);const w={instanceId:p.instanceId,effectId:x.id,definition:x,params:m,bypassed:!1};t(C=>{const v=new Map(C),k=v.get(f)||[];return v.set(f,[...k,w]),v})},[]),o=i.useCallback((f,y)=>{const x=n.current.get(f),m=x?.get(y);m&&(m.dispose(),x?.delete(y)),t(p=>{const w=new Map(p),C=w.get(f)||[];return w.set(f,C.filter(v=>v.instanceId!==y)),w})},[]),l=i.useCallback((f,y,x,m)=>{const w=n.current.get(f)?.get(y);w&&w.setParameter(x,m),t(C=>{const v=new Map(C),k=v.get(f)||[];return v.set(f,k.map(S=>S.instanceId===y?{...S,params:{...S.params,[x]:m}}:S)),v})},[]),c=i.useCallback((f,y)=>{const m=(d.current.get(f)||[]).find(v=>v.instanceId===y);if(!m)return;const p=!m.bypassed,C=n.current.get(f)?.get(y);if(C){const v=m.params.wet??1;C.setParameter("wet",p?0:v)}t(v=>{const k=new Map(v),S=k.get(f)||[];return k.set(f,S.map($=>$.instanceId===y?{...$,bypassed:p}:$)),k})},[]),u=i.useCallback(f=>{const y=n.current.get(f);y&&(y.forEach(x=>x.dispose()),y.clear()),t(x=>{const m=new Map(x);return m.set(f,[]),m})},[]),d=i.useRef(e);d.current=e;const b=i.useCallback(f=>(y,x,m)=>{a.current.set(f,{graphEnd:y,masterGainNode:x});const p=d.current.get(f)||[],w=n.current.get(f),C=p.map(v=>w?.get(v.instanceId)).filter(v=>v!==void 0);if(C.length===0)y.connect(x);else{let v=y;C.forEach(k=>{v.connect(k.effect),v=k.effect}),v.connect(x)}return function(){a.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,y)=>{r(y,f)})},[e,r]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(y=>y.dispose()),f.clear()}),n.current.clear()},[]);const h=i.useCallback(f=>{const x=(e.get(f)||[]).filter(m=>!m.bypassed);if(x.length!==0)return(m,p,w)=>{const C=[];for(const v of x){const k=pt(v.definition,v.params);C.push(k)}if(C.length===0)m.connect(p);else{let v=m;C.forEach(k=>{v.connect(k.effect),v=k.effect}),v.connect(p)}return function(){C.forEach(k=>k.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:b,createOfflineTrackEffectsFunction:h,availableEffects:Ct}}function ss(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,o=n/8,l=a*o,c=r*l,u=s*l,d=44,b=d+u,h=new ArrayBuffer(b),f=new DataView(h);St(f,0,"RIFF"),f.setUint32(4,b-8,!0),St(f,8,"WAVE"),St(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),St(f,36,"data"),f.setUint32(40,u,!0);const y=[];for(let m=0;m<a;m++)y.push(e.getChannelData(m));let x=d;if(n===16)for(let m=0;m<s;m++)for(let p=0;p<a;p++){const w=y[p][m],C=Math.max(-1,Math.min(1,w)),v=C<0?C*32768:C*32767;f.setInt16(x,v,!0),x+=2}else for(let m=0;m<s;m++)for(let p=0;p<a;p++)f.setFloat32(x,y[p][m],!0),x+=4;return new Blob([h],{type:"audio/wav"})}function St(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 ta(){const[e,t]=i.useState(!1),[n,a]=i.useState(0),[r,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:b="master",trackIndex:h,autoDownload:f=!0,applyEffects:y=!0,effectsFunction:x,createOfflineTrackEffects:m,bitDepth:p=16,onProgress:w}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(b==="individual"&&(h===void 0||h<0||h>=l.length))throw new Error("Invalid track index for individual export");const C=l[0].clips[0]?.sampleRate||44100;let v=0;for(const A of l)for(const B of A.clips){const _=B.startSample+B.durationSamples;v=Math.max(v,_)}v+=Math.round(C*.1);const k=v/C,S=b==="individual"?[{track:l[h],state:c[h],index:h}]:l.map((A,B)=>({track:A,state:c[B],index:B})),$=c.some(A=>A.soloed),M=!!m;let D;if((x||M)&&y)D=await ls(S,c,$,k,C,x,m,A=>{a(A),w?.(A)});else{const A=new OfflineAudioContext(2,v,C);let B=0;const _=S.reduce((F,{track:O})=>F+O.clips.length,0);for(const{track:F,state:O}of S)if(!(O.muted&&!O.soloed)&&!($&&!O.soloed))for(const G of F.clips){await us(A,G,O,C,y),B++;const j=B/_*.5;a(j),w?.(j)}a(.5),w?.(.5),D=await A.startRendering()}a(.9),w?.(.9);const I=ss(D,{bitDepth:p});if(a(1),w?.(1),f){const A=b==="individual"?`${d}_${l[h].name}`:d;is(I,`${A}.wav`)}return{audioBuffer:D,blob:I,duration:k}}catch(C){const v=C instanceof Error?C.message:"Export failed";throw s(v),C}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function ls(e,t,n,a,r,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:b,Player:h,ToneAudioBuffer:f}=await import("tone");l(.1);let y;try{y=await c(async({transport:x,destination:m})=>{const p=new u(0);let w;s?w=s(p,m,!0):p.connect(m);for(const{track:C,state:v}of e){if(v.muted&&!v.soloed||n&&!v.soloed)continue;const k=new u(cs(v.volume)),S=new b(v.pan),$=new d(v.muted?0:1),M=o?.(C.id);M?M($,p,!0):$.connect(p),S.connect($),k.connect(S);for(const D of C.clips){const{audioBuffer:I,startSample:A,durationSamples:B,offsetSamples:_,gain:F,fadeIn:O,fadeOut:G}=D,j=A/r,q=B/r,N=_/r,re=new f(I),J=new h(re),oe=new d(F);if(J.connect(oe),oe.connect(k),O){const ie=j,de=j+O.duration,fe=oe.gain._param;fe.setValueAtTime(0,ie),fe.linearRampToValueAtTime(F,de)}if(G){const ie=j+q-G.duration,de=j+q,fe=oe.gain._param;fe.setValueAtTime(F,ie),fe.linearRampToValueAtTime(0,de)}J.start(j,N,q)}}x.start(0)},a,2,r)}catch(x){throw x instanceof Error?x:new Error(`Tone.Offline rendering failed: ${String(x)}`)}return l(.9),y.get()}function cs(e){return 20*Math.log10(Math.max(e,1e-4))}async function us(e,t,n,a,r){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:d,fadeOut:b}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const h=o/a,f=l/a,y=c/a,x=e.createBufferSource();x.buffer=s;const m=e.createGain(),p=u*n.volume,w=e.createStereoPanner();if(w.pan.value=n.pan,x.connect(m),m.connect(w),w.connect(e.destination),r){if(d?m.gain.setValueAtTime(0,h):m.gain.setValueAtTime(p,h),d){const C=h,v=h+d.duration;yn(m.gain,C,v,0,p,d.type||"linear")}if(b){const C=h+f-b.duration,v=h+f;(!d||d.duration<f-b.duration)&&m.gain.setValueAtTime(p,C),yn(m.gain,C,v,p,0,b.type||"linear")}}else m.gain.setValueAtTime(p,h);x.start(h,y,f)}function yn(e,t,n,a,r,s){const o=n-t;if(!(o<=0))switch(s){case"linear":e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n);break;case"exponential":const l=Math.max(a,1e-4),c=Math.max(r,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),r===0&&e.setValueAtTime(0,n);break;case"logarithmic":const u=xn(a,r,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=xn(a,r,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function xn(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=i.createContext(null),aa=i.createContext(null),ra=i.createContext(null),oa=i.createContext(null),sa=i.createContext(null),ds=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:b,onAnnotationUpdate:h,onAnnotationsChange:f,barWidth:y=1,barGap:x=0,progressBarWidth:m,children:p})=>{const w=m??y+x,C=i.useMemo(()=>{if(!u?.annotations)return[];if(process.env.NODE_ENV!=="production"&&u.annotations.length>0){const R=u.annotations[0];if(typeof R.start!="number"||typeof R.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 R.start),[]}return u.annotations},[u?.annotations]),v=i.useRef(C);v.current=C;const[k,S]=i.useState(null),[$,M]=i.useState(!1),[D,I]=i.useState(0),[A,B]=i.useState(0),[_,F]=i.useState([]),[O,G]=i.useState([]),[j,q]=i.useState([]),[N,re]=i.useState(0),[J,oe]=i.useState(0),[ie,de]=i.useState(null),[fe,$e]=i.useState(o),[le,V]=i.useState(u?.isContinuousPlay??!1),[ue,Y]=i.useState(u?.linkEndpoints??!1),[U,se]=i.useState(u?.editable??!1),[ge,Q]=i.useState(!1),[Be,ze]=i.useState(0),[Ne,Le]=i.useState(0),[ee,Xe]=i.useState(!1),W=i.useRef(null),he=i.useRef(0),be=i.useRef(0),ve=i.useRef(null),nt=i.useRef(j),L=i.useRef(0),ae=i.useRef(0),Ae=i.useRef(null),me=i.useRef(null),Ze=i.useRef(!1),Ye=i.useRef(u?.isContinuousPlay??!1),Ue=i.useRef(null),at=i.useRef(r),it=i.useRef(!1),Bt=i.useRef(0),Z=i.useRef(0),H=i.useRef(0),te=i.useRef(0),{timeFormat:ye,setTimeFormat:Ce,formatTime:Ee}=Un(),Te=qn({initialSamplesPerPixel:r,zoomLevels:s}),De=Te.samplesPerPixel,{masterVolume:ne,setMasterVolume:we}=Jn({playoutRef:W,initialVolume:1}),qe=i.useCallback(R=>{Ye.current=R,V(R)},[]),Oe=i.useCallback(R=>{Ue.current=R,S(R)},[]),lt=i.useCallback(R=>{it.current=R,Q(R)},[]),Ve=i.useCallback((R,z)=>{H.current=R,te.current=z,ze(R),Le(z)},[]),Je=i.useCallback(()=>{const R=Bt.current,z=Z.current;R!==z&&z>R&&Ve(R,z)},[Ve]),dt=i.useCallback(()=>{Ve(0,0)},[Ve]);i.useEffect(()=>{Ze.current=fe},[fe]),i.useEffect(()=>{nt.current=j},[j]),i.useEffect(()=>{Bt.current=N,Z.current=J},[N,J]),i.useEffect(()=>{if(!me.current||!_.length)return;const R=me.current,z=at.current,K=De;if(z===K)return;const ce=c.show?c.width:0,X=R.clientWidth,ke=R.scrollLeft+X/2-ce,et=_[0].sampleRate,Se=ke*z/et*et/K,We=Math.max(0,Se+ce-X/2);R.scrollLeft=We,at.current=K},[De,_,c]);const Qe=i.useRef(null);i.useEffect(()=>{if(Xe(!1),e.length===0){F([]),B(0),q([]),G([]),W.current&&(W.current.dispose(),W.current=null);return}const R=$,z=be.current;return W.current&&R&&(W.current.stop(),ve.current&&(cancelAnimationFrame(ve.current),ve.current=null),Qe.current={position:z}),(async()=>{try{const ce=[];e.forEach(xe=>{xe.clips.length>0&&xe.clips[0].audioBuffer&&ce.push(xe.clips[0].audioBuffer)});let X=0;e.forEach(xe=>{xe.clips.forEach(Se=>{const We=Se.sampleRate,yt=(Se.startSample+Se.durationSamples)/We;X=Math.max(X,yt)})}),F(ce),B(X),q(xe=>xe.length===e.length?xe.map((Se,We)=>({...Se,name:e[We].name})):e.map(Se=>({name:Se.name,muted:Se.muted,soloed:Se.soloed,volume:Se.volume,pan:Se.pan}))),W.current&&W.current.dispose();const Ie=new Xa({effects:d}),ke=nt.current;e.forEach((xe,Se)=>{const We=xe.clips.filter(rt=>rt.audioBuffer);if(We.length>0){const rt=We[0].sampleRate,yt=Math.min(...We.map(Pe=>Pe.startSample/rt)),Ea=Math.max(...We.map(Pe=>(Pe.startSample+Pe.durationSamples)/rt)),xt=ke[Se],Ta={id:`track-${Se}`,name:xe.name,gain:xt?.volume??xe.volume,muted:xt?.muted??xe.muted,soloed:xt?.soloed??xe.soloed,stereoPan:xt?.pan??xe.pan,startTime:yt,endTime:Ea},Da=We.map(Pe=>{const Wt=Pe.sampleRate;return{buffer:Pe.audioBuffer,startTime:Pe.startSample/Wt-yt,duration:Pe.durationSamples/Wt,offset:Pe.offsetSamples/Wt,fadeIn:Pe.fadeIn,fadeOut:Pe.fadeOut,gain:Pe.gain}});Ie.addTrack({clips:Da,track:Ta,effects:xe.effects})}}),Ie.applyInitialSoloState(),W.current=Ie,Xe(!0);const et=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:X}});window.dispatchEvent(et),b?.()}catch(ce){console.error("Error loading audio:",ce)}})(),()=>{ve.current&&cancelAnimationFrame(ve.current),W.current&&W.current.dispose()}},[e,b,$]),i.useEffect(()=>{if(e.length===0)return;const R=16,z=e.map(K=>K.clips.map(X=>{if(X.waveformData){const ke=Kn(X.waveformData,De,0,X.offsetSamples,X.durationSamples);return{clipId:X.id,trackName:K.name,peaks:{length:ke.length,data:[ke.data],bits:ke.bits},startSample:X.startSample,durationSamples:X.durationSamples,fadeIn:X.fadeIn,fadeOut:X.fadeOut}}if(!X.audioBuffer)return console.warn(`Clip "${X.name||X.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:X.id,trackName:K.name,peaks:{length:0,data:[],bits:R},startSample:X.startSample,durationSamples:X.durationSamples,fadeIn:X.fadeIn,fadeOut:X.fadeOut};const Ie=xo(X.audioBuffer,De,n,R,X.offsetSamples,X.durationSamples);return{clipId:X.id,trackName:K.name,peaks:Ie,startSample:X.startSample,durationSamples:X.durationSamples,fadeIn:X.fadeIn,fadeOut:X.fadeOut}}));G(z)},[e,De,n]);const Ke=i.useCallback(()=>{ve.current&&(cancelAnimationFrame(ve.current),ve.current=null);const R=()=>{const z=P.getContext().currentTime-L.current,K=ae.current+z;be.current=K,I(K);const ce=v.current;if(ce.length>0){const Ie=ce.find(ke=>K>=ke.start&&K<ke.end);if(Ye.current)Ie&&Ie.id!==Ue.current?Oe(Ie.id):!Ie&&Ue.current!==null&&Oe(null);else if(Ue.current){const ke=ce.find(et=>et.id===Ue.current);if(ke&&K>=ke.end){W.current&&W.current.stop(),M(!1),be.current=he.current,I(he.current);return}}else Ie&&Oe(Ie.id)}if(Ze.current&&me.current&&_.length>0){const Ie=me.current,ke=_[0].sampleRate,et=K*ke/at.current,xe=Ie.clientWidth,Se=c.show?c.width:0,We=et+Se,rt=Math.max(0,We-xe/2);Ie.scrollLeft=rt}if(Ae.current!==null&&K>=Ae.current){W.current&&W.current.stop(),M(!1),be.current=Ae.current,I(Ae.current),Ae.current=null;return}const X=H.current!==te.current&&te.current>H.current;if(it.current&&X&&K>=te.current){W.current?.stop();const ke=P.getContext().currentTime;L.current=ke,ae.current=H.current,be.current=H.current,W.current?.play(ke,H.current),ve.current=requestAnimationFrame(R);return}if(K>=A){W.current&&W.current.stop(),M(!1),be.current=he.current,I(he.current),Oe(null);return}ve.current=requestAnimationFrame(R)};ve.current=requestAnimationFrame(R)},[A,_,De,le]),Fe=i.useCallback(()=>{ve.current&&(cancelAnimationFrame(ve.current),ve.current=null)},[]);i.useEffect(()=>{(async()=>{if($&&ve.current&&W.current)if(le){const z=be.current;W.current.stop(),Fe(),await W.current.init(),W.current.setOnPlaybackComplete(()=>{});const ce=P.getContext().currentTime;L.current=ce,ae.current=z,W.current.play(ce,z),Ke()}else Fe(),Ke()})()},[le,$,Ke,Fe]),i.useEffect(()=>{(async()=>{if(Qe.current&&W.current){const{position:z}=Qe.current;Qe.current=null,await W.current.init(),W.current.setOnPlaybackComplete(()=>{});const ce=P.getContext().currentTime;L.current=ce,ae.current=z,W.current.play(ce,z),M(!0),Ke()}})()},[e,Ke]);const ft=i.useCallback(async(R,z)=>{if(!W.current||_.length===0)return;await W.current.init();const K=R??be.current;he.current=K,be.current=K,W.current.setOnPlaybackComplete(()=>{}),W.current.stop(),Fe();const X=P.getContext().currentTime;L.current=X,ae.current=K,Ae.current=z!==void 0?K+z:null,W.current.play(X,K,z),M(!0),Ke()},[_.length,Ke,Fe]),pa=i.useCallback(()=>{if(!W.current)return;const R=P.getContext().currentTime-L.current,z=ae.current+R;W.current.pause(),M(!1),Fe(),be.current=z,I(z)},[Fe]),ga=i.useCallback(()=>{W.current&&(W.current.stop(),M(!1),Fe(),be.current=he.current,I(he.current),Oe(null))},[Fe]),ba=i.useCallback(R=>{const z=Math.max(0,Math.min(R,A));be.current=z,I(z),$&&W.current&&(W.current.stop(),Fe(),ft(z))},[A,$,ft,Fe]),va=i.useCallback((R,z)=>{const K=[...j];if(K[R]={...K[R],muted:z},q(K),W.current){const ce=`track-${R}`;W.current.setMute(ce,z)}},[j]),Ca=i.useCallback((R,z)=>{const K=[...j];if(K[R]={...K[R],soloed:z},q(K),W.current){const ce=`track-${R}`;W.current.setSolo(ce,z)}},[j]),ya=i.useCallback((R,z)=>{const K=[...j];if(K[R]={...K[R],volume:z},q(K),W.current){const ce=`track-${R}`,X=W.current.getTrack(ce);X&&X.setVolume(z)}},[j]),xa=i.useCallback((R,z)=>{const K=[...j];if(K[R]={...K[R],pan:z},q(K),W.current){const ce=`track-${R}`,X=W.current.getTrack(ce);X&&X.setPan(z)}},[j]),wa=i.useCallback((R,z)=>{re(R),oe(z),be.current=R,I(R),$&&W.current&&(W.current.stop(),W.current.play(P.getContext().currentTime,R))},[$]),ka=i.useCallback(R=>{me.current=R},[]),Ft=i.useRef(f);Ft.current=f;const Sa=i.useCallback(R=>{const z=typeof R=="function"?R(v.current):R;if(!Ft.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}Ft.current(z)},[]),Aa=_[0]?.sampleRate||44100,qt=t?30:0,Ia=e.length*a+qt,Jt={isPlaying:$,currentTime:D,currentTimeRef:be,playbackStartTimeRef:L,audioStartPositionRef:ae},Qt={continuousPlay:le,linkEndpoints:ue,annotationsEditable:U,isAutomaticScroll:fe,isLoopEnabled:ge,annotations:C,activeAnnotationId:k,selectionStart:N,selectionEnd:J,selectedTrackId:ie,loopStart:Be,loopEnd:Ne},en={play:ft,pause:pa,stop:ga,seekTo:ba,setCurrentTime:R=>{be.current=R,I(R)},setTrackMute:va,setTrackSolo:Ca,setTrackVolume:ya,setTrackPan:xa,setSelection:wa,setSelectedTrackId:de,setTimeFormat:Ce,formatTime:Ee,zoomIn:Te.zoomIn,zoomOut:Te.zoomOut,setMasterVolume:we,setAutomaticScroll:R=>{$e(R)},setScrollContainer:ka,scrollContainerRef:me,setContinuousPlay:qe,setLinkEndpoints:Y,setAnnotationsEditable:se,setAnnotations:Sa,setActiveAnnotationId:Oe,setLoopEnabled:lt,setLoopRegion:Ve,setLoopRegionFromSelection:Je,clearLoopRegion:dt},tn={duration:A,audioBuffers:_,peaksDataArray:O,trackStates:j,tracks:e,sampleRate:Aa,waveHeight:a,timeScaleHeight:qt,minimumPlaylistHeight:Ia,controls:c,playoutRef:W,samplesPerPixel:De,timeFormat:ye,masterVolume:ne,canZoomIn:Te.canZoomIn,canZoomOut:Te.canZoomOut,barWidth:y,barGap:x,progressBarWidth:w,isReady:ee,mono:n},Ma={...Jt,...Qt,...en,...tn},$a={...Fn,...l};return g.jsx(T.ThemeProvider,{theme:$a,children:g.jsx(na.Provider,{value:Jt,children:g.jsx(aa.Provider,{value:Qt,children:g.jsx(ra.Provider,{value:en,children:g.jsx(oa.Provider,{value:tn,children:g.jsx(sa.Provider,{value:Ma,children:p})})})})})})},Re=()=>{const e=i.useContext(na);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},_e=()=>{const e=i.useContext(aa);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},pe=()=>{const e=i.useContext(ra);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},Me=()=>{const e=i.useContext(oa);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},fs=()=>{const e=i.useContext(sa);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var ms=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate,"preservesPitch"in this.audioElement?this.audioElement.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?this.audioElement.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(this.audioElement.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},hs=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 ms({...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 ia=i.createContext(null),la=i.createContext(null),ca=i.createContext(null),ua=i.createContext(null),ps=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:s=!1,theme:o,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:d=0,progressBarWidth:b,onAnnotationsChange:h,onReady:f,children:y})=>{const x=b??u+d,[m,p]=i.useState(!1),[w,C]=i.useState(0),[v,k]=i.useState(0),[S,$]=i.useState([]),[M,D]=i.useState(r),I=i.useMemo(()=>{if(!c?.annotations)return[];if(process.env.NODE_ENV!=="production"&&c.annotations.length>0){const L=c.annotations[0];if(typeof L.start!="number"||typeof L.end!="number")return console.error("[waveform-playlist] Annotations must have numeric start/end values. In v6, use parseAeneas() from @waveform-playlist/annotations before passing annotations. Received start type: "+typeof L.start),[]}return c.annotations},[c?.annotations]),A=i.useRef(I);A.current=I;const[B,_]=i.useState(null),[F,O]=i.useState(c?.isContinuousPlay??!1),[G]=i.useState(t),[j,q]=i.useState(s),N=i.useRef(null),re=i.useRef(0),J=i.useRef(null),oe=i.useRef(F),ie=i.useRef(null),de=i.useRef(null),fe=i.useRef(s),$e=i.useRef(t);i.useEffect(()=>{oe.current=F},[F]),i.useEffect(()=>{fe.current=j},[j]);const le=i.useCallback(L=>{ie.current=L,_(L)},[]),V=i.useCallback(L=>{oe.current=L,O(L)},[]),ue=i.useCallback(L=>{de.current=L},[]),Y=e.waveformData.sample_rate;i.useEffect(()=>{const L=new hs({playbackRate:r});L.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const ae=L.getTrack(L.track?.id??"");return ae&&ae.setOnTimeUpdateCallback(Ae=>{re.current=Ae}),L.setOnPlaybackComplete(()=>{J.current&&(cancelAnimationFrame(J.current),J.current=null),p(!1),le(null),re.current=0,C(0)}),N.current=L,k(e.waveformData.duration),f?.(),()=>{J.current&&cancelAnimationFrame(J.current),L.dispose()}},[e.source,e.waveformData,e.name,r,f]),i.useEffect(()=>{const L=Kn(e.waveformData,G,0,0,Math.ceil(e.waveformData.duration*Y)),ae={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:L.length,data:[L.data],bits:L.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*Y)};$([[ae]])},[e.waveformData,e.name,G,Y]);const U=i.useCallback(()=>{J.current&&cancelAnimationFrame(J.current);const L=()=>{const ae=N.current?.getCurrentTime()??0;re.current=ae,C(ae);const Ae=A.current;if(Ae.length>0){const me=Ae.find(Ze=>ae>=Ze.start&&ae<Ze.end);if(oe.current)me&&me.id!==ie.current?le(me.id):!me&&ie.current!==null&&le(null);else if(ie.current){const Ze=Ae.find(Ye=>Ye.id===ie.current);if(Ze&&ae>=Ze.end){N.current?.stop(),p(!1);return}}else me&&le(me.id)}if(fe.current&&de.current){const me=de.current,Ze=ae*Y/$e.current,Ye=me.clientWidth,Ue=l.show?l.width:0,at=Ze+Ue,it=Math.max(0,at-Ye/2);me.scrollLeft=it}J.current=requestAnimationFrame(L)};J.current=requestAnimationFrame(L)},[le,Y,l]),se=i.useCallback(()=>{J.current&&(cancelAnimationFrame(J.current),J.current=null)},[]),ge=i.useCallback(L=>{if(!N.current)return;const ae=L??re.current;N.current.play(void 0,ae),p(!0),U()},[U]),Q=i.useCallback(()=>{N.current&&(N.current.pause(),p(!1),se(),C(N.current.getCurrentTime()))},[se]),Be=i.useCallback(()=>{N.current&&(N.current.stop(),p(!1),se(),re.current=0,C(0),le(null))},[se,le]),ze=i.useCallback(L=>{const ae=Math.max(0,Math.min(L,v));re.current=ae,C(ae),N.current&&N.current.seekTo(ae)},[v]),Ne=i.useCallback(L=>{const ae=Math.max(.5,Math.min(2,L));D(ae),N.current&&N.current.setPlaybackRate(ae)},[]),Le=a?30:0,ee=i.useMemo(()=>({isPlaying:m,currentTime:w,currentTimeRef:re}),[m,w]),Xe=i.useMemo(()=>({continuousPlay:F,annotations:I,activeAnnotationId:B,playbackRate:M,isAutomaticScroll:j}),[F,I,B,M,j]),W=i.useRef(h);W.current=h;const he=i.useCallback(L=>{const ae=typeof L=="function"?L(A.current):L;if(!W.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}W.current(ae)},[]),be=i.useMemo(()=>({play:ge,pause:Q,stop:Be,seekTo:ze,setPlaybackRate:Ne,setContinuousPlay:V,setAnnotations:he,setActiveAnnotationId:le,setAutomaticScroll:L=>{q(L)},setScrollContainer:ue,scrollContainerRef:de}),[ge,Q,Be,ze,Ne,V,he,le,ue]),ve=i.useMemo(()=>({duration:v,peaksDataArray:S,sampleRate:Y,waveHeight:n,timeScaleHeight:Le,samplesPerPixel:G,playoutRef:N,controls:l,barWidth:u,barGap:d,progressBarWidth:x}),[v,S,Y,n,Le,G,l,u,d,x]),nt={...Fn,...o};return g.jsx(T.ThemeProvider,{theme:nt,children:g.jsx(ia.Provider,{value:ee,children:g.jsx(la.Provider,{value:Xe,children:g.jsx(ca.Provider,{value:be,children:g.jsx(ua.Provider,{value:ve,children:y})})})})})},Tt=()=>{const e=i.useContext(ia);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Dt=()=>{const e=i.useContext(la);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},Kt=()=>{const e=i.useContext(ca);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Rt=()=>{const e=i.useContext(ua);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},gs=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Re(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=_e(),{play:o}=pe(),l=async()=>{if(a!==r&&r>a)if(s)await o(a);else{const u=r-a;await o(a,u)}else await o(n.current??0)};return g.jsx(He,{onClick:l,disabled:t,className:e,children:"Play"})},bs=({className:e})=>{const{isPlaying:t}=Re(),{pause:n}=pe();return g.jsx(He,{onClick:n,disabled:!t,className:e,children:"Pause"})},vs=({className:e})=>{const{isPlaying:t}=Re(),{stop:n}=pe();return g.jsx(He,{onClick:n,disabled:!t,className:e,children:"Stop"})},Cs=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=pe(),{playoutRef:r}=Me(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return g.jsx(He,{onClick:s,className:e,children:"Rewind"})},ys=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:a}=pe(),{duration:r,playoutRef:s}=Me(),o=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return g.jsx(He,{onClick:o,className:e,children:"Fast Forward"})},xs=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=pe(),{playoutRef:o}=Me(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&o.current&&(o.current.stop(),r(c))};return g.jsx(He,{onClick:l,className:t,children:"Skip Backward"})},ws=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Re(),{play:r,setCurrentTime:s}=pe(),{duration:o,playoutRef:l}=Me(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),a&&l.current&&(l.current.stop(),r(u))};return g.jsx(He,{onClick:c,className:t,children:"Skip Forward"})},ks=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=_e(),{setLoopEnabled:r,setLoopRegion:s}=pe(),{duration:o}=Me(),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 g.jsx(He,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Ss=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=_e(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=pe(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?o():s()};return g.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"})},As=({className:e,disabled:t})=>{const{zoomIn:n}=pe(),{canZoomIn:a}=Me();return g.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Is=({className:e,disabled:t})=>{const{zoomOut:n}=pe(),{canZoomOut:a}=Me();return g.jsx(He,{onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Ms=({className:e})=>{const{masterVolume:t}=Me(),{setMasterVolume:n}=pe();return g.jsx(yr,{volume:t,onChange:n,className:e})},$s=({className:e})=>{const{timeFormat:t}=Me(),{setTimeFormat:n}=pe();return g.jsx(eo,{value:t,onChange:n,className:e})},Es=T.span`
|
|
783
783
|
font-family: 'Courier New', Monaco, monospace;
|
|
784
784
|
font-size: 1rem;
|
|
785
785
|
font-weight: 600;
|
|
786
786
|
color: ${e=>e.theme?.textColor||"#333"};
|
|
787
787
|
user-select: none;
|
|
788
|
-
`,Ts=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:a,currentTimeRef:r,playbackStartTimeRef:s,audioStartPositionRef:o}=
|
|
788
|
+
`,Ts=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:a,currentTimeRef:r,playbackStartTimeRef:s,audioStartPositionRef:o}=Re(),{timeFormat:l}=Me(),c=l;return i.useEffect(()=>{const u=()=>{if(t.current){let d;if(a){const b=P.getContext().currentTime-(s.current??0);d=(o.current??0)+b}else d=r.current??0;t.current.textContent=ut(d,c)}a&&(n.current=requestAnimationFrame(u))};return a?n.current=requestAnimationFrame(u):u(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[a,c,r,s,o]),i.useEffect(()=>{!a&&t.current&&(t.current.textContent=ut(r.current??0,c))}),g.jsx(Es,{ref:t,className:e,"aria-label":"Audio position",children:ut(r.current??0,c)})},Ds=({className:e})=>{const{selectionStart:t,selectionEnd:n}=_e(),{setSelection:a}=pe();return g.jsx(Dr,{selectionStart:t,selectionEnd:n,onSelectionChange:a,className:e})},Rs=({className:e})=>{const{isAutomaticScroll:t}=_e(),{setAutomaticScroll:n}=pe();return g.jsx(nr,{checked:t,onChange:n,className:e})},_t=i.createContext(null),_s=_t.Provider;function st(){const e=i.useContext(_t);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 Bs=({className:e})=>{const{ContinuousPlayCheckbox:t}=st(),{continuousPlay:n}=_e(),{setContinuousPlay:a}=pe();return g.jsx(t,{checked:n,onChange:a,className:e})},Fs=({className:e})=>{const{LinkEndpointsCheckbox:t}=st(),{linkEndpoints:n}=_e(),{setLinkEndpoints:a}=pe();return g.jsx(t,{checked:n,onChange:a,className:e})},Ws=({className:e})=>{const{EditableCheckbox:t}=st(),{annotationsEditable:n}=_e(),{setAnnotationsEditable:a}=pe();return g.jsx(t,{checked:n,onChange:a,className:e})},Ps=({filename:e,className:t})=>{const{DownloadAnnotationsButton:n}=st(),{annotations:a}=_e();return g.jsx(n,{annotations:a,filename:e,className:t})},Zs=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:a,bitDepth:r=16,applyEffects:s=!0,effectsFunction:o,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:d})=>{const{tracks:b,trackStates:h}=Me(),{exportWav:f,isExporting:y,progress:x}=ta(),m=async()=>{try{const w=await f(b,h,{filename:t,mode:n,trackIndex:a,bitDepth:r,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(w.blob)}catch(w){d?.(w instanceof Error?w:new Error("Export failed"))}},p=y?`Exporting ${Math.round(x*100)}%`:e;return g.jsx(He,{onClick:m,disabled:y||b.length===0,className:c,children:p})},Vs=T.div.attrs(e=>({style:{width:`${e.$width}px`,background:e.$color}}))`
|
|
789
789
|
position: absolute;
|
|
790
790
|
top: 0;
|
|
791
791
|
left: 0;
|
|
@@ -793,9 +793,9 @@
|
|
|
793
793
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
794
794
|
pointer-events: none;
|
|
795
795
|
will-change: transform;
|
|
796
|
-
`,js=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=
|
|
796
|
+
`,js=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=Re(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:d}=Me();return i.useEffect(()=>{const b=()=>{if(n.current){let h;if(r){const y=P.getContext().currentTime-(o.current??0);h=(l.current??0)+y}else h=s.current??0;const f=h*u/c+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}r&&(a.current=requestAnimationFrame(b))};return r?a.current=requestAnimationFrame(b):b(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,u,c,t,s,o,l]),i.useEffect(()=>{if(!r&&n.current){const h=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${h}px, 0, 0)`}}),g.jsx(Vs,{ref:n,$color:e,$width:d,"data-playhead":!0})},Hs=T.div`
|
|
797
797
|
position: relative;
|
|
798
|
-
`,Vt=
|
|
798
|
+
`,Vt=T.div.attrs(e=>({style:{top:`${e.$top}px`,width:`${e.$width}px`,height:`${e.$height}px`,background:e.$color}}))`
|
|
799
799
|
position: absolute;
|
|
800
800
|
left: 0;
|
|
801
801
|
z-index: 0;
|
|
@@ -803,16 +803,16 @@
|
|
|
803
803
|
transform: translateZ(0);
|
|
804
804
|
backface-visibility: hidden;
|
|
805
805
|
will-change: transform;
|
|
806
|
-
`,zs=
|
|
806
|
+
`,zs=T.div.attrs(e=>({style:{top:`${e.$top}px`,height:`${e.$height}px`,background:e.$color}}))`
|
|
807
807
|
position: absolute;
|
|
808
808
|
left: 0;
|
|
809
809
|
pointer-events: none;
|
|
810
810
|
z-index: 1;
|
|
811
811
|
will-change: width;
|
|
812
|
-
`,Ls=
|
|
812
|
+
`,Ls=T.div`
|
|
813
813
|
position: relative;
|
|
814
814
|
z-index: 2;
|
|
815
|
-
`,wn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=vt(),{waveHeight:o}=$t(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=Be(),{samplesPerPixel:b,sampleRate:h}=Me(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const $=()=>{if(a.current){let A;if(l){const B=P.getContext().currentTime-(u.current??0);A=(d.current??0)+B}else A=c.current??0;const E=A*h,M=e+t;let I=0;if(E<=e)I=0;else if(E>=M)I=n.length;else{const B=E-e;I=Math.floor(B/b)}a.current.style.width=`${I}px`}l&&(r.current=requestAnimationFrame($))};return l?r.current=requestAnimationFrame($):$(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,h,b,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&a.current){const A=(c.current??0)*h,E=e+t;let M=0;if(A<=e)M=0;else if(A>=E)M=n.length;else{const I=A-e;M=Math.floor(I/b)}a.current.style.width=`${M}px`}});const y=s?.waveformDrawMode||"inverted";let x;y==="inverted"?x=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":x=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const m=n.renderMode==="spectrogram"||n.renderMode==="both",g=n.renderMode==="both",w=m?"#000":tt(x),C=Math.floor(o/2),v=o,k=n.index*o,S=tt(x);return p.jsxs(Hs,{children:[g?p.jsxs(p.Fragment,{children:[p.jsx(Vt,{$color:"#000",$height:C,$top:k,$width:n.length}),p.jsx(Vt,{$color:S,$height:C,$top:k+C,$width:n.length})]}):p.jsx(Vt,{$color:w,$height:v,$top:k,$width:n.length}),p.jsx(zs,{ref:a,$color:f,$height:v,$top:k}),p.jsx(Ls,{children:p.jsx(Ln,{...n,transparentBackground:!0})})]})},Ut=i.createContext(null),Xs=Ut.Provider;function Os(){const e=i.useContext(Ut);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const Gs=60,da=({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:d,recordingState:b})=>{const h=vt(),{isPlaying:f,currentTimeRef:y,playbackStartTimeRef:x,audioStartPositionRef:m}=Be(),{selectionStart:g,selectionEnd:w,annotations:C,activeAnnotationId:v,annotationsEditable:k,linkEndpoints:S,continuousPlay:$,selectedTrackId:A,loopStart:E,loopEnd:M,isLoopEnabled:I}=Fe(),B=i.useContext(_t),{setAnnotations:_,setActiveAnnotationId:F,setTrackMute:N,setTrackSolo:q,setTrackVolume:X,setTrackPan:K,setSelection:j,play:J,setScrollContainer:ne,setSelectedTrackId:de,setCurrentTime:le,setLoopRegion:ue}=me(),{audioBuffers:oe,peaksDataArray:Ee,trackStates:pe,tracks:V,duration:ce,samplesPerPixel:O,sampleRate:U,waveHeight:se,timeScaleHeight:ge,controls:te,playoutRef:$e,barWidth:Te,barGap:Le,isReady:Ge}=Me(),Q=i.useContext(Ut),Ke=i.useMemo(()=>{if(!Q)return new Map;const Z=new Map;return V.forEach(H=>{if((Q.trackSpectrogramOverrides.get(H.id)?.renderMode??H.renderMode??"waveform")==="waveform")return;const ye=Q.trackSpectrogramOverrides.get(H.id),Ce=ye?.colorMap??H.spectrogramColorMap??Q.spectrogramColorMap??"viridis",De=ye?.config??H.spectrogramConfig??Q.spectrogramConfig;Z.set(H.id,{colorLUT:Q.getColorMap(Ce),frequencyScaleFn:Q.getFrequencyScale(De?.frequencyScale??"mel"),config:De})}),Z},[V,Q]),W=i.useMemo(()=>{if(Q?.spectrogramWorkerApi)return{registerCanvas:Q.spectrogramWorkerApi.registerCanvas.bind(Q.spectrogramWorkerApi),unregisterCanvas:Q.spectrogramWorkerApi.unregisterCanvas.bind(Q.spectrogramWorkerApi)}},[Q?.spectrogramWorkerApi]),[be,ve]=i.useState(null),[he,nt]=i.useState(!1),L=i.useRef(null),re=i.useCallback(Z=>{L.current=Z,ne(Z)},[ne]);let Ae=oe.length>0?ce:Gs;if(b?.isRecording){const H=(b.startSample+b.durationSamples)/U;Ae=Math.max(Ae,H+10)}const fe=Math.floor(Ae*U/O),Ve=async Z=>{F(Z.id);const H=$?void 0:Z.end-Z.start;try{await J(Z.start,H)}catch(ee){console.error("waveform-playlist: Failed to start playback for annotation",Z.id,ee)}},Ne=i.useCallback(Z=>{if(Z>=0&&Z<V.length){const H=V[Z];de(H.id)}},[V,de]),Ue=Z=>{const H=Z.currentTarget.getBoundingClientRect(),ee=te.show?te.width:0,Ce=(Z.clientX-H.left-ee)*O/U,Re=Z.clientY-H.top;let _e=0,ae=-1;for(let we=0;we<Ee.length;we++){const qe=Ee[we],Xe=qe.length>0?Math.max(...qe.map(dt=>dt.peaks.data.length)):1,Je=((Q?.trackSpectrogramOverrides.get(V[we]?.id)?.renderMode??V[we]?.renderMode??"waveform")==="both"?Xe*2:Xe)*se+(o?22:0);if(Re>=_e&&Re<_e+Je){ae=we;break}_e+=Je}ae!==-1&&Ne(ae),nt(!0),le(Ce),j(Ce,Ce)},at=Z=>{if(!he)return;const H=Z.currentTarget.getBoundingClientRect(),ee=te.show?te.width:0,Ce=(Z.clientX-H.left-ee)*O/U,De=Math.min(g,Ce),Re=Math.max(g,Ce);j(De,Re)},it=Z=>{if(!he)return;nt(!1);const H=Z.currentTarget.getBoundingClientRect(),ee=te.show?te.width:0,Ce=(Z.clientX-H.left-ee)*O/U,De=Math.min(g,Ce),Re=Math.max(g,Ce);Math.abs(Re-De)<.1?(le(De),f&&$e.current?($e.current.stop(),J(De)):$e.current&&$e.current.stop()):j(De,Re)};return V.some(Z=>Z.clips.length>0)&&(oe.length===0||Ee.length===0)?p.jsx("div",{className:s,children:"Loading waveform..."}):p.jsxs(zn,{children:[p.jsx(bt.Provider,{value:{samplesPerPixel:O,sampleRate:U,zoomLevels:[O],waveHeight:se,timeScaleHeight:ge,duration:Ae*1e3,controls:te,barWidth:Te,barGap:Le},children:p.jsx(Xt,{theme:h,backgroundColor:tt(h.waveOutlineColor),timescaleBackgroundColor:h.timescaleBackgroundColor,scrollContainerWidth:fe+(te.show?te.width:0),timescaleWidth:fe,tracksWidth:fe,controlsWidth:te.show?te.width:0,onTracksMouseDown:Ue,onTracksMouseMove:at,onTracksMouseUp:it,scrollContainerRef:re,isSelecting:he,"data-playlist-state":Ge?"ready":"loading",timescale:ge>0?p.jsxs(p.Fragment,{children:[p.jsx(Xn,{renderTimestamp:t}),I&&p.jsx(Tr,{startPosition:Math.min(E,M)*U/O,endPosition:Math.max(E,M)*U/O,markerColor:h.loopMarkerColor,regionColor:h.loopRegionColor,minPosition:0,maxPosition:fe,controlsOffset:te.show?te.width:0,onLoopRegionChange:(Z,H)=>{const ee=Z*O/U,ye=H*O/U;ue(ee,ye)}})]}):void 0,children:p.jsxs(p.Fragment,{children:[Ee.map((Z,H)=>{const ee=V[H];if(!ee)return null;const ye=pe[H]||{name:`Track ${H+1}`,muted:!1,soloed:!1,volume:1,pan:0},Ce=Q?.trackSpectrogramOverrides.get(ee.id)?.renderMode??ee.renderMode??"waveform",De=e?e(H):p.jsxs(io,{onClick:()=>Ne(H),children:[p.jsxs(lo,{style:{justifyContent:"center",position:"relative"},children:[d&&p.jsx(so,{onClick:ae=>{ae.stopPropagation(),d(H)}}),p.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:ye.name||`Track ${H+1}`}),Q?.renderMenuItems&&p.jsx("span",{style:{position:"absolute",right:0,top:0},children:p.jsx(bo,{items:ae=>Q.renderMenuItems({renderMode:Ce,onRenderModeChange:we=>Q.setTrackRenderMode(ee.id,we),onOpenSettings:()=>ve(ee.id),onClose:ae})})})]}),p.jsxs(ro,{children:[p.jsx(pn,{$variant:ye.muted?"danger":"outline",onClick:()=>N(H,!ye.muted),children:"Mute"}),p.jsx(pn,{$variant:ye.soloed?"info":"outline",onClick:()=>q(H,!ye.soloed),children:"Solo"})]}),p.jsxs(bn,{children:[p.jsx(co,{}),p.jsx(gn,{min:"0",max:"1",step:"0.01",value:ye.volume,onChange:ae=>X(H,parseFloat(ae.target.value))}),p.jsx(uo,{})]}),p.jsxs(bn,{children:[p.jsx("span",{children:"L"}),p.jsx(gn,{min:"-1",max:"1",step:"0.01",value:ye.pan,onChange:ae=>K(H,parseFloat(ae.target.value))}),p.jsx("span",{children:"R"})]})]}),_e=Z.length>0?Math.max(...Z.map(ae=>ae.peaks.data.length)):1;return p.jsx(Gt.Provider,{value:De,children:p.jsxs(On,{numChannels:_e,backgroundColor:tt(h.waveOutlineColor),offset:0,width:fe,hasClipHeaders:o,trackId:ee.id,isSelected:ee.id===A,children:[Ce!=="waveform"&&(()=>{const ae=Ke.get(ee.id),we=ae?.config;return!we?.labels||!ae?null:p.jsx(Lr,{waveHeight:se,numChannels:_e,frequencyScaleFn:ae.frequencyScaleFn,minFrequency:we.minFrequency??0,maxFrequency:we.maxFrequency??U/2,labelsColor:we.labelsColor,labelsBackground:we.labelsBackground,renderMode:Ce,hasClipHeaders:o})})(),Z.map((ae,we)=>{const qe=ae.peaks,Xe=qe.length;return p.jsx(Ht,{clipId:ae.clipId,trackIndex:H,clipIndex:we,trackName:ae.trackName,startSample:ae.startSample,durationSamples:ae.durationSamples,samplesPerPixel:O,showHeader:o,disableHeaderDrag:!l,isSelected:ee.id===A,trackId:ee.id,fadeIn:ae.fadeIn,fadeOut:ae.fadeOut,sampleRate:U,showFades:c,touchOptimized:u,onMouseDown:lt=>{lt.target.closest('[role="button"][aria-roledescription="draggable"]')||Ne(H)},children:qe.data.map((lt,je)=>{const Je=Q?.spectrogramDataMap.get(ae.clipId),dt=Je?.[je]??Je?.[0],Qe=Ke.get(ee.id),Ye=Qe?.config;return p.jsx(wn,{index:je,data:lt,bits:qe.bits,length:Xe,isSelected:ee.id===A,clipStartSample:ae.startSample,clipDurationSamples:ae.durationSamples,renderMode:Ce,spectrogramData:dt,samplesPerPixel:O,spectrogramColorLUT:Qe?.colorLUT,spectrogramFrequencyScaleFn:Qe?.frequencyScaleFn,spectrogramMinFrequency:Ye?.minFrequency,spectrogramMaxFrequency:Ye?.maxFrequency,spectrogramWorkerApi:W,spectrogramClipId:ae.clipId,spectrogramOnCanvasesReady:Q?(We,ft)=>{Q.registerSpectrogramCanvases(ae.clipId,je,We,ft)}:void 0},`${ae.clipId}-${je}`)})},ae.clipId)}),b?.isRecording&&b.trackId===ee.id&&b.peaks.length>0&&p.jsx(Ht,{clipId:"recording-preview",trackIndex:H,clipIndex:Z.length,trackName:"Recording...",startSample:b.startSample,durationSamples:b.durationSamples,samplesPerPixel:O,showHeader:o,disableHeaderDrag:!0,isSelected:ee.id===A,trackId:ee.id,children:p.jsx(wn,{index:0,data:b.peaks,bits:16,length:Math.floor(b.peaks.length/2),isSelected:ee.id===A,clipStartSample:b.startSample,clipDurationSamples:b.durationSamples},`${ee.id}-recording-0`)},`${ee.id}-recording`)]})},ee.id)}),C.length>0&&B&&p.jsx(B.AnnotationBoxesWrapper,{height:30,width:fe,children:C.map((Z,H)=>{const ee=Z.start*U/O,ye=Z.end*U/O,Ce=r?r(Z,H):Z.id;return p.jsx(B.AnnotationBox,{annotationId:Z.id,annotationIndex:H,startPosition:ee,endPosition:ye,label:Ce,color:"#ff9800",isActive:Z.id===v,onClick:()=>Ve(Z),editable:k},Z.id)})}),g!==w&&p.jsx(Vn,{startPosition:Math.min(g,w)*U/O+(te.show?te.width:0),endPosition:Math.max(g,w)*U/O+(te.show?te.width:0),color:h.selectionColor}),(f||g===w)&&(n?n({position:(y.current??0)*U/O+(te.show?te.width:0),color:h.playheadColor,isPlaying:f,currentTimeRef:y,playbackStartTimeRef:x,audioStartPositionRef:m,samplesPerPixel:O,sampleRate:U,controlsOffset:te.show?te.width:0,getAudioContextTime:()=>P.getContext().currentTime}):p.jsx(js,{color:h.playheadColor,controlsOffset:te.show?te.width:0}))]})})}),Q?.SettingsModal&&typeof document<"u"&&kn.createPortal(p.jsx(Q.SettingsModal,{open:be!==null,onClose:()=>ve(null),config:be!==null?Q.trackSpectrogramOverrides.get(be)?.config??V.find(Z=>Z.id===be)?.spectrogramConfig??Q.spectrogramConfig??{}:{},colorMap:be!==null?Q.trackSpectrogramOverrides.get(be)?.colorMap??V.find(Z=>Z.id===be)?.spectrogramColorMap??Q.spectrogramColorMap??"viridis":"viridis",onApply:(Z,H)=>{be!==null&&Q.setTrackSpectrogramConfig(be,Z,H)}}),document.body)]})},fa=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:a,annotationListConfig:r,scrollActivePosition:s="center",scrollActiveContainer:o="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:d,continuousPlay:b}=Fe(),h=st(),{setAnnotations:f}=me(),y=r??{linkEndpoints:d,continuousPlay:b},x=i.useCallback(g=>{f(g),n?.(g)},[f,n]),{AnnotationText:m}=h;return p.jsx(m,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:o,editable:u,controls:u?a:void 0,annotationListConfig:y,height:e,onAnnotationUpdate:x,renderAnnotationItem:t})},Ns=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:d,showClipHeaders:b=!1,interactiveClips:h=!1,showFades:f=!1,touchOptimized:y=!1,onRemoveTrack:x,recordingState:m})=>{const{annotations:g}=Fe();return p.jsxs(p.Fragment,{children:[p.jsx(da,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:l,className:d,showClipHeaders:b,interactiveClips:h,showFades:f,touchOptimized:y,onRemoveTrack:x,recordingState:m}),g.length>0&&p.jsx(fa,{height:s,renderAnnotationItem:o,controls:a,annotationListConfig:r,scrollActivePosition:c,scrollActiveContainer:u})]})},Ys=D.div`
|
|
815
|
+
`,wn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=vt(),{waveHeight:o}=$t(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=Re(),{samplesPerPixel:b,sampleRate:h}=Me(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const $=()=>{if(a.current){let M;if(l){const B=P.getContext().currentTime-(u.current??0);M=(d.current??0)+B}else M=c.current??0;const D=M*h,I=e+t;let A=0;if(D<=e)A=0;else if(D>=I)A=n.length;else{const B=D-e;A=Math.floor(B/b)}a.current.style.width=`${A}px`}l&&(r.current=requestAnimationFrame($))};return l?r.current=requestAnimationFrame($):$(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,h,b,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&a.current){const M=(c.current??0)*h,D=e+t;let I=0;if(M<=e)I=0;else if(M>=D)I=n.length;else{const A=M-e;I=Math.floor(A/b)}a.current.style.width=`${I}px`}});const y=s?.waveformDrawMode||"inverted";let x;y==="inverted"?x=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":x=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const m=n.renderMode==="spectrogram"||n.renderMode==="both",p=n.renderMode==="both",w=m?"#000":tt(x),C=Math.floor(o/2),v=o,k=n.index*o,S=tt(x);return g.jsxs(Hs,{children:[p?g.jsxs(g.Fragment,{children:[g.jsx(Vt,{$color:"#000",$height:C,$top:k,$width:n.length}),g.jsx(Vt,{$color:S,$height:C,$top:k+C,$width:n.length})]}):g.jsx(Vt,{$color:w,$height:v,$top:k,$width:n.length}),g.jsx(zs,{ref:a,$color:f,$height:v,$top:k}),g.jsx(Ls,{children:g.jsx(Ln,{...n,transparentBackground:!0})})]})},Ut=i.createContext(null),Xs=Ut.Provider;function Os(){const e=i.useContext(Ut);if(!e)throw new Error("useSpectrogramIntegration must be used within <SpectrogramProvider>. Install @waveform-playlist/spectrogram and wrap your app with <SpectrogramProvider>.");return e}const Gs=60,da=({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:d,recordingState:b})=>{const h=vt(),{isPlaying:f,currentTimeRef:y,playbackStartTimeRef:x,audioStartPositionRef:m}=Re(),{selectionStart:p,selectionEnd:w,annotations:C,activeAnnotationId:v,annotationsEditable:k,linkEndpoints:S,continuousPlay:$,selectedTrackId:M,loopStart:D,loopEnd:I,isLoopEnabled:A}=_e(),B=i.useContext(_t),{setAnnotations:_,setActiveAnnotationId:F,setTrackMute:O,setTrackSolo:G,setTrackVolume:j,setTrackPan:q,setSelection:N,play:re,setScrollContainer:J,setSelectedTrackId:oe,setCurrentTime:ie,setLoopRegion:de}=pe(),{audioBuffers:fe,peaksDataArray:$e,trackStates:le,tracks:V,duration:ue,samplesPerPixel:Y,sampleRate:U,waveHeight:se,timeScaleHeight:ge,controls:Q,playoutRef:Be,barWidth:ze,barGap:Ne,isReady:Le}=Me(),ee=i.useContext(Ut),Xe=i.useMemo(()=>{if(!ee)return new Map;const Z=new Map;return V.forEach(H=>{if((ee.trackSpectrogramOverrides.get(H.id)?.renderMode??H.renderMode??"waveform")==="waveform")return;const ye=ee.trackSpectrogramOverrides.get(H.id),Ce=ye?.colorMap??H.spectrogramColorMap??ee.spectrogramColorMap??"viridis",Ee=ye?.config??H.spectrogramConfig??ee.spectrogramConfig;Z.set(H.id,{colorLUT:ee.getColorMap(Ce),frequencyScaleFn:ee.getFrequencyScale(Ee?.frequencyScale??"mel"),config:Ee})}),Z},[V,ee]),W=i.useMemo(()=>{if(ee?.spectrogramWorkerApi)return{registerCanvas:ee.spectrogramWorkerApi.registerCanvas.bind(ee.spectrogramWorkerApi),unregisterCanvas:ee.spectrogramWorkerApi.unregisterCanvas.bind(ee.spectrogramWorkerApi)}},[ee?.spectrogramWorkerApi]),[he,be]=i.useState(null),[ve,nt]=i.useState(!1),L=i.useRef(null),ae=i.useCallback(Z=>{L.current=Z,J(Z)},[J]);let Ae=fe.length>0?ue:Gs;if(b?.isRecording){const H=(b.startSample+b.durationSamples)/U;Ae=Math.max(Ae,H+10)}const me=Math.floor(Ae*U/Y),Ze=async Z=>{F(Z.id);const H=$?void 0:Z.end-Z.start;try{await re(Z.start,H)}catch(te){console.error("waveform-playlist: Failed to start playback for annotation",Z.id,te)}},Ye=i.useCallback(Z=>{if(Z>=0&&Z<V.length){const H=V[Z];oe(H.id)}},[V,oe]),Ue=Z=>{const H=Z.currentTarget.getBoundingClientRect(),te=Q.show?Q.width:0,Ce=(Z.clientX-H.left-te)*Y/U,Te=Z.clientY-H.top;let De=0,ne=-1;for(let we=0;we<$e.length;we++){const qe=$e[we],Oe=qe.length>0?Math.max(...qe.map(dt=>dt.peaks.data.length)):1,Je=((ee?.trackSpectrogramOverrides.get(V[we]?.id)?.renderMode??V[we]?.renderMode??"waveform")==="both"?Oe*2:Oe)*se+(o?22:0);if(Te>=De&&Te<De+Je){ne=we;break}De+=Je}ne!==-1&&Ye(ne),nt(!0),ie(Ce),N(Ce,Ce)},at=Z=>{if(!ve)return;const H=Z.currentTarget.getBoundingClientRect(),te=Q.show?Q.width:0,Ce=(Z.clientX-H.left-te)*Y/U,Ee=Math.min(p,Ce),Te=Math.max(p,Ce);N(Ee,Te)},it=Z=>{if(!ve)return;nt(!1);const H=Z.currentTarget.getBoundingClientRect(),te=Q.show?Q.width:0,Ce=(Z.clientX-H.left-te)*Y/U,Ee=Math.min(p,Ce),Te=Math.max(p,Ce);Math.abs(Te-Ee)<.1?(ie(Ee),f&&Be.current?(Be.current.stop(),re(Ee)):Be.current&&Be.current.stop()):N(Ee,Te)};return V.some(Z=>Z.clips.length>0)&&(fe.length===0||$e.length===0)?g.jsx("div",{className:s,children:"Loading waveform..."}):g.jsxs(zn,{children:[g.jsx(bt.Provider,{value:{samplesPerPixel:Y,sampleRate:U,zoomLevels:[Y],waveHeight:se,timeScaleHeight:ge,duration:Ae*1e3,controls:Q,barWidth:ze,barGap:Ne},children:g.jsx(Xt,{theme:h,backgroundColor:tt(h.waveOutlineColor),timescaleBackgroundColor:h.timescaleBackgroundColor,scrollContainerWidth:me+(Q.show?Q.width:0),timescaleWidth:me,tracksWidth:me,controlsWidth:Q.show?Q.width:0,onTracksMouseDown:Ue,onTracksMouseMove:at,onTracksMouseUp:it,scrollContainerRef:ae,isSelecting:ve,"data-playlist-state":Le?"ready":"loading",timescale:ge>0?g.jsxs(g.Fragment,{children:[g.jsx(Xn,{renderTimestamp:t}),A&&g.jsx(Tr,{startPosition:Math.min(D,I)*U/Y,endPosition:Math.max(D,I)*U/Y,markerColor:h.loopMarkerColor,regionColor:h.loopRegionColor,minPosition:0,maxPosition:me,controlsOffset:Q.show?Q.width:0,onLoopRegionChange:(Z,H)=>{const te=Z*Y/U,ye=H*Y/U;de(te,ye)}})]}):void 0,children:g.jsxs(g.Fragment,{children:[$e.map((Z,H)=>{const te=V[H];if(!te)return null;const ye=le[H]||{name:`Track ${H+1}`,muted:!1,soloed:!1,volume:1,pan:0},Ce=ee?.trackSpectrogramOverrides.get(te.id)?.renderMode??te.renderMode??"waveform",Ee=e?e(H):g.jsxs(io,{onClick:()=>Ye(H),children:[g.jsxs(lo,{style:{justifyContent:"center",position:"relative"},children:[d&&g.jsx(so,{onClick:ne=>{ne.stopPropagation(),d(H)}}),g.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:ye.name||`Track ${H+1}`}),ee?.renderMenuItems&&g.jsx("span",{style:{position:"absolute",right:0,top:0},children:g.jsx(bo,{items:ne=>ee.renderMenuItems({renderMode:Ce,onRenderModeChange:we=>ee.setTrackRenderMode(te.id,we),onOpenSettings:()=>be(te.id),onClose:ne})})})]}),g.jsxs(ro,{children:[g.jsx(pn,{$variant:ye.muted?"danger":"outline",onClick:()=>O(H,!ye.muted),children:"Mute"}),g.jsx(pn,{$variant:ye.soloed?"info":"outline",onClick:()=>G(H,!ye.soloed),children:"Solo"})]}),g.jsxs(bn,{children:[g.jsx(co,{}),g.jsx(gn,{min:"0",max:"1",step:"0.01",value:ye.volume,onChange:ne=>j(H,parseFloat(ne.target.value))}),g.jsx(uo,{})]}),g.jsxs(bn,{children:[g.jsx("span",{children:"L"}),g.jsx(gn,{min:"-1",max:"1",step:"0.01",value:ye.pan,onChange:ne=>q(H,parseFloat(ne.target.value))}),g.jsx("span",{children:"R"})]})]}),De=Z.length>0?Math.max(...Z.map(ne=>ne.peaks.data.length)):1;return g.jsx(Gt.Provider,{value:Ee,children:g.jsxs(On,{numChannels:De,backgroundColor:tt(h.waveOutlineColor),offset:0,width:me,hasClipHeaders:o,trackId:te.id,isSelected:te.id===M,children:[Ce!=="waveform"&&(()=>{const ne=Xe.get(te.id),we=ne?.config;return!we?.labels||!ne?null:g.jsx(Lr,{waveHeight:se,numChannels:De,frequencyScaleFn:ne.frequencyScaleFn,minFrequency:we.minFrequency??0,maxFrequency:we.maxFrequency??U/2,labelsColor:we.labelsColor,labelsBackground:we.labelsBackground,renderMode:Ce,hasClipHeaders:o})})(),Z.map((ne,we)=>{const qe=ne.peaks,Oe=qe.length;return g.jsx(Ht,{clipId:ne.clipId,trackIndex:H,clipIndex:we,trackName:ne.trackName,startSample:ne.startSample,durationSamples:ne.durationSamples,samplesPerPixel:Y,showHeader:o,disableHeaderDrag:!l,isSelected:te.id===M,trackId:te.id,fadeIn:ne.fadeIn,fadeOut:ne.fadeOut,sampleRate:U,showFades:c,touchOptimized:u,onMouseDown:lt=>{lt.target.closest('[role="button"][aria-roledescription="draggable"]')||Ye(H)},children:qe.data.map((lt,Ve)=>{const Je=ee?.spectrogramDataMap.get(ne.clipId),dt=Je?.[Ve]??Je?.[0],Qe=Xe.get(te.id),Ke=Qe?.config;return g.jsx(wn,{index:Ve,data:lt,bits:qe.bits,length:Oe,isSelected:te.id===M,clipStartSample:ne.startSample,clipDurationSamples:ne.durationSamples,renderMode:Ce,spectrogramData:dt,samplesPerPixel:Y,spectrogramColorLUT:Qe?.colorLUT,spectrogramFrequencyScaleFn:Qe?.frequencyScaleFn,spectrogramMinFrequency:Ke?.minFrequency,spectrogramMaxFrequency:Ke?.maxFrequency,spectrogramWorkerApi:W,spectrogramClipId:ne.clipId,spectrogramOnCanvasesReady:ee?(Fe,ft)=>{ee.registerSpectrogramCanvases(ne.clipId,Ve,Fe,ft)}:void 0},`${ne.clipId}-${Ve}`)})},ne.clipId)}),b?.isRecording&&b.trackId===te.id&&b.peaks.length>0&&g.jsx(Ht,{clipId:"recording-preview",trackIndex:H,clipIndex:Z.length,trackName:"Recording...",startSample:b.startSample,durationSamples:b.durationSamples,samplesPerPixel:Y,showHeader:o,disableHeaderDrag:!0,isSelected:te.id===M,trackId:te.id,children:g.jsx(wn,{index:0,data:b.peaks,bits:16,length:Math.floor(b.peaks.length/2),isSelected:te.id===M,clipStartSample:b.startSample,clipDurationSamples:b.durationSamples},`${te.id}-recording-0`)},`${te.id}-recording`)]})},te.id)}),C.length>0&&B&&g.jsx(B.AnnotationBoxesWrapper,{height:30,width:me,children:C.map((Z,H)=>{const te=Z.start*U/Y,ye=Z.end*U/Y,Ce=r?r(Z,H):Z.id;return g.jsx(B.AnnotationBox,{annotationId:Z.id,annotationIndex:H,startPosition:te,endPosition:ye,label:Ce,color:"#ff9800",isActive:Z.id===v,onClick:()=>Ze(Z),editable:k},Z.id)})}),p!==w&&g.jsx(Vn,{startPosition:Math.min(p,w)*U/Y+(Q.show?Q.width:0),endPosition:Math.max(p,w)*U/Y+(Q.show?Q.width:0),color:h.selectionColor}),(f||p===w)&&(n?n({position:(y.current??0)*U/Y+(Q.show?Q.width:0),color:h.playheadColor,isPlaying:f,currentTimeRef:y,playbackStartTimeRef:x,audioStartPositionRef:m,samplesPerPixel:Y,sampleRate:U,controlsOffset:Q.show?Q.width:0,getAudioContextTime:()=>P.getContext().currentTime}):g.jsx(js,{color:h.playheadColor,controlsOffset:Q.show?Q.width:0}))]})})}),ee?.SettingsModal&&typeof document<"u"&&kn.createPortal(g.jsx(ee.SettingsModal,{open:he!==null,onClose:()=>be(null),config:he!==null?ee.trackSpectrogramOverrides.get(he)?.config??V.find(Z=>Z.id===he)?.spectrogramConfig??ee.spectrogramConfig??{}:{},colorMap:he!==null?ee.trackSpectrogramOverrides.get(he)?.colorMap??V.find(Z=>Z.id===he)?.spectrogramColorMap??ee.spectrogramColorMap??"viridis":"viridis",onApply:(Z,H)=>{he!==null&&ee.setTrackSpectrogramConfig(he,Z,H)}}),document.body)]})},fa=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:a,annotationListConfig:r,scrollActivePosition:s="center",scrollActiveContainer:o="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:d,continuousPlay:b}=_e(),h=st(),{setAnnotations:f}=pe(),y=r??{linkEndpoints:d,continuousPlay:b},x=i.useCallback(p=>{f(p),n?.(p)},[f,n]),{AnnotationText:m}=h;return g.jsx(m,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:o,editable:u,controls:u?a:void 0,annotationListConfig:y,height:e,onAnnotationUpdate:x,renderAnnotationItem:t})},Ns=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:d,showClipHeaders:b=!1,interactiveClips:h=!1,showFades:f=!1,touchOptimized:y=!1,onRemoveTrack:x,recordingState:m})=>{const{annotations:p}=_e();return g.jsxs(g.Fragment,{children:[g.jsx(da,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:l,className:d,showClipHeaders:b,interactiveClips:h,showFades:f,touchOptimized:y,onRemoveTrack:x,recordingState:m}),p.length>0&&g.jsx(fa,{height:s,renderAnnotationItem:o,controls:a,annotationListConfig:r,scrollActivePosition:c,scrollActiveContainer:u})]})},Ys=T.div`
|
|
816
816
|
position: absolute;
|
|
817
817
|
top: 0;
|
|
818
818
|
left: 0;
|
|
@@ -822,9 +822,9 @@
|
|
|
822
822
|
z-index: 100;
|
|
823
823
|
pointer-events: none;
|
|
824
824
|
will-change: transform;
|
|
825
|
-
`,Ks=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s}=Tt(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=Rt();return i.useEffect(()=>{const u=()=>{if(n.current){const b=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${b}px, 0, 0)`}r&&(a.current=requestAnimationFrame(u))};return r?a.current=requestAnimationFrame(u):u(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,l,o,t,s]),i.useEffect(()=>{if(!r&&n.current){const d=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}}),
|
|
825
|
+
`,Ks=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s}=Tt(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=Rt();return i.useEffect(()=>{const u=()=>{if(n.current){const b=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${b}px, 0, 0)`}r&&(a.current=requestAnimationFrame(u))};return r?a.current=requestAnimationFrame(u):u(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,l,o,t,s]),i.useEffect(()=>{if(!r&&n.current){const d=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}}),g.jsx(Ys,{ref:n,$color:e,$width:c,"data-playhead":!0})},Us=T.div`
|
|
826
826
|
position: relative;
|
|
827
|
-
`,qs=
|
|
827
|
+
`,qs=T.div`
|
|
828
828
|
position: absolute;
|
|
829
829
|
top: ${e=>e.$top}px;
|
|
830
830
|
left: 0;
|
|
@@ -835,7 +835,7 @@
|
|
|
835
835
|
transform: translateZ(0);
|
|
836
836
|
backface-visibility: hidden;
|
|
837
837
|
will-change: transform;
|
|
838
|
-
`,Js=
|
|
838
|
+
`,Js=T.div`
|
|
839
839
|
position: absolute;
|
|
840
840
|
top: ${e=>e.$top}px;
|
|
841
841
|
left: 0;
|
|
@@ -844,8 +844,8 @@
|
|
|
844
844
|
pointer-events: none;
|
|
845
845
|
z-index: 1;
|
|
846
846
|
will-change: width;
|
|
847
|
-
`,Qs=
|
|
847
|
+
`,Qs=T.div`
|
|
848
848
|
position: relative;
|
|
849
849
|
z-index: 2;
|
|
850
|
-
`,ei=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=vt(),{waveHeight:o}=$t(),{isPlaying:l,currentTimeRef:c}=Tt(),{samplesPerPixel:u,sampleRate:d}=Rt(),b=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const x=()=>{if(a.current){const
|
|
850
|
+
`,ei=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=vt(),{waveHeight:o}=$t(),{isPlaying:l,currentTimeRef:c}=Tt(),{samplesPerPixel:u,sampleRate:d}=Rt(),b=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const x=()=>{if(a.current){const p=(c.current??0)*d,w=e+t;let C=0;if(p<=e)C=0;else if(p>=w)C=n.length;else{const v=p-e;C=Math.floor(v/u)}a.current.style.width=`${C}px`}l&&(r.current=requestAnimationFrame(x))};return l?r.current=requestAnimationFrame(x):x(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,d,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&a.current){const m=(c.current??0)*d,p=e+t;let w=0;if(m<=e)w=0;else if(m>=p)w=n.length;else{const C=m-e;w=Math.floor(C/u)}a.current.style.width=`${w}px`}});const h=s?.waveformDrawMode||"inverted";let f;h==="inverted"?f=s?.selectedWaveFillColor||s?.waveFillColor||"white":f=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const y=tt(f);return g.jsxs(Us,{children:[g.jsx(qs,{$color:y,$height:o,$top:n.index*o,$width:n.length}),g.jsx(Js,{ref:a,$color:b,$height:o,$top:n.index*o}),g.jsx(Qs,{children:g.jsx(Ln,{...n,isSelected:!0,transparentBackground:!0})})]})},ma=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:a,className:r})=>{const s=vt(),{isPlaying:o,currentTimeRef:l}=Tt(),{annotations:c,activeAnnotationId:u}=Dt(),d=i.useContext(_t),{play:b,seekTo:h,setActiveAnnotationId:f,setAnnotations:y,setScrollContainer:x}=Kt(),{duration:m,peaksDataArray:p,sampleRate:w,waveHeight:C,timeScaleHeight:v,samplesPerPixel:k,controls:S,playoutRef:$,barWidth:M,barGap:D}=Rt(),[I,A]=i.useState(0),[B,_]=i.useState(0),[F,O]=i.useState(!1),G=i.useRef(null),j=i.useCallback(V=>{G.current=V,x(V)},[x]),q=Math.floor(m*w/k),N=i.useCallback(async V=>{f(V.id);try{await b(V.start)}catch(ue){console.error("waveform-playlist: Failed to start playback for annotation",V.id,ue)}},[f,b]),re=i.useCallback(V=>{y(V),a?.(V)},[y,a]),{onDragStart:J,onDragMove:oe,onDragEnd:ie}=ea({annotations:c,onAnnotationsChange:re,samplesPerPixel:k,sampleRate:w,duration:m,linkEndpoints:n}),de=i.useCallback(V=>{const ue=V.currentTarget.getBoundingClientRect(),Y=S.show?S.width:0,se=(V.clientX-ue.left-Y)*k/w;O(!0),A(se),_(se)},[S,k,w]),fe=i.useCallback(V=>{if(!F)return;const ue=V.currentTarget.getBoundingClientRect(),Y=S.show?S.width:0,se=(V.clientX-ue.left-Y)*k/w;_(se)},[F,S,k,w]),$e=i.useCallback(V=>{if(!F)return;O(!1);const ue=V.currentTarget.getBoundingClientRect(),Y=S.show?S.width:0,se=(V.clientX-ue.left-Y)*k/w,ge=Math.min(I,se),Q=Math.max(I,se);Math.abs(Q-ge)<.1?(h(ge),A(ge),_(ge),o&&$.current&&($.current.stop(),b(ge))):(A(ge),_(Q))},[F,I,k,w,S,h,o,$,b]);if(p.length===0)return g.jsx("div",{className:r,children:"Loading waveform..."});const le=null;return g.jsx(zn,{children:g.jsx(bt.Provider,{value:{samplesPerPixel:k,sampleRate:w,zoomLevels:[k],waveHeight:C,timeScaleHeight:v,duration:m*1e3,controls:S,barWidth:M,barGap:D},children:g.jsx(Xt,{theme:s,backgroundColor:tt(s.waveOutlineColor),timescaleBackgroundColor:s.timescaleBackgroundColor,scrollContainerWidth:q+(S.show?S.width:0),timescaleWidth:q,tracksWidth:q,controlsWidth:S.show?S.width:0,onTracksMouseDown:de,onTracksMouseMove:fe,onTracksMouseUp:$e,scrollContainerRef:j,isSelecting:F,timescale:v>0?g.jsx(Xn,{}):void 0,children:g.jsxs(g.Fragment,{children:[p.map((V,ue)=>{const Y=V.length>0?Math.max(...V.map(U=>U.peaks.data.length)):1;return g.jsx(Gt.Provider,{value:le,children:g.jsx(On,{numChannels:Y,backgroundColor:tt(s.waveOutlineColor),offset:0,width:q,hasClipHeaders:!1,trackId:`media-element-track-${ue}`,isSelected:!0,children:V.map((U,se)=>{const ge=U.peaks,Q=ge.length;return g.jsx(Ht,{clipId:U.clipId,trackIndex:ue,clipIndex:se,trackName:U.trackName,startSample:U.startSample,durationSamples:U.durationSamples,samplesPerPixel:k,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${ue}`,children:ge.data.map((Be,ze)=>g.jsx(ei,{index:ze,data:Be,bits:ge.bits,length:Q,clipStartSample:U.startSample,clipDurationSamples:U.durationSamples},`${ue}-${se}-${ze}`))},`${ue}-${se}`)})})},ue)}),c.length>0&&d&&g.jsx(Ge.DndContext,{onDragStart:J,onDragMove:oe,onDragEnd:ie,modifiers:t?[Va.restrictToHorizontalAxis]:[],children:g.jsx(d.AnnotationBoxesWrapper,{height:30,width:q,children:c.map((V,ue)=>{const Y=V.start*w/k,U=V.end*w/k,se=e?e(V,ue):V.id;return g.jsx(d.AnnotationBox,{annotationId:V.id,annotationIndex:ue,startPosition:Y,endPosition:U,label:se,color:"#ff9800",isActive:V.id===u,onClick:()=>N(V),editable:t},V.id)})})}),I!==B&&g.jsx(Vn,{startPosition:Math.min(I,B)*w/k+(S.show?S.width:0),endPosition:Math.max(I,B)*w/k+(S.show?S.width:0),color:s.selectionColor}),g.jsx(Ks,{color:s.playheadColor,controlsOffset:S.show?S.width:0})]})})})})},ha=({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:d}=Dt(),b=st(),{setAnnotations:h}=Kt(),f=s??{linkEndpoints:!1,continuousPlay:d},y=i.useCallback(m=>{h(m),n?.(m)},[h,n]),{AnnotationText:x}=b;return g.jsx(x,{annotations:c,activeAnnotationId:u??void 0,shouldScrollToActive:!0,scrollActivePosition:o,scrollActiveContainer:l,editable:a,controls:a?r:void 0,annotationListConfig:f,height:e,onAnnotationUpdate:y,renderAnnotationItem:t})},ti=({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}=Dt();return g.jsxs(g.Fragment,{children:[g.jsx(ma,{getAnnotationBoxLabel:t,editable:a,linkEndpoints:r,onAnnotationUpdate:s,className:c}),u.length>0&&g.jsx(ha,{height:e,renderAnnotationItem:n,onAnnotationUpdate:s,editable:a,annotationListConfig:{linkEndpoints:r,continuousPlay:!1},scrollActivePosition:o,scrollActiveContainer:l})]})};exports.Tone=An;exports.AnnotationIntegrationProvider=_s;exports.AudioPosition=Ts;exports.AutomaticScrollCheckbox=Rs;exports.ContinuousPlayCheckbox=Bs;exports.DownloadAnnotationsButton=Ps;exports.EditableCheckbox=Ws;exports.ExportWavButton=Zs;exports.FastForwardButton=ys;exports.LinkEndpointsCheckbox=Fs;exports.LoopButton=ks;exports.MasterVolumeControl=Ms;exports.MediaElementAnnotationList=ha;exports.MediaElementPlaylist=ma;exports.MediaElementPlaylistProvider=ps;exports.MediaElementWaveform=ti;exports.PauseButton=bs;exports.PlayButton=gs;exports.PlaylistAnnotationList=fa;exports.PlaylistVisualization=da;exports.RewindButton=Cs;exports.SelectionTimeInputs=Ds;exports.SetLoopRegionButton=Ss;exports.SkipBackwardButton=xs;exports.SkipForwardButton=ws;exports.SpectrogramIntegrationProvider=Xs;exports.StopButton=vs;exports.TimeFormatSelect=$s;exports.Waveform=Ns;exports.WaveformPlaylistProvider=ds;exports.ZoomInButton=As;exports.ZoomOutButton=Is;exports.createEffectChain=as;exports.createEffectInstance=pt;exports.effectCategories=Qo;exports.effectDefinitions=Ct;exports.getEffectDefinition=Yt;exports.getEffectsByCategory=Jo;exports.getShortcutLabel=Ko;exports.getWaveformDataMetadata=Vo;exports.loadPeaksFromWaveformData=Zo;exports.loadWaveformData=Nt;exports.useAnnotationDragHandlers=ea;exports.useAnnotationIntegration=st;exports.useAnnotationKeyboardControls=qo;exports.useAudioTracks=Xo;exports.useClipDragHandlers=Oo;exports.useClipSplitting=Yo;exports.useDragSensors=No;exports.useDynamicEffects=rs;exports.useExportWav=ta;exports.useKeyboardShortcuts=Mt;exports.useMasterAnalyser=Ho;exports.useMasterVolume=Jn;exports.useMediaElementAnimation=Tt;exports.useMediaElementControls=Kt;exports.useMediaElementData=Rt;exports.useMediaElementState=Dt;exports.usePlaybackAnimation=Re;exports.usePlaybackShortcuts=Uo;exports.usePlaylistControls=pe;exports.usePlaylistData=Me;exports.usePlaylistState=_e;exports.useSpectrogramIntegration=Os;exports.useTimeFormat=Un;exports.useTrackDynamicEffects=os;exports.useWaveformPlaylist=fs;exports.useZoomControls=qn;exports.waveformDataToPeaks=Yn;
|
|
851
851
|
//# sourceMappingURL=index.js.map
|