import fs from"fs";import zlib from"zlib";import{promisify}from"util";var range=function(t,e,i){for(var a=[],r=ts;r?h++:h--)a.push(h);return a},classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},createClass=function(){function t(t,e){for(var i=0;i0)for(e=0,r=0<=(s=h);r?es;r?e++:e--)this.transparency.indexed.push(255);break;case 0:this.transparency.grayscale=this.read(a)[0];break;case 2:this.transparency.rgb=this.read(a)}break;case"tEXt":var o=this.read(a),n=o.indexOf(0),c=String.fromCharCode.apply(String,toConsumableArray(Array.from(o.slice(0,n)||[])));this.text[c]=String.fromCharCode.apply(String,toConsumableArray(Array.from(o.slice(n+1)||[])));break;case"IEND":this.colors=function(){switch(t.colorType){case 0:case 3:case 4:return 1;case 2:case 6:return 3}}(),this.hasAlphaChannel=[4,6].includes(this.colorType);var l=this.colors+(this.hasAlphaChannel?1:0);return this.pixelBitlength=this.bits*l,this.colorSpace=function(){switch(t.colors){case 1:return"DeviceGray";case 3:return"DeviceRGB"}}(),void(this.imgData=Buffer.from(this.imgData));default:this.pos+=a}if(this.pos+=4,this.pos>this.data.length)throw new Error("Incomplete or corrupt IndexedPNG file")}}},{key:"read",value:function(t){var e=this;return range(0,t,!1).map(function(t){return e.data[e.pos++]})}},{key:"readUInt32",value:function(){return this.data[this.pos++]<<24|this.data[this.pos++]<<16|this.data[this.pos++]<<8|this.data[this.pos++]}},{key:"readUInt16",value:function(){return this.data[this.pos++]<<8|this.data[this.pos++]}},{key:"decodePixels",value:async function(){var t=void 0;try{t=await inflateAsync(this.imgData)}catch(t){throw t}for(var e=this.pixelBitlength/8,i=e*this.width,a=Buffer.allocUnsafe(i*this.height),r=t.length,s=0,h=0,o=0;h=this.width)throw new Error("clip.x is out of bounds");if(t.clip.y<0||t.clip.y>=this.height)throw new Error("clip.y is out of bounds");if(t.clip.w<=0||t.clip.w>this.width)throw new Error("clip.w is out of bounds");if(t.clip.h<=0||t.clip.h>this.height)throw new Error("clip.h is out of bounds");for(var i=new Uint8ClampedArray(t.clip.w*t.clip.h*4),a=0;a