wavesurfer.js 7.0.0-beta.12 → 7.0.0-beta.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/dist/base-plugin.d.ts +5 -2
- package/dist/base-plugin.js +1 -0
- package/dist/decoder.js +17 -6
- package/dist/draggable.js +11 -6
- package/dist/fetcher.js +13 -2
- package/dist/plugins/envelope.d.ts +12 -4
- package/dist/plugins/envelope.js +29 -9
- package/dist/plugins/envelope.min.cjs +1 -1
- package/dist/plugins/hover.d.ts +35 -0
- package/dist/plugins/hover.js +101 -0
- package/dist/plugins/hover.min.cjs +1 -0
- package/dist/plugins/minimap.d.ts +2 -2
- package/dist/plugins/minimap.js +8 -13
- package/dist/plugins/minimap.min.cjs +1 -1
- package/dist/plugins/record.d.ts +2 -2
- package/dist/plugins/record.js +48 -32
- package/dist/plugins/record.min.cjs +1 -1
- package/dist/plugins/regions.d.ts +24 -3
- package/dist/plugins/regions.js +40 -34
- package/dist/plugins/regions.min.cjs +1 -1
- package/dist/plugins/spectrogram.d.ts +2 -2
- package/dist/plugins/spectrogram.js +1 -0
- package/dist/plugins/spectrogram.min.cjs +1 -1
- package/dist/plugins/timeline.d.ts +2 -2
- package/dist/plugins/timeline.js +8 -5
- package/dist/plugins/timeline.min.cjs +1 -1
- package/dist/renderer.js +3 -2
- package/dist/wavesurfer.d.ts +3 -3
- package/dist/wavesurfer.js +62 -41
- package/dist/wavesurfer.min.cjs +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -33,7 +33,12 @@ Alternatively, import it from a CDN as a ES6 module:
|
|
|
33
33
|
<script type="module">
|
|
34
34
|
import WaveSurfer from 'https://unpkg.com/wavesurfer.js@beta'
|
|
35
35
|
|
|
36
|
-
const wavesurfer = WaveSurfer.create({
|
|
36
|
+
const wavesurfer = WaveSurfer.create({
|
|
37
|
+
container: '#waveform',
|
|
38
|
+
waveColor: '#4F4A85',
|
|
39
|
+
progressColor: '#383351',
|
|
40
|
+
url: '/audio.mp3',
|
|
41
|
+
})
|
|
37
42
|
</script>
|
|
38
43
|
```
|
|
39
44
|
|
|
@@ -73,6 +78,7 @@ The "official" plugins have been completely rewritten and enhanced:
|
|
|
73
78
|
* [Envelope](https://wavesurfer-js.org/examples/#envelope.js) – a graphical interface to add fade-in and -out effects and control volume
|
|
74
79
|
* [Record](https://wavesurfer-js.org/examples/#record.js) – records audio from the microphone and renders a waveform
|
|
75
80
|
* [Spectrogram](https://wavesurfer-js.org/examples/#spectrogram.js) – visualization of an audio frequency spectrum (written by @akreal)
|
|
81
|
+
* [Hover](https://wavesurfer-js.org/examples/#hover.js) – shows a vertical line and timestmap on waveform hover
|
|
76
82
|
|
|
77
83
|
## CSS styling
|
|
78
84
|
|
|
@@ -99,8 +105,8 @@ Most options, events, and methods are similar to those in previous versions.
|
|
|
99
105
|
### Notable differences
|
|
100
106
|
* The `backend` option is removed – [HTML5 audio (or video) is the only playback mechanism](https://github.com/katspaugh/wavesurfer.js/discussions/2762#discussioncomment-5669347). However, you can still connect wavesurfer to Web Audio via `MediaElementSourceNode`. See this [example](https://wavesurfer-js.org/examples/#webaudio.js).
|
|
101
107
|
* The Markers plugin is removed – use the Regions plugin with just a `startTime`.
|
|
102
|
-
* No Microphone
|
|
103
|
-
*
|
|
108
|
+
* No Microphone plugin – superseded by the new Record plugin with more features.
|
|
109
|
+
* The Cursor plugin is replaced by the Hover plugin
|
|
104
110
|
|
|
105
111
|
### Removed options
|
|
106
112
|
* `backend`, `audioContext`, `closeAudioContext', 'audioScriptProcessor` – there's no Web Audio backend, so no AudioContext
|
package/dist/base-plugin.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import EventEmitter, { type GeneralEventTypes } from './event-emitter.js';
|
|
2
2
|
import type WaveSurfer from './wavesurfer.js';
|
|
3
|
-
export type
|
|
4
|
-
|
|
3
|
+
export type BasePluginEvents = {
|
|
4
|
+
destroy: [];
|
|
5
|
+
} & GeneralEventTypes;
|
|
6
|
+
export type GenericPlugin = BasePlugin<BasePluginEvents, unknown>;
|
|
7
|
+
export declare class BasePlugin<EventTypes extends BasePluginEvents, Options> extends EventEmitter<EventTypes> {
|
|
5
8
|
protected wavesurfer?: WaveSurfer;
|
|
6
9
|
protected subscriptions: (() => void)[];
|
|
7
10
|
protected options: Options;
|
package/dist/base-plugin.js
CHANGED
package/dist/decoder.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
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
|
+
};
|
|
1
10
|
/** Decode an array buffer into an audio buffer */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
function decode(audioData, sampleRate) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const audioCtx = new AudioContext({ sampleRate });
|
|
14
|
+
const decode = audioCtx.decodeAudioData(audioData);
|
|
15
|
+
decode.finally(() => audioCtx.close());
|
|
16
|
+
return decode;
|
|
17
|
+
});
|
|
7
18
|
}
|
|
8
19
|
/** Normalize peaks to -1..1 */
|
|
9
20
|
function normalize(channelData) {
|
|
@@ -36,7 +47,7 @@ function createBuffer(channelData, duration) {
|
|
|
36
47
|
length: channelData[0].length,
|
|
37
48
|
sampleRate: channelData[0].length / duration,
|
|
38
49
|
numberOfChannels: channelData.length,
|
|
39
|
-
getChannelData: (i) => channelData
|
|
50
|
+
getChannelData: (i) => channelData === null || channelData === void 0 ? void 0 : channelData[i],
|
|
40
51
|
copyFromChannel: AudioBuffer.prototype.copyFromChannel,
|
|
41
52
|
copyToChannel: AudioBuffer.prototype.copyToChannel,
|
|
42
53
|
};
|
package/dist/draggable.js
CHANGED
|
@@ -19,7 +19,7 @@ export function makeDraggable(element, onDrag, onStart, onEnd, threshold = 5) {
|
|
|
19
19
|
const { left, top } = element.getBoundingClientRect();
|
|
20
20
|
if (!isDragging) {
|
|
21
21
|
isDragging = true;
|
|
22
|
-
onStart
|
|
22
|
+
onStart === null || onStart === void 0 ? void 0 : onStart(startX - left, startY - top);
|
|
23
23
|
}
|
|
24
24
|
onDrag(x - startX, y - startY, x - left, y - top);
|
|
25
25
|
startX = x;
|
|
@@ -34,11 +34,20 @@ export function makeDraggable(element, onDrag, onStart, onEnd, threshold = 5) {
|
|
|
34
34
|
};
|
|
35
35
|
const up = () => {
|
|
36
36
|
if (isDragging) {
|
|
37
|
-
onEnd
|
|
37
|
+
onEnd === null || onEnd === void 0 ? void 0 : onEnd();
|
|
38
38
|
}
|
|
39
39
|
unsub();
|
|
40
40
|
};
|
|
41
|
+
// Prevent scrolling on touch devices
|
|
42
|
+
const touchMove = (e) => e.preventDefault();
|
|
43
|
+
const touchOptions = { passive: false };
|
|
44
|
+
document.addEventListener('touchmove', touchMove, touchOptions);
|
|
45
|
+
document.addEventListener('pointermove', move);
|
|
46
|
+
document.addEventListener('pointerup', up);
|
|
47
|
+
document.addEventListener('pointerleave', up);
|
|
48
|
+
document.addEventListener('click', click, true);
|
|
41
49
|
unsub = () => {
|
|
50
|
+
document.removeEventListener('touchmove', touchMove, touchOptions);
|
|
42
51
|
document.removeEventListener('pointermove', move);
|
|
43
52
|
document.removeEventListener('pointerup', up);
|
|
44
53
|
document.removeEventListener('pointerleave', up);
|
|
@@ -46,10 +55,6 @@ export function makeDraggable(element, onDrag, onStart, onEnd, threshold = 5) {
|
|
|
46
55
|
document.removeEventListener('click', click, true);
|
|
47
56
|
}, 10);
|
|
48
57
|
};
|
|
49
|
-
document.addEventListener('pointermove', move);
|
|
50
|
-
document.addEventListener('pointerup', up);
|
|
51
|
-
document.addEventListener('pointerleave', up);
|
|
52
|
-
document.addEventListener('click', click, true);
|
|
53
58
|
};
|
|
54
59
|
element.addEventListener('pointerdown', down);
|
|
55
60
|
return () => {
|
package/dist/fetcher.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
return
|
|
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
|
+
function fetchBlob(url, init) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
return fetch(url, init).then((response) => response.blob());
|
|
13
|
+
});
|
|
3
14
|
}
|
|
4
15
|
const Fetcher = {
|
|
5
16
|
fetchBlob,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Envelope is a visual UI for controlling the audio volume and add fade-in and fade-out effects.
|
|
3
3
|
*/
|
|
4
|
-
import BasePlugin from '../base-plugin.js';
|
|
4
|
+
import BasePlugin, { type BasePluginEvents } from '../base-plugin.js';
|
|
5
5
|
export type EnvelopePluginOptions = {
|
|
6
6
|
fadeInStart?: number;
|
|
7
7
|
fadeInEnd?: number;
|
|
@@ -26,7 +26,7 @@ declare const defaultOptions: {
|
|
|
26
26
|
dragPointStroke: string;
|
|
27
27
|
};
|
|
28
28
|
type Options = EnvelopePluginOptions & typeof defaultOptions;
|
|
29
|
-
export type EnvelopePluginEvents = {
|
|
29
|
+
export type EnvelopePluginEvents = BasePluginEvents & {
|
|
30
30
|
'fade-in-change': [time: number];
|
|
31
31
|
'fade-out-change': [time: number];
|
|
32
32
|
'volume-change': [volume: number];
|
|
@@ -60,11 +60,19 @@ export declare class EnvelopePlugin extends BasePlugin<EnvelopePluginEvents, Env
|
|
|
60
60
|
* @param moveFadeInEnd Whether to move the drag point to the new time (default: false)
|
|
61
61
|
*/
|
|
62
62
|
setStartTime(time: number, moveFadeInEnd?: boolean): void;
|
|
63
|
-
/** Set the fade-
|
|
64
|
-
* @param time The time (in seconds) to set the fade-
|
|
63
|
+
/** Set the fade-out end time.
|
|
64
|
+
* @param time The time (in seconds) to set the fade-out end time to
|
|
65
65
|
* @param moveFadeOutStart Whether to move the drag point to the new time (default: false)
|
|
66
66
|
*/
|
|
67
67
|
setEndTime(time: number, moveFadeOutStart?: boolean): void;
|
|
68
|
+
/** Set the fade-in end time.
|
|
69
|
+
* @param time The time (in seconds) to set the fade-in end time to
|
|
70
|
+
*/
|
|
71
|
+
setFadeInEnd(time: number): void;
|
|
72
|
+
/** Set the fade-out start time.
|
|
73
|
+
* @param time The time (in seconds) to set the fade-out start time to
|
|
74
|
+
*/
|
|
75
|
+
setFadeOutStart(time: number): void;
|
|
68
76
|
/** Set the volume of the audio */
|
|
69
77
|
setVolume(volume: number): void;
|
|
70
78
|
}
|
package/dist/plugins/envelope.js
CHANGED
|
@@ -121,6 +121,7 @@ class Polyline extends EventEmitter {
|
|
|
121
121
|
}
|
|
122
122
|
export class EnvelopePlugin extends BasePlugin {
|
|
123
123
|
constructor(options) {
|
|
124
|
+
var _a;
|
|
124
125
|
super(options);
|
|
125
126
|
this.polyline = null;
|
|
126
127
|
this.audioContext = null;
|
|
@@ -134,13 +135,14 @@ export class EnvelopePlugin extends BasePlugin {
|
|
|
134
135
|
this.options.lineColor = this.options.lineColor || defaultOptions.lineColor;
|
|
135
136
|
this.options.dragPointFill = this.options.dragPointFill || defaultOptions.dragPointFill;
|
|
136
137
|
this.options.dragPointStroke = this.options.dragPointStroke || defaultOptions.dragPointStroke;
|
|
137
|
-
this.volume = this.options.volume
|
|
138
|
+
this.volume = (_a = this.options.volume) !== null && _a !== void 0 ? _a : 1;
|
|
138
139
|
}
|
|
139
140
|
static create(options) {
|
|
140
141
|
return new EnvelopePlugin(options);
|
|
141
142
|
}
|
|
142
143
|
destroy() {
|
|
143
|
-
|
|
144
|
+
var _a;
|
|
145
|
+
(_a = this.polyline) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
144
146
|
super.destroy();
|
|
145
147
|
}
|
|
146
148
|
/** Called by wavesurfer, don't call manually */
|
|
@@ -152,7 +154,8 @@ export class EnvelopePlugin extends BasePlugin {
|
|
|
152
154
|
this.initSvg();
|
|
153
155
|
this.initFadeEffects();
|
|
154
156
|
this.subscriptions.push(this.wavesurfer.on('redraw', () => {
|
|
155
|
-
|
|
157
|
+
var _a;
|
|
158
|
+
const duration = (_a = this.wavesurfer) === null || _a === void 0 ? void 0 : _a.getDuration();
|
|
156
159
|
if (!duration)
|
|
157
160
|
return;
|
|
158
161
|
this.options.fadeInStart = this.options.fadeInStart || 0;
|
|
@@ -170,7 +173,8 @@ export class EnvelopePlugin extends BasePlugin {
|
|
|
170
173
|
this.subscriptions.push(this.polyline.on('line-move', (relativeY) => {
|
|
171
174
|
this.setVolume(this.naturalVolume(relativeY));
|
|
172
175
|
}), this.polyline.on('point-move', (index, relativeX) => {
|
|
173
|
-
|
|
176
|
+
var _a;
|
|
177
|
+
const duration = ((_a = this.wavesurfer) === null || _a === void 0 ? void 0 : _a.getDuration()) || 0;
|
|
174
178
|
const newTime = relativeX * duration;
|
|
175
179
|
// Fade-in end point
|
|
176
180
|
if (index === 1) {
|
|
@@ -204,10 +208,11 @@ export class EnvelopePlugin extends BasePlugin {
|
|
|
204
208
|
});
|
|
205
209
|
}
|
|
206
210
|
initWebAudio() {
|
|
207
|
-
|
|
211
|
+
var _a, _b;
|
|
212
|
+
const audio = (_a = this.wavesurfer) === null || _a === void 0 ? void 0 : _a.getMediaElement();
|
|
208
213
|
if (!audio)
|
|
209
214
|
return null;
|
|
210
|
-
this.volume = this.options.volume
|
|
215
|
+
this.volume = (_b = this.options.volume) !== null && _b !== void 0 ? _b : audio.volume;
|
|
211
216
|
// Create an AudioContext
|
|
212
217
|
const audioContext = new window.AudioContext();
|
|
213
218
|
// Create a GainNode for controlling the volume
|
|
@@ -241,9 +246,10 @@ export class EnvelopePlugin extends BasePlugin {
|
|
|
241
246
|
if (!this.audioContext || !this.wavesurfer)
|
|
242
247
|
return;
|
|
243
248
|
const unsub = this.wavesurfer.on('timeupdate', (currentTime) => {
|
|
249
|
+
var _a;
|
|
244
250
|
if (!this.audioContext || !this.gainNode)
|
|
245
251
|
return;
|
|
246
|
-
if (!this.wavesurfer
|
|
252
|
+
if (!((_a = this.wavesurfer) === null || _a === void 0 ? void 0 : _a.isPlaying()))
|
|
247
253
|
return;
|
|
248
254
|
if (this.audioContext.state === 'suspended') {
|
|
249
255
|
this.audioContext.resume();
|
|
@@ -303,8 +309,8 @@ export class EnvelopePlugin extends BasePlugin {
|
|
|
303
309
|
this.options.fadeInStart = time;
|
|
304
310
|
this.renderPolyline();
|
|
305
311
|
}
|
|
306
|
-
/** Set the fade-
|
|
307
|
-
* @param time The time (in seconds) to set the fade-
|
|
312
|
+
/** Set the fade-out end time.
|
|
313
|
+
* @param time The time (in seconds) to set the fade-out end time to
|
|
308
314
|
* @param moveFadeOutStart Whether to move the drag point to the new time (default: false)
|
|
309
315
|
*/
|
|
310
316
|
setEndTime(time, moveFadeOutStart = false) {
|
|
@@ -315,6 +321,20 @@ export class EnvelopePlugin extends BasePlugin {
|
|
|
315
321
|
this.options.fadeOutEnd = time;
|
|
316
322
|
this.renderPolyline();
|
|
317
323
|
}
|
|
324
|
+
/** Set the fade-in end time.
|
|
325
|
+
* @param time The time (in seconds) to set the fade-in end time to
|
|
326
|
+
*/
|
|
327
|
+
setFadeInEnd(time) {
|
|
328
|
+
this.options.fadeInEnd = time;
|
|
329
|
+
this.renderPolyline();
|
|
330
|
+
}
|
|
331
|
+
/** Set the fade-out start time.
|
|
332
|
+
* @param time The time (in seconds) to set the fade-out start time to
|
|
333
|
+
*/
|
|
334
|
+
setFadeOutStart(time) {
|
|
335
|
+
this.options.fadeOutStart = time;
|
|
336
|
+
this.renderPolyline();
|
|
337
|
+
}
|
|
318
338
|
/** Set the volume of the audio */
|
|
319
339
|
setVolume(volume) {
|
|
320
340
|
this.volume = volume;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Envelope=e():t.Envelope=e()}("undefined"!=typeof WaveSurfer?WaveSurfer:this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>a});const i=class{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),n=this.on(t,(()=>{i(),n()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}},n=class extends i{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.subscriptions.forEach((t=>t()))}},s={fadeInStart:0,fadeOutEnd:0,fadeInEnd:0,fadeOutStart:0,lineWidth:4,lineColor:"rgba(0, 0, 255, 0.5)",dragPointSize:10,dragPointFill:"rgba(255, 255, 255, 0.8)",dragPointStroke:"rgba(255, 255, 255, 0.8)"};class o extends i{constructor(t,e){super(),this.top=0,this.padding=t.dragPointSize/2+1;const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width","100%"),i.setAttribute("height","100%"),i.setAttribute("viewBox","0 0 0 0"),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("style","position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none;"),i.setAttribute("part","envelope"),this.svg=i;const n=document.createElementNS("http://www.w3.org/2000/svg","polyline");n.setAttribute("points","0,0 0,0 0,0 0,0"),n.setAttribute("stroke",t.lineColor),n.setAttribute("stroke-width",t.lineWidth),n.setAttribute("fill","none"),n.setAttribute("style","pointer-events: none;"),n.setAttribute("part","polyline"),i.appendChild(n);const s=document.createElementNS("http://www.w3.org/2000/svg","line");s.setAttribute("stroke","transparent"),s.setAttribute("stroke-width",(3*t.lineWidth).toString()),s.setAttribute("style","cursor: ns-resize; pointer-events: all;"),s.setAttribute("part","line"),i.appendChild(s),[0,1].forEach((()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("r",(t.dragPointSize/2).toString()),e.setAttribute("fill",t.dragPointFill),e.setAttribute("stroke",t.dragPointStroke||t.dragPointFill),e.setAttribute("stroke-width","2"),e.setAttribute("style","cursor: ew-resize; pointer-events: all;"),e.setAttribute("part","circle"),i.appendChild(e)})),e.appendChild(i);{const t=t=>{const e=this.top+t,{height:n}=i.viewBox.baseVal;if(e<-.5||e>n)return;const s=Math.min(1,Math.max(0,(n-e)/n));this.emit("line-move",s)},e=(t,e)=>{const s=n.points.getItem(t).x+e,{width:o}=i.viewBox.baseVal;this.emit("point-move",t,s/o)};this.makeDraggable(s,((e,i)=>t(i)));const o=this.svg.querySelectorAll("circle");Array.from(o).forEach(((t,i)=>{this.makeDraggable(t,(t=>e(i+1,t)))}))}}makeDraggable(t,e){!function(t,e,i,n,s=5){let o=()=>{};if(!t)return o;t.addEventListener("pointerdown",(r=>{r.preventDefault(),r.stopPropagation();let a=r.clientX,
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Envelope=e():t.Envelope=e()}("undefined"!=typeof WaveSurfer?WaveSurfer:this,(()=>(()=>{"use strict";var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>a});const i=class{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const i=this.on(t,e),n=this.on(t,(()=>{i(),n()}));return i}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}},n=class extends i{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}},s={fadeInStart:0,fadeOutEnd:0,fadeInEnd:0,fadeOutStart:0,lineWidth:4,lineColor:"rgba(0, 0, 255, 0.5)",dragPointSize:10,dragPointFill:"rgba(255, 255, 255, 0.8)",dragPointStroke:"rgba(255, 255, 255, 0.8)"};class o extends i{constructor(t,e){super(),this.top=0,this.padding=t.dragPointSize/2+1;const i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("width","100%"),i.setAttribute("height","100%"),i.setAttribute("viewBox","0 0 0 0"),i.setAttribute("preserveAspectRatio","none"),i.setAttribute("style","position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none;"),i.setAttribute("part","envelope"),this.svg=i;const n=document.createElementNS("http://www.w3.org/2000/svg","polyline");n.setAttribute("points","0,0 0,0 0,0 0,0"),n.setAttribute("stroke",t.lineColor),n.setAttribute("stroke-width",t.lineWidth),n.setAttribute("fill","none"),n.setAttribute("style","pointer-events: none;"),n.setAttribute("part","polyline"),i.appendChild(n);const s=document.createElementNS("http://www.w3.org/2000/svg","line");s.setAttribute("stroke","transparent"),s.setAttribute("stroke-width",(3*t.lineWidth).toString()),s.setAttribute("style","cursor: ns-resize; pointer-events: all;"),s.setAttribute("part","line"),i.appendChild(s),[0,1].forEach((()=>{const e=document.createElementNS("http://www.w3.org/2000/svg","circle");e.setAttribute("r",(t.dragPointSize/2).toString()),e.setAttribute("fill",t.dragPointFill),e.setAttribute("stroke",t.dragPointStroke||t.dragPointFill),e.setAttribute("stroke-width","2"),e.setAttribute("style","cursor: ew-resize; pointer-events: all;"),e.setAttribute("part","circle"),i.appendChild(e)})),e.appendChild(i);{const t=t=>{const e=this.top+t,{height:n}=i.viewBox.baseVal;if(e<-.5||e>n)return;const s=Math.min(1,Math.max(0,(n-e)/n));this.emit("line-move",s)},e=(t,e)=>{const s=n.points.getItem(t).x+e,{width:o}=i.viewBox.baseVal;this.emit("point-move",t,s/o)};this.makeDraggable(s,((e,i)=>t(i)));const o=this.svg.querySelectorAll("circle");Array.from(o).forEach(((t,i)=>{this.makeDraggable(t,(t=>e(i+1,t)))}))}}makeDraggable(t,e){!function(t,e,i,n,s=5){let o=()=>{};if(!t)return o;t.addEventListener("pointerdown",(r=>{r.preventDefault(),r.stopPropagation();let a=r.clientX,d=r.clientY,u=!1;const l=n=>{n.preventDefault(),n.stopPropagation();const o=n.clientX,r=n.clientY;if(u||Math.abs(o-a)>=s||Math.abs(r-d)>=s){const{left:n,top:s}=t.getBoundingClientRect();u||(u=!0,null==i||i(a-n,d-s)),e(o-a,r-d,o-n,r-s),a=o,d=r}},h=t=>{u&&(t.preventDefault(),t.stopPropagation())},p=()=>{u&&(null==n||n()),o()},c=t=>t.preventDefault(),g={passive:!1};document.addEventListener("touchmove",c,g),document.addEventListener("pointermove",l),document.addEventListener("pointerup",p),document.addEventListener("pointerleave",p),document.addEventListener("click",h,!0),o=()=>{document.removeEventListener("touchmove",c,g),document.removeEventListener("pointermove",l),document.removeEventListener("pointerup",p),document.removeEventListener("pointerleave",p),setTimeout((()=>{document.removeEventListener("click",h,!0)}),10)}}))}(t,e)}update({x1:t,x2:e,x3:i,x4:n,y:s}){const o=this.svg.clientWidth,r=this.svg.clientHeight;this.top=r-s*r;const a=Math.max(this.padding,Math.min(this.top,r-this.padding));this.svg.setAttribute("viewBox",`0 0 ${o} ${r}`);const d=this.svg.querySelector("polyline"),{points:u}=d;u.getItem(0).x=t*o,u.getItem(0).y=r,u.getItem(1).x=e*o,u.getItem(1).y=a,u.getItem(2).x=i*o,u.getItem(2).y=a,u.getItem(3).x=n*o,u.getItem(3).y=r;const l=this.svg.querySelector("line");l.setAttribute("x1",u.getItem(1).x.toString()),l.setAttribute("x2",u.getItem(2).x.toString()),l.setAttribute("y1",a.toString()),l.setAttribute("y2",a.toString());const h=this.svg.querySelectorAll("circle");Array.from(h).forEach(((t,e)=>{const i=u.getItem(e+1);t.setAttribute("cx",i.x.toString()),t.setAttribute("cy",i.y.toString())}))}destroy(){this.svg.remove()}}class r extends n{constructor(t){var e;super(t),this.polyline=null,this.audioContext=null,this.gainNode=null,this.volume=1,this.isFadingIn=!1,this.isFadingOut=!1,this.naturalVolumeExponent=1.5,this.options=Object.assign({},s,t),this.options.lineColor=this.options.lineColor||s.lineColor,this.options.dragPointFill=this.options.dragPointFill||s.dragPointFill,this.options.dragPointStroke=this.options.dragPointStroke||s.dragPointStroke,this.volume=null!==(e=this.options.volume)&&void 0!==e?e:1}static create(t){return new r(t)}destroy(){var t;null===(t=this.polyline)||void 0===t||t.destroy(),super.destroy()}onInit(){if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");this.initWebAudio(),this.initSvg(),this.initFadeEffects(),this.subscriptions.push(this.wavesurfer.on("redraw",(()=>{var t;const e=null===(t=this.wavesurfer)||void 0===t?void 0:t.getDuration();e&&(this.options.fadeInStart=this.options.fadeInStart||0,this.options.fadeOutEnd=this.options.fadeOutEnd||e,this.options.fadeInEnd=this.options.fadeInEnd||this.options.fadeInStart,this.options.fadeOutStart=this.options.fadeOutStart||this.options.fadeOutEnd,this.renderPolyline())})))}initSvg(){if(!this.wavesurfer)return;const t=this.wavesurfer.getWrapper();this.polyline=new o(this.options,t),this.subscriptions.push(this.polyline.on("line-move",(t=>{this.setVolume(this.naturalVolume(t))})),this.polyline.on("point-move",((t,e)=>{var i;const n=e*((null===(i=this.wavesurfer)||void 0===i?void 0:i.getDuration())||0);if(1===t){if(n<this.options.fadeInStart||n>this.options.fadeOutStart)return;this.options.fadeInEnd=n,this.emit("fade-in-change",n)}else if(2===t){if(n>this.options.fadeOutEnd||n<this.options.fadeInEnd)return;this.options.fadeOutStart=n,this.emit("fade-out-change",n)}this.renderPolyline()})))}renderPolyline(){if(!this.polyline||!this.wavesurfer)return;const t=this.wavesurfer.getDuration();t&&this.polyline.update({x1:this.options.fadeInStart/t,x2:this.options.fadeInEnd/t,x3:this.options.fadeOutStart/t,x4:this.options.fadeOutEnd/t,y:this.invertNaturalVolume(this.volume)})}initWebAudio(){var t,e;const i=null===(t=this.wavesurfer)||void 0===t?void 0:t.getMediaElement();if(!i)return null;this.volume=null!==(e=this.options.volume)&&void 0!==e?e:i.volume;const n=new window.AudioContext;this.gainNode=n.createGain(),this.setGainValue(),n.createMediaElementSource(i).connect(this.gainNode),this.gainNode.connect(n.destination),this.audioContext=n}invertNaturalVolume(t){return Math.pow((t-1e-4)/.9999,1/this.naturalVolumeExponent)}naturalVolume(t){return 1e-4+.9999*Math.pow(t,this.naturalVolumeExponent)}setGainValue(){this.gainNode&&(this.gainNode.gain.value=this.volume)}initFadeEffects(){if(!this.audioContext||!this.wavesurfer)return;const t=this.wavesurfer.on("timeupdate",(t=>{var e;if(!this.audioContext||!this.gainNode)return;if(!(null===(e=this.wavesurfer)||void 0===e?void 0:e.isPlaying()))return;if("suspended"===this.audioContext.state&&this.audioContext.resume(),!this.isFadingIn&&t>=this.options.fadeInStart&&t<=this.options.fadeInEnd)return this.isFadingIn=!0,this.gainNode.gain.setValueAtTime(0,this.audioContext.currentTime),void this.gainNode.gain.linearRampToValueAtTime(this.volume,this.audioContext.currentTime+(this.options.fadeInEnd-t));if(!this.isFadingOut&&t>=this.options.fadeOutStart&&t<=this.options.fadeOutEnd)return this.isFadingOut=!0,this.gainNode.gain.setValueAtTime(this.volume,this.audioContext.currentTime),void this.gainNode.gain.linearRampToValueAtTime(0,this.audioContext.currentTime+(this.options.fadeOutEnd-t));let i=!1;this.isFadingIn&&(t<this.options.fadeInStart||t>this.options.fadeInEnd)&&(this.isFadingIn=!1,i=!0),this.isFadingOut&&(t<this.options.fadeOutStart||t>=this.options.fadeOutEnd)&&(this.isFadingOut=!1,i=!0),i&&(this.gainNode.gain.cancelScheduledValues(this.audioContext.currentTime),this.setGainValue())}));this.subscriptions.push(t)}getCurrentVolume(){return this.gainNode?this.gainNode.gain.value:this.volume}setStartTime(t,e=!1){if(e){const e=this.options.fadeInEnd-this.options.fadeInStart;this.options.fadeInEnd=t+e}this.options.fadeInStart=t,this.renderPolyline()}setEndTime(t,e=!1){if(e){const e=this.options.fadeOutEnd-this.options.fadeOutStart;this.options.fadeOutStart=t-e}this.options.fadeOutEnd=t,this.renderPolyline()}setFadeInEnd(t){this.options.fadeInEnd=t,this.renderPolyline()}setFadeOutStart(t){this.options.fadeOutStart=t,this.renderPolyline()}setVolume(t){this.volume=t,this.setGainValue(),this.renderPolyline(),this.emit("volume-change",t)}}const a=r;return e.default})()));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Hover plugin follows the mouse and shows a timestamp
|
|
3
|
+
*/
|
|
4
|
+
import BasePlugin, { type BasePluginEvents } from '../base-plugin.js';
|
|
5
|
+
export type HoverPluginOptions = {
|
|
6
|
+
lineColor?: string;
|
|
7
|
+
lineWidth?: string | number;
|
|
8
|
+
labelColor?: string;
|
|
9
|
+
labelSize?: string | number;
|
|
10
|
+
labelBackground?: string;
|
|
11
|
+
};
|
|
12
|
+
declare const defaultOptions: {
|
|
13
|
+
lineWidth: number;
|
|
14
|
+
labelSize: number;
|
|
15
|
+
};
|
|
16
|
+
export type HoverPluginEvents = BasePluginEvents & {
|
|
17
|
+
hover: [relX: number];
|
|
18
|
+
};
|
|
19
|
+
export declare class HoverPlugin extends BasePlugin<HoverPluginEvents, HoverPluginOptions> {
|
|
20
|
+
protected options: HoverPluginOptions & typeof defaultOptions;
|
|
21
|
+
private wrapper;
|
|
22
|
+
private label;
|
|
23
|
+
private unsubscribe;
|
|
24
|
+
constructor(options?: HoverPluginOptions);
|
|
25
|
+
static create(options?: HoverPluginOptions): HoverPlugin;
|
|
26
|
+
private addUnits;
|
|
27
|
+
/** Called by wavesurfer, don't call manually */
|
|
28
|
+
onInit(): void;
|
|
29
|
+
private formatTime;
|
|
30
|
+
private onPointerMove;
|
|
31
|
+
private onPointerLeave;
|
|
32
|
+
/** Unmount */
|
|
33
|
+
destroy(): void;
|
|
34
|
+
}
|
|
35
|
+
export default HoverPlugin;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Hover plugin follows the mouse and shows a timestamp
|
|
3
|
+
*/
|
|
4
|
+
import BasePlugin from '../base-plugin.js';
|
|
5
|
+
const defaultOptions = {
|
|
6
|
+
lineWidth: 1,
|
|
7
|
+
labelSize: 11,
|
|
8
|
+
};
|
|
9
|
+
export class HoverPlugin extends BasePlugin {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options || {});
|
|
12
|
+
this.unsubscribe = () => undefined;
|
|
13
|
+
this.onPointerMove = (e) => {
|
|
14
|
+
if (!this.wavesurfer)
|
|
15
|
+
return;
|
|
16
|
+
// Position
|
|
17
|
+
const width = this.wavesurfer.getWrapper().clientWidth;
|
|
18
|
+
const { offsetX } = e;
|
|
19
|
+
const relX = Math.min(1, Math.max(0, offsetX / width));
|
|
20
|
+
const posX = Math.min(width - this.options.lineWidth - 1, offsetX);
|
|
21
|
+
this.wrapper.style.transform = `translateX(${posX}px)`;
|
|
22
|
+
this.wrapper.style.opacity = '1';
|
|
23
|
+
// Timestamp
|
|
24
|
+
const duration = this.wavesurfer.getDuration() || 0;
|
|
25
|
+
this.label.textContent = this.formatTime(duration * relX);
|
|
26
|
+
const labelWidth = this.label.offsetWidth;
|
|
27
|
+
this.label.style.transform =
|
|
28
|
+
posX + labelWidth > width ? `translateX(-${labelWidth + this.options.lineWidth}px)` : '';
|
|
29
|
+
// Emit a hover event with the relative X position
|
|
30
|
+
this.emit('hover', relX);
|
|
31
|
+
};
|
|
32
|
+
this.onPointerLeave = () => {
|
|
33
|
+
this.wrapper.style.opacity = '0';
|
|
34
|
+
};
|
|
35
|
+
this.options = Object.assign({}, defaultOptions, options);
|
|
36
|
+
// Create the plugin elements
|
|
37
|
+
this.wrapper = document.createElement('div');
|
|
38
|
+
this.label = document.createElement('span');
|
|
39
|
+
this.wrapper.appendChild(this.label);
|
|
40
|
+
}
|
|
41
|
+
static create(options) {
|
|
42
|
+
return new HoverPlugin(options);
|
|
43
|
+
}
|
|
44
|
+
addUnits(value) {
|
|
45
|
+
const units = typeof value === 'number' ? 'px' : '';
|
|
46
|
+
return `${value}${units}`;
|
|
47
|
+
}
|
|
48
|
+
/** Called by wavesurfer, don't call manually */
|
|
49
|
+
onInit() {
|
|
50
|
+
if (!this.wavesurfer) {
|
|
51
|
+
throw Error('WaveSurfer is not initialized');
|
|
52
|
+
}
|
|
53
|
+
const wsOptions = this.wavesurfer.options;
|
|
54
|
+
const lineColor = this.options.lineColor || wsOptions.cursorColor || wsOptions.progressColor;
|
|
55
|
+
// Vertical line
|
|
56
|
+
this.wrapper.setAttribute('part', 'hover');
|
|
57
|
+
Object.assign(this.wrapper.style, {
|
|
58
|
+
position: 'absolute',
|
|
59
|
+
zIndex: 10,
|
|
60
|
+
left: 0,
|
|
61
|
+
top: 0,
|
|
62
|
+
height: '100%',
|
|
63
|
+
pointerEvents: 'none',
|
|
64
|
+
borderLeft: `${this.addUnits(this.options.lineWidth)} solid ${lineColor}`,
|
|
65
|
+
transition: 'opacity .1s ease-in',
|
|
66
|
+
});
|
|
67
|
+
// Timestamp label
|
|
68
|
+
this.label.setAttribute('part', 'hover-label');
|
|
69
|
+
Object.assign(this.label.style, {
|
|
70
|
+
display: 'block',
|
|
71
|
+
backgroundColor: this.options.labelBackground,
|
|
72
|
+
color: this.options.labelColor,
|
|
73
|
+
fontSize: `${this.addUnits(this.options.labelSize)}`,
|
|
74
|
+
transition: 'transform .1s ease-in',
|
|
75
|
+
padding: '2px 3px',
|
|
76
|
+
});
|
|
77
|
+
// Append the wrapper
|
|
78
|
+
const container = this.wavesurfer.getWrapper();
|
|
79
|
+
container.appendChild(this.wrapper);
|
|
80
|
+
// Attach pointer events
|
|
81
|
+
container.addEventListener('pointermove', this.onPointerMove);
|
|
82
|
+
container.addEventListener('pointerleave', this.onPointerLeave);
|
|
83
|
+
this.unsubscribe = () => {
|
|
84
|
+
container.removeEventListener('pointermove', this.onPointerMove);
|
|
85
|
+
container.removeEventListener('pointerleave', this.onPointerLeave);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
formatTime(seconds) {
|
|
89
|
+
const minutes = Math.floor(seconds / 60);
|
|
90
|
+
const secondsRemainder = Math.round(seconds) % 60;
|
|
91
|
+
const paddedSeconds = `0${secondsRemainder}`.slice(-2);
|
|
92
|
+
return `${minutes}:${paddedSeconds}`;
|
|
93
|
+
}
|
|
94
|
+
/** Unmount */
|
|
95
|
+
destroy() {
|
|
96
|
+
super.destroy();
|
|
97
|
+
this.unsubscribe();
|
|
98
|
+
this.wrapper.remove();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export default HoverPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Hover=e():t.Hover=e()}("undefined"!=typeof WaveSurfer?WaveSurfer:this,(()=>(()=>{"use strict";var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>n});const s=class{constructor(){this.listeners={}}on(t,e){return this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),()=>this.un(t,e)}once(t,e){const s=this.on(t,e),i=this.on(t,(()=>{s(),i()}));return s}un(t,e){this.listeners[t]&&(e?this.listeners[t].delete(e):delete this.listeners[t])}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach((t=>t(...e)))}},i=class extends s{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach((t=>t()))}},r={lineWidth:1,labelSize:11};class o extends i{constructor(t){super(t||{}),this.unsubscribe=()=>{},this.onPointerMove=t=>{if(!this.wavesurfer)return;const e=this.wavesurfer.getWrapper().clientWidth,{offsetX:s}=t,i=Math.min(1,Math.max(0,s/e)),r=Math.min(e-this.options.lineWidth-1,s);this.wrapper.style.transform=`translateX(${r}px)`,this.wrapper.style.opacity="1";const o=this.wavesurfer.getDuration()||0;this.label.textContent=this.formatTime(o*i);const n=this.label.offsetWidth;this.label.style.transform=r+n>e?`translateX(-${n+this.options.lineWidth}px)`:"",this.emit("hover",i)},this.onPointerLeave=()=>{this.wrapper.style.opacity="0"},this.options=Object.assign({},r,t),this.wrapper=document.createElement("div"),this.label=document.createElement("span"),this.wrapper.appendChild(this.label)}static create(t){return new o(t)}addUnits(t){return`${t}${"number"==typeof t?"px":""}`}onInit(){if(!this.wavesurfer)throw Error("WaveSurfer is not initialized");const t=this.wavesurfer.options,e=this.options.lineColor||t.cursorColor||t.progressColor;this.wrapper.setAttribute("part","hover"),Object.assign(this.wrapper.style,{position:"absolute",zIndex:10,left:0,top:0,height:"100%",pointerEvents:"none",borderLeft:`${this.addUnits(this.options.lineWidth)} solid ${e}`,transition:"opacity .1s ease-in"}),this.label.setAttribute("part","hover-label"),Object.assign(this.label.style,{display:"block",backgroundColor:this.options.labelBackground,color:this.options.labelColor,fontSize:`${this.addUnits(this.options.labelSize)}`,transition:"transform .1s ease-in",padding:"2px 3px"});const s=this.wavesurfer.getWrapper();s.appendChild(this.wrapper),s.addEventListener("pointermove",this.onPointerMove),s.addEventListener("pointerleave",this.onPointerLeave),this.unsubscribe=()=>{s.removeEventListener("pointermove",this.onPointerMove),s.removeEventListener("pointerleave",this.onPointerLeave)}}formatTime(t){return`${Math.floor(t/60)}:${("0"+Math.round(t)%60).slice(-2)}`}destroy(){super.destroy(),this.unsubscribe(),this.wrapper.remove()}}const n=o;return e.default})()));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Minimap is a tiny copy of the main waveform serving as a navigation tool.
|
|
3
3
|
*/
|
|
4
|
-
import BasePlugin from '../base-plugin.js';
|
|
4
|
+
import BasePlugin, { type BasePluginEvents } from '../base-plugin.js';
|
|
5
5
|
import { type WaveSurferOptions } from '../wavesurfer.js';
|
|
6
6
|
export type MinimapPluginOptions = {
|
|
7
7
|
overlayColor?: string;
|
|
@@ -12,7 +12,7 @@ declare const defaultOptions: {
|
|
|
12
12
|
overlayColor: string;
|
|
13
13
|
insertPosition: string;
|
|
14
14
|
};
|
|
15
|
-
export type MinimapPluginEvents = {
|
|
15
|
+
export type MinimapPluginEvents = BasePluginEvents & {
|
|
16
16
|
ready: [];
|
|
17
17
|
interaction: [];
|
|
18
18
|
};
|
package/dist/plugins/minimap.js
CHANGED
|
@@ -22,6 +22,7 @@ export class MinimapPlugin extends BasePlugin {
|
|
|
22
22
|
}
|
|
23
23
|
/** Called by wavesurfer, don't call manually */
|
|
24
24
|
onInit() {
|
|
25
|
+
var _a, _b;
|
|
25
26
|
if (!this.wavesurfer) {
|
|
26
27
|
throw Error('WaveSurfer is not initialized');
|
|
27
28
|
}
|
|
@@ -32,11 +33,11 @@ export class MinimapPlugin extends BasePlugin {
|
|
|
32
33
|
else if (this.options.container instanceof HTMLElement) {
|
|
33
34
|
this.container = this.options.container;
|
|
34
35
|
}
|
|
35
|
-
this.container
|
|
36
|
+
(_a = this.container) === null || _a === void 0 ? void 0 : _a.appendChild(this.minimapWrapper);
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
this.container = this.wavesurfer.getWrapper().parentElement;
|
|
39
|
-
this.container
|
|
40
|
+
(_b = this.container) === null || _b === void 0 ? void 0 : _b.insertAdjacentElement(this.options.insertPosition, this.minimapWrapper);
|
|
40
41
|
}
|
|
41
42
|
this.initWaveSurferEvents();
|
|
42
43
|
}
|
|
@@ -64,15 +65,7 @@ export class MinimapPlugin extends BasePlugin {
|
|
|
64
65
|
const media = this.wavesurfer.getMediaElement();
|
|
65
66
|
if (!data || !media)
|
|
66
67
|
return;
|
|
67
|
-
this.miniWavesurfer = WaveSurfer.create({
|
|
68
|
-
...this.options,
|
|
69
|
-
container: this.minimapWrapper,
|
|
70
|
-
minPxPerSec: 0,
|
|
71
|
-
fillParent: true,
|
|
72
|
-
media,
|
|
73
|
-
peaks: [data.getChannelData(0)],
|
|
74
|
-
duration: data.duration,
|
|
75
|
-
});
|
|
68
|
+
this.miniWavesurfer = WaveSurfer.create(Object.assign(Object.assign({}, this.options), { container: this.minimapWrapper, minPxPerSec: 0, fillParent: true, media, peaks: [data.getChannelData(0)], duration: data.duration }));
|
|
76
69
|
this.subscriptions.push(this.miniWavesurfer.on('ready', () => {
|
|
77
70
|
this.emit('ready');
|
|
78
71
|
}), this.miniWavesurfer.on('interaction', () => {
|
|
@@ -80,7 +73,8 @@ export class MinimapPlugin extends BasePlugin {
|
|
|
80
73
|
}));
|
|
81
74
|
}
|
|
82
75
|
getOverlayWidth() {
|
|
83
|
-
|
|
76
|
+
var _a;
|
|
77
|
+
const waveformWidth = ((_a = this.wavesurfer) === null || _a === void 0 ? void 0 : _a.getWrapper().clientWidth) || 1;
|
|
84
78
|
return Math.round((this.minimapWrapper.clientWidth / waveformWidth) * 100);
|
|
85
79
|
}
|
|
86
80
|
onRedraw() {
|
|
@@ -106,7 +100,8 @@ export class MinimapPlugin extends BasePlugin {
|
|
|
106
100
|
}
|
|
107
101
|
/** Unmount */
|
|
108
102
|
destroy() {
|
|
109
|
-
|
|
103
|
+
var _a;
|
|
104
|
+
(_a = this.miniWavesurfer) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
110
105
|
this.minimapWrapper.remove();
|
|
111
106
|
super.destroy();
|
|
112
107
|
}
|