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