react-audio-wavekit 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.
Files changed (32) hide show
  1. package/LICENSE +116 -0
  2. package/README.md +231 -0
  3. package/dist/constants.cjs +20 -0
  4. package/dist/constants.js +20 -0
  5. package/dist/index.cjs +12 -0
  6. package/dist/index.d.ts +235 -0
  7. package/dist/index.js +12 -0
  8. package/dist/recorder/live-recorder/index.cjs +125 -0
  9. package/dist/recorder/live-recorder/index.js +125 -0
  10. package/dist/recorder/live-streaming/recorder/recorder-compound.cjs +244 -0
  11. package/dist/recorder/live-streaming/recorder/recorder-compound.js +244 -0
  12. package/dist/recorder/live-streaming/recorder/recorder-context.cjs +20 -0
  13. package/dist/recorder/live-streaming/recorder/recorder-context.js +20 -0
  14. package/dist/recorder/live-streaming/stack-recorder/stack-recorder-compound.cjs +126 -0
  15. package/dist/recorder/live-streaming/stack-recorder/stack-recorder-compound.js +126 -0
  16. package/dist/recorder/live-streaming/use-recording-amplitudes.cjs +92 -0
  17. package/dist/recorder/live-streaming/use-recording-amplitudes.js +92 -0
  18. package/dist/recorder/use-audio-analyser.cjs +59 -0
  19. package/dist/recorder/use-audio-analyser.js +59 -0
  20. package/dist/recorder/use-audio-recorder.cjs +139 -0
  21. package/dist/recorder/use-audio-recorder.js +139 -0
  22. package/dist/recorder/util-mime-type.cjs +15 -0
  23. package/dist/recorder/util-mime-type.js +15 -0
  24. package/dist/waveform/index.cjs +73 -0
  25. package/dist/waveform/index.js +73 -0
  26. package/dist/waveform/util-audio-decoder.cjs +45 -0
  27. package/dist/waveform/util-audio-decoder.js +45 -0
  28. package/dist/waveform/util-suspense.cjs +24 -0
  29. package/dist/waveform/util-suspense.js +24 -0
  30. package/dist/waveform/waveform-renderer.cjs +105 -0
  31. package/dist/waveform/waveform-renderer.js +105 -0
  32. package/package.json +74 -0
package/LICENSE ADDED
@@ -0,0 +1,116 @@
1
+ CC0 1.0 Universal
2
+
3
+ Statement of Purpose
4
+
5
+ The laws of most jurisdictions throughout the world automatically confer
6
+ exclusive Copyright and Related Rights (defined below) upon the creator and
7
+ subsequent owner(s) (each and all, an "owner") of an original work of
8
+ authorship and/or a database (each, a "Work").
9
+
10
+ Certain owners wish to permanently relinquish those rights to a Work for the
11
+ purpose of contributing to a commons of creative, cultural and scientific
12
+ works ("Commons") that the public can reliably and without fear of later
13
+ claims of infringement build upon, modify, incorporate in other works, reuse
14
+ and redistribute as freely as possible in any form whatsoever and for any
15
+ purposes, including without limitation commercial purposes. These owners may
16
+ contribute to the Commons to promote the ideal of a free culture and the
17
+ further production of creative and scientific works, or to gain reputation or
18
+ greater distribution for their Work in part through the use and efforts of
19
+ others.
20
+
21
+ For these and/or other purposes and motivations, and without any expectation
22
+ of additional consideration or compensation, the person associating CC0 with a
23
+ Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24
+ and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25
+ and publicly distribute the Work under its terms, with knowledge of his or her
26
+ Copyright and Related Rights in the Work and the meaning and intended legal
27
+ effect of CC0 on those rights.
28
+
29
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
30
+ protected by copyright and related or neighboring rights ("Copyright and
31
+ Related Rights"). Copyright and Related Rights include, but are not limited
32
+ to, the following:
33
+
34
+ i. the right to reproduce, adapt, distribute, perform, display, communicate,
35
+ and translate a Work;
36
+
37
+ ii. moral rights retained by the original author(s) and/or performer(s);
38
+
39
+ iii. publicity and privacy rights pertaining to a person's image or likeness
40
+ depicted in a Work;
41
+
42
+ iv. rights protecting against unfair competition in regards to a Work,
43
+ subject to the limitations in paragraph 4(a), below;
44
+
45
+ v. rights protecting the extraction, dissemination, use and reuse of data in
46
+ a Work;
47
+
48
+ vi. database rights (such as those arising under Directive 96/9/EC of the
49
+ European Parliament and of the Council of 11 March 1996 on the legal
50
+ protection of databases, and under any national implementation thereof,
51
+ including any amended or successor version of such directive); and
52
+
53
+ vii. other similar, equivalent or corresponding rights throughout the world
54
+ based on applicable law or treaty, and any national implementations thereof.
55
+
56
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57
+ applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58
+ unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59
+ and Related Rights and associated claims and causes of action, whether now
60
+ known or unknown (including existing as well as future claims and causes of
61
+ action), in the Work (i) in all territories worldwide, (ii) for the maximum
62
+ duration provided by applicable law or treaty (including future time
63
+ extensions), (iii) in any current or future medium and for any number of
64
+ copies, and (iv) for any purpose whatsoever, including without limitation
65
+ commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66
+ the Waiver for the benefit of each member of the public at large and to the
67
+ detriment of Affirmer's heirs and successors, fully intending that such Waiver
68
+ shall not be subject to revocation, rescission, cancellation, termination, or
69
+ any other legal or equitable action to disrupt the quiet enjoyment of the Work
70
+ by the public as contemplated by Affirmer's express Statement of Purpose.
71
+
72
+ 3. Public License Fallback. Should any part of the Waiver for any reason be
73
+ judged legally invalid or ineffective under applicable law, then the Waiver
74
+ shall be preserved to the maximum extent permitted taking into account
75
+ Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76
+ is so judged Affirmer hereby grants to each affected person a royalty-free,
77
+ non transferable, non sublicensable, non exclusive, irrevocable and
78
+ unconditional license to exercise Affirmer's Copyright and Related Rights in
79
+ the Work (i) in all territories worldwide, (ii) for the maximum duration
80
+ provided by applicable law or treaty (including future time extensions), (iii)
81
+ in any current or future medium and for any number of copies, and (iv) for any
82
+ purpose whatsoever, including without limitation commercial, advertising or
83
+ promotional purposes (the "License"). The License shall be deemed effective as
84
+ of the date CC0 was applied by Affirmer to the Work. Should any part of the
85
+ License for any reason be judged legally invalid or ineffective under
86
+ applicable law, such partial invalidity or ineffectiveness shall not
87
+ invalidate the remainder of the License, and in such case Affirmer hereby
88
+ affirms that he or she will not (i) exercise any of his or her remaining
89
+ Copyright and Related Rights in the Work or (ii) assert any associated claims
90
+ and causes of action with respect to the Work, in either case contrary to
91
+ Affirmer's express Statement of Purpose.
92
+
93
+ 4. Limitations and Disclaimers.
94
+
95
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
96
+ surrendered, licensed or otherwise affected by this document.
97
+
98
+ b. Affirmer offers the Work as-is and makes no representations or warranties
99
+ of any kind concerning the Work, express, implied, statutory or otherwise,
100
+ including without limitation warranties of title, merchantability, fitness
101
+ for a particular purpose, non infringement, or the absence of latent or
102
+ other defects, accuracy, or the present or absence of errors, whether or not
103
+ discoverable, all to the greatest extent permissible under applicable law.
104
+
105
+ c. Affirmer disclaims responsibility for clearing rights of other persons
106
+ that may apply to the Work or any use thereof, including without limitation
107
+ any person's Copyright and Related Rights in the Work. Further, Affirmer
108
+ disclaims responsibility for obtaining any necessary consents, permissions
109
+ or other rights required for any use of the Work.
110
+
111
+ d. Affirmer understands and acknowledges that Creative Commons is not a
112
+ party to this document and has no duty or obligation with respect to this
113
+ CC0 or use of the Work.
114
+
115
+ For more information, please see
116
+ <http://creativecommons.org/publicdomain/zero/1.0/>
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # react-audio-wavekit
2
+
3
+ React components for audio waveform visualization and live recording.
4
+
5
+ ## Features
6
+
7
+ - **Full TypeScript** - Complete type safety with detailed type definitions
8
+ - **Easy to Use** - Simple API with sensible defaults, works out of the box
9
+ - **Headless Hooks** - Full control with raw audio data for custom implementations
10
+ - **SSR Safe** - Compatible with Next.js and other SSR frameworks
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install react-audio-wavekit
16
+ # or
17
+ pnpm add react-audio-wavekit
18
+ # or
19
+ bun add react-audio-wavekit
20
+ ```
21
+
22
+ **Requirements:** React 18+, Web Audio API, MediaRecorder API
23
+
24
+ ---
25
+
26
+ ## Waveform
27
+
28
+ Visualize existing audio files (mp3, wav, etc.) with playhead and seek support.
29
+
30
+ ### AudioWaveform
31
+
32
+ ![AudioWaveform](https://react-audio-wavekit.netlify.app/audio-wave-form.png)
33
+
34
+ Static waveform visualization with playhead and click-to-seek.
35
+
36
+ [▶ Demo](https://react-audio-wavekit.netlify.app/?path=/story/waveform-audiowaveform--default)
37
+
38
+ ```tsx
39
+ <AudioWaveform
40
+ blob={audioBlob}
41
+ currentTime={currentTime}
42
+ duration={duration}
43
+ onSeek={(time) => (audioRef.current.currentTime = time)}
44
+ />
45
+ ```
46
+
47
+ | Prop | Type | Default | Description |
48
+ |------|------|---------|-------------|
49
+ | `blob` | `Blob \| null` | - | Audio blob to visualize (required) |
50
+ | `currentTime` | `number` | - | Current playback time in seconds |
51
+ | `duration` | `number` | - | Total audio duration in seconds |
52
+ | `onSeek` | `(time: number) => void` | - | Callback when user clicks on waveform |
53
+ | `suspense` | `boolean` | `false` | Enable React Suspense mode |
54
+ | `appearance` | `AudioWaveformAppearance` | - | See [Appearance Options](#appearance-options) |
55
+
56
+ ---
57
+
58
+ ## Recorder
59
+
60
+ Real-time waveform visualization during recording using MediaRecorder API.
61
+
62
+ ### useAudioRecorder
63
+
64
+ Headless hook to manage recording state. Use with recorder components below.
65
+
66
+ **Config:**
67
+
68
+ | Option | Type | Default | Description |
69
+ |--------|------|---------|-------------|
70
+ | `mimeType` | `string \| (() => string)` | auto | MIME type for recording |
71
+ | `audioConstraints` | `MediaTrackConstraints \| boolean` | `true` | Audio constraints for getUserMedia |
72
+ | `onRecordingComplete` | `(blob: Blob) => void` | - | Callback when recording is complete |
73
+
74
+ **Returns:**
75
+
76
+ | Property | Type | Description |
77
+ |----------|------|-------------|
78
+ | `startRecording` | `() => Promise<void>` | Start recording from microphone |
79
+ | `stopRecording` | `() => void` | Stop recording and generate blob |
80
+ | `pauseRecording` | `() => void` | Pause current recording |
81
+ | `resumeRecording` | `() => void` | Resume paused recording |
82
+ | `clearRecording` | `() => void` | Clear recording and reset state |
83
+ | `mediaRecorder` | `MediaRecorder \| null` | MediaRecorder instance |
84
+ | `recordingBlob` | `Blob \| null` | Recorded audio blob |
85
+ | `recordingTime` | `number` | Recording duration in seconds |
86
+ | `isRecording` | `boolean` | Whether currently recording |
87
+ | `isPaused` | `boolean` | Whether recording is paused |
88
+ | `error` | `Error \| null` | Any error that occurred |
89
+
90
+ ### LiveStreamingRecorder
91
+
92
+ ![LiveStreamingRecorder](https://react-audio-wavekit.netlify.app/live-stream.png)
93
+
94
+ Scrolling timeline waveform (Voice Memos style). Canvas grows horizontally as recording continues.
95
+
96
+ [▶ Demo](https://react-audio-wavekit.netlify.app/?path=/story/recorder-livestreamingrecorder--default)
97
+
98
+ ```tsx
99
+ <LiveStreamingRecorder.Root
100
+ mediaRecorder={mediaRecorder}
101
+ className="h-12 w-80 rounded bg-slate-100"
102
+ appearance={{ scrollbar: { thumbColor: "#94a3b8" } }}
103
+ >
104
+ <LiveStreamingRecorder.Canvas
105
+ appearance={{ barColor: "#3b82f6", barWidth: 2, barGap: 1 }}
106
+ growWidth={true}
107
+ />
108
+ </LiveStreamingRecorder.Root>
109
+ ```
110
+
111
+ **Root Props:**
112
+
113
+ | Prop | Type | Default | Description |
114
+ |------|------|---------|-------------|
115
+ | `mediaRecorder` | `MediaRecorder \| null` | - | MediaRecorder instance (required) |
116
+ | `fftSize` | `number` | `2048` | FFT size for frequency analysis |
117
+ | `smoothingTimeConstant` | `number` | `0.8` | Smoothing constant (0-1) |
118
+ | `sampleInterval` | `number` | `50` | Sample interval in ms |
119
+ | `appearance` | `LiveStreamingRecorderAppearance` | - | See [Appearance Options](#appearance-options) |
120
+
121
+ **Canvas Props:**
122
+
123
+ | Prop | Type | Default | Description |
124
+ |------|------|---------|-------------|
125
+ | `growWidth` | `boolean` | `true` | Canvas grows horizontally (enables scrolling) |
126
+ | `appearance` | `WaveformAppearance` | - | See [Appearance Options](#appearance-options) |
127
+
128
+ ### LiveStreamingStackRecorder
129
+
130
+ ![LiveStreamingStackRecorder](https://react-audio-wavekit.netlify.app/live-stream-stack.png)
131
+
132
+ Fixed-width waveform where bars compress as recording grows.
133
+
134
+ [▶ Demo](https://react-audio-wavekit.netlify.app/?path=/story/recorder-livestreamingstackrecorder--default)
135
+
136
+ ```tsx
137
+ <LiveStreamingStackRecorder
138
+ mediaRecorder={mediaRecorder}
139
+ className="h-12 w-80 rounded bg-slate-100"
140
+ appearance={{ barColor: "#3b82f6", barWidth: 2, barGap: 1 }}
141
+ />
142
+ ```
143
+
144
+ | Prop | Type | Default | Description |
145
+ |------|------|---------|-------------|
146
+ | `mediaRecorder` | `MediaRecorder \| null` | - | MediaRecorder instance (required) |
147
+ | `fftSize` | `number` | `2048` | FFT size for frequency analysis |
148
+ | `smoothingTimeConstant` | `number` | `0.8` | Smoothing constant (0-1) |
149
+ | `sampleInterval` | `number` | `50` | Sample interval in ms |
150
+ | `appearance` | `WaveformAppearance` | - | See [Appearance Options](#appearance-options) |
151
+
152
+ ### LiveRecorder
153
+
154
+ ![LiveRecorder](https://react-audio-wavekit.netlify.app/live-recorder.png)
155
+
156
+ Real-time frequency bars visualization.
157
+
158
+ [▶ Demo](https://react-audio-wavekit.netlify.app/?path=/story/recorder-liverecorder--default)
159
+
160
+ ```tsx
161
+ <LiveRecorder mediaRecorder={mediaRecorder} />
162
+ ```
163
+
164
+ | Prop | Type | Default | Description |
165
+ |------|------|---------|-------------|
166
+ | `mediaRecorder` | `MediaRecorder \| null` | - | MediaRecorder instance (required) |
167
+ | `fftSize` | `number` | `2048` | FFT size for frequency analysis |
168
+ | `smoothingTimeConstant` | `number` | `0.8` | Smoothing constant (0-1) |
169
+ | `showIdleState` | `boolean` | `true` | Show minimal bars when not recording |
170
+ | `appearance` | `WaveformAppearance` | - | See [Appearance Options](#appearance-options) |
171
+
172
+ ---
173
+
174
+ ## Appearance Options
175
+
176
+ ### WaveformAppearance
177
+
178
+ Common appearance options for all waveform components.
179
+
180
+ | Property | Type | Default | Description |
181
+ |----------|------|---------|-------------|
182
+ | `barColor` | `string` | `"#3b82f6"` | Color of waveform bars |
183
+ | `barWidth` | `number` | `1` | Width of each bar in pixels |
184
+ | `barGap` | `number` | `1` | Gap between bars in pixels |
185
+ | `barRadius` | `number` | `0` | Border radius of bars |
186
+ | `barHeightScale` | `number` | `0.95` | Scale factor for bar height (0-1) |
187
+
188
+ ### AudioWaveformAppearance
189
+
190
+ Extends `WaveformAppearance` with playhead options.
191
+
192
+ | Property | Type | Default | Description |
193
+ |----------|------|---------|-------------|
194
+ | `playheadColor` | `string` | `"#ef4444"` | Color of the playhead line |
195
+ | `playheadWidth` | `number` | `2` | Width of the playhead line |
196
+
197
+ ### ScrollbarAppearance
198
+
199
+ Options for scrollbar in `LiveStreamingRecorder`.
200
+
201
+ | Property | Type | Default | Description |
202
+ |----------|------|---------|-------------|
203
+ | `thumbColor` | `string` | `"rgba(148, 163, 184, 0.5)"` | Scrollbar thumb color |
204
+ | `hidden` | `boolean` | `false` | Hide scrollbar completely |
205
+
206
+ ---
207
+
208
+ ## Styling
209
+
210
+ Components accept `className`, `style`, and all standard canvas HTML attributes.
211
+
212
+ ```tsx
213
+ <AudioWaveform
214
+ blob={blob}
215
+ className="h-32 w-full rounded-lg bg-slate-900 p-4"
216
+ appearance={{
217
+ barColor: "#3b82f6",
218
+ barWidth: 2,
219
+ barGap: 1,
220
+ barRadius: 1,
221
+ playheadColor: "#ef4444",
222
+ playheadWidth: 2,
223
+ }}
224
+ />
225
+ ```
226
+
227
+ ---
228
+
229
+ ## License
230
+
231
+ [CC0 1.0](./LICENSE) - Public Domain
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const DEFAULT_WAVEFORM_APPEARANCE = {
4
+ barColor: "#3b82f6",
5
+ barWidth: 1,
6
+ barGap: 1,
7
+ barRadius: 0,
8
+ barHeightScale: 0.95
9
+ };
10
+ const DEFAULT_PLAYHEAD_APPEARANCE = {
11
+ playheadColor: "#ef4444",
12
+ playheadWidth: 2
13
+ };
14
+ const DEFAULT_SCROLLBAR_APPEARANCE = {
15
+ thumbColor: "rgba(148, 163, 184, 0.5)",
16
+ hidden: false
17
+ };
18
+ exports.DEFAULT_PLAYHEAD_APPEARANCE = DEFAULT_PLAYHEAD_APPEARANCE;
19
+ exports.DEFAULT_SCROLLBAR_APPEARANCE = DEFAULT_SCROLLBAR_APPEARANCE;
20
+ exports.DEFAULT_WAVEFORM_APPEARANCE = DEFAULT_WAVEFORM_APPEARANCE;
@@ -0,0 +1,20 @@
1
+ const DEFAULT_WAVEFORM_APPEARANCE = {
2
+ barColor: "#3b82f6",
3
+ barWidth: 1,
4
+ barGap: 1,
5
+ barRadius: 0,
6
+ barHeightScale: 0.95
7
+ };
8
+ const DEFAULT_PLAYHEAD_APPEARANCE = {
9
+ playheadColor: "#ef4444",
10
+ playheadWidth: 2
11
+ };
12
+ const DEFAULT_SCROLLBAR_APPEARANCE = {
13
+ thumbColor: "rgba(148, 163, 184, 0.5)",
14
+ hidden: false
15
+ };
16
+ export {
17
+ DEFAULT_PLAYHEAD_APPEARANCE,
18
+ DEFAULT_SCROLLBAR_APPEARANCE,
19
+ DEFAULT_WAVEFORM_APPEARANCE
20
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const index = require("./recorder/live-recorder/index.cjs");
4
+ const recorderCompound = require("./recorder/live-streaming/recorder/recorder-compound.cjs");
5
+ const stackRecorderCompound = require("./recorder/live-streaming/stack-recorder/stack-recorder-compound.cjs");
6
+ const useAudioRecorder = require("./recorder/use-audio-recorder.cjs");
7
+ const index$1 = require("./waveform/index.cjs");
8
+ exports.LiveRecorder = index.LiveRecorder;
9
+ exports.LiveStreamingRecorder = recorderCompound.LiveStreamingRecorder;
10
+ exports.LiveStreamingStackRecorder = stackRecorderCompound.LiveStreamingStackRecorder;
11
+ exports.useAudioRecorder = useAudioRecorder.useAudioRecorder;
12
+ exports.AudioWaveform = index$1.AudioWaveform;
@@ -0,0 +1,235 @@
1
+ import { ForwardRefExoticComponent } from 'react';
2
+ import { HTMLAttributes } from 'react';
3
+ import { ReactNode } from 'react';
4
+ import { RefAttributes } from 'react';
5
+
6
+ export declare const AudioWaveform: ForwardRefExoticComponent<AudioWaveformProps & RefAttributes<AudioWaveformRef>>;
7
+
8
+ /**
9
+ * AudioWaveform-specific appearance configuration
10
+ * Extends WaveformAppearance with playhead styles
11
+ */
12
+ export declare interface AudioWaveformAppearance extends WaveformAppearance {
13
+ /** Playhead color (CSS color value). Default: "#ef4444" (red-500) */
14
+ playheadColor?: string;
15
+ /** Playhead width (pixels). Default: 2 */
16
+ playheadWidth?: number;
17
+ }
18
+
19
+ declare interface AudioWaveformProps extends React.CanvasHTMLAttributes<HTMLCanvasElement> {
20
+ /** Audio blob to visualize */
21
+ blob: Blob | null;
22
+ /** Waveform appearance configuration (barColor, barWidth, playheadColor, etc.) */
23
+ appearance?: AudioWaveformAppearance;
24
+ /** Enable Suspense mode (requires Suspense boundary in parent) */
25
+ suspense?: boolean;
26
+ /** Current playback time in seconds (shows playhead) */
27
+ currentTime?: number;
28
+ /** Total audio duration in seconds (required for playhead positioning) */
29
+ duration?: number;
30
+ /** Callback when user clicks/seeks on waveform */
31
+ onSeek?: (time: number) => void;
32
+ }
33
+
34
+ declare interface AudioWaveformRef {
35
+ canvas: HTMLCanvasElement | null;
36
+ }
37
+
38
+ /**
39
+ * 실시간 오디오 주파수 시각화 컴포넌트
40
+ * MediaRecorder의 오디오를 Web Audio API로 분석하여 바 형태로 렌더링
41
+ */
42
+ export declare const LiveRecorder: ForwardRefExoticComponent<LiveRecorderProps & RefAttributes<LiveRecorderRef>>;
43
+
44
+ declare interface LiveRecorderProps extends React.CanvasHTMLAttributes<HTMLCanvasElement> {
45
+ /**
46
+ * MediaRecorder instance to visualize
47
+ */
48
+ mediaRecorder: MediaRecorder | null;
49
+ /**
50
+ * Waveform appearance configuration
51
+ */
52
+ appearance?: WaveformAppearance;
53
+ /**
54
+ * FFT size for frequency analysis (must be power of 2)
55
+ * @default 2048
56
+ */
57
+ fftSize?: number;
58
+ /**
59
+ * Smoothing time constant for analyser (0-1)
60
+ * @default 0.8
61
+ */
62
+ smoothingTimeConstant?: number;
63
+ /**
64
+ * Show minimal bars when not recording (idle state)
65
+ * @default true
66
+ */
67
+ showIdleState?: boolean;
68
+ }
69
+
70
+ declare interface LiveRecorderRef {
71
+ /** Get the canvas element */
72
+ getCanvas: () => HTMLCanvasElement | null;
73
+ /** Get the audio context */
74
+ getAudioContext: () => AudioContext | null;
75
+ /** Get the analyser node */
76
+ getAnalyser: () => AnalyserNode | null;
77
+ }
78
+
79
+ export declare const LiveStreamingRecorder: ForwardRefExoticComponent<LiveStreamingRecorderRootProps & RefAttributes<HTMLDivElement>> & {
80
+ Root: ForwardRefExoticComponent<LiveStreamingRecorderRootProps & RefAttributes<HTMLDivElement>>;
81
+ Canvas: ForwardRefExoticComponent<LiveStreamingRecorderCanvasProps & RefAttributes<HTMLCanvasElement>>;
82
+ };
83
+
84
+ /**
85
+ * LiveStreamingRecorder-specific appearance configuration
86
+ * Extends WaveformAppearance with scrollbar styles
87
+ */
88
+ declare interface LiveStreamingRecorderAppearance extends WaveformAppearance {
89
+ /** Scrollbar appearance configuration */
90
+ scrollbar?: ScrollbarAppearance;
91
+ }
92
+
93
+ declare interface LiveStreamingRecorderCanvasProps extends HTMLAttributes<HTMLCanvasElement> {
94
+ /** Additional className for canvas element */
95
+ className?: string;
96
+ /** Inline styles for canvas element */
97
+ style?: React.CSSProperties;
98
+ /** Waveform appearance configuration (barColor, barWidth, etc.) - scrollbar 설정은 Root에서만 유효 */
99
+ appearance?: LiveStreamingRecorderAppearance;
100
+ /**
101
+ * Allow canvas width to grow beyond container (enables scrolling)
102
+ * - true: Canvas grows horizontally as recording continues (Voice Memos style)
103
+ * - false: Canvas stays fixed width, bars get compressed
104
+ * @default true
105
+ */
106
+ growWidth?: boolean;
107
+ }
108
+
109
+ declare type LiveStreamingRecorderContextValue = UseRecordingAmplitudesReturn;
110
+
111
+ declare interface LiveStreamingRecorderRootProps extends UseRecordingAmplitudesOptions, Omit<HTMLAttributes<HTMLDivElement>, "children"> {
112
+ children: ReactNode | ((value: ReturnType<typeof useLiveStreamingRecorderContext>) => ReactNode);
113
+ /** Appearance configuration (waveform + scrollbar styles) */
114
+ appearance?: LiveStreamingRecorderAppearance;
115
+ }
116
+
117
+ export declare const LiveStreamingStackRecorder: ForwardRefExoticComponent<LiveStreamingStackRecorderProps & RefAttributes<HTMLCanvasElement>>;
118
+
119
+ declare interface LiveStreamingStackRecorderProps extends UseRecordingAmplitudesOptions, Omit<React.CanvasHTMLAttributes<HTMLCanvasElement>, "children"> {
120
+ /** Waveform appearance configuration (barColor, barWidth, etc.) */
121
+ appearance?: WaveformAppearance;
122
+ }
123
+
124
+ /**
125
+ * Scrollbar appearance configuration
126
+ * Used by LiveStreamingRecorder for custom scrollbar styling (OverlayScrollbars)
127
+ */
128
+ export declare interface ScrollbarAppearance {
129
+ /** Scrollbar thumb/handle color (CSS color value). Default: "rgba(148, 163, 184, 0.5)" */
130
+ thumbColor?: string;
131
+ /** Hide scrollbar completely. Default: false */
132
+ hidden?: boolean;
133
+ }
134
+
135
+ /**
136
+ * Custom hook for audio recording with real-time visualization support
137
+ * Based on react-audio-visualize patterns
138
+ */
139
+ export declare const useAudioRecorder: (config?: UseAudioRecorderConfig) => UseAudioRecorderReturn;
140
+
141
+ declare interface UseAudioRecorderConfig {
142
+ /**
143
+ * MIME type for the recording
144
+ * - string: Directly specify MIME type (e.g., 'audio/webm', 'audio/mp4')
145
+ * - function: Select MIME type with custom logic (browser detection, etc.)
146
+ * - undefined: Auto-select by browser (Safari: audio/mp4, Others: audio/webm)
147
+ * @default getDefaultMimeType() - Auto-select by browser
148
+ */
149
+ mimeType?: string | (() => string);
150
+ /**
151
+ * Audio constraints for getUserMedia
152
+ * @default true
153
+ */
154
+ audioConstraints?: MediaTrackConstraints | boolean;
155
+ /**
156
+ * Callback when recording is complete
157
+ */
158
+ onRecordingComplete?: (blob: Blob) => void;
159
+ }
160
+
161
+ export declare interface UseAudioRecorderReturn {
162
+ /** Start recording from the microphone */
163
+ startRecording: () => Promise<void>;
164
+ /** Stop recording and generate the audio blob */
165
+ stopRecording: () => void;
166
+ /** Pause the current recording */
167
+ pauseRecording: () => void;
168
+ /** Resume a paused recording */
169
+ resumeRecording: () => void;
170
+ /** Clear the recording and reset state */
171
+ clearRecording: () => void;
172
+ /** The MediaRecorder instance (for visualization) */
173
+ mediaRecorder: MediaRecorder | null;
174
+ /** The recorded audio as a Blob (available after stopRecording) */
175
+ recordingBlob: Blob | null;
176
+ /** Recording duration in seconds */
177
+ recordingTime: number;
178
+ /** Whether currently recording */
179
+ isRecording: boolean;
180
+ /** Whether recording is paused */
181
+ isPaused: boolean;
182
+ /** Any error that occurred */
183
+ error: Error | null;
184
+ }
185
+
186
+ /**
187
+ * LiveStreamingRecorder Context hook
188
+ * Must be used within LiveStreamingRecorder.Root component
189
+ */
190
+ declare function useLiveStreamingRecorderContext(): LiveStreamingRecorderContextValue;
191
+
192
+ declare interface UseRecordingAmplitudesOptions {
193
+ /** MediaRecorder instance to sample from */
194
+ mediaRecorder: MediaRecorder | null;
195
+ /** FFT size for frequency analysis (must be power of 2) */
196
+ fftSize?: number;
197
+ /** Smoothing time constant for analyser (0-1) */
198
+ smoothingTimeConstant?: number;
199
+ /** Interval in ms for sampling amplitude data */
200
+ sampleInterval?: number;
201
+ }
202
+
203
+ declare interface UseRecordingAmplitudesReturn {
204
+ /** Array of amplitude values (0-1 range) sampled over time */
205
+ amplitudes: number[];
206
+ /** Audio context instance */
207
+ audioContext: AudioContext | null;
208
+ /** Analyser node instance */
209
+ analyser: AnalyserNode | null;
210
+ /** Whether recording is active */
211
+ isRecording: boolean;
212
+ /** Whether recording is paused */
213
+ isPaused: boolean;
214
+ /** Clear all amplitude data */
215
+ clearAmplitudes: () => void;
216
+ }
217
+
218
+ /**
219
+ * Base waveform appearance configuration
220
+ * Used by all waveform components
221
+ */
222
+ export declare interface WaveformAppearance {
223
+ /** Bar color (CSS color value). Default: "#3b82f6" (blue-500) */
224
+ barColor?: string;
225
+ /** Bar width (pixels). Default: 3 */
226
+ barWidth?: number;
227
+ /** Bar gap (pixels). Default: 1 */
228
+ barGap?: number;
229
+ /** Bar corner radius (pixels). Default: 1.5 */
230
+ barRadius?: number;
231
+ /** Bar height scale (0.0 - 1.0). Default: 0.95 (5% top/bottom margin) */
232
+ barHeightScale?: number;
233
+ }
234
+
235
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { LiveRecorder } from "./recorder/live-recorder/index.js";
2
+ import { LiveStreamingRecorder } from "./recorder/live-streaming/recorder/recorder-compound.js";
3
+ import { LiveStreamingStackRecorder } from "./recorder/live-streaming/stack-recorder/stack-recorder-compound.js";
4
+ import { useAudioRecorder } from "./recorder/use-audio-recorder.js";
5
+ import { AudioWaveform } from "./waveform/index.js";
6
+ export {
7
+ AudioWaveform,
8
+ LiveRecorder,
9
+ LiveStreamingRecorder,
10
+ LiveStreamingStackRecorder,
11
+ useAudioRecorder
12
+ };