@remotion/paths 3.3.79 → 3.3.81
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/dist/get-subpaths.js +3 -1
- package/dist/helpers/construct.d.ts +7 -0
- package/dist/helpers/construct.js +13 -9
- package/dist/reverse-path.js +66 -116
- package/package.json +1 -1
package/dist/get-subpaths.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSubpaths = void 0;
|
|
4
4
|
const construct_1 = require("./helpers/construct");
|
|
5
|
+
const parse_path_1 = require("./parse-path");
|
|
5
6
|
const serialize_instructions_1 = require("./serialize-instructions");
|
|
6
7
|
/**
|
|
7
8
|
* @description Splits a valid SVG path into it's parts.
|
|
@@ -9,7 +10,8 @@ const serialize_instructions_1 = require("./serialize-instructions");
|
|
|
9
10
|
* @see [Documentation](https://remotion.dev/docs/paths/get-subpaths)
|
|
10
11
|
*/
|
|
11
12
|
const getSubpaths = (path) => {
|
|
12
|
-
const
|
|
13
|
+
const parsed = (0, parse_path_1.parsePath)(path);
|
|
14
|
+
const { segments } = (0, construct_1.constructFromInstructions)(parsed);
|
|
13
15
|
return segments.map((seg) => {
|
|
14
16
|
return (0, serialize_instructions_1.serializeInstructions)(seg);
|
|
15
17
|
});
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { Instruction, Point, Properties } from './types';
|
|
2
|
+
export declare const constructFromInstructions: (instructions: Instruction[]) => {
|
|
3
|
+
segments: Instruction[][];
|
|
4
|
+
initial_point: Point | null;
|
|
5
|
+
length: number;
|
|
6
|
+
partial_lengths: number[];
|
|
7
|
+
functions: (Properties | null)[];
|
|
8
|
+
};
|
|
2
9
|
export declare const construct: (string: string) => {
|
|
3
10
|
segments: Instruction[][];
|
|
4
11
|
initial_point: Point | null;
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copied from: https://github.com/rveciana/svg-path-properties
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.construct = void 0;
|
|
4
|
+
exports.construct = exports.constructFromInstructions = void 0;
|
|
5
5
|
const parse_path_1 = require("../parse-path");
|
|
6
6
|
const arc_1 = require("./arc");
|
|
7
7
|
const bezier_1 = require("./bezier");
|
|
8
8
|
const linear_1 = require("./linear");
|
|
9
|
-
const
|
|
9
|
+
const constructFromInstructions = (instructions) => {
|
|
10
10
|
let length = 0;
|
|
11
11
|
const partial_lengths = [];
|
|
12
12
|
const functions = [];
|
|
13
13
|
let initial_point = null;
|
|
14
|
-
const parsed = (0, parse_path_1.parsePath)(string);
|
|
15
14
|
let cur = [0, 0];
|
|
16
15
|
let prev_point = [0, 0];
|
|
17
16
|
let curve;
|
|
18
17
|
let ringStart = [0, 0];
|
|
19
18
|
const segments = [];
|
|
20
|
-
for (let i = 0; i <
|
|
21
|
-
const instruction =
|
|
19
|
+
for (let i = 0; i < instructions.length; i++) {
|
|
20
|
+
const instruction = instructions[i];
|
|
22
21
|
if (instruction.type !== 'm' &&
|
|
23
22
|
instruction.type !== 'M' &&
|
|
24
23
|
segments.length > 0) {
|
|
@@ -149,7 +148,7 @@ const construct = (string) => {
|
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
150
|
else if (instruction.type === 'S') {
|
|
152
|
-
const prev =
|
|
151
|
+
const prev = instructions[i - 1];
|
|
153
152
|
const prevWasCurve = prev.type === 'C' ||
|
|
154
153
|
prev.type === 'c' ||
|
|
155
154
|
prev.type === 'S' ||
|
|
@@ -188,7 +187,7 @@ const construct = (string) => {
|
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
189
|
else if (instruction.type === 's') {
|
|
191
|
-
const prev =
|
|
190
|
+
const prev = instructions[i - 1];
|
|
192
191
|
const prevWasCurve = prev.type === 'C' ||
|
|
193
192
|
prev.type === 'c' ||
|
|
194
193
|
prev.type === 'S' ||
|
|
@@ -285,7 +284,7 @@ const construct = (string) => {
|
|
|
285
284
|
cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
|
|
286
285
|
}
|
|
287
286
|
else if (instruction.type === 'T') {
|
|
288
|
-
const prev =
|
|
287
|
+
const prev = instructions[i - 1];
|
|
289
288
|
const prevWasQ = prev.type === 'Q' ||
|
|
290
289
|
prev.type === 'q' ||
|
|
291
290
|
prev.type === 'T' ||
|
|
@@ -318,7 +317,7 @@ const construct = (string) => {
|
|
|
318
317
|
cur = [instruction.x, instruction.y];
|
|
319
318
|
}
|
|
320
319
|
else if (instruction.type === 't') {
|
|
321
|
-
const prev =
|
|
320
|
+
const prev = instructions[i - 1];
|
|
322
321
|
const prevWasQ = prev.type === 'Q' ||
|
|
323
322
|
prev.type === 'q' ||
|
|
324
323
|
prev.type === 'T' ||
|
|
@@ -392,4 +391,9 @@ const construct = (string) => {
|
|
|
392
391
|
functions,
|
|
393
392
|
};
|
|
394
393
|
};
|
|
394
|
+
exports.constructFromInstructions = constructFromInstructions;
|
|
395
|
+
const construct = (string) => {
|
|
396
|
+
const parsed = (0, parse_path_1.parsePath)(string);
|
|
397
|
+
return (0, exports.constructFromInstructions)(parsed);
|
|
398
|
+
};
|
|
395
399
|
exports.construct = construct;
|
package/dist/reverse-path.js
CHANGED
|
@@ -7,123 +7,72 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.reversePath = void 0;
|
|
10
|
+
const construct_1 = require("./helpers/construct");
|
|
10
11
|
const normalize_path_1 = require("./normalize-path");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Reverse an SVG path.
|
|
18
|
-
* As long as the input path is normalised, this is actually really
|
|
19
|
-
* simple to do. As all pathing commands are symmetrical, meaning
|
|
20
|
-
* that they render the same when you reverse the coordinate order,
|
|
21
|
-
* the grand trick here is to reverse the path (making sure to keep
|
|
22
|
-
* coordinates ordered pairwise) and shift the operators left by
|
|
23
|
-
* one or two coordinate pairs depending on the operator:
|
|
24
|
-
*
|
|
25
|
-
* - Z is removed (after noting it existed),
|
|
26
|
-
* - L moves to 2 spots earlier (skipping one coordinate),
|
|
27
|
-
* - Q moves to 2 spots earlier (skipping one coordinate),
|
|
28
|
-
* - C moves to 4 spots earlier (skipping two coordinates)
|
|
29
|
-
* and its arguments get reversed,
|
|
30
|
-
* - the path start becomes M.
|
|
31
|
-
* - the path end becomes Z iff it was there to begin with.
|
|
32
|
-
*/
|
|
33
|
-
function reverseNormalizedPath(normalized) {
|
|
34
|
-
const terms = normalized.trim().split(' ');
|
|
35
|
-
let term;
|
|
36
|
-
const tlen = terms.length;
|
|
37
|
-
const tlen1 = tlen - 1;
|
|
38
|
-
let t;
|
|
12
|
+
const parse_path_1 = require("./parse-path");
|
|
13
|
+
const reduce_instructions_1 = require("./reduce-instructions");
|
|
14
|
+
const serialize_instructions_1 = require("./serialize-instructions");
|
|
15
|
+
function reverseNormalizedPath(instructions) {
|
|
39
16
|
const reversed = [];
|
|
40
|
-
let
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
// do the argument reading and operator shifting
|
|
88
|
-
if (pairs === shift) {
|
|
89
|
-
reversed.push(term);
|
|
90
|
-
}
|
|
91
|
-
for (pair = 0; pair < pairs; pair++) {
|
|
92
|
-
if (pair === shift) {
|
|
93
|
-
reversed.push(term);
|
|
94
|
-
}
|
|
95
|
-
x = terms[++t];
|
|
96
|
-
y = terms[++t];
|
|
97
|
-
reversed.push(y);
|
|
98
|
-
reversed.push(x);
|
|
99
|
-
}
|
|
17
|
+
let nextX = 0;
|
|
18
|
+
let nextY = 0;
|
|
19
|
+
for (const term of instructions) {
|
|
20
|
+
if (term.type === 'A') {
|
|
21
|
+
reversed.unshift({
|
|
22
|
+
type: 'A',
|
|
23
|
+
largeArcFlag: term.largeArcFlag,
|
|
24
|
+
rx: term.rx,
|
|
25
|
+
ry: term.ry,
|
|
26
|
+
xAxisRotation: term.xAxisRotation,
|
|
27
|
+
sweepFlag: !term.sweepFlag,
|
|
28
|
+
x: nextX,
|
|
29
|
+
y: nextY,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (term.type === 'C') {
|
|
33
|
+
reversed.unshift({
|
|
34
|
+
type: 'C',
|
|
35
|
+
cp1x: term.cp2x,
|
|
36
|
+
cp1y: term.cp2y,
|
|
37
|
+
cp2x: term.cp1x,
|
|
38
|
+
cp2y: term.cp1y,
|
|
39
|
+
x: nextX,
|
|
40
|
+
y: nextY,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else if (term.type === 'Q') {
|
|
44
|
+
reversed.unshift({
|
|
45
|
+
type: 'Q',
|
|
46
|
+
cpx: term.cpx,
|
|
47
|
+
cpy: term.cpy,
|
|
48
|
+
x: nextX,
|
|
49
|
+
y: nextY,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else if (term.type === 'L') {
|
|
53
|
+
reversed.unshift({
|
|
54
|
+
type: 'L',
|
|
55
|
+
x: nextX,
|
|
56
|
+
y: nextY,
|
|
57
|
+
});
|
|
58
|
+
// Do nothing
|
|
59
|
+
}
|
|
60
|
+
else if (term.type === 'M') {
|
|
61
|
+
// Do nothing
|
|
100
62
|
}
|
|
101
|
-
// the code has been set up so that every time we
|
|
102
|
-
// iterate because of the for() operation, the term
|
|
103
|
-
// we see is a pathing operator, not a number. As
|
|
104
|
-
// such, if we get to this "else" the path is malformed.
|
|
105
63
|
else {
|
|
106
|
-
|
|
107
|
-
const post = terms.slice(t + 1, Math.min(t + 4, tlen1)).join(' ');
|
|
108
|
-
const range = pre + ' [' + term + '] ' + post;
|
|
109
|
-
throw new Error('Error while trying to reverse normalized SVG path, at position ' +
|
|
110
|
-
t +
|
|
111
|
-
' (' +
|
|
112
|
-
range +
|
|
113
|
-
').\n' +
|
|
114
|
-
"Either the path is not normalised, or it's malformed.");
|
|
64
|
+
throw new Error('unnormalized instruction ' + term.type);
|
|
115
65
|
}
|
|
66
|
+
nextX = term.x;
|
|
67
|
+
nextY = term.y;
|
|
116
68
|
}
|
|
117
|
-
reversed.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
let
|
|
123
|
-
|
|
124
|
-
revstring += reversed[r] + ' ';
|
|
125
|
-
}
|
|
126
|
-
if (closed)
|
|
69
|
+
reversed.unshift({
|
|
70
|
+
type: 'M',
|
|
71
|
+
x: nextX,
|
|
72
|
+
y: nextY,
|
|
73
|
+
});
|
|
74
|
+
let revstring = (0, serialize_instructions_1.serializeInstructions)(reversed);
|
|
75
|
+
if (instructions[instructions.length - 1].type === 'Z')
|
|
127
76
|
revstring += 'Z';
|
|
128
77
|
revstring = revstring.replace(/M M/g, 'Z M');
|
|
129
78
|
return revstring;
|
|
@@ -134,12 +83,13 @@ function reverseNormalizedPath(normalized) {
|
|
|
134
83
|
* @see [Documentation](https://remotion.dev/docs/paths/reverse-path)
|
|
135
84
|
*/
|
|
136
85
|
const reversePath = (path) => {
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
86
|
+
const parsed = (0, parse_path_1.parsePath)(path);
|
|
87
|
+
const normalized = (0, normalize_path_1.normalizeInstructions)(parsed);
|
|
88
|
+
const reduced = (0, reduce_instructions_1.reduceInstructions)(normalized);
|
|
89
|
+
const { segments } = (0, construct_1.constructFromInstructions)(reduced);
|
|
90
|
+
return segments
|
|
141
91
|
.map((spath) => {
|
|
142
|
-
return reverseNormalizedPath(spath
|
|
92
|
+
return reverseNormalizedPath(spath);
|
|
143
93
|
})
|
|
144
94
|
.join(' ')
|
|
145
95
|
.replace(/ +/g, ' ')
|