@waveform-playlist/browser 5.0.0-alpha.12 → 5.0.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";var ia=Object.create;var mn=Object.defineProperty;var la=Object.getOwnPropertyDescriptor;var ca=Object.getOwnPropertyNames;var ua=Object.getPrototypeOf,da=Object.prototype.hasOwnProperty;var fa=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of ca(t))!da.call(e,a)&&a!==n&&mn(e,a,{get:()=>t[a],enumerable:!(r=la(t,a))||r.enumerable});return e};var ha=(e,t,n)=>(n=e!=null?ia(ua(e)):{},fa(t||!e||!e.__esModule?mn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("tone"),x=require("react/jsx-runtime"),i=require("react"),A=require("styled-components");require("react-dom");var Tt=typeof document<"u"?document.currentScript:null;function or(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const sr=or(E),X=or(i);function pn(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r;n[a]=t?s:1-s}return n}function ma(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r,o=t?a:e-1-a;n[o]=Math.exp(2*s-1)/Math.E}return n}function pa(e,t){const n=new Float32Array(e),r=t?Math.PI/2:-Math.PI/2;for(let a=0;a<e;a++)n[a]=Math.sin(Math.PI*a/e-r)/2+.5;return n}function ga(e,t,n=10){const r=new Float32Array(e);for(let a=0;a<e;a++){const s=t?a:e-1-a,o=a/e;r[s]=Math.log(1+n*o)/Math.log(1+n)}return r}function ir(e,t,n){switch(e){case"linear":return pn(t,n);case"exponential":return ma(t,n);case"sCurve":return pa(t,n);case"logarithmic":return ga(t,n);default:return pn(t,n)}}function gn(e,t,n,r="linear",a=0,s=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=ir(r,1e4,!0),l=new Float32Array(o.length),c=s-a;for(let u=0;u<o.length;u++)l[u]=a+o[u]*c;e.setValueCurveAtTime(l,t,n)}}function bn(e,t,n,r="linear",a=1,s=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=ir(r,1e4,!1),l=new Float32Array(o.length),c=a-s;for(let u=0;u<o.length;u++)l[u]=s+o[u]*c;e.setValueCurveAtTime(l,t,n)}}var ba=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new E.Volume(this.gainToDb(e.track.gain)),this.panNode=new E.Panner(e.track.stereoPan),this.muteGain=new E.Gain(e.track.muted?0:1);const t=e.destination||E.getDestination();if(e.effects){const r=e.effects(this.muteGain,t,!1);r&&(this.effectsCleanup=r)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]);this.clips=n.map(r=>{const a=new E.Player({url:r.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new E.Gain(r.gain);return a.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:a,clipInfo:r,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGain:a}=e,s=a.gain._param;s.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const l=r.fadeIn.duration;if(o<=0)gn(s,t,l,r.fadeIn.type||"linear",0,r.gain);else{const c=l-o,u=o/l,d=r.gain*u;gn(s,t,c,r.fadeIn.type||"linear",d,r.gain)}}else s.setValueAtTime(r.gain,t);if(r.fadeOut){const c=r.duration-r.fadeOut.duration-o;if(c>0){const u=t+c;bn(s,u,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(c>-r.fadeOut.duration){const u=-c,d=r.fadeOut.duration-u,b=u/r.fadeOut.duration,g=r.gain*(1-b);bn(s,t,d,r.fadeOut.type||"linear",g,0)}}}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e,this.muteGain.gain.value=e?0:1}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(r=>{r.player.stop(),r.player.disconnect(),r.player.dispose();const a=new E.Player({url:r.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});a.connect(r.fadeGain),r.player=a,r.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(r=>{const{player:a,clipInfo:s}=r,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??E.now();if(r.playStartTime=u,o>=l){const d=o-l+s.offset,b=s.duration-(o-l),g=n?Math.min(n,b):b;r.pausedPosition=d,this.scheduleFades(r,u,d),a.start(u,d,g)}else{const d=l-o,b=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(r.pausedPosition=s.offset,this.scheduleFades(r,u+d,s.offset),a.start(u+d,s.offset,b)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(E.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??E.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}},va=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 E.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,E.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 E.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new ba(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}applyInitialSoloState(){this.updateSoloMuting()}removeTrack(e){const t=this.tracks.get(e);t&&(t.dispose(),this.tracks.delete(e),this.manualMuteState.delete(e),this.soloedTracks.delete(e))}getTrack(e){return this.tracks.get(e)}play(e,t,n){if(!this.isInitialized){console.warn("TonePlayout not initialized. Call init() first.");return}const r=e??E.now(),a=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(a>=l){const c=a-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r,c,n)}else{const c=l-a;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r+c,0,n)}}),t!==void 0?E.getTransport().start(r,t):E.getTransport().start(r)}pause(){E.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){E.getTransport().stop(),this.tracks.forEach(e=>{e.stop()})}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return E.getTransport().seconds}seekTo(e){E.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return E.getContext()}get sampleRate(){return E.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},dt=null;function Ca(){return dt||(dt=new E.Context,E.setContext(dt)),dt}async function Wt(){const e=Ca();e.state!=="running"&&await e.resume()}const wa=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ct=wa?i.useLayoutEffect:i.useEffect;function xa(e){const t=i.useRef(e);return Ct(()=>{t.current=e}),i.useCallback(function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return t.current==null?void 0:t.current(...r)},[])}function lr(e,t){t===void 0&&(t=[e]);const n=i.useRef(e);return Ct(()=>{n.current!==e&&(n.current=e)},t),n}function pt(e){const t=xa(e),n=i.useRef(null),r=i.useCallback(a=>{a!==n.current&&t?.(a,n.current),n.current=a},[]);return[n,r]}let Ft={};function cr(e,t){return i.useMemo(()=>{const n=Ft[e]==null?0:Ft[e]+1;return Ft[e]=n,e+"-"+n},[e,t])}const Pt=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[Pt.Translate.toString(e),Pt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}});var vn;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(vn||(vn={}));function Cn(){}const ya=Object.freeze({x:0,y:0});var Ye;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Ye||(Ye={}));var wn;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(wn||(wn={}));var Ve;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Ve||(Ve={}));Ve.Space,Ve.Enter,Ve.Esc,Ve.Space,Ve.Enter,Ve.Tab;var xn;(function(e){e[e.RightClick=2]="RightClick"})(xn||(xn={}));var yn;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(yn||(yn={}));var In;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(In||(In={}));Ye.Backward+"",Ye.Forward+"",Ye.Backward+"",Ye.Forward+"";var Gt;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Gt||(Gt={}));var Lt;(function(e){e.Optimized="optimized"})(Lt||(Lt={}));function Ia(e,t){return i.useMemo(()=>e.reduce((n,r)=>{let{eventName:a,handler:s}=r;return n[a]=o=>{s(o,t)},n},{}),[e,t])}Gt.WhileDragging,Lt.Optimized;const Sa={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Cn,draggableNodes:new Map,over:null,measureDroppableContainers:Cn},Aa=i.createContext(Sa),ka=i.createContext({...ya,scaleX:1,scaleY:1});var Sn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Sn||(Sn={}));const $a=i.createContext(null),An="button",Da="Draggable";function Zt(e){let{id:t,data:n,disabled:r=!1,attributes:a}=e;const s=cr(Da),{activators:o,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:d,draggableNodes:b,over:g}=i.useContext(Aa),{role:f=An,roleDescription:v="draggable",tabIndex:y=0}=a??{},m=c?.id===t,h=i.useContext(m?ka:$a),[w,C]=pt(),[p,S]=pt(),I=Ia(o,t),k=lr(n);Ct(()=>(b.set(t,{id:t,key:s,node:w,activatorNode:p,data:k}),()=>{const M=b.get(t);M&&M.key===s&&b.delete(t)}),[b,t]);const R=i.useMemo(()=>({role:f,tabIndex:y,"aria-disabled":r,"aria-pressed":m&&f===An?!0:void 0,"aria-roledescription":v,"aria-describedby":d.draggable}),[r,f,y,m,v,d.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:R,isDragging:m,listeners:r?void 0:I,node:w,over:g,setNodeRef:C,setActivatorNodeRef:S,transform:h}}const Ma=new Map([["bold",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),X.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",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.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"}))]]),Ra=new Map([["bold",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),X.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",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.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",X.createElement(X.Fragment,null,X.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"}))]]),Ba=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),Qt=X.forwardRef((e,t)=>{const{alt:n,color:r,size:a,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:b,weight:g="regular",mirrored:f=!1,...v}=X.useContext(Ba);return X.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:a??b,height:a??b,fill:r??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...v,...u},!!n&&X.createElement("title",null,n),l,c.get(s??g))});Qt.displayName="IconBase";const ur=X.forwardRef((e,t)=>X.createElement(Qt,{ref:t,...e,weights:Ma}));ur.displayName="SpeakerHighIcon";const dr=X.forwardRef((e,t)=>X.createElement(Qt,{ref:t,...e,weights:Ra}));dr.displayName="SpeakerLowIcon";A.span`
1
+ "use strict";var Aa=Object.create;var wn=Object.defineProperty;var $a=Object.getOwnPropertyDescriptor;var Ma=Object.getOwnPropertyNames;var Da=Object.getPrototypeOf,Ra=Object.prototype.hasOwnProperty;var Ea=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Ma(t))!Ra.call(e,a)&&a!==n&&wn(e,a,{get:()=>t[a],enumerable:!(r=$a(t,a))||r.enumerable});return e};var Ta=(e,t,n)=>(n=e!=null?Aa(Da(e)):{},Ea(t||!e||!e.__esModule?wn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("tone"),w=require("react/jsx-runtime"),i=require("react"),S=require("styled-components");require("react-dom");var Pt=typeof document<"u"?document.currentScript:null;function ur(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const dr=ur(W),N=ur(i);function xn(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r;n[a]=t?s:1-s}return n}function Ba(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r,o=t?a:e-1-a;n[o]=Math.exp(2*s-1)/Math.E}return n}function Wa(e,t){const n=new Float32Array(e),r=t?Math.PI/2:-Math.PI/2;for(let a=0;a<e;a++)n[a]=Math.sin(Math.PI*a/e-r)/2+.5;return n}function Fa(e,t,n=10){const r=new Float32Array(e);for(let a=0;a<e;a++){const s=t?a:e-1-a,o=a/e;r[s]=Math.log(1+n*o)/Math.log(1+n)}return r}function fr(e,t,n){switch(e){case"linear":return xn(t,n);case"exponential":return Ba(t,n);case"sCurve":return Wa(t,n);case"logarithmic":return Fa(t,n);default:return xn(t,n)}}function yn(e,t,n,r="linear",a=0,s=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=fr(r,1e4,!0),l=new Float32Array(o.length),c=s-a;for(let u=0;u<o.length;u++)l[u]=a+o[u]*c;e.setValueCurveAtTime(l,t,n)}}function kn(e,t,n,r="linear",a=1,s=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=fr(r,1e4,!1),l=new Float32Array(o.length),c=a-s;for(let u=0;u<o.length;u++)l[u]=s+o[u]*c;e.setValueCurveAtTime(l,t,n)}}var _a=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new W.Volume(this.gainToDb(e.track.gain)),this.panNode=new W.Panner(e.track.stereoPan),this.muteGain=new W.Gain(e.track.muted?0:1);const t=e.destination||W.getDestination();if(e.effects){const r=e.effects(this.muteGain,t,!1);r&&(this.effectsCleanup=r)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]);this.clips=n.map(r=>{const a=new W.Player({url:r.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new W.Gain(r.gain);return a.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:a,clipInfo:r,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGain:a}=e,s=a.gain._param;s.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const l=r.fadeIn.duration;if(o<=0)yn(s,t,l,r.fadeIn.type||"linear",0,r.gain);else{const c=l-o,u=o/l,f=r.gain*u;yn(s,t,c,r.fadeIn.type||"linear",f,r.gain)}}else s.setValueAtTime(r.gain,t);if(r.fadeOut){const c=r.duration-r.fadeOut.duration-o;if(c>0){const u=t+c;kn(s,u,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(c>-r.fadeOut.duration){const u=-c,f=r.fadeOut.duration-u,x=u/r.fadeOut.duration,v=r.gain*(1-x);kn(s,t,f,r.fadeOut.type||"linear",v,0)}}}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e,this.muteGain.gain.value=e?0:1}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(r=>{r.player.stop(),r.player.disconnect(),r.player.dispose();const a=new W.Player({url:r.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});a.connect(r.fadeGain),r.player=a,r.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(r=>{const{player:a,clipInfo:s}=r,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??W.now();if(r.playStartTime=u,o>=l){const f=o-l+s.offset,x=s.duration-(o-l),v=n?Math.min(n,x):x;r.pausedPosition=f,this.scheduleFades(r,u,f),a.start(u,f,v)}else{const f=l-o,x=n?Math.min(n-f,s.duration):s.duration;f<(n??1/0)?(r.pausedPosition=s.offset,this.scheduleFades(r,u+f,s.offset),a.start(u+f,s.offset,x)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(W.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??W.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},Za=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this.activeTracks=new Map,this.playbackSessionId=0,this.masterVolume=new W.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,W.getDestination(),!1);t&&(this.effectsCleanup=t)}else this.masterVolume.toDestination();e.tracks&&e.tracks.forEach(t=>{this.tracks.set(t.id,t),this.manualMuteState.set(t.id,t.muted)})}gainToDb(e){return 20*Math.log10(e)}async init(){this.isInitialized||(await W.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new _a(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}applyInitialSoloState(){this.updateSoloMuting()}removeTrack(e){const t=this.tracks.get(e);t&&(t.dispose(),this.tracks.delete(e),this.manualMuteState.delete(e),this.soloedTracks.delete(e))}getTrack(e){return this.tracks.get(e)}play(e,t,n){if(!this.isInitialized){console.warn("TonePlayout not initialized. Call init() first.");return}const r=e??W.now(),a=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(a>=l){const c=a-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r,c,n)}else{const c=l-a;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r+c,0,n)}}),t!==void 0?W.getTransport().start(r,t):W.getTransport().start(r)}pause(){W.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){W.getTransport().stop(),this.tracks.forEach(e=>{e.stop()})}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return W.getTransport().seconds}seekTo(e){W.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return W.getContext()}get sampleRate(){return W.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},wt=null;function Pa(){return wt||(wt=new W.Context,W.setContext(wt)),wt}async function Vt(){const e=Pa();e.state!=="running"&&await e.resume()}const Va=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",$t=Va?i.useLayoutEffect:i.useEffect;function za(e){const t=i.useRef(e);return $t(()=>{t.current=e}),i.useCallback(function(){for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return t.current==null?void 0:t.current(...r)},[])}function hr(e,t){t===void 0&&(t=[e]);const n=i.useRef(e);return $t(()=>{n.current!==e&&(n.current=e)},t),n}function It(e){const t=za(e),n=i.useRef(null),r=i.useCallback(a=>{a!==n.current&&t?.(a,n.current),n.current=a},[]);return[n,r]}let zt={};function mr(e,t){return i.useMemo(()=>{const n=zt[e]==null?0:zt[e]+1;return zt[e]=n,e+"-"+n},[e,t])}const Yt=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[Yt.Translate.toString(e),Yt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}});var In;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(In||(In={}));function Sn(){}const ja=Object.freeze({x:0,y:0});var et;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(et||(et={}));var An;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(An||(An={}));var He;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(He||(He={}));He.Space,He.Enter,He.Esc,He.Space,He.Enter,He.Tab;var $n;(function(e){e[e.RightClick=2]="RightClick"})($n||($n={}));var Mn;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Mn||(Mn={}));var Dn;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Dn||(Dn={}));et.Backward+"",et.Forward+"",et.Backward+"",et.Forward+"";var Kt;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Kt||(Kt={}));var Ut;(function(e){e.Optimized="optimized"})(Ut||(Ut={}));function Xa(e,t){return i.useMemo(()=>e.reduce((n,r)=>{let{eventName:a,handler:s}=r;return n[a]=o=>{s(o,t)},n},{}),[e,t])}Kt.WhileDragging,Ut.Optimized;const Ha={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Sn,draggableNodes:new Map,over:null,measureDroppableContainers:Sn},La=i.createContext(Ha),Na=i.createContext({...ja,scaleX:1,scaleY:1});var Rn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Rn||(Rn={}));const Ga=i.createContext(null),En="button",Oa="Draggable";function jt(e){let{id:t,data:n,disabled:r=!1,attributes:a}=e;const s=mr(Oa),{activators:o,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:f,draggableNodes:x,over:v}=i.useContext(La),{role:d=En,roleDescription:C="draggable",tabIndex:y=0}=a??{},h=c?.id===t,b=i.useContext(h?Na:Ga),[g,m]=It(),[p,I]=It(),k=Xa(o,t),A=hr(n);$t(()=>(x.set(t,{id:t,key:s,node:g,activatorNode:p,data:A}),()=>{const D=x.get(t);D&&D.key===s&&x.delete(t)}),[x,t]);const R=i.useMemo(()=>({role:d,tabIndex:y,"aria-disabled":r,"aria-pressed":h&&d===En?!0:void 0,"aria-roledescription":C,"aria-describedby":f.draggable}),[r,d,y,h,C,f.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:R,isDragging:h,listeners:r?void 0:k,node:g,over:v,setNodeRef:m,setActivatorNodeRef:I,transform:b}}const Ya=new Map([["bold",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),N.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",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.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"}))]]),Ka=new Map([["bold",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),N.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",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.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",N.createElement(N.Fragment,null,N.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"}))]]),Ua=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),on=N.forwardRef((e,t)=>{const{alt:n,color:r,size:a,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:f="currentColor",size:x,weight:v="regular",mirrored:d=!1,...C}=N.useContext(Ua);return N.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:a??x,height:a??x,fill:r??f,viewBox:"0 0 256 256",transform:o||d?"scale(-1, 1)":void 0,...C,...u},!!n&&N.createElement("title",null,n),l,c.get(s??v))});on.displayName="IconBase";const pr=N.forwardRef((e,t)=>N.createElement(on,{ref:t,...e,weights:Ya}));pr.displayName="SpeakerHighIcon";const gr=N.forwardRef((e,t)=>N.createElement(on,{ref:t,...e,weights:Ka}));gr.displayName="SpeakerLowIcon";S.span`
2
2
  font-family: 'Courier New', Monaco, monospace;
3
3
  font-size: 1rem;
4
4
  font-weight: 600;
5
5
  color: ${e=>e.theme?.textColor||"#333"};
6
6
  user-select: none;
7
- `;var en=A.button`
7
+ `;var sn=S.button`
8
8
  display: inline-flex;
9
9
  align-items: center;
10
10
  justify-content: center;
@@ -33,37 +33,37 @@
33
33
  opacity: 0.6;
34
34
  cursor: not-allowed;
35
35
  }
36
- `;A(en)`
36
+ `;S(sn)`
37
37
  padding: 0.25rem 0.5rem;
38
38
  font-size: ${e=>e.theme.fontSizeSmall};
39
- `;A(en)`
39
+ `;S(sn)`
40
40
  padding: 0.5rem;
41
41
  min-width: 2.25rem;
42
42
  min-height: 2.25rem;
43
- `;A(en)`
43
+ `;S(sn)`
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 wt=A.div`
48
+ `;var Mt=S.div`
49
49
  display: inline-flex;
50
50
  align-items: center;
51
51
  gap: 0.5rem;
52
- `,xt=A.input`
52
+ `,Dt=S.input`
53
53
  cursor: pointer;
54
54
  accent-color: ${e=>e.theme.inputFocusBorder};
55
55
 
56
56
  &:disabled {
57
57
  cursor: not-allowed;
58
58
  }
59
- `,yt=A.label`
59
+ `,Rt=S.label`
60
60
  margin: 0;
61
61
  cursor: pointer;
62
62
  user-select: none;
63
63
  font-family: ${e=>e.theme.fontFamily};
64
64
  font-size: ${e=>e.theme.fontSize};
65
65
  color: ${e=>e.theme.textColor};
66
- `,ye=A.button`
66
+ `,$e=S.button`
67
67
  padding: 0.5rem 1rem;
68
68
  background: ${e=>e.theme.buttonBackground||"#007bff"};
69
69
  color: ${e=>e.theme.buttonText||"white"};
@@ -89,7 +89,7 @@
89
89
  cursor: not-allowed;
90
90
  opacity: 0.6;
91
91
  }
92
- `,fr=A.input`
92
+ `,br=S.input`
93
93
  padding: 0.5rem 0.75rem;
94
94
  font-family: ${e=>e.theme.fontFamily};
95
95
  font-size: ${e=>e.theme.fontSize};
@@ -113,17 +113,17 @@
113
113
  opacity: 0.6;
114
114
  cursor: not-allowed;
115
115
  }
116
- `;A(fr)`
116
+ `;S(br)`
117
117
  padding: 0.25rem 0.5rem;
118
118
  font-size: ${e=>e.theme.fontSizeSmall};
119
- `;var hr=A.label`
119
+ `;var vr=S.label`
120
120
  font-family: ${e=>e.theme.fontFamily};
121
121
  font-size: ${e=>e.theme.fontSizeSmall};
122
122
  font-weight: 500;
123
123
  color: ${e=>e.theme.textColorMuted};
124
124
  margin-bottom: 0.25rem;
125
125
  display: block;
126
- `;A.label`
126
+ `;S.label`
127
127
  font-family: ${e=>e.theme.fontFamily};
128
128
  font-size: ${e=>e.theme.fontSize};
129
129
  color: ${e=>e.theme.textColor};
@@ -131,7 +131,7 @@
131
131
  align-items: center;
132
132
  gap: 0.5rem;
133
133
  cursor: pointer;
134
- `;var Ea=A.span`
134
+ `;var Ja=S.span`
135
135
  position: absolute;
136
136
  width: 1px;
137
137
  height: 1px;
@@ -141,7 +141,7 @@
141
141
  clip: rect(0, 0, 0, 0);
142
142
  white-space: nowrap;
143
143
  border: 0;
144
- `,tn=A.select`
144
+ `,ln=S.select`
145
145
  padding: 0.5rem 2rem 0.5rem 0.75rem;
146
146
  font-family: ${e=>e.theme.fontFamily};
147
147
  font-size: ${e=>e.theme.fontSize};
@@ -172,10 +172,10 @@
172
172
  color: ${e=>e.theme.inputText};
173
173
  background-color: ${e=>e.theme.inputBackground};
174
174
  }
175
- `;A(tn)`
175
+ `;S(ln)`
176
176
  padding: 0.25rem 1.75rem 0.25rem 0.5rem;
177
177
  font-size: ${e=>e.theme.fontSizeSmall};
178
- `;var mr=A.input.attrs({type:"range"})`
178
+ `;var Cr=S.input.attrs({type:"range"})`
179
179
  -webkit-appearance: none;
180
180
  appearance: none;
181
181
  width: 100%;
@@ -251,7 +251,7 @@
251
251
  &:disabled::-moz-range-thumb {
252
252
  cursor: not-allowed;
253
253
  }
254
- `,Ta=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return x.jsxs(wt,{className:r,children:[x.jsx(xt,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:a,disabled:n}),x.jsx(yt,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function pr(e){return typeof e=="object"&&e!==null&&"type"in e}function gt(e){if(!pr(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(r=>`${r.color} ${r.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var Wa={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"},Fa=1e3;function Za(e,t,n,r){if(!pr(t))return t;let a;t.direction==="vertical"?a=e.createLinearGradient(0,0,0,r):a=e.createLinearGradient(0,0,n,0);for(const s of t.stops)a.addColorStop(s.offset,s.color);return a}var _a=A.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
254
+ `,qa=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return w.jsxs(Mt,{className:r,children:[w.jsx(Dt,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:a,disabled:n}),w.jsx(Rt,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function wr(e){return typeof e=="object"&&e!==null&&"type"in e}function Oe(e){if(!wr(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(r=>`${r.color} ${r.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var xr={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"},Qa=1e3;function eo(e,t,n,r){if(!wr(t))return t;let a;t.direction==="vertical"?a=e.createLinearGradient(0,0,0,r):a=e.createLinearGradient(0,0,n,0);for(const s of t.stops)a.addColorStop(s.offset,s.color);return a}var to=S.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
255
255
  float: left;
256
256
  position: relative;
257
257
  /* Promote to own compositing layer for smoother scrolling */
@@ -259,15 +259,15 @@
259
259
  /* Disable image rendering interpolation */
260
260
  image-rendering: pixelated;
261
261
  image-rendering: crisp-edges;
262
- `,Va=A.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
262
+ `,no=S.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
263
263
  position: absolute;
264
264
  background: ${e=>e.$waveFillColor};
265
265
  /* Force GPU compositing layer to reduce scroll flickering */
266
266
  transform: translateZ(0);
267
267
  backface-visibility: hidden;
268
- `,za=e=>{const{data:t,bits:n,length:r,index:a,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:b=0,transparentBackground:g=!1,drawMode:f="inverted"}=e,v=i.useRef([]),y=i.useCallback(S=>{if(S!==null){const I=parseInt(S.dataset.index,10);v.current[I]=S}},[]);i.useLayoutEffect(()=>{const S=v.current,I=d+b;let k=0;for(let R=0;R<S.length;R++){const M=S[R],D=M.getContext("2d"),$=Math.floor(l/2),T=2**(n-1);if(D){D.resetTransform(),D.clearRect(0,0,M.width,M.height),D.imageSmoothingEnabled=!1,D.scale(o,o);const W=M.width/o;let H;f==="normal"?H=u:H=c,D.fillStyle=Za(D,H,W,l);const P=k,j=k+W,N=Math.floor((P-d+I)/I)*I;for(let Y=Math.max(0,N);Y<j;Y+=I){const z=Y-P;if(z+d<=0)continue;const K=Y;if(K*2+1<t.length){const ne=t[K*2]/T,te=t[K*2+1]/T,U=Math.abs(ne*$),J=Math.abs(te*$);f==="normal"?D.fillRect(z,$-J,d,J+U):(D.fillRect(z,0,d,$-J),D.fillRect(z,$+U,d,$-U))}}}k+=M.width/o}},[t,n,l,c,u,o,r,d,b,f]);let m=r,h=0;const w=[];for(;m>0;){const S=Math.min(m,Fa),I=x.jsx(_a,{$cssWidth:S,width:S*o,height:l*o,$waveHeight:l,"data-index":h,ref:y},`${r}-${h}`);w.push(I),m-=S,h+=1}const p=g?"transparent":gt(u);return x.jsx(Va,{$index:a,$cssWidth:r,className:s,$waveHeight:l,$waveFillColor:p,children:w})},gr=22,br=A.div`
268
+ `,ro=e=>{const{data:t,bits:n,length:r,index:a,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:f=1,barGap:x=0,transparentBackground:v=!1,drawMode:d="inverted"}=e,C=i.useRef([]),y=i.useCallback(I=>{if(I!==null){const k=parseInt(I.dataset.index,10);C.current[k]=I}},[]);i.useLayoutEffect(()=>{const I=C.current,k=f+x;let A=0;for(let R=0;R<I.length;R++){const D=I[R],M=D.getContext("2d"),$=Math.floor(l/2),E=2**(n-1);if(M){M.resetTransform(),M.clearRect(0,0,D.width,D.height),M.imageSmoothingEnabled=!1,M.scale(o,o);const Z=D.width/o;let P;d==="normal"?P=u:P=c,M.fillStyle=eo(M,P,Z,l);const F=A,V=A+Z,H=Math.floor((F-f+k)/k)*k;for(let q=Math.max(0,H);q<V;q+=k){const z=q-F;if(z+f<=0)continue;const B=q;if(B*2+1<t.length){const K=t[B*2]/E,U=t[B*2+1]/E,G=Math.abs(K*$),O=Math.abs(U*$);d==="normal"?M.fillRect(z,$-O,f,O+G):(M.fillRect(z,0,f,$-O),M.fillRect(z,$+G,f,$-G))}}}A+=D.width/o}},[t,n,l,c,u,o,r,f,x,d]);let h=r,b=0;const g=[];for(;h>0;){const I=Math.min(h,Qa),k=w.jsx(to,{$cssWidth:I,width:I*o,height:l*o,$waveHeight:l,"data-index":b,ref:y},`${r}-${b}`);g.push(k),h-=I,b+=1}const p=v?"transparent":Oe(u);return w.jsx(no,{$index:a,$cssWidth:r,className:s,$waveHeight:l,$waveFillColor:p,children:g})},yr=22,kr=S.div`
269
269
  position: relative;
270
- height: ${gr}px;
270
+ height: ${yr}px;
271
271
  background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
272
272
  border-bottom: 1px solid ${e=>e.theme.clipHeaderBorderColor};
273
273
  display: flex;
@@ -289,7 +289,7 @@
289
289
  cursor: grabbing;
290
290
  }
291
291
  `}
292
- `,vr=A.span`
292
+ `,Ir=S.span`
293
293
  font-size: 11px;
294
294
  font-weight: 600;
295
295
  font-family: ${e=>e.theme.clipHeaderFontFamily};
@@ -297,12 +297,12 @@
297
297
  white-space: nowrap;
298
298
  overflow: hidden;
299
299
  text-overflow: ellipsis;
300
- `,Xa=({trackName:e,isSelected:t=!1})=>x.jsx(br,{$isDragging:!1,$interactive:!1,$isSelected:t,children:x.jsx(vr,{children:e})}),Ha=({clipId:e,trackIndex:t,clipIndex:n,trackName:r,isSelected:a=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return x.jsx(Xa,{trackName:r,isSelected:a});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return x.jsx(br,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:a,...c,...l,children:x.jsx(vr,{children:r})})},ja=8,Pa=24,Ga=A.div`
300
+ `,ao=({trackName:e,isSelected:t=!1})=>w.jsx(kr,{$isDragging:!1,$interactive:!1,$isSelected:t,children:w.jsx(Ir,{children:e})}),oo=({clipId:e,trackIndex:t,clipIndex:n,trackName:r,isSelected:a=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return w.jsx(ao,{trackName:r,isSelected:a});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return w.jsx(kr,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:a,...c,...l,children:w.jsx(Ir,{children:r})})},so=8,io=24,lo=S.div`
301
301
  position: absolute;
302
302
  ${e=>e.$edge==="left"?"left: 0;":"right: 0;"}
303
303
  top: 0;
304
304
  bottom: 0;
305
- width: ${e=>e.$touchOptimized?Pa:ja}px;
305
+ width: ${e=>e.$touchOptimized?io:so}px;
306
306
  cursor: col-resize;
307
307
  user-select: none;
308
308
  z-index: 105; /* Above waveform, below header */
@@ -325,19 +325,19 @@
325
325
  background: rgba(255, 255, 255, 0.4);
326
326
  ${e=>e.$edge==="left"?"border-left: 2px solid rgba(255, 255, 255, 0.8);":"border-right: 2px solid rgba(255, 255, 255, 0.8);"}
327
327
  }
328
- `,kn=({clipId:e,trackIndex:t,clipIndex:n,edge:r,dragHandleProps:a,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!a)return null;const{attributes:c,listeners:u,setActivatorNodeRef:d,isDragging:b}=a;return x.jsx(Ga,{ref:d,"data-clip-id":e,"data-boundary-edge":r,$edge:r,$isDragging:b,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},La=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
328
+ `,Tn=({clipId:e,trackIndex:t,clipIndex:n,edge:r,dragHandleProps:a,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!a)return null;const{attributes:c,listeners:u,setActivatorNodeRef:f,isDragging:x}=a;return w.jsx(lo,{ref:f,"data-clip-id":e,"data-boundary-edge":r,$edge:r,$isDragging:x,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},co=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
329
329
  position: absolute;
330
330
  top: 0;
331
331
  bottom: 0;
332
332
  pointer-events: none;
333
333
  z-index: 50;
334
- `,Na=A.svg`
334
+ `,uo=S.svg`
335
335
  width: 100%;
336
336
  height: 100%;
337
337
  display: block;
338
338
  /* Flip horizontally for fadeOut - makes it mirror of fadeIn */
339
339
  transform: ${e=>e.$type==="fadeOut"?"scaleX(-1)":"none"};
340
- `;function Ya(e,t,n="logarithmic"){const r=[],a=Math.max(20,Math.min(e,100));for(let s=0;s<=a;s++){const o=s/a*e,l=s/a;let c;switch(n){case"linear":c=l;break;case"exponential":c=l*l;break;case"sCurve":c=(1-Math.cos(l*Math.PI))/2;break;case"logarithmic":default:c=Math.log10(1+l*9)/Math.log10(10);break}const u=(1-c)*t;r.push(`${o},${u}`)}return`M 0,${t} L ${r.join(" L ")} L ${e},0 L 0,0 Z`}var $n=({left:e,width:t,type:n,curveType:r="logarithmic",color:a})=>{const s=A.useTheme();if(t<1)return null;const o=a||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return x.jsx(La,{$left:e,$width:t,$type:n,children:x.jsx(Na,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:x.jsx("path",{d:Ya(t,100,r),fill:o})})})},Oa=A.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
340
+ `;function fo(e,t,n="logarithmic"){const r=[],a=Math.max(20,Math.min(e,100));for(let s=0;s<=a;s++){const o=s/a*e,l=s/a;let c;switch(n){case"linear":c=l;break;case"exponential":c=l*l;break;case"sCurve":c=(1-Math.cos(l*Math.PI))/2;break;case"logarithmic":default:c=Math.log10(1+l*9)/Math.log10(10);break}const u=(1-c)*t;r.push(`${o},${u}`)}return`M 0,${t} L ${r.join(" L ")} L ${e},0 L 0,0 Z`}var Bn=({left:e,width:t,type:n,curveType:r="logarithmic",color:a})=>{const s=S.useTheme();if(t<1)return null;const o=a||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return w.jsx(co,{$left:e,$width:t,$type:n,children:w.jsx(uo,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:w.jsx("path",{d:fo(t,100,r),fill:o})})})},ho=S.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
341
341
  position: ${e=>e.$isOverlay?"relative":"absolute"};
342
342
  top: 0;
343
343
  height: ${e=>e.$isOverlay?"auto":"100%"};
@@ -351,20 +351,20 @@
351
351
  &:hover {
352
352
  background: rgba(255, 255, 255, 0.08);
353
353
  }
354
- `,Ka=A.div`
354
+ `,mo=S.div`
355
355
  flex: 1;
356
356
  position: relative;
357
357
  overflow: ${e=>e.$isOverlay?"visible":"hidden"};
358
- `,Dn=({children:e,className:t,clipId:n,trackIndex:r,clipIndex:a,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:d=!1,isOverlay:b=!1,isSelected:g=!1,onMouseDown:f,trackId:v,fadeIn:y,fadeOut:m,sampleRate:h=44100,showFades:w=!1,touchOptimized:C=!1})=>{const p=Math.floor(o/c),I=Math.floor((o+l)/c)-p,k=u&&!d&&!b,R=`clip-${r}-${a}`,{attributes:M,listeners:D,setNodeRef:$,setActivatorNodeRef:T,transform:W,isDragging:H}=Zt({id:R,data:{clipId:n,trackIndex:r,clipIndex:a},disabled:!k}),P=`clip-boundary-left-${r}-${a}`,{attributes:j,listeners:N,setActivatorNodeRef:Y,isDragging:z}=Zt({id:P,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"left"},disabled:!k}),K=`clip-boundary-right-${r}-${a}`,{attributes:ne,listeners:te,setActivatorNodeRef:U,isDragging:J}=Zt({id:K,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"right"},disabled:!k}),fe=W?{transform:Pt.Translate.toString(W),zIndex:H?100:void 0}:void 0;return x.jsxs(Oa,{ref:$,style:fe,className:t,$left:p,$width:I,$isOverlay:b,"data-clip-container":"true","data-track-id":v,onMouseDown:f,children:[u&&x.jsx(Ha,{clipId:n,trackIndex:r,clipIndex:a,trackName:s,isSelected:g,disableDrag:d,dragHandleProps:k?{attributes:M,listeners:D,setActivatorNodeRef:T}:void 0}),x.jsxs(Ka,{$isOverlay:b,children:[e,w&&y&&y.duration>0&&x.jsx($n,{left:0,width:Math.floor(y.duration*h/c),type:"fadeIn",curveType:y.type}),w&&m&&m.duration>0&&x.jsx($n,{left:I-Math.floor(m.duration*h/c),width:Math.floor(m.duration*h/c),type:"fadeOut",curveType:m.type})]}),u&&!d&&!b&&x.jsxs(x.Fragment,{children:[x.jsx(kn,{clipId:n,trackIndex:r,clipIndex:a,edge:"left",touchOptimized:C,dragHandleProps:{attributes:j,listeners:N,setActivatorNodeRef:Y,isDragging:z}}),x.jsx(kn,{clipId:n,trackIndex:r,clipIndex:a,edge:"right",touchOptimized:C,dragHandleProps:{attributes:ne,listeners:te,setActivatorNodeRef:U,isDragging:J}})]})]})},Ua=A.div`
358
+ `,Jt=({children:e,className:t,clipId:n,trackIndex:r,clipIndex:a,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:f=!1,isOverlay:x=!1,isSelected:v=!1,onMouseDown:d,trackId:C,fadeIn:y,fadeOut:h,sampleRate:b=44100,showFades:g=!1,touchOptimized:m=!1})=>{const p=Math.floor(o/c),k=Math.floor((o+l)/c)-p,A=u&&!f&&!x,R=`clip-${r}-${a}`,{attributes:D,listeners:M,setNodeRef:$,setActivatorNodeRef:E,transform:Z,isDragging:P}=jt({id:R,data:{clipId:n,trackIndex:r,clipIndex:a},disabled:!A}),F=`clip-boundary-left-${r}-${a}`,{attributes:V,listeners:H,setActivatorNodeRef:q,isDragging:z}=jt({id:F,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"left"},disabled:!A}),B=`clip-boundary-right-${r}-${a}`,{attributes:K,listeners:U,setActivatorNodeRef:G,isDragging:O}=jt({id:B,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"right"},disabled:!A}),te=Z?{transform:Yt.Translate.toString(Z),zIndex:P?100:void 0}:void 0;return w.jsxs(ho,{ref:$,style:te,className:t,$left:p,$width:k,$isOverlay:x,"data-clip-container":"true","data-track-id":C,onMouseDown:d,children:[u&&w.jsx(oo,{clipId:n,trackIndex:r,clipIndex:a,trackName:s,isSelected:v,disableDrag:f,dragHandleProps:A?{attributes:D,listeners:M,setActivatorNodeRef:E}:void 0}),w.jsxs(mo,{$isOverlay:x,children:[e,g&&y&&y.duration>0&&w.jsx(Bn,{left:0,width:Math.floor(y.duration*b/c),type:"fadeIn",curveType:y.type}),g&&h&&h.duration>0&&w.jsx(Bn,{left:k-Math.floor(h.duration*b/c),width:Math.floor(h.duration*b/c),type:"fadeOut",curveType:h.type})]}),u&&!f&&!x&&w.jsxs(w.Fragment,{children:[w.jsx(Tn,{clipId:n,trackIndex:r,clipIndex:a,edge:"left",touchOptimized:m,dragHandleProps:{attributes:V,listeners:H,setActivatorNodeRef:q,isDragging:z}}),w.jsx(Tn,{clipId:n,trackIndex:r,clipIndex:a,edge:"right",touchOptimized:m,dragHandleProps:{attributes:K,listeners:U,setActivatorNodeRef:G,isDragging:O}})]})]})},po=S.div`
359
359
  display: inline-flex;
360
360
  align-items: center;
361
361
  gap: 0.5rem;
362
- `,Ja=A(hr)`
362
+ `,go=S(vr)`
363
363
  margin: 0;
364
364
  white-space: nowrap;
365
- `,qa=A(mr)`
365
+ `,bo=S(Cr)`
366
366
  width: 120px;
367
- `,Qa=({volume:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(parseFloat(s.target.value)/100)};return x.jsxs(Ua,{className:r,children:[x.jsx(Ja,{htmlFor:"master-gain",children:"Master Volume"}),x.jsx(qa,{min:"0",max:"100",value:e*100,onChange:a,disabled:n,id:"master-gain"})]})};A.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
367
+ `,vo=({volume:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(parseFloat(s.target.value)/100)};return w.jsxs(po,{className:r,children:[w.jsx(go,{htmlFor:"master-gain",children:"Master Volume"}),w.jsx(bo,{min:"0",max:"100",value:e*100,onChange:a,disabled:n,id:"master-gain"})]})};S.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
368
368
  position: absolute;
369
369
  top: 0;
370
370
  left: 0;
@@ -374,7 +374,7 @@
374
374
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
375
375
  pointer-events: none;
376
376
  will-change: transform;
377
- `;A.div`
377
+ `;S.div`
378
378
  position: absolute;
379
379
  top: 0;
380
380
  left: 0;
@@ -382,7 +382,7 @@
382
382
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
383
383
  pointer-events: none;
384
384
  will-change: transform;
385
- `;A.div`
385
+ `;S.div`
386
386
  position: absolute;
387
387
  top: -10px;
388
388
  left: -6px;
@@ -391,30 +391,30 @@
391
391
  border-left: 7px solid transparent;
392
392
  border-right: 7px solid transparent;
393
393
  border-top: 10px solid ${e=>e.$color};
394
- `;A.div`
394
+ `;S.div`
395
395
  position: absolute;
396
396
  top: 0;
397
397
  left: 0;
398
398
  width: 2px;
399
399
  height: 100%;
400
400
  background: ${e=>e.$color};
401
- `;var eo=A.div`
401
+ `;var Co=S.div`
402
402
  overflow-y: hidden;
403
403
  overflow-x: auto;
404
404
  position: relative;
405
- `,to=A.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
405
+ `,wo=S.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
406
406
  position: relative;
407
407
  background: ${e=>e.$backgroundColor||"transparent"};
408
- `,no=A.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
408
+ `,xo=S.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
409
409
  background: ${e=>e.$backgroundColor||"white"};
410
410
  width: 100%;
411
411
  position: relative;
412
412
  overflow: hidden; /* Constrain loop region to timescale area */
413
- `,ro=A.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
413
+ `,yo=S.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
414
414
  position: relative;
415
415
  background: ${e=>e.$backgroundColor||"transparent"};
416
416
  width: 100%;
417
- `,ao=A.div`
417
+ `,ko=S.div`
418
418
  position: absolute;
419
419
  top: 0;
420
420
  left: 0;
@@ -423,7 +423,7 @@
423
423
  cursor: crosshair;
424
424
  /* When selecting, raise z-index above clip boundaries (z-index: 105) to prevent interference */
425
425
  z-index: ${e=>e.$isSelecting?110:1};
426
- `,Cr=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:r,timescaleWidth:a,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:d,onTracksMouseUp:b,scrollContainerRef:g,isSelecting:f})=>x.jsx(eo,{"data-scroll-container":"true",ref:g,children:x.jsxs(to,{$backgroundColor:t,$width:o,children:[r&&x.jsx(no,{$width:a,$backgroundColor:n,children:r}),x.jsxs(ro,{$width:s,$backgroundColor:t,children:[e,(c||u)&&x.jsx(ao,{$controlsWidth:l,$isSelecting:f,onClick:c,onMouseDown:u,onMouseMove:d,onMouseUp:b})]})]})});A.withTheme(Cr);var oo=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
426
+ `,cn=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:r,timescaleWidth:a,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:f,onTracksMouseUp:x,scrollContainerRef:v,isSelecting:d})=>w.jsx(Co,{"data-scroll-container":"true",ref:v,children:w.jsxs(wo,{$backgroundColor:t,$width:o,children:[r&&w.jsx(xo,{$width:a,$backgroundColor:n,children:r}),w.jsxs(yo,{$width:s,$backgroundColor:t,children:[e,(c||u)&&w.jsx(ko,{$controlsWidth:l,$isSelecting:d,onClick:c,onMouseDown:u,onMouseMove:f,onMouseUp:x})]})]})});S.withTheme(cn);var Io=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
427
427
  position: absolute;
428
428
  top: 0;
429
429
  background: ${e=>e.$color};
@@ -431,14 +431,14 @@
431
431
  z-index: 60; /* Above clips (z-index: 10) and fades (z-index: 50), below playhead (z-index: 100) */
432
432
  pointer-events: none;
433
433
  opacity: 0.3;
434
- `,so=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const r=Math.max(0,t-e);return r<=0?null:x.jsx(oo,{$left:e,$width:r,$color:n,"data-selection":!0})};A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
434
+ `,Sr=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const r=Math.max(0,t-e);return r<=0?null:w.jsx(Io,{$left:e,$width:r,$color:n,"data-selection":!0})};S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
435
435
  position: absolute;
436
436
  top: 0;
437
437
  background: ${e=>e.$color};
438
438
  height: 100%;
439
439
  z-index: 55; /* Between clips (z-index: 50) and selection (z-index: 60) */
440
440
  pointer-events: none;
441
- `;A.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
441
+ `;S.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
442
442
  position: absolute;
443
443
  top: 0;
444
444
  width: 2px;
@@ -458,7 +458,7 @@
458
458
  border-top: 8px solid ${e=>e.$color};
459
459
  ${e=>e.$isStart?"border-right: 8px solid transparent;":"border-left: 8px solid transparent;"}
460
460
  }
461
- `;var Mn=A.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
461
+ `;var Wn=S.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
462
462
  position: absolute;
463
463
  top: 0;
464
464
  width: 12px;
@@ -495,7 +495,7 @@
495
495
  &:hover::before {
496
496
  opacity: 1;
497
497
  }
498
- `,io=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
498
+ `,So=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
499
499
  position: absolute;
500
500
  top: 0;
501
501
  height: 100%;
@@ -506,41 +506,41 @@
506
506
  &:active {
507
507
  cursor: grabbing;
508
508
  }
509
- `,lo=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopStartChange:a,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),b=i.useRef(0),g=i.useRef(0),f=i.useRef(0),v=Math.max(0,t-e),y=i.useCallback((h,w)=>{h.preventDefault(),h.stopPropagation(),d(w),b.current=h.clientX,g.current=w==="start"?e:t;const C=S=>{const I=S.clientX-b.current,k=g.current+I;if(w==="start"){const R=Math.max(l,Math.min(t-10,k));a?.(R)}else{const R=Math.max(e+10,Math.min(c,k));s?.(R)}},p=()=>{d(null),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",p)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",p)},[e,t,l,c,a,s]),m=i.useCallback(h=>{h.preventDefault(),h.stopPropagation(),d("region"),b.current=h.clientX,g.current=e,f.current=t;const w=t-e,C=S=>{const I=S.clientX-b.current;let k=g.current+I,R=f.current+I;k<l&&(k=l,R=l+w),R>c&&(R=c,k=c-w),o?.(k,R)},p=()=>{d(null),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",p)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",p)},[e,t,l,c,o]);return v<=0?null:x.jsxs(x.Fragment,{children:[x.jsx(io,{$left:e,$width:v,$color:r,$isDragging:u==="region",onMouseDown:m,"data-loop-region-timescale":!0}),x.jsx(Mn,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:h=>y(h,"start"),"data-loop-marker-handle":"start"}),x.jsx(Mn,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:h=>y(h,"end"),"data-loop-marker-handle":"end"})]})},co=A.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
509
+ `,Ao=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopStartChange:a,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,f]=i.useState(null),x=i.useRef(0),v=i.useRef(0),d=i.useRef(0),C=Math.max(0,t-e),y=i.useCallback((b,g)=>{b.preventDefault(),b.stopPropagation(),f(g),x.current=b.clientX,v.current=g==="start"?e:t;const m=I=>{const k=I.clientX-x.current,A=v.current+k;if(g==="start"){const R=Math.max(l,Math.min(t-10,A));a?.(R)}else{const R=Math.max(e+10,Math.min(c,A));s?.(R)}},p=()=>{f(null),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",p)};document.addEventListener("mousemove",m),document.addEventListener("mouseup",p)},[e,t,l,c,a,s]),h=i.useCallback(b=>{b.preventDefault(),b.stopPropagation(),f("region"),x.current=b.clientX,v.current=e,d.current=t;const g=t-e,m=I=>{const k=I.clientX-x.current;let A=v.current+k,R=d.current+k;A<l&&(A=l,R=l+g),R>c&&(R=c,A=c-g),o?.(A,R)},p=()=>{f(null),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",p)};document.addEventListener("mousemove",m),document.addEventListener("mouseup",p)},[e,t,l,c,o]);return C<=0?null:w.jsxs(w.Fragment,{children:[w.jsx(So,{$left:e,$width:C,$color:r,$isDragging:u==="region",onMouseDown:h,"data-loop-region-timescale":!0}),w.jsx(Wn,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:b=>y(b,"start"),"data-loop-marker-handle":"start"}),w.jsx(Wn,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:b=>y(b,"end"),"data-loop-marker-handle":"end"})]})},$o=S.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
510
510
  position: absolute;
511
511
  top: 0;
512
512
  right: 0;
513
513
  height: 100%; /* Stay within timescale bounds, don't extend into tracks */
514
514
  cursor: crosshair;
515
515
  z-index: 40; /* Below markers and shading */
516
- `,uo=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopRegionChange:a,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),b=i.useRef(null),g=t>e,f=i.useCallback(v=>{const y=v.target;if(y.closest("[data-loop-marker-handle]")||y.closest("[data-loop-region-timescale]"))return;v.preventDefault(),u(!0);const m=b.current?.getBoundingClientRect();if(!m)return;const h=v.clientX-m.left,w=Math.max(s,Math.min(o,h));d.current=w,a?.(w,w);const C=S=>{const I=S.clientX-m.left,k=Math.max(s,Math.min(o,I)),R=Math.min(d.current,k),M=Math.max(d.current,k);a?.(R,M)},p=()=>{u(!1),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",p)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",p)},[s,o,a]);return x.jsx(co,{ref:b,$leftOffset:l,onMouseDown:f,"data-timescale-loop-creator":!0,children:g&&x.jsx(lo,{startPosition:e,endPosition:t,markerColor:n,regionColor:r,minPosition:s,maxPosition:o,onLoopStartChange:v=>a?.(v,t),onLoopEndChange:v=>a?.(e,v),onLoopRegionMove:(v,y)=>a?.(v,y)})})};function tt(e,t){const n=Math.floor(e/3600)%24,r=Math.floor(e/60)%60,a=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(r).padStart(2,"0")+":"+a.padStart(t+3,"0")}function Ue(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return tt(e,0);case"hh:mm:ss.u":return tt(e,1);case"hh:mm:ss.uu":return tt(e,2);case"hh:mm:ss.uuu":return tt(e,3);default:return tt(e,3)}}function wr(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const r=parseInt(n[0],10)||0,a=parseInt(n[1],10)||0,s=parseFloat(n[2])||0;return r*3600+a*60+s}default:return 0}}var Rn=({id:e,label:t,value:n,format:r,className:a,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const g=Ue(n,r);c(g)},[n,r,e]);const u=g=>{const f=g.target.value;c(f)},d=()=>{if(s){const g=wr(l,r);s(g)}c(Ue(n,r))},b=g=>{g.key==="Enter"&&g.currentTarget.blur()};return x.jsxs(x.Fragment,{children:[x.jsx(Ea,{as:"label",htmlFor:e,children:t}),x.jsx(fr,{type:"text",className:a,id:e,value:l,onChange:u,onBlur:d,onKeyDown:b,readOnly:o})]})},fo=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:r})=>{const[a,s]=i.useState("hh:mm:ss.uuu");i.useEffect(()=>{const c=document.querySelector(".time-format"),u=()=>{c&&s(c.value)};return c&&(s(c.value),c.addEventListener("change",u)),()=>{c?.removeEventListener("change",u)}},[]);const o=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return x.jsxs(x.Fragment,{children:[x.jsx(Rn,{id:"audio_start",label:"Start of audio selection",value:e,format:a,className:"audio-start form-control mr-sm-2",onChange:o}),x.jsx(Rn,{id:"audio_end",label:"End of audio selection",value:t,format:a,className:"audio-end form-control mr-sm-2",onChange:l})]})};function mt(){return window.devicePixelRatio}var xr=i.createContext(mt()),ho=({children:e})=>{const[t,n]=i.useState(mt());return matchMedia(`(resolution: ${mt()}dppx)`).addEventListener("change",()=>{n(mt())},{once:!0}),x.jsx(xr.Provider,{value:Math.ceil(t),children:e})},yr=()=>i.useContext(xr),nn=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}),It=()=>i.useContext(nn),rn=()=>i.useContext(A.ThemeContext),Ir=i.createContext(x.jsx(i.Fragment,{})),mo=()=>i.useContext(Ir),po=0,go=!1,bo=0,vo=0,Co={progress:po,isPlaying:go,selectionStart:bo,selectionEnd:vo};i.createContext(Co);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var wo=({isSelected:e,transparentBackground:t,...n})=>{const r=rn(),{waveHeight:a,barWidth:s,barGap:o}=It(),l=yr(),c=e&&r?r.selectedWaveOutlineColor:r?.waveOutlineColor,u=e&&r?r.selectedWaveFillColor:r?.waveFillColor,d=r?.waveformDrawMode||"inverted";return x.jsx(za,{...n,...r,waveOutlineColor:c,waveFillColor:u,waveHeight:a,devicePixelRatio:l,barWidth:s,barGap:o,transparentBackground:t,drawMode:d})};function xo(e,t,n){return Math.ceil(e*n/t)}function yo(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var Io=A.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
516
+ `,Mo=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopRegionChange:a,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),f=i.useRef(0),x=i.useRef(null),v=t>e,d=i.useCallback(C=>{const y=C.target;if(y.closest("[data-loop-marker-handle]")||y.closest("[data-loop-region-timescale]"))return;C.preventDefault(),u(!0);const h=x.current?.getBoundingClientRect();if(!h)return;const b=C.clientX-h.left,g=Math.max(s,Math.min(o,b));f.current=g,a?.(g,g);const m=I=>{const k=I.clientX-h.left,A=Math.max(s,Math.min(o,k)),R=Math.min(f.current,A),D=Math.max(f.current,A);a?.(R,D)},p=()=>{u(!1),document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",p)};document.addEventListener("mousemove",m),document.addEventListener("mouseup",p)},[s,o,a]);return w.jsx($o,{ref:x,$leftOffset:l,onMouseDown:d,"data-timescale-loop-creator":!0,children:v&&w.jsx(Ao,{startPosition:e,endPosition:t,markerColor:n,regionColor:r,minPosition:s,maxPosition:o,onLoopStartChange:C=>a?.(C,t),onLoopEndChange:C=>a?.(e,C),onLoopRegionMove:(C,y)=>a?.(C,y)})})};function it(e,t){const n=Math.floor(e/3600)%24,r=Math.floor(e/60)%60,a=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(r).padStart(2,"0")+":"+a.padStart(t+3,"0")}function rt(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return it(e,0);case"hh:mm:ss.u":return it(e,1);case"hh:mm:ss.uu":return it(e,2);case"hh:mm:ss.uuu":return it(e,3);default:return it(e,3)}}function Ar(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const r=parseInt(n[0],10)||0,a=parseInt(n[1],10)||0,s=parseFloat(n[2])||0;return r*3600+a*60+s}default:return 0}}var Fn=({id:e,label:t,value:n,format:r,className:a,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const v=rt(n,r);c(v)},[n,r,e]);const u=v=>{const d=v.target.value;c(d)},f=()=>{if(s){const v=Ar(l,r);s(v)}c(rt(n,r))},x=v=>{v.key==="Enter"&&v.currentTarget.blur()};return w.jsxs(w.Fragment,{children:[w.jsx(Ja,{as:"label",htmlFor:e,children:t}),w.jsx(br,{type:"text",className:a,id:e,value:l,onChange:u,onBlur:f,onKeyDown:x,readOnly:o})]})},Do=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:r})=>{const[a,s]=i.useState("hh:mm:ss.uuu");i.useEffect(()=>{const c=document.querySelector(".time-format"),u=()=>{c&&s(c.value)};return c&&(s(c.value),c.addEventListener("change",u)),()=>{c?.removeEventListener("change",u)}},[]);const o=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return w.jsxs(w.Fragment,{children:[w.jsx(Fn,{id:"audio_start",label:"Start of audio selection",value:e,format:a,className:"audio-start form-control mr-sm-2",onChange:o}),w.jsx(Fn,{id:"audio_end",label:"End of audio selection",value:t,format:a,className:"audio-end form-control mr-sm-2",onChange:l})]})};function kt(){return window.devicePixelRatio}var $r=i.createContext(kt()),Mr=({children:e})=>{const[t,n]=i.useState(kt());return matchMedia(`(resolution: ${kt()}dppx)`).addEventListener("change",()=>{n(kt())},{once:!0}),w.jsx($r.Provider,{value:Math.ceil(t),children:e})},Dr=()=>i.useContext($r),Et=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}),ut=()=>i.useContext(Et),dt=()=>i.useContext(S.ThemeContext),un=i.createContext(w.jsx(i.Fragment,{})),Ro=()=>i.useContext(un),Eo=0,To=!1,Bo=0,Wo=0,Fo={progress:Eo,isPlaying:To,selectionStart:Bo,selectionEnd:Wo};i.createContext(Fo);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var Rr=({isSelected:e,transparentBackground:t,...n})=>{const r=dt(),{waveHeight:a,barWidth:s,barGap:o}=ut(),l=Dr(),c=e&&r?r.selectedWaveOutlineColor:r?.waveOutlineColor,u=e&&r?r.selectedWaveFillColor:r?.waveFillColor,f=r?.waveformDrawMode||"inverted";return w.jsx(ro,{...n,...r,waveOutlineColor:c,waveFillColor:u,waveHeight:a,devicePixelRatio:l,barWidth:s,barGap:o,transparentBackground:t,drawMode:f})};function _o(e,t,n){return Math.ceil(e*n/t)}function Zo(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var Po=S.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
517
517
  position: relative;
518
518
  overflow: visible; /* Allow time labels to render above the container */
519
519
  border-bottom: 1px solid ${e=>e.theme.timeColor};
520
520
  box-sizing: border-box;
521
- `,So=A.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
521
+ `,Vo=S.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
522
522
  position: absolute;
523
523
  left: 0;
524
524
  right: 0;
525
525
  bottom: 0;
526
- `,Ao=A.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
526
+ `,zo=S.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
527
527
  position: absolute;
528
528
  font-size: 0.75rem; /* Smaller font to prevent overflow */
529
529
  white-space: nowrap; /* Prevent text wrapping */
530
530
  color: ${e=>e.theme.timeColor}; /* Use theme color instead of inheriting */
531
- `,ko=e=>{const{theme:{timeColor:t},duration:n,marker:r,bigStep:a,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:d,samplesPerPixel:b,timeScaleHeight:g,controls:{show:f,width:v}}=i.useContext(nn),y=yr();i.useEffect(()=>{if(u.current!==null){const C=u.current,p=C.getContext("2d");if(p){p.resetTransform(),p.clearRect(0,0,C.width,C.height),p.imageSmoothingEnabled=!1,p.fillStyle=t,p.scale(y,y);for(const[S,I]of l.entries()){const k=g-I;p.fillRect(S,k,1,I)}}}},[n,y,t,g,a,s,r,l]);const m=xo(n/1e3,b,d),h=d/b;let w=0;for(let C=0;C<m;C+=h*s/1e3){const p=Math.floor(C);if(w%r===0){const S=w,I=yo(S),k=o?x.jsx(i.Fragment,{children:o(S,p)},`timestamp-${w}`):x.jsx(Ao,{$left:p,children:I},I);c.push(k),l.set(p,g)}else w%a===0?l.set(p,Math.floor(g/2)):w%s===0&&l.set(p,Math.floor(g/5));w+=s}return x.jsxs(Io,{$cssWidth:m,$controlWidth:f?v:0,$timeScaleHeight:g,children:[c,x.jsx(So,{$cssWidth:m,$timeScaleHeight:g,width:m*y,height:g*y,ref:u})]})},$o=A.withTheme(ko),Do=A.div`
531
+ `,jo=e=>{const{theme:{timeColor:t},duration:n,marker:r,bigStep:a,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:f,samplesPerPixel:x,timeScaleHeight:v,controls:{show:d,width:C}}=i.useContext(Et),y=Dr();i.useEffect(()=>{if(u.current!==null){const m=u.current,p=m.getContext("2d");if(p){p.resetTransform(),p.clearRect(0,0,m.width,m.height),p.imageSmoothingEnabled=!1,p.fillStyle=t,p.scale(y,y);for(const[I,k]of l.entries()){const A=v-k;p.fillRect(I,A,1,k)}}}},[n,y,t,v,a,s,r,l]);const h=_o(n/1e3,x,f),b=f/x;let g=0;for(let m=0;m<h;m+=b*s/1e3){const p=Math.floor(m);if(g%r===0){const I=g,k=Zo(I),A=o?w.jsx(i.Fragment,{children:o(I,p)},`timestamp-${g}`):w.jsx(zo,{$left:p,children:k},k);c.push(A),l.set(p,v)}else g%a===0?l.set(p,Math.floor(v/2)):g%s===0&&l.set(p,Math.floor(v/5));g+=s}return w.jsxs(Po,{$cssWidth:h,$controlWidth:d?C:0,$timeScaleHeight:v,children:[c,w.jsx(Vo,{$cssWidth:h,$timeScaleHeight:v,width:h*y,height:v*y,ref:u})]})},Er=S.withTheme(jo),Xo=S.div`
532
532
  display: inline-flex;
533
533
  align-items: center;
534
534
  gap: 0.5rem;
535
- `,Mo=[{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"}],Ro=({value:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.value)};return x.jsx(Do,{className:r,children:x.jsx(tn,{className:"time-format",value:e,onChange:a,disabled:n,"aria-label":"Time format selection",children:Mo.map(s=>x.jsx("option",{value:s.value,children:s.label},s.value))})})},Bo=A.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?gr:0)}px`}}))`
535
+ `,Ho=[{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"}],Lo=({value:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.value)};return w.jsx(Xo,{className:r,children:w.jsx(ln,{className:"time-format",value:e,onChange:a,disabled:n,"aria-label":"Time format selection",children:Ho.map(s=>w.jsx("option",{value:s.value,children:s.label},s.value))})})},No=S.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?yr:0)}px`}}))`
536
536
  position: relative;
537
537
  display: flex;
538
538
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
539
- `,Eo=A.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
539
+ `,Go=S.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
540
540
  position: relative;
541
541
  background: ${e=>e.$backgroundColor||"transparent"};
542
542
  flex: 1;
543
- `,To=A.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
543
+ `,Oo=S.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
544
544
  position: sticky;
545
545
  z-index: 101; /* Above waveform content, below Docusaurus navbar (z-index: 200) */
546
546
  left: 0;
@@ -554,7 +554,7 @@
554
554
  ${e=>e.$isSelected&&`
555
555
  background: ${e.theme.selectedTrackControlsBackground};
556
556
  `}
557
- `,Wo=({numChannels:e,children:t,className:n,backgroundColor:r,offset:a=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:d,controls:{show:b,width:g}}=It(),f=mo();return x.jsxs(Bo,{$numChannels:e,className:n,$waveHeight:d,$controlWidth:b?g:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[x.jsx(To,{$controlWidth:b?g:0,$isSelected:u,children:f}),x.jsx(Eo,{$controlWidth:b?g:0,$backgroundColor:r,$offset:a,onClick:l,"data-track-id":c,children:t})]})},Bn=A.button.attrs({type:"button"})`
557
+ `,Tr=({numChannels:e,children:t,className:n,backgroundColor:r,offset:a=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:f,controls:{show:x,width:v}}=ut(),d=Ro();return w.jsxs(No,{$numChannels:e,className:n,$waveHeight:f,$controlWidth:x?v:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[w.jsx(Oo,{$controlWidth:x?v:0,$isSelected:u,children:d}),w.jsx(Go,{$controlWidth:x?v:0,$backgroundColor:r,$offset:a,onClick:l,"data-track-id":c,children:t})]})},_n=S.button.attrs({type:"button"})`
558
558
  display: inline-block;
559
559
  font-family: ${e=>e.theme.fontFamily};
560
560
  font-weight: 500;
@@ -613,7 +613,7 @@
613
613
  box-shadow: 0 0 0 0.2rem ${e.theme.inputFocusBorder}33;
614
614
  }
615
615
  `}
616
- `,Fo=A.div`
616
+ `,Yo=S.div`
617
617
  margin-bottom: 0.3rem;
618
618
 
619
619
  button:not(:first-child) {
@@ -625,7 +625,7 @@
625
625
  border-top-right-radius: 0;
626
626
  border-bottom-right-radius: 0;
627
627
  }
628
- `,Zo=A.div`
628
+ `,Ko=S.div`
629
629
  background: transparent;
630
630
  width: 100%;
631
631
  height: 100%;
@@ -638,7 +638,7 @@
638
638
  text-align: center;
639
639
  border: 1px solid ${e=>e.theme.borderColor};
640
640
  border-radius: ${e=>e.theme.borderRadius};
641
- `,_o=A.header`
641
+ `,Uo=S.header`
642
642
  overflow: hidden;
643
643
  height: 26px;
644
644
  width: 100%;
@@ -649,7 +649,7 @@
649
649
  font-size: ${e=>e.theme.fontSizeSmall};
650
650
  color: ${e=>e.theme.textColor};
651
651
  background-color: transparent;
652
- `,Vo=e=>x.jsx(dr,{weight:"light",...e}),zo=e=>x.jsx(ur,{weight:"light",...e}),En=A(mr)`
652
+ `,Jo=e=>w.jsx(gr,{weight:"light",...e}),qo=e=>w.jsx(pr,{weight:"light",...e}),Zn=S(Cr)`
653
653
  width: 75%;
654
654
  height: 5px;
655
655
  background: ${e=>e.theme.sliderTrackColor};
@@ -698,7 +698,7 @@
698
698
  &:focus::-moz-range-thumb {
699
699
  border: 2px solid ${e=>e.theme.textColor};
700
700
  }
701
- `,Tn=A.label`
701
+ `,Pn=S.label`
702
702
  width: 100%;
703
703
  display: flex;
704
704
  justify-content: space-between;
@@ -706,12 +706,12 @@
706
706
  padding: 0 1rem;
707
707
  margin-bottom: 0.2rem;
708
708
  font-size: 14px;
709
- `;A.div`
709
+ `;S.div`
710
710
  display: flex;
711
711
  align-items: center;
712
712
  gap: 0.25rem;
713
713
  padding: 0.5rem 0.5rem 0.25rem 0.5rem;
714
- `;A.span`
714
+ `;S.span`
715
715
  flex: 1;
716
716
  font-weight: 600;
717
717
  font-size: 0.875rem;
@@ -719,7 +719,7 @@
719
719
  text-overflow: ellipsis;
720
720
  white-space: nowrap;
721
721
  margin: 0 0.25rem;
722
- `;A.button`
722
+ `;S.button`
723
723
  display: flex;
724
724
  align-items: center;
725
725
  justify-content: center;
@@ -744,8 +744,8 @@
744
744
  &:active {
745
745
  transform: scale(0.9);
746
746
  }
747
- `;function Xo(e){let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){const a=e[r];t>a&&(t=a),n<a&&(n=a)}return{min:t,max:n}}function Wn(e,t){const n=Math.pow(2,t-1),r=e<0?e*n:e*(n-1);return Math.max(-n,Math.min(n-1,r))}function Sr(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function Fn(e,t,n){const r=e.length,a=Math.ceil(r/t),s=Sr(n,a*2);for(let o=0;o<a;o++){const l=o*t,c=Math.min((o+1)*t,r),u=e.subarray(l,c),d=Xo(u),b=Wn(d.min,n),g=Wn(d.max,n);s[o*2]=b,s[o*2+1]=g}return s}function Ho(e,t){const n=e.length,r=1/n,a=e[0].length/2,s=Sr(t,a*2);for(let o=0;o<a;o++){let l=0,c=0;for(let u=0;u<n;u++)l+=r*e[u][o*2],c+=r*e[u][o*2+1];s[o*2]=l,s[o*2+1]=c}return[s]}function jo(e,t=1e3,n=!0,r=0,a,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=a??e.length;for(let d=0;d<c;d++){const g=e.getChannelData(d).subarray(r,u);o.push(Fn(g,t,s))}}else{const c=a??e.length,u=e.subarray(r,c);o.push(Fn(u,t,s))}return n&&o.length>1&&(o=Ho(o,s)),{length:o[0].length/2,data:o,bits:s}}function Po(e,t=1e3,n=!0,r=8,a=0,s){const o=s!==void 0?a+s:void 0;return jo(e,t,n,a,o,r)}function je(e,t){this._waveformData=e,this._channelIndex=t}je.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};je.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};je.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};je.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};je.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};je.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 Go=127,Lo=-128,No=32767,Yo=-32768;function Oo(e,t){var n=Math.floor(e/t),r=e-n*t;return r>0&&n++,n}function Ko(e){for(var t=e.scale,n=e.amplitude_scale,r=e.split_channels,a=e.length,s=e.sample_rate,o=e.channels.map(function($){return new Float32Array($)}),l=r?o.length:1,c=24,u=Oo(a,t),d=e.bits===8?1:2,b=c+u*2*d*l,g=new ArrayBuffer(b),f=new DataView(g),v=0,y=c,m=new Array(l),h=new Array(l),w=0;w<l;w++)m[w]=1/0,h[w]=-1/0;var C=e.bits===8?Lo:Yo,p=e.bits===8?Go:No;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 S=0;S<a;S++){var I=0;if(l===1){for(var k=0;k<o.length;++k)I+=o[k][S];I=Math.floor(p*I*n/o.length),I<m[0]&&(m[0]=I,m[0]<C&&(m[0]=C)),I>h[0]&&(h[0]=I,h[0]>p&&(h[0]=p))}else for(var R=0;R<l;++R)I=Math.floor(p*o[R][S]*n),I<m[R]&&(m[R]=I,m[R]<C&&(m[R]=C)),I>h[R]&&(h[R]=I,h[R]>p&&(h[R]=p));if(++v===t){for(var M=0;M<l;M++)e.bits===8?(f.setInt8(y++,m[M]),f.setInt8(y++,h[M])):(f.setInt16(y,m[M],!0),f.setInt16(y+2,h[M],!0),y+=4),m[M]=1/0,h[M]=-1/0;v=0}}if(v>0)for(var D=0;D<l;D++)e.bits===8?(f.setInt8(y++,m[D]),f.setInt8(y++,h[D])):(f.setInt16(y,m[D],!0),f.setInt16(y+2,h[D],!0));return g}function bt(e){"@babel/helpers - typeof";return bt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},bt(e)}function Uo(e){return e&&bt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Jo(e){var t=e&&bt(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),r=n.getInt32(0,!0);if(r!==1&&r!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function qo(e){var t=e.data,n=e.channels||1,r=24,a=e.bits===8?1:2,s=e.length*2*n;if(t.length!==s)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var o=r+t.length*a,l=new ArrayBuffer(o),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=r;if(e.bits===8)for(var d=0;d<t.length;d++)c.setInt8(u++,t[d],!0);else for(var b=0;b<t.length;b++)c.setInt16(u,t[b],!0),u+=2;return l}function Ne(e){return e==null}function Qo(e,t){var n=atob(e);return n}function es(e,t,n){var r=Qo(e),a=r.indexOf(`
748
- `,10)+1,s=r.substring(a)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function ts(e,t,n){var r;return function(s){return r=r||es(e),new Worker(r,s)}}var ns=ts("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function xe(e){if(Uo(e)&&(e=qo(e)),Jo(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 je(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var nt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function rs(e){var t={scale:e.scale||nt.scale,bits:e.bits||nt.bits,amplitude_scale:e.amplitude_scale||nt.amplitude_scale,split_channels:e.split_channels||nt.split_channels,disable_worker:e.disable_worker||nt.disable_worker};return t}function as(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Ar(e,t,n){var r=as(e);if(t.disable_worker){var a=Ko({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r});n(void 0,new xe(a),e)}else{var s=new ns;s.onmessage=function(o){n(void 0,new xe(o.data),e)},s.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r},r)}}function os(e,t,n,r){function a(o){o||(o=new DOMException("EncodingError")),r(o),r=function(){}}var s=e.decodeAudioData(t,function(o){Ar(o,n,r)},a);s&&s.catch(a)}xe.create=function(t){return new xe(t)};xe.createFromAudio=function(e,t){var n=rs(e);if(e.audio_context&&e.array_buffer)return os(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Ar(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function St(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),r=24,a=this._inputData.bits===8?1:2,s=r+n*2*this._inputData.channels*a;this._output_data=new ArrayBuffer(s),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new xe(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}St.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};St.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,r;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var a=0;a<n;++a)r=this._outputWaveformData.channel(a),r.set_min_sample(this._output_index-1,this._min[a]),r.set_max_sample(this._output_index-1,this._max[a]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var s=0;s<n;++s)this._min[s]=this._max_value,this._max[s]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var o=0;o<n;++o){r=this._inputData.channel(o);var l=r.min_sample(this._input_index);l<this._min[o]&&(this._min[o]=l),l=r.max_sample(this._input_index),l>this._max[o]&&(this._max[o]=l)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var c=0;c<n;++c)r=this._outputWaveformData.channel(c),r.set_min_sample(this._output_index-1,this._min[c]),r.set_max_sample(this._output_index-1,this._max[c]);return!0};St.prototype.getOutputData=function(){return this._output_data};xe.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!Ne(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!Ne(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 St(t);!n.next(););return new xe(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(a){if(t.channels!==a.channels||t.sample_rate!==a.sample_rate||t.bits!==a.bits||t.scale!==a.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var r=this._concatBuffers.apply(this,n);return xe.create(r)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,r=n,a=0,s=[this].concat(t).map(function(h){return h._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);r+=l.byteLength-n,a+=c}for(var u=new ArrayBuffer(r),d=new DataView(s[0]),b=new DataView(u),g=0;g<n;g++)b.setUint8(g,d.getUint8(g));b.setInt32(16,a,!0);for(var f=0,v=new Uint8Array(u,n),y=0;y<s.length;y++){var m=s[y];v.set(new Uint8Array(m,n),f),f+=m.byteLength-n}return u},slice:function(t){var n=0,r=0;if(!Ne(t.startIndex)&&!Ne(t.endIndex)?(n=t.startIndex,r=t.endIndex):!Ne(t.startTime)&&!Ne(t.endTime)&&(n=this.at_time(t.startTime),r=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(r<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),r>this.length&&(r=this.length),n>r&&(n=r);var a=r-n,s=24,o=this.bits===8?1:2,l=s+a*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,a,!0),u.setInt32(20,this.channels,!0);for(var d=0;d<a*this.channels*2;d++){var 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 xe(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var r=0;r<this.channels;r++)t.data.push(this.channel(r).min_sample(n)),t.data.push(this.channel(r).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function an(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const r=await t.arrayBuffer();return xe.create(r)}else{const r=await t.json();return xe.create(r)}}function kr(e,t=0){const n=e.channel(t),r=e.bits,a=n.min_array(),s=n.max_array(),o=a.length,l=r===8?new Int8Array(o*2):new Int16Array(o*2);for(let c=0;c<o;c++)l[c*2]=a[c],l[c*2+1]=s[c];return{data:l,bits:r,length:o,sampleRate:e.sample_rate}}async function ss(e,t=0){const n=await an(e);return kr(n,t)}async function is(e){const t=await an(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function ls(e,t,n=0,r,a){let s=e;if(r!==void 0&&a!==void 0){const g=e.scale,f=Math.floor(r/g),v=Math.ceil((r+a)/g);s=s.slice({startIndex:f,endIndex:v})}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 g=0;g<d;g++)b[g*2]=c[g],b[g*2+1]=u[g];return{data:b,bits:l,length:d}}var Zn;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Zn||(Zn={}));function _n(){}const cs=Object.freeze({x:0,y:0});var Oe;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Oe||(Oe={}));var Vn;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Vn||(Vn={}));var ze;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(ze||(ze={}));ze.Space,ze.Enter,ze.Esc,ze.Space,ze.Enter,ze.Tab;var zn;(function(e){e[e.RightClick=2]="RightClick"})(zn||(zn={}));var Xn;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Xn||(Xn={}));var Hn;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Hn||(Hn={}));Oe.Backward+"",Oe.Forward+"",Oe.Backward+"",Oe.Forward+"";var Nt;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Nt||(Nt={}));var Yt;(function(e){e.Optimized="optimized"})(Yt||(Yt={}));function us(e,t){return i.useMemo(()=>e.reduce((n,r)=>{let{eventName:a,handler:s}=r;return n[a]=o=>{s(o,t)},n},{}),[e,t])}Nt.WhileDragging,Yt.Optimized;const ds={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:_n,draggableNodes:new Map,over:null,measureDroppableContainers:_n},fs=i.createContext(ds),hs=i.createContext({...cs,scaleX:1,scaleY:1});var jn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(jn||(jn={}));const ms=i.createContext(null),Pn="button",ps="Draggable";function Gn(e){let{id:t,data:n,disabled:r=!1,attributes:a}=e;const s=cr(ps),{activators:o,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:d,draggableNodes:b,over:g}=i.useContext(fs),{role:f=Pn,roleDescription:v="draggable",tabIndex:y=0}=a??{},m=c?.id===t,h=i.useContext(m?hs:ms),[w,C]=pt(),[p,S]=pt(),I=us(o,t),k=lr(n);Ct(()=>(b.set(t,{id:t,key:s,node:w,activatorNode:p,data:k}),()=>{const M=b.get(t);M&&M.key===s&&b.delete(t)}),[b,t]);const R=i.useMemo(()=>({role:f,tabIndex:y,"aria-disabled":r,"aria-pressed":m&&f===Pn?!0:void 0,"aria-roledescription":v,"aria-describedby":d.draggable}),[r,f,y,m,v,d.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:R,isDragging:m,listeners:r?void 0:I,node:w,over:g,setNodeRef:C,setActivatorNodeRef:S,transform:h}}function gs(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function bs(e){return{id:e.id,begin:e.start.toFixed(3),end:e.end.toFixed(3),lines:e.lines,language:e.lang||"en"}}A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
747
+ `;function Qo(e){let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){const a=e[r];t>a&&(t=a),n<a&&(n=a)}return{min:t,max:n}}function Vn(e,t){const n=Math.pow(2,t-1),r=e<0?e*n:e*(n-1);return Math.max(-n,Math.min(n-1,r))}function Br(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function zn(e,t,n){const r=e.length,a=Math.ceil(r/t),s=Br(n,a*2);for(let o=0;o<a;o++){const l=o*t,c=Math.min((o+1)*t,r),u=e.subarray(l,c),f=Qo(u),x=Vn(f.min,n),v=Vn(f.max,n);s[o*2]=x,s[o*2+1]=v}return s}function es(e,t){const n=e.length,r=1/n,a=e[0].length/2,s=Br(t,a*2);for(let o=0;o<a;o++){let l=0,c=0;for(let u=0;u<n;u++)l+=r*e[u][o*2],c+=r*e[u][o*2+1];s[o*2]=l,s[o*2+1]=c}return[s]}function ts(e,t=1e3,n=!0,r=0,a,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=a??e.length;for(let f=0;f<c;f++){const v=e.getChannelData(f).subarray(r,u);o.push(zn(v,t,s))}}else{const c=a??e.length,u=e.subarray(r,c);o.push(zn(u,t,s))}return n&&o.length>1&&(o=es(o,s)),{length:o[0].length/2,data:o,bits:s}}function ns(e,t=1e3,n=!0,r=8,a=0,s){const o=s!==void 0?a+s:void 0;return ts(e,t,n,a,o,r)}function Ye(e,t){this._waveformData=e,this._channelIndex=t}Ye.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};Ye.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};Ye.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};Ye.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};Ye.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};Ye.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 rs=127,as=-128,os=32767,ss=-32768;function is(e,t){var n=Math.floor(e/t),r=e-n*t;return r>0&&n++,n}function ls(e){for(var t=e.scale,n=e.amplitude_scale,r=e.split_channels,a=e.length,s=e.sample_rate,o=e.channels.map(function($){return new Float32Array($)}),l=r?o.length:1,c=24,u=is(a,t),f=e.bits===8?1:2,x=c+u*2*f*l,v=new ArrayBuffer(x),d=new DataView(v),C=0,y=c,h=new Array(l),b=new Array(l),g=0;g<l;g++)h[g]=1/0,b[g]=-1/0;var m=e.bits===8?as:ss,p=e.bits===8?rs:os;d.setInt32(0,2,!0),d.setUint32(4,e.bits===8,!0),d.setInt32(8,s,!0),d.setInt32(12,t,!0),d.setInt32(16,u,!0),d.setInt32(20,l,!0);for(var I=0;I<a;I++){var k=0;if(l===1){for(var A=0;A<o.length;++A)k+=o[A][I];k=Math.floor(p*k*n/o.length),k<h[0]&&(h[0]=k,h[0]<m&&(h[0]=m)),k>b[0]&&(b[0]=k,b[0]>p&&(b[0]=p))}else for(var R=0;R<l;++R)k=Math.floor(p*o[R][I]*n),k<h[R]&&(h[R]=k,h[R]<m&&(h[R]=m)),k>b[R]&&(b[R]=k,b[R]>p&&(b[R]=p));if(++C===t){for(var D=0;D<l;D++)e.bits===8?(d.setInt8(y++,h[D]),d.setInt8(y++,b[D])):(d.setInt16(y,h[D],!0),d.setInt16(y+2,b[D],!0),y+=4),h[D]=1/0,b[D]=-1/0;C=0}}if(C>0)for(var M=0;M<l;M++)e.bits===8?(d.setInt8(y++,h[M]),d.setInt8(y++,b[M])):(d.setInt16(y,h[M],!0),d.setInt16(y+2,b[M],!0));return v}function St(e){"@babel/helpers - typeof";return St=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},St(e)}function cs(e){return e&&St(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function us(e){var t=e&&St(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),r=n.getInt32(0,!0);if(r!==1&&r!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function ds(e){var t=e.data,n=e.channels||1,r=24,a=e.bits===8?1:2,s=e.length*2*n;if(t.length!==s)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var o=r+t.length*a,l=new ArrayBuffer(o),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=r;if(e.bits===8)for(var f=0;f<t.length;f++)c.setInt8(u++,t[f],!0);else for(var x=0;x<t.length;x++)c.setInt16(u,t[x],!0),u+=2;return l}function Qe(e){return e==null}function fs(e,t){var n=atob(e);return n}function hs(e,t,n){var r=fs(e),a=r.indexOf(`
748
+ `,10)+1,s=r.substring(a)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function ms(e,t,n){var r;return function(s){return r=r||hs(e),new Worker(r,s)}}var ps=ms("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function Ae(e){if(cs(e)&&(e=ds(e)),us(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 Ye(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var lt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function gs(e){var t={scale:e.scale||lt.scale,bits:e.bits||lt.bits,amplitude_scale:e.amplitude_scale||lt.amplitude_scale,split_channels:e.split_channels||lt.split_channels,disable_worker:e.disable_worker||lt.disable_worker};return t}function bs(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Wr(e,t,n){var r=bs(e);if(t.disable_worker){var a=ls({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r});n(void 0,new Ae(a),e)}else{var s=new ps;s.onmessage=function(o){n(void 0,new Ae(o.data),e)},s.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r},r)}}function vs(e,t,n,r){function a(o){o||(o=new DOMException("EncodingError")),r(o),r=function(){}}var s=e.decodeAudioData(t,function(o){Wr(o,n,r)},a);s&&s.catch(a)}Ae.create=function(t){return new Ae(t)};Ae.createFromAudio=function(e,t){var n=gs(e);if(e.audio_context&&e.array_buffer)return vs(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Wr(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Tt(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),r=24,a=this._inputData.bits===8?1:2,s=r+n*2*this._inputData.channels*a;this._output_data=new ArrayBuffer(s),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new Ae(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}Tt.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Tt.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,r;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var a=0;a<n;++a)r=this._outputWaveformData.channel(a),r.set_min_sample(this._output_index-1,this._min[a]),r.set_max_sample(this._output_index-1,this._max[a]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var s=0;s<n;++s)this._min[s]=this._max_value,this._max[s]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var o=0;o<n;++o){r=this._inputData.channel(o);var l=r.min_sample(this._input_index);l<this._min[o]&&(this._min[o]=l),l=r.max_sample(this._input_index),l>this._max[o]&&(this._max[o]=l)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var c=0;c<n;++c)r=this._outputWaveformData.channel(c),r.set_min_sample(this._output_index-1,this._min[c]),r.set_max_sample(this._output_index-1,this._max[c]);return!0};Tt.prototype.getOutputData=function(){return this._output_data};Ae.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!Qe(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!Qe(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 Tt(t);!n.next(););return new Ae(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(a){if(t.channels!==a.channels||t.sample_rate!==a.sample_rate||t.bits!==a.bits||t.scale!==a.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var r=this._concatBuffers.apply(this,n);return Ae.create(r)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,r=n,a=0,s=[this].concat(t).map(function(b){return b._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);r+=l.byteLength-n,a+=c}for(var u=new ArrayBuffer(r),f=new DataView(s[0]),x=new DataView(u),v=0;v<n;v++)x.setUint8(v,f.getUint8(v));x.setInt32(16,a,!0);for(var d=0,C=new Uint8Array(u,n),y=0;y<s.length;y++){var h=s[y];C.set(new Uint8Array(h,n),d),d+=h.byteLength-n}return u},slice:function(t){var n=0,r=0;if(!Qe(t.startIndex)&&!Qe(t.endIndex)?(n=t.startIndex,r=t.endIndex):!Qe(t.startTime)&&!Qe(t.endTime)&&(n=this.at_time(t.startTime),r=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(r<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),r>this.length&&(r=this.length),n>r&&(n=r);var a=r-n,s=24,o=this.bits===8?1:2,l=s+a*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,a,!0),u.setInt32(20,this.channels,!0);for(var f=0;f<a*this.channels*2;f++){var x=this._at(n*this.channels*2+f);this.bits===8?u.setInt8(s+f,x):u.setInt16(s+f*2,x,!0)}return new Ae(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var r=0;r<this.channels;r++)t.data.push(this.channel(r).min_sample(n)),t.data.push(this.channel(r).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function dn(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const r=await t.arrayBuffer();return Ae.create(r)}else{const r=await t.json();return Ae.create(r)}}function Fr(e,t=0){const n=e.channel(t),r=e.bits,a=n.min_array(),s=n.max_array(),o=a.length,l=r===8?new Int8Array(o*2):new Int16Array(o*2);for(let c=0;c<o;c++)l[c*2]=a[c],l[c*2+1]=s[c];return{data:l,bits:r,length:o,sampleRate:e.sample_rate}}async function Cs(e,t=0){const n=await dn(e);return Fr(n,t)}async function ws(e){const t=await dn(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function _r(e,t,n=0,r,a){let s=e;if(r!==void 0&&a!==void 0){const v=e.scale,d=Math.floor(r/v),C=Math.ceil((r+a)/v);s=s.slice({startIndex:d,endIndex:C})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),f=c.length,x=l===8?new Int8Array(f*2):new Int16Array(f*2);for(let v=0;v<f;v++)x[v*2]=c[v],x[v*2+1]=u[v];return{data:x,bits:l,length:f}}var jn;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(jn||(jn={}));function Xn(){}const xs=Object.freeze({x:0,y:0});var tt;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(tt||(tt={}));var Hn;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Hn||(Hn={}));var Le;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Le||(Le={}));Le.Space,Le.Enter,Le.Esc,Le.Space,Le.Enter,Le.Tab;var Ln;(function(e){e[e.RightClick=2]="RightClick"})(Ln||(Ln={}));var Nn;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Nn||(Nn={}));var Gn;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Gn||(Gn={}));tt.Backward+"",tt.Forward+"",tt.Backward+"",tt.Forward+"";var qt;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(qt||(qt={}));var Qt;(function(e){e.Optimized="optimized"})(Qt||(Qt={}));function ys(e,t){return i.useMemo(()=>e.reduce((n,r)=>{let{eventName:a,handler:s}=r;return n[a]=o=>{s(o,t)},n},{}),[e,t])}qt.WhileDragging,Qt.Optimized;const ks={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Xn,draggableNodes:new Map,over:null,measureDroppableContainers:Xn},Is=i.createContext(ks),Ss=i.createContext({...xs,scaleX:1,scaleY:1});var On;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(On||(On={}));const As=i.createContext(null),Yn="button",$s="Draggable";function Kn(e){let{id:t,data:n,disabled:r=!1,attributes:a}=e;const s=mr($s),{activators:o,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:f,draggableNodes:x,over:v}=i.useContext(Is),{role:d=Yn,roleDescription:C="draggable",tabIndex:y=0}=a??{},h=c?.id===t,b=i.useContext(h?Ss:As),[g,m]=It(),[p,I]=It(),k=ys(o,t),A=hr(n);$t(()=>(x.set(t,{id:t,key:s,node:g,activatorNode:p,data:A}),()=>{const D=x.get(t);D&&D.key===s&&x.delete(t)}),[x,t]);const R=i.useMemo(()=>({role:d,tabIndex:y,"aria-disabled":r,"aria-pressed":h&&d===Yn?!0:void 0,"aria-roledescription":C,"aria-describedby":f.draggable}),[r,d,y,h,C,f.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:R,isDragging:h,listeners:r?void 0:k,node:g,over:v,setNodeRef:m,setActivatorNodeRef:I,transform:b}}function Zr(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function Ms(e){return{id:e.id,begin:e.start.toFixed(3),end:e.end.toFixed(3),lines:e.lines,language:e.lang||"en"}}S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
749
749
  position: absolute;
750
750
  top: 0;
751
751
  background: ${e=>e.$color};
@@ -761,7 +761,7 @@
761
761
  opacity: 0.5;
762
762
  border-color: ${e=>e.$color};
763
763
  }
764
- `;A.div`
764
+ `;S.div`
765
765
  position: absolute;
766
766
  bottom: 0;
767
767
  left: 0;
@@ -777,7 +777,7 @@
777
777
  pointer-events: none;
778
778
  white-space: pre-wrap;
779
779
  word-break: break-word;
780
- `;A.textarea`
780
+ `;S.textarea`
781
781
  position: absolute;
782
782
  bottom: 0;
783
783
  left: 0;
@@ -797,7 +797,7 @@
797
797
  outline: none;
798
798
  border-color: #4CAF50;
799
799
  }
800
- `;A.div`
800
+ `;S.div`
801
801
  position: absolute;
802
802
  top: 0;
803
803
  left: 0;
@@ -808,7 +808,7 @@
808
808
  padding: 4px;
809
809
  justify-content: flex-start;
810
810
  align-items: center;
811
- `;A.button`
811
+ `;S.button`
812
812
  background: transparent;
813
813
  border: 1px solid rgba(255, 255, 255, 0.5);
814
814
  color: white;
@@ -830,12 +830,12 @@
830
830
  &:active {
831
831
  background: rgba(255, 255, 255, 0.3);
832
832
  }
833
- `;var vs=A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
833
+ `;var Ds=S.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
834
834
  position: absolute;
835
835
  top: 0;
836
836
  height: 100%;
837
837
  pointer-events: none; /* Let events pass through to children */
838
- `,Cs=A.div`
838
+ `,Rs=S.div`
839
839
  position: absolute;
840
840
  top: 0;
841
841
  left: 0;
@@ -859,7 +859,7 @@
859
859
  border-width: 3px;
860
860
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
861
861
  }
862
- `,ws=A.span`
862
+ `,Es=S.span`
863
863
  font-size: 12px;
864
864
  font-weight: 600;
865
865
  color: ${e=>e.theme?.annotationLabelColor||"#2a2a2a"};
@@ -869,7 +869,7 @@
869
869
  padding: 0 6px;
870
870
  letter-spacing: 0.3px;
871
871
  user-select: none;
872
- `,Ln=A.div`
872
+ `,Un=S.div`
873
873
  position: absolute;
874
874
  top: 0;
875
875
  ${e=>e.$position==="left"?"left: -8px":"right: -8px"};
@@ -904,13 +904,13 @@
904
904
  opacity: 1;
905
905
  background: ${e=>e.theme?.annotationResizeHandleActiveColor||"rgba(0, 0, 0, 0.7)"};
906
906
  }
907
- `,xs=({annotationId:e,annotationIndex:t,startPosition:n,endPosition:r,label:a,color:s="#ff9800",isActive:o=!1,onClick:l,editable:c=!0})=>{const u=Math.max(0,r-n),d=`annotation-boundary-start-${t}`,{attributes:b,listeners:g,setActivatorNodeRef:f,isDragging:v}=Gn({id:d,data:{annotationId:e,annotationIndex:t,edge:"start"},disabled:!c}),y=`annotation-boundary-end-${t}`,{attributes:m,listeners:h,setActivatorNodeRef:w,isDragging:C}=Gn({id:y,data:{annotationId:e,annotationIndex:t,edge:"end"},disabled:!c});if(u<=0)return null;const p=I=>k=>{k.stopPropagation(),I?.(k)},S=I=>{I.stopPropagation()};return x.jsxs(vs,{$left:n,$width:u,children:[x.jsx(Cs,{$color:s,$isActive:o,onClick:l,children:a&&x.jsx(ws,{children:a})}),c&&x.jsx(Ln,{ref:f,$position:"left",$isDragging:v,onClick:S,...g,onPointerDown:p(g?.onPointerDown),...b}),c&&x.jsx(Ln,{ref:w,$position:"right",$isDragging:C,onClick:S,...h,onPointerDown:p(h?.onPointerDown),...m})]})},ys=A.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
907
+ `,Pr=({annotationId:e,annotationIndex:t,startPosition:n,endPosition:r,label:a,color:s="#ff9800",isActive:o=!1,onClick:l,editable:c=!0})=>{const u=Math.max(0,r-n),f=`annotation-boundary-start-${t}`,{attributes:x,listeners:v,setActivatorNodeRef:d,isDragging:C}=Kn({id:f,data:{annotationId:e,annotationIndex:t,edge:"start"},disabled:!c}),y=`annotation-boundary-end-${t}`,{attributes:h,listeners:b,setActivatorNodeRef:g,isDragging:m}=Kn({id:y,data:{annotationId:e,annotationIndex:t,edge:"end"},disabled:!c});if(u<=0)return null;const p=k=>A=>{A.stopPropagation(),k?.(A)},I=k=>{k.stopPropagation()};return w.jsxs(Ds,{$left:n,$width:u,children:[w.jsx(Rs,{$color:s,$isActive:o,onClick:l,children:a&&w.jsx(Es,{children:a})}),c&&w.jsx(Un,{ref:d,$position:"left",$isDragging:C,onClick:I,...v,onPointerDown:p(v?.onPointerDown),...x}),c&&w.jsx(Un,{ref:g,$position:"right",$isDragging:m,onClick:I,...b,onPointerDown:p(b?.onPointerDown),...h})]})},Ts=S.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
908
908
  position: relative;
909
909
  display: flex;
910
910
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
911
911
  background: transparent;
912
912
  z-index: 110;
913
- `,Is=A.div`
913
+ `,Bs=S.div`
914
914
  position: sticky;
915
915
  z-index: 200;
916
916
  left: 0;
@@ -918,16 +918,16 @@
918
918
  width: ${e=>e.$controlWidth}px;
919
919
  flex-shrink: 0;
920
920
  background: transparent;
921
- `,Ss=A.div`
921
+ `,Ws=S.div`
922
922
  position: relative;
923
923
  flex: 1;
924
924
  padding-left: ${e=>e.$offset||0}px;
925
- `,As=({children:e,className:t,height:n=30,offset:r=0,width:a})=>{const{controls:{show:s,width:o}}=It();return x.jsxs(ys,{className:t,$height:n,$controlWidth:s?o:0,$width:a,children:[x.jsx(Is,{$controlWidth:s?o:0}),x.jsx(Ss,{$offset:r,children:e})]})};A.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
925
+ `,Vr=({children:e,className:t,height:n=30,offset:r=0,width:a})=>{const{controls:{show:s,width:o}}=ut();return w.jsxs(Ts,{className:t,$height:n,$controlWidth:s?o:0,$width:a,children:[w.jsx(Bs,{$controlWidth:s?o:0}),w.jsx(Ws,{$offset:r,children:e})]})};S.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
926
926
  position: relative;
927
927
  display: flex;
928
928
  ${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
929
929
  background: transparent;
930
- `;A.div`
930
+ `;S.div`
931
931
  position: sticky;
932
932
  z-index: 200;
933
933
  left: 0;
@@ -941,16 +941,16 @@
941
941
  font-size: 12px;
942
942
  color: ${e=>e.theme?.textColorMuted||"#666"};
943
943
  font-weight: bold;
944
- `;A.div`
944
+ `;S.div`
945
945
  position: relative;
946
946
  flex: 1;
947
947
  padding-left: ${e=>e.$offset||0}px;
948
- `;var ks=A.div`
948
+ `;var Fs=S.div`
949
949
  background: ${e=>e.theme?.backgroundColor||"#fff"};
950
950
  ${e=>e.$height?`height: ${e.$height}px;`:"max-height: 200px;"}
951
951
  overflow-y: auto;
952
952
  padding: 8px;
953
- `,$s=A.div`
953
+ `,_s=S.div`
954
954
  padding: 12px;
955
955
  margin-bottom: 6px;
956
956
  border-left: 4px solid ${e=>e.$isActive?"#ff9800":"transparent"};
@@ -969,16 +969,16 @@
969
969
  outline: 2px solid #ff9800;
970
970
  outline-offset: 2px;
971
971
  }
972
- `,Ds=A.div`
972
+ `,Zs=S.div`
973
973
  display: flex;
974
974
  justify-content: space-between;
975
975
  align-items: center;
976
976
  margin-bottom: 6px;
977
- `,Ms=A.div`
977
+ `,Ps=S.div`
978
978
  display: flex;
979
979
  align-items: center;
980
980
  gap: 8px;
981
- `,Rs=A.span`
981
+ `,Vs=S.span`
982
982
  font-size: 11px;
983
983
  font-weight: 600;
984
984
  color: ${e=>e.theme?.textColorMuted||"#666"};
@@ -992,16 +992,16 @@
992
992
  outline: 2px solid #ff9800;
993
993
  background: rgba(255, 152, 0, 0.1);
994
994
  }
995
- `,Bs=A.span`
995
+ `,zs=S.span`
996
996
  font-size: 12px;
997
997
  font-weight: 500;
998
998
  color: ${e=>e.theme?.textColorMuted||"#555"};
999
999
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
1000
1000
  letter-spacing: 0.5px;
1001
- `,Es=A.div`
1001
+ `,js=S.div`
1002
1002
  display: flex;
1003
1003
  gap: 6px;
1004
- `,Ts=A.button`
1004
+ `,Xs=S.button`
1005
1005
  background: ${e=>e.theme?.surfaceColor||"#f5f5f5"};
1006
1006
  border: 1px solid ${e=>e.theme?.borderColor||"#ccc"};
1007
1007
  color: ${e=>e.theme?.textColor||"#333"};
@@ -1020,7 +1020,7 @@
1020
1020
  &:active {
1021
1021
  transform: scale(0.95);
1022
1022
  }
1023
- `,Ws=A.div`
1023
+ `,Hs=S.div`
1024
1024
  font-size: 14px;
1025
1025
  line-height: 1.6;
1026
1026
  color: ${e=>e.theme?.textColor||"#2a2a2a"};
@@ -1035,9 +1035,9 @@
1035
1035
  outline: 2px solid #ff9800;
1036
1036
  background: rgba(255, 152, 0, 0.1);
1037
1037
  }
1038
- `,Fs=({annotations:e,activeAnnotationId:t,shouldScrollToActive:n=!1,editable:r=!1,controls:a=[],annotationListConfig:s,height:o,onAnnotationClick:l,onAnnotationUpdate:c})=>{const u=i.useRef(null),d=i.useRef(null),b=i.useRef(void 0);i.useEffect(()=>{}),i.useEffect(()=>{const h=d.current;if(!h)return;const w=()=>{};return h.addEventListener("scroll",w),()=>h.removeEventListener("scroll",w)},[]),i.useEffect(()=>{t&&u.current&&n&&u.current.scrollIntoView({behavior:"smooth",block:"nearest"}),b.current=t},[t,n]);const g=h=>{if(isNaN(h)||!isFinite(h))return"0:00.000";const w=Math.floor(h/60),C=(h%60).toFixed(3);return`${w}:${C.padStart(6,"0")}`},f=(h,w)=>{if(!r||!c)return;const C=[...e];C[h]={...C[h],lines:w.split(`
1039
- `)},c(C)},v=(h,w)=>{if(!r||!c)return;const C=w.trim();if(!C)return;const p=[...e];p[h]={...p[h],id:C},c(p)},y=(h,w,C)=>{if(!c)return;const p=[...e];h.action(p[C],C,p,s||{}),c(p)},m=h=>h.replace(/\./g," ");return x.jsx(ks,{ref:d,$height:o,children:e.map((h,w)=>{const C=h.id===t;return x.jsxs($s,{ref:C?u:null,$isActive:C,onClick:()=>l?.(h),children:[x.jsxs(Ds,{children:[x.jsxs(Ms,{children:[x.jsx(Rs,{$isEditable:r,contentEditable:r,suppressContentEditableWarning:!0,onBlur:p=>v(w,p.currentTarget.textContent||""),children:h.id}),x.jsxs(Bs,{children:[g(h.start)," - ",g(h.end)]})]}),a.length>0&&x.jsx(Es,{onClick:p=>p.stopPropagation(),children:a.map((p,S)=>x.jsx(Ts,{title:p.title,onClick:()=>y(p,h,w),children:p.text?p.text:x.jsx("i",{className:m(p.class||"")})},S))})]}),x.jsx(Ws,{$isEditable:r,contentEditable:r,suppressContentEditableWarning:!0,onBlur:p=>f(w,p.currentTarget.textContent||""),children:h.lines.join(`
1040
- `)})]},h.id)})})},Zs=i.memo(Fs),_s=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return x.jsxs(wt,{className:r,children:[x.jsx(xt,{type:"checkbox",id:"continuous-play",className:"continuous-play",checked:e,onChange:a,disabled:n}),x.jsx(yt,{htmlFor:"continuous-play",children:"Continuous Play"})]})},Vs=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return x.jsxs(wt,{className:r,children:[x.jsx(xt,{type:"checkbox",id:"link-endpoints",className:"link-endpoints",checked:e,onChange:a,disabled:n}),x.jsx(yt,{htmlFor:"link-endpoints",children:"Link Endpoints"})]})},zs=({checked:e,onChange:t,className:n})=>x.jsxs(wt,{className:n,children:[x.jsx(xt,{type:"checkbox",id:"editable-annotations",checked:e,onChange:r=>t(r.target.checked)}),x.jsx(yt,{htmlFor:"editable-annotations",children:"Editable Annotations"})]}),Xs=A.button`
1038
+ `,Ls=({annotations:e,activeAnnotationId:t,shouldScrollToActive:n=!1,editable:r=!1,controls:a=[],annotationListConfig:s,height:o,onAnnotationClick:l,onAnnotationUpdate:c,renderAnnotationItem:u})=>{const f=i.useRef(null),x=i.useRef(null),v=i.useRef(void 0);i.useEffect(()=>{}),i.useEffect(()=>{const g=x.current;if(!g)return;const m=()=>{};return g.addEventListener("scroll",m),()=>g.removeEventListener("scroll",m)},[]),i.useEffect(()=>{t&&f.current&&n&&f.current.scrollIntoView({behavior:"smooth",block:"nearest"}),v.current=t},[t,n]);const d=g=>{if(isNaN(g)||!isFinite(g))return"0:00.000";const m=Math.floor(g/60),p=(g%60).toFixed(3);return`${m}:${p.padStart(6,"0")}`},C=(g,m)=>{if(!r||!c)return;const p=[...e];p[g]={...p[g],lines:m.split(`
1039
+ `)},c(p)},y=(g,m)=>{if(!r||!c)return;const p=m.trim();if(!p)return;const I=[...e];I[g]={...I[g],id:p},c(I)},h=(g,m,p)=>{if(!c)return;const I=[...e];g.action(I[p],p,I,s||{}),c(I)},b=g=>g.replace(/\./g," ");return w.jsx(Fs,{ref:x,$height:o,children:e.map((g,m)=>{const p=g.id===t,I=()=>l?.(g);return u?w.jsx("div",{ref:p?f:null,children:u({annotation:g,index:m,isActive:p,onClick:I,formatTime:d})},g.id):w.jsxs(_s,{ref:p?f:null,$isActive:p,onClick:I,children:[w.jsxs(Zs,{children:[w.jsxs(Ps,{children:[w.jsx(Vs,{$isEditable:r,contentEditable:r,suppressContentEditableWarning:!0,onBlur:k=>y(m,k.currentTarget.textContent||""),children:g.id}),w.jsxs(zs,{children:[d(g.start)," - ",d(g.end)]})]}),a.length>0&&w.jsx(js,{onClick:k=>k.stopPropagation(),children:a.map((k,A)=>w.jsx(Xs,{title:k.title,onClick:()=>h(k,g,m),children:k.text?k.text:w.jsx("i",{className:b(k.class||"")})},A))})]}),w.jsx(Hs,{$isEditable:r,contentEditable:r,suppressContentEditableWarning:!0,onBlur:k=>C(m,k.currentTarget.textContent||""),children:g.lines.join(`
1040
+ `)})]},g.id)})})},zr=i.memo(Ls),Ns=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return w.jsxs(Mt,{className:r,children:[w.jsx(Dt,{type:"checkbox",id:"continuous-play",className:"continuous-play",checked:e,onChange:a,disabled:n}),w.jsx(Rt,{htmlFor:"continuous-play",children:"Continuous Play"})]})},Gs=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return w.jsxs(Mt,{className:r,children:[w.jsx(Dt,{type:"checkbox",id:"link-endpoints",className:"link-endpoints",checked:e,onChange:a,disabled:n}),w.jsx(Rt,{htmlFor:"link-endpoints",children:"Link Endpoints"})]})},Os=({checked:e,onChange:t,className:n})=>w.jsxs(Mt,{className:n,children:[w.jsx(Dt,{type:"checkbox",id:"editable-annotations",checked:e,onChange:r=>t(r.target.checked)}),w.jsx(Rt,{htmlFor:"editable-annotations",children:"Editable Annotations"})]}),Ys=S.button`
1041
1041
  padding: 0.5rem 1rem;
1042
1042
  background: ${e=>e.theme?.surfaceColor||"#f5f5f5"};
1043
1043
  color: ${e=>e.theme?.textColor||"#333"};
@@ -1063,7 +1063,7 @@
1063
1063
  opacity: 0.6;
1064
1064
  cursor: not-allowed;
1065
1065
  }
1066
- `,Hs=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:r,children:a="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(b=>bs(b)),l=JSON.stringify(o,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),d=document.createElement("a");d.href=u,d.download=t,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(u)};return x.jsx(Xs,{onClick:s,disabled:n||e.length===0,className:r,title:e.length===0?"No annotations to download":"Download the annotations as JSON",children:a})};function $r(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:a=>Ue(a,e),parseTime:a=>wr(a,e)}}const js=[256,512,1024,2048,4096,8192];function Dr({initialSamplesPerPixel:e,zoomLevels:t=js}){const[n,r]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),a=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{r(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{r(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:a,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function Mr({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[r,a]=i.useState(t),s=i.useCallback(o=>{a(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:r,setMasterVolume:s}}const Ps=(e=256)=>{const t=i.useRef(null),n=i.useCallback((r,a,s)=>{const o=new E.Analyser("fft",e);return r.connect(o),r.connect(a),t.current=o,function(){o.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function Ot(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,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 g=e.durationSamples??b;return{id:Rr(),audioBuffer:t,startSample:n,durationSamples:g,offsetSamples:r,sampleRate:d,sourceDurationSamples:b,gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function Gs(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const 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 g=e.duration??b;return Ot({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(g*d),offsetSamples:Math.round(r*d),sampleRate:d,sourceDurationSamples:Math.ceil(b*d),gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Ls(e){const{name:t,clips:n=[],muted:r=!1,soloed:a=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Rr(),name:t,clips:n,muted:r,soloed:a,volume:s,pan:o,color:l,height:c}}function Rr(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Ns(e,t={}){const{progressive:n=!1}=t,[r,a]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),b=e.length;return i.useEffect(()=>{if(e.length===0){a([]),o(!1),d(0);return}let g=!1;const f=new Map,v=(m,h,w)=>{const C=w??m.audioBuffer;if(!C&&!m.waveformData)throw new Error(`Track ${h+1}: Must provide src, audioBuffer, or waveformData`);const p=C?.duration??m.waveformData?.duration,S=Gs({audioBuffer:C,startTime:m.startTime??0,duration:m.duration??p,offset:m.offset??0,name:m.name||`Track ${h+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${h+1}`);return{...Ls({name:m.name||`Track ${h+1}`,clips:[S],muted:m.muted??!1,soloed:m.soloed??!1,volume:m.volume??1,pan:m.pan??0,color:m.color}),effects:m.effects}};return(async()=>{try{o(!0),c(null),d(0);const m=sr.getContext().rawContext,h=e.map(async(C,p)=>{if(C.audioBuffer){const M=v(C,p,C.audioBuffer);return n&&!g&&(f.set(p,M),d(D=>D+1),a(Array.from({length:e.length},(D,$)=>f.get($)).filter(D=>D!==void 0))),M}if(!C.src&&C.waveformData){const M=v(C,p);return n&&!g&&(f.set(p,M),d(D=>D+1),a(Array.from({length:e.length},(D,$)=>f.get($)).filter(D=>D!==void 0))),M}if(!C.src)throw new Error(`Track ${p+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(C.src);if(!S.ok)throw new Error(`Failed to fetch ${C.src}: ${S.statusText}`);const I=await S.arrayBuffer(),k=await m.decodeAudioData(I);if(!k||!k.sampleRate||!k.duration)throw new Error(`Invalid audio buffer for ${C.src}`);const R=v(C,p,k);return n&&!g&&(f.set(p,R),d(M=>M+1),a(Array.from({length:e.length},(M,D)=>f.get(D)).filter(M=>M!==void 0))),R}),w=await Promise.all(h);g||(n||(a(w),d(w.length)),o(!1))}catch(m){if(!g){const h=m instanceof Error?m.message:"Unknown error loading audio";c(h),o(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{g=!0}},[e,n]),{tracks:r,loading:s,error:l,loadedCount:u,totalCount:b}}function Ys({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:r}){const a=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:g,clipIndex:f,boundary:v}=b.data.current;if(v)return{...d,scaleX:1,scaleY:1};const y=e[g];if(!y)return{...d,scaleX:1,scaleY:1};const m=y.clips[f];if(!m)return{...d,scaleX:1,scaleY:1};const h=m.startSample/r,w=m.durationSamples/r,C=d.x*n/r;let p=h+C;const S=[...y.clips].sort(($,T)=>$.startSample-T.startSample),I=S.findIndex($=>$===m);p=Math.max(0,p);const k=I>0?S[I-1]:null;if(k){const $=(k.startSample+k.durationSamples)/r;p=Math.max(p,$)}const R=I<S.length-1?S[I+1]:null;if(R){const $=p+w,T=R.startSample/r;$>T&&(p=T-w)}const D=(p-h)*r/n;return{...d,x:D,scaleX:1,scaleY:1}},[e,n,r]),o=i.useCallback(u=>{const{active:d}=u,{boundary:b}=d.data.current;if(!b){a.current=null;return}const{trackIndex:g,clipIndex:f}=d.data.current,y=e[g]?.clips[f];y&&(a.current={offsetSamples:y.offsetSamples,durationSamples:y.durationSamples,startSample:y.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:b}=u,{boundary:g}=d.data.current;if(!g||!a.current)return;const{trackIndex:f,clipIndex:v}=d.data.current,y=b.x*n,m=Math.floor(.1*r),h=a.current,w=e.map((C,p)=>{if(p!==f)return C;const S=[...C.clips].sort((R,M)=>R.startSample-M.startSample),I=S.findIndex(R=>R===C.clips[v]),k=C.clips.map((R,M)=>{if(M!==v)return R;const D=R.sourceDurationSamples;if(g==="left"){let $=Math.floor(y);const T=-h.startSample;$<T&&($=T);const W=-h.offsetSamples;$<W&&($=W);const H=I>0?S[I-1]:null;if(H){const K=H.startSample+H.durationSamples-h.startSample;$<K&&($=K)}const P=h.durationSamples-m;$>P&&($=P);const j=h.offsetSamples+$,N=h.durationSamples-$,Y=h.startSample+$;return{...R,offsetSamples:j,durationSamples:N,startSample:Y}}else{let $=Math.floor(h.durationSamples+y);$=Math.max(m,$),h.offsetSamples+$>D&&($=D-h.offsetSamples);const T=I<S.length-1?S[I+1]:null;return T&&h.startSample+$>T.startSample&&($=T.startSample-h.startSample,$=Math.max(m,$)),{...R,durationSamples:$}}});return{...C,clips:k}});t(w)},[e,t,n,r]),c=i.useCallback(u=>{const{active:d,delta:b}=u,{trackIndex:g,clipIndex:f,boundary:v}=d.data.current,y=b.x*n;if(v){a.current=null;return}const m=e.map((h,w)=>{if(w!==g)return h;const C=[...h.clips].sort((I,k)=>I.startSample-k.startSample),p=C.findIndex(I=>I===h.clips[f]),S=h.clips.map((I,k)=>{if(k!==f)return I;let R=Math.floor(I.startSample+y);R=Math.max(0,R);const M=p>0?C[p-1]:null;if(M){const $=M.startSample+M.durationSamples;R=Math.max(R,$)}const D=p<C.length-1?C[p+1]:null;return D&&R+I.durationSamples>D.startSample&&(R=D.startSample-I.durationSamples),{...I,startSample:R}});return{...h,clips:S}});t(m)},[e,t,n,r]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const _t=.01;function Os({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:r,duration:a,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:b}=d,g=b.data.current;if(!g||g.annotationIndex===void 0){o.current=null;return}const f=e[g.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:g.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:b,delta:g}=d;if(!o.current)return;const f=b.data.current;if(!f)return;const{edge:v,annotationIndex:y}=f,m=o.current,h=g.x*n/r,w=v==="start"?m.start+h:m.end+h,C=Ks({annotationIndex:y,newTime:w,isDraggingStart:v==="start",annotations:e,duration:a,linkEndpoints:s});t(C)},[e,t,n,r,a,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Ks({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:r,duration:a,linkEndpoints:s}){const o=[...r],l=r[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<_t?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,a)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<_t){const b=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,b)};let g=e+1;for(;g<o.length-1;){const f=o[g],v=o[g+1];if(Math.abs(v.start-f.end)<_t){const y=f.end-r[g].end;o[g+1]={...v,start:Math.min(v.end-.1,v.start+y)},g++}else break}}else c>=d.start&&(o[e]={...o[e],end:d.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const d=o[e+1];o[e+1]={...d,start:c};let b=e+1;for(;b<o.length-1;){const g=o[b],f=o[b+1];if(g.end>f.start)o[b+1]={...f,start:g.end},b++;else break}}}return o}function on(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Br(e){return"nodeType"in e}function Je(e){var t,n;return e?on(e)?e:Br(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Us(e){const{Document:t}=Je(e);return e instanceof t}function Js(e){return on(e)?!1:e instanceof Je(e).HTMLElement}function qs(e){return e instanceof Je(e).SVGElement}function At(e){return e?on(e)?e.document:Br(e)?Us(e)?e:Js(e)||qs(e)?e.ownerDocument:document:document:document}function Qs(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return r.reduce((s,o)=>{const l=Object.entries(o);for(const[c,u]of l){const d=s[c];d!=null&&(s[c]=d+e*u)}return s},{...t})}}const ei=Qs(-1);function ti(e){return"clientX"in e&&"clientY"in e}function ni(e){if(!e)return!1;const{TouchEvent:t}=Je(e.target);return t&&e instanceof t}function Nn(e){if(ni(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return ti(e)?{x:e.clientX,y:e.clientY}:null}var Yn;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Yn||(Yn={}));function Vt(e,t){return i.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function ri(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return i.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const Kt=Object.freeze({x:0,y:0});var Ke;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Ke||(Ke={}));class zt{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=t}add(t,n,r){var a;(a=this.target)==null||a.addEventListener(t,n,r),this.listeners.push([t,n,r])}}function ai(e){const{EventTarget:t}=Je(e);return e instanceof t?e:At(e)}function Xt(e,t){const n=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+r**2)>t:"x"in t&&"y"in t?n>t.x&&r>t.y:"x"in t?n>t.x:"y"in t?r>t.y:!1}var Te;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Te||(Te={}));function On(e){e.preventDefault()}function oi(e){e.stopPropagation()}var We;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(We||(We={}));We.Space,We.Enter,We.Esc,We.Space,We.Enter,We.Tab;function Kn(e){return!!(e&&"distance"in e)}function Un(e){return!!(e&&"delay"in e)}class sn{constructor(t,n,r){var a;r===void 0&&(r=ai(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:s}=t,{target:o}=s;this.props=t,this.events=n,this.document=At(o),this.documentListeners=new zt(this.document),this.listeners=new zt(r),this.windowListeners=new zt(Je(o)),this.initialCoordinates=(a=Nn(s))!=null?a:Kt,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(Te.Resize,this.handleCancel),this.windowListeners.add(Te.DragStart,On),this.windowListeners.add(Te.VisibilityChange,this.handleCancel),this.windowListeners.add(Te.ContextMenu,On),this.documentListeners.add(Te.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(Un(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(Kn(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:r,onPending:a}=this.props;a(r,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(Te.Click,oi,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Te.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:r,initialCoordinates:a,props:s}=this,{onMove:o,options:{activationConstraint:l}}=s;if(!a)return;const c=(n=Nn(t))!=null?n:Kt,u=ei(a,c);if(!r&&l){if(Kn(l)){if(l.tolerance!=null&&Xt(u,l.tolerance))return this.handleCancel();if(Xt(u,l.distance))return this.handleStart()}if(Un(l)&&Xt(u,l.tolerance))return this.handleCancel();this.handlePending(l,u);return}t.cancelable&&t.preventDefault(),o(c)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===We.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const si={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Er extends sn{constructor(t){const{event:n}=t,r=At(n.target);super(t,si,r)}}Er.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];const ii={move:{name:"mousemove"},end:{name:"mouseup"}};var Ut;(function(e){e[e.RightClick=2]="RightClick"})(Ut||(Ut={}));class Tr extends sn{constructor(t){super(t,ii,At(t.event.target))}}Tr.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===Ut.RightClick?!1:(r?.({event:n}),!0)}}];const Ht={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Wr extends sn{constructor(t){super(t,Ht)}static setup(){return window.addEventListener(Ht.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Ht.move.name,t)};function t(){}}}Wr.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;const{touches:a}=n;return a.length>1?!1:(r?.({event:n}),!0)}}];var Jn;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Jn||(Jn={}));var qn;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(qn||(qn={}));Ke.Backward+"",Ke.Forward+"",Ke.Backward+"",Ke.Forward+"";var Jt;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Jt||(Jt={}));var qt;(function(e){e.Optimized="optimized"})(qt||(qt={}));Jt.WhileDragging,qt.Optimized;({...Kt});var Qn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Qn||(Qn={}));function li(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:r=5,mouseDistance:a=1}=e,s=Vt(Tr,{activationConstraint:{distance:a}}),o=Vt(Wr,{activationConstraint:t?{delay:n,tolerance:r}:{distance:a}}),l=Vt(Er,{activationConstraint:{distance:a}});return ri(...t?[s,o]:[l])}const ci=e=>{const{tracks:t,onTracksChange:n,sampleRate:r}=e,{currentTimeRef:a}=ge(),{selectedTrackId:s}=Ie(),o=i.useCallback((c,u,d)=>{const{sampleRate:b,samplesPerPixel:g}=e,f=t[c];if(!f)return!1;const v=f.clips[u];if(!v)return!1;const y=v.startSample/b,m=(v.startSample+v.durationSamples)/b;if(d<=y||d>=m)return console.warn("Split time is outside clip bounds"),!1;const h=Math.round(d*b),w=Math.floor(h/g),C=v.startSample+v.durationSamples,p=w*g,S=v.startSample,I=p-S,k=p,R=C-k,M=p-v.startSample,D=Ot({audioBuffer:v.audioBuffer,startSample:S,durationSamples:I,offsetSamples:v.offsetSamples,sampleRate:v.sampleRate,sourceDurationSamples:v.sourceDurationSamples,gain:v.gain,name:v.name?`${v.name} (1)`:void 0,color:v.color,fadeIn:v.fadeIn,waveformData:v.waveformData}),$=Ot({audioBuffer:v.audioBuffer,startSample:k,durationSamples:R,offsetSamples:v.offsetSamples+M,sampleRate:v.sampleRate,sourceDurationSamples:v.sourceDurationSamples,gain:v.gain,name:v.name?`${v.name} (2)`:void 0,color:v.color,waveformData:v.waveformData,fadeOut:v.fadeOut}),T=[...f.clips];T.splice(u,1,D,$);const W=[...t];return W[c]={...f,clips:T},n(W),!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=a.current??0;for(let b=0;b<u.clips.length;b++){const g=u.clips[b],f=g.startSample/r,v=(g.startSample+g.durationSamples)/r;if(d>f&&d<v)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,a,s,o,r]),splitClipAt:o}},vt=e=>{const{shortcuts:t,enabled:n=!0}=e,r=i.useCallback(a=>{if(!n)return;const s=a.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=a.key.toLowerCase()===l.key.toLowerCase()||a.key===l.key,u=l.ctrlKey===void 0||a.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||a.shiftKey===l.shiftKey,b=l.metaKey===void 0||a.metaKey===l.metaKey,g=l.altKey===void 0||a.altKey===l.altKey;return c&&u&&d&&b&&g});o&&(o.preventDefault!==!1&&a.preventDefault(),o.action())},[t,n]);i.useEffect(()=>{if(n)return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}},[r,n])},ui=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("+")},di=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:r}=e,{isPlaying:a}=ge(),{setCurrentTime:s,play:o,pause:l,stop:c}=oe(),{playoutRef:u}=me(),d=i.useCallback(()=>{a?l():o()},[a,o,l]),b=i.useCallback(()=>{c()},[c]),g=i.useCallback(()=>{a&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[a,u,s,o]),v=r??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:b,description:"Stop",preventDefault:!0},{key:"0",action:g,description:"Rewind to start",preventDefault:!0}],...n];return vt({shortcuts:v,enabled:t}),{rewindToStart:g,togglePlayPause:d,stopPlayback:b,shortcuts:v}},jt=.01,ft=.01;function fi({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:r,duration:a,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:b=0,onPlay:g}){const f=i.useMemo(()=>t?e.findIndex(M=>M.id===t):-1,[e,t]),v=i.useCallback(M=>{if(!c?.current||!u||!d)return;const D=e.find(z=>z.id===M);if(!D)return;const $=c.current,T=$.clientWidth,W=D.start*d/u+b,H=D.end*d/u+b,P=(W+H)/2,j=$.scrollLeft,N=j,Y=j+T;if(W<N||H>Y){const z=Math.max(0,P-T/2);$.scrollTo({left:z,behavior:"smooth"})}},[e,c,u,d,b]);i.useEffect(()=>{t&&c?.current&&u&&d&&v(t)},[t,v,c,u,d]);const y=i.useCallback(M=>{if(f<0)return;const D=e[f],$=Math.max(0,Math.min(D.end-.1,D.start+M)),T=$-D.start,W=[...e];if(W[f]={...D,start:$},s&&f>0){const H=W[f-1];Math.abs(H.end-D.start)<jt&&(W[f-1]={...H,end:Math.max(H.start+.1,H.end+T)})}else if(!s&&f>0){const H=W[f-1];$<H.end&&(W[f-1]={...H,end:$})}n(W)},[e,f,s,n]),m=i.useCallback(M=>{if(f<0)return;const D=e[f],$=Math.max(D.start+.1,Math.min(a,D.end+M)),T=$-D.end,W=[...e];if(W[f]={...D,end:$},s&&f<e.length-1){const H=W[f+1];if(Math.abs(H.start-D.end)<jt){const P=Math.min(H.end-.1,H.start+T);W[f+1]={...H,start:P};let j=f+1;for(;j<W.length-1;){const N=W[j],Y=W[j+1];if(Math.abs(Y.start-e[j].end)<jt){const z=N.end-e[j].end;W[j+1]={...Y,start:Math.min(Y.end-.1,Y.start+z)},j++}else break}}}else if(!s&&f<e.length-1){const H=W[f+1];if($>H.start){W[f+1]={...H,start:$};let P=f+1;for(;P<W.length-1;){const j=W[P],N=W[P+1];if(j.end>N.start)W[P+1]={...N,start:j.end},P++;else break}}}n(W)},[e,f,a,s,n]),h=i.useCallback(()=>{!r||e.length===0||(f<=0?r(e[e.length-1].id):r(e[f-1].id))},[e,f,r]),w=i.useCallback(()=>{!r||e.length===0||(f<0||f>=e.length-1?r(e[0].id):r(e[f+1].id))},[e,f,r]),C=i.useCallback(()=>{!r||e.length===0||r(e[0].id)},[e,r]),p=i.useCallback(()=>{!r||e.length===0||r(e[e.length-1].id)},[e,r]),S=i.useCallback(()=>{r&&r(null)},[r]),I=i.useCallback(()=>{if(f<0||!g)return;const M=e[f],D=o?void 0:M.end-M.start;g(M.start,D)},[e,f,o,g]),k=i.useMemo(()=>[{key:"[",action:()=>y(-ft),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>y(ft),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>m(-ft),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>m(ft),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:I,description:"Play selected annotation",preventDefault:!0}],[y,m,I]),R=i.useMemo(()=>[{key:"ArrowUp",action:h,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:h,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:p,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:S,description:"Deselect annotation",preventDefault:!0}],[h,w,C,p,S]);return vt({shortcuts:k,enabled:l&&f>=0}),vt({shortcuts:R,enabled:l&&e.length>0&&!!r}),{moveStartBoundary:y,moveEndBoundary:m,selectPrevious:h,selectNext:w,selectFirst:C,selectLast:p,clearSelection:S,scrollToAnnotation:v,playActiveAnnotation:I}}function hi(e){const t=e.reduce((a,s)=>a+s.length,0),n=new Float32Array(t);let r=0;for(const a of e)n.set(a,r),r+=a.length;return n}function mi(e,t,n,r=1){const a=e.createBuffer(r,t.length,n),s=new Float32Array(t);return a.copyToChannel(s,0),a}function er(e,t,n=16){const r=Math.ceil(e.length/t),a=n===8?new Int8Array(r*2):new Int16Array(r*2),s=2**(n-1);for(let o=0;o<r;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,d=0;for(let b=l;b<c;b++){const g=e[b];g<u&&(u=g),g>d&&(d=g)}a[o*2]=Math.floor(u*s),a[o*2+1]=Math.floor(d*s)}return a}function pi(e,t,n,r,a=16){const s=2**(a-1),o=r%n;let l=0;if(o>0&&e.length>0){const d=n-o,b=Math.min(d,t.length);let g=e[e.length-2]/s,f=e[e.length-1]/s;for(let h=0;h<b;h++){const w=t[h];w<g&&(g=w),w>f&&(f=w)}const v=new(a===8?Int8Array:Int16Array)(e.length);v.set(e),v[e.length-2]=Math.floor(g*s),v[e.length-1]=Math.floor(f*s),l=b;const y=er(t.slice(l),n,a),m=new(a===8?Int8Array:Int16Array)(v.length+y.length);return m.set(v),m.set(y,v.length),m}const c=er(t.slice(l),n,a),u=new(a===8?Int8Array:Int16Array)(e.length+c.length);return u.set(e),u.set(c,e.length),u}function gi(e,t={}){const{channelCount:n=1,samplesPerPixel:r=1024}=t,[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[d,b]=i.useState(new Int16Array(0)),[g,f]=i.useState(null),[v,y]=i.useState(null),[m,h]=i.useState(0),[w,C]=i.useState(0),p=16,S=i.useRef(!1),I=i.useRef(null),k=i.useRef(null),R=i.useRef([]),M=i.useRef(0),D=i.useRef(null),$=i.useRef(0),T=i.useRef(!1),W=i.useRef(!1),H=i.useCallback(async()=>{if(!S.current)try{const z=E.getContext(),K=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Tt&&Tt.tagName.toUpperCase()==="SCRIPT"&&Tt.src||new URL("index.js",document.baseURI).href).href;await z.addAudioWorkletModule(K),S.current=!0}catch(z){throw console.error("Failed to load AudioWorklet module:",z),new Error("Failed to load recording processor")}},[]),P=i.useCallback(async()=>{if(!e){y(new Error("No microphone stream available"));return}try{y(null);const z=E.getContext();z.state==="suspended"&&await z.resume(),await H();const K=z.createMediaStreamSource(e);k.current=K;const ne=z.createAudioWorkletNode("recording-processor");I.current=ne,K.connect(ne),ne.port.onmessage=U=>{const{samples:J}=U.data;R.current.push(J),M.current+=J.length,b(fe=>pi(fe,J,r,M.current-J.length,p))},ne.port.postMessage({command:"start",sampleRate:z.sampleRate,channelCount:n}),R.current=[],M.current=0,b(new Int16Array(0)),f(null),h(0),C(0),T.current=!0,W.current=!1,s(!0),l(!1),$.current=performance.now();const te=()=>{if(T.current&&!W.current){const U=(performance.now()-$.current)/1e3;u(U),D.current=requestAnimationFrame(te)}};te()}catch(z){console.error("Failed to start recording:",z),y(z instanceof Error?z:new Error("Failed to start recording"))}},[e,n,r,H,a,o]),j=i.useCallback(async()=>{if(!a)return null;try{if(I.current){if(I.current.port.postMessage({command:"stop"}),k.current)try{k.current.disconnect(I.current)}catch{}I.current.disconnect()}D.current!==null&&(cancelAnimationFrame(D.current),D.current=null);const z=hi(R.current),ne=E.getContext().rawContext,te=mi(ne,z,ne.sampleRate,n);return f(te),u(te.duration),T.current=!1,W.current=!1,s(!1),l(!1),h(0),te}catch(z){return console.error("Failed to stop recording:",z),y(z instanceof Error?z:new Error("Failed to stop recording")),null}},[a,n]),N=i.useCallback(()=>{a&&!o&&(D.current!==null&&(cancelAnimationFrame(D.current),D.current=null),W.current=!0,l(!0))},[a,o]),Y=i.useCallback(()=>{if(a&&o){W.current=!1,l(!1),$.current=performance.now()-c*1e3;const z=()=>{if(T.current&&!W.current){const K=(performance.now()-$.current)/1e3;u(K),D.current=requestAnimationFrame(z)}};z()}},[a,o,c]);return i.useEffect(()=>()=>{if(I.current){if(I.current.port.postMessage({command:"stop"}),k.current)try{k.current.disconnect(I.current)}catch{}I.current.disconnect()}D.current!==null&&cancelAnimationFrame(D.current)},[]),{isRecording:a,isPaused:o,duration:c,peaks:d,audioBuffer:g,level:m,peakLevel:w,startRecording:P,stopRecording:j,pauseRecording:N,resumeRecording:Y,error:v}}function bi(){const[e,t]=i.useState(null),[n,r]=i.useState([]),[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),d=i.useCallback(async()=>{try{const v=(await navigator.mediaDevices.enumerateDevices()).filter(y=>y.kind==="audioinput").map(y=>({deviceId:y.deviceId,label:y.label||`Microphone ${y.deviceId.slice(0,8)}`,groupId:y.groupId}));r(v)}catch(f){console.error("Failed to enumerate devices:",f),u(f instanceof Error?f:new Error("Failed to enumerate devices"))}},[]),b=i.useCallback(async(f,v)=>{l(!0),u(null);try{e&&e.getTracks().forEach(w=>w.stop());const m={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...v,...f&&{deviceId:{exact:f}}},video:!1},h=await navigator.mediaDevices.getUserMedia(m);t(h),s(!0),await d()}catch(y){console.error("Failed to access microphone:",y),u(y instanceof Error?y:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,d]),g=i.useCallback(()=>{e&&(e.getTracks().forEach(f=>f.stop()),t(null),s(!1))},[e]);return i.useEffect(()=>(d(),()=>{e&&e.getTracks().forEach(f=>f.stop())}),[]),{stream:e,devices:n,hasPermission:a,isLoading:o,requestAccess:b,stopStream:g,error:c}}function vi(e,t={}){const{updateRate:n=60,smoothingTimeConstant:r=.8}=t,[a,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),d=i.useRef(null),b=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let g=!0;return(async()=>{if(!g)return;const v=E.getContext();if(v.state==="suspended"&&await v.resume(),!g)return;const y=new E.Meter({smoothing:r,context:v});c.current=y;const m=v.createMediaStreamSource(e);u.current=m,E.connect(m,y);const h=1e3/n;let w=0;const C=p=>{if(!(!g||!c.current)){if(p-w>=h){w=p;const S=c.current.getValue(),I=typeof S=="number"?S:S[0],k=Math.max(0,Math.min(1,(I+100)/100));s(k),l(R=>Math.max(R,k))}d.current=requestAnimationFrame(C)}};d.current=requestAnimationFrame(C)})(),()=>{if(g=!1,d.current&&(cancelAnimationFrame(d.current),d.current=null),u.current){try{u.current.disconnect()}catch{}u.current=null}c.current&&(c.current.dispose(),c.current=null)}},[e,r,n]),{level:a,peakLevel:o,resetPeak:b}}A.button`
1066
+ `,Ks=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:r,children:a="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(x=>Ms(x)),l=JSON.stringify(o,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),f=document.createElement("a");f.href=u,f.download=t,document.body.appendChild(f),f.click(),document.body.removeChild(f),URL.revokeObjectURL(u)};return w.jsx(Ys,{onClick:s,disabled:n||e.length===0,className:r,title:e.length===0?"No annotations to download":"Download the annotations as JSON",children:a})};function jr(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:a=>rt(a,e),parseTime:a=>Ar(a,e)}}const Us=[256,512,1024,2048,4096,8192];function Xr({initialSamplesPerPixel:e,zoomLevels:t=Us}){const[n,r]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),a=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{r(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{r(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:a,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function Hr({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[r,a]=i.useState(t),s=i.useCallback(o=>{a(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:r,setMasterVolume:s}}const Js=(e=256)=>{const t=i.useRef(null),n=i.useCallback((r,a,s)=>{const o=new W.Analyser("fft",e);return r.connect(o),r.connect(a),t.current=o,function(){o.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function en(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,f=t?.sampleRate??e.sampleRate??u?.sample_rate,x=t?.length??e.sourceDurationSamples??(u&&f?Math.ceil(u.duration*f):void 0);if(f===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(x===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const v=e.durationSamples??x;return{id:Lr(),audioBuffer:t,startSample:n,durationSamples:v,offsetSamples:r,sampleRate:f,sourceDurationSamples:x,gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function qs(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,f=t?.sampleRate??e.sampleRate??u?.sample_rate;if(f===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const x=t?.duration??e.sourceDuration??u?.duration;if(x===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const v=e.duration??x;return en({audioBuffer:t,startSample:Math.round(n*f),durationSamples:Math.round(v*f),offsetSamples:Math.round(r*f),sampleRate:f,sourceDurationSamples:Math.ceil(x*f),gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Qs(e){const{name:t,clips:n=[],muted:r=!1,soloed:a=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Lr(),name:t,clips:n,muted:r,soloed:a,volume:s,pan:o,color:l,height:c}}function Lr(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function ei(e,t={}){const{progressive:n=!1}=t,[r,a]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,f]=i.useState(0),x=e.length;return i.useEffect(()=>{if(e.length===0){a([]),o(!1),f(0);return}let v=!1;const d=new Map,C=(h,b,g)=>{const m=g??h.audioBuffer;if(!m&&!h.waveformData)throw new Error(`Track ${b+1}: Must provide src, audioBuffer, or waveformData`);const p=m?.duration??h.waveformData?.duration,I=qs({audioBuffer:m,startTime:h.startTime??0,duration:h.duration??p,offset:h.offset??0,name:h.name||`Track ${b+1}`,fadeIn:h.fadeIn,fadeOut:h.fadeOut,waveformData:h.waveformData});if(isNaN(I.startSample)||isNaN(I.durationSamples)||isNaN(I.offsetSamples))throw console.error("Invalid clip values:",I),new Error(`Invalid clip values for track ${b+1}`);return{...Qs({name:h.name||`Track ${b+1}`,clips:[I],muted:h.muted??!1,soloed:h.soloed??!1,volume:h.volume??1,pan:h.pan??0,color:h.color}),effects:h.effects}};return(async()=>{try{o(!0),c(null),f(0);const h=dr.getContext().rawContext,b=e.map(async(m,p)=>{if(m.audioBuffer){const D=C(m,p,m.audioBuffer);return n&&!v&&(d.set(p,D),f(M=>M+1),a(Array.from({length:e.length},(M,$)=>d.get($)).filter(M=>M!==void 0))),D}if(!m.src&&m.waveformData){const D=C(m,p);return n&&!v&&(d.set(p,D),f(M=>M+1),a(Array.from({length:e.length},(M,$)=>d.get($)).filter(M=>M!==void 0))),D}if(!m.src)throw new Error(`Track ${p+1}: Must provide src, audioBuffer, or waveformData`);const I=await fetch(m.src);if(!I.ok)throw new Error(`Failed to fetch ${m.src}: ${I.statusText}`);const k=await I.arrayBuffer(),A=await h.decodeAudioData(k);if(!A||!A.sampleRate||!A.duration)throw new Error(`Invalid audio buffer for ${m.src}`);const R=C(m,p,A);return n&&!v&&(d.set(p,R),f(D=>D+1),a(Array.from({length:e.length},(D,M)=>d.get(M)).filter(D=>D!==void 0))),R}),g=await Promise.all(b);v||(n||(a(g),f(g.length)),o(!1))}catch(h){if(!v){const b=h instanceof Error?h.message:"Unknown error loading audio";c(b),o(!1),console.error("Error loading audio tracks:",h)}}})(),()=>{v=!0}},[e,n]),{tracks:r,loading:s,error:l,loadedCount:u,totalCount:x}}function ti({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:r}){const a=i.useRef(null),s=i.useCallback(u=>{const{transform:f,active:x}=u;if(!x?.data?.current)return{...f,scaleX:1,scaleY:1};const{trackIndex:v,clipIndex:d,boundary:C}=x.data.current;if(C)return{...f,scaleX:1,scaleY:1};const y=e[v];if(!y)return{...f,scaleX:1,scaleY:1};const h=y.clips[d];if(!h)return{...f,scaleX:1,scaleY:1};const b=h.startSample/r,g=h.durationSamples/r,m=f.x*n/r;let p=b+m;const I=[...y.clips].sort(($,E)=>$.startSample-E.startSample),k=I.findIndex($=>$===h);p=Math.max(0,p);const A=k>0?I[k-1]:null;if(A){const $=(A.startSample+A.durationSamples)/r;p=Math.max(p,$)}const R=k<I.length-1?I[k+1]:null;if(R){const $=p+g,E=R.startSample/r;$>E&&(p=E-g)}const M=(p-b)*r/n;return{...f,x:M,scaleX:1,scaleY:1}},[e,n,r]),o=i.useCallback(u=>{const{active:f}=u,{boundary:x}=f.data.current;if(!x){a.current=null;return}const{trackIndex:v,clipIndex:d}=f.data.current,y=e[v]?.clips[d];y&&(a.current={offsetSamples:y.offsetSamples,durationSamples:y.durationSamples,startSample:y.startSample})},[e]),l=i.useCallback(u=>{const{active:f,delta:x}=u,{boundary:v}=f.data.current;if(!v||!a.current)return;const{trackIndex:d,clipIndex:C}=f.data.current,y=x.x*n,h=Math.floor(.1*r),b=a.current,g=e.map((m,p)=>{if(p!==d)return m;const I=[...m.clips].sort((R,D)=>R.startSample-D.startSample),k=I.findIndex(R=>R===m.clips[C]),A=m.clips.map((R,D)=>{if(D!==C)return R;const M=R.sourceDurationSamples;if(v==="left"){let $=Math.floor(y);const E=-b.startSample;$<E&&($=E);const Z=-b.offsetSamples;$<Z&&($=Z);const P=k>0?I[k-1]:null;if(P){const B=P.startSample+P.durationSamples-b.startSample;$<B&&($=B)}const F=b.durationSamples-h;$>F&&($=F);const V=b.offsetSamples+$,H=b.durationSamples-$,q=b.startSample+$;return{...R,offsetSamples:V,durationSamples:H,startSample:q}}else{let $=Math.floor(b.durationSamples+y);$=Math.max(h,$),b.offsetSamples+$>M&&($=M-b.offsetSamples);const E=k<I.length-1?I[k+1]:null;return E&&b.startSample+$>E.startSample&&($=E.startSample-b.startSample,$=Math.max(h,$)),{...R,durationSamples:$}}});return{...m,clips:A}});t(g)},[e,t,n,r]),c=i.useCallback(u=>{const{active:f,delta:x}=u,{trackIndex:v,clipIndex:d,boundary:C}=f.data.current,y=x.x*n;if(C){a.current=null;return}const h=e.map((b,g)=>{if(g!==v)return b;const m=[...b.clips].sort((k,A)=>k.startSample-A.startSample),p=m.findIndex(k=>k===b.clips[d]),I=b.clips.map((k,A)=>{if(A!==d)return k;let R=Math.floor(k.startSample+y);R=Math.max(0,R);const D=p>0?m[p-1]:null;if(D){const $=D.startSample+D.durationSamples;R=Math.max(R,$)}const M=p<m.length-1?m[p+1]:null;return M&&R+k.durationSamples>M.startSample&&(R=M.startSample-k.durationSamples),{...k,startSample:R}});return{...b,clips:I}});t(h)},[e,t,n,r]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Xt=.01;function ni({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:r,duration:a,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(f=>{const{active:x}=f,v=x.data.current;if(!v||v.annotationIndex===void 0){o.current=null;return}const d=e[v.annotationIndex];d&&(o.current={start:d.start,end:d.end,annotationIndex:v.annotationIndex})},[e]),c=i.useCallback(f=>{const{active:x,delta:v}=f;if(!o.current)return;const d=x.data.current;if(!d)return;const{edge:C,annotationIndex:y}=d,h=o.current,b=v.x*n/r,g=C==="start"?h.start+b:h.end+b,m=ri({annotationIndex:y,newTime:g,isDraggingStart:C==="start",annotations:e,duration:a,linkEndpoints:s});t(m)},[e,t,n,r,a,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function ri({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:r,duration:a,linkEndpoints:s}){const o=[...r],l=r[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const f=o[e-1];Math.abs(f.end-l.start)<Xt?o[e-1]={...f,end:Math.max(f.start+.1,f.end+u)}:c<=f.end&&(o[e]={...o[e],start:f.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,a)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const f=o[e+1];if(Math.abs(f.start-l.end)<Xt){const x=f.start+u;o[e+1]={...f,start:Math.min(f.end-.1,x)};let v=e+1;for(;v<o.length-1;){const d=o[v],C=o[v+1];if(Math.abs(C.start-d.end)<Xt){const y=d.end-r[v].end;o[v+1]={...C,start:Math.min(C.end-.1,C.start+y)},v++}else break}}else c>=f.start&&(o[e]={...o[e],end:f.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const f=o[e+1];o[e+1]={...f,start:c};let x=e+1;for(;x<o.length-1;){const v=o[x],d=o[x+1];if(v.end>d.start)o[x+1]={...d,start:v.end},x++;else break}}}return o}function fn(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Nr(e){return"nodeType"in e}function at(e){var t,n;return e?fn(e)?e:Nr(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function ai(e){const{Document:t}=at(e);return e instanceof t}function oi(e){return fn(e)?!1:e instanceof at(e).HTMLElement}function si(e){return e instanceof at(e).SVGElement}function Bt(e){return e?fn(e)?e.document:Nr(e)?ai(e)?e:oi(e)||si(e)?e.ownerDocument:document:document:document}function ii(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),a=1;a<n;a++)r[a-1]=arguments[a];return r.reduce((s,o)=>{const l=Object.entries(o);for(const[c,u]of l){const f=s[c];f!=null&&(s[c]=f+e*u)}return s},{...t})}}const li=ii(-1);function ci(e){return"clientX"in e&&"clientY"in e}function ui(e){if(!e)return!1;const{TouchEvent:t}=at(e.target);return t&&e instanceof t}function Jn(e){if(ui(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return ci(e)?{x:e.clientX,y:e.clientY}:null}var qn;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(qn||(qn={}));function Ht(e,t){return i.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function di(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return i.useMemo(()=>[...t].filter(r=>r!=null),[...t])}const tn=Object.freeze({x:0,y:0});var nt;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(nt||(nt={}));class Lt{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var r;return(r=this.target)==null?void 0:r.removeEventListener(...n)})},this.target=t}add(t,n,r){var a;(a=this.target)==null||a.addEventListener(t,n,r),this.listeners.push([t,n,r])}}function fi(e){const{EventTarget:t}=at(e);return e instanceof t?e:Bt(e)}function Nt(e,t){const n=Math.abs(e.x),r=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+r**2)>t:"x"in t&&"y"in t?n>t.x&&r>t.y:"x"in t?n>t.x:"y"in t?r>t.y:!1}var Pe;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Pe||(Pe={}));function Qn(e){e.preventDefault()}function hi(e){e.stopPropagation()}var Ve;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(Ve||(Ve={}));Ve.Space,Ve.Enter,Ve.Esc,Ve.Space,Ve.Enter,Ve.Tab;function er(e){return!!(e&&"distance"in e)}function tr(e){return!!(e&&"delay"in e)}class hn{constructor(t,n,r){var a;r===void 0&&(r=fi(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:s}=t,{target:o}=s;this.props=t,this.events=n,this.document=Bt(o),this.documentListeners=new Lt(this.document),this.listeners=new Lt(r),this.windowListeners=new Lt(at(o)),this.initialCoordinates=(a=Jn(s))!=null?a:tn,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:r}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(Pe.Resize,this.handleCancel),this.windowListeners.add(Pe.DragStart,Qn),this.windowListeners.add(Pe.VisibilityChange,this.handleCancel),this.windowListeners.add(Pe.ContextMenu,Qn),this.documentListeners.add(Pe.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(tr(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(er(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:r,onPending:a}=this.props;a(r,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(Pe.Click,hi,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Pe.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:r,initialCoordinates:a,props:s}=this,{onMove:o,options:{activationConstraint:l}}=s;if(!a)return;const c=(n=Jn(t))!=null?n:tn,u=li(a,c);if(!r&&l){if(er(l)){if(l.tolerance!=null&&Nt(u,l.tolerance))return this.handleCancel();if(Nt(u,l.distance))return this.handleStart()}if(tr(l)&&Nt(u,l.tolerance))return this.handleCancel();this.handlePending(l,u);return}t.cancelable&&t.preventDefault(),o(c)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===Ve.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const mi={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Gr extends hn{constructor(t){const{event:n}=t,r=Bt(n.target);super(t,mi,r)}}Gr.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return!n.isPrimary||n.button!==0?!1:(r?.({event:n}),!0)}}];const pi={move:{name:"mousemove"},end:{name:"mouseup"}};var nn;(function(e){e[e.RightClick=2]="RightClick"})(nn||(nn={}));class Or extends hn{constructor(t){super(t,pi,Bt(t.event.target))}}Or.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===nn.RightClick?!1:(r?.({event:n}),!0)}}];const Gt={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Yr extends hn{constructor(t){super(t,Gt)}static setup(){return window.addEventListener(Gt.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Gt.move.name,t)};function t(){}}}Yr.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;const{touches:a}=n;return a.length>1?!1:(r?.({event:n}),!0)}}];var nr;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(nr||(nr={}));var rr;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(rr||(rr={}));nt.Backward+"",nt.Forward+"",nt.Backward+"",nt.Forward+"";var rn;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(rn||(rn={}));var an;(function(e){e.Optimized="optimized"})(an||(an={}));rn.WhileDragging,an.Optimized;({...tn});var ar;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(ar||(ar={}));function gi(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:r=5,mouseDistance:a=1}=e,s=Ht(Or,{activationConstraint:{distance:a}}),o=Ht(Yr,{activationConstraint:t?{delay:n,tolerance:r}:{distance:a}}),l=Ht(Gr,{activationConstraint:{distance:a}});return di(...t?[s,o]:[l])}const bi=e=>{const{tracks:t,onTracksChange:n,sampleRate:r}=e,{currentTimeRef:a}=xe(),{selectedTrackId:s}=Me(),o=i.useCallback((c,u,f)=>{const{sampleRate:x,samplesPerPixel:v}=e,d=t[c];if(!d)return!1;const C=d.clips[u];if(!C)return!1;const y=C.startSample/x,h=(C.startSample+C.durationSamples)/x;if(f<=y||f>=h)return console.warn("Split time is outside clip bounds"),!1;const b=Math.round(f*x),g=Math.floor(b/v),m=C.startSample+C.durationSamples,p=g*v,I=C.startSample,k=p-I,A=p,R=m-A,D=p-C.startSample,M=en({audioBuffer:C.audioBuffer,startSample:I,durationSamples:k,offsetSamples:C.offsetSamples,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (1)`:void 0,color:C.color,fadeIn:C.fadeIn,waveformData:C.waveformData}),$=en({audioBuffer:C.audioBuffer,startSample:A,durationSamples:R,offsetSamples:C.offsetSamples+D,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (2)`:void 0,color:C.color,waveformData:C.waveformData,fadeOut:C.fadeOut}),E=[...d.clips];E.splice(u,1,M,$);const Z=[...t];return Z[c]={...d,clips:E},n(Z),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(x=>x.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],f=a.current??0;for(let x=0;x<u.clips.length;x++){const v=u.clips[x],d=v.startSample/r,C=(v.startSample+v.durationSamples)/r;if(f>d&&f<C)return console.log(`Splitting clip on track "${u.name}" at ${f}s`),o(c,x,f)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,a,s,o,r]),splitClipAt:o}},At=e=>{const{shortcuts:t,enabled:n=!0}=e,r=i.useCallback(a=>{if(!n)return;const s=a.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=a.key.toLowerCase()===l.key.toLowerCase()||a.key===l.key,u=l.ctrlKey===void 0||a.ctrlKey===l.ctrlKey,f=l.shiftKey===void 0||a.shiftKey===l.shiftKey,x=l.metaKey===void 0||a.metaKey===l.metaKey,v=l.altKey===void 0||a.altKey===l.altKey;return c&&u&&f&&x&&v});o&&(o.preventDefault!==!1&&a.preventDefault(),o.action())},[t,n]);i.useEffect(()=>{if(n)return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}},[r,n])},vi=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("+")},Ci=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:r}=e,{isPlaying:a}=xe(),{setCurrentTime:s,play:o,pause:l,stop:c}=fe(),{playoutRef:u}=be(),f=i.useCallback(()=>{a?l():o()},[a,o,l]),x=i.useCallback(()=>{c()},[c]),v=i.useCallback(()=>{a&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[a,u,s,o]),C=r??[...[{key:" ",action:f,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:x,description:"Stop",preventDefault:!0},{key:"0",action:v,description:"Rewind to start",preventDefault:!0}],...n];return At({shortcuts:C,enabled:t}),{rewindToStart:v,togglePlayPause:f,stopPlayback:x,shortcuts:C}},Ot=.01,xt=.01;function wi({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:r,duration:a,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:f,controlsWidth:x=0,onPlay:v}){const d=i.useMemo(()=>t?e.findIndex(D=>D.id===t):-1,[e,t]),C=i.useCallback(D=>{if(!c?.current||!u||!f)return;const M=e.find(z=>z.id===D);if(!M)return;const $=c.current,E=$.clientWidth,Z=M.start*f/u+x,P=M.end*f/u+x,F=(Z+P)/2,V=$.scrollLeft,H=V,q=V+E;if(Z<H||P>q){const z=Math.max(0,F-E/2);$.scrollTo({left:z,behavior:"smooth"})}},[e,c,u,f,x]);i.useEffect(()=>{t&&c?.current&&u&&f&&C(t)},[t,C,c,u,f]);const y=i.useCallback(D=>{if(d<0)return;const M=e[d],$=Math.max(0,Math.min(M.end-.1,M.start+D)),E=$-M.start,Z=[...e];if(Z[d]={...M,start:$},s&&d>0){const P=Z[d-1];Math.abs(P.end-M.start)<Ot&&(Z[d-1]={...P,end:Math.max(P.start+.1,P.end+E)})}else if(!s&&d>0){const P=Z[d-1];$<P.end&&(Z[d-1]={...P,end:$})}n(Z)},[e,d,s,n]),h=i.useCallback(D=>{if(d<0)return;const M=e[d],$=Math.max(M.start+.1,Math.min(a,M.end+D)),E=$-M.end,Z=[...e];if(Z[d]={...M,end:$},s&&d<e.length-1){const P=Z[d+1];if(Math.abs(P.start-M.end)<Ot){const F=Math.min(P.end-.1,P.start+E);Z[d+1]={...P,start:F};let V=d+1;for(;V<Z.length-1;){const H=Z[V],q=Z[V+1];if(Math.abs(q.start-e[V].end)<Ot){const z=H.end-e[V].end;Z[V+1]={...q,start:Math.min(q.end-.1,q.start+z)},V++}else break}}}else if(!s&&d<e.length-1){const P=Z[d+1];if($>P.start){Z[d+1]={...P,start:$};let F=d+1;for(;F<Z.length-1;){const V=Z[F],H=Z[F+1];if(V.end>H.start)Z[F+1]={...H,start:V.end},F++;else break}}}n(Z)},[e,d,a,s,n]),b=i.useCallback(()=>{!r||e.length===0||(d<=0?r(e[e.length-1].id):r(e[d-1].id))},[e,d,r]),g=i.useCallback(()=>{!r||e.length===0||(d<0||d>=e.length-1?r(e[0].id):r(e[d+1].id))},[e,d,r]),m=i.useCallback(()=>{!r||e.length===0||r(e[0].id)},[e,r]),p=i.useCallback(()=>{!r||e.length===0||r(e[e.length-1].id)},[e,r]),I=i.useCallback(()=>{r&&r(null)},[r]),k=i.useCallback(()=>{if(d<0||!v)return;const D=e[d],M=o?void 0:D.end-D.start;v(D.start,M)},[e,d,o,v]),A=i.useMemo(()=>[{key:"[",action:()=>y(-xt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>y(xt),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>h(-xt),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>h(xt),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:k,description:"Play selected annotation",preventDefault:!0}],[y,h,k]),R=i.useMemo(()=>[{key:"ArrowUp",action:b,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:b,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:g,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:g,description:"Select next annotation",preventDefault:!0},{key:"Home",action:m,description:"Select first annotation",preventDefault:!0},{key:"End",action:p,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:I,description:"Deselect annotation",preventDefault:!0}],[b,g,m,p,I]);return At({shortcuts:A,enabled:l&&d>=0}),At({shortcuts:R,enabled:l&&e.length>0&&!!r}),{moveStartBoundary:y,moveEndBoundary:h,selectPrevious:b,selectNext:g,selectFirst:m,selectLast:p,clearSelection:I,scrollToAnnotation:C,playActiveAnnotation:k}}function xi(e){const t=e.reduce((a,s)=>a+s.length,0),n=new Float32Array(t);let r=0;for(const a of e)n.set(a,r),r+=a.length;return n}function yi(e,t,n,r=1){const a=e.createBuffer(r,t.length,n),s=new Float32Array(t);return a.copyToChannel(s,0),a}function or(e,t,n=16){const r=Math.ceil(e.length/t),a=n===8?new Int8Array(r*2):new Int16Array(r*2),s=2**(n-1);for(let o=0;o<r;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,f=0;for(let x=l;x<c;x++){const v=e[x];v<u&&(u=v),v>f&&(f=v)}a[o*2]=Math.floor(u*s),a[o*2+1]=Math.floor(f*s)}return a}function ki(e,t,n,r,a=16){const s=2**(a-1),o=r%n;let l=0;if(o>0&&e.length>0){const f=n-o,x=Math.min(f,t.length);let v=e[e.length-2]/s,d=e[e.length-1]/s;for(let b=0;b<x;b++){const g=t[b];g<v&&(v=g),g>d&&(d=g)}const C=new(a===8?Int8Array:Int16Array)(e.length);C.set(e),C[e.length-2]=Math.floor(v*s),C[e.length-1]=Math.floor(d*s),l=x;const y=or(t.slice(l),n,a),h=new(a===8?Int8Array:Int16Array)(C.length+y.length);return h.set(C),h.set(y,C.length),h}const c=or(t.slice(l),n,a),u=new(a===8?Int8Array:Int16Array)(e.length+c.length);return u.set(e),u.set(c,e.length),u}function Ii(e,t={}){const{channelCount:n=1,samplesPerPixel:r=1024}=t,[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[f,x]=i.useState(new Int16Array(0)),[v,d]=i.useState(null),[C,y]=i.useState(null),[h,b]=i.useState(0),[g,m]=i.useState(0),p=16,I=i.useRef(!1),k=i.useRef(null),A=i.useRef(null),R=i.useRef([]),D=i.useRef(0),M=i.useRef(null),$=i.useRef(0),E=i.useRef(!1),Z=i.useRef(!1),P=i.useCallback(async()=>{if(!I.current)try{const z=W.getContext(),B=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Pt&&Pt.tagName.toUpperCase()==="SCRIPT"&&Pt.src||new URL("index.js",document.baseURI).href).href;await z.addAudioWorkletModule(B),I.current=!0}catch(z){throw console.error("Failed to load AudioWorklet module:",z),new Error("Failed to load recording processor")}},[]),F=i.useCallback(async()=>{if(!e){y(new Error("No microphone stream available"));return}try{y(null);const z=W.getContext();z.state==="suspended"&&await z.resume(),await P();const B=z.createMediaStreamSource(e);A.current=B;const K=z.createAudioWorkletNode("recording-processor");k.current=K,B.connect(K),K.port.onmessage=G=>{const{samples:O}=G.data;R.current.push(O),D.current+=O.length,x(te=>ki(te,O,r,D.current-O.length,p))},K.port.postMessage({command:"start",sampleRate:z.sampleRate,channelCount:n}),R.current=[],D.current=0,x(new Int16Array(0)),d(null),b(0),m(0),E.current=!0,Z.current=!1,s(!0),l(!1),$.current=performance.now();const U=()=>{if(E.current&&!Z.current){const G=(performance.now()-$.current)/1e3;u(G),M.current=requestAnimationFrame(U)}};U()}catch(z){console.error("Failed to start recording:",z),y(z instanceof Error?z:new Error("Failed to start recording"))}},[e,n,r,P,a,o]),V=i.useCallback(async()=>{if(!a)return null;try{if(k.current){if(k.current.port.postMessage({command:"stop"}),A.current)try{A.current.disconnect(k.current)}catch{}k.current.disconnect()}M.current!==null&&(cancelAnimationFrame(M.current),M.current=null);const z=xi(R.current),K=W.getContext().rawContext,U=yi(K,z,K.sampleRate,n);return d(U),u(U.duration),E.current=!1,Z.current=!1,s(!1),l(!1),b(0),U}catch(z){return console.error("Failed to stop recording:",z),y(z instanceof Error?z:new Error("Failed to stop recording")),null}},[a,n]),H=i.useCallback(()=>{a&&!o&&(M.current!==null&&(cancelAnimationFrame(M.current),M.current=null),Z.current=!0,l(!0))},[a,o]),q=i.useCallback(()=>{if(a&&o){Z.current=!1,l(!1),$.current=performance.now()-c*1e3;const z=()=>{if(E.current&&!Z.current){const B=(performance.now()-$.current)/1e3;u(B),M.current=requestAnimationFrame(z)}};z()}},[a,o,c]);return i.useEffect(()=>()=>{if(k.current){if(k.current.port.postMessage({command:"stop"}),A.current)try{A.current.disconnect(k.current)}catch{}k.current.disconnect()}M.current!==null&&cancelAnimationFrame(M.current)},[]),{isRecording:a,isPaused:o,duration:c,peaks:f,audioBuffer:v,level:h,peakLevel:g,startRecording:F,stopRecording:V,pauseRecording:H,resumeRecording:q,error:C}}function Si(){const[e,t]=i.useState(null),[n,r]=i.useState([]),[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),f=i.useCallback(async()=>{try{const C=(await navigator.mediaDevices.enumerateDevices()).filter(y=>y.kind==="audioinput").map(y=>({deviceId:y.deviceId,label:y.label||`Microphone ${y.deviceId.slice(0,8)}`,groupId:y.groupId}));r(C)}catch(d){console.error("Failed to enumerate devices:",d),u(d instanceof Error?d:new Error("Failed to enumerate devices"))}},[]),x=i.useCallback(async(d,C)=>{l(!0),u(null);try{e&&e.getTracks().forEach(g=>g.stop());const h={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...C,...d&&{deviceId:{exact:d}}},video:!1},b=await navigator.mediaDevices.getUserMedia(h);t(b),s(!0),await f()}catch(y){console.error("Failed to access microphone:",y),u(y instanceof Error?y:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,f]),v=i.useCallback(()=>{e&&(e.getTracks().forEach(d=>d.stop()),t(null),s(!1))},[e]);return i.useEffect(()=>(f(),()=>{e&&e.getTracks().forEach(d=>d.stop())}),[]),{stream:e,devices:n,hasPermission:a,isLoading:o,requestAccess:x,stopStream:v,error:c}}function Ai(e,t={}){const{updateRate:n=60,smoothingTimeConstant:r=.8}=t,[a,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),f=i.useRef(null),x=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let v=!0;return(async()=>{if(!v)return;const C=W.getContext();if(C.state==="suspended"&&await C.resume(),!v)return;const y=new W.Meter({smoothing:r,context:C});c.current=y;const h=C.createMediaStreamSource(e);u.current=h,W.connect(h,y);const b=1e3/n;let g=0;const m=p=>{if(!(!v||!c.current)){if(p-g>=b){g=p;const I=c.current.getValue(),k=typeof I=="number"?I:I[0],A=Math.max(0,Math.min(1,(k+100)/100));s(A),l(R=>Math.max(R,A))}f.current=requestAnimationFrame(m)}};f.current=requestAnimationFrame(m)})(),()=>{if(v=!1,f.current&&(cancelAnimationFrame(f.current),f.current=null),u.current){try{u.current.disconnect()}catch{}u.current=null}c.current&&(c.current.dispose(),c.current=null)}},[e,r,n]),{level:a,peakLevel:o,resetPeak:x}}S.button`
1067
1067
  padding: 0.5rem 1rem;
1068
1068
  font-size: 0.875rem;
1069
1069
  font-weight: 500;
@@ -1093,7 +1093,7 @@
1093
1093
  outline: none;
1094
1094
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.3);
1095
1095
  }
1096
- `;A.span`
1096
+ `;S.span`
1097
1097
  display: inline-block;
1098
1098
  width: 8px;
1099
1099
  height: 8px;
@@ -1111,13 +1111,13 @@
1111
1111
  opacity: 0.3;
1112
1112
  }
1113
1113
  }
1114
- `;A(tn)`
1114
+ `;S(ln)`
1115
1115
  min-width: 200px;
1116
- `;A(hr)`
1116
+ `;S(vr)`
1117
1117
  display: flex;
1118
1118
  flex-direction: column;
1119
1119
  gap: 0.25rem;
1120
- `;A.div`
1120
+ `;S.div`
1121
1121
  display: flex;
1122
1122
  align-items: center;
1123
1123
  gap: 0.75rem;
@@ -1125,7 +1125,7 @@
1125
1125
  background: ${e=>e.$isRecording?"#fff3cd":"transparent"};
1126
1126
  border-radius: 0.25rem;
1127
1127
  transition: background 0.2s ease-in-out;
1128
- `;A.div`
1128
+ `;S.div`
1129
1129
  width: 12px;
1130
1130
  height: 12px;
1131
1131
  border-radius: 50%;
@@ -1145,18 +1145,18 @@
1145
1145
  }
1146
1146
  }
1147
1147
  `}
1148
- `;A.span`
1148
+ `;S.span`
1149
1149
  font-family: 'Courier New', Monaco, monospace;
1150
1150
  font-size: 1rem;
1151
1151
  font-weight: 600;
1152
1152
  color: #495057;
1153
1153
  min-width: 70px;
1154
- `;A.span`
1154
+ `;S.span`
1155
1155
  font-size: 0.75rem;
1156
1156
  font-weight: 500;
1157
1157
  color: ${e=>e.$isPaused?"#ffc107":"#dc3545"};
1158
1158
  text-transform: uppercase;
1159
- `;var Ci=A.div`
1159
+ `;var $i=S.div`
1160
1160
  position: relative;
1161
1161
  width: ${e=>e.$width}px;
1162
1162
  height: ${e=>e.$height}px;
@@ -1164,39 +1164,39 @@
1164
1164
  border-radius: 4px;
1165
1165
  overflow: hidden;
1166
1166
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
1167
- `,wi=e=>e<.6?"linear-gradient(90deg, #27ae60, #2ecc71)":e<.85?"linear-gradient(90deg, #f39c12, #f1c40f)":"linear-gradient(90deg, #c0392b, #e74c3c)",xi=A.div.attrs(e=>({style:{width:`${e.$level*100}%`,height:`${e.$height}px`,background:wi(e.$level),boxShadow:e.$level>.01?"0 0 8px rgba(255, 255, 255, 0.3)":"none"}}))`
1167
+ `,Mi=e=>e<.6?"linear-gradient(90deg, #27ae60, #2ecc71)":e<.85?"linear-gradient(90deg, #f39c12, #f1c40f)":"linear-gradient(90deg, #c0392b, #e74c3c)",Di=S.div.attrs(e=>({style:{width:`${e.$level*100}%`,height:`${e.$height}px`,background:Mi(e.$level),boxShadow:e.$level>.01?"0 0 8px rgba(255, 255, 255, 0.3)":"none"}}))`
1168
1168
  position: absolute;
1169
1169
  left: 0;
1170
1170
  top: 0;
1171
1171
  transition: width 0.05s ease-out, background 0.1s ease-out;
1172
- `,yi=A.div.attrs(e=>({style:{left:`${e.$peakLevel*100}%`,height:`${e.$height}px`}}))`
1172
+ `,Ri=S.div.attrs(e=>({style:{left:`${e.$peakLevel*100}%`,height:`${e.$height}px`}}))`
1173
1173
  position: absolute;
1174
1174
  top: 0;
1175
1175
  width: 2px;
1176
1176
  background: #ecf0f1;
1177
1177
  box-shadow: 0 0 4px rgba(236, 240, 241, 0.8);
1178
1178
  transition: left 0.1s ease-out;
1179
- `,Ii=A.div`
1179
+ `,Ei=S.div`
1180
1180
  position: absolute;
1181
1181
  top: 0;
1182
1182
  left: 0;
1183
1183
  width: 100%;
1184
1184
  height: ${e=>e.$height}px;
1185
1185
  pointer-events: none;
1186
- `,tr=A.div`
1186
+ `,sr=S.div`
1187
1187
  position: absolute;
1188
1188
  left: ${e=>e.$position}%;
1189
1189
  top: 0;
1190
1190
  width: 1px;
1191
1191
  height: ${e=>e.$height}px;
1192
1192
  background: rgba(255, 255, 255, 0.2);
1193
- `,Si=({level:e,peakLevel:t,width:n=200,height:r=20,className:a})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return x.jsxs(Ci,{$width:n,$height:r,className:a,children:[x.jsx(xi,{$level:s,$height:r}),t!==void 0&&o>0&&x.jsx(yi,{$peakLevel:o,$height:r}),x.jsxs(Ii,{$height:r,children:[x.jsx(tr,{$position:60,$height:r}),x.jsx(tr,{$position:85,$height:r})]})]})};i.memo(Si);function Ai(e,t,n,r={}){const{currentTime:a=0,audioConstraints:s,...o}=r,[l,c]=i.useState(!1),[u,d]=i.useState(null),{stream:b,devices:g,hasPermission:f,requestAccess:v,error:y}=bi(),{level:m,peakLevel:h}=vi(b),{isRecording:w,isPaused:C,duration:p,peaks:S,startRecording:I,stopRecording:k,pauseRecording:R,resumeRecording:M,error:D}=gi(b,o),$=i.useCallback(async()=>{n&&(l||(await Wt(),c(!0)),await I())},[n,l,I]),T=i.useCallback(async()=>{const P=await k();if(P&&n){const j=e.findIndex(U=>U.id===n);if(j===-1)return;const N=e[j],Y=Math.floor(a*P.sampleRate);let z=0;if(N.clips.length>0){const U=N.clips.map(J=>J.startSample+J.durationSamples);z=Math.max(...U)}const K=Math.max(Y,z),ne={id:`clip-${Date.now()}`,audioBuffer:P,startSample:K,durationSamples:P.length,offsetSamples:0,sampleRate:P.sampleRate,sourceDurationSamples:P.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},te=e.map((U,J)=>J===j?{...U,clips:[...U.clips,ne]}:U);t(te)}},[n,e,t,a,k]);i.useEffect(()=>{f&&g.length>0&&u===null&&d(g[0].deviceId)},[f,g.length]);const W=i.useCallback(async()=>{await v(void 0,s),await Wt(),c(!0)},[v,s]),H=i.useCallback(async P=>{d(P),await v(P,s),await Wt(),c(!0)},[v,s]);return{isRecording:w,isPaused:C,duration:p,level:m,peakLevel:h,error:y||D,stream:b,devices:g,hasPermission:f,selectedDevice:u,startRecording:$,stopRecording:T,pauseRecording:R,resumeRecording:M,requestMicAccess:W,changeDevice:H,recordingPeaks:S}}const at=[{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}]}],ln=e=>at.find(t=>t.id===e),ki=e=>at.filter(t=>t.category===e),$i=[{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"}],Di={reverb:E.Reverb,freeverb:E.Freeverb,jcReverb:E.JCReverb,feedbackDelay:E.FeedbackDelay,pingPongDelay:E.PingPongDelay,chorus:E.Chorus,phaser:E.Phaser,tremolo:E.Tremolo,vibrato:E.Vibrato,autoPanner:E.AutoPanner,autoFilter:E.AutoFilter,autoWah:E.AutoWah,eq3:E.EQ3,distortion:E.Distortion,bitCrusher:E.BitCrusher,chebyshev:E.Chebyshev,compressor:E.Compressor,limiter:E.Limiter,gate:E.Gate,stereoWidener:E.StereoWidener};let Mi=0;const Ri=()=>`effect_${Date.now()}_${++Mi}`;function rt(e,t){const n=Di[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const r={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;r[o.name]=l});const a=new n(r),s=Ri();return{effect:a,id:e.id,instanceId:s,dispose(){try{a.disconnect(),a.dispose()}catch{}},setParameter(o,l){o==="wet"&&a.wet?a.wet.value=l:a[o]!==void 0&&(a[o]?.value!==void 0?a[o].value=l:a[o]=l)},getParameter(o){if(o==="wet"&&a.wet)return a.wet.value;if(a[o]!==void 0)return a[o]?.value!==void 0?a[o].value:a[o]},connect(o){a.connect(o)},disconnect(){try{a.disconnect()}catch{}}}}function Bi(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function Ei(e=256){const[t,n]=i.useState([]),r=i.useRef(t);r.current=t;const a=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(m=>{const h=o.current;if(!h)return;const{masterGainNode:w,destination:C,analyserNode:p}=h;try{w.disconnect()}catch{}const S=m.map(I=>a.current.get(I.instanceId)).filter(I=>I!==void 0);if(S.length===0)w.connect(p),p.connect(C);else{let I=w;S.forEach(k=>{try{k.disconnect()}catch{}I.connect(k.effect),I=k.effect}),I.connect(p),p.connect(C)}},[]),c=i.useCallback(m=>{const h=ln(m);if(!h){console.error(`Unknown effect: ${m}`);return}const w={};h.parameters.forEach(S=>{w[S.name]=S.default});const C=rt(h,w);a.current.set(C.instanceId,C);const p={instanceId:C.instanceId,effectId:h.id,definition:h,params:w,bypassed:!1};n(S=>[...S,p])},[]),u=i.useCallback(m=>{const h=a.current.get(m);h&&(h.dispose(),a.current.delete(m)),n(w=>w.filter(C=>C.instanceId!==m))},[]),d=i.useCallback((m,h,w)=>{const C=a.current.get(m);C&&C.setParameter(h,w),n(p=>p.map(S=>S.instanceId===m?{...S,params:{...S.params,[h]:w}}:S))},[]),b=i.useCallback(m=>{const h=r.current.find(p=>p.instanceId===m);if(!h)return;const w=!h.bypassed,C=a.current.get(m);if(C){const p=h.params.wet??1;C.setParameter("wet",w?0:p)}n(p=>p.map(S=>S.instanceId===m?{...S,bypassed:w}:S))},[]),g=i.useCallback((m,h)=>{n(w=>{const C=[...w],[p]=C.splice(m,1);return C.splice(h,0,p),C})},[]),f=i.useCallback(()=>{a.current.forEach(m=>m.dispose()),a.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const v=i.useCallback((m,h,w)=>{const C=new E.Analyser("fft",e);s.current=C,o.current={masterGainNode:m,destination:h,analyserNode:C};const S=r.current.map(I=>a.current.get(I.instanceId)).filter(I=>I!==void 0);if(S.length===0)m.connect(C),C.connect(h);else{let I=m;S.forEach(k=>{I.connect(k.effect),I=k.effect}),I.connect(C),C.connect(h)}return function(){C.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{a.current.forEach(m=>m.dispose()),a.current.clear()},[]);const y=i.useCallback(()=>{const m=t.filter(h=>!h.bypassed);if(m.length!==0)return(h,w,C)=>{const p=[];for(const S of m){const I=rt(S.definition,S.params);p.push(I)}if(p.length===0)h.connect(w);else{let S=h;p.forEach(I=>{S.connect(I.effect),S=I.effect}),S.connect(w)}return function(){p.forEach(I=>I.dispose())}}},[t]);return{activeEffects:t,availableEffects:at,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:b,reorderEffects:g,clearAllEffects:f,masterEffects:v,createOfflineEffectsFunction:y,analyserRef:s}}function Ti(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),r=i.useRef(new Map),a=i.useCallback((f,v)=>{const y=r.current.get(f);if(!y)return;const{graphEnd:m,masterGainNode:h}=y,w=n.current.get(f);try{m.disconnect()}catch{}const C=v.map(p=>w?.get(p.instanceId)).filter(p=>p!==void 0);if(C.length===0)m.connect(h);else{let p=m;C.forEach(S=>{try{S.disconnect()}catch{}p.connect(S.effect),p=S.effect}),p.connect(h)}},[]),s=i.useCallback((f,v)=>{const y=ln(v);if(!y){console.error(`Unknown effect: ${v}`);return}const m={};y.parameters.forEach(C=>{m[C.name]=C.default});const h=rt(y,m);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(h.instanceId,h);const w={instanceId:h.instanceId,effectId:y.id,definition:y,params:m,bypassed:!1};t(C=>{const p=new Map(C),S=p.get(f)||[];return p.set(f,[...S,w]),p})},[]),o=i.useCallback((f,v)=>{const y=n.current.get(f),m=y?.get(v);m&&(m.dispose(),y?.delete(v)),t(h=>{const w=new Map(h),C=w.get(f)||[];return w.set(f,C.filter(p=>p.instanceId!==v)),w})},[]),l=i.useCallback((f,v,y,m)=>{const w=n.current.get(f)?.get(v);w&&w.setParameter(y,m),t(C=>{const p=new Map(C),S=p.get(f)||[];return p.set(f,S.map(I=>I.instanceId===v?{...I,params:{...I.params,[y]:m}}:I)),p})},[]),c=i.useCallback((f,v)=>{const m=(d.current.get(f)||[]).find(p=>p.instanceId===v);if(!m)return;const h=!m.bypassed,C=n.current.get(f)?.get(v);if(C){const p=m.params.wet??1;C.setParameter("wet",h?0:p)}t(p=>{const S=new Map(p),I=S.get(f)||[];return S.set(f,I.map(k=>k.instanceId===v?{...k,bypassed:h}:k)),S})},[]),u=i.useCallback(f=>{const v=n.current.get(f);v&&(v.forEach(y=>y.dispose()),v.clear()),t(y=>{const m=new Map(y);return m.set(f,[]),m})},[]),d=i.useRef(e);d.current=e;const b=i.useCallback(f=>(v,y,m)=>{r.current.set(f,{graphEnd:v,masterGainNode:y});const h=d.current.get(f)||[],w=n.current.get(f),C=h.map(p=>w?.get(p.instanceId)).filter(p=>p!==void 0);if(C.length===0)v.connect(y);else{let p=v;C.forEach(S=>{p.connect(S.effect),p=S.effect}),p.connect(y)}return function(){r.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,v)=>{a(v,f)})},[e,a]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(v=>v.dispose()),f.clear()}),n.current.clear()},[]);const g=i.useCallback(f=>{const y=(e.get(f)||[]).filter(m=>!m.bypassed);if(y.length!==0)return(m,h,w)=>{const C=[];for(const p of y){const S=rt(p.definition,p.params);C.push(S)}if(C.length===0)m.connect(h);else{let p=m;C.forEach(S=>{p.connect(S.effect),p=S.effect}),p.connect(h)}return function(){C.forEach(S=>S.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:b,createOfflineTrackEffectsFunction:g,availableEffects:at}}function Wi(e,t={}){const{bitDepth:n=16}=t,r=e.numberOfChannels,a=e.sampleRate,s=e.length,o=n/8,l=r*o,c=a*l,u=s*l,d=44,b=d+u,g=new ArrayBuffer(b),f=new DataView(g);ht(f,0,"RIFF"),f.setUint32(4,b-8,!0),ht(f,8,"WAVE"),ht(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,n===32?3:1,!0),f.setUint16(22,r,!0),f.setUint32(24,a,!0),f.setUint32(28,c,!0),f.setUint16(32,l,!0),f.setUint16(34,n,!0),ht(f,36,"data"),f.setUint32(40,u,!0);const v=[];for(let m=0;m<r;m++)v.push(e.getChannelData(m));let y=d;if(n===16)for(let m=0;m<s;m++)for(let h=0;h<r;h++){const w=v[h][m],C=Math.max(-1,Math.min(1,w)),p=C<0?C*32768:C*32767;f.setInt16(y,p,!0),y+=2}else for(let m=0;m<s;m++)for(let h=0;h<r;h++)f.setFloat32(y,v[h][m],!0),y+=4;return new Blob([g],{type:"audio/wav"})}function ht(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}function Fi(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function Fr(){const[e,t]=i.useState(!1),[n,r]=i.useState(0),[a,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:b="master",trackIndex:g,autoDownload:f=!0,applyEffects:v=!0,effectsFunction:y,createOfflineTrackEffects:m,bitDepth:h=16,onProgress:w}=u;t(!0),r(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(b==="individual"&&(g===void 0||g<0||g>=l.length))throw new Error("Invalid track index for individual export");const C=l[0].clips[0]?.sampleRate||44100;let p=0;for(const $ of l)for(const T of $.clips){const W=T.startSample+T.durationSamples;p=Math.max(p,W)}p+=Math.round(C*.1);const S=p/C,I=b==="individual"?[{track:l[g],state:c[g],index:g}]:l.map(($,T)=>({track:$,state:c[T],index:T})),k=c.some($=>$.soloed),R=!!m;let M;if((y||R)&&v)M=await Zi(I,c,k,S,C,y,m,$=>{r($),w?.($)});else{const $=new OfflineAudioContext(2,p,C);let T=0;const W=I.reduce((H,{track:P})=>H+P.clips.length,0);for(const{track:H,state:P}of I)if(!(P.muted&&!P.soloed)&&!(k&&!P.soloed))for(const j of H.clips){await Vi($,j,P,C,v),T++;const N=T/W*.5;r(N),w?.(N)}r(.5),w?.(.5),M=await $.startRendering()}r(.9),w?.(.9);const D=Wi(M,{bitDepth:h});if(r(1),w?.(1),f){const $=b==="individual"?`${d}_${l[g].name}`:d;Fi(D,`${$}.wav`)}return{audioBuffer:M,blob:D,duration:S}}catch(C){const p=C instanceof Error?C.message:"Export failed";throw s(p),C}finally{t(!1)}},[]),isExporting:e,progress:n,error:a}}async function Zi(e,t,n,r,a,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:b,Player:g,ToneAudioBuffer:f}=await import("tone");l(.1);let v;try{v=await c(async({transport:y,destination:m})=>{const h=new u(0);let w;s?w=s(h,m,!0):h.connect(m);for(const{track:C,state:p}of e){if(p.muted&&!p.soloed||n&&!p.soloed)continue;const S=new u(_i(p.volume)),I=new b(p.pan),k=new d(p.muted?0:1),R=o?.(C.id);R?R(k,h,!0):k.connect(h),I.connect(k),S.connect(I);for(const M of C.clips){const{audioBuffer:D,startSample:$,durationSamples:T,offsetSamples:W,gain:H,fadeIn:P,fadeOut:j}=M,N=$/a,Y=T/a,z=W/a,K=new f(D),ne=new g(K),te=new d(H);if(ne.connect(te),te.connect(S),P){const U=N,J=N+P.duration,fe=te.gain._param;fe.setValueAtTime(0,U),fe.linearRampToValueAtTime(H,J)}if(j){const U=N+Y-j.duration,J=N+Y,fe=te.gain._param;fe.setValueAtTime(H,U),fe.linearRampToValueAtTime(0,J)}ne.start(N,z,Y)}}y.start(0)},r,2,a)}catch(y){throw y instanceof Error?y:new Error(`Tone.Offline rendering failed: ${String(y)}`)}return l(.9),v.get()}function _i(e){return 20*Math.log10(Math.max(e,1e-4))}async function Vi(e,t,n,r,a){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 g=o/r,f=l/r,v=c/r,y=e.createBufferSource();y.buffer=s;const m=e.createGain(),h=u*n.volume,w=e.createStereoPanner();if(w.pan.value=n.pan,y.connect(m),m.connect(w),w.connect(e.destination),a){if(d?m.gain.setValueAtTime(0,g):m.gain.setValueAtTime(h,g),d){const C=g,p=g+d.duration;nr(m.gain,C,p,0,h,d.type||"linear")}if(b){const C=g+f-b.duration,p=g+f;(!d||d.duration<f-b.duration)&&m.gain.setValueAtTime(h,C),nr(m.gain,C,p,h,0,b.type||"linear")}}else m.gain.setValueAtTime(h,g);y.start(g,v,f)}function nr(e,t,n,r,a,s){const o=n-t;if(!(o<=0))switch(s){case"linear":e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n);break;case"exponential":const l=Math.max(r,1e-4),c=Math.max(a,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),a===0&&e.setValueAtTime(0,n);break;case"logarithmic":const u=rr(r,a,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=rr(r,a,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n)}}function rr(e,t,n,r){const a=new Float32Array(n),s=t-e;for(let o=0;o<n;o++){const l=o/(n-1);let c;r==="logarithmic"?s>0?c=Math.log10(1+l*9)/Math.log10(10):c=1-Math.log10(1+(1-l)*9)/Math.log10(10):c=l*l*(3-2*l),a[o]=e+s*c}return a}const Zr=i.createContext(null),_r=i.createContext(null),Vr=i.createContext(null),zr=i.createContext(null),Xr=i.createContext(null),zi=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:r=80,samplesPerPixel:a=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:b,onAnnotationUpdate:g,barWidth:f=1,barGap:v=0,progressBarWidth:y,children:m})=>{const h=y??f+v,[w,C]=i.useState([]),[p,S]=i.useState(null),[I,k]=i.useState(!1),[R,M]=i.useState(0),[D,$]=i.useState(0),[T,W]=i.useState([]),[H,P]=i.useState([]),[j,N]=i.useState([]),[Y,z]=i.useState(0),[K,ne]=i.useState(0),[te,U]=i.useState(null),[J,fe]=i.useState(o),[Pe,Xe]=i.useState(u?.isContinuousPlay??!1),[kt,se]=i.useState(u?.linkEndpoints??!0),[ie,ot]=i.useState(u?.editable??!1),[st,q]=i.useState(!1),[Ge,$t]=i.useState(0),[Dt,qe]=i.useState(0),F=i.useRef(null),Se=i.useRef(0),ce=i.useRef(0),re=i.useRef(null),De=i.useRef(j),Me=i.useRef(0),Ae=i.useRef(0),Fe=i.useRef(null),Ze=i.useRef(null),it=i.useRef(!1),Mt=i.useRef(u?.isContinuousPlay??!1),V=i.useRef(null),L=i.useRef(a),ee=i.useRef(!1),ue=i.useRef(0),pe=i.useRef(0),he=i.useRef(0),O=i.useRef(0),{timeFormat:Re,setTimeFormat:Be,formatTime:_e}=$r(),Ce=Dr({initialSamplesPerPixel:a,zoomLevels:s}),we=Ce.samplesPerPixel,{masterVolume:Qe,setMasterVolume:Rt}=Mr({playoutRef:F,initialVolume:1}),Hr=i.useCallback(B=>{Mt.current=B,Xe(B)},[]),Le=i.useCallback(B=>{V.current=B,S(B)},[]),jr=i.useCallback(B=>{ee.current=B,q(B)},[]),et=i.useCallback((B,_)=>{he.current=B,O.current=_,$t(B),qe(_)},[]),Pr=i.useCallback(()=>{const B=ue.current,_=pe.current;B!==_&&_>B&&et(B,_)},[et]),Gr=i.useCallback(()=>{et(0,0)},[et]);i.useEffect(()=>{it.current=J},[J]),i.useEffect(()=>{De.current=j},[j]),i.useEffect(()=>{ue.current=Y,pe.current=K},[Y,K]),i.useEffect(()=>{if(!Ze.current||!T.length)return;const B=Ze.current,_=L.current,G=we;if(_===G)return;const Q=c.show?c.width:0,Z=B.clientWidth,$e=B.scrollLeft+Z/2-Q,ae=T[0].sampleRate,be=$e*_/ae*ae/G,Ee=Math.max(0,be+Q-Z/2);B.scrollLeft=Ee,L.current=G},[we,T,c]);const lt=i.useRef(null);i.useEffect(()=>{if(e.length===0){W([]),$(0),N([]),P([]),F.current&&(F.current.dispose(),F.current=null);return}const B=I,_=ce.current;return F.current&&B&&(F.current.stop(),re.current&&(cancelAnimationFrame(re.current),re.current=null),lt.current={position:_}),(async()=>{try{const Q=[];e.forEach(ae=>{ae.clips.length>0&&ae.clips[0].audioBuffer&&Q.push(ae.clips[0].audioBuffer)});let Z=0;e.forEach(ae=>{ae.clips.forEach(de=>{const be=de.sampleRate,ct=(de.startSample+de.durationSamples)/be;Z=Math.max(Z,ct)})}),W(Q),$(Z),N(ae=>ae.length===e.length?ae.map((de,be)=>({...de,name:e[be].name})):e.map(de=>({name:de.name,muted:de.muted,soloed:de.soloed,volume:de.volume,pan:de.pan}))),F.current&&F.current.dispose();const le=new va({effects:d}),$e=De.current;e.forEach((ae,de)=>{const be=ae.clips.filter(Ee=>Ee.audioBuffer);if(be.length>0){const Ee=be[0].sampleRate,ct=Math.min(...be.map(ve=>ve.startSample/Ee)),aa=Math.max(...be.map(ve=>(ve.startSample+ve.durationSamples)/Ee)),ut=$e[de],oa={id:`track-${de}`,name:ae.name,gain:ut?.volume??ae.volume,muted:ut?.muted??ae.muted,soloed:ut?.soloed??ae.soloed,stereoPan:ut?.pan??ae.pan,startTime:ct,endTime:aa},sa=be.map(ve=>{const Et=ve.sampleRate;return{buffer:ve.audioBuffer,startTime:ve.startSample/Et-ct,duration:ve.durationSamples/Et,offset:ve.offsetSamples/Et,fadeIn:ve.fadeIn,fadeOut:ve.fadeOut,gain:ve.gain}});le.addTrack({clips:sa,track:oa,effects:ae.effects})}}),le.applyInitialSoloState(),F.current=le,b?.()}catch(Q){console.error("Error loading audio:",Q)}})(),()=>{re.current&&cancelAnimationFrame(re.current),F.current&&F.current.dispose()}},[e,b,I]),i.useEffect(()=>{if(e.length===0)return;const B=16,_=e.map(G=>G.clips.map(Z=>{if(Z.waveformData){const $e=ls(Z.waveformData,we,0,Z.offsetSamples,Z.durationSamples);return{clipId:Z.id,trackName:G.name,peaks:{length:$e.length,data:[$e.data],bits:$e.bits},startSample:Z.startSample,durationSamples:Z.durationSamples,fadeIn:Z.fadeIn,fadeOut:Z.fadeOut}}if(!Z.audioBuffer)return console.warn(`Clip "${Z.name||Z.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:Z.id,trackName:G.name,peaks:{length:0,data:[],bits:B},startSample:Z.startSample,durationSamples:Z.durationSamples,fadeIn:Z.fadeIn,fadeOut:Z.fadeOut};const le=Po(Z.audioBuffer,we,n,B,Z.offsetSamples,Z.durationSamples);return{clipId:Z.id,trackName:G.name,peaks:le,startSample:Z.startSample,durationSamples:Z.durationSamples,fadeIn:Z.fadeIn,fadeOut:Z.fadeOut}}));P(_)},[e,we,n]),i.useEffect(()=>{if(u?.annotations){const B=u.annotations.map(_=>typeof _.start=="number"?_:gs(_));C(B)}},[u]);const He=i.useCallback(()=>{re.current&&(cancelAnimationFrame(re.current),re.current=null);const B=()=>{const _=E.getContext().currentTime-Me.current,G=Ae.current+_;if(ce.current=G,M(G),w.length>0){const Z=w.find(le=>G>=le.start&&G<le.end);if(Mt.current){if(Z&&Z.id!==V.current)Le(Z.id);else if(!Z&&V.current!==null){const le=w[w.length-1];if(G>=le.end){F.current&&F.current.stop(),k(!1),ce.current=Se.current,M(Se.current),Le(null);return}}}else if(V.current){const le=w.find($e=>$e.id===V.current);if(le&&G>=le.end){F.current&&F.current.stop(),k(!1),ce.current=Se.current,M(Se.current);return}}else Z&&Le(Z.id)}if(it.current&&Ze.current&&T.length>0){const Z=Ze.current,le=T[0].sampleRate,$e=G*le/L.current,ae=Z.clientWidth,de=c.show?c.width:0,be=$e+de,Ee=Math.max(0,be-ae/2);Z.scrollLeft=Ee}if(Fe.current!==null&&G>=Fe.current){F.current&&F.current.stop(),k(!1),ce.current=Fe.current,M(Fe.current),Fe.current=null;return}const Q=he.current!==O.current&&O.current>he.current;if(ee.current&&Q&&G>=O.current){F.current?.stop();const le=E.getContext().currentTime;Me.current=le,Ae.current=he.current,ce.current=he.current,F.current?.play(le,he.current),re.current=requestAnimationFrame(B);return}if(G>=D){F.current&&F.current.stop(),k(!1),ce.current=Se.current,M(Se.current),Le(null);return}re.current=requestAnimationFrame(B)};re.current=requestAnimationFrame(B)},[D,T,we,w,Pe]),ke=i.useCallback(()=>{re.current&&(cancelAnimationFrame(re.current),re.current=null)},[]);i.useEffect(()=>{(async()=>{if(I&&re.current&&F.current)if(Pe){const _=ce.current;F.current.stop(),ke(),await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const Q=E.getContext().currentTime;Me.current=Q,Ae.current=_,F.current.play(Q,_),He()}else ke(),He()})()},[Pe,I,He,ke]),i.useEffect(()=>{(async()=>{if(lt.current&&F.current){const{position:_}=lt.current;lt.current=null,await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const Q=E.getContext().currentTime;Me.current=Q,Ae.current=_,F.current.play(Q,_),k(!0),He()}})()},[e,He]);const Bt=i.useCallback(async(B,_)=>{if(!F.current||T.length===0)return;await F.current.init(),await E.start();const G=B??ce.current;Se.current=G,ce.current=G,F.current.setOnPlaybackComplete(()=>{}),F.current.stop(),ke();const Z=E.getContext().currentTime;Me.current=Z,Ae.current=G,Fe.current=_!==void 0?G+_:null,F.current.play(Z,G,_),k(!0),He()},[T.length,He,ke]),Lr=i.useCallback(()=>{if(!F.current)return;const B=E.getContext().currentTime-Me.current,_=Ae.current+B;F.current.pause(),k(!1),ke(),ce.current=_,M(_)},[ke]),Nr=i.useCallback(()=>{F.current&&(F.current.stop(),k(!1),ke(),ce.current=Se.current,M(Se.current),Le(null))},[ke]),Yr=i.useCallback(B=>{const _=Math.max(0,Math.min(B,D));ce.current=_,M(_),I&&F.current&&(F.current.stop(),ke(),Bt(_))},[D,I,Bt,ke]),Or=i.useCallback((B,_)=>{const G=[...j];if(G[B]={...G[B],muted:_},N(G),F.current){const Q=`track-${B}`;F.current.setMute(Q,_)}},[j]),Kr=i.useCallback((B,_)=>{const G=[...j];if(G[B]={...G[B],soloed:_},N(G),F.current){const Q=`track-${B}`;F.current.setSolo(Q,_)}},[j]),Ur=i.useCallback((B,_)=>{const G=[...j];if(G[B]={...G[B],volume:_},N(G),F.current){const Q=`track-${B}`,Z=F.current.getTrack(Q);Z&&Z.setVolume(_)}},[j]),Jr=i.useCallback((B,_)=>{const G=[...j];if(G[B]={...G[B],pan:_},N(G),F.current){const Q=`track-${B}`,Z=F.current.getTrack(Q);Z&&Z.setPan(_)}},[j]),qr=i.useCallback((B,_)=>{z(B),ne(_),ce.current=B,M(B),I&&F.current&&(F.current.stop(),F.current.play(E.getContext().currentTime,B))},[I]),Qr=i.useCallback(B=>{Ze.current=B},[]),ea=T[0]?.sampleRate||44100,cn=t?30:0,ta=e.length*r+cn,un={isPlaying:I,currentTime:R,currentTimeRef:ce,playbackStartTimeRef:Me,audioStartPositionRef:Ae},dn={continuousPlay:Pe,linkEndpoints:kt,annotationsEditable:ie,isAutomaticScroll:J,isLoopEnabled:st,annotations:w,activeAnnotationId:p,selectionStart:Y,selectionEnd:K,selectedTrackId:te,loopStart:Ge,loopEnd:Dt},fn={play:Bt,pause:Lr,stop:Nr,seekTo:Yr,setCurrentTime:B=>{ce.current=B,M(B)},setTrackMute:Or,setTrackSolo:Kr,setTrackVolume:Ur,setTrackPan:Jr,setSelection:qr,setSelectedTrackId:U,setTimeFormat:Be,formatTime:_e,zoomIn:Ce.zoomIn,zoomOut:Ce.zoomOut,setMasterVolume:Rt,setAutomaticScroll:B=>{fe(B)},setScrollContainer:Qr,scrollContainerRef:Ze,setContinuousPlay:Hr,setLinkEndpoints:se,setAnnotationsEditable:ot,setAnnotations:C,setActiveAnnotationId:Le,setLoopEnabled:jr,setLoopRegion:et,setLoopRegionFromSelection:Pr,clearLoopRegion:Gr},hn={duration:D,audioBuffers:T,peaksDataArray:H,trackStates:j,tracks:e,sampleRate:ea,waveHeight:r,timeScaleHeight:cn,minimumPlaylistHeight:ta,controls:c,playoutRef:F,samplesPerPixel:we,timeFormat:Re,masterVolume:Qe,canZoomIn:Ce.canZoomIn,canZoomOut:Ce.canZoomOut,barWidth:f,barGap:v,progressBarWidth:h},na={...un,...dn,...fn,...hn},ra={...Wa,...l};return x.jsx(A.ThemeProvider,{theme:ra,children:x.jsx(Zr.Provider,{value:un,children:x.jsx(_r.Provider,{value:dn,children:x.jsx(Vr.Provider,{value:fn,children:x.jsx(zr.Provider,{value:hn,children:x.jsx(Xr.Provider,{value:na,children:m})})})})})})},ge=()=>{const e=i.useContext(Zr);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Ie=()=>{const e=i.useContext(_r);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},oe=()=>{const e=i.useContext(Vr);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},me=()=>{const e=i.useContext(zr);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},Xi=()=>{const e=i.useContext(Xr);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e},Hi=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=ge(),{selectionStart:r,selectionEnd:a,isLoopEnabled:s}=Ie(),{play:o}=oe(),l=async()=>{if(r!==a&&a>r)if(s)await o(r);else{const u=a-r;await o(r,u)}else await o(n.current??0)};return x.jsx(ye,{onClick:l,disabled:t,className:e,children:"Play"})},ji=({className:e})=>{const{isPlaying:t}=ge(),{pause:n}=oe();return x.jsx(ye,{onClick:n,disabled:!t,className:e,children:"Pause"})},Pi=({className:e})=>{const{isPlaying:t}=ge(),{stop:n}=oe();return x.jsx(ye,{onClick:n,disabled:!t,className:e,children:"Stop"})},Gi=({className:e})=>{const{isPlaying:t}=ge(),{play:n,setCurrentTime:r}=oe(),{playoutRef:a}=me(),s=()=>{r(0),t&&a.current&&(a.current.stop(),n(0))};return x.jsx(ye,{onClick:s,className:e,children:"Rewind"})},Li=({className:e})=>{const{isPlaying:t}=ge(),{play:n,setCurrentTime:r}=oe(),{duration:a,playoutRef:s}=me(),o=()=>{r(a),t&&s.current&&(s.current.stop(),n(a))};return x.jsx(ye,{onClick:o,className:e,children:"Fast Forward"})},Ni=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=ge(),{play:a,setCurrentTime:s}=oe(),{playoutRef:o}=me(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),r&&o.current&&(o.current.stop(),a(c))};return x.jsx(ye,{onClick:l,className:t,children:"Skip Backward"})},Yi=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=ge(),{play:a,setCurrentTime:s}=oe(),{duration:o,playoutRef:l}=me(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),r&&l.current&&(l.current.stop(),a(u))};return x.jsx(ye,{onClick:c,className:t,children:"Skip Forward"})},Oi=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:r}=Ie(),{setLoopEnabled:a,setLoopRegion:s}=oe(),{duration:o}=me(),l=n!==r&&r>n,c=()=>{if(!t&&!l){const u=Math.min(10,o*.25);s(0,Math.max(1,u))}a(!t)};return x.jsx(ye,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Ki=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:r,loopEnd:a}=Ie(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=oe(),l=t!==n&&n>t,c=r!==a&&a>r,u=()=>{c?o():s()};return x.jsx(ye,{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"})},Ui=({className:e,disabled:t})=>{const{zoomIn:n}=oe(),{canZoomIn:r}=me();return x.jsx(ye,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom In"})},Ji=({className:e,disabled:t})=>{const{zoomOut:n}=oe(),{canZoomOut:r}=me();return x.jsx(ye,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom Out"})},qi=({className:e})=>{const{masterVolume:t}=me(),{setMasterVolume:n}=oe();return x.jsx(Qa,{volume:t,onChange:n,className:e})},Qi=({className:e})=>{const{timeFormat:t}=me(),{setTimeFormat:n}=oe();return x.jsx(Ro,{value:t,onChange:n,className:e})},el=A.span`
1193
+ `,Ti=({level:e,peakLevel:t,width:n=200,height:r=20,className:a})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return w.jsxs($i,{$width:n,$height:r,className:a,children:[w.jsx(Di,{$level:s,$height:r}),t!==void 0&&o>0&&w.jsx(Ri,{$peakLevel:o,$height:r}),w.jsxs(Ei,{$height:r,children:[w.jsx(sr,{$position:60,$height:r}),w.jsx(sr,{$position:85,$height:r})]})]})};i.memo(Ti);function Bi(e,t,n,r={}){const{currentTime:a=0,audioConstraints:s,...o}=r,[l,c]=i.useState(!1),[u,f]=i.useState(null),{stream:x,devices:v,hasPermission:d,requestAccess:C,error:y}=Si(),{level:h,peakLevel:b}=Ai(x),{isRecording:g,isPaused:m,duration:p,peaks:I,startRecording:k,stopRecording:A,pauseRecording:R,resumeRecording:D,error:M}=Ii(x,o),$=i.useCallback(async()=>{n&&(l||(await Vt(),c(!0)),await k())},[n,l,k]),E=i.useCallback(async()=>{const F=await A();if(F&&n){const V=e.findIndex(G=>G.id===n);if(V===-1)return;const H=e[V],q=Math.floor(a*F.sampleRate);let z=0;if(H.clips.length>0){const G=H.clips.map(O=>O.startSample+O.durationSamples);z=Math.max(...G)}const B=Math.max(q,z),K={id:`clip-${Date.now()}`,audioBuffer:F,startSample:B,durationSamples:F.length,offsetSamples:0,sampleRate:F.sampleRate,sourceDurationSamples:F.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},U=e.map((G,O)=>O===V?{...G,clips:[...G.clips,K]}:G);t(U)}},[n,e,t,a,A]);i.useEffect(()=>{d&&v.length>0&&u===null&&f(v[0].deviceId)},[d,v.length]);const Z=i.useCallback(async()=>{await C(void 0,s),await Vt(),c(!0)},[C,s]),P=i.useCallback(async F=>{f(F),await C(F,s),await Vt(),c(!0)},[C,s]);return{isRecording:g,isPaused:m,duration:p,level:h,peakLevel:b,error:y||M,stream:x,devices:v,hasPermission:d,selectedDevice:u,startRecording:$,stopRecording:E,pauseRecording:R,resumeRecording:D,requestMicAccess:Z,changeDevice:P,recordingPeaks:I}}const ft=[{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}]}],mn=e=>ft.find(t=>t.id===e),Wi=e=>ft.filter(t=>t.category===e),Fi=[{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"}],_i={reverb:W.Reverb,freeverb:W.Freeverb,jcReverb:W.JCReverb,feedbackDelay:W.FeedbackDelay,pingPongDelay:W.PingPongDelay,chorus:W.Chorus,phaser:W.Phaser,tremolo:W.Tremolo,vibrato:W.Vibrato,autoPanner:W.AutoPanner,autoFilter:W.AutoFilter,autoWah:W.AutoWah,eq3:W.EQ3,distortion:W.Distortion,bitCrusher:W.BitCrusher,chebyshev:W.Chebyshev,compressor:W.Compressor,limiter:W.Limiter,gate:W.Gate,stereoWidener:W.StereoWidener};let Zi=0;const Pi=()=>`effect_${Date.now()}_${++Zi}`;function ct(e,t){const n=_i[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const r={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;r[o.name]=l});const a=new n(r),s=Pi();return{effect:a,id:e.id,instanceId:s,dispose(){try{a.disconnect(),a.dispose()}catch{}},setParameter(o,l){o==="wet"&&a.wet?a.wet.value=l:a[o]!==void 0&&(a[o]?.value!==void 0?a[o].value=l:a[o]=l)},getParameter(o){if(o==="wet"&&a.wet)return a.wet.value;if(a[o]!==void 0)return a[o]?.value!==void 0?a[o].value:a[o]},connect(o){a.connect(o)},disconnect(){try{a.disconnect()}catch{}}}}function Vi(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 zi(e=256){const[t,n]=i.useState([]),r=i.useRef(t);r.current=t;const a=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(h=>{const b=o.current;if(!b)return;const{masterGainNode:g,destination:m,analyserNode:p}=b;try{g.disconnect()}catch{}const I=h.map(k=>a.current.get(k.instanceId)).filter(k=>k!==void 0);if(I.length===0)g.connect(p),p.connect(m);else{let k=g;I.forEach(A=>{try{A.disconnect()}catch{}k.connect(A.effect),k=A.effect}),k.connect(p),p.connect(m)}},[]),c=i.useCallback(h=>{const b=mn(h);if(!b){console.error(`Unknown effect: ${h}`);return}const g={};b.parameters.forEach(I=>{g[I.name]=I.default});const m=ct(b,g);a.current.set(m.instanceId,m);const p={instanceId:m.instanceId,effectId:b.id,definition:b,params:g,bypassed:!1};n(I=>[...I,p])},[]),u=i.useCallback(h=>{const b=a.current.get(h);b&&(b.dispose(),a.current.delete(h)),n(g=>g.filter(m=>m.instanceId!==h))},[]),f=i.useCallback((h,b,g)=>{const m=a.current.get(h);m&&m.setParameter(b,g),n(p=>p.map(I=>I.instanceId===h?{...I,params:{...I.params,[b]:g}}:I))},[]),x=i.useCallback(h=>{const b=r.current.find(p=>p.instanceId===h);if(!b)return;const g=!b.bypassed,m=a.current.get(h);if(m){const p=b.params.wet??1;m.setParameter("wet",g?0:p)}n(p=>p.map(I=>I.instanceId===h?{...I,bypassed:g}:I))},[]),v=i.useCallback((h,b)=>{n(g=>{const m=[...g],[p]=m.splice(h,1);return m.splice(b,0,p),m})},[]),d=i.useCallback(()=>{a.current.forEach(h=>h.dispose()),a.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const C=i.useCallback((h,b,g)=>{const m=new W.Analyser("fft",e);s.current=m,o.current={masterGainNode:h,destination:b,analyserNode:m};const I=r.current.map(k=>a.current.get(k.instanceId)).filter(k=>k!==void 0);if(I.length===0)h.connect(m),m.connect(b);else{let k=h;I.forEach(A=>{k.connect(A.effect),k=A.effect}),k.connect(m),m.connect(b)}return function(){m.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{a.current.forEach(h=>h.dispose()),a.current.clear()},[]);const y=i.useCallback(()=>{const h=t.filter(b=>!b.bypassed);if(h.length!==0)return(b,g,m)=>{const p=[];for(const I of h){const k=ct(I.definition,I.params);p.push(k)}if(p.length===0)b.connect(g);else{let I=b;p.forEach(k=>{I.connect(k.effect),I=k.effect}),I.connect(g)}return function(){p.forEach(k=>k.dispose())}}},[t]);return{activeEffects:t,availableEffects:ft,addEffect:c,removeEffect:u,updateParameter:f,toggleBypass:x,reorderEffects:v,clearAllEffects:d,masterEffects:C,createOfflineEffectsFunction:y,analyserRef:s}}function ji(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),r=i.useRef(new Map),a=i.useCallback((d,C)=>{const y=r.current.get(d);if(!y)return;const{graphEnd:h,masterGainNode:b}=y,g=n.current.get(d);try{h.disconnect()}catch{}const m=C.map(p=>g?.get(p.instanceId)).filter(p=>p!==void 0);if(m.length===0)h.connect(b);else{let p=h;m.forEach(I=>{try{I.disconnect()}catch{}p.connect(I.effect),p=I.effect}),p.connect(b)}},[]),s=i.useCallback((d,C)=>{const y=mn(C);if(!y){console.error(`Unknown effect: ${C}`);return}const h={};y.parameters.forEach(m=>{h[m.name]=m.default});const b=ct(y,h);n.current.has(d)||n.current.set(d,new Map),n.current.get(d).set(b.instanceId,b);const g={instanceId:b.instanceId,effectId:y.id,definition:y,params:h,bypassed:!1};t(m=>{const p=new Map(m),I=p.get(d)||[];return p.set(d,[...I,g]),p})},[]),o=i.useCallback((d,C)=>{const y=n.current.get(d),h=y?.get(C);h&&(h.dispose(),y?.delete(C)),t(b=>{const g=new Map(b),m=g.get(d)||[];return g.set(d,m.filter(p=>p.instanceId!==C)),g})},[]),l=i.useCallback((d,C,y,h)=>{const g=n.current.get(d)?.get(C);g&&g.setParameter(y,h),t(m=>{const p=new Map(m),I=p.get(d)||[];return p.set(d,I.map(k=>k.instanceId===C?{...k,params:{...k.params,[y]:h}}:k)),p})},[]),c=i.useCallback((d,C)=>{const h=(f.current.get(d)||[]).find(p=>p.instanceId===C);if(!h)return;const b=!h.bypassed,m=n.current.get(d)?.get(C);if(m){const p=h.params.wet??1;m.setParameter("wet",b?0:p)}t(p=>{const I=new Map(p),k=I.get(d)||[];return I.set(d,k.map(A=>A.instanceId===C?{...A,bypassed:b}:A)),I})},[]),u=i.useCallback(d=>{const C=n.current.get(d);C&&(C.forEach(y=>y.dispose()),C.clear()),t(y=>{const h=new Map(y);return h.set(d,[]),h})},[]),f=i.useRef(e);f.current=e;const x=i.useCallback(d=>(C,y,h)=>{r.current.set(d,{graphEnd:C,masterGainNode:y});const b=f.current.get(d)||[],g=n.current.get(d),m=b.map(p=>g?.get(p.instanceId)).filter(p=>p!==void 0);if(m.length===0)C.connect(y);else{let p=C;m.forEach(I=>{p.connect(I.effect),p=I.effect}),p.connect(y)}return function(){r.current.delete(d)}},[]);i.useEffect(()=>{e.forEach((d,C)=>{a(C,d)})},[e,a]),i.useEffect(()=>()=>{n.current.forEach(d=>{d.forEach(C=>C.dispose()),d.clear()}),n.current.clear()},[]);const v=i.useCallback(d=>{const y=(e.get(d)||[]).filter(h=>!h.bypassed);if(y.length!==0)return(h,b,g)=>{const m=[];for(const p of y){const I=ct(p.definition,p.params);m.push(I)}if(m.length===0)h.connect(b);else{let p=h;m.forEach(I=>{p.connect(I.effect),p=I.effect}),p.connect(b)}return function(){m.forEach(I=>I.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:x,createOfflineTrackEffectsFunction:v,availableEffects:ft}}function Xi(e,t={}){const{bitDepth:n=16}=t,r=e.numberOfChannels,a=e.sampleRate,s=e.length,o=n/8,l=r*o,c=a*l,u=s*l,f=44,x=f+u,v=new ArrayBuffer(x),d=new DataView(v);yt(d,0,"RIFF"),d.setUint32(4,x-8,!0),yt(d,8,"WAVE"),yt(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,n===32?3:1,!0),d.setUint16(22,r,!0),d.setUint32(24,a,!0),d.setUint32(28,c,!0),d.setUint16(32,l,!0),d.setUint16(34,n,!0),yt(d,36,"data"),d.setUint32(40,u,!0);const C=[];for(let h=0;h<r;h++)C.push(e.getChannelData(h));let y=f;if(n===16)for(let h=0;h<s;h++)for(let b=0;b<r;b++){const g=C[b][h],m=Math.max(-1,Math.min(1,g)),p=m<0?m*32768:m*32767;d.setInt16(y,p,!0),y+=2}else for(let h=0;h<s;h++)for(let b=0;b<r;b++)d.setFloat32(y,C[b][h],!0),y+=4;return new Blob([v],{type:"audio/wav"})}function yt(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}function Hi(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function Kr(){const[e,t]=i.useState(!1),[n,r]=i.useState(0),[a,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:f="export",mode:x="master",trackIndex:v,autoDownload:d=!0,applyEffects:C=!0,effectsFunction:y,createOfflineTrackEffects:h,bitDepth:b=16,onProgress:g}=u;t(!0),r(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(x==="individual"&&(v===void 0||v<0||v>=l.length))throw new Error("Invalid track index for individual export");const m=l[0].clips[0]?.sampleRate||44100;let p=0;for(const $ of l)for(const E of $.clips){const Z=E.startSample+E.durationSamples;p=Math.max(p,Z)}p+=Math.round(m*.1);const I=p/m,k=x==="individual"?[{track:l[v],state:c[v],index:v}]:l.map(($,E)=>({track:$,state:c[E],index:E})),A=c.some($=>$.soloed),R=!!h;let D;if((y||R)&&C)D=await Li(k,c,A,I,m,y,h,$=>{r($),g?.($)});else{const $=new OfflineAudioContext(2,p,m);let E=0;const Z=k.reduce((P,{track:F})=>P+F.clips.length,0);for(const{track:P,state:F}of k)if(!(F.muted&&!F.soloed)&&!(A&&!F.soloed))for(const V of P.clips){await Gi($,V,F,m,C),E++;const H=E/Z*.5;r(H),g?.(H)}r(.5),g?.(.5),D=await $.startRendering()}r(.9),g?.(.9);const M=Xi(D,{bitDepth:b});if(r(1),g?.(1),d){const $=x==="individual"?`${f}_${l[v].name}`:f;Hi(M,`${$}.wav`)}return{audioBuffer:D,blob:M,duration:I}}catch(m){const p=m instanceof Error?m.message:"Export failed";throw s(p),m}finally{t(!1)}},[]),isExporting:e,progress:n,error:a}}async function Li(e,t,n,r,a,s,o,l){const{Offline:c,Volume:u,Gain:f,Panner:x,Player:v,ToneAudioBuffer:d}=await import("tone");l(.1);let C;try{C=await c(async({transport:y,destination:h})=>{const b=new u(0);let g;s?g=s(b,h,!0):b.connect(h);for(const{track:m,state:p}of e){if(p.muted&&!p.soloed||n&&!p.soloed)continue;const I=new u(Ni(p.volume)),k=new x(p.pan),A=new f(p.muted?0:1),R=o?.(m.id);R?R(A,b,!0):A.connect(b),k.connect(A),I.connect(k);for(const D of m.clips){const{audioBuffer:M,startSample:$,durationSamples:E,offsetSamples:Z,gain:P,fadeIn:F,fadeOut:V}=D,H=$/a,q=E/a,z=Z/a,B=new d(M),K=new v(B),U=new f(P);if(K.connect(U),U.connect(I),F){const G=H,O=H+F.duration,te=U.gain._param;te.setValueAtTime(0,G),te.linearRampToValueAtTime(P,O)}if(V){const G=H+q-V.duration,O=H+q,te=U.gain._param;te.setValueAtTime(P,G),te.linearRampToValueAtTime(0,O)}K.start(H,z,q)}}y.start(0)},r,2,a)}catch(y){throw y instanceof Error?y:new Error(`Tone.Offline rendering failed: ${String(y)}`)}return l(.9),C.get()}function Ni(e){return 20*Math.log10(Math.max(e,1e-4))}async function Gi(e,t,n,r,a){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:f,fadeOut:x}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const v=o/r,d=l/r,C=c/r,y=e.createBufferSource();y.buffer=s;const h=e.createGain(),b=u*n.volume,g=e.createStereoPanner();if(g.pan.value=n.pan,y.connect(h),h.connect(g),g.connect(e.destination),a){if(f?h.gain.setValueAtTime(0,v):h.gain.setValueAtTime(b,v),f){const m=v,p=v+f.duration;ir(h.gain,m,p,0,b,f.type||"linear")}if(x){const m=v+d-x.duration,p=v+d;(!f||f.duration<d-x.duration)&&h.gain.setValueAtTime(b,m),ir(h.gain,m,p,b,0,x.type||"linear")}}else h.gain.setValueAtTime(b,v);y.start(v,C,d)}function ir(e,t,n,r,a,s){const o=n-t;if(!(o<=0))switch(s){case"linear":e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n);break;case"exponential":const l=Math.max(r,1e-4),c=Math.max(a,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),a===0&&e.setValueAtTime(0,n);break;case"logarithmic":const u=lr(r,a,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const f=lr(r,a,256,"sCurve");e.setValueCurveAtTime(f,t,o);break;default:e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n)}}function lr(e,t,n,r){const a=new Float32Array(n),s=t-e;for(let o=0;o<n;o++){const l=o/(n-1);let c;r==="logarithmic"?s>0?c=Math.log10(1+l*9)/Math.log10(10):c=1-Math.log10(1+(1-l)*9)/Math.log10(10):c=l*l*(3-2*l),a[o]=e+s*c}return a}const Ur=i.createContext(null),Jr=i.createContext(null),qr=i.createContext(null),Qr=i.createContext(null),ea=i.createContext(null),Oi=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:r=80,samplesPerPixel:a=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:f,onReady:x,onAnnotationUpdate:v,barWidth:d=1,barGap:C=0,progressBarWidth:y,children:h})=>{const b=y??d+C,[g,m]=i.useState([]),[p,I]=i.useState(null),[k,A]=i.useState(!1),[R,D]=i.useState(0),[M,$]=i.useState(0),[E,Z]=i.useState([]),[P,F]=i.useState([]),[V,H]=i.useState([]),[q,z]=i.useState(0),[B,K]=i.useState(0),[U,G]=i.useState(null),[O,te]=i.useState(o),[ve,De]=i.useState(u?.isContinuousPlay??!1),[Fe,Be]=i.useState(u?.linkEndpoints??!0),[Ke,se]=i.useState(u?.editable??!1),[ie,Ue]=i.useState(!1),[Je,ne]=i.useState(0),[Q,ee]=i.useState(0),_=i.useRef(null),le=i.useRef(0),ce=i.useRef(0),pe=i.useRef(null),ht=i.useRef(V),ye=i.useRef(0),Ce=i.useRef(0),ze=i.useRef(null),We=i.useRef(null),mt=i.useRef(!1),pt=i.useRef(u?.isContinuousPlay??!1),Ne=i.useRef(null),gt=i.useRef(a),L=i.useRef(!1),J=i.useRef(0),oe=i.useRef(0),ue=i.useRef(0),me=i.useRef(0),{timeFormat:Re,setTimeFormat:re,formatTime:_e}=jr(),ke=Xr({initialSamplesPerPixel:a,zoomLevels:s}),we=ke.samplesPerPixel,{masterVolume:je,setMasterVolume:qe}=Hr({playoutRef:_,initialVolume:1}),ot=i.useCallback(T=>{pt.current=T,De(T)},[]),Xe=i.useCallback(T=>{Ne.current=T,I(T)},[]),ia=i.useCallback(T=>{L.current=T,Ue(T)},[]),st=i.useCallback((T,X)=>{ue.current=T,me.current=X,ne(T),ee(X)},[]),la=i.useCallback(()=>{const T=J.current,X=oe.current;T!==X&&X>T&&st(T,X)},[st]),ca=i.useCallback(()=>{st(0,0)},[st]);i.useEffect(()=>{mt.current=O},[O]),i.useEffect(()=>{ht.current=V},[V]),i.useEffect(()=>{J.current=q,oe.current=B},[q,B]),i.useEffect(()=>{if(!We.current||!E.length)return;const T=We.current,X=gt.current,Y=we;if(X===Y)return;const ae=c.show?c.width:0,j=T.clientWidth,Te=T.scrollLeft+j/2-ae,de=E[0].sampleRate,Ie=Te*X/de*de/Y,Ze=Math.max(0,Ie+ae-j/2);T.scrollLeft=Ze,gt.current=Y},[we,E,c]);const bt=i.useRef(null);i.useEffect(()=>{if(e.length===0){Z([]),$(0),H([]),F([]),_.current&&(_.current.dispose(),_.current=null);return}const T=k,X=ce.current;return _.current&&T&&(_.current.stop(),pe.current&&(cancelAnimationFrame(pe.current),pe.current=null),bt.current={position:X}),(async()=>{try{const ae=[];e.forEach(de=>{de.clips.length>0&&de.clips[0].audioBuffer&&ae.push(de.clips[0].audioBuffer)});let j=0;e.forEach(de=>{de.clips.forEach(ge=>{const Ie=ge.sampleRate,vt=(ge.startSample+ge.durationSamples)/Ie;j=Math.max(j,vt)})}),Z(ae),$(j),H(de=>de.length===e.length?de.map((ge,Ie)=>({...ge,name:e[Ie].name})):e.map(ge=>({name:ge.name,muted:ge.muted,soloed:ge.soloed,volume:ge.volume,pan:ge.pan}))),_.current&&_.current.dispose();const he=new Za({effects:f}),Te=ht.current;e.forEach((de,ge)=>{const Ie=de.clips.filter(Ze=>Ze.audioBuffer);if(Ie.length>0){const Ze=Ie[0].sampleRate,vt=Math.min(...Ie.map(Se=>Se.startSample/Ze)),ka=Math.max(...Ie.map(Se=>(Se.startSample+Se.durationSamples)/Ze)),Ct=Te[ge],Ia={id:`track-${ge}`,name:de.name,gain:Ct?.volume??de.volume,muted:Ct?.muted??de.muted,soloed:Ct?.soloed??de.soloed,stereoPan:Ct?.pan??de.pan,startTime:vt,endTime:ka},Sa=Ie.map(Se=>{const Zt=Se.sampleRate;return{buffer:Se.audioBuffer,startTime:Se.startSample/Zt-vt,duration:Se.durationSamples/Zt,offset:Se.offsetSamples/Zt,fadeIn:Se.fadeIn,fadeOut:Se.fadeOut,gain:Se.gain}});he.addTrack({clips:Sa,track:Ia,effects:de.effects})}}),he.applyInitialSoloState(),_.current=he,x?.()}catch(ae){console.error("Error loading audio:",ae)}})(),()=>{pe.current&&cancelAnimationFrame(pe.current),_.current&&_.current.dispose()}},[e,x,k]),i.useEffect(()=>{if(e.length===0)return;const T=16,X=e.map(Y=>Y.clips.map(j=>{if(j.waveformData){const Te=_r(j.waveformData,we,0,j.offsetSamples,j.durationSamples);return{clipId:j.id,trackName:Y.name,peaks:{length:Te.length,data:[Te.data],bits:Te.bits},startSample:j.startSample,durationSamples:j.durationSamples,fadeIn:j.fadeIn,fadeOut:j.fadeOut}}if(!j.audioBuffer)return console.warn(`Clip "${j.name||j.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:j.id,trackName:Y.name,peaks:{length:0,data:[],bits:T},startSample:j.startSample,durationSamples:j.durationSamples,fadeIn:j.fadeIn,fadeOut:j.fadeOut};const he=ns(j.audioBuffer,we,n,T,j.offsetSamples,j.durationSamples);return{clipId:j.id,trackName:Y.name,peaks:he,startSample:j.startSample,durationSamples:j.durationSamples,fadeIn:j.fadeIn,fadeOut:j.fadeOut}}));F(X)},[e,we,n]),i.useEffect(()=>{if(u?.annotations){const T=u.annotations.map(X=>typeof X.start=="number"?X:Zr(X));m(T)}},[u]);const Ge=i.useCallback(()=>{pe.current&&(cancelAnimationFrame(pe.current),pe.current=null);const T=()=>{const X=W.getContext().currentTime-ye.current,Y=Ce.current+X;if(ce.current=Y,D(Y),g.length>0){const j=g.find(he=>Y>=he.start&&Y<he.end);if(pt.current){if(j&&j.id!==Ne.current)Xe(j.id);else if(!j&&Ne.current!==null){const he=g[g.length-1];if(Y>=he.end){_.current&&_.current.stop(),A(!1),ce.current=le.current,D(le.current),Xe(null);return}}}else if(Ne.current){const he=g.find(Te=>Te.id===Ne.current);if(he&&Y>=he.end){_.current&&_.current.stop(),A(!1),ce.current=le.current,D(le.current);return}}else j&&Xe(j.id)}if(mt.current&&We.current&&E.length>0){const j=We.current,he=E[0].sampleRate,Te=Y*he/gt.current,de=j.clientWidth,ge=c.show?c.width:0,Ie=Te+ge,Ze=Math.max(0,Ie-de/2);j.scrollLeft=Ze}if(ze.current!==null&&Y>=ze.current){_.current&&_.current.stop(),A(!1),ce.current=ze.current,D(ze.current),ze.current=null;return}const ae=ue.current!==me.current&&me.current>ue.current;if(L.current&&ae&&Y>=me.current){_.current?.stop();const he=W.getContext().currentTime;ye.current=he,Ce.current=ue.current,ce.current=ue.current,_.current?.play(he,ue.current),pe.current=requestAnimationFrame(T);return}if(Y>=M){_.current&&_.current.stop(),A(!1),ce.current=le.current,D(le.current),Xe(null);return}pe.current=requestAnimationFrame(T)};pe.current=requestAnimationFrame(T)},[M,E,we,g,ve]),Ee=i.useCallback(()=>{pe.current&&(cancelAnimationFrame(pe.current),pe.current=null)},[]);i.useEffect(()=>{(async()=>{if(k&&pe.current&&_.current)if(ve){const X=ce.current;_.current.stop(),Ee(),await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const ae=W.getContext().currentTime;ye.current=ae,Ce.current=X,_.current.play(ae,X),Ge()}else Ee(),Ge()})()},[ve,k,Ge,Ee]),i.useEffect(()=>{(async()=>{if(bt.current&&_.current){const{position:X}=bt.current;bt.current=null,await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const ae=W.getContext().currentTime;ye.current=ae,Ce.current=X,_.current.play(ae,X),A(!0),Ge()}})()},[e,Ge]);const _t=i.useCallback(async(T,X)=>{if(!_.current||E.length===0)return;await _.current.init(),await W.start();const Y=T??ce.current;le.current=Y,ce.current=Y,_.current.setOnPlaybackComplete(()=>{}),_.current.stop(),Ee();const j=W.getContext().currentTime;ye.current=j,Ce.current=Y,ze.current=X!==void 0?Y+X:null,_.current.play(j,Y,X),A(!0),Ge()},[E.length,Ge,Ee]),ua=i.useCallback(()=>{if(!_.current)return;const T=W.getContext().currentTime-ye.current,X=Ce.current+T;_.current.pause(),A(!1),Ee(),ce.current=X,D(X)},[Ee]),da=i.useCallback(()=>{_.current&&(_.current.stop(),A(!1),Ee(),ce.current=le.current,D(le.current),Xe(null))},[Ee]),fa=i.useCallback(T=>{const X=Math.max(0,Math.min(T,M));ce.current=X,D(X),k&&_.current&&(_.current.stop(),Ee(),_t(X))},[M,k,_t,Ee]),ha=i.useCallback((T,X)=>{const Y=[...V];if(Y[T]={...Y[T],muted:X},H(Y),_.current){const ae=`track-${T}`;_.current.setMute(ae,X)}},[V]),ma=i.useCallback((T,X)=>{const Y=[...V];if(Y[T]={...Y[T],soloed:X},H(Y),_.current){const ae=`track-${T}`;_.current.setSolo(ae,X)}},[V]),pa=i.useCallback((T,X)=>{const Y=[...V];if(Y[T]={...Y[T],volume:X},H(Y),_.current){const ae=`track-${T}`,j=_.current.getTrack(ae);j&&j.setVolume(X)}},[V]),ga=i.useCallback((T,X)=>{const Y=[...V];if(Y[T]={...Y[T],pan:X},H(Y),_.current){const ae=`track-${T}`,j=_.current.getTrack(ae);j&&j.setPan(X)}},[V]),ba=i.useCallback((T,X)=>{z(T),K(X),ce.current=T,D(T),k&&_.current&&(_.current.stop(),_.current.play(W.getContext().currentTime,T))},[k]),va=i.useCallback(T=>{We.current=T},[]),Ca=E[0]?.sampleRate||44100,pn=t?30:0,wa=e.length*r+pn,gn={isPlaying:k,currentTime:R,currentTimeRef:ce,playbackStartTimeRef:ye,audioStartPositionRef:Ce},bn={continuousPlay:ve,linkEndpoints:Fe,annotationsEditable:Ke,isAutomaticScroll:O,isLoopEnabled:ie,annotations:g,activeAnnotationId:p,selectionStart:q,selectionEnd:B,selectedTrackId:U,loopStart:Je,loopEnd:Q},vn={play:_t,pause:ua,stop:da,seekTo:fa,setCurrentTime:T=>{ce.current=T,D(T)},setTrackMute:ha,setTrackSolo:ma,setTrackVolume:pa,setTrackPan:ga,setSelection:ba,setSelectedTrackId:G,setTimeFormat:re,formatTime:_e,zoomIn:ke.zoomIn,zoomOut:ke.zoomOut,setMasterVolume:qe,setAutomaticScroll:T=>{te(T)},setScrollContainer:va,scrollContainerRef:We,setContinuousPlay:ot,setLinkEndpoints:Be,setAnnotationsEditable:se,setAnnotations:m,setActiveAnnotationId:Xe,setLoopEnabled:ia,setLoopRegion:st,setLoopRegionFromSelection:la,clearLoopRegion:ca},Cn={duration:M,audioBuffers:E,peaksDataArray:P,trackStates:V,tracks:e,sampleRate:Ca,waveHeight:r,timeScaleHeight:pn,minimumPlaylistHeight:wa,controls:c,playoutRef:_,samplesPerPixel:we,timeFormat:Re,masterVolume:je,canZoomIn:ke.canZoomIn,canZoomOut:ke.canZoomOut,barWidth:d,barGap:C,progressBarWidth:b},xa={...gn,...bn,...vn,...Cn},ya={...xr,...l};return w.jsx(S.ThemeProvider,{theme:ya,children:w.jsx(Ur.Provider,{value:gn,children:w.jsx(Jr.Provider,{value:bn,children:w.jsx(qr.Provider,{value:vn,children:w.jsx(Qr.Provider,{value:Cn,children:w.jsx(ea.Provider,{value:xa,children:h})})})})})})},xe=()=>{const e=i.useContext(Ur);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Me=()=>{const e=i.useContext(Jr);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},fe=()=>{const e=i.useContext(qr);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},be=()=>{const e=i.useContext(Qr);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},Yi=()=>{const e=i.useContext(ea);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var Ki=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}},Ui=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 Ki({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const r=t??0;if(this._isPlaying=!0,this.track.play(r),n!==void 0){const a=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},a*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const ta=i.createContext(null),na=i.createContext(null),ra=i.createContext(null),aa=i.createContext(null),Ji=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:r=!1,playbackRate:a=1,theme:s,controls:o={show:!1,width:0},annotationList:l,barWidth:c=1,barGap:u=0,progressBarWidth:f,onReady:x,children:v})=>{const d=f??c+u,[C,y]=i.useState(!1),[h,b]=i.useState(0),[g,m]=i.useState(0),[p,I]=i.useState([]),[k,A]=i.useState(a),[R,D]=i.useState([]),[M,$]=i.useState(null),[E,Z]=i.useState(l?.isContinuousPlay??!1),[P]=i.useState(t),F=i.useRef(null),V=i.useRef(0),H=i.useRef(null),q=i.useRef(E),z=i.useRef(null);i.useEffect(()=>{q.current=E},[E]);const B=i.useCallback(Q=>{z.current=Q,$(Q)},[]),K=i.useCallback(Q=>{q.current=Q,Z(Q)},[]),U=e.waveformData.sample_rate;i.useEffect(()=>{const Q=new Ui({playbackRate:a});Q.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const ee=Q.getTrack(Q.track?.id??"");return ee&&ee.setOnTimeUpdateCallback(_=>{V.current=_}),Q.setOnPlaybackComplete(()=>{y(!1)}),F.current=Q,m(e.waveformData.duration),x?.(),()=>{H.current&&cancelAnimationFrame(H.current),Q.dispose()}},[e.source,e.waveformData,e.name,a,x]),i.useEffect(()=>{const Q=_r(e.waveformData,P,0,0,Math.ceil(e.waveformData.duration*U)),ee={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:Q.length,data:[Q.data],bits:Q.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*U)};I([[ee]])},[e.waveformData,e.name,P,U]),i.useEffect(()=>{if(l?.annotations){const Q=l.annotations.map(ee=>typeof ee.start=="number"?ee:Zr(ee));D(Q)}},[l]);const G=i.useCallback(()=>{H.current&&cancelAnimationFrame(H.current);const Q=()=>{const ee=F.current?.getCurrentTime()??0;if(V.current=ee,b(ee),R.length>0){const _=R.find(le=>ee>=le.start&&ee<le.end);if(q.current){if(_&&_.id!==z.current)B(_.id);else if(!_&&z.current!==null){const le=R[R.length-1];if(ee>=le.end){F.current?.stop(),y(!1),B(null);return}}}else if(z.current){const le=R.find(ce=>ce.id===z.current);if(le&&ee>=le.end){F.current?.stop(),y(!1);return}}else _&&B(_.id)}if(ee>=g){F.current?.stop(),y(!1),B(null);return}H.current=requestAnimationFrame(Q)};H.current=requestAnimationFrame(Q)},[g,R,B]),O=i.useCallback(()=>{H.current&&(cancelAnimationFrame(H.current),H.current=null)},[]),te=i.useCallback(Q=>{if(!F.current)return;const ee=Q??V.current;F.current.play(void 0,ee),y(!0),G()},[G]),ve=i.useCallback(()=>{F.current&&(F.current.pause(),y(!1),O(),b(F.current.getCurrentTime()))},[O]),De=i.useCallback(()=>{F.current&&(F.current.stop(),y(!1),O(),V.current=0,b(0),B(null))},[O,B]),Fe=i.useCallback(Q=>{const ee=Math.max(0,Math.min(Q,g));V.current=ee,b(ee),F.current&&F.current.seekTo(ee)},[g]),Be=i.useCallback(Q=>{const ee=Math.max(.5,Math.min(2,Q));A(ee),F.current&&F.current.setPlaybackRate(ee)},[]),Ke=r?30:0,se=i.useMemo(()=>({isPlaying:C,currentTime:h,currentTimeRef:V}),[C,h]),ie=i.useMemo(()=>({continuousPlay:E,annotations:R,activeAnnotationId:M,playbackRate:k}),[E,R,M,k]),Ue=i.useMemo(()=>({play:te,pause:ve,stop:De,seekTo:Fe,setPlaybackRate:Be,setContinuousPlay:K,setAnnotations:D,setActiveAnnotationId:B}),[te,ve,De,Fe,Be,K,B]),Je=i.useMemo(()=>({duration:g,peaksDataArray:p,sampleRate:U,waveHeight:n,timeScaleHeight:Ke,samplesPerPixel:P,playoutRef:F,controls:o,barWidth:c,barGap:u,progressBarWidth:d}),[g,p,U,n,Ke,P,o,c,u,d]),ne={...xr,...s};return w.jsx(S.ThemeProvider,{theme:ne,children:w.jsx(ta.Provider,{value:se,children:w.jsx(na.Provider,{value:ie,children:w.jsx(ra.Provider,{value:Ue,children:w.jsx(aa.Provider,{value:Je,children:v})})})})})},Wt=()=>{const e=i.useContext(ta);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},oa=()=>{const e=i.useContext(na);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},sa=()=>{const e=i.useContext(ra);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Ft=()=>{const e=i.useContext(aa);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},qi=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=xe(),{selectionStart:r,selectionEnd:a,isLoopEnabled:s}=Me(),{play:o}=fe(),l=async()=>{if(r!==a&&a>r)if(s)await o(r);else{const u=a-r;await o(r,u)}else await o(n.current??0)};return w.jsx($e,{onClick:l,disabled:t,className:e,children:"Play"})},Qi=({className:e})=>{const{isPlaying:t}=xe(),{pause:n}=fe();return w.jsx($e,{onClick:n,disabled:!t,className:e,children:"Pause"})},el=({className:e})=>{const{isPlaying:t}=xe(),{stop:n}=fe();return w.jsx($e,{onClick:n,disabled:!t,className:e,children:"Stop"})},tl=({className:e})=>{const{isPlaying:t}=xe(),{play:n,setCurrentTime:r}=fe(),{playoutRef:a}=be(),s=()=>{r(0),t&&a.current&&(a.current.stop(),n(0))};return w.jsx($e,{onClick:s,className:e,children:"Rewind"})},nl=({className:e})=>{const{isPlaying:t}=xe(),{play:n,setCurrentTime:r}=fe(),{duration:a,playoutRef:s}=be(),o=()=>{r(a),t&&s.current&&(s.current.stop(),n(a))};return w.jsx($e,{onClick:o,className:e,children:"Fast Forward"})},rl=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=xe(),{play:a,setCurrentTime:s}=fe(),{playoutRef:o}=be(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),r&&o.current&&(o.current.stop(),a(c))};return w.jsx($e,{onClick:l,className:t,children:"Skip Backward"})},al=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=xe(),{play:a,setCurrentTime:s}=fe(),{duration:o,playoutRef:l}=be(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),r&&l.current&&(l.current.stop(),a(u))};return w.jsx($e,{onClick:c,className:t,children:"Skip Forward"})},ol=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:r}=Me(),{setLoopEnabled:a,setLoopRegion:s}=fe(),{duration:o}=be(),l=n!==r&&r>n,c=()=>{if(!t&&!l){const u=Math.min(10,o*.25);s(0,Math.max(1,u))}a(!t)};return w.jsx($e,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},sl=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:r,loopEnd:a}=Me(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=fe(),l=t!==n&&n>t,c=r!==a&&a>r,u=()=>{c?o():s()};return w.jsx($e,{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"})},il=({className:e,disabled:t})=>{const{zoomIn:n}=fe(),{canZoomIn:r}=be();return w.jsx($e,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom In"})},ll=({className:e,disabled:t})=>{const{zoomOut:n}=fe(),{canZoomOut:r}=be();return w.jsx($e,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom Out"})},cl=({className:e})=>{const{masterVolume:t}=be(),{setMasterVolume:n}=fe();return w.jsx(vo,{volume:t,onChange:n,className:e})},ul=({className:e})=>{const{timeFormat:t}=be(),{setTimeFormat:n}=fe();return w.jsx(Lo,{value:t,onChange:n,className:e})},dl=S.span`
1194
1194
  font-family: 'Courier New', Monaco, monospace;
1195
1195
  font-size: 1rem;
1196
1196
  font-weight: 600;
1197
1197
  color: ${e=>e.theme?.textColor||"#333"};
1198
1198
  user-select: none;
1199
- `,tl=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:r,currentTimeRef:a,playbackStartTimeRef:s,audioStartPositionRef:o}=ge(),{timeFormat:l}=me(),c=l;return i.useEffect(()=>{const u=()=>{if(t.current){let d;if(r){const b=E.getContext().currentTime-(s.current??0);d=(o.current??0)+b}else d=a.current??0;t.current.textContent=Ue(d,c)}r&&(n.current=requestAnimationFrame(u))};return r?n.current=requestAnimationFrame(u):u(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,c,a,s,o]),i.useEffect(()=>{!r&&t.current&&(t.current.textContent=Ue(a.current??0,c))}),x.jsx(el,{ref:t,className:e,"aria-label":"Audio position",children:Ue(a.current??0,c)})},nl=({className:e})=>{const{selectionStart:t,selectionEnd:n}=Ie(),{setSelection:r}=oe();return x.jsx(fo,{selectionStart:t,selectionEnd:n,onSelectionChange:r,className:e})},rl=({className:e})=>{const{isAutomaticScroll:t}=Ie(),{setAutomaticScroll:n}=oe();return x.jsx(Ta,{checked:t,onChange:n,className:e})},al=({className:e})=>{const{continuousPlay:t}=Ie(),{setContinuousPlay:n}=oe();return x.jsx(_s,{checked:t,onChange:n,className:e})},ol=({className:e})=>{const{linkEndpoints:t}=Ie(),{setLinkEndpoints:n}=oe();return x.jsx(Vs,{checked:t,onChange:n,className:e})},sl=({className:e})=>{const{annotationsEditable:t}=Ie(),{setAnnotationsEditable:n}=oe();return x.jsx(zs,{checked:t,onChange:n,className:e})},il=({filename:e,className:t})=>{const{annotations:n}=Ie();return x.jsx(Hs,{annotations:n,filename:e,className:t})},ll=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:r,bitDepth:a=16,applyEffects:s=!0,effectsFunction:o,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:d})=>{const{tracks:b,trackStates:g}=me(),{exportWav:f,isExporting:v,progress:y}=Fr(),m=async()=>{try{const w=await f(b,g,{filename:t,mode:n,trackIndex:r,bitDepth:a,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(w.blob)}catch(w){d?.(w instanceof Error?w:new Error("Export failed"))}},h=v?`Exporting ${Math.round(y*100)}%`:e;return x.jsx(ye,{onClick:m,disabled:v||b.length===0,className:c,children:h})},cl=A.div`
1199
+ `,fl=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:r,currentTimeRef:a,playbackStartTimeRef:s,audioStartPositionRef:o}=xe(),{timeFormat:l}=be(),c=l;return i.useEffect(()=>{const u=()=>{if(t.current){let f;if(r){const x=W.getContext().currentTime-(s.current??0);f=(o.current??0)+x}else f=a.current??0;t.current.textContent=rt(f,c)}r&&(n.current=requestAnimationFrame(u))};return r?n.current=requestAnimationFrame(u):u(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,c,a,s,o]),i.useEffect(()=>{!r&&t.current&&(t.current.textContent=rt(a.current??0,c))}),w.jsx(dl,{ref:t,className:e,"aria-label":"Audio position",children:rt(a.current??0,c)})},hl=({className:e})=>{const{selectionStart:t,selectionEnd:n}=Me(),{setSelection:r}=fe();return w.jsx(Do,{selectionStart:t,selectionEnd:n,onSelectionChange:r,className:e})},ml=({className:e})=>{const{isAutomaticScroll:t}=Me(),{setAutomaticScroll:n}=fe();return w.jsx(qa,{checked:t,onChange:n,className:e})},pl=({className:e})=>{const{continuousPlay:t}=Me(),{setContinuousPlay:n}=fe();return w.jsx(Ns,{checked:t,onChange:n,className:e})},gl=({className:e})=>{const{linkEndpoints:t}=Me(),{setLinkEndpoints:n}=fe();return w.jsx(Gs,{checked:t,onChange:n,className:e})},bl=({className:e})=>{const{annotationsEditable:t}=Me(),{setAnnotationsEditable:n}=fe();return w.jsx(Os,{checked:t,onChange:n,className:e})},vl=({filename:e,className:t})=>{const{annotations:n}=Me();return w.jsx(Ks,{annotations:n,filename:e,className:t})},Cl=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:r,bitDepth:a=16,applyEffects:s=!0,effectsFunction:o,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:f})=>{const{tracks:x,trackStates:v}=be(),{exportWav:d,isExporting:C,progress:y}=Kr(),h=async()=>{try{const g=await d(x,v,{filename:t,mode:n,trackIndex:r,bitDepth:a,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(g.blob)}catch(g){f?.(g instanceof Error?g:new Error("Export failed"))}},b=C?`Exporting ${Math.round(y*100)}%`:e;return w.jsx($e,{onClick:h,disabled:C||x.length===0,className:c,children:b})},wl=S.div`
1200
1200
  position: absolute;
1201
1201
  top: 0;
1202
1202
  left: 0;
@@ -1206,9 +1206,9 @@
1206
1206
  z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
1207
1207
  pointer-events: none;
1208
1208
  will-change: transform;
1209
- `,ul=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),r=i.useRef(null),{isPlaying:a,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=ge(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:d}=me();return i.useEffect(()=>{const b=()=>{if(n.current){let g;if(a){const v=E.getContext().currentTime-(o.current??0);g=(l.current??0)+v}else g=s.current??0;const f=g*u/c+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}a&&(r.current=requestAnimationFrame(b))};return a?r.current=requestAnimationFrame(b):b(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[a,u,c,t,s,o,l]),i.useEffect(()=>{if(!a&&n.current){const g=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${g}px, 0, 0)`}}),x.jsx(cl,{ref:n,$color:e,$width:d,"data-playhead":!0})},dl=A.div`
1209
+ `,xl=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),r=i.useRef(null),{isPlaying:a,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=xe(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:f}=be();return i.useEffect(()=>{const x=()=>{if(n.current){let v;if(a){const C=W.getContext().currentTime-(o.current??0);v=(l.current??0)+C}else v=s.current??0;const d=v*u/c+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}a&&(r.current=requestAnimationFrame(x))};return a?r.current=requestAnimationFrame(x):x(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[a,u,c,t,s,o,l]),i.useEffect(()=>{if(!a&&n.current){const v=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${v}px, 0, 0)`}}),w.jsx(wl,{ref:n,$color:e,$width:f,"data-playhead":!0})},yl=S.div`
1210
1210
  position: relative;
1211
- `,fl=A.div`
1211
+ `,kl=S.div`
1212
1212
  position: absolute;
1213
1213
  top: ${e=>e.$top}px;
1214
1214
  left: 0;
@@ -1220,7 +1220,7 @@
1220
1220
  transform: translateZ(0);
1221
1221
  backface-visibility: hidden;
1222
1222
  will-change: transform;
1223
- `,hl=A.div`
1223
+ `,Il=S.div`
1224
1224
  position: absolute;
1225
1225
  top: ${e=>e.$top}px;
1226
1226
  left: 0;
@@ -1229,8 +1229,43 @@
1229
1229
  pointer-events: none;
1230
1230
  z-index: 1;
1231
1231
  will-change: width;
1232
- `,ml=A.div`
1232
+ `,Sl=S.div`
1233
1233
  position: relative;
1234
1234
  z-index: 2;
1235
- `,ar=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=i.useRef(null),a=i.useRef(null),s=rn(),{waveHeight:o}=It(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=ge(),{samplesPerPixel:b,sampleRate:g}=me(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const h=()=>{if(r.current){let w;if(l){const I=E.getContext().currentTime-(u.current??0);w=(d.current??0)+I}else w=c.current??0;const C=w*g,p=e+t;let S=0;if(C<=e)S=0;else if(C>=p)S=n.length;else{const I=C-e;S=Math.floor(I/b)}r.current.style.width=`${S}px`}l&&(a.current=requestAnimationFrame(h))};return l?a.current=requestAnimationFrame(h):h(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[l,g,b,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&r.current){const w=(c.current??0)*g,C=e+t;let p=0;if(w<=e)p=0;else if(w>=C)p=n.length;else{const S=w-e;p=Math.floor(S/b)}r.current.style.width=`${p}px`}});const v=s?.waveformDrawMode||"inverted";let y;v==="inverted"?y=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":y=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const m=gt(y);return x.jsxs(dl,{children:[x.jsx(fl,{$color:m,$height:o,$top:n.index*o,$width:n.length}),x.jsx(hl,{ref:r,$color:f,$height:o,$top:n.index*o}),x.jsx(ml,{children:x.jsx(wo,{...n,transparentBackground:!0})})]})},pl=60,gl=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,annotationListConfig:a,annotationTextHeight:s,className:o,showClipHeaders:l=!1,interactiveClips:c=!1,showFades:u=!1,touchOptimized:d=!1,recordingState:b})=>{const g=rn(),{isPlaying:f,currentTimeRef:v,playbackStartTimeRef:y,audioStartPositionRef:m}=ge(),{selectionStart:h,selectionEnd:w,annotations:C,activeAnnotationId:p,annotationsEditable:S,linkEndpoints:I,continuousPlay:k,selectedTrackId:R,loopStart:M,loopEnd:D,isLoopEnabled:$}=Ie(),{setAnnotations:T,setActiveAnnotationId:W,setTrackMute:H,setTrackSolo:P,setTrackVolume:j,setTrackPan:N,setSelection:Y,play:z,setScrollContainer:K,setSelectedTrackId:ne,setCurrentTime:te,setLoopRegion:U}=oe(),{audioBuffers:J,peaksDataArray:fe,trackStates:Pe,tracks:Xe,duration:kt,samplesPerPixel:se,sampleRate:ie,waveHeight:ot,timeScaleHeight:st,controls:q,playoutRef:Ge,barWidth:$t,barGap:Dt}=me(),[qe,F]=i.useState(!1),Se=i.useRef(null),ce=i.useCallback(V=>{Se.current=V,K(V)},[K]);let re=J.length>0?kt:pl;if(b?.isRecording){const L=(b.startSample+b.durationSamples)/ie;re=Math.max(re,L+10)}const De=Math.floor(re*ie/se),Me=async V=>{console.log("Annotation clicked:",V.id),W(V.id);const L=k?void 0:V.end-V.start;await z(V.start,L)},Ae=i.useCallback(V=>{if(V>=0&&V<Xe.length){const L=Xe[V];ne(L.id)}},[Xe,ne]),Fe=V=>{const L=V.currentTarget.getBoundingClientRect(),ee=q.show?q.width:0,pe=(V.clientX-L.left-ee)*se/ie,O=V.clientY-L.top;let Re=0,Be=-1;for(let _e=0;_e<fe.length;_e++){const Ce=fe[_e],Qe=(Ce.length>0?Math.max(...Ce.map(Rt=>Rt.peaks.data.length)):1)*ot+(l?22:0);if(O>=Re&&O<Re+Qe){Be=_e;break}Re+=Qe}Be!==-1&&Ae(Be),F(!0),te(pe),Y(pe,pe)},Ze=V=>{if(!qe)return;const L=V.currentTarget.getBoundingClientRect(),ee=q.show?q.width:0,pe=(V.clientX-L.left-ee)*se/ie,he=Math.min(h,pe),O=Math.max(h,pe);Y(he,O)},it=V=>{if(!qe)return;F(!1);const L=V.currentTarget.getBoundingClientRect(),ee=q.show?q.width:0,pe=(V.clientX-L.left-ee)*se/ie,he=Math.min(h,pe),O=Math.max(h,pe);Math.abs(O-he)<.1?(te(he),f&&Ge.current?(Ge.current.stop(),z(he)):Ge.current&&Ge.current.stop()):Y(he,O)};return Xe.some(V=>V.clips.length>0)&&(J.length===0||fe.length===0)?x.jsx("div",{className:o,children:"Loading waveform..."}):x.jsx(ho,{children:x.jsxs(nn.Provider,{value:{samplesPerPixel:se,sampleRate:ie,zoomLevels:[se],waveHeight:ot,timeScaleHeight:st,duration:re,controls:q,barWidth:$t,barGap:Dt},children:[x.jsx(Cr,{theme:g,backgroundColor:gt(g.waveOutlineColor),timescaleBackgroundColor:g.timescaleBackgroundColor,scrollContainerWidth:De+(q.show?q.width:0),timescaleWidth:De,tracksWidth:De,controlsWidth:q.show?q.width:0,onTracksMouseDown:Fe,onTracksMouseMove:Ze,onTracksMouseUp:it,scrollContainerRef:ce,isSelecting:qe,timescale:st>0?x.jsxs(x.Fragment,{children:[x.jsx($o,{duration:re*1e3,marker:1e4,bigStep:5e3,secondStep:1e3,renderTimestamp:t}),$&&x.jsx(uo,{startPosition:Math.min(M,D)*ie/se,endPosition:Math.max(M,D)*ie/se,markerColor:g.loopMarkerColor,regionColor:g.loopRegionColor,minPosition:0,maxPosition:De,controlsOffset:q.show?q.width:0,onLoopRegionChange:(V,L)=>{const ee=V*se/ie,ue=L*se/ie;U(ee,ue)}})]}):void 0,children:x.jsxs(x.Fragment,{children:[fe.map((V,L)=>{const ee=Xe[L];if(!ee)return null;const ue=Pe[L]||{name:`Track ${L+1}`,muted:!1,soloed:!1,volume:1,pan:0},pe=e?e(L):x.jsxs(Zo,{onClick:()=>Ae(L),children:[x.jsx(_o,{style:{justifyContent:"center"},children:ue.name||`Track ${L+1}`}),x.jsxs(Fo,{children:[x.jsx(Bn,{$variant:ue.muted?"danger":"outline",onClick:()=>H(L,!ue.muted),children:"Mute"}),x.jsx(Bn,{$variant:ue.soloed?"info":"outline",onClick:()=>P(L,!ue.soloed),children:"Solo"})]}),x.jsxs(Tn,{children:[x.jsx(Vo,{}),x.jsx(En,{min:"0",max:"1",step:"0.01",value:ue.volume,onChange:O=>j(L,parseFloat(O.target.value))}),x.jsx(zo,{})]}),x.jsxs(Tn,{children:[x.jsx("span",{children:"L"}),x.jsx(En,{min:"-1",max:"1",step:"0.01",value:ue.pan,onChange:O=>N(L,parseFloat(O.target.value))}),x.jsx("span",{children:"R"})]})]}),he=V.length>0?Math.max(...V.map(O=>O.peaks.data.length)):1;return x.jsx(Ir.Provider,{value:pe,children:x.jsxs(Wo,{numChannels:he,backgroundColor:gt(g.waveOutlineColor),offset:0,width:De,hasClipHeaders:l,trackId:ee.id,isSelected:ee.id===R,children:[V.map((O,Re)=>{const Be=O.peaks,_e=Be.length;return x.jsx(Dn,{clipId:O.clipId,trackIndex:L,clipIndex:Re,trackName:O.trackName,startSample:O.startSample,durationSamples:O.durationSamples,samplesPerPixel:se,showHeader:l,disableHeaderDrag:!c,isSelected:ee.id===R,trackId:ee.id,fadeIn:O.fadeIn,fadeOut:O.fadeOut,sampleRate:ie,showFades:u,touchOptimized:d,onMouseDown:Ce=>{Ce.target.closest('[role="button"][aria-roledescription="draggable"]')||Ae(L)},children:Be.data.map((Ce,we)=>x.jsx(ar,{index:we,data:Ce,bits:Be.bits,length:_e,isSelected:ee.id===R,clipStartSample:O.startSample,clipDurationSamples:O.durationSamples},`${L}-${Re}-${we}`))},`${L}-${Re}`)}),b?.isRecording&&b.trackId===ee.id&&b.peaks.length>0&&x.jsx(Dn,{clipId:"recording-preview",trackIndex:L,clipIndex:V.length,trackName:"Recording...",startSample:b.startSample,durationSamples:b.durationSamples,samplesPerPixel:se,showHeader:l,disableHeaderDrag:!0,isSelected:ee.id===R,trackId:ee.id,children:x.jsx(ar,{index:0,data:b.peaks,bits:16,length:Math.floor(b.peaks.length/2),isSelected:ee.id===R,clipStartSample:b.startSample,clipDurationSamples:b.durationSamples},`${L}-recording-0`)},`${L}-recording`)]})},ee.id)}),C.length>0&&x.jsx(As,{height:30,width:De,children:C.map((V,L)=>{const ee=V.start*ie/se,ue=V.end*ie/se;return x.jsx(xs,{annotationId:V.id,annotationIndex:L,startPosition:ee,endPosition:ue,label:V.id,color:"#ff9800",isActive:V.id===p,onClick:()=>Me(V),editable:S},V.id)})}),h!==w&&x.jsx(so,{startPosition:Math.min(h,w)*ie/se+(q.show?q.width:0),endPosition:Math.max(h,w)*ie/se+(q.show?q.width:0),color:g.selectionColor}),(f||h===w)&&(n?n({position:(v.current??0)*ie/se+(q.show?q.width:0),color:g.playheadColor,isPlaying:f,currentTimeRef:v,playbackStartTimeRef:y,audioStartPositionRef:m,samplesPerPixel:se,sampleRate:ie,controlsOffset:q.show?q.width:0,getAudioContextTime:()=>E.getContext().currentTime}):x.jsx(ul,{color:g.playheadColor,controlsOffset:q.show?q.width:0}))]})}),C.length>0&&x.jsx(Zs,{annotations:C,activeAnnotationId:p??void 0,shouldScrollToActive:!0,editable:S,controls:S?r:void 0,annotationListConfig:{linkEndpoints:I,continuousPlay:k},height:s,onAnnotationUpdate:V=>{T(V)}})]})})};exports.Tone=sr;exports.AudioPosition=tl;exports.AutomaticScrollCheckbox=rl;exports.ContinuousPlayCheckbox=al;exports.DownloadAnnotationsButton=il;exports.EditableCheckbox=sl;exports.ExportWavButton=ll;exports.FastForwardButton=Li;exports.LinkEndpointsCheckbox=ol;exports.LoopButton=Oi;exports.MasterVolumeControl=qi;exports.PauseButton=ji;exports.PlayButton=Hi;exports.RewindButton=Gi;exports.SelectionTimeInputs=nl;exports.SetLoopRegionButton=Ki;exports.SkipBackwardButton=Ni;exports.SkipForwardButton=Yi;exports.StopButton=Pi;exports.TimeFormatSelect=Qi;exports.Waveform=gl;exports.WaveformPlaylistProvider=zi;exports.ZoomInButton=Ui;exports.ZoomOutButton=Ji;exports.createEffectChain=Bi;exports.createEffectInstance=rt;exports.effectCategories=$i;exports.effectDefinitions=at;exports.getEffectDefinition=ln;exports.getEffectsByCategory=ki;exports.getShortcutLabel=ui;exports.getWaveformDataMetadata=is;exports.loadPeaksFromWaveformData=ss;exports.loadWaveformData=an;exports.useAnnotationDragHandlers=Os;exports.useAnnotationKeyboardControls=fi;exports.useAudioTracks=Ns;exports.useClipDragHandlers=Ys;exports.useClipSplitting=ci;exports.useDragSensors=li;exports.useDynamicEffects=Ei;exports.useExportWav=Fr;exports.useIntegratedRecording=Ai;exports.useKeyboardShortcuts=vt;exports.useMasterAnalyser=Ps;exports.useMasterVolume=Mr;exports.usePlaybackAnimation=ge;exports.usePlaybackShortcuts=di;exports.usePlaylistControls=oe;exports.usePlaylistData=me;exports.usePlaylistState=Ie;exports.useTimeFormat=$r;exports.useTrackDynamicEffects=Ti;exports.useWaveformPlaylist=Xi;exports.useZoomControls=Dr;exports.waveformDataToPeaks=kr;
1235
+ `,cr=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=i.useRef(null),a=i.useRef(null),s=dt(),{waveHeight:o}=ut(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:f}=xe(),{samplesPerPixel:x,sampleRate:v}=be(),d=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const b=()=>{if(r.current){let g;if(l){const k=W.getContext().currentTime-(u.current??0);g=(f.current??0)+k}else g=c.current??0;const m=g*v,p=e+t;let I=0;if(m<=e)I=0;else if(m>=p)I=n.length;else{const k=m-e;I=Math.floor(k/x)}r.current.style.width=`${I}px`}l&&(a.current=requestAnimationFrame(b))};return l?a.current=requestAnimationFrame(b):b(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[l,v,x,e,t,n.length,c,u,f]),i.useEffect(()=>{if(!l&&r.current){const g=(c.current??0)*v,m=e+t;let p=0;if(g<=e)p=0;else if(g>=m)p=n.length;else{const I=g-e;p=Math.floor(I/x)}r.current.style.width=`${p}px`}});const C=s?.waveformDrawMode||"inverted";let y;C==="inverted"?y=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":y=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const h=Oe(y);return w.jsxs(yl,{children:[w.jsx(kl,{$color:h,$height:o,$top:n.index*o,$width:n.length}),w.jsx(Il,{ref:r,$color:d,$height:o,$top:n.index*o}),w.jsx(Sl,{children:w.jsx(Rr,{...n,transparentBackground:!0})})]})},Al=60,$l=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,annotationListConfig:a,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,className:c,showClipHeaders:u=!1,interactiveClips:f=!1,showFades:x=!1,touchOptimized:v=!1,recordingState:d})=>{const C=dt(),{isPlaying:y,currentTimeRef:h,playbackStartTimeRef:b,audioStartPositionRef:g}=xe(),{selectionStart:m,selectionEnd:p,annotations:I,activeAnnotationId:k,annotationsEditable:A,linkEndpoints:R,continuousPlay:D,selectedTrackId:M,loopStart:$,loopEnd:E,isLoopEnabled:Z}=Me(),{setAnnotations:P,setActiveAnnotationId:F,setTrackMute:V,setTrackSolo:H,setTrackVolume:q,setTrackPan:z,setSelection:B,play:K,setScrollContainer:U,setSelectedTrackId:G,setCurrentTime:O,setLoopRegion:te}=fe(),{audioBuffers:ve,peaksDataArray:De,trackStates:Fe,tracks:Be,duration:Ke,samplesPerPixel:se,sampleRate:ie,waveHeight:Ue,timeScaleHeight:Je,controls:ne,playoutRef:Q,barWidth:ee,barGap:_}=be(),[le,ce]=i.useState(!1),pe=i.useRef(null),ht=i.useCallback(L=>{pe.current=L,U(L)},[U]);let ye=ve.length>0?Ke:Al;if(d?.isRecording){const J=(d.startSample+d.durationSamples)/ie;ye=Math.max(ye,J+10)}const Ce=Math.floor(ye*ie/se),ze=async L=>{console.log("Annotation clicked:",L.id),F(L.id);const J=D?void 0:L.end-L.start;await K(L.start,J)},We=i.useCallback(L=>{if(L>=0&&L<Be.length){const J=Be[L];G(J.id)}},[Be,G]),mt=L=>{const J=L.currentTarget.getBoundingClientRect(),oe=ne.show?ne.width:0,me=(L.clientX-J.left-oe)*se/ie,re=L.clientY-J.top;let _e=0,ke=-1;for(let we=0;we<De.length;we++){const je=De[we],ot=(je.length>0?Math.max(...je.map(Xe=>Xe.peaks.data.length)):1)*Ue+(u?22:0);if(re>=_e&&re<_e+ot){ke=we;break}_e+=ot}ke!==-1&&We(ke),ce(!0),O(me),B(me,me)},pt=L=>{if(!le)return;const J=L.currentTarget.getBoundingClientRect(),oe=ne.show?ne.width:0,me=(L.clientX-J.left-oe)*se/ie,Re=Math.min(m,me),re=Math.max(m,me);B(Re,re)},Ne=L=>{if(!le)return;ce(!1);const J=L.currentTarget.getBoundingClientRect(),oe=ne.show?ne.width:0,me=(L.clientX-J.left-oe)*se/ie,Re=Math.min(m,me),re=Math.max(m,me);Math.abs(re-Re)<.1?(O(Re),y&&Q.current?(Q.current.stop(),K(Re)):Q.current&&Q.current.stop()):B(Re,re)};return Be.some(L=>L.clips.length>0)&&(ve.length===0||De.length===0)?w.jsx("div",{className:c,children:"Loading waveform..."}):w.jsx(Mr,{children:w.jsxs(Et.Provider,{value:{samplesPerPixel:se,sampleRate:ie,zoomLevels:[se],waveHeight:Ue,timeScaleHeight:Je,duration:ye,controls:ne,barWidth:ee,barGap:_},children:[w.jsx(cn,{theme:C,backgroundColor:Oe(C.waveOutlineColor),timescaleBackgroundColor:C.timescaleBackgroundColor,scrollContainerWidth:Ce+(ne.show?ne.width:0),timescaleWidth:Ce,tracksWidth:Ce,controlsWidth:ne.show?ne.width:0,onTracksMouseDown:mt,onTracksMouseMove:pt,onTracksMouseUp:Ne,scrollContainerRef:ht,isSelecting:le,timescale:Je>0?w.jsxs(w.Fragment,{children:[w.jsx(Er,{duration:ye*1e3,marker:1e4,bigStep:5e3,secondStep:1e3,renderTimestamp:t}),Z&&w.jsx(Mo,{startPosition:Math.min($,E)*ie/se,endPosition:Math.max($,E)*ie/se,markerColor:C.loopMarkerColor,regionColor:C.loopRegionColor,minPosition:0,maxPosition:Ce,controlsOffset:ne.show?ne.width:0,onLoopRegionChange:(L,J)=>{const oe=L*se/ie,ue=J*se/ie;te(oe,ue)}})]}):void 0,children:w.jsxs(w.Fragment,{children:[De.map((L,J)=>{const oe=Be[J];if(!oe)return null;const ue=Fe[J]||{name:`Track ${J+1}`,muted:!1,soloed:!1,volume:1,pan:0},me=e?e(J):w.jsxs(Ko,{onClick:()=>We(J),children:[w.jsx(Uo,{style:{justifyContent:"center"},children:ue.name||`Track ${J+1}`}),w.jsxs(Yo,{children:[w.jsx(_n,{$variant:ue.muted?"danger":"outline",onClick:()=>V(J,!ue.muted),children:"Mute"}),w.jsx(_n,{$variant:ue.soloed?"info":"outline",onClick:()=>H(J,!ue.soloed),children:"Solo"})]}),w.jsxs(Pn,{children:[w.jsx(Jo,{}),w.jsx(Zn,{min:"0",max:"1",step:"0.01",value:ue.volume,onChange:re=>q(J,parseFloat(re.target.value))}),w.jsx(qo,{})]}),w.jsxs(Pn,{children:[w.jsx("span",{children:"L"}),w.jsx(Zn,{min:"-1",max:"1",step:"0.01",value:ue.pan,onChange:re=>z(J,parseFloat(re.target.value))}),w.jsx("span",{children:"R"})]})]}),Re=L.length>0?Math.max(...L.map(re=>re.peaks.data.length)):1;return w.jsx(un.Provider,{value:me,children:w.jsxs(Tr,{numChannels:Re,backgroundColor:Oe(C.waveOutlineColor),offset:0,width:Ce,hasClipHeaders:u,trackId:oe.id,isSelected:oe.id===M,children:[L.map((re,_e)=>{const ke=re.peaks,we=ke.length;return w.jsx(Jt,{clipId:re.clipId,trackIndex:J,clipIndex:_e,trackName:re.trackName,startSample:re.startSample,durationSamples:re.durationSamples,samplesPerPixel:se,showHeader:u,disableHeaderDrag:!f,isSelected:oe.id===M,trackId:oe.id,fadeIn:re.fadeIn,fadeOut:re.fadeOut,sampleRate:ie,showFades:x,touchOptimized:v,onMouseDown:je=>{je.target.closest('[role="button"][aria-roledescription="draggable"]')||We(J)},children:ke.data.map((je,qe)=>w.jsx(cr,{index:qe,data:je,bits:ke.bits,length:we,isSelected:oe.id===M,clipStartSample:re.startSample,clipDurationSamples:re.durationSamples},`${J}-${_e}-${qe}`))},`${J}-${_e}`)}),d?.isRecording&&d.trackId===oe.id&&d.peaks.length>0&&w.jsx(Jt,{clipId:"recording-preview",trackIndex:J,clipIndex:L.length,trackName:"Recording...",startSample:d.startSample,durationSamples:d.durationSamples,samplesPerPixel:se,showHeader:u,disableHeaderDrag:!0,isSelected:oe.id===M,trackId:oe.id,children:w.jsx(cr,{index:0,data:d.peaks,bits:16,length:Math.floor(d.peaks.length/2),isSelected:oe.id===M,clipStartSample:d.startSample,clipDurationSamples:d.durationSamples},`${J}-recording-0`)},`${J}-recording`)]})},oe.id)}),I.length>0&&w.jsx(Vr,{height:30,width:Ce,children:I.map((L,J)=>{const oe=L.start*ie/se,ue=L.end*ie/se,me=l?l(L):L.id;return w.jsx(Pr,{annotationId:L.id,annotationIndex:J,startPosition:oe,endPosition:ue,label:me,color:"#ff9800",isActive:L.id===k,onClick:()=>ze(L),editable:A},L.id)})}),m!==p&&w.jsx(Sr,{startPosition:Math.min(m,p)*ie/se+(ne.show?ne.width:0),endPosition:Math.max(m,p)*ie/se+(ne.show?ne.width:0),color:C.selectionColor}),(y||m===p)&&(n?n({position:(h.current??0)*ie/se+(ne.show?ne.width:0),color:C.playheadColor,isPlaying:y,currentTimeRef:h,playbackStartTimeRef:b,audioStartPositionRef:g,samplesPerPixel:se,sampleRate:ie,controlsOffset:ne.show?ne.width:0,getAudioContextTime:()=>W.getContext().currentTime}):w.jsx(xl,{color:C.playheadColor,controlsOffset:ne.show?ne.width:0}))]})}),I.length>0&&w.jsx(zr,{annotations:I,activeAnnotationId:k??void 0,shouldScrollToActive:!0,editable:A,controls:A?r:void 0,annotationListConfig:{linkEndpoints:R,continuousPlay:D},height:s,renderAnnotationItem:o,onAnnotationUpdate:L=>{P(L)}})]})})},Ml=S.div`
1236
+ position: absolute;
1237
+ top: 0;
1238
+ left: 0;
1239
+ width: ${e=>e.$width}px;
1240
+ background: ${e=>e.$color};
1241
+ height: 100%;
1242
+ z-index: 100;
1243
+ pointer-events: none;
1244
+ will-change: transform;
1245
+ `,Dl=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),r=i.useRef(null),{isPlaying:a,currentTimeRef:s}=Wt(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=Ft();return i.useEffect(()=>{const u=()=>{if(n.current){const x=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${x}px, 0, 0)`}a&&(r.current=requestAnimationFrame(u))};return a?r.current=requestAnimationFrame(u):u(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[a,l,o,t,s]),i.useEffect(()=>{if(!a&&n.current){const f=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}}),w.jsx(Ml,{ref:n,$color:e,$width:c,"data-playhead":!0})},Rl=S.div`
1246
+ position: relative;
1247
+ `,El=S.div`
1248
+ position: absolute;
1249
+ top: ${e=>e.$top}px;
1250
+ left: 0;
1251
+ width: ${e=>e.$width}px;
1252
+ height: ${e=>e.$height}px;
1253
+ background: ${e=>e.$color};
1254
+ z-index: 0;
1255
+ transform: translateZ(0);
1256
+ backface-visibility: hidden;
1257
+ will-change: transform;
1258
+ `,Tl=S.div`
1259
+ position: absolute;
1260
+ top: ${e=>e.$top}px;
1261
+ left: 0;
1262
+ height: ${e=>e.$height}px;
1263
+ background: ${e=>e.$color};
1264
+ pointer-events: none;
1265
+ z-index: 1;
1266
+ will-change: width;
1267
+ `,Bl=S.div`
1268
+ position: relative;
1269
+ z-index: 2;
1270
+ `,Wl=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=i.useRef(null),a=i.useRef(null),s=dt(),{waveHeight:o}=ut(),{isPlaying:l,currentTimeRef:c}=Wt(),{samplesPerPixel:u,sampleRate:f}=Ft(),x=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const y=()=>{if(r.current){const b=(c.current??0)*f,g=e+t;let m=0;if(b<=e)m=0;else if(b>=g)m=n.length;else{const p=b-e;m=Math.floor(p/u)}r.current.style.width=`${m}px`}l&&(a.current=requestAnimationFrame(y))};return l?a.current=requestAnimationFrame(y):y(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[l,f,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&r.current){const h=(c.current??0)*f,b=e+t;let g=0;if(h<=e)g=0;else if(h>=b)g=n.length;else{const m=h-e;g=Math.floor(m/u)}r.current.style.width=`${g}px`}});const v=s?.waveformDrawMode||"inverted";let d;v==="inverted"?d=s?.selectedWaveFillColor||s?.waveFillColor||"white":d=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const C=Oe(d);return w.jsxs(Rl,{children:[w.jsx(El,{$color:C,$height:o,$top:n.index*o,$width:n.length}),w.jsx(Tl,{ref:r,$color:x,$height:o,$top:n.index*o}),w.jsx(Bl,{children:w.jsx(Rr,{...n,isSelected:!0,transparentBackground:!0})})]})},Fl=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,className:r})=>{const a=dt(),{isPlaying:s,currentTimeRef:o}=Wt(),{annotations:l,activeAnnotationId:c,continuousPlay:u}=oa(),{play:f,seekTo:x,setActiveAnnotationId:v}=sa(),{duration:d,peaksDataArray:C,sampleRate:y,waveHeight:h,timeScaleHeight:b,samplesPerPixel:g,controls:m,playoutRef:p,barWidth:I,barGap:k}=Ft(),[A,R]=i.useState(0),[D,M]=i.useState(0),[$,E]=i.useState(!1),Z=i.useRef(null),P=Math.floor(d*y/g),F=i.useCallback(async B=>{v(B.id),f(B.start)},[v,f]),V=i.useCallback(B=>{const K=B.currentTarget.getBoundingClientRect(),U=m.show?m.width:0,O=(B.clientX-K.left-U)*g/y;E(!0),R(O),M(O)},[m,g,y]),H=i.useCallback(B=>{if(!$)return;const K=B.currentTarget.getBoundingClientRect(),U=m.show?m.width:0,O=(B.clientX-K.left-U)*g/y;M(O)},[$,m,g,y]),q=i.useCallback(B=>{if(!$)return;E(!1);const K=B.currentTarget.getBoundingClientRect(),U=m.show?m.width:0,O=(B.clientX-K.left-U)*g/y,te=Math.min(A,O),ve=Math.max(A,O);Math.abs(ve-te)<.1?(x(te),R(te),M(te),s&&p.current&&(p.current.stop(),f(te))):(R(te),M(ve))},[$,A,g,y,m,x,s,p,f]);if(C.length===0)return w.jsx("div",{className:r,children:"Loading waveform..."});const z=null;return w.jsx(Mr,{children:w.jsxs(Et.Provider,{value:{samplesPerPixel:g,sampleRate:y,zoomLevels:[g],waveHeight:h,timeScaleHeight:b,duration:d,controls:m,barWidth:I,barGap:k},children:[w.jsx(cn,{theme:a,backgroundColor:Oe(a.waveOutlineColor),timescaleBackgroundColor:a.timescaleBackgroundColor,scrollContainerWidth:P+(m.show?m.width:0),timescaleWidth:P,tracksWidth:P,controlsWidth:m.show?m.width:0,onTracksMouseDown:V,onTracksMouseMove:H,onTracksMouseUp:q,scrollContainerRef:B=>{Z.current=B},isSelecting:$,timescale:b>0?w.jsx(Er,{duration:d*1e3,marker:1e4,bigStep:5e3,secondStep:1e3}):void 0,children:w.jsxs(w.Fragment,{children:[C.map((B,K)=>{const U=B.length>0?Math.max(...B.map(G=>G.peaks.data.length)):1;return w.jsx(un.Provider,{value:z,children:w.jsx(Tr,{numChannels:U,backgroundColor:Oe(a.waveOutlineColor),offset:0,width:P,hasClipHeaders:!1,trackId:`media-element-track-${K}`,isSelected:!0,children:B.map((G,O)=>{const te=G.peaks,ve=te.length;return w.jsx(Jt,{clipId:G.clipId,trackIndex:K,clipIndex:O,trackName:G.trackName,startSample:G.startSample,durationSamples:G.durationSamples,samplesPerPixel:g,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${K}`,children:te.data.map((De,Fe)=>w.jsx(Wl,{index:Fe,data:De,bits:te.bits,length:ve,clipStartSample:G.startSample,clipDurationSamples:G.durationSamples},`${K}-${O}-${Fe}`))},`${K}-${O}`)})})},K)}),l.length>0&&w.jsx(Vr,{height:30,width:P,children:l.map((B,K)=>{const U=B.start*y/g,G=B.end*y/g,O=t?t(B):B.id;return w.jsx(Pr,{annotationId:B.id,annotationIndex:K,startPosition:U,endPosition:G,label:O,color:"#ff9800",isActive:B.id===c,onClick:()=>F(B),editable:!1},B.id)})}),A!==D&&w.jsx(Sr,{startPosition:Math.min(A,D)*y/g+(m.show?m.width:0),endPosition:Math.max(A,D)*y/g+(m.show?m.width:0),color:a.selectionColor}),w.jsx(Dl,{color:a.playheadColor,controlsOffset:m.show?m.width:0})]})}),l.length>0&&w.jsx(zr,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,editable:!1,annotationListConfig:{linkEndpoints:!1,continuousPlay:u},height:e,onAnnotationUpdate:()=>{},renderAnnotationItem:n})]})})};exports.Tone=dr;exports.AudioPosition=fl;exports.AutomaticScrollCheckbox=ml;exports.ContinuousPlayCheckbox=pl;exports.DownloadAnnotationsButton=vl;exports.EditableCheckbox=bl;exports.ExportWavButton=Cl;exports.FastForwardButton=nl;exports.LinkEndpointsCheckbox=gl;exports.LoopButton=ol;exports.MasterVolumeControl=cl;exports.MediaElementPlaylistProvider=Ji;exports.MediaElementWaveform=Fl;exports.PauseButton=Qi;exports.PlayButton=qi;exports.RewindButton=tl;exports.SelectionTimeInputs=hl;exports.SetLoopRegionButton=sl;exports.SkipBackwardButton=rl;exports.SkipForwardButton=al;exports.StopButton=el;exports.TimeFormatSelect=ul;exports.Waveform=$l;exports.WaveformPlaylistProvider=Oi;exports.ZoomInButton=il;exports.ZoomOutButton=ll;exports.createEffectChain=Vi;exports.createEffectInstance=ct;exports.effectCategories=Fi;exports.effectDefinitions=ft;exports.getEffectDefinition=mn;exports.getEffectsByCategory=Wi;exports.getShortcutLabel=vi;exports.getWaveformDataMetadata=ws;exports.loadPeaksFromWaveformData=Cs;exports.loadWaveformData=dn;exports.useAnnotationDragHandlers=ni;exports.useAnnotationKeyboardControls=wi;exports.useAudioTracks=ei;exports.useClipDragHandlers=ti;exports.useClipSplitting=bi;exports.useDragSensors=gi;exports.useDynamicEffects=zi;exports.useExportWav=Kr;exports.useIntegratedRecording=Bi;exports.useKeyboardShortcuts=At;exports.useMasterAnalyser=Js;exports.useMasterVolume=Hr;exports.useMediaElementAnimation=Wt;exports.useMediaElementControls=sa;exports.useMediaElementData=Ft;exports.useMediaElementState=oa;exports.usePlaybackAnimation=xe;exports.usePlaybackShortcuts=Ci;exports.usePlaylistControls=fe;exports.usePlaylistData=be;exports.usePlaylistState=Me;exports.useTimeFormat=jr;exports.useTrackDynamicEffects=ji;exports.useWaveformPlaylist=Yi;exports.useZoomControls=Xr;exports.waveformDataToPeaks=Fr;
1236
1271
  //# sourceMappingURL=index.js.map