@aardarch/aardink-web 0.5.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,98 @@
1
+
2
+
3
+ import { importObject, setWasmExports } from './aardink-web.import-object.mjs'
4
+
5
+ let wasmInstance;
6
+
7
+ const wasmOptions = { builtins: ['js-string'], importedStringConstants: "'" }
8
+
9
+ try {
10
+ if ((typeof process !== 'undefined') && (process.release.name === 'node')) {
11
+ const fs = await import(/* webpackIgnore: true */'node:fs');
12
+ const url = await import(/* webpackIgnore: true */'node:url');
13
+ const filepath = import.meta.resolve('./aardink-web.wasm');
14
+ const wasmBuffer = fs.readFileSync(url.fileURLToPath(filepath));
15
+ const wasmModule = new WebAssembly.Module(wasmBuffer, wasmOptions);
16
+ wasmInstance = new WebAssembly.Instance(wasmModule, importObject);
17
+ } else if (typeof Deno !== 'undefined') {
18
+ const path = await import(/* webpackIgnore: true */'https://deno.land/std/path/mod.ts');
19
+ const binary = Deno.readFileSync(path.fromFileUrl(import.meta.resolve('./aardink-web.wasm')));
20
+ const module = await WebAssembly.compile(binary, wasmOptions);
21
+ wasmInstance = await WebAssembly.instantiate(module, importObject);
22
+ } else if (
23
+ (typeof d8 !== 'undefined' // V8
24
+ || typeof inIon !== 'undefined' // SpiderMonkey
25
+ || typeof jscOptions !== 'undefined' // JavaScriptCore
26
+ )
27
+ ) {
28
+ const filepath = import.meta.url.replace(/\.mjs$/, '.wasm');
29
+ const wasmBuffer = read(filepath, 'binary');
30
+ const wasmModule = new WebAssembly.Module(wasmBuffer, wasmOptions);
31
+ wasmInstance = new WebAssembly.Instance(wasmModule, importObject);
32
+ } else {
33
+ wasmInstance = (await WebAssembly.instantiateStreaming(fetch(new URL('./aardink-web.wasm',import.meta.url).href), importObject, wasmOptions)).instance;
34
+ }
35
+ } catch (e) {
36
+ if (e instanceof WebAssembly.CompileError) {
37
+ let text = `Please make sure that your runtime environment supports the latest version of Wasm GC and Exception-Handling proposals.
38
+ For more information, see https://kotl.in/wasm-help
39
+ `;
40
+ if (typeof console !== "undefined" && console.error !== void 0) {
41
+ console.error(text);
42
+ } else {
43
+ const t = "\n" + text;
44
+ if (typeof console !== "undefined" && console.log !== void 0)
45
+ console.log(t);
46
+ else
47
+ print(t);
48
+ }
49
+ }
50
+ throw e;
51
+ }
52
+
53
+ const exports = wasmInstance.exports
54
+
55
+ let memoryFirstTimeAccess = true;
56
+ const memoryProxy = new Proxy(importObject.intrinsics.memory, {
57
+ get(target, prop, receiver) {
58
+ if (memoryFirstTimeAccess) {
59
+ memoryFirstTimeAccess = false;
60
+ console.error('Accessing `memory` via `wasmExports` is deprecated. Use `kotlin.wasm.unsafe.wasmMemory` or update dependencies. Read more: https://kotl.in/vr3szr');
61
+ }
62
+ return Reflect.get(target, prop);
63
+ }
64
+ });
65
+ const wasmExports = new Proxy(memoryProxy, {
66
+ get(target, prop, receiver) {
67
+ if (prop == 'memory') {
68
+ return target;
69
+ } else {
70
+ throw new Error('Accessing exports via `wasmExports` is no longer supported. Remove usages or update dependencies. Read more: https://kotl.in/vr3szr');
71
+ }
72
+ }
73
+ });
74
+
75
+ const wasmMemory = wasmExports.memory;
76
+ export { wasmMemory as memory }
77
+
78
+ export const {
79
+ aardinkSetBundledFontUrl,
80
+ aardinkCreate,
81
+ aardinkGetValue,
82
+ aardinkSetValue,
83
+ aardinkUpdateOptions,
84
+ aardinkOnChange,
85
+ aardinkOnCursorChange,
86
+ aardinkSetDiagnostics,
87
+ aardinkRevealPosition,
88
+ aardinkShowFind,
89
+ aardinkUndo,
90
+ aardinkRedo,
91
+ aardinkDispose,
92
+ aardinkVersion,
93
+ _start
94
+ } = exports
95
+
96
+ setWasmExports(wasmExports);
97
+
98
+ exports._start();
Binary file