@remotion/paths 3.3.39 → 3.3.41

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.
Files changed (42) hide show
  1. package/dist/get-bounding-box.d.ts +2 -0
  2. package/dist/get-bounding-box.js +146 -0
  3. package/dist/get-subpaths.js +4 -5
  4. package/dist/helpers/construct.d.ts +1 -2
  5. package/dist/helpers/construct.js +199 -123
  6. package/dist/helpers/iterate.d.ts +12 -0
  7. package/dist/helpers/iterate.js +53 -0
  8. package/dist/helpers/linear.d.ts +6 -1
  9. package/dist/helpers/linear.js +1 -1
  10. package/dist/helpers/remove-a-s-t-curves.d.ts +2 -0
  11. package/dist/helpers/remove-a-s-t-curves.js +260 -0
  12. package/dist/helpers/serialize.d.ts +2 -0
  13. package/dist/helpers/serialize.js +75 -0
  14. package/dist/helpers/types.d.ts +105 -1
  15. package/dist/helpers/unarc.d.ts +2 -0
  16. package/dist/helpers/unarc.js +254 -0
  17. package/dist/helpers/unshort.d.ts +2 -0
  18. package/dist/helpers/unshort.js +65 -0
  19. package/dist/index.d.ts +6 -1
  20. package/dist/index.js +11 -1
  21. package/dist/normalize-path.d.ts +2 -0
  22. package/dist/normalize-path.js +129 -275
  23. package/dist/parse-path.d.ts +2 -0
  24. package/dist/parse-path.js +259 -0
  25. package/dist/parse.d.ts +2 -0
  26. package/dist/parse.js +266 -0
  27. package/dist/reduce-instructions.d.ts +2 -0
  28. package/dist/reduce-instructions.js +10 -0
  29. package/dist/reset-path.d.ts +1 -0
  30. package/dist/reset-path.js +10 -0
  31. package/dist/serialize-instructions.d.ts +2 -0
  32. package/dist/serialize-instructions.js +72 -0
  33. package/dist/serialize.d.ts +2 -0
  34. package/dist/serialize.js +75 -0
  35. package/dist/simplify-instructions.d.ts +2 -0
  36. package/dist/simplify-instructions.js +10 -0
  37. package/dist/translate-path.js +89 -25
  38. package/dist/unarc.d.ts +2 -0
  39. package/dist/unarc.js +180 -0
  40. package/dist/unshort.d.ts +2 -0
  41. package/dist/unshort.js +118 -0
  42. package/package.json +2 -2
@@ -0,0 +1,259 @@
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
+ const parsePath = (path) => {
46
+ if (!path) {
47
+ throw new Error('No path provided');
48
+ }
49
+ const segments = path.match(segmentRegExp);
50
+ if (!segments) {
51
+ throw new Error(`No path elements found in string ${path}`);
52
+ }
53
+ return segments
54
+ .map((segmentString) => {
55
+ const command = segmentString.charAt(0);
56
+ const args = parseValues(segmentString.substring(1), command);
57
+ // overloaded moveTo
58
+ if (command === 'M' && args.length > 2) {
59
+ const segmentsArray = [];
60
+ segmentsArray.push({
61
+ type: command,
62
+ x: args[0],
63
+ y: args[1],
64
+ });
65
+ segmentsArray.push(...makeInstructions(args.slice(2), 'L', (numbers) => ({
66
+ type: 'L',
67
+ x: numbers[0],
68
+ y: numbers[1],
69
+ })));
70
+ return segmentsArray;
71
+ }
72
+ if (command === 'm' && args.length > 2) {
73
+ const segmentsArray = [];
74
+ segmentsArray.push({
75
+ type: command,
76
+ dx: args[0],
77
+ dy: args[1],
78
+ });
79
+ segmentsArray.push(...makeInstructions(args.slice(2), 'l', (numbers) => ({
80
+ type: 'l',
81
+ dx: numbers[0],
82
+ dy: numbers[1],
83
+ })));
84
+ return segmentsArray;
85
+ }
86
+ if (command === 'Z') {
87
+ return [
88
+ {
89
+ type: 'Z',
90
+ },
91
+ ];
92
+ }
93
+ if (command === 'A') {
94
+ return makeInstructions(args, command, (numbers) => ({
95
+ type: command,
96
+ rx: numbers[0],
97
+ ry: numbers[1],
98
+ xAxisRotation: numbers[2],
99
+ largeArcFlag: numbers[3] === 1,
100
+ sweepFlag: numbers[4] === 1,
101
+ x: numbers[5],
102
+ y: numbers[6],
103
+ }));
104
+ }
105
+ if (command === 'a') {
106
+ return makeInstructions(args, command, (numbers) => ({
107
+ type: command,
108
+ rx: numbers[0],
109
+ ry: numbers[1],
110
+ xAxisRotation: numbers[2],
111
+ largeArcFlag: numbers[3] === 1,
112
+ sweepFlag: numbers[4] === 1,
113
+ dx: numbers[5],
114
+ dy: numbers[6],
115
+ }));
116
+ }
117
+ if (command === 'C') {
118
+ return makeInstructions(args, command, (numbers) => ({
119
+ type: command,
120
+ cp1x: numbers[0],
121
+ cp1y: numbers[1],
122
+ cp2x: numbers[2],
123
+ cp2y: numbers[3],
124
+ x: numbers[4],
125
+ y: numbers[5],
126
+ }));
127
+ }
128
+ if (command === 'c') {
129
+ return makeInstructions(args, command, (numbers) => ({
130
+ type: command,
131
+ cp1dx: numbers[0],
132
+ cp1dy: numbers[1],
133
+ cp2dx: numbers[2],
134
+ cp2dy: numbers[3],
135
+ dx: numbers[4],
136
+ dy: numbers[5],
137
+ }));
138
+ }
139
+ if (command === 'S') {
140
+ return makeInstructions(args, command, (numbers) => ({
141
+ type: command,
142
+ cpx: numbers[0],
143
+ cpy: numbers[1],
144
+ x: numbers[2],
145
+ y: numbers[3],
146
+ }));
147
+ }
148
+ if (command === 's') {
149
+ return makeInstructions(args, command, (numbers) => ({
150
+ type: command,
151
+ cpdx: numbers[0],
152
+ cpdy: numbers[1],
153
+ dx: numbers[2],
154
+ dy: numbers[3],
155
+ }));
156
+ }
157
+ if (command === 'H') {
158
+ return makeInstructions(args, command, (numbers) => ({
159
+ type: command,
160
+ x: numbers[0],
161
+ }));
162
+ }
163
+ if (command === 'h') {
164
+ return makeInstructions(args, command, (numbers) => ({
165
+ type: command,
166
+ dx: numbers[0],
167
+ }));
168
+ }
169
+ if (command === 'V') {
170
+ return makeInstructions(args, command, (numbers) => ({
171
+ type: command,
172
+ y: numbers[0],
173
+ }));
174
+ }
175
+ if (command === 'v') {
176
+ return makeInstructions(args, command, (numbers) => ({
177
+ type: command,
178
+ dy: numbers[0],
179
+ }));
180
+ }
181
+ if (command === 'L') {
182
+ return makeInstructions(args, command, (numbers) => ({
183
+ type: command,
184
+ x: numbers[0],
185
+ y: numbers[1],
186
+ }));
187
+ }
188
+ if (command === 'M') {
189
+ return makeInstructions(args, command, (numbers) => ({
190
+ type: command,
191
+ x: numbers[0],
192
+ y: numbers[1],
193
+ }));
194
+ }
195
+ if (command === 'm') {
196
+ return makeInstructions(args, command, (numbers) => ({
197
+ type: command,
198
+ dx: numbers[0],
199
+ dy: numbers[1],
200
+ }));
201
+ }
202
+ if (command === 'l') {
203
+ return makeInstructions(args, command, (numbers) => ({
204
+ type: command,
205
+ dx: numbers[0],
206
+ dy: numbers[1],
207
+ }));
208
+ }
209
+ if (command === 'Q') {
210
+ return makeInstructions(args, command, (numbers) => ({
211
+ type: command,
212
+ cpx: numbers[0],
213
+ cpy: numbers[1],
214
+ x: numbers[2],
215
+ y: numbers[3],
216
+ }));
217
+ }
218
+ if (command === 'q') {
219
+ return makeInstructions(args, command, (numbers) => ({
220
+ type: command,
221
+ cpdx: numbers[0],
222
+ cpdy: numbers[1],
223
+ dx: numbers[2],
224
+ dy: numbers[3],
225
+ }));
226
+ }
227
+ if (command === 'T') {
228
+ return makeInstructions(args, command, (numbers) => ({
229
+ type: command,
230
+ x: numbers[0],
231
+ y: numbers[1],
232
+ }));
233
+ }
234
+ if (command === 't') {
235
+ return makeInstructions(args, command, (numbers) => ({
236
+ type: command,
237
+ dx: numbers[0],
238
+ dy: numbers[1],
239
+ }));
240
+ }
241
+ throw new Error(`Invalid path element ${segmentString}`);
242
+ }, [])
243
+ .flat(1);
244
+ };
245
+ exports.parsePath = parsePath;
246
+ const parseValues = (args, instructionType) => {
247
+ const numbers = args.match(numberRegExp);
248
+ if (!numbers) {
249
+ if (instructionType === 'Z' || instructionType === 'z') {
250
+ return [];
251
+ }
252
+ throw new Error(`Malformed path data: ${instructionType} was expected to have numbers afterwards`);
253
+ }
254
+ const expectedArguments = length[instructionType];
255
+ if (numbers.length % expectedArguments !== 0) {
256
+ throw new Error(`Malformed path data: ${instructionType} was expected to have a multiple of ${expectedArguments} numbers, but got "${instructionType} ${numbers.join(' ')} instead"`);
257
+ }
258
+ return numbers.map(Number);
259
+ };
@@ -0,0 +1,2 @@
1
+ import type { Instruction } from './types';
2
+ export declare const parsePath: (path: string) => Instruction[];
package/dist/parse.js ADDED
@@ -0,0 +1,266 @@
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
+ const parsePath = (path) => {
46
+ if (!path) {
47
+ throw new Error('No path provided');
48
+ }
49
+ const segments = path.match(segmentRegExp);
50
+ if (!segments) {
51
+ throw new Error(`No path elements found in string ${path}`);
52
+ }
53
+ return segments
54
+ .map((segmentString) => {
55
+ const command = segmentString.charAt(0);
56
+ const args = parseValues(segmentString.substring(1), command);
57
+ // overloaded moveTo
58
+ if (command === 'M' && args.length > 2) {
59
+ const segmentsArray = [];
60
+ segmentsArray.push({
61
+ type: command,
62
+ x: args[0],
63
+ y: args[1],
64
+ });
65
+ segmentsArray.push(...makeInstructions(args.slice(2), 'L', (numbers) => ({
66
+ type: 'L',
67
+ x: numbers[0],
68
+ y: numbers[1],
69
+ })));
70
+ return segmentsArray;
71
+ }
72
+ if (command === 'm' && args.length > 2) {
73
+ const segmentsArray = [];
74
+ segmentsArray.push({
75
+ type: command,
76
+ dx: args[0],
77
+ dy: args[1],
78
+ });
79
+ segmentsArray.push(...makeInstructions(args.slice(2), 'l', (numbers) => ({
80
+ type: 'l',
81
+ dx: numbers[0],
82
+ dy: numbers[1],
83
+ })));
84
+ return segmentsArray;
85
+ }
86
+ if (command === 'Z') {
87
+ return [
88
+ {
89
+ type: 'Z',
90
+ },
91
+ ];
92
+ }
93
+ if (command === 'z') {
94
+ return [
95
+ {
96
+ type: 'z',
97
+ },
98
+ ];
99
+ }
100
+ if (command === 'A') {
101
+ return makeInstructions(args, command, (numbers) => ({
102
+ type: command,
103
+ rx: numbers[0],
104
+ ry: numbers[1],
105
+ xAxisRotation: numbers[2],
106
+ largeArcFlag: numbers[3] === 1,
107
+ sweepFlag: numbers[4] === 1,
108
+ x: numbers[5],
109
+ y: numbers[6],
110
+ }));
111
+ }
112
+ if (command === 'a') {
113
+ return makeInstructions(args, command, (numbers) => ({
114
+ type: command,
115
+ rx: numbers[0],
116
+ ry: numbers[1],
117
+ xAxisRotation: numbers[2],
118
+ largeArcFlag: numbers[3] === 1,
119
+ sweepFlag: numbers[4] === 1,
120
+ dx: numbers[5],
121
+ dy: numbers[6],
122
+ }));
123
+ }
124
+ if (command === 'C') {
125
+ return makeInstructions(args, command, (numbers) => ({
126
+ type: command,
127
+ cp1x: numbers[0],
128
+ cp1y: numbers[1],
129
+ cp2x: numbers[2],
130
+ cp2y: numbers[3],
131
+ x: numbers[4],
132
+ y: numbers[5],
133
+ }));
134
+ }
135
+ if (command === 'c') {
136
+ return makeInstructions(args, command, (numbers) => ({
137
+ type: command,
138
+ cp1dx: numbers[0],
139
+ cp1dy: numbers[1],
140
+ cp2dx: numbers[2],
141
+ cp2dy: numbers[3],
142
+ dx: numbers[4],
143
+ dy: numbers[5],
144
+ }));
145
+ }
146
+ if (command === 'S') {
147
+ return makeInstructions(args, command, (numbers) => ({
148
+ type: command,
149
+ cpx: numbers[0],
150
+ cpy: numbers[1],
151
+ x: numbers[2],
152
+ y: numbers[3],
153
+ }));
154
+ }
155
+ if (command === 's') {
156
+ return makeInstructions(args, command, (numbers) => ({
157
+ type: command,
158
+ cpdx: numbers[0],
159
+ cpdy: numbers[1],
160
+ dx: numbers[2],
161
+ dy: numbers[3],
162
+ }));
163
+ }
164
+ if (command === 'H') {
165
+ return makeInstructions(args, command, (numbers) => ({
166
+ type: command,
167
+ x: numbers[0],
168
+ }));
169
+ }
170
+ if (command === 'h') {
171
+ return makeInstructions(args, command, (numbers) => ({
172
+ type: command,
173
+ dx: numbers[0],
174
+ }));
175
+ }
176
+ if (command === 'V') {
177
+ return makeInstructions(args, command, (numbers) => ({
178
+ type: command,
179
+ y: numbers[0],
180
+ }));
181
+ }
182
+ if (command === 'v') {
183
+ return makeInstructions(args, command, (numbers) => ({
184
+ type: command,
185
+ dy: numbers[0],
186
+ }));
187
+ }
188
+ if (command === 'L') {
189
+ return makeInstructions(args, command, (numbers) => ({
190
+ type: command,
191
+ x: numbers[0],
192
+ y: numbers[1],
193
+ }));
194
+ }
195
+ if (command === 'M') {
196
+ return makeInstructions(args, command, (numbers) => ({
197
+ type: command,
198
+ x: numbers[0],
199
+ y: numbers[1],
200
+ }));
201
+ }
202
+ if (command === 'm') {
203
+ return makeInstructions(args, command, (numbers) => ({
204
+ type: command,
205
+ dx: numbers[0],
206
+ dy: numbers[1],
207
+ }));
208
+ }
209
+ if (command === 'l') {
210
+ return makeInstructions(args, command, (numbers) => ({
211
+ type: command,
212
+ dx: numbers[0],
213
+ dy: numbers[1],
214
+ }));
215
+ }
216
+ if (command === 'Q') {
217
+ return makeInstructions(args, command, (numbers) => ({
218
+ type: command,
219
+ cpx: numbers[0],
220
+ cpy: numbers[1],
221
+ x: numbers[2],
222
+ y: numbers[3],
223
+ }));
224
+ }
225
+ if (command === 'q') {
226
+ return makeInstructions(args, command, (numbers) => ({
227
+ type: command,
228
+ cpdx: numbers[0],
229
+ cpdy: numbers[1],
230
+ dx: numbers[2],
231
+ dy: numbers[3],
232
+ }));
233
+ }
234
+ if (command === 'T') {
235
+ return makeInstructions(args, command, (numbers) => ({
236
+ type: command,
237
+ x: numbers[0],
238
+ y: numbers[1],
239
+ }));
240
+ }
241
+ if (command === 't') {
242
+ return makeInstructions(args, command, (numbers) => ({
243
+ type: command,
244
+ dx: numbers[0],
245
+ dy: numbers[1],
246
+ }));
247
+ }
248
+ throw new Error(`Invalid path element ${segmentString}`);
249
+ }, [])
250
+ .flat(1);
251
+ };
252
+ exports.parsePath = parsePath;
253
+ const parseValues = (args, instructionType) => {
254
+ const numbers = args.match(numberRegExp);
255
+ if (!numbers) {
256
+ if (instructionType === 'Z' || instructionType === 'z') {
257
+ return [];
258
+ }
259
+ throw new Error(`Malformed path data: ${instructionType} was expected to have numbers afterwards`);
260
+ }
261
+ const expectedArguments = length[instructionType];
262
+ if (numbers.length % expectedArguments !== 0) {
263
+ throw new Error(`Malformed path data: ${instructionType} was expected to have a multiple of ${expectedArguments} numbers, but got "${instructionType} ${numbers.join(' ')} instead"`);
264
+ }
265
+ return numbers.map(Number);
266
+ };
@@ -0,0 +1,2 @@
1
+ import type { Instruction, ReducedInstruction } from './helpers/types';
2
+ export declare const reduceInstructions: (instruction: Instruction[]) => ReducedInstruction[];
@@ -0,0 +1,10 @@
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
+ const reduceInstructions = (instruction) => {
7
+ const simplified = (0, normalize_path_1.normalizeInstructions)(instruction);
8
+ return (0, remove_a_s_t_curves_1.removeATSHVInstructions)(simplified);
9
+ };
10
+ exports.reduceInstructions = reduceInstructions;
@@ -0,0 +1 @@
1
+ export declare const resetPath: (d: string) => string;
@@ -0,0 +1,10 @@
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
+ const resetPath = (d) => {
7
+ const box = (0, get_bounding_box_1.getBoundingBox)(d);
8
+ return (0, translate_path_1.translatePath)(d, -box.x1, -box.y1);
9
+ };
10
+ exports.resetPath = resetPath;
@@ -0,0 +1,2 @@
1
+ import type { Instruction } from './helpers/types';
2
+ export declare const serializeInstructions: (path: Instruction[]) => string;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeInstructions = void 0;
4
+ const serializeInstruction = (instruction) => {
5
+ if (instruction.type === 'A') {
6
+ return `A ${instruction.rx} ${instruction.ry} ${instruction.xAxisRotation} ${Number(instruction.largeArcFlag)} ${Number(instruction.sweepFlag)} ${instruction.x} ${instruction.y}`;
7
+ }
8
+ if (instruction.type === 'a') {
9
+ return `a ${instruction.rx} ${instruction.ry} ${instruction.xAxisRotation} ${Number(instruction.largeArcFlag)} ${Number(instruction.sweepFlag)} ${instruction.dx} ${instruction.dy}`;
10
+ }
11
+ if (instruction.type === 'C') {
12
+ return `C ${instruction.cp1x} ${instruction.cp1y} ${instruction.cp2x} ${instruction.cp2y} ${instruction.x} ${instruction.y}`;
13
+ }
14
+ if (instruction.type === 'c') {
15
+ return `c ${instruction.cp1dx} ${instruction.cp1dy} ${instruction.cp2dx} ${instruction.cp2dy} ${instruction.dx} ${instruction.dy}`;
16
+ }
17
+ if (instruction.type === 'S') {
18
+ return `S ${instruction.cpx} ${instruction.cpy} ${instruction.x} ${instruction.y}`;
19
+ }
20
+ if (instruction.type === 's') {
21
+ return `s ${instruction.cpdx} ${instruction.cpdy} ${instruction.dx} ${instruction.dy}`;
22
+ }
23
+ if (instruction.type === 'Q') {
24
+ return `Q ${instruction.cpx} ${instruction.cpy} ${instruction.x} ${instruction.y}`;
25
+ }
26
+ if (instruction.type === 'q') {
27
+ return `q ${instruction.cpdx} ${instruction.cpdy} ${instruction.dx} ${instruction.dy}`;
28
+ }
29
+ if (instruction.type === 'Z') {
30
+ return 'Z';
31
+ }
32
+ if (instruction.type === 'H') {
33
+ return `H ${instruction.x}`;
34
+ }
35
+ if (instruction.type === 'h') {
36
+ return `h ${instruction.dx}`;
37
+ }
38
+ if (instruction.type === 'V') {
39
+ return `V ${instruction.y}`;
40
+ }
41
+ if (instruction.type === 'v') {
42
+ return `v ${instruction.dy}`;
43
+ }
44
+ if (instruction.type === 'L') {
45
+ return `L ${instruction.x} ${instruction.y}`;
46
+ }
47
+ if (instruction.type === 'l') {
48
+ return `l ${instruction.dx} ${instruction.dy}`;
49
+ }
50
+ if (instruction.type === 'M') {
51
+ return `M ${instruction.x} ${instruction.y}`;
52
+ }
53
+ if (instruction.type === 'm') {
54
+ return `m ${instruction.dx} ${instruction.dy}`;
55
+ }
56
+ if (instruction.type === 'T') {
57
+ return `T ${instruction.x} ${instruction.y}`;
58
+ }
59
+ if (instruction.type === 't') {
60
+ return `t ${instruction.dx} ${instruction.dy}`;
61
+ }
62
+ // @ts-expect-error
63
+ throw new Error(`Unknown instruction type: ${instruction.type}`);
64
+ };
65
+ const serializeInstructions = (path) => {
66
+ return path
67
+ .map((p) => {
68
+ return serializeInstruction(p);
69
+ })
70
+ .join(' ');
71
+ };
72
+ exports.serializeInstructions = serializeInstructions;
@@ -0,0 +1,2 @@
1
+ import type { Instruction } from './types';
2
+ export declare const serializeInstructions: (path: Instruction[]) => string;