react-audio-wavekit 0.1.1 → 0.1.3
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/README.md +1 -5
- package/dist/index.d.ts +0 -7
- package/dist/recorder/live-streaming/recorder/recorder-compound.cjs +16 -36
- package/dist/recorder/live-streaming/recorder/recorder-compound.js +16 -36
- package/dist/recorder/live-streaming/stack-recorder/stack-recorder-compound.cjs +1 -15
- package/dist/recorder/live-streaming/stack-recorder/stack-recorder-compound.js +1 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,10 +101,7 @@ Scrolling timeline waveform (Voice Memos style). Canvas grows horizontally as re
|
|
|
101
101
|
className="h-12 w-80 rounded bg-slate-100"
|
|
102
102
|
appearance={{ scrollbar: { thumbColor: "#94a3b8" } }}
|
|
103
103
|
>
|
|
104
|
-
<LiveStreamingRecorder.Canvas
|
|
105
|
-
appearance={{ barColor: "#3b82f6", barWidth: 2, barGap: 1 }}
|
|
106
|
-
growWidth={true}
|
|
107
|
-
/>
|
|
104
|
+
<LiveStreamingRecorder.Canvas appearance={{ barColor: "#3b82f6", barWidth: 2, barGap: 1 }} />
|
|
108
105
|
</LiveStreamingRecorder.Root>
|
|
109
106
|
```
|
|
110
107
|
|
|
@@ -122,7 +119,6 @@ Scrolling timeline waveform (Voice Memos style). Canvas grows horizontally as re
|
|
|
122
119
|
|
|
123
120
|
| Prop | Type | Default | Description |
|
|
124
121
|
|------|------|---------|-------------|
|
|
125
|
-
| `growWidth` | `boolean` | `true` | Canvas grows horizontally (enables scrolling) |
|
|
126
122
|
| `appearance` | `WaveformAppearance` | - | See [Appearance Options](#appearance-options) |
|
|
127
123
|
|
|
128
124
|
### LiveStreamingStackRecorder
|
package/dist/index.d.ts
CHANGED
|
@@ -97,13 +97,6 @@ declare interface LiveStreamingRecorderCanvasProps extends HTMLAttributes<HTMLCa
|
|
|
97
97
|
style?: React.CSSProperties;
|
|
98
98
|
/** Waveform appearance configuration (barColor, barWidth, etc.) - scrollbar 설정은 Root에서만 유효 */
|
|
99
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
100
|
}
|
|
108
101
|
|
|
109
102
|
declare type LiveStreamingRecorderContextValue = UseRecordingAmplitudesReturn;
|
|
@@ -100,7 +100,7 @@ const LiveStreamingRecorderRoot = react.forwardRef(
|
|
|
100
100
|
}
|
|
101
101
|
);
|
|
102
102
|
const LiveStreamingRecorderCanvas = react.forwardRef(
|
|
103
|
-
function LiveStreamingRecorderCanvas2({ className = "", style, appearance,
|
|
103
|
+
function LiveStreamingRecorderCanvas2({ className = "", style, appearance, ...props }, ref) {
|
|
104
104
|
const { amplitudes, isRecording, isPaused } = recorderContext.useLiveStreamingRecorderContext();
|
|
105
105
|
const canvasRef = react.useRef(null);
|
|
106
106
|
const animationRef = react.useRef(null);
|
|
@@ -137,17 +137,11 @@ const LiveStreamingRecorderCanvas = react.forwardRef(
|
|
|
137
137
|
const barHeightScale = appearance?.barHeightScale ?? constants.DEFAULT_WAVEFORM_APPEARANCE.barHeightScale;
|
|
138
138
|
const totalBarWidth = barWidth + barGap;
|
|
139
139
|
if (isRecording || amplitudes.length > 0) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
prevCanvasWidthRef.current = canvasWidth;
|
|
146
|
-
canvas.style.width = `${canvasWidth}px`;
|
|
147
|
-
} else {
|
|
148
|
-
canvasWidth = containerWidth;
|
|
149
|
-
canvas.style.width = "100%";
|
|
150
|
-
}
|
|
140
|
+
const requiredWidth = amplitudes.length * totalBarWidth;
|
|
141
|
+
const calculatedWidth = amplitudes.length > 0 ? requiredWidth : containerWidth;
|
|
142
|
+
const canvasWidth = Math.max(calculatedWidth, prevCanvasWidthRef.current);
|
|
143
|
+
prevCanvasWidthRef.current = canvasWidth;
|
|
144
|
+
canvas.style.width = `${canvasWidth}px`;
|
|
151
145
|
canvas.width = canvasWidth * dpr;
|
|
152
146
|
canvas.height = containerHeight * dpr;
|
|
153
147
|
ctx.scale(dpr, dpr);
|
|
@@ -155,29 +149,16 @@ const LiveStreamingRecorderCanvas = react.forwardRef(
|
|
|
155
149
|
ctx.fillStyle = barColor;
|
|
156
150
|
const minBarHeight = 2;
|
|
157
151
|
ctx.beginPath();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
ctx.roundRect(x, y, barWidth, barHeight, barRadius);
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
const barsCount = Math.floor(canvasWidth / totalBarWidth);
|
|
168
|
-
const step = amplitudes.length / barsCount;
|
|
169
|
-
for (let i = 0; i < barsCount; i++) {
|
|
170
|
-
const amplitudeIndex = Math.min(Math.floor(i * step), amplitudes.length - 1);
|
|
171
|
-
const amplitude = amplitudes[amplitudeIndex] || 0;
|
|
172
|
-
const barHeight = Math.max(minBarHeight, amplitude * containerHeight * barHeightScale);
|
|
173
|
-
const x = i * totalBarWidth;
|
|
174
|
-
const y = (containerHeight - barHeight) / 2;
|
|
175
|
-
ctx.roundRect(x, y, barWidth, barHeight, barRadius);
|
|
176
|
-
}
|
|
152
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
153
|
+
const amplitude = amplitudes[i];
|
|
154
|
+
const barHeight = Math.max(minBarHeight, amplitude * containerHeight * barHeightScale);
|
|
155
|
+
const x = i * totalBarWidth;
|
|
156
|
+
const y = (containerHeight - barHeight) / 2;
|
|
157
|
+
ctx.roundRect(x, y, barWidth, barHeight, barRadius);
|
|
177
158
|
}
|
|
178
159
|
ctx.fill();
|
|
179
160
|
}
|
|
180
|
-
}, [amplitudes, isRecording, appearance
|
|
161
|
+
}, [amplitudes, isRecording, appearance]);
|
|
181
162
|
react.useEffect(() => {
|
|
182
163
|
const canvas = canvasRef.current;
|
|
183
164
|
if (!canvas) return;
|
|
@@ -204,7 +185,7 @@ const LiveStreamingRecorderCanvas = react.forwardRef(
|
|
|
204
185
|
if (isRecording && !isPaused) {
|
|
205
186
|
const draw = () => {
|
|
206
187
|
drawWaveform();
|
|
207
|
-
if (
|
|
188
|
+
if (containerRef.current) {
|
|
208
189
|
containerRef.current.scrollLeft = containerRef.current.scrollWidth;
|
|
209
190
|
}
|
|
210
191
|
animationRef.current = requestAnimationFrame(draw);
|
|
@@ -218,15 +199,14 @@ const LiveStreamingRecorderCanvas = react.forwardRef(
|
|
|
218
199
|
};
|
|
219
200
|
}
|
|
220
201
|
drawWaveform();
|
|
221
|
-
}, [isRecording, isPaused, drawWaveform
|
|
202
|
+
}, [isRecording, isPaused, drawWaveform]);
|
|
222
203
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
223
204
|
"canvas",
|
|
224
205
|
{
|
|
225
206
|
ref: canvasRef,
|
|
226
207
|
className,
|
|
227
208
|
style: {
|
|
228
|
-
|
|
229
|
-
display: growWidth ? "block" : void 0,
|
|
209
|
+
display: "block",
|
|
230
210
|
height: "100%",
|
|
231
211
|
...style
|
|
232
212
|
},
|
|
@@ -98,7 +98,7 @@ const LiveStreamingRecorderRoot = forwardRef(
|
|
|
98
98
|
}
|
|
99
99
|
);
|
|
100
100
|
const LiveStreamingRecorderCanvas = forwardRef(
|
|
101
|
-
function LiveStreamingRecorderCanvas2({ className = "", style, appearance,
|
|
101
|
+
function LiveStreamingRecorderCanvas2({ className = "", style, appearance, ...props }, ref) {
|
|
102
102
|
const { amplitudes, isRecording, isPaused } = useLiveStreamingRecorderContext();
|
|
103
103
|
const canvasRef = useRef(null);
|
|
104
104
|
const animationRef = useRef(null);
|
|
@@ -135,17 +135,11 @@ const LiveStreamingRecorderCanvas = forwardRef(
|
|
|
135
135
|
const barHeightScale = appearance?.barHeightScale ?? DEFAULT_WAVEFORM_APPEARANCE.barHeightScale;
|
|
136
136
|
const totalBarWidth = barWidth + barGap;
|
|
137
137
|
if (isRecording || amplitudes.length > 0) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
prevCanvasWidthRef.current = canvasWidth;
|
|
144
|
-
canvas.style.width = `${canvasWidth}px`;
|
|
145
|
-
} else {
|
|
146
|
-
canvasWidth = containerWidth;
|
|
147
|
-
canvas.style.width = "100%";
|
|
148
|
-
}
|
|
138
|
+
const requiredWidth = amplitudes.length * totalBarWidth;
|
|
139
|
+
const calculatedWidth = amplitudes.length > 0 ? requiredWidth : containerWidth;
|
|
140
|
+
const canvasWidth = Math.max(calculatedWidth, prevCanvasWidthRef.current);
|
|
141
|
+
prevCanvasWidthRef.current = canvasWidth;
|
|
142
|
+
canvas.style.width = `${canvasWidth}px`;
|
|
149
143
|
canvas.width = canvasWidth * dpr;
|
|
150
144
|
canvas.height = containerHeight * dpr;
|
|
151
145
|
ctx.scale(dpr, dpr);
|
|
@@ -153,29 +147,16 @@ const LiveStreamingRecorderCanvas = forwardRef(
|
|
|
153
147
|
ctx.fillStyle = barColor;
|
|
154
148
|
const minBarHeight = 2;
|
|
155
149
|
ctx.beginPath();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
ctx.roundRect(x, y, barWidth, barHeight, barRadius);
|
|
163
|
-
}
|
|
164
|
-
} else {
|
|
165
|
-
const barsCount = Math.floor(canvasWidth / totalBarWidth);
|
|
166
|
-
const step = amplitudes.length / barsCount;
|
|
167
|
-
for (let i = 0; i < barsCount; i++) {
|
|
168
|
-
const amplitudeIndex = Math.min(Math.floor(i * step), amplitudes.length - 1);
|
|
169
|
-
const amplitude = amplitudes[amplitudeIndex] || 0;
|
|
170
|
-
const barHeight = Math.max(minBarHeight, amplitude * containerHeight * barHeightScale);
|
|
171
|
-
const x = i * totalBarWidth;
|
|
172
|
-
const y = (containerHeight - barHeight) / 2;
|
|
173
|
-
ctx.roundRect(x, y, barWidth, barHeight, barRadius);
|
|
174
|
-
}
|
|
150
|
+
for (let i = 0; i < amplitudes.length; i++) {
|
|
151
|
+
const amplitude = amplitudes[i];
|
|
152
|
+
const barHeight = Math.max(minBarHeight, amplitude * containerHeight * barHeightScale);
|
|
153
|
+
const x = i * totalBarWidth;
|
|
154
|
+
const y = (containerHeight - barHeight) / 2;
|
|
155
|
+
ctx.roundRect(x, y, barWidth, barHeight, barRadius);
|
|
175
156
|
}
|
|
176
157
|
ctx.fill();
|
|
177
158
|
}
|
|
178
|
-
}, [amplitudes, isRecording, appearance
|
|
159
|
+
}, [amplitudes, isRecording, appearance]);
|
|
179
160
|
useEffect(() => {
|
|
180
161
|
const canvas = canvasRef.current;
|
|
181
162
|
if (!canvas) return;
|
|
@@ -202,7 +183,7 @@ const LiveStreamingRecorderCanvas = forwardRef(
|
|
|
202
183
|
if (isRecording && !isPaused) {
|
|
203
184
|
const draw = () => {
|
|
204
185
|
drawWaveform();
|
|
205
|
-
if (
|
|
186
|
+
if (containerRef.current) {
|
|
206
187
|
containerRef.current.scrollLeft = containerRef.current.scrollWidth;
|
|
207
188
|
}
|
|
208
189
|
animationRef.current = requestAnimationFrame(draw);
|
|
@@ -216,15 +197,14 @@ const LiveStreamingRecorderCanvas = forwardRef(
|
|
|
216
197
|
};
|
|
217
198
|
}
|
|
218
199
|
drawWaveform();
|
|
219
|
-
}, [isRecording, isPaused, drawWaveform
|
|
200
|
+
}, [isRecording, isPaused, drawWaveform]);
|
|
220
201
|
return /* @__PURE__ */ jsx(
|
|
221
202
|
"canvas",
|
|
222
203
|
{
|
|
223
204
|
ref: canvasRef,
|
|
224
205
|
className,
|
|
225
206
|
style: {
|
|
226
|
-
|
|
227
|
-
display: growWidth ? "block" : void 0,
|
|
207
|
+
display: "block",
|
|
228
208
|
height: "100%",
|
|
229
209
|
...style
|
|
230
210
|
},
|
|
@@ -106,21 +106,7 @@ const LiveStreamingStackRecorder = react.forwardRef(
|
|
|
106
106
|
}
|
|
107
107
|
drawWaveform();
|
|
108
108
|
}, [isRecording, isPaused, drawWaveform]);
|
|
109
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
110
|
-
"canvas",
|
|
111
|
-
{
|
|
112
|
-
ref: canvasRef,
|
|
113
|
-
className,
|
|
114
|
-
style: {
|
|
115
|
-
width: "100%",
|
|
116
|
-
height: "100%",
|
|
117
|
-
...style
|
|
118
|
-
},
|
|
119
|
-
"aria-hidden": "true",
|
|
120
|
-
tabIndex: -1,
|
|
121
|
-
...props
|
|
122
|
-
}
|
|
123
|
-
);
|
|
109
|
+
return /* @__PURE__ */ jsxRuntime.jsx("canvas", { ref: canvasRef, className, style, "aria-hidden": "true", tabIndex: -1, ...props });
|
|
124
110
|
}
|
|
125
111
|
);
|
|
126
112
|
exports.LiveStreamingStackRecorder = LiveStreamingStackRecorder;
|
|
@@ -104,21 +104,7 @@ const LiveStreamingStackRecorder = forwardRef(
|
|
|
104
104
|
}
|
|
105
105
|
drawWaveform();
|
|
106
106
|
}, [isRecording, isPaused, drawWaveform]);
|
|
107
|
-
return /* @__PURE__ */ jsx(
|
|
108
|
-
"canvas",
|
|
109
|
-
{
|
|
110
|
-
ref: canvasRef,
|
|
111
|
-
className,
|
|
112
|
-
style: {
|
|
113
|
-
width: "100%",
|
|
114
|
-
height: "100%",
|
|
115
|
-
...style
|
|
116
|
-
},
|
|
117
|
-
"aria-hidden": "true",
|
|
118
|
-
tabIndex: -1,
|
|
119
|
-
...props
|
|
120
|
-
}
|
|
121
|
-
);
|
|
107
|
+
return /* @__PURE__ */ jsx("canvas", { ref: canvasRef, className, style, "aria-hidden": "true", tabIndex: -1, ...props });
|
|
122
108
|
}
|
|
123
109
|
);
|
|
124
110
|
export {
|