@lucaismyname/ginger 0.0.28 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +6 -0
  2. package/dist/client.cjs +1 -1
  3. package/dist/client.js +37 -28
  4. package/dist/components/controls/Controls.d.ts +1 -1
  5. package/dist/components/controls/Controls.d.ts.map +1 -1
  6. package/dist/components/icons/Pause.d.ts.map +1 -1
  7. package/dist/components/icons/Play.d.ts.map +1 -1
  8. package/dist/components/icons/RepeatGlyph.d.ts +5 -0
  9. package/dist/components/icons/RepeatGlyph.d.ts.map +1 -0
  10. package/dist/components/icons/ShuffleIcon.d.ts +2 -0
  11. package/dist/components/icons/ShuffleIcon.d.ts.map +1 -0
  12. package/dist/components/icons/SkipBack.d.ts +2 -0
  13. package/dist/components/icons/SkipBack.d.ts.map +1 -0
  14. package/dist/components/icons/SkipForward.d.ts +2 -0
  15. package/dist/components/icons/SkipForward.d.ts.map +1 -0
  16. package/dist/components/icons/Volume2.d.ts +2 -0
  17. package/dist/components/icons/Volume2.d.ts.map +1 -0
  18. package/dist/components/icons/VolumeX.d.ts +2 -0
  19. package/dist/components/icons/VolumeX.d.ts.map +1 -0
  20. package/dist/components/icons/Wrapper.d.ts.map +1 -1
  21. package/dist/components/icons/index.d.ts +11 -0
  22. package/dist/components/icons/index.d.ts.map +1 -0
  23. package/dist/ginger-B26HM2Ja.cjs +2 -0
  24. package/dist/ginger-B26HM2Ja.cjs.map +1 -0
  25. package/dist/ginger-DlNYfHbV.js +2278 -0
  26. package/dist/ginger-DlNYfHbV.js.map +1 -0
  27. package/dist/ginger.d.ts +12 -0
  28. package/dist/ginger.d.ts.map +1 -1
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +37 -28
  33. package/dist/testing/index.cjs +1 -1
  34. package/dist/testing/index.js +1 -1
  35. package/dist/{useNextTrackPrefetch-Mj8dQLYR.js → useNextTrackPrefetch-Y_fs2JEx.js} +51 -51
  36. package/dist/{useNextTrackPrefetch-Mj8dQLYR.js.map → useNextTrackPrefetch-Y_fs2JEx.js.map} +1 -1
  37. package/dist/{useNextTrackPrefetch-CtZp7EgH.cjs → useNextTrackPrefetch-wSILz6TL.cjs} +2 -2
  38. package/dist/{useNextTrackPrefetch-CtZp7EgH.cjs.map → useNextTrackPrefetch-wSILz6TL.cjs.map} +1 -1
  39. package/package.json +1 -1
  40. package/dist/ginger-CVwaVLpC.cjs +0 -2
  41. package/dist/ginger-CVwaVLpC.cjs.map +0 -1
  42. package/dist/ginger-G5-3BYSb.js +0 -2165
  43. package/dist/ginger-G5-3BYSb.js.map +0 -1
@@ -1,2165 +0,0 @@
1
- import { jsx as d, jsxs as W, Fragment as Cr } from "react/jsx-runtime";
2
- import { useContext as Le, createContext as we, useRef as O, useState as Dr, useEffect as P, useMemo as S, useReducer as Fr, useCallback as M, Children as Ur, isValidElement as Vr, cloneElement as Br } from "react";
3
- import { b as G, u as K, g as je, c as E, G as $r, d as Or } from "./GingerSplitContexts-BzBExb95.js";
4
- const He = we(null);
5
- function Yr() {
6
- const e = Le(He);
7
- if (!e) throw new Error("Ginger components must be used within <Ginger.Provider>");
8
- return e;
9
- }
10
- function Ye(e) {
11
- const { buffered: r, duration: n } = e;
12
- return !(n > 0) || r.length === 0 ? 0 : Math.min(1, r.end(r.length - 1) / n);
13
- }
14
- function Qr({
15
- className: e,
16
- style: r,
17
- preload: n = "metadata",
18
- crossOrigin: a,
19
- respectReducedMotion: t = !1
20
- }) {
21
- var x;
22
- const { audioRef: i, dispatch: o, state: u, notifyEnded: c } = Yr(), s = ((x = u.tracks[u.currentIndex]) == null ? void 0 : x.fileUrl) ?? "", p = O({
23
- currentTime: -1,
24
- duration: -1,
25
- bufferedFraction: -1
26
- }), m = O(""), [v, h] = Dr(!1);
27
- P(() => {
28
- if (!t || typeof window > "u") return;
29
- const g = window.matchMedia("(prefers-reduced-motion: reduce)"), I = () => h(g.matches);
30
- return I(), g.addEventListener("change", I), () => g.removeEventListener("change", I);
31
- }, [t]);
32
- const b = (g, I = !1) => {
33
- const _ = {
34
- currentTime: g.currentTime,
35
- duration: g.duration,
36
- bufferedFraction: Ye(g)
37
- }, w = p.current, Z = v ? 0.5 : 0.25, ee = Math.abs(_.currentTime - w.currentTime) >= Z || Math.abs(_.duration - w.duration) >= 0.01 || Math.abs(_.bufferedFraction - w.bufferedFraction) >= 0.01;
38
- !I && !ee || (p.current = _, o({
39
- type: "MEDIA_TIME_UPDATE",
40
- payload: _
41
- }));
42
- };
43
- return P(() => {
44
- const g = i.current;
45
- g && (g.volume = u.volume, g.muted = u.muted);
46
- }, [i, u.volume, u.muted]), P(() => {
47
- const g = i.current;
48
- if (g) {
49
- if (!s) {
50
- g.removeAttribute("src"), p.current = { currentTime: -1, duration: -1, bufferedFraction: -1 }, m.current !== "" && o({ type: "MEDIA_SOURCE_CLEARED" }), m.current = "";
51
- return;
52
- }
53
- g.getAttribute("src") !== s && (g.src = s, g.load(), p.current = { currentTime: -1, duration: -1, bufferedFraction: -1 }), m.current = s;
54
- }
55
- }, [i, o, u.currentIndex, u.tracks, s]), P(() => {
56
- const g = i.current;
57
- g && (g.playbackRate = u.playbackRate);
58
- }, [i, u.playbackRate, s]), /* @__PURE__ */ d(
59
- "audio",
60
- {
61
- "data-ginger-component": "Player",
62
- ref: i,
63
- className: e,
64
- style: r,
65
- preload: n,
66
- crossOrigin: a,
67
- controls: !1,
68
- playsInline: !0,
69
- onTimeUpdate: (g) => {
70
- b(g.currentTarget);
71
- },
72
- onLoadedMetadata: (g) => {
73
- const I = g.currentTarget;
74
- p.current = { currentTime: -1, duration: -1, bufferedFraction: -1 }, o({
75
- type: "MEDIA_LOADED_METADATA",
76
- payload: {
77
- duration: I.duration,
78
- bufferedFraction: Ye(I)
79
- }
80
- });
81
- },
82
- onSeeking: (g) => b(g.currentTarget, !0),
83
- onSeeked: (g) => b(g.currentTarget, !0),
84
- onEnded: () => c(),
85
- onPlay: () => o({ type: "MEDIA_PLAY" }),
86
- onPause: () => o({ type: "MEDIA_PAUSE" }),
87
- onWaiting: () => o({ type: "MEDIA_WAITING" }),
88
- onCanPlay: () => o({ type: "MEDIA_CANPLAY" }),
89
- onProgress: (g) => b(g.currentTarget, !0),
90
- onVolumeChange: (g) => {
91
- const I = g.currentTarget;
92
- o({
93
- type: "MEDIA_VOLUME_SYNC",
94
- payload: { volume: I.volume, muted: I.muted }
95
- });
96
- },
97
- onError: () => {
98
- var w;
99
- const g = i.current, I = (w = g == null ? void 0 : g.error) == null ? void 0 : w.code;
100
- o({ type: "MEDIA_ERROR", payload: { message: I === 1 ? "MEDIA_ERR_ABORTED" : I === 2 ? "MEDIA_ERR_NETWORK" : I === 3 ? "MEDIA_ERR_DECODE" : I === 4 ? "MEDIA_ERR_SRC_NOT_SUPPORTED" : "MEDIA_ERR_UNKNOWN" } });
101
- }
102
- }
103
- );
104
- }
105
- const Se = {
106
- seek: "Seek",
107
- volume: "Volume",
108
- playbackSpeed: "Playback speed",
109
- chaptersList: "Chapters",
110
- syncedLyricsList: "Synced lyrics",
111
- nextTrack: "Next track",
112
- previousTrack: "Previous track",
113
- shuffle: "Shuffle",
114
- mute: "Mute",
115
- unmute: "Unmute",
116
- play: "Play",
117
- pause: "Pause",
118
- repeat: {
119
- off: "Repeat off",
120
- all: "Repeat all",
121
- one: "Repeat one"
122
- },
123
- playbackRateNormal: "1× normal",
124
- playbackRateTimes: (e) => `${e}×`
125
- };
126
- function jr(e) {
127
- return e ? {
128
- ...Se,
129
- ...e,
130
- repeat: { ...Se.repeat, ...e.repeat }
131
- } : Se;
132
- }
133
- const Ke = we(Se);
134
- function Hr({
135
- locale: e,
136
- children: r
137
- }) {
138
- const n = jr(e);
139
- return /* @__PURE__ */ d(Ke.Provider, { value: n, children: r });
140
- }
141
- function R() {
142
- return Le(Ke);
143
- }
144
- function z(e) {
145
- if (!Number.isFinite(e) || e < 0) return "0:00";
146
- const r = Math.floor(e % 60);
147
- return `${Math.floor(e / 60)}:${r.toString().padStart(2, "0")}`;
148
- }
149
- function A(e, r) {
150
- return r <= 0 ? 0 : Math.max(0, Math.min(r - 1, e));
151
- }
152
- function Xe(e, r) {
153
- if (e.length <= 1) return [...e];
154
- const n = e[r];
155
- if (!n) return [...e];
156
- const a = e.filter((t, i) => i !== r);
157
- for (let t = a.length - 1; t > 0; t--) {
158
- const i = Math.floor(Math.random() * (t + 1));
159
- [a[t], a[i]] = [a[i], a[t]];
160
- }
161
- return [n, ...a];
162
- }
163
- function q(e) {
164
- return e ? e.id != null && e.id !== "" ? `id:${e.id}` : `file:${e.fileUrl}` : "";
165
- }
166
- function Kr(e, r) {
167
- var o, u;
168
- if (!r) return 0;
169
- const n = e.findIndex((c) => c === r);
170
- if (n !== -1) return n;
171
- const a = q(r);
172
- if (!a) return 0;
173
- const t = [];
174
- for (let c = 0; c < e.length; c += 1)
175
- q(e[c]) === a && t.push(c);
176
- if (t.length === 0) return 0;
177
- if (t.length === 1) return t[0];
178
- const i = typeof globalThis < "u" && "process" in globalThis ? (u = (o = globalThis.process) == null ? void 0 : o.env) == null ? void 0 : u.NODE_ENV : void 0;
179
- return i != null && i !== "production" && console.warn(
180
- "[@lucaismyname/ginger] Ambiguous track identity: multiple queue rows share the same fileUrl without a unique `id`. Resolving to the first match."
181
- ), t[0];
182
- }
183
- function ze(e, r, n) {
184
- const a = [...e], t = Math.max(0, Math.min(a.length, n ?? a.length));
185
- return a.splice(t, 0, r), a;
186
- }
187
- function Xr(e, r) {
188
- if (r < 0 || r >= e.length) return [...e];
189
- const n = [...e];
190
- return n.splice(r, 1), n;
191
- }
192
- function zr(e, r, n) {
193
- if (r === n || r < 0 || r >= e.length || n < 0 || n >= e.length)
194
- return [...e];
195
- const a = [...e], [t] = a.splice(r, 1);
196
- return t ? (a.splice(n, 0, t), a) : [...e];
197
- }
198
- function Wr(e, r, n) {
199
- return ze(e, n, Math.max(0, Math.min(e.length, r + 1)));
200
- }
201
- function qr(e) {
202
- const { tracks: r, currentIndex: n, repeatMode: a, playbackMode: t } = e, i = r.length;
203
- return i === 0 ? { kind: "stop", nextIndex: 0 } : a === "one" ? { kind: "replay_same" } : t === "single" ? { kind: "stop", nextIndex: A(n, i) } : n < i - 1 ? { kind: "advance", nextIndex: n + 1 } : a === "all" ? { kind: "wrap", nextIndex: 0 } : { kind: "stop", nextIndex: A(n, i) };
204
- }
205
- function Jr(e) {
206
- const { tracks: r, currentIndex: n, repeatMode: a, playbackMode: t } = e, i = r.length;
207
- return i === 0 ? 0 : t === "single" ? A(n, i) : n < i - 1 ? n + 1 : a === "all" ? 0 : A(n, i);
208
- }
209
- function Zr(e) {
210
- const { tracks: r, currentIndex: n, repeatMode: a, playbackMode: t } = e, i = r.length;
211
- return i === 0 ? 0 : t === "single" ? A(n, i) : n > 0 ? n - 1 : a === "all" ? i - 1 : 0;
212
- }
213
- function en(e) {
214
- return e === "off" ? "all" : e === "all" ? "one" : "off";
215
- }
216
- function We(e, r) {
217
- return (e == null ? void 0 : e.artworkUrl) ?? r ?? void 0;
218
- }
219
- function rn(e, r) {
220
- return (e == null ? void 0 : e.album) ?? r ?? void 0;
221
- }
222
- function B(e) {
223
- return e.tracks[e.currentIndex] ?? null;
224
- }
225
- function qe(e) {
226
- return e.errorMessage ? "error" : e.tracks.length === 0 ? "idle" : e.isBuffering ? "loading" : e.isPaused ? Number.isFinite(e.duration) && e.duration > 0 && e.currentTime >= e.duration - 0.05 ? "ended" : "paused" : "playing";
227
- }
228
- function J(e) {
229
- var a;
230
- const r = e.duration;
231
- if (Number.isFinite(r) && r > 0) return r;
232
- const n = (a = e.tracks[e.currentIndex]) == null ? void 0 : a.durationSeconds;
233
- return typeof n == "number" && Number.isFinite(n) && n > 0 ? n : 0;
234
- }
235
- function nn(e) {
236
- const n = J(e) - e.currentTime;
237
- return Number.isFinite(n) ? Math.max(0, n) : 0;
238
- }
239
- function Je(e) {
240
- const r = J(e);
241
- return r > 0 ? Math.min(1, Math.max(0, e.currentTime / r)) : 0;
242
- }
243
- function tn(e) {
244
- var n;
245
- const r = B(e);
246
- return We(r, (n = e.playlistMeta) == null ? void 0 : n.artworkUrl);
247
- }
248
- function an(e) {
249
- var n;
250
- const r = B(e);
251
- return rn(r, (n = e.playlistMeta) == null ? void 0 : n.subtitle);
252
- }
253
- function on() {
254
- const e = G(), r = K(), n = R(), a = S(() => je(e, r), [e, r]), t = J(a), i = t > 0 ? a.currentTime : 0, o = Number.isFinite(i) ? i : 0, u = t > 0 ? `${z(o)} of ${z(t)}` : z(o), c = (s) => {
255
- r.seek(Number(s.currentTarget.value));
256
- };
257
- return {
258
- state: a,
259
- value: o,
260
- min: 0,
261
- max: t > 0 ? t : 1,
262
- step: "any",
263
- ariaValueText: u,
264
- ariaLabel: n.seek,
265
- onSeekInput: c,
266
- onSeekChange: c
267
- };
268
- }
269
- function un() {
270
- const e = G(), r = K(), n = R(), a = S(() => je(e, r), [e, r]), t = (i) => {
271
- r.setVolume(Number(i.currentTarget.value));
272
- };
273
- return {
274
- state: a,
275
- value: a.volume,
276
- min: 0,
277
- max: 1,
278
- step: "any",
279
- ariaValueText: `${Math.round(a.volume * 100)}%`,
280
- ariaLabel: n.volume,
281
- onVolumeInput: t,
282
- onVolumeChange: t
283
- };
284
- }
285
- function sn(e) {
286
- const r = G(), n = R(), a = (e == null ? void 0 : e.playAriaLabel) ?? n.play, t = (e == null ? void 0 : e.pauseAriaLabel) ?? n.pause;
287
- return {
288
- isPaused: r.isPaused,
289
- toggle: r.togglePlayPause,
290
- ariaLabel: r.isPaused ? a : t
291
- };
292
- }
293
- function Ze({
294
- playLabel: e = "Play",
295
- pauseLabel: r = "Pause",
296
- playAriaLabel: n,
297
- pauseAriaLabel: a,
298
- children: t,
299
- type: i = "button",
300
- onClick: o,
301
- ...u
302
- }) {
303
- const c = R(), s = typeof e == "string" ? e : c.play, p = typeof r == "string" ? r : c.pause, m = sn({
304
- playAriaLabel: n ?? s,
305
- pauseAriaLabel: a ?? p
306
- });
307
- return /* @__PURE__ */ d(
308
- "button",
309
- {
310
- "data-ginger-component": "PlayPause",
311
- ...u,
312
- type: i,
313
- "aria-label": m.ariaLabel,
314
- onClick: (v) => {
315
- m.toggle(), o == null || o(v);
316
- },
317
- children: t ?? (m.isPaused ? e : r)
318
- }
319
- );
320
- }
321
- Ze.displayName = "Ginger.Control.PlayPause";
322
- function er({
323
- type: e = "button",
324
- ariaLabel: r,
325
- onClick: n,
326
- children: a,
327
- ...t
328
- }) {
329
- const { repeatMode: i, cycleRepeat: o } = G(), c = R().repeat[i];
330
- return /* @__PURE__ */ d(
331
- "button",
332
- {
333
- "data-ginger-component": "Repeat",
334
- ...t,
335
- type: e,
336
- "aria-label": r ?? c,
337
- onClick: (s) => {
338
- o(), n == null || n(s);
339
- },
340
- children: a ?? c
341
- }
342
- );
343
- }
344
- er.displayName = "Ginger.Control.Repeat";
345
- function rr({
346
- type: e = "button",
347
- children: r = "Next",
348
- ariaLabel: n,
349
- onClick: a,
350
- ...t
351
- }) {
352
- const { next: i } = G(), o = R();
353
- return /* @__PURE__ */ d(
354
- "button",
355
- {
356
- "data-ginger-component": "Next",
357
- ...t,
358
- type: e,
359
- "aria-label": n ?? o.nextTrack,
360
- onClick: (u) => {
361
- i(), a == null || a(u);
362
- },
363
- children: r ?? o.nextTrack
364
- }
365
- );
366
- }
367
- rr.displayName = "Ginger.Control.Next";
368
- function nr({
369
- type: e = "button",
370
- children: r = "Previous",
371
- ariaLabel: n,
372
- onClick: a,
373
- ...t
374
- }) {
375
- const { prev: i } = G(), o = R();
376
- return /* @__PURE__ */ d(
377
- "button",
378
- {
379
- "data-ginger-component": "Previous",
380
- ...t,
381
- type: e,
382
- "aria-label": n ?? o.previousTrack,
383
- onClick: (u) => {
384
- i(), a == null || a(u);
385
- },
386
- children: r
387
- }
388
- );
389
- }
390
- nr.displayName = "Ginger.Control.Previous";
391
- function tr({
392
- type: e = "button",
393
- children: r = "Shuffle",
394
- ariaLabel: n,
395
- onClick: a,
396
- ...t
397
- }) {
398
- const { isShuffled: i, toggleShuffle: o } = G(), u = R();
399
- return /* @__PURE__ */ d(
400
- "button",
401
- {
402
- "data-ginger-component": "Shuffle",
403
- ...t,
404
- type: e,
405
- "aria-pressed": i,
406
- "aria-label": n ?? u.shuffle,
407
- onClick: (c) => {
408
- o(), a == null || a(c);
409
- },
410
- children: r ?? u.shuffle
411
- }
412
- );
413
- }
414
- tr.displayName = "Ginger.Control.Shuffle";
415
- function ar({
416
- inputStyle: e,
417
- style: r,
418
- unstyled: n = !1,
419
- ariaLabel: a,
420
- ...t
421
- }) {
422
- const i = on(), o = n ? { ...r, ...e } : { width: "100%", ...r, ...e };
423
- return /* @__PURE__ */ d(
424
- "input",
425
- {
426
- "data-ginger-component": "SeekBar",
427
- ...t,
428
- type: "range",
429
- min: i.min,
430
- max: i.max,
431
- step: i.step,
432
- value: i.value,
433
- "aria-label": a ?? i.ariaLabel,
434
- "aria-valuetext": i.ariaValueText,
435
- onInput: i.onSeekInput,
436
- onChange: i.onSeekChange,
437
- style: o
438
- }
439
- );
440
- }
441
- ar.displayName = "Ginger.Control.SeekBar";
442
- function ir({
443
- inputStyle: e,
444
- style: r,
445
- unstyled: n = !1,
446
- ariaLabel: a,
447
- ...t
448
- }) {
449
- const i = un(), o = n ? { ...r, ...e } : { width: "100%", ...r, ...e };
450
- return /* @__PURE__ */ d(
451
- "input",
452
- {
453
- "data-ginger-component": "Volume",
454
- ...t,
455
- type: "range",
456
- min: i.min,
457
- max: i.max,
458
- step: i.step,
459
- value: i.value,
460
- "aria-label": a ?? i.ariaLabel,
461
- "aria-valuetext": i.ariaValueText,
462
- onInput: i.onVolumeInput,
463
- onChange: i.onVolumeChange,
464
- style: o
465
- }
466
- );
467
- }
468
- ir.displayName = "Ginger.Control.Volume";
469
- function or({
470
- ariaLabel: e,
471
- muteLabel: r,
472
- unmuteLabel: n,
473
- type: a = "button",
474
- onClick: t,
475
- children: i,
476
- ...o
477
- }) {
478
- const { muted: u, toggleMute: c } = K(), s = R(), p = r ?? s.mute, m = n ?? s.unmute;
479
- return /* @__PURE__ */ d(
480
- "button",
481
- {
482
- "data-ginger-component": "Mute",
483
- ...o,
484
- type: a,
485
- "aria-pressed": u,
486
- "aria-label": e ?? (u ? s.unmute : s.mute),
487
- onClick: (v) => {
488
- c(), t == null || t(v);
489
- },
490
- children: i ?? (u ? m : p)
491
- }
492
- );
493
- }
494
- or.displayName = "Ginger.Control.Mute";
495
- const cn = [0.5, 0.75, 1, 1.25, 1.5, 2];
496
- function ur({
497
- rates: e = cn,
498
- style: r,
499
- ariaLabel: n,
500
- children: a,
501
- ...t
502
- }) {
503
- const { playbackRate: i, setPlaybackRate: o } = K(), u = R(), c = S(
504
- () => Array.from(/* @__PURE__ */ new Set([...e, i])).sort((s, p) => s - p),
505
- [e, i]
506
- );
507
- return /* @__PURE__ */ d(
508
- "select",
509
- {
510
- "data-ginger-component": "PlaybackRate",
511
- ...t,
512
- "aria-label": n ?? u.playbackSpeed,
513
- value: String(i),
514
- style: r,
515
- onChange: (s) => o(Number(s.currentTarget.value)),
516
- children: a ?? c.map((s) => /* @__PURE__ */ d("option", { value: String(s), children: s === 1 ? u.playbackRateNormal : u.playbackRateTimes(s) }, s))
517
- }
518
- );
519
- }
520
- ur.displayName = "Ginger.Control.PlaybackRate";
521
- function Y(e, r) {
522
- function n(a) {
523
- const t = E(), o = (r(t) ?? "").trim(), { className: u, style: c, fallback: s, empty: p, children: m } = a;
524
- if (!o) {
525
- const v = p ?? s ?? null;
526
- return v ? /* @__PURE__ */ d("span", { className: u, style: c, children: v }) : null;
527
- }
528
- return m ? /* @__PURE__ */ d("span", { className: u, style: c, children: m(o, t) }) : /* @__PURE__ */ d("span", { className: u, style: c, children: o });
529
- }
530
- return n.displayName = e, n;
531
- }
532
- function Q(e, r) {
533
- return Y(e, (n) => r(B(n)));
534
- }
535
- const ln = Q("Ginger.Current.Title", (e) => e == null ? void 0 : e.title), dn = Q("Ginger.Current.Artist", (e) => e == null ? void 0 : e.artist), fn = Y("Ginger.Current.Album", (e) => an(e)), gn = Q(
536
- "Ginger.Current.Description",
537
- (e) => e == null ? void 0 : e.description
538
- ), pn = Y("Ginger.Current.Copyright", (e) => {
539
- var n;
540
- const r = B(e);
541
- return (r == null ? void 0 : r.copyright) ?? ((n = e.playlistMeta) == null ? void 0 : n.copyright);
542
- }), mn = Q("Ginger.Current.Genre", (e) => e == null ? void 0 : e.genre), yn = Q("Ginger.Current.Label", (e) => e == null ? void 0 : e.label), hn = Q("Ginger.Current.Isrc", (e) => e == null ? void 0 : e.isrc), bn = Q(
543
- "Ginger.Current.TrackNumber",
544
- (e) => (e == null ? void 0 : e.trackNumber) != null ? String(e.trackNumber) : void 0
545
- );
546
- function sr({
547
- className: e,
548
- style: r,
549
- fallback: n,
550
- empty: a,
551
- children: t,
552
- format: i
553
- }) {
554
- var s;
555
- const o = E(), u = (s = B(o)) == null ? void 0 : s.year;
556
- if (typeof u != "number" || !Number.isFinite(u)) {
557
- const p = a ?? n ?? null;
558
- return p ? /* @__PURE__ */ d("span", { "data-ginger-component": "Year", className: e, style: r, children: p }) : null;
559
- }
560
- const c = i ? i(u) : String(u);
561
- return t ? /* @__PURE__ */ d("span", { "data-ginger-component": "Year", className: e, style: r, children: t(c, o) }) : /* @__PURE__ */ d("span", { "data-ginger-component": "Year", className: e, style: r, children: c });
562
- }
563
- sr.displayName = "Ginger.Current.Year";
564
- function cr({
565
- className: e,
566
- style: r,
567
- fallback: n,
568
- empty: a,
569
- children: t,
570
- preserveWhitespace: i = !0,
571
- unstyled: o = !1
572
- }) {
573
- var m;
574
- const u = E(), c = ((m = B(u)) == null ? void 0 : m.lyrics) ?? "", s = i ? c.replace(/^\s+|\s+$/g, "") : c.trim();
575
- if (!s) {
576
- const v = a ?? n ?? null;
577
- return v ? /* @__PURE__ */ d(
578
- "span",
579
- {
580
- "data-ginger-component": "Lyrics",
581
- className: e,
582
- style: r,
583
- children: v
584
- }
585
- ) : null;
586
- }
587
- const p = !o && i ? { whiteSpace: "pre-wrap" } : void 0;
588
- return t ? /* @__PURE__ */ d("span", { className: e, style: { ...p, ...r }, children: t(s, u) }) : /* @__PURE__ */ d("span", { className: e, style: { ...p, ...r }, children: s });
589
- }
590
- cr.displayName = "Ginger.Current.Lyrics";
591
- const Qe = /\[(\d{1,2}):(\d{2})(?:\.(\d{1,3}))?\]/g;
592
- function vn(e) {
593
- const r = [];
594
- for (const n of e.split(/\r?\n/)) {
595
- const a = [...n.matchAll(Qe)];
596
- if (a.length === 0) continue;
597
- const t = n.replace(Qe, "").trim();
598
- for (const i of a) {
599
- const o = Number(i[1] ?? 0), u = Number(i[2] ?? 0), c = Number((i[3] ?? "0").padEnd(3, "0")), s = o * 60 + u + c / 1e3;
600
- Number.isFinite(s) && s >= 0 && r.push({ time: s, text: t });
601
- }
602
- }
603
- return r.sort((n, a) => n.time - a.time);
604
- }
605
- function kn() {
606
- const { tracks: e, currentIndex: r } = G(), { currentTime: n } = K(), a = e[r], t = S(() => a ? Array.isArray(a.lyricsTimed) && a.lyricsTimed.length > 0 ? [...a.lyricsTimed].filter((o) => Number.isFinite(o.time) && o.time >= 0).sort((o, u) => o.time - u.time) : typeof a.lyrics == "string" ? vn(a.lyrics) : [] : [], [a]), i = S(() => {
607
- for (let o = t.length - 1; o >= 0; o -= 1)
608
- if (n >= t[o].time) return o;
609
- return -1;
610
- }, [n, t]);
611
- return {
612
- lines: t,
613
- activeIndex: i,
614
- activeLine: i >= 0 ? t[i] ?? null : null
615
- };
616
- }
617
- function lr({
618
- className: e,
619
- style: r,
620
- fallback: n,
621
- empty: a,
622
- unstyled: t = !1,
623
- activeClassName: i,
624
- lineClassName: o,
625
- children: u
626
- }) {
627
- const c = E(), s = R(), { lines: p, activeIndex: m } = kn();
628
- if (p.length === 0) {
629
- const h = a ?? n ?? null;
630
- return h ? /* @__PURE__ */ d(
631
- "span",
632
- {
633
- "data-ginger-component": "LyricsSynced",
634
- className: e,
635
- style: r,
636
- children: h
637
- }
638
- ) : null;
639
- }
640
- return /* @__PURE__ */ d(
641
- "ul",
642
- {
643
- className: e,
644
- style: { ...t ? {} : {
645
- listStyle: "none",
646
- margin: 0,
647
- padding: 0,
648
- fontFamily: "var(--ginger-font-family, system-ui, sans-serif)",
649
- fontSize: "var(--ginger-font-size, 14px)",
650
- color: "var(--ginger-primary-color, #111827)"
651
- }, ...r },
652
- "aria-label": s.syncedLyricsList,
653
- children: p.map((h, b) => {
654
- const x = b === m;
655
- return /* @__PURE__ */ d(
656
- "li",
657
- {
658
- "aria-current": x ? "true" : void 0,
659
- "data-ginger-active": x || void 0,
660
- className: [o, x ? i : void 0].filter(Boolean).join(" ") || void 0,
661
- style: t ? void 0 : {
662
- padding: "var(--ginger-playlist-row-padding, 4px 8px)",
663
- fontWeight: x ? 600 : 400,
664
- opacity: x ? 1 : 0.75
665
- },
666
- children: u ? u(h, b, x, c) : h.text
667
- },
668
- `${h.time}-${b}`
669
- );
670
- })
671
- }
672
- );
673
- }
674
- lr.displayName = "Ginger.Current.LyricsSynced";
675
- function Tn() {
676
- const { tracks: e, currentIndex: r } = G(), { currentTime: n, seek: a } = K(), t = S(() => {
677
- var u;
678
- return [...((u = e[r]) == null ? void 0 : u.chapters) ?? []].filter((c) => c && Number.isFinite(c.startSeconds) && c.startSeconds >= 0).sort((c, s) => c.startSeconds - s.startSeconds);
679
- }, [r, e]), i = S(() => {
680
- if (t.length === 0) return -1;
681
- for (let o = t.length - 1; o >= 0; o -= 1)
682
- if (n >= t[o].startSeconds) return o;
683
- return -1;
684
- }, [n, t]);
685
- return {
686
- list: t,
687
- activeIndex: i,
688
- active: i >= 0 ? t[i] ?? null : null,
689
- seekTo: (o) => {
690
- const u = t[o];
691
- u && a(u.startSeconds);
692
- }
693
- };
694
- }
695
- function dr({
696
- className: e,
697
- style: r,
698
- fallback: n,
699
- empty: a,
700
- unstyled: t = !1,
701
- formatStart: i = z,
702
- children: o
703
- }) {
704
- const u = E(), c = R(), { list: s, activeIndex: p, seekTo: m } = Tn();
705
- if (s.length === 0) {
706
- const h = a ?? n ?? null;
707
- return h ? /* @__PURE__ */ d(
708
- "span",
709
- {
710
- "data-ginger-component": "Chapters",
711
- className: e,
712
- style: r,
713
- children: h
714
- }
715
- ) : null;
716
- }
717
- return /* @__PURE__ */ d(
718
- "ul",
719
- {
720
- className: e,
721
- style: { ...t ? {} : {
722
- listStyle: "none",
723
- margin: 0,
724
- padding: 0,
725
- fontFamily: "var(--ginger-font-family, system-ui, sans-serif)",
726
- fontSize: "var(--ginger-font-size, 14px)",
727
- color: "var(--ginger-primary-color, #111827)"
728
- }, ...r },
729
- "aria-label": c.chaptersList,
730
- children: s.map((h, b) => {
731
- const x = b === p;
732
- return /* @__PURE__ */ d("li", { children: /* @__PURE__ */ d(
733
- "button",
734
- {
735
- type: "button",
736
- "aria-current": x ? "true" : void 0,
737
- "data-ginger-active": x || void 0,
738
- onClick: () => m(b),
739
- style: {
740
- width: t ? void 0 : "100%",
741
- textAlign: t ? void 0 : "left",
742
- border: t ? void 0 : "none",
743
- background: t ? void 0 : x ? "var(--ginger-playlist-active-bg, rgba(17, 24, 39, 0.06))" : "transparent",
744
- color: t ? void 0 : "inherit",
745
- font: t ? void 0 : "inherit",
746
- cursor: t ? void 0 : "pointer",
747
- padding: t ? void 0 : "var(--ginger-playlist-row-padding, 6px 8px)"
748
- },
749
- children: o ? o(h, b, x, u) : t ? /* @__PURE__ */ W(Cr, { children: [
750
- i(h.startSeconds),
751
- " ",
752
- h.title
753
- ] }) : /* @__PURE__ */ W("span", { children: [
754
- /* @__PURE__ */ d("span", { style: { opacity: 0.75, marginRight: "0.35em" }, children: i(h.startSeconds) }),
755
- h.title
756
- ] })
757
- }
758
- ) }, `${h.startSeconds}-${h.title}`);
759
- })
760
- }
761
- );
762
- }
763
- dr.displayName = "Ginger.Current.Chapters";
764
- function fr({
765
- visible: e = !1,
766
- className: r,
767
- style: n,
768
- fallback: a,
769
- empty: t,
770
- children: i
771
- }) {
772
- var c;
773
- const o = E();
774
- if (!e) return null;
775
- const u = ((c = B(o)) == null ? void 0 : c.fileUrl) ?? "";
776
- if (!u) {
777
- const s = t ?? a ?? null;
778
- return s ? /* @__PURE__ */ d("span", { className: r, style: n, children: s }) : null;
779
- }
780
- return i ? /* @__PURE__ */ d("span", { "data-ginger-component": "FileUrl", className: r, style: n, children: i(u, o) }) : /* @__PURE__ */ d("span", { className: r, style: n, children: u });
781
- }
782
- fr.displayName = "Ginger.Current.FileUrl";
783
- function gr({
784
- className: e,
785
- style: r,
786
- fallback: n,
787
- empty: a,
788
- sizes: t,
789
- loading: i,
790
- onError: o,
791
- decoding: u,
792
- unstyled: c = !1,
793
- imgStyle: s
794
- }) {
795
- const p = E(), m = B(p), v = tn(p);
796
- if (!v) {
797
- const b = a ?? n ?? null;
798
- return b ? /* @__PURE__ */ d(
799
- "span",
800
- {
801
- className: e,
802
- style: r,
803
- children: b
804
- }
805
- ) : null;
806
- }
807
- const h = [m == null ? void 0 : m.title, m == null ? void 0 : m.artist].filter(Boolean).join(" — ") || "Artwork";
808
- return /* @__PURE__ */ d(
809
- "div",
810
- {
811
- "data-ginger-component": "Artwork",
812
- className: e,
813
- style: c ? { ...r } : {
814
- background: "var(--ginger-artwork-bg, transparent)",
815
- borderRadius: "var(--ginger-artwork-radius, 0)",
816
- overflow: "hidden",
817
- ...r
818
- },
819
- children: /* @__PURE__ */ d(
820
- "img",
821
- {
822
- src: v,
823
- alt: h,
824
- sizes: t,
825
- loading: i,
826
- decoding: u,
827
- onError: o,
828
- style: {
829
- display: c ? void 0 : "block",
830
- width: c ? void 0 : "100%",
831
- height: c ? void 0 : "100%",
832
- objectFit: c ? void 0 : "cover",
833
- ...s
834
- }
835
- }
836
- )
837
- }
838
- );
839
- }
840
- gr.displayName = "Ginger.Current.Artwork";
841
- function pr({
842
- base: e = 0,
843
- className: r,
844
- style: n,
845
- fallback: a,
846
- empty: t,
847
- children: i
848
- }) {
849
- const o = E();
850
- if (o.tracks.length === 0) {
851
- const s = t ?? a ?? null;
852
- return s ? /* @__PURE__ */ d(
853
- "span",
854
- {
855
- "data-ginger-component": "QueueIndex",
856
- className: r,
857
- style: n,
858
- children: s
859
- }
860
- ) : null;
861
- }
862
- const c = String(o.currentIndex + e);
863
- return i ? /* @__PURE__ */ d(
864
- "span",
865
- {
866
- "data-ginger-component": "QueueIndex",
867
- className: r,
868
- style: n,
869
- children: i(c, o)
870
- }
871
- ) : /* @__PURE__ */ d(
872
- "span",
873
- {
874
- "data-ginger-component": "QueueIndex",
875
- className: r,
876
- style: n,
877
- children: c
878
- }
879
- );
880
- }
881
- pr.displayName = "Ginger.Current.QueueIndex";
882
- function mr({
883
- className: e,
884
- style: r,
885
- fallback: n,
886
- empty: a,
887
- children: t
888
- }) {
889
- const i = E(), o = String(i.tracks.length);
890
- if (i.tracks.length === 0) {
891
- const u = a ?? n ?? null;
892
- return u ? /* @__PURE__ */ d("span", { className: e, style: r, children: u }) : null;
893
- }
894
- return t ? /* @__PURE__ */ d(
895
- "span",
896
- {
897
- "data-ginger-component": "QueueLength",
898
- className: e,
899
- style: r,
900
- children: t(o, i)
901
- }
902
- ) : /* @__PURE__ */ d(
903
- "span",
904
- {
905
- "data-ginger-component": "QueueLength",
906
- className: e,
907
- style: r,
908
- children: o
909
- }
910
- );
911
- }
912
- mr.displayName = "Ginger.Current.QueueLength";
913
- function yr({
914
- base: e = 0,
915
- separator: r = " / ",
916
- className: n,
917
- style: a,
918
- fallback: t,
919
- empty: i,
920
- children: o
921
- }) {
922
- const u = E(), c = u.tracks.length;
923
- if (c === 0) {
924
- const v = i ?? t ?? null;
925
- return v ? /* @__PURE__ */ d("span", { className: n, style: a, children: v }) : null;
926
- }
927
- const s = String(u.currentIndex + e), p = String(c), m = `${s}${r}${p}`;
928
- return o ? /* @__PURE__ */ d(
929
- "span",
930
- {
931
- "data-ginger-component": "QueuePosition",
932
- className: n,
933
- style: a,
934
- children: o({ index: s, length: p, label: m }, u)
935
- }
936
- ) : /* @__PURE__ */ d(
937
- "span",
938
- {
939
- "data-ginger-component": "QueuePosition",
940
- className: n,
941
- style: a,
942
- children: m
943
- }
944
- );
945
- }
946
- yr.displayName = "Ginger.Current.QueuePosition";
947
- function Ce(e, r, n) {
948
- const {
949
- className: a,
950
- style: t,
951
- fallback: i,
952
- empty: o,
953
- children: u,
954
- format: c = z
955
- } = n;
956
- if (!(e >= 0) || !Number.isFinite(e)) {
957
- const p = o ?? i ?? null;
958
- return p ? /* @__PURE__ */ d(
959
- "span",
960
- {
961
- "data-ginger-component": "TimeText",
962
- className: a,
963
- style: t,
964
- children: p
965
- }
966
- ) : null;
967
- }
968
- const s = c(e);
969
- return u ? /* @__PURE__ */ d(
970
- "span",
971
- {
972
- "data-ginger-component": "TimeText",
973
- className: a,
974
- style: t,
975
- children: u(s, r)
976
- }
977
- ) : /* @__PURE__ */ d("span", { "data-ginger-component": "TimeText", className: a, style: t, children: s });
978
- }
979
- function hr(e) {
980
- const r = E();
981
- return Ce(r.currentTime, r, e);
982
- }
983
- hr.displayName = "Ginger.Current.Elapsed";
984
- function br(e) {
985
- const r = E();
986
- return Ce(J(r), r, e);
987
- }
988
- br.displayName = "Ginger.Current.Duration";
989
- function vr(e) {
990
- const r = E();
991
- return Ce(nn(r), r, e);
992
- }
993
- vr.displayName = "Ginger.Current.Remaining";
994
- function kr({
995
- className: e,
996
- style: r,
997
- fallback: n,
998
- empty: a,
999
- children: t
1000
- }) {
1001
- const i = E(), o = J(i), u = Je(i);
1002
- if (!(o > 0)) {
1003
- const c = a ?? n ?? null;
1004
- return c ? /* @__PURE__ */ d(
1005
- "span",
1006
- {
1007
- "data-ginger-component": "Progress",
1008
- className: e,
1009
- style: r,
1010
- children: c
1011
- }
1012
- ) : null;
1013
- }
1014
- return t ? /* @__PURE__ */ d(
1015
- "span",
1016
- {
1017
- "data-ginger-component": "Progress",
1018
- className: e,
1019
- style: r,
1020
- children: t(
1021
- { fraction: u, currentTime: i.currentTime, duration: o },
1022
- i
1023
- )
1024
- }
1025
- ) : /* @__PURE__ */ d("span", { "data-ginger-component": "Progress", className: e, style: r, children: `${Math.round(u * 100)}%` });
1026
- }
1027
- kr.displayName = "Ginger.Current.Progress";
1028
- function Tr({
1029
- className: e,
1030
- style: r,
1031
- height: n = 4,
1032
- showBuffered: a = !1,
1033
- unstyled: t = !1
1034
- }) {
1035
- const i = E(), o = `${Math.round(Je(i) * 100)}%`, u = `${Math.round(Math.min(1, Math.max(0, i.bufferedFraction)) * 100)}%`;
1036
- return /* @__PURE__ */ W(
1037
- "div",
1038
- {
1039
- "data-ginger-component": "TimeRail",
1040
- className: e,
1041
- style: t ? { ...r } : {
1042
- width: "100%",
1043
- height: n,
1044
- background: "var(--ginger-muted-color, #e5e7eb)",
1045
- borderRadius: 999,
1046
- overflow: "hidden",
1047
- position: "relative",
1048
- ...r
1049
- },
1050
- "aria-hidden": !0,
1051
- children: [
1052
- a ? /* @__PURE__ */ d(
1053
- "div",
1054
- {
1055
- "data-ginger-component": "TimeRail",
1056
- style: {
1057
- position: t ? void 0 : "absolute",
1058
- left: t ? void 0 : 0,
1059
- top: t ? void 0 : 0,
1060
- height: t ? void 0 : "100%",
1061
- width: u,
1062
- background: t ? void 0 : "var(--ginger-buffer-color, rgba(107, 114, 128, 0.35))"
1063
- }
1064
- }
1065
- ) : null,
1066
- /* @__PURE__ */ d(
1067
- "div",
1068
- {
1069
- "data-ginger-component": "TimeRail",
1070
- style: {
1071
- position: t ? void 0 : "relative",
1072
- width: o,
1073
- height: t ? void 0 : "100%",
1074
- background: t ? void 0 : "var(--ginger-primary-color, #111827)"
1075
- }
1076
- }
1077
- )
1078
- ]
1079
- }
1080
- );
1081
- }
1082
- Tr.displayName = "Ginger.Current.TimeRail";
1083
- function xr({
1084
- className: e,
1085
- style: r,
1086
- height: n = 4,
1087
- unstyled: a = !1
1088
- }) {
1089
- const t = E(), i = `${Math.round(Math.min(1, Math.max(0, t.bufferedFraction)) * 100)}%`;
1090
- return /* @__PURE__ */ d(
1091
- "div",
1092
- {
1093
- "data-ginger-component": "BufferRail",
1094
- className: e,
1095
- style: a ? { ...r } : {
1096
- width: "100%",
1097
- height: n,
1098
- background: "var(--ginger-muted-color, #e5e7eb)",
1099
- borderRadius: 999,
1100
- overflow: "hidden",
1101
- ...r
1102
- },
1103
- "aria-hidden": !0,
1104
- children: /* @__PURE__ */ d(
1105
- "div",
1106
- {
1107
- "data-ginger-component": "BufferRail",
1108
- style: {
1109
- width: i,
1110
- height: a ? void 0 : "100%",
1111
- background: a ? void 0 : "var(--ginger-buffer-color, rgba(107, 114, 128, 0.35))"
1112
- }
1113
- }
1114
- )
1115
- }
1116
- );
1117
- }
1118
- xr.displayName = "Ginger.Current.BufferRail";
1119
- function Mr({
1120
- className: e,
1121
- style: r,
1122
- fallback: n,
1123
- empty: a,
1124
- children: t
1125
- }) {
1126
- const i = E(), o = qe(i);
1127
- return t ? /* @__PURE__ */ d(
1128
- "span",
1129
- {
1130
- "data-ginger-component": "PlaybackState",
1131
- className: e,
1132
- style: r,
1133
- children: t(o, i)
1134
- }
1135
- ) : /* @__PURE__ */ d(
1136
- "span",
1137
- {
1138
- "data-ginger-component": "PlaybackState",
1139
- className: e,
1140
- style: r,
1141
- children: o
1142
- }
1143
- );
1144
- }
1145
- Mr.displayName = "Ginger.Current.PlaybackState";
1146
- function Ir({
1147
- className: e,
1148
- style: r,
1149
- fallback: n,
1150
- empty: a,
1151
- live: t = "polite",
1152
- children: i
1153
- }) {
1154
- const o = E(), u = o.errorMessage ?? "";
1155
- if (!u) {
1156
- const c = a ?? n ?? null;
1157
- return c ? /* @__PURE__ */ d(
1158
- "span",
1159
- {
1160
- "data-ginger-component": "ErrorMessage",
1161
- className: e,
1162
- style: r,
1163
- children: c
1164
- }
1165
- ) : null;
1166
- }
1167
- return i ? /* @__PURE__ */ d(
1168
- "span",
1169
- {
1170
- "data-ginger-component": "ErrorMessage",
1171
- className: e,
1172
- style: r,
1173
- "aria-live": t,
1174
- children: i(u, o)
1175
- }
1176
- ) : /* @__PURE__ */ d(
1177
- "span",
1178
- {
1179
- "data-ginger-component": "ErrorMessage",
1180
- className: e,
1181
- style: r,
1182
- "aria-live": t,
1183
- children: u
1184
- }
1185
- );
1186
- }
1187
- Ir.displayName = "Ginger.Current.ErrorMessage";
1188
- const Ne = we(null);
1189
- function xn() {
1190
- const e = Le(Ne);
1191
- if (!e)
1192
- throw new Error("Ginger.Playlist.Track must be used inside <Ginger.Playlist>");
1193
- return e;
1194
- }
1195
- function Er({
1196
- children: e,
1197
- unstyled: r = !1,
1198
- rowStyle: n,
1199
- renderTrack: a,
1200
- playOnSelect: t = !0,
1201
- style: i,
1202
- ...o
1203
- }) {
1204
- const { tracks: u, currentIndex: c, playTrackAt: s, selectTrackAt: p } = G(), m = r ? { ...i } : {
1205
- listStyle: "none",
1206
- margin: 0,
1207
- padding: 0,
1208
- fontFamily: "var(--ginger-font-family, system-ui, sans-serif)",
1209
- fontSize: "var(--ginger-font-size, 14px)",
1210
- color: "var(--ginger-primary-color, #111827)",
1211
- ...i
1212
- };
1213
- return e !== void 0 ? /* @__PURE__ */ d(Ne.Provider, { value: { playOnSelect: t }, children: /* @__PURE__ */ d("ul", { style: m, ...o, children: e }) }) : /* @__PURE__ */ d(Ne.Provider, { value: { playOnSelect: t }, children: /* @__PURE__ */ d("ul", { "data-ginger-component": "Playlist", style: m, ...o, children: u.map((h, b) => {
1214
- const x = b === c;
1215
- return /* @__PURE__ */ d("li", { children: /* @__PURE__ */ d(
1216
- "button",
1217
- {
1218
- type: "button",
1219
- onClick: () => {
1220
- t ? s(b) : p(b);
1221
- },
1222
- style: {
1223
- width: r ? void 0 : "100%",
1224
- textAlign: r ? void 0 : "left",
1225
- border: r ? void 0 : "none",
1226
- background: r ? void 0 : x ? "var(--ginger-playlist-active-bg, rgba(17, 24, 39, 0.06))" : "transparent",
1227
- color: r ? void 0 : "inherit",
1228
- font: r ? void 0 : "inherit",
1229
- cursor: r ? void 0 : "pointer",
1230
- padding: r ? void 0 : "var(--ginger-playlist-row-padding, 6px 8px)",
1231
- ...n
1232
- },
1233
- children: a ? a(h, b, x) : /* @__PURE__ */ W("span", { children: [
1234
- h.title,
1235
- h.artist ? ` — ${h.artist}` : ""
1236
- ] })
1237
- }
1238
- ) }, `${b}-${q(h)}`);
1239
- }) }) });
1240
- }
1241
- Er.displayName = "Ginger.Playlist";
1242
- function Pr({
1243
- index: e,
1244
- unstyled: r = !1,
1245
- className: n,
1246
- style: a,
1247
- children: t,
1248
- liProps: i,
1249
- onClick: o,
1250
- ...u
1251
- }) {
1252
- const { playOnSelect: c } = xn(), { tracks: s, currentIndex: p, playTrackAt: m, selectTrackAt: v } = G(), h = e === p, b = s[e], x = b != null ? /* @__PURE__ */ W("span", { children: [
1253
- b.title,
1254
- b.artist ? ` — ${b.artist}` : ""
1255
- ] }) : null;
1256
- return /* @__PURE__ */ d("li", { ...i, children: /* @__PURE__ */ d(
1257
- "button",
1258
- {
1259
- type: "button",
1260
- "aria-current": h ? "true" : void 0,
1261
- "data-ginger-active": h || void 0,
1262
- className: n,
1263
- style: {
1264
- width: r ? void 0 : "100%",
1265
- textAlign: r ? void 0 : "left",
1266
- border: r ? void 0 : "none",
1267
- background: r ? void 0 : h ? "var(--ginger-playlist-active-bg, rgba(17, 24, 39, 0.06))" : "transparent",
1268
- color: r ? void 0 : "inherit",
1269
- font: r ? void 0 : "inherit",
1270
- cursor: r ? void 0 : "pointer",
1271
- padding: r ? void 0 : "var(--ginger-playlist-row-padding, 6px 8px)",
1272
- ...a
1273
- },
1274
- ...u,
1275
- onClick: (g) => {
1276
- o == null || o(g), !g.defaultPrevented && (c ? m(e) : v(e));
1277
- },
1278
- children: t ?? x
1279
- }
1280
- ) });
1281
- }
1282
- Pr.displayName = "Ginger.Playlist.Track";
1283
- const Mn = Object.assign(Er, {
1284
- Track: Pr
1285
- }), In = Y(
1286
- "Ginger.Queue.Title",
1287
- (e) => {
1288
- var r;
1289
- return (r = e.playlistMeta) == null ? void 0 : r.title;
1290
- }
1291
- ), En = Y(
1292
- "Ginger.Queue.Subtitle",
1293
- (e) => {
1294
- var r;
1295
- return (r = e.playlistMeta) == null ? void 0 : r.subtitle;
1296
- }
1297
- ), Pn = Y(
1298
- "Ginger.Queue.Description",
1299
- (e) => {
1300
- var r;
1301
- return (r = e.playlistMeta) == null ? void 0 : r.description;
1302
- }
1303
- ), Sn = Y(
1304
- "Ginger.Queue.Copyright",
1305
- (e) => {
1306
- var r;
1307
- return (r = e.playlistMeta) == null ? void 0 : r.copyright;
1308
- }
1309
- );
1310
- function Sr({
1311
- className: e,
1312
- style: r,
1313
- fallback: n,
1314
- empty: a,
1315
- unstyled: t = !1,
1316
- imgStyle: i
1317
- }) {
1318
- var s, p;
1319
- const o = E(), u = (s = o.playlistMeta) == null ? void 0 : s.artworkUrl;
1320
- if (!u) {
1321
- const m = a ?? n ?? null;
1322
- return m ? /* @__PURE__ */ d("span", { className: e, style: r, children: m }) : null;
1323
- }
1324
- const c = ((p = o.playlistMeta) == null ? void 0 : p.title) ?? "Playlist artwork";
1325
- return /* @__PURE__ */ d(
1326
- "span",
1327
- {
1328
- "data-ginger-component": "Artwork",
1329
- className: e,
1330
- style: t ? { ...r } : {
1331
- display: "inline-block",
1332
- background: "var(--ginger-artwork-bg, #f3f4f6)",
1333
- borderRadius: "var(--ginger-artwork-radius, 6px)",
1334
- overflow: "hidden",
1335
- ...r
1336
- },
1337
- children: /* @__PURE__ */ d(
1338
- "img",
1339
- {
1340
- src: u,
1341
- alt: c,
1342
- style: {
1343
- display: t ? void 0 : "block",
1344
- width: t ? void 0 : "100%",
1345
- height: t ? void 0 : "100%",
1346
- objectFit: t ? void 0 : "cover",
1347
- ...i
1348
- }
1349
- }
1350
- )
1351
- }
1352
- );
1353
- }
1354
- Sr.displayName = "Ginger.Queue.Artwork";
1355
- function Ae(e) {
1356
- return Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 1;
1357
- }
1358
- function De(e) {
1359
- return Number.isFinite(e) ? Math.min(4, Math.max(0.25, e)) : 1;
1360
- }
1361
- const V = {
1362
- currentTime: 0,
1363
- duration: 0,
1364
- bufferedFraction: 0,
1365
- isBuffering: !1,
1366
- errorMessage: null
1367
- }, An = {
1368
- ...V,
1369
- volume: 1,
1370
- muted: !1,
1371
- playbackRate: 1
1372
- };
1373
- function Ar(e) {
1374
- const r = [...e.tracks];
1375
- let n = A(e.currentIndex ?? 0, r.length), a = null, t = r;
1376
- return e.isShuffled && r.length > 1 && (a = [...r], t = Xe(r, n), n = 0), {
1377
- tracks: t,
1378
- currentIndex: n,
1379
- playbackMode: e.playbackMode ?? "playlist",
1380
- isPaused: e.isPaused ?? !0,
1381
- isShuffled: !!(e.isShuffled && t.length > 1),
1382
- repeatMode: e.repeatMode ?? "off",
1383
- originalTracks: a,
1384
- playlistMeta: e.playlistMeta ?? null,
1385
- ...An,
1386
- volume: Ae(e.volume ?? 1),
1387
- muted: e.muted ?? !1,
1388
- playbackRate: De(e.playbackRate ?? 1)
1389
- };
1390
- }
1391
- function Rn(e, r) {
1392
- switch (r.type) {
1393
- case "INIT": {
1394
- const {
1395
- tracks: n,
1396
- currentIndex: a,
1397
- playlistMeta: t,
1398
- isPaused: i,
1399
- isShuffled: o,
1400
- repeatMode: u,
1401
- playbackMode: c,
1402
- volume: s,
1403
- muted: p,
1404
- playbackRate: m
1405
- } = r.payload;
1406
- return Ar({
1407
- tracks: n,
1408
- currentIndex: a,
1409
- playlistMeta: t ?? null,
1410
- isPaused: i ?? !0,
1411
- isShuffled: o ?? !1,
1412
- repeatMode: u ?? "off",
1413
- playbackMode: c ?? "playlist",
1414
- volume: s,
1415
- muted: p,
1416
- playbackRate: m
1417
- });
1418
- }
1419
- case "SET_QUEUE": {
1420
- const { tracks: n, currentIndex: a } = r.payload, t = [...n], i = A(a ?? e.currentIndex, t.length);
1421
- return {
1422
- ...e,
1423
- tracks: t,
1424
- currentIndex: i,
1425
- isShuffled: !1,
1426
- originalTracks: null,
1427
- ...V
1428
- };
1429
- }
1430
- case "INSERT_TRACK": {
1431
- const n = r.payload.index ?? e.tracks.length, a = ze(e.tracks, r.payload.track, n);
1432
- if (r.payload.autoPlay) {
1433
- const i = A(n, a.length);
1434
- return {
1435
- ...e,
1436
- tracks: a,
1437
- currentIndex: i,
1438
- isShuffled: !1,
1439
- originalTracks: null,
1440
- isPaused: !1,
1441
- ...V
1442
- };
1443
- }
1444
- const t = n <= e.currentIndex ? e.currentIndex + 1 : e.currentIndex;
1445
- return {
1446
- ...e,
1447
- tracks: a,
1448
- isShuffled: !1,
1449
- originalTracks: null,
1450
- currentIndex: A(t, a.length)
1451
- };
1452
- }
1453
- case "REMOVE_TRACK": {
1454
- const n = r.payload.index, a = Xr(e.tracks, n), t = n < e.currentIndex ? e.currentIndex - 1 : n === e.currentIndex ? Math.min(e.currentIndex, Math.max(0, a.length - 1)) : e.currentIndex;
1455
- return {
1456
- ...e,
1457
- tracks: a,
1458
- isShuffled: !1,
1459
- originalTracks: null,
1460
- currentIndex: A(t, a.length),
1461
- ...n === e.currentIndex ? V : {}
1462
- };
1463
- }
1464
- case "MOVE_TRACK": {
1465
- const { fromIndex: n, toIndex: a } = r.payload, t = zr(e.tracks, n, a);
1466
- let i = e.currentIndex;
1467
- return e.currentIndex === n ? i = a : n < e.currentIndex && a >= e.currentIndex ? i -= 1 : n > e.currentIndex && a <= e.currentIndex && (i += 1), {
1468
- ...e,
1469
- tracks: t,
1470
- isShuffled: !1,
1471
- originalTracks: null,
1472
- currentIndex: A(i, t.length)
1473
- };
1474
- }
1475
- case "ADD_NEXT": {
1476
- const n = Wr(e.tracks, e.currentIndex, r.payload.track);
1477
- return {
1478
- ...e,
1479
- tracks: n,
1480
- isShuffled: !1,
1481
- originalTracks: null
1482
- };
1483
- }
1484
- case "SET_INDEX": {
1485
- const n = A(r.payload.index, e.tracks.length), a = r.payload.autoPlay, t = a === !0 ? !1 : a === !1 ? !0 : e.isPaused;
1486
- return {
1487
- ...e,
1488
- currentIndex: n,
1489
- ...V,
1490
- isPaused: t
1491
- };
1492
- }
1493
- case "PLAY":
1494
- return { ...e, isPaused: !1 };
1495
- case "PAUSE":
1496
- return { ...e, isPaused: !0 };
1497
- case "TOGGLE_PAUSE":
1498
- return { ...e, isPaused: !e.isPaused };
1499
- case "SET_REPEAT":
1500
- return { ...e, repeatMode: r.payload };
1501
- case "CYCLE_REPEAT":
1502
- return { ...e, repeatMode: en(e.repeatMode) };
1503
- case "TOGGLE_SHUFFLE": {
1504
- if (e.tracks.length <= 1) return { ...e, isShuffled: !1, originalTracks: null };
1505
- if (!e.isShuffled) {
1506
- const i = [...e.tracks], o = Xe(i, e.currentIndex);
1507
- return {
1508
- ...e,
1509
- isShuffled: !0,
1510
- originalTracks: i,
1511
- tracks: o,
1512
- currentIndex: 0
1513
- };
1514
- }
1515
- const n = e.originalTracks ? [...e.originalTracks] : [...e.tracks], a = e.tracks[e.currentIndex], t = Kr(n, a);
1516
- return {
1517
- ...e,
1518
- isShuffled: !1,
1519
- originalTracks: null,
1520
- tracks: n,
1521
- currentIndex: A(t, n.length)
1522
- };
1523
- }
1524
- case "NEXT": {
1525
- const n = Jr(e), a = n === e.currentIndex;
1526
- return {
1527
- ...e,
1528
- currentIndex: n,
1529
- ...a ? {} : V,
1530
- isPaused: a ? e.isPaused : !1
1531
- };
1532
- }
1533
- case "PREV": {
1534
- const n = Zr(e), a = n === e.currentIndex;
1535
- return {
1536
- ...e,
1537
- currentIndex: n,
1538
- ...a ? {} : V,
1539
- isPaused: a ? e.isPaused : !1
1540
- };
1541
- }
1542
- case "MEDIA_TIME_UPDATE":
1543
- return {
1544
- ...e,
1545
- currentTime: r.payload.currentTime,
1546
- duration: Number.isFinite(r.payload.duration) ? r.payload.duration : e.duration,
1547
- bufferedFraction: r.payload.bufferedFraction,
1548
- isBuffering: !1
1549
- };
1550
- case "MEDIA_LOADED_METADATA":
1551
- return {
1552
- ...e,
1553
- duration: Number.isFinite(r.payload.duration) ? r.payload.duration : e.duration,
1554
- bufferedFraction: r.payload.bufferedFraction,
1555
- errorMessage: null
1556
- };
1557
- case "SET_PLAYLIST_META":
1558
- return { ...e, playlistMeta: r.payload };
1559
- case "SET_PLAYBACK_MODE":
1560
- return { ...e, playbackMode: r.payload };
1561
- case "MEDIA_ERROR":
1562
- return {
1563
- ...e,
1564
- errorMessage: r.payload.message,
1565
- isPaused: !0,
1566
- isBuffering: !1
1567
- };
1568
- case "MEDIA_WAITING":
1569
- return { ...e, isBuffering: !0 };
1570
- case "MEDIA_CANPLAY":
1571
- return { ...e, isBuffering: !1, errorMessage: null };
1572
- case "MEDIA_PLAY":
1573
- return { ...e, isPaused: !1, isBuffering: !1 };
1574
- case "MEDIA_PAUSE":
1575
- return { ...e, isPaused: !0 };
1576
- case "RESET_MEDIA_TIMES":
1577
- return { ...e, currentTime: 0, duration: 0, bufferedFraction: 0 };
1578
- case "MEDIA_SOURCE_CLEARED":
1579
- return { ...e, ...V };
1580
- case "SET_VOLUME":
1581
- return { ...e, volume: Ae(r.payload) };
1582
- case "SET_MUTED":
1583
- return { ...e, muted: r.payload };
1584
- case "TOGGLE_MUTE":
1585
- return { ...e, muted: !e.muted };
1586
- case "SET_PLAYBACK_RATE":
1587
- return { ...e, playbackRate: De(r.payload) };
1588
- case "MEDIA_VOLUME_SYNC": {
1589
- const { volume: n, muted: a } = r.payload, t = Ae(n);
1590
- return t === e.volume && a === e.muted ? e : { ...e, volume: t, muted: a };
1591
- }
1592
- default:
1593
- return e;
1594
- }
1595
- }
1596
- function Ge() {
1597
- return typeof navigator > "u" || !("mediaSession" in navigator) ? null : navigator.mediaSession;
1598
- }
1599
- function _n(e, r, n) {
1600
- var c;
1601
- const a = r.tracks[r.currentIndex], t = a == null ? void 0 : a.title, i = a == null ? void 0 : a.artist, o = a == null ? void 0 : a.album, u = We(a, (c = r.playlistMeta) == null ? void 0 : c.artworkUrl);
1602
- P(() => {
1603
- const s = Ge();
1604
- !e || !s || (s.metadata = new MediaMetadata({
1605
- title: t ?? "Unknown track",
1606
- artist: i,
1607
- album: o,
1608
- artwork: u ? [{ src: u }] : void 0
1609
- }));
1610
- }, [e, t, i, o, u]), P(() => {
1611
- const s = Ge();
1612
- !e || !s || (s.playbackState = r.isPaused ? "paused" : "playing");
1613
- }, [e, r.isPaused]), P(() => {
1614
- const s = Ge();
1615
- if (!(!e || !s)) {
1616
- try {
1617
- s.setActionHandler("play", n.play), s.setActionHandler("pause", n.pause), s.setActionHandler("nexttrack", n.next), s.setActionHandler("previoustrack", n.prev), s.setActionHandler("seekto", (p) => {
1618
- typeof p.seekTime == "number" && Number.isFinite(p.seekTime) && n.seek(p.seekTime);
1619
- });
1620
- } catch {
1621
- }
1622
- return () => {
1623
- try {
1624
- s.setActionHandler("play", null), s.setActionHandler("pause", null), s.setActionHandler("nexttrack", null), s.setActionHandler("previoustrack", null), s.setActionHandler("seekto", null);
1625
- } catch {
1626
- }
1627
- };
1628
- }
1629
- }, [e, n]);
1630
- }
1631
- const Gn = {
1632
- "--ginger-primary-color": "#111827",
1633
- "--ginger-muted-color": "#6b7280",
1634
- "--ginger-font-size": "14px",
1635
- "--ginger-font-family": "system-ui, sans-serif",
1636
- "--ginger-playlist-row-padding": "6px 8px",
1637
- "--ginger-artwork-radius": "6px",
1638
- "--ginger-artwork-bg": "#f3f4f6",
1639
- "--ginger-playlist-active-bg": "rgba(17, 24, 39, 0.06)",
1640
- "--ginger-buffer-color": "rgba(107, 114, 128, 0.35)",
1641
- "--ginger-focus-ring": "0 0 0 2px rgba(59, 130, 246, 0.45)"
1642
- };
1643
- function Nn({
1644
- children: e,
1645
- initialTracks: r = [],
1646
- initialIndex: n = 0,
1647
- initialPlaylistMeta: a = null,
1648
- initialShuffle: t = !1,
1649
- initialRepeatMode: i = "off",
1650
- initialPlaybackMode: o = "playlist",
1651
- initialPaused: u = !0,
1652
- initialVolume: c = 1,
1653
- initialMuted: s = !1,
1654
- initialPlaybackRate: p = 1,
1655
- initialStateKey: m,
1656
- locale: v,
1657
- mediaSession: h = !1,
1658
- beforePlay: b,
1659
- onPlayBlocked: x,
1660
- persistence: g,
1661
- hydrateOnMount: I = !1,
1662
- resumeOnTrackChange: _ = !1,
1663
- unstyled: w = !1,
1664
- asChild: Z = !1,
1665
- className: ee,
1666
- style: Re,
1667
- onTrackChange: re,
1668
- onPlay: ne,
1669
- onPause: te,
1670
- onQueueEnd: ae,
1671
- onError: ie
1672
- }) {
1673
- var Oe;
1674
- const $ = O(null), [l, y] = Fr(
1675
- Rn,
1676
- void 0,
1677
- () => Ar({
1678
- tracks: r,
1679
- currentIndex: n,
1680
- playlistMeta: a,
1681
- isPaused: u,
1682
- isShuffled: t,
1683
- repeatMode: i,
1684
- playbackMode: o,
1685
- volume: c,
1686
- muted: s,
1687
- playbackRate: p
1688
- })
1689
- ), Fe = O(l), _e = O({
1690
- tracks: r,
1691
- currentIndex: n,
1692
- playlistMeta: a,
1693
- isPaused: u,
1694
- isShuffled: t,
1695
- repeatMode: i,
1696
- playbackMode: o,
1697
- volume: c,
1698
- muted: s,
1699
- playbackRate: p
1700
- });
1701
- _e.current = {
1702
- tracks: r,
1703
- currentIndex: n,
1704
- playlistMeta: a,
1705
- isPaused: u,
1706
- isShuffled: t,
1707
- repeatMode: i,
1708
- playbackMode: o,
1709
- volume: c,
1710
- muted: s,
1711
- playbackRate: p
1712
- };
1713
- const X = O(void 0);
1714
- P(() => {
1715
- if (m === void 0) {
1716
- X.current = void 0;
1717
- return;
1718
- }
1719
- if (X.current === void 0) {
1720
- X.current = m;
1721
- return;
1722
- }
1723
- if (X.current === m) return;
1724
- X.current = m;
1725
- const f = _e.current;
1726
- y({
1727
- type: "INIT",
1728
- payload: {
1729
- tracks: f.tracks,
1730
- currentIndex: f.currentIndex,
1731
- playlistMeta: f.playlistMeta,
1732
- isPaused: f.isPaused,
1733
- isShuffled: f.isShuffled,
1734
- repeatMode: f.repeatMode,
1735
- playbackMode: f.playbackMode,
1736
- volume: f.volume,
1737
- muted: f.muted,
1738
- playbackRate: f.playbackRate
1739
- }
1740
- });
1741
- }, [m, y]), P(() => {
1742
- Fe.current = l;
1743
- }, [l]);
1744
- const Ue = l.tracks[l.currentIndex] ?? null;
1745
- P(() => {
1746
- re == null || re(Ue, l.currentIndex);
1747
- }, [Ue, l.currentIndex, re]), P(() => {
1748
- l.errorMessage && (ie == null || ie(l.errorMessage));
1749
- }, [l.errorMessage, ie]);
1750
- const oe = O(void 0);
1751
- P(() => {
1752
- if (oe.current === void 0) {
1753
- oe.current = l.isPaused;
1754
- return;
1755
- }
1756
- oe.current !== l.isPaused && (l.isPaused ? te == null || te() : ne == null || ne()), oe.current = l.isPaused;
1757
- }, [l.isPaused, te, ne]);
1758
- const D = M(() => {
1759
- y({ type: "PLAY" });
1760
- }, []), F = M(() => {
1761
- var f;
1762
- y({ type: "PAUSE" }), (f = $.current) == null || f.pause();
1763
- }, []), ue = M(() => {
1764
- l.isPaused ? D() : F();
1765
- }, [F, D, l.isPaused]), U = M((f) => {
1766
- const k = $.current;
1767
- k && Number.isFinite(f) && (k.currentTime = Math.max(0, f));
1768
- }, []), se = M((f) => {
1769
- y({ type: "SET_VOLUME", payload: Ae(f) });
1770
- }, []), ce = M((f) => {
1771
- y({ type: "SET_MUTED", payload: f });
1772
- }, []), le = M(() => {
1773
- y({ type: "TOGGLE_MUTE" });
1774
- }, []), de = M((f) => {
1775
- y({ type: "SET_PLAYBACK_RATE", payload: De(f) });
1776
- }, []), j = M(() => {
1777
- y({ type: "NEXT" });
1778
- }, []), H = M(() => {
1779
- y({ type: "PREV" });
1780
- }, []), fe = M((f) => {
1781
- y({ type: "SET_REPEAT", payload: f });
1782
- }, []), ge = M(() => {
1783
- y({ type: "CYCLE_REPEAT" });
1784
- }, []), pe = M(() => {
1785
- y({ type: "TOGGLE_SHUFFLE" });
1786
- }, []), me = M((f, k) => {
1787
- y({ type: "SET_QUEUE", payload: { tracks: f, currentIndex: k } });
1788
- }, []), ye = M((f, k, T) => {
1789
- y({ type: "INSERT_TRACK", payload: { track: f, index: k, autoPlay: T } });
1790
- }, []), he = M((f) => {
1791
- y({ type: "REMOVE_TRACK", payload: { index: f } });
1792
- }, []), be = M((f, k) => {
1793
- y({ type: "MOVE_TRACK", payload: { fromIndex: f, toIndex: k } });
1794
- }, []), ve = M((f) => {
1795
- y({ type: "ADD_NEXT", payload: { track: f } });
1796
- }, []), ke = M((f) => {
1797
- y({ type: "SET_INDEX", payload: { index: f, autoPlay: !0 } });
1798
- }, []), Te = M((f) => {
1799
- y({ type: "SET_INDEX", payload: { index: f, autoPlay: !1 } });
1800
- }, []), xe = M((f) => {
1801
- y({ type: "SET_PLAYLIST_META", payload: f });
1802
- }, []), Me = M((f) => {
1803
- y({ type: "SET_PLAYBACK_MODE", payload: f });
1804
- }, []), Ie = M((f) => {
1805
- y({ type: "INIT", payload: f });
1806
- }, []);
1807
- P(() => {
1808
- if (!g || !I) return;
1809
- const f = g.get("ginger:volume"), k = g.get("ginger:muted"), T = g.get("ginger:playbackRate"), C = g.get("ginger:repeatMode"), Pe = g.get("ginger:currentIndex"), L = _e.current;
1810
- y({
1811
- type: "INIT",
1812
- payload: {
1813
- tracks: L.tracks,
1814
- playlistMeta: L.playlistMeta,
1815
- isPaused: L.isPaused,
1816
- isShuffled: L.isShuffled,
1817
- playbackMode: L.playbackMode,
1818
- currentIndex: typeof Pe == "number" ? Pe : L.currentIndex,
1819
- repeatMode: C === "off" || C === "all" || C === "one" ? C : L.repeatMode,
1820
- volume: typeof f == "number" ? f : L.volume,
1821
- muted: typeof k == "boolean" ? k : L.muted,
1822
- playbackRate: typeof T == "number" ? T : L.playbackRate
1823
- }
1824
- });
1825
- }, [I, g]), P(() => {
1826
- g && (g.set("ginger:volume", l.volume), g.set("ginger:muted", l.muted), g.set("ginger:playbackRate", l.playbackRate), g.set("ginger:repeatMode", l.repeatMode), g.set("ginger:currentIndex", l.currentIndex));
1827
- }, [
1828
- g,
1829
- l.volume,
1830
- l.muted,
1831
- l.playbackRate,
1832
- l.repeatMode,
1833
- l.currentIndex
1834
- ]), P(() => {
1835
- if (!g || !_) return;
1836
- const f = l.tracks[l.currentIndex];
1837
- if (!f) return;
1838
- const k = `ginger:resume:${q(f)}`, T = g.get(k);
1839
- typeof T == "number" && Number.isFinite(T) && U(T);
1840
- }, [g, _, l.currentIndex, l.tracks, U]), P(() => {
1841
- if (!g || !_) return;
1842
- const f = l.tracks[l.currentIndex];
1843
- if (!f || !(l.currentTime >= 0)) return;
1844
- const k = `ginger:resume:${q(f)}`, T = setTimeout(() => g.set(k, l.currentTime), 250);
1845
- return () => clearTimeout(T);
1846
- }, [g, _, l.currentIndex, l.tracks, l.currentTime]);
1847
- const Rr = (Oe = l.tracks[l.currentIndex]) == null ? void 0 : Oe.fileUrl;
1848
- P(() => {
1849
- const f = $.current;
1850
- if (!f) return;
1851
- if (l.isPaused) {
1852
- f.pause();
1853
- return;
1854
- }
1855
- let k = !1;
1856
- return (async () => {
1857
- if (b) {
1858
- let T = !1;
1859
- try {
1860
- T = await b();
1861
- } catch (C) {
1862
- const Pe = C instanceof Error ? C.message : "beforePlay rejected";
1863
- y({ type: "MEDIA_ERROR", payload: { message: Pe } });
1864
- return;
1865
- }
1866
- if (!T) {
1867
- k || (y({ type: "PAUSE" }), x == null || x());
1868
- return;
1869
- }
1870
- }
1871
- k || f.play().catch((T) => {
1872
- const C = T instanceof Error ? T.message : typeof T == "string" ? T : "Playback failed (e.g. autoplay blocked or unavailable source)";
1873
- y({ type: "MEDIA_ERROR", payload: { message: C } });
1874
- });
1875
- })(), () => {
1876
- k = !0;
1877
- };
1878
- }, [b, Rr, x, l.isPaused]);
1879
- const Ee = M(() => {
1880
- const f = qr(Fe.current);
1881
- if (f.kind === "replay_same") {
1882
- const T = $.current;
1883
- T && (T.currentTime = 0), y({ type: "PLAY" });
1884
- return;
1885
- }
1886
- if (f.kind === "stop") {
1887
- y({ type: "PAUSE" }), ae == null || ae();
1888
- return;
1889
- }
1890
- const k = f.nextIndex;
1891
- y({ type: "SET_INDEX", payload: { index: k, autoPlay: !0 } });
1892
- }, [ae]), _r = S(
1893
- () => ({ play: D, pause: F, next: j, prev: H, seek: U }),
1894
- [D, F, j, H, U]
1895
- );
1896
- _n(!!h, l, _r);
1897
- const Ve = v != null && v.seek && /[\u0590-\u08FF]/.test(v.seek) ? "rtl" : "ltr", Gr = S(
1898
- () => ({
1899
- state: l,
1900
- dispatch: y,
1901
- audioRef: $,
1902
- notifyEnded: Ee,
1903
- init: Ie,
1904
- play: D,
1905
- pause: F,
1906
- togglePlayPause: ue,
1907
- seek: U,
1908
- setVolume: se,
1909
- setMuted: ce,
1910
- toggleMute: le,
1911
- setPlaybackRate: de,
1912
- next: j,
1913
- prev: H,
1914
- setRepeatMode: fe,
1915
- cycleRepeat: ge,
1916
- toggleShuffle: pe,
1917
- setQueue: me,
1918
- insertTrackAt: ye,
1919
- removeTrackAt: he,
1920
- moveTrack: be,
1921
- enqueueNext: ve,
1922
- playTrackAt: ke,
1923
- selectTrackAt: Te,
1924
- setPlaylistMeta: xe,
1925
- setPlaybackMode: Me
1926
- }),
1927
- [
1928
- ge,
1929
- y,
1930
- Ie,
1931
- j,
1932
- Ee,
1933
- F,
1934
- D,
1935
- ke,
1936
- ye,
1937
- he,
1938
- be,
1939
- ve,
1940
- Te,
1941
- H,
1942
- U,
1943
- ce,
1944
- de,
1945
- me,
1946
- fe,
1947
- xe,
1948
- Me,
1949
- se,
1950
- l,
1951
- le,
1952
- ue,
1953
- pe
1954
- ]
1955
- ), Nr = S(
1956
- () => ({
1957
- tracks: l.tracks,
1958
- currentIndex: l.currentIndex,
1959
- isPaused: l.isPaused,
1960
- isShuffled: l.isShuffled,
1961
- repeatMode: l.repeatMode,
1962
- originalTracks: l.originalTracks,
1963
- playlistMeta: l.playlistMeta,
1964
- init: Ie,
1965
- play: D,
1966
- pause: F,
1967
- togglePlayPause: ue,
1968
- next: j,
1969
- prev: H,
1970
- setRepeatMode: fe,
1971
- cycleRepeat: ge,
1972
- toggleShuffle: pe,
1973
- playbackMode: l.playbackMode,
1974
- setQueue: me,
1975
- insertTrackAt: ye,
1976
- removeTrackAt: he,
1977
- moveTrack: be,
1978
- enqueueNext: ve,
1979
- playTrackAt: ke,
1980
- selectTrackAt: Te,
1981
- setPlaylistMeta: xe,
1982
- setPlaybackMode: Me,
1983
- dispatch: y
1984
- }),
1985
- [
1986
- l.tracks,
1987
- l.currentIndex,
1988
- l.isPaused,
1989
- l.isShuffled,
1990
- l.repeatMode,
1991
- l.playbackMode,
1992
- l.originalTracks,
1993
- l.playlistMeta,
1994
- Ie,
1995
- D,
1996
- F,
1997
- ue,
1998
- j,
1999
- H,
2000
- fe,
2001
- ge,
2002
- pe,
2003
- me,
2004
- ye,
2005
- he,
2006
- be,
2007
- ve,
2008
- ke,
2009
- Te,
2010
- xe,
2011
- Me,
2012
- y
2013
- ]
2014
- ), Lr = S(
2015
- () => ({
2016
- currentTime: l.currentTime,
2017
- duration: l.duration,
2018
- bufferedFraction: l.bufferedFraction,
2019
- isBuffering: l.isBuffering,
2020
- errorMessage: l.errorMessage,
2021
- volume: l.volume,
2022
- muted: l.muted,
2023
- playbackRate: l.playbackRate,
2024
- seek: U,
2025
- setVolume: se,
2026
- setMuted: ce,
2027
- toggleMute: le,
2028
- setPlaybackRate: de,
2029
- audioRef: $,
2030
- notifyEnded: Ee,
2031
- dispatch: y
2032
- }),
2033
- [
2034
- l.currentTime,
2035
- l.duration,
2036
- l.bufferedFraction,
2037
- l.isBuffering,
2038
- l.errorMessage,
2039
- l.volume,
2040
- l.muted,
2041
- l.playbackRate,
2042
- U,
2043
- se,
2044
- ce,
2045
- le,
2046
- de,
2047
- $,
2048
- Ee,
2049
- y
2050
- ]
2051
- ), Be = qe(l), $e = S(
2052
- () => w ? Re : { ...Gn, ...Re },
2053
- [Re, w]
2054
- ), N = S(
2055
- () => ({
2056
- className: ee,
2057
- style: $e,
2058
- "data-ginger-playback": Be,
2059
- dir: Ve
2060
- }),
2061
- [ee, $e, Be, Ve]
2062
- ), wr = S(() => {
2063
- if (!Z)
2064
- return /* @__PURE__ */ d(
2065
- "div",
2066
- {
2067
- className: N.className,
2068
- style: N.style,
2069
- "data-ginger-playback": N["data-ginger-playback"],
2070
- dir: N.dir,
2071
- children: e
2072
- }
2073
- );
2074
- const f = Ur.only(e);
2075
- if (!Vr(f))
2076
- throw new Error("Ginger.Provider asChild expects a single React element child.");
2077
- const k = f, T = k.props.style;
2078
- return Br(k, {
2079
- className: Ln(k.props.className, N.className),
2080
- style: T && typeof T == "object" ? { ...T, ...N.style } : N.style,
2081
- "data-ginger-playback": N["data-ginger-playback"],
2082
- dir: N.dir
2083
- });
2084
- }, [Z, e, N]);
2085
- return /* @__PURE__ */ d(Hr, { locale: v, children: /* @__PURE__ */ d($r.Provider, { value: Nr, children: /* @__PURE__ */ d(Or.Provider, { value: Lr, children: /* @__PURE__ */ d(He.Provider, { value: Gr, children: wr }) }) }) });
2086
- }
2087
- function Ln(e, r) {
2088
- const n = [e, r].filter(Boolean).join(" ");
2089
- return n === "" ? void 0 : n;
2090
- }
2091
- const Fn = {
2092
- Provider: Nn,
2093
- Player: Qr,
2094
- Current: {
2095
- Title: ln,
2096
- Artist: dn,
2097
- Album: fn,
2098
- Description: gn,
2099
- Copyright: pn,
2100
- Genre: mn,
2101
- Label: yn,
2102
- Isrc: hn,
2103
- TrackNumber: bn,
2104
- Year: sr,
2105
- Lyrics: cr,
2106
- LyricsSynced: lr,
2107
- Chapters: dr,
2108
- FileUrl: fr,
2109
- Artwork: gr,
2110
- QueueIndex: pr,
2111
- QueueLength: mr,
2112
- QueuePosition: yr,
2113
- Elapsed: hr,
2114
- Duration: br,
2115
- Remaining: vr,
2116
- Progress: kr,
2117
- TimeRail: Tr,
2118
- BufferRail: xr,
2119
- PlaybackState: Mr,
2120
- ErrorMessage: Ir
2121
- },
2122
- Queue: {
2123
- Title: In,
2124
- Subtitle: En,
2125
- Description: Pn,
2126
- Copyright: Sn,
2127
- Artwork: Sr
2128
- },
2129
- Control: {
2130
- PlayPause: Ze,
2131
- Repeat: er,
2132
- Next: rr,
2133
- Previous: nr,
2134
- Shuffle: tr,
2135
- SeekBar: ar,
2136
- Volume: ir,
2137
- Mute: or,
2138
- PlaybackRate: ur
2139
- },
2140
- Playlist: Mn
2141
- };
2142
- export {
2143
- dr as C,
2144
- Fn as G,
2145
- lr as L,
2146
- Ae as a,
2147
- qe as b,
2148
- De as c,
2149
- Se as d,
2150
- R as e,
2151
- kn as f,
2152
- sn as g,
2153
- on as h,
2154
- un as i,
2155
- tn as j,
2156
- Je as k,
2157
- nn as l,
2158
- J as m,
2159
- B as n,
2160
- Jr as o,
2161
- vn as p,
2162
- an as r,
2163
- Tn as u
2164
- };
2165
- //# sourceMappingURL=ginger-G5-3BYSb.js.map