@remotion/paths 4.0.0-webhook.27 → 4.1.0-alpha2
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
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copied from: https://github.com/rveciana/svg-path-properties
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parsePath = void 0;
|
|
5
|
+
const length = {
|
|
6
|
+
a: 7,
|
|
7
|
+
A: 7,
|
|
8
|
+
C: 6,
|
|
9
|
+
c: 6,
|
|
10
|
+
H: 1,
|
|
11
|
+
h: 1,
|
|
12
|
+
L: 2,
|
|
13
|
+
l: 2,
|
|
14
|
+
M: 2,
|
|
15
|
+
m: 2,
|
|
16
|
+
Q: 4,
|
|
17
|
+
q: 4,
|
|
18
|
+
S: 4,
|
|
19
|
+
s: 4,
|
|
20
|
+
T: 2,
|
|
21
|
+
t: 2,
|
|
22
|
+
V: 1,
|
|
23
|
+
v: 1,
|
|
24
|
+
Z: 0,
|
|
25
|
+
z: 0,
|
|
26
|
+
};
|
|
27
|
+
const chunkExact = (array, instruction) => {
|
|
28
|
+
const chunks = [];
|
|
29
|
+
const expectedSize = length[instruction];
|
|
30
|
+
if (array.length % expectedSize !== 0) {
|
|
31
|
+
throw new Error(`Expected number of arguments of SVG instruction "${instruction} ${array.join(' ')}" to be a multiple of ${expectedSize}`);
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < array.length; i += expectedSize) {
|
|
34
|
+
chunks.push(array.slice(i, i + expectedSize));
|
|
35
|
+
}
|
|
36
|
+
return chunks;
|
|
37
|
+
};
|
|
38
|
+
const makeInstructions = (arr, instruction, cb) => {
|
|
39
|
+
return chunkExact(arr, instruction).map((args) => {
|
|
40
|
+
return cb(args);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const segmentRegExp = /([astvzqmhlc])([^astvzqmhlc]*)/gi;
|
|
44
|
+
const numberRegExp = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;
|
|
45
|
+
/**
|
|
46
|
+
* @description Parses an SVG string path into an array of Instruction's.
|
|
47
|
+
* @param {string} path
|
|
48
|
+
* @returns an array of objects containing the Instructions
|
|
49
|
+
* @see [Documentation](https://www.remotion.dev/docs/paths/parse-path)
|
|
50
|
+
*/
|
|
51
|
+
const parsePath = (path) => {
|
|
52
|
+
if (!path) {
|
|
53
|
+
throw new Error('No path provided');
|
|
54
|
+
}
|
|
55
|
+
const segments = path.match(segmentRegExp);
|
|
56
|
+
if (!segments) {
|
|
57
|
+
throw new Error(`No path elements found in string ${path}`);
|
|
58
|
+
}
|
|
59
|
+
return segments
|
|
60
|
+
.map((segmentString) => {
|
|
61
|
+
const command = segmentString.charAt(0);
|
|
62
|
+
const args = parseValues(segmentString.substring(1), command);
|
|
63
|
+
// overloaded moveTo
|
|
64
|
+
if (command === 'M' && args.length > 2) {
|
|
65
|
+
const segmentsArray = [];
|
|
66
|
+
segmentsArray.push({
|
|
67
|
+
type: command,
|
|
68
|
+
x: args[0],
|
|
69
|
+
y: args[1],
|
|
70
|
+
});
|
|
71
|
+
segmentsArray.push(...makeInstructions(args.slice(2), 'L', (numbers) => ({
|
|
72
|
+
type: 'L',
|
|
73
|
+
x: numbers[0],
|
|
74
|
+
y: numbers[1],
|
|
75
|
+
})));
|
|
76
|
+
return segmentsArray;
|
|
77
|
+
}
|
|
78
|
+
if (command === 'm' && args.length > 2) {
|
|
79
|
+
const segmentsArray = [];
|
|
80
|
+
segmentsArray.push({
|
|
81
|
+
type: command,
|
|
82
|
+
dx: args[0],
|
|
83
|
+
dy: args[1],
|
|
84
|
+
});
|
|
85
|
+
segmentsArray.push(...makeInstructions(args.slice(2), 'l', (numbers) => ({
|
|
86
|
+
type: 'l',
|
|
87
|
+
dx: numbers[0],
|
|
88
|
+
dy: numbers[1],
|
|
89
|
+
})));
|
|
90
|
+
return segmentsArray;
|
|
91
|
+
}
|
|
92
|
+
if (command === 'Z' || command === 'z') {
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
type: 'Z',
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
if (command === 'A') {
|
|
100
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
101
|
+
type: command,
|
|
102
|
+
rx: numbers[0],
|
|
103
|
+
ry: numbers[1],
|
|
104
|
+
xAxisRotation: numbers[2],
|
|
105
|
+
largeArcFlag: numbers[3] === 1,
|
|
106
|
+
sweepFlag: numbers[4] === 1,
|
|
107
|
+
x: numbers[5],
|
|
108
|
+
y: numbers[6],
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
if (command === 'a') {
|
|
112
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
113
|
+
type: command,
|
|
114
|
+
rx: numbers[0],
|
|
115
|
+
ry: numbers[1],
|
|
116
|
+
xAxisRotation: numbers[2],
|
|
117
|
+
largeArcFlag: numbers[3] === 1,
|
|
118
|
+
sweepFlag: numbers[4] === 1,
|
|
119
|
+
dx: numbers[5],
|
|
120
|
+
dy: numbers[6],
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
if (command === 'C') {
|
|
124
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
125
|
+
type: command,
|
|
126
|
+
cp1x: numbers[0],
|
|
127
|
+
cp1y: numbers[1],
|
|
128
|
+
cp2x: numbers[2],
|
|
129
|
+
cp2y: numbers[3],
|
|
130
|
+
x: numbers[4],
|
|
131
|
+
y: numbers[5],
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
if (command === 'c') {
|
|
135
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
136
|
+
type: command,
|
|
137
|
+
cp1dx: numbers[0],
|
|
138
|
+
cp1dy: numbers[1],
|
|
139
|
+
cp2dx: numbers[2],
|
|
140
|
+
cp2dy: numbers[3],
|
|
141
|
+
dx: numbers[4],
|
|
142
|
+
dy: numbers[5],
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
if (command === 'S') {
|
|
146
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
147
|
+
type: command,
|
|
148
|
+
cpx: numbers[0],
|
|
149
|
+
cpy: numbers[1],
|
|
150
|
+
x: numbers[2],
|
|
151
|
+
y: numbers[3],
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
if (command === 's') {
|
|
155
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
156
|
+
type: command,
|
|
157
|
+
cpdx: numbers[0],
|
|
158
|
+
cpdy: numbers[1],
|
|
159
|
+
dx: numbers[2],
|
|
160
|
+
dy: numbers[3],
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
if (command === 'H') {
|
|
164
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
165
|
+
type: command,
|
|
166
|
+
x: numbers[0],
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
if (command === 'h') {
|
|
170
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
171
|
+
type: command,
|
|
172
|
+
dx: numbers[0],
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
if (command === 'V') {
|
|
176
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
177
|
+
type: command,
|
|
178
|
+
y: numbers[0],
|
|
179
|
+
}));
|
|
180
|
+
}
|
|
181
|
+
if (command === 'v') {
|
|
182
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
183
|
+
type: command,
|
|
184
|
+
dy: numbers[0],
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
if (command === 'L') {
|
|
188
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
189
|
+
type: command,
|
|
190
|
+
x: numbers[0],
|
|
191
|
+
y: numbers[1],
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
if (command === 'M') {
|
|
195
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
196
|
+
type: command,
|
|
197
|
+
x: numbers[0],
|
|
198
|
+
y: numbers[1],
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
if (command === 'm') {
|
|
202
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
203
|
+
type: command,
|
|
204
|
+
dx: numbers[0],
|
|
205
|
+
dy: numbers[1],
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
if (command === 'l') {
|
|
209
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
210
|
+
type: command,
|
|
211
|
+
dx: numbers[0],
|
|
212
|
+
dy: numbers[1],
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
if (command === 'Q') {
|
|
216
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
217
|
+
type: command,
|
|
218
|
+
cpx: numbers[0],
|
|
219
|
+
cpy: numbers[1],
|
|
220
|
+
x: numbers[2],
|
|
221
|
+
y: numbers[3],
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
if (command === 'q') {
|
|
225
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
226
|
+
type: command,
|
|
227
|
+
cpdx: numbers[0],
|
|
228
|
+
cpdy: numbers[1],
|
|
229
|
+
dx: numbers[2],
|
|
230
|
+
dy: numbers[3],
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
if (command === 'T') {
|
|
234
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
235
|
+
type: command,
|
|
236
|
+
x: numbers[0],
|
|
237
|
+
y: numbers[1],
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
if (command === 't') {
|
|
241
|
+
return makeInstructions(args, command, (numbers) => ({
|
|
242
|
+
type: command,
|
|
243
|
+
dx: numbers[0],
|
|
244
|
+
dy: numbers[1],
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
throw new Error(`Invalid path element ${segmentString}`);
|
|
248
|
+
}, [])
|
|
249
|
+
.flat(1);
|
|
250
|
+
};
|
|
251
|
+
exports.parsePath = parsePath;
|
|
252
|
+
const parseValues = (args, instructionType) => {
|
|
253
|
+
const numbers = args.match(numberRegExp);
|
|
254
|
+
if (!numbers) {
|
|
255
|
+
if (instructionType === 'Z' || instructionType === 'z') {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
throw new Error(`Malformed path data: ${instructionType} was expected to have numbers afterwards`);
|
|
259
|
+
}
|
|
260
|
+
const expectedArguments = length[instructionType];
|
|
261
|
+
if (numbers.length % expectedArguments !== 0) {
|
|
262
|
+
throw new Error(`Malformed path data: ${instructionType} was expected to have a multiple of ${expectedArguments} numbers, but got "${instructionType} ${numbers.join(' ')} instead"`);
|
|
263
|
+
}
|
|
264
|
+
return numbers.map(Number);
|
|
265
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Instruction, ReducedInstruction } from './helpers/types';
|
|
2
|
+
/**
|
|
3
|
+
* @description Takes an array of Instruction's and reduces the amount of instruction types them so the path only consists of M, L, C, Q and Z instructions.
|
|
4
|
+
* @param {Array} instruction
|
|
5
|
+
* @see [Documentation](https://www.remotion.dev/docs/paths/reduce-instructions)
|
|
6
|
+
*/
|
|
7
|
+
export declare const reduceInstructions: (instruction: Instruction[]) => ReducedInstruction[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reduceInstructions = void 0;
|
|
4
|
+
const remove_a_s_t_curves_1 = require("./helpers/remove-a-s-t-curves");
|
|
5
|
+
const normalize_path_1 = require("./normalize-path");
|
|
6
|
+
/**
|
|
7
|
+
* @description Takes an array of Instruction's and reduces the amount of instruction types them so the path only consists of M, L, C, Q and Z instructions.
|
|
8
|
+
* @param {Array} instruction
|
|
9
|
+
* @see [Documentation](https://www.remotion.dev/docs/paths/reduce-instructions)
|
|
10
|
+
*/
|
|
11
|
+
const reduceInstructions = (instruction) => {
|
|
12
|
+
const simplified = (0, normalize_path_1.normalizeInstructions)(instruction);
|
|
13
|
+
return (0, remove_a_s_t_curves_1.removeATSHVInstructions)(simplified);
|
|
14
|
+
};
|
|
15
|
+
exports.reduceInstructions = reduceInstructions;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Translates an SVG path so that the top-left corner of the bounding box is at 0, 0.
|
|
3
|
+
* @param {string} d a valid SVG path
|
|
4
|
+
* @see [Documentation](https://www.remotion.dev/docs/paths/reset-path)
|
|
5
|
+
*/
|
|
6
|
+
export declare const resetPath: (d: string) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetPath = void 0;
|
|
4
|
+
const get_bounding_box_1 = require("./get-bounding-box");
|
|
5
|
+
const translate_path_1 = require("./translate-path");
|
|
6
|
+
/**
|
|
7
|
+
* @description Translates an SVG path so that the top-left corner of the bounding box is at 0, 0.
|
|
8
|
+
* @param {string} d a valid SVG path
|
|
9
|
+
* @see [Documentation](https://www.remotion.dev/docs/paths/reset-path)
|
|
10
|
+
*/
|
|
11
|
+
const resetPath = (d) => {
|
|
12
|
+
const box = (0, get_bounding_box_1.getBoundingBox)(d);
|
|
13
|
+
return (0, translate_path_1.translatePath)(d, -box.x1, -box.y1);
|
|
14
|
+
};
|
|
15
|
+
exports.resetPath = resetPath;
|
package/dist/reverse-path.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* not recognise the public domain, where this code is MIT licensed.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
* Reverses a path so the end and start are switched.
|
|
8
|
+
* @description Reverses a path so the end and start are switched.
|
|
9
9
|
* @param {string} path A valid SVG path
|
|
10
|
-
* @
|
|
10
|
+
* @see [Documentation](https://remotion.dev/docs/paths/reverse-path)
|
|
11
11
|
*/
|
|
12
12
|
export declare const reversePath: (path: string) => string;
|
package/dist/reverse-path.js
CHANGED
|
@@ -7,139 +7,94 @@
|
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
//
|
|
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
|
|
62
|
+
}
|
|
63
|
+
else if (term.type === 'Z') {
|
|
64
|
+
// Do nothing
|
|
100
65
|
}
|
|
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
66
|
else {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
' (' +
|
|
112
|
-
range +
|
|
113
|
-
').\n' +
|
|
114
|
-
"Either the path is not normalised, or it's malformed.");
|
|
67
|
+
throw new Error('unnormalized instruction ' + term.type);
|
|
68
|
+
}
|
|
69
|
+
if (term.type !== 'Z') {
|
|
70
|
+
nextX = term.x;
|
|
71
|
+
nextY = term.y;
|
|
115
72
|
}
|
|
116
73
|
}
|
|
117
|
-
reversed.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
let
|
|
123
|
-
|
|
124
|
-
revstring += reversed[r] + ' ';
|
|
125
|
-
}
|
|
126
|
-
if (closed)
|
|
74
|
+
reversed.unshift({
|
|
75
|
+
type: 'M',
|
|
76
|
+
x: nextX,
|
|
77
|
+
y: nextY,
|
|
78
|
+
});
|
|
79
|
+
let revstring = (0, serialize_instructions_1.serializeInstructions)(reversed);
|
|
80
|
+
if (instructions[instructions.length - 1].type === 'Z')
|
|
127
81
|
revstring += 'Z';
|
|
128
82
|
revstring = revstring.replace(/M M/g, 'Z M');
|
|
129
83
|
return revstring;
|
|
130
84
|
}
|
|
131
85
|
/**
|
|
132
|
-
* Reverses a path so the end and start are switched.
|
|
86
|
+
* @description Reverses a path so the end and start are switched.
|
|
133
87
|
* @param {string} path A valid SVG path
|
|
134
|
-
* @
|
|
88
|
+
* @see [Documentation](https://remotion.dev/docs/paths/reverse-path)
|
|
135
89
|
*/
|
|
136
90
|
const reversePath = (path) => {
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
91
|
+
const parsed = (0, parse_path_1.parsePath)(path);
|
|
92
|
+
const normalized = (0, normalize_path_1.normalizeInstructions)(parsed);
|
|
93
|
+
const reduced = (0, reduce_instructions_1.reduceInstructions)(normalized);
|
|
94
|
+
const { segments } = (0, construct_1.constructFromInstructions)(reduced);
|
|
95
|
+
return segments
|
|
141
96
|
.map((spath) => {
|
|
142
|
-
return reverseNormalizedPath(spath
|
|
97
|
+
return reverseNormalizedPath(spath);
|
|
143
98
|
})
|
|
144
99
|
.join(' ')
|
|
145
100
|
.replace(/ +/g, ' ')
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Allows you to grow or shrink the size of a path.
|
|
3
|
+
* @param {string} path A valid SVG path
|
|
4
|
+
* @param {string} d
|
|
5
|
+
* @param {Number} scaleX
|
|
6
|
+
* @param {Number} scaleY
|
|
7
|
+
* @returns a new path with respect to the scale values provided
|
|
8
|
+
* @see [Documentation](https://www.remotion.dev/docs/paths/scale-path)
|
|
9
|
+
*/
|
|
10
|
+
export declare const scalePath: (d: string, scaleX: number, scaleY: number) => string;
|