@esm.sh/oxide-wasm 0.1.2 → 0.1.4
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.mjs +3 -3
- package/package.json +1 -1
- package/pkg/oxide_wasm.js +58 -63
- package/pkg/oxide_wasm_bg.wasm +0 -0
package/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import initWasm, {
|
|
1
|
+
import initWasm, { extract as wasmExtract, initSync as initWasmSync } from "./pkg/oxide_wasm.js";
|
|
2
2
|
|
|
3
3
|
export function extract(input) {
|
|
4
|
-
if (typeof input !== "string"
|
|
5
|
-
throw new
|
|
4
|
+
if (typeof input !== "string") {
|
|
5
|
+
throw new TypeError("input must be a non-empty string");
|
|
6
6
|
}
|
|
7
7
|
return wasmExtract(input);
|
|
8
8
|
}
|
package/package.json
CHANGED
package/pkg/oxide_wasm.js
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
let wasm;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let
|
|
3
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
4
|
+
ptr = ptr >>> 0;
|
|
5
|
+
const mem = getDataViewMemory0();
|
|
6
|
+
const result = [];
|
|
7
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
8
|
+
result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
|
|
9
|
+
}
|
|
10
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
let cachedDataViewMemory0 = null;
|
|
15
|
+
function getDataViewMemory0() {
|
|
16
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
17
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
12
18
|
}
|
|
13
|
-
return
|
|
19
|
+
return cachedDataViewMemory0;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
function getStringFromWasm0(ptr, len) {
|
|
17
23
|
ptr = ptr >>> 0;
|
|
18
|
-
return
|
|
24
|
+
return decodeText(ptr, len);
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return cachedTextEncoder.encodeInto(arg, view);
|
|
27
|
+
let cachedUint8ArrayMemory0 = null;
|
|
28
|
+
function getUint8ArrayMemory0() {
|
|
29
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
30
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
31
|
+
}
|
|
32
|
+
return cachedUint8ArrayMemory0;
|
|
28
33
|
}
|
|
29
|
-
: function (arg, view) {
|
|
30
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
31
|
-
view.set(buf);
|
|
32
|
-
return {
|
|
33
|
-
read: arg.length,
|
|
34
|
-
written: buf.length
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
34
|
|
|
38
35
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
39
|
-
|
|
40
36
|
if (realloc === undefined) {
|
|
41
37
|
const buf = cachedTextEncoder.encode(arg);
|
|
42
38
|
const ptr = malloc(buf.length, 1) >>> 0;
|
|
@@ -57,14 +53,13 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
57
53
|
if (code > 0x7F) break;
|
|
58
54
|
mem[ptr + offset] = code;
|
|
59
55
|
}
|
|
60
|
-
|
|
61
56
|
if (offset !== len) {
|
|
62
57
|
if (offset !== 0) {
|
|
63
58
|
arg = arg.slice(offset);
|
|
64
59
|
}
|
|
65
60
|
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
66
61
|
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
67
|
-
const ret =
|
|
62
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
68
63
|
|
|
69
64
|
offset += ret.written;
|
|
70
65
|
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
@@ -74,25 +69,35 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
74
69
|
return ptr;
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
let
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
73
|
+
cachedTextDecoder.decode();
|
|
74
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
75
|
+
let numBytesDecoded = 0;
|
|
76
|
+
function decodeText(ptr, len) {
|
|
77
|
+
numBytesDecoded += len;
|
|
78
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
79
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
80
|
+
cachedTextDecoder.decode();
|
|
81
|
+
numBytesDecoded = len;
|
|
82
82
|
}
|
|
83
|
-
return
|
|
83
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
const cachedTextEncoder = new TextEncoder();
|
|
87
|
+
|
|
88
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
89
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
90
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
91
|
+
view.set(buf);
|
|
92
|
+
return {
|
|
93
|
+
read: arg.length,
|
|
94
|
+
written: buf.length
|
|
95
|
+
};
|
|
92
96
|
}
|
|
93
|
-
wasm.__externref_drop_slice(ptr, len);
|
|
94
|
-
return result;
|
|
95
97
|
}
|
|
98
|
+
|
|
99
|
+
let WASM_VECTOR_LEN = 0;
|
|
100
|
+
|
|
96
101
|
/**
|
|
97
102
|
* @param {string} input
|
|
98
103
|
* @returns {any[]}
|
|
@@ -106,14 +111,17 @@ export function extract(input) {
|
|
|
106
111
|
return v2;
|
|
107
112
|
}
|
|
108
113
|
|
|
114
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
115
|
+
|
|
109
116
|
async function __wbg_load(module, imports) {
|
|
110
117
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
111
118
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
112
119
|
try {
|
|
113
120
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
114
|
-
|
|
115
121
|
} catch (e) {
|
|
116
|
-
|
|
122
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
123
|
+
|
|
124
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
117
125
|
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);
|
|
118
126
|
|
|
119
127
|
} else {
|
|
@@ -124,13 +132,11 @@ async function __wbg_load(module, imports) {
|
|
|
124
132
|
|
|
125
133
|
const bytes = await module.arrayBuffer();
|
|
126
134
|
return await WebAssembly.instantiate(bytes, imports);
|
|
127
|
-
|
|
128
135
|
} else {
|
|
129
136
|
const instance = await WebAssembly.instantiate(module, imports);
|
|
130
137
|
|
|
131
138
|
if (instance instanceof WebAssembly.Instance) {
|
|
132
139
|
return { instance, module };
|
|
133
|
-
|
|
134
140
|
} else {
|
|
135
141
|
return instance;
|
|
136
142
|
}
|
|
@@ -140,28 +146,24 @@ async function __wbg_load(module, imports) {
|
|
|
140
146
|
function __wbg_get_imports() {
|
|
141
147
|
const imports = {};
|
|
142
148
|
imports.wbg = {};
|
|
149
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
150
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
151
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
152
|
+
return ret;
|
|
153
|
+
};
|
|
143
154
|
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
144
|
-
const table = wasm.
|
|
155
|
+
const table = wasm.__wbindgen_externrefs;
|
|
145
156
|
const offset = table.grow(4);
|
|
146
157
|
table.set(0, undefined);
|
|
147
158
|
table.set(offset + 0, undefined);
|
|
148
159
|
table.set(offset + 1, null);
|
|
149
160
|
table.set(offset + 2, true);
|
|
150
161
|
table.set(offset + 3, false);
|
|
151
|
-
;
|
|
152
|
-
};
|
|
153
|
-
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
154
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
155
|
-
return ret;
|
|
156
162
|
};
|
|
157
163
|
|
|
158
164
|
return imports;
|
|
159
165
|
}
|
|
160
166
|
|
|
161
|
-
function __wbg_init_memory(imports, memory) {
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
167
|
function __wbg_finalize_init(instance, module) {
|
|
166
168
|
wasm = instance.exports;
|
|
167
169
|
__wbg_init.__wbindgen_wasm_module = module;
|
|
@@ -186,15 +188,10 @@ function initSync(module) {
|
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
const imports = __wbg_get_imports();
|
|
189
|
-
|
|
190
|
-
__wbg_init_memory(imports);
|
|
191
|
-
|
|
192
191
|
if (!(module instanceof WebAssembly.Module)) {
|
|
193
192
|
module = new WebAssembly.Module(module);
|
|
194
193
|
}
|
|
195
|
-
|
|
196
194
|
const instance = new WebAssembly.Instance(module, imports);
|
|
197
|
-
|
|
198
195
|
return __wbg_finalize_init(instance, module);
|
|
199
196
|
}
|
|
200
197
|
|
|
@@ -219,8 +216,6 @@ async function __wbg_init(module_or_path) {
|
|
|
219
216
|
module_or_path = fetch(module_or_path);
|
|
220
217
|
}
|
|
221
218
|
|
|
222
|
-
__wbg_init_memory(imports);
|
|
223
|
-
|
|
224
219
|
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
225
220
|
|
|
226
221
|
return __wbg_finalize_init(instance, module);
|
package/pkg/oxide_wasm_bg.wasm
CHANGED
|
Binary file
|