@esm.sh/oxide-wasm 0.1.4 → 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/index.d.ts +6 -0
- package/index.mjs +12 -3
- package/package.json +1 -1
- package/pkg/oxide_wasm.js +59 -55
- package/pkg/oxide_wasm_bg.wasm +0 -0
package/index.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
+
type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
2
|
+
type InitInput = RequestInfo | URL | Response | SyncInitInput;
|
|
3
|
+
|
|
4
|
+
export function initSync(module: SyncInitInput): void;
|
|
5
|
+
export function init(module_or_path?: InitInput | Promise<InitInput>): Promise<void>;
|
|
1
6
|
export function extract(input: string): string[];
|
|
7
|
+
export default init;
|
package/index.mjs
CHANGED
|
@@ -13,9 +13,18 @@ export function initSync(module) {
|
|
|
13
13
|
|
|
14
14
|
export async function init(module_or_path) {
|
|
15
15
|
const importUrl = import.meta.url;
|
|
16
|
-
if (!module_or_path && importUrl.startsWith("file://")
|
|
17
|
-
const
|
|
18
|
-
|
|
16
|
+
if (!module_or_path && importUrl.startsWith("file://")) {
|
|
17
|
+
const { pathname: filename } = new URL("./pkg/oxide_wasm_bg.wasm", importUrl);
|
|
18
|
+
let wasmBytes;
|
|
19
|
+
if (globalThis.Deno) {
|
|
20
|
+
wasmBytes = await Deno.readFile(filename);
|
|
21
|
+
} else if (globalThis.Bun) {
|
|
22
|
+
wasmBytes = await Bun.file(filename).arrayBuffer();
|
|
23
|
+
} else {
|
|
24
|
+
const moduleSpecifier = `node:fs/promises`;
|
|
25
|
+
const fsPromise = await import(moduleSpecifier); // <- use variable to skip deno-lsp analyzing
|
|
26
|
+
wasmBytes = await fsPromise.readFile(filename);
|
|
27
|
+
}
|
|
19
28
|
initWasmSync({ module: wasmBytes });
|
|
20
29
|
return;
|
|
21
30
|
}
|
package/package.json
CHANGED
package/pkg/oxide_wasm.js
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
/* @ts-self-types="./oxide_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} input
|
|
5
|
+
* @returns {any[]}
|
|
6
|
+
*/
|
|
7
|
+
export function extract(input) {
|
|
8
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
9
|
+
const len0 = WASM_VECTOR_LEN;
|
|
10
|
+
const ret = wasm.extract(ptr0, len0);
|
|
11
|
+
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
12
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
13
|
+
return v2;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function __wbg_get_imports() {
|
|
17
|
+
const import0 = {
|
|
18
|
+
__proto__: null,
|
|
19
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
20
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
21
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
22
|
+
return ret;
|
|
23
|
+
},
|
|
24
|
+
__wbindgen_init_externref_table: function() {
|
|
25
|
+
const table = wasm.__wbindgen_externrefs;
|
|
26
|
+
const offset = table.grow(4);
|
|
27
|
+
table.set(0, undefined);
|
|
28
|
+
table.set(offset + 0, undefined);
|
|
29
|
+
table.set(offset + 1, null);
|
|
30
|
+
table.set(offset + 2, true);
|
|
31
|
+
table.set(offset + 3, false);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
__proto__: null,
|
|
36
|
+
"./oxide_wasm_bg.js": import0,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
2
39
|
|
|
3
40
|
function getArrayJsValueFromWasm0(ptr, len) {
|
|
4
41
|
ptr = ptr >>> 0;
|
|
@@ -93,40 +130,33 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
93
130
|
read: arg.length,
|
|
94
131
|
written: buf.length
|
|
95
132
|
};
|
|
96
|
-
}
|
|
133
|
+
};
|
|
97
134
|
}
|
|
98
135
|
|
|
99
136
|
let WASM_VECTOR_LEN = 0;
|
|
100
137
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
110
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
111
|
-
return v2;
|
|
138
|
+
let wasmModule, wasm;
|
|
139
|
+
function __wbg_finalize_init(instance, module) {
|
|
140
|
+
wasm = instance.exports;
|
|
141
|
+
wasmModule = module;
|
|
142
|
+
cachedDataViewMemory0 = null;
|
|
143
|
+
cachedUint8ArrayMemory0 = null;
|
|
144
|
+
wasm.__wbindgen_start();
|
|
145
|
+
return wasm;
|
|
112
146
|
}
|
|
113
147
|
|
|
114
|
-
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
115
|
-
|
|
116
148
|
async function __wbg_load(module, imports) {
|
|
117
149
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
118
150
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
119
151
|
try {
|
|
120
152
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
121
153
|
} catch (e) {
|
|
122
|
-
const validResponse = module.ok &&
|
|
154
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
123
155
|
|
|
124
156
|
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
125
157
|
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);
|
|
126
158
|
|
|
127
|
-
} else {
|
|
128
|
-
throw e;
|
|
129
|
-
}
|
|
159
|
+
} else { throw e; }
|
|
130
160
|
}
|
|
131
161
|
}
|
|
132
162
|
|
|
@@ -141,45 +171,20 @@ async function __wbg_load(module, imports) {
|
|
|
141
171
|
return instance;
|
|
142
172
|
}
|
|
143
173
|
}
|
|
144
|
-
}
|
|
145
174
|
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return ret;
|
|
153
|
-
};
|
|
154
|
-
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
155
|
-
const table = wasm.__wbindgen_externrefs;
|
|
156
|
-
const offset = table.grow(4);
|
|
157
|
-
table.set(0, undefined);
|
|
158
|
-
table.set(offset + 0, undefined);
|
|
159
|
-
table.set(offset + 1, null);
|
|
160
|
-
table.set(offset + 2, true);
|
|
161
|
-
table.set(offset + 3, false);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
return imports;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function __wbg_finalize_init(instance, module) {
|
|
168
|
-
wasm = instance.exports;
|
|
169
|
-
__wbg_init.__wbindgen_wasm_module = module;
|
|
170
|
-
cachedDataViewMemory0 = null;
|
|
171
|
-
cachedUint8ArrayMemory0 = null;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
wasm.__wbindgen_start();
|
|
175
|
-
return wasm;
|
|
175
|
+
function expectedResponseType(type) {
|
|
176
|
+
switch (type) {
|
|
177
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
176
181
|
}
|
|
177
182
|
|
|
178
183
|
function initSync(module) {
|
|
179
184
|
if (wasm !== undefined) return wasm;
|
|
180
185
|
|
|
181
186
|
|
|
182
|
-
if (
|
|
187
|
+
if (module !== undefined) {
|
|
183
188
|
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
184
189
|
({module} = module)
|
|
185
190
|
} else {
|
|
@@ -199,7 +204,7 @@ async function __wbg_init(module_or_path) {
|
|
|
199
204
|
if (wasm !== undefined) return wasm;
|
|
200
205
|
|
|
201
206
|
|
|
202
|
-
if (
|
|
207
|
+
if (module_or_path !== undefined) {
|
|
203
208
|
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
204
209
|
({module_or_path} = module_or_path)
|
|
205
210
|
} else {
|
|
@@ -207,7 +212,7 @@ async function __wbg_init(module_or_path) {
|
|
|
207
212
|
}
|
|
208
213
|
}
|
|
209
214
|
|
|
210
|
-
if (
|
|
215
|
+
if (module_or_path === undefined) {
|
|
211
216
|
module_or_path = new URL('oxide_wasm_bg.wasm', import.meta.url);
|
|
212
217
|
}
|
|
213
218
|
const imports = __wbg_get_imports();
|
|
@@ -221,5 +226,4 @@ async function __wbg_init(module_or_path) {
|
|
|
221
226
|
return __wbg_finalize_init(instance, module);
|
|
222
227
|
}
|
|
223
228
|
|
|
224
|
-
export { initSync };
|
|
225
|
-
export default __wbg_init;
|
|
229
|
+
export { initSync, __wbg_init as default };
|
package/pkg/oxide_wasm_bg.wasm
CHANGED
|
Binary file
|