@jscad/io 2.4.6 → 3.0.0-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 -242
- package/README.md +2 -3
- package/package.json +31 -24
- package/src/deserialize.js +61 -0
- package/src/deserializers.js +16 -0
- package/{formats.js → src/formats.js} +43 -59
- package/src/index.js +14 -0
- package/{prepareOutput.js → src/prepareOutput.js} +14 -15
- package/src/serialize.js +35 -0
- package/src/serializers.js +21 -0
- package/tests/deserialize.test.js +45 -0
- package/tests/serialize.test.js +37 -0
- package/deserializers.js +0 -19
- package/index.js +0 -31
package/CHANGELOG.md
CHANGED
|
@@ -3,551 +3,320 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @jscad/io
|
|
6
|
+
# [3.0.0-alpha.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.4.3...@jscad/io@3.0.0-alpha.0) (2023-10-09)
|
|
9
7
|
|
|
8
|
+
### Bug Fixes
|
|
10
9
|
|
|
10
|
+
* **io:** fix io after V3 refactoring ([7a12bbd](https://github.com/jscad/OpenJSCAD.org/commit/7a12bbdb7b4b3df792a4c5b3c8b30a6a985a48f0))
|
|
11
11
|
|
|
12
|
+
### Features
|
|
12
13
|
|
|
14
|
+
* **3mf-deserializer:** initial version of 3MF deserializer and tests ([b22a27f](https://github.com/jscad/OpenJSCAD.org/commit/b22a27fa14c4f42b9160553cdd7b3c126ac72459))
|
|
15
|
+
* **cli:** reworked logic to use new io package exports and functions ([#1199](https://github.com/jscad/OpenJSCAD.org/issues/1199)) ([71a3d27](https://github.com/jscad/OpenJSCAD.org/commit/71a3d27a4cf416b1a9fea57a1fe40f5cfdaa905c))
|
|
16
|
+
* **modeling:** reworked exports to expose a flattened API ([8235238](https://github.com/jscad/OpenJSCAD.org/commit/8235238ad63d063f1e501478cae1208deb130a9c))
|
|
17
|
+
* **regl-renderer:** added rollup configuration to create ES6 bundle, adjusted imports and exports ([#1259](https://github.com/jscad/OpenJSCAD.org/issues/1259)) ([47a66bc](https://github.com/jscad/OpenJSCAD.org/commit/47a66bc07a137a748ce8571ea5d043ebaab9418d))
|
|
13
18
|
|
|
14
|
-
## [2.4.
|
|
19
|
+
## [2.4.6](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.4.5...@jscad/io@2.4.6) (2023-06-27)
|
|
15
20
|
|
|
16
21
|
**Note:** Version bump only for package @jscad/io
|
|
17
22
|
|
|
23
|
+
## [2.4.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.4.4...@jscad/io@2.4.5) (2023-04-30)
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
**Note:** Version bump only for package @jscad/io
|
|
21
26
|
|
|
22
27
|
## [2.4.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.4.3...@jscad/io@2.4.4) (2022-11-26)
|
|
23
28
|
|
|
24
29
|
**Note:** Version bump only for package @jscad/io
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
31
|
## [2.4.3](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.4.2...@jscad/io@2.4.3) (2022-09-23)
|
|
31
32
|
|
|
32
33
|
**Note:** Version bump only for package @jscad/io
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
35
|
## [2.4.2](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.4.1...@jscad/io@2.4.2) (2022-08-21)
|
|
39
36
|
|
|
40
37
|
**Note:** Version bump only for package @jscad/io
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
39
|
## [2.4.1](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.4.0...@jscad/io@2.4.1) (2022-07-17)
|
|
47
40
|
|
|
48
41
|
**Note:** Version bump only for package @jscad/io
|
|
49
42
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
43
|
# [2.4.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.3.3...@jscad/io@2.4.0) (2022-06-12)
|
|
55
44
|
|
|
56
|
-
|
|
57
45
|
### Features
|
|
58
46
|
|
|
59
47
|
* **x3d-serializer:** enhanced to convert 2D geometry and path to X3D Polyline2D ([#1091](https://github.com/jscad/OpenJSCAD.org/issues/1091)) ([4f763a8](https://github.com/jscad/OpenJSCAD.org/commit/4f763a8def39f3b0454f2079f3c1fd7da52dd880))
|
|
60
48
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
49
|
## [2.3.3](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.3.2...@jscad/io@2.3.3) (2022-05-15)
|
|
66
50
|
|
|
67
51
|
**Note:** Version bump only for package @jscad/io
|
|
68
52
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
53
|
## [2.3.2](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.3.1...@jscad/io@2.3.2) (2022-04-24)
|
|
74
54
|
|
|
75
55
|
**Note:** Version bump only for package @jscad/io
|
|
76
56
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
57
|
## [2.3.1](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.3.0...@jscad/io@2.3.1) (2022-04-03)
|
|
82
58
|
|
|
83
59
|
**Note:** Version bump only for package @jscad/io
|
|
84
60
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
61
|
# [2.3.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.2.6...@jscad/io@2.3.0) (2022-04-03)
|
|
90
62
|
|
|
91
|
-
|
|
92
63
|
### Features
|
|
93
64
|
|
|
94
65
|
* **3mf-serializer:** new serializer from JSCAD geometry to 3MF packages ([6b51aed](https://github.com/jscad/OpenJSCAD.org/commit/6b51aed63ee40674822a04ced773564552689763))
|
|
95
66
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
67
|
## [2.2.6](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.2.5...@jscad/io@2.2.6) (2022-03-13)
|
|
101
68
|
|
|
102
69
|
**Note:** Version bump only for package @jscad/io
|
|
103
70
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
71
|
## [2.2.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.2.4...@jscad/io@2.2.5) (2022-03-06)
|
|
109
72
|
|
|
110
73
|
**Note:** Version bump only for package @jscad/io
|
|
111
74
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
75
|
## [2.2.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.2.3...@jscad/io@2.2.4) (2022-02-19)
|
|
117
76
|
|
|
118
77
|
**Note:** Version bump only for package @jscad/io
|
|
119
78
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
79
|
## [2.2.3](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.2.2...@jscad/io@2.2.3) (2022-01-23)
|
|
125
80
|
|
|
126
81
|
**Note:** Version bump only for package @jscad/io
|
|
127
82
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
83
|
## [2.2.2](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.2.1...@jscad/io@2.2.2) (2021-12-26)
|
|
133
84
|
|
|
134
85
|
**Note:** Version bump only for package @jscad/io
|
|
135
86
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
87
|
## [2.2.1](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.2.0...@jscad/io@2.2.1) (2021-12-11)
|
|
141
88
|
|
|
142
89
|
**Note:** Version bump only for package @jscad/io
|
|
143
90
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
91
|
# [2.2.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.1.0...@jscad/io@2.2.0) (2021-11-07)
|
|
149
92
|
|
|
150
|
-
|
|
151
93
|
### Features
|
|
152
94
|
|
|
153
95
|
* **io:** new serializer for OBJ ([#942](https://github.com/jscad/OpenJSCAD.org/issues/942)) ([baaae18](https://github.com/jscad/OpenJSCAD.org/commit/baaae18ad55252ec71b074bd85dea7d137a22eb8))
|
|
154
96
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
97
|
# [2.1.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.9...@jscad/io@2.1.0) (2021-10-17)
|
|
160
98
|
|
|
161
|
-
|
|
162
99
|
### Features
|
|
163
100
|
|
|
164
101
|
* **io:** added registration of x3d-deserializer ([57aee3f](https://github.com/jscad/OpenJSCAD.org/commit/57aee3fee0626e8dd13bd89ea4a6a5f3f108bd54))
|
|
165
102
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
103
|
## [2.0.9](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.8...@jscad/io@2.0.9) (2021-10-04)
|
|
171
104
|
|
|
172
105
|
**Note:** Version bump only for package @jscad/io
|
|
173
106
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
107
|
## [2.0.8](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.7...@jscad/io@2.0.8) (2021-09-27)
|
|
179
108
|
|
|
180
109
|
**Note:** Version bump only for package @jscad/io
|
|
181
110
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
111
|
## [2.0.7](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.6...@jscad/io@2.0.7) (2021-09-09)
|
|
187
112
|
|
|
188
113
|
**Note:** Version bump only for package @jscad/io
|
|
189
114
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
115
|
## [2.0.6](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.5...@jscad/io@2.0.6) (2021-06-20)
|
|
195
116
|
|
|
196
117
|
**Note:** Version bump only for package @jscad/io
|
|
197
118
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
119
|
## [2.0.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.4...@jscad/io@2.0.5) (2021-06-11)
|
|
203
120
|
|
|
204
|
-
|
|
205
121
|
### Bug Fixes
|
|
206
122
|
|
|
207
123
|
* **io:** corrected assembly of serialization options in generateOutputData ([c57d8da](https://github.com/jscad/OpenJSCAD.org/commit/c57d8daa23db27992bc0c09137d1df51c2f039e8))
|
|
208
124
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
125
|
## [2.0.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.3...@jscad/io@2.0.4) (2021-06-01)
|
|
214
126
|
|
|
215
127
|
**Note:** Version bump only for package @jscad/io
|
|
216
128
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
129
|
## [2.0.3](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.2...@jscad/io@2.0.3) (2021-04-20)
|
|
222
130
|
|
|
223
131
|
**Note:** Version bump only for package @jscad/io
|
|
224
132
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
133
|
## [2.0.2](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.0...@jscad/io@2.0.2) (2021-04-17)
|
|
230
134
|
|
|
231
|
-
|
|
232
135
|
### Bug Fixes
|
|
233
136
|
|
|
234
137
|
* **all:** fix json import ([#675](https://github.com/jscad/OpenJSCAD.org/issues/675)) ([05caf60](https://github.com/jscad/OpenJSCAD.org/commit/05caf60efc3f090313b3e0bddcc0b4f94de67c78))
|
|
235
138
|
* **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
|
|
236
139
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
140
|
## [2.0.1](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.0...@jscad/io@2.0.1) (2021-04-15)
|
|
242
141
|
|
|
243
|
-
|
|
244
142
|
### Bug Fixes
|
|
245
143
|
|
|
246
144
|
* **all:** fix json import ([#675](https://github.com/jscad/OpenJSCAD.org/issues/675)) ([05caf60](https://github.com/jscad/OpenJSCAD.org/commit/05caf60efc3f090313b3e0bddcc0b4f94de67c78))
|
|
247
145
|
* **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
|
|
248
146
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
147
|
# [2.0.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.13...@jscad/io@2.0.0) (2021-04-12)
|
|
254
148
|
|
|
255
149
|
**Note:** Version bump only for package @jscad/io
|
|
256
150
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
151
|
# [2.0.0-alpha.13](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.12...@jscad/io@2.0.0-alpha.13) (2021-03-07)
|
|
262
152
|
|
|
263
153
|
**Note:** Version bump only for package @jscad/io
|
|
264
154
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
155
|
# [2.0.0-alpha.12](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.11...@jscad/io@2.0.0-alpha.12) (2021-02-07)
|
|
270
156
|
|
|
271
157
|
**Note:** Version bump only for package @jscad/io
|
|
272
158
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
159
|
# [2.0.0-alpha.11](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.10...@jscad/io@2.0.0-alpha.11) (2021-01-02)
|
|
278
160
|
|
|
279
161
|
**Note:** Version bump only for package @jscad/io
|
|
280
162
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
163
|
# [2.0.0-alpha.10](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.9...@jscad/io@2.0.0-alpha.10) (2020-12-04)
|
|
286
164
|
|
|
287
165
|
**Note:** Version bump only for package @jscad/io
|
|
288
166
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
167
|
# [2.0.0-alpha.9](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/io@2.0.0-alpha.8...@jscad/io@2.0.0-alpha.9) (2020-11-07)
|
|
294
168
|
|
|
295
|
-
|
|
296
169
|
### Bug Fixes
|
|
297
170
|
|
|
298
171
|
* **io:** io revisited ([#714](https://github.com/jscad/OpenJSCAD.org/issues/714)) ([22f04f1](https://github.com/jscad/OpenJSCAD.org/commit/22f04f1b2894a82e24952655875e73b74727bf86))
|
|
299
172
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
173
|
# [2.0.0-alpha.8](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.7...@jscad/io@2.0.0-alpha.8) (2020-10-24)
|
|
305
174
|
|
|
306
175
|
**Note:** Version bump only for package @jscad/io
|
|
307
176
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
177
|
# [2.0.0-alpha.7](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.6...@jscad/io@2.0.0-alpha.7) (2020-10-11)
|
|
313
178
|
|
|
314
179
|
**Note:** Version bump only for package @jscad/io
|
|
315
180
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
181
|
# [2.0.0-alpha.6](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.5...@jscad/io@2.0.0-alpha.6) (2020-09-29)
|
|
321
182
|
|
|
322
183
|
**Note:** Version bump only for package @jscad/io
|
|
323
184
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
185
|
# [2.0.0-alpha.5](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.4...@jscad/io@2.0.0-alpha.5) (2020-09-28)
|
|
329
186
|
|
|
330
187
|
**Note:** Version bump only for package @jscad/io
|
|
331
188
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
189
|
# [2.0.0-alpha.4](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.3...@jscad/io@2.0.0-alpha.4) (2020-09-19)
|
|
337
190
|
|
|
338
|
-
|
|
339
191
|
### Bug Fixes
|
|
340
192
|
|
|
341
193
|
* **all:** fix json import ([#675](https://github.com/jscad/io/issues/675)) ([05caf60](https://github.com/jscad/io/commit/05caf60efc3f090313b3e0bddcc0b4f94de67c78))
|
|
342
194
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
195
|
# [2.0.0-alpha.3](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.2...@jscad/io@2.0.0-alpha.3) (2020-09-08)
|
|
348
196
|
|
|
349
197
|
**Note:** Version bump only for package @jscad/io
|
|
350
198
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
199
|
# [2.0.0-alpha.2](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.1...@jscad/io@2.0.0-alpha.2) (2020-09-02)
|
|
356
200
|
|
|
357
201
|
**Note:** Version bump only for package @jscad/io
|
|
358
202
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
203
|
# [2.0.0-alpha.1](https://github.com/jscad/io/compare/@jscad/io@2.0.0-alpha.0...@jscad/io@2.0.0-alpha.1) (2020-08-19)
|
|
364
204
|
|
|
365
205
|
**Note:** Version bump only for package @jscad/io
|
|
366
206
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
207
|
# 2.0.0-alpha.0 (2020-08-13)
|
|
372
208
|
|
|
373
209
|
### Features
|
|
374
210
|
|
|
375
211
|
* **io:** merge IO packages into main repository (#436)
|
|
376
212
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
213
|
<a name="0.5.0"></a>
|
|
382
214
|
# [0.5.0](https://github.com/jscad/io/compare/@jscad/io@0.4.8...@jscad/io@0.5.0) (2018-11-25)
|
|
383
215
|
|
|
384
|
-
|
|
385
216
|
### Features
|
|
386
217
|
|
|
387
218
|
* **scad-deserializer:** added old openscad-openjscad-translator to the packages ([#75](https://github.com/jscad/io/issues/75)) ([0a20323](https://github.com/jscad/io/commit/0a20323))
|
|
388
219
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
220
|
<a name="0.4.8"></a>
|
|
393
221
|
## [0.4.8](https://github.com/jscad/io/compare/@jscad/io@0.4.7...@jscad/io@0.4.8) (2018-11-22)
|
|
394
222
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
223
|
**Note:** Version bump only for package @jscad/io
|
|
399
224
|
|
|
400
225
|
<a name="0.4.7"></a>
|
|
401
226
|
## [0.4.7](https://github.com/jscad/io/compare/@jscad/io@0.4.6...@jscad/io@0.4.7) (2018-09-02)
|
|
402
227
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
228
|
**Note:** Version bump only for package @jscad/io
|
|
407
229
|
|
|
408
230
|
<a name="0.4.6"></a>
|
|
409
231
|
## [0.4.6](https://github.com/jscad/io/compare/@jscad/io@0.4.5...@jscad/io@0.4.6) (2018-06-11)
|
|
410
232
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
233
|
**Note:** Version bump only for package @jscad/io
|
|
415
234
|
|
|
416
235
|
<a name="0.4.5"></a>
|
|
417
236
|
## [0.4.5](https://github.com/jscad/io/compare/@jscad/io@0.4.4...@jscad/io@0.4.5) (2018-05-24)
|
|
418
237
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
238
|
**Note:** Version bump only for package @jscad/io
|
|
423
239
|
|
|
424
240
|
<a name="0.4.4"></a>
|
|
425
241
|
## [0.4.4](https://github.com/jscad/io/compare/@jscad/io@0.4.3...@jscad/io@0.4.4) (2018-04-07)
|
|
426
242
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
243
|
**Note:** Version bump only for package @jscad/io
|
|
431
244
|
|
|
432
245
|
<a name="0.4.3"></a>
|
|
433
246
|
## [0.4.3](https://github.com/jscad/io/compare/@jscad/io@0.4.2...@jscad/io@0.4.3) (2018-04-01)
|
|
434
247
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
248
|
**Note:** Version bump only for package @jscad/io
|
|
439
249
|
|
|
440
250
|
<a name="0.4.2"></a>
|
|
441
251
|
## [0.4.2](https://github.com/jscad/io/compare/@jscad/io@0.4.1...@jscad/io@0.4.2) (2018-04-01)
|
|
442
252
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
253
|
**Note:** Version bump only for package @jscad/io
|
|
447
254
|
|
|
448
255
|
<a name="0.4.1"></a>
|
|
449
256
|
## [0.4.1](https://github.com/jscad/io/compare/@jscad/io@0.4.0...@jscad/io@0.4.1) (2018-03-15)
|
|
450
257
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
258
|
**Note:** Version bump only for package @jscad/io
|
|
455
259
|
|
|
456
260
|
<a name="0.4.0"></a>
|
|
457
261
|
# [0.4.0](https://github.com/jscad/io/compare/@jscad/io@0.3.12...@jscad/io@0.4.0) (2018-02-24)
|
|
458
262
|
|
|
459
|
-
|
|
460
263
|
### Features
|
|
461
264
|
|
|
462
265
|
* **DXF Deserializer:** Adds dxf deserializer and all associated code ([ae4a6c0](https://github.com/jscad/io/commit/ae4a6c0)), closes [#10](https://github.com/jscad/io/issues/10)
|
|
463
266
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
267
|
<a name="0.3.12"></a>
|
|
468
268
|
## [0.3.12](https://github.com/jscad/io/compare/@jscad/io@0.3.11...@jscad/io@0.3.12) (2017-12-14)
|
|
469
269
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
270
|
**Note:** Version bump only for package @jscad/io
|
|
474
271
|
|
|
475
272
|
<a name="0.3.11"></a>
|
|
476
273
|
## [0.3.11](https://github.com/jscad/io/compare/@jscad/io@0.3.10...@jscad/io@0.3.11) (2017-12-14)
|
|
477
274
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
275
|
**Note:** Version bump only for package @jscad/io
|
|
482
276
|
|
|
483
277
|
<a name="0.3.10"></a>
|
|
484
278
|
## [0.3.10](https://github.com/jscad/io/compare/@jscad/io@0.3.9...@jscad/io@0.3.10) (2017-11-29)
|
|
485
279
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
280
|
**Note:** Version bump only for package @jscad/io
|
|
490
281
|
|
|
491
282
|
<a name="0.3.9"></a>
|
|
492
283
|
## [0.3.9](https://github.com/jscad/io/compare/@jscad/io@0.3.8...@jscad/io@0.3.9) (2017-11-20)
|
|
493
284
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
285
|
**Note:** Version bump only for package @jscad/io
|
|
498
286
|
|
|
499
287
|
<a name="0.3.8"></a>
|
|
500
288
|
## [0.3.8](https://github.com/jscad/io/compare/@jscad/io@0.3.7...@jscad/io@0.3.8) (2017-11-14)
|
|
501
289
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
290
|
**Note:** Version bump only for package @jscad/io
|
|
506
291
|
|
|
507
292
|
<a name="0.3.7"></a>
|
|
508
293
|
## [0.3.7](https://github.com/jscad/io/compare/@jscad/io@0.3.6...@jscad/io@0.3.7) (2017-11-04)
|
|
509
294
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
295
|
**Note:** Version bump only for package @jscad/io
|
|
514
296
|
|
|
515
297
|
<a name="0.3.6"></a>
|
|
516
298
|
## [0.3.6](https://github.com/jscad/io/compare/@jscad/io@0.3.5...@jscad/io@0.3.6) (2017-11-04)
|
|
517
299
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
300
|
**Note:** Version bump only for package @jscad/io
|
|
522
301
|
|
|
523
302
|
<a name="0.3.5"></a>
|
|
524
303
|
## [0.3.5](https://github.com/jscad/io/compare/@jscad/io@0.3.4...@jscad/io@0.3.5) (2017-10-30)
|
|
525
304
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
305
|
**Note:** Version bump only for package @jscad/io
|
|
530
306
|
|
|
531
307
|
<a name="0.3.4"></a>
|
|
532
308
|
## [0.3.4](https://github.com/jscad/io/compare/@jscad/io@0.3.3...@jscad/io@0.3.4) (2017-10-15)
|
|
533
309
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
310
|
**Note:** Version bump only for package @jscad/io
|
|
538
311
|
|
|
539
312
|
<a name="0.3.3"></a>
|
|
540
313
|
## [0.3.3](https://github.com/jscad/io/compare/@jscad/io@0.3.2...@jscad/io@0.3.3) (2017-10-10)
|
|
541
314
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
315
|
**Note:** Version bump only for package @jscad/io
|
|
546
316
|
|
|
547
317
|
<a name="0.3.2"></a>
|
|
548
318
|
## 0.3.2 (2017-10-10)
|
|
549
319
|
|
|
550
|
-
|
|
551
320
|
### Bug Fixes
|
|
552
321
|
|
|
553
322
|
* **io:** fixed bad version numbers for svg de/serializers ([#28](https://github.com/jscad/io/issues/28)) ([60d239c](https://github.com/jscad/io/commit/60d239c))
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[](https://github.com/jscad/OpenJSCAD.org/blob/master/LICENSE)
|
|
10
10
|
|
|
11
11
|
[](https://openjscad.nodebb.com/)
|
|
12
|
-
[](https://github.com/ghiscoding/lerna-lite)
|
|
13
13
|
[](https://standardjs.com)
|
|
14
14
|
|
|
15
15
|
[](https://opencollective.com/openjscad)
|
|
@@ -26,20 +26,19 @@ This package is a metapackage and includes all the input/output format handling
|
|
|
26
26
|
ie: file data => JSCAD code or JSCAD geometry
|
|
27
27
|
|
|
28
28
|
Following formats are supported as inputs
|
|
29
|
-
- [AMF](../amf-deserializer)
|
|
30
29
|
- [DXF](../dxf-deserializer)
|
|
31
30
|
- [JSON](../json-deserializer)
|
|
32
31
|
- [OBJ](../obj-deserializer)
|
|
33
32
|
- [STL (binary, ASCII)](../stl-deserializer)
|
|
34
33
|
- [SVG](../svg-deserializer)
|
|
35
34
|
- [X3D](../x3d-deserializer)
|
|
35
|
+
- [3MF](../3mf-deserializer)
|
|
36
36
|
|
|
37
37
|
### Outputs/ Serializers
|
|
38
38
|
|
|
39
39
|
ie: geometry => blob
|
|
40
40
|
|
|
41
41
|
Following formats are supported as outputs
|
|
42
|
-
- [AMF](../amf-serializer)
|
|
43
42
|
- [DXF](../dxf-serializer)
|
|
44
43
|
- [JSON](../json-serializer)
|
|
45
44
|
- [OBJ](../obj-serializer)
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/io",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"description": "Meta Package for JSCAD IO Packages",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
7
|
-
"main": "index.js",
|
|
8
|
-
"
|
|
7
|
+
"main": "src/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"coverage": "c8 --all --reporter=html --reporter=text npm test",
|
|
11
|
+
"test": "ava --verbose --timeout 2m './tests/*.test.js'"
|
|
12
|
+
},
|
|
9
13
|
"contributors": [
|
|
10
14
|
{
|
|
11
15
|
"name": "Rene K. Mueller",
|
|
12
|
-
"url": "
|
|
16
|
+
"url": "https://github.com/Spiritdude"
|
|
13
17
|
},
|
|
14
18
|
{
|
|
15
19
|
"name": "z3dev",
|
|
@@ -17,7 +21,7 @@
|
|
|
17
21
|
},
|
|
18
22
|
{
|
|
19
23
|
"name": "Mark 'kaosat-dev' Moissette",
|
|
20
|
-
"url": "
|
|
24
|
+
"url": "https://github.com/kaosat-dev"
|
|
21
25
|
}
|
|
22
26
|
],
|
|
23
27
|
"keywords": [
|
|
@@ -30,24 +34,27 @@
|
|
|
30
34
|
],
|
|
31
35
|
"license": "MIT",
|
|
32
36
|
"dependencies": {
|
|
33
|
-
"@jscad/3mf-
|
|
34
|
-
"@jscad/
|
|
35
|
-
"@jscad/
|
|
36
|
-
"@jscad/
|
|
37
|
-
"@jscad/dxf-
|
|
38
|
-
"@jscad/
|
|
39
|
-
"@jscad/
|
|
40
|
-
"@jscad/json-
|
|
41
|
-
"@jscad/
|
|
42
|
-
"@jscad/
|
|
43
|
-
"@jscad/obj-
|
|
44
|
-
"@jscad/
|
|
45
|
-
"@jscad/stl-
|
|
46
|
-
"@jscad/
|
|
47
|
-
"@jscad/svg-
|
|
48
|
-
"@jscad/
|
|
49
|
-
"@jscad/x3d-
|
|
50
|
-
|
|
37
|
+
"@jscad/3mf-deserializer": "3.0.0-alpha.0",
|
|
38
|
+
"@jscad/3mf-serializer": "3.0.0-alpha.0",
|
|
39
|
+
"@jscad/array-utils": "3.0.0-alpha.0",
|
|
40
|
+
"@jscad/dxf-deserializer": "3.0.0-alpha.0",
|
|
41
|
+
"@jscad/dxf-serializer": "3.0.0-alpha.0",
|
|
42
|
+
"@jscad/io-utils": "3.0.0-alpha.0",
|
|
43
|
+
"@jscad/json-deserializer": "3.0.0-alpha.0",
|
|
44
|
+
"@jscad/json-serializer": "3.0.0-alpha.0",
|
|
45
|
+
"@jscad/modeling": "3.0.0-alpha.0",
|
|
46
|
+
"@jscad/obj-deserializer": "3.0.0-alpha.0",
|
|
47
|
+
"@jscad/obj-serializer": "3.0.0-alpha.0",
|
|
48
|
+
"@jscad/stl-deserializer": "3.0.0-alpha.0",
|
|
49
|
+
"@jscad/stl-serializer": "3.0.0-alpha.0",
|
|
50
|
+
"@jscad/svg-deserializer": "3.0.0-alpha.0",
|
|
51
|
+
"@jscad/svg-serializer": "3.0.0-alpha.0",
|
|
52
|
+
"@jscad/x3d-deserializer": "3.0.0-alpha.0",
|
|
53
|
+
"@jscad/x3d-serializer": "3.0.0-alpha.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"ava": "^4.3.3",
|
|
57
|
+
"c8": "^8.0.0"
|
|
51
58
|
},
|
|
52
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "3656d36ed9cd738ab884e86aae5a2ce08d52adf7"
|
|
53
60
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { deserializers } from './deserializers.js'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Transform the source into ES6 javascript
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// no transform required, just pass through the source
|
|
8
|
+
const nullTransform = (options, source) => source
|
|
9
|
+
|
|
10
|
+
// TODO : how to transform CommonJS code?
|
|
11
|
+
const transformers = {
|
|
12
|
+
'application/javascript': nullTransform
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Deserialize the given source as per the given mimeType.
|
|
17
|
+
* Options can be provided to over-ride or suppliment the defaults used during deserialization.
|
|
18
|
+
* Options must include 'output' as either 'script' or 'geometry'.
|
|
19
|
+
* @param {Object} options - options used during deserializing
|
|
20
|
+
* @param {String} mimeType - MIME type of the file
|
|
21
|
+
* @param {String} source - the contents of the file
|
|
22
|
+
* @return {[objects]|string} a list of objects (geometry) or a string (script)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const mimetype = getMimeType('svg')
|
|
26
|
+
* const myobjects = deserialize({output: 'geometry', target: 'path2'}, mimetype, source)
|
|
27
|
+
*/
|
|
28
|
+
export const deserialize = (options, mimeType, source) => {
|
|
29
|
+
// commonly used defaults from the deserializers
|
|
30
|
+
const defaults = {
|
|
31
|
+
addMetaData: true,
|
|
32
|
+
segments: 32
|
|
33
|
+
}
|
|
34
|
+
options = Object.assign({}, defaults, options)
|
|
35
|
+
|
|
36
|
+
if (options.output) {
|
|
37
|
+
if (options.output === 'script') {
|
|
38
|
+
// transform souce code if possible
|
|
39
|
+
if (mimeType in transformers) {
|
|
40
|
+
const transformer = transformers[mimeType]
|
|
41
|
+
return transformer(options, source)
|
|
42
|
+
}
|
|
43
|
+
// deserialize know formats if possible
|
|
44
|
+
if (mimeType in deserializers) {
|
|
45
|
+
const deserializer = deserializers[mimeType]
|
|
46
|
+
return deserializer(options, source)
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`Unknown mime type (${mimeType})`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (options.output === 'geometry') {
|
|
52
|
+
// deserialize know formats if possible
|
|
53
|
+
if (mimeType in deserializers) {
|
|
54
|
+
const deserializer = deserializers[mimeType]
|
|
55
|
+
return deserializer(options, source)
|
|
56
|
+
}
|
|
57
|
+
throw new Error(`Unknown mime type (${mimeType})`)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Unknown output option (${options.output}), only 'script' or 'geometry' allowed`)
|
|
61
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as mf3DeSerializer from '@jscad/3mf-deserializer'
|
|
2
|
+
import * as dxfDeSerializer from '@jscad/dxf-deserializer'
|
|
3
|
+
import * as jsonDeSerializer from '@jscad/json-deserializer'
|
|
4
|
+
import * as objDeSerializer from '@jscad/obj-deserializer'
|
|
5
|
+
import * as stlDeSerializer from '@jscad/stl-deserializer'
|
|
6
|
+
import * as svgDeSerializer from '@jscad/svg-deserializer'
|
|
7
|
+
import * as x3dDeSerializer from '@jscad/x3d-deserializer'
|
|
8
|
+
|
|
9
|
+
export const deserializers = {}
|
|
10
|
+
deserializers[mf3DeSerializer.mimeType] = mf3DeSerializer.deserialize
|
|
11
|
+
deserializers[dxfDeSerializer.mimeType] = dxfDeSerializer.deserialize
|
|
12
|
+
deserializers[jsonDeSerializer.mimeType] = jsonDeSerializer.deserialize
|
|
13
|
+
deserializers[objDeSerializer.mimeType] = objDeSerializer.deserialize
|
|
14
|
+
deserializers[stlDeSerializer.mimeType] = stlDeSerializer.deserialize
|
|
15
|
+
deserializers[svgDeSerializer.mimeType] = svgDeSerializer.deserialize
|
|
16
|
+
deserializers[x3dDeSerializer.mimeType] = x3dDeSerializer.deserialize
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { geom2, geom3, path2 } from '@jscad/modeling'
|
|
2
2
|
|
|
3
3
|
// handled format descriptions
|
|
4
|
-
// note: order is important as regular expressions are created from
|
|
5
|
-
|
|
4
|
+
// note: order is important as regular expressions are created from extensions
|
|
5
|
+
// see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
6
|
+
export const supportedFormats = {
|
|
6
7
|
stl: {
|
|
7
8
|
displayName: 'STL (Binary)',
|
|
8
9
|
description: 'STereoLithography, Binary',
|
|
9
10
|
extension: 'stl',
|
|
10
|
-
mimetype: '
|
|
11
|
+
mimetype: 'model/stl',
|
|
11
12
|
deserializable: true,
|
|
12
13
|
convertGeom3: false,
|
|
13
14
|
convertGeom2: false
|
|
@@ -16,7 +17,7 @@ const formats = {
|
|
|
16
17
|
displayName: 'STL (ASCII)',
|
|
17
18
|
description: 'STereoLithography, ASCII',
|
|
18
19
|
extension: 'stl',
|
|
19
|
-
mimetype: '
|
|
20
|
+
mimetype: 'model/stl',
|
|
20
21
|
deserializable: false, // just once
|
|
21
22
|
convertGeom3: true,
|
|
22
23
|
convertGeom2: false
|
|
@@ -25,25 +26,16 @@ const formats = {
|
|
|
25
26
|
displayName: 'STL (Binary)',
|
|
26
27
|
description: 'STereoLithography, Binary',
|
|
27
28
|
extension: 'stl',
|
|
28
|
-
mimetype: '
|
|
29
|
+
mimetype: 'model/stl',
|
|
29
30
|
deserializable: false, // just once
|
|
30
31
|
convertGeom3: true,
|
|
31
32
|
convertGeom2: false
|
|
32
33
|
},
|
|
33
|
-
amf: {
|
|
34
|
-
displayName: 'AMF (experimental)',
|
|
35
|
-
description: 'Additive Manufacturing File Format',
|
|
36
|
-
extension: 'amf',
|
|
37
|
-
mimetype: 'application/amf+xml',
|
|
38
|
-
deserializable: true,
|
|
39
|
-
convertGeom3: true,
|
|
40
|
-
convertGeom2: false
|
|
41
|
-
},
|
|
42
34
|
dxf: {
|
|
43
35
|
displayName: 'DXF (ASCII)',
|
|
44
36
|
description: 'AutoCAD Drawing Exchange Format',
|
|
45
37
|
extension: 'dxf',
|
|
46
|
-
mimetype: '
|
|
38
|
+
mimetype: 'image/vnd.dxf',
|
|
47
39
|
deserializable: true,
|
|
48
40
|
convertGeom3: true,
|
|
49
41
|
convertGeom2: true
|
|
@@ -79,7 +71,7 @@ const formats = {
|
|
|
79
71
|
displayName: 'OBJ',
|
|
80
72
|
description: 'Wavefront OBJ File',
|
|
81
73
|
extension: 'obj',
|
|
82
|
-
mimetype: '
|
|
74
|
+
mimetype: 'model/obj',
|
|
83
75
|
deserializable: true,
|
|
84
76
|
convertGeom3: true,
|
|
85
77
|
convertGeom2: false
|
|
@@ -107,42 +99,26 @@ const formats = {
|
|
|
107
99
|
description: '3D Manufacturing Format',
|
|
108
100
|
extension: '3mf',
|
|
109
101
|
mimetype: 'model/3mf',
|
|
110
|
-
deserializable:
|
|
102
|
+
deserializable: true,
|
|
111
103
|
convertGeom3: true,
|
|
112
104
|
convertGeom2: false
|
|
113
105
|
}
|
|
114
106
|
}
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
const conversionFormats = [
|
|
118
|
-
// 3D file formats
|
|
119
|
-
'amf',
|
|
120
|
-
'js',
|
|
121
|
-
'jscad',
|
|
122
|
-
'obj',
|
|
123
|
-
'scad',
|
|
124
|
-
'stl',
|
|
125
|
-
'dxf',
|
|
126
|
-
// 2D file formats
|
|
127
|
-
'svg',
|
|
128
|
-
'ttf',
|
|
129
|
-
'woff'
|
|
130
|
-
]
|
|
131
|
-
|
|
132
|
-
const supportedFormatsForObjects = (objects) => {
|
|
108
|
+
export const supportedFormatsForObjects = (objects) => {
|
|
133
109
|
const objectFormats = []
|
|
134
110
|
let found3Dsolid = false
|
|
135
111
|
let found2Dsolid = false
|
|
136
112
|
for (let i = 0; i < objects.length; i++) {
|
|
137
|
-
if (
|
|
138
|
-
if (
|
|
113
|
+
if (geom3.isA(objects[i])) { found3Dsolid = true }
|
|
114
|
+
if (geom2.isA(objects[i]) || path2.isA(objects[i])) { found2Dsolid = true }
|
|
139
115
|
}
|
|
140
|
-
for (const format in
|
|
141
|
-
if (found3Dsolid &&
|
|
116
|
+
for (const format in supportedFormats) {
|
|
117
|
+
if (found3Dsolid && supportedFormats[format].convertGeom3 === true) {
|
|
142
118
|
objectFormats[objectFormats.length] = format
|
|
143
119
|
continue // only add once
|
|
144
120
|
}
|
|
145
|
-
if (found2Dsolid &&
|
|
121
|
+
if (found2Dsolid && supportedFormats[format].convertGeom2 === true) {
|
|
146
122
|
objectFormats[objectFormats.length] = format
|
|
147
123
|
}
|
|
148
124
|
}
|
|
@@ -150,12 +126,12 @@ const supportedFormatsForObjects = (objects) => {
|
|
|
150
126
|
}
|
|
151
127
|
|
|
152
128
|
// Return a list of extensions as used by the serializers
|
|
153
|
-
const supportedOutputExtensions = () => {
|
|
129
|
+
export const supportedOutputExtensions = () => {
|
|
154
130
|
const supported = []
|
|
155
|
-
for (const format in
|
|
156
|
-
if (
|
|
157
|
-
if (supported.indexOf(
|
|
158
|
-
supported.push(
|
|
131
|
+
for (const format in supportedFormats) {
|
|
132
|
+
if (supportedFormats[format].convertGeom3 === true || supportedFormats[format].convertGeom2 === true) {
|
|
133
|
+
if (supported.indexOf(supportedFormats[format].extension) < 0) {
|
|
134
|
+
supported.push(supportedFormats[format].extension)
|
|
159
135
|
}
|
|
160
136
|
}
|
|
161
137
|
}
|
|
@@ -163,10 +139,10 @@ const supportedOutputExtensions = () => {
|
|
|
163
139
|
}
|
|
164
140
|
|
|
165
141
|
// Return a list of formats as used by the serializers
|
|
166
|
-
const supportedOutputFormats = () => {
|
|
142
|
+
export const supportedOutputFormats = () => {
|
|
167
143
|
const supported = []
|
|
168
|
-
for (const format in
|
|
169
|
-
if (
|
|
144
|
+
for (const format in supportedFormats) {
|
|
145
|
+
if (supportedFormats[format].convertGeom3 === true || supportedFormats[format].convertGeom2 === true) {
|
|
170
146
|
supported.push(format)
|
|
171
147
|
}
|
|
172
148
|
}
|
|
@@ -175,21 +151,29 @@ const supportedOutputFormats = () => {
|
|
|
175
151
|
|
|
176
152
|
// Return a list of file extensions as used by the deserializers
|
|
177
153
|
// See also code-loading/transfromSources.js
|
|
178
|
-
const supportedInputExtensions = () => {
|
|
154
|
+
export const supportedInputExtensions = () => {
|
|
179
155
|
const supported = []
|
|
180
|
-
for (const format in
|
|
181
|
-
if (
|
|
182
|
-
supported.push(
|
|
156
|
+
for (const format in supportedFormats) {
|
|
157
|
+
if (supportedFormats[format].deserializable === true) {
|
|
158
|
+
supported.push(supportedFormats[format].extension)
|
|
183
159
|
}
|
|
184
160
|
}
|
|
185
161
|
return supported
|
|
186
162
|
}
|
|
187
163
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
164
|
+
export const getMimeType = (extension) => {
|
|
165
|
+
for (const format in supportedFormats) {
|
|
166
|
+
const meta = supportedFormats[format]
|
|
167
|
+
if (meta.extension === extension) return meta.mimetype
|
|
168
|
+
if (format === extension) return meta.mimetype
|
|
169
|
+
}
|
|
170
|
+
return null
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export const getExtension = (mimeType) => {
|
|
174
|
+
for (const format in supportedFormats) {
|
|
175
|
+
const meta = supportedFormats[format]
|
|
176
|
+
if (meta.mimetype === mimeType) return meta.extension
|
|
177
|
+
}
|
|
178
|
+
return null
|
|
195
179
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { deserialize } from './deserialize.js'
|
|
2
|
+
export { deserializers } from './deserializers.js'
|
|
3
|
+
|
|
4
|
+
export { serialize } from './serialize.js'
|
|
5
|
+
export { serializers } from './serializers.js'
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
supportedFormats,
|
|
9
|
+
getMimeType,
|
|
10
|
+
supportedInputExtensions,
|
|
11
|
+
supportedOutputExtensions,
|
|
12
|
+
supportedOutputFormats,
|
|
13
|
+
supportedFormatsForObjects
|
|
14
|
+
} from './formats.js'
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { toArray } from '@jscad/array-utils'
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const x3dSerializer = require('@jscad/x3d-serializer')
|
|
11
|
-
const m3fSerializer = require('@jscad/3mf-serializer') // UG javascript doesn't allow names with leading #
|
|
3
|
+
import * as amfSerializer from '@jscad/amf-serializer'
|
|
4
|
+
import * as dxfSerializer from '@jscad/dxf-serializer'
|
|
5
|
+
import * as jsonSerializer from '@jscad/json-serializer'
|
|
6
|
+
import * as objSerializer from '@jscad/obj-serializer'
|
|
7
|
+
import * as stlSerializer from '@jscad/stl-serializer'
|
|
8
|
+
import * as svgSerializer from '@jscad/svg-serializer'
|
|
9
|
+
import * as x3dSerializer from '@jscad/x3d-serializer'
|
|
10
|
+
import * as m3fSerializer from '@jscad/3mf-serializer' // UG javascript doesn't allow names with leading #
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
import { supportedFormats } from './formats.js'
|
|
13
|
+
|
|
14
|
+
export const prepareOutput = (objects, params) => {
|
|
14
15
|
const defaults = {
|
|
15
16
|
format: undefined,
|
|
16
17
|
version: '0.0.0'
|
|
@@ -38,11 +39,11 @@ const prepareOutput = (objects, params) => {
|
|
|
38
39
|
'3mf': m3fSerializer, // Geom3 to 3MF
|
|
39
40
|
json: jsonSerializer, // Geom3 or Geom2 to JSON
|
|
40
41
|
js: {
|
|
41
|
-
mimeType:
|
|
42
|
+
mimeType: supportedFormats.js.mimetype,
|
|
42
43
|
serialize: (options, objects) => toArray(objects) // js , pass through
|
|
43
44
|
},
|
|
44
45
|
jscad: {
|
|
45
|
-
mimeType:
|
|
46
|
+
mimeType: supportedFormats.jscad.mimetype,
|
|
46
47
|
serialize: (options, objects) => toArray(objects) // jscad , pass through
|
|
47
48
|
},
|
|
48
49
|
undefined: () => {
|
|
@@ -54,5 +55,3 @@ const prepareOutput = (objects, params) => {
|
|
|
54
55
|
const mimeType = outputFormatHandlers[format].mimeType
|
|
55
56
|
return { data, mimeType }
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
module.exports = prepareOutput
|
package/src/serialize.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { flatten } from '@jscad/array-utils'
|
|
2
|
+
|
|
3
|
+
import { serializers } from './serializers.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serialize the given objects as per the given mimeType into the external format.
|
|
7
|
+
* Options can be provided to over-ride or suppliment the defaults used during serialization.
|
|
8
|
+
* See each serializer package for available options.
|
|
9
|
+
* @param {Object} options - options used during deserializing
|
|
10
|
+
* @param {String} mimeType - MIME type of the file
|
|
11
|
+
* @param {Object} objects - one or more objects of which to serialize
|
|
12
|
+
* @return {Object} an object containing the serialize data as well as mime type
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const mimetype = getMimeType('svg')
|
|
16
|
+
* const shapes = [primitives.cirlce(), primitives.star()]
|
|
17
|
+
* const output = serialize({units: 'inches'}, mimetype, shapes)
|
|
18
|
+
*/
|
|
19
|
+
export const serialize = (options, mimeType, ...objects) => {
|
|
20
|
+
const defaults = {
|
|
21
|
+
unit: 'mm',
|
|
22
|
+
statusCallback: null
|
|
23
|
+
}
|
|
24
|
+
options = Object.assign({}, defaults, options)
|
|
25
|
+
|
|
26
|
+
objects = flatten(objects)
|
|
27
|
+
|
|
28
|
+
if (mimeType in serializers) {
|
|
29
|
+
const serializer = serializers[mimeType]
|
|
30
|
+
const data = serializer(options, ...objects)
|
|
31
|
+
return { data, mimeType }
|
|
32
|
+
} else {
|
|
33
|
+
throw new Error(`Unknown mime type (${mimeType})`)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as mf3Serializer from '@jscad/3mf-serializer'
|
|
2
|
+
import * as dxfSerializer from '@jscad/dxf-serializer'
|
|
3
|
+
import * as jsonSerializer from '@jscad/json-serializer'
|
|
4
|
+
import * as objSerializer from '@jscad/obj-serializer'
|
|
5
|
+
import * as stlSerializer from '@jscad/stl-serializer'
|
|
6
|
+
import * as svgSerializer from '@jscad/svg-serializer'
|
|
7
|
+
import * as x3dSerializer from '@jscad/x3d-serializer'
|
|
8
|
+
|
|
9
|
+
// default serializer
|
|
10
|
+
const defaultSerialize = (options, ...objects) => objects
|
|
11
|
+
|
|
12
|
+
export const serializers = {}
|
|
13
|
+
serializers[mf3Serializer.mimeType] = mf3Serializer.serialize
|
|
14
|
+
serializers[dxfSerializer.mimeType] = dxfSerializer.serialize
|
|
15
|
+
serializers[jsonSerializer.mimeType] = jsonSerializer.serialize
|
|
16
|
+
serializers[objSerializer.mimeType] = objSerializer.serialize
|
|
17
|
+
serializers[stlSerializer.mimeType] = stlSerializer.serialize
|
|
18
|
+
serializers[svgSerializer.mimeType] = svgSerializer.serialize
|
|
19
|
+
serializers[x3dSerializer.mimeType] = x3dSerializer.serialize
|
|
20
|
+
|
|
21
|
+
serializers['application/javascript'] = defaultSerialize
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
|
|
3
|
+
import { countOf } from '../../test/helpers/countOf.js'
|
|
4
|
+
|
|
5
|
+
import { deserialize, getMimeType } from '../src/index.js'
|
|
6
|
+
|
|
7
|
+
test('deserialize svg (simple) to objects', (t) => {
|
|
8
|
+
const mimeType = 'image/svg+xml'
|
|
9
|
+
const objects = deserialize({ output: 'geometry' }, mimeType, source1)
|
|
10
|
+
const expected1 = [{
|
|
11
|
+
isClosed: false,
|
|
12
|
+
points: [[3, -3], [4, -2], [0, 0]],
|
|
13
|
+
transforms: [
|
|
14
|
+
1, 0, 0, 0,
|
|
15
|
+
0, 1, 0, 0,
|
|
16
|
+
0, 0, 1, 0,
|
|
17
|
+
0, 0, 0, 1
|
|
18
|
+
]
|
|
19
|
+
}]
|
|
20
|
+
t.deepEqual(expected1, objects)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('deserialize svg (simple) to script', (t) => {
|
|
24
|
+
const mimeType = getMimeType('svg')
|
|
25
|
+
const script = deserialize({ output: 'script', addMetaData: false }, mimeType, source1)
|
|
26
|
+
t.is(countOf('main(params)', script), 1)
|
|
27
|
+
t.is(countOf('path2', script), 3)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const source1 = `<?xml version="1.0" encoding="UTF-8"?>
|
|
31
|
+
<!-- Created by JSCAD SVG Serializer -->
|
|
32
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">
|
|
33
|
+
<svg width="4mm" height="3mm" viewBox="0 0 4 3" fill="none" fill-rule="evenodd" stroke-width="0.1px" version="1.1" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
34
|
+
<g>
|
|
35
|
+
<path d="M3 3L4 2L0 0"/>
|
|
36
|
+
</g>
|
|
37
|
+
</svg>
|
|
38
|
+
`
|
|
39
|
+
|
|
40
|
+
test('deserialize JS code to JS code', (t) => {
|
|
41
|
+
const mimeType = 'application/javascript'
|
|
42
|
+
const code = 'const a - 1;'
|
|
43
|
+
const script = deserialize({ output: 'script', addMetaData: false }, mimeType, code)
|
|
44
|
+
t.deepEqual(script, code)
|
|
45
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
|
|
3
|
+
import { line } from '@jscad/modeling'
|
|
4
|
+
|
|
5
|
+
import { serialize } from '../src/index.js'
|
|
6
|
+
|
|
7
|
+
test('serialize 2D path (simple) objects to svg', (t) => {
|
|
8
|
+
const mimeType = 'image/svg+xml'
|
|
9
|
+
// simple open path
|
|
10
|
+
const object1 = line([[0, 0], [1, 1], [-3, 3]])
|
|
11
|
+
const observed = serialize({}, mimeType, object1)
|
|
12
|
+
t.deepEqual(observed, expected1)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const expected1 = {
|
|
16
|
+
data: [`<?xml version="1.0" encoding="UTF-8"?>
|
|
17
|
+
<!-- Created by JSCAD SVG Serializer -->
|
|
18
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">
|
|
19
|
+
<svg width="4mm" height="3mm" viewBox="0 0 4 3" fill="none" fill-rule="evenodd" stroke-width="0.1px" version="1.1" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
20
|
+
<g>
|
|
21
|
+
<path d="M3 3L4 2L0 0"/>
|
|
22
|
+
</g>
|
|
23
|
+
</svg>
|
|
24
|
+
`],
|
|
25
|
+
mimeType: 'image/svg+xml'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
test('serialize JS code to JS code', (t) => {
|
|
29
|
+
const mimeType = 'application/javascript'
|
|
30
|
+
const code = 'const a - 1;'
|
|
31
|
+
const observed = serialize({}, mimeType, code)
|
|
32
|
+
const expected = {
|
|
33
|
+
data: [code],
|
|
34
|
+
mimeType: 'application/javascript'
|
|
35
|
+
}
|
|
36
|
+
t.deepEqual(observed, expected)
|
|
37
|
+
})
|
package/deserializers.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const amfDeSerializer = require('@jscad/amf-deserializer')
|
|
2
|
-
const dxfDeSerializer = require('@jscad/dxf-deserializer')
|
|
3
|
-
const jsonDeSerializer = require('@jscad/json-deserializer')
|
|
4
|
-
const objDeSerializer = require('@jscad/obj-deserializer')
|
|
5
|
-
// const scadDeSerializer = require('@jscad/scad-deserializer') //FIXME: upgrade, fix before re-enabling
|
|
6
|
-
const stlDeSerializer = require('@jscad/stl-deserializer')
|
|
7
|
-
const svgDeSerializer = require('@jscad/svg-deserializer')
|
|
8
|
-
const x3dDeSerializer = require('@jscad/x3d-deserializer')
|
|
9
|
-
|
|
10
|
-
const deserializers = {}
|
|
11
|
-
deserializers[amfDeSerializer.extension] = amfDeSerializer.deserialize
|
|
12
|
-
deserializers[dxfDeSerializer.extension] = dxfDeSerializer.deserialize
|
|
13
|
-
deserializers[jsonDeSerializer.extension] = jsonDeSerializer.deserialize
|
|
14
|
-
deserializers[objDeSerializer.extension] = objDeSerializer.deserialize
|
|
15
|
-
deserializers[stlDeSerializer.extension] = stlDeSerializer.deserialize
|
|
16
|
-
deserializers[svgDeSerializer.extension] = svgDeSerializer.deserialize
|
|
17
|
-
deserializers[x3dDeSerializer.extension] = x3dDeSerializer.deserialize
|
|
18
|
-
|
|
19
|
-
module.exports = deserializers
|
package/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const { makeBlob, convertToBlob } = require('@jscad/io-utils')
|
|
2
|
-
|
|
3
|
-
const amfSerializer = require('@jscad/amf-serializer')
|
|
4
|
-
const dxfSerializer = require('@jscad/dxf-serializer')
|
|
5
|
-
const jsonSerializer = require('@jscad/json-serializer')
|
|
6
|
-
const objSerializer = require('@jscad/obj-serializer')
|
|
7
|
-
const stlSerializer = require('@jscad/stl-serializer')
|
|
8
|
-
const svgSerializer = require('@jscad/svg-serializer')
|
|
9
|
-
const x3dSerializer = require('@jscad/x3d-serializer')
|
|
10
|
-
const m3fSerializer = require('@jscad/3mf-serializer')
|
|
11
|
-
|
|
12
|
-
const prepareOutput = require('./prepareOutput')
|
|
13
|
-
const deserializers = require('./deserializers')
|
|
14
|
-
|
|
15
|
-
const solidsAsBlob = (solids, params) => convertToBlob(prepareOutput(solids, params))
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
makeBlob,
|
|
19
|
-
solidsAsBlob,
|
|
20
|
-
|
|
21
|
-
amfSerializer,
|
|
22
|
-
dxfSerializer,
|
|
23
|
-
jsonSerializer,
|
|
24
|
-
objSerializer,
|
|
25
|
-
stlSerializer,
|
|
26
|
-
svgSerializer,
|
|
27
|
-
x3dSerializer,
|
|
28
|
-
m3fSerializer, // UG javascript doesn't allow names with leading digit
|
|
29
|
-
|
|
30
|
-
deserializers
|
|
31
|
-
}
|