@remotion/paths 4.0.0-newpathfunctions.13 → 4.0.0-newpaths.1

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.
@@ -1,9 +1,9 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBoundingBox = void 0;
4
+ const remove_a_s_t_curves_1 = require("./helpers/remove-a-s-t-curves");
4
5
  const normalize_path_1 = require("./normalize-path");
5
- const unarc_1 = require("./unarc");
6
- const unshort_1 = require("./unshort");
6
+ const parse_path_1 = require("./parse-path");
7
7
  // Precision for consider cubic polynom as quadratic one
8
8
  const CBEZIER_MINMAX_EPSILON = 0.00000001;
9
9
  // https://github.com/kpym/SVGPathy/blob/acd1a50c626b36d81969f6e98e8602e128ba4302/lib/box.js#L89
@@ -72,91 +72,73 @@ const getBoundingBox = (d) => {
72
72
  let minY = Infinity;
73
73
  let maxX = -Infinity;
74
74
  let maxY = -Infinity;
75
- const abs = (0, normalize_path_1.normalizePath)(d);
76
- const unarced = (0, unarc_1.unarc)(abs);
77
- const unshortened = (0, unshort_1.unshort)(unarced);
75
+ const parsed = (0, parse_path_1.parsePath)((0, normalize_path_1.normalizePath)(d));
76
+ const unarced = (0, remove_a_s_t_curves_1.removeATSHVInstructions)(parsed);
78
77
  let x = 0;
79
78
  let y = 0;
80
- for (const seg of unshortened) {
81
- switch (seg[0]) {
79
+ for (const seg of unarced) {
80
+ switch (seg.type) {
82
81
  case 'M':
83
82
  case 'L': {
84
- if (minX > seg[1]) {
85
- minX = seg[1];
83
+ if (minX > seg.x) {
84
+ minX = seg.x;
86
85
  }
87
- if (minY > seg[2]) {
88
- minY = seg[2];
86
+ if (minY > seg.y) {
87
+ minY = seg.y;
89
88
  }
90
- if (maxX < seg[1]) {
91
- maxX = seg[1];
89
+ if (maxX < seg.x) {
90
+ maxX = seg.x;
92
91
  }
93
- if (maxY < seg[2]) {
94
- maxY = seg[2];
92
+ if (maxY < seg.y) {
93
+ maxY = seg.y;
95
94
  }
96
- x = seg[1];
97
- y = seg[2];
98
- break;
99
- }
100
- case 'V': {
101
- if (minY > seg[1]) {
102
- minY = seg[1];
103
- }
104
- if (maxY < seg[1]) {
105
- maxY = seg[1];
106
- }
107
- y = seg[1];
108
- break;
109
- }
110
- case 'H': {
111
- if (minX > seg[1]) {
112
- minX = seg[1];
113
- }
114
- if (maxX < seg[1]) {
115
- maxX = seg[1];
116
- }
117
- x = seg[1];
95
+ x = seg.x;
96
+ y = seg.y;
118
97
  break;
119
98
  }
120
99
  case 'C': {
121
- const cxMinMax = minmaxC([x, seg[1], seg[3], seg[5]]);
100
+ const cxMinMax = minmaxC([x, seg.cp1x, seg.cp2x, seg.x]);
122
101
  if (minX > cxMinMax[0]) {
123
102
  minX = cxMinMax[0];
124
103
  }
125
104
  if (maxX < cxMinMax[1]) {
126
105
  maxX = cxMinMax[1];
127
106
  }
128
- const cyMinMax = minmaxC([y, seg[2], seg[4], seg[6]]);
107
+ const cyMinMax = minmaxC([y, seg.cp1y, seg.cp2y, seg.y]);
129
108
  if (minY > cyMinMax[0]) {
130
109
  minY = cyMinMax[0];
131
110
  }
132
111
  if (maxY < cyMinMax[1]) {
133
112
  maxY = cyMinMax[1];
134
113
  }
135
- x = seg[5];
136
- y = seg[6];
114
+ x = seg.x;
115
+ y = seg.y;
137
116
  break;
138
117
  }
139
118
  case 'Q': {
140
- const qxMinMax = minmaxQ([x, seg[1], seg[3]]);
119
+ const qxMinMax = minmaxQ([x, seg.cpx, seg.x]);
141
120
  if (minX > qxMinMax[0]) {
142
121
  minX = qxMinMax[0];
143
122
  }
144
123
  if (maxX < qxMinMax[1]) {
145
124
  maxX = qxMinMax[1];
146
125
  }
147
- const qyMinMax = minmaxQ([y, seg[2], seg[4]]);
126
+ const qyMinMax = minmaxQ([y, seg.cpy, seg.y]);
148
127
  if (minY > qyMinMax[0]) {
149
128
  minY = qyMinMax[0];
150
129
  }
151
130
  if (maxY < qyMinMax[1]) {
152
131
  maxY = qyMinMax[1];
153
132
  }
154
- x = seg[3];
155
- y = seg[4];
133
+ x = seg.x;
134
+ y = seg.y;
156
135
  break;
157
136
  }
137
+ case 'Z':
138
+ break;
158
139
  default:
159
- throw new Error(`Unknown instruction ${seg[0]}`);
140
+ // @ts-expect-error
141
+ throw new Error(`Unknown instruction ${seg.type}`);
160
142
  }
161
143
  }
162
144
  return { x1: minX, y1: minY, x2: maxX, y2: maxY };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSubpaths = void 0;
4
4
  const construct_1 = require("./helpers/construct");
5
+ const serialize_instructions_1 = require("./serialize-instructions");
5
6
  /**
6
7
  * Splits a valid SVG path into it's parts.
7
8
  * @param {string} path A valid SVG path
@@ -9,10 +10,8 @@ const construct_1 = require("./helpers/construct");
9
10
  */
10
11
  const getSubpaths = (path) => {
11
12
  const { segments } = (0, construct_1.construct)(path);
12
- return segments
13
- .map((seg) => {
14
- return seg.map((s) => s.join(' '));
15
- })
16
- .map((_s) => _s.join(' '));
13
+ return segments.map((seg) => {
14
+ return (0, serialize_instructions_1.serializeInstructions)(seg);
15
+ });
17
16
  };
18
17
  exports.getSubpaths = getSubpaths;
@@ -1,5 +1,4 @@
1
- import type { Instruction } from './parse';
2
- import type { Point, Properties } from './types';
1
+ import type { Instruction, Point, Properties } from './types';
3
2
  export declare const construct: (string: string) => {
4
3
  segments: Instruction[][];
5
4
  initial_point: Point | null;
@@ -2,16 +2,16 @@
2
2
  // Copied from: https://github.com/rveciana/svg-path-properties
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.construct = void 0;
5
+ const parse_path_1 = require("../parse-path");
5
6
  const arc_1 = require("./arc");
6
7
  const bezier_1 = require("./bezier");
7
8
  const linear_1 = require("./linear");
8
- const parse_1 = require("./parse");
9
9
  const construct = (string) => {
10
10
  let length = 0;
11
11
  const partial_lengths = [];
12
12
  const functions = [];
13
13
  let initial_point = null;
14
- const parsed = (0, parse_1.parsePath)(string);
14
+ const parsed = (0, parse_path_1.parsePath)(string);
15
15
  let cur = [0, 0];
16
16
  let prev_point = [0, 0];
17
17
  let curve;
@@ -19,100 +19,142 @@ const construct = (string) => {
19
19
  const segments = [];
20
20
  for (let i = 0; i < parsed.length; i++) {
21
21
  const instruction = parsed[i];
22
- if (instruction[0].toLowerCase() !== 'm' && segments.length > 0) {
22
+ if (instruction.type !== 'm' &&
23
+ instruction.type !== 'M' &&
24
+ segments.length > 0) {
23
25
  segments[segments.length - 1].push(instruction);
24
26
  }
25
27
  // moveTo
26
- if (instruction[0] === 'M') {
27
- cur = [instruction[1], instruction[2]];
28
+ if (instruction.type === 'M') {
29
+ cur = [instruction.x, instruction.y];
28
30
  ringStart = [cur[0], cur[1]];
29
31
  segments.push([instruction]);
30
32
  functions.push(null);
31
33
  if (i === 0) {
32
- initial_point = { x: instruction[1], y: instruction[2] };
34
+ initial_point = { x: instruction.x, y: instruction.y };
33
35
  }
34
36
  }
35
- else if (instruction[0] === 'm') {
36
- cur = [instruction[1] + cur[0], instruction[2] + cur[1]];
37
+ else if (instruction.type === 'm') {
38
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
37
39
  ringStart = [cur[0], cur[1]];
38
- segments.push([['M', cur[0], cur[1]]]);
40
+ segments.push([{ type: 'M', x: cur[0], y: cur[1] }]);
39
41
  functions.push(null);
40
42
  // lineTo
41
43
  }
42
- else if (instruction[0] === 'L') {
43
- length += Math.sqrt((cur[0] - instruction[1]) ** 2 + (cur[1] - instruction[2]) ** 2);
44
- functions.push((0, linear_1.makeLinearPosition)(cur[0], instruction[1], cur[1], instruction[2]));
45
- cur = [instruction[1], instruction[2]];
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];
46
53
  }
47
- else if (instruction[0] === 'l') {
48
- length += Math.sqrt(instruction[1] ** 2 + instruction[2] ** 2);
49
- functions.push((0, linear_1.makeLinearPosition)(cur[0], instruction[1] + cur[0], cur[1], instruction[2] + cur[1]));
50
- cur = [instruction[1] + cur[0], instruction[2] + cur[1]];
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]];
51
63
  }
52
- else if (instruction[0] === 'H') {
53
- length += Math.abs(cur[0] - instruction[1]);
54
- functions.push((0, linear_1.makeLinearPosition)(cur[0], instruction[1], cur[1], cur[1]));
55
- cur[0] = instruction[1];
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;
56
73
  }
57
- else if (instruction[0] === 'h') {
58
- length += Math.abs(instruction[1]);
59
- functions.push((0, linear_1.makeLinearPosition)(cur[0], cur[0] + instruction[1], cur[1], cur[1]));
60
- cur[0] = instruction[1] + cur[0];
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];
61
83
  }
62
- else if (instruction[0] === 'V') {
63
- length += Math.abs(cur[1] - instruction[1]);
64
- functions.push((0, linear_1.makeLinearPosition)(cur[0], cur[0], cur[1], instruction[1]));
65
- cur[1] = instruction[1];
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;
66
93
  }
67
- else if (instruction[0] === 'v') {
68
- length += Math.abs(instruction[1]);
69
- functions.push((0, linear_1.makeLinearPosition)(cur[0], cur[0], cur[1], cur[1] + instruction[1]));
70
- cur[1] = instruction[1] + cur[1];
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];
71
103
  // Close path
72
104
  }
73
- else if (instruction[0] === 'z' || instruction[0] === 'Z') {
105
+ else if (instruction.type === 'Z') {
74
106
  length += Math.sqrt((ringStart[0] - cur[0]) ** 2 + (ringStart[1] - cur[1]) ** 2);
75
- functions.push((0, linear_1.makeLinearPosition)(cur[0], ringStart[0], cur[1], ringStart[1]));
107
+ functions.push((0, linear_1.makeLinearPosition)({
108
+ x0: cur[0],
109
+ x1: ringStart[0],
110
+ y0: cur[1],
111
+ y1: ringStart[1],
112
+ }));
76
113
  cur = [ringStart[0], ringStart[1]];
77
114
  // Cubic Bezier curves
78
115
  }
79
- else if (instruction[0] === 'C') {
116
+ else if (instruction.type === 'C') {
80
117
  curve = (0, bezier_1.makeBezier)({
81
118
  ax: cur[0],
82
119
  ay: cur[1],
83
- bx: instruction[1],
84
- by: instruction[2],
85
- cx: instruction[3],
86
- cy: instruction[4],
87
- dx: instruction[5],
88
- dy: instruction[6],
120
+ bx: instruction.cp1x,
121
+ by: instruction.cp1y,
122
+ cx: instruction.cp2x,
123
+ cy: instruction.cp2y,
124
+ dx: instruction.x,
125
+ dy: instruction.y,
89
126
  });
90
127
  length += curve.getTotalLength();
91
- cur = [instruction[5], instruction[6]];
128
+ cur = [instruction.x, instruction.y];
92
129
  functions.push(curve);
93
130
  }
94
- else if (instruction[0] === 'c') {
131
+ else if (instruction.type === 'c') {
95
132
  curve = (0, bezier_1.makeBezier)({
96
133
  ax: cur[0],
97
134
  ay: cur[1],
98
- bx: cur[0] + instruction[1],
99
- by: cur[1] + instruction[2],
100
- cx: cur[0] + instruction[3],
101
- cy: cur[1] + instruction[4],
102
- dx: cur[0] + instruction[5],
103
- dy: cur[1] + instruction[6],
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,
104
141
  });
105
142
  if (curve.getTotalLength() > 0) {
106
143
  length += curve.getTotalLength();
107
144
  functions.push(curve);
108
- cur = [instruction[5] + cur[0], instruction[6] + cur[1]];
145
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
109
146
  }
110
147
  else {
111
- 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] }));
112
149
  }
113
150
  }
114
- else if (instruction[0] === 'S') {
115
- if (i > 0 && ['C', 'c', 'S', 's'].indexOf(parsed[i - 1][0]) > -1) {
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) {
116
158
  if (curve) {
117
159
  const c = curve.getC();
118
160
  curve = (0, bezier_1.makeBezier)({
@@ -120,10 +162,10 @@ const construct = (string) => {
120
162
  ay: cur[1],
121
163
  bx: 2 * cur[0] - c.x,
122
164
  by: 2 * cur[1] - c.y,
123
- cx: instruction[1],
124
- cy: instruction[2],
125
- dx: instruction[3],
126
- dy: instruction[4],
165
+ cx: instruction.cpx,
166
+ cy: instruction.cpy,
167
+ dx: instruction.x,
168
+ dy: instruction.y,
127
169
  });
128
170
  }
129
171
  }
@@ -133,21 +175,25 @@ const construct = (string) => {
133
175
  ay: cur[1],
134
176
  bx: cur[0],
135
177
  by: cur[1],
136
- cx: instruction[1],
137
- cy: instruction[2],
138
- dx: instruction[3],
139
- dy: instruction[4],
178
+ cx: instruction.cpx,
179
+ cy: instruction.cpy,
180
+ dx: instruction.x,
181
+ dy: instruction.y,
140
182
  });
141
183
  }
142
184
  if (curve) {
143
185
  length += curve.getTotalLength();
144
- cur = [instruction[3], instruction[4]];
186
+ cur = [instruction.x, instruction.y];
145
187
  functions.push(curve);
146
188
  }
147
189
  }
148
- else if (instruction[0] === 's') {
149
- // 240 225
150
- if (i > 0 && ['C', 'c', 'S', 's'].indexOf(parsed[i - 1][0]) > -1) {
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) {
151
197
  if (curve) {
152
198
  const c = curve.getC();
153
199
  const d = curve.getD();
@@ -156,10 +202,10 @@ const construct = (string) => {
156
202
  ay: cur[1],
157
203
  bx: cur[0] + d.x - c.x,
158
204
  by: cur[1] + d.y - c.y,
159
- cx: cur[0] + instruction[1],
160
- cy: cur[1] + instruction[2],
161
- dx: cur[0] + instruction[3],
162
- dy: cur[1] + instruction[4],
205
+ cx: cur[0] + instruction.cpdx,
206
+ cy: cur[1] + instruction.cpdy,
207
+ dx: cur[0] + instruction.dx,
208
+ dy: cur[1] + instruction.dy,
163
209
  });
164
210
  }
165
211
  }
@@ -169,22 +215,27 @@ const construct = (string) => {
169
215
  ay: cur[1],
170
216
  bx: cur[0],
171
217
  by: cur[1],
172
- cx: cur[0] + instruction[1],
173
- cy: cur[1] + instruction[2],
174
- dx: cur[0] + instruction[3],
175
- dy: cur[1] + instruction[4],
218
+ cx: cur[0] + instruction.cpdx,
219
+ cy: cur[1] + instruction.cpdy,
220
+ dx: cur[0] + instruction.dx,
221
+ dy: cur[1] + instruction.dy,
176
222
  });
177
223
  }
178
224
  if (curve) {
179
225
  length += curve.getTotalLength();
180
- cur = [instruction[3] + cur[0], instruction[4] + cur[1]];
226
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
181
227
  functions.push(curve);
182
228
  }
183
229
  }
184
230
  // Quadratic Bezier curves
185
- else if (instruction[0] === 'Q') {
186
- if (cur[0] === instruction[1] && cur[1] === instruction[2]) {
187
- const linearCurve = (0, linear_1.makeLinearPosition)(instruction[1], instruction[3], instruction[2], instruction[4]);
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
+ });
188
239
  length += linearCurve.getTotalLength();
189
240
  functions.push(linearCurve);
190
241
  }
@@ -192,22 +243,27 @@ const construct = (string) => {
192
243
  curve = (0, bezier_1.makeBezier)({
193
244
  ax: cur[0],
194
245
  ay: cur[1],
195
- bx: instruction[1],
196
- by: instruction[2],
197
- cx: instruction[3],
198
- cy: instruction[4],
246
+ bx: instruction.cpx,
247
+ by: instruction.cpy,
248
+ cx: instruction.x,
249
+ cy: instruction.y,
199
250
  dx: null,
200
251
  dy: null,
201
252
  });
202
253
  length += curve.getTotalLength();
203
254
  functions.push(curve);
204
255
  }
205
- cur = [instruction[3], instruction[4]];
206
- prev_point = [instruction[1], instruction[2]];
256
+ cur = [instruction.x, instruction.y];
257
+ prev_point = [instruction.cpx, instruction.cpy];
207
258
  }
208
- else if (instruction[0] === 'q') {
209
- if (instruction[1] === 0 && instruction[2] === 0) {
210
- const linearCurve = (0, linear_1.makeLinearPosition)(cur[0] + instruction[1], cur[0] + instruction[3], cur[1] + instruction[2], cur[1] + instruction[4]);
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
+ });
211
267
  length += linearCurve.getTotalLength();
212
268
  functions.push(linearCurve);
213
269
  }
@@ -215,28 +271,33 @@ const construct = (string) => {
215
271
  curve = (0, bezier_1.makeBezier)({
216
272
  ax: cur[0],
217
273
  ay: cur[1],
218
- bx: cur[0] + instruction[1],
219
- by: cur[1] + instruction[2],
220
- cx: cur[0] + instruction[3],
221
- cy: cur[1] + instruction[4],
274
+ bx: cur[0] + instruction.cpdx,
275
+ by: cur[1] + instruction.cpdy,
276
+ cx: cur[0] + instruction.dx,
277
+ cy: cur[1] + instruction.dy,
222
278
  dx: null,
223
279
  dy: null,
224
280
  });
225
281
  length += curve.getTotalLength();
226
282
  functions.push(curve);
227
283
  }
228
- prev_point = [cur[0] + instruction[1], cur[1] + instruction[2]];
229
- cur = [instruction[3] + cur[0], instruction[4] + cur[1]];
284
+ prev_point = [cur[0] + instruction.cpdx, cur[1] + instruction.cpdy];
285
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
230
286
  }
231
- else if (instruction[0] === 'T') {
232
- if (i > 0 && ['Q', 'q', 'T', 't'].indexOf(parsed[i - 1][0]) > -1) {
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) {
233
294
  curve = (0, bezier_1.makeBezier)({
234
295
  ax: cur[0],
235
296
  ay: cur[1],
236
297
  bx: 2 * cur[0] - prev_point[0],
237
298
  by: 2 * cur[1] - prev_point[1],
238
- cx: instruction[1],
239
- cy: instruction[2],
299
+ cx: instruction.x,
300
+ cy: instruction.y,
240
301
  dx: null,
241
302
  dy: null,
242
303
  });
@@ -244,22 +305,32 @@ const construct = (string) => {
244
305
  length += curve.getTotalLength();
245
306
  }
246
307
  else {
247
- const linearCurve = (0, linear_1.makeLinearPosition)(cur[0], instruction[1], cur[1], instruction[2]);
308
+ const linearCurve = (0, linear_1.makeLinearPosition)({
309
+ x0: cur[0],
310
+ x1: instruction.x,
311
+ y0: cur[1],
312
+ y1: instruction.y,
313
+ });
248
314
  functions.push(linearCurve);
249
315
  length += linearCurve.getTotalLength();
250
316
  }
251
317
  prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
252
- cur = [instruction[1], instruction[2]];
318
+ cur = [instruction.x, instruction.y];
253
319
  }
254
- else if (instruction[0] === 't') {
255
- if (i > 0 && ['Q', 'q', 'T', 't'].indexOf(parsed[i - 1][0]) > -1) {
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) {
256
327
  curve = (0, bezier_1.makeBezier)({
257
328
  ax: cur[0],
258
329
  ay: cur[1],
259
330
  bx: 2 * cur[0] - prev_point[0],
260
331
  by: 2 * cur[1] - prev_point[1],
261
- cx: cur[0] + instruction[1],
262
- cy: cur[1] + instruction[2],
332
+ cx: cur[0] + instruction.dx,
333
+ cy: cur[1] + instruction.dy,
263
334
  dx: null,
264
335
  dy: null,
265
336
  });
@@ -267,43 +338,48 @@ const construct = (string) => {
267
338
  functions.push(curve);
268
339
  }
269
340
  else {
270
- const linearCurve = (0, linear_1.makeLinearPosition)(cur[0], cur[0] + instruction[1], cur[1], cur[1] + instruction[2]);
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
+ });
271
347
  length += linearCurve.getTotalLength();
272
348
  functions.push(linearCurve);
273
349
  }
274
350
  prev_point = [2 * cur[0] - prev_point[0], 2 * cur[1] - prev_point[1]];
275
- cur = [instruction[1] + cur[0], instruction[2] + cur[1]];
351
+ cur = [instruction.dx + cur[0], instruction.dy + cur[1]];
276
352
  }
277
- else if (instruction[0] === 'A') {
353
+ else if (instruction.type === 'A') {
278
354
  const arcCurve = (0, arc_1.makeArc)({
279
355
  x0: cur[0],
280
356
  y0: cur[1],
281
- rx: instruction[1],
282
- ry: instruction[2],
283
- xAxisRotate: instruction[3],
284
- LargeArcFlag: instruction[4] === 1,
285
- SweepFlag: instruction[5] === 1,
286
- x1: instruction[6],
287
- y1: instruction[7],
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,
288
364
  });
289
365
  length += arcCurve.getTotalLength();
290
- cur = [instruction[6], instruction[7]];
366
+ cur = [instruction.x, instruction.y];
291
367
  functions.push(arcCurve);
292
368
  }
293
- else if (instruction[0] === 'a') {
369
+ else if (instruction.type === 'a') {
294
370
  const arcCurve = (0, arc_1.makeArc)({
295
371
  x0: cur[0],
296
372
  y0: cur[1],
297
- rx: instruction[1],
298
- ry: instruction[2],
299
- xAxisRotate: instruction[3],
300
- LargeArcFlag: instruction[4] === 1,
301
- SweepFlag: instruction[5] === 1,
302
- x1: cur[0] + instruction[6],
303
- y1: cur[1] + instruction[7],
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,
304
380
  });
305
381
  length += arcCurve.getTotalLength();
306
- cur = [cur[0] + instruction[6], cur[1] + instruction[7]];
382
+ cur = [cur[0] + instruction.dx, cur[1] + instruction.dy];
307
383
  functions.push(arcCurve);
308
384
  }
309
385
  partial_lengths.push(length);