@ethora/chat-component 26.7.5 → 26.7.6

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.
Files changed (151) hide show
  1. package/README.md +72 -16
  2. package/dist/ChatProfileModal-hxsWI8cx.js +2139 -0
  3. package/dist/FilePreviewModal-CwWnHsB1.js +736 -0
  4. package/dist/ManageDataModal-CDPXcC93.js +159 -0
  5. package/dist/MarkdownBody-DBJGraWM.js +16874 -0
  6. package/dist/SideDrawer-Dr_lkaOW.js +226 -0
  7. package/dist/UserProfileModal-Q_jhXpsX.js +568 -0
  8. package/dist/UserSettingsModal-OcAJao-d.js +50 -0
  9. package/dist/{VideoCallOverlay-C4M2I9oV.js → VideoCallOverlay-CC4sShdK.js} +9 -10
  10. package/dist/VisibilityModal-DkMhx_2k.js +132 -0
  11. package/dist/assets/icons.d.ts +30 -0
  12. package/dist/components/ContextMenu/ContextMenuComponents.d.ts +1 -3
  13. package/dist/components/EmojiPicker/LazyEmojiPicker.d.ts +3 -0
  14. package/dist/components/ExampleComponents/CustomMessage.d.ts +3 -3
  15. package/dist/components/Files/FilesList.d.ts +12 -0
  16. package/dist/components/Files/FilesPanel.d.ts +3 -0
  17. package/dist/components/Files/fileCategory.d.ts +13 -0
  18. package/dist/components/InputComponents/AttachmentPreview.d.ts +17 -0
  19. package/dist/components/InputComponents/MentionDropdown.d.ts +13 -0
  20. package/dist/components/InputComponents/MentionPickerModal.d.ts +19 -0
  21. package/dist/components/MainComponents/AttachmentList.d.ts +7 -0
  22. package/dist/components/MainComponents/ChatErrorBoundary.d.ts +53 -0
  23. package/dist/components/MainComponents/ChatErrorScreen.d.ts +24 -0
  24. package/dist/components/MainComponents/HeaderLogo.d.ts +18 -0
  25. package/dist/components/MainComponents/MediaMessage.d.ts +5 -0
  26. package/dist/components/MainComponents/MessageContainer.d.ts +2 -2
  27. package/dist/components/MainComponents/ReduxWrapper.d.ts +1 -2
  28. package/dist/components/MainComponents/SystemMessage.d.ts +1 -2
  29. package/dist/components/MenuRoom/MenuRoom.d.ts +1 -0
  30. package/dist/components/MessageBubble/CustomDivider.d.ts +3 -3
  31. package/dist/components/MessageBubble/Message.d.ts +2 -2
  32. package/dist/components/MessageBubble/MessageTranslate.d.ts +28 -10
  33. package/dist/components/MessageBubble/QuickReplies.d.ts +6 -5
  34. package/dist/components/Modals/ChatProfileModal/ChatProfileMemberRow.d.ts +18 -0
  35. package/dist/components/Modals/FilePreviewModal/FilePreviewModal.d.ts +17 -0
  36. package/dist/components/Modals/FilePreviewModal/ImageLightbox.d.ts +35 -0
  37. package/dist/components/Modals/FilePreviewModal/PdfView.d.ts +14 -3
  38. package/dist/components/Modals/NewChatModal/styledNewChatComponents.d.ts +12 -0
  39. package/dist/components/Modals/SettingsModals/Visibility/StyledComponents.d.ts +1 -1
  40. package/dist/components/Modals/SideDrawer/DrawerProfileParts.d.ts +13 -0
  41. package/dist/components/Modals/SideDrawer/SideDrawer.d.ts +44 -0
  42. package/dist/components/Modals/modalComponents.d.ts +6 -0
  43. package/dist/components/Modals/styledModalComponents.d.ts +14 -3
  44. package/dist/components/RoomComponents/ChatRoomItem.d.ts +0 -1
  45. package/dist/components/RoomComponents/OnlineUsersPopover.d.ts +0 -1
  46. package/dist/components/UsersList/StyledComponents.d.ts +5 -1
  47. package/dist/components/UsersList/UsersList.d.ts +23 -0
  48. package/dist/components/styled/Button.d.ts +11 -1
  49. package/dist/components/styled/ChatWrapperBox.d.ts +3 -1
  50. package/dist/components/styled/PdfMessage.d.ts +13 -0
  51. package/dist/components/styled/RoomListComponents/index.d.ts +22 -1
  52. package/dist/components/styled/SendInput.d.ts +19 -5
  53. package/dist/components/styled/StyledComponents.d.ts +1 -1
  54. package/dist/components/styled/StyledInputComponents/MediaComponents.d.ts +18 -0
  55. package/dist/components/styled/StyledInputComponents/StyledInputComponents.d.ts +21 -0
  56. package/dist/components/styled/TreadLabel.d.ts +2 -2
  57. package/dist/components/styled/UnsupportedType.d.ts +1 -1
  58. package/dist/examples/quiz/QuizDemo.d.ts +3 -0
  59. package/dist/examples/quiz/quizScript.d.ts +38 -0
  60. package/dist/examples/quiz/useDemoSession.d.ts +42 -0
  61. package/dist/examples/quiz/useQuizFlow.d.ts +47 -0
  62. package/dist/firebase-config.d.ts +2 -4
  63. package/dist/handleCopyClick-CpmPa6VI.js +32 -0
  64. package/dist/helpers/MarkdownBody.d.ts +7 -0
  65. package/dist/helpers/attachments.d.ts +33 -0
  66. package/dist/helpers/botMarkup.d.ts +30 -0
  67. package/dist/helpers/constants/MODAL_TYPES.d.ts +11 -7
  68. package/dist/helpers/ethoraLogger.d.ts +8 -0
  69. package/dist/helpers/fileKind.d.ts +17 -0
  70. package/dist/helpers/hiddenRooms.d.ts +1 -1
  71. package/dist/helpers/historyPreloadScheduler.d.ts +1 -0
  72. package/dist/helpers/lazyEmoji.d.ts +3 -0
  73. package/dist/helpers/localStorageUser.d.ts +1 -1
  74. package/dist/helpers/markdownSanitizeSchema.d.ts +3 -0
  75. package/dist/helpers/mentions.d.ts +63 -0
  76. package/dist/helpers/parseMessageBody.d.ts +12 -2
  77. package/dist/helpers/pdf/loadPdfjs.d.ts +64 -0
  78. package/dist/helpers/remarkLineBreaks.d.ts +42 -0
  79. package/dist/helpers/resolveMessageTranslation.d.ts +34 -0
  80. package/dist/helpers/roomImageGallery.d.ts +53 -0
  81. package/dist/helpers/secureFileUrl.d.ts +8 -0
  82. package/dist/helpers/sendFailureWatchdog.d.ts +62 -0
  83. package/dist/helpers/transformTranslatations.d.ts +1 -2
  84. package/dist/hooks/pushSubscriptionSweep.d.ts +41 -0
  85. package/dist/hooks/useChatWrapperInit.d.ts +1 -0
  86. package/dist/hooks/useFilesEndpointSupport.d.ts +9 -0
  87. package/dist/hooks/useInView.d.ts +17 -0
  88. package/dist/hooks/useMentionComposer.d.ts +45 -0
  89. package/dist/hooks/useMessageHeapState.d.ts +1 -1
  90. package/dist/hooks/useMessageTranslation.d.ts +4 -3
  91. package/dist/hooks/useModalDismiss.d.ts +27 -0
  92. package/dist/hooks/useMyFiles.d.ts +16 -0
  93. package/dist/hooks/usePdfThumbnail.d.ts +22 -0
  94. package/dist/hooks/useRoomMute.d.ts +19 -0
  95. package/dist/hooks/useRoomState.d.ts +1 -1
  96. package/dist/hooks/useSendMessage.d.ts +4 -3
  97. package/dist/hooks/useTypography.d.ts +1 -1
  98. package/dist/hooks/useUnreadMessagesCounter.d.ts +11 -2
  99. package/dist/index.esm-B-3fyDHY.js +28 -0
  100. package/dist/index.esm-CRM4VCRa.js +943 -0
  101. package/dist/index.esm-msbp26WN.js +3352 -0
  102. package/dist/index.esm2017-CL0mvq6y.js +1578 -0
  103. package/dist/main-B-8IhwaP.js +31837 -0
  104. package/dist/main.css +1 -1
  105. package/dist/main.d.ts +14 -0
  106. package/dist/main.js +21 -21
  107. package/dist/module-DGXkb0R_.js +2960 -0
  108. package/dist/native-CDi4YD_s.js +13 -0
  109. package/dist/networking/api-requests/files.api.d.ts +19 -0
  110. package/dist/networking/api-requests/rooms.api.d.ts +10 -2
  111. package/dist/networking/api-requests/translate.api.d.ts +15 -0
  112. package/dist/networking/api-requests/user.api.d.ts +2 -0
  113. package/dist/networking/sharedRequest.d.ts +4 -0
  114. package/dist/networking/xmpp/allRoomPresences.xmpp.d.ts +3 -1
  115. package/dist/networking/xmpp/createTimeoutPromise.xmpp.d.ts +14 -0
  116. package/dist/networking/xmpp/sendTextMessage.xmpp.d.ts +2 -1
  117. package/dist/networking/xmpp/sendTextMessageWithTranslateTag.xmpp.d.ts +2 -1
  118. package/dist/networking/xmppClient.d.ts +12 -3
  119. package/dist/pdf-B5b7qHu6.js +17130 -0
  120. package/dist/pdf.worker.min-COYn-gId.js +24385 -0
  121. package/dist/roomStore/index.d.ts +20 -0
  122. package/dist/roomStore/persistEncryption.d.ts +51 -0
  123. package/dist/roomStore/roomsSlice.d.ts +49 -6
  124. package/dist/styles/classNames.d.ts +35 -0
  125. package/dist/styles/motion.d.ts +44 -0
  126. package/dist/styles/tokens.d.ts +27 -0
  127. package/dist/testIds.d.ts +1 -1
  128. package/dist/types/models/attachment.model.d.ts +33 -0
  129. package/dist/types/models/config.model.d.ts +160 -19
  130. package/dist/types/models/file.model.d.ts +20 -0
  131. package/dist/types/models/message.model.d.ts +15 -6
  132. package/dist/types/models/room.model.d.ts +12 -2
  133. package/dist/types/types.d.ts +3 -1
  134. package/dist/utils/resendMessage.d.ts +22 -1
  135. package/dist/utils/translateModePolicy.d.ts +1 -0
  136. package/dist/wavesurfer.esm-D_a19qBW.js +952 -0
  137. package/package.json +22 -2
  138. package/dist/VideoCallOverlay-C4M2I9oV.js.map +0 -1
  139. package/dist/components/MainComponents/VirtualList.d.ts +0 -10
  140. package/dist/components/Modals/SettingsModals/BlockedUsers/BlockedUsersModal.d.ts +0 -6
  141. package/dist/components/Modals/SettingsModals/DocumentShares/DocumentSharesModal.d.ts +0 -6
  142. package/dist/components/Modals/SettingsModals/ManageDataModal/StyledComponents.d.ts +0 -0
  143. package/dist/components/Modals/SettingsModals/ProfileShares/ProfileShares.d.ts +0 -6
  144. package/dist/components/Modals/SettingsModals/Referrals/Referrals.d.ts +0 -6
  145. package/dist/hooks/useMessageQueue.d.ts +0 -4
  146. package/dist/main-DeiuFYsl.js +0 -55812
  147. package/dist/main-DeiuFYsl.js.map +0 -1
  148. package/dist/main.js.map +0 -1
  149. package/dist/networking/xmpp/getHistory.xmpp.d.ts +0 -3
  150. package/dist/networking/xmpp/listenerManager.d.ts +0 -17
  151. package/dist/utils/xmppMemoryMonitor.d.ts +0 -16
@@ -0,0 +1,952 @@
1
+ function y(p, t, e, i) {
2
+ return new (e || (e = Promise))((function(s, r) {
3
+ function n(a) {
4
+ try {
5
+ l(i.next(a));
6
+ } catch (o) {
7
+ r(o);
8
+ }
9
+ }
10
+ function h(a) {
11
+ try {
12
+ l(i.throw(a));
13
+ } catch (o) {
14
+ r(o);
15
+ }
16
+ }
17
+ function l(a) {
18
+ var o;
19
+ a.done ? s(a.value) : (o = a.value, o instanceof e ? o : new e((function(c) {
20
+ c(o);
21
+ }))).then(n, h);
22
+ }
23
+ l((i = i.apply(p, t || [])).next());
24
+ }));
25
+ }
26
+ class T {
27
+ constructor() {
28
+ this.listeners = {};
29
+ }
30
+ on(t, e, i) {
31
+ if (this.listeners[t] || (this.listeners[t] = /* @__PURE__ */ new Set()), this.listeners[t].add(e), i?.once) {
32
+ const s = () => {
33
+ this.un(t, s), this.un(t, e);
34
+ };
35
+ return this.on(t, s), s;
36
+ }
37
+ return () => 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 R = { decode: function(p, t) {
54
+ return y(this, void 0, void 0, (function* () {
55
+ const e = new AudioContext({ sampleRate: t });
56
+ return e.decodeAudioData(p).finally((() => e.close()));
57
+ }));
58
+ }, createBuffer: function(p, t) {
59
+ return typeof p[0] == "number" && (p = [p]), (function(e) {
60
+ const i = e[0];
61
+ if (i.some(((s) => s > 1 || s < -1))) {
62
+ const s = i.length;
63
+ let r = 0;
64
+ for (let n = 0; n < s; n++) {
65
+ const h = Math.abs(i[n]);
66
+ h > r && (r = h);
67
+ }
68
+ for (const n of e) for (let h = 0; h < s; h++) n[h] /= r;
69
+ }
70
+ })(p), { duration: t, length: p[0].length, sampleRate: p[0].length / t, numberOfChannels: p.length, getChannelData: (e) => p?.[e], copyFromChannel: AudioBuffer.prototype.copyFromChannel, copyToChannel: AudioBuffer.prototype.copyToChannel };
71
+ } };
72
+ function _(p, t) {
73
+ const e = t.xmlns ? document.createElementNS(t.xmlns, p) : document.createElement(p);
74
+ for (const [i, s] of Object.entries(t)) if (i === "children" && s) for (const [r, n] of Object.entries(s)) n instanceof Node ? e.appendChild(n) : typeof n == "string" ? e.appendChild(document.createTextNode(n)) : e.appendChild(_(r, n));
75
+ else i === "style" ? Object.assign(e.style, s) : i === "textContent" ? e.textContent = s : e.setAttribute(i, s.toString());
76
+ return e;
77
+ }
78
+ function N(p, t, e) {
79
+ const i = _(p, t || {});
80
+ return e?.appendChild(i), i;
81
+ }
82
+ var B = Object.freeze({ __proto__: null, createElement: N, default: N });
83
+ const $ = { fetchBlob: function(p, t, e) {
84
+ return y(this, void 0, void 0, (function* () {
85
+ const i = yield fetch(p, e);
86
+ if (i.status >= 400) throw new Error(`Failed to fetch ${p}: ${i.status} (${i.statusText})`);
87
+ return (function(s, r) {
88
+ y(this, void 0, void 0, (function* () {
89
+ if (!s.body || !s.headers) return;
90
+ const n = s.body.getReader(), h = Number(s.headers.get("Content-Length")) || 0;
91
+ let l = 0;
92
+ const a = (c) => y(this, void 0, void 0, (function* () {
93
+ l += c?.length || 0;
94
+ const d = Math.round(l / h * 100);
95
+ r(d);
96
+ })), o = () => y(this, void 0, void 0, (function* () {
97
+ let c;
98
+ try {
99
+ c = yield n.read();
100
+ } catch {
101
+ return;
102
+ }
103
+ c.done || (a(c.value), yield o());
104
+ }));
105
+ o();
106
+ }));
107
+ })(i.clone(), t), i.blob();
108
+ }));
109
+ } };
110
+ class j extends T {
111
+ constructor(t) {
112
+ super(), this.isExternalMedia = !1, t.media ? (this.media = t.media, this.isExternalMedia = !0) : this.media = document.createElement("audio"), t.mediaControls && (this.media.controls = !0), t.autoplay && (this.media.autoplay = !0), t.playbackRate != null && this.onMediaEvent("canplay", (() => {
113
+ t.playbackRate != null && (this.media.playbackRate = t.playbackRate);
114
+ }), { once: !0 });
115
+ }
116
+ onMediaEvent(t, e, i) {
117
+ return this.media.addEventListener(t, e, i), () => this.media.removeEventListener(t, e, i);
118
+ }
119
+ getSrc() {
120
+ return this.media.currentSrc || this.media.src || "";
121
+ }
122
+ revokeSrc() {
123
+ const t = this.getSrc();
124
+ t.startsWith("blob:") && URL.revokeObjectURL(t);
125
+ }
126
+ canPlayType(t) {
127
+ return this.media.canPlayType(t) !== "";
128
+ }
129
+ setSrc(t, e) {
130
+ const i = this.getSrc();
131
+ if (t && i === t) return;
132
+ this.revokeSrc();
133
+ const s = e instanceof Blob && (this.canPlayType(e.type) || !t) ? URL.createObjectURL(e) : t;
134
+ i && this.media.removeAttribute("src");
135
+ try {
136
+ this.media.src = s;
137
+ } catch {
138
+ this.media.src = t;
139
+ }
140
+ }
141
+ destroy() {
142
+ this.isExternalMedia || (this.media.pause(), this.media.remove(), this.revokeSrc(), this.media.removeAttribute("src"), this.media.load());
143
+ }
144
+ setMediaElement(t) {
145
+ this.media = t;
146
+ }
147
+ play() {
148
+ return y(this, void 0, void 0, (function* () {
149
+ return this.media.play();
150
+ }));
151
+ }
152
+ pause() {
153
+ this.media.pause();
154
+ }
155
+ isPlaying() {
156
+ return !this.media.paused && !this.media.ended;
157
+ }
158
+ setTime(t) {
159
+ this.media.currentTime = Math.max(0, Math.min(t, this.getDuration()));
160
+ }
161
+ getDuration() {
162
+ return this.media.duration;
163
+ }
164
+ getCurrentTime() {
165
+ return this.media.currentTime;
166
+ }
167
+ getVolume() {
168
+ return this.media.volume;
169
+ }
170
+ setVolume(t) {
171
+ this.media.volume = t;
172
+ }
173
+ getMuted() {
174
+ return this.media.muted;
175
+ }
176
+ setMuted(t) {
177
+ this.media.muted = t;
178
+ }
179
+ getPlaybackRate() {
180
+ return this.media.playbackRate;
181
+ }
182
+ isSeeking() {
183
+ return this.media.seeking;
184
+ }
185
+ setPlaybackRate(t, e) {
186
+ e != null && (this.media.preservesPitch = e), this.media.playbackRate = t;
187
+ }
188
+ getMediaElement() {
189
+ return this.media;
190
+ }
191
+ setSinkId(t) {
192
+ return this.media.setSinkId(t);
193
+ }
194
+ }
195
+ class D extends T {
196
+ constructor(t, e) {
197
+ super(), this.timeouts = [], this.isScrollable = !1, this.audioData = null, this.resizeObserver = null, this.lastContainerWidth = 0, this.isDragging = !1, this.subscriptions = [], this.unsubscribeOnScroll = [], this.subscriptions = [], this.options = t;
198
+ const i = this.parentFromOptionsContainer(t.container);
199
+ this.parent = i;
200
+ const [s, r] = this.initHtml();
201
+ i.appendChild(s), this.container = s, this.scrollContainer = r.querySelector(".scroll"), this.wrapper = r.querySelector(".wrapper"), this.canvasWrapper = r.querySelector(".canvases"), this.progressWrapper = r.querySelector(".progress"), this.cursor = r.querySelector(".cursor"), e && r.appendChild(e), this.initEvents();
202
+ }
203
+ parentFromOptionsContainer(t) {
204
+ let e;
205
+ if (typeof t == "string" ? e = document.querySelector(t) : t instanceof HTMLElement && (e = t), !e) throw new Error("Container not found");
206
+ return e;
207
+ }
208
+ initEvents() {
209
+ const t = (e) => {
210
+ const i = this.wrapper.getBoundingClientRect(), s = e.clientX - i.left, r = e.clientY - i.top;
211
+ return [s / i.width, r / i.height];
212
+ };
213
+ if (this.wrapper.addEventListener("click", ((e) => {
214
+ const [i, s] = t(e);
215
+ this.emit("click", i, s);
216
+ })), this.wrapper.addEventListener("dblclick", ((e) => {
217
+ const [i, s] = t(e);
218
+ this.emit("dblclick", i, s);
219
+ })), this.options.dragToSeek !== !0 && typeof this.options.dragToSeek != "object" || this.initDrag(), this.scrollContainer.addEventListener("scroll", (() => {
220
+ const { scrollLeft: e, scrollWidth: i, clientWidth: s } = this.scrollContainer, r = e / i, n = (e + s) / i;
221
+ this.emit("scroll", r, n, e, e + s);
222
+ })), typeof ResizeObserver == "function") {
223
+ const e = this.createDelay(100);
224
+ this.resizeObserver = new ResizeObserver((() => {
225
+ e().then((() => this.onContainerResize())).catch((() => {
226
+ }));
227
+ })), this.resizeObserver.observe(this.scrollContainer);
228
+ }
229
+ }
230
+ onContainerResize() {
231
+ const t = this.parent.clientWidth;
232
+ t === this.lastContainerWidth && this.options.height !== "auto" || (this.lastContainerWidth = t, this.reRender());
233
+ }
234
+ initDrag() {
235
+ this.subscriptions.push((function(t, e, i, s, r = 3, n = 0, h = 100) {
236
+ if (!t) return () => {
237
+ };
238
+ const l = matchMedia("(pointer: coarse)").matches;
239
+ let a = () => {
240
+ };
241
+ const o = (c) => {
242
+ if (c.button !== n) return;
243
+ c.preventDefault(), c.stopPropagation();
244
+ let d = c.clientX, u = c.clientY, m = !1;
245
+ const w = Date.now(), g = (f) => {
246
+ if (f.preventDefault(), f.stopPropagation(), l && Date.now() - w < h) return;
247
+ const S = f.clientX, M = f.clientY, P = S - d, x = M - u;
248
+ if (m || Math.abs(P) > r || Math.abs(x) > r) {
249
+ const k = t.getBoundingClientRect(), { left: A, top: O } = k;
250
+ m || (i?.(d - A, u - O), m = !0), e(P, x, S - A, M - O), d = S, u = M;
251
+ }
252
+ }, v = (f) => {
253
+ if (m) {
254
+ const S = f.clientX, M = f.clientY, P = t.getBoundingClientRect(), { left: x, top: k } = P;
255
+ s?.(S - x, M - k);
256
+ }
257
+ a();
258
+ }, b = (f) => {
259
+ f.relatedTarget && f.relatedTarget !== document.documentElement || v(f);
260
+ }, E = (f) => {
261
+ m && (f.stopPropagation(), f.preventDefault());
262
+ }, C = (f) => {
263
+ m && f.preventDefault();
264
+ };
265
+ document.addEventListener("pointermove", g), document.addEventListener("pointerup", v), document.addEventListener("pointerout", b), document.addEventListener("pointercancel", b), document.addEventListener("touchmove", C, { passive: !1 }), document.addEventListener("click", E, { capture: !0 }), a = () => {
266
+ document.removeEventListener("pointermove", g), document.removeEventListener("pointerup", v), document.removeEventListener("pointerout", b), document.removeEventListener("pointercancel", b), document.removeEventListener("touchmove", C), setTimeout((() => {
267
+ document.removeEventListener("click", E, { capture: !0 });
268
+ }), 10);
269
+ };
270
+ };
271
+ return t.addEventListener("pointerdown", o), () => {
272
+ a(), t.removeEventListener("pointerdown", o);
273
+ };
274
+ })(this.wrapper, ((t, e, i) => {
275
+ this.emit("drag", Math.max(0, Math.min(1, i / this.wrapper.getBoundingClientRect().width)));
276
+ }), ((t) => {
277
+ this.isDragging = !0, this.emit("dragstart", Math.max(0, Math.min(1, t / this.wrapper.getBoundingClientRect().width)));
278
+ }), ((t) => {
279
+ this.isDragging = !1, this.emit("dragend", Math.max(0, Math.min(1, t / this.wrapper.getBoundingClientRect().width)));
280
+ })));
281
+ }
282
+ getHeight(t, e) {
283
+ var i;
284
+ const s = ((i = this.audioData) === null || i === void 0 ? void 0 : i.numberOfChannels) || 1;
285
+ if (t == null) return 128;
286
+ if (!isNaN(Number(t))) return Number(t);
287
+ if (t === "auto") {
288
+ const r = this.parent.clientHeight || 128;
289
+ return e?.every(((n) => !n.overlay)) ? r / s : r;
290
+ }
291
+ return 128;
292
+ }
293
+ initHtml() {
294
+ const t = document.createElement("div"), e = t.attachShadow({ mode: "open" }), i = this.options.cspNonce && typeof this.options.cspNonce == "string" ? this.options.cspNonce.replace(/"/g, "") : "";
295
+ return e.innerHTML = `
296
+ <style${i ? ` nonce="${i}"` : ""}>
297
+ :host {
298
+ user-select: none;
299
+ min-width: 1px;
300
+ }
301
+ :host audio {
302
+ display: block;
303
+ width: 100%;
304
+ }
305
+ :host .scroll {
306
+ overflow-x: auto;
307
+ overflow-y: hidden;
308
+ width: 100%;
309
+ position: relative;
310
+ }
311
+ :host .noScrollbar {
312
+ scrollbar-color: transparent;
313
+ scrollbar-width: none;
314
+ }
315
+ :host .noScrollbar::-webkit-scrollbar {
316
+ display: none;
317
+ -webkit-appearance: none;
318
+ }
319
+ :host .wrapper {
320
+ position: relative;
321
+ overflow: visible;
322
+ z-index: 2;
323
+ }
324
+ :host .canvases {
325
+ min-height: ${this.getHeight(this.options.height, this.options.splitChannels)}px;
326
+ }
327
+ :host .canvases > div {
328
+ position: relative;
329
+ }
330
+ :host canvas {
331
+ display: block;
332
+ position: absolute;
333
+ top: 0;
334
+ image-rendering: pixelated;
335
+ }
336
+ :host .progress {
337
+ pointer-events: none;
338
+ position: absolute;
339
+ z-index: 2;
340
+ top: 0;
341
+ left: 0;
342
+ width: 0;
343
+ height: 100%;
344
+ overflow: hidden;
345
+ }
346
+ :host .progress > div {
347
+ position: relative;
348
+ }
349
+ :host .cursor {
350
+ pointer-events: none;
351
+ position: absolute;
352
+ z-index: 5;
353
+ top: 0;
354
+ left: 0;
355
+ height: 100%;
356
+ border-radius: 2px;
357
+ }
358
+ </style>
359
+
360
+ <div class="scroll" part="scroll">
361
+ <div class="wrapper" part="wrapper">
362
+ <div class="canvases" part="canvases"></div>
363
+ <div class="progress" part="progress"></div>
364
+ <div class="cursor" part="cursor"></div>
365
+ </div>
366
+ </div>
367
+ `, [t, e];
368
+ }
369
+ setOptions(t) {
370
+ if (this.options.container !== t.container) {
371
+ const e = this.parentFromOptionsContainer(t.container);
372
+ e.appendChild(this.container), this.parent = e;
373
+ }
374
+ t.dragToSeek !== !0 && typeof this.options.dragToSeek != "object" || this.initDrag(), this.options = t, this.reRender();
375
+ }
376
+ getWrapper() {
377
+ return this.wrapper;
378
+ }
379
+ getWidth() {
380
+ return this.scrollContainer.clientWidth;
381
+ }
382
+ getScroll() {
383
+ return this.scrollContainer.scrollLeft;
384
+ }
385
+ setScroll(t) {
386
+ this.scrollContainer.scrollLeft = t;
387
+ }
388
+ setScrollPercentage(t) {
389
+ const { scrollWidth: e } = this.scrollContainer, i = e * t;
390
+ this.setScroll(i);
391
+ }
392
+ destroy() {
393
+ var t, e;
394
+ this.subscriptions.forEach(((i) => i())), this.container.remove(), (t = this.resizeObserver) === null || t === void 0 || t.disconnect(), (e = this.unsubscribeOnScroll) === null || e === void 0 || e.forEach(((i) => i())), this.unsubscribeOnScroll = [];
395
+ }
396
+ createDelay(t = 10) {
397
+ let e, i;
398
+ const s = () => {
399
+ e && clearTimeout(e), i && i();
400
+ };
401
+ return this.timeouts.push(s), () => new Promise(((r, n) => {
402
+ s(), i = n, e = setTimeout((() => {
403
+ e = void 0, i = void 0, r();
404
+ }), t);
405
+ }));
406
+ }
407
+ convertColorValues(t) {
408
+ if (!Array.isArray(t)) return t || "";
409
+ if (t.length < 2) return t[0] || "";
410
+ const e = document.createElement("canvas"), i = e.getContext("2d"), s = e.height * (window.devicePixelRatio || 1), r = i.createLinearGradient(0, 0, 0, s), n = 1 / (t.length - 1);
411
+ return t.forEach(((h, l) => {
412
+ const a = l * n;
413
+ r.addColorStop(a, h);
414
+ })), r;
415
+ }
416
+ getPixelRatio() {
417
+ return Math.max(1, window.devicePixelRatio || 1);
418
+ }
419
+ renderBarWaveform(t, e, i, s) {
420
+ const r = t[0], n = t[1] || t[0], h = r.length, { width: l, height: a } = i.canvas, o = a / 2, c = this.getPixelRatio(), d = e.barWidth ? e.barWidth * c : 1, u = e.barGap ? e.barGap * c : e.barWidth ? d / 2 : 0, m = e.barRadius || 0, w = l / (d + u) / h, g = m && "roundRect" in i ? "roundRect" : "rect";
421
+ i.beginPath();
422
+ let v = 0, b = 0, E = 0;
423
+ for (let C = 0; C <= h; C++) {
424
+ const f = Math.round(C * w);
425
+ if (f > v) {
426
+ const P = Math.round(b * o * s), x = P + Math.round(E * o * s) || 1;
427
+ let k = o - P;
428
+ e.barAlign === "top" ? k = 0 : e.barAlign === "bottom" && (k = a - x), i[g](v * (d + u), k, d, x, m), v = f, b = 0, E = 0;
429
+ }
430
+ const S = Math.abs(r[C] || 0), M = Math.abs(n[C] || 0);
431
+ S > b && (b = S), M > E && (E = M);
432
+ }
433
+ i.fill(), i.closePath();
434
+ }
435
+ renderLineWaveform(t, e, i, s) {
436
+ const r = (n) => {
437
+ const h = t[n] || t[0], l = h.length, { height: a } = i.canvas, o = a / 2, c = i.canvas.width / l;
438
+ i.moveTo(0, o);
439
+ let d = 0, u = 0;
440
+ for (let m = 0; m <= l; m++) {
441
+ const w = Math.round(m * c);
442
+ if (w > d) {
443
+ const v = o + (Math.round(u * o * s) || 1) * (n === 0 ? -1 : 1);
444
+ i.lineTo(d, v), d = w, u = 0;
445
+ }
446
+ const g = Math.abs(h[m] || 0);
447
+ g > u && (u = g);
448
+ }
449
+ i.lineTo(d, o);
450
+ };
451
+ i.beginPath(), r(0), r(1), i.fill(), i.closePath();
452
+ }
453
+ renderWaveform(t, e, i) {
454
+ if (i.fillStyle = this.convertColorValues(e.waveColor), e.renderFunction) return void e.renderFunction(t, i);
455
+ let s = e.barHeight || 1;
456
+ if (e.normalize) {
457
+ const r = Array.from(t[0]).reduce(((n, h) => Math.max(n, Math.abs(h))), 0);
458
+ s = r ? 1 / r : 1;
459
+ }
460
+ e.barWidth || e.barGap || e.barAlign ? this.renderBarWaveform(t, e, i, s) : this.renderLineWaveform(t, e, i, s);
461
+ }
462
+ renderSingleCanvas(t, e, i, s, r, n, h) {
463
+ const l = this.getPixelRatio(), a = document.createElement("canvas");
464
+ a.width = Math.round(i * l), a.height = Math.round(s * l), a.style.width = `${i}px`, a.style.height = `${s}px`, a.style.left = `${Math.round(r)}px`, n.appendChild(a);
465
+ const o = a.getContext("2d");
466
+ if (this.renderWaveform(t, e, o), a.width > 0 && a.height > 0) {
467
+ const c = a.cloneNode(), d = c.getContext("2d");
468
+ d.drawImage(a, 0, 0), d.globalCompositeOperation = "source-in", d.fillStyle = this.convertColorValues(e.progressColor), d.fillRect(0, 0, a.width, a.height), h.appendChild(c);
469
+ }
470
+ }
471
+ renderMultiCanvas(t, e, i, s, r, n) {
472
+ const h = this.getPixelRatio(), { clientWidth: l } = this.scrollContainer, a = i / h;
473
+ let o = Math.min(D.MAX_CANVAS_WIDTH, l, a), c = {};
474
+ if (e.barWidth || e.barGap) {
475
+ const g = e.barWidth || 0.5, v = g + (e.barGap || g / 2);
476
+ o % v != 0 && (o = Math.floor(o / v) * v);
477
+ }
478
+ if (o === 0) return;
479
+ const d = (g) => {
480
+ if (g < 0 || g >= u || c[g]) return;
481
+ c[g] = !0;
482
+ const v = g * o;
483
+ let b = Math.min(a - v, o);
484
+ if (e.barWidth || e.barGap) {
485
+ const C = e.barWidth || 0.5, f = C + (e.barGap || C / 2);
486
+ b = Math.floor(b / f) * f;
487
+ }
488
+ if (b <= 0) return;
489
+ const E = t.map(((C) => {
490
+ const f = Math.floor(v / a * C.length), S = Math.floor((v + b) / a * C.length);
491
+ return C.slice(f, S);
492
+ }));
493
+ this.renderSingleCanvas(E, e, b, s, v, r, n);
494
+ }, u = Math.ceil(a / o);
495
+ if (!this.isScrollable) {
496
+ for (let g = 0; g < u; g++) d(g);
497
+ return;
498
+ }
499
+ const m = this.scrollContainer.scrollLeft / a, w = Math.floor(m * u);
500
+ if (d(w - 1), d(w), d(w + 1), u > 1) {
501
+ const g = this.on("scroll", (() => {
502
+ const { scrollLeft: v } = this.scrollContainer, b = Math.floor(v / a * u);
503
+ Object.keys(c).length > D.MAX_NODES && (r.innerHTML = "", n.innerHTML = "", c = {}), d(b - 1), d(b), d(b + 1);
504
+ }));
505
+ this.unsubscribeOnScroll.push(g);
506
+ }
507
+ }
508
+ renderChannel(t, e, i, s) {
509
+ var { overlay: r } = e, n = (function(o, c) {
510
+ var d = {};
511
+ for (var u in o) Object.prototype.hasOwnProperty.call(o, u) && c.indexOf(u) < 0 && (d[u] = o[u]);
512
+ if (o != null && typeof Object.getOwnPropertySymbols == "function") {
513
+ var m = 0;
514
+ for (u = Object.getOwnPropertySymbols(o); m < u.length; m++) c.indexOf(u[m]) < 0 && Object.prototype.propertyIsEnumerable.call(o, u[m]) && (d[u[m]] = o[u[m]]);
515
+ }
516
+ return d;
517
+ })(e, ["overlay"]);
518
+ const h = document.createElement("div"), l = this.getHeight(n.height, n.splitChannels);
519
+ h.style.height = `${l}px`, r && s > 0 && (h.style.marginTop = `-${l}px`), this.canvasWrapper.style.minHeight = `${l}px`, this.canvasWrapper.appendChild(h);
520
+ const a = h.cloneNode();
521
+ this.progressWrapper.appendChild(a), this.renderMultiCanvas(t, n, i, l, h, a);
522
+ }
523
+ render(t) {
524
+ return y(this, void 0, void 0, (function* () {
525
+ var e;
526
+ this.timeouts.forEach(((l) => l())), this.timeouts = [], this.canvasWrapper.innerHTML = "", this.progressWrapper.innerHTML = "", this.options.width != null && (this.scrollContainer.style.width = typeof this.options.width == "number" ? `${this.options.width}px` : this.options.width);
527
+ const i = this.getPixelRatio(), s = this.scrollContainer.clientWidth, r = Math.ceil(t.duration * (this.options.minPxPerSec || 0));
528
+ this.isScrollable = r > s;
529
+ const n = this.options.fillParent && !this.isScrollable, h = (n ? s : r) * i;
530
+ if (this.wrapper.style.width = n ? "100%" : `${r}px`, this.scrollContainer.style.overflowX = this.isScrollable ? "auto" : "hidden", this.scrollContainer.classList.toggle("noScrollbar", !!this.options.hideScrollbar), this.cursor.style.backgroundColor = `${this.options.cursorColor || this.options.progressColor}`, this.cursor.style.width = `${this.options.cursorWidth}px`, this.audioData = t, this.emit("render"), this.options.splitChannels) for (let l = 0; l < t.numberOfChannels; l++) {
531
+ const a = Object.assign(Object.assign({}, this.options), (e = this.options.splitChannels) === null || e === void 0 ? void 0 : e[l]);
532
+ this.renderChannel([t.getChannelData(l)], a, h, l);
533
+ }
534
+ else {
535
+ const l = [t.getChannelData(0)];
536
+ t.numberOfChannels > 1 && l.push(t.getChannelData(1)), this.renderChannel(l, this.options, h, 0);
537
+ }
538
+ Promise.resolve().then((() => this.emit("rendered")));
539
+ }));
540
+ }
541
+ reRender() {
542
+ if (this.unsubscribeOnScroll.forEach(((i) => i())), this.unsubscribeOnScroll = [], !this.audioData) return;
543
+ const { scrollWidth: t } = this.scrollContainer, { right: e } = this.progressWrapper.getBoundingClientRect();
544
+ if (this.render(this.audioData), this.isScrollable && t !== this.scrollContainer.scrollWidth) {
545
+ const { right: i } = this.progressWrapper.getBoundingClientRect();
546
+ let s = i - e;
547
+ s *= 2, s = s < 0 ? Math.floor(s) : Math.ceil(s), s /= 2, this.scrollContainer.scrollLeft += s;
548
+ }
549
+ }
550
+ zoom(t) {
551
+ this.options.minPxPerSec = t, this.reRender();
552
+ }
553
+ scrollIntoView(t, e = !1) {
554
+ const { scrollLeft: i, scrollWidth: s, clientWidth: r } = this.scrollContainer, n = t * s, h = i, l = i + r, a = r / 2;
555
+ if (this.isDragging)
556
+ n + 30 > l ? this.scrollContainer.scrollLeft += 30 : n - 30 < h && (this.scrollContainer.scrollLeft -= 30);
557
+ else {
558
+ (n < h || n > l) && (this.scrollContainer.scrollLeft = n - (this.options.autoCenter ? a : 0));
559
+ const o = n - i - a;
560
+ e && this.options.autoCenter && o > 0 && (this.scrollContainer.scrollLeft += Math.min(o, 10));
561
+ }
562
+ {
563
+ const o = this.scrollContainer.scrollLeft, c = o / s, d = (o + r) / s;
564
+ this.emit("scroll", c, d, o, o + r);
565
+ }
566
+ }
567
+ renderProgress(t, e) {
568
+ if (isNaN(t)) return;
569
+ const i = 100 * t;
570
+ 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 = `translateX(-${Math.round(i) === 100 ? this.options.cursorWidth : 0}px)`, this.isScrollable && this.options.autoScroll && this.scrollIntoView(t, e);
571
+ }
572
+ exportImage(t, e, i) {
573
+ return y(this, void 0, void 0, (function* () {
574
+ const s = this.canvasWrapper.querySelectorAll("canvas");
575
+ if (!s.length) throw new Error("No waveform data");
576
+ if (i === "dataURL") {
577
+ const r = Array.from(s).map(((n) => n.toDataURL(t, e)));
578
+ return Promise.resolve(r);
579
+ }
580
+ return Promise.all(Array.from(s).map(((r) => new Promise(((n, h) => {
581
+ r.toBlob(((l) => {
582
+ l ? n(l) : h(new Error("Could not export image"));
583
+ }), t, e);
584
+ })))));
585
+ }));
586
+ }
587
+ }
588
+ D.MAX_CANVAS_WIDTH = 8e3, D.MAX_NODES = 10;
589
+ class z extends T {
590
+ constructor() {
591
+ super(...arguments), this.unsubscribe = () => {
592
+ };
593
+ }
594
+ start() {
595
+ this.unsubscribe = this.on("tick", (() => {
596
+ requestAnimationFrame((() => {
597
+ this.emit("tick");
598
+ }));
599
+ })), this.emit("tick");
600
+ }
601
+ stop() {
602
+ this.unsubscribe(), this.unAll();
603
+ }
604
+ destroy() {
605
+ this.unsubscribe();
606
+ }
607
+ }
608
+ class W extends T {
609
+ constructor(t = new AudioContext()) {
610
+ super(), this.bufferNode = null, this.playStartTime = 0, this.playedDuration = 0, this._muted = !1, this._playbackRate = 1, this._duration = void 0, this.buffer = null, this.currentSrc = "", this.paused = !0, this.crossOrigin = null, this.seeking = !1, this.autoplay = !1, this.addEventListener = this.on, this.removeEventListener = this.un, this.audioContext = t, this.gainNode = this.audioContext.createGain(), this.gainNode.connect(this.audioContext.destination);
611
+ }
612
+ load() {
613
+ return y(this, void 0, void 0, (function* () {
614
+ }));
615
+ }
616
+ get src() {
617
+ return this.currentSrc;
618
+ }
619
+ set src(t) {
620
+ if (this.currentSrc = t, this._duration = void 0, !t) return this.buffer = null, void this.emit("emptied");
621
+ fetch(t).then(((e) => {
622
+ if (e.status >= 400) throw new Error(`Failed to fetch ${t}: ${e.status} (${e.statusText})`);
623
+ return e.arrayBuffer();
624
+ })).then(((e) => this.currentSrc !== t ? null : this.audioContext.decodeAudioData(e))).then(((e) => {
625
+ this.currentSrc === t && (this.buffer = e, this.emit("loadedmetadata"), this.emit("canplay"), this.autoplay && this.play());
626
+ }));
627
+ }
628
+ _play() {
629
+ var t;
630
+ if (!this.paused) return;
631
+ this.paused = !1, (t = this.bufferNode) === null || t === void 0 || t.disconnect(), this.bufferNode = this.audioContext.createBufferSource(), this.buffer && (this.bufferNode.buffer = this.buffer), this.bufferNode.playbackRate.value = this._playbackRate, this.bufferNode.connect(this.gainNode);
632
+ let e = this.playedDuration * this._playbackRate;
633
+ (e >= this.duration || e < 0) && (e = 0, this.playedDuration = 0), this.bufferNode.start(this.audioContext.currentTime, e), this.playStartTime = this.audioContext.currentTime, this.bufferNode.onended = () => {
634
+ this.currentTime >= this.duration && (this.pause(), this.emit("ended"));
635
+ };
636
+ }
637
+ _pause() {
638
+ var t;
639
+ this.paused = !0, (t = this.bufferNode) === null || t === void 0 || t.stop(), this.playedDuration += this.audioContext.currentTime - this.playStartTime;
640
+ }
641
+ play() {
642
+ return y(this, void 0, void 0, (function* () {
643
+ this.paused && (this._play(), this.emit("play"));
644
+ }));
645
+ }
646
+ pause() {
647
+ this.paused || (this._pause(), this.emit("pause"));
648
+ }
649
+ stopAt(t) {
650
+ const e = t - this.currentTime, i = this.bufferNode;
651
+ i?.stop(this.audioContext.currentTime + e), i?.addEventListener("ended", (() => {
652
+ i === this.bufferNode && (this.bufferNode = null, this.pause());
653
+ }), { once: !0 });
654
+ }
655
+ setSinkId(t) {
656
+ return y(this, void 0, void 0, (function* () {
657
+ return this.audioContext.setSinkId(t);
658
+ }));
659
+ }
660
+ get playbackRate() {
661
+ return this._playbackRate;
662
+ }
663
+ set playbackRate(t) {
664
+ this._playbackRate = t, this.bufferNode && (this.bufferNode.playbackRate.value = t);
665
+ }
666
+ get currentTime() {
667
+ return (this.paused ? this.playedDuration : this.playedDuration + (this.audioContext.currentTime - this.playStartTime)) * this._playbackRate;
668
+ }
669
+ set currentTime(t) {
670
+ const e = !this.paused;
671
+ e && this._pause(), this.playedDuration = t / this._playbackRate, e && this._play(), this.emit("seeking"), this.emit("timeupdate");
672
+ }
673
+ get duration() {
674
+ var t, e;
675
+ return (t = this._duration) !== null && t !== void 0 ? t : ((e = this.buffer) === null || e === void 0 ? void 0 : e.duration) || 0;
676
+ }
677
+ set duration(t) {
678
+ this._duration = t;
679
+ }
680
+ get volume() {
681
+ return this.gainNode.gain.value;
682
+ }
683
+ set volume(t) {
684
+ this.gainNode.gain.value = t, this.emit("volumechange");
685
+ }
686
+ get muted() {
687
+ return this._muted;
688
+ }
689
+ set muted(t) {
690
+ this._muted !== t && (this._muted = t, this._muted ? this.gainNode.disconnect() : this.gainNode.connect(this.audioContext.destination));
691
+ }
692
+ canPlayType(t) {
693
+ return /^(audio|video)\//.test(t);
694
+ }
695
+ getGainNode() {
696
+ return this.gainNode;
697
+ }
698
+ getChannelData() {
699
+ const t = [];
700
+ if (!this.buffer) return t;
701
+ const e = this.buffer.numberOfChannels;
702
+ for (let i = 0; i < e; i++) t.push(this.buffer.getChannelData(i));
703
+ return t;
704
+ }
705
+ }
706
+ const H = { waveColor: "#999", progressColor: "#555", cursorWidth: 1, minPxPerSec: 0, fillParent: !0, interact: !0, dragToSeek: !1, autoScroll: !0, autoCenter: !0, sampleRate: 8e3 };
707
+ class L extends j {
708
+ static create(t) {
709
+ return new L(t);
710
+ }
711
+ constructor(t) {
712
+ const e = t.media || (t.backend === "WebAudio" ? new W() : void 0);
713
+ super({ media: e, mediaControls: t.mediaControls, autoplay: t.autoplay, playbackRate: t.audioRate }), this.plugins = [], this.decodedData = null, this.stopAtPosition = null, this.subscriptions = [], this.mediaSubscriptions = [], this.abortController = null, this.options = Object.assign({}, H, t), this.timer = new z();
714
+ const i = e ? void 0 : this.getMediaElement();
715
+ this.renderer = new D(this.options, i), this.initPlayerEvents(), this.initRendererEvents(), this.initTimerEvents(), this.initPlugins();
716
+ const s = this.options.url || this.getSrc() || "";
717
+ Promise.resolve().then((() => {
718
+ this.emit("init");
719
+ const { peaks: r, duration: n } = this.options;
720
+ (s || r && n) && this.load(s, r, n).catch((() => null));
721
+ }));
722
+ }
723
+ updateProgress(t = this.getCurrentTime()) {
724
+ return this.renderer.renderProgress(t / this.getDuration(), this.isPlaying()), t;
725
+ }
726
+ initTimerEvents() {
727
+ this.subscriptions.push(this.timer.on("tick", (() => {
728
+ if (!this.isSeeking()) {
729
+ const t = this.updateProgress();
730
+ this.emit("timeupdate", t), this.emit("audioprocess", t), this.stopAtPosition != null && this.isPlaying() && t >= this.stopAtPosition && this.pause();
731
+ }
732
+ })));
733
+ }
734
+ initPlayerEvents() {
735
+ this.isPlaying() && (this.emit("play"), this.timer.start()), this.mediaSubscriptions.push(this.onMediaEvent("timeupdate", (() => {
736
+ const t = this.updateProgress();
737
+ this.emit("timeupdate", t);
738
+ })), this.onMediaEvent("play", (() => {
739
+ this.emit("play"), this.timer.start();
740
+ })), this.onMediaEvent("pause", (() => {
741
+ this.emit("pause"), this.timer.stop(), this.stopAtPosition = null;
742
+ })), this.onMediaEvent("emptied", (() => {
743
+ this.timer.stop(), this.stopAtPosition = null;
744
+ })), this.onMediaEvent("ended", (() => {
745
+ this.emit("timeupdate", this.getDuration()), this.emit("finish"), this.stopAtPosition = null;
746
+ })), this.onMediaEvent("seeking", (() => {
747
+ this.emit("seeking", this.getCurrentTime());
748
+ })), this.onMediaEvent("error", (() => {
749
+ var t;
750
+ this.emit("error", (t = this.getMediaElement().error) !== null && t !== void 0 ? t : new Error("Media error")), this.stopAtPosition = null;
751
+ })));
752
+ }
753
+ initRendererEvents() {
754
+ this.subscriptions.push(this.renderer.on("click", ((t, e) => {
755
+ this.options.interact && (this.seekTo(t), this.emit("interaction", t * this.getDuration()), this.emit("click", t, e));
756
+ })), this.renderer.on("dblclick", ((t, e) => {
757
+ this.emit("dblclick", t, e);
758
+ })), this.renderer.on("scroll", ((t, e, i, s) => {
759
+ const r = this.getDuration();
760
+ this.emit("scroll", t * r, e * r, i, s);
761
+ })), this.renderer.on("render", (() => {
762
+ this.emit("redraw");
763
+ })), this.renderer.on("rendered", (() => {
764
+ this.emit("redrawcomplete");
765
+ })), this.renderer.on("dragstart", ((t) => {
766
+ this.emit("dragstart", t);
767
+ })), this.renderer.on("dragend", ((t) => {
768
+ this.emit("dragend", t);
769
+ })));
770
+ {
771
+ let t;
772
+ this.subscriptions.push(this.renderer.on("drag", ((e) => {
773
+ if (!this.options.interact) return;
774
+ let i;
775
+ this.renderer.renderProgress(e), clearTimeout(t), this.isPlaying() ? i = 0 : this.options.dragToSeek === !0 ? i = 200 : typeof this.options.dragToSeek == "object" && this.options.dragToSeek !== void 0 && (i = this.options.dragToSeek.debounceTime), t = setTimeout((() => {
776
+ this.seekTo(e);
777
+ }), i), this.emit("interaction", e * this.getDuration()), this.emit("drag", e);
778
+ })));
779
+ }
780
+ }
781
+ initPlugins() {
782
+ var t;
783
+ !((t = this.options.plugins) === null || t === void 0) && t.length && this.options.plugins.forEach(((e) => {
784
+ this.registerPlugin(e);
785
+ }));
786
+ }
787
+ unsubscribePlayerEvents() {
788
+ this.mediaSubscriptions.forEach(((t) => t())), this.mediaSubscriptions = [];
789
+ }
790
+ setOptions(t) {
791
+ this.options = Object.assign({}, this.options, t), t.duration && !t.peaks && (this.decodedData = R.createBuffer(this.exportPeaks(), t.duration)), t.peaks && t.duration && (this.decodedData = R.createBuffer(t.peaks, t.duration)), this.renderer.setOptions(this.options), t.audioRate && this.setPlaybackRate(t.audioRate), t.mediaControls != null && (this.getMediaElement().controls = t.mediaControls);
792
+ }
793
+ registerPlugin(t) {
794
+ return t._init(this), this.plugins.push(t), this.subscriptions.push(t.once("destroy", (() => {
795
+ this.plugins = this.plugins.filter(((e) => e !== t));
796
+ }))), t;
797
+ }
798
+ getWrapper() {
799
+ return this.renderer.getWrapper();
800
+ }
801
+ getWidth() {
802
+ return this.renderer.getWidth();
803
+ }
804
+ getScroll() {
805
+ return this.renderer.getScroll();
806
+ }
807
+ setScroll(t) {
808
+ return this.renderer.setScroll(t);
809
+ }
810
+ setScrollTime(t) {
811
+ const e = t / this.getDuration();
812
+ this.renderer.setScrollPercentage(e);
813
+ }
814
+ getActivePlugins() {
815
+ return this.plugins;
816
+ }
817
+ loadAudio(t, e, i, s) {
818
+ return y(this, void 0, void 0, (function* () {
819
+ var r;
820
+ if (this.emit("load", t), !this.options.media && this.isPlaying() && this.pause(), this.decodedData = null, this.stopAtPosition = null, !e && !i) {
821
+ const h = this.options.fetchParams || {};
822
+ window.AbortController && !h.signal && (this.abortController = new AbortController(), h.signal = (r = this.abortController) === null || r === void 0 ? void 0 : r.signal);
823
+ const l = (o) => this.emit("loading", o);
824
+ e = yield $.fetchBlob(t, l, h);
825
+ const a = this.options.blobMimeType;
826
+ a && (e = new Blob([e], { type: a }));
827
+ }
828
+ t == "" ? this.getMediaElement().removeAttribute("src") : this.setSrc(t, e);
829
+ const n = yield new Promise(((h) => {
830
+ const l = s || this.getDuration();
831
+ l ? h(l) : this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata", (() => h(this.getDuration())), { once: !0 }));
832
+ }));
833
+ if (!t && !e) {
834
+ const h = this.getMediaElement();
835
+ h instanceof W && (h.duration = n);
836
+ }
837
+ if (i) this.decodedData = R.createBuffer(i, n || 0);
838
+ else if (e) {
839
+ const h = yield e.arrayBuffer();
840
+ this.decodedData = yield R.decode(h, this.options.sampleRate);
841
+ }
842
+ this.decodedData && (this.emit("decode", this.getDuration()), this.renderer.render(this.decodedData)), this.emit("ready", this.getDuration());
843
+ }));
844
+ }
845
+ load(t, e, i) {
846
+ return y(this, void 0, void 0, (function* () {
847
+ try {
848
+ return yield this.loadAudio(t, void 0, e, i);
849
+ } catch (s) {
850
+ throw this.emit("error", s), s;
851
+ }
852
+ }));
853
+ }
854
+ loadBlob(t, e, i) {
855
+ return y(this, void 0, void 0, (function* () {
856
+ try {
857
+ return yield this.loadAudio("", t, e, i);
858
+ } catch (s) {
859
+ throw this.emit("error", s), s;
860
+ }
861
+ }));
862
+ }
863
+ zoom(t) {
864
+ if (!this.decodedData) throw new Error("No audio loaded");
865
+ this.renderer.zoom(t), this.emit("zoom", t);
866
+ }
867
+ getDecodedData() {
868
+ return this.decodedData;
869
+ }
870
+ exportPeaks({ channels: t = 2, maxLength: e = 8e3, precision: i = 1e4 } = {}) {
871
+ if (!this.decodedData) throw new Error("The audio has not been decoded yet");
872
+ const s = Math.min(t, this.decodedData.numberOfChannels), r = [];
873
+ for (let n = 0; n < s; n++) {
874
+ const h = this.decodedData.getChannelData(n), l = [], a = h.length / e;
875
+ for (let o = 0; o < e; o++) {
876
+ const c = h.slice(Math.floor(o * a), Math.ceil((o + 1) * a));
877
+ let d = 0;
878
+ for (let u = 0; u < c.length; u++) {
879
+ const m = c[u];
880
+ Math.abs(m) > Math.abs(d) && (d = m);
881
+ }
882
+ l.push(Math.round(d * i) / i);
883
+ }
884
+ r.push(l);
885
+ }
886
+ return r;
887
+ }
888
+ getDuration() {
889
+ let t = super.getDuration() || 0;
890
+ return t !== 0 && t !== 1 / 0 || !this.decodedData || (t = this.decodedData.duration), t;
891
+ }
892
+ toggleInteraction(t) {
893
+ this.options.interact = t;
894
+ }
895
+ setTime(t) {
896
+ this.stopAtPosition = null, super.setTime(t), this.updateProgress(t), this.emit("timeupdate", t);
897
+ }
898
+ seekTo(t) {
899
+ const e = this.getDuration() * t;
900
+ this.setTime(e);
901
+ }
902
+ play(t, e) {
903
+ const i = Object.create(null, { play: { get: () => super.play } });
904
+ return y(this, void 0, void 0, (function* () {
905
+ t != null && this.setTime(t);
906
+ const s = yield i.play.call(this);
907
+ return e != null && (this.media instanceof W ? this.media.stopAt(e) : this.stopAtPosition = e), s;
908
+ }));
909
+ }
910
+ playPause() {
911
+ return y(this, void 0, void 0, (function* () {
912
+ return this.isPlaying() ? this.pause() : this.play();
913
+ }));
914
+ }
915
+ stop() {
916
+ this.pause(), this.setTime(0);
917
+ }
918
+ skip(t) {
919
+ this.setTime(this.getCurrentTime() + t);
920
+ }
921
+ empty() {
922
+ this.load("", [[0]], 1e-3);
923
+ }
924
+ setMediaElement(t) {
925
+ this.unsubscribePlayerEvents(), super.setMediaElement(t), this.initPlayerEvents();
926
+ }
927
+ exportImage() {
928
+ return y(this, arguments, void 0, (function* (t = "image/png", e = 1, i = "dataURL") {
929
+ return this.renderer.exportImage(t, e, i);
930
+ }));
931
+ }
932
+ destroy() {
933
+ var t;
934
+ this.emit("destroy"), (t = this.abortController) === null || t === void 0 || t.abort(), this.plugins.forEach(((e) => e.destroy())), this.subscriptions.forEach(((e) => e())), this.unsubscribePlayerEvents(), this.timer.destroy(), this.renderer.destroy(), super.destroy();
935
+ }
936
+ }
937
+ L.BasePlugin = class extends T {
938
+ constructor(p) {
939
+ super(), this.subscriptions = [], this.options = p;
940
+ }
941
+ onInit() {
942
+ }
943
+ _init(p) {
944
+ this.wavesurfer = p, this.onInit();
945
+ }
946
+ destroy() {
947
+ this.emit("destroy"), this.subscriptions.forEach(((p) => p()));
948
+ }
949
+ }, L.dom = B;
950
+ export {
951
+ L as default
952
+ };