🎥 Make videos programmatically with React
copywriting and make all parameters mandatory
Jonny Burger869db0196129
diff --git a/packages/docs/docs/paths/translate-path.md b/packages/docs/docs/paths/translate-path.mdindex d95c92d3df..bf53658ecc 100644--- a/packages/docs/docs/paths/translate-path.md+++ b/packages/docs/docs/paths/translate-path.md@@ -6,37 +6,42 @@ crumb: "@remotion/paths"_Part of the [`@remotion/paths`](/docs/paths) package._-Translates the X or Y coordinates of the path+Translates the path by the given `x` and `y` coordinates.- The function takes three arguments:+## Arguments-- `path`, string SVG paths coordinates.-- `x`, a number representing path x coordinate-- `y`, `optional` a number representing path y coordinate+The function takes three arguments:+- `path`, the original SVG path.+- `x`, the amount of horizontal translation.+- `y` the amount of vertical translation.-Returns a SVG path string if the path is valid:+## Return value-```tsx twoslash title='Translate path x coordinates'+Returns a new `string` containing a path if it is valid:++```tsx twoslash title='translate-x.ts'import { translatePath } from "@remotion/paths";-const translatedPath = translatePath("M 50 50 L 150 50", 10);+const translatedPath = translatePath("M 50 50 L 150 50", 10, 0);console.log(translatedPath); // "M 50 50 L 150 50"```--```tsx twoslash title='Translate path x and y coordinates'+```tsx twoslash title='translate-y.ts'import { translatePath } from "@remotion/paths";-const translatedPath = translatePath('M10 10 L15 15', 10, 10);+const translatedPath = translatePath("M10 10 L15 15", 10, 10);console.log(translatedPath); // "M 20,20 L 25,25"```--```tsx twoslash title='Translate circle path x and y coordinates'+```tsx twoslash title='translate-x-and-y.ts'import { translatePath } from "@remotion/paths";-const translatedPath = translatePath('M 35,50 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0', 10, 20);+const translatedPath = translatePath(+ "M 35,50 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0",+ 10,+ 20+);console.log(translatedPath); // "M 45,70 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0"```diff --git a/packages/paths/src/test/translate-path.test.ts b/packages/paths/src/test/translate-path.test.tsindex 134fe1ce05..fa3426e854 100644--- a/packages/paths/src/test/translate-path.test.ts+++ b/packages/paths/src/test/translate-path.test.ts@@ -2,7 +2,7 @@ import {expect, test} from 'vitest';import {translatePath} from '../translate-path';test('Should be able to translate simple path, update x', () => {- const path = translatePath('M10 10 L15 15', 10);+ const path = translatePath('M10 10 L15 15', 10, 0);expect(path).toEqual('M 20,10 L 25,15');});@@ -16,7 +16,8 @@ test('Should be able to translate simple path, update x and y', () => {test('Should be able to translate circle path, update x', () => {const path = translatePath('M 35,50 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0',- 10+ 10,+ 0);expect(path).toEqual('M 45,50 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0');@@ -33,13 +34,13 @@ test('Should be able to translate circle path, update x and y', () => {});test('Should be able to translate example path, update x', () => {- const path = translatePath('M 50 50 L 150 50', 10);+ const path = translatePath('M 50 50 L 150 50', 10, 0);expect(path).toEqual('M 60,50 L 160,50');});test('Translation should throw error', () => {expect(() => {- translatePath('remotion', 10);+ translatePath('remotion', 10, 0);}).toThrow('Malformed path data: "m" must have 2 elements and has 0: mo');});diff --git a/packages/paths/src/translate-path.ts b/packages/paths/src/translate-path.tsindex 122fae9a0c..c8468c8655 100644--- a/packages/paths/src/translate-path.ts+++ b/packages/paths/src/translate-path.ts@@ -8,11 +8,11 @@ const serialize = (path: (Instruction | number[])[]) => {}, '');};-const translateSegments = (path: string, x: number, y?: number) => {+const translateSegments = (path: string, x: number, y: number) => {const segments = parsePath(path);return segments.map((segment) => {- const cmd = segment[0] as string;+ const cmd = segment[0];// Shift coords only for commands with absolute valuesif ('ACHLMRQSTVZ'.indexOf(cmd) === -1) {@@ -46,6 +46,6 @@ const translateSegments = (path: string, x: number, y?: number) => {});};-export const translatePath = (path: string, x: number, y?: number) => {+export const translatePath = (path: string, x: number, y: number) => {return serialize(translateSegments(path, x, y));};