@remotion/paths 4.0.0-webhook.27 → 4.1.0-alpha1
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/LICENSE.md +1 -1
- package/README.md +1 -2
- package/dist/evolve-path.d.ts +2 -2
- package/dist/evolve-path.js +2 -2
- package/dist/extend-viewbox.d.ts +2 -2
- package/dist/extend-viewbox.js +2 -2
- package/dist/get-bounding-box.d.ts +8 -0
- package/dist/get-bounding-box.js +185 -0
- package/dist/get-length.d.ts +2 -2
- package/dist/get-length.js +2 -2
- package/dist/get-point-at-length.d.ts +2 -2
- package/dist/get-point-at-length.js +2 -2
- package/dist/get-subpaths.d.ts +6 -0
- package/dist/get-subpaths.js +19 -0
- package/dist/get-tangent-at-length.d.ts +2 -2
- package/dist/get-tangent-at-length.js +2 -2
- package/dist/helpers/arc.d.ts +0 -0
- package/dist/helpers/arc.js +0 -0
- package/dist/helpers/bezier-functions.d.ts +0 -0
- package/dist/helpers/bezier-functions.js +0 -0
- package/dist/helpers/bezier-values.d.ts +0 -0
- package/dist/helpers/bezier-values.js +0 -0
- package/dist/helpers/bezier.d.ts +0 -0
- package/dist/helpers/bezier.js +0 -0
- package/dist/helpers/construct.d.ts +9 -1
- package/dist/helpers/construct.js +218 -128
- package/dist/helpers/get-part-at-length.d.ts +0 -0
- package/dist/helpers/get-part-at-length.js +0 -0
- package/dist/helpers/iterate.d.ts +14 -0
- package/dist/helpers/iterate.js +95 -0
- package/dist/helpers/linear.d.ts +6 -1
- package/dist/helpers/linear.js +1 -1
- package/dist/helpers/remove-a-s-t-curves.d.ts +2 -0
- package/dist/helpers/remove-a-s-t-curves.js +271 -0
- package/dist/helpers/split-curve.d.ts +1 -1
- package/dist/helpers/split-curve.js +0 -0
- package/dist/helpers/types.d.ts +109 -2
- package/dist/helpers/types.js +0 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +19 -3
- package/dist/interpolate-path.d.ts +2 -2
- package/dist/interpolate-path.js +2 -2
- package/dist/normalize-path.d.ts +4 -2
- package/dist/normalize-path.js +141 -277
- package/dist/parse-path.d.ts +8 -0
- package/dist/parse-path.js +265 -0
- package/dist/reduce-instructions.d.ts +7 -0
- package/dist/reduce-instructions.js +15 -0
- package/dist/reset-path.d.ts +6 -0
- package/dist/reset-path.js +15 -0
- package/dist/reverse-path.d.ts +2 -2
- package/dist/reverse-path.js +73 -118
- package/dist/scale-path.d.ts +10 -0
- package/dist/scale-path.js +180 -0
- package/dist/serialize-instructions.d.ts +2 -0
- package/dist/serialize-instructions.js +78 -0
- package/dist/translate-path.d.ts +11 -0
- package/dist/translate-path.js +116 -0
- package/dist/warp-path/index.d.ts +10 -0
- package/dist/warp-path/index.js +26 -0
- package/dist/warp-path/warp-helpers.d.ts +14 -0
- package/dist/warp-path/warp-helpers.js +229 -0
- package/package.json +38 -38
- package/.prettierrc.js +0 -14
- package/dist/get-parts.d.ts +0 -7
- package/dist/get-parts.js +0 -31
- package/dist/helpers/parse.d.ts +0 -2
- package/dist/helpers/parse.js +0 -49
- package/tsconfig.json +0 -9
package/dist/normalize-path.js
CHANGED
|
@@ -1,300 +1,164 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizePath = void 0;
|
|
3
|
+
exports.normalizeInstructions = exports.normalizePath = void 0;
|
|
4
|
+
const parse_path_1 = require("./parse-path");
|
|
5
|
+
const serialize_instructions_1 = require("./serialize-instructions");
|
|
4
6
|
/**
|
|
5
|
-
* Removes all relative coordinates from an SVG path and converts them into absolute coordinates.
|
|
7
|
+
* @description Removes all relative coordinates from an SVG path and converts them into absolute coordinates.
|
|
6
8
|
* @param {string} path A valid SVG path
|
|
7
|
-
* @
|
|
9
|
+
* @see [Documentation](https://remotion.dev/docs/paths/normalize-path)
|
|
8
10
|
*/
|
|
9
11
|
const normalizePath = (path) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
const
|
|
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;
|
|
12
|
+
const instructions = (0, parse_path_1.parsePath)(path);
|
|
13
|
+
const normalized = (0, exports.normalizeInstructions)(instructions);
|
|
14
|
+
return (0, serialize_instructions_1.serializeInstructions)(normalized);
|
|
15
|
+
};
|
|
16
|
+
exports.normalizePath = normalizePath;
|
|
17
|
+
const normalizeInstructions = (instructions) => {
|
|
18
|
+
// Extended properties must already be normalized
|
|
19
|
+
const normalized = [];
|
|
29
20
|
let x = 0;
|
|
30
21
|
let y = 0;
|
|
31
|
-
let
|
|
32
|
-
let
|
|
33
|
-
let
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
22
|
+
let moveX = 0;
|
|
23
|
+
let moveY = 0;
|
|
24
|
+
for (let i = 0; i < instructions.length; i++) {
|
|
25
|
+
const instruction = instructions[i];
|
|
26
|
+
if (instruction.type === 'M') {
|
|
27
|
+
moveX = instruction.x;
|
|
28
|
+
moveY = instruction.y;
|
|
29
|
+
}
|
|
30
|
+
else if (instruction.type === 'm') {
|
|
31
|
+
moveX += instruction.dx;
|
|
32
|
+
moveY += instruction.dy;
|
|
33
|
+
}
|
|
34
|
+
if (instruction.type === 'A' ||
|
|
35
|
+
instruction.type === 'C' ||
|
|
36
|
+
instruction.type === 'L' ||
|
|
37
|
+
instruction.type === 'M' ||
|
|
38
|
+
instruction.type === 'Q' ||
|
|
39
|
+
instruction.type === 'S' ||
|
|
40
|
+
instruction.type === 'T') {
|
|
41
|
+
normalized.push(instruction);
|
|
42
|
+
x = instruction.x;
|
|
43
|
+
y = instruction.y;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (instruction.type === 'a' ||
|
|
47
|
+
instruction.type === 'c' ||
|
|
48
|
+
instruction.type === 'l' ||
|
|
49
|
+
instruction.type === 'm' ||
|
|
50
|
+
instruction.type === 'q' ||
|
|
51
|
+
instruction.type === 's' ||
|
|
52
|
+
instruction.type === 't') {
|
|
53
|
+
const currentX = x;
|
|
54
|
+
const currentY = y;
|
|
55
|
+
x += instruction.dx;
|
|
56
|
+
y += instruction.dy;
|
|
57
|
+
if (instruction.type === 'a') {
|
|
58
|
+
normalized.push({
|
|
59
|
+
type: 'A',
|
|
60
|
+
largeArcFlag: instruction.largeArcFlag,
|
|
61
|
+
rx: instruction.rx,
|
|
62
|
+
ry: instruction.ry,
|
|
63
|
+
sweepFlag: instruction.sweepFlag,
|
|
64
|
+
xAxisRotation: instruction.xAxisRotation,
|
|
65
|
+
x,
|
|
66
|
+
y,
|
|
67
|
+
});
|
|
68
|
+
continue;
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
if (instruction.type === 'c') {
|
|
71
|
+
normalized.push({
|
|
72
|
+
type: 'C',
|
|
73
|
+
cp1x: instruction.cp1dx + currentX,
|
|
74
|
+
cp1y: instruction.cp1dy + currentY,
|
|
75
|
+
cp2x: instruction.cp2dx + currentX,
|
|
76
|
+
cp2y: instruction.cp2dy + currentY,
|
|
77
|
+
x,
|
|
78
|
+
y,
|
|
79
|
+
});
|
|
80
|
+
continue;
|
|
73
81
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
}
|
|
82
|
+
if (instruction.type === 'l') {
|
|
83
|
+
normalized.push({
|
|
84
|
+
type: 'L',
|
|
85
|
+
x,
|
|
86
|
+
y,
|
|
87
|
+
});
|
|
88
|
+
continue;
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
x = args[a];
|
|
103
|
-
y = args[a + 1];
|
|
104
|
-
}
|
|
105
|
-
normalized += 'L ' + x + ' ' + y + ' ';
|
|
90
|
+
if (instruction.type === 'm') {
|
|
91
|
+
normalized.push({
|
|
92
|
+
type: 'M',
|
|
93
|
+
x,
|
|
94
|
+
y,
|
|
95
|
+
});
|
|
96
|
+
continue;
|
|
106
97
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
normalized += 'L ' + x + ' ' + y + ' ';
|
|
98
|
+
if (instruction.type === 'q') {
|
|
99
|
+
normalized.push({
|
|
100
|
+
type: 'Q',
|
|
101
|
+
cpx: instruction.cpdx + currentX,
|
|
102
|
+
cpy: instruction.cpdy + currentY,
|
|
103
|
+
x,
|
|
104
|
+
y,
|
|
105
|
+
});
|
|
106
|
+
continue;
|
|
117
107
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
normalized += 'L ' + x + ' ' + y + ' ';
|
|
108
|
+
if (instruction.type === 's') {
|
|
109
|
+
normalized.push({
|
|
110
|
+
type: 'S',
|
|
111
|
+
cpx: instruction.cpdx + currentX,
|
|
112
|
+
cpy: instruction.cpdy + currentY,
|
|
113
|
+
x,
|
|
114
|
+
y,
|
|
115
|
+
});
|
|
116
|
+
continue;
|
|
128
117
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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 + ' ';
|
|
118
|
+
if (instruction.type === 't') {
|
|
119
|
+
normalized.push({
|
|
120
|
+
type: 'T',
|
|
121
|
+
x,
|
|
122
|
+
y,
|
|
123
|
+
});
|
|
124
|
+
continue;
|
|
146
125
|
}
|
|
147
126
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
}
|
|
127
|
+
if (instruction.type === 'H') {
|
|
128
|
+
normalized.push(instruction);
|
|
129
|
+
x = instruction.x;
|
|
130
|
+
continue;
|
|
164
131
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
}
|
|
132
|
+
if (instruction.type === 'V') {
|
|
133
|
+
normalized.push(instruction);
|
|
134
|
+
y = instruction.y;
|
|
135
|
+
continue;
|
|
199
136
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
}
|
|
137
|
+
if (instruction.type === 'Z') {
|
|
138
|
+
normalized.push(instruction);
|
|
139
|
+
x = moveX;
|
|
140
|
+
y = moveY;
|
|
141
|
+
continue;
|
|
233
142
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
}
|
|
143
|
+
if (instruction.type === 'h') {
|
|
144
|
+
x += instruction.dx;
|
|
145
|
+
normalized.push({
|
|
146
|
+
type: 'H',
|
|
147
|
+
x,
|
|
148
|
+
});
|
|
149
|
+
continue;
|
|
290
150
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
151
|
+
if (instruction.type === 'v') {
|
|
152
|
+
y += instruction.dy;
|
|
153
|
+
normalized.push({
|
|
154
|
+
type: 'V',
|
|
155
|
+
y,
|
|
156
|
+
});
|
|
157
|
+
continue;
|
|
296
158
|
}
|
|
159
|
+
// @ts-expect-error
|
|
160
|
+
throw new Error('Unknown instruction type: ' + instruction.type);
|
|
297
161
|
}
|
|
298
|
-
return normalized
|
|
162
|
+
return normalized;
|
|
299
163
|
};
|
|
300
|
-
exports.
|
|
164
|
+
exports.normalizeInstructions = normalizeInstructions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Instruction } from './helpers/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description Parses an SVG string path into an array of Instruction's.
|
|
4
|
+
* @param {string} path
|
|
5
|
+
* @returns an array of objects containing the Instructions
|
|
6
|
+
* @see [Documentation](https://www.remotion.dev/docs/paths/parse-path)
|
|
7
|
+
*/
|
|
8
|
+
export declare const parsePath: (path: string) => Instruction[];
|