waveframe 0.1.2 → 0.2.0

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.
@@ -1,51 +1,224 @@
1
- import e, { memo as t, useCallback as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
1
+ import { memo as e, useEffect as t, useMemo as n, useRef as r, useState as i, useSyncExternalStore as a } from "react";
2
2
  //#region \0rolldown/runtime.js
3
- var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), c = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
3
+ var o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
4
4
  if (typeof require < "u") return require.apply(this, arguments);
5
5
  throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
6
- }), l = (e) => {
7
- let t = a(null), [i, s] = o(!1), [c, l] = o(0), [u, d] = o(0);
8
- r(() => {
9
- t.current && t.current.readyState >= 1 && d(t.current.duration);
10
- }, [e]);
11
- let f = n((e) => {
12
- e?.stopPropagation(), t.current && (i ? t.current.pause() : t.current.play().catch(console.error));
13
- }, [i]), p = n(() => {
14
- t.current && l(t.current.currentTime);
15
- }, []), m = n(() => {
16
- t.current && d(t.current.duration);
17
- }, []);
18
- return {
19
- isPlaying: i,
20
- currentTime: c,
21
- duration: u,
22
- togglePlay: f,
23
- seek: n((e) => {
24
- t.current && u && (t.current.currentTime = e * u);
25
- }, [u]),
26
- audioProps: {
27
- ref: t,
28
- src: e,
29
- onTimeUpdate: p,
30
- onLoadedMetadata: m,
31
- onPlay: () => s(!0),
32
- onPause: () => s(!1),
33
- onEnded: () => s(!1)
6
+ }), c = class {
7
+ audio;
8
+ listeners = /* @__PURE__ */ new Set();
9
+ _state;
10
+ constructor() {
11
+ this.audio = new Audio(), this._state = {
12
+ isPlaying: !1,
13
+ currentTime: 0,
14
+ duration: 0,
15
+ volume: 1,
16
+ muted: !1
17
+ }, this.initListeners();
18
+ }
19
+ initListeners() {
20
+ this.audio.addEventListener("play", () => this.updateState({ isPlaying: !0 })), this.audio.addEventListener("pause", () => this.updateState({ isPlaying: !1 })), this.audio.addEventListener("timeupdate", () => this.updateState({ currentTime: this.audio.currentTime })), this.audio.addEventListener("durationchange", () => this.updateState({ duration: this.audio.duration })), this.audio.addEventListener("volumechange", () => this.updateState({
21
+ volume: this.audio.volume,
22
+ muted: this.audio.muted
23
+ })), this.audio.addEventListener("ended", () => this.updateState({ isPlaying: !1 }));
24
+ }
25
+ updateState(e) {
26
+ this._state = {
27
+ ...this._state,
28
+ ...e
29
+ }, this.notify();
30
+ }
31
+ notify() {
32
+ this.listeners.forEach((e) => e(this._state));
33
+ }
34
+ subscribe(e) {
35
+ return this.listeners.add(e), () => this.listeners.delete(e);
36
+ }
37
+ get state() {
38
+ return this._state;
39
+ }
40
+ setSource(e) {
41
+ this.audio.src = e, this.audio.load();
42
+ }
43
+ play() {
44
+ return this.audio.play();
45
+ }
46
+ pause() {
47
+ this.audio.pause();
48
+ }
49
+ togglePlay() {
50
+ this._state.isPlaying ? this.pause() : this.play();
51
+ }
52
+ seek(e) {
53
+ this.audio.currentTime = e;
54
+ }
55
+ setVolume(e) {
56
+ this.audio.volume = e;
57
+ }
58
+ setMuted(e) {
59
+ this.audio.muted = e;
60
+ }
61
+ dispose() {
62
+ this.pause(), this.audio.src = "", this.listeners.clear();
63
+ }
64
+ }, l = class {
65
+ audioCtx = null;
66
+ constructor() {}
67
+ getContext() {
68
+ return this.audioCtx ||= new (window.AudioContext || window.webkitAudioContext)(), this.audioCtx;
69
+ }
70
+ async generatePeaks(e, t = 512) {
71
+ try {
72
+ let n;
73
+ if (typeof e == "string") {
74
+ let t = await fetch(e);
75
+ if (!t.ok) throw Error(`Failed to fetch audio: ${t.statusText}`);
76
+ n = await t.arrayBuffer();
77
+ } else n = await e.arrayBuffer();
78
+ let r = (await this.getContext().decodeAudioData(n)).getChannelData(0), i = Math.floor(r.length / t), a = [];
79
+ for (let e = 0; e < t; e++) {
80
+ let t = 0, n = e * i, o = n + i;
81
+ for (let e = n; e < o; e++) {
82
+ let n = Math.abs(r[e]);
83
+ n > t && (t = n);
84
+ }
85
+ a.push(t);
86
+ }
87
+ let o = Math.max(...a);
88
+ return a.map((e) => e / (o || 1));
89
+ } catch (e) {
90
+ throw console.error("PeakAnalyzer Error:", e), e;
34
91
  }
35
- };
36
- }, u = async (e, t = 512) => {
37
- let n = await (await fetch(e)).arrayBuffer(), r = (await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(n)).getChannelData(0), i = Math.floor(r.length / t), a = [];
38
- for (let e = 0; e < t; e++) {
39
- let t = 0, n = e * i, o = n + i;
40
- for (let e = n; e < o; e++) {
41
- let n = Math.abs(r[e]);
42
- n > t && (t = n);
92
+ }
93
+ dispose() {
94
+ this.audioCtx &&= (this.audioCtx.close(), null);
95
+ }
96
+ }, u = class {
97
+ player;
98
+ analyzer;
99
+ listeners = /* @__PURE__ */ new Set();
100
+ _state;
101
+ _media = null;
102
+ _objectUrl = null;
103
+ constructor() {
104
+ this.player = new c(), this.analyzer = new l(), this._state = {
105
+ ...this.player.state,
106
+ peaks: [],
107
+ isAnalyzing: !1,
108
+ error: null
109
+ }, this.player.subscribe((e) => {
110
+ this.updateState({ ...e });
111
+ });
112
+ }
113
+ updateState(e) {
114
+ this._state = {
115
+ ...this._state,
116
+ ...e
117
+ }, this.notify();
118
+ }
119
+ notify() {
120
+ this.listeners.forEach((e) => e(this._state));
121
+ }
122
+ subscribe(e) {
123
+ return this.listeners.add(e), () => this.listeners.delete(e);
124
+ }
125
+ getSnapshot() {
126
+ return this._state;
127
+ }
128
+ revokeOldSource() {
129
+ this._objectUrl &&= (URL.revokeObjectURL(this._objectUrl), null);
130
+ }
131
+ load(e, t) {
132
+ if (this._media !== e) {
133
+ this.revokeOldSource(), this._media = e;
134
+ let n;
135
+ typeof e == "string" ? n = e : (this._objectUrl = URL.createObjectURL(e), n = this._objectUrl), this.player.setSource(n);
136
+ let r = t && t.length > 0;
137
+ this.updateState({
138
+ peaks: t || [],
139
+ isAnalyzing: !1,
140
+ error: null
141
+ }), r || this.analyze();
142
+ } else t && t !== this._state.peaks && this.updateState({ peaks: t });
143
+ }
144
+ async analyze(e = 512) {
145
+ if (!this._media) {
146
+ this.updateState({ error: "No media loaded to analyze" });
147
+ return;
43
148
  }
44
- a.push(t);
149
+ this.updateState({
150
+ isAnalyzing: !0,
151
+ error: null
152
+ });
153
+ try {
154
+ let t = await this.analyzer.generatePeaks(this._media, e);
155
+ this.updateState({
156
+ peaks: t,
157
+ isAnalyzing: !1
158
+ });
159
+ } catch (e) {
160
+ this.updateState({
161
+ isAnalyzing: !1,
162
+ error: e instanceof Error ? e.message : "Analysis failed"
163
+ });
164
+ }
165
+ }
166
+ togglePlay() {
167
+ this.player.togglePlay();
168
+ }
169
+ play() {
170
+ this.player.play();
171
+ }
172
+ pause() {
173
+ this.player.pause();
174
+ }
175
+ seek(e) {
176
+ let { duration: t } = this._state;
177
+ t && this.player.seek(e * t);
178
+ }
179
+ setVolume(e) {
180
+ this.player.setVolume(e);
181
+ }
182
+ setMuted(e) {
183
+ this.player.setMuted(e);
184
+ }
185
+ dispose() {
186
+ this.revokeOldSource(), this.player.dispose(), this.analyzer.dispose(), this.listeners.clear();
187
+ }
188
+ }, d = (e) => a((t) => e.subscribe(t), () => e.getSnapshot()), f = (e, r = {}) => {
189
+ let { peaks: i, engine: a } = r, o = n(() => a || new u(), [a]), s = a || o, c = d(s);
190
+ return t(() => {
191
+ e && s.load(e, i);
192
+ }, [
193
+ s,
194
+ e,
195
+ i
196
+ ]), t(() => () => {
197
+ a || o.dispose();
198
+ }, [o, a]), {
199
+ state: c,
200
+ engine: s,
201
+ togglePlay: () => s.togglePlay(),
202
+ play: () => s.play(),
203
+ pause: () => s.pause(),
204
+ seek: (e) => s.seek(e),
205
+ setVolume: (e) => s.setVolume(e),
206
+ setMuted: (e) => s.setMuted(e),
207
+ analyze: (e) => s.analyze(e)
208
+ };
209
+ }, p = async (e, t = 512) => {
210
+ let n = new l();
211
+ try {
212
+ return await n.generatePeaks(e, t);
213
+ } finally {
214
+ n.dispose();
45
215
  }
46
- let o = Math.max(...a);
47
- return a.map((e) => e / (o || 1));
48
- }, d = (e) => isNaN(e) ? "0:00" : `${Math.floor(e / 60)}:${Math.floor(e % 60).toString().padStart(2, "0")}`, f = (e, t) => {
216
+ }, m = async (e) => {
217
+ let t = await (await fetch(e)).blob();
218
+ return URL.createObjectURL(t);
219
+ }, h = (e) => {
220
+ e && e.startsWith("blob:") && URL.revokeObjectURL(e);
221
+ }, g = (e) => isNaN(e) ? "0:00" : `${Math.floor(e / 60)}:${Math.floor(e % 60).toString().padStart(2, "0")}`, _ = (e, t) => {
49
222
  if (e.length === 0) return [];
50
223
  if (e.length === t) return e;
51
224
  let n = Array(t), r = e.length / t;
@@ -59,16 +232,24 @@ var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
59
232
  n[i] = e[a] + (e[o] - e[a]) * s;
60
233
  }
61
234
  return n;
62
- }, p = (e, t) => i(() => f(e, t), [e, t]), m = (e) => {
63
- let [t, n] = o(0);
64
- return r(() => {
235
+ }, v = (e) => e.split("\n").map((e) => {
236
+ let t = e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), n = {}, r = 0, i = (e, t) => {
237
+ let i = `__TOKEN_${r++}__`;
238
+ return n[i] = `<span class="${t}">${e}</span>`, i;
239
+ };
240
+ return t = t.replace(/("(?:[^"\\]|\\.)*")/g, (e) => i(e, "text-[#ce9178]")), t = t.replace(/\b(\d+(\.\d+)?)\b/g, (e) => i(e, "text-[#b5cea8]")), t = t.replace(/\b(WaveframePlayer)\b/g, (e) => i(e, "text-[#4ec9b0]")), t = t.replace(/\b([a-z][a-zA-Z0-9]+)(?==)/g, (e) => i(e, "text-[#9cdcfe]")), t = t.replace(/(&lt;|&gt;|\{|\}|\/|:|,)/g, "<span class=\"text-gray-500\">$1</span>"), Object.entries(n).forEach(([e, n]) => {
241
+ t = t.replace(e, n);
242
+ }), t;
243
+ }), y = (e, t) => n(() => _(e, t), [e, t]), b = (e) => {
244
+ let [n, r] = i(0);
245
+ return t(() => {
65
246
  if (!e.current) return;
66
247
  let t = new ResizeObserver((e) => {
67
- for (let t of e) n(t.contentRect.width);
248
+ for (let t of e) r(t.contentRect.width);
68
249
  });
69
250
  return t.observe(e.current), () => t.disconnect();
70
- }, [e]), t;
71
- }, h = /* @__PURE__ */ s(((e) => {
251
+ }, [e]), n;
252
+ }, x = /* @__PURE__ */ o(((e) => {
72
253
  var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
73
254
  function r(e, n, r) {
74
255
  var i = null;
@@ -83,7 +264,7 @@ var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
83
264
  };
84
265
  }
85
266
  e.Fragment = n, e.jsx = r, e.jsxs = r;
86
- })), g = /* @__PURE__ */ s(((e) => {
267
+ })), S = /* @__PURE__ */ o(((e) => {
87
268
  process.env.NODE_ENV !== "production" && (function() {
88
269
  function t(e) {
89
270
  if (e == null) return null;
@@ -146,7 +327,7 @@ var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
146
327
  function o() {
147
328
  return Error("react-stack-top-frame");
148
329
  }
149
- function s(e) {
330
+ function c(e) {
150
331
  if (j.call(e, "key")) {
151
332
  var t = Object.getOwnPropertyDescriptor(e, "key").get;
152
333
  if (t && t.isReactWarning) return !1;
@@ -202,7 +383,7 @@ var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
202
383
  value: a
203
384
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
204
385
  }
205
- function f(e, n, i, o, c, u) {
386
+ function f(e, n, i, o, s, u) {
206
387
  var f = n.children;
207
388
  if (f !== void 0) if (o) if (M(f)) {
208
389
  for (o = 0; o < f.length; o++) p(f[o]);
@@ -216,9 +397,9 @@ var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
216
397
  });
217
398
  o = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", R[f + o] || (m = 0 < m.length ? "{" + m.join(": ..., ") + ": ...}" : "{}", console.error("A props object containing a \"key\" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />", o, f, m, f), R[f + o] = !0);
218
399
  }
219
- if (f = null, i !== void 0 && (r(i), f = "" + i), s(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
400
+ if (f = null, i !== void 0 && (r(i), f = "" + i), c(n) && (r(n.key), f = "" + n.key), "key" in n) for (var h in i = {}, n) h !== "key" && (i[h] = n[h]);
220
401
  else i = n;
221
- return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, a(), c, u);
402
+ return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, a(), s, u);
222
403
  }
223
404
  function p(e) {
224
405
  m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e && e.$$typeof === D && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
@@ -226,7 +407,7 @@ var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
226
407
  function m(e) {
227
408
  return typeof e == "object" && !!e && e.$$typeof === g;
228
409
  }
229
- var h = c("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
410
+ var h = s("react"), g = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), y = Symbol.for("react.strict_mode"), b = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), S = Symbol.for("react.context"), C = Symbol.for("react.forward_ref"), w = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), E = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), O = Symbol.for("react.activity"), k = Symbol.for("react.client.reference"), A = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, M = Array.isArray, N = console.createTask ? console.createTask : function() {
230
411
  return null;
231
412
  };
232
413
  h = { react_stack_bottom_frame: function(e) {
@@ -241,195 +422,182 @@ var s = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
241
422
  return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
242
423
  };
243
424
  })();
244
- })), _ = (/* @__PURE__ */ s(((e, t) => {
245
- process.env.NODE_ENV === "production" ? t.exports = h() : t.exports = g();
246
- })))(), v = t(({ artworkUrl: e, title: t, isPlaying: n, onToggle: r, isLoading: i }) => /* @__PURE__ */ (0, _.jsxs)("div", {
425
+ })), C = (/* @__PURE__ */ o(((e, t) => {
426
+ process.env.NODE_ENV === "production" ? t.exports = x() : t.exports = S();
427
+ })))(), w = e(({ artworkUrl: e, title: t, isLoading: n }) => /* @__PURE__ */ (0, C.jsxs)("div", {
247
428
  className: "relative flex-shrink-0 w-32 h-32 md:w-40 md:h-40 overflow-hidden rounded-[var(--wf-artwork-rounded,0.75rem)] shadow-lg group/artwork",
248
- children: [/* @__PURE__ */ (0, _.jsx)("div", {
249
- className: `w-full h-full transition-all duration-700 ${i ? "blur-md scale-110" : ""}`,
250
- children: e ? /* @__PURE__ */ (0, _.jsx)("img", {
429
+ children: [/* @__PURE__ */ (0, C.jsx)("div", {
430
+ className: `w-full h-full transition-all duration-700 ${n ? "blur-md scale-110" : ""}`,
431
+ children: e ? /* @__PURE__ */ (0, C.jsx)("img", {
251
432
  src: e,
252
433
  alt: t,
253
434
  className: "w-full h-full object-cover transition-transform duration-500 group-hover/artwork:scale-110"
254
- }) : /* @__PURE__ */ (0, _.jsx)("div", {
435
+ }) : /* @__PURE__ */ (0, C.jsx)("div", {
255
436
  className: "w-full h-full bg-gradient-to-br from-[var(--wf-placeholder-from,#fb923c)] to-[var(--wf-placeholder-to,#ec4899)] flex items-center justify-center",
256
- children: /* @__PURE__ */ (0, _.jsx)("svg", {
437
+ children: /* @__PURE__ */ (0, C.jsx)("svg", {
257
438
  className: "w-16 h-16 text-white opacity-50",
258
439
  fill: "currentColor",
259
440
  viewBox: "0 0 24 24",
260
- children: /* @__PURE__ */ (0, _.jsx)("path", { d: "M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z" })
441
+ children: /* @__PURE__ */ (0, C.jsx)("path", { d: "M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z" })
261
442
  })
262
443
  })
263
- }), i ? /* @__PURE__ */ (0, _.jsx)("div", {
444
+ }), n && /* @__PURE__ */ (0, C.jsx)("div", {
264
445
  className: "absolute inset-0 flex items-center justify-center bg-black/10 backdrop-blur-[1px]",
265
- children: /* @__PURE__ */ (0, _.jsx)("div", { className: "w-8 h-8 border-4 border-white/30 border-t-white rounded-full animate-spin" })
266
- }) : /* @__PURE__ */ (0, _.jsx)("button", {
267
- className: "absolute inset-0 bg-[var(--wf-overlay-color,rgba(0,0,0,0.3))] backdrop-blur-[var(--wf-overlay-blur,2px)] opacity-0 group-hover/artwork:opacity-100 transition-opacity duration-300 flex items-center justify-center cursor-pointer border-none outline-none",
268
- onClick: r,
269
- "aria-label": n ? "Pause" : "Play",
270
- children: /* @__PURE__ */ (0, _.jsx)("div", {
271
- className: "w-14 h-14 flex items-center justify-center bg-[var(--wf-play-btn-bg,#f97316)] rounded-full text-[var(--wf-play-btn-color,white)] shadow-lg transform scale-90 group-hover/artwork:scale-100 transition-transform duration-300",
272
- children: n ? /* @__PURE__ */ (0, _.jsx)("svg", {
273
- className: "w-8 h-8",
274
- fill: "currentColor",
275
- viewBox: "0 0 24 24",
276
- children: /* @__PURE__ */ (0, _.jsx)("path", { d: "M6 19h4V5H6v14zm8-14v14h4V5h-4z" })
277
- }) : /* @__PURE__ */ (0, _.jsx)("svg", {
278
- className: "w-8 h-8 ml-1",
279
- fill: "currentColor",
280
- viewBox: "0 0 24 24",
281
- children: /* @__PURE__ */ (0, _.jsx)("path", { d: "M8 5v14l11-7z" })
282
- })
283
- })
446
+ children: /* @__PURE__ */ (0, C.jsx)("div", { className: "w-8 h-8 border-4 border-white/30 border-t-white rounded-full animate-spin" })
284
447
  })]
285
448
  }));
286
- v.displayName = "ArtworkOverlay";
449
+ w.displayName = "ArtworkOverlay";
287
450
  //#endregion
288
451
  //#region src/organisms/Waveform.tsx
289
- var y = t(({ peaks: e, currentTime: t, duration: n, waveColor: i, progressColor: o, height: s, onSeek: c, resolution: l = "auto", barWidth: u = 2, barGap: d = 1 }) => {
290
- let f = a(null), p = a(null), h = a(null), g = m(h);
291
- r(() => {
452
+ var T = e(({ peaks: e, currentTime: n, duration: i, waveColor: a, progressColor: o, height: s, onSeek: c, resolution: l = "auto", barWidth: u = 2, barGap: d = 1 }) => {
453
+ let f = r(null), p = r(null), m = r(null), h = b(m);
454
+ t(() => {
292
455
  let t = f.current, n = p.current;
293
456
  if (!t || !n) return;
294
- let r = t.getContext("2d"), a = n.getContext("2d");
295
- if (!r || !a) return;
457
+ let r = t.getContext("2d"), i = n.getContext("2d");
458
+ if (!r || !i) return;
296
459
  let s = window.devicePixelRatio || 1, c = t.getBoundingClientRect(), m = c.width * s, h = c.height * s;
297
460
  [t, n].forEach((e) => {
298
461
  (e.width !== m || e.height !== h) && (e.width = m, e.height = h);
299
462
  }), (() => {
300
463
  if (e.length === 0) return;
301
464
  let { width: n, height: c } = t;
302
- r.clearRect(0, 0, n, c), a.clearRect(0, 0, n, c);
465
+ r.clearRect(0, 0, n, c), i.clearRect(0, 0, n, c);
303
466
  let f = n / e.length, p = typeof l == "number" ? f * .7 : u * s, m = typeof l == "number" ? f * .3 : d * s;
304
- r.lineCap = "round", r.lineWidth = p, a.lineCap = "round", a.lineWidth = p, e.forEach((e, t) => {
467
+ r.lineCap = "round", r.lineWidth = p, i.lineCap = "round", i.lineWidth = p, e.forEach((e, t) => {
305
468
  let n = t * (p + m) + p / 2, s = e * c * .8, l = (c - s) / 2, u = l + s;
306
- r.beginPath(), r.strokeStyle = i, r.moveTo(n, l), r.lineTo(n, u), r.stroke(), a.beginPath(), a.strokeStyle = o, a.moveTo(n, l), a.lineTo(n, u), a.stroke();
469
+ r.beginPath(), r.strokeStyle = a, r.moveTo(n, l), r.lineTo(n, u), r.stroke(), i.beginPath(), i.strokeStyle = o, i.moveTo(n, l), i.lineTo(n, u), i.stroke();
307
470
  });
308
471
  })();
309
472
  }, [
310
473
  e,
311
- i,
474
+ a,
312
475
  o,
313
476
  l,
314
477
  u,
315
478
  d,
316
479
  s
317
480
  ]);
318
- let v = (e) => {
319
- if (h.current && n) {
320
- let t = h.current.getBoundingClientRect(), n = e.clientX - t.left;
481
+ let g = (e) => {
482
+ if (m.current && i) {
483
+ let t = m.current.getBoundingClientRect(), n = e.clientX - t.left;
321
484
  c(Math.max(0, Math.min(1, n / t.width)));
322
485
  }
323
- }, y = n ? t / n * 100 : 0;
324
- return /* @__PURE__ */ (0, _.jsxs)("div", {
325
- ref: h,
486
+ }, _ = i ? n / i * 100 : 0;
487
+ return /* @__PURE__ */ (0, C.jsxs)("div", {
488
+ ref: m,
326
489
  className: "relative w-full cursor-pointer overflow-hidden",
327
490
  style: { height: `${s}px` },
328
- onClick: v,
329
- children: [/* @__PURE__ */ (0, _.jsx)("canvas", {
491
+ onClick: g,
492
+ children: [/* @__PURE__ */ (0, C.jsx)("canvas", {
330
493
  ref: f,
331
494
  className: "absolute inset-0 w-full h-full"
332
- }), /* @__PURE__ */ (0, _.jsx)("div", {
495
+ }), /* @__PURE__ */ (0, C.jsx)("div", {
333
496
  className: "absolute inset-0 h-full overflow-hidden transition-[width] duration-100 ease-linear pointer-events-none",
334
- style: { width: `${y}%` },
335
- children: /* @__PURE__ */ (0, _.jsx)("canvas", {
497
+ style: { width: `${_}%` },
498
+ children: /* @__PURE__ */ (0, C.jsx)("canvas", {
336
499
  ref: p,
337
500
  className: "absolute h-full",
338
- style: { width: `${g}px` }
501
+ style: { width: `${h}px` }
339
502
  })
340
503
  })]
341
504
  });
342
505
  });
343
- y.displayName = "Waveform";
506
+ T.displayName = "Waveform";
344
507
  //#endregion
345
508
  //#region src/components/WaveframePlayer.tsx
346
- var b = t(({ audioUrl: t, peaks: n, artworkUrl: a, title: s, artist: c, waveColor: f, progressColor: h, height: g = 80, className: b = "", style: x, resolution: S = "auto", barWidth: C = 2, barGap: w = 1, theme: T, autoAnalyze: E = !0 }) => {
347
- let { isPlaying: D, currentTime: O, duration: k, togglePlay: A, seek: j, audioProps: M } = l(t), N = e.useRef(null), P = m(N), [F, I] = o(void 0), [L, R] = o(!1);
348
- r(() => {
349
- !n && E && t ? (async () => {
350
- R(!0);
351
- try {
352
- I(await u(t, 512));
353
- } catch (e) {
354
- console.error("Auto-analysis failed", e);
355
- } finally {
356
- R(!1);
357
- }
358
- })() : I(void 0);
359
- }, [
360
- t,
361
- n,
362
- E
363
- ]);
364
- let z = n || F || [], B = p(z, i(() => typeof S == "number" ? S : P > 0 ? Math.max(1, Math.floor(P / (C + w))) : z.length || 1, [
365
- S,
366
- P,
367
- C,
368
- w,
369
- z.length
370
- ])), V = i(() => f || (T ? T.bg === "#ffffff" ? "#e5e7eb" : "#374151" : "#e5e7eb"), [f, T]), H = h || T?.primary || "#3b82f6", U = i(() => ({
371
- "--wf-bg-color": T?.bg || "white",
372
- "--wf-border-color": T?.border || "#f3f4f6",
373
- "--wf-title-color": T?.text || "#111827",
374
- "--wf-artist-color": T?.text || "#6b7280",
375
- "--wf-time-color": T?.text || "#9ca3af",
376
- "--wf-play-btn-bg": T?.primary || "#3b82f6",
377
- "--wf-placeholder-from": T?.primary || "#fb923c",
378
- "--wf-placeholder-to": T?.bg || "#ec4899",
379
- ...x
380
- }), [T, x]);
381
- return /* @__PURE__ */ (0, _.jsxs)("div", {
382
- className: `group relative flex flex-col md:flex-row items-center gap-6 p-6 bg-[var(--wf-bg-color,white)] border border-[var(--wf-border-color,#f3f4f6)] rounded-[var(--wf-rounded,1rem)] shadow-xl hover:shadow-2xl transition-all duration-300 overflow-hidden ${b}`,
383
- style: U,
384
- children: [
385
- /* @__PURE__ */ (0, _.jsx)(v, {
386
- artworkUrl: a,
387
- title: s,
388
- isPlaying: D,
389
- onToggle: A,
390
- isLoading: L
391
- }),
392
- /* @__PURE__ */ (0, _.jsxs)("div", {
393
- className: "flex-1 w-full flex flex-col justify-between py-1",
394
- children: [/* @__PURE__ */ (0, _.jsxs)("div", {
395
- className: "mb-4",
396
- children: [/* @__PURE__ */ (0, _.jsxs)("div", {
397
- className: "flex items-center justify-between mb-1",
398
- children: [s && /* @__PURE__ */ (0, _.jsx)("h3", {
399
- className: "text-xl md:text-2xl font-black text-[var(--wf-title-color,#111827)] tracking-tight line-clamp-1",
400
- children: s
401
- }), /* @__PURE__ */ (0, _.jsxs)("div", {
402
- className: "text-xs font-mono text-[var(--wf-time-color,#9ca3af)] tabular-nums",
509
+ var E = e(({ media: e, peaks: a, artwork: o, title: s, artist: c, waveColor: l, progressColor: u, height: d = 80, className: p = "", style: m, resolution: h = "auto", barWidth: _ = 2, barGap: v = 1, theme: x, engine: S }) => {
510
+ let { state: E, togglePlay: D, seek: O } = f(e, {
511
+ peaks: a,
512
+ engine: S
513
+ }), { isPlaying: k, currentTime: A, duration: j, peaks: M, isAnalyzing: N } = E, [P, F] = i(typeof o == "string" ? o : void 0);
514
+ t(() => {
515
+ if (o instanceof Blob) {
516
+ let e = URL.createObjectURL(o);
517
+ return F(e), () => URL.revokeObjectURL(e);
518
+ } else F(o);
519
+ }, [o]);
520
+ let I = r(null), L = b(I), R = y(M, n(() => typeof h == "number" ? h : L > 0 ? Math.max(1, Math.floor(L / (_ + v))) : M.length || 1, [
521
+ h,
522
+ L,
523
+ _,
524
+ v,
525
+ M.length
526
+ ])), z = n(() => l || (x ? x.bg === "#ffffff" ? "#e5e7eb" : "#374151" : "#e5e7eb"), [l, x]), B = u || x?.primary || "#3b82f6", V = n(() => ({
527
+ "--wf-bg-color": x?.bg || "white",
528
+ "--wf-border-color": x?.border || "#f3f4f6",
529
+ "--wf-title-color": x?.text || "#111827",
530
+ "--wf-artist-color": x?.text || "#6b7280",
531
+ "--wf-time-color": x?.text || "#9ca3af",
532
+ "--wf-play-btn-bg": x?.primary || "#3b82f6",
533
+ "--wf-placeholder-from": x?.primary || "#fb923c",
534
+ "--wf-placeholder-to": x?.bg || "#ec4899",
535
+ ...m
536
+ }), [x, m]);
537
+ return /* @__PURE__ */ (0, C.jsxs)("div", {
538
+ className: `group relative flex flex-col md:flex-row items-stretch gap-6 p-6 bg-[var(--wf-bg-color,white)] border border-[var(--wf-border-color,#f3f4f6)] rounded-[var(--wf-rounded,1rem)] shadow-xl hover:shadow-2xl transition-all duration-300 overflow-hidden ${p}`,
539
+ style: V,
540
+ children: [/* @__PURE__ */ (0, C.jsx)(w, {
541
+ artworkUrl: P,
542
+ title: s,
543
+ isLoading: N
544
+ }), /* @__PURE__ */ (0, C.jsxs)("div", {
545
+ className: "flex-1 w-full flex flex-col min-w-0",
546
+ children: [/* @__PURE__ */ (0, C.jsxs)("div", {
547
+ className: "flex items-center gap-4 mb-6",
548
+ children: [/* @__PURE__ */ (0, C.jsx)("button", {
549
+ onClick: D,
550
+ className: "w-12 h-12 md:w-14 md:h-14 flex-shrink-0 flex items-center justify-center rounded-full bg-[var(--wf-play-btn-bg,#3b82f6)] text-white shadow-[0_4px_12px_rgba(0,0,0,0.15)] hover:shadow-[0_6px_16px_rgba(0,0,0,0.2)] transition-all hover:scale-105 active:scale-95 cursor-pointer border-none outline-none group/play",
551
+ children: k ? /* @__PURE__ */ (0, C.jsx)("svg", {
552
+ className: "w-6 h-6 md:w-7 md:h-7",
553
+ fill: "currentColor",
554
+ viewBox: "0 0 24 24",
555
+ children: /* @__PURE__ */ (0, C.jsx)("path", { d: "M6 19h4V5H6v14zm8-14v14h4V5h-4z" })
556
+ }) : /* @__PURE__ */ (0, C.jsx)("svg", {
557
+ className: "w-6 h-6 md:w-7 md:h-7 ml-1",
558
+ fill: "currentColor",
559
+ viewBox: "0 0 24 24",
560
+ children: /* @__PURE__ */ (0, C.jsx)("path", { d: "M8 5v14l11-7z" })
561
+ })
562
+ }), /* @__PURE__ */ (0, C.jsxs)("div", {
563
+ className: "flex-1 flex flex-col min-w-0",
564
+ children: [/* @__PURE__ */ (0, C.jsxs)("div", {
565
+ className: "flex items-center justify-between gap-4",
566
+ children: [c && /* @__PURE__ */ (0, C.jsx)("p", {
567
+ className: "text-[10px] md:text-xs font-bold uppercase text-[var(--wf-artist-color,#6b7280)] opacity-60 tracking-[0.1em] line-clamp-1",
568
+ children: c
569
+ }), /* @__PURE__ */ (0, C.jsxs)("div", {
570
+ className: "text-[10px] font-mono text-[var(--wf-time-color,#9ca3af)] tabular-nums flex-shrink-0",
403
571
  children: [
404
- d(O),
572
+ g(A),
405
573
  " / ",
406
- d(k)
574
+ g(j)
407
575
  ]
408
576
  })]
409
- }), c && /* @__PURE__ */ (0, _.jsx)("p", {
410
- className: "text-sm md:text-base font-medium text-[var(--wf-artist-color,#6b7280)] line-clamp-1 tracking-wide",
411
- children: c
577
+ }), s && /* @__PURE__ */ (0, C.jsx)("h3", {
578
+ className: "text-lg md:text-xl font-black text-[var(--wf-title-color,#111827)] tracking-tight line-clamp-1 mt-0.5 leading-tight",
579
+ children: s
412
580
  })]
413
- }), /* @__PURE__ */ (0, _.jsx)("div", {
414
- ref: N,
415
- children: /* @__PURE__ */ (0, _.jsx)(y, {
416
- peaks: B,
417
- currentTime: O,
418
- duration: k,
419
- waveColor: V,
420
- progressColor: H,
421
- height: g,
422
- onSeek: j,
423
- resolution: S,
424
- barWidth: C,
425
- barGap: w
426
- })
427
581
  })]
428
- }),
429
- /* @__PURE__ */ (0, _.jsx)("audio", { ...M })
430
- ]
582
+ }), /* @__PURE__ */ (0, C.jsx)("div", {
583
+ className: "mt-auto",
584
+ ref: I,
585
+ children: /* @__PURE__ */ (0, C.jsx)(T, {
586
+ peaks: R,
587
+ currentTime: A,
588
+ duration: j,
589
+ waveColor: z,
590
+ progressColor: B,
591
+ height: d,
592
+ onSeek: O,
593
+ resolution: h,
594
+ barWidth: _,
595
+ barGap: v
596
+ })
597
+ })]
598
+ })]
431
599
  });
432
600
  });
433
- b.displayName = "WaveframePlayer";
601
+ E.displayName = "WaveframePlayer";
434
602
  //#endregion
435
- export { b as WaveframePlayer };
603
+ export { l as PeakAnalyzer, c as PlayerCore, u as WaveframeEngine, E as WaveframePlayer, g as formatTime, p as generatePeaks, v as highlightCode, m as loadAudioToMemory, _ as resamplePeaks, h as revokeAudioMemory, d as useWaveframeStore };