@aigamo/nostalgic-diva 1.3.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/LICENSE +22 -0
- package/README.md +125 -0
- package/dist/components/AudioPlayer.d.ts +3 -0
- package/dist/components/NiconicoPlayer.d.ts +3 -0
- package/dist/components/NostalgicDiva.d.ts +9 -0
- package/dist/components/NostalgicDivaProvider.d.ts +11 -0
- package/dist/components/PlayerContainer.d.ts +16 -0
- package/dist/components/SoundCloudPlayer.d.ts +3 -0
- package/dist/components/VimeoPlayer.d.ts +3 -0
- package/dist/components/YouTubePlayer.d.ts +3 -0
- package/dist/components/index.d.ts +7 -0
- package/dist/components/useFirstMountState.d.ts +1 -0
- package/dist/components/usePreviousDistinct.d.ts +2 -0
- package/dist/global.d.ts +757 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +802 -0
- package/dist/index.es.js.map +1 -0
- package/dist/players/AudioPlayerApi.d.ts +17 -0
- package/dist/players/NiconicoPlayerApi.d.ts +27 -0
- package/dist/players/PlayerApi.d.ts +58 -0
- package/dist/players/PlayerApiImpl.d.ts +18 -0
- package/dist/players/PlayerConsole.d.ts +8 -0
- package/dist/players/SoundCloudPlayerApi.d.ts +20 -0
- package/dist/players/VimeoPlayerApi.d.ts +17 -0
- package/dist/players/YouTubePlayerApi.d.ts +28 -0
- package/dist/players/ensureScriptLoaded.d.ts +1 -0
- package/dist/players/getScript.d.ts +1 -0
- package/dist/players/index.d.ts +6 -0
- package/package.json +69 -0
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,802 @@
|
|
|
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");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class $ extends b {
|
|
11
|
+
constructor(e, t, r) {
|
|
12
|
+
super(e, t, r);
|
|
13
|
+
m(this, "player");
|
|
14
|
+
this.player = t.current;
|
|
15
|
+
}
|
|
16
|
+
async attach() {
|
|
17
|
+
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);
|
|
20
|
+
}, this.player.onloadeddata = () => {
|
|
21
|
+
var e, t;
|
|
22
|
+
return (t = (e = this.options) == null ? void 0 : e.onLoaded) == null ? void 0 : t.call(e, { id: this.player.src });
|
|
23
|
+
}, this.player.onplay = () => {
|
|
24
|
+
var e, t;
|
|
25
|
+
return (t = (e = this.options) == null ? void 0 : e.onPlay) == null ? void 0 : t.call(e);
|
|
26
|
+
}, this.player.onpause = () => {
|
|
27
|
+
var e, t;
|
|
28
|
+
return (t = (e = this.options) == null ? void 0 : e.onPause) == null ? void 0 : t.call(e);
|
|
29
|
+
}, this.player.onended = () => {
|
|
30
|
+
var e, t;
|
|
31
|
+
return (t = (e = this.options) == null ? void 0 : e.onEnded) == null ? void 0 : t.call(e);
|
|
32
|
+
}, this.player.ontimeupdate = () => {
|
|
33
|
+
var e, t;
|
|
34
|
+
(t = (e = this.options) == null ? void 0 : e.onTimeUpdate) == null || t.call(e, {
|
|
35
|
+
duration: this.player.duration,
|
|
36
|
+
percent: this.player.currentTime / this.player.duration,
|
|
37
|
+
seconds: this.player.currentTime
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async detach() {
|
|
42
|
+
this.player.onerror = null, this.player.onloadeddata = null, this.player.onplay = null, this.player.onpause = null, this.player.onended = null, this.player.ontimeupdate = null;
|
|
43
|
+
}
|
|
44
|
+
async loadVideo(e) {
|
|
45
|
+
this.player.src = e;
|
|
46
|
+
}
|
|
47
|
+
async play() {
|
|
48
|
+
this.player.play();
|
|
49
|
+
}
|
|
50
|
+
async pause() {
|
|
51
|
+
this.player.pause();
|
|
52
|
+
}
|
|
53
|
+
async setCurrentTime(e) {
|
|
54
|
+
this.player.currentTime = e;
|
|
55
|
+
}
|
|
56
|
+
async setVolume(e) {
|
|
57
|
+
this.player.volume = e;
|
|
58
|
+
}
|
|
59
|
+
async setMuted(e) {
|
|
60
|
+
this.player.muted = e;
|
|
61
|
+
}
|
|
62
|
+
async getDuration() {
|
|
63
|
+
return this.player.duration;
|
|
64
|
+
}
|
|
65
|
+
async getCurrentTime() {
|
|
66
|
+
return this.player.currentTime;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
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) {
|
|
94
|
+
m(this, "id");
|
|
95
|
+
m(this, "impl");
|
|
96
|
+
this.type = a, this.playerElementRef = e, this.options = t, this.loadScript = r, this.playerApiFactory = d, this.id = M.nextId++;
|
|
97
|
+
}
|
|
98
|
+
createMessage(a) {
|
|
99
|
+
return `${this.type}#${this.id} ${a}`;
|
|
100
|
+
}
|
|
101
|
+
debug(a, ...e) {
|
|
102
|
+
h.debug(this.createMessage(a), ...e);
|
|
103
|
+
}
|
|
104
|
+
error(a, ...e) {
|
|
105
|
+
h.error(this.createMessage(a), ...e);
|
|
106
|
+
}
|
|
107
|
+
async attach(a) {
|
|
108
|
+
var e;
|
|
109
|
+
if (this.debug("attach", a), this.impl) {
|
|
110
|
+
this.debug("player is already attached");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
await ((e = this.loadScript) == null ? void 0 : e.call(this)), this.debug("Attaching player..."), this.impl = new this.playerApiFactory(
|
|
114
|
+
this,
|
|
115
|
+
this.playerElementRef,
|
|
116
|
+
this.options
|
|
117
|
+
), await this.impl.attach(a), this.debug("player attached");
|
|
118
|
+
}
|
|
119
|
+
assertPlayerAttached() {
|
|
120
|
+
h.assert(!!this.impl, "player is not attached");
|
|
121
|
+
}
|
|
122
|
+
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());
|
|
157
|
+
}
|
|
158
|
+
};
|
|
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;
|
|
164
|
+
}
|
|
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;
|
|
169
|
+
}
|
|
170
|
+
const E = ({
|
|
171
|
+
type: s,
|
|
172
|
+
playerApiRef: a,
|
|
173
|
+
videoId: e,
|
|
174
|
+
options: t,
|
|
175
|
+
loadScript: r,
|
|
176
|
+
playerApiFactory: d,
|
|
177
|
+
children: u
|
|
178
|
+
}) => {
|
|
179
|
+
h.debug("PlayerContainer");
|
|
180
|
+
const n = i.useRef(e), o = i.useRef(void 0), [p, y] = i.useState();
|
|
181
|
+
i.useEffect(() => {
|
|
182
|
+
const c = new P(
|
|
183
|
+
s,
|
|
184
|
+
o,
|
|
185
|
+
t,
|
|
186
|
+
r,
|
|
187
|
+
d
|
|
188
|
+
);
|
|
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));
|
|
196
|
+
};
|
|
197
|
+
}, [s, t, r, d, a]);
|
|
198
|
+
const l = O(e);
|
|
199
|
+
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",
|
|
212
|
+
{
|
|
213
|
+
ref: a,
|
|
214
|
+
src: e,
|
|
215
|
+
style: { width: "100%", height: "100%" },
|
|
216
|
+
preload: "auto",
|
|
217
|
+
autoPlay: !0,
|
|
218
|
+
controls: !0
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
))
|
|
222
|
+
);
|
|
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);
|
|
227
|
+
m(this, "player");
|
|
228
|
+
m(this, "duration");
|
|
229
|
+
m(this, "currentTime");
|
|
230
|
+
this.player = t.current;
|
|
231
|
+
}
|
|
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
|
+
async attach() {
|
|
285
|
+
window.addEventListener("message", this.handleMessage);
|
|
286
|
+
}
|
|
287
|
+
async detach() {
|
|
288
|
+
window.removeEventListener("message", this.handleMessage);
|
|
289
|
+
}
|
|
290
|
+
async loadVideo(e) {
|
|
291
|
+
return new Promise((t, r) => {
|
|
292
|
+
this.duration = void 0, this.currentTime = void 0, this.player.onload = () => {
|
|
293
|
+
this.player.onload = null, t();
|
|
294
|
+
}, this.player.src = `https://embed.nicovideo.jp/watch/${e}?jsapi=1&playerId=1`;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
postMessage(e) {
|
|
298
|
+
var t;
|
|
299
|
+
(t = this.player.contentWindow) == null || t.postMessage(
|
|
300
|
+
{
|
|
301
|
+
...e,
|
|
302
|
+
playerId: "1",
|
|
303
|
+
sourceConnectorType: 1
|
|
304
|
+
},
|
|
305
|
+
D.origin
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
async play() {
|
|
309
|
+
this.postMessage({ eventName: "play" });
|
|
310
|
+
}
|
|
311
|
+
async pause() {
|
|
312
|
+
this.postMessage({ eventName: "pause" });
|
|
313
|
+
}
|
|
314
|
+
async setCurrentTime(e) {
|
|
315
|
+
this.postMessage({ eventName: "seek", data: { time: e * 1e3 } });
|
|
316
|
+
}
|
|
317
|
+
async setVolume(e) {
|
|
318
|
+
this.postMessage({
|
|
319
|
+
eventName: "volumeChange",
|
|
320
|
+
data: { volume: e }
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
async setMuted(e) {
|
|
324
|
+
this.postMessage({
|
|
325
|
+
eventName: "mute",
|
|
326
|
+
data: { mute: e }
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
async getDuration() {
|
|
330
|
+
return this.duration;
|
|
331
|
+
}
|
|
332
|
+
async getCurrentTime() {
|
|
333
|
+
return this.currentTime;
|
|
334
|
+
}
|
|
335
|
+
};
|
|
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",
|
|
348
|
+
{
|
|
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(
|
|
360
|
+
void 0
|
|
361
|
+
), ae = ({
|
|
362
|
+
children: s
|
|
363
|
+
}) => {
|
|
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 () => {
|
|
368
|
+
var l;
|
|
369
|
+
await ((l = a.current) == null ? void 0 : l.play());
|
|
370
|
+
}, []), r = i.useCallback(async () => {
|
|
371
|
+
var l;
|
|
372
|
+
await ((l = a.current) == null ? void 0 : l.pause());
|
|
373
|
+
}, []), 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));
|
|
379
|
+
}, []), n = i.useCallback(async (l) => {
|
|
380
|
+
var c;
|
|
381
|
+
await ((c = a.current) == null ? void 0 : c.setMuted(l));
|
|
382
|
+
}, []), o = i.useCallback(async () => {
|
|
383
|
+
var l;
|
|
384
|
+
return await ((l = a.current) == null ? void 0 : l.getDuration());
|
|
385
|
+
}, []), p = i.useCallback(async () => {
|
|
386
|
+
var l;
|
|
387
|
+
return await ((l = a.current) == null ? void 0 : l.getCurrentTime());
|
|
388
|
+
}, []), y = i.useMemo(
|
|
389
|
+
() => ({
|
|
390
|
+
playerApiRef: a,
|
|
391
|
+
loadVideo: e,
|
|
392
|
+
play: t,
|
|
393
|
+
pause: r,
|
|
394
|
+
setCurrentTime: d,
|
|
395
|
+
setVolume: u,
|
|
396
|
+
setMuted: n,
|
|
397
|
+
getDuration: o,
|
|
398
|
+
getCurrentTime: p
|
|
399
|
+
}),
|
|
400
|
+
[
|
|
401
|
+
e,
|
|
402
|
+
t,
|
|
403
|
+
r,
|
|
404
|
+
d,
|
|
405
|
+
u,
|
|
406
|
+
n,
|
|
407
|
+
o,
|
|
408
|
+
p
|
|
409
|
+
]
|
|
410
|
+
);
|
|
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);
|
|
416
|
+
m(this, "player");
|
|
417
|
+
this.player = SC.Widget(this.playerElementRef.current);
|
|
418
|
+
}
|
|
419
|
+
static playerGetDurationAsync(e) {
|
|
420
|
+
return new Promise((t, r) => {
|
|
421
|
+
e.getDuration(t);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
attach(e) {
|
|
425
|
+
return new Promise((t, r) => {
|
|
426
|
+
this.player.bind(SC.Widget.Events.READY, () => {
|
|
427
|
+
var d, u;
|
|
428
|
+
this.player.bind(
|
|
429
|
+
SC.Widget.Events.PLAY_PROGRESS,
|
|
430
|
+
async (n) => {
|
|
431
|
+
var p, y;
|
|
432
|
+
const o = await v.playerGetDurationAsync(
|
|
433
|
+
this.player
|
|
434
|
+
);
|
|
435
|
+
(y = (p = this.options) == null ? void 0 : p.onTimeUpdate) == null || y.call(p, {
|
|
436
|
+
duration: o / 1e3,
|
|
437
|
+
percent: n.currentPosition / o,
|
|
438
|
+
seconds: n.currentPosition / 1e3
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
), this.player.bind(
|
|
442
|
+
SC.Widget.Events.ERROR,
|
|
443
|
+
(n) => {
|
|
444
|
+
var o, p;
|
|
445
|
+
return (p = (o = this.options) == null ? void 0 : o.onError) == null ? void 0 : p.call(o, n);
|
|
446
|
+
}
|
|
447
|
+
), this.player.bind(
|
|
448
|
+
SC.Widget.Events.PLAY,
|
|
449
|
+
() => {
|
|
450
|
+
var n, o;
|
|
451
|
+
return (o = (n = this.options) == null ? void 0 : n.onPlay) == null ? void 0 : o.call(n);
|
|
452
|
+
}
|
|
453
|
+
), this.player.bind(
|
|
454
|
+
SC.Widget.Events.PAUSE,
|
|
455
|
+
() => {
|
|
456
|
+
var n, o;
|
|
457
|
+
return (o = (n = this.options) == null ? void 0 : n.onPause) == null ? void 0 : o.call(n);
|
|
458
|
+
}
|
|
459
|
+
), this.player.bind(
|
|
460
|
+
SC.Widget.Events.FINISH,
|
|
461
|
+
() => {
|
|
462
|
+
var n, o;
|
|
463
|
+
return (o = (n = this.options) == null ? void 0 : n.onEnded) == null ? void 0 : o.call(n);
|
|
464
|
+
}
|
|
465
|
+
), (u = (d = this.options) == null ? void 0 : d.onLoaded) == null || u.call(d, { id: e }), t();
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
async detach() {
|
|
470
|
+
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
|
+
}
|
|
472
|
+
static playerLoadAsync(e, t, r) {
|
|
473
|
+
return new Promise((d, u) => {
|
|
474
|
+
e.load(t, { ...r, callback: d });
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
async loadVideo(e) {
|
|
478
|
+
var t, r;
|
|
479
|
+
await v.playerLoadAsync(this.player, e, {
|
|
480
|
+
auto_play: !0
|
|
481
|
+
}), (r = (t = this.options) == null ? void 0 : t.onLoaded) == null || r.call(t, { id: e });
|
|
482
|
+
}
|
|
483
|
+
async play() {
|
|
484
|
+
this.player.play();
|
|
485
|
+
}
|
|
486
|
+
async pause() {
|
|
487
|
+
this.player.pause();
|
|
488
|
+
}
|
|
489
|
+
async setCurrentTime(e) {
|
|
490
|
+
this.player.seekTo(e * 1e3);
|
|
491
|
+
}
|
|
492
|
+
async setVolume(e) {
|
|
493
|
+
this.player.setVolume(e * 100);
|
|
494
|
+
}
|
|
495
|
+
async setMuted(e) {
|
|
496
|
+
this.setVolume(e ? 0 : 1);
|
|
497
|
+
}
|
|
498
|
+
async getDuration() {
|
|
499
|
+
return await v.playerGetDurationAsync(
|
|
500
|
+
this.player
|
|
501
|
+
) / 1e3;
|
|
502
|
+
}
|
|
503
|
+
static playerGetPositionAsync(e) {
|
|
504
|
+
return new Promise((t, r) => {
|
|
505
|
+
e.getPosition(t);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
async getCurrentTime() {
|
|
509
|
+
return await v.playerGetPositionAsync(
|
|
510
|
+
this.player
|
|
511
|
+
) / 1e3;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
function J(s) {
|
|
515
|
+
return new Promise((a, e) => {
|
|
516
|
+
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());
|
|
520
|
+
}, document.head.appendChild(t);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
const U = [];
|
|
524
|
+
async function k(s) {
|
|
525
|
+
if (U.includes(s))
|
|
526
|
+
return h.debug(s, "script is already loaded"), !1;
|
|
527
|
+
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;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
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
|
+
}, []);
|
|
539
|
+
return /* @__PURE__ */ i.createElement(
|
|
540
|
+
E,
|
|
541
|
+
{
|
|
542
|
+
...s,
|
|
543
|
+
loadScript: a,
|
|
544
|
+
playerApiFactory: v
|
|
545
|
+
},
|
|
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
|
+
}
|
|
555
|
+
)
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
class Q extends b {
|
|
560
|
+
constructor(e, t, r) {
|
|
561
|
+
super(e, t, r);
|
|
562
|
+
m(this, "player");
|
|
563
|
+
this.player = new Vimeo.Player(this.playerElementRef.current);
|
|
564
|
+
}
|
|
565
|
+
async attach() {
|
|
566
|
+
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);
|
|
569
|
+
}), this.player.on(
|
|
570
|
+
"loaded",
|
|
571
|
+
(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() });
|
|
574
|
+
}
|
|
575
|
+
), this.player.on("play", () => {
|
|
576
|
+
var e, t;
|
|
577
|
+
return (t = (e = this.options) == null ? void 0 : e.onPlay) == null ? void 0 : t.call(e);
|
|
578
|
+
}), this.player.on("pause", () => {
|
|
579
|
+
var e, t;
|
|
580
|
+
return (t = (e = this.options) == null ? void 0 : e.onPause) == null ? void 0 : t.call(e);
|
|
581
|
+
}), this.player.on("ended", () => {
|
|
582
|
+
var e, t;
|
|
583
|
+
return (t = (e = this.options) == null ? void 0 : e.onEnded) == null ? void 0 : t.call(e);
|
|
584
|
+
}), this.player.on("timeupdate", (e) => {
|
|
585
|
+
var t, r;
|
|
586
|
+
(r = (t = this.options) == null ? void 0 : t.onTimeUpdate) == null || r.call(t, {
|
|
587
|
+
duration: e.duration,
|
|
588
|
+
percent: e.percent,
|
|
589
|
+
seconds: e.seconds
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
async detach() {
|
|
594
|
+
this.player.off("error"), this.player.off("loaded"), this.player.off("play"), this.player.off("pause"), this.player.off("ended"), this.player.off("timeupdate");
|
|
595
|
+
}
|
|
596
|
+
async loadVideo(e) {
|
|
597
|
+
await this.player.loadVideo(e);
|
|
598
|
+
}
|
|
599
|
+
async play() {
|
|
600
|
+
await this.player.play();
|
|
601
|
+
}
|
|
602
|
+
async pause() {
|
|
603
|
+
await this.player.pause();
|
|
604
|
+
}
|
|
605
|
+
async setCurrentTime(e) {
|
|
606
|
+
await this.player.setCurrentTime(e);
|
|
607
|
+
}
|
|
608
|
+
async setVolume(e) {
|
|
609
|
+
await this.player.setVolume(e);
|
|
610
|
+
}
|
|
611
|
+
async setMuted(e) {
|
|
612
|
+
await this.player.setMuted(e);
|
|
613
|
+
}
|
|
614
|
+
async getDuration() {
|
|
615
|
+
return await this.player.getDuration();
|
|
616
|
+
}
|
|
617
|
+
async getCurrentTime() {
|
|
618
|
+
return await this.player.getCurrentTime();
|
|
619
|
+
}
|
|
620
|
+
}
|
|
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
|
+
}, []);
|
|
627
|
+
return /* @__PURE__ */ i.createElement(
|
|
628
|
+
E,
|
|
629
|
+
{
|
|
630
|
+
...s,
|
|
631
|
+
loadScript: a,
|
|
632
|
+
playerApiFactory: Q
|
|
633
|
+
},
|
|
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
|
+
}
|
|
643
|
+
)
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
);
|
|
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);
|
|
651
|
+
m(this, "player");
|
|
652
|
+
m(this, "previousTime");
|
|
653
|
+
m(this, "timeUpdateIntervalId");
|
|
654
|
+
this.player = new YT.Player(this.playerElementRef.current, {
|
|
655
|
+
host: R.origin,
|
|
656
|
+
width: "100%",
|
|
657
|
+
height: "100%"
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
clearTimeUpdateInterval() {
|
|
661
|
+
this.logger.debug("clearTimeUpdateInterval", this.timeUpdateIntervalId), window.clearInterval(this.timeUpdateIntervalId), this.timeUpdateIntervalId = void 0;
|
|
662
|
+
}
|
|
663
|
+
invokeTimeUpdate(e) {
|
|
664
|
+
var d, u;
|
|
665
|
+
const t = e.getCurrentTime();
|
|
666
|
+
if (t === this.previousTime)
|
|
667
|
+
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,
|
|
672
|
+
seconds: t
|
|
673
|
+
}), this.previousTime = t;
|
|
674
|
+
}
|
|
675
|
+
setTimeUpdateInterval() {
|
|
676
|
+
this.logger.debug("setTimeUpdateInterval"), this.clearTimeUpdateInterval(), this.timeUpdateIntervalId = window.setInterval(
|
|
677
|
+
() => this.invokeTimeUpdate(this.player),
|
|
678
|
+
250
|
|
679
|
+
), this.logger.debug("timeUpdateIntervalId", this.timeUpdateIntervalId), this.invokeTimeUpdate(this.player);
|
|
680
|
+
}
|
|
681
|
+
attach(e) {
|
|
682
|
+
return new Promise((t, r) => {
|
|
683
|
+
this.player.addEventListener("onReady", async () => {
|
|
684
|
+
this.player.addEventListener(
|
|
685
|
+
"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);
|
|
689
|
+
}
|
|
690
|
+
), this.player.addEventListener(
|
|
691
|
+
"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) {
|
|
697
|
+
case YT.PlayerState.CUED:
|
|
698
|
+
(n = (u = this.options) == null ? void 0 : u.onLoaded) == null || n.call(u, { id: e });
|
|
699
|
+
break;
|
|
700
|
+
case YT.PlayerState.PLAYING:
|
|
701
|
+
(p = (o = this.options) == null ? void 0 : o.onPlay) == null || p.call(o), this.setTimeUpdateInterval();
|
|
702
|
+
break;
|
|
703
|
+
case YT.PlayerState.PAUSED:
|
|
704
|
+
(l = (y = this.options) == null ? void 0 : y.onPause) == null || l.call(y), this.clearTimeUpdateInterval();
|
|
705
|
+
break;
|
|
706
|
+
case YT.PlayerState.ENDED:
|
|
707
|
+
(w = (c = this.options) == null ? void 0 : c.onEnded) == null || w.call(c), this.clearTimeUpdateInterval();
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
), await this.loadVideo(e), t();
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
async detach() {
|
|
716
|
+
this.clearTimeUpdateInterval();
|
|
717
|
+
}
|
|
718
|
+
async loadVideo(e) {
|
|
719
|
+
this.previousTime = void 0, this.player.cueVideoById(e);
|
|
720
|
+
}
|
|
721
|
+
async play() {
|
|
722
|
+
this.player.playVideo();
|
|
723
|
+
}
|
|
724
|
+
async pause() {
|
|
725
|
+
this.player.pauseVideo();
|
|
726
|
+
}
|
|
727
|
+
async setCurrentTime(e) {
|
|
728
|
+
this.player.seekTo(e), this.invokeTimeUpdate(this.player);
|
|
729
|
+
}
|
|
730
|
+
async setVolume(e) {
|
|
731
|
+
this.player.setVolume(e * 100);
|
|
732
|
+
}
|
|
733
|
+
async setMuted(e) {
|
|
734
|
+
e ? this.player.mute() : this.player.unMute();
|
|
735
|
+
}
|
|
736
|
+
async getDuration() {
|
|
737
|
+
return this.player.getDuration();
|
|
738
|
+
}
|
|
739
|
+
async getCurrentTime() {
|
|
740
|
+
return this.player.getCurrentTime();
|
|
741
|
+
}
|
|
742
|
+
};
|
|
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"
|
|
751
|
+
) ? window.onYouTubeIframeAPIReady = () => {
|
|
752
|
+
h.debug("YouTube iframe API ready"), e();
|
|
753
|
+
} : e();
|
|
754
|
+
}), []);
|
|
755
|
+
return /* @__PURE__ */ i.createElement(
|
|
756
|
+
E,
|
|
757
|
+
{
|
|
758
|
+
...s,
|
|
759
|
+
loadScript: a,
|
|
760
|
+
playerApiFactory: A
|
|
761
|
+
},
|
|
762
|
+
(e) => /* @__PURE__ */ i.createElement("div", { style: { width: "100%", height: "100%" } }, /* @__PURE__ */ i.createElement("div", { ref: e }))
|
|
763
|
+
);
|
|
764
|
+
}
|
|
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];
|
|
775
|
+
return /* @__PURE__ */ i.createElement(
|
|
776
|
+
r,
|
|
777
|
+
{
|
|
778
|
+
type: s,
|
|
779
|
+
playerApiRef: t.playerApiRef,
|
|
780
|
+
videoId: a,
|
|
781
|
+
options: e
|
|
782
|
+
}
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
);
|
|
786
|
+
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
|
|
801
|
+
};
|
|
802
|
+
//# sourceMappingURL=index.es.js.map
|