@diodeinc/pcb-zen-wasm 0.3.10

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 ADDED
@@ -0,0 +1,17 @@
1
+ # pcb-zen-wasm
2
+
3
+ WebAssembly bindings for the Zen PCB design language.
4
+
5
+ ## Testing with WASI
6
+
7
+ Build the WASI binary:
8
+
9
+ ```bash
10
+ cargo build -p pcb-zen-wasm --bin pcb-zen-wasi --target wasm32-wasip2 --release
11
+ ```
12
+
13
+ Run with wasmtime:
14
+
15
+ ```bash
16
+ cat src.zip | wasmtime run target/wasm32-wasip2/release/pcb-zen-wasi.wasm
17
+ ```
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@diodeinc/pcb-zen-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Diode Computers, Inc. <founders@diode.computer>"
6
+ ],
7
+ "description": "WebAssembly bindings for Zen PCB design language",
8
+ "version": "0.3.10",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/diodeinc/pcb.git"
12
+ },
13
+ "files": [
14
+ "pcb_zen_wasm_bg.wasm",
15
+ "pcb_zen_wasm.js",
16
+ "pcb_zen_wasm.d.ts"
17
+ ],
18
+ "main": "pcb_zen_wasm.js",
19
+ "homepage": "https://github.com/diodeinc/pcb",
20
+ "types": "pcb_zen_wasm.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ]
24
+ }
@@ -0,0 +1,44 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Evaluate a Zener module from a zip archive (WASM binding).
5
+ *
6
+ * This is a thin wrapper around `evaluate_impl` for wasm-bindgen.
7
+ */
8
+ export function evaluate(zip_bytes: Uint8Array, main_file: string, inputs_json: string): any;
9
+ export function start(): void;
10
+
11
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
12
+
13
+ export interface InitOutput {
14
+ readonly memory: WebAssembly.Memory;
15
+ readonly evaluate: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
16
+ readonly start: () => void;
17
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
18
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
19
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
20
+ readonly __wbindgen_export_3: WebAssembly.Table;
21
+ readonly __externref_table_dealloc: (a: number) => void;
22
+ readonly __wbindgen_start: () => void;
23
+ }
24
+
25
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
26
+ /**
27
+ * Instantiates the given `module`, which can either be bytes or
28
+ * a precompiled `WebAssembly.Module`.
29
+ *
30
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
31
+ *
32
+ * @returns {InitOutput}
33
+ */
34
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
35
+
36
+ /**
37
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
38
+ * for everything else, calls `WebAssembly.instantiate` directly.
39
+ *
40
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
41
+ *
42
+ * @returns {Promise<InitOutput>}
43
+ */
44
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,335 @@
1
+ let wasm;
2
+
3
+ let WASM_VECTOR_LEN = 0;
4
+
5
+ let cachedUint8ArrayMemory0 = null;
6
+
7
+ function getUint8ArrayMemory0() {
8
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
9
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
10
+ }
11
+ return cachedUint8ArrayMemory0;
12
+ }
13
+
14
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
15
+
16
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
17
+ ? function (arg, view) {
18
+ return cachedTextEncoder.encodeInto(arg, view);
19
+ }
20
+ : function (arg, view) {
21
+ const buf = cachedTextEncoder.encode(arg);
22
+ view.set(buf);
23
+ return {
24
+ read: arg.length,
25
+ written: buf.length
26
+ };
27
+ });
28
+
29
+ function passStringToWasm0(arg, malloc, realloc) {
30
+
31
+ if (realloc === undefined) {
32
+ const buf = cachedTextEncoder.encode(arg);
33
+ const ptr = malloc(buf.length, 1) >>> 0;
34
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
35
+ WASM_VECTOR_LEN = buf.length;
36
+ return ptr;
37
+ }
38
+
39
+ let len = arg.length;
40
+ let ptr = malloc(len, 1) >>> 0;
41
+
42
+ const mem = getUint8ArrayMemory0();
43
+
44
+ let offset = 0;
45
+
46
+ for (; offset < len; offset++) {
47
+ const code = arg.charCodeAt(offset);
48
+ if (code > 0x7F) break;
49
+ mem[ptr + offset] = code;
50
+ }
51
+
52
+ if (offset !== len) {
53
+ if (offset !== 0) {
54
+ arg = arg.slice(offset);
55
+ }
56
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
57
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
58
+ const ret = encodeString(arg, view);
59
+
60
+ offset += ret.written;
61
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
62
+ }
63
+
64
+ WASM_VECTOR_LEN = offset;
65
+ return ptr;
66
+ }
67
+
68
+ let cachedDataViewMemory0 = null;
69
+
70
+ function getDataViewMemory0() {
71
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
72
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
73
+ }
74
+ return cachedDataViewMemory0;
75
+ }
76
+
77
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
78
+
79
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
80
+
81
+ function getStringFromWasm0(ptr, len) {
82
+ ptr = ptr >>> 0;
83
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
84
+ }
85
+
86
+ function passArray8ToWasm0(arg, malloc) {
87
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
88
+ getUint8ArrayMemory0().set(arg, ptr / 1);
89
+ WASM_VECTOR_LEN = arg.length;
90
+ return ptr;
91
+ }
92
+
93
+ function takeFromExternrefTable0(idx) {
94
+ const value = wasm.__wbindgen_export_3.get(idx);
95
+ wasm.__externref_table_dealloc(idx);
96
+ return value;
97
+ }
98
+ /**
99
+ * Evaluate a Zener module from a zip archive (WASM binding).
100
+ *
101
+ * This is a thin wrapper around `evaluate_impl` for wasm-bindgen.
102
+ * @param {Uint8Array} zip_bytes
103
+ * @param {string} main_file
104
+ * @param {string} inputs_json
105
+ * @returns {any}
106
+ */
107
+ export function evaluate(zip_bytes, main_file, inputs_json) {
108
+ const ptr0 = passArray8ToWasm0(zip_bytes, wasm.__wbindgen_malloc);
109
+ const len0 = WASM_VECTOR_LEN;
110
+ const ptr1 = passStringToWasm0(main_file, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
111
+ const len1 = WASM_VECTOR_LEN;
112
+ const ptr2 = passStringToWasm0(inputs_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
113
+ const len2 = WASM_VECTOR_LEN;
114
+ const ret = wasm.evaluate(ptr0, len0, ptr1, len1, ptr2, len2);
115
+ if (ret[2]) {
116
+ throw takeFromExternrefTable0(ret[1]);
117
+ }
118
+ return takeFromExternrefTable0(ret[0]);
119
+ }
120
+
121
+ export function start() {
122
+ wasm.start();
123
+ }
124
+
125
+ async function __wbg_load(module, imports) {
126
+ if (typeof Response === 'function' && module instanceof Response) {
127
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
128
+ try {
129
+ return await WebAssembly.instantiateStreaming(module, imports);
130
+
131
+ } catch (e) {
132
+ if (module.headers.get('Content-Type') != 'application/wasm') {
133
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
134
+
135
+ } else {
136
+ throw e;
137
+ }
138
+ }
139
+ }
140
+
141
+ const bytes = await module.arrayBuffer();
142
+ return await WebAssembly.instantiate(bytes, imports);
143
+
144
+ } else {
145
+ const instance = await WebAssembly.instantiate(module, imports);
146
+
147
+ if (instance instanceof WebAssembly.Instance) {
148
+ return { instance, module };
149
+
150
+ } else {
151
+ return instance;
152
+ }
153
+ }
154
+ }
155
+
156
+ function __wbg_get_imports() {
157
+ const imports = {};
158
+ imports.wbg = {};
159
+ imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
160
+ const ret = String(arg1);
161
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
162
+ const len1 = WASM_VECTOR_LEN;
163
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
164
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
165
+ };
166
+ imports.wbg.__wbg_debug_3cb59063b29f58c1 = function(arg0) {
167
+ console.debug(arg0);
168
+ };
169
+ imports.wbg.__wbg_error_524f506f44df1645 = function(arg0) {
170
+ console.error(arg0);
171
+ };
172
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
173
+ let deferred0_0;
174
+ let deferred0_1;
175
+ try {
176
+ deferred0_0 = arg0;
177
+ deferred0_1 = arg1;
178
+ console.error(getStringFromWasm0(arg0, arg1));
179
+ } finally {
180
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
181
+ }
182
+ };
183
+ imports.wbg.__wbg_info_3daf2e093e091b66 = function(arg0) {
184
+ console.info(arg0);
185
+ };
186
+ imports.wbg.__wbg_log_c222819a41e063d3 = function(arg0) {
187
+ console.log(arg0);
188
+ };
189
+ imports.wbg.__wbg_new_405e22f390576ce2 = function() {
190
+ const ret = new Object();
191
+ return ret;
192
+ };
193
+ imports.wbg.__wbg_new_5e0be73521bc8c17 = function() {
194
+ const ret = new Map();
195
+ return ret;
196
+ };
197
+ imports.wbg.__wbg_new_78feb108b6472713 = function() {
198
+ const ret = new Array();
199
+ return ret;
200
+ };
201
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
202
+ const ret = new Error();
203
+ return ret;
204
+ };
205
+ imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
206
+ arg0[arg1 >>> 0] = arg2;
207
+ };
208
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
209
+ arg0[arg1] = arg2;
210
+ };
211
+ imports.wbg.__wbg_set_8fc6bf8a5b1071d1 = function(arg0, arg1, arg2) {
212
+ const ret = arg0.set(arg1, arg2);
213
+ return ret;
214
+ };
215
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
216
+ const ret = arg1.stack;
217
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
218
+ const len1 = WASM_VECTOR_LEN;
219
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
220
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
221
+ };
222
+ imports.wbg.__wbg_warn_4ca3906c248c47c4 = function(arg0) {
223
+ console.warn(arg0);
224
+ };
225
+ imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
226
+ const ret = arg0;
227
+ return ret;
228
+ };
229
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
230
+ const ret = BigInt.asUintN(64, arg0);
231
+ return ret;
232
+ };
233
+ imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
234
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
235
+ return ret;
236
+ };
237
+ imports.wbg.__wbindgen_init_externref_table = function() {
238
+ const table = wasm.__wbindgen_export_3;
239
+ const offset = table.grow(4);
240
+ table.set(0, undefined);
241
+ table.set(offset + 0, undefined);
242
+ table.set(offset + 1, null);
243
+ table.set(offset + 2, true);
244
+ table.set(offset + 3, false);
245
+ ;
246
+ };
247
+ imports.wbg.__wbindgen_is_string = function(arg0) {
248
+ const ret = typeof(arg0) === 'string';
249
+ return ret;
250
+ };
251
+ imports.wbg.__wbindgen_number_new = function(arg0) {
252
+ const ret = arg0;
253
+ return ret;
254
+ };
255
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
256
+ const ret = getStringFromWasm0(arg0, arg1);
257
+ return ret;
258
+ };
259
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
260
+ throw new Error(getStringFromWasm0(arg0, arg1));
261
+ };
262
+
263
+ return imports;
264
+ }
265
+
266
+ function __wbg_init_memory(imports, memory) {
267
+
268
+ }
269
+
270
+ function __wbg_finalize_init(instance, module) {
271
+ wasm = instance.exports;
272
+ __wbg_init.__wbindgen_wasm_module = module;
273
+ cachedDataViewMemory0 = null;
274
+ cachedUint8ArrayMemory0 = null;
275
+
276
+
277
+ wasm.__wbindgen_start();
278
+ return wasm;
279
+ }
280
+
281
+ function initSync(module) {
282
+ if (wasm !== undefined) return wasm;
283
+
284
+
285
+ if (typeof module !== 'undefined') {
286
+ if (Object.getPrototypeOf(module) === Object.prototype) {
287
+ ({module} = module)
288
+ } else {
289
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
290
+ }
291
+ }
292
+
293
+ const imports = __wbg_get_imports();
294
+
295
+ __wbg_init_memory(imports);
296
+
297
+ if (!(module instanceof WebAssembly.Module)) {
298
+ module = new WebAssembly.Module(module);
299
+ }
300
+
301
+ const instance = new WebAssembly.Instance(module, imports);
302
+
303
+ return __wbg_finalize_init(instance, module);
304
+ }
305
+
306
+ async function __wbg_init(module_or_path) {
307
+ if (wasm !== undefined) return wasm;
308
+
309
+
310
+ if (typeof module_or_path !== 'undefined') {
311
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
312
+ ({module_or_path} = module_or_path)
313
+ } else {
314
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
315
+ }
316
+ }
317
+
318
+ if (typeof module_or_path === 'undefined') {
319
+ module_or_path = new URL('pcb_zen_wasm_bg.wasm', import.meta.url);
320
+ }
321
+ const imports = __wbg_get_imports();
322
+
323
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
324
+ module_or_path = fetch(module_or_path);
325
+ }
326
+
327
+ __wbg_init_memory(imports);
328
+
329
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
330
+
331
+ return __wbg_finalize_init(instance, module);
332
+ }
333
+
334
+ export { initSync };
335
+ export default __wbg_init;
Binary file