@lucaismyname/ginger 0.0.1 → 0.0.3

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.
package/dist/index.js CHANGED
@@ -1,204 +1,214 @@
1
- import { jsx as s, jsxs as De } from "react/jsx-runtime";
2
- import { useContext as Ne, createContext as we, useEffect as S, useRef as J, useReducer as Ue, useCallback as M, useMemo as D } from "react";
3
- const re = we(null);
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
4
  function g() {
5
- const e = Ne(re);
5
+ const e = ce(fe);
6
6
  if (!e) throw new Error("Ginger components must be used within <Ginger.Provider>");
7
7
  return e;
8
8
  }
9
- function Z(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);
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);
12
12
  }
13
- function Fe({ className: e, style: r, preload: n = "metadata", crossOrigin: t }) {
14
- var d;
15
- const { audioRef: i, dispatch: u, state: a, notifyEnded: l } = g(), c = ((d = a.tracks[a.currentIndex]) == null ? void 0 : d.fileUrl) ?? "";
16
- return S(() => {
17
- const o = i.current;
18
- if (o) {
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) {
19
22
  if (!c) {
20
- o.removeAttribute("src");
23
+ s.removeAttribute("src");
21
24
  return;
22
25
  }
23
- o.getAttribute("src") !== c && (o.src = c, o.load());
26
+ s.getAttribute("src") !== c && (s.src = c, s.load());
24
27
  }
25
- }, [i, a.currentIndex, a.tracks, c]), /* @__PURE__ */ s(
28
+ }, [i, u.currentIndex, u.tracks, c]), /* @__PURE__ */ l(
26
29
  "audio",
27
30
  {
28
31
  ref: i,
29
32
  className: e,
30
33
  style: r,
31
- preload: n,
32
- crossOrigin: t,
34
+ preload: t,
35
+ crossOrigin: n,
33
36
  controls: !1,
34
- onTimeUpdate: (o) => {
35
- const p = o.currentTarget;
36
- u({
37
+ onTimeUpdate: (s) => {
38
+ const d = s.currentTarget;
39
+ a({
37
40
  type: "MEDIA_TIME_UPDATE",
38
41
  payload: {
39
- currentTime: p.currentTime,
40
- duration: p.duration,
41
- bufferedFraction: Z(p)
42
+ currentTime: d.currentTime,
43
+ duration: d.duration,
44
+ bufferedFraction: le(d)
42
45
  }
43
46
  });
44
47
  },
45
- onLoadedMetadata: (o) => {
46
- const p = o.currentTarget;
47
- u({
48
+ onLoadedMetadata: (s) => {
49
+ const d = s.currentTarget;
50
+ a({
48
51
  type: "MEDIA_LOADED_METADATA",
49
52
  payload: {
50
- duration: p.duration,
51
- bufferedFraction: Z(p)
53
+ duration: d.duration,
54
+ bufferedFraction: le(d)
52
55
  }
53
56
  });
54
57
  },
55
- onEnded: () => l(),
56
- onPlay: () => u({ type: "MEDIA_PLAY" }),
57
- onPause: () => u({ type: "MEDIA_PAUSE" }),
58
- onWaiting: () => u({ type: "MEDIA_WAITING" }),
59
- onCanPlay: () => u({ type: "MEDIA_CANPLAY" }),
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({
66
+ type: "MEDIA_VOLUME_SYNC",
67
+ payload: { volume: d.volume, muted: d.muted }
68
+ });
69
+ },
60
70
  onError: () => {
61
- var m;
62
- const o = i.current, p = (m = o == null ? void 0 : o.error) == null ? void 0 : m.code;
63
- u({ type: "MEDIA_ERROR", payload: { message: p === 1 ? "MEDIA_ERR_ABORTED" : p === 2 ? "MEDIA_ERR_NETWORK" : p === 3 ? "MEDIA_ERR_DECODE" : p === 4 ? "MEDIA_ERR_SRC_NOT_SUPPORTED" : "MEDIA_ERR_UNKNOWN" } });
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" } });
64
74
  }
65
75
  }
66
76
  );
67
77
  }
68
- function E(e, r) {
78
+ function S(e, r) {
69
79
  return r <= 0 ? 0 : Math.max(0, Math.min(r - 1, e));
70
80
  }
71
- function ne(e, r) {
81
+ function pe(e, r) {
72
82
  if (e.length <= 1) return [...e];
73
- const n = e[r];
74
- if (!n) return [...e];
75
- const t = e.filter((i, u) => u !== r);
76
- for (let i = t.length - 1; i > 0; i--) {
77
- const u = Math.floor(Math.random() * (i + 1));
78
- [t[i], t[u]] = [t[u], t[i]];
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]];
79
89
  }
80
- return [n, ...t];
90
+ return [t, ...n];
81
91
  }
82
- function Le(e, r) {
83
- const n = e.findIndex((t) => t.fileUrl === r);
84
- return n === -1 ? 0 : n;
92
+ function qe(e, r) {
93
+ const t = e.findIndex((n) => n.fileUrl === r);
94
+ return t === -1 ? 0 : t;
85
95
  }
86
- function Qe(e) {
87
- const { tracks: r, currentIndex: n, repeatMode: t } = e, i = r.length;
88
- return i === 0 ? { kind: "stop", nextIndex: 0 } : t === "one" ? { kind: "replay_same" } : n < i - 1 ? { kind: "advance", nextIndex: n + 1 } : t === "all" ? { kind: "wrap", nextIndex: 0 } : { kind: "stop", nextIndex: E(n, i) };
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) };
89
99
  }
90
- function Be(e) {
91
- const { tracks: r, currentIndex: n, repeatMode: t } = e, i = r.length;
92
- return i === 0 ? 0 : n < i - 1 ? n + 1 : t === "all" ? 0 : E(n, i);
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);
93
103
  }
94
- function $e(e) {
95
- const { tracks: r, currentIndex: n, repeatMode: t } = e, i = r.length;
96
- return i === 0 ? 0 : n > 0 ? n - 1 : t === "all" ? i - 1 : 0;
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;
97
107
  }
98
- function Ye(e) {
108
+ function er(e) {
99
109
  return e === "off" ? "all" : e === "all" ? "one" : "off";
100
110
  }
101
- function Oe(e, r) {
111
+ function rr(e, r) {
102
112
  return (e == null ? void 0 : e.artworkUrl) ?? r ?? void 0;
103
113
  }
104
- function je(e, r) {
114
+ function tr(e, r) {
105
115
  return (e == null ? void 0 : e.album) ?? r ?? void 0;
106
116
  }
107
- function A(e) {
117
+ function E(e) {
108
118
  return e.tracks[e.currentIndex] ?? null;
109
119
  }
110
- function te(e) {
120
+ function ge(e) {
111
121
  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";
112
122
  }
113
- function R(e) {
114
- var t;
123
+ function C(e) {
124
+ var n;
115
125
  const r = e.duration;
116
126
  if (Number.isFinite(r) && r > 0) return r;
117
- const n = (t = e.tracks[e.currentIndex]) == null ? void 0 : t.durationSeconds;
118
- return typeof n == "number" && Number.isFinite(n) && n > 0 ? n : 0;
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;
119
129
  }
120
- function ie(e) {
121
- const n = R(e) - e.currentTime;
122
- return Number.isFinite(n) ? Math.max(0, n) : 0;
130
+ function ye(e) {
131
+ const t = C(e) - e.currentTime;
132
+ return Number.isFinite(t) ? Math.max(0, t) : 0;
123
133
  }
124
- function N(e) {
125
- const r = R(e);
134
+ function O(e) {
135
+ const r = C(e);
126
136
  return r > 0 ? Math.min(1, Math.max(0, e.currentTime / r)) : 0;
127
137
  }
128
- function ue(e) {
129
- var n;
130
- const r = A(e);
131
- return Oe(r, (n = e.playlistMeta) == null ? void 0 : n.artworkUrl);
138
+ function me(e) {
139
+ var t;
140
+ const r = E(e);
141
+ return rr(r, (t = e.playlistMeta) == null ? void 0 : t.artworkUrl);
132
142
  }
133
- function ae(e) {
134
- var n;
135
- const r = A(e);
136
- return je(r, (n = e.playlistMeta) == null ? void 0 : n.subtitle);
137
- }
138
- function T(e, r) {
139
- function n(t) {
140
- const { state: i } = g(), a = (r(i) ?? "").trim(), { className: l, style: c, fallback: d, empty: o, children: p } = t;
141
- if (!a) {
142
- const b = o ?? d ?? null;
143
- return b ? /* @__PURE__ */ s("span", { className: l, style: c, children: b }) : null;
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;
144
154
  }
145
- return p ? /* @__PURE__ */ s("span", { className: l, style: c, children: p(a, i) }) : /* @__PURE__ */ s("span", { className: l, style: c, children: a });
155
+ return d ? /* @__PURE__ */ l("span", { className: o, style: c, children: d(u, i) }) : /* @__PURE__ */ l("span", { className: o, style: c, children: u });
146
156
  }
147
- return n.displayName = e, n;
157
+ return t.displayName = e, t;
148
158
  }
149
159
  function I(e, r) {
150
- return T(e, (n) => r(A(n)));
160
+ return v(e, (t) => r(E(t)));
151
161
  }
152
- const Ve = I("Ginger.Current.Title", (e) => e == null ? void 0 : e.title), Xe = I("Ginger.Current.Artist", (e) => e == null ? void 0 : e.artist), We = T("Ginger.Current.Album", (e) => ae(e)), ze = I("Ginger.Current.Description", (e) => e == null ? void 0 : e.description), qe = T("Ginger.Current.Copyright", (e) => {
153
- var n;
154
- const r = A(e);
155
- return (r == null ? void 0 : r.copyright) ?? ((n = e.playlistMeta) == null ? void 0 : n.copyright);
156
- }), He = I("Ginger.Current.Genre", (e) => e == null ? void 0 : e.genre), Ke = I("Ginger.Current.Label", (e) => e == null ? void 0 : e.label), Je = I("Ginger.Current.Isrc", (e) => e == null ? void 0 : e.isrc), Ze = I(
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(
157
167
  "Ginger.Current.TrackNumber",
158
168
  (e) => (e == null ? void 0 : e.trackNumber) != null ? String(e.trackNumber) : void 0
159
169
  );
160
- function se({ className: e, style: r, fallback: n, empty: t, children: i, format: u }) {
161
- var d;
162
- const { state: a } = g(), l = (d = A(a)) == null ? void 0 : d.year;
163
- if (typeof l != "number" || !Number.isFinite(l)) {
164
- const o = t ?? n ?? null;
165
- return o ? /* @__PURE__ */ s("span", { className: e, style: r, children: o }) : null;
170
+ function be({ className: e, style: r, fallback: t, empty: n, children: i, format: a }) {
171
+ 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;
166
176
  }
167
- const c = u ? u(l) : String(l);
168
- return i ? /* @__PURE__ */ s("span", { className: e, style: r, children: i(c, a) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: c });
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 });
169
179
  }
170
- se.displayName = "Ginger.Current.Year";
171
- function le({ className: e, style: r, fallback: n, empty: t, children: i, preserveWhitespace: u = !0 }) {
172
- var o;
173
- const { state: a } = g(), l = ((o = A(a)) == null ? void 0 : o.lyrics) ?? "", c = u ? l.replace(/^\s+|\s+$/g, "") : l.trim();
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();
174
184
  if (!c) {
175
- const p = t ?? n ?? null;
176
- return p ? /* @__PURE__ */ s("span", { className: e, style: r, children: p }) : null;
185
+ const d = n ?? t ?? null;
186
+ return d ? /* @__PURE__ */ l("span", { className: e, style: r, children: d }) : null;
177
187
  }
178
- const d = u ? { whiteSpace: "pre-wrap" } : void 0;
179
- return i ? /* @__PURE__ */ s("span", { className: e, style: { ...d, ...r }, children: i(c, a) }) : /* @__PURE__ */ s("span", { className: e, style: { ...d, ...r }, children: c });
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 });
180
190
  }
181
- le.displayName = "Ginger.Current.Lyrics";
182
- function oe({ visible: e = !1, className: r, style: n, fallback: t, empty: i, children: u }) {
191
+ Pe.displayName = "Ginger.Current.Lyrics";
192
+ function ke({ visible: e = !1, className: r, style: t, fallback: n, empty: i, children: a }) {
183
193
  var c;
184
- const { state: a } = g();
194
+ const { state: u } = g();
185
195
  if (!e) return null;
186
- const l = ((c = A(a)) == null ? void 0 : c.fileUrl) ?? "";
187
- if (!l) {
188
- const d = i ?? t ?? null;
189
- return d ? /* @__PURE__ */ s("span", { className: r, style: n, children: d }) : 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;
190
200
  }
191
- return u ? /* @__PURE__ */ s("span", { className: r, style: n, children: u(l, a) }) : /* @__PURE__ */ s("span", { className: r, style: n, children: l });
192
- }
193
- oe.displayName = "Ginger.Current.FileUrl";
194
- function ce({ className: e, style: r, fallback: n, empty: t, sizes: i, loading: u, onError: a, decoding: l, imgStyle: c }) {
195
- const { state: d } = g(), o = A(d), p = ue(d);
196
- if (!p) {
197
- const m = t ?? n ?? null;
198
- return m ? /* @__PURE__ */ s("span", { className: e, style: r, children: m }) : null;
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;
199
209
  }
200
- const b = [o == null ? void 0 : o.title, o == null ? void 0 : o.artist].filter(Boolean).join(" — ") || "Artwork";
201
- return /* @__PURE__ */ s(
210
+ const y = [s == null ? void 0 : s.title, s == null ? void 0 : s.artist].filter(Boolean).join(" — ") || "Artwork";
211
+ return /* @__PURE__ */ l(
202
212
  "span",
203
213
  {
204
214
  className: e,
@@ -209,15 +219,15 @@ function ce({ className: e, style: r, fallback: n, empty: t, sizes: i, loading:
209
219
  overflow: "hidden",
210
220
  ...r
211
221
  },
212
- children: /* @__PURE__ */ s(
222
+ children: /* @__PURE__ */ l(
213
223
  "img",
214
224
  {
215
- src: p,
216
- alt: b,
225
+ src: d,
226
+ alt: y,
217
227
  sizes: i,
218
- loading: u,
219
- decoding: l,
220
- onError: a,
228
+ loading: a,
229
+ decoding: o,
230
+ onError: u,
221
231
  style: {
222
232
  display: "block",
223
233
  width: "100%",
@@ -230,238 +240,338 @@ function ce({ className: e, style: r, fallback: n, empty: t, sizes: i, loading:
230
240
  }
231
241
  );
232
242
  }
233
- ce.displayName = "Ginger.Current.Artwork";
234
- function de({ base: e = 0, className: r, style: n, fallback: t, empty: i, children: u }) {
235
- const { state: a } = g();
236
- if (a.tracks.length === 0) {
237
- const d = i ?? t ?? null;
238
- return d ? /* @__PURE__ */ s("span", { className: r, style: n, children: d }) : null;
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;
239
249
  }
240
- const c = String(a.currentIndex + e);
241
- return u ? /* @__PURE__ */ s("span", { className: r, style: n, children: u(c, a) }) : /* @__PURE__ */ s("span", { className: r, style: n, children: c });
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 });
242
252
  }
243
- de.displayName = "Ginger.Current.QueueIndex";
244
- function fe({ className: e, style: r, fallback: n, empty: t, children: i }) {
245
- const { state: u } = g(), a = String(u.tracks.length);
246
- if (u.tracks.length === 0) {
247
- const l = t ?? n ?? null;
248
- return l ? /* @__PURE__ */ s("span", { className: e, style: r, children: l }) : null;
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;
249
259
  }
250
- return i ? /* @__PURE__ */ s("span", { className: e, style: r, children: i(a, u) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: a });
260
+ return i ? /* @__PURE__ */ l("span", { className: e, style: r, children: i(u, a) }) : /* @__PURE__ */ l("span", { className: e, style: r, children: u });
251
261
  }
252
- fe.displayName = "Ginger.Current.QueueLength";
253
- function pe({
262
+ Ee.displayName = "Ginger.Current.QueueLength";
263
+ function Ae({
254
264
  base: e = 0,
255
265
  separator: r = " / ",
256
- className: n,
257
- style: t,
266
+ className: t,
267
+ style: n,
258
268
  fallback: i,
259
- empty: u,
260
- children: a
269
+ empty: a,
270
+ children: u
261
271
  }) {
262
- const { state: l } = g(), c = l.tracks.length;
272
+ const { state: o } = g(), c = o.tracks.length;
263
273
  if (c === 0) {
264
- const b = u ?? i ?? null;
265
- return b ? /* @__PURE__ */ s("span", { className: n, style: t, children: b }) : null;
274
+ const y = a ?? i ?? null;
275
+ return y ? /* @__PURE__ */ l("span", { className: t, style: n, children: y }) : null;
266
276
  }
267
- const d = String(l.currentIndex + e), o = String(c), p = `${d}${r}${o}`;
268
- return a ? /* @__PURE__ */ s("span", { className: n, style: t, children: a({ index: d, length: o, label: p }, l) }) : /* @__PURE__ */ s("span", { className: n, style: t, children: p });
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 });
269
279
  }
270
- pe.displayName = "Ginger.Current.QueuePosition";
271
- function er(e) {
280
+ Ae.displayName = "Ginger.Current.QueuePosition";
281
+ function fr(e) {
272
282
  if (!Number.isFinite(e) || e < 0) return "0:00";
273
283
  const r = Math.floor(e % 60);
274
284
  return `${Math.floor(e / 60)}:${r.toString().padStart(2, "0")}`;
275
285
  }
276
- function w(e, r, n) {
277
- const { className: t, style: i, fallback: u, empty: a, children: l, format: c = er } = n;
286
+ function Y(e, r, t) {
287
+ const { className: n, style: i, fallback: a, empty: u, children: o, format: c = fr } = t;
278
288
  if (!(e >= 0) || !Number.isFinite(e)) {
279
- const o = a ?? u ?? null;
280
- return o ? /* @__PURE__ */ s("span", { className: t, style: i, children: o }) : null;
289
+ const s = u ?? a ?? null;
290
+ return s ? /* @__PURE__ */ l("span", { className: n, style: i, children: s }) : null;
281
291
  }
282
- const d = c(e);
283
- return l ? /* @__PURE__ */ s("span", { className: t, style: i, children: l(d, r) }) : /* @__PURE__ */ s("span", { className: t, style: i, children: d });
292
+ 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 });
284
294
  }
285
- function ge(e) {
295
+ function xe(e) {
286
296
  const { state: r } = g();
287
- return w(r.currentTime, r, e);
297
+ return Y(r.currentTime, r, e);
288
298
  }
289
- ge.displayName = "Ginger.Current.Elapsed";
290
- function ye(e) {
299
+ xe.displayName = "Ginger.Current.Elapsed";
300
+ function ve(e) {
291
301
  const { state: r } = g();
292
- return w(R(r), r, e);
302
+ return Y(C(r), r, e);
293
303
  }
294
- ye.displayName = "Ginger.Current.Duration";
295
- function he(e) {
304
+ ve.displayName = "Ginger.Current.Duration";
305
+ function Ie(e) {
296
306
  const { state: r } = g();
297
- return w(ie(r), r, e);
298
- }
299
- he.displayName = "Ginger.Current.Remaining";
300
- function me({ className: e, style: r, fallback: n, empty: t, children: i }) {
301
- const { state: u } = g(), a = R(u), l = N(u);
302
- if (!(a > 0)) {
303
- const c = t ?? n ?? null;
304
- return c ? /* @__PURE__ */ s("span", { className: e, style: r, children: c }) : null;
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;
305
315
  }
306
- return i ? /* @__PURE__ */ s("span", { className: e, style: r, children: i({ fraction: l, currentTime: u.currentTime, duration: a }, u) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: `${Math.round(l * 100)}%` });
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)}%` });
307
317
  }
308
- me.displayName = "Ginger.Current.Progress";
309
- function Pe({ className: e, style: r, height: n = 4 }) {
310
- const { state: t } = g(), i = `${Math.round(N(t) * 100)}%`;
311
- return /* @__PURE__ */ s(
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(
312
322
  "div",
313
323
  {
314
324
  className: e,
315
325
  style: {
316
326
  width: "100%",
317
- height: n,
327
+ height: t,
318
328
  background: "var(--ginger-muted-color, #e5e7eb)",
319
329
  borderRadius: 999,
320
330
  overflow: "hidden",
321
331
  ...r
322
332
  },
323
333
  "aria-hidden": !0,
324
- children: /* @__PURE__ */ s("div", { style: { width: i, height: "100%", background: "var(--ginger-primary-color, #111827)" } })
334
+ children: /* @__PURE__ */ l("div", { style: { width: i, height: "100%", background: "var(--ginger-primary-color, #111827)" } })
325
335
  }
326
336
  );
327
337
  }
328
- Pe.displayName = "Ginger.Current.TimeRail";
329
- function Me({ className: e, style: r, fallback: n, empty: t, children: i }) {
330
- const { state: u } = g(), a = te(u);
331
- return i ? /* @__PURE__ */ s("span", { className: e, style: r, children: i(a, u) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: a });
332
- }
333
- Me.displayName = "Ginger.Current.PlaybackState";
334
- function be({ className: e, style: r, fallback: n, empty: t, children: i }) {
335
- const { state: u } = g(), a = u.errorMessage ?? "";
336
- if (!a) {
337
- const l = t ?? n ?? null;
338
- return l ? /* @__PURE__ */ s("span", { className: e, style: r, children: l }) : null;
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;
339
349
  }
340
- return i ? /* @__PURE__ */ s("span", { className: e, style: r, children: i(a, u) }) : /* @__PURE__ */ s("span", { className: e, style: r, children: a });
350
+ return i ? /* @__PURE__ */ l("span", { className: e, style: r, children: i(u, a) }) : /* @__PURE__ */ l("span", { className: e, style: r, children: u });
341
351
  }
342
- be.displayName = "Ginger.Current.ErrorMessage";
343
- function ke({ playLabel: e = "Play", pauseLabel: r = "Pause", type: n = "button", ...t }) {
344
- const { state: i, togglePlayPause: u } = g();
345
- return /* @__PURE__ */ s("button", { type: n, "aria-label": i.isPaused ? "Play" : "Pause", onClick: u, ...t, children: i.isPaused ? e : r });
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 });
346
356
  }
347
- ke.displayName = "Ginger.Control.PlayPause";
348
- const ee = {
357
+ _e.displayName = "Ginger.Control.PlayPause";
358
+ const oe = {
349
359
  off: "Repeat off",
350
360
  all: "Repeat all",
351
361
  one: "Repeat one"
352
362
  };
353
- function xe({ type: e = "button", ...r }) {
354
- const { state: n, cycleRepeat: t } = g();
355
- return /* @__PURE__ */ s("button", { type: e, "aria-label": ee[n.repeatMode], onClick: t, ...r, children: ee[n.repeatMode] });
356
- }
357
- xe.displayName = "Ginger.Control.Repeat";
358
- function Ae({ type: e = "button", children: r = "Next", ...n }) {
359
- const { next: t } = g();
360
- return /* @__PURE__ */ s("button", { type: e, "aria-label": "Next track", onClick: t, ...n, children: r });
361
- }
362
- Ae.displayName = "Ginger.Control.Next";
363
- function Te({ type: e = "button", children: r = "Previous", ...n }) {
364
- const { prev: t } = g();
365
- return /* @__PURE__ */ s("button", { type: e, "aria-label": "Previous track", onClick: t, ...n, children: r });
366
- }
367
- Te.displayName = "Ginger.Control.Previous";
368
- function Ie({ type: e = "button", children: r = "Shuffle", ...n }) {
369
- const { state: t, toggleShuffle: i } = g();
370
- return /* @__PURE__ */ s("button", { type: e, "aria-pressed": t.isShuffled, "aria-label": "Shuffle", onClick: i, ...n, children: r });
371
- }
372
- Ie.displayName = "Ginger.Control.Shuffle";
373
- function Ee({ inputStyle: e, style: r, ...n }) {
374
- const { state: t, seek: i } = g(), u = Number.isFinite(t.duration) && t.duration > 0 ? t.duration : 0, a = u > 0 ? t.currentTime : 0;
375
- return /* @__PURE__ */ s(
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(
376
386
  "input",
377
387
  {
378
388
  type: "range",
379
389
  min: 0,
380
- max: u > 0 ? u : 1,
390
+ max: a > 0 ? a : 1,
381
391
  step: "any",
382
- value: Number.isFinite(a) ? a : 0,
392
+ value: Number.isFinite(u) ? u : 0,
383
393
  "aria-label": "Seek",
384
- onChange: (l) => i(Number(l.currentTarget.value)),
394
+ onChange: (o) => i(Number(o.currentTarget.value)),
385
395
  style: { width: "100%", ...r, ...e },
386
- ...n
396
+ ...t
397
+ }
398
+ );
399
+ }
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(
404
+ "input",
405
+ {
406
+ 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
415
+ }
416
+ );
417
+ }
418
+ Fe.displayName = "Ginger.Control.Volume";
419
+ function Oe({
420
+ muteLabel: e = "Mute",
421
+ unmuteLabel: r = "Unmute",
422
+ type: t = "button",
423
+ ...n
424
+ }) {
425
+ const { state: i, toggleMute: a } = g();
426
+ return /* @__PURE__ */ l(
427
+ "button",
428
+ {
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
387
435
  }
388
436
  );
389
437
  }
390
- Ee.displayName = "Ginger.Control.SeekBar";
391
- function Se({
392
- rowStyle: e,
393
- renderTrack: r,
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]
444
+ );
445
+ return /* @__PURE__ */ l(
446
+ "select",
447
+ {
448
+ "aria-label": "Playback speed",
449
+ value: String(n.playbackRate),
450
+ 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))
454
+ }
455
+ );
456
+ }
457
+ Ye.displayName = "Ginger.Control.PlaybackRate";
458
+ const F = de(null);
459
+ function gr() {
460
+ const e = ce(F);
461
+ if (!e)
462
+ throw new Error("Ginger.Playlist.Track must be used inside <Ginger.Playlist>");
463
+ return e;
464
+ }
465
+ function Be({
466
+ children: e,
467
+ rowStyle: r,
468
+ renderTrack: t,
394
469
  playOnSelect: n = !0,
470
+ style: i,
471
+ ...a
472
+ }) {
473
+ const { state: u, playTrackAt: o, selectTrackAt: c } = g(), f = {
474
+ listStyle: "none",
475
+ margin: 0,
476
+ padding: 0,
477
+ fontFamily: "var(--ginger-font-family, system-ui, sans-serif)",
478
+ fontSize: "var(--ginger-font-size, 14px)",
479
+ color: "var(--ginger-primary-color, #111827)",
480
+ ...i
481
+ };
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(
485
+ "button",
486
+ {
487
+ type: "button",
488
+ onClick: () => {
489
+ n ? o(y) : c(y);
490
+ },
491
+ style: {
492
+ width: "100%",
493
+ textAlign: "left",
494
+ border: "none",
495
+ background: P ? "rgba(17, 24, 39, 0.06)" : "transparent",
496
+ color: "inherit",
497
+ font: "inherit",
498
+ cursor: "pointer",
499
+ padding: "var(--ginger-playlist-row-padding, 6px 8px)",
500
+ ...r
501
+ },
502
+ children: t ? t(d, y, P) : /* @__PURE__ */ se("span", { children: [
503
+ d.title,
504
+ d.artist ? ` — ${d.artist}` : ""
505
+ ] })
506
+ }
507
+ ) }, `${d.fileUrl}-${y}`);
508
+ }) }) });
509
+ }
510
+ Be.displayName = "Ginger.Playlist";
511
+ function Ve({
512
+ index: e,
513
+ className: r,
395
514
  style: t,
396
- ...i
515
+ children: n,
516
+ liProps: i,
517
+ onClick: a,
518
+ ...u
397
519
  }) {
398
- const { state: u, playTrackAt: a, selectTrackAt: l } = g();
399
- return /* @__PURE__ */ s(
400
- "ul",
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: [
521
+ y.title,
522
+ y.artist ? ` — ${y.artist}` : ""
523
+ ] }) : null;
524
+ return /* @__PURE__ */ l("li", { ...i, children: /* @__PURE__ */ l(
525
+ "button",
401
526
  {
527
+ type: "button",
528
+ "aria-current": d ? "true" : void 0,
529
+ "data-ginger-active": d || void 0,
530
+ className: r,
402
531
  style: {
403
- listStyle: "none",
404
- margin: 0,
405
- padding: 0,
406
- fontFamily: "var(--ginger-font-family, system-ui, sans-serif)",
407
- fontSize: "var(--ginger-font-size, 14px)",
408
- color: "var(--ginger-primary-color, #111827)",
532
+ width: "100%",
533
+ textAlign: "left",
534
+ border: "none",
535
+ background: d ? "rgba(17, 24, 39, 0.06)" : "transparent",
536
+ color: "inherit",
537
+ font: "inherit",
538
+ cursor: "pointer",
539
+ padding: "var(--ginger-playlist-row-padding, 6px 8px)",
409
540
  ...t
410
541
  },
411
- ...i,
412
- children: u.tracks.map((c, d) => {
413
- const o = d === u.currentIndex;
414
- return /* @__PURE__ */ s("li", { children: /* @__PURE__ */ s(
415
- "button",
416
- {
417
- type: "button",
418
- onClick: () => {
419
- n ? a(d) : l(d);
420
- },
421
- style: {
422
- width: "100%",
423
- textAlign: "left",
424
- border: "none",
425
- background: o ? "rgba(17, 24, 39, 0.06)" : "transparent",
426
- color: "inherit",
427
- font: "inherit",
428
- cursor: "pointer",
429
- padding: "var(--ginger-playlist-row-padding, 6px 8px)",
430
- ...e
431
- },
432
- children: r ? r(c, d, o) : /* @__PURE__ */ De("span", { children: [
433
- c.title,
434
- c.artist ? ` — ${c.artist}` : ""
435
- ] })
436
- }
437
- ) }, `${c.fileUrl}-${d}`);
438
- })
542
+ ...u,
543
+ onClick: (x) => {
544
+ a == null || a(x), !x.defaultPrevented && (o ? f(e) : s(e));
545
+ },
546
+ children: n ?? P
439
547
  }
440
- );
548
+ ) });
441
549
  }
442
- Se.displayName = "Ginger.Playlist";
443
- const rr = T("Ginger.Queue.Title", (e) => {
550
+ Ve.displayName = "Ginger.Playlist.Track";
551
+ const yr = Object.assign(Be, {
552
+ Track: Ve
553
+ }), mr = v("Ginger.Queue.Title", (e) => {
444
554
  var r;
445
555
  return (r = e.playlistMeta) == null ? void 0 : r.title;
446
- }), nr = T("Ginger.Queue.Subtitle", (e) => {
556
+ }), hr = v("Ginger.Queue.Subtitle", (e) => {
447
557
  var r;
448
558
  return (r = e.playlistMeta) == null ? void 0 : r.subtitle;
449
- }), tr = T("Ginger.Queue.Description", (e) => {
559
+ }), br = v("Ginger.Queue.Description", (e) => {
450
560
  var r;
451
561
  return (r = e.playlistMeta) == null ? void 0 : r.description;
452
- }), ir = T("Ginger.Queue.Copyright", (e) => {
562
+ }), Pr = v("Ginger.Queue.Copyright", (e) => {
453
563
  var r;
454
564
  return (r = e.playlistMeta) == null ? void 0 : r.copyright;
455
565
  });
456
- function ve({ className: e, style: r, fallback: n, empty: t, imgStyle: i }) {
457
- var c, d;
458
- const { state: u } = g(), a = (c = u.playlistMeta) == null ? void 0 : c.artworkUrl;
459
- if (!a) {
460
- const o = t ?? n ?? null;
461
- return o ? /* @__PURE__ */ s("span", { className: e, style: r, children: o }) : null;
566
+ function $e({ className: e, style: r, fallback: t, empty: n, imgStyle: i }) {
567
+ 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;
462
572
  }
463
- const l = ((d = u.playlistMeta) == null ? void 0 : d.title) ?? "Playlist artwork";
464
- return /* @__PURE__ */ s(
573
+ const o = ((f = a.playlistMeta) == null ? void 0 : f.title) ?? "Playlist artwork";
574
+ return /* @__PURE__ */ l(
465
575
  "span",
466
576
  {
467
577
  className: e,
@@ -472,11 +582,11 @@ function ve({ className: e, style: r, fallback: n, empty: t, imgStyle: i }) {
472
582
  overflow: "hidden",
473
583
  ...r
474
584
  },
475
- children: /* @__PURE__ */ s(
585
+ children: /* @__PURE__ */ l(
476
586
  "img",
477
587
  {
478
- src: a,
479
- alt: l,
588
+ src: u,
589
+ alt: o,
480
590
  style: {
481
591
  display: "block",
482
592
  width: "100%",
@@ -489,56 +599,83 @@ function ve({ className: e, style: r, fallback: n, empty: t, imgStyle: i }) {
489
599
  }
490
600
  );
491
601
  }
492
- ve.displayName = "Ginger.Queue.Artwork";
493
- const v = {
602
+ $e.displayName = "Ginger.Queue.Artwork";
603
+ function L(e) {
604
+ return Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 1;
605
+ }
606
+ function B(e) {
607
+ return Number.isFinite(e) ? Math.min(4, Math.max(0.25, e)) : 1;
608
+ }
609
+ const G = {
494
610
  currentTime: 0,
495
611
  duration: 0,
496
612
  bufferedFraction: 0,
497
613
  isBuffering: !1,
498
614
  errorMessage: null
615
+ }, kr = {
616
+ ...G,
617
+ volume: 1,
618
+ muted: !1,
619
+ playbackRate: 1
499
620
  };
500
- function Re(e) {
621
+ function Qe(e) {
501
622
  const r = [...e.tracks];
502
- let n = E(e.currentIndex ?? 0, r.length), t = null, i = r;
503
- return e.isShuffled && r.length > 1 && (t = [...r], i = ne(r, n), n = 0), {
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), {
504
625
  tracks: i,
505
- currentIndex: n,
626
+ currentIndex: t,
506
627
  isPaused: e.isPaused ?? !0,
507
628
  isShuffled: !!(e.isShuffled && i.length > 1),
508
629
  repeatMode: e.repeatMode ?? "off",
509
- originalTracks: t,
630
+ originalTracks: n,
510
631
  playlistMeta: e.playlistMeta ?? null,
511
- ...v
632
+ ...kr,
633
+ volume: L(e.volume ?? 1),
634
+ muted: e.muted ?? !1,
635
+ playbackRate: B(e.playbackRate ?? 1)
512
636
  };
513
637
  }
514
- function ur(e, r) {
638
+ function Mr(e, r) {
515
639
  switch (r.type) {
516
640
  case "INIT": {
517
- const { tracks: n, currentIndex: t, playlistMeta: i, isPaused: u, isShuffled: a, repeatMode: l } = r.payload;
518
- return Re({
519
- tracks: n,
520
- currentIndex: t,
641
+ const {
642
+ tracks: t,
643
+ currentIndex: n,
644
+ playlistMeta: i,
645
+ isPaused: a,
646
+ isShuffled: u,
647
+ repeatMode: o,
648
+ volume: c,
649
+ muted: f,
650
+ playbackRate: s
651
+ } = r.payload;
652
+ return Qe({
653
+ tracks: t,
654
+ currentIndex: n,
521
655
  playlistMeta: i ?? null,
522
- isPaused: u ?? !0,
523
- isShuffled: a ?? !1,
524
- repeatMode: l ?? "off"
656
+ isPaused: a ?? !0,
657
+ isShuffled: u ?? !1,
658
+ repeatMode: o ?? "off",
659
+ volume: c,
660
+ muted: f,
661
+ playbackRate: s
525
662
  });
526
663
  }
527
664
  case "SET_QUEUE": {
528
- const { tracks: n, currentIndex: t } = r.payload, i = [...n], u = E(t ?? e.currentIndex, i.length);
665
+ const { tracks: t, currentIndex: n } = r.payload, i = [...t], a = S(n ?? e.currentIndex, i.length);
529
666
  return {
530
667
  ...e,
531
668
  tracks: i,
532
- currentIndex: u,
533
- ...v
669
+ currentIndex: a,
670
+ ...G
534
671
  };
535
672
  }
536
673
  case "SET_INDEX": {
537
- const n = E(r.payload.index, e.tracks.length), t = r.payload.autoPlay, i = t === !0 ? !1 : t === !1 ? !0 : e.isPaused;
674
+ const t = S(r.payload.index, e.tracks.length), n = r.payload.autoPlay, i = n === !0 ? !1 : n === !1 ? !0 : e.isPaused;
538
675
  return {
539
676
  ...e,
540
- currentIndex: n,
541
- ...v,
677
+ currentIndex: t,
678
+ ...G,
542
679
  isPaused: i
543
680
  };
544
681
  }
@@ -551,44 +688,44 @@ function ur(e, r) {
551
688
  case "SET_REPEAT":
552
689
  return { ...e, repeatMode: r.payload };
553
690
  case "CYCLE_REPEAT":
554
- return { ...e, repeatMode: Ye(e.repeatMode) };
691
+ return { ...e, repeatMode: er(e.repeatMode) };
555
692
  case "TOGGLE_SHUFFLE": {
556
693
  if (e.tracks.length <= 1) return { ...e, isShuffled: !1, originalTracks: null };
557
694
  if (!e.isShuffled) {
558
- const a = [...e.tracks], l = ne(a, e.currentIndex);
695
+ const u = [...e.tracks], o = pe(u, e.currentIndex);
559
696
  return {
560
697
  ...e,
561
698
  isShuffled: !0,
562
- originalTracks: a,
563
- tracks: l,
699
+ originalTracks: u,
700
+ tracks: o,
564
701
  currentIndex: 0
565
702
  };
566
703
  }
567
- const n = e.originalTracks ? [...e.originalTracks] : [...e.tracks], t = e.tracks[e.currentIndex], i = (t == null ? void 0 : t.fileUrl) ?? "", u = Le(n, i);
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);
568
705
  return {
569
706
  ...e,
570
707
  isShuffled: !1,
571
708
  originalTracks: null,
572
- tracks: n,
573
- currentIndex: E(u, n.length)
709
+ tracks: t,
710
+ currentIndex: S(a, t.length)
574
711
  };
575
712
  }
576
713
  case "NEXT": {
577
- const n = Be(e), t = n === e.currentIndex;
714
+ const t = Je(e), n = t === e.currentIndex;
578
715
  return {
579
716
  ...e,
580
- currentIndex: n,
581
- ...t ? {} : v,
582
- isPaused: t ? e.isPaused : !1
717
+ currentIndex: t,
718
+ ...n ? {} : G,
719
+ isPaused: n ? e.isPaused : !1
583
720
  };
584
721
  }
585
722
  case "PREV": {
586
- const n = $e(e), t = n === e.currentIndex;
723
+ const t = Ze(e), n = t === e.currentIndex;
587
724
  return {
588
725
  ...e,
589
- currentIndex: n,
590
- ...t ? {} : v,
591
- isPaused: t ? e.isPaused : !1
726
+ currentIndex: t,
727
+ ...n ? {} : G,
728
+ isPaused: n ? e.isPaused : !1
592
729
  };
593
730
  }
594
731
  case "MEDIA_TIME_UPDATE":
@@ -625,11 +762,23 @@ function ur(e, r) {
625
762
  return { ...e, isPaused: !0 };
626
763
  case "RESET_MEDIA_TIMES":
627
764
  return { ...e, currentTime: 0, duration: 0, bufferedFraction: 0 };
765
+ case "SET_VOLUME":
766
+ return { ...e, volume: L(r.payload) };
767
+ case "SET_MUTED":
768
+ return { ...e, muted: r.payload };
769
+ case "TOGGLE_MUTE":
770
+ return { ...e, muted: !e.muted };
771
+ case "SET_PLAYBACK_RATE":
772
+ return { ...e, playbackRate: B(r.payload) };
773
+ 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 };
776
+ }
628
777
  default:
629
778
  return e;
630
779
  }
631
780
  }
632
- const ar = {
781
+ const Tr = {
633
782
  "--ginger-primary-color": "#111827",
634
783
  "--ginger-muted-color": "#6b7280",
635
784
  "--ginger-font-size": "14px",
@@ -638,226 +787,243 @@ const ar = {
638
787
  "--ginger-artwork-radius": "6px",
639
788
  "--ginger-artwork-bg": "#f3f4f6"
640
789
  };
641
- function sr({
790
+ function Er({
642
791
  children: e,
643
792
  initialTracks: r = [],
644
- initialIndex: n = 0,
645
- initialPlaylistMeta: t = null,
793
+ initialIndex: t = 0,
794
+ initialPlaylistMeta: n = null,
646
795
  initialShuffle: i = !1,
647
- initialRepeatMode: u = "off",
648
- initialPaused: a = !0,
649
- className: l,
650
- style: c,
651
- onTrackChange: d,
652
- onPlay: o,
653
- onPause: p,
654
- onQueueEnd: b,
655
- onError: m
796
+ initialRepeatMode: a = "off",
797
+ initialPaused: u = !0,
798
+ initialVolume: o = 1,
799
+ initialMuted: c = !1,
800
+ initialPlaybackRate: f = 1,
801
+ className: s,
802
+ style: d,
803
+ onTrackChange: y,
804
+ onPlay: P,
805
+ onPause: x,
806
+ onQueueEnd: _,
807
+ onError: M
656
808
  }) {
657
- var K;
658
- const k = J(null), [y, P] = Ue(
659
- ur,
809
+ var ae;
810
+ const A = ue(null), [m, h] = Ke(
811
+ Mr,
660
812
  void 0,
661
- () => Re({
813
+ () => Qe({
662
814
  tracks: r,
663
- currentIndex: n,
664
- playlistMeta: t,
665
- isPaused: a,
815
+ currentIndex: t,
816
+ playlistMeta: n,
817
+ isPaused: u,
666
818
  isShuffled: i,
667
- repeatMode: u
819
+ repeatMode: a,
820
+ volume: o,
821
+ muted: c,
822
+ playbackRate: f
668
823
  })
669
- ), U = y.tracks[y.currentIndex] ?? null;
670
- S(() => {
671
- d == null || d(U, y.currentIndex);
672
- }, [U, y.currentIndex, d]), S(() => {
673
- y.errorMessage && (m == null || m(y.errorMessage));
674
- }, [y.errorMessage, m]);
675
- const C = J(void 0);
676
- S(() => {
677
- if (C.current === void 0) {
678
- C.current = y.isPaused;
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;
679
834
  return;
680
835
  }
681
- C.current !== y.isPaused && (y.isPaused ? p == null || p() : o == null || o()), C.current = y.isPaused;
682
- }, [y.isPaused, p, o]);
683
- const G = M(() => {
684
- var f;
685
- P({ type: "PLAY" }), (f = k.current) == null || f.play().catch((h) => {
686
- P({ type: "PAUSE" });
687
- const x = h instanceof Error ? h.message : "Playback failed";
688
- m == null || m(x);
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);
689
844
  });
690
- }, [m]), _ = M(() => {
691
- var f;
692
- P({ type: "PAUSE" }), (f = k.current) == null || f.pause();
693
- }, []), F = M(() => {
694
- y.isPaused ? G() : _();
695
- }, [_, G, y.isPaused]), L = M((f) => {
696
- const h = k.current;
697
- h && Number.isFinite(f) && (h.currentTime = Math.max(0, f));
698
- }, []), Q = M((f) => {
699
- const h = k.current;
700
- h && (h.volume = Math.min(1, Math.max(0, f)));
701
- }, []), B = M((f) => {
702
- const h = k.current;
703
- h && (h.muted = f);
704
- }, []), $ = M(() => {
705
- P({ type: "NEXT" });
706
- }, []), Y = M(() => {
707
- P({ type: "PREV" });
708
- }, []), O = M((f) => {
709
- P({ type: "SET_REPEAT", payload: f });
710
- }, []), j = M(() => {
711
- P({ type: "CYCLE_REPEAT" });
712
- }, []), V = M(() => {
713
- P({ type: "TOGGLE_SHUFFLE" });
714
- }, []), X = M((f, h) => {
715
- P({ type: "SET_QUEUE", payload: { tracks: f, currentIndex: h } });
716
- }, []), W = M((f) => {
717
- P({ type: "SET_INDEX", payload: { index: f, autoPlay: !0 } }), queueMicrotask(() => {
718
- var h;
719
- (h = k.current) == null || h.play().catch(() => {
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(() => {
720
877
  });
721
878
  });
722
- }, []), z = M((f) => {
723
- P({ type: "SET_INDEX", payload: { index: f, autoPlay: !1 } });
724
- }, []), q = M((f) => {
725
- P({ type: "SET_PLAYLIST_META", payload: f });
726
- }, []), Ce = (K = y.tracks[y.currentIndex]) == null ? void 0 : K.fileUrl;
727
- S(() => {
728
- const f = k.current;
729
- f && (y.isPaused ? f.pause() : f.play().catch((h) => {
730
- P({ type: "PAUSE" });
731
- const x = h instanceof Error ? h.message : "Playback failed";
732
- m == null || m(x);
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);
733
890
  }));
734
- }, [y.isPaused, Ce, m]);
735
- const H = M(() => {
736
- const f = Qe(y);
737
- if (f.kind === "replay_same") {
738
- const x = k.current;
739
- x && (x.currentTime = 0, x.play().catch(() => {
740
- })), P({ type: "PLAY" });
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" });
741
898
  return;
742
899
  }
743
- if (f.kind === "stop") {
744
- P({ type: "PAUSE" }), b == null || b();
900
+ if (p.kind === "stop") {
901
+ h({ type: "PAUSE" }), _ == null || _();
745
902
  return;
746
903
  }
747
- const h = f.nextIndex;
748
- P({ type: "SET_INDEX", payload: { index: h, autoPlay: !0 } }), queueMicrotask(() => {
749
- var x;
750
- (x = k.current) == null || x.play().catch(() => {
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(() => {
751
908
  });
752
909
  });
753
- }, [b, y]), Ge = D(
910
+ }, [_, m]), Xe = U(
754
911
  () => ({
755
- state: y,
756
- dispatch: P,
757
- audioRef: k,
758
- notifyEnded: H,
759
- play: G,
760
- pause: _,
761
- togglePlayPause: F,
762
- seek: L,
763
- setVolume: Q,
764
- setMuted: B,
765
- next: $,
766
- prev: Y,
767
- setRepeatMode: O,
768
- cycleRepeat: j,
769
- toggleShuffle: V,
770
- setQueue: X,
771
- playTrackAt: W,
772
- selectTrackAt: z,
773
- setPlaylistMeta: q
912
+ state: m,
913
+ dispatch: h,
914
+ audioRef: A,
915
+ notifyEnded: ie,
916
+ play: D,
917
+ pause: w,
918
+ togglePlayPause: $,
919
+ seek: Q,
920
+ setVolume: j,
921
+ setMuted: X,
922
+ toggleMute: W,
923
+ 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
774
933
  }),
775
934
  [
776
- j,
777
- P,
778
- $,
779
- H,
780
- _,
781
- G,
782
- W,
935
+ J,
936
+ h,
783
937
  z,
784
- Y,
785
- L,
786
- B,
787
- X,
788
- O,
938
+ ie,
939
+ w,
940
+ D,
941
+ re,
942
+ te,
789
943
  q,
790
944
  Q,
791
- y,
792
- F,
793
- V
945
+ X,
946
+ K,
947
+ ee,
948
+ H,
949
+ ne,
950
+ j,
951
+ m,
952
+ W,
953
+ $,
954
+ Z
794
955
  ]
795
- ), _e = D(() => ({ ...ar, ...c }), [c]);
796
- return /* @__PURE__ */ s(re.Provider, { value: Ge, children: /* @__PURE__ */ s("div", { className: l, style: _e, children: e }) });
956
+ ), We = U(() => ({ ...Tr, ...d }), [d]);
957
+ return /* @__PURE__ */ l(fe.Provider, { value: Xe, children: /* @__PURE__ */ l("div", { className: s, style: We, children: e }) });
797
958
  }
798
- const cr = {
799
- Provider: sr,
800
- Player: Fe,
959
+ const vr = {
960
+ Provider: Er,
961
+ Player: ze,
801
962
  Current: {
802
- Title: Ve,
803
- Artist: Xe,
804
- Album: We,
805
- Description: ze,
806
- Copyright: qe,
807
- Genre: He,
808
- Label: Ke,
809
- Isrc: Je,
810
- TrackNumber: Ze,
811
- Year: se,
812
- Lyrics: le,
813
- FileUrl: oe,
814
- Artwork: ce,
815
- QueueIndex: de,
816
- QueueLength: fe,
817
- QueuePosition: pe,
818
- Elapsed: ge,
819
- Duration: ye,
820
- Remaining: he,
821
- Progress: me,
822
- TimeRail: Pe,
823
- PlaybackState: Me,
824
- ErrorMessage: be
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
825
986
  },
826
987
  Queue: {
827
- Title: rr,
828
- Subtitle: nr,
829
- Description: tr,
830
- Copyright: ir,
831
- Artwork: ve
988
+ Title: mr,
989
+ Subtitle: hr,
990
+ Description: br,
991
+ Copyright: Pr,
992
+ Artwork: $e
832
993
  },
833
994
  Control: {
834
- PlayPause: ke,
835
- Repeat: xe,
836
- Next: Ae,
837
- Previous: Te,
838
- Shuffle: Ie,
839
- SeekBar: Ee
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
840
1004
  },
841
- Playlist: Se
1005
+ Playlist: yr
842
1006
  };
843
- function dr() {
1007
+ function Ir() {
844
1008
  const e = g(), { state: r } = e;
845
- return D(
1009
+ return U(
846
1010
  () => ({
847
1011
  state: r,
848
- currentTrack: A(r),
849
- playbackUi: te(r),
850
- duration: R(r),
851
- remaining: ie(r),
852
- progress: N(r),
853
- artworkUrl: ue(r),
854
- albumLine: ae(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),
855
1019
  play: e.play,
856
1020
  pause: e.pause,
857
1021
  togglePlayPause: e.togglePlayPause,
858
1022
  seek: e.seek,
859
1023
  setVolume: e.setVolume,
860
1024
  setMuted: e.setMuted,
1025
+ toggleMute: e.toggleMute,
1026
+ setPlaybackRate: e.setPlaybackRate,
861
1027
  next: e.next,
862
1028
  prev: e.prev,
863
1029
  setRepeatMode: e.setRepeatMode,
@@ -880,10 +1046,12 @@ function dr() {
880
1046
  e.prev,
881
1047
  e.seek,
882
1048
  e.setMuted,
1049
+ e.setPlaybackRate,
883
1050
  e.setPlaylistMeta,
884
1051
  e.setQueue,
885
1052
  e.setRepeatMode,
886
1053
  e.setVolume,
1054
+ e.toggleMute,
887
1055
  e.togglePlayPause,
888
1056
  e.toggleShuffle,
889
1057
  r
@@ -891,7 +1059,7 @@ function dr() {
891
1059
  );
892
1060
  }
893
1061
  export {
894
- cr as Ginger,
895
- dr as useGinger
1062
+ vr as Ginger,
1063
+ Ir as useGinger
896
1064
  };
897
1065
  //# sourceMappingURL=index.js.map