wavesurf 1.0.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.
@@ -0,0 +1,212 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ /**
5
+ * Represents a song/track that can be played by the audio player.
6
+ */
7
+ interface Song {
8
+ /** Unique identifier for the song */
9
+ id: string;
10
+ /** Display title of the song */
11
+ title: string;
12
+ /** Artist name (optional) */
13
+ artist?: string;
14
+ /** Album name (optional) */
15
+ album?: string;
16
+ /** URL to the audio file */
17
+ audioUrl: string;
18
+ /** Duration in seconds (optional, will be detected if not provided) */
19
+ duration?: number;
20
+ /** Pre-computed waveform peaks for fast visualization (optional) */
21
+ peaks?: number[];
22
+ }
23
+ /**
24
+ * Internal state of the audio player.
25
+ */
26
+ interface AudioPlayerState {
27
+ /** Currently loaded song (null if none) */
28
+ currentSong: Song | null;
29
+ /** Whether audio is currently playing */
30
+ isPlaying: boolean;
31
+ /** Current playback position in seconds */
32
+ currentTime: number;
33
+ /** Total duration in seconds */
34
+ duration: number;
35
+ /** User's target/saved volume (0-1) */
36
+ volume: number;
37
+ /** Actual current volume, follows fade-in animation (0-1) */
38
+ displayVolume: number;
39
+ /** Whether volume is currently fading in */
40
+ isFadingIn: boolean;
41
+ }
42
+ /**
43
+ * Actions available to control the audio player.
44
+ */
45
+ interface AudioPlayerActions {
46
+ /** Play a song (loads and starts playback with fade-in) */
47
+ play: (song: Song) => void;
48
+ /** Pause playback */
49
+ pause: () => void;
50
+ /** Toggle between play and pause */
51
+ togglePlay: () => void;
52
+ /** Seek to a specific time in seconds */
53
+ seek: (time: number) => void;
54
+ /** Set volume (0-1, persisted to localStorage if enabled) */
55
+ setVolume: (volume: number) => void;
56
+ /** Stop playback and clear current song */
57
+ stop: () => void;
58
+ }
59
+ /**
60
+ * Combined context value including state and actions.
61
+ */
62
+ interface AudioPlayerContextValue extends AudioPlayerState, AudioPlayerActions {
63
+ }
64
+ /**
65
+ * Configuration options for the AudioPlayerProvider.
66
+ */
67
+ interface AudioPlayerConfig {
68
+ /** Enable volume fade-in effect on play (default: true) */
69
+ fadeInEnabled?: boolean;
70
+ /** Duration of fade-in effect in milliseconds (default: 3000) */
71
+ fadeInDuration?: number;
72
+ /** Persist volume to localStorage (default: true) */
73
+ persistVolume?: boolean;
74
+ /** localStorage key for volume persistence (default: 'audioPlayerVolume') */
75
+ storageKey?: string;
76
+ /** Default volume level 0-1 (default: 1) */
77
+ defaultVolume?: number;
78
+ /** Callback when a song starts playing */
79
+ onPlay?: (song: Song) => void;
80
+ /** Callback when playback is paused */
81
+ onPause?: () => void;
82
+ /** Callback when a song ends */
83
+ onEnd?: () => void;
84
+ /** Callback when current time changes (called frequently) */
85
+ onTimeUpdate?: (time: number) => void;
86
+ }
87
+ /**
88
+ * Configuration options for waveform visualization.
89
+ */
90
+ interface WaveformConfig {
91
+ /** Color of the waveform (default: '#666666') */
92
+ waveColor?: string;
93
+ /** Color of the played/progress portion (default: '#D4AF37') */
94
+ progressColor?: string;
95
+ /** Color of the cursor/playhead (default: '#D4AF37') */
96
+ cursorColor?: string;
97
+ /** Width of each bar in pixels (default: 2) */
98
+ barWidth?: number;
99
+ /** Gap between bars in pixels (default: 1) */
100
+ barGap?: number;
101
+ /** Border radius of bars in pixels (default: 2) */
102
+ barRadius?: number;
103
+ /** Height of the waveform in pixels (default: 60) */
104
+ height?: number;
105
+ /** Normalize waveform to fill height (default: true) */
106
+ normalize?: boolean;
107
+ }
108
+ /**
109
+ * Props for the WaveformPlayer component.
110
+ */
111
+ interface WaveformPlayerProps {
112
+ /** The song to display/play */
113
+ song: Song;
114
+ /** Waveform styling configuration */
115
+ waveformConfig?: WaveformConfig;
116
+ /** Enable lazy loading via IntersectionObserver (default: true) */
117
+ lazyLoad?: boolean;
118
+ /** Show time display below waveform (default: true) */
119
+ showTime?: boolean;
120
+ /** Additional CSS class name */
121
+ className?: string;
122
+ /** Custom render function for the header area */
123
+ renderHeader?: (song: Song, isPlaying: boolean) => React.ReactNode;
124
+ /** Custom render function for additional controls */
125
+ renderControls?: (song: Song, isPlaying: boolean) => React.ReactNode;
126
+ }
127
+ /**
128
+ * Position of the mini player.
129
+ */
130
+ type MiniPlayerPosition = 'top' | 'bottom';
131
+ /**
132
+ * Props for the MiniPlayer component.
133
+ */
134
+ interface MiniPlayerProps {
135
+ /** Position on screen (default: 'bottom') */
136
+ position?: MiniPlayerPosition;
137
+ /** Show volume control (default: true on desktop, false on mobile) */
138
+ showVolume?: boolean;
139
+ /** Show close button (default: true) */
140
+ showClose?: boolean;
141
+ /** Callback when close button is clicked */
142
+ onClose?: () => void;
143
+ /** Additional CSS class name */
144
+ className?: string;
145
+ /** Waveform styling configuration for the mini waveform */
146
+ waveformConfig?: WaveformConfig;
147
+ }
148
+ /**
149
+ * Return type for the useLazyLoad hook.
150
+ */
151
+ interface UseLazyLoadResult {
152
+ /** Ref to attach to the element to observe */
153
+ ref: React.RefObject<HTMLDivElement>;
154
+ /** Whether the element is visible/intersecting */
155
+ isVisible: boolean;
156
+ }
157
+ /**
158
+ * Options for the useLazyLoad hook.
159
+ */
160
+ interface UseLazyLoadOptions {
161
+ /** Root margin for IntersectionObserver (default: '100px') */
162
+ rootMargin?: string;
163
+ /** Visibility threshold 0-1 (default: 0) */
164
+ threshold?: number;
165
+ /** Start as visible (skip lazy loading) */
166
+ forceVisible?: boolean;
167
+ }
168
+
169
+ declare const MINI_PLAYER_PLAY_EVENT = "wavesurfer-player-mini-play";
170
+ interface AudioPlayerProviderProps {
171
+ children: ReactNode;
172
+ config?: AudioPlayerConfig;
173
+ }
174
+ declare function AudioPlayerProvider({ children, config: userConfig, }: AudioPlayerProviderProps): react_jsx_runtime.JSX.Element;
175
+ declare function useAudioPlayer(): AudioPlayerContextValue;
176
+
177
+ declare function WaveformPlayer({ song, waveformConfig: userWaveformConfig, lazyLoad, showTime, className, renderHeader, renderControls, }: WaveformPlayerProps): react_jsx_runtime.JSX.Element;
178
+
179
+ declare function MiniPlayer({ position, showVolume, showClose, onClose, className, waveformConfig: userWaveformConfig, }: MiniPlayerProps): react_jsx_runtime.JSX.Element | null;
180
+
181
+ /**
182
+ * Hook for lazy loading elements using IntersectionObserver.
183
+ * Returns a ref to attach to the target element and a boolean indicating visibility.
184
+ *
185
+ * @param options - Configuration options for the IntersectionObserver
186
+ * @returns Object containing ref and isVisible state
187
+ *
188
+ * @example
189
+ * const { ref, isVisible } = useLazyLoad();
190
+ *
191
+ * return (
192
+ * <div ref={ref}>
193
+ * {isVisible && <ExpensiveComponent />}
194
+ * </div>
195
+ * );
196
+ */
197
+ declare function useLazyLoad(options?: UseLazyLoadOptions): UseLazyLoadResult;
198
+
199
+ /**
200
+ * Formats seconds into a human-readable time string (M:SS or MM:SS).
201
+ *
202
+ * @param seconds - The number of seconds to format
203
+ * @returns Formatted time string (e.g., "3:45" or "12:05")
204
+ *
205
+ * @example
206
+ * formatTime(125) // "2:05"
207
+ * formatTime(0) // "0:00"
208
+ * formatTime(3600) // "60:00"
209
+ */
210
+ declare function formatTime(seconds: number): string;
211
+
212
+ export { type AudioPlayerActions, type AudioPlayerConfig, type AudioPlayerContextValue, AudioPlayerProvider, type AudioPlayerState, MINI_PLAYER_PLAY_EVENT, MiniPlayer, type MiniPlayerPosition, type MiniPlayerProps, type Song, type UseLazyLoadOptions, type UseLazyLoadResult, type WaveformConfig, WaveformPlayer, type WaveformPlayerProps, formatTime, useAudioPlayer, useLazyLoad };