@wq-hook/volcano-react 1.0.5 → 1.0.6
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/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +47 -7
- package/dist/index.mjs +48 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -678,10 +678,10 @@ interface AudioWaveVisualizerProps {
|
|
|
678
678
|
color?: string | [string, string];
|
|
679
679
|
/** 波形条数 */
|
|
680
680
|
bars?: number;
|
|
681
|
-
/**
|
|
682
|
-
height?: number;
|
|
683
|
-
/**
|
|
684
|
-
width?: number;
|
|
681
|
+
/** 高度:数字(像素)或 CSS 字符串(如 "60px"、"100%"、"5rem") */
|
|
682
|
+
height?: number | string;
|
|
683
|
+
/** 宽度:数字(像素)或 CSS 字符串(如 "100%"、"80%"、"300px") */
|
|
684
|
+
width?: number | string;
|
|
685
685
|
/** 自定义类名 */
|
|
686
686
|
className?: string;
|
|
687
687
|
/** 自定义样式 */
|
package/dist/index.d.ts
CHANGED
|
@@ -678,10 +678,10 @@ interface AudioWaveVisualizerProps {
|
|
|
678
678
|
color?: string | [string, string];
|
|
679
679
|
/** 波形条数 */
|
|
680
680
|
bars?: number;
|
|
681
|
-
/**
|
|
682
|
-
height?: number;
|
|
683
|
-
/**
|
|
684
|
-
width?: number;
|
|
681
|
+
/** 高度:数字(像素)或 CSS 字符串(如 "60px"、"100%"、"5rem") */
|
|
682
|
+
height?: number | string;
|
|
683
|
+
/** 宽度:数字(像素)或 CSS 字符串(如 "100%"、"80%"、"300px") */
|
|
684
|
+
width?: number | string;
|
|
685
685
|
/** 自定义类名 */
|
|
686
686
|
className?: string;
|
|
687
687
|
/** 自定义样式 */
|
package/dist/index.js
CHANGED
|
@@ -1865,10 +1865,40 @@ var AudioWaveVisualizer = ({
|
|
|
1865
1865
|
styleObj
|
|
1866
1866
|
}) => {
|
|
1867
1867
|
const canvasRef = (0, import_react5.useRef)(null);
|
|
1868
|
+
const containerRef = (0, import_react5.useRef)(null);
|
|
1868
1869
|
const requestRef = (0, import_react5.useRef)(null);
|
|
1870
|
+
const isWidthResponsive = typeof width === "string";
|
|
1871
|
+
const isHeightResponsive = typeof height === "string";
|
|
1872
|
+
const [canvasWidth, setCanvasWidth] = (0, import_react5.useState)(() => {
|
|
1873
|
+
return typeof width === "number" ? width : 200;
|
|
1874
|
+
});
|
|
1875
|
+
const [canvasHeight, setCanvasHeight] = (0, import_react5.useState)(() => {
|
|
1876
|
+
return typeof height === "number" ? height : 60;
|
|
1877
|
+
});
|
|
1878
|
+
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
1879
|
+
(0, import_react5.useEffect)(() => {
|
|
1880
|
+
if (!containerRef.current) return;
|
|
1881
|
+
if (!isWidthResponsive && !isHeightResponsive) return;
|
|
1882
|
+
const container = containerRef.current;
|
|
1883
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
1884
|
+
for (const entry of entries) {
|
|
1885
|
+
const { width: containerWidth, height: containerHeight } = entry.contentRect;
|
|
1886
|
+
if (isWidthResponsive) {
|
|
1887
|
+
setCanvasWidth(Math.floor(containerWidth * dpr));
|
|
1888
|
+
}
|
|
1889
|
+
if (isHeightResponsive) {
|
|
1890
|
+
setCanvasHeight(Math.floor(containerHeight * dpr));
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
});
|
|
1894
|
+
resizeObserver.observe(container);
|
|
1895
|
+
return () => {
|
|
1896
|
+
resizeObserver.disconnect();
|
|
1897
|
+
};
|
|
1898
|
+
}, [isWidthResponsive, isHeightResponsive, dpr]);
|
|
1869
1899
|
const progressBackground = Array.isArray(color) ? `linear-gradient(90deg, ${color[0]}, ${color[1]})` : color;
|
|
1870
1900
|
const textColor = Array.isArray(color) ? color[0] : color;
|
|
1871
|
-
const draw = () => {
|
|
1901
|
+
const draw = (0, import_react5.useCallback)(() => {
|
|
1872
1902
|
const canvas = canvasRef.current;
|
|
1873
1903
|
if (!canvas) return;
|
|
1874
1904
|
const ctx = canvas.getContext("2d");
|
|
@@ -1930,7 +1960,7 @@ var AudioWaveVisualizer = ({
|
|
|
1930
1960
|
if (isPlaying && !isPaused) {
|
|
1931
1961
|
requestRef.current = requestAnimationFrame(draw);
|
|
1932
1962
|
}
|
|
1933
|
-
};
|
|
1963
|
+
}, [isPlaying, isPaused, frequencyData, timeDomainData, style, color, bars]);
|
|
1934
1964
|
(0, import_react5.useEffect)(() => {
|
|
1935
1965
|
if (isPlaying && !isPaused) {
|
|
1936
1966
|
requestRef.current = requestAnimationFrame(draw);
|
|
@@ -1947,26 +1977,36 @@ var AudioWaveVisualizer = ({
|
|
|
1947
1977
|
frequencyData,
|
|
1948
1978
|
timeDomainData,
|
|
1949
1979
|
style,
|
|
1950
|
-
color
|
|
1980
|
+
color,
|
|
1981
|
+
draw
|
|
1951
1982
|
]);
|
|
1983
|
+
const actualCanvasWidth = isWidthResponsive ? canvasWidth : width;
|
|
1984
|
+
const actualCanvasHeight = isHeightResponsive ? canvasHeight : height;
|
|
1952
1985
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1953
1986
|
"div",
|
|
1954
1987
|
{
|
|
1988
|
+
ref: containerRef,
|
|
1955
1989
|
className,
|
|
1956
1990
|
style: {
|
|
1957
1991
|
display: "inline-flex",
|
|
1958
1992
|
flexDirection: "column",
|
|
1959
1993
|
gap: "4px",
|
|
1960
|
-
width,
|
|
1994
|
+
width: isWidthResponsive ? width : width,
|
|
1995
|
+
height: isHeightResponsive ? height : height,
|
|
1961
1996
|
...styleObj
|
|
1962
1997
|
},
|
|
1963
1998
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1964
1999
|
"canvas",
|
|
1965
2000
|
{
|
|
1966
2001
|
ref: canvasRef,
|
|
1967
|
-
width,
|
|
1968
|
-
height,
|
|
1969
|
-
style: {
|
|
2002
|
+
width: actualCanvasWidth,
|
|
2003
|
+
height: actualCanvasHeight,
|
|
2004
|
+
style: {
|
|
2005
|
+
display: "block",
|
|
2006
|
+
// 响应式模式下,CSS 尺寸为 100%;固定模式下使用像素值
|
|
2007
|
+
width: isWidthResponsive ? "100%" : actualCanvasWidth,
|
|
2008
|
+
height: isHeightResponsive ? "100%" : actualCanvasHeight
|
|
2009
|
+
}
|
|
1970
2010
|
}
|
|
1971
2011
|
)
|
|
1972
2012
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1805,7 +1805,7 @@ function useStreamTTS({
|
|
|
1805
1805
|
}
|
|
1806
1806
|
|
|
1807
1807
|
// src/components/AudioWaveVisualizer.tsx
|
|
1808
|
-
import { useEffect as useEffect4, useRef as useRef5 } from "react";
|
|
1808
|
+
import { useEffect as useEffect4, useRef as useRef5, useState as useState5, useCallback as useCallback5 } from "react";
|
|
1809
1809
|
import { jsx } from "react/jsx-runtime";
|
|
1810
1810
|
var AudioWaveVisualizer = ({
|
|
1811
1811
|
isPlaying,
|
|
@@ -1821,10 +1821,40 @@ var AudioWaveVisualizer = ({
|
|
|
1821
1821
|
styleObj
|
|
1822
1822
|
}) => {
|
|
1823
1823
|
const canvasRef = useRef5(null);
|
|
1824
|
+
const containerRef = useRef5(null);
|
|
1824
1825
|
const requestRef = useRef5(null);
|
|
1826
|
+
const isWidthResponsive = typeof width === "string";
|
|
1827
|
+
const isHeightResponsive = typeof height === "string";
|
|
1828
|
+
const [canvasWidth, setCanvasWidth] = useState5(() => {
|
|
1829
|
+
return typeof width === "number" ? width : 200;
|
|
1830
|
+
});
|
|
1831
|
+
const [canvasHeight, setCanvasHeight] = useState5(() => {
|
|
1832
|
+
return typeof height === "number" ? height : 60;
|
|
1833
|
+
});
|
|
1834
|
+
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
1835
|
+
useEffect4(() => {
|
|
1836
|
+
if (!containerRef.current) return;
|
|
1837
|
+
if (!isWidthResponsive && !isHeightResponsive) return;
|
|
1838
|
+
const container = containerRef.current;
|
|
1839
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
1840
|
+
for (const entry of entries) {
|
|
1841
|
+
const { width: containerWidth, height: containerHeight } = entry.contentRect;
|
|
1842
|
+
if (isWidthResponsive) {
|
|
1843
|
+
setCanvasWidth(Math.floor(containerWidth * dpr));
|
|
1844
|
+
}
|
|
1845
|
+
if (isHeightResponsive) {
|
|
1846
|
+
setCanvasHeight(Math.floor(containerHeight * dpr));
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
});
|
|
1850
|
+
resizeObserver.observe(container);
|
|
1851
|
+
return () => {
|
|
1852
|
+
resizeObserver.disconnect();
|
|
1853
|
+
};
|
|
1854
|
+
}, [isWidthResponsive, isHeightResponsive, dpr]);
|
|
1825
1855
|
const progressBackground = Array.isArray(color) ? `linear-gradient(90deg, ${color[0]}, ${color[1]})` : color;
|
|
1826
1856
|
const textColor = Array.isArray(color) ? color[0] : color;
|
|
1827
|
-
const draw = () => {
|
|
1857
|
+
const draw = useCallback5(() => {
|
|
1828
1858
|
const canvas = canvasRef.current;
|
|
1829
1859
|
if (!canvas) return;
|
|
1830
1860
|
const ctx = canvas.getContext("2d");
|
|
@@ -1886,7 +1916,7 @@ var AudioWaveVisualizer = ({
|
|
|
1886
1916
|
if (isPlaying && !isPaused) {
|
|
1887
1917
|
requestRef.current = requestAnimationFrame(draw);
|
|
1888
1918
|
}
|
|
1889
|
-
};
|
|
1919
|
+
}, [isPlaying, isPaused, frequencyData, timeDomainData, style, color, bars]);
|
|
1890
1920
|
useEffect4(() => {
|
|
1891
1921
|
if (isPlaying && !isPaused) {
|
|
1892
1922
|
requestRef.current = requestAnimationFrame(draw);
|
|
@@ -1903,26 +1933,36 @@ var AudioWaveVisualizer = ({
|
|
|
1903
1933
|
frequencyData,
|
|
1904
1934
|
timeDomainData,
|
|
1905
1935
|
style,
|
|
1906
|
-
color
|
|
1936
|
+
color,
|
|
1937
|
+
draw
|
|
1907
1938
|
]);
|
|
1939
|
+
const actualCanvasWidth = isWidthResponsive ? canvasWidth : width;
|
|
1940
|
+
const actualCanvasHeight = isHeightResponsive ? canvasHeight : height;
|
|
1908
1941
|
return /* @__PURE__ */ jsx(
|
|
1909
1942
|
"div",
|
|
1910
1943
|
{
|
|
1944
|
+
ref: containerRef,
|
|
1911
1945
|
className,
|
|
1912
1946
|
style: {
|
|
1913
1947
|
display: "inline-flex",
|
|
1914
1948
|
flexDirection: "column",
|
|
1915
1949
|
gap: "4px",
|
|
1916
|
-
width,
|
|
1950
|
+
width: isWidthResponsive ? width : width,
|
|
1951
|
+
height: isHeightResponsive ? height : height,
|
|
1917
1952
|
...styleObj
|
|
1918
1953
|
},
|
|
1919
1954
|
children: /* @__PURE__ */ jsx(
|
|
1920
1955
|
"canvas",
|
|
1921
1956
|
{
|
|
1922
1957
|
ref: canvasRef,
|
|
1923
|
-
width,
|
|
1924
|
-
height,
|
|
1925
|
-
style: {
|
|
1958
|
+
width: actualCanvasWidth,
|
|
1959
|
+
height: actualCanvasHeight,
|
|
1960
|
+
style: {
|
|
1961
|
+
display: "block",
|
|
1962
|
+
// 响应式模式下,CSS 尺寸为 100%;固定模式下使用像素值
|
|
1963
|
+
width: isWidthResponsive ? "100%" : actualCanvasWidth,
|
|
1964
|
+
height: isHeightResponsive ? "100%" : actualCanvasHeight
|
|
1965
|
+
}
|
|
1926
1966
|
}
|
|
1927
1967
|
)
|
|
1928
1968
|
}
|