@lucaismyname/ginger 0.0.3 → 0.0.8

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