@remotion/paths 3.2.11
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/.prettierrc.js +14 -0
- package/LICENSE.md +7 -0
- package/README.md +25 -0
- package/dist/arc.d.ts +12 -0
- package/dist/arc.js +231 -0
- package/dist/bezier-functions.d.ts +11 -0
- package/dist/bezier-functions.js +138 -0
- package/dist/bezier-values.d.ts +3 -0
- package/dist/bezier-values.js +693 -0
- package/dist/bezier.d.ts +26 -0
- package/dist/bezier.js +81 -0
- package/dist/construct.d.ts +7 -0
- package/dist/construct.js +308 -0
- package/dist/evolve-path.d.ts +10 -0
- package/dist/evolve-path.js +17 -0
- package/dist/get-length.d.ts +6 -0
- package/dist/get-length.js +15 -0
- package/dist/get-part-at-length.d.ts +4 -0
- package/dist/get-part-at-length.js +20 -0
- package/dist/get-parts.d.ts +7 -0
- package/dist/get-parts.js +31 -0
- package/dist/get-point-at-length.d.ts +7 -0
- package/dist/get-point-at-length.js +24 -0
- package/dist/get-properties-at-length.d.ts +1 -0
- package/dist/get-properties-at-length.js +23 -0
- package/dist/get-reversed-path.d.ts +12 -0
- package/dist/get-reversed-path.js +159 -0
- package/dist/get-tangent-at-length.d.ts +7 -0
- package/dist/get-tangent-at-length.js +24 -0
- package/dist/helpers/arc.d.ts +12 -0
- package/dist/helpers/arc.js +226 -0
- package/dist/helpers/bezier-functions.d.ts +11 -0
- package/dist/helpers/bezier-functions.js +135 -0
- package/dist/helpers/bezier-values.d.ts +3 -0
- package/dist/helpers/bezier-values.js +694 -0
- package/dist/helpers/bezier.d.ts +26 -0
- package/dist/helpers/bezier.js +82 -0
- package/dist/helpers/construct.d.ts +7 -0
- package/dist/helpers/construct.js +309 -0
- package/dist/helpers/get-part-at-length.d.ts +4 -0
- package/dist/helpers/get-part-at-length.js +20 -0
- package/dist/helpers/linear.d.ts +7 -0
- package/dist/helpers/linear.js +30 -0
- package/dist/helpers/parse.d.ts +2 -0
- package/dist/helpers/parse.js +49 -0
- package/dist/helpers/split-curve.d.ts +47 -0
- package/dist/helpers/split-curve.js +190 -0
- package/dist/helpers/types.d.ts +22 -0
- package/dist/helpers/types.js +3 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +19 -0
- package/dist/interpolate-path.d.ts +8 -0
- package/dist/interpolate-path.js +366 -0
- package/dist/linear.d.ts +7 -0
- package/dist/linear.js +31 -0
- package/dist/normalize-path.d.ts +6 -0
- package/dist/normalize-path.js +300 -0
- package/dist/parse.d.ts +2 -0
- package/dist/parse.js +48 -0
- package/dist/reverse-path.d.ts +12 -0
- package/dist/reverse-path.js +148 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.js +2 -0
- package/package.json +39 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizePath = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Removes all relative coordinates from an SVG path and converts them into absolute coordinates.
|
|
6
|
+
* @param {string} path A valid SVG path
|
|
7
|
+
* @link https://remotion.dev/docs/paths/normalize-path
|
|
8
|
+
*/
|
|
9
|
+
const normalizePath = (path) => {
|
|
10
|
+
// preprocess "d" so that we have spaces between values
|
|
11
|
+
path = path
|
|
12
|
+
.replace(/,/g, ' ')
|
|
13
|
+
.replace(/([^eE])-/g, '$1 -')
|
|
14
|
+
.replace(/\s*([achlmqstvzACHLMQSTVZ])\s*/g, ' $1 ')
|
|
15
|
+
.replace(/\s+/g, ' ');
|
|
16
|
+
// set up the variables used in this function
|
|
17
|
+
const instructions = path
|
|
18
|
+
.replace(/([achlmqstvzACHLMQSTVZ])\s?/g, '|$1')
|
|
19
|
+
.split('|');
|
|
20
|
+
const instructionLength = instructions.length;
|
|
21
|
+
let i;
|
|
22
|
+
let instruction;
|
|
23
|
+
let op;
|
|
24
|
+
let lop;
|
|
25
|
+
let alen;
|
|
26
|
+
let a;
|
|
27
|
+
let sx = 0;
|
|
28
|
+
let sy = 0;
|
|
29
|
+
let x = 0;
|
|
30
|
+
let y = 0;
|
|
31
|
+
let cx = 0;
|
|
32
|
+
let cy = 0;
|
|
33
|
+
let cx2 = 0;
|
|
34
|
+
let cy2 = 0;
|
|
35
|
+
let rx = 0;
|
|
36
|
+
let ry = 0;
|
|
37
|
+
let xrot = 0;
|
|
38
|
+
let lflag = 0;
|
|
39
|
+
let sweep = 0;
|
|
40
|
+
let normalized = '';
|
|
41
|
+
// we run through the instruction list starting at 1, not 0,
|
|
42
|
+
// because we split up "|M x y ...." so the first element will
|
|
43
|
+
// always be an empty string. By design.
|
|
44
|
+
for (i = 1; i < instructionLength; i++) {
|
|
45
|
+
// which instruction is this?
|
|
46
|
+
instruction = instructions[i];
|
|
47
|
+
op = instruction.substring(0, 1);
|
|
48
|
+
lop = op.toLowerCase();
|
|
49
|
+
// what are the arguments? note that we need to convert
|
|
50
|
+
// all strings into numbers, or + will do silly things.
|
|
51
|
+
const oargs = instruction
|
|
52
|
+
.replace(op, '')
|
|
53
|
+
.trim()
|
|
54
|
+
.split(' ')
|
|
55
|
+
.filter((v) => {
|
|
56
|
+
return v !== '';
|
|
57
|
+
});
|
|
58
|
+
const args = oargs.map((_a) => parseFloat(String(_a)));
|
|
59
|
+
alen = args.length;
|
|
60
|
+
// we could use a switch, but elaborate code in a "case" with
|
|
61
|
+
// fallthrough is just horrid to read. So let's use ifthen
|
|
62
|
+
// statements instead.
|
|
63
|
+
// moveto command (plus possible lineto)
|
|
64
|
+
if (lop === 'm') {
|
|
65
|
+
normalized += 'M ';
|
|
66
|
+
if (op === 'm') {
|
|
67
|
+
x += args[0];
|
|
68
|
+
y += args[1];
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
x = args[0];
|
|
72
|
+
y = args[1];
|
|
73
|
+
}
|
|
74
|
+
// records start position, for dealing
|
|
75
|
+
// with the shape close operator ('Z')
|
|
76
|
+
sx = x;
|
|
77
|
+
sy = y;
|
|
78
|
+
normalized += x + ' ' + y + ' ';
|
|
79
|
+
if (alen > 2) {
|
|
80
|
+
for (a = 0; a < alen; a += 2) {
|
|
81
|
+
// eslint-disable-next-line max-depth
|
|
82
|
+
if (op === 'm') {
|
|
83
|
+
x += args[a];
|
|
84
|
+
y += args[a + 1];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
x = args[a];
|
|
88
|
+
y = args[a + 1];
|
|
89
|
+
}
|
|
90
|
+
normalized += 'L ' + x + ' ' + y + ' ';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// lineto commands
|
|
95
|
+
else if (lop === 'l') {
|
|
96
|
+
for (a = 0; a < alen; a += 2) {
|
|
97
|
+
if (op === 'l') {
|
|
98
|
+
x += args[a];
|
|
99
|
+
y += args[a + 1];
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
x = args[a];
|
|
103
|
+
y = args[a + 1];
|
|
104
|
+
}
|
|
105
|
+
normalized += 'L ' + x + ' ' + y + ' ';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else if (lop === 'h') {
|
|
109
|
+
for (a = 0; a < alen; a++) {
|
|
110
|
+
if (op === 'h') {
|
|
111
|
+
x += args[a];
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
x = args[a];
|
|
115
|
+
}
|
|
116
|
+
normalized += 'L ' + x + ' ' + y + ' ';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (lop === 'v') {
|
|
120
|
+
for (a = 0; a < alen; a++) {
|
|
121
|
+
if (op === 'v') {
|
|
122
|
+
y += args[a];
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
y = args[a];
|
|
126
|
+
}
|
|
127
|
+
normalized += 'L ' + x + ' ' + y + ' ';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// quadratic curveto commands
|
|
131
|
+
else if (lop === 'q') {
|
|
132
|
+
for (a = 0; a < alen; a += 4) {
|
|
133
|
+
if (op === 'q') {
|
|
134
|
+
cx = x + args[a];
|
|
135
|
+
cy = y + args[a + 1];
|
|
136
|
+
x += args[a + 2];
|
|
137
|
+
y += args[a + 3];
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
cx = args[a];
|
|
141
|
+
cy = args[a + 1];
|
|
142
|
+
x = args[a + 2];
|
|
143
|
+
y = args[a + 3];
|
|
144
|
+
}
|
|
145
|
+
normalized += 'Q ' + cx + ' ' + cy + ' ' + x + ' ' + y + ' ';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (lop === 't') {
|
|
149
|
+
for (a = 0; a < alen; a += 2) {
|
|
150
|
+
// reflect previous cx/cy over x/y
|
|
151
|
+
cx = x + (x - cx);
|
|
152
|
+
cy = y + (y - cy);
|
|
153
|
+
// then get real end point
|
|
154
|
+
if (op === 't') {
|
|
155
|
+
x += args[a];
|
|
156
|
+
y += args[a + 1];
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
x = args[a];
|
|
160
|
+
y = args[a + 1];
|
|
161
|
+
}
|
|
162
|
+
normalized += 'Q ' + cx + ' ' + cy + ' ' + x + ' ' + y + ' ';
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// cubic curveto commands
|
|
166
|
+
else if (lop === 'c') {
|
|
167
|
+
for (a = 0; a < alen; a += 6) {
|
|
168
|
+
if (op === 'c') {
|
|
169
|
+
cx = x + args[a];
|
|
170
|
+
cy = y + args[a + 1];
|
|
171
|
+
cx2 = x + args[a + 2];
|
|
172
|
+
cy2 = y + args[a + 3];
|
|
173
|
+
x += args[a + 4];
|
|
174
|
+
y += args[a + 5];
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
cx = args[a];
|
|
178
|
+
cy = args[a + 1];
|
|
179
|
+
cx2 = args[a + 2];
|
|
180
|
+
cy2 = args[a + 3];
|
|
181
|
+
x = args[a + 4];
|
|
182
|
+
y = args[a + 5];
|
|
183
|
+
}
|
|
184
|
+
normalized +=
|
|
185
|
+
'C ' +
|
|
186
|
+
cx +
|
|
187
|
+
' ' +
|
|
188
|
+
cy +
|
|
189
|
+
' ' +
|
|
190
|
+
cx2 +
|
|
191
|
+
' ' +
|
|
192
|
+
cy2 +
|
|
193
|
+
' ' +
|
|
194
|
+
x +
|
|
195
|
+
' ' +
|
|
196
|
+
y +
|
|
197
|
+
' ';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else if (lop === 's') {
|
|
201
|
+
for (a = 0; a < alen; a += 4) {
|
|
202
|
+
// reflect previous cx2/cy2 over x/y
|
|
203
|
+
cx = x + (x - cx2);
|
|
204
|
+
cy = y + (y - cy2);
|
|
205
|
+
// then get real control and end point
|
|
206
|
+
if (op === 's') {
|
|
207
|
+
cx2 = x + args[a];
|
|
208
|
+
cy2 = y + args[a + 1];
|
|
209
|
+
x += args[a + 2];
|
|
210
|
+
y += args[a + 3];
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
cx2 = args[a];
|
|
214
|
+
cy2 = args[a + 1];
|
|
215
|
+
x = args[a + 2];
|
|
216
|
+
y = args[a + 3];
|
|
217
|
+
}
|
|
218
|
+
normalized +=
|
|
219
|
+
'C ' +
|
|
220
|
+
cx +
|
|
221
|
+
' ' +
|
|
222
|
+
cy +
|
|
223
|
+
' ' +
|
|
224
|
+
cx2 +
|
|
225
|
+
' ' +
|
|
226
|
+
cy2 +
|
|
227
|
+
' ' +
|
|
228
|
+
x +
|
|
229
|
+
' ' +
|
|
230
|
+
y +
|
|
231
|
+
' ';
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// rx ry x-axis-rotation large-arc-flag sweep-flag x y
|
|
235
|
+
// a 25,25 -30 0, 1 50,-25
|
|
236
|
+
// arc command
|
|
237
|
+
else if (lop === 'a') {
|
|
238
|
+
for (a = 0; a < alen; a += 7) {
|
|
239
|
+
rx = args[a];
|
|
240
|
+
ry = args[a + 1];
|
|
241
|
+
xrot = args[a + 2];
|
|
242
|
+
lflag = oargs[a + 3]; // we need the original string to deal with leading zeroes
|
|
243
|
+
let fixed = false;
|
|
244
|
+
if (lflag.length > 1) {
|
|
245
|
+
const b1 = parseInt(lflag[0], 10);
|
|
246
|
+
const b2 = parseInt(lflag[1], 10);
|
|
247
|
+
let rest;
|
|
248
|
+
// eslint-disable-next-line max-depth
|
|
249
|
+
if (lflag.length > 2)
|
|
250
|
+
rest = parseFloat(lflag.substring(2));
|
|
251
|
+
args[a + 3] = b1;
|
|
252
|
+
args.splice(a + 4, 0, b2);
|
|
253
|
+
// eslint-disable-next-line max-depth
|
|
254
|
+
if (rest !== undefined)
|
|
255
|
+
args.splice(a + 5, 0, rest);
|
|
256
|
+
fixed = true;
|
|
257
|
+
}
|
|
258
|
+
lflag = args[a + 3];
|
|
259
|
+
sweep = fixed ? args[a + 4] : oargs[a + 4]; // we need the original string to deal with leading zeroes
|
|
260
|
+
if (!fixed && sweep.length > 1) {
|
|
261
|
+
args[a + 4] = parseInt(sweep[0], 10);
|
|
262
|
+
args.splice(a + 5, 0, parseFloat(sweep.substring(1)));
|
|
263
|
+
}
|
|
264
|
+
sweep = args[a + 4];
|
|
265
|
+
if (op === 'a') {
|
|
266
|
+
x += args[a + 5];
|
|
267
|
+
y += args[a + 6];
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
x = args[a + 5];
|
|
271
|
+
y = args[a + 6];
|
|
272
|
+
}
|
|
273
|
+
normalized +=
|
|
274
|
+
'A ' +
|
|
275
|
+
rx +
|
|
276
|
+
' ' +
|
|
277
|
+
ry +
|
|
278
|
+
' ' +
|
|
279
|
+
xrot +
|
|
280
|
+
' ' +
|
|
281
|
+
lflag +
|
|
282
|
+
' ' +
|
|
283
|
+
sweep +
|
|
284
|
+
' ' +
|
|
285
|
+
x +
|
|
286
|
+
' ' +
|
|
287
|
+
y +
|
|
288
|
+
' ';
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else if (lop === 'z') {
|
|
292
|
+
normalized += 'Z ';
|
|
293
|
+
// not unimportant: path closing changes the current x/y coordinate
|
|
294
|
+
x = sx;
|
|
295
|
+
y = sy;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return normalized.trim();
|
|
299
|
+
};
|
|
300
|
+
exports.normalizePath = normalizePath;
|
package/dist/parse.d.ts
ADDED
package/dist/parse.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const length = {
|
|
4
|
+
a: 7,
|
|
5
|
+
c: 6,
|
|
6
|
+
h: 1,
|
|
7
|
+
l: 2,
|
|
8
|
+
m: 2,
|
|
9
|
+
q: 4,
|
|
10
|
+
s: 4,
|
|
11
|
+
t: 2,
|
|
12
|
+
v: 1,
|
|
13
|
+
z: 0
|
|
14
|
+
};
|
|
15
|
+
const segmentRegExp = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
|
|
16
|
+
const numberRegExp = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
|
|
17
|
+
exports.default = (path) => {
|
|
18
|
+
const segments = (path && path.length > 0 ? path : "M0,0").match(segmentRegExp);
|
|
19
|
+
if (!segments) {
|
|
20
|
+
throw new Error(`No path elements found in string ${path}`);
|
|
21
|
+
}
|
|
22
|
+
return segments.reduce((segmentsArray, segmentString) => {
|
|
23
|
+
let command = segmentString.charAt(0);
|
|
24
|
+
let type = command.toLowerCase();
|
|
25
|
+
const args = parseValues(segmentString.substr(1));
|
|
26
|
+
// overloaded moveTo
|
|
27
|
+
if (type === "m" && args.length > 2) {
|
|
28
|
+
segmentsArray.push([command, ...args.splice(0, 2)]);
|
|
29
|
+
type = "l";
|
|
30
|
+
command = command === "m" ? "l" : "L";
|
|
31
|
+
}
|
|
32
|
+
while (args.length >= 0) {
|
|
33
|
+
if (args.length === length[type]) {
|
|
34
|
+
segmentsArray.push([command, ...args.splice(0, length[type])]);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (args.length < length[type]) {
|
|
38
|
+
throw new Error(`Malformed path data: "${command}" must have ${length[type]} elements and has ${args.length}: ${segmentString}`);
|
|
39
|
+
}
|
|
40
|
+
segmentsArray.push([command, ...args.splice(0, length[type])]);
|
|
41
|
+
}
|
|
42
|
+
return segmentsArray;
|
|
43
|
+
}, []);
|
|
44
|
+
};
|
|
45
|
+
const parseValues = (args) => {
|
|
46
|
+
const numbers = args.match(numberRegExp);
|
|
47
|
+
return numbers ? numbers.map(Number) : [];
|
|
48
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://github.com/Pomax/svg-path-reverse
|
|
3
|
+
*
|
|
4
|
+
* This code is in the public domain, except in jurisdictions that do
|
|
5
|
+
* not recognise the public domain, where this code is MIT licensed.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Reverses a path so the end and start are switched.
|
|
9
|
+
* @param {string} path A valid SVG path
|
|
10
|
+
* @link https://remotion.dev/docs/paths/reverse-path
|
|
11
|
+
*/
|
|
12
|
+
export declare const reversePath: (path: string) => string;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* https://github.com/Pomax/svg-path-reverse
|
|
4
|
+
*
|
|
5
|
+
* This code is in the public domain, except in jurisdictions that do
|
|
6
|
+
* not recognise the public domain, where this code is MIT licensed.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.reversePath = void 0;
|
|
10
|
+
const normalize_path_1 = require("./normalize-path");
|
|
11
|
+
/**
|
|
12
|
+
* Normalise an SVG path to absolute coordinates
|
|
13
|
+
* and full commands, rather than relative coordinates
|
|
14
|
+
* and/or shortcut commands.
|
|
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;
|
|
39
|
+
const reversed = [];
|
|
40
|
+
let x;
|
|
41
|
+
let y;
|
|
42
|
+
let pair;
|
|
43
|
+
let pairs;
|
|
44
|
+
let shift;
|
|
45
|
+
const matcher = /[QAZLCM]/;
|
|
46
|
+
const closed = terms.slice(-1)[0].toUpperCase() === 'Z';
|
|
47
|
+
for (t = 0; t < tlen; t++) {
|
|
48
|
+
term = terms[t];
|
|
49
|
+
// Is this an operator? If it is, run through its
|
|
50
|
+
// argument list, which we know is fixed length.
|
|
51
|
+
if (matcher.test(term)) {
|
|
52
|
+
// Arc processing relies on not-just-coordinates
|
|
53
|
+
if (term === 'A') {
|
|
54
|
+
reversed.push(terms[t + 5] === '0' ? '1' : '0');
|
|
55
|
+
reversed.push(terms[t + 4]);
|
|
56
|
+
reversed.push(terms[t + 3]);
|
|
57
|
+
reversed.push(terms[t + 2]);
|
|
58
|
+
reversed.push(terms[t + 1]);
|
|
59
|
+
reversed.push(term);
|
|
60
|
+
reversed.push(terms[t + 7]);
|
|
61
|
+
reversed.push(terms[t + 6]);
|
|
62
|
+
t += 7;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
// how many coordinate pairs do we need to read,
|
|
66
|
+
// and by how many pairs should this operator be
|
|
67
|
+
// shifted left?
|
|
68
|
+
else if (term === 'C') {
|
|
69
|
+
pairs = 3;
|
|
70
|
+
shift = 2;
|
|
71
|
+
}
|
|
72
|
+
else if (term === 'Q') {
|
|
73
|
+
pairs = 2;
|
|
74
|
+
shift = 1;
|
|
75
|
+
}
|
|
76
|
+
else if (term === 'L') {
|
|
77
|
+
pairs = 1;
|
|
78
|
+
shift = 1;
|
|
79
|
+
}
|
|
80
|
+
else if (term === 'M') {
|
|
81
|
+
pairs = 1;
|
|
82
|
+
shift = 0;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
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
|
+
}
|
|
100
|
+
}
|
|
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
|
+
else {
|
|
106
|
+
const pre = terms.slice(Math.max(t - 3, 0), 3).join(' ');
|
|
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.");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
reversed.push('M');
|
|
118
|
+
// generating the reversed path string involves
|
|
119
|
+
// running through our transformed terms in reverse.
|
|
120
|
+
let revstring = '';
|
|
121
|
+
const rlen1 = reversed.length - 1;
|
|
122
|
+
let r;
|
|
123
|
+
for (r = rlen1; r > 0; r--) {
|
|
124
|
+
revstring += reversed[r] + ' ';
|
|
125
|
+
}
|
|
126
|
+
if (closed)
|
|
127
|
+
revstring += 'Z';
|
|
128
|
+
revstring = revstring.replace(/M M/g, 'Z M');
|
|
129
|
+
return revstring;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Reverses a path so the end and start are switched.
|
|
133
|
+
* @param {string} path A valid SVG path
|
|
134
|
+
* @link https://remotion.dev/docs/paths/reverse-path
|
|
135
|
+
*/
|
|
136
|
+
const reversePath = (path) => {
|
|
137
|
+
const normalizedPath = (0, normalize_path_1.normalizePath)(path);
|
|
138
|
+
const paths = normalizedPath.replace(/M/g, '|M').split('|');
|
|
139
|
+
paths.splice(0, 1);
|
|
140
|
+
return paths
|
|
141
|
+
.map((spath) => {
|
|
142
|
+
return reverseNormalizedPath(spath.trim());
|
|
143
|
+
})
|
|
144
|
+
.join(' ')
|
|
145
|
+
.replace(/ +/g, ' ')
|
|
146
|
+
.trim();
|
|
147
|
+
};
|
|
148
|
+
exports.reversePath = reversePath;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface Properties {
|
|
2
|
+
getTotalLength(): number;
|
|
3
|
+
getPointAtLength(pos: number): Point;
|
|
4
|
+
getTangentAtLength(pos: number): Point;
|
|
5
|
+
getPropertiesAtLength(pos: number): PointProperties;
|
|
6
|
+
}
|
|
7
|
+
export interface PartProperties {
|
|
8
|
+
start: Point;
|
|
9
|
+
end: Point;
|
|
10
|
+
length: number;
|
|
11
|
+
getPointAtLength(pos: number): Point;
|
|
12
|
+
getTangentAtLength(pos: number): Point;
|
|
13
|
+
getPropertiesAtLength(pos: number): PointProperties;
|
|
14
|
+
}
|
|
15
|
+
export interface Point {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
}
|
|
19
|
+
export declare type PointArray = [number, number];
|
|
20
|
+
export interface PointProperties {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
tangentX: number;
|
|
24
|
+
tangentY: number;
|
|
25
|
+
}
|
|
26
|
+
export declare type pathOrders = "a" | "c" | "h" | "l" | "m" | "q" | "s" | "t" | "v" | "z";
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@remotion/paths",
|
|
3
|
+
"version": "3.2.11",
|
|
4
|
+
"description": "Utility functions for SVG paths",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "eslint src --ext ts,tsx",
|
|
9
|
+
"watch": "tsc -w",
|
|
10
|
+
"build": "tsc -d",
|
|
11
|
+
"test": "vitest --run"
|
|
12
|
+
},
|
|
13
|
+
"author": "Jonny Burger <jonny@remotion.dev>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"url": "https://github.com/remotion-dev/remotion"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@jonny/eslint-config": "3.0.266",
|
|
23
|
+
"@types/node": "^16.7.5",
|
|
24
|
+
"eslint": "8.13.0",
|
|
25
|
+
"prettier": "^2.0.5",
|
|
26
|
+
"prettier-plugin-organize-imports": "^2.3.4",
|
|
27
|
+
"typescript": "^4.7.0",
|
|
28
|
+
"vitest": "^0.18.0"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"svg",
|
|
32
|
+
"path",
|
|
33
|
+
"utilities"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "43d44e718e41200aea544719e9963482f9a65120"
|
|
39
|
+
}
|