@lucaismyname/ginger 0.0.55 → 0.0.57

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