UNPKG

koishi-plugin-image-tools

Version:
2,064 lines (2,047 loc) 1.13 MB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name2 in all) __defProp(target, name2, { get: all[name2], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.tsx var src_exports = {}; __export(src_exports, { Config: () => Config, apply: () => apply, errorHandle: () => errorHandle, inject: () => inject, name: () => name }); module.exports = __toCommonJS(src_exports); var import_node_fs2 = require("node:fs"); var import_promises2 = require("node:fs/promises"); var import_node_path2 = __toESM(require("node:path")); var import_node_url = require("node:url"); var import_koishi2 = require("koishi"); // ../../node_modules/image-in-browser/lib/common/math-utils.js var MathUtils = class _MathUtils { static { __name(this, "MathUtils"); } static fract(x) { return x - Math.floor(x); } static smoothStep(edge0, edge1, x) { const t0 = (x - edge0) / (edge1 - edge0); const t = _MathUtils.clamp(t0, 0, 1); return t * t * (3 - 2 * t); } static mix(x, y, a) { return x * (1 - a) + y * a; } static sign(x) { return x < 0 ? -1 : x > 0 ? 1 : 0; } static step(edge, x) { return x < edge ? 0 : 1; } static length3(x, y, z) { return Math.sqrt(x * x + y * y + z * z); } static gcd(x, y) { let _x = Math.abs(x); let _y = Math.abs(y); while (_y) { const t = _y; _y = _x % _y; _x = t; } return _x; } static clamp(num, low, high) { return Math.max(low, Math.min(num, high)); } static clampInt(num, low, high) { return Math.trunc(_MathUtils.clamp(num, low, high)); } static clampInt255(num) { return Math.trunc(_MathUtils.clamp(num, 0, 255)); } }; // ../../node_modules/image-in-browser/lib/error/lib-error.js var LibError = class extends Error { static { __name(this, "LibError"); } toString() { return `${this.constructor.name} (${this.message})`; } }; // ../../node_modules/image-in-browser/lib/color/format.js var Format; (function(Format2) { Format2[Format2["uint1"] = 0] = "uint1"; Format2[Format2["uint2"] = 1] = "uint2"; Format2[Format2["uint4"] = 2] = "uint4"; Format2[Format2["uint8"] = 3] = "uint8"; Format2[Format2["uint16"] = 4] = "uint16"; Format2[Format2["uint32"] = 5] = "uint32"; Format2[Format2["int8"] = 6] = "int8"; Format2[Format2["int16"] = 7] = "int16"; Format2[Format2["int32"] = 8] = "int32"; Format2[Format2["float16"] = 9] = "float16"; Format2[Format2["float32"] = 10] = "float32"; Format2[Format2["float64"] = 11] = "float64"; })(Format || (Format = {})); var FormatType; (function(FormatType2) { FormatType2[FormatType2["uint"] = 0] = "uint"; FormatType2[FormatType2["int"] = 1] = "int"; FormatType2[FormatType2["float"] = 2] = "float"; })(FormatType || (FormatType = {})); var FormatToFormatType = /* @__PURE__ */ new Map([ [Format.uint1, FormatType.uint], [Format.uint2, FormatType.uint], [Format.uint4, FormatType.uint], [Format.uint8, FormatType.uint], [Format.uint16, FormatType.uint], [Format.uint32, FormatType.uint], [Format.int8, FormatType.int], [Format.int16, FormatType.int], [Format.int32, FormatType.int], [Format.float16, FormatType.float], [Format.float32, FormatType.float], [Format.float64, FormatType.float] ]); var FormatSize = /* @__PURE__ */ new Map([ [Format.uint1, 1], [Format.uint2, 1], [Format.uint4, 1], [Format.uint8, 1], [Format.uint16, 2], [Format.uint32, 4], [Format.int8, 1], [Format.int16, 2], [Format.int32, 4], [Format.float16, 2], [Format.float32, 4], [Format.float64, 8] ]); var FormatMaxValue = /* @__PURE__ */ new Map([ [Format.uint1, 1], [Format.uint2, 3], [Format.uint4, 15], [Format.uint8, 255], [Format.uint16, 65535], [Format.uint32, 4294967295], [Format.int8, 127], [Format.int16, 32767], [Format.int32, 2147483647], [Format.float16, 1], [Format.float32, 1], [Format.float64, 1] ]); function getRowStride(width, numChannels, format) { return format === Format.uint1 ? Math.ceil(width * numChannels / 8) : format === Format.uint2 ? Math.ceil(width * numChannels / 4) : format === Format.uint4 ? Math.ceil(width * numChannels / 2) : width * numChannels * FormatSize.get(format); } __name(getRowStride, "getRowStride"); function convertFormatValue(value, from, to) { if (from === to) { return value; } switch (from) { case Format.uint1: return value === 0 ? 0 : FormatMaxValue.get(to); case Format.uint2: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return value; case Format.uint4: return value * 5; case Format.uint8: return value * 75; case Format.uint16: return value * 21845; case Format.uint32: return value * 1431655765; case Format.int8: return value * 42; case Format.int16: return value * 10922; case Format.int32: return value * 715827882; case Format.float16: case Format.float32: case Format.float64: return value / 3; } break; case Format.uint4: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return Math.trunc(value) >>> 1; case Format.uint4: return value; case Format.uint8: return value * 17; case Format.uint16: return value * 4369; case Format.uint32: return value * 286331153; case Format.int8: return value * 8; case Format.int16: return value * 2184; case Format.int32: return value * 143165576; case Format.float16: case Format.float32: case Format.float64: return value / 3; } break; case Format.uint8: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return Math.trunc(value) >>> 6; case Format.uint4: return Math.trunc(value) >>> 4; case Format.uint8: return value; case Format.uint16: return value * 257; case Format.uint32: return value * 16843009; case Format.int8: return Math.trunc(value) >>> 1; case Format.int16: return value * 128; case Format.int32: return value * 8421504; case Format.float16: case Format.float32: case Format.float64: return value / 255; } break; case Format.uint16: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return Math.trunc(value) >>> 14; case Format.uint4: return Math.trunc(value) >>> 12; case Format.uint8: return Math.trunc(value) >>> 8; case Format.uint16: return value; case Format.uint32: return Math.trunc(value) << 8; case Format.int8: return Math.trunc(value) >>> 9; case Format.int16: return Math.trunc(value) >>> 1; case Format.int32: return value * 524296; case Format.float16: case Format.float32: case Format.float64: return value / 65535; } break; case Format.uint32: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return Math.trunc(value) >>> 30; case Format.uint4: return Math.trunc(value) >>> 28; case Format.uint8: return Math.trunc(value) >>> 24; case Format.uint16: return Math.trunc(value) >>> 16; case Format.uint32: return value; case Format.int8: return Math.trunc(value) >>> 25; case Format.int16: return Math.trunc(value) >>> 17; case Format.int32: return Math.trunc(value) >>> 1; case Format.float16: case Format.float32: case Format.float64: return value / 4294967295; } break; case Format.int8: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return value <= 0 ? 0 : Math.trunc(value) >>> 5; case Format.uint4: return value <= 0 ? 0 : Math.trunc(value) >>> 3; case Format.uint8: return value <= 0 ? 0 : Math.trunc(value) << 1; case Format.uint16: return value <= 0 ? 0 : Math.trunc(value) * 516; case Format.uint32: return value <= 0 ? 0 : Math.trunc(value) * 33818640; case Format.int8: return value; case Format.int16: return value * 258; case Format.int32: return value * 16909320; case Format.float16: case Format.float32: case Format.float64: return value / 127; } break; case Format.int16: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return value <= 0 ? 0 : Math.trunc(value) >>> 15; case Format.uint4: return value <= 0 ? 0 : Math.trunc(value) >>> 11; case Format.uint8: return value <= 0 ? 0 : Math.trunc(value) >>> 7; case Format.uint16: return value <= 0 ? 0 : Math.trunc(value) << 1; case Format.uint32: return value <= 0 ? 0 : Math.trunc(value) * 131076; case Format.int8: return Math.trunc(value) >>> 8; case Format.int16: return value; case Format.int32: return Math.trunc(value) * 65538; case Format.float16: case Format.float32: case Format.float64: return value / 32767; } break; case Format.int32: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return value <= 0 ? 0 : Math.trunc(value) >>> 29; case Format.uint4: return value <= 0 ? 0 : Math.trunc(value) >>> 27; case Format.uint8: return value <= 0 ? 0 : Math.trunc(value) >>> 23; case Format.uint16: return value <= 0 ? 0 : Math.trunc(value) >>> 16; case Format.uint32: return value <= 0 ? 0 : Math.trunc(value) << 1; case Format.int8: return Math.trunc(value) >>> 24; case Format.int16: return Math.trunc(value) >>> 16; case Format.int32: return value; case Format.float16: case Format.float32: case Format.float64: return value / 2147483647; } break; case Format.float16: case Format.float32: case Format.float64: switch (to) { case Format.uint1: return value === 0 ? 0 : 1; case Format.uint2: return Math.trunc(MathUtils.clamp(value, 0, 1) * 3); case Format.uint4: return Math.trunc(MathUtils.clamp(value, 0, 1) * 15); case Format.uint8: return Math.trunc(MathUtils.clamp(value, 0, 1) * 255); case Format.uint16: return Math.trunc(MathUtils.clamp(value, 0, 1) * 65535); case Format.uint32: return Math.trunc(MathUtils.clamp(value, 0, 1) * 4294967295); case Format.int8: return Math.trunc(value < 0 ? MathUtils.clamp(value, -1, 1) * 128 : MathUtils.clamp(value, -1, 1) * 127); case Format.int16: return Math.trunc(value < 0 ? MathUtils.clamp(value, -1, 1) * 32768 : MathUtils.clamp(value, -1, 1) * 32767); case Format.int32: return Math.trunc(value < 0 ? MathUtils.clamp(value, -1, 1) * 2147483648 : MathUtils.clamp(value, -1, 1) * 2147483647); case Format.float16: case Format.float32: case Format.float64: return value; } break; } throw new LibError("Unknown format."); } __name(convertFormatValue, "convertFormatValue"); // ../../node_modules/image-in-browser/lib/common/rational.js var Rational = class { static { __name(this, "Rational"); } get numerator() { return this._numerator; } get denominator() { return this._denominator; } get toInt() { return this.denominator !== 0 ? Math.trunc(this.numerator / this.denominator) : 0; } get toDouble() { return this.denominator !== 0 ? this.numerator / this.denominator : 0; } constructor(numerator, denominator) { this._numerator = numerator; this._denominator = denominator; } simplify() { const d = MathUtils.gcd(this.numerator, this.denominator); if (d !== 0) { this._numerator = Math.trunc(this.numerator / d); this._denominator = Math.trunc(this.denominator / d); } } equals(other) { return this._numerator === other._numerator && this._denominator === other._denominator; } toString() { return `${this.constructor.name} (${this._numerator}/${this._denominator})`; } }; // ../../node_modules/image-in-browser/lib/common/array-utils.js var ArrayUtils = class _ArrayUtils { static { __name(this, "ArrayUtils"); } static copyInt8(from, begin, end) { return Int8Array.from(from.subarray(begin, end)); } static copyUint8(from, begin, end) { return Uint8Array.from(from.subarray(begin, end)); } static copyInt16(from, begin, end) { return Int16Array.from(from.subarray(begin, end)); } static copyUint16(from, begin, end) { return Uint16Array.from(from.subarray(begin, end)); } static copyInt32(from, begin, end) { return Int32Array.from(from.subarray(begin, end)); } static copyUint32(from, begin, end) { return Uint32Array.from(from.subarray(begin, end)); } static copyFloat32(from, begin, end) { return Float32Array.from(from.subarray(begin, end)); } static copyFloat64(from, begin, end) { return Float64Array.from(from.subarray(begin, end)); } static copy(from, begin, end) { if (from instanceof Int8Array) { return _ArrayUtils.copyInt8(from, begin, end); } else if (from instanceof Uint8Array) { return _ArrayUtils.copyUint8(from, begin, end); } else if (from instanceof Int16Array) { return _ArrayUtils.copyInt16(from, begin, end); } else if (from instanceof Uint16Array) { return _ArrayUtils.copyUint16(from, begin, end); } else if (from instanceof Int32Array) { return _ArrayUtils.copyInt32(from, begin, end); } else if (from instanceof Uint32Array) { return _ArrayUtils.copyUint32(from, begin, end); } else if (from instanceof Float32Array) { return _ArrayUtils.copyFloat32(from, begin, end); } else if (from instanceof Float64Array) { return _ArrayUtils.copyFloat64(from, begin, end); } throw new LibError("Unknown array type"); } static copyRange(from, fromStart, to, toStart, length) { const viewFrom = from.subarray(fromStart, fromStart + length); to.set(viewFrom, toStart); } static fill(length, value) { const a = new Array(length); return a.fill(value); } static generate(length, func) { const a = new Array(length); for (let i = 0; i < length; ++i) { a[i] = func(i); } return a; } static equals(a1, a2) { if (a1 === a2) return true; if (a1.length !== a2.length) return false; for (let i = 0, l = a1.length; i < l; i++) { if (_ArrayUtils.isNumArrayOrTypedArray(a1[i]) && _ArrayUtils.isNumArrayOrTypedArray(a2[i])) { if (!_ArrayUtils.equals(a1[i], a2[i])) return false; } else if (a1[i] !== a2[i]) { return false; } } return true; } static equalsRationalArray(a1, a2) { if (a1 === a2) return true; if (a1.length !== a2.length) return false; for (let i = 0, l = a1.length; i < l; i++) { if (!a1[i].equals(a2[i])) { return false; } } return true; } static getNumEnumValues(t) { return Object.values(t).filter((v) => typeof v === "number"); } static isNumArrayOrTypedArray(obj) { return Boolean(obj && typeof obj === "object" && (Array.isArray(obj) && obj.every((v) => typeof v === "number") || ArrayBuffer.isView(obj) && !(obj instanceof DataView))); } static isArrayOfRational(obj) { return Boolean(obj && typeof obj === "object" && Array.isArray(obj) && obj.every((v) => v instanceof Rational)); } }; // ../../node_modules/image-in-browser/lib/common/bit-utils.js var BitUtils = class { static { __name(this, "BitUtils"); } static countTrailingZeroBits(v) { let c = 32; const _v = v & -v; if (_v !== 0) c--; if ((_v & 65535) !== 0) c -= 16; if ((_v & 16711935) !== 0) c -= 8; if ((_v & 252645135) !== 0) c -= 4; if ((_v & 858993459) !== 0) c -= 2; if ((_v & 1431655765) !== 0) c -= 1; return c; } static reverseByte(x) { return this._reverseByteTable[x]; } static sshR(v, n) { return v >> n; } static ushR(v, n) { return v >>> n; } static sshL(v, n) { return v << n; } static ushL(v, n) { return v << n >>> 0; } static uint8ToInt8(d) { this._uint8[0] = d; return this._uint8ToInt8[0]; } static int8ToUint8(d) { this._int8[0] = d; return this._int8ToUint8[0]; } static uint16ToInt16(d) { this._uint16[0] = d; return this._uint16ToInt16[0]; } static int16ToUint16(d) { this._int16[0] = d; return this._int16ToUint16[0]; } static uint32ToInt32(d) { this._uint32[0] = d; return this._uint32ToInt32[0]; } static uint32ToFloat32(d) { this._uint32[0] = d; return this._uint32ToFloat32[0]; } static uint64ToFloat64(d) { this._uint64[0] = d; return this._uint64ToFloat64[0]; } static int32ToUint32(d) { this._int32[0] = d; return this._int32ToUint32[0]; } static float32ToUint32(d) { this._float32[0] = d; return this._float32ToUint32[0]; } static debugBits32(value) { if (value === void 0) { return "undefined"; } const bitCount = 32; let result = ""; for (let i = bitCount; i > -1; i--) { result += (value & 1 << i) === 0 ? "0" : "1"; } return result; } }; BitUtils._uint8 = new Uint8Array(1); BitUtils._uint8ToInt8 = new Int8Array(BitUtils._uint8.buffer); BitUtils._int8 = new Int8Array(1); BitUtils._int8ToUint8 = new Uint8Array(BitUtils._int8.buffer); BitUtils._uint16 = new Uint16Array(1); BitUtils._uint16ToInt16 = new Int16Array(BitUtils._uint16.buffer); BitUtils._int16 = new Int16Array(1); BitUtils._int16ToUint16 = new Uint16Array(BitUtils._int16.buffer); BitUtils._uint32 = new Uint32Array(1); BitUtils._uint32ToInt32 = new Int32Array(BitUtils._uint32.buffer); BitUtils._uint32ToFloat32 = new Float32Array(BitUtils._uint32.buffer); BitUtils._int32 = new Int32Array(1); BitUtils._int32ToUint32 = new Uint32Array(BitUtils._int32.buffer); BitUtils._float32 = new Float32Array(1); BitUtils._float32ToUint32 = new Uint32Array(BitUtils._float32.buffer); BitUtils._uint64 = new BigUint64Array(1); BitUtils._uint64ToFloat64 = new Float64Array(BitUtils._uint64.buffer); BitUtils._reverseByteTable = [ 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 ]; // ../../node_modules/image-in-browser/lib/common/string-utils.js var StringUtils = class { static { __name(this, "StringUtils"); } static getCodePoints(str) { const array = new Uint8Array(str.length); for (let i = 0; i < str.length; i++) { const codePoint = str.codePointAt(i); if (codePoint !== void 0) { if (0 <= codePoint && codePoint < 256) { array[i] = codePoint; } else { throw new LibError(`Error encoding text "${str}": unknown character code point ${codePoint}`); } } else { throw new LibError(`Error encoding text "${str}"`); } } return array; } }; StringUtils.utf8Decoder = new TextDecoder("utf8"); StringUtils.latin1Decoder = new TextDecoder("latin1"); // ../../node_modules/image-in-browser/lib/common/input-buffer.js var InputBuffer = class _InputBuffer { static { __name(this, "InputBuffer"); } set buffer(v) { this._buffer = v; } get buffer() { return this._buffer; } set bigEndian(v) { this._bigEndian = v; } get bigEndian() { return this._bigEndian; } set offset(v) { this._offset = v; } get offset() { return this._offset; } get start() { return this._start; } get end() { return this._end; } get position() { return this._offset - this._start; } get length() { return this._end - this._offset; } get isEOS() { return this._offset >= this._end; } constructor(opt) { var _a4, _b; this._buffer = opt.buffer; this._bigEndian = (_a4 = opt.bigEndian) !== null && _a4 !== void 0 ? _a4 : false; this._offset = (_b = opt.offset) !== null && _b !== void 0 ? _b : 0; this._start = this._offset; this._end = opt.length !== void 0 ? this._start + opt.length : this._buffer.length; } static from(other, offset, length) { const offsetFromOther = offset !== null && offset !== void 0 ? offset : 0; const result = new _InputBuffer({ buffer: other._buffer, bigEndian: other._bigEndian, offset: other._offset + offsetFromOther, length }); result._start = other._start; result._end = length !== void 0 ? other.offset + offsetFromOther + length : other._end; return result; } rewind() { this._offset = this._start; } get(index) { return this._buffer[this._offset + index]; } set(index, value) { return this._buffer[this._offset + index] = value; } memcpy(start, length, other, offset = 0) { if (other instanceof _InputBuffer) { ArrayUtils.copyRange(other.buffer, other.offset + offset, this._buffer, this.offset + start, length); } else { ArrayUtils.copyRange(other, offset, this._buffer, this.offset + start, length); } } memset(start, length, value) { this._buffer.fill(value, this._offset + start, this._offset + start + length); } subarray(count, position, offset = 0) { let pos = position !== void 0 ? this._start + position : this._offset; pos += offset; return new _InputBuffer({ buffer: this._buffer, bigEndian: this._bigEndian, offset: pos, length: count }); } indexOf(value, offset = 0) { const end = this.offset + this.length; for (let i = this.offset + offset; i < end; ++i) { if (this._buffer[i] === value) { return i - this._start; } } return -1; } peek(count, offset = 0) { return this.subarray(count, void 0, offset); } skip(count) { this._offset += count; } read() { return this._buffer[this._offset++]; } readRange(count) { const bytes = this.subarray(count); this._offset += bytes.length; return bytes; } readInt8() { return BitUtils.uint8ToInt8(this.read()); } readString(length) { if (length === void 0) { const codes = []; while (!this.isEOS) { const c = this.read(); if (c === 0) { return String.fromCodePoint(...codes); } codes.push(c); } throw new LibError("EOF reached without finding string terminator."); } const s = this.readRange(length); const bytes = s.toUint8Array(); const result = String.fromCodePoint(...bytes); return result; } readStringLine(length = 256) { const codes = []; while (!this.isEOS) { const c = this.read(); codes.push(c); if (c === 10 || codes.length >= length) { return String.fromCodePoint(...codes); } } return String.fromCodePoint(...codes); } readStringUtf8() { const codes = []; while (!this.isEOS) { const c = this.read(); if (c === 0) { const array2 = new Uint8Array(codes); return StringUtils.utf8Decoder.decode(array2); } codes.push(c); } const array = new Uint8Array(codes); return StringUtils.utf8Decoder.decode(array); } readUint16() { const b1 = this._buffer[this._offset++] & 255; const b2 = this._buffer[this._offset++] & 255; if (this._bigEndian) { return b1 << 8 | b2; } return b2 << 8 | b1; } readInt16() { return BitUtils.uint16ToInt16(this.readUint16()); } readUint24() { const b1 = this._buffer[this._offset++] & 255; const b2 = this._buffer[this._offset++] & 255; const b3 = this._buffer[this._offset++] & 255; if (this._bigEndian) { return b3 | b2 << 8 | b1 << 16; } return b1 | b2 << 8 | b3 << 16; } readUint32() { return BitUtils.int32ToUint32(this.readInt32()); } readInt32() { const b1 = this._buffer[this._offset++] & 255; const b2 = this._buffer[this._offset++] & 255; const b3 = this._buffer[this._offset++] & 255; const b4 = this._buffer[this._offset++] & 255; return this._bigEndian ? b1 << 24 | b2 << 16 | b3 << 8 | b4 : b4 << 24 | b3 << 16 | b2 << 8 | b1; } readFloat32() { return BitUtils.uint32ToFloat32(this.readUint32()); } readFloat64() { return BitUtils.uint64ToFloat64(this.readUint64()); } readUint64() { const b1 = this._buffer[this._offset++] & 255; const b2 = this._buffer[this._offset++] & 255; const b3 = this._buffer[this._offset++] & 255; const b4 = this._buffer[this._offset++] & 255; const b5 = this._buffer[this._offset++] & 255; const b6 = this._buffer[this._offset++] & 255; const b7 = this._buffer[this._offset++] & 255; const b8 = this._buffer[this._offset++] & 255; if (this._bigEndian) { return BigInt(b1 << 56) | BigInt(b2 << 48) | BigInt(b3 << 40) | BigInt(b4 << 32) | BigInt(b5 << 24) | BigInt(b6 << 16) | BigInt(b7 << 8) | BigInt(b8); } return BigInt(b8 << 56) | BigInt(b7 << 48) | BigInt(b6 << 40) | BigInt(b5 << 32) | BigInt(b4 << 24) | BigInt(b3 << 16) | BigInt(b2 << 8) | BigInt(b1); } toUint8Array(offset = 0, length) { const correctedLength = length !== null && length !== void 0 ? length : this.length - offset; if (this._buffer instanceof Uint8Array) { return new Uint8Array(this._buffer.buffer, this._buffer.byteOffset + this._offset + offset, correctedLength); } return Uint8Array.from(this._buffer.subarray(this._offset + offset, this._offset + offset + correctedLength)); } toUint32Array(offset = 0) { if (this._buffer instanceof Uint8Array) { return new Uint32Array(this._buffer.buffer, this._buffer.byteOffset + this._offset + offset); } const uint8array = this.toUint8Array(); return new Uint32Array(uint8array.buffer); } }; // ../../node_modules/image-in-browser/lib/color/channel-order.js var ChannelOrder; (function(ChannelOrder2) { ChannelOrder2[ChannelOrder2["rgba"] = 0] = "rgba"; ChannelOrder2[ChannelOrder2["bgra"] = 1] = "bgra"; ChannelOrder2[ChannelOrder2["abgr"] = 2] = "abgr"; ChannelOrder2[ChannelOrder2["argb"] = 3] = "argb"; ChannelOrder2[ChannelOrder2["rgb"] = 4] = "rgb"; ChannelOrder2[ChannelOrder2["bgr"] = 5] = "bgr"; ChannelOrder2[ChannelOrder2["grayAlpha"] = 6] = "grayAlpha"; ChannelOrder2[ChannelOrder2["red"] = 7] = "red"; })(ChannelOrder || (ChannelOrder = {})); var ChannelOrderLength = /* @__PURE__ */ new Map([ [ChannelOrder.rgba, 4], [ChannelOrder.bgra, 4], [ChannelOrder.abgr, 4], [ChannelOrder.argb, 4], [ChannelOrder.rgb, 3], [ChannelOrder.bgr, 3], [ChannelOrder.grayAlpha, 2], [ChannelOrder.red, 1] ]); // ../../node_modules/image-in-browser/lib/color/channel.js var Channel; (function(Channel2) { Channel2[Channel2["red"] = 0] = "red"; Channel2[Channel2["green"] = 1] = "green"; Channel2[Channel2["blue"] = 2] = "blue"; Channel2[Channel2["alpha"] = 3] = "alpha"; Channel2[Channel2["luminance"] = 4] = "luminance"; })(Channel || (Channel = {})); // ../../node_modules/image-in-browser/lib/common/float16.js var Float16 = class _Float16 { static { __name(this, "Float16"); } static get _toFloatFloat32() { return this._toFloatFloat32Data !== void 0 ? this._toFloatFloat32Data : this.initialize(); } constructor(f) { this.bits = f !== void 0 ? _Float16.doubleToFloat16(f) : 0; } static convert(i) { const s = i >>> 16 & 32768; let e = (i >>> 23 & 255) - (127 - 15); let m = i & 8388607; if (e <= 0) { if (e < -10) { return s; } m |= 8388608; const t = 14 - e; const a = (1 << t - 1) - 1; const b = m >>> t & 1; m = m + a + b >>> t; return s | m; } else if (e === 255 - (127 - 15)) { if (m === 0) { return s | 31744; } else { m >>>= 13; return s | 31744 | m | (m === 0 ? 1 : 0); } } else { m = m + 4095 + (m >>> 13 & 1); if ((m & 8388608) !== 0) { m = 0; e += 1; } if (e > 30) { return s | 31744; } return s | e << 10 | m >>> 13; } } static initialize() { if (this._toFloatFloat32Data !== void 0) { return this._toFloatFloat32Data; } const floatUint32Data = new Uint32Array(1 << 16); this._toFloatFloat32Data = new Float32Array(floatUint32Data.buffer); this._eLut = new Uint16Array(1 << 9); for (let i = 0; i < 256; i++) { const e = (i & 255) - (127 - 15); if (e <= 0 || e >= 30) { this._eLut[i] = 0; this._eLut[i | 256] = 0; } else { this._eLut[i] = e << 10; this._eLut[i | 256] = e << 10 | 32768; } } const iMax = 1 << 16; for (let i = 0; i < iMax; i++) { floatUint32Data[i] = this.halfToFloat(i); } return this._toFloatFloat32Data; } static halfToFloat(y) { const s = y >>> 15 & 1; let e = y >>> 10 & 31; let m = y & 1023; if (e === 0) { if (m === 0) { return s << 31; } else { while ((m & 1024) === 0) { m <<= 1; e -= 1; } e += 1; m &= ~1024; } } else if (e === 31) { if (m === 0) { return s << 31 | 2139095040; } else { return s << 31 | 2139095040 | m << 13; } } e += 127 - 15; m <<= 13; return s << 31 | e << 23 | m; } static from(other) { const float16 = new _Float16(); float16.bits = other.bits; return float16; } static fromBits(bits) { const float16 = new _Float16(); float16.bits = bits; return float16; } static float16ToDouble(bits) { return this._toFloatFloat32[bits]; } static doubleToFloat16(n) { const f = n; const xI = BitUtils.float32ToUint32(f); if (f === 0) { return xI >>> 16; } if (this._toFloatFloat32Data === void 0) { this.initialize(); } let e = xI >>> 23 & 511; e = this._eLut[e]; if (e !== 0) { const m = xI & 8388607; return e + (m + 4095 + (m >>> 13 & 1) >>> 13); } return this.convert(xI); } static posInf() { return _Float16.fromBits(31744); } static negInf() { return _Float16.fromBits(64512); } static qNan() { return _Float16.fromBits(32767); } static sNan() { return _Float16.fromBits(32255); } toDouble() { return _Float16._toFloatFloat32[this.bits]; } minus() { return _Float16.fromBits(this.bits ^ 32768); } add(f) { const d = f instanceof _Float16 ? f.toDouble() : typeof f === "number" ? f : 0; return new _Float16(this.toDouble() + d); } sub(f) { const d = f instanceof _Float16 ? f.toDouble() : typeof f === "number" ? f : 0; return new _Float16(this.toDouble() - d); } mul(f) { const d = f instanceof _Float16 ? f.toDouble() : typeof f === "number" ? f : 0; return new _Float16(this.toDouble() * d); } div(f) { const d = f instanceof _Float16 ? f.toDouble() : typeof f === "number" ? f : 0; return new _Float16(this.toDouble() / d); } round(n) { if (n >= 10) { return _Float16.from(this); } const s = this.bits & 32768; let e = this.bits & 32767; e >>>= 9 - n; e += e & 1; e <<= 9 - n; if (e >= 31744) { e = this.bits; e >>>= 10 - n; e <<= 10 - n; } return _Float16.fromBits(s | e); } isFinite() { const e = this.bits >>> 10 & 31; return e < 31; } isNormalized() { const e = this.bits >>> 10 & 31; return e > 0 && e < 31; } isDenormalized() { const e = this.bits >>> 10 & 31; const m = this.bits & 1023; return e === 0 && m !== 0; } isZero() { return (this.bits & 32767) === 0; } isNaN() { const e = this.bits >>> 10 & 31; const m = this.bits & 1023; return e === 31 && m !== 0; } isInfinity() { const e = this.bits >>> 10 & 31; const m = this.bits & 1023; return e === 31 && m === 0; } isNegative() { return (this.bits & 32768) !== 0; } }; // ../../node_modules/image-in-browser/lib/color/color-float16.js var ColorFloat16 = class _ColorFloat16 { static { __name(this, "ColorFloat16"); } get format() { return Format.float16; } get length() { return this.data.length; } get maxChannelValue() { return 1; } get maxIndexValue() { return 1; } get isLdrFormat() { return false; } get isHdrFormat() { return true; } get hasPalette() { return false; } get palette() { return void 0; } get index() { return this.r; } set index(i) { this.r = i; } get r() { return this.getChannel(0); } set r(r) { this.setChannel(0, r); } get g() { return this.getChannel(1); } set g(g) { this.setChannel(1, g); } get b() { return this.getChannel(2); } set b(b) { this.setChannel(2, b); } get a() { return this.getChannel(3); } set a(a) { this.setChannel(3, a); } get rNormalized() { return this.r / this.maxChannelValue; } set rNormalized(v) { this.r = v * this.maxChannelValue; } get gNormalized() { return this.g / this.maxChannelValue; } set gNormalized(v) { this.g = v * this.maxChannelValue; } get bNormalized() { return this.b / this.maxChannelValue; } set bNormalized(v) { this.b = v * this.maxChannelValue; } get aNormalized() { return this.a / this.maxChannelValue; } set aNormalized(v) { this.a = v * this.maxChannelValue; } get luminance() { return ColorUtils.getLuminance(this); } get luminanceNormalized() { return ColorUtils.getLuminanceNormalized(this); } constructor(data) { if (typeof data === "number") { this.data = new Uint16Array(data); } else { this.data = data.slice(); } } static from(other) { const c = new _ColorFloat16(other.length); c.data = other.data; return c; } static fromArray(color) { const c = new _ColorFloat16(color); const l = color.length; for (let i = 0; i < l; ++i) { c.data[i] = Float16.doubleToFloat16(color[i]); } return c; } static rgb(r, g, b) { const data = new Uint16Array([ Float16.doubleToFloat16(r), Float16.doubleToFloat16(g), Float16.doubleToFloat16(b) ]); return new _ColorFloat16(data); } static rgba(r, g, b, a) { const data = new Uint16Array([ Float16.doubleToFloat16(r), Float16.doubleToFloat16(g), Float16.doubleToFloat16(b), Float16.doubleToFloat16(a) ]); return new _ColorFloat16(data); } getChannel(channel) { if (channel === Channel.luminance) { return this.luminance; } else { return channel < this.data.length ? Float16.float16ToDouble(this.data[channel]) : 0; } } getChannelNormalized(channel) { return this.getChannel(channel) / this.maxChannelValue; } setChannel(index, value) { if (index < this.data.length) { this.data[index] = Float16.doubleToFloat16(value); } } set(c) { this.setRgba(c.r, c.g, c.b, c.a); } setRgb(r, g, b) { this.data[0] = Float16.doubleToFloat16(r); const nc = this.data.length; if (nc > 1) { this.data[1] = Float16.doubleToFloat16(g); if (nc > 2) { this.data[2] = Float16.doubleToFloat16(b); } } } setRgba(r, g, b, a) { this.data[0] = Float16.doubleToFloat16(r); const nc = this.data.length; if (nc > 1) { this.data[1] = Float16.doubleToFloat16(g); if (nc > 2) { this.data[2] = Float16.doubleToFloat16(b); if (nc > 3) { this.data[3] = Float16.doubleToFloat16(a); } } } } toArray() { return ArrayUtils.generate(this.length, (i) => this.getChannel(i)); } clone() { return _ColorFloat16.from(this); } equals(other) { if (other.length !== this.length) { return false; } for (let i = 0; i < this.length; i++) { if (other.getChannel(i) !== this.getChannel(i)) { return false; } } return true; } convert(opt) { return ColorUtils.convertColor({ from: this, format: opt === null || opt === void 0 ? void 0 : opt.format, numChannels: opt === null || opt === void 0 ? void 0 : opt.numChannels, alpha: opt === null || opt === void 0 ? void 0 : opt.alpha }); } }; // ../../node_modules/image-in-browser/lib/color/color-float32.js var ColorFloat32 = class _ColorFloat32 { static { __name(this, "ColorFloat32"); } get format() { return Format.float32; } get length() { return this.data.length; } get maxChannelValue() { return 1; } get maxIndexValue() { return 1; } get isLdrFormat() { return false; } get isHdrFormat() { return true; } get hasPalette() { return false; } get palette() { return void 0; } get index() { return this.r; } set index(i) { this.r = i; } get r() { return this.getChannel(0); } set r(r) { this.setChannel(0, r); } get g() { return this.getChannel(1); } set g(g) { this.setChannel(1, g); } get b() { return this.getChannel(2); } set b(b) { this.setChannel(2, b); } get a() { return this.getChannel(3); } set a(a) { this.setChannel(3, a); } get rNormalized() { return this.r / this.maxChannelValue; } set rNormalized(v) { this.r = v * this.maxChannelValue; } get gNormalized() { return this.g / this.maxChannelValue; } set gNormalized(v) { this.g = v * this.maxChannelValue; } get bNormalized() { return this.b / this.maxChannelValue; } set bNormalized(v) { this.b = v * this.maxChannelValue; } get aNormalized() { return this.a / this.maxChannelValue; } set aNormalized(v) { this.a = v * this.maxChannelValue; } get luminance() { return ColorUtils.getLuminance(this); } get luminanceNormalized() { return ColorUtils.getLuminanceNormalized(this); } constructor(data) { if (typeof data === "number") { this.data = new Float32Array(data); } else { this.data = data.slice(); } } static from(other) { const c = new _ColorFloat32(other.length); c.data = other.data; return c; } static fromArray(color) { return new _ColorFloat32(color); } static rgb(r, g, b) { const data = new Float32Array([r, g, b]); return new _ColorFloat32(data); } static rgba(r, g, b, a) { const data = new Float32Array([r, g, b, a]); return new _ColorFloat32(data); } getChannel(channel) { if (channel === Channel.luminance) { return this.luminance; } else { return channel < this.data.length ? this.data[channel] : 0; } } getChannelNormalized(channel) { return this.getChannel(channel) / this.maxChannelValue; } setChannel(index, value) { if (index < this.data.length) { this.data[index] = value; } } set(c) { this.setRgba(c.r, c.g, c.b, c.a); } setRgb(r, g, b) { this.data[0] = r; const nc = this.data.length; if (nc > 1) { this.data[1] = g; if (nc > 2) { this.data[2] = b; } } } setRgba(r, g, b, a) { this.data[0] = r; const nc = this.data.length; if (nc > 1) { this.data[1] = g; if (nc > 2) { this.data[2] = b; if (nc > 3) { this.data[3] = a; } } } } toArray() { return ArrayUtils.generate(this.length, (i) => this.getChannel(i)); } clone() { return _ColorFloat32.from(this); } equals(other) { if (other.length !== this.length) { return false; } for (let i = 0; i < this.length; i++) { if (other.getChannel(i) !== this.getChannel(i)) { return false; } } return true; } convert(opt) { return ColorUtils.convertColor({ from: this, format: opt === null || opt === void 0 ? void 0 : opt.format, numChannels: opt === null || opt === void 0 ? void 0 : opt.numChannels, alpha: opt === null || opt === void 0 ? void 0 : opt.alpha }); } }; // ../../node_modules/image-in-browser/lib/color/color-float64.js var ColorFloat64 = class _ColorFloat64 { static { __name(this, "ColorFloat64"); } get format() { return Format.float64; } get length() { return this.data.length; } get maxChannelValue() { return 1; } get maxIndexValue() { return 1; } get isLdrFormat() { return true; } get isHdrFormat() { return false; } get hasPalette() { return false; } get palette() { return void 0; } get index() { return this.r; } set index(i) { this.r = i; } get r() { return this.getChannel(0); } set r(r) { this.setChannel(0, r); } get g() { return this.getChannel(1); } set g(g) { this.setChannel(1, g); } get b() { return this.getChannel(2); } set b(b) { this.setChannel(2, b); } get a() { return this.getChannel(3); } set a(a) { this.setChannel(3, a); } get rNormalized() { return this.r / this.maxChannelValue; } set rNormalized(v) { this.r = v * this.maxChannelValue; } get gNormalized() { return this.g / this.maxChannelValue; } set gNormalized(v) { this.g = v * this.maxChannelValue; } get bNormalized() { return this.b / this.maxChannelValue; } set bNormalized(v) { this.b = v * this.maxChannelValue; } get aNormalized() { return this.a / this.maxChannelValue; } set aNormalized(v) { this.a = v * this.maxChannelValue; } get luminance() { return ColorUtils.getLuminance(this); } get luminanceNormalized() { return ColorUtils.getLuminanceNormalized(this); } constructor(data) { if (typeof data === "number") { this.data = new Float64Array(data); } else { this.data = data.slice(); } } static from(other) { const c = new _ColorFloat64(other.length); c.data = other.data; return c; } static fromArray(color) { return new _ColorFloat64(color); } static rgb(r, g, b) { const data = new Float64Array([r, g, b]); return new _ColorFloat64(data); } static rgba(r, g, b, a) { const data = new Float64Array([r, g, b, a]); return new _ColorFloat64(data); } getChannel(channel) { if (channel === Channel.luminance) { return this.luminance; } else { return channel < this.data.length ? this.data[channel] : 0; } } getChannelNormalized(channel) { return this.getChannel(channel) / this.maxChannelValue; } setChannel(index, value) { if (index < this.data.length) { this.data[index] = value; } } set(c) { this.setRgba(c.r, c.g, c.b, c.a); } setRgb(r, g, b) { this.data[0] = r; const nc = this.data.length; if (nc > 1) { this.data[1] = g; if (nc > 2) { this.data[2] = b; } } } setRgba(r, g, b, a) { this.data[0] = r; const nc = this.data.length; if (nc > 1) { this.data[1] = g; if (nc > 2) { this.data[2] = b; if (nc > 3) { this.data[3] = a; } } } } toArray() { return ArrayUtils.generate(this.length, (i) => this.getChannel(i)); } clone() { return _ColorFloat64.from(this); } equals(other) { if (other.length !== this.length) { return false; } for (let i = 0; i < this.length; i++) { if (other.getChannel(i) !== this.getChannel(i)) { return false; } } return true; } convert(opt) { return ColorUtils.convertColor({ from: this, format: opt === null || opt === void 0 ? void 0 : opt.format, numChannels: opt === null || opt === void 0 ? void 0 : opt.numChannels, alpha: opt === null || opt === void 0 ? void 0 : opt.alpha }); } }; // ../../node_modules/image-in-browser/lib/color/color-int16.js var ColorInt16 = class _ColorInt16 { static { __name(this, "ColorInt16"); } get format() { return Format.int16; } get length() { return this._data.length; } get maxChannelValue() { return 32767; } get maxIndexValue() { return 32767; } get isLdrFormat() { return false; } get isHdrFormat() { return true; } get hasPalette() { return false; } get palette() { return void 0; } get index() { return this.r; } set index(i) { this.r = i; } get r() { return this._data.length > 0 ? this._data[0] : 0; } set r(r) { if (this._data.length > 0) { this._data[0] = Math.trunc(r); } } get g() { return this._data.length > 1 ? this._data[1] : 0; } set g(g) { if (this._data.length > 1) { this._data[1] = Math.trunc(g); } } get b() { return this._data.length > 2 ? this._data[2] : 0; } set b(b) { if (this._data.length > 2) { this._data[2] = Math.trunc(b); } } get a() { return this._data.length > 3 ? this._data[3] : 0; } set a(a) { if (this._data.length > 3) { this._data[3] = Math.trunc(a); } } get rNormalized() { return this.r / this.maxChannelValue; } set rNormalized(v) { this.r = v * this.maxChannelValue; } get gNormalized() { return this.g / this.maxChannelValue; } set gNormalized(v) { this.g = v * this.maxChannelValue; } get bNormalized() { return this.b / this.maxChannelValue; } set bNormalized(v) { this.b = v * this.maxChannelValue; } get aNormalized() { return this.a / this.maxChannelValue; } set aNormalized(v) { this.a = v * this.maxChannelValue; } get luminance() { return ColorUtils.getLuminance(this); } get luminanceNormalized() { return ColorUtils.getLuminanceNormalized(this); } constructor(data) { if (typeof data === "number") { this._data = new Int16Array(data); } else { this._data = data.slice(); } } static from(other) { const c = new _ColorInt16(other.length); c._data = other._data; return c; } static fromArray(color) {