@remotion/paths 4.0.178 → 4.0.180

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/paths"
4
4
  },
5
5
  "name": "@remotion/paths",
6
- "version": "4.0.178",
6
+ "version": "4.0.180",
7
7
  "description": "Utilities for working with SVG paths",
8
8
  "main": "dist/index.js",
9
9
  "sideEffects": false,
@@ -1 +0,0 @@
1
- export declare function arrayOfLength<T>(length: number, value: T): T[];
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.arrayOfLength = void 0;
4
- function arrayOfLength(length, value) {
5
- const array = Array(length);
6
- for (let i = 0; i < length; i++) {
7
- array[i] = value;
8
- }
9
- return array;
10
- }
11
- exports.arrayOfLength = arrayOfLength;
@@ -1,7 +0,0 @@
1
- import type { Command } from './command';
2
- /**
3
- * Converts a command object to a string to be used in a `d` attribute
4
- * @param {Object} command A command object
5
- * @return {String} The string for the `d` attribute
6
- */
7
- export declare function commandToString(command: Command): string;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commandToString = void 0;
4
- const command_1 = require("./command");
5
- /**
6
- * Converts a command object to a string to be used in a `d` attribute
7
- * @param {Object} command A command object
8
- * @return {String} The string for the `d` attribute
9
- */
10
- function commandToString(command) {
11
- return `${command.type} ${command_1.typeMap[command.type]
12
- .map((p) => command[p])
13
- .join(' ')}`;
14
- }
15
- exports.commandToString = commandToString;
@@ -1,37 +0,0 @@
1
- /**
2
- * List of params for each command type in a path `d` attribute
3
- */
4
- export declare const typeMap: {
5
- M: string[];
6
- L: string[];
7
- H: string[];
8
- V: string[];
9
- C: string[];
10
- S: string[];
11
- Q: string[];
12
- T: string[];
13
- A: string[];
14
- Z: never[];
15
- m: string[];
16
- l: string[];
17
- h: string[];
18
- v: string[];
19
- c: string[];
20
- s: string[];
21
- q: string[];
22
- t: string[];
23
- a: string[];
24
- z: never[];
25
- };
26
- export type Command = {
27
- x2?: number | undefined;
28
- y2?: number | undefined;
29
- x1?: number | undefined;
30
- y1?: number | undefined;
31
- x?: number;
32
- y?: number;
33
- xAxisRotate?: number;
34
- largeArcFlag?: boolean;
35
- sweepFlag?: boolean;
36
- type: keyof typeof typeMap;
37
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typeMap = void 0;
4
- /**
5
- * List of params for each command type in a path `d` attribute
6
- */
7
- exports.typeMap = {
8
- M: ['x', 'y'],
9
- L: ['x', 'y'],
10
- H: ['x'],
11
- V: ['y'],
12
- C: ['x1', 'y1', 'x2', 'y2', 'x', 'y'],
13
- S: ['x2', 'y2', 'x', 'y'],
14
- Q: ['x1', 'y1', 'x', 'y'],
15
- T: ['x', 'y'],
16
- A: ['rx', 'ry', 'xAxisRotation', 'largeArcFlag', 'sweepFlag', 'x', 'y'],
17
- Z: [],
18
- m: ['x', 'y'],
19
- l: ['x', 'y'],
20
- h: ['x'],
21
- v: ['y'],
22
- c: ['x1', 'y1', 'x2', 'y2', 'x', 'y'],
23
- s: ['x2', 'y2', 'x', 'y'],
24
- q: ['x1', 'y1', 'x', 'y'],
25
- t: ['x', 'y'],
26
- a: ['rx', 'ry', 'xAxisRotation', 'largeArcFlag', 'sweepFlag', 'x', 'y'],
27
- z: [],
28
- };
@@ -1,22 +0,0 @@
1
- import type { Command } from './command';
2
- /**
3
- * Converts command A to have the same type as command B.
4
- *
5
- * e.g., L0,5 -> C0,5,0,5,0,5
6
- *
7
- * Uses these rules:
8
- * x1 <- x
9
- * x2 <- x
10
- * y1 <- y
11
- * y2 <- y
12
- * rx <- 0
13
- * ry <- 0
14
- * xAxisRotation <- read from B
15
- * largeArcFlag <- read from B
16
- * sweepflag <- read from B
17
- *
18
- * @param {Object} aCommand Command object from path `d` attribute
19
- * @param {Object} bCommand Command object from path `d` attribute to match against
20
- * @return {Object} aCommand converted to type of bCommand
21
- */
22
- export declare function convertToSameType(aCommand: Command, bCommand: Command): Command;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToSameType = void 0;
4
- /**
5
- * Converts command A to have the same type as command B.
6
- *
7
- * e.g., L0,5 -> C0,5,0,5,0,5
8
- *
9
- * Uses these rules:
10
- * x1 <- x
11
- * x2 <- x
12
- * y1 <- y
13
- * y2 <- y
14
- * rx <- 0
15
- * ry <- 0
16
- * xAxisRotation <- read from B
17
- * largeArcFlag <- read from B
18
- * sweepflag <- read from B
19
- *
20
- * @param {Object} aCommand Command object from path `d` attribute
21
- * @param {Object} bCommand Command object from path `d` attribute to match against
22
- * @return {Object} aCommand converted to type of bCommand
23
- */
24
- function convertToSameType(aCommand, bCommand) {
25
- const conversionMap = {
26
- x1: 'x',
27
- y1: 'y',
28
- x2: 'x',
29
- y2: 'y',
30
- };
31
- const readFromBKeys = ['xAxisRotation', 'largeArcFlag', 'sweepFlag'];
32
- // convert (but ignore M types)
33
- if (aCommand.type !== bCommand.type && bCommand.type.toUpperCase() !== 'M') {
34
- const aConverted = {
35
- type: bCommand.type,
36
- };
37
- Object.keys(bCommand).forEach((bKey) => {
38
- const bValue = bCommand[bKey];
39
- // first read from the A command
40
- let aValue = aCommand[bKey];
41
- // if it is one of these values, read from B no matter what
42
- if (aValue === undefined) {
43
- if (readFromBKeys.includes(bKey)) {
44
- aValue = bValue;
45
- }
46
- else {
47
- // if it wasn't in the A command, see if an equivalent was
48
- if (aValue === undefined &&
49
- conversionMap[bKey]) {
50
- aValue =
51
- aCommand[conversionMap[bKey]];
52
- }
53
- // if it doesn't have a converted value, use 0
54
- if (aValue === undefined) {
55
- aValue = 0;
56
- }
57
- }
58
- }
59
- // @ts-expect-error
60
- aConverted[bKey] = aValue;
61
- });
62
- // update the type to match B
63
- aConverted.type = bCommand.type;
64
- aCommand = aConverted;
65
- }
66
- return aCommand;
67
- }
68
- exports.convertToSameType = convertToSameType;
@@ -1,16 +0,0 @@
1
- import { type Command } from './command';
2
- /**
3
- * Interpolate from A to B by extending A and B during interpolation to have
4
- * the same number of points. This allows for a smooth transition when they
5
- * have a different number of points.
6
- *
7
- * Ignores the `Z` command in paths unless both A and B end with it.
8
- *
9
- * This function works directly with arrays of command objects instead of with
10
- * path `d` strings (see interpolatePath for working with `d` strings).
11
- *
12
- * @param {Object[]} aCommandsInput Array of path commands
13
- * @param {Object[]} bCommandsInput Array of path commands
14
- * @returns {Function} Interpolation function that maps t ([0, 1]) to an array of path commands.
15
- */
16
- export declare function interpolatePathCommands(aCommandsInput: Command[], bCommandsInput: Command[]): (t: number) => Command[];
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.interpolatePathCommands = void 0;
4
- const command_1 = require("./command");
5
- const convert_to_same_type_1 = require("./convert-to-same-type");
6
- const extend_command_1 = require("./extend-command");
7
- /**
8
- * Interpolate from A to B by extending A and B during interpolation to have
9
- * the same number of points. This allows for a smooth transition when they
10
- * have a different number of points.
11
- *
12
- * Ignores the `Z` command in paths unless both A and B end with it.
13
- *
14
- * This function works directly with arrays of command objects instead of with
15
- * path `d` strings (see interpolatePath for working with `d` strings).
16
- *
17
- * @param {Object[]} aCommandsInput Array of path commands
18
- * @param {Object[]} bCommandsInput Array of path commands
19
- * @returns {Function} Interpolation function that maps t ([0, 1]) to an array of path commands.
20
- */
21
- function interpolatePathCommands(aCommandsInput, bCommandsInput) {
22
- // make a copy so we don't mess with the input arrays
23
- let aCommands = aCommandsInput === null || aCommandsInput === undefined
24
- ? []
25
- : aCommandsInput.slice();
26
- let bCommands = bCommandsInput === null || bCommandsInput === undefined
27
- ? []
28
- : bCommandsInput.slice();
29
- // both input sets are empty, so we don't interpolate
30
- if (!aCommands.length && !bCommands.length) {
31
- return function () {
32
- return [];
33
- };
34
- }
35
- // do we add Z during interpolation? yes if both have it. (we'd expect both to have it or not)
36
- const addZ = (aCommands.length === 0 || aCommands[aCommands.length - 1].type === 'Z') &&
37
- (bCommands.length === 0 || bCommands[bCommands.length - 1].type === 'Z');
38
- // we temporarily remove Z
39
- if (aCommands.length > 0 && aCommands[aCommands.length - 1].type === 'Z') {
40
- aCommands.pop();
41
- }
42
- if (bCommands.length > 0 && bCommands[bCommands.length - 1].type === 'Z') {
43
- bCommands.pop();
44
- }
45
- // if A is empty, treat it as if it used to contain just the first point
46
- // of B. This makes it so the line extends out of from that first point.
47
- if (!aCommands.length) {
48
- aCommands.push(bCommands[0]);
49
- // otherwise if B is empty, treat it as if it contains the first point
50
- // of A. This makes it so the line retracts into the first point.
51
- }
52
- else if (!bCommands.length) {
53
- bCommands.push(aCommands[0]);
54
- }
55
- // extend to match equal size
56
- const numPointsToExtend = Math.abs(bCommands.length - aCommands.length);
57
- if (numPointsToExtend !== 0) {
58
- // B has more points than A, so add points to A before interpolating
59
- if (bCommands.length > aCommands.length) {
60
- aCommands = (0, extend_command_1.extend)(aCommands, bCommands);
61
- // else if A has more points than B, add more points to B
62
- }
63
- else if (bCommands.length < aCommands.length) {
64
- bCommands = (0, extend_command_1.extend)(bCommands, aCommands);
65
- }
66
- }
67
- // commands have same length now.
68
- // convert commands in A to the same type as those in B
69
- aCommands = aCommands.map((aCommand, i) => (0, convert_to_same_type_1.convertToSameType)(aCommand, bCommands[i]));
70
- // create mutable interpolated command objects
71
- const interpolatedCommands = aCommands.map((aCommand) => ({ ...aCommand }));
72
- if (addZ) {
73
- interpolatedCommands.push({ type: 'Z' });
74
- aCommands.push({ type: 'Z' }); // required for when returning at t == 0
75
- }
76
- return function (t) {
77
- // at 1 return the final value without the extensions used during interpolation
78
- if (t === 1) {
79
- return bCommandsInput === null || bCommandsInput === undefined
80
- ? []
81
- : bCommandsInput;
82
- }
83
- // work with aCommands directly since interpolatedCommands are mutated
84
- if (t === 0) {
85
- return aCommands;
86
- }
87
- // interpolate the commands using the mutable interpolated command objs
88
- for (let i = 0; i < interpolatedCommands.length; ++i) {
89
- // if (interpolatedCommands[i].type === 'Z') continue;
90
- const aCommand = aCommands[i];
91
- const bCommand = bCommands[i];
92
- const interpolatedCommand = interpolatedCommands[i];
93
- for (const arg of command_1.typeMap[interpolatedCommand.type]) {
94
- // @ts-expect-error
95
- interpolatedCommand[arg] =
96
- (1 - t) * aCommand[arg] +
97
- t * bCommand[arg];
98
- // do not use floats for flags (#27), round to integer
99
- if (arg === 'largeArcFlag' || arg === 'sweepFlag') {
100
- // @ts-expect-error
101
- interpolatedCommand[arg] = Math.round(interpolatedCommand[arg]);
102
- }
103
- }
104
- }
105
- return interpolatedCommands;
106
- };
107
- }
108
- exports.interpolatePathCommands = interpolatePathCommands;
@@ -1,8 +0,0 @@
1
- import { type Command } from './command';
2
- /**
3
- * Takes a path `d` string and converts it into an array of command
4
- * objects. Drops the `Z` character.
5
- *
6
- * @param {String|null} d A path `d` string
7
- */
8
- export declare function pathCommandsFromString(d: string | null): Command[];
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pathCommandsFromString = void 0;
4
- const command_1 = require("./command");
5
- const commandTokenRegex = /[MLCSTQAHVZmlcstqahv]|-?[\d.e+-]+/g;
6
- /**
7
- * Takes a path `d` string and converts it into an array of command
8
- * objects. Drops the `Z` character.
9
- *
10
- * @param {String|null} d A path `d` string
11
- */
12
- function pathCommandsFromString(d) {
13
- // split into valid tokens
14
- const tokens = (d || '').match(commandTokenRegex) || [];
15
- const commands = [];
16
- let commandArgs;
17
- let command;
18
- // iterate over each token, checking if we are at a new command
19
- // by presence in the typeMap
20
- for (let i = 0; i < tokens.length; ++i) {
21
- commandArgs = command_1.typeMap[tokens[i]];
22
- // new command found:
23
- if (commandArgs) {
24
- command = {
25
- type: tokens[i],
26
- };
27
- // add each of the expected args for this command:
28
- for (let a = 0; a < commandArgs.length; ++a) {
29
- // @ts-expect-error
30
- command[commandArgs[a]] = Number(tokens[i + a + 1]);
31
- }
32
- // need to increment our token index appropriately since
33
- // we consumed token args
34
- i += commandArgs.length;
35
- commands.push(command);
36
- }
37
- }
38
- return commands;
39
- }
40
- exports.pathCommandsFromString = pathCommandsFromString;