@jscad/svg-deserializer 2.5.11 → 3.0.1-alpha.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/CHANGELOG.md +11 -240
- package/LICENSE +1 -1
- package/README.md +5 -1
- package/dist/jscad-svg-deserializer.es.js +38 -0
- package/dist/jscad-svg-deserializer.min.js +38 -0
- package/package.json +24 -13
- package/rollup.config.js +29 -0
- package/src/constants.js +6 -15
- package/src/helpers.js +11 -24
- package/src/index.js +27 -37
- package/src/shapesMapGeometry.js +42 -42
- package/src/shapesMapJscad.js +37 -39
- package/src/svgElementHelpers.js +16 -31
- package/tests/inkscape.test.js +5 -7
- package/tests/instantiate.test.js +103 -84
- package/tests/issue.1135.test.js +3 -3
- package/tests/issue.885.test.js +5 -9
- package/tests/translate.test.js +59 -63
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { measureArea, measureBoundingBox } from '@jscad/modeling'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// deserializer
|
|
5
|
+
import { deserialize } from '../src/index.js'
|
|
8
6
|
|
|
9
7
|
test('deserialize : instantiate svg (rect) to objects', (t) => {
|
|
10
8
|
const sourceSvg = `<svg pxpmm="10" width="500" height="500">
|
|
11
9
|
<rect x="80" y="60" width="250" height="250" color="red"/>
|
|
12
|
-
<rect x="140" y="120" width="250" height="250" rx="40" color="
|
|
10
|
+
<rect x="140" y="120" width="250" height="250" rx="40" color="rgb(0,255,0)"/>
|
|
13
11
|
<rect x="140" y="120" width="250" height="250" ry="40" color="blue"/>
|
|
14
12
|
<rect x="40" y="20" width="250" height="250" transform="translate(60 50) scale(2 3)"/>
|
|
15
13
|
</svg>`
|
|
16
14
|
|
|
17
|
-
let observed =
|
|
15
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
18
16
|
t.is(observed.length, 4)
|
|
19
17
|
let shape = observed[0]
|
|
20
|
-
t.is(shape.
|
|
21
|
-
t.is(
|
|
18
|
+
t.is(shape.outlines.length, 1)
|
|
19
|
+
t.is(shape.outlines[0].length, 4)
|
|
20
|
+
t.is(measureArea(shape), 625)
|
|
22
21
|
shape = observed[1]
|
|
23
|
-
t.is(shape.
|
|
24
|
-
t.is(
|
|
22
|
+
t.is(shape.outlines.length, 1)
|
|
23
|
+
t.is(shape.outlines[0].length, 36)
|
|
24
|
+
t.is(measureArea(shape), 610.943122436129)
|
|
25
25
|
shape = observed[3]
|
|
26
|
-
t.is(shape.
|
|
27
|
-
t.is(
|
|
28
|
-
t.
|
|
26
|
+
t.is(shape.outlines.length, 1)
|
|
27
|
+
t.is(shape.outlines[0].length, 4)
|
|
28
|
+
t.is(measureArea(shape), 3750)
|
|
29
|
+
t.deepEqual(measureBoundingBox(shape), [[14, -86, 0], [64, -11, 0]])
|
|
29
30
|
|
|
30
|
-
observed =
|
|
31
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
31
32
|
t.is(observed.length, 4)
|
|
32
33
|
shape = observed[0]
|
|
33
34
|
t.is(shape.points.length, 4)
|
|
@@ -38,7 +39,7 @@ test('deserialize : instantiate svg (rect) to objects', (t) => {
|
|
|
38
39
|
shape = observed[3]
|
|
39
40
|
t.is(shape.points.length, 4)
|
|
40
41
|
t.true(shape.isClosed)
|
|
41
|
-
t.deepEqual(
|
|
42
|
+
t.deepEqual(measureBoundingBox(shape), [[14, -86, 0], [64, -11, 0]])
|
|
42
43
|
})
|
|
43
44
|
|
|
44
45
|
// ################################
|
|
@@ -49,20 +50,21 @@ test('deserialize : instantiate svg (circle) to objects', (t) => {
|
|
|
49
50
|
</svg>
|
|
50
51
|
`
|
|
51
52
|
|
|
52
|
-
let observed =
|
|
53
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
53
54
|
t.is(observed.length, 1)
|
|
54
55
|
let shape = observed[0]
|
|
55
|
-
t.is(shape.
|
|
56
|
+
t.is(shape.outlines.length, 1)
|
|
57
|
+
t.is(shape.outlines[0].length, 32)
|
|
56
58
|
t.deepEqual(shape.color, [1, 0, 0, 1])
|
|
57
59
|
|
|
58
|
-
observed =
|
|
60
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
59
61
|
t.is(observed.length, 1)
|
|
60
62
|
shape = observed[0]
|
|
61
63
|
t.is(shape.points.length, 32)
|
|
62
64
|
t.true(shape.isClosed)
|
|
63
65
|
t.deepEqual(shape.color, [0, 0, 0, 1])
|
|
64
66
|
|
|
65
|
-
observed =
|
|
67
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false, segments: 16 }, sourceSvg)
|
|
66
68
|
t.is(observed.length, 1)
|
|
67
69
|
shape = observed[0]
|
|
68
70
|
t.is(shape.points.length, 16)
|
|
@@ -78,18 +80,19 @@ test('deserialize : instantiate svg (ellipse) to objects', (t) => {
|
|
|
78
80
|
</svg>
|
|
79
81
|
`
|
|
80
82
|
|
|
81
|
-
let observed =
|
|
83
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
82
84
|
t.is(observed.length, 1)
|
|
83
85
|
let shape = observed[0]
|
|
84
|
-
t.is(shape.
|
|
86
|
+
t.is(shape.outlines.length, 1)
|
|
87
|
+
t.is(shape.outlines[0].length, 32)
|
|
85
88
|
|
|
86
|
-
observed =
|
|
89
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
87
90
|
t.is(observed.length, 1)
|
|
88
91
|
shape = observed[0]
|
|
89
92
|
t.is(shape.points.length, 32)
|
|
90
93
|
t.true(shape.isClosed)
|
|
91
94
|
|
|
92
|
-
observed =
|
|
95
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false, segments: 16 }, sourceSvg)
|
|
93
96
|
t.is(observed.length, 1)
|
|
94
97
|
shape = observed[0]
|
|
95
98
|
t.is(shape.points.length, 16)
|
|
@@ -103,12 +106,12 @@ test('deserialize : instantiate svg (polyline) to objects', (t) => {
|
|
|
103
106
|
<polyline fill="none" stroke="black" points="20,100 40,60 70,80 100,20"/>
|
|
104
107
|
</svg>`
|
|
105
108
|
|
|
106
|
-
let observed =
|
|
109
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
107
110
|
t.is(observed.length, 1)
|
|
108
111
|
let shape = observed[0]
|
|
109
|
-
// FIXME t.is(shape.
|
|
112
|
+
// FIXME t.is(shape.outlines[0].length, 16)
|
|
110
113
|
|
|
111
|
-
observed =
|
|
114
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
112
115
|
t.is(observed.length, 1)
|
|
113
116
|
shape = observed[0]
|
|
114
117
|
t.is(shape.points.length, 4)
|
|
@@ -121,12 +124,13 @@ test('deserialize : instantiate svg (polygon) to objects', (t) => {
|
|
|
121
124
|
<polygon points="60,20 100,40 100,80 60,100 20,80 20,40"/>
|
|
122
125
|
</svg>`
|
|
123
126
|
|
|
124
|
-
let observed =
|
|
127
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
125
128
|
t.is(observed.length, 1)
|
|
126
129
|
let shape = observed[0]
|
|
127
|
-
t.is(shape.
|
|
130
|
+
t.is(shape.outlines.length, 1)
|
|
131
|
+
t.is(shape.outlines[0].length, 6)
|
|
128
132
|
|
|
129
|
-
observed =
|
|
133
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
130
134
|
t.is(observed.length, 1)
|
|
131
135
|
shape = observed[0]
|
|
132
136
|
t.is(shape.points.length, 6)
|
|
@@ -139,12 +143,12 @@ test('deserialize : instantiate svg (line) to objects', (t) => {
|
|
|
139
143
|
<line x1="20" y1="100" x2="100" y2="20" stroke-width="2" stroke="black"/>
|
|
140
144
|
</svg> `
|
|
141
145
|
|
|
142
|
-
let observed =
|
|
146
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
143
147
|
t.is(observed.length, 1)
|
|
144
148
|
let shape = observed[0]
|
|
145
|
-
// TODO t.is(shape.
|
|
149
|
+
// TODO t.is(shape.outlines[0].length, 6)
|
|
146
150
|
|
|
147
|
-
observed =
|
|
151
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
148
152
|
t.is(observed.length, 1)
|
|
149
153
|
shape = observed[0]
|
|
150
154
|
t.is(shape.points.length, 2)
|
|
@@ -156,7 +160,7 @@ test('deserialize : instantiate svg (line) to objects', (t) => {
|
|
|
156
160
|
</g>
|
|
157
161
|
</svg>`
|
|
158
162
|
|
|
159
|
-
observed =
|
|
163
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
160
164
|
t.is(observed.length, 1)
|
|
161
165
|
shape = observed[0]
|
|
162
166
|
t.is(shape.points.length, 2)
|
|
@@ -170,12 +174,13 @@ test('deserialize : instantiate svg (path: simple) to objects', (t) => {
|
|
|
170
174
|
<path stroke="black" stroke-width="2" d="M150 0 L75 200 L225 200 Z" />
|
|
171
175
|
</svg>`
|
|
172
176
|
|
|
173
|
-
let observed =
|
|
177
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
174
178
|
t.is(observed.length, 1)
|
|
175
179
|
let shape = observed[0]
|
|
176
|
-
t.is(shape.
|
|
180
|
+
t.is(shape.outlines.length, 1)
|
|
181
|
+
t.is(shape.outlines[0].length, 3)
|
|
177
182
|
|
|
178
|
-
observed =
|
|
183
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
179
184
|
t.is(observed.length, 1)
|
|
180
185
|
shape = observed[0]
|
|
181
186
|
t.is(shape.points.length, 3)
|
|
@@ -187,12 +192,13 @@ test('deserialize : instantiate svg (path: simple) to objects', (t) => {
|
|
|
187
192
|
</g>
|
|
188
193
|
</svg>`
|
|
189
194
|
|
|
190
|
-
observed =
|
|
195
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
191
196
|
t.is(observed.length, 1)
|
|
192
197
|
shape = observed[0]
|
|
193
|
-
t.is(shape.
|
|
198
|
+
t.is(shape.outlines.length, 1)
|
|
199
|
+
t.is(shape.outlines[0].length, 3)
|
|
194
200
|
|
|
195
|
-
observed =
|
|
201
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
196
202
|
t.is(observed.length, 1)
|
|
197
203
|
shape = observed[0]
|
|
198
204
|
t.is(shape.points.length, 3)
|
|
@@ -201,12 +207,13 @@ test('deserialize : instantiate svg (path: simple) to objects', (t) => {
|
|
|
201
207
|
<path d="m 150 0 l 75 200 l -225 0 z" />
|
|
202
208
|
</svg>`
|
|
203
209
|
|
|
204
|
-
observed =
|
|
210
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
205
211
|
t.is(observed.length, 1)
|
|
206
212
|
shape = observed[0]
|
|
207
|
-
t.is(shape.
|
|
213
|
+
t.is(shape.outlines.length, 1)
|
|
214
|
+
t.is(shape.outlines[0].length, 3)
|
|
208
215
|
|
|
209
|
-
observed =
|
|
216
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
210
217
|
t.is(observed.length, 1)
|
|
211
218
|
shape = observed[0]
|
|
212
219
|
t.is(shape.points.length, 3)
|
|
@@ -215,12 +222,13 @@ test('deserialize : instantiate svg (path: simple) to objects', (t) => {
|
|
|
215
222
|
<path d="M 240.00000 56.00000 H 270.00000 V 86.00000 H 300.00000 V 116.00000 H 330.00000 V 146.00000 H 240.00000 V 56.00000 Z"/>
|
|
216
223
|
</svg>`
|
|
217
224
|
|
|
218
|
-
observed =
|
|
225
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
219
226
|
t.is(observed.length, 1)
|
|
220
227
|
shape = observed[0]
|
|
221
|
-
t.is(shape.
|
|
228
|
+
t.is(shape.outlines.length, 1)
|
|
229
|
+
t.is(shape.outlines[0].length, 8)
|
|
222
230
|
|
|
223
|
-
observed =
|
|
231
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
224
232
|
t.is(observed.length, 1)
|
|
225
233
|
shape = observed[0]
|
|
226
234
|
t.is(shape.points.length, 8)
|
|
@@ -234,24 +242,25 @@ test('deserialize : instantiate svg (path: arc) to objects', (t) => {
|
|
|
234
242
|
<path d="M 230 230 A 45 45 0 1 1 275 275 L 275 230 Z" transform="translate(180 80) rotate(45)"/>
|
|
235
243
|
</svg>`
|
|
236
244
|
|
|
237
|
-
let observed =
|
|
245
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
238
246
|
t.is(observed.length, 2)
|
|
239
247
|
let shape = observed[0]
|
|
240
|
-
t.is(shape.
|
|
248
|
+
t.is(shape.outlines.length, 1)
|
|
249
|
+
t.is(shape.outlines[0].length, 27)
|
|
241
250
|
|
|
242
|
-
observed =
|
|
251
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
243
252
|
t.is(observed.length, 2)
|
|
244
253
|
shape = observed[0]
|
|
245
254
|
t.is(shape.points.length, 27)
|
|
246
255
|
|
|
247
|
-
observed =
|
|
256
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false, segments: 16 }, sourceSvg)
|
|
248
257
|
t.is(observed.length, 2)
|
|
249
258
|
shape = observed[0]
|
|
250
259
|
t.is(shape.points.length, 15) // segments double on a 3/4 circle
|
|
251
|
-
t.deepEqual(
|
|
260
|
+
t.deepEqual(measureBoundingBox(shape), [[64.91110599999999, -77.611105, 0], [90.21850570104527, -52.30370029895471, 0]])
|
|
252
261
|
shape = observed[1]
|
|
253
262
|
t.is(shape.points.length, 15) // segments double on a 3/4 circle
|
|
254
|
-
t.deepEqual(
|
|
263
|
+
t.deepEqual(measureBoundingBox(shape), [[50.799996, -136.03302387090216, 0], [72.27222493929787, -110.6793647936299, 0]])
|
|
255
264
|
})
|
|
256
265
|
|
|
257
266
|
// ################################
|
|
@@ -261,17 +270,18 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
261
270
|
<path d="M100,100 L150,100 a50,25 0 0,0 150,100 q50,-50 70,-170 Z" style="stroke: #006666; fill: none;"/>
|
|
262
271
|
</svg>`
|
|
263
272
|
|
|
264
|
-
let observed =
|
|
273
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
265
274
|
t.is(observed.length, 1)
|
|
266
275
|
let shape = observed[0]
|
|
267
|
-
t.is(shape.
|
|
276
|
+
t.is(shape.outlines.length, 1)
|
|
277
|
+
t.is(shape.outlines[0].length, 14)
|
|
268
278
|
|
|
269
|
-
observed =
|
|
279
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
270
280
|
t.is(observed.length, 1)
|
|
271
281
|
shape = observed[0]
|
|
272
282
|
t.is(shape.points.length, 14)
|
|
273
283
|
|
|
274
|
-
observed =
|
|
284
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false, segments: 16 }, sourceSvg)
|
|
275
285
|
t.is(observed.length, 1)
|
|
276
286
|
shape = observed[0]
|
|
277
287
|
t.is(shape.points.length, 9)
|
|
@@ -282,12 +292,13 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
282
292
|
<path d="M 240 90 c 0 30 7 50 50 0 c 43 -50 50 -30 50 0 c 0 83 -68 -34 -90 -30 C 240 60 240 90 240 90 z"/>
|
|
283
293
|
</svg>`
|
|
284
294
|
|
|
285
|
-
observed =
|
|
295
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
286
296
|
t.is(observed.length, 1)
|
|
287
297
|
shape = observed[0]
|
|
288
|
-
t.is(shape.
|
|
298
|
+
t.is(shape.outlines.length, 1)
|
|
299
|
+
t.is(shape.outlines[0].length, 62)
|
|
289
300
|
|
|
290
|
-
observed =
|
|
301
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
291
302
|
t.is(observed.length, 1)
|
|
292
303
|
shape = observed[0]
|
|
293
304
|
t.is(shape.points.length, 62)
|
|
@@ -297,12 +308,13 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
297
308
|
<path d="M 60 100 Q -40 150 60 200 Q 160 150 60 100 z"/>
|
|
298
309
|
</svg>`
|
|
299
310
|
|
|
300
|
-
observed =
|
|
311
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
301
312
|
t.is(observed.length, 1)
|
|
302
313
|
shape = observed[0]
|
|
303
|
-
t.is(shape.
|
|
314
|
+
t.is(shape.outlines.length, 1)
|
|
315
|
+
t.is(shape.outlines[0].length, 28)
|
|
304
316
|
|
|
305
|
-
observed =
|
|
317
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
306
318
|
t.is(observed.length, 1)
|
|
307
319
|
shape = observed[0]
|
|
308
320
|
t.is(shape.points.length, 28)
|
|
@@ -313,12 +325,12 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
313
325
|
<path d="M 210 130 C 145 130 110 80 110 80 S 75 25 10 25 m 0 105 c 65 0 100 -50 100 -50 s 35 -55 100 -55"/>
|
|
314
326
|
</svg>`
|
|
315
327
|
|
|
316
|
-
observed =
|
|
328
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
317
329
|
t.is(observed.length, 2)
|
|
318
330
|
shape = observed[0]
|
|
319
331
|
t.is(shape.points.length, 14) // open path
|
|
320
332
|
|
|
321
|
-
observed =
|
|
333
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
322
334
|
t.is(observed.length, 2)
|
|
323
335
|
shape = observed[0]
|
|
324
336
|
t.is(shape.points.length, 14)
|
|
@@ -331,12 +343,12 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
331
343
|
<path d="M 10 80 Q 52.5 10 95 80 T 180 80"/>
|
|
332
344
|
</svg>`
|
|
333
345
|
|
|
334
|
-
observed =
|
|
346
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
335
347
|
t.is(observed.length, 1)
|
|
336
348
|
shape = observed[0]
|
|
337
349
|
t.is(shape.points.length, 29) // open path
|
|
338
350
|
|
|
339
|
-
observed =
|
|
351
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
340
352
|
t.is(observed.length, 1)
|
|
341
353
|
shape = observed[0]
|
|
342
354
|
t.is(shape.points.length, 29)
|
|
@@ -346,13 +358,13 @@ test('deserialize : instantiate svg (path: with bezier) to objects', (t) => {
|
|
|
346
358
|
<path id="Sin_Mqttttz" fill="#FF0000" d="M240 296 q25-100 47 0 t47 0 t47 0 t47 0 t47 0 z"/>
|
|
347
359
|
</svg>`
|
|
348
360
|
|
|
349
|
-
observed =
|
|
361
|
+
observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
350
362
|
t.is(observed.length, 1)
|
|
351
363
|
shape = observed[0]
|
|
352
|
-
t.is(shape.
|
|
364
|
+
t.is(shape.outlines.length, 1)
|
|
353
365
|
t.deepEqual(shape.color, [1, 0, 0, 1])
|
|
354
366
|
|
|
355
|
-
observed =
|
|
367
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
356
368
|
t.is(observed.length, 1)
|
|
357
369
|
shape = observed[0]
|
|
358
370
|
t.is(shape.points.length, 101)
|
|
@@ -407,14 +419,16 @@ test('deserialize : instantiate svg produced by inkscape to objects', (t) => {
|
|
|
407
419
|
</svg>
|
|
408
420
|
`
|
|
409
421
|
|
|
410
|
-
let observed =
|
|
422
|
+
let observed = deserialize({ filename: 'inkscape', output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
411
423
|
t.is(observed.length, 2)
|
|
412
424
|
let shape = observed[0]
|
|
413
|
-
t.is(shape.
|
|
425
|
+
t.is(shape.outlines.length, 1)
|
|
426
|
+
t.is(shape.outlines[0].length, 19)
|
|
414
427
|
shape = observed[1]
|
|
415
|
-
t.is(shape.
|
|
428
|
+
t.is(shape.outlines.length, 1)
|
|
429
|
+
t.is(shape.outlines[0].length, 20)
|
|
416
430
|
|
|
417
|
-
observed =
|
|
431
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
418
432
|
t.is(observed.length, 2)
|
|
419
433
|
shape = observed[0]
|
|
420
434
|
t.is(shape.points.length, 19)
|
|
@@ -431,14 +445,16 @@ test('deserialize : instantiate shape with a hole to objects', (t) => {
|
|
|
431
445
|
</svg>
|
|
432
446
|
`
|
|
433
447
|
|
|
434
|
-
let observed =
|
|
448
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
435
449
|
t.is(observed.length, 2)
|
|
436
450
|
let shape = observed[0]
|
|
437
|
-
t.is(shape.
|
|
451
|
+
t.is(shape.outlines.length, 1)
|
|
452
|
+
t.is(shape.outlines[0].length, 38)
|
|
438
453
|
shape = observed[1]
|
|
439
|
-
t.is(shape.
|
|
454
|
+
t.is(shape.outlines.length, 1)
|
|
455
|
+
t.is(shape.outlines[0].length, 38)
|
|
440
456
|
|
|
441
|
-
observed =
|
|
457
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
442
458
|
t.is(observed.length, 2)
|
|
443
459
|
shape = observed[0]
|
|
444
460
|
t.is(shape.points.length, 38)
|
|
@@ -455,12 +471,13 @@ test('deserialize : instantiate shape with a nested hole to objects', (t) => {
|
|
|
455
471
|
</svg>
|
|
456
472
|
`
|
|
457
473
|
|
|
458
|
-
let observed =
|
|
474
|
+
let observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
459
475
|
t.is(observed.length, 4)
|
|
460
476
|
let shape = observed[0]
|
|
461
|
-
t.is(shape.
|
|
477
|
+
t.is(shape.outlines.length, 1)
|
|
478
|
+
t.is(shape.outlines[0].length, 38)
|
|
462
479
|
|
|
463
|
-
observed =
|
|
480
|
+
observed = deserialize({ output: 'geometry', target: 'path', addMetaData: false }, sourceSvg)
|
|
464
481
|
t.is(observed.length, 4)
|
|
465
482
|
shape = observed[0]
|
|
466
483
|
t.is(shape.points.length, 38)
|
|
@@ -480,10 +497,11 @@ test('deserialize : translate svg with simple defs to script', (t) => {
|
|
|
480
497
|
</g>
|
|
481
498
|
</svg>`
|
|
482
499
|
|
|
483
|
-
const observed =
|
|
500
|
+
const observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
484
501
|
t.is(observed.length, 1)
|
|
485
502
|
const shape = observed[0]
|
|
486
|
-
t.is(shape.
|
|
503
|
+
t.is(shape.outlines.length, 1)
|
|
504
|
+
t.is(shape.outlines[0].length, 32)
|
|
487
505
|
})
|
|
488
506
|
|
|
489
507
|
// ################################
|
|
@@ -505,8 +523,9 @@ test('deserialize : translate svg with defs using defs to script', (t) => {
|
|
|
505
523
|
</g>
|
|
506
524
|
</svg>`
|
|
507
525
|
|
|
508
|
-
const observed =
|
|
526
|
+
const observed = deserialize({ output: 'geometry', target: 'geom2', addMetaData: false }, sourceSvg)
|
|
509
527
|
t.is(observed.length, 1)
|
|
510
528
|
const shape = observed[0]
|
|
511
|
-
t.is(shape.
|
|
529
|
+
t.is(shape.outlines.length, 1)
|
|
530
|
+
t.is(shape.outlines[0].length, 32)
|
|
512
531
|
})
|
package/tests/issue.1135.test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { deserialize } from '../src/index.js'
|
|
4
4
|
|
|
5
5
|
test('deserialize issue 885 do not fail on close at the end', (t) => {
|
|
6
6
|
const svg = '<svg><g><path d="M0 0 L10 10L10 0L0 0" id="path4544" /></g></svg>'
|
|
7
7
|
|
|
8
|
-
const shapes =
|
|
8
|
+
const shapes = deserialize({ output: 'geometry', pathSelfClosed: 'error' }, svg)
|
|
9
9
|
t.is(shapes.length, 1)
|
|
10
10
|
})
|
package/tests/issue.885.test.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// deserializer
|
|
6
|
-
|
|
7
|
-
// ################################
|
|
3
|
+
import { deserialize } from '../src/index.js'
|
|
8
4
|
|
|
9
5
|
test('deserialize issue 885', (t) => {
|
|
10
6
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="5.791015625" height="11.71875">
|
|
@@ -12,12 +8,12 @@ test('deserialize issue 885', (t) => {
|
|
|
12
8
|
</svg>`
|
|
13
9
|
|
|
14
10
|
t.throws(() => {
|
|
15
|
-
|
|
11
|
+
deserialize({ output: 'geometry' }, svg)
|
|
16
12
|
}, { instanceOf: Error }, 'Malformed svg path at 2:445. Path closed itself with command #29: "Q2.12 -3.54 1.84 -3.17". to avoid this error use pathSelfClosed:\'split\' or pathSelfClosed:\'trim\' option')
|
|
17
13
|
|
|
18
|
-
let shapes =
|
|
14
|
+
let shapes = deserialize({ output: 'geometry', pathSelfClosed: 'split' }, svg)
|
|
19
15
|
t.is(shapes.length, 2)
|
|
20
16
|
|
|
21
|
-
shapes =
|
|
17
|
+
shapes = deserialize({ output: 'geometry', pathSelfClosed: 'trim' }, svg)
|
|
22
18
|
t.is(shapes.length, 1)
|
|
23
19
|
})
|