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