waveframe 0.2.1 → 0.3.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.
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +3 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +491 -0
- package/dist/index.d.ts +491 -2
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/package.json +8 -8
- package/dist/src/App.d.ts +0 -2
- package/dist/src/__tests__/WaveframePlayer.test.d.ts +0 -1
- package/dist/src/atoms/CodeBlock.d.ts +0 -9
- package/dist/src/components/WaveframePlayer.d.ts +0 -83
- package/dist/src/core/PeakAnalyzer.d.ts +0 -41
- package/dist/src/core/PlayerCore.d.ts +0 -92
- package/dist/src/core/WaveframeEngine.d.ts +0 -122
- package/dist/src/hooks/usePersistentSettings.d.ts +0 -1
- package/dist/src/hooks/useResampledPeaks.d.ts +0 -1
- package/dist/src/hooks/useResizeObserver.d.ts +0 -1
- package/dist/src/hooks/useWaveframe.d.ts +0 -51
- package/dist/src/hooks/useWaveframeStore.d.ts +0 -27
- package/dist/src/index.d.ts +0 -7
- package/dist/src/main.d.ts +0 -0
- package/dist/src/molecules/ArtworkOverlay.d.ts +0 -20
- package/dist/src/organisms/SettingsPanel.d.ts +0 -29
- package/dist/src/organisms/Waveform.d.ts +0 -15
- package/dist/src/types/index.d.ts +0 -75
- package/dist/src/utils/audio.d.ts +0 -33
- package/dist/src/utils/index.d.ts +0 -13
- package/dist/waveframe.css +0 -3
- package/dist/waveframe.es.js +0 -603
- package/dist/waveframe.umd.js +0 -7
package/dist/waveframe.es.js
DELETED
|
@@ -1,603 +0,0 @@
|
|
|
1
|
-
import { memo as e, useEffect as t, useMemo as n, useRef as r, useState as i, useSyncExternalStore as a } from "react";
|
|
2
|
-
//#region \0rolldown/runtime.js
|
|
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
|
-
if (typeof require < "u") return require.apply(this, arguments);
|
|
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
|
-
}), 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;
|
|
91
|
-
}
|
|
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;
|
|
148
|
-
}
|
|
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();
|
|
215
|
-
}
|
|
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) => {
|
|
222
|
-
if (e.length === 0) return [];
|
|
223
|
-
if (e.length === t) return e;
|
|
224
|
-
let n = Array(t), r = e.length / t;
|
|
225
|
-
if (r > 1) for (let i = 0; i < t; i++) {
|
|
226
|
-
let t = 0, a = Math.floor(i * r), o = Math.floor((i + 1) * r);
|
|
227
|
-
for (let n = a; n < o; n++) e[n] > t && (t = e[n]);
|
|
228
|
-
n[i] = t;
|
|
229
|
-
}
|
|
230
|
-
else for (let i = 0; i < t; i++) {
|
|
231
|
-
let t = i * r, a = Math.floor(t), o = Math.min(a + 1, e.length - 1), s = t - a;
|
|
232
|
-
n[i] = e[a] + (e[o] - e[a]) * s;
|
|
233
|
-
}
|
|
234
|
-
return n;
|
|
235
|
-
}, v = (e) => e.split("\n").map((e) => {
|
|
236
|
-
let t = e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), 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(/(<|>|\{|\}|\/|:|,)/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(() => {
|
|
246
|
-
if (!e.current) return;
|
|
247
|
-
let t = new ResizeObserver((e) => {
|
|
248
|
-
for (let t of e) r(t.contentRect.width);
|
|
249
|
-
});
|
|
250
|
-
return t.observe(e.current), () => t.disconnect();
|
|
251
|
-
}, [e]), n;
|
|
252
|
-
}, x = /* @__PURE__ */ o(((e) => {
|
|
253
|
-
var t = Symbol.for("react.transitional.element"), n = Symbol.for("react.fragment");
|
|
254
|
-
function r(e, n, r) {
|
|
255
|
-
var i = null;
|
|
256
|
-
if (r !== void 0 && (i = "" + r), n.key !== void 0 && (i = "" + n.key), "key" in n) for (var a in r = {}, n) a !== "key" && (r[a] = n[a]);
|
|
257
|
-
else r = n;
|
|
258
|
-
return n = r.ref, {
|
|
259
|
-
$$typeof: t,
|
|
260
|
-
type: e,
|
|
261
|
-
key: i,
|
|
262
|
-
ref: n === void 0 ? null : n,
|
|
263
|
-
props: r
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
e.Fragment = n, e.jsx = r, e.jsxs = r;
|
|
267
|
-
})), S = /* @__PURE__ */ o(((e) => {
|
|
268
|
-
process.env.NODE_ENV !== "production" && (function() {
|
|
269
|
-
function t(e) {
|
|
270
|
-
if (e == null) return null;
|
|
271
|
-
if (typeof e == "function") return e.$$typeof === k ? null : e.displayName || e.name || null;
|
|
272
|
-
if (typeof e == "string") return e;
|
|
273
|
-
switch (e) {
|
|
274
|
-
case v: return "Fragment";
|
|
275
|
-
case b: return "Profiler";
|
|
276
|
-
case y: return "StrictMode";
|
|
277
|
-
case w: return "Suspense";
|
|
278
|
-
case T: return "SuspenseList";
|
|
279
|
-
case O: return "Activity";
|
|
280
|
-
}
|
|
281
|
-
if (typeof e == "object") switch (typeof e.tag == "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), e.$$typeof) {
|
|
282
|
-
case _: return "Portal";
|
|
283
|
-
case S: return e.displayName || "Context";
|
|
284
|
-
case x: return (e._context.displayName || "Context") + ".Consumer";
|
|
285
|
-
case C:
|
|
286
|
-
var n = e.render;
|
|
287
|
-
return e = e.displayName, e ||= (e = n.displayName || n.name || "", e === "" ? "ForwardRef" : "ForwardRef(" + e + ")"), e;
|
|
288
|
-
case E: return n = e.displayName || null, n === null ? t(e.type) || "Memo" : n;
|
|
289
|
-
case D:
|
|
290
|
-
n = e._payload, e = e._init;
|
|
291
|
-
try {
|
|
292
|
-
return t(e(n));
|
|
293
|
-
} catch {}
|
|
294
|
-
}
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
function n(e) {
|
|
298
|
-
return "" + e;
|
|
299
|
-
}
|
|
300
|
-
function r(e) {
|
|
301
|
-
try {
|
|
302
|
-
n(e);
|
|
303
|
-
var t = !1;
|
|
304
|
-
} catch {
|
|
305
|
-
t = !0;
|
|
306
|
-
}
|
|
307
|
-
if (t) {
|
|
308
|
-
t = console;
|
|
309
|
-
var r = t.error, i = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
310
|
-
return r.call(t, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", i), n(e);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
function i(e) {
|
|
314
|
-
if (e === v) return "<>";
|
|
315
|
-
if (typeof e == "object" && e && e.$$typeof === D) return "<...>";
|
|
316
|
-
try {
|
|
317
|
-
var n = t(e);
|
|
318
|
-
return n ? "<" + n + ">" : "<...>";
|
|
319
|
-
} catch {
|
|
320
|
-
return "<...>";
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function a() {
|
|
324
|
-
var e = A.A;
|
|
325
|
-
return e === null ? null : e.getOwner();
|
|
326
|
-
}
|
|
327
|
-
function o() {
|
|
328
|
-
return Error("react-stack-top-frame");
|
|
329
|
-
}
|
|
330
|
-
function c(e) {
|
|
331
|
-
if (j.call(e, "key")) {
|
|
332
|
-
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
333
|
-
if (t && t.isReactWarning) return !1;
|
|
334
|
-
}
|
|
335
|
-
return e.key !== void 0;
|
|
336
|
-
}
|
|
337
|
-
function l(e, t) {
|
|
338
|
-
function n() {
|
|
339
|
-
P || (P = !0, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", t));
|
|
340
|
-
}
|
|
341
|
-
n.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
342
|
-
get: n,
|
|
343
|
-
configurable: !0
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
function u() {
|
|
347
|
-
var e = t(this.type);
|
|
348
|
-
return F[e] || (F[e] = !0, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")), e = this.props.ref, e === void 0 ? null : e;
|
|
349
|
-
}
|
|
350
|
-
function d(e, t, n, r, i, a) {
|
|
351
|
-
var o = n.ref;
|
|
352
|
-
return e = {
|
|
353
|
-
$$typeof: g,
|
|
354
|
-
type: e,
|
|
355
|
-
key: t,
|
|
356
|
-
props: n,
|
|
357
|
-
_owner: r
|
|
358
|
-
}, (o === void 0 ? null : o) === null ? Object.defineProperty(e, "ref", {
|
|
359
|
-
enumerable: !1,
|
|
360
|
-
value: null
|
|
361
|
-
}) : Object.defineProperty(e, "ref", {
|
|
362
|
-
enumerable: !1,
|
|
363
|
-
get: u
|
|
364
|
-
}), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
365
|
-
configurable: !1,
|
|
366
|
-
enumerable: !1,
|
|
367
|
-
writable: !0,
|
|
368
|
-
value: 0
|
|
369
|
-
}), Object.defineProperty(e, "_debugInfo", {
|
|
370
|
-
configurable: !1,
|
|
371
|
-
enumerable: !1,
|
|
372
|
-
writable: !0,
|
|
373
|
-
value: null
|
|
374
|
-
}), Object.defineProperty(e, "_debugStack", {
|
|
375
|
-
configurable: !1,
|
|
376
|
-
enumerable: !1,
|
|
377
|
-
writable: !0,
|
|
378
|
-
value: i
|
|
379
|
-
}), Object.defineProperty(e, "_debugTask", {
|
|
380
|
-
configurable: !1,
|
|
381
|
-
enumerable: !1,
|
|
382
|
-
writable: !0,
|
|
383
|
-
value: a
|
|
384
|
-
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
385
|
-
}
|
|
386
|
-
function f(e, n, i, o, s, u) {
|
|
387
|
-
var f = n.children;
|
|
388
|
-
if (f !== void 0) if (o) if (M(f)) {
|
|
389
|
-
for (o = 0; o < f.length; o++) p(f[o]);
|
|
390
|
-
Object.freeze && Object.freeze(f);
|
|
391
|
-
} else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
392
|
-
else p(f);
|
|
393
|
-
if (j.call(n, "key")) {
|
|
394
|
-
f = t(e);
|
|
395
|
-
var m = Object.keys(n).filter(function(e) {
|
|
396
|
-
return e !== "key";
|
|
397
|
-
});
|
|
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);
|
|
399
|
-
}
|
|
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]);
|
|
401
|
-
else i = n;
|
|
402
|
-
return f && l(i, typeof e == "function" ? e.displayName || e.name || "Unknown" : e), d(e, f, i, a(), s, u);
|
|
403
|
-
}
|
|
404
|
-
function p(e) {
|
|
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));
|
|
406
|
-
}
|
|
407
|
-
function m(e) {
|
|
408
|
-
return typeof e == "object" && !!e && e.$$typeof === g;
|
|
409
|
-
}
|
|
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() {
|
|
411
|
-
return null;
|
|
412
|
-
};
|
|
413
|
-
h = { react_stack_bottom_frame: function(e) {
|
|
414
|
-
return e();
|
|
415
|
-
} };
|
|
416
|
-
var P, F = {}, I = h.react_stack_bottom_frame.bind(h, o)(), L = N(i(o)), R = {};
|
|
417
|
-
e.Fragment = v, e.jsx = function(e, t, n) {
|
|
418
|
-
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
419
|
-
return f(e, t, n, !1, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
420
|
-
}, e.jsxs = function(e, t, n) {
|
|
421
|
-
var r = 1e4 > A.recentlyCreatedOwnerStacks++;
|
|
422
|
-
return f(e, t, n, !0, r ? Error("react-stack-top-frame") : I, r ? N(i(e)) : L);
|
|
423
|
-
};
|
|
424
|
-
})();
|
|
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", {
|
|
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",
|
|
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", {
|
|
432
|
-
src: e,
|
|
433
|
-
alt: t,
|
|
434
|
-
className: "w-full h-full object-cover transition-transform duration-500 group-hover/artwork:scale-110"
|
|
435
|
-
}) : /* @__PURE__ */ (0, C.jsx)("div", {
|
|
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",
|
|
437
|
-
children: /* @__PURE__ */ (0, C.jsx)("svg", {
|
|
438
|
-
className: "w-16 h-16 text-white opacity-50",
|
|
439
|
-
fill: "currentColor",
|
|
440
|
-
viewBox: "0 0 24 24",
|
|
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" })
|
|
442
|
-
})
|
|
443
|
-
})
|
|
444
|
-
}), n && /* @__PURE__ */ (0, C.jsx)("div", {
|
|
445
|
-
className: "absolute inset-0 flex items-center justify-center bg-black/10 backdrop-blur-[1px]",
|
|
446
|
-
children: /* @__PURE__ */ (0, C.jsx)("div", { className: "w-8 h-8 border-4 border-white/30 border-t-white rounded-full animate-spin" })
|
|
447
|
-
})]
|
|
448
|
-
}));
|
|
449
|
-
w.displayName = "ArtworkOverlay";
|
|
450
|
-
//#endregion
|
|
451
|
-
//#region src/organisms/Waveform.tsx
|
|
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(() => {
|
|
455
|
-
let t = f.current, n = p.current;
|
|
456
|
-
if (!t || !n) return;
|
|
457
|
-
let r = t.getContext("2d"), i = n.getContext("2d");
|
|
458
|
-
if (!r || !i) return;
|
|
459
|
-
let s = window.devicePixelRatio || 1, c = t.getBoundingClientRect(), m = c.width * s, h = c.height * s;
|
|
460
|
-
[t, n].forEach((e) => {
|
|
461
|
-
(e.width !== m || e.height !== h) && (e.width = m, e.height = h);
|
|
462
|
-
}), (() => {
|
|
463
|
-
if (e.length === 0) return;
|
|
464
|
-
let { width: n, height: c } = t;
|
|
465
|
-
r.clearRect(0, 0, n, c), i.clearRect(0, 0, n, c);
|
|
466
|
-
let f = n / e.length, p = typeof l == "number" ? f * .7 : u * s, m = typeof l == "number" ? f * .3 : d * s;
|
|
467
|
-
r.lineCap = "round", r.lineWidth = p, i.lineCap = "round", i.lineWidth = p, e.forEach((e, t) => {
|
|
468
|
-
let n = t * (p + m) + p / 2, s = e * c * .8, l = (c - s) / 2, u = l + s;
|
|
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();
|
|
470
|
-
});
|
|
471
|
-
})();
|
|
472
|
-
}, [
|
|
473
|
-
e,
|
|
474
|
-
a,
|
|
475
|
-
o,
|
|
476
|
-
l,
|
|
477
|
-
u,
|
|
478
|
-
d,
|
|
479
|
-
s
|
|
480
|
-
]);
|
|
481
|
-
let g = (e) => {
|
|
482
|
-
if (m.current && i) {
|
|
483
|
-
let t = m.current.getBoundingClientRect(), n = e.clientX - t.left;
|
|
484
|
-
c(Math.max(0, Math.min(1, n / t.width)));
|
|
485
|
-
}
|
|
486
|
-
}, _ = i ? n / i * 100 : 0;
|
|
487
|
-
return /* @__PURE__ */ (0, C.jsxs)("div", {
|
|
488
|
-
ref: m,
|
|
489
|
-
className: "relative w-full cursor-pointer overflow-hidden",
|
|
490
|
-
style: { height: `${s}px` },
|
|
491
|
-
onClick: g,
|
|
492
|
-
children: [/* @__PURE__ */ (0, C.jsx)("canvas", {
|
|
493
|
-
ref: f,
|
|
494
|
-
className: "absolute inset-0 w-full h-full"
|
|
495
|
-
}), /* @__PURE__ */ (0, C.jsx)("div", {
|
|
496
|
-
className: "absolute inset-0 h-full overflow-hidden transition-[width] duration-100 ease-linear pointer-events-none",
|
|
497
|
-
style: { width: `${_}%` },
|
|
498
|
-
children: /* @__PURE__ */ (0, C.jsx)("canvas", {
|
|
499
|
-
ref: p,
|
|
500
|
-
className: "absolute h-full",
|
|
501
|
-
style: { width: `${h}px` }
|
|
502
|
-
})
|
|
503
|
-
})]
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
T.displayName = "Waveform";
|
|
507
|
-
//#endregion
|
|
508
|
-
//#region src/components/WaveframePlayer.tsx
|
|
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",
|
|
571
|
-
children: [
|
|
572
|
-
g(A),
|
|
573
|
-
" / ",
|
|
574
|
-
g(j)
|
|
575
|
-
]
|
|
576
|
-
})]
|
|
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
|
|
580
|
-
})]
|
|
581
|
-
})]
|
|
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
|
-
})]
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
E.displayName = "WaveframePlayer";
|
|
602
|
-
//#endregion
|
|
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 };
|
package/dist/waveframe.umd.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`)):typeof define==`function`&&define.amd?define([`exports`,`react`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Waveframe={},e.React))})(this,function(e,t){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e};t=((e,t,i)=>(i=e==null?{}:n(o(e)),l(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)))(t,1);var u=class{audio;listeners=new Set;_state;constructor(){this.audio=new Audio,this._state={isPlaying:!1,currentTime:0,duration:0,volume:1,muted:!1},this.initListeners()}initListeners(){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({volume:this.audio.volume,muted:this.audio.muted})),this.audio.addEventListener(`ended`,()=>this.updateState({isPlaying:!1}))}updateState(e){this._state={...this._state,...e},this.notify()}notify(){this.listeners.forEach(e=>e(this._state))}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}get state(){return this._state}setSource(e){this.audio.src=e,this.audio.load()}play(){return this.audio.play()}pause(){this.audio.pause()}togglePlay(){this._state.isPlaying?this.pause():this.play()}seek(e){this.audio.currentTime=e}setVolume(e){this.audio.volume=e}setMuted(e){this.audio.muted=e}dispose(){this.pause(),this.audio.src=``,this.listeners.clear()}},d=class{audioCtx=null;constructor(){}getContext(){return this.audioCtx||=new(window.AudioContext||window.webkitAudioContext),this.audioCtx}async generatePeaks(e,t=512){try{let n;if(typeof e==`string`){let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch audio: ${t.statusText}`);n=await t.arrayBuffer()}else n=await e.arrayBuffer();let r=(await this.getContext().decodeAudioData(n)).getChannelData(0),i=Math.floor(r.length/t),a=[];for(let e=0;e<t;e++){let t=0,n=e*i,o=n+i;for(let e=n;e<o;e++){let n=Math.abs(r[e]);n>t&&(t=n)}a.push(t)}let o=Math.max(...a);return a.map(e=>e/(o||1))}catch(e){throw console.error(`PeakAnalyzer Error:`,e),e}}dispose(){this.audioCtx&&=(this.audioCtx.close(),null)}},f=class{player;analyzer;listeners=new Set;_state;_media=null;_objectUrl=null;constructor(){this.player=new u,this.analyzer=new d,this._state={...this.player.state,peaks:[],isAnalyzing:!1,error:null},this.player.subscribe(e=>{this.updateState({...e})})}updateState(e){this._state={...this._state,...e},this.notify()}notify(){this.listeners.forEach(e=>e(this._state))}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}getSnapshot(){return this._state}revokeOldSource(){this._objectUrl&&=(URL.revokeObjectURL(this._objectUrl),null)}load(e,t){if(this._media!==e){this.revokeOldSource(),this._media=e;let n;typeof e==`string`?n=e:(this._objectUrl=URL.createObjectURL(e),n=this._objectUrl),this.player.setSource(n);let r=t&&t.length>0;this.updateState({peaks:t||[],isAnalyzing:!1,error:null}),r||this.analyze()}else t&&t!==this._state.peaks&&this.updateState({peaks:t})}async analyze(e=512){if(!this._media){this.updateState({error:`No media loaded to analyze`});return}this.updateState({isAnalyzing:!0,error:null});try{let t=await this.analyzer.generatePeaks(this._media,e);this.updateState({peaks:t,isAnalyzing:!1})}catch(e){this.updateState({isAnalyzing:!1,error:e instanceof Error?e.message:`Analysis failed`})}}togglePlay(){this.player.togglePlay()}play(){this.player.play()}pause(){this.player.pause()}seek(e){let{duration:t}=this._state;t&&this.player.seek(e*t)}setVolume(e){this.player.setVolume(e)}setMuted(e){this.player.setMuted(e)}dispose(){this.revokeOldSource(),this.player.dispose(),this.analyzer.dispose(),this.listeners.clear()}},p=e=>(0,t.useSyncExternalStore)(t=>e.subscribe(t),()=>e.getSnapshot()),m=(e,n={})=>{let{peaks:r,engine:i}=n,a=(0,t.useMemo)(()=>i||new f,[i]),o=i||a,s=p(o);return(0,t.useEffect)(()=>{e&&o.load(e,r)},[o,e,r]),(0,t.useEffect)(()=>()=>{i||a.dispose()},[a,i]),{state:s,engine:o,togglePlay:()=>o.togglePlay(),play:()=>o.play(),pause:()=>o.pause(),seek:e=>o.seek(e),setVolume:e=>o.setVolume(e),setMuted:e=>o.setMuted(e),analyze:e=>o.analyze(e)}},h=async(e,t=512)=>{let n=new d;try{return await n.generatePeaks(e,t)}finally{n.dispose()}},g=async e=>{let t=await(await fetch(e)).blob();return URL.createObjectURL(t)},_=e=>{e&&e.startsWith(`blob:`)&&URL.revokeObjectURL(e)},v=e=>isNaN(e)?`0:00`:`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,`0`)}`,y=(e,t)=>{if(e.length===0)return[];if(e.length===t)return e;let n=Array(t),r=e.length/t;if(r>1)for(let i=0;i<t;i++){let t=0,a=Math.floor(i*r),o=Math.floor((i+1)*r);for(let n=a;n<o;n++)e[n]>t&&(t=e[n]);n[i]=t}else for(let i=0;i<t;i++){let t=i*r,a=Math.floor(t),o=Math.min(a+1,e.length-1),s=t-a;n[i]=e[a]+(e[o]-e[a])*s}return n},b=e=>e.split(`
|
|
2
|
-
`).map(e=>{let t=e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`),n={},r=0,i=(e,t)=>{let i=`__TOKEN_${r++}__`;return n[i]=`<span class="${t}">${e}</span>`,i};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(/(<|>|\{|\}|\/|:|,)/g,`<span class="text-gray-500">$1</span>`),Object.entries(n).forEach(([e,n])=>{t=t.replace(e,n)}),t}),x=(e,n)=>(0,t.useMemo)(()=>y(e,n),[e,n]),S=e=>{let[n,r]=(0,t.useState)(0);return(0,t.useEffect)(()=>{if(!e.current)return;let t=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return t.observe(e.current),()=>t.disconnect()},[e]),n},C=c((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.fragment`);function r(e,n,r){var i=null;if(r!==void 0&&(i=``+r),n.key!==void 0&&(i=``+n.key),`key`in n)for(var a in r={},n)a!==`key`&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:i,ref:n===void 0?null:n,props:r}}e.Fragment=n,e.jsx=r,e.jsxs=r})),w=c((e=>{process.env.NODE_ENV!==`production`&&(function(){function t(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case _:return`Fragment`;case y:return`Profiler`;case v:return`StrictMode`;case C:return`Suspense`;case w:return`SuspenseList`;case D:return`Activity`}if(typeof e==`object`)switch(typeof e.tag==`number`&&console.error(`Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue.`),e.$$typeof){case g:return`Portal`;case x:return e.displayName||`Context`;case b:return(e._context.displayName||`Context`)+`.Consumer`;case S:var n=e.render;return e=e.displayName,e||=(e=n.displayName||n.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case T:return n=e.displayName||null,n===null?t(e.type)||`Memo`:n;case E:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function n(e){return``+e}function r(e){try{n(e);var t=!1}catch{t=!0}if(t){t=console;var r=t.error,i=typeof Symbol==`function`&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||`Object`;return r.call(t,`The provided key is an unsupported type %s. This value must be coerced to a string before using it here.`,i),n(e)}}function i(e){if(e===_)return`<>`;if(typeof e==`object`&&e&&e.$$typeof===E)return`<...>`;try{var n=t(e);return n?`<`+n+`>`:`<...>`}catch{return`<...>`}}function a(){var e=k.A;return e===null?null:e.getOwner()}function o(){return Error(`react-stack-top-frame`)}function s(e){if(A.call(e,`key`)){var t=Object.getOwnPropertyDescriptor(e,`key`).get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function c(e,t){function n(){N||(N=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,`key`,{get:n,configurable:!0})}function l(){var e=t(this.type);return P[e]||(P[e]=!0,console.error(`Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.`)),e=this.props.ref,e===void 0?null:e}function u(e,t,n,r,i,a){var o=n.ref;return e={$$typeof:h,type:e,key:t,props:n,_owner:r},(o===void 0?null:o)===null?Object.defineProperty(e,`ref`,{enumerable:!1,value:null}):Object.defineProperty(e,`ref`,{enumerable:!1,get:l}),e._store={},Object.defineProperty(e._store,`validated`,{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,`_debugInfo`,{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,`_debugStack`,{configurable:!1,enumerable:!1,writable:!0,value:i}),Object.defineProperty(e,`_debugTask`,{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function d(e,n,i,o,l,d){var p=n.children;if(p!==void 0)if(o)if(j(p)){for(o=0;o<p.length;o++)f(p[o]);Object.freeze&&Object.freeze(p)}else console.error(`React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.`);else f(p);if(A.call(n,`key`)){p=t(e);var m=Object.keys(n).filter(function(e){return e!==`key`});o=0<m.length?`{key: someKey, `+m.join(`: ..., `)+`: ...}`:`{key: someKey}`,L[p+o]||(m=0<m.length?`{`+m.join(`: ..., `)+`: ...}`:`{}`,console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
3
|
-
let props = %s;
|
|
4
|
-
<%s {...props} />
|
|
5
|
-
React keys must be passed directly to JSX without using spread:
|
|
6
|
-
let props = %s;
|
|
7
|
-
<%s key={someKey} {...props} />`,o,p,m,p),L[p+o]=!0)}if(p=null,i!==void 0&&(r(i),p=``+i),s(n)&&(r(n.key),p=``+n.key),`key`in n)for(var h in i={},n)h!==`key`&&(i[h]=n[h]);else i=n;return p&&c(i,typeof e==`function`?e.displayName||e.name||`Unknown`:e),u(e,p,i,a(),l,d)}function f(e){p(e)?e._store&&(e._store.validated=1):typeof e==`object`&&e&&e.$$typeof===E&&(e._payload.status===`fulfilled`?p(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function p(e){return typeof e==`object`&&!!e&&e.$$typeof===h}var m=require(`react`),h=Symbol.for(`react.transitional.element`),g=Symbol.for(`react.portal`),_=Symbol.for(`react.fragment`),v=Symbol.for(`react.strict_mode`),y=Symbol.for(`react.profiler`),b=Symbol.for(`react.consumer`),x=Symbol.for(`react.context`),S=Symbol.for(`react.forward_ref`),C=Symbol.for(`react.suspense`),w=Symbol.for(`react.suspense_list`),T=Symbol.for(`react.memo`),E=Symbol.for(`react.lazy`),D=Symbol.for(`react.activity`),O=Symbol.for(`react.client.reference`),k=m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,A=Object.prototype.hasOwnProperty,j=Array.isArray,M=console.createTask?console.createTask:function(){return null};m={react_stack_bottom_frame:function(e){return e()}};var N,P={},F=m.react_stack_bottom_frame.bind(m,o)(),I=M(i(o)),L={};e.Fragment=_,e.jsx=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!1,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)},e.jsxs=function(e,t,n){var r=1e4>k.recentlyCreatedOwnerStacks++;return d(e,t,n,!0,r?Error(`react-stack-top-frame`):F,r?M(i(e)):I)}})()})),T=c(((e,t)=>{process.env.NODE_ENV===`production`?t.exports=C():t.exports=w()}))(),E=(0,t.memo)(({artworkUrl:e,title:t,isLoading:n})=>(0,T.jsxs)(`div`,{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`,children:[(0,T.jsx)(`div`,{className:`w-full h-full transition-all duration-700 ${n?`blur-md scale-110`:``}`,children:e?(0,T.jsx)(`img`,{src:e,alt:t,className:`w-full h-full object-cover transition-transform duration-500 group-hover/artwork:scale-110`}):(0,T.jsx)(`div`,{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`,children:(0,T.jsx)(`svg`,{className:`w-16 h-16 text-white opacity-50`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,T.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`})})})}),n&&(0,T.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-black/10 backdrop-blur-[1px]`,children:(0,T.jsx)(`div`,{className:`w-8 h-8 border-4 border-white/30 border-t-white rounded-full animate-spin`})})]}));E.displayName=`ArtworkOverlay`;var D=(0,t.memo)(({peaks:e,currentTime:n,duration:r,waveColor:i,progressColor:a,height:o,onSeek:s,resolution:c=`auto`,barWidth:l=2,barGap:u=1})=>{let d=(0,t.useRef)(null),f=(0,t.useRef)(null),p=(0,t.useRef)(null),m=S(p);(0,t.useEffect)(()=>{let t=d.current,n=f.current;if(!t||!n)return;let r=t.getContext(`2d`),o=n.getContext(`2d`);if(!r||!o)return;let s=window.devicePixelRatio||1,p=t.getBoundingClientRect(),m=p.width*s,h=p.height*s;[t,n].forEach(e=>{(e.width!==m||e.height!==h)&&(e.width=m,e.height=h)}),(()=>{if(e.length===0)return;let{width:n,height:d}=t;r.clearRect(0,0,n,d),o.clearRect(0,0,n,d);let f=n/e.length,p=typeof c==`number`?f*.7:l*s,m=typeof c==`number`?f*.3:u*s;r.lineCap=`round`,r.lineWidth=p,o.lineCap=`round`,o.lineWidth=p,e.forEach((e,t)=>{let n=t*(p+m)+p/2,s=e*d*.8,c=(d-s)/2,l=c+s;r.beginPath(),r.strokeStyle=i,r.moveTo(n,c),r.lineTo(n,l),r.stroke(),o.beginPath(),o.strokeStyle=a,o.moveTo(n,c),o.lineTo(n,l),o.stroke()})})()},[e,i,a,c,l,u,o]);let h=e=>{if(p.current&&r){let t=p.current.getBoundingClientRect(),n=e.clientX-t.left;s(Math.max(0,Math.min(1,n/t.width)))}},g=r?n/r*100:0;return(0,T.jsxs)(`div`,{ref:p,className:`relative w-full cursor-pointer overflow-hidden`,style:{height:`${o}px`},onClick:h,children:[(0,T.jsx)(`canvas`,{ref:d,className:`absolute inset-0 w-full h-full`}),(0,T.jsx)(`div`,{className:`absolute inset-0 h-full overflow-hidden transition-[width] duration-100 ease-linear pointer-events-none`,style:{width:`${g}%`},children:(0,T.jsx)(`canvas`,{ref:f,className:`absolute h-full`,style:{width:`${m}px`}})})]})});D.displayName=`Waveform`;var O=(0,t.memo)(({media:e,peaks:n,artwork:r,title:i,artist:a,waveColor:o,progressColor:s,height:c=80,className:l=``,style:u,resolution:d=`auto`,barWidth:f=2,barGap:p=1,theme:h,engine:g})=>{let{state:_,togglePlay:y,seek:b}=m(e,{peaks:n,engine:g}),{isPlaying:C,currentTime:w,duration:O,peaks:k,isAnalyzing:A}=_,[j,M]=(0,t.useState)(typeof r==`string`?r:void 0);(0,t.useEffect)(()=>{if(r instanceof Blob){let e=URL.createObjectURL(r);return M(e),()=>URL.revokeObjectURL(e)}else M(r)},[r]);let N=(0,t.useRef)(null),P=S(N),F=x(k,(0,t.useMemo)(()=>typeof d==`number`?d:P>0?Math.max(1,Math.floor(P/(f+p))):k.length||1,[d,P,f,p,k.length])),I=(0,t.useMemo)(()=>o||(h?h.bg===`#ffffff`?`#e5e7eb`:`#374151`:`#e5e7eb`),[o,h]),L=s||h?.primary||`#3b82f6`,R=(0,t.useMemo)(()=>({"--wf-bg-color":h?.bg||`white`,"--wf-border-color":h?.border||`#f3f4f6`,"--wf-title-color":h?.text||`#111827`,"--wf-artist-color":h?.text||`#6b7280`,"--wf-time-color":h?.text||`#9ca3af`,"--wf-play-btn-bg":h?.primary||`#3b82f6`,"--wf-placeholder-from":h?.primary||`#fb923c`,"--wf-placeholder-to":h?.bg||`#ec4899`,...u}),[h,u]);return(0,T.jsxs)(`div`,{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 ${l}`,style:R,children:[(0,T.jsx)(E,{artworkUrl:j,title:i,isLoading:A}),(0,T.jsxs)(`div`,{className:`flex-1 w-full flex flex-col min-w-0`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-4 mb-6`,children:[(0,T.jsx)(`button`,{onClick:y,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`,children:C?(0,T.jsx)(`svg`,{className:`w-6 h-6 md:w-7 md:h-7`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,T.jsx)(`path`,{d:`M6 19h4V5H6v14zm8-14v14h4V5h-4z`})}):(0,T.jsx)(`svg`,{className:`w-6 h-6 md:w-7 md:h-7 ml-1`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,T.jsx)(`path`,{d:`M8 5v14l11-7z`})})}),(0,T.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[a&&(0,T.jsx)(`p`,{className:`text-[10px] md:text-xs font-bold uppercase text-[var(--wf-artist-color,#6b7280)] opacity-60 tracking-[0.1em] line-clamp-1`,children:a}),(0,T.jsxs)(`div`,{className:`text-[10px] font-mono text-[var(--wf-time-color,#9ca3af)] tabular-nums flex-shrink-0`,children:[v(w),` / `,v(O)]})]}),i&&(0,T.jsx)(`h3`,{className:`text-lg md:text-xl font-black text-[var(--wf-title-color,#111827)] tracking-tight line-clamp-1 mt-0.5 leading-tight`,children:i})]})]}),(0,T.jsx)(`div`,{className:`mt-auto`,ref:N,children:(0,T.jsx)(D,{peaks:F,currentTime:w,duration:O,waveColor:I,progressColor:L,height:c,onSeek:b,resolution:d,barWidth:f,barGap:p})})]})]})});O.displayName=`WaveframePlayer`,e.PeakAnalyzer=d,e.PlayerCore=u,e.WaveframeEngine=f,e.WaveframePlayer=O,e.formatTime=v,e.generatePeaks=h,e.highlightCode=b,e.loadAudioToMemory=g,e.resamplePeaks=y,e.revokeAudioMemory=_,e.useWaveframeStore=p});
|