1 |
|
2 | let wasm;
|
3 |
|
4 | const heap = new Array(32).fill(undefined);
|
5 |
|
6 | heap.push(undefined, null, true, false);
|
7 |
|
8 | function getObject(idx) { return heap[idx]; }
|
9 |
|
10 | let heap_next = heap.length;
|
11 |
|
12 | function dropObject(idx) {
|
13 | if (idx < 36) return;
|
14 | heap[idx] = heap_next;
|
15 | heap_next = idx;
|
16 | }
|
17 |
|
18 | function takeObject(idx) {
|
19 | const ret = getObject(idx);
|
20 | dropObject(idx);
|
21 | return ret;
|
22 | }
|
23 |
|
24 | function addHeapObject(obj) {
|
25 | if (heap_next === heap.length) heap.push(heap.length + 1);
|
26 | const idx = heap_next;
|
27 | heap_next = heap[idx];
|
28 |
|
29 | heap[idx] = obj;
|
30 | return idx;
|
31 | }
|
32 |
|
33 | const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
34 |
|
35 | cachedTextDecoder.decode();
|
36 |
|
37 | let cachegetUint8Memory0 = null;
|
38 | function getUint8Memory0() {
|
39 | if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
|
40 | cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
41 | }
|
42 | return cachegetUint8Memory0;
|
43 | }
|
44 |
|
45 | function getStringFromWasm0(ptr, len) {
|
46 | return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
47 | }
|
48 |
|
49 | let WASM_VECTOR_LEN = 0;
|
50 |
|
51 | function passArray8ToWasm0(arg, malloc) {
|
52 | const ptr = malloc(arg.length * 1);
|
53 | getUint8Memory0().set(arg, ptr / 1);
|
54 | WASM_VECTOR_LEN = arg.length;
|
55 | return ptr;
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | export function get_color_thief(colors, pixel_count, quality, colors_count) {
|
65 | const ptr0 = passArray8ToWasm0(colors, wasm.__wbindgen_malloc);
|
66 | const len0 = WASM_VECTOR_LEN;
|
67 | const ret = wasm.get_color_thief(ptr0, len0, pixel_count, quality, colors_count);
|
68 | return takeObject(ret);
|
69 | }
|
70 |
|
71 | const cachedTextEncoder = new TextEncoder('utf-8');
|
72 |
|
73 | const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
74 | ? function (arg, view) {
|
75 | return cachedTextEncoder.encodeInto(arg, view);
|
76 | }
|
77 | : function (arg, view) {
|
78 | const buf = cachedTextEncoder.encode(arg);
|
79 | view.set(buf);
|
80 | return {
|
81 | read: arg.length,
|
82 | written: buf.length
|
83 | };
|
84 | });
|
85 |
|
86 | function passStringToWasm0(arg, malloc, realloc) {
|
87 |
|
88 | if (realloc === undefined) {
|
89 | const buf = cachedTextEncoder.encode(arg);
|
90 | const ptr = malloc(buf.length);
|
91 | getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
92 | WASM_VECTOR_LEN = buf.length;
|
93 | return ptr;
|
94 | }
|
95 |
|
96 | let len = arg.length;
|
97 | let ptr = malloc(len);
|
98 |
|
99 | const mem = getUint8Memory0();
|
100 |
|
101 | let offset = 0;
|
102 |
|
103 | for (; offset < len; offset++) {
|
104 | const code = arg.charCodeAt(offset);
|
105 | if (code > 0x7F) break;
|
106 | mem[ptr + offset] = code;
|
107 | }
|
108 |
|
109 | if (offset !== len) {
|
110 | if (offset !== 0) {
|
111 | arg = arg.slice(offset);
|
112 | }
|
113 | ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
114 | const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
115 | const ret = encodeString(arg, view);
|
116 |
|
117 | offset += ret.written;
|
118 | }
|
119 |
|
120 | WASM_VECTOR_LEN = offset;
|
121 | return ptr;
|
122 | }
|
123 |
|
124 | let cachegetInt32Memory0 = null;
|
125 | function getInt32Memory0() {
|
126 | if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
127 | cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
128 | }
|
129 | return cachegetInt32Memory0;
|
130 | }
|
131 |
|
132 | async function load(module, imports) {
|
133 | if (typeof Response === 'function' && module instanceof Response) {
|
134 | if (typeof WebAssembly.instantiateStreaming === 'function') {
|
135 | try {
|
136 | return await WebAssembly.instantiateStreaming(module, imports);
|
137 |
|
138 | } catch (e) {
|
139 | if (module.headers.get('Content-Type') != 'application/wasm') {
|
140 | 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);
|
141 |
|
142 | } else {
|
143 | throw e;
|
144 | }
|
145 | }
|
146 | }
|
147 |
|
148 | const bytes = await module.arrayBuffer();
|
149 | return await WebAssembly.instantiate(bytes, imports);
|
150 |
|
151 | } else {
|
152 | const instance = await WebAssembly.instantiate(module, imports);
|
153 |
|
154 | if (instance instanceof WebAssembly.Instance) {
|
155 | return { instance, module };
|
156 |
|
157 | } else {
|
158 | return instance;
|
159 | }
|
160 | }
|
161 | }
|
162 |
|
163 | async function init(input) {
|
164 | if (typeof input === 'undefined') {
|
165 | input = new URL('color_thief_wasm_bg.wasm', import.meta.url);
|
166 | }
|
167 | const imports = {};
|
168 | imports.wbg = {};
|
169 | imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
170 | takeObject(arg0);
|
171 | };
|
172 | imports.wbg.__wbindgen_number_new = function(arg0) {
|
173 | const ret = arg0;
|
174 | return addHeapObject(ret);
|
175 | };
|
176 | imports.wbg.__wbg_new_693216e109162396 = function() {
|
177 | const ret = new Error();
|
178 | return addHeapObject(ret);
|
179 | };
|
180 | imports.wbg.__wbg_stack_0ddaca5d1abfb52f = function(arg0, arg1) {
|
181 | const ret = getObject(arg1).stack;
|
182 | const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
183 | const len0 = WASM_VECTOR_LEN;
|
184 | getInt32Memory0()[arg0 / 4 + 1] = len0;
|
185 | getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
186 | };
|
187 | imports.wbg.__wbg_error_09919627ac0992f5 = function(arg0, arg1) {
|
188 | try {
|
189 | console.error(getStringFromWasm0(arg0, arg1));
|
190 | } finally {
|
191 | wasm.__wbindgen_free(arg0, arg1);
|
192 | }
|
193 | };
|
194 | imports.wbg.__wbg_new_94fb1279cf6afea5 = function() {
|
195 | const ret = new Array();
|
196 | return addHeapObject(ret);
|
197 | };
|
198 | imports.wbg.__wbg_push_40c6a90f1805aa90 = function(arg0, arg1) {
|
199 | const ret = getObject(arg0).push(getObject(arg1));
|
200 | return ret;
|
201 | };
|
202 | imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
203 | throw new Error(getStringFromWasm0(arg0, arg1));
|
204 | };
|
205 |
|
206 | if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
207 | input = fetch(input);
|
208 | }
|
209 |
|
210 |
|
211 |
|
212 | const { instance, module } = await load(await input, imports);
|
213 |
|
214 | wasm = instance.exports;
|
215 | init.__wbindgen_wasm_module = module;
|
216 |
|
217 | return wasm;
|
218 | }
|
219 |
|
220 | export default init;
|
221 |
|