Skip to content

🎥 Make videos programmatically with React

@remotion/paths package

Jonny Burger721e07d25712
diff --git a/packages/docs/docs/paths/get-parts.md b/packages/docs/docs/paths/get-parts.md
index 706a0570cc..41374b7ce8 100644
--- a/packages/docs/docs/paths/get-parts.md
+++ b/packages/docs/docs/paths/get-parts.md
@@ -102,7 +102,7 @@ console.log(parts[0].getPointAtLength(50)); // { x: 50, y: 0 }
### `getTangentAtLength()`
-Returns `tangentX` and `tangentY` of a point along the line of a part. The input must be between `0` and `length`.
+Returns tagent point `x` and `y` of a point along the line of a part. The input must be between `0` and the return value of [`getLength`](/docs/paths/get-length).
```tsx twoslash
import { getParts } from "@remotion/paths";
@@ -113,5 +113,5 @@ const parts = getParts(`
`);
// ---cut---
-console.log(parts[0].getTangentAtLength(50)); // { tangentX: 1, tangentY: 0 }
+console.log(parts[0].getTangentAtLength(50)); // { x: 1, y: 0 }
```
diff --git a/packages/docs/docs/paths/get-tangent-at-length.md b/packages/docs/docs/paths/get-tangent-at-length.md
new file mode 100644
index 0000000000..53fd016349
--- /dev/null
+++ b/packages/docs/docs/paths/get-tangent-at-length.md
@@ -0,0 +1,24 @@
+---
+title: getTangentAtLength()
+---
+
+_Part of the [`@remotion/paths`](/docs/paths) package._
+
+Gets tangent values `x` and `y` of a point which is on an SVG path. The first argument is an SVG path, the second one is the at which length the point should be sampled. It must be between 0 and the return value of [`getLength()`](/docs/paths/get-length).
+
+Returns a point if the path is valid:
+
+```tsx twoslash
+import { getTangentAtLength } from "@remotion/paths";
+
+const tangent = getTangentAtLength("M 50 50 L 150 50", 50);
+console.log(tangent); // { x: 1, y: 0}
+```
+
+The function will throw if the path is invalid:
+
+```tsx twoslash
+import { getTangentAtLength } from "@remotion/paths";
+// ---cut---
+getTangentAtLength("remotion", 50); // Error: Malformed path data: ...
+```
diff --git a/packages/docs/docs/paths/index.md b/packages/docs/docs/paths/index.md
index 1a319b2873..85b189ec2a 100644
--- a/packages/docs/docs/paths/index.md
+++ b/packages/docs/docs/paths/index.md
@@ -46,3 +46,12 @@ yarn add @remotion/paths
</TabItem>
</Tabs>
+
+## Functions
+
+- [`getLength()`](/docs/paths/get-length)
+- [`getParts()`](/docs/paths/get-parts)
+- [`getPointAtLength()`](/docs/paths/get-point-at-length)
+- [`reversePath()`](/docs/paths/reverse-path)
+- [`normalizePath()`](/docs/paths/normalize-path)
+- [`getTangentAtLength()`](/docs/paths/get-tangent-at-length)
diff --git a/packages/docs/docs/paths/normalize-path.md b/packages/docs/docs/paths/normalize-path.md
new file mode 100644
index 0000000000..4fdf09bc14
--- /dev/null
+++ b/packages/docs/docs/paths/normalize-path.md
@@ -0,0 +1,24 @@
+---
+title: normalizePath()
+---
+
+_Part of the [`@remotion/paths`](/docs/paths) package._
+
+Removes all relative coordinates from a path and converts them into absolute coordinates.
+
+Returns a string if the path is valid:
+
+```tsx twoslash
+import { normalizePath } from "@remotion/paths";
+
+const reversedPath = normalizePath("M 50 50 L 150 50");
+console.log(reversedPath); // "M 50 50 L 150 50"
+```
+
+The function will throw if the path is invalid:
+
+```tsx twoslash
+import { normalizePath } from "@remotion/paths";
+// ---cut---
+normalizePath("remotion"); // Error: Malformed path data: ...
+```
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index b0047f06eb..dd7b4edce3 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -287,6 +287,8 @@ module.exports = {
"paths/get-parts",
"paths/get-point-at-length",
"paths/reverse-path",
+ "paths/normalize-path",
+ "paths/get-tangent-at-length",
],
},
{
diff --git a/packages/paths/src/index.ts b/packages/paths/src/index.ts
index eb3781c21a..f8170b6535 100644
--- a/packages/paths/src/index.ts
+++ b/packages/paths/src/index.ts
@@ -1,7 +1,7 @@
export {getLength} from './get-length';
export {getParts} from './get-parts';
export {getPointAtLength} from './get-point-at-length';
-export {reversePath} from './get-reversed-path';
export {getTangentAtLength} from './get-tangent-at-length';
export {Part} from './helpers/types';
export {normalizePath} from './normalize-path';
+export {reversePath} from './reverse-path';
diff --git a/packages/paths/src/test/get-tangent-at-length.test.ts b/packages/paths/src/test/get-tangent-at-length.test.ts
new file mode 100644
index 0000000000..956e16877e
--- /dev/null
+++ b/packages/paths/src/test/get-tangent-at-length.test.ts
@@ -0,0 +1,8 @@
+import {expect, test} from 'vitest';
+import {getTangentAtLength} from '../get-tangent-at-length';
+
+test('Should be able to get parts of a path', () => {
+ const parts = getTangentAtLength('M 0 0 L 100 0', 50);
+
+ expect(parts).toEqual({x: 1, y: 0});
+});
diff --git a/packages/paths/src/test/normalize-path.test.ts b/packages/paths/src/test/normalize-path.test.ts
new file mode 100644
index 0000000000..971de6ca61
--- /dev/null
+++ b/packages/paths/src/test/normalize-path.test.ts
@@ -0,0 +1,9 @@
+import {expect, test} from 'vitest';
+import {normalizePath} from '../normalize-path';
+
+test('Should be able to normalize a path', () => {
+ const reversedPath = normalizePath(`
+ M 50 50 l 100 0
+ `);
+ expect(reversedPath).toEqual('M 50 50 L 150 50');
+});