@aigamo/nostalgic-diva 1.19.2 → 1.19.4

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 (73) hide show
  1. package/dist/AudioPlayer-BMxdg9dp.js +35 -0
  2. package/dist/AudioPlayer-BMxdg9dp.js.map +1 -0
  3. package/dist/AudioPlayer-CgUxIJwa.cjs +2 -0
  4. package/dist/AudioPlayer-CgUxIJwa.cjs.map +1 -0
  5. package/dist/DailymotionPlayer-B4M9j0Lx.js +65 -0
  6. package/dist/DailymotionPlayer-B4M9j0Lx.js.map +1 -0
  7. package/dist/DailymotionPlayer-BdI4qcvJ.cjs +2 -0
  8. package/dist/DailymotionPlayer-BdI4qcvJ.cjs.map +1 -0
  9. package/dist/NiconicoPlayer-C1bgzaCT.cjs +2 -0
  10. package/dist/NiconicoPlayer-C1bgzaCT.cjs.map +1 -0
  11. package/dist/NiconicoPlayer-Cx3hGYsw.js +36 -0
  12. package/dist/NiconicoPlayer-Cx3hGYsw.js.map +1 -0
  13. package/dist/SoundCloudPlayer-BiFTnxn9.cjs +2 -0
  14. package/dist/SoundCloudPlayer-BiFTnxn9.cjs.map +1 -0
  15. package/dist/SoundCloudPlayer-C8QVPCXH.js +43 -0
  16. package/dist/SoundCloudPlayer-C8QVPCXH.js.map +1 -0
  17. package/dist/TwitchPlayer-C9D_eEaj.js +40 -0
  18. package/dist/TwitchPlayer-C9D_eEaj.js.map +1 -0
  19. package/dist/TwitchPlayer-DdhZD1Bh.cjs +2 -0
  20. package/dist/TwitchPlayer-DdhZD1Bh.cjs.map +1 -0
  21. package/dist/VimeoPlayer-DfBZwtd9.cjs +2 -0
  22. package/dist/VimeoPlayer-DfBZwtd9.cjs.map +1 -0
  23. package/dist/VimeoPlayer-UnKk2VAq.js +43 -0
  24. package/dist/VimeoPlayer-UnKk2VAq.js.map +1 -0
  25. package/dist/YouTubePlayer-CeTkdcOO.cjs +2 -0
  26. package/dist/YouTubePlayer-CeTkdcOO.cjs.map +1 -0
  27. package/dist/YouTubePlayer-bNmEJD02.js +39 -0
  28. package/dist/YouTubePlayer-bNmEJD02.js.map +1 -0
  29. package/dist/ensureScriptLoaded-CkK_-Amf.cjs +2 -0
  30. package/dist/ensureScriptLoaded-CkK_-Amf.cjs.map +1 -0
  31. package/dist/ensureScriptLoaded-HHnKf-aZ.js +24 -0
  32. package/dist/ensureScriptLoaded-HHnKf-aZ.js.map +1 -0
  33. package/dist/index.cjs.js +2 -2
  34. package/dist/index.cjs.js.map +1 -1
  35. package/dist/index.es.js +1232 -767
  36. package/dist/index.es.js.map +1 -1
  37. package/package.json +5 -5
  38. package/dist/AudioPlayer-CWI95ZSf.cjs +0 -2
  39. package/dist/AudioPlayer-CWI95ZSf.cjs.map +0 -1
  40. package/dist/AudioPlayer-Rgj403rr.js +0 -30
  41. package/dist/AudioPlayer-Rgj403rr.js.map +0 -1
  42. package/dist/DailymotionPlayer-CqYR3YjJ.cjs +0 -2
  43. package/dist/DailymotionPlayer-CqYR3YjJ.cjs.map +0 -1
  44. package/dist/DailymotionPlayer-DKnJvBrE.js +0 -60
  45. package/dist/DailymotionPlayer-DKnJvBrE.js.map +0 -1
  46. package/dist/NiconicoPlayer-BWepjJRp.js +0 -34
  47. package/dist/NiconicoPlayer-BWepjJRp.js.map +0 -1
  48. package/dist/NiconicoPlayer-DK-XPLSb.cjs +0 -2
  49. package/dist/NiconicoPlayer-DK-XPLSb.cjs.map +0 -1
  50. package/dist/PlayerContainer-CxyDj9x4.js +0 -690
  51. package/dist/PlayerContainer-CxyDj9x4.js.map +0 -1
  52. package/dist/PlayerContainer-LUwekvvj.cjs +0 -17
  53. package/dist/PlayerContainer-LUwekvvj.cjs.map +0 -1
  54. package/dist/SoundCloudPlayer-CIo1SPsW.js +0 -32
  55. package/dist/SoundCloudPlayer-CIo1SPsW.js.map +0 -1
  56. package/dist/SoundCloudPlayer-D1-SE7fO.cjs +0 -2
  57. package/dist/SoundCloudPlayer-D1-SE7fO.cjs.map +0 -1
  58. package/dist/TwitchPlayer-C-Zg7RPI.cjs +0 -2
  59. package/dist/TwitchPlayer-C-Zg7RPI.cjs.map +0 -1
  60. package/dist/TwitchPlayer-CipxSXDX.js +0 -33
  61. package/dist/TwitchPlayer-CipxSXDX.js.map +0 -1
  62. package/dist/VimeoPlayer-B2ew922s.cjs +0 -2
  63. package/dist/VimeoPlayer-B2ew922s.cjs.map +0 -1
  64. package/dist/VimeoPlayer-C-0MryDy.js +0 -32
  65. package/dist/VimeoPlayer-C-0MryDy.js.map +0 -1
  66. package/dist/YouTubePlayer-DXq_8Mrm.js +0 -35
  67. package/dist/YouTubePlayer-DXq_8Mrm.js.map +0 -1
  68. package/dist/YouTubePlayer-RHJqDD5s.cjs +0 -2
  69. package/dist/YouTubePlayer-RHJqDD5s.cjs.map +0 -1
  70. package/dist/ensureScriptLoaded-Bd04DRhn.js +0 -26
  71. package/dist/ensureScriptLoaded-Bd04DRhn.js.map +0 -1
  72. package/dist/ensureScriptLoaded-TVFV277C.cjs +0 -2
  73. package/dist/ensureScriptLoaded-TVFV277C.cjs.map +0 -1
package/dist/index.es.js CHANGED
@@ -1,773 +1,1238 @@
1
- import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./PlayerContainer-CxyDj9x4.js";
2
- import { Suspense as s, createContext as c, lazy as l, memo as u, useCallback as d, useContext as f, useMemo as p, useRef as m } from "react";
3
- import h from "react-dom";
4
- //#region src/components/NostalgicDivaProvider.tsx
5
- var g = t(), _ = c(void 0), v = ({ children: t, logger: n = a }) => {
6
- let i = m(e), o = d((e) => {
7
- n.log(r.Debug, "NostalgicDivaProvider.handleControllerChange", i.current, e), i.current = e;
8
- }, [n]), s = d(async (e) => {
9
- n.log(r.Debug, "NostalgicDivaProvider.loadVideo", i.current), await i.current.loadVideo(e);
10
- }, [n]), c = d(async () => {
11
- n.log(r.Debug, "NostalgicDivaProvider.play", i.current), await i.current.play();
12
- }, [n]), l = d(async () => {
13
- n.log(r.Debug, "NostalgicDivaProvider.pause", i.current), await i.current.pause();
14
- }, [n]), u = d(async (e) => {
15
- n.log(r.Debug, "NostalgicDivaProvider.setCurrentTime", i.current), await i.current.setCurrentTime(e), await i.current.play();
16
- }, [n]), f = d(async (e) => {
17
- n.log(r.Debug, "NostalgicDivaProvider.setVolume", i.current), await i.current.setVolume(e);
18
- }, [n]), h = d(async (e) => {
19
- n.log(r.Debug, "NostalgicDivaProvider.setMuted", i.current), await i.current.setMuted(e);
20
- }, [n]), v = d(async (e) => {
21
- n.log(r.Debug, "NostalgicDivaProvider.setPlaybackRate", i.current), await i.current.setPlaybackRate(e);
22
- }, [n]), y = d(async () => (n.log(r.Debug, "NostalgicDivaProvider.getDuration", i.current), await i.current.getDuration()), [n]), b = d(async () => (n.log(r.Debug, "NostalgicDivaProvider.getCurrentTime", i.current), await i.current.getCurrentTime()), [n]), x = d(async () => (n.log(r.Debug, "NostalgicDivaProvider.getVolume", i.current), await i.current.getVolume()), [n]), S = d(async () => (n.log(r.Debug, "NostalgicDivaProvider.getMuted", i.current), await i.current.getMuted()), [n]), C = d(async () => (n.log(r.Debug, "NostalgicDivaProvider.getPlaybackRate", i.current), await i.current.getPlaybackRate()), [n]), w = d((e) => i.current.supports(e), []), T = p(() => ({
23
- logger: n,
24
- handleControllerChange: o,
25
- loadVideo: s,
26
- play: c,
27
- pause: l,
28
- setCurrentTime: u,
29
- setVolume: f,
30
- setMuted: h,
31
- setPlaybackRate: v,
32
- getDuration: y,
33
- getCurrentTime: b,
34
- getVolume: x,
35
- getMuted: S,
36
- getPlaybackRate: C,
37
- supports: w
38
- }), [
39
- n,
40
- o,
41
- s,
42
- c,
43
- l,
44
- u,
45
- f,
46
- h,
47
- v,
48
- y,
49
- b,
50
- x,
51
- S,
52
- C,
53
- w
54
- ]);
55
- return /* @__PURE__ */ (0, g.jsx)(_.Provider, {
56
- value: T,
57
- children: t
58
- });
59
- }, y = () => f(_), b = class {
60
- constructor(e) {
61
- this.type = e;
62
- }
63
- }, x = /\.(m4a|m4b|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i, S = /\.(mp4|og[gv]|webm|mov|m4v)(#t=[,\d+]+)?($|\?)/i, C = class extends b {
64
- constructor() {
65
- super("Audio");
66
- }
67
- canPlay(e) {
68
- return x.test(e) || S.test(e);
69
- }
70
- extractVideoId(e) {
71
- return e;
72
- }
73
- }, w = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:[\w.#_-]+)?/, T = class extends b {
74
- constructor() {
75
- super("Dailymotion");
76
- }
77
- canPlay(e) {
78
- return w.test(e);
79
- }
80
- extractVideoId(e) {
81
- return w.exec(e)?.[1];
82
- }
83
- }, E = /(?:www\.|)?nicovideo\.jp\/watch\/(\w+)$/, D = class extends b {
84
- constructor() {
85
- super("Niconico");
86
- }
87
- canPlay(e) {
88
- return E.test(e);
89
- }
90
- extractVideoId(e) {
91
- return E.exec(e)?.[1];
92
- }
93
- }, O = /(?:soundcloud\.com|snd\.sc)\/[^.]+$/, k = class extends b {
94
- constructor() {
95
- super("SoundCloud");
96
- }
97
- canPlay(e) {
98
- return O.test(e);
99
- }
100
- extractVideoId(e) {
101
- return e;
102
- }
103
- }, A = /(?:www\.|go\.)?twitch\.tv\/videos\/(\d+)($|\?)/, j = class extends b {
104
- constructor() {
105
- super("Twitch");
106
- }
107
- canPlay(e) {
108
- return A.test(e);
109
- }
110
- extractVideoId(e) {
111
- return A.exec(e)?.[1];
112
- }
113
- }, M = /vimeo\.com\/(\d+)$/, N = class extends b {
114
- constructor() {
115
- super("Vimeo");
116
- }
117
- canPlay(e) {
118
- return M.test(e);
119
- }
120
- extractVideoId(e) {
121
- return M.exec(e)?.[1];
122
- }
123
- }, P = /(?:youtu\.be\/|youtube(?:-nocookie|education)?\.com\/(?:embed\/|v\/|watch\/|watch\?v=|watch\?.+&v=|shorts\/|live\/))((\w|-){11})|youtube\.com\/playlist\?list=|youtube\.com\/user\//, F = [
124
- new class extends b {
125
- constructor() {
126
- super("YouTube");
127
- }
128
- canPlay(e) {
129
- return P.test(e);
130
- }
131
- extractVideoId(e) {
132
- return P.exec(e)?.[1];
133
- }
134
- }(),
135
- new j(),
136
- new N(),
137
- new T(),
138
- new k(),
139
- new C(),
140
- new D()
1
+ import { jsx as d, Fragment as F } from "react/jsx-runtime";
2
+ import { createContext as H, useContext as G, useRef as C, useCallback as o, useMemo as B, lazy as m, memo as $, Suspense as z, useState as I, useEffect as k } from "react";
3
+ import X from "react-dom";
4
+ var s = /* @__PURE__ */ ((a) => (a[a.Trace = 0] = "Trace", a[a.Debug = 1] = "Debug", a[a.Information = 2] = "Information", a[a.Warning = 3] = "Warning", a[a.Error = 4] = "Error", a[a.Critical = 5] = "Critical", a[a.None = 6] = "None", a))(s || {});
5
+ class q {
6
+ title = "nostalgic-diva";
7
+ createMessage(e) {
8
+ return `[${this.title}] ${e}`;
9
+ }
10
+ debug(e, ...t) {
11
+ console.debug(this.createMessage(e), ...t);
12
+ }
13
+ error(e, ...t) {
14
+ console.error(this.createMessage(e), ...t);
15
+ }
16
+ warn(e, ...t) {
17
+ console.warn(this.createMessage(e), ...t);
18
+ }
19
+ isEnabled() {
20
+ return !0;
21
+ }
22
+ log(e, t, ...r) {
23
+ switch (e) {
24
+ case 1:
25
+ this.debug(t, ...r);
26
+ break;
27
+ case 3:
28
+ this.warn(t, ...r);
29
+ break;
30
+ case 4:
31
+ this.error(t, ...r);
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ const K = new q();
37
+ class Z {
38
+ async attach() {
39
+ }
40
+ async detach() {
41
+ }
42
+ async loadVideo(e) {
43
+ }
44
+ async play() {
45
+ }
46
+ async pause() {
47
+ }
48
+ async setCurrentTime(e) {
49
+ }
50
+ async setVolume(e) {
51
+ }
52
+ async setMuted(e) {
53
+ }
54
+ async setPlaybackRate(e) {
55
+ }
56
+ async getDuration() {
57
+ return 0;
58
+ }
59
+ async getCurrentTime() {
60
+ return 0;
61
+ }
62
+ async getVolume() {
63
+ return 0;
64
+ }
65
+ async getMuted() {
66
+ return !1;
67
+ }
68
+ async getPlaybackRate() {
69
+ return 0;
70
+ }
71
+ supports(e) {
72
+ return !1;
73
+ }
74
+ }
75
+ const f = new Z(), W = H(
76
+ void 0
77
+ ), J = ({
78
+ children: a,
79
+ logger: e = K
80
+ }) => {
81
+ const t = C(f), r = o(
82
+ (c) => {
83
+ e.log(
84
+ s.Debug,
85
+ "NostalgicDivaProvider.handleControllerChange",
86
+ t.current,
87
+ c
88
+ ), t.current = c;
89
+ },
90
+ [e]
91
+ ), i = o(
92
+ async (c) => {
93
+ e.log(
94
+ s.Debug,
95
+ "NostalgicDivaProvider.loadVideo",
96
+ t.current
97
+ ), await t.current.loadVideo(c);
98
+ },
99
+ [e]
100
+ ), n = o(async () => {
101
+ e.log(
102
+ s.Debug,
103
+ "NostalgicDivaProvider.play",
104
+ t.current
105
+ ), await t.current.play();
106
+ }, [e]), u = o(async () => {
107
+ e.log(
108
+ s.Debug,
109
+ "NostalgicDivaProvider.pause",
110
+ t.current
111
+ ), await t.current.pause();
112
+ }, [e]), p = o(
113
+ async (c) => {
114
+ e.log(
115
+ s.Debug,
116
+ "NostalgicDivaProvider.setCurrentTime",
117
+ t.current
118
+ ), await t.current.setCurrentTime(c), await t.current.play();
119
+ },
120
+ [e]
121
+ ), y = o(
122
+ async (c) => {
123
+ e.log(
124
+ s.Debug,
125
+ "NostalgicDivaProvider.setVolume",
126
+ t.current
127
+ ), await t.current.setVolume(c);
128
+ },
129
+ [e]
130
+ ), h = o(
131
+ async (c) => {
132
+ e.log(
133
+ s.Debug,
134
+ "NostalgicDivaProvider.setMuted",
135
+ t.current
136
+ ), await t.current.setMuted(c);
137
+ },
138
+ [e]
139
+ ), E = o(
140
+ async (c) => {
141
+ e.log(
142
+ s.Debug,
143
+ "NostalgicDivaProvider.setPlaybackRate",
144
+ t.current
145
+ ), await t.current.setPlaybackRate(c);
146
+ },
147
+ [e]
148
+ ), b = o(async () => (e.log(
149
+ s.Debug,
150
+ "NostalgicDivaProvider.getDuration",
151
+ t.current
152
+ ), await t.current.getDuration()), [e]), D = o(async () => (e.log(
153
+ s.Debug,
154
+ "NostalgicDivaProvider.getCurrentTime",
155
+ t.current
156
+ ), await t.current.getCurrentTime()), [e]), P = o(async () => (e.log(
157
+ s.Debug,
158
+ "NostalgicDivaProvider.getVolume",
159
+ t.current
160
+ ), await t.current.getVolume()), [e]), V = o(async () => (e.log(
161
+ s.Debug,
162
+ "NostalgicDivaProvider.getMuted",
163
+ t.current
164
+ ), await t.current.getMuted()), [e]), w = o(async () => (e.log(
165
+ s.Debug,
166
+ "NostalgicDivaProvider.getPlaybackRate",
167
+ t.current
168
+ ), await t.current.getPlaybackRate()), [e]), T = o(
169
+ (c) => t.current.supports(c),
170
+ []
171
+ ), l = B(
172
+ () => ({
173
+ logger: e,
174
+ handleControllerChange: r,
175
+ loadVideo: i,
176
+ play: n,
177
+ pause: u,
178
+ setCurrentTime: p,
179
+ setVolume: y,
180
+ setMuted: h,
181
+ setPlaybackRate: E,
182
+ getDuration: b,
183
+ getCurrentTime: D,
184
+ getVolume: P,
185
+ getMuted: V,
186
+ getPlaybackRate: w,
187
+ supports: T
188
+ }),
189
+ [
190
+ e,
191
+ r,
192
+ i,
193
+ n,
194
+ u,
195
+ p,
196
+ y,
197
+ h,
198
+ E,
199
+ b,
200
+ D,
201
+ P,
202
+ V,
203
+ w,
204
+ T
205
+ ]
206
+ );
207
+ return /* @__PURE__ */ d(W.Provider, { value: l, children: a });
208
+ }, Q = () => G(W);
209
+ class g {
210
+ constructor(e) {
211
+ this.type = e;
212
+ }
213
+ }
214
+ const ee = /\.(m4a|m4b|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i, te = /\.(mp4|og[gv]|webm|mov|m4v)(#t=[,\d+]+)?($|\?)/i;
215
+ class ae extends g {
216
+ constructor() {
217
+ super("Audio");
218
+ }
219
+ canPlay(e) {
220
+ return ee.test(e) || te.test(e);
221
+ }
222
+ extractVideoId(e) {
223
+ return e;
224
+ }
225
+ }
226
+ const S = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:[\w.#_-]+)?/;
227
+ class re extends g {
228
+ constructor() {
229
+ super("Dailymotion");
230
+ }
231
+ canPlay(e) {
232
+ return S.test(e);
233
+ }
234
+ extractVideoId(e) {
235
+ return S.exec(e)?.[1];
236
+ }
237
+ }
238
+ const A = /(?:www\.|)?nicovideo\.jp\/watch\/(\w+)$/;
239
+ class se extends g {
240
+ constructor() {
241
+ super("Niconico");
242
+ }
243
+ canPlay(e) {
244
+ return A.test(e);
245
+ }
246
+ extractVideoId(e) {
247
+ return A.exec(e)?.[1];
248
+ }
249
+ }
250
+ const ie = /(?:soundcloud\.com|snd\.sc)\/[^.]+$/;
251
+ class ne extends g {
252
+ constructor() {
253
+ super("SoundCloud");
254
+ }
255
+ canPlay(e) {
256
+ return ie.test(e);
257
+ }
258
+ extractVideoId(e) {
259
+ return e;
260
+ }
261
+ }
262
+ const U = /(?:www\.|go\.)?twitch\.tv\/videos\/(\d+)($|\?)/;
263
+ class oe extends g {
264
+ constructor() {
265
+ super("Twitch");
266
+ }
267
+ canPlay(e) {
268
+ return U.test(e);
269
+ }
270
+ extractVideoId(e) {
271
+ return U.exec(e)?.[1];
272
+ }
273
+ }
274
+ const x = /vimeo\.com\/(\d+)$/;
275
+ class ce extends g {
276
+ constructor() {
277
+ super("Vimeo");
278
+ }
279
+ canPlay(e) {
280
+ return x.test(e);
281
+ }
282
+ extractVideoId(e) {
283
+ return x.exec(e)?.[1];
284
+ }
285
+ }
286
+ const _ = /(?:youtu\.be\/|youtube(?:-nocookie|education)?\.com\/(?:embed\/|v\/|watch\/|watch\?v=|watch\?.+&v=|shorts\/|live\/))((\w|-){11})|youtube\.com\/playlist\?list=|youtube\.com\/user\//;
287
+ class le extends g {
288
+ constructor() {
289
+ super("YouTube");
290
+ }
291
+ canPlay(e) {
292
+ return _.test(e);
293
+ }
294
+ extractVideoId(e) {
295
+ return _.exec(e)?.[1];
296
+ }
297
+ }
298
+ const de = [
299
+ new le(),
300
+ new oe(),
301
+ new ce(),
302
+ new re(),
303
+ new ne(),
304
+ new ae(),
305
+ new se()
141
306
  ];
142
- function I(e) {
143
- return F.find((t) => t.canPlay(e));
307
+ function ue(a) {
308
+ return de.find((e) => e.canPlay(a));
309
+ }
310
+ const he = new Map(
311
+ Object.entries({
312
+ Audio: m(() => import("./AudioPlayer-BMxdg9dp.js")),
313
+ Dailymotion: m(() => import("./DailymotionPlayer-B4M9j0Lx.js")),
314
+ Niconico: m(() => import("./NiconicoPlayer-Cx3hGYsw.js")),
315
+ SoundCloud: m(() => import("./SoundCloudPlayer-C8QVPCXH.js")),
316
+ Twitch: m(() => import("./TwitchPlayer-C9D_eEaj.js")),
317
+ Vimeo: m(() => import("./VimeoPlayer-UnKk2VAq.js")),
318
+ YouTube: m(() => import("./YouTubePlayer-bNmEJD02.js"))
319
+ })
320
+ );
321
+ function pe(a) {
322
+ const e = ue(a);
323
+ if (e === void 0)
324
+ return;
325
+ const { type: t, extractVideoId: r } = e, i = r(a);
326
+ if (i !== void 0)
327
+ return { type: t, videoId: i };
328
+ }
329
+ const Y = $(() => /* @__PURE__ */ d("div", { style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ d(
330
+ "iframe",
331
+ {
332
+ src: "about:blank",
333
+ title: "about:blank",
334
+ style: {
335
+ width: "100%",
336
+ height: "100%",
337
+ border: 0
338
+ }
339
+ }
340
+ ) })), ye = $(
341
+ ({
342
+ src: a,
343
+ options: e,
344
+ onControllerChange: t
345
+ }) => {
346
+ const r = Q(), i = o(
347
+ (h) => {
348
+ r.handleControllerChange(h), t?.(h);
349
+ },
350
+ [r, t]
351
+ );
352
+ r.logger.log(s.Debug, "NostalgicDiva");
353
+ const n = pe(a);
354
+ if (n === void 0)
355
+ return r.logger.log(
356
+ s.Warning,
357
+ `Failed to extract type and videoId from src: "${a}". Returning EmptyPlayer.`
358
+ ), /* @__PURE__ */ d(Y, {});
359
+ const { type: u, videoId: p } = n, y = he.get(u);
360
+ return y === void 0 ? (r.logger.log(
361
+ s.Warning,
362
+ `No player found for type "${u}" (videoId: "${p}"). Returning EmptyPlayer.`
363
+ ), /* @__PURE__ */ d(Y, {})) : /* @__PURE__ */ d(z, { fallback: null, children: /* @__PURE__ */ d(
364
+ y,
365
+ {
366
+ logger: r.logger,
367
+ type: u,
368
+ onControllerChange: i,
369
+ videoId: p,
370
+ options: e
371
+ }
372
+ ) });
373
+ }
374
+ );
375
+ class me extends HTMLElement {
376
+ static observedAttributes = ["src"];
377
+ container;
378
+ controller = f;
379
+ constructor() {
380
+ super(), this.container = this.attachShadow({ mode: "closed" });
381
+ }
382
+ get src() {
383
+ return this.getAttribute("src") ?? "";
384
+ }
385
+ set src(e) {
386
+ this.setAttribute("src", e);
387
+ }
388
+ #t = {
389
+ onError: (e) => this.dispatchEvent(new CustomEvent("error", { detail: e })),
390
+ onLoaded: (e) => this.dispatchEvent(new CustomEvent("loaded", { detail: e })),
391
+ onPlay: () => this.dispatchEvent(new CustomEvent("play")),
392
+ onPause: () => this.dispatchEvent(new CustomEvent("pause")),
393
+ onEnded: () => this.dispatchEvent(new CustomEvent("ended")),
394
+ onTimeUpdate: (e) => this.dispatchEvent(new CustomEvent("timeupdate", { detail: e }))
395
+ };
396
+ #a = (e) => {
397
+ console.debug(
398
+ "[@nostalgic-diva/web-components] handleControllerChange"
399
+ ), this.controller = e;
400
+ };
401
+ #e() {
402
+ X.render(
403
+ /* @__PURE__ */ d(J, { children: /* @__PURE__ */ d(
404
+ ye,
405
+ {
406
+ src: this.src,
407
+ options: this.#t,
408
+ onControllerChange: this.#a
409
+ }
410
+ ) }),
411
+ this.container
412
+ );
413
+ }
414
+ connectedCallback() {
415
+ console.debug("[@nostalgic-diva/web-components] connectedCallback"), this.#e();
416
+ }
417
+ disconnectedCallback() {
418
+ console.debug("[@nostalgic-diva/web-components] disconnectedCallback");
419
+ }
420
+ attributeChangedCallback() {
421
+ console.debug(
422
+ "[@nostalgic-diva/web-components] attributeChangedCallback"
423
+ ), this.#e();
424
+ }
425
+ async loadVideo(e) {
426
+ await this.controller.loadVideo(e);
427
+ }
428
+ async play() {
429
+ await this.controller.play();
430
+ }
431
+ async pause() {
432
+ await this.controller.pause();
433
+ }
434
+ async setCurrentTime(e) {
435
+ await this.controller.setCurrentTime(e);
436
+ }
437
+ async setVolume(e) {
438
+ await this.controller.setVolume(e);
439
+ }
440
+ async setMuted(e) {
441
+ await this.controller.setMuted(e);
442
+ }
443
+ async setPlaybackRate(e) {
444
+ await this.controller.setPlaybackRate(e);
445
+ }
446
+ async getDuration() {
447
+ return await this.controller.getDuration();
448
+ }
449
+ async getCurrentTime() {
450
+ return await this.controller.getCurrentTime();
451
+ }
452
+ async getVolume() {
453
+ return await this.controller.getVolume();
454
+ }
455
+ async getMuted() {
456
+ return await this.controller.getMuted();
457
+ }
458
+ async getPlaybackRate() {
459
+ return await this.controller.getPlaybackRate();
460
+ }
461
+ supports(e) {
462
+ return this.controller.supports(e);
463
+ }
144
464
  }
145
- //#endregion
146
- //#region src/components/NostalgicDiva.tsx
147
- var L = new Map(Object.entries({
148
- Audio: l(() => import("./AudioPlayer-Rgj403rr.js")),
149
- Dailymotion: l(() => import("./DailymotionPlayer-DKnJvBrE.js")),
150
- Niconico: l(() => import("./NiconicoPlayer-BWepjJRp.js")),
151
- SoundCloud: l(() => import("./SoundCloudPlayer-CIo1SPsW.js")),
152
- Twitch: l(() => import("./TwitchPlayer-CipxSXDX.js")),
153
- Vimeo: l(() => import("./VimeoPlayer-C-0MryDy.js")),
154
- YouTube: l(() => import("./YouTubePlayer-DXq_8Mrm.js"))
155
- }));
156
- function R(e) {
157
- let t = I(e);
158
- if (t === void 0) return;
159
- let { type: n, extractVideoId: r } = t, i = r(e);
160
- if (i !== void 0) return {
161
- type: n,
162
- videoId: i
163
- };
465
+ function Pe() {
466
+ customElements.define("nostalgic-diva", me);
164
467
  }
165
- var z = u(() => /* @__PURE__ */ (0, g.jsx)("div", {
166
- style: {
167
- width: "100%",
168
- height: "100%"
169
- },
170
- children: /* @__PURE__ */ (0, g.jsx)("iframe", {
171
- src: "about:blank",
172
- title: "about:blank",
173
- style: {
174
- width: "100%",
175
- height: "100%",
176
- border: 0
177
- }
178
- })
179
- })), B = u(({ src: e, options: t, onControllerChange: n }) => {
180
- let i = y(), a = d((e) => {
181
- i.handleControllerChange(e), n?.(e);
182
- }, [i, n]);
183
- i.logger.log(r.Debug, "NostalgicDiva");
184
- let o = R(e);
185
- if (o === void 0) return i.logger.log(r.Warning, `Failed to extract type and videoId from src: "${e}". Returning EmptyPlayer.`), /* @__PURE__ */ (0, g.jsx)(z, {});
186
- let { type: c, videoId: l } = o, u = L.get(c);
187
- return u === void 0 ? (i.logger.log(r.Warning, `No player found for type "${c}" (videoId: "${l}"). Returning EmptyPlayer.`), /* @__PURE__ */ (0, g.jsx)(z, {})) : /* @__PURE__ */ (0, g.jsx)(s, {
188
- fallback: null,
189
- children: /* @__PURE__ */ (0, g.jsx)(u, {
190
- logger: i.logger,
191
- type: c,
192
- onControllerChange: a,
193
- videoId: l,
194
- options: t
195
- })
196
- });
197
- }), V = class extends HTMLElement {
198
- static observedAttributes = ["src"];
199
- container;
200
- controller = e;
201
- constructor() {
202
- super(), this.container = this.attachShadow({ mode: "closed" });
203
- }
204
- get src() {
205
- return this.getAttribute("src") ?? "";
206
- }
207
- set src(e) {
208
- this.setAttribute("src", e);
209
- }
210
- #e = {
211
- onError: (e) => this.dispatchEvent(new CustomEvent("error", { detail: e })),
212
- onLoaded: (e) => this.dispatchEvent(new CustomEvent("loaded", { detail: e })),
213
- onPlay: () => this.dispatchEvent(new CustomEvent("play")),
214
- onPause: () => this.dispatchEvent(new CustomEvent("pause")),
215
- onEnded: () => this.dispatchEvent(new CustomEvent("ended")),
216
- onTimeUpdate: (e) => this.dispatchEvent(new CustomEvent("timeupdate", { detail: e }))
217
- };
218
- #t = (e) => {
219
- console.debug("[@nostalgic-diva/web-components] handleControllerChange"), this.controller = e;
220
- };
221
- #n() {
222
- h.render(/* @__PURE__ */ (0, g.jsx)(v, { children: /* @__PURE__ */ (0, g.jsx)(B, {
223
- src: this.src,
224
- options: this.#e,
225
- onControllerChange: this.#t
226
- }) }), this.container);
227
- }
228
- connectedCallback() {
229
- console.debug("[@nostalgic-diva/web-components] connectedCallback"), this.#n();
230
- }
231
- disconnectedCallback() {
232
- console.debug("[@nostalgic-diva/web-components] disconnectedCallback");
233
- }
234
- attributeChangedCallback() {
235
- console.debug("[@nostalgic-diva/web-components] attributeChangedCallback"), this.#n();
236
- }
237
- async loadVideo(e) {
238
- await this.controller.loadVideo(e);
239
- }
240
- async play() {
241
- await this.controller.play();
242
- }
243
- async pause() {
244
- await this.controller.pause();
245
- }
246
- async setCurrentTime(e) {
247
- await this.controller.setCurrentTime(e);
248
- }
249
- async setVolume(e) {
250
- await this.controller.setVolume(e);
251
- }
252
- async setMuted(e) {
253
- await this.controller.setMuted(e);
254
- }
255
- async setPlaybackRate(e) {
256
- await this.controller.setPlaybackRate(e);
257
- }
258
- async getDuration() {
259
- return await this.controller.getDuration();
260
- }
261
- async getCurrentTime() {
262
- return await this.controller.getCurrentTime();
263
- }
264
- async getVolume() {
265
- return await this.controller.getVolume();
266
- }
267
- async getMuted() {
268
- return await this.controller.getMuted();
269
- }
270
- async getPlaybackRate() {
271
- return await this.controller.getPlaybackRate();
272
- }
273
- supports(e) {
274
- return this.controller.supports(e);
275
- }
468
+ function ge() {
469
+ const a = C(!0);
470
+ return a.current ? (a.current = !1, !0) : a.current;
471
+ }
472
+ const ve = (a, e) => a === e;
473
+ function be(a, e = ve) {
474
+ const t = C(), r = C(a);
475
+ return !ge() && !e(r.current, a) && (t.current = r.current, r.current = a), t.current;
476
+ }
477
+ class v {
478
+ constructor(e, t, r) {
479
+ this.logger = e, this.player = t, this.options = r, this.logger.log(s.Debug, "ctor");
480
+ }
481
+ supports(e) {
482
+ return this[e] !== void 0;
483
+ }
484
+ }
485
+ class M {
486
+ constructor(e, t, r, i, n) {
487
+ this.logger = e, this.type = t, this.player = r, this.options = i, this.controllerFactory = n, this.id = M.nextId++;
488
+ }
489
+ static nextId = 1;
490
+ id;
491
+ impl;
492
+ createMessage(e) {
493
+ return `${this.type}#${this.id} ${e}`;
494
+ }
495
+ debug(e, ...t) {
496
+ this.logger.log(
497
+ s.Debug,
498
+ this.createMessage(e),
499
+ ...t
500
+ );
501
+ }
502
+ error(e, ...t) {
503
+ this.logger.log(
504
+ s.Error,
505
+ this.createMessage(e),
506
+ ...t
507
+ );
508
+ }
509
+ async attach(e) {
510
+ if (this.debug("attach", e), this.impl) {
511
+ this.debug("player is already attached");
512
+ return;
513
+ }
514
+ this.debug("Attaching player..."), this.impl = new this.controllerFactory(
515
+ this.logger,
516
+ this.player,
517
+ this.options
518
+ ), await this.impl.attach(e), this.debug("player attached");
519
+ }
520
+ createPlayerNotAttachedError() {
521
+ return this.error("player is not attached"), new Error("player is not attached");
522
+ }
523
+ createCommandNotSupportedError(e) {
524
+ return new Error(`${e} is not supported`);
525
+ }
526
+ async detach() {
527
+ if (this.debug("detach"), this.impl === void 0)
528
+ throw this.createPlayerNotAttachedError();
529
+ await this.impl.detach(), this.impl = void 0;
530
+ }
531
+ async loadVideo(e) {
532
+ if (this.debug("loadVideo", e), this.impl === void 0)
533
+ throw this.createPlayerNotAttachedError();
534
+ if (this.impl.loadVideo === void 0)
535
+ throw this.createCommandNotSupportedError("loadVideo");
536
+ this.debug("Loading video..."), await this.impl.loadVideo(e), this.debug("video loaded", e);
537
+ }
538
+ play() {
539
+ if (this.debug("play"), this.impl === void 0)
540
+ throw this.createPlayerNotAttachedError();
541
+ if (this.impl.play === void 0)
542
+ throw this.createCommandNotSupportedError("play");
543
+ return this.impl.play();
544
+ }
545
+ pause() {
546
+ if (this.debug("pause"), this.impl === void 0)
547
+ throw this.createPlayerNotAttachedError();
548
+ if (this.impl.pause === void 0)
549
+ throw this.createCommandNotSupportedError("pause");
550
+ return this.impl.pause();
551
+ }
552
+ setCurrentTime(e) {
553
+ if (this.debug("setCurrentTime", e), this.impl === void 0)
554
+ throw this.createPlayerNotAttachedError();
555
+ if (this.impl.setCurrentTime === void 0)
556
+ throw this.createCommandNotSupportedError("setCurrentTime");
557
+ return this.impl.setCurrentTime(e);
558
+ }
559
+ setVolume(e) {
560
+ if (this.debug("setVolume", e), this.impl === void 0)
561
+ throw this.createPlayerNotAttachedError();
562
+ if (this.impl.setVolume === void 0)
563
+ throw this.createCommandNotSupportedError("setVolume");
564
+ return this.impl.setVolume(e);
565
+ }
566
+ setMuted(e) {
567
+ if (this.debug("setMuted", e), this.impl === void 0)
568
+ throw this.createPlayerNotAttachedError();
569
+ if (this.impl.setMuted === void 0)
570
+ throw this.createCommandNotSupportedError("setMuted");
571
+ return this.impl.setMuted(e);
572
+ }
573
+ setPlaybackRate(e) {
574
+ if (this.debug("setPlaybackRate", e), this.impl === void 0)
575
+ throw this.createPlayerNotAttachedError();
576
+ if (this.impl.setPlaybackRate === void 0)
577
+ throw this.createCommandNotSupportedError("setPlaybackRate");
578
+ return this.impl.setPlaybackRate(e);
579
+ }
580
+ getDuration() {
581
+ if (this.debug("getDuration"), this.impl === void 0)
582
+ throw this.createPlayerNotAttachedError();
583
+ if (this.impl.getDuration === void 0)
584
+ throw this.createCommandNotSupportedError("getDuration");
585
+ return this.impl.getDuration();
586
+ }
587
+ getCurrentTime() {
588
+ if (this.debug("getCurrentTime"), this.impl === void 0)
589
+ throw this.createPlayerNotAttachedError();
590
+ if (this.impl.getCurrentTime === void 0)
591
+ throw this.createCommandNotSupportedError("getCurrentTime");
592
+ return this.impl.getCurrentTime();
593
+ }
594
+ getVolume() {
595
+ if (this.debug("getVolume"), this.impl === void 0)
596
+ throw this.createPlayerNotAttachedError();
597
+ if (this.impl.getVolume === void 0)
598
+ throw this.createCommandNotSupportedError("getVolume");
599
+ return this.impl.getVolume();
600
+ }
601
+ getMuted() {
602
+ if (this.debug("getMuted"), this.impl === void 0)
603
+ throw this.createPlayerNotAttachedError();
604
+ if (this.impl.getMuted === void 0)
605
+ throw this.createCommandNotSupportedError("getMuted");
606
+ return this.impl.getMuted();
607
+ }
608
+ getPlaybackRate() {
609
+ if (this.debug("getPlaybackRate"), this.impl === void 0)
610
+ throw this.createPlayerNotAttachedError();
611
+ if (this.impl.getPlaybackRate === void 0)
612
+ throw this.createCommandNotSupportedError("getPlaybackRate");
613
+ return this.impl.getPlaybackRate();
614
+ }
615
+ supports(e) {
616
+ if (this.impl === void 0)
617
+ throw this.createPlayerNotAttachedError();
618
+ return this.impl.supports(e);
619
+ }
620
+ }
621
+ const Te = ({
622
+ logger: a,
623
+ type: e,
624
+ loadScript: t,
625
+ playerFactory: r,
626
+ onControllerChange: i,
627
+ videoId: n,
628
+ options: u,
629
+ controllerFactory: p,
630
+ children: y
631
+ }) => {
632
+ a.log(s.Debug, "PlayerContainer");
633
+ const h = C(n), E = C(void 0), [b, D] = I(), [P, V] = I(f), w = o(
634
+ (l) => {
635
+ V(l), i?.(l);
636
+ },
637
+ [i]
638
+ );
639
+ k(() => {
640
+ (t?.() ?? Promise.resolve()).then(() => r(E.current, h.current)).then((l) => D(l));
641
+ }, [t, r]), k(() => {
642
+ if (b === void 0)
643
+ return;
644
+ const l = new M(
645
+ a,
646
+ e,
647
+ b,
648
+ u,
649
+ p
650
+ );
651
+ return l.attach(h.current).then(() => w(l)), () => {
652
+ l.detach().finally(() => w(f));
653
+ };
654
+ }, [
655
+ a,
656
+ e,
657
+ t,
658
+ b,
659
+ u,
660
+ p,
661
+ w
662
+ ]);
663
+ const T = be(n);
664
+ return k(() => {
665
+ T !== void 0 && P.loadVideo(n);
666
+ }, [T, n, P]), /* @__PURE__ */ d(F, { children: y(E, h.current) });
276
667
  };
277
- function H() {
278
- customElements.define("nostalgic-diva", V);
668
+ class De extends v {
669
+ async attach() {
670
+ this.player.onerror = (e) => this.options?.onError?.(e), this.player.onloadeddata = () => this.options?.onLoaded?.({ id: this.player.src }), this.player.onplay = () => this.options?.onPlay?.(), this.player.onpause = () => this.options?.onPause?.(), this.player.onended = () => this.options?.onEnded?.(), this.player.ontimeupdate = () => {
671
+ this.options?.onTimeUpdate?.({
672
+ duration: this.player.duration,
673
+ percent: this.player.currentTime / this.player.duration,
674
+ seconds: this.player.currentTime
675
+ });
676
+ };
677
+ }
678
+ async detach() {
679
+ this.player.onerror = null, this.player.onloadeddata = null, this.player.onplay = null, this.player.onpause = null, this.player.onended = null, this.player.ontimeupdate = null;
680
+ }
681
+ async loadVideo(e) {
682
+ this.player.src = e;
683
+ }
684
+ async play() {
685
+ await this.player.play();
686
+ }
687
+ async pause() {
688
+ this.player.pause();
689
+ }
690
+ async setCurrentTime(e) {
691
+ this.player.currentTime = e;
692
+ }
693
+ async setVolume(e) {
694
+ this.player.volume = e;
695
+ }
696
+ async setMuted(e) {
697
+ this.player.muted = e;
698
+ }
699
+ async setPlaybackRate(e) {
700
+ this.player.playbackRate = e;
701
+ }
702
+ async getDuration() {
703
+ return this.player.duration;
704
+ }
705
+ async getCurrentTime() {
706
+ return this.player.currentTime;
707
+ }
708
+ async getVolume() {
709
+ return this.player.volume;
710
+ }
711
+ async getMuted() {
712
+ return this.player.muted;
713
+ }
714
+ async getPlaybackRate() {
715
+ return this.player.playbackRate;
716
+ }
717
+ }
718
+ const O = [
719
+ "apiready",
720
+ "seeked",
721
+ "video_end",
722
+ "durationchange",
723
+ "pause",
724
+ "playing",
725
+ "error"
726
+ ];
727
+ class Ve extends v {
728
+ handlePlayerEvents = (e) => {
729
+ switch (e.type) {
730
+ case "apiready":
731
+ this.options?.onLoaded?.({ id: this.player.video.videoId });
732
+ break;
733
+ case "seeked":
734
+ this.options?.onTimeUpdate?.({
735
+ duration: this.player.duration,
736
+ percent: this.player.currentTime / this.player.duration,
737
+ seconds: this.player.currentTime
738
+ });
739
+ break;
740
+ case "video_end":
741
+ this.options?.onEnded?.();
742
+ break;
743
+ case "durationchange":
744
+ break;
745
+ case "pause":
746
+ this.options?.onPause?.();
747
+ break;
748
+ case "playing":
749
+ this.options?.onPlay?.();
750
+ break;
751
+ case "error":
752
+ this.options?.onError?.(e);
753
+ break;
754
+ }
755
+ };
756
+ async attach(e) {
757
+ for (const t of O)
758
+ this.player.addEventListener(t, this.handlePlayerEvents);
759
+ }
760
+ async detach() {
761
+ for (const e of O)
762
+ this.player.removeEventListener(e, this.handlePlayerEvents);
763
+ }
764
+ async loadVideo(e) {
765
+ this.player.load(e);
766
+ }
767
+ async play() {
768
+ this.player.play();
769
+ }
770
+ async pause() {
771
+ this.player.pause();
772
+ }
773
+ async setCurrentTime(e) {
774
+ this.player.seek(e);
775
+ }
776
+ async setVolume(e) {
777
+ this.player.setVolume(e);
778
+ }
779
+ async setMuted(e) {
780
+ this.player.setMuted(e);
781
+ }
782
+ setPlaybackRate = void 0;
783
+ async getDuration() {
784
+ return this.player.duration;
785
+ }
786
+ async getCurrentTime() {
787
+ return this.player.currentTime;
788
+ }
789
+ async getVolume() {
790
+ return this.player.volume;
791
+ }
792
+ async getMuted() {
793
+ return this.player.muted;
794
+ }
795
+ getPlaybackRate = void 0;
796
+ }
797
+ var N = /* @__PURE__ */ ((a) => (a[a.Play = 2] = "Play", a[a.Pause = 3] = "Pause", a[a.End = 4] = "End", a))(N || {});
798
+ class R extends v {
799
+ static origin = "https://embed.nicovideo.jp";
800
+ duration = 0;
801
+ currentTime = 0;
802
+ volume = 0;
803
+ muted = !1;
804
+ handleMessage = (e) => {
805
+ if (e.origin !== R.origin) return;
806
+ const t = e.data;
807
+ switch (t.eventName) {
808
+ case "playerStatusChange":
809
+ this.logger.log(
810
+ s.Debug,
811
+ `player status changed: ${N[t.data.playerStatus] ?? t.data.playerStatus}`
812
+ );
813
+ break;
814
+ case "statusChange":
815
+ switch (this.logger.log(
816
+ s.Debug,
817
+ `status changed: ${N[t.data.playerStatus] ?? t.data.playerStatus}`
818
+ ), t.data.playerStatus) {
819
+ case 2:
820
+ this.options?.onPlay?.();
821
+ break;
822
+ case 3:
823
+ this.options?.onPause?.();
824
+ break;
825
+ case 4:
826
+ this.options?.onEnded?.();
827
+ break;
828
+ }
829
+ break;
830
+ case "playerMetadataChange":
831
+ t.data.duration !== void 0 && (this.duration = t.data.duration / 1e3), this.currentTime = t.data.currentTime === void 0 ? 0 : t.data.currentTime / 1e3, this.volume = t.data.volume, this.muted = t.data.muted, this.options?.onTimeUpdate?.({
832
+ duration: this.duration,
833
+ percent: this.currentTime !== 0 && this.duration !== 0 ? this.currentTime / this.duration : 0,
834
+ seconds: this.currentTime
835
+ });
836
+ break;
837
+ case "loadComplete":
838
+ this.logger.log(s.Debug, "load completed"), this.duration = t.data.videoInfo.lengthInSeconds, this.options?.onLoaded?.({ id: t.data.videoInfo.watchId });
839
+ break;
840
+ case "error":
841
+ this.options?.onError?.(t);
842
+ break;
843
+ case "player-error:video:play":
844
+ case "player-error:video:seek":
845
+ this.options?.onError?.(t);
846
+ break;
847
+ default:
848
+ this.logger.log(
849
+ s.Debug,
850
+ "message",
851
+ t.eventName,
852
+ t.data
853
+ );
854
+ break;
855
+ }
856
+ };
857
+ async attach() {
858
+ window.addEventListener("message", this.handleMessage);
859
+ }
860
+ async detach() {
861
+ window.removeEventListener("message", this.handleMessage);
862
+ }
863
+ async loadVideo(e) {
864
+ return new Promise((t, r) => {
865
+ this.duration = 0, this.currentTime = 0, this.volume = 0, this.muted = !1, this.player.onload = () => {
866
+ this.player.onload = null, t();
867
+ }, this.player.src = `https://embed.nicovideo.jp/watch/${e}?jsapi=1&playerId=1`;
868
+ });
869
+ }
870
+ // https://blog.hayu.io/web/create/nicovideo-embed-player-api/.
871
+ postMessage(e) {
872
+ this.player.contentWindow?.postMessage(
873
+ {
874
+ ...e,
875
+ playerId: "1",
876
+ sourceConnectorType: 1
877
+ },
878
+ R.origin
879
+ );
880
+ }
881
+ async play() {
882
+ this.postMessage({ eventName: "play" });
883
+ }
884
+ async pause() {
885
+ this.postMessage({ eventName: "pause" });
886
+ }
887
+ async setCurrentTime(e) {
888
+ this.postMessage({ eventName: "seek", data: { time: e * 1e3 } });
889
+ }
890
+ async setVolume(e) {
891
+ this.postMessage({
892
+ eventName: "volumeChange",
893
+ data: { volume: e }
894
+ });
895
+ }
896
+ async setMuted(e) {
897
+ this.postMessage({
898
+ eventName: "mute",
899
+ data: { mute: e }
900
+ });
901
+ }
902
+ setPlaybackRate = void 0;
903
+ async getDuration() {
904
+ return this.duration;
905
+ }
906
+ async getCurrentTime() {
907
+ return this.currentTime;
908
+ }
909
+ async getVolume() {
910
+ return this.volume;
911
+ }
912
+ async getMuted() {
913
+ return this.muted;
914
+ }
915
+ getPlaybackRate = void 0;
916
+ }
917
+ class L extends v {
918
+ getDurationCore() {
919
+ return new Promise((e, t) => {
920
+ this.player.getDuration(e);
921
+ });
922
+ }
923
+ attach(e) {
924
+ return new Promise((t, r) => {
925
+ this.player.bind(SC.Widget.Events.READY, () => {
926
+ this.player.bind(
927
+ SC.Widget.Events.PLAY_PROGRESS,
928
+ async (i) => {
929
+ const n = await this.getDurationCore();
930
+ this.options?.onTimeUpdate?.({
931
+ duration: n / 1e3,
932
+ percent: i.currentPosition / n,
933
+ seconds: i.currentPosition / 1e3
934
+ });
935
+ }
936
+ ), this.player.bind(
937
+ SC.Widget.Events.ERROR,
938
+ (i) => this.options?.onError?.(i)
939
+ ), this.player.bind(
940
+ SC.Widget.Events.PLAY,
941
+ () => this.options?.onPlay?.()
942
+ ), this.player.bind(
943
+ SC.Widget.Events.PAUSE,
944
+ () => this.options?.onPause?.()
945
+ ), this.player.bind(
946
+ SC.Widget.Events.FINISH,
947
+ () => this.options?.onEnded?.()
948
+ ), this.options?.onLoaded?.({ id: e }), t();
949
+ });
950
+ });
951
+ }
952
+ async detach() {
953
+ this.player.unbind(SC.Widget.Events.READY), this.player.unbind(SC.Widget.Events.PLAY_PROGRESS), this.player.unbind(SC.Widget.Events.ERROR), this.player.unbind(SC.Widget.Events.PLAY), this.player.unbind(SC.Widget.Events.PAUSE), this.player.unbind(SC.Widget.Events.FINISH);
954
+ }
955
+ static playerLoadAsync(e, t, r) {
956
+ return new Promise((i, n) => {
957
+ e.load(t, { ...r, callback: i });
958
+ });
959
+ }
960
+ async loadVideo(e) {
961
+ await L.playerLoadAsync(this.player, e, {
962
+ auto_play: !0
963
+ }), this.options?.onLoaded?.({ id: e });
964
+ }
965
+ async play() {
966
+ this.player.play();
967
+ }
968
+ async pause() {
969
+ this.player.pause();
970
+ }
971
+ async setCurrentTime(e) {
972
+ this.player.seekTo(e * 1e3);
973
+ }
974
+ async setVolume(e) {
975
+ this.player.setVolume(e * 100);
976
+ }
977
+ setMuted = void 0;
978
+ setPlaybackRate = void 0;
979
+ async getDuration() {
980
+ return await this.getDurationCore() / 1e3;
981
+ }
982
+ getCurrentTimeCore() {
983
+ return new Promise((e, t) => {
984
+ this.player.getPosition(e);
985
+ });
986
+ }
987
+ async getCurrentTime() {
988
+ return await this.getCurrentTimeCore() / 1e3;
989
+ }
990
+ getVolumeCore() {
991
+ return new Promise((e, t) => {
992
+ this.player.getVolume(e);
993
+ });
994
+ }
995
+ async getVolume() {
996
+ return await this.getVolumeCore() / 100;
997
+ }
998
+ getMuted = void 0;
999
+ getPlaybackRate = void 0;
1000
+ }
1001
+ class fe extends v {
1002
+ handleReady = () => {
1003
+ this.options?.onLoaded?.({ id: this.player.getVideo() });
1004
+ };
1005
+ handlePlay = () => {
1006
+ this.options?.onPlay?.();
1007
+ };
1008
+ handlePause = () => {
1009
+ this.options?.onPause?.();
1010
+ };
1011
+ handleEnded = () => {
1012
+ this.options?.onEnded?.();
1013
+ };
1014
+ handleSeek = () => {
1015
+ this.options?.onTimeUpdate?.({
1016
+ duration: 0,
1017
+ percent: 0,
1018
+ seconds: 0
1019
+ });
1020
+ };
1021
+ async attach(e) {
1022
+ this.player.addEventListener(Twitch.Player.READY, this.handleReady), this.player.addEventListener(Twitch.Player.PLAYING, this.handlePlay), this.player.addEventListener(Twitch.Player.PAUSE, this.handlePause), this.player.addEventListener(Twitch.Player.ENDED, this.handleEnded), this.player.addEventListener(Twitch.Player.SEEK, this.handleSeek);
1023
+ }
1024
+ async detach() {
1025
+ }
1026
+ async loadVideo(e) {
1027
+ this.player.setVideo(e, 0);
1028
+ }
1029
+ async play() {
1030
+ this.player.play();
1031
+ }
1032
+ async pause() {
1033
+ this.player.pause();
1034
+ }
1035
+ async setCurrentTime(e) {
1036
+ this.player.seek(e);
1037
+ }
1038
+ async setVolume(e) {
1039
+ this.player.setVolume(e);
1040
+ }
1041
+ async setMuted(e) {
1042
+ this.player.setMuted(e);
1043
+ }
1044
+ setPlaybackRate = void 0;
1045
+ async getDuration() {
1046
+ return this.player.getDuration();
1047
+ }
1048
+ async getCurrentTime() {
1049
+ return this.player.getCurrentTime();
1050
+ }
1051
+ async getVolume() {
1052
+ return this.player.getVolume();
1053
+ }
1054
+ async getMuted() {
1055
+ return this.player.getMuted();
1056
+ }
1057
+ getPlaybackRate = void 0;
1058
+ }
1059
+ class ke extends v {
1060
+ async attach() {
1061
+ await this.player.ready(), this.player.on("error", (e) => this.options?.onError?.(e)), this.player.on(
1062
+ "loaded",
1063
+ (e) => this.options?.onLoaded?.({ id: e.id.toString() })
1064
+ ), this.player.on("play", () => this.options?.onPlay?.()), this.player.on("pause", () => this.options?.onPause?.()), this.player.on("ended", () => this.options?.onEnded?.()), this.player.on("timeupdate", (e) => {
1065
+ this.options?.onTimeUpdate?.({
1066
+ duration: e.duration,
1067
+ percent: e.percent,
1068
+ seconds: e.seconds
1069
+ });
1070
+ });
1071
+ }
1072
+ async detach() {
1073
+ this.player.off("error"), this.player.off("loaded"), this.player.off("play"), this.player.off("pause"), this.player.off("ended"), this.player.off("timeupdate");
1074
+ }
1075
+ async loadVideo(e) {
1076
+ await this.player.loadVideo(e);
1077
+ }
1078
+ async play() {
1079
+ await this.player.play();
1080
+ }
1081
+ async pause() {
1082
+ await this.player.pause();
1083
+ }
1084
+ async setCurrentTime(e) {
1085
+ await this.player.setCurrentTime(e);
1086
+ }
1087
+ async setVolume(e) {
1088
+ await this.player.setVolume(e);
1089
+ }
1090
+ async setMuted(e) {
1091
+ await this.player.setMuted(e);
1092
+ }
1093
+ async setPlaybackRate(e) {
1094
+ await this.player.setPlaybackRate(e);
1095
+ }
1096
+ async getDuration() {
1097
+ return this.player.getDuration();
1098
+ }
1099
+ async getCurrentTime() {
1100
+ return this.player.getCurrentTime();
1101
+ }
1102
+ async getVolume() {
1103
+ return this.player.getVolume();
1104
+ }
1105
+ async getMuted() {
1106
+ return await this.player.getMuted();
1107
+ }
1108
+ async getPlaybackRate() {
1109
+ return this.player.getPlaybackRate();
1110
+ }
1111
+ }
1112
+ var j = /* @__PURE__ */ ((a) => (a[a.UNSTARTED = -1] = "UNSTARTED", a[a.ENDED = 0] = "ENDED", a[a.PLAYING = 1] = "PLAYING", a[a.PAUSED = 2] = "PAUSED", a[a.BUFFERING = 3] = "BUFFERING", a[a.CUED = 5] = "CUED", a))(j || {});
1113
+ class Ne extends v {
1114
+ previousTime;
1115
+ timeUpdateIntervalId;
1116
+ clearTimeUpdateInterval() {
1117
+ this.logger.log(
1118
+ s.Debug,
1119
+ "clearTimeUpdateInterval",
1120
+ this.timeUpdateIntervalId
1121
+ ), window.clearInterval(this.timeUpdateIntervalId), this.timeUpdateIntervalId = void 0;
1122
+ }
1123
+ invokeTimeUpdate(e) {
1124
+ const t = e.getCurrentTime();
1125
+ if (t === this.previousTime) return;
1126
+ const r = e.getDuration();
1127
+ this.options?.onTimeUpdate?.({
1128
+ duration: r,
1129
+ percent: t / r,
1130
+ seconds: t
1131
+ }), this.previousTime = t;
1132
+ }
1133
+ setTimeUpdateInterval() {
1134
+ this.logger.log(s.Debug, "setTimeUpdateInterval"), this.clearTimeUpdateInterval(), this.timeUpdateIntervalId = window.setInterval(
1135
+ () => this.invokeTimeUpdate(this.player),
1136
+ 250
1137
+ ), this.logger.log(
1138
+ s.Debug,
1139
+ "timeUpdateIntervalId",
1140
+ this.timeUpdateIntervalId
1141
+ ), this.invokeTimeUpdate(this.player);
1142
+ }
1143
+ attach(e) {
1144
+ return new Promise((t, r) => {
1145
+ this.player.addEventListener("onReady", async () => {
1146
+ this.player.addEventListener(
1147
+ "onError",
1148
+ (i) => this.options?.onError?.(i.data)
1149
+ ), this.player.addEventListener(
1150
+ "onStateChange",
1151
+ (i) => {
1152
+ switch (this.logger.log(
1153
+ s.Debug,
1154
+ `state changed: ${j[i.data]}`
1155
+ ), i.data) {
1156
+ case YT.PlayerState.CUED:
1157
+ this.options?.onLoaded?.({ id: e });
1158
+ break;
1159
+ case YT.PlayerState.PLAYING:
1160
+ this.options?.onPlay?.(), this.setTimeUpdateInterval();
1161
+ break;
1162
+ case YT.PlayerState.PAUSED:
1163
+ this.options?.onPause?.(), this.clearTimeUpdateInterval();
1164
+ break;
1165
+ case YT.PlayerState.ENDED:
1166
+ this.options?.onEnded?.(), this.clearTimeUpdateInterval();
1167
+ break;
1168
+ }
1169
+ }
1170
+ ), await this.loadVideo(e), t();
1171
+ });
1172
+ });
1173
+ }
1174
+ async detach() {
1175
+ this.clearTimeUpdateInterval();
1176
+ }
1177
+ async loadVideo(e) {
1178
+ this.previousTime = void 0, this.player.cueVideoById(e);
1179
+ }
1180
+ async play() {
1181
+ this.player.playVideo();
1182
+ }
1183
+ async pause() {
1184
+ this.player.pauseVideo();
1185
+ }
1186
+ async setCurrentTime(e) {
1187
+ this.player.seekTo(e), this.invokeTimeUpdate(this.player);
1188
+ }
1189
+ async setVolume(e) {
1190
+ this.player.setVolume(e * 100);
1191
+ }
1192
+ async setMuted(e) {
1193
+ e ? this.player.mute() : this.player.unMute();
1194
+ }
1195
+ async setPlaybackRate(e) {
1196
+ this.player.setPlaybackRate(e);
1197
+ }
1198
+ async getDuration() {
1199
+ return this.player.getDuration();
1200
+ }
1201
+ async getCurrentTime() {
1202
+ return this.player.getCurrentTime();
1203
+ }
1204
+ async getVolume() {
1205
+ return this.player.getVolume() / 100;
1206
+ }
1207
+ async getMuted() {
1208
+ return this.player.isMuted();
1209
+ }
1210
+ async getPlaybackRate() {
1211
+ return this.player.getPlaybackRate();
1212
+ }
279
1213
  }
280
- //#endregion
281
- //#region src/controllers/AudioPlayerController.ts
282
- var U = class extends i {
283
- async attach() {
284
- this.player.onerror = (e) => this.options?.onError?.(e), this.player.onloadeddata = () => this.options?.onLoaded?.({ id: this.player.src }), this.player.onplay = () => this.options?.onPlay?.(), this.player.onpause = () => this.options?.onPause?.(), this.player.onended = () => this.options?.onEnded?.(), this.player.ontimeupdate = () => {
285
- this.options?.onTimeUpdate?.({
286
- duration: this.player.duration,
287
- percent: this.player.currentTime / this.player.duration,
288
- seconds: this.player.currentTime
289
- });
290
- };
291
- }
292
- async detach() {
293
- this.player.onerror = null, this.player.onloadeddata = null, this.player.onplay = null, this.player.onpause = null, this.player.onended = null, this.player.ontimeupdate = null;
294
- }
295
- async loadVideo(e) {
296
- this.player.src = e;
297
- }
298
- async play() {
299
- await this.player.play();
300
- }
301
- async pause() {
302
- this.player.pause();
303
- }
304
- async setCurrentTime(e) {
305
- this.player.currentTime = e;
306
- }
307
- async setVolume(e) {
308
- this.player.volume = e;
309
- }
310
- async setMuted(e) {
311
- this.player.muted = e;
312
- }
313
- async setPlaybackRate(e) {
314
- this.player.playbackRate = e;
315
- }
316
- async getDuration() {
317
- return this.player.duration;
318
- }
319
- async getCurrentTime() {
320
- return this.player.currentTime;
321
- }
322
- async getVolume() {
323
- return this.player.volume;
324
- }
325
- async getMuted() {
326
- return this.player.muted;
327
- }
328
- async getPlaybackRate() {
329
- return this.player.playbackRate;
330
- }
331
- }, W = [
332
- "apiready",
333
- "seeked",
334
- "video_end",
335
- "durationchange",
336
- "pause",
337
- "playing",
338
- "error"
339
- ], G = class extends i {
340
- handlePlayerEvents = (e) => {
341
- switch (e.type) {
342
- case "apiready":
343
- this.options?.onLoaded?.({ id: this.player.video.videoId });
344
- break;
345
- case "seeked":
346
- this.options?.onTimeUpdate?.({
347
- duration: this.player.duration,
348
- percent: this.player.currentTime / this.player.duration,
349
- seconds: this.player.currentTime
350
- });
351
- break;
352
- case "video_end":
353
- this.options?.onEnded?.();
354
- break;
355
- case "durationchange": break;
356
- case "pause":
357
- this.options?.onPause?.();
358
- break;
359
- case "playing":
360
- this.options?.onPlay?.();
361
- break;
362
- case "error":
363
- this.options?.onError?.(e);
364
- break;
365
- }
366
- };
367
- async attach(e) {
368
- for (let e of W) this.player.addEventListener(e, this.handlePlayerEvents);
369
- }
370
- async detach() {
371
- for (let e of W) this.player.removeEventListener(e, this.handlePlayerEvents);
372
- }
373
- async loadVideo(e) {
374
- this.player.load(e);
375
- }
376
- async play() {
377
- this.player.play();
378
- }
379
- async pause() {
380
- this.player.pause();
381
- }
382
- async setCurrentTime(e) {
383
- this.player.seek(e);
384
- }
385
- async setVolume(e) {
386
- this.player.setVolume(e);
387
- }
388
- async setMuted(e) {
389
- this.player.setMuted(e);
390
- }
391
- setPlaybackRate = void 0;
392
- async getDuration() {
393
- return this.player.duration;
394
- }
395
- async getCurrentTime() {
396
- return this.player.currentTime;
397
- }
398
- async getVolume() {
399
- return this.player.volume;
400
- }
401
- async getMuted() {
402
- return this.player.muted;
403
- }
404
- getPlaybackRate = void 0;
405
- }, K = /* @__PURE__ */ function(e) {
406
- return e[e.Play = 2] = "Play", e[e.Pause = 3] = "Pause", e[e.End = 4] = "End", e;
407
- }(K || {}), q = class e extends i {
408
- static origin = "https://embed.nicovideo.jp";
409
- duration = 0;
410
- currentTime = 0;
411
- volume = 0;
412
- muted = !1;
413
- handleMessage = (t) => {
414
- if (t.origin !== e.origin) return;
415
- let n = t.data;
416
- switch (n.eventName) {
417
- case "playerStatusChange":
418
- this.logger.log(r.Debug, `player status changed: ${K[n.data.playerStatus] ?? n.data.playerStatus}`);
419
- break;
420
- case "statusChange":
421
- switch (this.logger.log(r.Debug, `status changed: ${K[n.data.playerStatus] ?? n.data.playerStatus}`), n.data.playerStatus) {
422
- case K.Play:
423
- this.options?.onPlay?.();
424
- break;
425
- case K.Pause:
426
- this.options?.onPause?.();
427
- break;
428
- case K.End:
429
- this.options?.onEnded?.();
430
- break;
431
- }
432
- break;
433
- case "playerMetadataChange":
434
- n.data.duration !== void 0 && (this.duration = n.data.duration / 1e3), this.currentTime = n.data.currentTime === void 0 ? 0 : n.data.currentTime / 1e3, this.volume = n.data.volume, this.muted = n.data.muted, this.options?.onTimeUpdate?.({
435
- duration: this.duration,
436
- percent: this.currentTime !== 0 && this.duration !== 0 ? this.currentTime / this.duration : 0,
437
- seconds: this.currentTime
438
- });
439
- break;
440
- case "loadComplete":
441
- this.logger.log(r.Debug, "load completed"), this.duration = n.data.videoInfo.lengthInSeconds, this.options?.onLoaded?.({ id: n.data.videoInfo.watchId });
442
- break;
443
- case "error":
444
- this.options?.onError?.(n);
445
- break;
446
- case "player-error:video:play":
447
- case "player-error:video:seek":
448
- this.options?.onError?.(n);
449
- break;
450
- default:
451
- this.logger.log(r.Debug, "message", n.eventName, n.data);
452
- break;
453
- }
454
- };
455
- async attach() {
456
- window.addEventListener("message", this.handleMessage);
457
- }
458
- async detach() {
459
- window.removeEventListener("message", this.handleMessage);
460
- }
461
- async loadVideo(e) {
462
- return new Promise((t, n) => {
463
- this.duration = 0, this.currentTime = 0, this.volume = 0, this.muted = !1, this.player.onload = () => {
464
- this.player.onload = null, t();
465
- }, this.player.src = `https://embed.nicovideo.jp/watch/${e}?jsapi=1&playerId=1`;
466
- });
467
- }
468
- postMessage(t) {
469
- this.player.contentWindow?.postMessage({
470
- ...t,
471
- playerId: "1",
472
- sourceConnectorType: 1
473
- }, e.origin);
474
- }
475
- async play() {
476
- this.postMessage({ eventName: "play" });
477
- }
478
- async pause() {
479
- this.postMessage({ eventName: "pause" });
480
- }
481
- async setCurrentTime(e) {
482
- this.postMessage({
483
- eventName: "seek",
484
- data: { time: e * 1e3 }
485
- });
486
- }
487
- async setVolume(e) {
488
- this.postMessage({
489
- eventName: "volumeChange",
490
- data: { volume: e }
491
- });
492
- }
493
- async setMuted(e) {
494
- this.postMessage({
495
- eventName: "mute",
496
- data: { mute: e }
497
- });
498
- }
499
- setPlaybackRate = void 0;
500
- async getDuration() {
501
- return this.duration;
502
- }
503
- async getCurrentTime() {
504
- return this.currentTime;
505
- }
506
- async getVolume() {
507
- return this.volume;
508
- }
509
- async getMuted() {
510
- return this.muted;
511
- }
512
- getPlaybackRate = void 0;
513
- }, J = class e extends i {
514
- getDurationCore() {
515
- return new Promise((e, t) => {
516
- this.player.getDuration(e);
517
- });
518
- }
519
- attach(e) {
520
- return new Promise((t, n) => {
521
- this.player.bind(SC.Widget.Events.READY, () => {
522
- this.player.bind(SC.Widget.Events.PLAY_PROGRESS, async (e) => {
523
- let t = await this.getDurationCore();
524
- this.options?.onTimeUpdate?.({
525
- duration: t / 1e3,
526
- percent: e.currentPosition / t,
527
- seconds: e.currentPosition / 1e3
528
- });
529
- }), this.player.bind(SC.Widget.Events.ERROR, (e) => this.options?.onError?.(e)), this.player.bind(SC.Widget.Events.PLAY, () => this.options?.onPlay?.()), this.player.bind(SC.Widget.Events.PAUSE, () => this.options?.onPause?.()), this.player.bind(SC.Widget.Events.FINISH, () => this.options?.onEnded?.()), this.options?.onLoaded?.({ id: e }), t();
530
- });
531
- });
532
- }
533
- async detach() {
534
- this.player.unbind(SC.Widget.Events.READY), this.player.unbind(SC.Widget.Events.PLAY_PROGRESS), this.player.unbind(SC.Widget.Events.ERROR), this.player.unbind(SC.Widget.Events.PLAY), this.player.unbind(SC.Widget.Events.PAUSE), this.player.unbind(SC.Widget.Events.FINISH);
535
- }
536
- static playerLoadAsync(e, t, n) {
537
- return new Promise((r, i) => {
538
- e.load(t, {
539
- ...n,
540
- callback: r
541
- });
542
- });
543
- }
544
- async loadVideo(t) {
545
- await e.playerLoadAsync(this.player, t, { auto_play: !0 }), this.options?.onLoaded?.({ id: t });
546
- }
547
- async play() {
548
- this.player.play();
549
- }
550
- async pause() {
551
- this.player.pause();
552
- }
553
- async setCurrentTime(e) {
554
- this.player.seekTo(e * 1e3);
555
- }
556
- async setVolume(e) {
557
- this.player.setVolume(e * 100);
558
- }
559
- setMuted = void 0;
560
- setPlaybackRate = void 0;
561
- async getDuration() {
562
- return await this.getDurationCore() / 1e3;
563
- }
564
- getCurrentTimeCore() {
565
- return new Promise((e, t) => {
566
- this.player.getPosition(e);
567
- });
568
- }
569
- async getCurrentTime() {
570
- return await this.getCurrentTimeCore() / 1e3;
571
- }
572
- getVolumeCore() {
573
- return new Promise((e, t) => {
574
- this.player.getVolume(e);
575
- });
576
- }
577
- async getVolume() {
578
- return await this.getVolumeCore() / 100;
579
- }
580
- getMuted = void 0;
581
- getPlaybackRate = void 0;
582
- }, Y = class extends i {
583
- handleReady = () => {
584
- this.options?.onLoaded?.({ id: this.player.getVideo() });
585
- };
586
- handlePlay = () => {
587
- this.options?.onPlay?.();
588
- };
589
- handlePause = () => {
590
- this.options?.onPause?.();
591
- };
592
- handleEnded = () => {
593
- this.options?.onEnded?.();
594
- };
595
- handleSeek = () => {
596
- this.options?.onTimeUpdate?.({
597
- duration: 0,
598
- percent: 0,
599
- seconds: 0
600
- });
601
- };
602
- async attach(e) {
603
- this.player.addEventListener(Twitch.Player.READY, this.handleReady), this.player.addEventListener(Twitch.Player.PLAYING, this.handlePlay), this.player.addEventListener(Twitch.Player.PAUSE, this.handlePause), this.player.addEventListener(Twitch.Player.ENDED, this.handleEnded), this.player.addEventListener(Twitch.Player.SEEK, this.handleSeek);
604
- }
605
- async detach() {}
606
- async loadVideo(e) {
607
- this.player.setVideo(e, 0);
608
- }
609
- async play() {
610
- this.player.play();
611
- }
612
- async pause() {
613
- this.player.pause();
614
- }
615
- async setCurrentTime(e) {
616
- this.player.seek(e);
617
- }
618
- async setVolume(e) {
619
- this.player.setVolume(e);
620
- }
621
- async setMuted(e) {
622
- this.player.setMuted(e);
623
- }
624
- setPlaybackRate = void 0;
625
- async getDuration() {
626
- return this.player.getDuration();
627
- }
628
- async getCurrentTime() {
629
- return this.player.getCurrentTime();
630
- }
631
- async getVolume() {
632
- return this.player.getVolume();
633
- }
634
- async getMuted() {
635
- return this.player.getMuted();
636
- }
637
- getPlaybackRate = void 0;
638
- }, X = class extends i {
639
- async attach() {
640
- await this.player.ready(), this.player.on("error", (e) => this.options?.onError?.(e)), this.player.on("loaded", (e) => this.options?.onLoaded?.({ id: e.id.toString() })), this.player.on("play", () => this.options?.onPlay?.()), this.player.on("pause", () => this.options?.onPause?.()), this.player.on("ended", () => this.options?.onEnded?.()), this.player.on("timeupdate", (e) => {
641
- this.options?.onTimeUpdate?.({
642
- duration: e.duration,
643
- percent: e.percent,
644
- seconds: e.seconds
645
- });
646
- });
647
- }
648
- async detach() {
649
- this.player.off("error"), this.player.off("loaded"), this.player.off("play"), this.player.off("pause"), this.player.off("ended"), this.player.off("timeupdate");
650
- }
651
- async loadVideo(e) {
652
- await this.player.loadVideo(e);
653
- }
654
- async play() {
655
- await this.player.play();
656
- }
657
- async pause() {
658
- await this.player.pause();
659
- }
660
- async setCurrentTime(e) {
661
- await this.player.setCurrentTime(e);
662
- }
663
- async setVolume(e) {
664
- await this.player.setVolume(e);
665
- }
666
- async setMuted(e) {
667
- await this.player.setMuted(e);
668
- }
669
- async setPlaybackRate(e) {
670
- await this.player.setPlaybackRate(e);
671
- }
672
- async getDuration() {
673
- return this.player.getDuration();
674
- }
675
- async getCurrentTime() {
676
- return this.player.getCurrentTime();
677
- }
678
- async getVolume() {
679
- return this.player.getVolume();
680
- }
681
- async getMuted() {
682
- return await this.player.getMuted();
683
- }
684
- async getPlaybackRate() {
685
- return this.player.getPlaybackRate();
686
- }
687
- }, Z = /* @__PURE__ */ function(e) {
688
- return e[e.UNSTARTED = -1] = "UNSTARTED", e[e.ENDED = 0] = "ENDED", e[e.PLAYING = 1] = "PLAYING", e[e.PAUSED = 2] = "PAUSED", e[e.BUFFERING = 3] = "BUFFERING", e[e.CUED = 5] = "CUED", e;
689
- }(Z || {}), Q = class extends i {
690
- previousTime;
691
- timeUpdateIntervalId;
692
- clearTimeUpdateInterval() {
693
- this.logger.log(r.Debug, "clearTimeUpdateInterval", this.timeUpdateIntervalId), window.clearInterval(this.timeUpdateIntervalId), this.timeUpdateIntervalId = void 0;
694
- }
695
- invokeTimeUpdate(e) {
696
- let t = e.getCurrentTime();
697
- if (t === this.previousTime) return;
698
- let n = e.getDuration();
699
- this.options?.onTimeUpdate?.({
700
- duration: n,
701
- percent: t / n,
702
- seconds: t
703
- }), this.previousTime = t;
704
- }
705
- setTimeUpdateInterval() {
706
- this.logger.log(r.Debug, "setTimeUpdateInterval"), this.clearTimeUpdateInterval(), this.timeUpdateIntervalId = window.setInterval(() => this.invokeTimeUpdate(this.player), 250), this.logger.log(r.Debug, "timeUpdateIntervalId", this.timeUpdateIntervalId), this.invokeTimeUpdate(this.player);
707
- }
708
- attach(e) {
709
- return new Promise((t, n) => {
710
- this.player.addEventListener("onReady", async () => {
711
- this.player.addEventListener("onError", (e) => this.options?.onError?.(e.data)), this.player.addEventListener("onStateChange", (t) => {
712
- switch (this.logger.log(r.Debug, `state changed: ${Z[t.data]}`), t.data) {
713
- case YT.PlayerState.CUED:
714
- this.options?.onLoaded?.({ id: e });
715
- break;
716
- case YT.PlayerState.PLAYING:
717
- this.options?.onPlay?.(), this.setTimeUpdateInterval();
718
- break;
719
- case YT.PlayerState.PAUSED:
720
- this.options?.onPause?.(), this.clearTimeUpdateInterval();
721
- break;
722
- case YT.PlayerState.ENDED:
723
- this.options?.onEnded?.(), this.clearTimeUpdateInterval();
724
- break;
725
- }
726
- }), await this.loadVideo(e), t();
727
- });
728
- });
729
- }
730
- async detach() {
731
- this.clearTimeUpdateInterval();
732
- }
733
- async loadVideo(e) {
734
- this.previousTime = void 0, this.player.cueVideoById(e);
735
- }
736
- async play() {
737
- this.player.playVideo();
738
- }
739
- async pause() {
740
- this.player.pauseVideo();
741
- }
742
- async setCurrentTime(e) {
743
- this.player.seekTo(e), this.invokeTimeUpdate(this.player);
744
- }
745
- async setVolume(e) {
746
- this.player.setVolume(e * 100);
747
- }
748
- async setMuted(e) {
749
- e ? this.player.mute() : this.player.unMute();
750
- }
751
- async setPlaybackRate(e) {
752
- this.player.setPlaybackRate(e);
753
- }
754
- async getDuration() {
755
- return this.player.getDuration();
756
- }
757
- async getCurrentTime() {
758
- return this.player.getCurrentTime();
759
- }
760
- async getVolume() {
761
- return this.player.getVolume() / 100;
762
- }
763
- async getMuted() {
764
- return this.player.isMuted();
765
- }
766
- async getPlaybackRate() {
767
- return this.player.getPlaybackRate();
768
- }
1214
+ export {
1215
+ De as AudioPlayerController,
1216
+ Ve as DailymotionPlayerController,
1217
+ s as LogLevel,
1218
+ R as NiconicoPlayerController,
1219
+ ye as NostalgicDiva,
1220
+ me as NostalgicDivaElement,
1221
+ J as NostalgicDivaProvider,
1222
+ Te as PlayerContainer,
1223
+ M as PlayerController,
1224
+ v as PlayerControllerImpl,
1225
+ L as SoundCloudPlayerController,
1226
+ fe as TwitchPlayerController,
1227
+ g as VideoService,
1228
+ ke as VimeoPlayerController,
1229
+ Ne as YouTubePlayerController,
1230
+ K as defaultLogger,
1231
+ Pe as defineNostalgicDiva,
1232
+ ue as findVideoService,
1233
+ f as nullPlayerController,
1234
+ he as players,
1235
+ Q as useNostalgicDiva,
1236
+ de as videoServices
769
1237
  };
770
- //#endregion
771
- export { U as AudioPlayerController, G as DailymotionPlayerController, r as LogLevel, q as NiconicoPlayerController, B as NostalgicDiva, V as NostalgicDivaElement, v as NostalgicDivaProvider, o as PlayerContainer, n as PlayerController, i as PlayerControllerImpl, J as SoundCloudPlayerController, Y as TwitchPlayerController, b as VideoService, X as VimeoPlayerController, Q as YouTubePlayerController, a as defaultLogger, H as defineNostalgicDiva, I as findVideoService, e as nullPlayerController, L as players, y as useNostalgicDiva, F as videoServices };
772
-
773
- //# sourceMappingURL=index.es.js.map
1238
+ //# sourceMappingURL=index.es.js.map