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