@waveform-playlist/browser 5.0.0-alpha.13 → 5.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +156 -0
- package/dist/index.js +126 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3251 -3175
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var ia=Object.create;var pn=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&&pn(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?pn(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 Wt=typeof document<"u"?document.currentScript:null;function sr(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 ir=sr(E),X=sr(i);function gn(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 lr(e,t,n){switch(e){case"linear":return gn(t,n);case"exponential":return ma(t,n);case"sCurve":return pa(t,n);case"logarithmic":return ga(t,n);default:return gn(t,n)}}function bn(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=lr(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 vn(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=lr(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)bn(s,t,l,r.fadeIn.type||"linear",0,r.gain);else{const c=l-o,u=o/l,f=r.gain*u;bn(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;vn(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,C=u/r.fadeOut.duration,p=r.gain*(1-C);vn(s,t,f,r.fadeOut.type||"linear",p,0)}}}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e,this.muteGain.gain.value=e?0:1}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(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 f=o-l+s.offset,C=s.duration-(o-l),p=n?Math.min(n,C):C;r.pausedPosition=f,this.scheduleFades(r,u,f),a.start(u,f,p)}else{const f=l-o,C=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,C)):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}},mt=null;function Ca(){return mt||(mt=new E.Context,E.setContext(mt)),mt}async function Ft(){const e=Ca();e.state!=="running"&&await e.resume()}const wa=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",yt=wa?i.useLayoutEffect:i.useEffect;function xa(e){const t=i.useRef(e);return yt(()=>{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 cr(e,t){t===void 0&&(t=[e]);const n=i.useRef(e);return yt(()=>{n.current!==e&&(n.current=e)},t),n}function vt(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 Zt={};function ur(e,t){return i.useMemo(()=>{const n=Zt[e]==null?0:Zt[e]+1;return Zt[e]=n,e+"-"+n},[e,t])}const Gt=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[Gt.Translate.toString(e),Gt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}});var Cn;(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"})(Cn||(Cn={}));function wn(){}const ya=Object.freeze({x:0,y:0});var Oe;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Oe||(Oe={}));var xn;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(xn||(xn={}));var _e;(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"})(_e||(_e={}));_e.Space,_e.Enter,_e.Esc,_e.Space,_e.Enter,_e.Tab;var yn;(function(e){e[e.RightClick=2]="RightClick"})(yn||(yn={}));var In;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(In||(In={}));var Sn;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Sn||(Sn={}));Oe.Backward+"",Oe.Forward+"",Oe.Backward+"",Oe.Forward+"";var Lt;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Lt||(Lt={}));var Nt;(function(e){e.Optimized="optimized"})(Nt||(Nt={}));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])}Lt.WhileDragging,Nt.Optimized;const Sa={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:wn,draggableNodes:new Map,over:null,measureDroppableContainers:wn},Aa=i.createContext(Sa),ka=i.createContext({...ya,scaleX:1,scaleY:1});var An;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(An||(An={}));const $a=i.createContext(null),kn="button",Da="Draggable";function _t(e){let{id:t,data:n,disabled:r=!1,attributes:a}=e;const s=ur(Da),{activators:o,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:f,draggableNodes:C,over:p}=i.useContext(Aa),{role:d=kn,roleDescription:g="draggable",tabIndex:I=0}=a??{},h=c?.id===t,b=i.useContext(h?ka:$a),[w,v]=vt(),[m,S]=vt(),y=Ia(o,t),k=cr(n);yt(()=>(C.set(t,{id:t,key:s,node:w,activatorNode:m,data:k}),()=>{const M=C.get(t);M&&M.key===s&&C.delete(t)}),[C,t]);const R=i.useMemo(()=>({role:d,tabIndex:I,"aria-disabled":r,"aria-pressed":h&&d===kn?!0:void 0,"aria-roledescription":g,"aria-describedby":f.draggable}),[r,d,I,h,g,f.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:R,isDragging:h,listeners:r?void 0:y,node:w,over:p,setNodeRef:v,setActivatorNodeRef:S,transform:b}}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}),en=X.forwardRef((e,t)=>{const{alt:n,color:r,size:a,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:f="currentColor",size:C,weight:p="regular",mirrored:d=!1,...g}=X.useContext(Ba);return X.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:a??C,height:a??C,fill:r??f,viewBox:"0 0 256 256",transform:o||d?"scale(-1, 1)":void 0,...g,...u},!!n&&X.createElement("title",null,n),l,c.get(s??p))});en.displayName="IconBase";const dr=X.forwardRef((e,t)=>X.createElement(en,{ref:t,...e,weights:Ma}));dr.displayName="SpeakerHighIcon";const fr=X.forwardRef((e,t)=>X.createElement(en,{ref:t,...e,weights:Ra}));fr.displayName="SpeakerLowIcon";A.span`
|
|
1
|
+
"use strict";var Ia=Object.create;var Yt=Object.defineProperty;var Aa=Object.getOwnPropertyDescriptor;var Sa=Object.getOwnPropertyNames;var $a=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var Ra=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Sa(t))!Ma.call(e,r)&&r!==n&&Yt(e,r,{get:()=>t[r],enumerable:!(a=Aa(t,r))||a.enumerable});return e};var Ea=(e,t,n)=>(n=e!=null?Ia($a(e)):{},Ra(t||!e||!e.__esModule?Yt(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("tone"),v=require("react/jsx-runtime"),i=require("react"),A=require("styled-components"),Re=require("@dnd-kit/core"),Da=require("@dnd-kit/modifiers");var Mt=typeof document<"u"?document.currentScript:null;function mn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const hn=mn(W),G=mn(i);function Ot(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const s=r/a;n[r]=t?s:1-s}return n}function Ba(e,t){const n=new Float32Array(e),a=e-1;for(let r=0;r<e;r++){const s=r/a,o=t?r:e-1-r;n[o]=Math.exp(2*s-1)/Math.E}return n}function Ta(e,t){const n=new Float32Array(e),a=t?Math.PI/2:-Math.PI/2;for(let r=0;r<e;r++)n[r]=Math.sin(Math.PI*r/e-a)/2+.5;return n}function Wa(e,t,n=10){const a=new Float32Array(e);for(let r=0;r<e;r++){const s=t?r:e-1-r,o=r/e;a[s]=Math.log(1+n*o)/Math.log(1+n)}return a}function pn(e,t,n){switch(e){case"linear":return Ot(t,n);case"exponential":return Ba(t,n);case"sCurve":return Ta(t,n);case"logarithmic":return Wa(t,n);default:return Ot(t,n)}}function Kt(e,t,n,a="linear",r=0,s=1){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=pn(a,1e4,!0),l=new Float32Array(o.length),c=s-r;for(let u=0;u<o.length;u++)l[u]=r+o[u]*c;e.setValueCurveAtTime(l,t,n)}}function Ut(e,t,n,a="linear",r=1,s=0){if(!(n<=0))if(a==="linear")e.setValueAtTime(r,t),e.linearRampToValueAtTime(s,t+n);else if(a==="exponential")e.setValueAtTime(Math.max(r,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=pn(a,1e4,!1),l=new Float32Array(o.length),c=r-s;for(let u=0;u<o.length;u++)l[u]=s+o[u]*c;e.setValueCurveAtTime(l,t,n)}}var _a=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new W.Volume(this.gainToDb(e.track.gain)),this.panNode=new W.Panner(e.track.stereoPan),this.muteGain=new W.Gain(e.track.muted?0:1);const t=e.destination||W.getDestination();if(e.effects){const a=e.effects(this.muteGain,t,!1);a&&(this.effectsCleanup=a)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]);this.clips=n.map(a=>{const r=new W.Player({url:a.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new W.Gain(a.gain);return r.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:r,clipInfo:a,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:a,fadeGain:r}=e,s=r.gain._param;s.cancelScheduledValues(0);const o=n-a.offset;if(a.fadeIn&&o<a.fadeIn.duration){const l=a.fadeIn.duration;if(o<=0)Kt(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-o,u=o/l,f=a.gain*u;Kt(s,t,c,a.fadeIn.type||"linear",f,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-o;if(c>0){const u=t+c;Ut(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,f=a.fadeOut.duration-u,w=u/a.fadeOut.duration,g=a.gain*(1-w);Ut(s,t,f,a.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(a=>{a.player.stop(),a.player.disconnect(),a.player.dispose();const r=new W.Player({url:a.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});r.connect(a.fadeGain),a.player=r,a.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(a=>{const{player:r,clipInfo:s}=a,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??W.now();if(a.playStartTime=u,o>=l){const f=o-l+s.offset,w=s.duration-(o-l),g=n?Math.min(n,w):w;a.pausedPosition=f,this.scheduleFades(a,u,f),r.start(u,f,g)}else{const f=l-o,w=n?Math.min(n-f,s.duration):s.duration;f<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+f,s.offset),r.start(u+f,s.offset,w)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(W.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??W.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},Fa=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this.activeTracks=new Map,this.playbackSessionId=0,this.masterVolume=new W.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,W.getDestination(),!1);t&&(this.effectsCleanup=t)}else this.masterVolume.toDestination();e.tracks&&e.tracks.forEach(t=>{this.tracks.set(t.id,t),this.manualMuteState.set(t.id,t.muted)})}gainToDb(e){return 20*Math.log10(e)}async init(){this.isInitialized||(await W.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new _a(t);return this.tracks.set(n.id,n),this.manualMuteState.set(n.id,e.track.muted??!1),e.track.soloed&&this.soloedTracks.add(n.id),n}applyInitialSoloState(){this.updateSoloMuting()}removeTrack(e){const t=this.tracks.get(e);t&&(t.dispose(),this.tracks.delete(e),this.manualMuteState.delete(e),this.soloedTracks.delete(e))}getTrack(e){return this.tracks.get(e)}play(e,t,n){if(!this.isInitialized){console.warn("TonePlayout not initialized. Call init() first.");return}const a=e??W.now(),r=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(r>=l){const c=r-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a,c,n)}else{const c=l-r;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(a+c,0,n)}}),t!==void 0?W.getTransport().start(a,t):W.getTransport().start(a)}pause(){W.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){W.getTransport().stop(),this.tracks.forEach(e=>{e.stop()})}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const a=this.manualMuteState.get(n)??!1;t.setMute(a)}else{const a=this.manualMuteState.get(n)??!1;t.setMute(a)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return W.getTransport().seconds}seekTo(e){W.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return W.getContext()}get sampleRate(){return W.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},mt=null;function Za(){return mt||(mt=new W.Context,W.setContext(mt)),mt}async function Rt(){const e=Za();e.state!=="running"&&await e.resume()}const Bt=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[Bt.Translate.toString(e),Bt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),Va=new Map([["bold",G.createElement(G.Fragment,null,G.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",G.createElement(G.Fragment,null,G.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),G.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",G.createElement(G.Fragment,null,G.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",G.createElement(G.Fragment,null,G.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",G.createElement(G.Fragment,null,G.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",G.createElement(G.Fragment,null,G.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),Pa=new Map([["bold",G.createElement(G.Fragment,null,G.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",G.createElement(G.Fragment,null,G.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),G.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",G.createElement(G.Fragment,null,G.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",G.createElement(G.Fragment,null,G.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",G.createElement(G.Fragment,null,G.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",G.createElement(G.Fragment,null,G.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),za=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),_t=G.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:f="currentColor",size:w,weight:g="regular",mirrored:d=!1,...x}=G.useContext(za);return G.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??w,height:r??w,fill:a??f,viewBox:"0 0 256 256",transform:o||d?"scale(-1, 1)":void 0,...x,...u},!!n&&G.createElement("title",null,n),l,c.get(s??g))});_t.displayName="IconBase";const gn=G.forwardRef((e,t)=>G.createElement(_t,{ref:t,...e,weights:Va}));gn.displayName="SpeakerHighIcon";const bn=G.forwardRef((e,t)=>G.createElement(_t,{ref:t,...e,weights:Pa}));bn.displayName="SpeakerLowIcon";A.span`
|
|
2
2
|
font-family: 'Courier New', Monaco, monospace;
|
|
3
3
|
font-size: 1rem;
|
|
4
4
|
font-weight: 600;
|
|
5
5
|
color: ${e=>e.theme?.textColor||"#333"};
|
|
6
6
|
user-select: none;
|
|
7
|
-
`;var
|
|
7
|
+
`;var Ft=A.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(
|
|
36
|
+
`;A(Ft)`
|
|
37
37
|
padding: 0.25rem 0.5rem;
|
|
38
38
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
39
|
-
`;A(
|
|
39
|
+
`;A(Ft)`
|
|
40
40
|
padding: 0.5rem;
|
|
41
41
|
min-width: 2.25rem;
|
|
42
42
|
min-height: 2.25rem;
|
|
43
|
-
`;A(
|
|
43
|
+
`;A(Ft)`
|
|
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
|
|
48
|
+
`;var Ct=A.div`
|
|
49
49
|
display: inline-flex;
|
|
50
50
|
align-items: center;
|
|
51
51
|
gap: 0.5rem;
|
|
52
|
-
`,
|
|
52
|
+
`,xt=A.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
|
-
`,
|
|
59
|
+
`,wt=A.label`
|
|
60
60
|
margin: 0;
|
|
61
61
|
cursor: pointer;
|
|
62
62
|
user-select: none;
|
|
63
63
|
font-family: ${e=>e.theme.fontFamily};
|
|
64
64
|
font-size: ${e=>e.theme.fontSize};
|
|
65
65
|
color: ${e=>e.theme.textColor};
|
|
66
|
-
`,
|
|
66
|
+
`,Be=A.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
|
-
`,
|
|
92
|
+
`,vn=A.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,10 +113,10 @@
|
|
|
113
113
|
opacity: 0.6;
|
|
114
114
|
cursor: not-allowed;
|
|
115
115
|
}
|
|
116
|
-
`;A(
|
|
116
|
+
`;A(vn)`
|
|
117
117
|
padding: 0.25rem 0.5rem;
|
|
118
118
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
119
|
-
`;var
|
|
119
|
+
`;var Cn=A.label`
|
|
120
120
|
font-family: ${e=>e.theme.fontFamily};
|
|
121
121
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
122
122
|
font-weight: 500;
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
align-items: center;
|
|
132
132
|
gap: 0.5rem;
|
|
133
133
|
cursor: pointer;
|
|
134
|
-
`;var
|
|
134
|
+
`;var ja=A.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
|
-
`,
|
|
144
|
+
`,Zt=A.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(
|
|
175
|
+
`;A(Zt)`
|
|
176
176
|
padding: 0.25rem 1.75rem 0.25rem 0.5rem;
|
|
177
177
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
178
|
-
`;var
|
|
178
|
+
`;var xn=A.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
|
-
`,
|
|
254
|
+
`,Ha=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return v.jsxs(Ct,{className:a,children:[v.jsx(xt,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:r,disabled:n}),v.jsx(wt,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function wn(e){return typeof e=="object"&&e!==null&&"type"in e}function Ye(e){if(!wn(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(a=>`${a.color} ${a.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var yn={waveformDrawMode:"inverted",waveOutlineColor:"#ffffff",waveFillColor:"#1a7f8e",waveProgressColor:"rgba(0, 0, 0, 0.10)",selectedWaveOutlineColor:"#ffffff",selectedWaveFillColor:"#00b4d8",selectedTrackControlsBackground:"#d9e9ff",timeColor:"#000",timescaleBackgroundColor:"#fff",playheadColor:"#f00",selectionColor:"rgba(255, 105, 180, 0.7)",loopRegionColor:"rgba(59, 130, 246, 0.3)",loopMarkerColor:"#3b82f6",clipHeaderBackgroundColor:"rgba(0, 0, 0, 0.1)",clipHeaderBorderColor:"rgba(0, 0, 0, 0.2)",clipHeaderTextColor:"#333",clipHeaderFontFamily:"inherit",selectedClipHeaderBackgroundColor:"#b3d9ff",fadeOverlayColor:"rgba(0, 0, 0, 0.4)",backgroundColor:"#ffffff",surfaceColor:"#f5f5f5",borderColor:"#ddd",textColor:"#333",textColorMuted:"#666",inputBackground:"#ffffff",inputBorder:"#ccc",inputText:"#333",inputPlaceholder:"#999",inputFocusBorder:"#0066cc",buttonBackground:"#0091ff",buttonText:"#ffffff",buttonBorder:"#0081e6",buttonHoverBackground:"#0081e6",sliderTrackColor:"#ddd",sliderThumbColor:"#daa520",annotationBoxBackground:"rgba(255, 255, 255, 0.85)",annotationBoxActiveBackground:"rgba(255, 255, 255, 0.95)",annotationBoxHoverBackground:"rgba(255, 255, 255, 0.98)",annotationBoxBorder:"#ff9800",annotationBoxActiveBorder:"#d67600",annotationLabelColor:"#2a2a2a",annotationResizeHandleColor:"rgba(0, 0, 0, 0.4)",annotationResizeHandleActiveColor:"rgba(0, 0, 0, 0.8)",annotationTextItemHoverBackground:"rgba(0, 0, 0, 0.03)",borderRadius:"4px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif',fontSize:"14px",fontSizeSmall:"12px"},Xa=1e3;function Ga(e,t,n,a){if(!wn(t))return t;let r;t.direction==="vertical"?r=e.createLinearGradient(0,0,0,a):r=e.createLinearGradient(0,0,n,0);for(const s of t.stops)r.addColorStop(s.offset,s.color);return r}var Na=A.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
|
-
`,
|
|
262
|
+
`,La=A.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
|
-
`,
|
|
268
|
+
`,Ya=e=>{const{data:t,bits:n,length:a,index:r,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:f=1,barGap:w=0,transparentBackground:g=!1,drawMode:d="inverted"}=e,x=i.useRef([]),I=i.useCallback(k=>{if(k!==null){const y=parseInt(k.dataset.index,10);x.current[y]=k}},[]);i.useLayoutEffect(()=>{const k=x.current,y=f+w;let S=0;for(let R=0;R<k.length;R++){const E=k[R],$=E.getContext("2d"),M=Math.floor(l/2),D=2**(n-1);if($){$.resetTransform(),$.clearRect(0,0,E.width,E.height),$.imageSmoothingEnabled=!1,$.scale(o,o);const _=E.width/o;let Z;d==="normal"?Z=u:Z=c,$.fillStyle=Ga($,Z,_,l);const T=S,P=S+_,j=Math.floor((T-f+y)/y)*y;for(let U=Math.max(0,j);U<P;U+=y){const V=U-T;if(V+f<=0)continue;const L=U;if(L*2+1<t.length){const re=t[L*2]/D,te=t[L*2+1]/D,Q=Math.abs(re*M),q=Math.abs(te*M);d==="normal"?$.fillRect(V,M-q,f,q+Q):($.fillRect(V,0,f,M-q),$.fillRect(V,M+Q,f,M-Q))}}}S+=E.width/o}},[t,n,l,c,u,o,a,f,w,d]);let m=a,b=0;const p=[];for(;m>0;){const k=Math.min(m,Xa),y=v.jsx(Na,{$cssWidth:k,width:k*o,height:l*o,$waveHeight:l,"data-index":b,ref:I},`${a}-${b}`);p.push(y),m-=k,b+=1}const h=g?"transparent":Ye(u);return v.jsx(La,{$index:r,$cssWidth:a,className:s,$waveHeight:l,$waveFillColor:h,children:p})},kn=22,In=A.div`
|
|
269
269
|
position: relative;
|
|
270
|
-
height: ${
|
|
270
|
+
height: ${kn}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
|
-
`,
|
|
292
|
+
`,An=A.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
|
-
`,
|
|
300
|
+
`,Oa=({trackName:e,isSelected:t=!1})=>v.jsx(In,{$isDragging:!1,$interactive:!1,$isSelected:t,children:v.jsx(An,{children:e})}),Ka=({clipId:e,trackIndex:t,clipIndex:n,trackName:a,isSelected:r=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return v.jsx(Oa,{trackName:a,isSelected:r});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return v.jsx(In,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:r,...c,...l,children:v.jsx(An,{children:a})})},Ua=8,Ja=24,qa=A.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?
|
|
305
|
+
width: ${e=>e.$touchOptimized?Ja:Ua}px;
|
|
306
306
|
cursor: col-resize;
|
|
307
307
|
user-select: none;
|
|
308
308
|
z-index: 105; /* Above waveform, below header */
|
|
@@ -325,19 +325,19 @@
|
|
|
325
325
|
background: rgba(255, 255, 255, 0.4);
|
|
326
326
|
${e=>e.$edge==="left"?"border-left: 2px solid rgba(255, 255, 255, 0.8);":"border-right: 2px solid rgba(255, 255, 255, 0.8);"}
|
|
327
327
|
}
|
|
328
|
-
|
|
328
|
+
`,Jt=({clipId:e,trackIndex:t,clipIndex:n,edge:a,dragHandleProps:r,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!r)return null;const{attributes:c,listeners:u,setActivatorNodeRef:f,isDragging:w}=r;return v.jsx(qa,{ref:f,"data-clip-id":e,"data-boundary-edge":a,$edge:a,$isDragging:w,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},Qa=A.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
|
-
`,
|
|
334
|
+
`,er=A.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
|
|
340
|
+
`;function tr(e,t,n="logarithmic"){const a=[],r=Math.max(20,Math.min(e,100));for(let s=0;s<=r;s++){const o=s/r*e,l=s/r;let c;switch(n){case"linear":c=l;break;case"exponential":c=l*l;break;case"sCurve":c=(1-Math.cos(l*Math.PI))/2;break;case"logarithmic":default:c=Math.log10(1+l*9)/Math.log10(10);break}const u=(1-c)*t;a.push(`${o},${u}`)}return`M 0,${t} L ${a.join(" L ")} L ${e},0 L 0,0 Z`}var qt=({left:e,width:t,type:n,curveType:a="logarithmic",color:r})=>{const s=A.useTheme();if(t<1)return null;const o=r||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return v.jsx(Qa,{$left:e,$width:t,$type:n,children:v.jsx(er,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:v.jsx("path",{d:tr(t,100,a),fill:o})})})},nr=A.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
|
-
`,
|
|
354
|
+
`,ar=A.div`
|
|
355
355
|
flex: 1;
|
|
356
356
|
position: relative;
|
|
357
357
|
overflow: ${e=>e.$isOverlay?"visible":"hidden"};
|
|
358
|
-
`,
|
|
358
|
+
`,Tt=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:f=!1,isOverlay:w=!1,isSelected:g=!1,onMouseDown:d,trackId:x,fadeIn:I,fadeOut:m,sampleRate:b=44100,showFades:p=!1,touchOptimized:C=!1})=>{const h=Math.floor(o/c),y=Math.floor((o+l)/c)-h,S=u&&!f&&!w,R=`clip-${a}-${r}`,{attributes:E,listeners:$,setNodeRef:M,setActivatorNodeRef:D,transform:_,isDragging:Z}=Re.useDraggable({id:R,data:{clipId:n,trackIndex:a,clipIndex:r},disabled:!S}),T=`clip-boundary-left-${a}-${r}`,{attributes:P,listeners:j,setActivatorNodeRef:U,isDragging:V}=Re.useDraggable({id:T,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"left"},disabled:!S}),L=`clip-boundary-right-${a}-${r}`,{attributes:re,listeners:te,setActivatorNodeRef:Q,isDragging:q}=Re.useDraggable({id:L,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"right"},disabled:!S}),be=_?{transform:Bt.Translate.toString(_),zIndex:Z?100:void 0}:void 0;return v.jsxs(nr,{ref:M,style:be,className:t,$left:h,$width:y,$isOverlay:w,"data-clip-container":"true","data-track-id":x,onMouseDown:d,children:[u&&v.jsx(Ka,{clipId:n,trackIndex:a,clipIndex:r,trackName:s,isSelected:g,disableDrag:f,dragHandleProps:S?{attributes:E,listeners:$,setActivatorNodeRef:D}:void 0}),v.jsxs(ar,{$isOverlay:w,children:[e,p&&I&&I.duration>0&&v.jsx(qt,{left:0,width:Math.floor(I.duration*b/c),type:"fadeIn",curveType:I.type}),p&&m&&m.duration>0&&v.jsx(qt,{left:y-Math.floor(m.duration*b/c),width:Math.floor(m.duration*b/c),type:"fadeOut",curveType:m.type})]}),u&&!f&&!w&&v.jsxs(v.Fragment,{children:[v.jsx(Jt,{clipId:n,trackIndex:a,clipIndex:r,edge:"left",touchOptimized:C,dragHandleProps:{attributes:P,listeners:j,setActivatorNodeRef:U,isDragging:V}}),v.jsx(Jt,{clipId:n,trackIndex:a,clipIndex:r,edge:"right",touchOptimized:C,dragHandleProps:{attributes:re,listeners:te,setActivatorNodeRef:Q,isDragging:q}})]})]})},rr=A.div`
|
|
359
359
|
display: inline-flex;
|
|
360
360
|
align-items: center;
|
|
361
361
|
gap: 0.5rem;
|
|
362
|
-
`,
|
|
362
|
+
`,or=A(Cn)`
|
|
363
363
|
margin: 0;
|
|
364
364
|
white-space: nowrap;
|
|
365
|
-
`,
|
|
365
|
+
`,sr=A(xn)`
|
|
366
366
|
width: 120px;
|
|
367
|
-
`,
|
|
367
|
+
`,ir=({volume:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(parseFloat(s.target.value)/100)};return v.jsxs(rr,{className:a,children:[v.jsx(or,{htmlFor:"master-gain",children:"Master Volume"}),v.jsx(sr,{min:"0",max:"100",value:e*100,onChange:r,disabled:n,id:"master-gain"})]})};A.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
|
|
368
368
|
position: absolute;
|
|
369
369
|
top: 0;
|
|
370
370
|
left: 0;
|
|
@@ -398,23 +398,23 @@
|
|
|
398
398
|
width: 2px;
|
|
399
399
|
height: 100%;
|
|
400
400
|
background: ${e=>e.$color};
|
|
401
|
-
`;var
|
|
401
|
+
`;var lr=A.div`
|
|
402
402
|
overflow-y: hidden;
|
|
403
403
|
overflow-x: auto;
|
|
404
404
|
position: relative;
|
|
405
|
-
`,
|
|
405
|
+
`,cr=A.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
|
|
406
406
|
position: relative;
|
|
407
407
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
408
|
-
`,
|
|
408
|
+
`,ur=A.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
|
-
`,
|
|
413
|
+
`,dr=A.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
|
-
`,
|
|
417
|
+
`,fr=A.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
|
-
`,
|
|
426
|
+
`,Vt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:f,onTracksMouseUp:w,scrollContainerRef:g,isSelecting:d})=>v.jsx(lr,{"data-scroll-container":"true",ref:g,children:v.jsxs(cr,{$backgroundColor:t,$width:o,children:[a&&v.jsx(ur,{$width:r,$backgroundColor:n,children:a}),v.jsxs(dr,{$width:s,$backgroundColor:t,children:[e,(c||u)&&v.jsx(fr,{$controlsWidth:l,$isSelecting:d,onClick:c,onMouseDown:u,onMouseMove:f,onMouseUp:w})]})]})});A.withTheme(Vt);var mr=A.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,7 +431,7 @@
|
|
|
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
|
-
`,
|
|
434
|
+
`,Sn=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const a=Math.max(0,t-e);return a<=0?null:v.jsx(mr,{$left:e,$width:a,$color:n,"data-selection":!0})};A.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};
|
|
@@ -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
|
|
461
|
+
`;var Qt=A.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
|
-
`,
|
|
498
|
+
`,hr=A.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
|
-
`,
|
|
509
|
+
`,pr=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,f]=i.useState(null),w=i.useRef(0),g=i.useRef(0),d=i.useRef(0),x=Math.max(0,t-e),I=i.useCallback((b,p)=>{b.preventDefault(),b.stopPropagation(),f(p),w.current=b.clientX,g.current=p==="start"?e:t;const C=k=>{const y=k.clientX-w.current,S=g.current+y;if(p==="start"){const R=Math.max(l,Math.min(t-10,S));r?.(R)}else{const R=Math.max(e+10,Math.min(c,S));s?.(R)}},h=()=>{f(null),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",h)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",h)},[e,t,l,c,r,s]),m=i.useCallback(b=>{b.preventDefault(),b.stopPropagation(),f("region"),w.current=b.clientX,g.current=e,d.current=t;const p=t-e,C=k=>{const y=k.clientX-w.current;let S=g.current+y,R=d.current+y;S<l&&(S=l,R=l+p),R>c&&(R=c,S=c-p),o?.(S,R)},h=()=>{f(null),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",h)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",h)},[e,t,l,c,o]);return x<=0?null:v.jsxs(v.Fragment,{children:[v.jsx(hr,{$left:e,$width:x,$color:a,$isDragging:u==="region",onMouseDown:m,"data-loop-region-timescale":!0}),v.jsx(Qt,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:b=>I(b,"start"),"data-loop-marker-handle":"start"}),v.jsx(Qt,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:b=>I(b,"end"),"data-loop-marker-handle":"end"})]})},gr=A.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
|
-
`,
|
|
516
|
+
`,br=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),f=i.useRef(0),w=i.useRef(null),g=t>e,d=i.useCallback(x=>{const I=x.target;if(I.closest("[data-loop-marker-handle]")||I.closest("[data-loop-region-timescale]"))return;x.preventDefault(),u(!0);const m=w.current?.getBoundingClientRect();if(!m)return;const b=x.clientX-m.left,p=Math.max(s,Math.min(o,b));f.current=p,r?.(p,p);const C=k=>{const y=k.clientX-m.left,S=Math.max(s,Math.min(o,y)),R=Math.min(f.current,S),E=Math.max(f.current,S);r?.(R,E)},h=()=>{u(!1),document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",h)};document.addEventListener("mousemove",C),document.addEventListener("mouseup",h)},[s,o,r]);return v.jsx(gr,{ref:w,$leftOffset:l,onMouseDown:d,"data-timescale-loop-creator":!0,children:g&&v.jsx(pr,{startPosition:e,endPosition:t,markerColor:n,regionColor:a,minPosition:s,maxPosition:o,onLoopStartChange:x=>r?.(x,t),onLoopEndChange:x=>r?.(e,x),onLoopRegionMove:(x,I)=>r?.(x,I)})})};function et(e,t){const n=Math.floor(e/3600)%24,a=Math.floor(e/60)%60,r=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(a).padStart(2,"0")+":"+r.padStart(t+3,"0")}function Je(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return et(e,0);case"hh:mm:ss.u":return et(e,1);case"hh:mm:ss.uu":return et(e,2);case"hh:mm:ss.uuu":return et(e,3);default:return et(e,3)}}function $n(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const a=parseInt(n[0],10)||0,r=parseInt(n[1],10)||0,s=parseFloat(n[2])||0;return a*3600+r*60+s}default:return 0}}var en=({id:e,label:t,value:n,format:a,className:r,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const g=Je(n,a);c(g)},[n,a,e]);const u=g=>{const d=g.target.value;c(d)},f=()=>{if(s){const g=$n(l,a);s(g)}c(Je(n,a))},w=g=>{g.key==="Enter"&&g.currentTarget.blur()};return v.jsxs(v.Fragment,{children:[v.jsx(ja,{as:"label",htmlFor:e,children:t}),v.jsx(vn,{type:"text",className:r,id:e,value:l,onChange:u,onBlur:f,onKeyDown:w,readOnly:o})]})},vr=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:a})=>{const[r,s]=i.useState("hh:mm:ss.uuu");i.useEffect(()=>{const c=document.querySelector(".time-format"),u=()=>{c&&s(c.value)};return c&&(s(c.value),c.addEventListener("change",u)),()=>{c?.removeEventListener("change",u)}},[]);const o=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return v.jsxs(v.Fragment,{children:[v.jsx(en,{id:"audio_start",label:"Start of audio selection",value:e,format:r,className:"audio-start form-control mr-sm-2",onChange:o}),v.jsx(en,{id:"audio_end",label:"End of audio selection",value:t,format:r,className:"audio-end form-control mr-sm-2",onChange:l})]})};function gt(){return window.devicePixelRatio}var Mn=i.createContext(gt()),Rn=({children:e})=>{const[t,n]=i.useState(gt());return matchMedia(`(resolution: ${gt()}dppx)`).addEventListener("change",()=>{n(gt())},{once:!0}),v.jsx(Mn.Provider,{value:Math.ceil(t),children:e})},En=()=>i.useContext(Mn),yt=i.createContext({sampleRate:48e3,samplesPerPixel:1e3,zoomLevels:[1e3,1500,2e3,2500],waveHeight:80,timeScaleHeight:15,controls:{show:!1,width:150},duration:3e4,barWidth:1,barGap:0}),at=()=>i.useContext(yt),rt=()=>i.useContext(A.ThemeContext),Pt=i.createContext(v.jsx(i.Fragment,{})),Cr=()=>i.useContext(Pt),xr=0,wr=!1,yr=0,kr=0,Ir={progress:xr,isPlaying:wr,selectionStart:yr,selectionEnd:kr};i.createContext(Ir);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var Dn=({isSelected:e,transparentBackground:t,...n})=>{const a=rt(),{waveHeight:r,barWidth:s,barGap:o}=at(),l=En(),c=e&&a?a.selectedWaveOutlineColor:a?.waveOutlineColor,u=e&&a?a.selectedWaveFillColor:a?.waveFillColor,f=a?.waveformDrawMode||"inverted";return v.jsx(Ya,{...n,...a,waveOutlineColor:c,waveFillColor:u,waveHeight:r,devicePixelRatio:l,barWidth:s,barGap:o,transparentBackground:t,drawMode:f})};function Ar(e,t,n){return Math.ceil(e*n/t)}function Sr(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var $r=A.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
|
-
`,
|
|
521
|
+
`,Mr=A.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
|
-
`,
|
|
526
|
+
`,Rr=A.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
|
-
`,
|
|
531
|
+
`,Er=e=>{const{theme:{timeColor:t},duration:n,marker:a,bigStep:r,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:f,samplesPerPixel:w,timeScaleHeight:g,controls:{show:d,width:x}}=i.useContext(yt),I=En();i.useEffect(()=>{if(u.current!==null){const C=u.current,h=C.getContext("2d");if(h){h.resetTransform(),h.clearRect(0,0,C.width,C.height),h.imageSmoothingEnabled=!1,h.fillStyle=t,h.scale(I,I);for(const[k,y]of l.entries()){const S=g-y;h.fillRect(k,S,1,y)}}}},[n,I,t,g,r,s,a,l]);const m=Ar(n/1e3,w,f),b=f/w;let p=0;for(let C=0;C<m;C+=b*s/1e3){const h=Math.floor(C);if(p%a===0){const k=p,y=Sr(k),S=o?v.jsx(i.Fragment,{children:o(k,h)},`timestamp-${p}`):v.jsx(Rr,{$left:h,children:y},y);c.push(S),l.set(h,g)}else p%r===0?l.set(h,Math.floor(g/2)):p%s===0&&l.set(h,Math.floor(g/5));p+=s}return v.jsxs($r,{$cssWidth:m,$controlWidth:d?x:0,$timeScaleHeight:g,children:[c,v.jsx(Mr,{$cssWidth:m,$timeScaleHeight:g,width:m*I,height:g*I,ref:u})]})},Bn=A.withTheme(Er),Dr=A.div`
|
|
532
532
|
display: inline-flex;
|
|
533
533
|
align-items: center;
|
|
534
534
|
gap: 0.5rem;
|
|
535
|
-
`,
|
|
535
|
+
`,Br=[{value:"seconds",label:"seconds"},{value:"thousandths",label:"thousandths"},{value:"hh:mm:ss",label:"hh:mm:ss"},{value:"hh:mm:ss.u",label:"hh:mm:ss + tenths"},{value:"hh:mm:ss.uu",label:"hh:mm:ss + hundredths"},{value:"hh:mm:ss.uuu",label:"hh:mm:ss + milliseconds"}],Tr=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return v.jsx(Dr,{className:a,children:v.jsx(Zt,{className:"time-format",value:e,onChange:r,disabled:n,"aria-label":"Time format selection",children:Br.map(s=>v.jsx("option",{value:s.value,children:s.label},s.value))})})},Wr=A.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?kn:0)}px`}}))`
|
|
536
536
|
position: relative;
|
|
537
537
|
display: flex;
|
|
538
538
|
${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
|
|
539
|
-
`,
|
|
539
|
+
`,_r=A.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
|
-
`,
|
|
543
|
+
`,Fr=A.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
|
-
`,
|
|
557
|
+
`,Tn=({numChannels:e,children:t,className:n,backgroundColor:a,offset:r=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:f,controls:{show:w,width:g}}=at(),d=Cr();return v.jsxs(Wr,{$numChannels:e,className:n,$waveHeight:f,$controlWidth:w?g:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[v.jsx(Fr,{$controlWidth:w?g:0,$isSelected:u,children:d}),v.jsx(_r,{$controlWidth:w?g:0,$backgroundColor:a,$offset:r,onClick:l,"data-track-id":c,children:t})]})},tn=A.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
|
-
`,
|
|
616
|
+
`,Zr=A.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
|
-
`,
|
|
628
|
+
`,Vr=A.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
|
-
`,
|
|
641
|
+
`,Pr=A.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
|
-
`,
|
|
652
|
+
`,zr=e=>v.jsx(bn,{weight:"light",...e}),jr=e=>v.jsx(gn,{weight:"light",...e}),nn=A(xn)`
|
|
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
|
-
`,
|
|
701
|
+
`,an=A.label`
|
|
702
702
|
width: 100%;
|
|
703
703
|
display: flex;
|
|
704
704
|
justify-content: space-between;
|
|
@@ -744,8 +744,8 @@
|
|
|
744
744
|
&:active {
|
|
745
745
|
transform: scale(0.9);
|
|
746
746
|
}
|
|
747
|
-
`;function
|
|
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 Ie(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 Pe(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 kr(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 Ie(a),e)}else{var s=new ns;s.onmessage=function(o){n(void 0,new Ie(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){kr(o,n,r)},a);s&&s.catch(a)}Ie.create=function(t){return new Ie(t)};Ie.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 kr(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function $t(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 Ie(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}$t.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};$t.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};$t.prototype.getOutputData=function(){return this._output_data};Ie.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!Ye(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!Ye(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 $t(t);!n.next(););return new Ie(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 Ie.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]),C=new DataView(u),p=0;p<n;p++)C.setUint8(p,f.getUint8(p));C.setInt32(16,a,!0);for(var d=0,g=new Uint8Array(u,n),I=0;I<s.length;I++){var h=s[I];g.set(new Uint8Array(h,n),d),d+=h.byteLength-n}return u},slice:function(t){var n=0,r=0;if(!Ye(t.startIndex)&&!Ye(t.endIndex)?(n=t.startIndex,r=t.endIndex):!Ye(t.startTime)&&!Ye(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 C=this._at(n*this.channels*2+f);this.bits===8?u.setInt8(s+f,C):u.setInt16(s+f*2,C,!0)}return new Ie(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 on(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 Ie.create(r)}else{const r=await t.json();return Ie.create(r)}}function $r(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 on(e);return $r(n,t)}async function is(e){const t=await on(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 p=e.scale,d=Math.floor(r/p),g=Math.ceil((r+a)/p);s=s.slice({startIndex:d,endIndex:g})}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,C=l===8?new Int8Array(f*2):new Int16Array(f*2);for(let p=0;p<f;p++)C[p*2]=c[p],C[p*2+1]=u[p];return{data:C,bits:l,length:f}}var _n;(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"})(_n||(_n={}));function Vn(){}const cs=Object.freeze({x:0,y:0});var Ke;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Ke||(Ke={}));var zn;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(zn||(zn={}));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 Hn;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Hn||(Hn={}));var jn;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(jn||(jn={}));Ke.Backward+"",Ke.Forward+"",Ke.Backward+"",Ke.Forward+"";var Yt;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Yt||(Yt={}));var Ot;(function(e){e.Optimized="optimized"})(Ot||(Ot={}));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])}Yt.WhileDragging,Ot.Optimized;const ds={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Vn,draggableNodes:new Map,over:null,measureDroppableContainers:Vn},fs=i.createContext(ds),hs=i.createContext({...cs,scaleX:1,scaleY:1});var Pn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Pn||(Pn={}));const ms=i.createContext(null),Gn="button",ps="Draggable";function Ln(e){let{id:t,data:n,disabled:r=!1,attributes:a}=e;const s=ur(ps),{activators:o,activatorEvent:l,active:c,activeNodeRect:u,ariaDescribedById:f,draggableNodes:C,over:p}=i.useContext(fs),{role:d=Gn,roleDescription:g="draggable",tabIndex:I=0}=a??{},h=c?.id===t,b=i.useContext(h?hs:ms),[w,v]=vt(),[m,S]=vt(),y=us(o,t),k=cr(n);yt(()=>(C.set(t,{id:t,key:s,node:w,activatorNode:m,data:k}),()=>{const M=C.get(t);M&&M.key===s&&C.delete(t)}),[C,t]);const R=i.useMemo(()=>({role:d,tabIndex:I,"aria-disabled":r,"aria-pressed":h&&d===Gn?!0:void 0,"aria-roledescription":g,"aria-describedby":f.draggable}),[r,d,I,h,g,f.draggable]);return{active:c,activatorEvent:l,activeNodeRect:u,attributes:R,isDragging:h,listeners:r?void 0:y,node:w,over:p,setNodeRef:v,setActivatorNodeRef:S,transform:b}}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 Hr(e){let t=1/0,n=-1/0;for(let a=0;a<e.length;a++){const r=e[a];t>r&&(t=r),n<r&&(n=r)}return{min:t,max:n}}function rn(e,t){const n=Math.pow(2,t-1),a=e<0?e*n:e*(n-1);return Math.max(-n,Math.min(n-1,a))}function Wn(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function on(e,t,n){const a=e.length,r=Math.ceil(a/t),s=Wn(n,r*2);for(let o=0;o<r;o++){const l=o*t,c=Math.min((o+1)*t,a),u=e.subarray(l,c),f=Hr(u),w=rn(f.min,n),g=rn(f.max,n);s[o*2]=w,s[o*2+1]=g}return s}function Xr(e,t){const n=e.length,a=1/n,r=e[0].length/2,s=Wn(t,r*2);for(let o=0;o<r;o++){let l=0,c=0;for(let u=0;u<n;u++)l+=a*e[u][o*2],c+=a*e[u][o*2+1];s[o*2]=l,s[o*2+1]=c}return[s]}function Gr(e,t=1e3,n=!0,a=0,r,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=r??e.length;for(let f=0;f<c;f++){const g=e.getChannelData(f).subarray(a,u);o.push(on(g,t,s))}}else{const c=r??e.length,u=e.subarray(a,c);o.push(on(u,t,s))}return n&&o.length>1&&(o=Xr(o,s)),{length:o[0].length/2,data:o,bits:s}}function Nr(e,t=1e3,n=!0,a=8,r=0,s){const o=s!==void 0?r+s:void 0;return Gr(e,t,n,r,o,a)}function Oe(e,t){this._waveformData=e,this._channelIndex=t}Oe.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};Oe.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};Oe.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};Oe.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};Oe.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};Oe.prototype.max_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.max_sample(n));return t};var Lr=127,Yr=-128,Or=32767,Kr=-32768;function Ur(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function Jr(e){for(var t=e.scale,n=e.amplitude_scale,a=e.split_channels,r=e.length,s=e.sample_rate,o=e.channels.map(function(M){return new Float32Array(M)}),l=a?o.length:1,c=24,u=Ur(r,t),f=e.bits===8?1:2,w=c+u*2*f*l,g=new ArrayBuffer(w),d=new DataView(g),x=0,I=c,m=new Array(l),b=new Array(l),p=0;p<l;p++)m[p]=1/0,b[p]=-1/0;var C=e.bits===8?Yr:Kr,h=e.bits===8?Lr:Or;d.setInt32(0,2,!0),d.setUint32(4,e.bits===8,!0),d.setInt32(8,s,!0),d.setInt32(12,t,!0),d.setInt32(16,u,!0),d.setInt32(20,l,!0);for(var k=0;k<r;k++){var y=0;if(l===1){for(var S=0;S<o.length;++S)y+=o[S][k];y=Math.floor(h*y*n/o.length),y<m[0]&&(m[0]=y,m[0]<C&&(m[0]=C)),y>b[0]&&(b[0]=y,b[0]>h&&(b[0]=h))}else for(var R=0;R<l;++R)y=Math.floor(h*o[R][k]*n),y<m[R]&&(m[R]=y,m[R]<C&&(m[R]=C)),y>b[R]&&(b[R]=y,b[R]>h&&(b[R]=h));if(++x===t){for(var E=0;E<l;E++)e.bits===8?(d.setInt8(I++,m[E]),d.setInt8(I++,b[E])):(d.setInt16(I,m[E],!0),d.setInt16(I+2,b[E],!0),I+=4),m[E]=1/0,b[E]=-1/0;x=0}}if(x>0)for(var $=0;$<l;$++)e.bits===8?(d.setInt8(I++,m[$]),d.setInt8(I++,b[$])):(d.setInt16(I,m[$],!0),d.setInt16(I+2,b[$],!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 qr(e){return e&&bt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Qr(e){var t=e&&bt(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),a=n.getInt32(0,!0);if(a!==1&&a!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function eo(e){var t=e.data,n=e.channels||1,a=24,r=e.bits===8?1:2,s=e.length*2*n;if(t.length!==s)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var o=a+t.length*r,l=new ArrayBuffer(o),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=a;if(e.bits===8)for(var f=0;f<t.length;f++)c.setInt8(u++,t[f],!0);else for(var w=0;w<t.length;w++)c.setInt16(u,t[w],!0),u+=2;return l}function Ue(e){return e==null}function to(e,t){var n=atob(e);return n}function no(e,t,n){var a=to(e),r=a.indexOf(`
|
|
748
|
+
`,10)+1,s=a.substring(r)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function ao(e,t,n){var a;return function(s){return a=a||no(e),new Worker(a,s)}}var ro=ao("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function De(e){if(qr(e)&&(e=eo(e)),Qr(e)){this._data=new DataView(e),this._offset=this._version()===2?24:20,this._channels=[];for(var t=0;t<this.channels;t++)this._channels[t]=new Oe(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var tt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function oo(e){var t={scale:e.scale||tt.scale,bits:e.bits||tt.bits,amplitude_scale:e.amplitude_scale||tt.amplitude_scale,split_channels:e.split_channels||tt.split_channels,disable_worker:e.disable_worker||tt.disable_worker};return t}function so(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function _n(e,t,n){var a=so(e);if(t.disable_worker){var r=Jr({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a});n(void 0,new De(r),e)}else{var s=new ro;s.onmessage=function(o){n(void 0,new De(o.data),e)},s.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:a},a)}}function io(e,t,n,a){function r(o){o||(o=new DOMException("EncodingError")),a(o),a=function(){}}var s=e.decodeAudioData(t,function(o){_n(o,n,a)},r);s&&s.catch(r)}De.create=function(t){return new De(t)};De.createFromAudio=function(e,t){var n=oo(e);if(e.audio_context&&e.array_buffer)return io(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return _n(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function kt(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),a=24,r=this._inputData.bits===8?1:2,s=a+n*2*this._inputData.channels*r;this._output_data=new ArrayBuffer(s),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new De(this._output_data),this._input_index=0,this._output_index=0;var o=this._inputData.channels;this._min=new Array(o),this._max=new Array(o);for(var l=0;l<o;++l)this._input_buffer_size>0?(this._min[l]=this._inputData.channel(l).min_sample(this._input_index),this._max[l]=this._inputData.channel(l).max_sample(this._input_index)):(this._min[l]=0,this._max[l]=0);this._min_value=this._inputData.bits===8?-128:-32768,this._max_value=this._inputData.bits===8?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}kt.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};kt.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,a;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var r=0;r<n;++r)a=this._outputWaveformData.channel(r),a.set_min_sample(this._output_index-1,this._min[r]),a.set_max_sample(this._output_index-1,this._max[r]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var s=0;s<n;++s)this._min[s]=this._max_value,this._max[s]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var o=0;o<n;++o){a=this._inputData.channel(o);var l=a.min_sample(this._input_index);l<this._min[o]&&(this._min[o]=l),l=a.max_sample(this._input_index),l>this._max[o]&&(this._max[o]=l)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var c=0;c<n;++c)a=this._outputWaveformData.channel(c),a.set_min_sample(this._output_index-1,this._min[c]),a.set_max_sample(this._output_index-1,this._max[c]);return!0};kt.prototype.getOutputData=function(){return this._output_data};De.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!Ue(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!Ue(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new kt(t);!n.next(););return new De(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(r){if(t.channels!==r.channels||t.sample_rate!==r.sample_rate||t.bits!==r.bits||t.scale!==r.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var a=this._concatBuffers.apply(this,n);return De.create(a)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,a=n,r=0,s=[this].concat(t).map(function(b){return b._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),f=new DataView(s[0]),w=new DataView(u),g=0;g<n;g++)w.setUint8(g,f.getUint8(g));w.setInt32(16,r,!0);for(var d=0,x=new Uint8Array(u,n),I=0;I<s.length;I++){var m=s[I];x.set(new Uint8Array(m,n),d),d+=m.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!Ue(t.startIndex)&&!Ue(t.endIndex)?(n=t.startIndex,a=t.endIndex):!Ue(t.startTime)&&!Ue(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,s=24,o=this.bits===8?1:2,l=s+r*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var f=0;f<r*this.channels*2;f++){var w=this._at(n*this.channels*2+f);this.bits===8?u.setInt8(s+f,w):u.setInt16(s+f*2,w,!0)}return new De(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var a=0;a<this.channels;a++)t.data.push(this.channel(a).min_sample(n)),t.data.push(this.channel(a).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function zt(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const a=await t.arrayBuffer();return De.create(a)}else{const a=await t.json();return De.create(a)}}function Fn(e,t=0){const n=e.channel(t),a=e.bits,r=n.min_array(),s=n.max_array(),o=r.length,l=a===8?new Int8Array(o*2):new Int16Array(o*2);for(let c=0;c<o;c++)l[c*2]=r[c],l[c*2+1]=s[c];return{data:l,bits:a,length:o,sampleRate:e.sample_rate}}async function lo(e,t=0){const n=await zt(e);return Fn(n,t)}async function co(e){const t=await zt(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function Zn(e,t,n=0,a,r){let s=e;if(a!==void 0&&r!==void 0){const g=e.scale,d=Math.floor(a/g),x=Math.ceil((a+r)/g);s=s.slice({startIndex:d,endIndex:x})}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,w=l===8?new Int8Array(f*2):new Int16Array(f*2);for(let g=0;g<f;g++)w[g*2]=c[g],w[g*2+1]=u[g];return{data:w,bits:l,length:f}}function Vn(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function uo(e){return{id:e.id,begin:e.start.toFixed(3),end:e.end.toFixed(3),lines:e.lines,language:e.lang||"en"}}A.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
749
749
|
position: absolute;
|
|
750
750
|
top: 0;
|
|
751
751
|
background: ${e=>e.$color};
|
|
@@ -830,12 +830,12 @@
|
|
|
830
830
|
&:active {
|
|
831
831
|
background: rgba(255, 255, 255, 0.3);
|
|
832
832
|
}
|
|
833
|
-
`;var
|
|
833
|
+
`;var fo=A.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
|
-
`,
|
|
838
|
+
`,mo=A.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
|
-
`,
|
|
862
|
+
`,ho=A.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
|
-
`,
|
|
872
|
+
`,sn=A.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
|
-
`,
|
|
907
|
+
`,Pn=({annotationId:e,annotationIndex:t,startPosition:n,endPosition:a,label:r,color:s="#ff9800",isActive:o=!1,onClick:l,editable:c=!0})=>{const u=Math.max(0,a-n),f=`annotation-boundary-start-${t}`,{attributes:w,listeners:g,setActivatorNodeRef:d,isDragging:x}=Re.useDraggable({id:f,data:{annotationId:e,annotationIndex:t,edge:"start"},disabled:!c}),I=`annotation-boundary-end-${t}`,{attributes:m,listeners:b,setActivatorNodeRef:p,isDragging:C}=Re.useDraggable({id:I,data:{annotationId:e,annotationIndex:t,edge:"end"},disabled:!c});if(u<=0)return null;const h=y=>S=>{S.stopPropagation(),y?.(S)},k=y=>{y.stopPropagation()};return v.jsxs(fo,{$left:n,$width:u,children:[v.jsx(mo,{$color:s,$isActive:o,onClick:l,children:r&&v.jsx(ho,{children:r})}),c&&v.jsx(sn,{ref:d,$position:"left",$isDragging:x,onClick:k,...g,onPointerDown:h(g?.onPointerDown),...w}),c&&v.jsx(sn,{ref:p,$position:"right",$isDragging:C,onClick:k,...b,onPointerDown:h(b?.onPointerDown),...m})]})},po=A.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
|
-
`,
|
|
913
|
+
`,go=A.div`
|
|
914
914
|
position: sticky;
|
|
915
915
|
z-index: 200;
|
|
916
916
|
left: 0;
|
|
@@ -918,11 +918,11 @@
|
|
|
918
918
|
width: ${e=>e.$controlWidth}px;
|
|
919
919
|
flex-shrink: 0;
|
|
920
920
|
background: transparent;
|
|
921
|
-
`,
|
|
921
|
+
`,bo=A.div`
|
|
922
922
|
position: relative;
|
|
923
923
|
flex: 1;
|
|
924
924
|
padding-left: ${e=>e.$offset||0}px;
|
|
925
|
-
`,
|
|
925
|
+
`,zn=({children:e,className:t,height:n=30,offset:a=0,width:r})=>{const{controls:{show:s,width:o}}=at();return v.jsxs(po,{className:t,$height:n,$controlWidth:s?o:0,$width:r,children:[v.jsx(go,{$controlWidth:s?o:0}),v.jsx(bo,{$offset:a,children:e})]})};A.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;`}
|
|
@@ -945,12 +945,12 @@
|
|
|
945
945
|
position: relative;
|
|
946
946
|
flex: 1;
|
|
947
947
|
padding-left: ${e=>e.$offset||0}px;
|
|
948
|
-
`;var
|
|
948
|
+
`;var vo=A.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
|
-
|
|
953
|
+
`,Co=A.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
|
-
`,
|
|
972
|
+
`,xo=A.div`
|
|
973
973
|
display: flex;
|
|
974
974
|
justify-content: space-between;
|
|
975
975
|
align-items: center;
|
|
976
976
|
margin-bottom: 6px;
|
|
977
|
-
`,
|
|
977
|
+
`,wo=A.div`
|
|
978
978
|
display: flex;
|
|
979
979
|
align-items: center;
|
|
980
980
|
gap: 8px;
|
|
981
|
-
`,
|
|
981
|
+
`,yo=A.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
|
-
`,
|
|
995
|
+
`,ko=A.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
|
-
`,
|
|
1001
|
+
`,Io=A.div`
|
|
1002
1002
|
display: flex;
|
|
1003
1003
|
gap: 6px;
|
|
1004
|
-
`,
|
|
1004
|
+
`,Ao=A.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
|
-
`,
|
|
1023
|
+
`,So=A.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
|
-
|
|
1039
|
-
`)},c(
|
|
1040
|
-
`)})]},
|
|
1038
|
+
`,$o=({annotations:e,activeAnnotationId:t,shouldScrollToActive:n=!1,editable:a=!1,controls:r=[],annotationListConfig:s,height:o,onAnnotationClick:l,onAnnotationUpdate:c,renderAnnotationItem:u})=>{const f=i.useRef(null),w=i.useRef(null),g=i.useRef(void 0);i.useEffect(()=>{}),i.useEffect(()=>{const p=w.current;if(!p)return;const C=()=>{};return p.addEventListener("scroll",C),()=>p.removeEventListener("scroll",C)},[]),i.useEffect(()=>{t&&f.current&&n&&f.current.scrollIntoView({behavior:"smooth",block:"nearest"}),g.current=t},[t,n]);const d=p=>{if(isNaN(p)||!isFinite(p))return"0:00.000";const C=Math.floor(p/60),h=(p%60).toFixed(3);return`${C}:${h.padStart(6,"0")}`},x=(p,C)=>{if(!a||!c)return;const h=[...e];h[p]={...h[p],lines:C.split(`
|
|
1039
|
+
`)},c(h)},I=(p,C)=>{if(!a||!c)return;const h=C.trim();if(!h)return;const k=[...e];k[p]={...k[p],id:h},c(k)},m=(p,C,h)=>{if(!c)return;const k=[...e];p.action(k[h],h,k,s||{}),c(k)},b=p=>p.replace(/\./g," ");return v.jsx(vo,{ref:w,$height:o,children:e.map((p,C)=>{const h=p.id===t,k=()=>l?.(p);return u?v.jsx("div",{ref:h?f:null,children:u({annotation:p,index:C,isActive:h,onClick:k,formatTime:d})},p.id):v.jsxs(Co,{ref:h?f:null,$isActive:h,onClick:k,children:[v.jsxs(xo,{children:[v.jsxs(wo,{children:[v.jsx(yo,{$isEditable:a,contentEditable:a,suppressContentEditableWarning:!0,onBlur:y=>I(C,y.currentTarget.textContent||""),children:p.id}),v.jsxs(ko,{children:[d(p.start)," - ",d(p.end)]})]}),r.length>0&&v.jsx(Io,{onClick:y=>y.stopPropagation(),children:r.map((y,S)=>v.jsx(Ao,{title:y.title,onClick:()=>m(y,p,C),children:y.text?y.text:v.jsx("i",{className:b(y.class||"")})},S))})]}),v.jsx(So,{$isEditable:a,contentEditable:a,suppressContentEditableWarning:!0,onBlur:y=>x(C,y.currentTarget.textContent||""),children:p.lines.join(`
|
|
1040
|
+
`)})]},p.id)})})},jn=i.memo($o),Mo=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return v.jsxs(Ct,{className:a,children:[v.jsx(xt,{type:"checkbox",id:"continuous-play",className:"continuous-play",checked:e,onChange:r,disabled:n}),v.jsx(wt,{htmlFor:"continuous-play",children:"Continuous Play"})]})},Ro=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return v.jsxs(Ct,{className:a,children:[v.jsx(xt,{type:"checkbox",id:"link-endpoints",className:"link-endpoints",checked:e,onChange:r,disabled:n}),v.jsx(wt,{htmlFor:"link-endpoints",children:"Link Endpoints"})]})},Eo=({checked:e,onChange:t,className:n})=>v.jsxs(Ct,{className:n,children:[v.jsx(xt,{type:"checkbox",id:"editable-annotations",checked:e,onChange:a=>t(a.target.checked)}),v.jsx(wt,{htmlFor:"editable-annotations",children:"Editable Annotations"})]}),Do=A.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(C=>bs(C)),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 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 Dr(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:a=>Je(a,e),parseTime:a=>xr(a,e)}}const js=[256,512,1024,2048,4096,8192];function Mr({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 Rr({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 Kt(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,C=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(C===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.durationSamples??C;return{id:Br(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:r,sampleRate:f,sourceDurationSamples:C,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,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 C=t?.duration??e.sourceDuration??u?.duration;if(C===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const p=e.duration??C;return Kt({audioBuffer:t,startSample:Math.round(n*f),durationSamples:Math.round(p*f),offsetSamples:Math.round(r*f),sampleRate:f,sourceDurationSamples:Math.ceil(C*f),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:Br(),name:t,clips:n,muted:r,soloed:a,volume:s,pan:o,color:l,height:c}}function Br(){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,f]=i.useState(0),C=e.length;return i.useEffect(()=>{if(e.length===0){a([]),o(!1),f(0);return}let p=!1;const d=new Map,g=(h,b,w)=>{const v=w??h.audioBuffer;if(!v&&!h.waveformData)throw new Error(`Track ${b+1}: Must provide src, audioBuffer, or waveformData`);const m=v?.duration??h.waveformData?.duration,S=Gs({audioBuffer:v,startTime:h.startTime??0,duration:h.duration??m,offset:h.offset??0,name:h.name||`Track ${b+1}`,fadeIn:h.fadeIn,fadeOut:h.fadeOut,waveformData:h.waveformData});if(isNaN(S.startSample)||isNaN(S.durationSamples)||isNaN(S.offsetSamples))throw console.error("Invalid clip values:",S),new Error(`Invalid clip values for track ${b+1}`);return{...Ls({name:h.name||`Track ${b+1}`,clips:[S],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=ir.getContext().rawContext,b=e.map(async(v,m)=>{if(v.audioBuffer){const M=g(v,m,v.audioBuffer);return n&&!p&&(d.set(m,M),f(D=>D+1),a(Array.from({length:e.length},(D,$)=>d.get($)).filter(D=>D!==void 0))),M}if(!v.src&&v.waveformData){const M=g(v,m);return n&&!p&&(d.set(m,M),f(D=>D+1),a(Array.from({length:e.length},(D,$)=>d.get($)).filter(D=>D!==void 0))),M}if(!v.src)throw new Error(`Track ${m+1}: Must provide src, audioBuffer, or waveformData`);const S=await fetch(v.src);if(!S.ok)throw new Error(`Failed to fetch ${v.src}: ${S.statusText}`);const y=await S.arrayBuffer(),k=await h.decodeAudioData(y);if(!k||!k.sampleRate||!k.duration)throw new Error(`Invalid audio buffer for ${v.src}`);const R=g(v,m,k);return n&&!p&&(d.set(m,R),f(M=>M+1),a(Array.from({length:e.length},(M,D)=>d.get(D)).filter(M=>M!==void 0))),R}),w=await Promise.all(b);p||(n||(a(w),f(w.length)),o(!1))}catch(h){if(!p){const b=h instanceof Error?h.message:"Unknown error loading audio";c(b),o(!1),console.error("Error loading audio tracks:",h)}}})(),()=>{p=!0}},[e,n]),{tracks:r,loading:s,error:l,loadedCount:u,totalCount:C}}function Ys({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:r}){const a=i.useRef(null),s=i.useCallback(u=>{const{transform:f,active:C}=u;if(!C?.data?.current)return{...f,scaleX:1,scaleY:1};const{trackIndex:p,clipIndex:d,boundary:g}=C.data.current;if(g)return{...f,scaleX:1,scaleY:1};const I=e[p];if(!I)return{...f,scaleX:1,scaleY:1};const h=I.clips[d];if(!h)return{...f,scaleX:1,scaleY:1};const b=h.startSample/r,w=h.durationSamples/r,v=f.x*n/r;let m=b+v;const S=[...I.clips].sort(($,T)=>$.startSample-T.startSample),y=S.findIndex($=>$===h);m=Math.max(0,m);const k=y>0?S[y-1]:null;if(k){const $=(k.startSample+k.durationSamples)/r;m=Math.max(m,$)}const R=y<S.length-1?S[y+1]:null;if(R){const $=m+w,T=R.startSample/r;$>T&&(m=T-w)}const D=(m-b)*r/n;return{...f,x:D,scaleX:1,scaleY:1}},[e,n,r]),o=i.useCallback(u=>{const{active:f}=u,{boundary:C}=f.data.current;if(!C){a.current=null;return}const{trackIndex:p,clipIndex:d}=f.data.current,I=e[p]?.clips[d];I&&(a.current={offsetSamples:I.offsetSamples,durationSamples:I.durationSamples,startSample:I.startSample})},[e]),l=i.useCallback(u=>{const{active:f,delta:C}=u,{boundary:p}=f.data.current;if(!p||!a.current)return;const{trackIndex:d,clipIndex:g}=f.data.current,I=C.x*n,h=Math.floor(.1*r),b=a.current,w=e.map((v,m)=>{if(m!==d)return v;const S=[...v.clips].sort((R,M)=>R.startSample-M.startSample),y=S.findIndex(R=>R===v.clips[g]),k=v.clips.map((R,M)=>{if(M!==g)return R;const D=R.sourceDurationSamples;if(p==="left"){let $=Math.floor(I);const T=-b.startSample;$<T&&($=T);const W=-b.offsetSamples;$<W&&($=W);const H=y>0?S[y-1]:null;if(H){const O=H.startSample+H.durationSamples-b.startSample;$<O&&($=O)}const P=b.durationSamples-h;$>P&&($=P);const j=b.offsetSamples+$,N=b.durationSamples-$,Y=b.startSample+$;return{...R,offsetSamples:j,durationSamples:N,startSample:Y}}else{let $=Math.floor(b.durationSamples+I);$=Math.max(h,$),b.offsetSamples+$>D&&($=D-b.offsetSamples);const T=y<S.length-1?S[y+1]:null;return T&&b.startSample+$>T.startSample&&($=T.startSample-b.startSample,$=Math.max(h,$)),{...R,durationSamples:$}}});return{...v,clips:k}});t(w)},[e,t,n,r]),c=i.useCallback(u=>{const{active:f,delta:C}=u,{trackIndex:p,clipIndex:d,boundary:g}=f.data.current,I=C.x*n;if(g){a.current=null;return}const h=e.map((b,w)=>{if(w!==p)return b;const v=[...b.clips].sort((y,k)=>y.startSample-k.startSample),m=v.findIndex(y=>y===b.clips[d]),S=b.clips.map((y,k)=>{if(k!==d)return y;let R=Math.floor(y.startSample+I);R=Math.max(0,R);const M=m>0?v[m-1]:null;if(M){const $=M.startSample+M.durationSamples;R=Math.max(R,$)}const D=m<v.length-1?v[m+1]:null;return D&&R+y.durationSamples>D.startSample&&(R=D.startSample-y.durationSamples),{...y,startSample:R}});return{...b,clips:S}});t(h)},[e,t,n,r]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Vt=.01;function Os({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:r,duration:a,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(f=>{const{active:C}=f,p=C.data.current;if(!p||p.annotationIndex===void 0){o.current=null;return}const d=e[p.annotationIndex];d&&(o.current={start:d.start,end:d.end,annotationIndex:p.annotationIndex})},[e]),c=i.useCallback(f=>{const{active:C,delta:p}=f;if(!o.current)return;const d=C.data.current;if(!d)return;const{edge:g,annotationIndex:I}=d,h=o.current,b=p.x*n/r,w=g==="start"?h.start+b:h.end+b,v=Ks({annotationIndex:I,newTime:w,isDraggingStart:g==="start",annotations:e,duration:a,linkEndpoints:s});t(v)},[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 f=o[e-1];Math.abs(f.end-l.start)<Vt?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)<Vt){const C=f.start+u;o[e+1]={...f,start:Math.min(f.end-.1,C)};let p=e+1;for(;p<o.length-1;){const d=o[p],g=o[p+1];if(Math.abs(g.start-d.end)<Vt){const I=d.end-r[p].end;o[p+1]={...g,start:Math.min(g.end-.1,g.start+I)},p++}else break}}else c>=f.start&&(o[e]={...o[e],end:f.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const f=o[e+1];o[e+1]={...f,start:c};let C=e+1;for(;C<o.length-1;){const p=o[C],d=o[C+1];if(p.end>d.start)o[C+1]={...d,start:p.end},C++;else break}}}return o}function sn(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Er(e){return"nodeType"in e}function qe(e){var t,n;return e?sn(e)?e:Er(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Us(e){const{Document:t}=qe(e);return e instanceof t}function Js(e){return sn(e)?!1:e instanceof qe(e).HTMLElement}function qs(e){return e instanceof qe(e).SVGElement}function Dt(e){return e?sn(e)?e.document:Er(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 f=s[c];f!=null&&(s[c]=f+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}=qe(e.target);return t&&e instanceof t}function Yn(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 On;(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"})(On||(On={}));function zt(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 Ut=Object.freeze({x:0,y:0});var Ue;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(Ue||(Ue={}));class Xt{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}=qe(e);return e instanceof t?e:Dt(e)}function Ht(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 Ee;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Ee||(Ee={}));function Kn(e){e.preventDefault()}function oi(e){e.stopPropagation()}var Te;(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"})(Te||(Te={}));Te.Space,Te.Enter,Te.Esc,Te.Space,Te.Enter,Te.Tab;function Un(e){return!!(e&&"distance"in e)}function Jn(e){return!!(e&&"delay"in e)}class ln{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=Dt(o),this.documentListeners=new Xt(this.document),this.listeners=new Xt(r),this.windowListeners=new Xt(qe(o)),this.initialCoordinates=(a=Yn(s))!=null?a:Ut,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(Ee.Resize,this.handleCancel),this.windowListeners.add(Ee.DragStart,Kn),this.windowListeners.add(Ee.VisibilityChange,this.handleCancel),this.windowListeners.add(Ee.ContextMenu,Kn),this.documentListeners.add(Ee.Keydown,this.handleKeydown),n){if(r!=null&&r({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(Jn(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(Un(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(Ee.Click,oi,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ee.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=Yn(t))!=null?n:Ut,u=ei(a,c);if(!r&&l){if(Un(l)){if(l.tolerance!=null&&Ht(u,l.tolerance))return this.handleCancel();if(Ht(u,l.distance))return this.handleStart()}if(Jn(l)&&Ht(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===Te.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 Tr extends ln{constructor(t){const{event:n}=t,r=Dt(n.target);super(t,si,r)}}Tr.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 Jt;(function(e){e[e.RightClick=2]="RightClick"})(Jt||(Jt={}));class Wr extends ln{constructor(t){super(t,ii,Dt(t.event.target))}}Wr.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:r}=t;return n.button===Jt.RightClick?!1:(r?.({event:n}),!0)}}];const jt={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Fr extends ln{constructor(t){super(t,jt)}static setup(){return window.addEventListener(jt.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(jt.move.name,t)};function t(){}}}Fr.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 qn;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(qn||(qn={}));var Qn;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Qn||(Qn={}));Ue.Backward+"",Ue.Forward+"",Ue.Backward+"",Ue.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={}));qt.WhileDragging,Qt.Optimized;({...Ut});var er;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(er||(er={}));function li(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:r=5,mouseDistance:a=1}=e,s=zt(Wr,{activationConstraint:{distance:a}}),o=zt(Fr,{activationConstraint:t?{delay:n,tolerance:r}:{distance:a}}),l=zt(Tr,{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}=Ae(),o=i.useCallback((c,u,f)=>{const{sampleRate:C,samplesPerPixel:p}=e,d=t[c];if(!d)return!1;const g=d.clips[u];if(!g)return!1;const I=g.startSample/C,h=(g.startSample+g.durationSamples)/C;if(f<=I||f>=h)return console.warn("Split time is outside clip bounds"),!1;const b=Math.round(f*C),w=Math.floor(b/p),v=g.startSample+g.durationSamples,m=w*p,S=g.startSample,y=m-S,k=m,R=v-k,M=m-g.startSample,D=Kt({audioBuffer:g.audioBuffer,startSample:S,durationSamples:y,offsetSamples:g.offsetSamples,sampleRate:g.sampleRate,sourceDurationSamples:g.sourceDurationSamples,gain:g.gain,name:g.name?`${g.name} (1)`:void 0,color:g.color,fadeIn:g.fadeIn,waveformData:g.waveformData}),$=Kt({audioBuffer:g.audioBuffer,startSample:k,durationSamples:R,offsetSamples:g.offsetSamples+M,sampleRate:g.sampleRate,sourceDurationSamples:g.sourceDurationSamples,gain:g.gain,name:g.name?`${g.name} (2)`:void 0,color:g.color,waveformData:g.waveformData,fadeOut:g.fadeOut}),T=[...d.clips];T.splice(u,1,D,$);const W=[...t];return W[c]={...d,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(C=>C.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],f=a.current??0;for(let C=0;C<u.clips.length;C++){const p=u.clips[C],d=p.startSample/r,g=(p.startSample+p.durationSamples)/r;if(f>d&&f<g)return console.log(`Splitting clip on track "${u.name}" at ${f}s`),o(c,C,f)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,a,s,o,r]),splitClipAt:o}},xt=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,C=l.metaKey===void 0||a.metaKey===l.metaKey,p=l.altKey===void 0||a.altKey===l.altKey;return c&&u&&f&&C&&p});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}=he(),f=i.useCallback(()=>{a?l():o()},[a,o,l]),C=i.useCallback(()=>{c()},[c]),p=i.useCallback(()=>{a&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[a,u,s,o]),g=r??[...[{key:" ",action:f,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:C,description:"Stop",preventDefault:!0},{key:"0",action:p,description:"Rewind to start",preventDefault:!0}],...n];return xt({shortcuts:g,enabled:t}),{rewindToStart:p,togglePlayPause:f,stopPlayback:C,shortcuts:g}},Pt=.01,pt=.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:f,controlsWidth:C=0,onPlay:p}){const d=i.useMemo(()=>t?e.findIndex(M=>M.id===t):-1,[e,t]),g=i.useCallback(M=>{if(!c?.current||!u||!f)return;const D=e.find(V=>V.id===M);if(!D)return;const $=c.current,T=$.clientWidth,W=D.start*f/u+C,H=D.end*f/u+C,P=(W+H)/2,j=$.scrollLeft,N=j,Y=j+T;if(W<N||H>Y){const V=Math.max(0,P-T/2);$.scrollTo({left:V,behavior:"smooth"})}},[e,c,u,f,C]);i.useEffect(()=>{t&&c?.current&&u&&f&&g(t)},[t,g,c,u,f]);const I=i.useCallback(M=>{if(d<0)return;const D=e[d],$=Math.max(0,Math.min(D.end-.1,D.start+M)),T=$-D.start,W=[...e];if(W[d]={...D,start:$},s&&d>0){const H=W[d-1];Math.abs(H.end-D.start)<Pt&&(W[d-1]={...H,end:Math.max(H.start+.1,H.end+T)})}else if(!s&&d>0){const H=W[d-1];$<H.end&&(W[d-1]={...H,end:$})}n(W)},[e,d,s,n]),h=i.useCallback(M=>{if(d<0)return;const D=e[d],$=Math.max(D.start+.1,Math.min(a,D.end+M)),T=$-D.end,W=[...e];if(W[d]={...D,end:$},s&&d<e.length-1){const H=W[d+1];if(Math.abs(H.start-D.end)<Pt){const P=Math.min(H.end-.1,H.start+T);W[d+1]={...H,start:P};let j=d+1;for(;j<W.length-1;){const N=W[j],Y=W[j+1];if(Math.abs(Y.start-e[j].end)<Pt){const V=N.end-e[j].end;W[j+1]={...Y,start:Math.min(Y.end-.1,Y.start+V)},j++}else break}}}else if(!s&&d<e.length-1){const H=W[d+1];if($>H.start){W[d+1]={...H,start:$};let P=d+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,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]),w=i.useCallback(()=>{!r||e.length===0||(d<0||d>=e.length-1?r(e[0].id):r(e[d+1].id))},[e,d,r]),v=i.useCallback(()=>{!r||e.length===0||r(e[0].id)},[e,r]),m=i.useCallback(()=>{!r||e.length===0||r(e[e.length-1].id)},[e,r]),S=i.useCallback(()=>{r&&r(null)},[r]),y=i.useCallback(()=>{if(d<0||!p)return;const M=e[d],D=o?void 0:M.end-M.start;p(M.start,D)},[e,d,o,p]),k=i.useMemo(()=>[{key:"[",action:()=>I(-pt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>I(pt),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>h(-pt),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>h(pt),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:y,description:"Play selected annotation",preventDefault:!0}],[I,h,y]),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:w,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:w,description:"Select next annotation",preventDefault:!0},{key:"Home",action:v,description:"Select first annotation",preventDefault:!0},{key:"End",action:m,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:S,description:"Deselect annotation",preventDefault:!0}],[b,w,v,m,S]);return xt({shortcuts:k,enabled:l&&d>=0}),xt({shortcuts:R,enabled:l&&e.length>0&&!!r}),{moveStartBoundary:I,moveEndBoundary:h,selectPrevious:b,selectNext:w,selectFirst:v,selectLast:m,clearSelection:S,scrollToAnnotation:g,playActiveAnnotation:y}}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 tr(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 C=l;C<c;C++){const p=e[C];p<u&&(u=p),p>f&&(f=p)}a[o*2]=Math.floor(u*s),a[o*2+1]=Math.floor(f*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 f=n-o,C=Math.min(f,t.length);let p=e[e.length-2]/s,d=e[e.length-1]/s;for(let b=0;b<C;b++){const w=t[b];w<p&&(p=w),w>d&&(d=w)}const g=new(a===8?Int8Array:Int16Array)(e.length);g.set(e),g[e.length-2]=Math.floor(p*s),g[e.length-1]=Math.floor(d*s),l=C;const I=tr(t.slice(l),n,a),h=new(a===8?Int8Array:Int16Array)(g.length+I.length);return h.set(g),h.set(I,g.length),h}const c=tr(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),[f,C]=i.useState(new Int16Array(0)),[p,d]=i.useState(null),[g,I]=i.useState(null),[h,b]=i.useState(0),[w,v]=i.useState(0),m=16,S=i.useRef(!1),y=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 V=E.getContext(),O=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Wt&&Wt.tagName.toUpperCase()==="SCRIPT"&&Wt.src||new URL("index.js",document.baseURI).href).href;await V.addAudioWorkletModule(O),S.current=!0}catch(V){throw console.error("Failed to load AudioWorklet module:",V),new Error("Failed to load recording processor")}},[]),P=i.useCallback(async()=>{if(!e){I(new Error("No microphone stream available"));return}try{I(null);const V=E.getContext();V.state==="suspended"&&await V.resume(),await H();const O=V.createMediaStreamSource(e);k.current=O;const ne=V.createAudioWorkletNode("recording-processor");y.current=ne,O.connect(ne),ne.port.onmessage=K=>{const{samples:U}=K.data;R.current.push(U),M.current+=U.length,C(be=>pi(be,U,r,M.current-U.length,m))},ne.port.postMessage({command:"start",sampleRate:V.sampleRate,channelCount:n}),R.current=[],M.current=0,C(new Int16Array(0)),d(null),b(0),v(0),T.current=!0,W.current=!1,s(!0),l(!1),$.current=performance.now();const te=()=>{if(T.current&&!W.current){const K=(performance.now()-$.current)/1e3;u(K),D.current=requestAnimationFrame(te)}};te()}catch(V){console.error("Failed to start recording:",V),I(V instanceof Error?V:new Error("Failed to start recording"))}},[e,n,r,H,a,o]),j=i.useCallback(async()=>{if(!a)return null;try{if(y.current){if(y.current.port.postMessage({command:"stop"}),k.current)try{k.current.disconnect(y.current)}catch{}y.current.disconnect()}D.current!==null&&(cancelAnimationFrame(D.current),D.current=null);const V=hi(R.current),ne=E.getContext().rawContext,te=mi(ne,V,ne.sampleRate,n);return d(te),u(te.duration),T.current=!1,W.current=!1,s(!1),l(!1),b(0),te}catch(V){return console.error("Failed to stop recording:",V),I(V instanceof Error?V: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 V=()=>{if(T.current&&!W.current){const O=(performance.now()-$.current)/1e3;u(O),D.current=requestAnimationFrame(V)}};V()}},[a,o,c]);return i.useEffect(()=>()=>{if(y.current){if(y.current.port.postMessage({command:"stop"}),k.current)try{k.current.disconnect(y.current)}catch{}y.current.disconnect()}D.current!==null&&cancelAnimationFrame(D.current)},[]),{isRecording:a,isPaused:o,duration:c,peaks:f,audioBuffer:p,level:h,peakLevel:w,startRecording:P,stopRecording:j,pauseRecording:N,resumeRecording:Y,error:g}}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),f=i.useCallback(async()=>{try{const g=(await navigator.mediaDevices.enumerateDevices()).filter(I=>I.kind==="audioinput").map(I=>({deviceId:I.deviceId,label:I.label||`Microphone ${I.deviceId.slice(0,8)}`,groupId:I.groupId}));r(g)}catch(d){console.error("Failed to enumerate devices:",d),u(d instanceof Error?d:new Error("Failed to enumerate devices"))}},[]),C=i.useCallback(async(d,g)=>{l(!0),u(null);try{e&&e.getTracks().forEach(w=>w.stop());const h={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...g,...d&&{deviceId:{exact:d}}},video:!1},b=await navigator.mediaDevices.getUserMedia(h);t(b),s(!0),await f()}catch(I){console.error("Failed to access microphone:",I),u(I instanceof Error?I:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,f]),p=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:C,stopStream:p,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),f=i.useRef(null),C=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let p=!0;return(async()=>{if(!p)return;const g=E.getContext();if(g.state==="suspended"&&await g.resume(),!p)return;const I=new E.Meter({smoothing:r,context:g});c.current=I;const h=g.createMediaStreamSource(e);u.current=h,E.connect(h,I);const b=1e3/n;let w=0;const v=m=>{if(!(!p||!c.current)){if(m-w>=b){w=m;const S=c.current.getValue(),y=typeof S=="number"?S:S[0],k=Math.max(0,Math.min(1,(y+100)/100));s(k),l(R=>Math.max(R,k))}f.current=requestAnimationFrame(v)}};f.current=requestAnimationFrame(v)})(),()=>{if(p=!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:C}}A.button`
|
|
1066
|
+
`,Bo=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:a,children:r="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(w=>uo(w)),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 v.jsx(Do,{onClick:s,disabled:n||e.length===0,className:a,title:e.length===0?"No annotations to download":"Download the annotations as JSON",children:r})};function Hn(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>Je(r,e),parseTime:r=>$n(r,e)}}const To=[256,512,1024,2048,4096,8192];function Xn({initialSamplesPerPixel:e,zoomLevels:t=To}){const[n,a]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),r=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{a(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{a(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:r,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function Gn({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[a,r]=i.useState(t),s=i.useCallback(o=>{r(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:a,setMasterVolume:s}}const Wo=(e=256)=>{const t=i.useRef(null),n=i.useCallback((a,r,s)=>{const o=new W.Analyser("fft",e);return a.connect(o),a.connect(r),t.current=o,function(){o.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function Wt(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,f=t?.sampleRate??e.sampleRate??u?.sample_rate,w=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(w===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??w;return{id:Nn(),audioBuffer:t,startSample:n,durationSamples:g,offsetSamples:a,sampleRate:f,sourceDurationSamples:w,gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function _o(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,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 w=t?.duration??e.sourceDuration??u?.duration;if(w===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??w;return Wt({audioBuffer:t,startSample:Math.round(n*f),durationSamples:Math.round(g*f),offsetSamples:Math.round(a*f),sampleRate:f,sourceDurationSamples:Math.ceil(w*f),gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Fo(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Nn(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:o,color:l,height:c}}function Nn(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Zo(e,t={}){const{progressive:n=!1}=t,[a,r]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,f]=i.useState(0),w=e.length;return i.useEffect(()=>{if(e.length===0){r([]),o(!1),f(0);return}let g=!1;const d=new Map,x=(m,b,p)=>{const C=p??m.audioBuffer;if(!C&&!m.waveformData)throw new Error(`Track ${b+1}: Must provide src, audioBuffer, or waveformData`);const h=C?.duration??m.waveformData?.duration,k=_o({audioBuffer:C,startTime:m.startTime??0,duration:m.duration??h,offset:m.offset??0,name:m.name||`Track ${b+1}`,fadeIn:m.fadeIn,fadeOut:m.fadeOut,waveformData:m.waveformData});if(isNaN(k.startSample)||isNaN(k.durationSamples)||isNaN(k.offsetSamples))throw console.error("Invalid clip values:",k),new Error(`Invalid clip values for track ${b+1}`);return{...Fo({name:m.name||`Track ${b+1}`,clips:[k],muted:m.muted??!1,soloed:m.soloed??!1,volume:m.volume??1,pan:m.pan??0,color:m.color}),effects:m.effects}};return(async()=>{try{o(!0),c(null),f(0);const m=hn.getContext().rawContext,b=e.map(async(C,h)=>{if(C.audioBuffer){const E=x(C,h,C.audioBuffer);return n&&!g&&(d.set(h,E),f($=>$+1),r(Array.from({length:e.length},($,M)=>d.get(M)).filter($=>$!==void 0))),E}if(!C.src&&C.waveformData){const E=x(C,h);return n&&!g&&(d.set(h,E),f($=>$+1),r(Array.from({length:e.length},($,M)=>d.get(M)).filter($=>$!==void 0))),E}if(!C.src)throw new Error(`Track ${h+1}: Must provide src, audioBuffer, or waveformData`);const k=await fetch(C.src);if(!k.ok)throw new Error(`Failed to fetch ${C.src}: ${k.statusText}`);const y=await k.arrayBuffer(),S=await m.decodeAudioData(y);if(!S||!S.sampleRate||!S.duration)throw new Error(`Invalid audio buffer for ${C.src}`);const R=x(C,h,S);return n&&!g&&(d.set(h,R),f(E=>E+1),r(Array.from({length:e.length},(E,$)=>d.get($)).filter(E=>E!==void 0))),R}),p=await Promise.all(b);g||(n||(r(p),f(p.length)),o(!1))}catch(m){if(!g){const b=m instanceof Error?m.message:"Unknown error loading audio";c(b),o(!1),console.error("Error loading audio tracks:",m)}}})(),()=>{g=!0}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:w}}function Vo({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=i.useRef(null),s=i.useCallback(u=>{const{transform:f,active:w}=u;if(!w?.data?.current)return{...f,scaleX:1,scaleY:1};const{trackIndex:g,clipIndex:d,boundary:x}=w.data.current;if(x)return{...f,scaleX:1,scaleY:1};const I=e[g];if(!I)return{...f,scaleX:1,scaleY:1};const m=I.clips[d];if(!m)return{...f,scaleX:1,scaleY:1};const b=m.startSample/a,p=m.durationSamples/a,C=f.x*n/a;let h=b+C;const k=[...I.clips].sort((M,D)=>M.startSample-D.startSample),y=k.findIndex(M=>M===m);h=Math.max(0,h);const S=y>0?k[y-1]:null;if(S){const M=(S.startSample+S.durationSamples)/a;h=Math.max(h,M)}const R=y<k.length-1?k[y+1]:null;if(R){const M=h+p,D=R.startSample/a;M>D&&(h=D-p)}const $=(h-b)*a/n;return{...f,x:$,scaleX:1,scaleY:1}},[e,n,a]),o=i.useCallback(u=>{const{active:f}=u,{boundary:w}=f.data.current;if(!w){r.current=null;return}const{trackIndex:g,clipIndex:d}=f.data.current,I=e[g]?.clips[d];I&&(r.current={offsetSamples:I.offsetSamples,durationSamples:I.durationSamples,startSample:I.startSample})},[e]),l=i.useCallback(u=>{const{active:f,delta:w}=u,{boundary:g}=f.data.current;if(!g||!r.current)return;const{trackIndex:d,clipIndex:x}=f.data.current,I=w.x*n,m=Math.floor(.1*a),b=r.current,p=e.map((C,h)=>{if(h!==d)return C;const k=[...C.clips].sort((R,E)=>R.startSample-E.startSample),y=k.findIndex(R=>R===C.clips[x]),S=C.clips.map((R,E)=>{if(E!==x)return R;const $=R.sourceDurationSamples;if(g==="left"){let M=Math.floor(I);const D=-b.startSample;M<D&&(M=D);const _=-b.offsetSamples;M<_&&(M=_);const Z=y>0?k[y-1]:null;if(Z){const L=Z.startSample+Z.durationSamples-b.startSample;M<L&&(M=L)}const T=b.durationSamples-m;M>T&&(M=T);const P=b.offsetSamples+M,j=b.durationSamples-M,U=b.startSample+M;return{...R,offsetSamples:P,durationSamples:j,startSample:U}}else{let M=Math.floor(b.durationSamples+I);M=Math.max(m,M),b.offsetSamples+M>$&&(M=$-b.offsetSamples);const D=y<k.length-1?k[y+1]:null;return D&&b.startSample+M>D.startSample&&(M=D.startSample-b.startSample,M=Math.max(m,M)),{...R,durationSamples:M}}});return{...C,clips:S}});t(p)},[e,t,n,a]),c=i.useCallback(u=>{const{active:f,delta:w}=u,{trackIndex:g,clipIndex:d,boundary:x}=f.data.current,I=w.x*n;if(x){r.current=null;return}const m=e.map((b,p)=>{if(p!==g)return b;const C=[...b.clips].sort((y,S)=>y.startSample-S.startSample),h=C.findIndex(y=>y===b.clips[d]),k=b.clips.map((y,S)=>{if(S!==d)return y;let R=Math.floor(y.startSample+I);R=Math.max(0,R);const E=h>0?C[h-1]:null;if(E){const M=E.startSample+E.durationSamples;R=Math.max(R,M)}const $=h<C.length-1?C[h+1]:null;return $&&R+y.durationSamples>$.startSample&&(R=$.startSample-y.durationSamples),{...y,startSample:R}});return{...b,clips:k}});t(m)},[e,t,n,a]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Et=.01;function Ln({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(f=>{const{active:w}=f,g=w.data.current;if(!g||g.annotationIndex===void 0){o.current=null;return}const d=e[g.annotationIndex];d&&(o.current={start:d.start,end:d.end,annotationIndex:g.annotationIndex})},[e]),c=i.useCallback(f=>{const{active:w,delta:g}=f;if(!o.current)return;const d=w.data.current;if(!d)return;const{edge:x,annotationIndex:I}=d,m=o.current,b=g.x*n/a,p=x==="start"?m.start+b:m.end+b,C=Po({annotationIndex:I,newTime:p,isDraggingStart:x==="start",annotations:e,duration:r,linkEndpoints:s});t(C)},[e,t,n,a,r,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Po({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const o=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const f=o[e-1];Math.abs(f.end-l.start)<Et?o[e-1]={...f,end:Math.max(f.start+.1,f.end+u)}:c<=f.end&&(o[e]={...o[e],start:f.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const f=o[e+1];if(Math.abs(f.start-l.end)<Et){const w=f.start+u;o[e+1]={...f,start:Math.min(f.end-.1,w)};let g=e+1;for(;g<o.length-1;){const d=o[g],x=o[g+1];if(Math.abs(x.start-d.end)<Et){const I=d.end-a[g].end;o[g+1]={...x,start:Math.min(x.end-.1,x.start+I)},g++}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 w=e+1;for(;w<o.length-1;){const g=o[w],d=o[w+1];if(g.end>d.start)o[w+1]={...d,start:g.end},w++;else break}}}return o}function zo(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Re.useSensor(Re.MouseSensor,{activationConstraint:{distance:r}}),o=Re.useSensor(Re.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Re.useSensor(Re.PointerSensor,{activationConstraint:{distance:r}});return Re.useSensors(...t?[s,o]:[l])}const jo=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Ie(),{selectedTrackId:s}=Te(),o=i.useCallback((c,u,f)=>{const{sampleRate:w,samplesPerPixel:g}=e,d=t[c];if(!d)return!1;const x=d.clips[u];if(!x)return!1;const I=x.startSample/w,m=(x.startSample+x.durationSamples)/w;if(f<=I||f>=m)return console.warn("Split time is outside clip bounds"),!1;const b=Math.round(f*w),p=Math.floor(b/g),C=x.startSample+x.durationSamples,h=p*g,k=x.startSample,y=h-k,S=h,R=C-S,E=h-x.startSample,$=Wt({audioBuffer:x.audioBuffer,startSample:k,durationSamples:y,offsetSamples:x.offsetSamples,sampleRate:x.sampleRate,sourceDurationSamples:x.sourceDurationSamples,gain:x.gain,name:x.name?`${x.name} (1)`:void 0,color:x.color,fadeIn:x.fadeIn,waveformData:x.waveformData}),M=Wt({audioBuffer:x.audioBuffer,startSample:S,durationSamples:R,offsetSamples:x.offsetSamples+E,sampleRate:x.sampleRate,sourceDurationSamples:x.sourceDurationSamples,gain:x.gain,name:x.name?`${x.name} (2)`:void 0,color:x.color,waveformData:x.waveformData,fadeOut:x.fadeOut}),D=[...d.clips];D.splice(u,1,$,M);const _=[...t];return _[c]={...d,clips:D},n(_),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(w=>w.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],f=r.current??0;for(let w=0;w<u.clips.length;w++){const g=u.clips[w],d=g.startSample/a,x=(g.startSample+g.durationSamples)/a;if(f>d&&f<x)return console.log(`Splitting clip on track "${u.name}" at ${f}s`),o(c,w,f)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,o,a]),splitClipAt:o}},vt=e=>{const{shortcuts:t,enabled:n=!0}=e,a=i.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,f=l.shiftKey===void 0||r.shiftKey===l.shiftKey,w=l.metaKey===void 0||r.metaKey===l.metaKey,g=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&f&&w&&g});o&&(o.preventDefault!==!1&&r.preventDefault(),o.action())},[t,n]);i.useEffect(()=>{if(n)return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[a,n])},Ho=e=>{const t=[],n=typeof navigator<"u"&&navigator.platform.includes("Mac");return e.metaKey&&t.push(n?"Cmd":"Ctrl"),e.ctrlKey&&!e.metaKey&&t.push("Ctrl"),e.altKey&&t.push(n?"Option":"Alt"),e.shiftKey&&t.push("Shift"),t.push(e.key.toUpperCase()),t.join("+")},Xo=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Ie(),{setCurrentTime:s,play:o,pause:l,stop:c}=he(),{playoutRef:u}=we(),f=i.useCallback(()=>{r?l():o()},[r,o,l]),w=i.useCallback(()=>{c()},[c]),g=i.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[r,u,s,o]),x=a??[...[{key:" ",action:f,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:w,description:"Stop",preventDefault:!0},{key:"0",action:g,description:"Rewind to start",preventDefault:!0}],...n];return vt({shortcuts:x,enabled:t}),{rewindToStart:g,togglePlayPause:f,stopPlayback:w,shortcuts:x}},Dt=.01,ht=.01;function Go({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:f,controlsWidth:w=0,onPlay:g}){const d=i.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),x=i.useCallback(E=>{if(!c?.current||!u||!f)return;const $=e.find(V=>V.id===E);if(!$)return;const M=c.current,D=M.clientWidth,_=$.start*f/u+w,Z=$.end*f/u+w,T=(_+Z)/2,P=M.scrollLeft,j=P,U=P+D;if(_<j||Z>U){const V=Math.max(0,T-D/2);M.scrollTo({left:V,behavior:"smooth"})}},[e,c,u,f,w]);i.useEffect(()=>{t&&c?.current&&u&&f&&x(t)},[t,x,c,u,f]);const I=i.useCallback(E=>{if(d<0)return;const $=e[d],M=Math.max(0,Math.min($.end-.1,$.start+E)),D=M-$.start,_=[...e];if(_[d]={...$,start:M},s&&d>0){const Z=_[d-1];Math.abs(Z.end-$.start)<Dt&&(_[d-1]={...Z,end:Math.max(Z.start+.1,Z.end+D)})}else if(!s&&d>0){const Z=_[d-1];M<Z.end&&(_[d-1]={...Z,end:M})}n(_)},[e,d,s,n]),m=i.useCallback(E=>{if(d<0)return;const $=e[d],M=Math.max($.start+.1,Math.min(r,$.end+E)),D=M-$.end,_=[...e];if(_[d]={...$,end:M},s&&d<e.length-1){const Z=_[d+1];if(Math.abs(Z.start-$.end)<Dt){const T=Math.min(Z.end-.1,Z.start+D);_[d+1]={...Z,start:T};let P=d+1;for(;P<_.length-1;){const j=_[P],U=_[P+1];if(Math.abs(U.start-e[P].end)<Dt){const V=j.end-e[P].end;_[P+1]={...U,start:Math.min(U.end-.1,U.start+V)},P++}else break}}}else if(!s&&d<e.length-1){const Z=_[d+1];if(M>Z.start){_[d+1]={...Z,start:M};let T=d+1;for(;T<_.length-1;){const P=_[T],j=_[T+1];if(P.end>j.start)_[T+1]={...j,start:P.end},T++;else break}}}n(_)},[e,d,r,s,n]),b=i.useCallback(()=>{!a||e.length===0||(d<=0?a(e[e.length-1].id):a(e[d-1].id))},[e,d,a]),p=i.useCallback(()=>{!a||e.length===0||(d<0||d>=e.length-1?a(e[0].id):a(e[d+1].id))},[e,d,a]),C=i.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),h=i.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),k=i.useCallback(()=>{a&&a(null)},[a]),y=i.useCallback(()=>{if(d<0||!g)return;const E=e[d],$=o?void 0:E.end-E.start;g(E.start,$)},[e,d,o,g]),S=i.useMemo(()=>[{key:"[",action:()=>I(-ht),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>I(ht),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>m(-ht),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>m(ht),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:y,description:"Play selected annotation",preventDefault:!0}],[I,m,y]),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:p,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:p,description:"Select next annotation",preventDefault:!0},{key:"Home",action:C,description:"Select first annotation",preventDefault:!0},{key:"End",action:h,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:k,description:"Deselect annotation",preventDefault:!0}],[b,p,C,h,k]);return vt({shortcuts:S,enabled:l&&d>=0}),vt({shortcuts:R,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:I,moveEndBoundary:m,selectPrevious:b,selectNext:p,selectFirst:C,selectLast:h,clearSelection:k,scrollToAnnotation:x,playActiveAnnotation:y}}function No(e){const t=e.reduce((r,s)=>r+s.length,0),n=new Float32Array(t);let a=0;for(const r of e)n.set(r,a),a+=r.length;return n}function Lo(e,t,n,a=1){const r=e.createBuffer(a,t.length,n),s=new Float32Array(t);return r.copyToChannel(s,0),r}function ln(e,t,n=16){const a=Math.ceil(e.length/t),r=n===8?new Int8Array(a*2):new Int16Array(a*2),s=2**(n-1);for(let o=0;o<a;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,f=0;for(let w=l;w<c;w++){const g=e[w];g<u&&(u=g),g>f&&(f=g)}r[o*2]=Math.floor(u*s),r[o*2+1]=Math.floor(f*s)}return r}function Yo(e,t,n,a,r=16){const s=2**(r-1),o=a%n;let l=0;if(o>0&&e.length>0){const f=n-o,w=Math.min(f,t.length);let g=e[e.length-2]/s,d=e[e.length-1]/s;for(let b=0;b<w;b++){const p=t[b];p<g&&(g=p),p>d&&(d=p)}const x=new(r===8?Int8Array:Int16Array)(e.length);x.set(e),x[e.length-2]=Math.floor(g*s),x[e.length-1]=Math.floor(d*s),l=w;const I=ln(t.slice(l),n,r),m=new(r===8?Int8Array:Int16Array)(x.length+I.length);return m.set(x),m.set(I,x.length),m}const c=ln(t.slice(l),n,r),u=new(r===8?Int8Array:Int16Array)(e.length+c.length);return u.set(e),u.set(c,e.length),u}function Oo(e,t={}){const{channelCount:n=1,samplesPerPixel:a=1024}=t,[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[f,w]=i.useState(new Int16Array(0)),[g,d]=i.useState(null),[x,I]=i.useState(null),[m,b]=i.useState(0),[p,C]=i.useState(0),h=16,k=i.useRef(!1),y=i.useRef(null),S=i.useRef(null),R=i.useRef([]),E=i.useRef(0),$=i.useRef(null),M=i.useRef(0),D=i.useRef(!1),_=i.useRef(!1),Z=i.useCallback(async()=>{if(!k.current)try{const V=W.getContext(),L=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Mt&&Mt.tagName.toUpperCase()==="SCRIPT"&&Mt.src||new URL("index.js",document.baseURI).href).href;await V.addAudioWorkletModule(L),k.current=!0}catch(V){throw console.error("Failed to load AudioWorklet module:",V),new Error("Failed to load recording processor")}},[]),T=i.useCallback(async()=>{if(!e){I(new Error("No microphone stream available"));return}try{I(null);const V=W.getContext();V.state==="suspended"&&await V.resume(),await Z();const L=V.createMediaStreamSource(e);S.current=L;const re=V.createAudioWorkletNode("recording-processor");y.current=re,L.connect(re),re.port.onmessage=Q=>{const{samples:q}=Q.data;R.current.push(q),E.current+=q.length,w(be=>Yo(be,q,a,E.current-q.length,h))},re.port.postMessage({command:"start",sampleRate:V.sampleRate,channelCount:n}),R.current=[],E.current=0,w(new Int16Array(0)),d(null),b(0),C(0),D.current=!0,_.current=!1,s(!0),l(!1),M.current=performance.now();const te=()=>{if(D.current&&!_.current){const Q=(performance.now()-M.current)/1e3;u(Q),$.current=requestAnimationFrame(te)}};te()}catch(V){console.error("Failed to start recording:",V),I(V instanceof Error?V:new Error("Failed to start recording"))}},[e,n,a,Z,r,o]),P=i.useCallback(async()=>{if(!r)return null;try{if(y.current){if(y.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(y.current)}catch{}y.current.disconnect()}$.current!==null&&(cancelAnimationFrame($.current),$.current=null);const V=No(R.current),re=W.getContext().rawContext,te=Lo(re,V,re.sampleRate,n);return d(te),u(te.duration),D.current=!1,_.current=!1,s(!1),l(!1),b(0),te}catch(V){return console.error("Failed to stop recording:",V),I(V instanceof Error?V:new Error("Failed to stop recording")),null}},[r,n]),j=i.useCallback(()=>{r&&!o&&($.current!==null&&(cancelAnimationFrame($.current),$.current=null),_.current=!0,l(!0))},[r,o]),U=i.useCallback(()=>{if(r&&o){_.current=!1,l(!1),M.current=performance.now()-c*1e3;const V=()=>{if(D.current&&!_.current){const L=(performance.now()-M.current)/1e3;u(L),$.current=requestAnimationFrame(V)}};V()}},[r,o,c]);return i.useEffect(()=>()=>{if(y.current){if(y.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(y.current)}catch{}y.current.disconnect()}$.current!==null&&cancelAnimationFrame($.current)},[]),{isRecording:r,isPaused:o,duration:c,peaks:f,audioBuffer:g,level:m,peakLevel:p,startRecording:T,stopRecording:P,pauseRecording:j,resumeRecording:U,error:x}}function Ko(){const[e,t]=i.useState(null),[n,a]=i.useState([]),[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),f=i.useCallback(async()=>{try{const x=(await navigator.mediaDevices.enumerateDevices()).filter(I=>I.kind==="audioinput").map(I=>({deviceId:I.deviceId,label:I.label||`Microphone ${I.deviceId.slice(0,8)}`,groupId:I.groupId}));a(x)}catch(d){console.error("Failed to enumerate devices:",d),u(d instanceof Error?d:new Error("Failed to enumerate devices"))}},[]),w=i.useCallback(async(d,x)=>{l(!0),u(null);try{e&&e.getTracks().forEach(p=>p.stop());const m={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...x,...d&&{deviceId:{exact:d}}},video:!1},b=await navigator.mediaDevices.getUserMedia(m);t(b),s(!0),await f()}catch(I){console.error("Failed to access microphone:",I),u(I instanceof Error?I:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,f]),g=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:r,isLoading:o,requestAccess:w,stopStream:g,error:c}}function Uo(e,t={}){const{updateRate:n=60,smoothingTimeConstant:a=.8}=t,[r,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),f=i.useRef(null),w=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let g=!0;return(async()=>{if(!g)return;const x=W.getContext();if(x.state==="suspended"&&await x.resume(),!g)return;const I=new W.Meter({smoothing:a,context:x});c.current=I;const m=x.createMediaStreamSource(e);u.current=m,W.connect(m,I);const b=1e3/n;let p=0;const C=h=>{if(!(!g||!c.current)){if(h-p>=b){p=h;const k=c.current.getValue(),y=typeof k=="number"?k:k[0],S=Math.max(0,Math.min(1,(y+100)/100));s(S),l(R=>Math.max(R,S))}f.current=requestAnimationFrame(C)}};f.current=requestAnimationFrame(C)})(),()=>{if(g=!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,a,n]),{level:r,peakLevel:o,resetPeak:w}}A.button`
|
|
1067
1067
|
padding: 0.5rem 1rem;
|
|
1068
1068
|
font-size: 0.875rem;
|
|
1069
1069
|
font-weight: 500;
|
|
@@ -1111,9 +1111,9 @@
|
|
|
1111
1111
|
opacity: 0.3;
|
|
1112
1112
|
}
|
|
1113
1113
|
}
|
|
1114
|
-
`;A(
|
|
1114
|
+
`;A(Zt)`
|
|
1115
1115
|
min-width: 200px;
|
|
1116
|
-
`;A(
|
|
1116
|
+
`;A(Cn)`
|
|
1117
1117
|
display: flex;
|
|
1118
1118
|
flex-direction: column;
|
|
1119
1119
|
gap: 0.25rem;
|
|
@@ -1156,7 +1156,7 @@
|
|
|
1156
1156
|
font-weight: 500;
|
|
1157
1157
|
color: ${e=>e.$isPaused?"#ffc107":"#dc3545"};
|
|
1158
1158
|
text-transform: uppercase;
|
|
1159
|
-
`;var
|
|
1159
|
+
`;var Jo=A.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
|
-
`,
|
|
1167
|
+
`,qo=e=>e<.6?"linear-gradient(90deg, #27ae60, #2ecc71)":e<.85?"linear-gradient(90deg, #f39c12, #f1c40f)":"linear-gradient(90deg, #c0392b, #e74c3c)",Qo=A.div.attrs(e=>({style:{width:`${e.$level*100}%`,height:`${e.$height}px`,background:qo(e.$level),boxShadow:e.$level>.01?"0 0 8px rgba(255, 255, 255, 0.3)":"none"}}))`
|
|
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
|
-
`,
|
|
1172
|
+
`,es=A.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
|
-
`,
|
|
1179
|
+
`,ts=A.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
|
-
`,
|
|
1186
|
+
`,cn=A.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(nr,{$position:60,$height:r}),x.jsx(nr,{$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,f]=i.useState(null),{stream:C,devices:p,hasPermission:d,requestAccess:g,error:I}=bi(),{level:h,peakLevel:b}=vi(C),{isRecording:w,isPaused:v,duration:m,peaks:S,startRecording:y,stopRecording:k,pauseRecording:R,resumeRecording:M,error:D}=gi(C,o),$=i.useCallback(async()=>{n&&(l||(await Ft(),c(!0)),await y())},[n,l,y]),T=i.useCallback(async()=>{const P=await k();if(P&&n){const j=e.findIndex(K=>K.id===n);if(j===-1)return;const N=e[j],Y=Math.floor(a*P.sampleRate);let V=0;if(N.clips.length>0){const K=N.clips.map(U=>U.startSample+U.durationSamples);V=Math.max(...K)}const O=Math.max(Y,V),ne={id:`clip-${Date.now()}`,audioBuffer:P,startSample:O,durationSamples:P.length,offsetSamples:0,sampleRate:P.sampleRate,sourceDurationSamples:P.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},te=e.map((K,U)=>U===j?{...K,clips:[...K.clips,ne]}:K);t(te)}},[n,e,t,a,k]);i.useEffect(()=>{d&&p.length>0&&u===null&&f(p[0].deviceId)},[d,p.length]);const W=i.useCallback(async()=>{await g(void 0,s),await Ft(),c(!0)},[g,s]),H=i.useCallback(async P=>{f(P),await g(P,s),await Ft(),c(!0)},[g,s]);return{isRecording:w,isPaused:v,duration:m,level:h,peakLevel:b,error:I||D,stream:C,devices:p,hasPermission:d,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}]}],cn=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(h=>{const b=o.current;if(!b)return;const{masterGainNode:w,destination:v,analyserNode:m}=b;try{w.disconnect()}catch{}const S=h.map(y=>a.current.get(y.instanceId)).filter(y=>y!==void 0);if(S.length===0)w.connect(m),m.connect(v);else{let y=w;S.forEach(k=>{try{k.disconnect()}catch{}y.connect(k.effect),y=k.effect}),y.connect(m),m.connect(v)}},[]),c=i.useCallback(h=>{const b=cn(h);if(!b){console.error(`Unknown effect: ${h}`);return}const w={};b.parameters.forEach(S=>{w[S.name]=S.default});const v=rt(b,w);a.current.set(v.instanceId,v);const m={instanceId:v.instanceId,effectId:b.id,definition:b,params:w,bypassed:!1};n(S=>[...S,m])},[]),u=i.useCallback(h=>{const b=a.current.get(h);b&&(b.dispose(),a.current.delete(h)),n(w=>w.filter(v=>v.instanceId!==h))},[]),f=i.useCallback((h,b,w)=>{const v=a.current.get(h);v&&v.setParameter(b,w),n(m=>m.map(S=>S.instanceId===h?{...S,params:{...S.params,[b]:w}}:S))},[]),C=i.useCallback(h=>{const b=r.current.find(m=>m.instanceId===h);if(!b)return;const w=!b.bypassed,v=a.current.get(h);if(v){const m=b.params.wet??1;v.setParameter("wet",w?0:m)}n(m=>m.map(S=>S.instanceId===h?{...S,bypassed:w}:S))},[]),p=i.useCallback((h,b)=>{n(w=>{const v=[...w],[m]=v.splice(h,1);return v.splice(b,0,m),v})},[]),d=i.useCallback(()=>{a.current.forEach(h=>h.dispose()),a.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const g=i.useCallback((h,b,w)=>{const v=new E.Analyser("fft",e);s.current=v,o.current={masterGainNode:h,destination:b,analyserNode:v};const S=r.current.map(y=>a.current.get(y.instanceId)).filter(y=>y!==void 0);if(S.length===0)h.connect(v),v.connect(b);else{let y=h;S.forEach(k=>{y.connect(k.effect),y=k.effect}),y.connect(v),v.connect(b)}return function(){v.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{a.current.forEach(h=>h.dispose()),a.current.clear()},[]);const I=i.useCallback(()=>{const h=t.filter(b=>!b.bypassed);if(h.length!==0)return(b,w,v)=>{const m=[];for(const S of h){const y=rt(S.definition,S.params);m.push(y)}if(m.length===0)b.connect(w);else{let S=b;m.forEach(y=>{S.connect(y.effect),S=y.effect}),S.connect(w)}return function(){m.forEach(y=>y.dispose())}}},[t]);return{activeEffects:t,availableEffects:at,addEffect:c,removeEffect:u,updateParameter:f,toggleBypass:C,reorderEffects:p,clearAllEffects:d,masterEffects:g,createOfflineEffectsFunction:I,analyserRef:s}}function Ti(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),r=i.useRef(new Map),a=i.useCallback((d,g)=>{const I=r.current.get(d);if(!I)return;const{graphEnd:h,masterGainNode:b}=I,w=n.current.get(d);try{h.disconnect()}catch{}const v=g.map(m=>w?.get(m.instanceId)).filter(m=>m!==void 0);if(v.length===0)h.connect(b);else{let m=h;v.forEach(S=>{try{S.disconnect()}catch{}m.connect(S.effect),m=S.effect}),m.connect(b)}},[]),s=i.useCallback((d,g)=>{const I=cn(g);if(!I){console.error(`Unknown effect: ${g}`);return}const h={};I.parameters.forEach(v=>{h[v.name]=v.default});const b=rt(I,h);n.current.has(d)||n.current.set(d,new Map),n.current.get(d).set(b.instanceId,b);const w={instanceId:b.instanceId,effectId:I.id,definition:I,params:h,bypassed:!1};t(v=>{const m=new Map(v),S=m.get(d)||[];return m.set(d,[...S,w]),m})},[]),o=i.useCallback((d,g)=>{const I=n.current.get(d),h=I?.get(g);h&&(h.dispose(),I?.delete(g)),t(b=>{const w=new Map(b),v=w.get(d)||[];return w.set(d,v.filter(m=>m.instanceId!==g)),w})},[]),l=i.useCallback((d,g,I,h)=>{const w=n.current.get(d)?.get(g);w&&w.setParameter(I,h),t(v=>{const m=new Map(v),S=m.get(d)||[];return m.set(d,S.map(y=>y.instanceId===g?{...y,params:{...y.params,[I]:h}}:y)),m})},[]),c=i.useCallback((d,g)=>{const h=(f.current.get(d)||[]).find(m=>m.instanceId===g);if(!h)return;const b=!h.bypassed,v=n.current.get(d)?.get(g);if(v){const m=h.params.wet??1;v.setParameter("wet",b?0:m)}t(m=>{const S=new Map(m),y=S.get(d)||[];return S.set(d,y.map(k=>k.instanceId===g?{...k,bypassed:b}:k)),S})},[]),u=i.useCallback(d=>{const g=n.current.get(d);g&&(g.forEach(I=>I.dispose()),g.clear()),t(I=>{const h=new Map(I);return h.set(d,[]),h})},[]),f=i.useRef(e);f.current=e;const C=i.useCallback(d=>(g,I,h)=>{r.current.set(d,{graphEnd:g,masterGainNode:I});const b=f.current.get(d)||[],w=n.current.get(d),v=b.map(m=>w?.get(m.instanceId)).filter(m=>m!==void 0);if(v.length===0)g.connect(I);else{let m=g;v.forEach(S=>{m.connect(S.effect),m=S.effect}),m.connect(I)}return function(){r.current.delete(d)}},[]);i.useEffect(()=>{e.forEach((d,g)=>{a(g,d)})},[e,a]),i.useEffect(()=>()=>{n.current.forEach(d=>{d.forEach(g=>g.dispose()),d.clear()}),n.current.clear()},[]);const p=i.useCallback(d=>{const I=(e.get(d)||[]).filter(h=>!h.bypassed);if(I.length!==0)return(h,b,w)=>{const v=[];for(const m of I){const S=rt(m.definition,m.params);v.push(S)}if(v.length===0)h.connect(b);else{let m=h;v.forEach(S=>{m.connect(S.effect),m=S.effect}),m.connect(b)}return function(){v.forEach(S=>S.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:C,createOfflineTrackEffectsFunction:p,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,f=44,C=f+u,p=new ArrayBuffer(C),d=new DataView(p);gt(d,0,"RIFF"),d.setUint32(4,C-8,!0),gt(d,8,"WAVE"),gt(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),gt(d,36,"data"),d.setUint32(40,u,!0);const g=[];for(let h=0;h<r;h++)g.push(e.getChannelData(h));let I=f;if(n===16)for(let h=0;h<s;h++)for(let b=0;b<r;b++){const w=g[b][h],v=Math.max(-1,Math.min(1,w)),m=v<0?v*32768:v*32767;d.setInt16(I,m,!0),I+=2}else for(let h=0;h<s;h++)for(let b=0;b<r;b++)d.setFloat32(I,g[b][h],!0),I+=4;return new Blob([p],{type:"audio/wav"})}function gt(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 Zr(){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:C="master",trackIndex:p,autoDownload:d=!0,applyEffects:g=!0,effectsFunction:I,createOfflineTrackEffects:h,bitDepth:b=16,onProgress:w}=u;t(!0),r(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(C==="individual"&&(p===void 0||p<0||p>=l.length))throw new Error("Invalid track index for individual export");const v=l[0].clips[0]?.sampleRate||44100;let m=0;for(const $ of l)for(const T of $.clips){const W=T.startSample+T.durationSamples;m=Math.max(m,W)}m+=Math.round(v*.1);const S=m/v,y=C==="individual"?[{track:l[p],state:c[p],index:p}]:l.map(($,T)=>({track:$,state:c[T],index:T})),k=c.some($=>$.soloed),R=!!h;let M;if((I||R)&&g)M=await Zi(y,c,k,S,v,I,h,$=>{r($),w?.($)});else{const $=new OfflineAudioContext(2,m,v);let T=0;const W=y.reduce((H,{track:P})=>H+P.clips.length,0);for(const{track:H,state:P}of y)if(!(P.muted&&!P.soloed)&&!(k&&!P.soloed))for(const j of H.clips){await Vi($,j,P,v,g),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:b});if(r(1),w?.(1),d){const $=C==="individual"?`${f}_${l[p].name}`:f;Fi(D,`${$}.wav`)}return{audioBuffer:M,blob:D,duration:S}}catch(v){const m=v instanceof Error?v.message:"Export failed";throw s(m),v}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:f,Panner:C,Player:p,ToneAudioBuffer:d}=await import("tone");l(.1);let g;try{g=await c(async({transport:I,destination:h})=>{const b=new u(0);let w;s?w=s(b,h,!0):b.connect(h);for(const{track:v,state:m}of e){if(m.muted&&!m.soloed||n&&!m.soloed)continue;const S=new u(_i(m.volume)),y=new C(m.pan),k=new f(m.muted?0:1),R=o?.(v.id);R?R(k,b,!0):k.connect(b),y.connect(k),S.connect(y);for(const M of v.clips){const{audioBuffer:D,startSample:$,durationSamples:T,offsetSamples:W,gain:H,fadeIn:P,fadeOut:j}=M,N=$/a,Y=T/a,V=W/a,O=new d(D),ne=new p(O),te=new f(H);if(ne.connect(te),te.connect(S),P){const K=N,U=N+P.duration,be=te.gain._param;be.setValueAtTime(0,K),be.linearRampToValueAtTime(H,U)}if(j){const K=N+Y-j.duration,U=N+Y,be=te.gain._param;be.setValueAtTime(H,K),be.linearRampToValueAtTime(0,U)}ne.start(N,V,Y)}}I.start(0)},r,2,a)}catch(I){throw I instanceof Error?I:new Error(`Tone.Offline rendering failed: ${String(I)}`)}return l(.9),g.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:f,fadeOut:C}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const p=o/r,d=l/r,g=c/r,I=e.createBufferSource();I.buffer=s;const h=e.createGain(),b=u*n.volume,w=e.createStereoPanner();if(w.pan.value=n.pan,I.connect(h),h.connect(w),w.connect(e.destination),a){if(f?h.gain.setValueAtTime(0,p):h.gain.setValueAtTime(b,p),f){const v=p,m=p+f.duration;rr(h.gain,v,m,0,b,f.type||"linear")}if(C){const v=p+d-C.duration,m=p+d;(!f||f.duration<d-C.duration)&&h.gain.setValueAtTime(b,v),rr(h.gain,v,m,b,0,C.type||"linear")}}else h.gain.setValueAtTime(b,p);I.start(p,g,d)}function rr(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=ar(r,a,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const f=ar(r,a,256,"sCurve");e.setValueCurveAtTime(f,t,o);break;default:e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n)}}function ar(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 _r=i.createContext(null),Vr=i.createContext(null),zr=i.createContext(null),Xr=i.createContext(null),Hr=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:f,onReady:C,onAnnotationUpdate:p,barWidth:d=1,barGap:g=0,progressBarWidth:I,children:h})=>{const b=I??d+g,[w,v]=i.useState([]),[m,S]=i.useState(null),[y,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,V]=i.useState(0),[O,ne]=i.useState(0),[te,K]=i.useState(null),[U,be]=i.useState(o),[ze,Ge]=i.useState(u?.isContinuousPlay??!1),[Mt,Xe]=i.useState(u?.linkEndpoints??!0),[Rt,se]=i.useState(u?.editable??!1),[ie,ot]=i.useState(!1),[st,J]=i.useState(0),[Le,Bt]=i.useState(0),F=i.useRef(null),ve=i.useRef(0),le=i.useRef(0),de=i.useRef(null),it=i.useRef(j),Ce=i.useRef(0),me=i.useRef(0),We=i.useRef(null),Me=i.useRef(null),lt=i.useRef(!1),ct=i.useRef(u?.isContinuousPlay??!1),He=i.useRef(null),ut=i.useRef(a),z=i.useRef(!1),L=i.useRef(0),ee=i.useRef(0),re=i.useRef(0),ue=i.useRef(0),{timeFormat:ke,setTimeFormat:q,formatTime:Re}=Dr(),we=Mr({initialSamplesPerPixel:a,zoomLevels:s}),pe=we.samplesPerPixel,{masterVolume:Fe,setMasterVolume:Ne}=Rr({playoutRef:F,initialVolume:1}),Qe=i.useCallback(B=>{ct.current=B,Ge(B)},[]),Ze=i.useCallback(B=>{He.current=B,S(B)},[]),jr=i.useCallback(B=>{z.current=B,ot(B)},[]),et=i.useCallback((B,_)=>{re.current=B,ue.current=_,J(B),Bt(_)},[]),Pr=i.useCallback(()=>{const B=L.current,_=ee.current;B!==_&&_>B&&et(B,_)},[et]),Gr=i.useCallback(()=>{et(0,0)},[et]);i.useEffect(()=>{lt.current=U},[U]),i.useEffect(()=>{it.current=j},[j]),i.useEffect(()=>{L.current=Y,ee.current=O},[Y,O]),i.useEffect(()=>{if(!Me.current||!T.length)return;const B=Me.current,_=ut.current,G=pe;if(_===G)return;const Q=c.show?c.width:0,Z=B.clientWidth,De=B.scrollLeft+Z/2-Q,ae=T[0].sampleRate,xe=De*_/ae*ae/G,Be=Math.max(0,xe+Q-Z/2);B.scrollLeft=Be,ut.current=G},[pe,T,c]);const dt=i.useRef(null);i.useEffect(()=>{if(e.length===0){W([]),$(0),N([]),P([]),F.current&&(F.current.dispose(),F.current=null);return}const B=y,_=le.current;return F.current&&B&&(F.current.stop(),de.current&&(cancelAnimationFrame(de.current),de.current=null),dt.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(fe=>{const xe=fe.sampleRate,ft=(fe.startSample+fe.durationSamples)/xe;Z=Math.max(Z,ft)})}),W(Q),$(Z),N(ae=>ae.length===e.length?ae.map((fe,xe)=>({...fe,name:e[xe].name})):e.map(fe=>({name:fe.name,muted:fe.muted,soloed:fe.soloed,volume:fe.volume,pan:fe.pan}))),F.current&&F.current.dispose();const ce=new va({effects:f}),De=it.current;e.forEach((ae,fe)=>{const xe=ae.clips.filter(Be=>Be.audioBuffer);if(xe.length>0){const Be=xe[0].sampleRate,ft=Math.min(...xe.map(ye=>ye.startSample/Be)),aa=Math.max(...xe.map(ye=>(ye.startSample+ye.durationSamples)/Be)),ht=De[fe],oa={id:`track-${fe}`,name:ae.name,gain:ht?.volume??ae.volume,muted:ht?.muted??ae.muted,soloed:ht?.soloed??ae.soloed,stereoPan:ht?.pan??ae.pan,startTime:ft,endTime:aa},sa=xe.map(ye=>{const Tt=ye.sampleRate;return{buffer:ye.audioBuffer,startTime:ye.startSample/Tt-ft,duration:ye.durationSamples/Tt,offset:ye.offsetSamples/Tt,fadeIn:ye.fadeIn,fadeOut:ye.fadeOut,gain:ye.gain}});ce.addTrack({clips:sa,track:oa,effects:ae.effects})}}),ce.applyInitialSoloState(),F.current=ce,C?.()}catch(Q){console.error("Error loading audio:",Q)}})(),()=>{de.current&&cancelAnimationFrame(de.current),F.current&&F.current.dispose()}},[e,C,y]),i.useEffect(()=>{if(e.length===0)return;const B=16,_=e.map(G=>G.clips.map(Z=>{if(Z.waveformData){const De=ls(Z.waveformData,pe,0,Z.offsetSamples,Z.durationSamples);return{clipId:Z.id,trackName:G.name,peaks:{length:De.length,data:[De.data],bits:De.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 ce=Po(Z.audioBuffer,pe,n,B,Z.offsetSamples,Z.durationSamples);return{clipId:Z.id,trackName:G.name,peaks:ce,startSample:Z.startSample,durationSamples:Z.durationSamples,fadeIn:Z.fadeIn,fadeOut:Z.fadeOut}}));P(_)},[e,pe,n]),i.useEffect(()=>{if(u?.annotations){const B=u.annotations.map(_=>typeof _.start=="number"?_:gs(_));v(B)}},[u]);const je=i.useCallback(()=>{de.current&&(cancelAnimationFrame(de.current),de.current=null);const B=()=>{const _=E.getContext().currentTime-Ce.current,G=me.current+_;if(le.current=G,M(G),w.length>0){const Z=w.find(ce=>G>=ce.start&&G<ce.end);if(ct.current){if(Z&&Z.id!==He.current)Ze(Z.id);else if(!Z&&He.current!==null){const ce=w[w.length-1];if(G>=ce.end){F.current&&F.current.stop(),k(!1),le.current=ve.current,M(ve.current),Ze(null);return}}}else if(He.current){const ce=w.find(De=>De.id===He.current);if(ce&&G>=ce.end){F.current&&F.current.stop(),k(!1),le.current=ve.current,M(ve.current);return}}else Z&&Ze(Z.id)}if(lt.current&&Me.current&&T.length>0){const Z=Me.current,ce=T[0].sampleRate,De=G*ce/ut.current,ae=Z.clientWidth,fe=c.show?c.width:0,xe=De+fe,Be=Math.max(0,xe-ae/2);Z.scrollLeft=Be}if(We.current!==null&&G>=We.current){F.current&&F.current.stop(),k(!1),le.current=We.current,M(We.current),We.current=null;return}const Q=re.current!==ue.current&&ue.current>re.current;if(z.current&&Q&&G>=ue.current){F.current?.stop();const ce=E.getContext().currentTime;Ce.current=ce,me.current=re.current,le.current=re.current,F.current?.play(ce,re.current),de.current=requestAnimationFrame(B);return}if(G>=D){F.current&&F.current.stop(),k(!1),le.current=ve.current,M(ve.current),Ze(null);return}de.current=requestAnimationFrame(B)};de.current=requestAnimationFrame(B)},[D,T,pe,w,ze]),$e=i.useCallback(()=>{de.current&&(cancelAnimationFrame(de.current),de.current=null)},[]);i.useEffect(()=>{(async()=>{if(y&&de.current&&F.current)if(ze){const _=le.current;F.current.stop(),$e(),await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const Q=E.getContext().currentTime;Ce.current=Q,me.current=_,F.current.play(Q,_),je()}else $e(),je()})()},[ze,y,je,$e]),i.useEffect(()=>{(async()=>{if(dt.current&&F.current){const{position:_}=dt.current;dt.current=null,await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const Q=E.getContext().currentTime;Ce.current=Q,me.current=_,F.current.play(Q,_),k(!0),je()}})()},[e,je]);const Et=i.useCallback(async(B,_)=>{if(!F.current||T.length===0)return;await F.current.init(),await E.start();const G=B??le.current;ve.current=G,le.current=G,F.current.setOnPlaybackComplete(()=>{}),F.current.stop(),$e();const Z=E.getContext().currentTime;Ce.current=Z,me.current=G,We.current=_!==void 0?G+_:null,F.current.play(Z,G,_),k(!0),je()},[T.length,je,$e]),Lr=i.useCallback(()=>{if(!F.current)return;const B=E.getContext().currentTime-Ce.current,_=me.current+B;F.current.pause(),k(!1),$e(),le.current=_,M(_)},[$e]),Nr=i.useCallback(()=>{F.current&&(F.current.stop(),k(!1),$e(),le.current=ve.current,M(ve.current),Ze(null))},[$e]),Yr=i.useCallback(B=>{const _=Math.max(0,Math.min(B,D));le.current=_,M(_),y&&F.current&&(F.current.stop(),$e(),Et(_))},[D,y,Et,$e]),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,_)=>{V(B),ne(_),le.current=B,M(B),y&&F.current&&(F.current.stop(),F.current.play(E.getContext().currentTime,B))},[y]),Qr=i.useCallback(B=>{Me.current=B},[]),ea=T[0]?.sampleRate||44100,un=t?30:0,ta=e.length*r+un,dn={isPlaying:y,currentTime:R,currentTimeRef:le,playbackStartTimeRef:Ce,audioStartPositionRef:me},fn={continuousPlay:ze,linkEndpoints:Mt,annotationsEditable:Rt,isAutomaticScroll:U,isLoopEnabled:ie,annotations:w,activeAnnotationId:m,selectionStart:Y,selectionEnd:O,selectedTrackId:te,loopStart:st,loopEnd:Le},hn={play:Et,pause:Lr,stop:Nr,seekTo:Yr,setCurrentTime:B=>{le.current=B,M(B)},setTrackMute:Or,setTrackSolo:Kr,setTrackVolume:Ur,setTrackPan:Jr,setSelection:qr,setSelectedTrackId:K,setTimeFormat:q,formatTime:Re,zoomIn:we.zoomIn,zoomOut:we.zoomOut,setMasterVolume:Ne,setAutomaticScroll:B=>{be(B)},setScrollContainer:Qr,scrollContainerRef:Me,setContinuousPlay:Qe,setLinkEndpoints:Xe,setAnnotationsEditable:se,setAnnotations:v,setActiveAnnotationId:Ze,setLoopEnabled:jr,setLoopRegion:et,setLoopRegionFromSelection:Pr,clearLoopRegion:Gr},mn={duration:D,audioBuffers:T,peaksDataArray:H,trackStates:j,tracks:e,sampleRate:ea,waveHeight:r,timeScaleHeight:un,minimumPlaylistHeight:ta,controls:c,playoutRef:F,samplesPerPixel:pe,timeFormat:ke,masterVolume:Fe,canZoomIn:we.canZoomIn,canZoomOut:we.canZoomOut,barWidth:d,barGap:g,progressBarWidth:b},na={...dn,...fn,...hn,...mn},ra={...Wa,...l};return x.jsx(A.ThemeProvider,{theme:ra,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:mn,children:x.jsx(Hr.Provider,{value:na,children:h})})})})})})},ge=()=>{const e=i.useContext(_r);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Ae=()=>{const e=i.useContext(Vr);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},oe=()=>{const e=i.useContext(zr);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},he=()=>{const e=i.useContext(Xr);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},Xi=()=>{const e=i.useContext(Hr);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}=Ae(),{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(Se,{onClick:l,disabled:t,className:e,children:"Play"})},ji=({className:e})=>{const{isPlaying:t}=ge(),{pause:n}=oe();return x.jsx(Se,{onClick:n,disabled:!t,className:e,children:"Pause"})},Pi=({className:e})=>{const{isPlaying:t}=ge(),{stop:n}=oe();return x.jsx(Se,{onClick:n,disabled:!t,className:e,children:"Stop"})},Gi=({className:e})=>{const{isPlaying:t}=ge(),{play:n,setCurrentTime:r}=oe(),{playoutRef:a}=he(),s=()=>{r(0),t&&a.current&&(a.current.stop(),n(0))};return x.jsx(Se,{onClick:s,className:e,children:"Rewind"})},Li=({className:e})=>{const{isPlaying:t}=ge(),{play:n,setCurrentTime:r}=oe(),{duration:a,playoutRef:s}=he(),o=()=>{r(a),t&&s.current&&(s.current.stop(),n(a))};return x.jsx(Se,{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}=he(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),r&&o.current&&(o.current.stop(),a(c))};return x.jsx(Se,{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}=he(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),r&&l.current&&(l.current.stop(),a(u))};return x.jsx(Se,{onClick:c,className:t,children:"Skip Forward"})},Oi=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:r}=Ae(),{setLoopEnabled:a,setLoopRegion:s}=oe(),{duration:o}=he(),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(Se,{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}=Ae(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=oe(),l=t!==n&&n>t,c=r!==a&&a>r,u=()=>{c?o():s()};return x.jsx(Se,{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}=he();return x.jsx(Se,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom In"})},Ji=({className:e,disabled:t})=>{const{zoomOut:n}=oe(),{canZoomOut:r}=he();return x.jsx(Se,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom Out"})},qi=({className:e})=>{const{masterVolume:t}=he(),{setMasterVolume:n}=oe();return x.jsx(Qa,{volume:t,onChange:n,className:e})},Qi=({className:e})=>{const{timeFormat:t}=he(),{setTimeFormat:n}=oe();return x.jsx(Ro,{value:t,onChange:n,className:e})},el=A.span`
|
|
1193
|
+
`,ns=({level:e,peakLevel:t,width:n=200,height:a=20,className:r})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return v.jsxs(Jo,{$width:n,$height:a,className:r,children:[v.jsx(Qo,{$level:s,$height:a}),t!==void 0&&o>0&&v.jsx(es,{$peakLevel:o,$height:a}),v.jsxs(ts,{$height:a,children:[v.jsx(cn,{$position:60,$height:a}),v.jsx(cn,{$position:85,$height:a})]})]})};i.memo(ns);function as(e,t,n,a={}){const{currentTime:r=0,audioConstraints:s,...o}=a,[l,c]=i.useState(!1),[u,f]=i.useState(null),{stream:w,devices:g,hasPermission:d,requestAccess:x,error:I}=Ko(),{level:m,peakLevel:b}=Uo(w),{isRecording:p,isPaused:C,duration:h,peaks:k,startRecording:y,stopRecording:S,pauseRecording:R,resumeRecording:E,error:$}=Oo(w,o),M=i.useCallback(async()=>{n&&(l||(await Rt(),c(!0)),await y())},[n,l,y]),D=i.useCallback(async()=>{const T=await S();if(T&&n){const P=e.findIndex(Q=>Q.id===n);if(P===-1)return;const j=e[P],U=Math.floor(r*T.sampleRate);let V=0;if(j.clips.length>0){const Q=j.clips.map(q=>q.startSample+q.durationSamples);V=Math.max(...Q)}const L=Math.max(U,V),re={id:`clip-${Date.now()}`,audioBuffer:T,startSample:L,durationSamples:T.length,offsetSamples:0,sampleRate:T.sampleRate,sourceDurationSamples:T.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},te=e.map((Q,q)=>q===P?{...Q,clips:[...Q.clips,re]}:Q);t(te)}},[n,e,t,r,S]);i.useEffect(()=>{d&&g.length>0&&u===null&&f(g[0].deviceId)},[d,g.length]);const _=i.useCallback(async()=>{await x(void 0,s),await Rt(),c(!0)},[x,s]),Z=i.useCallback(async T=>{f(T),await x(T,s),await Rt(),c(!0)},[x,s]);return{isRecording:p,isPaused:C,duration:h,level:m,peakLevel:b,error:I||$,stream:w,devices:g,hasPermission:d,selectedDevice:u,startRecording:M,stopRecording:D,pauseRecording:R,resumeRecording:E,requestMicAccess:_,changeDevice:Z,recordingPeaks:k}}const ot=[{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}]}],jt=e=>ot.find(t=>t.id===e),rs=e=>ot.filter(t=>t.category===e),os=[{id:"reverb",name:"Reverb"},{id:"delay",name:"Delay"},{id:"modulation",name:"Modulation"},{id:"filter",name:"Filter"},{id:"distortion",name:"Distortion"},{id:"dynamics",name:"Dynamics"},{id:"spatial",name:"Spatial"}],ss={reverb:W.Reverb,freeverb:W.Freeverb,jcReverb:W.JCReverb,feedbackDelay:W.FeedbackDelay,pingPongDelay:W.PingPongDelay,chorus:W.Chorus,phaser:W.Phaser,tremolo:W.Tremolo,vibrato:W.Vibrato,autoPanner:W.AutoPanner,autoFilter:W.AutoFilter,autoWah:W.AutoWah,eq3:W.EQ3,distortion:W.Distortion,bitCrusher:W.BitCrusher,chebyshev:W.Chebyshev,compressor:W.Compressor,limiter:W.Limiter,gate:W.Gate,stereoWidener:W.StereoWidener};let is=0;const ls=()=>`effect_${Date.now()}_${++is}`;function nt(e,t){const n=ss[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const a={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;a[o.name]=l});const r=new n(a),s=ls();return{effect:r,id:e.id,instanceId:s,dispose(){try{r.disconnect(),r.dispose()}catch{}},setParameter(o,l){o==="wet"&&r.wet?r.wet.value=l:r[o]!==void 0&&(r[o]?.value!==void 0?r[o].value=l:r[o]=l)},getParameter(o){if(o==="wet"&&r.wet)return r.wet.value;if(r[o]!==void 0)return r[o]?.value!==void 0?r[o].value:r[o]},connect(o){r.connect(o)},disconnect(){try{r.disconnect()}catch{}}}}function cs(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function us(e=256){const[t,n]=i.useState([]),a=i.useRef(t);a.current=t;const r=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(m=>{const b=o.current;if(!b)return;const{masterGainNode:p,destination:C,analyserNode:h}=b;try{p.disconnect()}catch{}const k=m.map(y=>r.current.get(y.instanceId)).filter(y=>y!==void 0);if(k.length===0)p.connect(h),h.connect(C);else{let y=p;k.forEach(S=>{try{S.disconnect()}catch{}y.connect(S.effect),y=S.effect}),y.connect(h),h.connect(C)}},[]),c=i.useCallback(m=>{const b=jt(m);if(!b){console.error(`Unknown effect: ${m}`);return}const p={};b.parameters.forEach(k=>{p[k.name]=k.default});const C=nt(b,p);r.current.set(C.instanceId,C);const h={instanceId:C.instanceId,effectId:b.id,definition:b,params:p,bypassed:!1};n(k=>[...k,h])},[]),u=i.useCallback(m=>{const b=r.current.get(m);b&&(b.dispose(),r.current.delete(m)),n(p=>p.filter(C=>C.instanceId!==m))},[]),f=i.useCallback((m,b,p)=>{const C=r.current.get(m);C&&C.setParameter(b,p),n(h=>h.map(k=>k.instanceId===m?{...k,params:{...k.params,[b]:p}}:k))},[]),w=i.useCallback(m=>{const b=a.current.find(h=>h.instanceId===m);if(!b)return;const p=!b.bypassed,C=r.current.get(m);if(C){const h=b.params.wet??1;C.setParameter("wet",p?0:h)}n(h=>h.map(k=>k.instanceId===m?{...k,bypassed:p}:k))},[]),g=i.useCallback((m,b)=>{n(p=>{const C=[...p],[h]=C.splice(m,1);return C.splice(b,0,h),C})},[]),d=i.useCallback(()=>{r.current.forEach(m=>m.dispose()),r.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const x=i.useCallback((m,b,p)=>{const C=new W.Analyser("fft",e);s.current=C,o.current={masterGainNode:m,destination:b,analyserNode:C};const k=a.current.map(y=>r.current.get(y.instanceId)).filter(y=>y!==void 0);if(k.length===0)m.connect(C),C.connect(b);else{let y=m;k.forEach(S=>{y.connect(S.effect),y=S.effect}),y.connect(C),C.connect(b)}return function(){C.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{r.current.forEach(m=>m.dispose()),r.current.clear()},[]);const I=i.useCallback(()=>{const m=t.filter(b=>!b.bypassed);if(m.length!==0)return(b,p,C)=>{const h=[];for(const k of m){const y=nt(k.definition,k.params);h.push(y)}if(h.length===0)b.connect(p);else{let k=b;h.forEach(y=>{k.connect(y.effect),k=y.effect}),k.connect(p)}return function(){h.forEach(y=>y.dispose())}}},[t]);return{activeEffects:t,availableEffects:ot,addEffect:c,removeEffect:u,updateParameter:f,toggleBypass:w,reorderEffects:g,clearAllEffects:d,masterEffects:x,createOfflineEffectsFunction:I,analyserRef:s}}function ds(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),a=i.useRef(new Map),r=i.useCallback((d,x)=>{const I=a.current.get(d);if(!I)return;const{graphEnd:m,masterGainNode:b}=I,p=n.current.get(d);try{m.disconnect()}catch{}const C=x.map(h=>p?.get(h.instanceId)).filter(h=>h!==void 0);if(C.length===0)m.connect(b);else{let h=m;C.forEach(k=>{try{k.disconnect()}catch{}h.connect(k.effect),h=k.effect}),h.connect(b)}},[]),s=i.useCallback((d,x)=>{const I=jt(x);if(!I){console.error(`Unknown effect: ${x}`);return}const m={};I.parameters.forEach(C=>{m[C.name]=C.default});const b=nt(I,m);n.current.has(d)||n.current.set(d,new Map),n.current.get(d).set(b.instanceId,b);const p={instanceId:b.instanceId,effectId:I.id,definition:I,params:m,bypassed:!1};t(C=>{const h=new Map(C),k=h.get(d)||[];return h.set(d,[...k,p]),h})},[]),o=i.useCallback((d,x)=>{const I=n.current.get(d),m=I?.get(x);m&&(m.dispose(),I?.delete(x)),t(b=>{const p=new Map(b),C=p.get(d)||[];return p.set(d,C.filter(h=>h.instanceId!==x)),p})},[]),l=i.useCallback((d,x,I,m)=>{const p=n.current.get(d)?.get(x);p&&p.setParameter(I,m),t(C=>{const h=new Map(C),k=h.get(d)||[];return h.set(d,k.map(y=>y.instanceId===x?{...y,params:{...y.params,[I]:m}}:y)),h})},[]),c=i.useCallback((d,x)=>{const m=(f.current.get(d)||[]).find(h=>h.instanceId===x);if(!m)return;const b=!m.bypassed,C=n.current.get(d)?.get(x);if(C){const h=m.params.wet??1;C.setParameter("wet",b?0:h)}t(h=>{const k=new Map(h),y=k.get(d)||[];return k.set(d,y.map(S=>S.instanceId===x?{...S,bypassed:b}:S)),k})},[]),u=i.useCallback(d=>{const x=n.current.get(d);x&&(x.forEach(I=>I.dispose()),x.clear()),t(I=>{const m=new Map(I);return m.set(d,[]),m})},[]),f=i.useRef(e);f.current=e;const w=i.useCallback(d=>(x,I,m)=>{a.current.set(d,{graphEnd:x,masterGainNode:I});const b=f.current.get(d)||[],p=n.current.get(d),C=b.map(h=>p?.get(h.instanceId)).filter(h=>h!==void 0);if(C.length===0)x.connect(I);else{let h=x;C.forEach(k=>{h.connect(k.effect),h=k.effect}),h.connect(I)}return function(){a.current.delete(d)}},[]);i.useEffect(()=>{e.forEach((d,x)=>{r(x,d)})},[e,r]),i.useEffect(()=>()=>{n.current.forEach(d=>{d.forEach(x=>x.dispose()),d.clear()}),n.current.clear()},[]);const g=i.useCallback(d=>{const I=(e.get(d)||[]).filter(m=>!m.bypassed);if(I.length!==0)return(m,b,p)=>{const C=[];for(const h of I){const k=nt(h.definition,h.params);C.push(k)}if(C.length===0)m.connect(b);else{let h=m;C.forEach(k=>{h.connect(k.effect),h=k.effect}),h.connect(b)}return function(){C.forEach(k=>k.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:w,createOfflineTrackEffectsFunction:g,availableEffects:ot}}function fs(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,o=n/8,l=a*o,c=r*l,u=s*l,f=44,w=f+u,g=new ArrayBuffer(w),d=new DataView(g);pt(d,0,"RIFF"),d.setUint32(4,w-8,!0),pt(d,8,"WAVE"),pt(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,n===32?3:1,!0),d.setUint16(22,a,!0),d.setUint32(24,r,!0),d.setUint32(28,c,!0),d.setUint16(32,l,!0),d.setUint16(34,n,!0),pt(d,36,"data"),d.setUint32(40,u,!0);const x=[];for(let m=0;m<a;m++)x.push(e.getChannelData(m));let I=f;if(n===16)for(let m=0;m<s;m++)for(let b=0;b<a;b++){const p=x[b][m],C=Math.max(-1,Math.min(1,p)),h=C<0?C*32768:C*32767;d.setInt16(I,h,!0),I+=2}else for(let m=0;m<s;m++)for(let b=0;b<a;b++)d.setFloat32(I,x[b][m],!0),I+=4;return new Blob([g],{type:"audio/wav"})}function pt(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function ms(e,t){const n=URL.createObjectURL(e),a=document.createElement("a");a.href=n,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}function Yn(){const[e,t]=i.useState(!1),[n,a]=i.useState(0),[r,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:f="export",mode:w="master",trackIndex:g,autoDownload:d=!0,applyEffects:x=!0,effectsFunction:I,createOfflineTrackEffects:m,bitDepth:b=16,onProgress:p}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(w==="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 h=0;for(const M of l)for(const D of M.clips){const _=D.startSample+D.durationSamples;h=Math.max(h,_)}h+=Math.round(C*.1);const k=h/C,y=w==="individual"?[{track:l[g],state:c[g],index:g}]:l.map((M,D)=>({track:M,state:c[D],index:D})),S=c.some(M=>M.soloed),R=!!m;let E;if((I||R)&&x)E=await hs(y,c,S,k,C,I,m,M=>{a(M),p?.(M)});else{const M=new OfflineAudioContext(2,h,C);let D=0;const _=y.reduce((Z,{track:T})=>Z+T.clips.length,0);for(const{track:Z,state:T}of y)if(!(T.muted&&!T.soloed)&&!(S&&!T.soloed))for(const P of Z.clips){await gs(M,P,T,C,x),D++;const j=D/_*.5;a(j),p?.(j)}a(.5),p?.(.5),E=await M.startRendering()}a(.9),p?.(.9);const $=fs(E,{bitDepth:b});if(a(1),p?.(1),d){const M=w==="individual"?`${f}_${l[g].name}`:f;ms($,`${M}.wav`)}return{audioBuffer:E,blob:$,duration:k}}catch(C){const h=C instanceof Error?C.message:"Export failed";throw s(h),C}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function hs(e,t,n,a,r,s,o,l){const{Offline:c,Volume:u,Gain:f,Panner:w,Player:g,ToneAudioBuffer:d}=await import("tone");l(.1);let x;try{x=await c(async({transport:I,destination:m})=>{const b=new u(0);let p;s?p=s(b,m,!0):b.connect(m);for(const{track:C,state:h}of e){if(h.muted&&!h.soloed||n&&!h.soloed)continue;const k=new u(ps(h.volume)),y=new w(h.pan),S=new f(h.muted?0:1),R=o?.(C.id);R?R(S,b,!0):S.connect(b),y.connect(S),k.connect(y);for(const E of C.clips){const{audioBuffer:$,startSample:M,durationSamples:D,offsetSamples:_,gain:Z,fadeIn:T,fadeOut:P}=E,j=M/r,U=D/r,V=_/r,L=new d($),re=new g(L),te=new f(Z);if(re.connect(te),te.connect(k),T){const Q=j,q=j+T.duration,be=te.gain._param;be.setValueAtTime(0,Q),be.linearRampToValueAtTime(Z,q)}if(P){const Q=j+U-P.duration,q=j+U,be=te.gain._param;be.setValueAtTime(Z,Q),be.linearRampToValueAtTime(0,q)}re.start(j,V,U)}}I.start(0)},a,2,r)}catch(I){throw I instanceof Error?I:new Error(`Tone.Offline rendering failed: ${String(I)}`)}return l(.9),x.get()}function ps(e){return 20*Math.log10(Math.max(e,1e-4))}async function gs(e,t,n,a,r){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:f,fadeOut:w}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const g=o/a,d=l/a,x=c/a,I=e.createBufferSource();I.buffer=s;const m=e.createGain(),b=u*n.volume,p=e.createStereoPanner();if(p.pan.value=n.pan,I.connect(m),m.connect(p),p.connect(e.destination),r){if(f?m.gain.setValueAtTime(0,g):m.gain.setValueAtTime(b,g),f){const C=g,h=g+f.duration;un(m.gain,C,h,0,b,f.type||"linear")}if(w){const C=g+d-w.duration,h=g+d;(!f||f.duration<d-w.duration)&&m.gain.setValueAtTime(b,C),un(m.gain,C,h,b,0,w.type||"linear")}}else m.gain.setValueAtTime(b,g);I.start(g,x,d)}function un(e,t,n,a,r,s){const o=n-t;if(!(o<=0))switch(s){case"linear":e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n);break;case"exponential":const l=Math.max(a,1e-4),c=Math.max(r,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),r===0&&e.setValueAtTime(0,n);break;case"logarithmic":const u=dn(a,r,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const f=dn(a,r,256,"sCurve");e.setValueCurveAtTime(f,t,o);break;default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function dn(e,t,n,a){const r=new Float32Array(n),s=t-e;for(let o=0;o<n;o++){const l=o/(n-1);let c;a==="logarithmic"?s>0?c=Math.log10(1+l*9)/Math.log10(10):c=1-Math.log10(1+(1-l)*9)/Math.log10(10):c=l*l*(3-2*l),r[o]=e+s*c}return r}const On=i.createContext(null),Kn=i.createContext(null),Un=i.createContext(null),Jn=i.createContext(null),qn=i.createContext(null),bs=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:f,onReady:w,onAnnotationUpdate:g,barWidth:d=1,barGap:x=0,progressBarWidth:I,children:m})=>{const b=I??d+x,[p,C]=i.useState([]),[h,k]=i.useState(null),[y,S]=i.useState(!1),[R,E]=i.useState(0),[$,M]=i.useState(0),[D,_]=i.useState([]),[Z,T]=i.useState([]),[P,j]=i.useState([]),[U,V]=i.useState(0),[L,re]=i.useState(0),[te,Q]=i.useState(null),[q,be]=i.useState(o),[Ee,Y]=i.useState(u?.isContinuousPlay??!1),[le,pe]=i.useState(u?.linkEndpoints??!0),[ce,K]=i.useState(u?.editable??!1),[ee,We]=i.useState(!1),[je,ne]=i.useState(0),[J,ae]=i.useState(0),F=i.useRef(null),ue=i.useRef(0),de=i.useRef(0),Ce=i.useRef(null),st=i.useRef(P),Ae=i.useRef(0),ye=i.useRef(0),He=i.useRef(null),Ve=i.useRef(null),it=i.useRef(!1),lt=i.useRef(u?.isContinuousPlay??!1),Ne=i.useRef(null),ct=i.useRef(r),X=i.useRef(!1),O=i.useRef(0),ie=i.useRef(0),fe=i.useRef(0),ve=i.useRef(0),{timeFormat:_e,setTimeFormat:oe,formatTime:Pe}=Hn(),Se=Xn({initialSamplesPerPixel:r,zoomLevels:s}),ke=Se.samplesPerPixel,{masterVolume:Xe,setMasterVolume:Ke}=Gn({playoutRef:F,initialVolume:1}),qe=i.useCallback(B=>{lt.current=B,Y(B)},[]),Ge=i.useCallback(B=>{Ne.current=B,k(B)},[]),oa=i.useCallback(B=>{X.current=B,We(B)},[]),Qe=i.useCallback((B,H)=>{fe.current=B,ve.current=H,ne(B),ae(H)},[]),sa=i.useCallback(()=>{const B=O.current,H=ie.current;B!==H&&H>B&&Qe(B,H)},[Qe]),ia=i.useCallback(()=>{Qe(0,0)},[Qe]);i.useEffect(()=>{it.current=q},[q]),i.useEffect(()=>{st.current=P},[P]),i.useEffect(()=>{O.current=U,ie.current=L},[U,L]),i.useEffect(()=>{if(!Ve.current||!D.length)return;const B=Ve.current,H=ct.current,N=ke;if(H===N)return;const se=c.show?c.width:0,z=B.clientWidth,Ze=B.scrollLeft+z/2-se,me=D[0].sampleRate,$e=Ze*H/me*me/N,ze=Math.max(0,$e+se-z/2);B.scrollLeft=ze,ct.current=N},[ke,D,c]);const ut=i.useRef(null);i.useEffect(()=>{if(e.length===0){_([]),M(0),j([]),T([]),F.current&&(F.current.dispose(),F.current=null);return}const B=y,H=de.current;return F.current&&B&&(F.current.stop(),Ce.current&&(cancelAnimationFrame(Ce.current),Ce.current=null),ut.current={position:H}),(async()=>{try{const se=[];e.forEach(me=>{me.clips.length>0&&me.clips[0].audioBuffer&&se.push(me.clips[0].audioBuffer)});let z=0;e.forEach(me=>{me.clips.forEach(xe=>{const $e=xe.sampleRate,dt=(xe.startSample+xe.durationSamples)/$e;z=Math.max(z,dt)})}),_(se),M(z),j(me=>me.length===e.length?me.map((xe,$e)=>({...xe,name:e[$e].name})):e.map(xe=>({name:xe.name,muted:xe.muted,soloed:xe.soloed,volume:xe.volume,pan:xe.pan}))),F.current&&F.current.dispose();const ge=new Fa({effects:f}),Ze=st.current;e.forEach((me,xe)=>{const $e=me.clips.filter(ze=>ze.audioBuffer);if($e.length>0){const ze=$e[0].sampleRate,dt=Math.min(...$e.map(Me=>Me.startSample/ze)),wa=Math.max(...$e.map(Me=>(Me.startSample+Me.durationSamples)/ze)),ft=Ze[xe],ya={id:`track-${xe}`,name:me.name,gain:ft?.volume??me.volume,muted:ft?.muted??me.muted,soloed:ft?.soloed??me.soloed,stereoPan:ft?.pan??me.pan,startTime:dt,endTime:wa},ka=$e.map(Me=>{const $t=Me.sampleRate;return{buffer:Me.audioBuffer,startTime:Me.startSample/$t-dt,duration:Me.durationSamples/$t,offset:Me.offsetSamples/$t,fadeIn:Me.fadeIn,fadeOut:Me.fadeOut,gain:Me.gain}});ge.addTrack({clips:ka,track:ya,effects:me.effects})}}),ge.applyInitialSoloState(),F.current=ge,w?.()}catch(se){console.error("Error loading audio:",se)}})(),()=>{Ce.current&&cancelAnimationFrame(Ce.current),F.current&&F.current.dispose()}},[e,w,y]),i.useEffect(()=>{if(e.length===0)return;const B=16,H=e.map(N=>N.clips.map(z=>{if(z.waveformData){const Ze=Zn(z.waveformData,ke,0,z.offsetSamples,z.durationSamples);return{clipId:z.id,trackName:N.name,peaks:{length:Ze.length,data:[Ze.data],bits:Ze.bits},startSample:z.startSample,durationSamples:z.durationSamples,fadeIn:z.fadeIn,fadeOut:z.fadeOut}}if(!z.audioBuffer)return console.warn(`Clip "${z.name||z.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:z.id,trackName:N.name,peaks:{length:0,data:[],bits:B},startSample:z.startSample,durationSamples:z.durationSamples,fadeIn:z.fadeIn,fadeOut:z.fadeOut};const ge=Nr(z.audioBuffer,ke,n,B,z.offsetSamples,z.durationSamples);return{clipId:z.id,trackName:N.name,peaks:ge,startSample:z.startSample,durationSamples:z.durationSamples,fadeIn:z.fadeIn,fadeOut:z.fadeOut}}));T(H)},[e,ke,n]),i.useEffect(()=>{if(u?.annotations){const B=u.annotations.map(H=>typeof H.start=="number"?H:Vn(H));C(B)}},[u]);const Le=i.useCallback(()=>{Ce.current&&(cancelAnimationFrame(Ce.current),Ce.current=null);const B=()=>{const H=W.getContext().currentTime-Ae.current,N=ye.current+H;if(de.current=N,E(N),p.length>0){const z=p.find(ge=>N>=ge.start&&N<ge.end);if(lt.current){if(z&&z.id!==Ne.current)Ge(z.id);else if(!z&&Ne.current!==null){const ge=p[p.length-1];if(N>=ge.end){F.current&&F.current.stop(),S(!1),de.current=ue.current,E(ue.current),Ge(null);return}}}else if(Ne.current){const ge=p.find(Ze=>Ze.id===Ne.current);if(ge&&N>=ge.end){F.current&&F.current.stop(),S(!1),de.current=ue.current,E(ue.current);return}}else z&&Ge(z.id)}if(it.current&&Ve.current&&D.length>0){const z=Ve.current,ge=D[0].sampleRate,Ze=N*ge/ct.current,me=z.clientWidth,xe=c.show?c.width:0,$e=Ze+xe,ze=Math.max(0,$e-me/2);z.scrollLeft=ze}if(He.current!==null&&N>=He.current){F.current&&F.current.stop(),S(!1),de.current=He.current,E(He.current),He.current=null;return}const se=fe.current!==ve.current&&ve.current>fe.current;if(X.current&&se&&N>=ve.current){F.current?.stop();const ge=W.getContext().currentTime;Ae.current=ge,ye.current=fe.current,de.current=fe.current,F.current?.play(ge,fe.current),Ce.current=requestAnimationFrame(B);return}if(N>=$){F.current&&F.current.stop(),S(!1),de.current=ue.current,E(ue.current),Ge(null);return}Ce.current=requestAnimationFrame(B)};Ce.current=requestAnimationFrame(B)},[$,D,ke,p,Ee]),Fe=i.useCallback(()=>{Ce.current&&(cancelAnimationFrame(Ce.current),Ce.current=null)},[]);i.useEffect(()=>{(async()=>{if(y&&Ce.current&&F.current)if(Ee){const H=de.current;F.current.stop(),Fe(),await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const se=W.getContext().currentTime;Ae.current=se,ye.current=H,F.current.play(se,H),Le()}else Fe(),Le()})()},[Ee,y,Le,Fe]),i.useEffect(()=>{(async()=>{if(ut.current&&F.current){const{position:H}=ut.current;ut.current=null,await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const se=W.getContext().currentTime;Ae.current=se,ye.current=H,F.current.play(se,H),S(!0),Le()}})()},[e,Le]);const St=i.useCallback(async(B,H)=>{if(!F.current||D.length===0)return;await F.current.init(),await W.start();const N=B??de.current;ue.current=N,de.current=N,F.current.setOnPlaybackComplete(()=>{}),F.current.stop(),Fe();const z=W.getContext().currentTime;Ae.current=z,ye.current=N,He.current=H!==void 0?N+H:null,F.current.play(z,N,H),S(!0),Le()},[D.length,Le,Fe]),la=i.useCallback(()=>{if(!F.current)return;const B=W.getContext().currentTime-Ae.current,H=ye.current+B;F.current.pause(),S(!1),Fe(),de.current=H,E(H)},[Fe]),ca=i.useCallback(()=>{F.current&&(F.current.stop(),S(!1),Fe(),de.current=ue.current,E(ue.current),Ge(null))},[Fe]),ua=i.useCallback(B=>{const H=Math.max(0,Math.min(B,$));de.current=H,E(H),y&&F.current&&(F.current.stop(),Fe(),St(H))},[$,y,St,Fe]),da=i.useCallback((B,H)=>{const N=[...P];if(N[B]={...N[B],muted:H},j(N),F.current){const se=`track-${B}`;F.current.setMute(se,H)}},[P]),fa=i.useCallback((B,H)=>{const N=[...P];if(N[B]={...N[B],soloed:H},j(N),F.current){const se=`track-${B}`;F.current.setSolo(se,H)}},[P]),ma=i.useCallback((B,H)=>{const N=[...P];if(N[B]={...N[B],volume:H},j(N),F.current){const se=`track-${B}`,z=F.current.getTrack(se);z&&z.setVolume(H)}},[P]),ha=i.useCallback((B,H)=>{const N=[...P];if(N[B]={...N[B],pan:H},j(N),F.current){const se=`track-${B}`,z=F.current.getTrack(se);z&&z.setPan(H)}},[P]),pa=i.useCallback((B,H)=>{V(B),re(H),de.current=B,E(B),y&&F.current&&(F.current.stop(),F.current.play(W.getContext().currentTime,B))},[y]),ga=i.useCallback(B=>{Ve.current=B},[]),ba=D[0]?.sampleRate||44100,Ht=t?30:0,va=e.length*a+Ht,Xt={isPlaying:y,currentTime:R,currentTimeRef:de,playbackStartTimeRef:Ae,audioStartPositionRef:ye},Gt={continuousPlay:Ee,linkEndpoints:le,annotationsEditable:ce,isAutomaticScroll:q,isLoopEnabled:ee,annotations:p,activeAnnotationId:h,selectionStart:U,selectionEnd:L,selectedTrackId:te,loopStart:je,loopEnd:J},Nt={play:St,pause:la,stop:ca,seekTo:ua,setCurrentTime:B=>{de.current=B,E(B)},setTrackMute:da,setTrackSolo:fa,setTrackVolume:ma,setTrackPan:ha,setSelection:pa,setSelectedTrackId:Q,setTimeFormat:oe,formatTime:Pe,zoomIn:Se.zoomIn,zoomOut:Se.zoomOut,setMasterVolume:Ke,setAutomaticScroll:B=>{be(B)},setScrollContainer:ga,scrollContainerRef:Ve,setContinuousPlay:qe,setLinkEndpoints:pe,setAnnotationsEditable:K,setAnnotations:C,setActiveAnnotationId:Ge,setLoopEnabled:oa,setLoopRegion:Qe,setLoopRegionFromSelection:sa,clearLoopRegion:ia},Lt={duration:$,audioBuffers:D,peaksDataArray:Z,trackStates:P,tracks:e,sampleRate:ba,waveHeight:a,timeScaleHeight:Ht,minimumPlaylistHeight:va,controls:c,playoutRef:F,samplesPerPixel:ke,timeFormat:_e,masterVolume:Xe,canZoomIn:Se.canZoomIn,canZoomOut:Se.canZoomOut,barWidth:d,barGap:x,progressBarWidth:b},Ca={...Xt,...Gt,...Nt,...Lt},xa={...yn,...l};return v.jsx(A.ThemeProvider,{theme:xa,children:v.jsx(On.Provider,{value:Xt,children:v.jsx(Kn.Provider,{value:Gt,children:v.jsx(Un.Provider,{value:Nt,children:v.jsx(Jn.Provider,{value:Lt,children:v.jsx(qn.Provider,{value:Ca,children:m})})})})})})},Ie=()=>{const e=i.useContext(On);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Te=()=>{const e=i.useContext(Kn);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},he=()=>{const e=i.useContext(Un);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},we=()=>{const e=i.useContext(Jn);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},vs=()=>{const e=i.useContext(qn);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var Cs=class{constructor(e){this._playbackRate=1,this.handleEnded=()=>{this.onStopCallback&&this.onStopCallback()},this.handleTimeUpdate=()=>{this.onTimeUpdateCallback&&this.onTimeUpdateCallback(this.audioElement.currentTime)},this._peaks=e.peaks,this._id=e.id??`track-${Date.now()}`,this._name=e.name??"Track",this._playbackRate=e.playbackRate??1,typeof e.source=="string"?(this.audioElement=new Audio(e.source),this.ownsElement=!0):(this.audioElement=e.source,this.ownsElement=!1),this.audioElement.preload="auto",this.audioElement.volume=e.volume??1,this.audioElement.playbackRate=this._playbackRate,"preservesPitch"in this.audioElement?this.audioElement.preservesPitch=!0:"mozPreservesPitch"in this.audioElement?this.audioElement.mozPreservesPitch=!0:"webkitPreservesPitch"in this.audioElement&&(this.audioElement.webkitPreservesPitch=!0),this.audioElement.addEventListener("ended",this.handleEnded),this.audioElement.addEventListener("timeupdate",this.handleTimeUpdate)}play(e=0){this.audioElement.currentTime=e,this.audioElement.play().catch(t=>{console.warn("MediaElementTrack: play() failed:",t)})}pause(){this.audioElement.pause()}stop(){this.audioElement.pause(),this.audioElement.currentTime=0}seekTo(e){this.audioElement.currentTime=Math.max(0,Math.min(e,this.duration))}setVolume(e){this.audioElement.volume=Math.max(0,Math.min(1,e))}setPlaybackRate(e){const t=Math.max(.5,Math.min(2,e));this._playbackRate=t,this.audioElement.playbackRate=t}setMuted(e){this.audioElement.muted=e}setOnStopCallback(e){this.onStopCallback=e}setOnTimeUpdateCallback(e){this.onTimeUpdateCallback=e}dispose(){this.audioElement.removeEventListener("ended",this.handleEnded),this.audioElement.removeEventListener("timeupdate",this.handleTimeUpdate),this.audioElement.pause(),this.ownsElement&&(this.audioElement.src="",this.audioElement.load())}get id(){return this._id}get name(){return this._name}get peaks(){return this._peaks}get currentTime(){return this.audioElement.currentTime}get duration(){return this.audioElement.duration||this._peaks.duration}get isPlaying(){return!this.audioElement.paused&&!this.audioElement.ended}get volume(){return this.audioElement.volume}get playbackRate(){return this._playbackRate}get muted(){return this.audioElement.muted}get element(){return this.audioElement}},xs=class{constructor(e={}){this.track=null,this._isPlaying=!1,this._masterVolume=e.masterVolume??1,this._playbackRate=e.playbackRate??1}async init(){}addTrack(e){return this.track&&(console.warn("MediaElementPlayout: Only one track is supported. Disposing previous track. For multi-track, use TonePlayout."),this.track.dispose()),this.track=new Cs({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const a=t??0;if(this._isPlaying=!0,this.track.play(a),n!==void 0){const r=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},r*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const Qn=i.createContext(null),ea=i.createContext(null),ta=i.createContext(null),na=i.createContext(null),ws=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,theme:s,controls:o={show:!1,width:0},annotationList:l,barWidth:c=1,barGap:u=0,progressBarWidth:f,onReady:w,children:g})=>{const d=f??c+u,[x,I]=i.useState(!1),[m,b]=i.useState(0),[p,C]=i.useState(0),[h,k]=i.useState([]),[y,S]=i.useState(r),[R,E]=i.useState([]),[$,M]=i.useState(null),[D,_]=i.useState(l?.isContinuousPlay??!1),[Z]=i.useState(t),T=i.useRef(null),P=i.useRef(0),j=i.useRef(null),U=i.useRef(D),V=i.useRef(null);i.useEffect(()=>{U.current=D},[D]);const L=i.useCallback(J=>{V.current=J,M(J)},[]),re=i.useCallback(J=>{U.current=J,_(J)},[]),te=e.waveformData.sample_rate;i.useEffect(()=>{const J=new xs({playbackRate:r});J.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const ae=J.getTrack(J.track?.id??"");return ae&&ae.setOnTimeUpdateCallback(F=>{P.current=F}),J.setOnPlaybackComplete(()=>{I(!1)}),T.current=J,C(e.waveformData.duration),w?.(),()=>{j.current&&cancelAnimationFrame(j.current),J.dispose()}},[e.source,e.waveformData,e.name,r,w]),i.useEffect(()=>{const J=Zn(e.waveformData,Z,0,0,Math.ceil(e.waveformData.duration*te)),ae={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:J.length,data:[J.data],bits:J.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*te)};k([[ae]])},[e.waveformData,e.name,Z,te]),i.useEffect(()=>{if(l?.annotations){const J=l.annotations.map(ae=>typeof ae.start=="number"?ae:Vn(ae));E(J)}},[l]);const Q=i.useCallback(()=>{j.current&&cancelAnimationFrame(j.current);const J=()=>{const ae=T.current?.getCurrentTime()??0;if(P.current=ae,b(ae),R.length>0){const F=R.find(ue=>ae>=ue.start&&ae<ue.end);if(U.current){if(F&&F.id!==V.current)L(F.id);else if(!F&&V.current!==null){const ue=R[R.length-1];if(ae>=ue.end){T.current?.stop(),I(!1),L(null);return}}}else if(V.current){const ue=R.find(de=>de.id===V.current);if(ue&&ae>=ue.end){T.current?.stop(),I(!1);return}}else F&&L(F.id)}if(ae>=p){T.current?.stop(),I(!1),L(null);return}j.current=requestAnimationFrame(J)};j.current=requestAnimationFrame(J)},[p,R,L]),q=i.useCallback(()=>{j.current&&(cancelAnimationFrame(j.current),j.current=null)},[]),be=i.useCallback(J=>{if(!T.current)return;const ae=J??P.current;T.current.play(void 0,ae),I(!0),Q()},[Q]),Ee=i.useCallback(()=>{T.current&&(T.current.pause(),I(!1),q(),b(T.current.getCurrentTime()))},[q]),Y=i.useCallback(()=>{T.current&&(T.current.stop(),I(!1),q(),P.current=0,b(0),L(null))},[q,L]),le=i.useCallback(J=>{const ae=Math.max(0,Math.min(J,p));P.current=ae,b(ae),T.current&&T.current.seekTo(ae)},[p]),pe=i.useCallback(J=>{const ae=Math.max(.5,Math.min(2,J));S(ae),T.current&&T.current.setPlaybackRate(ae)},[]),ce=a?30:0,K=i.useMemo(()=>({isPlaying:x,currentTime:m,currentTimeRef:P}),[x,m]),ee=i.useMemo(()=>({continuousPlay:D,annotations:R,activeAnnotationId:$,playbackRate:y}),[D,R,$,y]),We=i.useMemo(()=>({play:be,pause:Ee,stop:Y,seekTo:le,setPlaybackRate:pe,setContinuousPlay:re,setAnnotations:E,setActiveAnnotationId:L}),[be,Ee,Y,le,pe,re,L]),je=i.useMemo(()=>({duration:p,peaksDataArray:h,sampleRate:te,waveHeight:n,timeScaleHeight:ce,samplesPerPixel:Z,playoutRef:T,controls:o,barWidth:c,barGap:u,progressBarWidth:d}),[p,h,te,n,ce,Z,o,c,u,d]),ne={...yn,...s};return v.jsx(A.ThemeProvider,{theme:ne,children:v.jsx(Qn.Provider,{value:K,children:v.jsx(ea.Provider,{value:ee,children:v.jsx(ta.Provider,{value:We,children:v.jsx(na.Provider,{value:je,children:g})})})})})},It=()=>{const e=i.useContext(Qn);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},aa=()=>{const e=i.useContext(ea);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},ra=()=>{const e=i.useContext(ta);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},At=()=>{const e=i.useContext(na);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},ys=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Ie(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=Te(),{play:o}=he(),l=async()=>{if(a!==r&&r>a)if(s)await o(a);else{const u=r-a;await o(a,u)}else await o(n.current??0)};return v.jsx(Be,{onClick:l,disabled:t,className:e,children:"Play"})},ks=({className:e})=>{const{isPlaying:t}=Ie(),{pause:n}=he();return v.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Pause"})},Is=({className:e})=>{const{isPlaying:t}=Ie(),{stop:n}=he();return v.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Stop"})},As=({className:e})=>{const{isPlaying:t}=Ie(),{play:n,setCurrentTime:a}=he(),{playoutRef:r}=we(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return v.jsx(Be,{onClick:s,className:e,children:"Rewind"})},Ss=({className:e})=>{const{isPlaying:t}=Ie(),{play:n,setCurrentTime:a}=he(),{duration:r,playoutRef:s}=we(),o=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return v.jsx(Be,{onClick:o,className:e,children:"Fast Forward"})},$s=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Ie(),{play:r,setCurrentTime:s}=he(),{playoutRef:o}=we(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&o.current&&(o.current.stop(),r(c))};return v.jsx(Be,{onClick:l,className:t,children:"Skip Backward"})},Ms=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Ie(),{play:r,setCurrentTime:s}=he(),{duration:o,playoutRef:l}=we(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),a&&l.current&&(l.current.stop(),r(u))};return v.jsx(Be,{onClick:c,className:t,children:"Skip Forward"})},Rs=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=Te(),{setLoopEnabled:r,setLoopRegion:s}=he(),{duration:o}=we(),l=n!==a&&a>n,c=()=>{if(!t&&!l){const u=Math.min(10,o*.25);s(0,Math.max(1,u))}r(!t)};return v.jsx(Be,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},Es=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=Te(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=he(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?o():s()};return v.jsx(Be,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},Ds=({className:e,disabled:t})=>{const{zoomIn:n}=he(),{canZoomIn:a}=we();return v.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Bs=({className:e,disabled:t})=>{const{zoomOut:n}=he(),{canZoomOut:a}=we();return v.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Ts=({className:e})=>{const{masterVolume:t}=we(),{setMasterVolume:n}=he();return v.jsx(ir,{volume:t,onChange:n,className:e})},Ws=({className:e})=>{const{timeFormat:t}=we(),{setTimeFormat:n}=he();return v.jsx(Tr,{value:t,onChange:n,className:e})},_s=A.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
|
-
`,
|
|
1199
|
+
`,Fs=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:a,currentTimeRef:r,playbackStartTimeRef:s,audioStartPositionRef:o}=Ie(),{timeFormat:l}=we(),c=l;return i.useEffect(()=>{const u=()=>{if(t.current){let f;if(a){const w=W.getContext().currentTime-(s.current??0);f=(o.current??0)+w}else f=r.current??0;t.current.textContent=Je(f,c)}a&&(n.current=requestAnimationFrame(u))};return a?n.current=requestAnimationFrame(u):u(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[a,c,r,s,o]),i.useEffect(()=>{!a&&t.current&&(t.current.textContent=Je(r.current??0,c))}),v.jsx(_s,{ref:t,className:e,"aria-label":"Audio position",children:Je(r.current??0,c)})},Zs=({className:e})=>{const{selectionStart:t,selectionEnd:n}=Te(),{setSelection:a}=he();return v.jsx(vr,{selectionStart:t,selectionEnd:n,onSelectionChange:a,className:e})},Vs=({className:e})=>{const{isAutomaticScroll:t}=Te(),{setAutomaticScroll:n}=he();return v.jsx(Ha,{checked:t,onChange:n,className:e})},Ps=({className:e})=>{const{continuousPlay:t}=Te(),{setContinuousPlay:n}=he();return v.jsx(Mo,{checked:t,onChange:n,className:e})},zs=({className:e})=>{const{linkEndpoints:t}=Te(),{setLinkEndpoints:n}=he();return v.jsx(Ro,{checked:t,onChange:n,className:e})},js=({className:e})=>{const{annotationsEditable:t}=Te(),{setAnnotationsEditable:n}=he();return v.jsx(Eo,{checked:t,onChange:n,className:e})},Hs=({filename:e,className:t})=>{const{annotations:n}=Te();return v.jsx(Bo,{annotations:n,filename:e,className:t})},Xs=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:a,bitDepth:r=16,applyEffects:s=!0,effectsFunction:o,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:f})=>{const{tracks:w,trackStates:g}=we(),{exportWav:d,isExporting:x,progress:I}=Yn(),m=async()=>{try{const p=await d(w,g,{filename:t,mode:n,trackIndex:a,bitDepth:r,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(p.blob)}catch(p){f?.(p instanceof Error?p:new Error("Export failed"))}},b=x?`Exporting ${Math.round(I*100)}%`:e;return v.jsx(Be,{onClick:m,disabled:x||w.length===0,className:c,children:b})},Gs=A.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
|
-
`,
|
|
1209
|
+
`,Ns=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=Ie(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:f}=we();return i.useEffect(()=>{const w=()=>{if(n.current){let g;if(r){const x=W.getContext().currentTime-(o.current??0);g=(l.current??0)+x}else g=s.current??0;const d=g*u/c+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}r&&(a.current=requestAnimationFrame(w))};return r?a.current=requestAnimationFrame(w):w(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,u,c,t,s,o,l]),i.useEffect(()=>{if(!r&&n.current){const g=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${g}px, 0, 0)`}}),v.jsx(Gs,{ref:n,$color:e,$width:f,"data-playhead":!0})},Ls=A.div`
|
|
1210
1210
|
position: relative;
|
|
1211
|
-
`,
|
|
1211
|
+
`,Ys=A.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
|
-
`,
|
|
1223
|
+
`,Os=A.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
|
-
`,
|
|
1232
|
+
`,Ks=A.div`
|
|
1233
1233
|
position: relative;
|
|
1234
1234
|
z-index: 2;
|
|
1235
|
-
`,
|
|
1235
|
+
`,fn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=rt(),{waveHeight:o}=at(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:f}=Ie(),{samplesPerPixel:w,sampleRate:g}=we(),d=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const b=()=>{if(a.current){let p;if(l){const y=W.getContext().currentTime-(u.current??0);p=(f.current??0)+y}else p=c.current??0;const C=p*g,h=e+t;let k=0;if(C<=e)k=0;else if(C>=h)k=n.length;else{const y=C-e;k=Math.floor(y/w)}a.current.style.width=`${k}px`}l&&(r.current=requestAnimationFrame(b))};return l?r.current=requestAnimationFrame(b):b(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,g,w,e,t,n.length,c,u,f]),i.useEffect(()=>{if(!l&&a.current){const p=(c.current??0)*g,C=e+t;let h=0;if(p<=e)h=0;else if(p>=C)h=n.length;else{const k=p-e;h=Math.floor(k/w)}a.current.style.width=`${h}px`}});const x=s?.waveformDrawMode||"inverted";let I;x==="inverted"?I=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":I=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const m=Ye(I);return v.jsxs(Ls,{children:[v.jsx(Ys,{$color:m,$height:o,$top:n.index*o,$width:n.length}),v.jsx(Os,{ref:a,$color:d,$height:o,$top:n.index*o}),v.jsx(Ks,{children:v.jsx(Dn,{...n,transparentBackground:!0})})]})},Us=60,Js=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,className:c,showClipHeaders:u=!1,interactiveClips:f=!1,showFades:w=!1,touchOptimized:g=!1,recordingState:d})=>{const x=rt(),{isPlaying:I,currentTimeRef:m,playbackStartTimeRef:b,audioStartPositionRef:p}=Ie(),{selectionStart:C,selectionEnd:h,annotations:k,activeAnnotationId:y,annotationsEditable:S,linkEndpoints:R,continuousPlay:E,selectedTrackId:$,loopStart:M,loopEnd:D,isLoopEnabled:_}=Te(),{setAnnotations:Z,setActiveAnnotationId:T,setTrackMute:P,setTrackSolo:j,setTrackVolume:U,setTrackPan:V,setSelection:L,play:re,setScrollContainer:te,setSelectedTrackId:Q,setCurrentTime:q,setLoopRegion:be}=he(),{audioBuffers:Ee,peaksDataArray:Y,trackStates:le,tracks:pe,duration:ce,samplesPerPixel:K,sampleRate:ee,waveHeight:We,timeScaleHeight:je,controls:ne,playoutRef:J,barWidth:ae,barGap:F}=we(),[ue,de]=i.useState(!1),Ce=i.useRef(null),st=i.useCallback(X=>{Ce.current=X,te(X)},[te]);let Ae=Ee.length>0?ce:Us;if(d?.isRecording){const O=(d.startSample+d.durationSamples)/ee;Ae=Math.max(Ae,O+10)}const ye=Math.floor(Ae*ee/K),He=async X=>{console.log("Annotation clicked:",X.id),T(X.id);const O=E?void 0:X.end-X.start;await re(X.start,O)},Ve=i.useCallback(X=>{if(X>=0&&X<pe.length){const O=pe[X];Q(O.id)}},[pe,Q]),it=X=>{const O=X.currentTarget.getBoundingClientRect(),ie=ne.show?ne.width:0,ve=(X.clientX-O.left-ie)*K/ee,oe=X.clientY-O.top;let Pe=0,Se=-1;for(let ke=0;ke<Y.length;ke++){const Xe=Y[ke],qe=(Xe.length>0?Math.max(...Xe.map(Ge=>Ge.peaks.data.length)):1)*We+(u?22:0);if(oe>=Pe&&oe<Pe+qe){Se=ke;break}Pe+=qe}Se!==-1&&Ve(Se),de(!0),q(ve),L(ve,ve)},lt=X=>{if(!ue)return;const O=X.currentTarget.getBoundingClientRect(),ie=ne.show?ne.width:0,ve=(X.clientX-O.left-ie)*K/ee,_e=Math.min(C,ve),oe=Math.max(C,ve);L(_e,oe)},Ne=X=>{if(!ue)return;de(!1);const O=X.currentTarget.getBoundingClientRect(),ie=ne.show?ne.width:0,ve=(X.clientX-O.left-ie)*K/ee,_e=Math.min(C,ve),oe=Math.max(C,ve);Math.abs(oe-_e)<.1?(q(_e),I&&J.current?(J.current.stop(),re(_e)):J.current&&J.current.stop()):L(_e,oe)};return pe.some(X=>X.clips.length>0)&&(Ee.length===0||Y.length===0)?v.jsx("div",{className:c,children:"Loading waveform..."}):v.jsx(Rn,{children:v.jsxs(yt.Provider,{value:{samplesPerPixel:K,sampleRate:ee,zoomLevels:[K],waveHeight:We,timeScaleHeight:je,duration:Ae,controls:ne,barWidth:ae,barGap:F},children:[v.jsx(Vt,{theme:x,backgroundColor:Ye(x.waveOutlineColor),timescaleBackgroundColor:x.timescaleBackgroundColor,scrollContainerWidth:ye+(ne.show?ne.width:0),timescaleWidth:ye,tracksWidth:ye,controlsWidth:ne.show?ne.width:0,onTracksMouseDown:it,onTracksMouseMove:lt,onTracksMouseUp:Ne,scrollContainerRef:st,isSelecting:ue,timescale:je>0?v.jsxs(v.Fragment,{children:[v.jsx(Bn,{duration:Ae*1e3,marker:1e4,bigStep:5e3,secondStep:1e3,renderTimestamp:t}),_&&v.jsx(br,{startPosition:Math.min(M,D)*ee/K,endPosition:Math.max(M,D)*ee/K,markerColor:x.loopMarkerColor,regionColor:x.loopRegionColor,minPosition:0,maxPosition:ye,controlsOffset:ne.show?ne.width:0,onLoopRegionChange:(X,O)=>{const ie=X*K/ee,fe=O*K/ee;be(ie,fe)}})]}):void 0,children:v.jsxs(v.Fragment,{children:[Y.map((X,O)=>{const ie=pe[O];if(!ie)return null;const fe=le[O]||{name:`Track ${O+1}`,muted:!1,soloed:!1,volume:1,pan:0},ve=e?e(O):v.jsxs(Vr,{onClick:()=>Ve(O),children:[v.jsx(Pr,{style:{justifyContent:"center"},children:fe.name||`Track ${O+1}`}),v.jsxs(Zr,{children:[v.jsx(tn,{$variant:fe.muted?"danger":"outline",onClick:()=>P(O,!fe.muted),children:"Mute"}),v.jsx(tn,{$variant:fe.soloed?"info":"outline",onClick:()=>j(O,!fe.soloed),children:"Solo"})]}),v.jsxs(an,{children:[v.jsx(zr,{}),v.jsx(nn,{min:"0",max:"1",step:"0.01",value:fe.volume,onChange:oe=>U(O,parseFloat(oe.target.value))}),v.jsx(jr,{})]}),v.jsxs(an,{children:[v.jsx("span",{children:"L"}),v.jsx(nn,{min:"-1",max:"1",step:"0.01",value:fe.pan,onChange:oe=>V(O,parseFloat(oe.target.value))}),v.jsx("span",{children:"R"})]})]}),_e=X.length>0?Math.max(...X.map(oe=>oe.peaks.data.length)):1;return v.jsx(Pt.Provider,{value:ve,children:v.jsxs(Tn,{numChannels:_e,backgroundColor:Ye(x.waveOutlineColor),offset:0,width:ye,hasClipHeaders:u,trackId:ie.id,isSelected:ie.id===$,children:[X.map((oe,Pe)=>{const Se=oe.peaks,ke=Se.length;return v.jsx(Tt,{clipId:oe.clipId,trackIndex:O,clipIndex:Pe,trackName:oe.trackName,startSample:oe.startSample,durationSamples:oe.durationSamples,samplesPerPixel:K,showHeader:u,disableHeaderDrag:!f,isSelected:ie.id===$,trackId:ie.id,fadeIn:oe.fadeIn,fadeOut:oe.fadeOut,sampleRate:ee,showFades:w,touchOptimized:g,onMouseDown:Xe=>{Xe.target.closest('[role="button"][aria-roledescription="draggable"]')||Ve(O)},children:Se.data.map((Xe,Ke)=>v.jsx(fn,{index:Ke,data:Xe,bits:Se.bits,length:ke,isSelected:ie.id===$,clipStartSample:oe.startSample,clipDurationSamples:oe.durationSamples},`${O}-${Pe}-${Ke}`))},`${O}-${Pe}`)}),d?.isRecording&&d.trackId===ie.id&&d.peaks.length>0&&v.jsx(Tt,{clipId:"recording-preview",trackIndex:O,clipIndex:X.length,trackName:"Recording...",startSample:d.startSample,durationSamples:d.durationSamples,samplesPerPixel:K,showHeader:u,disableHeaderDrag:!0,isSelected:ie.id===$,trackId:ie.id,children:v.jsx(fn,{index:0,data:d.peaks,bits:16,length:Math.floor(d.peaks.length/2),isSelected:ie.id===$,clipStartSample:d.startSample,clipDurationSamples:d.durationSamples},`${O}-recording-0`)},`${O}-recording`)]})},ie.id)}),k.length>0&&v.jsx(zn,{height:30,width:ye,children:k.map((X,O)=>{const ie=X.start*ee/K,fe=X.end*ee/K,ve=l?l(X):X.id;return v.jsx(Pn,{annotationId:X.id,annotationIndex:O,startPosition:ie,endPosition:fe,label:ve,color:"#ff9800",isActive:X.id===y,onClick:()=>He(X),editable:S},X.id)})}),C!==h&&v.jsx(Sn,{startPosition:Math.min(C,h)*ee/K+(ne.show?ne.width:0),endPosition:Math.max(C,h)*ee/K+(ne.show?ne.width:0),color:x.selectionColor}),(I||C===h)&&(n?n({position:(m.current??0)*ee/K+(ne.show?ne.width:0),color:x.playheadColor,isPlaying:I,currentTimeRef:m,playbackStartTimeRef:b,audioStartPositionRef:p,samplesPerPixel:K,sampleRate:ee,controlsOffset:ne.show?ne.width:0,getAudioContextTime:()=>W.getContext().currentTime}):v.jsx(Ns,{color:x.playheadColor,controlsOffset:ne.show?ne.width:0}))]})}),k.length>0&&v.jsx(jn,{annotations:k,activeAnnotationId:y??void 0,shouldScrollToActive:!0,editable:S,controls:S?a:void 0,annotationListConfig:{linkEndpoints:R,continuousPlay:E},height:s,renderAnnotationItem:o,onAnnotationUpdate:X=>{Z(X)}})]})})},qs=A.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
|
+
`,Qs=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),a=i.useRef(null),{isPlaying:r,currentTimeRef:s}=It(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=At();return i.useEffect(()=>{const u=()=>{if(n.current){const w=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${w}px, 0, 0)`}r&&(a.current=requestAnimationFrame(u))};return r?a.current=requestAnimationFrame(u):u(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[r,l,o,t,s]),i.useEffect(()=>{if(!r&&n.current){const f=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}}),v.jsx(qs,{ref:n,$color:e,$width:c,"data-playhead":!0})},ei=A.div`
|
|
1246
|
+
position: relative;
|
|
1247
|
+
`,ti=A.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
|
+
`,ni=A.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
|
+
`,ai=A.div`
|
|
1268
|
+
position: relative;
|
|
1269
|
+
z-index: 2;
|
|
1270
|
+
`,ri=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=rt(),{waveHeight:o}=at(),{isPlaying:l,currentTimeRef:c}=It(),{samplesPerPixel:u,sampleRate:f}=At(),w=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const I=()=>{if(a.current){const b=(c.current??0)*f,p=e+t;let C=0;if(b<=e)C=0;else if(b>=p)C=n.length;else{const h=b-e;C=Math.floor(h/u)}a.current.style.width=`${C}px`}l&&(r.current=requestAnimationFrame(I))};return l?r.current=requestAnimationFrame(I):I(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,f,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&a.current){const m=(c.current??0)*f,b=e+t;let p=0;if(m<=e)p=0;else if(m>=b)p=n.length;else{const C=m-e;p=Math.floor(C/u)}a.current.style.width=`${p}px`}});const g=s?.waveformDrawMode||"inverted";let d;g==="inverted"?d=s?.selectedWaveFillColor||s?.waveFillColor||"white":d=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const x=Ye(d);return v.jsxs(ei,{children:[v.jsx(ti,{$color:x,$height:o,$top:n.index*o,$width:n.length}),v.jsx(ni,{ref:a,$color:w,$height:o,$top:n.index*o}),v.jsx(ai,{children:v.jsx(Dn,{...n,isSelected:!0,transparentBackground:!0})})]})},oi=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:a=!1,onAnnotationUpdate:r,className:s})=>{const o=rt(),{isPlaying:l,currentTimeRef:c}=It(),{annotations:u,activeAnnotationId:f,continuousPlay:w}=aa(),{play:g,seekTo:d,setActiveAnnotationId:x,setAnnotations:I}=ra(),{duration:m,peaksDataArray:b,sampleRate:p,waveHeight:C,timeScaleHeight:h,samplesPerPixel:k,controls:y,playoutRef:S,barWidth:R,barGap:E}=At(),[$,M]=i.useState(0),[D,_]=i.useState(0),[Z,T]=i.useState(!1),P=i.useRef(null),j=Math.floor(m*p/k),U=i.useCallback(async Y=>{x(Y.id),g(Y.start)},[x,g]),V=i.useCallback(Y=>{I(Y),r?.(Y)},[I,r]),{onDragStart:L,onDragMove:re,onDragEnd:te}=Ln({annotations:u,onAnnotationsChange:V,samplesPerPixel:k,sampleRate:p,duration:m,linkEndpoints:!0}),Q=i.useCallback(Y=>{const le=Y.currentTarget.getBoundingClientRect(),pe=y.show?y.width:0,K=(Y.clientX-le.left-pe)*k/p;T(!0),M(K),_(K)},[y,k,p]),q=i.useCallback(Y=>{if(!Z)return;const le=Y.currentTarget.getBoundingClientRect(),pe=y.show?y.width:0,K=(Y.clientX-le.left-pe)*k/p;_(K)},[Z,y,k,p]),be=i.useCallback(Y=>{if(!Z)return;T(!1);const le=Y.currentTarget.getBoundingClientRect(),pe=y.show?y.width:0,K=(Y.clientX-le.left-pe)*k/p,ee=Math.min($,K),We=Math.max($,K);Math.abs(We-ee)<.1?(d(ee),M(ee),_(ee),l&&S.current&&(S.current.stop(),g(ee))):(M(ee),_(We))},[Z,$,k,p,y,d,l,S,g]);if(b.length===0)return v.jsx("div",{className:s,children:"Loading waveform..."});const Ee=null;return v.jsx(Rn,{children:v.jsxs(yt.Provider,{value:{samplesPerPixel:k,sampleRate:p,zoomLevels:[k],waveHeight:C,timeScaleHeight:h,duration:m,controls:y,barWidth:R,barGap:E},children:[v.jsx(Vt,{theme:o,backgroundColor:Ye(o.waveOutlineColor),timescaleBackgroundColor:o.timescaleBackgroundColor,scrollContainerWidth:j+(y.show?y.width:0),timescaleWidth:j,tracksWidth:j,controlsWidth:y.show?y.width:0,onTracksMouseDown:Q,onTracksMouseMove:q,onTracksMouseUp:be,scrollContainerRef:Y=>{P.current=Y},isSelecting:Z,timescale:h>0?v.jsx(Bn,{duration:m*1e3,marker:1e4,bigStep:5e3,secondStep:1e3}):void 0,children:v.jsxs(v.Fragment,{children:[b.map((Y,le)=>{const pe=Y.length>0?Math.max(...Y.map(ce=>ce.peaks.data.length)):1;return v.jsx(Pt.Provider,{value:Ee,children:v.jsx(Tn,{numChannels:pe,backgroundColor:Ye(o.waveOutlineColor),offset:0,width:j,hasClipHeaders:!1,trackId:`media-element-track-${le}`,isSelected:!0,children:Y.map((ce,K)=>{const ee=ce.peaks,We=ee.length;return v.jsx(Tt,{clipId:ce.clipId,trackIndex:le,clipIndex:K,trackName:ce.trackName,startSample:ce.startSample,durationSamples:ce.durationSamples,samplesPerPixel:k,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${le}`,children:ee.data.map((je,ne)=>v.jsx(ri,{index:ne,data:je,bits:ee.bits,length:We,clipStartSample:ce.startSample,clipDurationSamples:ce.durationSamples},`${le}-${K}-${ne}`))},`${le}-${K}`)})})},le)}),u.length>0&&v.jsx(Re.DndContext,{onDragStart:L,onDragMove:re,onDragEnd:te,modifiers:a?[Da.restrictToHorizontalAxis]:[],children:v.jsx(zn,{height:30,width:j,children:u.map((Y,le)=>{const pe=Y.start*p/k,ce=Y.end*p/k,K=t?t(Y):Y.id;return v.jsx(Pn,{annotationId:Y.id,annotationIndex:le,startPosition:pe,endPosition:ce,label:K,color:"#ff9800",isActive:Y.id===f,onClick:()=>U(Y),editable:a},Y.id)})})}),$!==D&&v.jsx(Sn,{startPosition:Math.min($,D)*p/k+(y.show?y.width:0),endPosition:Math.max($,D)*p/k+(y.show?y.width:0),color:o.selectionColor}),v.jsx(Qs,{color:o.playheadColor,controlsOffset:y.show?y.width:0})]})}),u.length>0&&v.jsx(jn,{annotations:u,activeAnnotationId:f??void 0,shouldScrollToActive:!0,editable:a,annotationListConfig:{linkEndpoints:!0,continuousPlay:w},height:e,onAnnotationUpdate:V,renderAnnotationItem:n})]})})};exports.Tone=hn;exports.AudioPosition=Fs;exports.AutomaticScrollCheckbox=Vs;exports.ContinuousPlayCheckbox=Ps;exports.DownloadAnnotationsButton=Hs;exports.EditableCheckbox=js;exports.ExportWavButton=Xs;exports.FastForwardButton=Ss;exports.LinkEndpointsCheckbox=zs;exports.LoopButton=Rs;exports.MasterVolumeControl=Ts;exports.MediaElementPlaylistProvider=ws;exports.MediaElementWaveform=oi;exports.PauseButton=ks;exports.PlayButton=ys;exports.RewindButton=As;exports.SelectionTimeInputs=Zs;exports.SetLoopRegionButton=Es;exports.SkipBackwardButton=$s;exports.SkipForwardButton=Ms;exports.StopButton=Is;exports.TimeFormatSelect=Ws;exports.Waveform=Js;exports.WaveformPlaylistProvider=bs;exports.ZoomInButton=Ds;exports.ZoomOutButton=Bs;exports.createEffectChain=cs;exports.createEffectInstance=nt;exports.effectCategories=os;exports.effectDefinitions=ot;exports.getEffectDefinition=jt;exports.getEffectsByCategory=rs;exports.getShortcutLabel=Ho;exports.getWaveformDataMetadata=co;exports.loadPeaksFromWaveformData=lo;exports.loadWaveformData=zt;exports.useAnnotationDragHandlers=Ln;exports.useAnnotationKeyboardControls=Go;exports.useAudioTracks=Zo;exports.useClipDragHandlers=Vo;exports.useClipSplitting=jo;exports.useDragSensors=zo;exports.useDynamicEffects=us;exports.useExportWav=Yn;exports.useIntegratedRecording=as;exports.useKeyboardShortcuts=vt;exports.useMasterAnalyser=Wo;exports.useMasterVolume=Gn;exports.useMediaElementAnimation=It;exports.useMediaElementControls=ra;exports.useMediaElementData=At;exports.useMediaElementState=aa;exports.usePlaybackAnimation=Ie;exports.usePlaybackShortcuts=Xo;exports.usePlaylistControls=he;exports.usePlaylistData=we;exports.usePlaylistState=Te;exports.useTimeFormat=Hn;exports.useTrackDynamicEffects=ds;exports.useWaveformPlaylist=vs;exports.useZoomControls=Xn;exports.waveformDataToPeaks=Fn;
|
|
1236
1271
|
//# sourceMappingURL=index.js.map
|