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