@aigamo/nostalgic-diva 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,23 +1,23 @@
1
1
  var W = Object.defineProperty;
2
- var Y = (a, r, e) => r in a ? W(a, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[r] = e;
3
- var m = (a, r, e) => (Y(a, typeof r != "symbol" ? r + "" : r, e), e);
4
- import i, { useRef as A } from "react";
5
- var u = /* @__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))(u || {});
2
+ var Y = (r, a, e) => a in r ? W(r, a, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[a] = e;
3
+ var y = (r, a, e) => (Y(r, typeof a != "symbol" ? a + "" : a, e), e);
4
+ import s, { useRef as V } from "react";
5
+ var d = /* @__PURE__ */ ((r) => (r[r.Trace = 0] = "Trace", r[r.Debug = 1] = "Debug", r[r.Information = 2] = "Information", r[r.Warning = 3] = "Warning", r[r.Error = 4] = "Error", r[r.Critical = 5] = "Critical", r[r.None = 6] = "None", r))(d || {});
6
6
  class E {
7
- constructor(r, e, t) {
8
- this.logger = r, this.playerElementRef = e, this.options = t, this.logger.log(u.Debug, "ctor");
7
+ constructor(a, e, t) {
8
+ this.logger = a, this.playerElementRef = e, this.options = t, this.logger.log(d.Debug, "ctor");
9
9
  }
10
10
  }
11
11
  class j extends E {
12
- constructor(e, t, s) {
13
- super(e, t, s);
14
- m(this, "player");
12
+ constructor(e, t, i) {
13
+ super(e, t, i);
14
+ y(this, "player");
15
15
  this.player = t.current;
16
16
  }
17
17
  async attach() {
18
18
  this.player.onerror = (e) => {
19
- var t, s;
20
- return (s = (t = this.options) == null ? void 0 : t.onError) == null ? void 0 : s.call(t, e);
19
+ var t, i;
20
+ return (i = (t = this.options) == null ? void 0 : t.onError) == null ? void 0 : i.call(t, e);
21
21
  }, this.player.onloadeddata = () => {
22
22
  var e, t;
23
23
  return (t = (e = this.options) == null ? void 0 : e.onLoaded) == null ? void 0 : t.call(e, { id: this.player.src });
@@ -66,33 +66,36 @@ class j extends E {
66
66
  async getCurrentTime() {
67
67
  return this.player.currentTime;
68
68
  }
69
+ async getVolume() {
70
+ return this.player.volume;
71
+ }
69
72
  }
70
- const U = class {
71
- constructor(r, e, t, s, c, d) {
72
- m(this, "id");
73
- m(this, "impl");
74
- this.logger = r, this.type = e, this.playerElementRef = t, this.options = s, this.loadScript = c, this.playerApiFactory = d, this.id = U.nextId++;
73
+ const S = class {
74
+ constructor(a, e, t, i, c, u) {
75
+ y(this, "id");
76
+ y(this, "impl");
77
+ this.logger = a, this.type = e, this.playerElementRef = t, this.options = i, this.loadScript = c, this.playerApiFactory = u, this.id = S.nextId++;
75
78
  }
76
- createMessage(r) {
77
- return `${this.type}#${this.id} ${r}`;
79
+ createMessage(a) {
80
+ return `${this.type}#${this.id} ${a}`;
78
81
  }
79
- debug(r, ...e) {
82
+ debug(a, ...e) {
80
83
  this.logger.log(
81
- u.Debug,
82
- this.createMessage(r),
84
+ d.Debug,
85
+ this.createMessage(a),
83
86
  ...e
84
87
  );
85
88
  }
86
- error(r, ...e) {
89
+ error(a, ...e) {
87
90
  this.logger.log(
88
- u.Error,
89
- this.createMessage(r),
91
+ d.Error,
92
+ this.createMessage(a),
90
93
  ...e
91
94
  );
92
95
  }
93
- async attach(r) {
96
+ async attach(a) {
94
97
  var e;
95
- if (this.debug("attach", r), this.impl) {
98
+ if (this.debug("attach", a), this.impl) {
96
99
  this.debug("player is already attached");
97
100
  return;
98
101
  }
@@ -100,7 +103,7 @@ const U = class {
100
103
  this.logger,
101
104
  this.playerElementRef,
102
105
  this.options
103
- ), await this.impl.attach(r), this.debug("player attached");
106
+ ), await this.impl.attach(a), this.debug("player attached");
104
107
  }
105
108
  createPlayerNotAttachedError() {
106
109
  return new Error("player is not attached");
@@ -110,10 +113,10 @@ const U = class {
110
113
  throw this.createPlayerNotAttachedError();
111
114
  await this.impl.detach(), this.impl = void 0;
112
115
  }
113
- async loadVideo(r) {
114
- if (this.debug("loadVideo", r), this.impl === void 0)
116
+ async loadVideo(a) {
117
+ if (this.debug("loadVideo", a), this.impl === void 0)
115
118
  throw this.createPlayerNotAttachedError();
116
- this.debug("Loading video..."), await this.impl.loadVideo(r), this.debug("video loaded", r);
119
+ this.debug("Loading video..."), await this.impl.loadVideo(a), this.debug("video loaded", a);
117
120
  }
118
121
  play() {
119
122
  if (this.debug("play"), this.impl === void 0)
@@ -125,20 +128,20 @@ const U = class {
125
128
  throw this.createPlayerNotAttachedError();
126
129
  return this.impl.pause();
127
130
  }
128
- setCurrentTime(r) {
129
- if (this.debug("setCurrentTime", r), this.impl === void 0)
131
+ setCurrentTime(a) {
132
+ if (this.debug("setCurrentTime", a), this.impl === void 0)
130
133
  throw this.createPlayerNotAttachedError();
131
- return this.impl.setCurrentTime(r);
134
+ return this.impl.setCurrentTime(a);
132
135
  }
133
- setVolume(r) {
134
- if (this.debug("setVolume", r), this.impl === void 0)
136
+ setVolume(a) {
137
+ if (this.debug("setVolume", a), this.impl === void 0)
135
138
  throw this.createPlayerNotAttachedError();
136
- return this.impl.setVolume(r);
139
+ return this.impl.setVolume(a);
137
140
  }
138
- setMuted(r) {
139
- if (this.debug("setMuted", r), this.impl === void 0)
141
+ setMuted(a) {
142
+ if (this.debug("setMuted", a), this.impl === void 0)
140
143
  throw this.createPlayerNotAttachedError();
141
- return this.impl.setMuted(r);
144
+ return this.impl.setMuted(a);
142
145
  }
143
146
  getDuration() {
144
147
  if (this.debug("getDuration"), this.impl === void 0)
@@ -150,60 +153,65 @@ const U = class {
150
153
  throw this.createPlayerNotAttachedError();
151
154
  return this.impl.getCurrentTime();
152
155
  }
156
+ getVolume() {
157
+ if (this.debug("getVolume"), this.impl === void 0)
158
+ throw this.createPlayerNotAttachedError();
159
+ return this.impl.getVolume();
160
+ }
153
161
  };
154
- let T = U;
155
- m(T, "nextId", 1);
156
- function G() {
157
- const a = A(!0);
158
- return a.current ? (a.current = !1, !0) : a.current;
162
+ let f = S;
163
+ y(f, "nextId", 1);
164
+ function $() {
165
+ const r = V(!0);
166
+ return r.current ? (r.current = !1, !0) : r.current;
159
167
  }
160
- const $ = (a, r) => a === r;
161
- function x(a, r = $) {
162
- const e = A(), t = A(a);
163
- return !G() && !r(t.current, a) && (e.current = t.current, t.current = a), e.current;
168
+ const x = (r, a) => r === a;
169
+ function G(r, a = x) {
170
+ const e = V(), t = V(r);
171
+ return !$() && !a(t.current, r) && (e.current = t.current, t.current = r), e.current;
164
172
  }
165
173
  const b = ({
166
- logger: a,
167
- type: r,
174
+ logger: r,
175
+ type: a,
168
176
  playerApiRef: e,
169
177
  videoId: t,
170
- options: s,
178
+ options: i,
171
179
  loadScript: c,
172
- playerApiFactory: d,
173
- children: n
180
+ playerApiFactory: u,
181
+ children: o
174
182
  }) => {
175
- a.log(u.Debug, "PlayerContainer");
176
- const o = i.useRef(t), y = i.useRef(void 0), [p, g] = i.useState();
177
- i.useEffect(() => {
178
- const h = new T(
179
- a,
183
+ r.log(d.Debug, "PlayerContainer");
184
+ const l = s.useRef(t), p = s.useRef(void 0), [h, w] = s.useState();
185
+ s.useEffect(() => {
186
+ const n = new f(
180
187
  r,
181
- y,
182
- s,
188
+ a,
189
+ p,
190
+ i,
183
191
  c,
184
- d
192
+ u
185
193
  );
186
- return e && (e.current = h), h.attach(o.current).then(() => g(h)), () => {
187
- if (e && h !== e.current)
194
+ return e && (e.current = n), n.attach(l.current).then(() => w(n)), () => {
195
+ if (e && n !== e.current)
188
196
  throw new Error("playerApi differs");
189
- h.detach().then(() => g(void 0));
197
+ n.detach().then(() => w(void 0));
190
198
  };
191
- }, [a, r, s, c, d, e]);
192
- const l = x(t);
193
- return i.useEffect(() => {
194
- l !== void 0 && (p == null || p.loadVideo(t));
195
- }, [l, t, p]), /* @__PURE__ */ i.createElement(i.Fragment, null, n(y, o.current));
196
- }, B = i.memo(
197
- ({ ...a }) => {
198
- const { logger: r } = a;
199
- return r.log(u.Debug, "AudioPlayer"), /* @__PURE__ */ i.createElement(
199
+ }, [r, a, i, c, u, e]);
200
+ const g = G(t);
201
+ return s.useEffect(() => {
202
+ g !== void 0 && (h == null || h.loadVideo(t));
203
+ }, [g, t, h]), /* @__PURE__ */ s.createElement(s.Fragment, null, o(p, l.current));
204
+ }, B = s.memo(
205
+ ({ ...r }) => {
206
+ const { logger: a } = r;
207
+ return a.log(d.Debug, "AudioPlayer"), /* @__PURE__ */ s.createElement(
200
208
  b,
201
209
  {
202
- ...a,
210
+ ...r,
203
211
  loadScript: void 0,
204
212
  playerApiFactory: j
205
213
  },
206
- (e, t) => /* @__PURE__ */ i.createElement(
214
+ (e, t) => /* @__PURE__ */ s.createElement(
207
215
  "audio",
208
216
  {
209
217
  ref: e,
@@ -217,70 +225,71 @@ const b = ({
217
225
  );
218
226
  }
219
227
  );
220
- var k = /* @__PURE__ */ ((a) => (a[a.Play = 2] = "Play", a[a.Pause = 3] = "Pause", a[a.End = 4] = "End", a))(k || {});
221
- const P = class extends E {
222
- constructor(e, t, s) {
223
- super(e, t, s);
224
- m(this, "player");
225
- m(this, "duration");
226
- m(this, "currentTime");
228
+ var I = /* @__PURE__ */ ((r) => (r[r.Play = 2] = "Play", r[r.Pause = 3] = "Pause", r[r.End = 4] = "End", r))(I || {});
229
+ const D = class extends E {
230
+ constructor(e, t, i) {
231
+ super(e, t, i);
232
+ y(this, "player");
233
+ y(this, "duration");
234
+ y(this, "currentTime");
235
+ y(this, "volume");
236
+ y(this, "handleMessage", (e) => {
237
+ var i, c, u, o, l, p, h, w, g, n, m, U, v, M;
238
+ if (e.origin !== D.origin)
239
+ return;
240
+ const t = e.data;
241
+ switch (t.eventName) {
242
+ case "playerStatusChange":
243
+ this.logger.log(
244
+ d.Debug,
245
+ `player status changed: ${I[t.data.playerStatus] ?? t.data.playerStatus}`
246
+ );
247
+ break;
248
+ case "statusChange":
249
+ switch (this.logger.log(
250
+ d.Debug,
251
+ `status changed: ${I[t.data.playerStatus] ?? t.data.playerStatus}`
252
+ ), t.data.playerStatus) {
253
+ case 2:
254
+ (c = (i = this.options) == null ? void 0 : i.onPlay) == null || c.call(i);
255
+ break;
256
+ case 3:
257
+ (o = (u = this.options) == null ? void 0 : u.onPause) == null || o.call(u);
258
+ break;
259
+ case 4:
260
+ (p = (l = this.options) == null ? void 0 : l.onEnded) == null || p.call(l);
261
+ break;
262
+ }
263
+ break;
264
+ case "playerMetadataChange":
265
+ t.data.duration !== void 0 && (this.duration = t.data.duration / 1e3), this.currentTime = t.data.currentTime === void 0 ? void 0 : t.data.currentTime / 1e3, this.volume = t.data.volume, (w = (h = this.options) == null ? void 0 : h.onTimeUpdate) == null || w.call(h, {
266
+ duration: this.duration,
267
+ percent: this.currentTime !== void 0 && this.duration !== void 0 ? this.currentTime / this.duration : void 0,
268
+ seconds: this.currentTime
269
+ });
270
+ break;
271
+ case "loadComplete":
272
+ this.logger.log(d.Debug, "load completed"), this.duration = t.data.videoInfo.lengthInSeconds, (n = (g = this.options) == null ? void 0 : g.onLoaded) == null || n.call(g, { id: t.data.videoInfo.watchId });
273
+ break;
274
+ case "error":
275
+ (U = (m = this.options) == null ? void 0 : m.onError) == null || U.call(m, t);
276
+ break;
277
+ case "player-error:video:play":
278
+ case "player-error:video:seek":
279
+ (M = (v = this.options) == null ? void 0 : v.onError) == null || M.call(v, t);
280
+ break;
281
+ default:
282
+ this.logger.log(
283
+ d.Debug,
284
+ "message",
285
+ t.eventName,
286
+ t.data
287
+ );
288
+ break;
289
+ }
290
+ });
227
291
  this.player = t.current;
228
292
  }
229
- handleMessage(e) {
230
- var s, c, d, n, o, y, p, g, l, h, v, V, f, M;
231
- if (e.origin !== P.origin)
232
- return;
233
- const t = e.data;
234
- switch (t.eventName) {
235
- case "playerStatusChange":
236
- this.logger.log(
237
- u.Debug,
238
- `player status changed: ${k[t.data.playerStatus] ?? t.data.playerStatus}`
239
- );
240
- break;
241
- case "statusChange":
242
- switch (this.logger.log(
243
- u.Debug,
244
- `status changed: ${k[t.data.playerStatus] ?? t.data.playerStatus}`
245
- ), t.data.playerStatus) {
246
- case 2:
247
- (c = (s = this.options) == null ? void 0 : s.onPlay) == null || c.call(s);
248
- break;
249
- case 3:
250
- (n = (d = this.options) == null ? void 0 : d.onPause) == null || n.call(d);
251
- break;
252
- case 4:
253
- (y = (o = this.options) == null ? void 0 : o.onEnded) == null || y.call(o);
254
- break;
255
- }
256
- break;
257
- case "playerMetadataChange":
258
- t.data.duration !== void 0 && (this.duration = t.data.duration / 1e3), this.currentTime = t.data.currentTime === void 0 ? void 0 : t.data.currentTime / 1e3, (g = (p = this.options) == null ? void 0 : p.onTimeUpdate) == null || g.call(p, {
259
- duration: this.duration,
260
- percent: this.currentTime !== void 0 && this.duration !== void 0 ? this.currentTime / this.duration : void 0,
261
- seconds: this.currentTime
262
- });
263
- break;
264
- case "loadComplete":
265
- this.logger.log(u.Debug, "load completed"), this.duration = t.data.videoInfo.lengthInSeconds, (h = (l = this.options) == null ? void 0 : l.onLoaded) == null || h.call(l, { id: t.data.videoInfo.watchId });
266
- break;
267
- case "error":
268
- (V = (v = this.options) == null ? void 0 : v.onError) == null || V.call(v, t);
269
- break;
270
- case "player-error:video:play":
271
- case "player-error:video:seek":
272
- (M = (f = this.options) == null ? void 0 : f.onError) == null || M.call(f, t);
273
- break;
274
- default:
275
- this.logger.log(
276
- u.Debug,
277
- "message",
278
- t.eventName,
279
- t.data
280
- );
281
- break;
282
- }
283
- }
284
293
  async attach() {
285
294
  window.addEventListener("message", this.handleMessage);
286
295
  }
@@ -288,7 +297,7 @@ const P = class extends E {
288
297
  window.removeEventListener("message", this.handleMessage);
289
298
  }
290
299
  async loadVideo(e) {
291
- return new Promise((t, s) => {
300
+ return new Promise((t, i) => {
292
301
  this.duration = void 0, this.currentTime = void 0, this.player.onload = () => {
293
302
  this.player.onload = null, t();
294
303
  }, this.player.src = `https://embed.nicovideo.jp/watch/${e}?jsapi=1&playerId=1`;
@@ -303,7 +312,7 @@ const P = class extends E {
303
312
  playerId: "1",
304
313
  sourceConnectorType: 1
305
314
  },
306
- P.origin
315
+ D.origin
307
316
  );
308
317
  }
309
318
  async play() {
@@ -333,20 +342,23 @@ const P = class extends E {
333
342
  async getCurrentTime() {
334
343
  return this.currentTime;
335
344
  }
345
+ async getVolume() {
346
+ return this.volume;
347
+ }
336
348
  };
337
- let C = P;
338
- m(C, "origin", "https://embed.nicovideo.jp");
339
- const O = i.memo(
340
- ({ ...a }) => {
341
- const { logger: r } = a;
342
- return r.log(u.Debug, "NiconicoPlayer"), /* @__PURE__ */ i.createElement(
349
+ let C = D;
350
+ y(C, "origin", "https://embed.nicovideo.jp");
351
+ const O = s.memo(
352
+ ({ ...r }) => {
353
+ const { logger: a } = r;
354
+ return a.log(d.Debug, "NiconicoPlayer"), /* @__PURE__ */ s.createElement(
343
355
  b,
344
356
  {
345
- ...a,
357
+ ...r,
346
358
  loadScript: void 0,
347
359
  playerApiFactory: C
348
360
  },
349
- (e, t) => /* @__PURE__ */ i.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ i.createElement(
361
+ (e, t) => /* @__PURE__ */ s.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ s.createElement(
350
362
  "iframe",
351
363
  {
352
364
  ref: e,
@@ -360,165 +372,168 @@ const O = i.memo(
360
372
  ))
361
373
  );
362
374
  }
363
- ), R = i.createContext(
375
+ ), R = s.createContext(
364
376
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
365
377
  void 0
366
378
  ), H = new class {
367
379
  constructor() {
368
- m(this, "title", "nostalgic-diva");
380
+ y(this, "title", "nostalgic-diva");
369
381
  }
370
- createMessage(a) {
371
- return `[${this.title}] ${a}`;
382
+ createMessage(r) {
383
+ return `[${this.title}] ${r}`;
372
384
  }
373
- debug(a, ...r) {
374
- console.debug(this.createMessage(a), ...r);
385
+ debug(r, ...a) {
386
+ console.debug(this.createMessage(r), ...a);
375
387
  }
376
- error(a, ...r) {
377
- console.error(this.createMessage(a), ...r);
388
+ error(r, ...a) {
389
+ console.error(this.createMessage(r), ...a);
378
390
  }
379
- warn(a, ...r) {
380
- console.warn(this.createMessage(a), ...r);
391
+ warn(r, ...a) {
392
+ console.warn(this.createMessage(r), ...a);
381
393
  }
382
394
  isEnabled() {
383
395
  return !0;
384
396
  }
385
- log(a, r, ...e) {
386
- switch (a) {
387
- case u.Debug:
388
- this.debug(r, ...e);
397
+ log(r, a, ...e) {
398
+ switch (r) {
399
+ case d.Debug:
400
+ this.debug(a, ...e);
389
401
  break;
390
- case u.Warning:
391
- this.warn(r, ...e);
402
+ case d.Warning:
403
+ this.warn(a, ...e);
392
404
  break;
393
- case u.Error:
394
- this.error(r, ...e);
405
+ case d.Error:
406
+ this.error(a, ...e);
395
407
  break;
396
408
  }
397
409
  }
398
410
  }(), ee = ({
399
- logger: a = H,
400
- children: r
411
+ logger: r = H,
412
+ children: a
401
413
  }) => {
402
- const e = i.useRef(), t = i.useCallback(async (l) => {
403
- var h;
404
- await ((h = e.current) == null ? void 0 : h.loadVideo(l));
405
- }, []), s = i.useCallback(async () => {
406
- var l;
407
- await ((l = e.current) == null ? void 0 : l.play());
408
- }, []), c = i.useCallback(async () => {
409
- var l;
410
- await ((l = e.current) == null ? void 0 : l.pause());
411
- }, []), d = i.useCallback(async (l) => {
412
- const h = e.current;
413
- h && (await h.setCurrentTime(l), await h.play());
414
- }, []), n = i.useCallback(async (l) => {
415
- var h;
416
- await ((h = e.current) == null ? void 0 : h.setVolume(l));
417
- }, []), o = i.useCallback(async (l) => {
418
- var h;
419
- await ((h = e.current) == null ? void 0 : h.setMuted(l));
420
- }, []), y = i.useCallback(async () => {
421
- var l;
422
- return await ((l = e.current) == null ? void 0 : l.getDuration());
423
- }, []), p = i.useCallback(async () => {
424
- var l;
425
- return await ((l = e.current) == null ? void 0 : l.getCurrentTime());
426
- }, []), g = i.useMemo(
414
+ const e = s.useRef(), t = s.useCallback(async (n) => {
415
+ var m;
416
+ await ((m = e.current) == null ? void 0 : m.loadVideo(n));
417
+ }, []), i = s.useCallback(async () => {
418
+ var n;
419
+ await ((n = e.current) == null ? void 0 : n.play());
420
+ }, []), c = s.useCallback(async () => {
421
+ var n;
422
+ await ((n = e.current) == null ? void 0 : n.pause());
423
+ }, []), u = s.useCallback(async (n) => {
424
+ const m = e.current;
425
+ m && (await m.setCurrentTime(n), await m.play());
426
+ }, []), o = s.useCallback(async (n) => {
427
+ var m;
428
+ await ((m = e.current) == null ? void 0 : m.setVolume(n));
429
+ }, []), l = s.useCallback(async (n) => {
430
+ var m;
431
+ await ((m = e.current) == null ? void 0 : m.setMuted(n));
432
+ }, []), p = s.useCallback(async () => {
433
+ var n;
434
+ return await ((n = e.current) == null ? void 0 : n.getDuration());
435
+ }, []), h = s.useCallback(async () => {
436
+ var n;
437
+ return await ((n = e.current) == null ? void 0 : n.getCurrentTime());
438
+ }, []), w = s.useCallback(async () => {
439
+ var n;
440
+ return await ((n = e.current) == null ? void 0 : n.getVolume());
441
+ }, []), g = s.useMemo(
427
442
  () => ({
428
- logger: a,
443
+ logger: r,
429
444
  playerApiRef: e,
430
445
  loadVideo: t,
431
- play: s,
446
+ play: i,
432
447
  pause: c,
433
- setCurrentTime: d,
434
- setVolume: n,
435
- setMuted: o,
436
- getDuration: y,
437
- getCurrentTime: p
448
+ setCurrentTime: u,
449
+ setVolume: o,
450
+ setMuted: l,
451
+ getDuration: p,
452
+ getCurrentTime: h,
453
+ getVolume: w
438
454
  }),
439
455
  [
440
- a,
456
+ r,
441
457
  t,
442
- s,
458
+ i,
443
459
  c,
444
- d,
445
- n,
460
+ u,
446
461
  o,
447
- y,
448
- p
462
+ l,
463
+ p,
464
+ h,
465
+ w
449
466
  ]
450
467
  );
451
- return /* @__PURE__ */ i.createElement(R.Provider, { value: g }, r);
452
- }, q = () => i.useContext(R);
453
- class w extends E {
454
- constructor(e, t, s) {
455
- super(e, t, s);
456
- m(this, "player");
468
+ return /* @__PURE__ */ s.createElement(R.Provider, { value: g }, a);
469
+ }, q = () => s.useContext(R);
470
+ class A extends E {
471
+ constructor(e, t, i) {
472
+ super(e, t, i);
473
+ y(this, "player");
457
474
  this.player = SC.Widget(this.playerElementRef.current);
458
475
  }
459
- static playerGetDurationAsync(e) {
460
- return new Promise((t, s) => {
461
- e.getDuration(t);
476
+ getDurationCore() {
477
+ return new Promise((e, t) => {
478
+ this.player.getDuration(e);
462
479
  });
463
480
  }
464
481
  attach(e) {
465
- return new Promise((t, s) => {
482
+ return new Promise((t, i) => {
466
483
  this.player.bind(SC.Widget.Events.READY, () => {
467
- var c, d;
484
+ var c, u;
468
485
  this.player.bind(
469
486
  SC.Widget.Events.PLAY_PROGRESS,
470
- async (n) => {
471
- var y, p;
472
- const o = await w.playerGetDurationAsync(
473
- this.player
474
- );
475
- (p = (y = this.options) == null ? void 0 : y.onTimeUpdate) == null || p.call(y, {
476
- duration: o / 1e3,
477
- percent: n.currentPosition / o,
478
- seconds: n.currentPosition / 1e3
487
+ async (o) => {
488
+ var p, h;
489
+ const l = await this.getDurationCore();
490
+ (h = (p = this.options) == null ? void 0 : p.onTimeUpdate) == null || h.call(p, {
491
+ duration: l / 1e3,
492
+ percent: o.currentPosition / l,
493
+ seconds: o.currentPosition / 1e3
479
494
  });
480
495
  }
481
496
  ), this.player.bind(
482
497
  SC.Widget.Events.ERROR,
483
- (n) => {
484
- var o, y;
485
- return (y = (o = this.options) == null ? void 0 : o.onError) == null ? void 0 : y.call(o, n);
498
+ (o) => {
499
+ var l, p;
500
+ return (p = (l = this.options) == null ? void 0 : l.onError) == null ? void 0 : p.call(l, o);
486
501
  }
487
502
  ), this.player.bind(
488
503
  SC.Widget.Events.PLAY,
489
504
  () => {
490
- var n, o;
491
- return (o = (n = this.options) == null ? void 0 : n.onPlay) == null ? void 0 : o.call(n);
505
+ var o, l;
506
+ return (l = (o = this.options) == null ? void 0 : o.onPlay) == null ? void 0 : l.call(o);
492
507
  }
493
508
  ), this.player.bind(
494
509
  SC.Widget.Events.PAUSE,
495
510
  () => {
496
- var n, o;
497
- return (o = (n = this.options) == null ? void 0 : n.onPause) == null ? void 0 : o.call(n);
511
+ var o, l;
512
+ return (l = (o = this.options) == null ? void 0 : o.onPause) == null ? void 0 : l.call(o);
498
513
  }
499
514
  ), this.player.bind(
500
515
  SC.Widget.Events.FINISH,
501
516
  () => {
502
- var n, o;
503
- return (o = (n = this.options) == null ? void 0 : n.onEnded) == null ? void 0 : o.call(n);
517
+ var o, l;
518
+ return (l = (o = this.options) == null ? void 0 : o.onEnded) == null ? void 0 : l.call(o);
504
519
  }
505
- ), (d = (c = this.options) == null ? void 0 : c.onLoaded) == null || d.call(c, { id: e }), t();
520
+ ), (u = (c = this.options) == null ? void 0 : c.onLoaded) == null || u.call(c, { id: e }), t();
506
521
  });
507
522
  });
508
523
  }
509
524
  async detach() {
510
525
  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);
511
526
  }
512
- static playerLoadAsync(e, t, s) {
513
- return new Promise((c, d) => {
514
- e.load(t, { ...s, callback: c });
527
+ static playerLoadAsync(e, t, i) {
528
+ return new Promise((c, u) => {
529
+ e.load(t, { ...i, callback: c });
515
530
  });
516
531
  }
517
532
  async loadVideo(e) {
518
- var t, s;
519
- await w.playerLoadAsync(this.player, e, {
533
+ var t, i;
534
+ await A.playerLoadAsync(this.player, e, {
520
535
  auto_play: !0
521
- }), (s = (t = this.options) == null ? void 0 : t.onLoaded) == null || s.call(t, { id: e });
536
+ }), (i = (t = this.options) == null ? void 0 : t.onLoaded) == null || i.call(t, { id: e });
522
537
  }
523
538
  async play() {
524
539
  this.player.play();
@@ -539,64 +554,68 @@ class w extends E {
539
554
  );
540
555
  }
541
556
  async getDuration() {
542
- return await w.playerGetDurationAsync(
543
- this.player
544
- ) / 1e3;
557
+ return await this.getDurationCore() / 1e3;
545
558
  }
546
- static playerGetPositionAsync(e) {
547
- return new Promise((t, s) => {
548
- e.getPosition(t);
559
+ getCurrentTimeCore() {
560
+ return new Promise((e, t) => {
561
+ this.player.getPosition(e);
549
562
  });
550
563
  }
551
564
  async getCurrentTime() {
552
- return await w.playerGetPositionAsync(
553
- this.player
554
- ) / 1e3;
565
+ return await this.getCurrentTimeCore() / 1e3;
566
+ }
567
+ getVolumeCore() {
568
+ return new Promise((e, t) => {
569
+ this.player.getVolume(e);
570
+ });
571
+ }
572
+ async getVolume() {
573
+ return await this.getVolumeCore() / 100;
555
574
  }
556
575
  }
557
- function z(a) {
558
- return new Promise((r, e) => {
576
+ function z(r) {
577
+ return new Promise((a, e) => {
559
578
  const t = document.createElement("script");
560
- t.src = a, t.async = !0, t.onerror = e, t.onload = t.onreadystatechange = function() {
561
- const s = this.readyState;
562
- s && s !== "loaded" && s !== "complete" || (t.onload = t.onreadystatechange = null, r());
579
+ t.src = r, t.async = !0, t.onerror = e, t.onload = t.onreadystatechange = function() {
580
+ const i = this.readyState;
581
+ i && i !== "loaded" && i !== "complete" || (t.onload = t.onreadystatechange = null, a());
563
582
  }, document.head.appendChild(t);
564
583
  });
565
584
  }
566
- const I = [];
567
- async function N(a, r) {
568
- if (I.includes(a))
569
- return r.log(u.Debug, a, "script is already loaded"), !1;
585
+ const P = [];
586
+ async function k(r, a) {
587
+ if (P.includes(r))
588
+ return a.log(d.Debug, r, "script is already loaded"), !1;
570
589
  try {
571
- return r.log(u.Debug, a, "Loading script..."), await z(a), I.includes(a) ? (r.log(u.Debug, a, "script is already loaded"), !1) : (I.push(a), r.log(u.Debug, a, "script loaded"), !0);
590
+ return a.log(d.Debug, r, "Loading script..."), await z(r), P.includes(r) ? (a.log(d.Debug, r, "script is already loaded"), !1) : (P.push(r), a.log(d.Debug, r, "script loaded"), !0);
572
591
  } catch (e) {
573
- throw r.log(u.Error, a, "Failed to load script"), e;
592
+ throw a.log(d.Error, r, "Failed to load script"), e;
574
593
  }
575
594
  }
576
- const J = i.memo(
577
- ({ ...a }) => {
578
- const { logger: r } = a;
579
- r.log(u.Debug, "SoundCloudPlayer");
580
- const e = i.useCallback(async () => {
581
- await N(
595
+ const J = s.memo(
596
+ ({ ...r }) => {
597
+ const { logger: a } = r;
598
+ a.log(d.Debug, "SoundCloudPlayer");
599
+ const e = s.useCallback(async () => {
600
+ await k(
582
601
  "https://w.soundcloud.com/player/api.js",
583
- r
602
+ a
584
603
  );
585
- }, [r]);
586
- return /* @__PURE__ */ i.createElement(
604
+ }, [a]);
605
+ return /* @__PURE__ */ s.createElement(
587
606
  b,
588
607
  {
589
- ...a,
608
+ ...r,
590
609
  loadScript: e,
591
- playerApiFactory: w
610
+ playerApiFactory: A
592
611
  },
593
- (t, s) => (
612
+ (t, i) => (
594
613
  // eslint-disable-next-line jsx-a11y/iframe-has-title
595
- /* @__PURE__ */ i.createElement(
614
+ /* @__PURE__ */ s.createElement(
596
615
  "iframe",
597
616
  {
598
617
  ref: t,
599
- src: `https://w.soundcloud.com/player/?url=${s}`,
618
+ src: `https://w.soundcloud.com/player/?url=${i}`,
600
619
  frameBorder: 0,
601
620
  allow: "autoplay",
602
621
  style: { width: "100%", height: "100%" }
@@ -607,20 +626,20 @@ const J = i.memo(
607
626
  }
608
627
  );
609
628
  class K extends E {
610
- constructor(e, t, s) {
611
- super(e, t, s);
612
- m(this, "player");
629
+ constructor(e, t, i) {
630
+ super(e, t, i);
631
+ y(this, "player");
613
632
  this.player = new Vimeo.Player(this.playerElementRef.current);
614
633
  }
615
634
  async attach() {
616
635
  await this.player.ready(), this.player.on("error", (e) => {
617
- var t, s;
618
- return (s = (t = this.options) == null ? void 0 : t.onError) == null ? void 0 : s.call(t, e);
636
+ var t, i;
637
+ return (i = (t = this.options) == null ? void 0 : t.onError) == null ? void 0 : i.call(t, e);
619
638
  }), this.player.on(
620
639
  "loaded",
621
640
  (e) => {
622
- var t, s;
623
- return (s = (t = this.options) == null ? void 0 : t.onLoaded) == null ? void 0 : s.call(t, { id: e.id.toString() });
641
+ var t, i;
642
+ return (i = (t = this.options) == null ? void 0 : t.onLoaded) == null ? void 0 : i.call(t, { id: e.id.toString() });
624
643
  }
625
644
  ), this.player.on("play", () => {
626
645
  var e, t;
@@ -632,8 +651,8 @@ class K extends E {
632
651
  var e, t;
633
652
  return (t = (e = this.options) == null ? void 0 : e.onEnded) == null ? void 0 : t.call(e);
634
653
  }), this.player.on("timeupdate", (e) => {
635
- var t, s;
636
- (s = (t = this.options) == null ? void 0 : t.onTimeUpdate) == null || s.call(t, {
654
+ var t, i;
655
+ (i = (t = this.options) == null ? void 0 : t.onTimeUpdate) == null || i.call(t, {
637
656
  duration: e.duration,
638
657
  percent: e.percent,
639
658
  seconds: e.seconds
@@ -662,36 +681,39 @@ class K extends E {
662
681
  await this.player.setMuted(e);
663
682
  }
664
683
  async getDuration() {
665
- return await this.player.getDuration();
684
+ return this.player.getDuration();
666
685
  }
667
686
  async getCurrentTime() {
668
687
  return await this.player.getCurrentTime();
669
688
  }
689
+ async getVolume() {
690
+ return await this.player.getVolume();
691
+ }
670
692
  }
671
- const Q = i.memo(
672
- ({ ...a }) => {
673
- const { logger: r } = a;
674
- r.log(u.Debug, "VimeoPlayer");
675
- const e = i.useCallback(async () => {
676
- await N(
693
+ const Q = s.memo(
694
+ ({ ...r }) => {
695
+ const { logger: a } = r;
696
+ a.log(d.Debug, "VimeoPlayer");
697
+ const e = s.useCallback(async () => {
698
+ await k(
677
699
  "https://player.vimeo.com/api/player.js",
678
- r
700
+ a
679
701
  );
680
- }, [r]);
681
- return /* @__PURE__ */ i.createElement(
702
+ }, [a]);
703
+ return /* @__PURE__ */ s.createElement(
682
704
  b,
683
705
  {
684
- ...a,
706
+ ...r,
685
707
  loadScript: e,
686
708
  playerApiFactory: K
687
709
  },
688
- (t, s) => (
710
+ (t, i) => (
689
711
  // eslint-disable-next-line jsx-a11y/iframe-has-title
690
- /* @__PURE__ */ i.createElement(
712
+ /* @__PURE__ */ s.createElement(
691
713
  "iframe",
692
714
  {
693
715
  ref: t,
694
- src: `https://player.vimeo.com/video/${s}`,
716
+ src: `https://player.vimeo.com/video/${i}`,
695
717
  frameBorder: 0,
696
718
  allow: "autoplay",
697
719
  style: { width: "100%", height: "100%" }
@@ -701,76 +723,76 @@ const Q = i.memo(
701
723
  );
702
724
  }
703
725
  );
704
- var F = /* @__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))(F || {});
705
- const S = class extends E {
706
- constructor(e, t, s) {
707
- super(e, t, s);
708
- m(this, "player");
709
- m(this, "previousTime");
710
- m(this, "timeUpdateIntervalId");
726
+ var F = /* @__PURE__ */ ((r) => (r[r.UNSTARTED = -1] = "UNSTARTED", r[r.ENDED = 0] = "ENDED", r[r.PLAYING = 1] = "PLAYING", r[r.PAUSED = 2] = "PAUSED", r[r.BUFFERING = 3] = "BUFFERING", r[r.CUED = 5] = "CUED", r))(F || {});
727
+ const N = class extends E {
728
+ constructor(e, t, i) {
729
+ super(e, t, i);
730
+ y(this, "player");
731
+ y(this, "previousTime");
732
+ y(this, "timeUpdateIntervalId");
711
733
  this.player = new YT.Player(this.playerElementRef.current, {
712
- host: S.origin,
734
+ host: N.origin,
713
735
  width: "100%",
714
736
  height: "100%"
715
737
  });
716
738
  }
717
739
  clearTimeUpdateInterval() {
718
740
  this.logger.log(
719
- u.Debug,
741
+ d.Debug,
720
742
  "clearTimeUpdateInterval",
721
743
  this.timeUpdateIntervalId
722
744
  ), window.clearInterval(this.timeUpdateIntervalId), this.timeUpdateIntervalId = void 0;
723
745
  }
724
746
  invokeTimeUpdate(e) {
725
- var c, d;
747
+ var c, u;
726
748
  const t = e.getCurrentTime();
727
749
  if (t === this.previousTime)
728
750
  return;
729
- const s = e.getDuration();
730
- (d = (c = this.options) == null ? void 0 : c.onTimeUpdate) == null || d.call(c, {
731
- duration: s,
732
- percent: t / s,
751
+ const i = e.getDuration();
752
+ (u = (c = this.options) == null ? void 0 : c.onTimeUpdate) == null || u.call(c, {
753
+ duration: i,
754
+ percent: t / i,
733
755
  seconds: t
734
756
  }), this.previousTime = t;
735
757
  }
736
758
  setTimeUpdateInterval() {
737
- this.logger.log(u.Debug, "setTimeUpdateInterval"), this.clearTimeUpdateInterval(), this.timeUpdateIntervalId = window.setInterval(
759
+ this.logger.log(d.Debug, "setTimeUpdateInterval"), this.clearTimeUpdateInterval(), this.timeUpdateIntervalId = window.setInterval(
738
760
  () => this.invokeTimeUpdate(this.player),
739
761
  250
740
762
  ), this.logger.log(
741
- u.Debug,
763
+ d.Debug,
742
764
  "timeUpdateIntervalId",
743
765
  this.timeUpdateIntervalId
744
766
  ), this.invokeTimeUpdate(this.player);
745
767
  }
746
768
  attach(e) {
747
- return new Promise((t, s) => {
769
+ return new Promise((t, i) => {
748
770
  this.player.addEventListener("onReady", async () => {
749
771
  this.player.addEventListener(
750
772
  "onError",
751
773
  (c) => {
752
- var d, n;
753
- return (n = (d = this.options) == null ? void 0 : d.onError) == null ? void 0 : n.call(d, c.data);
774
+ var u, o;
775
+ return (o = (u = this.options) == null ? void 0 : u.onError) == null ? void 0 : o.call(u, c.data);
754
776
  }
755
777
  ), this.player.addEventListener(
756
778
  "onStateChange",
757
779
  (c) => {
758
- var d, n, o, y, p, g, l, h;
780
+ var u, o, l, p, h, w, g, n;
759
781
  switch (this.logger.log(
760
- u.Debug,
782
+ d.Debug,
761
783
  `state changed: ${F[c.data]}`
762
784
  ), c.data) {
763
785
  case YT.PlayerState.CUED:
764
- (n = (d = this.options) == null ? void 0 : d.onLoaded) == null || n.call(d, { id: e });
786
+ (o = (u = this.options) == null ? void 0 : u.onLoaded) == null || o.call(u, { id: e });
765
787
  break;
766
788
  case YT.PlayerState.PLAYING:
767
- (y = (o = this.options) == null ? void 0 : o.onPlay) == null || y.call(o), this.setTimeUpdateInterval();
789
+ (p = (l = this.options) == null ? void 0 : l.onPlay) == null || p.call(l), this.setTimeUpdateInterval();
768
790
  break;
769
791
  case YT.PlayerState.PAUSED:
770
- (g = (p = this.options) == null ? void 0 : p.onPause) == null || g.call(p), this.clearTimeUpdateInterval();
792
+ (w = (h = this.options) == null ? void 0 : h.onPause) == null || w.call(h), this.clearTimeUpdateInterval();
771
793
  break;
772
794
  case YT.PlayerState.ENDED:
773
- (h = (l = this.options) == null ? void 0 : l.onEnded) == null || h.call(l), this.clearTimeUpdateInterval();
795
+ (n = (g = this.options) == null ? void 0 : g.onEnded) == null || n.call(g), this.clearTimeUpdateInterval();
774
796
  break;
775
797
  }
776
798
  }
@@ -805,29 +827,32 @@ const S = class extends E {
805
827
  async getCurrentTime() {
806
828
  return this.player.getCurrentTime();
807
829
  }
830
+ async getVolume() {
831
+ return this.player.getVolume();
832
+ }
808
833
  };
809
- let D = S;
810
- m(D, "origin", "https://www.youtube-nocookie.com");
811
- const X = i.memo(
812
- ({ ...a }) => {
813
- const { logger: r } = a;
814
- r.log(u.Debug, "YouTubePlayer");
815
- const e = i.useCallback(() => new Promise(async (t, s) => {
816
- await N(
834
+ let T = N;
835
+ y(T, "origin", "https://www.youtube-nocookie.com");
836
+ const X = s.memo(
837
+ ({ ...r }) => {
838
+ const { logger: a } = r;
839
+ a.log(d.Debug, "YouTubePlayer");
840
+ const e = s.useCallback(() => new Promise(async (t, i) => {
841
+ await k(
817
842
  "https://www.youtube.com/iframe_api",
818
- r
843
+ a
819
844
  ) ? window.onYouTubeIframeAPIReady = () => {
820
- r.log(u.Debug, "YouTube iframe API ready"), t();
845
+ a.log(d.Debug, "YouTube iframe API ready"), t();
821
846
  } : t();
822
- }), [r]);
823
- return /* @__PURE__ */ i.createElement(
847
+ }), [a]);
848
+ return /* @__PURE__ */ s.createElement(
824
849
  b,
825
850
  {
826
- ...a,
851
+ ...r,
827
852
  loadScript: e,
828
- playerApiFactory: D
853
+ playerApiFactory: T
829
854
  },
830
- (t) => /* @__PURE__ */ i.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ i.createElement("div", { ref: t }))
855
+ (t) => /* @__PURE__ */ s.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ s.createElement("div", { ref: t }))
831
856
  );
832
857
  }
833
858
  ), Z = {
@@ -836,18 +861,18 @@ const X = i.memo(
836
861
  SoundCloud: J,
837
862
  Vimeo: Q,
838
863
  YouTube: X
839
- }, te = i.memo(
840
- ({ type: a, videoId: r, options: e }) => {
841
- const { logger: t, playerApiRef: s } = q();
842
- t.log(u.Debug, "NostalgicDiva");
843
- const c = Z[a];
844
- return /* @__PURE__ */ i.createElement(
864
+ }, te = s.memo(
865
+ ({ type: r, videoId: a, options: e }) => {
866
+ const { logger: t, playerApiRef: i } = q();
867
+ t.log(d.Debug, "NostalgicDiva");
868
+ const c = Z[r];
869
+ return /* @__PURE__ */ s.createElement(
845
870
  c,
846
871
  {
847
872
  logger: t,
848
- type: a,
849
- playerApiRef: s,
850
- videoId: r,
873
+ type: r,
874
+ playerApiRef: i,
875
+ videoId: a,
851
876
  options: e
852
877
  }
853
878
  );
@@ -860,13 +885,13 @@ export {
860
885
  C as NiconicoPlayerApi,
861
886
  te as NostalgicDiva,
862
887
  ee as NostalgicDivaProvider,
863
- T as PlayerApi,
888
+ f as PlayerApi,
864
889
  J as SoundCloudPlayer,
865
- w as SoundCloudPlayerApi,
890
+ A as SoundCloudPlayerApi,
866
891
  Q as VimeoPlayer,
867
892
  K as VimeoPlayerApi,
868
893
  X as YouTubePlayer,
869
- D as YouTubePlayerApi,
894
+ T as YouTubePlayerApi,
870
895
  q as useNostalgicDiva
871
896
  };
872
897
  //# sourceMappingURL=index.es.js.map