@aigamo/nostalgic-diva 1.3.1 → 1.4.1

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