@lucaismyname/ginger 0.0.15 → 0.0.20

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 (59) hide show
  1. package/README.md +113 -1
  2. package/dist/client.cjs +1 -1
  3. package/dist/client.js +31 -28
  4. package/dist/client.test.d.ts +2 -0
  5. package/dist/client.test.d.ts.map +1 -0
  6. package/dist/components/controls/Controls.d.ts +26 -13
  7. package/dist/components/controls/Controls.d.ts.map +1 -1
  8. package/dist/components/current/Chapters.d.ts +15 -0
  9. package/dist/components/current/Chapters.d.ts.map +1 -0
  10. package/dist/components/current/ChaptersLyricsSynced.test.d.ts +2 -0
  11. package/dist/components/current/ChaptersLyricsSynced.test.d.ts.map +1 -0
  12. package/dist/components/current/LyricsSynced.d.ts +16 -0
  13. package/dist/components/current/LyricsSynced.d.ts.map +1 -0
  14. package/dist/components/current/index.d.ts +4 -0
  15. package/dist/components/current/index.d.ts.map +1 -1
  16. package/dist/core/transitions.d.ts +5 -3
  17. package/dist/core/transitions.d.ts.map +1 -1
  18. package/dist/experimental-gapless/index.cjs.map +1 -1
  19. package/dist/experimental-gapless/index.d.ts +3 -1
  20. package/dist/experimental-gapless/index.d.ts.map +1 -1
  21. package/dist/experimental-gapless/index.js.map +1 -1
  22. package/dist/ginger-8x4WzVmw.js +1818 -0
  23. package/dist/ginger-8x4WzVmw.js.map +1 -0
  24. package/dist/ginger-CMbd3s8C.cjs +2 -0
  25. package/dist/ginger-CMbd3s8C.cjs.map +1 -0
  26. package/dist/ginger.d.ts +2 -0
  27. package/dist/ginger.d.ts.map +1 -1
  28. package/dist/hooks/useNextTrackPrefetch.d.ts +16 -0
  29. package/dist/hooks/useNextTrackPrefetch.d.ts.map +1 -0
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.d.ts +50 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +31 -28
  34. package/dist/testing/helpers.d.ts +29 -0
  35. package/dist/testing/helpers.d.ts.map +1 -1
  36. package/dist/testing/helpers.test.d.ts +2 -0
  37. package/dist/testing/helpers.test.d.ts.map +1 -0
  38. package/dist/testing/index.cjs +48 -43
  39. package/dist/testing/index.cjs.map +1 -1
  40. package/dist/testing/index.d.ts +1 -1
  41. package/dist/testing/index.d.ts.map +1 -1
  42. package/dist/testing/index.js +6888 -3749
  43. package/dist/testing/index.js.map +1 -1
  44. package/dist/testing/index.test.d.ts +2 -0
  45. package/dist/testing/index.test.d.ts.map +1 -0
  46. package/dist/testing/renderGinger.d.ts.map +1 -1
  47. package/dist/useNextTrackPrefetch-CFoUynDv.cjs +2 -0
  48. package/dist/useNextTrackPrefetch-CFoUynDv.cjs.map +1 -0
  49. package/dist/useNextTrackPrefetch-CV1khU0h.js +257 -0
  50. package/dist/useNextTrackPrefetch-CV1khU0h.js.map +1 -0
  51. package/package.json +9 -1
  52. package/dist/ginger-BTPRqWHs.js +0 -1621
  53. package/dist/ginger-BTPRqWHs.js.map +0 -1
  54. package/dist/ginger-BiI69vrn.cjs +0 -2
  55. package/dist/ginger-BiI69vrn.cjs.map +0 -1
  56. package/dist/useSeekDrag-Br1V0Vao.js +0 -290
  57. package/dist/useSeekDrag-Br1V0Vao.js.map +0 -1
  58. package/dist/useSeekDrag-aS7uk26h.cjs +0 -2
  59. package/dist/useSeekDrag-aS7uk26h.cjs.map +0 -1
@@ -1,1621 +0,0 @@
1
- import { jsx as s, jsxs as _e } from "react/jsx-runtime";
2
- import { useContext as Ge, createContext as Ne, useRef as $, useState as Sr, useEffect as I, useMemo as U, useReducer as _r, useCallback as b } from "react";
3
- import { c as x, b as w, u as Ee, g as Ve, G as Gr, d as Nr } from "./GingerSplitContexts-BzBExb95.js";
4
- const Oe = Ne(null);
5
- function wr() {
6
- const e = Ge(Oe);
7
- if (!e) throw new Error("Ginger components must be used within <Ginger.Provider>");
8
- return e;
9
- }
10
- function Ue(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 Dr({
15
- className: e,
16
- style: r,
17
- preload: n = "metadata",
18
- crossOrigin: a,
19
- respectReducedMotion: t = !1
20
- }) {
21
- var P;
22
- const { audioRef: i, dispatch: u, state: o, notifyEnded: c } = wr(), d = ((P = o.tracks[o.currentIndex]) == null ? void 0 : P.fileUrl) ?? "", g = $({
23
- currentTime: -1,
24
- duration: -1,
25
- bufferedFraction: -1
26
- }), m = $(""), [M, E] = Sr(!1);
27
- I(() => {
28
- if (!t || typeof window > "u") return;
29
- const p = window.matchMedia("(prefers-reduced-motion: reduce)"), T = () => E(p.matches);
30
- return T(), p.addEventListener("change", T), () => p.removeEventListener("change", T);
31
- }, [t]);
32
- const h = (p, T = !1) => {
33
- const R = {
34
- currentTime: p.currentTime,
35
- duration: p.duration,
36
- bufferedFraction: Ue(p)
37
- }, G = g.current, Ae = M ? 0.5 : 0.25, j = Math.abs(R.currentTime - G.currentTime) >= Ae || Math.abs(R.duration - G.duration) >= 0.01 || Math.abs(R.bufferedFraction - G.bufferedFraction) >= 0.01;
38
- !T && !j || (g.current = R, u({
39
- type: "MEDIA_TIME_UPDATE",
40
- payload: R
41
- }));
42
- };
43
- return I(() => {
44
- const p = i.current;
45
- p && (p.volume = o.volume, p.muted = o.muted, p.playbackRate = o.playbackRate);
46
- }, [i, o.volume, o.muted, o.playbackRate]), I(() => {
47
- const p = i.current;
48
- if (p) {
49
- if (!d) {
50
- p.removeAttribute("src"), g.current = { currentTime: -1, duration: -1, bufferedFraction: -1 }, m.current !== "" && u({ type: "MEDIA_SOURCE_CLEARED" }), m.current = "";
51
- return;
52
- }
53
- p.getAttribute("src") !== d && (p.src = d, p.load(), g.current = { currentTime: -1, duration: -1, bufferedFraction: -1 }), m.current = d;
54
- }
55
- }, [i, u, o.currentIndex, o.tracks, d]), /* @__PURE__ */ s(
56
- "audio",
57
- {
58
- ref: i,
59
- className: e,
60
- style: r,
61
- preload: n,
62
- crossOrigin: a,
63
- controls: !1,
64
- playsInline: !0,
65
- onTimeUpdate: (p) => {
66
- h(p.currentTarget);
67
- },
68
- onLoadedMetadata: (p) => {
69
- const T = p.currentTarget;
70
- g.current = { currentTime: -1, duration: -1, bufferedFraction: -1 }, u({
71
- type: "MEDIA_LOADED_METADATA",
72
- payload: {
73
- duration: T.duration,
74
- bufferedFraction: Ue(T)
75
- }
76
- });
77
- },
78
- onSeeking: (p) => h(p.currentTarget, !0),
79
- onSeeked: (p) => h(p.currentTarget, !0),
80
- onEnded: () => c(),
81
- onPlay: () => u({ type: "MEDIA_PLAY" }),
82
- onPause: () => u({ type: "MEDIA_PAUSE" }),
83
- onWaiting: () => u({ type: "MEDIA_WAITING" }),
84
- onCanPlay: () => u({ type: "MEDIA_CANPLAY" }),
85
- onProgress: (p) => h(p.currentTarget, !0),
86
- onVolumeChange: (p) => {
87
- const T = p.currentTarget;
88
- u({
89
- type: "MEDIA_VOLUME_SYNC",
90
- payload: { volume: T.volume, muted: T.muted }
91
- });
92
- },
93
- onError: () => {
94
- var G;
95
- const p = i.current, T = (G = p == null ? void 0 : p.error) == null ? void 0 : G.code;
96
- u({ type: "MEDIA_ERROR", payload: { message: T === 1 ? "MEDIA_ERR_ABORTED" : T === 2 ? "MEDIA_ERR_NETWORK" : T === 3 ? "MEDIA_ERR_DECODE" : T === 4 ? "MEDIA_ERR_SRC_NOT_SUPPORTED" : "MEDIA_ERR_UNKNOWN" } });
97
- }
98
- }
99
- );
100
- }
101
- function A(e, r) {
102
- return r <= 0 ? 0 : Math.max(0, Math.min(r - 1, e));
103
- }
104
- function $e(e, r) {
105
- if (e.length <= 1) return [...e];
106
- const n = e[r];
107
- if (!n) return [...e];
108
- const a = e.filter((t, i) => i !== r);
109
- for (let t = a.length - 1; t > 0; t--) {
110
- const i = Math.floor(Math.random() * (t + 1));
111
- [a[t], a[i]] = [a[i], a[t]];
112
- }
113
- return [n, ...a];
114
- }
115
- function X(e) {
116
- return e ? e.id != null && e.id !== "" ? `id:${e.id}` : `file:${e.fileUrl}` : "";
117
- }
118
- function Cr(e, r) {
119
- var u, o;
120
- if (!r) return 0;
121
- const n = e.findIndex((c) => c === r);
122
- if (n !== -1) return n;
123
- const a = X(r);
124
- if (!a) return 0;
125
- const t = [];
126
- for (let c = 0; c < e.length; c += 1)
127
- X(e[c]) === a && t.push(c);
128
- if (t.length === 0) return 0;
129
- if (t.length === 1) return t[0];
130
- const i = typeof globalThis < "u" && "process" in globalThis ? (o = (u = globalThis.process) == null ? void 0 : u.env) == null ? void 0 : o.NODE_ENV : void 0;
131
- return i != null && i !== "production" && console.warn(
132
- "[@lucaismyname/ginger] Ambiguous track identity: multiple queue rows share the same fileUrl without a unique `id`. Resolving to the first match."
133
- ), t[0];
134
- }
135
- function Be(e, r, n) {
136
- const a = [...e], t = Math.max(0, Math.min(a.length, n ?? a.length));
137
- return a.splice(t, 0, r), a;
138
- }
139
- function Lr(e, r) {
140
- if (r < 0 || r >= e.length) return [...e];
141
- const n = [...e];
142
- return n.splice(r, 1), n;
143
- }
144
- function Fr(e, r, n) {
145
- if (r === n || r < 0 || r >= e.length || n < 0 || n >= e.length)
146
- return [...e];
147
- const a = [...e], [t] = a.splice(r, 1);
148
- return t ? (a.splice(n, 0, t), a) : [...e];
149
- }
150
- function Ur(e, r, n) {
151
- return Be(e, n, Math.max(0, Math.min(e.length, r + 1)));
152
- }
153
- function Vr(e) {
154
- const { tracks: r, currentIndex: n, repeatMode: a, playbackMode: t } = e, i = r.length;
155
- 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) };
156
- }
157
- function Or(e) {
158
- const { tracks: r, currentIndex: n, repeatMode: a, playbackMode: t } = e, i = r.length;
159
- return i === 0 ? 0 : t === "single" ? A(n, i) : n < i - 1 ? n + 1 : a === "all" ? 0 : A(n, i);
160
- }
161
- function $r(e) {
162
- const { tracks: r, currentIndex: n, repeatMode: a, playbackMode: t } = e, i = r.length;
163
- return i === 0 ? 0 : t === "single" ? A(n, i) : n > 0 ? n - 1 : a === "all" ? i - 1 : 0;
164
- }
165
- function Br(e) {
166
- return e === "off" ? "all" : e === "all" ? "one" : "off";
167
- }
168
- function Ye(e, r) {
169
- return (e == null ? void 0 : e.artworkUrl) ?? r ?? void 0;
170
- }
171
- function Yr(e, r) {
172
- return (e == null ? void 0 : e.album) ?? r ?? void 0;
173
- }
174
- function V(e) {
175
- return e.tracks[e.currentIndex] ?? null;
176
- }
177
- function Qe(e) {
178
- 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";
179
- }
180
- function W(e) {
181
- var a;
182
- const r = e.duration;
183
- if (Number.isFinite(r) && r > 0) return r;
184
- const n = (a = e.tracks[e.currentIndex]) == null ? void 0 : a.durationSeconds;
185
- return typeof n == "number" && Number.isFinite(n) && n > 0 ? n : 0;
186
- }
187
- function Qr(e) {
188
- const n = W(e) - e.currentTime;
189
- return Number.isFinite(n) ? Math.max(0, n) : 0;
190
- }
191
- function He(e) {
192
- const r = W(e);
193
- return r > 0 ? Math.min(1, Math.max(0, e.currentTime / r)) : 0;
194
- }
195
- function Hr(e) {
196
- var n;
197
- const r = V(e);
198
- return Ye(r, (n = e.playlistMeta) == null ? void 0 : n.artworkUrl);
199
- }
200
- function jr(e) {
201
- var n;
202
- const r = V(e);
203
- return Yr(r, (n = e.playlistMeta) == null ? void 0 : n.subtitle);
204
- }
205
- function B(e, r) {
206
- function n(a) {
207
- const t = x(), u = (r(t) ?? "").trim(), { className: o, style: c, fallback: d, empty: g, children: m } = a;
208
- if (!u) {
209
- const M = g ?? d ?? null;
210
- return M ? /* @__PURE__ */ s("span", { className: o, style: c, children: M }) : null;
211
- }
212
- return m ? /* @__PURE__ */ s("span", { className: o, style: c, children: m(u, t) }) : /* @__PURE__ */ s("span", { className: o, style: c, children: u });
213
- }
214
- return n.displayName = e, n;
215
- }
216
- function Y(e, r) {
217
- return B(e, (n) => r(V(n)));
218
- }
219
- const Kr = Y("Ginger.Current.Title", (e) => e == null ? void 0 : e.title), Xr = Y("Ginger.Current.Artist", (e) => e == null ? void 0 : e.artist), Wr = B("Ginger.Current.Album", (e) => jr(e)), qr = Y("Ginger.Current.Description", (e) => e == null ? void 0 : e.description), zr = B("Ginger.Current.Copyright", (e) => {
220
- var n;
221
- const r = V(e);
222
- return (r == null ? void 0 : r.copyright) ?? ((n = e.playlistMeta) == null ? void 0 : n.copyright);
223
- }), Jr = Y("Ginger.Current.Genre", (e) => e == null ? void 0 : e.genre), Zr = Y("Ginger.Current.Label", (e) => e == null ? void 0 : e.label), en = Y("Ginger.Current.Isrc", (e) => e == null ? void 0 : e.isrc), rn = Y(
224
- "Ginger.Current.TrackNumber",
225
- (e) => (e == null ? void 0 : e.trackNumber) != null ? String(e.trackNumber) : void 0
226
- );
227
- function je({ className: e, style: r, fallback: n, empty: a, children: t, format: i }) {
228
- var d;
229
- const u = x(), o = (d = V(u)) == null ? void 0 : d.year;
230
- if (typeof o != "number" || !Number.isFinite(o)) {
231
- const g = a ?? n ?? null;
232
- return g ? /* @__PURE__ */ s("span", { className: e, style: r, children: g }) : null;
233
- }
234
- const c = i ? i(o) : String(o);
235
- return t ? /* @__PURE__ */ s("span", { className: e, style: r, children: t(c, u) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: c });
236
- }
237
- je.displayName = "Ginger.Current.Year";
238
- function Ke({ className: e, style: r, fallback: n, empty: a, children: t, preserveWhitespace: i = !0 }) {
239
- var g;
240
- const u = x(), o = ((g = V(u)) == null ? void 0 : g.lyrics) ?? "", c = i ? o.replace(/^\s+|\s+$/g, "") : o.trim();
241
- if (!c) {
242
- const m = a ?? n ?? null;
243
- return m ? /* @__PURE__ */ s("span", { className: e, style: r, children: m }) : null;
244
- }
245
- const d = i ? { whiteSpace: "pre-wrap" } : void 0;
246
- return t ? /* @__PURE__ */ s("span", { className: e, style: { ...d, ...r }, children: t(c, u) }) : /* @__PURE__ */ s("span", { className: e, style: { ...d, ...r }, children: c });
247
- }
248
- Ke.displayName = "Ginger.Current.Lyrics";
249
- function Xe({ visible: e = !1, className: r, style: n, fallback: a, empty: t, children: i }) {
250
- var c;
251
- const u = x();
252
- if (!e) return null;
253
- const o = ((c = V(u)) == null ? void 0 : c.fileUrl) ?? "";
254
- if (!o) {
255
- const d = t ?? a ?? null;
256
- return d ? /* @__PURE__ */ s("span", { className: r, style: n, children: d }) : null;
257
- }
258
- return i ? /* @__PURE__ */ s("span", { className: r, style: n, children: i(o, u) }) : /* @__PURE__ */ s("span", { className: r, style: n, children: o });
259
- }
260
- Xe.displayName = "Ginger.Current.FileUrl";
261
- function We({
262
- className: e,
263
- style: r,
264
- fallback: n,
265
- empty: a,
266
- sizes: t,
267
- loading: i,
268
- onError: u,
269
- decoding: o,
270
- unstyled: c = !1,
271
- imgStyle: d
272
- }) {
273
- const g = x(), m = V(g), M = Hr(g);
274
- if (!M) {
275
- const h = a ?? n ?? null;
276
- return h ? /* @__PURE__ */ s("span", { className: e, style: r, children: h }) : null;
277
- }
278
- const E = [m == null ? void 0 : m.title, m == null ? void 0 : m.artist].filter(Boolean).join(" — ") || "Artwork";
279
- return /* @__PURE__ */ s(
280
- "div",
281
- {
282
- className: e,
283
- style: c ? { ...r } : {
284
- background: "var(--ginger-artwork-bg, transparent)",
285
- borderRadius: "var(--ginger-artwork-radius, 0)",
286
- overflow: "hidden",
287
- ...r
288
- },
289
- children: /* @__PURE__ */ s(
290
- "img",
291
- {
292
- src: M,
293
- alt: E,
294
- sizes: t,
295
- loading: i,
296
- decoding: o,
297
- onError: u,
298
- style: {
299
- display: c ? void 0 : "block",
300
- width: c ? void 0 : "100%",
301
- height: c ? void 0 : "100%",
302
- objectFit: c ? void 0 : "cover",
303
- ...d
304
- }
305
- }
306
- )
307
- }
308
- );
309
- }
310
- We.displayName = "Ginger.Current.Artwork";
311
- function qe({ base: e = 0, className: r, style: n, fallback: a, empty: t, children: i }) {
312
- const u = x();
313
- if (u.tracks.length === 0) {
314
- const d = t ?? a ?? null;
315
- return d ? /* @__PURE__ */ s("span", { className: r, style: n, children: d }) : null;
316
- }
317
- const c = String(u.currentIndex + e);
318
- return i ? /* @__PURE__ */ s("span", { className: r, style: n, children: i(c, u) }) : /* @__PURE__ */ s("span", { className: r, style: n, children: c });
319
- }
320
- qe.displayName = "Ginger.Current.QueueIndex";
321
- function ze({ className: e, style: r, fallback: n, empty: a, children: t }) {
322
- const i = x(), u = String(i.tracks.length);
323
- if (i.tracks.length === 0) {
324
- const o = a ?? n ?? null;
325
- return o ? /* @__PURE__ */ s("span", { className: e, style: r, children: o }) : null;
326
- }
327
- return t ? /* @__PURE__ */ s("span", { className: e, style: r, children: t(u, i) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: u });
328
- }
329
- ze.displayName = "Ginger.Current.QueueLength";
330
- function Je({
331
- base: e = 0,
332
- separator: r = " / ",
333
- className: n,
334
- style: a,
335
- fallback: t,
336
- empty: i,
337
- children: u
338
- }) {
339
- const o = x(), c = o.tracks.length;
340
- if (c === 0) {
341
- const M = i ?? t ?? null;
342
- return M ? /* @__PURE__ */ s("span", { className: n, style: a, children: M }) : null;
343
- }
344
- const d = String(o.currentIndex + e), g = String(c), m = `${d}${r}${g}`;
345
- return u ? /* @__PURE__ */ s("span", { className: n, style: a, children: u({ index: d, length: g, label: m }, o) }) : /* @__PURE__ */ s("span", { className: n, style: a, children: m });
346
- }
347
- Je.displayName = "Ginger.Current.QueuePosition";
348
- function Te(e) {
349
- if (!Number.isFinite(e) || e < 0) return "0:00";
350
- const r = Math.floor(e % 60);
351
- return `${Math.floor(e / 60)}:${r.toString().padStart(2, "0")}`;
352
- }
353
- function we(e, r, n) {
354
- const { className: a, style: t, fallback: i, empty: u, children: o, format: c = Te } = n;
355
- if (!(e >= 0) || !Number.isFinite(e)) {
356
- const g = u ?? i ?? null;
357
- return g ? /* @__PURE__ */ s("span", { className: a, style: t, children: g }) : null;
358
- }
359
- const d = c(e);
360
- return o ? /* @__PURE__ */ s("span", { className: a, style: t, children: o(d, r) }) : /* @__PURE__ */ s("span", { className: a, style: t, children: d });
361
- }
362
- function Ze(e) {
363
- const r = x();
364
- return we(r.currentTime, r, e);
365
- }
366
- Ze.displayName = "Ginger.Current.Elapsed";
367
- function er(e) {
368
- const r = x();
369
- return we(W(r), r, e);
370
- }
371
- er.displayName = "Ginger.Current.Duration";
372
- function rr(e) {
373
- const r = x();
374
- return we(Qr(r), r, e);
375
- }
376
- rr.displayName = "Ginger.Current.Remaining";
377
- function nr({ className: e, style: r, fallback: n, empty: a, children: t }) {
378
- const i = x(), u = W(i), o = He(i);
379
- if (!(u > 0)) {
380
- const c = a ?? n ?? null;
381
- return c ? /* @__PURE__ */ s("span", { className: e, style: r, children: c }) : null;
382
- }
383
- return t ? /* @__PURE__ */ s("span", { className: e, style: r, children: t({ fraction: o, currentTime: i.currentTime, duration: u }, i) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: `${Math.round(o * 100)}%` });
384
- }
385
- nr.displayName = "Ginger.Current.Progress";
386
- function tr({
387
- className: e,
388
- style: r,
389
- height: n = 4,
390
- showBuffered: a = !1,
391
- unstyled: t = !1
392
- }) {
393
- const i = x(), u = `${Math.round(He(i) * 100)}%`, o = `${Math.round(Math.min(1, Math.max(0, i.bufferedFraction)) * 100)}%`;
394
- return /* @__PURE__ */ _e(
395
- "div",
396
- {
397
- className: e,
398
- style: t ? { ...r } : {
399
- width: "100%",
400
- height: n,
401
- background: "var(--ginger-muted-color, #e5e7eb)",
402
- borderRadius: 999,
403
- overflow: "hidden",
404
- position: "relative",
405
- ...r
406
- },
407
- "aria-hidden": !0,
408
- children: [
409
- a ? /* @__PURE__ */ s(
410
- "div",
411
- {
412
- style: {
413
- position: t ? void 0 : "absolute",
414
- left: t ? void 0 : 0,
415
- top: t ? void 0 : 0,
416
- height: t ? void 0 : "100%",
417
- width: o,
418
- background: t ? void 0 : "var(--ginger-buffer-color, rgba(107, 114, 128, 0.35))"
419
- }
420
- }
421
- ) : null,
422
- /* @__PURE__ */ s(
423
- "div",
424
- {
425
- style: {
426
- position: t ? void 0 : "relative",
427
- width: u,
428
- height: t ? void 0 : "100%",
429
- background: t ? void 0 : "var(--ginger-primary-color, #111827)"
430
- }
431
- }
432
- )
433
- ]
434
- }
435
- );
436
- }
437
- tr.displayName = "Ginger.Current.TimeRail";
438
- function ar({ className: e, style: r, height: n = 4, unstyled: a = !1 }) {
439
- const t = x(), i = `${Math.round(Math.min(1, Math.max(0, t.bufferedFraction)) * 100)}%`;
440
- return /* @__PURE__ */ s(
441
- "div",
442
- {
443
- className: e,
444
- style: a ? { ...r } : {
445
- width: "100%",
446
- height: n,
447
- background: "var(--ginger-muted-color, #e5e7eb)",
448
- borderRadius: 999,
449
- overflow: "hidden",
450
- ...r
451
- },
452
- "aria-hidden": !0,
453
- children: /* @__PURE__ */ s(
454
- "div",
455
- {
456
- style: {
457
- width: i,
458
- height: a ? void 0 : "100%",
459
- background: a ? void 0 : "var(--ginger-buffer-color, rgba(107, 114, 128, 0.35))"
460
- }
461
- }
462
- )
463
- }
464
- );
465
- }
466
- ar.displayName = "Ginger.Current.BufferRail";
467
- function ir({ className: e, style: r, fallback: n, empty: a, children: t }) {
468
- const i = x(), u = Qe(i);
469
- return t ? /* @__PURE__ */ s("span", { className: e, style: r, children: t(u, i) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: u });
470
- }
471
- ir.displayName = "Ginger.Current.PlaybackState";
472
- function ur({ className: e, style: r, fallback: n, empty: a, live: t = "polite", children: i }) {
473
- const u = x(), o = u.errorMessage ?? "";
474
- if (!o) {
475
- const c = a ?? n ?? null;
476
- return c ? /* @__PURE__ */ s("span", { className: e, style: r, children: c }) : null;
477
- }
478
- return i ? /* @__PURE__ */ s("span", { className: e, style: r, "aria-live": t, children: i(o, u) }) : /* @__PURE__ */ s("span", { className: e, style: r, "aria-live": t, children: o });
479
- }
480
- ur.displayName = "Ginger.Current.ErrorMessage";
481
- const xe = {
482
- seek: "Seek",
483
- volume: "Volume",
484
- playbackSpeed: "Playback speed",
485
- nextTrack: "Next track",
486
- previousTrack: "Previous track",
487
- shuffle: "Shuffle",
488
- mute: "Mute",
489
- unmute: "Unmute",
490
- play: "Play",
491
- pause: "Pause",
492
- repeat: {
493
- off: "Repeat off",
494
- all: "Repeat all",
495
- one: "Repeat one"
496
- },
497
- playbackRateNormal: "1× normal",
498
- playbackRateTimes: (e) => `${e}×`
499
- };
500
- function nn(e) {
501
- return e ? {
502
- ...xe,
503
- ...e,
504
- repeat: { ...xe.repeat, ...e.repeat }
505
- } : xe;
506
- }
507
- const or = Ne(xe);
508
- function tn({
509
- locale: e,
510
- children: r
511
- }) {
512
- const n = nn(e);
513
- return /* @__PURE__ */ s(or.Provider, { value: n, children: r });
514
- }
515
- function _() {
516
- return Ge(or);
517
- }
518
- function an() {
519
- const e = w(), r = Ee(), n = _(), a = U(() => Ve(e, r), [e, r]), t = W(a), i = t > 0 ? a.currentTime : 0, u = Number.isFinite(i) ? i : 0, o = t > 0 ? `${Te(u)} of ${Te(t)}` : Te(u), c = (d) => {
520
- r.seek(Number(d.currentTarget.value));
521
- };
522
- return {
523
- state: a,
524
- value: u,
525
- min: 0,
526
- max: t > 0 ? t : 1,
527
- step: "any",
528
- ariaValueText: o,
529
- ariaLabel: n.seek,
530
- onSeekInput: c,
531
- onSeekChange: c
532
- };
533
- }
534
- function un() {
535
- const e = w(), r = Ee(), n = _(), a = U(() => Ve(e, r), [e, r]), t = (i) => {
536
- r.setVolume(Number(i.currentTarget.value));
537
- };
538
- return {
539
- state: a,
540
- value: a.volume,
541
- min: 0,
542
- max: 1,
543
- step: "any",
544
- ariaValueText: `${Math.round(a.volume * 100)}%`,
545
- ariaLabel: n.volume,
546
- onVolumeInput: t,
547
- onVolumeChange: t
548
- };
549
- }
550
- function on(e) {
551
- const r = w(), n = _(), a = (e == null ? void 0 : e.playAriaLabel) ?? n.play, t = (e == null ? void 0 : e.pauseAriaLabel) ?? n.pause;
552
- return {
553
- isPaused: r.isPaused,
554
- toggle: r.togglePlayPause,
555
- ariaLabel: r.isPaused ? a : t
556
- };
557
- }
558
- function lr({
559
- playLabel: e = "Play",
560
- pauseLabel: r = "Pause",
561
- playAriaLabel: n,
562
- pauseAriaLabel: a,
563
- type: t = "button",
564
- onClick: i,
565
- ...u
566
- }) {
567
- const o = _(), c = typeof e == "string" ? e : o.play, d = typeof r == "string" ? r : o.pause, g = on({
568
- playAriaLabel: n ?? c,
569
- pauseAriaLabel: a ?? d
570
- });
571
- return /* @__PURE__ */ s(
572
- "button",
573
- {
574
- ...u,
575
- type: t,
576
- "aria-label": g.ariaLabel,
577
- onClick: (m) => {
578
- g.toggle(), i == null || i(m);
579
- },
580
- children: g.isPaused ? e : r
581
- }
582
- );
583
- }
584
- lr.displayName = "Ginger.Control.PlayPause";
585
- function sr({ type: e = "button", onClick: r, ...n }) {
586
- const { repeatMode: a, cycleRepeat: t } = w(), u = _().repeat[a];
587
- return /* @__PURE__ */ s("button", { ...n, type: e, "aria-label": u, onClick: (o) => {
588
- t(), r == null || r(o);
589
- }, children: u });
590
- }
591
- sr.displayName = "Ginger.Control.Repeat";
592
- function cr({ type: e = "button", children: r = "Next", onClick: n, ...a }) {
593
- const { next: t } = w(), i = _();
594
- return /* @__PURE__ */ s("button", { ...a, type: e, "aria-label": i.nextTrack, onClick: (u) => {
595
- t(), n == null || n(u);
596
- }, children: r });
597
- }
598
- cr.displayName = "Ginger.Control.Next";
599
- function dr({ type: e = "button", children: r = "Previous", onClick: n, ...a }) {
600
- const { prev: t } = w(), i = _();
601
- return /* @__PURE__ */ s("button", { ...a, type: e, "aria-label": i.previousTrack, onClick: (u) => {
602
- t(), n == null || n(u);
603
- }, children: r });
604
- }
605
- dr.displayName = "Ginger.Control.Previous";
606
- function fr({ type: e = "button", children: r = "Shuffle", onClick: n, ...a }) {
607
- const { isShuffled: t, toggleShuffle: i } = w(), u = _();
608
- return /* @__PURE__ */ s(
609
- "button",
610
- {
611
- ...a,
612
- type: e,
613
- "aria-pressed": t,
614
- "aria-label": u.shuffle,
615
- onClick: (o) => {
616
- i(), n == null || n(o);
617
- },
618
- children: r
619
- }
620
- );
621
- }
622
- fr.displayName = "Ginger.Control.Shuffle";
623
- function pr({ inputStyle: e, style: r, unstyled: n = !1, ...a }) {
624
- const t = an(), i = n ? { ...r, ...e } : { width: "100%", ...r, ...e };
625
- return /* @__PURE__ */ s(
626
- "input",
627
- {
628
- ...a,
629
- type: "range",
630
- min: t.min,
631
- max: t.max,
632
- step: t.step,
633
- value: t.value,
634
- "aria-label": t.ariaLabel,
635
- "aria-valuetext": t.ariaValueText,
636
- onInput: t.onSeekInput,
637
- onChange: t.onSeekChange,
638
- style: i
639
- }
640
- );
641
- }
642
- pr.displayName = "Ginger.Control.SeekBar";
643
- function gr({ inputStyle: e, style: r, unstyled: n = !1, ...a }) {
644
- const t = un(), i = n ? { ...r, ...e } : { width: "100%", ...r, ...e };
645
- return /* @__PURE__ */ s(
646
- "input",
647
- {
648
- ...a,
649
- type: "range",
650
- min: t.min,
651
- max: t.max,
652
- step: t.step,
653
- value: t.value,
654
- "aria-label": t.ariaLabel,
655
- "aria-valuetext": t.ariaValueText,
656
- onInput: t.onVolumeInput,
657
- onChange: t.onVolumeChange,
658
- style: i
659
- }
660
- );
661
- }
662
- gr.displayName = "Ginger.Control.Volume";
663
- function mr({
664
- muteLabel: e,
665
- unmuteLabel: r,
666
- type: n = "button",
667
- onClick: a,
668
- ...t
669
- }) {
670
- const { muted: i, toggleMute: u } = Ee(), o = _(), c = e ?? o.mute, d = r ?? o.unmute;
671
- return /* @__PURE__ */ s(
672
- "button",
673
- {
674
- ...t,
675
- type: n,
676
- "aria-pressed": i,
677
- "aria-label": i ? o.unmute : o.mute,
678
- onClick: (g) => {
679
- u(), a == null || a(g);
680
- },
681
- children: i ? d : c
682
- }
683
- );
684
- }
685
- mr.displayName = "Ginger.Control.Mute";
686
- const ln = [0.5, 0.75, 1, 1.25, 1.5, 2];
687
- function yr({ rates: e = ln, style: r, ...n }) {
688
- const { playbackRate: a, setPlaybackRate: t } = Ee(), i = _(), u = U(
689
- () => Array.from(/* @__PURE__ */ new Set([...e, a])).sort((o, c) => o - c),
690
- [e, a]
691
- );
692
- return /* @__PURE__ */ s(
693
- "select",
694
- {
695
- ...n,
696
- "aria-label": i.playbackSpeed,
697
- value: String(a),
698
- style: r,
699
- onChange: (o) => t(Number(o.currentTarget.value)),
700
- children: u.map((o) => /* @__PURE__ */ s("option", { value: String(o), children: o === 1 ? i.playbackRateNormal : i.playbackRateTimes(o) }, o))
701
- }
702
- );
703
- }
704
- yr.displayName = "Ginger.Control.PlaybackRate";
705
- const Se = Ne(null);
706
- function sn() {
707
- const e = Ge(Se);
708
- if (!e)
709
- throw new Error("Ginger.Playlist.Track must be used inside <Ginger.Playlist>");
710
- return e;
711
- }
712
- function br({
713
- children: e,
714
- unstyled: r = !1,
715
- rowStyle: n,
716
- renderTrack: a,
717
- playOnSelect: t = !0,
718
- style: i,
719
- ...u
720
- }) {
721
- const { tracks: o, currentIndex: c, playTrackAt: d, selectTrackAt: g } = w(), m = r ? { ...i } : {
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
- ...i
729
- };
730
- return e !== void 0 ? /* @__PURE__ */ s(Se.Provider, { value: { playOnSelect: t }, children: /* @__PURE__ */ s("ul", { style: m, ...u, children: e }) }) : /* @__PURE__ */ s(Se.Provider, { value: { playOnSelect: t }, children: /* @__PURE__ */ s("ul", { style: m, ...u, children: o.map((E, h) => {
731
- const P = h === c;
732
- return /* @__PURE__ */ s("li", { children: /* @__PURE__ */ s(
733
- "button",
734
- {
735
- type: "button",
736
- onClick: () => {
737
- t ? d(h) : g(h);
738
- },
739
- style: {
740
- width: r ? void 0 : "100%",
741
- textAlign: r ? void 0 : "left",
742
- border: r ? void 0 : "none",
743
- background: r ? void 0 : P ? "var(--ginger-playlist-active-bg, rgba(17, 24, 39, 0.06))" : "transparent",
744
- color: r ? void 0 : "inherit",
745
- font: r ? void 0 : "inherit",
746
- cursor: r ? void 0 : "pointer",
747
- padding: r ? void 0 : "var(--ginger-playlist-row-padding, 6px 8px)",
748
- ...n
749
- },
750
- children: a ? a(E, h, P) : /* @__PURE__ */ _e("span", { children: [
751
- E.title,
752
- E.artist ? ` — ${E.artist}` : ""
753
- ] })
754
- }
755
- ) }, `${h}-${X(E)}`);
756
- }) }) });
757
- }
758
- br.displayName = "Ginger.Playlist";
759
- function hr({
760
- index: e,
761
- unstyled: r = !1,
762
- className: n,
763
- style: a,
764
- children: t,
765
- liProps: i,
766
- onClick: u,
767
- ...o
768
- }) {
769
- const { playOnSelect: c } = sn(), { tracks: d, currentIndex: g, playTrackAt: m, selectTrackAt: M } = w(), E = e === g, h = d[e], P = h != null ? /* @__PURE__ */ _e("span", { children: [
770
- h.title,
771
- h.artist ? ` — ${h.artist}` : ""
772
- ] }) : null;
773
- return /* @__PURE__ */ s("li", { ...i, children: /* @__PURE__ */ s(
774
- "button",
775
- {
776
- type: "button",
777
- "aria-current": E ? "true" : void 0,
778
- "data-ginger-active": E || void 0,
779
- className: n,
780
- style: {
781
- width: r ? void 0 : "100%",
782
- textAlign: r ? void 0 : "left",
783
- border: r ? void 0 : "none",
784
- background: r ? void 0 : E ? "var(--ginger-playlist-active-bg, rgba(17, 24, 39, 0.06))" : "transparent",
785
- color: r ? void 0 : "inherit",
786
- font: r ? void 0 : "inherit",
787
- cursor: r ? void 0 : "pointer",
788
- padding: r ? void 0 : "var(--ginger-playlist-row-padding, 6px 8px)",
789
- ...a
790
- },
791
- ...o,
792
- onClick: (p) => {
793
- u == null || u(p), !p.defaultPrevented && (c ? m(e) : M(e));
794
- },
795
- children: t ?? P
796
- }
797
- ) });
798
- }
799
- hr.displayName = "Ginger.Playlist.Track";
800
- const cn = Object.assign(br, {
801
- Track: hr
802
- }), dn = B("Ginger.Queue.Title", (e) => {
803
- var r;
804
- return (r = e.playlistMeta) == null ? void 0 : r.title;
805
- }), fn = B("Ginger.Queue.Subtitle", (e) => {
806
- var r;
807
- return (r = e.playlistMeta) == null ? void 0 : r.subtitle;
808
- }), pn = B("Ginger.Queue.Description", (e) => {
809
- var r;
810
- return (r = e.playlistMeta) == null ? void 0 : r.description;
811
- }), gn = B("Ginger.Queue.Copyright", (e) => {
812
- var r;
813
- return (r = e.playlistMeta) == null ? void 0 : r.copyright;
814
- });
815
- function vr({ className: e, style: r, fallback: n, empty: a, unstyled: t = !1, imgStyle: i }) {
816
- var d, g;
817
- const u = x(), o = (d = u.playlistMeta) == null ? void 0 : d.artworkUrl;
818
- if (!o) {
819
- const m = a ?? n ?? null;
820
- return m ? /* @__PURE__ */ s("span", { className: e, style: r, children: m }) : null;
821
- }
822
- const c = ((g = u.playlistMeta) == null ? void 0 : g.title) ?? "Playlist artwork";
823
- return /* @__PURE__ */ s(
824
- "span",
825
- {
826
- className: e,
827
- style: t ? { ...r } : {
828
- display: "inline-block",
829
- background: "var(--ginger-artwork-bg, #f3f4f6)",
830
- borderRadius: "var(--ginger-artwork-radius, 6px)",
831
- overflow: "hidden",
832
- ...r
833
- },
834
- children: /* @__PURE__ */ s(
835
- "img",
836
- {
837
- src: o,
838
- alt: c,
839
- style: {
840
- display: t ? void 0 : "block",
841
- width: t ? void 0 : "100%",
842
- height: t ? void 0 : "100%",
843
- objectFit: t ? void 0 : "cover",
844
- ...i
845
- }
846
- }
847
- )
848
- }
849
- );
850
- }
851
- vr.displayName = "Ginger.Queue.Artwork";
852
- function Ie(e) {
853
- return Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 1;
854
- }
855
- function De(e) {
856
- return Number.isFinite(e) ? Math.min(4, Math.max(0.25, e)) : 1;
857
- }
858
- const F = {
859
- currentTime: 0,
860
- duration: 0,
861
- bufferedFraction: 0,
862
- isBuffering: !1,
863
- errorMessage: null
864
- }, mn = {
865
- ...F,
866
- volume: 1,
867
- muted: !1,
868
- playbackRate: 1
869
- };
870
- function kr(e) {
871
- const r = [...e.tracks];
872
- let n = A(e.currentIndex ?? 0, r.length), a = null, t = r;
873
- return e.isShuffled && r.length > 1 && (a = [...r], t = $e(r, n), n = 0), {
874
- tracks: t,
875
- currentIndex: n,
876
- playbackMode: e.playbackMode ?? "playlist",
877
- isPaused: e.isPaused ?? !0,
878
- isShuffled: !!(e.isShuffled && t.length > 1),
879
- repeatMode: e.repeatMode ?? "off",
880
- originalTracks: a,
881
- playlistMeta: e.playlistMeta ?? null,
882
- ...mn,
883
- volume: Ie(e.volume ?? 1),
884
- muted: e.muted ?? !1,
885
- playbackRate: De(e.playbackRate ?? 1)
886
- };
887
- }
888
- function yn(e, r) {
889
- switch (r.type) {
890
- case "INIT": {
891
- const {
892
- tracks: n,
893
- currentIndex: a,
894
- playlistMeta: t,
895
- isPaused: i,
896
- isShuffled: u,
897
- repeatMode: o,
898
- playbackMode: c,
899
- volume: d,
900
- muted: g,
901
- playbackRate: m
902
- } = r.payload;
903
- return kr({
904
- tracks: n,
905
- currentIndex: a,
906
- playlistMeta: t ?? null,
907
- isPaused: i ?? !0,
908
- isShuffled: u ?? !1,
909
- repeatMode: o ?? "off",
910
- playbackMode: c ?? "playlist",
911
- volume: d,
912
- muted: g,
913
- playbackRate: m
914
- });
915
- }
916
- case "SET_QUEUE": {
917
- const { tracks: n, currentIndex: a } = r.payload, t = [...n], i = A(a ?? e.currentIndex, t.length);
918
- return {
919
- ...e,
920
- tracks: t,
921
- currentIndex: i,
922
- isShuffled: !1,
923
- originalTracks: null,
924
- ...F
925
- };
926
- }
927
- case "INSERT_TRACK": {
928
- const n = r.payload.index ?? e.tracks.length, a = Be(e.tracks, r.payload.track, n);
929
- if (r.payload.autoPlay) {
930
- const i = A(n, a.length);
931
- return {
932
- ...e,
933
- tracks: a,
934
- currentIndex: i,
935
- isShuffled: !1,
936
- originalTracks: null,
937
- isPaused: !1,
938
- ...F
939
- };
940
- }
941
- const t = n <= e.currentIndex ? e.currentIndex + 1 : e.currentIndex;
942
- return {
943
- ...e,
944
- tracks: a,
945
- isShuffled: !1,
946
- originalTracks: null,
947
- currentIndex: A(t, a.length)
948
- };
949
- }
950
- case "REMOVE_TRACK": {
951
- const n = r.payload.index, a = Lr(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;
952
- return {
953
- ...e,
954
- tracks: a,
955
- isShuffled: !1,
956
- originalTracks: null,
957
- currentIndex: A(t, a.length),
958
- ...n === e.currentIndex ? F : {}
959
- };
960
- }
961
- case "MOVE_TRACK": {
962
- const { fromIndex: n, toIndex: a } = r.payload, t = Fr(e.tracks, n, a);
963
- let i = e.currentIndex;
964
- return e.currentIndex === n ? i = a : n < e.currentIndex && a >= e.currentIndex ? i -= 1 : n > e.currentIndex && a <= e.currentIndex && (i += 1), {
965
- ...e,
966
- tracks: t,
967
- isShuffled: !1,
968
- originalTracks: null,
969
- currentIndex: A(i, t.length)
970
- };
971
- }
972
- case "ADD_NEXT": {
973
- const n = Ur(e.tracks, e.currentIndex, r.payload.track);
974
- return {
975
- ...e,
976
- tracks: n,
977
- isShuffled: !1,
978
- originalTracks: null
979
- };
980
- }
981
- case "SET_INDEX": {
982
- const n = A(r.payload.index, e.tracks.length), a = r.payload.autoPlay, t = a === !0 ? !1 : a === !1 ? !0 : e.isPaused;
983
- return {
984
- ...e,
985
- currentIndex: n,
986
- ...F,
987
- isPaused: t
988
- };
989
- }
990
- case "PLAY":
991
- return { ...e, isPaused: !1 };
992
- case "PAUSE":
993
- return { ...e, isPaused: !0 };
994
- case "TOGGLE_PAUSE":
995
- return { ...e, isPaused: !e.isPaused };
996
- case "SET_REPEAT":
997
- return { ...e, repeatMode: r.payload };
998
- case "CYCLE_REPEAT":
999
- return { ...e, repeatMode: Br(e.repeatMode) };
1000
- case "TOGGLE_SHUFFLE": {
1001
- if (e.tracks.length <= 1) return { ...e, isShuffled: !1, originalTracks: null };
1002
- if (!e.isShuffled) {
1003
- const i = [...e.tracks], u = $e(i, e.currentIndex);
1004
- return {
1005
- ...e,
1006
- isShuffled: !0,
1007
- originalTracks: i,
1008
- tracks: u,
1009
- currentIndex: 0
1010
- };
1011
- }
1012
- const n = e.originalTracks ? [...e.originalTracks] : [...e.tracks], a = e.tracks[e.currentIndex], t = Cr(n, a);
1013
- return {
1014
- ...e,
1015
- isShuffled: !1,
1016
- originalTracks: null,
1017
- tracks: n,
1018
- currentIndex: A(t, n.length)
1019
- };
1020
- }
1021
- case "NEXT": {
1022
- const n = Or(e), a = n === e.currentIndex;
1023
- return {
1024
- ...e,
1025
- currentIndex: n,
1026
- ...a ? {} : F,
1027
- isPaused: a ? e.isPaused : !1
1028
- };
1029
- }
1030
- case "PREV": {
1031
- const n = $r(e), a = n === e.currentIndex;
1032
- return {
1033
- ...e,
1034
- currentIndex: n,
1035
- ...a ? {} : F,
1036
- isPaused: a ? e.isPaused : !1
1037
- };
1038
- }
1039
- case "MEDIA_TIME_UPDATE":
1040
- return {
1041
- ...e,
1042
- currentTime: r.payload.currentTime,
1043
- duration: Number.isFinite(r.payload.duration) ? r.payload.duration : e.duration,
1044
- bufferedFraction: r.payload.bufferedFraction,
1045
- isBuffering: !1
1046
- };
1047
- case "MEDIA_LOADED_METADATA":
1048
- return {
1049
- ...e,
1050
- duration: Number.isFinite(r.payload.duration) ? r.payload.duration : e.duration,
1051
- bufferedFraction: r.payload.bufferedFraction,
1052
- errorMessage: null
1053
- };
1054
- case "SET_PLAYLIST_META":
1055
- return { ...e, playlistMeta: r.payload };
1056
- case "SET_PLAYBACK_MODE":
1057
- return { ...e, playbackMode: r.payload };
1058
- case "MEDIA_ERROR":
1059
- return {
1060
- ...e,
1061
- errorMessage: r.payload.message,
1062
- isPaused: !0,
1063
- isBuffering: !1
1064
- };
1065
- case "MEDIA_WAITING":
1066
- return { ...e, isBuffering: !0 };
1067
- case "MEDIA_CANPLAY":
1068
- return { ...e, isBuffering: !1, errorMessage: null };
1069
- case "MEDIA_PLAY":
1070
- return { ...e, isPaused: !1, isBuffering: !1 };
1071
- case "MEDIA_PAUSE":
1072
- return { ...e, isPaused: !0 };
1073
- case "RESET_MEDIA_TIMES":
1074
- return { ...e, currentTime: 0, duration: 0, bufferedFraction: 0 };
1075
- case "MEDIA_SOURCE_CLEARED":
1076
- return { ...e, ...F };
1077
- case "SET_VOLUME":
1078
- return { ...e, volume: Ie(r.payload) };
1079
- case "SET_MUTED":
1080
- return { ...e, muted: r.payload };
1081
- case "TOGGLE_MUTE":
1082
- return { ...e, muted: !e.muted };
1083
- case "SET_PLAYBACK_RATE":
1084
- return { ...e, playbackRate: De(r.payload) };
1085
- case "MEDIA_VOLUME_SYNC": {
1086
- const { volume: n, muted: a } = r.payload, t = Ie(n);
1087
- return t === e.volume && a === e.muted ? e : { ...e, volume: t, muted: a };
1088
- }
1089
- default:
1090
- return e;
1091
- }
1092
- }
1093
- function Re() {
1094
- return typeof navigator > "u" || !("mediaSession" in navigator) ? null : navigator.mediaSession;
1095
- }
1096
- function bn(e, r, n) {
1097
- var c;
1098
- const a = r.tracks[r.currentIndex], t = a == null ? void 0 : a.title, i = a == null ? void 0 : a.artist, u = a == null ? void 0 : a.album, o = Ye(a, (c = r.playlistMeta) == null ? void 0 : c.artworkUrl);
1099
- I(() => {
1100
- const d = Re();
1101
- !e || !d || (d.metadata = new MediaMetadata({
1102
- title: t ?? "Unknown track",
1103
- artist: i,
1104
- album: u,
1105
- artwork: o ? [{ src: o }] : void 0
1106
- }));
1107
- }, [e, t, i, u, o]), I(() => {
1108
- const d = Re();
1109
- !e || !d || (d.playbackState = r.isPaused ? "paused" : "playing");
1110
- }, [e, r.isPaused]), I(() => {
1111
- const d = Re();
1112
- if (!(!e || !d)) {
1113
- try {
1114
- d.setActionHandler("play", n.play), d.setActionHandler("pause", n.pause), d.setActionHandler("nexttrack", n.next), d.setActionHandler("previoustrack", n.prev), d.setActionHandler("seekto", (g) => {
1115
- typeof g.seekTime == "number" && Number.isFinite(g.seekTime) && n.seek(g.seekTime);
1116
- });
1117
- } catch {
1118
- }
1119
- return () => {
1120
- try {
1121
- d.setActionHandler("play", null), d.setActionHandler("pause", null), d.setActionHandler("nexttrack", null), d.setActionHandler("previoustrack", null), d.setActionHandler("seekto", null);
1122
- } catch {
1123
- }
1124
- };
1125
- }
1126
- }, [e, n]);
1127
- }
1128
- const hn = {
1129
- "--ginger-primary-color": "#111827",
1130
- "--ginger-muted-color": "#6b7280",
1131
- "--ginger-font-size": "14px",
1132
- "--ginger-font-family": "system-ui, sans-serif",
1133
- "--ginger-playlist-row-padding": "6px 8px",
1134
- "--ginger-artwork-radius": "6px",
1135
- "--ginger-artwork-bg": "#f3f4f6",
1136
- "--ginger-playlist-active-bg": "rgba(17, 24, 39, 0.06)",
1137
- "--ginger-buffer-color": "rgba(107, 114, 128, 0.35)",
1138
- "--ginger-focus-ring": "0 0 0 2px rgba(59, 130, 246, 0.45)"
1139
- };
1140
- function vn({
1141
- children: e,
1142
- initialTracks: r = [],
1143
- initialIndex: n = 0,
1144
- initialPlaylistMeta: a = null,
1145
- initialShuffle: t = !1,
1146
- initialRepeatMode: i = "off",
1147
- initialPlaybackMode: u = "playlist",
1148
- initialPaused: o = !0,
1149
- initialVolume: c = 1,
1150
- initialMuted: d = !1,
1151
- initialPlaybackRate: g = 1,
1152
- initialStateKey: m,
1153
- locale: M,
1154
- mediaSession: E = !1,
1155
- beforePlay: h,
1156
- onPlayBlocked: P,
1157
- persistence: p,
1158
- hydrateOnMount: T = !1,
1159
- resumeOnTrackChange: R = !1,
1160
- unstyled: G = !1,
1161
- className: Ae,
1162
- style: j,
1163
- onTrackChange: q,
1164
- onPlay: z,
1165
- onPause: J,
1166
- onQueueEnd: Z,
1167
- onError: ee
1168
- }) {
1169
- var Fe;
1170
- const O = $(null), [l, y] = _r(
1171
- yn,
1172
- void 0,
1173
- () => kr({
1174
- tracks: r,
1175
- currentIndex: n,
1176
- playlistMeta: a,
1177
- isPaused: o,
1178
- isShuffled: t,
1179
- repeatMode: i,
1180
- playbackMode: u,
1181
- volume: c,
1182
- muted: d,
1183
- playbackRate: g
1184
- })
1185
- ), Ce = $(l), Pe = $({
1186
- tracks: r,
1187
- currentIndex: n,
1188
- playlistMeta: a,
1189
- isPaused: o,
1190
- isShuffled: t,
1191
- repeatMode: i,
1192
- playbackMode: u,
1193
- volume: c,
1194
- muted: d,
1195
- playbackRate: g
1196
- });
1197
- Pe.current = {
1198
- tracks: r,
1199
- currentIndex: n,
1200
- playlistMeta: a,
1201
- isPaused: o,
1202
- isShuffled: t,
1203
- repeatMode: i,
1204
- playbackMode: u,
1205
- volume: c,
1206
- muted: d,
1207
- playbackRate: g
1208
- };
1209
- const K = $(void 0);
1210
- I(() => {
1211
- if (m === void 0) {
1212
- K.current = void 0;
1213
- return;
1214
- }
1215
- if (K.current === void 0) {
1216
- K.current = m;
1217
- return;
1218
- }
1219
- if (K.current === m) return;
1220
- K.current = m;
1221
- const f = Pe.current;
1222
- y({
1223
- type: "INIT",
1224
- payload: {
1225
- tracks: f.tracks,
1226
- currentIndex: f.currentIndex,
1227
- playlistMeta: f.playlistMeta,
1228
- isPaused: f.isPaused,
1229
- isShuffled: f.isShuffled,
1230
- repeatMode: f.repeatMode,
1231
- playbackMode: f.playbackMode,
1232
- volume: f.volume,
1233
- muted: f.muted,
1234
- playbackRate: f.playbackRate
1235
- }
1236
- });
1237
- }, [m, y]), I(() => {
1238
- Ce.current = l;
1239
- }, [l]);
1240
- const Le = l.tracks[l.currentIndex] ?? null;
1241
- I(() => {
1242
- q == null || q(Le, l.currentIndex);
1243
- }, [Le, l.currentIndex, q]), I(() => {
1244
- l.errorMessage && (ee == null || ee(l.errorMessage));
1245
- }, [l.errorMessage, ee]);
1246
- const re = $(void 0);
1247
- I(() => {
1248
- if (re.current === void 0) {
1249
- re.current = l.isPaused;
1250
- return;
1251
- }
1252
- re.current !== l.isPaused && (l.isPaused ? J == null || J() : z == null || z()), re.current = l.isPaused;
1253
- }, [l.isPaused, J, z]);
1254
- const D = b(() => {
1255
- y({ type: "PLAY" });
1256
- }, []), C = b(() => {
1257
- var f;
1258
- y({ type: "PAUSE" }), (f = O.current) == null || f.pause();
1259
- }, []), ne = b(() => {
1260
- l.isPaused ? D() : C();
1261
- }, [C, D, l.isPaused]), L = b((f) => {
1262
- const v = O.current;
1263
- v && Number.isFinite(f) && (v.currentTime = Math.max(0, f));
1264
- }, []), te = b((f) => {
1265
- y({ type: "SET_VOLUME", payload: Ie(f) });
1266
- }, []), ae = b((f) => {
1267
- y({ type: "SET_MUTED", payload: f });
1268
- }, []), ie = b(() => {
1269
- y({ type: "TOGGLE_MUTE" });
1270
- }, []), ue = b((f) => {
1271
- y({ type: "SET_PLAYBACK_RATE", payload: De(f) });
1272
- }, []), Q = b(() => {
1273
- y({ type: "NEXT" });
1274
- }, []), H = b(() => {
1275
- y({ type: "PREV" });
1276
- }, []), oe = b((f) => {
1277
- y({ type: "SET_REPEAT", payload: f });
1278
- }, []), le = b(() => {
1279
- y({ type: "CYCLE_REPEAT" });
1280
- }, []), se = b(() => {
1281
- y({ type: "TOGGLE_SHUFFLE" });
1282
- }, []), ce = b((f, v) => {
1283
- y({ type: "SET_QUEUE", payload: { tracks: f, currentIndex: v } });
1284
- }, []), de = b((f, v, k) => {
1285
- y({ type: "INSERT_TRACK", payload: { track: f, index: v, autoPlay: k } });
1286
- }, []), fe = b((f) => {
1287
- y({ type: "REMOVE_TRACK", payload: { index: f } });
1288
- }, []), pe = b((f, v) => {
1289
- y({ type: "MOVE_TRACK", payload: { fromIndex: f, toIndex: v } });
1290
- }, []), ge = b((f) => {
1291
- y({ type: "ADD_NEXT", payload: { track: f } });
1292
- }, []), me = b((f) => {
1293
- y({ type: "SET_INDEX", payload: { index: f, autoPlay: !0 } });
1294
- }, []), ye = b((f) => {
1295
- y({ type: "SET_INDEX", payload: { index: f, autoPlay: !1 } });
1296
- }, []), be = b((f) => {
1297
- y({ type: "SET_PLAYLIST_META", payload: f });
1298
- }, []), he = b((f) => {
1299
- y({ type: "SET_PLAYBACK_MODE", payload: f });
1300
- }, []), ve = b((f) => {
1301
- y({ type: "INIT", payload: f });
1302
- }, []);
1303
- I(() => {
1304
- if (!p || !T) return;
1305
- const f = p.get("ginger:volume"), v = p.get("ginger:muted"), k = p.get("ginger:playbackRate"), N = p.get("ginger:repeatMode"), Me = p.get("ginger:currentIndex"), S = Pe.current;
1306
- y({
1307
- type: "INIT",
1308
- payload: {
1309
- tracks: S.tracks,
1310
- playlistMeta: S.playlistMeta,
1311
- isPaused: S.isPaused,
1312
- isShuffled: S.isShuffled,
1313
- playbackMode: S.playbackMode,
1314
- currentIndex: typeof Me == "number" ? Me : S.currentIndex,
1315
- repeatMode: N === "off" || N === "all" || N === "one" ? N : S.repeatMode,
1316
- volume: typeof f == "number" ? f : S.volume,
1317
- muted: typeof v == "boolean" ? v : S.muted,
1318
- playbackRate: typeof k == "number" ? k : S.playbackRate
1319
- }
1320
- });
1321
- }, [T, p]), I(() => {
1322
- p && (p.set("ginger:volume", l.volume), p.set("ginger:muted", l.muted), p.set("ginger:playbackRate", l.playbackRate), p.set("ginger:repeatMode", l.repeatMode), p.set("ginger:currentIndex", l.currentIndex));
1323
- }, [p, l.volume, l.muted, l.playbackRate, l.repeatMode, l.currentIndex]), I(() => {
1324
- if (!p || !R) return;
1325
- const f = l.tracks[l.currentIndex];
1326
- if (!f) return;
1327
- const v = `ginger:resume:${X(f)}`, k = p.get(v);
1328
- typeof k == "number" && Number.isFinite(k) && L(k);
1329
- }, [p, R, l.currentIndex, l.tracks, L]), I(() => {
1330
- if (!p || !R) return;
1331
- const f = l.tracks[l.currentIndex];
1332
- if (!f || !(l.currentTime >= 0)) return;
1333
- const v = `ginger:resume:${X(f)}`, k = setTimeout(() => p.set(v, l.currentTime), 250);
1334
- return () => clearTimeout(k);
1335
- }, [p, R, l.currentIndex, l.tracks, l.currentTime]);
1336
- const Mr = (Fe = l.tracks[l.currentIndex]) == null ? void 0 : Fe.fileUrl;
1337
- I(() => {
1338
- const f = O.current;
1339
- if (!f) return;
1340
- if (l.isPaused) {
1341
- f.pause();
1342
- return;
1343
- }
1344
- let v = !1;
1345
- return (async () => {
1346
- if (h) {
1347
- let k = !1;
1348
- try {
1349
- k = await h();
1350
- } catch (N) {
1351
- const Me = N instanceof Error ? N.message : "beforePlay rejected";
1352
- y({ type: "MEDIA_ERROR", payload: { message: Me } });
1353
- return;
1354
- }
1355
- if (!k) {
1356
- v || (y({ type: "PAUSE" }), P == null || P());
1357
- return;
1358
- }
1359
- }
1360
- v || f.play().catch((k) => {
1361
- const N = k instanceof Error ? k.message : typeof k == "string" ? k : "Playback failed (e.g. autoplay blocked or unavailable source)";
1362
- y({ type: "MEDIA_ERROR", payload: { message: N } });
1363
- });
1364
- })(), () => {
1365
- v = !0;
1366
- };
1367
- }, [h, Mr, P, l.isPaused]);
1368
- const ke = b(() => {
1369
- const f = Vr(Ce.current);
1370
- if (f.kind === "replay_same") {
1371
- const k = O.current;
1372
- k && (k.currentTime = 0), y({ type: "PLAY" });
1373
- return;
1374
- }
1375
- if (f.kind === "stop") {
1376
- y({ type: "PAUSE" }), Z == null || Z();
1377
- return;
1378
- }
1379
- const v = f.nextIndex;
1380
- y({ type: "SET_INDEX", payload: { index: v, autoPlay: !0 } });
1381
- }, [Z]), Tr = U(
1382
- () => ({ play: D, pause: C, next: Q, prev: H, seek: L }),
1383
- [D, C, Q, H, L]
1384
- );
1385
- bn(!!E, l, Tr);
1386
- const xr = M != null && M.seek && /[\u0590-\u08FF]/.test(M.seek) ? "rtl" : "ltr", Ir = U(
1387
- () => ({
1388
- state: l,
1389
- dispatch: y,
1390
- audioRef: O,
1391
- notifyEnded: ke,
1392
- init: ve,
1393
- play: D,
1394
- pause: C,
1395
- togglePlayPause: ne,
1396
- seek: L,
1397
- setVolume: te,
1398
- setMuted: ae,
1399
- toggleMute: ie,
1400
- setPlaybackRate: ue,
1401
- next: Q,
1402
- prev: H,
1403
- setRepeatMode: oe,
1404
- cycleRepeat: le,
1405
- toggleShuffle: se,
1406
- setQueue: ce,
1407
- insertTrackAt: de,
1408
- removeTrackAt: fe,
1409
- moveTrack: pe,
1410
- enqueueNext: ge,
1411
- playTrackAt: me,
1412
- selectTrackAt: ye,
1413
- setPlaylistMeta: be,
1414
- setPlaybackMode: he
1415
- }),
1416
- [
1417
- le,
1418
- y,
1419
- ve,
1420
- Q,
1421
- ke,
1422
- C,
1423
- D,
1424
- me,
1425
- de,
1426
- fe,
1427
- pe,
1428
- ge,
1429
- ye,
1430
- H,
1431
- L,
1432
- ae,
1433
- ue,
1434
- ce,
1435
- oe,
1436
- be,
1437
- he,
1438
- te,
1439
- l,
1440
- ie,
1441
- ne,
1442
- se
1443
- ]
1444
- ), Er = U(
1445
- () => ({
1446
- tracks: l.tracks,
1447
- currentIndex: l.currentIndex,
1448
- isPaused: l.isPaused,
1449
- isShuffled: l.isShuffled,
1450
- repeatMode: l.repeatMode,
1451
- originalTracks: l.originalTracks,
1452
- playlistMeta: l.playlistMeta,
1453
- init: ve,
1454
- play: D,
1455
- pause: C,
1456
- togglePlayPause: ne,
1457
- next: Q,
1458
- prev: H,
1459
- setRepeatMode: oe,
1460
- cycleRepeat: le,
1461
- toggleShuffle: se,
1462
- playbackMode: l.playbackMode,
1463
- setQueue: ce,
1464
- insertTrackAt: de,
1465
- removeTrackAt: fe,
1466
- moveTrack: pe,
1467
- enqueueNext: ge,
1468
- playTrackAt: me,
1469
- selectTrackAt: ye,
1470
- setPlaylistMeta: be,
1471
- setPlaybackMode: he,
1472
- dispatch: y
1473
- }),
1474
- [
1475
- l.tracks,
1476
- l.currentIndex,
1477
- l.isPaused,
1478
- l.isShuffled,
1479
- l.repeatMode,
1480
- l.playbackMode,
1481
- l.originalTracks,
1482
- l.playlistMeta,
1483
- ve,
1484
- D,
1485
- C,
1486
- ne,
1487
- Q,
1488
- H,
1489
- oe,
1490
- le,
1491
- se,
1492
- ce,
1493
- de,
1494
- fe,
1495
- pe,
1496
- ge,
1497
- me,
1498
- ye,
1499
- be,
1500
- he,
1501
- y
1502
- ]
1503
- ), Ar = U(
1504
- () => ({
1505
- currentTime: l.currentTime,
1506
- duration: l.duration,
1507
- bufferedFraction: l.bufferedFraction,
1508
- isBuffering: l.isBuffering,
1509
- errorMessage: l.errorMessage,
1510
- volume: l.volume,
1511
- muted: l.muted,
1512
- playbackRate: l.playbackRate,
1513
- seek: L,
1514
- setVolume: te,
1515
- setMuted: ae,
1516
- toggleMute: ie,
1517
- setPlaybackRate: ue,
1518
- audioRef: O,
1519
- notifyEnded: ke,
1520
- dispatch: y
1521
- }),
1522
- [
1523
- l.currentTime,
1524
- l.duration,
1525
- l.bufferedFraction,
1526
- l.isBuffering,
1527
- l.errorMessage,
1528
- l.volume,
1529
- l.muted,
1530
- l.playbackRate,
1531
- L,
1532
- te,
1533
- ae,
1534
- ie,
1535
- ue,
1536
- O,
1537
- ke,
1538
- y
1539
- ]
1540
- ), Pr = Qe(l), Rr = U(
1541
- () => G ? j : { ...hn, ...j },
1542
- [j, G]
1543
- );
1544
- return /* @__PURE__ */ s(tn, { locale: M, children: /* @__PURE__ */ s(Gr.Provider, { value: Er, children: /* @__PURE__ */ s(Nr.Provider, { value: Ar, children: /* @__PURE__ */ s(Oe.Provider, { value: Ir, children: /* @__PURE__ */ s(
1545
- "div",
1546
- {
1547
- className: Ae,
1548
- style: Rr,
1549
- "data-ginger-playback": Pr,
1550
- dir: xr,
1551
- children: e
1552
- }
1553
- ) }) }) }) });
1554
- }
1555
- const xn = {
1556
- Provider: vn,
1557
- Player: Dr,
1558
- Current: {
1559
- Title: Kr,
1560
- Artist: Xr,
1561
- Album: Wr,
1562
- Description: qr,
1563
- Copyright: zr,
1564
- Genre: Jr,
1565
- Label: Zr,
1566
- Isrc: en,
1567
- TrackNumber: rn,
1568
- Year: je,
1569
- Lyrics: Ke,
1570
- FileUrl: Xe,
1571
- Artwork: We,
1572
- QueueIndex: qe,
1573
- QueueLength: ze,
1574
- QueuePosition: Je,
1575
- Elapsed: Ze,
1576
- Duration: er,
1577
- Remaining: rr,
1578
- Progress: nr,
1579
- TimeRail: tr,
1580
- BufferRail: ar,
1581
- PlaybackState: ir,
1582
- ErrorMessage: ur
1583
- },
1584
- Queue: {
1585
- Title: dn,
1586
- Subtitle: fn,
1587
- Description: pn,
1588
- Copyright: gn,
1589
- Artwork: vr
1590
- },
1591
- Control: {
1592
- PlayPause: lr,
1593
- Repeat: sr,
1594
- Next: cr,
1595
- Previous: dr,
1596
- Shuffle: fr,
1597
- SeekBar: pr,
1598
- Volume: gr,
1599
- Mute: mr,
1600
- PlaybackRate: yr
1601
- },
1602
- Playlist: cn
1603
- };
1604
- export {
1605
- xn as G,
1606
- Ie as a,
1607
- Qe as b,
1608
- De as c,
1609
- xe as d,
1610
- on as e,
1611
- an as f,
1612
- un as g,
1613
- Hr as h,
1614
- Qr as i,
1615
- W as j,
1616
- V as k,
1617
- He as p,
1618
- jr as r,
1619
- _ as u
1620
- };
1621
- //# sourceMappingURL=ginger-BTPRqWHs.js.map