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/index.d.ts
CHANGED
|
@@ -1,2 +1,491 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Defines the core color palette for the Waveframe component.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const darkTheme: WaveframeTheme = {
|
|
9
|
+
* bg: '#111827',
|
|
10
|
+
* primary: '#ec4899',
|
|
11
|
+
* text: '#f9fafb',
|
|
12
|
+
* border: '#1f2937'
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
interface WaveframeTheme {
|
|
17
|
+
/** The main background color of the player */
|
|
18
|
+
bg: string;
|
|
19
|
+
/** The primary accent color (used for play button and progress) */
|
|
20
|
+
primary: string;
|
|
21
|
+
/** The color of the text elements (title, artist, time) */
|
|
22
|
+
text: string;
|
|
23
|
+
/** The color of borders and dividers */
|
|
24
|
+
border: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Metadata associated with an audio track.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const track: TrackInfo = {
|
|
32
|
+
* title: 'Electronic Sunset',
|
|
33
|
+
* artist: 'Digital Nomad',
|
|
34
|
+
* artwork: 'https://example.com/art.jpg', // or a Blob object
|
|
35
|
+
* audioUrl: 'https://example.com/audio.mp3'
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
interface TrackInfo {
|
|
40
|
+
/** The title of the track */
|
|
41
|
+
title: string;
|
|
42
|
+
/** The artist of the track */
|
|
43
|
+
artist: string;
|
|
44
|
+
/** The artwork source (URL string or Blob/File object) */
|
|
45
|
+
artwork: string | Blob;
|
|
46
|
+
/** The URL to the actual audio file */
|
|
47
|
+
audioUrl: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Defines the resolution of the waveform.
|
|
51
|
+
* - `number`: A fixed number of bars to render.
|
|
52
|
+
* - `'auto'`: Compute the number of bars dynamically based on the container width.
|
|
53
|
+
*/
|
|
54
|
+
type Resolution = number | 'auto';
|
|
55
|
+
/**
|
|
56
|
+
* Configuration options for how the waveform is rendered visually.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* const config: WaveformConfig = {
|
|
61
|
+
* resolution: 'auto',
|
|
62
|
+
* barWidth: 2,
|
|
63
|
+
* barGap: 1,
|
|
64
|
+
* height: 100
|
|
65
|
+
* };
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
interface WaveformConfig {
|
|
69
|
+
/** The number of bars to render, or 'auto' to compute based on container width */
|
|
70
|
+
resolution: Resolution;
|
|
71
|
+
/** The width of each individual bar in pixels */
|
|
72
|
+
barWidth: number;
|
|
73
|
+
/** The spacing between each bar in pixels */
|
|
74
|
+
barGap: number;
|
|
75
|
+
/** The total height of the waveform in pixels */
|
|
76
|
+
height: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Represents the low-level playback state of the audio element.
|
|
81
|
+
*/
|
|
82
|
+
type PlayerState = {
|
|
83
|
+
/** Whether the audio is currently playing */
|
|
84
|
+
isPlaying: boolean;
|
|
85
|
+
/** The current playback time in seconds */
|
|
86
|
+
currentTime: number;
|
|
87
|
+
/** The total duration of the track in seconds */
|
|
88
|
+
duration: number;
|
|
89
|
+
/** The current volume level (0 to 1) */
|
|
90
|
+
volume: number;
|
|
91
|
+
/** Whether the audio is currently muted */
|
|
92
|
+
muted: boolean;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* A callback function that receives the latest PlayerState.
|
|
96
|
+
*/
|
|
97
|
+
type PlayerListener = (state: PlayerState) => void;
|
|
98
|
+
/**
|
|
99
|
+
* The internal core class responsible for managing the HTMLAudioElement.
|
|
100
|
+
*
|
|
101
|
+
* It handles raw playback logic, volume control, and synchronizes the
|
|
102
|
+
* internal `PlayerState` with DOM events from the underlying `Audio` instance.
|
|
103
|
+
*/
|
|
104
|
+
declare class PlayerCore {
|
|
105
|
+
private audio;
|
|
106
|
+
private listeners;
|
|
107
|
+
private _state;
|
|
108
|
+
/**
|
|
109
|
+
* Initializes a new PlayerCore instance and sets up event listeners on a new Audio object.
|
|
110
|
+
*/
|
|
111
|
+
constructor();
|
|
112
|
+
/**
|
|
113
|
+
* Subscribes to various HTMLMediaElement events to keep the internal state in sync.
|
|
114
|
+
*/
|
|
115
|
+
private initListeners;
|
|
116
|
+
/**
|
|
117
|
+
* Updates the internal state and notifies subscribers.
|
|
118
|
+
*/
|
|
119
|
+
private updateState;
|
|
120
|
+
/**
|
|
121
|
+
* Triggers all registered listener callbacks.
|
|
122
|
+
*/
|
|
123
|
+
private notify;
|
|
124
|
+
/**
|
|
125
|
+
* Registers a listener for state updates.
|
|
126
|
+
* @param listener The callback function.
|
|
127
|
+
* @returns An unsubscribe function.
|
|
128
|
+
*/
|
|
129
|
+
subscribe(listener: PlayerListener): () => boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the current playback state.
|
|
132
|
+
*/
|
|
133
|
+
get state(): PlayerState;
|
|
134
|
+
/**
|
|
135
|
+
* Updates the source URL of the underlying audio element.
|
|
136
|
+
* @param url The audio source URL.
|
|
137
|
+
*/
|
|
138
|
+
setSource(url: string): void;
|
|
139
|
+
/**
|
|
140
|
+
* Starts playback. Returns a promise that resolves when playback begins.
|
|
141
|
+
*/
|
|
142
|
+
play(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Pauses playback.
|
|
145
|
+
*/
|
|
146
|
+
pause(): void;
|
|
147
|
+
/**
|
|
148
|
+
* Toggles between play and pause states.
|
|
149
|
+
*/
|
|
150
|
+
togglePlay(): void;
|
|
151
|
+
/**
|
|
152
|
+
* Seeks to a specific time.
|
|
153
|
+
* @param time Time in seconds.
|
|
154
|
+
*/
|
|
155
|
+
seek(time: number): void;
|
|
156
|
+
/**
|
|
157
|
+
* Sets the volume level.
|
|
158
|
+
* @param volume Level from 0 to 1.
|
|
159
|
+
*/
|
|
160
|
+
setVolume(volume: number): void;
|
|
161
|
+
/**
|
|
162
|
+
* Mutes or unmutes the audio element.
|
|
163
|
+
* @param muted Mute status.
|
|
164
|
+
*/
|
|
165
|
+
setMuted(muted: boolean): void;
|
|
166
|
+
/**
|
|
167
|
+
* Cleans up the audio element and removes all listeners.
|
|
168
|
+
*/
|
|
169
|
+
dispose(): void;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Represents the complete state of the Waveframe engine, combining playback and analysis.
|
|
174
|
+
*/
|
|
175
|
+
type EngineState = PlayerState & {
|
|
176
|
+
/** The current set of generated or provided waveform peaks (0-1 range) */
|
|
177
|
+
peaks: number[];
|
|
178
|
+
/** Whether an audio analysis process is currently in progress */
|
|
179
|
+
isAnalyzing: boolean;
|
|
180
|
+
/** Any error message encountered during playback or analysis */
|
|
181
|
+
error: string | null;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* A callback function that receives the latest EngineState.
|
|
185
|
+
*/
|
|
186
|
+
type EngineListener = (state: EngineState) => void;
|
|
187
|
+
/**
|
|
188
|
+
* The orchestrator class for Waveframe.
|
|
189
|
+
*
|
|
190
|
+
* It manages the lifecycle of audio playback and waveform analysis, providing a unified
|
|
191
|
+
* store-like interface that can be easily consumed by React or other frameworks.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const engine = new WaveframeEngine();
|
|
196
|
+
*
|
|
197
|
+
* // Load from URL (automatic analysis if peaks omitted)
|
|
198
|
+
* engine.load('https://example.com/audio.mp3');
|
|
199
|
+
*
|
|
200
|
+
* // Load from Blob with pre-computed peaks
|
|
201
|
+
* engine.load(myBlob, [0.1, 0.5, 0.8]);
|
|
202
|
+
*
|
|
203
|
+
* // Subscription
|
|
204
|
+
* const unsubscribe = engine.subscribe((state) => {
|
|
205
|
+
* console.log('Current time:', state.currentTime);
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare class WaveframeEngine {
|
|
210
|
+
private player;
|
|
211
|
+
private analyzer;
|
|
212
|
+
private listeners;
|
|
213
|
+
private _state;
|
|
214
|
+
private _media;
|
|
215
|
+
private _objectUrl;
|
|
216
|
+
/**
|
|
217
|
+
* Creates a new instance of the WaveframeEngine.
|
|
218
|
+
* Initializes internal PlayerCore and PeakAnalyzer.
|
|
219
|
+
*/
|
|
220
|
+
constructor();
|
|
221
|
+
/**
|
|
222
|
+
* Internal method to update the state and notify all subscribers.
|
|
223
|
+
*/
|
|
224
|
+
private updateState;
|
|
225
|
+
/**
|
|
226
|
+
* Notifies all registered listeners of a state change.
|
|
227
|
+
*/
|
|
228
|
+
private notify;
|
|
229
|
+
/**
|
|
230
|
+
* Registers a listener to be called whenever the engine state changes.
|
|
231
|
+
* @param listener The callback function.
|
|
232
|
+
* @returns An unsubscribe function.
|
|
233
|
+
*/
|
|
234
|
+
subscribe(listener: EngineListener): () => boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Returns a snapshot of the current engine state.
|
|
237
|
+
* Useful for `useSyncExternalStore`.
|
|
238
|
+
*/
|
|
239
|
+
getSnapshot(): EngineState;
|
|
240
|
+
/**
|
|
241
|
+
* Revokes any existing Object URLs to prevent memory leaks.
|
|
242
|
+
*/
|
|
243
|
+
private revokeOldSource;
|
|
244
|
+
/**
|
|
245
|
+
* Loads media (URL or Blob) into the player.
|
|
246
|
+
*
|
|
247
|
+
* If a string is passed, it's treated as a URL and used directly for playback.
|
|
248
|
+
* If a Blob is passed, an Object URL is created for playback.
|
|
249
|
+
*
|
|
250
|
+
* If `peaks` are not provided, it automatically triggers an analysis.
|
|
251
|
+
*
|
|
252
|
+
* @param media The audio source (URL string or Blob/File object).
|
|
253
|
+
* @param peaks Optional pre-generated peaks for the waveform.
|
|
254
|
+
*/
|
|
255
|
+
load(media: string | Blob, peaks?: number[]): void;
|
|
256
|
+
/**
|
|
257
|
+
* Analyzes the current media to generate waveform peaks.
|
|
258
|
+
* @param samples The number of peaks to generate. Defaults to 512.
|
|
259
|
+
*/
|
|
260
|
+
analyze(samples?: number): Promise<void>;
|
|
261
|
+
/**
|
|
262
|
+
* Toggles playback between playing and paused.
|
|
263
|
+
*/
|
|
264
|
+
togglePlay(): void;
|
|
265
|
+
/**
|
|
266
|
+
* Starts audio playback.
|
|
267
|
+
*/
|
|
268
|
+
play(): void;
|
|
269
|
+
/**
|
|
270
|
+
* Pauses audio playback.
|
|
271
|
+
*/
|
|
272
|
+
pause(): void;
|
|
273
|
+
/**
|
|
274
|
+
* Seeks to a specific position in the track.
|
|
275
|
+
* @param percentage The seek position as a decimal (0 to 1).
|
|
276
|
+
*/
|
|
277
|
+
seek(percentage: number): void;
|
|
278
|
+
/**
|
|
279
|
+
* Sets the playback volume.
|
|
280
|
+
* @param volume The volume level (0 to 1).
|
|
281
|
+
*/
|
|
282
|
+
setVolume(volume: number): void;
|
|
283
|
+
/**
|
|
284
|
+
* Mutes or unmutes the audio.
|
|
285
|
+
* @param muted Whether the audio should be muted.
|
|
286
|
+
*/
|
|
287
|
+
setMuted(muted: boolean): void;
|
|
288
|
+
/**
|
|
289
|
+
* Disposes of the engine, pausing playback and clearing all listeners and resources.
|
|
290
|
+
*/
|
|
291
|
+
dispose(): void;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Props for the WaveframePlayer component
|
|
296
|
+
*/
|
|
297
|
+
interface WaveframePlayerProps {
|
|
298
|
+
/**
|
|
299
|
+
* The audio source to play. Can be a URL string or a Blob/File object.
|
|
300
|
+
*/
|
|
301
|
+
media?: string | Blob;
|
|
302
|
+
/**
|
|
303
|
+
* Optional pre-generated peaks for the waveform (0-1 range).
|
|
304
|
+
* If omitted or empty, the player will automatically analyze the media.
|
|
305
|
+
*/
|
|
306
|
+
peaks?: number[];
|
|
307
|
+
/**
|
|
308
|
+
* The artwork source to display. Can be a URL string or a Blob/File object.
|
|
309
|
+
*/
|
|
310
|
+
artwork?: string | Blob;
|
|
311
|
+
/**
|
|
312
|
+
* The title of the track
|
|
313
|
+
*/
|
|
314
|
+
title?: string;
|
|
315
|
+
/**
|
|
316
|
+
* The artist of the track
|
|
317
|
+
*/
|
|
318
|
+
artist?: string;
|
|
319
|
+
/**
|
|
320
|
+
* The base color of the waveform bars
|
|
321
|
+
* @default "#e5e7eb" (light) or "#374151" (dark)
|
|
322
|
+
*/
|
|
323
|
+
waveColor?: string;
|
|
324
|
+
/**
|
|
325
|
+
* The color of the played progress part of the waveform
|
|
326
|
+
* @default theme.primary or "#3b82f6"
|
|
327
|
+
*/
|
|
328
|
+
progressColor?: string;
|
|
329
|
+
/**
|
|
330
|
+
* The height of the waveform in pixels
|
|
331
|
+
* @default 80
|
|
332
|
+
*/
|
|
333
|
+
height?: number;
|
|
334
|
+
/**
|
|
335
|
+
* Additional CSS classes for the container
|
|
336
|
+
*/
|
|
337
|
+
className?: string;
|
|
338
|
+
/**
|
|
339
|
+
* Inline styles for the container
|
|
340
|
+
*/
|
|
341
|
+
style?: React.CSSProperties;
|
|
342
|
+
/**
|
|
343
|
+
* The number of bars to render. Use 'auto' to fit the container width.
|
|
344
|
+
* @default "auto"
|
|
345
|
+
*/
|
|
346
|
+
resolution?: number | 'auto';
|
|
347
|
+
/**
|
|
348
|
+
* The width of each bar in pixels (if resolution is 'auto')
|
|
349
|
+
* @default 2
|
|
350
|
+
*/
|
|
351
|
+
barWidth?: number;
|
|
352
|
+
/**
|
|
353
|
+
* The gap between bars in pixels (if resolution is 'auto')
|
|
354
|
+
* @default 1
|
|
355
|
+
*/
|
|
356
|
+
barGap?: number;
|
|
357
|
+
/**
|
|
358
|
+
* Custom theme configuration
|
|
359
|
+
*/
|
|
360
|
+
theme?: WaveframeTheme;
|
|
361
|
+
/**
|
|
362
|
+
* Optional WaveframeEngine instance for external control.
|
|
363
|
+
* If provided, the player will sync with this engine instead of creating its own.
|
|
364
|
+
*/
|
|
365
|
+
engine?: WaveframeEngine;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* The standard "all-in-one" Waveframe player component.
|
|
369
|
+
*
|
|
370
|
+
* This component features a SoundCloud-inspired layout with a prominent
|
|
371
|
+
* play/pause button positioned next to the track metadata.
|
|
372
|
+
*/
|
|
373
|
+
declare const WaveframePlayer: React.FC<WaveframePlayerProps>;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* A specialized class for decoding audio data and generating waveform peaks.
|
|
377
|
+
*
|
|
378
|
+
* It leverages the Web Audio API (`AudioContext`) to process audio buffers
|
|
379
|
+
* and extract amplitude data for visualization.
|
|
380
|
+
*/
|
|
381
|
+
declare class PeakAnalyzer {
|
|
382
|
+
private audioCtx;
|
|
383
|
+
/**
|
|
384
|
+
* Initializes the analyzer. AudioContext creation is deferred to the first use
|
|
385
|
+
* to comply with browser autoplay and resource management policies.
|
|
386
|
+
*/
|
|
387
|
+
constructor();
|
|
388
|
+
/**
|
|
389
|
+
* Lazily creates or returns the existing AudioContext.
|
|
390
|
+
*/
|
|
391
|
+
private getContext;
|
|
392
|
+
/**
|
|
393
|
+
* Processes media (URL or Blob) and generates a set of normalized peaks.
|
|
394
|
+
*
|
|
395
|
+
* @param media The URL string or Blob object to analyze.
|
|
396
|
+
* @param samples The number of peaks (bars) to generate. Defaults to 512.
|
|
397
|
+
* @returns A promise resolving to an array of normalized peak values (0 to 1).
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```typescript
|
|
401
|
+
* const analyzer = new PeakAnalyzer();
|
|
402
|
+
*
|
|
403
|
+
* // Analyze from URL
|
|
404
|
+
* const peaksFromUrl = await analyzer.generatePeaks('https://example.com/audio.mp3');
|
|
405
|
+
*
|
|
406
|
+
* // Analyze from Blob
|
|
407
|
+
* const peaksFromBlob = await analyzer.generatePeaks(myAudioBlob);
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
generatePeaks(media: string | Blob, samples?: number): Promise<number[]>;
|
|
411
|
+
/**
|
|
412
|
+
* Closes the AudioContext and releases system audio resources.
|
|
413
|
+
*/
|
|
414
|
+
dispose(): void;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* A React hook that synchronizes a WaveframeEngine's state with a React component.
|
|
419
|
+
*
|
|
420
|
+
* It uses `useSyncExternalStore` for high-performance updates, ensuring that
|
|
421
|
+
* the component only re-renders when the engine's state snapshot actually changes.
|
|
422
|
+
*
|
|
423
|
+
* @param engine The WaveframeEngine instance to subscribe to.
|
|
424
|
+
* @returns The current EngineState (isPlaying, currentTime, peaks, etc.).
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* ```tsx
|
|
428
|
+
* const MyPlayer = ({ engine }: { engine: WaveframeEngine }) => {
|
|
429
|
+
* const { isPlaying, currentTime, duration } = useWaveframeStore(engine);
|
|
430
|
+
*
|
|
431
|
+
* return (
|
|
432
|
+
* <div>
|
|
433
|
+
* <button onClick={() => engine.togglePlay()}>
|
|
434
|
+
* {isPlaying ? 'Pause' : 'Play'}
|
|
435
|
+
* </button>
|
|
436
|
+
* <p>{currentTime.toFixed(2)} / {duration.toFixed(2)}</p>
|
|
437
|
+
* </div>
|
|
438
|
+
* );
|
|
439
|
+
* };
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare const useWaveframeStore: (engine: WaveframeEngine) => EngineState;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Loads audio from a URL, decodes it, and generates a specific number of peaks (samples).
|
|
446
|
+
*
|
|
447
|
+
* This is a high-level utility function that internally manages a `PeakAnalyzer` instance.
|
|
448
|
+
*
|
|
449
|
+
* @param audioUrl The URL of the audio file to analyze.
|
|
450
|
+
* @param samples The number of peaks (bars) to generate. Defaults to 512.
|
|
451
|
+
* @returns A promise resolving to an array of normalized peak values (0 to 1).
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```typescript
|
|
455
|
+
* const peaks = await generatePeaks('https://example.com/audio.mp3', 256);
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
declare const generatePeaks: (audioUrl: string, samples?: number) => Promise<number[]>;
|
|
459
|
+
/**
|
|
460
|
+
* Loads audio into memory as a Blob and returns a temporary Object URL.
|
|
461
|
+
*
|
|
462
|
+
* Useful for ensuring audio data is fully loaded locally before starting
|
|
463
|
+
* playback or analysis, which can help with CORS issues or slow networks.
|
|
464
|
+
*
|
|
465
|
+
* @param url The URL of the remote audio file.
|
|
466
|
+
* @returns A promise resolving to a temporary `blob:` URL.
|
|
467
|
+
*/
|
|
468
|
+
declare const loadAudioToMemory: (url: string) => Promise<string>;
|
|
469
|
+
/**
|
|
470
|
+
* Cleanup function to prevent memory leaks from Object URLs.
|
|
471
|
+
*
|
|
472
|
+
* Call this when a `blob:` URL is no longer needed (e.g., when the component unmounts).
|
|
473
|
+
*
|
|
474
|
+
* @param url The Object URL to revoke.
|
|
475
|
+
*/
|
|
476
|
+
declare const revokeAudioMemory: (url: string) => void;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Formats seconds into a M:SS string
|
|
480
|
+
*/
|
|
481
|
+
declare const formatTime: (seconds: number) => string;
|
|
482
|
+
/**
|
|
483
|
+
* Resamples an array of peaks to a target count using bucket-max or linear interpolation
|
|
484
|
+
*/
|
|
485
|
+
declare const resamplePeaks: (peaks: number[], targetCount: number) => number[];
|
|
486
|
+
/**
|
|
487
|
+
* High-performance token-based syntax highlighter for React snippets
|
|
488
|
+
*/
|
|
489
|
+
declare const highlightCode: (code: string) => string[];
|
|
490
|
+
|
|
491
|
+
export { type EngineListener, type EngineState, PeakAnalyzer, PlayerCore, type PlayerListener, type PlayerState, type Resolution, type TrackInfo, type WaveformConfig, WaveframeEngine, WaveframePlayer, type WaveframePlayerProps, type WaveframeTheme, formatTime, generatePeaks, highlightCode, loadAudioToMemory, resamplePeaks, revokeAudioMemory, useWaveframeStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {memo,useRef,useEffect,useState,useMemo,useSyncExternalStore}from'react';import {jsxs,jsx}from'react/jsx-runtime';var A=class{audio;listeners=new Set;_state;constructor(){this.audio=new Audio,this._state={isPlaying:false,currentTime:0,duration:0,volume:1,muted:false},this.initListeners();}initListeners(){this.audio.addEventListener("play",()=>this.updateState({isPlaying:true})),this.audio.addEventListener("pause",()=>this.updateState({isPlaying:false})),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:false}));}updateState(t){this._state={...this._state,...t},this.notify();}notify(){this.listeners.forEach(t=>t(this._state));}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}get state(){return this._state}setSource(t){this.audio.src=t,this.audio.load();}play(){return this.audio.play()}pause(){this.audio.pause();}togglePlay(){this._state.isPlaying?this.pause():this.play();}seek(t){this.audio.currentTime=t;}setVolume(t){this.audio.volume=t;}setMuted(t){this.audio.muted=t;}dispose(){this.pause(),this.audio.src="",this.listeners.clear();}};var C=class{audioCtx=null;constructor(){}getContext(){return this.audioCtx||(this.audioCtx=new(window.AudioContext||window.webkitAudioContext)),this.audioCtx}async generatePeaks(t,e=512){try{let o;if(typeof t=="string"){let c=await fetch(t);if(!c.ok)throw new Error(`Failed to fetch audio: ${c.statusText}`);o=await c.arrayBuffer();}else o=await t.arrayBuffer();let n=(await this.getContext().decodeAudioData(o)).getChannelData(0),s=Math.floor(n.length/e),l=[];for(let c=0;c<e;c++){let u=0,g=c*s,d=g+s;for(let y=g;y<d;y++){let S=Math.abs(n[y]);S>u&&(u=S);}l.push(u);}let x=Math.max(...l);return l.map(c=>c/(x||1))}catch(o){throw console.error("PeakAnalyzer Error:",o),o}}dispose(){this.audioCtx&&(this.audioCtx.close(),this.audioCtx=null);}};var W=class{player;analyzer;listeners=new Set;_state;_media=null;_objectUrl=null;constructor(){this.player=new A,this.analyzer=new C,this._state={...this.player.state,peaks:[],isAnalyzing:false,error:null},this.player.subscribe(t=>{this.updateState({...t});});}updateState(t){this._state={...this._state,...t},this.notify();}notify(){this.listeners.forEach(t=>t(this._state));}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}getSnapshot(){return this._state}revokeOldSource(){this._objectUrl&&(URL.revokeObjectURL(this._objectUrl),this._objectUrl=null);}load(t,e){if(this._media!==t){this.revokeOldSource(),this._media=t;let i;typeof t=="string"?i=t:(this._objectUrl=URL.createObjectURL(t),i=this._objectUrl),this.player.setSource(i);let a=e&&e.length>0;this.updateState({peaks:e||[],isAnalyzing:false,error:null}),a||this.analyze();}else e&&e!==this._state.peaks&&this.updateState({peaks:e});}async analyze(t=512){if(!this._media){this.updateState({error:"No media loaded to analyze"});return}this.updateState({isAnalyzing:true,error:null});try{let e=await this.analyzer.generatePeaks(this._media,t);this.updateState({peaks:e,isAnalyzing:!1});}catch(e){this.updateState({isAnalyzing:false,error:e instanceof Error?e.message:"Analysis failed"});}}togglePlay(){this.player.togglePlay();}play(){this.player.play();}pause(){this.player.pause();}seek(t){let{duration:e}=this._state;e&&this.player.seek(t*e);}setVolume(t){this.player.setVolume(t);}setMuted(t){this.player.setMuted(t);}dispose(){this.revokeOldSource(),this.player.dispose(),this.analyzer.dispose(),this.listeners.clear();}};var q=r=>useSyncExternalStore(t=>r.subscribe(t),()=>r.getSnapshot());var Q=(r,t={})=>{let{peaks:e,engine:o}=t,i=useMemo(()=>o||new W,[o]),a=o||i,n=q(a);return useEffect(()=>{r&&a.load(r,e);},[a,r,e]),useEffect(()=>()=>{o||i.dispose();},[i,o]),{state:n,engine:a,togglePlay:()=>a.togglePlay(),play:()=>a.play(),pause:()=>a.pause(),seek:s=>a.seek(s),setVolume:s=>a.setVolume(s),setMuted:s=>a.setMuted(s),analyze:s=>a.analyze(s)}};var Nt=async(r,t=512)=>{let e=new C;try{return await e.generatePeaks(r,t)}finally{e.dispose();}},jt=async r=>{let e=await(await fetch(r)).blob();return URL.createObjectURL(e)},At=r=>{r&&r.startsWith("blob:")&&URL.revokeObjectURL(r);};var V=r=>{if(isNaN(r))return "0:00";let t=Math.floor(r/60),e=Math.floor(r%60);return `${t}:${e.toString().padStart(2,"0")}`},Y=(r,t)=>{if(r.length===0)return [];if(r.length===t)return r;let e=new Array(t),o=r.length/t;if(o>1)for(let i=0;i<t;i++){let a=0,n=Math.floor(i*o),s=Math.floor((i+1)*o);for(let l=n;l<s;l++)r[l]>a&&(a=r[l]);e[i]=a;}else for(let i=0;i<t;i++){let a=i*o,n=Math.floor(a),s=Math.min(n+1,r.length-1),l=a-n;e[i]=r[n]+(r[s]-r[n])*l;}return e},Tt=r=>r.split(`
|
|
3
|
+
`).map(t=>{let e=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),o={},i=0,a=(n,s)=>{let l=`__TOKEN_${i++}__`;return o[l]=`<span class="${s}">${n}</span>`,l};return e=e.replace(/("(?:[^"\\]|\\.)*")/g,n=>a(n,"text-[#ce9178]")),e=e.replace(/\b(\d+(\.\d+)?)\b/g,n=>a(n,"text-[#b5cea8]")),e=e.replace(/\b(WaveframePlayer)\b/g,n=>a(n,"text-[#4ec9b0]")),e=e.replace(/\b([a-z][a-zA-Z0-9]+)(?==)/g,n=>a(n,"text-[#9cdcfe]")),e=e.replace(/(<|>|\{|\}|\/|:|,)/g,'<span class="text-gray-500">$1</span>'),Object.entries(o).forEach(([n,s])=>{e=e.replace(n,s);}),e});var tt=(r,t)=>useMemo(()=>Y(r,t),[r,t]);var T=r=>{let[t,e]=useState(0);return useEffect(()=>{if(!r.current)return;let o=new ResizeObserver(i=>{for(let a of i)e(a.contentRect.width);});return o.observe(r.current),()=>o.disconnect()},[r]),t};var D=memo(({artworkUrl:r,title:t,isLoading:e})=>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:[jsx("div",{className:`w-full h-full transition-all duration-700 ${e?"blur-md scale-110":""}`,children:r?jsx("img",{src:r,alt:t,className:"w-full h-full object-cover transition-transform duration-500 group-hover/artwork:scale-110"}):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:jsx("svg",{className:"w-16 h-16 text-white opacity-50",fill:"currentColor",viewBox:"0 0 24 24",children: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"})})})}),e&&jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/10 backdrop-blur-[1px]",children:jsx("div",{className:"w-8 h-8 border-4 border-white/30 border-t-white rounded-full animate-spin"})})]}));D.displayName="ArtworkOverlay";var G=memo(({peaks:r,currentTime:t,duration:e,waveColor:o,progressColor:i,height:a,onSeek:n,resolution:s="auto",barWidth:l=2,barGap:x=1})=>{let c=useRef(null),u=useRef(null),g=useRef(null),d=T(g);useEffect(()=>{let b=c.current,f=u.current;if(!b||!f)return;let h=b.getContext("2d"),p=f.getContext("2d");if(!h||!p)return;let k=window.devicePixelRatio||1,P=b.getBoundingClientRect(),_=P.width*k,L=P.height*k;[b,f].forEach(w=>{(w.width!==_||w.height!==L)&&(w.width=_,w.height=L);}),(()=>{if(r.length===0)return;let{width:w,height:m}=b;h.clearRect(0,0,w,m),p.clearRect(0,0,w,m);let O=r.length,N=w/O,E=typeof s=="number"?N*.7:l*k,B=typeof s=="number"?N*.3:x*k;h.lineCap="round",h.lineWidth=E,p.lineCap="round",p.lineWidth=E,r.forEach(($,R)=>{let j=R*(E+B)+E/2,X=$*m*.8,H=(m-X)/2,Z=H+X;h.beginPath(),h.strokeStyle=o,h.moveTo(j,H),h.lineTo(j,Z),h.stroke(),p.beginPath(),p.strokeStyle=i,p.moveTo(j,H),p.lineTo(j,Z),p.stroke();});})();},[r,o,i,s,l,x,a]);let y=b=>{if(g.current&&e){let f=g.current.getBoundingClientRect(),h=b.clientX-f.left,p=Math.max(0,Math.min(1,h/f.width));n(p);}},S=e?t/e*100:0;return jsxs("div",{ref:g,className:"relative w-full cursor-pointer overflow-hidden",style:{height:`${a}px`},onClick:y,children:[jsx("canvas",{ref:c,className:"absolute inset-0 w-full h-full"}),jsx("div",{className:"absolute inset-0 h-full overflow-hidden transition-[width] duration-100 ease-linear pointer-events-none",style:{width:`${S}%`},children:jsx("canvas",{ref:u,className:"absolute h-full",style:{width:`${d}px`}})})]})});G.displayName="Waveform";var ut=memo(({media:r,peaks:t,artwork:e,title:o,artist:i,waveColor:a,progressColor:n,height:s=80,className:l="",style:x,resolution:c="auto",barWidth:u=2,barGap:g=1,theme:d,engine:y})=>{let{state:S,togglePlay:b,seek:f}=Q(r,{peaks:t,engine:y}),{isPlaying:h,currentTime:p,duration:k,peaks:P,isAnalyzing:_}=S,[L,U]=useState(typeof e=="string"?e:void 0);useEffect(()=>{if(e instanceof Blob){let R=URL.createObjectURL(e);return U(R),()=>URL.revokeObjectURL(R)}else U(e);},[e]);let w=useRef(null),m=T(w),O=useMemo(()=>typeof c=="number"?c:m>0?Math.max(1,Math.floor(m/(u+g))):P.length||1,[c,m,u,g,P.length]),N=tt(P,O),E=useMemo(()=>a||(d?d.bg==="#ffffff"?"#e5e7eb":"#374151":"#e5e7eb"),[a,d]),B=n||d?.primary||"#3b82f6",$=useMemo(()=>({...{"--wf-bg-color":d?.bg||"white","--wf-border-color":d?.border||"#f3f4f6","--wf-title-color":d?.text||"#111827","--wf-artist-color":d?.text||"#6b7280","--wf-time-color":d?.text||"#9ca3af","--wf-play-btn-bg":d?.primary||"#3b82f6","--wf-placeholder-from":d?.primary||"#fb923c","--wf-placeholder-to":d?.bg||"#ec4899"},...x}),[d,x]);return 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:$,children:[jsx(D,{artworkUrl:L,title:o,isLoading:_}),jsxs("div",{className:"flex-1 w-full flex flex-col min-w-0",children:[jsxs("div",{className:"flex items-center gap-4 mb-6",children:[jsx("button",{onClick:b,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:h?jsx("svg",{className:"w-6 h-6 md:w-7 md:h-7",fill:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{d:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"})}):jsx("svg",{className:"w-6 h-6 md:w-7 md:h-7 ml-1",fill:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{d:"M8 5v14l11-7z"})})}),jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[jsxs("div",{className:"flex items-center justify-between gap-4",children:[i&&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:i}),jsxs("div",{className:"text-[10px] font-mono text-[var(--wf-time-color,#9ca3af)] tabular-nums flex-shrink-0",children:[V(p)," / ",V(k)]})]}),o&&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:o})]})]}),jsx("div",{className:"mt-auto",ref:w,children:jsx(G,{peaks:N,currentTime:p,duration:k,waveColor:E,progressColor:B,height:s,onSeek:f,resolution:c,barWidth:u,barGap:g})})]})]})});ut.displayName="WaveframePlayer";export{C as PeakAnalyzer,A as PlayerCore,W as WaveframeEngine,ut as WaveframePlayer,V as formatTime,Nt as generatePeaks,Tt as highlightCode,jt as loadAudioToMemory,Y as resamplePeaks,At as revokeAudioMemory,q as useWaveframeStore};//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/PlayerCore.ts","../src/core/PeakAnalyzer.ts","../src/core/WaveframeEngine.ts","../src/hooks/useWaveframeStore.ts","../src/hooks/useWaveframe.ts","../src/utils/audio.ts","../src/utils/index.ts","../src/hooks/useResampledPeaks.ts","../src/hooks/useResizeObserver.ts","../src/molecules/ArtworkOverlay.tsx","../src/organisms/Waveform.tsx","../src/components/WaveframePlayer.tsx"],"names":["PlayerCore","patch","l","listener","url","time","volume","muted","PeakAnalyzer","media","samples","arrayBuffer","response","channelData","blockSize","peaks","i","max","start","end","j","val","maxPeak","p","error","WaveframeEngine","playerState","sourceUrl","hasPeaks","percentage","duration","useWaveframeStore","engine","useSyncExternalStore","callback","useWaveframe","options","providedEngine","internalEngine","useMemo","state","useEffect","v","m","generatePeaks","audioUrl","analyzer","loadAudioToMemory","blob","revokeAudioMemory","formatTime","seconds","min","sec","resamplePeaks","targetCount","resampled","ratio","position","index","nextIndex","fraction","highlightCode","code","line","h","tokens","counter","addToken","cls","id","html","useResampledPeaks","useResizeObserver","ref","width","setWidth","useState","observer","entries","entry","ArtworkOverlay","memo","artworkUrl","title","isLoading","jsxs","jsx","Waveform","currentTime","waveColor","progressColor","height","onSeek","resolution","barWidth","barGap","canvasRef","useRef","progressCanvasRef","containerRef","containerWidth","canvas","progressCanvas","ctx","pCtx","dpr","rect","targetWidth","targetHeight","c","barCount","actualBarTotalWidth","actualBarWidth","actualBarGap","peak","x","barHeight","yStart","yEnd","handleSeek","e","progressPercent","WaveframePlayer","propPeaks","artwork","artist","propWaveColor","propProgressColor","className","propStyle","theme","togglePlay","seek","isPlaying","isAnalyzing","resolvedArtworkUrl","setResolvedArtworkUrl","resampledPeaks","mergedStyle"],"mappings":"yHA2BO,IAAMA,CAAAA,CAAN,KAAiB,CACd,MACA,SAAA,CAAiC,IAAI,GAAA,CACrC,MAAA,CAKR,WAAA,EAAc,CACZ,IAAA,CAAK,KAAA,CAAQ,IAAI,KAA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CAAAwC,CAAAA,EACCvC,GAAAA,CAAC,GAAA,CAAA,CAAE,UAAU,2HAAA,CACV,QAAA,CAAAuC,CAAAA,CACH,CAAA,CAEFxC,IAAAA,CAAC,KAAA,CAAA,CAAI,SAAA,CAAU,sFAAA,CACZ,QAAA,CAAA,CAAApC,CAAAA,CAAWuC,CAAW,CAAA,CAAE,KAAA,CAAIvC,CAAAA,CAAWpB,CAAQ,CAAA,CAAA,CAClD,CAAA,CAAA,CACF,CAAA,CACCsD,CAAAA,EACCG,GAAAA,CAAC,IAAA,CAAA,CAAG,SAAA,CAAU,qHAAA,CACX,QAAA,CAAAH,CAAAA,CACH,CAAA,CAAA,CAEJ,CAAA,CAAA,CACF,CAAA,CAEAG,GAAAA,CAAC,KAAA,CAAA,CAAI,SAAA,CAAU,SAAA,CAAU,GAAA,CAAKa,CAAAA,CAC5B,QAAA,CAAAb,GAAAA,CAACC,CAAAA,CAAA,CACC,KAAA,CAAOkD,CAAAA,CACP,WAAA,CAAajD,CAAAA,CACb,QAAA,CAAU3D,CAAAA,CACV,SAAA,CAAW4D,CAAAA,CACX,aAAA,CAAeC,CAAAA,CACf,MAAA,CAAQC,CAAAA,CACR,MAAA,CAAQyC,CAAAA,CACR,UAAA,CAAYvC,CAAAA,CACZ,QAAA,CAAUC,CAAAA,CACV,MAAA,CAAQC,CAAAA,CACV,CAAA,CACF,CAAA,CAAA,CACF,CAAA,CAAA,CACF,CAEJ,CAAC,EAED2B,GAAgB,WAAA,CAAc,iBAAA","file":"index.js","sourcesContent":["/**\n * Represents the low-level playback state of the audio element.\n */\nexport type PlayerState = {\n /** Whether the audio is currently playing */\n isPlaying: boolean;\n /** The current playback time in seconds */\n currentTime: number;\n /** The total duration of the track in seconds */\n duration: number;\n /** The current volume level (0 to 1) */\n volume: number;\n /** Whether the audio is currently muted */\n muted: boolean;\n};\n\n/**\n * A callback function that receives the latest PlayerState.\n */\nexport type PlayerListener = (state: PlayerState) => void;\n\n/**\n * The internal core class responsible for managing the HTMLAudioElement.\n * \n * It handles raw playback logic, volume control, and synchronizes the \n * internal `PlayerState` with DOM events from the underlying `Audio` instance.\n */\nexport class PlayerCore {\n private audio: HTMLAudioElement;\n private listeners: Set<PlayerListener> = new Set();\n private _state: PlayerState;\n\n /**\n * Initializes a new PlayerCore instance and sets up event listeners on a new Audio object.\n */\n constructor() {\n this.audio = new Audio();\n this._state = {\n isPlaying: false,\n currentTime: 0,\n duration: 0,\n volume: 1,\n muted: false,\n };\n\n this.initListeners();\n }\n\n /**\n * Subscribes to various HTMLMediaElement events to keep the internal state in sync.\n */\n private initListeners() {\n this.audio.addEventListener('play', () => this.updateState({ isPlaying: true }));\n this.audio.addEventListener('pause', () => this.updateState({ isPlaying: false }));\n this.audio.addEventListener('timeupdate', () => this.updateState({ currentTime: this.audio.currentTime }));\n this.audio.addEventListener('durationchange', () => this.updateState({ duration: this.audio.duration }));\n this.audio.addEventListener('volumechange', () => this.updateState({ \n volume: this.audio.volume, \n muted: this.audio.muted \n }));\n this.audio.addEventListener('ended', () => this.updateState({ isPlaying: false }));\n }\n\n /**\n * Updates the internal state and notifies subscribers.\n */\n private updateState(patch: Partial<PlayerState>) {\n this._state = { ...this._state, ...patch };\n this.notify();\n }\n\n /**\n * Triggers all registered listener callbacks.\n */\n private notify() {\n this.listeners.forEach(l => l(this._state));\n }\n\n /**\n * Registers a listener for state updates.\n * @param listener The callback function.\n * @returns An unsubscribe function.\n */\n public subscribe(listener: PlayerListener) {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n /**\n * Returns the current playback state.\n */\n public get state() {\n return this._state;\n }\n\n /**\n * Updates the source URL of the underlying audio element.\n * @param url The audio source URL.\n */\n public setSource(url: string) {\n this.audio.src = url;\n this.audio.load();\n }\n\n /**\n * Starts playback. Returns a promise that resolves when playback begins.\n */\n public play() {\n return this.audio.play();\n }\n\n /**\n * Pauses playback.\n */\n public pause() {\n this.audio.pause();\n }\n\n /**\n * Toggles between play and pause states.\n */\n public togglePlay() {\n if (this._state.isPlaying) {\n this.pause();\n } else {\n this.play();\n }\n }\n\n /**\n * Seeks to a specific time.\n * @param time Time in seconds.\n */\n public seek(time: number) {\n this.audio.currentTime = time;\n }\n\n /**\n * Sets the volume level.\n * @param volume Level from 0 to 1.\n */\n public setVolume(volume: number) {\n this.audio.volume = volume;\n }\n\n /**\n * Mutes or unmutes the audio element.\n * @param muted Mute status.\n */\n public setMuted(muted: boolean) {\n this.audio.muted = muted;\n }\n\n /**\n * Cleans up the audio element and removes all listeners.\n */\n public dispose() {\n this.pause();\n this.audio.src = '';\n this.listeners.clear();\n }\n}\n","/**\n * A specialized class for decoding audio data and generating waveform peaks.\n * \n * It leverages the Web Audio API (`AudioContext`) to process audio buffers \n * and extract amplitude data for visualization.\n */\nexport class PeakAnalyzer {\n private audioCtx: AudioContext | null = null;\n\n /**\n * Initializes the analyzer. AudioContext creation is deferred to the first use \n * to comply with browser autoplay and resource management policies.\n */\n constructor() {}\n\n /**\n * Lazily creates or returns the existing AudioContext.\n */\n private getContext(): AudioContext {\n if (!this.audioCtx) {\n this.audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)();\n }\n return this.audioCtx;\n }\n\n /**\n * Processes media (URL or Blob) and generates a set of normalized peaks.\n * \n * @param media The URL string or Blob object to analyze.\n * @param samples The number of peaks (bars) to generate. Defaults to 512.\n * @returns A promise resolving to an array of normalized peak values (0 to 1).\n * \n * @example\n * ```typescript\n * const analyzer = new PeakAnalyzer();\n * \n * // Analyze from URL\n * const peaksFromUrl = await analyzer.generatePeaks('https://example.com/audio.mp3');\n * \n * // Analyze from Blob\n * const peaksFromBlob = await analyzer.generatePeaks(myAudioBlob);\n * ```\n */\n public async generatePeaks(media: string | Blob, samples: number = 512): Promise<number[]> {\n try {\n let arrayBuffer: ArrayBuffer;\n\n if (typeof media === 'string') {\n const response = await fetch(media);\n if (!response.ok) throw new Error(`Failed to fetch audio: ${response.statusText}`);\n arrayBuffer = await response.arrayBuffer();\n } else {\n arrayBuffer = await media.arrayBuffer();\n }\n\n const audioCtx = this.getContext();\n const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);\n \n const channelData = audioBuffer.getChannelData(0); // Use left channel\n const blockSize = Math.floor(channelData.length / samples);\n const peaks = [];\n\n for (let i = 0; i < samples; i++) {\n let max = 0;\n const start = i * blockSize;\n const end = start + blockSize;\n \n for (let j = start; j < end; j++) {\n const val = Math.abs(channelData[j]);\n if (val > max) max = val;\n }\n peaks.push(max);\n }\n \n // Normalize peaks to 0-1 range\n const maxPeak = Math.max(...peaks);\n return peaks.map(p => p / (maxPeak || 1));\n } catch (error) {\n console.error('PeakAnalyzer Error:', error);\n throw error;\n }\n }\n\n /**\n * Closes the AudioContext and releases system audio resources.\n */\n public dispose() {\n if (this.audioCtx) {\n this.audioCtx.close();\n this.audioCtx = null;\n }\n }\n}\n","import { PlayerCore, PlayerState } from './PlayerCore';\nimport { PeakAnalyzer } from './PeakAnalyzer';\n\n/**\n * Represents the complete state of the Waveframe engine, combining playback and analysis.\n */\nexport type EngineState = PlayerState & {\n /** The current set of generated or provided waveform peaks (0-1 range) */\n peaks: number[];\n /** Whether an audio analysis process is currently in progress */\n isAnalyzing: boolean;\n /** Any error message encountered during playback or analysis */\n error: string | null;\n};\n\n/**\n * A callback function that receives the latest EngineState.\n */\nexport type EngineListener = (state: EngineState) => void;\n\n/**\n * The orchestrator class for Waveframe. \n * \n * It manages the lifecycle of audio playback and waveform analysis, providing a unified \n * store-like interface that can be easily consumed by React or other frameworks.\n * \n * @example\n * ```typescript\n * const engine = new WaveframeEngine();\n * \n * // Load from URL (automatic analysis if peaks omitted)\n * engine.load('https://example.com/audio.mp3');\n * \n * // Load from Blob with pre-computed peaks\n * engine.load(myBlob, [0.1, 0.5, 0.8]);\n * \n * // Subscription\n * const unsubscribe = engine.subscribe((state) => {\n * console.log('Current time:', state.currentTime);\n * });\n * ```\n */\nexport class WaveframeEngine {\n private player: PlayerCore;\n private analyzer: PeakAnalyzer;\n private listeners: Set<EngineListener> = new Set();\n private _state: EngineState;\n\n private _media: string | Blob | null = null;\n private _objectUrl: string | null = null;\n\n /**\n * Creates a new instance of the WaveframeEngine.\n * Initializes internal PlayerCore and PeakAnalyzer.\n */\n constructor() {\n this.player = new PlayerCore();\n this.analyzer = new PeakAnalyzer();\n \n this._state = {\n ...this.player.state,\n peaks: [],\n isAnalyzing: false,\n error: null,\n };\n\n // Subscribe to player updates\n this.player.subscribe((playerState) => {\n this.updateState({ ...playerState });\n });\n }\n\n /**\n * Internal method to update the state and notify all subscribers.\n */\n private updateState(patch: Partial<EngineState>) {\n this._state = { ...this._state, ...patch };\n this.notify();\n }\n\n /**\n * Notifies all registered listeners of a state change.\n */\n private notify() {\n this.listeners.forEach(l => l(this._state));\n }\n\n // --- Store Interface ---\n\n /**\n * Registers a listener to be called whenever the engine state changes.\n * @param listener The callback function.\n * @returns An unsubscribe function.\n */\n public subscribe(listener: EngineListener) {\n this.listeners.add(listener);\n return () => this.listeners.delete(listener);\n }\n\n /**\n * Returns a snapshot of the current engine state.\n * Useful for `useSyncExternalStore`.\n */\n public getSnapshot(): EngineState {\n return this._state;\n }\n\n // --- Actions ---\n\n /**\n * Revokes any existing Object URLs to prevent memory leaks.\n */\n private revokeOldSource() {\n if (this._objectUrl) {\n URL.revokeObjectURL(this._objectUrl);\n this._objectUrl = null;\n }\n }\n\n /**\n * Loads media (URL or Blob) into the player.\n * \n * If a string is passed, it's treated as a URL and used directly for playback.\n * If a Blob is passed, an Object URL is created for playback.\n * \n * If `peaks` are not provided, it automatically triggers an analysis.\n * \n * @param media The audio source (URL string or Blob/File object).\n * @param peaks Optional pre-generated peaks for the waveform.\n */\n public load(media: string | Blob, peaks?: number[]) {\n const isNewMedia = this._media !== media;\n \n if (isNewMedia) {\n this.revokeOldSource();\n this._media = media;\n\n let sourceUrl: string;\n if (typeof media === 'string') {\n sourceUrl = media;\n } else {\n this._objectUrl = URL.createObjectURL(media);\n sourceUrl = this._objectUrl;\n }\n\n this.player.setSource(sourceUrl);\n \n const hasPeaks = peaks && peaks.length > 0;\n this.updateState({ \n peaks: peaks || [], \n isAnalyzing: false, \n error: null \n });\n\n // Automatic analysis if peaks are missing\n if (!hasPeaks) {\n this.analyze();\n }\n } else if (peaks && peaks !== this._state.peaks) {\n // Update peaks if they change even if media is same\n this.updateState({ peaks });\n }\n }\n\n /**\n * Analyzes the current media to generate waveform peaks.\n * @param samples The number of peaks to generate. Defaults to 512.\n */\n public async analyze(samples: number = 512) {\n if (!this._media) {\n this.updateState({ error: 'No media loaded to analyze' });\n return;\n }\n\n this.updateState({ isAnalyzing: true, error: null });\n try {\n const peaks = await this.analyzer.generatePeaks(this._media, samples);\n this.updateState({ peaks, isAnalyzing: false });\n } catch (e) {\n this.updateState({ \n isAnalyzing: false, \n error: e instanceof Error ? e.message : 'Analysis failed' \n });\n }\n }\n\n /**\n * Toggles playback between playing and paused.\n */\n public togglePlay() {\n this.player.togglePlay();\n }\n\n /**\n * Starts audio playback.\n */\n public play() {\n this.player.play();\n }\n\n /**\n * Pauses audio playback.\n */\n public pause() {\n this.player.pause();\n }\n\n /**\n * Seeks to a specific position in the track.\n * @param percentage The seek position as a decimal (0 to 1).\n */\n public seek(percentage: number) {\n const { duration } = this._state;\n if (duration) {\n this.player.seek(percentage * duration);\n }\n }\n\n /**\n * Sets the playback volume.\n * @param volume The volume level (0 to 1).\n */\n public setVolume(volume: number) {\n this.player.setVolume(volume);\n }\n\n /**\n * Mutes or unmutes the audio.\n * @param muted Whether the audio should be muted.\n */\n public setMuted(muted: boolean) {\n this.player.setMuted(muted);\n }\n\n /**\n * Disposes of the engine, pausing playback and clearing all listeners and resources.\n */\n public dispose() {\n this.revokeOldSource();\n this.player.dispose();\n this.analyzer.dispose();\n this.listeners.clear();\n }\n}\n","import { useSyncExternalStore } from 'react';\nimport { WaveframeEngine, EngineState } from '../core/WaveframeEngine';\n\n/**\n * A React hook that synchronizes a WaveframeEngine's state with a React component.\n * \n * It uses `useSyncExternalStore` for high-performance updates, ensuring that \n * the component only re-renders when the engine's state snapshot actually changes.\n * \n * @param engine The WaveframeEngine instance to subscribe to.\n * @returns The current EngineState (isPlaying, currentTime, peaks, etc.).\n * \n * @example\n * ```tsx\n * const MyPlayer = ({ engine }: { engine: WaveframeEngine }) => {\n * const { isPlaying, currentTime, duration } = useWaveframeStore(engine);\n * \n * return (\n * <div>\n * <button onClick={() => engine.togglePlay()}>\n * {isPlaying ? 'Pause' : 'Play'}\n * </button>\n * <p>{currentTime.toFixed(2)} / {duration.toFixed(2)}</p>\n * </div>\n * );\n * };\n * ```\n */\nexport const useWaveframeStore = (engine: WaveframeEngine): EngineState => {\n return useSyncExternalStore(\n (callback) => engine.subscribe(callback),\n () => engine.getSnapshot()\n );\n};\n","import { useMemo, useEffect } from 'react';\nimport { WaveframeEngine, EngineState } from '../core/WaveframeEngine';\nimport { useWaveframeStore } from './useWaveframeStore';\n\n/**\n * Configuration options for the `useWaveframe` hook.\n */\nexport interface UseWaveframeOptions {\n /** Optional pre-computed peaks to skip automatic analysis */\n peaks?: number[];\n /** Optional external engine instance for shared playback across components */\n engine?: WaveframeEngine;\n}\n\n/**\n * A headless hook that provides full control over the Waveframe engine.\n * \n * It manages the engine's lifecycle, loads the provided media, and returns \n * the current state along with playback controls.\n * \n * @param media The audio source (URL string or Blob/File object).\n * @param options Additional configuration and an optional external engine.\n * \n * @example\n * ```tsx\n * const { state, togglePlay, seek } = useWaveframe('https://example.com/audio.mp3');\n * \n * return (\n * <div>\n * <button onClick={togglePlay}>{state.isPlaying ? 'Pause' : 'Play'}</button>\n * <div onClick={(e) => seek(0.5)}>Seek to Middle</div>\n * </div>\n * );\n * ```\n */\nexport const useWaveframe = (media: string | Blob | undefined, options: UseWaveframeOptions = {}) => {\n const { peaks, engine: providedEngine } = options;\n\n // Initialize engine (only once)\n const internalEngine = useMemo(() => providedEngine || new WaveframeEngine(), [providedEngine]);\n const engine = providedEngine || internalEngine;\n\n // Subscribe to engine state\n const state = useWaveframeStore(engine);\n\n // Sync media with engine\n useEffect(() => {\n if (media) {\n engine.load(media, peaks);\n }\n }, [engine, media, peaks]);\n\n // Handle disposal\n useEffect(() => {\n return () => {\n // Only dispose if we created it internally\n if (!providedEngine) {\n internalEngine.dispose();\n }\n };\n }, [internalEngine, providedEngine]);\n\n return {\n /** The current reactive state of the engine */\n state,\n /** The raw WaveframeEngine instance for advanced usage */\n engine,\n /** Toggles playback between playing and paused */\n togglePlay: () => engine.togglePlay(),\n /** Starts audio playback */\n play: () => engine.play(),\n /** Pauses audio playback */\n pause: () => engine.pause(),\n /** Seeks to a specific percentage (0-1) */\n seek: (percentage: number) => engine.seek(percentage),\n /** Sets the playback volume (0-1) */\n setVolume: (v: number) => engine.setVolume(v),\n /** Mutes or unmutes the audio */\n setMuted: (m: boolean) => engine.setMuted(m),\n /** Manually triggers a re-analysis of the current media */\n analyze: (samples?: number) => engine.analyze(samples),\n };\n};\n","/**\n * Advanced Audio Utilities using Web Audio API\n */\nimport { PeakAnalyzer } from '../core/PeakAnalyzer';\n\n/**\n * Loads audio from a URL, decodes it, and generates a specific number of peaks (samples).\n * \n * This is a high-level utility function that internally manages a `PeakAnalyzer` instance.\n * \n * @param audioUrl The URL of the audio file to analyze.\n * @param samples The number of peaks (bars) to generate. Defaults to 512.\n * @returns A promise resolving to an array of normalized peak values (0 to 1).\n * \n * @example\n * ```typescript\n * const peaks = await generatePeaks('https://example.com/audio.mp3', 256);\n * ```\n */\nexport const generatePeaks = async (audioUrl: string, samples: number = 512): Promise<number[]> => {\n const analyzer = new PeakAnalyzer();\n try {\n return await analyzer.generatePeaks(audioUrl, samples);\n } finally {\n analyzer.dispose();\n }\n};\n\n/**\n * Loads audio into memory as a Blob and returns a temporary Object URL.\n * \n * Useful for ensuring audio data is fully loaded locally before starting \n * playback or analysis, which can help with CORS issues or slow networks.\n * \n * @param url The URL of the remote audio file.\n * @returns A promise resolving to a temporary `blob:` URL.\n */\nexport const loadAudioToMemory = async (url: string): Promise<string> => {\n const response = await fetch(url);\n const blob = await response.blob();\n return URL.createObjectURL(blob);\n};\n\n/**\n * Cleanup function to prevent memory leaks from Object URLs.\n * \n * Call this when a `blob:` URL is no longer needed (e.g., when the component unmounts).\n * \n * @param url The Object URL to revoke.\n */\nexport const revokeAudioMemory = (url: string) => {\n if (url && url.startsWith('blob:')) {\n URL.revokeObjectURL(url);\n }\n};\n","/**\n * Formats seconds into a M:SS string\n */\nexport const formatTime = (seconds: number): string => {\n if (isNaN(seconds)) return '0:00';\n const min = Math.floor(seconds / 60);\n const sec = Math.floor(seconds % 60);\n return `${min}:${sec.toString().padStart(2, '0')}`;\n};\n\n/**\n * Resamples an array of peaks to a target count using bucket-max or linear interpolation\n */\nexport const resamplePeaks = (peaks: number[], targetCount: number): number[] => {\n if (peaks.length === 0) return [];\n if (peaks.length === targetCount) return peaks;\n\n const resampled = new Array(targetCount);\n const ratio = peaks.length / targetCount;\n\n if (ratio > 1) {\n // Downsampling: Bucket Max\n for (let i = 0; i < targetCount; i++) {\n let max = 0;\n const start = Math.floor(i * ratio);\n const end = Math.floor((i + 1) * ratio);\n for (let j = start; j < end; j++) {\n if (peaks[j] > max) max = peaks[j];\n }\n resampled[i] = max;\n }\n } else {\n // Upsampling: Linear Interpolation\n for (let i = 0; i < targetCount; i++) {\n const position = i * ratio;\n const index = Math.floor(position);\n const nextIndex = Math.min(index + 1, peaks.length - 1);\n const fraction = position - index;\n resampled[i] = peaks[index] + (peaks[nextIndex] - peaks[index]) * fraction;\n }\n }\n return resampled;\n};\n\n/**\n * High-performance token-based syntax highlighter for React snippets\n */\nexport const highlightCode = (code: string): string[] => {\n return code.split('\\n').map((line) => {\n // 1. Escape basic HTML\n let h = line.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\n // 2. Identify and tokenize segments to avoid nested replacement issues\n const tokens: { [key: string]: string } = {};\n let counter = 0;\n const addToken = (val: string, cls: string) => {\n const id = `__TOKEN_${counter++}__`;\n tokens[id] = `<span class=\"${cls}\">${val}</span>`;\n return id;\n };\n\n // Strings\n h = h.replace(/(\"(?:[^\"\\\\]|\\\\.)*\")/g, (m) => addToken(m, 'text-[#ce9178]'));\n // Numbers\n h = h.replace(/\\b(\\d+(\\.\\d+)?)\\b/g, (m) => addToken(m, 'text-[#b5cea8]'));\n // Component Name\n h = h.replace(/\\b(WaveframePlayer)\\b/g, (m) => addToken(m, 'text-[#4ec9b0]'));\n // Props (anything followed by =)\n h = h.replace(/\\b([a-z][a-zA-Z0-9]+)(?==)/g, (m) => addToken(m, 'text-[#9cdcfe]'));\n\n // 3. Style remaining symbols\n h = h.replace(/(<|>|\\{|\\}|\\/|:|,)/g, '<span class=\"text-gray-500\">$1</span>');\n\n // 4. In-place token resolution\n Object.entries(tokens).forEach(([id, html]) => {\n h = h.replace(id, html);\n });\n\n return h;\n });\n};\n\nexport * from './audio';\n","import { useMemo } from 'react';\nimport { resamplePeaks } from '../utils';\n\nexport const useResampledPeaks = (peaks: number[], targetCount: number) => {\n return useMemo(() => resamplePeaks(peaks, targetCount), [peaks, targetCount]);\n};\n","import { useState, useEffect } from 'react';\n\nexport const useResizeObserver = (ref: React.RefObject<HTMLElement | null>) => {\n const [width, setWidth] = useState(0);\n\n useEffect(() => {\n if (!ref.current) return;\n\n const observer = new ResizeObserver((entries) => {\n for (const entry of entries) {\n setWidth(entry.contentRect.width);\n }\n });\n\n observer.observe(ref.current);\n return () => observer.disconnect();\n }, [ref]);\n\n return width;\n};\n","import React, { memo } from 'react';\n\n/**\n * Props for the ArtworkOverlay component.\n */\ninterface ArtworkOverlayProps {\n /** The URL or Object URL of the artwork image */\n artworkUrl?: string;\n /** The title of the track (used for alt text) */\n title?: string;\n /** Whether the artwork is currently being processed or the audio is analyzing */\n isLoading?: boolean;\n}\n\n/**\n * A purely visual component for displaying track artwork.\n * \n * It handles loading states with a blur effect and provides a consistent \n * container for the track image.\n */\nexport const ArtworkOverlay: React.FC<ArtworkOverlayProps> = memo(({ \n artworkUrl, \n title, \n isLoading\n}) => {\n return (\n <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\">\n <div className={`w-full h-full transition-all duration-700 ${isLoading ? 'blur-md scale-110' : ''}`}>\n {artworkUrl ? (\n <img\n src={artworkUrl}\n alt={title}\n className=\"w-full h-full object-cover transition-transform duration-500 group-hover/artwork:scale-110\"\n />\n ) : (\n <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\">\n <svg className=\"w-16 h-16 text-white opacity-50\" fill=\"currentColor\" viewBox=\"0 0 24 24\">\n <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 </svg>\n </div>\n )}\n </div>\n\n {isLoading && (\n <div className=\"absolute inset-0 flex items-center justify-center bg-black/10 backdrop-blur-[1px]\">\n <div className=\"w-8 h-8 border-4 border-white/30 border-t-white rounded-full animate-spin\" />\n </div>\n )}\n </div>\n );\n});\n\nArtworkOverlay.displayName = 'ArtworkOverlay';\n","import React, { useRef, useEffect, memo } from 'react';\nimport { useResizeObserver } from '../hooks/useResizeObserver';\n\ninterface WaveformProps {\n peaks: number[];\n currentTime: number;\n duration: number;\n waveColor: string;\n progressColor: string;\n height: number;\n onSeek: (percentage: number) => void;\n resolution?: number | 'auto';\n barWidth?: number;\n barGap?: number;\n}\n\nexport const Waveform: React.FC<WaveformProps> = memo(({\n peaks,\n currentTime,\n duration,\n waveColor,\n progressColor,\n height,\n onSeek,\n resolution = 'auto',\n barWidth = 2,\n barGap = 1,\n}) => {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const progressCanvasRef = useRef<HTMLCanvasElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const containerWidth = useResizeObserver(containerRef);\n\n useEffect(() => {\n const canvas = canvasRef.current;\n const progressCanvas = progressCanvasRef.current;\n if (!canvas || !progressCanvas) return;\n\n const ctx = canvas.getContext('2d');\n const pCtx = progressCanvas.getContext('2d');\n if (!ctx || !pCtx) return;\n\n const dpr = window.devicePixelRatio || 1;\n const rect = canvas.getBoundingClientRect();\n const targetWidth = rect.width * dpr;\n const targetHeight = rect.height * dpr;\n\n [canvas, progressCanvas].forEach(c => {\n if (c.width !== targetWidth || c.height !== targetHeight) {\n c.width = targetWidth;\n c.height = targetHeight;\n }\n });\n\n const draw = () => {\n if (peaks.length === 0) return;\n const { width, height } = canvas;\n \n ctx.clearRect(0, 0, width, height);\n pCtx.clearRect(0, 0, width, height);\n\n const barCount = peaks.length;\n const actualBarTotalWidth = width / barCount;\n const actualBarWidth = typeof resolution === 'number' \n ? actualBarTotalWidth * 0.7 \n : barWidth * dpr;\n const actualBarGap = typeof resolution === 'number'\n ? actualBarTotalWidth * 0.3\n : barGap * dpr;\n\n ctx.lineCap = 'round';\n ctx.lineWidth = actualBarWidth;\n pCtx.lineCap = 'round';\n pCtx.lineWidth = actualBarWidth;\n\n peaks.forEach((peak, index) => {\n const x = index * (actualBarWidth + actualBarGap) + actualBarWidth / 2;\n const barHeight = peak * height * 0.8;\n const yStart = (height - barHeight) / 2;\n const yEnd = yStart + barHeight;\n\n ctx.beginPath();\n ctx.strokeStyle = waveColor;\n ctx.moveTo(x, yStart);\n ctx.lineTo(x, yEnd);\n ctx.stroke();\n\n pCtx.beginPath();\n pCtx.strokeStyle = progressColor;\n pCtx.moveTo(x, yStart);\n pCtx.lineTo(x, yEnd);\n pCtx.stroke();\n });\n };\n\n draw();\n }, [peaks, waveColor, progressColor, resolution, barWidth, barGap, height]);\n\n const handleSeek = (e: React.MouseEvent<HTMLDivElement>) => {\n if (containerRef.current && duration) {\n const rect = containerRef.current.getBoundingClientRect();\n const x = e.clientX - rect.left;\n const percentage = Math.max(0, Math.min(1, x / rect.width));\n onSeek(percentage);\n }\n };\n\n const progressPercent = duration ? (currentTime / duration) * 100 : 0;\n\n return (\n <div \n ref={containerRef} \n className=\"relative w-full cursor-pointer overflow-hidden\" \n style={{ height: `${height}px` }}\n onClick={handleSeek}\n >\n <canvas ref={canvasRef} className=\"absolute inset-0 w-full h-full\" />\n <div \n className=\"absolute inset-0 h-full overflow-hidden transition-[width] duration-100 ease-linear pointer-events-none\"\n style={{ width: `${progressPercent}%` }}\n >\n <canvas ref={progressCanvasRef} className=\"absolute h-full\" style={{ width: `${containerWidth}px` }} />\n </div>\n </div>\n );\n});\n\nWaveform.displayName = 'Waveform';\n","import React, { memo, useMemo, useRef, useState, useEffect } from 'react';\nimport { WaveframeTheme } from '../types';\nimport { WaveframeEngine } from '../core/WaveframeEngine';\nimport { useWaveframe } from '../hooks/useWaveframe';\nimport { useResampledPeaks } from '../hooks/useResampledPeaks';\nimport { useResizeObserver } from '../hooks/useResizeObserver';\nimport { ArtworkOverlay } from '../molecules/ArtworkOverlay';\nimport { Waveform } from '../organisms/Waveform';\nimport { formatTime } from '../utils';\n\n/**\n * Props for the WaveframePlayer component\n */\nexport interface WaveframePlayerProps {\n /**\n * The audio source to play. Can be a URL string or a Blob/File object.\n */\n media?: string | Blob;\n /**\n * Optional pre-generated peaks for the waveform (0-1 range).\n * If omitted or empty, the player will automatically analyze the media.\n */\n peaks?: number[];\n /**\n * The artwork source to display. Can be a URL string or a Blob/File object.\n */\n artwork?: string | Blob;\n /**\n * The title of the track\n */\n title?: string;\n /**\n * The artist of the track\n */\n artist?: string;\n /**\n * The base color of the waveform bars\n * @default \"#e5e7eb\" (light) or \"#374151\" (dark)\n */\n waveColor?: string;\n /**\n * The color of the played progress part of the waveform\n * @default theme.primary or \"#3b82f6\"\n */\n progressColor?: string;\n /**\n * The height of the waveform in pixels\n * @default 80\n */\n height?: number;\n /**\n * Additional CSS classes for the container\n */\n className?: string;\n /**\n * Inline styles for the container\n */\n style?: React.CSSProperties;\n /**\n * The number of bars to render. Use 'auto' to fit the container width.\n * @default \"auto\"\n */\n resolution?: number | 'auto';\n /**\n * The width of each bar in pixels (if resolution is 'auto')\n * @default 2\n */\n barWidth?: number;\n /**\n * The gap between bars in pixels (if resolution is 'auto')\n * @default 1\n */\n barGap?: number;\n /**\n * Custom theme configuration\n */\n theme?: WaveframeTheme;\n /**\n * Optional WaveframeEngine instance for external control.\n * If provided, the player will sync with this engine instead of creating its own.\n */\n engine?: WaveframeEngine;\n}\n\n/**\n * The standard \"all-in-one\" Waveframe player component.\n * \n * This component features a SoundCloud-inspired layout with a prominent \n * play/pause button positioned next to the track metadata.\n */\nexport const WaveframePlayer: React.FC<WaveframePlayerProps> = memo(({\n media,\n peaks: propPeaks,\n artwork,\n title,\n artist,\n waveColor: propWaveColor,\n progressColor: propProgressColor,\n height = 80,\n className = '',\n style: propStyle,\n resolution = 'auto',\n barWidth = 2,\n barGap = 1,\n theme,\n engine: providedEngine,\n}) => {\n // Use the headless hook for state and controls\n const { state, togglePlay, seek } = useWaveframe(media, {\n peaks: propPeaks,\n engine: providedEngine,\n });\n\n const { isPlaying, currentTime, duration, peaks, isAnalyzing } = state;\n\n // Handle Artwork Blob -> Object URL\n const [resolvedArtworkUrl, setResolvedArtworkUrl] = useState<string | undefined>(\n typeof artwork === 'string' ? artwork : undefined\n );\n\n useEffect(() => {\n if (artwork instanceof Blob) {\n const url = URL.createObjectURL(artwork);\n setResolvedArtworkUrl(url);\n return () => URL.revokeObjectURL(url);\n } else {\n setResolvedArtworkUrl(artwork);\n }\n }, [artwork]);\n\n const containerRef = useRef<HTMLDivElement>(null);\n const containerWidth = useResizeObserver(containerRef);\n\n const targetCount = useMemo(() => {\n if (typeof resolution === 'number') return resolution;\n if (containerWidth > 0) {\n return Math.max(1, Math.floor(containerWidth / (barWidth + barGap)));\n }\n return peaks.length || 1;\n }, [resolution, containerWidth, barWidth, barGap, peaks.length]);\n\n const resampledPeaks = useResampledPeaks(peaks, targetCount);\n\n const waveColor = useMemo(() => {\n if (propWaveColor) return propWaveColor;\n if (theme) return theme.bg === '#ffffff' ? '#e5e7eb' : '#374151';\n return '#e5e7eb';\n }, [propWaveColor, theme]);\n\n const progressColor = propProgressColor || theme?.primary || '#3b82f6';\n\n const mergedStyle = useMemo(() => {\n const baseStyle = {\n '--wf-bg-color': theme?.bg || 'white',\n '--wf-border-color': theme?.border || '#f3f4f6',\n '--wf-title-color': theme?.text || '#111827',\n '--wf-artist-color': theme?.text || '#6b7280',\n '--wf-time-color': theme?.text || '#9ca3af',\n '--wf-play-btn-bg': theme?.primary || '#3b82f6',\n '--wf-placeholder-from': theme?.primary || '#fb923c',\n '--wf-placeholder-to': theme?.bg || '#ec4899',\n };\n return { ...baseStyle, ...propStyle } as React.CSSProperties;\n }, [theme, propStyle]);\n\n return (\n <div\n 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 ${className}`}\n style={mergedStyle}\n >\n <ArtworkOverlay \n artworkUrl={resolvedArtworkUrl} \n title={title} \n isLoading={isAnalyzing}\n />\n\n <div className=\"flex-1 w-full flex flex-col min-w-0\">\n <div className=\"flex items-center gap-4 mb-6\">\n {/* SoundCloud-style circular play button */}\n <button\n onClick={togglePlay}\n 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\"\n >\n {isPlaying ? (\n <svg className=\"w-6 h-6 md:w-7 md:h-7\" fill=\"currentColor\" viewBox=\"0 0 24 24\">\n <path d=\"M6 19h4V5H6v14zm8-14v14h4V5h-4z\" />\n </svg>\n ) : (\n <svg className=\"w-6 h-6 md:w-7 md:h-7 ml-1\" fill=\"currentColor\" viewBox=\"0 0 24 24\">\n <path d=\"M8 5v14l11-7z\" />\n </svg>\n )}\n </button>\n\n <div className=\"flex-1 flex flex-col min-w-0\">\n <div className=\"flex items-center justify-between gap-4\">\n {artist && (\n <p className=\"text-[10px] md:text-xs font-bold uppercase text-[var(--wf-artist-color,#6b7280)] opacity-60 tracking-[0.1em] line-clamp-1\">\n {artist}\n </p>\n )}\n <div className=\"text-[10px] font-mono text-[var(--wf-time-color,#9ca3af)] tabular-nums flex-shrink-0\">\n {formatTime(currentTime)} / {formatTime(duration)}\n </div>\n </div>\n {title && (\n <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\">\n {title}\n </h3>\n )}\n </div>\n </div>\n\n <div className=\"mt-auto\" ref={containerRef}>\n <Waveform \n peaks={resampledPeaks}\n currentTime={currentTime}\n duration={duration}\n waveColor={waveColor}\n progressColor={progressColor}\n height={height}\n onSeek={seek}\n resolution={resolution}\n barWidth={barWidth}\n barGap={barGap}\n />\n </div>\n </div>\n </div>\n );\n});\n\nWaveframePlayer.displayName = 'WaveframePlayer';\n"]}
|