@arraypress/waveform-player-react 0.1.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/CHANGELOG.md +67 -0
- package/LICENSE +21 -0
- package/README.md +256 -0
- package/dist/index.cjs +202 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +280 -0
- package/dist/index.d.ts +280 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/package.json +86 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @module types
|
|
5
|
+
* @description
|
|
6
|
+
* Public TypeScript types for `@arraypress/waveform-player-react`.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the option surface of `@arraypress/waveform-player` and
|
|
9
|
+
* adds React-specific extras:
|
|
10
|
+
*
|
|
11
|
+
* - Callback props (`onLoad`, `onPlay`, `onPause`, `onTimeUpdate`,
|
|
12
|
+
* `onEnd`, `onError`) that map directly to the library's
|
|
13
|
+
* same-named option fields.
|
|
14
|
+
* - DOM pass-through (`className`, `style`, `id`).
|
|
15
|
+
* - A `WaveformPlayerHandle` exposed via `ref` for imperative
|
|
16
|
+
* control (`loadTrack`, `seekTo`, `setVolume`, etc.).
|
|
17
|
+
*
|
|
18
|
+
* @see {@link https://github.com/arraypress/waveform-player} — core library
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Visual style of the waveform.
|
|
22
|
+
*
|
|
23
|
+
* - `bars` — vertical bars from the baseline up
|
|
24
|
+
* - `mirror` — symmetrical bars mirrored around the centre line
|
|
25
|
+
* - `line` — connected line graph
|
|
26
|
+
* - `blocks` — chunky square blocks
|
|
27
|
+
* - `dots` — dotted plot
|
|
28
|
+
* - `seekbar` — minimal seek bar with no peak detail
|
|
29
|
+
*/
|
|
30
|
+
type WaveformStyle = 'bars' | 'mirror' | 'line' | 'blocks' | 'dots' | 'seekbar';
|
|
31
|
+
/**
|
|
32
|
+
* Forced colour scheme. `null` (the default) auto-detects from the
|
|
33
|
+
* page theme and `prefers-color-scheme`.
|
|
34
|
+
*/
|
|
35
|
+
type ColorPreset = 'dark' | 'light' | null;
|
|
36
|
+
/**
|
|
37
|
+
* How the player handles audio.
|
|
38
|
+
*
|
|
39
|
+
* - `self` — the player owns an `<audio>` element and plays the
|
|
40
|
+
* URL itself. Default.
|
|
41
|
+
* - `external` — the player renders waveform visualisation only and
|
|
42
|
+
* dispatches `waveformplayer:request-play|pause|seek` events for
|
|
43
|
+
* an external controller to handle. Drive the visualisation by
|
|
44
|
+
* calling `setProgress()` and `setPlayingState()` on the instance
|
|
45
|
+
* via the forwarded ref.
|
|
46
|
+
*/
|
|
47
|
+
type AudioMode = 'self' | 'external';
|
|
48
|
+
/** Browser preload hint for the underlying `<audio>` element. */
|
|
49
|
+
type AudioPreload = 'auto' | 'metadata' | 'none';
|
|
50
|
+
/** Vertical alignment of the play button relative to the waveform. */
|
|
51
|
+
type ButtonAlign = 'auto' | 'top' | 'center' | 'bottom';
|
|
52
|
+
/**
|
|
53
|
+
* A clickable chapter marker rendered on top of the waveform.
|
|
54
|
+
*/
|
|
55
|
+
interface WaveformMarker {
|
|
56
|
+
/** Time in seconds at which the marker appears. */
|
|
57
|
+
time: number;
|
|
58
|
+
/** Short label shown as a tooltip. */
|
|
59
|
+
label: string;
|
|
60
|
+
/** Optional override colour (CSS colour string). */
|
|
61
|
+
color?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Pre-computed waveform peaks, OR a string pointer to them.
|
|
65
|
+
*
|
|
66
|
+
* - `number[]` — inline array of peak amplitudes (0..1)
|
|
67
|
+
* - `string` (.json URL) — JSON file URL the library will `fetch()`
|
|
68
|
+
* - `string` (JSON array) — inline JSON string the library will parse
|
|
69
|
+
* - `null` / omitted — the library decodes the audio file with
|
|
70
|
+
* the Web Audio API at load time
|
|
71
|
+
*/
|
|
72
|
+
type WaveformPeaks = number[] | string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Imperative handle exposed through `ref`. Lets consumers drive the
|
|
75
|
+
* player directly — useful for "play this track when X happens"
|
|
76
|
+
* flows where wiring everything through props is awkward.
|
|
77
|
+
*
|
|
78
|
+
* Every method is a thin pass-through to the underlying
|
|
79
|
+
* `WaveformPlayer` instance; refer to the core library's docs for
|
|
80
|
+
* exact behaviour. Most methods return `void`; `play()` returns the
|
|
81
|
+
* native `HTMLMediaElement.play()` promise when the player owns the
|
|
82
|
+
* audio (`audioMode: 'self'`), `undefined` otherwise.
|
|
83
|
+
*/
|
|
84
|
+
interface WaveformPlayerHandle {
|
|
85
|
+
/** Start playback. */
|
|
86
|
+
play(): Promise<void> | undefined;
|
|
87
|
+
/** Pause playback. */
|
|
88
|
+
pause(): void;
|
|
89
|
+
/** Toggle play / pause. */
|
|
90
|
+
togglePlay(): void;
|
|
91
|
+
/** Seek to a specific time in seconds. Self-mode only. */
|
|
92
|
+
seekTo(seconds: number): void;
|
|
93
|
+
/** Seek to a percentage of total duration (0..1). Self-mode only. */
|
|
94
|
+
seekToPercent(percent: number): void;
|
|
95
|
+
/** Set output volume (0..1). Self-mode only. */
|
|
96
|
+
setVolume(volume: number): void;
|
|
97
|
+
/** Set playback rate (0.5..2). Self-mode only. */
|
|
98
|
+
setPlaybackRate(rate: number): void;
|
|
99
|
+
/**
|
|
100
|
+
* External-mode only: push the play/pause state into the player so
|
|
101
|
+
* the visualisation can reflect what your own audio source is
|
|
102
|
+
* doing.
|
|
103
|
+
*/
|
|
104
|
+
setPlayingState(playing: boolean): void;
|
|
105
|
+
/**
|
|
106
|
+
* External-mode only: push the current playback position into the
|
|
107
|
+
* player so the progress overlay can advance with your own audio
|
|
108
|
+
* source.
|
|
109
|
+
*/
|
|
110
|
+
setProgress(currentTime: number, duration: number): void;
|
|
111
|
+
/**
|
|
112
|
+
* Load a new track without remounting the component. Resets state,
|
|
113
|
+
* fetches the new waveform / audio, then plays.
|
|
114
|
+
*/
|
|
115
|
+
loadTrack(url: string, title?: string, subtitle?: string, options?: Record<string, unknown>): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Underlying instance. Cast in your code if you need access to
|
|
118
|
+
* features not exposed by this handle (the core library has no
|
|
119
|
+
* shipped TypeScript types yet).
|
|
120
|
+
*/
|
|
121
|
+
readonly instance: unknown;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Props accepted by `<WaveformPlayer>`.
|
|
125
|
+
*
|
|
126
|
+
* Grouped to mirror the README sections:
|
|
127
|
+
* 1. Audio source
|
|
128
|
+
* 2. Waveform visualisation
|
|
129
|
+
* 3. Colours
|
|
130
|
+
* 4. Playback controls
|
|
131
|
+
* 5. UI toggles
|
|
132
|
+
* 6. Markers
|
|
133
|
+
* 7. Content metadata
|
|
134
|
+
* 8. Behaviour flags
|
|
135
|
+
* 9. Icons
|
|
136
|
+
* 10. React-specific extras (callbacks, className, style, id)
|
|
137
|
+
*/
|
|
138
|
+
interface WaveformPlayerProps {
|
|
139
|
+
/** Audio file URL. Required. */
|
|
140
|
+
url: string;
|
|
141
|
+
/**
|
|
142
|
+
* Whether the player owns its `<audio>` element (`self`) or only
|
|
143
|
+
* renders visualisation and emits request events (`external`).
|
|
144
|
+
*
|
|
145
|
+
* Changing this prop **re-mounts** the player instance — it's
|
|
146
|
+
* part of the "identity" dep array.
|
|
147
|
+
*
|
|
148
|
+
* @default 'self'
|
|
149
|
+
*/
|
|
150
|
+
audioMode?: AudioMode;
|
|
151
|
+
/** Browser preload hint. @default 'metadata' */
|
|
152
|
+
preload?: AudioPreload;
|
|
153
|
+
/** Visual style. @default 'mirror' */
|
|
154
|
+
waveformStyle?: WaveformStyle;
|
|
155
|
+
/** Canvas height in pixels. @default 60 */
|
|
156
|
+
height?: number;
|
|
157
|
+
/** Number of peak samples. @default 200 */
|
|
158
|
+
samples?: number;
|
|
159
|
+
/** Bar/block width in pixels. */
|
|
160
|
+
barWidth?: number;
|
|
161
|
+
/** Gap between bars in pixels. */
|
|
162
|
+
barSpacing?: number;
|
|
163
|
+
/** Pre-computed peaks data. See {@link WaveformPeaks}. */
|
|
164
|
+
waveform?: WaveformPeaks;
|
|
165
|
+
/** Forced colour preset; `null` auto-detects. @default null */
|
|
166
|
+
colorPreset?: ColorPreset;
|
|
167
|
+
/** Unplayed peak colour (CSS colour string). */
|
|
168
|
+
waveformColor?: string;
|
|
169
|
+
/** Progress/played-through colour. */
|
|
170
|
+
progressColor?: string;
|
|
171
|
+
/** Play button border/text colour. */
|
|
172
|
+
buttonColor?: string;
|
|
173
|
+
/** Play button hover colour. */
|
|
174
|
+
buttonHoverColor?: string;
|
|
175
|
+
/** Primary text (title) colour. */
|
|
176
|
+
textColor?: string;
|
|
177
|
+
/** Secondary text (subtitle, time) colour. */
|
|
178
|
+
textSecondaryColor?: string;
|
|
179
|
+
/** Reserved. */
|
|
180
|
+
backgroundColor?: string;
|
|
181
|
+
/** Reserved. */
|
|
182
|
+
borderColor?: string;
|
|
183
|
+
/** Initial playback rate (0.5..2). @default 1 */
|
|
184
|
+
playbackRate?: number;
|
|
185
|
+
/** Show the playback-speed control menu. @default false */
|
|
186
|
+
showPlaybackSpeed?: boolean;
|
|
187
|
+
/** Speeds offered in the menu. */
|
|
188
|
+
playbackRates?: number[];
|
|
189
|
+
/** Show play/pause button. @default true */
|
|
190
|
+
showControls?: boolean;
|
|
191
|
+
/** Show info bar (title, subtitle, time, BPM, speed). @default true */
|
|
192
|
+
showInfo?: boolean;
|
|
193
|
+
/** Show current/total time. @default true */
|
|
194
|
+
showTime?: boolean;
|
|
195
|
+
/** Show hover-time indicator. Reserved. @default false */
|
|
196
|
+
showHoverTime?: boolean;
|
|
197
|
+
/** Detect and display BPM. @default false */
|
|
198
|
+
showBPM?: boolean;
|
|
199
|
+
/** Vertical alignment of play button. @default 'auto' */
|
|
200
|
+
buttonAlign?: ButtonAlign;
|
|
201
|
+
/** Chapter markers. */
|
|
202
|
+
markers?: WaveformMarker[];
|
|
203
|
+
/** Whether to render markers. @default true */
|
|
204
|
+
showMarkers?: boolean;
|
|
205
|
+
/** Track title (defaults to prettified filename). */
|
|
206
|
+
title?: string;
|
|
207
|
+
/** Subtitle / artist. */
|
|
208
|
+
subtitle?: string;
|
|
209
|
+
/** Cover image URL. */
|
|
210
|
+
artwork?: string;
|
|
211
|
+
/** Album name (Media Session API). */
|
|
212
|
+
album?: string;
|
|
213
|
+
/** Start as soon as metadata loads. @default false */
|
|
214
|
+
autoplay?: boolean;
|
|
215
|
+
/** Pause other players on the page when this one starts. @default true */
|
|
216
|
+
singlePlay?: boolean;
|
|
217
|
+
/** Resume on seek if paused. @default true */
|
|
218
|
+
playOnSeek?: boolean;
|
|
219
|
+
/** Wire up the browser's Media Session API. @default true */
|
|
220
|
+
enableMediaSession?: boolean;
|
|
221
|
+
/** Inline HTML/SVG for the play button. */
|
|
222
|
+
playIcon?: string;
|
|
223
|
+
/** Inline HTML/SVG for the pause button. */
|
|
224
|
+
pauseIcon?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Called once on mount after the player's `onLoad` fires. Signature
|
|
227
|
+
* mirrors the underlying library callback — receives the instance.
|
|
228
|
+
*/
|
|
229
|
+
onLoad?: (instance: unknown) => void;
|
|
230
|
+
/** Called when playback starts. */
|
|
231
|
+
onPlay?: (instance: unknown) => void;
|
|
232
|
+
/** Called when playback pauses. */
|
|
233
|
+
onPause?: (instance: unknown) => void;
|
|
234
|
+
/** Called when the track ends. */
|
|
235
|
+
onEnd?: (instance: unknown) => void;
|
|
236
|
+
/**
|
|
237
|
+
* Called on each progress frame in self-mode (signature varies in
|
|
238
|
+
* external-mode — see the core library docs).
|
|
239
|
+
*/
|
|
240
|
+
onTimeUpdate?: (currentTime: number, duration: number, instance: unknown) => void;
|
|
241
|
+
/** Called on audio load / playback error. */
|
|
242
|
+
onError?: (error: Error, instance: unknown) => void;
|
|
243
|
+
/**
|
|
244
|
+
* DOM id forwarded to the container `<div>`. Useful for targeting
|
|
245
|
+
* the player from external scripts.
|
|
246
|
+
*/
|
|
247
|
+
id?: string;
|
|
248
|
+
/**
|
|
249
|
+
* Extra class names appended to the container. The base class
|
|
250
|
+
* `wfp-host` is always applied.
|
|
251
|
+
*/
|
|
252
|
+
className?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Inline style passed through to the container. Useful for
|
|
255
|
+
* setting `min-height` to reserve layout space before the
|
|
256
|
+
* waveform draws.
|
|
257
|
+
*/
|
|
258
|
+
style?: React.CSSProperties;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* `WaveformPlayer` — React component wrapping
|
|
263
|
+
* `@arraypress/waveform-player`.
|
|
264
|
+
*
|
|
265
|
+
* Render at the spot you want a waveform-driven audio player to
|
|
266
|
+
* appear. The container `<div>` is rendered immediately for layout;
|
|
267
|
+
* the actual player UI hydrates in once the library loads
|
|
268
|
+
* client-side.
|
|
269
|
+
*
|
|
270
|
+
* @example Basic
|
|
271
|
+
* <WaveformPlayer url="/audio/track.mp3" title="My Track" />
|
|
272
|
+
*
|
|
273
|
+
* @example With ref for imperative control
|
|
274
|
+
* const ref = useRef<WaveformPlayerHandle>(null);
|
|
275
|
+
* <WaveformPlayer ref={ref} url={url} />
|
|
276
|
+
* <button onClick={() => ref.current?.togglePlay()}>Play/Pause</button>
|
|
277
|
+
*/
|
|
278
|
+
declare const WaveformPlayer: react.ForwardRefExoticComponent<WaveformPlayerProps & react.RefAttributes<WaveformPlayerHandle>>;
|
|
279
|
+
|
|
280
|
+
export { type AudioMode, type AudioPreload, type ButtonAlign, type ColorPreset, type WaveformMarker, type WaveformPeaks, WaveformPlayer, type WaveformPlayerHandle, type WaveformPlayerProps, type WaveformStyle, WaveformPlayer as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @module types
|
|
5
|
+
* @description
|
|
6
|
+
* Public TypeScript types for `@arraypress/waveform-player-react`.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the option surface of `@arraypress/waveform-player` and
|
|
9
|
+
* adds React-specific extras:
|
|
10
|
+
*
|
|
11
|
+
* - Callback props (`onLoad`, `onPlay`, `onPause`, `onTimeUpdate`,
|
|
12
|
+
* `onEnd`, `onError`) that map directly to the library's
|
|
13
|
+
* same-named option fields.
|
|
14
|
+
* - DOM pass-through (`className`, `style`, `id`).
|
|
15
|
+
* - A `WaveformPlayerHandle` exposed via `ref` for imperative
|
|
16
|
+
* control (`loadTrack`, `seekTo`, `setVolume`, etc.).
|
|
17
|
+
*
|
|
18
|
+
* @see {@link https://github.com/arraypress/waveform-player} — core library
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Visual style of the waveform.
|
|
22
|
+
*
|
|
23
|
+
* - `bars` — vertical bars from the baseline up
|
|
24
|
+
* - `mirror` — symmetrical bars mirrored around the centre line
|
|
25
|
+
* - `line` — connected line graph
|
|
26
|
+
* - `blocks` — chunky square blocks
|
|
27
|
+
* - `dots` — dotted plot
|
|
28
|
+
* - `seekbar` — minimal seek bar with no peak detail
|
|
29
|
+
*/
|
|
30
|
+
type WaveformStyle = 'bars' | 'mirror' | 'line' | 'blocks' | 'dots' | 'seekbar';
|
|
31
|
+
/**
|
|
32
|
+
* Forced colour scheme. `null` (the default) auto-detects from the
|
|
33
|
+
* page theme and `prefers-color-scheme`.
|
|
34
|
+
*/
|
|
35
|
+
type ColorPreset = 'dark' | 'light' | null;
|
|
36
|
+
/**
|
|
37
|
+
* How the player handles audio.
|
|
38
|
+
*
|
|
39
|
+
* - `self` — the player owns an `<audio>` element and plays the
|
|
40
|
+
* URL itself. Default.
|
|
41
|
+
* - `external` — the player renders waveform visualisation only and
|
|
42
|
+
* dispatches `waveformplayer:request-play|pause|seek` events for
|
|
43
|
+
* an external controller to handle. Drive the visualisation by
|
|
44
|
+
* calling `setProgress()` and `setPlayingState()` on the instance
|
|
45
|
+
* via the forwarded ref.
|
|
46
|
+
*/
|
|
47
|
+
type AudioMode = 'self' | 'external';
|
|
48
|
+
/** Browser preload hint for the underlying `<audio>` element. */
|
|
49
|
+
type AudioPreload = 'auto' | 'metadata' | 'none';
|
|
50
|
+
/** Vertical alignment of the play button relative to the waveform. */
|
|
51
|
+
type ButtonAlign = 'auto' | 'top' | 'center' | 'bottom';
|
|
52
|
+
/**
|
|
53
|
+
* A clickable chapter marker rendered on top of the waveform.
|
|
54
|
+
*/
|
|
55
|
+
interface WaveformMarker {
|
|
56
|
+
/** Time in seconds at which the marker appears. */
|
|
57
|
+
time: number;
|
|
58
|
+
/** Short label shown as a tooltip. */
|
|
59
|
+
label: string;
|
|
60
|
+
/** Optional override colour (CSS colour string). */
|
|
61
|
+
color?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Pre-computed waveform peaks, OR a string pointer to them.
|
|
65
|
+
*
|
|
66
|
+
* - `number[]` — inline array of peak amplitudes (0..1)
|
|
67
|
+
* - `string` (.json URL) — JSON file URL the library will `fetch()`
|
|
68
|
+
* - `string` (JSON array) — inline JSON string the library will parse
|
|
69
|
+
* - `null` / omitted — the library decodes the audio file with
|
|
70
|
+
* the Web Audio API at load time
|
|
71
|
+
*/
|
|
72
|
+
type WaveformPeaks = number[] | string | null;
|
|
73
|
+
/**
|
|
74
|
+
* Imperative handle exposed through `ref`. Lets consumers drive the
|
|
75
|
+
* player directly — useful for "play this track when X happens"
|
|
76
|
+
* flows where wiring everything through props is awkward.
|
|
77
|
+
*
|
|
78
|
+
* Every method is a thin pass-through to the underlying
|
|
79
|
+
* `WaveformPlayer` instance; refer to the core library's docs for
|
|
80
|
+
* exact behaviour. Most methods return `void`; `play()` returns the
|
|
81
|
+
* native `HTMLMediaElement.play()` promise when the player owns the
|
|
82
|
+
* audio (`audioMode: 'self'`), `undefined` otherwise.
|
|
83
|
+
*/
|
|
84
|
+
interface WaveformPlayerHandle {
|
|
85
|
+
/** Start playback. */
|
|
86
|
+
play(): Promise<void> | undefined;
|
|
87
|
+
/** Pause playback. */
|
|
88
|
+
pause(): void;
|
|
89
|
+
/** Toggle play / pause. */
|
|
90
|
+
togglePlay(): void;
|
|
91
|
+
/** Seek to a specific time in seconds. Self-mode only. */
|
|
92
|
+
seekTo(seconds: number): void;
|
|
93
|
+
/** Seek to a percentage of total duration (0..1). Self-mode only. */
|
|
94
|
+
seekToPercent(percent: number): void;
|
|
95
|
+
/** Set output volume (0..1). Self-mode only. */
|
|
96
|
+
setVolume(volume: number): void;
|
|
97
|
+
/** Set playback rate (0.5..2). Self-mode only. */
|
|
98
|
+
setPlaybackRate(rate: number): void;
|
|
99
|
+
/**
|
|
100
|
+
* External-mode only: push the play/pause state into the player so
|
|
101
|
+
* the visualisation can reflect what your own audio source is
|
|
102
|
+
* doing.
|
|
103
|
+
*/
|
|
104
|
+
setPlayingState(playing: boolean): void;
|
|
105
|
+
/**
|
|
106
|
+
* External-mode only: push the current playback position into the
|
|
107
|
+
* player so the progress overlay can advance with your own audio
|
|
108
|
+
* source.
|
|
109
|
+
*/
|
|
110
|
+
setProgress(currentTime: number, duration: number): void;
|
|
111
|
+
/**
|
|
112
|
+
* Load a new track without remounting the component. Resets state,
|
|
113
|
+
* fetches the new waveform / audio, then plays.
|
|
114
|
+
*/
|
|
115
|
+
loadTrack(url: string, title?: string, subtitle?: string, options?: Record<string, unknown>): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Underlying instance. Cast in your code if you need access to
|
|
118
|
+
* features not exposed by this handle (the core library has no
|
|
119
|
+
* shipped TypeScript types yet).
|
|
120
|
+
*/
|
|
121
|
+
readonly instance: unknown;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Props accepted by `<WaveformPlayer>`.
|
|
125
|
+
*
|
|
126
|
+
* Grouped to mirror the README sections:
|
|
127
|
+
* 1. Audio source
|
|
128
|
+
* 2. Waveform visualisation
|
|
129
|
+
* 3. Colours
|
|
130
|
+
* 4. Playback controls
|
|
131
|
+
* 5. UI toggles
|
|
132
|
+
* 6. Markers
|
|
133
|
+
* 7. Content metadata
|
|
134
|
+
* 8. Behaviour flags
|
|
135
|
+
* 9. Icons
|
|
136
|
+
* 10. React-specific extras (callbacks, className, style, id)
|
|
137
|
+
*/
|
|
138
|
+
interface WaveformPlayerProps {
|
|
139
|
+
/** Audio file URL. Required. */
|
|
140
|
+
url: string;
|
|
141
|
+
/**
|
|
142
|
+
* Whether the player owns its `<audio>` element (`self`) or only
|
|
143
|
+
* renders visualisation and emits request events (`external`).
|
|
144
|
+
*
|
|
145
|
+
* Changing this prop **re-mounts** the player instance — it's
|
|
146
|
+
* part of the "identity" dep array.
|
|
147
|
+
*
|
|
148
|
+
* @default 'self'
|
|
149
|
+
*/
|
|
150
|
+
audioMode?: AudioMode;
|
|
151
|
+
/** Browser preload hint. @default 'metadata' */
|
|
152
|
+
preload?: AudioPreload;
|
|
153
|
+
/** Visual style. @default 'mirror' */
|
|
154
|
+
waveformStyle?: WaveformStyle;
|
|
155
|
+
/** Canvas height in pixels. @default 60 */
|
|
156
|
+
height?: number;
|
|
157
|
+
/** Number of peak samples. @default 200 */
|
|
158
|
+
samples?: number;
|
|
159
|
+
/** Bar/block width in pixels. */
|
|
160
|
+
barWidth?: number;
|
|
161
|
+
/** Gap between bars in pixels. */
|
|
162
|
+
barSpacing?: number;
|
|
163
|
+
/** Pre-computed peaks data. See {@link WaveformPeaks}. */
|
|
164
|
+
waveform?: WaveformPeaks;
|
|
165
|
+
/** Forced colour preset; `null` auto-detects. @default null */
|
|
166
|
+
colorPreset?: ColorPreset;
|
|
167
|
+
/** Unplayed peak colour (CSS colour string). */
|
|
168
|
+
waveformColor?: string;
|
|
169
|
+
/** Progress/played-through colour. */
|
|
170
|
+
progressColor?: string;
|
|
171
|
+
/** Play button border/text colour. */
|
|
172
|
+
buttonColor?: string;
|
|
173
|
+
/** Play button hover colour. */
|
|
174
|
+
buttonHoverColor?: string;
|
|
175
|
+
/** Primary text (title) colour. */
|
|
176
|
+
textColor?: string;
|
|
177
|
+
/** Secondary text (subtitle, time) colour. */
|
|
178
|
+
textSecondaryColor?: string;
|
|
179
|
+
/** Reserved. */
|
|
180
|
+
backgroundColor?: string;
|
|
181
|
+
/** Reserved. */
|
|
182
|
+
borderColor?: string;
|
|
183
|
+
/** Initial playback rate (0.5..2). @default 1 */
|
|
184
|
+
playbackRate?: number;
|
|
185
|
+
/** Show the playback-speed control menu. @default false */
|
|
186
|
+
showPlaybackSpeed?: boolean;
|
|
187
|
+
/** Speeds offered in the menu. */
|
|
188
|
+
playbackRates?: number[];
|
|
189
|
+
/** Show play/pause button. @default true */
|
|
190
|
+
showControls?: boolean;
|
|
191
|
+
/** Show info bar (title, subtitle, time, BPM, speed). @default true */
|
|
192
|
+
showInfo?: boolean;
|
|
193
|
+
/** Show current/total time. @default true */
|
|
194
|
+
showTime?: boolean;
|
|
195
|
+
/** Show hover-time indicator. Reserved. @default false */
|
|
196
|
+
showHoverTime?: boolean;
|
|
197
|
+
/** Detect and display BPM. @default false */
|
|
198
|
+
showBPM?: boolean;
|
|
199
|
+
/** Vertical alignment of play button. @default 'auto' */
|
|
200
|
+
buttonAlign?: ButtonAlign;
|
|
201
|
+
/** Chapter markers. */
|
|
202
|
+
markers?: WaveformMarker[];
|
|
203
|
+
/** Whether to render markers. @default true */
|
|
204
|
+
showMarkers?: boolean;
|
|
205
|
+
/** Track title (defaults to prettified filename). */
|
|
206
|
+
title?: string;
|
|
207
|
+
/** Subtitle / artist. */
|
|
208
|
+
subtitle?: string;
|
|
209
|
+
/** Cover image URL. */
|
|
210
|
+
artwork?: string;
|
|
211
|
+
/** Album name (Media Session API). */
|
|
212
|
+
album?: string;
|
|
213
|
+
/** Start as soon as metadata loads. @default false */
|
|
214
|
+
autoplay?: boolean;
|
|
215
|
+
/** Pause other players on the page when this one starts. @default true */
|
|
216
|
+
singlePlay?: boolean;
|
|
217
|
+
/** Resume on seek if paused. @default true */
|
|
218
|
+
playOnSeek?: boolean;
|
|
219
|
+
/** Wire up the browser's Media Session API. @default true */
|
|
220
|
+
enableMediaSession?: boolean;
|
|
221
|
+
/** Inline HTML/SVG for the play button. */
|
|
222
|
+
playIcon?: string;
|
|
223
|
+
/** Inline HTML/SVG for the pause button. */
|
|
224
|
+
pauseIcon?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Called once on mount after the player's `onLoad` fires. Signature
|
|
227
|
+
* mirrors the underlying library callback — receives the instance.
|
|
228
|
+
*/
|
|
229
|
+
onLoad?: (instance: unknown) => void;
|
|
230
|
+
/** Called when playback starts. */
|
|
231
|
+
onPlay?: (instance: unknown) => void;
|
|
232
|
+
/** Called when playback pauses. */
|
|
233
|
+
onPause?: (instance: unknown) => void;
|
|
234
|
+
/** Called when the track ends. */
|
|
235
|
+
onEnd?: (instance: unknown) => void;
|
|
236
|
+
/**
|
|
237
|
+
* Called on each progress frame in self-mode (signature varies in
|
|
238
|
+
* external-mode — see the core library docs).
|
|
239
|
+
*/
|
|
240
|
+
onTimeUpdate?: (currentTime: number, duration: number, instance: unknown) => void;
|
|
241
|
+
/** Called on audio load / playback error. */
|
|
242
|
+
onError?: (error: Error, instance: unknown) => void;
|
|
243
|
+
/**
|
|
244
|
+
* DOM id forwarded to the container `<div>`. Useful for targeting
|
|
245
|
+
* the player from external scripts.
|
|
246
|
+
*/
|
|
247
|
+
id?: string;
|
|
248
|
+
/**
|
|
249
|
+
* Extra class names appended to the container. The base class
|
|
250
|
+
* `wfp-host` is always applied.
|
|
251
|
+
*/
|
|
252
|
+
className?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Inline style passed through to the container. Useful for
|
|
255
|
+
* setting `min-height` to reserve layout space before the
|
|
256
|
+
* waveform draws.
|
|
257
|
+
*/
|
|
258
|
+
style?: React.CSSProperties;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* `WaveformPlayer` — React component wrapping
|
|
263
|
+
* `@arraypress/waveform-player`.
|
|
264
|
+
*
|
|
265
|
+
* Render at the spot you want a waveform-driven audio player to
|
|
266
|
+
* appear. The container `<div>` is rendered immediately for layout;
|
|
267
|
+
* the actual player UI hydrates in once the library loads
|
|
268
|
+
* client-side.
|
|
269
|
+
*
|
|
270
|
+
* @example Basic
|
|
271
|
+
* <WaveformPlayer url="/audio/track.mp3" title="My Track" />
|
|
272
|
+
*
|
|
273
|
+
* @example With ref for imperative control
|
|
274
|
+
* const ref = useRef<WaveformPlayerHandle>(null);
|
|
275
|
+
* <WaveformPlayer ref={ref} url={url} />
|
|
276
|
+
* <button onClick={() => ref.current?.togglePlay()}>Play/Pause</button>
|
|
277
|
+
*/
|
|
278
|
+
declare const WaveformPlayer: react.ForwardRefExoticComponent<WaveformPlayerProps & react.RefAttributes<WaveformPlayerHandle>>;
|
|
279
|
+
|
|
280
|
+
export { type AudioMode, type AudioPreload, type ButtonAlign, type ColorPreset, type WaveformMarker, type WaveformPeaks, WaveformPlayer, type WaveformPlayerHandle, type WaveformPlayerProps, type WaveformStyle, WaveformPlayer as default };
|