@wexio/messenger-widget-react 1.0.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/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/widget-react-AgErOR36.js +325 -0
- package/dist/widget-react-AgErOR36.js.map +1 -0
- package/dist/widget-react-BAOIDvhV.js +4250 -0
- package/dist/widget-react-BAOIDvhV.js.map +1 -0
- package/dist/widget-react-BfPdgAQ-.js +5767 -0
- package/dist/widget-react-BfPdgAQ-.js.map +1 -0
- package/dist/widget-react-BxvW64LH.js +4429 -0
- package/dist/widget-react-BxvW64LH.js.map +1 -0
- package/dist/widget-react-C5COLy3m.js +23847 -0
- package/dist/widget-react-C5COLy3m.js.map +1 -0
- package/dist/widget-react-CAWxn8I0.js +247 -0
- package/dist/widget-react-CAWxn8I0.js.map +1 -0
- package/dist/widget-react-CDPzwV1i.js +11685 -0
- package/dist/widget-react-CDPzwV1i.js.map +1 -0
- package/dist/widget-react-CPYwD6FR.js +498 -0
- package/dist/widget-react-CPYwD6FR.js.map +1 -0
- package/dist/widget-react-CUBFPjaV.js +23 -0
- package/dist/widget-react-CUBFPjaV.js.map +1 -0
- package/dist/widget-react-CUuKGDZN.js +355 -0
- package/dist/widget-react-CUuKGDZN.js.map +1 -0
- package/dist/widget-react-CZs0xRrr.js +1336 -0
- package/dist/widget-react-CZs0xRrr.js.map +1 -0
- package/dist/widget-react-Cj_zbk_F.js +325 -0
- package/dist/widget-react-Cj_zbk_F.js.map +1 -0
- package/dist/widget-react-D-QrEVpv.js +125 -0
- package/dist/widget-react-D-QrEVpv.js.map +1 -0
- package/dist/widget-react-D8TPnM9r.js +26 -0
- package/dist/widget-react-D8TPnM9r.js.map +1 -0
- package/dist/widget-react-DE7AVrCo.js +5737 -0
- package/dist/widget-react-DE7AVrCo.js.map +1 -0
- package/dist/widget-react-DOX6j7_Q.js +30 -0
- package/dist/widget-react-DOX6j7_Q.js.map +1 -0
- package/dist/widget-react-DSw03RG7.js +262 -0
- package/dist/widget-react-DSw03RG7.js.map +1 -0
- package/dist/widget-react-Dew7YaLU.js +16 -0
- package/dist/widget-react-Dew7YaLU.js.map +1 -0
- package/dist/widget-react-DtOeNw5z.js +325 -0
- package/dist/widget-react-DtOeNw5z.js.map +1 -0
- package/dist/widget-react-DwL_rsx_.js +630 -0
- package/dist/widget-react-DwL_rsx_.js.map +1 -0
- package/dist/widget-react.d.ts +301 -0
- package/dist/widget-react.js +22285 -0
- package/dist/widget-react.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,1336 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
import "react-dom";
|
|
3
|
+
import "react/jsx-runtime";
|
|
4
|
+
import "react-dom/client";
|
|
5
|
+
//#region node_modules/wavesurfer.js/dist/wavesurfer.esm.js
|
|
6
|
+
function e(e, t, n, r) {
|
|
7
|
+
return new (n || (n = Promise))((function(i, a) {
|
|
8
|
+
function o(e) {
|
|
9
|
+
try {
|
|
10
|
+
c(r.next(e));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
a(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function s(e) {
|
|
16
|
+
try {
|
|
17
|
+
c(r.throw(e));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
a(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function c(e) {
|
|
23
|
+
var t;
|
|
24
|
+
e.done ? i(e.value) : (t = e.value, t instanceof n ? t : new n((function(e) {
|
|
25
|
+
e(t);
|
|
26
|
+
}))).then(o, s);
|
|
27
|
+
}
|
|
28
|
+
c((r = r.apply(e, t || [])).next());
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
var t = class {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.listeners = {};
|
|
34
|
+
}
|
|
35
|
+
on(e, t, n) {
|
|
36
|
+
if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), n?.once) {
|
|
37
|
+
let n = (...r) => {
|
|
38
|
+
this.un(e, n), t(...r);
|
|
39
|
+
};
|
|
40
|
+
return this.listeners[e].add(n), () => this.un(e, n);
|
|
41
|
+
}
|
|
42
|
+
return this.listeners[e].add(t), () => this.un(e, t);
|
|
43
|
+
}
|
|
44
|
+
un(e, t) {
|
|
45
|
+
var n;
|
|
46
|
+
(n = this.listeners[e]) == null || n.delete(t);
|
|
47
|
+
}
|
|
48
|
+
once(e, t) {
|
|
49
|
+
return this.on(e, t, { once: !0 });
|
|
50
|
+
}
|
|
51
|
+
unAll() {
|
|
52
|
+
this.listeners = {};
|
|
53
|
+
}
|
|
54
|
+
emit(e, ...t) {
|
|
55
|
+
this.listeners[e] && this.listeners[e].forEach(((e) => e(...t)));
|
|
56
|
+
}
|
|
57
|
+
}, n = {
|
|
58
|
+
decode: function(t, n) {
|
|
59
|
+
return e(this, void 0, void 0, (function* () {
|
|
60
|
+
let e = new AudioContext({ sampleRate: n });
|
|
61
|
+
try {
|
|
62
|
+
return yield e.decodeAudioData(t);
|
|
63
|
+
} finally {
|
|
64
|
+
e.close();
|
|
65
|
+
}
|
|
66
|
+
}));
|
|
67
|
+
},
|
|
68
|
+
createBuffer: function(e, t) {
|
|
69
|
+
if (!e || e.length === 0) throw Error("channelData must be a non-empty array");
|
|
70
|
+
if (t <= 0) throw Error("duration must be greater than 0");
|
|
71
|
+
if (typeof e[0] == "number" && (e = [e]), !e[0] || e[0].length === 0) throw Error("channelData must contain non-empty channel arrays");
|
|
72
|
+
(function(e) {
|
|
73
|
+
let t = e[0];
|
|
74
|
+
if (t.some(((e) => e > 1 || e < -1))) {
|
|
75
|
+
let n = t.length, r = 0;
|
|
76
|
+
for (let e = 0; e < n; e++) {
|
|
77
|
+
let n = Math.abs(t[e]);
|
|
78
|
+
n > r && (r = n);
|
|
79
|
+
}
|
|
80
|
+
for (let t of e) for (let e = 0; e < n; e++) t[e] /= r;
|
|
81
|
+
}
|
|
82
|
+
})(e);
|
|
83
|
+
let n = e.map(((e) => e instanceof Float32Array ? e : Float32Array.from(e)));
|
|
84
|
+
return {
|
|
85
|
+
duration: t,
|
|
86
|
+
length: n[0].length,
|
|
87
|
+
sampleRate: n[0].length / t,
|
|
88
|
+
numberOfChannels: n.length,
|
|
89
|
+
getChannelData: (e) => {
|
|
90
|
+
let t = n[e];
|
|
91
|
+
if (!t) throw Error(`Channel ${e} not found`);
|
|
92
|
+
return t;
|
|
93
|
+
},
|
|
94
|
+
copyFromChannel: AudioBuffer.prototype.copyFromChannel,
|
|
95
|
+
copyToChannel: AudioBuffer.prototype.copyToChannel
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function r(e, t) {
|
|
100
|
+
let n = t.xmlns ? document.createElementNS(t.xmlns, e) : document.createElement(e);
|
|
101
|
+
for (let [e, i] of Object.entries(t)) if (e === "children" && i) for (let [e, t] of Object.entries(i)) t instanceof Node ? n.appendChild(t) : typeof t == "string" ? n.appendChild(document.createTextNode(t)) : n.appendChild(r(e, t));
|
|
102
|
+
else e === "style" ? Object.assign(n.style, i) : e === "textContent" ? n.textContent = i : n.setAttribute(e, i.toString());
|
|
103
|
+
return n;
|
|
104
|
+
}
|
|
105
|
+
function i(e, t, n) {
|
|
106
|
+
let i = r(e, t || {});
|
|
107
|
+
return n?.appendChild(i), i;
|
|
108
|
+
}
|
|
109
|
+
var a = Object.freeze({
|
|
110
|
+
__proto__: null,
|
|
111
|
+
createElement: i,
|
|
112
|
+
default: i
|
|
113
|
+
}), o = { fetchBlob: function(t, n, r) {
|
|
114
|
+
return e(this, void 0, void 0, (function* () {
|
|
115
|
+
let i = yield fetch(t, r);
|
|
116
|
+
if (i.status >= 400) throw Error(`Failed to fetch ${t}: ${i.status} (${i.statusText})`);
|
|
117
|
+
return function(t, n) {
|
|
118
|
+
e(this, void 0, void 0, (function* () {
|
|
119
|
+
if (!t.body || !t.headers) return;
|
|
120
|
+
let e = t.body.getReader(), r = Number(t.headers.get("Content-Length")) || 0, i = 0, a = (e) => {
|
|
121
|
+
i += e?.length || 0, n(Math.round(i / r * 100));
|
|
122
|
+
};
|
|
123
|
+
try {
|
|
124
|
+
for (;;) {
|
|
125
|
+
let t = yield e.read();
|
|
126
|
+
if (t.done) break;
|
|
127
|
+
a(t.value);
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
console.warn("Progress tracking error:", e);
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
}(i.clone(), n), i.blob();
|
|
134
|
+
}));
|
|
135
|
+
} };
|
|
136
|
+
function s(e) {
|
|
137
|
+
let t = e, n = /* @__PURE__ */ new Set();
|
|
138
|
+
return {
|
|
139
|
+
get value() {
|
|
140
|
+
return t;
|
|
141
|
+
},
|
|
142
|
+
set(e) {
|
|
143
|
+
Object.is(t, e) || (t = e, n.forEach(((e) => e(t))));
|
|
144
|
+
},
|
|
145
|
+
update(e) {
|
|
146
|
+
this.set(e(t));
|
|
147
|
+
},
|
|
148
|
+
subscribe: (e) => (n.add(e), () => n.delete(e))
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function c(e, t) {
|
|
152
|
+
let n = s(e());
|
|
153
|
+
return t.forEach(((t) => t.subscribe((() => {
|
|
154
|
+
let t = e();
|
|
155
|
+
Object.is(n.value, t) || n.set(t);
|
|
156
|
+
})))), {
|
|
157
|
+
get value() {
|
|
158
|
+
return n.value;
|
|
159
|
+
},
|
|
160
|
+
subscribe: (e) => n.subscribe(e)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function l(e, t) {
|
|
164
|
+
let n, r = () => {
|
|
165
|
+
n && (n(), n = void 0), n = e();
|
|
166
|
+
}, i = t.map(((e) => e.subscribe(r)));
|
|
167
|
+
return r(), () => {
|
|
168
|
+
n && (n(), n = void 0), i.forEach(((e) => e()));
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
var u = class extends t {
|
|
172
|
+
get isPlayingSignal() {
|
|
173
|
+
return this._isPlaying;
|
|
174
|
+
}
|
|
175
|
+
get currentTimeSignal() {
|
|
176
|
+
return this._currentTime;
|
|
177
|
+
}
|
|
178
|
+
get durationSignal() {
|
|
179
|
+
return this._duration;
|
|
180
|
+
}
|
|
181
|
+
get volumeSignal() {
|
|
182
|
+
return this._volume;
|
|
183
|
+
}
|
|
184
|
+
get mutedSignal() {
|
|
185
|
+
return this._muted;
|
|
186
|
+
}
|
|
187
|
+
get playbackRateSignal() {
|
|
188
|
+
return this._playbackRate;
|
|
189
|
+
}
|
|
190
|
+
get seekingSignal() {
|
|
191
|
+
return this._seeking;
|
|
192
|
+
}
|
|
193
|
+
constructor(e) {
|
|
194
|
+
super(), this.isExternalMedia = !1, this.reactiveMediaEventCleanups = [], e.media ? (this.media = e.media, this.isExternalMedia = !0) : this.media = document.createElement("audio"), this._isPlaying = s(!1), this._currentTime = s(0), this._duration = s(0), this._volume = s(this.media.volume), this._muted = s(this.media.muted), this._playbackRate = s(this.media.playbackRate || 1), this._seeking = s(!1), this.setupReactiveMediaEvents(), e.mediaControls && (this.media.controls = !0), e.autoplay && (this.media.autoplay = !0), e.playbackRate != null && this.onMediaEvent("canplay", (() => {
|
|
195
|
+
e.playbackRate != null && (this.media.playbackRate = e.playbackRate);
|
|
196
|
+
}), { once: !0 });
|
|
197
|
+
}
|
|
198
|
+
setupReactiveMediaEvents() {
|
|
199
|
+
this.reactiveMediaEventCleanups.push(this.onMediaEvent("play", (() => {
|
|
200
|
+
this._isPlaying.set(!0);
|
|
201
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("pause", (() => {
|
|
202
|
+
this._isPlaying.set(!1);
|
|
203
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("ended", (() => {
|
|
204
|
+
this._isPlaying.set(!1);
|
|
205
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("timeupdate", (() => {
|
|
206
|
+
this._currentTime.set(this.media.currentTime);
|
|
207
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("durationchange", (() => {
|
|
208
|
+
this._duration.set(this.media.duration || 0);
|
|
209
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("loadedmetadata", (() => {
|
|
210
|
+
this._duration.set(this.media.duration || 0);
|
|
211
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("seeking", (() => {
|
|
212
|
+
this._seeking.set(!0);
|
|
213
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("seeked", (() => {
|
|
214
|
+
this._seeking.set(!1);
|
|
215
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("volumechange", (() => {
|
|
216
|
+
this._volume.set(this.media.volume), this._muted.set(this.media.muted);
|
|
217
|
+
}))), this.reactiveMediaEventCleanups.push(this.onMediaEvent("ratechange", (() => {
|
|
218
|
+
this._playbackRate.set(this.media.playbackRate);
|
|
219
|
+
})));
|
|
220
|
+
}
|
|
221
|
+
onMediaEvent(e, t, n) {
|
|
222
|
+
return this.media.addEventListener(e, t, n), () => this.media.removeEventListener(e, t, n);
|
|
223
|
+
}
|
|
224
|
+
getSrc() {
|
|
225
|
+
return this.media.currentSrc || this.media.src || "";
|
|
226
|
+
}
|
|
227
|
+
revokeSrc() {
|
|
228
|
+
let e = this.getSrc();
|
|
229
|
+
e.startsWith("blob:") && URL.revokeObjectURL(e);
|
|
230
|
+
}
|
|
231
|
+
canPlayType(e) {
|
|
232
|
+
return this.media.canPlayType(e) !== "";
|
|
233
|
+
}
|
|
234
|
+
setSrc(e, t) {
|
|
235
|
+
let n = this.getSrc();
|
|
236
|
+
if (e && n === e) return;
|
|
237
|
+
this.revokeSrc();
|
|
238
|
+
let r = t instanceof Blob && (this.canPlayType(t.type) || !e) ? URL.createObjectURL(t) : e;
|
|
239
|
+
if (n && this.media.removeAttribute("src"), r || e) try {
|
|
240
|
+
this.media.src = r;
|
|
241
|
+
} catch {
|
|
242
|
+
this.media.src = e;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
destroy() {
|
|
246
|
+
this.reactiveMediaEventCleanups.forEach(((e) => e())), this.reactiveMediaEventCleanups = [], this.isExternalMedia || (this.media.pause(), this.revokeSrc(), this.media.removeAttribute("src"), this.media.load(), this.media.remove());
|
|
247
|
+
}
|
|
248
|
+
setMediaElement(e) {
|
|
249
|
+
this.reactiveMediaEventCleanups.forEach(((e) => e())), this.reactiveMediaEventCleanups = [], this.media = e, this.setupReactiveMediaEvents();
|
|
250
|
+
}
|
|
251
|
+
play() {
|
|
252
|
+
return e(this, void 0, void 0, (function* () {
|
|
253
|
+
try {
|
|
254
|
+
return yield this.media.play();
|
|
255
|
+
} catch (e) {
|
|
256
|
+
if (e instanceof DOMException && e.name === "AbortError") return;
|
|
257
|
+
throw e;
|
|
258
|
+
}
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
pause() {
|
|
262
|
+
this.media.pause();
|
|
263
|
+
}
|
|
264
|
+
isPlaying() {
|
|
265
|
+
return !this.media.paused && !this.media.ended;
|
|
266
|
+
}
|
|
267
|
+
setTime(e) {
|
|
268
|
+
this.media.currentTime = Math.max(0, Math.min(e, this.getDuration()));
|
|
269
|
+
}
|
|
270
|
+
getDuration() {
|
|
271
|
+
return this.media.duration;
|
|
272
|
+
}
|
|
273
|
+
getCurrentTime() {
|
|
274
|
+
return this.media.currentTime;
|
|
275
|
+
}
|
|
276
|
+
getVolume() {
|
|
277
|
+
return this.media.volume;
|
|
278
|
+
}
|
|
279
|
+
setVolume(e) {
|
|
280
|
+
this.media.volume = e;
|
|
281
|
+
}
|
|
282
|
+
getMuted() {
|
|
283
|
+
return this.media.muted;
|
|
284
|
+
}
|
|
285
|
+
setMuted(e) {
|
|
286
|
+
this.media.muted = e;
|
|
287
|
+
}
|
|
288
|
+
getPlaybackRate() {
|
|
289
|
+
return this.media.playbackRate;
|
|
290
|
+
}
|
|
291
|
+
isSeeking() {
|
|
292
|
+
return this.media.seeking;
|
|
293
|
+
}
|
|
294
|
+
setPlaybackRate(e, t) {
|
|
295
|
+
t != null && (this.media.preservesPitch = t), this.media.playbackRate = e;
|
|
296
|
+
}
|
|
297
|
+
getMediaElement() {
|
|
298
|
+
return this.media;
|
|
299
|
+
}
|
|
300
|
+
setSinkId(e) {
|
|
301
|
+
return this.media.setSinkId(e);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
function d({ maxTop: e, maxBottom: t, halfHeight: n, vScale: r, barMinHeight: i = 0, barAlign: a }) {
|
|
305
|
+
let o = Math.round(e * n * r), s = o + Math.round(t * n * r) || 1;
|
|
306
|
+
return s < i && (s = i, a || (o = s / 2)), {
|
|
307
|
+
topHeight: o,
|
|
308
|
+
totalHeight: s
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function f({ barAlign: e, halfHeight: t, topHeight: n, totalHeight: r, canvasHeight: i }) {
|
|
312
|
+
return e === "top" ? 0 : e === "bottom" ? i - r : t - n;
|
|
313
|
+
}
|
|
314
|
+
function p(e, t, n) {
|
|
315
|
+
let r = t - e.left, i = n - e.top;
|
|
316
|
+
return [r / e.width, i / e.height];
|
|
317
|
+
}
|
|
318
|
+
function m(e) {
|
|
319
|
+
return !!(e.barWidth || e.barGap || e.barAlign);
|
|
320
|
+
}
|
|
321
|
+
function h(e, t) {
|
|
322
|
+
if (!m(t)) return e;
|
|
323
|
+
let n = t.barWidth || .5, r = n + (t.barGap || n / 2);
|
|
324
|
+
return r === 0 ? e : Math.floor(e / r) * r;
|
|
325
|
+
}
|
|
326
|
+
function g({ scrollLeft: e, totalWidth: t, numCanvases: n }) {
|
|
327
|
+
if (t === 0) return [0];
|
|
328
|
+
let r = e / t, i = Math.floor(r * n);
|
|
329
|
+
return [
|
|
330
|
+
i - 1,
|
|
331
|
+
i,
|
|
332
|
+
i + 1
|
|
333
|
+
];
|
|
334
|
+
}
|
|
335
|
+
function _(e) {
|
|
336
|
+
let t = e._cleanup;
|
|
337
|
+
typeof t == "function" && t();
|
|
338
|
+
}
|
|
339
|
+
function v(e) {
|
|
340
|
+
let t = s({
|
|
341
|
+
scrollLeft: e.scrollLeft,
|
|
342
|
+
scrollWidth: e.scrollWidth,
|
|
343
|
+
clientWidth: e.clientWidth
|
|
344
|
+
}), n = c((() => function(e) {
|
|
345
|
+
let { scrollLeft: t, scrollWidth: n, clientWidth: r } = e;
|
|
346
|
+
if (n === 0) return {
|
|
347
|
+
startX: 0,
|
|
348
|
+
endX: 1
|
|
349
|
+
};
|
|
350
|
+
let i = t / n, a = (t + r) / n;
|
|
351
|
+
return {
|
|
352
|
+
startX: Math.max(0, Math.min(1, i)),
|
|
353
|
+
endX: Math.max(0, Math.min(1, a))
|
|
354
|
+
};
|
|
355
|
+
}(t.value)), [t]), r = c((() => function(e) {
|
|
356
|
+
return {
|
|
357
|
+
left: e.scrollLeft,
|
|
358
|
+
right: e.scrollLeft + e.clientWidth
|
|
359
|
+
};
|
|
360
|
+
}(t.value)), [t]), i = () => {
|
|
361
|
+
t.set({
|
|
362
|
+
scrollLeft: e.scrollLeft,
|
|
363
|
+
scrollWidth: e.scrollWidth,
|
|
364
|
+
clientWidth: e.clientWidth
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
return e.addEventListener("scroll", i, { passive: !0 }), {
|
|
368
|
+
scrollData: t,
|
|
369
|
+
percentages: n,
|
|
370
|
+
bounds: r,
|
|
371
|
+
cleanup: () => {
|
|
372
|
+
e.removeEventListener("scroll", i), _(t);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
var y = class extends t {
|
|
377
|
+
constructor(e, t) {
|
|
378
|
+
super(), this.timeouts = [], this.isScrollable = !1, this.audioData = null, this.resizeObserver = null, this.lastContainerWidth = 0, this.isDragging = !1, this.subscriptions = [], this.unsubscribeOnScroll = [], this.dragStream = null, this.scrollStream = null, this.containerInlinePadding = 0, this.subscriptions = [], this.options = e;
|
|
379
|
+
let n = this.parentFromOptionsContainer(e.container);
|
|
380
|
+
this.parent = n;
|
|
381
|
+
let [r, i] = this.initHtml();
|
|
382
|
+
n.appendChild(r), this.container = r, this.scrollContainer = i.querySelector(".scroll"), this.wrapper = i.querySelector(".wrapper"), this.canvasWrapper = i.querySelector(".canvases"), this.progressWrapper = i.querySelector(".progress"), this.cursor = i.querySelector(".cursor"), this.calculateInlinePadding(), t && i.appendChild(t), this.initEvents();
|
|
383
|
+
}
|
|
384
|
+
parentFromOptionsContainer(e) {
|
|
385
|
+
let t;
|
|
386
|
+
if (typeof e == "string" ? t = document.querySelector(e) : e instanceof HTMLElement && (t = e), !t) throw Error("Container not found");
|
|
387
|
+
return t;
|
|
388
|
+
}
|
|
389
|
+
initEvents() {
|
|
390
|
+
this.wrapper.addEventListener("click", ((e) => {
|
|
391
|
+
let [t, n] = p(this.wrapper.getBoundingClientRect(), e.clientX, e.clientY);
|
|
392
|
+
this.emit("click", t, n);
|
|
393
|
+
})), this.wrapper.addEventListener("dblclick", ((e) => {
|
|
394
|
+
let [t, n] = p(this.wrapper.getBoundingClientRect(), e.clientX, e.clientY);
|
|
395
|
+
this.emit("dblclick", t, n);
|
|
396
|
+
})), !0 !== this.options.dragToSeek && typeof this.options.dragToSeek != "object" || this.initDrag(), this.scrollStream = v(this.scrollContainer);
|
|
397
|
+
let e = l((() => {
|
|
398
|
+
let { startX: e, endX: t } = this.scrollStream.percentages.value, { left: n, right: r } = this.scrollStream.bounds.value;
|
|
399
|
+
this.emit("scroll", e, t, n, r);
|
|
400
|
+
}), [this.scrollStream.percentages, this.scrollStream.bounds]);
|
|
401
|
+
if (this.subscriptions.push(e), typeof ResizeObserver == "function") {
|
|
402
|
+
let e = this.createDelay(100);
|
|
403
|
+
this.resizeObserver = new ResizeObserver((() => {
|
|
404
|
+
e().then((() => this.onContainerResize())).catch((() => {}));
|
|
405
|
+
})), this.resizeObserver.observe(this.scrollContainer);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
onContainerResize() {
|
|
409
|
+
let e = this.parent.clientWidth;
|
|
410
|
+
this.calculateInlinePadding(), e === this.lastContainerWidth && this.options.height !== "auto" || (this.lastContainerWidth = e, this.reRender(), this.emit("resize"));
|
|
411
|
+
}
|
|
412
|
+
initDrag() {
|
|
413
|
+
if (this.dragStream) return;
|
|
414
|
+
this.dragStream = function(e, t = {}) {
|
|
415
|
+
let { threshold: n = 3, mouseButton: r = 0, touchDelay: i = 100 } = t, a = s(null), o = /* @__PURE__ */ new Map(), c = matchMedia("(pointer: coarse)").matches, l = () => {}, u = (t) => {
|
|
416
|
+
if (t.button !== r || (o.set(t.pointerId, t), o.size > 1)) return;
|
|
417
|
+
let s = t.clientX, u = t.clientY, d = !1, f = Date.now(), { left: p, top: m } = e.getBoundingClientRect(), h = (e) => {
|
|
418
|
+
if (e.defaultPrevented || o.size > 1 || c && Date.now() - f < i) return;
|
|
419
|
+
let t = e.clientX, r = e.clientY, l = t - s, h = r - u;
|
|
420
|
+
(d || Math.abs(l) > n || Math.abs(h) > n) && (e.preventDefault(), e.stopPropagation(), d || (a.set({
|
|
421
|
+
type: "start",
|
|
422
|
+
x: s - p,
|
|
423
|
+
y: u - m
|
|
424
|
+
}), d = !0), a.set({
|
|
425
|
+
type: "move",
|
|
426
|
+
x: t - p,
|
|
427
|
+
y: r - m,
|
|
428
|
+
deltaX: l,
|
|
429
|
+
deltaY: h
|
|
430
|
+
}), s = t, u = r);
|
|
431
|
+
}, g = (e) => {
|
|
432
|
+
if (o.delete(e.pointerId), d) {
|
|
433
|
+
let t = e.clientX, n = e.clientY;
|
|
434
|
+
a.set({
|
|
435
|
+
type: "end",
|
|
436
|
+
x: t - p,
|
|
437
|
+
y: n - m
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
l();
|
|
441
|
+
}, _ = (e) => {
|
|
442
|
+
o.delete(e.pointerId), e.relatedTarget && e.relatedTarget !== document.documentElement || g(e);
|
|
443
|
+
}, v = (e) => {
|
|
444
|
+
d && (e.stopPropagation(), e.preventDefault());
|
|
445
|
+
}, y = (e) => {
|
|
446
|
+
e.defaultPrevented || o.size > 1 || d && e.preventDefault();
|
|
447
|
+
};
|
|
448
|
+
document.addEventListener("pointermove", h), document.addEventListener("pointerup", g), document.addEventListener("pointerout", _), document.addEventListener("pointercancel", _), document.addEventListener("touchmove", y, { passive: !1 }), document.addEventListener("click", v, { capture: !0 }), l = () => {
|
|
449
|
+
document.removeEventListener("pointermove", h), document.removeEventListener("pointerup", g), document.removeEventListener("pointerout", _), document.removeEventListener("pointercancel", _), document.removeEventListener("touchmove", y), setTimeout((() => {
|
|
450
|
+
document.removeEventListener("click", v, { capture: !0 });
|
|
451
|
+
}), 10);
|
|
452
|
+
};
|
|
453
|
+
};
|
|
454
|
+
return e.addEventListener("pointerdown", u), {
|
|
455
|
+
signal: a,
|
|
456
|
+
cleanup: () => {
|
|
457
|
+
l(), e.removeEventListener("pointerdown", u), o.clear(), _(a);
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
}(this.wrapper);
|
|
461
|
+
let e = l((() => {
|
|
462
|
+
let e = this.dragStream.signal.value;
|
|
463
|
+
if (!e) return;
|
|
464
|
+
let t = this.wrapper.getBoundingClientRect().width, n = (r = e.x / t) < 0 ? 0 : r > 1 ? 1 : r;
|
|
465
|
+
var r;
|
|
466
|
+
e.type === "start" ? (this.isDragging = !0, this.emit("dragstart", n)) : e.type === "move" ? this.emit("drag", n) : e.type === "end" && (this.isDragging = !1, this.emit("dragend", n));
|
|
467
|
+
}), [this.dragStream.signal]);
|
|
468
|
+
this.subscriptions.push(e);
|
|
469
|
+
}
|
|
470
|
+
calculateInlinePadding() {
|
|
471
|
+
let { paddingLeft: e, paddingRight: t } = getComputedStyle(this.scrollContainer), n = parseFloat(e) + parseFloat(t);
|
|
472
|
+
this.containerInlinePadding = Number.isNaN(n) ? 0 : n;
|
|
473
|
+
}
|
|
474
|
+
initHtml() {
|
|
475
|
+
let e = document.createElement("div"), t = e.attachShadow({ mode: "open" }), n = this.options.cspNonce && typeof this.options.cspNonce == "string" ? this.options.cspNonce.replace(/"/g, "") : "";
|
|
476
|
+
return t.innerHTML = `\n <style${n ? ` nonce="${n}"` : ""}>\n :host {\n user-select: none;\n min-width: 1px;\n }\n :host audio {\n display: block;\n width: 100%;\n }\n :host .scroll {\n overflow-x: auto;\n overflow-y: hidden;\n width: 100%;\n position: relative;\n }\n :host .noScrollbar {\n scrollbar-color: transparent;\n scrollbar-width: none;\n }\n :host .noScrollbar::-webkit-scrollbar {\n display: none;\n -webkit-appearance: none;\n }\n :host .wrapper {\n position: relative;\n overflow: visible;\n z-index: 2;\n }\n :host .canvases {\n min-height: ${this.getHeight(this.options.height, this.options.splitChannels)}px;\n pointer-events: none;\n }\n :host .canvases > div {\n position: relative;\n }\n :host canvas {\n display: block;\n position: absolute;\n top: 0;\n image-rendering: pixelated;\n }\n :host .progress {\n pointer-events: none;\n position: absolute;\n z-index: 2;\n top: 0;\n left: 0;\n width: 0;\n height: 100%;\n overflow: hidden;\n }\n :host .progress > div {\n position: relative;\n }\n :host .cursor {\n pointer-events: none;\n position: absolute;\n z-index: 5;\n top: 0;\n left: 0;\n height: 100%;\n border-radius: 2px;\n }\n </style>\n\n <div class="scroll" part="scroll">\n <div class="wrapper" part="wrapper">\n <div class="canvases" part="canvases"></div>\n <div class="progress" part="progress"></div>\n <div class="cursor" part="cursor"></div>\n </div>\n </div>\n `, [e, t];
|
|
477
|
+
}
|
|
478
|
+
setOptions(e) {
|
|
479
|
+
var t;
|
|
480
|
+
if (this.options.container !== e.container) {
|
|
481
|
+
let t = this.parentFromOptionsContainer(e.container);
|
|
482
|
+
t.appendChild(this.container), this.parent = t;
|
|
483
|
+
}
|
|
484
|
+
!0 === e.dragToSeek || typeof this.options.dragToSeek == "object" ? this.initDrag() : ((t = this.dragStream) == null || t.cleanup(), this.dragStream = null), this.options = e, this.reRender();
|
|
485
|
+
}
|
|
486
|
+
getWrapper() {
|
|
487
|
+
return this.wrapper;
|
|
488
|
+
}
|
|
489
|
+
getWidth() {
|
|
490
|
+
return this.scrollContainer.clientWidth - this.containerInlinePadding;
|
|
491
|
+
}
|
|
492
|
+
getScroll() {
|
|
493
|
+
return this.scrollContainer.scrollLeft;
|
|
494
|
+
}
|
|
495
|
+
setScroll(e) {
|
|
496
|
+
this.scrollContainer.scrollLeft = e;
|
|
497
|
+
}
|
|
498
|
+
setScrollPercentage(e) {
|
|
499
|
+
let { scrollWidth: t } = this.scrollContainer, n = t * e;
|
|
500
|
+
this.setScroll(n);
|
|
501
|
+
}
|
|
502
|
+
destroy() {
|
|
503
|
+
var e;
|
|
504
|
+
this.subscriptions.forEach(((e) => e())), this.container.remove(), this.resizeObserver && (this.resizeObserver.disconnect(), this.resizeObserver = null), (e = this.unsubscribeOnScroll) == null || e.forEach(((e) => e())), this.unsubscribeOnScroll = [], this.dragStream && (this.dragStream.cleanup(), this.dragStream = null), this.scrollStream && (this.scrollStream.cleanup(), this.scrollStream = null);
|
|
505
|
+
}
|
|
506
|
+
createDelay(e = 10) {
|
|
507
|
+
let t, n, r = () => {
|
|
508
|
+
t && (clearTimeout(t), t = void 0), n && (n(), n = void 0);
|
|
509
|
+
};
|
|
510
|
+
return this.timeouts.push(r), () => new Promise(((i, a) => {
|
|
511
|
+
r(), n = a, t = setTimeout((() => {
|
|
512
|
+
t = void 0, n = void 0, i();
|
|
513
|
+
}), e);
|
|
514
|
+
}));
|
|
515
|
+
}
|
|
516
|
+
getHeight(e, t) {
|
|
517
|
+
let n = this.audioData?.numberOfChannels || 1;
|
|
518
|
+
return function({ optionsHeight: e, optionsSplitChannels: t, parentHeight: n, numberOfChannels: r, defaultHeight: i = 128 }) {
|
|
519
|
+
if (e == null) return i;
|
|
520
|
+
let a = Number(e);
|
|
521
|
+
if (!isNaN(a)) return a;
|
|
522
|
+
if (e === "auto") {
|
|
523
|
+
let e = n || i;
|
|
524
|
+
return t?.every(((e) => !e.overlay)) ? e / r : e;
|
|
525
|
+
}
|
|
526
|
+
return i;
|
|
527
|
+
}({
|
|
528
|
+
optionsHeight: e,
|
|
529
|
+
optionsSplitChannels: t,
|
|
530
|
+
parentHeight: this.parent.clientHeight,
|
|
531
|
+
numberOfChannels: n,
|
|
532
|
+
defaultHeight: 128
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
convertColorValues(e, t) {
|
|
536
|
+
return function(e, t, n) {
|
|
537
|
+
if (!Array.isArray(e)) return e || "";
|
|
538
|
+
if (e.length === 0) return "#999";
|
|
539
|
+
if (e.length < 2) return e[0] || "";
|
|
540
|
+
let r = document.createElement("canvas"), i = r.getContext("2d"), a = n ?? r.height * t, o = i.createLinearGradient(0, 0, 0, a || t), s = 1 / (e.length - 1);
|
|
541
|
+
return e.forEach(((e, t) => {
|
|
542
|
+
o.addColorStop(t * s, e);
|
|
543
|
+
})), o;
|
|
544
|
+
}(e, this.getPixelRatio(), t?.canvas.height);
|
|
545
|
+
}
|
|
546
|
+
getPixelRatio() {
|
|
547
|
+
return e = window.devicePixelRatio, Math.max(1, e || 1);
|
|
548
|
+
var e;
|
|
549
|
+
}
|
|
550
|
+
renderBarWaveform(e, t, n, r) {
|
|
551
|
+
let { width: i, height: a } = n.canvas, { halfHeight: o, barWidth: s, barRadius: c, barIndexScale: l, barSpacing: u, barMinHeight: p } = function({ width: e, height: t, length: n, options: r, pixelRatio: i }) {
|
|
552
|
+
let a = t / 2, o = r.barWidth ? r.barWidth * i : 1, s = r.barGap ? r.barGap * i : r.barWidth ? o / 2 : 0, c = o + s || 1;
|
|
553
|
+
return {
|
|
554
|
+
halfHeight: a,
|
|
555
|
+
barWidth: o,
|
|
556
|
+
barGap: s,
|
|
557
|
+
barRadius: r.barRadius || 0,
|
|
558
|
+
barMinHeight: r.barMinHeight ? r.barMinHeight * i : 0,
|
|
559
|
+
barIndexScale: n > 0 ? e / c / n : 0,
|
|
560
|
+
barSpacing: c
|
|
561
|
+
};
|
|
562
|
+
}({
|
|
563
|
+
width: i,
|
|
564
|
+
height: a,
|
|
565
|
+
length: (e[0] || []).length,
|
|
566
|
+
options: t,
|
|
567
|
+
pixelRatio: this.getPixelRatio()
|
|
568
|
+
}), m = function({ channelData: e, barIndexScale: t, barSpacing: n, barWidth: r, halfHeight: i, vScale: a, canvasHeight: o, barAlign: s, barMinHeight: c }) {
|
|
569
|
+
let l = e[0] || [], u = e[1] || l, p = l.length, m = [], h = 0, g = 0, _ = 0;
|
|
570
|
+
for (let e = 0; e <= p; e++) {
|
|
571
|
+
let p = Math.round(e * t);
|
|
572
|
+
if (p > h) {
|
|
573
|
+
let { topHeight: e, totalHeight: t } = d({
|
|
574
|
+
maxTop: g,
|
|
575
|
+
maxBottom: _,
|
|
576
|
+
halfHeight: i,
|
|
577
|
+
vScale: a,
|
|
578
|
+
barMinHeight: c,
|
|
579
|
+
barAlign: s
|
|
580
|
+
}), l = f({
|
|
581
|
+
barAlign: s,
|
|
582
|
+
halfHeight: i,
|
|
583
|
+
topHeight: e,
|
|
584
|
+
totalHeight: t,
|
|
585
|
+
canvasHeight: o
|
|
586
|
+
});
|
|
587
|
+
m.push({
|
|
588
|
+
x: h * n,
|
|
589
|
+
y: l,
|
|
590
|
+
width: r,
|
|
591
|
+
height: t
|
|
592
|
+
}), h = p, g = 0, _ = 0;
|
|
593
|
+
}
|
|
594
|
+
let v = Math.abs(l[e] || 0), y = Math.abs(u[e] || 0);
|
|
595
|
+
v > g && (g = v), y > _ && (_ = y);
|
|
596
|
+
}
|
|
597
|
+
return m;
|
|
598
|
+
}({
|
|
599
|
+
channelData: e,
|
|
600
|
+
barIndexScale: l,
|
|
601
|
+
barSpacing: u,
|
|
602
|
+
barWidth: s,
|
|
603
|
+
halfHeight: o,
|
|
604
|
+
vScale: r,
|
|
605
|
+
canvasHeight: a,
|
|
606
|
+
barAlign: t.barAlign,
|
|
607
|
+
barMinHeight: p
|
|
608
|
+
});
|
|
609
|
+
n.beginPath();
|
|
610
|
+
for (let e of m) c && "roundRect" in n ? n.roundRect(e.x, e.y, e.width, e.height, c) : n.rect(e.x, e.y, e.width, e.height);
|
|
611
|
+
n.fill(), n.closePath();
|
|
612
|
+
}
|
|
613
|
+
renderLineWaveform(e, t, n, r) {
|
|
614
|
+
let { width: i, height: a } = n.canvas, o = function({ channelData: e, width: t, height: n, vScale: r }) {
|
|
615
|
+
let i = n / 2, a = e[0] || [];
|
|
616
|
+
return [a, e[1] || a].map(((e, n) => {
|
|
617
|
+
let a = e.length, o = a ? t / a : 0, s = i, c = n === 0 ? -1 : 1, l = [{
|
|
618
|
+
x: 0,
|
|
619
|
+
y: s
|
|
620
|
+
}], u = 0, d = 0;
|
|
621
|
+
for (let t = 0; t <= a; t++) {
|
|
622
|
+
let n = Math.round(t * o);
|
|
623
|
+
if (n > u) {
|
|
624
|
+
let e = s + (Math.round(d * i * r) || 1) * c;
|
|
625
|
+
l.push({
|
|
626
|
+
x: u,
|
|
627
|
+
y: e
|
|
628
|
+
}), u = n, d = 0;
|
|
629
|
+
}
|
|
630
|
+
let a = Math.abs(e[t] || 0);
|
|
631
|
+
a > d && (d = a);
|
|
632
|
+
}
|
|
633
|
+
return l.push({
|
|
634
|
+
x: u,
|
|
635
|
+
y: s
|
|
636
|
+
}), l;
|
|
637
|
+
}));
|
|
638
|
+
}({
|
|
639
|
+
channelData: e,
|
|
640
|
+
width: i,
|
|
641
|
+
height: a,
|
|
642
|
+
vScale: r
|
|
643
|
+
});
|
|
644
|
+
n.beginPath();
|
|
645
|
+
for (let e of o) if (e.length) {
|
|
646
|
+
n.moveTo(e[0].x, e[0].y);
|
|
647
|
+
for (let t = 1; t < e.length; t++) {
|
|
648
|
+
let r = e[t];
|
|
649
|
+
n.lineTo(r.x, r.y);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
n.fill(), n.closePath();
|
|
653
|
+
}
|
|
654
|
+
renderWaveform(e, t, n) {
|
|
655
|
+
if (n.fillStyle = this.convertColorValues(t.waveColor, n), t.renderFunction) return void t.renderFunction(e, n);
|
|
656
|
+
let r = function({ channelData: e, barHeight: t, normalize: n, maxPeak: r }) {
|
|
657
|
+
let i = t || 1;
|
|
658
|
+
if (!n) return i;
|
|
659
|
+
let a = e[0];
|
|
660
|
+
if (!a || a.length === 0) return i;
|
|
661
|
+
let o = r ?? 0;
|
|
662
|
+
if (!r) for (let e = 0; e < a.length; e++) {
|
|
663
|
+
let t = a[e] ?? 0, n = Math.abs(t);
|
|
664
|
+
n > o && (o = n);
|
|
665
|
+
}
|
|
666
|
+
return o ? i / o : i;
|
|
667
|
+
}({
|
|
668
|
+
channelData: e,
|
|
669
|
+
barHeight: t.barHeight,
|
|
670
|
+
normalize: t.normalize,
|
|
671
|
+
maxPeak: t.maxPeak
|
|
672
|
+
});
|
|
673
|
+
m(t) ? this.renderBarWaveform(e, t, n, r) : this.renderLineWaveform(e, t, n, r);
|
|
674
|
+
}
|
|
675
|
+
renderSingleCanvas(e, t, n, r, i, a, o) {
|
|
676
|
+
let s = this.getPixelRatio(), c = document.createElement("canvas");
|
|
677
|
+
c.width = Math.round(n * s), c.height = Math.round(r * s), c.style.width = `${n}px`, c.style.height = `${r}px`, c.style.left = `${Math.round(i)}px`, a.appendChild(c);
|
|
678
|
+
let l = c.getContext("2d");
|
|
679
|
+
if (t.renderFunction ? (l.fillStyle = this.convertColorValues(t.waveColor, l), t.renderFunction(e, l)) : this.renderWaveform(e, t, l), c.width > 0 && c.height > 0) {
|
|
680
|
+
let e = c.cloneNode(), n = e.getContext("2d");
|
|
681
|
+
n.drawImage(c, 0, 0), n.globalCompositeOperation = "source-in", n.fillStyle = this.convertColorValues(t.progressColor, n), n.fillRect(0, 0, c.width, c.height), o.appendChild(e);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
renderMultiCanvas(e, t, n, r, i, a) {
|
|
685
|
+
let o = this.getPixelRatio(), { clientWidth: s } = this.scrollContainer, c = n / o, l = function({ clientWidth: e, totalWidth: t, options: n }) {
|
|
686
|
+
return h(Math.min(8e3, e, t), n);
|
|
687
|
+
}({
|
|
688
|
+
clientWidth: s,
|
|
689
|
+
totalWidth: c,
|
|
690
|
+
options: t
|
|
691
|
+
}), u = {};
|
|
692
|
+
if (l === 0) return;
|
|
693
|
+
let d = (n) => {
|
|
694
|
+
if (n < 0 || n >= f || u[n]) return;
|
|
695
|
+
u[n] = !0;
|
|
696
|
+
let o = n * l, s = Math.min(c - o, l);
|
|
697
|
+
if (s = h(s, t), s <= 0) return;
|
|
698
|
+
let d = function({ channelData: e, offset: t, clampedWidth: n, totalWidth: r }) {
|
|
699
|
+
return e.map(((e) => {
|
|
700
|
+
let i = Math.floor(t / r * e.length), a = Math.floor((t + n) / r * e.length);
|
|
701
|
+
return e.slice(i, a);
|
|
702
|
+
}));
|
|
703
|
+
}({
|
|
704
|
+
channelData: e,
|
|
705
|
+
offset: o,
|
|
706
|
+
clampedWidth: s,
|
|
707
|
+
totalWidth: c
|
|
708
|
+
});
|
|
709
|
+
this.renderSingleCanvas(d, t, s, r, o, i, a);
|
|
710
|
+
}, f = Math.ceil(c / l);
|
|
711
|
+
if (!this.isScrollable) {
|
|
712
|
+
for (let e = 0; e < f; e++) d(e);
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
if (g({
|
|
716
|
+
scrollLeft: this.scrollContainer.scrollLeft,
|
|
717
|
+
totalWidth: c,
|
|
718
|
+
numCanvases: f
|
|
719
|
+
}).forEach(((e) => d(e))), f > 1) {
|
|
720
|
+
let e = this.on("scroll", (() => {
|
|
721
|
+
let { scrollLeft: e } = this.scrollContainer;
|
|
722
|
+
Object.keys(u).length > 10 && (i.innerHTML = "", a.innerHTML = "", u = {}), g({
|
|
723
|
+
scrollLeft: e,
|
|
724
|
+
totalWidth: c,
|
|
725
|
+
numCanvases: f
|
|
726
|
+
}).forEach(((e) => d(e)));
|
|
727
|
+
}));
|
|
728
|
+
this.unsubscribeOnScroll.push(e);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
renderChannel(e, t, n, r) {
|
|
732
|
+
var { overlay: i } = t, a = function(e, t) {
|
|
733
|
+
var n = {};
|
|
734
|
+
for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
|
|
735
|
+
if (e != null && typeof Object.getOwnPropertySymbols == "function") {
|
|
736
|
+
var i = 0;
|
|
737
|
+
for (r = Object.getOwnPropertySymbols(e); i < r.length; i++) t.indexOf(r[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[i]) && (n[r[i]] = e[r[i]]);
|
|
738
|
+
}
|
|
739
|
+
return n;
|
|
740
|
+
}(t, ["overlay"]);
|
|
741
|
+
let o = document.createElement("div"), s = this.getHeight(a.height, a.splitChannels);
|
|
742
|
+
o.style.height = `${s}px`, i && r > 0 && (o.style.marginTop = `-${s}px`), this.canvasWrapper.style.minHeight = `${s}px`, this.canvasWrapper.appendChild(o);
|
|
743
|
+
let c = o.cloneNode();
|
|
744
|
+
this.progressWrapper.appendChild(c), this.renderMultiCanvas(e, a, n, s, o, c);
|
|
745
|
+
}
|
|
746
|
+
render(t) {
|
|
747
|
+
return e(this, void 0, void 0, (function* () {
|
|
748
|
+
this.timeouts.forEach(((e) => e())), this.timeouts = [], this.canvasWrapper.innerHTML = "", this.progressWrapper.innerHTML = "", this.options.width != null && (this.scrollContainer.style.width = typeof this.options.width == "number" ? `${this.options.width}px` : this.options.width);
|
|
749
|
+
let e = this.getPixelRatio(), n = this.scrollContainer.clientWidth - this.containerInlinePadding, { scrollWidth: r, isScrollable: i, useParentWidth: a, width: o } = function({ duration: e, minPxPerSec: t = 0, parentWidth: n, fillParent: r, pixelRatio: i }) {
|
|
750
|
+
let a = Math.ceil(e * t), o = a > n, s = !!(r && !o);
|
|
751
|
+
return {
|
|
752
|
+
scrollWidth: a,
|
|
753
|
+
isScrollable: o,
|
|
754
|
+
useParentWidth: s,
|
|
755
|
+
width: (s ? n : a) * i
|
|
756
|
+
};
|
|
757
|
+
}({
|
|
758
|
+
duration: t.duration,
|
|
759
|
+
minPxPerSec: this.options.minPxPerSec || 0,
|
|
760
|
+
parentWidth: n,
|
|
761
|
+
fillParent: this.options.fillParent,
|
|
762
|
+
pixelRatio: e
|
|
763
|
+
});
|
|
764
|
+
if (this.isScrollable = i, this.wrapper.style.width = a ? "100%" : `${r}px`, this.scrollContainer.style.overflowX = this.isScrollable ? "auto" : "hidden", this.scrollContainer.classList.toggle("noScrollbar", !!this.options.hideScrollbar), this.cursor.style.backgroundColor = `${this.options.cursorColor || this.options.progressColor}`, this.cursor.style.width = `${this.options.cursorWidth}px`, this.audioData = t, this.emit("render"), this.options.splitChannels) for (let e = 0; e < t.numberOfChannels; e++) {
|
|
765
|
+
let n = Object.assign(Object.assign({}, this.options), this.options.splitChannels?.[e]);
|
|
766
|
+
this.renderChannel([t.getChannelData(e)], n, o, e);
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
let e = [t.getChannelData(0)];
|
|
770
|
+
t.numberOfChannels > 1 && e.push(t.getChannelData(1)), this.renderChannel(e, this.options, o, 0);
|
|
771
|
+
}
|
|
772
|
+
Promise.resolve().then((() => this.emit("rendered")));
|
|
773
|
+
}));
|
|
774
|
+
}
|
|
775
|
+
reRender() {
|
|
776
|
+
if (this.unsubscribeOnScroll.forEach(((e) => e())), this.unsubscribeOnScroll = [], !this.audioData) return;
|
|
777
|
+
let { scrollWidth: e } = this.scrollContainer, { right: t } = this.progressWrapper.getBoundingClientRect();
|
|
778
|
+
if (this.render(this.audioData), !this.isScrollable && this.scrollContainer.scrollLeft) this.scrollContainer.scrollLeft = 0;
|
|
779
|
+
else if (this.isScrollable && e !== this.scrollContainer.scrollWidth) {
|
|
780
|
+
let { right: e } = this.progressWrapper.getBoundingClientRect(), n = function(e) {
|
|
781
|
+
let t = 2 * e;
|
|
782
|
+
return (t < 0 ? Math.floor(t) : Math.ceil(t)) / 2;
|
|
783
|
+
}(e - t);
|
|
784
|
+
this.scrollContainer.scrollLeft += n;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
zoom(e) {
|
|
788
|
+
this.options.minPxPerSec = e, this.reRender();
|
|
789
|
+
}
|
|
790
|
+
scrollIntoView(e, t = !1) {
|
|
791
|
+
let { scrollLeft: n, scrollWidth: r, clientWidth: i } = this.scrollContainer, a = e * r, o = n, s = n + i, c = i / 2;
|
|
792
|
+
if (this.isDragging) a + 30 > s ? this.scrollContainer.scrollLeft += 30 : a - 30 < o && (this.scrollContainer.scrollLeft -= 30);
|
|
793
|
+
else {
|
|
794
|
+
(a < o || a > s) && (this.scrollContainer.scrollLeft = a - (this.options.autoCenter ? c : 0));
|
|
795
|
+
let e = a - n - c;
|
|
796
|
+
if (t && this.options.autoCenter && e > 0) {
|
|
797
|
+
let t = this.audioData?.duration;
|
|
798
|
+
if (t === void 0 || t <= 0) return void (this.scrollContainer.scrollLeft += e);
|
|
799
|
+
let n = r / t;
|
|
800
|
+
this.scrollContainer.scrollLeft += n <= 600 ? Math.min(e, 10) : e;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
renderProgress(e, t) {
|
|
805
|
+
if (isNaN(e)) return;
|
|
806
|
+
let n = 100 * e;
|
|
807
|
+
this.canvasWrapper.style.clipPath = `polygon(${n}% 0%, 100% 0%, 100% 100%, ${n}% 100%)`, this.progressWrapper.style.width = `${n}%`, this.cursor.style.left = `${n}%`, this.cursor.style.transform = this.options.cursorWidth ? `translateX(-${e * this.options.cursorWidth}px)` : "", this.isScrollable && this.options.autoScroll && this.audioData && this.audioData.duration > 0 && this.scrollIntoView(e, t);
|
|
808
|
+
}
|
|
809
|
+
exportImage(t, n, r) {
|
|
810
|
+
return e(this, void 0, void 0, (function* () {
|
|
811
|
+
let e = this.canvasWrapper.querySelectorAll("canvas");
|
|
812
|
+
if (!e.length) throw Error("No waveform data");
|
|
813
|
+
if (r === "dataURL") {
|
|
814
|
+
let r = Array.from(e).map(((e) => e.toDataURL(t, n)));
|
|
815
|
+
return Promise.resolve(r);
|
|
816
|
+
}
|
|
817
|
+
return Promise.all(Array.from(e).map(((e) => new Promise(((r, i) => {
|
|
818
|
+
e.toBlob(((e) => {
|
|
819
|
+
e ? r(e) : i(/* @__PURE__ */ Error("Could not export image"));
|
|
820
|
+
}), t, n);
|
|
821
|
+
})))));
|
|
822
|
+
}));
|
|
823
|
+
}
|
|
824
|
+
}, b = class extends t {
|
|
825
|
+
constructor() {
|
|
826
|
+
super(...arguments), this.animationFrameId = null, this.isRunning = !1;
|
|
827
|
+
}
|
|
828
|
+
start() {
|
|
829
|
+
if (this.isRunning) return;
|
|
830
|
+
this.isRunning = !0;
|
|
831
|
+
let e = () => {
|
|
832
|
+
this.isRunning && (this.emit("tick"), this.animationFrameId = requestAnimationFrame(e));
|
|
833
|
+
};
|
|
834
|
+
e();
|
|
835
|
+
}
|
|
836
|
+
stop() {
|
|
837
|
+
this.isRunning = !1, this.animationFrameId !== null && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null);
|
|
838
|
+
}
|
|
839
|
+
destroy() {
|
|
840
|
+
this.stop();
|
|
841
|
+
}
|
|
842
|
+
}, x = class extends t {
|
|
843
|
+
constructor(e = new AudioContext()) {
|
|
844
|
+
super(), this.bufferNode = null, this.playStartTime = 0, this.playbackPosition = 0, this._muted = !1, this._playbackRate = 1, this._duration = void 0, this.buffer = null, this.currentSrc = "", this.paused = !0, this.crossOrigin = null, this.seeking = !1, this.autoplay = !1, this.addEventListener = this.on, this.removeEventListener = this.un, this.audioContext = e, this.gainNode = this.audioContext.createGain(), this.gainNode.connect(this.audioContext.destination);
|
|
845
|
+
}
|
|
846
|
+
load() {
|
|
847
|
+
return e(this, void 0, void 0, (function* () {}));
|
|
848
|
+
}
|
|
849
|
+
get src() {
|
|
850
|
+
return this.currentSrc;
|
|
851
|
+
}
|
|
852
|
+
set src(e) {
|
|
853
|
+
if (this.currentSrc = e, this._duration = void 0, !e) return this.buffer = null, void this.emit("emptied");
|
|
854
|
+
fetch(e).then(((t) => {
|
|
855
|
+
if (t.status >= 400) throw Error(`Failed to fetch ${e}: ${t.status} (${t.statusText})`);
|
|
856
|
+
return t.arrayBuffer();
|
|
857
|
+
})).then(((t) => this.currentSrc === e ? this.audioContext.decodeAudioData(t) : null)).then(((t) => {
|
|
858
|
+
this.currentSrc === e && (this.buffer = t, this.emit("loadedmetadata"), this.emit("canplay"), this.autoplay && this.play());
|
|
859
|
+
})).catch(((e) => {
|
|
860
|
+
console.error("WebAudioPlayer load error:", e);
|
|
861
|
+
}));
|
|
862
|
+
}
|
|
863
|
+
_play() {
|
|
864
|
+
if (!this.paused) return;
|
|
865
|
+
this.paused = !1, this.bufferNode && (this.bufferNode.onended = null, this.bufferNode.disconnect()), this.bufferNode = this.audioContext.createBufferSource(), this.buffer && (this.bufferNode.buffer = this.buffer), this.bufferNode.playbackRate.value = this._playbackRate, this.bufferNode.connect(this.gainNode);
|
|
866
|
+
let e = this.playbackPosition;
|
|
867
|
+
(e >= this.duration || e < 0) && (e = 0, this.playbackPosition = 0), this.bufferNode.start(this.audioContext.currentTime, e), this.playStartTime = this.audioContext.currentTime, this.bufferNode.onended = () => {
|
|
868
|
+
this.currentTime >= this.duration && (this.pause(), this.emit("ended"));
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
_pause() {
|
|
872
|
+
var e;
|
|
873
|
+
this.paused = !0, (e = this.bufferNode) == null || e.stop(), this.playbackPosition += (this.audioContext.currentTime - this.playStartTime) * this._playbackRate;
|
|
874
|
+
}
|
|
875
|
+
play() {
|
|
876
|
+
return e(this, void 0, void 0, (function* () {
|
|
877
|
+
this.paused && (this._play(), this.emit("play"));
|
|
878
|
+
}));
|
|
879
|
+
}
|
|
880
|
+
pause() {
|
|
881
|
+
this.paused || (this._pause(), this.emit("pause"));
|
|
882
|
+
}
|
|
883
|
+
stopAt(e) {
|
|
884
|
+
let t = e - this.currentTime, n = this.bufferNode;
|
|
885
|
+
n?.stop(this.audioContext.currentTime + t), n?.addEventListener("ended", (() => {
|
|
886
|
+
n === this.bufferNode && (this.bufferNode = null, this.pause());
|
|
887
|
+
}), { once: !0 });
|
|
888
|
+
}
|
|
889
|
+
setSinkId(t) {
|
|
890
|
+
return e(this, void 0, void 0, (function* () {
|
|
891
|
+
return this.audioContext.setSinkId(t);
|
|
892
|
+
}));
|
|
893
|
+
}
|
|
894
|
+
get playbackRate() {
|
|
895
|
+
return this._playbackRate;
|
|
896
|
+
}
|
|
897
|
+
set playbackRate(e) {
|
|
898
|
+
let t = !this.paused;
|
|
899
|
+
t && this._pause(), this._playbackRate = e, t && this._play(), this.bufferNode && (this.bufferNode.playbackRate.value = e);
|
|
900
|
+
}
|
|
901
|
+
get currentTime() {
|
|
902
|
+
return this.paused ? this.playbackPosition : this.playbackPosition + (this.audioContext.currentTime - this.playStartTime) * this._playbackRate;
|
|
903
|
+
}
|
|
904
|
+
set currentTime(e) {
|
|
905
|
+
let t = !this.paused;
|
|
906
|
+
t && this._pause(), this.playbackPosition = e, t && this._play(), this.emit("seeking"), this.emit("timeupdate");
|
|
907
|
+
}
|
|
908
|
+
get duration() {
|
|
909
|
+
return this._duration ?? (this.buffer?.duration || 0);
|
|
910
|
+
}
|
|
911
|
+
set duration(e) {
|
|
912
|
+
this._duration = e;
|
|
913
|
+
}
|
|
914
|
+
get volume() {
|
|
915
|
+
return this.gainNode.gain.value;
|
|
916
|
+
}
|
|
917
|
+
set volume(e) {
|
|
918
|
+
this.gainNode.gain.value = e, this.emit("volumechange");
|
|
919
|
+
}
|
|
920
|
+
get muted() {
|
|
921
|
+
return this._muted;
|
|
922
|
+
}
|
|
923
|
+
set muted(e) {
|
|
924
|
+
this._muted !== e && (this._muted = e, this._muted ? this.gainNode.disconnect() : this.gainNode.connect(this.audioContext.destination));
|
|
925
|
+
}
|
|
926
|
+
canPlayType(e) {
|
|
927
|
+
return /^(audio|video)\//.test(e);
|
|
928
|
+
}
|
|
929
|
+
getGainNode() {
|
|
930
|
+
return this.gainNode;
|
|
931
|
+
}
|
|
932
|
+
getChannelData() {
|
|
933
|
+
let e = [];
|
|
934
|
+
if (!this.buffer) return e;
|
|
935
|
+
let t = this.buffer.numberOfChannels;
|
|
936
|
+
for (let n = 0; n < t; n++) e.push(this.buffer.getChannelData(n));
|
|
937
|
+
return e;
|
|
938
|
+
}
|
|
939
|
+
removeAttribute(e) {
|
|
940
|
+
switch (e) {
|
|
941
|
+
case "src":
|
|
942
|
+
this.src = "";
|
|
943
|
+
break;
|
|
944
|
+
case "playbackRate":
|
|
945
|
+
this.playbackRate = 0;
|
|
946
|
+
break;
|
|
947
|
+
case "currentTime":
|
|
948
|
+
this.currentTime = 0;
|
|
949
|
+
break;
|
|
950
|
+
case "duration":
|
|
951
|
+
this.duration = 0;
|
|
952
|
+
break;
|
|
953
|
+
case "volume":
|
|
954
|
+
this.volume = 0;
|
|
955
|
+
break;
|
|
956
|
+
case "muted": this.muted = !1;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}, S = {
|
|
960
|
+
waveColor: "#999",
|
|
961
|
+
progressColor: "#555",
|
|
962
|
+
cursorWidth: 1,
|
|
963
|
+
minPxPerSec: 0,
|
|
964
|
+
fillParent: !0,
|
|
965
|
+
interact: !0,
|
|
966
|
+
dragToSeek: !1,
|
|
967
|
+
autoScroll: !0,
|
|
968
|
+
autoCenter: !0,
|
|
969
|
+
sampleRate: 8e3
|
|
970
|
+
}, C = class t extends u {
|
|
971
|
+
static create(e) {
|
|
972
|
+
return new t(e);
|
|
973
|
+
}
|
|
974
|
+
getState() {
|
|
975
|
+
return this.wavesurferState;
|
|
976
|
+
}
|
|
977
|
+
getRenderer() {
|
|
978
|
+
return this.renderer;
|
|
979
|
+
}
|
|
980
|
+
constructor(e) {
|
|
981
|
+
let t = e.media || (e.backend === "WebAudio" ? new x() : void 0);
|
|
982
|
+
super({
|
|
983
|
+
media: t,
|
|
984
|
+
mediaControls: e.mediaControls,
|
|
985
|
+
autoplay: e.autoplay,
|
|
986
|
+
playbackRate: e.audioRate
|
|
987
|
+
}), this.plugins = [], this.decodedData = null, this.stopAtPosition = null, this.subscriptions = [], this.mediaSubscriptions = [], this.abortController = null, this.reactiveCleanups = [], this.options = Object.assign({}, S, e);
|
|
988
|
+
let { state: n, actions: r } = function(e) {
|
|
989
|
+
let t = e?.currentTime ?? s(0), n = e?.duration ?? s(0), r = e?.isPlaying ?? s(!1), i = e?.isSeeking ?? s(!1), a = e?.volume ?? s(1), o = e?.playbackRate ?? s(1), l = s(null), u = s(null), d = s(""), f = s(0), p = s(0), m = c((() => !r.value), [r]), h = c((() => l.value !== null), [l]);
|
|
990
|
+
return {
|
|
991
|
+
state: {
|
|
992
|
+
currentTime: t,
|
|
993
|
+
duration: n,
|
|
994
|
+
isPlaying: r,
|
|
995
|
+
isPaused: m,
|
|
996
|
+
isSeeking: i,
|
|
997
|
+
volume: a,
|
|
998
|
+
playbackRate: o,
|
|
999
|
+
audioBuffer: l,
|
|
1000
|
+
peaks: u,
|
|
1001
|
+
url: d,
|
|
1002
|
+
zoom: f,
|
|
1003
|
+
scrollPosition: p,
|
|
1004
|
+
canPlay: h,
|
|
1005
|
+
isReady: c((() => h.value && n.value > 0), [h, n]),
|
|
1006
|
+
progress: c((() => t.value), [t]),
|
|
1007
|
+
progressPercent: c((() => n.value > 0 ? t.value / n.value : 0), [t, n])
|
|
1008
|
+
},
|
|
1009
|
+
actions: {
|
|
1010
|
+
setCurrentTime: (e) => {
|
|
1011
|
+
let r = Math.max(0, Math.min(n.value || Infinity, e));
|
|
1012
|
+
t.set(r);
|
|
1013
|
+
},
|
|
1014
|
+
setDuration: (e) => {
|
|
1015
|
+
n.set(Math.max(0, e));
|
|
1016
|
+
},
|
|
1017
|
+
setPlaying: (e) => {
|
|
1018
|
+
r.set(e);
|
|
1019
|
+
},
|
|
1020
|
+
setSeeking: (e) => {
|
|
1021
|
+
i.set(e);
|
|
1022
|
+
},
|
|
1023
|
+
setVolume: (e) => {
|
|
1024
|
+
let t = Math.max(0, Math.min(1, e));
|
|
1025
|
+
a.set(t);
|
|
1026
|
+
},
|
|
1027
|
+
setPlaybackRate: (e) => {
|
|
1028
|
+
let t = Math.max(.1, Math.min(16, e));
|
|
1029
|
+
o.set(t);
|
|
1030
|
+
},
|
|
1031
|
+
setAudioBuffer: (e) => {
|
|
1032
|
+
l.set(e), e && n.set(e.duration);
|
|
1033
|
+
},
|
|
1034
|
+
setPeaks: (e) => {
|
|
1035
|
+
u.set(e);
|
|
1036
|
+
},
|
|
1037
|
+
setUrl: (e) => {
|
|
1038
|
+
d.set(e);
|
|
1039
|
+
},
|
|
1040
|
+
setZoom: (e) => {
|
|
1041
|
+
f.set(Math.max(0, e));
|
|
1042
|
+
},
|
|
1043
|
+
setScrollPosition: (e) => {
|
|
1044
|
+
p.set(Math.max(0, e));
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
};
|
|
1048
|
+
}({
|
|
1049
|
+
isPlaying: this.isPlayingSignal,
|
|
1050
|
+
currentTime: this.currentTimeSignal,
|
|
1051
|
+
duration: this.durationSignal,
|
|
1052
|
+
volume: this.volumeSignal,
|
|
1053
|
+
playbackRate: this.playbackRateSignal,
|
|
1054
|
+
isSeeking: this.seekingSignal
|
|
1055
|
+
});
|
|
1056
|
+
this.wavesurferState = n, this.wavesurferActions = r, this.timer = new b();
|
|
1057
|
+
let i = t ? void 0 : this.getMediaElement();
|
|
1058
|
+
this.renderer = new y(this.options, i), this.initPlayerEvents(), this.initRendererEvents(), this.initTimerEvents(), this.initReactiveState(), this.initPlugins();
|
|
1059
|
+
let a = this.options.url || this.getSrc() || "";
|
|
1060
|
+
Promise.resolve().then((() => {
|
|
1061
|
+
this.emit("init");
|
|
1062
|
+
let { peaks: e, duration: t } = this.options;
|
|
1063
|
+
(a || e && t) && this.load(a, e, t).catch(((e) => {
|
|
1064
|
+
this.emit("error", e instanceof Error ? e : Error(String(e)));
|
|
1065
|
+
}));
|
|
1066
|
+
}));
|
|
1067
|
+
}
|
|
1068
|
+
updateProgress(e = this.getCurrentTime()) {
|
|
1069
|
+
return this.renderer.renderProgress(e / this.getDuration(), this.isPlaying()), e;
|
|
1070
|
+
}
|
|
1071
|
+
initTimerEvents() {
|
|
1072
|
+
this.subscriptions.push(this.timer.on("tick", (() => {
|
|
1073
|
+
if (!this.isSeeking()) {
|
|
1074
|
+
let e = this.updateProgress();
|
|
1075
|
+
this.emit("timeupdate", e), this.emit("audioprocess", e), this.stopAtPosition != null && this.isPlaying() && e >= this.stopAtPosition && this.pause();
|
|
1076
|
+
}
|
|
1077
|
+
})));
|
|
1078
|
+
}
|
|
1079
|
+
initReactiveState() {
|
|
1080
|
+
this.reactiveCleanups.push(function(e, t) {
|
|
1081
|
+
let n = [];
|
|
1082
|
+
n.push(l((() => {
|
|
1083
|
+
let n = e.isPlaying.value;
|
|
1084
|
+
t.emit(n ? "play" : "pause");
|
|
1085
|
+
}), [e.isPlaying])), n.push(l((() => {
|
|
1086
|
+
let n = e.currentTime.value;
|
|
1087
|
+
t.emit("timeupdate", n), e.isPlaying.value && t.emit("audioprocess", n);
|
|
1088
|
+
}), [e.currentTime, e.isPlaying])), n.push(l((() => {
|
|
1089
|
+
e.isSeeking.value && t.emit("seeking", e.currentTime.value);
|
|
1090
|
+
}), [e.isSeeking, e.currentTime]));
|
|
1091
|
+
let r = !1;
|
|
1092
|
+
n.push(l((() => {
|
|
1093
|
+
e.isReady.value && !r && (r = !0, t.emit("ready", e.duration.value));
|
|
1094
|
+
}), [e.isReady, e.duration]));
|
|
1095
|
+
let i = !1;
|
|
1096
|
+
return n.push(l((() => {
|
|
1097
|
+
let n = e.isPlaying.value, r = e.currentTime.value, a = e.duration.value, o = a > 0 && r >= a;
|
|
1098
|
+
i && !n && o && t.emit("finish"), i = n && o;
|
|
1099
|
+
}), [
|
|
1100
|
+
e.isPlaying,
|
|
1101
|
+
e.currentTime,
|
|
1102
|
+
e.duration
|
|
1103
|
+
])), n.push(l((() => {
|
|
1104
|
+
let n = e.zoom.value;
|
|
1105
|
+
n > 0 && t.emit("zoom", n);
|
|
1106
|
+
}), [e.zoom])), () => {
|
|
1107
|
+
n.forEach(((e) => e()));
|
|
1108
|
+
};
|
|
1109
|
+
}(this.wavesurferState, { emit: this.emit.bind(this) }));
|
|
1110
|
+
}
|
|
1111
|
+
initPlayerEvents() {
|
|
1112
|
+
this.isPlaying() && (this.emit("play"), this.timer.start()), this.mediaSubscriptions.push(this.onMediaEvent("timeupdate", (() => {
|
|
1113
|
+
let e = this.updateProgress();
|
|
1114
|
+
this.emit("timeupdate", e);
|
|
1115
|
+
})), this.onMediaEvent("play", (() => {
|
|
1116
|
+
this.emit("play"), this.timer.start();
|
|
1117
|
+
})), this.onMediaEvent("pause", (() => {
|
|
1118
|
+
this.emit("pause"), this.timer.stop(), this.stopAtPosition = null;
|
|
1119
|
+
})), this.onMediaEvent("emptied", (() => {
|
|
1120
|
+
this.timer.stop(), this.stopAtPosition = null;
|
|
1121
|
+
})), this.onMediaEvent("ended", (() => {
|
|
1122
|
+
this.emit("timeupdate", this.getDuration()), this.emit("finish"), this.stopAtPosition = null;
|
|
1123
|
+
})), this.onMediaEvent("seeking", (() => {
|
|
1124
|
+
this.emit("seeking", this.getCurrentTime());
|
|
1125
|
+
})), this.onMediaEvent("error", (() => {
|
|
1126
|
+
this.emit("error", this.getMediaElement().error ?? /* @__PURE__ */ Error("Media error")), this.stopAtPosition = null;
|
|
1127
|
+
})));
|
|
1128
|
+
}
|
|
1129
|
+
initRendererEvents() {
|
|
1130
|
+
this.subscriptions.push(this.renderer.on("click", ((e, t) => {
|
|
1131
|
+
this.options.interact && (this.seekTo(e), this.emit("interaction", e * this.getDuration()), this.emit("click", e, t));
|
|
1132
|
+
})), this.renderer.on("dblclick", ((e, t) => {
|
|
1133
|
+
this.emit("dblclick", e, t);
|
|
1134
|
+
})), this.renderer.on("scroll", ((e, t, n, r) => {
|
|
1135
|
+
let i = this.getDuration();
|
|
1136
|
+
this.emit("scroll", e * i, t * i, n, r);
|
|
1137
|
+
})), this.renderer.on("render", (() => {
|
|
1138
|
+
this.emit("redraw");
|
|
1139
|
+
})), this.renderer.on("rendered", (() => {
|
|
1140
|
+
this.emit("redrawcomplete");
|
|
1141
|
+
})), this.renderer.on("dragstart", ((e) => {
|
|
1142
|
+
this.emit("dragstart", e);
|
|
1143
|
+
})), this.renderer.on("dragend", ((e) => {
|
|
1144
|
+
this.emit("dragend", e);
|
|
1145
|
+
})), this.renderer.on("resize", (() => {
|
|
1146
|
+
this.emit("resize");
|
|
1147
|
+
})));
|
|
1148
|
+
{
|
|
1149
|
+
let e, t = this.renderer.on("drag", ((t) => {
|
|
1150
|
+
if (!this.options.interact) return;
|
|
1151
|
+
this.renderer.renderProgress(t), clearTimeout(e);
|
|
1152
|
+
let n = 0, r = this.options.dragToSeek;
|
|
1153
|
+
this.isPlaying() ? n = 0 : !0 === r ? n = 200 : r && typeof r == "object" && (n = r.debounceTime ?? 200), e = setTimeout((() => {
|
|
1154
|
+
this.seekTo(t);
|
|
1155
|
+
}), n), this.emit("interaction", t * this.getDuration()), this.emit("drag", t);
|
|
1156
|
+
}));
|
|
1157
|
+
this.subscriptions.push((() => {
|
|
1158
|
+
clearTimeout(e), t();
|
|
1159
|
+
}));
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
initPlugins() {
|
|
1163
|
+
var e;
|
|
1164
|
+
(e = this.options.plugins) != null && e.length && this.options.plugins.forEach(((e) => {
|
|
1165
|
+
this.registerPlugin(e);
|
|
1166
|
+
}));
|
|
1167
|
+
}
|
|
1168
|
+
unsubscribePlayerEvents() {
|
|
1169
|
+
this.mediaSubscriptions.forEach(((e) => e())), this.mediaSubscriptions = [];
|
|
1170
|
+
}
|
|
1171
|
+
setOptions(e) {
|
|
1172
|
+
this.options = Object.assign({}, this.options, e), e.duration && !e.peaks && (this.decodedData = n.createBuffer(this.exportPeaks(), e.duration)), e.peaks && e.duration && (this.decodedData = n.createBuffer(e.peaks, e.duration)), this.renderer.setOptions(this.options), e.audioRate && this.setPlaybackRate(e.audioRate), e.mediaControls != null && (this.getMediaElement().controls = e.mediaControls);
|
|
1173
|
+
}
|
|
1174
|
+
registerPlugin(e) {
|
|
1175
|
+
if (this.plugins.includes(e)) return e;
|
|
1176
|
+
e._init(this), this.plugins.push(e);
|
|
1177
|
+
let t = e.once("destroy", (() => {
|
|
1178
|
+
this.plugins = this.plugins.filter(((t) => t !== e)), this.subscriptions = this.subscriptions.filter(((e) => e !== t));
|
|
1179
|
+
}));
|
|
1180
|
+
return this.subscriptions.push(t), e;
|
|
1181
|
+
}
|
|
1182
|
+
unregisterPlugin(e) {
|
|
1183
|
+
this.plugins = this.plugins.filter(((t) => t !== e)), e.destroy();
|
|
1184
|
+
}
|
|
1185
|
+
getWrapper() {
|
|
1186
|
+
return this.renderer.getWrapper();
|
|
1187
|
+
}
|
|
1188
|
+
getWidth() {
|
|
1189
|
+
return this.renderer.getWidth();
|
|
1190
|
+
}
|
|
1191
|
+
getScroll() {
|
|
1192
|
+
return this.renderer.getScroll();
|
|
1193
|
+
}
|
|
1194
|
+
setScroll(e) {
|
|
1195
|
+
return this.renderer.setScroll(e);
|
|
1196
|
+
}
|
|
1197
|
+
setScrollTime(e) {
|
|
1198
|
+
let t = e / this.getDuration();
|
|
1199
|
+
this.renderer.setScrollPercentage(t);
|
|
1200
|
+
}
|
|
1201
|
+
getActivePlugins() {
|
|
1202
|
+
return this.plugins;
|
|
1203
|
+
}
|
|
1204
|
+
loadAudio(t, r, i, a) {
|
|
1205
|
+
return e(this, void 0, void 0, (function* () {
|
|
1206
|
+
var e;
|
|
1207
|
+
if (this.emit("load", t), !this.options.media && this.isPlaying() && this.pause(), this.decodedData = null, this.stopAtPosition = null, (e = this.abortController) == null || e.abort(), this.abortController = null, !r && !i) {
|
|
1208
|
+
let e = this.options.fetchParams || {};
|
|
1209
|
+
window.AbortController && !e.signal && (this.abortController = new AbortController(), e.signal = this.abortController.signal), r = yield o.fetchBlob(t, (e) => this.emit("loading", e), e);
|
|
1210
|
+
let n = this.options.blobMimeType;
|
|
1211
|
+
n && (r = new Blob([r], { type: n }));
|
|
1212
|
+
}
|
|
1213
|
+
this.setSrc(t, r);
|
|
1214
|
+
let s = yield new Promise(((e) => {
|
|
1215
|
+
let t = a || this.getDuration();
|
|
1216
|
+
t ? e(t) : this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata", (() => e(this.getDuration())), { once: !0 }));
|
|
1217
|
+
}));
|
|
1218
|
+
if (!t && !r) {
|
|
1219
|
+
let e = this.getMediaElement();
|
|
1220
|
+
e instanceof x && (e.duration = s);
|
|
1221
|
+
}
|
|
1222
|
+
if (i) this.decodedData = n.createBuffer(i, s || 0);
|
|
1223
|
+
else if (r) {
|
|
1224
|
+
let e = yield r.arrayBuffer();
|
|
1225
|
+
this.decodedData = yield n.decode(e, this.options.sampleRate);
|
|
1226
|
+
}
|
|
1227
|
+
this.decodedData && (this.emit("decode", this.getDuration()), this.renderer.render(this.decodedData)), this.emit("ready", this.getDuration());
|
|
1228
|
+
}));
|
|
1229
|
+
}
|
|
1230
|
+
load(t, n, r) {
|
|
1231
|
+
return e(this, void 0, void 0, (function* () {
|
|
1232
|
+
try {
|
|
1233
|
+
return yield this.loadAudio(t, void 0, n, r);
|
|
1234
|
+
} catch (e) {
|
|
1235
|
+
throw this.emit("error", e), e;
|
|
1236
|
+
}
|
|
1237
|
+
}));
|
|
1238
|
+
}
|
|
1239
|
+
loadBlob(t, n, r) {
|
|
1240
|
+
return e(this, void 0, void 0, (function* () {
|
|
1241
|
+
try {
|
|
1242
|
+
return yield this.loadAudio("", t, n, r);
|
|
1243
|
+
} catch (e) {
|
|
1244
|
+
throw this.emit("error", e), e;
|
|
1245
|
+
}
|
|
1246
|
+
}));
|
|
1247
|
+
}
|
|
1248
|
+
zoom(e) {
|
|
1249
|
+
if (!this.decodedData) throw Error("No audio loaded");
|
|
1250
|
+
this.renderer.zoom(e), this.emit("zoom", e);
|
|
1251
|
+
}
|
|
1252
|
+
getDecodedData() {
|
|
1253
|
+
return this.decodedData;
|
|
1254
|
+
}
|
|
1255
|
+
exportPeaks({ channels: e = 2, maxLength: t = 8e3, precision: n = 1e4 } = {}) {
|
|
1256
|
+
if (!this.decodedData) throw Error("The audio has not been decoded yet");
|
|
1257
|
+
let r = Math.min(e, this.decodedData.numberOfChannels), i = [];
|
|
1258
|
+
for (let e = 0; e < r; e++) {
|
|
1259
|
+
let r = this.decodedData.getChannelData(e), a = [], o = r.length / t;
|
|
1260
|
+
for (let e = 0; e < t; e++) {
|
|
1261
|
+
let t = r.slice(Math.floor(e * o), Math.ceil((e + 1) * o)), i = 0;
|
|
1262
|
+
for (let e = 0; e < t.length; e++) {
|
|
1263
|
+
let n = t[e];
|
|
1264
|
+
Math.abs(n) > Math.abs(i) && (i = n);
|
|
1265
|
+
}
|
|
1266
|
+
a.push(Math.round(i * n) / n);
|
|
1267
|
+
}
|
|
1268
|
+
i.push(a);
|
|
1269
|
+
}
|
|
1270
|
+
return i;
|
|
1271
|
+
}
|
|
1272
|
+
getDuration() {
|
|
1273
|
+
let e = super.getDuration() || 0;
|
|
1274
|
+
return e !== 0 && e !== Infinity || !this.decodedData || (e = this.decodedData.duration), e;
|
|
1275
|
+
}
|
|
1276
|
+
toggleInteraction(e) {
|
|
1277
|
+
this.options.interact = e;
|
|
1278
|
+
}
|
|
1279
|
+
setTime(e) {
|
|
1280
|
+
this.stopAtPosition = null, super.setTime(e), this.updateProgress(e), this.emit("timeupdate", e);
|
|
1281
|
+
}
|
|
1282
|
+
seekTo(e) {
|
|
1283
|
+
let t = this.getDuration() * e;
|
|
1284
|
+
this.setTime(t);
|
|
1285
|
+
}
|
|
1286
|
+
play(t, n) {
|
|
1287
|
+
let r = Object.create(null, { play: { get: () => super.play } });
|
|
1288
|
+
return e(this, void 0, void 0, (function* () {
|
|
1289
|
+
t != null && this.setTime(t);
|
|
1290
|
+
let e = yield r.play.call(this);
|
|
1291
|
+
return n != null && (this.media instanceof x ? this.media.stopAt(n) : this.stopAtPosition = n), e;
|
|
1292
|
+
}));
|
|
1293
|
+
}
|
|
1294
|
+
playPause() {
|
|
1295
|
+
return e(this, void 0, void 0, (function* () {
|
|
1296
|
+
return this.isPlaying() ? this.pause() : this.play();
|
|
1297
|
+
}));
|
|
1298
|
+
}
|
|
1299
|
+
stop() {
|
|
1300
|
+
this.pause(), this.setTime(0);
|
|
1301
|
+
}
|
|
1302
|
+
skip(e) {
|
|
1303
|
+
this.setTime(this.getCurrentTime() + e);
|
|
1304
|
+
}
|
|
1305
|
+
empty() {
|
|
1306
|
+
this.load("", [[0]], .001);
|
|
1307
|
+
}
|
|
1308
|
+
setMediaElement(e) {
|
|
1309
|
+
this.unsubscribePlayerEvents(), super.setMediaElement(e), this.initPlayerEvents();
|
|
1310
|
+
}
|
|
1311
|
+
exportImage() {
|
|
1312
|
+
return e(this, arguments, void 0, (function* (e = "image/png", t = 1, n = "dataURL") {
|
|
1313
|
+
return this.renderer.exportImage(e, t, n);
|
|
1314
|
+
}));
|
|
1315
|
+
}
|
|
1316
|
+
destroy() {
|
|
1317
|
+
var e;
|
|
1318
|
+
this.emit("destroy"), (e = this.abortController) == null || e.abort(), this.plugins.forEach(((e) => e.destroy())), this.subscriptions.forEach(((e) => e())), this.unsubscribePlayerEvents(), this.reactiveCleanups.forEach(((e) => e())), this.reactiveCleanups = [], this.timer.destroy(), this.renderer.destroy(), super.destroy();
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
C.BasePlugin = class extends t {
|
|
1322
|
+
constructor(e) {
|
|
1323
|
+
super(), this.subscriptions = [], this.isDestroyed = !1, this.options = e;
|
|
1324
|
+
}
|
|
1325
|
+
onInit() {}
|
|
1326
|
+
_init(e) {
|
|
1327
|
+
this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = e, this.onInit();
|
|
1328
|
+
}
|
|
1329
|
+
destroy() {
|
|
1330
|
+
this.emit("destroy"), this.subscriptions.forEach(((e) => e())), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
|
|
1331
|
+
}
|
|
1332
|
+
}, C.dom = a;
|
|
1333
|
+
//#endregion
|
|
1334
|
+
export { C as t };
|
|
1335
|
+
|
|
1336
|
+
//# sourceMappingURL=widget-react-CZs0xRrr.js.map
|