translatePath()
Part of the @remotion/paths package.
Translates the path by the given x and y coordinates.
Arguments
The function takes three arguments:
path
The original SVG path.
x
The amount of horizontal translation.
y
The amount of vertical translation.
Return value
Returns a new string containing a path if it is valid:
translate-x.tsimport {translatePath } from "@remotion/paths"; consttranslatedPath =translatePath ("M 50 50 L 150 50", 10, 0);console .log (translatedPath ); // "M 60 50 L 160 50"
translate-y.tsimport {translatePath } from "@remotion/paths"; consttranslatedPath =translatePath ("M10 10 L15 15", 0, 10);console .log (translatedPath ); // "M 10 20 L 15 25"
translate-x-and-y.tsimport {translatePath } from "@remotion/paths"; consttranslatedPath =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"
The function will throw if the path is invalid:
translatePath ("remotion", 10, 0); // Error: Malformed path data: m was expected to have numbers afterwardsCredits
Source code stems mostly from translate-svg-path and serialize-svg-path.
Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||