@waveform-playlist/browser 5.2.0 → 5.3.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 +149 -0
- package/dist/index.js +179 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3191 -2584
- 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 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`
|
|
1
|
+
"use strict";var Gr=Object.create;var sn=Object.defineProperty;var Nr=Object.getOwnPropertyDescriptor;var Or=Object.getOwnPropertyNames;var Yr=Object.getPrototypeOf,Kr=Object.prototype.hasOwnProperty;var Ur=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Or(t))!Kr.call(e,a)&&a!==n&&sn(e,a,{get:()=>t[a],enumerable:!(r=Nr(t,a))||r.enumerable});return e};var Jr=(e,t,n)=>(n=e!=null?Gr(Yr(e)):{},Ur(t||!e||!e.__esModule?sn(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("tone"),h=require("react/jsx-runtime"),i=require("react"),$=require("styled-components"),_e=require("@dnd-kit/core"),Rn=require("react-dom"),qr=require("@dnd-kit/modifiers");var Vt=typeof document<"u"?document.currentScript:null;function Dn(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const Tn=Dn(Z),D=Dn(i);function ln(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r;n[a]=t?s:1-s}return n}function Qr(e,t){const n=new Float32Array(e),r=e-1;for(let a=0;a<e;a++){const s=a/r,o=t?a:e-1-a;n[o]=Math.exp(2*s-1)/Math.E}return n}function ea(e,t){const n=new Float32Array(e),r=t?Math.PI/2:-Math.PI/2;for(let a=0;a<e;a++)n[a]=Math.sin(Math.PI*a/e-r)/2+.5;return n}function ta(e,t,n=10){const r=new Float32Array(e);for(let a=0;a<e;a++){const s=t?a:e-1-a,o=a/e;r[s]=Math.log(1+n*o)/Math.log(1+n)}return r}function Bn(e,t,n){switch(e){case"linear":return ln(t,n);case"exponential":return Qr(t,n);case"sCurve":return ea(t,n);case"logarithmic":return ta(t,n);default:return ln(t,n)}}function cn(e,t,n,r="linear",a=0,s=1){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=Bn(r,1e4,!0),l=new Float32Array(o.length),c=s-a;for(let u=0;u<o.length;u++)l[u]=a+o[u]*c;e.setValueCurveAtTime(l,t,n)}}function un(e,t,n,r="linear",a=1,s=0){if(!(n<=0))if(r==="linear")e.setValueAtTime(a,t),e.linearRampToValueAtTime(s,t+n);else if(r==="exponential")e.setValueAtTime(Math.max(a,.001),t),e.exponentialRampToValueAtTime(Math.max(s,.001),t+n);else{const o=Bn(r,1e4,!1),l=new Float32Array(o.length),c=a-s;for(let u=0;u<o.length;u++)l[u]=s+o[u]*c;e.setValueCurveAtTime(l,t,n)}}var na=class{constructor(e){this.activePlayers=0,this.track=e.track,this.volumeNode=new Z.Volume(this.gainToDb(e.track.gain)),this.panNode=new Z.Panner(e.track.stereoPan),this.muteGain=new Z.Gain(e.track.muted?0:1);const t=e.destination||Z.getDestination();if(e.effects){const r=e.effects(this.muteGain,t,!1);r&&(this.effectsCleanup=r)}else this.muteGain.connect(t);const n=e.clips||(e.buffer?[{buffer:e.buffer,startTime:0,duration:e.buffer.duration,offset:0,fadeIn:e.track.fadeIn,fadeOut:e.track.fadeOut,gain:1}]:[]);this.clips=n.map(r=>{const a=new Z.Player({url:r.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}}),s=new Z.Gain(r.gain);return a.connect(s),s.chain(this.volumeNode,this.panNode,this.muteGain),{player:a,clipInfo:r,fadeGain:s,pausedPosition:0,playStartTime:0}})}scheduleFades(e,t,n=0){const{clipInfo:r,fadeGain:a}=e,s=a.gain._param;s.cancelScheduledValues(0);const o=n-r.offset;if(r.fadeIn&&o<r.fadeIn.duration){const l=r.fadeIn.duration;if(o<=0)cn(s,t,l,r.fadeIn.type||"linear",0,r.gain);else{const c=l-o,u=o/l,d=r.gain*u;cn(s,t,c,r.fadeIn.type||"linear",d,r.gain)}}else s.setValueAtTime(r.gain,t);if(r.fadeOut){const c=r.duration-r.fadeOut.duration-o;if(c>0){const u=t+c;un(s,u,r.fadeOut.duration,r.fadeOut.type||"linear",r.gain,0)}else if(c>-r.fadeOut.duration){const u=-c,d=r.fadeOut.duration-u,v=u/r.fadeOut.duration,p=r.gain*(1-v);un(s,t,d,r.fadeOut.type||"linear",p,0)}}}gainToDb(e){return 20*Math.log10(e)}setVolume(e){this.track.gain=e,this.volumeNode.volume.value=this.gainToDb(e)}setPan(e){this.track.stereoPan=e,this.panNode.pan.value=e}setMute(e){this.track.muted=e;const t=e?0:1;this.muteGain.gain._param.setValueAtTime(t,0),this.muteGain.gain.value=t}setSolo(e){this.track.soloed=e}play(e,t=0,n){this.clips.forEach(r=>{r.player.stop(),r.player.disconnect(),r.player.dispose();const a=new Z.Player({url:r.clipInfo.buffer,loop:!1,onstop:()=>{this.activePlayers--,this.activePlayers===0&&this.onStopCallback&&this.onStopCallback()}});a.connect(r.fadeGain),r.player=a,r.pausedPosition=0}),this.activePlayers=0,this.clips.forEach(r=>{const{player:a,clipInfo:s}=r,o=t,l=s.startTime,c=s.startTime+s.duration;if(o<c){this.activePlayers++;const u=e??Z.now();if(r.playStartTime=u,o>=l){const d=o-l+s.offset,v=s.duration-(o-l),p=n?Math.min(n,v):v;r.pausedPosition=d,this.scheduleFades(r,u,d),a.start(u,d,p)}else{const d=l-o,v=n?Math.min(n-d,s.duration):s.duration;d<(n??1/0)?(r.pausedPosition=s.offset,this.scheduleFades(r,u+d,s.offset),a.start(u+d,s.offset,v)):this.activePlayers--}}})}pause(){this.clips.forEach(e=>{if(e.player.state==="started"){const t=(Z.now()-e.playStartTime)*e.player.playbackRate;e.pausedPosition=e.pausedPosition+t}e.player.stop()}),this.activePlayers=0}stop(e){const t=e??Z.now();this.clips.forEach(n=>{n.player.stop(t),n.pausedPosition=0}),this.activePlayers=0}dispose(){this.effectsCleanup&&this.effectsCleanup(),this.clips.forEach(e=>{e.player.dispose(),e.fadeGain.dispose()}),this.volumeNode.dispose(),this.panNode.dispose(),this.muteGain.dispose()}get id(){return this.track.id}get duration(){if(this.clips.length===0)return 0;const e=this.clips[this.clips.length-1];return e.clipInfo.startTime+e.clipInfo.duration}get buffer(){return this.clips[0]?.clipInfo.buffer}get isPlaying(){return this.clips.some(e=>e.player.state==="started")}get muted(){return this.track.muted}get startTime(){return this.track.startTime}setOnStopCallback(e){this.onStopCallback=e}},ra=class{constructor(e={}){if(this.tracks=new Map,this.isInitialized=!1,this.soloedTracks=new Set,this.manualMuteState=new Map,this.activeTracks=new Map,this.playbackSessionId=0,this.masterVolume=new Z.Volume(this.gainToDb(e.masterGain??1)),e.effects){const t=e.effects(this.masterVolume,Z.getDestination(),!1);t&&(this.effectsCleanup=t)}else this.masterVolume.toDestination();e.tracks&&e.tracks.forEach(t=>{this.tracks.set(t.id,t),this.manualMuteState.set(t.id,t.muted)})}gainToDb(e){return 20*Math.log10(e)}async init(){this.isInitialized||(await Z.start(),this.isInitialized=!0)}addTrack(e){const t={...e,destination:this.masterVolume},n=new 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 r=e??Z.now(),a=t??0;this.playbackSessionId++;const s=this.playbackSessionId;this.activeTracks.clear(),this.tracks.forEach(o=>{const l=o.startTime;if(a>=l){const c=a-l;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r,c,n)}else{const c=l-a;n!==void 0&&(this.activeTracks.set(o.id,s),o.setOnStopCallback(()=>{this.activeTracks.get(o.id)===s&&(this.activeTracks.delete(o.id),this.activeTracks.size===0&&this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())})),o.play(r+c,0,n)}}),t!==void 0?Z.getTransport().start(r,t):Z.getTransport().start(r)}pause(){Z.getTransport().pause(),this.tracks.forEach(e=>{e.pause()})}stop(){Z.getTransport().stop(),this.tracks.forEach(e=>{e.stop()})}setMasterGain(e){this.masterVolume.volume.value=this.gainToDb(e)}setSolo(e,t){const n=this.tracks.get(e);n&&(n.setSolo(t),t?this.soloedTracks.add(e):this.soloedTracks.delete(e),this.updateSoloMuting())}updateSoloMuting(){const e=this.soloedTracks.size>0;this.tracks.forEach((t,n)=>{if(e)if(!this.soloedTracks.has(n))t.setMute(!0);else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}else{const r=this.manualMuteState.get(n)??!1;t.setMute(r)}})}setMute(e,t){const n=this.tracks.get(e);n&&(this.manualMuteState.set(e,t),n.setMute(t))}getCurrentTime(){return Z.getTransport().seconds}seekTo(e){Z.getTransport().seconds=e}dispose(){this.tracks.forEach(e=>{e.dispose()}),this.tracks.clear(),this.effectsCleanup&&this.effectsCleanup(),this.masterVolume.dispose()}get context(){return Z.getContext()}get sampleRate(){return Z.getContext().sampleRate}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}},yt=null;function aa(){return yt||(yt=new Z.Context,Z.setContext(yt)),yt}async function jt(){const e=aa();e.state!=="running"&&await e.resume()}const Xt=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[Xt.Translate.toString(e),Xt.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),oa=new Map([["bold",D.createElement(D.Fragment,null,D.createElement("path",{d:"M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128ZM60,112a16,16,0,1,0,16,16A16,16,0,0,0,60,112Zm136,0a16,16,0,1,0,16,16A16,16,0,0,0,196,112Z"}))],["duotone",D.createElement(D.Fragment,null,D.createElement("path",{d:"M240,96v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V96A16,16,0,0,1,32,80H224A16,16,0,0,1,240,96Z",opacity:"0.2"}),D.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["fill",D.createElement(D.Fragment,null,D.createElement("path",{d:"M224,80H32A16,16,0,0,0,16,96v64a16,16,0,0,0,16,16H224a16,16,0,0,0,16-16V96A16,16,0,0,0,224,80ZM60,140a12,12,0,1,1,12-12A12,12,0,0,1,60,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,128,140Zm68,0a12,12,0,1,1,12-12A12,12,0,0,1,196,140Z"}))],["light",D.createElement(D.Fragment,null,D.createElement("path",{d:"M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128ZM60,118a10,10,0,1,0,10,10A10,10,0,0,0,60,118Zm136,0a10,10,0,1,0,10,10A10,10,0,0,0,196,118Z"}))],["regular",D.createElement(D.Fragment,null,D.createElement("path",{d:"M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Zm56-12a12,12,0,1,0,12,12A12,12,0,0,0,196,116ZM60,116a12,12,0,1,0,12,12A12,12,0,0,0,60,116Z"}))],["thin",D.createElement(D.Fragment,null,D.createElement("path",{d:"M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Zm-76-8a8,8,0,1,0,8,8A8,8,0,0,0,60,120Zm136,0a8,8,0,1,0,8,8A8,8,0,0,0,196,120Z"}))]]),sa=new Map([["bold",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),D.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",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.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"}))]]),ia=new Map([["bold",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.createElement("path",{d:"M80,88v80H32a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8Z",opacity:"0.2"}),D.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",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.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",D.createElement(D.Fragment,null,D.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"}))]]),la=new Map([["bold",D.createElement(D.Fragment,null,D.createElement("path",{d:"M208.49,191.51a12,12,0,0,1-17,17L128,145,64.49,208.49a12,12,0,0,1-17-17L111,128,47.51,64.49a12,12,0,0,1,17-17L128,111l63.51-63.52a12,12,0,0,1,17,17L145,128Z"}))],["duotone",D.createElement(D.Fragment,null,D.createElement("path",{d:"M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z",opacity:"0.2"}),D.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["fill",D.createElement(D.Fragment,null,D.createElement("path",{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM181.66,170.34a8,8,0,0,1-11.32,11.32L128,139.31,85.66,181.66a8,8,0,0,1-11.32-11.32L116.69,128,74.34,85.66A8,8,0,0,1,85.66,74.34L128,116.69l42.34-42.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["light",D.createElement(D.Fragment,null,D.createElement("path",{d:"M204.24,195.76a6,6,0,1,1-8.48,8.48L128,136.49,60.24,204.24a6,6,0,0,1-8.48-8.48L119.51,128,51.76,60.24a6,6,0,0,1,8.48-8.48L128,119.51l67.76-67.75a6,6,0,0,1,8.48,8.48L136.49,128Z"}))],["regular",D.createElement(D.Fragment,null,D.createElement("path",{d:"M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"}))],["thin",D.createElement(D.Fragment,null,D.createElement("path",{d:"M202.83,197.17a4,4,0,0,1-5.66,5.66L128,133.66,58.83,202.83a4,4,0,0,1-5.66-5.66L122.34,128,53.17,58.83a4,4,0,0,1,5.66-5.66L128,122.34l69.17-69.17a4,4,0,1,1,5.66,5.66L133.66,128Z"}))]]),ca=i.createContext({color:"currentColor",size:"1em",weight:"regular",mirrored:!1}),pt=D.forwardRef((e,t)=>{const{alt:n,color:r,size:a,weight:s,mirrored:o,children:l,weights:c,...u}=e,{color:d="currentColor",size:v,weight:p="regular",mirrored:f=!1,...C}=D.useContext(ca);return D.createElement("svg",{ref:t,xmlns:"http://www.w3.org/2000/svg",width:a??v,height:a??v,fill:r??d,viewBox:"0 0 256 256",transform:o||f?"scale(-1, 1)":void 0,...C,...u},!!n&&D.createElement("title",null,n),l,c.get(s??p))});pt.displayName="IconBase";const Wn=D.forwardRef((e,t)=>D.createElement(pt,{ref:t,...e,weights:oa}));Wn.displayName="DotsThreeIcon";const Fn=D.forwardRef((e,t)=>D.createElement(pt,{ref:t,...e,weights:sa}));Fn.displayName="SpeakerHighIcon";const _n=D.forwardRef((e,t)=>D.createElement(pt,{ref:t,...e,weights:ia}));_n.displayName="SpeakerLowIcon";const Zn=D.forwardRef((e,t)=>D.createElement(pt,{ref:t,...e,weights:la}));Zn.displayName="XIcon";const ua=Zn;$.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 Ot=$.button`
|
|
8
8
|
display: inline-flex;
|
|
9
9
|
align-items: center;
|
|
10
10
|
justify-content: center;
|
|
@@ -33,37 +33,37 @@
|
|
|
33
33
|
opacity: 0.6;
|
|
34
34
|
cursor: not-allowed;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
`;$(Ot)`
|
|
37
37
|
padding: 0.25rem 0.5rem;
|
|
38
38
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
39
|
-
|
|
39
|
+
`;$(Ot)`
|
|
40
40
|
padding: 0.5rem;
|
|
41
41
|
min-width: 2.25rem;
|
|
42
42
|
min-height: 2.25rem;
|
|
43
|
-
|
|
43
|
+
`;$(Ot)`
|
|
44
44
|
padding: 0.25rem;
|
|
45
45
|
min-width: 1.75rem;
|
|
46
46
|
min-height: 1.75rem;
|
|
47
47
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
48
|
-
`;var
|
|
48
|
+
`;var Et=$.div`
|
|
49
49
|
display: inline-flex;
|
|
50
50
|
align-items: center;
|
|
51
51
|
gap: 0.5rem;
|
|
52
|
-
`,
|
|
52
|
+
`,Rt=$.input`
|
|
53
53
|
cursor: pointer;
|
|
54
54
|
accent-color: ${e=>e.theme.inputFocusBorder};
|
|
55
55
|
|
|
56
56
|
&:disabled {
|
|
57
57
|
cursor: not-allowed;
|
|
58
58
|
}
|
|
59
|
-
`,
|
|
59
|
+
`,Dt=$.label`
|
|
60
60
|
margin: 0;
|
|
61
61
|
cursor: pointer;
|
|
62
62
|
user-select: none;
|
|
63
63
|
font-family: ${e=>e.theme.fontFamily};
|
|
64
64
|
font-size: ${e=>e.theme.fontSize};
|
|
65
65
|
color: ${e=>e.theme.textColor};
|
|
66
|
-
`,
|
|
66
|
+
`,je=$.button`
|
|
67
67
|
padding: 0.5rem 1rem;
|
|
68
68
|
background: ${e=>e.theme.buttonBackground||"#007bff"};
|
|
69
69
|
color: ${e=>e.theme.buttonText||"white"};
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
cursor: not-allowed;
|
|
90
90
|
opacity: 0.6;
|
|
91
91
|
}
|
|
92
|
-
`,
|
|
92
|
+
`,Pn=$.input`
|
|
93
93
|
padding: 0.5rem 0.75rem;
|
|
94
94
|
font-family: ${e=>e.theme.fontFamily};
|
|
95
95
|
font-size: ${e=>e.theme.fontSize};
|
|
@@ -113,17 +113,17 @@
|
|
|
113
113
|
opacity: 0.6;
|
|
114
114
|
cursor: not-allowed;
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
`;$(Pn)`
|
|
117
117
|
padding: 0.25rem 0.5rem;
|
|
118
118
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
119
|
-
`;var
|
|
119
|
+
`;var Vn=$.label`
|
|
120
120
|
font-family: ${e=>e.theme.fontFamily};
|
|
121
121
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
122
122
|
font-weight: 500;
|
|
123
123
|
color: ${e=>e.theme.textColorMuted};
|
|
124
124
|
margin-bottom: 0.25rem;
|
|
125
125
|
display: block;
|
|
126
|
-
|
|
126
|
+
`;$.label`
|
|
127
127
|
font-family: ${e=>e.theme.fontFamily};
|
|
128
128
|
font-size: ${e=>e.theme.fontSize};
|
|
129
129
|
color: ${e=>e.theme.textColor};
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
align-items: center;
|
|
132
132
|
gap: 0.5rem;
|
|
133
133
|
cursor: pointer;
|
|
134
|
-
`;var
|
|
134
|
+
`;var da=$.span`
|
|
135
135
|
position: absolute;
|
|
136
136
|
width: 1px;
|
|
137
137
|
height: 1px;
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
clip: rect(0, 0, 0, 0);
|
|
142
142
|
white-space: nowrap;
|
|
143
143
|
border: 0;
|
|
144
|
-
`,
|
|
144
|
+
`,Yt=$.select`
|
|
145
145
|
padding: 0.5rem 2rem 0.5rem 0.75rem;
|
|
146
146
|
font-family: ${e=>e.theme.fontFamily};
|
|
147
147
|
font-size: ${e=>e.theme.fontSize};
|
|
@@ -172,10 +172,10 @@
|
|
|
172
172
|
color: ${e=>e.theme.inputText};
|
|
173
173
|
background-color: ${e=>e.theme.inputBackground};
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
`;$(Yt)`
|
|
176
176
|
padding: 0.25rem 1.75rem 0.25rem 0.5rem;
|
|
177
177
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
178
|
-
`;var
|
|
178
|
+
`;var jn=$.input.attrs({type:"range"})`
|
|
179
179
|
-webkit-appearance: none;
|
|
180
180
|
appearance: none;
|
|
181
181
|
width: 100%;
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
&:disabled::-moz-range-thumb {
|
|
252
252
|
cursor: not-allowed;
|
|
253
253
|
}
|
|
254
|
-
`,
|
|
254
|
+
`,fa=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return h.jsxs(Et,{className:r,children:[h.jsx(Rt,{type:"checkbox",id:"automatic-scroll",className:"automatic-scroll",checked:e,onChange:a,disabled:n}),h.jsx(Dt,{htmlFor:"automatic-scroll",children:"Automatic Scroll"})]})};function zn(e){return typeof e=="object"&&e!==null&&"type"in e}function Qe(e){if(!zn(e))return e;const t=e.direction==="vertical"?"to bottom":"to right",n=e.stops.map(r=>`${r.color} ${r.offset*100}%`).join(", ");return`linear-gradient(${t}, ${n})`}var Hn={waveformDrawMode:"inverted",waveOutlineColor:"#ffffff",waveFillColor:"#1a7f8e",waveProgressColor:"rgba(0, 0, 0, 0.10)",selectedWaveOutlineColor:"#ffffff",selectedWaveFillColor:"#00b4d8",selectedTrackControlsBackground:"#d9e9ff",timeColor:"#000",timescaleBackgroundColor:"#fff",playheadColor:"#f00",selectionColor:"rgba(255, 105, 180, 0.7)",loopRegionColor:"rgba(59, 130, 246, 0.3)",loopMarkerColor:"#3b82f6",clipHeaderBackgroundColor:"rgba(0, 0, 0, 0.1)",clipHeaderBorderColor:"rgba(0, 0, 0, 0.2)",clipHeaderTextColor:"#333",clipHeaderFontFamily:"inherit",selectedClipHeaderBackgroundColor:"#b3d9ff",fadeOverlayColor:"rgba(0, 0, 0, 0.4)",backgroundColor:"#ffffff",surfaceColor:"#f5f5f5",borderColor:"#ddd",textColor:"#333",textColorMuted:"#666",inputBackground:"#ffffff",inputBorder:"#ccc",inputText:"#333",inputPlaceholder:"#999",inputFocusBorder:"#0066cc",buttonBackground:"#0091ff",buttonText:"#ffffff",buttonBorder:"#0081e6",buttonHoverBackground:"#0081e6",sliderTrackColor:"#ddd",sliderThumbColor:"#daa520",annotationBoxBackground:"rgba(255, 255, 255, 0.85)",annotationBoxActiveBackground:"rgba(255, 255, 255, 0.95)",annotationBoxHoverBackground:"rgba(255, 255, 255, 0.98)",annotationBoxBorder:"#ff9800",annotationBoxActiveBorder:"#d67600",annotationLabelColor:"#2a2a2a",annotationResizeHandleColor:"rgba(0, 0, 0, 0.4)",annotationResizeHandleActiveColor:"rgba(0, 0, 0, 0.8)",annotationTextItemHoverBackground:"rgba(0, 0, 0, 0.03)",borderRadius:"4px",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif',fontSize:"14px",fontSizeSmall:"12px"},ma=1e3;function ha(e,t,n,r){if(!zn(t))return t;let a;t.direction==="vertical"?a=e.createLinearGradient(0,0,0,r):a=e.createLinearGradient(0,0,n,0);for(const s of t.stops)a.addColorStop(s.offset,s.color);return a}var pa=$.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
255
255
|
float: left;
|
|
256
256
|
position: relative;
|
|
257
257
|
/* Promote to own compositing layer for smoother scrolling */
|
|
@@ -259,15 +259,15 @@
|
|
|
259
259
|
/* Disable image rendering interpolation */
|
|
260
260
|
image-rendering: pixelated;
|
|
261
261
|
image-rendering: crisp-edges;
|
|
262
|
-
`,
|
|
262
|
+
`,ga=$.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
263
263
|
position: absolute;
|
|
264
264
|
background: ${e=>e.$waveFillColor};
|
|
265
265
|
/* Force GPU compositing layer to reduce scroll flickering */
|
|
266
266
|
transform: translateZ(0);
|
|
267
267
|
backface-visibility: hidden;
|
|
268
|
-
`,
|
|
268
|
+
`,dn=e=>{const{data:t,bits:n,length:r,index:a,className:s,devicePixelRatio:o=1,waveHeight:l=80,waveOutlineColor:c="#E0EFF1",waveFillColor:u="grey",barWidth:d=1,barGap:v=0,transparentBackground:p=!1,drawMode:f="inverted"}=e,C=i.useRef([]),x=i.useCallback(y=>{if(y!==null){const k=parseInt(y.dataset.index,10);C.current[k]=y}},[]);i.useLayoutEffect(()=>{const y=C.current,k=d+v;let I=0;for(let A=0;A<y.length;A++){const R=y[A],E=R.getContext("2d"),M=Math.floor(l/2),F=2**(n-1);if(E){E.resetTransform(),E.clearRect(0,0,R.width,R.height),E.imageSmoothingEnabled=!1,E.scale(o,o);const T=R.width/o;let P;f==="normal"?P=u:P=c,E.fillStyle=ha(E,P,T,l);const H=I,O=I+T,j=Math.floor((H-d+k)/k)*k;for(let L=Math.max(0,j);L<O;L+=k){const B=L-H;if(B+d<=0)continue;const q=L;if(q*2+1<t.length){const U=t[q*2]/F,ie=t[q*2+1]/F,te=Math.abs(U*M),Q=Math.abs(ie*M);f==="normal"?E.fillRect(B,M-Q,d,Q+te):(E.fillRect(B,0,d,M-Q),E.fillRect(B,M+te,d,M-te))}}}I+=R.width/o}},[t,n,l,c,u,o,r,d,v,f]);let b=r,g=0;const S=[];for(;b>0;){const y=Math.min(b,ma),k=h.jsx(pa,{$cssWidth:y,width:y*o,height:l*o,$waveHeight:l,"data-index":g,ref:x},`${r}-${g}`);S.push(k),b-=y,g+=1}const m=p?"transparent":Qe(u);return h.jsx(ga,{$index:a,$cssWidth:r,className:s,$waveHeight:l,$waveFillColor:m,children:S})},Ln=22,Xn=$.div`
|
|
269
269
|
position: relative;
|
|
270
|
-
height: ${
|
|
270
|
+
height: ${Ln}px;
|
|
271
271
|
background: ${e=>e.$isSelected?e.theme.selectedClipHeaderBackgroundColor:e.theme.clipHeaderBackgroundColor};
|
|
272
272
|
border-bottom: 1px solid ${e=>e.theme.clipHeaderBorderColor};
|
|
273
273
|
display: flex;
|
|
@@ -289,7 +289,7 @@
|
|
|
289
289
|
cursor: grabbing;
|
|
290
290
|
}
|
|
291
291
|
`}
|
|
292
|
-
`,
|
|
292
|
+
`,Gn=$.span`
|
|
293
293
|
font-size: 11px;
|
|
294
294
|
font-weight: 600;
|
|
295
295
|
font-family: ${e=>e.theme.clipHeaderFontFamily};
|
|
@@ -297,12 +297,12 @@
|
|
|
297
297
|
white-space: nowrap;
|
|
298
298
|
overflow: hidden;
|
|
299
299
|
text-overflow: ellipsis;
|
|
300
|
-
`,
|
|
300
|
+
`,ba=({trackName:e,isSelected:t=!1})=>h.jsx(Xn,{$isDragging:!1,$interactive:!1,$isSelected:t,children:h.jsx(Gn,{children:e})}),va=({clipId:e,trackIndex:t,clipIndex:n,trackName:r,isSelected:a=!1,disableDrag:s=!1,dragHandleProps:o})=>{if(s||!o)return h.jsx(ba,{trackName:r,isSelected:a});const{attributes:l,listeners:c,setActivatorNodeRef:u}=o;return h.jsx(Xn,{ref:u,"data-clip-id":e,$interactive:!0,$isSelected:a,...c,...l,children:h.jsx(Gn,{children:r})})},Ca=8,xa=24,wa=$.div`
|
|
301
301
|
position: absolute;
|
|
302
302
|
${e=>e.$edge==="left"?"left: 0;":"right: 0;"}
|
|
303
303
|
top: 0;
|
|
304
304
|
bottom: 0;
|
|
305
|
-
width: ${e=>e.$touchOptimized?
|
|
305
|
+
width: ${e=>e.$touchOptimized?xa:Ca}px;
|
|
306
306
|
cursor: col-resize;
|
|
307
307
|
user-select: none;
|
|
308
308
|
z-index: 105; /* Above waveform, below header */
|
|
@@ -325,19 +325,19 @@
|
|
|
325
325
|
background: rgba(255, 255, 255, 0.4);
|
|
326
326
|
${e=>e.$edge==="left"?"border-left: 2px solid rgba(255, 255, 255, 0.8);":"border-right: 2px solid rgba(255, 255, 255, 0.8);"}
|
|
327
327
|
}
|
|
328
|
-
`,
|
|
328
|
+
`,fn=({clipId:e,trackIndex:t,clipIndex:n,edge:r,dragHandleProps:a,touchOptimized:s=!1})=>{const[o,l]=i.useState(!1);if(!a)return null;const{attributes:c,listeners:u,setActivatorNodeRef:d,isDragging:v}=a;return h.jsx(wa,{ref:d,"data-clip-id":e,"data-boundary-edge":r,$edge:r,$isDragging:v,$isHovered:o,$touchOptimized:s,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),...u,...c})},ya=$.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
329
329
|
position: absolute;
|
|
330
330
|
top: 0;
|
|
331
331
|
bottom: 0;
|
|
332
332
|
pointer-events: none;
|
|
333
333
|
z-index: 50;
|
|
334
|
-
`,
|
|
334
|
+
`,ka=$.svg`
|
|
335
335
|
width: 100%;
|
|
336
336
|
height: 100%;
|
|
337
337
|
display: block;
|
|
338
338
|
/* Flip horizontally for fadeOut - makes it mirror of fadeIn */
|
|
339
339
|
transform: ${e=>e.$type==="fadeOut"?"scaleX(-1)":"none"};
|
|
340
|
-
`;function
|
|
340
|
+
`;function Sa(e,t,n="logarithmic"){const r=[],a=Math.max(20,Math.min(e,100));for(let s=0;s<=a;s++){const o=s/a*e,l=s/a;let c;switch(n){case"linear":c=l;break;case"exponential":c=l*l;break;case"sCurve":c=(1-Math.cos(l*Math.PI))/2;break;case"logarithmic":default:c=Math.log10(1+l*9)/Math.log10(10);break}const u=(1-c)*t;r.push(`${o},${u}`)}return`M 0,${t} L ${r.join(" L ")} L ${e},0 L 0,0 Z`}var mn=({left:e,width:t,type:n,curveType:r="logarithmic",color:a})=>{const s=$.useTheme();if(t<1)return null;const o=a||s?.fadeOverlayColor||"rgba(0, 0, 0, 0.4)";return h.jsx(ya,{$left:e,$width:t,$type:n,children:h.jsx(ka,{$type:n,viewBox:`0 0 ${t} 100`,preserveAspectRatio:"none",children:h.jsx("path",{d:Sa(t,100,r),fill:o})})})},Aa=$.div.attrs(e=>({style:e.$isOverlay?{}:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
341
341
|
position: ${e=>e.$isOverlay?"relative":"absolute"};
|
|
342
342
|
top: 0;
|
|
343
343
|
height: ${e=>e.$isOverlay?"auto":"100%"};
|
|
@@ -351,20 +351,20 @@
|
|
|
351
351
|
&:hover {
|
|
352
352
|
background: rgba(255, 255, 255, 0.08);
|
|
353
353
|
}
|
|
354
|
-
`,
|
|
354
|
+
`,Ia=$.div`
|
|
355
355
|
flex: 1;
|
|
356
356
|
position: relative;
|
|
357
357
|
overflow: ${e=>e.$isOverlay?"visible":"hidden"};
|
|
358
|
-
`,
|
|
358
|
+
`,Gt=({children:e,className:t,clipId:n,trackIndex:r,clipIndex:a,trackName:s,startSample:o,durationSamples:l,samplesPerPixel:c,showHeader:u=!1,disableHeaderDrag:d=!1,isOverlay:v=!1,isSelected:p=!1,onMouseDown:f,trackId:C,fadeIn:x,fadeOut:b,sampleRate:g=44100,showFades:S=!1,touchOptimized:w=!1})=>{const m=Math.floor(o/c),k=Math.floor((o+l)/c)-m,I=u&&!d&&!v,A=`clip-${r}-${a}`,{attributes:R,listeners:E,setNodeRef:M,setActivatorNodeRef:F,transform:T,isDragging:P}=_e.useDraggable({id:A,data:{clipId:n,trackIndex:r,clipIndex:a},disabled:!I}),H=`clip-boundary-left-${r}-${a}`,{attributes:O,listeners:j,setActivatorNodeRef:L,isDragging:B}=_e.useDraggable({id:H,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"left"},disabled:!I}),q=`clip-boundary-right-${r}-${a}`,{attributes:U,listeners:ie,setActivatorNodeRef:te,isDragging:Q}=_e.useDraggable({id:q,data:{clipId:n,trackIndex:r,clipIndex:a,boundary:"right"},disabled:!I}),le=T?{transform:Xt.Translate.toString(T),zIndex:P?100:void 0}:void 0;return h.jsxs(Aa,{ref:M,style:le,className:t,$left:m,$width:k,$isOverlay:v,"data-clip-container":"true","data-track-id":C,onMouseDown:f,children:[u&&h.jsx(va,{clipId:n,trackIndex:r,clipIndex:a,trackName:s,isSelected:p,disableDrag:d,dragHandleProps:I?{attributes:R,listeners:E,setActivatorNodeRef:F}:void 0}),h.jsxs(Ia,{$isOverlay:v,children:[e,S&&x&&x.duration>0&&h.jsx(mn,{left:0,width:Math.floor(x.duration*g/c),type:"fadeIn",curveType:x.type}),S&&b&&b.duration>0&&h.jsx(mn,{left:k-Math.floor(b.duration*g/c),width:Math.floor(b.duration*g/c),type:"fadeOut",curveType:b.type})]}),u&&!d&&!v&&h.jsxs(h.Fragment,{children:[h.jsx(fn,{clipId:n,trackIndex:r,clipIndex:a,edge:"left",touchOptimized:w,dragHandleProps:{attributes:O,listeners:j,setActivatorNodeRef:L,isDragging:B}}),h.jsx(fn,{clipId:n,trackIndex:r,clipIndex:a,edge:"right",touchOptimized:w,dragHandleProps:{attributes:U,listeners:ie,setActivatorNodeRef:te,isDragging:Q}})]})]})},$a=$.div`
|
|
359
359
|
display: inline-flex;
|
|
360
360
|
align-items: center;
|
|
361
361
|
gap: 0.5rem;
|
|
362
|
-
`,
|
|
362
|
+
`,Ma=$(Vn)`
|
|
363
363
|
margin: 0;
|
|
364
364
|
white-space: nowrap;
|
|
365
|
-
`,
|
|
365
|
+
`,Ea=$(jn)`
|
|
366
366
|
width: 120px;
|
|
367
|
-
`,
|
|
367
|
+
`,Ra=({volume:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(parseFloat(s.target.value)/100)};return h.jsxs($a,{className:r,children:[h.jsx(Ma,{htmlFor:"master-gain",children:"Master Volume"}),h.jsx(Ea,{min:"0",max:"100",value:e*100,onChange:a,disabled:n,id:"master-gain"})]})};$.div.attrs(e=>({style:{transform:`translate3d(${e.$position}px, 0, 0)`}}))`
|
|
368
368
|
position: absolute;
|
|
369
369
|
top: 0;
|
|
370
370
|
left: 0;
|
|
@@ -374,7 +374,7 @@
|
|
|
374
374
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
375
375
|
pointer-events: none;
|
|
376
376
|
will-change: transform;
|
|
377
|
-
|
|
377
|
+
`;$.div`
|
|
378
378
|
position: absolute;
|
|
379
379
|
top: 0;
|
|
380
380
|
left: 0;
|
|
@@ -382,7 +382,7 @@
|
|
|
382
382
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
383
383
|
pointer-events: none;
|
|
384
384
|
will-change: transform;
|
|
385
|
-
|
|
385
|
+
`;$.div`
|
|
386
386
|
position: absolute;
|
|
387
387
|
top: -10px;
|
|
388
388
|
left: -6px;
|
|
@@ -391,30 +391,30 @@
|
|
|
391
391
|
border-left: 7px solid transparent;
|
|
392
392
|
border-right: 7px solid transparent;
|
|
393
393
|
border-top: 10px solid ${e=>e.$color};
|
|
394
|
-
|
|
394
|
+
`;$.div`
|
|
395
395
|
position: absolute;
|
|
396
396
|
top: 0;
|
|
397
397
|
left: 0;
|
|
398
398
|
width: 2px;
|
|
399
399
|
height: 100%;
|
|
400
400
|
background: ${e=>e.$color};
|
|
401
|
-
`;var
|
|
401
|
+
`;var Da=$.div`
|
|
402
402
|
overflow-y: hidden;
|
|
403
403
|
overflow-x: auto;
|
|
404
404
|
position: relative;
|
|
405
|
-
`,
|
|
405
|
+
`,Ta=$.div.attrs(e=>({style:e.$width!==void 0?{width:`${e.$width}px`}:{}}))`
|
|
406
406
|
position: relative;
|
|
407
407
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
408
|
-
`,
|
|
408
|
+
`,Ba=$.div.attrs(e=>({style:e.$width?{minWidth:`${e.$width}px`}:{}}))`
|
|
409
409
|
background: ${e=>e.$backgroundColor||"white"};
|
|
410
410
|
width: 100%;
|
|
411
411
|
position: relative;
|
|
412
412
|
overflow: hidden; /* Constrain loop region to timescale area */
|
|
413
|
-
`,
|
|
413
|
+
`,Wa=$.div.attrs(e=>({style:e.$width!==void 0?{minWidth:`${e.$width}px`}:{}}))`
|
|
414
414
|
position: relative;
|
|
415
415
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
416
416
|
width: 100%;
|
|
417
|
-
`,
|
|
417
|
+
`,Fa=$.div`
|
|
418
418
|
position: absolute;
|
|
419
419
|
top: 0;
|
|
420
420
|
left: 0;
|
|
@@ -423,7 +423,7 @@
|
|
|
423
423
|
cursor: crosshair;
|
|
424
424
|
/* When selecting, raise z-index above clip boundaries (z-index: 105) to prevent interference */
|
|
425
425
|
z-index: ${e=>e.$isSelecting?110:1};
|
|
426
|
-
`,
|
|
426
|
+
`,Kt=({children:e,backgroundColor:t,timescaleBackgroundColor:n,timescale:r,timescaleWidth:a,tracksWidth:s,scrollContainerWidth:o,controlsWidth:l,onTracksClick:c,onTracksMouseDown:u,onTracksMouseMove:d,onTracksMouseUp:v,scrollContainerRef:p,isSelecting:f,"data-playlist-state":C})=>h.jsx(Da,{"data-scroll-container":"true","data-playlist-state":C,ref:p,children:h.jsxs(Ta,{$backgroundColor:t,$width:o,children:[r&&h.jsx(Ba,{$width:a,$backgroundColor:n,children:r}),h.jsxs(Wa,{$width:s,$backgroundColor:t,children:[e,(c||u)&&h.jsx(Fa,{$controlsWidth:l,$isSelecting:f,onClick:c,onMouseDown:u,onMouseMove:d,onMouseUp:v})]})]})});$.withTheme(Kt);var _a=$.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
427
427
|
position: absolute;
|
|
428
428
|
top: 0;
|
|
429
429
|
background: ${e=>e.$color};
|
|
@@ -431,14 +431,14 @@
|
|
|
431
431
|
z-index: 60; /* Above clips (z-index: 10) and fades (z-index: 50), below playhead (z-index: 100) */
|
|
432
432
|
pointer-events: none;
|
|
433
433
|
opacity: 0.3;
|
|
434
|
-
`,
|
|
434
|
+
`,Nn=({startPosition:e,endPosition:t,color:n="#00ff00"})=>{const r=Math.max(0,t-e);return r<=0?null:h.jsx(_a,{$left:e,$width:r,$color:n,"data-selection":!0})};$.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
435
435
|
position: absolute;
|
|
436
436
|
top: 0;
|
|
437
437
|
background: ${e=>e.$color};
|
|
438
438
|
height: 100%;
|
|
439
439
|
z-index: 55; /* Between clips (z-index: 50) and selection (z-index: 60) */
|
|
440
440
|
pointer-events: none;
|
|
441
|
-
|
|
441
|
+
`;$.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
|
|
442
442
|
position: absolute;
|
|
443
443
|
top: 0;
|
|
444
444
|
width: 2px;
|
|
@@ -458,7 +458,7 @@
|
|
|
458
458
|
border-top: 8px solid ${e=>e.$color};
|
|
459
459
|
${e=>e.$isStart?"border-right: 8px solid transparent;":"border-left: 8px solid transparent;"}
|
|
460
460
|
}
|
|
461
|
-
`;var
|
|
461
|
+
`;var hn=$.div.attrs(e=>({style:{left:`${e.$left}px`}}))`
|
|
462
462
|
position: absolute;
|
|
463
463
|
top: 0;
|
|
464
464
|
width: 12px;
|
|
@@ -495,7 +495,7 @@
|
|
|
495
495
|
&:hover::before {
|
|
496
496
|
opacity: 1;
|
|
497
497
|
}
|
|
498
|
-
`,
|
|
498
|
+
`,Za=$.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
499
499
|
position: absolute;
|
|
500
500
|
top: 0;
|
|
501
501
|
height: 100%;
|
|
@@ -506,43 +506,62 @@
|
|
|
506
506
|
&:active {
|
|
507
507
|
cursor: grabbing;
|
|
508
508
|
}
|
|
509
|
-
`,
|
|
509
|
+
`,Pa=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopStartChange:a,onLoopEndChange:s,onLoopRegionMove:o,minPosition:l=0,maxPosition:c=1/0})=>{const[u,d]=i.useState(null),v=i.useRef(0),p=i.useRef(0),f=i.useRef(0),C=Math.max(0,t-e),x=i.useCallback((g,S)=>{g.preventDefault(),g.stopPropagation(),d(S),v.current=g.clientX,p.current=S==="start"?e:t;const w=y=>{const k=y.clientX-v.current,I=p.current+k;if(S==="start"){const A=Math.max(l,Math.min(t-10,I));a?.(A)}else{const A=Math.max(e+10,Math.min(c,I));s?.(A)}},m=()=>{d(null),document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",w),document.addEventListener("mouseup",m)},[e,t,l,c,a,s]),b=i.useCallback(g=>{g.preventDefault(),g.stopPropagation(),d("region"),v.current=g.clientX,p.current=e,f.current=t;const S=t-e,w=y=>{const k=y.clientX-v.current;let I=p.current+k,A=f.current+k;I<l&&(I=l,A=l+S),A>c&&(A=c,I=c-S),o?.(I,A)},m=()=>{d(null),document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",w),document.addEventListener("mouseup",m)},[e,t,l,c,o]);return C<=0?null:h.jsxs(h.Fragment,{children:[h.jsx(Za,{$left:e,$width:C,$color:r,$isDragging:u==="region",onMouseDown:b,"data-loop-region-timescale":!0}),h.jsx(hn,{$left:e,$color:n,$isStart:!0,$isDragging:u==="start",onMouseDown:g=>x(g,"start"),"data-loop-marker-handle":"start"}),h.jsx(hn,{$left:t,$color:n,$isStart:!1,$isDragging:u==="end",onMouseDown:g=>x(g,"end"),"data-loop-marker-handle":"end"})]})},Va=$.div.attrs(e=>({style:{left:`${e.$leftOffset||0}px`}}))`
|
|
510
510
|
position: absolute;
|
|
511
511
|
top: 0;
|
|
512
512
|
right: 0;
|
|
513
513
|
height: 100%; /* Stay within timescale bounds, don't extend into tracks */
|
|
514
514
|
cursor: crosshair;
|
|
515
515
|
z-index: 40; /* Below markers and shading */
|
|
516
|
-
|
|
516
|
+
`,ja=({startPosition:e,endPosition:t,markerColor:n="#3b82f6",regionColor:r="rgba(59, 130, 246, 0.3)",onLoopRegionChange:a,minPosition:s=0,maxPosition:o=1/0,controlsOffset:l=0})=>{const[c,u]=i.useState(!1),d=i.useRef(0),v=i.useRef(null),p=t>e,f=i.useCallback(C=>{const x=C.target;if(x.closest("[data-loop-marker-handle]")||x.closest("[data-loop-region-timescale]"))return;C.preventDefault(),u(!0);const b=v.current?.getBoundingClientRect();if(!b)return;const g=C.clientX-b.left,S=Math.max(s,Math.min(o,g));d.current=S,a?.(S,S);const w=y=>{const k=y.clientX-b.left,I=Math.max(s,Math.min(o,k)),A=Math.min(d.current,I),R=Math.max(d.current,I);a?.(A,R)},m=()=>{u(!1),document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",m)};document.addEventListener("mousemove",w),document.addEventListener("mouseup",m)},[s,o,a]);return h.jsx(Va,{ref:v,$leftOffset:l,onMouseDown:f,"data-timescale-loop-creator":!0,children:p&&h.jsx(Pa,{startPosition:e,endPosition:t,markerColor:n,regionColor:r,minPosition:s,maxPosition:o,onLoopStartChange:C=>a?.(C,t),onLoopEndChange:C=>a?.(e,C),onLoopRegionMove:(C,x)=>a?.(C,x)})})};function ft(e,t){const n=Math.floor(e/3600)%24,r=Math.floor(e/60)%60,a=(e%60).toFixed(t);return String(n).padStart(2,"0")+":"+String(r).padStart(2,"0")+":"+a.padStart(t+3,"0")}function lt(e,t){switch(t){case"seconds":return e.toFixed(0);case"thousandths":return e.toFixed(3);case"hh:mm:ss":return ft(e,0);case"hh:mm:ss.u":return ft(e,1);case"hh:mm:ss.uu":return ft(e,2);case"hh:mm:ss.uuu":return ft(e,3);default:return ft(e,3)}}function On(e,t){if(!e)return 0;switch(t){case"seconds":case"thousandths":return parseFloat(e)||0;case"hh:mm:ss":case"hh:mm:ss.u":case"hh:mm:ss.uu":case"hh:mm:ss.uuu":{const n=e.split(":");if(n.length!==3)return 0;const r=parseInt(n[0],10)||0,a=parseInt(n[1],10)||0,s=parseFloat(n[2])||0;return r*3600+a*60+s}default:return 0}}var pn=({id:e,label:t,value:n,format:r,className:a,onChange:s,readOnly:o=!1})=>{const[l,c]=i.useState("");i.useEffect(()=>{const p=lt(n,r);c(p)},[n,r,e]);const u=p=>{const f=p.target.value;c(f)},d=()=>{if(s){const p=On(l,r);s(p)}c(lt(n,r))},v=p=>{p.key==="Enter"&&p.currentTarget.blur()};return h.jsxs(h.Fragment,{children:[h.jsx(da,{as:"label",htmlFor:e,children:t}),h.jsx(Pn,{type:"text",className:a,id:e,value:l,onChange:u,onBlur:d,onKeyDown:v,readOnly:o})]})},za=({selectionStart:e,selectionEnd:t,onSelectionChange:n,className:r})=>{const[a,s]=i.useState("hh:mm:ss.uuu");i.useEffect(()=>{const c=document.querySelector(".time-format"),u=()=>{c&&s(c.value)};return c&&(s(c.value),c.addEventListener("change",u)),()=>{c?.removeEventListener("change",u)}},[]);const o=c=>{n&&n(c,t)},l=c=>{n&&n(e,c)};return h.jsxs(h.Fragment,{children:[h.jsx(pn,{id:"audio_start",label:"Start of audio selection",value:e,format:a,className:"audio-start form-control mr-sm-2",onChange:o}),h.jsx(pn,{id:"audio_end",label:"End of audio selection",value:t,format:a,className:"audio-end form-control mr-sm-2",onChange:l})]})};function It(){return window.devicePixelRatio}var Yn=i.createContext(It()),Kn=({children:e})=>{const[t,n]=i.useState(It());return matchMedia(`(resolution: ${It()}dppx)`).addEventListener("change",()=>{n(It())},{once:!0}),h.jsx(Yn.Provider,{value:Math.ceil(t),children:e})},Ut=()=>i.useContext(Yn),gt=i.createContext({sampleRate:48e3,samplesPerPixel:1e3,zoomLevels:[1e3,1500,2e3,2500],waveHeight:80,timeScaleHeight:15,controls:{show:!1,width:150},duration:3e4,barWidth:1,barGap:0}),bt=()=>i.useContext(gt),vt=()=>i.useContext($.ThemeContext),Jt=i.createContext(h.jsx(i.Fragment,{})),Ha=()=>i.useContext(Jt),La=0,Xa=!1,Ga=0,Na=0,Oa={progress:La,isPlaying:Xa,selectionStart:Ga,selectionEnd:Na};i.createContext(Oa);i.createContext({setIsPlaying:()=>{},setProgress:()=>{},setSelection:()=>{}});var kt=1e3,Ya=$.div.attrs(e=>({style:{top:`${e.$waveHeight*e.$index}px`,width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
517
|
+
position: absolute;
|
|
518
|
+
background: #000;
|
|
519
|
+
transform: translateZ(0);
|
|
520
|
+
backface-visibility: hidden;
|
|
521
|
+
`,Ka=$.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$waveHeight}px`}}))`
|
|
522
|
+
float: left;
|
|
523
|
+
position: relative;
|
|
524
|
+
will-change: transform;
|
|
525
|
+
image-rendering: pixelated;
|
|
526
|
+
image-rendering: crisp-edges;
|
|
527
|
+
`;function Ua(){const e=new Uint8Array(768);for(let t=0;t<256;t++)e[t*3]=e[t*3+1]=e[t*3+2]=t;return e}var gn=({index:e,data:t,length:n,waveHeight:r,devicePixelRatio:a=1,samplesPerPixel:s,colorLUT:o,frequencyScaleFn:l,minFrequency:c=0,maxFrequency:u,workerApi:d,clipId:v,onCanvasesReady:p})=>{const f=i.useRef([]),C=i.useRef([]),x=!!(d&&v),b=i.useCallback(I=>{if(I!==null){const A=parseInt(I.dataset.index,10);f.current[A]=I}},[]);i.useEffect(()=>{if(!x)return;const I=Math.ceil(n/kt);f.current.length=I;const A=f.current,R=[],E=[];for(let M=0;M<A.length;M++){const F=A[M];if(!F)continue;const T=`${v}-ch${e}-chunk${M}`;try{const P=F.transferControlToOffscreen();d.registerCanvas(T,P),R.push(T),E.push(Math.min(n-M*kt,kt))}catch(P){console.warn(`[spectrogram] transferControlToOffscreen failed for ${T}:`,P);continue}}return C.current=R,R.length>0&&p&&p(R,E),()=>{for(const M of C.current)d.unregisterCanvas(M);C.current=[]}},[x,v,e,n]);const g=o??Ua(),S=u??(t?t.sampleRate/2:22050),w=l??((I,A,R)=>(I-A)/(R-A));i.useLayoutEffect(()=>{if(x||!t)return;const I=f.current,{frequencyBinCount:A,frameCount:R,hopSize:E,sampleRate:M,gainDb:F,rangeDb:T}=t,P=T===0?1:T;let H=0;const O=j=>j/A*(M/2);for(let j=0;j<I.length;j++){const L=I[j];if(!L)continue;const B=L.getContext("2d");if(!B)continue;const q=L.width/a,U=r;B.resetTransform(),B.clearRect(0,0,L.width,L.height),B.imageSmoothingEnabled=!1,B.scale(a,a);const ie=B.createImageData(q,U),te=ie.data;for(let Q=0;Q<q;Q++){const Ge=(H+Q)*s,V=Math.floor(Ge/E);if(V<0||V>=R)continue;const de=V*A;for(let ne=0;ne<U;ne++){const N=1-ne/U;let ce=Math.floor(N*A);if(l){let ze=0,Le=A-1;for(;ze<Le;){const ae=ze+Le>>1,Ye=O(ae);w(Ye,c,S)<N?ze=ae+1:Le=ae}ce=ze}if(ce<0||ce>=A)continue;const fe=t.data[de+ce],oe=Math.max(0,Math.min(1,(fe+P+F)/P)),Ie=Math.floor(oe*255),$e=(ne*q+Q)*4;te[$e]=g[Ie*3],te[$e+1]=g[Ie*3+1],te[$e+2]=g[Ie*3+2],te[$e+3]=255}}if(B.resetTransform(),B.putImageData(ie,0,0),a!==1){const Q=document.createElement("canvas");Q.width=q,Q.height=U;const le=Q.getContext("2d");if(!le)continue;le.putImageData(ie,0,0),B.clearRect(0,0,L.width,L.height),B.imageSmoothingEnabled=!1,B.drawImage(Q,0,0,L.width,L.height)}H+=q}},[x,t,n,r,a,s,g,l,c,S,w]);let m=n,y=0;const k=[];for(;m>0;){const I=Math.min(m,kt);k.push(h.jsx(Ka,{$cssWidth:I,width:I*a,height:r*a,$waveHeight:r,"data-index":y,ref:b},`${n}-${y}`)),m-=I,y++}return h.jsx(Ya,{$index:e,$cssWidth:n,$waveHeight:r,children:k})},Un=({isSelected:e,transparentBackground:t,renderMode:n="waveform",spectrogramData:r,spectrogramColorLUT:a,samplesPerPixel:s,spectrogramFrequencyScaleFn:o,spectrogramMinFrequency:l,spectrogramMaxFrequency:c,spectrogramWorkerApi:u,spectrogramClipId:d,spectrogramOnCanvasesReady:v,...p})=>{const f=vt(),{waveHeight:C,barWidth:x,barGap:b,samplesPerPixel:g}=bt(),S=Ut(),w=s??g,m=e&&f?f.selectedWaveOutlineColor:f?.waveOutlineColor,y=e&&f?f.selectedWaveFillColor:f?.waveFillColor,k=f?.waveformDrawMode||"inverted",I=r||u;if(n==="spectrogram"&&I)return h.jsx(gn,{index:p.index,data:r,length:p.length,waveHeight:C,devicePixelRatio:S,samplesPerPixel:w,colorLUT:a,frequencyScaleFn:o,minFrequency:l,maxFrequency:c,workerApi:u,clipId:d,onCanvasesReady:v});if(n==="both"&&I){const A=Math.floor(C/2);return h.jsxs(h.Fragment,{children:[h.jsx(gn,{index:p.index*2,data:r,length:p.length,waveHeight:A,devicePixelRatio:S,samplesPerPixel:w,colorLUT:a,frequencyScaleFn:o,minFrequency:l,maxFrequency:c,workerApi:u,clipId:d,onCanvasesReady:v}),h.jsx("div",{style:{position:"absolute",top:(p.index*2+1)*A,width:p.length,height:A},children:h.jsx(dn,{...p,...f,index:0,waveOutlineColor:m,waveFillColor:y,waveHeight:A,devicePixelRatio:S,barWidth:x,barGap:b,transparentBackground:t,drawMode:k})})]})}return h.jsx(dn,{...p,...f,waveOutlineColor:m,waveFillColor:y,waveHeight:C,devicePixelRatio:S,barWidth:x,barGap:b,transparentBackground:t,drawMode:k})},bn=72,Ja=$.div`
|
|
528
|
+
position: sticky;
|
|
529
|
+
left: 0;
|
|
530
|
+
z-index: 101;
|
|
531
|
+
pointer-events: none;
|
|
532
|
+
height: 0;
|
|
533
|
+
width: 0;
|
|
534
|
+
overflow: visible;
|
|
535
|
+
`;function qa(e,t,n){const a=[20,50,100,200,500,1e3,2e3,3e3,4e3,5e3,8e3,1e4,12e3,16e3,2e4].filter(c=>c>=e&&c<=t),s=Math.max(2,Math.floor(n/20));if(a.length<=s)return a;const o=(a.length-1)/(s-1),l=[];for(let c=0;c<s;c++)l.push(a[Math.round(c*o)]);return l}var Qa=({waveHeight:e,numChannels:t,frequencyScaleFn:n,minFrequency:r,maxFrequency:a,labelsColor:s="#ccc",labelsBackground:o="rgba(0,0,0,0.6)",renderMode:l="spectrogram",hasClipHeaders:c=!1})=>{const u=i.useRef(null),d=Ut(),v=l==="both"?Math.floor(e/2):e,p=t*e,f=c?22:0;return i.useLayoutEffect(()=>{const C=u.current;if(!C)return;const x=C.getContext("2d");if(!x)return;x.resetTransform(),x.clearRect(0,0,C.width,C.height),x.scale(d,d);const b=qa(r,a,v);for(let g=0;g<t;g++){const S=g*e+f;x.font="11px monospace",x.textBaseline="middle";for(const w of b){const m=n(w,r,a);if(m<0||m>1)continue;const y=S+v*(1-m),k=w>=1e3?`${(w/1e3).toFixed(1)}k`:`${w} Hz`,I=x.measureText(k),A=3;x.fillStyle=o,x.fillRect(0,y-7,I.width+A*2,14),x.fillStyle=s,x.fillText(k,A,y)}}},[e,t,n,r,a,s,o,d,v,f]),h.jsx(Ja,{$height:p+f,children:h.jsx("canvas",{ref:u,width:bn*d,height:(p+f)*d,style:{width:bn,height:p+f,pointerEvents:"none"}})})};function eo(e,t,n){return Math.ceil(e*n/t)}function to(e){const t=Math.floor(e/1e3),n=t%60;return`${(t-n)/60}:${String(n).padStart(2,"0")}`}var no=$.div.attrs(e=>({style:{width:`${e.$cssWidth}px`,marginLeft:`${e.$controlWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
|
|
517
536
|
position: relative;
|
|
518
537
|
overflow: visible; /* Allow time labels to render above the container */
|
|
519
538
|
border-bottom: 1px solid ${e=>e.theme.timeColor};
|
|
520
539
|
box-sizing: border-box;
|
|
521
|
-
`,
|
|
540
|
+
`,ro=$.canvas.attrs(e=>({style:{width:`${e.$cssWidth}px`,height:`${e.$timeScaleHeight}px`}}))`
|
|
522
541
|
position: absolute;
|
|
523
542
|
left: 0;
|
|
524
543
|
right: 0;
|
|
525
544
|
bottom: 0;
|
|
526
|
-
`,
|
|
545
|
+
`,ao=$.div.attrs(e=>({style:{left:`${e.$left+4}px`}}))`
|
|
527
546
|
position: absolute;
|
|
528
547
|
font-size: 0.75rem; /* Smaller font to prevent overflow */
|
|
529
548
|
white-space: nowrap; /* Prevent text wrapping */
|
|
530
549
|
color: ${e=>e.theme.timeColor}; /* Use theme color instead of inheriting */
|
|
531
|
-
`,
|
|
550
|
+
`,oo=e=>{const{theme:{timeColor:t},duration:n,marker:r,bigStep:a,secondStep:s,renderTimestamp:o}=e,l=new Map,c=[],u=i.useRef(null),{sampleRate:d,samplesPerPixel:v,timeScaleHeight:p,controls:{show:f,width:C}}=i.useContext(gt),x=Ut();i.useEffect(()=>{if(u.current!==null){const w=u.current,m=w.getContext("2d");if(m){m.resetTransform(),m.clearRect(0,0,w.width,w.height),m.imageSmoothingEnabled=!1,m.fillStyle=t,m.scale(x,x);for(const[y,k]of l.entries()){const I=p-k;m.fillRect(y,I,1,k)}}}},[n,x,t,p,a,s,r,l]);const b=eo(n/1e3,v,d),g=d/v;let S=0;for(let w=0;w<b;w+=g*s/1e3){const m=Math.floor(w);if(S%r===0){const y=S,k=to(y),I=o?h.jsx(i.Fragment,{children:o(y,m)},`timestamp-${S}`):h.jsx(ao,{$left:m,children:k},k);c.push(I),l.set(m,p)}else S%a===0?l.set(m,Math.floor(p/2)):S%s===0&&l.set(m,Math.floor(p/5));S+=s}return h.jsxs(no,{$cssWidth:b,$controlWidth:f?C:0,$timeScaleHeight:p,children:[c,h.jsx(ro,{$cssWidth:b,$timeScaleHeight:p,width:b*x,height:p*x,ref:u})]})},so=$.withTheme(oo),vn=new Map([[700,{marker:1e3,bigStep:500,smallStep:100}],[1500,{marker:2e3,bigStep:1e3,smallStep:200}],[2500,{marker:2e3,bigStep:1e3,smallStep:500}],[5e3,{marker:5e3,bigStep:1e3,smallStep:500}],[1e4,{marker:1e4,bigStep:5e3,smallStep:1e3}],[12e3,{marker:15e3,bigStep:5e3,smallStep:1e3}],[1/0,{marker:3e4,bigStep:1e4,smallStep:5e3}]]);function io(e){const t=vn.keys();let n;for(const r of t)if(e<r){n=vn.get(r);break}return n===void 0&&(n={marker:3e4,bigStep:1e4,smallStep:5e3}),n}var Jn=({renderTimestamp:e})=>{const{samplesPerPixel:t,duration:n}=i.useContext(gt);let r=io(t);return h.jsx(so,{marker:r.marker,bigStep:r.bigStep,secondStep:r.smallStep,duration:n,renderTimestamp:e})},lo=$.div`
|
|
532
551
|
display: inline-flex;
|
|
533
552
|
align-items: center;
|
|
534
553
|
gap: 0.5rem;
|
|
535
|
-
`,
|
|
554
|
+
`,co=[{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"}],uo=({value:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.value)};return h.jsx(lo,{className:r,children:h.jsx(Yt,{className:"time-format",value:e,onChange:a,disabled:n,"aria-label":"Time format selection",children:co.map(s=>h.jsx("option",{value:s.value,children:s.label},s.value))})})},fo=$.div.attrs(e=>({style:{height:`${e.$waveHeight*e.$numChannels+(e.$hasClipHeaders?Ln:0)}px`}}))`
|
|
536
555
|
position: relative;
|
|
537
556
|
display: flex;
|
|
538
557
|
${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
|
|
539
|
-
`,
|
|
558
|
+
`,mo=$.div.attrs(e=>({style:{paddingLeft:`${e.$offset||0}px`}}))`
|
|
540
559
|
position: relative;
|
|
541
560
|
background: ${e=>e.$backgroundColor||"transparent"};
|
|
542
561
|
flex: 1;
|
|
543
|
-
`,
|
|
562
|
+
`,ho=$.div.attrs(e=>({style:{width:`${e.$controlWidth}px`}}))`
|
|
544
563
|
position: sticky;
|
|
545
|
-
z-index:
|
|
564
|
+
z-index: 102; /* Above waveform content and spectrogram labels (101), below Docusaurus navbar (200) */
|
|
546
565
|
left: 0;
|
|
547
566
|
height: 100%;
|
|
548
567
|
flex-shrink: 0;
|
|
@@ -554,7 +573,7 @@
|
|
|
554
573
|
${e=>e.$isSelected&&`
|
|
555
574
|
background: ${e.theme.selectedTrackControlsBackground};
|
|
556
575
|
`}
|
|
557
|
-
`,
|
|
576
|
+
`,qn=({numChannels:e,children:t,className:n,backgroundColor:r,offset:a=0,width:s,hasClipHeaders:o=!1,onClick:l,trackId:c,isSelected:u=!1})=>{const{waveHeight:d,controls:{show:v,width:p}}=bt(),f=Ha();return h.jsxs(fo,{$numChannels:e,className:n,$waveHeight:d,$controlWidth:v?p:0,$width:s,$hasClipHeaders:o,$isSelected:u,children:[h.jsx(ho,{$controlWidth:v?p:0,$isSelected:u,children:f}),h.jsx(mo,{$controlWidth:v?p:0,$backgroundColor:r,$offset:a,onClick:l,"data-track-id":c,children:t})]})},Cn=$.button.attrs({type:"button"})`
|
|
558
577
|
display: inline-block;
|
|
559
578
|
font-family: ${e=>e.theme.fontFamily};
|
|
560
579
|
font-weight: 500;
|
|
@@ -613,7 +632,7 @@
|
|
|
613
632
|
box-shadow: 0 0 0 0.2rem ${e.theme.inputFocusBorder}33;
|
|
614
633
|
}
|
|
615
634
|
`}
|
|
616
|
-
`,
|
|
635
|
+
`,po=$.div`
|
|
617
636
|
margin-bottom: 0.3rem;
|
|
618
637
|
|
|
619
638
|
button:not(:first-child) {
|
|
@@ -625,7 +644,27 @@
|
|
|
625
644
|
border-top-right-radius: 0;
|
|
626
645
|
border-bottom-right-radius: 0;
|
|
627
646
|
}
|
|
628
|
-
`,
|
|
647
|
+
`,go=$.button`
|
|
648
|
+
position: absolute;
|
|
649
|
+
left: 0;
|
|
650
|
+
top: 0;
|
|
651
|
+
border: none;
|
|
652
|
+
background: transparent;
|
|
653
|
+
color: inherit;
|
|
654
|
+
cursor: pointer;
|
|
655
|
+
font-size: 16px;
|
|
656
|
+
padding: 2px 4px;
|
|
657
|
+
display: flex;
|
|
658
|
+
align-items: center;
|
|
659
|
+
justify-content: center;
|
|
660
|
+
opacity: 0.7;
|
|
661
|
+
transition: opacity 0.15s, color 0.15s;
|
|
662
|
+
|
|
663
|
+
&:hover {
|
|
664
|
+
opacity: 1;
|
|
665
|
+
color: #dc3545;
|
|
666
|
+
}
|
|
667
|
+
`,bo=({onClick:e,title:t="Remove track"})=>h.jsx(go,{onClick:e,title:t,children:h.jsx(ua,{size:12,weight:"bold"})}),vo=$.div`
|
|
629
668
|
background: transparent;
|
|
630
669
|
width: 100%;
|
|
631
670
|
height: 100%;
|
|
@@ -638,7 +677,7 @@
|
|
|
638
677
|
text-align: center;
|
|
639
678
|
border: 1px solid ${e=>e.theme.borderColor};
|
|
640
679
|
border-radius: ${e=>e.theme.borderRadius};
|
|
641
|
-
`,
|
|
680
|
+
`,Co=$.header`
|
|
642
681
|
overflow: hidden;
|
|
643
682
|
height: 26px;
|
|
644
683
|
width: 100%;
|
|
@@ -649,7 +688,7 @@
|
|
|
649
688
|
font-size: ${e=>e.theme.fontSizeSmall};
|
|
650
689
|
color: ${e=>e.theme.textColor};
|
|
651
690
|
background-color: transparent;
|
|
652
|
-
`,
|
|
691
|
+
`,xo=e=>h.jsx(_n,{weight:"light",...e}),wo=e=>h.jsx(Fn,{weight:"light",...e}),yo=e=>h.jsx(Wn,{weight:"bold",...e}),xn=$(jn)`
|
|
653
692
|
width: 75%;
|
|
654
693
|
height: 5px;
|
|
655
694
|
background: ${e=>e.theme.sliderTrackColor};
|
|
@@ -698,7 +737,7 @@
|
|
|
698
737
|
&:focus::-moz-range-thumb {
|
|
699
738
|
border: 2px solid ${e=>e.theme.textColor};
|
|
700
739
|
}
|
|
701
|
-
`,
|
|
740
|
+
`,wn=$.label`
|
|
702
741
|
width: 100%;
|
|
703
742
|
display: flex;
|
|
704
743
|
justify-content: space-between;
|
|
@@ -706,46 +745,41 @@
|
|
|
706
745
|
padding: 0 1rem;
|
|
707
746
|
margin-bottom: 0.2rem;
|
|
708
747
|
font-size: 14px;
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
font-size: 0.875rem;
|
|
718
|
-
overflow: hidden;
|
|
719
|
-
text-overflow: ellipsis;
|
|
720
|
-
white-space: nowrap;
|
|
721
|
-
margin: 0 0.25rem;
|
|
722
|
-
`;A.button`
|
|
748
|
+
`,ko=$.div`
|
|
749
|
+
position: relative;
|
|
750
|
+
display: inline-block;
|
|
751
|
+
`,So=$.button`
|
|
752
|
+
background: none;
|
|
753
|
+
border: none;
|
|
754
|
+
cursor: pointer;
|
|
755
|
+
padding: 2px 4px;
|
|
723
756
|
display: flex;
|
|
724
757
|
align-items: center;
|
|
725
758
|
justify-content: center;
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
padding: 0;
|
|
729
|
-
border: none;
|
|
730
|
-
background: transparent;
|
|
731
|
-
color: #999;
|
|
732
|
-
cursor: pointer;
|
|
733
|
-
font-size: 16px;
|
|
734
|
-
line-height: 1;
|
|
735
|
-
border-radius: 3px;
|
|
736
|
-
transition: all 0.2s ease-in-out;
|
|
737
|
-
flex-shrink: 0;
|
|
759
|
+
color: inherit;
|
|
760
|
+
opacity: 0.7;
|
|
738
761
|
|
|
739
762
|
&:hover {
|
|
740
|
-
|
|
741
|
-
color: white;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
&:active {
|
|
745
|
-
transform: scale(0.9);
|
|
763
|
+
opacity: 1;
|
|
746
764
|
}
|
|
747
|
-
|
|
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`}}))`
|
|
765
|
+
`,Ao=$.div`
|
|
766
|
+
position: fixed;
|
|
767
|
+
top: ${e=>e.$top}px;
|
|
768
|
+
left: ${e=>e.$left}px;
|
|
769
|
+
z-index: 10000;
|
|
770
|
+
background: ${e=>e.theme.timescaleBackgroundColor??"#222"};
|
|
771
|
+
color: ${e=>e.theme.textColor??"inherit"};
|
|
772
|
+
border: 1px solid rgba(128, 128, 128, 0.4);
|
|
773
|
+
border-radius: 6px;
|
|
774
|
+
padding: 0.5rem 0;
|
|
775
|
+
min-width: 180px;
|
|
776
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
777
|
+
`,Io=$.hr`
|
|
778
|
+
border: none;
|
|
779
|
+
border-top: 1px solid rgba(128, 128, 128, 0.3);
|
|
780
|
+
margin: 0.35rem 0;
|
|
781
|
+
`,$o=({items:e})=>{const[t,n]=i.useState(!1),a=typeof e=="function"?e(()=>n(!1)):e,[s,o]=i.useState({top:0,left:0}),l=i.useRef(null),c=i.useRef(null);return i.useEffect(()=>{if(t&&l.current){const u=l.current.getBoundingClientRect();o({top:u.bottom+2,left:Math.max(0,u.right-180)})}},[t]),i.useEffect(()=>{if(!t)return;const u=d=>{const v=d.target;l.current&&!l.current.contains(v)&&c.current&&!c.current.contains(v)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[t]),h.jsxs(ko,{children:[h.jsx(So,{ref:l,onClick:u=>{u.stopPropagation(),n(d=>!d)},onMouseDown:u=>u.stopPropagation(),title:"Track menu","aria-label":"Track menu",children:h.jsx(yo,{size:16})}),t&&typeof document<"u"&&Rn.createPortal(h.jsx(Ao,{ref:c,$top:s.top,$left:s.left,onMouseDown:u=>u.stopPropagation(),children:a.map((u,d)=>h.jsxs(i.Fragment,{children:[d>0&&h.jsx(Io,{}),u.content]},u.id))}),document.body)]})};function Mo(e){let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){const a=e[r];t>a&&(t=a),n<a&&(n=a)}return{min:t,max:n}}function yn(e,t){const n=Math.pow(2,t-1),r=e<0?e*n:e*(n-1);return Math.max(-n,Math.min(n-1,r))}function Qn(e,t){switch(e){case 8:return new Int8Array(t);case 16:return new Int16Array(t)}}function kn(e,t,n){const r=e.length,a=Math.ceil(r/t),s=Qn(n,a*2);for(let o=0;o<a;o++){const l=o*t,c=Math.min((o+1)*t,r),u=e.subarray(l,c),d=Mo(u),v=yn(d.min,n),p=yn(d.max,n);s[o*2]=v,s[o*2+1]=p}return s}function Eo(e,t){const n=e.length,r=1/n,a=e[0].length/2,s=Qn(t,a*2);for(let o=0;o<a;o++){let l=0,c=0;for(let u=0;u<n;u++)l+=r*e[u][o*2],c+=r*e[u][o*2+1];s[o*2]=l,s[o*2+1]=c}return[s]}function Ro(e,t=1e3,n=!0,r=0,a,s=16){if(s!==8&&s!==16)throw new Error("Invalid number of bits specified for peaks. Must be 8 or 16.");let o=[];if("getChannelData"in e){const c=e.numberOfChannels,u=a??e.length;for(let d=0;d<c;d++){const p=e.getChannelData(d).subarray(r,u);o.push(kn(p,t,s))}}else{const c=a??e.length,u=e.subarray(r,c);o.push(kn(u,t,s))}return n&&o.length>1&&(o=Eo(o,s)),{length:o[0].length/2,data:o,bits:s}}function Do(e,t=1e3,n=!0,r=8,a=0,s){const o=s!==void 0?a+s:void 0;return Ro(e,t,n,a,o,r)}function at(e,t){this._waveformData=e,this._channelIndex=t}at.prototype.min_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._at(t)};at.prototype.max_sample=function(e){var t=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._at(t)};at.prototype.set_min_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2;return this._waveformData._set_at(n,t)};at.prototype.set_max_sample=function(e,t){var n=(e*this._waveformData.channels+this._channelIndex)*2+1;return this._waveformData._set_at(n,t)};at.prototype.min_array=function(){for(var e=this._waveformData.length,t=[],n=0;n<e;n++)t.push(this.min_sample(n));return t};at.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 To=127,Bo=-128,Wo=32767,Fo=-32768;function _o(e,t){var n=Math.floor(e/t),r=e-n*t;return r>0&&n++,n}function Zo(e){for(var t=e.scale,n=e.amplitude_scale,r=e.split_channels,a=e.length,s=e.sample_rate,o=e.channels.map(function(M){return new Float32Array(M)}),l=r?o.length:1,c=24,u=_o(a,t),d=e.bits===8?1:2,v=c+u*2*d*l,p=new ArrayBuffer(v),f=new DataView(p),C=0,x=c,b=new Array(l),g=new Array(l),S=0;S<l;S++)b[S]=1/0,g[S]=-1/0;var w=e.bits===8?Bo:Fo,m=e.bits===8?To:Wo;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 y=0;y<a;y++){var k=0;if(l===1){for(var I=0;I<o.length;++I)k+=o[I][y];k=Math.floor(m*k*n/o.length),k<b[0]&&(b[0]=k,b[0]<w&&(b[0]=w)),k>g[0]&&(g[0]=k,g[0]>m&&(g[0]=m))}else for(var A=0;A<l;++A)k=Math.floor(m*o[A][y]*n),k<b[A]&&(b[A]=k,b[A]<w&&(b[A]=w)),k>g[A]&&(g[A]=k,g[A]>m&&(g[A]=m));if(++C===t){for(var R=0;R<l;R++)e.bits===8?(f.setInt8(x++,b[R]),f.setInt8(x++,g[R])):(f.setInt16(x,b[R],!0),f.setInt16(x+2,g[R],!0),x+=4),b[R]=1/0,g[R]=-1/0;C=0}}if(C>0)for(var E=0;E<l;E++)e.bits===8?(f.setInt8(x++,b[E]),f.setInt8(x++,g[E])):(f.setInt16(x,b[E],!0),f.setInt16(x+2,g[E],!0));return p}function $t(e){"@babel/helpers - typeof";return $t=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},$t(e)}function Po(e){return e&&$t(e)==="object"&&"sample_rate"in e&&"samples_per_pixel"in e&&"bits"in e&&"length"in e&&"data"in e}function Vo(e){var t=e&&$t(e)==="object"&&"byteLength"in e;if(t){var n=new DataView(e),r=n.getInt32(0,!0);if(r!==1&&r!==2)throw new TypeError("WaveformData.create(): This waveform data version not supported")}return t}function jo(e){var t=e.data,n=e.channels||1,r=24,a=e.bits===8?1:2,s=e.length*2*n;if(t.length!==s)throw new Error("WaveformData.create(): Length mismatch in JSON waveform data");var o=r+t.length*a,l=new ArrayBuffer(o),c=new DataView(l);c.setInt32(0,2,!0),c.setUint32(4,e.bits===8,!0),c.setInt32(8,e.sample_rate,!0),c.setInt32(12,e.samples_per_pixel,!0),c.setInt32(16,e.length,!0),c.setInt32(20,n,!0);var u=r;if(e.bits===8)for(var d=0;d<t.length;d++)c.setInt8(u++,t[d],!0);else for(var v=0;v<t.length;v++)c.setInt16(u,t[v],!0),u+=2;return l}function it(e){return e==null}function zo(e,t){var n=atob(e);return n}function Ho(e,t,n){var r=zo(e),a=r.indexOf(`
|
|
782
|
+
`,10)+1,s=r.substring(a)+"",o=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(o)}function Lo(e,t,n){var r;return function(s){return r=r||Ho(e),new Worker(r,s)}}var Xo=Lo("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICd1c2Ugc3RyaWN0JzsKCiAgLyoqCiAgICogQXVkaW9CdWZmZXItYmFzZWQgV2F2ZWZvcm1EYXRhIGdlbmVyYXRvcgogICAqCiAgICogQWRhcHRlZCBmcm9tIEJsb2NrRmlsZTo6Q2FsY1N1bW1hcnkgaW4gQXVkYWNpdHksIHdpdGggcGVybWlzc2lvbi4KICAgKiBTZWUgaHR0cHM6Ly9naXRodWIuY29tL2F1ZGFjaXR5L2F1ZGFjaXR5L2Jsb2IvCiAgICogICAxMTA4YzEzNzZjMDkxNjYxNjIzMzVmYWI0NzQzMDA4Y2JhNTdjNGVlL3NyYy9CbG9ja0ZpbGUuY3BwI0wxOTgKICAgKi8KCiAgdmFyIElOVDhfTUFYID0gMTI3OwogIHZhciBJTlQ4X01JTiA9IC0xMjg7CiAgdmFyIElOVDE2X01BWCA9IDMyNzY3OwogIHZhciBJTlQxNl9NSU4gPSAtMzI3Njg7CiAgZnVuY3Rpb24gY2FsY3VsYXRlV2F2ZWZvcm1EYXRhTGVuZ3RoKGF1ZGlvX3NhbXBsZV9jb3VudCwgc2NhbGUpIHsKICAgIHZhciBkYXRhX2xlbmd0aCA9IE1hdGguZmxvb3IoYXVkaW9fc2FtcGxlX2NvdW50IC8gc2NhbGUpOwogICAgdmFyIHNhbXBsZXNfcmVtYWluaW5nID0gYXVkaW9fc2FtcGxlX2NvdW50IC0gZGF0YV9sZW5ndGggKiBzY2FsZTsKICAgIGlmIChzYW1wbGVzX3JlbWFpbmluZyA+IDApIHsKICAgICAgZGF0YV9sZW5ndGgrKzsKICAgIH0KICAgIHJldHVybiBkYXRhX2xlbmd0aDsKICB9CiAgZnVuY3Rpb24gZ2VuZXJhdGVXYXZlZm9ybURhdGEob3B0aW9ucykgewogICAgdmFyIHNjYWxlID0gb3B0aW9ucy5zY2FsZTsKICAgIHZhciBhbXBsaXR1ZGVfc2NhbGUgPSBvcHRpb25zLmFtcGxpdHVkZV9zY2FsZTsKICAgIHZhciBzcGxpdF9jaGFubmVscyA9IG9wdGlvbnMuc3BsaXRfY2hhbm5lbHM7CiAgICB2YXIgbGVuZ3RoID0gb3B0aW9ucy5sZW5ndGg7CiAgICB2YXIgc2FtcGxlX3JhdGUgPSBvcHRpb25zLnNhbXBsZV9yYXRlOwogICAgdmFyIGNoYW5uZWxzID0gb3B0aW9ucy5jaGFubmVscy5tYXAoZnVuY3Rpb24gKGNoYW5uZWwpIHsKICAgICAgcmV0dXJuIG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICB9KTsKICAgIHZhciBvdXRwdXRfY2hhbm5lbHMgPSBzcGxpdF9jaGFubmVscyA/IGNoYW5uZWxzLmxlbmd0aCA6IDE7CiAgICB2YXIgaGVhZGVyX3NpemUgPSAyNDsKICAgIHZhciBkYXRhX2xlbmd0aCA9IGNhbGN1bGF0ZVdhdmVmb3JtRGF0YUxlbmd0aChsZW5ndGgsIHNjYWxlKTsKICAgIHZhciBieXRlc19wZXJfc2FtcGxlID0gb3B0aW9ucy5iaXRzID09PSA4ID8gMSA6IDI7CiAgICB2YXIgdG90YWxfc2l6ZSA9IGhlYWRlcl9zaXplICsgZGF0YV9sZW5ndGggKiAyICogYnl0ZXNfcGVyX3NhbXBsZSAqIG91dHB1dF9jaGFubmVsczsKICAgIHZhciBidWZmZXIgPSBuZXcgQXJyYXlCdWZmZXIodG90YWxfc2l6ZSk7CiAgICB2YXIgZGF0YV92aWV3ID0gbmV3IERhdGFWaWV3KGJ1ZmZlcik7CiAgICB2YXIgc2NhbGVfY291bnRlciA9IDA7CiAgICB2YXIgb2Zmc2V0ID0gaGVhZGVyX3NpemU7CiAgICB2YXIgbWluX3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICB2YXIgbWF4X3ZhbHVlID0gbmV3IEFycmF5KG91dHB1dF9jaGFubmVscyk7CiAgICBmb3IgKHZhciBjaGFubmVsID0gMDsgY2hhbm5lbCA8IG91dHB1dF9jaGFubmVsczsgY2hhbm5lbCsrKSB7CiAgICAgIG1pbl92YWx1ZVtjaGFubmVsXSA9IEluZmluaXR5OwogICAgICBtYXhfdmFsdWVbY2hhbm5lbF0gPSAtSW5maW5pdHk7CiAgICB9CiAgICB2YXIgcmFuZ2VfbWluID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NSU4gOiBJTlQxNl9NSU47CiAgICB2YXIgcmFuZ2VfbWF4ID0gb3B0aW9ucy5iaXRzID09PSA4ID8gSU5UOF9NQVggOiBJTlQxNl9NQVg7CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMCwgMiwgdHJ1ZSk7IC8vIFZlcnNpb24KICAgIGRhdGFfdmlldy5zZXRVaW50MzIoNCwgb3B0aW9ucy5iaXRzID09PSA4LCB0cnVlKTsgLy8gSXMgOCBiaXQ/CiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoOCwgc2FtcGxlX3JhdGUsIHRydWUpOyAvLyBTYW1wbGUgcmF0ZQogICAgZGF0YV92aWV3LnNldEludDMyKDEyLCBzY2FsZSwgdHJ1ZSk7IC8vIFNjYWxlCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMTYsIGRhdGFfbGVuZ3RoLCB0cnVlKTsgLy8gTGVuZ3RoCiAgICBkYXRhX3ZpZXcuc2V0SW50MzIoMjAsIG91dHB1dF9jaGFubmVscywgdHJ1ZSk7CiAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKSB7CiAgICAgIHZhciBzYW1wbGUgPSAwOwogICAgICBpZiAob3V0cHV0X2NoYW5uZWxzID09PSAxKSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwgPSAwOyBfY2hhbm5lbCA8IGNoYW5uZWxzLmxlbmd0aDsgKytfY2hhbm5lbCkgewogICAgICAgICAgc2FtcGxlICs9IGNoYW5uZWxzW19jaGFubmVsXVtpXTsKICAgICAgICB9CiAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBzYW1wbGUgKiBhbXBsaXR1ZGVfc2NhbGUgLyBjaGFubmVscy5sZW5ndGgpOwogICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbMF0pIHsKICAgICAgICAgIG1pbl92YWx1ZVswXSA9IHNhbXBsZTsKICAgICAgICAgIGlmIChtaW5fdmFsdWVbMF0gPCByYW5nZV9taW4pIHsKICAgICAgICAgICAgbWluX3ZhbHVlWzBdID0gcmFuZ2VfbWluOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoc2FtcGxlID4gbWF4X3ZhbHVlWzBdKSB7CiAgICAgICAgICBtYXhfdmFsdWVbMF0gPSBzYW1wbGU7CiAgICAgICAgICBpZiAobWF4X3ZhbHVlWzBdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgIG1heF92YWx1ZVswXSA9IHJhbmdlX21heDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZm9yICh2YXIgX2NoYW5uZWwyID0gMDsgX2NoYW5uZWwyIDwgb3V0cHV0X2NoYW5uZWxzOyArK19jaGFubmVsMikgewogICAgICAgICAgc2FtcGxlID0gTWF0aC5mbG9vcihyYW5nZV9tYXggKiBjaGFubmVsc1tfY2hhbm5lbDJdW2ldICogYW1wbGl0dWRlX3NjYWxlKTsKICAgICAgICAgIGlmIChzYW1wbGUgPCBtaW5fdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtaW5fdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1pbl92YWx1ZVtfY2hhbm5lbDJdIDwgcmFuZ2VfbWluKSB7CiAgICAgICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9taW47CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzYW1wbGUgPiBtYXhfdmFsdWVbX2NoYW5uZWwyXSkgewogICAgICAgICAgICBtYXhfdmFsdWVbX2NoYW5uZWwyXSA9IHNhbXBsZTsKICAgICAgICAgICAgaWYgKG1heF92YWx1ZVtfY2hhbm5lbDJdID4gcmFuZ2VfbWF4KSB7CiAgICAgICAgICAgICAgbWF4X3ZhbHVlW19jaGFubmVsMl0gPSByYW5nZV9tYXg7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKCsrc2NhbGVfY291bnRlciA9PT0gc2NhbGUpIHsKICAgICAgICBmb3IgKHZhciBfY2hhbm5lbDMgPSAwOyBfY2hhbm5lbDMgPCBvdXRwdXRfY2hhbm5lbHM7IF9jaGFubmVsMysrKSB7CiAgICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtaW5fdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQ4KG9mZnNldCsrLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50MTYob2Zmc2V0LCBtaW5fdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIGRhdGFfdmlldy5zZXRJbnQxNihvZmZzZXQgKyAyLCBtYXhfdmFsdWVbX2NoYW5uZWwzXSwgdHJ1ZSk7CiAgICAgICAgICAgIG9mZnNldCArPSA0OwogICAgICAgICAgfQogICAgICAgICAgbWluX3ZhbHVlW19jaGFubmVsM10gPSBJbmZpbml0eTsKICAgICAgICAgIG1heF92YWx1ZVtfY2hhbm5lbDNdID0gLUluZmluaXR5OwogICAgICAgIH0KICAgICAgICBzY2FsZV9jb3VudGVyID0gMDsKICAgICAgfQogICAgfQogICAgaWYgKHNjYWxlX2NvdW50ZXIgPiAwKSB7CiAgICAgIGZvciAodmFyIF9jaGFubmVsNCA9IDA7IF9jaGFubmVsNCA8IG91dHB1dF9jaGFubmVsczsgX2NoYW5uZWw0KyspIHsKICAgICAgICBpZiAob3B0aW9ucy5iaXRzID09PSA4KSB7CiAgICAgICAgICBkYXRhX3ZpZXcuc2V0SW50OChvZmZzZXQrKywgbWluX3ZhbHVlW19jaGFubmVsNF0pOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDgob2Zmc2V0KyssIG1heF92YWx1ZVtfY2hhbm5lbDRdKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCwgbWluX3ZhbHVlW19jaGFubmVsNF0sIHRydWUpOwogICAgICAgICAgZGF0YV92aWV3LnNldEludDE2KG9mZnNldCArIDIsIG1heF92YWx1ZVtfY2hhbm5lbDRdLCB0cnVlKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBidWZmZXI7CiAgfQoKICBvbm1lc3NhZ2UgPSBmdW5jdGlvbiBvbm1lc3NhZ2UoZXZ0KSB7CiAgICB2YXIgYnVmZmVyID0gZ2VuZXJhdGVXYXZlZm9ybURhdGEoZXZ0LmRhdGEpOwoKICAgIC8vIFRyYW5zZmVyIGJ1ZmZlciB0byB0aGUgY2FsbGluZyB0aHJlYWQKICAgIHRoaXMucG9zdE1lc3NhZ2UoYnVmZmVyLCBbYnVmZmVyXSk7CiAgICB0aGlzLmNsb3NlKCk7CiAgfTsKCn0pKCk7Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdhdmVmb3JtLWRhdGEtd29ya2VyLmpzLm1hcAoK");function Ve(e){if(Po(e)&&(e=jo(e)),Vo(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 at(this,t)}else throw new TypeError("WaveformData.create(): Unknown data format")}var mt={scale:512,bits:8,amplitude_scale:1,split_channels:!1,disable_worker:!1};function Go(e){var t={scale:e.scale||mt.scale,bits:e.bits||mt.bits,amplitude_scale:e.amplitude_scale||mt.amplitude_scale,split_channels:e.split_channels||mt.split_channels,disable_worker:e.disable_worker||mt.disable_worker};return t}function No(e){for(var t=[],n=0;n<e.numberOfChannels;++n)t.push(e.getChannelData(n).buffer);return t}function er(e,t,n){var r=No(e);if(t.disable_worker){var a=Zo({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r});n(void 0,new Ve(a),e)}else{var s=new Xo;s.onmessage=function(o){n(void 0,new Ve(o.data),e)},s.postMessage({scale:t.scale,bits:t.bits,amplitude_scale:t.amplitude_scale,split_channels:t.split_channels,length:e.length,sample_rate:e.sampleRate,channels:r},r)}}function Oo(e,t,n,r){function a(o){o||(o=new DOMException("EncodingError")),r(o),r=function(){}}var s=e.decodeAudioData(t,function(o){er(o,n,r)},a);s&&s.catch(a)}Ve.create=function(t){return new Ve(t)};Ve.createFromAudio=function(e,t){var n=Go(e);if(e.audio_context&&e.array_buffer)return Oo(e.audio_context,e.array_buffer,n,t);if(e.audio_buffer)return er(e.audio_buffer,n,t);throw new TypeError("WaveformData.createFromAudio(): Pass either an AudioContext and ArrayBuffer, or an AudioBuffer object")};function Tt(e){this._inputData=e.waveformData,this._output_samples_per_pixel=e.scale,this._scale=this._inputData.scale,this._input_buffer_size=this._inputData.length;var t=this._input_buffer_size*this._inputData.scale,n=Math.ceil(t/this._output_samples_per_pixel),r=24,a=this._inputData.bits===8?1:2,s=r+n*2*this._inputData.channels*a;this._output_data=new ArrayBuffer(s),this.output_dataview=new DataView(this._output_data),this.output_dataview.setInt32(0,2,!0),this.output_dataview.setUint32(4,this._inputData.bits===8,!0),this.output_dataview.setInt32(8,this._inputData.sample_rate,!0),this.output_dataview.setInt32(12,this._output_samples_per_pixel,!0),this.output_dataview.setInt32(16,n,!0),this.output_dataview.setInt32(20,this._inputData.channels,!0),this._outputWaveformData=new Ve(this._output_data),this._input_index=0,this._output_index=0;var o=this._inputData.channels;this._min=new Array(o),this._max=new Array(o);for(var l=0;l<o;++l)this._input_buffer_size>0?(this._min[l]=this._inputData.channel(l).min_sample(this._input_index),this._max[l]=this._inputData.channel(l).max_sample(this._input_index)):(this._min[l]=0,this._max[l]=0);this._min_value=this._inputData.bits===8?-128:-32768,this._max_value=this._inputData.bits===8?127:32767,this._where=0,this._prev_where=0,this._stop=0,this._last_input_index=0}Tt.prototype.sample_at_pixel=function(e){return Math.floor(e*this._output_samples_per_pixel)};Tt.prototype.next=function(){for(var e=0,t=1e3,n=this._inputData.channels,r;this._input_index<this._input_buffer_size&&e<t;){for(;Math.floor(this.sample_at_pixel(this._output_index)/this._scale)===this._input_index;){if(this._output_index>0)for(var a=0;a<n;++a)r=this._outputWaveformData.channel(a),r.set_min_sample(this._output_index-1,this._min[a]),r.set_max_sample(this._output_index-1,this._max[a]);if(this._last_input_index=this._input_index,this._output_index++,this._where=this.sample_at_pixel(this._output_index),this._prev_where=this.sample_at_pixel(this._output_index-1),this._where!==this._prev_where)for(var s=0;s<n;++s)this._min[s]=this._max_value,this._max[s]=this._min_value}for(this._where=this.sample_at_pixel(this._output_index),this._stop=Math.floor(this._where/this._scale),this._stop>this._input_buffer_size&&(this._stop=this._input_buffer_size);this._input_index<this._stop;){for(var o=0;o<n;++o){r=this._inputData.channel(o);var l=r.min_sample(this._input_index);l<this._min[o]&&(this._min[o]=l),l=r.max_sample(this._input_index),l>this._max[o]&&(this._max[o]=l)}this._input_index++}e++}if(this._input_index<this._input_buffer_size)return!1;if(this._input_index!==this._last_input_index)for(var c=0;c<n;++c)r=this._outputWaveformData.channel(c),r.set_min_sample(this._output_index-1,this._min[c]),r.set_max_sample(this._output_index-1,this._max[c]);return!0};Tt.prototype.getOutputData=function(){return this._output_data};Ve.prototype={_getResampleOptions:function(t){var n={};if(n.scale=t.scale,n.width=t.width,!it(n.width)&&(typeof n.width!="number"||n.width<=0))throw new RangeError("WaveformData.resample(): width should be a positive integer value");if(!it(n.scale)&&(typeof n.scale!="number"||n.scale<=0))throw new RangeError("WaveformData.resample(): scale should be a positive integer value");if(!n.scale&&!n.width)throw new Error("WaveformData.resample(): Missing scale or width option");if(n.width&&(n.scale=Math.floor(this.duration*this.sample_rate/n.width)),n.scale<this.scale)throw new Error("WaveformData.resample(): Zoom level "+n.scale+" too low, minimum: "+this.scale);return n.abortSignal=t.abortSignal,n},resample:function(t){t=this._getResampleOptions(t),t.waveformData=this;for(var n=new Tt(t);!n.next(););return new Ve(n.getOutputData())},concat:function(){var t=this,n=Array.prototype.slice.call(arguments);n.forEach(function(a){if(t.channels!==a.channels||t.sample_rate!==a.sample_rate||t.bits!==a.bits||t.scale!==a.scale)throw new Error("WaveformData.concat(): Waveforms are incompatible")});var r=this._concatBuffers.apply(this,n);return Ve.create(r)},_concatBuffers:function(){for(var t=Array.prototype.slice.call(arguments),n=this._offset,r=n,a=0,s=[this].concat(t).map(function(g){return g._data.buffer}),o=0;o<s.length;o++){var l=s[o],c=new DataView(l).getInt32(16,!0);r+=l.byteLength-n,a+=c}for(var u=new ArrayBuffer(r),d=new DataView(s[0]),v=new DataView(u),p=0;p<n;p++)v.setUint8(p,d.getUint8(p));v.setInt32(16,a,!0);for(var f=0,C=new Uint8Array(u,n),x=0;x<s.length;x++){var b=s[x];C.set(new Uint8Array(b,n),f),f+=b.byteLength-n}return u},slice:function(t){var n=0,r=0;if(!it(t.startIndex)&&!it(t.endIndex)?(n=t.startIndex,r=t.endIndex):!it(t.startTime)&&!it(t.endTime)&&(n=this.at_time(t.startTime),r=this.at_time(t.endTime)),n<0)throw new RangeError("startIndex or startTime must not be negative");if(r<0)throw new RangeError("endIndex or endTime must not be negative");n>this.length&&(n=this.length),r>this.length&&(r=this.length),n>r&&(n=r);var a=r-n,s=24,o=this.bits===8?1:2,l=s+a*2*this.channels*o,c=new ArrayBuffer(l),u=new DataView(c);u.setInt32(0,2,!0),u.setUint32(4,this.bits===8,!0),u.setInt32(8,this.sample_rate,!0),u.setInt32(12,this.scale,!0),u.setInt32(16,a,!0),u.setInt32(20,this.channels,!0);for(var d=0;d<a*this.channels*2;d++){var 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 Ve(c)},_version:function(){return this._data.getInt32(0,!0)},get length(){return this._data.getUint32(16,!0)},get bits(){var e=!!this._data.getUint32(4,!0);return e?8:16},get duration(){return this.length*this.scale/this.sample_rate},get pixels_per_second(){return this.sample_rate/this.scale},get seconds_per_pixel(){return this.scale/this.sample_rate},get channels(){return this._version()===2?this._data.getInt32(20,!0):1},channel:function(t){if(t>=0&&t<this._channels.length)return this._channels[t];throw new RangeError("Invalid channel: "+t)},get sample_rate(){return this._data.getInt32(8,!0)},get scale(){return this._data.getInt32(12,!0)},_at:function(t){return this.bits===8?this._data.getInt8(this._offset+t):this._data.getInt16(this._offset+t*2,!0)},_set_at:function(t,n){return this.bits===8?this._data.setInt8(this._offset+t,n):this._data.setInt16(this._offset+t*2,n,!0)},at_time:function(t){return Math.floor(t*this.sample_rate/this.scale)},time:function(t){return t*this.scale/this.sample_rate},toJSON:function(){for(var t={version:2,channels:this.channels,sample_rate:this.sample_rate,samples_per_pixel:this.scale,bits:this.bits,length:this.length,data:[]},n=0;n<this.length;n++)for(var r=0;r<this.channels;r++)t.data.push(this.channel(r).min_sample(n)),t.data.push(this.channel(r).max_sample(n));return t},toArrayBuffer:function(){return this._data.buffer}};async function qt(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch waveform data: ${t.statusText}`);if(e.endsWith(".dat")){const r=await t.arrayBuffer();return Ve.create(r)}else{const r=await t.json();return Ve.create(r)}}function tr(e,t=0){const n=e.channel(t),r=e.bits,a=n.min_array(),s=n.max_array(),o=a.length,l=r===8?new Int8Array(o*2):new Int16Array(o*2);for(let c=0;c<o;c++)l[c*2]=a[c],l[c*2+1]=s[c];return{data:l,bits:r,length:o,sampleRate:e.sample_rate}}async function Yo(e,t=0){const n=await qt(e);return tr(n,t)}async function Ko(e){const t=await qt(e);return{sampleRate:t.sample_rate,channels:t.channels,duration:t.duration,samplesPerPixel:t.scale,length:t.length,bits:t.bits}}function nr(e,t,n=0,r,a){let s=e;if(r!==void 0&&a!==void 0){const p=e.scale,f=Math.floor(r/p),C=Math.ceil((r+a)/p);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 p=0;p<d;p++)v[p*2]=c[p],v[p*2+1]=u[p];return{data:v,bits:l,length:d}}function rr(e){return{id:e.id,start:parseFloat(e.begin),end:parseFloat(e.end),lines:e.lines,lang:e.language}}function Uo(e){return{id:e.id,begin:e.start.toFixed(3),end:e.end.toFixed(3),lines:e.lines,language:e.lang||"en"}}$.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
749
783
|
position: absolute;
|
|
750
784
|
top: 0;
|
|
751
785
|
background: ${e=>e.$color};
|
|
@@ -761,7 +795,7 @@
|
|
|
761
795
|
opacity: 0.5;
|
|
762
796
|
border-color: ${e=>e.$color};
|
|
763
797
|
}
|
|
764
|
-
|
|
798
|
+
`;$.div`
|
|
765
799
|
position: absolute;
|
|
766
800
|
bottom: 0;
|
|
767
801
|
left: 0;
|
|
@@ -777,7 +811,7 @@
|
|
|
777
811
|
pointer-events: none;
|
|
778
812
|
white-space: pre-wrap;
|
|
779
813
|
word-break: break-word;
|
|
780
|
-
|
|
814
|
+
`;$.textarea`
|
|
781
815
|
position: absolute;
|
|
782
816
|
bottom: 0;
|
|
783
817
|
left: 0;
|
|
@@ -797,7 +831,7 @@
|
|
|
797
831
|
outline: none;
|
|
798
832
|
border-color: #4CAF50;
|
|
799
833
|
}
|
|
800
|
-
|
|
834
|
+
`;$.div`
|
|
801
835
|
position: absolute;
|
|
802
836
|
top: 0;
|
|
803
837
|
left: 0;
|
|
@@ -808,7 +842,7 @@
|
|
|
808
842
|
padding: 4px;
|
|
809
843
|
justify-content: flex-start;
|
|
810
844
|
align-items: center;
|
|
811
|
-
|
|
845
|
+
`;$.button`
|
|
812
846
|
background: transparent;
|
|
813
847
|
border: 1px solid rgba(255, 255, 255, 0.5);
|
|
814
848
|
color: white;
|
|
@@ -830,12 +864,12 @@
|
|
|
830
864
|
&:active {
|
|
831
865
|
background: rgba(255, 255, 255, 0.3);
|
|
832
866
|
}
|
|
833
|
-
`;var
|
|
867
|
+
`;var Jo=$.div.attrs(e=>({style:{left:`${e.$left}px`,width:`${e.$width}px`}}))`
|
|
834
868
|
position: absolute;
|
|
835
869
|
top: 0;
|
|
836
870
|
height: 100%;
|
|
837
871
|
pointer-events: none; /* Let events pass through to children */
|
|
838
|
-
`,
|
|
872
|
+
`,qo=$.div`
|
|
839
873
|
position: absolute;
|
|
840
874
|
top: 0;
|
|
841
875
|
left: 0;
|
|
@@ -859,7 +893,7 @@
|
|
|
859
893
|
border-width: 3px;
|
|
860
894
|
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
|
|
861
895
|
}
|
|
862
|
-
`,
|
|
896
|
+
`,Qo=$.span`
|
|
863
897
|
font-size: 12px;
|
|
864
898
|
font-weight: 600;
|
|
865
899
|
color: ${e=>e.theme?.annotationLabelColor||"#2a2a2a"};
|
|
@@ -869,7 +903,7 @@
|
|
|
869
903
|
padding: 0 6px;
|
|
870
904
|
letter-spacing: 0.3px;
|
|
871
905
|
user-select: none;
|
|
872
|
-
`,
|
|
906
|
+
`,Sn=$.div`
|
|
873
907
|
position: absolute;
|
|
874
908
|
top: 0;
|
|
875
909
|
${e=>e.$position==="left"?"left: 0":"right: 0"};
|
|
@@ -904,13 +938,13 @@
|
|
|
904
938
|
opacity: 1;
|
|
905
939
|
background: ${e=>e.theme?.annotationResizeHandleActiveColor||"rgba(0, 0, 0, 0.7)"};
|
|
906
940
|
}
|
|
907
|
-
`,
|
|
941
|
+
`,ar=({annotationId:e,annotationIndex:t,startPosition:n,endPosition:r,label:a,color:s="#ff9800",isActive:o=!1,onClick:l,editable:c=!0})=>{const u=Math.max(0,r-n),d=`annotation-boundary-start-${t}`,{attributes:v,listeners:p,setActivatorNodeRef:f,isDragging:C}=_e.useDraggable({id:d,data:{annotationId:e,annotationIndex:t,edge:"start"},disabled:!c}),x=`annotation-boundary-end-${t}`,{attributes:b,listeners:g,setActivatorNodeRef:S,isDragging:w}=_e.useDraggable({id:x,data:{annotationId:e,annotationIndex:t,edge:"end"},disabled:!c});if(u<=0)return null;const m=k=>I=>{I.stopPropagation(),k?.(I)},y=k=>{k.stopPropagation()};return h.jsxs(Jo,{$left:n,$width:u,children:[h.jsx(qo,{$color:s,$isActive:o,onClick:l,children:a&&h.jsx(Qo,{children:a})}),c&&h.jsx(Sn,{ref:f,$position:"left",$isDragging:C,onClick:y,...p,onPointerDown:m(p?.onPointerDown),...v}),c&&h.jsx(Sn,{ref:S,$position:"right",$isDragging:w,onClick:y,...g,onPointerDown:m(g?.onPointerDown),...b})]})},es=$.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
|
|
908
942
|
position: relative;
|
|
909
943
|
display: flex;
|
|
910
944
|
${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
|
|
911
945
|
background: transparent;
|
|
912
946
|
z-index: 110;
|
|
913
|
-
`,
|
|
947
|
+
`,ts=$.div`
|
|
914
948
|
position: sticky;
|
|
915
949
|
z-index: 200;
|
|
916
950
|
left: 0;
|
|
@@ -918,16 +952,16 @@
|
|
|
918
952
|
width: ${e=>e.$controlWidth}px;
|
|
919
953
|
flex-shrink: 0;
|
|
920
954
|
background: transparent;
|
|
921
|
-
|
|
955
|
+
`,ns=$.div`
|
|
922
956
|
position: relative;
|
|
923
957
|
flex: 1;
|
|
924
958
|
padding-left: ${e=>e.$offset||0}px;
|
|
925
|
-
`,
|
|
959
|
+
`,or=({children:e,className:t,height:n=30,offset:r=0,width:a})=>{const{controls:{show:s,width:o}}=bt();return h.jsxs(es,{className:t,$height:n,$controlWidth:s?o:0,$width:a,children:[h.jsx(ts,{$controlWidth:s?o:0}),h.jsx(ns,{$offset:r,children:e})]})};$.div.attrs(e=>({style:{height:`${e.$height}px`}}))`
|
|
926
960
|
position: relative;
|
|
927
961
|
display: flex;
|
|
928
962
|
${e=>e.$width!==void 0&&`width: ${e.$width}px;`}
|
|
929
963
|
background: transparent;
|
|
930
|
-
|
|
964
|
+
`;$.div`
|
|
931
965
|
position: sticky;
|
|
932
966
|
z-index: 200;
|
|
933
967
|
left: 0;
|
|
@@ -941,16 +975,16 @@
|
|
|
941
975
|
font-size: 12px;
|
|
942
976
|
color: ${e=>e.theme?.textColorMuted||"#666"};
|
|
943
977
|
font-weight: bold;
|
|
944
|
-
|
|
978
|
+
`;$.div`
|
|
945
979
|
position: relative;
|
|
946
980
|
flex: 1;
|
|
947
981
|
padding-left: ${e=>e.$offset||0}px;
|
|
948
|
-
`;var
|
|
982
|
+
`;var rs=$.div`
|
|
949
983
|
background: ${e=>e.theme?.backgroundColor||"#fff"};
|
|
950
984
|
${e=>e.$height?`height: ${e.$height}px;`:"max-height: 200px;"}
|
|
951
985
|
overflow-y: auto;
|
|
952
986
|
padding: 8px;
|
|
953
|
-
`,
|
|
987
|
+
`,as=$.div`
|
|
954
988
|
padding: 12px;
|
|
955
989
|
margin-bottom: 6px;
|
|
956
990
|
border-left: 4px solid ${e=>e.$isActive?"#ff9800":"transparent"};
|
|
@@ -969,16 +1003,16 @@
|
|
|
969
1003
|
outline: 2px solid #ff9800;
|
|
970
1004
|
outline-offset: 2px;
|
|
971
1005
|
}
|
|
972
|
-
`,
|
|
1006
|
+
`,os=$.div`
|
|
973
1007
|
display: flex;
|
|
974
1008
|
justify-content: space-between;
|
|
975
1009
|
align-items: center;
|
|
976
1010
|
margin-bottom: 6px;
|
|
977
|
-
`,
|
|
1011
|
+
`,ss=$.div`
|
|
978
1012
|
display: flex;
|
|
979
1013
|
align-items: center;
|
|
980
1014
|
gap: 8px;
|
|
981
|
-
`,
|
|
1015
|
+
`,is=$.span`
|
|
982
1016
|
font-size: 11px;
|
|
983
1017
|
font-weight: 600;
|
|
984
1018
|
color: ${e=>e.theme?.textColorMuted||"#666"};
|
|
@@ -992,16 +1026,16 @@
|
|
|
992
1026
|
outline: 2px solid #ff9800;
|
|
993
1027
|
background: rgba(255, 152, 0, 0.1);
|
|
994
1028
|
}
|
|
995
|
-
`,
|
|
1029
|
+
`,ls=$.span`
|
|
996
1030
|
font-size: 12px;
|
|
997
1031
|
font-weight: 500;
|
|
998
1032
|
color: ${e=>e.theme?.textColorMuted||"#555"};
|
|
999
1033
|
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
1000
1034
|
letter-spacing: 0.5px;
|
|
1001
|
-
`,
|
|
1035
|
+
`,cs=$.div`
|
|
1002
1036
|
display: flex;
|
|
1003
1037
|
gap: 6px;
|
|
1004
|
-
`,
|
|
1038
|
+
`,us=$.button`
|
|
1005
1039
|
background: ${e=>e.theme?.surfaceColor||"#f5f5f5"};
|
|
1006
1040
|
border: 1px solid ${e=>e.theme?.borderColor||"#ccc"};
|
|
1007
1041
|
color: ${e=>e.theme?.textColor||"#333"};
|
|
@@ -1020,7 +1054,7 @@
|
|
|
1020
1054
|
&:active {
|
|
1021
1055
|
transform: scale(0.95);
|
|
1022
1056
|
}
|
|
1023
|
-
`,
|
|
1057
|
+
`,ds=$.div`
|
|
1024
1058
|
font-size: 14px;
|
|
1025
1059
|
line-height: 1.6;
|
|
1026
1060
|
color: ${e=>e.theme?.textColor||"#2a2a2a"};
|
|
@@ -1035,9 +1069,9 @@
|
|
|
1035
1069
|
outline: 2px solid #ff9800;
|
|
1036
1070
|
background: rgba(255, 152, 0, 0.1);
|
|
1037
1071
|
}
|
|
1038
|
-
`,
|
|
1039
|
-
`)},d(k)},
|
|
1040
|
-
`)})]},m.id)})})},
|
|
1072
|
+
`,fs=({annotations:e,activeAnnotationId:t,shouldScrollToActive:n=!1,scrollActivePosition:r="center",scrollActiveContainer:a="nearest",editable:s=!1,controls:o=[],annotationListConfig:l,height:c,onAnnotationClick:u,onAnnotationUpdate:d,renderAnnotationItem:v})=>{const p=i.useRef(null),f=i.useRef(null),C=i.useRef(void 0);i.useEffect(()=>{}),i.useEffect(()=>{const m=f.current;if(!m)return;const y=()=>{};return m.addEventListener("scroll",y),()=>m.removeEventListener("scroll",y)},[]),i.useEffect(()=>{t&&p.current&&n&&p.current.scrollIntoView({behavior:"smooth",block:r,container:a}),C.current=t},[t,n,r,a]);const x=m=>{if(isNaN(m)||!isFinite(m))return"0:00.000";const y=Math.floor(m/60),k=(m%60).toFixed(3);return`${y}:${k.padStart(6,"0")}`},b=(m,y)=>{if(!s||!d)return;const k=[...e];k[m]={...k[m],lines:y.split(`
|
|
1073
|
+
`)},d(k)},g=(m,y)=>{if(!s||!d)return;const k=y.trim();if(!k)return;const I=[...e];I[m]={...I[m],id:k},d(I)},S=(m,y,k)=>{if(!d)return;const I=[...e];m.action(I[k],k,I,l||{}),d(I)},w=m=>m.replace(/\./g," ");return h.jsx(rs,{ref:f,$height:c,children:e.map((m,y)=>{const k=m.id===t,I=()=>u?.(m);return v?h.jsx("div",{ref:k?p:null,children:v({annotation:m,index:y,isActive:k,onClick:I,formatTime:x})},m.id):h.jsxs(as,{ref:k?p:null,$isActive:k,onClick:I,children:[h.jsxs(os,{children:[h.jsxs(ss,{children:[h.jsx(is,{$isEditable:s,contentEditable:s,suppressContentEditableWarning:!0,onBlur:A=>g(y,A.currentTarget.textContent||""),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),A.currentTarget.blur())},children:m.id}),h.jsxs(ls,{children:[x(m.start)," - ",x(m.end)]})]}),o.length>0&&h.jsx(cs,{onClick:A=>A.stopPropagation(),children:o.map((A,R)=>h.jsx(us,{title:A.title,onClick:()=>S(A,m,y),children:A.text?A.text:h.jsx("i",{className:w(A.class||"")})},R))})]}),h.jsx(ds,{$isEditable:s,contentEditable:s,suppressContentEditableWarning:!0,onBlur:A=>b(y,A.currentTarget.textContent||""),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),A.currentTarget.blur())},children:m.lines.join(`
|
|
1074
|
+
`)})]},m.id)})})},sr=i.memo(fs),ms=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return h.jsxs(Et,{className:r,children:[h.jsx(Rt,{type:"checkbox",id:"continuous-play",className:"continuous-play",checked:e,onChange:a,disabled:n}),h.jsx(Dt,{htmlFor:"continuous-play",children:"Continuous Play"})]})},hs=({checked:e,onChange:t,disabled:n=!1,className:r})=>{const a=s=>{t(s.target.checked)};return h.jsxs(Et,{className:r,children:[h.jsx(Rt,{type:"checkbox",id:"link-endpoints",className:"link-endpoints",checked:e,onChange:a,disabled:n}),h.jsx(Dt,{htmlFor:"link-endpoints",children:"Link Endpoints"})]})},ps=({checked:e,onChange:t,className:n})=>h.jsxs(Et,{className:n,children:[h.jsx(Rt,{type:"checkbox",id:"editable-annotations",checked:e,onChange:r=>t(r.target.checked)}),h.jsx(Dt,{htmlFor:"editable-annotations",children:"Editable Annotations"})]}),gs=$.button`
|
|
1041
1075
|
padding: 0.5rem 1rem;
|
|
1042
1076
|
background: ${e=>e.theme?.surfaceColor||"#f5f5f5"};
|
|
1043
1077
|
color: ${e=>e.theme?.textColor||"#333"};
|
|
@@ -1063,7 +1097,7 @@
|
|
|
1063
1097
|
opacity: 0.6;
|
|
1064
1098
|
cursor: not-allowed;
|
|
1065
1099
|
}
|
|
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`
|
|
1100
|
+
`,bs=({annotations:e,filename:t="annotations.json",disabled:n=!1,className:r,children:a="Download JSON"})=>{const s=()=>{if(e.length===0)return;const o=e.map(v=>Uo(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 h.jsx(gs,{onClick:s,disabled:n||e.length===0,className:r,title:e.length===0?"No annotations to download":"Download the annotations as JSON",children:a})};function ir(){const[e,t]=i.useState("hh:mm:ss.uuu");return{timeFormat:e,setTimeFormat:t,formatTime:a=>lt(a,e),parseTime:a=>On(a,e)}}const vs=[256,512,1024,2048,4096,8192];function lr({initialSamplesPerPixel:e,zoomLevels:t=vs}){const[n,r]=i.useState(()=>{const u=t.indexOf(e);return u!==-1?u:Math.floor(t.length/2)}),a=t[n],s=n>0,o=n<t.length-1,l=i.useCallback(()=>{r(u=>Math.max(0,u-1))},[]),c=i.useCallback(()=>{r(u=>Math.min(t.length-1,u+1))},[t.length]);return{samplesPerPixel:a,zoomIn:l,zoomOut:c,canZoomIn:s,canZoomOut:o}}function cr({playoutRef:e,initialVolume:t=1,onVolumeChange:n}){const[r,a]=i.useState(t),s=i.useCallback(o=>{a(o),e.current&&e.current.setMasterGain(o),n?.(o)},[e,n]);return{masterVolume:r,setMasterVolume:s}}const Cs=(e=256)=>{const t=i.useRef(null),n=i.useCallback((r,a,s)=>{const o=new Z.Analyser("fft",e);return r.connect(o),r.connect(a),t.current=o,function(){o.dispose(),t.current=null}},[e]);return{analyserRef:t,masterEffects:n}};function Nt(e){const{audioBuffer:t,startSample:n,offsetSamples:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate,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 p=e.durationSamples??v;return{id:ur(),audioBuffer:t,startSample:n,durationSamples:p,offsetSamples:r,sampleRate:d,sourceDurationSamples:v,gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}}function xs(e){const{audioBuffer:t,startTime:n,offset:r=0,gain:a=1,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u}=e,d=t?.sampleRate??e.sampleRate??u?.sample_rate;if(d===void 0)throw new Error("createClipFromSeconds: sampleRate is required when audioBuffer is not provided (can use waveformData.sample_rate)");const 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 p=e.duration??v;return Nt({audioBuffer:t,startSample:Math.round(n*d),durationSamples:Math.round(p*d),offsetSamples:Math.round(r*d),sampleRate:d,sourceDurationSamples:Math.ceil(v*d),gain:a,name:s,color:o,fadeIn:l,fadeOut:c,waveformData:u})}function ws(e){const{name:t,clips:n=[],muted:r=!1,soloed:a=!1,volume:s=1,pan:o=0,color:l,height:c}=e;return{id:ur(),name:t,clips:n,muted:r,soloed:a,volume:s,pan:o,color:l,height:c}}function ur(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function ys(e,t={}){const{progressive:n=!1}=t,[r,a]=i.useState([]),[s,o]=i.useState(!0),[l,c]=i.useState(null),[u,d]=i.useState(0),v=e.length;return i.useEffect(()=>{if(e.length===0){a([]),o(!1),d(0);return}let p=!1;const f=new Map,C=(b,g,S)=>{const w=S??b.audioBuffer;if(!w&&!b.waveformData)throw new Error(`Track ${g+1}: Must provide src, audioBuffer, or waveformData`);const m=w?.duration??b.waveformData?.duration,y=xs({audioBuffer:w,startTime:b.startTime??0,duration:b.duration??m,offset:b.offset??0,name:b.name||`Track ${g+1}`,fadeIn:b.fadeIn,fadeOut:b.fadeOut,waveformData:b.waveformData});if(isNaN(y.startSample)||isNaN(y.durationSamples)||isNaN(y.offsetSamples))throw console.error("Invalid clip values:",y),new Error(`Invalid clip values for track ${g+1}`);return{...ws({name:b.name||`Track ${g+1}`,clips:[y],muted:b.muted??!1,soloed:b.soloed??!1,volume:b.volume??1,pan:b.pan??0,color:b.color}),effects:b.effects,renderMode:b.renderMode,spectrogramConfig:b.spectrogramConfig,spectrogramColorMap:b.spectrogramColorMap}};return(async()=>{try{o(!0),c(null),d(0);const b=Tn.getContext().rawContext,g=e.map(async(w,m)=>{if(w.audioBuffer){const R=C(w,m,w.audioBuffer);return n&&!p&&(f.set(m,R),d(E=>E+1),a(Array.from({length:e.length},(E,M)=>f.get(M)).filter(E=>E!==void 0))),R}if(!w.src&&w.waveformData){const R=C(w,m);return n&&!p&&(f.set(m,R),d(E=>E+1),a(Array.from({length:e.length},(E,M)=>f.get(M)).filter(E=>E!==void 0))),R}if(!w.src)throw new Error(`Track ${m+1}: Must provide src, audioBuffer, or waveformData`);const y=await fetch(w.src);if(!y.ok)throw new Error(`Failed to fetch ${w.src}: ${y.statusText}`);const k=await y.arrayBuffer(),I=await b.decodeAudioData(k);if(!I||!I.sampleRate||!I.duration)throw new Error(`Invalid audio buffer for ${w.src}`);const A=C(w,m,I);return n&&!p&&(f.set(m,A),d(R=>R+1),a(Array.from({length:e.length},(R,E)=>f.get(E)).filter(R=>R!==void 0))),A}),S=await Promise.all(g);p||(n||(a(S),d(S.length)),o(!1))}catch(b){if(!p){const g=b instanceof Error?b.message:"Unknown error loading audio";c(g),o(!1),console.error("Error loading audio tracks:",b)}}})(),()=>{p=!0}},[e,n]),{tracks:r,loading:s,error:l,loadedCount:u,totalCount:v}}function ks({tracks:e,onTracksChange:t,samplesPerPixel:n,sampleRate:r}){const a=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:p,clipIndex:f,boundary:C}=v.data.current;if(C)return{...d,scaleX:1,scaleY:1};const x=e[p];if(!x)return{...d,scaleX:1,scaleY:1};const b=x.clips[f];if(!b)return{...d,scaleX:1,scaleY:1};const g=b.startSample/r,S=b.durationSamples/r,w=d.x*n/r;let m=g+w;const y=[...x.clips].sort((M,F)=>M.startSample-F.startSample),k=y.findIndex(M=>M===b);m=Math.max(0,m);const I=k>0?y[k-1]:null;if(I){const M=(I.startSample+I.durationSamples)/r;m=Math.max(m,M)}const A=k<y.length-1?y[k+1]:null;if(A){const M=m+S,F=A.startSample/r;M>F&&(m=F-S)}const E=(m-g)*r/n;return{...d,x:E,scaleX:1,scaleY:1}},[e,n,r]),o=i.useCallback(u=>{const{active:d}=u,{boundary:v}=d.data.current;if(!v){a.current=null;return}const{trackIndex:p,clipIndex:f}=d.data.current,x=e[p]?.clips[f];x&&(a.current={offsetSamples:x.offsetSamples,durationSamples:x.durationSamples,startSample:x.startSample})},[e]),l=i.useCallback(u=>{const{active:d,delta:v}=u,{boundary:p}=d.data.current;if(!p||!a.current)return;const{trackIndex:f,clipIndex:C}=d.data.current,x=v.x*n,b=Math.floor(.1*r),g=a.current,S=e.map((w,m)=>{if(m!==f)return w;const y=[...w.clips].sort((A,R)=>A.startSample-R.startSample),k=y.findIndex(A=>A===w.clips[C]),I=w.clips.map((A,R)=>{if(R!==C)return A;const E=A.sourceDurationSamples;if(p==="left"){let M=Math.floor(x);const F=-g.startSample;M<F&&(M=F);const T=-g.offsetSamples;M<T&&(M=T);const P=k>0?y[k-1]:null;if(P){const q=P.startSample+P.durationSamples-g.startSample;M<q&&(M=q)}const H=g.durationSamples-b;M>H&&(M=H);const O=g.offsetSamples+M,j=g.durationSamples-M,L=g.startSample+M;return{...A,offsetSamples:O,durationSamples:j,startSample:L}}else{let M=Math.floor(g.durationSamples+x);M=Math.max(b,M),g.offsetSamples+M>E&&(M=E-g.offsetSamples);const F=k<y.length-1?y[k+1]:null;return F&&g.startSample+M>F.startSample&&(M=F.startSample-g.startSample,M=Math.max(b,M)),{...A,durationSamples:M}}});return{...w,clips:I}});t(S)},[e,t,n,r]),c=i.useCallback(u=>{const{active:d,delta:v}=u,{trackIndex:p,clipIndex:f,boundary:C}=d.data.current,x=v.x*n;if(C){a.current=null;return}const b=e.map((g,S)=>{if(S!==p)return g;const w=[...g.clips].sort((k,I)=>k.startSample-I.startSample),m=w.findIndex(k=>k===g.clips[f]),y=g.clips.map((k,I)=>{if(I!==f)return k;let A=Math.floor(k.startSample+x);A=Math.max(0,A);const R=m>0?w[m-1]:null;if(R){const M=R.startSample+R.durationSamples;A=Math.max(A,M)}const E=m<w.length-1?w[m+1]:null;return E&&A+k.durationSamples>E.startSample&&(A=E.startSample-k.durationSamples),{...k,startSample:A}});return{...g,clips:y}});t(b)},[e,t,n,r]);return{onDragStart:o,onDragMove:l,onDragEnd:c,collisionModifier:s}}const zt=.01;function dr({annotations:e,onAnnotationsChange:t,samplesPerPixel:n,sampleRate:r,duration:a,linkEndpoints:s}){const o=i.useRef(null),l=i.useCallback(d=>{const{active:v}=d,p=v.data.current;if(!p||p.annotationIndex===void 0){o.current=null;return}const f=e[p.annotationIndex];f&&(o.current={start:f.start,end:f.end,annotationIndex:p.annotationIndex})},[e]),c=i.useCallback(d=>{const{active:v,delta:p}=d;if(!o.current)return;const f=v.data.current;if(!f)return;const{edge:C,annotationIndex:x}=f,b=o.current,g=p.x*n/r,S=C==="start"?b.start+g:b.end+g,w=Ss({annotationIndex:x,newTime:S,isDraggingStart:C==="start",annotations:e,duration:a,linkEndpoints:s});t(w)},[e,t,n,r,a,s]),u=i.useCallback(()=>{o.current=null},[]);return{onDragStart:l,onDragMove:c,onDragEnd:u}}function Ss({annotationIndex:e,newTime:t,isDraggingStart:n,annotations:r,duration:a,linkEndpoints:s}){const o=[...r],l=r[e];if(n){const c=Math.min(l.end-.1,Math.max(0,t)),u=c-l.start;if(o[e]={...l,start:c},s&&e>0){const d=o[e-1];Math.abs(d.end-l.start)<zt?o[e-1]={...d,end:Math.max(d.start+.1,d.end+u)}:c<=d.end&&(o[e]={...o[e],start:d.end})}else!s&&e>0&&c<o[e-1].end&&(o[e-1]={...o[e-1],end:c})}else{const c=Math.max(l.start+.1,Math.min(t,a)),u=c-l.end;if(o[e]={...l,end:c},s&&e<o.length-1){const d=o[e+1];if(Math.abs(d.start-l.end)<zt){const v=d.start+u;o[e+1]={...d,start:Math.min(d.end-.1,v)};let p=e+1;for(;p<o.length-1;){const f=o[p],C=o[p+1];if(Math.abs(C.start-f.end)<zt){const x=f.end-r[p].end;o[p+1]={...C,start:Math.min(C.end-.1,C.start+x)},p++}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 p=o[v],f=o[v+1];if(p.end>f.start)o[v+1]={...f,start:p.end},v++;else break}}}return o}function As(e={}){const{touchOptimized:t=!1,touchDelay:n=250,touchTolerance:r=5,mouseDistance:a=1}=e,s=_e.useSensor(_e.MouseSensor,{activationConstraint:{distance:a}}),o=_e.useSensor(_e.TouchSensor,{activationConstraint:t?{delay:n,tolerance:r}:{distance:a}}),l=_e.useSensor(_e.PointerSensor,{activationConstraint:{distance:a}});return _e.useSensors(...t?[s,o]:[l])}const Is=e=>{const{tracks:t,onTracksChange:n,sampleRate:r}=e,{currentTimeRef:a}=Re(),{selectedTrackId:s}=De(),o=i.useCallback((c,u,d)=>{const{sampleRate:v,samplesPerPixel:p}=e,f=t[c];if(!f)return!1;const C=f.clips[u];if(!C)return!1;const x=C.startSample/v,b=(C.startSample+C.durationSamples)/v;if(d<=x||d>=b)return console.warn("Split time is outside clip bounds"),!1;const g=Math.round(d*v),S=Math.floor(g/p),w=C.startSample+C.durationSamples,m=S*p,y=C.startSample,k=m-y,I=m,A=w-I,R=m-C.startSample,E=Nt({audioBuffer:C.audioBuffer,startSample:y,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=Nt({audioBuffer:C.audioBuffer,startSample:I,durationSamples:A,offsetSamples:C.offsetSamples+R,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}),F=[...f.clips];F.splice(u,1,E,M);const T=[...t];return T[c]={...f,clips:F},n(T),!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=a.current??0;for(let v=0;v<u.clips.length;v++){const p=u.clips[v],f=p.startSample/r,C=(p.startSample+p.durationSamples)/r;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,a,s,o,r]),splitClipAt:o}},Mt=e=>{const{shortcuts:t,enabled:n=!0}=e,r=i.useCallback(a=>{if(!n)return;const s=a.target;if(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.isContentEditable)return;const o=t.find(l=>{const c=a.key.toLowerCase()===l.key.toLowerCase()||a.key===l.key,u=l.ctrlKey===void 0||a.ctrlKey===l.ctrlKey,d=l.shiftKey===void 0||a.shiftKey===l.shiftKey,v=l.metaKey===void 0||a.metaKey===l.metaKey,p=l.altKey===void 0||a.altKey===l.altKey;return c&&u&&d&&v&&p});o&&(o.preventDefault!==!1&&a.preventDefault(),o.action())},[t,n]);i.useEffect(()=>{if(n)return window.addEventListener("keydown",r),()=>{window.removeEventListener("keydown",r)}},[r,n])},$s=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("+")},Ms=(e={})=>{const{enabled:t=!0,additionalShortcuts:n=[],shortcuts:r}=e,{isPlaying:a}=Re(),{setCurrentTime:s,play:o,pause:l,stop:c}=he(),{playoutRef:u}=Ae(),d=i.useCallback(()=>{a?l():o()},[a,o,l]),v=i.useCallback(()=>{c()},[c]),p=i.useCallback(()=>{a&&u.current?(u.current.stop(),s(0),o(0)):s(0)},[a,u,s,o]),C=r??[...[{key:" ",action:d,description:"Play/Pause",preventDefault:!0},{key:"Escape",action:v,description:"Stop",preventDefault:!0},{key:"0",action:p,description:"Rewind to start",preventDefault:!0}],...n];return Mt({shortcuts:C,enabled:t}),{rewindToStart:p,togglePlayPause:d,stopPlayback:v,shortcuts:C}},Ht=.01,St=.01;function Es({annotations:e,activeAnnotationId:t,onAnnotationsChange:n,onActiveAnnotationChange:r,duration:a,linkEndpoints:s,continuousPlay:o=!1,enabled:l=!0,scrollContainerRef:c,samplesPerPixel:u,sampleRate:d,controlsWidth:v=0,onPlay:p}){const f=i.useMemo(()=>t?e.findIndex(R=>R.id===t):-1,[e,t]),C=i.useCallback(R=>{if(!c?.current||!u||!d)return;const E=e.find(B=>B.id===R);if(!E)return;const M=c.current,F=M.clientWidth,T=E.start*d/u+v,P=E.end*d/u+v,H=(T+P)/2,O=M.scrollLeft,j=O,L=O+F;if(T<j||P>L){const B=Math.max(0,H-F/2);M.scrollTo({left:B,behavior:"smooth"})}},[e,c,u,d,v]);i.useEffect(()=>{t&&c?.current&&u&&d&&C(t)},[t,C,c,u,d]);const x=i.useCallback(R=>{if(f<0)return;const E=e[f],M=Math.max(0,Math.min(E.end-.1,E.start+R)),F=M-E.start,T=[...e];if(T[f]={...E,start:M},s&&f>0){const P=T[f-1];Math.abs(P.end-E.start)<Ht&&(T[f-1]={...P,end:Math.max(P.start+.1,P.end+F)})}else if(!s&&f>0){const P=T[f-1];M<P.end&&(T[f-1]={...P,end:M})}n(T)},[e,f,s,n]),b=i.useCallback(R=>{if(f<0)return;const E=e[f],M=Math.max(E.start+.1,Math.min(a,E.end+R)),F=M-E.end,T=[...e];if(T[f]={...E,end:M},s&&f<e.length-1){const P=T[f+1];if(Math.abs(P.start-E.end)<Ht){const H=Math.min(P.end-.1,P.start+F);T[f+1]={...P,start:H};let O=f+1;for(;O<T.length-1;){const j=T[O],L=T[O+1];if(Math.abs(L.start-e[O].end)<Ht){const B=j.end-e[O].end;T[O+1]={...L,start:Math.min(L.end-.1,L.start+B)},O++}else break}}}else if(!s&&f<e.length-1){const P=T[f+1];if(M>P.start){T[f+1]={...P,start:M};let H=f+1;for(;H<T.length-1;){const O=T[H],j=T[H+1];if(O.end>j.start)T[H+1]={...j,start:O.end},H++;else break}}}n(T)},[e,f,a,s,n]),g=i.useCallback(()=>{!r||e.length===0||(f<=0?r(e[e.length-1].id):r(e[f-1].id))},[e,f,r]),S=i.useCallback(()=>{!r||e.length===0||(f<0||f>=e.length-1?r(e[0].id):r(e[f+1].id))},[e,f,r]),w=i.useCallback(()=>{!r||e.length===0||r(e[0].id)},[e,r]),m=i.useCallback(()=>{!r||e.length===0||r(e[e.length-1].id)},[e,r]),y=i.useCallback(()=>{r&&r(null)},[r]),k=i.useCallback(()=>{if(f<0||!p)return;const R=e[f],E=o?void 0:R.end-R.start;p(R.start,E)},[e,f,o,p]),I=i.useMemo(()=>[{key:"[",action:()=>x(-St),description:"Move annotation start earlier",preventDefault:!0},{key:"]",action:()=>x(St),description:"Move annotation start later",preventDefault:!0},{key:"{",shiftKey:!0,action:()=>b(-St),description:"Move annotation end earlier",preventDefault:!0},{key:"}",shiftKey:!0,action:()=>b(St),description:"Move annotation end later",preventDefault:!0},{key:"Enter",action:k,description:"Play selected annotation",preventDefault:!0}],[x,b,k]),A=i.useMemo(()=>[{key:"ArrowUp",action:g,description:"Select previous annotation",preventDefault:!0},{key:"ArrowLeft",action:g,description:"Select previous annotation",preventDefault:!0},{key:"ArrowDown",action:S,description:"Select next annotation",preventDefault:!0},{key:"ArrowRight",action:S,description:"Select next annotation",preventDefault:!0},{key:"Home",action:w,description:"Select first annotation",preventDefault:!0},{key:"End",action:m,description:"Select last annotation",preventDefault:!0},{key:"Escape",action:y,description:"Deselect annotation",preventDefault:!0}],[g,S,w,m,y]);return Mt({shortcuts:I,enabled:l&&f>=0}),Mt({shortcuts:A,enabled:l&&e.length>0&&!!r}),{moveStartBoundary:x,moveEndBoundary:b,selectPrevious:g,selectNext:S,selectFirst:w,selectLast:m,clearSelection:y,scrollToAnnotation:C,playActiveAnnotation:k}}function Rs(e){const t=e.reduce((a,s)=>a+s.length,0),n=new Float32Array(t);let r=0;for(const a of e)n.set(a,r),r+=a.length;return n}function Ds(e,t,n,r=1){const a=e.createBuffer(r,t.length,n),s=new Float32Array(t);return a.copyToChannel(s,0),a}function An(e,t,n=16){const r=Math.ceil(e.length/t),a=n===8?new Int8Array(r*2):new Int16Array(r*2),s=2**(n-1);for(let o=0;o<r;o++){const l=o*t,c=Math.min(l+t,e.length);let u=0,d=0;for(let v=l;v<c;v++){const p=e[v];p<u&&(u=p),p>d&&(d=p)}a[o*2]=Math.floor(u*s),a[o*2+1]=Math.floor(d*s)}return a}function Ts(e,t,n,r,a=16){const s=2**(a-1),o=r%n;let l=0;if(o>0&&e.length>0){const d=n-o,v=Math.min(d,t.length);let p=e[e.length-2]/s,f=e[e.length-1]/s;for(let g=0;g<v;g++){const S=t[g];S<p&&(p=S),S>f&&(f=S)}const C=new(a===8?Int8Array:Int16Array)(e.length);C.set(e),C[e.length-2]=Math.floor(p*s),C[e.length-1]=Math.floor(f*s),l=v;const x=An(t.slice(l),n,a),b=new(a===8?Int8Array:Int16Array)(C.length+x.length);return b.set(C),b.set(x,C.length),b}const c=An(t.slice(l),n,a),u=new(a===8?Int8Array:Int16Array)(e.length+c.length);return u.set(e),u.set(c,e.length),u}function Bs(e,t={}){const{channelCount:n=1,samplesPerPixel:r=1024}=t,[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(0),[d,v]=i.useState(new Int16Array(0)),[p,f]=i.useState(null),[C,x]=i.useState(null),[b,g]=i.useState(0),[S,w]=i.useState(0),m=16,y=i.useRef(!1),k=i.useRef(null),I=i.useRef(null),A=i.useRef([]),R=i.useRef(0),E=i.useRef(null),M=i.useRef(0),F=i.useRef(!1),T=i.useRef(!1),P=i.useCallback(async()=>{if(!y.current)try{const B=Z.getContext(),q=new URL("data:text/javascript;base64,InVzZSBzdHJpY3QiOwoKLy8gc3JjL3dvcmtsZXQvcmVjb3JkaW5nLXByb2Nlc3Nvci53b3JrbGV0LnRzCnZhciBSZWNvcmRpbmdQcm9jZXNzb3IgPSBjbGFzcyBleHRlbmRzIEF1ZGlvV29ya2xldFByb2Nlc3NvciB7CiAgY29uc3RydWN0b3IoKSB7CiAgICBzdXBlcigpOwogICAgdGhpcy5idWZmZXJTaXplID0gMDsKICAgIHRoaXMuYnVmZmVycyA9IFtdOwogICAgdGhpcy5zYW1wbGVzQ29sbGVjdGVkID0gMDsKICAgIHRoaXMuaXNSZWNvcmRpbmcgPSBmYWxzZTsKICAgIHRoaXMuY2hhbm5lbENvdW50ID0gMTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSAoZXZlbnQpID0+IHsKICAgICAgY29uc3QgeyBjb21tYW5kLCBzYW1wbGVSYXRlOiBzYW1wbGVSYXRlMiwgY2hhbm5lbENvdW50IH0gPSBldmVudC5kYXRhOwogICAgICBpZiAoY29tbWFuZCA9PT0gInN0YXJ0IikgewogICAgICAgIHRoaXMuaXNSZWNvcmRpbmcgPSB0cnVlOwogICAgICAgIHRoaXMuY2hhbm5lbENvdW50ID0gY2hhbm5lbENvdW50IHx8IDE7CiAgICAgICAgdGhpcy5idWZmZXJTaXplID0gTWF0aC5mbG9vcigoc2FtcGxlUmF0ZTIgfHwgNDhlMykgKiAwLjAxNik7CiAgICAgICAgdGhpcy5idWZmZXJzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCB0aGlzLmNoYW5uZWxDb3VudDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmJ1ZmZlcnNbaV0gPSBuZXcgRmxvYXQzMkFycmF5KHRoaXMuYnVmZmVyU2l6ZSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuc2FtcGxlc0NvbGxlY3RlZCA9IDA7CiAgICAgIH0gZWxzZSBpZiAoY29tbWFuZCA9PT0gInN0b3AiKSB7CiAgICAgICAgdGhpcy5pc1JlY29yZGluZyA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPiAwKSB7CiAgICAgICAgICB0aGlzLmZsdXNoQnVmZmVycygpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKICB9CiAgcHJvY2VzcyhpbnB1dHMsIG91dHB1dHMsIHBhcmFtZXRlcnMpIHsKICAgIGlmICghdGhpcy5pc1JlY29yZGluZykgewogICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIGNvbnN0IGlucHV0ID0gaW5wdXRzWzBdOwogICAgaWYgKCFpbnB1dCB8fCBpbnB1dC5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICBjb25zdCBmcmFtZUNvdW50ID0gaW5wdXRbMF0ubGVuZ3RoOwogICAgZm9yIChsZXQgY2hhbm5lbCA9IDA7IGNoYW5uZWwgPCBNYXRoLm1pbihpbnB1dC5sZW5ndGgsIHRoaXMuY2hhbm5lbENvdW50KTsgY2hhbm5lbCsrKSB7CiAgICAgIGNvbnN0IGlucHV0Q2hhbm5lbCA9IGlucHV0W2NoYW5uZWxdOwogICAgICBjb25zdCBidWZmZXIgPSB0aGlzLmJ1ZmZlcnNbY2hhbm5lbF07CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZnJhbWVDb3VudDsgaSsrKSB7CiAgICAgICAgYnVmZmVyW3RoaXMuc2FtcGxlc0NvbGxlY3RlZCArIGldID0gaW5wdXRDaGFubmVsW2ldOwogICAgICB9CiAgICB9CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgKz0gZnJhbWVDb3VudDsKICAgIGlmICh0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPj0gdGhpcy5idWZmZXJTaXplKSB7CiAgICAgIHRoaXMuZmx1c2hCdWZmZXJzKCk7CiAgICB9CiAgICByZXR1cm4gdHJ1ZTsKICB9CiAgZmx1c2hCdWZmZXJzKCkgewogICAgY29uc3Qgc2FtcGxlcyA9IHRoaXMuYnVmZmVyc1swXS5zbGljZSgwLCB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQpOwogICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgc2FtcGxlcywKICAgICAgc2FtcGxlUmF0ZSwKICAgICAgY2hhbm5lbENvdW50OiB0aGlzLmNoYW5uZWxDb3VudAogICAgfSk7CiAgICB0aGlzLnNhbXBsZXNDb2xsZWN0ZWQgPSAwOwogIH0KfTsKcmVnaXN0ZXJQcm9jZXNzb3IoInJlY29yZGluZy1wcm9jZXNzb3IiLCBSZWNvcmRpbmdQcm9jZXNzb3IpOwovLyMgc291cmNlTWFwcGluZ1VSTD1yZWNvcmRpbmctcHJvY2Vzc29yLndvcmtsZXQuanMubWFw",typeof document>"u"?require("url").pathToFileURL(__filename).href:Vt&&Vt.tagName.toUpperCase()==="SCRIPT"&&Vt.src||new URL("index.js",document.baseURI).href).href;await B.addAudioWorkletModule(q),y.current=!0}catch(B){throw console.error("Failed to load AudioWorklet module:",B),new Error("Failed to load recording processor")}},[]),H=i.useCallback(async()=>{if(!e){x(new Error("No microphone stream available"));return}try{x(null);const B=Z.getContext();B.state==="suspended"&&await B.resume(),await P();const q=B.createMediaStreamSource(e);I.current=q;const U=B.createAudioWorkletNode("recording-processor");k.current=U,q.connect(U),U.port.onmessage=te=>{const{samples:Q}=te.data;A.current.push(Q),R.current+=Q.length,v(le=>Ts(le,Q,r,R.current-Q.length,m))},U.port.postMessage({command:"start",sampleRate:B.sampleRate,channelCount:n}),A.current=[],R.current=0,v(new Int16Array(0)),f(null),g(0),w(0),F.current=!0,T.current=!1,s(!0),l(!1),M.current=performance.now();const ie=()=>{if(F.current&&!T.current){const te=(performance.now()-M.current)/1e3;u(te),E.current=requestAnimationFrame(ie)}};ie()}catch(B){console.error("Failed to start recording:",B),x(B instanceof Error?B:new Error("Failed to start recording"))}},[e,n,r,P,a,o]),O=i.useCallback(async()=>{if(!a)return null;try{if(k.current){if(k.current.port.postMessage({command:"stop"}),I.current)try{I.current.disconnect(k.current)}catch{}k.current.disconnect()}E.current!==null&&(cancelAnimationFrame(E.current),E.current=null);const B=Rs(A.current),U=Z.getContext().rawContext,ie=Ds(U,B,U.sampleRate,n);return f(ie),u(ie.duration),F.current=!1,T.current=!1,s(!1),l(!1),g(0),ie}catch(B){return console.error("Failed to stop recording:",B),x(B instanceof Error?B:new Error("Failed to stop recording")),null}},[a,n]),j=i.useCallback(()=>{a&&!o&&(E.current!==null&&(cancelAnimationFrame(E.current),E.current=null),T.current=!0,l(!0))},[a,o]),L=i.useCallback(()=>{if(a&&o){T.current=!1,l(!1),M.current=performance.now()-c*1e3;const B=()=>{if(F.current&&!T.current){const q=(performance.now()-M.current)/1e3;u(q),E.current=requestAnimationFrame(B)}};B()}},[a,o,c]);return i.useEffect(()=>()=>{if(k.current){if(k.current.port.postMessage({command:"stop"}),I.current)try{I.current.disconnect(k.current)}catch{}k.current.disconnect()}E.current!==null&&cancelAnimationFrame(E.current)},[]),{isRecording:a,isPaused:o,duration:c,peaks:d,audioBuffer:p,level:b,peakLevel:S,startRecording:H,stopRecording:O,pauseRecording:j,resumeRecording:L,error:C}}function Ws(){const[e,t]=i.useState(null),[n,r]=i.useState([]),[a,s]=i.useState(!1),[o,l]=i.useState(!1),[c,u]=i.useState(null),d=i.useCallback(async()=>{try{const C=(await navigator.mediaDevices.enumerateDevices()).filter(x=>x.kind==="audioinput").map(x=>({deviceId:x.deviceId,label:x.label||`Microphone ${x.deviceId.slice(0,8)}`,groupId:x.groupId}));r(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(S=>S.stop());const b={audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1,latency:0,...C,...f&&{deviceId:{exact:f}}},video:!1},g=await navigator.mediaDevices.getUserMedia(b);t(g),s(!0),await d()}catch(x){console.error("Failed to access microphone:",x),u(x instanceof Error?x:new Error("Failed to access microphone")),s(!1)}finally{l(!1)}},[e,d]),p=i.useCallback(()=>{e&&(e.getTracks().forEach(f=>f.stop()),t(null),s(!1))},[e]);return i.useEffect(()=>(d(),()=>{e&&e.getTracks().forEach(f=>f.stop())}),[]),{stream:e,devices:n,hasPermission:a,isLoading:o,requestAccess:v,stopStream:p,error:c}}function Fs(e,t={}){const{updateRate:n=60,smoothingTimeConstant:r=.8}=t,[a,s]=i.useState(0),[o,l]=i.useState(0),c=i.useRef(null),u=i.useRef(null),d=i.useRef(null),v=()=>l(0);return i.useEffect(()=>{if(!e){s(0),l(0);return}let p=!0;return(async()=>{if(!p)return;const C=Z.getContext();if(C.state==="suspended"&&await C.resume(),!p)return;const x=new Z.Meter({smoothing:r,context:C});c.current=x;const b=C.createMediaStreamSource(e);u.current=b,Z.connect(b,x);const g=1e3/n;let S=0;const w=m=>{if(!(!p||!c.current)){if(m-S>=g){S=m;const y=c.current.getValue(),k=typeof y=="number"?y:y[0],I=Math.max(0,Math.min(1,(k+100)/100));s(I),l(A=>Math.max(A,I))}d.current=requestAnimationFrame(w)}};d.current=requestAnimationFrame(w)})(),()=>{if(p=!1,d.current&&(cancelAnimationFrame(d.current),d.current=null),u.current){try{u.current.disconnect()}catch{}u.current=null}c.current&&(c.current.dispose(),c.current=null)}},[e,r,n]),{level:a,peakLevel:o,resetPeak:v}}$.button`
|
|
1067
1101
|
padding: 0.5rem 1rem;
|
|
1068
1102
|
font-size: 0.875rem;
|
|
1069
1103
|
font-weight: 500;
|
|
@@ -1093,7 +1127,7 @@
|
|
|
1093
1127
|
outline: none;
|
|
1094
1128
|
box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.3);
|
|
1095
1129
|
}
|
|
1096
|
-
|
|
1130
|
+
`;$.span`
|
|
1097
1131
|
display: inline-block;
|
|
1098
1132
|
width: 8px;
|
|
1099
1133
|
height: 8px;
|
|
@@ -1111,13 +1145,13 @@
|
|
|
1111
1145
|
opacity: 0.3;
|
|
1112
1146
|
}
|
|
1113
1147
|
}
|
|
1114
|
-
|
|
1148
|
+
`;$(Yt)`
|
|
1115
1149
|
min-width: 200px;
|
|
1116
|
-
|
|
1150
|
+
`;$(Vn)`
|
|
1117
1151
|
display: flex;
|
|
1118
1152
|
flex-direction: column;
|
|
1119
1153
|
gap: 0.25rem;
|
|
1120
|
-
|
|
1154
|
+
`;$.div`
|
|
1121
1155
|
display: flex;
|
|
1122
1156
|
align-items: center;
|
|
1123
1157
|
gap: 0.75rem;
|
|
@@ -1125,7 +1159,7 @@
|
|
|
1125
1159
|
background: ${e=>e.$isRecording?"#fff3cd":"transparent"};
|
|
1126
1160
|
border-radius: 0.25rem;
|
|
1127
1161
|
transition: background 0.2s ease-in-out;
|
|
1128
|
-
|
|
1162
|
+
`;$.div`
|
|
1129
1163
|
width: 12px;
|
|
1130
1164
|
height: 12px;
|
|
1131
1165
|
border-radius: 50%;
|
|
@@ -1145,18 +1179,18 @@
|
|
|
1145
1179
|
}
|
|
1146
1180
|
}
|
|
1147
1181
|
`}
|
|
1148
|
-
|
|
1182
|
+
`;$.span`
|
|
1149
1183
|
font-family: 'Courier New', Monaco, monospace;
|
|
1150
1184
|
font-size: 1rem;
|
|
1151
1185
|
font-weight: 600;
|
|
1152
1186
|
color: #495057;
|
|
1153
1187
|
min-width: 70px;
|
|
1154
|
-
|
|
1188
|
+
`;$.span`
|
|
1155
1189
|
font-size: 0.75rem;
|
|
1156
1190
|
font-weight: 500;
|
|
1157
1191
|
color: ${e=>e.$isPaused?"#ffc107":"#dc3545"};
|
|
1158
1192
|
text-transform: uppercase;
|
|
1159
|
-
`;var
|
|
1193
|
+
`;var _s=$.div`
|
|
1160
1194
|
position: relative;
|
|
1161
1195
|
width: ${e=>e.$width}px;
|
|
1162
1196
|
height: ${e=>e.$height}px;
|
|
@@ -1164,39 +1198,39 @@
|
|
|
1164
1198
|
border-radius: 4px;
|
|
1165
1199
|
overflow: hidden;
|
|
1166
1200
|
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
|
|
1167
|
-
`,
|
|
1201
|
+
`,Zs=e=>e<.6?"linear-gradient(90deg, #27ae60, #2ecc71)":e<.85?"linear-gradient(90deg, #f39c12, #f1c40f)":"linear-gradient(90deg, #c0392b, #e74c3c)",Ps=$.div.attrs(e=>({style:{width:`${e.$level*100}%`,height:`${e.$height}px`,background:Zs(e.$level),boxShadow:e.$level>.01?"0 0 8px rgba(255, 255, 255, 0.3)":"none"}}))`
|
|
1168
1202
|
position: absolute;
|
|
1169
1203
|
left: 0;
|
|
1170
1204
|
top: 0;
|
|
1171
1205
|
transition: width 0.05s ease-out, background 0.1s ease-out;
|
|
1172
|
-
`,
|
|
1206
|
+
`,Vs=$.div.attrs(e=>({style:{left:`${e.$peakLevel*100}%`,height:`${e.$height}px`}}))`
|
|
1173
1207
|
position: absolute;
|
|
1174
1208
|
top: 0;
|
|
1175
1209
|
width: 2px;
|
|
1176
1210
|
background: #ecf0f1;
|
|
1177
1211
|
box-shadow: 0 0 4px rgba(236, 240, 241, 0.8);
|
|
1178
1212
|
transition: left 0.1s ease-out;
|
|
1179
|
-
`,
|
|
1213
|
+
`,js=$.div`
|
|
1180
1214
|
position: absolute;
|
|
1181
1215
|
top: 0;
|
|
1182
1216
|
left: 0;
|
|
1183
1217
|
width: 100%;
|
|
1184
1218
|
height: ${e=>e.$height}px;
|
|
1185
1219
|
pointer-events: none;
|
|
1186
|
-
`,
|
|
1220
|
+
`,In=$.div`
|
|
1187
1221
|
position: absolute;
|
|
1188
1222
|
left: ${e=>e.$position}%;
|
|
1189
1223
|
top: 0;
|
|
1190
1224
|
width: 1px;
|
|
1191
1225
|
height: ${e=>e.$height}px;
|
|
1192
1226
|
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:$,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`
|
|
1227
|
+
`,zs=({level:e,peakLevel:t,width:n=200,height:r=20,className:a})=>{const s=Math.max(0,Math.min(1,e)),o=t!==void 0?Math.max(0,Math.min(1,t)):0;return h.jsxs(_s,{$width:n,$height:r,className:a,children:[h.jsx(Ps,{$level:s,$height:r}),t!==void 0&&o>0&&h.jsx(Vs,{$peakLevel:o,$height:r}),h.jsxs(js,{$height:r,children:[h.jsx(In,{$position:60,$height:r}),h.jsx(In,{$position:85,$height:r})]})]})};i.memo(zs);function Hs(e,t,n,r={}){const{currentTime:a=0,audioConstraints:s,...o}=r,[l,c]=i.useState(!1),[u,d]=i.useState(null),{stream:v,devices:p,hasPermission:f,requestAccess:C,error:x}=Ws(),{level:b,peakLevel:g}=Fs(v),{isRecording:S,isPaused:w,duration:m,peaks:y,startRecording:k,stopRecording:I,pauseRecording:A,resumeRecording:R,error:E}=Bs(v,o),M=i.useCallback(async()=>{n&&(l||(await jt(),c(!0)),await k())},[n,l,k]),F=i.useCallback(async()=>{const H=await I();if(H&&n){const O=e.findIndex(te=>te.id===n);if(O===-1)return;const j=e[O],L=Math.floor(a*H.sampleRate);let B=0;if(j.clips.length>0){const te=j.clips.map(Q=>Q.startSample+Q.durationSamples);B=Math.max(...te)}const q=Math.max(L,B),U={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()}`},ie=e.map((te,Q)=>Q===O?{...te,clips:[...te.clips,U]}:te);t(ie)}},[n,e,t,a,I]);i.useEffect(()=>{f&&p.length>0&&u===null&&d(p[0].deviceId)},[f,p.length]);const T=i.useCallback(async()=>{await C(void 0,s),await jt(),c(!0)},[C,s]),P=i.useCallback(async H=>{d(H),await C(H,s),await jt(),c(!0)},[C,s]);return{isRecording:S,isPaused:w,duration:m,level:b,peakLevel:g,error:x||E,stream:v,devices:p,hasPermission:f,selectedDevice:u,startRecording:M,stopRecording:F,pauseRecording:A,resumeRecording:R,requestMicAccess:T,changeDevice:P,recordingPeaks:y}}const Ct=[{id:"reverb",name:"Reverb",category:"reverb",description:"Simple convolution reverb with adjustable decay time",parameters:[{name:"decay",label:"Decay",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"s"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"freeverb",name:"Freeverb",category:"reverb",description:"Classic Schroeder/Moorer reverb with room size and dampening",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.7},{name:"dampening",label:"Dampening",type:"number",min:0,max:1e4,step:100,default:3e3,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"jcReverb",name:"JC Reverb",category:"reverb",description:"Attempt at Roland JC-120 chorus reverb emulation",parameters:[{name:"roomSize",label:"Room Size",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"feedbackDelay",name:"Feedback Delay",category:"delay",description:"Delay line with feedback for echo effects",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"pingPongDelay",name:"Ping Pong Delay",category:"delay",description:"Stereo delay bouncing between left and right channels",parameters:[{name:"delayTime",label:"Delay Time",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"feedback",label:"Feedback",type:"number",min:0,max:.95,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"chorus",name:"Chorus",category:"modulation",description:"Creates thickness by layering detuned copies of the signal",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1.5,unit:"Hz"},{name:"delayTime",label:"Delay",type:"number",min:0,max:20,step:.5,default:3.5,unit:"ms"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.7},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"phaser",name:"Phaser",category:"modulation",description:"Classic phaser effect using allpass filters",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:.5,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:6,step:1,default:3},{name:"baseFrequency",label:"Base Freq",type:"number",min:100,max:2e3,step:10,default:350,unit:"Hz"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:.5}]},{id:"tremolo",name:"Tremolo",category:"modulation",description:"Rhythmic volume modulation",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:4,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.5},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"vibrato",name:"Vibrato",category:"modulation",description:"Pitch modulation effect",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:20,step:.1,default:5,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:.1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoPanner",name:"Auto Panner",category:"modulation",description:"Automatic left-right panning",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoFilter",name:"Auto Filter",category:"filter",description:"Automated filter sweep with LFO",parameters:[{name:"frequency",label:"Rate",type:"number",min:.1,max:10,step:.1,default:1,unit:"Hz"},{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:2e3,step:10,default:200,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:.5,max:8,step:.5,default:2.6},{name:"depth",label:"Depth",type:"number",min:0,max:1,step:.01,default:1},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"autoWah",name:"Auto Wah",category:"filter",description:"Envelope follower filter effect",parameters:[{name:"baseFrequency",label:"Base Freq",type:"number",min:20,max:500,step:10,default:100,unit:"Hz"},{name:"octaves",label:"Octaves",type:"number",min:1,max:8,step:1,default:6},{name:"sensitivity",label:"Sensitivity",type:"number",min:-40,max:0,step:1,default:0,unit:"dB"},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"eq3",name:"3-Band EQ",category:"filter",description:"Three band equalizer with low, mid, and high controls",parameters:[{name:"low",label:"Low",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"mid",label:"Mid",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"high",label:"High",type:"number",min:-24,max:24,step:.5,default:0,unit:"dB"},{name:"lowFrequency",label:"Low Freq",type:"number",min:20,max:500,step:10,default:400,unit:"Hz"},{name:"highFrequency",label:"High Freq",type:"number",min:1e3,max:1e4,step:100,default:2500,unit:"Hz"}]},{id:"distortion",name:"Distortion",category:"distortion",description:"Wave shaping distortion effect",parameters:[{name:"distortion",label:"Drive",type:"number",min:0,max:1,step:.01,default:.4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"bitCrusher",name:"Bit Crusher",category:"distortion",description:"Reduces bit depth for lo-fi digital texture",parameters:[{name:"bits",label:"Bits",type:"number",min:1,max:16,step:1,default:4},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"chebyshev",name:"Chebyshev",category:"distortion",description:"Waveshaping distortion using Chebyshev polynomials",parameters:[{name:"order",label:"Order",type:"number",min:1,max:100,step:1,default:50},{name:"wet",label:"Mix",type:"number",min:0,max:1,step:.01,default:1}]},{id:"compressor",name:"Compressor",category:"dynamics",description:"Dynamic range compressor",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-60,max:0,step:1,default:-24,unit:"dB"},{name:"ratio",label:"Ratio",type:"number",min:1,max:20,step:.5,default:4},{name:"attack",label:"Attack",type:"number",min:0,max:1,step:.001,default:.003,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:1,step:.01,default:.25,unit:"s"},{name:"knee",label:"Knee",type:"number",min:0,max:40,step:1,default:30,unit:"dB"}]},{id:"limiter",name:"Limiter",category:"dynamics",description:"Hard limiter to prevent clipping",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-12,max:0,step:.5,default:-6,unit:"dB"}]},{id:"gate",name:"Gate",category:"dynamics",description:"Noise gate to silence signal below threshold",parameters:[{name:"threshold",label:"Threshold",type:"number",min:-100,max:0,step:1,default:-40,unit:"dB"},{name:"attack",label:"Attack",type:"number",min:0,max:.3,step:.001,default:.001,unit:"s"},{name:"release",label:"Release",type:"number",min:0,max:.5,step:.01,default:.1,unit:"s"}]},{id:"stereoWidener",name:"Stereo Widener",category:"spatial",description:"Expands or narrows the stereo image",parameters:[{name:"width",label:"Width",type:"number",min:0,max:1,step:.01,default:.5}]}],Qt=e=>Ct.find(t=>t.id===e),Ls=e=>Ct.filter(t=>t.category===e),Xs=[{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:Z.Reverb,freeverb:Z.Freeverb,jcReverb:Z.JCReverb,feedbackDelay:Z.FeedbackDelay,pingPongDelay:Z.PingPongDelay,chorus:Z.Chorus,phaser:Z.Phaser,tremolo:Z.Tremolo,vibrato:Z.Vibrato,autoPanner:Z.AutoPanner,autoFilter:Z.AutoFilter,autoWah:Z.AutoWah,eq3:Z.EQ3,distortion:Z.Distortion,bitCrusher:Z.BitCrusher,chebyshev:Z.Chebyshev,compressor:Z.Compressor,limiter:Z.Limiter,gate:Z.Gate,stereoWidener:Z.StereoWidener};let Ns=0;const Os=()=>`effect_${Date.now()}_${++Ns}`;function ht(e,t){const n=Gs[e.id];if(!n)throw new Error(`Unknown effect type: ${e.id}`);const r={};e.parameters.forEach(o=>{const l=t?.[o.name]??o.default;r[o.name]=l});const a=new n(r),s=Os();return{effect:a,id:e.id,instanceId:s,dispose(){try{a.disconnect(),a.dispose()}catch{}},setParameter(o,l){o==="wet"&&a.wet?a.wet.value=l:a[o]!==void 0&&(a[o]?.value!==void 0?a[o].value=l:a[o]=l)},getParameter(o){if(o==="wet"&&a.wet)return a.wet.value;if(a[o]!==void 0)return a[o]?.value!==void 0?a[o].value:a[o]},connect(o){a.connect(o)},disconnect(){try{a.disconnect()}catch{}}}}function Ys(e){if(e.length===0)throw new Error("Cannot create effect chain with no effects");for(let t=0;t<e.length-1;t++)e[t].effect.connect(e[t+1].effect);return{input:e[0].effect,output:e[e.length-1].effect,dispose(){e.forEach(t=>t.dispose())}}}function Ks(e=256){const[t,n]=i.useState([]),r=i.useRef(t);r.current=t;const a=i.useRef(new Map),s=i.useRef(null),o=i.useRef(null),l=i.useCallback(b=>{const g=o.current;if(!g)return;const{masterGainNode:S,destination:w,analyserNode:m}=g;try{S.disconnect()}catch{}const y=b.map(k=>a.current.get(k.instanceId)).filter(k=>k!==void 0);if(y.length===0)S.connect(m),m.connect(w);else{let k=S;y.forEach(I=>{try{I.disconnect()}catch{}k.connect(I.effect),k=I.effect}),k.connect(m),m.connect(w)}},[]),c=i.useCallback(b=>{const g=Qt(b);if(!g){console.error(`Unknown effect: ${b}`);return}const S={};g.parameters.forEach(y=>{S[y.name]=y.default});const w=ht(g,S);a.current.set(w.instanceId,w);const m={instanceId:w.instanceId,effectId:g.id,definition:g,params:S,bypassed:!1};n(y=>[...y,m])},[]),u=i.useCallback(b=>{const g=a.current.get(b);g&&(g.dispose(),a.current.delete(b)),n(S=>S.filter(w=>w.instanceId!==b))},[]),d=i.useCallback((b,g,S)=>{const w=a.current.get(b);w&&w.setParameter(g,S),n(m=>m.map(y=>y.instanceId===b?{...y,params:{...y.params,[g]:S}}:y))},[]),v=i.useCallback(b=>{const g=r.current.find(m=>m.instanceId===b);if(!g)return;const S=!g.bypassed,w=a.current.get(b);if(w){const m=g.params.wet??1;w.setParameter("wet",S?0:m)}n(m=>m.map(y=>y.instanceId===b?{...y,bypassed:S}:y))},[]),p=i.useCallback((b,g)=>{n(S=>{const w=[...S],[m]=w.splice(b,1);return w.splice(g,0,m),w})},[]),f=i.useCallback(()=>{a.current.forEach(b=>b.dispose()),a.current.clear(),n([])},[]);i.useEffect(()=>{l(t)},[t,l]);const C=i.useCallback((b,g,S)=>{const w=new Z.Analyser("fft",e);s.current=w,o.current={masterGainNode:b,destination:g,analyserNode:w};const y=r.current.map(k=>a.current.get(k.instanceId)).filter(k=>k!==void 0);if(y.length===0)b.connect(w),w.connect(g);else{let k=b;y.forEach(I=>{k.connect(I.effect),k=I.effect}),k.connect(w),w.connect(g)}return function(){w.dispose(),s.current=null,o.current=null}},[e]);i.useEffect(()=>()=>{a.current.forEach(b=>b.dispose()),a.current.clear()},[]);const x=i.useCallback(()=>{const b=t.filter(g=>!g.bypassed);if(b.length!==0)return(g,S,w)=>{const m=[];for(const y of b){const k=ht(y.definition,y.params);m.push(k)}if(m.length===0)g.connect(S);else{let y=g;m.forEach(k=>{y.connect(k.effect),y=k.effect}),y.connect(S)}return function(){m.forEach(k=>k.dispose())}}},[t]);return{activeEffects:t,availableEffects:Ct,addEffect:c,removeEffect:u,updateParameter:d,toggleBypass:v,reorderEffects:p,clearAllEffects:f,masterEffects:C,createOfflineEffectsFunction:x,analyserRef:s}}function Us(){const[e,t]=i.useState(new Map),n=i.useRef(new Map),r=i.useRef(new Map),a=i.useCallback((f,C)=>{const x=r.current.get(f);if(!x)return;const{graphEnd:b,masterGainNode:g}=x,S=n.current.get(f);try{b.disconnect()}catch{}const w=C.map(m=>S?.get(m.instanceId)).filter(m=>m!==void 0);if(w.length===0)b.connect(g);else{let m=b;w.forEach(y=>{try{y.disconnect()}catch{}m.connect(y.effect),m=y.effect}),m.connect(g)}},[]),s=i.useCallback((f,C)=>{const x=Qt(C);if(!x){console.error(`Unknown effect: ${C}`);return}const b={};x.parameters.forEach(w=>{b[w.name]=w.default});const g=ht(x,b);n.current.has(f)||n.current.set(f,new Map),n.current.get(f).set(g.instanceId,g);const S={instanceId:g.instanceId,effectId:x.id,definition:x,params:b,bypassed:!1};t(w=>{const m=new Map(w),y=m.get(f)||[];return m.set(f,[...y,S]),m})},[]),o=i.useCallback((f,C)=>{const x=n.current.get(f),b=x?.get(C);b&&(b.dispose(),x?.delete(C)),t(g=>{const S=new Map(g),w=S.get(f)||[];return S.set(f,w.filter(m=>m.instanceId!==C)),S})},[]),l=i.useCallback((f,C,x,b)=>{const S=n.current.get(f)?.get(C);S&&S.setParameter(x,b),t(w=>{const m=new Map(w),y=m.get(f)||[];return m.set(f,y.map(k=>k.instanceId===C?{...k,params:{...k.params,[x]:b}}:k)),m})},[]),c=i.useCallback((f,C)=>{const b=(d.current.get(f)||[]).find(m=>m.instanceId===C);if(!b)return;const g=!b.bypassed,w=n.current.get(f)?.get(C);if(w){const m=b.params.wet??1;w.setParameter("wet",g?0:m)}t(m=>{const y=new Map(m),k=y.get(f)||[];return y.set(f,k.map(I=>I.instanceId===C?{...I,bypassed:g}:I)),y})},[]),u=i.useCallback(f=>{const C=n.current.get(f);C&&(C.forEach(x=>x.dispose()),C.clear()),t(x=>{const b=new Map(x);return b.set(f,[]),b})},[]),d=i.useRef(e);d.current=e;const v=i.useCallback(f=>(C,x,b)=>{r.current.set(f,{graphEnd:C,masterGainNode:x});const g=d.current.get(f)||[],S=n.current.get(f),w=g.map(m=>S?.get(m.instanceId)).filter(m=>m!==void 0);if(w.length===0)C.connect(x);else{let m=C;w.forEach(y=>{m.connect(y.effect),m=y.effect}),m.connect(x)}return function(){r.current.delete(f)}},[]);i.useEffect(()=>{e.forEach((f,C)=>{a(C,f)})},[e,a]),i.useEffect(()=>()=>{n.current.forEach(f=>{f.forEach(C=>C.dispose()),f.clear()}),n.current.clear()},[]);const p=i.useCallback(f=>{const x=(e.get(f)||[]).filter(b=>!b.bypassed);if(x.length!==0)return(b,g,S)=>{const w=[];for(const m of x){const y=ht(m.definition,m.params);w.push(y)}if(w.length===0)b.connect(g);else{let m=b;w.forEach(y=>{m.connect(y.effect),m=y.effect}),m.connect(g)}return function(){w.forEach(y=>y.dispose())}}},[e]);return{trackEffectsState:e,addEffectToTrack:s,removeEffectFromTrack:o,updateTrackEffectParameter:l,toggleBypass:c,clearTrackEffects:u,getTrackEffectsFunction:v,createOfflineTrackEffectsFunction:p,availableEffects:Ct}}function Js(e,t={}){const{bitDepth:n=16}=t,r=e.numberOfChannels,a=e.sampleRate,s=e.length,o=n/8,l=r*o,c=a*l,u=s*l,d=44,v=d+u,p=new ArrayBuffer(v),f=new DataView(p);At(f,0,"RIFF"),f.setUint32(4,v-8,!0),At(f,8,"WAVE"),At(f,12,"fmt "),f.setUint32(16,16,!0),f.setUint16(20,n===32?3:1,!0),f.setUint16(22,r,!0),f.setUint32(24,a,!0),f.setUint32(28,c,!0),f.setUint16(32,l,!0),f.setUint16(34,n,!0),At(f,36,"data"),f.setUint32(40,u,!0);const C=[];for(let b=0;b<r;b++)C.push(e.getChannelData(b));let x=d;if(n===16)for(let b=0;b<s;b++)for(let g=0;g<r;g++){const S=C[g][b],w=Math.max(-1,Math.min(1,S)),m=w<0?w*32768:w*32767;f.setInt16(x,m,!0),x+=2}else for(let b=0;b<s;b++)for(let g=0;g<r;g++)f.setFloat32(x,C[g][b],!0),x+=4;return new Blob([p],{type:"audio/wav"})}function At(e,t,n){for(let r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}function qs(e,t){const n=URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}function fr(){const[e,t]=i.useState(!1),[n,r]=i.useState(0),[a,s]=i.useState(null);return{exportWav:i.useCallback(async(l,c,u={})=>{const{filename:d="export",mode:v="master",trackIndex:p,autoDownload:f=!0,applyEffects:C=!0,effectsFunction:x,createOfflineTrackEffects:b,bitDepth:g=16,onProgress:S}=u;t(!0),r(0),s(null);try{if(l.length===0)throw new Error("No tracks to export");if(v==="individual"&&(p===void 0||p<0||p>=l.length))throw new Error("Invalid track index for individual export");const w=l[0].clips[0]?.sampleRate||44100;let m=0;for(const M of l)for(const F of M.clips){const T=F.startSample+F.durationSamples;m=Math.max(m,T)}m+=Math.round(w*.1);const y=m/w,k=v==="individual"?[{track:l[p],state:c[p],index:p}]:l.map((M,F)=>({track:M,state:c[F],index:F})),I=c.some(M=>M.soloed),A=!!b;let R;if((x||A)&&C)R=await Qs(k,c,I,y,w,x,b,M=>{r(M),S?.(M)});else{const M=new OfflineAudioContext(2,m,w);let F=0;const T=k.reduce((P,{track:H})=>P+H.clips.length,0);for(const{track:P,state:H}of k)if(!(H.muted&&!H.soloed)&&!(I&&!H.soloed))for(const O of P.clips){await ti(M,O,H,w,C),F++;const j=F/T*.5;r(j),S?.(j)}r(.5),S?.(.5),R=await M.startRendering()}r(.9),S?.(.9);const E=Js(R,{bitDepth:g});if(r(1),S?.(1),f){const M=v==="individual"?`${d}_${l[p].name}`:d;qs(E,`${M}.wav`)}return{audioBuffer:R,blob:E,duration:y}}catch(w){const m=w instanceof Error?w.message:"Export failed";throw s(m),w}finally{t(!1)}},[]),isExporting:e,progress:n,error:a}}async function Qs(e,t,n,r,a,s,o,l){const{Offline:c,Volume:u,Gain:d,Panner:v,Player:p,ToneAudioBuffer:f}=await import("tone");l(.1);let C;try{C=await c(async({transport:x,destination:b})=>{const g=new u(0);let S;s?S=s(g,b,!0):g.connect(b);for(const{track:w,state:m}of e){if(m.muted&&!m.soloed||n&&!m.soloed)continue;const y=new u(ei(m.volume)),k=new v(m.pan),I=new d(m.muted?0:1),A=o?.(w.id);A?A(I,g,!0):I.connect(g),k.connect(I),y.connect(k);for(const R of w.clips){const{audioBuffer:E,startSample:M,durationSamples:F,offsetSamples:T,gain:P,fadeIn:H,fadeOut:O}=R,j=M/a,L=F/a,B=T/a,q=new f(E),U=new p(q),ie=new d(P);if(U.connect(ie),ie.connect(y),H){const te=j,Q=j+H.duration,le=ie.gain._param;le.setValueAtTime(0,te),le.linearRampToValueAtTime(P,Q)}if(O){const te=j+L-O.duration,Q=j+L,le=ie.gain._param;le.setValueAtTime(P,te),le.linearRampToValueAtTime(0,Q)}U.start(j,B,L)}}x.start(0)},r,2,a)}catch(x){throw x instanceof Error?x:new Error(`Tone.Offline rendering failed: ${String(x)}`)}return l(.9),C.get()}function ei(e){return 20*Math.log10(Math.max(e,1e-4))}async function ti(e,t,n,r,a){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 p=o/r,f=l/r,C=c/r,x=e.createBufferSource();x.buffer=s;const b=e.createGain(),g=u*n.volume,S=e.createStereoPanner();if(S.pan.value=n.pan,x.connect(b),b.connect(S),S.connect(e.destination),a){if(d?b.gain.setValueAtTime(0,p):b.gain.setValueAtTime(g,p),d){const w=p,m=p+d.duration;$n(b.gain,w,m,0,g,d.type||"linear")}if(v){const w=p+f-v.duration,m=p+f;(!d||d.duration<f-v.duration)&&b.gain.setValueAtTime(g,w),$n(b.gain,w,m,g,0,v.type||"linear")}}else b.gain.setValueAtTime(g,p);x.start(p,C,f)}function $n(e,t,n,r,a,s){const o=n-t;if(!(o<=0))switch(s){case"linear":e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n);break;case"exponential":const l=Math.max(r,1e-4),c=Math.max(a,1e-4);e.setValueAtTime(l,t),e.exponentialRampToValueAtTime(c,n),a===0&&e.setValueAtTime(0,n);break;case"logarithmic":const u=Mn(r,a,256,"logarithmic");e.setValueCurveAtTime(u,t,o);break;case"sCurve":const d=Mn(r,a,256,"sCurve");e.setValueCurveAtTime(d,t,o);break;default:e.setValueAtTime(r,t),e.linearRampToValueAtTime(a,n)}}function Mn(e,t,n,r){const a=new Float32Array(n),s=t-e;for(let o=0;o<n;o++){const l=o/(n-1);let c;r==="logarithmic"?s>0?c=Math.log10(1+l*9)/Math.log10(10):c=1-Math.log10(1+(1-l)*9)/Math.log10(10):c=l*l*(3-2*l),a[o]=e+s*c}return a}const mr=i.createContext(null),hr=i.createContext(null),pr=i.createContext(null),gr=i.createContext(null),br=i.createContext(null),ni=({tracks:e,timescale:t=!1,mono:n=!1,waveHeight:r=80,samplesPerPixel:a=1024,zoomLevels:s,automaticScroll:o=!1,theme:l,controls:c={show:!1,width:0},annotationList:u,effects:d,onReady:v,onAnnotationUpdate:p,onAnnotationsChange:f,barWidth:C=1,barGap:x=0,progressBarWidth:b,children:g})=>{const S=b??C+x,w=i.useMemo(()=>u?.annotations?u.annotations.map(W=>typeof W.start=="number"?W:rr(W)):[],[u?.annotations]),m=i.useRef(w);m.current=w;const[y,k]=i.useState(null),[I,A]=i.useState(!1),[R,E]=i.useState(0),[M,F]=i.useState(0),[T,P]=i.useState([]),[H,O]=i.useState([]),[j,L]=i.useState([]),[B,q]=i.useState(0),[U,ie]=i.useState(0),[te,Q]=i.useState(null),[le,Ge]=i.useState(o),[V,de]=i.useState(u?.isContinuousPlay??!1),[ne,N]=i.useState(u?.linkEndpoints??!1),[ce,fe]=i.useState(u?.editable??!1),[oe,Ie]=i.useState(!1),[$e,ze]=i.useState(0),[Le,ae]=i.useState(0),[Ye,et]=i.useState(!1),_=i.useRef(null),Te=i.useRef(0),pe=i.useRef(0),ge=i.useRef(null),ot=i.useRef(j),G=i.useRef(0),se=i.useRef(0),ve=i.useRef(null),xe=i.useRef(null),Me=i.useRef(!1),Ke=i.useRef(u?.isContinuousPlay??!1),Ne=i.useRef(null),tt=i.useRef(a),ct=i.useRef(!1),z=i.useRef(0),Y=i.useRef(0),re=i.useRef(0),me=i.useRef(0),{timeFormat:be,setTimeFormat:Ee,formatTime:Xe}=ir(),Ze=lr({initialSamplesPerPixel:a,zoomLevels:s}),ee=Ze.samplesPerPixel,{masterVolume:we,setMasterVolume:Ue}=cr({playoutRef:_,initialVolume:1}),st=i.useCallback(W=>{Ke.current=W,de(W)},[]),He=i.useCallback(W=>{Ne.current=W,k(W)},[]),Je=i.useCallback(W=>{ct.current=W,Ie(W)},[]),Pe=i.useCallback((W,X)=>{re.current=W,me.current=X,ze(W),ae(X)},[]),ut=i.useCallback(()=>{const W=z.current,X=Y.current;W!==X&&X>W&&Pe(W,X)},[Pe]),dt=i.useCallback(()=>{Pe(0,0)},[Pe]);i.useEffect(()=>{Me.current=le},[le]),i.useEffect(()=>{ot.current=j},[j]),i.useEffect(()=>{z.current=B,Y.current=U},[B,U]),i.useEffect(()=>{if(!xe.current||!T.length)return;const W=xe.current,X=tt.current,J=ee;if(X===J)return;const ue=c.show?c.width:0,K=W.clientWidth,ye=W.scrollLeft+K/2-ue,qe=T[0].sampleRate,ke=ye*X/qe*qe/J,We=Math.max(0,ke+ue-K/2);W.scrollLeft=We,tt.current=J},[ee,T,c]);const nt=i.useRef(null);i.useEffect(()=>{if(et(!1),e.length===0){P([]),F(0),L([]),O([]),_.current&&(_.current.dispose(),_.current=null);return}const W=I,X=pe.current;return _.current&&W&&(_.current.stop(),ge.current&&(cancelAnimationFrame(ge.current),ge.current=null),nt.current={position:X}),(async()=>{try{const ue=[];e.forEach(Ce=>{Ce.clips.length>0&&Ce.clips[0].audioBuffer&&ue.push(Ce.clips[0].audioBuffer)});let K=0;e.forEach(Ce=>{Ce.clips.forEach(ke=>{const We=ke.sampleRate,xt=(ke.startSample+ke.durationSamples)/We;K=Math.max(K,xt)})}),P(ue),F(K),L(Ce=>Ce.length===e.length?Ce.map((ke,We)=>({...ke,name:e[We].name})):e.map(ke=>({name:ke.name,muted:ke.muted,soloed:ke.soloed,volume:ke.volume,pan:ke.pan}))),_.current&&_.current.dispose();const Se=new ra({effects:d}),ye=ot.current;e.forEach((Ce,ke)=>{const We=Ce.clips.filter(rt=>rt.audioBuffer);if(We.length>0){const rt=We[0].sampleRate,xt=Math.min(...We.map(Fe=>Fe.startSample/rt)),Hr=Math.max(...We.map(Fe=>(Fe.startSample+Fe.durationSamples)/rt)),wt=ye[ke],Lr={id:`track-${ke}`,name:Ce.name,gain:wt?.volume??Ce.volume,muted:wt?.muted??Ce.muted,soloed:wt?.soloed??Ce.soloed,stereoPan:wt?.pan??Ce.pan,startTime:xt,endTime:Hr},Xr=We.map(Fe=>{const Pt=Fe.sampleRate;return{buffer:Fe.audioBuffer,startTime:Fe.startSample/Pt-xt,duration:Fe.durationSamples/Pt,offset:Fe.offsetSamples/Pt,fadeIn:Fe.fadeIn,fadeOut:Fe.fadeOut,gain:Fe.gain}});Se.addTrack({clips:Xr,track:Lr,effects:Ce.effects})}}),Se.applyInitialSoloState(),_.current=Se,et(!0);const qe=new CustomEvent("waveform-playlist:ready",{detail:{trackCount:e.length,duration:K}});window.dispatchEvent(qe),v?.()}catch(ue){console.error("Error loading audio:",ue)}})(),()=>{ge.current&&cancelAnimationFrame(ge.current),_.current&&_.current.dispose()}},[e,v,I]),i.useEffect(()=>{if(e.length===0)return;const W=16,X=e.map(J=>J.clips.map(K=>{if(K.waveformData){const ye=nr(K.waveformData,ee,0,K.offsetSamples,K.durationSamples);return{clipId:K.id,trackName:J.name,peaks:{length:ye.length,data:[ye.data],bits:ye.bits},startSample:K.startSample,durationSamples:K.durationSamples,fadeIn:K.fadeIn,fadeOut:K.fadeOut}}if(!K.audioBuffer)return console.warn(`Clip "${K.name||K.id}" has neither waveformData nor audioBuffer - rendering empty`),{clipId:K.id,trackName:J.name,peaks:{length:0,data:[],bits:W},startSample:K.startSample,durationSamples:K.durationSamples,fadeIn:K.fadeIn,fadeOut:K.fadeOut};const Se=Do(K.audioBuffer,ee,n,W,K.offsetSamples,K.durationSamples);return{clipId:K.id,trackName:J.name,peaks:Se,startSample:K.startSample,durationSamples:K.durationSamples,fadeIn:K.fadeIn,fadeOut:K.fadeOut}}));O(X)},[e,ee,n]);const Oe=i.useCallback(()=>{ge.current&&(cancelAnimationFrame(ge.current),ge.current=null);const W=()=>{const X=Z.getContext().currentTime-G.current,J=se.current+X;pe.current=J,E(J);const ue=m.current;if(ue.length>0){const Se=ue.find(ye=>J>=ye.start&&J<ye.end);if(Ke.current)Se&&Se.id!==Ne.current?He(Se.id):!Se&&Ne.current!==null&&He(null);else if(Ne.current){const ye=ue.find(qe=>qe.id===Ne.current);if(ye&&J>=ye.end){_.current&&_.current.stop(),A(!1),pe.current=Te.current,E(Te.current);return}}else Se&&He(Se.id)}if(Me.current&&xe.current&&T.length>0){const Se=xe.current,ye=T[0].sampleRate,qe=J*ye/tt.current,Ce=Se.clientWidth,ke=c.show?c.width:0,We=qe+ke,rt=Math.max(0,We-Ce/2);Se.scrollLeft=rt}if(ve.current!==null&&J>=ve.current){_.current&&_.current.stop(),A(!1),pe.current=ve.current,E(ve.current),ve.current=null;return}const K=re.current!==me.current&&me.current>re.current;if(ct.current&&K&&J>=me.current){_.current?.stop();const ye=Z.getContext().currentTime;G.current=ye,se.current=re.current,pe.current=re.current,_.current?.play(ye,re.current),ge.current=requestAnimationFrame(W);return}if(J>=M){_.current&&_.current.stop(),A(!1),pe.current=Te.current,E(Te.current),He(null);return}ge.current=requestAnimationFrame(W)};ge.current=requestAnimationFrame(W)},[M,T,ee,V]),Be=i.useCallback(()=>{ge.current&&(cancelAnimationFrame(ge.current),ge.current=null)},[]);i.useEffect(()=>{(async()=>{if(I&&ge.current&&_.current)if(V){const X=pe.current;_.current.stop(),Be(),await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const ue=Z.getContext().currentTime;G.current=ue,se.current=X,_.current.play(ue,X),Oe()}else Be(),Oe()})()},[V,I,Oe,Be]),i.useEffect(()=>{(async()=>{if(nt.current&&_.current){const{position:X}=nt.current;nt.current=null,await _.current.init(),_.current.setOnPlaybackComplete(()=>{});const ue=Z.getContext().currentTime;G.current=ue,se.current=X,_.current.play(ue,X),A(!0),Oe()}})()},[e,Oe]);const _t=i.useCallback(async(W,X)=>{if(!_.current||T.length===0)return;await _.current.init(),await Z.start();const J=W??pe.current;Te.current=J,pe.current=J,_.current.setOnPlaybackComplete(()=>{}),_.current.stop(),Be();const K=Z.getContext().currentTime;G.current=K,se.current=J,ve.current=X!==void 0?J+X:null,_.current.play(K,J,X),A(!0),Oe()},[T.length,Oe,Be]),Mr=i.useCallback(()=>{if(!_.current)return;const W=Z.getContext().currentTime-G.current,X=se.current+W;_.current.pause(),A(!1),Be(),pe.current=X,E(X)},[Be]),Er=i.useCallback(()=>{_.current&&(_.current.stop(),A(!1),Be(),pe.current=Te.current,E(Te.current),He(null))},[Be]),Rr=i.useCallback(W=>{const X=Math.max(0,Math.min(W,M));pe.current=X,E(X),I&&_.current&&(_.current.stop(),Be(),_t(X))},[M,I,_t,Be]),Dr=i.useCallback((W,X)=>{const J=[...j];if(J[W]={...J[W],muted:X},L(J),_.current){const ue=`track-${W}`;_.current.setMute(ue,X)}},[j]),Tr=i.useCallback((W,X)=>{const J=[...j];if(J[W]={...J[W],soloed:X},L(J),_.current){const ue=`track-${W}`;_.current.setSolo(ue,X)}},[j]),Br=i.useCallback((W,X)=>{const J=[...j];if(J[W]={...J[W],volume:X},L(J),_.current){const ue=`track-${W}`,K=_.current.getTrack(ue);K&&K.setVolume(X)}},[j]),Wr=i.useCallback((W,X)=>{const J=[...j];if(J[W]={...J[W],pan:X},L(J),_.current){const ue=`track-${W}`,K=_.current.getTrack(ue);K&&K.setPan(X)}},[j]),Fr=i.useCallback((W,X)=>{q(W),ie(X),pe.current=W,E(W),I&&_.current&&(_.current.stop(),_.current.play(Z.getContext().currentTime,W))},[I]),_r=i.useCallback(W=>{xe.current=W},[]),Zt=i.useRef(f);Zt.current=f;const Zr=i.useCallback(W=>{const X=typeof W=="function"?W(m.current):W;if(!Zt.current){process.env.NODE_ENV!=="production"&&console.warn("waveform-playlist: setAnnotations was called but no onAnnotationsChange callback is provided. Annotation edits will not persist. Pass onAnnotationsChange to WaveformPlaylistProvider to handle annotation updates.");return}Zt.current(X)},[]),Pr=T[0]?.sampleRate||44100,tn=t?30:0,Vr=e.length*r+tn,nn={isPlaying:I,currentTime:R,currentTimeRef:pe,playbackStartTimeRef:G,audioStartPositionRef:se},rn={continuousPlay:V,linkEndpoints:ne,annotationsEditable:ce,isAutomaticScroll:le,isLoopEnabled:oe,annotations:w,activeAnnotationId:y,selectionStart:B,selectionEnd:U,selectedTrackId:te,loopStart:$e,loopEnd:Le},an={play:_t,pause:Mr,stop:Er,seekTo:Rr,setCurrentTime:W=>{pe.current=W,E(W)},setTrackMute:Dr,setTrackSolo:Tr,setTrackVolume:Br,setTrackPan:Wr,setSelection:Fr,setSelectedTrackId:Q,setTimeFormat:Ee,formatTime:Xe,zoomIn:Ze.zoomIn,zoomOut:Ze.zoomOut,setMasterVolume:Ue,setAutomaticScroll:W=>{Ge(W)},setScrollContainer:_r,scrollContainerRef:xe,setContinuousPlay:st,setLinkEndpoints:N,setAnnotationsEditable:fe,setAnnotations:Zr,setActiveAnnotationId:He,setLoopEnabled:Je,setLoopRegion:Pe,setLoopRegionFromSelection:ut,clearLoopRegion:dt},on={duration:M,audioBuffers:T,peaksDataArray:H,trackStates:j,tracks:e,sampleRate:Pr,waveHeight:r,timeScaleHeight:tn,minimumPlaylistHeight:Vr,controls:c,playoutRef:_,samplesPerPixel:ee,timeFormat:be,masterVolume:we,canZoomIn:Ze.canZoomIn,canZoomOut:Ze.canZoomOut,barWidth:C,barGap:x,progressBarWidth:S,isReady:Ye,mono:n},jr={...nn,...rn,...an,...on},zr={...Hn,...l};return h.jsx($.ThemeProvider,{theme:zr,children:h.jsx(mr.Provider,{value:nn,children:h.jsx(hr.Provider,{value:rn,children:h.jsx(pr.Provider,{value:an,children:h.jsx(gr.Provider,{value:on,children:h.jsx(br.Provider,{value:jr,children:g})})})})})})},Re=()=>{const e=i.useContext(mr);if(!e)throw new Error("usePlaybackAnimation must be used within WaveformPlaylistProvider");return e},De=()=>{const e=i.useContext(hr);if(!e)throw new Error("usePlaylistState must be used within WaveformPlaylistProvider");return e},he=()=>{const e=i.useContext(pr);if(!e)throw new Error("usePlaylistControls must be used within WaveformPlaylistProvider");return e},Ae=()=>{const e=i.useContext(gr);if(!e)throw new Error("usePlaylistData must be used within WaveformPlaylistProvider");return e},ri=()=>{const e=i.useContext(br);if(!e)throw new Error("useWaveformPlaylist must be used within WaveformPlaylistProvider");return e};var ai=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}},oi=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 ai({...e,volume:this._masterVolume*(e.volume??1),playbackRate:this._playbackRate}),this.track.setOnStopCallback(()=>{this._isPlaying=!1,this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback()}),this.track}removeTrack(e){this.track&&this.track.id===e&&(this.track.dispose(),this.track=null)}getTrack(e){if(this.track&&this.track.id===e)return this.track}play(e,t,n){if(!this.track){console.warn("MediaElementPlayout: No track to play");return}const r=t??0;if(this._isPlaying=!0,this.track.play(r),n!==void 0){const a=n/this._playbackRate;setTimeout(()=>{this._isPlaying&&(this.pause(),this.onPlaybackCompleteCallback&&this.onPlaybackCompleteCallback())},a*1e3)}}pause(){this.track&&this.track.pause(),this._isPlaying=!1}stop(){this.track&&this.track.stop(),this._isPlaying=!1}seekTo(e){this.track&&this.track.seekTo(e)}getCurrentTime(){return this.track?this.track.currentTime:0}setMasterVolume(e){this._masterVolume=Math.max(0,Math.min(1,e)),this.track&&this.track.setVolume(this._masterVolume)}setPlaybackRate(e){this._playbackRate=Math.max(.5,Math.min(2,e)),this.track&&this.track.setPlaybackRate(this._playbackRate)}setMute(e,t){const n=this.getTrack(e);n&&n.setMuted(t)}setSolo(e,t){console.warn("MediaElementPlayout: Solo is not applicable for single-track playback")}setOnPlaybackComplete(e){this.onPlaybackCompleteCallback=e}dispose(){this.track&&(this.track.dispose(),this.track=null)}get isPlaying(){return this._isPlaying}get masterVolume(){return this._masterVolume}get playbackRate(){return this._playbackRate}get duration(){return this.track?.duration??0}get sampleRate(){return this.track?.peaks.sample_rate??44100}};const vr=i.createContext(null),Cr=i.createContext(null),xr=i.createContext(null),wr=i.createContext(null),si=({track:e,samplesPerPixel:t=1024,waveHeight:n=100,timescale:r=!1,playbackRate:a=1,automaticScroll:s=!1,theme:o,controls:l={show:!1,width:0},annotationList:c,barWidth:u=1,barGap:d=0,progressBarWidth:v,onAnnotationsChange:p,onReady:f,children:C})=>{const x=v??u+d,[b,g]=i.useState(!1),[S,w]=i.useState(0),[m,y]=i.useState(0),[k,I]=i.useState([]),[A,R]=i.useState(a),E=i.useMemo(()=>c?.annotations?c.annotations.map(G=>typeof G.start=="number"?G:rr(G)):[],[c?.annotations]),M=i.useRef(E);M.current=E;const[F,T]=i.useState(null),[P,H]=i.useState(c?.isContinuousPlay??!1),[O]=i.useState(t),[j,L]=i.useState(s),B=i.useRef(null),q=i.useRef(0),U=i.useRef(null),ie=i.useRef(P),te=i.useRef(null),Q=i.useRef(null),le=i.useRef(s),Ge=i.useRef(t);i.useEffect(()=>{ie.current=P},[P]),i.useEffect(()=>{le.current=j},[j]);const V=i.useCallback(G=>{te.current=G,T(G)},[]),de=i.useCallback(G=>{ie.current=G,H(G)},[]),ne=i.useCallback(G=>{Q.current=G},[]),N=e.waveformData.sample_rate;i.useEffect(()=>{const G=new oi({playbackRate:a});G.addTrack({source:e.source,peaks:e.waveformData,name:e.name});const se=G.getTrack(G.track?.id??"");return se&&se.setOnTimeUpdateCallback(ve=>{q.current=ve}),G.setOnPlaybackComplete(()=>{U.current&&(cancelAnimationFrame(U.current),U.current=null),g(!1),V(null),q.current=0,w(0)}),B.current=G,y(e.waveformData.duration),f?.(),()=>{U.current&&cancelAnimationFrame(U.current),G.dispose()}},[e.source,e.waveformData,e.name,a,f]),i.useEffect(()=>{const G=nr(e.waveformData,O,0,0,Math.ceil(e.waveformData.duration*N)),se={clipId:"media-element-clip",trackName:e.name??"Track",peaks:{length:G.length,data:[G.data],bits:G.bits},startSample:0,durationSamples:Math.ceil(e.waveformData.duration*N)};I([[se]])},[e.waveformData,e.name,O,N]);const ce=i.useCallback(()=>{U.current&&cancelAnimationFrame(U.current);const G=()=>{const se=B.current?.getCurrentTime()??0;q.current=se,w(se);const ve=M.current;if(ve.length>0){const xe=ve.find(Me=>se>=Me.start&&se<Me.end);if(ie.current)xe&&xe.id!==te.current?V(xe.id):!xe&&te.current!==null&&V(null);else if(te.current){const Me=ve.find(Ke=>Ke.id===te.current);if(Me&&se>=Me.end){B.current?.stop(),g(!1);return}}else xe&&V(xe.id)}if(le.current&&Q.current){const xe=Q.current,Me=se*N/Ge.current,Ke=xe.clientWidth,Ne=l.show?l.width:0,tt=Me+Ne,ct=Math.max(0,tt-Ke/2);xe.scrollLeft=ct}U.current=requestAnimationFrame(G)};U.current=requestAnimationFrame(G)},[V,N,l]),fe=i.useCallback(()=>{U.current&&(cancelAnimationFrame(U.current),U.current=null)},[]),oe=i.useCallback(G=>{if(!B.current)return;const se=G??q.current;B.current.play(void 0,se),g(!0),ce()},[ce]),Ie=i.useCallback(()=>{B.current&&(B.current.pause(),g(!1),fe(),w(B.current.getCurrentTime()))},[fe]),$e=i.useCallback(()=>{B.current&&(B.current.stop(),g(!1),fe(),q.current=0,w(0),V(null))},[fe,V]),ze=i.useCallback(G=>{const se=Math.max(0,Math.min(G,m));q.current=se,w(se),B.current&&B.current.seekTo(se)},[m]),Le=i.useCallback(G=>{const se=Math.max(.5,Math.min(2,G));R(se),B.current&&B.current.setPlaybackRate(se)},[]),ae=r?30:0,Ye=i.useMemo(()=>({isPlaying:b,currentTime:S,currentTimeRef:q}),[b,S]),et=i.useMemo(()=>({continuousPlay:P,annotations:E,activeAnnotationId:F,playbackRate:A,isAutomaticScroll:j}),[P,E,F,A,j]),_=i.useRef(p);_.current=p;const Te=i.useCallback(G=>{const se=typeof G=="function"?G(M.current):G;if(!_.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}_.current(se)},[]),pe=i.useMemo(()=>({play:oe,pause:Ie,stop:$e,seekTo:ze,setPlaybackRate:Le,setContinuousPlay:de,setAnnotations:Te,setActiveAnnotationId:V,setAutomaticScroll:G=>{L(G)},setScrollContainer:ne,scrollContainerRef:Q}),[oe,Ie,$e,ze,Le,de,Te,V,ne]),ge=i.useMemo(()=>({duration:m,peaksDataArray:k,sampleRate:N,waveHeight:n,timeScaleHeight:ae,samplesPerPixel:O,playoutRef:B,controls:l,barWidth:u,barGap:d,progressBarWidth:x}),[m,k,N,n,ae,O,l,u,d,x]),ot={...Hn,...o};return h.jsx($.ThemeProvider,{theme:ot,children:h.jsx(vr.Provider,{value:Ye,children:h.jsx(Cr.Provider,{value:et,children:h.jsx(xr.Provider,{value:pe,children:h.jsx(wr.Provider,{value:ge,children:C})})})})})},Bt=()=>{const e=i.useContext(vr);if(!e)throw new Error("useMediaElementAnimation must be used within MediaElementPlaylistProvider");return e},Wt=()=>{const e=i.useContext(Cr);if(!e)throw new Error("useMediaElementState must be used within MediaElementPlaylistProvider");return e},en=()=>{const e=i.useContext(xr);if(!e)throw new Error("useMediaElementControls must be used within MediaElementPlaylistProvider");return e},Ft=()=>{const e=i.useContext(wr);if(!e)throw new Error("useMediaElementData must be used within MediaElementPlaylistProvider");return e},ii=({className:e})=>{const{isPlaying:t,currentTimeRef:n}=Re(),{selectionStart:r,selectionEnd:a,isLoopEnabled:s}=De(),{play:o}=he(),l=async()=>{if(r!==a&&a>r)if(s)await o(r);else{const u=a-r;await o(r,u)}else await o(n.current??0)};return h.jsx(je,{onClick:l,disabled:t,className:e,children:"Play"})},li=({className:e})=>{const{isPlaying:t}=Re(),{pause:n}=he();return h.jsx(je,{onClick:n,disabled:!t,className:e,children:"Pause"})},ci=({className:e})=>{const{isPlaying:t}=Re(),{stop:n}=he();return h.jsx(je,{onClick:n,disabled:!t,className:e,children:"Stop"})},ui=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:r}=he(),{playoutRef:a}=Ae(),s=()=>{r(0),t&&a.current&&(a.current.stop(),n(0))};return h.jsx(je,{onClick:s,className:e,children:"Rewind"})},di=({className:e})=>{const{isPlaying:t}=Re(),{play:n,setCurrentTime:r}=he(),{duration:a,playoutRef:s}=Ae(),o=()=>{r(a),t&&s.current&&(s.current.stop(),n(a))};return h.jsx(je,{onClick:o,className:e,children:"Fast Forward"})},fi=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=Re(),{play:a,setCurrentTime:s}=he(),{playoutRef:o}=Ae(),l=()=>{const c=Math.max(0,(n.current??0)-e);s(c),r&&o.current&&(o.current.stop(),a(c))};return h.jsx(je,{onClick:l,className:t,children:"Skip Backward"})},mi=({skipAmount:e=5,className:t})=>{const{currentTimeRef:n,isPlaying:r}=Re(),{play:a,setCurrentTime:s}=he(),{duration:o,playoutRef:l}=Ae(),c=()=>{const u=Math.min(o,(n.current??0)+e);s(u),r&&l.current&&(l.current.stop(),a(u))};return h.jsx(je,{onClick:c,className:t,children:"Skip Forward"})},hi=({className:e})=>{const{isLoopEnabled:t,loopStart:n,loopEnd:r}=De(),{setLoopEnabled:a,setLoopRegion:s}=he(),{duration:o}=Ae(),l=n!==r&&r>n,c=()=>{if(!t&&!l){const u=Math.min(10,o*.25);s(0,Math.max(1,u))}a(!t)};return h.jsx(je,{onClick:c,className:e,title:t?"Disable loop":"Enable loop",children:t?"Loop On":"Loop Off"})},pi=({className:e})=>{const{selectionStart:t,selectionEnd:n,loopStart:r,loopEnd:a}=De(),{setLoopRegionFromSelection:s,clearLoopRegion:o}=he(),l=t!==n&&n>t,c=r!==a&&a>r,u=()=>{c?o():s()};return h.jsx(je,{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"})},gi=({className:e,disabled:t})=>{const{zoomIn:n}=he(),{canZoomIn:r}=Ae();return h.jsx(je,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom In"})},bi=({className:e,disabled:t})=>{const{zoomOut:n}=he(),{canZoomOut:r}=Ae();return h.jsx(je,{variant:"success",onClick:n,disabled:t||!r,className:e,children:"Zoom Out"})},vi=({className:e})=>{const{masterVolume:t}=Ae(),{setMasterVolume:n}=he();return h.jsx(Ra,{volume:t,onChange:n,className:e})},Ci=({className:e})=>{const{timeFormat:t}=Ae(),{setTimeFormat:n}=he();return h.jsx(uo,{value:t,onChange:n,className:e})},xi=$.span`
|
|
1194
1228
|
font-family: 'Courier New', Monaco, monospace;
|
|
1195
1229
|
font-size: 1rem;
|
|
1196
1230
|
font-weight: 600;
|
|
1197
1231
|
color: ${e=>e.theme?.textColor||"#333"};
|
|
1198
1232
|
user-select: none;
|
|
1199
|
-
`,
|
|
1233
|
+
`,wi=({className:e})=>{const t=i.useRef(null),n=i.useRef(null),{isPlaying:r,currentTimeRef:a,playbackStartTimeRef:s,audioStartPositionRef:o}=Re(),{timeFormat:l}=Ae(),c=l;return i.useEffect(()=>{const u=()=>{if(t.current){let d;if(r){const v=Z.getContext().currentTime-(s.current??0);d=(o.current??0)+v}else d=a.current??0;t.current.textContent=lt(d,c)}r&&(n.current=requestAnimationFrame(u))};return r?n.current=requestAnimationFrame(u):u(),()=>{n.current&&(cancelAnimationFrame(n.current),n.current=null)}},[r,c,a,s,o]),i.useEffect(()=>{!r&&t.current&&(t.current.textContent=lt(a.current??0,c))}),h.jsx(xi,{ref:t,className:e,"aria-label":"Audio position",children:lt(a.current??0,c)})},yi=({className:e})=>{const{selectionStart:t,selectionEnd:n}=De(),{setSelection:r}=he();return h.jsx(za,{selectionStart:t,selectionEnd:n,onSelectionChange:r,className:e})},ki=({className:e})=>{const{isAutomaticScroll:t}=De(),{setAutomaticScroll:n}=he();return h.jsx(fa,{checked:t,onChange:n,className:e})},Si=({className:e})=>{const{continuousPlay:t}=De(),{setContinuousPlay:n}=he();return h.jsx(ms,{checked:t,onChange:n,className:e})},Ai=({className:e})=>{const{linkEndpoints:t}=De(),{setLinkEndpoints:n}=he();return h.jsx(hs,{checked:t,onChange:n,className:e})},Ii=({className:e})=>{const{annotationsEditable:t}=De(),{setAnnotationsEditable:n}=he();return h.jsx(ps,{checked:t,onChange:n,className:e})},$i=({filename:e,className:t})=>{const{annotations:n}=De();return h.jsx(bs,{annotations:n,filename:e,className:t})},Mi=({label:e="Export WAV",filename:t="export",mode:n="master",trackIndex:r,bitDepth:a=16,applyEffects:s=!0,effectsFunction:o,createOfflineTrackEffects:l,className:c,onExportComplete:u,onExportError:d})=>{const{tracks:v,trackStates:p}=Ae(),{exportWav:f,isExporting:C,progress:x}=fr(),b=async()=>{try{const S=await f(v,p,{filename:t,mode:n,trackIndex:r,bitDepth:a,applyEffects:s,effectsFunction:o,createOfflineTrackEffects:l,autoDownload:!0});u?.(S.blob)}catch(S){d?.(S instanceof Error?S:new Error("Export failed"))}},g=C?`Exporting ${Math.round(x*100)}%`:e;return h.jsx(je,{onClick:b,disabled:C||v.length===0,className:c,children:g})},Ei=$.div`
|
|
1200
1234
|
position: absolute;
|
|
1201
1235
|
top: 0;
|
|
1202
1236
|
left: 0;
|
|
@@ -1206,9 +1240,9 @@
|
|
|
1206
1240
|
z-index: 100; /* Below sticky controls (z-index: 101) so playhead is hidden when scrolled behind controls */
|
|
1207
1241
|
pointer-events: none;
|
|
1208
1242
|
will-change: transform;
|
|
1209
|
-
`,
|
|
1243
|
+
`,Ri=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),r=i.useRef(null),{isPlaying:a,currentTimeRef:s,playbackStartTimeRef:o,audioStartPositionRef:l}=Re(),{samplesPerPixel:c,sampleRate:u,progressBarWidth:d}=Ae();return i.useEffect(()=>{const v=()=>{if(n.current){let p;if(a){const C=Z.getContext().currentTime-(o.current??0);p=(l.current??0)+C}else p=s.current??0;const f=p*u/c+t;n.current.style.transform=`translate3d(${f}px, 0, 0)`}a&&(r.current=requestAnimationFrame(v))};return a?r.current=requestAnimationFrame(v):v(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[a,u,c,t,s,o,l]),i.useEffect(()=>{if(!a&&n.current){const p=(s.current??0)*u/c+t;n.current.style.transform=`translate3d(${p}px, 0, 0)`}}),h.jsx(Ei,{ref:n,$color:e,$width:d,"data-playhead":!0})},Di=$.div`
|
|
1210
1244
|
position: relative;
|
|
1211
|
-
`,
|
|
1245
|
+
`,Lt=$.div`
|
|
1212
1246
|
position: absolute;
|
|
1213
1247
|
top: ${e=>e.$top}px;
|
|
1214
1248
|
left: 0;
|
|
@@ -1220,7 +1254,7 @@
|
|
|
1220
1254
|
transform: translateZ(0);
|
|
1221
1255
|
backface-visibility: hidden;
|
|
1222
1256
|
will-change: transform;
|
|
1223
|
-
`,
|
|
1257
|
+
`,Ti=$.div`
|
|
1224
1258
|
position: absolute;
|
|
1225
1259
|
top: ${e=>e.$top}px;
|
|
1226
1260
|
left: 0;
|
|
@@ -1229,10 +1263,10 @@
|
|
|
1229
1263
|
pointer-events: none;
|
|
1230
1264
|
z-index: 1;
|
|
1231
1265
|
will-change: width;
|
|
1232
|
-
`,
|
|
1266
|
+
`,Bi=$.div`
|
|
1233
1267
|
position: relative;
|
|
1234
1268
|
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:$,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`
|
|
1269
|
+
`,En=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=i.useRef(null),a=i.useRef(null),s=vt(),{waveHeight:o}=bt(),{isPlaying:l,currentTimeRef:c,playbackStartTimeRef:u,audioStartPositionRef:d}=Re(),{samplesPerPixel:v,sampleRate:p}=Ae(),f=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const I=()=>{if(r.current){let A;if(l){const F=Z.getContext().currentTime-(u.current??0);A=(d.current??0)+F}else A=c.current??0;const R=A*p,E=e+t;let M=0;if(R<=e)M=0;else if(R>=E)M=n.length;else{const F=R-e;M=Math.floor(F/v)}r.current.style.width=`${M}px`}l&&(a.current=requestAnimationFrame(I))};return l?a.current=requestAnimationFrame(I):I(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[l,p,v,e,t,n.length,c,u,d]),i.useEffect(()=>{if(!l&&r.current){const A=(c.current??0)*p,R=e+t;let E=0;if(A<=e)E=0;else if(A>=R)E=n.length;else{const M=A-e;E=Math.floor(M/v)}r.current.style.width=`${E}px`}});const C=s?.waveformDrawMode||"inverted";let x;C==="inverted"?x=n.isSelected&&s?s.selectedWaveFillColor:s?.waveFillColor||"white":x=n.isSelected&&s?s.selectedWaveOutlineColor:s?.waveOutlineColor||"grey";const b=n.renderMode==="spectrogram"||n.renderMode==="both",g=n.renderMode==="both",S=b?"#000":Qe(x),w=Math.floor(o/2),m=o,y=n.index*o,k=Qe(x);return h.jsxs(Di,{children:[g?h.jsxs(h.Fragment,{children:[h.jsx(Lt,{$color:"#000",$height:w,$top:y,$width:n.length}),h.jsx(Lt,{$color:k,$height:w,$top:y+w,$width:n.length})]}):h.jsx(Lt,{$color:S,$height:m,$top:y,$width:n.length}),h.jsx(Ti,{ref:r,$color:f,$height:m,$top:y}),h.jsx(Bi,{children:h.jsx(Un,{...n,transparentBackground:!0})})]})},yr=i.createContext(null),Wi=yr.Provider;function kr(){return i.useContext(yr)}const Fi=60,Sr=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,getAnnotationBoxLabel:a,className:s,showClipHeaders:o=!1,interactiveClips:l=!1,showFades:c=!1,touchOptimized:u=!1,onRemoveTrack:d,recordingState:v})=>{const p=vt(),{isPlaying:f,currentTimeRef:C,playbackStartTimeRef:x,audioStartPositionRef:b}=Re(),{selectionStart:g,selectionEnd:S,annotations:w,activeAnnotationId:m,annotationsEditable:y,linkEndpoints:k,continuousPlay:I,selectedTrackId:A,loopStart:R,loopEnd:E,isLoopEnabled:M}=De(),{setAnnotations:F,setActiveAnnotationId:T,setTrackMute:P,setTrackSolo:H,setTrackVolume:O,setTrackPan:j,setSelection:L,play:B,setScrollContainer:q,setSelectedTrackId:U,setCurrentTime:ie,setLoopRegion:te}=he(),{audioBuffers:Q,peaksDataArray:le,trackStates:Ge,tracks:V,duration:de,samplesPerPixel:ne,sampleRate:N,waveHeight:ce,timeScaleHeight:fe,controls:oe,playoutRef:Ie,barWidth:$e,barGap:ze,isReady:Le}=Ae(),ae=kr(),Ye=i.useMemo(()=>{if(!ae)return new Map;const z=new Map;return V.forEach(Y=>{if((ae.trackSpectrogramOverrides.get(Y.id)?.renderMode??Y.renderMode??"waveform")==="waveform")return;const me=ae.trackSpectrogramOverrides.get(Y.id),be=me?.colorMap??Y.spectrogramColorMap??ae.spectrogramColorMap??"viridis",Ee=me?.config??Y.spectrogramConfig??ae.spectrogramConfig;z.set(Y.id,{colorLUT:ae.getColorMap(be),frequencyScaleFn:ae.getFrequencyScale(Ee?.frequencyScale??"mel"),config:Ee})}),z},[V,ae]),et=i.useMemo(()=>{if(ae?.spectrogramWorkerApi)return{registerCanvas:ae.spectrogramWorkerApi.registerCanvas.bind(ae.spectrogramWorkerApi),unregisterCanvas:ae.spectrogramWorkerApi.unregisterCanvas.bind(ae.spectrogramWorkerApi)}},[ae?.spectrogramWorkerApi]),[_,Te]=i.useState(null),[pe,ge]=i.useState(!1),ot=i.useRef(null),G=i.useCallback(z=>{ot.current=z,q(z)},[q]);let se=Q.length>0?de:Fi;if(v?.isRecording){const Y=(v.startSample+v.durationSamples)/N;se=Math.max(se,Y+10)}const ve=Math.floor(se*N/ne),xe=async z=>{T(z.id);const Y=I?void 0:z.end-z.start;try{await B(z.start,Y)}catch(re){console.error("waveform-playlist: Failed to start playback for annotation",z.id,re)}},Me=i.useCallback(z=>{if(z>=0&&z<V.length){const Y=V[z];U(Y.id)}},[V,U]),Ke=z=>{const Y=z.currentTarget.getBoundingClientRect(),re=oe.show?oe.width:0,be=(z.clientX-Y.left-re)*ne/N,Xe=z.clientY-Y.top;let Ze=0,ee=-1;for(let we=0;we<le.length;we++){const Ue=le[we],st=Ue.length>0?Math.max(...Ue.map(ut=>ut.peaks.data.length)):1,Pe=((ae?.trackSpectrogramOverrides.get(V[we]?.id)?.renderMode??V[we]?.renderMode??"waveform")==="both"?st*2:st)*ce+(o?22:0);if(Xe>=Ze&&Xe<Ze+Pe){ee=we;break}Ze+=Pe}ee!==-1&&Me(ee),ge(!0),ie(be),L(be,be)},Ne=z=>{if(!pe)return;const Y=z.currentTarget.getBoundingClientRect(),re=oe.show?oe.width:0,be=(z.clientX-Y.left-re)*ne/N,Ee=Math.min(g,be),Xe=Math.max(g,be);L(Ee,Xe)},tt=z=>{if(!pe)return;ge(!1);const Y=z.currentTarget.getBoundingClientRect(),re=oe.show?oe.width:0,be=(z.clientX-Y.left-re)*ne/N,Ee=Math.min(g,be),Xe=Math.max(g,be);Math.abs(Xe-Ee)<.1?(ie(Ee),f&&Ie.current?(Ie.current.stop(),B(Ee)):Ie.current&&Ie.current.stop()):L(Ee,Xe)};return V.some(z=>z.clips.length>0)&&(Q.length===0||le.length===0)?h.jsx("div",{className:s,children:"Loading waveform..."}):h.jsxs(Kn,{children:[h.jsx(gt.Provider,{value:{samplesPerPixel:ne,sampleRate:N,zoomLevels:[ne],waveHeight:ce,timeScaleHeight:fe,duration:se*1e3,controls:oe,barWidth:$e,barGap:ze},children:h.jsx(Kt,{theme:p,backgroundColor:Qe(p.waveOutlineColor),timescaleBackgroundColor:p.timescaleBackgroundColor,scrollContainerWidth:ve+(oe.show?oe.width:0),timescaleWidth:ve,tracksWidth:ve,controlsWidth:oe.show?oe.width:0,onTracksMouseDown:Ke,onTracksMouseMove:Ne,onTracksMouseUp:tt,scrollContainerRef:G,isSelecting:pe,"data-playlist-state":Le?"ready":"loading",timescale:fe>0?h.jsxs(h.Fragment,{children:[h.jsx(Jn,{renderTimestamp:t}),M&&h.jsx(ja,{startPosition:Math.min(R,E)*N/ne,endPosition:Math.max(R,E)*N/ne,markerColor:p.loopMarkerColor,regionColor:p.loopRegionColor,minPosition:0,maxPosition:ve,controlsOffset:oe.show?oe.width:0,onLoopRegionChange:(z,Y)=>{const re=z*ne/N,me=Y*ne/N;te(re,me)}})]}):void 0,children:h.jsxs(h.Fragment,{children:[le.map((z,Y)=>{const re=V[Y];if(!re)return null;const me=Ge[Y]||{name:`Track ${Y+1}`,muted:!1,soloed:!1,volume:1,pan:0},be=ae?.trackSpectrogramOverrides.get(re.id)?.renderMode??re.renderMode??"waveform",Ee=e?e(Y):h.jsxs(vo,{onClick:()=>Me(Y),children:[h.jsxs(Co,{style:{justifyContent:"center",position:"relative"},children:[d&&h.jsx(bo,{onClick:ee=>{ee.stopPropagation(),d(Y)}}),h.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"0 24px",display:"block"},children:me.name||`Track ${Y+1}`}),ae?.renderMenuItems&&h.jsx("span",{style:{position:"absolute",right:0,top:0},children:h.jsx($o,{items:ee=>ae.renderMenuItems({renderMode:be,onRenderModeChange:we=>ae.setTrackRenderMode(re.id,we),onOpenSettings:()=>Te(re.id),onClose:ee})})})]}),h.jsxs(po,{children:[h.jsx(Cn,{$variant:me.muted?"danger":"outline",onClick:()=>P(Y,!me.muted),children:"Mute"}),h.jsx(Cn,{$variant:me.soloed?"info":"outline",onClick:()=>H(Y,!me.soloed),children:"Solo"})]}),h.jsxs(wn,{children:[h.jsx(xo,{}),h.jsx(xn,{min:"0",max:"1",step:"0.01",value:me.volume,onChange:ee=>O(Y,parseFloat(ee.target.value))}),h.jsx(wo,{})]}),h.jsxs(wn,{children:[h.jsx("span",{children:"L"}),h.jsx(xn,{min:"-1",max:"1",step:"0.01",value:me.pan,onChange:ee=>j(Y,parseFloat(ee.target.value))}),h.jsx("span",{children:"R"})]})]}),Ze=z.length>0?Math.max(...z.map(ee=>ee.peaks.data.length)):1;return h.jsx(Jt.Provider,{value:Ee,children:h.jsxs(qn,{numChannels:Ze,backgroundColor:Qe(p.waveOutlineColor),offset:0,width:ve,hasClipHeaders:o,trackId:re.id,isSelected:re.id===A,children:[be!=="waveform"&&(()=>{const ee=Ye.get(re.id),we=ee?.config;return!we?.labels||!ee?null:h.jsx(Qa,{waveHeight:ce,numChannels:Ze,frequencyScaleFn:ee.frequencyScaleFn,minFrequency:we.minFrequency??0,maxFrequency:we.maxFrequency??N/2,labelsColor:we.labelsColor,labelsBackground:we.labelsBackground,renderMode:be,hasClipHeaders:o})})(),z.map((ee,we)=>{const Ue=ee.peaks,st=Ue.length;return h.jsx(Gt,{clipId:ee.clipId,trackIndex:Y,clipIndex:we,trackName:ee.trackName,startSample:ee.startSample,durationSamples:ee.durationSamples,samplesPerPixel:ne,showHeader:o,disableHeaderDrag:!l,isSelected:re.id===A,trackId:re.id,fadeIn:ee.fadeIn,fadeOut:ee.fadeOut,sampleRate:N,showFades:c,touchOptimized:u,onMouseDown:He=>{He.target.closest('[role="button"][aria-roledescription="draggable"]')||Me(Y)},children:Ue.data.map((He,Je)=>{const Pe=ae?.spectrogramDataMap.get(ee.clipId),ut=Pe?.[Je]??Pe?.[0],dt=Ye.get(re.id),nt=dt?.config;return h.jsx(En,{index:Je,data:He,bits:Ue.bits,length:st,isSelected:re.id===A,clipStartSample:ee.startSample,clipDurationSamples:ee.durationSamples,renderMode:be,spectrogramData:ut,samplesPerPixel:ne,spectrogramColorLUT:dt?.colorLUT,spectrogramFrequencyScaleFn:dt?.frequencyScaleFn,spectrogramMinFrequency:nt?.minFrequency,spectrogramMaxFrequency:nt?.maxFrequency,spectrogramWorkerApi:et,spectrogramClipId:ee.clipId,spectrogramOnCanvasesReady:ae?(Oe,Be)=>{ae.registerSpectrogramCanvases(ee.clipId,Je,Oe,Be)}:void 0},`${ee.clipId}-${Je}`)})},ee.clipId)}),v?.isRecording&&v.trackId===re.id&&v.peaks.length>0&&h.jsx(Gt,{clipId:"recording-preview",trackIndex:Y,clipIndex:z.length,trackName:"Recording...",startSample:v.startSample,durationSamples:v.durationSamples,samplesPerPixel:ne,showHeader:o,disableHeaderDrag:!0,isSelected:re.id===A,trackId:re.id,children:h.jsx(En,{index:0,data:v.peaks,bits:16,length:Math.floor(v.peaks.length/2),isSelected:re.id===A,clipStartSample:v.startSample,clipDurationSamples:v.durationSamples},`${re.id}-recording-0`)},`${re.id}-recording`)]})},re.id)}),w.length>0&&h.jsx(or,{height:30,width:ve,children:w.map((z,Y)=>{const re=z.start*N/ne,me=z.end*N/ne,be=a?a(z,Y):z.id;return h.jsx(ar,{annotationId:z.id,annotationIndex:Y,startPosition:re,endPosition:me,label:be,color:"#ff9800",isActive:z.id===m,onClick:()=>xe(z),editable:y},z.id)})}),g!==S&&h.jsx(Nn,{startPosition:Math.min(g,S)*N/ne+(oe.show?oe.width:0),endPosition:Math.max(g,S)*N/ne+(oe.show?oe.width:0),color:p.selectionColor}),(f||g===S)&&(n?n({position:(C.current??0)*N/ne+(oe.show?oe.width:0),color:p.playheadColor,isPlaying:f,currentTimeRef:C,playbackStartTimeRef:x,audioStartPositionRef:b,samplesPerPixel:ne,sampleRate:N,controlsOffset:oe.show?oe.width:0,getAudioContextTime:()=>Z.getContext().currentTime}):h.jsx(Ri,{color:p.playheadColor,controlsOffset:oe.show?oe.width:0}))]})})}),ae?.SettingsModal&&typeof document<"u"&&Rn.createPortal(h.jsx(ae.SettingsModal,{open:_!==null,onClose:()=>Te(null),config:_!==null?ae.trackSpectrogramOverrides.get(_)?.config??V.find(z=>z.id===_)?.spectrogramConfig??ae.spectrogramConfig??{}:{},colorMap:_!==null?ae.trackSpectrogramOverrides.get(_)?.colorMap??V.find(z=>z.id===_)?.spectrogramColorMap??ae.spectrogramColorMap??"viridis":"viridis",onApply:(z,Y)=>{_!==null&&ae.setTrackSpectrogramConfig(_,z,Y)}}),document.body)]})},Ar=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,controls:r,annotationListConfig:a,scrollActivePosition:s="center",scrollActiveContainer:o="nearest"})=>{const{annotations:l,activeAnnotationId:c,annotationsEditable:u,linkEndpoints:d,continuousPlay:v}=De(),{setAnnotations:p}=he(),f=a??{linkEndpoints:d,continuousPlay:v},C=i.useCallback(x=>{p(x),n?.(x)},[p,n]);return h.jsx(sr,{annotations:l,activeAnnotationId:c??void 0,shouldScrollToActive:!0,scrollActivePosition:s,scrollActiveContainer:o,editable:u,controls:u?r:void 0,annotationListConfig:f,height:e,onAnnotationUpdate:C,renderAnnotationItem:t})},_i=({renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,annotationListConfig:a,annotationTextHeight:s,renderAnnotationItem:o,getAnnotationBoxLabel:l,scrollActivePosition:c="center",scrollActiveContainer:u="nearest",className:d,showClipHeaders:v=!1,interactiveClips:p=!1,showFades:f=!1,touchOptimized:C=!1,onRemoveTrack:x,recordingState:b})=>{const{annotations:g}=De();return h.jsxs(h.Fragment,{children:[h.jsx(Sr,{renderTrackControls:e,renderTimestamp:t,renderPlayhead:n,annotationControls:r,getAnnotationBoxLabel:l,className:d,showClipHeaders:v,interactiveClips:p,showFades:f,touchOptimized:C,onRemoveTrack:x,recordingState:b}),g.length>0&&h.jsx(Ar,{height:s,renderAnnotationItem:o,controls:r,annotationListConfig:a,scrollActivePosition:c,scrollActiveContainer:u})]})},Zi=$.div`
|
|
1236
1270
|
position: absolute;
|
|
1237
1271
|
top: 0;
|
|
1238
1272
|
left: 0;
|
|
@@ -1242,9 +1276,9 @@
|
|
|
1242
1276
|
z-index: 100;
|
|
1243
1277
|
pointer-events: none;
|
|
1244
1278
|
will-change: transform;
|
|
1245
|
-
`,
|
|
1279
|
+
`,Pi=({color:e="#ff0000",controlsOffset:t=0})=>{const n=i.useRef(null),r=i.useRef(null),{isPlaying:a,currentTimeRef:s}=Bt(),{samplesPerPixel:o,sampleRate:l,progressBarWidth:c}=Ft();return i.useEffect(()=>{const u=()=>{if(n.current){const v=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${v}px, 0, 0)`}a&&(r.current=requestAnimationFrame(u))};return a?r.current=requestAnimationFrame(u):u(),()=>{r.current&&(cancelAnimationFrame(r.current),r.current=null)}},[a,l,o,t,s]),i.useEffect(()=>{if(!a&&n.current){const d=(s.current??0)*l/o+t;n.current.style.transform=`translate3d(${d}px, 0, 0)`}}),h.jsx(Zi,{ref:n,$color:e,$width:c,"data-playhead":!0})},Vi=$.div`
|
|
1246
1280
|
position: relative;
|
|
1247
|
-
`,
|
|
1281
|
+
`,ji=$.div`
|
|
1248
1282
|
position: absolute;
|
|
1249
1283
|
top: ${e=>e.$top}px;
|
|
1250
1284
|
left: 0;
|
|
@@ -1255,7 +1289,7 @@
|
|
|
1255
1289
|
transform: translateZ(0);
|
|
1256
1290
|
backface-visibility: hidden;
|
|
1257
1291
|
will-change: transform;
|
|
1258
|
-
`,
|
|
1292
|
+
`,zi=$.div`
|
|
1259
1293
|
position: absolute;
|
|
1260
1294
|
top: ${e=>e.$top}px;
|
|
1261
1295
|
left: 0;
|
|
@@ -1264,8 +1298,8 @@
|
|
|
1264
1298
|
pointer-events: none;
|
|
1265
1299
|
z-index: 1;
|
|
1266
1300
|
will-change: width;
|
|
1267
|
-
`,
|
|
1301
|
+
`,Hi=$.div`
|
|
1268
1302
|
position: relative;
|
|
1269
1303
|
z-index: 2;
|
|
1270
|
-
`,
|
|
1304
|
+
`,Li=({clipStartSample:e,clipDurationSamples:t,...n})=>{const r=i.useRef(null),a=i.useRef(null),s=vt(),{waveHeight:o}=bt(),{isPlaying:l,currentTimeRef:c}=Bt(),{samplesPerPixel:u,sampleRate:d}=Ft(),v=s?.waveProgressColor||"rgba(0, 0, 0, 0.1)";i.useEffect(()=>{const x=()=>{if(r.current){const g=(c.current??0)*d,S=e+t;let w=0;if(g<=e)w=0;else if(g>=S)w=n.length;else{const m=g-e;w=Math.floor(m/u)}r.current.style.width=`${w}px`}l&&(a.current=requestAnimationFrame(x))};return l?a.current=requestAnimationFrame(x):x(),()=>{a.current&&(cancelAnimationFrame(a.current),a.current=null)}},[l,d,u,e,t,n.length,c]),i.useEffect(()=>{if(!l&&r.current){const b=(c.current??0)*d,g=e+t;let S=0;if(b<=e)S=0;else if(b>=g)S=n.length;else{const w=b-e;S=Math.floor(w/u)}r.current.style.width=`${S}px`}});const p=s?.waveformDrawMode||"inverted";let f;p==="inverted"?f=s?.selectedWaveFillColor||s?.waveFillColor||"white":f=s?.selectedWaveOutlineColor||s?.waveOutlineColor||"grey";const C=Qe(f);return h.jsxs(Vi,{children:[h.jsx(ji,{$color:C,$height:o,$top:n.index*o,$width:n.length}),h.jsx(zi,{ref:r,$color:v,$height:o,$top:n.index*o}),h.jsx(Hi,{children:h.jsx(Un,{...n,isSelected:!0,transparentBackground:!0})})]})},Ir=({getAnnotationBoxLabel:e,editable:t=!1,linkEndpoints:n=!1,onAnnotationUpdate:r,className:a})=>{const s=vt(),{isPlaying:o,currentTimeRef:l}=Bt(),{annotations:c,activeAnnotationId:u}=Wt(),{play:d,seekTo:v,setActiveAnnotationId:p,setAnnotations:f,setScrollContainer:C}=en(),{duration:x,peaksDataArray:b,sampleRate:g,waveHeight:S,timeScaleHeight:w,samplesPerPixel:m,controls:y,playoutRef:k,barWidth:I,barGap:A}=Ft(),[R,E]=i.useState(0),[M,F]=i.useState(0),[T,P]=i.useState(!1),H=i.useRef(null),O=i.useCallback(V=>{H.current=V,C(V)},[C]),j=Math.floor(x*g/m),L=i.useCallback(async V=>{p(V.id);try{await d(V.start)}catch(de){console.error("waveform-playlist: Failed to start playback for annotation",V.id,de)}},[p,d]),B=i.useCallback(V=>{f(V),r?.(V)},[f,r]),{onDragStart:q,onDragMove:U,onDragEnd:ie}=dr({annotations:c,onAnnotationsChange:B,samplesPerPixel:m,sampleRate:g,duration:x,linkEndpoints:n}),te=i.useCallback(V=>{const de=V.currentTarget.getBoundingClientRect(),ne=y.show?y.width:0,ce=(V.clientX-de.left-ne)*m/g;P(!0),E(ce),F(ce)},[y,m,g]),Q=i.useCallback(V=>{if(!T)return;const de=V.currentTarget.getBoundingClientRect(),ne=y.show?y.width:0,ce=(V.clientX-de.left-ne)*m/g;F(ce)},[T,y,m,g]),le=i.useCallback(V=>{if(!T)return;P(!1);const de=V.currentTarget.getBoundingClientRect(),ne=y.show?y.width:0,ce=(V.clientX-de.left-ne)*m/g,fe=Math.min(R,ce),oe=Math.max(R,ce);Math.abs(oe-fe)<.1?(v(fe),E(fe),F(fe),o&&k.current&&(k.current.stop(),d(fe))):(E(fe),F(oe))},[T,R,m,g,y,v,o,k,d]);if(b.length===0)return h.jsx("div",{className:a,children:"Loading waveform..."});const Ge=null;return h.jsx(Kn,{children:h.jsx(gt.Provider,{value:{samplesPerPixel:m,sampleRate:g,zoomLevels:[m],waveHeight:S,timeScaleHeight:w,duration:x*1e3,controls:y,barWidth:I,barGap:A},children:h.jsx(Kt,{theme:s,backgroundColor:Qe(s.waveOutlineColor),timescaleBackgroundColor:s.timescaleBackgroundColor,scrollContainerWidth:j+(y.show?y.width:0),timescaleWidth:j,tracksWidth:j,controlsWidth:y.show?y.width:0,onTracksMouseDown:te,onTracksMouseMove:Q,onTracksMouseUp:le,scrollContainerRef:O,isSelecting:T,timescale:w>0?h.jsx(Jn,{}):void 0,children:h.jsxs(h.Fragment,{children:[b.map((V,de)=>{const ne=V.length>0?Math.max(...V.map(N=>N.peaks.data.length)):1;return h.jsx(Jt.Provider,{value:Ge,children:h.jsx(qn,{numChannels:ne,backgroundColor:Qe(s.waveOutlineColor),offset:0,width:j,hasClipHeaders:!1,trackId:`media-element-track-${de}`,isSelected:!0,children:V.map((N,ce)=>{const fe=N.peaks,oe=fe.length;return h.jsx(Gt,{clipId:N.clipId,trackIndex:de,clipIndex:ce,trackName:N.trackName,startSample:N.startSample,durationSamples:N.durationSamples,samplesPerPixel:m,showHeader:!1,disableHeaderDrag:!0,isSelected:!0,trackId:`media-element-track-${de}`,children:fe.data.map((Ie,$e)=>h.jsx(Li,{index:$e,data:Ie,bits:fe.bits,length:oe,clipStartSample:N.startSample,clipDurationSamples:N.durationSamples},`${de}-${ce}-${$e}`))},`${de}-${ce}`)})})},de)}),c.length>0&&h.jsx(_e.DndContext,{onDragStart:q,onDragMove:U,onDragEnd:ie,modifiers:t?[qr.restrictToHorizontalAxis]:[],children:h.jsx(or,{height:30,width:j,children:c.map((V,de)=>{const ne=V.start*g/m,N=V.end*g/m,ce=e?e(V,de):V.id;return h.jsx(ar,{annotationId:V.id,annotationIndex:de,startPosition:ne,endPosition:N,label:ce,color:"#ff9800",isActive:V.id===u,onClick:()=>L(V),editable:t},V.id)})})}),R!==M&&h.jsx(Nn,{startPosition:Math.min(R,M)*g/m+(y.show?y.width:0),endPosition:Math.max(R,M)*g/m+(y.show?y.width:0),color:s.selectionColor}),h.jsx(Pi,{color:s.playheadColor,controlsOffset:y.show?y.width:0})]})})})})},$r=({height:e,renderAnnotationItem:t,onAnnotationUpdate:n,editable:r=!1,controls:a,annotationListConfig:s,scrollActivePosition:o="center",scrollActiveContainer:l="nearest"})=>{const{annotations:c,activeAnnotationId:u,continuousPlay:d}=Wt(),{setAnnotations:v}=en(),p=s??{linkEndpoints:!1,continuousPlay:d},f=i.useCallback(C=>{v(C),n?.(C)},[v,n]);return h.jsx(sr,{annotations:c,activeAnnotationId:u??void 0,shouldScrollToActive:!0,scrollActivePosition:o,scrollActiveContainer:l,editable:r,controls:r?a:void 0,annotationListConfig:p,height:e,onAnnotationUpdate:f,renderAnnotationItem:t})},Xi=({annotationTextHeight:e,getAnnotationBoxLabel:t,renderAnnotationItem:n,editable:r=!1,linkEndpoints:a=!1,onAnnotationUpdate:s,scrollActivePosition:o="center",scrollActiveContainer:l="nearest",className:c})=>{const{annotations:u}=Wt();return h.jsxs(h.Fragment,{children:[h.jsx(Ir,{getAnnotationBoxLabel:t,editable:r,linkEndpoints:a,onAnnotationUpdate:s,className:c}),u.length>0&&h.jsx($r,{height:e,renderAnnotationItem:n,onAnnotationUpdate:s,editable:r,annotationListConfig:{linkEndpoints:a,continuousPlay:!1},scrollActivePosition:o,scrollActiveContainer:l})]})};exports.Tone=Tn;exports.AudioPosition=wi;exports.AutomaticScrollCheckbox=ki;exports.ContinuousPlayCheckbox=Si;exports.DownloadAnnotationsButton=$i;exports.EditableCheckbox=Ii;exports.ExportWavButton=Mi;exports.FastForwardButton=di;exports.LinkEndpointsCheckbox=Ai;exports.LoopButton=hi;exports.MasterVolumeControl=vi;exports.MediaElementAnnotationList=$r;exports.MediaElementPlaylist=Ir;exports.MediaElementPlaylistProvider=si;exports.MediaElementWaveform=Xi;exports.PauseButton=li;exports.PlayButton=ii;exports.PlaylistAnnotationList=Ar;exports.PlaylistVisualization=Sr;exports.RewindButton=ui;exports.SelectionTimeInputs=yi;exports.SetLoopRegionButton=pi;exports.SkipBackwardButton=fi;exports.SkipForwardButton=mi;exports.SpectrogramIntegrationProvider=Wi;exports.StopButton=ci;exports.TimeFormatSelect=Ci;exports.Waveform=_i;exports.WaveformPlaylistProvider=ni;exports.ZoomInButton=gi;exports.ZoomOutButton=bi;exports.createEffectChain=Ys;exports.createEffectInstance=ht;exports.effectCategories=Xs;exports.effectDefinitions=Ct;exports.getEffectDefinition=Qt;exports.getEffectsByCategory=Ls;exports.getShortcutLabel=$s;exports.getWaveformDataMetadata=Ko;exports.loadPeaksFromWaveformData=Yo;exports.loadWaveformData=qt;exports.useAnnotationDragHandlers=dr;exports.useAnnotationKeyboardControls=Es;exports.useAudioTracks=ys;exports.useClipDragHandlers=ks;exports.useClipSplitting=Is;exports.useDragSensors=As;exports.useDynamicEffects=Ks;exports.useExportWav=fr;exports.useIntegratedRecording=Hs;exports.useKeyboardShortcuts=Mt;exports.useMasterAnalyser=Cs;exports.useMasterVolume=cr;exports.useMediaElementAnimation=Bt;exports.useMediaElementControls=en;exports.useMediaElementData=Ft;exports.useMediaElementState=Wt;exports.usePlaybackAnimation=Re;exports.usePlaybackShortcuts=Ms;exports.usePlaylistControls=he;exports.usePlaylistData=Ae;exports.usePlaylistState=De;exports.useSpectrogramIntegration=kr;exports.useTimeFormat=ir;exports.useTrackDynamicEffects=Us;exports.useWaveformPlaylist=ri;exports.useZoomControls=lr;exports.waveformDataToPeaks=tr;
|
|
1271
1305
|
//# sourceMappingURL=index.js.map
|