@lucaismyname/ginger 0.0.11 → 0.0.13

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