@tonpc64/vixel-wasm 0.0.0-stage → 0.3.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/LICENSE +24 -0
- package/README.md +134 -2
- package/package.json +21 -4
- package/vixel.d.ts +48 -0
- package/vixel.js +284 -0
- package/vixel_bg.wasm +0 -0
- package/vixel_bg.wasm.d.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chanwit Piromplad
|
|
4
|
+
|
|
5
|
+
Bundled Heifer components (heifer, heifer-hevc-dec, and heifer-isobmff) are
|
|
6
|
+
Copyright (c) 2026 heifer contributors and distributed under these MIT terms.
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Process images in the browser with WebAssembly
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use Vixel's WebAssembly module to resize and convert local images in a modern browser. The browser reads the file and runs the transformation locally.
|
|
4
|
+
|
|
5
|
+
## Install with npm
|
|
6
|
+
|
|
7
|
+
Add the published package to your frontend project.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @tonpc64/vixel-wasm
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
In your browser code, initialize the module before calling `resize`. See the example below for reading a file and downloading the result.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import init, { resize } from "@tonpc64/vixel-wasm";
|
|
17
|
+
|
|
18
|
+
await init();
|
|
19
|
+
const output = resize(input, 800, 600, "webp");
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The Vite example builds Vixel from source and runs it in a Web Worker. It previews the original and resized images, supports iPhone HEIC and HEIF files, and loads a separate encoder for lossy WebP. [Live demo](https://tonpc64.github.io/vixel/) · [Run the example locally](https://github.com/TonPC64/vixel/tree/main/examples/wasm-web/)
|
|
23
|
+
|
|
24
|
+
## Get the browser bundle
|
|
25
|
+
|
|
26
|
+
Download and extract `vixel-web.tar.gz`. The `vixel-web/` directory contains the JavaScript module, the `.wasm` binary, and TypeScript declarations. [Download the browser bundle](https://github.com/TonPC64/vixel/releases/latest/download/vixel-web.tar.gz)
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
tar -xzf vixel-web.tar.gz
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To build the same bundle from source, run the following commands from your Vixel checkout.
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
rustup target add wasm32-unknown-unknown
|
|
36
|
+
cargo install --locked wasm-bindgen-cli --version "$(cargo pkgid --locked wasm-bindgen | sed 's/.*@//')"
|
|
37
|
+
make wasm
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The build writes the bundle to `target/vixel-web/`. Copy that directory alongside your web page.
|
|
41
|
+
|
|
42
|
+
## Resize a file in the browser
|
|
43
|
+
|
|
44
|
+
Save this page as `index.html` next to the `vixel-web/` directory.
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<!doctype html>
|
|
48
|
+
<html lang="en">
|
|
49
|
+
<meta charset="utf-8">
|
|
50
|
+
<title>Vixel thumbnail</title>
|
|
51
|
+
<label>Choose an image <input id="image" type="file" accept="image/*" disabled></label>
|
|
52
|
+
<p id="status" role="status">Loading Vixel…</p>
|
|
53
|
+
<a id="download" download="thumbnail.webp" hidden>Download thumbnail</a>
|
|
54
|
+
|
|
55
|
+
<script type="module">
|
|
56
|
+
import init, { resize } from "./vixel-web/vixel.js";
|
|
57
|
+
|
|
58
|
+
const picker = document.querySelector("#image");
|
|
59
|
+
const status = document.querySelector("#status");
|
|
60
|
+
const download = document.querySelector("#download");
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await init();
|
|
64
|
+
picker.disabled = false;
|
|
65
|
+
status.textContent = "Choose an image to resize.";
|
|
66
|
+
} catch (error) {
|
|
67
|
+
status.textContent = error.message;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
picker.addEventListener("change", async () => {
|
|
71
|
+
const file = picker.files[0];
|
|
72
|
+
if (!file) return;
|
|
73
|
+
|
|
74
|
+
picker.disabled = true;
|
|
75
|
+
download.hidden = true;
|
|
76
|
+
if (download.hasAttribute("href")) {
|
|
77
|
+
URL.revokeObjectURL(download.href);
|
|
78
|
+
download.removeAttribute("href");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const input = new Uint8Array(await file.arrayBuffer());
|
|
83
|
+
const output = resize(input, 800, 600, "webp");
|
|
84
|
+
download.href = URL.createObjectURL(new Blob([output], { type: "image/webp" }));
|
|
85
|
+
download.hidden = false;
|
|
86
|
+
status.textContent = "Thumbnail ready.";
|
|
87
|
+
} catch (error) {
|
|
88
|
+
status.textContent = error.message;
|
|
89
|
+
} finally {
|
|
90
|
+
picker.disabled = false;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
</script>
|
|
94
|
+
</html>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Serve the directory over HTTP so the browser can load the JavaScript and WebAssembly files together.
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
python3 -m http.server --bind 127.0.0.1 8000
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Open `http://127.0.0.1:8000`, choose a supported image, and download `thumbnail.webp`. Vixel applies EXIF orientation and fits the image within 800×600 while preserving its aspect ratio. It leaves smaller images at their original size.
|
|
104
|
+
|
|
105
|
+
## Use `resize` in your own page
|
|
106
|
+
|
|
107
|
+
After calling `await init()` once, pass a `Uint8Array` to `resize(input, maxWidth, maxHeight, format, quality?)`. It returns a new `Uint8Array` with the encoded image. Each bound must be an integer from 1 to 8192. For JPEG, the optional quality argument is an integer from 1 to 100 and defaults to 82.
|
|
108
|
+
|
|
109
|
+
The module reads JPEG, PNG, WebP, GIF, TIFF, BMP, and ICO. It writes JPEG, PNG, lossless WebP, GIF, and TIFF. Animated inputs produce a still image. Input limits are 32 MiB, 24 megapixels, and 8192 pixels per side. Run `resize` in a Web Worker to keep the page responsive while processing large files.
|
|
110
|
+
|
|
111
|
+
Version 0.3.0 and newer also accept HEIC and HEIF still-photo bytes directly. Read the selected file with `new Uint8Array(await file.arrayBuffer())` and pass it to `resize` as shown above. For larger images such as 48-megapixel iPhone photos, use the CLI, the server, or the live demo's fallback decoder.
|
|
112
|
+
|
|
113
|
+
## Read source dimensions
|
|
114
|
+
|
|
115
|
+
Version 0.3.0 and newer export `image_dimensions(input)`. It reads the header and returns a `Uint32Array` containing the displayed width and height, including image orientation. It accepts the same input formats and 32 MiB file limit as `resize` and can inspect larger resolutions because it does not decode pixels.
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import init, { image_dimensions } from "./vixel-web/vixel.js";
|
|
119
|
+
|
|
120
|
+
await init();
|
|
121
|
+
const input = new Uint8Array(await file.arrayBuffer());
|
|
122
|
+
const [width, height] = image_dimensions(input);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For additional source metadata, use `vixel img info` or call the server's `/info` endpoint. [CLI metadata](https://github.com/TonPC64/vixel/blob/main/docs/cli.md#inspect-an-image) · [Server metadata](https://github.com/TonPC64/vixel/blob/main/docs/server.md#inspect-image-metadata)
|
|
126
|
+
|
|
127
|
+
## Publish the npm package
|
|
128
|
+
|
|
129
|
+
For the first version, run `make wasm-npm` with the build tools listed above. The command prints the npm tarball filename and uses the Cargo package version. Sign in with `npm login` and publish the tarball. For version `0.3.0`, run the following command.
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
npm publish ./target/tonpc64-vixel-wasm-0.3.0.tgz --access public
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
In the npm package settings, add a GitHub Actions trusted publisher for owner `TonPC64`, repository `vixel`, and workflow `release.yml`. Allow `npm publish` and leave the environment field empty. Subsequent GitHub releases publish the matching version to npm. [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)
|
package/package.json
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonpc64/vixel-wasm",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "Resize and convert images in the browser with Vixel WebAssembly",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./vixel.js",
|
|
6
|
+
"types": "./vixel.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"vixel.js",
|
|
9
|
+
"vixel.d.ts",
|
|
10
|
+
"vixel_bg.wasm",
|
|
11
|
+
"vixel_bg.wasm.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/TonPC64/vixel.git"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org/"
|
|
21
|
+
},
|
|
22
|
+
"version": "0.3.0"
|
|
23
|
+
}
|
package/vixel.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Reads displayed source width and height without decoding the pixels.
|
|
6
|
+
*/
|
|
7
|
+
export function image_dimensions(input: Uint8Array): Uint32Array;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fits an image inside a bounding box without enlargement and encodes it into the requested format.
|
|
11
|
+
*/
|
|
12
|
+
export function resize(input: Uint8Array, max_width: number, max_height: number, format: string, quality?: number | null): Uint8Array;
|
|
13
|
+
|
|
14
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
15
|
+
|
|
16
|
+
export interface InitOutput {
|
|
17
|
+
readonly memory: WebAssembly.Memory;
|
|
18
|
+
readonly image_dimensions: (a: any) => [number, number, number, number];
|
|
19
|
+
readonly resize: (a: any, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
20
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
21
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
22
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
23
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
24
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
25
|
+
readonly __wbindgen_start: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
32
|
+
* a precompiled `WebAssembly.Module`.
|
|
33
|
+
*
|
|
34
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
35
|
+
*
|
|
36
|
+
* @returns {InitOutput}
|
|
37
|
+
*/
|
|
38
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
42
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
43
|
+
*
|
|
44
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
45
|
+
*
|
|
46
|
+
* @returns {Promise<InitOutput>}
|
|
47
|
+
*/
|
|
48
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/vixel.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/* @ts-self-types="./vixel.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads displayed source width and height without decoding the pixels.
|
|
5
|
+
* @param {Uint8Array} input
|
|
6
|
+
* @returns {Uint32Array}
|
|
7
|
+
*/
|
|
8
|
+
export function image_dimensions(input) {
|
|
9
|
+
const ret = wasm.image_dimensions(input);
|
|
10
|
+
if (ret[3]) {
|
|
11
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
12
|
+
}
|
|
13
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
14
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
15
|
+
return v1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Fits an image inside a bounding box without enlargement and encodes it into the requested format.
|
|
20
|
+
* @param {Uint8Array} input
|
|
21
|
+
* @param {number} max_width
|
|
22
|
+
* @param {number} max_height
|
|
23
|
+
* @param {string} format
|
|
24
|
+
* @param {number | null} [quality]
|
|
25
|
+
* @returns {Uint8Array}
|
|
26
|
+
*/
|
|
27
|
+
export function resize(input, max_width, max_height, format, quality) {
|
|
28
|
+
const val2 = +max_width;
|
|
29
|
+
const val3 = +max_height;
|
|
30
|
+
const val4 = +(isLikeNone(quality) ? 0 : quality);
|
|
31
|
+
const ptr0 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
32
|
+
const len0 = WASM_VECTOR_LEN;
|
|
33
|
+
const ret = wasm.resize(input, val2, val3, ptr0, len0, !isLikeNone(quality), val4);
|
|
34
|
+
if (ret[3]) {
|
|
35
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
36
|
+
}
|
|
37
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
38
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
39
|
+
return v5;
|
|
40
|
+
}
|
|
41
|
+
function __wbg_get_imports() {
|
|
42
|
+
const import0 = {
|
|
43
|
+
__proto__: null,
|
|
44
|
+
__wbg_Error_208446807d0d1e30: function(arg0, arg1) {
|
|
45
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
46
|
+
return ret;
|
|
47
|
+
},
|
|
48
|
+
__wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
|
|
49
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
50
|
+
},
|
|
51
|
+
__wbg_length_186163212ffe79c3: function(arg0) {
|
|
52
|
+
const ret = arg0.length;
|
|
53
|
+
return ret;
|
|
54
|
+
},
|
|
55
|
+
__wbg_prototypesetcall_13162965d1fe7aa3: function(arg0, arg1, arg2) {
|
|
56
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
57
|
+
},
|
|
58
|
+
__wbindgen_init_externref_table: function() {
|
|
59
|
+
const table = wasm.__wbindgen_externrefs;
|
|
60
|
+
table.set(0, undefined);
|
|
61
|
+
table.set(1024, undefined);
|
|
62
|
+
table.set(1025, null);
|
|
63
|
+
table.set(1026, true);
|
|
64
|
+
table.set(1027, false);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
__proto__: null,
|
|
69
|
+
"./vixel_bg.js": import0,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
74
|
+
ptr = ptr >>> 0;
|
|
75
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
79
|
+
ptr = ptr >>> 0;
|
|
80
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getStringFromWasm0(ptr, len) {
|
|
84
|
+
ptr = ptr >>> 0;
|
|
85
|
+
return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let cachedUint32ArrayMemory0 = null;
|
|
89
|
+
function getUint32ArrayMemory0() {
|
|
90
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
91
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
92
|
+
}
|
|
93
|
+
return cachedUint32ArrayMemory0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let cachedUint8ArrayMemory0 = null;
|
|
97
|
+
function getUint8ArrayMemory0() {
|
|
98
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
99
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
100
|
+
}
|
|
101
|
+
return cachedUint8ArrayMemory0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isLikeNone(x) {
|
|
105
|
+
return x === undefined || x === null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
109
|
+
if (realloc === undefined) {
|
|
110
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
111
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
112
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
113
|
+
WASM_VECTOR_LEN = buf.length;
|
|
114
|
+
return ptr;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let len = arg.length;
|
|
118
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
119
|
+
|
|
120
|
+
const mem = getUint8ArrayMemory0();
|
|
121
|
+
|
|
122
|
+
let offset = 0;
|
|
123
|
+
|
|
124
|
+
for (; offset < len; offset++) {
|
|
125
|
+
const code = arg.charCodeAt(offset);
|
|
126
|
+
if (code > 0x7F) break;
|
|
127
|
+
mem[ptr + offset] = code;
|
|
128
|
+
}
|
|
129
|
+
if (offset !== len) {
|
|
130
|
+
if (offset !== 0) {
|
|
131
|
+
arg = arg.slice(offset);
|
|
132
|
+
}
|
|
133
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
134
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
135
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
136
|
+
|
|
137
|
+
offset += ret.written;
|
|
138
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
WASM_VECTOR_LEN = offset;
|
|
142
|
+
return ptr;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function takeFromExternrefTable0(idx) {
|
|
146
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
147
|
+
wasm.__externref_table_dealloc(idx);
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
152
|
+
cachedTextDecoder.decode();
|
|
153
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
154
|
+
let numBytesDecoded = 0;
|
|
155
|
+
function decodeText(bytes) {
|
|
156
|
+
numBytesDecoded += bytes.length;
|
|
157
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
158
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
159
|
+
cachedTextDecoder.decode();
|
|
160
|
+
numBytesDecoded = bytes.length;
|
|
161
|
+
}
|
|
162
|
+
return cachedTextDecoder.decode(bytes);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const cachedTextEncoder = new TextEncoder();
|
|
166
|
+
|
|
167
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
168
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
169
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
170
|
+
view.set(buf);
|
|
171
|
+
return {
|
|
172
|
+
read: arg.length,
|
|
173
|
+
written: buf.length
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let WASM_VECTOR_LEN = 0;
|
|
179
|
+
|
|
180
|
+
let wasmModule, wasmInstance, wasm;
|
|
181
|
+
function __wbg_finalize_init(instance, module) {
|
|
182
|
+
wasmInstance = instance;
|
|
183
|
+
wasm = instance.exports;
|
|
184
|
+
wasmModule = module;
|
|
185
|
+
cachedUint32ArrayMemory0 = null;
|
|
186
|
+
cachedUint8ArrayMemory0 = null;
|
|
187
|
+
wasm.__wbindgen_start();
|
|
188
|
+
return wasm;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function __wbg_load(module, imports) {
|
|
192
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
193
|
+
if (!module.ok) {
|
|
194
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
198
|
+
try {
|
|
199
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
const validResponse = expectedResponseType(module.type);
|
|
202
|
+
|
|
203
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
204
|
+
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);
|
|
205
|
+
|
|
206
|
+
} else { throw e; }
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const bytes = await module.arrayBuffer();
|
|
211
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
212
|
+
} else {
|
|
213
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
214
|
+
|
|
215
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
216
|
+
return { instance, module };
|
|
217
|
+
} else {
|
|
218
|
+
return instance;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function expectedResponseType(type) {
|
|
223
|
+
switch (type) {
|
|
224
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
225
|
+
}
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function initSync(module) {
|
|
231
|
+
if (wasm !== undefined) return wasm;
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
if (module !== undefined) {
|
|
235
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
236
|
+
({module} = module)
|
|
237
|
+
} else {
|
|
238
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const imports = __wbg_get_imports();
|
|
243
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
244
|
+
module = new WebAssembly.Module(module);
|
|
245
|
+
}
|
|
246
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
247
|
+
return __wbg_finalize_init(instance, module);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
let __wbg_init_promise;
|
|
251
|
+
async function __wbg_init(module_or_path) {
|
|
252
|
+
if (wasm !== undefined) return wasm;
|
|
253
|
+
if (__wbg_init_promise === undefined) {
|
|
254
|
+
__wbg_init_promise = __wbg_init_once(module_or_path);
|
|
255
|
+
__wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
|
|
256
|
+
}
|
|
257
|
+
return __wbg_init_promise;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async function __wbg_init_once(module_or_path) {
|
|
261
|
+
|
|
262
|
+
if (module_or_path !== undefined) {
|
|
263
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
264
|
+
({module_or_path} = module_or_path)
|
|
265
|
+
} else {
|
|
266
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (module_or_path === undefined) {
|
|
271
|
+
module_or_path = new URL('vixel_bg.wasm', import.meta.url);
|
|
272
|
+
}
|
|
273
|
+
const imports = __wbg_get_imports();
|
|
274
|
+
|
|
275
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
276
|
+
module_or_path = fetch(module_or_path);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
280
|
+
|
|
281
|
+
return __wbg_finalize_init(instance, module);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export { initSync, __wbg_init as default };
|
package/vixel_bg.wasm
ADDED
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const image_dimensions: (a: any) => [number, number, number, number];
|
|
5
|
+
export const resize: (a: any, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
6
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
8
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
9
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
10
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
11
|
+
export const __wbindgen_start: () => void;
|