@mocanvas/wasm 1.0.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.
@@ -0,0 +1,505 @@
1
+ /* @ts-self-types="./mocanvas.d.ts" */
2
+
3
+ /**
4
+ * The engine: one scene (the current page) and one renderer.
5
+ */
6
+ export class Engine {
7
+ __destroy_into_raw() {
8
+ const ptr = this.__wbg_ptr;
9
+ this.__wbg_ptr = 0;
10
+ EngineFinalization.unregister(this);
11
+ return ptr;
12
+ }
13
+ free() {
14
+ const ptr = this.__destroy_into_raw();
15
+ wasm.__wbg_engine_free(ptr, 0);
16
+ }
17
+ /**
18
+ * Union of all page bounds → `f32_ptr()`. Returns false if the scene is empty.
19
+ * @returns {boolean}
20
+ */
21
+ all_bounds() {
22
+ const ret = wasm.engine_all_bounds(this.__wbg_ptr);
23
+ return ret !== 0;
24
+ }
25
+ /**
26
+ * Union of all geometry bounds → `f32_ptr()`. Returns false if the scene is empty.
27
+ * @returns {boolean}
28
+ */
29
+ all_geometry_bounds() {
30
+ const ret = wasm.engine_all_geometry_bounds(this.__wbg_ptr);
31
+ return ret !== 0;
32
+ }
33
+ /**
34
+ * Apply `len` words of commands from the command buffer. Returns the number of
35
+ * commands applied; on a malformed stream applies what it can and records an error.
36
+ * @param {number} len
37
+ * @returns {number}
38
+ */
39
+ apply(len) {
40
+ const ret = wasm.engine_apply(this.__wbg_ptr, len);
41
+ return ret >>> 0;
42
+ }
43
+ /**
44
+ * Number of u32 in the batch buffer (7 per batch).
45
+ * @returns {number}
46
+ */
47
+ batches_len() {
48
+ const ret = wasm.engine_batches_len(this.__wbg_ptr);
49
+ return ret >>> 0;
50
+ }
51
+ /**
52
+ * Pointer to batch records: `first_index count texture clip_minx clip_miny clip_maxx
53
+ * clip_maxy` (clip as f32 bits; all four zero = no clip).
54
+ * @returns {number}
55
+ */
56
+ batches_ptr() {
57
+ const ret = wasm.engine_batches_ptr(this.__wbg_ptr);
58
+ return ret >>> 0;
59
+ }
60
+ /**
61
+ * Page bounds of a shape → `f32_ptr()` holds `minx miny maxx maxy`. Returns false if missing.
62
+ * @param {number} handle
63
+ * @returns {boolean}
64
+ */
65
+ bounds(handle) {
66
+ const ret = wasm.engine_bounds(this.__wbg_ptr, handle);
67
+ return ret !== 0;
68
+ }
69
+ /**
70
+ * Current capacity of the command buffer in words.
71
+ * @returns {number}
72
+ */
73
+ cmd_capacity() {
74
+ const ret = wasm.engine_cmd_capacity(this.__wbg_ptr);
75
+ return ret >>> 0;
76
+ }
77
+ /**
78
+ * Reserve the command buffer for at least `words` u32 words and return its pointer.
79
+ * The host writes commands into a `Uint32Array(memory.buffer, ptr, words)` view
80
+ * (bit-casting floats) and then calls [`Engine::apply`].
81
+ * @param {number} words
82
+ * @returns {number}
83
+ */
84
+ cmd_ptr(words) {
85
+ const ret = wasm.engine_cmd_ptr(this.__wbg_ptr, words);
86
+ return ret >>> 0;
87
+ }
88
+ /**
89
+ * Shapes culled last frame.
90
+ * @returns {number}
91
+ */
92
+ culled_count() {
93
+ const ret = wasm.engine_culled_count(this.__wbg_ptr);
94
+ return ret >>> 0;
95
+ }
96
+ /**
97
+ * The default per-frame tessellation budget.
98
+ * @returns {number}
99
+ */
100
+ static default_tess_budget() {
101
+ const ret = wasm.engine_default_tess_budget();
102
+ return ret >>> 0;
103
+ }
104
+ /**
105
+ * Shapes drawn last frame.
106
+ * @returns {number}
107
+ */
108
+ drawn_count() {
109
+ const ret = wasm.engine_drawn_count(this.__wbg_ptr);
110
+ return ret >>> 0;
111
+ }
112
+ /**
113
+ * Change counter.
114
+ * @returns {number}
115
+ */
116
+ epoch() {
117
+ const ret = wasm.engine_epoch(this.__wbg_ptr);
118
+ return ret;
119
+ }
120
+ /**
121
+ * Pointer to the small f32 result buffer.
122
+ * @returns {number}
123
+ */
124
+ f32_ptr() {
125
+ const ret = wasm.engine_f32_ptr(this.__wbg_ptr);
126
+ return ret >>> 0;
127
+ }
128
+ /**
129
+ * Build the frame for a camera (`cx, cy` page offset, `zoom`) and viewport size in
130
+ * screen pixels. Afterwards read the buffers through the `*_ptr`/`*_len` getters.
131
+ *
132
+ * The buffers are page-space, so they do not depend on the camera: when the scene
133
+ * is unchanged and the camera has only moved a little, this reuses the previous
134
+ * build, leaves the buffers alone and reports [`Engine::frame_dirty`] `false` — the
135
+ * host can then skip re-uploading them and just redraw with the new camera uniform.
136
+ *
137
+ * `tess_budget` caps how many shapes may be tessellated in this call (0 = no cap);
138
+ * the rest are drawn as level-of-detail quads until a later frame catches up, with
139
+ * [`Engine::frame_pending`] set meanwhile.
140
+ * @param {number} cam_x
141
+ * @param {number} cam_y
142
+ * @param {number} zoom
143
+ * @param {number} vp_w
144
+ * @param {number} vp_h
145
+ * @param {number} tess_budget
146
+ */
147
+ frame(cam_x, cam_y, zoom, vp_w, vp_h, tess_budget) {
148
+ wasm.engine_frame(this.__wbg_ptr, cam_x, cam_y, zoom, vp_w, vp_h, tess_budget);
149
+ }
150
+ /**
151
+ * Whether the last [`Engine::frame`] rebuilt the buffers. When false the pointers,
152
+ * lengths and contents are exactly what the previous frame produced.
153
+ * @returns {boolean}
154
+ */
155
+ frame_dirty() {
156
+ const ret = wasm.engine_frame_dirty(this.__wbg_ptr);
157
+ return ret !== 0;
158
+ }
159
+ /**
160
+ * Whether shapes are still waiting on the tessellation budget and are meanwhile
161
+ * drawn as quads. The host should keep scheduling frames while this is true.
162
+ * @returns {boolean}
163
+ */
164
+ frame_pending() {
165
+ const ret = wasm.engine_frame_pending(this.__wbg_ptr);
166
+ return ret !== 0;
167
+ }
168
+ /**
169
+ * Counter bumped on every rebuild. A host that has uploaded version `v` can skip
170
+ * the upload for as long as this still reads `v`.
171
+ * @returns {number}
172
+ */
173
+ frame_version() {
174
+ const ret = wasm.engine_frame_version(this.__wbg_ptr);
175
+ return ret;
176
+ }
177
+ /**
178
+ * Geometry-only page bounds of a shape → `f32_ptr()` holds `minx miny maxx maxy`.
179
+ * Same box as `bounds` without the half-stroke pad. Returns false if missing.
180
+ * @param {number} handle
181
+ * @returns {boolean}
182
+ */
183
+ geometry_bounds(handle) {
184
+ const ret = wasm.engine_geometry_bounds(this.__wbg_ptr, handle);
185
+ return ret !== 0;
186
+ }
187
+ /**
188
+ * Pointer to the handle result buffer.
189
+ * @returns {number}
190
+ */
191
+ handles_ptr() {
192
+ const ret = wasm.engine_handles_ptr(this.__wbg_ptr);
193
+ return ret >>> 0;
194
+ }
195
+ /**
196
+ * Topmost shape at a page point, or 0. `filter` bits: 1 include locked, 2 include hidden, 4 hollow only.
197
+ * @param {number} x
198
+ * @param {number} y
199
+ * @param {number} tolerance
200
+ * @param {number} filter
201
+ * @returns {number}
202
+ */
203
+ hit_test(x, y, tolerance, filter) {
204
+ const ret = wasm.engine_hit_test(this.__wbg_ptr, x, y, tolerance, filter);
205
+ return ret >>> 0;
206
+ }
207
+ /**
208
+ * Number of indices.
209
+ * @returns {number}
210
+ */
211
+ indices_len() {
212
+ const ret = wasm.engine_indices_len(this.__wbg_ptr);
213
+ return ret >>> 0;
214
+ }
215
+ /**
216
+ * Pointer to u32 indices.
217
+ * @returns {number}
218
+ */
219
+ indices_ptr() {
220
+ const ret = wasm.engine_indices_ptr(this.__wbg_ptr);
221
+ return ret >>> 0;
222
+ }
223
+ /**
224
+ * Create an empty engine.
225
+ */
226
+ constructor() {
227
+ const ret = wasm.engine_new();
228
+ this.__wbg_ptr = ret;
229
+ EngineFinalization.register(this, this.__wbg_ptr, this);
230
+ return this;
231
+ }
232
+ /**
233
+ * Number of u32 in the overlay buffer (10 per entry).
234
+ * @returns {number}
235
+ */
236
+ overlay_len() {
237
+ const ret = wasm.engine_overlay_len(this.__wbg_ptr);
238
+ return ret >>> 0;
239
+ }
240
+ /**
241
+ * Pointer to overlay entries (`handle x y w h rot clip_minx clip_miny clip_maxx
242
+ * clip_maxy`, floats as bits; clip all zero = unclipped).
243
+ * @returns {number}
244
+ */
245
+ overlay_ptr() {
246
+ const ret = wasm.engine_overlay_ptr(this.__wbg_ptr);
247
+ return ret >>> 0;
248
+ }
249
+ /**
250
+ * Page transform of a shape → `f32_ptr()` holds `a b c d e f`. Returns false if missing.
251
+ * @param {number} handle
252
+ * @returns {boolean}
253
+ */
254
+ page_transform(handle) {
255
+ const ret = wasm.engine_page_transform(this.__wbg_ptr, handle);
256
+ return ret !== 0;
257
+ }
258
+ /**
259
+ * Shapes in a page box. `mode` 0 = intersects, 1 = contains. Returns count; read via `handles_ptr`.
260
+ * @param {number} minx
261
+ * @param {number} miny
262
+ * @param {number} maxx
263
+ * @param {number} maxy
264
+ * @param {number} mode
265
+ * @param {number} filter
266
+ * @returns {number}
267
+ */
268
+ query_box(minx, miny, maxx, maxy, mode, filter) {
269
+ const ret = wasm.engine_query_box(this.__wbg_ptr, minx, miny, maxx, maxy, mode, filter);
270
+ return ret >>> 0;
271
+ }
272
+ /**
273
+ * Grow the box each frame is built for by `pad` (a fraction of the viewport size)
274
+ * on every side, so a camera panning inside that margin reuses the build instead
275
+ * of re-tessellating and re-uploading. Defaults to
276
+ * `mocanvas_render::DEFAULT_VIEWPORT_PAD` — see `Renderer::set_viewport_pad` for
277
+ * the trade-off, which depends on how expensive the host's rasteriser makes
278
+ * geometry relative to uploads.
279
+ * @param {number} pad
280
+ */
281
+ set_viewport_pad(pad) {
282
+ wasm.engine_set_viewport_pad(this.__wbg_ptr, pad);
283
+ }
284
+ /**
285
+ * Number of shapes in the scene.
286
+ * @returns {number}
287
+ */
288
+ shape_count() {
289
+ const ret = wasm.engine_shape_count(this.__wbg_ptr);
290
+ return ret >>> 0;
291
+ }
292
+ /**
293
+ * Take the last error message, if any.
294
+ * @returns {string | undefined}
295
+ */
296
+ take_error() {
297
+ const ret = wasm.engine_take_error(this.__wbg_ptr);
298
+ let v1;
299
+ if (ret[0] !== 0) {
300
+ v1 = getStringFromWasm0(ret[0], ret[1]);
301
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
302
+ }
303
+ return v1;
304
+ }
305
+ /**
306
+ * Union of page bounds for `len` handles read from the command buffer → `f32_ptr()`.
307
+ * Returns false if the union is empty.
308
+ * @param {number} len
309
+ * @returns {boolean}
310
+ */
311
+ union_bounds(len) {
312
+ const ret = wasm.engine_union_bounds(this.__wbg_ptr, len);
313
+ return ret !== 0;
314
+ }
315
+ /**
316
+ * Number of f32 in the vertex buffer.
317
+ * @returns {number}
318
+ */
319
+ vertices_len() {
320
+ const ret = wasm.engine_vertices_len(this.__wbg_ptr);
321
+ return ret >>> 0;
322
+ }
323
+ /**
324
+ * Pointer to interleaved `x y u v r g b a` f32 vertices (8 per vertex).
325
+ * @returns {number}
326
+ */
327
+ vertices_ptr() {
328
+ const ret = wasm.engine_vertices_ptr(this.__wbg_ptr);
329
+ return ret >>> 0;
330
+ }
331
+ /**
332
+ * The current viewport pad.
333
+ * @returns {number}
334
+ */
335
+ viewport_pad() {
336
+ const ret = wasm.engine_viewport_pad(this.__wbg_ptr);
337
+ return ret;
338
+ }
339
+ }
340
+ if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
341
+
342
+ /**
343
+ * Library version.
344
+ * @returns {string}
345
+ */
346
+ export function version() {
347
+ let deferred1_0;
348
+ let deferred1_1;
349
+ try {
350
+ const ret = wasm.version();
351
+ deferred1_0 = ret[0];
352
+ deferred1_1 = ret[1];
353
+ return getStringFromWasm0(ret[0], ret[1]);
354
+ } finally {
355
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
356
+ }
357
+ }
358
+ function __wbg_get_imports() {
359
+ const import0 = {
360
+ __proto__: null,
361
+ __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
362
+ throw new Error(getStringFromWasm0(arg0, arg1));
363
+ },
364
+ __wbindgen_init_externref_table: function() {
365
+ const table = wasm.__wbindgen_externrefs;
366
+ const offset = table.grow(4);
367
+ table.set(0, undefined);
368
+ table.set(offset + 0, undefined);
369
+ table.set(offset + 1, null);
370
+ table.set(offset + 2, true);
371
+ table.set(offset + 3, false);
372
+ },
373
+ };
374
+ return {
375
+ __proto__: null,
376
+ "./mocanvas_bg.js": import0,
377
+ };
378
+ }
379
+
380
+ const EngineFinalization = (typeof FinalizationRegistry === 'undefined')
381
+ ? { register: () => {}, unregister: () => {} }
382
+ : new FinalizationRegistry(ptr => wasm.__wbg_engine_free(ptr, 1));
383
+
384
+ function getStringFromWasm0(ptr, len) {
385
+ return decodeText(ptr >>> 0, len);
386
+ }
387
+
388
+ let cachedUint8ArrayMemory0 = null;
389
+ function getUint8ArrayMemory0() {
390
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
391
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
392
+ }
393
+ return cachedUint8ArrayMemory0;
394
+ }
395
+
396
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
397
+ cachedTextDecoder.decode();
398
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
399
+ let numBytesDecoded = 0;
400
+ function decodeText(ptr, len) {
401
+ numBytesDecoded += len;
402
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
403
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
404
+ cachedTextDecoder.decode();
405
+ numBytesDecoded = len;
406
+ }
407
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
408
+ }
409
+
410
+ let wasmModule, wasmInstance, wasm;
411
+ function __wbg_finalize_init(instance, module) {
412
+ wasmInstance = instance;
413
+ wasm = instance.exports;
414
+ wasmModule = module;
415
+ cachedUint8ArrayMemory0 = null;
416
+ wasm.__wbindgen_start();
417
+ return wasm;
418
+ }
419
+
420
+ async function __wbg_load(module, imports) {
421
+ if (typeof Response === 'function' && module instanceof Response) {
422
+ if (!module.ok) {
423
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
424
+ }
425
+
426
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
427
+ try {
428
+ return await WebAssembly.instantiateStreaming(module, imports);
429
+ } catch (e) {
430
+ const validResponse = expectedResponseType(module.type);
431
+
432
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
433
+ 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);
434
+
435
+ } else { throw e; }
436
+ }
437
+ }
438
+
439
+ const bytes = await module.arrayBuffer();
440
+ return await WebAssembly.instantiate(bytes, imports);
441
+ } else {
442
+ const instance = await WebAssembly.instantiate(module, imports);
443
+
444
+ if (instance instanceof WebAssembly.Instance) {
445
+ return { instance, module };
446
+ } else {
447
+ return instance;
448
+ }
449
+ }
450
+
451
+ function expectedResponseType(type) {
452
+ switch (type) {
453
+ case 'basic': case 'cors': case 'default': return true;
454
+ }
455
+ return false;
456
+ }
457
+ }
458
+
459
+ function initSync(module) {
460
+ if (wasm !== undefined) return wasm;
461
+
462
+
463
+ if (module !== undefined) {
464
+ if (Object.getPrototypeOf(module) === Object.prototype) {
465
+ ({module} = module)
466
+ } else {
467
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
468
+ }
469
+ }
470
+
471
+ const imports = __wbg_get_imports();
472
+ if (!(module instanceof WebAssembly.Module)) {
473
+ module = new WebAssembly.Module(module);
474
+ }
475
+ const instance = new WebAssembly.Instance(module, imports);
476
+ return __wbg_finalize_init(instance, module);
477
+ }
478
+
479
+ async function __wbg_init(module_or_path) {
480
+ if (wasm !== undefined) return wasm;
481
+
482
+
483
+ if (module_or_path !== undefined) {
484
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
485
+ ({module_or_path} = module_or_path)
486
+ } else {
487
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
488
+ }
489
+ }
490
+
491
+ if (module_or_path === undefined) {
492
+ module_or_path = new URL('mocanvas_bg.wasm', import.meta.url);
493
+ }
494
+ const imports = __wbg_get_imports();
495
+
496
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
497
+ module_or_path = fetch(module_or_path);
498
+ }
499
+
500
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
501
+
502
+ return __wbg_finalize_init(instance, module);
503
+ }
504
+
505
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,42 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_engine_free: (a: number, b: number) => void;
5
+ export const engine_all_bounds: (a: number) => number;
6
+ export const engine_all_geometry_bounds: (a: number) => number;
7
+ export const engine_apply: (a: number, b: number) => number;
8
+ export const engine_batches_len: (a: number) => number;
9
+ export const engine_batches_ptr: (a: number) => number;
10
+ export const engine_bounds: (a: number, b: number) => number;
11
+ export const engine_cmd_capacity: (a: number) => number;
12
+ export const engine_cmd_ptr: (a: number, b: number) => number;
13
+ export const engine_culled_count: (a: number) => number;
14
+ export const engine_default_tess_budget: () => number;
15
+ export const engine_drawn_count: (a: number) => number;
16
+ export const engine_epoch: (a: number) => number;
17
+ export const engine_f32_ptr: (a: number) => number;
18
+ export const engine_frame: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
19
+ export const engine_frame_dirty: (a: number) => number;
20
+ export const engine_frame_pending: (a: number) => number;
21
+ export const engine_frame_version: (a: number) => number;
22
+ export const engine_geometry_bounds: (a: number, b: number) => number;
23
+ export const engine_handles_ptr: (a: number) => number;
24
+ export const engine_hit_test: (a: number, b: number, c: number, d: number, e: number) => number;
25
+ export const engine_indices_len: (a: number) => number;
26
+ export const engine_indices_ptr: (a: number) => number;
27
+ export const engine_new: () => number;
28
+ export const engine_overlay_len: (a: number) => number;
29
+ export const engine_overlay_ptr: (a: number) => number;
30
+ export const engine_page_transform: (a: number, b: number) => number;
31
+ export const engine_query_box: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => number;
32
+ export const engine_set_viewport_pad: (a: number, b: number) => void;
33
+ export const engine_shape_count: (a: number) => number;
34
+ export const engine_take_error: (a: number) => [number, number];
35
+ export const engine_union_bounds: (a: number, b: number) => number;
36
+ export const engine_vertices_len: (a: number) => number;
37
+ export const engine_vertices_ptr: (a: number) => number;
38
+ export const engine_viewport_pad: (a: number) => number;
39
+ export const version: () => [number, number];
40
+ export const __wbindgen_externrefs: WebAssembly.Table;
41
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
42
+ export const __wbindgen_start: () => void;