react-audio-wavekit 0.1.0 → 0.1.1
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/dist/waveform/index.cjs +5 -9
- package/dist/waveform/index.js +6 -10
- package/package.json +1 -1
package/dist/waveform/index.cjs
CHANGED
|
@@ -5,20 +5,16 @@ const react = require("react");
|
|
|
5
5
|
const utilAudioDecoder = require("./util-audio-decoder.cjs");
|
|
6
6
|
const utilSuspense = require("./util-suspense.cjs");
|
|
7
7
|
const waveformRenderer = require("./waveform-renderer.cjs");
|
|
8
|
-
const
|
|
8
|
+
const getInitialSampleCount = () => {
|
|
9
|
+
if (typeof window === "undefined") return 500;
|
|
10
|
+
return Math.max(500, Math.ceil(window.innerWidth));
|
|
11
|
+
};
|
|
9
12
|
const AudioWaveform = react.forwardRef(function AudioWaveform2({ blob, appearance, suspense = false, currentTime, duration, onSeek, ...props }, ref) {
|
|
10
13
|
const [peaks, setPeaks] = react.useState(null);
|
|
11
14
|
const [error, setError] = react.useState(null);
|
|
12
|
-
const [sampleCount, setSampleCount] = react.useState(DEFAULT_SAMPLE_COUNT);
|
|
13
|
-
const sampleCountInitializedRef = react.useRef(false);
|
|
14
15
|
const blobRef = react.useRef(null);
|
|
15
16
|
const rendererRef = react.useRef(null);
|
|
16
|
-
react.
|
|
17
|
-
if (!sampleCountInitializedRef.current) {
|
|
18
|
-
setSampleCount(Math.max(500, Math.ceil(window.innerWidth)));
|
|
19
|
-
sampleCountInitializedRef.current = true;
|
|
20
|
-
}
|
|
21
|
-
}, []);
|
|
17
|
+
const sampleCount = react.useMemo(() => getInitialSampleCount(), []);
|
|
22
18
|
react.useEffect(() => {
|
|
23
19
|
if (ref && typeof ref === "function") {
|
|
24
20
|
ref({ canvas: rendererRef.current?.canvas || null });
|
package/dist/waveform/index.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useState, useRef, useEffect } from "react";
|
|
2
|
+
import { forwardRef, useState, useRef, useMemo, useEffect } from "react";
|
|
3
3
|
import { getAudioData, decodeAudioBlob } from "./util-audio-decoder.js";
|
|
4
4
|
import { unwrapPromise } from "./util-suspense.js";
|
|
5
5
|
import { WaveformRenderer } from "./waveform-renderer.js";
|
|
6
|
-
const
|
|
6
|
+
const getInitialSampleCount = () => {
|
|
7
|
+
if (typeof window === "undefined") return 500;
|
|
8
|
+
return Math.max(500, Math.ceil(window.innerWidth));
|
|
9
|
+
};
|
|
7
10
|
const AudioWaveform = forwardRef(function AudioWaveform2({ blob, appearance, suspense = false, currentTime, duration, onSeek, ...props }, ref) {
|
|
8
11
|
const [peaks, setPeaks] = useState(null);
|
|
9
12
|
const [error, setError] = useState(null);
|
|
10
|
-
const [sampleCount, setSampleCount] = useState(DEFAULT_SAMPLE_COUNT);
|
|
11
|
-
const sampleCountInitializedRef = useRef(false);
|
|
12
13
|
const blobRef = useRef(null);
|
|
13
14
|
const rendererRef = useRef(null);
|
|
14
|
-
|
|
15
|
-
if (!sampleCountInitializedRef.current) {
|
|
16
|
-
setSampleCount(Math.max(500, Math.ceil(window.innerWidth)));
|
|
17
|
-
sampleCountInitializedRef.current = true;
|
|
18
|
-
}
|
|
19
|
-
}, []);
|
|
15
|
+
const sampleCount = useMemo(() => getInitialSampleCount(), []);
|
|
20
16
|
useEffect(() => {
|
|
21
17
|
if (ref && typeof ref === "function") {
|
|
22
18
|
ref({ canvas: rendererRef.current?.canvas || null });
|