@openbim/ifcx 0.1.0 → 0.2.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/README.md +92 -10
- package/bundler/fetch-imports.d.ts +53 -0
- package/bundler/fetch-imports.js +137 -0
- package/bundler/openbim_ifcx_wasm.d.ts +139 -0
- package/bundler/openbim_ifcx_wasm.js +10 -0
- package/bundler/openbim_ifcx_wasm_bg.js +481 -0
- package/bundler/openbim_ifcx_wasm_bg.wasm +0 -0
- package/bundler/openbim_ifcx_wasm_bg.wasm.d.ts +18 -0
- package/bundler/package.json +3 -0
- package/fetch-imports.d.ts +53 -0
- package/fetch-imports.js +139 -0
- package/openbim_ifcx_wasm.d.ts +3 -1
- package/openbim_ifcx_wasm.js +1 -0
- package/openbim_ifcx_wasm_bg.wasm +0 -0
- package/package.json +29 -3
- package/web/fetch-imports.d.ts +53 -0
- package/web/fetch-imports.js +137 -0
- package/web/openbim_ifcx_wasm.d.ts +182 -0
- package/web/openbim_ifcx_wasm.js +585 -0
- package/web/openbim_ifcx_wasm_bg.wasm +0 -0
- package/web/openbim_ifcx_wasm_bg.wasm.d.ts +18 -0
- package/web/package.json +3 -0
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One IFCX file. Writing it back is lossless: key order, unknown fields,
|
|
3
|
+
* `null` deletions and every number stay as read.
|
|
4
|
+
*
|
|
5
|
+
* A newtype because `wasm_bindgen` can only export a type defined in this
|
|
6
|
+
* crate; all state and behaviour are the core's.
|
|
7
|
+
*/
|
|
8
|
+
export class IfcxFile {
|
|
9
|
+
static __wrap(ptr) {
|
|
10
|
+
const obj = Object.create(IfcxFile.prototype);
|
|
11
|
+
obj.__wbg_ptr = ptr;
|
|
12
|
+
IfcxFileFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
__destroy_into_raw() {
|
|
16
|
+
const ptr = this.__wbg_ptr;
|
|
17
|
+
this.__wbg_ptr = 0;
|
|
18
|
+
IfcxFileFinalization.unregister(this);
|
|
19
|
+
return ptr;
|
|
20
|
+
}
|
|
21
|
+
free() {
|
|
22
|
+
const ptr = this.__destroy_into_raw();
|
|
23
|
+
wasm.__wbg_ifcxfile_free(ptr, 0);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The `header` object.
|
|
27
|
+
* @returns {Record<string, unknown>}
|
|
28
|
+
*/
|
|
29
|
+
get header() {
|
|
30
|
+
try {
|
|
31
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
32
|
+
wasm.ifcxfile_header(retptr, this.__wbg_ptr);
|
|
33
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
34
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
35
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
36
|
+
if (r2) {
|
|
37
|
+
throw takeObject(r1);
|
|
38
|
+
}
|
|
39
|
+
return takeObject(r0);
|
|
40
|
+
} finally {
|
|
41
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Number of entries in `data`; several may share a path.
|
|
46
|
+
* @returns {number}
|
|
47
|
+
*/
|
|
48
|
+
get nodeCount() {
|
|
49
|
+
const ret = wasm.ifcxfile_nodeCount(this.__wbg_ptr);
|
|
50
|
+
return ret >>> 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Read an IFCX file from its JSON text or UTF-8 bytes.
|
|
54
|
+
* @param {IfcxInput} input
|
|
55
|
+
* @returns {IfcxFile}
|
|
56
|
+
*/
|
|
57
|
+
static parse(input) {
|
|
58
|
+
try {
|
|
59
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
60
|
+
wasm.ifcxfile_parse(retptr, addBorrowedObject(input));
|
|
61
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
62
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
63
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
64
|
+
if (r2) {
|
|
65
|
+
throw takeObject(r1);
|
|
66
|
+
}
|
|
67
|
+
return IfcxFile.__wrap(r0);
|
|
68
|
+
} finally {
|
|
69
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
70
|
+
heap[stack_pointer++] = undefined;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The file as a plain object, so `JSON.stringify(file)` works. Unlike
|
|
75
|
+
* `write`, a plain object may reorder integer-like keys and round
|
|
76
|
+
* integers beyond 2^53.
|
|
77
|
+
* @returns {Record<string, unknown>}
|
|
78
|
+
*/
|
|
79
|
+
toJSON() {
|
|
80
|
+
try {
|
|
81
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
82
|
+
wasm.ifcxfile_toJSON(retptr, this.__wbg_ptr);
|
|
83
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
84
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
85
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
86
|
+
if (r2) {
|
|
87
|
+
throw takeObject(r1);
|
|
88
|
+
}
|
|
89
|
+
return takeObject(r0);
|
|
90
|
+
} finally {
|
|
91
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check every attribute against this file's own `schemas`. Imports are
|
|
96
|
+
* not resolved; use the `validate` function to include them.
|
|
97
|
+
* @returns {ValidationReport}
|
|
98
|
+
*/
|
|
99
|
+
validate() {
|
|
100
|
+
try {
|
|
101
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
102
|
+
wasm.ifcxfile_validate(retptr, this.__wbg_ptr);
|
|
103
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
104
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
105
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
106
|
+
if (r2) {
|
|
107
|
+
throw takeObject(r1);
|
|
108
|
+
}
|
|
109
|
+
return takeObject(r0);
|
|
110
|
+
} finally {
|
|
111
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The file as JSON text; `pretty` indents it by two spaces.
|
|
116
|
+
* @param {boolean | null} [pretty]
|
|
117
|
+
* @returns {string}
|
|
118
|
+
*/
|
|
119
|
+
write(pretty) {
|
|
120
|
+
let deferred2_0;
|
|
121
|
+
let deferred2_1;
|
|
122
|
+
try {
|
|
123
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
124
|
+
wasm.ifcxfile_write(retptr, this.__wbg_ptr, isLikeNone(pretty) ? 0xFFFFFF : pretty ? 1 : 0);
|
|
125
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
126
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
127
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
128
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
129
|
+
var ptr1 = r0;
|
|
130
|
+
var len1 = r1;
|
|
131
|
+
if (r3) {
|
|
132
|
+
ptr1 = 0; len1 = 0;
|
|
133
|
+
throw takeObject(r2);
|
|
134
|
+
}
|
|
135
|
+
deferred2_0 = ptr1;
|
|
136
|
+
deferred2_1 = len1;
|
|
137
|
+
return getStringFromWasm0(ptr1, len1);
|
|
138
|
+
} finally {
|
|
139
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
140
|
+
wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (Symbol.dispose) IfcxFile.prototype[Symbol.dispose] = IfcxFile.prototype.free;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Compose layers, weakest first, into a tree of plain objects: the
|
|
148
|
+
* artificial root (path `""`) over every root node. Declared for
|
|
149
|
+
* TypeScript in `TYPES`, where `options` can be optional.
|
|
150
|
+
* @param {any} layers
|
|
151
|
+
* @param {any | null} [options]
|
|
152
|
+
* @returns {any}
|
|
153
|
+
*/
|
|
154
|
+
export function compose(layers, options) {
|
|
155
|
+
try {
|
|
156
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
157
|
+
wasm.compose(retptr, addBorrowedObject(layers), isLikeNone(options) ? 0 : addHeapObject(options));
|
|
158
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
159
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
160
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
161
|
+
if (r2) {
|
|
162
|
+
throw takeObject(r1);
|
|
163
|
+
}
|
|
164
|
+
return takeObject(r0);
|
|
165
|
+
} finally {
|
|
166
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
167
|
+
heap[stack_pointer++] = undefined;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Compose layers, weakest first, and write their render scene as GLB
|
|
173
|
+
* bytes. Declared for TypeScript in `TYPES`.
|
|
174
|
+
* @param {any} layers
|
|
175
|
+
* @param {any | null} [options]
|
|
176
|
+
* @returns {Uint8Array}
|
|
177
|
+
*/
|
|
178
|
+
export function exportGlb(layers, options) {
|
|
179
|
+
try {
|
|
180
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
181
|
+
wasm.exportGlb(retptr, addBorrowedObject(layers), isLikeNone(options) ? 0 : addHeapObject(options));
|
|
182
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
183
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
184
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
185
|
+
if (r2) {
|
|
186
|
+
throw takeObject(r1);
|
|
187
|
+
}
|
|
188
|
+
return takeObject(r0);
|
|
189
|
+
} finally {
|
|
190
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
191
|
+
heap[stack_pointer++] = undefined;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Check the attributes of the layers, weakest first, against the schemas
|
|
197
|
+
* of every layer (and of resolved imports), after merging nodes that share
|
|
198
|
+
* a path. Declared for TypeScript in `TYPES`.
|
|
199
|
+
* @param {any} layers
|
|
200
|
+
* @param {any | null} [options]
|
|
201
|
+
* @returns {any}
|
|
202
|
+
*/
|
|
203
|
+
export function validate(layers, options) {
|
|
204
|
+
try {
|
|
205
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
206
|
+
wasm.validate(retptr, addBorrowedObject(layers), isLikeNone(options) ? 0 : addHeapObject(options));
|
|
207
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
208
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
209
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
210
|
+
if (r2) {
|
|
211
|
+
throw takeObject(r1);
|
|
212
|
+
}
|
|
213
|
+
return takeObject(r0);
|
|
214
|
+
} finally {
|
|
215
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
216
|
+
heap[stack_pointer++] = undefined;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export function __wbg___wbindgen_boolean_get_7a12af2b3f899c5a(arg0) {
|
|
220
|
+
const v = getObject(arg0);
|
|
221
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
222
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
223
|
+
}
|
|
224
|
+
export function __wbg___wbindgen_is_null_5160b3e381865372(arg0) {
|
|
225
|
+
const ret = getObject(arg0) === null;
|
|
226
|
+
return ret;
|
|
227
|
+
}
|
|
228
|
+
export function __wbg___wbindgen_is_object_edb6b15aa3afe12e(arg0) {
|
|
229
|
+
const val = getObject(arg0);
|
|
230
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
231
|
+
return ret;
|
|
232
|
+
}
|
|
233
|
+
export function __wbg___wbindgen_is_undefined_8c687d0b90d5b524(arg0) {
|
|
234
|
+
const ret = getObject(arg0) === undefined;
|
|
235
|
+
return ret;
|
|
236
|
+
}
|
|
237
|
+
export function __wbg___wbindgen_string_get_92ab86bb19cbc12f(arg0, arg1) {
|
|
238
|
+
const obj = getObject(arg1);
|
|
239
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
240
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
241
|
+
var len1 = WASM_VECTOR_LEN;
|
|
242
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
243
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
244
|
+
}
|
|
245
|
+
export function __wbg___wbindgen_throw_5d9e815e6fdf150f(arg0, arg1) {
|
|
246
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
247
|
+
}
|
|
248
|
+
export function __wbg_entries_20b9608d57d8ddd6(arg0) {
|
|
249
|
+
const ret = getObject(arg0).entries();
|
|
250
|
+
return addHeapObject(ret);
|
|
251
|
+
}
|
|
252
|
+
export function __wbg_entries_972a87586902cf87(arg0) {
|
|
253
|
+
const ret = Object.entries(getObject(arg0));
|
|
254
|
+
return addHeapObject(ret);
|
|
255
|
+
}
|
|
256
|
+
export function __wbg_from_a39669ce566077da(arg0) {
|
|
257
|
+
const ret = Array.from(getObject(arg0));
|
|
258
|
+
return addHeapObject(ret);
|
|
259
|
+
}
|
|
260
|
+
export function __wbg_get_989d0a1309644f2b() { return handleError(function (arg0, arg1) {
|
|
261
|
+
const ret = Reflect.get(getObject(arg0), getObject(arg1));
|
|
262
|
+
return addHeapObject(ret);
|
|
263
|
+
}, arguments); }
|
|
264
|
+
export function __wbg_get_b1f0ab13c737f856(arg0, arg1) {
|
|
265
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
|
266
|
+
return addHeapObject(ret);
|
|
267
|
+
}
|
|
268
|
+
export function __wbg_get_unchecked_363572bdd397d473(arg0, arg1) {
|
|
269
|
+
const ret = getObject(arg0)[arg1 >>> 0];
|
|
270
|
+
return addHeapObject(ret);
|
|
271
|
+
}
|
|
272
|
+
export function __wbg_instanceof_Map_1ff6a2b54c899f0d(arg0) {
|
|
273
|
+
let result;
|
|
274
|
+
try {
|
|
275
|
+
result = getObject(arg0) instanceof Map;
|
|
276
|
+
} catch (_) {
|
|
277
|
+
result = false;
|
|
278
|
+
}
|
|
279
|
+
const ret = result;
|
|
280
|
+
return ret;
|
|
281
|
+
}
|
|
282
|
+
export function __wbg_instanceof_Uint8Array_598adc0fef426aa8(arg0) {
|
|
283
|
+
let result;
|
|
284
|
+
try {
|
|
285
|
+
result = getObject(arg0) instanceof Uint8Array;
|
|
286
|
+
} catch (_) {
|
|
287
|
+
result = false;
|
|
288
|
+
}
|
|
289
|
+
const ret = result;
|
|
290
|
+
return ret;
|
|
291
|
+
}
|
|
292
|
+
export function __wbg_isArray_5674713bb7b79043(arg0) {
|
|
293
|
+
const ret = Array.isArray(getObject(arg0));
|
|
294
|
+
return ret;
|
|
295
|
+
}
|
|
296
|
+
export function __wbg_length_31bdaf014f5fbde2(arg0) {
|
|
297
|
+
const ret = getObject(arg0).length;
|
|
298
|
+
return ret;
|
|
299
|
+
}
|
|
300
|
+
export function __wbg_length_4e1adc0d42e23620(arg0) {
|
|
301
|
+
const ret = getObject(arg0).length;
|
|
302
|
+
return ret;
|
|
303
|
+
}
|
|
304
|
+
export function __wbg_new_a32a1ab6c6655abe(arg0, arg1) {
|
|
305
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
306
|
+
return addHeapObject(ret);
|
|
307
|
+
}
|
|
308
|
+
export function __wbg_new_from_slice_4ee02165f9de919e(arg0, arg1) {
|
|
309
|
+
const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
|
|
310
|
+
return addHeapObject(ret);
|
|
311
|
+
}
|
|
312
|
+
export function __wbg_parse_6937a9050adfb0e1() { return handleError(function (arg0, arg1) {
|
|
313
|
+
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
314
|
+
return addHeapObject(ret);
|
|
315
|
+
}, arguments); }
|
|
316
|
+
export function __wbg_prototypesetcall_ae9f5e7459250748(arg0, arg1, arg2) {
|
|
317
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
318
|
+
}
|
|
319
|
+
export function __wbg_set_a377297433dfea63() { return handleError(function (arg0, arg1, arg2) {
|
|
320
|
+
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
321
|
+
return ret;
|
|
322
|
+
}, arguments); }
|
|
323
|
+
export function __wbg_set_name_6e2a5da46a9ae1e7(arg0, arg1, arg2) {
|
|
324
|
+
getObject(arg0).name = getStringFromWasm0(arg1, arg2);
|
|
325
|
+
}
|
|
326
|
+
export function __wbindgen_generic_0000000000000001(arg0, arg1) {
|
|
327
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
328
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
329
|
+
return addHeapObject(ret);
|
|
330
|
+
}
|
|
331
|
+
export function __wbindgen_object_drop_ref(arg0) {
|
|
332
|
+
takeObject(arg0);
|
|
333
|
+
}
|
|
334
|
+
const IfcxFileFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
335
|
+
? { register: () => {}, unregister: () => {} }
|
|
336
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_ifcxfile_free(ptr, 1));
|
|
337
|
+
|
|
338
|
+
function addHeapObject(obj) {
|
|
339
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
340
|
+
const idx = heap_next;
|
|
341
|
+
heap_next = heap[idx];
|
|
342
|
+
|
|
343
|
+
heap[idx] = obj;
|
|
344
|
+
return idx;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function addBorrowedObject(obj) {
|
|
348
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
349
|
+
heap[--stack_pointer] = obj;
|
|
350
|
+
return stack_pointer;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function dropObject(idx) {
|
|
354
|
+
if (idx < 1028) return;
|
|
355
|
+
heap[idx] = heap_next;
|
|
356
|
+
heap_next = idx;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
360
|
+
ptr = ptr >>> 0;
|
|
361
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
let cachedDataViewMemory0 = null;
|
|
365
|
+
function getDataViewMemory0() {
|
|
366
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
367
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
368
|
+
}
|
|
369
|
+
return cachedDataViewMemory0;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function getStringFromWasm0(ptr, len) {
|
|
373
|
+
return decodeText(ptr >>> 0, len);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let cachedUint8ArrayMemory0 = null;
|
|
377
|
+
function getUint8ArrayMemory0() {
|
|
378
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
379
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
380
|
+
}
|
|
381
|
+
return cachedUint8ArrayMemory0;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function getObject(idx) { return heap[idx]; }
|
|
385
|
+
|
|
386
|
+
function handleError(f, args) {
|
|
387
|
+
try {
|
|
388
|
+
return f.apply(this, args);
|
|
389
|
+
} catch (e) {
|
|
390
|
+
wasm.__wbindgen_export3(addHeapObject(e));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
let heap = new Array(1024).fill(undefined);
|
|
395
|
+
heap.push(undefined, null, true, false);
|
|
396
|
+
|
|
397
|
+
let heap_next = heap.length;
|
|
398
|
+
|
|
399
|
+
function isLikeNone(x) {
|
|
400
|
+
return x === undefined || x === null;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
404
|
+
if (realloc === undefined) {
|
|
405
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
406
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
407
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
408
|
+
WASM_VECTOR_LEN = buf.length;
|
|
409
|
+
return ptr;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
let len = arg.length;
|
|
413
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
414
|
+
|
|
415
|
+
const mem = getUint8ArrayMemory0();
|
|
416
|
+
|
|
417
|
+
let offset = 0;
|
|
418
|
+
|
|
419
|
+
for (; offset < len; offset++) {
|
|
420
|
+
const code = arg.charCodeAt(offset);
|
|
421
|
+
if (code > 0x7F) break;
|
|
422
|
+
mem[ptr + offset] = code;
|
|
423
|
+
}
|
|
424
|
+
if (offset !== len) {
|
|
425
|
+
if (offset !== 0) {
|
|
426
|
+
arg = arg.slice(offset);
|
|
427
|
+
}
|
|
428
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
429
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
430
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
431
|
+
|
|
432
|
+
offset += ret.written;
|
|
433
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
WASM_VECTOR_LEN = offset;
|
|
437
|
+
return ptr;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let stack_pointer = 1024;
|
|
441
|
+
|
|
442
|
+
function takeObject(idx) {
|
|
443
|
+
const ret = getObject(idx);
|
|
444
|
+
dropObject(idx);
|
|
445
|
+
return ret;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
449
|
+
cachedTextDecoder.decode();
|
|
450
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
451
|
+
let numBytesDecoded = 0;
|
|
452
|
+
function decodeText(ptr, len) {
|
|
453
|
+
numBytesDecoded += len;
|
|
454
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
455
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
456
|
+
cachedTextDecoder.decode();
|
|
457
|
+
numBytesDecoded = len;
|
|
458
|
+
}
|
|
459
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const cachedTextEncoder = new TextEncoder();
|
|
463
|
+
|
|
464
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
465
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
466
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
467
|
+
view.set(buf);
|
|
468
|
+
return {
|
|
469
|
+
read: arg.length,
|
|
470
|
+
written: buf.length
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
let WASM_VECTOR_LEN = 0;
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
let wasm;
|
|
479
|
+
export function __wbg_set_wasm(val) {
|
|
480
|
+
wasm = val;
|
|
481
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_ifcxfile_free: (a: number, b: number) => void;
|
|
5
|
+
export const compose: (a: number, b: number, c: number) => void;
|
|
6
|
+
export const exportGlb: (a: number, b: number, c: number) => void;
|
|
7
|
+
export const ifcxfile_header: (a: number, b: number) => void;
|
|
8
|
+
export const ifcxfile_nodeCount: (a: number) => number;
|
|
9
|
+
export const ifcxfile_parse: (a: number, b: number) => void;
|
|
10
|
+
export const ifcxfile_toJSON: (a: number, b: number) => void;
|
|
11
|
+
export const ifcxfile_validate: (a: number, b: number) => void;
|
|
12
|
+
export const ifcxfile_write: (a: number, b: number, c: number) => void;
|
|
13
|
+
export const validate: (a: number, b: number, c: number) => void;
|
|
14
|
+
export const __wbindgen_export: (a: number, b: number) => number;
|
|
15
|
+
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
16
|
+
export const __wbindgen_export3: (a: number) => void;
|
|
17
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
18
|
+
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IfcxInput } from "./openbim_ifcx_wasm.js";
|
|
2
|
+
|
|
3
|
+
/** The part of a `fetch` `Response` that `fetchImports` reads. */
|
|
4
|
+
export interface FetchedResponse {
|
|
5
|
+
ok?: boolean;
|
|
6
|
+
status?: number;
|
|
7
|
+
statusText?: string;
|
|
8
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Loads one imported file. `fetch` itself fits; a custom function may also
|
|
13
|
+
* return the file directly. `url` is the import `uri` resolved against the
|
|
14
|
+
* importing file's URL (or `baseUrl`); when a relative `uri` has no base to
|
|
15
|
+
* resolve against, a custom function receives the `uri` unchanged.
|
|
16
|
+
*/
|
|
17
|
+
export type ImportFetcher = (
|
|
18
|
+
url: string,
|
|
19
|
+
init?: { signal?: AbortSignal },
|
|
20
|
+
) => Promise<FetchedResponse | IfcxInput | ArrayBuffer>;
|
|
21
|
+
|
|
22
|
+
/** Options for `fetchImports`. */
|
|
23
|
+
export interface FetchImportsOptions {
|
|
24
|
+
/**
|
|
25
|
+
* URL that relative import URIs of the given layers resolve against.
|
|
26
|
+
* Defaults to `location.href` in a browser. Imports of a fetched file
|
|
27
|
+
* resolve against that file's URL.
|
|
28
|
+
*/
|
|
29
|
+
baseUrl?: string | URL;
|
|
30
|
+
/** Loads each file. Defaults to the global `fetch`. */
|
|
31
|
+
fetch?: ImportFetcher;
|
|
32
|
+
/** Files already at hand, keyed by import `uri`; never fetched again. */
|
|
33
|
+
imports?: Record<string, IfcxInput> | Map<string, IfcxInput>;
|
|
34
|
+
/** Passed to every fetch call. */
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Fetch every file the layers import, recursively and each `uri` once, and
|
|
40
|
+
* return them keyed by the exact import `uri`: the `imports` option of
|
|
41
|
+
* `compose`, `validate` and `exportGlb`. Network access happens here, in
|
|
42
|
+
* JavaScript; the WebAssembly module never fetches anything. A file that
|
|
43
|
+
* cannot be fetched rejects with an `IfcxError` whose `code` is `"fetch"`.
|
|
44
|
+
*
|
|
45
|
+
* ```js
|
|
46
|
+
* const imports = await fetchImports(layers, { baseUrl: "https://example.org/model/" });
|
|
47
|
+
* const tree = compose(layers, { imports });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function fetchImports(
|
|
51
|
+
layers: IfcxInput | IfcxInput[],
|
|
52
|
+
options?: FetchImportsOptions,
|
|
53
|
+
): Promise<Map<string, IfcxInput>>;
|
package/fetch-imports.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Import resolution over `fetch`, for the `imports` option of `compose`,
|
|
3
|
+
// `validate` and `exportGlb`.
|
|
4
|
+
//
|
|
5
|
+
// Plain JavaScript on purpose: the Rust crates perform no network access
|
|
6
|
+
// (ADR 0002), so the binding resolves imports in memory only and this
|
|
7
|
+
// module does the fetching on the JavaScript side. It reads each layer's
|
|
8
|
+
// `imports` list, fetches every named file (recursively, each URI once) and
|
|
9
|
+
// returns the files keyed by their exact import `uri`, which is what the
|
|
10
|
+
// in-memory `imports` option expects. Integrity values are checked later,
|
|
11
|
+
// by the binding, against the fetched bytes.
|
|
12
|
+
//
|
|
13
|
+
// This file is the ES module source. scripts/build-npm-pkg.sh copies it into
|
|
14
|
+
// the `web` and `bundler` builds and derives the CommonJS copy for the Node
|
|
15
|
+
// build from it, so it must stay self-contained: no imports, and every
|
|
16
|
+
// export a top-level `export async function` or `export function`.
|
|
17
|
+
|
|
18
|
+
/** The imports of an IFCX file, or none when it is not readable JSON. */
|
|
19
|
+
function importUris(input) {
|
|
20
|
+
let text = input;
|
|
21
|
+
if (typeof input !== "string") {
|
|
22
|
+
text = new TextDecoder().decode(input);
|
|
23
|
+
}
|
|
24
|
+
let file;
|
|
25
|
+
try {
|
|
26
|
+
file = JSON.parse(text);
|
|
27
|
+
} catch {
|
|
28
|
+
// Not JSON: the binding call that receives it reports where.
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const imports = file !== null && typeof file === "object" ? file.imports : undefined;
|
|
32
|
+
if (!Array.isArray(imports)) return [];
|
|
33
|
+
return imports
|
|
34
|
+
.map((entry) => (entry !== null && typeof entry === "object" ? entry.uri : undefined))
|
|
35
|
+
.filter((uri) => typeof uri === "string");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function fetchError(message, cause) {
|
|
39
|
+
const error = new Error(message, cause === undefined ? undefined : { cause });
|
|
40
|
+
error.name = "IfcxError";
|
|
41
|
+
error.code = "fetch";
|
|
42
|
+
return error;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isInput(value) {
|
|
46
|
+
return typeof value === "string" || value instanceof Uint8Array;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The URL `uri` names, relative to `base`; `undefined` if it cannot be resolved. */
|
|
50
|
+
function resolveUrl(uri, base) {
|
|
51
|
+
try {
|
|
52
|
+
return base === undefined ? new URL(uri).href : new URL(uri, base).href;
|
|
53
|
+
} catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** What a fetch function returned, as an IFCX input. */
|
|
59
|
+
async function readResponse(response, uri, url) {
|
|
60
|
+
if (isInput(response)) return response;
|
|
61
|
+
if (response instanceof ArrayBuffer) return new Uint8Array(response);
|
|
62
|
+
if (response !== null && typeof response === "object" && typeof response.arrayBuffer === "function") {
|
|
63
|
+
if (response.ok === false) {
|
|
64
|
+
const status = [response.status, response.statusText].filter(Boolean).join(" ");
|
|
65
|
+
throw fetchError(`could not fetch import ${JSON.stringify(uri)} from ${url}: HTTP ${status}`);
|
|
66
|
+
}
|
|
67
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
68
|
+
}
|
|
69
|
+
throw fetchError(
|
|
70
|
+
`the fetch function returned neither a Response, a Uint8Array, an ArrayBuffer nor a string for ${JSON.stringify(uri)}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Fetch every file the layers import, recursively, keyed by the exact
|
|
76
|
+
* import `uri`, for the `imports` option of `compose`, `validate` and
|
|
77
|
+
* `exportGlb`.
|
|
78
|
+
*/
|
|
79
|
+
async function fetchImports(layers, options = {}) {
|
|
80
|
+
const list = Array.isArray(layers) ? layers : [layers];
|
|
81
|
+
for (const layer of list) {
|
|
82
|
+
if (!isInput(layer)) {
|
|
83
|
+
throw fetchError("every layer must be a string or a Uint8Array");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
87
|
+
if (typeof fetcher !== "function") {
|
|
88
|
+
throw fetchError("no fetch function: pass options.fetch");
|
|
89
|
+
}
|
|
90
|
+
const custom = options.fetch !== undefined;
|
|
91
|
+
const base =
|
|
92
|
+
options.baseUrl !== undefined ? String(options.baseUrl) : globalThis.location?.href;
|
|
93
|
+
const init = options.signal === undefined ? undefined : { signal: options.signal };
|
|
94
|
+
|
|
95
|
+
const found = new Map();
|
|
96
|
+
if (options.imports !== undefined) {
|
|
97
|
+
const known = options.imports instanceof Map ? options.imports : Object.entries(options.imports);
|
|
98
|
+
for (const [uri, file] of known) found.set(uri, file);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Breadth first; each level's fetches run concurrently. `url` is where a
|
|
102
|
+
// layer came from, so its relative imports resolve against it.
|
|
103
|
+
let level = list.map((file) => ({ file, url: base }));
|
|
104
|
+
for (const [, file] of found) level.push({ file, url: base });
|
|
105
|
+
while (level.length > 0) {
|
|
106
|
+
const pending = [];
|
|
107
|
+
for (const { file, url: importer } of level) {
|
|
108
|
+
for (const uri of importUris(file)) {
|
|
109
|
+
if (found.has(uri)) continue;
|
|
110
|
+
found.set(uri, undefined); // claimed: fetch each URI once
|
|
111
|
+
const url = resolveUrl(uri, importer);
|
|
112
|
+
if (url === undefined && !custom) {
|
|
113
|
+
throw fetchError(
|
|
114
|
+
`cannot resolve import ${JSON.stringify(uri)} to a URL: pass options.baseUrl`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
pending.push(
|
|
118
|
+
(async () => {
|
|
119
|
+
let response;
|
|
120
|
+
try {
|
|
121
|
+
response = await fetcher(url ?? uri, init);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw fetchError(
|
|
124
|
+
`could not fetch import ${JSON.stringify(uri)} from ${url ?? uri}: ${error?.message ?? error}`,
|
|
125
|
+
error,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const fetched = await readResponse(response, uri, url ?? uri);
|
|
129
|
+
found.set(uri, fetched);
|
|
130
|
+
return { file: fetched, url: url ?? importer };
|
|
131
|
+
})(),
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
level = await Promise.all(pending);
|
|
136
|
+
}
|
|
137
|
+
return found;
|
|
138
|
+
}
|
|
139
|
+
exports.fetchImports = fetchImports;
|