@ingcreators/annot-imagequant 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # @ingcreators/annot-imagequant
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - adae49d: Initial public release of `@ingcreators/annot-imagequant` — a small wasm-bindgen wrapper around the upstream [ImageOptim/libimagequant](https://github.com/ImageOptim/libimagequant) Rust crate (the same engine pngquant uses). Drives the PNG-8 palette quantization path in Annot's "smart" capture encoder.
8
+
9
+ **License: GPL-3.0-or-later** — inherited from libimagequant. The package is published as an opt-in `optionalDependencies` of `@ingcreators/annot-annotator@0.3.0`; the annotator stays Apache-2.0 and falls back gracefully to PNG-32 / JPEG when this WASM module isn't installed. Consumers who want the smaller PNG-8 output explicitly add this package to their own dependencies and assume the GPL-3.0 obligations that entails.
10
+
11
+ ABI (unchanged since the workspace-internal 0.1.0):
12
+
13
+ ```ts
14
+ import init, { quantize_image } from "@ingcreators/annot-imagequant";
15
+ await init();
16
+ const { palette, indices } = quantize_image(rgba, w, h, /* maxColors */ 256);
17
+ // palette: Uint8Array — flattened RGBA8, length = colorCount * 4
18
+ // indices: Uint8Array — one byte per pixel, index into palette
19
+ ```
20
+
21
+ Build artefacts (`pkg/annot_imagequant.{js,d.ts}` + `_bg.wasm`) are committed to the repo so consumers don't need a Rust toolchain on install. Rebuilds happen only when the upstream `libimagequant-sys` pin moves.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 ingcreators
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # `@ingcreators/annot-imagequant`
2
+
3
+ In-tree wasm-bindgen wrapper around the upstream
4
+ [ImageOptim/libimagequant](https://github.com/ImageOptim/libimagequant)
5
+ Rust crate. Replaces [`@panda-ai/imagequant`](https://www.npmjs.com/package/@panda-ai/imagequant)
6
+ as the WASM-side palette quantizer for Annot's PNG-8 capture pipeline.
7
+
8
+ Why we own the build: see
9
+ [`docs/plans/vendor-libimagequant.md`](../../docs/plans/vendor-libimagequant.md).
10
+
11
+ ## ABI
12
+
13
+ ```ts
14
+ import init, { quantize_image } from "@ingcreators/annot-imagequant";
15
+
16
+ await init();
17
+ const result = quantize_image(rgbaPixels, width, height, 256);
18
+ // result.palette : Uint8Array — flattened RGBA8, length = colorCount * 4
19
+ // result.indices : Uint8Array — one byte per pixel, index into palette
20
+ ```
21
+
22
+ This is the same shape consumed at
23
+ [`packages/core/src/encode/index.ts`](../core/src/encode/index.ts).
24
+ Phase 1 lands the package only; the call-site swap is Phase 4.
25
+
26
+ ## Building the WASM
27
+
28
+ The compiled artefact (`pkg/annot_imagequant_bg.wasm` + JS glue +
29
+ `.d.ts`) is **committed to the repo** so a default `pnpm install` flow
30
+ doesn't require a Rust toolchain. Only contributors editing
31
+ `src/lib.rs` or bumping the pinned crate versions need to rebuild.
32
+
33
+ ### Toolchain
34
+
35
+ | Tool | Pinned version | Install |
36
+ |------|----------------|---------|
37
+ | Rust | stable (any 1.94+) | https://rustup.rs/ |
38
+ | wasm32 target | — | `rustup target add wasm32-unknown-unknown` |
39
+ | wasm-pack | 0.13.1 | `cargo install wasm-pack --version 0.13.1 --locked` |
40
+
41
+ **Canonical build environment is Linux x86_64.** rustc's WASM
42
+ codegen is byte-deterministic on a single host platform but is NOT
43
+ cross-platform: the same source compiled on Windows MSVC vs.
44
+ Linux GNU produces different `.wasm` bytes. The committed
45
+ `pkg/annot_imagequant_bg.wasm` is the Linux output, regenerated by
46
+ the `verify-wasm` CI job on every PR. If you build locally on
47
+ Windows or macOS and the diff fails, do NOT commit your local
48
+ artefact — instead, push the source change and let CI's "Upload
49
+ fresh pkg/ on diff" step expose the canonical Linux bytes as a
50
+ downloadable workflow artefact (`imagequant-fresh-pkg`); download
51
+ that and commit it.
52
+
53
+ ### Commands
54
+
55
+ ```bash
56
+ # Rebuild pkg/ from src/lib.rs.
57
+ pnpm --filter @ingcreators/annot-imagequant build:wasm
58
+
59
+ # Verify the committed pkg/ matches a fresh build (used by CI).
60
+ pnpm --filter @ingcreators/annot-imagequant verify:wasm
61
+ ```
62
+
63
+ `build:wasm` shells out to [`scripts/build-wasm.sh`](./scripts/build-wasm.sh),
64
+ which calls `wasm-pack build --release --target web --locked`. The
65
+ release profile in `Cargo.toml` (`opt-level = "z"`, `lto = true`,
66
+ `codegen-units = 1`, `strip = true`, `panic = "abort"`) is what makes
67
+ the output deterministic across machines that share the same toolchain.
68
+
69
+ ## Version pinning
70
+
71
+ Both Rust deps are pinned **exactly** in [`Cargo.toml`](./Cargo.toml):
72
+
73
+ ```toml
74
+ imagequant = "=4.4.1"
75
+ wasm-bindgen = "=0.2.118"
76
+ js-sys = "=0.3.95"
77
+ ```
78
+
79
+ A bump is a deliberate PR — the whole point of this vendor swap is to
80
+ reject silent supply-chain drift. `Cargo.lock` is committed alongside
81
+ the manifest so `cargo --locked` is byte-equivalent across reviewers.
82
+
83
+ ## Licensing
84
+
85
+ This wrapper is **GPL-3.0-or-later** because the upstream
86
+ [ImageOptim/libimagequant](https://github.com/ImageOptim/libimagequant)
87
+ crate is GPL-3.0-or-later (with a separate commercial licence
88
+ available from the upstream maintainer). The compiled WASM blob in
89
+ `pkg/` inherits that licence.
90
+
91
+ The rest of the Annot project remains Apache-2.0; this is the same
92
+ arrangement as the existing `@panda-ai/imagequant` dependency it
93
+ replaces.
94
+
95
+ ## Audit notes
96
+
97
+ - The JS glue in `pkg/annot_imagequant.js` is generated by
98
+ `wasm-bindgen-cli` (vendored by `wasm-pack`). It contains no
99
+ hand-written code beyond what `wasm-bindgen` emits for the
100
+ `quantize_image` export declared in [`src/lib.rs`](./src/lib.rs).
101
+ - The `.wasm` blob is the linked output of: `imagequant` 4.4.1 +
102
+ `wasm-bindgen` 0.2.118 + `js-sys` 0.3.95 + their transitive deps,
103
+ exactly as enumerated in `Cargo.lock`.
104
+ - Reviewers who want to verify the artefact themselves: install the
105
+ toolchain above, run `bash scripts/verify-wasm.sh`, and diff against
106
+ the committed `pkg/` (the script does this automatically and exits
107
+ non-zero on drift).
108
+ - `pkg/` is NOT shipped to npm — `package.json` is `private: true`
109
+ and only used by the in-repo `workspace:*` consumer in
110
+ [`packages/core`](../core/) (wired in Phase 4).
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@ingcreators/annot-imagequant",
3
+ "version": "0.1.0",
4
+ "description": "In-tree wasm-bindgen wrapper around ImageOptim/libimagequant. Drives the PNG-8 palette quantization in Annot's PNG-8 capture pipeline. GPL-3.0 — installed only when consumers opt into the smart PNG-8 encoder.",
5
+ "license": "GPL-3.0-or-later",
6
+ "author": "ingcreators",
7
+ "homepage": "https://github.com/ingcreators/annot/tree/main/packages/imagequant#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/ingcreators/annot/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ingcreators/annot.git",
14
+ "directory": "packages/imagequant"
15
+ },
16
+ "keywords": [
17
+ "image",
18
+ "quantization",
19
+ "png-8",
20
+ "palette",
21
+ "libimagequant",
22
+ "pngquant",
23
+ "wasm",
24
+ "wasm-bindgen",
25
+ "annot"
26
+ ],
27
+ "type": "module",
28
+ "main": "./pkg/annot_imagequant.js",
29
+ "types": "./pkg/annot_imagequant.d.ts",
30
+ "files": [
31
+ "pkg/annot_imagequant.js",
32
+ "pkg/annot_imagequant.d.ts",
33
+ "pkg/annot_imagequant_bg.wasm",
34
+ "pkg/annot_imagequant_bg.wasm.d.ts",
35
+ "README.md",
36
+ "CHANGELOG.md"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "sideEffects": false,
42
+ "scripts": {
43
+ "build:wasm": "bash scripts/build-wasm.sh",
44
+ "verify:wasm": "bash scripts/verify-wasm.sh"
45
+ }
46
+ }
@@ -0,0 +1,36 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export function quantize_image(rgba: Uint8Array, width: number, height: number, max_colors: number): any;
5
+
6
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
7
+
8
+ export interface InitOutput {
9
+ readonly memory: WebAssembly.Memory;
10
+ readonly quantize_image: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
11
+ readonly __wbindgen_export: (a: number) => void;
12
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
13
+ readonly __wbindgen_export2: (a: number, b: number) => number;
14
+ }
15
+
16
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
17
+
18
+ /**
19
+ * Instantiates the given `module`, which can either be bytes or
20
+ * a precompiled `WebAssembly.Module`.
21
+ *
22
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
23
+ *
24
+ * @returns {InitOutput}
25
+ */
26
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
27
+
28
+ /**
29
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
30
+ * for everything else, calls `WebAssembly.instantiate` directly.
31
+ *
32
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
33
+ *
34
+ * @returns {Promise<InitOutput>}
35
+ */
36
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,242 @@
1
+ /* @ts-self-types="./annot_imagequant.d.ts" */
2
+
3
+ /**
4
+ * @param {Uint8Array} rgba
5
+ * @param {number} width
6
+ * @param {number} height
7
+ * @param {number} max_colors
8
+ * @returns {any}
9
+ */
10
+ export function quantize_image(rgba, width, height, max_colors) {
11
+ try {
12
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
13
+ const ptr0 = passArray8ToWasm0(rgba, wasm.__wbindgen_export2);
14
+ const len0 = WASM_VECTOR_LEN;
15
+ wasm.quantize_image(retptr, ptr0, len0, width, height, max_colors);
16
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
17
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
18
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
19
+ if (r2) {
20
+ throw takeObject(r1);
21
+ }
22
+ return takeObject(r0);
23
+ } finally {
24
+ wasm.__wbindgen_add_to_stack_pointer(16);
25
+ }
26
+ }
27
+ function __wbg_get_imports() {
28
+ const import0 = {
29
+ __proto__: null,
30
+ __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
31
+ throw new Error(getStringFromWasm0(arg0, arg1));
32
+ },
33
+ __wbg_length_9f1775224cf1d815: function(arg0) {
34
+ const ret = getObject(arg0).length;
35
+ return ret;
36
+ },
37
+ __wbg_new_aa8d0fa9762c29bd: function() {
38
+ const ret = new Object();
39
+ return addHeapObject(ret);
40
+ },
41
+ __wbg_new_with_length_8c854e41ea4dae9b: function(arg0) {
42
+ const ret = new Uint8Array(arg0 >>> 0);
43
+ return addHeapObject(ret);
44
+ },
45
+ __wbg_set_022bee52d0b05b19: function() { return handleError(function (arg0, arg1, arg2) {
46
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
47
+ return ret;
48
+ }, arguments); },
49
+ __wbg_set_3d484eb794afec82: function(arg0, arg1, arg2) {
50
+ getObject(arg0).set(getArrayU8FromWasm0(arg1, arg2));
51
+ },
52
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
53
+ // Cast intrinsic for `Ref(String) -> Externref`.
54
+ const ret = getStringFromWasm0(arg0, arg1);
55
+ return addHeapObject(ret);
56
+ },
57
+ __wbindgen_object_drop_ref: function(arg0) {
58
+ takeObject(arg0);
59
+ },
60
+ };
61
+ return {
62
+ __proto__: null,
63
+ "./annot_imagequant_bg.js": import0,
64
+ };
65
+ }
66
+
67
+ function addHeapObject(obj) {
68
+ if (heap_next === heap.length) heap.push(heap.length + 1);
69
+ const idx = heap_next;
70
+ heap_next = heap[idx];
71
+
72
+ heap[idx] = obj;
73
+ return idx;
74
+ }
75
+
76
+ function dropObject(idx) {
77
+ if (idx < 1028) return;
78
+ heap[idx] = heap_next;
79
+ heap_next = idx;
80
+ }
81
+
82
+ function getArrayU8FromWasm0(ptr, len) {
83
+ ptr = ptr >>> 0;
84
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
85
+ }
86
+
87
+ let cachedDataViewMemory0 = null;
88
+ function getDataViewMemory0() {
89
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
90
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
91
+ }
92
+ return cachedDataViewMemory0;
93
+ }
94
+
95
+ function getStringFromWasm0(ptr, len) {
96
+ ptr = ptr >>> 0;
97
+ return decodeText(ptr, len);
98
+ }
99
+
100
+ let cachedUint8ArrayMemory0 = null;
101
+ function getUint8ArrayMemory0() {
102
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
103
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
104
+ }
105
+ return cachedUint8ArrayMemory0;
106
+ }
107
+
108
+ function getObject(idx) { return heap[idx]; }
109
+
110
+ function handleError(f, args) {
111
+ try {
112
+ return f.apply(this, args);
113
+ } catch (e) {
114
+ wasm.__wbindgen_export(addHeapObject(e));
115
+ }
116
+ }
117
+
118
+ let heap = new Array(1024).fill(undefined);
119
+ heap.push(undefined, null, true, false);
120
+
121
+ let heap_next = heap.length;
122
+
123
+ function passArray8ToWasm0(arg, malloc) {
124
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
125
+ getUint8ArrayMemory0().set(arg, ptr / 1);
126
+ WASM_VECTOR_LEN = arg.length;
127
+ return ptr;
128
+ }
129
+
130
+ function takeObject(idx) {
131
+ const ret = getObject(idx);
132
+ dropObject(idx);
133
+ return ret;
134
+ }
135
+
136
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
137
+ cachedTextDecoder.decode();
138
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
139
+ let numBytesDecoded = 0;
140
+ function decodeText(ptr, len) {
141
+ numBytesDecoded += len;
142
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
143
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
144
+ cachedTextDecoder.decode();
145
+ numBytesDecoded = len;
146
+ }
147
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
148
+ }
149
+
150
+ let WASM_VECTOR_LEN = 0;
151
+
152
+ let wasmModule, wasm;
153
+ function __wbg_finalize_init(instance, module) {
154
+ wasm = instance.exports;
155
+ wasmModule = module;
156
+ cachedDataViewMemory0 = null;
157
+ cachedUint8ArrayMemory0 = null;
158
+ return wasm;
159
+ }
160
+
161
+ async function __wbg_load(module, imports) {
162
+ if (typeof Response === 'function' && module instanceof Response) {
163
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
164
+ try {
165
+ return await WebAssembly.instantiateStreaming(module, imports);
166
+ } catch (e) {
167
+ const validResponse = module.ok && expectedResponseType(module.type);
168
+
169
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
170
+ 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);
171
+
172
+ } else { throw e; }
173
+ }
174
+ }
175
+
176
+ const bytes = await module.arrayBuffer();
177
+ return await WebAssembly.instantiate(bytes, imports);
178
+ } else {
179
+ const instance = await WebAssembly.instantiate(module, imports);
180
+
181
+ if (instance instanceof WebAssembly.Instance) {
182
+ return { instance, module };
183
+ } else {
184
+ return instance;
185
+ }
186
+ }
187
+
188
+ function expectedResponseType(type) {
189
+ switch (type) {
190
+ case 'basic': case 'cors': case 'default': return true;
191
+ }
192
+ return false;
193
+ }
194
+ }
195
+
196
+ function initSync(module) {
197
+ if (wasm !== undefined) return wasm;
198
+
199
+
200
+ if (module !== undefined) {
201
+ if (Object.getPrototypeOf(module) === Object.prototype) {
202
+ ({module} = module)
203
+ } else {
204
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
205
+ }
206
+ }
207
+
208
+ const imports = __wbg_get_imports();
209
+ if (!(module instanceof WebAssembly.Module)) {
210
+ module = new WebAssembly.Module(module);
211
+ }
212
+ const instance = new WebAssembly.Instance(module, imports);
213
+ return __wbg_finalize_init(instance, module);
214
+ }
215
+
216
+ async function __wbg_init(module_or_path) {
217
+ if (wasm !== undefined) return wasm;
218
+
219
+
220
+ if (module_or_path !== undefined) {
221
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
222
+ ({module_or_path} = module_or_path)
223
+ } else {
224
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
225
+ }
226
+ }
227
+
228
+ if (module_or_path === undefined) {
229
+ module_or_path = new URL('annot_imagequant_bg.wasm', import.meta.url);
230
+ }
231
+ const imports = __wbg_get_imports();
232
+
233
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
234
+ module_or_path = fetch(module_or_path);
235
+ }
236
+
237
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
238
+
239
+ return __wbg_finalize_init(instance, module);
240
+ }
241
+
242
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,7 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const quantize_image: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
5
+ export const __wbindgen_export: (a: number) => void;
6
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
7
+ export const __wbindgen_export2: (a: number, b: number) => number;