@ascii-web/wasm 0.9.0 → 0.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ascii-web/wasm",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "WASM core for ascii-web: converts raw pixel data to ASCII art",
5
5
  "author": "Raffaele Cataldo",
6
6
  "license": "MIT OR Apache-2.0",
@@ -18,6 +18,6 @@
18
18
  "pkg-node/"
19
19
  ],
20
20
  "scripts": {
21
- "build": "wasm-pack build --target web --no-pack && wasm-pack build --target nodejs --out-dir pkg-node --no-pack"
21
+ "build": "wasm-pack build --target web --no-pack && wasm-pack build --target nodejs --out-dir pkg-node --no-pack && rm -f pkg/.gitignore pkg-node/.gitignore"
22
22
  }
23
23
  }
@@ -0,0 +1,37 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function ascii_art(img_bytes: Uint8Array | number[], width: number, height: number, cols: number, rows: number): string;
5
+
6
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
7
+
8
+ export interface InitOutput {
9
+ readonly memory: WebAssembly.Memory;
10
+ readonly ascii_art: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
11
+ readonly __wbindgen_externrefs: WebAssembly.Table;
12
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
13
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
14
+ readonly __wbindgen_start: () => void;
15
+ }
16
+
17
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
18
+
19
+ /**
20
+ * Instantiates the given `module`, which can either be bytes or
21
+ * a precompiled `WebAssembly.Module`.
22
+ *
23
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
24
+ *
25
+ * @returns {InitOutput}
26
+ */
27
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
28
+
29
+ /**
30
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
31
+ * for everything else, calls `WebAssembly.instantiate` directly.
32
+ *
33
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
34
+ *
35
+ * @returns {Promise<InitOutput>}
36
+ */
37
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,186 @@
1
+ /* @ts-self-types="./ascii_web.d.ts" */
2
+
3
+ /**
4
+ * @param {Uint8Array | number[]} img_bytes
5
+ * @param {number} width
6
+ * @param {number} height
7
+ * @param {number} cols
8
+ * @param {number} rows
9
+ * @returns {string}
10
+ */
11
+ export function ascii_art(img_bytes, width, height, cols, rows) {
12
+ let deferred6_0;
13
+ let deferred6_1;
14
+ try {
15
+ const val2 = +width;
16
+ const val3 = +height;
17
+ const val4 = +cols;
18
+ const val5 = +rows;
19
+ const ptr0 = passArray8ToWasm0(img_bytes, wasm.__wbindgen_malloc);
20
+ const len0 = WASM_VECTOR_LEN;
21
+ const ret = wasm.ascii_art(ptr0, len0, val2, val3, val4, val5);
22
+ deferred6_0 = ret[0];
23
+ deferred6_1 = ret[1];
24
+ return getStringFromWasm0(ret[0], ret[1]);
25
+ } finally {
26
+ wasm.__wbindgen_free(deferred6_0, deferred6_1, 1);
27
+ }
28
+ }
29
+ function __wbg_get_imports() {
30
+ const import0 = {
31
+ __proto__: null,
32
+ __wbindgen_init_externref_table: function() {
33
+ const table = wasm.__wbindgen_externrefs;
34
+ table.set(0, undefined);
35
+ table.set(1024, undefined);
36
+ table.set(1025, null);
37
+ table.set(1026, true);
38
+ table.set(1027, false);
39
+ },
40
+ };
41
+ return {
42
+ __proto__: null,
43
+ "./ascii_web_bg.js": import0,
44
+ };
45
+ }
46
+
47
+ function getStringFromWasm0(ptr, len) {
48
+ ptr = ptr >>> 0;
49
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
50
+ }
51
+
52
+ let cachedUint8ArrayMemory0 = null;
53
+ function getUint8ArrayMemory0() {
54
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
55
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
56
+ }
57
+ return cachedUint8ArrayMemory0;
58
+ }
59
+
60
+ function passArray8ToWasm0(arg, malloc) {
61
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
62
+ getUint8ArrayMemory0().set(arg, ptr / 1);
63
+ WASM_VECTOR_LEN = arg.length;
64
+ return ptr;
65
+ }
66
+
67
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
68
+ cachedTextDecoder.decode();
69
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
70
+ let numBytesDecoded = 0;
71
+ function decodeText(bytes) {
72
+ numBytesDecoded += bytes.length;
73
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
74
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
75
+ cachedTextDecoder.decode();
76
+ numBytesDecoded = bytes.length;
77
+ }
78
+ return cachedTextDecoder.decode(bytes);
79
+ }
80
+
81
+ let WASM_VECTOR_LEN = 0;
82
+
83
+ let wasmModule, wasmInstance, wasm;
84
+ function __wbg_finalize_init(instance, module) {
85
+ wasmInstance = instance;
86
+ wasm = instance.exports;
87
+ wasmModule = module;
88
+ cachedUint8ArrayMemory0 = null;
89
+ wasm.__wbindgen_start();
90
+ return wasm;
91
+ }
92
+
93
+ async function __wbg_load(module, imports) {
94
+ if (typeof Response === 'function' && module instanceof Response) {
95
+ if (!module.ok) {
96
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
97
+ }
98
+
99
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
100
+ try {
101
+ return await WebAssembly.instantiateStreaming(module, imports);
102
+ } catch (e) {
103
+ const validResponse = expectedResponseType(module.type);
104
+
105
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
106
+ 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);
107
+
108
+ } else { throw e; }
109
+ }
110
+ }
111
+
112
+ const bytes = await module.arrayBuffer();
113
+ return await WebAssembly.instantiate(bytes, imports);
114
+ } else {
115
+ const instance = await WebAssembly.instantiate(module, imports);
116
+
117
+ if (instance instanceof WebAssembly.Instance) {
118
+ return { instance, module };
119
+ } else {
120
+ return instance;
121
+ }
122
+ }
123
+
124
+ function expectedResponseType(type) {
125
+ switch (type) {
126
+ case 'basic': case 'cors': case 'default': return true;
127
+ }
128
+ return false;
129
+ }
130
+ }
131
+
132
+ function initSync(module) {
133
+ if (wasm !== undefined) return wasm;
134
+
135
+
136
+ if (module !== undefined) {
137
+ if (Object.getPrototypeOf(module) === Object.prototype) {
138
+ ({module} = module)
139
+ } else {
140
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
141
+ }
142
+ }
143
+
144
+ const imports = __wbg_get_imports();
145
+ if (!(module instanceof WebAssembly.Module)) {
146
+ module = new WebAssembly.Module(module);
147
+ }
148
+ const instance = new WebAssembly.Instance(module, imports);
149
+ return __wbg_finalize_init(instance, module);
150
+ }
151
+
152
+ let __wbg_init_promise;
153
+ async function __wbg_init(module_or_path) {
154
+ if (wasm !== undefined) return wasm;
155
+ if (__wbg_init_promise === undefined) {
156
+ __wbg_init_promise = __wbg_init_once(module_or_path);
157
+ __wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
158
+ }
159
+ return __wbg_init_promise;
160
+ }
161
+
162
+ async function __wbg_init_once(module_or_path) {
163
+
164
+ if (module_or_path !== undefined) {
165
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
166
+ ({module_or_path} = module_or_path)
167
+ } else {
168
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
169
+ }
170
+ }
171
+
172
+ if (module_or_path === undefined) {
173
+ module_or_path = new URL('ascii_web_bg.wasm', import.meta.url);
174
+ }
175
+ const imports = __wbg_get_imports();
176
+
177
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
178
+ module_or_path = fetch(module_or_path);
179
+ }
180
+
181
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
182
+
183
+ return __wbg_finalize_init(instance, module);
184
+ }
185
+
186
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,8 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const ascii_art: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
5
+ export const __wbindgen_externrefs: WebAssembly.Table;
6
+ export const __wbindgen_malloc: (a: number, b: number) => number;
7
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
8
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,4 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function ascii_art(img_bytes: Uint8Array | number[], width: number, height: number, cols: number, rows: number): string;
@@ -0,0 +1,81 @@
1
+ /* @ts-self-types="./ascii_web.d.ts" */
2
+
3
+ /**
4
+ * @param {Uint8Array | number[]} img_bytes
5
+ * @param {number} width
6
+ * @param {number} height
7
+ * @param {number} cols
8
+ * @param {number} rows
9
+ * @returns {string}
10
+ */
11
+ function ascii_art(img_bytes, width, height, cols, rows) {
12
+ let deferred6_0;
13
+ let deferred6_1;
14
+ try {
15
+ const val2 = +width;
16
+ const val3 = +height;
17
+ const val4 = +cols;
18
+ const val5 = +rows;
19
+ const ptr0 = passArray8ToWasm0(img_bytes, wasm.__wbindgen_malloc);
20
+ const len0 = WASM_VECTOR_LEN;
21
+ const ret = wasm.ascii_art(ptr0, len0, val2, val3, val4, val5);
22
+ deferred6_0 = ret[0];
23
+ deferred6_1 = ret[1];
24
+ return getStringFromWasm0(ret[0], ret[1]);
25
+ } finally {
26
+ wasm.__wbindgen_free(deferred6_0, deferred6_1, 1);
27
+ }
28
+ }
29
+ exports.ascii_art = ascii_art;
30
+ function __wbg_get_imports() {
31
+ const import0 = {
32
+ __proto__: null,
33
+ __wbindgen_init_externref_table: function() {
34
+ const table = wasm.__wbindgen_externrefs;
35
+ table.set(0, undefined);
36
+ table.set(1024, undefined);
37
+ table.set(1025, null);
38
+ table.set(1026, true);
39
+ table.set(1027, false);
40
+ },
41
+ };
42
+ return {
43
+ __proto__: null,
44
+ "./ascii_web_bg.js": import0,
45
+ };
46
+ }
47
+
48
+ function getStringFromWasm0(ptr, len) {
49
+ ptr = ptr >>> 0;
50
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
51
+ }
52
+
53
+ let cachedUint8ArrayMemory0 = null;
54
+ function getUint8ArrayMemory0() {
55
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
56
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
57
+ }
58
+ return cachedUint8ArrayMemory0;
59
+ }
60
+
61
+ function passArray8ToWasm0(arg, malloc) {
62
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
63
+ getUint8ArrayMemory0().set(arg, ptr / 1);
64
+ WASM_VECTOR_LEN = arg.length;
65
+ return ptr;
66
+ }
67
+
68
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
69
+ cachedTextDecoder.decode();
70
+ function decodeText(bytes) {
71
+ return cachedTextDecoder.decode(bytes);
72
+ }
73
+
74
+ let WASM_VECTOR_LEN = 0;
75
+
76
+ const wasmPath = `${__dirname}/ascii_web_bg.wasm`;
77
+ const wasmBytes = require('fs').readFileSync(wasmPath);
78
+ const wasmModule = new WebAssembly.Module(wasmBytes);
79
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
80
+ let wasm = wasmInstance.exports;
81
+ wasm.__wbindgen_start();
Binary file
@@ -0,0 +1,8 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const ascii_art: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
5
+ export const __wbindgen_externrefs: WebAssembly.Table;
6
+ export const __wbindgen_malloc: (a: number, b: number) => number;
7
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
8
+ export const __wbindgen_start: () => void;