vizmatic 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1876,1789 +1876,6 @@ async function renderRgbaVideo(renderFrame, options) {
1876
1876
  }
1877
1877
  }
1878
1878
 
1879
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/convert_indexed_to_rgb.js
1880
- function convertIndexedToRgb(decodedImage) {
1881
- const palette = decodedImage.palette;
1882
- const depth = decodedImage.depth;
1883
- if (!palette) {
1884
- throw new Error("Color palette is undefined.");
1885
- }
1886
- checkDataSize(decodedImage);
1887
- const indexSize = decodedImage.width * decodedImage.height;
1888
- const resSize = indexSize * palette[0].length;
1889
- const res = new Uint8Array(resSize);
1890
- let indexPos = 0;
1891
- let offset = 0;
1892
- const indexes = new Uint8Array(indexSize);
1893
- let bit = 255;
1894
- switch (depth) {
1895
- case 1:
1896
- bit = 128;
1897
- break;
1898
- case 2:
1899
- bit = 192;
1900
- break;
1901
- case 4:
1902
- bit = 240;
1903
- break;
1904
- case 8:
1905
- bit = 255;
1906
- break;
1907
- default:
1908
- throw new Error("Incorrect depth value");
1909
- }
1910
- for (const byte of decodedImage.data) {
1911
- let bit2 = bit;
1912
- let shift = 8;
1913
- while (bit2) {
1914
- shift -= depth;
1915
- indexes[indexPos++] = (byte & bit2) >> shift;
1916
- bit2 = bit2 >> depth;
1917
- if (indexPos % decodedImage.width === 0) {
1918
- break;
1919
- }
1920
- }
1921
- }
1922
- if (decodedImage.palette) {
1923
- for (const index of indexes) {
1924
- const color = decodedImage.palette.at(index);
1925
- if (!color) {
1926
- throw new Error("Incorrect index of palette color");
1927
- }
1928
- res.set(color, offset);
1929
- offset += color.length;
1930
- }
1931
- }
1932
- return res;
1933
- }
1934
- function checkDataSize(image) {
1935
- const expectedSize = image.depth < 8 ? Math.ceil(image.width * image.depth / 8) * image.height * image.channels : image.width * image.height * image.channels;
1936
- if (image.data.length !== expectedSize) {
1937
- throw new RangeError(`wrong data size. Found ${image.data.length}, expected ${expectedSize}`);
1938
- }
1939
- }
1940
-
1941
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/png_decoder.js
1942
- import { Unzlib as Inflator, unzlibSync } from "fflate";
1943
-
1944
- // node_modules/.pnpm/iobuffer@6.0.1/node_modules/iobuffer/lib/text.js
1945
- function decode(bytes, encoding = "utf8") {
1946
- const decoder = new TextDecoder(encoding);
1947
- return decoder.decode(bytes);
1948
- }
1949
- var encoder = new TextEncoder();
1950
- function encode(str) {
1951
- return encoder.encode(str);
1952
- }
1953
-
1954
- // node_modules/.pnpm/iobuffer@6.0.1/node_modules/iobuffer/lib/iobuffer.js
1955
- var defaultByteLength = 1024 * 8;
1956
- var hostBigEndian = (() => {
1957
- const array = new Uint8Array(4);
1958
- const view = new Uint32Array(array.buffer);
1959
- return !((view[0] = 1) & array[0]);
1960
- })();
1961
- var typedArrays = {
1962
- int8: globalThis.Int8Array,
1963
- uint8: globalThis.Uint8Array,
1964
- int16: globalThis.Int16Array,
1965
- uint16: globalThis.Uint16Array,
1966
- int32: globalThis.Int32Array,
1967
- uint32: globalThis.Uint32Array,
1968
- uint64: globalThis.BigUint64Array,
1969
- int64: globalThis.BigInt64Array,
1970
- float32: globalThis.Float32Array,
1971
- float64: globalThis.Float64Array
1972
- };
1973
- var IOBuffer = class _IOBuffer {
1974
- /**
1975
- * Reference to the internal ArrayBuffer object.
1976
- */
1977
- buffer;
1978
- /**
1979
- * Byte length of the internal ArrayBuffer.
1980
- */
1981
- byteLength;
1982
- /**
1983
- * Byte offset of the internal ArrayBuffer.
1984
- */
1985
- byteOffset;
1986
- /**
1987
- * Byte length of the internal ArrayBuffer.
1988
- */
1989
- length;
1990
- /**
1991
- * The current offset of the buffer's pointer.
1992
- */
1993
- offset;
1994
- lastWrittenByte;
1995
- littleEndian;
1996
- _data;
1997
- _mark;
1998
- _marks;
1999
- /**
2000
- * Create a new IOBuffer.
2001
- * @param data - The data to construct the IOBuffer with.
2002
- * If data is a number, it will be the new buffer's length<br>
2003
- * If data is `undefined`, the buffer will be initialized with a default length of 8Kb<br>
2004
- * If data is an ArrayBuffer, SharedArrayBuffer, an ArrayBufferView (Typed Array), an IOBuffer instance,
2005
- * or a Node.js Buffer, a view will be created over the underlying ArrayBuffer.
2006
- * @param options - An object for the options.
2007
- * @returns A new IOBuffer instance.
2008
- */
2009
- constructor(data = defaultByteLength, options = {}) {
2010
- let dataIsGiven = false;
2011
- if (typeof data === "number") {
2012
- data = new ArrayBuffer(data);
2013
- } else {
2014
- dataIsGiven = true;
2015
- this.lastWrittenByte = data.byteLength;
2016
- }
2017
- const offset = options.offset ? options.offset >>> 0 : 0;
2018
- const byteLength = data.byteLength - offset;
2019
- let dvOffset = offset;
2020
- if (ArrayBuffer.isView(data) || data instanceof _IOBuffer) {
2021
- if (data.byteLength !== data.buffer.byteLength) {
2022
- dvOffset = data.byteOffset + offset;
2023
- }
2024
- data = data.buffer;
2025
- }
2026
- if (dataIsGiven) {
2027
- this.lastWrittenByte = byteLength;
2028
- } else {
2029
- this.lastWrittenByte = 0;
2030
- }
2031
- this.buffer = data;
2032
- this.length = byteLength;
2033
- this.byteLength = byteLength;
2034
- this.byteOffset = dvOffset;
2035
- this.offset = 0;
2036
- this.littleEndian = true;
2037
- this._data = new DataView(this.buffer, dvOffset, byteLength);
2038
- this._mark = 0;
2039
- this._marks = [];
2040
- }
2041
- /**
2042
- * Checks if the memory allocated to the buffer is sufficient to store more
2043
- * bytes after the offset.
2044
- * @param byteLength - The needed memory in bytes.
2045
- * @returns `true` if there is sufficient space and `false` otherwise.
2046
- */
2047
- available(byteLength = 1) {
2048
- return this.offset + byteLength <= this.length;
2049
- }
2050
- /**
2051
- * Check if little-endian mode is used for reading and writing multi-byte
2052
- * values.
2053
- * @returns `true` if little-endian mode is used, `false` otherwise.
2054
- */
2055
- isLittleEndian() {
2056
- return this.littleEndian;
2057
- }
2058
- /**
2059
- * Set little-endian mode for reading and writing multi-byte values.
2060
- * @returns This.
2061
- */
2062
- setLittleEndian() {
2063
- this.littleEndian = true;
2064
- return this;
2065
- }
2066
- /**
2067
- * Check if big-endian mode is used for reading and writing multi-byte values.
2068
- * @returns `true` if big-endian mode is used, `false` otherwise.
2069
- */
2070
- isBigEndian() {
2071
- return !this.littleEndian;
2072
- }
2073
- /**
2074
- * Switches to big-endian mode for reading and writing multi-byte values.
2075
- * @returns This.
2076
- */
2077
- setBigEndian() {
2078
- this.littleEndian = false;
2079
- return this;
2080
- }
2081
- /**
2082
- * Move the pointer n bytes forward.
2083
- * @param n - Number of bytes to skip.
2084
- * @returns This.
2085
- */
2086
- skip(n = 1) {
2087
- this.offset += n;
2088
- return this;
2089
- }
2090
- /**
2091
- * Move the pointer n bytes backward.
2092
- * @param n - Number of bytes to move back.
2093
- * @returns This.
2094
- */
2095
- back(n = 1) {
2096
- this.offset -= n;
2097
- return this;
2098
- }
2099
- /**
2100
- * Move the pointer to the given offset.
2101
- * @param offset - The offset to move to.
2102
- * @returns This.
2103
- */
2104
- seek(offset) {
2105
- this.offset = offset;
2106
- return this;
2107
- }
2108
- /**
2109
- * Store the current pointer offset.
2110
- * @see {@link IOBuffer#reset}
2111
- * @returns This.
2112
- */
2113
- mark() {
2114
- this._mark = this.offset;
2115
- return this;
2116
- }
2117
- /**
2118
- * Move the pointer back to the last pointer offset set by mark.
2119
- * @see {@link IOBuffer#mark}
2120
- * @returns This.
2121
- */
2122
- reset() {
2123
- this.offset = this._mark;
2124
- return this;
2125
- }
2126
- /**
2127
- * Push the current pointer offset to the mark stack.
2128
- * @see {@link IOBuffer#popMark}
2129
- * @returns This.
2130
- */
2131
- pushMark() {
2132
- this._marks.push(this.offset);
2133
- return this;
2134
- }
2135
- /**
2136
- * Pop the last pointer offset from the mark stack, and set the current
2137
- * pointer offset to the popped value.
2138
- * @see {@link IOBuffer#pushMark}
2139
- * @returns This.
2140
- */
2141
- popMark() {
2142
- const offset = this._marks.pop();
2143
- if (offset === void 0) {
2144
- throw new Error("Mark stack empty");
2145
- }
2146
- this.seek(offset);
2147
- return this;
2148
- }
2149
- /**
2150
- * Move the pointer offset back to 0.
2151
- * @returns This.
2152
- */
2153
- rewind() {
2154
- this.offset = 0;
2155
- return this;
2156
- }
2157
- /**
2158
- * Make sure the buffer has sufficient memory to write a given byteLength at
2159
- * the current pointer offset.
2160
- * If the buffer's memory is insufficient, this method will create a new
2161
- * buffer (a copy) with a length that is twice (byteLength + current offset).
2162
- * @param byteLength - The needed memory in bytes.
2163
- * @returns This.
2164
- */
2165
- ensureAvailable(byteLength = 1) {
2166
- if (!this.available(byteLength)) {
2167
- const lengthNeeded = this.offset + byteLength;
2168
- const newLength = lengthNeeded * 2;
2169
- const newArray = new Uint8Array(newLength);
2170
- newArray.set(new Uint8Array(this.buffer));
2171
- this.buffer = newArray.buffer;
2172
- this.length = newLength;
2173
- this.byteLength = newLength;
2174
- this._data = new DataView(this.buffer);
2175
- }
2176
- return this;
2177
- }
2178
- /**
2179
- * Read a byte and return false if the byte's value is 0, or true otherwise.
2180
- * Moves pointer forward by one byte.
2181
- * @returns The read boolean.
2182
- */
2183
- readBoolean() {
2184
- return this.readUint8() !== 0;
2185
- }
2186
- /**
2187
- * Read a signed 8-bit integer and move pointer forward by 1 byte.
2188
- * @returns The read byte.
2189
- */
2190
- readInt8() {
2191
- return this._data.getInt8(this.offset++);
2192
- }
2193
- /**
2194
- * Read an unsigned 8-bit integer and move pointer forward by 1 byte.
2195
- * @returns The read byte.
2196
- */
2197
- readUint8() {
2198
- return this._data.getUint8(this.offset++);
2199
- }
2200
- /**
2201
- * Alias for {@link IOBuffer#readUint8}.
2202
- * @returns The read byte.
2203
- */
2204
- readByte() {
2205
- return this.readUint8();
2206
- }
2207
- /**
2208
- * Read `n` bytes and move pointer forward by `n` bytes.
2209
- * @param n - Number of bytes to read.
2210
- * @returns The read bytes.
2211
- */
2212
- readBytes(n = 1) {
2213
- return this.readArray(n, "uint8");
2214
- }
2215
- /**
2216
- * Creates an array of corresponding to the type `type` and size `size`.
2217
- * For example, type `uint8` will create a `Uint8Array`.
2218
- * @param size - size of the resulting array
2219
- * @param type - number type of elements to read
2220
- * @returns The read array.
2221
- */
2222
- readArray(size, type) {
2223
- const bytes = typedArrays[type].BYTES_PER_ELEMENT * size;
2224
- const offset = this.byteOffset + this.offset;
2225
- const slice = this.buffer.slice(offset, offset + bytes);
2226
- if (this.littleEndian === hostBigEndian && type !== "uint8" && type !== "int8") {
2227
- const slice2 = new Uint8Array(this.buffer.slice(offset, offset + bytes));
2228
- slice2.reverse();
2229
- const returnArray2 = new typedArrays[type](slice2.buffer);
2230
- this.offset += bytes;
2231
- returnArray2.reverse();
2232
- return returnArray2;
2233
- }
2234
- const returnArray = new typedArrays[type](slice);
2235
- this.offset += bytes;
2236
- return returnArray;
2237
- }
2238
- /**
2239
- * Read a 16-bit signed integer and move pointer forward by 2 bytes.
2240
- * @returns The read value.
2241
- */
2242
- readInt16() {
2243
- const value = this._data.getInt16(this.offset, this.littleEndian);
2244
- this.offset += 2;
2245
- return value;
2246
- }
2247
- /**
2248
- * Read a 16-bit unsigned integer and move pointer forward by 2 bytes.
2249
- * @returns The read value.
2250
- */
2251
- readUint16() {
2252
- const value = this._data.getUint16(this.offset, this.littleEndian);
2253
- this.offset += 2;
2254
- return value;
2255
- }
2256
- /**
2257
- * Read a 32-bit signed integer and move pointer forward by 4 bytes.
2258
- * @returns The read value.
2259
- */
2260
- readInt32() {
2261
- const value = this._data.getInt32(this.offset, this.littleEndian);
2262
- this.offset += 4;
2263
- return value;
2264
- }
2265
- /**
2266
- * Read a 32-bit unsigned integer and move pointer forward by 4 bytes.
2267
- * @returns The read value.
2268
- */
2269
- readUint32() {
2270
- const value = this._data.getUint32(this.offset, this.littleEndian);
2271
- this.offset += 4;
2272
- return value;
2273
- }
2274
- /**
2275
- * Read a 32-bit floating number and move pointer forward by 4 bytes.
2276
- * @returns The read value.
2277
- */
2278
- readFloat32() {
2279
- const value = this._data.getFloat32(this.offset, this.littleEndian);
2280
- this.offset += 4;
2281
- return value;
2282
- }
2283
- /**
2284
- * Read a 64-bit floating number and move pointer forward by 8 bytes.
2285
- * @returns The read value.
2286
- */
2287
- readFloat64() {
2288
- const value = this._data.getFloat64(this.offset, this.littleEndian);
2289
- this.offset += 8;
2290
- return value;
2291
- }
2292
- /**
2293
- * Read a 64-bit signed integer number and move pointer forward by 8 bytes.
2294
- * @returns The read value.
2295
- */
2296
- readBigInt64() {
2297
- const value = this._data.getBigInt64(this.offset, this.littleEndian);
2298
- this.offset += 8;
2299
- return value;
2300
- }
2301
- /**
2302
- * Read a 64-bit unsigned integer number and move pointer forward by 8 bytes.
2303
- * @returns The read value.
2304
- */
2305
- readBigUint64() {
2306
- const value = this._data.getBigUint64(this.offset, this.littleEndian);
2307
- this.offset += 8;
2308
- return value;
2309
- }
2310
- /**
2311
- * Read a 1-byte ASCII character and move pointer forward by 1 byte.
2312
- * @returns The read character.
2313
- */
2314
- readChar() {
2315
- return String.fromCharCode(this.readInt8());
2316
- }
2317
- /**
2318
- * Read `n` 1-byte ASCII characters and move pointer forward by `n` bytes.
2319
- * @param n - Number of characters to read.
2320
- * @returns The read characters.
2321
- */
2322
- readChars(n = 1) {
2323
- let result = "";
2324
- for (let i = 0; i < n; i++) {
2325
- result += this.readChar();
2326
- }
2327
- return result;
2328
- }
2329
- /**
2330
- * Read the next `n` bytes, return a UTF-8 decoded string and move pointer
2331
- * forward by `n` bytes.
2332
- * @param n - Number of bytes to read.
2333
- * @returns The decoded string.
2334
- */
2335
- readUtf8(n = 1) {
2336
- return decode(this.readBytes(n));
2337
- }
2338
- /**
2339
- * Read the next `n` bytes, return a string decoded with `encoding` and move pointer
2340
- * forward by `n` bytes.
2341
- * If no encoding is passed, the function is equivalent to @see {@link IOBuffer#readUtf8}
2342
- * @param n - Number of bytes to read.
2343
- * @param encoding - The encoding to use. Default is 'utf8'.
2344
- * @returns The decoded string.
2345
- */
2346
- decodeText(n = 1, encoding = "utf8") {
2347
- return decode(this.readBytes(n), encoding);
2348
- }
2349
- /**
2350
- * Write 0xff if the passed value is truthy, 0x00 otherwise and move pointer
2351
- * forward by 1 byte.
2352
- * @param value - The value to write.
2353
- * @returns This.
2354
- */
2355
- writeBoolean(value) {
2356
- this.writeUint8(value ? 255 : 0);
2357
- return this;
2358
- }
2359
- /**
2360
- * Write `value` as an 8-bit signed integer and move pointer forward by 1 byte.
2361
- * @param value - The value to write.
2362
- * @returns This.
2363
- */
2364
- writeInt8(value) {
2365
- this.ensureAvailable(1);
2366
- this._data.setInt8(this.offset++, value);
2367
- this._updateLastWrittenByte();
2368
- return this;
2369
- }
2370
- /**
2371
- * Write `value` as an 8-bit unsigned integer and move pointer forward by 1
2372
- * byte.
2373
- * @param value - The value to write.
2374
- * @returns This.
2375
- */
2376
- writeUint8(value) {
2377
- this.ensureAvailable(1);
2378
- this._data.setUint8(this.offset++, value);
2379
- this._updateLastWrittenByte();
2380
- return this;
2381
- }
2382
- /**
2383
- * An alias for {@link IOBuffer#writeUint8}.
2384
- * @param value - The value to write.
2385
- * @returns This.
2386
- */
2387
- writeByte(value) {
2388
- return this.writeUint8(value);
2389
- }
2390
- /**
2391
- * Write all elements of `bytes` as uint8 values and move pointer forward by
2392
- * `bytes.length` bytes.
2393
- * @param bytes - The array of bytes to write.
2394
- * @returns This.
2395
- */
2396
- writeBytes(bytes) {
2397
- this.ensureAvailable(bytes.length);
2398
- for (let i = 0; i < bytes.length; i++) {
2399
- this._data.setUint8(this.offset++, bytes[i]);
2400
- }
2401
- this._updateLastWrittenByte();
2402
- return this;
2403
- }
2404
- /**
2405
- * Write `value` as a 16-bit signed integer and move pointer forward by 2
2406
- * bytes.
2407
- * @param value - The value to write.
2408
- * @returns This.
2409
- */
2410
- writeInt16(value) {
2411
- this.ensureAvailable(2);
2412
- this._data.setInt16(this.offset, value, this.littleEndian);
2413
- this.offset += 2;
2414
- this._updateLastWrittenByte();
2415
- return this;
2416
- }
2417
- /**
2418
- * Write `value` as a 16-bit unsigned integer and move pointer forward by 2
2419
- * bytes.
2420
- * @param value - The value to write.
2421
- * @returns This.
2422
- */
2423
- writeUint16(value) {
2424
- this.ensureAvailable(2);
2425
- this._data.setUint16(this.offset, value, this.littleEndian);
2426
- this.offset += 2;
2427
- this._updateLastWrittenByte();
2428
- return this;
2429
- }
2430
- /**
2431
- * Write `value` as a 32-bit signed integer and move pointer forward by 4
2432
- * bytes.
2433
- * @param value - The value to write.
2434
- * @returns This.
2435
- */
2436
- writeInt32(value) {
2437
- this.ensureAvailable(4);
2438
- this._data.setInt32(this.offset, value, this.littleEndian);
2439
- this.offset += 4;
2440
- this._updateLastWrittenByte();
2441
- return this;
2442
- }
2443
- /**
2444
- * Write `value` as a 32-bit unsigned integer and move pointer forward by 4
2445
- * bytes.
2446
- * @param value - The value to write.
2447
- * @returns This.
2448
- */
2449
- writeUint32(value) {
2450
- this.ensureAvailable(4);
2451
- this._data.setUint32(this.offset, value, this.littleEndian);
2452
- this.offset += 4;
2453
- this._updateLastWrittenByte();
2454
- return this;
2455
- }
2456
- /**
2457
- * Write `value` as a 32-bit floating number and move pointer forward by 4
2458
- * bytes.
2459
- * @param value - The value to write.
2460
- * @returns This.
2461
- */
2462
- writeFloat32(value) {
2463
- this.ensureAvailable(4);
2464
- this._data.setFloat32(this.offset, value, this.littleEndian);
2465
- this.offset += 4;
2466
- this._updateLastWrittenByte();
2467
- return this;
2468
- }
2469
- /**
2470
- * Write `value` as a 64-bit floating number and move pointer forward by 8
2471
- * bytes.
2472
- * @param value - The value to write.
2473
- * @returns This.
2474
- */
2475
- writeFloat64(value) {
2476
- this.ensureAvailable(8);
2477
- this._data.setFloat64(this.offset, value, this.littleEndian);
2478
- this.offset += 8;
2479
- this._updateLastWrittenByte();
2480
- return this;
2481
- }
2482
- /**
2483
- * Write `value` as a 64-bit signed bigint and move pointer forward by 8
2484
- * bytes.
2485
- * @param value - The value to write.
2486
- * @returns This.
2487
- */
2488
- writeBigInt64(value) {
2489
- this.ensureAvailable(8);
2490
- this._data.setBigInt64(this.offset, value, this.littleEndian);
2491
- this.offset += 8;
2492
- this._updateLastWrittenByte();
2493
- return this;
2494
- }
2495
- /**
2496
- * Write `value` as a 64-bit unsigned bigint and move pointer forward by 8
2497
- * bytes.
2498
- * @param value - The value to write.
2499
- * @returns This.
2500
- */
2501
- writeBigUint64(value) {
2502
- this.ensureAvailable(8);
2503
- this._data.setBigUint64(this.offset, value, this.littleEndian);
2504
- this.offset += 8;
2505
- this._updateLastWrittenByte();
2506
- return this;
2507
- }
2508
- /**
2509
- * Write the charCode of `str`'s first character as an 8-bit unsigned integer
2510
- * and move pointer forward by 1 byte.
2511
- * @param str - The character to write.
2512
- * @returns This.
2513
- */
2514
- writeChar(str) {
2515
- return this.writeUint8(str.charCodeAt(0));
2516
- }
2517
- /**
2518
- * Write the charCodes of all `str`'s characters as 8-bit unsigned integers
2519
- * and move pointer forward by `str.length` bytes.
2520
- * @param str - The characters to write.
2521
- * @returns This.
2522
- */
2523
- writeChars(str) {
2524
- for (let i = 0; i < str.length; i++) {
2525
- this.writeUint8(str.charCodeAt(i));
2526
- }
2527
- return this;
2528
- }
2529
- /**
2530
- * UTF-8 encode and write `str` to the current pointer offset and move pointer
2531
- * forward according to the encoded length.
2532
- * @param str - The string to write.
2533
- * @returns This.
2534
- */
2535
- writeUtf8(str) {
2536
- return this.writeBytes(encode(str));
2537
- }
2538
- /**
2539
- * Export a Uint8Array view of the internal buffer.
2540
- * The view starts at the byte offset and its length
2541
- * is calculated to stop at the last written byte or the original length.
2542
- * @returns A new Uint8Array view.
2543
- */
2544
- toArray() {
2545
- return new Uint8Array(this.buffer, this.byteOffset, this.lastWrittenByte);
2546
- }
2547
- /**
2548
- * Get the total number of bytes written so far, regardless of the current offset.
2549
- * @returns - Total number of bytes.
2550
- */
2551
- getWrittenByteLength() {
2552
- return this.lastWrittenByte - this.byteOffset;
2553
- }
2554
- /**
2555
- * Update the last written byte offset
2556
- * @private
2557
- */
2558
- _updateLastWrittenByte() {
2559
- if (this.offset > this.lastWrittenByte) {
2560
- this.lastWrittenByte = this.offset;
2561
- }
2562
- }
2563
- };
2564
-
2565
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/helpers/crc.js
2566
- var crcTable = [];
2567
- for (let n = 0; n < 256; n++) {
2568
- let c = n;
2569
- for (let k = 0; k < 8; k++) {
2570
- if (c & 1) {
2571
- c = 3988292384 ^ c >>> 1;
2572
- } else {
2573
- c = c >>> 1;
2574
- }
2575
- }
2576
- crcTable[n] = c;
2577
- }
2578
- var initialCrc = 4294967295;
2579
- function updateCrc(currentCrc, data, length) {
2580
- let c = currentCrc;
2581
- for (let n = 0; n < length; n++) {
2582
- c = crcTable[(c ^ data[n]) & 255] ^ c >>> 8;
2583
- }
2584
- return c;
2585
- }
2586
- function crc(data, length) {
2587
- return (updateCrc(initialCrc, data, length) ^ initialCrc) >>> 0;
2588
- }
2589
- function checkCrc(buffer, crcLength, chunkName) {
2590
- const expectedCrc = buffer.readUint32();
2591
- const actualCrc = crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - crcLength - 4, crcLength), crcLength);
2592
- if (actualCrc !== expectedCrc) {
2593
- throw new Error(`CRC mismatch for chunk ${chunkName}. Expected ${expectedCrc}, found ${actualCrc}`);
2594
- }
2595
- }
2596
- function writeCrc(buffer, length) {
2597
- buffer.writeUint32(crc(new Uint8Array(buffer.buffer, buffer.byteOffset + buffer.offset - length, length), length));
2598
- }
2599
-
2600
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/helpers/unfilter.js
2601
- function unfilterNone(currentLine, newLine, bytesPerLine) {
2602
- for (let i = 0; i < bytesPerLine; i++) {
2603
- newLine[i] = currentLine[i];
2604
- }
2605
- }
2606
- function unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel) {
2607
- let i = 0;
2608
- for (; i < bytesPerPixel; i++) {
2609
- newLine[i] = currentLine[i];
2610
- }
2611
- for (; i < bytesPerLine; i++) {
2612
- newLine[i] = currentLine[i] + newLine[i - bytesPerPixel] & 255;
2613
- }
2614
- }
2615
- function unfilterUp(currentLine, newLine, prevLine, bytesPerLine) {
2616
- let i = 0;
2617
- if (prevLine.length === 0) {
2618
- for (; i < bytesPerLine; i++) {
2619
- newLine[i] = currentLine[i];
2620
- }
2621
- } else {
2622
- for (; i < bytesPerLine; i++) {
2623
- newLine[i] = currentLine[i] + prevLine[i] & 255;
2624
- }
2625
- }
2626
- }
2627
- function unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {
2628
- let i = 0;
2629
- if (prevLine.length === 0) {
2630
- for (; i < bytesPerPixel; i++) {
2631
- newLine[i] = currentLine[i];
2632
- }
2633
- for (; i < bytesPerLine; i++) {
2634
- newLine[i] = currentLine[i] + (newLine[i - bytesPerPixel] >> 1) & 255;
2635
- }
2636
- } else {
2637
- for (; i < bytesPerPixel; i++) {
2638
- newLine[i] = currentLine[i] + (prevLine[i] >> 1) & 255;
2639
- }
2640
- for (; i < bytesPerLine; i++) {
2641
- newLine[i] = currentLine[i] + (newLine[i - bytesPerPixel] + prevLine[i] >> 1) & 255;
2642
- }
2643
- }
2644
- }
2645
- function unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel) {
2646
- let i = 0;
2647
- if (prevLine.length === 0) {
2648
- for (; i < bytesPerPixel; i++) {
2649
- newLine[i] = currentLine[i];
2650
- }
2651
- for (; i < bytesPerLine; i++) {
2652
- newLine[i] = currentLine[i] + newLine[i - bytesPerPixel] & 255;
2653
- }
2654
- } else {
2655
- for (; i < bytesPerPixel; i++) {
2656
- newLine[i] = currentLine[i] + prevLine[i] & 255;
2657
- }
2658
- for (; i < bytesPerLine; i++) {
2659
- newLine[i] = currentLine[i] + paethPredictor(newLine[i - bytesPerPixel], prevLine[i], prevLine[i - bytesPerPixel]) & 255;
2660
- }
2661
- }
2662
- }
2663
- function paethPredictor(a, b, c) {
2664
- const p = a + b - c;
2665
- const pa = Math.abs(p - a);
2666
- const pb = Math.abs(p - b);
2667
- const pc = Math.abs(p - c);
2668
- if (pa <= pb && pa <= pc)
2669
- return a;
2670
- else if (pb <= pc)
2671
- return b;
2672
- else
2673
- return c;
2674
- }
2675
-
2676
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/helpers/apply_unfilter.js
2677
- function applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel) {
2678
- switch (filterType) {
2679
- case 0:
2680
- unfilterNone(currentLine, newLine, passLineBytes);
2681
- break;
2682
- case 1:
2683
- unfilterSub(currentLine, newLine, passLineBytes, bytesPerPixel);
2684
- break;
2685
- case 2:
2686
- unfilterUp(currentLine, newLine, prevLine, passLineBytes);
2687
- break;
2688
- case 3:
2689
- unfilterAverage(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
2690
- break;
2691
- case 4:
2692
- unfilterPaeth(currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
2693
- break;
2694
- default:
2695
- throw new Error(`Unsupported filter: ${filterType}`);
2696
- }
2697
- }
2698
-
2699
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/helpers/decode_interlace_adam7.js
2700
- var uint16 = new Uint16Array([255]);
2701
- var uint8 = new Uint8Array(uint16.buffer);
2702
- var osIsLittleEndian = uint8[0] === 255;
2703
- function decodeInterlaceAdam7(params) {
2704
- const { data, width, height, channels, depth } = params;
2705
- const passes = [
2706
- { x: 0, y: 0, xStep: 8, yStep: 8 },
2707
- // Pass 1
2708
- { x: 4, y: 0, xStep: 8, yStep: 8 },
2709
- // Pass 2
2710
- { x: 0, y: 4, xStep: 4, yStep: 8 },
2711
- // Pass 3
2712
- { x: 2, y: 0, xStep: 4, yStep: 4 },
2713
- // Pass 4
2714
- { x: 0, y: 2, xStep: 2, yStep: 4 },
2715
- // Pass 5
2716
- { x: 1, y: 0, xStep: 2, yStep: 2 },
2717
- // Pass 6
2718
- { x: 0, y: 1, xStep: 1, yStep: 2 }
2719
- // Pass 7
2720
- ];
2721
- const bytesPerPixel = Math.ceil(depth / 8) * channels;
2722
- const resultData = new Uint8Array(height * width * bytesPerPixel);
2723
- let offset = 0;
2724
- for (let passIndex = 0; passIndex < 7; passIndex++) {
2725
- const pass = passes[passIndex];
2726
- const passWidth = Math.ceil((width - pass.x) / pass.xStep);
2727
- const passHeight = Math.ceil((height - pass.y) / pass.yStep);
2728
- if (passWidth <= 0 || passHeight <= 0)
2729
- continue;
2730
- const passLineBytes = passWidth * bytesPerPixel;
2731
- const prevLine = new Uint8Array(passLineBytes);
2732
- for (let y = 0; y < passHeight; y++) {
2733
- const filterType = data[offset++];
2734
- const currentLine = data.subarray(offset, offset + passLineBytes);
2735
- offset += passLineBytes;
2736
- const newLine = new Uint8Array(passLineBytes);
2737
- applyUnfilter(filterType, currentLine, newLine, prevLine, passLineBytes, bytesPerPixel);
2738
- prevLine.set(newLine);
2739
- for (let x = 0; x < passWidth; x++) {
2740
- const outputX = pass.x + x * pass.xStep;
2741
- const outputY = pass.y + y * pass.yStep;
2742
- if (outputX >= width || outputY >= height)
2743
- continue;
2744
- for (let i = 0; i < bytesPerPixel; i++) {
2745
- resultData[(outputY * width + outputX) * bytesPerPixel + i] = newLine[x * bytesPerPixel + i];
2746
- }
2747
- }
2748
- }
2749
- }
2750
- if (depth === 16) {
2751
- const uint16Data = new Uint16Array(resultData.buffer);
2752
- if (osIsLittleEndian) {
2753
- for (let k = 0; k < uint16Data.length; k++) {
2754
- uint16Data[k] = swap16(uint16Data[k]);
2755
- }
2756
- }
2757
- return uint16Data;
2758
- } else {
2759
- return resultData;
2760
- }
2761
- }
2762
- function swap16(val) {
2763
- return (val & 255) << 8 | val >> 8 & 255;
2764
- }
2765
-
2766
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/helpers/decode_interlace_null.js
2767
- var uint162 = new Uint16Array([255]);
2768
- var uint82 = new Uint8Array(uint162.buffer);
2769
- var osIsLittleEndian2 = uint82[0] === 255;
2770
- var empty = new Uint8Array(0);
2771
- function decodeInterlaceNull(params) {
2772
- const { data, width, height, channels, depth } = params;
2773
- const bytesPerPixel = Math.ceil(depth / 8) * channels;
2774
- const bytesPerLine = Math.ceil(depth / 8 * channels * width);
2775
- const newData = new Uint8Array(height * bytesPerLine);
2776
- let prevLine = empty;
2777
- let offset = 0;
2778
- let currentLine;
2779
- let newLine;
2780
- for (let i = 0; i < height; i++) {
2781
- currentLine = data.subarray(offset + 1, offset + 1 + bytesPerLine);
2782
- newLine = newData.subarray(i * bytesPerLine, (i + 1) * bytesPerLine);
2783
- switch (data[offset]) {
2784
- case 0:
2785
- unfilterNone(currentLine, newLine, bytesPerLine);
2786
- break;
2787
- case 1:
2788
- unfilterSub(currentLine, newLine, bytesPerLine, bytesPerPixel);
2789
- break;
2790
- case 2:
2791
- unfilterUp(currentLine, newLine, prevLine, bytesPerLine);
2792
- break;
2793
- case 3:
2794
- unfilterAverage(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
2795
- break;
2796
- case 4:
2797
- unfilterPaeth(currentLine, newLine, prevLine, bytesPerLine, bytesPerPixel);
2798
- break;
2799
- default:
2800
- throw new Error(`Unsupported filter: ${data[offset]}`);
2801
- }
2802
- prevLine = newLine;
2803
- offset += bytesPerLine + 1;
2804
- }
2805
- if (depth === 16) {
2806
- const uint16Data = new Uint16Array(newData.buffer);
2807
- if (osIsLittleEndian2) {
2808
- for (let k = 0; k < uint16Data.length; k++) {
2809
- uint16Data[k] = swap162(uint16Data[k]);
2810
- }
2811
- }
2812
- return uint16Data;
2813
- } else {
2814
- return newData;
2815
- }
2816
- }
2817
- function swap162(val) {
2818
- return (val & 255) << 8 | val >> 8 & 255;
2819
- }
2820
-
2821
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/helpers/signature.js
2822
- var pngSignature = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
2823
- function writeSignature(buffer) {
2824
- buffer.writeBytes(pngSignature);
2825
- }
2826
- function checkSignature(buffer) {
2827
- if (!hasPngSignature(buffer.readBytes(pngSignature.length))) {
2828
- throw new Error("wrong PNG signature");
2829
- }
2830
- }
2831
- function hasPngSignature(array) {
2832
- if (array.length < pngSignature.length) {
2833
- return false;
2834
- }
2835
- for (let i = 0; i < pngSignature.length; i++) {
2836
- if (array[i] !== pngSignature[i]) {
2837
- return false;
2838
- }
2839
- }
2840
- return true;
2841
- }
2842
-
2843
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/helpers/text.js
2844
- var textChunkName = "tEXt";
2845
- var NULL = 0;
2846
- var latin1Decoder = new TextDecoder("latin1");
2847
- function validateKeyword(keyword) {
2848
- validateLatin1(keyword);
2849
- if (keyword.length === 0 || keyword.length > 79) {
2850
- throw new Error("keyword length must be between 1 and 79");
2851
- }
2852
- }
2853
- var latin1Regex = /^[\u0000-\u00FF]*$/;
2854
- function validateLatin1(text) {
2855
- if (!latin1Regex.test(text)) {
2856
- throw new Error("invalid latin1 text");
2857
- }
2858
- }
2859
- function decodetEXt(text, buffer, length) {
2860
- const keyword = readKeyword(buffer);
2861
- text[keyword] = readLatin1(buffer, length - keyword.length - 1);
2862
- }
2863
- function encodetEXt(buffer, keyword, text) {
2864
- validateKeyword(keyword);
2865
- validateLatin1(text);
2866
- const length = keyword.length + 1 + text.length;
2867
- buffer.writeUint32(length);
2868
- buffer.writeChars(textChunkName);
2869
- buffer.writeChars(keyword);
2870
- buffer.writeByte(NULL);
2871
- buffer.writeChars(text);
2872
- writeCrc(buffer, length + 4);
2873
- }
2874
- function readKeyword(buffer) {
2875
- buffer.mark();
2876
- while (buffer.readByte() !== NULL) {
2877
- }
2878
- const end = buffer.offset;
2879
- buffer.reset();
2880
- const keyword = latin1Decoder.decode(buffer.readBytes(end - buffer.offset - 1));
2881
- buffer.skip(1);
2882
- validateKeyword(keyword);
2883
- return keyword;
2884
- }
2885
- function readLatin1(buffer, length) {
2886
- return latin1Decoder.decode(buffer.readBytes(length));
2887
- }
2888
-
2889
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/internal_types.js
2890
- var ColorType = {
2891
- UNKNOWN: -1,
2892
- GREYSCALE: 0,
2893
- TRUECOLOUR: 2,
2894
- INDEXED_COLOUR: 3,
2895
- GREYSCALE_ALPHA: 4,
2896
- TRUECOLOUR_ALPHA: 6
2897
- };
2898
- var CompressionMethod = {
2899
- UNKNOWN: -1,
2900
- DEFLATE: 0
2901
- };
2902
- var FilterMethod = {
2903
- UNKNOWN: -1,
2904
- ADAPTIVE: 0
2905
- };
2906
- var InterlaceMethod = {
2907
- UNKNOWN: -1,
2908
- NO_INTERLACE: 0,
2909
- ADAM7: 1
2910
- };
2911
- var DisposeOpType = {
2912
- NONE: 0,
2913
- BACKGROUND: 1,
2914
- PREVIOUS: 2
2915
- };
2916
- var BlendOpType = {
2917
- SOURCE: 0,
2918
- OVER: 1
2919
- };
2920
-
2921
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/png_decoder.js
2922
- var PngDecoder = class extends IOBuffer {
2923
- _checkCrc;
2924
- _inflator;
2925
- _png;
2926
- _apng;
2927
- _end;
2928
- _hasPalette;
2929
- _palette;
2930
- _hasTransparency;
2931
- _transparency;
2932
- _compressionMethod;
2933
- _filterMethod;
2934
- _interlaceMethod;
2935
- _colorType;
2936
- _isAnimated;
2937
- _numberOfFrames;
2938
- _numberOfPlays;
2939
- _frames;
2940
- _writingDataChunks;
2941
- _chunks;
2942
- _inflatorResult;
2943
- constructor(data, options = {}) {
2944
- super(data);
2945
- const { checkCrc: checkCrc2 = false } = options;
2946
- this._checkCrc = checkCrc2;
2947
- this._inflator = new Inflator((chunk, final) => {
2948
- this._chunks.push(chunk);
2949
- if (final) {
2950
- const totalLength = this._chunks.reduce((sum, c) => sum + c.length, 0);
2951
- this._inflatorResult = new Uint8Array(totalLength);
2952
- let offset = 0;
2953
- for (const chunk2 of this._chunks) {
2954
- this._inflatorResult.set(chunk2, offset);
2955
- offset += chunk2.length;
2956
- }
2957
- this._chunks = [];
2958
- }
2959
- });
2960
- this._chunks = [];
2961
- this._png = {
2962
- width: -1,
2963
- height: -1,
2964
- channels: -1,
2965
- data: new Uint8Array(0),
2966
- depth: 1,
2967
- text: {}
2968
- };
2969
- this._apng = {
2970
- width: -1,
2971
- height: -1,
2972
- channels: -1,
2973
- depth: 1,
2974
- numberOfFrames: 1,
2975
- numberOfPlays: 0,
2976
- text: {},
2977
- frames: []
2978
- };
2979
- this._end = false;
2980
- this._hasPalette = false;
2981
- this._palette = [];
2982
- this._hasTransparency = false;
2983
- this._transparency = new Uint16Array(0);
2984
- this._compressionMethod = CompressionMethod.UNKNOWN;
2985
- this._filterMethod = FilterMethod.UNKNOWN;
2986
- this._interlaceMethod = InterlaceMethod.UNKNOWN;
2987
- this._colorType = ColorType.UNKNOWN;
2988
- this._isAnimated = false;
2989
- this._numberOfFrames = 1;
2990
- this._numberOfPlays = 0;
2991
- this._frames = [];
2992
- this._writingDataChunks = false;
2993
- this._inflatorResult = new Uint8Array(0);
2994
- this.setBigEndian();
2995
- }
2996
- decode() {
2997
- checkSignature(this);
2998
- while (!this._end) {
2999
- const length = this.readUint32();
3000
- const type = this.readChars(4);
3001
- this.decodeChunk(length, type);
3002
- }
3003
- this._inflator.push(new Uint8Array(0), true);
3004
- this.decodeImage();
3005
- return this._png;
3006
- }
3007
- decodeApng() {
3008
- checkSignature(this);
3009
- while (!this._end) {
3010
- const length = this.readUint32();
3011
- const type = this.readChars(4);
3012
- this.decodeApngChunk(length, type);
3013
- }
3014
- this.decodeApngImage();
3015
- return this._apng;
3016
- }
3017
- // https://www.w3.org/TR/PNG/#5Chunk-layout
3018
- decodeChunk(length, type) {
3019
- const offset = this.offset;
3020
- switch (type) {
3021
- // 11.2 Critical chunks
3022
- case "IHDR":
3023
- this.decodeIHDR();
3024
- break;
3025
- case "PLTE":
3026
- this.decodePLTE(length);
3027
- break;
3028
- case "IDAT":
3029
- this.decodeIDAT(length);
3030
- break;
3031
- case "IEND":
3032
- this._end = true;
3033
- break;
3034
- // 11.3 Ancillary chunks
3035
- case "tRNS":
3036
- this.decodetRNS(length);
3037
- break;
3038
- case "iCCP":
3039
- this.decodeiCCP(length);
3040
- break;
3041
- case textChunkName:
3042
- decodetEXt(this._png.text, this, length);
3043
- break;
3044
- case "pHYs":
3045
- this.decodepHYs();
3046
- break;
3047
- default:
3048
- this.skip(length);
3049
- break;
3050
- }
3051
- if (this.offset - offset !== length) {
3052
- throw new Error(`Length mismatch while decoding chunk ${type}`);
3053
- }
3054
- if (this._checkCrc) {
3055
- checkCrc(this, length + 4, type);
3056
- } else {
3057
- this.skip(4);
3058
- }
3059
- }
3060
- decodeApngChunk(length, type) {
3061
- const offset = this.offset;
3062
- if (type !== "fdAT" && type !== "IDAT" && this._writingDataChunks) {
3063
- this.pushDataToFrame();
3064
- }
3065
- switch (type) {
3066
- case "acTL":
3067
- this.decodeACTL();
3068
- break;
3069
- case "fcTL":
3070
- this.decodeFCTL();
3071
- break;
3072
- case "fdAT":
3073
- this.decodeFDAT(length);
3074
- break;
3075
- default:
3076
- this.decodeChunk(length, type);
3077
- this.offset = offset + length;
3078
- break;
3079
- }
3080
- if (this.offset - offset !== length) {
3081
- throw new Error(`Length mismatch while decoding chunk ${type}`);
3082
- }
3083
- if (this._checkCrc) {
3084
- checkCrc(this, length + 4, type);
3085
- } else {
3086
- this.skip(4);
3087
- }
3088
- }
3089
- // https://www.w3.org/TR/PNG/#11IHDR
3090
- decodeIHDR() {
3091
- const image = this._png;
3092
- image.width = this.readUint32();
3093
- image.height = this.readUint32();
3094
- image.depth = checkBitDepth(this.readUint8());
3095
- const colorType = this.readUint8();
3096
- this._colorType = colorType;
3097
- let channels;
3098
- switch (colorType) {
3099
- case ColorType.GREYSCALE:
3100
- channels = 1;
3101
- break;
3102
- case ColorType.TRUECOLOUR:
3103
- channels = 3;
3104
- break;
3105
- case ColorType.INDEXED_COLOUR:
3106
- channels = 1;
3107
- break;
3108
- case ColorType.GREYSCALE_ALPHA:
3109
- channels = 2;
3110
- break;
3111
- case ColorType.TRUECOLOUR_ALPHA:
3112
- channels = 4;
3113
- break;
3114
- // Kept for exhaustiveness.
3115
- // eslint-disable-next-line unicorn/no-useless-switch-case
3116
- case ColorType.UNKNOWN:
3117
- default:
3118
- throw new Error(`Unknown color type: ${colorType}`);
3119
- }
3120
- this._png.channels = channels;
3121
- this._compressionMethod = this.readUint8();
3122
- if (this._compressionMethod !== CompressionMethod.DEFLATE) {
3123
- throw new Error(`Unsupported compression method: ${this._compressionMethod}`);
3124
- }
3125
- this._filterMethod = this.readUint8();
3126
- this._interlaceMethod = this.readUint8();
3127
- }
3128
- decodeACTL() {
3129
- this._numberOfFrames = this.readUint32();
3130
- this._numberOfPlays = this.readUint32();
3131
- this._isAnimated = true;
3132
- }
3133
- decodeFCTL() {
3134
- const image = {
3135
- sequenceNumber: this.readUint32(),
3136
- width: this.readUint32(),
3137
- height: this.readUint32(),
3138
- xOffset: this.readUint32(),
3139
- yOffset: this.readUint32(),
3140
- delayNumber: this.readUint16(),
3141
- delayDenominator: this.readUint16(),
3142
- disposeOp: this.readUint8(),
3143
- blendOp: this.readUint8(),
3144
- data: new Uint8Array(0)
3145
- };
3146
- this._frames.push(image);
3147
- }
3148
- // https://www.w3.org/TR/PNG/#11PLTE
3149
- decodePLTE(length) {
3150
- if (length % 3 !== 0) {
3151
- throw new RangeError(`PLTE field length must be a multiple of 3. Got ${length}`);
3152
- }
3153
- const l = length / 3;
3154
- this._hasPalette = true;
3155
- const palette = [];
3156
- this._palette = palette;
3157
- for (let i = 0; i < l; i++) {
3158
- palette.push([this.readUint8(), this.readUint8(), this.readUint8()]);
3159
- }
3160
- }
3161
- // https://www.w3.org/TR/PNG/#11IDAT
3162
- decodeIDAT(length) {
3163
- this._writingDataChunks = true;
3164
- const dataLength = length;
3165
- const dataOffset = this.offset + this.byteOffset;
3166
- try {
3167
- this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength), false);
3168
- } catch (error) {
3169
- throw new Error("Error while decompressing the data:", { cause: error });
3170
- }
3171
- this.skip(length);
3172
- }
3173
- decodeFDAT(length) {
3174
- this._writingDataChunks = true;
3175
- let dataLength = length;
3176
- let dataOffset = this.offset + this.byteOffset;
3177
- dataOffset += 4;
3178
- dataLength -= 4;
3179
- try {
3180
- this._inflator.push(new Uint8Array(this.buffer, dataOffset, dataLength), false);
3181
- } catch (error) {
3182
- throw new Error("Error while decompressing the data:", { cause: error });
3183
- }
3184
- this.skip(length);
3185
- }
3186
- // https://www.w3.org/TR/PNG/#11tRNS
3187
- decodetRNS(length) {
3188
- switch (this._colorType) {
3189
- case ColorType.GREYSCALE:
3190
- case ColorType.TRUECOLOUR: {
3191
- if (length % 2 !== 0) {
3192
- throw new RangeError(`tRNS chunk length must be a multiple of 2. Got ${length}`);
3193
- }
3194
- if (length / 2 > this._png.width * this._png.height) {
3195
- throw new Error(`tRNS chunk contains more alpha values than there are pixels (${length / 2} vs ${this._png.width * this._png.height})`);
3196
- }
3197
- this._hasTransparency = true;
3198
- this._transparency = new Uint16Array(length / 2);
3199
- for (let i = 0; i < length / 2; i++) {
3200
- this._transparency[i] = this.readUint16();
3201
- }
3202
- break;
3203
- }
3204
- case ColorType.INDEXED_COLOUR: {
3205
- if (length > this._palette.length) {
3206
- throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${length} vs ${this._palette.length})`);
3207
- }
3208
- let i = 0;
3209
- for (; i < length; i++) {
3210
- const alpha = this.readByte();
3211
- this._palette[i].push(alpha);
3212
- }
3213
- for (; i < this._palette.length; i++) {
3214
- this._palette[i].push(255);
3215
- }
3216
- break;
3217
- }
3218
- // Kept for exhaustiveness.
3219
- /* eslint-disable unicorn/no-useless-switch-case */
3220
- case ColorType.UNKNOWN:
3221
- case ColorType.GREYSCALE_ALPHA:
3222
- case ColorType.TRUECOLOUR_ALPHA:
3223
- default: {
3224
- throw new Error(`tRNS chunk is not supported for color type ${this._colorType}`);
3225
- }
3226
- }
3227
- }
3228
- // https://www.w3.org/TR/PNG/#11iCCP
3229
- decodeiCCP(length) {
3230
- const name = readKeyword(this);
3231
- const compressionMethod = this.readUint8();
3232
- if (compressionMethod !== CompressionMethod.DEFLATE) {
3233
- throw new Error(`Unsupported iCCP compression method: ${compressionMethod}`);
3234
- }
3235
- const compressedProfile = this.readBytes(length - name.length - 2);
3236
- this._png.iccEmbeddedProfile = {
3237
- name,
3238
- profile: unzlibSync(compressedProfile)
3239
- };
3240
- }
3241
- // https://www.w3.org/TR/PNG/#11pHYs
3242
- decodepHYs() {
3243
- const ppuX = this.readUint32();
3244
- const ppuY = this.readUint32();
3245
- const unitSpecifier = this.readByte();
3246
- this._png.resolution = {
3247
- x: ppuX,
3248
- y: ppuY,
3249
- unit: unitSpecifier
3250
- };
3251
- }
3252
- decodeApngImage() {
3253
- this._apng.width = this._png.width;
3254
- this._apng.height = this._png.height;
3255
- this._apng.channels = this._png.channels;
3256
- this._apng.depth = this._png.depth;
3257
- this._apng.numberOfFrames = this._numberOfFrames;
3258
- this._apng.numberOfPlays = this._numberOfPlays;
3259
- this._apng.text = this._png.text;
3260
- this._apng.resolution = this._png.resolution;
3261
- for (let i = 0; i < this._numberOfFrames; i++) {
3262
- const newFrame = {
3263
- sequenceNumber: this._frames[i].sequenceNumber,
3264
- delayNumber: this._frames[i].delayNumber,
3265
- delayDenominator: this._frames[i].delayDenominator,
3266
- data: this._apng.depth === 8 ? new Uint8Array(this._apng.width * this._apng.height * this._apng.channels) : new Uint16Array(this._apng.width * this._apng.height * this._apng.channels)
3267
- };
3268
- const frame = this._frames.at(i);
3269
- if (frame) {
3270
- frame.data = decodeInterlaceNull({
3271
- data: frame.data,
3272
- width: frame.width,
3273
- height: frame.height,
3274
- channels: this._apng.channels,
3275
- depth: this._apng.depth
3276
- });
3277
- if (this._hasPalette) {
3278
- this._apng.palette = this._palette;
3279
- }
3280
- if (this._hasTransparency) {
3281
- this._apng.transparency = this._transparency;
3282
- }
3283
- if (i === 0 || frame.xOffset === 0 && frame.yOffset === 0 && frame.width === this._png.width && frame.height === this._png.height) {
3284
- newFrame.data = frame.data;
3285
- } else {
3286
- const prevFrame = this._apng.frames.at(i - 1);
3287
- this.disposeFrame(frame, prevFrame, newFrame);
3288
- this.addFrameDataToCanvas(newFrame, frame);
3289
- }
3290
- this._apng.frames.push(newFrame);
3291
- }
3292
- }
3293
- return this._apng;
3294
- }
3295
- disposeFrame(frame, prevFrame, imageFrame) {
3296
- switch (frame.disposeOp) {
3297
- case DisposeOpType.NONE:
3298
- break;
3299
- case DisposeOpType.BACKGROUND:
3300
- for (let row = 0; row < this._png.height; row++) {
3301
- for (let col = 0; col < this._png.width; col++) {
3302
- const index = (row * frame.width + col) * this._png.channels;
3303
- for (let channel = 0; channel < this._png.channels; channel++) {
3304
- imageFrame.data[index + channel] = 0;
3305
- }
3306
- }
3307
- }
3308
- break;
3309
- case DisposeOpType.PREVIOUS:
3310
- imageFrame.data.set(prevFrame.data);
3311
- break;
3312
- default:
3313
- throw new Error("Unknown disposeOp");
3314
- }
3315
- }
3316
- addFrameDataToCanvas(imageFrame, frame) {
3317
- const maxValue = 1 << this._png.depth;
3318
- const calculatePixelIndices = (row, col) => {
3319
- const index = ((row + frame.yOffset) * this._png.width + frame.xOffset + col) * this._png.channels;
3320
- const frameIndex = (row * frame.width + col) * this._png.channels;
3321
- return { index, frameIndex };
3322
- };
3323
- switch (frame.blendOp) {
3324
- case BlendOpType.SOURCE:
3325
- for (let row = 0; row < frame.height; row++) {
3326
- for (let col = 0; col < frame.width; col++) {
3327
- const { index, frameIndex } = calculatePixelIndices(row, col);
3328
- for (let channel = 0; channel < this._png.channels; channel++) {
3329
- imageFrame.data[index + channel] = frame.data[frameIndex + channel];
3330
- }
3331
- }
3332
- }
3333
- break;
3334
- // https://www.w3.org/TR/png-3/#13Alpha-channel-processing
3335
- case BlendOpType.OVER:
3336
- for (let row = 0; row < frame.height; row++) {
3337
- for (let col = 0; col < frame.width; col++) {
3338
- const { index, frameIndex } = calculatePixelIndices(row, col);
3339
- for (let channel = 0; channel < this._png.channels; channel++) {
3340
- const sourceAlpha = frame.data[frameIndex + this._png.channels - 1] / maxValue;
3341
- const foregroundValue = channel % (this._png.channels - 1) === 0 ? 1 : frame.data[frameIndex + channel];
3342
- const value = Math.floor(sourceAlpha * foregroundValue + (1 - sourceAlpha) * imageFrame.data[index + channel]);
3343
- imageFrame.data[index + channel] += value;
3344
- }
3345
- }
3346
- }
3347
- break;
3348
- default:
3349
- throw new Error("Unknown blendOp");
3350
- }
3351
- }
3352
- decodeImage() {
3353
- const data = this._inflatorResult;
3354
- if (this._filterMethod !== FilterMethod.ADAPTIVE) {
3355
- throw new Error(`Filter method ${this._filterMethod} not supported`);
3356
- }
3357
- if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {
3358
- this._png.data = decodeInterlaceNull({
3359
- data,
3360
- width: this._png.width,
3361
- height: this._png.height,
3362
- channels: this._png.channels,
3363
- depth: this._png.depth
3364
- });
3365
- } else if (this._interlaceMethod === InterlaceMethod.ADAM7) {
3366
- this._png.data = decodeInterlaceAdam7({
3367
- data,
3368
- width: this._png.width,
3369
- height: this._png.height,
3370
- channels: this._png.channels,
3371
- depth: this._png.depth
3372
- });
3373
- } else {
3374
- throw new Error(`Interlace method ${this._interlaceMethod} not supported`);
3375
- }
3376
- if (this._hasPalette) {
3377
- this._png.palette = this._palette;
3378
- }
3379
- if (this._hasTransparency) {
3380
- this._png.transparency = this._transparency;
3381
- }
3382
- }
3383
- pushDataToFrame() {
3384
- this._inflator.push(new Uint8Array(0), true);
3385
- const result = this._inflatorResult;
3386
- const lastFrame = this._frames.at(-1);
3387
- if (lastFrame) {
3388
- lastFrame.data = result;
3389
- } else {
3390
- this._frames.push({
3391
- sequenceNumber: 0,
3392
- width: this._png.width,
3393
- height: this._png.height,
3394
- xOffset: 0,
3395
- yOffset: 0,
3396
- delayNumber: 0,
3397
- delayDenominator: 0,
3398
- disposeOp: DisposeOpType.NONE,
3399
- blendOp: BlendOpType.SOURCE,
3400
- data: result
3401
- });
3402
- }
3403
- this._inflator = new Inflator((chunk, final) => {
3404
- this._chunks.push(chunk);
3405
- if (final) {
3406
- const totalLength = this._chunks.reduce((sum, c) => sum + c.length, 0);
3407
- this._inflatorResult = new Uint8Array(totalLength);
3408
- let offset = 0;
3409
- for (const chunk2 of this._chunks) {
3410
- this._inflatorResult.set(chunk2, offset);
3411
- offset += chunk2.length;
3412
- }
3413
- this._chunks = [];
3414
- }
3415
- });
3416
- this._chunks = [];
3417
- this._writingDataChunks = false;
3418
- }
3419
- };
3420
- function checkBitDepth(value) {
3421
- if (value !== 1 && value !== 2 && value !== 4 && value !== 8 && value !== 16) {
3422
- throw new Error(`invalid bit depth: ${value}`);
3423
- }
3424
- return value;
3425
- }
3426
-
3427
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/png_encoder.js
3428
- import { zlibSync } from "fflate";
3429
- var defaultZlibOptions = {
3430
- level: 3
3431
- };
3432
- var PngEncoder = class extends IOBuffer {
3433
- _png;
3434
- _zlibOptions;
3435
- _colorType;
3436
- _interlaceMethod;
3437
- constructor(data, options = {}) {
3438
- super();
3439
- this._colorType = ColorType.UNKNOWN;
3440
- this._zlibOptions = { ...defaultZlibOptions, ...options.zlib };
3441
- this._png = this._checkData(data);
3442
- this._interlaceMethod = (options.interlace === "Adam7" ? InterlaceMethod.ADAM7 : InterlaceMethod.NO_INTERLACE) ?? InterlaceMethod.NO_INTERLACE;
3443
- this.setBigEndian();
3444
- }
3445
- encode() {
3446
- writeSignature(this);
3447
- this.encodeIHDR();
3448
- if (this._png.palette) {
3449
- this.encodePLTE();
3450
- if (this._png.palette[0].length === 4) {
3451
- this.encodeTRNS();
3452
- }
3453
- }
3454
- this.encodeData();
3455
- if (this._png.text) {
3456
- for (const [keyword, text] of Object.entries(this._png.text)) {
3457
- encodetEXt(this, keyword, text);
3458
- }
3459
- }
3460
- this.encodeIEND();
3461
- return this.toArray();
3462
- }
3463
- // https://www.w3.org/TR/PNG/#11IHDR
3464
- encodeIHDR() {
3465
- this.writeUint32(13);
3466
- this.writeChars("IHDR");
3467
- this.writeUint32(this._png.width);
3468
- this.writeUint32(this._png.height);
3469
- this.writeByte(this._png.depth);
3470
- this.writeByte(this._colorType);
3471
- this.writeByte(CompressionMethod.DEFLATE);
3472
- this.writeByte(FilterMethod.ADAPTIVE);
3473
- this.writeByte(this._interlaceMethod);
3474
- writeCrc(this, 17);
3475
- }
3476
- // https://www.w3.org/TR/PNG/#11IEND
3477
- encodeIEND() {
3478
- this.writeUint32(0);
3479
- this.writeChars("IEND");
3480
- writeCrc(this, 4);
3481
- }
3482
- encodePLTE() {
3483
- const paletteLength = this._png.palette?.length * 3;
3484
- this.writeUint32(paletteLength);
3485
- this.writeChars("PLTE");
3486
- for (const color of this._png.palette) {
3487
- this.writeByte(color[0]);
3488
- this.writeByte(color[1]);
3489
- this.writeByte(color[2]);
3490
- }
3491
- writeCrc(this, 4 + paletteLength);
3492
- }
3493
- encodeTRNS() {
3494
- const alpha = this._png.palette.filter((color) => {
3495
- return color.at(-1) !== 255;
3496
- });
3497
- this.writeUint32(alpha.length);
3498
- this.writeChars("tRNS");
3499
- for (const el of alpha) {
3500
- this.writeByte(el.at(-1));
3501
- }
3502
- writeCrc(this, 4 + alpha.length);
3503
- }
3504
- // https://www.w3.org/TR/PNG/#11IDAT
3505
- encodeIDAT(data) {
3506
- this.writeUint32(data.length);
3507
- this.writeChars("IDAT");
3508
- this.writeBytes(data);
3509
- writeCrc(this, data.length + 4);
3510
- }
3511
- encodeData() {
3512
- const { width, height, channels, depth, data } = this._png;
3513
- const slotsPerLine = depth <= 8 ? Math.ceil(width * depth / 8) * channels : Math.ceil(width * depth / 8 * channels / 2);
3514
- const newData = new IOBuffer().setBigEndian();
3515
- let offset = 0;
3516
- if (this._interlaceMethod === InterlaceMethod.NO_INTERLACE) {
3517
- for (let i = 0; i < height; i++) {
3518
- newData.writeByte(0);
3519
- if (depth === 16) {
3520
- offset = writeDataUint16(data, newData, slotsPerLine, offset);
3521
- } else {
3522
- offset = writeDataBytes(data, newData, slotsPerLine, offset);
3523
- }
3524
- }
3525
- } else if (this._interlaceMethod === InterlaceMethod.ADAM7) {
3526
- offset = writeDataInterlaced(this._png, data, newData, offset);
3527
- }
3528
- const buffer = newData.toArray();
3529
- const compressed = zlibSync(buffer, this._zlibOptions);
3530
- this.encodeIDAT(compressed);
3531
- }
3532
- _checkData(data) {
3533
- const { colorType, channels, depth } = getColorType(data, data.palette);
3534
- const png = {
3535
- width: checkInteger(data.width, "width"),
3536
- height: checkInteger(data.height, "height"),
3537
- channels,
3538
- data: data.data,
3539
- depth,
3540
- text: data.text,
3541
- palette: data.palette
3542
- };
3543
- this._colorType = colorType;
3544
- const expectedSize = depth < 8 ? Math.ceil(png.width * depth / 8) * png.height * channels : png.width * png.height * channels;
3545
- if (png.data.length !== expectedSize) {
3546
- throw new RangeError(`wrong data size. Found ${png.data.length}, expected ${expectedSize}`);
3547
- }
3548
- return png;
3549
- }
3550
- };
3551
- function checkInteger(value, name) {
3552
- if (Number.isInteger(value) && value > 0) {
3553
- return value;
3554
- }
3555
- throw new TypeError(`${name} must be a positive integer`);
3556
- }
3557
- function getColorType(data, palette) {
3558
- const { channels = 4, depth = 8 } = data;
3559
- if (channels !== 4 && channels !== 3 && channels !== 2 && channels !== 1) {
3560
- throw new RangeError(`unsupported number of channels: ${channels}`);
3561
- }
3562
- const returnValue = {
3563
- channels,
3564
- depth,
3565
- colorType: ColorType.UNKNOWN
3566
- };
3567
- switch (channels) {
3568
- case 4:
3569
- returnValue.colorType = ColorType.TRUECOLOUR_ALPHA;
3570
- break;
3571
- case 3:
3572
- returnValue.colorType = ColorType.TRUECOLOUR;
3573
- break;
3574
- case 1:
3575
- if (palette) {
3576
- returnValue.colorType = ColorType.INDEXED_COLOUR;
3577
- } else {
3578
- returnValue.colorType = ColorType.GREYSCALE;
3579
- }
3580
- break;
3581
- case 2:
3582
- returnValue.colorType = ColorType.GREYSCALE_ALPHA;
3583
- break;
3584
- default:
3585
- throw new Error("unsupported number of channels");
3586
- }
3587
- return returnValue;
3588
- }
3589
- function writeDataBytes(data, newData, slotsPerLine, offset) {
3590
- for (let j = 0; j < slotsPerLine; j++) {
3591
- newData.writeByte(data[offset++]);
3592
- }
3593
- return offset;
3594
- }
3595
- function writeDataInterlaced(imageData, data, newData, offset) {
3596
- const passes = [
3597
- { x: 0, y: 0, xStep: 8, yStep: 8 },
3598
- { x: 4, y: 0, xStep: 8, yStep: 8 },
3599
- { x: 0, y: 4, xStep: 4, yStep: 8 },
3600
- { x: 2, y: 0, xStep: 4, yStep: 4 },
3601
- { x: 0, y: 2, xStep: 2, yStep: 4 },
3602
- { x: 1, y: 0, xStep: 2, yStep: 2 },
3603
- { x: 0, y: 1, xStep: 1, yStep: 2 }
3604
- ];
3605
- const { width, height, channels, depth } = imageData;
3606
- let pixelSize;
3607
- if (depth === 16) {
3608
- pixelSize = channels * depth / 8 / 2;
3609
- } else {
3610
- pixelSize = channels * depth / 8;
3611
- }
3612
- for (let passIndex = 0; passIndex < 7; passIndex++) {
3613
- const pass = passes[passIndex];
3614
- const passWidth = Math.floor((width - pass.x + pass.xStep - 1) / pass.xStep);
3615
- const passHeight = Math.floor((height - pass.y + pass.yStep - 1) / pass.yStep);
3616
- if (passWidth <= 0 || passHeight <= 0)
3617
- continue;
3618
- const passLineBytes = passWidth * pixelSize;
3619
- for (let y = 0; y < passHeight; y++) {
3620
- const imageY = pass.y + y * pass.yStep;
3621
- const rawScanline = depth <= 8 ? new Uint8Array(passLineBytes) : new Uint16Array(passLineBytes);
3622
- let rawOffset = 0;
3623
- for (let x = 0; x < passWidth; x++) {
3624
- const imageX = pass.x + x * pass.xStep;
3625
- if (imageX < width && imageY < height) {
3626
- const srcPos = (imageY * width + imageX) * pixelSize;
3627
- for (let i = 0; i < pixelSize; i++) {
3628
- rawScanline[rawOffset++] = data[srcPos + i];
3629
- }
3630
- }
3631
- }
3632
- newData.writeByte(0);
3633
- if (depth === 8) {
3634
- newData.writeBytes(rawScanline);
3635
- } else if (depth === 16) {
3636
- for (const value of rawScanline) {
3637
- newData.writeByte(value >> 8 & 255);
3638
- newData.writeByte(value & 255);
3639
- }
3640
- }
3641
- }
3642
- }
3643
- return offset;
3644
- }
3645
- function writeDataUint16(data, newData, slotsPerLine, offset) {
3646
- for (let j = 0; j < slotsPerLine; j++) {
3647
- newData.writeUint16(data[offset++]);
3648
- }
3649
- return offset;
3650
- }
3651
-
3652
- // node_modules/.pnpm/fast-png@8.0.0/node_modules/fast-png/lib/index.js
3653
- function decodePng(data, options) {
3654
- const decoder = new PngDecoder(data, options);
3655
- return decoder.decode();
3656
- }
3657
- function encodePng(png, options) {
3658
- const encoder2 = new PngEncoder(png, options);
3659
- return encoder2.encode();
3660
- }
3661
-
3662
1879
  export {
3663
1880
  getRenderBackground,
3664
1881
  withRenderContext,
@@ -3671,9 +1888,6 @@ export {
3671
1888
  CHART_FRAME_COMPONENT,
3672
1889
  isCanvasChart,
3673
1890
  CanvasChartFit,
3674
- convertIndexedToRgb,
3675
- decodePng,
3676
- encodePng,
3677
1891
  normalizeWatermark,
3678
1892
  Watermark,
3679
1893
  wrapWithWatermark,