@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
|
@@ -1,114 +1,159 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copied from: https://github.com/rveciana/svg-path-properties
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.construct = void 0;
|
|
4
|
+
exports.construct = exports.constructFromInstructions = void 0;
|
|
5
|
+
const parse_path_1 = require("../parse-path");
|
|
8
6
|
const arc_1 = require("./arc");
|
|
9
7
|
const bezier_1 = require("./bezier");
|
|
10
8
|
const linear_1 = require("./linear");
|
|
11
|
-
const
|
|
12
|
-
const construct = (string) => {
|
|
9
|
+
const constructFromInstructions = (instructions) => {
|
|
13
10
|
let length = 0;
|
|
14
11
|
const partial_lengths = [];
|
|
15
12
|
const functions = [];
|
|
16
13
|
let initial_point = null;
|
|
17
|
-
const parsed = (0, parse_1.default)(string);
|
|
18
14
|
let cur = [0, 0];
|
|
19
15
|
let prev_point = [0, 0];
|
|
20
16
|
let curve;
|
|
21
17
|
let ringStart = [0, 0];
|
|
22
|
-
|
|
18
|
+
const segments = [];
|
|
19
|
+
for (let i = 0; i < instructions.length; i++) {
|
|
20
|
+
const instruction = instructions[i];
|
|
21
|
+
if (instruction.type !== 'm' &&
|
|
22
|
+
instruction.type !== 'M' &&
|
|
23
|
+
segments.length > 0) {
|
|
24
|
+
segments[segments.length - 1].push(instruction);
|
|
25
|
+
}
|
|
23
26
|
// moveTo
|
|
24
|
-
if (
|
|
25
|
-
cur = [
|
|
27
|
+
if (instruction.type === 'M') {
|
|
28
|
+
cur = [instruction.x, instruction.y];
|
|
26
29
|
ringStart = [cur[0], cur[1]];
|
|
30
|
+
segments.push([instruction]);
|
|
27
31
|
functions.push(null);
|
|
28
32
|
if (i === 0) {
|
|
29
|
-
initial_point = { x:
|
|
33
|
+
initial_point = { x: instruction.x, y: instruction.y };
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
|
-
else if (
|
|
33
|
-
cur = [
|
|
36
|
+
else if (instruction.type === 'm') {
|
|
37
|
+
cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
|
|
34
38
|
ringStart = [cur[0], cur[1]];
|
|
39
|
+
segments.push([{ type: 'M', x: cur[0], y: cur[1] }]);
|
|
35
40
|
functions.push(null);
|
|
36
41
|
// lineTo
|
|
37
42
|
}
|
|
38
|
-
else if (
|
|
39
|
-
length += Math.sqrt((cur[0] -
|
|
40
|
-
functions.push((0, linear_1.makeLinearPosition)(
|
|
41
|
-
|
|
43
|
+
else if (instruction.type === 'L') {
|
|
44
|
+
length += Math.sqrt((cur[0] - instruction.x) ** 2 + (cur[1] - instruction.y) ** 2);
|
|
45
|
+
functions.push((0, linear_1.makeLinearPosition)({
|
|
46
|
+
x0: cur[0],
|
|
47
|
+
x1: instruction.x,
|
|
48
|
+
y0: cur[1],
|
|
49
|
+
y1: instruction.y,
|
|
50
|
+
}));
|
|
51
|
+
cur = [instruction.x, instruction.y];
|
|
42
52
|
}
|
|
43
|
-
else if (
|
|
44
|
-
length += Math.sqrt(
|
|
45
|
-
functions.push((0, linear_1.makeLinearPosition)(
|
|
46
|
-
|
|
53
|
+
else if (instruction.type === 'l') {
|
|
54
|
+
length += Math.sqrt(instruction.dx ** 2 + instruction.dy ** 2);
|
|
55
|
+
functions.push((0, linear_1.makeLinearPosition)({
|
|
56
|
+
x0: cur[0],
|
|
57
|
+
x1: instruction.dx + cur[0],
|
|
58
|
+
y0: cur[1],
|
|
59
|
+
y1: instruction.dy + cur[1],
|
|
60
|
+
}));
|
|
61
|
+
cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
|
|
47
62
|
}
|
|
48
|
-
else if (
|
|
49
|
-
length += Math.abs(cur[0] -
|
|
50
|
-
functions.push((0, linear_1.makeLinearPosition)(
|
|
51
|
-
|
|
63
|
+
else if (instruction.type === 'H') {
|
|
64
|
+
length += Math.abs(cur[0] - instruction.x);
|
|
65
|
+
functions.push((0, linear_1.makeLinearPosition)({
|
|
66
|
+
x0: cur[0],
|
|
67
|
+
x1: instruction.x,
|
|
68
|
+
y0: cur[1],
|
|
69
|
+
y1: cur[1],
|
|
70
|
+
}));
|
|
71
|
+
cur[0] = instruction.x;
|
|
52
72
|
}
|
|
53
|
-
else if (
|
|
54
|
-
length += Math.abs(
|
|
55
|
-
functions.push((0, linear_1.makeLinearPosition)(
|
|
56
|
-
|
|
73
|
+
else if (instruction.type === 'h') {
|
|
74
|
+
length += Math.abs(instruction.dx);
|
|
75
|
+
functions.push((0, linear_1.makeLinearPosition)({
|
|
76
|
+
x0: cur[0],
|
|
77
|
+
x1: cur[0] + instruction.dx,
|
|
78
|
+
y0: cur[1],
|
|
79
|
+
y1: cur[1],
|
|
80
|
+
}));
|
|
81
|
+
cur[0] = instruction.dx + cur[0];
|
|
57
82
|
}
|
|
58
|
-
else if (
|
|
59
|
-
length += Math.abs(cur[1] -
|
|
60
|
-
functions.push((0, linear_1.makeLinearPosition)(
|
|
61
|
-
|
|
83
|
+
else if (instruction.type === 'V') {
|
|
84
|
+
length += Math.abs(cur[1] - instruction.y);
|
|
85
|
+
functions.push((0, linear_1.makeLinearPosition)({
|
|
86
|
+
x0: cur[0],
|
|
87
|
+
x1: cur[0],
|
|
88
|
+
y0: cur[1],
|
|
89
|
+
y1: instruction.y,
|
|
90
|
+
}));
|
|
91
|
+
cur[1] = instruction.y;
|
|
62
92
|
}
|
|
63
|
-
else if (
|
|
64
|
-
length += Math.abs(
|
|
65
|
-
functions.push((0, linear_1.makeLinearPosition)(
|
|
66
|
-
|
|
93
|
+
else if (instruction.type === 'v') {
|
|
94
|
+
length += Math.abs(instruction.dy);
|
|
95
|
+
functions.push((0, linear_1.makeLinearPosition)({
|
|
96
|
+
x0: cur[0],
|
|
97
|
+
x1: cur[0],
|
|
98
|
+
y0: cur[1],
|
|
99
|
+
y1: cur[1] + instruction.dy,
|
|
100
|
+
}));
|
|
101
|
+
cur[1] = instruction.dy + cur[1];
|
|
67
102
|
// Close path
|
|
68
103
|
}
|
|
69
|
-
else if (
|
|
104
|
+
else if (instruction.type === 'Z') {
|
|
70
105
|
length += Math.sqrt((ringStart[0] - cur[0]) ** 2 + (ringStart[1] - cur[1]) ** 2);
|
|
71
|
-
functions.push((0, linear_1.makeLinearPosition)(
|
|
106
|
+
functions.push((0, linear_1.makeLinearPosition)({
|
|
107
|
+
x0: cur[0],
|
|
108
|
+
x1: ringStart[0],
|
|
109
|
+
y0: cur[1],
|
|
110
|
+
y1: ringStart[1],
|
|
111
|
+
}));
|
|
72
112
|
cur = [ringStart[0], ringStart[1]];
|
|
73
113
|
// Cubic Bezier curves
|
|
74
114
|
}
|
|
75
|
-
else if (
|
|
115
|
+
else if (instruction.type === 'C') {
|
|
76
116
|
curve = (0, bezier_1.makeBezier)({
|
|
77
117
|
ax: cur[0],
|
|
78
118
|
ay: cur[1],
|
|
79
|
-
bx:
|
|
80
|
-
by:
|
|
81
|
-
cx:
|
|
82
|
-
cy:
|
|
83
|
-
dx:
|
|
84
|
-
dy:
|
|
119
|
+
bx: instruction.cp1x,
|
|
120
|
+
by: instruction.cp1y,
|
|
121
|
+
cx: instruction.cp2x,
|
|
122
|
+
cy: instruction.cp2y,
|
|
123
|
+
dx: instruction.x,
|
|
124
|
+
dy: instruction.y,
|
|
85
125
|
});
|
|
86
126
|
length += curve.getTotalLength();
|
|
87
|
-
cur = [
|
|
127
|
+
cur = [instruction.x, instruction.y];
|
|
88
128
|
functions.push(curve);
|
|
89
129
|
}
|
|
90
|
-
else if (
|
|
130
|
+
else if (instruction.type === 'c') {
|
|
91
131
|
curve = (0, bezier_1.makeBezier)({
|
|
92
132
|
ax: cur[0],
|
|
93
133
|
ay: cur[1],
|
|
94
|
-
bx: cur[0] +
|
|
95
|
-
by: cur[1] +
|
|
96
|
-
cx: cur[0] +
|
|
97
|
-
cy: cur[1] +
|
|
98
|
-
dx: cur[0] +
|
|
99
|
-
dy: cur[1] +
|
|
134
|
+
bx: cur[0] + instruction.cp1dx,
|
|
135
|
+
by: cur[1] + instruction.cp1dy,
|
|
136
|
+
cx: cur[0] + instruction.cp2dx,
|
|
137
|
+
cy: cur[1] + instruction.cp2dy,
|
|
138
|
+
dx: cur[0] + instruction.dx,
|
|
139
|
+
dy: cur[1] + instruction.dy,
|
|
100
140
|
});
|
|
101
141
|
if (curve.getTotalLength() > 0) {
|
|
102
142
|
length += curve.getTotalLength();
|
|
103
143
|
functions.push(curve);
|
|
104
|
-
cur = [
|
|
144
|
+
cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
|
|
105
145
|
}
|
|
106
146
|
else {
|
|
107
|
-
functions.push((0, linear_1.makeLinearPosition)(cur[0], cur[0], cur[1], cur[1]));
|
|
147
|
+
functions.push((0, linear_1.makeLinearPosition)({ x0: cur[0], x1: cur[0], y0: cur[1], y1: cur[1] }));
|
|
108
148
|
}
|
|
109
149
|
}
|
|
110
|
-
else if (
|
|
111
|
-
|
|
150
|
+
else if (instruction.type === 'S') {
|
|
151
|
+
const prev = instructions[i - 1];
|
|
152
|
+
const prevWasCurve = prev.type === 'C' ||
|
|
153
|
+
prev.type === 'c' ||
|
|
154
|
+
prev.type === 'S' ||
|
|
155
|
+
prev.type === 's';
|
|
156
|
+
if (i > 0 && prevWasCurve) {
|
|
112
157
|
if (curve) {
|
|
113
158
|
const c = curve.getC();
|
|
114
159
|
curve = (0, bezier_1.makeBezier)({
|
|
@@ -116,10 +161,10 @@ const construct = (string) => {
|
|
|
116
161
|
ay: cur[1],
|
|
117
162
|
bx: 2 * cur[0] - c.x,
|
|
118
163
|
by: 2 * cur[1] - c.y,
|
|
119
|
-
cx:
|
|
120
|
-
cy:
|
|
121
|
-
dx:
|
|
122
|
-
dy:
|
|
164
|
+
cx: instruction.cpx,
|
|
165
|
+
cy: instruction.cpy,
|
|
166
|
+
dx: instruction.x,
|
|
167
|
+
dy: instruction.y,
|
|
123
168
|
});
|
|
124
169
|
}
|
|
125
170
|
}
|
|
@@ -129,21 +174,25 @@ const construct = (string) => {
|
|
|
129
174
|
ay: cur[1],
|
|
130
175
|
bx: cur[0],
|
|
131
176
|
by: cur[1],
|
|
132
|
-
cx:
|
|
133
|
-
cy:
|
|
134
|
-
dx:
|
|
135
|
-
dy:
|
|
177
|
+
cx: instruction.cpx,
|
|
178
|
+
cy: instruction.cpy,
|
|
179
|
+
dx: instruction.x,
|
|
180
|
+
dy: instruction.y,
|
|
136
181
|
});
|
|
137
182
|
}
|
|
138
183
|
if (curve) {
|
|
139
184
|
length += curve.getTotalLength();
|
|
140
|
-
cur = [
|
|
185
|
+
cur = [instruction.x, instruction.y];
|
|
141
186
|
functions.push(curve);
|
|
142
187
|
}
|
|
143
188
|
}
|
|
144
|
-
else if (
|
|
145
|
-
|
|
146
|
-
|
|
189
|
+
else if (instruction.type === 's') {
|
|
190
|
+
const prev = instructions[i - 1];
|
|
191
|
+
const prevWasCurve = prev.type === 'C' ||
|
|
192
|
+
prev.type === 'c' ||
|
|
193
|
+
prev.type === 'S' ||
|
|
194
|
+
prev.type === 's';
|
|
195
|
+
if (i > 0 && prevWasCurve) {
|
|
147
196
|
if (curve) {
|
|
148
197
|
const c = curve.getC();
|
|
149
198
|
const d = curve.getD();
|
|
@@ -152,10 +201,10 @@ const construct = (string) => {
|
|
|
152
201
|
ay: cur[1],
|
|
153
202
|
bx: cur[0] + d.x - c.x,
|
|
154
203
|
by: cur[1] + d.y - c.y,
|
|
155
|
-
cx: cur[0] +
|
|
156
|
-
cy: cur[1] +
|
|
157
|
-
dx: cur[0] +
|
|
158
|
-
dy: cur[1] +
|
|
204
|
+
cx: cur[0] + instruction.cpdx,
|
|
205
|
+
cy: cur[1] + instruction.cpdy,
|
|
206
|
+
dx: cur[0] + instruction.dx,
|
|
207
|
+
dy: cur[1] + instruction.dy,
|
|
159
208
|
});
|
|
160
209
|
}
|
|
161
210
|
}
|
|
@@ -165,22 +214,27 @@ const construct = (string) => {
|
|
|
165
214
|
ay: cur[1],
|
|
166
215
|
bx: cur[0],
|
|
167
216
|
by: cur[1],
|
|
168
|
-
cx: cur[0] +
|
|
169
|
-
cy: cur[1] +
|
|
170
|
-
dx: cur[0] +
|
|
171
|
-
dy: cur[1] +
|
|
217
|
+
cx: cur[0] + instruction.cpdx,
|
|
218
|
+
cy: cur[1] + instruction.cpdy,
|
|
219
|
+
dx: cur[0] + instruction.dx,
|
|
220
|
+
dy: cur[1] + instruction.dy,
|
|
172
221
|
});
|
|
173
222
|
}
|
|
174
223
|
if (curve) {
|
|
175
224
|
length += curve.getTotalLength();
|
|
176
|
-
cur = [
|
|
225
|
+
cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
|
|
177
226
|
functions.push(curve);
|
|
178
227
|
}
|
|
179
228
|
}
|
|
180
229
|
// Quadratic Bezier curves
|
|
181
|
-
else if (
|
|
182
|
-
if (cur[0] ===
|
|
183
|
-
const linearCurve = (0, linear_1.makeLinearPosition)(
|
|
230
|
+
else if (instruction.type === 'Q') {
|
|
231
|
+
if (cur[0] === instruction.cpx && cur[1] === instruction.cpy) {
|
|
232
|
+
const linearCurve = (0, linear_1.makeLinearPosition)({
|
|
233
|
+
x0: instruction.cpx,
|
|
234
|
+
x1: instruction.x,
|
|
235
|
+
y0: instruction.cpy,
|
|
236
|
+
y1: instruction.y,
|
|
237
|
+
});
|
|
184
238
|
length += linearCurve.getTotalLength();
|
|
185
239
|
functions.push(linearCurve);
|
|
186
240
|
}
|
|
@@ -188,22 +242,27 @@ const construct = (string) => {
|
|
|
188
242
|
curve = (0, bezier_1.makeBezier)({
|
|
189
243
|
ax: cur[0],
|
|
190
244
|
ay: cur[1],
|
|
191
|
-
bx:
|
|
192
|
-
by:
|
|
193
|
-
cx:
|
|
194
|
-
cy:
|
|
245
|
+
bx: instruction.cpx,
|
|
246
|
+
by: instruction.cpy,
|
|
247
|
+
cx: instruction.x,
|
|
248
|
+
cy: instruction.y,
|
|
195
249
|
dx: null,
|
|
196
250
|
dy: null,
|
|
197
251
|
});
|
|
198
252
|
length += curve.getTotalLength();
|
|
199
253
|
functions.push(curve);
|
|
200
254
|
}
|
|
201
|
-
cur = [
|
|
202
|
-
prev_point = [
|
|
255
|
+
cur = [instruction.x, instruction.y];
|
|
256
|
+
prev_point = [instruction.cpx, instruction.cpy];
|
|
203
257
|
}
|
|
204
|
-
else if (
|
|
205
|
-
if (
|
|
206
|
-
const linearCurve = (0, linear_1.makeLinearPosition)(
|
|
258
|
+
else if (instruction.type === 'q') {
|
|
259
|
+
if (instruction.cpdx === 0 && instruction.cpdy === 0) {
|
|
260
|
+
const linearCurve = (0, linear_1.makeLinearPosition)({
|
|
261
|
+
x0: cur[0] + instruction.cpdx,
|
|
262
|
+
x1: cur[0] + instruction.cpdy,
|
|
263
|
+
y0: cur[1] + instruction.dx,
|
|
264
|
+
y1: cur[1] + instruction.dy,
|
|
265
|
+
});
|
|
207
266
|
length += linearCurve.getTotalLength();
|
|
208
267
|
functions.push(linearCurve);
|
|
209
268
|
}
|
|
@@ -211,28 +270,33 @@ const construct = (string) => {
|
|
|
211
270
|
curve = (0, bezier_1.makeBezier)({
|
|
212
271
|
ax: cur[0],
|
|
213
272
|
ay: cur[1],
|
|
214
|
-
bx: cur[0] +
|
|
215
|
-
by: cur[1] +
|
|
216
|
-
cx: cur[0] +
|
|
217
|
-
cy: cur[1] +
|
|
273
|
+
bx: cur[0] + instruction.cpdx,
|
|
274
|
+
by: cur[1] + instruction.cpdy,
|
|
275
|
+
cx: cur[0] + instruction.dx,
|
|
276
|
+
cy: cur[1] + instruction.dy,
|
|
218
277
|
dx: null,
|
|
219
278
|
dy: null,
|
|
220
279
|
});
|
|
221
280
|
length += curve.getTotalLength();
|
|
222
281
|
functions.push(curve);
|
|
223
282
|
}
|
|
224
|
-
prev_point = [cur[0] +
|
|
225
|
-
cur = [
|
|
283
|
+
prev_point = [cur[0] + instruction.cpdx, cur[1] + instruction.cpdy];
|
|
284
|
+
cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
|
|
226
285
|
}
|
|
227
|
-
else if (
|
|
228
|
-
|
|
286
|
+
else if (instruction.type === 'T') {
|
|
287
|
+
const prev = instructions[i - 1];
|
|
288
|
+
const prevWasQ = prev.type === 'Q' ||
|
|
289
|
+
prev.type === 'q' ||
|
|
290
|
+
prev.type === 'T' ||
|
|
291
|
+
prev.type === 't';
|
|
292
|
+
if (i > 0 && prevWasQ) {
|
|
229
293
|
curve = (0, bezier_1.makeBezier)({
|
|
230
294
|
ax: cur[0],
|
|
231
295
|
ay: cur[1],
|
|
232
296
|
bx: 2 * cur[0] - prev_point[0],
|
|
233
297
|
by: 2 * cur[1] - prev_point[1],
|
|
234
|
-
cx:
|
|
235
|
-
cy:
|
|
298
|
+
cx: instruction.x,
|
|
299
|
+
cy: instruction.y,
|
|
236
300
|
dx: null,
|
|
237
301
|
dy: null,
|
|
238
302
|
});
|
|
@@ -240,22 +304,32 @@ const construct = (string) => {
|
|
|
240
304
|
length += curve.getTotalLength();
|
|
241
305
|
}
|
|
242
306
|
else {
|
|
243
|
-
const linearCurve = (0, linear_1.makeLinearPosition)(
|
|
307
|
+
const linearCurve = (0, linear_1.makeLinearPosition)({
|
|
308
|
+
x0: cur[0],
|
|
309
|
+
x1: instruction.x,
|
|
310
|
+
y0: cur[1],
|
|
311
|
+
y1: instruction.y,
|
|
312
|
+
});
|
|
244
313
|
functions.push(linearCurve);
|
|
245
314
|
length += linearCurve.getTotalLength();
|
|
246
315
|
}
|
|
247
316
|
prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
|
|
248
|
-
cur = [
|
|
317
|
+
cur = [instruction.x, instruction.y];
|
|
249
318
|
}
|
|
250
|
-
else if (
|
|
251
|
-
|
|
319
|
+
else if (instruction.type === 't') {
|
|
320
|
+
const prev = instructions[i - 1];
|
|
321
|
+
const prevWasQ = prev.type === 'Q' ||
|
|
322
|
+
prev.type === 'q' ||
|
|
323
|
+
prev.type === 'T' ||
|
|
324
|
+
prev.type === 't';
|
|
325
|
+
if (i > 0 && prevWasQ) {
|
|
252
326
|
curve = (0, bezier_1.makeBezier)({
|
|
253
327
|
ax: cur[0],
|
|
254
328
|
ay: cur[1],
|
|
255
329
|
bx: 2 * cur[0] - prev_point[0],
|
|
256
330
|
by: 2 * cur[1] - prev_point[1],
|
|
257
|
-
cx: cur[0] +
|
|
258
|
-
cy: cur[1] +
|
|
331
|
+
cx: cur[0] + instruction.dx,
|
|
332
|
+
cy: cur[1] + instruction.dy,
|
|
259
333
|
dx: null,
|
|
260
334
|
dy: null,
|
|
261
335
|
});
|
|
@@ -263,47 +337,63 @@ const construct = (string) => {
|
|
|
263
337
|
functions.push(curve);
|
|
264
338
|
}
|
|
265
339
|
else {
|
|
266
|
-
const linearCurve = (0, linear_1.makeLinearPosition)(
|
|
340
|
+
const linearCurve = (0, linear_1.makeLinearPosition)({
|
|
341
|
+
x0: cur[0],
|
|
342
|
+
x1: cur[0] + instruction.dx,
|
|
343
|
+
y0: cur[1],
|
|
344
|
+
y1: cur[1] + instruction.dy,
|
|
345
|
+
});
|
|
267
346
|
length += linearCurve.getTotalLength();
|
|
268
347
|
functions.push(linearCurve);
|
|
269
348
|
}
|
|
270
349
|
prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
|
|
271
|
-
cur = [
|
|
350
|
+
cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
|
|
272
351
|
}
|
|
273
|
-
else if (
|
|
352
|
+
else if (instruction.type === 'A') {
|
|
274
353
|
const arcCurve = (0, arc_1.makeArc)({
|
|
275
354
|
x0: cur[0],
|
|
276
355
|
y0: cur[1],
|
|
277
|
-
rx:
|
|
278
|
-
ry:
|
|
279
|
-
xAxisRotate:
|
|
280
|
-
LargeArcFlag:
|
|
281
|
-
SweepFlag:
|
|
282
|
-
x1:
|
|
283
|
-
y1:
|
|
356
|
+
rx: instruction.rx,
|
|
357
|
+
ry: instruction.ry,
|
|
358
|
+
xAxisRotate: instruction.xAxisRotation,
|
|
359
|
+
LargeArcFlag: instruction.largeArcFlag,
|
|
360
|
+
SweepFlag: instruction.sweepFlag,
|
|
361
|
+
x1: instruction.x,
|
|
362
|
+
y1: instruction.y,
|
|
284
363
|
});
|
|
285
364
|
length += arcCurve.getTotalLength();
|
|
286
|
-
cur = [
|
|
365
|
+
cur = [instruction.x, instruction.y];
|
|
287
366
|
functions.push(arcCurve);
|
|
288
367
|
}
|
|
289
|
-
else if (
|
|
368
|
+
else if (instruction.type === 'a') {
|
|
290
369
|
const arcCurve = (0, arc_1.makeArc)({
|
|
291
370
|
x0: cur[0],
|
|
292
371
|
y0: cur[1],
|
|
293
|
-
rx:
|
|
294
|
-
ry:
|
|
295
|
-
xAxisRotate:
|
|
296
|
-
LargeArcFlag:
|
|
297
|
-
SweepFlag:
|
|
298
|
-
x1: cur[0] +
|
|
299
|
-
y1: cur[1] +
|
|
372
|
+
rx: instruction.rx,
|
|
373
|
+
ry: instruction.ry,
|
|
374
|
+
xAxisRotate: instruction.xAxisRotation,
|
|
375
|
+
LargeArcFlag: instruction.largeArcFlag,
|
|
376
|
+
SweepFlag: instruction.sweepFlag,
|
|
377
|
+
x1: cur[0] + instruction.dx,
|
|
378
|
+
y1: cur[1] + instruction.dy,
|
|
300
379
|
});
|
|
301
380
|
length += arcCurve.getTotalLength();
|
|
302
|
-
cur = [cur[0] +
|
|
381
|
+
cur = [cur[0] + instruction.dx, cur[1] + instruction.dy];
|
|
303
382
|
functions.push(arcCurve);
|
|
304
383
|
}
|
|
305
384
|
partial_lengths.push(length);
|
|
306
385
|
}
|
|
307
|
-
return {
|
|
386
|
+
return {
|
|
387
|
+
segments,
|
|
388
|
+
initial_point,
|
|
389
|
+
length,
|
|
390
|
+
partial_lengths,
|
|
391
|
+
functions,
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
exports.constructFromInstructions = constructFromInstructions;
|
|
395
|
+
const construct = (string) => {
|
|
396
|
+
const parsed = (0, parse_path_1.parsePath)(string);
|
|
397
|
+
return (0, exports.constructFromInstructions)(parsed);
|
|
308
398
|
};
|
|
309
399
|
exports.construct = construct;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AbsoluteInstruction, ReducedInstruction } from './types';
|
|
2
|
+
export declare const iterateOverSegments: <T extends ReducedInstruction>({ segments, iterate, }: {
|
|
3
|
+
segments: AbsoluteInstruction[];
|
|
4
|
+
iterate: (options: {
|
|
5
|
+
segment: AbsoluteInstruction;
|
|
6
|
+
prevSegment: AbsoluteInstruction | null;
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
initialX: number;
|
|
10
|
+
initialY: number;
|
|
11
|
+
cpX: number | null;
|
|
12
|
+
cpY: number | null;
|
|
13
|
+
}) => T[];
|
|
14
|
+
}) => T[];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.iterateOverSegments = void 0;
|
|
4
|
+
const iterateOverSegments = ({ segments, iterate, }) => {
|
|
5
|
+
let x = 0;
|
|
6
|
+
let y = 0;
|
|
7
|
+
let initialX = 0;
|
|
8
|
+
let initialY = 0;
|
|
9
|
+
let cpX = null;
|
|
10
|
+
let cpY = null;
|
|
11
|
+
const newSegments = segments.map((s, i) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const newSeg = iterate({
|
|
14
|
+
segment: s,
|
|
15
|
+
x,
|
|
16
|
+
y,
|
|
17
|
+
prevSegment: (_a = segments[i - 1]) !== null && _a !== void 0 ? _a : null,
|
|
18
|
+
initialX,
|
|
19
|
+
initialY,
|
|
20
|
+
cpX,
|
|
21
|
+
cpY,
|
|
22
|
+
});
|
|
23
|
+
switch (s.type) {
|
|
24
|
+
case 'M':
|
|
25
|
+
initialX = s.x;
|
|
26
|
+
initialY = s.y;
|
|
27
|
+
x = s.x;
|
|
28
|
+
y = s.y;
|
|
29
|
+
cpX = null;
|
|
30
|
+
cpY = null;
|
|
31
|
+
break;
|
|
32
|
+
case 'Q':
|
|
33
|
+
x = s.x;
|
|
34
|
+
y = s.y;
|
|
35
|
+
cpX = s.cpx;
|
|
36
|
+
cpY = s.cpy;
|
|
37
|
+
break;
|
|
38
|
+
case 'A':
|
|
39
|
+
x = s.x;
|
|
40
|
+
y = s.y;
|
|
41
|
+
cpX = null;
|
|
42
|
+
cpY = null;
|
|
43
|
+
break;
|
|
44
|
+
case 'C':
|
|
45
|
+
x = s.x;
|
|
46
|
+
y = s.y;
|
|
47
|
+
cpX = s.cp2x;
|
|
48
|
+
cpY = s.cp2y;
|
|
49
|
+
break;
|
|
50
|
+
case 'S':
|
|
51
|
+
x = s.x;
|
|
52
|
+
y = s.y;
|
|
53
|
+
cpX = s.cpx;
|
|
54
|
+
cpY = s.cpy;
|
|
55
|
+
break;
|
|
56
|
+
case 'T':
|
|
57
|
+
// Order of if statement is important here
|
|
58
|
+
if (cpX !== null && cpY !== null) {
|
|
59
|
+
cpX = x - (cpX - x);
|
|
60
|
+
cpY = y - (cpY - y);
|
|
61
|
+
}
|
|
62
|
+
x = s.x;
|
|
63
|
+
y = s.y;
|
|
64
|
+
break;
|
|
65
|
+
case 'L':
|
|
66
|
+
x = s.x;
|
|
67
|
+
y = s.y;
|
|
68
|
+
cpX = null;
|
|
69
|
+
cpY = null;
|
|
70
|
+
break;
|
|
71
|
+
case 'V':
|
|
72
|
+
y = s.y;
|
|
73
|
+
cpX = null;
|
|
74
|
+
cpY = null;
|
|
75
|
+
break;
|
|
76
|
+
case 'H':
|
|
77
|
+
x = s.x;
|
|
78
|
+
cpX = null;
|
|
79
|
+
cpY = null;
|
|
80
|
+
break;
|
|
81
|
+
case 'Z':
|
|
82
|
+
x = initialX;
|
|
83
|
+
y = initialY;
|
|
84
|
+
cpX = null;
|
|
85
|
+
cpY = null;
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
throw new Error(`Unexpected instruction ${s.type}`);
|
|
90
|
+
}
|
|
91
|
+
return newSeg;
|
|
92
|
+
});
|
|
93
|
+
return newSegments.flat(1);
|
|
94
|
+
};
|
|
95
|
+
exports.iterateOverSegments = iterateOverSegments;
|
package/dist/helpers/linear.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Point, PointProperties } from './types';
|
|
2
|
-
export declare const makeLinearPosition: (x0
|
|
2
|
+
export declare const makeLinearPosition: ({ x0, x1, y0, y1, }: {
|
|
3
|
+
x0: number;
|
|
4
|
+
x1: number;
|
|
5
|
+
y0: number;
|
|
6
|
+
y1: number;
|
|
7
|
+
}) => {
|
|
3
8
|
getTotalLength: () => number;
|
|
4
9
|
getPointAtLength: (pos: number) => Point;
|
|
5
10
|
getTangentAtLength: () => Point;
|
package/dist/helpers/linear.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeLinearPosition = void 0;
|
|
4
|
-
const makeLinearPosition = (x0, x1, y0, y1) => {
|
|
4
|
+
const makeLinearPosition = ({ x0, x1, y0, y1, }) => {
|
|
5
5
|
const getTotalLength = () => {
|
|
6
6
|
return Math.sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2);
|
|
7
7
|
};
|