@esm.sh/oxide-wasm 0.1.3 → 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 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
@@ -1,8 +1,8 @@
1
- import initWasm, { initSync as initWasmSync, extract as wasmExtract} from "./pkg/oxide_wasm.js";
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" || input === "") {
5
- throw new Error("filename is required");
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
  }
@@ -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://") && globalThis.Deno) {
17
- const wasmUrl = new URL("./pkg/oxide_wasm_bg.wasm", importUrl);
18
- const wasmBytes = await Deno.readFile(wasmUrl);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esm.sh/oxide-wasm",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "A wasm build of the tailwindcss oxide",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
package/pkg/oxide_wasm.js CHANGED
@@ -1,28 +1,59 @@
1
- let wasm;
1
+ /* @ts-self-types="./oxide_wasm.d.ts" */
2
2
 
3
- let cachedUint8ArrayMemory0 = null;
4
-
5
- function getUint8ArrayMemory0() {
6
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
7
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
8
- }
9
- return cachedUint8ArrayMemory0;
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;
10
14
  }
11
15
 
12
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
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
+ }
13
39
 
14
- cachedTextDecoder.decode();
40
+ function getArrayJsValueFromWasm0(ptr, len) {
41
+ ptr = ptr >>> 0;
42
+ const mem = getDataViewMemory0();
43
+ const result = [];
44
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
45
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
46
+ }
47
+ wasm.__externref_drop_slice(ptr, len);
48
+ return result;
49
+ }
15
50
 
16
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
17
- let numBytesDecoded = 0;
18
- function decodeText(ptr, len) {
19
- numBytesDecoded += len;
20
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
21
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
22
- cachedTextDecoder.decode();
23
- numBytesDecoded = len;
51
+ let cachedDataViewMemory0 = null;
52
+ function getDataViewMemory0() {
53
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
54
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
24
55
  }
25
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
56
+ return cachedDataViewMemory0;
26
57
  }
27
58
 
28
59
  function getStringFromWasm0(ptr, len) {
@@ -30,23 +61,15 @@ function getStringFromWasm0(ptr, len) {
30
61
  return decodeText(ptr, len);
31
62
  }
32
63
 
33
- let WASM_VECTOR_LEN = 0;
34
-
35
- const cachedTextEncoder = new TextEncoder();
36
-
37
- if (!('encodeInto' in cachedTextEncoder)) {
38
- cachedTextEncoder.encodeInto = function (arg, view) {
39
- const buf = cachedTextEncoder.encode(arg);
40
- view.set(buf);
41
- return {
42
- read: arg.length,
43
- written: buf.length
44
- };
64
+ let cachedUint8ArrayMemory0 = null;
65
+ function getUint8ArrayMemory0() {
66
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
67
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
45
68
  }
69
+ return cachedUint8ArrayMemory0;
46
70
  }
47
71
 
48
72
  function passStringToWasm0(arg, malloc, realloc) {
49
-
50
73
  if (realloc === undefined) {
51
74
  const buf = cachedTextEncoder.encode(arg);
52
75
  const ptr = malloc(buf.length, 1) >>> 0;
@@ -67,7 +90,6 @@ function passStringToWasm0(arg, malloc, realloc) {
67
90
  if (code > 0x7F) break;
68
91
  mem[ptr + offset] = code;
69
92
  }
70
-
71
93
  if (offset !== len) {
72
94
  if (offset !== 0) {
73
95
  arg = arg.slice(offset);
@@ -84,115 +106,85 @@ function passStringToWasm0(arg, malloc, realloc) {
84
106
  return ptr;
85
107
  }
86
108
 
87
- let cachedDataViewMemory0 = null;
88
-
89
- function getDataViewMemory0() {
90
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
91
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
109
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
110
+ cachedTextDecoder.decode();
111
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
112
+ let numBytesDecoded = 0;
113
+ function decodeText(ptr, len) {
114
+ numBytesDecoded += len;
115
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
116
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
117
+ cachedTextDecoder.decode();
118
+ numBytesDecoded = len;
92
119
  }
93
- return cachedDataViewMemory0;
120
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
94
121
  }
95
122
 
96
- function getArrayJsValueFromWasm0(ptr, len) {
97
- ptr = ptr >>> 0;
98
- const mem = getDataViewMemory0();
99
- const result = [];
100
- for (let i = ptr; i < ptr + 4 * len; i += 4) {
101
- result.push(wasm.__wbindgen_export_0.get(mem.getUint32(i, true)));
102
- }
103
- wasm.__externref_drop_slice(ptr, len);
104
- return result;
105
- }
106
- /**
107
- * @param {string} input
108
- * @returns {any[]}
109
- */
110
- export function extract(input) {
111
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
112
- const len0 = WASM_VECTOR_LEN;
113
- const ret = wasm.extract(ptr0, len0);
114
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
115
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
116
- return v2;
123
+ const cachedTextEncoder = new TextEncoder();
124
+
125
+ if (!('encodeInto' in cachedTextEncoder)) {
126
+ cachedTextEncoder.encodeInto = function (arg, view) {
127
+ const buf = cachedTextEncoder.encode(arg);
128
+ view.set(buf);
129
+ return {
130
+ read: arg.length,
131
+ written: buf.length
132
+ };
133
+ };
117
134
  }
118
135
 
119
- const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
136
+ let WASM_VECTOR_LEN = 0;
137
+
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;
146
+ }
120
147
 
121
148
  async function __wbg_load(module, imports) {
122
149
  if (typeof Response === 'function' && module instanceof Response) {
123
150
  if (typeof WebAssembly.instantiateStreaming === 'function') {
124
151
  try {
125
152
  return await WebAssembly.instantiateStreaming(module, imports);
126
-
127
153
  } catch (e) {
128
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
154
+ const validResponse = module.ok && expectedResponseType(module.type);
129
155
 
130
156
  if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
131
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);
132
158
 
133
- } else {
134
- throw e;
135
- }
159
+ } else { throw e; }
136
160
  }
137
161
  }
138
162
 
139
163
  const bytes = await module.arrayBuffer();
140
164
  return await WebAssembly.instantiate(bytes, imports);
141
-
142
165
  } else {
143
166
  const instance = await WebAssembly.instantiate(module, imports);
144
167
 
145
168
  if (instance instanceof WebAssembly.Instance) {
146
169
  return { instance, module };
147
-
148
170
  } else {
149
171
  return instance;
150
172
  }
151
173
  }
152
- }
153
-
154
- function __wbg_get_imports() {
155
- const imports = {};
156
- imports.wbg = {};
157
- imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
158
- // Cast intrinsic for `Ref(String) -> Externref`.
159
- const ret = getStringFromWasm0(arg0, arg1);
160
- return ret;
161
- };
162
- imports.wbg.__wbindgen_init_externref_table = function() {
163
- const table = wasm.__wbindgen_export_0;
164
- const offset = table.grow(4);
165
- table.set(0, undefined);
166
- table.set(offset + 0, undefined);
167
- table.set(offset + 1, null);
168
- table.set(offset + 2, true);
169
- table.set(offset + 3, false);
170
- ;
171
- };
172
-
173
- return imports;
174
- }
175
174
 
176
- function __wbg_init_memory(imports, memory) {
177
-
178
- }
179
-
180
- function __wbg_finalize_init(instance, module) {
181
- wasm = instance.exports;
182
- __wbg_init.__wbindgen_wasm_module = module;
183
- cachedDataViewMemory0 = null;
184
- cachedUint8ArrayMemory0 = null;
185
-
186
-
187
- wasm.__wbindgen_start();
188
- return wasm;
175
+ function expectedResponseType(type) {
176
+ switch (type) {
177
+ case 'basic': case 'cors': case 'default': return true;
178
+ }
179
+ return false;
180
+ }
189
181
  }
190
182
 
191
183
  function initSync(module) {
192
184
  if (wasm !== undefined) return wasm;
193
185
 
194
186
 
195
- if (typeof module !== 'undefined') {
187
+ if (module !== undefined) {
196
188
  if (Object.getPrototypeOf(module) === Object.prototype) {
197
189
  ({module} = module)
198
190
  } else {
@@ -201,15 +193,10 @@ function initSync(module) {
201
193
  }
202
194
 
203
195
  const imports = __wbg_get_imports();
204
-
205
- __wbg_init_memory(imports);
206
-
207
196
  if (!(module instanceof WebAssembly.Module)) {
208
197
  module = new WebAssembly.Module(module);
209
198
  }
210
-
211
199
  const instance = new WebAssembly.Instance(module, imports);
212
-
213
200
  return __wbg_finalize_init(instance, module);
214
201
  }
215
202
 
@@ -217,7 +204,7 @@ async function __wbg_init(module_or_path) {
217
204
  if (wasm !== undefined) return wasm;
218
205
 
219
206
 
220
- if (typeof module_or_path !== 'undefined') {
207
+ if (module_or_path !== undefined) {
221
208
  if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
222
209
  ({module_or_path} = module_or_path)
223
210
  } else {
@@ -225,7 +212,7 @@ async function __wbg_init(module_or_path) {
225
212
  }
226
213
  }
227
214
 
228
- if (typeof module_or_path === 'undefined') {
215
+ if (module_or_path === undefined) {
229
216
  module_or_path = new URL('oxide_wasm_bg.wasm', import.meta.url);
230
217
  }
231
218
  const imports = __wbg_get_imports();
@@ -234,12 +221,9 @@ async function __wbg_init(module_or_path) {
234
221
  module_or_path = fetch(module_or_path);
235
222
  }
236
223
 
237
- __wbg_init_memory(imports);
238
-
239
224
  const { instance, module } = await __wbg_load(await module_or_path, imports);
240
225
 
241
226
  return __wbg_finalize_init(instance, module);
242
227
  }
243
228
 
244
- export { initSync };
245
- export default __wbg_init;
229
+ export { initSync, __wbg_init as default };
Binary file