wavesurfer.js 7.0.0-alpha.8 → 7.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -18
- package/dist/base-plugin.d.ts +6 -4
- package/dist/base-plugin.js +9 -3
- package/dist/decoder.d.ts +8 -7
- package/dist/decoder.js +43 -38
- package/dist/event-emitter.d.ts +16 -10
- package/dist/event-emitter.js +38 -16
- package/dist/fetcher.d.ts +4 -3
- package/dist/fetcher.js +5 -15
- package/dist/player.d.ts +31 -11
- package/dist/player.js +58 -31
- package/dist/plugins/envelope.d.ts +71 -0
- package/dist/plugins/envelope.js +347 -0
- package/dist/plugins/envelope.min.js +1 -0
- package/dist/plugins/minimap.d.ts +39 -0
- package/dist/plugins/minimap.js +117 -0
- package/dist/plugins/minimap.min.js +1 -0
- package/dist/plugins/multitrack.d.ts +117 -0
- package/dist/plugins/multitrack.js +507 -0
- package/dist/plugins/multitrack.min.js +1 -0
- package/dist/plugins/record.d.ts +26 -0
- package/dist/plugins/record.js +126 -0
- package/dist/plugins/record.min.js +1 -0
- package/dist/plugins/regions.d.ts +83 -43
- package/dist/plugins/regions.js +362 -190
- package/dist/plugins/regions.min.js +1 -0
- package/dist/plugins/spectrogram.d.ts +69 -0
- package/dist/plugins/spectrogram.js +340 -0
- package/dist/plugins/spectrogram.min.js +1 -0
- package/dist/plugins/timeline.d.ts +26 -9
- package/dist/plugins/timeline.js +65 -22
- package/dist/plugins/timeline.min.js +1 -0
- package/dist/renderer.d.ts +29 -13
- package/dist/renderer.js +280 -161
- package/dist/timer.d.ts +1 -1
- package/dist/wavesurfer.d.ts +151 -0
- package/dist/wavesurfer.js +241 -0
- package/dist/wavesurfer.min.js +1 -1
- package/package.json +54 -27
- package/dist/index.d.ts +0 -117
- package/dist/index.js +0 -227
- package/dist/player-webaudio.d.ts +0 -8
- package/dist/player-webaudio.js +0 -32
- package/dist/react/useWavesurfer.d.ts +0 -5
- package/dist/react/useWavesurfer.js +0 -20
- package/dist/wavesurfer.Regions.min.js +0 -1
- package/dist/wavesurfer.Timeline.min.js +0 -1
package/dist/index.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import Fetcher from './fetcher.js';
|
|
11
|
-
import Decoder from './decoder.js';
|
|
12
|
-
import Renderer from './renderer.js';
|
|
13
|
-
import Player from './player.js';
|
|
14
|
-
import EventEmitter from './event-emitter.js';
|
|
15
|
-
import Timer from './timer.js';
|
|
16
|
-
const defaultOptions = {
|
|
17
|
-
height: 128,
|
|
18
|
-
waveColor: '#999',
|
|
19
|
-
progressColor: '#555',
|
|
20
|
-
minPxPerSec: 0,
|
|
21
|
-
fillParent: true,
|
|
22
|
-
interactive: true,
|
|
23
|
-
};
|
|
24
|
-
export class WaveSurfer extends EventEmitter {
|
|
25
|
-
/** Create a new WaveSurfer instance */
|
|
26
|
-
static create(options) {
|
|
27
|
-
return new WaveSurfer(options);
|
|
28
|
-
}
|
|
29
|
-
/** Create a new WaveSurfer instance */
|
|
30
|
-
constructor(options) {
|
|
31
|
-
var _a;
|
|
32
|
-
super();
|
|
33
|
-
this.plugins = [];
|
|
34
|
-
this.subscriptions = [];
|
|
35
|
-
this.decodedData = null;
|
|
36
|
-
this.options = Object.assign({}, defaultOptions, options);
|
|
37
|
-
this.fetcher = new Fetcher();
|
|
38
|
-
this.decoder = new Decoder();
|
|
39
|
-
this.timer = new Timer();
|
|
40
|
-
this.player = new Player({
|
|
41
|
-
media: this.options.media,
|
|
42
|
-
autoplay: this.options.autoplay,
|
|
43
|
-
});
|
|
44
|
-
this.renderer = new Renderer({
|
|
45
|
-
container: this.options.container,
|
|
46
|
-
height: this.options.height,
|
|
47
|
-
waveColor: this.options.waveColor,
|
|
48
|
-
progressColor: this.options.progressColor,
|
|
49
|
-
cursorColor: this.options.cursorColor,
|
|
50
|
-
minPxPerSec: this.options.minPxPerSec,
|
|
51
|
-
fillParent: this.options.fillParent,
|
|
52
|
-
barWidth: this.options.barWidth,
|
|
53
|
-
barGap: this.options.barGap,
|
|
54
|
-
barRadius: this.options.barRadius,
|
|
55
|
-
});
|
|
56
|
-
this.initPlayerEvents();
|
|
57
|
-
this.initRendererEvents();
|
|
58
|
-
this.initTimerEvents();
|
|
59
|
-
this.initReadyEvent();
|
|
60
|
-
const url = this.options.url || ((_a = this.options.media) === null || _a === void 0 ? void 0 : _a.src);
|
|
61
|
-
if (url) {
|
|
62
|
-
this.load(url, this.options.peaks, this.options.duration);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
initPlayerEvents() {
|
|
66
|
-
this.subscriptions.push(this.player.on('timeupdate', () => {
|
|
67
|
-
const currentTime = this.getCurrentTime();
|
|
68
|
-
this.renderer.renderProgress(currentTime / this.getDuration(), this.isPlaying());
|
|
69
|
-
this.emit('timeupdate', { currentTime });
|
|
70
|
-
}), this.player.on('play', () => {
|
|
71
|
-
this.emit('play');
|
|
72
|
-
this.timer.start();
|
|
73
|
-
}), this.player.on('pause', () => {
|
|
74
|
-
this.emit('pause');
|
|
75
|
-
this.timer.stop();
|
|
76
|
-
}), this.player.on('canplay', () => {
|
|
77
|
-
this.emit('canplay', { duration: this.getDuration() });
|
|
78
|
-
}), this.player.on('seeking', () => {
|
|
79
|
-
this.emit('seeking', { currentTime: this.getCurrentTime() });
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
initRendererEvents() {
|
|
83
|
-
// Seek on click
|
|
84
|
-
this.subscriptions.push(this.renderer.on('click', ({ relativeX }) => {
|
|
85
|
-
if (this.options.interactive) {
|
|
86
|
-
const time = this.getDuration() * relativeX;
|
|
87
|
-
this.seekTo(time);
|
|
88
|
-
this.emit('seekClick', { currentTime: this.getCurrentTime() });
|
|
89
|
-
}
|
|
90
|
-
}));
|
|
91
|
-
}
|
|
92
|
-
initTimerEvents() {
|
|
93
|
-
// The timer fires every 16ms for a smooth progress animation
|
|
94
|
-
this.subscriptions.push(this.timer.on('tick', () => {
|
|
95
|
-
const currentTime = this.getCurrentTime();
|
|
96
|
-
this.renderer.renderProgress(currentTime / this.getDuration(), true);
|
|
97
|
-
this.emit('timeupdate', { currentTime });
|
|
98
|
-
}));
|
|
99
|
-
}
|
|
100
|
-
initReadyEvent() {
|
|
101
|
-
let isDecoded = false;
|
|
102
|
-
let isPlayable = false;
|
|
103
|
-
const emitReady = () => {
|
|
104
|
-
if (isDecoded && isPlayable) {
|
|
105
|
-
this.emit('ready', { duration: this.getDuration() });
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
this.subscriptions.push(this.on('decode', () => {
|
|
109
|
-
isDecoded = true;
|
|
110
|
-
emitReady();
|
|
111
|
-
}), this.on('canplay', () => {
|
|
112
|
-
isPlayable = true;
|
|
113
|
-
emitReady();
|
|
114
|
-
}), this.player.on('waiting', () => {
|
|
115
|
-
isPlayable = false;
|
|
116
|
-
isDecoded = false;
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
/** Load an audio file by URL, with optional pre-decoded audio data */
|
|
120
|
-
load(url, channelData, duration) {
|
|
121
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
this.player.loadUrl(url);
|
|
123
|
-
// Fetch and decode the audio of no pre-computed audio data is provided
|
|
124
|
-
if (channelData == null) {
|
|
125
|
-
const audio = yield this.fetcher.load(url);
|
|
126
|
-
const data = yield this.decoder.decode(audio);
|
|
127
|
-
this.decodedData = data;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
if (!duration) {
|
|
131
|
-
duration =
|
|
132
|
-
(yield new Promise((resolve) => {
|
|
133
|
-
this.player.on('canplay', () => resolve(this.getDuration()), { once: true });
|
|
134
|
-
})) || 0;
|
|
135
|
-
}
|
|
136
|
-
this.decodedData = {
|
|
137
|
-
duration,
|
|
138
|
-
numberOfChannels: channelData.length,
|
|
139
|
-
sampleRate: channelData[0].length / duration,
|
|
140
|
-
getChannelData: (i) => channelData[i],
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
this.renderer.render(this.decodedData);
|
|
144
|
-
this.emit('decode', { duration: this.decodedData.duration });
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
/** Zoom in or out */
|
|
148
|
-
zoom(minPxPerSec) {
|
|
149
|
-
if (!this.decodedData) {
|
|
150
|
-
throw new Error('No audio loaded');
|
|
151
|
-
}
|
|
152
|
-
this.renderer.zoom(this.decodedData, minPxPerSec);
|
|
153
|
-
}
|
|
154
|
-
/** Start playing the audio */
|
|
155
|
-
play() {
|
|
156
|
-
this.player.play();
|
|
157
|
-
}
|
|
158
|
-
/** Pause the audio */
|
|
159
|
-
pause() {
|
|
160
|
-
this.player.pause();
|
|
161
|
-
}
|
|
162
|
-
/** Skip to a time position in seconds */
|
|
163
|
-
seekTo(time) {
|
|
164
|
-
this.player.seekTo(time);
|
|
165
|
-
}
|
|
166
|
-
/** Check if the audio is playing */
|
|
167
|
-
isPlaying() {
|
|
168
|
-
return this.player.isPlaying();
|
|
169
|
-
}
|
|
170
|
-
/** Get the duration of the audio in seconds */
|
|
171
|
-
getDuration() {
|
|
172
|
-
var _a;
|
|
173
|
-
return this.player.getDuration() || ((_a = this.decodedData) === null || _a === void 0 ? void 0 : _a.duration) || 0;
|
|
174
|
-
}
|
|
175
|
-
/** Get the current audio position in seconds */
|
|
176
|
-
getCurrentTime() {
|
|
177
|
-
return this.player.getCurrentTime();
|
|
178
|
-
}
|
|
179
|
-
/** Get the audio volume */
|
|
180
|
-
getVolume() {
|
|
181
|
-
return this.player.getVolume();
|
|
182
|
-
}
|
|
183
|
-
/** Set the audio volume */
|
|
184
|
-
setVolume(volume) {
|
|
185
|
-
this.player.setVolume(volume);
|
|
186
|
-
}
|
|
187
|
-
/** Get the audio muted state */
|
|
188
|
-
getMuted() {
|
|
189
|
-
return this.player.getMuted();
|
|
190
|
-
}
|
|
191
|
-
/** Mute or unmute the audio */
|
|
192
|
-
setMuted(muted) {
|
|
193
|
-
this.player.setMuted(muted);
|
|
194
|
-
}
|
|
195
|
-
/** Get playback rate */
|
|
196
|
-
getPlaybackRate() {
|
|
197
|
-
return this.player.getPlaybackRate();
|
|
198
|
-
}
|
|
199
|
-
/** Set playback rate, with an optional parameter to NOT preserve the pitch if false */
|
|
200
|
-
setPlaybackRate(rate, preservePitch) {
|
|
201
|
-
this.player.setPlaybackRate(rate, preservePitch);
|
|
202
|
-
}
|
|
203
|
-
/** Register and initialize a plugin */
|
|
204
|
-
registerPlugin(CustomPlugin, options) {
|
|
205
|
-
const plugin = new CustomPlugin({
|
|
206
|
-
wavesurfer: this,
|
|
207
|
-
container: this.renderer.getContainer(),
|
|
208
|
-
}, options);
|
|
209
|
-
this.plugins.push(plugin);
|
|
210
|
-
return plugin;
|
|
211
|
-
}
|
|
212
|
-
/** Get the decoded audio data */
|
|
213
|
-
getDecodedData() {
|
|
214
|
-
return this.decodedData;
|
|
215
|
-
}
|
|
216
|
-
/** Unmount wavesurfer */
|
|
217
|
-
destroy() {
|
|
218
|
-
this.emit('destroy');
|
|
219
|
-
this.subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
220
|
-
this.plugins.forEach((plugin) => plugin.destroy());
|
|
221
|
-
this.timer.destroy();
|
|
222
|
-
this.player.destroy();
|
|
223
|
-
this.decoder.destroy();
|
|
224
|
-
this.renderer.destroy();
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
export default WaveSurfer;
|
package/dist/player-webaudio.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import Player from './player.js';
|
|
2
|
-
class WebAudioPlayer extends Player {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(...arguments);
|
|
5
|
-
this.audioCtx = null;
|
|
6
|
-
this.sourceNode = null;
|
|
7
|
-
}
|
|
8
|
-
destroy() {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
(_a = this.sourceNode) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
11
|
-
this.sourceNode = null;
|
|
12
|
-
(_b = this.audioCtx) === null || _b === void 0 ? void 0 : _b.close();
|
|
13
|
-
this.audioCtx = null;
|
|
14
|
-
super.destroy();
|
|
15
|
-
}
|
|
16
|
-
loadUrl(url) {
|
|
17
|
-
super.loadUrl(url);
|
|
18
|
-
if (!this.audioCtx) {
|
|
19
|
-
this.audioCtx = new AudioContext({
|
|
20
|
-
latencyHint: 'playback',
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
if (this.sourceNode) {
|
|
24
|
-
this.sourceNode.disconnect();
|
|
25
|
-
}
|
|
26
|
-
if (this.media) {
|
|
27
|
-
this.sourceNode = this.audioCtx.createMediaElementSource(this.media);
|
|
28
|
-
this.sourceNode.connect(this.audioCtx.destination);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export default WebAudioPlayer;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import WaveSurfer from '../index.js';
|
|
3
|
-
const { useEffect, useState } = React;
|
|
4
|
-
// A React hook to use WaveSurfer
|
|
5
|
-
export const useWavesurfer = (containerRef, options) => {
|
|
6
|
-
const [wavesurfer, setWavesurfer] = useState(null);
|
|
7
|
-
// Initialize wavesurfer when the container mounts
|
|
8
|
-
// or any of the props change
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (!containerRef.current)
|
|
11
|
-
return;
|
|
12
|
-
const ws = WaveSurfer.create(Object.assign(Object.assign({}, options), { container: containerRef.current }));
|
|
13
|
-
setWavesurfer(ws);
|
|
14
|
-
return () => {
|
|
15
|
-
ws.destroy();
|
|
16
|
-
};
|
|
17
|
-
}, [options, containerRef]);
|
|
18
|
-
return wavesurfer;
|
|
19
|
-
};
|
|
20
|
-
export default useWavesurfer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Regions=t():e.Regions=t()}(WaveSurfer,(()=>(()=>{"use strict";var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>a});const i=class{constructor(){this.eventTarget=new EventTarget}emit(e,t){const i=new CustomEvent(String(e),{detail:t});this.eventTarget.dispatchEvent(i)}on(e,t,i){const n=e=>{e instanceof CustomEvent&&t(e.detail)},s=String(e);return this.eventTarget.addEventListener(s,n,{once:i}),()=>this.eventTarget.removeEventListener(s,n)}once(e,t){return this.on(e,t,!0)}},n=class extends i{constructor(e,t){super(),this.subscriptions=[],this.wavesurfer=e.wavesurfer,this.container=e.container,this.options=t}destroy(){this.subscriptions.forEach((e=>e()))}},s={dragSelection:!0,draggable:!0,resizable:!0},o=(e,t)=>{for(const i in t)e.style[i]=t[i]||""},r=(e,t)=>{const i=document.createElement(e);return o(i,t),i},a=class extends n{constructor(e,t){super(e,t),this.dragStart=NaN,this.regions=[],this.createdRegion=null,this.modifiedRegion=null,this.isResizingLeft=!1,this.isMoving=!1,this.handleMouseDown=e=>{(this.options.draggable||this.options.resizable||this.options.dragSelection)&&(this.dragStart=e.clientX-this.container.getBoundingClientRect().left)},this.handleMouseMove=e=>{const t=e.clientX-this.container.getBoundingClientRect().left;if(this.modifiedRegion&&this.isMoving)return this.moveRegion(this.modifiedRegion,t-this.dragStart),void(this.dragStart=t);if(this.modifiedRegion)this.updateRegion(this.modifiedRegion,this.isResizingLeft?t:void 0,this.isResizingLeft?void 0:t);else if(!isNaN(this.dragStart)){const t=e.clientX-this.wrapper.getBoundingClientRect().left;t-this.dragStart>=10&&(this.createdRegion?this.updateRegion(this.createdRegion,this.dragStart,t):(this.container.style.pointerEvents="none",this.createdRegion=this.createRegion(this.dragStart,t)))}},this.handleMouseUp=()=>{this.createdRegion&&(this.addRegion(this.createdRegion),this.createdRegion=null),this.modifiedRegion=null,this.isMoving=!1,this.dragStart=NaN,this.container.style.pointerEvents=""},this.options=Object.assign(Object.assign({},s),t),this.wrapper=this.initWrapper();const i=this.wavesurfer.once("decode",(()=>{this.container.appendChild(this.wrapper)}));this.subscriptions.push(i),this.container.addEventListener("mousedown",this.handleMouseDown),document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp)}destroy(){this.container.removeEventListener("mousedown",this.handleMouseDown),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp,!0),this.wrapper.remove(),super.destroy()}initWrapper(){return r("div",{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",zIndex:"3",pointerEvents:"none"})}createRegionElement(e,t,i=""){const n=e===t,s=r("div",{position:"absolute",left:`${e}px`,width:t-e+"px",height:"100%",backgroundColor:n?"":"rgba(0, 0, 0, 0.1)",borderRadius:"2px",boxSizing:"border-box",borderLeft:"2px solid rgba(0, 0, 0, 0.5)",borderRight:n?"":"2px solid rgba(0, 0, 0, 0.5)",transition:"background-color 0.2s ease",cursor:this.options.draggable?"move":"",pointerEvents:"all",padding:"0.2em"});s.textContent=i;const a=r("div",{position:"absolute",left:"0",width:"6px",height:"100%",cursor:this.options.resizable?"ew-resize":"",pointerEvents:"all"});s.appendChild(a);const d=a.cloneNode();return o(d,{left:"",right:"0",borderLeft:""}),s.appendChild(d),a.addEventListener("mousedown",(e=>{this.options.resizable&&(e.stopPropagation(),this.modifiedRegion=this.regions.find((e=>e.element===s))||null,this.isResizingLeft=!0,this.isMoving=!1)})),d.addEventListener("mousedown",(e=>{this.options.resizable&&(e.stopPropagation(),this.modifiedRegion=this.regions.find((e=>e.element===s))||null,this.isResizingLeft=!1,this.isMoving=!1)})),s.addEventListener("mousedown",(()=>{this.options.draggable&&(this.modifiedRegion=this.regions.find((e=>e.element===s))||null,this.isMoving=!0)})),s.addEventListener("click",(()=>{const e=this.regions.find((e=>e.element===s));e&&this.emit("region-clicked",{region:e})})),this.wrapper.appendChild(s),s}createRegion(e,t,i=""){const n=this.wavesurfer.getDuration(),s=this.wrapper.clientWidth;return e=Math.max(0,Math.min(e,s-1)),t=Math.max(0,Math.min(t,s-1)),{element:this.createRegionElement(e,t,i),start:e,end:t,startTime:e/s*n,endTime:t/s*n,title:i}}addRegion(e){this.regions.push(e),this.emit("region-created",{region:e})}updateRegion(e,t,i){const n=this.wrapper.clientWidth;null!=t&&(t=Math.max(0,Math.min(t,n)),e.start=t,e.element.style.left=`${e.start}px`,e.startTime=t/this.wrapper.clientWidth*this.wavesurfer.getDuration()),null!=i&&(i=Math.max(0,Math.min(i,n)),e.end=i,e.element.style.width=e.end-e.start+"px",e.endTime=i/this.wrapper.clientWidth*this.wavesurfer.getDuration()),this.emit("region-updated",{region:e})}moveRegion(e,t){this.updateRegion(e,e.start+t,e.end+t)}add(e,t,i=""){const n=this.wavesurfer.getDuration(),s=this.wrapper.clientWidth,o=e/n*s,r=t/n*s,a=this.createRegion(o,r,i);return this.addRegion(a),a}setRegionColor(e,t){e.element.style[e.startTime===e.endTime?"borderColor":"backgroundColor"]=t}};return t.default})()));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Timeline=t():e.Timeline=t()}(WaveSurfer,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>o});const n=class{constructor(){this.eventTarget=new EventTarget}emit(e,t){const n=new CustomEvent(String(e),{detail:t});this.eventTarget.dispatchEvent(n)}on(e,t,n){const i=e=>{e instanceof CustomEvent&&t(e.detail)},r=String(e);return this.eventTarget.addEventListener(r,i,{once:n}),()=>this.eventTarget.removeEventListener(r,i)}once(e,t){return this.on(e,t,!0)}},i=class extends n{constructor(e,t){super(),this.subscriptions=[],this.wavesurfer=e.wavesurfer,this.container=e.container,this.options=t}destroy(){this.subscriptions.forEach((e=>e()))}},r={height:20},o=class extends i{constructor(e,t){super(e,t),this.options=Object.assign({},r,t),this.wrapper=this.initWrapper(),this.container.appendChild(this.wrapper),this.subscriptions.push(this.wavesurfer.on("decode",(({duration:e})=>{this.initTimeline(e)})))}destroy(){this.wrapper.remove(),super.destroy()}initWrapper(){return document.createElement("div")}formatTime(e){return e/60>1?`${Math.round(e/60)}:${(e=Math.round(e%60))<10?"0":""}${e}`:""+Math.round(1e3*e)/1e3}defaultTimeInterval(e){return e>=25?1:5*e>=25?5:15*e>=25?15:60*Math.ceil(.5/e)}defaultPrimaryLabelInterval(e){return e>=25?10:5*e>=25?6:4}defaultSecondaryLabelInterval(e){return e>=25?5:2}initTimeline(e){var t,n,i;const r=Math.round(this.wrapper.scrollWidth*devicePixelRatio)/e,o=null!==(t=this.options.timeInterval)&&void 0!==t?t:this.defaultTimeInterval(r),s=null!==(n=this.options.primaryLabelInterval)&&void 0!==n?n:this.defaultPrimaryLabelInterval(r),a=null!==(i=this.options.secondaryLabelInterval)&&void 0!==i?i:this.defaultSecondaryLabelInterval(r),l=document.createElement("div");l.setAttribute("style",`\n height: ${this.options.height}px;\n overflow: hidden;\n display: flex;\n justify-content: space-between;\n align-items: flex-end;\n font-size: ${this.options.height/2}px;\n `);const d=document.createElement("div");d.setAttribute("style","\n width: 1px;\n height: 50%;\n display: flex;\n flex-direction: column;\n justify-content: flex-end;\n overflow: visible;\n border-left: 1px solid currentColor;\n opacity: 0.25;\n ");for(let t=0;t<e;t+=o){const e=d.cloneNode(),n=t%s==0;(n||t%a==0)&&(e.style.height="100%",e.style.textIndent="3px",e.textContent=this.formatTime(t),n&&(e.style.opacity="1")),l.appendChild(e)}this.wrapper.appendChild(l),this.emit("ready")}};return t.default})()));
|