@meersagor/wavesurfer-vue 1.0.0 → 2.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.
@@ -1,137 +1,953 @@
1
- import { ref as v, onMounted as w, onUnmounted as S, defineComponent as T, getCurrentInstance as M, openBlock as A, createElementBlock as O, computed as y } from "vue";
2
- import E from "wavesurfer.js";
3
- const P = ({ containerRef: n, options: e }) => {
4
- const t = v(null), i = () => {
5
- n.value && (t.value = E.create({
6
- container: n.value,
7
- ...e
1
+ import { ref as I, onMounted as D, onUnmounted as st, defineComponent as zt, getCurrentInstance as Gt, openBlock as Xt, createElementBlock as Nt } from "vue";
2
+ import Ot from "wavesurfer.js";
3
+ const nt = ({ containerRef: o, options: t }) => {
4
+ const e = I(null), i = () => {
5
+ o.value && (e.value = Ot.create({
6
+ container: o.value,
7
+ ...t
8
8
  }));
9
9
  }, s = () => {
10
- t.value && (t.value.destroy(), t.value = null);
10
+ e.value && (e.value.destroy(), e.value = null);
11
11
  };
12
- return w(() => {
12
+ return D(() => {
13
13
  i();
14
- }), S(() => {
14
+ }), st(() => {
15
15
  s();
16
- }), { waveSurfer: t };
17
- }, I = (n) => {
18
- const e = v(!1), t = v(!1), i = v(0), s = v(0), r = () => {
19
- e.value = !1, t.value = !1, i.value = 0;
20
- }, o = (m) => {
21
- e.value = !0, t.value = !1, i.value = 0, s.value = m;
22
- }, a = () => {
23
- t.value = !0;
24
- }, d = () => {
25
- t.value = !1;
26
- }, h = () => {
27
- n.value && (i.value = n.value.getCurrentTime());
16
+ }), { waveSurfer: e };
17
+ }, Yt = (o) => {
18
+ const t = I(!1), e = I(!1), i = I(0), s = I(0), r = () => {
19
+ t.value = !1, e.value = !1, i.value = 0;
20
+ }, n = (d) => {
21
+ t.value = !0, e.value = !1, i.value = 0, s.value = d;
28
22
  }, l = () => {
29
- e.value = !1, t.value = !1;
23
+ e.value = !0;
24
+ }, h = () => {
25
+ e.value = !1;
26
+ }, c = () => {
27
+ o.value && (i.value = o.value.getCurrentTime());
28
+ }, a = () => {
29
+ t.value = !1, e.value = !1;
30
30
  };
31
- return w(() => {
32
- n.value && (n.value.on("load", r), n.value.on("ready", o), n.value.on("play", a), n.value.on("pause", d), n.value.on("timeupdate", h), n.value.on("destroy", l));
33
- }), S(() => {
34
- n.value && n.value.unAll();
31
+ return D(() => {
32
+ o.value && (o.value.on("load", r), o.value.on("ready", n), o.value.on("play", l), o.value.on("pause", h), o.value.on("timeupdate", c), o.value.on("destroy", a));
33
+ }), st(() => {
34
+ o.value && o.value.unAll();
35
35
  }), {
36
- isReady: e,
37
- isPlaying: t,
36
+ isReady: t,
37
+ isPlaying: e,
38
38
  currentTime: i,
39
39
  totalDuration: s
40
40
  };
41
- }, k = ({ containerRef: n, options: e }) => {
42
- const { waveSurfer: t } = P({ containerRef: n, options: e }), { isReady: i, totalDuration: s, isPlaying: r, currentTime: o } = I(t);
41
+ }, Vt = ({ containerRef: o, options: t }) => {
42
+ const { waveSurfer: e } = nt({ containerRef: o, options: t }), { isReady: i, totalDuration: s, isPlaying: r, currentTime: n } = Yt(e);
43
43
  return {
44
- waveSurfer: t,
44
+ waveSurfer: e,
45
45
  isReady: i,
46
46
  totalDuration: s,
47
47
  isPlaying: r,
48
- currentTime: o
48
+ currentTime: n
49
49
  };
50
- }, x = ["audioprocess", "click", "dblclick", "decode", "drag", "finish", "init", "interaction", "load", "loading", "pause", "play", "ready", "redraw", "redrawcomplete", "scroll", "seeking", "timeupdate", "zoom"], U = /* @__PURE__ */ T({
50
+ }, Kt = ["audioprocess", "click", "dblclick", "decode", "drag", "finish", "init", "interaction", "load", "loading", "pause", "play", "ready", "redraw", "redrawcomplete", "scroll", "seeking", "timeupdate", "zoom"], Se = /* @__PURE__ */ zt({
51
51
  __name: "WaveSurferPlayer",
52
52
  props: {
53
53
  options: {}
54
54
  },
55
- setup(n) {
56
- const e = n, t = v(null), { waveSurfer: i } = k({ containerRef: t, options: e.options }), s = M();
57
- return w(() => {
58
- x.forEach((r) => {
59
- i.value?.on(r, (...o) => {
60
- s?.emit(r, ...o);
55
+ setup(o) {
56
+ const t = o, e = I(null), { waveSurfer: i } = Vt({ containerRef: e, options: t.options }), s = Gt();
57
+ return D(() => {
58
+ Kt.forEach((r) => {
59
+ i.value?.on(r, (...n) => {
60
+ s?.emit(r, ...n);
61
61
  });
62
62
  }), s?.emit("waveSurfer", i.value);
63
- }), (r, o) => (A(), O("div", {
63
+ }), (r, n) => (Xt(), Nt("div", {
64
64
  ref_key: "containerRef",
65
- ref: t
65
+ ref: e
66
66
  }, null, 512));
67
67
  }
68
- });
69
- function W(n, e, t, i) {
70
- return new (t || (t = Promise))(function(s, r) {
71
- function o(h) {
72
- try {
73
- d(i.next(h));
74
- } catch (l) {
75
- r(l);
68
+ }), z = (o, t = {}) => {
69
+ const e = I(null);
70
+ return {
71
+ pluginInstance: e,
72
+ createPlugin: (s) => {
73
+ if (s) {
74
+ const r = s.registerPlugin(
75
+ o.create({
76
+ ...t
77
+ })
78
+ );
79
+ r && (e.value = r);
76
80
  }
77
81
  }
78
- function a(h) {
79
- try {
80
- d(i.throw(h));
81
- } catch (l) {
82
- r(l);
83
- }
82
+ };
83
+ }, G = (o, { containerRef: t, options: e, pluginOptions: i = {} }) => {
84
+ const { waveSurfer: s } = nt({ containerRef: t, options: e }), r = I(null);
85
+ return D(() => {
86
+ if (s.value) {
87
+ const n = s.value.registerPlugin(
88
+ o.create({
89
+ ...i
90
+ })
91
+ );
92
+ n && (r.value = n);
84
93
  }
85
- function d(h) {
86
- var l;
87
- h.done ? s(h.value) : (l = h.value, l instanceof t ? l : new t(function(m) {
88
- m(l);
89
- })).then(o, a);
94
+ }), {
95
+ waveSurfer: s,
96
+ pluginInstance: r
97
+ };
98
+ };
99
+ let jt = class {
100
+ constructor() {
101
+ this.listeners = {};
102
+ }
103
+ on(t, e, i) {
104
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
105
+ const s = () => {
106
+ this.un(t, s), this.un(t, e);
107
+ };
108
+ return this.on(t, s), s;
90
109
  }
91
- d((i = i.apply(n, [])).next());
92
- });
110
+ return () => this.un(t, e);
111
+ }
112
+ un(t, e) {
113
+ var i;
114
+ (i = this.listeners[t]) === null || i === void 0 || i.delete(e);
115
+ }
116
+ once(t, e) {
117
+ return this.on(t, e, { once: !0 });
118
+ }
119
+ unAll() {
120
+ this.listeners = {};
121
+ }
122
+ emit(t, ...e) {
123
+ this.listeners[t] && this.listeners[t].forEach((i) => i(...e));
124
+ }
125
+ }, At = class extends jt {
126
+ constructor(t) {
127
+ super(), this.subscriptions = [], this.isDestroyed = !1, this.options = t;
128
+ }
129
+ onInit() {
130
+ }
131
+ _init(t) {
132
+ this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = t, this.onInit();
133
+ }
134
+ destroy() {
135
+ this.emit("destroy"), this.subscriptions.forEach((t) => t()), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
136
+ }
137
+ };
138
+ function rt(o, t) {
139
+ const e = t.xmlns ? document.createElementNS(t.xmlns, o) : document.createElement(o);
140
+ for (const [i, s] of Object.entries(t)) if (i === "children" && s) for (const [r, n] of Object.entries(s)) n instanceof Node ? e.appendChild(n) : typeof n == "string" ? e.appendChild(document.createTextNode(n)) : e.appendChild(rt(r, n));
141
+ else i === "style" ? Object.assign(e.style, s) : i === "textContent" ? e.textContent = s : e.setAttribute(i, s.toString());
142
+ return e;
93
143
  }
94
- class b {
144
+ function H(o, t, e) {
145
+ return rt(o, t || {});
146
+ }
147
+ const Ft = { height: 20, timeOffset: 0, formatTimeCallback: (o) => o / 60 > 1 ? `${Math.floor(o / 60)}:${`${(o = Math.round(o % 60)) < 10 ? "0" : ""}${o}`}` : `${Math.round(1e3 * o) / 1e3}` };
148
+ let ot = class at extends At {
149
+ constructor(t) {
150
+ super(t || {}), this.unsubscribeNotches = [], this.options = Object.assign({}, Ft, t), this.timelineWrapper = this.initTimelineWrapper();
151
+ }
152
+ static create(t) {
153
+ return new at(t);
154
+ }
155
+ onInit() {
156
+ var t;
157
+ if (!this.wavesurfer) throw Error("WaveSurfer is not initialized");
158
+ let e = this.wavesurfer.getWrapper();
159
+ if (this.options.container instanceof HTMLElement) e = this.options.container;
160
+ else if (typeof this.options.container == "string") {
161
+ const i = document.querySelector(this.options.container);
162
+ if (!i) throw Error(`No Timeline container found matching ${this.options.container}`);
163
+ e = i;
164
+ }
165
+ this.options.insertPosition ? (e.firstElementChild || e).insertAdjacentElement(this.options.insertPosition, this.timelineWrapper) : e.appendChild(this.timelineWrapper), this.subscriptions.push(this.wavesurfer.on("redraw", () => this.initTimeline())), (!((t = this.wavesurfer) === null || t === void 0) && t.getDuration() || this.options.duration) && this.initTimeline();
166
+ }
167
+ destroy() {
168
+ this.unsubscribeNotches.forEach((t) => t()), this.unsubscribeNotches = [], this.timelineWrapper.remove(), super.destroy();
169
+ }
170
+ initTimelineWrapper() {
171
+ return H("div", { part: "timeline-wrapper", style: { pointerEvents: "none" } });
172
+ }
173
+ defaultTimeInterval(t) {
174
+ return t >= 25 ? 1 : 5 * t >= 25 ? 5 : 15 * t >= 25 ? 15 : 60 * Math.ceil(0.5 / t);
175
+ }
176
+ defaultPrimaryLabelInterval(t) {
177
+ return t >= 25 ? 10 : 5 * t >= 25 ? 6 : 4;
178
+ }
179
+ defaultSecondaryLabelInterval(t) {
180
+ return t >= 25 ? 5 : 2;
181
+ }
182
+ virtualAppend(t, e, i) {
183
+ let s = !1;
184
+ const r = (h, c) => {
185
+ if (!this.wavesurfer) return;
186
+ const a = i.clientWidth, d = t >= h && t + a < c;
187
+ d !== s && (s = d, d ? e.appendChild(i) : i.remove());
188
+ };
189
+ if (!this.wavesurfer) return;
190
+ const n = this.wavesurfer.getScroll(), l = n + this.wavesurfer.getWidth();
191
+ r(n, l), this.unsubscribeNotches.push(this.wavesurfer.on("scroll", (h, c, a, d) => {
192
+ r(a, d);
193
+ }));
194
+ }
195
+ initTimeline() {
196
+ var t, e, i, s, r, n, l, h;
197
+ this.unsubscribeNotches.forEach((w) => w()), this.unsubscribeNotches = [];
198
+ const c = (i = (e = (t = this.wavesurfer) === null || t === void 0 ? void 0 : t.getDuration()) !== null && e !== void 0 ? e : this.options.duration) !== null && i !== void 0 ? i : 0, a = (((s = this.wavesurfer) === null || s === void 0 ? void 0 : s.getWrapper().scrollWidth) || this.timelineWrapper.scrollWidth) / c, d = (r = this.options.timeInterval) !== null && r !== void 0 ? r : this.defaultTimeInterval(a), u = (n = this.options.primaryLabelInterval) !== null && n !== void 0 ? n : this.defaultPrimaryLabelInterval(a), p = this.options.primaryLabelSpacing, b = (l = this.options.secondaryLabelInterval) !== null && l !== void 0 ? l : this.defaultSecondaryLabelInterval(a), x = this.options.secondaryLabelSpacing, g = this.options.insertPosition === "beforebegin", m = H("div", { style: Object.assign({ height: `${this.options.height}px`, overflow: "hidden", fontSize: this.options.height / 2 + "px", whiteSpace: "nowrap" }, g ? { position: "absolute", top: "0", left: "0", right: "0", zIndex: "2" } : { position: "relative" }) });
199
+ m.setAttribute("part", "timeline"), typeof this.options.style == "string" ? m.setAttribute("style", m.getAttribute("style") + this.options.style) : typeof this.options.style == "object" && Object.assign(m.style, this.options.style);
200
+ const y = H("div", { style: { width: "0", height: "50%", display: "flex", flexDirection: "column", justifyContent: g ? "flex-start" : "flex-end", top: g ? "0" : "auto", bottom: g ? "auto" : "0", overflow: "visible", borderLeft: "1px solid currentColor", opacity: `${(h = this.options.secondaryLabelOpacity) !== null && h !== void 0 ? h : 0.25}`, position: "absolute", zIndex: "1" } });
201
+ for (let w = 0, v = 0; w < c; w += d, v++) {
202
+ const f = y.cloneNode(), C = Math.round(100 * w) % Math.round(100 * u) == 0 || p && v % p == 0, W = Math.round(100 * w) % Math.round(100 * b) == 0 || x && v % x == 0;
203
+ (C || W) && (f.style.height = "100%", f.style.textIndent = "3px", f.textContent = this.options.formatTimeCallback(w), C && (f.style.opacity = "1"));
204
+ const S = C ? "primary" : W ? "secondary" : "tick";
205
+ f.setAttribute("part", `timeline-notch timeline-notch-${S}`);
206
+ const M = Math.round(100 * (w + this.options.timeOffset)) / 100 * a;
207
+ f.style.left = `${M}px`, this.virtualAppend(M, m, f);
208
+ }
209
+ this.timelineWrapper.innerHTML = "", this.timelineWrapper.appendChild(m), this.emit("ready");
210
+ }
211
+ };
212
+ const Ee = ({
213
+ waveSurfer: o,
214
+ timelineOptions: t = {}
215
+ }) => {
216
+ const { pluginInstance: e, createPlugin: i } = z(
217
+ ot,
218
+ t
219
+ );
220
+ return D(() => {
221
+ o.value && i(o.value);
222
+ }), {
223
+ timelinePlugin: e
224
+ };
225
+ }, Pe = ({
226
+ containerRef: o,
227
+ options: t,
228
+ timelineOptions: e = {}
229
+ }) => G(
230
+ ot,
231
+ { containerRef: o, options: t, pluginOptions: e }
232
+ );
233
+ let Ut = class {
95
234
  constructor() {
96
235
  this.listeners = {};
97
236
  }
98
- on(e, t, i) {
99
- if (this.listeners[e] || (this.listeners[e] = /* @__PURE__ */ new Set()), this.listeners[e].add(t), i?.once) {
237
+ on(t, e, i) {
238
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
100
239
  const s = () => {
101
- this.un(e, s), this.un(e, t);
240
+ this.un(t, s), this.un(t, e);
102
241
  };
103
- return this.on(e, s), s;
242
+ return this.on(t, s), s;
104
243
  }
105
- return () => this.un(e, t);
244
+ return () => this.un(t, e);
106
245
  }
107
- un(e, t) {
246
+ un(t, e) {
108
247
  var i;
109
- (i = this.listeners[e]) === null || i === void 0 || i.delete(t);
248
+ (i = this.listeners[t]) === null || i === void 0 || i.delete(e);
110
249
  }
111
- once(e, t) {
112
- return this.on(e, t, { once: !0 });
250
+ once(t, e) {
251
+ return this.on(t, e, { once: !0 });
113
252
  }
114
253
  unAll() {
115
254
  this.listeners = {};
116
255
  }
117
- emit(e, ...t) {
118
- this.listeners[e] && this.listeners[e].forEach((i) => i(...t));
256
+ emit(t, ...e) {
257
+ this.listeners[t] && this.listeners[t].forEach((i) => i(...e));
119
258
  }
120
- }
121
- class B extends b {
122
- constructor(e) {
123
- super(), this.subscriptions = [], this.options = e;
259
+ }, Bt = class extends Ut {
260
+ constructor(t) {
261
+ super(), this.subscriptions = [], this.isDestroyed = !1, this.options = t;
262
+ }
263
+ onInit() {
264
+ }
265
+ _init(t) {
266
+ this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = t, this.onInit();
267
+ }
268
+ destroy() {
269
+ this.emit("destroy"), this.subscriptions.forEach((t) => t()), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
270
+ }
271
+ };
272
+ const Ht = { scale: 0.5, deltaThreshold: 5, exponentialZooming: !1, iterations: 20 };
273
+ let lt = class ht extends Bt {
274
+ constructor(t) {
275
+ super(t || {}), this.wrapper = void 0, this.container = null, this.accumulatedDelta = 0, this.pointerTime = 0, this.oldX = 0, this.endZoom = 0, this.startZoom = 0, this.onWheel = (e) => {
276
+ if (this.wavesurfer && this.container && !(Math.abs(e.deltaX) >= Math.abs(e.deltaY)) && (e.preventDefault(), this.accumulatedDelta += -e.deltaY, this.startZoom === 0 && this.options.exponentialZooming && (this.startZoom = this.wavesurfer.getWrapper().clientWidth / this.wavesurfer.getDuration()), this.options.deltaThreshold === 0 || Math.abs(this.accumulatedDelta) >= this.options.deltaThreshold)) {
277
+ const i = this.wavesurfer.getDuration(), s = this.wavesurfer.options.minPxPerSec === 0 ? this.wavesurfer.getWrapper().scrollWidth / i : this.wavesurfer.options.minPxPerSec, r = e.clientX - this.container.getBoundingClientRect().left, n = this.container.clientWidth, l = this.wavesurfer.getScroll();
278
+ r === this.oldX && this.oldX !== 0 || (this.pointerTime = (l + r) / s), this.oldX = r;
279
+ const h = this.calculateNewZoom(s, this.accumulatedDelta), c = n / h * (r / n);
280
+ h * i < n ? (this.wavesurfer.zoom(n / i), this.container.scrollLeft = 0) : (this.wavesurfer.zoom(h), this.container.scrollLeft = (this.pointerTime - c) * h), this.accumulatedDelta = 0;
281
+ }
282
+ }, this.calculateNewZoom = (e, i) => {
283
+ let s;
284
+ if (this.options.exponentialZooming) {
285
+ const r = i > 0 ? Math.pow(this.endZoom / this.startZoom, 1 / (this.options.iterations - 1)) : Math.pow(this.startZoom / this.endZoom, 1 / (this.options.iterations - 1));
286
+ s = Math.max(0, e * r);
287
+ } else s = Math.max(0, e + i * this.options.scale);
288
+ return Math.min(s, this.options.maxZoom);
289
+ }, this.options = Object.assign({}, Ht, t);
290
+ }
291
+ static create(t) {
292
+ return new ht(t);
293
+ }
294
+ onInit() {
295
+ var t;
296
+ this.wrapper = (t = this.wavesurfer) === null || t === void 0 ? void 0 : t.getWrapper(), this.wrapper && (this.container = this.wrapper.parentElement, this.container.addEventListener("wheel", this.onWheel), this.options.maxZoom === void 0 && (this.options.maxZoom = this.container.clientWidth), this.endZoom = this.options.maxZoom);
297
+ }
298
+ destroy() {
299
+ this.wrapper && this.wrapper.removeEventListener("wheel", this.onWheel), super.destroy();
300
+ }
301
+ };
302
+ const Te = ({
303
+ waveSurfer: o,
304
+ zoomOptions: t = {}
305
+ }) => {
306
+ const { pluginInstance: e, createPlugin: i } = z(
307
+ lt,
308
+ t
309
+ ), s = () => {
310
+ o.value && o.value.zoom(100);
311
+ }, r = () => {
312
+ o.value && o.value.zoom(50);
313
+ }, n = (l) => {
314
+ o.value && o.value.zoom(l);
315
+ };
316
+ return D(() => {
317
+ o.value && i(o.value);
318
+ }), {
319
+ zoomPlugin: e,
320
+ zoomIn: s,
321
+ zoomOut: r,
322
+ setZoom: n
323
+ };
324
+ }, De = ({
325
+ containerRef: o,
326
+ options: t,
327
+ zoomOptions: e = {}
328
+ }) => {
329
+ const { waveSurfer: i, pluginInstance: s } = G(
330
+ lt,
331
+ { containerRef: o, options: t, pluginOptions: e }
332
+ );
333
+ return {
334
+ waveSurfer: i,
335
+ zoomPlugin: s,
336
+ zoomIn: () => {
337
+ i.value && i.value.zoom(100);
338
+ },
339
+ zoomOut: () => {
340
+ i.value && i.value.zoom(50);
341
+ },
342
+ setZoom: (h) => {
343
+ i.value && i.value.zoom(h);
344
+ }
345
+ };
346
+ };
347
+ let V = class {
348
+ constructor() {
349
+ this.listeners = {};
350
+ }
351
+ on(t, e, i) {
352
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
353
+ const s = () => {
354
+ this.un(t, s), this.un(t, e);
355
+ };
356
+ return this.on(t, s), s;
357
+ }
358
+ return () => this.un(t, e);
359
+ }
360
+ un(t, e) {
361
+ var i;
362
+ (i = this.listeners[t]) === null || i === void 0 || i.delete(e);
363
+ }
364
+ once(t, e) {
365
+ return this.on(t, e, { once: !0 });
366
+ }
367
+ unAll() {
368
+ this.listeners = {};
369
+ }
370
+ emit(t, ...e) {
371
+ this.listeners[t] && this.listeners[t].forEach((i) => i(...e));
372
+ }
373
+ }, ct = class extends V {
374
+ constructor(t) {
375
+ super(), this.subscriptions = [], this.isDestroyed = !1, this.options = t;
124
376
  }
125
377
  onInit() {
126
378
  }
127
- _init(e) {
128
- this.wavesurfer = e, this.onInit();
379
+ _init(t) {
380
+ this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = t, this.onInit();
129
381
  }
130
382
  destroy() {
131
- this.emit("destroy"), this.subscriptions.forEach((e) => e());
383
+ this.emit("destroy"), this.subscriptions.forEach((t) => t()), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
132
384
  }
385
+ };
386
+ function k(o, t, e, i) {
387
+ return new (e || (e = Promise))(function(s, r) {
388
+ function n(c) {
389
+ try {
390
+ h(i.next(c));
391
+ } catch (a) {
392
+ r(a);
393
+ }
394
+ }
395
+ function l(c) {
396
+ try {
397
+ h(i.throw(c));
398
+ } catch (a) {
399
+ r(a);
400
+ }
401
+ }
402
+ function h(c) {
403
+ var a;
404
+ c.done ? s(c.value) : (a = c.value, a instanceof e ? a : new e(function(d) {
405
+ d(a);
406
+ })).then(n, l);
407
+ }
408
+ h((i = i.apply(o, t || [])).next());
409
+ });
410
+ }
411
+ const K = { decode: function(o, t) {
412
+ return k(this, void 0, void 0, function* () {
413
+ const e = new AudioContext({ sampleRate: t });
414
+ return e.decodeAudioData(o).finally(() => e.close());
415
+ });
416
+ }, createBuffer: function(o, t) {
417
+ return typeof o[0] == "number" && (o = [o]), function(e) {
418
+ const i = e[0];
419
+ if (i.some((s) => s > 1 || s < -1)) {
420
+ const s = i.length;
421
+ let r = 0;
422
+ for (let n = 0; n < s; n++) {
423
+ const l = Math.abs(i[n]);
424
+ l > r && (r = l);
425
+ }
426
+ for (const n of e) for (let l = 0; l < s; l++) n[l] /= r;
427
+ }
428
+ }(o), { duration: t, length: o[0].length, sampleRate: o[0].length / t, numberOfChannels: o.length, getChannelData: (e) => o?.[e], copyFromChannel: AudioBuffer.prototype.copyFromChannel, copyToChannel: AudioBuffer.prototype.copyToChannel };
429
+ } };
430
+ function ut(o, t) {
431
+ const e = t.xmlns ? document.createElementNS(t.xmlns, o) : document.createElement(o);
432
+ for (const [i, s] of Object.entries(t)) if (i === "children" && s) for (const [r, n] of Object.entries(s)) n instanceof Node ? e.appendChild(n) : typeof n == "string" ? e.appendChild(document.createTextNode(n)) : e.appendChild(ut(r, n));
433
+ else i === "style" ? Object.assign(e.style, s) : i === "textContent" ? e.textContent = s : e.setAttribute(i, s.toString());
434
+ return e;
435
+ }
436
+ function U(o, t, e) {
437
+ const i = ut(o, t || {});
438
+ return e?.appendChild(i), i;
133
439
  }
134
- class _ extends b {
440
+ var $t = Object.freeze({ __proto__: null, createElement: U, default: U });
441
+ const qt = { fetchBlob: function(o, t, e) {
442
+ return k(this, void 0, void 0, function* () {
443
+ const i = yield fetch(o, e);
444
+ if (i.status >= 400) throw new Error(`Failed to fetch ${o}: ${i.status} (${i.statusText})`);
445
+ return function(s, r) {
446
+ k(this, void 0, void 0, function* () {
447
+ if (!s.body || !s.headers) return;
448
+ const n = s.body.getReader(), l = Number(s.headers.get("Content-Length")) || 0;
449
+ let h = 0;
450
+ const c = (d) => k(this, void 0, void 0, function* () {
451
+ h += d?.length || 0;
452
+ const u = Math.round(h / l * 100);
453
+ r(u);
454
+ }), a = () => k(this, void 0, void 0, function* () {
455
+ let d;
456
+ try {
457
+ d = yield n.read();
458
+ } catch {
459
+ return;
460
+ }
461
+ d.done || (c(d.value), yield a());
462
+ });
463
+ a();
464
+ });
465
+ }(i.clone(), t), i.blob();
466
+ });
467
+ } };
468
+ let Qt = class extends V {
469
+ constructor(t) {
470
+ super(), this.isExternalMedia = !1, t.media ? (this.media = t.media, this.isExternalMedia = !0) : this.media = document.createElement("audio"), t.mediaControls && (this.media.controls = !0), t.autoplay && (this.media.autoplay = !0), t.playbackRate != null && this.onMediaEvent("canplay", () => {
471
+ t.playbackRate != null && (this.media.playbackRate = t.playbackRate);
472
+ }, { once: !0 });
473
+ }
474
+ onMediaEvent(t, e, i) {
475
+ return this.media.addEventListener(t, e, i), () => this.media.removeEventListener(t, e, i);
476
+ }
477
+ getSrc() {
478
+ return this.media.currentSrc || this.media.src || "";
479
+ }
480
+ revokeSrc() {
481
+ const t = this.getSrc();
482
+ t.startsWith("blob:") && URL.revokeObjectURL(t);
483
+ }
484
+ canPlayType(t) {
485
+ return this.media.canPlayType(t) !== "";
486
+ }
487
+ setSrc(t, e) {
488
+ const i = this.getSrc();
489
+ if (t && i === t) return;
490
+ this.revokeSrc();
491
+ const s = e instanceof Blob && (this.canPlayType(e.type) || !t) ? URL.createObjectURL(e) : t;
492
+ if (i && this.media.removeAttribute("src"), s || t) try {
493
+ this.media.src = s;
494
+ } catch {
495
+ this.media.src = t;
496
+ }
497
+ }
498
+ destroy() {
499
+ this.isExternalMedia || (this.media.pause(), this.media.remove(), this.revokeSrc(), this.media.removeAttribute("src"), this.media.load());
500
+ }
501
+ setMediaElement(t) {
502
+ this.media = t;
503
+ }
504
+ play() {
505
+ return k(this, void 0, void 0, function* () {
506
+ try {
507
+ return yield this.media.play();
508
+ } catch (t) {
509
+ if (t instanceof DOMException && t.name === "AbortError") return;
510
+ throw t;
511
+ }
512
+ });
513
+ }
514
+ pause() {
515
+ this.media.pause();
516
+ }
517
+ isPlaying() {
518
+ return !this.media.paused && !this.media.ended;
519
+ }
520
+ setTime(t) {
521
+ this.media.currentTime = Math.max(0, Math.min(t, this.getDuration()));
522
+ }
523
+ getDuration() {
524
+ return this.media.duration;
525
+ }
526
+ getCurrentTime() {
527
+ return this.media.currentTime;
528
+ }
529
+ getVolume() {
530
+ return this.media.volume;
531
+ }
532
+ setVolume(t) {
533
+ this.media.volume = t;
534
+ }
535
+ getMuted() {
536
+ return this.media.muted;
537
+ }
538
+ setMuted(t) {
539
+ this.media.muted = t;
540
+ }
541
+ getPlaybackRate() {
542
+ return this.media.playbackRate;
543
+ }
544
+ isSeeking() {
545
+ return this.media.seeking;
546
+ }
547
+ setPlaybackRate(t, e) {
548
+ e != null && (this.media.preservesPitch = e), this.media.playbackRate = t;
549
+ }
550
+ getMediaElement() {
551
+ return this.media;
552
+ }
553
+ setSinkId(t) {
554
+ return this.media.setSinkId(t);
555
+ }
556
+ }, Q = class _ extends V {
557
+ constructor(t, e) {
558
+ super(), this.timeouts = [], this.isScrollable = !1, this.audioData = null, this.resizeObserver = null, this.lastContainerWidth = 0, this.isDragging = !1, this.subscriptions = [], this.unsubscribeOnScroll = [], this.subscriptions = [], this.options = t;
559
+ const i = this.parentFromOptionsContainer(t.container);
560
+ this.parent = i;
561
+ const [s, r] = this.initHtml();
562
+ i.appendChild(s), this.container = s, this.scrollContainer = r.querySelector(".scroll"), this.wrapper = r.querySelector(".wrapper"), this.canvasWrapper = r.querySelector(".canvases"), this.progressWrapper = r.querySelector(".progress"), this.cursor = r.querySelector(".cursor"), e && r.appendChild(e), this.initEvents();
563
+ }
564
+ parentFromOptionsContainer(t) {
565
+ let e;
566
+ if (typeof t == "string" ? e = document.querySelector(t) : t instanceof HTMLElement && (e = t), !e) throw new Error("Container not found");
567
+ return e;
568
+ }
569
+ initEvents() {
570
+ const t = (e) => {
571
+ const i = this.wrapper.getBoundingClientRect(), s = e.clientX - i.left, r = e.clientY - i.top;
572
+ return [s / i.width, r / i.height];
573
+ };
574
+ if (this.wrapper.addEventListener("click", (e) => {
575
+ const [i, s] = t(e);
576
+ this.emit("click", i, s);
577
+ }), this.wrapper.addEventListener("dblclick", (e) => {
578
+ const [i, s] = t(e);
579
+ this.emit("dblclick", i, s);
580
+ }), this.options.dragToSeek !== !0 && typeof this.options.dragToSeek != "object" || this.initDrag(), this.scrollContainer.addEventListener("scroll", () => {
581
+ const { scrollLeft: e, scrollWidth: i, clientWidth: s } = this.scrollContainer, r = e / i, n = (e + s) / i;
582
+ this.emit("scroll", r, n, e, e + s);
583
+ }), typeof ResizeObserver == "function") {
584
+ const e = this.createDelay(100);
585
+ this.resizeObserver = new ResizeObserver(() => {
586
+ e().then(() => this.onContainerResize()).catch(() => {
587
+ });
588
+ }), this.resizeObserver.observe(this.scrollContainer);
589
+ }
590
+ }
591
+ onContainerResize() {
592
+ const t = this.parent.clientWidth;
593
+ t === this.lastContainerWidth && this.options.height !== "auto" || (this.lastContainerWidth = t, this.reRender());
594
+ }
595
+ initDrag() {
596
+ this.subscriptions.push(function(t, e, i, s, r = 3, n = 0, l = 100) {
597
+ if (!t) return () => {
598
+ };
599
+ const h = matchMedia("(pointer: coarse)").matches;
600
+ let c = () => {
601
+ };
602
+ const a = (d) => {
603
+ if (d.button !== n) return;
604
+ d.preventDefault(), d.stopPropagation();
605
+ let u = d.clientX, p = d.clientY, b = !1;
606
+ const x = Date.now(), g = (f) => {
607
+ if (f.preventDefault(), f.stopPropagation(), h && Date.now() - x < l) return;
608
+ const C = f.clientX, W = f.clientY, S = C - u, M = W - p;
609
+ if (b || Math.abs(S) > r || Math.abs(M) > r) {
610
+ const E = t.getBoundingClientRect(), { left: L, top: T } = E;
611
+ b || (i?.(u - L, p - T), b = !0), e(S, M, C - L, W - T), u = C, p = W;
612
+ }
613
+ }, m = (f) => {
614
+ if (b) {
615
+ const C = f.clientX, W = f.clientY, S = t.getBoundingClientRect(), { left: M, top: E } = S;
616
+ s?.(C - M, W - E);
617
+ }
618
+ c();
619
+ }, y = (f) => {
620
+ f.relatedTarget && f.relatedTarget !== document.documentElement || m(f);
621
+ }, w = (f) => {
622
+ b && (f.stopPropagation(), f.preventDefault());
623
+ }, v = (f) => {
624
+ b && f.preventDefault();
625
+ };
626
+ document.addEventListener("pointermove", g), document.addEventListener("pointerup", m), document.addEventListener("pointerout", y), document.addEventListener("pointercancel", y), document.addEventListener("touchmove", v, { passive: !1 }), document.addEventListener("click", w, { capture: !0 }), c = () => {
627
+ document.removeEventListener("pointermove", g), document.removeEventListener("pointerup", m), document.removeEventListener("pointerout", y), document.removeEventListener("pointercancel", y), document.removeEventListener("touchmove", v), setTimeout(() => {
628
+ document.removeEventListener("click", w, { capture: !0 });
629
+ }, 10);
630
+ };
631
+ };
632
+ return t.addEventListener("pointerdown", a), () => {
633
+ c(), t.removeEventListener("pointerdown", a);
634
+ };
635
+ }(this.wrapper, (t, e, i) => {
636
+ this.emit("drag", Math.max(0, Math.min(1, i / this.wrapper.getBoundingClientRect().width)));
637
+ }, (t) => {
638
+ this.isDragging = !0, this.emit("dragstart", Math.max(0, Math.min(1, t / this.wrapper.getBoundingClientRect().width)));
639
+ }, (t) => {
640
+ this.isDragging = !1, this.emit("dragend", Math.max(0, Math.min(1, t / this.wrapper.getBoundingClientRect().width)));
641
+ }));
642
+ }
643
+ getHeight(t, e) {
644
+ var i;
645
+ const s = ((i = this.audioData) === null || i === void 0 ? void 0 : i.numberOfChannels) || 1;
646
+ if (t == null) return 128;
647
+ if (!isNaN(Number(t))) return Number(t);
648
+ if (t === "auto") {
649
+ const r = this.parent.clientHeight || 128;
650
+ return e?.every((n) => !n.overlay) ? r / s : r;
651
+ }
652
+ return 128;
653
+ }
654
+ initHtml() {
655
+ const t = document.createElement("div"), e = t.attachShadow({ mode: "open" }), i = this.options.cspNonce && typeof this.options.cspNonce == "string" ? this.options.cspNonce.replace(/"/g, "") : "";
656
+ return e.innerHTML = `
657
+ <style${i ? ` nonce="${i}"` : ""}>
658
+ :host {
659
+ user-select: none;
660
+ min-width: 1px;
661
+ }
662
+ :host audio {
663
+ display: block;
664
+ width: 100%;
665
+ }
666
+ :host .scroll {
667
+ overflow-x: auto;
668
+ overflow-y: hidden;
669
+ width: 100%;
670
+ position: relative;
671
+ }
672
+ :host .noScrollbar {
673
+ scrollbar-color: transparent;
674
+ scrollbar-width: none;
675
+ }
676
+ :host .noScrollbar::-webkit-scrollbar {
677
+ display: none;
678
+ -webkit-appearance: none;
679
+ }
680
+ :host .wrapper {
681
+ position: relative;
682
+ overflow: visible;
683
+ z-index: 2;
684
+ }
685
+ :host .canvases {
686
+ min-height: ${this.getHeight(this.options.height, this.options.splitChannels)}px;
687
+ }
688
+ :host .canvases > div {
689
+ position: relative;
690
+ }
691
+ :host canvas {
692
+ display: block;
693
+ position: absolute;
694
+ top: 0;
695
+ image-rendering: pixelated;
696
+ }
697
+ :host .progress {
698
+ pointer-events: none;
699
+ position: absolute;
700
+ z-index: 2;
701
+ top: 0;
702
+ left: 0;
703
+ width: 0;
704
+ height: 100%;
705
+ overflow: hidden;
706
+ }
707
+ :host .progress > div {
708
+ position: relative;
709
+ }
710
+ :host .cursor {
711
+ pointer-events: none;
712
+ position: absolute;
713
+ z-index: 5;
714
+ top: 0;
715
+ left: 0;
716
+ height: 100%;
717
+ border-radius: 2px;
718
+ }
719
+ </style>
720
+
721
+ <div class="scroll" part="scroll">
722
+ <div class="wrapper" part="wrapper">
723
+ <div class="canvases" part="canvases"></div>
724
+ <div class="progress" part="progress"></div>
725
+ <div class="cursor" part="cursor"></div>
726
+ </div>
727
+ </div>
728
+ `, [t, e];
729
+ }
730
+ setOptions(t) {
731
+ if (this.options.container !== t.container) {
732
+ const e = this.parentFromOptionsContainer(t.container);
733
+ e.appendChild(this.container), this.parent = e;
734
+ }
735
+ t.dragToSeek !== !0 && typeof this.options.dragToSeek != "object" || this.initDrag(), this.options = t, this.reRender();
736
+ }
737
+ getWrapper() {
738
+ return this.wrapper;
739
+ }
740
+ getWidth() {
741
+ return this.scrollContainer.clientWidth;
742
+ }
743
+ getScroll() {
744
+ return this.scrollContainer.scrollLeft;
745
+ }
746
+ setScroll(t) {
747
+ this.scrollContainer.scrollLeft = t;
748
+ }
749
+ setScrollPercentage(t) {
750
+ const { scrollWidth: e } = this.scrollContainer, i = e * t;
751
+ this.setScroll(i);
752
+ }
753
+ destroy() {
754
+ var t, e;
755
+ this.subscriptions.forEach((i) => i()), this.container.remove(), (t = this.resizeObserver) === null || t === void 0 || t.disconnect(), (e = this.unsubscribeOnScroll) === null || e === void 0 || e.forEach((i) => i()), this.unsubscribeOnScroll = [];
756
+ }
757
+ createDelay(t = 10) {
758
+ let e, i;
759
+ const s = () => {
760
+ e && clearTimeout(e), i && i();
761
+ };
762
+ return this.timeouts.push(s), () => new Promise((r, n) => {
763
+ s(), i = n, e = setTimeout(() => {
764
+ e = void 0, i = void 0, r();
765
+ }, t);
766
+ });
767
+ }
768
+ convertColorValues(t) {
769
+ if (!Array.isArray(t)) return t || "";
770
+ if (t.length < 2) return t[0] || "";
771
+ const e = document.createElement("canvas"), i = e.getContext("2d"), s = e.height * (window.devicePixelRatio || 1), r = i.createLinearGradient(0, 0, 0, s), n = 1 / (t.length - 1);
772
+ return t.forEach((l, h) => {
773
+ const c = h * n;
774
+ r.addColorStop(c, l);
775
+ }), r;
776
+ }
777
+ getPixelRatio() {
778
+ return Math.max(1, window.devicePixelRatio || 1);
779
+ }
780
+ renderBarWaveform(t, e, i, s) {
781
+ const r = t[0], n = t[1] || t[0], l = r.length, { width: h, height: c } = i.canvas, a = c / 2, d = this.getPixelRatio(), u = e.barWidth ? e.barWidth * d : 1, p = e.barGap ? e.barGap * d : e.barWidth ? u / 2 : 0, b = e.barRadius || 0, x = h / (u + p) / l, g = b && "roundRect" in i ? "roundRect" : "rect";
782
+ i.beginPath();
783
+ let m = 0, y = 0, w = 0;
784
+ for (let v = 0; v <= l; v++) {
785
+ const f = Math.round(v * x);
786
+ if (f > m) {
787
+ const S = Math.round(y * a * s), M = S + Math.round(w * a * s) || 1;
788
+ let E = a - S;
789
+ e.barAlign === "top" ? E = 0 : e.barAlign === "bottom" && (E = c - M), i[g](m * (u + p), E, u, M, b), m = f, y = 0, w = 0;
790
+ }
791
+ const C = Math.abs(r[v] || 0), W = Math.abs(n[v] || 0);
792
+ C > y && (y = C), W > w && (w = W);
793
+ }
794
+ i.fill(), i.closePath();
795
+ }
796
+ renderLineWaveform(t, e, i, s) {
797
+ const r = (n) => {
798
+ const l = t[n] || t[0], h = l.length, { height: c } = i.canvas, a = c / 2, d = i.canvas.width / h;
799
+ i.moveTo(0, a);
800
+ let u = 0, p = 0;
801
+ for (let b = 0; b <= h; b++) {
802
+ const x = Math.round(b * d);
803
+ if (x > u) {
804
+ const m = a + (Math.round(p * a * s) || 1) * (n === 0 ? -1 : 1);
805
+ i.lineTo(u, m), u = x, p = 0;
806
+ }
807
+ const g = Math.abs(l[b] || 0);
808
+ g > p && (p = g);
809
+ }
810
+ i.lineTo(u, a);
811
+ };
812
+ i.beginPath(), r(0), r(1), i.fill(), i.closePath();
813
+ }
814
+ renderWaveform(t, e, i) {
815
+ if (i.fillStyle = this.convertColorValues(e.waveColor), e.renderFunction) return void e.renderFunction(t, i);
816
+ let s = e.barHeight || 1;
817
+ if (e.normalize) {
818
+ const r = Array.from(t[0]).reduce((n, l) => Math.max(n, Math.abs(l)), 0);
819
+ s = r ? 1 / r : 1;
820
+ }
821
+ e.barWidth || e.barGap || e.barAlign ? this.renderBarWaveform(t, e, i, s) : this.renderLineWaveform(t, e, i, s);
822
+ }
823
+ renderSingleCanvas(t, e, i, s, r, n, l) {
824
+ const h = this.getPixelRatio(), c = document.createElement("canvas");
825
+ c.width = Math.round(i * h), c.height = Math.round(s * h), c.style.width = `${i}px`, c.style.height = `${s}px`, c.style.left = `${Math.round(r)}px`, n.appendChild(c);
826
+ const a = c.getContext("2d");
827
+ if (this.renderWaveform(t, e, a), c.width > 0 && c.height > 0) {
828
+ const d = c.cloneNode(), u = d.getContext("2d");
829
+ u.drawImage(c, 0, 0), u.globalCompositeOperation = "source-in", u.fillStyle = this.convertColorValues(e.progressColor), u.fillRect(0, 0, c.width, c.height), l.appendChild(d);
830
+ }
831
+ }
832
+ renderMultiCanvas(t, e, i, s, r, n) {
833
+ const l = this.getPixelRatio(), { clientWidth: h } = this.scrollContainer, c = i / l;
834
+ let a = Math.min(_.MAX_CANVAS_WIDTH, h, c), d = {};
835
+ if (e.barWidth || e.barGap) {
836
+ const g = e.barWidth || 0.5, m = g + (e.barGap || g / 2);
837
+ a % m != 0 && (a = Math.floor(a / m) * m);
838
+ }
839
+ if (a === 0) return;
840
+ const u = (g) => {
841
+ if (g < 0 || g >= p || d[g]) return;
842
+ d[g] = !0;
843
+ const m = g * a;
844
+ let y = Math.min(c - m, a);
845
+ if (e.barWidth || e.barGap) {
846
+ const v = e.barWidth || 0.5, f = v + (e.barGap || v / 2);
847
+ y = Math.floor(y / f) * f;
848
+ }
849
+ if (y <= 0) return;
850
+ const w = t.map((v) => {
851
+ const f = Math.floor(m / c * v.length), C = Math.floor((m + y) / c * v.length);
852
+ return v.slice(f, C);
853
+ });
854
+ this.renderSingleCanvas(w, e, y, s, m, r, n);
855
+ }, p = Math.ceil(c / a);
856
+ if (!this.isScrollable) {
857
+ for (let g = 0; g < p; g++) u(g);
858
+ return;
859
+ }
860
+ const b = this.scrollContainer.scrollLeft / c, x = Math.floor(b * p);
861
+ if (u(x - 1), u(x), u(x + 1), p > 1) {
862
+ const g = this.on("scroll", () => {
863
+ const { scrollLeft: m } = this.scrollContainer, y = Math.floor(m / c * p);
864
+ Object.keys(d).length > _.MAX_NODES && (r.innerHTML = "", n.innerHTML = "", d = {}), u(y - 1), u(y), u(y + 1);
865
+ });
866
+ this.unsubscribeOnScroll.push(g);
867
+ }
868
+ }
869
+ renderChannel(t, e, i, s) {
870
+ var { overlay: r } = e, n = function(a, d) {
871
+ var u = {};
872
+ for (var p in a) Object.prototype.hasOwnProperty.call(a, p) && d.indexOf(p) < 0 && (u[p] = a[p]);
873
+ if (a != null && typeof Object.getOwnPropertySymbols == "function") {
874
+ var b = 0;
875
+ for (p = Object.getOwnPropertySymbols(a); b < p.length; b++) d.indexOf(p[b]) < 0 && Object.prototype.propertyIsEnumerable.call(a, p[b]) && (u[p[b]] = a[p[b]]);
876
+ }
877
+ return u;
878
+ }(e, ["overlay"]);
879
+ const l = document.createElement("div"), h = this.getHeight(n.height, n.splitChannels);
880
+ l.style.height = `${h}px`, r && s > 0 && (l.style.marginTop = `-${h}px`), this.canvasWrapper.style.minHeight = `${h}px`, this.canvasWrapper.appendChild(l);
881
+ const c = l.cloneNode();
882
+ this.progressWrapper.appendChild(c), this.renderMultiCanvas(t, n, i, h, l, c);
883
+ }
884
+ render(t) {
885
+ return k(this, void 0, void 0, function* () {
886
+ var e;
887
+ this.timeouts.forEach((h) => h()), 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);
888
+ const i = this.getPixelRatio(), s = this.scrollContainer.clientWidth, r = Math.ceil(t.duration * (this.options.minPxPerSec || 0));
889
+ this.isScrollable = r > s;
890
+ const n = this.options.fillParent && !this.isScrollable, l = (n ? s : r) * i;
891
+ if (this.wrapper.style.width = n ? "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 h = 0; h < t.numberOfChannels; h++) {
892
+ const c = Object.assign(Object.assign({}, this.options), (e = this.options.splitChannels) === null || e === void 0 ? void 0 : e[h]);
893
+ this.renderChannel([t.getChannelData(h)], c, l, h);
894
+ }
895
+ else {
896
+ const h = [t.getChannelData(0)];
897
+ t.numberOfChannels > 1 && h.push(t.getChannelData(1)), this.renderChannel(h, this.options, l, 0);
898
+ }
899
+ Promise.resolve().then(() => this.emit("rendered"));
900
+ });
901
+ }
902
+ reRender() {
903
+ if (this.unsubscribeOnScroll.forEach((i) => i()), this.unsubscribeOnScroll = [], !this.audioData) return;
904
+ const { scrollWidth: t } = this.scrollContainer, { right: e } = this.progressWrapper.getBoundingClientRect();
905
+ if (this.render(this.audioData), this.isScrollable && t !== this.scrollContainer.scrollWidth) {
906
+ const { right: i } = this.progressWrapper.getBoundingClientRect();
907
+ let s = i - e;
908
+ s *= 2, s = s < 0 ? Math.floor(s) : Math.ceil(s), s /= 2, this.scrollContainer.scrollLeft += s;
909
+ }
910
+ }
911
+ zoom(t) {
912
+ this.options.minPxPerSec = t, this.reRender();
913
+ }
914
+ scrollIntoView(t, e = !1) {
915
+ const { scrollLeft: i, scrollWidth: s, clientWidth: r } = this.scrollContainer, n = t * s, l = i, h = i + r, c = r / 2;
916
+ if (this.isDragging)
917
+ n + 30 > h ? this.scrollContainer.scrollLeft += 30 : n - 30 < l && (this.scrollContainer.scrollLeft -= 30);
918
+ else {
919
+ (n < l || n > h) && (this.scrollContainer.scrollLeft = n - (this.options.autoCenter ? c : 0));
920
+ const a = n - i - c;
921
+ e && this.options.autoCenter && a > 0 && (this.scrollContainer.scrollLeft += Math.min(a, 10));
922
+ }
923
+ {
924
+ const a = this.scrollContainer.scrollLeft, d = a / s, u = (a + r) / s;
925
+ this.emit("scroll", d, u, a, a + r);
926
+ }
927
+ }
928
+ renderProgress(t, e) {
929
+ if (isNaN(t)) return;
930
+ const i = 100 * t;
931
+ this.canvasWrapper.style.clipPath = `polygon(${i}% 0%, 100% 0%, 100% 100%, ${i}% 100%)`, this.progressWrapper.style.width = `${i}%`, this.cursor.style.left = `${i}%`, this.cursor.style.transform = this.options.cursorWidth ? `translateX(-${t * this.options.cursorWidth}px)` : "", this.isScrollable && this.options.autoScroll && this.scrollIntoView(t, e);
932
+ }
933
+ exportImage(t, e, i) {
934
+ return k(this, void 0, void 0, function* () {
935
+ const s = this.canvasWrapper.querySelectorAll("canvas");
936
+ if (!s.length) throw new Error("No waveform data");
937
+ if (i === "dataURL") {
938
+ const r = Array.from(s).map((n) => n.toDataURL(t, e));
939
+ return Promise.resolve(r);
940
+ }
941
+ return Promise.all(Array.from(s).map((r) => new Promise((n, l) => {
942
+ r.toBlob((h) => {
943
+ h ? n(h) : l(new Error("Could not export image"));
944
+ }, t, e);
945
+ })));
946
+ });
947
+ }
948
+ };
949
+ Q.MAX_CANVAS_WIDTH = 8e3, Q.MAX_NODES = 10;
950
+ let _t = class extends V {
135
951
  constructor() {
136
952
  super(...arguments), this.unsubscribe = () => {
137
953
  };
@@ -149,188 +965,1792 @@ class _ extends b {
149
965
  destroy() {
150
966
  this.unsubscribe();
151
967
  }
152
- }
153
- const F = ["audio/webm", "audio/wav", "audio/mpeg", "audio/mp4", "audio/mp3"];
154
- class R extends B {
155
- constructor(e) {
156
- var t, i, s, r, o, a;
157
- super(Object.assign(Object.assign({}, e), { audioBitsPerSecond: (t = e.audioBitsPerSecond) !== null && t !== void 0 ? t : 128e3, scrollingWaveform: (i = e.scrollingWaveform) !== null && i !== void 0 && i, scrollingWaveformWindow: (s = e.scrollingWaveformWindow) !== null && s !== void 0 ? s : 5, continuousWaveform: (r = e.continuousWaveform) !== null && r !== void 0 && r, renderRecordedAudio: (o = e.renderRecordedAudio) === null || o === void 0 || o, mediaRecorderTimeslice: (a = e.mediaRecorderTimeslice) !== null && a !== void 0 ? a : void 0 })), this.stream = null, this.mediaRecorder = null, this.dataWindow = null, this.isWaveformPaused = !1, this.lastStartTime = 0, this.lastDuration = 0, this.duration = 0, this.timer = new _(), this.subscriptions.push(this.timer.on("tick", () => {
158
- const d = performance.now() - this.lastStartTime;
159
- this.duration = this.isPaused() ? this.duration : this.lastDuration + d, this.emit("record-progress", this.duration);
160
- }));
968
+ }, $ = class extends V {
969
+ constructor(t = new AudioContext()) {
970
+ super(), this.bufferNode = null, this.playStartTime = 0, this.playedDuration = 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 = t, this.gainNode = this.audioContext.createGain(), this.gainNode.connect(this.audioContext.destination);
161
971
  }
162
- static create(e) {
163
- return new R(e || {});
972
+ load() {
973
+ return k(this, void 0, void 0, function* () {
974
+ });
975
+ }
976
+ get src() {
977
+ return this.currentSrc;
978
+ }
979
+ set src(t) {
980
+ if (this.currentSrc = t, this._duration = void 0, !t) return this.buffer = null, void this.emit("emptied");
981
+ fetch(t).then((e) => {
982
+ if (e.status >= 400) throw new Error(`Failed to fetch ${t}: ${e.status} (${e.statusText})`);
983
+ return e.arrayBuffer();
984
+ }).then((e) => this.currentSrc !== t ? null : this.audioContext.decodeAudioData(e)).then((e) => {
985
+ this.currentSrc === t && (this.buffer = e, this.emit("loadedmetadata"), this.emit("canplay"), this.autoplay && this.play());
986
+ });
164
987
  }
165
- renderMicStream(e) {
988
+ _play() {
166
989
  var t;
167
- const i = new AudioContext(), s = i.createMediaStreamSource(e), r = i.createAnalyser();
168
- s.connect(r), this.options.continuousWaveform && (r.fftSize = 32);
169
- const o = r.frequencyBinCount, a = new Float32Array(o);
170
- let d = 0;
171
- this.wavesurfer && ((t = this.originalOptions) !== null && t !== void 0 || (this.originalOptions = Object.assign({}, this.wavesurfer.options)), this.wavesurfer.options.interact = !1, this.options.scrollingWaveform && (this.wavesurfer.options.cursorWidth = 0));
172
- const h = setInterval(() => {
173
- var l, m, p, g;
174
- if (!this.isWaveformPaused) {
175
- if (r.getFloatTimeDomainData(a), this.options.scrollingWaveform) {
176
- const u = Math.floor((this.options.scrollingWaveformWindow || 0) * i.sampleRate), c = Math.min(u, this.dataWindow ? this.dataWindow.length + o : o), f = new Float32Array(u);
177
- if (this.dataWindow) {
178
- const D = Math.max(0, u - this.dataWindow.length);
179
- f.set(this.dataWindow.slice(-c + o), D);
180
- }
181
- f.set(a, u - o), this.dataWindow = f;
182
- } else if (this.options.continuousWaveform) {
183
- if (!this.dataWindow) {
184
- const c = this.options.continuousWaveformDuration ? Math.round(100 * this.options.continuousWaveformDuration) : ((m = (l = this.wavesurfer) === null || l === void 0 ? void 0 : l.getWidth()) !== null && m !== void 0 ? m : 0) * window.devicePixelRatio;
185
- this.dataWindow = new Float32Array(c);
186
- }
187
- let u = 0;
188
- for (let c = 0; c < o; c++) {
189
- const f = Math.abs(a[c]);
190
- f > u && (u = f);
191
- }
192
- if (d + 1 > this.dataWindow.length) {
193
- const c = new Float32Array(2 * this.dataWindow.length);
194
- c.set(this.dataWindow, 0), this.dataWindow = c;
195
- }
196
- this.dataWindow[d] = u, d++;
197
- } else this.dataWindow = a;
198
- if (this.wavesurfer) {
199
- const u = ((g = (p = this.dataWindow) === null || p === void 0 ? void 0 : p.length) !== null && g !== void 0 ? g : 0) / 100;
200
- this.wavesurfer.load("", [this.dataWindow], this.options.scrollingWaveform ? this.options.scrollingWaveformWindow : u).then(() => {
201
- this.wavesurfer && this.options.continuousWaveform && (this.wavesurfer.setTime(this.getDuration() / 1e3), this.wavesurfer.options.minPxPerSec || this.wavesurfer.setOptions({ minPxPerSec: this.wavesurfer.getWidth() / this.wavesurfer.getDuration() }));
202
- }).catch((c) => {
203
- console.error("Error rendering real-time recording data:", c);
204
- });
205
- }
206
- }
207
- }, 10);
208
- return { onDestroy: () => {
209
- clearInterval(h), s?.disconnect(), i?.close();
210
- }, onEnd: () => {
211
- this.isWaveformPaused = !0, clearInterval(h), this.stopMic();
212
- } };
213
- }
214
- startMic(e) {
215
- return W(this, void 0, void 0, function* () {
216
- let t;
217
- try {
218
- t = yield navigator.mediaDevices.getUserMedia({ audio: !e?.deviceId || { deviceId: e.deviceId } });
219
- } catch (r) {
220
- throw new Error("Error accessing the microphone: " + r.message);
221
- }
222
- const { onDestroy: i, onEnd: s } = this.renderMicStream(t);
223
- return this.subscriptions.push(this.once("destroy", i)), this.subscriptions.push(this.once("record-end", s)), this.stream = t, t;
990
+ if (!this.paused) return;
991
+ this.paused = !1, (t = this.bufferNode) === null || t === void 0 || t.disconnect(), this.bufferNode = this.audioContext.createBufferSource(), this.buffer && (this.bufferNode.buffer = this.buffer), this.bufferNode.playbackRate.value = this._playbackRate, this.bufferNode.connect(this.gainNode);
992
+ let e = this.playedDuration * this._playbackRate;
993
+ (e >= this.duration || e < 0) && (e = 0, this.playedDuration = 0), this.bufferNode.start(this.audioContext.currentTime, e), this.playStartTime = this.audioContext.currentTime, this.bufferNode.onended = () => {
994
+ this.currentTime >= this.duration && (this.pause(), this.emit("ended"));
995
+ };
996
+ }
997
+ _pause() {
998
+ var t;
999
+ this.paused = !0, (t = this.bufferNode) === null || t === void 0 || t.stop(), this.playedDuration += this.audioContext.currentTime - this.playStartTime;
1000
+ }
1001
+ play() {
1002
+ return k(this, void 0, void 0, function* () {
1003
+ this.paused && (this._play(), this.emit("play"));
224
1004
  });
225
1005
  }
226
- stopMic() {
227
- this.stream && (this.stream.getTracks().forEach((e) => e.stop()), this.stream = null, this.mediaRecorder = null);
228
- }
229
- startRecording(e) {
230
- return W(this, void 0, void 0, function* () {
231
- const t = this.stream || (yield this.startMic(e));
232
- this.dataWindow = null;
233
- const i = this.mediaRecorder || new MediaRecorder(t, { mimeType: this.options.mimeType || F.find((o) => MediaRecorder.isTypeSupported(o)), audioBitsPerSecond: this.options.audioBitsPerSecond });
234
- this.mediaRecorder = i, this.stopRecording();
235
- const s = [];
236
- i.ondataavailable = (o) => {
237
- o.data.size > 0 && s.push(o.data), this.emit("record-data-available", o.data);
238
- };
239
- const r = (o) => {
240
- var a;
241
- const d = new Blob(s, { type: i.mimeType });
242
- this.emit(o, d), this.options.renderRecordedAudio && (this.applyOriginalOptionsIfNeeded(), (a = this.wavesurfer) === null || a === void 0 || a.load(URL.createObjectURL(d)));
243
- };
244
- i.onpause = () => r("record-pause"), i.onstop = () => r("record-end"), i.start(this.options.mediaRecorderTimeslice), this.lastStartTime = performance.now(), this.lastDuration = 0, this.duration = 0, this.isWaveformPaused = !1, this.timer.start(), this.emit("record-start");
1006
+ pause() {
1007
+ this.paused || (this._pause(), this.emit("pause"));
1008
+ }
1009
+ stopAt(t) {
1010
+ const e = t - this.currentTime, i = this.bufferNode;
1011
+ i?.stop(this.audioContext.currentTime + e), i?.addEventListener("ended", () => {
1012
+ i === this.bufferNode && (this.bufferNode = null, this.pause());
1013
+ }, { once: !0 });
1014
+ }
1015
+ setSinkId(t) {
1016
+ return k(this, void 0, void 0, function* () {
1017
+ return this.audioContext.setSinkId(t);
245
1018
  });
246
1019
  }
247
- getDuration() {
248
- return this.duration;
1020
+ get playbackRate() {
1021
+ return this._playbackRate;
249
1022
  }
250
- isRecording() {
251
- var e;
252
- return ((e = this.mediaRecorder) === null || e === void 0 ? void 0 : e.state) === "recording";
1023
+ set playbackRate(t) {
1024
+ this._playbackRate = t, this.bufferNode && (this.bufferNode.playbackRate.value = t);
253
1025
  }
254
- isPaused() {
255
- var e;
256
- return ((e = this.mediaRecorder) === null || e === void 0 ? void 0 : e.state) === "paused";
1026
+ get currentTime() {
1027
+ return (this.paused ? this.playedDuration : this.playedDuration + (this.audioContext.currentTime - this.playStartTime)) * this._playbackRate;
257
1028
  }
258
- isActive() {
259
- var e;
260
- return ((e = this.mediaRecorder) === null || e === void 0 ? void 0 : e.state) !== "inactive";
1029
+ set currentTime(t) {
1030
+ const e = !this.paused;
1031
+ e && this._pause(), this.playedDuration = t / this._playbackRate, e && this._play(), this.emit("seeking"), this.emit("timeupdate");
261
1032
  }
262
- stopRecording() {
263
- var e;
264
- this.isActive() && ((e = this.mediaRecorder) === null || e === void 0 || e.stop(), this.timer.stop());
1033
+ get duration() {
1034
+ var t, e;
1035
+ return (t = this._duration) !== null && t !== void 0 ? t : ((e = this.buffer) === null || e === void 0 ? void 0 : e.duration) || 0;
265
1036
  }
266
- pauseRecording() {
267
- var e, t;
268
- this.isRecording() && (this.isWaveformPaused = !0, (e = this.mediaRecorder) === null || e === void 0 || e.requestData(), (t = this.mediaRecorder) === null || t === void 0 || t.pause(), this.timer.stop(), this.lastDuration = this.duration);
1037
+ set duration(t) {
1038
+ this._duration = t;
269
1039
  }
270
- resumeRecording() {
271
- var e;
272
- this.isPaused() && (this.isWaveformPaused = !1, (e = this.mediaRecorder) === null || e === void 0 || e.resume(), this.timer.start(), this.lastStartTime = performance.now(), this.emit("record-resume"));
1040
+ get volume() {
1041
+ return this.gainNode.gain.value;
273
1042
  }
274
- static getAvailableAudioDevices() {
275
- return W(this, void 0, void 0, function* () {
276
- return navigator.mediaDevices.enumerateDevices().then((e) => e.filter((t) => t.kind === "audioinput"));
277
- });
1043
+ set volume(t) {
1044
+ this.gainNode.gain.value = t, this.emit("volumechange");
278
1045
  }
279
- destroy() {
280
- this.applyOriginalOptionsIfNeeded(), super.destroy(), this.stopRecording(), this.stopMic();
1046
+ get muted() {
1047
+ return this._muted;
281
1048
  }
282
- applyOriginalOptionsIfNeeded() {
283
- this.wavesurfer && this.originalOptions && (this.wavesurfer.setOptions(this.originalOptions), delete this.originalOptions);
1049
+ set muted(t) {
1050
+ this._muted !== t && (this._muted = t, this._muted ? this.gainNode.disconnect() : this.gainNode.connect(this.audioContext.destination));
284
1051
  }
285
- }
286
- const q = ({ containerRef: n, options: e, recordPluginOptions: t }) => {
287
- const { waveSurfer: i } = P({ containerRef: n, options: e }), s = v(null), r = v(0), o = v(!1), a = v(!1), d = y(() => [
288
- Math.floor(r.value % 36e5 / 6e4),
289
- // minutes
290
- Math.floor(r.value % 6e4 / 1e3)
291
- // seconds
292
- ].map((u) => u < 10 ? "0" + u : u).join(":")), h = y(() => o.value || !a.value), l = () => {
293
- s.value && s.value?.on("record-progress", (u) => {
294
- r.value = u;
295
- });
296
- }, m = () => {
297
- if (s.value?.isRecording() || s.value?.isPaused()) {
298
- s.value?.stopRecording(), o.value = !1, a.value = !0;
299
- return;
1052
+ canPlayType(t) {
1053
+ return /^(audio|video)\//.test(t);
1054
+ }
1055
+ getGainNode() {
1056
+ return this.gainNode;
1057
+ }
1058
+ getChannelData() {
1059
+ const t = [];
1060
+ if (!this.buffer) return t;
1061
+ const e = this.buffer.numberOfChannels;
1062
+ for (let i = 0; i < e; i++) t.push(this.buffer.getChannelData(i));
1063
+ return t;
1064
+ }
1065
+ removeAttribute(t) {
1066
+ switch (t) {
1067
+ case "src":
1068
+ this.src = "";
1069
+ break;
1070
+ case "playbackRate":
1071
+ this.playbackRate = 0;
1072
+ break;
1073
+ case "currentTime":
1074
+ this.currentTime = 0;
1075
+ break;
1076
+ case "duration":
1077
+ this.duration = 0;
1078
+ break;
1079
+ case "volume":
1080
+ this.volume = 0;
1081
+ break;
1082
+ case "muted":
1083
+ this.muted = !1;
300
1084
  }
301
- s.value?.startRecording(), o.value = !0, a.value = !1, l();
302
- }, p = () => new Promise((u) => {
303
- let c;
304
- (s.value?.isRecording() || s.value?.isPaused()) && (s.value?.stopRecording(), o.value = !1, a.value = !1), s.value?.on("record-end", (f) => {
305
- c = f, u(c);
1085
+ }
1086
+ };
1087
+ const Jt = { waveColor: "#999", progressColor: "#555", cursorWidth: 1, minPxPerSec: 0, fillParent: !0, interact: !0, dragToSeek: !1, autoScroll: !0, autoCenter: !0, sampleRate: 8e3 };
1088
+ let J = class dt extends Qt {
1089
+ static create(t) {
1090
+ return new dt(t);
1091
+ }
1092
+ constructor(t) {
1093
+ const e = t.media || (t.backend === "WebAudio" ? new $() : void 0);
1094
+ super({ media: e, mediaControls: t.mediaControls, autoplay: t.autoplay, playbackRate: t.audioRate }), this.plugins = [], this.decodedData = null, this.stopAtPosition = null, this.subscriptions = [], this.mediaSubscriptions = [], this.abortController = null, this.options = Object.assign({}, Jt, t), this.timer = new _t();
1095
+ const i = e ? void 0 : this.getMediaElement();
1096
+ this.renderer = new Q(this.options, i), this.initPlayerEvents(), this.initRendererEvents(), this.initTimerEvents(), this.initPlugins();
1097
+ const s = this.options.url || this.getSrc() || "";
1098
+ Promise.resolve().then(() => {
1099
+ this.emit("init");
1100
+ const { peaks: r, duration: n } = this.options;
1101
+ (s || r && n) && this.load(s, r, n).catch(() => null);
306
1102
  });
307
- }), g = () => {
308
- if (s.value?.isPaused()) {
309
- s.value?.resumeRecording(), o.value = !0, a.value = !1;
310
- return;
1103
+ }
1104
+ updateProgress(t = this.getCurrentTime()) {
1105
+ return this.renderer.renderProgress(t / this.getDuration(), this.isPlaying()), t;
1106
+ }
1107
+ initTimerEvents() {
1108
+ this.subscriptions.push(this.timer.on("tick", () => {
1109
+ if (!this.isSeeking()) {
1110
+ const t = this.updateProgress();
1111
+ this.emit("timeupdate", t), this.emit("audioprocess", t), this.stopAtPosition != null && this.isPlaying() && t >= this.stopAtPosition && this.pause();
1112
+ }
1113
+ }));
1114
+ }
1115
+ initPlayerEvents() {
1116
+ this.isPlaying() && (this.emit("play"), this.timer.start()), this.mediaSubscriptions.push(this.onMediaEvent("timeupdate", () => {
1117
+ const t = this.updateProgress();
1118
+ this.emit("timeupdate", t);
1119
+ }), this.onMediaEvent("play", () => {
1120
+ this.emit("play"), this.timer.start();
1121
+ }), this.onMediaEvent("pause", () => {
1122
+ this.emit("pause"), this.timer.stop(), this.stopAtPosition = null;
1123
+ }), this.onMediaEvent("emptied", () => {
1124
+ this.timer.stop(), this.stopAtPosition = null;
1125
+ }), this.onMediaEvent("ended", () => {
1126
+ this.emit("timeupdate", this.getDuration()), this.emit("finish"), this.stopAtPosition = null;
1127
+ }), this.onMediaEvent("seeking", () => {
1128
+ this.emit("seeking", this.getCurrentTime());
1129
+ }), this.onMediaEvent("error", () => {
1130
+ var t;
1131
+ this.emit("error", (t = this.getMediaElement().error) !== null && t !== void 0 ? t : new Error("Media error")), this.stopAtPosition = null;
1132
+ }));
1133
+ }
1134
+ initRendererEvents() {
1135
+ this.subscriptions.push(this.renderer.on("click", (t, e) => {
1136
+ this.options.interact && (this.seekTo(t), this.emit("interaction", t * this.getDuration()), this.emit("click", t, e));
1137
+ }), this.renderer.on("dblclick", (t, e) => {
1138
+ this.emit("dblclick", t, e);
1139
+ }), this.renderer.on("scroll", (t, e, i, s) => {
1140
+ const r = this.getDuration();
1141
+ this.emit("scroll", t * r, e * r, i, s);
1142
+ }), this.renderer.on("render", () => {
1143
+ this.emit("redraw");
1144
+ }), this.renderer.on("rendered", () => {
1145
+ this.emit("redrawcomplete");
1146
+ }), this.renderer.on("dragstart", (t) => {
1147
+ this.emit("dragstart", t);
1148
+ }), this.renderer.on("dragend", (t) => {
1149
+ this.emit("dragend", t);
1150
+ }));
1151
+ {
1152
+ let t;
1153
+ this.subscriptions.push(this.renderer.on("drag", (e) => {
1154
+ if (!this.options.interact) return;
1155
+ let i;
1156
+ this.renderer.renderProgress(e), clearTimeout(t), this.isPlaying() ? i = 0 : this.options.dragToSeek === !0 ? i = 200 : typeof this.options.dragToSeek == "object" && this.options.dragToSeek !== void 0 && (i = this.options.dragToSeek.debounceTime), t = setTimeout(() => {
1157
+ this.seekTo(e);
1158
+ }, i), this.emit("interaction", e * this.getDuration()), this.emit("drag", e);
1159
+ }));
311
1160
  }
312
- o.value = !1, a.value = !0, s.value?.pauseRecording();
1161
+ }
1162
+ initPlugins() {
1163
+ var t;
1164
+ !((t = this.options.plugins) === null || t === void 0) && t.length && this.options.plugins.forEach((e) => {
1165
+ this.registerPlugin(e);
1166
+ });
1167
+ }
1168
+ unsubscribePlayerEvents() {
1169
+ this.mediaSubscriptions.forEach((t) => t()), this.mediaSubscriptions = [];
1170
+ }
1171
+ setOptions(t) {
1172
+ this.options = Object.assign({}, this.options, t), t.duration && !t.peaks && (this.decodedData = K.createBuffer(this.exportPeaks(), t.duration)), t.peaks && t.duration && (this.decodedData = K.createBuffer(t.peaks, t.duration)), this.renderer.setOptions(this.options), t.audioRate && this.setPlaybackRate(t.audioRate), t.mediaControls != null && (this.getMediaElement().controls = t.mediaControls);
1173
+ }
1174
+ registerPlugin(t) {
1175
+ if (this.plugins.includes(t)) return t;
1176
+ t._init(this), this.plugins.push(t);
1177
+ const e = t.once("destroy", () => {
1178
+ this.plugins = this.plugins.filter((i) => i !== t), this.subscriptions = this.subscriptions.filter((i) => i !== e);
1179
+ });
1180
+ return this.subscriptions.push(e), t;
1181
+ }
1182
+ unregisterPlugin(t) {
1183
+ this.plugins = this.plugins.filter((e) => e !== t), t.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(t) {
1195
+ return this.renderer.setScroll(t);
1196
+ }
1197
+ setScrollTime(t) {
1198
+ const e = t / this.getDuration();
1199
+ this.renderer.setScrollPercentage(e);
1200
+ }
1201
+ getActivePlugins() {
1202
+ return this.plugins;
1203
+ }
1204
+ loadAudio(t, e, i, s) {
1205
+ return k(this, void 0, void 0, function* () {
1206
+ var r;
1207
+ if (this.emit("load", t), !this.options.media && this.isPlaying() && this.pause(), this.decodedData = null, this.stopAtPosition = null, !e && !i) {
1208
+ const l = this.options.fetchParams || {};
1209
+ window.AbortController && !l.signal && (this.abortController = new AbortController(), l.signal = (r = this.abortController) === null || r === void 0 ? void 0 : r.signal);
1210
+ const h = (a) => this.emit("loading", a);
1211
+ e = yield qt.fetchBlob(t, h, l);
1212
+ const c = this.options.blobMimeType;
1213
+ c && (e = new Blob([e], { type: c }));
1214
+ }
1215
+ this.setSrc(t, e);
1216
+ const n = yield new Promise((l) => {
1217
+ const h = s || this.getDuration();
1218
+ h ? l(h) : this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata", () => l(this.getDuration()), { once: !0 }));
1219
+ });
1220
+ if (!t && !e) {
1221
+ const l = this.getMediaElement();
1222
+ l instanceof $ && (l.duration = n);
1223
+ }
1224
+ if (i) this.decodedData = K.createBuffer(i, n || 0);
1225
+ else if (e) {
1226
+ const l = yield e.arrayBuffer();
1227
+ this.decodedData = yield K.decode(l, this.options.sampleRate);
1228
+ }
1229
+ this.decodedData && (this.emit("decode", this.getDuration()), this.renderer.render(this.decodedData)), this.emit("ready", this.getDuration());
1230
+ });
1231
+ }
1232
+ load(t, e, i) {
1233
+ return k(this, void 0, void 0, function* () {
1234
+ try {
1235
+ return yield this.loadAudio(t, void 0, e, i);
1236
+ } catch (s) {
1237
+ throw this.emit("error", s), s;
1238
+ }
1239
+ });
1240
+ }
1241
+ loadBlob(t, e, i) {
1242
+ return k(this, void 0, void 0, function* () {
1243
+ try {
1244
+ return yield this.loadAudio("", t, e, i);
1245
+ } catch (s) {
1246
+ throw this.emit("error", s), s;
1247
+ }
1248
+ });
1249
+ }
1250
+ zoom(t) {
1251
+ if (!this.decodedData) throw new Error("No audio loaded");
1252
+ this.renderer.zoom(t), this.emit("zoom", t);
1253
+ }
1254
+ getDecodedData() {
1255
+ return this.decodedData;
1256
+ }
1257
+ exportPeaks({ channels: t = 2, maxLength: e = 8e3, precision: i = 1e4 } = {}) {
1258
+ if (!this.decodedData) throw new Error("The audio has not been decoded yet");
1259
+ const s = Math.min(t, this.decodedData.numberOfChannels), r = [];
1260
+ for (let n = 0; n < s; n++) {
1261
+ const l = this.decodedData.getChannelData(n), h = [], c = l.length / e;
1262
+ for (let a = 0; a < e; a++) {
1263
+ const d = l.slice(Math.floor(a * c), Math.ceil((a + 1) * c));
1264
+ let u = 0;
1265
+ for (let p = 0; p < d.length; p++) {
1266
+ const b = d[p];
1267
+ Math.abs(b) > Math.abs(u) && (u = b);
1268
+ }
1269
+ h.push(Math.round(u * i) / i);
1270
+ }
1271
+ r.push(h);
1272
+ }
1273
+ return r;
1274
+ }
1275
+ getDuration() {
1276
+ let t = super.getDuration() || 0;
1277
+ return t !== 0 && t !== 1 / 0 || !this.decodedData || (t = this.decodedData.duration), t;
1278
+ }
1279
+ toggleInteraction(t) {
1280
+ this.options.interact = t;
1281
+ }
1282
+ setTime(t) {
1283
+ this.stopAtPosition = null, super.setTime(t), this.updateProgress(t), this.emit("timeupdate", t);
1284
+ }
1285
+ seekTo(t) {
1286
+ const e = this.getDuration() * t;
1287
+ this.setTime(e);
1288
+ }
1289
+ play(t, e) {
1290
+ const i = Object.create(null, { play: { get: () => super.play } });
1291
+ return k(this, void 0, void 0, function* () {
1292
+ t != null && this.setTime(t);
1293
+ const s = yield i.play.call(this);
1294
+ return e != null && (this.media instanceof $ ? this.media.stopAt(e) : this.stopAtPosition = e), s;
1295
+ });
1296
+ }
1297
+ playPause() {
1298
+ return k(this, void 0, void 0, function* () {
1299
+ return this.isPlaying() ? this.pause() : this.play();
1300
+ });
1301
+ }
1302
+ stop() {
1303
+ this.pause(), this.setTime(0);
1304
+ }
1305
+ skip(t) {
1306
+ this.setTime(this.getCurrentTime() + t);
1307
+ }
1308
+ empty() {
1309
+ this.load("", [[0]], 1e-3);
1310
+ }
1311
+ setMediaElement(t) {
1312
+ this.unsubscribePlayerEvents(), super.setMediaElement(t), this.initPlayerEvents();
1313
+ }
1314
+ exportImage() {
1315
+ return k(this, arguments, void 0, function* (t = "image/png", e = 1, i = "dataURL") {
1316
+ return this.renderer.exportImage(t, e, i);
1317
+ });
1318
+ }
1319
+ destroy() {
1320
+ var t;
1321
+ this.emit("destroy"), (t = this.abortController) === null || t === void 0 || t.abort(), this.plugins.forEach((e) => e.destroy()), this.subscriptions.forEach((e) => e()), this.unsubscribePlayerEvents(), this.timer.destroy(), this.renderer.destroy(), super.destroy();
1322
+ }
1323
+ };
1324
+ J.BasePlugin = ct, J.dom = $t;
1325
+ const te = { height: 50, overlayColor: "rgba(100, 100, 100, 0.1)", insertPosition: "afterend" };
1326
+ let pt = class mt extends ct {
1327
+ constructor(t) {
1328
+ super(t), this.miniWavesurfer = null, this.container = null, this.options = Object.assign({}, te, t), this.minimapWrapper = this.initMinimapWrapper(), this.overlay = this.initOverlay();
1329
+ }
1330
+ static create(t) {
1331
+ return new mt(t);
1332
+ }
1333
+ onInit() {
1334
+ var t, e;
1335
+ if (!this.wavesurfer) throw Error("WaveSurfer is not initialized");
1336
+ this.options.container ? (typeof this.options.container == "string" ? this.container = document.querySelector(this.options.container) : this.options.container instanceof HTMLElement && (this.container = this.options.container), (t = this.container) === null || t === void 0 || t.appendChild(this.minimapWrapper)) : (this.container = this.wavesurfer.getWrapper().parentElement, (e = this.container) === null || e === void 0 || e.insertAdjacentElement(this.options.insertPosition, this.minimapWrapper)), this.initWaveSurferEvents(), Promise.resolve().then(() => {
1337
+ this.initMinimap();
1338
+ });
1339
+ }
1340
+ initMinimapWrapper() {
1341
+ return U("div", { part: "minimap", style: { position: "relative" } });
1342
+ }
1343
+ initOverlay() {
1344
+ return U("div", { part: "minimap-overlay", style: { position: "absolute", zIndex: "2", left: "0", top: "0", bottom: "0", transition: "left 100ms ease-out", pointerEvents: "none", backgroundColor: this.options.overlayColor } }, this.minimapWrapper);
1345
+ }
1346
+ initMinimap() {
1347
+ if (this.miniWavesurfer && (this.miniWavesurfer.destroy(), this.miniWavesurfer = null), !this.wavesurfer) return;
1348
+ const t = this.wavesurfer.getDecodedData(), e = this.wavesurfer.getMediaElement();
1349
+ if (!t || !e) return;
1350
+ const i = [];
1351
+ for (let s = 0; s < t.numberOfChannels; s++) i.push(t.getChannelData(s));
1352
+ this.miniWavesurfer = J.create(Object.assign(Object.assign({}, this.options), { container: this.minimapWrapper, minPxPerSec: 0, fillParent: !0, media: e, peaks: i, duration: t.duration })), this.subscriptions.push(this.miniWavesurfer.on("audioprocess", (s) => {
1353
+ this.emit("audioprocess", s);
1354
+ }), this.miniWavesurfer.on("click", (s, r) => {
1355
+ this.emit("click", s, r);
1356
+ }), this.miniWavesurfer.on("dblclick", (s, r) => {
1357
+ this.emit("dblclick", s, r);
1358
+ }), this.miniWavesurfer.on("decode", (s) => {
1359
+ this.emit("decode", s);
1360
+ }), this.miniWavesurfer.on("destroy", () => {
1361
+ this.emit("destroy");
1362
+ }), this.miniWavesurfer.on("drag", (s) => {
1363
+ this.emit("drag", s);
1364
+ }), this.miniWavesurfer.on("dragend", (s) => {
1365
+ this.emit("dragend", s);
1366
+ }), this.miniWavesurfer.on("dragstart", (s) => {
1367
+ this.emit("dragstart", s);
1368
+ }), this.miniWavesurfer.on("interaction", () => {
1369
+ this.emit("interaction");
1370
+ }), this.miniWavesurfer.on("init", () => {
1371
+ this.emit("init");
1372
+ }), this.miniWavesurfer.on("ready", () => {
1373
+ this.emit("ready");
1374
+ }), this.miniWavesurfer.on("redraw", () => {
1375
+ this.emit("redraw");
1376
+ }), this.miniWavesurfer.on("redrawcomplete", () => {
1377
+ this.emit("redrawcomplete");
1378
+ }), this.miniWavesurfer.on("seeking", (s) => {
1379
+ this.emit("seeking", s);
1380
+ }), this.miniWavesurfer.on("timeupdate", (s) => {
1381
+ this.emit("timeupdate", s);
1382
+ }));
1383
+ }
1384
+ getOverlayWidth() {
1385
+ var t;
1386
+ const e = ((t = this.wavesurfer) === null || t === void 0 ? void 0 : t.getWrapper().clientWidth) || 1;
1387
+ return Math.round(this.minimapWrapper.clientWidth / e * 100);
1388
+ }
1389
+ onRedraw() {
1390
+ const t = this.getOverlayWidth();
1391
+ this.overlay.style.width = `${t}%`;
1392
+ }
1393
+ onScroll(t) {
1394
+ if (!this.wavesurfer) return;
1395
+ const e = this.wavesurfer.getDuration();
1396
+ this.overlay.style.left = t / e * 100 + "%";
1397
+ }
1398
+ initWaveSurferEvents() {
1399
+ this.wavesurfer && this.subscriptions.push(this.wavesurfer.on("decode", () => {
1400
+ this.initMinimap();
1401
+ }), this.wavesurfer.on("scroll", (t) => {
1402
+ this.onScroll(t);
1403
+ }), this.wavesurfer.on("redraw", () => {
1404
+ this.onRedraw();
1405
+ }));
1406
+ }
1407
+ destroy() {
1408
+ var t;
1409
+ (t = this.miniWavesurfer) === null || t === void 0 || t.destroy(), this.minimapWrapper.remove(), super.destroy();
1410
+ }
1411
+ };
1412
+ const Xe = ({
1413
+ waveSurfer: o,
1414
+ minimapOptions: t = {}
1415
+ }) => {
1416
+ const { pluginInstance: e, createPlugin: i } = z(
1417
+ pt,
1418
+ t
1419
+ );
1420
+ return D(() => {
1421
+ o.value && i(o.value);
1422
+ }), {
1423
+ minimapPlugin: e
313
1424
  };
314
- return w(() => {
315
- const u = i.value?.registerPlugin(R.create({
316
- renderRecordedAudio: !1,
317
- ...t
1425
+ }, Ne = ({
1426
+ containerRef: o,
1427
+ options: t,
1428
+ minimapOptions: e = {}
1429
+ }) => G(
1430
+ pt,
1431
+ { containerRef: o, options: t, pluginOptions: e }
1432
+ );
1433
+ let vt = class {
1434
+ constructor() {
1435
+ this.listeners = {};
1436
+ }
1437
+ on(t, e, i) {
1438
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
1439
+ const s = () => {
1440
+ this.un(t, s), this.un(t, e);
1441
+ };
1442
+ return this.on(t, s), s;
1443
+ }
1444
+ return () => this.un(t, e);
1445
+ }
1446
+ un(t, e) {
1447
+ var i;
1448
+ (i = this.listeners[t]) === null || i === void 0 || i.delete(e);
1449
+ }
1450
+ once(t, e) {
1451
+ return this.on(t, e, { once: !0 });
1452
+ }
1453
+ unAll() {
1454
+ this.listeners = {};
1455
+ }
1456
+ emit(t, ...e) {
1457
+ this.listeners[t] && this.listeners[t].forEach((i) => i(...e));
1458
+ }
1459
+ }, ee = class extends vt {
1460
+ constructor(t) {
1461
+ super(), this.subscriptions = [], this.isDestroyed = !1, this.options = t;
1462
+ }
1463
+ onInit() {
1464
+ }
1465
+ _init(t) {
1466
+ this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = t, this.onInit();
1467
+ }
1468
+ destroy() {
1469
+ this.emit("destroy"), this.subscriptions.forEach((t) => t()), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
1470
+ }
1471
+ };
1472
+ function tt(o, t, e, i, s = 3, r = 0, n = 100) {
1473
+ if (!o) return () => {
1474
+ };
1475
+ const l = matchMedia("(pointer: coarse)").matches;
1476
+ let h = () => {
1477
+ };
1478
+ const c = (a) => {
1479
+ if (a.button !== r) return;
1480
+ a.preventDefault(), a.stopPropagation();
1481
+ let d = a.clientX, u = a.clientY, p = !1;
1482
+ const b = Date.now(), x = (v) => {
1483
+ if (v.preventDefault(), v.stopPropagation(), l && Date.now() - b < n) return;
1484
+ const f = v.clientX, C = v.clientY, W = f - d, S = C - u;
1485
+ if (p || Math.abs(W) > s || Math.abs(S) > s) {
1486
+ const M = o.getBoundingClientRect(), { left: E, top: L } = M;
1487
+ p || (e?.(d - E, u - L), p = !0), t(W, S, f - E, C - L), d = f, u = C;
1488
+ }
1489
+ }, g = (v) => {
1490
+ if (p) {
1491
+ const f = v.clientX, C = v.clientY, W = o.getBoundingClientRect(), { left: S, top: M } = W;
1492
+ i?.(f - S, C - M);
1493
+ }
1494
+ h();
1495
+ }, m = (v) => {
1496
+ v.relatedTarget && v.relatedTarget !== document.documentElement || g(v);
1497
+ }, y = (v) => {
1498
+ p && (v.stopPropagation(), v.preventDefault());
1499
+ }, w = (v) => {
1500
+ p && v.preventDefault();
1501
+ };
1502
+ document.addEventListener("pointermove", x), document.addEventListener("pointerup", g), document.addEventListener("pointerout", m), document.addEventListener("pointercancel", m), document.addEventListener("touchmove", w, { passive: !1 }), document.addEventListener("click", y, { capture: !0 }), h = () => {
1503
+ document.removeEventListener("pointermove", x), document.removeEventListener("pointerup", g), document.removeEventListener("pointerout", m), document.removeEventListener("pointercancel", m), document.removeEventListener("touchmove", w), setTimeout(() => {
1504
+ document.removeEventListener("click", y, { capture: !0 });
1505
+ }, 10);
1506
+ };
1507
+ };
1508
+ return o.addEventListener("pointerdown", c), () => {
1509
+ h(), o.removeEventListener("pointerdown", c);
1510
+ };
1511
+ }
1512
+ function ft(o, t) {
1513
+ const e = t.xmlns ? document.createElementNS(t.xmlns, o) : document.createElement(o);
1514
+ for (const [i, s] of Object.entries(t)) if (i === "children" && s) for (const [r, n] of Object.entries(s)) n instanceof Node ? e.appendChild(n) : typeof n == "string" ? e.appendChild(document.createTextNode(n)) : e.appendChild(ft(r, n));
1515
+ else i === "style" ? Object.assign(e.style, s) : i === "textContent" ? e.textContent = s : e.setAttribute(i, s.toString());
1516
+ return e;
1517
+ }
1518
+ function q(o, t, e) {
1519
+ const i = ft(o, t || {});
1520
+ return e?.appendChild(i), i;
1521
+ }
1522
+ const N = { points: [], lineWidth: 4, lineColor: "rgba(0, 0, 255, 0.5)", dragPointSize: 10, dragPointFill: "rgba(255, 255, 255, 0.8)", dragPointStroke: "rgba(255, 255, 255, 0.8)" };
1523
+ let ie = class extends vt {
1524
+ constructor(t, e) {
1525
+ super(), this.subscriptions = [], this.subscriptions = [], this.options = t, this.polyPoints = /* @__PURE__ */ new Map();
1526
+ const i = e.clientWidth, s = e.clientHeight, r = q("svg", { xmlns: "http://www.w3.org/2000/svg", width: "100%", height: "100%", viewBox: `0 0 ${i} ${s}`, preserveAspectRatio: "none", style: { position: "absolute", left: "0", top: "0", zIndex: "4" }, part: "envelope" }, e);
1527
+ this.svg = r;
1528
+ const n = q("polyline", { xmlns: "http://www.w3.org/2000/svg", points: `0,${s} ${i},${s}`, stroke: t.lineColor, "stroke-width": t.lineWidth, fill: "none", part: "polyline", style: t.dragLine ? { cursor: "row-resize", pointerEvents: "stroke" } : {} }, r);
1529
+ t.dragLine && this.subscriptions.push(tt(n, (l, h) => {
1530
+ const { height: c } = r.viewBox.baseVal, { points: a } = n;
1531
+ for (let u = 1; u < a.numberOfItems - 1; u++) {
1532
+ const p = a.getItem(u);
1533
+ p.y = Math.min(c, Math.max(0, p.y + h));
1534
+ }
1535
+ const d = r.querySelectorAll("ellipse");
1536
+ Array.from(d).forEach((u) => {
1537
+ const p = Math.min(c, Math.max(0, Number(u.getAttribute("cy")) + h));
1538
+ u.setAttribute("cy", p.toString());
1539
+ }), this.emit("line-move", h / c);
1540
+ })), r.addEventListener("dblclick", (l) => {
1541
+ const h = r.getBoundingClientRect(), c = l.clientX - h.left, a = l.clientY - h.top;
1542
+ this.emit("point-create", c / h.width, a / h.height);
1543
+ });
1544
+ {
1545
+ let l;
1546
+ const h = () => clearTimeout(l);
1547
+ r.addEventListener("touchstart", (c) => {
1548
+ c.touches.length === 1 ? l = window.setTimeout(() => {
1549
+ c.preventDefault();
1550
+ const a = r.getBoundingClientRect(), d = c.touches[0].clientX - a.left, u = c.touches[0].clientY - a.top;
1551
+ this.emit("point-create", d / a.width, u / a.height);
1552
+ }, 500) : h();
1553
+ }), r.addEventListener("touchmove", h), r.addEventListener("touchend", h);
1554
+ }
1555
+ }
1556
+ makeDraggable(t, e) {
1557
+ this.subscriptions.push(tt(t, e, () => t.style.cursor = "grabbing", () => t.style.cursor = "grab", 1));
1558
+ }
1559
+ createCircle(t, e) {
1560
+ const i = this.options.dragPointSize / 2;
1561
+ return q("ellipse", { xmlns: "http://www.w3.org/2000/svg", cx: t, cy: e, rx: i, ry: i, fill: this.options.dragPointFill, stroke: this.options.dragPointStroke, "stroke-width": "2", style: { cursor: "grab", pointerEvents: "all" }, part: "envelope-circle" }, this.svg);
1562
+ }
1563
+ removePolyPoint(t) {
1564
+ const e = this.polyPoints.get(t);
1565
+ if (!e) return;
1566
+ const { polyPoint: i, circle: s } = e, { points: r } = this.svg.querySelector("polyline"), n = Array.from(r).findIndex((l) => l.x === i.x && l.y === i.y);
1567
+ r.removeItem(n), s.remove(), this.polyPoints.delete(t);
1568
+ }
1569
+ addPolyPoint(t, e, i) {
1570
+ const { svg: s } = this, { width: r, height: n } = s.viewBox.baseVal, l = t * r, h = n - e * n, c = this.options.dragPointSize / 2, a = s.createSVGPoint();
1571
+ a.x = t * r, a.y = n - e * n;
1572
+ const d = this.createCircle(l, h), { points: u } = s.querySelector("polyline"), p = Array.from(u).findIndex((b) => b.x >= l);
1573
+ u.insertItemBefore(a, Math.max(p, 1)), this.polyPoints.set(i, { polyPoint: a, circle: d }), this.makeDraggable(d, (b, x) => {
1574
+ const g = a.x + b, m = a.y + x;
1575
+ if (g < -c || m < -c || g > r + c || m > n + c) return void this.emit("point-dragout", i);
1576
+ const y = Array.from(u).find((v) => v.x > a.x), w = Array.from(u).findLast((v) => v.x < a.x);
1577
+ y && g >= y.x || w && g <= w.x || (a.x = g, a.y = m, d.setAttribute("cx", g.toString()), d.setAttribute("cy", m.toString()), this.emit("point-move", i, g / r, m / n));
1578
+ });
1579
+ }
1580
+ update() {
1581
+ const { svg: t } = this, { clientWidth: e, clientHeight: i } = t;
1582
+ if (!e || !i) return;
1583
+ const s = t.viewBox.baseVal.width / e, r = t.viewBox.baseVal.height / i;
1584
+ t.querySelectorAll("ellipse").forEach((n) => {
1585
+ const l = this.options.dragPointSize / 2, h = l * s, c = l * r;
1586
+ n.setAttribute("rx", h.toString()), n.setAttribute("ry", c.toString());
1587
+ });
1588
+ }
1589
+ destroy() {
1590
+ this.subscriptions.forEach((t) => t()), this.polyPoints.clear(), this.svg.remove();
1591
+ }
1592
+ }, gt = class bt extends ee {
1593
+ constructor(t) {
1594
+ super(t), this.polyline = null, this.throttleTimeout = null, this.volume = 1, this.points = t.points || [], this.options = Object.assign({}, N, t), this.options.lineColor = this.options.lineColor || N.lineColor, this.options.dragPointFill = this.options.dragPointFill || N.dragPointFill, this.options.dragPointStroke = this.options.dragPointStroke || N.dragPointStroke, this.options.dragPointSize = this.options.dragPointSize || N.dragPointSize;
1595
+ }
1596
+ static create(t) {
1597
+ return new bt(t);
1598
+ }
1599
+ addPoint(t) {
1600
+ var e;
1601
+ t.id || (t.id = Math.random().toString(36).slice(2));
1602
+ const i = this.points.findLastIndex((r) => r.time < t.time);
1603
+ this.points.splice(i + 1, 0, t), this.emitPoints();
1604
+ const s = (e = this.wavesurfer) === null || e === void 0 ? void 0 : e.getDuration();
1605
+ s && this.addPolyPoint(t, s);
1606
+ }
1607
+ removePoint(t) {
1608
+ var e;
1609
+ const i = this.points.indexOf(t);
1610
+ i > -1 && (this.points.splice(i, 1), (e = this.polyline) === null || e === void 0 || e.removePolyPoint(t), this.emitPoints());
1611
+ }
1612
+ getPoints() {
1613
+ return this.points;
1614
+ }
1615
+ setPoints(t) {
1616
+ this.points.slice().forEach((e) => this.removePoint(e)), t.forEach((e) => this.addPoint(e));
1617
+ }
1618
+ destroy() {
1619
+ var t;
1620
+ (t = this.polyline) === null || t === void 0 || t.destroy(), super.destroy();
1621
+ }
1622
+ getCurrentVolume() {
1623
+ return this.volume;
1624
+ }
1625
+ setVolume(t) {
1626
+ var e;
1627
+ this.volume = t, (e = this.wavesurfer) === null || e === void 0 || e.setVolume(t);
1628
+ }
1629
+ onInit() {
1630
+ var t;
1631
+ if (!this.wavesurfer) throw Error("WaveSurfer is not initialized");
1632
+ const { options: e } = this;
1633
+ e.volume = (t = e.volume) !== null && t !== void 0 ? t : this.wavesurfer.getVolume(), this.setVolume(e.volume), this.subscriptions.push(this.wavesurfer.on("decode", (i) => {
1634
+ this.initPolyline(), this.points.forEach((s) => {
1635
+ this.addPolyPoint(s, i);
1636
+ });
1637
+ }), this.wavesurfer.on("redraw", () => {
1638
+ var i;
1639
+ (i = this.polyline) === null || i === void 0 || i.update();
1640
+ }), this.wavesurfer.on("timeupdate", (i) => {
1641
+ this.onTimeUpdate(i);
1642
+ }));
1643
+ }
1644
+ emitPoints() {
1645
+ this.throttleTimeout && clearTimeout(this.throttleTimeout), this.throttleTimeout = setTimeout(() => {
1646
+ this.emit("points-change", this.points);
1647
+ }, 200);
1648
+ }
1649
+ initPolyline() {
1650
+ if (this.polyline && this.polyline.destroy(), !this.wavesurfer) return;
1651
+ const t = this.wavesurfer.getWrapper();
1652
+ this.polyline = new ie(this.options, t), this.subscriptions.push(this.polyline.on("point-move", (e, i, s) => {
1653
+ var r;
1654
+ const n = ((r = this.wavesurfer) === null || r === void 0 ? void 0 : r.getDuration()) || 0;
1655
+ e.time = i * n, e.volume = 1 - s, this.emitPoints();
1656
+ }), this.polyline.on("point-dragout", (e) => {
1657
+ this.removePoint(e);
1658
+ }), this.polyline.on("point-create", (e, i) => {
1659
+ var s;
1660
+ this.addPoint({ time: e * (((s = this.wavesurfer) === null || s === void 0 ? void 0 : s.getDuration()) || 0), volume: 1 - i });
1661
+ }), this.polyline.on("line-move", (e) => {
1662
+ var i;
1663
+ this.points.forEach((s) => {
1664
+ s.volume = Math.min(1, Math.max(0, s.volume - e));
1665
+ }), this.emitPoints(), this.onTimeUpdate(((i = this.wavesurfer) === null || i === void 0 ? void 0 : i.getCurrentTime()) || 0);
318
1666
  }));
319
- u && (s.value = u);
1667
+ }
1668
+ addPolyPoint(t, e) {
1669
+ var i;
1670
+ (i = this.polyline) === null || i === void 0 || i.addPolyPoint(t.time / e, t.volume, t);
1671
+ }
1672
+ onTimeUpdate(t) {
1673
+ if (!this.wavesurfer) return;
1674
+ let e = this.points.find((c) => c.time > t);
1675
+ e || (e = { time: this.wavesurfer.getDuration() || 0, volume: 0 });
1676
+ let i = this.points.findLast((c) => c.time <= t);
1677
+ i || (i = { time: 0, volume: 0 });
1678
+ const s = e.time - i.time, r = e.volume - i.volume, n = i.volume + (t - i.time) * (r / s), l = Math.min(1, Math.max(0, n)), h = Math.round(100 * l) / 100;
1679
+ h !== this.getCurrentVolume() && (this.setVolume(h), this.emit("volume-change", h));
1680
+ }
1681
+ };
1682
+ const Ke = ({
1683
+ waveSurfer: o,
1684
+ envelopeOptions: t = {}
1685
+ }) => {
1686
+ const { pluginInstance: e, createPlugin: i } = z(
1687
+ gt,
1688
+ t
1689
+ );
1690
+ return D(() => {
1691
+ o.value && i(o.value);
320
1692
  }), {
321
- waveSurfer: i,
322
- waveSurferRecorder: s,
323
- currentTime: d,
324
- startRecording: m,
325
- stopRecording: p,
326
- pauseRecording: g,
327
- isRecording: o,
328
- isPaused: a,
329
- isPauseResume: h
1693
+ envelopePlugin: e
1694
+ };
1695
+ }, je = ({
1696
+ containerRef: o,
1697
+ options: t,
1698
+ envelopeOptions: e = {}
1699
+ }) => G(
1700
+ gt,
1701
+ { containerRef: o, options: t, pluginOptions: e }
1702
+ );
1703
+ function O(o, t, e, i) {
1704
+ return new (e || (e = Promise))(function(s, r) {
1705
+ function n(c) {
1706
+ try {
1707
+ h(i.next(c));
1708
+ } catch (a) {
1709
+ r(a);
1710
+ }
1711
+ }
1712
+ function l(c) {
1713
+ try {
1714
+ h(i.throw(c));
1715
+ } catch (a) {
1716
+ r(a);
1717
+ }
1718
+ }
1719
+ function h(c) {
1720
+ var a;
1721
+ c.done ? s(c.value) : (a = c.value, a instanceof e ? a : new e(function(d) {
1722
+ d(a);
1723
+ })).then(n, l);
1724
+ }
1725
+ h((i = i.apply(o, [])).next());
1726
+ });
1727
+ }
1728
+ const yt = 1e3 * Math.log(10) / 107.939;
1729
+ function wt(o) {
1730
+ return 2595 * Math.log10(1 + o / 700);
1731
+ }
1732
+ function Ct(o) {
1733
+ return 700 * (Math.pow(10, o / 2595) - 1);
1734
+ }
1735
+ function xt(o) {
1736
+ return Math.log10(Math.max(1, o));
1737
+ }
1738
+ function St(o) {
1739
+ return Math.pow(10, o);
1740
+ }
1741
+ function Wt(o) {
1742
+ let t = 26.81 * o / (1960 + o) - 0.53;
1743
+ return t < 2 && (t += 0.15 * (2 - t)), t > 20.1 && (t += 0.22 * (t - 20.1)), t;
1744
+ }
1745
+ function Mt(o) {
1746
+ return o < 2 && (o = (o - 0.3) / 0.85), o > 20.1 && (o = (o + 4.422) / 1.22), (o + 0.53) / (26.28 - o) * 1960;
1747
+ }
1748
+ function Et(o) {
1749
+ return yt * Math.log10(1 + 437e-5 * o);
1750
+ }
1751
+ function Pt(o) {
1752
+ return (Math.pow(10, o / yt) - 1) / 437e-5;
1753
+ }
1754
+ function X(o, t) {
1755
+ switch (t) {
1756
+ case "mel":
1757
+ return wt(o);
1758
+ case "logarithmic":
1759
+ return xt(o);
1760
+ case "bark":
1761
+ return Wt(o);
1762
+ case "erb":
1763
+ return Et(o);
1764
+ default:
1765
+ return o;
1766
+ }
1767
+ }
1768
+ function j(o, t, e, i, s) {
1769
+ const r = i(0), n = i(e / 2), l = Array.from({ length: o }, () => Array(t / 2 + 1).fill(0)), h = e / t;
1770
+ for (let c = 0; c < o; c++) {
1771
+ const a = s(r + c / o * (n - r)), d = Math.floor(a / h), u = d * h, p = (a - u) / ((d + 1) * h - u);
1772
+ l[c][d] = 1 - p, l[c][d + 1] = p;
1773
+ }
1774
+ return l;
1775
+ }
1776
+ function se(o, t) {
1777
+ const e = t.length, i = Float32Array.from({ length: e }, () => 0);
1778
+ for (let s = 0; s < e; s++) for (let r = 0; r < o.length; r++) i[s] += o[r] * t[s][r];
1779
+ return i;
1780
+ }
1781
+ const ne = { gray: () => {
1782
+ const o = [];
1783
+ for (let t = 0; t < 256; t++) {
1784
+ const e = (255 - t) / 256;
1785
+ o.push([e, e, e, 1]);
1786
+ }
1787
+ return o;
1788
+ }, igray: () => {
1789
+ const o = [];
1790
+ for (let t = 0; t < 256; t++) {
1791
+ const e = t / 256;
1792
+ o.push([e, e, e, 1]);
1793
+ }
1794
+ return o;
1795
+ }, roseus: () => [[4528e-6, 4341e-6, 4307e-6, 1], [5625e-6, 6156e-6, 601e-5, 1], [6628e-6, 8293e-6, 8161e-6, 1], [7551e-6, 0.010738, 0.01079, 1], [8382e-6, 0.013482, 0.013941, 1], [9111e-6, 0.01652, 0.017662, 1], [9727e-6, 0.019846, 0.022009, 1], [0.010223, 0.023452, 0.027035, 1], [0.010593, 0.027331, 0.032799, 1], [0.010833, 0.031475, 0.039361, 1], [0.010941, 0.035875, 0.046415, 1], [0.010918, 0.04052, 0.053597, 1], [0.010768, 0.045158, 0.060914, 1], [0.010492, 0.049708, 0.068367, 1], [0.010098, 0.054171, 0.075954, 1], [9594e-6, 0.058549, 0.083672, 1], [8989e-6, 0.06284, 0.091521, 1], [8297e-6, 0.067046, 0.099499, 1], [753e-5, 0.071165, 0.107603, 1], [6704e-6, 0.075196, 0.11583, 1], [5838e-6, 0.07914, 0.124178, 1], [4949e-6, 0.082994, 0.132643, 1], [4062e-6, 0.086758, 0.141223, 1], [3198e-6, 0.09043, 0.149913, 1], [2382e-6, 0.09401, 0.158711, 1], [1643e-6, 0.097494, 0.167612, 1], [1009e-6, 0.100883, 0.176612, 1], [514e-6, 0.104174, 0.185704, 1], [187e-6, 0.107366, 0.194886, 1], [66e-6, 0.110457, 0.204151, 1], [186e-6, 0.113445, 0.213496, 1], [587e-6, 0.116329, 0.222914, 1], [1309e-6, 0.119106, 0.232397, 1], [2394e-6, 0.121776, 0.241942, 1], [3886e-6, 0.124336, 0.251542, 1], [5831e-6, 0.126784, 0.261189, 1], [8276e-6, 0.12912, 0.270876, 1], [0.011268, 0.131342, 0.280598, 1], [0.014859, 0.133447, 0.290345, 1], [0.0191, 0.135435, 0.300111, 1], [0.024043, 0.137305, 0.309888, 1], [0.029742, 0.139054, 0.319669, 1], [0.036252, 0.140683, 0.329441, 1], [0.043507, 0.142189, 0.339203, 1], [0.050922, 0.143571, 0.348942, 1], [0.058432, 0.144831, 0.358649, 1], [0.066041, 0.145965, 0.368319, 1], [0.073744, 0.146974, 0.377938, 1], [0.081541, 0.147858, 0.387501, 1], [0.089431, 0.148616, 0.396998, 1], [0.097411, 0.149248, 0.406419, 1], [0.105479, 0.149754, 0.415755, 1], [0.113634, 0.150134, 0.424998, 1], [0.121873, 0.150389, 0.434139, 1], [0.130192, 0.150521, 0.443167, 1], [0.138591, 0.150528, 0.452075, 1], [0.147065, 0.150413, 0.460852, 1], [0.155614, 0.150175, 0.469493, 1], [0.164232, 0.149818, 0.477985, 1], [0.172917, 0.149343, 0.486322, 1], [0.181666, 0.148751, 0.494494, 1], [0.190476, 0.148046, 0.502493, 1], [0.199344, 0.147229, 0.510313, 1], [0.208267, 0.146302, 0.517944, 1], [0.217242, 0.145267, 0.52538, 1], [0.226264, 0.144131, 0.532613, 1], [0.235331, 0.142894, 0.539635, 1], [0.24444, 0.141559, 0.546442, 1], [0.253587, 0.140131, 0.553026, 1], [0.262769, 0.138615, 0.559381, 1], [0.271981, 0.137016, 0.5655, 1], [0.281222, 0.135335, 0.571381, 1], [0.290487, 0.133581, 0.577017, 1], [0.299774, 0.131757, 0.582404, 1], [0.30908, 0.129867, 0.587538, 1], [0.318399, 0.12792, 0.592415, 1], [0.32773, 0.125921, 0.597032, 1], [0.337069, 0.123877, 0.601385, 1], [0.346413, 0.121793, 0.605474, 1], [0.355758, 0.119678, 0.609295, 1], [0.365102, 0.11754, 0.612846, 1], [0.374443, 0.115386, 0.616127, 1], [0.383774, 0.113226, 0.619138, 1], [0.393096, 0.111066, 0.621876, 1], [0.402404, 0.108918, 0.624343, 1], [0.411694, 0.106794, 0.62654, 1], [0.420967, 0.104698, 0.628466, 1], [0.430217, 0.102645, 0.630123, 1], [0.439442, 0.100647, 0.631513, 1], [0.448637, 0.098717, 0.632638, 1], [0.457805, 0.096861, 0.633499, 1], [0.46694, 0.095095, 0.6341, 1], [0.47604, 0.093433, 0.634443, 1], [0.485102, 0.091885, 0.634532, 1], [0.494125, 0.090466, 0.63437, 1], [0.503104, 0.08919, 0.633962, 1], [0.512041, 0.088067, 0.633311, 1], [0.520931, 0.087108, 0.63242, 1], [0.529773, 0.086329, 0.631297, 1], [0.538564, 0.085738, 0.629944, 1], [0.547302, 0.085346, 0.628367, 1], [0.555986, 0.085162, 0.626572, 1], [0.564615, 0.08519, 0.624563, 1], [0.573187, 0.085439, 0.622345, 1], [0.581698, 0.085913, 0.619926, 1], [0.590149, 0.086615, 0.617311, 1], [0.598538, 0.087543, 0.614503, 1], [0.606862, 0.0887, 0.611511, 1], [0.61512, 0.090084, 0.608343, 1], [0.623312, 0.09169, 0.605001, 1], [0.631438, 0.093511, 0.601489, 1], [0.639492, 0.095546, 0.597821, 1], [0.647476, 0.097787, 0.593999, 1], [0.655389, 0.100226, 0.590028, 1], [0.66323, 0.102856, 0.585914, 1], [0.670995, 0.105669, 0.581667, 1], [0.678686, 0.108658, 0.577291, 1], [0.686302, 0.111813, 0.57279, 1], [0.69384, 0.115129, 0.568175, 1], [0.7013, 0.118597, 0.563449, 1], [0.708682, 0.122209, 0.558616, 1], [0.715984, 0.125959, 0.553687, 1], [0.723206, 0.12984, 0.548666, 1], [0.730346, 0.133846, 0.543558, 1], [0.737406, 0.13797, 0.538366, 1], [0.744382, 0.142209, 0.533101, 1], [0.751274, 0.146556, 0.527767, 1], [0.758082, 0.151008, 0.522369, 1], [0.764805, 0.155559, 0.516912, 1], [0.771443, 0.160206, 0.511402, 1], [0.777995, 0.164946, 0.505845, 1], [0.784459, 0.169774, 0.500246, 1], [0.790836, 0.174689, 0.494607, 1], [0.797125, 0.179688, 0.488935, 1], [0.803325, 0.184767, 0.483238, 1], [0.809435, 0.189925, 0.477518, 1], [0.815455, 0.19516, 0.471781, 1], [0.821384, 0.200471, 0.466028, 1], [0.827222, 0.205854, 0.460267, 1], [0.832968, 0.211308, 0.454505, 1], [0.838621, 0.216834, 0.448738, 1], [0.844181, 0.222428, 0.442979, 1], [0.849647, 0.22809, 0.43723, 1], [0.855019, 0.233819, 0.431491, 1], [0.860295, 0.239613, 0.425771, 1], [0.865475, 0.245471, 0.420074, 1], [0.870558, 0.251393, 0.414403, 1], [0.875545, 0.25738, 0.408759, 1], [0.880433, 0.263427, 0.403152, 1], [0.885223, 0.269535, 0.397585, 1], [0.889913, 0.275705, 0.392058, 1], [0.894503, 0.281934, 0.386578, 1], [0.898993, 0.288222, 0.381152, 1], [0.903381, 0.294569, 0.375781, 1], [0.907667, 0.300974, 0.370469, 1], [0.911849, 0.307435, 0.365223, 1], [0.915928, 0.313953, 0.360048, 1], [0.919902, 0.320527, 0.354948, 1], [0.923771, 0.327155, 0.349928, 1], [0.927533, 0.333838, 0.344994, 1], [0.931188, 0.340576, 0.340149, 1], [0.934736, 0.347366, 0.335403, 1], [0.938175, 0.354207, 0.330762, 1], [0.941504, 0.361101, 0.326229, 1], [0.944723, 0.368045, 0.321814, 1], [0.947831, 0.375039, 0.317523, 1], [0.950826, 0.382083, 0.313364, 1], [0.953709, 0.389175, 0.309345, 1], [0.956478, 0.396314, 0.305477, 1], [0.959133, 0.403499, 0.301766, 1], [0.961671, 0.410731, 0.298221, 1], [0.964093, 0.418008, 0.294853, 1], [0.966399, 0.425327, 0.291676, 1], [0.968586, 0.43269, 0.288696, 1], [0.970654, 0.440095, 0.285926, 1], [0.972603, 0.44754, 0.28338, 1], [0.974431, 0.455025, 0.281067, 1], [0.976139, 0.462547, 0.279003, 1], [0.977725, 0.470107, 0.277198, 1], [0.979188, 0.477703, 0.275666, 1], [0.980529, 0.485332, 0.274422, 1], [0.981747, 0.492995, 0.273476, 1], [0.98284, 0.50069, 0.272842, 1], [0.983808, 0.508415, 0.272532, 1], [0.984653, 0.516168, 0.27256, 1], [0.985373, 0.523948, 0.272937, 1], [0.985966, 0.531754, 0.273673, 1], [0.986436, 0.539582, 0.274779, 1], [0.98678, 0.547434, 0.276264, 1], [0.986998, 0.555305, 0.278135, 1], [0.987091, 0.563195, 0.280401, 1], [0.987061, 0.5711, 0.283066, 1], [0.986907, 0.579019, 0.286137, 1], [0.986629, 0.58695, 0.289615, 1], [0.986229, 0.594891, 0.293503, 1], [0.985709, 0.602839, 0.297802, 1], [0.985069, 0.610792, 0.302512, 1], [0.98431, 0.618748, 0.307632, 1], [0.983435, 0.626704, 0.313159, 1], [0.982445, 0.634657, 0.319089, 1], [0.981341, 0.642606, 0.32542, 1], [0.98013, 0.650546, 0.332144, 1], [0.978812, 0.658475, 0.339257, 1], [0.977392, 0.666391, 0.346753, 1], [0.97587, 0.67429, 0.354625, 1], [0.974252, 0.68217, 0.362865, 1], [0.972545, 0.690026, 0.371466, 1], [0.97075, 0.697856, 0.380419, 1], [0.968873, 0.705658, 0.389718, 1], [0.966921, 0.713426, 0.399353, 1], [0.964901, 0.721157, 0.409313, 1], [0.962815, 0.728851, 0.419594, 1], [0.960677, 0.7365, 0.430181, 1], [0.95849, 0.744103, 0.44107, 1], [0.956263, 0.751656, 0.452248, 1], [0.954009, 0.759153, 0.463702, 1], [0.951732, 0.766595, 0.475429, 1], [0.949445, 0.773974, 0.487414, 1], [0.947158, 0.781289, 0.499647, 1], [0.944885, 0.788535, 0.512116, 1], [0.942634, 0.795709, 0.524811, 1], [0.940423, 0.802807, 0.537717, 1], [0.938261, 0.809825, 0.550825, 1], [0.936163, 0.81676, 0.564121, 1], [0.934146, 0.823608, 0.577591, 1], [0.932224, 0.830366, 0.59122, 1], [0.930412, 0.837031, 0.604997, 1], [0.928727, 0.843599, 0.618904, 1], [0.927187, 0.850066, 0.632926, 1], [0.925809, 0.856432, 0.647047, 1], [0.92461, 0.862691, 0.661249, 1], [0.923607, 0.868843, 0.675517, 1], [0.92282, 0.874884, 0.689832, 1], [0.922265, 0.880812, 0.704174, 1], [0.921962, 0.886626, 0.718523, 1], [0.92193, 0.892323, 0.732859, 1], [0.922183, 0.897903, 0.747163, 1], [0.922741, 0.903364, 0.76141, 1], [0.92362, 0.908706, 0.77558, 1], [0.924837, 0.913928, 0.789648, 1], [0.926405, 0.919031, 0.80359, 1], [0.92834, 0.924015, 0.817381, 1], [0.930655, 0.928881, 0.830995, 1], [0.93336, 0.933631, 0.844405, 1], [0.936466, 0.938267, 0.857583, 1], [0.939982, 0.942791, 0.870499, 1], [0.943914, 0.947207, 0.883122, 1], [0.948267, 0.951519, 0.895421, 1], [0.953044, 0.955732, 0.907359, 1], [0.958246, 0.959852, 0.918901, 1], [0.963869, 0.963887, 0.930004, 1], [0.969909, 0.967845, 0.940623, 1], [0.976355, 0.971737, 0.950704, 1], [0.983195, 0.97558, 0.960181, 1], [0.990402, 0.979395, 0.968966, 1], [0.99793, 0.983217, 0.97692, 1]] };
1796
+ function re(o) {
1797
+ return o >= 1e3 ? (o / 1e3).toFixed(1) : Math.round(o).toString();
1798
+ }
1799
+ function oe(o) {
1800
+ return o >= 1e3 ? "kHz" : "Hz";
1801
+ }
1802
+ function ae(o, t, e, i, s) {
1803
+ const r = X(e, s);
1804
+ return function(n, l) {
1805
+ switch (l) {
1806
+ case "mel":
1807
+ return Ct(n);
1808
+ case "logarithmic":
1809
+ return St(n);
1810
+ case "bark":
1811
+ return Mt(n);
1812
+ case "erb":
1813
+ return Pt(n);
1814
+ default:
1815
+ return n;
1816
+ }
1817
+ }(r + o / t * (X(i, s) - r), s);
1818
+ }
1819
+ function le(o, t, e, i) {
1820
+ switch (this.bufferSize = o, this.sampleRate = t, this.bandwidth = 2 / o * (t / 2), this.sinTable = new Float32Array(o), this.cosTable = new Float32Array(o), this.windowValues = new Float32Array(o), this.reverseTable = new Uint32Array(o), this.peakBand = 0, this.peak = 0, e) {
1821
+ case "bartlett":
1822
+ for (let n = 0; n < o; n++) this.windowValues[n] = 2 / (o - 1) * ((o - 1) / 2 - Math.abs(n - (o - 1) / 2));
1823
+ break;
1824
+ case "bartlettHann":
1825
+ for (let n = 0; n < o; n++) this.windowValues[n] = 0.62 - 0.48 * Math.abs(n / (o - 1) - 0.5) - 0.38 * Math.cos(2 * Math.PI * n / (o - 1));
1826
+ break;
1827
+ case "blackman":
1828
+ i = i || 0.16;
1829
+ for (let n = 0; n < o; n++) this.windowValues[n] = (1 - i) / 2 - 0.5 * Math.cos(2 * Math.PI * n / (o - 1)) + i / 2 * Math.cos(4 * Math.PI * n / (o - 1));
1830
+ break;
1831
+ case "cosine":
1832
+ for (let n = 0; n < o; n++) this.windowValues[n] = Math.cos(Math.PI * n / (o - 1) - Math.PI / 2);
1833
+ break;
1834
+ case "gauss":
1835
+ i = i || 0.25;
1836
+ for (let n = 0; n < o; n++) this.windowValues[n] = Math.pow(Math.E, -0.5 * Math.pow((n - (o - 1) / 2) / (i * (o - 1) / 2), 2));
1837
+ break;
1838
+ case "hamming":
1839
+ for (let n = 0; n < o; n++) this.windowValues[n] = 0.54 - 0.46 * Math.cos(2 * Math.PI * n / (o - 1));
1840
+ break;
1841
+ case "hann":
1842
+ case void 0:
1843
+ for (let n = 0; n < o; n++) this.windowValues[n] = 0.5 * (1 - Math.cos(2 * Math.PI * n / (o - 1)));
1844
+ break;
1845
+ case "lanczoz":
1846
+ for (let n = 0; n < o; n++) this.windowValues[n] = Math.sin(Math.PI * (2 * n / (o - 1) - 1)) / (Math.PI * (2 * n / (o - 1) - 1));
1847
+ break;
1848
+ case "rectangular":
1849
+ for (let n = 0; n < o; n++) this.windowValues[n] = 1;
1850
+ break;
1851
+ case "triangular":
1852
+ for (let n = 0; n < o; n++) this.windowValues[n] = 2 / o * (o / 2 - Math.abs(n - (o - 1) / 2));
1853
+ break;
1854
+ default:
1855
+ throw Error("No such window function '" + e + "'");
1856
+ }
1857
+ let s = 1, r = o >> 1;
1858
+ for (; s < o; ) {
1859
+ for (let n = 0; n < s; n++) this.reverseTable[n + s] = this.reverseTable[n] + r;
1860
+ s <<= 1, r >>= 1;
1861
+ }
1862
+ for (let n = 0; n < o; n++) this.sinTable[n] = Math.sin(-Math.PI / n), this.cosTable[n] = Math.cos(-Math.PI / n);
1863
+ this.calculateSpectrum = function(n) {
1864
+ const l = this.bufferSize, h = this.cosTable, c = this.sinTable, a = this.reverseTable, d = new Float32Array(l), u = new Float32Array(l), p = 2 / this.bufferSize, b = Math.sqrt, x = new Float32Array(l / 2);
1865
+ let g, m, y;
1866
+ const w = Math.floor(Math.log(l) / Math.LN2);
1867
+ if (Math.pow(2, w) !== l) throw "Invalid buffer size, must be a power of 2.";
1868
+ if (l !== n.length) throw "Supplied buffer is not the same size as defined FFT. FFT Size: " + l + " Buffer Size: " + n.length;
1869
+ let v, f, C, W, S, M, E, L, T = 1;
1870
+ for (let P = 0; P < l; P++) d[P] = n[a[P]] * this.windowValues[a[P]], u[P] = 0;
1871
+ for (; T < l; ) {
1872
+ v = h[T], f = c[T], C = 1, W = 0;
1873
+ for (let P = 0; P < T; P++) {
1874
+ let Z = P;
1875
+ for (; Z < l; ) S = Z + T, M = C * d[S] - W * u[S], E = C * u[S] + W * d[S], d[S] = d[Z] - M, u[S] = u[Z] - E, d[Z] += M, u[Z] += E, Z += T << 1;
1876
+ L = C, C = L * v - W * f, W = L * f + W * v;
1877
+ }
1878
+ T <<= 1;
1879
+ }
1880
+ for (let P = 0, Z = l / 2; P < Z; P++) g = d[P], m = u[P], y = p * b(g * g + m * m), y > this.peak && (this.peakBand = P, this.peak = y), x[P] = y;
1881
+ return x;
1882
+ };
1883
+ }
1884
+ class he {
1885
+ constructor() {
1886
+ this.listeners = {};
1887
+ }
1888
+ on(t, e, i) {
1889
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
1890
+ const s = () => {
1891
+ this.un(t, s), this.un(t, e);
1892
+ };
1893
+ return this.on(t, s), s;
1894
+ }
1895
+ return () => this.un(t, e);
1896
+ }
1897
+ un(t, e) {
1898
+ var i;
1899
+ (i = this.listeners[t]) === null || i === void 0 || i.delete(e);
1900
+ }
1901
+ once(t, e) {
1902
+ return this.on(t, e, { once: !0 });
1903
+ }
1904
+ unAll() {
1905
+ this.listeners = {};
1906
+ }
1907
+ emit(t, ...e) {
1908
+ this.listeners[t] && this.listeners[t].forEach((i) => i(...e));
1909
+ }
1910
+ }
1911
+ class ce extends he {
1912
+ constructor(t) {
1913
+ super(), this.subscriptions = [], this.isDestroyed = !1, this.options = t;
1914
+ }
1915
+ onInit() {
1916
+ }
1917
+ _init(t) {
1918
+ this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = t, this.onInit();
1919
+ }
1920
+ destroy() {
1921
+ this.emit("destroy"), this.subscriptions.forEach((t) => t()), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
1922
+ }
1923
+ }
1924
+ function kt(o, t) {
1925
+ const e = t.xmlns ? document.createElementNS(t.xmlns, o) : document.createElement(o);
1926
+ for (const [i, s] of Object.entries(t)) if (i === "children" && s) for (const [r, n] of Object.entries(s)) n instanceof Node ? e.appendChild(n) : typeof n == "string" ? e.appendChild(document.createTextNode(n)) : e.appendChild(kt(r, n));
1927
+ else i === "style" ? Object.assign(e.style, s) : i === "textContent" ? e.textContent = s : e.setAttribute(i, s.toString());
1928
+ return e;
1929
+ }
1930
+ function A(o, t, e) {
1931
+ const i = kt(o, t || {});
1932
+ return e?.appendChild(i), i;
1933
+ }
1934
+ var Lt = null;
1935
+ try {
1936
+ var ue = typeof module < "u" && typeof module.require == "function" && module.require("worker_threads") || typeof __non_webpack_require__ == "function" && __non_webpack_require__("worker_threads") || typeof require == "function" && require("worker_threads");
1937
+ Lt = ue.Worker;
1938
+ } catch {
1939
+ }
1940
+ function de(o, t, e) {
1941
+ var i = function(n) {
1942
+ return Buffer.from(n, "base64").toString("utf8");
1943
+ }(o), s = i.indexOf(`
1944
+ `, 10) + 1, r = i.substring(s) + "";
1945
+ return function(n) {
1946
+ return new Lt(r, Object.assign({}, n, { eval: !0 }));
1947
+ };
1948
+ }
1949
+ function pe(o, t, e) {
1950
+ var i = function(l) {
1951
+ return atob(l);
1952
+ }(o), s = i.indexOf(`
1953
+ `, 10) + 1, r = i.substring(s) + "", n = new Blob([r], { type: "application/javascript" });
1954
+ return URL.createObjectURL(n);
1955
+ }
1956
+ var me = Object.prototype.toString.call(typeof process < "u" ? process : 0) === "[object process]";
1957
+ function ve(o, t, e) {
1958
+ return me ? de(o) : /* @__PURE__ */ function(i) {
1959
+ var s;
1960
+ return function(r) {
1961
+ return s = s || pe(i), new Worker(s, r);
1962
+ };
1963
+ }(o);
1964
+ }
1965
+ var fe = ve("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y29uc3QgdD0xZTMqTWF0aC5sb2coMTApLzEwNy45Mzk7ZnVuY3Rpb24gZSh0KXtyZXR1cm4gMjU5NSpNYXRoLmxvZzEwKDErdC83MDApfWZ1bmN0aW9uIGEodCl7cmV0dXJuIDcwMCooTWF0aC5wb3coMTAsdC8yNTk1KS0xKX1mdW5jdGlvbiByKHQpe3JldHVybiBNYXRoLmxvZzEwKE1hdGgubWF4KDEsdCkpfWZ1bmN0aW9uIHModCl7cmV0dXJuIE1hdGgucG93KDEwLHQpfWZ1bmN0aW9uIG4odCl7bGV0IGU9MjYuODEqdC8oMTk2MCt0KS0uNTM7cmV0dXJuIGU8MiYmKGUrPS4xNSooMi1lKSksZT4yMC4xJiYoZSs9LjIyKihlLTIwLjEpKSxlfWZ1bmN0aW9uIG8odCl7cmV0dXJuIHQ8MiYmKHQ9KHQtLjMpLy44NSksdD4yMC4xJiYodD0odCs0LjQyMikvMS4yMiksKHQrLjUzKS8oMjYuMjgtdCkqMTk2MH1mdW5jdGlvbiBsKGUpe3JldHVybiB0Kk1hdGgubG9nMTAoMSsuMDA0MzcqZSl9ZnVuY3Rpb24gaShlKXtyZXR1cm4oTWF0aC5wb3coMTAsZS90KS0xKS8uMDA0Mzd9ZnVuY3Rpb24gaCh0LGUsYSxyLHMpe2NvbnN0IG49cigwKSxvPXIoYS8yKSxsPUFycmF5LmZyb20oe2xlbmd0aDp0fSwoKCk9PkFycmF5KGUvMisxKS5maWxsKDApKSksaT1hL2U7Zm9yKGxldCBlPTA7ZTx0O2UrKyl7Y29uc3QgYT1zKG4rZS90KihvLW4pKSxyPU1hdGguZmxvb3IoYS9pKSxoPXIqaSxjPShhLWgpLygocisxKSppLWgpO2xbZV1bcl09MS1jLGxbZV1bcisxXT1jfXJldHVybiBsfWZ1bmN0aW9uIGModCxlKXtjb25zdCBhPWUubGVuZ3RoLHI9RmxvYXQzMkFycmF5LmZyb20oe2xlbmd0aDphfSwoKCk9PjApKTtmb3IobGV0IHM9MDtzPGE7cysrKWZvcihsZXQgYT0wO2E8dC5sZW5ndGg7YSsrKXJbc10rPXRbYV0qZVtzXVthXTtyZXR1cm4gcn1mdW5jdGlvbiB1KHQsZSxhLHIpe3N3aXRjaCh0aGlzLmJ1ZmZlclNpemU9dCx0aGlzLnNhbXBsZVJhdGU9ZSx0aGlzLmJhbmR3aWR0aD0yL3QqKGUvMiksdGhpcy5zaW5UYWJsZT1uZXcgRmxvYXQzMkFycmF5KHQpLHRoaXMuY29zVGFibGU9bmV3IEZsb2F0MzJBcnJheSh0KSx0aGlzLndpbmRvd1ZhbHVlcz1uZXcgRmxvYXQzMkFycmF5KHQpLHRoaXMucmV2ZXJzZVRhYmxlPW5ldyBVaW50MzJBcnJheSh0KSx0aGlzLnBlYWtCYW5kPTAsdGhpcy5wZWFrPTAsYSl7Y2FzZSJiYXJ0bGV0dCI6Zm9yKGxldCBlPTA7ZTx0O2UrKyl0aGlzLndpbmRvd1ZhbHVlc1tlXT0yLyh0LTEpKigodC0xKS8yLU1hdGguYWJzKGUtKHQtMSkvMikpO2JyZWFrO2Nhc2UiYmFydGxldHRIYW5uIjpmb3IobGV0IGU9MDtlPHQ7ZSsrKXRoaXMud2luZG93VmFsdWVzW2VdPS42Mi0uNDgqTWF0aC5hYnMoZS8odC0xKS0uNSktLjM4Kk1hdGguY29zKDIqTWF0aC5QSSplLyh0LTEpKTticmVhaztjYXNlImJsYWNrbWFuIjpyPXJ8fC4xNjtmb3IobGV0IGU9MDtlPHQ7ZSsrKXRoaXMud2luZG93VmFsdWVzW2VdPSgxLXIpLzItLjUqTWF0aC5jb3MoMipNYXRoLlBJKmUvKHQtMSkpK3IvMipNYXRoLmNvcyg0Kk1hdGguUEkqZS8odC0xKSk7YnJlYWs7Y2FzZSJjb3NpbmUiOmZvcihsZXQgZT0wO2U8dDtlKyspdGhpcy53aW5kb3dWYWx1ZXNbZV09TWF0aC5jb3MoTWF0aC5QSSplLyh0LTEpLU1hdGguUEkvMik7YnJlYWs7Y2FzZSJnYXVzcyI6cj1yfHwuMjU7Zm9yKGxldCBlPTA7ZTx0O2UrKyl0aGlzLndpbmRvd1ZhbHVlc1tlXT1NYXRoLnBvdyhNYXRoLkUsLS41Kk1hdGgucG93KChlLSh0LTEpLzIpLyhyKih0LTEpLzIpLDIpKTticmVhaztjYXNlImhhbW1pbmciOmZvcihsZXQgZT0wO2U8dDtlKyspdGhpcy53aW5kb3dWYWx1ZXNbZV09LjU0LS40NipNYXRoLmNvcygyKk1hdGguUEkqZS8odC0xKSk7YnJlYWs7Y2FzZSJoYW5uIjpjYXNlIHZvaWQgMDpmb3IobGV0IGU9MDtlPHQ7ZSsrKXRoaXMud2luZG93VmFsdWVzW2VdPS41KigxLU1hdGguY29zKDIqTWF0aC5QSSplLyh0LTEpKSk7YnJlYWs7Y2FzZSJsYW5jem96Ijpmb3IobGV0IGU9MDtlPHQ7ZSsrKXRoaXMud2luZG93VmFsdWVzW2VdPU1hdGguc2luKE1hdGguUEkqKDIqZS8odC0xKS0xKSkvKE1hdGguUEkqKDIqZS8odC0xKS0xKSk7YnJlYWs7Y2FzZSJyZWN0YW5ndWxhciI6Zm9yKGxldCBlPTA7ZTx0O2UrKyl0aGlzLndpbmRvd1ZhbHVlc1tlXT0xO2JyZWFrO2Nhc2UidHJpYW5ndWxhciI6Zm9yKGxldCBlPTA7ZTx0O2UrKyl0aGlzLndpbmRvd1ZhbHVlc1tlXT0yL3QqKHQvMi1NYXRoLmFicyhlLSh0LTEpLzIpKTticmVhaztkZWZhdWx0OnRocm93IEVycm9yKCJObyBzdWNoIHdpbmRvdyBmdW5jdGlvbiAnIithKyInIil9bGV0IHM9MSxuPXQ+PjE7Zm9yKDtzPHQ7KXtmb3IobGV0IHQ9MDt0PHM7dCsrKXRoaXMucmV2ZXJzZVRhYmxlW3Qrc109dGhpcy5yZXZlcnNlVGFibGVbdF0rbjtzPDw9MSxuPj49MX1mb3IobGV0IGU9MDtlPHQ7ZSsrKXRoaXMuc2luVGFibGVbZV09TWF0aC5zaW4oLU1hdGguUEkvZSksdGhpcy5jb3NUYWJsZVtlXT1NYXRoLmNvcygtTWF0aC5QSS9lKTt0aGlzLmNhbGN1bGF0ZVNwZWN0cnVtPWZ1bmN0aW9uKHQpe2NvbnN0IGU9dGhpcy5idWZmZXJTaXplLGE9dGhpcy5jb3NUYWJsZSxyPXRoaXMuc2luVGFibGUscz10aGlzLnJldmVyc2VUYWJsZSxuPW5ldyBGbG9hdDMyQXJyYXkoZSksbz1uZXcgRmxvYXQzMkFycmF5KGUpLGw9Mi90aGlzLmJ1ZmZlclNpemUsaT1NYXRoLnNxcnQsaD1uZXcgRmxvYXQzMkFycmF5KGUvMik7bGV0IGMsdSxmO2NvbnN0IE09TWF0aC5mbG9vcihNYXRoLmxvZyhlKS9NYXRoLkxOMik7aWYoTWF0aC5wb3coMixNKSE9PWUpdGhyb3ciSW52YWxpZCBidWZmZXIgc2l6ZSwgbXVzdCBiZSBhIHBvd2VyIG9mIDIuIjtpZihlIT09dC5sZW5ndGgpdGhyb3ciU3VwcGxpZWQgYnVmZmVyIGlzIG5vdCB0aGUgc2FtZSBzaXplIGFzIGRlZmluZWQgRkZULiBGRlQgU2l6ZTogIitlKyIgQnVmZmVyIFNpemU6ICIrdC5sZW5ndGg7bGV0IHcsYixkLHAsZyxtLGsseSxUPTE7Zm9yKGxldCBhPTA7YTxlO2ErKyluW2FdPXRbc1thXV0qdGhpcy53aW5kb3dWYWx1ZXNbc1thXV0sb1thXT0wO2Zvcig7VDxlOyl7dz1hW1RdLGI9cltUXSxkPTEscD0wO2ZvcihsZXQgdD0wO3Q8VDt0Kyspe2xldCBhPXQ7Zm9yKDthPGU7KWc9YStULG09ZCpuW2ddLXAqb1tnXSxrPWQqb1tnXStwKm5bZ10sbltnXT1uW2FdLW0sb1tnXT1vW2FdLWssblthXSs9bSxvW2FdKz1rLGErPVQ8PDE7eT1kLGQ9eSp3LXAqYixwPXkqYitwKnd9VDw8PTF9Zm9yKGxldCB0PTAsYT1lLzI7dDxhO3QrKyljPW5bdF0sdT1vW3RdLGY9bCppKGMqYyt1KnUpLGY+dGhpcy5wZWFrJiYodGhpcy5wZWFrQmFuZD10LHRoaXMucGVhaz1mKSxoW3RdPWY7cmV0dXJuIGh9fWxldCBmPW51bGw7c2VsZi5vbm1lc3NhZ2U9ZnVuY3Rpb24odCl7Y29uc3R7dHlwZTpNLGlkOncsYXVkaW9EYXRhOmIsb3B0aW9uczpkfT10LmRhdGE7aWYoImNhbGN1bGF0ZUZyZXF1ZW5jaWVzIj09PU0pdHJ5e2NvbnN0IHQ9ZnVuY3Rpb24odCxNKXtjb25zdHtzdGFydFRpbWU6dyxlbmRUaW1lOmIsc2FtcGxlUmF0ZTpkLGZmdFNhbXBsZXM6cCx3aW5kb3dGdW5jOmcsYWxwaGE6bSxub3ZlcmxhcDprLHNjYWxlOnksZ2FpbkRCOlQscmFuZ2VEQjpGLHNwbGl0Q2hhbm5lbHM6SX09TSxWPU1hdGguZmxvb3IodypkKSxBPU1hdGguZmxvb3IoYipkKSxQPUk/dC5sZW5ndGg6MTtmJiZmLmJ1ZmZlclNpemU9PT1wfHwoZj1uZXcgdShwLGQsZyxtfHwuMTYpKTtjb25zdCBTPWZ1bmN0aW9uKHQsYyx1LGYpe3N3aXRjaCh0KXtjYXNlIm1lbCI6cmV0dXJuIGgoYyx1LGYsZSxhKTtjYXNlImxvZ2FyaXRobWljIjpyZXR1cm4gaChjLHUsZixyLHMpO2Nhc2UiYmFyayI6cmV0dXJuIGgoYyx1LGYsbixvKTtjYXNlImVyYiI6cmV0dXJuIGgoYyx1LGYsbCxpKTtkZWZhdWx0OnJldHVybiBudWxsfX0oeSxwLzIscCxkKTtsZXQgej1rfHxNYXRoLm1heCgwLE1hdGgucm91bmQoLjUqcCkpO2NvbnN0IHY9LjUqcDt6PU1hdGgubWluKHosdik7Y29uc3QgQj1NYXRoLm1heCg2NCwuMjUqcCkscT1NYXRoLm1heChCLHAteikseD1bXTtmb3IobGV0IGU9MDtlPFA7ZSsrKXtjb25zdCBhPXRbZV0scj1bXTtmb3IobGV0IHQ9Vjt0K3A8QTt0Kz1xKXtjb25zdCBlPWEuc2xpY2UodCx0K3ApO2xldCBzPWYuY2FsY3VsYXRlU3BlY3RydW0oZSk7UyYmKHM9YyhzLFMpKTtjb25zdCBuPW5ldyBVaW50OEFycmF5KHMubGVuZ3RoKSxvPVQrRjtmb3IobGV0IHQ9MDt0PHMubGVuZ3RoO3QrKyl7Y29uc3QgZT1zW3RdPjFlLTEyP3NbdF06MWUtMTIsYT0yMCpNYXRoLmxvZzEwKGUpO25bdF09YTwtbz8wOmE+LVQ/MjU1Ok1hdGgucm91bmQoKGErVCkvRioyNTUpfXIucHVzaChuKX14LnB1c2gocil9cmV0dXJuIHh9KGIsZCksTT17dHlwZToiZnJlcXVlbmNpZXNSZXN1bHQiLGlkOncscmVzdWx0OnR9O3NlbGYucG9zdE1lc3NhZ2UoTSl9Y2F0Y2godCl7Y29uc3QgZT17dHlwZToiZnJlcXVlbmNpZXNSZXN1bHQiLGlkOncsZXJyb3I6dCBpbnN0YW5jZW9mIEVycm9yP3QubWVzc2FnZTpTdHJpbmcodCl9O3NlbGYucG9zdE1lc3NhZ2UoZSl9fX0oKTsKLy8jIHNvdXJjZU1hcHBpbmdVUkw9c3BlY3Ryb2dyYW0td29ya2VyLmpzLm1hcAoK");
1966
+ class R extends ce {
1967
+ static create(t) {
1968
+ return new R(t || {});
1969
+ }
1970
+ constructor(t) {
1971
+ var e, i;
1972
+ if (super(t), this.canvases = [], this.useWebWorker = !1, this.worker = null, this.workerPromises = /* @__PURE__ */ new Map(), this.cachedFrequencies = null, this.cachedResampledData = null, this.cachedBuffer = null, this.cachedWidth = 0, this.renderTimeout = null, this.isRendering = !1, this.lastZoomLevel = 0, this.renderThrottleMs = 50, this.zoomThreshold = 0.05, this.drawnCanvases = {}, this.pendingBitmaps = /* @__PURE__ */ new Set(), this.isScrollable = !1, this.scrollUnsubscribe = null, this.frequenciesDataUrl = t.frequenciesDataUrl, this.frequenciesDataUrl && !t.sampleRate) throw new Error("sampleRate option is required when using frequenciesDataUrl");
1973
+ this.container = typeof t.container == "string" ? document.querySelector(t.container) : t.container, this.useWebWorker = t.useWebWorker === !0, this.colorMap = function(s = "roseus") {
1974
+ if (s && typeof s != "string") {
1975
+ if (s.length < 256) throw new Error("Colormap must contain 256 elements");
1976
+ for (let n = 0; n < s.length; n++) if (s[n].length !== 4) throw new Error("ColorMap entries must contain 4 values");
1977
+ return s;
1978
+ }
1979
+ const r = ne[s];
1980
+ if (!r) throw Error("No such colormap '" + s + "'");
1981
+ return r();
1982
+ }(t.colorMap), this.fftSamples = t.fftSamples || 512, this.height = t.height || 200, this.noverlap = t.noverlap || null, this.windowFunc = t.windowFunc || "hann", this.alpha = t.alpha, this.frequencyMin = t.frequencyMin || 0, this.frequencyMax = t.frequencyMax || 0, this.gainDB = (e = t.gainDB) !== null && e !== void 0 ? e : 20, this.rangeDB = (i = t.rangeDB) !== null && i !== void 0 ? i : 80, this.scale = t.scale || "mel", this.numMelFilters = this.fftSamples / 2, this.numLogFilters = this.fftSamples / 2, this.numBarkFilters = this.fftSamples / 2, this.numErbFilters = this.fftSamples / 2, t.maxCanvasWidth && (R.MAX_CANVAS_WIDTH = t.maxCanvasWidth), this.renderThrottleMs = 50, this.zoomThreshold = 0.05, this.createWrapper(), this.createCanvas(), this.useWebWorker && this.initializeWorker();
1983
+ }
1984
+ initializeWorker() {
1985
+ if (typeof window < "u" && typeof Worker < "u") try {
1986
+ this.worker = new fe(), this.worker.onmessage = (t) => {
1987
+ const { type: e, id: i, result: s, error: r } = t.data;
1988
+ if (e === "frequenciesResult") {
1989
+ const n = this.workerPromises.get(i);
1990
+ n && (this.workerPromises.delete(i), r ? n.reject(new Error(r)) : n.resolve(s));
1991
+ }
1992
+ }, this.worker.onerror = (t) => {
1993
+ console.warn("Spectrogram worker error, falling back to main thread:", t), this.worker = null;
1994
+ };
1995
+ } catch (t) {
1996
+ console.warn("Failed to initialize worker, falling back to main thread:", t), this.worker = null;
1997
+ }
1998
+ else console.warn("Worker not available in this environment, using main thread calculation");
1999
+ }
2000
+ onInit() {
2001
+ this.wrapper || this.createWrapper(), this.canvasContainer || this.createCanvas(), this.container = this.wavesurfer.getWrapper(), this.container.appendChild(this.wrapper), this.wavesurfer.options.fillParent && Object.assign(this.wrapper.style, { width: "100%", overflowX: "hidden", overflowY: "hidden" }), this.subscriptions.push(this.wavesurfer.on("redraw", () => this.throttledRender())), this.wavesurfer.getDecodedData() && setTimeout(() => {
2002
+ this.throttledRender();
2003
+ }, 0);
2004
+ }
2005
+ destroy() {
2006
+ this.unAll(), this.wavesurfer && (typeof this._onReady == "function" && this.wavesurfer.un("ready", this._onReady), typeof this._onRender == "function" && this.wavesurfer.un("redraw", this._onRender)), this.renderTimeout && (clearTimeout(this.renderTimeout), this.renderTimeout = null), this.scrollUnsubscribe && (this.scrollUnsubscribe(), this.scrollUnsubscribe = null), this.pendingBitmaps.clear(), this.worker && (this.worker.terminate(), this.worker = null), this.cachedFrequencies = null, this.cachedResampledData = null, this.cachedBuffer = null, this.clearCanvases(), this.canvasContainer && (this.canvasContainer.remove(), this.canvasContainer = null), this.wrapper && (this.wrapper.remove(), this.wrapper = null), this.labelsEl && (this.labelsEl.remove(), this.labelsEl = null), this.container = null, this.isRendering = !1, this.lastZoomLevel = 0, this.wavesurfer = null, this.util = null, this.options = null, super.destroy();
2007
+ }
2008
+ loadFrequenciesData(t) {
2009
+ return O(this, void 0, void 0, function* () {
2010
+ const e = yield fetch(t);
2011
+ if (!e.ok) throw new Error("Unable to fetch frequencies data");
2012
+ const i = yield e.json();
2013
+ this.drawSpectrogram(i);
2014
+ });
2015
+ }
2016
+ getFrequenciesData() {
2017
+ return O(this, void 0, void 0, function* () {
2018
+ var t;
2019
+ const e = (t = this.wavesurfer) === null || t === void 0 ? void 0 : t.getDecodedData();
2020
+ if (!e) return null;
2021
+ if (this.cachedBuffer === e && this.cachedFrequencies) return this.cachedFrequencies;
2022
+ {
2023
+ const i = yield this.getFrequencies(e);
2024
+ return this.cachedFrequencies = i, this.cachedBuffer = e, i;
2025
+ }
2026
+ });
2027
+ }
2028
+ clearCache() {
2029
+ this.cachedFrequencies = null, this.cachedResampledData = null, this.cachedBuffer = null, this.cachedWidth = 0, this.lastZoomLevel = 0;
2030
+ }
2031
+ createWrapper() {
2032
+ var t, e;
2033
+ this.wrapper = A("div", { style: { display: "block", position: "relative", userSelect: "none" } }), this.options.labels && (this.labelsEl = A("canvas", { part: "spec-labels", style: { position: "absolute", zIndex: 9, width: "55px", height: "100%" } }, this.wrapper)), this._onWrapperClick = (t = this.wrapper, e = this.emit.bind(this), (i) => {
2034
+ const s = t.getBoundingClientRect(), r = i.clientX - s.left, n = s.width;
2035
+ e("click", r / n);
2036
+ }), this.wrapper.addEventListener("click", this._onWrapperClick);
2037
+ }
2038
+ createCanvas() {
2039
+ this.canvasContainer = A("div", { style: { position: "absolute", left: 0, top: 0, width: "100%", height: "100%", zIndex: 4 } }, this.wrapper);
2040
+ }
2041
+ createSingleCanvas(t, e, i) {
2042
+ const s = A("canvas", { style: { position: "absolute", left: `${Math.round(i)}px`, top: "0", width: `${t}px`, height: `${e}px`, zIndex: 4 } });
2043
+ return s.width = Math.round(t), s.height = Math.round(e), this.canvasContainer.appendChild(s), s;
2044
+ }
2045
+ clearCanvases() {
2046
+ this.canvases.forEach((t) => t.remove()), this.canvases = [], this.drawnCanvases = {};
2047
+ }
2048
+ clearExcessCanvases() {
2049
+ Object.keys(this.drawnCanvases).length > R.MAX_NODES && this.clearCanvases();
2050
+ }
2051
+ throttledRender() {
2052
+ var t;
2053
+ if (this.renderTimeout && clearTimeout(this.renderTimeout), this.isRendering) return;
2054
+ const e = ((t = this.wavesurfer) === null || t === void 0 ? void 0 : t.options.minPxPerSec) || 0;
2055
+ Math.abs(e - this.lastZoomLevel) / Math.max(e, this.lastZoomLevel, 1) < this.zoomThreshold && this.cachedFrequencies ? this.renderTimeout = window.setTimeout(() => {
2056
+ this.fastRender();
2057
+ }, this.renderThrottleMs) : this.renderTimeout = window.setTimeout(() => {
2058
+ this.render();
2059
+ }, this.renderThrottleMs);
2060
+ }
2061
+ render() {
2062
+ return O(this, void 0, void 0, function* () {
2063
+ var t, e;
2064
+ if (!this.isRendering) {
2065
+ this.isRendering = !0;
2066
+ try {
2067
+ this.frequenciesDataUrl ? yield this.loadFrequenciesData(this.frequenciesDataUrl) : !((t = this.wavesurfer) === null || t === void 0) && t.getDecodedData() && (yield this.getFrequenciesData(), this.drawSpectrogram(this.cachedFrequencies)), this.lastZoomLevel = ((e = this.wavesurfer) === null || e === void 0 ? void 0 : e.options.minPxPerSec) || 0;
2068
+ } finally {
2069
+ this.isRendering = !1;
2070
+ }
2071
+ }
2072
+ });
2073
+ }
2074
+ fastRender() {
2075
+ var t;
2076
+ if (!this.isRendering && this.cachedFrequencies) {
2077
+ this.isRendering = !0;
2078
+ try {
2079
+ this.drawSpectrogram(this.cachedFrequencies), this.lastZoomLevel = ((t = this.wavesurfer) === null || t === void 0 ? void 0 : t.options.minPxPerSec) || 0;
2080
+ } finally {
2081
+ this.isRendering = !1;
2082
+ }
2083
+ }
2084
+ }
2085
+ drawSpectrogram(t) {
2086
+ var e, i, s;
2087
+ isNaN(t[0][0]) || (t = [t]), this.clearCanvases();
2088
+ const r = this.height * t.length;
2089
+ this.wrapper.style.height = r + "px";
2090
+ const n = this.getWidth(), l = Math.min(R.MAX_CANVAS_WIDTH, n);
2091
+ if (n === 0 || r === 0) return;
2092
+ const h = Math.ceil(n / l);
2093
+ let c;
2094
+ const a = ((e = t[0]) === null || e === void 0 ? void 0 : e.length) || 0;
2095
+ n !== a ? this.cachedResampledData && this.cachedWidth === n ? c = this.cachedResampledData : (c = this.efficientResample(t, n), this.cachedResampledData = c, this.cachedWidth = n) : c = t;
2096
+ const d = !((i = this.buffer) === null || i === void 0) && i.sampleRate ? this.buffer.sampleRate / 2 : (this.options.sampleRate || 0) / 2, u = this.frequencyMin, p = this.frequencyMax, b = p > d, x = b ? this.colorMap[this.colorMap.length - 1] : null, g = (m) => {
2097
+ if (m < 0 || m >= h || this.drawnCanvases[m]) return;
2098
+ this.drawnCanvases[m] = !0;
2099
+ const y = m * l, w = Math.min(l, n - y);
2100
+ if (w <= 0) return;
2101
+ const v = this.createSingleCanvas(w, r, y);
2102
+ this.canvases.push(v);
2103
+ const f = v.getContext("2d");
2104
+ if (f) {
2105
+ b && x && (f.fillStyle = `rgba(${255 * x[0]}, ${255 * x[1]}, ${255 * x[2]}, ${x[3]})`, f.fillRect(0, 0, w, r));
2106
+ for (let C = 0; C < c.length; C++) this.drawSpectrogramSegment(c[C], f, w, this.height, C * this.height, y, n, d, u, p);
2107
+ }
2108
+ };
2109
+ if (this.isScrollable = n > this.getWrapperWidth(), this.scrollUnsubscribe && (this.scrollUnsubscribe(), this.scrollUnsubscribe = null), !this.isScrollable || h <= 3) for (let m = 0; m < h; m++) g(m);
2110
+ else {
2111
+ const m = () => {
2112
+ var f;
2113
+ const C = (f = this.wavesurfer) === null || f === void 0 ? void 0 : f.getWrapper();
2114
+ if (!C) return;
2115
+ const W = C.scrollLeft || 0, S = C.clientWidth || 0, M = Math.max(0, W - 0.5 * S), E = Math.min(n, W + 1.5 * S), L = Math.floor(M / n * h), T = Math.min(Math.ceil(E / n * h), h - 1);
2116
+ Object.keys(this.drawnCanvases).length > R.MAX_NODES && this.clearExcessCanvases();
2117
+ for (let P = L; P <= T; P++) g(P);
2118
+ };
2119
+ m();
2120
+ let y = null;
2121
+ const w = () => {
2122
+ y && clearTimeout(y), y = window.setTimeout(m, 16);
2123
+ }, v = (s = this.wavesurfer) === null || s === void 0 ? void 0 : s.getWrapper();
2124
+ v && (v.addEventListener("scroll", w, { passive: !0 }), this.scrollUnsubscribe = () => {
2125
+ v.removeEventListener("scroll", w), y && clearTimeout(y);
2126
+ });
2127
+ }
2128
+ this.options.labels && this.loadLabels(this.options.labelsBackground, "12px", "12px", "", this.options.labelsColor, this.options.labelsHzColor || this.options.labelsColor, "center", "#specLabels", t.length), this.emit("ready");
2129
+ }
2130
+ drawSpectrogramSegment(t, e, i, s, r, n, l, h, c, a) {
2131
+ const d = t[0].length, u = Math.floor(n / l * t.length), p = Math.min(Math.ceil((n + i) / l * t.length), t.length), b = t.slice(u, p);
2132
+ if (b.length === 0) return;
2133
+ const x = b.length, g = new ImageData(x, d), m = g.data;
2134
+ this.fillImageDataQuality(m, b, x, d);
2135
+ const y = X(c, this.scale) / X(h, this.scale), w = X(a, this.scale) / X(h, this.scale), v = Math.min(1, w), f = createImageBitmap(g, 0, Math.round(d * (1 - v)), x, Math.round(d * (v - y)));
2136
+ this.pendingBitmaps.add(f), f.then((C) => {
2137
+ if (this.pendingBitmaps.delete(f), e.canvas.parentNode) {
2138
+ const W = s * v / w, S = r + s * (1 - v / w);
2139
+ e.drawImage(C, 0, S, i, W), "close" in C && C.close();
2140
+ }
2141
+ }).catch((C) => {
2142
+ this.pendingBitmaps.delete(f);
2143
+ });
2144
+ }
2145
+ getWidth() {
2146
+ return this.wavesurfer.getWrapper().offsetWidth;
2147
+ }
2148
+ getWrapperWidth() {
2149
+ var t, e;
2150
+ return ((e = (t = this.wavesurfer) === null || t === void 0 ? void 0 : t.getWrapper()) === null || e === void 0 ? void 0 : e.clientWidth) || 0;
2151
+ }
2152
+ calculateFrequenciesWithWorker(t) {
2153
+ return O(this, void 0, void 0, function* () {
2154
+ var e, i;
2155
+ if (!this.worker) throw new Error("Worker not available");
2156
+ const s = this.fftSamples, r = ((e = this.options.splitChannels) !== null && e !== void 0 ? e : !((i = this.wavesurfer) === null || i === void 0) && i.options.splitChannels) ? t.numberOfChannels : 1;
2157
+ let n = this.noverlap;
2158
+ if (!n) {
2159
+ const a = this.getWidth(), d = t.length / a;
2160
+ n = Math.max(0, Math.round(s - d));
2161
+ }
2162
+ const l = [];
2163
+ for (let a = 0; a < r; a++) l.push(t.getChannelData(a));
2164
+ const h = `${Date.now()}_${Math.random()}`, c = new Promise((a, d) => {
2165
+ this.workerPromises.set(h, { resolve: a, reject: d }), setTimeout(() => {
2166
+ this.workerPromises.has(h) && (this.workerPromises.delete(h), d(new Error("Worker timeout")));
2167
+ }, 3e4);
2168
+ });
2169
+ return this.worker.postMessage({ type: "calculateFrequencies", id: h, audioData: l, options: { startTime: 0, endTime: t.duration, sampleRate: t.sampleRate, fftSamples: this.fftSamples, windowFunc: this.windowFunc, alpha: this.alpha, noverlap: n, scale: this.scale, gainDB: this.gainDB, rangeDB: this.rangeDB, splitChannels: this.options.splitChannels || !1 } }), c;
2170
+ });
2171
+ }
2172
+ getFrequencies(t) {
2173
+ return O(this, void 0, void 0, function* () {
2174
+ var e, i;
2175
+ if (this.frequencyMax = this.frequencyMax || t.sampleRate / 2, this.buffer = t, !t) return [];
2176
+ if (this.useWebWorker && this.worker) try {
2177
+ return yield this.calculateFrequenciesWithWorker(t);
2178
+ } catch (g) {
2179
+ console.warn("Worker calculation failed, falling back to main thread:", g);
2180
+ }
2181
+ const s = this.fftSamples, r = ((e = this.options.splitChannels) !== null && e !== void 0 ? e : !((i = this.wavesurfer) === null || i === void 0) && i.options.splitChannels) ? t.numberOfChannels : 1, n = t.sampleRate, l = [];
2182
+ let h = this.noverlap;
2183
+ if (!h) {
2184
+ const g = this.getWidth(), m = t.length / g;
2185
+ h = Math.max(0, Math.round(s - m));
2186
+ }
2187
+ let c = h || Math.max(0, Math.round(0.5 * s));
2188
+ const a = 0.5 * s;
2189
+ c = Math.min(c, a);
2190
+ const d = Math.max(64, 0.25 * s), u = Math.max(d, s - c), p = new le(s, n, this.windowFunc, this.alpha), b = this.fftSamples / 2, x = function(g, m, y, w) {
2191
+ switch (g) {
2192
+ case "mel":
2193
+ return j(m, y, w, wt, Ct);
2194
+ case "logarithmic":
2195
+ return j(m, y, w, xt, St);
2196
+ case "bark":
2197
+ return j(m, y, w, Wt, Mt);
2198
+ case "erb":
2199
+ return j(m, y, w, Et, Pt);
2200
+ default:
2201
+ return null;
2202
+ }
2203
+ }(this.scale, b, this.fftSamples, n);
2204
+ for (let g = 0; g < r; g++) {
2205
+ const m = t.getChannelData(g), y = [];
2206
+ for (let w = 0; w + s < m.length; w += u) {
2207
+ const v = m.slice(w, w + s);
2208
+ let f = p.calculateSpectrum(v);
2209
+ x && (f = se(f, x));
2210
+ const C = new Uint8Array(f.length), W = this.gainDB + this.rangeDB;
2211
+ for (let S = 0; S < f.length; S++) {
2212
+ const M = f[S] > 1e-12 ? f[S] : 1e-12, E = 20 * Math.log10(M);
2213
+ E < -W ? C[S] = 0 : E > -this.gainDB ? C[S] = 255 : C[S] = Math.round((E + this.gainDB) / this.rangeDB * 255);
2214
+ }
2215
+ y.push(C);
2216
+ }
2217
+ l.push(y);
2218
+ }
2219
+ return l;
2220
+ });
2221
+ }
2222
+ loadLabels(t, e, i, s, r, n, l, h, c) {
2223
+ t = t || "rgba(68,68,68,0)", e = e || "12px", i = i || "12px", s = s || "Helvetica", r = r || "#fff", n = n || "#fff", l = l || "center";
2224
+ const a = this.height || 512, d = a / 256 * 5;
2225
+ this.frequencyMin, this.frequencyMax;
2226
+ const u = this.labelsEl.getContext("2d"), p = window.devicePixelRatio;
2227
+ if (this.labelsEl.height = this.height * c * p, this.labelsEl.width = 55 * p, u.scale(p, p), u) for (let b = 0; b < c; b++) {
2228
+ let x;
2229
+ for (u.fillStyle = t, u.fillRect(0, b * a, 55, (1 + b) * a), u.fill(), x = 0; x <= d; x++) {
2230
+ u.textAlign = l, u.textBaseline = "middle";
2231
+ const g = ae(x, d, this.frequencyMin, this.frequencyMax, this.scale), m = re(g), y = oe(g), w = 16;
2232
+ let v = (1 + b) * a - x / d * a;
2233
+ v = Math.min(Math.max(v, b * a + 10), (1 + b) * a - 10), u.fillStyle = n, u.font = i + " " + s, u.fillText(y, w + 24, v), u.fillStyle = r, u.font = e + " " + s, u.fillText(m, w, v);
2234
+ }
2235
+ }
2236
+ }
2237
+ efficientResample(t, e) {
2238
+ return t.map((i) => this.resampleChannel(i, e));
2239
+ }
2240
+ resampleChannel(t, e) {
2241
+ var i;
2242
+ const s = t.length, r = ((i = t[0]) === null || i === void 0 ? void 0 : i.length) || 0;
2243
+ if (s === e || e === 0) return t;
2244
+ const n = s / e, l = new Array(e);
2245
+ if (n >= 1) for (let h = 0; h < e; h++) {
2246
+ const c = Math.floor(h * n), a = Math.min(Math.ceil((h + 1) * n), s), d = a - c, u = new Uint8Array(r);
2247
+ if (d === 1) u.set(t[c]);
2248
+ else for (let p = 0; p < r; p++) {
2249
+ let b = 0;
2250
+ for (let x = c; x < a; x++) b += t[x][p];
2251
+ u[p] = Math.round(b / d);
2252
+ }
2253
+ l[h] = u;
2254
+ }
2255
+ else for (let h = 0; h < e; h++) {
2256
+ const c = h * n, a = Math.floor(c), d = Math.min(a + 1, s - 1), u = c - a, p = new Uint8Array(r);
2257
+ if (u === 0 || a === d) p.set(t[a]);
2258
+ else {
2259
+ const b = t[a], x = t[d], g = 1 - u;
2260
+ for (let m = 0; m < r; m++) p[m] = Math.round(b[m] * g + x[m] * u);
2261
+ }
2262
+ l[h] = p;
2263
+ }
2264
+ return l;
2265
+ }
2266
+ fillImageDataQuality(t, e, i, s) {
2267
+ const r = this.colorMap;
2268
+ for (let n = 0; n < i; n++) {
2269
+ const l = e[n];
2270
+ for (let h = 0; h < s; h++) {
2271
+ const c = r[l[h]], a = 4 * ((s - h - 1) * i + n);
2272
+ t[a] = 255 * c[0], t[a + 1] = 255 * c[1], t[a + 2] = 255 * c[2], t[a + 3] = 255 * c[3];
2273
+ }
2274
+ }
2275
+ }
2276
+ }
2277
+ R.MAX_CANVAS_WIDTH = 3e4, R.MAX_NODES = 10;
2278
+ const Ae = ({
2279
+ waveSurfer: o,
2280
+ spectrogramOptions: t = {}
2281
+ }) => {
2282
+ const { pluginInstance: e, createPlugin: i } = z(
2283
+ R,
2284
+ t
2285
+ );
2286
+ return D(() => {
2287
+ o.value && i(o.value);
2288
+ }), {
2289
+ spectrogramPlugin: e
330
2290
  };
2291
+ }, Fe = ({
2292
+ containerRef: o,
2293
+ options: t,
2294
+ spectrogramOptions: e = {}
2295
+ }) => G(
2296
+ R,
2297
+ { containerRef: o, options: t, pluginOptions: e }
2298
+ );
2299
+ let ge = class {
2300
+ constructor() {
2301
+ this.listeners = {};
2302
+ }
2303
+ on(t, e, i) {
2304
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
2305
+ const s = () => {
2306
+ this.un(t, s), this.un(t, e);
2307
+ };
2308
+ return this.on(t, s), s;
2309
+ }
2310
+ return () => this.un(t, e);
2311
+ }
2312
+ un(t, e) {
2313
+ var i;
2314
+ (i = this.listeners[t]) === null || i === void 0 || i.delete(e);
2315
+ }
2316
+ once(t, e) {
2317
+ return this.on(t, e, { once: !0 });
2318
+ }
2319
+ unAll() {
2320
+ this.listeners = {};
2321
+ }
2322
+ emit(t, ...e) {
2323
+ this.listeners[t] && this.listeners[t].forEach((i) => i(...e));
2324
+ }
2325
+ }, be = class extends ge {
2326
+ constructor(t) {
2327
+ super(), this.subscriptions = [], this.isDestroyed = !1, this.options = t;
2328
+ }
2329
+ onInit() {
2330
+ }
2331
+ _init(t) {
2332
+ this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = t, this.onInit();
2333
+ }
2334
+ destroy() {
2335
+ this.emit("destroy"), this.subscriptions.forEach((t) => t()), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
2336
+ }
331
2337
  };
2338
+ function Tt(o, t) {
2339
+ const e = t.xmlns ? document.createElementNS(t.xmlns, o) : document.createElement(o);
2340
+ for (const [i, s] of Object.entries(t)) if (i === "children" && s) for (const [r, n] of Object.entries(s)) n instanceof Node ? e.appendChild(n) : typeof n == "string" ? e.appendChild(document.createTextNode(n)) : e.appendChild(Tt(r, n));
2341
+ else i === "style" ? Object.assign(e.style, s) : i === "textContent" ? e.textContent = s : e.setAttribute(i, s.toString());
2342
+ return e;
2343
+ }
2344
+ function et(o, t, e) {
2345
+ const i = Tt(o, t || {});
2346
+ return e?.appendChild(i), i;
2347
+ }
2348
+ const ye = { lineWidth: 1, labelSize: 11, labelPreferLeft: !1, formatTimeCallback: (o) => `${Math.floor(o / 60)}:${`0${Math.floor(o) % 60}`.slice(-2)}` };
2349
+ let Dt = class Rt extends be {
2350
+ constructor(t) {
2351
+ super(t || {}), this.lastPointerMove = null, this.unsubscribe = () => {
2352
+ }, this.onPointerMove = (e) => {
2353
+ if (!this.wavesurfer) return;
2354
+ this.lastPointerMove = e;
2355
+ const i = this.wavesurfer.getWrapper().getBoundingClientRect(), { width: s } = i, r = e.clientX - i.left, n = Math.min(1, Math.max(0, r / s)), l = Math.min(s - this.options.lineWidth - 1, r);
2356
+ this.wrapper.style.transform = `translateX(${l}px)`, this.wrapper.style.opacity = "1";
2357
+ const h = this.wavesurfer.getDuration() || 0;
2358
+ this.label.textContent = this.options.formatTimeCallback(h * n);
2359
+ const c = this.label.offsetWidth, a = this.options.labelPreferLeft ? l - c > 0 : l + c > s;
2360
+ this.label.style.transform = a ? `translateX(-${c + this.options.lineWidth}px)` : "", this.emit("hover", n);
2361
+ }, this.onPointerLeave = () => {
2362
+ this.wrapper.style.opacity = "0", this.lastPointerMove = null;
2363
+ }, this.options = Object.assign({}, ye, t), this.wrapper = et("div", { part: "hover" }), this.label = et("span", { part: "hover-label" }, this.wrapper);
2364
+ }
2365
+ static create(t) {
2366
+ return new Rt(t);
2367
+ }
2368
+ addUnits(t) {
2369
+ return `${t}${typeof t == "number" ? "px" : ""}`;
2370
+ }
2371
+ onInit() {
2372
+ if (!this.wavesurfer) throw Error("WaveSurfer is not initialized");
2373
+ const t = this.wavesurfer.options, e = this.options.lineColor || t.cursorColor || t.progressColor;
2374
+ Object.assign(this.wrapper.style, { position: "absolute", zIndex: 10, left: 0, top: 0, height: "100%", pointerEvents: "none", borderLeft: `${this.addUnits(this.options.lineWidth)} solid ${e}`, opacity: "0", transition: "opacity .1s ease-in" }), Object.assign(this.label.style, { display: "block", backgroundColor: this.options.labelBackground, color: this.options.labelColor, fontSize: `${this.addUnits(this.options.labelSize)}`, transition: "transform .1s ease-in", padding: "2px 3px" });
2375
+ const i = this.wavesurfer.getWrapper();
2376
+ i.appendChild(this.wrapper), i.addEventListener("pointermove", this.onPointerMove), i.addEventListener("pointerleave", this.onPointerLeave);
2377
+ const s = () => {
2378
+ this.lastPointerMove && this.onPointerMove(this.lastPointerMove);
2379
+ };
2380
+ this.wavesurfer.on("zoom", s), this.wavesurfer.on("scroll", s), this.unsubscribe = () => {
2381
+ var r, n;
2382
+ i.removeEventListener("pointermove", this.onPointerMove), i.removeEventListener("pointerleave", this.onPointerLeave), (r = this.wavesurfer) === null || r === void 0 || r.un("zoom", s), (n = this.wavesurfer) === null || n === void 0 || n.un("scroll", s);
2383
+ };
2384
+ }
2385
+ destroy() {
2386
+ super.destroy(), this.unsubscribe(), this.wrapper.remove();
2387
+ }
2388
+ };
2389
+ const He = ({
2390
+ waveSurfer: o,
2391
+ hoverOptions: t = {}
2392
+ }) => {
2393
+ const { pluginInstance: e, createPlugin: i } = z(
2394
+ Dt,
2395
+ t
2396
+ );
2397
+ return D(() => {
2398
+ o.value && i(o.value);
2399
+ }), {
2400
+ hoverPlugin: e
2401
+ };
2402
+ }, $e = ({
2403
+ containerRef: o,
2404
+ options: t,
2405
+ hoverOptions: e = {}
2406
+ }) => G(
2407
+ Dt,
2408
+ { containerRef: o, options: t, pluginOptions: e }
2409
+ );
2410
+ class Zt {
2411
+ constructor() {
2412
+ this.listeners = {};
2413
+ }
2414
+ on(t, e, i) {
2415
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
2416
+ const s = () => {
2417
+ this.un(t, s), this.un(t, e);
2418
+ };
2419
+ return this.on(t, s), s;
2420
+ }
2421
+ return () => this.un(t, e);
2422
+ }
2423
+ un(t, e) {
2424
+ var i;
2425
+ (i = this.listeners[t]) === null || i === void 0 || i.delete(e);
2426
+ }
2427
+ once(t, e) {
2428
+ return this.on(t, e, { once: !0 });
2429
+ }
2430
+ unAll() {
2431
+ this.listeners = {};
2432
+ }
2433
+ emit(t, ...e) {
2434
+ this.listeners[t] && this.listeners[t].forEach((i) => i(...e));
2435
+ }
2436
+ }
2437
+ class we extends Zt {
2438
+ constructor(t) {
2439
+ super(), this.subscriptions = [], this.isDestroyed = !1, this.options = t;
2440
+ }
2441
+ onInit() {
2442
+ }
2443
+ _init(t) {
2444
+ this.isDestroyed && (this.subscriptions = [], this.isDestroyed = !1), this.wavesurfer = t, this.onInit();
2445
+ }
2446
+ destroy() {
2447
+ this.emit("destroy"), this.subscriptions.forEach((t) => t()), this.subscriptions = [], this.isDestroyed = !0, this.wavesurfer = void 0;
2448
+ }
2449
+ }
2450
+ function F(o, t, e, i, s = 3, r = 0, n = 100) {
2451
+ if (!o) return () => {
2452
+ };
2453
+ const l = matchMedia("(pointer: coarse)").matches;
2454
+ let h = () => {
2455
+ };
2456
+ const c = (a) => {
2457
+ if (a.button !== r) return;
2458
+ a.preventDefault(), a.stopPropagation();
2459
+ let d = a.clientX, u = a.clientY, p = !1;
2460
+ const b = Date.now(), x = (v) => {
2461
+ if (v.preventDefault(), v.stopPropagation(), l && Date.now() - b < n) return;
2462
+ const f = v.clientX, C = v.clientY, W = f - d, S = C - u;
2463
+ if (p || Math.abs(W) > s || Math.abs(S) > s) {
2464
+ const M = o.getBoundingClientRect(), { left: E, top: L } = M;
2465
+ p || (e?.(d - E, u - L), p = !0), t(W, S, f - E, C - L), d = f, u = C;
2466
+ }
2467
+ }, g = (v) => {
2468
+ if (p) {
2469
+ const f = v.clientX, C = v.clientY, W = o.getBoundingClientRect(), { left: S, top: M } = W;
2470
+ i?.(f - S, C - M);
2471
+ }
2472
+ h();
2473
+ }, m = (v) => {
2474
+ v.relatedTarget && v.relatedTarget !== document.documentElement || g(v);
2475
+ }, y = (v) => {
2476
+ p && (v.stopPropagation(), v.preventDefault());
2477
+ }, w = (v) => {
2478
+ p && v.preventDefault();
2479
+ };
2480
+ document.addEventListener("pointermove", x), document.addEventListener("pointerup", g), document.addEventListener("pointerout", m), document.addEventListener("pointercancel", m), document.addEventListener("touchmove", w, { passive: !1 }), document.addEventListener("click", y, { capture: !0 }), h = () => {
2481
+ document.removeEventListener("pointermove", x), document.removeEventListener("pointerup", g), document.removeEventListener("pointerout", m), document.removeEventListener("pointercancel", m), document.removeEventListener("touchmove", w), setTimeout(() => {
2482
+ document.removeEventListener("click", y, { capture: !0 });
2483
+ }, 10);
2484
+ };
2485
+ };
2486
+ return o.addEventListener("pointerdown", c), () => {
2487
+ h(), o.removeEventListener("pointerdown", c);
2488
+ };
2489
+ }
2490
+ function It(o, t) {
2491
+ const e = t.xmlns ? document.createElementNS(t.xmlns, o) : document.createElement(o);
2492
+ for (const [i, s] of Object.entries(t)) if (i === "children" && s) for (const [r, n] of Object.entries(s)) n instanceof Node ? e.appendChild(n) : typeof n == "string" ? e.appendChild(document.createTextNode(n)) : e.appendChild(It(r, n));
2493
+ else i === "style" ? Object.assign(e.style, s) : i === "textContent" ? e.textContent = s : e.setAttribute(i, s.toString());
2494
+ return e;
2495
+ }
2496
+ function Y(o, t, e) {
2497
+ const i = It(o, t || {});
2498
+ return e?.appendChild(i), i;
2499
+ }
2500
+ class it extends Zt {
2501
+ constructor(t, e, i = 0) {
2502
+ var s, r, n, l, h, c, a, d, u, p;
2503
+ super(), this.totalDuration = e, this.numberOfChannels = i, this.element = null, this.minLength = 0, this.maxLength = 1 / 0, this.contentEditable = !1, this.subscriptions = [], this.isRemoved = !1, this.subscriptions = [], this.id = t.id || `region-${Math.random().toString(32).slice(2)}`, this.start = this.clampPosition(t.start), this.end = this.clampPosition((s = t.end) !== null && s !== void 0 ? s : t.start), this.drag = (r = t.drag) === null || r === void 0 || r, this.resize = (n = t.resize) === null || n === void 0 || n, this.resizeStart = (l = t.resizeStart) === null || l === void 0 || l, this.resizeEnd = (h = t.resizeEnd) === null || h === void 0 || h, this.color = (c = t.color) !== null && c !== void 0 ? c : "rgba(0, 0, 0, 0.1)", this.minLength = (a = t.minLength) !== null && a !== void 0 ? a : this.minLength, this.maxLength = (d = t.maxLength) !== null && d !== void 0 ? d : this.maxLength, this.channelIdx = (u = t.channelIdx) !== null && u !== void 0 ? u : -1, this.contentEditable = (p = t.contentEditable) !== null && p !== void 0 ? p : this.contentEditable, this.element = this.initElement(), this.setContent(t.content), this.setPart(), this.renderPosition(), this.initMouseEvents();
2504
+ }
2505
+ clampPosition(t) {
2506
+ return Math.max(0, Math.min(this.totalDuration, t));
2507
+ }
2508
+ setPart() {
2509
+ var t;
2510
+ const e = this.start === this.end;
2511
+ (t = this.element) === null || t === void 0 || t.setAttribute("part", `${e ? "marker" : "region"} ${this.id}`);
2512
+ }
2513
+ addResizeHandles(t) {
2514
+ const e = { position: "absolute", zIndex: "2", width: "6px", height: "100%", top: "0", cursor: "ew-resize", wordBreak: "keep-all" }, i = Y("div", { part: "region-handle region-handle-left", style: Object.assign(Object.assign({}, e), { left: "0", borderLeft: "2px solid rgba(0, 0, 0, 0.5)", borderRadius: "2px 0 0 2px" }) }, t), s = Y("div", { part: "region-handle region-handle-right", style: Object.assign(Object.assign({}, e), { right: "0", borderRight: "2px solid rgba(0, 0, 0, 0.5)", borderRadius: "0 2px 2px 0" }) }, t);
2515
+ this.subscriptions.push(F(i, (r) => this.onResize(r, "start"), () => null, () => this.onEndResizing(), 1), F(s, (r) => this.onResize(r, "end"), () => null, () => this.onEndResizing(), 1));
2516
+ }
2517
+ removeResizeHandles(t) {
2518
+ const e = t.querySelector('[part*="region-handle-left"]'), i = t.querySelector('[part*="region-handle-right"]');
2519
+ e && t.removeChild(e), i && t.removeChild(i);
2520
+ }
2521
+ initElement() {
2522
+ if (this.isRemoved) return null;
2523
+ const t = this.start === this.end;
2524
+ let e = 0, i = 100;
2525
+ this.channelIdx >= 0 && this.channelIdx < this.numberOfChannels && (i = 100 / this.numberOfChannels, e = i * this.channelIdx);
2526
+ const s = Y("div", { style: { position: "absolute", top: `${e}%`, height: `${i}%`, backgroundColor: t ? "none" : this.color, borderLeft: t ? "2px solid " + this.color : "none", borderRadius: "2px", boxSizing: "border-box", transition: "background-color 0.2s ease", cursor: this.drag ? "grab" : "default", pointerEvents: "all" } });
2527
+ return !t && this.resize && this.addResizeHandles(s), s;
2528
+ }
2529
+ renderPosition() {
2530
+ if (!this.element) return;
2531
+ const t = this.start / this.totalDuration, e = (this.totalDuration - this.end) / this.totalDuration;
2532
+ this.element.style.left = 100 * t + "%", this.element.style.right = 100 * e + "%";
2533
+ }
2534
+ toggleCursor(t) {
2535
+ var e;
2536
+ this.drag && (!((e = this.element) === null || e === void 0) && e.style) && (this.element.style.cursor = t ? "grabbing" : "grab");
2537
+ }
2538
+ initMouseEvents() {
2539
+ const { element: t } = this;
2540
+ t && (t.addEventListener("click", (e) => this.emit("click", e)), t.addEventListener("mouseenter", (e) => this.emit("over", e)), t.addEventListener("mouseleave", (e) => this.emit("leave", e)), t.addEventListener("dblclick", (e) => this.emit("dblclick", e)), t.addEventListener("pointerdown", () => this.toggleCursor(!0)), t.addEventListener("pointerup", () => this.toggleCursor(!1)), this.subscriptions.push(F(t, (e) => this.onMove(e), () => this.toggleCursor(!0), () => {
2541
+ this.toggleCursor(!1), this.drag && this.emit("update-end");
2542
+ })), this.contentEditable && this.content && (this.content.addEventListener("click", (e) => this.onContentClick(e)), this.content.addEventListener("blur", () => this.onContentBlur())));
2543
+ }
2544
+ _onUpdate(t, e) {
2545
+ var i;
2546
+ if (!(!((i = this.element) === null || i === void 0) && i.parentElement)) return;
2547
+ const { width: s } = this.element.parentElement.getBoundingClientRect(), r = t / s * this.totalDuration, n = e && e !== "start" ? this.start : this.start + r, l = e && e !== "end" ? this.end : this.end + r, h = l - n;
2548
+ n >= 0 && l <= this.totalDuration && n <= l && h >= this.minLength && h <= this.maxLength && (this.start = n, this.end = l, this.renderPosition(), this.emit("update", e));
2549
+ }
2550
+ onMove(t) {
2551
+ this.drag && this._onUpdate(t);
2552
+ }
2553
+ onResize(t, e) {
2554
+ this.resize && (this.resizeStart || e !== "start") && (this.resizeEnd || e !== "end") && this._onUpdate(t, e);
2555
+ }
2556
+ onEndResizing() {
2557
+ this.resize && this.emit("update-end");
2558
+ }
2559
+ onContentClick(t) {
2560
+ t.stopPropagation(), t.target.focus(), this.emit("click", t);
2561
+ }
2562
+ onContentBlur() {
2563
+ this.emit("update-end");
2564
+ }
2565
+ _setTotalDuration(t) {
2566
+ this.totalDuration = t, this.renderPosition();
2567
+ }
2568
+ play(t) {
2569
+ this.emit("play", t && this.end !== this.start ? this.end : void 0);
2570
+ }
2571
+ getContent(t = !1) {
2572
+ var e;
2573
+ return t ? this.content || void 0 : this.element instanceof HTMLElement ? ((e = this.content) === null || e === void 0 ? void 0 : e.innerHTML) || void 0 : "";
2574
+ }
2575
+ setContent(t) {
2576
+ var e;
2577
+ if (this.element) if ((e = this.content) === null || e === void 0 || e.remove(), t) {
2578
+ if (typeof t == "string") {
2579
+ const i = this.start === this.end;
2580
+ this.content = Y("div", { style: { padding: `0.2em ${i ? 0.2 : 0.4}em`, display: "inline-block" }, textContent: t });
2581
+ } else this.content = t;
2582
+ this.contentEditable && (this.content.contentEditable = "true"), this.content.setAttribute("part", "region-content"), this.element.appendChild(this.content), this.emit("content-changed");
2583
+ } else this.content = void 0;
2584
+ }
2585
+ setOptions(t) {
2586
+ var e, i;
2587
+ if (this.element) {
2588
+ if (t.color && (this.color = t.color, this.element.style.backgroundColor = this.color), t.drag !== void 0 && (this.drag = t.drag, this.element.style.cursor = this.drag ? "grab" : "default"), t.start !== void 0 || t.end !== void 0) {
2589
+ const s = this.start === this.end;
2590
+ this.start = this.clampPosition((e = t.start) !== null && e !== void 0 ? e : this.start), this.end = this.clampPosition((i = t.end) !== null && i !== void 0 ? i : s ? this.start : this.end), this.renderPosition(), this.setPart();
2591
+ }
2592
+ if (t.content && this.setContent(t.content), t.id && (this.id = t.id, this.setPart()), t.resize !== void 0 && t.resize !== this.resize) {
2593
+ const s = this.start === this.end;
2594
+ this.resize = t.resize, this.resize && !s ? this.addResizeHandles(this.element) : this.removeResizeHandles(this.element);
2595
+ }
2596
+ t.resizeStart !== void 0 && (this.resizeStart = t.resizeStart), t.resizeEnd !== void 0 && (this.resizeEnd = t.resizeEnd);
2597
+ }
2598
+ }
2599
+ remove() {
2600
+ this.isRemoved = !0, this.emit("remove"), this.subscriptions.forEach((t) => t()), this.element && (this.element.remove(), this.element = null);
2601
+ }
2602
+ }
2603
+ class B extends we {
2604
+ constructor(t) {
2605
+ super(t), this.regions = [], this.regionsContainer = this.initRegionsContainer();
2606
+ }
2607
+ static create(t) {
2608
+ return new B(t);
2609
+ }
2610
+ onInit() {
2611
+ if (!this.wavesurfer) throw Error("WaveSurfer is not initialized");
2612
+ this.wavesurfer.getWrapper().appendChild(this.regionsContainer);
2613
+ let t = [];
2614
+ this.subscriptions.push(this.wavesurfer.on("timeupdate", (e) => {
2615
+ const i = this.regions.filter((s) => s.start <= e && (s.end === s.start ? s.start + 0.05 : s.end) >= e);
2616
+ i.forEach((s) => {
2617
+ t.includes(s) || this.emit("region-in", s);
2618
+ }), t.forEach((s) => {
2619
+ i.includes(s) || this.emit("region-out", s);
2620
+ }), t = i;
2621
+ }));
2622
+ }
2623
+ initRegionsContainer() {
2624
+ return Y("div", { style: { position: "absolute", top: "0", left: "0", width: "100%", height: "100%", zIndex: "5", pointerEvents: "none" } });
2625
+ }
2626
+ getRegions() {
2627
+ return this.regions;
2628
+ }
2629
+ avoidOverlapping(t) {
2630
+ t.content && setTimeout(() => {
2631
+ const e = t.content, i = e.getBoundingClientRect(), s = this.regions.map((r) => {
2632
+ if (r === t || !r.content) return 0;
2633
+ const n = r.content.getBoundingClientRect();
2634
+ return i.left < n.left + n.width && n.left < i.left + i.width ? n.height : 0;
2635
+ }).reduce((r, n) => r + n, 0);
2636
+ e.style.marginTop = `${s}px`;
2637
+ }, 10);
2638
+ }
2639
+ adjustScroll(t) {
2640
+ var e, i;
2641
+ if (!t.element) return;
2642
+ const s = (i = (e = this.wavesurfer) === null || e === void 0 ? void 0 : e.getWrapper()) === null || i === void 0 ? void 0 : i.parentElement;
2643
+ if (!s) return;
2644
+ const { clientWidth: r, scrollWidth: n } = s;
2645
+ if (n <= r) return;
2646
+ const l = s.getBoundingClientRect(), h = t.element.getBoundingClientRect(), c = h.left - l.left, a = h.right - l.left;
2647
+ c < 0 ? s.scrollLeft += c : a > r && (s.scrollLeft += a - r);
2648
+ }
2649
+ virtualAppend(t, e, i) {
2650
+ const s = () => {
2651
+ if (!this.wavesurfer) return;
2652
+ const r = this.wavesurfer.getWidth(), n = this.wavesurfer.getScroll(), l = e.clientWidth, h = this.wavesurfer.getDuration(), c = Math.round(t.start / h * l), a = c + (Math.round((t.end - t.start) / h * l) || 1) > n && c < n + r;
2653
+ a && !i.parentElement ? e.appendChild(i) : !a && i.parentElement && i.remove();
2654
+ };
2655
+ setTimeout(() => {
2656
+ if (!this.wavesurfer || !t.element) return;
2657
+ s();
2658
+ const r = this.wavesurfer.on("scroll", s), n = this.wavesurfer.on("zoom", s);
2659
+ this.subscriptions.push(t.once("remove", r), r), this.subscriptions.push(t.once("remove", n), n);
2660
+ }, 0);
2661
+ }
2662
+ saveRegion(t) {
2663
+ if (!t.element) return;
2664
+ this.virtualAppend(t, this.regionsContainer, t.element), this.avoidOverlapping(t), this.regions.push(t);
2665
+ const e = [t.on("update", (i) => {
2666
+ i || this.adjustScroll(t), this.emit("region-update", t, i);
2667
+ }), t.on("update-end", () => {
2668
+ this.avoidOverlapping(t), this.emit("region-updated", t);
2669
+ }), t.on("play", (i) => {
2670
+ var s;
2671
+ (s = this.wavesurfer) === null || s === void 0 || s.play(t.start, i);
2672
+ }), t.on("click", (i) => {
2673
+ this.emit("region-clicked", t, i);
2674
+ }), t.on("dblclick", (i) => {
2675
+ this.emit("region-double-clicked", t, i);
2676
+ }), t.on("content-changed", () => {
2677
+ this.emit("region-content-changed", t);
2678
+ }), t.once("remove", () => {
2679
+ e.forEach((i) => i()), this.regions = this.regions.filter((i) => i !== t), this.emit("region-removed", t);
2680
+ })];
2681
+ this.subscriptions.push(...e), this.emit("region-created", t);
2682
+ }
2683
+ addRegion(t) {
2684
+ var e, i;
2685
+ if (!this.wavesurfer) throw Error("WaveSurfer is not initialized");
2686
+ const s = this.wavesurfer.getDuration(), r = (i = (e = this.wavesurfer) === null || e === void 0 ? void 0 : e.getDecodedData()) === null || i === void 0 ? void 0 : i.numberOfChannels, n = new it(t, s, r);
2687
+ return this.emit("region-initialized", n), s ? this.saveRegion(n) : this.subscriptions.push(this.wavesurfer.once("ready", (l) => {
2688
+ n._setTotalDuration(l), this.saveRegion(n);
2689
+ })), n;
2690
+ }
2691
+ enableDragSelection(t, e = 3) {
2692
+ var i;
2693
+ const s = (i = this.wavesurfer) === null || i === void 0 ? void 0 : i.getWrapper();
2694
+ if (!(s && s instanceof HTMLElement)) return () => {
2695
+ };
2696
+ let r = null, n = 0;
2697
+ return F(s, (l, h, c) => {
2698
+ r && r._onUpdate(l, c > n ? "end" : "start");
2699
+ }, (l) => {
2700
+ var h, c;
2701
+ if (n = l, !this.wavesurfer) return;
2702
+ const a = this.wavesurfer.getDuration(), d = (c = (h = this.wavesurfer) === null || h === void 0 ? void 0 : h.getDecodedData()) === null || c === void 0 ? void 0 : c.numberOfChannels, { width: u } = this.wavesurfer.getWrapper().getBoundingClientRect(), p = l / u * a, b = (l + 5) / u * a;
2703
+ r = new it(Object.assign(Object.assign({}, t), { start: p, end: b }), a, d), this.emit("region-initialized", r), r.element && this.regionsContainer.appendChild(r.element);
2704
+ }, () => {
2705
+ r && (this.saveRegion(r), r = null);
2706
+ }, e);
2707
+ }
2708
+ clearRegions() {
2709
+ this.regions.slice().forEach((t) => t.remove()), this.regions = [];
2710
+ }
2711
+ destroy() {
2712
+ this.clearRegions(), super.destroy(), this.regionsContainer.remove();
2713
+ }
2714
+ }
2715
+ const qe = ({
2716
+ waveSurfer: o,
2717
+ regionsOptions: t = {}
2718
+ }) => {
2719
+ const { pluginInstance: e, createPlugin: i } = z(
2720
+ B,
2721
+ t
2722
+ );
2723
+ return D(() => {
2724
+ o.value && i(o.value);
2725
+ }), {
2726
+ regionsPlugin: e
2727
+ };
2728
+ }, Qe = ({
2729
+ containerRef: o,
2730
+ options: t,
2731
+ regionsOptions: e = {}
2732
+ }) => G(
2733
+ B,
2734
+ { containerRef: o, options: t, pluginOptions: e }
2735
+ );
332
2736
  export {
333
- U as WaveSurferPlayer,
334
- k as useWaveSurfer,
335
- q as useWaveSurferRecorder
2737
+ Se as WaveSurferPlayer,
2738
+ Vt as useWaveSurfer,
2739
+ Ke as useWaveSurferEnvelope,
2740
+ je as useWaveSurferEnvelopeStandalone,
2741
+ He as useWaveSurferHover,
2742
+ $e as useWaveSurferHoverStandalone,
2743
+ nt as useWaveSurferInstance,
2744
+ Xe as useWaveSurferMinimap,
2745
+ Ne as useWaveSurferMinimapStandalone,
2746
+ z as useWaveSurferPlugin,
2747
+ G as useWaveSurferPluginStandalone,
2748
+ qe as useWaveSurferRegions,
2749
+ Qe as useWaveSurferRegionsStandalone,
2750
+ Ae as useWaveSurferSpectrogram,
2751
+ Fe as useWaveSurferSpectrogramStandalone,
2752
+ Ee as useWaveSurferTimeline,
2753
+ Pe as useWaveSurferTimelineStandalone,
2754
+ Te as useWaveSurferZoom,
2755
+ De as useWaveSurferZoomStandalone
336
2756
  };