@u1f992/pdfdiff 0.2.0 → 0.2.2
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/.github/workflows/gh-pages.yml +6 -1
- package/dist/browser.js +1219 -19
- package/dist/browser.js.map +1 -1
- package/dist/cli-png-worker.d.ts +13 -0
- package/dist/cli-png-worker.d.ts.map +1 -0
- package/dist/cli-png-worker.js +303 -0
- package/dist/cli-png-worker.js.map +1 -0
- package/dist/cli.js +240 -26
- package/dist/cli.js.map +1 -1
- package/dist/diff.d.ts +2 -1
- package/dist/diff.d.ts.map +1 -1
- package/dist/image.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.html +6 -1
- package/dist/index.js +123 -15
- package/dist/index.js.map +1 -1
- package/dist/pdf.d.ts.map +1 -1
- package/dist/perf.d.ts +16 -0
- package/dist/perf.d.ts.map +1 -0
- package/dist/squoosh_png_bg.wasm +0 -0
- package/dist/style.css +12 -0
- package/dist/transferable.d.ts +7 -0
- package/dist/transferable.d.ts.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/worker.d.ts +9 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +274 -88
- package/dist/worker.js.map +1 -1
- package/package.json +5 -2
- package/rollup.config.js +20 -0
- package/scripts/version.ts +35 -0
- package/src/browser.ts +119 -5
- package/src/cli-png-worker.ts +59 -0
- package/src/cli.ts +106 -21
- package/src/diff.ts +99 -34
- package/src/image.ts +3 -0
- package/src/index.html +6 -1
- package/src/index.ts +53 -27
- package/src/pdf.ts +9 -1
- package/src/perf.ts +94 -0
- package/src/style.css +12 -0
- package/src/transferable.ts +30 -0
- package/src/worker.ts +77 -54
package/dist/browser.js
CHANGED
|
@@ -1,3 +1,1006 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
const heap = new Array(128).fill(undefined);
|
|
4
|
+
|
|
5
|
+
heap.push(undefined, null, true, false);
|
|
6
|
+
|
|
7
|
+
let heap_next = heap.length;
|
|
8
|
+
|
|
9
|
+
function addHeapObject(obj) {
|
|
10
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
11
|
+
const idx = heap_next;
|
|
12
|
+
heap_next = heap[idx];
|
|
13
|
+
|
|
14
|
+
heap[idx] = obj;
|
|
15
|
+
return idx;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getObject(idx) { return heap[idx]; }
|
|
19
|
+
|
|
20
|
+
function dropObject(idx) {
|
|
21
|
+
if (idx < 132) return;
|
|
22
|
+
heap[idx] = heap_next;
|
|
23
|
+
heap_next = idx;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function takeObject(idx) {
|
|
27
|
+
const ret = getObject(idx);
|
|
28
|
+
dropObject(idx);
|
|
29
|
+
return ret;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
33
|
+
|
|
34
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }
|
|
35
|
+
let cachedUint8Memory0 = null;
|
|
36
|
+
|
|
37
|
+
function getUint8Memory0() {
|
|
38
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
39
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
40
|
+
}
|
|
41
|
+
return cachedUint8Memory0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getStringFromWasm0(ptr, len) {
|
|
45
|
+
ptr = ptr >>> 0;
|
|
46
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let cachedUint8ClampedMemory0 = null;
|
|
50
|
+
|
|
51
|
+
function getUint8ClampedMemory0() {
|
|
52
|
+
if (cachedUint8ClampedMemory0 === null || cachedUint8ClampedMemory0.byteLength === 0) {
|
|
53
|
+
cachedUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
|
|
54
|
+
}
|
|
55
|
+
return cachedUint8ClampedMemory0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getClampedArrayU8FromWasm0(ptr, len) {
|
|
59
|
+
ptr = ptr >>> 0;
|
|
60
|
+
return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let WASM_VECTOR_LEN = 0;
|
|
64
|
+
|
|
65
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
66
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
67
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
68
|
+
WASM_VECTOR_LEN = arg.length;
|
|
69
|
+
return ptr;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let cachedInt32Memory0 = null;
|
|
73
|
+
|
|
74
|
+
function getInt32Memory0() {
|
|
75
|
+
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
|
|
76
|
+
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
77
|
+
}
|
|
78
|
+
return cachedInt32Memory0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
82
|
+
ptr = ptr >>> 0;
|
|
83
|
+
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @param {Uint8Array} data
|
|
87
|
+
* @param {number} width
|
|
88
|
+
* @param {number} height
|
|
89
|
+
* @param {number} bit_depth
|
|
90
|
+
* @returns {Uint8Array}
|
|
91
|
+
*/
|
|
92
|
+
function encode$4(data, width, height, bit_depth) {
|
|
93
|
+
try {
|
|
94
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
95
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
96
|
+
const len0 = WASM_VECTOR_LEN;
|
|
97
|
+
wasm.encode(retptr, ptr0, len0, width, height, bit_depth);
|
|
98
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
99
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
100
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
101
|
+
wasm.__wbindgen_free(r0, r1 * 1, 1);
|
|
102
|
+
return v2;
|
|
103
|
+
} finally {
|
|
104
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function __wbg_load(module, imports) {
|
|
109
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
110
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
111
|
+
try {
|
|
112
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
113
|
+
|
|
114
|
+
} catch (e) {
|
|
115
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
116
|
+
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);
|
|
117
|
+
|
|
118
|
+
} else {
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const bytes = await module.arrayBuffer();
|
|
125
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
126
|
+
|
|
127
|
+
} else {
|
|
128
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
129
|
+
|
|
130
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
131
|
+
return { instance, module };
|
|
132
|
+
|
|
133
|
+
} else {
|
|
134
|
+
return instance;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function __wbg_get_imports() {
|
|
140
|
+
const imports = {};
|
|
141
|
+
imports.wbg = {};
|
|
142
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
143
|
+
const ret = wasm.memory;
|
|
144
|
+
return addHeapObject(ret);
|
|
145
|
+
};
|
|
146
|
+
imports.wbg.__wbg_buffer_a448f833075b71ba = function(arg0) {
|
|
147
|
+
const ret = getObject(arg0).buffer;
|
|
148
|
+
return addHeapObject(ret);
|
|
149
|
+
};
|
|
150
|
+
imports.wbg.__wbg_newwithbyteoffsetandlength_099217381c451830 = function(arg0, arg1, arg2) {
|
|
151
|
+
const ret = new Uint16Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
|
152
|
+
return addHeapObject(ret);
|
|
153
|
+
};
|
|
154
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
155
|
+
takeObject(arg0);
|
|
156
|
+
};
|
|
157
|
+
imports.wbg.__wbg_newwithownedu8clampedarrayandsh_91db5987993a08fb = function(arg0, arg1, arg2, arg3) {
|
|
158
|
+
var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
|
|
159
|
+
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
|
|
160
|
+
const ret = new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
|
|
161
|
+
return addHeapObject(ret);
|
|
162
|
+
};
|
|
163
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
164
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
return imports;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function __wbg_finalize_init(instance, module) {
|
|
171
|
+
wasm = instance.exports;
|
|
172
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
173
|
+
cachedInt32Memory0 = null;
|
|
174
|
+
cachedUint8Memory0 = null;
|
|
175
|
+
cachedUint8ClampedMemory0 = null;
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
return wasm;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function __wbg_init(input) {
|
|
182
|
+
if (wasm !== undefined) return wasm;
|
|
183
|
+
|
|
184
|
+
if (typeof input === 'undefined') {
|
|
185
|
+
input = new URL('squoosh_png_bg.wasm', import.meta.url);
|
|
186
|
+
}
|
|
187
|
+
const imports = __wbg_get_imports();
|
|
188
|
+
|
|
189
|
+
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
|
190
|
+
input = fetch(input);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const { instance, module } = await __wbg_load(await input, imports);
|
|
194
|
+
|
|
195
|
+
return __wbg_finalize_init(instance, module);
|
|
196
|
+
}
|
|
197
|
+
const isServiceWorker = globalThis.ServiceWorkerGlobalScope !== undefined;
|
|
198
|
+
const isRunningInCloudFlareWorkers = isServiceWorker && typeof self !== 'undefined' && globalThis.caches && globalThis.caches.default !== undefined;
|
|
199
|
+
const isRunningInNode = typeof process === 'object' && process.release && process.release.name === 'node';
|
|
200
|
+
|
|
201
|
+
if (isRunningInCloudFlareWorkers || isRunningInNode) {
|
|
202
|
+
if (!globalThis.ImageData) {
|
|
203
|
+
// Simple Polyfill for ImageData Object
|
|
204
|
+
globalThis.ImageData = class ImageData {
|
|
205
|
+
constructor(data, width, height) {
|
|
206
|
+
this.data = data;
|
|
207
|
+
this.width = width;
|
|
208
|
+
this.height = height;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (import.meta.url === undefined) {
|
|
214
|
+
import.meta.url = 'https://localhost';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (typeof self !== 'undefined' && self.location === undefined) {
|
|
218
|
+
self.location = { href: '' };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
224
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
225
|
+
* you may not use this file except in compliance with the License.
|
|
226
|
+
* You may obtain a copy of the License at
|
|
227
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
228
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
229
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
230
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
231
|
+
* See the License for the specific language governing permissions and
|
|
232
|
+
* limitations under the License.
|
|
233
|
+
*/
|
|
234
|
+
let pngModule;
|
|
235
|
+
async function init$1(moduleOrPath) {
|
|
236
|
+
if (!pngModule) {
|
|
237
|
+
pngModule = __wbg_init(moduleOrPath);
|
|
238
|
+
}
|
|
239
|
+
return pngModule;
|
|
240
|
+
}
|
|
241
|
+
async function encode$3(data, options = {}) {
|
|
242
|
+
var _a;
|
|
243
|
+
await init$1();
|
|
244
|
+
const bitDepth = (_a = options === null || options === void 0 ? void 0 : options.bitDepth) !== null && _a !== void 0 ? _a : 8;
|
|
245
|
+
if (bitDepth !== 8 && bitDepth !== 16) {
|
|
246
|
+
throw new Error('Invalid bit depth. Must be either 8 or 16.');
|
|
247
|
+
}
|
|
248
|
+
const isUint16Array = data.data instanceof Uint16Array;
|
|
249
|
+
if (isUint16Array && bitDepth !== 16) {
|
|
250
|
+
throw new Error('Invalid bit depth, must be 16 for Uint16Array or manually convert to RGB8 values with Uint8Array.');
|
|
251
|
+
}
|
|
252
|
+
if (!isUint16Array && bitDepth === 16) {
|
|
253
|
+
throw new Error('Invalid bit depth, must be 8 for Uint8Array or manually convert to RGB16 values with Uint16Array.');
|
|
254
|
+
}
|
|
255
|
+
const encodeData = new Uint8Array(data.data.buffer);
|
|
256
|
+
const output = await encode$4(encodeData, data.width, data.height, bitDepth);
|
|
257
|
+
if (!output)
|
|
258
|
+
throw new Error('Encoding error.');
|
|
259
|
+
return output.buffer;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// DEFLATE is a complex format; to read this code, you should probably check the RFC first:
|
|
263
|
+
// https://tools.ietf.org/html/rfc1951
|
|
264
|
+
// You may also wish to take a look at the guide I made about this program:
|
|
265
|
+
// https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad
|
|
266
|
+
// Some of the following code is similar to that of UZIP.js:
|
|
267
|
+
// https://github.com/photopea/UZIP.js
|
|
268
|
+
// However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.
|
|
269
|
+
// Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint
|
|
270
|
+
// is better for memory in most engines (I *think*).
|
|
271
|
+
|
|
272
|
+
// aliases for shorter compressed code (most minifers don't do this)
|
|
273
|
+
var u8 = Uint8Array, u16 = Uint16Array, i32 = Int32Array;
|
|
274
|
+
// fixed length extra bits
|
|
275
|
+
var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);
|
|
276
|
+
// fixed distance extra bits
|
|
277
|
+
var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);
|
|
278
|
+
// code length index map
|
|
279
|
+
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
280
|
+
// get base, reverse index map from extra bits
|
|
281
|
+
var freb = function (eb, start) {
|
|
282
|
+
var b = new u16(31);
|
|
283
|
+
for (var i = 0; i < 31; ++i) {
|
|
284
|
+
b[i] = start += 1 << eb[i - 1];
|
|
285
|
+
}
|
|
286
|
+
// numbers here are at max 18 bits
|
|
287
|
+
var r = new i32(b[30]);
|
|
288
|
+
for (var i = 1; i < 30; ++i) {
|
|
289
|
+
for (var j = b[i]; j < b[i + 1]; ++j) {
|
|
290
|
+
r[j] = ((j - b[i]) << 5) | i;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return { b: b, r: r };
|
|
294
|
+
};
|
|
295
|
+
var _a = freb(fleb, 2), fl = _a.b, revfl = _a.r;
|
|
296
|
+
// we can ignore the fact that the other numbers are wrong; they never happen anyway
|
|
297
|
+
fl[28] = 258, revfl[258] = 28;
|
|
298
|
+
var _b = freb(fdeb, 0), revfd = _b.r;
|
|
299
|
+
// map of value to reverse (assuming 16 bits)
|
|
300
|
+
var rev = new u16(32768);
|
|
301
|
+
for (var i$1 = 0; i$1 < 32768; ++i$1) {
|
|
302
|
+
// reverse table algorithm from SO
|
|
303
|
+
var x$3 = ((i$1 & 0xAAAA) >> 1) | ((i$1 & 0x5555) << 1);
|
|
304
|
+
x$3 = ((x$3 & 0xCCCC) >> 2) | ((x$3 & 0x3333) << 2);
|
|
305
|
+
x$3 = ((x$3 & 0xF0F0) >> 4) | ((x$3 & 0x0F0F) << 4);
|
|
306
|
+
rev[i$1] = (((x$3 & 0xFF00) >> 8) | ((x$3 & 0x00FF) << 8)) >> 1;
|
|
307
|
+
}
|
|
308
|
+
// create huffman tree from u8 "map": index -> code length for code index
|
|
309
|
+
// mb (max bits) must be at most 15
|
|
310
|
+
// TODO: optimize/split up?
|
|
311
|
+
var hMap = (function (cd, mb, r) {
|
|
312
|
+
var s = cd.length;
|
|
313
|
+
// index
|
|
314
|
+
var i = 0;
|
|
315
|
+
// u16 "map": index -> # of codes with bit length = index
|
|
316
|
+
var l = new u16(mb);
|
|
317
|
+
// length of cd must be 288 (total # of codes)
|
|
318
|
+
for (; i < s; ++i) {
|
|
319
|
+
if (cd[i])
|
|
320
|
+
++l[cd[i] - 1];
|
|
321
|
+
}
|
|
322
|
+
// u16 "map": index -> minimum code for bit length = index
|
|
323
|
+
var le = new u16(mb);
|
|
324
|
+
for (i = 1; i < mb; ++i) {
|
|
325
|
+
le[i] = (le[i - 1] + l[i - 1]) << 1;
|
|
326
|
+
}
|
|
327
|
+
var co;
|
|
328
|
+
if (r) {
|
|
329
|
+
// u16 "map": index -> number of actual bits, symbol for code
|
|
330
|
+
co = new u16(1 << mb);
|
|
331
|
+
// bits to remove for reverser
|
|
332
|
+
var rvb = 15 - mb;
|
|
333
|
+
for (i = 0; i < s; ++i) {
|
|
334
|
+
// ignore 0 lengths
|
|
335
|
+
if (cd[i]) {
|
|
336
|
+
// num encoding both symbol and bits read
|
|
337
|
+
var sv = (i << 4) | cd[i];
|
|
338
|
+
// free bits
|
|
339
|
+
var r_1 = mb - cd[i];
|
|
340
|
+
// start value
|
|
341
|
+
var v = le[cd[i] - 1]++ << r_1;
|
|
342
|
+
// m is end value
|
|
343
|
+
for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {
|
|
344
|
+
// every 16 bit value starting with the code yields the same result
|
|
345
|
+
co[rev[v] >> rvb] = sv;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
co = new u16(s);
|
|
352
|
+
for (i = 0; i < s; ++i) {
|
|
353
|
+
if (cd[i]) {
|
|
354
|
+
co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return co;
|
|
359
|
+
});
|
|
360
|
+
// fixed length tree
|
|
361
|
+
var flt = new u8(288);
|
|
362
|
+
for (var i$1 = 0; i$1 < 144; ++i$1)
|
|
363
|
+
flt[i$1] = 8;
|
|
364
|
+
for (var i$1 = 144; i$1 < 256; ++i$1)
|
|
365
|
+
flt[i$1] = 9;
|
|
366
|
+
for (var i$1 = 256; i$1 < 280; ++i$1)
|
|
367
|
+
flt[i$1] = 7;
|
|
368
|
+
for (var i$1 = 280; i$1 < 288; ++i$1)
|
|
369
|
+
flt[i$1] = 8;
|
|
370
|
+
// fixed distance tree
|
|
371
|
+
var fdt = new u8(32);
|
|
372
|
+
for (var i$1 = 0; i$1 < 32; ++i$1)
|
|
373
|
+
fdt[i$1] = 5;
|
|
374
|
+
// fixed length map
|
|
375
|
+
var flm = /*#__PURE__*/ hMap(flt, 9, 0);
|
|
376
|
+
// fixed distance map
|
|
377
|
+
var fdm = /*#__PURE__*/ hMap(fdt, 5, 0);
|
|
378
|
+
// get end of byte
|
|
379
|
+
var shft = function (p) { return ((p + 7) / 8) | 0; };
|
|
380
|
+
// typed array slice - allows garbage collector to free original reference,
|
|
381
|
+
// while being more compatible than .slice
|
|
382
|
+
var slc = function (v, s, e) {
|
|
383
|
+
if (e == null || e > v.length)
|
|
384
|
+
e = v.length;
|
|
385
|
+
// can't use .constructor in case user-supplied
|
|
386
|
+
return new u8(v.subarray(s, e));
|
|
387
|
+
};
|
|
388
|
+
// error codes
|
|
389
|
+
var ec = [
|
|
390
|
+
'unexpected EOF',
|
|
391
|
+
'invalid block type',
|
|
392
|
+
'invalid length/literal',
|
|
393
|
+
'invalid distance',
|
|
394
|
+
'stream finished',
|
|
395
|
+
'no stream handler',
|
|
396
|
+
,
|
|
397
|
+
'no callback',
|
|
398
|
+
'invalid UTF-8 data',
|
|
399
|
+
'extra field too long',
|
|
400
|
+
'date not in range 1980-2099',
|
|
401
|
+
'filename too long',
|
|
402
|
+
'stream finishing',
|
|
403
|
+
'invalid zip data'
|
|
404
|
+
// determined by unknown compression method
|
|
405
|
+
];
|
|
406
|
+
var err = function (ind, msg, nt) {
|
|
407
|
+
var e = new Error(msg || ec[ind]);
|
|
408
|
+
e.code = ind;
|
|
409
|
+
if (Error.captureStackTrace)
|
|
410
|
+
Error.captureStackTrace(e, err);
|
|
411
|
+
if (!nt)
|
|
412
|
+
throw e;
|
|
413
|
+
return e;
|
|
414
|
+
};
|
|
415
|
+
// starting at p, write the minimum number of bits that can hold v to d
|
|
416
|
+
var wbits = function (d, p, v) {
|
|
417
|
+
v <<= p & 7;
|
|
418
|
+
var o = (p / 8) | 0;
|
|
419
|
+
d[o] |= v;
|
|
420
|
+
d[o + 1] |= v >> 8;
|
|
421
|
+
};
|
|
422
|
+
// starting at p, write the minimum number of bits (>8) that can hold v to d
|
|
423
|
+
var wbits16 = function (d, p, v) {
|
|
424
|
+
v <<= p & 7;
|
|
425
|
+
var o = (p / 8) | 0;
|
|
426
|
+
d[o] |= v;
|
|
427
|
+
d[o + 1] |= v >> 8;
|
|
428
|
+
d[o + 2] |= v >> 16;
|
|
429
|
+
};
|
|
430
|
+
// creates code lengths from a frequency table
|
|
431
|
+
var hTree = function (d, mb) {
|
|
432
|
+
// Need extra info to make a tree
|
|
433
|
+
var t = [];
|
|
434
|
+
for (var i = 0; i < d.length; ++i) {
|
|
435
|
+
if (d[i])
|
|
436
|
+
t.push({ s: i, f: d[i] });
|
|
437
|
+
}
|
|
438
|
+
var s = t.length;
|
|
439
|
+
var t2 = t.slice();
|
|
440
|
+
if (!s)
|
|
441
|
+
return { t: et, l: 0 };
|
|
442
|
+
if (s == 1) {
|
|
443
|
+
var v = new u8(t[0].s + 1);
|
|
444
|
+
v[t[0].s] = 1;
|
|
445
|
+
return { t: v, l: 1 };
|
|
446
|
+
}
|
|
447
|
+
t.sort(function (a, b) { return a.f - b.f; });
|
|
448
|
+
// after i2 reaches last ind, will be stopped
|
|
449
|
+
// freq must be greater than largest possible number of symbols
|
|
450
|
+
t.push({ s: -1, f: 25001 });
|
|
451
|
+
var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;
|
|
452
|
+
t[0] = { s: -1, f: l.f + r.f, l: l, r: r };
|
|
453
|
+
// efficient algorithm from UZIP.js
|
|
454
|
+
// i0 is lookbehind, i2 is lookahead - after processing two low-freq
|
|
455
|
+
// symbols that combined have high freq, will start processing i2 (high-freq,
|
|
456
|
+
// non-composite) symbols instead
|
|
457
|
+
// see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/
|
|
458
|
+
while (i1 != s - 1) {
|
|
459
|
+
l = t[t[i0].f < t[i2].f ? i0++ : i2++];
|
|
460
|
+
r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];
|
|
461
|
+
t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };
|
|
462
|
+
}
|
|
463
|
+
var maxSym = t2[0].s;
|
|
464
|
+
for (var i = 1; i < s; ++i) {
|
|
465
|
+
if (t2[i].s > maxSym)
|
|
466
|
+
maxSym = t2[i].s;
|
|
467
|
+
}
|
|
468
|
+
// code lengths
|
|
469
|
+
var tr = new u16(maxSym + 1);
|
|
470
|
+
// max bits in tree
|
|
471
|
+
var mbt = ln(t[i1 - 1], tr, 0);
|
|
472
|
+
if (mbt > mb) {
|
|
473
|
+
// more algorithms from UZIP.js
|
|
474
|
+
// TODO: find out how this code works (debt)
|
|
475
|
+
// ind debt
|
|
476
|
+
var i = 0, dt = 0;
|
|
477
|
+
// left cost
|
|
478
|
+
var lft = mbt - mb, cst = 1 << lft;
|
|
479
|
+
t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });
|
|
480
|
+
for (; i < s; ++i) {
|
|
481
|
+
var i2_1 = t2[i].s;
|
|
482
|
+
if (tr[i2_1] > mb) {
|
|
483
|
+
dt += cst - (1 << (mbt - tr[i2_1]));
|
|
484
|
+
tr[i2_1] = mb;
|
|
485
|
+
}
|
|
486
|
+
else
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
dt >>= lft;
|
|
490
|
+
while (dt > 0) {
|
|
491
|
+
var i2_2 = t2[i].s;
|
|
492
|
+
if (tr[i2_2] < mb)
|
|
493
|
+
dt -= 1 << (mb - tr[i2_2]++ - 1);
|
|
494
|
+
else
|
|
495
|
+
++i;
|
|
496
|
+
}
|
|
497
|
+
for (; i >= 0 && dt; --i) {
|
|
498
|
+
var i2_3 = t2[i].s;
|
|
499
|
+
if (tr[i2_3] == mb) {
|
|
500
|
+
--tr[i2_3];
|
|
501
|
+
++dt;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
mbt = mb;
|
|
505
|
+
}
|
|
506
|
+
return { t: new u8(tr), l: mbt };
|
|
507
|
+
};
|
|
508
|
+
// get the max length and assign length codes
|
|
509
|
+
var ln = function (n, l, d) {
|
|
510
|
+
return n.s == -1
|
|
511
|
+
? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))
|
|
512
|
+
: (l[n.s] = d);
|
|
513
|
+
};
|
|
514
|
+
// length codes generation
|
|
515
|
+
var lc = function (c) {
|
|
516
|
+
var s = c.length;
|
|
517
|
+
// Note that the semicolon was intentional
|
|
518
|
+
while (s && !c[--s])
|
|
519
|
+
;
|
|
520
|
+
var cl = new u16(++s);
|
|
521
|
+
// ind num streak
|
|
522
|
+
var cli = 0, cln = c[0], cls = 1;
|
|
523
|
+
var w = function (v) { cl[cli++] = v; };
|
|
524
|
+
for (var i = 1; i <= s; ++i) {
|
|
525
|
+
if (c[i] == cln && i != s)
|
|
526
|
+
++cls;
|
|
527
|
+
else {
|
|
528
|
+
if (!cln && cls > 2) {
|
|
529
|
+
for (; cls > 138; cls -= 138)
|
|
530
|
+
w(32754);
|
|
531
|
+
if (cls > 2) {
|
|
532
|
+
w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);
|
|
533
|
+
cls = 0;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
else if (cls > 3) {
|
|
537
|
+
w(cln), --cls;
|
|
538
|
+
for (; cls > 6; cls -= 6)
|
|
539
|
+
w(8304);
|
|
540
|
+
if (cls > 2)
|
|
541
|
+
w(((cls - 3) << 5) | 8208), cls = 0;
|
|
542
|
+
}
|
|
543
|
+
while (cls--)
|
|
544
|
+
w(cln);
|
|
545
|
+
cls = 1;
|
|
546
|
+
cln = c[i];
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return { c: cl.subarray(0, cli), n: s };
|
|
550
|
+
};
|
|
551
|
+
// calculate the length of output from tree, code lengths
|
|
552
|
+
var clen = function (cf, cl) {
|
|
553
|
+
var l = 0;
|
|
554
|
+
for (var i = 0; i < cl.length; ++i)
|
|
555
|
+
l += cf[i] * cl[i];
|
|
556
|
+
return l;
|
|
557
|
+
};
|
|
558
|
+
// writes a fixed block
|
|
559
|
+
// returns the new bit pos
|
|
560
|
+
var wfblk = function (out, pos, dat) {
|
|
561
|
+
// no need to write 00 as type: TypedArray defaults to 0
|
|
562
|
+
var s = dat.length;
|
|
563
|
+
var o = shft(pos + 2);
|
|
564
|
+
out[o] = s & 255;
|
|
565
|
+
out[o + 1] = s >> 8;
|
|
566
|
+
out[o + 2] = out[o] ^ 255;
|
|
567
|
+
out[o + 3] = out[o + 1] ^ 255;
|
|
568
|
+
for (var i = 0; i < s; ++i)
|
|
569
|
+
out[o + i + 4] = dat[i];
|
|
570
|
+
return (o + 4 + s) * 8;
|
|
571
|
+
};
|
|
572
|
+
// writes a block
|
|
573
|
+
var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
|
|
574
|
+
wbits(out, p++, final);
|
|
575
|
+
++lf[256];
|
|
576
|
+
var _a = hTree(lf, 15), dlt = _a.t, mlb = _a.l;
|
|
577
|
+
var _b = hTree(df, 15), ddt = _b.t, mdb = _b.l;
|
|
578
|
+
var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
|
|
579
|
+
var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
|
|
580
|
+
var lcfreq = new u16(19);
|
|
581
|
+
for (var i = 0; i < lclt.length; ++i)
|
|
582
|
+
++lcfreq[lclt[i] & 31];
|
|
583
|
+
for (var i = 0; i < lcdt.length; ++i)
|
|
584
|
+
++lcfreq[lcdt[i] & 31];
|
|
585
|
+
var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
|
|
586
|
+
var nlcc = 19;
|
|
587
|
+
for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
|
|
588
|
+
;
|
|
589
|
+
var flen = (bl + 5) << 3;
|
|
590
|
+
var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
|
|
591
|
+
var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
|
|
592
|
+
if (bs >= 0 && flen <= ftlen && flen <= dtlen)
|
|
593
|
+
return wfblk(out, p, dat.subarray(bs, bs + bl));
|
|
594
|
+
var lm, ll, dm, dl;
|
|
595
|
+
wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
|
|
596
|
+
if (dtlen < ftlen) {
|
|
597
|
+
lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
|
|
598
|
+
var llm = hMap(lct, mlcb, 0);
|
|
599
|
+
wbits(out, p, nlc - 257);
|
|
600
|
+
wbits(out, p + 5, ndc - 1);
|
|
601
|
+
wbits(out, p + 10, nlcc - 4);
|
|
602
|
+
p += 14;
|
|
603
|
+
for (var i = 0; i < nlcc; ++i)
|
|
604
|
+
wbits(out, p + 3 * i, lct[clim[i]]);
|
|
605
|
+
p += 3 * nlcc;
|
|
606
|
+
var lcts = [lclt, lcdt];
|
|
607
|
+
for (var it = 0; it < 2; ++it) {
|
|
608
|
+
var clct = lcts[it];
|
|
609
|
+
for (var i = 0; i < clct.length; ++i) {
|
|
610
|
+
var len = clct[i] & 31;
|
|
611
|
+
wbits(out, p, llm[len]), p += lct[len];
|
|
612
|
+
if (len > 15)
|
|
613
|
+
wbits(out, p, (clct[i] >> 5) & 127), p += clct[i] >> 12;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
else {
|
|
618
|
+
lm = flm, ll = flt, dm = fdm, dl = fdt;
|
|
619
|
+
}
|
|
620
|
+
for (var i = 0; i < li; ++i) {
|
|
621
|
+
var sym = syms[i];
|
|
622
|
+
if (sym > 255) {
|
|
623
|
+
var len = (sym >> 18) & 31;
|
|
624
|
+
wbits16(out, p, lm[len + 257]), p += ll[len + 257];
|
|
625
|
+
if (len > 7)
|
|
626
|
+
wbits(out, p, (sym >> 23) & 31), p += fleb[len];
|
|
627
|
+
var dst = sym & 31;
|
|
628
|
+
wbits16(out, p, dm[dst]), p += dl[dst];
|
|
629
|
+
if (dst > 3)
|
|
630
|
+
wbits16(out, p, (sym >> 5) & 8191), p += fdeb[dst];
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
wbits16(out, p, lm[sym]), p += ll[sym];
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
wbits16(out, p, lm[256]);
|
|
637
|
+
return p + ll[256];
|
|
638
|
+
};
|
|
639
|
+
// deflate options (nice << 13) | chain
|
|
640
|
+
var deo = /*#__PURE__*/ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
|
|
641
|
+
// empty
|
|
642
|
+
var et = /*#__PURE__*/ new u8(0);
|
|
643
|
+
// compresses data into a raw DEFLATE buffer
|
|
644
|
+
var dflt = function (dat, lvl, plvl, pre, post, st) {
|
|
645
|
+
var s = st.z || dat.length;
|
|
646
|
+
var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
|
|
647
|
+
// writing to this writes to the output buffer
|
|
648
|
+
var w = o.subarray(pre, o.length - post);
|
|
649
|
+
var lst = st.l;
|
|
650
|
+
var pos = (st.r || 0) & 7;
|
|
651
|
+
if (lvl) {
|
|
652
|
+
if (pos)
|
|
653
|
+
w[0] = st.r >> 3;
|
|
654
|
+
var opt = deo[lvl - 1];
|
|
655
|
+
var n = opt >> 13, c = opt & 8191;
|
|
656
|
+
var msk_1 = (1 << plvl) - 1;
|
|
657
|
+
// prev 2-byte val map curr 2-byte val map
|
|
658
|
+
var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
|
|
659
|
+
var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
|
|
660
|
+
var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };
|
|
661
|
+
// 24576 is an arbitrary number of maximum symbols per block
|
|
662
|
+
// 424 buffer for last block
|
|
663
|
+
var syms = new i32(25000);
|
|
664
|
+
// length/literal freq distance freq
|
|
665
|
+
var lf = new u16(288), df = new u16(32);
|
|
666
|
+
// l/lcnt exbits index l/lind waitdx blkpos
|
|
667
|
+
var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
|
|
668
|
+
for (; i + 2 < s; ++i) {
|
|
669
|
+
// hash value
|
|
670
|
+
var hv = hsh(i);
|
|
671
|
+
// index mod 32768 previous index mod
|
|
672
|
+
var imod = i & 32767, pimod = head[hv];
|
|
673
|
+
prev[imod] = pimod;
|
|
674
|
+
head[hv] = imod;
|
|
675
|
+
// We always should modify head and prev, but only add symbols if
|
|
676
|
+
// this data is not yet processed ("wait" for wait index)
|
|
677
|
+
if (wi <= i) {
|
|
678
|
+
// bytes remaining
|
|
679
|
+
var rem = s - i;
|
|
680
|
+
if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
|
|
681
|
+
pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);
|
|
682
|
+
li = lc_1 = eb = 0, bs = i;
|
|
683
|
+
for (var j = 0; j < 286; ++j)
|
|
684
|
+
lf[j] = 0;
|
|
685
|
+
for (var j = 0; j < 30; ++j)
|
|
686
|
+
df[j] = 0;
|
|
687
|
+
}
|
|
688
|
+
// len dist chain
|
|
689
|
+
var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
|
|
690
|
+
if (rem > 2 && hv == hsh(i - dif)) {
|
|
691
|
+
var maxn = Math.min(n, rem) - 1;
|
|
692
|
+
var maxd = Math.min(32767, i);
|
|
693
|
+
// max possible length
|
|
694
|
+
// not capped at dif because decompressors implement "rolling" index population
|
|
695
|
+
var ml = Math.min(258, rem);
|
|
696
|
+
while (dif <= maxd && --ch_1 && imod != pimod) {
|
|
697
|
+
if (dat[i + l] == dat[i + l - dif]) {
|
|
698
|
+
var nl = 0;
|
|
699
|
+
for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)
|
|
700
|
+
;
|
|
701
|
+
if (nl > l) {
|
|
702
|
+
l = nl, d = dif;
|
|
703
|
+
// break out early when we reach "nice" (we are satisfied enough)
|
|
704
|
+
if (nl > maxn)
|
|
705
|
+
break;
|
|
706
|
+
// now, find the rarest 2-byte sequence within this
|
|
707
|
+
// length of literals and search for that instead.
|
|
708
|
+
// Much faster than just using the start
|
|
709
|
+
var mmd = Math.min(dif, nl - 2);
|
|
710
|
+
var md = 0;
|
|
711
|
+
for (var j = 0; j < mmd; ++j) {
|
|
712
|
+
var ti = i - dif + j & 32767;
|
|
713
|
+
var pti = prev[ti];
|
|
714
|
+
var cd = ti - pti & 32767;
|
|
715
|
+
if (cd > md)
|
|
716
|
+
md = cd, pimod = ti;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
// check the previous match
|
|
721
|
+
imod = pimod, pimod = prev[imod];
|
|
722
|
+
dif += imod - pimod & 32767;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
// d will be nonzero only when a match was found
|
|
726
|
+
if (d) {
|
|
727
|
+
// store both dist and len data in one int32
|
|
728
|
+
// Make sure this is recognized as a len/dist with 28th bit (2^28)
|
|
729
|
+
syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];
|
|
730
|
+
var lin = revfl[l] & 31, din = revfd[d] & 31;
|
|
731
|
+
eb += fleb[lin] + fdeb[din];
|
|
732
|
+
++lf[257 + lin];
|
|
733
|
+
++df[din];
|
|
734
|
+
wi = i + l;
|
|
735
|
+
++lc_1;
|
|
736
|
+
}
|
|
737
|
+
else {
|
|
738
|
+
syms[li++] = dat[i];
|
|
739
|
+
++lf[dat[i]];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
for (i = Math.max(i, wi); i < s; ++i) {
|
|
744
|
+
syms[li++] = dat[i];
|
|
745
|
+
++lf[dat[i]];
|
|
746
|
+
}
|
|
747
|
+
pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);
|
|
748
|
+
if (!lst) {
|
|
749
|
+
st.r = (pos & 7) | w[(pos / 8) | 0] << 3;
|
|
750
|
+
// shft(pos) now 1 less if pos & 7 != 0
|
|
751
|
+
pos -= 7;
|
|
752
|
+
st.h = head, st.p = prev, st.i = i, st.w = wi;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
else {
|
|
756
|
+
for (var i = st.w || 0; i < s + lst; i += 65535) {
|
|
757
|
+
// end
|
|
758
|
+
var e = i + 65535;
|
|
759
|
+
if (e >= s) {
|
|
760
|
+
// write final block
|
|
761
|
+
w[(pos / 8) | 0] = lst;
|
|
762
|
+
e = s;
|
|
763
|
+
}
|
|
764
|
+
pos = wfblk(w, pos + 1, dat.subarray(i, e));
|
|
765
|
+
}
|
|
766
|
+
st.i = s;
|
|
767
|
+
}
|
|
768
|
+
return slc(o, 0, pre + shft(pos) + post);
|
|
769
|
+
};
|
|
770
|
+
// CRC32 table
|
|
771
|
+
var crct = /*#__PURE__*/ (function () {
|
|
772
|
+
var t = new Int32Array(256);
|
|
773
|
+
for (var i = 0; i < 256; ++i) {
|
|
774
|
+
var c = i, k = 9;
|
|
775
|
+
while (--k)
|
|
776
|
+
c = ((c & 1) && -306674912) ^ (c >>> 1);
|
|
777
|
+
t[i] = c;
|
|
778
|
+
}
|
|
779
|
+
return t;
|
|
780
|
+
})();
|
|
781
|
+
// CRC32
|
|
782
|
+
var crc = function () {
|
|
783
|
+
var c = -1;
|
|
784
|
+
return {
|
|
785
|
+
p: function (d) {
|
|
786
|
+
// closures have awful performance
|
|
787
|
+
var cr = c;
|
|
788
|
+
for (var i = 0; i < d.length; ++i)
|
|
789
|
+
cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);
|
|
790
|
+
c = cr;
|
|
791
|
+
},
|
|
792
|
+
d: function () { return ~c; }
|
|
793
|
+
};
|
|
794
|
+
};
|
|
795
|
+
// deflate with opts
|
|
796
|
+
var dopt = function (dat, opt, pre, post, st) {
|
|
797
|
+
if (!st) {
|
|
798
|
+
st = { l: 1 };
|
|
799
|
+
if (opt.dictionary) {
|
|
800
|
+
var dict = opt.dictionary.subarray(-32768);
|
|
801
|
+
var newDat = new u8(dict.length + dat.length);
|
|
802
|
+
newDat.set(dict);
|
|
803
|
+
newDat.set(dat, dict.length);
|
|
804
|
+
dat = newDat;
|
|
805
|
+
st.w = dict.length;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? (st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20) : (12 + opt.mem), pre, post, st);
|
|
809
|
+
};
|
|
810
|
+
// Walmart object spread
|
|
811
|
+
var mrg = function (a, b) {
|
|
812
|
+
var o = {};
|
|
813
|
+
for (var k in a)
|
|
814
|
+
o[k] = a[k];
|
|
815
|
+
for (var k in b)
|
|
816
|
+
o[k] = b[k];
|
|
817
|
+
return o;
|
|
818
|
+
};
|
|
819
|
+
// write bytes
|
|
820
|
+
var wbytes = function (d, b, v) {
|
|
821
|
+
for (; v; ++b)
|
|
822
|
+
d[b] = v, v >>>= 8;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Compresses data with DEFLATE without any wrapper
|
|
826
|
+
* @param data The data to compress
|
|
827
|
+
* @param opts The compression options
|
|
828
|
+
* @returns The deflated version of the data
|
|
829
|
+
*/
|
|
830
|
+
function deflateSync(data, opts) {
|
|
831
|
+
return dopt(data, opts || {}, 0, 0);
|
|
832
|
+
}
|
|
833
|
+
// flatten a directory structure
|
|
834
|
+
var fltn = function (d, p, t, o) {
|
|
835
|
+
for (var k in d) {
|
|
836
|
+
var val = d[k], n = p + k, op = o;
|
|
837
|
+
if (Array.isArray(val))
|
|
838
|
+
op = mrg(o, val[1]), val = val[0];
|
|
839
|
+
if (val instanceof u8)
|
|
840
|
+
t[n] = [val, op];
|
|
841
|
+
else {
|
|
842
|
+
t[n += '/'] = [new u8(0), op];
|
|
843
|
+
fltn(val, n, t, o);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
// text encoder
|
|
848
|
+
var te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();
|
|
849
|
+
// text decoder
|
|
850
|
+
var td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();
|
|
851
|
+
// text decoder stream
|
|
852
|
+
var tds = 0;
|
|
853
|
+
try {
|
|
854
|
+
td.decode(et, { stream: true });
|
|
855
|
+
tds = 1;
|
|
856
|
+
}
|
|
857
|
+
catch (e) { }
|
|
858
|
+
/**
|
|
859
|
+
* Converts a string into a Uint8Array for use with compression/decompression methods
|
|
860
|
+
* @param str The string to encode
|
|
861
|
+
* @param latin1 Whether or not to interpret the data as Latin-1. This should
|
|
862
|
+
* not need to be true unless decoding a binary string.
|
|
863
|
+
* @returns The string encoded in UTF-8/Latin-1 binary
|
|
864
|
+
*/
|
|
865
|
+
function strToU8(str, latin1) {
|
|
866
|
+
var i;
|
|
867
|
+
if (te)
|
|
868
|
+
return te.encode(str);
|
|
869
|
+
var l = str.length;
|
|
870
|
+
var ar = new u8(str.length + (str.length >> 1));
|
|
871
|
+
var ai = 0;
|
|
872
|
+
var w = function (v) { ar[ai++] = v; };
|
|
873
|
+
for (var i = 0; i < l; ++i) {
|
|
874
|
+
if (ai + 5 > ar.length) {
|
|
875
|
+
var n = new u8(ai + 8 + ((l - i) << 1));
|
|
876
|
+
n.set(ar);
|
|
877
|
+
ar = n;
|
|
878
|
+
}
|
|
879
|
+
var c = str.charCodeAt(i);
|
|
880
|
+
if (c < 128 || latin1)
|
|
881
|
+
w(c);
|
|
882
|
+
else if (c < 2048)
|
|
883
|
+
w(192 | (c >> 6)), w(128 | (c & 63));
|
|
884
|
+
else if (c > 55295 && c < 57344)
|
|
885
|
+
c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),
|
|
886
|
+
w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
|
|
887
|
+
else
|
|
888
|
+
w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
|
|
889
|
+
}
|
|
890
|
+
return slc(ar, 0, ai);
|
|
891
|
+
}
|
|
892
|
+
// extra field length
|
|
893
|
+
var exfl = function (ex) {
|
|
894
|
+
var le = 0;
|
|
895
|
+
if (ex) {
|
|
896
|
+
for (var k in ex) {
|
|
897
|
+
var l = ex[k].length;
|
|
898
|
+
if (l > 65535)
|
|
899
|
+
err(9);
|
|
900
|
+
le += l + 4;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
return le;
|
|
904
|
+
};
|
|
905
|
+
// write zip header
|
|
906
|
+
var wzh = function (d, b, f, fn, u, c, ce, co) {
|
|
907
|
+
var fl = fn.length, ex = f.extra, col = co && co.length;
|
|
908
|
+
var exl = exfl(ex);
|
|
909
|
+
wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;
|
|
910
|
+
if (ce != null)
|
|
911
|
+
d[b++] = 20, d[b++] = f.os;
|
|
912
|
+
d[b] = 20, b += 2; // spec compliance? what's that?
|
|
913
|
+
d[b++] = (f.flag << 1) | (c < 0 && 8), d[b++] = u && 8;
|
|
914
|
+
d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
|
|
915
|
+
var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
|
|
916
|
+
if (y < 0 || y > 119)
|
|
917
|
+
err(10);
|
|
918
|
+
wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >> 1)), b += 4;
|
|
919
|
+
if (c != -1) {
|
|
920
|
+
wbytes(d, b, f.crc);
|
|
921
|
+
wbytes(d, b + 4, c < 0 ? -c - 2 : c);
|
|
922
|
+
wbytes(d, b + 8, f.size);
|
|
923
|
+
}
|
|
924
|
+
wbytes(d, b + 12, fl);
|
|
925
|
+
wbytes(d, b + 14, exl), b += 16;
|
|
926
|
+
if (ce != null) {
|
|
927
|
+
wbytes(d, b, col);
|
|
928
|
+
wbytes(d, b + 6, f.attrs);
|
|
929
|
+
wbytes(d, b + 10, ce), b += 14;
|
|
930
|
+
}
|
|
931
|
+
d.set(fn, b);
|
|
932
|
+
b += fl;
|
|
933
|
+
if (exl) {
|
|
934
|
+
for (var k in ex) {
|
|
935
|
+
var exf = ex[k], l = exf.length;
|
|
936
|
+
wbytes(d, b, +k);
|
|
937
|
+
wbytes(d, b + 2, l);
|
|
938
|
+
d.set(exf, b + 4), b += 4 + l;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
if (col)
|
|
942
|
+
d.set(co, b), b += col;
|
|
943
|
+
return b;
|
|
944
|
+
};
|
|
945
|
+
// write zip footer (end of central directory)
|
|
946
|
+
var wzf = function (o, b, c, d, e) {
|
|
947
|
+
wbytes(o, b, 0x6054B50); // skip disk
|
|
948
|
+
wbytes(o, b + 8, c);
|
|
949
|
+
wbytes(o, b + 10, c);
|
|
950
|
+
wbytes(o, b + 12, d);
|
|
951
|
+
wbytes(o, b + 16, e);
|
|
952
|
+
};
|
|
953
|
+
/**
|
|
954
|
+
* Synchronously creates a ZIP file. Prefer using `zip` for better performance
|
|
955
|
+
* with more than one file.
|
|
956
|
+
* @param data The directory structure for the ZIP archive
|
|
957
|
+
* @param opts The main options, merged with per-file options
|
|
958
|
+
* @returns The generated ZIP archive
|
|
959
|
+
*/
|
|
960
|
+
function zipSync(data, opts) {
|
|
961
|
+
if (!opts)
|
|
962
|
+
opts = {};
|
|
963
|
+
var r = {};
|
|
964
|
+
var files = [];
|
|
965
|
+
fltn(data, '', r, opts);
|
|
966
|
+
var o = 0;
|
|
967
|
+
var tot = 0;
|
|
968
|
+
for (var fn in r) {
|
|
969
|
+
var _a = r[fn], file = _a[0], p = _a[1];
|
|
970
|
+
var compression = p.level == 0 ? 0 : 8;
|
|
971
|
+
var f = strToU8(fn), s = f.length;
|
|
972
|
+
var com = p.comment, m = com && strToU8(com), ms = m && m.length;
|
|
973
|
+
var exl = exfl(p.extra);
|
|
974
|
+
if (s > 65535)
|
|
975
|
+
err(11);
|
|
976
|
+
var d = compression ? deflateSync(file, p) : file, l = d.length;
|
|
977
|
+
var c = crc();
|
|
978
|
+
c.p(file);
|
|
979
|
+
files.push(mrg(p, {
|
|
980
|
+
size: file.length,
|
|
981
|
+
crc: c.d(),
|
|
982
|
+
c: d,
|
|
983
|
+
f: f,
|
|
984
|
+
m: m,
|
|
985
|
+
u: s != fn.length || (m && (com.length != ms)),
|
|
986
|
+
o: o,
|
|
987
|
+
compression: compression
|
|
988
|
+
}));
|
|
989
|
+
o += 30 + s + exl + l;
|
|
990
|
+
tot += 76 + 2 * (s + exl) + (ms || 0) + l;
|
|
991
|
+
}
|
|
992
|
+
var out = new u8(tot + 22), oe = o, cdl = tot - o;
|
|
993
|
+
for (var i = 0; i < files.length; ++i) {
|
|
994
|
+
var f = files[i];
|
|
995
|
+
wzh(out, f.o, f, f.f, f.u, f.c.length);
|
|
996
|
+
var badd = 30 + f.f.length + exfl(f.extra);
|
|
997
|
+
out.set(f.c, f.o + badd);
|
|
998
|
+
wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
|
|
999
|
+
}
|
|
1000
|
+
wzf(out, o, files.length, cdl, oe);
|
|
1001
|
+
return out;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1
1004
|
var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs$1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function getAugmentedNamespace(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype;}else i={};return Object.defineProperty(i,"__esModule",{value:true}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:true,get:function(){return e[t]}});})),i}"undefined"==typeof self&&"object"==typeof commonjsGlobal&&(commonjsGlobal.self=commonjsGlobal);var global$1="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,inited=false;function init(){inited=true;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)lookup[t]=e[t],revLookup[e.charCodeAt(t)]=t;revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;}function toByteArray(e){var t,i,r,n,a,o;inited||init();var s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");a="="===e[s-2]?2:"="===e[s-1]?1:0,o=new Arr(3*s/4-a),r=a>0?s-4:s;var l=0;for(t=0,i=0;t<r;t+=4,i+=3)n=revLookup[e.charCodeAt(t)]<<18|revLookup[e.charCodeAt(t+1)]<<12|revLookup[e.charCodeAt(t+2)]<<6|revLookup[e.charCodeAt(t+3)],o[l++]=n>>16&255,o[l++]=n>>8&255,o[l++]=255&n;return 2===a?(n=revLookup[e.charCodeAt(t)]<<2|revLookup[e.charCodeAt(t+1)]>>4,o[l++]=255&n):1===a&&(n=revLookup[e.charCodeAt(t)]<<10|revLookup[e.charCodeAt(t+1)]<<4|revLookup[e.charCodeAt(t+2)]>>2,o[l++]=n>>8&255,o[l++]=255&n),o}function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,t,i){for(var r,n=[],a=t;a<i;a+=3)r=(e[a]<<16)+(e[a+1]<<8)+e[a+2],n.push(tripletToBase64(r));return n.join("")}function fromByteArray(e){var t;inited||init();for(var i=e.length,r=i%3,n="",a=[],o=16383,s=0,l=i-r;s<l;s+=o)a.push(encodeChunk(e,s,s+o>l?l:s+o));return 1===r?(t=e[i-1],n+=lookup[t>>2],n+=lookup[t<<4&63],n+="=="):2===r&&(t=(e[i-2]<<8)+e[i-1],n+=lookup[t>>10],n+=lookup[t>>4&63],n+=lookup[t<<2&63],n+="="),a.push(n),a.join("")}function read(e,t,i,r,n){var a,o,s=8*n-r-1,l=(1<<s)-1,u=l>>1,h=-7,c=i?n-1:0,f=i?-1:1,d=e[t+c];for(c+=f,a=d&(1<<-h)-1,d>>=-h,h+=s;h>0;a=256*a+e[t+c],c+=f,h-=8);for(o=a&(1<<-h)-1,a>>=-h,h+=r;h>0;o=256*o+e[t+c],c+=f,h-=8);if(0===a)a=1-u;else {if(a===l)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),a-=u;}return (d?-1:1)*o*Math.pow(2,a-r)}function write(e,t,i,r,n,a){var o,s,l,u=8*a-n-1,h=(1<<u)-1,c=h>>1,f=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:a-1,p=r?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=h):(o=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-o))<1&&(o--,l*=2),(t+=o+c>=1?f/l:f*Math.pow(2,1-c))*l>=2&&(o++,l/=2),o+c>=h?(s=0,o=h):o+c>=1?(s=(t*l-1)*Math.pow(2,n),o+=c):(s=t*Math.pow(2,c-1)*Math.pow(2,n),o=0));n>=8;e[i+d]=255&s,d+=p,s/=256,n-=8);for(o=o<<n|s,u+=n;u>0;e[i+d]=255&o,d+=p,o/=256,u-=8);e[i+d-p]|=128*m;}var toString={}.toString,isArray=Array.isArray||function(e){return "[object Array]"==toString.call(e)},INSPECT_MAX_BYTES=50;function kMaxLength(){return Buffer$1.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(e,t){if(kMaxLength()<t)throw new RangeError("Invalid typed array length");return Buffer$1.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=Buffer$1.prototype:(null===e&&(e=new Buffer$1(t)),e.length=t),e}function Buffer$1(e,t,i){if(!(Buffer$1.TYPED_ARRAY_SUPPORT||this instanceof Buffer$1))return new Buffer$1(e,t,i);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return allocUnsafe(this,e)}return from(this,e,t,i)}function from(e,t,i,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return "undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?fromArrayBuffer(e,t,i,r):"string"==typeof t?fromString$1(e,t,i):fromObject(e,t)}function assertSize(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function alloc(e,t,i,r){return assertSize(t),t<=0?createBuffer(e,t):void 0!==i?"string"==typeof r?createBuffer(e,t).fill(i,r):createBuffer(e,t).fill(i):createBuffer(e,t)}function allocUnsafe(e,t){if(assertSize(t),e=createBuffer(e,t<0?0:0|checked(t)),!Buffer$1.TYPED_ARRAY_SUPPORT)for(var i=0;i<t;++i)e[i]=0;return e}function fromString$1(e,t,i){if("string"==typeof i&&""!==i||(i="utf8"),!Buffer$1.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var r=0|byteLength(t,i),n=(e=createBuffer(e,r)).write(t,i);return n!==r&&(e=e.slice(0,n)),e}function fromArrayLike(e,t){var i=t.length<0?0:0|checked(t.length);e=createBuffer(e,i);for(var r=0;r<i;r+=1)e[r]=255&t[r];return e}function fromArrayBuffer(e,t,i,r){if(t.byteLength,i<0||t.byteLength<i)throw new RangeError("'offset' is out of bounds");if(t.byteLength<i+(r||0))throw new RangeError("'length' is out of bounds");return t=void 0===i&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,i):new Uint8Array(t,i,r),Buffer$1.TYPED_ARRAY_SUPPORT?(e=t).__proto__=Buffer$1.prototype:e=fromArrayLike(e,t),e}function fromObject(e,t){if(internalIsBuffer(t)){var i=0|checked(t.length);return 0===(e=createBuffer(e,i)).length||t.copy(e,0,0,i),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return "number"!=typeof t.length||isnan(t.length)?createBuffer(e,0):fromArrayLike(e,t);if("Buffer"===t.type&&isArray(t.data))return fromArrayLike(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function checked(e){if(e>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return 0|e}function internalIsBuffer(e){return !(null==e||!e._isBuffer)}function byteLength(e,t){if(internalIsBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var i=e.length;if(0===i)return 0;for(var r=false;;)switch(t){case "ascii":case "latin1":case "binary":return i;case "utf8":case "utf-8":case void 0:return utf8ToBytes(e).length;case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return 2*i;case "hex":return i>>>1;case "base64":return base64ToBytes(e).length;default:if(r)return utf8ToBytes(e).length;t=(""+t).toLowerCase(),r=true;}}function slowToString(e,t,i){var r=false;if((void 0===t||t<0)&&(t=0),t>this.length)return "";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return "";if((i>>>=0)<=(t>>>=0))return "";for(e||(e="utf8");;)switch(e){case "hex":return hexSlice(this,t,i);case "utf8":case "utf-8":return utf8Slice(this,t,i);case "ascii":return asciiSlice(this,t,i);case "latin1":case "binary":return latin1Slice(this,t,i);case "base64":return base64Slice(this,t,i);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return utf16leSlice(this,t,i);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=true;}}function swap(e,t,i){var r=e[t];e[t]=e[i],e[i]=r;}function bidirectionalIndexOf(e,t,i,r,n){if(0===e.length)return -1;if("string"==typeof i?(r=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=n?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(n)return -1;i=e.length-1;}else if(i<0){if(!n)return -1;i=0;}if("string"==typeof t&&(t=Buffer$1.from(t,r)),internalIsBuffer(t))return 0===t.length?-1:arrayIndexOf(e,t,i,r,n);if("number"==typeof t)return t&=255,Buffer$1.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):arrayIndexOf(e,[t],i,r,n);throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(e,t,i,r,n){var a,o=1,s=e.length,l=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return -1;o=2,s/=2,l/=2,i/=2;}function u(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(n){var h=-1;for(a=i;a<s;a++)if(u(e,a)===u(t,-1===h?0:a-h)){if(-1===h&&(h=a),a-h+1===l)return h*o}else -1!==h&&(a-=a-h),h=-1;}else for(i+l>s&&(i=s-l),a=i;a>=0;a--){for(var c=true,f=0;f<l;f++)if(u(e,a+f)!==u(t,f)){c=false;break}if(c)return a}return -1}function hexWrite(e,t,i,r){i=Number(i)||0;var n=e.length-i;r?(r=Number(r))>n&&(r=n):r=n;var a=t.length;if(a%2!=0)throw new TypeError("Invalid hex string");r>a/2&&(r=a/2);for(var o=0;o<r;++o){var s=parseInt(t.substr(2*o,2),16);if(isNaN(s))return o;e[i+o]=s;}return o}function utf8Write(e,t,i,r){return blitBuffer(utf8ToBytes(t,e.length-i),e,i,r)}function asciiWrite(e,t,i,r){return blitBuffer(asciiToBytes(t),e,i,r)}function latin1Write(e,t,i,r){return asciiWrite(e,t,i,r)}function base64Write(e,t,i,r){return blitBuffer(base64ToBytes(t),e,i,r)}function ucs2Write(e,t,i,r){return blitBuffer(utf16leToBytes(t,e.length-i),e,i,r)}function base64Slice(e,t,i){return 0===t&&i===e.length?fromByteArray(e):fromByteArray(e.slice(t,i))}function utf8Slice(e,t,i){i=Math.min(e.length,i);for(var r=[],n=t;n<i;){var a,o,s,l,u=e[n],h=null,c=u>239?4:u>223?3:u>191?2:1;if(n+c<=i)switch(c){case 1:u<128&&(h=u);break;case 2:128==(192&(a=e[n+1]))&&(l=(31&u)<<6|63&a)>127&&(h=l);break;case 3:a=e[n+1],o=e[n+2],128==(192&a)&&128==(192&o)&&(l=(15&u)<<12|(63&a)<<6|63&o)>2047&&(l<55296||l>57343)&&(h=l);break;case 4:a=e[n+1],o=e[n+2],s=e[n+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&(l=(15&u)<<18|(63&a)<<12|(63&o)<<6|63&s)>65535&&l<1114112&&(h=l);}null===h?(h=65533,c=1):h>65535&&(h-=65536,r.push(h>>>10&1023|55296),h=56320|1023&h),r.push(h),n+=c;}return decodeCodePointsArray(r)}Buffer$1.TYPED_ARRAY_SUPPORT=void 0===global$1.TYPED_ARRAY_SUPPORT||global$1.TYPED_ARRAY_SUPPORT,kMaxLength(),Buffer$1.poolSize=8192,Buffer$1._augment=function(e){return e.__proto__=Buffer$1.prototype,e},Buffer$1.from=function(e,t,i){return from(null,e,t,i)},Buffer$1.TYPED_ARRAY_SUPPORT&&(Buffer$1.prototype.__proto__=Uint8Array.prototype,Buffer$1.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&Buffer$1[Symbol.species]),Buffer$1.alloc=function(e,t,i){return alloc(null,e,t,i)},Buffer$1.allocUnsafe=function(e){return allocUnsafe(null,e)},Buffer$1.allocUnsafeSlow=function(e){return allocUnsafe(null,e)},Buffer$1.isBuffer=isBuffer,Buffer$1.compare=function(e,t){if(!internalIsBuffer(e)||!internalIsBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,r=t.length,n=0,a=Math.min(i,r);n<a;++n)if(e[n]!==t[n]){i=e[n],r=t[n];break}return i<r?-1:r<i?1:0},Buffer$1.isEncoding=function(e){switch(String(e).toLowerCase()){case "hex":case "utf8":case "utf-8":case "ascii":case "latin1":case "binary":case "base64":case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return true;default:return false}},Buffer$1.concat=function(e,t){if(!isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return Buffer$1.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var r=Buffer$1.allocUnsafe(t),n=0;for(i=0;i<e.length;++i){var a=e[i];if(!internalIsBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(r,n),n+=a.length;}return r},Buffer$1.byteLength=byteLength,Buffer$1.prototype._isBuffer=true,Buffer$1.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)swap(this,t,t+1);return this},Buffer$1.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)swap(this,t,t+3),swap(this,t+1,t+2);return this},Buffer$1.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)swap(this,t,t+7),swap(this,t+1,t+6),swap(this,t+2,t+5),swap(this,t+3,t+4);return this},Buffer$1.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?utf8Slice(this,0,e):slowToString.apply(this,arguments)},Buffer$1.prototype.equals=function(e){if(!internalIsBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===Buffer$1.compare(this,e)},Buffer$1.prototype.inspect=function(){var e="",t=INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),"<Buffer "+e+">"},Buffer$1.prototype.compare=function(e,t,i,r,n){if(!internalIsBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===r&&(r=0),void 0===n&&(n=this.length),t<0||i>e.length||r<0||n>this.length)throw new RangeError("out of range index");if(r>=n&&t>=i)return 0;if(r>=n)return -1;if(t>=i)return 1;if(this===e)return 0;for(var a=(n>>>=0)-(r>>>=0),o=(i>>>=0)-(t>>>=0),s=Math.min(a,o),l=this.slice(r,n),u=e.slice(t,i),h=0;h<s;++h)if(l[h]!==u[h]){a=l[h],o=u[h];break}return a<o?-1:o<a?1:0},Buffer$1.prototype.includes=function(e,t,i){return -1!==this.indexOf(e,t,i)},Buffer$1.prototype.indexOf=function(e,t,i){return bidirectionalIndexOf(this,e,t,i,true)},Buffer$1.prototype.lastIndexOf=function(e,t,i){return bidirectionalIndexOf(this,e,t,i,false)},Buffer$1.prototype.write=function(e,t,i,r){if(void 0===t)r="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)r=t,i=this.length,t=0;else {if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(i)?(i|=0,void 0===r&&(r="utf8")):(r=i,i=void 0);}var n=this.length-t;if((void 0===i||i>n)&&(i=n),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var a=false;;)switch(r){case "hex":return hexWrite(this,e,t,i);case "utf8":case "utf-8":return utf8Write(this,e,t,i);case "ascii":return asciiWrite(this,e,t,i);case "latin1":case "binary":return latin1Write(this,e,t,i);case "base64":return base64Write(this,e,t,i);case "ucs2":case "ucs-2":case "utf16le":case "utf-16le":return ucs2Write(this,e,t,i);default:if(a)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),a=true;}},Buffer$1.prototype.toJSON=function(){return {type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(e){var t=e.length;if(t<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,e);for(var i="",r=0;r<t;)i+=String.fromCharCode.apply(String,e.slice(r,r+=MAX_ARGUMENTS_LENGTH));return i}function asciiSlice(e,t,i){var r="";i=Math.min(e.length,i);for(var n=t;n<i;++n)r+=String.fromCharCode(127&e[n]);return r}function latin1Slice(e,t,i){var r="";i=Math.min(e.length,i);for(var n=t;n<i;++n)r+=String.fromCharCode(e[n]);return r}function hexSlice(e,t,i){var r=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>r)&&(i=r);for(var n="",a=t;a<i;++a)n+=toHex(e[a]);return n}function utf16leSlice(e,t,i){for(var r=e.slice(t,i),n="",a=0;a<r.length;a+=2)n+=String.fromCharCode(r[a]+256*r[a+1]);return n}function checkOffset(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function checkInt(e,t,i,r,n,a){if(!internalIsBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>n||t<a)throw new RangeError('"value" argument is out of bounds');if(i+r>e.length)throw new RangeError("Index out of range")}function objectWriteUInt16(e,t,i,r){t<0&&(t=65535+t+1);for(var n=0,a=Math.min(e.length-i,2);n<a;++n)e[i+n]=(t&255<<8*(r?n:1-n))>>>8*(r?n:1-n);}function objectWriteUInt32(e,t,i,r){t<0&&(t=4294967295+t+1);for(var n=0,a=Math.min(e.length-i,4);n<a;++n)e[i+n]=t>>>8*(r?n:3-n)&255;}function checkIEEE754(e,t,i,r,n,a){if(i+r>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function writeFloat(e,t,i,r,n){return n||checkIEEE754(e,t,i,4),write(e,t,i,r,23,4),i+4}function writeDouble(e,t,i,r,n){return n||checkIEEE754(e,t,i,8),write(e,t,i,r,52,8),i+8}Buffer$1.prototype.slice=function(e,t){var i,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),Buffer$1.TYPED_ARRAY_SUPPORT)(i=this.subarray(e,t)).__proto__=Buffer$1.prototype;else {var n=t-e;i=new Buffer$1(n,void 0);for(var a=0;a<n;++a)i[a]=this[a+e];}return i},Buffer$1.prototype.readUIntLE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e],n=1,a=0;++a<t&&(n*=256);)r+=this[e+a]*n;return r},Buffer$1.prototype.readUIntBE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e+--t],n=1;t>0&&(n*=256);)r+=this[e+--t]*n;return r},Buffer$1.prototype.readUInt8=function(e,t){return t||checkOffset(e,1,this.length),this[e]},Buffer$1.prototype.readUInt16LE=function(e,t){return t||checkOffset(e,2,this.length),this[e]|this[e+1]<<8},Buffer$1.prototype.readUInt16BE=function(e,t){return t||checkOffset(e,2,this.length),this[e]<<8|this[e+1]},Buffer$1.prototype.readUInt32LE=function(e,t){return t||checkOffset(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},Buffer$1.prototype.readUInt32BE=function(e,t){return t||checkOffset(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},Buffer$1.prototype.readIntLE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e],n=1,a=0;++a<t&&(n*=256);)r+=this[e+a]*n;return r>=(n*=128)&&(r-=Math.pow(2,8*t)),r},Buffer$1.prototype.readIntBE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=t,n=1,a=this[e+--r];r>0&&(n*=256);)a+=this[e+--r]*n;return a>=(n*=128)&&(a-=Math.pow(2,8*t)),a},Buffer$1.prototype.readInt8=function(e,t){return t||checkOffset(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},Buffer$1.prototype.readInt16LE=function(e,t){t||checkOffset(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},Buffer$1.prototype.readInt16BE=function(e,t){t||checkOffset(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},Buffer$1.prototype.readInt32LE=function(e,t){return t||checkOffset(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},Buffer$1.prototype.readInt32BE=function(e,t){return t||checkOffset(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},Buffer$1.prototype.readFloatLE=function(e,t){return t||checkOffset(e,4,this.length),read(this,e,true,23,4)},Buffer$1.prototype.readFloatBE=function(e,t){return t||checkOffset(e,4,this.length),read(this,e,false,23,4)},Buffer$1.prototype.readDoubleLE=function(e,t){return t||checkOffset(e,8,this.length),read(this,e,true,52,8)},Buffer$1.prototype.readDoubleBE=function(e,t){return t||checkOffset(e,8,this.length),read(this,e,false,52,8)},Buffer$1.prototype.writeUIntLE=function(e,t,i,r){(e=+e,t|=0,i|=0,r)||checkInt(this,e,t,i,Math.pow(2,8*i)-1,0);var n=1,a=0;for(this[t]=255&e;++a<i&&(n*=256);)this[t+a]=e/n&255;return t+i},Buffer$1.prototype.writeUIntBE=function(e,t,i,r){(e=+e,t|=0,i|=0,r)||checkInt(this,e,t,i,Math.pow(2,8*i)-1,0);var n=i-1,a=1;for(this[t+n]=255&e;--n>=0&&(a*=256);)this[t+n]=e/a&255;return t+i},Buffer$1.prototype.writeUInt8=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,1,255,0),Buffer$1.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},Buffer$1.prototype.writeUInt16LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,65535,0),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):objectWriteUInt16(this,e,t,true),t+2},Buffer$1.prototype.writeUInt16BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,65535,0),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):objectWriteUInt16(this,e,t,false),t+2},Buffer$1.prototype.writeUInt32LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,4294967295,0),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):objectWriteUInt32(this,e,t,true),t+4},Buffer$1.prototype.writeUInt32BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,4294967295,0),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):objectWriteUInt32(this,e,t,false),t+4},Buffer$1.prototype.writeIntLE=function(e,t,i,r){if(e=+e,t|=0,!r){var n=Math.pow(2,8*i-1);checkInt(this,e,t,i,n-1,-n);}var a=0,o=1,s=0;for(this[t]=255&e;++a<i&&(o*=256);)e<0&&0===s&&0!==this[t+a-1]&&(s=1),this[t+a]=(e/o|0)-s&255;return t+i},Buffer$1.prototype.writeIntBE=function(e,t,i,r){if(e=+e,t|=0,!r){var n=Math.pow(2,8*i-1);checkInt(this,e,t,i,n-1,-n);}var a=i-1,o=1,s=0;for(this[t+a]=255&e;--a>=0&&(o*=256);)e<0&&0===s&&0!==this[t+a+1]&&(s=1),this[t+a]=(e/o|0)-s&255;return t+i},Buffer$1.prototype.writeInt8=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,1,127,-128),Buffer$1.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},Buffer$1.prototype.writeInt16LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,32767,-32768),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):objectWriteUInt16(this,e,t,true),t+2},Buffer$1.prototype.writeInt16BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,32767,-32768),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):objectWriteUInt16(this,e,t,false),t+2},Buffer$1.prototype.writeInt32LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,2147483647,-2147483648),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):objectWriteUInt32(this,e,t,true),t+4},Buffer$1.prototype.writeInt32BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),Buffer$1.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):objectWriteUInt32(this,e,t,false),t+4},Buffer$1.prototype.writeFloatLE=function(e,t,i){return writeFloat(this,e,t,true,i)},Buffer$1.prototype.writeFloatBE=function(e,t,i){return writeFloat(this,e,t,false,i)},Buffer$1.prototype.writeDoubleLE=function(e,t,i){return writeDouble(this,e,t,true,i)},Buffer$1.prototype.writeDoubleBE=function(e,t,i){return writeDouble(this,e,t,false,i)},Buffer$1.prototype.copy=function(e,t,i,r){if(i||(i=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<i&&(r=i),r===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-i&&(r=e.length-t+i);var n,a=r-i;if(this===e&&i<t&&t<r)for(n=a-1;n>=0;--n)e[n+t]=this[n+i];else if(a<1e3||!Buffer$1.TYPED_ARRAY_SUPPORT)for(n=0;n<a;++n)e[n+t]=this[n+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+a),t);return a},Buffer$1.prototype.fill=function(e,t,i,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,i=this.length):"string"==typeof i&&(r=i,i=this.length),1===e.length){var n=e.charCodeAt(0);n<256&&(e=n);}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!Buffer$1.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else "number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var a;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(a=t;a<i;++a)this[a]=e;else {var o=internalIsBuffer(e)?e:utf8ToBytes(new Buffer$1(e,r).toString()),s=o.length;for(a=0;a<i-t;++a)this[a+t]=o[a%s];}return this};var INVALID_BASE64_RE=/[^+\/0-9A-Za-z-_]/g,HeaderTypes;function base64clean(e){if((e=stringtrim(e).replace(INVALID_BASE64_RE,"")).length<2)return "";for(;e.length%4!=0;)e+="=";return e}function stringtrim(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function toHex(e){return e<16?"0"+e.toString(16):e.toString(16)}function utf8ToBytes(e,t){var i;t=t||1/0;for(var r=e.length,n=null,a=[],o=0;o<r;++o){if((i=e.charCodeAt(o))>55295&&i<57344){if(!n){if(i>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&a.push(239,191,189);continue}n=i;continue}if(i<56320){(t-=3)>-1&&a.push(239,191,189),n=i;continue}i=65536+(n-55296<<10|i-56320);}else n&&(t-=3)>-1&&a.push(239,191,189);if(n=null,i<128){if((t-=1)<0)break;a.push(i);}else if(i<2048){if((t-=2)<0)break;a.push(i>>6|192,63&i|128);}else if(i<65536){if((t-=3)<0)break;a.push(i>>12|224,i>>6&63|128,63&i|128);}else {if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;a.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128);}}return a}function asciiToBytes(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}function utf16leToBytes(e,t){for(var i,r,n,a=[],o=0;o<e.length&&!((t-=2)<0);++o)r=(i=e.charCodeAt(o))>>8,n=i%256,a.push(n),a.push(r);return a}function base64ToBytes(e){return toByteArray(base64clean(e))}function blitBuffer(e,t,i,r){for(var n=0;n<r&&!(n+i>=t.length||n>=e.length);++n)t[n+i]=e[n];return n}function isnan(e){return e!=e}function isBuffer(e){return null!=e&&(!!e._isBuffer||isFastBuffer(e)||isSlowBuffer(e))}function isFastBuffer(e){return !!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function isSlowBuffer(e){return "function"==typeof e.readFloatLE&&"function"==typeof e.slice&&isFastBuffer(e.slice(0,0))}!function(e){e[e.BITMAP_INFO_HEADER=40]="BITMAP_INFO_HEADER",e[e.BITMAP_V2_INFO_HEADER=52]="BITMAP_V2_INFO_HEADER",e[e.BITMAP_V3_INFO_HEADER=56]="BITMAP_V3_INFO_HEADER",e[e.BITMAP_V4_HEADER=108]="BITMAP_V4_HEADER",e[e.BITMAP_V5_HEADER=124]="BITMAP_V5_HEADER";}(HeaderTypes||(HeaderTypes={}));var HeaderTypes$1=HeaderTypes,BmpCompression;function maskColor(e,t,i,r){const n=1+~e&e,a=1+~t&t,o=1+~i&i,s=1+~r&r,l=e/n+1,u=t/a+1,h=i/o+1,c=r/s+1;return {shiftRed:t=>(t&e)/n*256/l,shiftGreen:e=>(e&t)/a*256/u,shiftBlue:e=>(e&i)/o*256/h,shiftAlpha:0!==r?e=>(e&r)/s*256/c:()=>255}}!function(e){e[e.NONE=0]="NONE",e[e.BI_RLE8=1]="BI_RLE8",e[e.BI_RLE4=2]="BI_RLE4",e[e.BI_BIT_FIELDS=3]="BI_BIT_FIELDS",e[e.BI_ALPHA_BIT_FIELDS=6]="BI_ALPHA_BIT_FIELDS";}(BmpCompression||(BmpCompression={}));class BmpDecoder{flag;fileSize;reserved1;reserved2;offset;headerSize;width;height;planes;bitPP;compression;rawSize;hr;vr;colors;importantColors;palette;data;maskRed;maskGreen;maskBlue;maskAlpha;toRGBA;pos;bottomUp;buffer;locRed;locGreen;locBlue;locAlpha;shiftRed;shiftGreen;shiftBlue;shiftAlpha;constructor(e,{toRGBA:t}={toRGBA:false}){if(this.buffer=e,this.toRGBA=!!t,this.pos=0,this.bottomUp=true,this.flag=this.buffer.toString("utf-8",0,this.pos+=2),"BM"!==this.flag)throw new Error("Invalid BMP File");this.locRed=this.toRGBA?0:3,this.locGreen=this.toRGBA?1:2,this.locBlue=this.toRGBA?2:1,this.locAlpha=this.toRGBA?3:0,this.parseHeader(),this.parseRGBA();}parseHeader(){if(this.fileSize=this.readUInt32LE(),this.reserved1=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.reserved2=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.offset=this.readUInt32LE(),this.headerSize=this.readUInt32LE(),!(this.headerSize in HeaderTypes$1))throw new Error(`Unsupported BMP header size ${this.headerSize}`);if(this.width=this.readUInt32LE(),this.height=this.readUInt32LE(),this.height=this.height>2147483647?this.height-4294967296:this.height,this.planes=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.bitPP=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.compression=this.readUInt32LE(),this.rawSize=this.readUInt32LE(),this.hr=this.readUInt32LE(),this.vr=this.readUInt32LE(),this.colors=this.readUInt32LE(),this.importantColors=this.readUInt32LE(),32===this.bitPP?(this.maskAlpha=0,this.maskRed=16711680,this.maskGreen=65280,this.maskBlue=255):16===this.bitPP&&(this.maskAlpha=0,this.maskRed=31744,this.maskGreen=992,this.maskBlue=31),(this.headerSize>HeaderTypes$1.BITMAP_INFO_HEADER||this.compression===BmpCompression.BI_BIT_FIELDS||this.compression===BmpCompression.BI_ALPHA_BIT_FIELDS)&&(this.maskRed=this.readUInt32LE(),this.maskGreen=this.readUInt32LE(),this.maskBlue=this.readUInt32LE()),(this.headerSize>HeaderTypes$1.BITMAP_V2_INFO_HEADER||this.compression===BmpCompression.BI_ALPHA_BIT_FIELDS)&&(this.maskAlpha=this.readUInt32LE()),this.headerSize>HeaderTypes$1.BITMAP_V3_INFO_HEADER&&(this.pos+=HeaderTypes$1.BITMAP_V4_HEADER-HeaderTypes$1.BITMAP_V3_INFO_HEADER),this.headerSize>HeaderTypes$1.BITMAP_V4_HEADER&&(this.pos+=HeaderTypes$1.BITMAP_V5_HEADER-HeaderTypes$1.BITMAP_V4_HEADER),this.bitPP<=8||this.colors>0){const e=0===this.colors?1<<this.bitPP:this.colors;this.palette=new Array(e);for(let t=0;t<e;t++){const e=this.buffer.readUInt8(this.pos++),i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++);this.palette[t]={red:r,green:i,blue:e,quad:n};}}this.height<0&&(this.height*=-1,this.bottomUp=false);const e=maskColor(this.maskRed,this.maskGreen,this.maskBlue,this.maskAlpha);this.shiftRed=e.shiftRed,this.shiftGreen=e.shiftGreen,this.shiftBlue=e.shiftBlue,this.shiftAlpha=e.shiftAlpha;}parseRGBA(){switch(this.data=Buffer$1.alloc(this.width*this.height*4),this.bitPP){case 1:this.bit1();break;case 4:this.bit4();break;case 8:this.bit8();break;case 16:this.bit16();break;case 24:this.bit24();break;default:this.bit32();}}bit1(){const e=Math.ceil(this.width/8),t=e%4,i=0!==t?4-t:0;this.scanImage(i,e,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+8*e*4;for(let t=0;t<8&&8*e+t<this.width;t++){const e=this.palette[i>>7-t&1];this.data[r+t*this.locAlpha]=0,this.data[r+4*t+this.locBlue]=e.blue,this.data[r+4*t+this.locGreen]=e.green,this.data[r+4*t+this.locRed]=e.red;}}));}bit4(){if(this.compression===BmpCompression.BI_RLE4){this.data.fill(0);let e=false,t=this.bottomUp?this.height-1:0,i=0;for(;i<this.data.length;){const r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++);if(0===r){if(0===n){t+=this.bottomUp?-1:1,i=t*this.width*4,e=false;continue}if(1===n)break;if(2===n){const e=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);t+=this.bottomUp?-r:r,i+=r*this.width*4+4*e;}else {let t=this.buffer.readUInt8(this.pos++);for(let r=0;r<n;r++)i=this.setPixelData(i,e?15&t:(240&t)>>4),1&r&&r+1<n&&(t=this.buffer.readUInt8(this.pos++)),e=!e;1==(n+1>>1&1)&&this.pos++;}}else for(let t=0;t<r;t++)i=this.setPixelData(i,e?15&n:(240&n)>>4),e=!e;}}else {const e=Math.ceil(this.width/2),t=e%4,i=0!==t?4-t:0;this.scanImage(i,e,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+2*e*4,n=i>>4;let a=this.palette[n];if(this.data[r]=0,this.data[r+1]=a.blue,this.data[r+2]=a.green,this.data[r+3]=a.red,2*e+1>=this.width)return false;const o=15&i;a=this.palette[o],this.data[r+4]=0,this.data[r+4+1]=a.blue,this.data[r+4+2]=a.green,this.data[r+4+3]=a.red;}));}}bit8(){if(this.compression===BmpCompression.BI_RLE8){this.data.fill(0);let e=this.bottomUp?this.height-1:0,t=0;for(;t<this.data.length;){const i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);if(0===i){if(0===r){e+=this.bottomUp?-1:1,t=e*this.width*4;continue}if(1===r)break;if(2===r){const i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);e+=this.bottomUp?-r:r,t+=r*this.width*4+4*i;}else {for(let e=0;e<r;e++){const e=this.buffer.readUInt8(this.pos++);t=this.setPixelData(t,e);} true&r&&this.pos++;}}else for(let e=0;e<i;e++)t=this.setPixelData(t,r);}}else {const e=this.width%4,t=0!==e?4-e:0;this.scanImage(t,this.width,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+4*e;if(i<this.palette.length){const e=this.palette[i];this.data[r]=0,this.data[r+1]=e.blue,this.data[r+2]=e.green,this.data[r+3]=e.red;}else this.data[r]=0,this.data[r+1]=255,this.data[r+2]=255,this.data[r+3]=255;}));}}bit16(){const e=this.width%2*2;this.scanImage(e,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.buffer.readUInt16LE(this.pos);this.pos+=2,this.data[i+this.locRed]=this.shiftRed(r),this.data[i+this.locGreen]=this.shiftGreen(r),this.data[i+this.locBlue]=this.shiftBlue(r),this.data[i+this.locAlpha]=this.shiftAlpha(r);}));}bit24(){const e=this.width%4;this.scanImage(e,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++),a=this.buffer.readUInt8(this.pos++);this.data[i+this.locRed]=a,this.data[i+this.locGreen]=n,this.data[i+this.locBlue]=r,this.data[i+this.locAlpha]=0;}));}bit32(){this.scanImage(0,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.readUInt32LE();this.data[i+this.locRed]=this.shiftRed(r),this.data[i+this.locGreen]=this.shiftGreen(r),this.data[i+this.locBlue]=this.shiftBlue(r),this.data[i+this.locAlpha]=this.shiftAlpha(r);}));}scanImage(e=0,t=this.width,i){for(let r=this.height-1;r>=0;r--){const n=this.bottomUp?r:this.height-1-r;for(let e=0;e<t;e++){if(false===i.call(this,e,n))return}this.pos+=e;}}readUInt32LE(){const e=this.buffer.readUInt32LE(this.pos);return this.pos+=4,e}setPixelData(e,t){const{blue:i,green:r,red:n}=this.palette[t];return this.data[e+this.locAlpha]=0,this.data[e+1+this.locBlue]=i,this.data[e+2+this.locGreen]=r,this.data[e+3+this.locRed]=n,e+4}}function createInteger(e){return e.reduce(((e,t)=>e<<1|t),0)}function createColor(e){return e.quad<<24|e.red<<16|e.green<<8|e.blue}class BmpEncoder{fileSize;reserved1;reserved2;offset;width;flag;height;planes;bitPP;compress;hr;vr;colors;importantColors;rawSize;headerSize;data;palette;extraBytes;buffer;bytesInColor;pos;constructor(e){switch(this.buffer=e.data,this.width=e.width,this.height=e.height,this.headerSize=HeaderTypes$1.BITMAP_INFO_HEADER,this.flag="BM",this.bitPP=e.bitPP||24,this.offset=54,this.reserved1=e.reserved1||0,this.reserved2=e.reserved2||0,this.planes=1,this.compress=0,this.hr=e.hr||0,this.vr=e.vr||0,this.importantColors=e.importantColors||0,this.colors=Math.min(2**(this.bitPP-1||1),e.colors||1/0),this.palette=e.palette||[],this.colors&&this.bitPP<16?this.offset+=4*this.colors:this.colors=0,this.bitPP){case 32:this.bytesInColor=4;break;case 16:this.bytesInColor=2;break;case 8:this.bytesInColor=1;break;case 4:this.bytesInColor=.5;break;case 1:this.bytesInColor=1/8;break;default:this.bytesInColor=3,this.bitPP=24;}const t=this.width*this.bitPP/32,i=Math.ceil(t);this.extraBytes=4*(i-t),this.rawSize=this.height*i*4+2,this.fileSize=this.rawSize+this.offset,this.data=Buffer$1.alloc(this.fileSize,1),this.pos=0,this.encode();}encode(){switch(this.pos=0,this.writeHeader(),this.bitPP){case 32:this.bit32();break;case 16:this.bit16();break;case 8:this.bit8();break;case 4:this.bit4();break;case 1:this.bit1();break;default:this.bit24();}}writeHeader(){this.data.write(this.flag,this.pos,2),this.pos+=2,this.writeUInt32LE(this.fileSize),this.writeUInt32LE(this.reserved1<<16|this.reserved2),this.writeUInt32LE(this.offset),this.writeUInt32LE(this.headerSize),this.writeUInt32LE(this.width),this.writeUInt32LE(this.height),this.data.writeUInt16LE(this.planes,this.pos),this.pos+=2,this.data.writeUInt16LE(this.bitPP,this.pos),this.pos+=2,this.writeUInt32LE(this.compress),this.writeUInt32LE(this.rawSize),this.writeUInt32LE(this.hr),this.writeUInt32LE(this.vr),this.writeUInt32LE(this.colors),this.writeUInt32LE(this.importantColors);}bit1(){this.palette.length&&2===this.colors?this.initColors(1):(this.writeUInt32LE(16777215),this.writeUInt32LE(0)),this.pos+=1;let e=[];this.writeImage(((t,i,r)=>{let n=i;n++;const a=this.buffer[n++],o=this.buffer[n++],s=.2126*this.buffer[n++]+.7152*o+.0722*a;return e.push(s>127?0:1),(r+1)%8==0?(this.data[t-1]=createInteger(e),e=[]):r===this.width-1&&e.length>0&&(this.data[t-1]=createInteger(e)<<4,e=[]),n}));}bit4(){const e=this.initColors(4);let t=[];this.writeImage(((i,r,n)=>{let a=r;const o=createColor({quad:this.buffer[a++],blue:this.buffer[a++],green:this.buffer[a++],red:this.buffer[a++]}),s=e.findIndex((e=>e===o));return -1!==s?t.push(s):t.push(0),(n+1)%2==0&&(this.data[i]=t[0]<<4|t[1],t=[]),a}));}bit8(){const e=this.initColors(8);this.writeImage(((t,i)=>{let r=i;const n=createColor({quad:this.buffer[r++],blue:this.buffer[r++],green:this.buffer[r++],red:this.buffer[r++]}),a=e.findIndex((e=>e===n));return this.data[t]=-1!==a?a:0,r}));}bit16(){this.writeImage(((e,t)=>{let i=t+1;const r=this.buffer[i++]/8,n=this.buffer[i++]/8,a=this.buffer[i++]/8<<10|n<<5|r;return this.data[e]=255&a,this.data[e+1]=(65280&a)>>8,i}));}bit24(){this.writeImage(((e,t)=>{let i=t+1;return this.data[e]=this.buffer[i++],this.data[e+1]=this.buffer[i++],this.data[e+2]=this.buffer[i++],i}));}bit32(){this.writeImage(((e,t)=>{let i=t;return this.data[e+3]=this.buffer[i++],this.data[e]=this.buffer[i++],this.data[e+1]=this.buffer[i++],this.data[e+2]=this.buffer[i++],i}));}writeImage(e){const t=this.extraBytes+this.width*this.bytesInColor;let i=0;for(let r=0;r<this.height;r++)for(let n=0;n<this.width;n++){const a=Math.floor(this.pos+(this.height-1-r)*t+n*this.bytesInColor);i=e.call(this,a,i,n,r);}}initColors(e){const t=[];if(!this.palette.length)throw new Error(`To encode ${e}-bit BMPs a pallette is needed. Please choose up to ${this.colors} colors. Colors must be 32-bit integers.`);for(let e=0;e<this.colors;e++){const i=createColor(this.palette[e]);this.writeUInt32LE(i),t.push(i);}return t}writeUInt32LE(e){this.data.writeUInt32LE(e,this.pos),this.pos+=4;}}function decode$2(e,t){return new BmpDecoder(e,t)}function encode$2(e){return new BmpEncoder(e)}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var trimLeft=/^\s+/,trimRight=/\s+$/;function tinycolor(e,t){if(t=t||{},(e=e||"")instanceof tinycolor)return e;if(!(this instanceof tinycolor))return new tinycolor(e,t);var i=inputToRGB(e);this._originalInput=e,this._r=i.r,this._g=i.g,this._b=i.b,this._a=i.a,this._roundA=Math.round(100*this._a)/100,this._format=t.format||i.format,this._gradientType=t.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=i.ok;}function inputToRGB(e){var t={r:0,g:0,b:0},i=1,r=null,n=null,a=null,o=false,s=false;return "string"==typeof e&&(e=stringInputToObject(e)),"object"==_typeof(e)&&(isValidCSSUnit(e.r)&&isValidCSSUnit(e.g)&&isValidCSSUnit(e.b)?(t=rgbToRgb(e.r,e.g,e.b),o=true,s="%"===String(e.r).substr(-1)?"prgb":"rgb"):isValidCSSUnit(e.h)&&isValidCSSUnit(e.s)&&isValidCSSUnit(e.v)?(r=convertToPercentage(e.s),n=convertToPercentage(e.v),t=hsvToRgb(e.h,r,n),o=true,s="hsv"):isValidCSSUnit(e.h)&&isValidCSSUnit(e.s)&&isValidCSSUnit(e.l)&&(r=convertToPercentage(e.s),a=convertToPercentage(e.l),t=hslToRgb(e.h,r,a),o=true,s="hsl"),e.hasOwnProperty("a")&&(i=e.a)),i=boundAlpha(i),{ok:o,format:e.format||s,r:Math.min(255,Math.max(t.r,0)),g:Math.min(255,Math.max(t.g,0)),b:Math.min(255,Math.max(t.b,0)),a:i}}function rgbToRgb(e,t,i){return {r:255*bound01(e,255),g:255*bound01(t,255),b:255*bound01(i,255)}}function rgbToHsl(e,t,i){e=bound01(e,255),t=bound01(t,255),i=bound01(i,255);var r,n,a=Math.max(e,t,i),o=Math.min(e,t,i),s=(a+o)/2;if(a==o)r=n=0;else {var l=a-o;switch(n=s>.5?l/(2-a-o):l/(a+o),a){case e:r=(t-i)/l+(t<i?6:0);break;case t:r=(i-e)/l+2;break;case i:r=(e-t)/l+4;}r/=6;}return {h:r,s:n,l:s}}function hslToRgb(e,t,i){var r,n,a;function o(e,t,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?e+6*(t-e)*i:i<.5?t:i<2/3?e+(t-e)*(2/3-i)*6:e}if(e=bound01(e,360),t=bound01(t,100),i=bound01(i,100),0===t)r=n=a=i;else {var s=i<.5?i*(1+t):i+t-i*t,l=2*i-s;r=o(l,s,e+1/3),n=o(l,s,e),a=o(l,s,e-1/3);}return {r:255*r,g:255*n,b:255*a}}function rgbToHsv(e,t,i){e=bound01(e,255),t=bound01(t,255),i=bound01(i,255);var r,n,a=Math.max(e,t,i),o=Math.min(e,t,i),s=a,l=a-o;if(n=0===a?0:l/a,a==o)r=0;else {switch(a){case e:r=(t-i)/l+(t<i?6:0);break;case t:r=(i-e)/l+2;break;case i:r=(e-t)/l+4;}r/=6;}return {h:r,s:n,v:s}}function hsvToRgb(e,t,i){e=6*bound01(e,360),t=bound01(t,100),i=bound01(i,100);var r=Math.floor(e),n=e-r,a=i*(1-t),o=i*(1-n*t),s=i*(1-(1-n)*t),l=r%6;return {r:255*[i,o,a,a,s,i][l],g:255*[s,i,i,o,a,a][l],b:255*[a,a,s,i,i,o][l]}}function rgbToHex(e,t,i,r){var n=[pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16))];return r&&n[0].charAt(0)==n[0].charAt(1)&&n[1].charAt(0)==n[1].charAt(1)&&n[2].charAt(0)==n[2].charAt(1)?n[0].charAt(0)+n[1].charAt(0)+n[2].charAt(0):n.join("")}function rgbaToHex(e,t,i,r,n){var a=[pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16)),pad2(convertDecimalToHex(r))];return n&&a[0].charAt(0)==a[0].charAt(1)&&a[1].charAt(0)==a[1].charAt(1)&&a[2].charAt(0)==a[2].charAt(1)&&a[3].charAt(0)==a[3].charAt(1)?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0):a.join("")}function rgbaToArgbHex(e,t,i,r){return [pad2(convertDecimalToHex(r)),pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16))].join("")}function _desaturate(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.s-=t/100,i.s=clamp01(i.s),tinycolor(i)}function _saturate(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.s+=t/100,i.s=clamp01(i.s),tinycolor(i)}function _greyscale(e){return tinycolor(e).desaturate(100)}function _lighten(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.l+=t/100,i.l=clamp01(i.l),tinycolor(i)}function _brighten(e,t){t=0===t?0:t||10;var i=tinycolor(e).toRgb();return i.r=Math.max(0,Math.min(255,i.r-Math.round(-t/100*255))),i.g=Math.max(0,Math.min(255,i.g-Math.round(-t/100*255))),i.b=Math.max(0,Math.min(255,i.b-Math.round(-t/100*255))),tinycolor(i)}function _darken(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.l-=t/100,i.l=clamp01(i.l),tinycolor(i)}function _spin(e,t){var i=tinycolor(e).toHsl(),r=(i.h+t)%360;return i.h=r<0?360+r:r,tinycolor(i)}function _complement(e){var t=tinycolor(e).toHsl();return t.h=(t.h+180)%360,tinycolor(t)}function polyad(e,t){if(isNaN(t)||t<=0)throw new Error("Argument to polyad must be a positive number");for(var i=tinycolor(e).toHsl(),r=[tinycolor(e)],n=360/t,a=1;a<t;a++)r.push(tinycolor({h:(i.h+a*n)%360,s:i.s,l:i.l}));return r}function _splitcomplement(e){var t=tinycolor(e).toHsl(),i=t.h;return [tinycolor(e),tinycolor({h:(i+72)%360,s:t.s,l:t.l}),tinycolor({h:(i+216)%360,s:t.s,l:t.l})]}function _analogous(e,t,i){t=t||6,i=i||30;var r=tinycolor(e).toHsl(),n=360/i,a=[tinycolor(e)];for(r.h=(r.h-(n*t>>1)+720)%360;--t;)r.h=(r.h+n)%360,a.push(tinycolor(r));return a}function _monochromatic(e,t){t=t||6;for(var i=tinycolor(e).toHsv(),r=i.h,n=i.s,a=i.v,o=[],s=1/t;t--;)o.push(tinycolor({h:r,s:n,v:a})),a=(a+s)%1;return o}tinycolor.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return !this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var e=this.toRgb();return (299*e.r+587*e.g+114*e.b)/1e3},getLuminance:function(){var e,t,i,r=this.toRgb();return e=r.r/255,t=r.g/255,i=r.b/255,.2126*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.7152*(t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4))+.0722*(i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4))},setAlpha:function(e){return this._a=boundAlpha(e),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var e=rgbToHsv(this._r,this._g,this._b);return {h:360*e.h,s:e.s,v:e.v,a:this._a}},toHsvString:function(){var e=rgbToHsv(this._r,this._g,this._b),t=Math.round(360*e.h),i=Math.round(100*e.s),r=Math.round(100*e.v);return 1==this._a?"hsv("+t+", "+i+"%, "+r+"%)":"hsva("+t+", "+i+"%, "+r+"%, "+this._roundA+")"},toHsl:function(){var e=rgbToHsl(this._r,this._g,this._b);return {h:360*e.h,s:e.s,l:e.l,a:this._a}},toHslString:function(){var e=rgbToHsl(this._r,this._g,this._b),t=Math.round(360*e.h),i=Math.round(100*e.s),r=Math.round(100*e.l);return 1==this._a?"hsl("+t+", "+i+"%, "+r+"%)":"hsla("+t+", "+i+"%, "+r+"%, "+this._roundA+")"},toHex:function(e){return rgbToHex(this._r,this._g,this._b,e)},toHexString:function(e){return "#"+this.toHex(e)},toHex8:function(e){return rgbaToHex(this._r,this._g,this._b,this._a,e)},toHex8String:function(e){return "#"+this.toHex8(e)},toRgb:function(){return {r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return {r:Math.round(100*bound01(this._r,255))+"%",g:Math.round(100*bound01(this._g,255))+"%",b:Math.round(100*bound01(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+Math.round(100*bound01(this._r,255))+"%, "+Math.round(100*bound01(this._g,255))+"%, "+Math.round(100*bound01(this._b,255))+"%)":"rgba("+Math.round(100*bound01(this._r,255))+"%, "+Math.round(100*bound01(this._g,255))+"%, "+Math.round(100*bound01(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":!(this._a<1)&&(hexNames[rgbToHex(this._r,this._g,this._b,true)]||false)},toFilter:function(e){var t="#"+rgbaToArgbHex(this._r,this._g,this._b,this._a),i=t,r=this._gradientType?"GradientType = 1, ":"";if(e){var n=tinycolor(e);i="#"+rgbaToArgbHex(n._r,n._g,n._b,n._a);}return "progid:DXImageTransform.Microsoft.gradient("+r+"startColorstr="+t+",endColorstr="+i+")"},toString:function(e){var t=!!e;e=e||this._format;var i=false,r=this._a<1&&this._a>=0;return t||!r||"hex"!==e&&"hex6"!==e&&"hex3"!==e&&"hex4"!==e&&"hex8"!==e&&"name"!==e?("rgb"===e&&(i=this.toRgbString()),"prgb"===e&&(i=this.toPercentageRgbString()),"hex"!==e&&"hex6"!==e||(i=this.toHexString()),"hex3"===e&&(i=this.toHexString(true)),"hex4"===e&&(i=this.toHex8String(true)),"hex8"===e&&(i=this.toHex8String()),"name"===e&&(i=this.toName()),"hsl"===e&&(i=this.toHslString()),"hsv"===e&&(i=this.toHsvString()),i||this.toHexString()):"name"===e&&0===this._a?this.toName():this.toRgbString()},clone:function(){return tinycolor(this.toString())},_applyModification:function(e,t){var i=e.apply(null,[this].concat([].slice.call(t)));return this._r=i._r,this._g=i._g,this._b=i._b,this.setAlpha(i._a),this},lighten:function(){return this._applyModification(_lighten,arguments)},brighten:function(){return this._applyModification(_brighten,arguments)},darken:function(){return this._applyModification(_darken,arguments)},desaturate:function(){return this._applyModification(_desaturate,arguments)},saturate:function(){return this._applyModification(_saturate,arguments)},greyscale:function(){return this._applyModification(_greyscale,arguments)},spin:function(){return this._applyModification(_spin,arguments)},_applyCombination:function(e,t){return e.apply(null,[this].concat([].slice.call(t)))},analogous:function(){return this._applyCombination(_analogous,arguments)},complement:function(){return this._applyCombination(_complement,arguments)},monochromatic:function(){return this._applyCombination(_monochromatic,arguments)},splitcomplement:function(){return this._applyCombination(_splitcomplement,arguments)},triad:function(){return this._applyCombination(polyad,[3])},tetrad:function(){return this._applyCombination(polyad,[4])}},tinycolor.fromRatio=function(e,t){if("object"==_typeof(e)){var i={};for(var r in e)e.hasOwnProperty(r)&&(i[r]="a"===r?e[r]:convertToPercentage(e[r]));e=i;}return tinycolor(e,t)},tinycolor.equals=function(e,t){return !(!e||!t)&&tinycolor(e).toRgbString()==tinycolor(t).toRgbString()},tinycolor.random=function(){return tinycolor.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})},tinycolor.mix=function(e,t,i){i=0===i?0:i||50;var r=tinycolor(e).toRgb(),n=tinycolor(t).toRgb(),a=i/100;return tinycolor({r:(n.r-r.r)*a+r.r,g:(n.g-r.g)*a+r.g,b:(n.b-r.b)*a+r.b,a:(n.a-r.a)*a+r.a})},tinycolor.readability=function(e,t){var i=tinycolor(e),r=tinycolor(t);return (Math.max(i.getLuminance(),r.getLuminance())+.05)/(Math.min(i.getLuminance(),r.getLuminance())+.05)},tinycolor.isReadable=function(e,t,i){var r,n,a=tinycolor.readability(e,t);switch(n=false,(r=validateWCAG2Parms(i)).level+r.size){case "AAsmall":case "AAAlarge":n=a>=4.5;break;case "AAlarge":n=a>=3;break;case "AAAsmall":n=a>=7;}return n},tinycolor.mostReadable=function(e,t,i){var r,n,a,o,s=null,l=0;n=(i=i||{}).includeFallbackColors,a=i.level,o=i.size;for(var u=0;u<t.length;u++)(r=tinycolor.readability(e,t[u]))>l&&(l=r,s=tinycolor(t[u]));return tinycolor.isReadable(e,s,{level:a,size:o})||!n?s:(i.includeFallbackColors=false,tinycolor.mostReadable(e,["#fff","#000"],i))};var names$1=tinycolor.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},hexNames=tinycolor.hexNames=flip(names$1);function flip(e){var t={};for(var i in e)e.hasOwnProperty(i)&&(t[e[i]]=i);return t}function boundAlpha(e){return e=parseFloat(e),(isNaN(e)||e<0||e>1)&&(e=1),e}function bound01(e,t){isOnePointZero(e)&&(e="100%");var i=isPercentage(e);return e=Math.min(t,Math.max(0,parseFloat(e))),i&&(e=parseInt(e*t,10)/100),Math.abs(e-t)<1e-6?1:e%t/parseFloat(t)}function clamp01(e){return Math.min(1,Math.max(0,e))}function parseIntFromHex(e){return parseInt(e,16)}function isOnePointZero(e){return "string"==typeof e&&-1!=e.indexOf(".")&&1===parseFloat(e)}function isPercentage(e){return "string"==typeof e&&-1!=e.indexOf("%")}function pad2(e){return 1==e.length?"0"+e:""+e}function convertToPercentage(e){return e<=1&&(e=100*e+"%"),e}function convertDecimalToHex(e){return Math.round(255*parseFloat(e)).toString(16)}function convertHexToDecimal(e){return parseIntFromHex(e)/255}var matchers=(CSS_UNIT="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",PERMISSIVE_MATCH3="[\\s|\\(]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")\\s*\\)?",PERMISSIVE_MATCH4="[\\s|\\(]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")[,|\\s]+("+CSS_UNIT+")\\s*\\)?",{CSS_UNIT:new RegExp(CSS_UNIT),rgb:new RegExp("rgb"+PERMISSIVE_MATCH3),rgba:new RegExp("rgba"+PERMISSIVE_MATCH4),hsl:new RegExp("hsl"+PERMISSIVE_MATCH3),hsla:new RegExp("hsla"+PERMISSIVE_MATCH4),hsv:new RegExp("hsv"+PERMISSIVE_MATCH3),hsva:new RegExp("hsva"+PERMISSIVE_MATCH4),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}),CSS_UNIT,PERMISSIVE_MATCH3,PERMISSIVE_MATCH4;function isValidCSSUnit(e){return !!matchers.CSS_UNIT.exec(e)}function stringInputToObject(e){e=e.replace(trimLeft,"").replace(trimRight,"").toLowerCase();var t,i=false;if(names$1[e])e=names$1[e],i=true;else if("transparent"==e)return {r:0,g:0,b:0,a:0,format:"name"};return (t=matchers.rgb.exec(e))?{r:t[1],g:t[2],b:t[3]}:(t=matchers.rgba.exec(e))?{r:t[1],g:t[2],b:t[3],a:t[4]}:(t=matchers.hsl.exec(e))?{h:t[1],s:t[2],l:t[3]}:(t=matchers.hsla.exec(e))?{h:t[1],s:t[2],l:t[3],a:t[4]}:(t=matchers.hsv.exec(e))?{h:t[1],s:t[2],v:t[3]}:(t=matchers.hsva.exec(e))?{h:t[1],s:t[2],v:t[3],a:t[4]}:(t=matchers.hex8.exec(e))?{r:parseIntFromHex(t[1]),g:parseIntFromHex(t[2]),b:parseIntFromHex(t[3]),a:convertHexToDecimal(t[4]),format:i?"name":"hex8"}:(t=matchers.hex6.exec(e))?{r:parseIntFromHex(t[1]),g:parseIntFromHex(t[2]),b:parseIntFromHex(t[3]),format:i?"name":"hex"}:(t=matchers.hex4.exec(e))?{r:parseIntFromHex(t[1]+""+t[1]),g:parseIntFromHex(t[2]+""+t[2]),b:parseIntFromHex(t[3]+""+t[3]),a:convertHexToDecimal(t[4]+""+t[4]),format:i?"name":"hex8"}:!!(t=matchers.hex3.exec(e))&&{r:parseIntFromHex(t[1]+""+t[1]),g:parseIntFromHex(t[2]+""+t[2]),b:parseIntFromHex(t[3]+""+t[3]),format:i?"name":"hex"}}function validateWCAG2Parms(e){var t,i;return "AA"!==(t=((e=e||{level:"AA",size:"small"}).level||"AA").toUpperCase())&&"AAA"!==t&&(t="AA"),"small"!==(i=(e.size||"small").toLowerCase())&&"large"!==i&&(i="small"),{level:t,size:i}}function clone(e){const t={width:e.bitmap.width,height:e.bitmap.height,data:Buffer$1.from(e.bitmap.data)};return new e.constructor(t)}function scan(e,t,i,r,n,a){let o,s,l,u,h;if("function"==typeof t)h=t,o=0,s=0,l=e.bitmap.width,u=e.bitmap.height;else {if(o=t,"number"!=typeof i)throw new Error("y must be a number");if(s=i,"number"!=typeof r)throw new Error("w must be a number");if(l=r,"number"!=typeof n)throw new Error("h must be a number");if(u=n,"function"!=typeof a)throw new Error("cb must be a function");h=a;}o=Math.round(o),s=Math.round(s),l=Math.round(l),u=Math.round(u);const c=h.bind(e);for(let t=s;t<s+u;t++)for(let i=o;i<o+l;i++){c(i,t,e.bitmap.width*t+i<<2);}return e}function*scanIterator(e,t,i,r,n){t=Math.round(t),i=Math.round(i),r=Math.round(r),n=Math.round(n);for(let a=i;a<i+n;a++)for(let i=t;i<t+r;i++){const t=e.bitmap.width*a+i<<2;yield {x:i,y:a,idx:t,image:e};}}function intToRGBA$1(e){if("number"!=typeof e)throw new Error("i must be a number");const t={r:0,g:0,b:0,a:0};return t.r=Math.floor(e/Math.pow(256,3)),t.g=Math.floor((e-t.r*Math.pow(256,3))/Math.pow(256,2)),t.b=Math.floor((e-t.r*Math.pow(256,3)-t.g*Math.pow(256,2))/Math.pow(256,1)),t.a=Math.floor((e-t.r*Math.pow(256,3)-t.g*Math.pow(256,2)-t.b*Math.pow(256,1))/Math.pow(256,0)),t}function colorDiff(e,t){const i=e=>Math.pow(e,2),{max:r}=Math,n="a"in e?e.a:255,a="a"in t?t.a:255;return (r(i(e.r-t.r),i(e.r-t.r-n+a))+r(i(e.g-t.g),i(e.g-t.g-n+a))+r(i(e.b-t.b),i(e.b-t.b-n+a)))/195075}function limit255(e){return e=Math.max(e,0),e=Math.min(e,255)}function cssColorToHex(e){return "number"==typeof e?e:parseInt(tinycolor(e).toHex8(),16)}function encode$1(e,t={}){return scan({bitmap:e},0,0,e.width,e.height,(function(t,i,r){const n=e.data[r+0],a=e.data[r+1],o=e.data[r+2],s=e.data[r+3];e.data[r+0]=s,e.data[r+1]=o,e.data[r+2]=a,e.data[r+3]=n;})),encode$2({...e,...t}).data}function decode$1(e,t){const i=decode$2(e,t);return scan({bitmap:i},0,0,i.width,i.height,(function(e,t,r){const n=i.data[r+1],a=i.data[r+2],o=i.data[r+3];i.data[r+0]=o,i.data[r+1]=a,i.data[r+2]=n,i.data[r+3]=255;})),i}function msBmp(){return {mime:"image/x-ms-bmp",encode:encode$1,decode:decode$1}}function bmp(){return {mime:"image/bmp",encode:encode$1,decode:decode$1}}var omggif={},GifReader_1,GifWriter_1;function GifWriter(e,t,i,r){var n=0,a=void 0===(r=void 0===r?{}:r).loop?null:r.loop,o=void 0===r.palette?null:r.palette;if(t<=0||i<=0||t>65535||i>65535)throw new Error("Width/Height invalid.");function s(e){var t=e.length;if(t<2||t>256||t&t-1)throw new Error("Invalid code/color length, must be power of 2 and 2 .. 256.");return t}e[n++]=71,e[n++]=73,e[n++]=70,e[n++]=56,e[n++]=57,e[n++]=97;var l=0,u=0;if(null!==o){for(var h=s(o);h>>=1;)++l;if(h=1<<l,--l,void 0!==r.background){if((u=r.background)>=h)throw new Error("Background index out of range.");if(0===u)throw new Error("Background index explicitly passed as 0.")}}if(e[n++]=255&t,e[n++]=t>>8&255,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=(null!==o?128:0)|l,e[n++]=u,e[n++]=0,null!==o)for(var c=0,f=o.length;c<f;++c){var d=o[c];e[n++]=d>>16&255,e[n++]=d>>8&255,e[n++]=255&d;}if(null!==a){if(a<0||a>65535)throw new Error("Loop count invalid.");e[n++]=33,e[n++]=255,e[n++]=11,e[n++]=78,e[n++]=69,e[n++]=84,e[n++]=83,e[n++]=67,e[n++]=65,e[n++]=80,e[n++]=69,e[n++]=50,e[n++]=46,e[n++]=48,e[n++]=3,e[n++]=1,e[n++]=255&a,e[n++]=a>>8&255,e[n++]=0;}var p=false;this.addFrame=function(t,i,r,a,l,u){if(true===p&&(--n,p=false),u=void 0===u?{}:u,t<0||i<0||t>65535||i>65535)throw new Error("x/y invalid.");if(r<=0||a<=0||r>65535||a>65535)throw new Error("Width/Height invalid.");if(l.length<r*a)throw new Error("Not enough pixels for the frame size.");var h=true,c=u.palette;if(null==c&&(h=false,c=o),null==c)throw new Error("Must supply either a local or global palette.");for(var f=s(c),d=0;f>>=1;)++d;f=1<<d;var m=void 0===u.delay?0:u.delay,_=void 0===u.disposal?0:u.disposal;if(_<0||_>3)throw new Error("Disposal out of range.");var g=false,b=0;if(void 0!==u.transparent&&null!==u.transparent&&(g=true,(b=u.transparent)<0||b>=f))throw new Error("Transparent color index.");if((0!==_||g||0!==m)&&(e[n++]=33,e[n++]=249,e[n++]=4,e[n++]=_<<2|(true===g?1:0),e[n++]=255&m,e[n++]=m>>8&255,e[n++]=b,e[n++]=0),e[n++]=44,e[n++]=255&t,e[n++]=t>>8&255,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=255&r,e[n++]=r>>8&255,e[n++]=255&a,e[n++]=a>>8&255,e[n++]=true===h?128|d-1:0,true===h)for(var y=0,w=c.length;y<w;++y){var v=c[y];e[n++]=v>>16&255,e[n++]=v>>8&255,e[n++]=255&v;}return n=GifWriterOutputLZWCodeStream(e,n,d<2?2:d,l)},this.end=function(){return false===p&&(e[n++]=59,p=true),n},this.getOutputBuffer=function(){return e},this.setOutputBuffer=function(t){e=t;},this.getOutputBufferPosition=function(){return n},this.setOutputBufferPosition=function(e){n=e;};}function GifWriterOutputLZWCodeStream(e,t,i,r){e[t++]=i;var n=t++,a=1<<i,o=a-1,s=a+1,l=s+1,u=i+1,h=0,c=0;function f(i){for(;h>=i;)e[t++]=255&c,c>>=8,h-=8,t===n+256&&(e[n]=255,n=t++);}function d(e){c|=e<<h,h+=u,f(8);}var p=r[0]&o,m={};d(a);for(var _=1,g=r.length;_<g;++_){var b=r[_]&o,y=p<<8|b,w=m[y];if(void 0===w){for(c|=p<<h,h+=u;h>=8;)e[t++]=255&c,c>>=8,h-=8,t===n+256&&(e[n]=255,n=t++);4096===l?(d(a),l=s+1,u=i+1,m={}):(l>=1<<u&&++u,m[y]=l++),p=b;}else p=w;}return d(p),d(s),f(1),n+1===t?e[n]=0:(e[n]=t-n-1,e[t++]=0),t}function GifReader(e){var t=0;if(71!==e[t++]||73!==e[t++]||70!==e[t++]||56!==e[t++]||56!=(e[t++]+1&253)||97!==e[t++])throw new Error("Invalid GIF 87a/89a header.");var i=e[t++]|e[t++]<<8,r=e[t++]|e[t++]<<8,n=e[t++],a=n>>7,o=1<<(7&n)+1;e[t++],e[t++];var s=null,l=null;a&&(s=t,l=o,t+=3*o);var u=true,h=[],c=0,f=null,d=0,p=null;for(this.width=i,this.height=r;u&&t<e.length;)switch(e[t++]){case 33:switch(e[t++]){case 255:if(11!==e[t]||78==e[t+1]&&69==e[t+2]&&84==e[t+3]&&83==e[t+4]&&67==e[t+5]&&65==e[t+6]&&80==e[t+7]&&69==e[t+8]&&50==e[t+9]&&46==e[t+10]&&48==e[t+11]&&3==e[t+12]&&1==e[t+13]&&0==e[t+16])t+=14,p=e[t++]|e[t++]<<8,t++;else for(t+=12;;){if(!((I=e[t++])>=0))throw Error("Invalid block size");if(0===I)break;t+=I;}break;case 249:if(4!==e[t++]||0!==e[t+4])throw new Error("Invalid graphics extension block.");var m=e[t++];c=e[t++]|e[t++]<<8,f=e[t++],1&m||(f=null),d=m>>2&7,t++;break;case 254:for(;;){if(!((I=e[t++])>=0))throw Error("Invalid block size");if(0===I)break;t+=I;}break;default:throw new Error("Unknown graphic control label: 0x"+e[t-1].toString(16))}break;case 44:var _=e[t++]|e[t++]<<8,g=e[t++]|e[t++]<<8,b=e[t++]|e[t++]<<8,y=e[t++]|e[t++]<<8,w=e[t++],v=w>>6&1,x=1<<(7&w)+1,E=s,k=l,S=false;if(w>>7){S=true;E=t,k=x,t+=3*x;}var A=t;for(t++;;){var I;if(!((I=e[t++])>=0))throw Error("Invalid block size");if(0===I)break;t+=I;}h.push({x:_,y:g,width:b,height:y,has_local_palette:S,palette_offset:E,palette_size:k,data_offset:A,data_length:t-A,transparent_index:f,interlaced:!!v,delay:c,disposal:d});break;case 59:u=false;break;default:throw new Error("Unknown gif block: 0x"+e[t-1].toString(16))}this.numFrames=function(){return h.length},this.loopCount=function(){return p},this.frameInfo=function(e){if(e<0||e>=h.length)throw new Error("Frame index out of range.");return h[e]},this.decodeAndBlitFrameBGRA=function(t,r){var n=this.frameInfo(t),a=n.width*n.height,o=new Uint8Array(a);GifReaderLZWOutputIndexStream(e,n.data_offset,o,a);var s=n.palette_offset,l=n.transparent_index;null===l&&(l=256);var u=n.width,h=i-u,c=u,f=4*(n.y*i+n.x),d=4*((n.y+n.height)*i+n.x),p=f,m=4*h;true===n.interlaced&&(m+=4*i*7);for(var _=8,g=0,b=o.length;g<b;++g){var y=o[g];if(0===c&&(c=u,(p+=m)>=d&&(m=4*h+4*i*(_-1),p=f+(u+h)*(_<<1),_>>=1)),y===l)p+=4;else {var w=e[s+3*y],v=e[s+3*y+1],x=e[s+3*y+2];r[p++]=x,r[p++]=v,r[p++]=w,r[p++]=255;}--c;}},this.decodeAndBlitFrameRGBA=function(t,r){var n=this.frameInfo(t),a=n.width*n.height,o=new Uint8Array(a);GifReaderLZWOutputIndexStream(e,n.data_offset,o,a);var s=n.palette_offset,l=n.transparent_index;null===l&&(l=256);var u=n.width,h=i-u,c=u,f=4*(n.y*i+n.x),d=4*((n.y+n.height)*i+n.x),p=f,m=4*h;true===n.interlaced&&(m+=4*i*7);for(var _=8,g=0,b=o.length;g<b;++g){var y=o[g];if(0===c&&(c=u,(p+=m)>=d&&(m=4*h+4*i*(_-1),p=f+(u+h)*(_<<1),_>>=1)),y===l)p+=4;else {var w=e[s+3*y],v=e[s+3*y+1],x=e[s+3*y+2];r[p++]=w,r[p++]=v,r[p++]=x,r[p++]=255;}--c;}};}function GifReaderLZWOutputIndexStream(e,t,i,r){for(var n=e[t++],a=1<<n,o=a+1,s=o+1,l=n+1,u=(1<<l)-1,h=0,c=0,f=0,d=e[t++],p=new Int32Array(4096),m=null;;){for(;h<16&&0!==d;)c|=e[t++]<<h,h+=8,1===d?d=e[t++]:--d;if(h<l)break;var _=c&u;if(c>>=l,h-=l,_!==a){if(_===o)break;for(var g=_<s?_:m,b=0,y=g;y>a;)y=p[y]>>8,++b;var w=y;if(f+b+(g!==_?1:0)>r)return void console.log("Warning, gif stream longer than expected.");i[f++]=w;var v=f+=b;for(g!==_&&(i[f++]=w),y=g;b--;)y=p[y],i[--v]=255&y,y>>=8;null!==m&&s<4096&&(p[s++]=m<<8|w,s>=u+1&&l<12&&(++l,u=u<<1|1)),m=_;}else s=o+1,u=(1<<(l=n+1))-1,m=null;}return f!==r&&console.log("Warning, gif stream shorter than expected."),i}try{GifWriter_1=omggif.GifWriter=GifWriter,GifReader_1=omggif.GifReader=GifReader;}catch(e){}let BitmapImage$2=class e{constructor(...t){if(0===t.length)throw new Error("constructor requires parameters");const i=t[0];if(null!==i&&"object"==typeof i)if(i instanceof e){const e=i.bitmap;this.bitmap={width:e.width,height:e.height,data:new Buffer$1(e.width*e.height*4)},e.data.copy(this.bitmap.data);}else {if(!(i.width&&i.height&&i.data))throw new Error("unrecognized constructor parameters");this.bitmap=i;}else {if("number"!=typeof i||"number"!=typeof t[1])throw new Error("unrecognized constructor parameters");{const e=i,r=t[1],n=t[2];this.bitmap={width:e,height:r},Buffer$1.isBuffer(n)?this.bitmap.data=n:(this.bitmap.data=new Buffer$1(e*r*4),"number"==typeof n&&this.fillRGBA(n));}}}blit(e,t,i,r,n,a,o){if(r+a>this.bitmap.width)throw new Error("copy exceeds width of source bitmap");if(t+a>e.bitmap.width)throw new Error("copy exceeds width of target bitmap");if(n+o>this.bitmap.height)throw new Error("copy exceeds height of source bitmap");if(i+o>e.bitmap.height)throw new Erro("copy exceeds height of target bitmap");const s=this.bitmap.data,l=e.bitmap.data,u=4*this.bitmap.width,h=4*e.bitmap.width,c=4*a;let f=n*u+4*r,d=i*h+4*t;for(;--o>=0;)s.copy(l,d,f,f+c),f+=u,d+=h;return this}fillRGBA(e){const t=this.bitmap.data,i=4*this.bitmap.height;let r=0;for(;r<i;)t.writeUInt32BE(e,r),r+=4;for(;r<t.length;)t.copy(t,r,0,i),r+=i;return this}getRGBA(e,t){const i=4*(t*this.bitmap.width+e);return this.bitmap.data.readUInt32BE(i)}getRGBASet(){const e=new Set,t=this.bitmap.data;for(let i=0;i<t.length;i+=4)e.add(t.readUInt32BE(i,true));return e}greyscale(){const e=this.bitmap.data;return this.scan(0,0,this.bitmap.width,this.bitmap.height,((t,i,r)=>{const n=Math.round(.299*e[r]+.587*e[r+1]+.114*e[r+2]);e[r]=n,e[r+1]=n,e[r+2]=n;})),this}reframe(t,i,r,n,a){const o=t<0?0:t,s=i<0?0:i,l=r+o>this.bitmap.width?this.bitmap.width-o:r,u=n+s>this.bitmap.height?this.bitmap.height-s:n,h=t<0?-t:0,c=i<0?-i:0;let f;if(void 0===a){if(o!==t||s!=i||l!==r||u!==n)throw new GifError("fillRGBA required for this reframing");f=new e(r,n);}else f=new e(r,n,a);return this.blit(f,h,c,o,s,l,u),this.bitmap=f.bitmap,this}scale(e){if(1===e)return;if(!Number.isInteger(e)||e<1)throw new Error("the scale must be an integer >= 1");const t=this.bitmap.width,i=this.bitmap.height,r=t*e*4,n=this.bitmap.data,a=new Buffer$1(i*r*e);let o,s=0,l=0;for(let u=0;u<i;++u){o=l;for(let i=0;i<t;++i){const t=n.readUInt32BE(s,true);for(let i=0;i<e;++i)a.writeUInt32BE(t,l),l+=4;s+=4;}for(let t=1;t<e;++t)a.copy(a,l,o,l),l+=r,o+=r;}return this.bitmap={width:t*e,height:i*e,data:a},this}scanAllCoords(e){const t=this.bitmap.width,i=this.bitmap.data.length;let r=0,n=0;for(let a=0;a<i;a+=4)e(r,n,a),++r===t&&(r=0,++n);}scanAllIndexes(e){const t=this.bitmap.data.length;for(let i=0;i<t;i+=4)e(i);}};var bitmapimage=BitmapImage$2,gif$1={};let Gif$1=class{constructor(e,t,i){this.width=i.width,this.height=i.height,this.loops=i.loops,this.usesTransparency=i.usesTransparency,this.colorScope=i.colorScope,this.frames=t,this.buffer=e;}};Gif$1.GlobalColorsPreferred=0,Gif$1.GlobalColorsOnly=1,Gif$1.LocalColorsOnly=2;let GifError$2=class extends Error{constructor(e){super(e),e instanceof Error&&(this.stack="Gif"+e.stack);}};gif$1.Gif=Gif$1,gif$1.GifError=GifError$2;var gifcodec={},gifutil={},_polyfillNode_fs={},_polyfillNode_fs$1=Object.freeze({__proto__:null,default:_polyfillNode_fs}),require$$0=getAugmentedNamespace(_polyfillNode_fs$1),__defProp$3=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__defNormalProp$3=(e,t,i)=>t in e?__defProp$3(e,t,{enumerable:true,configurable:true,writable:true,value:i}):e[t]=i,__markAsModule=e=>__defProp$3(e,"__esModule",{value:true}),__export$1=(e,t)=>{for(var i in t)__defProp$3(e,i,{get:t[i],enumerable:true});},__reExport=(e,t,i,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))!__hasOwnProp.call(e,n)&&i&&__defProp$3(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||r.enumerable});return e},__toCommonJS=(e=>(t,i)=>e&&e.get(t)||(i=__reExport(__markAsModule({}),t,1),e&&e.set(t,i),i))("undefined"!=typeof WeakMap?new WeakMap:0),__publicField$3=(e,t,i)=>(__defNormalProp$3(e,"symbol"!=typeof t?t+"":t,i),i),src_exports={};__export$1(src_exports,{applyPalette:()=>applyPalette,applyPaletteSync:()=>applyPaletteSync$1,buildPalette:()=>buildPalette,buildPaletteSync:()=>buildPaletteSync$1,constants:()=>constants_exports$1,conversion:()=>conversion_exports$1,distance:()=>distance_exports$1,image:()=>image_exports$1,palette:()=>palette_exports$1,quality:()=>quality_exports$1,utils:()=>utils_exports$1});var constants_exports$1={};__export$1(constants_exports$1,{bt709:()=>bt709_exports$1});var bt709_exports$1={};__export$1(bt709_exports$1,{Y:()=>Y$1,x:()=>x$2,y:()=>y$2});var Y$1=(e=>(e[e.RED=.2126]="RED",e[e.GREEN=.7152]="GREEN",e[e.BLUE=.0722]="BLUE",e[e.WHITE=1]="WHITE",e))(Y$1||{}),x$2=(e=>(e[e.RED=.64]="RED",e[e.GREEN=.3]="GREEN",e[e.BLUE=.15]="BLUE",e[e.WHITE=.3127]="WHITE",e))(x$2||{}),y$2=(e=>(e[e.RED=.33]="RED",e[e.GREEN=.6]="GREEN",e[e.BLUE=.06]="BLUE",e[e.WHITE=.329]="WHITE",e))(y$2||{}),conversion_exports$1={};function correctGamma$1(e){return e>.04045?((e+.055)/1.055)**2.4:e/12.92}function rgb2xyz$1(e,t,i){return {x:.4124*(e=correctGamma$1(e/255))+.3576*(t=correctGamma$1(t/255))+.1805*(i=correctGamma$1(i/255)),y:.2126*e+.7152*t+.0722*i,z:.0193*e+.1192*t+.9505*i}}__export$1(conversion_exports$1,{lab2rgb:()=>lab2rgb$1,lab2xyz:()=>lab2xyz$1,rgb2hsl:()=>rgb2hsl$1,rgb2lab:()=>rgb2lab$1,rgb2xyz:()=>rgb2xyz$1,xyz2lab:()=>xyz2lab$1,xyz2rgb:()=>xyz2rgb$1});var arithmetic_exports$1={};function degrees2radians$1(e){return e*(Math.PI/180)}function max3$1(e,t,i){let r=e;return r<t&&(r=t),r<i&&(r=i),r}function min3$1(e,t,i){let r=e;return r>t&&(r=t),r>i&&(r=i),r}function intInRange$1(e,t,i){return e>i&&(e=i),e<t&&(e=t),0|e}function inRange0to255Rounded$1(e){return (e=Math.round(e))>255?e=255:e<0&&(e=0),e}function inRange0to255$1(e){return e>255?e=255:e<0&&(e=0),e}function stableSort$1(e,t){const i=typeof e[0];let r;if("number"===i||"string"===i){const i=Object.create(null);for(let t=0,r=e.length;t<r;t++){const r=e[t];i[r]||0===i[r]||(i[r]=t);}r=e.sort(((e,r)=>t(e,r)||i[e]-i[r]));}else {const i=e.slice(0);r=e.sort(((e,r)=>t(e,r)||i.indexOf(e)-i.indexOf(r)));}return r}function rgb2hsl$1(e,t,i){const r=min3$1(e,t,i),n=max3$1(e,t,i),a=n-r,o=(r+n)/510;let s=0;o>0&&o<1&&(s=a/(o<.5?n+r:510-n-r));let l=0;return a>0&&(l=n===e?(t-i)/a:n===t?2+(i-e)/a:4+(e-t)/a,l*=60,l<0&&(l+=360)),{h:l,s:s,l:o}}__export$1(arithmetic_exports$1,{degrees2radians:()=>degrees2radians$1,inRange0to255:()=>inRange0to255$1,inRange0to255Rounded:()=>inRange0to255Rounded$1,intInRange:()=>intInRange$1,max3:()=>max3$1,min3:()=>min3$1,stableSort:()=>stableSort$1});var refX$1=.95047,refY$1=1,refZ$1=1.08883;function pivot$1(e){return e>.008856?e**(1/3):7.787*e+16/116}function xyz2lab$1(e,t,i){if(e=pivot$1(e/refX$1),t=pivot$1(t/refY$1),i=pivot$1(i/refZ$1),116*t-16<0)throw new Error("xxx");return {L:Math.max(0,116*t-16),a:500*(e-t),b:200*(t-i)}}function rgb2lab$1(e,t,i){const r=rgb2xyz$1(e,t,i);return xyz2lab$1(r.x,r.y,r.z)}var refX2$1=.95047,refY2$1=1,refZ2$1=1.08883;function pivot2$1(e){return e>.206893034?e**3:(e-16/116)/7.787}function lab2xyz$1(e,t,i){const r=(e+16)/116,n=r-i/200;return {x:refX2$1*pivot2$1(t/500+r),y:refY2$1*pivot2$1(r),z:refZ2$1*pivot2$1(n)}}function correctGamma2$1(e){return e>.0031308?1.055*e**(1/2.4)-.055:12.92*e}function xyz2rgb$1(e,t,i){const r=correctGamma2$1(3.2406*e+-1.5372*t+-0.4986*i),n=correctGamma2$1(-0.9689*e+1.8758*t+.0415*i),a=correctGamma2$1(.0557*e+-0.204*t+1.057*i);return {r:inRange0to255Rounded$1(255*r),g:inRange0to255Rounded$1(255*n),b:inRange0to255Rounded$1(255*a)}}function lab2rgb$1(e,t,i){const r=lab2xyz$1(e,t,i);return xyz2rgb$1(r.x,r.y,r.z)}var distance_exports$1={};__export$1(distance_exports$1,{AbstractDistanceCalculator:()=>AbstractDistanceCalculator$1,AbstractEuclidean:()=>AbstractEuclidean$1,AbstractManhattan:()=>AbstractManhattan$1,CIE94GraphicArts:()=>CIE94GraphicArts$1,CIE94Textiles:()=>CIE94Textiles$1,CIEDE2000:()=>CIEDE2000$1,CMetric:()=>CMetric$1,Euclidean:()=>Euclidean$1,EuclideanBT709:()=>EuclideanBT709$1,EuclideanBT709NoAlpha:()=>EuclideanBT709NoAlpha$1,Manhattan:()=>Manhattan$1,ManhattanBT709:()=>ManhattanBT709$1,ManhattanNommyde:()=>ManhattanNommyde$1,PNGQuant:()=>PNGQuant$1});var AbstractDistanceCalculator$1=class{constructor(){__publicField$3(this,"_maxDistance"),__publicField$3(this,"_whitePoint"),this._setDefaults(),this.setWhitePoint(255,255,255,255);}setWhitePoint(e,t,i,r){this._whitePoint={r:e>0?255/e:0,g:t>0?255/t:0,b:i>0?255/i:0,a:r>0?255/r:0},this._maxDistance=this.calculateRaw(e,t,i,r,0,0,0,0);}calculateNormalized(e,t){return this.calculateRaw(e.r,e.g,e.b,e.a,t.r,t.g,t.b,t.a)/this._maxDistance}},AbstractCIE94$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=rgb2lab$1(inRange0to255$1(e*this._whitePoint.r),inRange0to255$1(t*this._whitePoint.g),inRange0to255$1(i*this._whitePoint.b)),u=rgb2lab$1(inRange0to255$1(n*this._whitePoint.r),inRange0to255$1(a*this._whitePoint.g),inRange0to255$1(o*this._whitePoint.b)),h=l.L-u.L,c=l.a-u.a,f=l.b-u.b,d=Math.sqrt(l.a*l.a+l.b*l.b),p=d-Math.sqrt(u.a*u.a+u.b*u.b);let m=c*c+f*f-p*p;m=m<0?0:Math.sqrt(m);const _=(s-r)*this._whitePoint.a*this._kA;return Math.sqrt((h/this._Kl)**2+(p/(1+this._K1*d))**2+(m/(1+this._K2*d))**2+_**2)}},CIE94Textiles$1=class extends AbstractCIE94$1{_setDefaults(){this._Kl=2,this._K1=.048,this._K2=.014,this._kA=12.5/255;}},CIE94GraphicArts$1=class extends AbstractCIE94$1{_setDefaults(){this._Kl=1,this._K1=.045,this._K2=.015,this._kA=25/255;}},_CIEDE2000$1=class extends AbstractDistanceCalculator$1{_setDefaults(){}static _calculatehp(e,t){const i=Math.atan2(e,t);return i>=0?i:i+_CIEDE2000$1._deg360InRad}static _calculateRT(e,t){const i=t**7,r=2*Math.sqrt(i/(i+_CIEDE2000$1._pow25to7)),n=_CIEDE2000$1._deg30InRad*Math.exp(-(((e-_CIEDE2000$1._deg275InRad)/_CIEDE2000$1._deg25InRad)**2));return -Math.sin(2*n)*r}static _calculateT(e){return 1-.17*Math.cos(e-_CIEDE2000$1._deg30InRad)+.24*Math.cos(2*e)+.32*Math.cos(3*e+_CIEDE2000$1._deg6InRad)-.2*Math.cos(4*e-_CIEDE2000$1._deg63InRad)}static _calculate_ahp(e,t,i,r){const n=i+r;return 0===e?n:t<=_CIEDE2000$1._deg180InRad?n/2:n<_CIEDE2000$1._deg360InRad?(n+_CIEDE2000$1._deg360InRad)/2:(n-_CIEDE2000$1._deg360InRad)/2}static _calculate_dHp(e,t,i,r){let n;return n=0===e?0:t<=_CIEDE2000$1._deg180InRad?i-r:i<=r?i-r+_CIEDE2000$1._deg360InRad:i-r-_CIEDE2000$1._deg360InRad,2*Math.sqrt(e)*Math.sin(n/2)}calculateRaw(e,t,i,r,n,a,o,s){const l=rgb2lab$1(inRange0to255$1(e*this._whitePoint.r),inRange0to255$1(t*this._whitePoint.g),inRange0to255$1(i*this._whitePoint.b)),u=rgb2lab$1(inRange0to255$1(n*this._whitePoint.r),inRange0to255$1(a*this._whitePoint.g),inRange0to255$1(o*this._whitePoint.b)),h=(s-r)*this._whitePoint.a*_CIEDE2000$1._kA,c=this.calculateRawInLab(l,u);return Math.sqrt(c+h*h)}calculateRawInLab(e,t){const i=e.L,r=e.a,n=e.b,a=t.L,o=t.a,s=t.b,l=((Math.sqrt(r*r+n*n)+Math.sqrt(o*o+s*s))/2)**7,u=.5*(1-Math.sqrt(l/(l+_CIEDE2000$1._pow25to7))),h=(1+u)*r,c=(1+u)*o,f=Math.sqrt(h*h+n*n),d=Math.sqrt(c*c+s*s),p=f*d,m=_CIEDE2000$1._calculatehp(n,h),_=_CIEDE2000$1._calculatehp(s,c),g=Math.abs(m-_),b=a-i,y=d-f,w=_CIEDE2000$1._calculate_dHp(p,g,_,m),v=_CIEDE2000$1._calculate_ahp(p,g,m,_),x=(f+d)/2,E=((i+a)/2-50)**2,k=y/(1+.045*x),S=w/(1+.015*_CIEDE2000$1._calculateT(v)*x);return (b/(1+.015*E/Math.sqrt(20+E)))**2+k**2+S**2+_CIEDE2000$1._calculateRT(v,x)*k*S}},CIEDE2000$1=_CIEDE2000$1;__publicField$3(CIEDE2000$1,"_kA",25/255),__publicField$3(CIEDE2000$1,"_pow25to7",25**7),__publicField$3(CIEDE2000$1,"_deg360InRad",degrees2radians$1(360)),__publicField$3(CIEDE2000$1,"_deg180InRad",degrees2radians$1(180)),__publicField$3(CIEDE2000$1,"_deg30InRad",degrees2radians$1(30)),__publicField$3(CIEDE2000$1,"_deg6InRad",degrees2radians$1(6)),__publicField$3(CIEDE2000$1,"_deg63InRad",degrees2radians$1(63)),__publicField$3(CIEDE2000$1,"_deg275InRad",degrees2radians$1(275)),__publicField$3(CIEDE2000$1,"_deg25InRad",degrees2radians$1(25));var CMetric$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=(e+n)/2*this._whitePoint.r,u=(e-n)*this._whitePoint.r,h=(t-a)*this._whitePoint.g,c=(i-o)*this._whitePoint.b,f=((512+l)*u*u>>8)+4*h*h+((767-l)*c*c>>8),d=(s-r)*this._whitePoint.a;return Math.sqrt(f+d*d)}_setDefaults(){}},AbstractEuclidean$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=n-e,u=a-t,h=o-i,c=s-r;return Math.sqrt(this._kR*l*l+this._kG*u*u+this._kB*h*h+this._kA*c*c)}},Euclidean$1=class extends AbstractEuclidean$1{_setDefaults(){this._kR=1,this._kG=1,this._kB=1,this._kA=1;}},EuclideanBT709$1=class extends AbstractEuclidean$1{_setDefaults(){this._kR=.2126,this._kG=.7152,this._kB=.0722,this._kA=1;}},EuclideanBT709NoAlpha$1=class extends AbstractEuclidean$1{_setDefaults(){this._kR=.2126,this._kG=.7152,this._kB=.0722,this._kA=0;}},AbstractManhattan$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){let l=n-e,u=a-t,h=o-i,c=s-r;return l<0&&(l=0-l),u<0&&(u=0-u),h<0&&(h=0-h),c<0&&(c=0-c),this._kR*l+this._kG*u+this._kB*h+this._kA*c}},Manhattan$1=class extends AbstractManhattan$1{_setDefaults(){this._kR=1,this._kG=1,this._kB=1,this._kA=1;}},ManhattanNommyde$1=class extends AbstractManhattan$1{_setDefaults(){this._kR=.4984,this._kG=.8625,this._kB=.2979,this._kA=1;}},ManhattanBT709$1=class extends AbstractManhattan$1{_setDefaults(){this._kR=.2126,this._kG=.7152,this._kB=.0722,this._kA=1;}},PNGQuant$1=class extends AbstractDistanceCalculator$1{calculateRaw(e,t,i,r,n,a,o,s){const l=(s-r)*this._whitePoint.a;return this._colordifferenceCh(e*this._whitePoint.r,n*this._whitePoint.r,l)+this._colordifferenceCh(t*this._whitePoint.g,a*this._whitePoint.g,l)+this._colordifferenceCh(i*this._whitePoint.b,o*this._whitePoint.b,l)}_colordifferenceCh(e,t,i){const r=e-t,n=r+i;return r*r+n*n}_setDefaults(){}},palette_exports$1={};__export$1(palette_exports$1,{AbstractPaletteQuantizer:()=>AbstractPaletteQuantizer$1,ColorHistogram:()=>ColorHistogram$1,NeuQuant:()=>NeuQuant$1,NeuQuantFloat:()=>NeuQuantFloat$1,RGBQuant:()=>RGBQuant$1,WuColorCube:()=>WuColorCube$1,WuQuant:()=>WuQuant$1});var AbstractPaletteQuantizer$1=class{quantizeSync(){for(const e of this.quantize())if(e.palette)return e.palette;throw new Error("unreachable")}},Point$1=class{constructor(){__publicField$3(this,"r"),__publicField$3(this,"g"),__publicField$3(this,"b"),__publicField$3(this,"a"),__publicField$3(this,"uint32"),__publicField$3(this,"rgba"),this.uint32=-1>>>0,this.r=this.g=this.b=this.a=0,this.rgba=new Array(4),this.rgba[0]=0,this.rgba[1]=0,this.rgba[2]=0,this.rgba[3]=0;}static createByQuadruplet(e){const t=new Point$1;return t.r=0|e[0],t.g=0|e[1],t.b=0|e[2],t.a=0|e[3],t._loadUINT32(),t._loadQuadruplet(),t}static createByRGBA(e,t,i,r){const n=new Point$1;return n.r=0|e,n.g=0|t,n.b=0|i,n.a=0|r,n._loadUINT32(),n._loadQuadruplet(),n}static createByUint32(e){const t=new Point$1;return t.uint32=e>>>0,t._loadRGBA(),t._loadQuadruplet(),t}from(e){this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this.uint32=e.uint32,this.rgba[0]=e.r,this.rgba[1]=e.g,this.rgba[2]=e.b,this.rgba[3]=e.a;}getLuminosity(e){let t=this.r,i=this.g,r=this.b;return e&&(t=Math.min(255,255-this.a+this.a*t/255),i=Math.min(255,255-this.a+this.a*i/255),r=Math.min(255,255-this.a+this.a*r/255)),.2126*t+.7152*i+.0722*r}_loadUINT32(){this.uint32=(this.a<<24|this.b<<16|this.g<<8|this.r)>>>0;}_loadRGBA(){this.r=255&this.uint32,this.g=this.uint32>>>8&255,this.b=this.uint32>>>16&255,this.a=this.uint32>>>24&255;}_loadQuadruplet(){this.rgba[0]=this.r,this.rgba[1]=this.g,this.rgba[2]=this.b,this.rgba[3]=this.a;}},PointContainer$1=class{constructor(){__publicField$3(this,"_pointArray"),__publicField$3(this,"_width"),__publicField$3(this,"_height"),this._width=0,this._height=0,this._pointArray=[];}getWidth(){return this._width}getHeight(){return this._height}setWidth(e){this._width=e;}setHeight(e){this._height=e;}getPointArray(){return this._pointArray}clone(){const e=new PointContainer$1;e._width=this._width,e._height=this._height;for(let t=0,i=this._pointArray.length;t<i;t++)e._pointArray[t]=Point$1.createByUint32(0|this._pointArray[t].uint32);return e}toUint32Array(){const e=this._pointArray.length,t=new Uint32Array(e);for(let i=0;i<e;i++)t[i]=this._pointArray[i].uint32;return t}toUint8Array(){return new Uint8Array(this.toUint32Array().buffer)}static fromHTMLImageElement(e){const t=e.naturalWidth,i=e.naturalHeight,r=document.createElement("canvas");r.width=t,r.height=i;return r.getContext("2d").drawImage(e,0,0,t,i,0,0,t,i),PointContainer$1.fromHTMLCanvasElement(r)}static fromHTMLCanvasElement(e){const t=e.width,i=e.height,r=e.getContext("2d").getImageData(0,0,t,i);return PointContainer$1.fromImageData(r)}static fromImageData(e){const t=e.width,i=e.height;return PointContainer$1.fromUint8Array(e.data,t,i)}static fromUint8Array(e,t,i){switch(Object.prototype.toString.call(e)){case "[object Uint8ClampedArray]":case "[object Uint8Array]":break;default:e=new Uint8Array(e);}const r=new Uint32Array(e.buffer);return PointContainer$1.fromUint32Array(r,t,i)}static fromUint32Array(e,t,i){const r=new PointContainer$1;r._width=t,r._height=i;for(let t=0,i=e.length;t<i;t++)r._pointArray[t]=Point$1.createByUint32(0|e[t]);return r}static fromBuffer(e,t,i){const r=new Uint32Array(e.buffer,e.byteOffset,e.byteLength/Uint32Array.BYTES_PER_ELEMENT);return PointContainer$1.fromUint32Array(r,t,i)}},hueGroups$1=10;function hueGroup$1(e,t){const i=360/t;for(let r=1,n=i-i/2;r<t;r++,n+=i)if(e>=n&&e<n+i)return r;return 0}var Palette$1=class{constructor(){__publicField$3(this,"_pointContainer"),__publicField$3(this,"_pointArray",[]),__publicField$3(this,"_i32idx",{}),this._pointContainer=new PointContainer$1,this._pointContainer.setHeight(1),this._pointArray=this._pointContainer.getPointArray();}add(e){this._pointArray.push(e),this._pointContainer.setWidth(this._pointArray.length);}has(e){for(let t=this._pointArray.length-1;t>=0;t--)if(e.uint32===this._pointArray[t].uint32)return true;return false}getNearestColor(e,t){return this._pointArray[0|this._getNearestIndex(e,t)]}getPointContainer(){return this._pointContainer}_nearestPointFromCache(e){return "number"==typeof this._i32idx[e]?this._i32idx[e]:-1}_getNearestIndex(e,t){let i=this._nearestPointFromCache(""+t.uint32);if(i>=0)return i;let r=Number.MAX_VALUE;i=0;for(let n=0,a=this._pointArray.length;n<a;n++){const a=this._pointArray[n],o=e.calculateRaw(t.r,t.g,t.b,t.a,a.r,a.g,a.b,a.a);o<r&&(r=o,i=n);}return this._i32idx[t.uint32]=i,i}sort(){this._i32idx={},this._pointArray.sort(((e,t)=>{const i=rgb2hsl$1(e.r,e.g,e.b),r=rgb2hsl$1(t.r,t.g,t.b),n=e.r===e.g&&e.g===e.b?0:1+hueGroup$1(i.h,hueGroups$1),a=(t.r===t.g&&t.g===t.b?0:1+hueGroup$1(r.h,hueGroups$1))-n;if(a)return -a;const o=e.getLuminosity(true),s=t.getLuminosity(true);if(s-o!=0)return s-o;const l=(100*r.s|0)-(100*i.s|0);return l?-l:0}));}},utils_exports$1={};__export$1(utils_exports$1,{HueStatistics:()=>HueStatistics$1,Palette:()=>Palette$1,Point:()=>Point$1,PointContainer:()=>PointContainer$1,ProgressTracker:()=>ProgressTracker$1,arithmetic:()=>arithmetic_exports$1});var HueGroup$1=class{constructor(){__publicField$3(this,"num",0),__publicField$3(this,"cols",[]);}},HueStatistics$1=class{constructor(e,t){__publicField$3(this,"_numGroups"),__publicField$3(this,"_minCols"),__publicField$3(this,"_stats"),__publicField$3(this,"_groupsFull"),this._numGroups=e,this._minCols=t,this._stats=[];for(let t=0;t<=e;t++)this._stats[t]=new HueGroup$1;this._groupsFull=0;}check(e){this._groupsFull===this._numGroups+1&&(this.check=()=>{});const t=255&e,i=e>>>8&255,r=e>>>16&255,n=t===i&&i===r?0:1+hueGroup$1(rgb2hsl$1(t,i,r).h,this._numGroups),a=this._stats[n],o=this._minCols;a.num++,a.num>o||(a.num===o&&this._groupsFull++,a.num<=o&&this._stats[n].cols.push(e));}injectIntoDictionary(e){for(let t=0;t<=this._numGroups;t++)this._stats[t].num<=this._minCols&&this._stats[t].cols.forEach((t=>{e[t]?e[t]++:e[t]=1;}));}injectIntoArray(e){for(let t=0;t<=this._numGroups;t++)this._stats[t].num<=this._minCols&&this._stats[t].cols.forEach((t=>{ -1===e.indexOf(t)&&e.push(t);}));}},_ProgressTracker$1=class{constructor(e,t){__publicField$3(this,"progress"),__publicField$3(this,"_step"),__publicField$3(this,"_range"),__publicField$3(this,"_last"),__publicField$3(this,"_progressRange"),this._range=e,this._progressRange=t,this._step=Math.max(1,this._range/(_ProgressTracker$1.steps+1)|0),this._last=-this._step,this.progress=0;}shouldNotify(e){return e-this._last>=this._step&&(this._last=e,this.progress=Math.min(this._progressRange*this._last/this._range,this._progressRange),true)}},ProgressTracker$1=_ProgressTracker$1;__publicField$3(ProgressTracker$1,"steps",100);var networkBiasShift$1=3,Neuron$1=class{constructor(e){__publicField$3(this,"r"),__publicField$3(this,"g"),__publicField$3(this,"b"),__publicField$3(this,"a"),this.r=this.g=this.b=this.a=e;}toPoint(){return Point$1.createByRGBA(this.r>>networkBiasShift$1,this.g>>networkBiasShift$1,this.b>>networkBiasShift$1,this.a>>networkBiasShift$1)}subtract(e,t,i,r){this.r-=0|e,this.g-=0|t,this.b-=0|i,this.a-=0|r;}},_NeuQuant$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256){super(),__publicField$3(this,"_pointArray"),__publicField$3(this,"_networkSize"),__publicField$3(this,"_network"),__publicField$3(this,"_sampleFactor"),__publicField$3(this,"_radPower"),__publicField$3(this,"_freq"),__publicField$3(this,"_bias"),__publicField$3(this,"_distance"),this._distance=e,this._pointArray=[],this._sampleFactor=1,this._networkSize=t,this._distance.setWhitePoint(255<<networkBiasShift$1,255<<networkBiasShift$1,255<<networkBiasShift$1,255<<networkBiasShift$1);}sample(e){this._pointArray=this._pointArray.concat(e.getPointArray());}*quantize(){this._init(),yield*this._learn(),yield {palette:this._buildPalette(),progress:100};}_init(){this._freq=[],this._bias=[],this._radPower=[],this._network=[];for(let e=0;e<this._networkSize;e++)this._network[e]=new Neuron$1((e<<networkBiasShift$1+8)/this._networkSize|0),this._freq[e]=_NeuQuant$1._initialBias/this._networkSize|0,this._bias[e]=0;}*_learn(){let e=this._sampleFactor;const t=this._pointArray.length;t<_NeuQuant$1._minpicturebytes&&(e=1);const i=30+(e-1)/3|0,r=t/e|0;let n,a=r/_NeuQuant$1._nCycles|0,o=_NeuQuant$1._initAlpha,s=(this._networkSize>>3)*_NeuQuant$1._radiusBias,l=s>>_NeuQuant$1._radiusBiasShift;l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuant$1._radBias/(l*l))>>>0;n=t<_NeuQuant$1._minpicturebytes?1:t%_NeuQuant$1._prime1!=0?_NeuQuant$1._prime1:t%_NeuQuant$1._prime2!=0?_NeuQuant$1._prime2:t%_NeuQuant$1._prime3!=0?_NeuQuant$1._prime3:_NeuQuant$1._prime4;const u=new ProgressTracker$1(r,99);for(let e=0,h=0;e<r;){u.shouldNotify(e)&&(yield {progress:u.progress});const r=this._pointArray[h],c=r.b<<networkBiasShift$1,f=r.g<<networkBiasShift$1,d=r.r<<networkBiasShift$1,p=r.a<<networkBiasShift$1,m=this._contest(c,f,d,p);if(this._alterSingle(o,m,c,f,d,p),0!==l&&this._alterNeighbour(l,m,c,f,d,p),h+=n,h>=t&&(h-=t),e++,0===a&&(a=1),e%a==0){o-=o/i|0,s-=s/_NeuQuant$1._radiusDecrease|0,l=s>>_NeuQuant$1._radiusBiasShift,l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuant$1._radBias/(l*l))>>>0;}}}_buildPalette(){const e=new Palette$1;return this._network.forEach((t=>{e.add(t.toPoint());})),e.sort(),e}_alterNeighbour(e,t,i,r,n,a){let o=t-e;o<-1&&(o=-1);let s=t+e;s>this._networkSize&&(s=this._networkSize);let l=t+1,u=t-1,h=1;for(;l<s||u>o;){const e=this._radPower[h++]/_NeuQuant$1._alphaRadBias;if(l<s){const t=this._network[l++];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}if(u>o){const t=this._network[u--];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}}}_alterSingle(e,t,i,r,n,a){e/=_NeuQuant$1._initAlpha;const o=this._network[t];o.subtract(e*(o.r-n),e*(o.g-r),e*(o.b-i),e*(o.a-a));}_contest(e,t,i,r){const n=1020<<networkBiasShift$1;let a=2147483647,o=a,s=-1,l=s;for(let u=0;u<this._networkSize;u++){const h=this._network[u],c=this._distance.calculateNormalized(h,{r:i,g:t,b:e,a:r})*n|0;c<a&&(a=c,s=u);const f=c-(this._bias[u]>>_NeuQuant$1._initialBiasShift-networkBiasShift$1);f<o&&(o=f,l=u);const d=this._freq[u]>>_NeuQuant$1._betaShift;this._freq[u]-=d,this._bias[u]+=d<<_NeuQuant$1._gammaShift;}return this._freq[s]+=_NeuQuant$1._beta,this._bias[s]-=_NeuQuant$1._betaGamma,l}},NeuQuant$1=_NeuQuant$1;__publicField$3(NeuQuant$1,"_prime1",499),__publicField$3(NeuQuant$1,"_prime2",491),__publicField$3(NeuQuant$1,"_prime3",487),__publicField$3(NeuQuant$1,"_prime4",503),__publicField$3(NeuQuant$1,"_minpicturebytes",_NeuQuant$1._prime4),__publicField$3(NeuQuant$1,"_nCycles",100),__publicField$3(NeuQuant$1,"_initialBiasShift",16),__publicField$3(NeuQuant$1,"_initialBias",1<<_NeuQuant$1._initialBiasShift),__publicField$3(NeuQuant$1,"_gammaShift",10),__publicField$3(NeuQuant$1,"_betaShift",10),__publicField$3(NeuQuant$1,"_beta",_NeuQuant$1._initialBias>>_NeuQuant$1._betaShift),__publicField$3(NeuQuant$1,"_betaGamma",_NeuQuant$1._initialBias<<_NeuQuant$1._gammaShift-_NeuQuant$1._betaShift),__publicField$3(NeuQuant$1,"_radiusBiasShift",6),__publicField$3(NeuQuant$1,"_radiusBias",1<<_NeuQuant$1._radiusBiasShift),__publicField$3(NeuQuant$1,"_radiusDecrease",30),__publicField$3(NeuQuant$1,"_alphaBiasShift",10),__publicField$3(NeuQuant$1,"_initAlpha",1<<_NeuQuant$1._alphaBiasShift),__publicField$3(NeuQuant$1,"_radBiasShift",8),__publicField$3(NeuQuant$1,"_radBias",1<<_NeuQuant$1._radBiasShift),__publicField$3(NeuQuant$1,"_alphaRadBiasShift",_NeuQuant$1._alphaBiasShift+_NeuQuant$1._radBiasShift),__publicField$3(NeuQuant$1,"_alphaRadBias",1<<_NeuQuant$1._alphaRadBiasShift);var networkBiasShift2$1=3,NeuronFloat$1=class{constructor(e){__publicField$3(this,"r"),__publicField$3(this,"g"),__publicField$3(this,"b"),__publicField$3(this,"a"),this.r=this.g=this.b=this.a=e;}toPoint(){return Point$1.createByRGBA(this.r>>networkBiasShift2$1,this.g>>networkBiasShift2$1,this.b>>networkBiasShift2$1,this.a>>networkBiasShift2$1)}subtract(e,t,i,r){this.r-=e,this.g-=t,this.b-=i,this.a-=r;}},_NeuQuantFloat$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256){super(),__publicField$3(this,"_pointArray"),__publicField$3(this,"_networkSize"),__publicField$3(this,"_network"),__publicField$3(this,"_sampleFactor"),__publicField$3(this,"_radPower"),__publicField$3(this,"_freq"),__publicField$3(this,"_bias"),__publicField$3(this,"_distance"),this._distance=e,this._pointArray=[],this._sampleFactor=1,this._networkSize=t,this._distance.setWhitePoint(255<<networkBiasShift2$1,255<<networkBiasShift2$1,255<<networkBiasShift2$1,255<<networkBiasShift2$1);}sample(e){this._pointArray=this._pointArray.concat(e.getPointArray());}*quantize(){this._init(),yield*this._learn(),yield {palette:this._buildPalette(),progress:100};}_init(){this._freq=[],this._bias=[],this._radPower=[],this._network=[];for(let e=0;e<this._networkSize;e++)this._network[e]=new NeuronFloat$1((e<<networkBiasShift2$1+8)/this._networkSize),this._freq[e]=_NeuQuantFloat$1._initialBias/this._networkSize,this._bias[e]=0;}*_learn(){let e=this._sampleFactor;const t=this._pointArray.length;t<_NeuQuantFloat$1._minpicturebytes&&(e=1);const i=30+(e-1)/3,r=t/e;let n,a=r/_NeuQuantFloat$1._nCycles|0,o=_NeuQuantFloat$1._initAlpha,s=(this._networkSize>>3)*_NeuQuantFloat$1._radiusBias,l=s>>_NeuQuantFloat$1._radiusBiasShift;l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuantFloat$1._radBias/(l*l));n=t<_NeuQuantFloat$1._minpicturebytes?1:t%_NeuQuantFloat$1._prime1!=0?_NeuQuantFloat$1._prime1:t%_NeuQuantFloat$1._prime2!=0?_NeuQuantFloat$1._prime2:t%_NeuQuantFloat$1._prime3!=0?_NeuQuantFloat$1._prime3:_NeuQuantFloat$1._prime4;const u=new ProgressTracker$1(r,99);for(let e=0,h=0;e<r;){u.shouldNotify(e)&&(yield {progress:u.progress});const r=this._pointArray[h],c=r.b<<networkBiasShift2$1,f=r.g<<networkBiasShift2$1,d=r.r<<networkBiasShift2$1,p=r.a<<networkBiasShift2$1,m=this._contest(c,f,d,p);if(this._alterSingle(o,m,c,f,d,p),0!==l&&this._alterNeighbour(l,m,c,f,d,p),h+=n,h>=t&&(h-=t),e++,0===a&&(a=1),e%a==0){o-=o/i,s-=s/_NeuQuantFloat$1._radiusDecrease,l=s>>_NeuQuantFloat$1._radiusBiasShift,l<=1&&(l=0);for(let e=0;e<l;e++)this._radPower[e]=o*((l*l-e*e)*_NeuQuantFloat$1._radBias/(l*l));}}}_buildPalette(){const e=new Palette$1;return this._network.forEach((t=>{e.add(t.toPoint());})),e.sort(),e}_alterNeighbour(e,t,i,r,n,a){let o=t-e;o<-1&&(o=-1);let s=t+e;s>this._networkSize&&(s=this._networkSize);let l=t+1,u=t-1,h=1;for(;l<s||u>o;){const e=this._radPower[h++]/_NeuQuantFloat$1._alphaRadBias;if(l<s){const t=this._network[l++];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}if(u>o){const t=this._network[u--];t.subtract(e*(t.r-n),e*(t.g-r),e*(t.b-i),e*(t.a-a));}}}_alterSingle(e,t,i,r,n,a){e/=_NeuQuantFloat$1._initAlpha;const o=this._network[t];o.subtract(e*(o.r-n),e*(o.g-r),e*(o.b-i),e*(o.a-a));}_contest(e,t,i,r){const n=1020<<networkBiasShift2$1;let a=2147483647,o=a,s=-1,l=s;for(let u=0;u<this._networkSize;u++){const h=this._network[u],c=this._distance.calculateNormalized(h,{r:i,g:t,b:e,a:r})*n;c<a&&(a=c,s=u);const f=c-(this._bias[u]>>_NeuQuantFloat$1._initialBiasShift-networkBiasShift2$1);f<o&&(o=f,l=u);const d=this._freq[u]>>_NeuQuantFloat$1._betaShift;this._freq[u]-=d,this._bias[u]+=d<<_NeuQuantFloat$1._gammaShift;}return this._freq[s]+=_NeuQuantFloat$1._beta,this._bias[s]-=_NeuQuantFloat$1._betaGamma,l}},NeuQuantFloat$1=_NeuQuantFloat$1;__publicField$3(NeuQuantFloat$1,"_prime1",499),__publicField$3(NeuQuantFloat$1,"_prime2",491),__publicField$3(NeuQuantFloat$1,"_prime3",487),__publicField$3(NeuQuantFloat$1,"_prime4",503),__publicField$3(NeuQuantFloat$1,"_minpicturebytes",_NeuQuantFloat$1._prime4),__publicField$3(NeuQuantFloat$1,"_nCycles",100),__publicField$3(NeuQuantFloat$1,"_initialBiasShift",16),__publicField$3(NeuQuantFloat$1,"_initialBias",1<<_NeuQuantFloat$1._initialBiasShift),__publicField$3(NeuQuantFloat$1,"_gammaShift",10),__publicField$3(NeuQuantFloat$1,"_betaShift",10),__publicField$3(NeuQuantFloat$1,"_beta",_NeuQuantFloat$1._initialBias>>_NeuQuantFloat$1._betaShift),__publicField$3(NeuQuantFloat$1,"_betaGamma",_NeuQuantFloat$1._initialBias<<_NeuQuantFloat$1._gammaShift-_NeuQuantFloat$1._betaShift),__publicField$3(NeuQuantFloat$1,"_radiusBiasShift",6),__publicField$3(NeuQuantFloat$1,"_radiusBias",1<<_NeuQuantFloat$1._radiusBiasShift),__publicField$3(NeuQuantFloat$1,"_radiusDecrease",30),__publicField$3(NeuQuantFloat$1,"_alphaBiasShift",10),__publicField$3(NeuQuantFloat$1,"_initAlpha",1<<_NeuQuantFloat$1._alphaBiasShift),__publicField$3(NeuQuantFloat$1,"_radBiasShift",8),__publicField$3(NeuQuantFloat$1,"_radBias",1<<_NeuQuantFloat$1._radBiasShift),__publicField$3(NeuQuantFloat$1,"_alphaRadBiasShift",_NeuQuantFloat$1._alphaBiasShift+_NeuQuantFloat$1._radBiasShift),__publicField$3(NeuQuantFloat$1,"_alphaRadBias",1<<_NeuQuantFloat$1._alphaRadBiasShift);var _ColorHistogram$1=class{constructor(e,t){__publicField$3(this,"_method"),__publicField$3(this,"_hueStats"),__publicField$3(this,"_histogram"),__publicField$3(this,"_initColors"),__publicField$3(this,"_minHueCols"),this._method=e,this._minHueCols=t<<2,this._initColors=t<<2,this._hueStats=new HueStatistics$1(_ColorHistogram$1._hueGroups,this._minHueCols),this._histogram=Object.create(null);}sample(e){switch(this._method){case 1:this._colorStats1D(e);break;case 2:this._colorStats2D(e);}}getImportanceSortedColorsIDXI32(){const e=stableSort$1(Object.keys(this._histogram),((e,t)=>this._histogram[t]-this._histogram[e]));if(0===e.length)return [];let t;switch(this._method){case 1:const i=Math.min(e.length,this._initColors),r=e[i-1],n=this._histogram[r];t=e.slice(0,i);let a=i;const o=e.length;for(;a<o&&this._histogram[e[a]]===n;)t.push(e[a++]);this._hueStats.injectIntoArray(t);break;case 2:t=e;break;default:throw new Error("Incorrect method")}return t.map((e=>+e))}_colorStats1D(e){const t=this._histogram,i=e.getPointArray(),r=i.length;for(let e=0;e<r;e++){const r=i[e].uint32;this._hueStats.check(r),r in t?t[r]++:t[r]=1;}}_colorStats2D(e){const t=e.getWidth(),i=e.getHeight(),r=e.getPointArray(),n=_ColorHistogram$1._boxSize[0],a=_ColorHistogram$1._boxSize[1],o=n*a,s=this._makeBoxes(t,i,n,a),l=this._histogram;s.forEach((e=>{let i=Math.round(e.w*e.h/o)*_ColorHistogram$1._boxPixels;i<2&&(i=2);const n={};this._iterateBox(e,t,(e=>{const t=r[e].uint32;this._hueStats.check(t),t in l?l[t]++:t in n?++n[t]>=i&&(l[t]=n[t]):n[t]=1;}));})),this._hueStats.injectIntoDictionary(l);}_iterateBox(e,t,i){const r=e,n=r.y*t+r.x,a=(r.y+r.h-1)*t+(r.x+r.w-1),o=t-r.w+1;let s=0,l=n;do{i.call(this,l),l+=++s%r.w==0?o:1;}while(l<=a)}_makeBoxes(e,t,i,r){const n=e%i,a=t%r,o=e-n,s=t-a,l=[];for(let u=0;u<t;u+=r)for(let t=0;t<e;t+=i)l.push({x:t,y:u,w:t===o?n:i,h:u===s?a:r});return l}},ColorHistogram$1=_ColorHistogram$1;__publicField$3(ColorHistogram$1,"_boxSize",[64,64]),__publicField$3(ColorHistogram$1,"_boxPixels",2),__publicField$3(ColorHistogram$1,"_hueGroups",10);var RemovedColor$1=class{constructor(e,t,i){__publicField$3(this,"index"),__publicField$3(this,"color"),__publicField$3(this,"distance"),this.index=e,this.color=t,this.distance=i;}},RGBQuant$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256,i=2){super(),__publicField$3(this,"_colors"),__publicField$3(this,"_initialDistance"),__publicField$3(this,"_distanceIncrement"),__publicField$3(this,"_histogram"),__publicField$3(this,"_distance"),this._distance=e,this._colors=t,this._histogram=new ColorHistogram$1(i,t),this._initialDistance=.01,this._distanceIncrement=.005;}sample(e){this._histogram.sample(e);}*quantize(){const e=this._histogram.getImportanceSortedColorsIDXI32();if(0===e.length)throw new Error("No colors in image");yield*this._buildPalette(e);}*_buildPalette(e){const t=new Palette$1,i=t.getPointContainer().getPointArray(),r=new Array(e.length);for(let t=0;t<e.length;t++)i.push(Point$1.createByUint32(e[t])),r[t]=1;const n=i.length,a=[];let o=n,s=this._initialDistance;const l=new ProgressTracker$1(o-this._colors,99);for(;o>this._colors;){a.length=0;for(let e=0;e<n;e++){if(l.shouldNotify(n-o)&&(yield {progress:l.progress}),0===r[e])continue;const t=i[e];for(let l=e+1;l<n;l++){if(0===r[l])continue;const e=i[l],n=this._distance.calculateNormalized(t,e);n<s&&(a.push(new RemovedColor$1(l,e,n)),r[l]=0,o--);}}s+=o>3*this._colors?this._initialDistance:this._distanceIncrement;}if(o<this._colors){stableSort$1(a,((e,t)=>t.distance-e.distance));let e=0;for(;o<this._colors&&e<a.length;){r[a[e].index]=1,o++,e++;}}let u=i.length;for(let e=u-1;e>=0;e--)0===r[e]&&(e!==u-1&&(i[e]=i[u-1]),--u);i.length=u,t.sort(),yield {palette:t,progress:100};}};function createArray1D$1(e){const t=[];for(let i=0;i<e;i++)t[i]=0;return t}function createArray4D$1(e,t,i,r){const n=new Array(e);for(let a=0;a<e;a++){n[a]=new Array(t);for(let e=0;e<t;e++){n[a][e]=new Array(i);for(let t=0;t<i;t++){n[a][e][t]=new Array(r);for(let i=0;i<r;i++)n[a][e][t][i]=0;}}}return n}function createArray3D$1(e,t,i){const r=new Array(e);for(let n=0;n<e;n++){r[n]=new Array(t);for(let e=0;e<t;e++){r[n][e]=new Array(i);for(let t=0;t<i;t++)r[n][e][t]=0;}}return r}function fillArray3D$1(e,t,i,r,n){for(let a=0;a<t;a++){e[a]=[];for(let t=0;t<i;t++){e[a][t]=[];for(let i=0;i<r;i++)e[a][t][i]=n;}}}function fillArray1D$1(e,t,i){for(let r=0;r<t;r++)e[r]=i;}var WuColorCube$1=class{constructor(){__publicField$3(this,"redMinimum"),__publicField$3(this,"redMaximum"),__publicField$3(this,"greenMinimum"),__publicField$3(this,"greenMaximum"),__publicField$3(this,"blueMinimum"),__publicField$3(this,"blueMaximum"),__publicField$3(this,"volume"),__publicField$3(this,"alphaMinimum"),__publicField$3(this,"alphaMaximum");}},_WuQuant$1=class extends AbstractPaletteQuantizer$1{constructor(e,t=256,i=5){super(),__publicField$3(this,"_reds"),__publicField$3(this,"_greens"),__publicField$3(this,"_blues"),__publicField$3(this,"_alphas"),__publicField$3(this,"_sums"),__publicField$3(this,"_weights"),__publicField$3(this,"_momentsRed"),__publicField$3(this,"_momentsGreen"),__publicField$3(this,"_momentsBlue"),__publicField$3(this,"_momentsAlpha"),__publicField$3(this,"_moments"),__publicField$3(this,"_table"),__publicField$3(this,"_pixels"),__publicField$3(this,"_cubes"),__publicField$3(this,"_colors"),__publicField$3(this,"_significantBitsPerChannel"),__publicField$3(this,"_maxSideIndex"),__publicField$3(this,"_alphaMaxSideIndex"),__publicField$3(this,"_sideSize"),__publicField$3(this,"_alphaSideSize"),__publicField$3(this,"_distance"),this._distance=e,this._setQuality(i),this._initialize(t);}sample(e){const t=e.getPointArray();for(let e=0,i=t.length;e<i;e++)this._addColor(t[e]);this._pixels=this._pixels.concat(t);}*quantize(){yield*this._preparePalette();const e=new Palette$1;for(let t=0;t<this._colors;t++)if(this._sums[t]>0){const i=this._sums[t],r=this._reds[t]/i,n=this._greens[t]/i,a=this._blues[t]/i,o=this._alphas[t]/i,s=Point$1.createByRGBA(0|r,0|n,0|a,0|o);e.add(s);}e.sort(),yield {palette:e,progress:100};}*_preparePalette(){yield*this._calculateMoments();let e=0;const t=createArray1D$1(this._colors);for(let i=1;i<this._colors;++i){this._cut(this._cubes[e],this._cubes[i])?(t[e]=this._cubes[e].volume>1?this._calculateVariance(this._cubes[e]):0,t[i]=this._cubes[i].volume>1?this._calculateVariance(this._cubes[i]):0):(t[e]=0,i--),e=0;let r=t[0];for(let n=1;n<=i;++n)t[n]>r&&(r=t[n],e=n);if(r<=0){this._colors=i+1;break}}const i=[],r=[],n=[],a=[];for(let e=0;e<this._colors;++e){const t=_WuQuant$1._volume(this._cubes[e],this._weights);t>0?(i[e]=_WuQuant$1._volume(this._cubes[e],this._momentsRed)/t|0,r[e]=_WuQuant$1._volume(this._cubes[e],this._momentsGreen)/t|0,n[e]=_WuQuant$1._volume(this._cubes[e],this._momentsBlue)/t|0,a[e]=_WuQuant$1._volume(this._cubes[e],this._momentsAlpha)/t|0):(i[e]=0,r[e]=0,n[e]=0,a[e]=0);}this._reds=createArray1D$1(this._colors+1),this._greens=createArray1D$1(this._colors+1),this._blues=createArray1D$1(this._colors+1),this._alphas=createArray1D$1(this._colors+1),this._sums=createArray1D$1(this._colors+1);for(let e=0,t=this._pixels.length;e<t;e++){const t=this._pixels[e];let o=-1,s=Number.MAX_VALUE;for(let e=0;e<this._colors;e++){const l=i[e],u=r[e],h=n[e],c=a[e],f=this._distance.calculateRaw(l,u,h,c,t.r,t.g,t.b,t.a);f<s&&(s=f,o=e);}this._reds[o]+=t.r,this._greens[o]+=t.g,this._blues[o]+=t.b,this._alphas[o]+=t.a,this._sums[o]++;}}_addColor(e){const t=8-this._significantBitsPerChannel,i=1+(e.r>>t),r=1+(e.g>>t),n=1+(e.b>>t),a=1+(e.a>>t);this._weights[a][i][r][n]++,this._momentsRed[a][i][r][n]+=e.r,this._momentsGreen[a][i][r][n]+=e.g,this._momentsBlue[a][i][r][n]+=e.b,this._momentsAlpha[a][i][r][n]+=e.a,this._moments[a][i][r][n]+=this._table[e.r]+this._table[e.g]+this._table[e.b]+this._table[e.a];}*_calculateMoments(){const e=[],t=[],i=[],r=[],n=[],a=[],o=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),s=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),l=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),u=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),h=createArray3D$1(this._sideSize,this._sideSize,this._sideSize),c=createArray3D$1(this._sideSize,this._sideSize,this._sideSize);let f=0;const d=new ProgressTracker$1(this._alphaMaxSideIndex*this._maxSideIndex,99);for(let p=1;p<=this._alphaMaxSideIndex;++p){fillArray3D$1(o,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(s,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(l,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(u,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(h,this._sideSize,this._sideSize,this._sideSize,0),fillArray3D$1(c,this._sideSize,this._sideSize,this._sideSize,0);for(let m=1;m<=this._maxSideIndex;++m,++f){d.shouldNotify(f)&&(yield {progress:d.progress}),fillArray1D$1(e,this._sideSize,0),fillArray1D$1(t,this._sideSize,0),fillArray1D$1(i,this._sideSize,0),fillArray1D$1(r,this._sideSize,0),fillArray1D$1(n,this._sideSize,0),fillArray1D$1(a,this._sideSize,0);for(let f=1;f<=this._maxSideIndex;++f){let d=0,_=0,g=0,b=0,y=0,w=0;for(let v=1;v<=this._maxSideIndex;++v)d+=this._weights[p][m][f][v],_+=this._momentsRed[p][m][f][v],g+=this._momentsGreen[p][m][f][v],b+=this._momentsBlue[p][m][f][v],y+=this._momentsAlpha[p][m][f][v],w+=this._moments[p][m][f][v],e[v]+=d,t[v]+=_,i[v]+=g,r[v]+=b,n[v]+=y,a[v]+=w,o[m][f][v]=o[m-1][f][v]+e[v],s[m][f][v]=s[m-1][f][v]+t[v],l[m][f][v]=l[m-1][f][v]+i[v],u[m][f][v]=u[m-1][f][v]+r[v],h[m][f][v]=h[m-1][f][v]+n[v],c[m][f][v]=c[m-1][f][v]+a[v],this._weights[p][m][f][v]=this._weights[p-1][m][f][v]+o[m][f][v],this._momentsRed[p][m][f][v]=this._momentsRed[p-1][m][f][v]+s[m][f][v],this._momentsGreen[p][m][f][v]=this._momentsGreen[p-1][m][f][v]+l[m][f][v],this._momentsBlue[p][m][f][v]=this._momentsBlue[p-1][m][f][v]+u[m][f][v],this._momentsAlpha[p][m][f][v]=this._momentsAlpha[p-1][m][f][v]+h[m][f][v],this._moments[p][m][f][v]=this._moments[p-1][m][f][v]+c[m][f][v];}}}}static _volumeFloat(e,t){return t[e.alphaMaximum][e.redMaximum][e.greenMaximum][e.blueMaximum]-t[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMaximum]-t[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMaximum]+t[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMaximum]-t[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMaximum]+t[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMaximum]+t[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMaximum]-t[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(t[e.alphaMaximum][e.redMaximum][e.greenMaximum][e.blueMinimum]-t[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMinimum]-t[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMinimum]+t[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]-t[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMinimum]+t[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]+t[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]-t[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum])}static _volume(e,t){return 0|_WuQuant$1._volumeFloat(e,t)}static _top(e,t,i,r){let n;switch(t){case _WuQuant$1._alpha:n=r[i][e.redMaximum][e.greenMaximum][e.blueMaximum]-r[i][e.redMaximum][e.greenMinimum][e.blueMaximum]-r[i][e.redMinimum][e.greenMaximum][e.blueMaximum]+r[i][e.redMinimum][e.greenMinimum][e.blueMaximum]-(r[i][e.redMaximum][e.greenMaximum][e.blueMinimum]-r[i][e.redMaximum][e.greenMinimum][e.blueMinimum]-r[i][e.redMinimum][e.greenMaximum][e.blueMinimum]+r[i][e.redMinimum][e.greenMinimum][e.blueMinimum]);break;case _WuQuant$1._red:n=r[e.alphaMaximum][i][e.greenMaximum][e.blueMaximum]-r[e.alphaMaximum][i][e.greenMinimum][e.blueMaximum]-r[e.alphaMinimum][i][e.greenMaximum][e.blueMaximum]+r[e.alphaMinimum][i][e.greenMinimum][e.blueMaximum]-(r[e.alphaMaximum][i][e.greenMaximum][e.blueMinimum]-r[e.alphaMaximum][i][e.greenMinimum][e.blueMinimum]-r[e.alphaMinimum][i][e.greenMaximum][e.blueMinimum]+r[e.alphaMinimum][i][e.greenMinimum][e.blueMinimum]);break;case _WuQuant$1._green:n=r[e.alphaMaximum][e.redMaximum][i][e.blueMaximum]-r[e.alphaMaximum][e.redMinimum][i][e.blueMaximum]-r[e.alphaMinimum][e.redMaximum][i][e.blueMaximum]+r[e.alphaMinimum][e.redMinimum][i][e.blueMaximum]-(r[e.alphaMaximum][e.redMaximum][i][e.blueMinimum]-r[e.alphaMaximum][e.redMinimum][i][e.blueMinimum]-r[e.alphaMinimum][e.redMaximum][i][e.blueMinimum]+r[e.alphaMinimum][e.redMinimum][i][e.blueMinimum]);break;case _WuQuant$1._blue:n=r[e.alphaMaximum][e.redMaximum][e.greenMaximum][i]-r[e.alphaMaximum][e.redMaximum][e.greenMinimum][i]-r[e.alphaMaximum][e.redMinimum][e.greenMaximum][i]+r[e.alphaMaximum][e.redMinimum][e.greenMinimum][i]-(r[e.alphaMinimum][e.redMaximum][e.greenMaximum][i]-r[e.alphaMinimum][e.redMaximum][e.greenMinimum][i]-r[e.alphaMinimum][e.redMinimum][e.greenMaximum][i]+r[e.alphaMinimum][e.redMinimum][e.greenMinimum][i]);break;default:throw new Error("impossible")}return 0|n}static _bottom(e,t,i){switch(t){case _WuQuant$1._alpha:return -i[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMaximum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMaximum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMaximum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(-i[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMinimum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);case _WuQuant$1._red:return -i[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMaximum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMaximum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMaximum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(-i[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMinimum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);case _WuQuant$1._green:return -i[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMaximum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMaximum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMaximum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMaximum]-(-i[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);case _WuQuant$1._blue:return -i[e.alphaMaximum][e.redMaximum][e.greenMaximum][e.blueMinimum]+i[e.alphaMaximum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMaximum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMaximum][e.redMinimum][e.greenMinimum][e.blueMinimum]-(-i[e.alphaMinimum][e.redMaximum][e.greenMaximum][e.blueMinimum]+i[e.alphaMinimum][e.redMaximum][e.greenMinimum][e.blueMinimum]+i[e.alphaMinimum][e.redMinimum][e.greenMaximum][e.blueMinimum]-i[e.alphaMinimum][e.redMinimum][e.greenMinimum][e.blueMinimum]);default:return 0}}_calculateVariance(e){const t=_WuQuant$1._volume(e,this._momentsRed),i=_WuQuant$1._volume(e,this._momentsGreen),r=_WuQuant$1._volume(e,this._momentsBlue),n=_WuQuant$1._volume(e,this._momentsAlpha);return _WuQuant$1._volumeFloat(e,this._moments)-(t*t+i*i+r*r+n*n)/_WuQuant$1._volume(e,this._weights)}_maximize(e,t,i,r,n,a,o,s,l){const u=0|_WuQuant$1._bottom(e,t,this._momentsRed),h=0|_WuQuant$1._bottom(e,t,this._momentsGreen),c=0|_WuQuant$1._bottom(e,t,this._momentsBlue),f=0|_WuQuant$1._bottom(e,t,this._momentsAlpha),d=0|_WuQuant$1._bottom(e,t,this._weights);let p=0,m=-1;for(let _=i;_<r;++_){let i=u+_WuQuant$1._top(e,t,_,this._momentsRed),r=h+_WuQuant$1._top(e,t,_,this._momentsGreen),g=c+_WuQuant$1._top(e,t,_,this._momentsBlue),b=f+_WuQuant$1._top(e,t,_,this._momentsAlpha),y=d+_WuQuant$1._top(e,t,_,this._weights);if(0!==y){let e=i*i+r*r+g*g+b*b,t=e/y;i=n-i,r=a-r,g=o-g,b=s-b,y=l-y,0!==y&&(e=i*i+r*r+g*g+b*b,t+=e/y,t>p&&(p=t,m=_));}}return {max:p,position:m}}_cut(e,t){let i;const r=_WuQuant$1._volume(e,this._momentsRed),n=_WuQuant$1._volume(e,this._momentsGreen),a=_WuQuant$1._volume(e,this._momentsBlue),o=_WuQuant$1._volume(e,this._momentsAlpha),s=_WuQuant$1._volume(e,this._weights),l=this._maximize(e,_WuQuant$1._red,e.redMinimum+1,e.redMaximum,r,n,a,o,s),u=this._maximize(e,_WuQuant$1._green,e.greenMinimum+1,e.greenMaximum,r,n,a,o,s),h=this._maximize(e,_WuQuant$1._blue,e.blueMinimum+1,e.blueMaximum,r,n,a,o,s),c=this._maximize(e,_WuQuant$1._alpha,e.alphaMinimum+1,e.alphaMaximum,r,n,a,o,s);if(c.max>=l.max&&c.max>=u.max&&c.max>=h.max){if(i=_WuQuant$1._alpha,c.position<0)return false}else i=l.max>=c.max&&l.max>=u.max&&l.max>=h.max?_WuQuant$1._red:u.max>=c.max&&u.max>=l.max&&u.max>=h.max?_WuQuant$1._green:_WuQuant$1._blue;switch(t.redMaximum=e.redMaximum,t.greenMaximum=e.greenMaximum,t.blueMaximum=e.blueMaximum,t.alphaMaximum=e.alphaMaximum,i){case _WuQuant$1._red:t.redMinimum=e.redMaximum=l.position,t.greenMinimum=e.greenMinimum,t.blueMinimum=e.blueMinimum,t.alphaMinimum=e.alphaMinimum;break;case _WuQuant$1._green:t.greenMinimum=e.greenMaximum=u.position,t.redMinimum=e.redMinimum,t.blueMinimum=e.blueMinimum,t.alphaMinimum=e.alphaMinimum;break;case _WuQuant$1._blue:t.blueMinimum=e.blueMaximum=h.position,t.redMinimum=e.redMinimum,t.greenMinimum=e.greenMinimum,t.alphaMinimum=e.alphaMinimum;break;case _WuQuant$1._alpha:t.alphaMinimum=e.alphaMaximum=c.position,t.blueMinimum=e.blueMinimum,t.redMinimum=e.redMinimum,t.greenMinimum=e.greenMinimum;}return e.volume=(e.redMaximum-e.redMinimum)*(e.greenMaximum-e.greenMinimum)*(e.blueMaximum-e.blueMinimum)*(e.alphaMaximum-e.alphaMinimum),t.volume=(t.redMaximum-t.redMinimum)*(t.greenMaximum-t.greenMinimum)*(t.blueMaximum-t.blueMinimum)*(t.alphaMaximum-t.alphaMinimum),true}_initialize(e){this._colors=e,this._cubes=[];for(let t=0;t<e;t++)this._cubes[t]=new WuColorCube$1;this._cubes[0].redMinimum=0,this._cubes[0].greenMinimum=0,this._cubes[0].blueMinimum=0,this._cubes[0].alphaMinimum=0,this._cubes[0].redMaximum=this._maxSideIndex,this._cubes[0].greenMaximum=this._maxSideIndex,this._cubes[0].blueMaximum=this._maxSideIndex,this._cubes[0].alphaMaximum=this._alphaMaxSideIndex,this._weights=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsRed=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsGreen=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsBlue=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._momentsAlpha=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._moments=createArray4D$1(this._alphaSideSize,this._sideSize,this._sideSize,this._sideSize),this._table=[];for(let e=0;e<256;++e)this._table[e]=e*e;this._pixels=[];}_setQuality(e=5){this._significantBitsPerChannel=e,this._maxSideIndex=1<<this._significantBitsPerChannel,this._alphaMaxSideIndex=this._maxSideIndex,this._sideSize=this._maxSideIndex+1,this._alphaSideSize=this._alphaMaxSideIndex+1;}},WuQuant$1=_WuQuant$1;__publicField$3(WuQuant$1,"_alpha",3),__publicField$3(WuQuant$1,"_red",2),__publicField$3(WuQuant$1,"_green",1),__publicField$3(WuQuant$1,"_blue",0);var image_exports$1={};__export$1(image_exports$1,{AbstractImageQuantizer:()=>AbstractImageQuantizer$1,ErrorDiffusionArray:()=>ErrorDiffusionArray$1,ErrorDiffusionArrayKernel:()=>ErrorDiffusionArrayKernel$1,ErrorDiffusionRiemersma:()=>ErrorDiffusionRiemersma$1,NearestColor:()=>NearestColor$1});var AbstractImageQuantizer$1=class{quantizeSync(e,t){for(const i of this.quantize(e,t))if(i.pointContainer)return i.pointContainer;throw new Error("unreachable")}},NearestColor$1=class extends AbstractImageQuantizer$1{constructor(e){super(),__publicField$3(this,"_distance"),this._distance=e;}*quantize(e,t){const i=e.getPointArray(),r=e.getWidth(),n=e.getHeight(),a=new ProgressTracker$1(n,99);for(let e=0;e<n;e++){a.shouldNotify(e)&&(yield {progress:a.progress});for(let n=0,a=e*r;n<r;n++,a++){const e=i[a];e.from(t.getNearestColor(this._distance,e));}}yield {pointContainer:e,progress:100};}},ErrorDiffusionArrayKernel$1=(e=>(e[e.FloydSteinberg=0]="FloydSteinberg",e[e.FalseFloydSteinberg=1]="FalseFloydSteinberg",e[e.Stucki=2]="Stucki",e[e.Atkinson=3]="Atkinson",e[e.Jarvis=4]="Jarvis",e[e.Burkes=5]="Burkes",e[e.Sierra=6]="Sierra",e[e.TwoSierra=7]="TwoSierra",e[e.SierraLite=8]="SierraLite",e))(ErrorDiffusionArrayKernel$1||{}),ErrorDiffusionArray$1=class extends AbstractImageQuantizer$1{constructor(e,t,i=true,r=0,n=false){super(),__publicField$3(this,"_minColorDistance"),__publicField$3(this,"_serpentine"),__publicField$3(this,"_kernel"),__publicField$3(this,"_calculateErrorLikeGIMP"),__publicField$3(this,"_distance"),this._setKernel(t),this._distance=e,this._minColorDistance=r,this._serpentine=i,this._calculateErrorLikeGIMP=n;}*quantize(e,t){const i=e.getPointArray(),r=new Point$1,n=e.getWidth(),a=e.getHeight(),o=[];let s=1,l=1;for(const e of this._kernel){const t=e[2]+1;l<t&&(l=t);}for(let e=0;e<l;e++)this._fillErrorLine(o[e]=[],n);const u=new ProgressTracker$1(a,99);for(let e=0;e<a;e++){u.shouldNotify(e)&&(yield {progress:u.progress}),this._serpentine&&(s*=-1);const l=e*n,h=1===s?0:n-1,c=1===s?n:-1;this._fillErrorLine(o[0],n),o.push(o.shift());const f=o[0];for(let u=h,d=l+h;u!==c;u+=s,d+=s){const l=i[d],h=f[u];r.from(l);const c=Point$1.createByRGBA(inRange0to255Rounded$1(l.r+h[0]),inRange0to255Rounded$1(l.g+h[1]),inRange0to255Rounded$1(l.b+h[2]),inRange0to255Rounded$1(l.a+h[3])),p=t.getNearestColor(this._distance,c);if(l.from(p),this._minColorDistance){if(this._distance.calculateNormalized(r,p)<this._minColorDistance)continue}let m,_,g,b;this._calculateErrorLikeGIMP?(m=c.r-p.r,_=c.g-p.g,g=c.b-p.b,b=c.a-p.a):(m=r.r-p.r,_=r.g-p.g,g=r.b-p.b,b=r.a-p.a);const y=1===s?0:this._kernel.length-1,w=1===s?this._kernel.length:-1;for(let t=y;t!==w;t+=s){const i=this._kernel[t][1]*s,r=this._kernel[t][2];if(i+u>=0&&i+u<n&&r+e>=0&&r+e<a){const e=this._kernel[t][0],n=o[r][i+u];n[0]+=m*e,n[1]+=_*e,n[2]+=g*e,n[3]+=b*e;}}}}yield {pointContainer:e,progress:100};}_fillErrorLine(e,t){e.length>t&&(e.length=t);const i=e.length;for(let t=0;t<i;t++){const i=e[t];i[0]=i[1]=i[2]=i[3]=0;}for(let r=i;r<t;r++)e[r]=[0,0,0,0];}_setKernel(e){switch(e){case 0:this._kernel=[[7/16,1,0],[3/16,-1,1],[5/16,0,1],[1/16,1,1]];break;case 1:this._kernel=[[3/8,1,0],[3/8,0,1],[2/8,1,1]];break;case 2:this._kernel=[[8/42,1,0],[4/42,2,0],[2/42,-2,1],[4/42,-1,1],[8/42,0,1],[4/42,1,1],[2/42,2,1],[1/42,-2,2],[2/42,-1,2],[4/42,0,2],[2/42,1,2],[1/42,2,2]];break;case 3:this._kernel=[[1/8,1,0],[1/8,2,0],[1/8,-1,1],[1/8,0,1],[1/8,1,1],[1/8,0,2]];break;case 4:this._kernel=[[7/48,1,0],[5/48,2,0],[3/48,-2,1],[5/48,-1,1],[7/48,0,1],[5/48,1,1],[3/48,2,1],[1/48,-2,2],[3/48,-1,2],[5/48,0,2],[3/48,1,2],[1/48,2,2]];break;case 5:this._kernel=[[.25,1,0],[4/32,2,0],[2/32,-2,1],[4/32,-1,1],[.25,0,1],[4/32,1,1],[2/32,2,1]];break;case 6:this._kernel=[[5/32,1,0],[3/32,2,0],[2/32,-2,1],[4/32,-1,1],[5/32,0,1],[4/32,1,1],[2/32,2,1],[2/32,-1,2],[3/32,0,2],[2/32,1,2]];break;case 7:this._kernel=[[.25,1,0],[3/16,2,0],[1/16,-2,1],[2/16,-1,1],[3/16,0,1],[2/16,1,1],[1/16,2,1]];break;case 8:this._kernel=[[.5,1,0],[1/4,-1,1],[1/4,0,1]];break;default:throw new Error(`ErrorDiffusionArray: unknown kernel = ${e}`)}}};function*hilbertCurve$1(e,t,i){const r=Math.max(e,t),n={width:e,height:t,level:Math.floor(Math.log(r)/Math.log(2)+1),callback:i,tracker:new ProgressTracker$1(e*t,99),index:0,x:0,y:0};yield*walkHilbert$1(n,1),visit$1(n,0);}function*walkHilbert$1(e,t){if(!(e.level<1)){switch(e.tracker.shouldNotify(e.index)&&(yield {progress:e.tracker.progress}),e.level--,t){case 2:yield*walkHilbert$1(e,1),visit$1(e,3),yield*walkHilbert$1(e,2),visit$1(e,4),yield*walkHilbert$1(e,2),visit$1(e,2),yield*walkHilbert$1(e,4);break;case 3:yield*walkHilbert$1(e,4),visit$1(e,2),yield*walkHilbert$1(e,3),visit$1(e,1),yield*walkHilbert$1(e,3),visit$1(e,3),yield*walkHilbert$1(e,1);break;case 1:yield*walkHilbert$1(e,2),visit$1(e,4),yield*walkHilbert$1(e,1),visit$1(e,3),yield*walkHilbert$1(e,1),visit$1(e,1),yield*walkHilbert$1(e,3);break;case 4:yield*walkHilbert$1(e,3),visit$1(e,1),yield*walkHilbert$1(e,4),visit$1(e,2),yield*walkHilbert$1(e,4),visit$1(e,4),yield*walkHilbert$1(e,2);}e.level++;}}function visit$1(e,t){switch(e.x>=0&&e.x<e.width&&e.y>=0&&e.y<e.height&&(e.callback(e.x,e.y),e.index++),t){case 2:e.x--;break;case 3:e.x++;break;case 1:e.y--;break;case 4:e.y++;}}var ErrorDiffusionRiemersma$1=class extends AbstractImageQuantizer$1{constructor(e,t=16,i=1){super(),__publicField$3(this,"_distance"),__publicField$3(this,"_weights"),__publicField$3(this,"_errorQueueSize"),this._distance=e,this._errorQueueSize=t,this._weights=ErrorDiffusionRiemersma$1._createWeights(i,t);}*quantize(e,t){const i=e.getPointArray(),r=e.getWidth(),n=e.getHeight(),a=[];let o=0;for(let e=0;e<this._errorQueueSize;e++)a[e]={r:0,g:0,b:0,a:0};yield*hilbertCurve$1(r,n,((e,n)=>{const s=i[e+n*r];let{r:l,g:u,b:h,a:c}=s;for(let e=0;e<this._errorQueueSize;e++){const t=this._weights[e],i=a[(e+o)%this._errorQueueSize];l+=i.r*t,u+=i.g*t,h+=i.b*t,c+=i.a*t;}const f=Point$1.createByRGBA(inRange0to255Rounded$1(l),inRange0to255Rounded$1(u),inRange0to255Rounded$1(h),inRange0to255Rounded$1(c)),d=t.getNearestColor(this._distance,f);o=(o+1)%this._errorQueueSize;const p=(o+this._errorQueueSize-1)%this._errorQueueSize;a[p].r=s.r-d.r,a[p].g=s.g-d.g,a[p].b=s.b-d.b,a[p].a=s.a-d.a,s.from(d);})),yield {pointContainer:e,progress:100};}static _createWeights(e,t){const i=[],r=Math.exp(Math.log(t)/(t-1));for(let n=0,a=1;n<t;n++)i[n]=(a+.5|0)/t*e,a*=r;return i}},quality_exports$1={};__export$1(quality_exports$1,{ssim:()=>ssim$1});var K1$1=.01,K2$1=.03;function ssim$1(e,t){if(e.getHeight()!==t.getHeight()||e.getWidth()!==t.getWidth())throw new Error("Images have different sizes!");const i=(255*K1$1)**2,r=(255*K2$1)**2;let n=0,a=0;return iterate$1(e,t,((e,t,o,s)=>{let l=0,u=0,h=0;for(let i=0;i<e.length;i++)u+=(e[i]-o)**2,h+=(t[i]-s)**2,l+=(e[i]-o)*(t[i]-s);const c=e.length-1;u/=c,h/=c,l/=c;a+=(2*o*s+i)*(2*l+r)/((o**2+s**2+i)*(u+h+r)),n++;})),a/n}function iterate$1(e,t,i){const r=e.getWidth(),n=e.getHeight();for(let a=0;a<n;a+=8)for(let o=0;o<r;o+=8){const s=Math.min(8,r-o),l=Math.min(8,n-a),u=calculateLumaValuesForWindow$1(e,o,a,s,l),h=calculateLumaValuesForWindow$1(t,o,a,s,l);i(u,h,calculateAverageLuma$1(u),calculateAverageLuma$1(h));}}function calculateLumaValuesForWindow$1(e,t,i,r,n){const a=e.getPointArray(),o=[];let s=0;for(let l=i;l<i+n;l++){const i=l*e.getWidth();for(let e=t;e<t+r;e++){const t=a[i+e];o[s]=.2126*t.r+.7152*t.g+.0722*t.b,s++;}}return o}function calculateAverageLuma$1(e){let t=0;for(const i of e)t+=i;return t/e.length}var setImmediateImpl="function"==typeof setImmediate?setImmediate:"undefined"!=typeof process&&"function"==typeof(null==process?void 0:process.nextTick)?e=>process.nextTick(e):e=>setTimeout(e,0);function buildPaletteSync$1(e,{colorDistanceFormula:t,paletteQuantization:i,colors:r}={}){const n=paletteQuantizationToPaletteQuantizer$1(colorDistanceFormulaToColorDistance$1(t),i,r);return e.forEach((e=>n.sample(e))),n.quantizeSync()}async function buildPalette(e,{colorDistanceFormula:t,paletteQuantization:i,colors:r,onProgress:n}={}){return new Promise(((a,o)=>{const s=paletteQuantizationToPaletteQuantizer$1(colorDistanceFormulaToColorDistance$1(t),i,r);let l;e.forEach((e=>s.sample(e)));const u=s.quantize(),h=()=>{try{const e=u.next();e.done?a(l):(e.value.palette&&(l=e.value.palette),n&&n(e.value.progress),setImmediateImpl(h));}catch(e){o(e);}};setImmediateImpl(h);}))}function applyPaletteSync$1(e,t,{colorDistanceFormula:i,imageQuantization:r}={}){return imageQuantizationToImageQuantizer$1(colorDistanceFormulaToColorDistance$1(i),r).quantizeSync(e,t)}async function applyPalette(e,t,{colorDistanceFormula:i,imageQuantization:r,onProgress:n}={}){return new Promise(((a,o)=>{let s;const l=imageQuantizationToImageQuantizer$1(colorDistanceFormulaToColorDistance$1(i),r).quantize(e,t),u=()=>{try{const e=l.next();e.done?a(s):(e.value.pointContainer&&(s=e.value.pointContainer),n&&n(e.value.progress),setImmediateImpl(u));}catch(e){o(e);}};setImmediateImpl(u);}))}function colorDistanceFormulaToColorDistance$1(e="euclidean-bt709"){switch(e){case "cie94-graphic-arts":return new CIE94GraphicArts$1;case "cie94-textiles":return new CIE94Textiles$1;case "ciede2000":return new CIEDE2000$1;case "color-metric":return new CMetric$1;case "euclidean":return new Euclidean$1;case "euclidean-bt709":return new EuclideanBT709$1;case "euclidean-bt709-noalpha":return new EuclideanBT709NoAlpha$1;case "manhattan":return new Manhattan$1;case "manhattan-bt709":return new ManhattanBT709$1;case "manhattan-nommyde":return new ManhattanNommyde$1;case "pngquant":return new PNGQuant$1;default:throw new Error(`Unknown colorDistanceFormula ${e}`)}}function imageQuantizationToImageQuantizer$1(e,t="floyd-steinberg"){switch(t){case "nearest":return new NearestColor$1(e);case "riemersma":return new ErrorDiffusionRiemersma$1(e);case "floyd-steinberg":return new ErrorDiffusionArray$1(e,0);case "false-floyd-steinberg":return new ErrorDiffusionArray$1(e,1);case "stucki":return new ErrorDiffusionArray$1(e,2);case "atkinson":return new ErrorDiffusionArray$1(e,3);case "jarvis":return new ErrorDiffusionArray$1(e,4);case "burkes":return new ErrorDiffusionArray$1(e,5);case "sierra":return new ErrorDiffusionArray$1(e,6);case "two-sierra":return new ErrorDiffusionArray$1(e,7);case "sierra-lite":return new ErrorDiffusionArray$1(e,8);default:throw new Error(`Unknown imageQuantization ${t}`)}}function paletteQuantizationToPaletteQuantizer$1(e,t="wuquant",i=256){switch(t){case "neuquant":return new NeuQuant$1(e,i);case "rgbquant":return new RGBQuant$1(e,i);case "wuquant":return new WuQuant$1(e,i);case "neuquant-float":return new NeuQuantFloat$1(e,i);default:throw new Error(`Unknown paletteQuantization ${t}`)}}var imageQ=__toCommonJS(src_exports),gifframe={};const BitmapImage$1=bitmapimage;let GifFrame$1=class e extends BitmapImage$1{constructor(...t){if(super(...t),t[0]instanceof e){const e=t[0];this.xOffset=e.xOffset,this.yOffset=e.yOffset,this.disposalMethod=e.disposalMethod,this.delayCentisecs=e.delayCentisecs,this.interlaced=e.interlaced;}else {const i=t[t.length-1];let r={};"object"!=typeof i||i instanceof BitmapImage$1||(r=i),this.xOffset=r.xOffset||0,this.yOffset=r.yOffset||0,this.disposalMethod=void 0!==r.disposalMethod?r.disposalMethod:e.DisposeToBackgroundColor,this.delayCentisecs=r.delayCentisecs||8,this.interlaced=r.interlaced||false;}}getPalette(){const e=new Set,t=this.bitmap.data;let i=0,r=false;for(;i<t.length;){if(0===t[i+3])r=true;else {const r=t.readUInt32BE(i,true)>>8&16777215;e.add(r);}i+=4;}const n=new Array(e.size),a=e.values();for(i=0;i<n.length;++i)n[i]=a.next().value;n.sort(((e,t)=>e-t));let o=n.length;return r&&++o,{colors:n,usesTransparency:r,indexCount:o}}};var hasRequiredGifutil,hasRequiredGifcodec;function requireGifutil(){return hasRequiredGifutil||(hasRequiredGifutil=1,function(e){const t=require$$0,i=imageQ,r=bitmapimage,{GifFrame:n}=gifframe,{GifError:a}=gif$1,{GifCodec:o}=requireGifcodec(),s=[".jpg",".jpeg",".png",".bmp"],l=new o;function u(e,t,r,n,a){const o=Array.isArray(e)?e:[e];if(a){if(["FloydSteinberg","FalseFloydSteinberg","Stucki","Atkinson","Jarvis","Burkes","Sierra","TwoSierra","SierraLite"].indexOf(a.ditherAlgorithm)<0)throw new Error(`Invalid ditherAlgorithm '${a.ditherAlgorithm}'`);void 0===a.serpentine&&(a.serpentine=true),void 0===a.minimumColorDistanceToDither&&(a.minimumColorDistanceToDither=0),void 0===a.calculateErrorLikeGIMP&&(a.calculateErrorLikeGIMP=false);}const s=new i.distance.Euclidean,l=new i.palette[t](s,r,n);let u;u=a?new i.image.ErrorDiffusionArray(s,i.image.ErrorDiffusionArrayKernel[a.ditherAlgorithm],a.serpentine,a.minimumColorDistanceToDither,a.calculateErrorLikeGIMP):new i.image.NearestColor(s);const h=[];o.forEach((e=>{const t=e.bitmap.data,r=new ArrayBuffer(t.length),n=new Uint32Array(r);for(let e=0,i=0;e<t.length;e+=4,++i)n[i]=t.readUInt32LE(e,true);const a=i.utils.PointContainer.fromUint32Array(n,e.bitmap.width,e.bitmap.height);l.sample(a),h.push(a);}));const c=l.quantizeSync();for(let e=0;e<o.length;++e){const t=o[e].bitmap.data,i=u.quantizeSync(h[e],c).toUint32Array();for(let e=0,r=0;e<t.length;e+=4,++r)t.writeUInt32LE(i[r],e);}}e.cloneFrames=function(e){let t=[];return e.forEach((e=>{t.push(new n(e));})),t},e.getColorInfo=function(e,t){let i=false;const r=[];for(let t=0;t<e.length;++t){let n=e[t].getPalette();if(n.usesTransparency&&(i=true),n.indexCount>256)throw new a(`Frame ${t} uses more than 256 color indexes`);r.push(n);}if(0===t)return {usesTransparency:i,palettes:r};const n=new Set;r.forEach((e=>{e.colors.forEach((e=>{n.add(e);}));}));let o=n.size;if(i&&++o,t&&o>t)return {usesTransparency:i,palettes:r};const s=new Array(n.size),l=n.values();for(let e=0;e<s.length;++e)s[e]=l.next().value;return s.sort(((e,t)=>e-t)),{colors:s,indexCount:o,usesTransparency:i,palettes:r}},e.copyAsJimp=function(t,i){return e.shareAsJimp(t,new r(i))},e.getMaxDimensions=function(e){let t=0,i=0;return e.forEach((e=>{const r=e.xOffset+e.bitmap.width;r>t&&(t=r);const n=e.yOffset+e.bitmap.height;n>i&&(i=n);})),{maxWidth:t,maxHeight:i}},e.quantizeDekker=function(e,t,i){u(e,"NeuQuantFloat",t=t||256,0,i);},e.quantizeSorokin=function(e,t,i,r){let n;switch(t=t||256,i=i||"min-pop"){case "min-pop":n=2;break;case "top-pop":n=1;break;default:throw new Error(`Invalid quantizeSorokin histogram '${i}'`)}u(e,"RGBQuant",t,n,r);},e.quantizeWu=function(e,t,i,r){if(t=t||256,(i=i||5)<1||i>8)throw new Error("Invalid quantization quality");u(e,"WuQuant",t,i,r);},e.read=function(e,i){return i=i||l,Buffer$1.isBuffer(e)?i.decodeGif(e):function(e){return new Promise(((i,r)=>{t.readFile(e,((e,t)=>e?r(e):i(t)));}))}(e).then((e=>i.decodeGif(e)))},e.shareAsJimp=function(e,t){const i=new e(t.bitmap.width,t.bitmap.height,0);return i.bitmap.data=t.bitmap.data,i},e.write=function(e,i,r,n){n=n||l;const a=e.match(/\.[a-zA-Z]+$/);if(null!==a&&s.includes(a[0].toLowerCase()))throw new Error(`GIF '${e}' has an unexpected suffix`);return n.encodeGif(i,r).then((i=>function(e,i){return new Promise(((r,n)=>{t.writeFile(e,i,(e=>e?n(e):r()));}))}(e,i.buffer).then((()=>i))))};}(gifutil)),gifutil}function requireGifcodec(){if(hasRequiredGifcodec)return gifcodec;hasRequiredGifcodec=1;const e=omggif,{Gif:t,GifError:i}=gif$1;function r(){const e=requireGifutil();return r=function(){return e},e}const{GifFrame:n}=gifframe;function a(e,t){const i=e.indexOf(t);return -1===i?null:i}function o(e,t){for(var i,r=0,n=e.length-1;r<=n;)if(e[i=Math.floor((r+n)/2)]>t)n=i-1;else {if(!(e[i]<t))return i;r=i+1;}return null}function s(e){const t=e.colors;e.usesTransparency&&t.push(0);const i=t.length;let r=2;for(;i>r;)r<<=1;t.length=r,t.fill(0,i);}function l(e,t){let i=e.bitmap.width*e.bitmap.height;return i=Math.ceil(i*t/8),i+=Math.ceil(i/255),100+i+768}function u(e){let t=e.indexCount,i=0;for(--t;t;)++i,t>>=1;return i>0?i:1}function h(e,t,r,n,l){if(r.interlaced)throw new i("writing interlaced GIFs is not supported");const u=function(e,t,r){const n=r.colors,s=n.length<=8?a:o,l=t.bitmap.data,u=new Buffer$1(l.length/4);let h=n.length,c=0,f=0;for(;c<l.length;){if(0!==l[c+3]){const e=l.readUInt32BE(c,true)>>8&16777215;u[f]=s(n,e);}else u[f]=h;c+=4,++f;}if(r.usesTransparency){if(256===h)throw new i(`Frame ${e} already has 256 colorsand so can't use transparency`)}else h=null;return {buffer:u,transparentIndex:h}}(t,r,n),h={delay:r.delayCentisecs,disposal:r.disposalMethod,transparent:u.transparentIndex};l&&(s(n),h.palette=n.colors);try{let t,i=e.getOutputBuffer(),n=e.getOutputBufferPosition(),a=!0;for(;a;)if(t=e.addFrame(r.xOffset,r.yOffset,r.bitmap.width,r.bitmap.height,u.buffer,h),a=!1,t>=i.length-1){const t=new Buffer$1(1.5*i.length);i.copy(t),e.setOutputBuffer(t),e.setOutputBufferPosition(n),i=t,a=!0;}return i}catch(e){throw new i(e)}}return gifcodec.GifCodec=class{constructor(e={}){this._transparentRGB=null,"number"==typeof e.transparentRGB&&0!==e.transparentRGB&&(this._transparentRGBA=256*e.transparentRGB),this._testInitialBufferSize=0;}decodeGif(r){try{let n;try{n=new e.GifReader(r);}catch(e){throw new i(e)}const a=n.numFrames(),o=[],s={width:n.width,height:n.height,loops:n.loopCount(),usesTransparency:!1};for(let e=0;e<a;++e){const t=this._decodeFrame(n,e,s.usesTransparency);o.push(t.frame),t.usesTransparency&&(s.usesTransparency=!0);}return Promise.resolve(new t(r,o,s))}catch(e){return Promise.reject(e)}}encodeGif(e,n={}){try{if(null===e||0===e.length)throw new i("there are no frames");const a=r().getMaxDimensions(e);return (n=Object.assign({},n)).width=a.maxWidth,n.height=a.maxHeight,void 0===n.loops&&(n.loops=0),n.colorScope=n.colorScope||t.GlobalColorsPreferred,Promise.resolve(this._encodeGif(e,n))}catch(e){return Promise.reject(e)}}_decodeFrame(e,t,r){let a,o;try{if(a=e.frameInfo(t),o=new Buffer$1(e.width*e.height*4),e.decodeAndBlitFrameRGBA(t,o),a.width!==e.width||a.height!==e.height){if(a.y&&(o=o.slice(a.y*e.width*4)),e.width>a.width)for(let t=0;t<a.height;++t)o.copy(o,t*a.width*4,4*(a.x+t*e.width),4*(a.x+t*e.width)+4*a.width);o=o.slice(0,a.width*a.height*4);}}catch(e){throw new i(e)}let s=false;if(null===this._transparentRGBA){if(!r)for(let e=3;e<o.length;e+=4)0===o[e]&&(s=true,e=o.length);}else for(let e=3;e<o.length;e+=4)0===o[e]&&(o.writeUInt32BE(this._transparentRGBA,e-3),s=true);return {frame:new n(a.width,a.height,o,{xOffset:a.x,yOffset:a.y,disposalMethod:a.disposal,interlaced:a.interlaced,delayCentisecs:a.delay}),usesTransparency:s}}_encodeGif(n,a){let o;if(a.colorScope===t.LocalColorsOnly)o=r().getColorInfo(n,0);else if(o=r().getColorInfo(n,256),!o.colors){if(a.colorScope===t.GlobalColorsOnly)throw new i("Too many color indexes for global color table");a.colorScope=t.LocalColorsOnly;}a.usesTransparency=o.usesTransparency;const l=o.palettes;if(a.colorScope===t.LocalColorsOnly){return function(r,n,a,o){const s={loop:n.loops};let l,u=new Buffer$1(a);try{l=new e.GifWriter(u,n.width,n.height,s);}catch(e){throw new i(e)}for(let e=0;e<r.length;++e)u=h(l,e,r[e],o[e],true);return new t(u.slice(0,l.end()),r,n)}(n,a,2e3,l)}return function(r,n,a,o){const l={colors:o.colors.slice(),usesTransparency:o.usesTransparency};s(l);const u={palette:l.colors,loop:n.loops};let c,f=new Buffer$1(a);try{c=new e.GifWriter(f,n.width,n.height,u);}catch(e){throw new i(e)}for(let e=0;e<r.length;++e)f=h(c,e,r[e],o,false);return new t(f.slice(0,c.end()),r,n)}(n,a,2e3,o)}_getSizeEstimateGlobal(e,t){if(this._testInitialBufferSize>0)return this._testInitialBufferSize;let i=968;const r=u(e);return t.forEach((e=>{i+=l(e,r);})),i}_getSizeEstimateLocal(e,t){if(this._testInitialBufferSize>0)return this._testInitialBufferSize;let i=200;for(let r=0;r<t.length;++r){const n=u(e[r]);i+=l(t[r],n);}return i}},gifcodec}GifFrame$1.DisposeToAnything=0,GifFrame$1.DisposeNothing=1,GifFrame$1.DisposeToBackgroundColor=2,GifFrame$1.DisposeToPrevious=3,gifframe.GifFrame=GifFrame$1;const BitmapImage=bitmapimage,{GifCodec:GifCodec}=requireGifcodec(),{GifFrame:GifFrame}=gifframe,GifUtil=requireGifutil();var src={BitmapImage:BitmapImage,GifCodec:GifCodec,GifFrame:GifFrame,GifUtil:GifUtil};function gif(){return {mime:"image/gif",encode:async e=>{const t=new src.BitmapImage(e);src.GifUtil.quantizeDekker(t,256);const i=new src.GifFrame(e),r=new src.GifCodec;return (await r.encodeGif([i],{})).buffer},decode:e=>{const t=new omggif.GifReader(e),i=Buffer$1.alloc(t.width*t.height*4);return t.decodeAndBlitFrameRGBA(0,i),{data:i,width:t.width,height:t.height}}}}var encoder={exports:{}};!function(e){function t(e){var t,i,r,n,a,o=Math.floor,s=new Array(64),l=new Array(64),u=new Array(64),h=new Array(64),c=new Array(65535),f=new Array(65535),d=new Array(64),p=new Array(64),m=[],_=0,g=7,b=new Array(64),y=new Array(64),w=new Array(64),v=new Array(256),x=new Array(2048),E=[0,1,5,6,14,15,27,28,2,4,7,13,16,26,29,42,3,8,12,17,25,30,41,43,9,11,18,24,31,40,44,53,10,19,23,32,39,45,52,54,20,22,33,38,46,51,55,60,21,34,37,47,50,56,59,61,35,36,48,49,57,58,62,63],k=[0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0],S=[0,1,2,3,4,5,6,7,8,9,10,11],A=[0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,125],I=[1,2,3,0,4,17,5,18,33,49,65,6,19,81,97,7,34,113,20,50,129,145,161,8,35,66,177,193,21,82,209,240,36,51,98,114,130,9,10,22,23,24,25,26,37,38,39,40,41,42,52,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,225,226,227,228,229,230,231,232,233,234,241,242,243,244,245,246,247,248,249,250],M=[0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0],T=[0,1,2,3,4,5,6,7,8,9,10,11],P=[0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,119],B=[0,1,2,3,17,4,5,33,49,6,18,65,81,7,97,113,19,34,50,129,8,20,66,145,161,177,193,9,35,51,82,240,21,98,114,209,10,22,36,52,225,37,241,23,24,25,26,38,39,40,41,42,53,54,55,56,57,58,67,68,69,70,71,72,73,74,83,84,85,86,87,88,89,90,99,100,101,102,103,104,105,106,115,116,117,118,119,120,121,122,130,131,132,133,134,135,136,137,138,146,147,148,149,150,151,152,153,154,162,163,164,165,166,167,168,169,170,178,179,180,181,182,183,184,185,186,194,195,196,197,198,199,200,201,202,210,211,212,213,214,215,216,217,218,226,227,228,229,230,231,232,233,234,242,243,244,245,246,247,248,249,250];function C(e,t){for(var i=0,r=0,n=new Array,a=1;a<=16;a++){for(var o=1;o<=e[a];o++)n[t[r]]=[],n[t[r]][0]=i,n[t[r]][1]=a,r++,i++;i*=2;}return n}function R(e){for(var t=e[0],i=e[1]-1;i>=0;)t&1<<i&&(_|=1<<g),i--,--g<0&&(255==_?(z(255),z(0)):z(_),g=7,_=0);}function z(e){m.push(e);}function F(e){z(e>>8&255),z(255&e);}function N(e,t,i,r,n){for(var a,o=n[0],s=n[240],l=function(e,t){var i,r,n,a,o,s,l,u,h,c,f=0;for(h=0;h<8;++h){i=e[f],r=e[f+1],n=e[f+2],a=e[f+3],o=e[f+4],s=e[f+5],l=e[f+6];var p=i+(u=e[f+7]),m=i-u,_=r+l,g=r-l,b=n+s,y=n-s,w=a+o,v=a-o,x=p+w,E=p-w,k=_+b,S=_-b;e[f]=x+k,e[f+4]=x-k;var A=.707106781*(S+E);e[f+2]=E+A,e[f+6]=E-A;var I=.382683433*((x=v+y)-(S=g+m)),M=.5411961*x+I,T=1.306562965*S+I,P=.707106781*(k=y+g),B=m+P,C=m-P;e[f+5]=C+M,e[f+3]=C-M,e[f+1]=B+T,e[f+7]=B-T,f+=8;}for(f=0,h=0;h<8;++h){i=e[f],r=e[f+8],n=e[f+16],a=e[f+24],o=e[f+32],s=e[f+40],l=e[f+48];var R=i+(u=e[f+56]),z=i-u,F=r+l,N=r-l,O=n+s,D=n-s,$=a+o,L=a-o,U=R+$,Z=R-$,j=F+O,G=F-O;e[f]=U+j,e[f+32]=U-j;var H=.707106781*(G+Z);e[f+16]=Z+H,e[f+48]=Z-H;var Q=.382683433*((U=L+D)-(G=N+z)),W=.5411961*U+Q,q=1.306562965*G+Q,V=.707106781*(j=D+N),Y=z+V,K=z-V;e[f+40]=K+W,e[f+24]=K-W,e[f+8]=Y+q,e[f+56]=Y-q,f++;}for(h=0;h<64;++h)c=e[h]*t[h],d[h]=c>0?c+.5|0:c-.5|0;return d}(e,t),u=0;u<64;++u)p[E[u]]=l[u];var h=p[0]-i;i=p[0],0==h?R(r[0]):(R(r[f[a=32767+h]]),R(c[a]));for(var m=63;m>0&&0==p[m];m--);if(0==m)return R(o),i;for(var _,g=1;g<=m;){for(var b=g;0==p[g]&&g<=m;++g);var y=g-b;if(y>=16){_=y>>4;for(var w=1;w<=_;++w)R(s);y&=15;}a=32767+p[g],R(n[(y<<4)+f[a]]),R(c[a]),g++;}return 63!=m&&R(o),i}function O(e){if(e<=0&&(e=1),e>100&&(e=100),a!=e){((function(e){for(var t=[16,11,10,16,24,40,51,61,12,12,14,19,26,58,60,55,14,13,16,24,40,57,69,56,14,17,22,29,51,87,80,62,18,22,37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99],i=0;i<64;i++){var r=o((t[i]*e+50)/100);r<1?r=1:r>255&&(r=255),s[E[i]]=r;}for(var n=[17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],a=0;a<64;a++){var c=o((n[a]*e+50)/100);c<1?c=1:c>255&&(c=255),l[E[a]]=c;}for(var f=[1,1.387039845,1.306562965,1.175875602,1,.785694958,.5411961,.275899379],d=0,p=0;p<8;p++)for(var m=0;m<8;m++)u[d]=1/(s[E[d]]*f[p]*f[m]*8),h[d]=1/(l[E[d]]*f[p]*f[m]*8),d++;}))(e<50?Math.floor(5e3/e):Math.floor(200-2*e)),a=e;}}this.encode=function(e,a){var o;(new Date).getTime(),a&&O(a),m=new Array,_=0,g=7,F(65496),F(65504),F(16),z(74),z(70),z(73),z(70),z(0),z(1),z(1),z(0),F(1),F(1),z(0),z(0),void 0!==(o=e.comments)&&o.constructor===Array&&o.forEach((e=>{if("string"==typeof e){F(65534);var t,i=e.length;for(F(i+2),t=0;t<i;t++)z(e.charCodeAt(t));}})),function(e){if(e){F(65505),69===e[0]&&120===e[1]&&105===e[2]&&102===e[3]?F(e.length+2):(F(e.length+5+2),z(69),z(120),z(105),z(102),z(0));for(var t=0;t<e.length;t++)z(e[t]);}}(e.exifBuffer),function(){F(65499),F(132),z(0);for(var e=0;e<64;e++)z(s[e]);z(1);for(var t=0;t<64;t++)z(l[t]);}(),function(e,t){F(65472),F(17),z(8),F(t),F(e),z(3),z(1),z(17),z(0),z(2),z(17),z(1),z(3),z(17),z(1);}(e.width,e.height),function(){F(65476),F(418),z(0);for(var e=0;e<16;e++)z(k[e+1]);for(var t=0;t<=11;t++)z(S[t]);z(16);for(var i=0;i<16;i++)z(A[i+1]);for(var r=0;r<=161;r++)z(I[r]);z(1);for(var n=0;n<16;n++)z(M[n+1]);for(var a=0;a<=11;a++)z(T[a]);z(17);for(var o=0;o<16;o++)z(P[o+1]);for(var s=0;s<=161;s++)z(B[s]);}(),F(65498),F(12),z(3),z(1),z(0),z(2),z(17),z(3),z(17),z(0),z(63),z(0);var c=0,f=0,d=0;_=0,g=7,this.encode.displayName="_encode_";for(var p,v,E,C,D,$,L,U,Z,j=e.data,G=e.width,H=e.height,Q=4*G,W=0;W<H;){for(p=0;p<Q;){for($=D=Q*W+p,L=-1,U=0,Z=0;Z<64;Z++)$=D+(U=Z>>3)*Q+(L=4*(7&Z)),W+U>=H&&($-=Q*(W+1+U-H)),p+L>=Q&&($-=p+L-Q+4),v=j[$++],E=j[$++],C=j[$++],b[Z]=(x[v]+x[E+256|0]+x[C+512|0]>>16)-128,y[Z]=(x[v+768|0]+x[E+1024|0]+x[C+1280|0]>>16)-128,w[Z]=(x[v+1280|0]+x[E+1536|0]+x[C+1792|0]>>16)-128;c=N(b,u,c,t,r),f=N(y,h,f,i,n),d=N(w,h,d,i,n),p+=32;}W+=8;}if(g>=0){var q=[];q[1]=g+1,q[0]=(1<<g+1)-1,R(q);}return F(65497),Buffer$1.from(m)},(new Date).getTime(),e||(e=50),function(){for(var e=String.fromCharCode,t=0;t<256;t++)v[t]=e(t);}(),t=C(k,S),i=C(M,T),r=C(A,I),n=C(P,B),function(){for(var e=1,t=2,i=1;i<=15;i++){for(var r=e;r<t;r++)f[32767+r]=i,c[32767+r]=[],c[32767+r][1]=i,c[32767+r][0]=r;for(var n=-(t-1);n<=-e;n++)f[32767+n]=i,c[32767+n]=[],c[32767+n][1]=i,c[32767+n][0]=t-1+n;e<<=1,t<<=1;}}(),function(){for(var e=0;e<256;e++)x[e]=19595*e,x[e+256|0]=38470*e,x[e+512|0]=7471*e+32768,x[e+768|0]=-11059*e,x[e+1024|0]=-21709*e,x[e+1280|0]=32768*e+8421375,x[e+1536|0]=-27439*e,x[e+1792|0]=-5329*e;}(),O(e),(new Date).getTime();}encoder.exports=function(e,i){ void 0===i&&(i=50);var r=new t(i),n=r.encode(e,i);return {data:n,width:e.width,height:e.height}};}();var encoderExports=encoder.exports,decoder={exports:{}},module,JpegImage;module=decoder,JpegImage=function(){var e=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),t=4017,i=799,r=3406,n=2276,a=1567,o=3784,s=5793,l=2896;function u(){}function h(e,t){for(var i,r,n=0,a=[],o=16;o>0&&!e[o-1];)o--;a.push({children:[],index:0});var s,l=a[0];for(i=0;i<o;i++){for(r=0;r<e[i];r++){for((l=a.pop()).children[l.index]=t[n];l.index>0;){if(0===a.length)throw new Error("Could not recreate Huffman Table");l=a.pop();}for(l.index++,a.push(l);a.length<=i;)a.push(s={children:[],index:0}),l.children[l.index]=s.children,l=s;n++;}i+1<o&&(a.push(s={children:[],index:0}),l.children[l.index]=s.children,l=s);}return a[0].children}function c(t,i,r,n,a,o,s,l,u,h){r.precision,r.samplesPerLine,r.scanLines;var c=r.mcusPerLine,f=r.progressive;r.maxH,r.maxV;var d=i,p=0,m=0;function _(){if(m>0)return m--,p>>m&1;if(255==(p=t[i++])){var e=t[i++];if(e)throw new Error("unexpected marker: "+(p<<8|e).toString(16))}return m=7,p>>>7}function g(e){for(var t,i=e;null!==(t=_());){if("number"==typeof(i=i[t]))return i;if("object"!=typeof i)throw new Error("invalid huffman sequence")}return null}function b(e){for(var t=0;e>0;){var i=_();if(null===i)return;t=t<<1|i,e--;}return t}function y(e){var t=b(e);return t>=1<<e-1?t:t+(-1<<e)+1}var w,v=0,x=0;function E(e,t,i,r,n){var a=i%c,o=(i/c|0)*e.v+r,s=a*e.h+n;void 0===e.blocks[o]&&h.tolerantDecoding||t(e,e.blocks[o][s]);}function k(e,t,i){var r=i/e.blocksPerLine|0,n=i%e.blocksPerLine;void 0===e.blocks[r]&&h.tolerantDecoding||t(e,e.blocks[r][n]);}var S,A,I,M,T,P,B=n.length;P=f?0===o?0===l?function(e,t){var i=g(e.huffmanTableDC),r=0===i?0:y(i)<<u;t[0]=e.pred+=r;}:function(e,t){t[0]|=_()<<u;}:0===l?function(t,i){if(v>0)v--;else for(var r=o,n=s;r<=n;){var a=g(t.huffmanTableAC),l=15&a,h=a>>4;if(0!==l)i[e[r+=h]]=y(l)*(1<<u),r++;else {if(h<15){v=b(h)+(1<<h)-1;break}r+=16;}}}:function(t,i){for(var r=o,n=s,a=0;r<=n;){var l=e[r],h=i[l]<0?-1:1;switch(x){case 0:var c=g(t.huffmanTableAC),f=15&c;if(a=c>>4,0===f)a<15?(v=b(a)+(1<<a),x=4):(a=16,x=1);else {if(1!==f)throw new Error("invalid ACn encoding");w=y(f),x=a?2:3;}continue;case 1:case 2:i[l]?i[l]+=(_()<<u)*h:0==--a&&(x=2==x?3:0);break;case 3:i[l]?i[l]+=(_()<<u)*h:(i[l]=w<<u,x=0);break;case 4:i[l]&&(i[l]+=(_()<<u)*h);}r++;}4===x&&0==--v&&(x=0);}:function(t,i){var r=g(t.huffmanTableDC),n=0===r?0:y(r);i[0]=t.pred+=n;for(var a=1;a<64;){var o=g(t.huffmanTableAC),s=15&o,l=o>>4;if(0!==s)i[e[a+=l]]=y(s),a++;else {if(l<15)break;a+=16;}}};var C,R,z,F,N=0;for(R=1==B?n[0].blocksPerLine*n[0].blocksPerColumn:c*r.mcusPerColumn,a||(a=R);N<R;){for(A=0;A<B;A++)n[A].pred=0;if(v=0,1==B)for(S=n[0],T=0;T<a;T++)k(S,P,N),N++;else for(T=0;T<a;T++){for(A=0;A<B;A++)for(z=(S=n[A]).h,F=S.v,I=0;I<F;I++)for(M=0;M<z;M++)E(S,P,N,I,M);if(++N===R)break}if(N===R)do{if(255===t[i]&&0!==t[i+1])break;i+=1;}while(i<t.length-2);if(m=0,(C=t[i]<<8|t[i+1])<65280)throw new Error("marker was not found");if(!(C>=65488&&C<=65495))break;i+=2;}return i-d}function f(e,u){var h,c,f=[],d=u.blocksPerLine,p=u.blocksPerColumn,m=d<<3,g=new Int32Array(64),b=new Uint8Array(64);function y(e,h,c){var f,d,p,m,_,g,b,y,w,v,x=u.quantizationTable,E=c;for(v=0;v<64;v++)E[v]=e[v]*x[v];for(v=0;v<8;++v){var k=8*v;0!=E[1+k]||0!=E[2+k]||0!=E[3+k]||0!=E[4+k]||0!=E[5+k]||0!=E[6+k]||0!=E[7+k]?(f=s*E[0+k]+128>>8,d=s*E[4+k]+128>>8,p=E[2+k],m=E[6+k],_=l*(E[1+k]-E[7+k])+128>>8,y=l*(E[1+k]+E[7+k])+128>>8,g=E[3+k]<<4,b=E[5+k]<<4,w=f-d+1>>1,f=f+d+1>>1,d=w,w=p*o+m*a+128>>8,p=p*a-m*o+128>>8,m=w,w=_-b+1>>1,_=_+b+1>>1,b=w,w=y+g+1>>1,g=y-g+1>>1,y=w,w=f-m+1>>1,f=f+m+1>>1,m=w,w=d-p+1>>1,d=d+p+1>>1,p=w,w=_*n+y*r+2048>>12,_=_*r-y*n+2048>>12,y=w,w=g*i+b*t+2048>>12,g=g*t-b*i+2048>>12,b=w,E[0+k]=f+y,E[7+k]=f-y,E[1+k]=d+b,E[6+k]=d-b,E[2+k]=p+g,E[5+k]=p-g,E[3+k]=m+_,E[4+k]=m-_):(w=s*E[0+k]+512>>10,E[0+k]=w,E[1+k]=w,E[2+k]=w,E[3+k]=w,E[4+k]=w,E[5+k]=w,E[6+k]=w,E[7+k]=w);}for(v=0;v<8;++v){var S=v;0!=E[8+S]||0!=E[16+S]||0!=E[24+S]||0!=E[32+S]||0!=E[40+S]||0!=E[48+S]||0!=E[56+S]?(f=s*E[0+S]+2048>>12,d=s*E[32+S]+2048>>12,p=E[16+S],m=E[48+S],_=l*(E[8+S]-E[56+S])+2048>>12,y=l*(E[8+S]+E[56+S])+2048>>12,g=E[24+S],b=E[40+S],w=f-d+1>>1,f=f+d+1>>1,d=w,w=p*o+m*a+2048>>12,p=p*a-m*o+2048>>12,m=w,w=_-b+1>>1,_=_+b+1>>1,b=w,w=y+g+1>>1,g=y-g+1>>1,y=w,w=f-m+1>>1,f=f+m+1>>1,m=w,w=d-p+1>>1,d=d+p+1>>1,p=w,w=_*n+y*r+2048>>12,_=_*r-y*n+2048>>12,y=w,w=g*i+b*t+2048>>12,g=g*t-b*i+2048>>12,b=w,E[0+S]=f+y,E[56+S]=f-y,E[8+S]=d+b,E[48+S]=d-b,E[16+S]=p+g,E[40+S]=p-g,E[24+S]=m+_,E[32+S]=m-_):(w=s*c[v+0]+8192>>14,E[0+S]=w,E[8+S]=w,E[16+S]=w,E[24+S]=w,E[32+S]=w,E[40+S]=w,E[48+S]=w,E[56+S]=w);}for(v=0;v<64;++v){var A=128+(E[v]+8>>4);h[v]=A<0?0:A>255?255:A;}}_(m*p*8);for(var w=0;w<p;w++){var v=w<<3;for(h=0;h<8;h++)f.push(new Uint8Array(m));for(var x=0;x<d;x++){y(u.blocks[w][x],b,g);var E=0,k=x<<3;for(c=0;c<8;c++){var S=f[v+c];for(h=0;h<8;h++)S[k+h]=b[E++];}}}return f}function d(e){return e<0?0:e>255?255:e}u.prototype={load:function(e){var t=new XMLHttpRequest;t.open("GET",e,true),t.responseType="arraybuffer",t.onload=function(){var e=new Uint8Array(t.response||t.mozResponseArrayBuffer);this.parse(e),this.onload&&this.onload();}.bind(this),t.send(null);},parse:function(t){var i=1e3*this.opts.maxResolutionInMP*1e3,r=0;function n(){var e=t[r]<<8|t[r+1];return r+=2,e}function a(e){var t,i,r=1,n=1;for(i in e.components)e.components.hasOwnProperty(i)&&(r<(t=e.components[i]).h&&(r=t.h),n<t.v&&(n=t.v));var a=Math.ceil(e.samplesPerLine/8/r),o=Math.ceil(e.scanLines/8/n);for(i in e.components)if(e.components.hasOwnProperty(i)){t=e.components[i];var s=Math.ceil(Math.ceil(e.samplesPerLine/8)*t.h/r),l=Math.ceil(Math.ceil(e.scanLines/8)*t.v/n),u=a*t.h,h=o*t.v,c=[];_(h*u*256);for(var f=0;f<h;f++){for(var d=[],p=0;p<u;p++)d.push(new Int32Array(64));c.push(d);}t.blocksPerLine=s,t.blocksPerColumn=l,t.blocks=c;}e.maxH=r,e.maxV=n,e.mcusPerLine=a,e.mcusPerColumn=o;}t.length;var o,s,l,u,d=null,p=null,m=[],g=[],b=[],y=[],w=n(),v=-1;if(this.comments=[],65496!=w)throw new Error("SOI not found");for(w=n();65497!=w;){switch(w){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:var x=(l=void 0,u=void 0,l=n(),u=t.subarray(r,r+l-2),r+=u.length,u);if(65534===w){var E=String.fromCharCode.apply(null,x);this.comments.push(E);}65504===w&&74===x[0]&&70===x[1]&&73===x[2]&&70===x[3]&&0===x[4]&&(d={version:{major:x[5],minor:x[6]},densityUnits:x[7],xDensity:x[8]<<8|x[9],yDensity:x[10]<<8|x[11],thumbWidth:x[12],thumbHeight:x[13],thumbData:x.subarray(14,14+3*x[12]*x[13])}),65505===w&&69===x[0]&&120===x[1]&&105===x[2]&&102===x[3]&&0===x[4]&&(this.exifBuffer=x.subarray(5,x.length)),65518===w&&65===x[0]&&100===x[1]&&111===x[2]&&98===x[3]&&101===x[4]&&0===x[5]&&(p={version:x[6],flags0:x[7]<<8|x[8],flags1:x[9]<<8|x[10],transformCode:x[11]});break;case 65499:for(var k=n()+r-2;r<k;){var S=t[r++];_(256);var A=new Int32Array(64);if(S>>4){if(S>>4!=1)throw new Error("DQT: invalid table spec");for(q=0;q<64;q++)A[e[q]]=n();}else for(q=0;q<64;q++)A[e[q]]=t[r++];m[15&S]=A;}break;case 65472:case 65473:case 65474:n(),(o={}).extended=65473===w,o.progressive=65474===w,o.precision=t[r++],o.scanLines=n(),o.samplesPerLine=n(),o.components={},o.componentsOrder=[];var I=o.scanLines*o.samplesPerLine;if(I>i){var M=Math.ceil((I-i)/1e6);throw new Error(`maxResolutionInMP limit exceeded by ${M}MP`)}var T,P=t[r++];for(Q=0;Q<P;Q++){T=t[r];var B=t[r+1]>>4,C=15&t[r+1],R=t[r+2];if(B<=0||C<=0)throw new Error("Invalid sampling factor, expected values above 0");o.componentsOrder.push(T),o.components[T]={h:B,v:C,quantizationIdx:R},r+=3;}a(o),g.push(o);break;case 65476:var z=n();for(Q=2;Q<z;){var F=t[r++],N=new Uint8Array(16),O=0;for(q=0;q<16;q++,r++)O+=N[q]=t[r];_(16+O);var D=new Uint8Array(O);for(q=0;q<O;q++,r++)D[q]=t[r];Q+=17+O,(F>>4?b:y)[15&F]=h(N,D);}break;case 65501:n(),s=n();break;case 65500:n(),n();break;case 65498:n();var $=t[r++],L=[];for(Q=0;Q<$;Q++){V=o.components[t[r++]];var U=t[r++];V.huffmanTableDC=y[U>>4],V.huffmanTableAC=b[15&U],L.push(V);}var Z=t[r++],j=t[r++],G=t[r++],H=c(t,r,o,L,s,Z,j,G>>4,15&G,this.opts);r+=H;break;case 65535:255!==t[r]&&r--;break;default:if(255==t[r-3]&&t[r-2]>=192&&t[r-2]<=254){r-=3;break}if(224===w||225==w){if(-1!==v)throw new Error(`first unknown JPEG marker at offset ${v.toString(16)}, second unknown JPEG marker ${w.toString(16)} at offset ${(r-1).toString(16)}`);v=r-1;const e=n();if(255===t[r+e-2]){r+=e-2;break}}throw new Error("unknown JPEG marker "+w.toString(16))}w=n();}if(1!=g.length)throw new Error("only single frame JPEGs supported");for(var Q=0;Q<g.length;Q++){var W=g[Q].components;for(var q in W)W[q].quantizationTable=m[W[q].quantizationIdx],delete W[q].quantizationIdx;}for(this.width=o.samplesPerLine,this.height=o.scanLines,this.jfif=d,this.adobe=p,this.components=[],Q=0;Q<o.componentsOrder.length;Q++){var V=o.components[o.componentsOrder[Q]];this.components.push({lines:f(0,V),scaleX:V.h/o.maxH,scaleY:V.v/o.maxV});}},getData:function(e,t){var i,r,n,a,o,s,l,u,h,c,f,p,m,g,b,y,w,v,x,E,k,S=this.width/e,A=this.height/t,I=0,M=e*t*this.components.length;_(M);var T=new Uint8Array(M);switch(this.components.length){case 1:for(i=this.components[0],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],h=0;h<e;h++)f=o[0|h*i.scaleX*S],T[I++]=f;break;case 2:for(i=this.components[0],r=this.components[1],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],s=r.lines[0|c*r.scaleY*A],h=0;h<e;h++)f=o[0|h*i.scaleX*S],T[I++]=f,f=s[0|h*r.scaleX*S],T[I++]=f;break;case 3:for(k=true,this.adobe&&this.adobe.transformCode?k=true:void 0!==this.opts.colorTransform&&(k=!!this.opts.colorTransform),i=this.components[0],r=this.components[1],n=this.components[2],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],s=r.lines[0|c*r.scaleY*A],l=n.lines[0|c*n.scaleY*A],h=0;h<e;h++)k?(f=o[0|h*i.scaleX*S],p=s[0|h*r.scaleX*S],v=d(f+1.402*((m=l[0|h*n.scaleX*S])-128)),x=d(f-.3441363*(p-128)-.71413636*(m-128)),E=d(f+1.772*(p-128))):(v=o[0|h*i.scaleX*S],x=s[0|h*r.scaleX*S],E=l[0|h*n.scaleX*S]),T[I++]=v,T[I++]=x,T[I++]=E;break;case 4:if(!this.adobe)throw new Error("Unsupported color mode (4 components)");for(k=false,this.adobe&&this.adobe.transformCode?k=true:void 0!==this.opts.colorTransform&&(k=!!this.opts.colorTransform),i=this.components[0],r=this.components[1],n=this.components[2],a=this.components[3],c=0;c<t;c++)for(o=i.lines[0|c*i.scaleY*A],s=r.lines[0|c*r.scaleY*A],l=n.lines[0|c*n.scaleY*A],u=a.lines[0|c*a.scaleY*A],h=0;h<e;h++)k?(f=o[0|h*i.scaleX*S],p=s[0|h*r.scaleX*S],m=l[0|h*n.scaleX*S],g=u[0|h*a.scaleX*S],b=255-d(f+1.402*(m-128)),y=255-d(f-.3441363*(p-128)-.71413636*(m-128)),w=255-d(f+1.772*(p-128))):(b=o[0|h*i.scaleX*S],y=s[0|h*r.scaleX*S],w=l[0|h*n.scaleX*S],g=u[0|h*a.scaleX*S]),T[I++]=255-b,T[I++]=255-y,T[I++]=255-w,T[I++]=255-g;break;default:throw new Error("Unsupported color mode")}return T},copyToImageData:function(e,t){var i,r,n,a,o,s,l,u,h,c=e.width,f=e.height,p=e.data,m=this.getData(c,f),_=0,g=0;switch(this.components.length){case 1:for(r=0;r<f;r++)for(i=0;i<c;i++)n=m[_++],p[g++]=n,p[g++]=n,p[g++]=n,t&&(p[g++]=255);break;case 3:for(r=0;r<f;r++)for(i=0;i<c;i++)l=m[_++],u=m[_++],h=m[_++],p[g++]=l,p[g++]=u,p[g++]=h,t&&(p[g++]=255);break;case 4:for(r=0;r<f;r++)for(i=0;i<c;i++)o=m[_++],s=m[_++],n=m[_++],l=255-d(o*(1-(a=m[_++])/255)+a),u=255-d(s*(1-a/255)+a),h=255-d(n*(1-a/255)+a),p[g++]=l,p[g++]=u,p[g++]=h,t&&(p[g++]=255);break;default:throw new Error("Unsupported color mode")}}};var p=0,m=0;function _(e=0){var t=p+e;if(t>m){var i=Math.ceil((t-m)/1024/1024);throw new Error(`maxMemoryUsageInMB limit exceeded by at least ${i}MB`)}p=t;}return u.resetMaxMemoryUsage=function(e){p=0,m=e;},u.getBytesAllocated=function(){return p},u.requestMemoryAllocation=_,u}(),module.exports=function(e,t={}){var i={colorTransform:void 0,useTArray:false,formatAsRGBA:true,tolerantDecoding:true,maxResolutionInMP:100,maxMemoryUsageInMB:512,...t},r=new Uint8Array(e),n=new JpegImage;n.opts=i,JpegImage.resetMaxMemoryUsage(1024*i.maxMemoryUsageInMB*1024),n.parse(r);var a=i.formatAsRGBA?4:3,o=n.width*n.height*a;try{JpegImage.requestMemoryAllocation(o);var s={width:n.width,height:n.height,exifBuffer:n.exifBuffer,data:i.useTArray?new Uint8Array(o):Buffer$1.alloc(o)};n.comments.length>0&&(s.comments=n.comments);}catch(e){if(e instanceof RangeError)throw new Error("Could not allocate enough memory for the image. Required: "+o);if(e instanceof ReferenceError&&"Buffer is not defined"===e.message)throw new Error("Buffer is not globally defined in this environment. Consider setting useTArray to true");throw e}return n.copyToImageData(s,i.formatAsRGBA),s};var decoderExports=decoder.exports,encode=encoderExports,decode=decoderExports,jpegJs={encode:encode,decode:decode},JPEG=getDefaultExportFromCjs$1(jpegJs);function jpeg$2(){return {mime:"image/jpeg",encode:(e,{quality:t=100}={})=>JPEG.encode(e,t).data,decode:(e,t)=>JPEG.decode(e,t)}}function commonjsRequire(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var browser$1={exports:{}};browser$1.exports=function(){function e(t,i,r){function n(o,s){if(!i[o]){if(!t[o]){var l="function"==typeof commonjsRequire&&commonjsRequire;if(!s&&l)return l(o,true);if(a)return a(o,true);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=i[o]={exports:{}};t[o][0].call(h.exports,(function(e){return n(t[o][1][e]||e)}),h,h.exports,e,t,i,r);}return i[o].exports}for(var a="function"==typeof commonjsRequire&&commonjsRequire,o=0;o<r.length;o++)n(r[o]);return n}return e}()({1:[function(e,t,i){(function(t){(function(){let r=e("./interlace"),n=[function(){},function(e,t,i,r){if(r===t.length)throw new Error("Ran out of data");let n=t[r];e[i]=n,e[i+1]=n,e[i+2]=n,e[i+3]=255;},function(e,t,i,r){if(r+1>=t.length)throw new Error("Ran out of data");let n=t[r];e[i]=n,e[i+1]=n,e[i+2]=n,e[i+3]=t[r+1];},function(e,t,i,r){if(r+2>=t.length)throw new Error("Ran out of data");e[i]=t[r],e[i+1]=t[r+1],e[i+2]=t[r+2],e[i+3]=255;},function(e,t,i,r){if(r+3>=t.length)throw new Error("Ran out of data");e[i]=t[r],e[i+1]=t[r+1],e[i+2]=t[r+2],e[i+3]=t[r+3];}],a=[function(){},function(e,t,i,r){let n=t[0];e[i]=n,e[i+1]=n,e[i+2]=n,e[i+3]=r;},function(e,t,i){let r=t[0];e[i]=r,e[i+1]=r,e[i+2]=r,e[i+3]=t[1];},function(e,t,i,r){e[i]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=r;},function(e,t,i){e[i]=t[0],e[i+1]=t[1],e[i+2]=t[2],e[i+3]=t[3];}];function o(e,t){let i=[],r=0;function n(){if(r===e.length)throw new Error("Ran out of data");let n,a,o,s,l,u,h,c,f=e[r];switch(r++,t){default:throw new Error("unrecognised depth");case 16:h=e[r],r++,i.push((f<<8)+h);break;case 4:h=15&f,c=f>>4,i.push(c,h);break;case 2:l=3&f,u=f>>2&3,h=f>>4&3,c=f>>6&3,i.push(c,h,u,l);break;case 1:n=1&f,a=f>>1&1,o=f>>2&1,s=f>>3&1,l=f>>4&1,u=f>>5&1,h=f>>6&1,c=f>>7&1,i.push(c,h,u,l,s,o,a,n);}}return {get:function(e){for(;i.length<e;)n();let t=i.slice(0,e);return i=i.slice(e),t},resetAfterLine:function(){i.length=0;},end:function(){if(r!==e.length)throw new Error("extra data found")}}}function s(e,t,i,r,a,o){let s=e.width,l=e.height,u=e.index;for(let e=0;e<l;e++)for(let l=0;l<s;l++){let s=i(l,e,u);n[r](t,a,s,o),o+=r;}return o}function l(e,t,i,r,n,o){let s=e.width,l=e.height,u=e.index;for(let e=0;e<l;e++){for(let l=0;l<s;l++){let s=n.get(r),h=i(l,e,u);a[r](t,s,h,o);}n.resetAfterLine();}}i.dataToBitMap=function(e,i){let n,a,u=i.width,h=i.height,c=i.depth,f=i.bpp,d=i.interlace;8!==c&&(n=o(e,c)),a=c<=8?t.alloc(u*h*4):new Uint16Array(u*h*4);let p,m,_=Math.pow(2,c)-1,g=0;if(d)p=r.getImagePasses(u,h),m=r.getInterlaceIterator(u,h);else {let e=0;m=function(){let t=e;return e+=4,t},p=[{width:u,height:h}];}for(let t=0;t<p.length;t++)8===c?g=s(p[t],a,m,f,e,g):l(p[t],a,m,f,n,_);if(8===c){if(g!==e.length)throw new Error("extra data found")}else n.end();return a};}).call(this);}).call(this,e("buffer").Buffer);},{"./interlace":11,buffer:32}],2:[function(e,t,i){(function(i){(function(){let r=e("./constants");t.exports=function(e,t,n,a){let o=-1!==[r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(a.colorType);if(a.colorType===a.inputColorType){let t=function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,true),256!==new Int16Array(e)[0]}();if(8===a.bitDepth||16===a.bitDepth&&t)return e}let s=16!==a.bitDepth?e:new Uint16Array(e.buffer),l=255,u=r.COLORTYPE_TO_BPP_MAP[a.inputColorType];4!==u||a.inputHasAlpha||(u=3);let h=r.COLORTYPE_TO_BPP_MAP[a.colorType];16===a.bitDepth&&(l=65535,h*=2);let c=i.alloc(t*n*h),f=0,d=0,p=a.bgColor||{};function m(){let e,t,i,n=l;switch(a.inputColorType){case r.COLORTYPE_COLOR_ALPHA:n=s[f+3],e=s[f],t=s[f+1],i=s[f+2];break;case r.COLORTYPE_COLOR:e=s[f],t=s[f+1],i=s[f+2];break;case r.COLORTYPE_ALPHA:n=s[f+1],e=s[f],t=e,i=e;break;case r.COLORTYPE_GRAYSCALE:e=s[f],t=e,i=e;break;default:throw new Error("input color type:"+a.inputColorType+" is not supported at present")}return a.inputHasAlpha&&(o||(n/=l,e=Math.min(Math.max(Math.round((1-n)*p.red+n*e),0),l),t=Math.min(Math.max(Math.round((1-n)*p.green+n*t),0),l),i=Math.min(Math.max(Math.round((1-n)*p.blue+n*i),0),l))),{red:e,green:t,blue:i,alpha:n}} void 0===p.red&&(p.red=l),void 0===p.green&&(p.green=l),void 0===p.blue&&(p.blue=l);for(let e=0;e<n;e++)for(let e=0;e<t;e++){let e=m();switch(a.colorType){case r.COLORTYPE_COLOR_ALPHA:case r.COLORTYPE_COLOR:8===a.bitDepth?(c[d]=e.red,c[d+1]=e.green,c[d+2]=e.blue,o&&(c[d+3]=e.alpha)):(c.writeUInt16BE(e.red,d),c.writeUInt16BE(e.green,d+2),c.writeUInt16BE(e.blue,d+4),o&&c.writeUInt16BE(e.alpha,d+6));break;case r.COLORTYPE_ALPHA:case r.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;8===a.bitDepth?(c[d]=t,o&&(c[d+1]=e.alpha)):(c.writeUInt16BE(t,d),o&&c.writeUInt16BE(e.alpha,d+2));break}default:throw new Error("unrecognised color Type "+a.colorType)}f+=u,d+=h;}return c};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,buffer:32}],3:[function(e,t,i){(function(i,r){(function(){let n=e("util"),a=e("stream"),o=t.exports=function(){a.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=false,this._encoding="utf8",this.writable=true;};n.inherits(o,a),o.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),i.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=false,this.emit("drain"));}.bind(this));},o.prototype.write=function(e,t){if(!this.writable)return this.emit("error",new Error("Stream not writable")),false;let i;return i=r.isBuffer(e)?e:r.from(e,t||this._encoding),this._buffers.push(i),this._buffered+=i.length,this._process(),this._reads&&0===this._reads.length&&(this._paused=true),this.writable&&!this._paused},o.prototype.end=function(e,t){e&&this.write(e,t),this.writable=false,this._buffers&&(0===this._buffers.length?this._end():(this._buffers.push(null),this._process()));},o.prototype.destroySoon=o.prototype.end,o.prototype._end=function(){this._reads.length>0&&this.emit("error",new Error("Unexpected end of input")),this.destroy();},o.prototype.destroy=function(){this._buffers&&(this.writable=false,this._reads=null,this._buffers=null,this.emit("close"));},o.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t));},o.prototype._processRead=function(e){this._reads.shift();let t=0,i=0,n=r.alloc(e.length);for(;t<e.length;){let r=this._buffers[i++],a=Math.min(r.length,e.length-t);r.copy(n,t,0,a),t+=a,a!==r.length&&(this._buffers[--i]=r.slice(a));}i>0&&this._buffers.splice(0,i),this._buffered-=e.length,e.func.call(this,n);},o.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else {if(!(this._buffered>=e.length))break;this._processRead(e);}}this._buffers&&!this.writable&&this._end();}catch(e){this.emit("error",e);}};}).call(this);}).call(this,e("_process"),e("buffer").Buffer);},{_process:63,buffer:32,stream:65,util:84}],4:[function(e,t,i){t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5};},{}],5:[function(e,t,i){let r=[];!function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)1&t?t=3988292384^t>>>1:t>>>=1;r[e]=t;}}();let n=t.exports=function(){this._crc=-1;};n.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=r[255&(this._crc^e[t])]^this._crc>>>8;return true},n.prototype.crc32=function(){return ~this._crc},n.crc32=function(e){let t=-1;for(let i=0;i<e.length;i++)t=r[255&(t^e[i])]^t>>>8;return ~t};},{}],6:[function(e,t,i){(function(i){(function(){let r=e("./paeth-predictor");function n(e,t,i,r,n){for(let a=0;a<i;a++)r[n+a]=e[t+a];}function a(e,t,i){let r=0,n=t+i;for(let i=t;i<n;i++)r+=Math.abs(e[i]);return r}function o(e,t,i,r,n,a){for(let o=0;o<i;o++){let i=o>=a?e[t+o-a]:0,s=e[t+o]-i;r[n+o]=s;}}function s(e,t,i,r){let n=0;for(let a=0;a<i;a++){let i=a>=r?e[t+a-r]:0,o=e[t+a]-i;n+=Math.abs(o);}return n}function l(e,t,i,r,n){for(let a=0;a<i;a++){let o=t>0?e[t+a-i]:0,s=e[t+a]-o;r[n+a]=s;}}function u(e,t,i){let r=0,n=t+i;for(let a=t;a<n;a++){let n=t>0?e[a-i]:0,o=e[a]-n;r+=Math.abs(o);}return r}function h(e,t,i,r,n,a){for(let o=0;o<i;o++){let s=o>=a?e[t+o-a]:0,l=t>0?e[t+o-i]:0,u=e[t+o]-(s+l>>1);r[n+o]=u;}}function c(e,t,i,r){let n=0;for(let a=0;a<i;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-i]:0,l=e[t+a]-(o+s>>1);n+=Math.abs(l);}return n}function f(e,t,i,n,a,o){for(let s=0;s<i;s++){let l=s>=o?e[t+s-o]:0,u=t>0?e[t+s-i]:0,h=t>0&&s>=o?e[t+s-(i+o)]:0,c=e[t+s]-r(l,u,h);n[a+s]=c;}}function d(e,t,i,n){let a=0;for(let o=0;o<i;o++){let s=o>=n?e[t+o-n]:0,l=t>0?e[t+o-i]:0,u=t>0&&o>=n?e[t+o-(i+n)]:0,h=e[t+o]-r(s,l,u);a+=Math.abs(h);}return a}let p={0:n,1:o,2:l,3:h,4:f},m={0:a,1:s,2:u,3:c,4:d};t.exports=function(e,t,r,n,a){let o;if("filterType"in n&&-1!==n.filterType){if("number"!=typeof n.filterType)throw new Error("unrecognised filter types");o=[n.filterType];}else o=[0,1,2,3,4];16===n.bitDepth&&(a*=2);let s=t*a,l=0,u=0,h=i.alloc((s+1)*r),c=o[0];for(let t=0;t<r;t++){if(o.length>1){let t=1/0;for(let i=0;i<o.length;i++){let r=m[o[i]](e,u,s,a);r<t&&(c=o[i],t=r);}}h[l]=c,l++,p[c](e,u,s,h,l,a),l+=s,u+=s;}return h};}).call(this);}).call(this,e("buffer").Buffer);},{"./paeth-predictor":15,buffer:32}],7:[function(e,t,i){(function(i){(function(){let r=e("util"),n=e("./chunkstream"),a=e("./filter-parse"),o=t.exports=function(e){n.call(this);let t=[],r=this;this._filter=new a(e,{read:this.read.bind(this),write:function(e){t.push(e);},complete:function(){r.emit("complete",i.concat(t));}}),this._filter.start();};r.inherits(o,n);}).call(this);}).call(this,e("buffer").Buffer);},{"./chunkstream":3,"./filter-parse":9,buffer:32,util:84}],8:[function(e,t,i){(function(t){(function(){let r=e("./sync-reader"),n=e("./filter-parse");i.process=function(e,i){let a=[],o=new r(e);return new n(i,{read:o.read.bind(o),write:function(e){a.push(e);},complete:function(){}}).start(),o.process(),t.concat(a)};}).call(this);}).call(this,e("buffer").Buffer);},{"./filter-parse":9,"./sync-reader":22,buffer:32}],9:[function(e,t,i){(function(i){(function(){let r=e("./interlace"),n=e("./paeth-predictor");function a(e,t,i){let r=e*t;return 8!==i&&(r=Math.ceil(r/(8/i))),r}let o=t.exports=function(e,t){let i=e.width,n=e.height,o=e.interlace,s=e.bpp,l=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],o){let e=r.getImagePasses(i,n);for(let t=0;t<e.length;t++)this._images.push({byteWidth:a(e[t].width,s,l),height:e[t].height,lineIndex:0});}else this._images.push({byteWidth:a(i,s,l),height:n,lineIndex:0});this._xComparison=8===l?s:16===l?2*s:1;};o.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this));},o.prototype._unFilterType1=function(e,t,i){let r=this._xComparison,n=r-1;for(let a=0;a<i;a++){let i=e[1+a],o=a>n?t[a-r]:0;t[a]=i+o;}},o.prototype._unFilterType2=function(e,t,i){let r=this._lastLine;for(let n=0;n<i;n++){let i=e[1+n],a=r?r[n]:0;t[n]=i+a;}},o.prototype._unFilterType3=function(e,t,i){let r=this._xComparison,n=r-1,a=this._lastLine;for(let o=0;o<i;o++){let i=e[1+o],s=a?a[o]:0,l=o>n?t[o-r]:0,u=Math.floor((l+s)/2);t[o]=i+u;}},o.prototype._unFilterType4=function(e,t,i){let r=this._xComparison,a=r-1,o=this._lastLine;for(let s=0;s<i;s++){let i=e[1+s],l=o?o[s]:0,u=s>a?t[s-r]:0,h=s>a&&o?o[s-r]:0,c=n(u,l,h);t[s]=i+c;}},o.prototype._reverseFilterLine=function(e){let t,r=e[0],n=this._images[this._imageIndex],a=n.byteWidth;if(0===r)t=e.slice(1,a+1);else switch(t=i.alloc(a),r){case 1:this._unFilterType1(e,t,a);break;case 2:this._unFilterType2(e,t,a);break;case 3:this._unFilterType3(e,t,a);break;case 4:this._unFilterType4(e,t,a);break;default:throw new Error("Unrecognised filter type - "+r)}this.write(t),n.lineIndex++,n.lineIndex>=n.height?(this._lastLine=null,this._imageIndex++,n=this._images[this._imageIndex]):this._lastLine=t,n?this.read(n.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete());};}).call(this);}).call(this,e("buffer").Buffer);},{"./interlace":11,"./paeth-predictor":15,buffer:32}],10:[function(e,t,i){(function(e){(function(){function i(e,t,i,r,n){let a=0;for(let o=0;o<r;o++)for(let r=0;r<i;r++){let i=n[e[a]];if(!i)throw new Error("index "+e[a]+" not in palette");for(let e=0;e<4;e++)t[a+e]=i[e];a+=4;}}function r(e,t,i,r,n){let a=0;for(let o=0;o<r;o++)for(let r=0;r<i;r++){let i=false;if(1===n.length?n[0]===e[a]&&(i=true):n[0]===e[a]&&n[1]===e[a+1]&&n[2]===e[a+2]&&(i=true),i)for(let e=0;e<4;e++)t[a+e]=0;a+=4;}}function n(e,t,i,r,n){let a=255,o=Math.pow(2,n)-1,s=0;for(let n=0;n<r;n++)for(let r=0;r<i;r++){for(let i=0;i<4;i++)t[s+i]=Math.floor(e[s+i]*a/o+.5);s+=4;}}t.exports=function(t,a,o=false){let s=a.depth,l=a.width,u=a.height,h=a.colorType,c=a.transColor,f=a.palette,d=t;return 3===h?i(t,d,l,u,f):(c&&r(t,d,l,u,c),8===s||o||(16===s&&(d=e.alloc(l*u*4)),n(t,d,l,u,s))),d};}).call(this);}).call(this,e("buffer").Buffer);},{buffer:32}],11:[function(e,t,i){let r=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];i.getImagePasses=function(e,t){let i=[],n=e%8,a=t%8,o=(e-n)/8,s=(t-a)/8;for(let e=0;e<r.length;e++){let t=r[e],l=o*t.x.length,u=s*t.y.length;for(let e=0;e<t.x.length&&t.x[e]<n;e++)l++;for(let e=0;e<t.y.length&&t.y[e]<a;e++)u++;l>0&&u>0&&i.push({width:l,height:u,index:e});}return i},i.getInterlaceIterator=function(e){return function(t,i,n){let a=t%r[n].x.length,o=(t-a)/r[n].x.length*8+r[n].x[a],s=i%r[n].y.length;return 4*o+((i-s)/r[n].y.length*8+r[n].y[s])*e*4}};},{}],12:[function(e,t,i){(function(i){(function(){let r=e("util"),n=e("stream"),a=e("./constants"),o=e("./packer"),s=t.exports=function(e){n.call(this);let t=e||{};this._packer=new o(t),this._deflate=this._packer.createDeflate(),this.readable=true;};r.inherits(s,n),s.prototype.pack=function(e,t,r,n){this.emit("data",i.from(a.PNG_SIGNATURE)),this.emit("data",this._packer.packIHDR(t,r)),n&&this.emit("data",this._packer.packGAMA(n));let o=this._packer.filterData(e,t,r);this._deflate.on("error",this.emit.bind(this,"error")),this._deflate.on("data",function(e){this.emit("data",this._packer.packIDAT(e));}.bind(this)),this._deflate.on("end",function(){this.emit("data",this._packer.packIEND()),this.emit("end");}.bind(this)),this._deflate.end(o);};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,"./packer":14,buffer:32,stream:65,util:84}],13:[function(e,t,i){(function(i){(function(){let r=true,n=e("zlib");n.deflateSync||(r=false);let a=e("./constants"),o=e("./packer");t.exports=function(e,t){if(!r)throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let s=new o(t||{}),l=[];l.push(i.from(a.PNG_SIGNATURE)),l.push(s.packIHDR(e.width,e.height)),e.gamma&&l.push(s.packGAMA(e.gamma));let u=s.filterData(e.data,e.width,e.height),h=n.deflateSync(u,s.getDeflateOptions());if(u=null,!h||!h.length)throw new Error("bad png - invalid compressed data response");return l.push(s.packIDAT(h)),l.push(s.packIEND()),i.concat(l)};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,"./packer":14,buffer:32,zlib:31}],14:[function(e,t,i){(function(i){(function(){let r=e("./constants"),n=e("./crc"),a=e("./bitpacker"),o=e("./filter-pack"),s=e("zlib"),l=t.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=null!=e.deflateLevel?e.deflateLevel:9,e.deflateStrategy=null!=e.deflateStrategy?e.deflateStrategy:3,e.inputHasAlpha=null==e.inputHasAlpha||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||s.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType="number"==typeof e.colorType?e.colorType:r.COLORTYPE_COLOR_ALPHA,e.inputColorType="number"==typeof e.inputColorType?e.inputColorType:r.COLORTYPE_COLOR_ALPHA,-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.colorType))throw new Error("option color type:"+e.colorType+" is not supported at present");if(-1===[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.inputColorType))throw new Error("option input color type:"+e.inputColorType+" is not supported at present");if(8!==e.bitDepth&&16!==e.bitDepth)throw new Error("option bit depth:"+e.bitDepth+" is not supported at present")};l.prototype.getDeflateOptions=function(){return {chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},l.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},l.prototype.filterData=function(e,t,i){let n=a(e,t,i,this._options),s=r.COLORTYPE_TO_BPP_MAP[this._options.colorType];return o(n,t,i,this._options,s)},l.prototype._packChunk=function(e,t){let r=t?t.length:0,a=i.alloc(r+12);return a.writeUInt32BE(r,0),a.writeUInt32BE(e,4),t&&t.copy(a,8),a.writeInt32BE(n.crc32(a.slice(4,a.length-4)),a.length-4),a},l.prototype.packGAMA=function(e){let t=i.alloc(4);return t.writeUInt32BE(Math.floor(e*r.GAMMA_DIVISION),0),this._packChunk(r.TYPE_gAMA,t)},l.prototype.packIHDR=function(e,t){let n=i.alloc(13);return n.writeUInt32BE(e,0),n.writeUInt32BE(t,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(r.TYPE_IHDR,n)},l.prototype.packIDAT=function(e){return this._packChunk(r.TYPE_IDAT,e)},l.prototype.packIEND=function(){return this._packChunk(r.TYPE_IEND,null)};}).call(this);}).call(this,e("buffer").Buffer);},{"./bitpacker":2,"./constants":4,"./crc":5,"./filter-pack":6,buffer:32,zlib:31}],15:[function(e,t,i){t.exports=function(e,t,i){let r=e+t-i,n=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-i);return n<=a&&n<=o?e:a<=o?t:i};},{}],16:[function(e,t,i){let r=e("util"),n=e("zlib"),a=e("./chunkstream"),o=e("./filter-parse-async"),s=e("./parser"),l=e("./bitmapper"),u=e("./format-normaliser"),h=t.exports=function(e){a.call(this),this._parser=new s(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,"gamma"),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=true,this._parser.start();};r.inherits(h,a),h.prototype._handleError=function(e){this.emit("error",e),this.writable=false,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on("error",(function(){}))),this.errord=true;},h.prototype._inflateData=function(e){if(!this._inflate)if(this._bitmapInfo.interlace)this._inflate=n.createInflate(),this._inflate.on("error",this.emit.bind(this,"error")),this._filter.on("complete",this._complete.bind(this)),this._inflate.pipe(this._filter);else {let e=(1+(this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3))*this._bitmapInfo.height,t=Math.max(e,n.Z_MIN_CHUNK);this._inflate=n.createInflate({chunkSize:t});let i=e,r=this.emit.bind(this,"error");this._inflate.on("error",(function(e){i&&r(e);})),this._filter.on("complete",this._complete.bind(this));let a=this._filter.write.bind(this._filter);this._inflate.on("data",(function(e){i&&(e.length>i&&(e=e.slice(0,i)),i-=e.length,a(e));})),this._inflate.on("end",this._filter.end.bind(this._filter));}this._inflate.write(e);},h.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new o(this._bitmapInfo);},h.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e;},h.prototype._handlePalette=function(e){this._bitmapInfo.palette=e;},h.prototype._simpleTransparency=function(){this._metaData.alpha=true;},h.prototype._headersFinished=function(){this.emit("metadata",this._metaData);},h.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit("error","No Inflate block"));},h.prototype._complete=function(e){if(this.errord)return;let t;try{let i=l.dataToBitMap(e,this._bitmapInfo);t=u(i,this._bitmapInfo,this._options.skipRescale),i=null;}catch(e){return void this._handleError(e)}this.emit("parsed",t);};},{"./bitmapper":1,"./chunkstream":3,"./filter-parse-async":7,"./format-normaliser":10,"./parser":18,util:84,zlib:31}],17:[function(e,t,i){(function(i){(function(){let r=true,n=e("zlib"),a=e("./sync-inflate");n.deflateSync||(r=false);let o=e("./sync-reader"),s=e("./filter-parse-sync"),l=e("./parser"),u=e("./bitmapper"),h=e("./format-normaliser");t.exports=function(e,t){if(!r)throw new Error("To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0");let c,f,d;function p(e){c=e;}function m(e){f=e;}function _(e){f.transColor=e;}function g(e){f.palette=e;}function b(){f.alpha=true;}function y(e){d=e;}let w=[];function v(e){w.push(e);}let x=new o(e);if(new l(t,{read:x.read.bind(x),error:p,metadata:m,gamma:y,palette:g,transColor:_,inflateData:v,simpleTransparency:b}).start(),x.process(),c)throw c;let E,k=i.concat(w);if(w.length=0,f.interlace)E=n.inflateSync(k);else {let e=(1+(f.width*f.bpp*f.depth+7>>3))*f.height;E=a(k,{chunkSize:e,maxLength:e});}if(k=null,!E||!E.length)throw new Error("bad png - invalid inflate data response");let S=s.process(E,f);k=null;let A=u.dataToBitMap(S,f);S=null;let I=h(A,f,t.skipRescale);return f.data=I,f.gamma=d||0,f};}).call(this);}).call(this,e("buffer").Buffer);},{"./bitmapper":1,"./filter-parse-sync":8,"./format-normaliser":10,"./parser":18,"./sync-inflate":21,"./sync-reader":22,buffer:32,zlib:31}],18:[function(e,t,i){(function(i){(function(){let r=e("./constants"),n=e("./crc"),a=t.exports=function(e,t){this._options=e,e.checkCRC=false!==e.checkCRC,this._hasIHDR=false,this._hasIEND=false,this._emittedHeadersFinished=false,this._palette=[],this._colorType=0,this._chunks={},this._chunks[r.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[r.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[r.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[r.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[r.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[r.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){};};a.prototype.start=function(){this.read(r.PNG_SIGNATURE.length,this._parseSignature.bind(this));},a.prototype._parseSignature=function(e){let t=r.PNG_SIGNATURE;for(let i=0;i<t.length;i++)if(e[i]!==t[i])return void this.error(new Error("Invalid file signature"));this.read(8,this._parseChunkBegin.bind(this));},a.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),a=e.readUInt32BE(4),o="";for(let t=4;t<8;t++)o+=String.fromCharCode(e[t]);let s=Boolean(32&e[4]);if(this._hasIHDR||a===r.TYPE_IHDR){if(this._crc=new n,this._crc.write(i.from(o)),this._chunks[a])return this._chunks[a](t);s?this.read(t+4,this._skipChunk.bind(this)):this.error(new Error("Unsupported critical chunk type "+o));}else this.error(new Error("Expected IHDR on beggining"));},a.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this));},a.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this));},a.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),i=this._crc.crc32();this._options.checkCRC&&i!==t?this.error(new Error("Crc error - "+t+" - "+i)):this._hasIEND||this.read(8,this._parseChunkBegin.bind(this));},a.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this));},a.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),i=e.readUInt32BE(4),n=e[8],a=e[9],o=e[10],s=e[11],l=e[12];if(8!==n&&4!==n&&2!==n&&1!==n&&16!==n)return void this.error(new Error("Unsupported bit depth "+n));if(!(a in r.COLORTYPE_TO_BPP_MAP))return void this.error(new Error("Unsupported color type"));if(0!==o)return void this.error(new Error("Unsupported compression method"));if(0!==s)return void this.error(new Error("Unsupported filter method"));if(0!==l&&1!==l)return void this.error(new Error("Unsupported interlace method"));this._colorType=a;let u=r.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=true,this.metadata({width:t,height:i,depth:n,interlace:Boolean(l),palette:Boolean(a&r.COLORTYPE_PALETTE),color:Boolean(a&r.COLORTYPE_COLOR),alpha:Boolean(a&r.COLORTYPE_ALPHA),bpp:u,colorType:a}),this._handleChunkEnd();},a.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this));},a.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let i=0;i<t;i++)this._palette.push([e[3*i],e[3*i+1],e[3*i+2],255]);this.palette(this._palette),this._handleChunkEnd();},a.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this));},a.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===r.COLORTYPE_PALETTE_COLOR){if(0===this._palette.length)return void this.error(new Error("Transparency chunk must be after palette"));if(e.length>this._palette.length)return void this.error(new Error("More transparent colors than palette size"));for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette);}this._colorType===r.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===r.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd();},a.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this));},a.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/r.GAMMA_DIVISION),this._handleChunkEnd();},a.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=true,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e));},a.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===r.COLORTYPE_PALETTE_COLOR&&0===this._palette.length)throw new Error("Expected palette not found");this.inflateData(t);let i=e-t.length;i>0?this._handleIDAT(i):this._handleChunkEnd();},a.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this));},a.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=true,this._handleChunkEnd(),this.finished&&this.finished();};}).call(this);}).call(this,e("buffer").Buffer);},{"./constants":4,"./crc":5,buffer:32}],19:[function(e,t,i){let r=e("./parser-sync"),n=e("./packer-sync");i.read=function(e,t){return r(e,t||{})},i.write=function(e,t){return n(e,t)};},{"./packer-sync":13,"./parser-sync":17}],20:[function(e,t,i){(function(t,r){(function(){let n=e("util"),a=e("stream"),o=e("./parser-async"),s=e("./packer-async"),l=e("./png-sync"),u=i.PNG=function(e){a.call(this),e=e||{},this.width=0|e.width,this.height=0|e.height,this.data=this.width>0&&this.height>0?r.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=true,this._parser=new o(e),this._parser.on("error",this.emit.bind(this,"error")),this._parser.on("close",this._handleClose.bind(this)),this._parser.on("metadata",this._metadata.bind(this)),this._parser.on("gamma",this._gamma.bind(this)),this._parser.on("parsed",function(e){this.data=e,this.emit("parsed",e);}.bind(this)),this._packer=new s(e),this._packer.on("data",this.emit.bind(this,"data")),this._packer.on("end",this.emit.bind(this,"end")),this._parser.on("close",this._handleClose.bind(this)),this._packer.on("error",this.emit.bind(this,"error"));};n.inherits(u,a),u.sync=l,u.prototype.pack=function(){return this.data&&this.data.length?(t.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma);}.bind(this)),this):(this.emit("error","No data provided"),this)},u.prototype.parse=function(e,t){if(t){let e,i;e=function(e){this.removeListener("error",i),this.data=e,t(null,this);}.bind(this),i=function(i){this.removeListener("parsed",e),t(i,null);}.bind(this),this.once("parsed",e),this.once("error",i);}return this.end(e),this},u.prototype.write=function(e){return this._parser.write(e),true},u.prototype.end=function(e){this._parser.end(e);},u.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit("metadata",e);},u.prototype._gamma=function(e){this.gamma=e;},u.prototype._handleClose=function(){this._parser.writable||this._packer.readable||this.emit("close");},u.bitblt=function(e,t,i,r,n,a,o,s){if(r|=0,n|=0,a|=0,o|=0,s|=0,(i|=0)>e.width||r>e.height||i+n>e.width||r+a>e.height)throw new Error("bitblt reading outside image");if(o>t.width||s>t.height||o+n>t.width||s+a>t.height)throw new Error("bitblt writing outside image");for(let l=0;l<a;l++)e.data.copy(t.data,(s+l)*t.width+o<<2,(r+l)*e.width+i<<2,(r+l)*e.width+i+n<<2);},u.prototype.bitblt=function(e,t,i,r,n,a,o){return u.bitblt(this,e,t,i,r,n,a,o),this},u.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let i=0;i<e.width;i++){let r=e.width*t+i<<2;for(let t=0;t<3;t++){let i=e.data[r+t]/255;i=Math.pow(i,1/2.2/e.gamma),e.data[r+t]=Math.round(255*i);}}e.gamma=0;}},u.prototype.adjustGamma=function(){u.adjustGamma(this);};}).call(this);}).call(this,e("_process"),e("buffer").Buffer);},{"./packer-async":12,"./parser-async":16,"./png-sync":19,_process:63,buffer:32,stream:65,util:84}],21:[function(e,t,i){(function(r,n){(function(){let r=e("assert").ok,a=e("zlib"),o=e("util"),s=e("buffer").kMaxLength;function l(e){if(!(this instanceof l))return new l(e);e&&e.chunkSize<a.Z_MIN_CHUNK&&(e.chunkSize=a.Z_MIN_CHUNK),a.Inflate.call(this,e),this._offset=void 0===this._offset?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&null!=e.maxLength&&(this._maxLength=e.maxLength);}function u(e){return new l(e)}function h(e,t){e._handle&&(e._handle.close(),e._handle=null);}function c(e,t){if("string"==typeof t&&(t=n.from(t)),!(t instanceof n))throw new TypeError("Not a string or buffer");let i=e._finishFlushFlag;return null==i&&(i=a.Z_FINISH),e._processChunk(t,i)}function f(e,t){return c(new l(t),e)}l.prototype._processChunk=function(e,t,i){if("function"==typeof i)return a.Inflate._processChunk.call(this,e,t,i);let o,l,u=this,c=e&&e.length,f=this._chunkSize-this._offset,d=this._maxLength,p=0,m=[],_=0;function g(e,t){if(u._hadError)return;let i=f-t;if(r(i>=0,"have should not go down"),i>0){let e=u._buffer.slice(u._offset,u._offset+i);if(u._offset+=i,e.length>d&&(e=e.slice(0,d)),m.push(e),_+=e.length,d-=e.length,0===d)return false}return (0===t||u._offset>=u._chunkSize)&&(f=u._chunkSize,u._offset=0,u._buffer=n.allocUnsafe(u._chunkSize)),0===t&&(p+=c-e,c=e,true)}this.on("error",(function(e){o=e;})),r(this._handle,"zlib binding closed");do{l=this._handle.writeSync(t,e,p,c,this._buffer,this._offset,f),l=l||this._writeState;}while(!this._hadError&&g(l[0],l[1]));if(this._hadError)throw o;if(_>=s)throw h(this),new RangeError("Cannot create final Buffer. It would be larger than 0x"+s.toString(16)+" bytes");let b=n.concat(m,_);return h(this),b},o.inherits(l,a.Inflate),t.exports=i=f,i.Inflate=l,i.createInflate=u,i.inflateSync=f;}).call(this);}).call(this,e("_process"),e("buffer").Buffer);},{_process:63,assert:23,buffer:32,util:84,zlib:31}],22:[function(e,t,i){let r=t.exports=function(e){this._buffer=e,this._reads=[];};r.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t});},r.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(!this._buffer.length||!(this._buffer.length>=e.length||e.allowLess))break;{this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length));}}if(this._reads.length>0)throw new Error("There are some read requests waitng on finished stream");if(this._buffer.length>0)throw new Error("unrecognised content at end of stream")};},{}],23:[function(e,t,i){(function(i){(function(){var r=e("object-assign");
|
|
2
1005
|
/*!
|
|
3
1006
|
* The buffer module from node.js, for the browser.
|
|
@@ -3233,6 +4236,82 @@ function requireBrowser () {
|
|
|
3233
4236
|
var browserExports = requireBrowser();
|
|
3234
4237
|
var Worker$1 = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
3235
4238
|
|
|
4239
|
+
/*
|
|
4240
|
+
* Copyright (C) 2025 Koutaro Mukai
|
|
4241
|
+
*
|
|
4242
|
+
* This program is free software: you can redistribute it and/or modify
|
|
4243
|
+
* it under the terms of the GNU General Public License as published by
|
|
4244
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
4245
|
+
* (at your option) any later version.
|
|
4246
|
+
*
|
|
4247
|
+
* This program is distributed in the hope that it will be useful,
|
|
4248
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
4249
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
4250
|
+
* GNU General Public License for more details.
|
|
4251
|
+
*
|
|
4252
|
+
* You should have received a copy of the GNU General Public License
|
|
4253
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
4254
|
+
*/
|
|
4255
|
+
const _enabled = (() => {
|
|
4256
|
+
try {
|
|
4257
|
+
if (typeof process !== "undefined" &&
|
|
4258
|
+
process.env &&
|
|
4259
|
+
process.env.PDFDIFF_PROFILE === "1") {
|
|
4260
|
+
return true;
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
catch {
|
|
4264
|
+
// process not available (e.g. in some browser worker environments)
|
|
4265
|
+
}
|
|
4266
|
+
const g = globalThis;
|
|
4267
|
+
return g.__PDFDIFF_PROFILE__ === true;
|
|
4268
|
+
})();
|
|
4269
|
+
const _counters = Object.create(null);
|
|
4270
|
+
const _NOOP_SPAN = Object.freeze({ stop() { } });
|
|
4271
|
+
const _noop = () => { };
|
|
4272
|
+
const _emptyDump = () => Object.freeze({});
|
|
4273
|
+
const _realPerf = {
|
|
4274
|
+
enabled: true,
|
|
4275
|
+
span(key) {
|
|
4276
|
+
const t0 = performance.now();
|
|
4277
|
+
return {
|
|
4278
|
+
stop() {
|
|
4279
|
+
_counters[key] = (_counters[key] ?? 0) + (performance.now() - t0);
|
|
4280
|
+
},
|
|
4281
|
+
};
|
|
4282
|
+
},
|
|
4283
|
+
incr(key, delta = 1) {
|
|
4284
|
+
_counters[key] = (_counters[key] ?? 0) + delta;
|
|
4285
|
+
},
|
|
4286
|
+
setMax(key, value) {
|
|
4287
|
+
const cur = _counters[key];
|
|
4288
|
+
if (cur === undefined || value > cur)
|
|
4289
|
+
_counters[key] = value;
|
|
4290
|
+
},
|
|
4291
|
+
merge(other) {
|
|
4292
|
+
for (const k of Object.keys(other)) {
|
|
4293
|
+
_counters[k] = (_counters[k] ?? 0) + other[k];
|
|
4294
|
+
}
|
|
4295
|
+
},
|
|
4296
|
+
dump() {
|
|
4297
|
+
return { ..._counters };
|
|
4298
|
+
},
|
|
4299
|
+
reset() {
|
|
4300
|
+
for (const k of Object.keys(_counters))
|
|
4301
|
+
delete _counters[k];
|
|
4302
|
+
},
|
|
4303
|
+
};
|
|
4304
|
+
const _noopPerf = {
|
|
4305
|
+
enabled: false,
|
|
4306
|
+
span: () => _NOOP_SPAN,
|
|
4307
|
+
incr: _noop,
|
|
4308
|
+
setMax: _noop,
|
|
4309
|
+
merge: _noop,
|
|
4310
|
+
dump: _emptyDump,
|
|
4311
|
+
reset: _noop,
|
|
4312
|
+
};
|
|
4313
|
+
const perf = _enabled ? _realPerf : _noopPerf;
|
|
4314
|
+
|
|
3236
4315
|
/*
|
|
3237
4316
|
* Copyright (C) 2025 Koutaro Mukai
|
|
3238
4317
|
*
|
|
@@ -3339,6 +4418,8 @@ async function* withIndex(iter, start = 0) {
|
|
|
3339
4418
|
}
|
|
3340
4419
|
}
|
|
3341
4420
|
|
|
4421
|
+
const VERSION = "0.2.2";
|
|
4422
|
+
|
|
3342
4423
|
/*
|
|
3343
4424
|
* Copyright (C) 2025 Koutaro Mukai
|
|
3344
4425
|
*
|
|
@@ -3382,24 +4463,42 @@ function asSharedBytes(bytes) {
|
|
|
3382
4463
|
}
|
|
3383
4464
|
class WorkerHandle {
|
|
3384
4465
|
worker;
|
|
4466
|
+
loaded;
|
|
3385
4467
|
pendingResolve = null;
|
|
3386
4468
|
pendingReject = null;
|
|
3387
4469
|
constructor(url) {
|
|
3388
4470
|
this.worker = new Worker$1(url, { type: "module" });
|
|
3389
|
-
this.
|
|
3390
|
-
const
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
4471
|
+
this.loaded = new Promise((resolveLoaded, rejectLoaded) => {
|
|
4472
|
+
const onMessage = (e) => {
|
|
4473
|
+
const data = e.data;
|
|
4474
|
+
if (data.type === "loaded") {
|
|
4475
|
+
resolveLoaded();
|
|
4476
|
+
return;
|
|
4477
|
+
}
|
|
4478
|
+
const resolve = this.pendingResolve;
|
|
4479
|
+
const reject = this.pendingReject;
|
|
4480
|
+
this.pendingResolve = null;
|
|
4481
|
+
this.pendingReject = null;
|
|
4482
|
+
if (data.type === "error") {
|
|
4483
|
+
reject?.(new Error(`worker: ${data.message}`));
|
|
4484
|
+
}
|
|
4485
|
+
else {
|
|
4486
|
+
resolve?.(data);
|
|
4487
|
+
}
|
|
4488
|
+
};
|
|
4489
|
+
this.worker.addEventListener("message", onMessage);
|
|
4490
|
+
this.worker.addEventListener("error", (e) => {
|
|
4491
|
+
const err = e.error ?? new Error(e.message);
|
|
4492
|
+
rejectLoaded(err);
|
|
4493
|
+
const reject = this.pendingReject;
|
|
4494
|
+
this.pendingResolve = null;
|
|
4495
|
+
this.pendingReject = null;
|
|
4496
|
+
reject?.(err);
|
|
4497
|
+
});
|
|
3400
4498
|
});
|
|
3401
4499
|
}
|
|
3402
|
-
init(msg) {
|
|
4500
|
+
async init(msg) {
|
|
4501
|
+
await this.loaded;
|
|
3403
4502
|
return new Promise((resolve, reject) => {
|
|
3404
4503
|
this.pendingResolve = resolve;
|
|
3405
4504
|
this.pendingReject = reject;
|
|
@@ -3419,10 +4518,12 @@ class WorkerHandle {
|
|
|
3419
4518
|
}
|
|
3420
4519
|
}
|
|
3421
4520
|
function workerUrl() {
|
|
3422
|
-
|
|
4521
|
+
const file = import.meta.url.endsWith(".ts") ? "./worker.ts" : "./worker.js";
|
|
4522
|
+
return new URL(`${file}?v=${encodeURIComponent(VERSION)}`, import.meta.url);
|
|
3423
4523
|
}
|
|
3424
4524
|
function pageResultToResult(msg) {
|
|
3425
|
-
|
|
4525
|
+
const sP = perf.span("main.pageResultToResult_ms");
|
|
4526
|
+
const r = {
|
|
3426
4527
|
a: Jimp.fromBitmap({
|
|
3427
4528
|
width: msg.a.width,
|
|
3428
4529
|
height: msg.a.height,
|
|
@@ -3442,6 +4543,11 @@ function pageResultToResult(msg) {
|
|
|
3442
4543
|
deletion: msg.deletion,
|
|
3443
4544
|
modification: msg.modification,
|
|
3444
4545
|
};
|
|
4546
|
+
sP.stop();
|
|
4547
|
+
perf.incr("main.resultsReceived");
|
|
4548
|
+
if (msg.perf)
|
|
4549
|
+
perf.merge(msg.perf);
|
|
4550
|
+
return r;
|
|
3445
4551
|
}
|
|
3446
4552
|
async function* visualizeDifferences(a, b, options) {
|
|
3447
4553
|
const merged = {
|
|
@@ -3507,6 +4613,7 @@ async function* visualizeDifferences(a, b, options) {
|
|
|
3507
4613
|
}
|
|
3508
4614
|
else {
|
|
3509
4615
|
buffered.set(idx, result);
|
|
4616
|
+
perf.setMax("main.bufferedPeak", buffered.size);
|
|
3510
4617
|
}
|
|
3511
4618
|
}
|
|
3512
4619
|
catch (e) {
|
|
@@ -3529,11 +4636,15 @@ async function* visualizeDifferences(a, b, options) {
|
|
|
3529
4636
|
r = buf;
|
|
3530
4637
|
}
|
|
3531
4638
|
else {
|
|
4639
|
+
const sWait = perf.span("main.yieldWaitMain_ms");
|
|
3532
4640
|
r = await new Promise((resolve) => resolvers.set(i, resolve));
|
|
4641
|
+
sWait.stop();
|
|
3533
4642
|
if (workerError !== null)
|
|
3534
4643
|
throw workerError;
|
|
3535
4644
|
}
|
|
4645
|
+
const sYield = perf.span("main.consumerTime_ms");
|
|
3536
4646
|
yield r;
|
|
4647
|
+
sYield.stop();
|
|
3537
4648
|
}
|
|
3538
4649
|
await Promise.all(loops);
|
|
3539
4650
|
}
|
|
@@ -3544,6 +4655,59 @@ async function* visualizeDifferences(a, b, options) {
|
|
|
3544
4655
|
}
|
|
3545
4656
|
|
|
3546
4657
|
/// <reference lib="dom" />
|
|
4658
|
+
async function encodeBitmapToPng(img) {
|
|
4659
|
+
const data = img.bitmap.data;
|
|
4660
|
+
const view = data instanceof Uint8ClampedArray
|
|
4661
|
+
? data
|
|
4662
|
+
: new Uint8ClampedArray(data.buffer, data.byteOffset, data.byteLength);
|
|
4663
|
+
const png = await encode$3(new ImageData(view, img.width, img.height));
|
|
4664
|
+
return new Uint8Array(png);
|
|
4665
|
+
}
|
|
4666
|
+
const versionEl = document.getElementById("version");
|
|
4667
|
+
if (versionEl)
|
|
4668
|
+
versionEl.textContent = "v" + VERSION;
|
|
4669
|
+
const hideNoDiffEl = document.getElementById("hide-no-diff");
|
|
4670
|
+
const applyHideNoDiff = () => {
|
|
4671
|
+
document.body.classList.toggle("hide-no-diff", !!hideNoDiffEl?.checked);
|
|
4672
|
+
};
|
|
4673
|
+
hideNoDiffEl?.addEventListener("change", applyHideNoDiff);
|
|
4674
|
+
applyHideNoDiff();
|
|
4675
|
+
const downloadButton = document.getElementById("download-zip");
|
|
4676
|
+
let lastResultPages = null;
|
|
4677
|
+
const updateDownloadLabel = () => {
|
|
4678
|
+
if (!downloadButton)
|
|
4679
|
+
return;
|
|
4680
|
+
downloadButton.textContent = hideNoDiffEl?.checked
|
|
4681
|
+
? "Download zip (diff only)"
|
|
4682
|
+
: "Download zip";
|
|
4683
|
+
};
|
|
4684
|
+
hideNoDiffEl?.addEventListener("change", updateDownloadLabel);
|
|
4685
|
+
updateDownloadLabel();
|
|
4686
|
+
downloadButton?.addEventListener("click", () => {
|
|
4687
|
+
if (!lastResultPages)
|
|
4688
|
+
return;
|
|
4689
|
+
const diffOnly = !!hideNoDiffEl?.checked;
|
|
4690
|
+
const files = {};
|
|
4691
|
+
for (const [i, page] of lastResultPages) {
|
|
4692
|
+
if (diffOnly && !page.hasDiff)
|
|
4693
|
+
continue;
|
|
4694
|
+
files[`${i}/a.png`] = page.a;
|
|
4695
|
+
files[`${i}/b.png`] = page.b;
|
|
4696
|
+
files[`${i}/diff.png`] = page.diff;
|
|
4697
|
+
}
|
|
4698
|
+
if (Object.keys(files).length === 0)
|
|
4699
|
+
return;
|
|
4700
|
+
const zipped = zipSync(files, { level: 0 });
|
|
4701
|
+
const blob = new Blob([new Uint8Array(zipped)], { type: "application/zip" });
|
|
4702
|
+
const url = URL.createObjectURL(blob);
|
|
4703
|
+
const a = document.createElement("a");
|
|
4704
|
+
a.href = url;
|
|
4705
|
+
a.download = diffOnly ? "pdfdiff-result-diff-only.zip" : "pdfdiff-result.zip";
|
|
4706
|
+
document.body.appendChild(a);
|
|
4707
|
+
a.click();
|
|
4708
|
+
document.body.removeChild(a);
|
|
4709
|
+
URL.revokeObjectURL(url);
|
|
4710
|
+
});
|
|
3547
4711
|
async function readFileAsUint8Array(file) {
|
|
3548
4712
|
return new Promise((resolve, reject) => {
|
|
3549
4713
|
const reader = new FileReader();
|
|
@@ -3564,6 +4728,17 @@ document
|
|
|
3564
4728
|
const errorElement = document.getElementById("error-message");
|
|
3565
4729
|
if (errorElement)
|
|
3566
4730
|
errorElement.textContent = "";
|
|
4731
|
+
const submitButton = event.currentTarget.querySelector('button[type="submit"]');
|
|
4732
|
+
const originalSubmitText = submitButton?.textContent ?? "";
|
|
4733
|
+
if (submitButton) {
|
|
4734
|
+
submitButton.disabled = true;
|
|
4735
|
+
submitButton.textContent = "Preparing...";
|
|
4736
|
+
}
|
|
4737
|
+
if (downloadButton)
|
|
4738
|
+
downloadButton.disabled = true;
|
|
4739
|
+
lastResultPages = null;
|
|
4740
|
+
const resultPages = new Map();
|
|
4741
|
+
let completed = false;
|
|
3567
4742
|
try {
|
|
3568
4743
|
const pdfAFile = document.getElementById("pdf-a")?.files?.[0];
|
|
3569
4744
|
const pdfBFile = document.getElementById("pdf-b")?.files?.[0];
|
|
@@ -3628,10 +4803,14 @@ document
|
|
|
3628
4803
|
options.pallet.modification = modificationColor;
|
|
3629
4804
|
}
|
|
3630
4805
|
for await (const [i, { a, b, diff, addition, deletion, modification },] of withIndex(visualizeDifferences(pdfA, pdfB, options), 1)) {
|
|
4806
|
+
if (submitButton)
|
|
4807
|
+
submitButton.textContent = `Page ${i}...`;
|
|
3631
4808
|
const pageResult = document.createElement("details");
|
|
3632
4809
|
pageResult.className = "diff-details";
|
|
3633
|
-
|
|
3634
|
-
|
|
4810
|
+
const totalDiff = addition.length + deletion.length + modification.length;
|
|
4811
|
+
if (totalDiff === 0)
|
|
4812
|
+
pageResult.classList.add("no-diff");
|
|
4813
|
+
pageResult.open = totalDiff > 0;
|
|
3635
4814
|
const summary = document.createElement("summary");
|
|
3636
4815
|
const summaryInline = document.createElement("div");
|
|
3637
4816
|
summaryInline.className = "summary-content";
|
|
@@ -3657,21 +4836,30 @@ document
|
|
|
3657
4836
|
headerRow.appendChild(headerDiff);
|
|
3658
4837
|
imagesTable.appendChild(headerRow);
|
|
3659
4838
|
const imagesRow = document.createElement("tr");
|
|
4839
|
+
const aPng = await encodeBitmapToPng(a);
|
|
4840
|
+
const bPng = await encodeBitmapToPng(b);
|
|
4841
|
+
const diffPng = await encodeBitmapToPng(diff);
|
|
4842
|
+
resultPages.set(i, {
|
|
4843
|
+
a: aPng,
|
|
4844
|
+
b: bPng,
|
|
4845
|
+
diff: diffPng,
|
|
4846
|
+
hasDiff: totalDiff > 0,
|
|
4847
|
+
});
|
|
3660
4848
|
const cellA = document.createElement("td");
|
|
3661
4849
|
const imageA = document.createElement("img");
|
|
3662
|
-
imageA.src =
|
|
4850
|
+
imageA.src = URL.createObjectURL(new Blob([new Uint8Array(aPng)], { type: "image/png" }));
|
|
3663
4851
|
imageA.className = "checkerboard-bg";
|
|
3664
4852
|
cellA.appendChild(imageA);
|
|
3665
4853
|
imagesRow.appendChild(cellA);
|
|
3666
4854
|
const cellB = document.createElement("td");
|
|
3667
4855
|
const imageB = document.createElement("img");
|
|
3668
|
-
imageB.src =
|
|
4856
|
+
imageB.src = URL.createObjectURL(new Blob([new Uint8Array(bPng)], { type: "image/png" }));
|
|
3669
4857
|
imageB.className = "checkerboard-bg";
|
|
3670
4858
|
cellB.appendChild(imageB);
|
|
3671
4859
|
imagesRow.appendChild(cellB);
|
|
3672
4860
|
const cellDiff = document.createElement("td");
|
|
3673
4861
|
const imageDiff = document.createElement("img");
|
|
3674
|
-
imageDiff.src =
|
|
4862
|
+
imageDiff.src = URL.createObjectURL(new Blob([new Uint8Array(diffPng)], { type: "image/png" }));
|
|
3675
4863
|
imageDiff.className = "checkerboard-bg";
|
|
3676
4864
|
cellDiff.appendChild(imageDiff);
|
|
3677
4865
|
imagesRow.appendChild(cellDiff);
|
|
@@ -3679,6 +4867,7 @@ document
|
|
|
3679
4867
|
pageResult.appendChild(imagesTable);
|
|
3680
4868
|
resultsContainer?.appendChild(pageResult);
|
|
3681
4869
|
}
|
|
4870
|
+
completed = true;
|
|
3682
4871
|
}
|
|
3683
4872
|
catch (e) {
|
|
3684
4873
|
console.error(e);
|
|
@@ -3686,5 +4875,16 @@ document
|
|
|
3686
4875
|
errorElement.textContent = `Error: ${e.message}`;
|
|
3687
4876
|
}
|
|
3688
4877
|
}
|
|
4878
|
+
finally {
|
|
4879
|
+
if (submitButton) {
|
|
4880
|
+
submitButton.disabled = false;
|
|
4881
|
+
submitButton.textContent = originalSubmitText;
|
|
4882
|
+
}
|
|
4883
|
+
if (completed && resultPages.size > 0) {
|
|
4884
|
+
lastResultPages = resultPages;
|
|
4885
|
+
if (downloadButton)
|
|
4886
|
+
downloadButton.disabled = false;
|
|
4887
|
+
}
|
|
4888
|
+
}
|
|
3689
4889
|
});
|
|
3690
4890
|
//# sourceMappingURL=browser.js.map
|