🎥 Make videos programmatically with React
add JSDoc comments
Jonny Burger60b08c18bdb0
diff --git a/packages/paths/src/get-length.ts b/packages/paths/src/get-length.tsindex e7f12b2751..f7d15aaab4 100644--- a/packages/paths/src/get-length.ts+++ b/packages/paths/src/get-length.ts@@ -2,7 +2,12 @@import {construct} from './helpers/construct';-export const getLength = (p: string) => {- const constructucted = construct(p);+/**+ * Gets the length of an SVG path.+ * @param {string} path A valid SVG path+ * @link https://remotion.dev/docs/paths/get-length+ */+export const getLength = (path: string) => {+ const constructucted = construct(path);return constructucted.length;};diff --git a/packages/paths/src/get-parts.ts b/packages/paths/src/get-parts.tsindex 0a94068125..78356dc6fe 100644--- a/packages/paths/src/get-parts.ts+++ b/packages/paths/src/get-parts.ts@@ -1,9 +1,14 @@import {construct} from './helpers/construct';import type {Part} from './helpers/types';-export const getParts = (p: string): Part[] => {+/**+ * Splits a valid SVG path into it's parts.+ * @param {string} path A valid SVG path+ * @link https://remotion.dev/docs/paths/get-parts+ */+export const getParts = (path: string): Part[] => {const parts = [];- const constructed = construct(p);+ const constructed = construct(path);let i = 0;for (const fn of constructed.functions) {diff --git a/packages/paths/src/get-point-at-length.ts b/packages/paths/src/get-point-at-length.tsindex c738353be6..97f5b9b382 100644--- a/packages/paths/src/get-point-at-length.ts+++ b/packages/paths/src/get-point-at-length.ts@@ -1,9 +1,15 @@import {construct} from './helpers/construct';import {getPartAtLength} from './helpers/get-part-at-length';-export const getPointAtLength = (p: string, fractionLength: number) => {- const constructed = construct(p);- const fractionPart = getPartAtLength(p, fractionLength);+/**+ * Gets the coordinates of a point which is on an SVG path.+ * @param {string} path A valid SVG path+ * @param {number} length The length at which the point should be sampled+ * @link https://remotion.dev/docs/paths/get-point-at-length+ */+export const getPointAtLength = (path: string, length: number) => {+ const constructed = construct(path);+ const fractionPart = getPartAtLength(path, length);const functionAtPart = constructed.functions[fractionPart.i];if (functionAtPart) {diff --git a/packages/paths/src/get-tangent-at-length.ts b/packages/paths/src/get-tangent-at-length.tsindex 73eba222d6..23cfe8273e 100644--- a/packages/paths/src/get-tangent-at-length.ts+++ b/packages/paths/src/get-tangent-at-length.ts@@ -1,10 +1,16 @@import {construct} from './helpers/construct';import {getPartAtLength} from './helpers/get-part-at-length';-export const getTangentAtLength = (p: string, fractionLength: number) => {- const constructed = construct(p);+/**+ * Gets tangent values x and y of a point which is on an SVG path+ * @param {string} path A valid SVG path+ * @param {number} length The length at which the tangent should be sampled+ * @link https://remotion.dev/docs/paths/get-tangent-at-length+ */+export const getTangentAtLength = (path: string, length: number) => {+ const constructed = construct(path);- const fractionPart = getPartAtLength(p, fractionLength);+ const fractionPart = getPartAtLength(path, length);const functionAtPart = constructed.functions[fractionPart.i];if (functionAtPart) {return functionAtPart.getTangentAtLength(fractionPart.fraction);diff --git a/packages/paths/src/interpolate-path.ts b/packages/paths/src/interpolate-path.tsindex 84e8aa91d1..e384ce0369 100644--- a/packages/paths/src/interpolate-path.ts+++ b/packages/paths/src/interpolate-path.ts@@ -418,34 +418,34 @@ function interpolatePathCommands(}/**- * Interpolate from A to B by extending A and B during interpolation to have- * the same number of points. This allows for a smooth transition when they- * have a different number of points.- *- * Ignores the `Z` character in paths unless both A and B end with it.- *- * @param {String} a The `d` attribute for a path- * @param {String} b The `d` attribute for a path- * @returns {Function} Interpolation function that maps t ([0, 1]) to a path `d` string.+ * Interpolates between two SVG paths.+ * @param {number} value A number - 0 means first path, 1 means second path, any other values will be interpolated+ * @param {string} firstPath The first valid SVG path+ * @param {string} secondPath The second valid SVG path+ * @link https://remotion.dev/docs/paths/interpolate-path*/-export const interpolatePath = (value: number, a: string, b: string) => {+export const interpolatePath = (+ value: number,+ firstPath: string,+ secondPath: string+) => {// at 1 return the final value without the extensions used during interpolationif (value === 1) {- return b;+ return secondPath;}if (value === 0) {- return a;+ return firstPath;}- const aCommands = pathCommandsFromString(a);+ const aCommands = pathCommandsFromString(firstPath);if (aCommands.length === 0) {- throw new TypeError(`SVG Path "${a}" is not valid`);+ throw new TypeError(`SVG Path "${firstPath}" is not valid`);}- const bCommands = pathCommandsFromString(b);+ const bCommands = pathCommandsFromString(secondPath);if (bCommands.length === 0) {- throw new TypeError(`SVG Path "${b}" is not valid`);+ throw new TypeError(`SVG Path "${secondPath}" is not valid`);}const commandInterpolator = interpolatePathCommands(aCommands, bCommands);diff --git a/packages/paths/src/normalize-path.ts b/packages/paths/src/normalize-path.tsindex ef8b4272f4..8eae08df55 100644--- a/packages/paths/src/normalize-path.ts+++ b/packages/paths/src/normalize-path.ts@@ -1,13 +1,18 @@-export const normalizePath = (d: string) => {+/**+ * Removes all relative coordinates from an SVG path and converts them into absolute coordinates.+ * @param {string} path A valid SVG path+ * @link https://remotion.dev/docs/paths/normalize-path+ */+export const normalizePath = (path: string) => {// preprocess "d" so that we have spaces between values- d = d+ path = path.replace(/,/g, ' ').replace(/([^eE])-/g, '$1 -').replace(/\s*([achlmqstvzACHLMQSTVZ])\s*/g, ' $1 ').replace(/\s+/g, ' ');// set up the variables used in this function- const instructions = d+ const instructions = path.replace(/([achlmqstvzACHLMQSTVZ])\s?/g, '|$1').split('|');const instructionLength = instructions.length;diff --git a/packages/paths/src/reverse-path.ts b/packages/paths/src/reverse-path.tsindex 7d0370873b..56f41c4860 100644--- a/packages/paths/src/reverse-path.ts+++ b/packages/paths/src/reverse-path.ts@@ -137,31 +137,20 @@ function reverseNormalizedPath(normalized: string) {}/**- * This is the function that you'll actually want to- * make use of, because it lets you reverse individual- * subpaths in some <path> "d" attribute.+ * Reverses a path so the end and start are switched.+ * @param {string} path A valid SVG path+ * @link https://remotion.dev/docs/paths/reverse-path*/-export const reversePath = (_path: string, _subpath?: number) => {- const subpath = _subpath ?? false;- const path = normalizePath(_path);- let paths = path.replace(/M/g, '|M').split('|');- let revpath;+export const reversePath = (path: string) => {+ const normalizedPath = normalizePath(path);+ const paths = normalizedPath.replace(/M/g, '|M').split('|');paths.splice(0, 1);- if (subpath !== false && subpath >= paths.length) {- return path;- }- if (subpath === false) {- paths = paths.map((spath) => {+ return paths+ .map((spath) => {return reverseNormalizedPath(spath.trim());- });- } else {- const spath = paths[subpath];- if (spath) {- revpath = reverseNormalizedPath(spath.trim());- paths[subpath] = revpath;- }- }-- return paths.join(' ').replace(/ +/g, ' ').trim();+ })+ .join(' ')+ .replace(/ +/g, ' ')+ .trim();};