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