jimp
Version:
An image processing library written entirely in JavaScript.
1 lines • 728 kB
JavaScript
var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function getAugmentedNamespace(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var i=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};i.prototype=t.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(i,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),i}"undefined"==typeof self&&"object"==typeof commonjsGlobal&&(commonjsGlobal.self=commonjsGlobal);var global$1="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,inited=!1;function init(){inited=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0;t<64;++t)lookup[t]=e[t],revLookup[e.charCodeAt(t)]=t;revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63}function toByteArray(e){var t,i,r,n,a,o;inited||init();var s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");a="="===e[s-2]?2:"="===e[s-1]?1:0,o=new Arr(3*s/4-a),r=a>0?s-4:s;var l=0;for(t=0,i=0;t<r;t+=4,i+=3)n=revLookup[e.charCodeAt(t)]<<18|revLookup[e.charCodeAt(t+1)]<<12|revLookup[e.charCodeAt(t+2)]<<6|revLookup[e.charCodeAt(t+3)],o[l++]=n>>16&255,o[l++]=n>>8&255,o[l++]=255&n;return 2===a?(n=revLookup[e.charCodeAt(t)]<<2|revLookup[e.charCodeAt(t+1)]>>4,o[l++]=255&n):1===a&&(n=revLookup[e.charCodeAt(t)]<<10|revLookup[e.charCodeAt(t+1)]<<4|revLookup[e.charCodeAt(t+2)]>>2,o[l++]=n>>8&255,o[l++]=255&n),o}function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,t,i){for(var r,n=[],a=t;a<i;a+=3)r=(e[a]<<16)+(e[a+1]<<8)+e[a+2],n.push(tripletToBase64(r));return n.join("")}function fromByteArray(e){var t;inited||init();for(var i=e.length,r=i%3,n="",a=[],o=16383,s=0,l=i-r;s<l;s+=o)a.push(encodeChunk(e,s,s+o>l?l:s+o));return 1===r?(t=e[i-1],n+=lookup[t>>2],n+=lookup[t<<4&63],n+="=="):2===r&&(t=(e[i-2]<<8)+e[i-1],n+=lookup[t>>10],n+=lookup[t>>4&63],n+=lookup[t<<2&63],n+="="),a.push(n),a.join("")}function read(e,t,i,r,n){var a,o,s=8*n-r-1,l=(1<<s)-1,u=l>>1,h=-7,c=i?n-1:0,f=i?-1:1,d=e[t+c];for(c+=f,a=d&(1<<-h)-1,d>>=-h,h+=s;h>0;a=256*a+e[t+c],c+=f,h-=8);for(o=a&(1<<-h)-1,a>>=-h,h+=r;h>0;o=256*o+e[t+c],c+=f,h-=8);if(0===a)a=1-u;else{if(a===l)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),a-=u}return(d?-1:1)*o*Math.pow(2,a-r)}function write(e,t,i,r,n,a){var o,s,l,u=8*a-n-1,h=(1<<u)-1,c=h>>1,f=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:a-1,p=r?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=h):(o=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-o))<1&&(o--,l*=2),(t+=o+c>=1?f/l:f*Math.pow(2,1-c))*l>=2&&(o++,l/=2),o+c>=h?(s=0,o=h):o+c>=1?(s=(t*l-1)*Math.pow(2,n),o+=c):(s=t*Math.pow(2,c-1)*Math.pow(2,n),o=0));n>=8;e[i+d]=255&s,d+=p,s/=256,n-=8);for(o=o<<n|s,u+=n;u>0;e[i+d]=255&o,d+=p,o/=256,u-=8);e[i+d-p]|=128*m}var toString={}.toString,isArray=Array.isArray||function(e){return"[object Array]"==toString.call(e)},INSPECT_MAX_BYTES=50;function kMaxLength(){return Buffer.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function createBuffer(e,t){if(kMaxLength()<t)throw new RangeError("Invalid typed array length");return Buffer.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=Buffer.prototype:(null===e&&(e=new Buffer(t)),e.length=t),e}function Buffer(e,t,i){if(!(Buffer.TYPED_ARRAY_SUPPORT||this instanceof Buffer))return new Buffer(e,t,i);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return allocUnsafe(this,e)}return from(this,e,t,i)}function from(e,t,i,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?fromArrayBuffer(e,t,i,r):"string"==typeof t?fromString(e,t,i):fromObject(e,t)}function assertSize(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function alloc(e,t,i,r){return assertSize(t),t<=0?createBuffer(e,t):void 0!==i?"string"==typeof r?createBuffer(e,t).fill(i,r):createBuffer(e,t).fill(i):createBuffer(e,t)}function allocUnsafe(e,t){if(assertSize(t),e=createBuffer(e,t<0?0:0|checked(t)),!Buffer.TYPED_ARRAY_SUPPORT)for(var i=0;i<t;++i)e[i]=0;return e}function fromString(e,t,i){if("string"==typeof i&&""!==i||(i="utf8"),!Buffer.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var r=0|byteLength(t,i),n=(e=createBuffer(e,r)).write(t,i);return n!==r&&(e=e.slice(0,n)),e}function fromArrayLike(e,t){var i=t.length<0?0:0|checked(t.length);e=createBuffer(e,i);for(var r=0;r<i;r+=1)e[r]=255&t[r];return e}function fromArrayBuffer(e,t,i,r){if(t.byteLength,i<0||t.byteLength<i)throw new RangeError("'offset' is out of bounds");if(t.byteLength<i+(r||0))throw new RangeError("'length' is out of bounds");return t=void 0===i&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,i):new Uint8Array(t,i,r),Buffer.TYPED_ARRAY_SUPPORT?(e=t).__proto__=Buffer.prototype:e=fromArrayLike(e,t),e}function fromObject(e,t){if(internalIsBuffer(t)){var i=0|checked(t.length);return 0===(e=createBuffer(e,i)).length||t.copy(e,0,0,i),e}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||isnan(t.length)?createBuffer(e,0):fromArrayLike(e,t);if("Buffer"===t.type&&isArray(t.data))return fromArrayLike(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function checked(e){if(e>=kMaxLength())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+kMaxLength().toString(16)+" bytes");return 0|e}function internalIsBuffer(e){return!(null==e||!e._isBuffer)}function byteLength(e,t){if(internalIsBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var i=e.length;if(0===i)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return utf8ToBytes(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return base64ToBytes(e).length;default:if(r)return utf8ToBytes(e).length;t=(""+t).toLowerCase(),r=!0}}function slowToString(e,t,i){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return hexSlice(this,t,i);case"utf8":case"utf-8":return utf8Slice(this,t,i);case"ascii":return asciiSlice(this,t,i);case"latin1":case"binary":return latin1Slice(this,t,i);case"base64":return base64Slice(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,t,i);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function swap(e,t,i){var r=e[t];e[t]=e[i],e[i]=r}function bidirectionalIndexOf(e,t,i,r,n){if(0===e.length)return-1;if("string"==typeof i?(r=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=n?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(n)return-1;i=e.length-1}else if(i<0){if(!n)return-1;i=0}if("string"==typeof t&&(t=Buffer.from(t,r)),internalIsBuffer(t))return 0===t.length?-1:arrayIndexOf(e,t,i,r,n);if("number"==typeof t)return t&=255,Buffer.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):arrayIndexOf(e,[t],i,r,n);throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(e,t,i,r,n){var a,o=1,s=e.length,l=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;o=2,s/=2,l/=2,i/=2}function u(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(n){var h=-1;for(a=i;a<s;a++)if(u(e,a)===u(t,-1===h?0:a-h)){if(-1===h&&(h=a),a-h+1===l)return h*o}else-1!==h&&(a-=a-h),h=-1}else for(i+l>s&&(i=s-l),a=i;a>=0;a--){for(var c=!0,f=0;f<l;f++)if(u(e,a+f)!==u(t,f)){c=!1;break}if(c)return a}return-1}function hexWrite(e,t,i,r){i=Number(i)||0;var n=e.length-i;r?(r=Number(r))>n&&(r=n):r=n;var a=t.length;if(a%2!=0)throw new TypeError("Invalid hex string");r>a/2&&(r=a/2);for(var o=0;o<r;++o){var s=parseInt(t.substr(2*o,2),16);if(isNaN(s))return o;e[i+o]=s}return o}function utf8Write(e,t,i,r){return blitBuffer(utf8ToBytes(t,e.length-i),e,i,r)}function asciiWrite(e,t,i,r){return blitBuffer(asciiToBytes(t),e,i,r)}function latin1Write(e,t,i,r){return asciiWrite(e,t,i,r)}function base64Write(e,t,i,r){return blitBuffer(base64ToBytes(t),e,i,r)}function ucs2Write(e,t,i,r){return blitBuffer(utf16leToBytes(t,e.length-i),e,i,r)}function base64Slice(e,t,i){return 0===t&&i===e.length?fromByteArray(e):fromByteArray(e.slice(t,i))}function utf8Slice(e,t,i){i=Math.min(e.length,i);for(var r=[],n=t;n<i;){var a,o,s,l,u=e[n],h=null,c=u>239?4:u>223?3:u>191?2:1;if(n+c<=i)switch(c){case 1:u<128&&(h=u);break;case 2:128==(192&(a=e[n+1]))&&(l=(31&u)<<6|63&a)>127&&(h=l);break;case 3:a=e[n+1],o=e[n+2],128==(192&a)&&128==(192&o)&&(l=(15&u)<<12|(63&a)<<6|63&o)>2047&&(l<55296||l>57343)&&(h=l);break;case 4:a=e[n+1],o=e[n+2],s=e[n+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&(l=(15&u)<<18|(63&a)<<12|(63&o)<<6|63&s)>65535&&l<1114112&&(h=l)}null===h?(h=65533,c=1):h>65535&&(h-=65536,r.push(h>>>10&1023|55296),h=56320|1023&h),r.push(h),n+=c}return decodeCodePointsArray(r)}Buffer.TYPED_ARRAY_SUPPORT=void 0===global$1.TYPED_ARRAY_SUPPORT||global$1.TYPED_ARRAY_SUPPORT,kMaxLength(),Buffer.poolSize=8192,Buffer._augment=function(e){return e.__proto__=Buffer.prototype,e},Buffer.from=function(e,t,i){return from(null,e,t,i)},Buffer.TYPED_ARRAY_SUPPORT&&(Buffer.prototype.__proto__=Uint8Array.prototype,Buffer.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&Buffer[Symbol.species]),Buffer.alloc=function(e,t,i){return alloc(null,e,t,i)},Buffer.allocUnsafe=function(e){return allocUnsafe(null,e)},Buffer.allocUnsafeSlow=function(e){return allocUnsafe(null,e)},Buffer.isBuffer=isBuffer,Buffer.compare=function(e,t){if(!internalIsBuffer(e)||!internalIsBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,r=t.length,n=0,a=Math.min(i,r);n<a;++n)if(e[n]!==t[n]){i=e[n],r=t[n];break}return i<r?-1:r<i?1:0},Buffer.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},Buffer.concat=function(e,t){if(!isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return Buffer.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var r=Buffer.allocUnsafe(t),n=0;for(i=0;i<e.length;++i){var a=e[i];if(!internalIsBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(r,n),n+=a.length}return r},Buffer.byteLength=byteLength,Buffer.prototype._isBuffer=!0,Buffer.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)swap(this,t,t+1);return this},Buffer.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)swap(this,t,t+3),swap(this,t+1,t+2);return this},Buffer.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)swap(this,t,t+7),swap(this,t+1,t+6),swap(this,t+2,t+5),swap(this,t+3,t+4);return this},Buffer.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?utf8Slice(this,0,e):slowToString.apply(this,arguments)},Buffer.prototype.equals=function(e){if(!internalIsBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===Buffer.compare(this,e)},Buffer.prototype.inspect=function(){var e="",t=INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),"<Buffer "+e+">"},Buffer.prototype.compare=function(e,t,i,r,n){if(!internalIsBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===r&&(r=0),void 0===n&&(n=this.length),t<0||i>e.length||r<0||n>this.length)throw new RangeError("out of range index");if(r>=n&&t>=i)return 0;if(r>=n)return-1;if(t>=i)return 1;if(this===e)return 0;for(var a=(n>>>=0)-(r>>>=0),o=(i>>>=0)-(t>>>=0),s=Math.min(a,o),l=this.slice(r,n),u=e.slice(t,i),h=0;h<s;++h)if(l[h]!==u[h]){a=l[h],o=u[h];break}return a<o?-1:o<a?1:0},Buffer.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},Buffer.prototype.indexOf=function(e,t,i){return bidirectionalIndexOf(this,e,t,i,!0)},Buffer.prototype.lastIndexOf=function(e,t,i){return bidirectionalIndexOf(this,e,t,i,!1)},Buffer.prototype.write=function(e,t,i,r){if(void 0===t)r="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)r=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(i)?(i|=0,void 0===r&&(r="utf8")):(r=i,i=void 0)}var n=this.length-t;if((void 0===i||i>n)&&(i=n),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var a=!1;;)switch(r){case"hex":return hexWrite(this,e,t,i);case"utf8":case"utf-8":return utf8Write(this,e,t,i);case"ascii":return asciiWrite(this,e,t,i);case"latin1":case"binary":return latin1Write(this,e,t,i);case"base64":return base64Write(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,e,t,i);default:if(a)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),a=!0}},Buffer.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(e){var t=e.length;if(t<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,e);for(var i="",r=0;r<t;)i+=String.fromCharCode.apply(String,e.slice(r,r+=MAX_ARGUMENTS_LENGTH));return i}function asciiSlice(e,t,i){var r="";i=Math.min(e.length,i);for(var n=t;n<i;++n)r+=String.fromCharCode(127&e[n]);return r}function latin1Slice(e,t,i){var r="";i=Math.min(e.length,i);for(var n=t;n<i;++n)r+=String.fromCharCode(e[n]);return r}function hexSlice(e,t,i){var r=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>r)&&(i=r);for(var n="",a=t;a<i;++a)n+=toHex(e[a]);return n}function utf16leSlice(e,t,i){for(var r=e.slice(t,i),n="",a=0;a<r.length;a+=2)n+=String.fromCharCode(r[a]+256*r[a+1]);return n}function checkOffset(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function checkInt(e,t,i,r,n,a){if(!internalIsBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>n||t<a)throw new RangeError('"value" argument is out of bounds');if(i+r>e.length)throw new RangeError("Index out of range")}function objectWriteUInt16(e,t,i,r){t<0&&(t=65535+t+1);for(var n=0,a=Math.min(e.length-i,2);n<a;++n)e[i+n]=(t&255<<8*(r?n:1-n))>>>8*(r?n:1-n)}function objectWriteUInt32(e,t,i,r){t<0&&(t=4294967295+t+1);for(var n=0,a=Math.min(e.length-i,4);n<a;++n)e[i+n]=t>>>8*(r?n:3-n)&255}function checkIEEE754(e,t,i,r,n,a){if(i+r>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function writeFloat(e,t,i,r,n){return n||checkIEEE754(e,t,i,4),write(e,t,i,r,23,4),i+4}function writeDouble(e,t,i,r,n){return n||checkIEEE754(e,t,i,8),write(e,t,i,r,52,8),i+8}Buffer.prototype.slice=function(e,t){var i,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e),Buffer.TYPED_ARRAY_SUPPORT)(i=this.subarray(e,t)).__proto__=Buffer.prototype;else{var n=t-e;i=new Buffer(n,void 0);for(var a=0;a<n;++a)i[a]=this[a+e]}return i},Buffer.prototype.readUIntLE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e],n=1,a=0;++a<t&&(n*=256);)r+=this[e+a]*n;return r},Buffer.prototype.readUIntBE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e+--t],n=1;t>0&&(n*=256);)r+=this[e+--t]*n;return r},Buffer.prototype.readUInt8=function(e,t){return t||checkOffset(e,1,this.length),this[e]},Buffer.prototype.readUInt16LE=function(e,t){return t||checkOffset(e,2,this.length),this[e]|this[e+1]<<8},Buffer.prototype.readUInt16BE=function(e,t){return t||checkOffset(e,2,this.length),this[e]<<8|this[e+1]},Buffer.prototype.readUInt32LE=function(e,t){return t||checkOffset(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},Buffer.prototype.readUInt32BE=function(e,t){return t||checkOffset(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},Buffer.prototype.readIntLE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=this[e],n=1,a=0;++a<t&&(n*=256);)r+=this[e+a]*n;return r>=(n*=128)&&(r-=Math.pow(2,8*t)),r},Buffer.prototype.readIntBE=function(e,t,i){e|=0,t|=0,i||checkOffset(e,t,this.length);for(var r=t,n=1,a=this[e+--r];r>0&&(n*=256);)a+=this[e+--r]*n;return a>=(n*=128)&&(a-=Math.pow(2,8*t)),a},Buffer.prototype.readInt8=function(e,t){return t||checkOffset(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},Buffer.prototype.readInt16LE=function(e,t){t||checkOffset(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},Buffer.prototype.readInt16BE=function(e,t){t||checkOffset(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},Buffer.prototype.readInt32LE=function(e,t){return t||checkOffset(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},Buffer.prototype.readInt32BE=function(e,t){return t||checkOffset(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},Buffer.prototype.readFloatLE=function(e,t){return t||checkOffset(e,4,this.length),read(this,e,!0,23,4)},Buffer.prototype.readFloatBE=function(e,t){return t||checkOffset(e,4,this.length),read(this,e,!1,23,4)},Buffer.prototype.readDoubleLE=function(e,t){return t||checkOffset(e,8,this.length),read(this,e,!0,52,8)},Buffer.prototype.readDoubleBE=function(e,t){return t||checkOffset(e,8,this.length),read(this,e,!1,52,8)},Buffer.prototype.writeUIntLE=function(e,t,i,r){(e=+e,t|=0,i|=0,r)||checkInt(this,e,t,i,Math.pow(2,8*i)-1,0);var n=1,a=0;for(this[t]=255&e;++a<i&&(n*=256);)this[t+a]=e/n&255;return t+i},Buffer.prototype.writeUIntBE=function(e,t,i,r){(e=+e,t|=0,i|=0,r)||checkInt(this,e,t,i,Math.pow(2,8*i)-1,0);var n=i-1,a=1;for(this[t+n]=255&e;--n>=0&&(a*=256);)this[t+n]=e/a&255;return t+i},Buffer.prototype.writeUInt8=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,1,255,0),Buffer.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},Buffer.prototype.writeUInt16LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):objectWriteUInt16(this,e,t,!0),t+2},Buffer.prototype.writeUInt16BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,65535,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):objectWriteUInt16(this,e,t,!1),t+2},Buffer.prototype.writeUInt32LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):objectWriteUInt32(this,e,t,!0),t+4},Buffer.prototype.writeUInt32BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,4294967295,0),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):objectWriteUInt32(this,e,t,!1),t+4},Buffer.prototype.writeIntLE=function(e,t,i,r){if(e=+e,t|=0,!r){var n=Math.pow(2,8*i-1);checkInt(this,e,t,i,n-1,-n)}var a=0,o=1,s=0;for(this[t]=255&e;++a<i&&(o*=256);)e<0&&0===s&&0!==this[t+a-1]&&(s=1),this[t+a]=(e/o|0)-s&255;return t+i},Buffer.prototype.writeIntBE=function(e,t,i,r){if(e=+e,t|=0,!r){var n=Math.pow(2,8*i-1);checkInt(this,e,t,i,n-1,-n)}var a=i-1,o=1,s=0;for(this[t+a]=255&e;--a>=0&&(o*=256);)e<0&&0===s&&0!==this[t+a+1]&&(s=1),this[t+a]=(e/o|0)-s&255;return t+i},Buffer.prototype.writeInt8=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,1,127,-128),Buffer.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},Buffer.prototype.writeInt16LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):objectWriteUInt16(this,e,t,!0),t+2},Buffer.prototype.writeInt16BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,2,32767,-32768),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):objectWriteUInt16(this,e,t,!1),t+2},Buffer.prototype.writeInt32LE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,2147483647,-2147483648),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):objectWriteUInt32(this,e,t,!0),t+4},Buffer.prototype.writeInt32BE=function(e,t,i){return e=+e,t|=0,i||checkInt(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),Buffer.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):objectWriteUInt32(this,e,t,!1),t+4},Buffer.prototype.writeFloatLE=function(e,t,i){return writeFloat(this,e,t,!0,i)},Buffer.prototype.writeFloatBE=function(e,t,i){return writeFloat(this,e,t,!1,i)},Buffer.prototype.writeDoubleLE=function(e,t,i){return writeDouble(this,e,t,!0,i)},Buffer.prototype.writeDoubleBE=function(e,t,i){return writeDouble(this,e,t,!1,i)},Buffer.prototype.copy=function(e,t,i,r){if(i||(i=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<i&&(r=i),r===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-i&&(r=e.length-t+i);var n,a=r-i;if(this===e&&i<t&&t<r)for(n=a-1;n>=0;--n)e[n+t]=this[n+i];else if(a<1e3||!Buffer.TYPED_ARRAY_SUPPORT)for(n=0;n<a;++n)e[n+t]=this[n+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+a),t);return a},Buffer.prototype.fill=function(e,t,i,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,i=this.length):"string"==typeof i&&(r=i,i=this.length),1===e.length){var n=e.charCodeAt(0);n<256&&(e=n)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!Buffer.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var a;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(a=t;a<i;++a)this[a]=e;else{var o=internalIsBuffer(e)?e:utf8ToBytes(new Buffer(e,r).toString()),s=o.length;for(a=0;a<i-t;++a)this[a+t]=o[a%s]}return this};var INVALID_BASE64_RE=/[^+\/0-9A-Za-z-_]/g,HeaderTypes;function base64clean(e){if((e=stringtrim(e).replace(INVALID_BASE64_RE,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}function stringtrim(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function toHex(e){return e<16?"0"+e.toString(16):e.toString(16)}function utf8ToBytes(e,t){var i;t=t||1/0;for(var r=e.length,n=null,a=[],o=0;o<r;++o){if((i=e.charCodeAt(o))>55295&&i<57344){if(!n){if(i>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&a.push(239,191,189);continue}n=i;continue}if(i<56320){(t-=3)>-1&&a.push(239,191,189),n=i;continue}i=65536+(n-55296<<10|i-56320)}else n&&(t-=3)>-1&&a.push(239,191,189);if(n=null,i<128){if((t-=1)<0)break;a.push(i)}else if(i<2048){if((t-=2)<0)break;a.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;a.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;a.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return a}function asciiToBytes(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}function utf16leToBytes(e,t){for(var i,r,n,a=[],o=0;o<e.length&&!((t-=2)<0);++o)r=(i=e.charCodeAt(o))>>8,n=i%256,a.push(n),a.push(r);return a}function base64ToBytes(e){return toByteArray(base64clean(e))}function blitBuffer(e,t,i,r){for(var n=0;n<r&&!(n+i>=t.length||n>=e.length);++n)t[n+i]=e[n];return n}function isnan(e){return e!=e}function isBuffer(e){return null!=e&&(!!e._isBuffer||isFastBuffer(e)||isSlowBuffer(e))}function isFastBuffer(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}function isSlowBuffer(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&isFastBuffer(e.slice(0,0))}!function(e){e[e.BITMAP_INFO_HEADER=40]="BITMAP_INFO_HEADER",e[e.BITMAP_V2_INFO_HEADER=52]="BITMAP_V2_INFO_HEADER",e[e.BITMAP_V3_INFO_HEADER=56]="BITMAP_V3_INFO_HEADER",e[e.BITMAP_V4_HEADER=108]="BITMAP_V4_HEADER",e[e.BITMAP_V5_HEADER=124]="BITMAP_V5_HEADER"}(HeaderTypes||(HeaderTypes={}));var HeaderTypes$1=HeaderTypes,BmpCompression;function maskColor(e,t,i,r){const n=1+~e&e,a=1+~t&t,o=1+~i&i,s=1+~r&r,l=e/n+1,u=t/a+1,h=i/o+1,c=r/s+1;return{shiftRed:t=>(t&e)/n*256/l,shiftGreen:e=>(e&t)/a*256/u,shiftBlue:e=>(e&i)/o*256/h,shiftAlpha:0!==r?e=>(e&r)/s*256/c:()=>255}}!function(e){e[e.NONE=0]="NONE",e[e.BI_RLE8=1]="BI_RLE8",e[e.BI_RLE4=2]="BI_RLE4",e[e.BI_BIT_FIELDS=3]="BI_BIT_FIELDS",e[e.BI_ALPHA_BIT_FIELDS=6]="BI_ALPHA_BIT_FIELDS"}(BmpCompression||(BmpCompression={}));class BmpDecoder{flag;fileSize;reserved1;reserved2;offset;headerSize;width;height;planes;bitPP;compression;rawSize;hr;vr;colors;importantColors;palette;data;maskRed;maskGreen;maskBlue;maskAlpha;toRGBA;pos;bottomUp;buffer;locRed;locGreen;locBlue;locAlpha;shiftRed;shiftGreen;shiftBlue;shiftAlpha;constructor(e,{toRGBA:t}={toRGBA:!1}){if(this.buffer=e,this.toRGBA=!!t,this.pos=0,this.bottomUp=!0,this.flag=this.buffer.toString("utf-8",0,this.pos+=2),"BM"!==this.flag)throw new Error("Invalid BMP File");this.locRed=this.toRGBA?0:3,this.locGreen=this.toRGBA?1:2,this.locBlue=this.toRGBA?2:1,this.locAlpha=this.toRGBA?3:0,this.parseHeader(),this.parseRGBA()}parseHeader(){if(this.fileSize=this.readUInt32LE(),this.reserved1=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.reserved2=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.offset=this.readUInt32LE(),this.headerSize=this.readUInt32LE(),!(this.headerSize in HeaderTypes$1))throw new Error(`Unsupported BMP header size ${this.headerSize}`);if(this.width=this.readUInt32LE(),this.height=this.readUInt32LE(),this.height=this.height>2147483647?this.height-4294967296:this.height,this.planes=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.bitPP=this.buffer.readUInt16LE(this.pos),this.pos+=2,this.compression=this.readUInt32LE(),this.rawSize=this.readUInt32LE(),this.hr=this.readUInt32LE(),this.vr=this.readUInt32LE(),this.colors=this.readUInt32LE(),this.importantColors=this.readUInt32LE(),32===this.bitPP?(this.maskAlpha=0,this.maskRed=16711680,this.maskGreen=65280,this.maskBlue=255):16===this.bitPP&&(this.maskAlpha=0,this.maskRed=31744,this.maskGreen=992,this.maskBlue=31),(this.headerSize>HeaderTypes$1.BITMAP_INFO_HEADER||this.compression===BmpCompression.BI_BIT_FIELDS||this.compression===BmpCompression.BI_ALPHA_BIT_FIELDS)&&(this.maskRed=this.readUInt32LE(),this.maskGreen=this.readUInt32LE(),this.maskBlue=this.readUInt32LE()),(this.headerSize>HeaderTypes$1.BITMAP_V2_INFO_HEADER||this.compression===BmpCompression.BI_ALPHA_BIT_FIELDS)&&(this.maskAlpha=this.readUInt32LE()),this.headerSize>HeaderTypes$1.BITMAP_V3_INFO_HEADER&&(this.pos+=HeaderTypes$1.BITMAP_V4_HEADER-HeaderTypes$1.BITMAP_V3_INFO_HEADER),this.headerSize>HeaderTypes$1.BITMAP_V4_HEADER&&(this.pos+=HeaderTypes$1.BITMAP_V5_HEADER-HeaderTypes$1.BITMAP_V4_HEADER),this.bitPP<=8||this.colors>0){const e=0===this.colors?1<<this.bitPP:this.colors;this.palette=new Array(e);for(let t=0;t<e;t++){const e=this.buffer.readUInt8(this.pos++),i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++);this.palette[t]={red:r,green:i,blue:e,quad:n}}}this.height<0&&(this.height*=-1,this.bottomUp=!1);const e=maskColor(this.maskRed,this.maskGreen,this.maskBlue,this.maskAlpha);this.shiftRed=e.shiftRed,this.shiftGreen=e.shiftGreen,this.shiftBlue=e.shiftBlue,this.shiftAlpha=e.shiftAlpha}parseRGBA(){switch(this.data=Buffer.alloc(this.width*this.height*4),this.bitPP){case 1:this.bit1();break;case 4:this.bit4();break;case 8:this.bit8();break;case 16:this.bit16();break;case 24:this.bit24();break;default:this.bit32()}}bit1(){const e=Math.ceil(this.width/8),t=e%4,i=0!==t?4-t:0;this.scanImage(i,e,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+8*e*4;for(let t=0;t<8&&8*e+t<this.width;t++){const e=this.palette[i>>7-t&1];this.data[r+t*this.locAlpha]=0,this.data[r+4*t+this.locBlue]=e.blue,this.data[r+4*t+this.locGreen]=e.green,this.data[r+4*t+this.locRed]=e.red}}))}bit4(){if(this.compression===BmpCompression.BI_RLE4){this.data.fill(0);let e=!1,t=this.bottomUp?this.height-1:0,i=0;for(;i<this.data.length;){const r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++);if(0===r){if(0===n){t+=this.bottomUp?-1:1,i=t*this.width*4,e=!1;continue}if(1===n)break;if(2===n){const e=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);t+=this.bottomUp?-r:r,i+=r*this.width*4+4*e}else{let t=this.buffer.readUInt8(this.pos++);for(let r=0;r<n;r++)i=this.setPixelData(i,e?15&t:(240&t)>>4),1&r&&r+1<n&&(t=this.buffer.readUInt8(this.pos++)),e=!e;1==(n+1>>1&1)&&this.pos++}}else for(let t=0;t<r;t++)i=this.setPixelData(i,e?15&n:(240&n)>>4),e=!e}}else{const e=Math.ceil(this.width/2),t=e%4,i=0!==t?4-t:0;this.scanImage(i,e,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+2*e*4,n=i>>4;let a=this.palette[n];if(this.data[r]=0,this.data[r+1]=a.blue,this.data[r+2]=a.green,this.data[r+3]=a.red,2*e+1>=this.width)return!1;const o=15&i;a=this.palette[o],this.data[r+4]=0,this.data[r+4+1]=a.blue,this.data[r+4+2]=a.green,this.data[r+4+3]=a.red}))}}bit8(){if(this.compression===BmpCompression.BI_RLE8){this.data.fill(0);let e=this.bottomUp?this.height-1:0,t=0;for(;t<this.data.length;){const i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);if(0===i){if(0===r){e+=this.bottomUp?-1:1,t=e*this.width*4;continue}if(1===r)break;if(2===r){const i=this.buffer.readUInt8(this.pos++),r=this.buffer.readUInt8(this.pos++);e+=this.bottomUp?-r:r,t+=r*this.width*4+4*i}else{for(let e=0;e<r;e++){const e=this.buffer.readUInt8(this.pos++);t=this.setPixelData(t,e)}!0&r&&this.pos++}}else for(let e=0;e<i;e++)t=this.setPixelData(t,r)}}else{const e=this.width%4,t=0!==e?4-e:0;this.scanImage(t,this.width,((e,t)=>{const i=this.buffer.readUInt8(this.pos++),r=t*this.width*4+4*e;if(i<this.palette.length){const e=this.palette[i];this.data[r]=0,this.data[r+1]=e.blue,this.data[r+2]=e.green,this.data[r+3]=e.red}else this.data[r]=0,this.data[r+1]=255,this.data[r+2]=255,this.data[r+3]=255}))}}bit16(){const e=this.width%2*2;this.scanImage(e,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.buffer.readUInt16LE(this.pos);this.pos+=2,this.data[i+this.locRed]=this.shiftRed(r),this.data[i+this.locGreen]=this.shiftGreen(r),this.data[i+this.locBlue]=this.shiftBlue(r),this.data[i+this.locAlpha]=this.shiftAlpha(r)}))}bit24(){const e=this.width%4;this.scanImage(e,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.buffer.readUInt8(this.pos++),n=this.buffer.readUInt8(this.pos++),a=this.buffer.readUInt8(this.pos++);this.data[i+this.locRed]=a,this.data[i+this.locGreen]=n,this.data[i+this.locBlue]=r,this.data[i+this.locAlpha]=0}))}bit32(){this.scanImage(0,this.width,((e,t)=>{const i=t*this.width*4+4*e,r=this.readUInt32LE();this.data[i+this.locRed]=this.shiftRed(r),this.data[i+this.locGreen]=this.shiftGreen(r),this.data[i+this.locBlue]=this.shiftBlue(r),this.data[i+this.locAlpha]=this.shiftAlpha(r)}))}scanImage(e=0,t=this.width,i){for(let r=this.height-1;r>=0;r--){const n=this.bottomUp?r:this.height-1-r;for(let e=0;e<t;e++){if(!1===i.call(this,e,n))return}this.pos+=e}}readUInt32LE(){const e=this.buffer.readUInt32LE(this.pos);return this.pos+=4,e}setPixelData(e,t){const{blue:i,green:r,red:n}=this.palette[t];return this.data[e+this.locAlpha]=0,this.data[e+1+this.locBlue]=i,this.data[e+2+this.locGreen]=r,this.data[e+3+this.locRed]=n,e+4}}function createInteger(e){return e.reduce(((e,t)=>e<<1|t),0)}function createColor(e){return e.quad<<24|e.red<<16|e.green<<8|e.blue}class BmpEncoder{fileSize;reserved1;reserved2;offset;width;flag;height;planes;bitPP;compress;hr;vr;colors;importantColors;rawSize;headerSize;data;palette;extraBytes;buffer;bytesInColor;pos;constructor(e){switch(this.buffer=e.data,this.width=e.width,this.height=e.height,this.headerSize=HeaderTypes$1.BITMAP_INFO_HEADER,this.flag="BM",this.bitPP=e.bitPP||24,this.offset=54,this.reserved1=e.reserved1||0,this.reserved2=e.reserved2||0,this.planes=1,this.compress=0,this.hr=e.hr||0,this.vr=e.vr||0,this.importantColors=e.importantColors||0,this.colors=Math.min(2**(this.bitPP-1||1),e.colors||1/0),this.palette=e.palette||[],this.colors&&this.bitPP<16?this.offset+=4*this.colors:this.colors=0,this.bitPP){case 32:this.bytesInColor=4;break;case 16:this.bytesInColor=2;break;case 8:this.bytesInColor=1;break;case 4:this.bytesInColor=.5;break;case 1:this.bytesInColor=1/8;break;default:this.bytesInColor=3,this.bitPP=24}const t=this.width*this.bitPP/32,i=Math.ceil(t);this.extraBytes=4*(i-t),this.rawSize=this.height*i*4+2,this.fileSize=this.rawSize+this.offset,this.data=Buffer.alloc(this.fileSize,1),this.pos=0,this.encode()}encode(){switch(this.pos=0,this.writeHeader(),this.bitPP){case 32:this.bit32();break;case 16:this.bit16();break;case 8:this.bit8();break;case 4:this.bit4();break;case 1:this.bit1();break;default:this.bit24()}}writeHeader(){this.data.write(this.flag,this.pos,2),this.pos+=2,this.writeUInt32LE(this.fileSize),this.writeUInt32LE(this.reserved1<<16|this.reserved2),this.writeUInt32LE(this.offset),this.writeUInt32LE(this.headerSize),this.writeUInt32LE(this.width),this.writeUInt32LE(this.height),this.data.writeUInt16LE(this.planes,this.pos),this.pos+=2,this.data.writeUInt16LE(this.bitPP,this.pos),this.pos+=2,this.writeUInt32LE(this.compress),this.writeUInt32LE(this.rawSize),this.writeUInt32LE(this.hr),this.writeUInt32LE(this.vr),this.writeUInt32LE(this.colors),this.writeUInt32LE(this.importantColors)}bit1(){this.palette.length&&2===this.colors?this.initColors(1):(this.writeUInt32LE(16777215),this.writeUInt32LE(0)),this.pos+=1;let e=[];this.writeImage(((t,i,r)=>{let n=i;n++;const a=this.buffer[n++],o=this.buffer[n++],s=.2126*this.buffer[n++]+.7152*o+.0722*a;return e.push(s>127?0:1),(r+1)%8==0?(this.data[t-1]=createInteger(e),e=[]):r===this.width-1&&e.length>0&&(this.data[t-1]=createInteger(e)<<4,e=[]),n}))}bit4(){const e=this.initColors(4);let t=[];this.writeImage(((i,r,n)=>{let a=r;const o=createColor({quad:this.buffer[a++],blue:this.buffer[a++],green:this.buffer[a++],red:this.buffer[a++]}),s=e.findIndex((e=>e===o));return-1!==s?t.push(s):t.push(0),(n+1)%2==0&&(this.data[i]=t[0]<<4|t[1],t=[]),a}))}bit8(){const e=this.initColors(8);this.writeImage(((t,i)=>{let r=i;const n=createColor({quad:this.buffer[r++],blue:this.buffer[r++],green:this.buffer[r++],red:this.buffer[r++]}),a=e.findIndex((e=>e===n));return this.data[t]=-1!==a?a:0,r}))}bit16(){this.writeImage(((e,t)=>{let i=t+1;const r=this.buffer[i++]/8,n=this.buffer[i++]/8,a=this.buffer[i++]/8<<10|n<<5|r;return this.data[e]=255&a,this.data[e+1]=(65280&a)>>8,i}))}bit24(){this.writeImage(((e,t)=>{let i=t+1;return this.data[e]=this.buffer[i++],this.data[e+1]=this.buffer[i++],this.data[e+2]=this.buffer[i++],i}))}bit32(){this.writeImage(((e,t)=>{let i=t;return this.data[e+3]=this.buffer[i++],this.data[e]=this.buffer[i++],this.data[e+1]=this.buffer[i++],this.data[e+2]=this.buffer[i++],i}))}writeImage(e){const t=this.extraBytes+this.width*this.bytesInColor;let i=0;for(let r=0;r<this.height;r++)for(let n=0;n<this.width;n++){const a=Math.floor(this.pos+(this.height-1-r)*t+n*this.bytesInColor);i=e.call(this,a,i,n,r)}}initColors(e){const t=[];if(!this.palette.length)throw new Error(`To encode ${e}-bit BMPs a pallette is needed. Please choose up to ${this.colors} colors. Colors must be 32-bit integers.`);for(let e=0;e<this.colors;e++){const i=createColor(this.palette[e]);this.writeUInt32LE(i),t.push(i)}return t}writeUInt32LE(e){this.data.writeUInt32LE(e,this.pos),this.pos+=4}}function decode$2(e,t){return new BmpDecoder(e,t)}function encode$2(e){return new BmpEncoder(e)}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var trimLeft=/^\s+/,trimRight=/\s+$/;function tinycolor(e,t){if(t=t||{},(e=e||"")instanceof tinycolor)return e;if(!(this instanceof tinycolor))return new tinycolor(e,t);var i=inputToRGB(e);this._originalInput=e,this._r=i.r,this._g=i.g,this._b=i.b,this._a=i.a,this._roundA=Math.round(100*this._a)/100,this._format=t.format||i.format,this._gradientType=t.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=i.ok}function inputToRGB(e){var t={r:0,g:0,b:0},i=1,r=null,n=null,a=null,o=!1,s=!1;return"string"==typeof e&&(e=stringInputToObject(e)),"object"==_typeof(e)&&(isValidCSSUnit(e.r)&&isValidCSSUnit(e.g)&&isValidCSSUnit(e.b)?(t=rgbToRgb(e.r,e.g,e.b),o=!0,s="%"===String(e.r).substr(-1)?"prgb":"rgb"):isValidCSSUnit(e.h)&&isValidCSSUnit(e.s)&&isValidCSSUnit(e.v)?(r=convertToPercentage(e.s),n=convertToPercentage(e.v),t=hsvToRgb(e.h,r,n),o=!0,s="hsv"):isValidCSSUnit(e.h)&&isValidCSSUnit(e.s)&&isValidCSSUnit(e.l)&&(r=convertToPercentage(e.s),a=convertToPercentage(e.l),t=hslToRgb(e.h,r,a),o=!0,s="hsl"),e.hasOwnProperty("a")&&(i=e.a)),i=boundAlpha(i),{ok:o,format:e.format||s,r:Math.min(255,Math.max(t.r,0)),g:Math.min(255,Math.max(t.g,0)),b:Math.min(255,Math.max(t.b,0)),a:i}}function rgbToRgb(e,t,i){return{r:255*bound01(e,255),g:255*bound01(t,255),b:255*bound01(i,255)}}function rgbToHsl(e,t,i){e=bound01(e,255),t=bound01(t,255),i=bound01(i,255);var r,n,a=Math.max(e,t,i),o=Math.min(e,t,i),s=(a+o)/2;if(a==o)r=n=0;else{var l=a-o;switch(n=s>.5?l/(2-a-o):l/(a+o),a){case e:r=(t-i)/l+(t<i?6:0);break;case t:r=(i-e)/l+2;break;case i:r=(e-t)/l+4}r/=6}return{h:r,s:n,l:s}}function hslToRgb(e,t,i){var r,n,a;function o(e,t,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?e+6*(t-e)*i:i<.5?t:i<2/3?e+(t-e)*(2/3-i)*6:e}if(e=bound01(e,360),t=bound01(t,100),i=bound01(i,100),0===t)r=n=a=i;else{var s=i<.5?i*(1+t):i+t-i*t,l=2*i-s;r=o(l,s,e+1/3),n=o(l,s,e),a=o(l,s,e-1/3)}return{r:255*r,g:255*n,b:255*a}}function rgbToHsv(e,t,i){e=bound01(e,255),t=bound01(t,255),i=bound01(i,255);var r,n,a=Math.max(e,t,i),o=Math.min(e,t,i),s=a,l=a-o;if(n=0===a?0:l/a,a==o)r=0;else{switch(a){case e:r=(t-i)/l+(t<i?6:0);break;case t:r=(i-e)/l+2;break;case i:r=(e-t)/l+4}r/=6}return{h:r,s:n,v:s}}function hsvToRgb(e,t,i){e=6*bound01(e,360),t=bound01(t,100),i=bound01(i,100);var r=Math.floor(e),n=e-r,a=i*(1-t),o=i*(1-n*t),s=i*(1-(1-n)*t),l=r%6;return{r:255*[i,o,a,a,s,i][l],g:255*[s,i,i,o,a,a][l],b:255*[a,a,s,i,i,o][l]}}function rgbToHex(e,t,i,r){var n=[pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16))];return r&&n[0].charAt(0)==n[0].charAt(1)&&n[1].charAt(0)==n[1].charAt(1)&&n[2].charAt(0)==n[2].charAt(1)?n[0].charAt(0)+n[1].charAt(0)+n[2].charAt(0):n.join("")}function rgbaToHex(e,t,i,r,n){var a=[pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16)),pad2(convertDecimalToHex(r))];return n&&a[0].charAt(0)==a[0].charAt(1)&&a[1].charAt(0)==a[1].charAt(1)&&a[2].charAt(0)==a[2].charAt(1)&&a[3].charAt(0)==a[3].charAt(1)?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0):a.join("")}function rgbaToArgbHex(e,t,i,r){return[pad2(convertDecimalToHex(r)),pad2(Math.round(e).toString(16)),pad2(Math.round(t).toString(16)),pad2(Math.round(i).toString(16))].join("")}function _desaturate(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.s-=t/100,i.s=clamp01(i.s),tinycolor(i)}function _saturate(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.s+=t/100,i.s=clamp01(i.s),tinycolor(i)}function _greyscale(e){return tinycolor(e).desaturate(100)}function _lighten(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.l+=t/100,i.l=clamp01(i.l),tinycolor(i)}function _brighten(e,t){t=0===t?0:t||10;var i=tinycolor(e).toRgb();return i.r=Math.max(0,Math.min(255,i.r-Math.round(-t/100*255))),i.g=Math.max(0,Math.min(255,i.g-Math.round(-t/100*255))),i.b=Math.max(0,Math.min(255,i.b-Math.round(-t/100*255))),tinycolor(i)}function _darken(e,t){t=0===t?0:t||10;var i=tinycolor(e).toHsl();return i.l-=t/100,i.l=clamp01(i.l),tinycolor(i)}function _spin(e,t){var i=tinycolor(e).toHsl(),r=(i.h+t)%360;return i.h=r<0?360+r:r,tinycolor(i)}function _complement(e){var t=tinycolor(e).toHsl();return t.h=(t.h+180)%360,tinycolor(t)}function polyad(e,t){if(isNaN(t)||t<=0)throw new Error("Argument to polyad must be a positive number");for(var i=tinycolor(e).toHsl(),r=[tinycolor(e)],n=360/t,a=1;a<t;a++)r.push(tinycolor({h:(i.h+a*n)%360,s:i.s,l:i.l}));return r}function _splitcomplement(e){var t=tinycolor(e).toHsl(),i=t.h;return[tinycolor(e),tinycolor({h:(i+72)%360,s:t.s,l:t.l}),tinycolor({h:(i+216)%360,s:t.s,l:t.l})]}function _analogous(e,t,i){t=t||6,i=i||30;var r=tinycolor(e).toHsl(),n=360/i,a=[tinycolor(e)];for(r.h=(r.h-(n*t>>1)+720)%360;--t;)r.h=(r.h+n)%360,a.push(tinycolor(r));return a}function _monochromatic(e,t){t=t||6;for(var i=tinycolor(e).toHsv(),r=i.h,n=i.s,a=i.v,o=[],s=1/t;t--;)o.push(tinycolor({h:r,s:n,v:a})),a=(a+s)%1;return o}tinycolor.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var e=this.toRgb();return(299*e.r+587*e.g+114*e.b)/1e3},getLuminance:function(){var e,t,i,r=this.toRgb();return e=r.r/255,t=r.g/255,i=r.b/255,.2126*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.7152*(t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4))+.0722*(i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4))},setAlpha:function(e){return this._a=boundAlpha(e),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var e=rgbToHsv(this._r,this._g,this._b);return{h:360*e.h,s:e.s,v:e.v,a:this._a}},toHsvString:function(){var e=rgbToHsv(this._r,this._g,this._b),t=Math.round(360*e.h),i=Math.round(100*e.s),r=Math.round(100*e.v);return 1==this._a?"hsv("+t+", "+i+"%, "+r+"%)":"hsva("+t+", "+i+"%, "+r+"%, "+this._roundA+")"},toHsl:function(){var e=rgbToHsl(this._r,this._g,this._b);return{h:360*e.h,s:e.s,l:e.l,a:this._a}},toHslString:function(){var e=rgbToHsl(this._r,this._g,this._b),t=Math.round(360*e.h),i=Math.round(100*e.s),r=Math.round(100*e.l);return 1==this._a?"hsl("+t+", "+i+"%, "+r+"%)":"hsla("+t+", "+i+"%, "+r+"%, "+this._roundA+")"},toHex:function(e){return rgbToHex(this._r,this._g,this._b,e)},toHexString:function(e){return"#"+this.toHex(e)},toHex8:function(e){return rgbaToHex(this._r,this._g,this._b,this._a,e)},toHex8String:function(e){return"#"+this.toHex8(e)},toRgb:function(){return{r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:Math.round(100*bound01(this._r,255))+"%",g:Math.round(100*bound01(this._g,255))+"%",b:Math.round(100*bound01(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+Math.round(100*bound01(this._r,255))+"%, "+Math.round(100*bound01(this._g,255))+"%, "+Math.round(100*bound01(this._b,255))+"%)":"rgba("+Math.round(100*bound01(this._r,255))+"%, "+Math.round(100*bound01(this._g,255))+"%, "+Math.round(100*bound01(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":!(this._a<1)&&(hexNames[rgbToHex(this._r,this._g,this._b,!0)]||!1)},toFilter:function(e){var t="#"+rgbaToArgbHex(this._r,this._g,this._b,this._a),i=t,r=this._gradientType?"GradientType = 1, ":"";if(e){var n=tinycolor(e);i="#"+rgbaToArgbHex(n._r,n._g,n._b,n._a)}return"progid:DXImageTransform.Microsoft.gradient("+r+"startColorstr="+t+",endColorstr="+i+")"},toString:function(e){var t=!!e;e=e||this._format;var i=!1,r=this._a<1&&this._a>=0;return t||!r||"hex"!==e&&"hex6"!==e&&"hex3"!==e&&"hex4"!==e&&"hex8"!==e&&"name"!==e?("rgb"===e&&(i=this.toRgbString()),"prgb"===e&&(i=this.toPercentageRgbString()),"hex"!==e&&"hex6"!==e||(i=this.toHexString()),"hex3"===e&&(i=this.toHexString(!0)),"hex4"===e&&(i=this.toHex8String(!0)),"hex8"===e&&(i=this.toHex8String()),"name"===e&&(i=this.toName()),"hsl"===e&&(i=this.toHslString()),"hsv"===e&&(i=this.toHsvString()),i||this.toHexString()):"name"===e&&0===this._a?this.toName():this.toRgbString()},clone:function(){return tinycolor(this.toString())},_applyModification:function(e,t){var i=e.apply(null,[this].concat([].slice.call(t)));return this._r=i._r,this._g=i._g,this._b=i._b,this.setAlpha(i._a),this},lighten:function(){return this._applyModification(_lighten,arguments)},brighten:function(){return this._applyModification(_brighten,arguments)},darken:function(){return this._applyModification(_darken,arguments)},desaturate:function(){return this._applyModification(_desaturate,arguments)},saturate:function(){return this._applyModification(_saturate,arguments)},greyscale:function(){return this._applyModification(_greyscale,arguments)},spin:function(){return this._applyModification(_spin,arguments)},_applyCombination:function(e,t){return e.apply(null,[this].concat([].slice.call(t)))},analogous:function(){return this._applyCombination(_analogous,arguments)},complement:function(){return this._applyCombination(_complement,arguments)},monochromatic:function(){return this._applyCombination(_monochromatic,arguments)},splitcomplement:function(){return this._applyCombination(_splitcomplement,arguments)},triad:function(){return this._applyCombination(polyad,[3])},tetrad:function(){return this._applyCombination(polyad,[4])}},tinycolor.fromRatio=function(e,t){if("object"==_typeof(e)){var i={};for(var r in e)e.hasOwnProperty(r)&&(i[r]="a"===r?e[r]:convertToPercentage(e[r]));e=i}return tinycolor(e,t)},tinycolor.equals=function(e,t){return!(!e||!t)&&tinycolor(e).toRgbString()==tinycolor(t).toRgbString()},tinycolor.random=function(){return tinycolor.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})},tinycolor.mix=function(e,t,i){i=0===i?0:i||50;var r=tinycolor(e).toRgb(),n=tinycolor(t).toRgb(),a=i/100;return tinycolor({r:(n.r-r.r)*a+r.r,g:(n.g-r.g)*a+r.g,b:(n.b-r.b)*a+r.b,a:(n.a-r.a)*a+r.a})},tinycolor.readability=function(e,t){var i=tinycolor(e),r=tinycolor(t);return(Math.max(i.getLuminance(),r.getLuminance())+.05)/(Math.min(i.getLuminance(),r.getLuminance())+.05)},tinycolor.isReadable=function(e,t,i){var r,n,a=tinycolor.readability(e,t);switch(n=!1,(r=validateWCAG2Parms(i)).level+r.size){case"AAsmall":case"AAAlarge":n=a>=4.5;break;case"AAlarge":n=a>=3;break;case"AAAsmall":n=a>=7}return n},tinycolor.mostReadable=function(e,t,i){var r,n,a,o,s=null,l=0;n=(i=i||{}).includeFallbackColors,a=i.level,o=i.size;for(var u=0;u<t.length;u++)(r=tinycolor.readability(e,t[u]))>l&&(l=r,s=tinycolor(t[u]));return tinycolor.isReadable(e,s,{level:a,size:o})||!n?s:(i.includeFallbackColors=!1,tinycolor.mostReadable(e,["#fff","#000"],i))};var names$1=tinycolor.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de"