okgeometry-api 0.5.1 → 0.5.2

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/src/engine.ts CHANGED
@@ -1,92 +1,92 @@
1
- import { WASM_B64 } from "./wasm-base64.js";
2
- import * as bg from "../wasm/okgeometrycore_bg.js";
3
-
4
- let initialized = false;
5
- let wasmExports: Record<string, unknown> | null = null;
6
-
7
- const engineGlobal = globalThis as typeof globalThis & {
8
- __okgeometry_boolean_should_cancel?: () => boolean;
9
- };
10
-
11
- if (typeof engineGlobal.__okgeometry_boolean_should_cancel !== "function") {
12
- engineGlobal.__okgeometry_boolean_should_cancel = () => false;
13
- }
14
-
15
- function buildWasmImports(requiredNames: string[] = []): Record<string, unknown> {
16
- const bgAny = bg as Record<string, unknown>;
17
- const importModule: Record<string, unknown> = { ...bgAny };
18
- const cancelKey = Object.keys(importModule).find(k => k.startsWith("__wbg___okgeometry_boolean_should_cancel_"));
19
- const cancelFn = () => {
20
- try {
21
- return !!engineGlobal.__okgeometry_boolean_should_cancel?.();
22
- } catch {
23
- return false;
24
- }
25
- };
26
- if (cancelKey) {
27
- importModule[cancelKey] = cancelFn;
28
- } else {
29
- // Fallback to current known symbol in generated bindings.
30
- importModule.__wbg___okgeometry_boolean_should_cancel_3e76652b5286d323 = cancelFn;
31
- }
32
-
33
- // Fill hash-suffixed imports that may not be exported by generated glue in this runtime.
34
- for (const name of requiredNames) {
35
- const existing = importModule[name];
36
- if (typeof existing === "function") {
37
- continue;
38
- }
39
- if (name.startsWith("__wbg___okgeometry_boolean_should_cancel_")) {
40
- importModule[name] = cancelFn;
41
- continue;
42
- }
43
- if (name.startsWith("__wbg_now_")) {
44
- importModule[name] = () => Date.now();
45
- continue;
46
- }
47
- if (name.startsWith("__wbg___wbindgen_throw_")) {
48
- importModule[name] = () => {
49
- throw new Error("WASM trap: __wbindgen_throw");
50
- };
51
- continue;
52
- }
53
- if (name === "__wbindgen_init_externref_table") {
54
- importModule[name] = () => {};
55
- continue;
56
- }
57
- }
58
-
59
- return importModule;
60
- }
61
-
62
- export async function init(): Promise<void> {
63
- if (initialized) return;
64
- const raw = atob(WASM_B64);
65
- const bytes = new Uint8Array(raw.length);
66
- for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
67
-
68
- const wasmModule = await WebAssembly.compile(bytes.buffer);
69
- const requiredNames = WebAssembly.Module.imports(wasmModule)
70
- .filter((imp) => imp.module === "./okgeometrycore_bg.js")
71
- .map((imp) => imp.name);
72
- const importModule = buildWasmImports(requiredNames);
73
- const instance = await WebAssembly.instantiate(wasmModule, {
74
- "./okgeometrycore_bg.js": importModule as any,
75
- });
76
- wasmExports = instance.exports as Record<string, unknown>;
77
-
78
- (bg as any).__wbg_set_wasm(instance.exports);
79
- (instance.exports as any).__wbindgen_start();
80
-
81
- initialized = true;
82
- }
83
-
84
- export function ensureInit(): void {
85
- if (!initialized) {
86
- throw new Error("OkGeometry WASM not initialized. Call `await init()` before using geometry operations.");
87
- }
88
- }
89
-
90
- export function isInitialized(): boolean {
91
- return initialized;
92
- }
1
+ import { WASM_B64 } from "./wasm-base64.js";
2
+ import * as bg from "../wasm/okgeometrycore_bg.js";
3
+
4
+ let initialized = false;
5
+ let wasmExports: Record<string, unknown> | null = null;
6
+
7
+ const engineGlobal = globalThis as typeof globalThis & {
8
+ __okgeometry_boolean_should_cancel?: () => boolean;
9
+ };
10
+
11
+ if (typeof engineGlobal.__okgeometry_boolean_should_cancel !== "function") {
12
+ engineGlobal.__okgeometry_boolean_should_cancel = () => false;
13
+ }
14
+
15
+ function buildWasmImports(requiredNames: string[] = []): Record<string, unknown> {
16
+ const bgAny = bg as Record<string, unknown>;
17
+ const importModule: Record<string, unknown> = { ...bgAny };
18
+ const cancelKey = Object.keys(importModule).find(k => k.startsWith("__wbg___okgeometry_boolean_should_cancel_"));
19
+ const cancelFn = () => {
20
+ try {
21
+ return !!engineGlobal.__okgeometry_boolean_should_cancel?.();
22
+ } catch {
23
+ return false;
24
+ }
25
+ };
26
+ if (cancelKey) {
27
+ importModule[cancelKey] = cancelFn;
28
+ } else {
29
+ // Fallback to current known symbol in generated bindings.
30
+ importModule.__wbg___okgeometry_boolean_should_cancel_3e76652b5286d323 = cancelFn;
31
+ }
32
+
33
+ // Fill hash-suffixed imports that may not be exported by generated glue in this runtime.
34
+ for (const name of requiredNames) {
35
+ const existing = importModule[name];
36
+ if (typeof existing === "function") {
37
+ continue;
38
+ }
39
+ if (name.startsWith("__wbg___okgeometry_boolean_should_cancel_")) {
40
+ importModule[name] = cancelFn;
41
+ continue;
42
+ }
43
+ if (name.startsWith("__wbg_now_")) {
44
+ importModule[name] = () => Date.now();
45
+ continue;
46
+ }
47
+ if (name.startsWith("__wbg___wbindgen_throw_")) {
48
+ importModule[name] = () => {
49
+ throw new Error("WASM trap: __wbindgen_throw");
50
+ };
51
+ continue;
52
+ }
53
+ if (name === "__wbindgen_init_externref_table") {
54
+ importModule[name] = () => {};
55
+ continue;
56
+ }
57
+ }
58
+
59
+ return importModule;
60
+ }
61
+
62
+ export async function init(): Promise<void> {
63
+ if (initialized) return;
64
+ const raw = atob(WASM_B64);
65
+ const bytes = new Uint8Array(raw.length);
66
+ for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
67
+
68
+ const wasmModule = await WebAssembly.compile(bytes.buffer);
69
+ const requiredNames = WebAssembly.Module.imports(wasmModule)
70
+ .filter((imp) => imp.module === "./okgeometrycore_bg.js")
71
+ .map((imp) => imp.name);
72
+ const importModule = buildWasmImports(requiredNames);
73
+ const instance = await WebAssembly.instantiate(wasmModule, {
74
+ "./okgeometrycore_bg.js": importModule as any,
75
+ });
76
+ wasmExports = instance.exports as Record<string, unknown>;
77
+
78
+ (bg as any).__wbg_set_wasm(instance.exports);
79
+ (instance.exports as any).__wbindgen_start();
80
+
81
+ initialized = true;
82
+ }
83
+
84
+ export function ensureInit(): void {
85
+ if (!initialized) {
86
+ throw new Error("OkGeometry WASM not initialized. Call `await init()` before using geometry operations.");
87
+ }
88
+ }
89
+
90
+ export function isInitialized(): boolean {
91
+ return initialized;
92
+ }