-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
168 lines (160 loc) · 6.04 KB
/
Copy pathtypes.ts
File metadata and controls
168 lines (160 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* @module types
* @description
* Public TypeScript types for `@arraypress/waveform-player-react`.
*
* The shared option surface — `WaveformStyle`, `ColorPreset`,
* `AudioMode`, `AudioPreload`, `ButtonAlign`, `WaveformMarker`,
* `WaveformPeaks`, and the full per-option list behind
* `WaveformPlayerProps` — is now owned by the core library and
* re-exported / extended here rather than re-declared. The core's
* hand-authored `index.d.ts` is the single source of truth, so this
* wrapper can never drift out of sync with it.
*
* This module only adds the React-specific surface:
*
* - Callback props (`onLoad`, `onPlay`, `onPause`, `onTimeUpdate`,
* `onEnd`, `onError`) that map to the library's same-named option
* fields but receive the typed `WaveformPlayer` instance.
* - DOM pass-through (`className`, `style`, `id`).
* - A `WaveformPlayerHandle` exposed via `ref` for imperative
* control (`loadTrack`, `seekTo`, `setVolume`, etc.).
*
* @see {@link https://github.com/arraypress/waveform-player} — core library
*/
import type {
WaveformPlayer,
WaveformPlayerOptions,
} from '@arraypress/waveform-player';
/**
* Shared option types re-exported from the core library so existing
* consumers importing them from this package keep working. These are
* the single-source-of-truth definitions shipped by
* `@arraypress/waveform-player` — not local copies.
*/
export type {
WaveformStyle,
ColorPreset,
AudioMode,
AudioPreload,
ButtonAlign,
WaveformMarker,
WaveformPeaks,
} from '@arraypress/waveform-player';
/**
* Imperative handle exposed through `ref`. Lets consumers drive the
* player directly — useful for "play this track when X happens"
* flows where wiring everything through props is awkward.
*
* Every method is a thin pass-through to the underlying
* `WaveformPlayer` instance; refer to the core library's docs for
* exact behaviour. Most methods return `void`; `play()` returns the
* native `HTMLMediaElement.play()` promise when the player owns the
* audio (`audioMode: 'self'`), `undefined` otherwise.
*/
export interface WaveformPlayerHandle {
/** Start playback. */
play(): Promise<void> | undefined;
/** Pause playback. */
pause(): void;
/** Toggle play / pause. */
togglePlay(): void;
/** Seek to a specific time in seconds. Self-mode only. */
seekTo(seconds: number): void;
/** Seek to a percentage of total duration (0..1). Self-mode only. */
seekToPercent(percent: number): void;
/** Set output volume (0..1). Self-mode only. */
setVolume(volume: number): void;
/** Set playback rate (0.5..2). Self-mode only. */
setPlaybackRate(rate: number): void;
/**
* External-mode only: push the play/pause state into the player so
* the visualisation can reflect what your own audio source is
* doing.
*/
setPlayingState(playing: boolean): void;
/**
* External-mode only: push the current playback position into the
* player so the progress overlay can advance with your own audio
* source.
*/
setProgress(currentTime: number, duration: number): void;
/**
* Load a new track without remounting the component. Resets state,
* fetches the new waveform / audio, then plays.
*/
loadTrack(
url: string,
title?: string,
artist?: string,
options?: Record<string, unknown>
): Promise<void>;
/**
* Underlying `WaveformPlayer` instance. Exposes the full core API
* (static helpers, `options`, `load`, `setWaveformData`, …) for the
* rare cases the handle methods above don't cover.
*/
readonly instance: WaveformPlayer;
}
/**
* Props accepted by `<WaveformPlayer>`.
*
* Extends the core library's `WaveformPlayerOptions` so every library
* option is accepted as a typed prop automatically — including
* `accessibleSeek`, `seekLabel`, `barRadius`, and gradient-array
* colours — and stays in sync as the core evolves. The core's `url`
* and callback options are omitted and re-declared below with the
* React-specific shapes (`url` is required; callbacks receive the
* typed instance).
*
* React-specific extras layered on top: the callback props, plus the
* DOM pass-throughs `id`, `className`, and `style`.
*/
export interface WaveformPlayerProps
extends Omit<
WaveformPlayerOptions,
'url' | 'style' | 'onLoad' | 'onPlay' | 'onPause' | 'onEnd' | 'onError' | 'onTimeUpdate'
> {
// ── Audio source ───────────────────────────────────────────────────
/**
* Audio file URL. Optional only because the core's `src` shorthand is
* an accepted alias — provide one of `url` or `src`.
*/
url?: string;
// ── React-specific callbacks ───────────────────────────────────────
/**
* Called once on mount after the player's `onLoad` fires. Receives
* the live `WaveformPlayer` instance.
*/
onLoad?: (instance: WaveformPlayer) => void;
/** Called when playback starts. */
onPlay?: (instance: WaveformPlayer) => void;
/** Called when playback pauses. */
onPause?: (instance: WaveformPlayer) => void;
/** Called when the track ends. */
onEnd?: (instance: WaveformPlayer) => void;
/**
* Called on each progress frame. Fires with the same
* `(currentTime, duration, instance)` order in both audio modes.
*/
onTimeUpdate?: (currentTime: number, duration: number, instance: WaveformPlayer) => void;
/** Called on audio load / playback error. */
onError?: (error: Error, instance: WaveformPlayer) => void;
// ── React-specific extras ──────────────────────────────────────────
/**
* DOM id forwarded to the container `<div>`. Useful for targeting
* the player from external scripts.
*/
id?: string;
/**
* Extra class names appended to the container. The base class
* `wfp-host` is always applied.
*/
className?: string;
/**
* Inline style passed through to the container. Useful for
* setting `min-height` to reserve layout space before the
* waveform draws.
*/
style?: React.CSSProperties;
}