Skip to main content

getLength()

属于 @remotion/paths 包。

获取 SVG 路径的长度。参数必须是有效的 SVG 路径属性。

如果路径有效,则返回一个数字:

tsx
import { getLength } from "@remotion/paths";
 
const length = getLength("M 0 0 L 100 0");
console.log(length); // 100
tsx
import { getLength } from "@remotion/paths";
 
const length = getLength("M 0 0 L 100 0");
console.log(length); // 100

如果路径无效,该函数将抛出错误:

tsx
getLength("remotion"); // Error: Malformed path data: ...
tsx
getLength("remotion"); // Error: Malformed path data: ...

Credits

源代码主要来自 svg-path-properties

另请参阅