@waveform-playlist/browser 5.2.0-next.4 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -4
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +617 -589
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var Wa=Object.create;var Jt=Object.defineProperty;var Fa=Object.getOwnPropertyDescriptor;var _a=Object.getOwnPropertyNames;var Za=Object.getPrototypeOf,Pa=Object.prototype.hasOwnProperty;var Va=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _a(t))!Pa.call(e,r)&&r!==n&&Jt(e,r,{get:()=>t[r],enumerable:!(a=Fa(t,r))||a.enumerable});return e};var ja=(e,t,n)=>(n=e!=null?Wa(Za(e)):{},Va(t||!e||!e.__esModule?Jt(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("tone"),b=require("react/jsx-runtime"),i=require("react"),A=require("styled-components"),Ee=require("@dnd-kit/core"),za=require("@dnd-kit/modifiers");var Et=typeof document<"u"?document.currentScript:null;function bn(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 vn=bn(W),N=bn(i);function qt(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 Ha(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 Xa(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 Ga(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 Cn(e,t,n){switch(e){case"linear":return qt(t,n);case"exponential":return Ha(t,n);case"sCurve":return Xa(t,n);case"logarithmic":return Ga(t,n);default:return qt(t,n)}}function Qt(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=Cn(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 en(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=Cn(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 Na=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)Qt(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-o,u=o/l,d=a.gain*u;Qt(s,t,c,a.fadeIn.type||"linear",d,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-o;if(c>0){const u=t+c;en(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,d=a.fadeOut.duration-u,v=u/a.fadeOut.duration,g=a.gain*(1-v);en(s,t,d,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 d=o-l+s.offset,v=s.duration-(o-l),g=n?Math.min(n,v):v;a.pausedPosition=d,this.scheduleFades(a,u,d),r.start(u,d,g)}else{const d=l-o,v=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+d,s.offset),r.start(u+d,s.offset,v)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(W.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??W.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},La=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 Na(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}},ht=null;function Ya(){return ht||(ht=new W.Context,W.setContext(ht)),ht}async function Dt(){const e=Ya();e.state!=="running"&&await e.resume()}const Wt=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[Wt.Translate.toString(e),Wt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),Oa=new Map([["bold",N.createElement(N.Fragment,null,N.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",N.createElement(N.Fragment,null,N.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",N.createElement(N.Fragment,null,N.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",N.createElement(N.Fragment,null,N.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",N.createElement(N.Fragment,null,N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",N.createElement(N.Fragment,null,N.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),Ka=new Map([["bold",N.createElement(N.Fragment,null,N.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",N.createElement(N.Fragment,null,N.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",N.createElement(N.Fragment,null,N.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",N.createElement(N.Fragment,null,N.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",N.createElement(N.Fragment,null,N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",N.createElement(N.Fragment,null,N.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),Ua=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),Zt=N.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:v,weight:g="regular",mirrored:f=!1,...C}=N.useContext(Ua);return N.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??v,height:r??v,fill:a??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...C,...u},!!n&&N.createElement("title",null,n),l,c.get(s??g))});Zt.displayName="IconBase";const xn=N.forwardRef((e,t)=>N.createElement(Zt,{ref:t,...e,weights:Oa}));xn.displayName="SpeakerHighIcon";const wn=N.forwardRef((e,t)=>N.createElement(Zt,{ref:t,...e,weights:Ka}));wn.displayName="SpeakerLowIcon";A.span`
|
|
1
|
+
"use strict";var Wa=Object.create;var Jt=Object.defineProperty;var Fa=Object.getOwnPropertyDescriptor;var _a=Object.getOwnPropertyNames;var Za=Object.getPrototypeOf,Pa=Object.prototype.hasOwnProperty;var Va=(e,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of _a(t))!Pa.call(e,r)&&r!==n&&Jt(e,r,{get:()=>t[r],enumerable:!(a=Fa(t,r))||a.enumerable});return e};var ja=(e,t,n)=>(n=e!=null?Wa(Za(e)):{},Va(t||!e||!e.__esModule?Jt(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("tone"),b=require("react/jsx-runtime"),i=require("react"),A=require("styled-components"),Ee=require("@dnd-kit/core"),za=require("@dnd-kit/modifiers");var Dt=typeof document<"u"?document.currentScript:null;function bn(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 vn=bn(W),N=bn(i);function qt(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 Ha(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 Xa(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 Ga(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 Cn(e,t,n){switch(e){case"linear":return qt(t,n);case"exponential":return Ha(t,n);case"sCurve":return Xa(t,n);case"logarithmic":return Ga(t,n);default:return qt(t,n)}}function Qt(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=Cn(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 en(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=Cn(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 Na=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)Qt(s,t,l,a.fadeIn.type||"linear",0,a.gain);else{const c=l-o,u=o/l,d=a.gain*u;Qt(s,t,c,a.fadeIn.type||"linear",d,a.gain)}}else s.setValueAtTime(a.gain,t);if(a.fadeOut){const c=a.duration-a.fadeOut.duration-o;if(c>0){const u=t+c;en(s,u,a.fadeOut.duration,a.fadeOut.type||"linear",a.gain,0)}else if(c>-a.fadeOut.duration){const u=-c,d=a.fadeOut.duration-u,v=u/a.fadeOut.duration,g=a.gain*(1-v);en(s,t,d,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 d=o-l+s.offset,v=s.duration-(o-l),g=n?Math.min(n,v):v;a.pausedPosition=d,this.scheduleFades(a,u,d),r.start(u,d,g)}else{const d=l-o,v=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(a.pausedPosition=s.offset,this.scheduleFades(a,u+d,s.offset),r.start(u+d,s.offset,v)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(W.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??W.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},La=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 Na(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}},ht=null;function Ya(){return ht||(ht=new W.Context,W.setContext(ht)),ht}async function Bt(){const e=Ya();e.state!=="running"&&await e.resume()}const Ft=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[Ft.Translate.toString(e),Ft.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:a}=e;return t+" "+n+"ms "+a}}}),Oa=new Map([["bold",N.createElement(N.Fragment,null,N.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,1,1-18-15.88,20,20,0,0,0,0-26.43,12,12,0,0,1,18-15.86A43.94,43.94,0,0,1,212,128Zm40,0a83.87,83.87,0,0,1-21.39,56,12,12,0,0,1-17.89-16,60,60,0,0,0,0-80,12,12,0,1,1,17.88-16A83.87,83.87,0,0,1,252,128Z"}))],["duotone",N.createElement(N.Fragment,null,N.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["fill",N.createElement(N.Fragment,null,N.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80Zm126.77,20.84a8,8,0,0,0-.72,11.3,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88A8,8,0,0,0,186.74,100.84Zm40.89-26.17a8,8,0,1,0-11.92,10.66,64,64,0,0,1,0,85.34,8,8,0,1,0,11.92,10.66,80,80,0,0,0,0-106.66Z"}))],["light",N.createElement(N.Fragment,null,N.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66Zm50.53-108.85a38,38,0,0,1,0,50.24,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93ZM246,128a77.86,77.86,0,0,1-19.86,52,6,6,0,1,1-8.94-8,66,66,0,0,0,0-88,6,6,0,1,1,8.94-8A77.86,77.86,0,0,1,246,128Z"}))],["regular",N.createElement(N.Fragment,null,N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55Zm54-106.08a40,40,0,0,1,0,52.88,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,0,1,12-10.58ZM248,128a79.9,79.9,0,0,1-20.37,53.34,8,8,0,0,1-11.92-10.67,64,64,0,0,0,0-85.33,8,8,0,1,1,11.92-10.67A79.83,79.83,0,0,1,248,128Z"}))],["thin",N.createElement(N.Fragment,null,N.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78Zm47-111.61a36,36,0,0,1,0,47.59,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28ZM244,128a75.88,75.88,0,0,1-19.35,50.67,4,4,0,0,1-6-5.34,68,68,0,0,0,0-90.66,4,4,0,0,1,6-5.34A75.88,75.88,0,0,1,244,128Z"}))]]),Ka=new Map([["bold",N.createElement(N.Fragment,null,N.createElement("path",{d:"M157.27,21.22a12,12,0,0,0-12.64,1.31L75.88,76H32A20,20,0,0,0,12,96v64a20,20,0,0,0,20,20H75.88l68.75,53.47A12,12,0,0,0,164,224V32A12,12,0,0,0,157.27,21.22ZM36,100H68v56H36Zm104,99.46L92,162.13V93.87l48-37.33ZM212,128a44,44,0,0,1-11,29.11,12,12,0,0,1-18-15.88,20,20,0,0,0,0-26.44,12,12,0,0,1,18-15.85A43.94,43.94,0,0,1,212,128Z"}))],["duotone",N.createElement(N.Fragment,null,N.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["fill",N.createElement(N.Fragment,null,N.createElement("path",{d:"M160,32.25V223.69a8.29,8.29,0,0,1-3.91,7.18,8,8,0,0,1-9-.56l-65.57-51A4,4,0,0,1,80,176.16V79.84a4,4,0,0,1,1.55-3.15l65.57-51a8,8,0,0,1,10,.16A8.27,8.27,0,0,1,160,32.25ZM60,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H60a4,4,0,0,0,4-4V84A4,4,0,0,0,60,80ZM198,101.56a8,8,0,1,0-12,10.58,24,24,0,0,1,0,31.72,8,8,0,1,0,12,10.58,40,40,0,0,0,0-52.88Z"}))],["light",N.createElement(N.Fragment,null,N.createElement("path",{d:"M154.64,26.61a6,6,0,0,0-6.32.65L77.94,82H32A14,14,0,0,0,18,96v64a14,14,0,0,0,14,14H77.94l70.38,54.74A6,6,0,0,0,158,224V32A6,6,0,0,0,154.64,26.61ZM30,160V96a2,2,0,0,1,2-2H74v68H32A2,2,0,0,1,30,160Zm116,51.73L86,165.07V90.93l60-46.66ZM206,128a37.94,37.94,0,0,1-9.5,25.14,6,6,0,1,1-9-7.94,26,26,0,0,0,0-34.37,6,6,0,0,1,9-7.93A38,38,0,0,1,206,128Z"}))],["regular",N.createElement(N.Fragment,null,N.createElement("path",{d:"M155.51,24.81a8,8,0,0,0-8.42.88L77.25,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H77.25l69.84,54.31A8,8,0,0,0,160,224V32A8,8,0,0,0,155.51,24.81ZM32,96H72v64H32ZM144,207.64,88,164.09V91.91l56-43.55ZM208,128a39.93,39.93,0,0,1-10,26.46,8,8,0,0,1-12-10.58,24,24,0,0,0,0-31.72,8,8,0,1,1,12-10.58A40,40,0,0,1,208,128Z"}))],["thin",N.createElement(N.Fragment,null,N.createElement("path",{d:"M153.76,28.41a4,4,0,0,0-4.22.43L78.63,84H32A12,12,0,0,0,20,96v64a12,12,0,0,0,12,12H78.63l70.91,55.16A4.07,4.07,0,0,0,152,228a3.92,3.92,0,0,0,1.76-.41A4,4,0,0,0,156,224V32A4,4,0,0,0,153.76,28.41ZM28,160V96a4,4,0,0,1,4-4H76v72H32A4,4,0,0,1,28,160Zm120,55.82L84,166V90l64-49.78ZM204,128a36,36,0,0,1-9,23.82,4,4,0,1,1-6-5.3,28,28,0,0,0,0-37,4,4,0,0,1,6-5.28A36,36,0,0,1,204,128Z"}))]]),Ua=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),Pt=N.forwardRef((e,t)=>{const{alt:n,color:a,size:r,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:v,weight:g="regular",mirrored:f=!1,...C}=N.useContext(Ua);return N.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:r??v,height:r??v,fill:a??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...C,...u},!!n&&N.createElement("title",null,n),l,c.get(s??g))});Pt.displayName="IconBase";const xn=N.forwardRef((e,t)=>N.createElement(Pt,{ref:t,...e,weights:Oa}));xn.displayName="SpeakerHighIcon";const wn=N.forwardRef((e,t)=>N.createElement(Pt,{ref:t,...e,weights:Ka}));wn.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 Vt=A.button`
|
|
8
8
|
display: inline-flex;
|
|
9
9
|
align-items: center;
|
|
10
10
|
justify-content: center;
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
opacity: 0.6;
|
|
34
34
|
cursor: not-allowed;
|
|
35
35
|
}
|
|
36
|
-
`;A(
|
|
36
|
+
`;A(Vt)`
|
|
37
37
|
padding: 0.25rem 0.5rem;
|
|
38
38
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
39
|
-
`;A(
|
|
39
|
+
`;A(Vt)`
|
|
40
40
|
padding: 0.5rem;
|
|
41
41
|
min-width: 2.25rem;
|
|
42
42
|
min-height: 2.25rem;
|
|
43
|
-
`;A(
|
|
43
|
+
`;A(Vt)`
|
|
44
44
|
padding: 0.25rem;
|
|
45
45
|
min-width: 1.75rem;
|
|
46
46
|
min-height: 1.75rem;
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
clip: rect(0, 0, 0, 0);
|
|
142
142
|
white-space: nowrap;
|
|
143
143
|
border: 0;
|
|
144
|
-
`,
|
|
144
|
+
`,jt=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,7 +172,7 @@
|
|
|
172
172
|
color: ${e=>e.theme.inputText};
|
|
173
173
|
background-color: ${e=>e.theme.inputBackground};
|
|
174
174
|
}
|
|
175
|
-
`;A(
|
|
175
|
+
`;A(jt)`
|
|
176
176
|
padding: 0.25rem 1.75rem 0.25rem 0.5rem;
|
|
177
177
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
178
178
|
`;var In=A.input.attrs({type:"range"})`
|
|
@@ -265,7 +265,7 @@
|
|
|
265
265
|
/* Force GPU compositing layer to reduce scroll flickering */
|
|
266
266
|
transform: translateZ(0);
|
|
267
267
|
backface-visibility: hidden;
|
|
268
|
-
`,ar=e=>{const{data:t,bits:n,length:a,index:r,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:v=0,transparentBackground:g=!1,drawMode:f="inverted"}=e,C=i.useRef([]),y=i.useCallback(w=>{if(w!==null){const k=parseInt(w.dataset.index,10);C.current[k]=w}},[]);i.useLayoutEffect(()=>{const w=C.current,k=d+v;let S=0;for(let
|
|
268
|
+
`,ar=e=>{const{data:t,bits:n,length:a,index:r,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:v=0,transparentBackground:g=!1,drawMode:f="inverted"}=e,C=i.useRef([]),y=i.useCallback(w=>{if(w!==null){const k=parseInt(w.dataset.index,10);C.current[k]=w}},[]);i.useLayoutEffect(()=>{const w=C.current,k=d+v;let S=0;for(let $=0;$<w.length;$++){const E=w[$],R=E.getContext("2d"),M=Math.floor(l/2),Z=2**(n-1);if(R){R.resetTransform(),R.clearRect(0,0,E.width,E.height),R.imageSmoothingEnabled=!1,R.scale(o,o);const D=E.width/o;let P;f==="normal"?P=u:P=c,R.fillStyle=er(R,P,D,l);const H=S,O=S+D,V=Math.floor((H-d+k)/k)*k;for(let q=Math.max(0,V);q<O;q+=k){const T=q-H;if(T+d<=0)continue;const Q=q;if(Q*2+1<t.length){const J=t[Q*2]/Z,oe=t[Q*2+1]/Z,ee=Math.abs(J*M),te=Math.abs(oe*M);f==="normal"?R.fillRect(T,M-te,d,te+ee):(R.fillRect(T,0,d,M-te),R.fillRect(T,M+ee,d,M-ee))}}}S+=E.width/o}},[t,n,l,c,u,o,a,d,v,f]);let h=a,p=0;const I=[];for(;h>0;){const w=Math.min(h,Qa),k=b.jsx(tr,{$cssWidth:w,width:w*o,height:l*o,$waveHeight:l,"data-index":p,ref:y},`${a}-${p}`);I.push(k),h-=w,p+=1}const m=g?"transparent":Ye(u);return b.jsx(nr,{$index:r,$cssWidth:a,className:s,$waveHeight:l,$waveFillColor:m,children:I})},$n=22,Mn=A.div`
|
|
269
269
|
position: relative;
|
|
270
270
|
height: ${$n}px;
|
|
271
271
|
background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
|
|
@@ -355,7 +355,7 @@
|
|
|
355
355
|
flex: 1;
|
|
356
356
|
position: relative;
|
|
357
357
|
overflow: ${e=>e.$isOverlay?"visible":"hidden"};
|
|
358
|
-
`,
|
|
358
|
+
`,_t=({children:e,className:t,clipId:n,trackIndex:a,clipIndex:r,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:d=!1,isOverlay:v=!1,isSelected:g=!1,onMouseDown:f,trackId:C,fadeIn:y,fadeOut:h,sampleRate:p=44100,showFades:I=!1,touchOptimized:x=!1})=>{const m=Math.floor(o/c),k=Math.floor((o+l)/c)-m,S=u&&!d&&!v,$=`clip-${a}-${r}`,{attributes:E,listeners:R,setNodeRef:M,setActivatorNodeRef:Z,transform:D,isDragging:P}=Ee.useDraggable({id:$,data:{clipId:n,trackIndex:a,clipIndex:r},disabled:!S}),H=`clip-boundary-left-${a}-${r}`,{attributes:O,listeners:V,setActivatorNodeRef:q,isDragging:T}=Ee.useDraggable({id:H,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"left"},disabled:!S}),Q=`clip-boundary-right-${a}-${r}`,{attributes:J,listeners:oe,setActivatorNodeRef:ee,isDragging:te}=Ee.useDraggable({id:Q,data:{clipId:n,trackIndex:a,clipIndex:r,boundary:"right"},disabled:!S}),me=D?{transform:Ft.Translate.toString(D),zIndex:P?100:void 0}:void 0;return b.jsxs(fr,{ref:M,style:me,className:t,$left:m,$width:k,$isOverlay:v,"data-clip-container":"true","data-track-id":C,onMouseDown:f,children:[u&&b.jsx(or,{clipId:n,trackIndex:a,clipIndex:r,trackName:s,isSelected:g,disableDrag:d,dragHandleProps:S?{attributes:E,listeners:R,setActivatorNodeRef:Z}:void 0}),b.jsxs(mr,{$isOverlay:v,children:[e,I&&y&&y.duration>0&&b.jsx(nn,{left:0,width:Math.floor(y.duration*p/c),type:"fadeIn",curveType:y.type}),I&&h&&h.duration>0&&b.jsx(nn,{left:k-Math.floor(h.duration*p/c),width:Math.floor(h.duration*p/c),type:"fadeOut",curveType:h.type})]}),u&&!d&&!v&&b.jsxs(b.Fragment,{children:[b.jsx(tn,{clipId:n,trackIndex:a,clipIndex:r,edge:"left",touchOptimized:x,dragHandleProps:{attributes:O,listeners:V,setActivatorNodeRef:q,isDragging:T}}),b.jsx(tn,{clipId:n,trackIndex:a,clipIndex:r,edge:"right",touchOptimized:x,dragHandleProps:{attributes:J,listeners:oe,setActivatorNodeRef:ee,isDragging:te}})]})]})},hr=A.div`
|
|
359
359
|
display: inline-flex;
|
|
360
360
|
align-items: center;
|
|
361
361
|
gap: 0.5rem;
|
|
@@ -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
|
+
`,zt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:a,timescaleWidth:r,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:d,onTracksMouseUp:v,scrollContainerRef:g,isSelecting:f,"data-playlist-state":C})=>b.jsx(vr,{"data-scroll-container":"true","data-playlist-state":C,ref:g,children:b.jsxs(Cr,{$backgroundColor:t,$width:o,children:[a&&b.jsx(xr,{$width:r,$backgroundColor:n,children:a}),b.jsxs(wr,{$width:s,$backgroundColor:t,children:[e,(c||u)&&b.jsx(yr,{$controlsWidth:l,$isSelecting:f,onClick:c,onMouseDown:u,onMouseMove:d,onMouseUp:v})]})]})});A.withTheme(zt);var kr=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};
|
|
@@ -506,14 +506,14 @@
|
|
|
506
506
|
&:active {
|
|
507
507
|
cursor: grabbing;
|
|
508
508
|
}
|
|
509
|
-
`,Ar=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),v=i.useRef(0),g=i.useRef(0),f=i.useRef(0),C=Math.max(0,t-e),y=i.useCallback((p,I)=>{p.preventDefault(),p.stopPropagation(),d(I),v.current=p.clientX,g.current=I==="start"?e:t;const x=w=>{const k=w.clientX-v.current,S=g.current+k;if(I==="start"){const
|
|
509
|
+
`,Ar=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopStartChange:r,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),v=i.useRef(0),g=i.useRef(0),f=i.useRef(0),C=Math.max(0,t-e),y=i.useCallback((p,I)=>{p.preventDefault(),p.stopPropagation(),d(I),v.current=p.clientX,g.current=I==="start"?e:t;const x=w=>{const k=w.clientX-v.current,S=g.current+k;if(I==="start"){const $=Math.max(l,Math.min(t-10,S));r?.($)}else{const $=Math.max(e+10,Math.min(c,S));s?.($)}},m=()=>{d(null),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",m)},[e,t,l,c,r,s]),h=i.useCallback(p=>{p.preventDefault(),p.stopPropagation(),d("region"),v.current=p.clientX,g.current=e,f.current=t;const I=t-e,x=w=>{const k=w.clientX-v.current;let S=g.current+k,$=f.current+k;S<l&&(S=l,$=l+I),$>c&&($=c,S=c-I),o?.(S,$)},m=()=>{d(null),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",m)},[e,t,l,c,o]);return C<=0?null:b.jsxs(b.Fragment,{children:[b.jsx(Ir,{$left:e,$width:C,$color:a,$isDragging:u==="region",onMouseDown:h,"data-loop-region-timescale":!0}),b.jsx(an,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:p=>y(p,"start"),"data-loop-marker-handle":"start"}),b.jsx(an,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:p=>y(p,"end"),"data-loop-marker-handle":"end"})]})},Sr=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
|
-
`,$r=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),v=i.useRef(null),g=t>e,f=i.useCallback(C=>{const y=C.target;if(y.closest("[data-loop-marker-handle]")||y.closest("[data-loop-region-timescale]"))return;C.preventDefault(),u(!0);const h=v.current?.getBoundingClientRect();if(!h)return;const p=C.clientX-h.left,I=Math.max(s,Math.min(o,p));d.current=I,r?.(I,I);const x=w=>{const k=w.clientX-h.left,S=Math.max(s,Math.min(o,k))
|
|
516
|
+
`,$r=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:a="rgba(59, 130, 246, 0.3)",onLoopRegionChange:r,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),v=i.useRef(null),g=t>e,f=i.useCallback(C=>{const y=C.target;if(y.closest("[data-loop-marker-handle]")||y.closest("[data-loop-region-timescale]"))return;C.preventDefault(),u(!0);const h=v.current?.getBoundingClientRect();if(!h)return;const p=C.clientX-h.left,I=Math.max(s,Math.min(o,p));d.current=I,r?.(I,I);const x=w=>{const k=w.clientX-h.left,S=Math.max(s,Math.min(o,k)),$=Math.min(d.current,S),E=Math.max(d.current,S);r?.($,E)},m=()=>{u(!1),document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",m)},[s,o,r]);return b.jsx(Sr,{ref:v,$leftOffset:l,onMouseDown:f,"data-timescale-loop-creator":!0,children:g&&b.jsx(Ar,{startPosition:e,endPosition:t,markerColor:n,regionColor:a,minPosition:s,maxPosition:o,onLoopStartChange:C=>r?.(C,t),onLoopEndChange:C=>r?.(e,C),onLoopRegionMove:(C,y)=>r?.(C,y)})})};function ot(e,t){const n=Math.floor(e/3600)%24,a=Math.floor(e/60)%60,r=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(a).padStart(2,"0")+":"+r.padStart(t+3,"0")}function tt(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return ot(e,0);case"hh:mm:ss.u":return ot(e,1);case"hh:mm:ss.uu":return ot(e,2);case"hh:mm:ss.uuu":return ot(e,3);default:return ot(e,3)}}function Dn(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 rn=({id:e,label:t,value:n,format:a,className:r,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const g=tt(n,a);c(g)},[n,a,e]);const u=g=>{const f=g.target.value;c(f)},d=()=>{if(s){const g=Dn(l,a);s(g)}c(tt(n,a))},v=g=>{g.key==="Enter"&&g.currentTarget.blur()};return b.jsxs(b.Fragment,{children:[b.jsx(Ja,{as:"label",htmlFor:e,children:t}),b.jsx(yn,{type:"text",className:r,id:e,value:l,onChange:u,onBlur:d,onKeyDown:v,readOnly:o})]})},Mr=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:a})=>{const[r,s]=i.useState("hh:mm:ss.uuu");i.useEffect(()=>{const c=document.querySelector(".time-format"),u=()=>{c&&s(c.value)};return c&&(s(c.value),c.addEventListener("change",u)),()=>{c?.removeEventListener("change",u)}},[]);const o=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return b.jsxs(b.Fragment,{children:[b.jsx(rn,{id:"audio_start",label:"Start of audio selection",value:e,format:r,className:"audio-start form-control mr-sm-2",onChange:o}),b.jsx(rn,{id:"audio_end",label:"End of audio selection",value:t,format:r,className:"audio-end form-control mr-sm-2",onChange:l})]})};function bt(){return window.devicePixelRatio}var Bn=i.createContext(bt()),Tn=({children:e})=>{const[t,n]=i.useState(bt());return matchMedia(`(resolution: ${bt()}dppx)`).addEventListener("change",()=>{n(bt())},{once:!0}),b.jsx(Bn.Provider,{value:Math.ceil(t),children:e})},Wn=()=>i.useContext(Bn),kt=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}),lt=()=>i.useContext(kt),ct=()=>i.useContext(A.ThemeContext),Ht=i.createContext(b.jsx(i.Fragment,{})),Rr=()=>i.useContext(Ht),Er=0,Dr=!1,Br=0,Tr=0,Wr={progress:Er,isPlaying:Dr,selectionStart:Br,selectionEnd:Tr};i.createContext(Wr);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var Fn=({isSelected:e,transparentBackground:t,...n})=>{const a=ct(),{waveHeight:r,barWidth:s,barGap:o}=lt(),l=Wn(),c=e&&a?a.selectedWaveOutlineColor:a?.waveOutlineColor,u=e&&a?a.selectedWaveFillColor:a?.waveFillColor,d=a?.waveformDrawMode||"inverted";return b.jsx(ar,{...n,...a,waveOutlineColor:c,waveFillColor:u,waveHeight:r,devicePixelRatio:l,barWidth:s,barGap:o,transparentBackground:t,drawMode:d})};function Fr(e,t,n){return Math.ceil(e*n/t)}function _r(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var Zr=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};
|
|
@@ -532,7 +532,7 @@
|
|
|
532
532
|
display: inline-flex;
|
|
533
533
|
align-items: center;
|
|
534
534
|
gap: 0.5rem;
|
|
535
|
-
`,Hr=[{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"}],Xr=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return b.jsx(zr,{className:a,children:b.jsx(
|
|
535
|
+
`,Hr=[{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"}],Xr=({value:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.value)};return b.jsx(zr,{className:a,children:b.jsx(jt,{className:"time-format",value:e,onChange:r,disabled:n,"aria-label":"Time format selection",children:Hr.map(s=>b.jsx("option",{value:s.value,children:s.label},s.value))})})},Gr=A.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?$n:0)}px`}}))`
|
|
536
536
|
position: relative;
|
|
537
537
|
display: flex;
|
|
538
538
|
${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
|
|
@@ -744,8 +744,8 @@
|
|
|
744
744
|
&:active {
|
|
745
745
|
transform: scale(0.9);
|
|
746
746
|
}
|
|
747
|
-
`;function qr(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 cn(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 Pn(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function un(e,t,n){const a=e.length,r=Math.ceil(a/t),s=Pn(n,r*2);for(let o=0;o<r;o++){const l=o*t,c=Math.min((o+1)*t,a),u=e.subarray(l,c),d=qr(u),v=cn(d.min,n),g=cn(d.max,n);s[o*2]=v,s[o*2+1]=g}return s}function Qr(e,t){const n=e.length,a=1/n,r=e[0].length/2,s=Pn(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 eo(e,t=1e3,n=!0,a=0,r,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=r??e.length;for(let d=0;d<c;d++){const g=e.getChannelData(d).subarray(a,u);o.push(un(g,t,s))}}else{const c=r??e.length,u=e.subarray(a,c);o.push(un(u,t,s))}return n&&o.length>1&&(o=Qr(o,s)),{length:o[0].length/2,data:o,bits:s}}function to(e,t=1e3,n=!0,a=8,r=0,s){const o=s!==void 0?r+s:void 0;return eo(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 no=127,ao=-128,ro=32767,oo=-32768;function so(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function io(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(
|
|
748
|
-
`,10)+1,s=a.substring(r)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function ho(e,t,n){var a;return function(s){return a=a||mo(e),new Worker(a,s)}}var po=ho("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function De(e){if(lo(e)&&(e=uo(e)),co(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 st={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function go(e){var t={scale:e.scale||st.scale,bits:e.bits||st.bits,amplitude_scale:e.amplitude_scale||st.amplitude_scale,split_channels:e.split_channels||st.split_channels,disable_worker:e.disable_worker||st.disable_worker};return t}function bo(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Vn(e,t,n){var a=bo(e);if(t.disable_worker){var r=io({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 po;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 vo(e,t,n,a){function r(o){o||(o=new DOMException("EncodingError")),a(o),a=function(){}}var s=e.decodeAudioData(t,function(o){Vn(o,n,a)},r);s&&s.catch(r)}De.create=function(t){return new De(t)};De.createFromAudio=function(e,t){var n=go(e);if(e.audio_context&&e.array_buffer)return vo(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Vn(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function It(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}It.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};It.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};It.prototype.getOutputData=function(){return this._output_data};De.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!et(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!et(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new It(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(p){return p._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),d=new DataView(s[0]),v=new DataView(u),g=0;g<n;g++)v.setUint8(g,d.getUint8(g));v.setInt32(16,r,!0);for(var f=0,C=new Uint8Array(u,n),y=0;y<s.length;y++){var h=s[y];C.set(new Uint8Array(h,n),f),f+=h.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!et(t.startIndex)&&!et(t.endIndex)?(n=t.startIndex,a=t.endIndex):!et(t.startTime)&&!et(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,s=24,o=this.bits===8?1:2,l=s+r*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var d=0;d<r*this.channels*2;d++){var v=this._at(n*this.channels*2+d);this.bits===8?u.setInt8(s+d,v):u.setInt16(s+d*2,v,!0)}return new De(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var a=0;a<this.channels;a++)t.data.push(this.channel(a).min_sample(n)),t.data.push(this.channel(a).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function Ht(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 jn(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 Co(e,t=0){const n=await Ht(e);return jn(n,t)}async function xo(e){const t=await Ht(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,f=Math.floor(a/g),C=Math.ceil((a+r)/g);s=s.slice({startIndex:f,endIndex:C})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),d=c.length,v=l===8?new Int8Array(d*2):new Int16Array(d*2);for(let g=0;g<d;g++)v[g*2]=c[g],v[g*2+1]=u[g];return{data:v,bits:l,length:d}}function Hn(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function wo(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 qr(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 cn(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 Pn(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function un(e,t,n){const a=e.length,r=Math.ceil(a/t),s=Pn(n,r*2);for(let o=0;o<r;o++){const l=o*t,c=Math.min((o+1)*t,a),u=e.subarray(l,c),d=qr(u),v=cn(d.min,n),g=cn(d.max,n);s[o*2]=v,s[o*2+1]=g}return s}function Qr(e,t){const n=e.length,a=1/n,r=e[0].length/2,s=Pn(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 eo(e,t=1e3,n=!0,a=0,r,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=r??e.length;for(let d=0;d<c;d++){const g=e.getChannelData(d).subarray(a,u);o.push(un(g,t,s))}}else{const c=r??e.length,u=e.subarray(a,c);o.push(un(u,t,s))}return n&&o.length>1&&(o=Qr(o,s)),{length:o[0].length/2,data:o,bits:s}}function to(e,t=1e3,n=!0,a=8,r=0,s){const o=s!==void 0?r+s:void 0;return eo(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 no=127,ao=-128,ro=32767,oo=-32768;function so(e,t){var n=Math.floor(e/t),a=e-n*t;return a>0&&n++,n}function io(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=so(r,t),d=e.bits===8?1:2,v=c+u*2*d*l,g=new ArrayBuffer(v),f=new DataView(g),C=0,y=c,h=new Array(l),p=new Array(l),I=0;I<l;I++)h[I]=1/0,p[I]=-1/0;var x=e.bits===8?ao:oo,m=e.bits===8?no:ro;f.setInt32(0,2,!0),f.setUint32(4,e.bits===8,!0),f.setInt32(8,s,!0),f.setInt32(12,t,!0),f.setInt32(16,u,!0),f.setInt32(20,l,!0);for(var w=0;w<r;w++){var k=0;if(l===1){for(var S=0;S<o.length;++S)k+=o[S][w];k=Math.floor(m*k*n/o.length),k<h[0]&&(h[0]=k,h[0]<x&&(h[0]=x)),k>p[0]&&(p[0]=k,p[0]>m&&(p[0]=m))}else for(var $=0;$<l;++$)k=Math.floor(m*o[$][w]*n),k<h[$]&&(h[$]=k,h[$]<x&&(h[$]=x)),k>p[$]&&(p[$]=k,p[$]>m&&(p[$]=m));if(++C===t){for(var E=0;E<l;E++)e.bits===8?(f.setInt8(y++,h[E]),f.setInt8(y++,p[E])):(f.setInt16(y,h[E],!0),f.setInt16(y+2,p[E],!0),y+=4),h[E]=1/0,p[E]=-1/0;C=0}}if(C>0)for(var R=0;R<l;R++)e.bits===8?(f.setInt8(y++,h[R]),f.setInt8(y++,p[R])):(f.setInt16(y,h[R],!0),f.setInt16(y+2,p[R],!0));return g}function vt(e){"@babel/helpers - typeof";return vt=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},vt(e)}function lo(e){return e&&vt(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function co(e){var t=e&&vt(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 uo(e){var t=e.data,n=e.channels||1,a=24,r=e.bits===8?1:2,s=e.length*2*n;if(t.length!==s)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var o=a+t.length*r,l=new ArrayBuffer(o),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=a;if(e.bits===8)for(var d=0;d<t.length;d++)c.setInt8(u++,t[d],!0);else for(var v=0;v<t.length;v++)c.setInt16(u,t[v],!0),u+=2;return l}function et(e){return e==null}function fo(e,t){var n=atob(e);return n}function mo(e,t,n){var a=fo(e),r=a.indexOf(`
|
|
748
|
+
`,10)+1,s=a.substring(r)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function ho(e,t,n){var a;return function(s){return a=a||mo(e),new Worker(a,s)}}var po=ho("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function De(e){if(lo(e)&&(e=uo(e)),co(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 st={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function go(e){var t={scale:e.scale||st.scale,bits:e.bits||st.bits,amplitude_scale:e.amplitude_scale||st.amplitude_scale,split_channels:e.split_channels||st.split_channels,disable_worker:e.disable_worker||st.disable_worker};return t}function bo(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function Vn(e,t,n){var a=bo(e);if(t.disable_worker){var r=io({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 po;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 vo(e,t,n,a){function r(o){o||(o=new DOMException("EncodingError")),a(o),a=function(){}}var s=e.decodeAudioData(t,function(o){Vn(o,n,a)},r);s&&s.catch(r)}De.create=function(t){return new De(t)};De.createFromAudio=function(e,t){var n=go(e);if(e.audio_context&&e.array_buffer)return vo(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return Vn(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function It(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}It.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};It.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};It.prototype.getOutputData=function(){return this._output_data};De.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!et(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!et(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new It(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(p){return p._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);a+=l.byteLength-n,r+=c}for(var u=new ArrayBuffer(a),d=new DataView(s[0]),v=new DataView(u),g=0;g<n;g++)v.setUint8(g,d.getUint8(g));v.setInt32(16,r,!0);for(var f=0,C=new Uint8Array(u,n),y=0;y<s.length;y++){var h=s[y];C.set(new Uint8Array(h,n),f),f+=h.byteLength-n}return u},slice:function(t){var n=0,a=0;if(!et(t.startIndex)&&!et(t.endIndex)?(n=t.startIndex,a=t.endIndex):!et(t.startTime)&&!et(t.endTime)&&(n=this.at_time(t.startTime),a=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(a<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),a>this.length&&(a=this.length),n>a&&(n=a);var r=a-n,s=24,o=this.bits===8?1:2,l=s+r*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,r,!0),u.setInt32(20,this.channels,!0);for(var d=0;d<r*this.channels*2;d++){var v=this._at(n*this.channels*2+d);this.bits===8?u.setInt8(s+d,v):u.setInt16(s+d*2,v,!0)}return new De(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var a=0;a<this.channels;a++)t.data.push(this.channel(a).min_sample(n)),t.data.push(this.channel(a).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function Xt(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 jn(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 Co(e,t=0){const n=await Xt(e);return jn(n,t)}async function xo(e){const t=await Xt(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,f=Math.floor(a/g),C=Math.ceil((a+r)/g);s=s.slice({startIndex:f,endIndex:C})}s.scale!==t&&(s=s.resample({scale:t}));const o=s.channel(n),l=s.bits,c=o.min_array(),u=o.max_array(),d=c.length,v=l===8?new Int8Array(d*2):new Int16Array(d*2);for(let g=0;g<d;g++)v[g*2]=c[g],v[g*2+1]=u[g];return{data:v,bits:l,length:d}}function Hn(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function wo(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};
|
|
@@ -1036,7 +1036,7 @@
|
|
|
1036
1036
|
background: rgba(255, 152, 0, 0.1);
|
|
1037
1037
|
}
|
|
1038
1038
|
`,Zo=({annotations:e,activeAnnotationId:t,shouldScrollToActive:n=!1,scrollActivePosition:a="center",scrollActiveContainer:r="nearest",editable:s=!1,controls:o=[],annotationListConfig:l,height:c,onAnnotationClick:u,onAnnotationUpdate:d,renderAnnotationItem:v})=>{const g=i.useRef(null),f=i.useRef(null),C=i.useRef(void 0);i.useEffect(()=>{}),i.useEffect(()=>{const m=f.current;if(!m)return;const w=()=>{};return m.addEventListener("scroll",w),()=>m.removeEventListener("scroll",w)},[]),i.useEffect(()=>{t&&g.current&&n&&g.current.scrollIntoView({behavior:"smooth",block:a,container:r}),C.current=t},[t,n,a,r]);const y=m=>{if(isNaN(m)||!isFinite(m))return"0:00.000";const w=Math.floor(m/60),k=(m%60).toFixed(3);return`${w}:${k.padStart(6,"0")}`},h=(m,w)=>{if(!s||!d)return;const k=[...e];k[m]={...k[m],lines:w.split(`
|
|
1039
|
-
`)},d(k)},p=(m,w)=>{if(!s||!d)return;const k=w.trim();if(!k)return;const S=[...e];S[m]={...S[m],id:k},d(S)},I=(m,w,k)=>{if(!d)return;const S=[...e];m.action(S[k],k,S,l||{}),d(S)},x=m=>m.replace(/\./g," ");return b.jsx(Mo,{ref:f,$height:c,children:e.map((m,w)=>{const k=m.id===t,S=()=>u?.(m);return v?b.jsx("div",{ref:k?g:null,children:v({annotation:m,index:w,isActive:k,onClick:S,formatTime:y})},m.id):b.jsxs(Ro,{ref:k?g:null,$isActive:k,onClick:S,children:[b.jsxs(Eo,{children:[b.jsxs(Do,{children:[b.jsx(Bo,{$isEditable:s,contentEditable:s,suppressContentEditableWarning:!0,onBlur
|
|
1039
|
+
`)},d(k)},p=(m,w)=>{if(!s||!d)return;const k=w.trim();if(!k)return;const S=[...e];S[m]={...S[m],id:k},d(S)},I=(m,w,k)=>{if(!d)return;const S=[...e];m.action(S[k],k,S,l||{}),d(S)},x=m=>m.replace(/\./g," ");return b.jsx(Mo,{ref:f,$height:c,children:e.map((m,w)=>{const k=m.id===t,S=()=>u?.(m);return v?b.jsx("div",{ref:k?g:null,children:v({annotation:m,index:w,isActive:k,onClick:S,formatTime:y})},m.id):b.jsxs(Ro,{ref:k?g:null,$isActive:k,onClick:S,children:[b.jsxs(Eo,{children:[b.jsxs(Do,{children:[b.jsx(Bo,{$isEditable:s,contentEditable:s,suppressContentEditableWarning:!0,onBlur:$=>p(w,$.currentTarget.textContent||""),onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),$.currentTarget.blur())},children:m.id}),b.jsxs(To,{children:[y(m.start)," - ",y(m.end)]})]}),o.length>0&&b.jsx(Wo,{onClick:$=>$.stopPropagation(),children:o.map(($,E)=>b.jsx(Fo,{title:$.title,onClick:()=>I($,m,w),children:$.text?$.text:b.jsx("i",{className:x($.class||"")})},E))})]}),b.jsx(_o,{$isEditable:s,contentEditable:s,suppressContentEditableWarning:!0,onBlur:$=>h(w,$.currentTarget.textContent||""),onKeyDown:$=>{$.key==="Enter"&&($.preventDefault(),$.currentTarget.blur())},children:m.lines.join(`
|
|
1040
1040
|
`)})]},m.id)})})},Nn=i.memo(Zo),Po=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return b.jsxs(xt,{className:a,children:[b.jsx(wt,{type:"checkbox",id:"continuous-play",className:"continuous-play",checked:e,onChange:r,disabled:n}),b.jsx(yt,{htmlFor:"continuous-play",children:"Continuous Play"})]})},Vo=({checked:e,onChange:t,disabled:n=!1,className:a})=>{const r=s=>{t(s.target.checked)};return b.jsxs(xt,{className:a,children:[b.jsx(wt,{type:"checkbox",id:"link-endpoints",className:"link-endpoints",checked:e,onChange:r,disabled:n}),b.jsx(yt,{htmlFor:"link-endpoints",children:"Link Endpoints"})]})},jo=({checked:e,onChange:t,className:n})=>b.jsxs(xt,{className:n,children:[b.jsx(wt,{type:"checkbox",id:"editable-annotations",checked:e,onChange:a=>t(a.target.checked)}),b.jsx(yt,{htmlFor:"editable-annotations",children:"Editable Annotations"})]}),zo=A.button`
|
|
1041
1041
|
padding: 0.5rem 1rem;
|
|
1042
1042
|
background: ${e=>e.theme?.surfaceColor||"#f5f5f5"};
|
|
@@ -1063,7 +1063,7 @@
|
|
|
1063
1063
|
opacity: 0.6;
|
|
1064
1064
|
cursor: not-allowed;
|
|
1065
1065
|
}
|
|
1066
|
-
`,Ho=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:a,children:r="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(v=>wo(v)),l=JSON.stringify(o,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),d=document.createElement("a");d.href=u,d.download=t,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(u)};return b.jsx(zo,{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 Ln(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>tt(r,e),parseTime:r=>Dn(r,e)}}const Xo=[256,512,1024,2048,4096,8192];function Yn({initialSamplesPerPixel:e,zoomLevels:t=Xo}){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 On({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 Go=(e=256)=>{const t=i.useRef(null),n=i.useCallback((a,r,s)=>{const o=new W.Analyser("fft",e);return a.connect(o),a.connect(r),t.current=o,function(){o.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function _t(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,v=t?.length??e.sourceDurationSamples??(u&&d?Math.ceil(u.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(v===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.durationSamples??v;return{id:Kn(),audioBuffer:t,startSample:n,durationSamples:g,offsetSamples:a,sampleRate:d,sourceDurationSamples:v,gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function No(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const v=t?.duration??e.sourceDuration??u?.duration;if(v===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.duration??v;return _t({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(g*d),offsetSamples:Math.round(a*d),sampleRate:d,sourceDurationSamples:Math.ceil(v*d),gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Lo(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Kn(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:o,color:l,height:c}}function Kn(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Yo(e,t={}){const{progressive:n=!1}=t,[a,r]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),v=e.length;return i.useEffect(()=>{if(e.length===0){r([]),o(!1),d(0);return}let g=!1;const f=new Map,C=(h,p,I)=>{const x=I??h.audioBuffer;if(!x&&!h.waveformData)throw new Error(`Track ${p+1}: Must provide src, audioBuffer, or waveformData`);const m=x?.duration??h.waveformData?.duration,w=No({audioBuffer:x,startTime:h.startTime??0,duration:h.duration??m,offset:h.offset??0,name:h.name||`Track ${p+1}`,fadeIn:h.fadeIn,fadeOut:h.fadeOut,waveformData:h.waveformData});if(isNaN(w.startSample)||isNaN(w.durationSamples)||isNaN(w.offsetSamples))throw console.error("Invalid clip values:",w),new Error(`Invalid clip values for track ${p+1}`);return{...Lo({name:h.name||`Track ${p+1}`,clips:[w],muted:h.muted??!1,soloed:h.soloed??!1,volume:h.volume??1,pan:h.pan??0,color:h.color}),effects:h.effects}};return(async()=>{try{o(!0),c(null),d(0);const h=vn.getContext().rawContext,p=e.map(async(x,m)=>{if(x.audioBuffer){const E=C(x,m,x.audioBuffer);return n&&!g&&(f.set(m,E),d(M=>M+1),r(Array.from({length:e.length},(M,$)=>f.get($)).filter(M=>M!==void 0))),E}if(!x.src&&x.waveformData){const E=C(x,m);return n&&!g&&(f.set(m,E),d(M=>M+1),r(Array.from({length:e.length},(M,$)=>f.get($)).filter(M=>M!==void 0))),E}if(!x.src)throw new Error(`Track ${m+1}: Must provide src, audioBuffer, or waveformData`);const w=await fetch(x.src);if(!w.ok)throw new Error(`Failed to fetch ${x.src}: ${w.statusText}`);const k=await w.arrayBuffer(),S=await h.decodeAudioData(k);if(!S||!S.sampleRate||!S.duration)throw new Error(`Invalid audio buffer for ${x.src}`);const R=C(x,m,S);return n&&!g&&(f.set(m,R),d(E=>E+1),r(Array.from({length:e.length},(E,M)=>f.get(M)).filter(E=>E!==void 0))),R}),I=await Promise.all(p);g||(n||(r(I),d(I.length)),o(!1))}catch(h){if(!g){const p=h instanceof Error?h.message:"Unknown error loading audio";c(p),o(!1),console.error("Error loading audio tracks:",h)}}})(),()=>{g=!0}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:v}}function Oo({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=i.useRef(null),s=i.useCallback(u=>{const{transform:d,active:v}=u;if(!v?.data?.current)return{...d,scaleX:1,scaleY:1};const{trackIndex:g,clipIndex:f,boundary:C}=v.data.current;if(C)return{...d,scaleX:1,scaleY:1};const y=e[g];if(!y)return{...d,scaleX:1,scaleY:1};const h=y.clips[f];if(!h)return{...d,scaleX:1,scaleY:1};const p=h.startSample/a,I=h.durationSamples/a,x=d.x*n/a;let m=p+x;const w=[...y.clips].sort(($,Z)=>$.startSample-Z.startSample),k=w.findIndex($=>$===h);m=Math.max(0,m);const S=k>0?w[k-1]:null;if(S){const $=(S.startSample+S.durationSamples)/a;m=Math.max(m,$)}const R=k<w.length-1?w[k+1]:null;if(R){const $=m+I,Z=R.startSample/a;$>Z&&(m=Z-I)}const M=(m-p)*a/n;return{...d,x:M,scaleX:1,scaleY:1}},[e,n,a]),o=i.useCallback(u=>{const{active:d}=u,{boundary:v}=d.data.current;if(!v){r.current=null;return}const{trackIndex:g,clipIndex:f}=d.data.current,y=e[g]?.clips[f];y&&(r.current={offsetSamples:y.offsetSamples,durationSamples:y.durationSamples,startSample:y.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:v}=u,{boundary:g}=d.data.current;if(!g||!r.current)return;const{trackIndex:f,clipIndex:C}=d.data.current,y=v.x*n,h=Math.floor(.1*a),p=r.current,I=e.map((x,m)=>{if(m!==f)return x;const w=[...x.clips].sort((R,E)=>R.startSample-E.startSample),k=w.findIndex(R=>R===x.clips[C]),S=x.clips.map((R,E)=>{if(E!==C)return R;const M=R.sourceDurationSamples;if(g==="left"){let $=Math.floor(y);const Z=-p.startSample;$<Z&&($=Z);const D=-p.offsetSamples;$<D&&($=D);const P=k>0?w[k-1]:null;if(P){const Q=P.startSample+P.durationSamples-p.startSample;$<Q&&($=Q)}const z=p.durationSamples-h;$>z&&($=z);const O=p.offsetSamples+$,V=p.durationSamples-$,q=p.startSample+$;return{...R,offsetSamples:O,durationSamples:V,startSample:q}}else{let $=Math.floor(p.durationSamples+y);$=Math.max(h,$),p.offsetSamples+$>M&&($=M-p.offsetSamples);const Z=k<w.length-1?w[k+1]:null;return Z&&p.startSample+$>Z.startSample&&($=Z.startSample-p.startSample,$=Math.max(h,$)),{...R,durationSamples:$}}});return{...x,clips:S}});t(I)},[e,t,n,a]),c=i.useCallback(u=>{const{active:d,delta:v}=u,{trackIndex:g,clipIndex:f,boundary:C}=d.data.current,y=v.x*n;if(C){r.current=null;return}const h=e.map((p,I)=>{if(I!==g)return p;const x=[...p.clips].sort((k,S)=>k.startSample-S.startSample),m=x.findIndex(k=>k===p.clips[f]),w=p.clips.map((k,S)=>{if(S!==f)return k;let R=Math.floor(k.startSample+y);R=Math.max(0,R);const E=m>0?x[m-1]:null;if(E){const $=E.startSample+E.durationSamples;R=Math.max(R,$)}const M=m<x.length-1?x[m+1]:null;return M&&R+k.durationSamples>M.startSample&&(R=M.startSample-k.durationSamples),{...k,startSample:R}});return{...p,clips:w}});t(h)},[e,t,n,a]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Bt=.01;function Un({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:v}=d,g=v.data.current;if(!g||g.annotationIndex===void 0){o.current=null;return}const f=e[g.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:g.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:v,delta:g}=d;if(!o.current)return;const f=v.data.current;if(!f)return;const{edge:C,annotationIndex:y}=f,h=o.current,p=g.x*n/a,I=C==="start"?h.start+p:h.end+p,x=Ko({annotationIndex:y,newTime:I,isDraggingStart:C==="start",annotations:e,duration:r,linkEndpoints:s});t(x)},[e,t,n,a,r,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Ko({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const o=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<Bt?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<Bt){const v=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,v)};let g=e+1;for(;g<o.length-1;){const f=o[g],C=o[g+1];if(Math.abs(C.start-f.end)<Bt){const y=f.end-a[g].end;o[g+1]={...C,start:Math.min(C.end-.1,C.start+y)},g++}else break}}else c>=d.start&&(o[e]={...o[e],end:d.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const d=o[e+1];o[e+1]={...d,start:c};let v=e+1;for(;v<o.length-1;){const g=o[v],f=o[v+1];if(g.end>f.start)o[v+1]={...f,start:g.end},v++;else break}}}return o}function Uo(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Ee.useSensor(Ee.MouseSensor,{activationConstraint:{distance:r}}),o=Ee.useSensor(Ee.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Ee.useSensor(Ee.PointerSensor,{activationConstraint:{distance:r}});return Ee.useSensors(...t?[s,o]:[l])}const Jo=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Ae(),{selectedTrackId:s}=Se(),o=i.useCallback((c,u,d)=>{const{sampleRate:v,samplesPerPixel:g}=e,f=t[c];if(!f)return!1;const C=f.clips[u];if(!C)return!1;const y=C.startSample/v,h=(C.startSample+C.durationSamples)/v;if(d<=y||d>=h)return console.warn("Split time is outside clip bounds"),!1;const p=Math.round(d*v),I=Math.floor(p/g),x=C.startSample+C.durationSamples,m=I*g,w=C.startSample,k=m-w,S=m,R=x-S,E=m-C.startSample,M=_t({audioBuffer:C.audioBuffer,startSample:w,durationSamples:k,offsetSamples:C.offsetSamples,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (1)`:void 0,color:C.color,fadeIn:C.fadeIn,waveformData:C.waveformData}),$=_t({audioBuffer:C.audioBuffer,startSample:S,durationSamples:R,offsetSamples:C.offsetSamples+E,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (2)`:void 0,color:C.color,waveformData:C.waveformData,fadeOut:C.fadeOut}),Z=[...f.clips];Z.splice(u,1,M,$);const D=[...t];return D[c]={...f,clips:Z},n(D),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(v=>v.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],d=r.current??0;for(let v=0;v<u.clips.length;v++){const g=u.clips[v],f=g.startSample/a,C=(g.startSample+g.durationSamples)/a;if(d>f&&d<C)return console.log(`Splitting clip on track "${u.name}" at ${d}s`),o(c,v,d)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,o,a]),splitClipAt:o}},Ct=e=>{const{shortcuts:t,enabled:n=!0}=e,a=i.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||r.shiftKey===l.shiftKey,v=l.metaKey===void 0||r.metaKey===l.metaKey,g=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&d&&v&&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])},qo=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("+")},Qo=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Ae(),{setCurrentTime:s,play:o,pause:l,stop:c}=ue(),{playoutRef:u}=we(),d=i.useCallback(()=>{r?l():o()},[r,o,l]),v=i.useCallback(()=>{c()},[c]),g=i.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[r,u,s,o]),C=a??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:v,description:"Stop",preventDefault:!0},{key:"0",action:g,description:"Rewind to start",preventDefault:!0}],...n];return Ct({shortcuts:C,enabled:t}),{rewindToStart:g,togglePlayPause:d,stopPlayback:v,shortcuts:C}},Tt=.01,pt=.01;function es({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:v=0,onPlay:g}){const f=i.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),C=i.useCallback(E=>{if(!c?.current||!u||!d)return;const M=e.find(T=>T.id===E);if(!M)return;const $=c.current,Z=$.clientWidth,D=M.start*d/u+v,P=M.end*d/u+v,z=(D+P)/2,O=$.scrollLeft,V=O,q=O+Z;if(D<V||P>q){const T=Math.max(0,z-Z/2);$.scrollTo({left:T,behavior:"smooth"})}},[e,c,u,d,v]);i.useEffect(()=>{t&&c?.current&&u&&d&&C(t)},[t,C,c,u,d]);const y=i.useCallback(E=>{if(f<0)return;const M=e[f],$=Math.max(0,Math.min(M.end-.1,M.start+E)),Z=$-M.start,D=[...e];if(D[f]={...M,start:$},s&&f>0){const P=D[f-1];Math.abs(P.end-M.start)<Tt&&(D[f-1]={...P,end:Math.max(P.start+.1,P.end+Z)})}else if(!s&&f>0){const P=D[f-1];$<P.end&&(D[f-1]={...P,end:$})}n(D)},[e,f,s,n]),h=i.useCallback(E=>{if(f<0)return;const M=e[f],$=Math.max(M.start+.1,Math.min(r,M.end+E)),Z=$-M.end,D=[...e];if(D[f]={...M,end:$},s&&f<e.length-1){const P=D[f+1];if(Math.abs(P.start-M.end)<Tt){const z=Math.min(P.end-.1,P.start+Z);D[f+1]={...P,start:z};let O=f+1;for(;O<D.length-1;){const V=D[O],q=D[O+1];if(Math.abs(q.start-e[O].end)<Tt){const T=V.end-e[O].end;D[O+1]={...q,start:Math.min(q.end-.1,q.start+T)},O++}else break}}}else if(!s&&f<e.length-1){const P=D[f+1];if($>P.start){D[f+1]={...P,start:$};let z=f+1;for(;z<D.length-1;){const O=D[z],V=D[z+1];if(O.end>V.start)D[z+1]={...V,start:O.end},z++;else break}}}n(D)},[e,f,r,s,n]),p=i.useCallback(()=>{!a||e.length===0||(f<=0?a(e[e.length-1].id):a(e[f-1].id))},[e,f,a]),I=i.useCallback(()=>{!a||e.length===0||(f<0||f>=e.length-1?a(e[0].id):a(e[f+1].id))},[e,f,a]),x=i.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),m=i.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),w=i.useCallback(()=>{a&&a(null)},[a]),k=i.useCallback(()=>{if(f<0||!g)return;const E=e[f],M=o?void 0:E.end-E.start;g(E.start,M)},[e,f,o,g]),S=i.useMemo(()=>[{key:"[",action:()=>y(-pt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>y(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:k,description:"Play selected annotation",preventDefault:!0}],[y,h,k]),R=i.useMemo(()=>[{key:"ArrowUp",action:p,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:p,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:I,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:I,description:"Select next annotation",preventDefault:!0},{key:"Home",action:x,description:"Select first annotation",preventDefault:!0},{key:"End",action:m,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:w,description:"Deselect annotation",preventDefault:!0}],[p,I,x,m,w]);return Ct({shortcuts:S,enabled:l&&f>=0}),Ct({shortcuts:R,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:y,moveEndBoundary:h,selectPrevious:p,selectNext:I,selectFirst:x,selectLast:m,clearSelection:w,scrollToAnnotation:C,playActiveAnnotation:k}}function ts(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 ns(e,t,n,a=1){const r=e.createBuffer(a,t.length,n),s=new Float32Array(t);return r.copyToChannel(s,0),r}function fn(e,t,n=16){const a=Math.ceil(e.length/t),r=n===8?new Int8Array(a*2):new Int16Array(a*2),s=2**(n-1);for(let o=0;o<a;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,d=0;for(let v=l;v<c;v++){const g=e[v];g<u&&(u=g),g>d&&(d=g)}r[o*2]=Math.floor(u*s),r[o*2+1]=Math.floor(d*s)}return r}function as(e,t,n,a,r=16){const s=2**(r-1),o=a%n;let l=0;if(o>0&&e.length>0){const d=n-o,v=Math.min(d,t.length);let g=e[e.length-2]/s,f=e[e.length-1]/s;for(let p=0;p<v;p++){const I=t[p];I<g&&(g=I),I>f&&(f=I)}const C=new(r===8?Int8Array:Int16Array)(e.length);C.set(e),C[e.length-2]=Math.floor(g*s),C[e.length-1]=Math.floor(f*s),l=v;const y=fn(t.slice(l),n,r),h=new(r===8?Int8Array:Int16Array)(C.length+y.length);return h.set(C),h.set(y,C.length),h}const c=fn(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 rs(e,t={}){const{channelCount:n=1,samplesPerPixel:a=1024}=t,[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[d,v]=i.useState(new Int16Array(0)),[g,f]=i.useState(null),[C,y]=i.useState(null),[h,p]=i.useState(0),[I,x]=i.useState(0),m=16,w=i.useRef(!1),k=i.useRef(null),S=i.useRef(null),R=i.useRef([]),E=i.useRef(0),M=i.useRef(null),$=i.useRef(0),Z=i.useRef(!1),D=i.useRef(!1),P=i.useCallback(async()=>{if(!w.current)try{const T=W.getContext(),Q=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Et&&Et.tagName.toUpperCase()==="SCRIPT"&&Et.src||new URL("index.js",document.baseURI).href).href;await T.addAudioWorkletModule(Q),w.current=!0}catch(T){throw console.error("Failed to load AudioWorklet module:",T),new Error("Failed to load recording processor")}},[]),z=i.useCallback(async()=>{if(!e){y(new Error("No microphone stream available"));return}try{y(null);const T=W.getContext();T.state==="suspended"&&await T.resume(),await P();const Q=T.createMediaStreamSource(e);S.current=Q;const J=T.createAudioWorkletNode("recording-processor");k.current=J,Q.connect(J),J.port.onmessage=ee=>{const{samples:te}=ee.data;R.current.push(te),E.current+=te.length,v(me=>as(me,te,a,E.current-te.length,m))},J.port.postMessage({command:"start",sampleRate:T.sampleRate,channelCount:n}),R.current=[],E.current=0,v(new Int16Array(0)),f(null),p(0),x(0),Z.current=!0,D.current=!1,s(!0),l(!1),$.current=performance.now();const oe=()=>{if(Z.current&&!D.current){const ee=(performance.now()-$.current)/1e3;u(ee),M.current=requestAnimationFrame(oe)}};oe()}catch(T){console.error("Failed to start recording:",T),y(T instanceof Error?T:new Error("Failed to start recording"))}},[e,n,a,P,r,o]),O=i.useCallback(async()=>{if(!r)return null;try{if(k.current){if(k.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(k.current)}catch{}k.current.disconnect()}M.current!==null&&(cancelAnimationFrame(M.current),M.current=null);const T=ts(R.current),J=W.getContext().rawContext,oe=ns(J,T,J.sampleRate,n);return f(oe),u(oe.duration),Z.current=!1,D.current=!1,s(!1),l(!1),p(0),oe}catch(T){return console.error("Failed to stop recording:",T),y(T instanceof Error?T:new Error("Failed to stop recording")),null}},[r,n]),V=i.useCallback(()=>{r&&!o&&(M.current!==null&&(cancelAnimationFrame(M.current),M.current=null),D.current=!0,l(!0))},[r,o]),q=i.useCallback(()=>{if(r&&o){D.current=!1,l(!1),$.current=performance.now()-c*1e3;const T=()=>{if(Z.current&&!D.current){const Q=(performance.now()-$.current)/1e3;u(Q),M.current=requestAnimationFrame(T)}};T()}},[r,o,c]);return i.useEffect(()=>()=>{if(k.current){if(k.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(k.current)}catch{}k.current.disconnect()}M.current!==null&&cancelAnimationFrame(M.current)},[]),{isRecording:r,isPaused:o,duration:c,peaks:d,audioBuffer:g,level:h,peakLevel:I,startRecording:z,stopRecording:O,pauseRecording:V,resumeRecording:q,error:C}}function os(){const[e,t]=i.useState(null),[n,a]=i.useState([]),[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),d=i.useCallback(async()=>{try{const C=(await navigator.mediaDevices.enumerateDevices()).filter(y=>y.kind==="audioinput").map(y=>({deviceId:y.deviceId,label:y.label||`Microphone ${y.deviceId.slice(0,8)}`,groupId:y.groupId}));a(C)}catch(f){console.error("Failed to enumerate devices:",f),u(f instanceof Error?f:new Error("Failed to enumerate devices"))}},[]),v=i.useCallback(async(f,C)=>{l(!0),u(null);try{e&&e.getTracks().forEach(I=>I.stop());const h={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...C,...f&&{deviceId:{exact:f}}},video:!1},p=await navigator.mediaDevices.getUserMedia(h);t(p),s(!0),await d()}catch(y){console.error("Failed to access microphone:",y),u(y instanceof Error?y:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,d]),g=i.useCallback(()=>{e&&(e.getTracks().forEach(f=>f.stop()),t(null),s(!1))},[e]);return i.useEffect(()=>(d(),()=>{e&&e.getTracks().forEach(f=>f.stop())}),[]),{stream:e,devices:n,hasPermission:r,isLoading:o,requestAccess:v,stopStream:g,error:c}}function ss(e,t={}){const{updateRate:n=60,smoothingTimeConstant:a=.8}=t,[r,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),d=i.useRef(null),v=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let g=!0;return(async()=>{if(!g)return;const C=W.getContext();if(C.state==="suspended"&&await C.resume(),!g)return;const y=new W.Meter({smoothing:a,context:C});c.current=y;const h=C.createMediaStreamSource(e);u.current=h,W.connect(h,y);const p=1e3/n;let I=0;const x=m=>{if(!(!g||!c.current)){if(m-I>=p){I=m;const w=c.current.getValue(),k=typeof w=="number"?w:w[0],S=Math.max(0,Math.min(1,(k+100)/100));s(S),l(R=>Math.max(R,S))}d.current=requestAnimationFrame(x)}};d.current=requestAnimationFrame(x)})(),()=>{if(g=!1,d.current&&(cancelAnimationFrame(d.current),d.current=null),u.current){try{u.current.disconnect()}catch{}u.current=null}c.current&&(c.current.dispose(),c.current=null)}},[e,a,n]),{level:r,peakLevel:o,resetPeak:v}}A.button`
|
|
1066
|
+
`,Ho=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:a,children:r="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(v=>wo(v)),l=JSON.stringify(o,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),d=document.createElement("a");d.href=u,d.download=t,document.body.appendChild(d),d.click(),document.body.removeChild(d),URL.revokeObjectURL(u)};return b.jsx(zo,{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 Ln(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:r=>tt(r,e),parseTime:r=>Dn(r,e)}}const Xo=[256,512,1024,2048,4096,8192];function Yn({initialSamplesPerPixel:e,zoomLevels:t=Xo}){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 On({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 Go=(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 Zt(e){const{audioBuffer:t,startSample:n,offsetSamples:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,v=t?.length??e.sourceDurationSamples??(u&&d?Math.ceil(u.duration*d):void 0);if(d===void 0)throw new Error("createClip: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");if(v===void 0)throw new Error("createClip: sourceDurationSamples is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.durationSamples??v;return{id:Kn(),audioBuffer:t,startSample:n,durationSamples:g,offsetSamples:a,sampleRate:d,sourceDurationSamples:v,gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function No(e){const{audioBuffer:t,startTime:n,offset:a=0,gain:r=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const v=t?.duration??e.sourceDuration??u?.duration;if(v===void 0)throw new Error("createClipFromSeconds: sourceDuration is required when audioBuffer is not provided (can use waveformData.duration)");t&&u&&t.sampleRate!==u.sample_rate&&console.warn(`Sample rate mismatch: audioBuffer (${t.sampleRate}) vs waveformData (${u.sample_rate}). Using audioBuffer sample rate. Waveform visualization may be slightly off.`);const g=e.duration??v;return Zt({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(g*d),offsetSamples:Math.round(a*d),sampleRate:d,sourceDurationSamples:Math.ceil(v*d),gain:r,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function Lo(e){const{name:t,clips:n=[],muted:a=!1,soloed:r=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:Kn(),name:t,clips:n,muted:a,soloed:r,volume:s,pan:o,color:l,height:c}}function Kn(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function Yo(e,t={}){const{progressive:n=!1}=t,[a,r]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),v=e.length;return i.useEffect(()=>{if(e.length===0){r([]),o(!1),d(0);return}let g=!1;const f=new Map,C=(h,p,I)=>{const x=I??h.audioBuffer;if(!x&&!h.waveformData)throw new Error(`Track ${p+1}: Must provide src, audioBuffer, or waveformData`);const m=x?.duration??h.waveformData?.duration,w=No({audioBuffer:x,startTime:h.startTime??0,duration:h.duration??m,offset:h.offset??0,name:h.name||`Track ${p+1}`,fadeIn:h.fadeIn,fadeOut:h.fadeOut,waveformData:h.waveformData});if(isNaN(w.startSample)||isNaN(w.durationSamples)||isNaN(w.offsetSamples))throw console.error("Invalid clip values:",w),new Error(`Invalid clip values for track ${p+1}`);return{...Lo({name:h.name||`Track ${p+1}`,clips:[w],muted:h.muted??!1,soloed:h.soloed??!1,volume:h.volume??1,pan:h.pan??0,color:h.color}),effects:h.effects}};return(async()=>{try{o(!0),c(null),d(0);const h=vn.getContext().rawContext,p=e.map(async(x,m)=>{if(x.audioBuffer){const E=C(x,m,x.audioBuffer);return n&&!g&&(f.set(m,E),d(R=>R+1),r(Array.from({length:e.length},(R,M)=>f.get(M)).filter(R=>R!==void 0))),E}if(!x.src&&x.waveformData){const E=C(x,m);return n&&!g&&(f.set(m,E),d(R=>R+1),r(Array.from({length:e.length},(R,M)=>f.get(M)).filter(R=>R!==void 0))),E}if(!x.src)throw new Error(`Track ${m+1}: Must provide src, audioBuffer, or waveformData`);const w=await fetch(x.src);if(!w.ok)throw new Error(`Failed to fetch ${x.src}: ${w.statusText}`);const k=await w.arrayBuffer(),S=await h.decodeAudioData(k);if(!S||!S.sampleRate||!S.duration)throw new Error(`Invalid audio buffer for ${x.src}`);const $=C(x,m,S);return n&&!g&&(f.set(m,$),d(E=>E+1),r(Array.from({length:e.length},(E,R)=>f.get(R)).filter(E=>E!==void 0))),$}),I=await Promise.all(p);g||(n||(r(I),d(I.length)),o(!1))}catch(h){if(!g){const p=h instanceof Error?h.message:"Unknown error loading audio";c(p),o(!1),console.error("Error loading audio tracks:",h)}}})(),()=>{g=!0}},[e,n]),{tracks:a,loading:s,error:l,loadedCount:u,totalCount:v}}function Oo({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:a}){const r=i.useRef(null),s=i.useCallback(u=>{const{transform:d,active:v}=u;if(!v?.data?.current)return{...d,scaleX:1,scaleY:1};const{trackIndex:g,clipIndex:f,boundary:C}=v.data.current;if(C)return{...d,scaleX:1,scaleY:1};const y=e[g];if(!y)return{...d,scaleX:1,scaleY:1};const h=y.clips[f];if(!h)return{...d,scaleX:1,scaleY:1};const p=h.startSample/a,I=h.durationSamples/a,x=d.x*n/a;let m=p+x;const w=[...y.clips].sort((M,Z)=>M.startSample-Z.startSample),k=w.findIndex(M=>M===h);m=Math.max(0,m);const S=k>0?w[k-1]:null;if(S){const M=(S.startSample+S.durationSamples)/a;m=Math.max(m,M)}const $=k<w.length-1?w[k+1]:null;if($){const M=m+I,Z=$.startSample/a;M>Z&&(m=Z-I)}const R=(m-p)*a/n;return{...d,x:R,scaleX:1,scaleY:1}},[e,n,a]),o=i.useCallback(u=>{const{active:d}=u,{boundary:v}=d.data.current;if(!v){r.current=null;return}const{trackIndex:g,clipIndex:f}=d.data.current,y=e[g]?.clips[f];y&&(r.current={offsetSamples:y.offsetSamples,durationSamples:y.durationSamples,startSample:y.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:v}=u,{boundary:g}=d.data.current;if(!g||!r.current)return;const{trackIndex:f,clipIndex:C}=d.data.current,y=v.x*n,h=Math.floor(.1*a),p=r.current,I=e.map((x,m)=>{if(m!==f)return x;const w=[...x.clips].sort(($,E)=>$.startSample-E.startSample),k=w.findIndex($=>$===x.clips[C]),S=x.clips.map(($,E)=>{if(E!==C)return $;const R=$.sourceDurationSamples;if(g==="left"){let M=Math.floor(y);const Z=-p.startSample;M<Z&&(M=Z);const D=-p.offsetSamples;M<D&&(M=D);const P=k>0?w[k-1]:null;if(P){const Q=P.startSample+P.durationSamples-p.startSample;M<Q&&(M=Q)}const H=p.durationSamples-h;M>H&&(M=H);const O=p.offsetSamples+M,V=p.durationSamples-M,q=p.startSample+M;return{...$,offsetSamples:O,durationSamples:V,startSample:q}}else{let M=Math.floor(p.durationSamples+y);M=Math.max(h,M),p.offsetSamples+M>R&&(M=R-p.offsetSamples);const Z=k<w.length-1?w[k+1]:null;return Z&&p.startSample+M>Z.startSample&&(M=Z.startSample-p.startSample,M=Math.max(h,M)),{...$,durationSamples:M}}});return{...x,clips:S}});t(I)},[e,t,n,a]),c=i.useCallback(u=>{const{active:d,delta:v}=u,{trackIndex:g,clipIndex:f,boundary:C}=d.data.current,y=v.x*n;if(C){r.current=null;return}const h=e.map((p,I)=>{if(I!==g)return p;const x=[...p.clips].sort((k,S)=>k.startSample-S.startSample),m=x.findIndex(k=>k===p.clips[f]),w=p.clips.map((k,S)=>{if(S!==f)return k;let $=Math.floor(k.startSample+y);$=Math.max(0,$);const E=m>0?x[m-1]:null;if(E){const M=E.startSample+E.durationSamples;$=Math.max($,M)}const R=m<x.length-1?x[m+1]:null;return R&&$+k.durationSamples>R.startSample&&($=R.startSample-k.durationSamples),{...k,startSample:$}});return{...p,clips:w}});t(h)},[e,t,n,a]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const Tt=.01;function Un({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:a,duration:r,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:v}=d,g=v.data.current;if(!g||g.annotationIndex===void 0){o.current=null;return}const f=e[g.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:g.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:v,delta:g}=d;if(!o.current)return;const f=v.data.current;if(!f)return;const{edge:C,annotationIndex:y}=f,h=o.current,p=g.x*n/a,I=C==="start"?h.start+p:h.end+p,x=Ko({annotationIndex:y,newTime:I,isDraggingStart:C==="start",annotations:e,duration:r,linkEndpoints:s});t(x)},[e,t,n,a,r,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Ko({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:a,duration:r,linkEndpoints:s}){const o=[...a],l=a[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<Tt?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,r)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<Tt){const v=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,v)};let g=e+1;for(;g<o.length-1;){const f=o[g],C=o[g+1];if(Math.abs(C.start-f.end)<Tt){const y=f.end-a[g].end;o[g+1]={...C,start:Math.min(C.end-.1,C.start+y)},g++}else break}}else c>=d.start&&(o[e]={...o[e],end:d.start})}else if(!s&&e<o.length-1&&c>o[e+1].start){const d=o[e+1];o[e+1]={...d,start:c};let v=e+1;for(;v<o.length-1;){const g=o[v],f=o[v+1];if(g.end>f.start)o[v+1]={...f,start:g.end},v++;else break}}}return o}function Uo(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:a=5,mouseDistance:r=1}=e,s=Ee.useSensor(Ee.MouseSensor,{activationConstraint:{distance:r}}),o=Ee.useSensor(Ee.TouchSensor,{activationConstraint:t?{delay:n,tolerance:a}:{distance:r}}),l=Ee.useSensor(Ee.PointerSensor,{activationConstraint:{distance:r}});return Ee.useSensors(...t?[s,o]:[l])}const Jo=e=>{const{tracks:t,onTracksChange:n,sampleRate:a}=e,{currentTimeRef:r}=Ae(),{selectedTrackId:s}=Se(),o=i.useCallback((c,u,d)=>{const{sampleRate:v,samplesPerPixel:g}=e,f=t[c];if(!f)return!1;const C=f.clips[u];if(!C)return!1;const y=C.startSample/v,h=(C.startSample+C.durationSamples)/v;if(d<=y||d>=h)return console.warn("Split time is outside clip bounds"),!1;const p=Math.round(d*v),I=Math.floor(p/g),x=C.startSample+C.durationSamples,m=I*g,w=C.startSample,k=m-w,S=m,$=x-S,E=m-C.startSample,R=Zt({audioBuffer:C.audioBuffer,startSample:w,durationSamples:k,offsetSamples:C.offsetSamples,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (1)`:void 0,color:C.color,fadeIn:C.fadeIn,waveformData:C.waveformData}),M=Zt({audioBuffer:C.audioBuffer,startSample:S,durationSamples:$,offsetSamples:C.offsetSamples+E,sampleRate:C.sampleRate,sourceDurationSamples:C.sourceDurationSamples,gain:C.gain,name:C.name?`${C.name} (2)`:void 0,color:C.color,waveformData:C.waveformData,fadeOut:C.fadeOut}),Z=[...f.clips];Z.splice(u,1,R,M);const D=[...t];return D[c]={...f,clips:Z},n(D),!0},[t,n,e]);return{splitClipAtPlayhead:i.useCallback(()=>{if(!s)return console.log("No track selected - click a clip to select a track first"),!1;const c=t.findIndex(v=>v.id===s);if(c===-1)return console.warn("Selected track not found"),!1;const u=t[c],d=r.current??0;for(let v=0;v<u.clips.length;v++){const g=u.clips[v],f=g.startSample/a,C=(g.startSample+g.durationSamples)/a;if(d>f&&d<C)return console.log(`Splitting clip on track "${u.name}" at ${d}s`),o(c,v,d)}return console.log(`No clip found at playhead position on track "${u.name}"`),!1},[t,r,s,o,a]),splitClipAt:o}},Ct=e=>{const{shortcuts:t,enabled:n=!0}=e,a=i.useCallback(r=>{if(!n)return;const s=r.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=r.key.toLowerCase()===l.key.toLowerCase()||r.key===l.key,u=l.ctrlKey===void 0||r.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||r.shiftKey===l.shiftKey,v=l.metaKey===void 0||r.metaKey===l.metaKey,g=l.altKey===void 0||r.altKey===l.altKey;return c&&u&&d&&v&&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])},qo=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("+")},Qo=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:a}=e,{isPlaying:r}=Ae(),{setCurrentTime:s,play:o,pause:l,stop:c}=ue(),{playoutRef:u}=we(),d=i.useCallback(()=>{r?l():o()},[r,o,l]),v=i.useCallback(()=>{c()},[c]),g=i.useCallback(()=>{r&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[r,u,s,o]),C=a??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:v,description:"Stop",preventDefault:!0},{key:"0",action:g,description:"Rewind to start",preventDefault:!0}],...n];return Ct({shortcuts:C,enabled:t}),{rewindToStart:g,togglePlayPause:d,stopPlayback:v,shortcuts:C}},Wt=.01,pt=.01;function es({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:a,duration:r,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:v=0,onPlay:g}){const f=i.useMemo(()=>t?e.findIndex(E=>E.id===t):-1,[e,t]),C=i.useCallback(E=>{if(!c?.current||!u||!d)return;const R=e.find(T=>T.id===E);if(!R)return;const M=c.current,Z=M.clientWidth,D=R.start*d/u+v,P=R.end*d/u+v,H=(D+P)/2,O=M.scrollLeft,V=O,q=O+Z;if(D<V||P>q){const T=Math.max(0,H-Z/2);M.scrollTo({left:T,behavior:"smooth"})}},[e,c,u,d,v]);i.useEffect(()=>{t&&c?.current&&u&&d&&C(t)},[t,C,c,u,d]);const y=i.useCallback(E=>{if(f<0)return;const R=e[f],M=Math.max(0,Math.min(R.end-.1,R.start+E)),Z=M-R.start,D=[...e];if(D[f]={...R,start:M},s&&f>0){const P=D[f-1];Math.abs(P.end-R.start)<Wt&&(D[f-1]={...P,end:Math.max(P.start+.1,P.end+Z)})}else if(!s&&f>0){const P=D[f-1];M<P.end&&(D[f-1]={...P,end:M})}n(D)},[e,f,s,n]),h=i.useCallback(E=>{if(f<0)return;const R=e[f],M=Math.max(R.start+.1,Math.min(r,R.end+E)),Z=M-R.end,D=[...e];if(D[f]={...R,end:M},s&&f<e.length-1){const P=D[f+1];if(Math.abs(P.start-R.end)<Wt){const H=Math.min(P.end-.1,P.start+Z);D[f+1]={...P,start:H};let O=f+1;for(;O<D.length-1;){const V=D[O],q=D[O+1];if(Math.abs(q.start-e[O].end)<Wt){const T=V.end-e[O].end;D[O+1]={...q,start:Math.min(q.end-.1,q.start+T)},O++}else break}}}else if(!s&&f<e.length-1){const P=D[f+1];if(M>P.start){D[f+1]={...P,start:M};let H=f+1;for(;H<D.length-1;){const O=D[H],V=D[H+1];if(O.end>V.start)D[H+1]={...V,start:O.end},H++;else break}}}n(D)},[e,f,r,s,n]),p=i.useCallback(()=>{!a||e.length===0||(f<=0?a(e[e.length-1].id):a(e[f-1].id))},[e,f,a]),I=i.useCallback(()=>{!a||e.length===0||(f<0||f>=e.length-1?a(e[0].id):a(e[f+1].id))},[e,f,a]),x=i.useCallback(()=>{!a||e.length===0||a(e[0].id)},[e,a]),m=i.useCallback(()=>{!a||e.length===0||a(e[e.length-1].id)},[e,a]),w=i.useCallback(()=>{a&&a(null)},[a]),k=i.useCallback(()=>{if(f<0||!g)return;const E=e[f],R=o?void 0:E.end-E.start;g(E.start,R)},[e,f,o,g]),S=i.useMemo(()=>[{key:"[",action:()=>y(-pt),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>y(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:k,description:"Play selected annotation",preventDefault:!0}],[y,h,k]),$=i.useMemo(()=>[{key:"ArrowUp",action:p,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:p,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:I,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:I,description:"Select next annotation",preventDefault:!0},{key:"Home",action:x,description:"Select first annotation",preventDefault:!0},{key:"End",action:m,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:w,description:"Deselect annotation",preventDefault:!0}],[p,I,x,m,w]);return Ct({shortcuts:S,enabled:l&&f>=0}),Ct({shortcuts:$,enabled:l&&e.length>0&&!!a}),{moveStartBoundary:y,moveEndBoundary:h,selectPrevious:p,selectNext:I,selectFirst:x,selectLast:m,clearSelection:w,scrollToAnnotation:C,playActiveAnnotation:k}}function ts(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 ns(e,t,n,a=1){const r=e.createBuffer(a,t.length,n),s=new Float32Array(t);return r.copyToChannel(s,0),r}function fn(e,t,n=16){const a=Math.ceil(e.length/t),r=n===8?new Int8Array(a*2):new Int16Array(a*2),s=2**(n-1);for(let o=0;o<a;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,d=0;for(let v=l;v<c;v++){const g=e[v];g<u&&(u=g),g>d&&(d=g)}r[o*2]=Math.floor(u*s),r[o*2+1]=Math.floor(d*s)}return r}function as(e,t,n,a,r=16){const s=2**(r-1),o=a%n;let l=0;if(o>0&&e.length>0){const d=n-o,v=Math.min(d,t.length);let g=e[e.length-2]/s,f=e[e.length-1]/s;for(let p=0;p<v;p++){const I=t[p];I<g&&(g=I),I>f&&(f=I)}const C=new(r===8?Int8Array:Int16Array)(e.length);C.set(e),C[e.length-2]=Math.floor(g*s),C[e.length-1]=Math.floor(f*s),l=v;const y=fn(t.slice(l),n,r),h=new(r===8?Int8Array:Int16Array)(C.length+y.length);return h.set(C),h.set(y,C.length),h}const c=fn(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 rs(e,t={}){const{channelCount:n=1,samplesPerPixel:a=1024}=t,[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[d,v]=i.useState(new Int16Array(0)),[g,f]=i.useState(null),[C,y]=i.useState(null),[h,p]=i.useState(0),[I,x]=i.useState(0),m=16,w=i.useRef(!1),k=i.useRef(null),S=i.useRef(null),$=i.useRef([]),E=i.useRef(0),R=i.useRef(null),M=i.useRef(0),Z=i.useRef(!1),D=i.useRef(!1),P=i.useCallback(async()=>{if(!w.current)try{const T=W.getContext(),Q=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Dt&&Dt.tagName.toUpperCase()==="SCRIPT"&&Dt.src||new URL("index.js",document.baseURI).href).href;await T.addAudioWorkletModule(Q),w.current=!0}catch(T){throw console.error("Failed to load AudioWorklet module:",T),new Error("Failed to load recording processor")}},[]),H=i.useCallback(async()=>{if(!e){y(new Error("No microphone stream available"));return}try{y(null);const T=W.getContext();T.state==="suspended"&&await T.resume(),await P();const Q=T.createMediaStreamSource(e);S.current=Q;const J=T.createAudioWorkletNode("recording-processor");k.current=J,Q.connect(J),J.port.onmessage=ee=>{const{samples:te}=ee.data;$.current.push(te),E.current+=te.length,v(me=>as(me,te,a,E.current-te.length,m))},J.port.postMessage({command:"start",sampleRate:T.sampleRate,channelCount:n}),$.current=[],E.current=0,v(new Int16Array(0)),f(null),p(0),x(0),Z.current=!0,D.current=!1,s(!0),l(!1),M.current=performance.now();const oe=()=>{if(Z.current&&!D.current){const ee=(performance.now()-M.current)/1e3;u(ee),R.current=requestAnimationFrame(oe)}};oe()}catch(T){console.error("Failed to start recording:",T),y(T instanceof Error?T:new Error("Failed to start recording"))}},[e,n,a,P,r,o]),O=i.useCallback(async()=>{if(!r)return null;try{if(k.current){if(k.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(k.current)}catch{}k.current.disconnect()}R.current!==null&&(cancelAnimationFrame(R.current),R.current=null);const T=ts($.current),J=W.getContext().rawContext,oe=ns(J,T,J.sampleRate,n);return f(oe),u(oe.duration),Z.current=!1,D.current=!1,s(!1),l(!1),p(0),oe}catch(T){return console.error("Failed to stop recording:",T),y(T instanceof Error?T:new Error("Failed to stop recording")),null}},[r,n]),V=i.useCallback(()=>{r&&!o&&(R.current!==null&&(cancelAnimationFrame(R.current),R.current=null),D.current=!0,l(!0))},[r,o]),q=i.useCallback(()=>{if(r&&o){D.current=!1,l(!1),M.current=performance.now()-c*1e3;const T=()=>{if(Z.current&&!D.current){const Q=(performance.now()-M.current)/1e3;u(Q),R.current=requestAnimationFrame(T)}};T()}},[r,o,c]);return i.useEffect(()=>()=>{if(k.current){if(k.current.port.postMessage({command:"stop"}),S.current)try{S.current.disconnect(k.current)}catch{}k.current.disconnect()}R.current!==null&&cancelAnimationFrame(R.current)},[]),{isRecording:r,isPaused:o,duration:c,peaks:d,audioBuffer:g,level:h,peakLevel:I,startRecording:H,stopRecording:O,pauseRecording:V,resumeRecording:q,error:C}}function os(){const[e,t]=i.useState(null),[n,a]=i.useState([]),[r,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),d=i.useCallback(async()=>{try{const C=(await navigator.mediaDevices.enumerateDevices()).filter(y=>y.kind==="audioinput").map(y=>({deviceId:y.deviceId,label:y.label||`Microphone ${y.deviceId.slice(0,8)}`,groupId:y.groupId}));a(C)}catch(f){console.error("Failed to enumerate devices:",f),u(f instanceof Error?f:new Error("Failed to enumerate devices"))}},[]),v=i.useCallback(async(f,C)=>{l(!0),u(null);try{e&&e.getTracks().forEach(I=>I.stop());const h={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...C,...f&&{deviceId:{exact:f}}},video:!1},p=await navigator.mediaDevices.getUserMedia(h);t(p),s(!0),await d()}catch(y){console.error("Failed to access microphone:",y),u(y instanceof Error?y:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,d]),g=i.useCallback(()=>{e&&(e.getTracks().forEach(f=>f.stop()),t(null),s(!1))},[e]);return i.useEffect(()=>(d(),()=>{e&&e.getTracks().forEach(f=>f.stop())}),[]),{stream:e,devices:n,hasPermission:r,isLoading:o,requestAccess:v,stopStream:g,error:c}}function ss(e,t={}){const{updateRate:n=60,smoothingTimeConstant:a=.8}=t,[r,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),d=i.useRef(null),v=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let g=!0;return(async()=>{if(!g)return;const C=W.getContext();if(C.state==="suspended"&&await C.resume(),!g)return;const y=new W.Meter({smoothing:a,context:C});c.current=y;const h=C.createMediaStreamSource(e);u.current=h,W.connect(h,y);const p=1e3/n;let I=0;const x=m=>{if(!(!g||!c.current)){if(m-I>=p){I=m;const w=c.current.getValue(),k=typeof w=="number"?w:w[0],S=Math.max(0,Math.min(1,(k+100)/100));s(S),l($=>Math.max($,S))}d.current=requestAnimationFrame(x)}};d.current=requestAnimationFrame(x)})(),()=>{if(g=!1,d.current&&(cancelAnimationFrame(d.current),d.current=null),u.current){try{u.current.disconnect()}catch{}u.current=null}c.current&&(c.current.dispose(),c.current=null)}},[e,a,n]),{level:r,peakLevel:o,resetPeak:v}}A.button`
|
|
1067
1067
|
padding: 0.5rem 1rem;
|
|
1068
1068
|
font-size: 0.875rem;
|
|
1069
1069
|
font-weight: 500;
|
|
@@ -1111,7 +1111,7 @@
|
|
|
1111
1111
|
opacity: 0.3;
|
|
1112
1112
|
}
|
|
1113
1113
|
}
|
|
1114
|
-
`;A(
|
|
1114
|
+
`;A(jt)`
|
|
1115
1115
|
min-width: 200px;
|
|
1116
1116
|
`;A(kn)`
|
|
1117
1117
|
display: flex;
|
|
@@ -1190,7 +1190,7 @@
|
|
|
1190
1190
|
width: 1px;
|
|
1191
1191
|
height: ${e=>e.$height}px;
|
|
1192
1192
|
background: rgba(255, 255, 255, 0.2);
|
|
1193
|
-
`,fs=({level:e,peakLevel:t,width:n=200,height:a=20,className:r})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return b.jsxs(is,{$width:n,$height:a,className:r,children:[b.jsx(cs,{$level:s,$height:a}),t!==void 0&&o>0&&b.jsx(us,{$peakLevel:o,$height:a}),b.jsxs(ds,{$height:a,children:[b.jsx(mn,{$position:60,$height:a}),b.jsx(mn,{$position:85,$height:a})]})]})};i.memo(fs);function ms(e,t,n,a={}){const{currentTime:r=0,audioConstraints:s,...o}=a,[l,c]=i.useState(!1),[u,d]=i.useState(null),{stream:v,devices:g,hasPermission:f,requestAccess:C,error:y}=os(),{level:h,peakLevel:p}=ss(v),{isRecording:I,isPaused:x,duration:m,peaks:w,startRecording:k,stopRecording:S,pauseRecording:R,resumeRecording:E,error:M}=rs(v,o),$=i.useCallback(async()=>{n&&(l||(await Dt(),c(!0)),await k())},[n,l,k]),Z=i.useCallback(async()=>{const z=await S();if(z&&n){const O=e.findIndex(ee=>ee.id===n);if(O===-1)return;const V=e[O],q=Math.floor(r*z.sampleRate);let T=0;if(V.clips.length>0){const ee=V.clips.map(te=>te.startSample+te.durationSamples);T=Math.max(...ee)}const Q=Math.max(q,T),J={id:`clip-${Date.now()}`,audioBuffer:z,startSample:Q,durationSamples:z.length,offsetSamples:0,sampleRate:z.sampleRate,sourceDurationSamples:z.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},oe=e.map((ee,te)=>te===O?{...ee,clips:[...ee.clips,J]}:ee);t(oe)}},[n,e,t,r,S]);i.useEffect(()=>{f&&g.length>0&&u===null&&d(g[0].deviceId)},[f,g.length]);const D=i.useCallback(async()=>{await C(void 0,s),await Dt(),c(!0)},[C,s]),P=i.useCallback(async z=>{d(z),await C(z,s),await Dt(),c(!0)},[C,s]);return{isRecording:I,isPaused:x,duration:m,level:h,peakLevel:p,error:y||M,stream:v,devices:g,hasPermission:f,selectedDevice:u,startRecording:$,stopRecording:Z,pauseRecording:R,resumeRecording:E,requestMicAccess:D,changeDevice:P,recordingPeaks:w}}const ut=[{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}]}],Xt=e=>ut.find(t=>t.id===e),hs=e=>ut.filter(t=>t.category===e),ps=[{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"}],gs={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 bs=0;const vs=()=>`effect_${Date.now()}_${++bs}`;function it(e,t){const n=gs[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=vs();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 xs(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(h=>{const p=o.current;if(!p)return;const{masterGainNode:I,destination:x,analyserNode:m}=p;try{I.disconnect()}catch{}const w=h.map(k=>r.current.get(k.instanceId)).filter(k=>k!==void 0);if(w.length===0)I.connect(m),m.connect(x);else{let k=I;w.forEach(S=>{try{S.disconnect()}catch{}k.connect(S.effect),k=S.effect}),k.connect(m),m.connect(x)}},[]),c=i.useCallback(h=>{const p=Xt(h);if(!p){console.error(`Unknown effect: ${h}`);return}const I={};p.parameters.forEach(w=>{I[w.name]=w.default});const x=it(p,I);r.current.set(x.instanceId,x);const m={instanceId:x.instanceId,effectId:p.id,definition:p,params:I,bypassed:!1};n(w=>[...w,m])},[]),u=i.useCallback(h=>{const p=r.current.get(h);p&&(p.dispose(),r.current.delete(h)),n(I=>I.filter(x=>x.instanceId!==h))},[]),d=i.useCallback((h,p,I)=>{const x=r.current.get(h);x&&x.setParameter(p,I),n(m=>m.map(w=>w.instanceId===h?{...w,params:{...w.params,[p]:I}}:w))},[]),v=i.useCallback(h=>{const p=a.current.find(m=>m.instanceId===h);if(!p)return;const I=!p.bypassed,x=r.current.get(h);if(x){const m=p.params.wet??1;x.setParameter("wet",I?0:m)}n(m=>m.map(w=>w.instanceId===h?{...w,bypassed:I}:w))},[]),g=i.useCallback((h,p)=>{n(I=>{const x=[...I],[m]=x.splice(h,1);return x.splice(p,0,m),x})},[]),f=i.useCallback(()=>{r.current.forEach(h=>h.dispose()),r.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const C=i.useCallback((h,p,I)=>{const x=new W.Analyser("fft",e);s.current=x,o.current={masterGainNode:h,destination:p,analyserNode:x};const w=a.current.map(k=>r.current.get(k.instanceId)).filter(k=>k!==void 0);if(w.length===0)h.connect(x),x.connect(p);else{let k=h;w.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(x),x.connect(p)}return function(){x.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{r.current.forEach(h=>h.dispose()),r.current.clear()},[]);const y=i.useCallback(()=>{const h=t.filter(p=>!p.bypassed);if(h.length!==0)return(p,I,x)=>{const m=[];for(const w of h){const k=it(w.definition,w.params);m.push(k)}if(m.length===0)p.connect(I);else{let w=p;m.forEach(k=>{w.connect(k.effect),w=k.effect}),w.connect(I)}return function(){m.forEach(k=>k.dispose())}}},[t]);return{activeEffects:t,availableEffects:ut,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:v,reorderEffects:g,clearAllEffects:f,masterEffects:C,createOfflineEffectsFunction:y,analyserRef:s}}function ws(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),a=i.useRef(new Map),r=i.useCallback((f,C)=>{const y=a.current.get(f);if(!y)return;const{graphEnd:h,masterGainNode:p}=y,I=n.current.get(f);try{h.disconnect()}catch{}const x=C.map(m=>I?.get(m.instanceId)).filter(m=>m!==void 0);if(x.length===0)h.connect(p);else{let m=h;x.forEach(w=>{try{w.disconnect()}catch{}m.connect(w.effect),m=w.effect}),m.connect(p)}},[]),s=i.useCallback((f,C)=>{const y=Xt(C);if(!y){console.error(`Unknown effect: ${C}`);return}const h={};y.parameters.forEach(x=>{h[x.name]=x.default});const p=it(y,h);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(p.instanceId,p);const I={instanceId:p.instanceId,effectId:y.id,definition:y,params:h,bypassed:!1};t(x=>{const m=new Map(x),w=m.get(f)||[];return m.set(f,[...w,I]),m})},[]),o=i.useCallback((f,C)=>{const y=n.current.get(f),h=y?.get(C);h&&(h.dispose(),y?.delete(C)),t(p=>{const I=new Map(p),x=I.get(f)||[];return I.set(f,x.filter(m=>m.instanceId!==C)),I})},[]),l=i.useCallback((f,C,y,h)=>{const I=n.current.get(f)?.get(C);I&&I.setParameter(y,h),t(x=>{const m=new Map(x),w=m.get(f)||[];return m.set(f,w.map(k=>k.instanceId===C?{...k,params:{...k.params,[y]:h}}:k)),m})},[]),c=i.useCallback((f,C)=>{const h=(d.current.get(f)||[]).find(m=>m.instanceId===C);if(!h)return;const p=!h.bypassed,x=n.current.get(f)?.get(C);if(x){const m=h.params.wet??1;x.setParameter("wet",p?0:m)}t(m=>{const w=new Map(m),k=w.get(f)||[];return w.set(f,k.map(S=>S.instanceId===C?{...S,bypassed:p}:S)),w})},[]),u=i.useCallback(f=>{const C=n.current.get(f);C&&(C.forEach(y=>y.dispose()),C.clear()),t(y=>{const h=new Map(y);return h.set(f,[]),h})},[]),d=i.useRef(e);d.current=e;const v=i.useCallback(f=>(C,y,h)=>{a.current.set(f,{graphEnd:C,masterGainNode:y});const p=d.current.get(f)||[],I=n.current.get(f),x=p.map(m=>I?.get(m.instanceId)).filter(m=>m!==void 0);if(x.length===0)C.connect(y);else{let m=C;x.forEach(w=>{m.connect(w.effect),m=w.effect}),m.connect(y)}return function(){a.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,C)=>{r(C,f)})},[e,r]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(C=>C.dispose()),f.clear()}),n.current.clear()},[]);const g=i.useCallback(f=>{const y=(e.get(f)||[]).filter(h=>!h.bypassed);if(y.length!==0)return(h,p,I)=>{const x=[];for(const m of y){const w=it(m.definition,m.params);x.push(w)}if(x.length===0)h.connect(p);else{let m=h;x.forEach(w=>{m.connect(w.effect),m=w.effect}),m.connect(p)}return function(){x.forEach(w=>w.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:v,createOfflineTrackEffectsFunction:g,availableEffects:ut}}function ys(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,o=n/8,l=a*o,c=r*l,u=s*l,d=44,v=d+u,g=new ArrayBuffer(v),f=new DataView(g);gt(f,0,"RIFF"),f.setUint32(4,v-8,!0),gt(f,8,"WAVE"),gt(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,n===32?3:1,!0),f.setUint16(22,a,!0),f.setUint32(24,r,!0),f.setUint32(28,c,!0),f.setUint16(32,l,!0),f.setUint16(34,n,!0),gt(f,36,"data"),f.setUint32(40,u,!0);const C=[];for(let h=0;h<a;h++)C.push(e.getChannelData(h));let y=d;if(n===16)for(let h=0;h<s;h++)for(let p=0;p<a;p++){const I=C[p][h],x=Math.max(-1,Math.min(1,I)),m=x<0?x*32768:x*32767;f.setInt16(y,m,!0),y+=2}else for(let h=0;h<s;h++)for(let p=0;p<a;p++)f.setFloat32(y,C[p][h],!0),y+=4;return new Blob([g],{type:"audio/wav"})}function gt(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function ks(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 Jn(){const[e,t]=i.useState(!1),[n,a]=i.useState(0),[r,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:v="master",trackIndex:g,autoDownload:f=!0,applyEffects:C=!0,effectsFunction:y,createOfflineTrackEffects:h,bitDepth:p=16,onProgress:I}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(v==="individual"&&(g===void 0||g<0||g>=l.length))throw new Error("Invalid track index for individual export");const x=l[0].clips[0]?.sampleRate||44100;let m=0;for(const $ of l)for(const Z of $.clips){const D=Z.startSample+Z.durationSamples;m=Math.max(m,D)}m+=Math.round(x*.1);const w=m/x,k=v==="individual"?[{track:l[g],state:c[g],index:g}]:l.map(($,Z)=>({track:$,state:c[Z],index:Z})),S=c.some($=>$.soloed),R=!!h;let E;if((y||R)&&C)E=await Is(k,c,S,w,x,y,h,$=>{a($),I?.($)});else{const $=new OfflineAudioContext(2,m,x);let Z=0;const D=k.reduce((P,{track:z})=>P+z.clips.length,0);for(const{track:P,state:z}of k)if(!(z.muted&&!z.soloed)&&!(S&&!z.soloed))for(const O of P.clips){await Ss($,O,z,x,C),Z++;const V=Z/D*.5;a(V),I?.(V)}a(.5),I?.(.5),E=await $.startRendering()}a(.9),I?.(.9);const M=ys(E,{bitDepth:p});if(a(1),I?.(1),f){const $=v==="individual"?`${d}_${l[g].name}`:d;ks(M,`${$}.wav`)}return{audioBuffer:E,blob:M,duration:w}}catch(x){const m=x instanceof Error?x.message:"Export failed";throw s(m),x}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function Is(e,t,n,a,r,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:v,Player:g,ToneAudioBuffer:f}=await import("tone");l(.1);let C;try{C=await c(async({transport:y,destination:h})=>{const p=new u(0);let I;s?I=s(p,h,!0):p.connect(h);for(const{track:x,state:m}of e){if(m.muted&&!m.soloed||n&&!m.soloed)continue;const w=new u(As(m.volume)),k=new v(m.pan),S=new d(m.muted?0:1),R=o?.(x.id);R?R(S,p,!0):S.connect(p),k.connect(S),w.connect(k);for(const E of x.clips){const{audioBuffer:M,startSample:$,durationSamples:Z,offsetSamples:D,gain:P,fadeIn:z,fadeOut:O}=E,V=$/r,q=Z/r,T=D/r,Q=new f(M),J=new g(Q),oe=new d(P);if(J.connect(oe),oe.connect(w),z){const ee=V,te=V+z.duration,me=oe.gain._param;me.setValueAtTime(0,ee),me.linearRampToValueAtTime(P,te)}if(O){const ee=V+q-O.duration,te=V+q,me=oe.gain._param;me.setValueAtTime(P,ee),me.linearRampToValueAtTime(0,te)}J.start(V,T,q)}}y.start(0)},a,2,r)}catch(y){throw y instanceof Error?y:new Error(`Tone.Offline rendering failed: ${String(y)}`)}return l(.9),C.get()}function As(e){return 20*Math.log10(Math.max(e,1e-4))}async function Ss(e,t,n,a,r){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:d,fadeOut:v}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const g=o/a,f=l/a,C=c/a,y=e.createBufferSource();y.buffer=s;const h=e.createGain(),p=u*n.volume,I=e.createStereoPanner();if(I.pan.value=n.pan,y.connect(h),h.connect(I),I.connect(e.destination),r){if(d?h.gain.setValueAtTime(0,g):h.gain.setValueAtTime(p,g),d){const x=g,m=g+d.duration;hn(h.gain,x,m,0,p,d.type||"linear")}if(v){const x=g+f-v.duration,m=g+f;(!d||d.duration<f-v.duration)&&h.gain.setValueAtTime(p,x),hn(h.gain,x,m,p,0,v.type||"linear")}}else h.gain.setValueAtTime(p,g);y.start(g,C,f)}function hn(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=pn(a,r,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=pn(a,r,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function pn(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 qn=i.createContext(null),Qn=i.createContext(null),ea=i.createContext(null),ta=i.createContext(null),na=i.createContext(null),$s=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:v,onAnnotationUpdate:g,onAnnotationsChange:f,barWidth:C=1,barGap:y=0,progressBarWidth:h,children:p})=>{const I=h??C+y,x=i.useMemo(()=>u?.annotations?u.annotations.map(B=>typeof B.start=="number"?B:Hn(B)):[],[u?.annotations]),m=i.useRef(x);m.current=x;const[w,k]=i.useState(null),[S,R]=i.useState(!1),[E,M]=i.useState(0),[$,Z]=i.useState(0),[D,P]=i.useState([]),[z,O]=i.useState([]),[V,q]=i.useState([]),[T,Q]=i.useState(0),[J,oe]=i.useState(0),[ee,te]=i.useState(null),[me,Te]=i.useState(o),[H,U]=i.useState(u?.isContinuousPlay??!1),[ne,se]=i.useState(u?.linkEndpoints??!1),[de,K]=i.useState(u?.editable??!1),[ye,Pe]=i.useState(!1),[Ze,Ke]=i.useState(0),[Ve,He]=i.useState(0),[nt,Ue]=i.useState(!1),F=i.useRef(null),Ce=i.useRef(0),he=i.useRef(0),fe=i.useRef(null),Je=i.useRef(V),X=i.useRef(0),ae=i.useRef(0),$e=i.useRef(null),_=i.useRef(null),G=i.useRef(!1),re=i.useRef(u?.isContinuousPlay??!1),ce=i.useRef(null),pe=i.useRef(r),ke=i.useRef(!1),le=i.useRef(0),_e=i.useRef(0),Ie=i.useRef(0),We=i.useRef(0),{timeFormat:je,setTimeFormat:qe,formatTime:at}=Ln(),Xe=Yn({initialSamplesPerPixel:r,zoomLevels:s}),Ge=Xe.samplesPerPixel,{masterVolume:da,setMasterVolume:fa}=On({playoutRef:F,initialVolume:1}),ma=i.useCallback(B=>{re.current=B,U(B)},[]),Qe=i.useCallback(B=>{ce.current=B,k(B)},[]),ha=i.useCallback(B=>{ke.current=B,Pe(B)},[]),rt=i.useCallback((B,j)=>{Ie.current=B,We.current=j,Ke(B),He(j)},[]),pa=i.useCallback(()=>{const B=le.current,j=_e.current;B!==j&&j>B&&rt(B,j)},[rt]),ga=i.useCallback(()=>{rt(0,0)},[rt]);i.useEffect(()=>{G.current=me},[me]),i.useEffect(()=>{Je.current=V},[V]),i.useEffect(()=>{le.current=T,_e.current=J},[T,J]),i.useEffect(()=>{if(!_.current||!D.length)return;const B=_.current,j=pe.current,Y=Ge;if(j===Y)return;const ie=c.show?c.width:0,L=B.clientWidth,be=B.scrollLeft+L/2-ie,ze=D[0].sampleRate,ve=be*j/ze*ze/Y,Me=Math.max(0,ve+ie-L/2);B.scrollLeft=Me,pe.current=Y},[Ge,D,c]);const dt=i.useRef(null);i.useEffect(()=>{if(Ue(!1),e.length===0){P([]),Z(0),q([]),O([]),F.current&&(F.current.dispose(),F.current=null);return}const B=S,j=he.current;return F.current&&B&&(F.current.stop(),fe.current&&(cancelAnimationFrame(fe.current),fe.current=null),dt.current={position:j}),(async()=>{try{const ie=[];e.forEach(ge=>{ge.clips.length>0&&ge.clips[0].audioBuffer&&ie.push(ge.clips[0].audioBuffer)});let L=0;e.forEach(ge=>{ge.clips.forEach(ve=>{const Me=ve.sampleRate,ft=(ve.startSample+ve.durationSamples)/Me;L=Math.max(L,ft)})}),P(ie),Z(L),q(ge=>ge.length===e.length?ge.map((ve,Me)=>({...ve,name:e[Me].name})):e.map(ve=>({name:ve.name,muted:ve.muted,soloed:ve.soloed,volume:ve.volume,pan:ve.pan}))),F.current&&F.current.dispose();const xe=new La({effects:d}),be=Je.current;e.forEach((ge,ve)=>{const Me=ge.clips.filter(Le=>Le.audioBuffer);if(Me.length>0){const Le=Me[0].sampleRate,ft=Math.min(...Me.map(Re=>Re.startSample/Le)),Da=Math.max(...Me.map(Re=>(Re.startSample+Re.durationSamples)/Le)),mt=be[ve],Ba={id:`track-${ve}`,name:ge.name,gain:mt?.volume??ge.volume,muted:mt?.muted??ge.muted,soloed:mt?.soloed??ge.soloed,stereoPan:mt?.pan??ge.pan,startTime:ft,endTime:Da},Ta=Me.map(Re=>{const Rt=Re.sampleRate;return{buffer:Re.audioBuffer,startTime:Re.startSample/Rt-ft,duration:Re.durationSamples/Rt,offset:Re.offsetSamples/Rt,fadeIn:Re.fadeIn,fadeOut:Re.fadeOut,gain:Re.gain}});xe.addTrack({clips:Ta,track:Ba,effects:ge.effects})}}),xe.applyInitialSoloState(),F.current=xe,Ue(!0);const ze=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:L}});window.dispatchEvent(ze),v?.()}catch(ie){console.error("Error loading audio:",ie)}})(),()=>{fe.current&&cancelAnimationFrame(fe.current),F.current&&F.current.dispose()}},[e,v,S]),i.useEffect(()=>{if(e.length===0)return;const B=16,j=e.map(Y=>Y.clips.map(L=>{if(L.waveformData){const be=zn(L.waveformData,Ge,0,L.offsetSamples,L.durationSamples);return{clipId:L.id,trackName:Y.name,peaks:{length:be.length,data:[be.data],bits:be.bits},startSample:L.startSample,durationSamples:L.durationSamples,fadeIn:L.fadeIn,fadeOut:L.fadeOut}}if(!L.audioBuffer)return console.warn(`Clip "${L.name||L.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:L.id,trackName:Y.name,peaks:{length:0,data:[],bits:B},startSample:L.startSample,durationSamples:L.durationSamples,fadeIn:L.fadeIn,fadeOut:L.fadeOut};const xe=to(L.audioBuffer,Ge,n,B,L.offsetSamples,L.durationSamples);return{clipId:L.id,trackName:Y.name,peaks:xe,startSample:L.startSample,durationSamples:L.durationSamples,fadeIn:L.fadeIn,fadeOut:L.fadeOut}}));O(j)},[e,Ge,n]);const Ne=i.useCallback(()=>{fe.current&&(cancelAnimationFrame(fe.current),fe.current=null);const B=()=>{const j=W.getContext().currentTime-X.current,Y=ae.current+j;he.current=Y,M(Y);const ie=m.current;if(ie.length>0){const xe=ie.find(be=>Y>=be.start&&Y<be.end);if(re.current)xe&&xe.id!==ce.current?Qe(xe.id):!xe&&ce.current!==null&&Qe(null);else if(ce.current){const be=ie.find(ze=>ze.id===ce.current);if(be&&Y>=be.end){F.current&&F.current.stop(),R(!1),he.current=Ce.current,M(Ce.current);return}}else xe&&Qe(xe.id)}if(G.current&&_.current&&D.length>0){const xe=_.current,be=D[0].sampleRate,ze=Y*be/pe.current,ge=xe.clientWidth,ve=c.show?c.width:0,Me=ze+ve,Le=Math.max(0,Me-ge/2);xe.scrollLeft=Le}if($e.current!==null&&Y>=$e.current){F.current&&F.current.stop(),R(!1),he.current=$e.current,M($e.current),$e.current=null;return}const L=Ie.current!==We.current&&We.current>Ie.current;if(ke.current&&L&&Y>=We.current){F.current?.stop();const be=W.getContext().currentTime;X.current=be,ae.current=Ie.current,he.current=Ie.current,F.current?.play(be,Ie.current),fe.current=requestAnimationFrame(B);return}if(Y>=$){F.current&&F.current.stop(),R(!1),he.current=Ce.current,M(Ce.current),Qe(null);return}fe.current=requestAnimationFrame(B)};fe.current=requestAnimationFrame(B)},[$,D,Ge,H]),Fe=i.useCallback(()=>{fe.current&&(cancelAnimationFrame(fe.current),fe.current=null)},[]);i.useEffect(()=>{(async()=>{if(S&&fe.current&&F.current)if(H){const j=he.current;F.current.stop(),Fe(),await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const ie=W.getContext().currentTime;X.current=ie,ae.current=j,F.current.play(ie,j),Ne()}else Fe(),Ne()})()},[H,S,Ne,Fe]),i.useEffect(()=>{(async()=>{if(dt.current&&F.current){const{position:j}=dt.current;dt.current=null,await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const ie=W.getContext().currentTime;X.current=ie,ae.current=j,F.current.play(ie,j),R(!0),Ne()}})()},[e,Ne]);const Mt=i.useCallback(async(B,j)=>{if(!F.current||D.length===0)return;await F.current.init(),await W.start();const Y=B??he.current;Ce.current=Y,he.current=Y,F.current.setOnPlaybackComplete(()=>{}),F.current.stop(),Fe();const L=W.getContext().currentTime;X.current=L,ae.current=Y,$e.current=j!==void 0?Y+j:null,F.current.play(L,Y,j),R(!0),Ne()},[D.length,Ne,Fe]),ba=i.useCallback(()=>{if(!F.current)return;const B=W.getContext().currentTime-X.current,j=ae.current+B;F.current.pause(),R(!1),Fe(),he.current=j,M(j)},[Fe]),va=i.useCallback(()=>{F.current&&(F.current.stop(),R(!1),Fe(),he.current=Ce.current,M(Ce.current),Qe(null))},[Fe]),Ca=i.useCallback(B=>{const j=Math.max(0,Math.min(B,$));he.current=j,M(j),S&&F.current&&(F.current.stop(),Fe(),Mt(j))},[$,S,Mt,Fe]),xa=i.useCallback((B,j)=>{const Y=[...V];if(Y[B]={...Y[B],muted:j},q(Y),F.current){const ie=`track-${B}`;F.current.setMute(ie,j)}},[V]),wa=i.useCallback((B,j)=>{const Y=[...V];if(Y[B]={...Y[B],soloed:j},q(Y),F.current){const ie=`track-${B}`;F.current.setSolo(ie,j)}},[V]),ya=i.useCallback((B,j)=>{const Y=[...V];if(Y[B]={...Y[B],volume:j},q(Y),F.current){const ie=`track-${B}`,L=F.current.getTrack(ie);L&&L.setVolume(j)}},[V]),ka=i.useCallback((B,j)=>{const Y=[...V];if(Y[B]={...Y[B],pan:j},q(Y),F.current){const ie=`track-${B}`,L=F.current.getTrack(ie);L&&L.setPan(j)}},[V]),Ia=i.useCallback((B,j)=>{Q(B),oe(j),he.current=B,M(B),S&&F.current&&(F.current.stop(),F.current.play(W.getContext().currentTime,B))},[S]),Aa=i.useCallback(B=>{_.current=B},[]),Nt=i.useRef(f);Nt.current=f;const Sa=i.useCallback(B=>{const j=typeof B=="function"?B(m.current):B;Nt.current?.(j)},[]),$a=D[0]?.sampleRate||44100,Lt=t?30:0,Ma=e.length*a+Lt,Yt={isPlaying:S,currentTime:E,currentTimeRef:he,playbackStartTimeRef:X,audioStartPositionRef:ae},Ot={continuousPlay:H,linkEndpoints:ne,annotationsEditable:de,isAutomaticScroll:me,isLoopEnabled:ye,annotations:x,activeAnnotationId:w,selectionStart:T,selectionEnd:J,selectedTrackId:ee,loopStart:Ze,loopEnd:Ve},Kt={play:Mt,pause:ba,stop:va,seekTo:Ca,setCurrentTime:B=>{he.current=B,M(B)},setTrackMute:xa,setTrackSolo:wa,setTrackVolume:ya,setTrackPan:ka,setSelection:Ia,setSelectedTrackId:te,setTimeFormat:qe,formatTime:at,zoomIn:Xe.zoomIn,zoomOut:Xe.zoomOut,setMasterVolume:fa,setAutomaticScroll:B=>{Te(B)},setScrollContainer:Aa,scrollContainerRef:_,setContinuousPlay:ma,setLinkEndpoints:se,setAnnotationsEditable:K,setAnnotations:Sa,setActiveAnnotationId:Qe,setLoopEnabled:ha,setLoopRegion:rt,setLoopRegionFromSelection:pa,clearLoopRegion:ga},Ut={duration:$,audioBuffers:D,peaksDataArray:z,trackStates:V,tracks:e,sampleRate:$a,waveHeight:a,timeScaleHeight:Lt,minimumPlaylistHeight:Ma,controls:c,playoutRef:F,samplesPerPixel:Ge,timeFormat:je,masterVolume:da,canZoomIn:Xe.canZoomIn,canZoomOut:Xe.canZoomOut,barWidth:C,barGap:y,progressBarWidth:I,isReady:nt},Ra={...Yt,...Ot,...Kt,...Ut},Ea={...Sn,...l};return b.jsx(A.ThemeProvider,{theme:Ea,children:b.jsx(qn.Provider,{value:Yt,children:b.jsx(Qn.Provider,{value:Ot,children:b.jsx(ea.Provider,{value:Kt,children:b.jsx(ta.Provider,{value:Ut,children:b.jsx(na.Provider,{value:Ra,children:p})})})})})})},Ae=()=>{const e=i.useContext(qn);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Se=()=>{const e=i.useContext(Qn);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},ue=()=>{const e=i.useContext(ea);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},we=()=>{const e=i.useContext(ta);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},Ms=()=>{const e=i.useContext(na);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var Rs=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}},Es=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 Rs({...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 aa=i.createContext(null),ra=i.createContext(null),oa=i.createContext(null),sa=i.createContext(null),Ds=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:s=!1,theme:o,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:d=0,progressBarWidth:v,onAnnotationsChange:g,onReady:f,children:C})=>{const y=v??u+d,[h,p]=i.useState(!1),[I,x]=i.useState(0),[m,w]=i.useState(0),[k,S]=i.useState([]),[R,E]=i.useState(r),M=i.useMemo(()=>c?.annotations?c.annotations.map(X=>typeof X.start=="number"?X:Hn(X)):[],[c?.annotations]),$=i.useRef(M);$.current=M;const[Z,D]=i.useState(null),[P,z]=i.useState(c?.isContinuousPlay??!1),[O]=i.useState(t),[V,q]=i.useState(s),T=i.useRef(null),Q=i.useRef(0),J=i.useRef(null),oe=i.useRef(P),ee=i.useRef(null),te=i.useRef(null),me=i.useRef(s),Te=i.useRef(t);i.useEffect(()=>{oe.current=P},[P]),i.useEffect(()=>{me.current=V},[V]);const H=i.useCallback(X=>{ee.current=X,D(X)},[]),U=i.useCallback(X=>{oe.current=X,z(X)},[]),ne=i.useCallback(X=>{te.current=X},[]),se=e.waveformData.sample_rate;i.useEffect(()=>{const X=new Es({playbackRate:r});X.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const ae=X.getTrack(X.track?.id??"");return ae&&ae.setOnTimeUpdateCallback($e=>{Q.current=$e}),X.setOnPlaybackComplete(()=>{J.current&&(cancelAnimationFrame(J.current),J.current=null),p(!1),H(null),Q.current=0,x(0)}),T.current=X,w(e.waveformData.duration),f?.(),()=>{J.current&&cancelAnimationFrame(J.current),X.dispose()}},[e.source,e.waveformData,e.name,r,f]),i.useEffect(()=>{const X=zn(e.waveformData,O,0,0,Math.ceil(e.waveformData.duration*se)),ae={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:X.length,data:[X.data],bits:X.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*se)};S([[ae]])},[e.waveformData,e.name,O,se]);const de=i.useCallback(()=>{J.current&&cancelAnimationFrame(J.current);const X=()=>{const ae=T.current?.getCurrentTime()??0;Q.current=ae,x(ae);const $e=$.current;if($e.length>0){const _=$e.find(G=>ae>=G.start&&ae<G.end);if(oe.current)_&&_.id!==ee.current?H(_.id):!_&&ee.current!==null&&H(null);else if(ee.current){const G=$e.find(re=>re.id===ee.current);if(G&&ae>=G.end){T.current?.stop(),p(!1);return}}else _&&H(_.id)}if(me.current&&te.current){const _=te.current,G=ae*se/Te.current,re=_.clientWidth,ce=l.show?l.width:0,pe=G+ce,ke=Math.max(0,pe-re/2);_.scrollLeft=ke}J.current=requestAnimationFrame(X)};J.current=requestAnimationFrame(X)},[H,se,l]),K=i.useCallback(()=>{J.current&&(cancelAnimationFrame(J.current),J.current=null)},[]),ye=i.useCallback(X=>{if(!T.current)return;const ae=X??Q.current;T.current.play(void 0,ae),p(!0),de()},[de]),Pe=i.useCallback(()=>{T.current&&(T.current.pause(),p(!1),K(),x(T.current.getCurrentTime()))},[K]),Ze=i.useCallback(()=>{T.current&&(T.current.stop(),p(!1),K(),Q.current=0,x(0),H(null))},[K,H]),Ke=i.useCallback(X=>{const ae=Math.max(0,Math.min(X,m));Q.current=ae,x(ae),T.current&&T.current.seekTo(ae)},[m]),Ve=i.useCallback(X=>{const ae=Math.max(.5,Math.min(2,X));E(ae),T.current&&T.current.setPlaybackRate(ae)},[]),He=a?30:0,nt=i.useMemo(()=>({isPlaying:h,currentTime:I,currentTimeRef:Q}),[h,I]),Ue=i.useMemo(()=>({continuousPlay:P,annotations:M,activeAnnotationId:Z,playbackRate:R,isAutomaticScroll:V}),[P,M,Z,R,V]),F=i.useRef(g);F.current=g;const Ce=i.useCallback(X=>{const ae=typeof X=="function"?X($.current):X;F.current?.(ae)},[]),he=i.useMemo(()=>({play:ye,pause:Pe,stop:Ze,seekTo:Ke,setPlaybackRate:Ve,setContinuousPlay:U,setAnnotations:Ce,setActiveAnnotationId:H,setAutomaticScroll:X=>{q(X)},setScrollContainer:ne,scrollContainerRef:te}),[ye,Pe,Ze,Ke,Ve,U,Ce,H,ne]),fe=i.useMemo(()=>({duration:m,peaksDataArray:k,sampleRate:se,waveHeight:n,timeScaleHeight:He,samplesPerPixel:O,playoutRef:T,controls:l,barWidth:u,barGap:d,progressBarWidth:y}),[m,k,se,n,He,O,l,u,d,y]),Je={...Sn,...o};return b.jsx(A.ThemeProvider,{theme:Je,children:b.jsx(aa.Provider,{value:nt,children:b.jsx(ra.Provider,{value:Ue,children:b.jsx(oa.Provider,{value:he,children:b.jsx(sa.Provider,{value:fe,children:C})})})})})},At=()=>{const e=i.useContext(aa);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},St=()=>{const e=i.useContext(ra);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},Gt=()=>{const e=i.useContext(oa);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},$t=()=>{const e=i.useContext(sa);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},Bs=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Ae(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=Se(),{play:o}=ue(),l=async()=>{if(a!==r&&r>a)if(s)await o(a);else{const u=r-a;await o(a,u)}else await o(n.current??0)};return b.jsx(Be,{onClick:l,disabled:t,className:e,children:"Play"})},Ts=({className:e})=>{const{isPlaying:t}=Ae(),{pause:n}=ue();return b.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Pause"})},Ws=({className:e})=>{const{isPlaying:t}=Ae(),{stop:n}=ue();return b.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Stop"})},Fs=({className:e})=>{const{isPlaying:t}=Ae(),{play:n,setCurrentTime:a}=ue(),{playoutRef:r}=we(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return b.jsx(Be,{onClick:s,className:e,children:"Rewind"})},_s=({className:e})=>{const{isPlaying:t}=Ae(),{play:n,setCurrentTime:a}=ue(),{duration:r,playoutRef:s}=we(),o=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return b.jsx(Be,{onClick:o,className:e,children:"Fast Forward"})},Zs=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Ae(),{play:r,setCurrentTime:s}=ue(),{playoutRef:o}=we(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&o.current&&(o.current.stop(),r(c))};return b.jsx(Be,{onClick:l,className:t,children:"Skip Backward"})},Ps=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Ae(),{play:r,setCurrentTime:s}=ue(),{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 b.jsx(Be,{onClick:c,className:t,children:"Skip Forward"})},Vs=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=Se(),{setLoopEnabled:r,setLoopRegion:s}=ue(),{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 b.jsx(Be,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},js=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=Se(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=ue(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?o():s()};return b.jsx(Be,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},zs=({className:e,disabled:t})=>{const{zoomIn:n}=ue(),{canZoomIn:a}=we();return b.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Hs=({className:e,disabled:t})=>{const{zoomOut:n}=ue(),{canZoomOut:a}=we();return b.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Xs=({className:e})=>{const{masterVolume:t}=we(),{setMasterVolume:n}=ue();return b.jsx(br,{volume:t,onChange:n,className:e})},Gs=({className:e})=>{const{timeFormat:t}=we(),{setTimeFormat:n}=ue();return b.jsx(Xr,{value:t,onChange:n,className:e})},Ns=A.span`
|
|
1193
|
+
`,fs=({level:e,peakLevel:t,width:n=200,height:a=20,className:r})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return b.jsxs(is,{$width:n,$height:a,className:r,children:[b.jsx(cs,{$level:s,$height:a}),t!==void 0&&o>0&&b.jsx(us,{$peakLevel:o,$height:a}),b.jsxs(ds,{$height:a,children:[b.jsx(mn,{$position:60,$height:a}),b.jsx(mn,{$position:85,$height:a})]})]})};i.memo(fs);function ms(e,t,n,a={}){const{currentTime:r=0,audioConstraints:s,...o}=a,[l,c]=i.useState(!1),[u,d]=i.useState(null),{stream:v,devices:g,hasPermission:f,requestAccess:C,error:y}=os(),{level:h,peakLevel:p}=ss(v),{isRecording:I,isPaused:x,duration:m,peaks:w,startRecording:k,stopRecording:S,pauseRecording:$,resumeRecording:E,error:R}=rs(v,o),M=i.useCallback(async()=>{n&&(l||(await Bt(),c(!0)),await k())},[n,l,k]),Z=i.useCallback(async()=>{const H=await S();if(H&&n){const O=e.findIndex(ee=>ee.id===n);if(O===-1)return;const V=e[O],q=Math.floor(r*H.sampleRate);let T=0;if(V.clips.length>0){const ee=V.clips.map(te=>te.startSample+te.durationSamples);T=Math.max(...ee)}const Q=Math.max(q,T),J={id:`clip-${Date.now()}`,audioBuffer:H,startSample:Q,durationSamples:H.length,offsetSamples:0,sampleRate:H.sampleRate,sourceDurationSamples:H.length,gain:1,name:`Recording ${new Date().toLocaleTimeString()}`},oe=e.map((ee,te)=>te===O?{...ee,clips:[...ee.clips,J]}:ee);t(oe)}},[n,e,t,r,S]);i.useEffect(()=>{f&&g.length>0&&u===null&&d(g[0].deviceId)},[f,g.length]);const D=i.useCallback(async()=>{await C(void 0,s),await Bt(),c(!0)},[C,s]),P=i.useCallback(async H=>{d(H),await C(H,s),await Bt(),c(!0)},[C,s]);return{isRecording:I,isPaused:x,duration:m,level:h,peakLevel:p,error:y||R,stream:v,devices:g,hasPermission:f,selectedDevice:u,startRecording:M,stopRecording:Z,pauseRecording:$,resumeRecording:E,requestMicAccess:D,changeDevice:P,recordingPeaks:w}}const ut=[{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}]}],Gt=e=>ut.find(t=>t.id===e),hs=e=>ut.filter(t=>t.category===e),ps=[{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"}],gs={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 bs=0;const vs=()=>`effect_${Date.now()}_${++bs}`;function it(e,t){const n=gs[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=vs();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 xs(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(h=>{const p=o.current;if(!p)return;const{masterGainNode:I,destination:x,analyserNode:m}=p;try{I.disconnect()}catch{}const w=h.map(k=>r.current.get(k.instanceId)).filter(k=>k!==void 0);if(w.length===0)I.connect(m),m.connect(x);else{let k=I;w.forEach(S=>{try{S.disconnect()}catch{}k.connect(S.effect),k=S.effect}),k.connect(m),m.connect(x)}},[]),c=i.useCallback(h=>{const p=Gt(h);if(!p){console.error(`Unknown effect: ${h}`);return}const I={};p.parameters.forEach(w=>{I[w.name]=w.default});const x=it(p,I);r.current.set(x.instanceId,x);const m={instanceId:x.instanceId,effectId:p.id,definition:p,params:I,bypassed:!1};n(w=>[...w,m])},[]),u=i.useCallback(h=>{const p=r.current.get(h);p&&(p.dispose(),r.current.delete(h)),n(I=>I.filter(x=>x.instanceId!==h))},[]),d=i.useCallback((h,p,I)=>{const x=r.current.get(h);x&&x.setParameter(p,I),n(m=>m.map(w=>w.instanceId===h?{...w,params:{...w.params,[p]:I}}:w))},[]),v=i.useCallback(h=>{const p=a.current.find(m=>m.instanceId===h);if(!p)return;const I=!p.bypassed,x=r.current.get(h);if(x){const m=p.params.wet??1;x.setParameter("wet",I?0:m)}n(m=>m.map(w=>w.instanceId===h?{...w,bypassed:I}:w))},[]),g=i.useCallback((h,p)=>{n(I=>{const x=[...I],[m]=x.splice(h,1);return x.splice(p,0,m),x})},[]),f=i.useCallback(()=>{r.current.forEach(h=>h.dispose()),r.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const C=i.useCallback((h,p,I)=>{const x=new W.Analyser("fft",e);s.current=x,o.current={masterGainNode:h,destination:p,analyserNode:x};const w=a.current.map(k=>r.current.get(k.instanceId)).filter(k=>k!==void 0);if(w.length===0)h.connect(x),x.connect(p);else{let k=h;w.forEach(S=>{k.connect(S.effect),k=S.effect}),k.connect(x),x.connect(p)}return function(){x.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{r.current.forEach(h=>h.dispose()),r.current.clear()},[]);const y=i.useCallback(()=>{const h=t.filter(p=>!p.bypassed);if(h.length!==0)return(p,I,x)=>{const m=[];for(const w of h){const k=it(w.definition,w.params);m.push(k)}if(m.length===0)p.connect(I);else{let w=p;m.forEach(k=>{w.connect(k.effect),w=k.effect}),w.connect(I)}return function(){m.forEach(k=>k.dispose())}}},[t]);return{activeEffects:t,availableEffects:ut,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:v,reorderEffects:g,clearAllEffects:f,masterEffects:C,createOfflineEffectsFunction:y,analyserRef:s}}function ws(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),a=i.useRef(new Map),r=i.useCallback((f,C)=>{const y=a.current.get(f);if(!y)return;const{graphEnd:h,masterGainNode:p}=y,I=n.current.get(f);try{h.disconnect()}catch{}const x=C.map(m=>I?.get(m.instanceId)).filter(m=>m!==void 0);if(x.length===0)h.connect(p);else{let m=h;x.forEach(w=>{try{w.disconnect()}catch{}m.connect(w.effect),m=w.effect}),m.connect(p)}},[]),s=i.useCallback((f,C)=>{const y=Gt(C);if(!y){console.error(`Unknown effect: ${C}`);return}const h={};y.parameters.forEach(x=>{h[x.name]=x.default});const p=it(y,h);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(p.instanceId,p);const I={instanceId:p.instanceId,effectId:y.id,definition:y,params:h,bypassed:!1};t(x=>{const m=new Map(x),w=m.get(f)||[];return m.set(f,[...w,I]),m})},[]),o=i.useCallback((f,C)=>{const y=n.current.get(f),h=y?.get(C);h&&(h.dispose(),y?.delete(C)),t(p=>{const I=new Map(p),x=I.get(f)||[];return I.set(f,x.filter(m=>m.instanceId!==C)),I})},[]),l=i.useCallback((f,C,y,h)=>{const I=n.current.get(f)?.get(C);I&&I.setParameter(y,h),t(x=>{const m=new Map(x),w=m.get(f)||[];return m.set(f,w.map(k=>k.instanceId===C?{...k,params:{...k.params,[y]:h}}:k)),m})},[]),c=i.useCallback((f,C)=>{const h=(d.current.get(f)||[]).find(m=>m.instanceId===C);if(!h)return;const p=!h.bypassed,x=n.current.get(f)?.get(C);if(x){const m=h.params.wet??1;x.setParameter("wet",p?0:m)}t(m=>{const w=new Map(m),k=w.get(f)||[];return w.set(f,k.map(S=>S.instanceId===C?{...S,bypassed:p}:S)),w})},[]),u=i.useCallback(f=>{const C=n.current.get(f);C&&(C.forEach(y=>y.dispose()),C.clear()),t(y=>{const h=new Map(y);return h.set(f,[]),h})},[]),d=i.useRef(e);d.current=e;const v=i.useCallback(f=>(C,y,h)=>{a.current.set(f,{graphEnd:C,masterGainNode:y});const p=d.current.get(f)||[],I=n.current.get(f),x=p.map(m=>I?.get(m.instanceId)).filter(m=>m!==void 0);if(x.length===0)C.connect(y);else{let m=C;x.forEach(w=>{m.connect(w.effect),m=w.effect}),m.connect(y)}return function(){a.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,C)=>{r(C,f)})},[e,r]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(C=>C.dispose()),f.clear()}),n.current.clear()},[]);const g=i.useCallback(f=>{const y=(e.get(f)||[]).filter(h=>!h.bypassed);if(y.length!==0)return(h,p,I)=>{const x=[];for(const m of y){const w=it(m.definition,m.params);x.push(w)}if(x.length===0)h.connect(p);else{let m=h;x.forEach(w=>{m.connect(w.effect),m=w.effect}),m.connect(p)}return function(){x.forEach(w=>w.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:v,createOfflineTrackEffectsFunction:g,availableEffects:ut}}function ys(e,t={}){const{bitDepth:n=16}=t,a=e.numberOfChannels,r=e.sampleRate,s=e.length,o=n/8,l=a*o,c=r*l,u=s*l,d=44,v=d+u,g=new ArrayBuffer(v),f=new DataView(g);gt(f,0,"RIFF"),f.setUint32(4,v-8,!0),gt(f,8,"WAVE"),gt(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,n===32?3:1,!0),f.setUint16(22,a,!0),f.setUint32(24,r,!0),f.setUint32(28,c,!0),f.setUint16(32,l,!0),f.setUint16(34,n,!0),gt(f,36,"data"),f.setUint32(40,u,!0);const C=[];for(let h=0;h<a;h++)C.push(e.getChannelData(h));let y=d;if(n===16)for(let h=0;h<s;h++)for(let p=0;p<a;p++){const I=C[p][h],x=Math.max(-1,Math.min(1,I)),m=x<0?x*32768:x*32767;f.setInt16(y,m,!0),y+=2}else for(let h=0;h<s;h++)for(let p=0;p<a;p++)f.setFloat32(y,C[p][h],!0),y+=4;return new Blob([g],{type:"audio/wav"})}function gt(e,t,n){for(let a=0;a<n.length;a++)e.setUint8(t+a,n.charCodeAt(a))}function ks(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 Jn(){const[e,t]=i.useState(!1),[n,a]=i.useState(0),[r,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:v="master",trackIndex:g,autoDownload:f=!0,applyEffects:C=!0,effectsFunction:y,createOfflineTrackEffects:h,bitDepth:p=16,onProgress:I}=u;t(!0),a(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(v==="individual"&&(g===void 0||g<0||g>=l.length))throw new Error("Invalid track index for individual export");const x=l[0].clips[0]?.sampleRate||44100;let m=0;for(const M of l)for(const Z of M.clips){const D=Z.startSample+Z.durationSamples;m=Math.max(m,D)}m+=Math.round(x*.1);const w=m/x,k=v==="individual"?[{track:l[g],state:c[g],index:g}]:l.map((M,Z)=>({track:M,state:c[Z],index:Z})),S=c.some(M=>M.soloed),$=!!h;let E;if((y||$)&&C)E=await Is(k,c,S,w,x,y,h,M=>{a(M),I?.(M)});else{const M=new OfflineAudioContext(2,m,x);let Z=0;const D=k.reduce((P,{track:H})=>P+H.clips.length,0);for(const{track:P,state:H}of k)if(!(H.muted&&!H.soloed)&&!(S&&!H.soloed))for(const O of P.clips){await Ss(M,O,H,x,C),Z++;const V=Z/D*.5;a(V),I?.(V)}a(.5),I?.(.5),E=await M.startRendering()}a(.9),I?.(.9);const R=ys(E,{bitDepth:p});if(a(1),I?.(1),f){const M=v==="individual"?`${d}_${l[g].name}`:d;ks(R,`${M}.wav`)}return{audioBuffer:E,blob:R,duration:w}}catch(x){const m=x instanceof Error?x.message:"Export failed";throw s(m),x}finally{t(!1)}},[]),isExporting:e,progress:n,error:r}}async function Is(e,t,n,a,r,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:v,Player:g,ToneAudioBuffer:f}=await import("tone");l(.1);let C;try{C=await c(async({transport:y,destination:h})=>{const p=new u(0);let I;s?I=s(p,h,!0):p.connect(h);for(const{track:x,state:m}of e){if(m.muted&&!m.soloed||n&&!m.soloed)continue;const w=new u(As(m.volume)),k=new v(m.pan),S=new d(m.muted?0:1),$=o?.(x.id);$?$(S,p,!0):S.connect(p),k.connect(S),w.connect(k);for(const E of x.clips){const{audioBuffer:R,startSample:M,durationSamples:Z,offsetSamples:D,gain:P,fadeIn:H,fadeOut:O}=E,V=M/r,q=Z/r,T=D/r,Q=new f(R),J=new g(Q),oe=new d(P);if(J.connect(oe),oe.connect(w),H){const ee=V,te=V+H.duration,me=oe.gain._param;me.setValueAtTime(0,ee),me.linearRampToValueAtTime(P,te)}if(O){const ee=V+q-O.duration,te=V+q,me=oe.gain._param;me.setValueAtTime(P,ee),me.linearRampToValueAtTime(0,te)}J.start(V,T,q)}}y.start(0)},a,2,r)}catch(y){throw y instanceof Error?y:new Error(`Tone.Offline rendering failed: ${String(y)}`)}return l(.9),C.get()}function As(e){return 20*Math.log10(Math.max(e,1e-4))}async function Ss(e,t,n,a,r){const{audioBuffer:s,startSample:o,durationSamples:l,offsetSamples:c,gain:u,fadeIn:d,fadeOut:v}=t;if(!s){console.warn(`Skipping clip "${t.name||t.id}" - no audioBuffer for export`);return}const g=o/a,f=l/a,C=c/a,y=e.createBufferSource();y.buffer=s;const h=e.createGain(),p=u*n.volume,I=e.createStereoPanner();if(I.pan.value=n.pan,y.connect(h),h.connect(I),I.connect(e.destination),r){if(d?h.gain.setValueAtTime(0,g):h.gain.setValueAtTime(p,g),d){const x=g,m=g+d.duration;hn(h.gain,x,m,0,p,d.type||"linear")}if(v){const x=g+f-v.duration,m=g+f;(!d||d.duration<f-v.duration)&&h.gain.setValueAtTime(p,x),hn(h.gain,x,m,p,0,v.type||"linear")}}else h.gain.setValueAtTime(p,g);y.start(g,C,f)}function hn(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=pn(a,r,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=pn(a,r,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(a,t),e.linearRampToValueAtTime(r,n)}}function pn(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 qn=i.createContext(null),Qn=i.createContext(null),ea=i.createContext(null),ta=i.createContext(null),na=i.createContext(null),$s=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:a=80,samplesPerPixel:r=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:v,onAnnotationUpdate:g,onAnnotationsChange:f,barWidth:C=1,barGap:y=0,progressBarWidth:h,children:p})=>{const I=h??C+y,x=i.useMemo(()=>u?.annotations?u.annotations.map(B=>typeof B.start=="number"?B:Hn(B)):[],[u?.annotations]),m=i.useRef(x);m.current=x;const[w,k]=i.useState(null),[S,$]=i.useState(!1),[E,R]=i.useState(0),[M,Z]=i.useState(0),[D,P]=i.useState([]),[H,O]=i.useState([]),[V,q]=i.useState([]),[T,Q]=i.useState(0),[J,oe]=i.useState(0),[ee,te]=i.useState(null),[me,Te]=i.useState(o),[j,K]=i.useState(u?.isContinuousPlay??!1),[ne,se]=i.useState(u?.linkEndpoints??!1),[de,U]=i.useState(u?.editable??!1),[ye,Pe]=i.useState(!1),[Ze,Ke]=i.useState(0),[Ve,He]=i.useState(0),[nt,Ue]=i.useState(!1),F=i.useRef(null),Ce=i.useRef(0),he=i.useRef(0),fe=i.useRef(null),Je=i.useRef(V),X=i.useRef(0),ae=i.useRef(0),$e=i.useRef(null),_=i.useRef(null),G=i.useRef(!1),re=i.useRef(u?.isContinuousPlay??!1),ce=i.useRef(null),pe=i.useRef(r),ke=i.useRef(!1),le=i.useRef(0),_e=i.useRef(0),Ie=i.useRef(0),We=i.useRef(0),{timeFormat:je,setTimeFormat:qe,formatTime:at}=Ln(),Xe=Yn({initialSamplesPerPixel:r,zoomLevels:s}),Ge=Xe.samplesPerPixel,{masterVolume:da,setMasterVolume:fa}=On({playoutRef:F,initialVolume:1}),ma=i.useCallback(B=>{re.current=B,K(B)},[]),Qe=i.useCallback(B=>{ce.current=B,k(B)},[]),ha=i.useCallback(B=>{ke.current=B,Pe(B)},[]),rt=i.useCallback((B,z)=>{Ie.current=B,We.current=z,Ke(B),He(z)},[]),pa=i.useCallback(()=>{const B=le.current,z=_e.current;B!==z&&z>B&&rt(B,z)},[rt]),ga=i.useCallback(()=>{rt(0,0)},[rt]);i.useEffect(()=>{G.current=me},[me]),i.useEffect(()=>{Je.current=V},[V]),i.useEffect(()=>{le.current=T,_e.current=J},[T,J]),i.useEffect(()=>{if(!_.current||!D.length)return;const B=_.current,z=pe.current,Y=Ge;if(z===Y)return;const ie=c.show?c.width:0,L=B.clientWidth,be=B.scrollLeft+L/2-ie,ze=D[0].sampleRate,ve=be*z/ze*ze/Y,Me=Math.max(0,ve+ie-L/2);B.scrollLeft=Me,pe.current=Y},[Ge,D,c]);const dt=i.useRef(null);i.useEffect(()=>{if(Ue(!1),e.length===0){P([]),Z(0),q([]),O([]),F.current&&(F.current.dispose(),F.current=null);return}const B=S,z=he.current;return F.current&&B&&(F.current.stop(),fe.current&&(cancelAnimationFrame(fe.current),fe.current=null),dt.current={position:z}),(async()=>{try{const ie=[];e.forEach(ge=>{ge.clips.length>0&&ge.clips[0].audioBuffer&&ie.push(ge.clips[0].audioBuffer)});let L=0;e.forEach(ge=>{ge.clips.forEach(ve=>{const Me=ve.sampleRate,ft=(ve.startSample+ve.durationSamples)/Me;L=Math.max(L,ft)})}),P(ie),Z(L),q(ge=>ge.length===e.length?ge.map((ve,Me)=>({...ve,name:e[Me].name})):e.map(ve=>({name:ve.name,muted:ve.muted,soloed:ve.soloed,volume:ve.volume,pan:ve.pan}))),F.current&&F.current.dispose();const xe=new La({effects:d}),be=Je.current;e.forEach((ge,ve)=>{const Me=ge.clips.filter(Le=>Le.audioBuffer);if(Me.length>0){const Le=Me[0].sampleRate,ft=Math.min(...Me.map(Re=>Re.startSample/Le)),Da=Math.max(...Me.map(Re=>(Re.startSample+Re.durationSamples)/Le)),mt=be[ve],Ba={id:`track-${ve}`,name:ge.name,gain:mt?.volume??ge.volume,muted:mt?.muted??ge.muted,soloed:mt?.soloed??ge.soloed,stereoPan:mt?.pan??ge.pan,startTime:ft,endTime:Da},Ta=Me.map(Re=>{const Et=Re.sampleRate;return{buffer:Re.audioBuffer,startTime:Re.startSample/Et-ft,duration:Re.durationSamples/Et,offset:Re.offsetSamples/Et,fadeIn:Re.fadeIn,fadeOut:Re.fadeOut,gain:Re.gain}});xe.addTrack({clips:Ta,track:Ba,effects:ge.effects})}}),xe.applyInitialSoloState(),F.current=xe,Ue(!0);const ze=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:L}});window.dispatchEvent(ze),v?.()}catch(ie){console.error("Error loading audio:",ie)}})(),()=>{fe.current&&cancelAnimationFrame(fe.current),F.current&&F.current.dispose()}},[e,v,S]),i.useEffect(()=>{if(e.length===0)return;const B=16,z=e.map(Y=>Y.clips.map(L=>{if(L.waveformData){const be=zn(L.waveformData,Ge,0,L.offsetSamples,L.durationSamples);return{clipId:L.id,trackName:Y.name,peaks:{length:be.length,data:[be.data],bits:be.bits},startSample:L.startSample,durationSamples:L.durationSamples,fadeIn:L.fadeIn,fadeOut:L.fadeOut}}if(!L.audioBuffer)return console.warn(`Clip "${L.name||L.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:L.id,trackName:Y.name,peaks:{length:0,data:[],bits:B},startSample:L.startSample,durationSamples:L.durationSamples,fadeIn:L.fadeIn,fadeOut:L.fadeOut};const xe=to(L.audioBuffer,Ge,n,B,L.offsetSamples,L.durationSamples);return{clipId:L.id,trackName:Y.name,peaks:xe,startSample:L.startSample,durationSamples:L.durationSamples,fadeIn:L.fadeIn,fadeOut:L.fadeOut}}));O(z)},[e,Ge,n]);const Ne=i.useCallback(()=>{fe.current&&(cancelAnimationFrame(fe.current),fe.current=null);const B=()=>{const z=W.getContext().currentTime-X.current,Y=ae.current+z;he.current=Y,R(Y);const ie=m.current;if(ie.length>0){const xe=ie.find(be=>Y>=be.start&&Y<be.end);if(re.current)xe&&xe.id!==ce.current?Qe(xe.id):!xe&&ce.current!==null&&Qe(null);else if(ce.current){const be=ie.find(ze=>ze.id===ce.current);if(be&&Y>=be.end){F.current&&F.current.stop(),$(!1),he.current=Ce.current,R(Ce.current);return}}else xe&&Qe(xe.id)}if(G.current&&_.current&&D.length>0){const xe=_.current,be=D[0].sampleRate,ze=Y*be/pe.current,ge=xe.clientWidth,ve=c.show?c.width:0,Me=ze+ve,Le=Math.max(0,Me-ge/2);xe.scrollLeft=Le}if($e.current!==null&&Y>=$e.current){F.current&&F.current.stop(),$(!1),he.current=$e.current,R($e.current),$e.current=null;return}const L=Ie.current!==We.current&&We.current>Ie.current;if(ke.current&&L&&Y>=We.current){F.current?.stop();const be=W.getContext().currentTime;X.current=be,ae.current=Ie.current,he.current=Ie.current,F.current?.play(be,Ie.current),fe.current=requestAnimationFrame(B);return}if(Y>=M){F.current&&F.current.stop(),$(!1),he.current=Ce.current,R(Ce.current),Qe(null);return}fe.current=requestAnimationFrame(B)};fe.current=requestAnimationFrame(B)},[M,D,Ge,j]),Fe=i.useCallback(()=>{fe.current&&(cancelAnimationFrame(fe.current),fe.current=null)},[]);i.useEffect(()=>{(async()=>{if(S&&fe.current&&F.current)if(j){const z=he.current;F.current.stop(),Fe(),await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const ie=W.getContext().currentTime;X.current=ie,ae.current=z,F.current.play(ie,z),Ne()}else Fe(),Ne()})()},[j,S,Ne,Fe]),i.useEffect(()=>{(async()=>{if(dt.current&&F.current){const{position:z}=dt.current;dt.current=null,await F.current.init(),F.current.setOnPlaybackComplete(()=>{});const ie=W.getContext().currentTime;X.current=ie,ae.current=z,F.current.play(ie,z),$(!0),Ne()}})()},[e,Ne]);const Mt=i.useCallback(async(B,z)=>{if(!F.current||D.length===0)return;await F.current.init(),await W.start();const Y=B??he.current;Ce.current=Y,he.current=Y,F.current.setOnPlaybackComplete(()=>{}),F.current.stop(),Fe();const L=W.getContext().currentTime;X.current=L,ae.current=Y,$e.current=z!==void 0?Y+z:null,F.current.play(L,Y,z),$(!0),Ne()},[D.length,Ne,Fe]),ba=i.useCallback(()=>{if(!F.current)return;const B=W.getContext().currentTime-X.current,z=ae.current+B;F.current.pause(),$(!1),Fe(),he.current=z,R(z)},[Fe]),va=i.useCallback(()=>{F.current&&(F.current.stop(),$(!1),Fe(),he.current=Ce.current,R(Ce.current),Qe(null))},[Fe]),Ca=i.useCallback(B=>{const z=Math.max(0,Math.min(B,M));he.current=z,R(z),S&&F.current&&(F.current.stop(),Fe(),Mt(z))},[M,S,Mt,Fe]),xa=i.useCallback((B,z)=>{const Y=[...V];if(Y[B]={...Y[B],muted:z},q(Y),F.current){const ie=`track-${B}`;F.current.setMute(ie,z)}},[V]),wa=i.useCallback((B,z)=>{const Y=[...V];if(Y[B]={...Y[B],soloed:z},q(Y),F.current){const ie=`track-${B}`;F.current.setSolo(ie,z)}},[V]),ya=i.useCallback((B,z)=>{const Y=[...V];if(Y[B]={...Y[B],volume:z},q(Y),F.current){const ie=`track-${B}`,L=F.current.getTrack(ie);L&&L.setVolume(z)}},[V]),ka=i.useCallback((B,z)=>{const Y=[...V];if(Y[B]={...Y[B],pan:z},q(Y),F.current){const ie=`track-${B}`,L=F.current.getTrack(ie);L&&L.setPan(z)}},[V]),Ia=i.useCallback((B,z)=>{Q(B),oe(z),he.current=B,R(B),S&&F.current&&(F.current.stop(),F.current.play(W.getContext().currentTime,B))},[S]),Aa=i.useCallback(B=>{_.current=B},[]),Rt=i.useRef(f);Rt.current=f;const Sa=i.useCallback(B=>{const z=typeof B=="function"?B(m.current):B;if(!Rt.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}Rt.current(z)},[]),$a=D[0]?.sampleRate||44100,Lt=t?30:0,Ma=e.length*a+Lt,Yt={isPlaying:S,currentTime:E,currentTimeRef:he,playbackStartTimeRef:X,audioStartPositionRef:ae},Ot={continuousPlay:j,linkEndpoints:ne,annotationsEditable:de,isAutomaticScroll:me,isLoopEnabled:ye,annotations:x,activeAnnotationId:w,selectionStart:T,selectionEnd:J,selectedTrackId:ee,loopStart:Ze,loopEnd:Ve},Kt={play:Mt,pause:ba,stop:va,seekTo:Ca,setCurrentTime:B=>{he.current=B,R(B)},setTrackMute:xa,setTrackSolo:wa,setTrackVolume:ya,setTrackPan:ka,setSelection:Ia,setSelectedTrackId:te,setTimeFormat:qe,formatTime:at,zoomIn:Xe.zoomIn,zoomOut:Xe.zoomOut,setMasterVolume:fa,setAutomaticScroll:B=>{Te(B)},setScrollContainer:Aa,scrollContainerRef:_,setContinuousPlay:ma,setLinkEndpoints:se,setAnnotationsEditable:U,setAnnotations:Sa,setActiveAnnotationId:Qe,setLoopEnabled:ha,setLoopRegion:rt,setLoopRegionFromSelection:pa,clearLoopRegion:ga},Ut={duration:M,audioBuffers:D,peaksDataArray:H,trackStates:V,tracks:e,sampleRate:$a,waveHeight:a,timeScaleHeight:Lt,minimumPlaylistHeight:Ma,controls:c,playoutRef:F,samplesPerPixel:Ge,timeFormat:je,masterVolume:da,canZoomIn:Xe.canZoomIn,canZoomOut:Xe.canZoomOut,barWidth:C,barGap:y,progressBarWidth:I,isReady:nt},Ra={...Yt,...Ot,...Kt,...Ut},Ea={...Sn,...l};return b.jsx(A.ThemeProvider,{theme:Ea,children:b.jsx(qn.Provider,{value:Yt,children:b.jsx(Qn.Provider,{value:Ot,children:b.jsx(ea.Provider,{value:Kt,children:b.jsx(ta.Provider,{value:Ut,children:b.jsx(na.Provider,{value:Ra,children:p})})})})})})},Ae=()=>{const e=i.useContext(qn);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},Se=()=>{const e=i.useContext(Qn);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},ue=()=>{const e=i.useContext(ea);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},we=()=>{const e=i.useContext(ta);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},Ms=()=>{const e=i.useContext(na);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var Rs=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}},Es=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 Rs({...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 aa=i.createContext(null),ra=i.createContext(null),oa=i.createContext(null),sa=i.createContext(null),Ds=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:a=!1,playbackRate:r=1,automaticScroll:s=!1,theme:o,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:d=0,progressBarWidth:v,onAnnotationsChange:g,onReady:f,children:C})=>{const y=v??u+d,[h,p]=i.useState(!1),[I,x]=i.useState(0),[m,w]=i.useState(0),[k,S]=i.useState([]),[$,E]=i.useState(r),R=i.useMemo(()=>c?.annotations?c.annotations.map(X=>typeof X.start=="number"?X:Hn(X)):[],[c?.annotations]),M=i.useRef(R);M.current=R;const[Z,D]=i.useState(null),[P,H]=i.useState(c?.isContinuousPlay??!1),[O]=i.useState(t),[V,q]=i.useState(s),T=i.useRef(null),Q=i.useRef(0),J=i.useRef(null),oe=i.useRef(P),ee=i.useRef(null),te=i.useRef(null),me=i.useRef(s),Te=i.useRef(t);i.useEffect(()=>{oe.current=P},[P]),i.useEffect(()=>{me.current=V},[V]);const j=i.useCallback(X=>{ee.current=X,D(X)},[]),K=i.useCallback(X=>{oe.current=X,H(X)},[]),ne=i.useCallback(X=>{te.current=X},[]),se=e.waveformData.sample_rate;i.useEffect(()=>{const X=new Es({playbackRate:r});X.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const ae=X.getTrack(X.track?.id??"");return ae&&ae.setOnTimeUpdateCallback($e=>{Q.current=$e}),X.setOnPlaybackComplete(()=>{J.current&&(cancelAnimationFrame(J.current),J.current=null),p(!1),j(null),Q.current=0,x(0)}),T.current=X,w(e.waveformData.duration),f?.(),()=>{J.current&&cancelAnimationFrame(J.current),X.dispose()}},[e.source,e.waveformData,e.name,r,f]),i.useEffect(()=>{const X=zn(e.waveformData,O,0,0,Math.ceil(e.waveformData.duration*se)),ae={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:X.length,data:[X.data],bits:X.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*se)};S([[ae]])},[e.waveformData,e.name,O,se]);const de=i.useCallback(()=>{J.current&&cancelAnimationFrame(J.current);const X=()=>{const ae=T.current?.getCurrentTime()??0;Q.current=ae,x(ae);const $e=M.current;if($e.length>0){const _=$e.find(G=>ae>=G.start&&ae<G.end);if(oe.current)_&&_.id!==ee.current?j(_.id):!_&&ee.current!==null&&j(null);else if(ee.current){const G=$e.find(re=>re.id===ee.current);if(G&&ae>=G.end){T.current?.stop(),p(!1);return}}else _&&j(_.id)}if(me.current&&te.current){const _=te.current,G=ae*se/Te.current,re=_.clientWidth,ce=l.show?l.width:0,pe=G+ce,ke=Math.max(0,pe-re/2);_.scrollLeft=ke}J.current=requestAnimationFrame(X)};J.current=requestAnimationFrame(X)},[j,se,l]),U=i.useCallback(()=>{J.current&&(cancelAnimationFrame(J.current),J.current=null)},[]),ye=i.useCallback(X=>{if(!T.current)return;const ae=X??Q.current;T.current.play(void 0,ae),p(!0),de()},[de]),Pe=i.useCallback(()=>{T.current&&(T.current.pause(),p(!1),U(),x(T.current.getCurrentTime()))},[U]),Ze=i.useCallback(()=>{T.current&&(T.current.stop(),p(!1),U(),Q.current=0,x(0),j(null))},[U,j]),Ke=i.useCallback(X=>{const ae=Math.max(0,Math.min(X,m));Q.current=ae,x(ae),T.current&&T.current.seekTo(ae)},[m]),Ve=i.useCallback(X=>{const ae=Math.max(.5,Math.min(2,X));E(ae),T.current&&T.current.setPlaybackRate(ae)},[]),He=a?30:0,nt=i.useMemo(()=>({isPlaying:h,currentTime:I,currentTimeRef:Q}),[h,I]),Ue=i.useMemo(()=>({continuousPlay:P,annotations:R,activeAnnotationId:Z,playbackRate:$,isAutomaticScroll:V}),[P,R,Z,$,V]),F=i.useRef(g);F.current=g;const Ce=i.useCallback(X=>{const ae=typeof X=="function"?X(M.current):X;if(!F.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to MediaElementPlaylistProvider to handle annotation updates.");return}F.current(ae)},[]),he=i.useMemo(()=>({play:ye,pause:Pe,stop:Ze,seekTo:Ke,setPlaybackRate:Ve,setContinuousPlay:K,setAnnotations:Ce,setActiveAnnotationId:j,setAutomaticScroll:X=>{q(X)},setScrollContainer:ne,scrollContainerRef:te}),[ye,Pe,Ze,Ke,Ve,K,Ce,j,ne]),fe=i.useMemo(()=>({duration:m,peaksDataArray:k,sampleRate:se,waveHeight:n,timeScaleHeight:He,samplesPerPixel:O,playoutRef:T,controls:l,barWidth:u,barGap:d,progressBarWidth:y}),[m,k,se,n,He,O,l,u,d,y]),Je={...Sn,...o};return b.jsx(A.ThemeProvider,{theme:Je,children:b.jsx(aa.Provider,{value:nt,children:b.jsx(ra.Provider,{value:Ue,children:b.jsx(oa.Provider,{value:he,children:b.jsx(sa.Provider,{value:fe,children:C})})})})})},At=()=>{const e=i.useContext(aa);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},St=()=>{const e=i.useContext(ra);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},Nt=()=>{const e=i.useContext(oa);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},$t=()=>{const e=i.useContext(sa);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},Bs=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Ae(),{selectionStart:a,selectionEnd:r,isLoopEnabled:s}=Se(),{play:o}=ue(),l=async()=>{if(a!==r&&r>a)if(s)await o(a);else{const u=r-a;await o(a,u)}else await o(n.current??0)};return b.jsx(Be,{onClick:l,disabled:t,className:e,children:"Play"})},Ts=({className:e})=>{const{isPlaying:t}=Ae(),{pause:n}=ue();return b.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Pause"})},Ws=({className:e})=>{const{isPlaying:t}=Ae(),{stop:n}=ue();return b.jsx(Be,{onClick:n,disabled:!t,className:e,children:"Stop"})},Fs=({className:e})=>{const{isPlaying:t}=Ae(),{play:n,setCurrentTime:a}=ue(),{playoutRef:r}=we(),s=()=>{a(0),t&&r.current&&(r.current.stop(),n(0))};return b.jsx(Be,{onClick:s,className:e,children:"Rewind"})},_s=({className:e})=>{const{isPlaying:t}=Ae(),{play:n,setCurrentTime:a}=ue(),{duration:r,playoutRef:s}=we(),o=()=>{a(r),t&&s.current&&(s.current.stop(),n(r))};return b.jsx(Be,{onClick:o,className:e,children:"Fast Forward"})},Zs=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Ae(),{play:r,setCurrentTime:s}=ue(),{playoutRef:o}=we(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),a&&o.current&&(o.current.stop(),r(c))};return b.jsx(Be,{onClick:l,className:t,children:"Skip Backward"})},Ps=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:a}=Ae(),{play:r,setCurrentTime:s}=ue(),{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 b.jsx(Be,{onClick:c,className:t,children:"Skip Forward"})},Vs=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:a}=Se(),{setLoopEnabled:r,setLoopRegion:s}=ue(),{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 b.jsx(Be,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},js=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:a,loopEnd:r}=Se(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=ue(),l=t!==n&&n>t,c=a!==r&&r>a,u=()=>{c?o():s()};return b.jsx(Be,{onClick:u,disabled:!l&&!c,className:e,title:c?"Clear loop region":l?"Set loop region from selection":"Create a selection first",children:c?"Clear Loop":"Set Loop"})},zs=({className:e,disabled:t})=>{const{zoomIn:n}=ue(),{canZoomIn:a}=we();return b.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom In"})},Hs=({className:e,disabled:t})=>{const{zoomOut:n}=ue(),{canZoomOut:a}=we();return b.jsx(Be,{variant:"success",onClick:n,disabled:t||!a,className:e,children:"Zoom Out"})},Xs=({className:e})=>{const{masterVolume:t}=we(),{setMasterVolume:n}=ue();return b.jsx(br,{volume:t,onChange:n,className:e})},Gs=({className:e})=>{const{timeFormat:t}=we(),{setTimeFormat:n}=ue();return b.jsx(Xr,{value:t,onChange:n,className:e})},Ns=A.span`
|
|
1194
1194
|
font-family: 'Courier New', Monaco, monospace;
|
|
1195
1195
|
font-size: 1rem;
|
|
1196
1196
|
font-weight: 600;
|
|
@@ -1232,7 +1232,7 @@
|
|
|
1232
1232
|
`,oi=A.div`
|
|
1233
1233
|
position: relative;
|
|
1234
1234
|
z-index: 2;
|
|
1235
|
-
`,gn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=ct(),{waveHeight:o}=lt(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=Ae(),{samplesPerPixel:v,sampleRate:g}=we(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const p=()=>{if(a.current){let I;if(l){const k=W.getContext().currentTime-(u.current??0);I=(d.current??0)+k}else I=c.current??0;const x=I*g,m=e+t;let w=0;if(x<=e)w=0;else if(x>=m)w=n.length;else{const k=x-e;w=Math.floor(k/v)}a.current.style.width=`${w}px`}l&&(r.current=requestAnimationFrame(p))};return l?r.current=requestAnimationFrame(p):p(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,g,v,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&a.current){const I=(c.current??0)*g,x=e+t;let m=0;if(I<=e)m=0;else if(I>=x)m=n.length;else{const w=I-e;m=Math.floor(w/v)}a.current.style.width=`${m}px`}});const C=s?.waveformDrawMode||"inverted";let y;C==="inverted"?y=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":y=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const h=Ye(y);return b.jsxs(ni,{children:[b.jsx(ai,{$color:h,$height:o,$top:n.index*o,$width:n.length}),b.jsx(ri,{ref:a,$color:f,$height:o,$top:n.index*o}),b.jsx(oi,{children:b.jsx(Fn,{...n,transparentBackground:!0})})]})},si=60,ia=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:r,className:s,showClipHeaders:o=!1,interactiveClips:l=!1,showFades:c=!1,touchOptimized:u=!1,recordingState:d})=>{const v=ct(),{isPlaying:g,currentTimeRef:f,playbackStartTimeRef:C,audioStartPositionRef:y}=Ae(),{selectionStart:h,selectionEnd:p,annotations:I,activeAnnotationId:x,annotationsEditable:m,linkEndpoints:w,continuousPlay:k,selectedTrackId:S,loopStart
|
|
1235
|
+
`,gn=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=ct(),{waveHeight:o}=lt(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=Ae(),{samplesPerPixel:v,sampleRate:g}=we(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const p=()=>{if(a.current){let I;if(l){const k=W.getContext().currentTime-(u.current??0);I=(d.current??0)+k}else I=c.current??0;const x=I*g,m=e+t;let w=0;if(x<=e)w=0;else if(x>=m)w=n.length;else{const k=x-e;w=Math.floor(k/v)}a.current.style.width=`${w}px`}l&&(r.current=requestAnimationFrame(p))};return l?r.current=requestAnimationFrame(p):p(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,g,v,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&a.current){const I=(c.current??0)*g,x=e+t;let m=0;if(I<=e)m=0;else if(I>=x)m=n.length;else{const w=I-e;m=Math.floor(w/v)}a.current.style.width=`${m}px`}});const C=s?.waveformDrawMode||"inverted";let y;C==="inverted"?y=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":y=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const h=Ye(y);return b.jsxs(ni,{children:[b.jsx(ai,{$color:h,$height:o,$top:n.index*o,$width:n.length}),b.jsx(ri,{ref:a,$color:f,$height:o,$top:n.index*o}),b.jsx(oi,{children:b.jsx(Fn,{...n,transparentBackground:!0})})]})},si=60,ia=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:r,className:s,showClipHeaders:o=!1,interactiveClips:l=!1,showFades:c=!1,touchOptimized:u=!1,recordingState:d})=>{const v=ct(),{isPlaying:g,currentTimeRef:f,playbackStartTimeRef:C,audioStartPositionRef:y}=Ae(),{selectionStart:h,selectionEnd:p,annotations:I,activeAnnotationId:x,annotationsEditable:m,linkEndpoints:w,continuousPlay:k,selectedTrackId:S,loopStart:$,loopEnd:E,isLoopEnabled:R}=Se(),{setAnnotations:M,setActiveAnnotationId:Z,setTrackMute:D,setTrackSolo:P,setTrackVolume:H,setTrackPan:O,setSelection:V,play:q,setScrollContainer:T,setSelectedTrackId:Q,setCurrentTime:J,setLoopRegion:oe}=ue(),{audioBuffers:ee,peaksDataArray:te,trackStates:me,tracks:Te,duration:j,samplesPerPixel:K,sampleRate:ne,waveHeight:se,timeScaleHeight:de,controls:U,playoutRef:ye,barWidth:Pe,barGap:Ze,isReady:Ke}=we(),[Ve,He]=i.useState(!1),nt=i.useRef(null),Ue=i.useCallback(_=>{nt.current=_,T(_)},[T]);let F=ee.length>0?j:si;if(d?.isRecording){const G=(d.startSample+d.durationSamples)/ne;F=Math.max(F,G+10)}const Ce=Math.floor(F*ne/K),he=async _=>{Z(_.id);const G=k?void 0:_.end-_.start;try{await q(_.start,G)}catch(re){console.error("waveform-playlist: Failed to start playback for annotation",_.id,re)}},fe=i.useCallback(_=>{if(_>=0&&_<Te.length){const G=Te[_];Q(G.id)}},[Te,Q]),Je=_=>{const G=_.currentTarget.getBoundingClientRect(),re=U.show?U.width:0,pe=(_.clientX-G.left-re)*K/ne,le=_.clientY-G.top;let _e=0,Ie=-1;for(let We=0;We<te.length;We++){const je=te[We],at=(je.length>0?Math.max(...je.map(Xe=>Xe.peaks.data.length)):1)*se+(o?22:0);if(le>=_e&&le<_e+at){Ie=We;break}_e+=at}Ie!==-1&&fe(Ie),He(!0),J(pe),V(pe,pe)},X=_=>{if(!Ve)return;const G=_.currentTarget.getBoundingClientRect(),re=U.show?U.width:0,pe=(_.clientX-G.left-re)*K/ne,ke=Math.min(h,pe),le=Math.max(h,pe);V(ke,le)},ae=_=>{if(!Ve)return;He(!1);const G=_.currentTarget.getBoundingClientRect(),re=U.show?U.width:0,pe=(_.clientX-G.left-re)*K/ne,ke=Math.min(h,pe),le=Math.max(h,pe);Math.abs(le-ke)<.1?(J(ke),g&&ye.current?(ye.current.stop(),q(ke)):ye.current&&ye.current.stop()):V(ke,le)};return Te.some(_=>_.clips.length>0)&&(ee.length===0||te.length===0)?b.jsx("div",{className:s,children:"Loading waveform..."}):b.jsx(Tn,{children:b.jsx(kt.Provider,{value:{samplesPerPixel:K,sampleRate:ne,zoomLevels:[K],waveHeight:se,timeScaleHeight:de,duration:F,controls:U,barWidth:Pe,barGap:Ze},children:b.jsx(zt,{theme:v,backgroundColor:Ye(v.waveOutlineColor),timescaleBackgroundColor:v.timescaleBackgroundColor,scrollContainerWidth:Ce+(U.show?U.width:0),timescaleWidth:Ce,tracksWidth:Ce,controlsWidth:U.show?U.width:0,onTracksMouseDown:Je,onTracksMouseMove:X,onTracksMouseUp:ae,scrollContainerRef:Ue,isSelecting:Ve,"data-playlist-state":Ke?"ready":"loading",timescale:de>0?b.jsxs(b.Fragment,{children:[b.jsx(_n,{duration:F*1e3,marker:1e4,bigStep:5e3,secondStep:1e3,renderTimestamp:t}),R&&b.jsx($r,{startPosition:Math.min($,E)*ne/K,endPosition:Math.max($,E)*ne/K,markerColor:v.loopMarkerColor,regionColor:v.loopRegionColor,minPosition:0,maxPosition:Ce,controlsOffset:U.show?U.width:0,onLoopRegionChange:(_,G)=>{const re=_*K/ne,ce=G*K/ne;oe(re,ce)}})]}):void 0,children:b.jsxs(b.Fragment,{children:[te.map((_,G)=>{const re=Te[G];if(!re)return null;const ce=me[G]||{name:`Track ${G+1}`,muted:!1,soloed:!1,volume:1,pan:0},pe=e?e(G):b.jsxs(Or,{onClick:()=>fe(G),children:[b.jsx(Kr,{style:{justifyContent:"center"},children:ce.name||`Track ${G+1}`}),b.jsxs(Yr,{children:[b.jsx(on,{$variant:ce.muted?"danger":"outline",onClick:()=>D(G,!ce.muted),children:"Mute"}),b.jsx(on,{$variant:ce.soloed?"info":"outline",onClick:()=>P(G,!ce.soloed),children:"Solo"})]}),b.jsxs(ln,{children:[b.jsx(Ur,{}),b.jsx(sn,{min:"0",max:"1",step:"0.01",value:ce.volume,onChange:le=>H(G,parseFloat(le.target.value))}),b.jsx(Jr,{})]}),b.jsxs(ln,{children:[b.jsx("span",{children:"L"}),b.jsx(sn,{min:"-1",max:"1",step:"0.01",value:ce.pan,onChange:le=>O(G,parseFloat(le.target.value))}),b.jsx("span",{children:"R"})]})]}),ke=_.length>0?Math.max(..._.map(le=>le.peaks.data.length)):1;return b.jsx(Ht.Provider,{value:pe,children:b.jsxs(Zn,{numChannels:ke,backgroundColor:Ye(v.waveOutlineColor),offset:0,width:Ce,hasClipHeaders:o,trackId:re.id,isSelected:re.id===S,children:[_.map((le,_e)=>{const Ie=le.peaks,We=Ie.length;return b.jsx(_t,{clipId:le.clipId,trackIndex:G,clipIndex:_e,trackName:le.trackName,startSample:le.startSample,durationSamples:le.durationSamples,samplesPerPixel:K,showHeader:o,disableHeaderDrag:!l,isSelected:re.id===S,trackId:re.id,fadeIn:le.fadeIn,fadeOut:le.fadeOut,sampleRate:ne,showFades:c,touchOptimized:u,onMouseDown:je=>{je.target.closest('[role="button"][aria-roledescription="draggable"]')||fe(G)},children:Ie.data.map((je,qe)=>b.jsx(gn,{index:qe,data:je,bits:Ie.bits,length:We,isSelected:re.id===S,clipStartSample:le.startSample,clipDurationSamples:le.durationSamples},`${G}-${_e}-${qe}`))},`${G}-${_e}`)}),d?.isRecording&&d.trackId===re.id&&d.peaks.length>0&&b.jsx(_t,{clipId:"recording-preview",trackIndex:G,clipIndex:_.length,trackName:"Recording...",startSample:d.startSample,durationSamples:d.durationSamples,samplesPerPixel:K,showHeader:o,disableHeaderDrag:!0,isSelected:re.id===S,trackId:re.id,children:b.jsx(gn,{index:0,data:d.peaks,bits:16,length:Math.floor(d.peaks.length/2),isSelected:re.id===S,clipStartSample:d.startSample,clipDurationSamples:d.durationSamples},`${G}-recording-0`)},`${G}-recording`)]})},re.id)}),I.length>0&&b.jsx(Gn,{height:30,width:Ce,children:I.map((_,G)=>{const re=_.start*ne/K,ce=_.end*ne/K,pe=r?r(_,G):_.id;return b.jsx(Xn,{annotationId:_.id,annotationIndex:G,startPosition:re,endPosition:ce,label:pe,color:"#ff9800",isActive:_.id===x,onClick:()=>he(_),editable:m},_.id)})}),h!==p&&b.jsx(En,{startPosition:Math.min(h,p)*ne/K+(U.show?U.width:0),endPosition:Math.max(h,p)*ne/K+(U.show?U.width:0),color:v.selectionColor}),(g||h===p)&&(n?n({position:(f.current??0)*ne/K+(U.show?U.width:0),color:v.playheadColor,isPlaying:g,currentTimeRef:f,playbackStartTimeRef:C,audioStartPositionRef:y,samplesPerPixel:K,sampleRate:ne,controlsOffset:U.show?U.width:0,getAudioContextTime:()=>W.getContext().currentTime}):b.jsx(ti,{color:v.playheadColor,controlsOffset:U.show?U.width:0}))]})})})})},la=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:a,annotationListConfig:r,scrollActivePosition:s="center",scrollActiveContainer:o="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:d,continuousPlay:v}=Se(),{setAnnotations:g}=ue(),f=r??{linkEndpoints:d,continuousPlay:v},C=i.useCallback(y=>{g(y),n?.(y)},[g,n]);return b.jsx(Nn,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:o,editable:u,controls:u?a:void 0,annotationListConfig:f,height:e,onAnnotationUpdate:C,renderAnnotationItem:t})},ii=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,annotationListConfig:r,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:d,showClipHeaders:v=!1,interactiveClips:g=!1,showFades:f=!1,touchOptimized:C=!1,recordingState:y})=>{const{annotations:h}=Se();return b.jsxs(b.Fragment,{children:[b.jsx(ia,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:a,getAnnotationBoxLabel:l,className:d,showClipHeaders:v,interactiveClips:g,showFades:f,touchOptimized:C,recordingState:y}),h.length>0&&b.jsx(la,{height:s,renderAnnotationItem:o,controls:a,annotationListConfig:r,scrollActivePosition:c,scrollActiveContainer:u})]})},li=A.div`
|
|
1236
1236
|
position: absolute;
|
|
1237
1237
|
top: 0;
|
|
1238
1238
|
left: 0;
|
|
@@ -1267,5 +1267,5 @@
|
|
|
1267
1267
|
`,mi=A.div`
|
|
1268
1268
|
position: relative;
|
|
1269
1269
|
z-index: 2;
|
|
1270
|
-
`,hi=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=ct(),{waveHeight:o}=lt(),{isPlaying:l,currentTimeRef:c}=At(),{samplesPerPixel:u,sampleRate:d}=$t(),v=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const y=()=>{if(a.current){const p=(c.current??0)*d,I=e+t;let x=0;if(p<=e)x=0;else if(p>=I)x=n.length;else{const m=p-e;x=Math.floor(m/u)}a.current.style.width=`${x}px`}l&&(r.current=requestAnimationFrame(y))};return l?r.current=requestAnimationFrame(y):y(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,d,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&a.current){const h=(c.current??0)*d,p=e+t;let I=0;if(h<=e)I=0;else if(h>=p)I=n.length;else{const x=h-e;I=Math.floor(x/u)}a.current.style.width=`${I}px`}});const g=s?.waveformDrawMode||"inverted";let f;g==="inverted"?f=s?.selectedWaveFillColor||s?.waveFillColor||"white":f=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const C=Ye(f);return b.jsxs(ui,{children:[b.jsx(di,{$color:C,$height:o,$top:n.index*o,$width:n.length}),b.jsx(fi,{ref:a,$color:v,$height:o,$top:n.index*o}),b.jsx(mi,{children:b.jsx(Fn,{...n,isSelected:!0,transparentBackground:!0})})]})},ca=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:a,className:r})=>{const s=ct(),{isPlaying:o,currentTimeRef:l}=At(),{annotations:c,activeAnnotationId:u}=St(),{play:d,seekTo:v,setActiveAnnotationId:g,setAnnotations:f,setScrollContainer:C}=
|
|
1270
|
+
`,hi=({clipStartSample:e,clipDurationSamples:t,...n})=>{const a=i.useRef(null),r=i.useRef(null),s=ct(),{waveHeight:o}=lt(),{isPlaying:l,currentTimeRef:c}=At(),{samplesPerPixel:u,sampleRate:d}=$t(),v=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const y=()=>{if(a.current){const p=(c.current??0)*d,I=e+t;let x=0;if(p<=e)x=0;else if(p>=I)x=n.length;else{const m=p-e;x=Math.floor(m/u)}a.current.style.width=`${x}px`}l&&(r.current=requestAnimationFrame(y))};return l?r.current=requestAnimationFrame(y):y(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[l,d,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&a.current){const h=(c.current??0)*d,p=e+t;let I=0;if(h<=e)I=0;else if(h>=p)I=n.length;else{const x=h-e;I=Math.floor(x/u)}a.current.style.width=`${I}px`}});const g=s?.waveformDrawMode||"inverted";let f;g==="inverted"?f=s?.selectedWaveFillColor||s?.waveFillColor||"white":f=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const C=Ye(f);return b.jsxs(ui,{children:[b.jsx(di,{$color:C,$height:o,$top:n.index*o,$width:n.length}),b.jsx(fi,{ref:a,$color:v,$height:o,$top:n.index*o}),b.jsx(mi,{children:b.jsx(Fn,{...n,isSelected:!0,transparentBackground:!0})})]})},ca=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:a,className:r})=>{const s=ct(),{isPlaying:o,currentTimeRef:l}=At(),{annotations:c,activeAnnotationId:u}=St(),{play:d,seekTo:v,setActiveAnnotationId:g,setAnnotations:f,setScrollContainer:C}=Nt(),{duration:y,peaksDataArray:h,sampleRate:p,waveHeight:I,timeScaleHeight:x,samplesPerPixel:m,controls:w,playoutRef:k,barWidth:S,barGap:$}=$t(),[E,R]=i.useState(0),[M,Z]=i.useState(0),[D,P]=i.useState(!1),H=i.useRef(null),O=i.useCallback(j=>{H.current=j,C(j)},[C]),V=Math.floor(y*p/m),q=i.useCallback(async j=>{g(j.id);try{await d(j.start)}catch(K){console.error("waveform-playlist: Failed to start playback for annotation",j.id,K)}},[g,d]),T=i.useCallback(j=>{f(j),a?.(j)},[f,a]),{onDragStart:Q,onDragMove:J,onDragEnd:oe}=Un({annotations:c,onAnnotationsChange:T,samplesPerPixel:m,sampleRate:p,duration:y,linkEndpoints:n}),ee=i.useCallback(j=>{const K=j.currentTarget.getBoundingClientRect(),ne=w.show?w.width:0,de=(j.clientX-K.left-ne)*m/p;P(!0),R(de),Z(de)},[w,m,p]),te=i.useCallback(j=>{if(!D)return;const K=j.currentTarget.getBoundingClientRect(),ne=w.show?w.width:0,de=(j.clientX-K.left-ne)*m/p;Z(de)},[D,w,m,p]),me=i.useCallback(j=>{if(!D)return;P(!1);const K=j.currentTarget.getBoundingClientRect(),ne=w.show?w.width:0,de=(j.clientX-K.left-ne)*m/p,U=Math.min(E,de),ye=Math.max(E,de);Math.abs(ye-U)<.1?(v(U),R(U),Z(U),o&&k.current&&(k.current.stop(),d(U))):(R(U),Z(ye))},[D,E,m,p,w,v,o,k,d]);if(h.length===0)return b.jsx("div",{className:r,children:"Loading waveform..."});const Te=null;return b.jsx(Tn,{children:b.jsx(kt.Provider,{value:{samplesPerPixel:m,sampleRate:p,zoomLevels:[m],waveHeight:I,timeScaleHeight:x,duration:y,controls:w,barWidth:S,barGap:$},children:b.jsx(zt,{theme:s,backgroundColor:Ye(s.waveOutlineColor),timescaleBackgroundColor:s.timescaleBackgroundColor,scrollContainerWidth:V+(w.show?w.width:0),timescaleWidth:V,tracksWidth:V,controlsWidth:w.show?w.width:0,onTracksMouseDown:ee,onTracksMouseMove:te,onTracksMouseUp:me,scrollContainerRef:O,isSelecting:D,timescale:x>0?b.jsx(_n,{duration:y*1e3,marker:1e4,bigStep:5e3,secondStep:1e3}):void 0,children:b.jsxs(b.Fragment,{children:[h.map((j,K)=>{const ne=j.length>0?Math.max(...j.map(se=>se.peaks.data.length)):1;return b.jsx(Ht.Provider,{value:Te,children:b.jsx(Zn,{numChannels:ne,backgroundColor:Ye(s.waveOutlineColor),offset:0,width:V,hasClipHeaders:!1,trackId:`media-element-track-${K}`,isSelected:!0,children:j.map((se,de)=>{const U=se.peaks,ye=U.length;return b.jsx(_t,{clipId:se.clipId,trackIndex:K,clipIndex:de,trackName:se.trackName,startSample:se.startSample,durationSamples:se.durationSamples,samplesPerPixel:m,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${K}`,children:U.data.map((Pe,Ze)=>b.jsx(hi,{index:Ze,data:Pe,bits:U.bits,length:ye,clipStartSample:se.startSample,clipDurationSamples:se.durationSamples},`${K}-${de}-${Ze}`))},`${K}-${de}`)})})},K)}),c.length>0&&b.jsx(Ee.DndContext,{onDragStart:Q,onDragMove:J,onDragEnd:oe,modifiers:t?[za.restrictToHorizontalAxis]:[],children:b.jsx(Gn,{height:30,width:V,children:c.map((j,K)=>{const ne=j.start*p/m,se=j.end*p/m,de=e?e(j,K):j.id;return b.jsx(Xn,{annotationId:j.id,annotationIndex:K,startPosition:ne,endPosition:se,label:de,color:"#ff9800",isActive:j.id===u,onClick:()=>q(j),editable:t},j.id)})})}),E!==M&&b.jsx(En,{startPosition:Math.min(E,M)*p/m+(w.show?w.width:0),endPosition:Math.max(E,M)*p/m+(w.show?w.width:0),color:s.selectionColor}),b.jsx(ci,{color:s.playheadColor,controlsOffset:w.show?w.width:0})]})})})})},ua=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,editable:a=!1,controls:r,annotationListConfig:s,scrollActivePosition:o="center",scrollActiveContainer:l="nearest"})=>{const{annotations:c,activeAnnotationId:u,continuousPlay:d}=St(),{setAnnotations:v}=Nt(),g=s??{linkEndpoints:!1,continuousPlay:d},f=i.useCallback(C=>{v(C),n?.(C)},[v,n]);return b.jsx(Nn,{annotations:c,activeAnnotationId:u??void 0,shouldScrollToActive:!0,scrollActivePosition:o,scrollActiveContainer:l,editable:a,controls:a?r:void 0,annotationListConfig:g,height:e,onAnnotationUpdate:f,renderAnnotationItem:t})},pi=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:a=!1,linkEndpoints:r=!1,onAnnotationUpdate:s,scrollActivePosition:o="center",scrollActiveContainer:l="nearest",className:c})=>{const{annotations:u}=St();return b.jsxs(b.Fragment,{children:[b.jsx(ca,{getAnnotationBoxLabel:t,editable:a,linkEndpoints:r,onAnnotationUpdate:s,className:c}),u.length>0&&b.jsx(ua,{height:e,renderAnnotationItem:n,onAnnotationUpdate:s,editable:a,annotationListConfig:{linkEndpoints:r,continuousPlay:!1},scrollActivePosition:o,scrollActiveContainer:l})]})};exports.Tone=vn;exports.AudioPosition=Ls;exports.AutomaticScrollCheckbox=Os;exports.ContinuousPlayCheckbox=Ks;exports.DownloadAnnotationsButton=qs;exports.EditableCheckbox=Js;exports.ExportWavButton=Qs;exports.FastForwardButton=_s;exports.LinkEndpointsCheckbox=Us;exports.LoopButton=Vs;exports.MasterVolumeControl=Xs;exports.MediaElementAnnotationList=ua;exports.MediaElementPlaylist=ca;exports.MediaElementPlaylistProvider=Ds;exports.MediaElementWaveform=pi;exports.PauseButton=Ts;exports.PlayButton=Bs;exports.PlaylistAnnotationList=la;exports.PlaylistVisualization=ia;exports.RewindButton=Fs;exports.SelectionTimeInputs=Ys;exports.SetLoopRegionButton=js;exports.SkipBackwardButton=Zs;exports.SkipForwardButton=Ps;exports.StopButton=Ws;exports.TimeFormatSelect=Gs;exports.Waveform=ii;exports.WaveformPlaylistProvider=$s;exports.ZoomInButton=zs;exports.ZoomOutButton=Hs;exports.createEffectChain=Cs;exports.createEffectInstance=it;exports.effectCategories=ps;exports.effectDefinitions=ut;exports.getEffectDefinition=Gt;exports.getEffectsByCategory=hs;exports.getShortcutLabel=qo;exports.getWaveformDataMetadata=xo;exports.loadPeaksFromWaveformData=Co;exports.loadWaveformData=Xt;exports.useAnnotationDragHandlers=Un;exports.useAnnotationKeyboardControls=es;exports.useAudioTracks=Yo;exports.useClipDragHandlers=Oo;exports.useClipSplitting=Jo;exports.useDragSensors=Uo;exports.useDynamicEffects=xs;exports.useExportWav=Jn;exports.useIntegratedRecording=ms;exports.useKeyboardShortcuts=Ct;exports.useMasterAnalyser=Go;exports.useMasterVolume=On;exports.useMediaElementAnimation=At;exports.useMediaElementControls=Nt;exports.useMediaElementData=$t;exports.useMediaElementState=St;exports.usePlaybackAnimation=Ae;exports.usePlaybackShortcuts=Qo;exports.usePlaylistControls=ue;exports.usePlaylistData=we;exports.usePlaylistState=Se;exports.useTimeFormat=Ln;exports.useTrackDynamicEffects=ws;exports.useWaveformPlaylist=Ms;exports.useZoomControls=Yn;exports.waveformDataToPeaks=jn;
|
|
1271
1271
|
//# sourceMappingURL=index.js.map
|