>>=x,p-=x),p<15&&(m+=E[i++]<>>24,m>>>=x,p-=x,x=_>>>16&255,!(16&x)){if(0==(64&x)){_=f[(65535&_)+(m&(1<d){e.msg="invalid distance too far back",R.mode=Go;break e}if(m>>>=x,p-=x,x=o-r,y>x){if(x=y-x,x>l&&R.sane){e.msg="invalid distance too far back",R.mode=Go;break e}if(w=0,k=h,0===c){if(w+=s-x,x2;)I[o++]=k[w++],I[o++]=k[w++],I[o++]=k[w++],v-=3;v&&(I[o++]=k[w++],v>1&&(I[o++]=k[w++]))}else{w=o-y;do{I[o++]=I[w++],I[o++]=I[w++],I[o++]=I[w++],v-=3}while(v>2);v&&(I[o++]=I[w++],v>1&&(I[o++]=I[w++]))}break}}break}}while(i>3,i-=v,p-=v<<3,m&=(1<{const s=d.bits;let l,c,h,m,p,u,f=0,g=0,b=0,_=0,x=0,v=0,y=0,w=0,k=0,E=0,I=null;const R=new Uint16Array(16),C=new Uint16Array(16);let A,T,S,O=null;for(f=0;f<=jo;f++)R[f]=0;for(g=0;g=1&&0===R[_];_--);if(x>_&&(x=_),0===_)return o[r++]=20971520,o[r++]=20971520,d.bits=1,0;for(b=1;b<_&&0===R[b];b++);for(x0&&(0===e||1!==_))return-1;for(C[1]=0,f=1;f852||2===e&&k>592)return 1;for(;;){A=f-y,a[g]+1=u?(T=O[a[g]-u],S=I[a[g]-u]):(T=96,S=0),l=1<>y)+c]=A<<24|T<<16|S|0}while(0!==c);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,g++,0==--R[f]){if(f===_)break;f=t[i+a[g]]}if(f>x&&(E&m)!==h){for(0===y&&(y=x),p+=b,v=f-y,w=1<852||2===e&&k>592)return 1;h=E&m,o[h]=x<<24|v<<16|p-r|0}}return 0!==E&&(o[p+E]=f-y<<24|64<<16|0),d.bits=x,0};const{Z_FINISH:Jo,Z_BLOCK:er,Z_TREES:tr,Z_OK:ir,Z_STREAM_END:nr,Z_NEED_DICT:or,Z_STREAM_ERROR:rr,Z_DATA_ERROR:ar,Z_MEM_ERROR:dr,Z_BUF_ERROR:sr,Z_DEFLATED:lr}=In,cr=16180,hr=16190,mr=16191,pr=16192,ur=16194,fr=16199,gr=16200,br=16206,_r=16209,xr=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function vr(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const yr=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode16211?1:0},wr=e=>{if(yr(e))return rr;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=cr,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,ir},kr=e=>{if(yr(e))return rr;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,wr(e)},Er=(e,t)=>{let i;if(yr(e))return rr;const n=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?rr:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,kr(e))},Ir=(e,t)=>{if(!e)return rr;const i=new vr;e.state=i,i.strm=e,i.window=null,i.mode=cr;const n=Er(e,t);return n!==ir&&(e.state=null),n};let Rr,Cr,Ar=!0;const Tr=e=>{if(Ar){Rr=new Int32Array(512),Cr=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Qo(1,e.lens,0,288,Rr,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Qo(2,e.lens,0,32,Cr,0,e.work,{bits:5}),Ar=!1}e.lencode=Rr,e.lenbits=9,e.distcode=Cr,e.distbits=5},Sr=(e,t,i,n)=>{let o;const r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(r.window.set(t.subarray(i-r.wsize,i),0),r.wnext=0,r.whave=r.wsize):(o=r.wsize-r.wnext,o>n&&(o=n),r.window.set(t.subarray(i-n,i-n+o),r.wnext),(n-=o)?(r.window.set(t.subarray(i-n,i),0),r.wnext=n,r.whave=r.wsize):(r.wnext+=o,r.wnext===r.wsize&&(r.wnext=0),r.whave{let i,n,o,r,a,d,s,l,c,h,m,p,u,f,g,b,_,x,v,y,w,k,E=0;const I=new Uint8Array(4);let R,C;const A=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(yr(e)||!e.output||!e.input&&0!==e.avail_in)return rr;i=e.state,i.mode===mr&&(i.mode=pr),a=e.next_out,o=e.output,s=e.avail_out,r=e.next_in,n=e.input,d=e.avail_in,l=i.hold,c=i.bits,h=d,m=s,k=ir;e:for(;;)switch(i.mode){case cr:if(0===i.wrap){i.mode=pr;break}for(;c<16;){if(0===d)break e;d--,l+=n[r++]<>>8&255,i.check=kn(i.check,I,2,0),l=0,c=0,i.mode=16181;break}if(i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){e.msg="incorrect header check",i.mode=_r;break}if((15&l)!==lr){e.msg="unknown compression method",i.mode=_r;break}if(l>>>=4,c-=4,w=8+(15&l),0===i.wbits&&(i.wbits=w),w>15||w>i.wbits){e.msg="invalid window size",i.mode=_r;break}i.dmax=1<>8&1),512&i.flags&&4&i.wrap&&(I[0]=255&l,I[1]=l>>>8&255,i.check=kn(i.check,I,2,0)),l=0,c=0,i.mode=16182;case 16182:for(;c<32;){if(0===d)break e;d--,l+=n[r++]<>>8&255,I[2]=l>>>16&255,I[3]=l>>>24&255,i.check=kn(i.check,I,4,0)),l=0,c=0,i.mode=16183;case 16183:for(;c<16;){if(0===d)break e;d--,l+=n[r++]<>8),512&i.flags&&4&i.wrap&&(I[0]=255&l,I[1]=l>>>8&255,i.check=kn(i.check,I,2,0)),l=0,c=0,i.mode=16184;case 16184:if(1024&i.flags){for(;c<16;){if(0===d)break e;d--,l+=n[r++]<>>8&255,i.check=kn(i.check,I,2,0)),l=0,c=0}else i.head&&(i.head.extra=null);i.mode=16185;case 16185:if(1024&i.flags&&(p=i.length,p>d&&(p=d),p&&(i.head&&(w=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(r,r+p),w)),512&i.flags&&4&i.wrap&&(i.check=kn(i.check,n,p,r)),d-=p,r+=p,i.length-=p),i.length))break e;i.length=0,i.mode=16186;case 16186:if(2048&i.flags){if(0===d)break e;p=0;do{w=n[r+p++],i.head&&w&&i.length<65536&&(i.head.name+=String.fromCharCode(w))}while(w&&p>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=mr;break;case 16189:for(;c<32;){if(0===d)break e;d--,l+=n[r++]<>>=7&c,c-=7&c,i.mode=br;break}for(;c<3;){if(0===d)break e;d--,l+=n[r++]<>>=1,c-=1,3&l){case 0:i.mode=16193;break;case 1:if(Tr(i),i.mode=fr,t===tr){l>>>=2,c-=2;break e}break;case 2:i.mode=16196;break;case 3:e.msg="invalid block type",i.mode=_r}l>>>=2,c-=2;break;case 16193:for(l>>>=7&c,c-=7&c;c<32;){if(0===d)break e;d--,l+=n[r++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=_r;break}if(i.length=65535&l,l=0,c=0,i.mode=ur,t===tr)break e;case ur:i.mode=16195;case 16195:if(p=i.length,p){if(p>d&&(p=d),p>s&&(p=s),0===p)break e;o.set(n.subarray(r,r+p),a),d-=p,r+=p,s-=p,a+=p,i.length-=p;break}i.mode=mr;break;case 16196:for(;c<14;){if(0===d)break e;d--,l+=n[r++]<>>=5,c-=5,i.ndist=1+(31&l),l>>>=5,c-=5,i.ncode=4+(15&l),l>>>=4,c-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=_r;break}i.have=0,i.mode=16197;case 16197:for(;i.have>>=3,c-=3}for(;i.have<19;)i.lens[A[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,R={bits:i.lenbits},k=Qo(0,i.lens,0,19,i.lencode,0,i.work,R),i.lenbits=R.bits,k){e.msg="invalid code lengths set",i.mode=_r;break}i.have=0,i.mode=16198;case 16198:for(;i.have>>24,b=E>>>16&255,_=65535&E,!(g<=c);){if(0===d)break e;d--,l+=n[r++]<>>=g,c-=g,i.lens[i.have++]=_;else{if(16===_){for(C=g+2;c>>=g,c-=g,0===i.have){e.msg="invalid bit length repeat",i.mode=_r;break}w=i.lens[i.have-1],p=3+(3&l),l>>>=2,c-=2}else if(17===_){for(C=g+3;c>>=g,c-=g,w=0,p=3+(7&l),l>>>=3,c-=3}else{for(C=g+7;c>>=g,c-=g,w=0,p=11+(127&l),l>>>=7,c-=7}if(i.have+p>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=_r;break}for(;p--;)i.lens[i.have++]=w}}if(i.mode===_r)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=_r;break}if(i.lenbits=9,R={bits:i.lenbits},k=Qo(1,i.lens,0,i.nlen,i.lencode,0,i.work,R),i.lenbits=R.bits,k){e.msg="invalid literal/lengths set",i.mode=_r;break}if(i.distbits=6,i.distcode=i.distdyn,R={bits:i.distbits},k=Qo(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,R),i.distbits=R.bits,k){e.msg="invalid distances set",i.mode=_r;break}if(i.mode=fr,t===tr)break e;case fr:i.mode=gr;case gr:if(d>=6&&s>=258){e.next_out=a,e.avail_out=s,e.next_in=r,e.avail_in=d,i.hold=l,i.bits=c,Xo(e,m),a=e.next_out,o=e.output,s=e.avail_out,r=e.next_in,n=e.input,d=e.avail_in,l=i.hold,c=i.bits,i.mode===mr&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,_=65535&E,!(g<=c);){if(0===d)break e;d--,l+=n[r++]<>x)],g=E>>>24,b=E>>>16&255,_=65535&E,!(x+g<=c);){if(0===d)break e;d--,l+=n[r++]<>>=x,c-=x,i.back+=x}if(l>>>=g,c-=g,i.back+=g,i.length=_,0===b){i.mode=16205;break}if(32&b){i.back=-1,i.mode=mr;break}if(64&b){e.msg="invalid literal/length code",i.mode=_r;break}i.extra=15&b,i.mode=16201;case 16201:if(i.extra){for(C=i.extra;c>>=i.extra,c-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=16202;case 16202:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,_=65535&E,!(g<=c);){if(0===d)break e;d--,l+=n[r++]<>x)],g=E>>>24,b=E>>>16&255,_=65535&E,!(x+g<=c);){if(0===d)break e;d--,l+=n[r++]<>>=x,c-=x,i.back+=x}if(l>>>=g,c-=g,i.back+=g,64&b){e.msg="invalid distance code",i.mode=_r;break}i.offset=_,i.extra=15&b,i.mode=16203;case 16203:if(i.extra){for(C=i.extra;c>>=i.extra,c-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=_r;break}i.mode=16204;case 16204:if(0===s)break e;if(p=m-s,i.offset>p){if(p=i.offset-p,p>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=_r;break}p>i.wnext?(p-=i.wnext,u=i.wsize-p):u=i.wnext-p,p>i.length&&(p=i.length),f=i.window}else f=o,u=a-i.offset,p=i.length;p>s&&(p=s),s-=p,i.length-=p;do{o[a++]=f[u++]}while(--p);0===i.length&&(i.mode=gr);break;case 16205:if(0===s)break e;o[a++]=i.length,s--,i.mode=gr;break;case br:if(i.wrap){for(;c<32;){if(0===d)break e;d--,l|=n[r++]<Ir(e,15),inflateInit2:Ir,inflate:Or,inflateEnd:e=>{if(yr(e))return rr;let t=e.state;return t.window&&(t.window=null),e.state=null,ir},inflateGetHeader:(e,t)=>{if(yr(e))return rr;const i=e.state;return 0==(2&i.wrap)?rr:(i.head=t,t.done=!1,ir)},inflateSetDictionary:(e,t)=>{const i=t.length;let n,o,r;return yr(e)?rr:(n=e.state,0!==n.wrap&&n.mode!==hr?rr:n.mode===hr&&(o=1,o=yn(o,t,i,0),o!==n.check)?ar:(r=Sr(e,t,i,i),r?(n.mode=16210,dr):(n.havedict=1,ir)))},inflateInfo:"pako inflate (from Nodeca project)"};var Fr=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const zr=Object.prototype.toString,{Z_NO_FLUSH:Dr,Z_FINISH:Br,Z_OK:Nr,Z_STREAM_END:$r,Z_NEED_DICT:Mr,Z_STREAM_ERROR:Ur,Z_DATA_ERROR:Pr,Z_MEM_ERROR:Hr}=In;function Vr(e){this.options=Co.assign({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Oo,this.strm.avail_out=0;let i=Lr.inflateInit2(this.strm,t.windowBits);if(i!==Nr)throw new Error(En[i]);if(this.header=new Fr,Lr.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=So.string2buf(t.dictionary):"[object ArrayBuffer]"===zr.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Lr.inflateSetDictionary(this.strm,t.dictionary),i!==Nr)))throw new Error(En[i])}Vr.prototype.push=function(e,t){const i=this.strm,n=this.options.chunkSize,o=this.options.dictionary;let r,a,d;if(this.ended)return!1;for(a=t===~~t?t:!0===t?Br:Dr,"[object ArrayBuffer]"===zr.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),r=Lr.inflate(i,a),r===Mr&&o&&(r=Lr.inflateSetDictionary(i,o),r===Nr?r=Lr.inflate(i,a):r===Pr&&(r=Mr));i.avail_in>0&&r===$r&&i.state.wrap>0&&0!==e[i.next_in];)Lr.inflateReset(i),r=Lr.inflate(i,a);switch(r){case Ur:case Pr:case Mr:case Hr:return this.onEnd(r),this.ended=!0,!1}if(d=i.avail_out,i.next_out&&(0===i.avail_out||r===$r))if("string"===this.options.to){let e=So.utf8border(i.output,i.next_out),t=i.next_out-e,o=So.buf2string(i.output,e);i.next_out=t,i.avail_out=n-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(o)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(r!==Nr||0!==d){if(r===$r)return r=Lr.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Vr.prototype.onData=function(e){this.chunks.push(e)},Vr.prototype.onEnd=function(e){e===Nr&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Co.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};const{Deflate:Wr,deflate:Gr,deflateRaw:Xr,gzip:jr}=Wo;var Yr=Gr;const qr={b:{u:DataView.prototype.getInt8,p:DataView.prototype.setInt8,bytes:1},B:{u:DataView.prototype.getUint8,p:DataView.prototype.setUint8,bytes:1},h:{u:DataView.prototype.getInt16,p:DataView.prototype.setInt16,bytes:2},H:{u:DataView.prototype.getUint16,p:DataView.prototype.setUint16,bytes:2},i:{u:DataView.prototype.getInt32,p:DataView.prototype.setInt32,bytes:4},I:{u:DataView.prototype.getUint32,p:DataView.prototype.setUint32,bytes:4},q:{u:DataView.prototype.getInt64,p:DataView.prototype.setInt64,bytes:8},Q:{u:DataView.prototype.getUint64,p:DataView.prototype.setUint64,bytes:8}},Zr=(e,...t)=>{let i=0;if(e.replace(/[<>]/,"").length!=t.length)throw"Pack format to Argument count mismatch";let n=[],o=!0;for(let n=0;n"==e[n]?o=!1:(r(e[n],t[i]),i++);function r(e,t){if(!(e in qr))throw"Unhandled character '"+e+"' in pack format";let i=qr[e].bytes,r=new DataView(new ArrayBuffer(i));qr[e].p.bind(r)(0,t,o);for(let e=0;e{let i=0,n=[],o=!0;for(let t of e)"<"==t?o=!0:">"==t?o=!1:r(t);function r(e){if(!(e in qr))throw"Unhandled character '"+e+"' in unpack format";let r=qr[e].bytes,a=new DataView(new ArrayBuffer(r));for(let e=0;e>>0];if(void 0===t)throw new Error(`Unknown Chip: Hex: ${ui(e>>>0,8).toLowerCase()} Number: ${e}`);this.chipName=t.name,this.chipFamily=t.family;let i=Si(this.getChipFamily()).macFuse;for(let e=0;e<4;e++)this._efuses[e]=await this.readRegister(i+4*e);this.logger.log(`Chip type ${this.chipName}`)}async readLoop(){this.debug&&this.logger.debug("Starting read loop"),this._reader=this.port.readable.getReader();try{for(;;){const{value:e,done:t}=await this._reader.read();if(t){this._reader.releaseLock();break}e&&0!==e.length&&this._inputBuffer.push(...Array.from(e))}}catch(e){console.error("Read loop got disconnected")}this.connected=!1,this.dispatchEvent(new Event("disconnect")),this.logger.debug("Finished read loop")}sleep(e=100){return new Promise((t=>setTimeout(t,e)))}async setRTS(e){await this.port.setSignals({requestToSend:e}),await this.setDTR(this.state_DTR)}async setDTR(e){this.state_DTR=e,await this.port.setSignals({dataTerminalReady:e})}async hardReset(e=!1){this.logger.log("Try hard reset."),e?4097===this.port.getInfo().usbProductId?(await this.setDTR(!1),await this.setRTS(!1),await this.sleep(100),await this.setDTR(!0),await this.setRTS(!1),await this.sleep(100),await this.setRTS(!0),await this.setDTR(!1),await this.setRTS(!0),await this.sleep(100),await this.setDTR(!1),await this.setRTS(!1)):(await this.setDTR(!1),await this.setRTS(!0),await this.sleep(100),await this.setDTR(!0),await this.setRTS(!1),await this.sleep(50),await this.setDTR(!1)):(await this.setRTS(!0),await this.sleep(100),await this.setRTS(!1)),await new Promise((e=>setTimeout(e,1e3)))}macAddr(){let e,t=new Array(6).fill(0),i=this._efuses[0],n=this._efuses[1],o=this._efuses[2],r=this._efuses[3];if(this.chipFamily==_i){if(0!=r)e=[r>>16&255,r>>8&255,255&r];else if(0==(n>>16&255))e=[24,254,52];else{if(1!=(n>>16&255))throw new Error("Couldnt determine OUI");e=[172,208,116]}t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=n>>8&255,t[4]=255&n,t[5]=i>>24&255}else if(this.chipFamily==xi)t[0]=o>>8&255,t[1]=255&o,t[2]=n>>24&255,t[3]=n>>16&255,t[4]=n>>8&255,t[5]=255&n;else{if(this.chipFamily!=vi&&this.chipFamily!=yi&&this.chipFamily!=wi&&this.chipFamily!=ki&&this.chipFamily!=Ei&&this.chipFamily!=Ii)throw new Error("Unknown chip family");t[0]=n>>8&255,t[1]=255&n,t[2]=i>>24&255,t[3]=i>>16&255,t[4]=i>>8&255,t[5]=255&i}return t}async readRegister(e){this.debug&&this.logger.debug("Reading from Register "+ui(e,8));let t=Zr("{let t=[192];for(let i of e)219==i?t=t.concat([219,221]):192==i?t=t.concat([219,220]):t.push(i);return t.push(192),t})([...Zr("0){n.push(this._inputBuffer.shift());break}await fi(10)}if(0==n.length){throw new Oi("Timed out waiting for packet "+(null===t?"header":"content"))}this.debug&&this.logger.debug("Read "+n.length+" bytes: "+pi(n));for(let e of n)if(null===t){if(192!=e)throw this.debug&&(this.logger.debug("Read invalid data: "+pi(n)),this.logger.debug("Remaining data in serial buffer: "+pi(this._inputBuffer))),new Oi("Invalid head of packet ("+ui(e)+")");t=[]}else if(i)if(i=!1,220==e)t.push(192);else{if(221!=e)throw this.debug&&(this.logger.debug("Read invalid data: "+pi(n)),this.logger.debug("Remaining data in serial buffer: "+pi(this._inputBuffer))),new Oi("Invalid SLIP escape (0xdb, "+ui(e)+")");t.push(219)}else if(219==e)i=!0;else{if(192==e)return this.debug&&this.logger.debug("Received full packet: "+pi(t)),t;t.push(e)}}throw new Oi("Invalid state")}async getResponse(e,t=3e3){for(let i=0;i<100;i++){const i=await this.readPacket(t);if(i.length<8)continue;const[n,o,r,a]=Kr("1&&0==t[0]&&0==t[1])return!0}catch(e){}return!1}getFlashWriteSize(){return this.IS_STUB?16384:1024}async flashData(e,t,i=0,n=!1){if(e.byteLength>=8){var o=Array.from(new Uint8Array(e,0,4));let t=o[0],i=o[2],n=o[3];this.logger.log(`Image header, Magic=${ui(t)}, FlashMode=${ui(i)}, FlashSizeFreq=${ui(n)}`)}let r,a=e.byteLength,d=0,s=Ci;n?(r=Yr(new Uint8Array(e),{level:9}).buffer,d=r.byteLength,this.logger.log(`Writing data with filesize: ${a}. Compressed Size: ${d}`),s=await this.flashDeflBegin(a,d,i)):(this.logger.log(`Writing data with filesize: ${a}`),r=e,await this.flashBegin(a,i));let l=[],c=0,h=0,m=0,p=Date.now(),u=this.getFlashWriteSize(),f=n?d:a;for(;f-m>0;)this.debug&&this.logger.log(`Writing at ${ui(i+c*u,8)} `),f-m>=u?l=Array.from(new Uint8Array(r,m,u)):(l=Array.from(new Uint8Array(r,m,f-m)),n||(l=l.concat(new Array(u-l.length).fill(255)))),n?await this.flashDeflBlock(l,c,s):await this.flashBlock(l,c),c+=1,h+=n?Math.round(l.length*a/d):l.length,m+=u,t(Math.min(h,a),a);this.logger.log("Took "+(Date.now()-p)+"ms to write "+f+" bytes"),this.IS_STUB&&(await this.flashBegin(0,0),n?await this.flashDeflFinish():await this.flashFinish())}async flashBlock(e,t,i=3e3){await this.checkCommand(3,Zr("0&&r.concat(Zr("0&&await this.writeRegister(n,t-1),i>0&&await this.writeRegister(o,i-1)}else{let n=e.regBase+e.usr1Offs,o=(0==i?0:i-1)<<8|(0==t?0:t-1)<<17;await this.writeRegister(n,o)}}async waitDone(e,t){for(let i=0;i<10;i++){if(0==(await this.readRegister(e)&t))return}throw Error("SPI command did not complete in time")}async runSpiFlashCommand(e,t,i=0){let n=Si(this.getChipFamily()),o=n.regBase,r=o,a=o+n.usrOffs,d=o+n.usr2Offs,s=o+n.w0Offs,l=1<<18;if(i>32)throw new Error("Reading more than 32 bits back from a SPI flash operation is unsupported");if(t.length>64)throw new Error("Writing more than 64 bytes of data with one SPI command is unsupported");let c=8*t.length,h=await this.readRegister(a),m=await this.readRegister(d),p=1<<31;if(i>0&&(p|=268435456),c>0&&(p|=134217728),await this.setDataLengths(n,c,i),await this.writeRegister(a,p),await this.writeRegister(d,7<<28|e),0==c)await this.writeRegister(s,0);else{t.concat(new Array(t.length%4).fill(0));let e=Kr("I".repeat(Math.floor(t.length/4)),t),i=s;this.logger.debug(`Words Length: ${e.length}`);for(const t of e)this.logger.debug(`Writing word ${ui(t)} to register offset ${ui(i)}`),await this.writeRegister(i,t),i+=4}await this.writeRegister(r,l),await this.waitDone(r,l);let u=await this.readRegister(s);return await this.writeRegister(a,h),await this.writeRegister(d,m),u}async detectFlashSize(){this.logger.log("Detecting Flash Size");let e=await this.flashId(),t=255&e,i=e>>16&255;this.logger.log(`FlashId: ${ui(e)}`),this.logger.log(`Flash Manufacturer: ${t.toString(16)}`),this.logger.log(`Flash Device: ${(e>>8&255).toString(16)}${i.toString(16)}`),this.flashSize=gi[i],this.logger.log(`Auto-detected Flash size: ${this.flashSize}`)}getEraseSize(e,t){let i=4096,n=Math.floor((t+i-1)/i),o=16-Math.floor(e/i)%16;return no&&(a=o),await this.memBlock(e[t].slice(r,a),n)}}this.logger.log("Running stub..."),await this.memFinish(e.entry);const n=await this.readPacket(500);if(t=String.fromCharCode(...n),"OHAI"!=t)throw new Error("Failed to start stub. Unexpected response: "+t);this.logger.log("Stub is now running...");const o=new Jr(this.port,this.logger,this);return await o.detectFlashSize(),o}async writeToStream(e){const t=this.port.writable.getWriter();await t.write(new Uint8Array(e));try{t.releaseLock()}catch(e){console.error("Ignoring release lock error",e)}}async disconnect(){this._parent?await this._parent.disconnect():(await this.port.writable.getWriter().close(),await new Promise((e=>{this._reader||e(void 0),this.addEventListener("disconnect",e,{once:!0}),this._reader.cancel()})),this.connected=!1)}}class Jr extends Qr{constructor(){super(...arguments),this.IS_STUB=!0}async memBegin(e,t,i,n){let o=await Li(this.chipFamily),r=n,a=n+e;console.log(r,a),console.log(o.data_start,o.data.length,o.text_start,o.text.length);for(let[e,t]of[[o.data_start,o.data_start+o.data.length],[o.text_start,o.text_start+o.text.length]])if(re)throw new Error("Software loader is resident at "+ui(e,8)+"-"+ui(t,8)+". Can't load binary at overlapping address range "+ui(r,8)+"-"+ui(a,8)+". Try changing the binary loading address.")}async eraseFlash(){await this.checkCommand(208,[],0,Ai)}}const ea=async(e,t,i,n,o,r)=>{let a,d,s;const l=t=>e({...t,manifest:a,build:d,chipFamily:s});var c=null,h="";try{c=JSON.parse(n)}catch{h=new URL(n,location.toString()).toString(),c=fetch(h).then((e=>e.json()))}const m=new Qr(t,i);window.esploader=m,l({state:"initializing",message:"Initializing...",details:{done:!1}});try{await m.initialize()}catch(e){return i.error(e),l({state:"error",message:"Failed to initialize. Try resetting your device or holding the BOOT button while clicking INSTALL.",details:{error:"failed_initialize",details:e}}),void(m.connected&&await m.disconnect())}s=(e=>{switch(e.chipFamily){case xi:return"ESP32";case vi:return"ESP32-S2";case yi:return"ESP32-S3";case wi:return"ESP32-C2";case ki:return"ESP32-C3";case Ei:return"ESP32-C6";case Ii:return"ESP32-H2";case _i:return"ESP8266";default:return"Unknown Chip"}})(m),l({state:"initializing",message:`Initialized. Found ${s}`,details:{done:!0}}),l({state:"manifest",message:"Fetching manifest...",details:{done:!1}});try{a=await c}catch(e){return l({state:"error",message:`Unable to fetch manifest: ${e}`,details:{error:"fetch_manifest_failed",details:e}}),void await m.disconnect()}if(d=a.builds.find((e=>e.chipFamily===s)),l({state:"manifest",message:`Found manifest for ${a.name}`,details:{done:!0}}),!d)return l({state:"error",message:`Your ${s} board is not supported.`,details:{error:"not_supported",details:s}}),void await m.disconnect();l({state:"preparing",message:"Preparing installation...",details:{done:!1}});const p=d.parts.map((async e=>{if(0==r.length){const t=new URL(e.path,h).toString(),i=await fetch(t);if(!i.ok)throw new Error(`Downlading firmware ${e.path} failed: ${i.status}`);return i.arrayBuffer()}return r})),u=await m.runStub(),f=[];let g=0;for(const e of p)try{const t=await e;f.push(t),g+=t.byteLength}catch(e){return l({state:"error",message:e.message,details:{error:"failed_firmware_download",details:e.message}}),void await m.disconnect()}l({state:"preparing",message:"Installation prepared",details:{done:!0}}),o&&(l({state:"erasing",message:"Erasing device...",details:{done:!1}}),await u.eraseFlash(),l({state:"erasing",message:"Device erased",details:{done:!0}}));let b=0;l({state:"writing",message:`Writing progress: ${b}%`,details:{bytesTotal:g,bytesWritten:0,percentage:b}});let _=0;for(const e of d.parts){const t=f.shift();try{await u.flashData(t,(e=>{const t=Math.floor((_+e)/g*100);t!==b&&(b=t,l({state:"writing",message:`Writing progress: ${t}%`,details:{bytesTotal:g,bytesWritten:_+e,percentage:t}}))}),e.offset,!0)}catch(e){return l({state:"error",message:e.message,details:{error:"write_failed",details:e}}),void await m.disconnect()}_+=t.byteLength}l({state:"writing",message:"Writing complete",details:{bytesTotal:g,bytesWritten:_,percentage:100}}),await V(100),console.log("DISCONNECT"),await m.disconnect(),console.log("HARD RESET"),await m.hardReset(),l({state:"finished",message:"All done!"})},ta=(e,t="")=>{const i=new Blob([e],{type:"text/plain"}),n=URL.createObjectURL(i);((e,t="")=>{const i=document.createElement("a");i.target="_blank",i.href=e,i.download=t,document.body.appendChild(i),i.dispatchEvent(new MouseEvent("click")),document.body.removeChild(i)})(n,t),setTimeout((()=>URL.revokeObjectURL(n)),0)};class ia extends x{constructor(){super(...arguments),this.logger=console,this._state="DASHBOARD",this._installErase=!1,this._installConfirmed=!1,this._provisionForce=!1,this._wasProvisioned=!1,this._busy=!1,this._selectedSsid=-1,this._handleDisconnect=()=>{this._state="ERROR",this._error="Disconnected"}}render(){if(!this.port)return h``;let e,t,i=!1,n=!1;return void 0===this._client&&"INSTALL"!==this._state&&"LOGS"!==this._state?this._error?[e,t,i]=this._renderError(this._error):(t=this._renderProgress("Connecting"),i=!0):"INSTALL"===this._state?[e,t,i,n]=this._renderInstall():"ASK_ERASE"===this._state?[e,t]=this._renderAskErase():"ERROR"===this._state?[e,t,i]=this._renderError(this._error):"DASHBOARD"===this._state?[e,t,i,n]=this._client?this._renderDashboard():this._renderDashboardNoImprov():"PROVISION"===this._state?[e,t,i]=this._renderProvision():"LOGS"===this._state&&([e,t,i]=this._renderLogs()),h`
+`,ri=["I".charCodeAt(0),"M".charCodeAt(0),"P".charCodeAt(0),"R".charCodeAt(0),"O".charCodeAt(0),"V".charCodeAt(0),1];var ai,di;!function(e){e[e.CURRENT_STATE=1]="CURRENT_STATE",e[e.ERROR_STATE=2]="ERROR_STATE",e[e.RPC=3]="RPC",e[e.RPC_RESULT=4]="RPC_RESULT"}(ai||(ai={})),function(e){e[e.READY=2]="READY",e[e.PROVISIONING=3]="PROVISIONING",e[e.PROVISIONED=4]="PROVISIONED"}(di||(di={}));const si={0:"NO_ERROR",1:"INVALID_RPC_PACKET",2:"UNKNOWN_RPC_COMMAND",3:"UNABLE_TO_CONNECT",254:"TIMEOUT",255:"UNKNOWN_ERROR"};class li extends Error{constructor(){super("Port is not ready")}}const ci=e=>"["+e.map((e=>((e,t=2)=>{let i=e.toString(16).toUpperCase();return i.startsWith("-")?"-0x"+i.substring(1).padStart(t,"0"):"0x"+i.padStart(t,"0")})(e))).join(", ")+"]";class hi extends EventTarget{constructor(e,t){if(super(),this.port=e,this.logger=t,this.error=0,null===e.readable)throw new Error("Port is not readable");if(null===e.writable)throw new Error("Port is not writable")}async initialize(e=1e3){var t;if(this.logger.log("Initializing Improv Serial"),this._processInput(),await(t=1e3,new Promise((e=>setTimeout(e,t)))),void 0===this._reader)throw new li;try{await new Promise((async(t,i)=>{setTimeout((()=>i(new Error("Improv Wi-Fi Serial not detected"))),e),await this.requestCurrentState(),t(void 0)})),await this.requestInfo()}catch(e){throw await this.close(),e}return this.info}async close(){this._reader&&await new Promise((e=>{this._reader.cancel(),this.addEventListener("disconnect",e,{once:!0})}))}async requestCurrentState(){let e;try{await new Promise((async(t,i)=>{this.addEventListener("state-changed",t,{once:!0});e=this._sendRPCWithResponse(2,[]),e.catch((e=>{this.removeEventListener("state-changed",t),i(e)}))}))}catch(e){throw this._rpcFeedback=void 0,new Error(`Error fetching current state: ${e}`)}if(this.state!==di.PROVISIONED)return void(this._rpcFeedback=void 0);const t=await e;this.nextUrl=t[0]}async requestInfo(e){const t=await this._sendRPCWithResponse(3,[],e);this.info={firmware:t[0],version:t[1],name:t[3],chipFamily:t[2]}}async provision(e,t,i){const n=new TextEncoder,o=n.encode(e),r=n.encode(t),a=[o.length,...o,r.length,...r],d=await this._sendRPCWithResponse(1,a,i);this.nextUrl=d[0]}async scan(){const e=(await this._sendRPCWithMultipleResponses(4,[])).map((([e,t,i])=>({name:e,rssi:parseInt(t),secured:"YES"===i})));return e.sort(((e,t)=>e.name.toLocaleLowerCase().localeCompare(t.name.toLocaleLowerCase()))),e}_sendRPC(e,t){this.writePacketToStream(ai.RPC,[e,t.length,...t])}async _sendRPCWithResponse(e,t,i){if(this._rpcFeedback)throw new Error("Only 1 RPC command that requires feedback can be active");return await this._awaitRPCResultWithTimeout(new Promise(((i,n)=>{this._rpcFeedback={command:e,resolve:i,reject:n},this._sendRPC(e,t)})),i)}async _sendRPCWithMultipleResponses(e,t,i){if(this._rpcFeedback)throw new Error("Only 1 RPC command that requires feedback can be active");return await this._awaitRPCResultWithTimeout(new Promise(((i,n)=>{this._rpcFeedback={command:e,resolve:i,reject:n,receivedData:[]},this._sendRPC(e,t)})),i)}async _awaitRPCResultWithTimeout(e,t){return t?await new Promise(((i,n)=>{const o=setTimeout((()=>this._setError(254)),t);e.finally((()=>clearTimeout(o))),e.then(i,n)})):await e}async _processInput(){this.logger.debug("Starting read loop"),this._reader=this.port.readable.getReader();try{let e,t=[],i=0;for(;;){const{value:n,done:o}=await this._reader.read();if(o)break;if(n&&0!==n.length)for(const o of n){if(!1===e){10===o&&(e=void 0);continue}if(!0===e){t.push(o),t.length===i&&(this._handleIncomingPacket(t),e=void 0,t=[]);continue}if(10===o){t=[];continue}if(t.push(o),9!==t.length)continue;if(e="IMPROV"===String.fromCharCode(...t.slice(0,6)),!e){t=[];continue}i=9+t[8]+1}}}catch(e){this.logger.error("Error while reading serial port",e)}finally{this._reader.releaseLock(),this._reader=void 0}this.logger.debug("Finished read loop"),this.dispatchEvent(new Event("disconnect"))}_handleIncomingPacket(e){const t=e.slice(6),i=t[0],n=t[1],o=t[2],r=t.slice(3,3+o);if(this.logger.debug("PROCESS",{version:i,packetType:n,packetLength:o,data:ci(r)}),1!==i)return void this.logger.error("Received unsupported version",i);let a=t[3+o],d=0;for(let t=0;t0?this._rpcFeedback.receivedData.push(t):(this._rpcFeedback.resolve(this._rpcFeedback.receivedData),this._rpcFeedback=void 0):(this._rpcFeedback.resolve(t),this._rpcFeedback=void 0)}else this.logger.error("Unable to handle packet",t);else this.logger.error(`Received invalid checksum ${a}. Expected ${d}`)}async writePacketToStream(e,t){const i=new Uint8Array([...ri,e,t.length,...t,0,0]);i[i.length-2]=255&i.reduce(((e,t)=>e+t),0),i[i.length-1]=10,this.logger.debug("Writing to stream:",ci(new Array(...i)));const n=this.port.writable.getWriter();await n.write(i);try{n.releaseLock()}catch(e){console.error("Ignoring release lock error",e)}}_setError(e){this.error=e,e>0&&this._rpcFeedback&&(this._rpcFeedback.reject(si[e]||`UNKNOWN_ERROR (${e})`),this._rpcFeedback=void 0),this.dispatchEvent(new CustomEvent("error-changed",{detail:this.error}))}}const mi=e=>{let t=[];for(let i=0;i"["+e.map((e=>ui(e))).join(", ")+"]",ui=(e,t=2)=>{let i=e.toString(16).toUpperCase();return i.startsWith("-")?"-0x"+i.substring(1).padStart(t,"0"):"0x"+i.padStart(t,"0")},fi=e=>new Promise((t=>setTimeout(t,e))),gi={18:"256KB",19:"512KB",20:"1MB",21:"2MB",22:"4MB",23:"8MB",24:"16MB",25:"32MB",26:"64MB"},bi=mi(" UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"),_i=33382,xi=50,vi=12882,yi=12883,wi=12994,ki=12995,Ei=12998,Ii=12914,Ri={4293968129:{name:"ESP8266",family:_i},15736195:{name:"ESP32",family:xi},1990:{name:"ESP32-S2",family:vi},9:{name:"ESP32-S3",family:yi},1867591791:{name:"ESP32-C2",family:wi},2084675695:{name:"ESP32-C2",family:wi},1763790959:{name:"ESP32-C3",family:ki},456216687:{name:"ESP32-C3",family:ki},1216438383:{name:"ESP32-C3",family:ki},1130455151:{name:"ESP32-C3",family:ki},3619110528:{name:"ESP32-H2",family:Ii},752910447:{name:"ESP32-C6",family:Ei}},Ci=3e3,Ai=6e5,Ti=(e,t)=>{let i=Math.floor(e*(t/486));return i{switch(e){case xi:return{regBase:1072963584,baseFuse:1073061888,macFuse:1073061888,usrOffs:28,usr1Offs:32,usr2Offs:36,mosiDlenOffs:40,misoDlenOffs:44,w0Offs:128,uartDateReg:1610612856,flashOffs:4096};case vi:return{regBase:1061167104,baseFuse:1061265408,macFuse:1061265476,usrOffs:24,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612856,flashOffs:4096};case yi:return{regBase:1610620928,usrOffs:24,baseFuse:1610641408,macFuse:1610641476,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612864,flashOffs:0};case _i:return{regBase:1610613248,usrOffs:28,baseFuse:1072693328,macFuse:1072693328,usr1Offs:32,usr2Offs:36,mosiDlenOffs:-1,misoDlenOffs:-1,w0Offs:64,uartDateReg:1610612856,flashOffs:0};case wi:case ki:return{regBase:1610620928,baseFuse:1610647552,macFuse:1610647620,usrOffs:24,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612860,flashOffs:0};case Ei:return{regBase:1610625024,baseFuse:1611335680,macFuse:1611335748,usrOffs:24,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612860,flashOffs:0};case Ii:return{regBase:1610620928,baseFuse:1610719232,macFuse:1610719300,usrOffs:24,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612860,flashOffs:0};default:return{regBase:-1,baseFuse:-1,macFuse:-1,usrOffs:-1,usr1Offs:-1,usr2Offs:-1,mosiDlenOffs:-1,misoDlenOffs:-1,w0Offs:-1,uartDateReg:-1,flashOffs:-1}}};class Oi extends Error{constructor(e){super(e),this.name="SlipReadError"}}const Li=async e=>{let t;return e==xi?t=await import("./esp32-BLbsWvxO.js"):e==vi?t=await import("./esp32s2-CrsP1231.js"):e==yi?t=await import("./esp32s3-CiJyd6Fk.js"):e==_i?t=await import("./esp8266-CQFcqJ_a.js"):e==wi?t=await import("./esp32c2-wLQhZItC.js"):e==ki?t=await import("./esp32c3-DmSvHQKL.js"):e==Ei?t=await import("./esp32c6-ZuxjUVr4.js"):e==Ii&&(t=await import("./esp32h2-CZ4EIL3w.js")),{...t,text:mi(atob(t.text)),data:mi(atob(t.data))}};function Fi(e){let t=e.length;for(;--t>=0;)e[t]=0}const zi=256,Di=286,Bi=30,Ni=15,$i=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),Mi=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),Ui=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Pi=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Hi=new Array(576);Fi(Hi);const Vi=new Array(60);Fi(Vi);const Wi=new Array(512);Fi(Wi);const Gi=new Array(256);Fi(Gi);const Xi=new Array(29);Fi(Xi);const ji=new Array(Bi);function Yi(e,t,i,n,o){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=n,this.max_length=o,this.has_stree=e&&e.length}let qi,Zi,Ki;function Qi(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}Fi(ji);const Ji=e=>e<256?Wi[e]:Wi[256+(e>>>7)],en=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},tn=(e,t,i)=>{e.bi_valid>16-i?(e.bi_buf|=t<>16-e.bi_valid,e.bi_valid+=i-16):(e.bi_buf|=t<{tn(e,i[2*t],i[2*t+1])},on=(e,t)=>{let i=0;do{i|=1&e,e>>>=1,i<<=1}while(--t>0);return i>>>1},rn=(e,t,i)=>{const n=new Array(16);let o,r,a=0;for(o=1;o<=Ni;o++)a=a+i[o-1]<<1,n[o]=a;for(r=0;r<=t;r++){let t=e[2*r+1];0!==t&&(e[2*r]=on(n[t]++,t))}},an=e=>{let t;for(t=0;t{e.bi_valid>8?en(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},sn=(e,t,i,n)=>{const o=2*t,r=2*i;return e[o]{const n=e.heap[i];let o=i<<1;for(;o<=e.heap_len&&(o{let n,o,r,a,d=0;if(0!==e.sym_next)do{n=255&e.pending_buf[e.sym_buf+d++],n+=(255&e.pending_buf[e.sym_buf+d++])<<8,o=e.pending_buf[e.sym_buf+d++],0===n?nn(e,o,t):(r=Gi[o],nn(e,r+zi+1,t),a=$i[r],0!==a&&(o-=Xi[r],tn(e,o,a)),n--,r=Ji(n),nn(e,r,i),a=Mi[r],0!==a&&(n-=ji[r],tn(e,n,a)))}while(d{const i=t.dyn_tree,n=t.stat_desc.static_tree,o=t.stat_desc.has_stree,r=t.stat_desc.elems;let a,d,s,l=-1;for(e.heap_len=0,e.heap_max=573,a=0;a>1;a>=1;a--)ln(e,i,a);s=r;do{a=e.heap[1],e.heap[1]=e.heap[e.heap_len--],ln(e,i,1),d=e.heap[1],e.heap[--e.heap_max]=a,e.heap[--e.heap_max]=d,i[2*s]=i[2*a]+i[2*d],e.depth[s]=(e.depth[a]>=e.depth[d]?e.depth[a]:e.depth[d])+1,i[2*a+1]=i[2*d+1]=s,e.heap[1]=s++,ln(e,i,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],((e,t)=>{const i=t.dyn_tree,n=t.max_code,o=t.stat_desc.static_tree,r=t.stat_desc.has_stree,a=t.stat_desc.extra_bits,d=t.stat_desc.extra_base,s=t.stat_desc.max_length;let l,c,h,m,p,u,f=0;for(m=0;m<=Ni;m++)e.bl_count[m]=0;for(i[2*e.heap[e.heap_max]+1]=0,l=e.heap_max+1;l<573;l++)c=e.heap[l],m=i[2*i[2*c+1]+1]+1,m>s&&(m=s,f++),i[2*c+1]=m,c>n||(e.bl_count[m]++,p=0,c>=d&&(p=a[c-d]),u=i[2*c],e.opt_len+=u*(m+p),r&&(e.static_len+=u*(o[2*c+1]+p)));if(0!==f){do{for(m=s-1;0===e.bl_count[m];)m--;e.bl_count[m]--,e.bl_count[m+1]+=2,e.bl_count[s]--,f-=2}while(f>0);for(m=s;0!==m;m--)for(c=e.bl_count[m];0!==c;)h=e.heap[--l],h>n||(i[2*h+1]!==m&&(e.opt_len+=(m-i[2*h+1])*i[2*h],i[2*h+1]=m),c--)}})(e,t),rn(i,l,e.bl_count)},mn=(e,t,i)=>{let n,o,r=-1,a=t[1],d=0,s=7,l=4;for(0===a&&(s=138,l=3),t[2*(i+1)+1]=65535,n=0;n<=i;n++)o=a,a=t[2*(n+1)+1],++d{let n,o,r=-1,a=t[1],d=0,s=7,l=4;for(0===a&&(s=138,l=3),n=0;n<=i;n++)if(o=a,a=t[2*(n+1)+1],!(++d{tn(e,0+(n?1:0),3),dn(e),en(e,i),en(e,~i),i&&e.pending_buf.set(e.window.subarray(t,t+i),e.pending),e.pending+=i};var gn=e=>{un||((()=>{let e,t,i,n,o;const r=new Array(16);for(i=0,n=0;n<28;n++)for(Xi[n]=i,e=0;e<1<<$i[n];e++)Gi[i++]=n;for(Gi[i-1]=n,o=0,n=0;n<16;n++)for(ji[n]=o,e=0;e<1<>=7;n{let o,r,a=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,i=4093624447;for(t=0;t<=31;t++,i>>>=1)if(1&i&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t{let t;for(mn(e,e.dyn_ltree,e.l_desc.max_code),mn(e,e.dyn_dtree,e.d_desc.max_code),hn(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*Pi[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),o=e.opt_len+3+7>>>3,r=e.static_len+3+7>>>3,r<=o&&(o=r)):o=r=i+5,i+4<=o&&-1!==t?fn(e,t,i,n):4===e.strategy||r===o?(tn(e,2+(n?1:0),3),cn(e,Hi,Vi)):(tn(e,4+(n?1:0),3),((e,t,i,n)=>{let o;for(tn(e,t-257,5),tn(e,i-1,5),tn(e,n-4,4),o=0;o(e.pending_buf[e.sym_buf+e.sym_next++]=t,e.pending_buf[e.sym_buf+e.sym_next++]=t>>8,e.pending_buf[e.sym_buf+e.sym_next++]=i,0===t?e.dyn_ltree[2*i]++:(e.matches++,t--,e.dyn_ltree[2*(Gi[i]+zi+1)]++,e.dyn_dtree[2*Ji(t)]++),e.sym_next===e.sym_end),xn=e=>{tn(e,2,3),nn(e,256,Hi),(e=>{16===e.bi_valid?(en(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)})(e)},vn={_tr_init:gn,_tr_stored_block:fn,_tr_flush_block:bn,_tr_tally:_n,_tr_align:xn};var yn=(e,t,i,n)=>{let o=65535&e|0,r=e>>>16&65535|0,a=0;for(;0!==i;){a=i>2e3?2e3:i,i-=a;do{o=o+t[n++]|0,r=r+o|0}while(--a);o%=65521,r%=65521}return o|r<<16|0};const wn=new Uint32Array((()=>{let e,t=[];for(var i=0;i<256;i++){e=i;for(var n=0;n<8;n++)e=1&e?3988292384^e>>>1:e>>>1;t[i]=e}return t})());var kn=(e,t,i,n)=>{const o=wn,r=n+i;e^=-1;for(let i=n;i>>8^o[255&(e^t[i])];return-1^e},En={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},In={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:Rn,_tr_stored_block:Cn,_tr_flush_block:An,_tr_tally:Tn,_tr_align:Sn}=vn,{Z_NO_FLUSH:On,Z_PARTIAL_FLUSH:Ln,Z_FULL_FLUSH:Fn,Z_FINISH:zn,Z_BLOCK:Dn,Z_OK:Bn,Z_STREAM_END:Nn,Z_STREAM_ERROR:$n,Z_DATA_ERROR:Mn,Z_BUF_ERROR:Un,Z_DEFAULT_COMPRESSION:Pn,Z_FILTERED:Hn,Z_HUFFMAN_ONLY:Vn,Z_RLE:Wn,Z_FIXED:Gn,Z_DEFAULT_STRATEGY:Xn,Z_UNKNOWN:jn,Z_DEFLATED:Yn}=In,qn=258,Zn=262,Kn=42,Qn=113,Jn=666,eo=(e,t)=>(e.msg=En[t],t),to=e=>2*e-(e>4?9:0),io=e=>{let t=e.length;for(;--t>=0;)e[t]=0},no=e=>{let t,i,n,o=e.w_size;t=e.hash_size,n=t;do{i=e.head[--n],e.head[n]=i>=o?i-o:0}while(--t);t=o,n=t;do{i=e.prev[--n],e.prev[n]=i>=o?i-o:0}while(--t)};let oo=(e,t,i)=>(t<{const t=e.state;let i=t.pending;i>e.avail_out&&(i=e.avail_out),0!==i&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+i),e.next_out),e.next_out+=i,t.pending_out+=i,e.total_out+=i,e.avail_out-=i,t.pending-=i,0===t.pending&&(t.pending_out=0))},ao=(e,t)=>{An(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ro(e.strm)},so=(e,t)=>{e.pending_buf[e.pending++]=t},lo=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},co=(e,t,i,n)=>{let o=e.avail_in;return o>n&&(o=n),0===o?0:(e.avail_in-=o,t.set(e.input.subarray(e.next_in,e.next_in+o),i),1===e.state.wrap?e.adler=yn(e.adler,t,o,i):2===e.state.wrap&&(e.adler=kn(e.adler,t,o,i)),e.next_in+=o,e.total_in+=o,o)},ho=(e,t)=>{let i,n,o=e.max_chain_length,r=e.strstart,a=e.prev_length,d=e.nice_match;const s=e.strstart>e.w_size-Zn?e.strstart-(e.w_size-Zn):0,l=e.window,c=e.w_mask,h=e.prev,m=e.strstart+qn;let p=l[r+a-1],u=l[r+a];e.prev_length>=e.good_match&&(o>>=2),d>e.lookahead&&(d=e.lookahead);do{if(i=t,l[i+a]===u&&l[i+a-1]===p&&l[i]===l[r]&&l[++i]===l[r+1]){r+=2,i++;do{}while(l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&l[++r]===l[++i]&&ra){if(e.match_start=t,a=n,n>=d)break;p=l[r+a-1],u=l[r+a]}}}while((t=h[t&c])>s&&0!=--o);return a<=e.lookahead?a:e.lookahead},mo=e=>{const t=e.w_size;let i,n,o;do{if(n=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-Zn)&&(e.window.set(e.window.subarray(t,t+t-n),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,e.insert>e.strstart&&(e.insert=e.strstart),no(e),n+=t),0===e.strm.avail_in)break;if(i=co(e.strm,e.window,e.strstart+e.lookahead,n),e.lookahead+=i,e.lookahead+e.insert>=3)for(o=e.strstart-e.insert,e.ins_h=e.window[o],e.ins_h=oo(e,e.ins_h,e.window[o+1]);e.insert&&(e.ins_h=oo(e,e.ins_h,e.window[o+3-1]),e.prev[o&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=o,o++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead{let i,n,o,r=e.pending_buf_size-5>e.w_size?e.w_size:e.pending_buf_size-5,a=0,d=e.strm.avail_in;do{if(i=65535,o=e.bi_valid+42>>3,e.strm.avail_outn+e.strm.avail_in&&(i=n+e.strm.avail_in),i>o&&(i=o),i>8,e.pending_buf[e.pending-2]=~i,e.pending_buf[e.pending-1]=~i>>8,ro(e.strm),n&&(n>i&&(n=i),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+n),e.strm.next_out),e.strm.next_out+=n,e.strm.avail_out-=n,e.strm.total_out+=n,e.block_start+=n,i-=n),i&&(co(e.strm,e.strm.output,e.strm.next_out,i),e.strm.next_out+=i,e.strm.avail_out-=i,e.strm.total_out+=i)}while(0===a);return d-=e.strm.avail_in,d&&(d>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=d&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-d,e.strm.next_in),e.strstart),e.strstart+=d,e.insert+=d>e.w_size-e.insert?e.w_size-e.insert:d),e.block_start=e.strstart),e.high_watero&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,o+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),o>e.strm.avail_in&&(o=e.strm.avail_in),o&&(co(e.strm,e.window,e.strstart,o),e.strstart+=o,e.insert+=o>e.w_size-e.insert?e.w_size-e.insert:o),e.high_water>3,o=e.pending_buf_size-o>65535?65535:e.pending_buf_size-o,r=o>e.w_size?e.w_size:o,n=e.strstart-e.block_start,(n>=r||(n||t===zn)&&t!==On&&0===e.strm.avail_in&&n<=o)&&(i=n>o?o:n,a=t===zn&&0===e.strm.avail_in&&i===n?1:0,Cn(e,e.block_start,i,a),e.block_start+=i,ro(e.strm)),a?3:1)},uo=(e,t)=>{let i,n;for(;;){if(e.lookahead=3&&(e.ins_h=oo(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==i&&e.strstart-i<=e.w_size-Zn&&(e.match_length=ho(e,i)),e.match_length>=3)if(n=Tn(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=oo(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!=--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=oo(e,e.ins_h,e.window[e.strstart+1]);else n=Tn(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(ao(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===zn?(ao(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ao(e,!1),0===e.strm.avail_out)?1:2},fo=(e,t)=>{let i,n,o;for(;;){if(e.lookahead=3&&(e.ins_h=oo(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==i&&e.prev_length4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){o=e.strstart+e.lookahead-3,n=Tn(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=o&&(e.ins_h=oo(e,e.ins_h,e.window[e.strstart+3-1]),i=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!=--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,n&&(ao(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(n=Tn(e,0,e.window[e.strstart-1]),n&&ao(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=Tn(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===zn?(ao(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ao(e,!1),0===e.strm.avail_out)?1:2};function go(e,t,i,n,o){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=n,this.func=o}const bo=[new go(0,0,0,0,po),new go(4,4,8,4,uo),new go(4,5,16,8,uo),new go(4,6,32,32,uo),new go(4,4,16,16,fo),new go(8,16,32,32,fo),new go(8,16,128,128,fo),new go(8,32,128,256,fo),new go(32,128,258,1024,fo),new go(32,258,258,4096,fo)];function _o(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Yn,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),io(this.dyn_ltree),io(this.dyn_dtree),io(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),io(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),io(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const xo=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.status!==Kn&&57!==t.status&&69!==t.status&&73!==t.status&&91!==t.status&&103!==t.status&&t.status!==Qn&&t.status!==Jn?1:0},vo=e=>{if(xo(e))return eo(e,$n);e.total_in=e.total_out=0,e.data_type=jn;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=2===t.wrap?57:t.wrap?Kn:Qn,e.adler=2===t.wrap?0:1,t.last_flush=-2,Rn(t),Bn},yo=e=>{const t=vo(e);return t===Bn&&(e=>{e.window_size=2*e.w_size,io(e.head),e.max_lazy_match=bo[e.level].max_lazy,e.good_match=bo[e.level].good_length,e.nice_match=bo[e.level].nice_length,e.max_chain_length=bo[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=2,e.match_available=0,e.ins_h=0})(e.state),t},wo=(e,t,i,n,o,r)=>{if(!e)return $n;let a=1;if(t===Pn&&(t=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),o<1||o>9||i!==Yn||n<8||n>15||t<0||t>9||r<0||r>Gn||8===n&&1!==a)return eo(e,$n);8===n&&(n=9);const d=new _o;return e.state=d,d.strm=e,d.status=Kn,d.wrap=a,d.gzhead=null,d.w_bits=n,d.w_size=1<{if(xo(e)||t>Dn||t<0)return e?eo(e,$n):$n;const i=e.state;if(!e.output||0!==e.avail_in&&!e.input||i.status===Jn&&t!==zn)return eo(e,0===e.avail_out?Un:$n);const n=i.last_flush;if(i.last_flush=t,0!==i.pending){if(ro(e),0===e.avail_out)return i.last_flush=-1,Bn}else if(0===e.avail_in&&to(t)<=to(n)&&t!==zn)return eo(e,Un);if(i.status===Jn&&0!==e.avail_in)return eo(e,Un);if(i.status===Kn&&0===i.wrap&&(i.status=Qn),i.status===Kn){let t=Yn+(i.w_bits-8<<4)<<8,n=-1;if(n=i.strategy>=Vn||i.level<2?0:i.level<6?1:6===i.level?2:3,t|=n<<6,0!==i.strstart&&(t|=32),t+=31-t%31,lo(i,t),0!==i.strstart&&(lo(i,e.adler>>>16),lo(i,65535&e.adler)),e.adler=1,i.status=Qn,ro(e),0!==i.pending)return i.last_flush=-1,Bn}if(57===i.status)if(e.adler=0,so(i,31),so(i,139),so(i,8),i.gzhead)so(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),so(i,255&i.gzhead.time),so(i,i.gzhead.time>>8&255),so(i,i.gzhead.time>>16&255),so(i,i.gzhead.time>>24&255),so(i,9===i.level?2:i.strategy>=Vn||i.level<2?4:0),so(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(so(i,255&i.gzhead.extra.length),so(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=kn(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69;else if(so(i,0),so(i,0),so(i,0),so(i,0),so(i,0),so(i,9===i.level?2:i.strategy>=Vn||i.level<2?4:0),so(i,3),i.status=Qn,ro(e),0!==i.pending)return i.last_flush=-1,Bn;if(69===i.status){if(i.gzhead.extra){let t=i.pending,n=(65535&i.gzhead.extra.length)-i.gzindex;for(;i.pending+n>i.pending_buf_size;){let o=i.pending_buf_size-i.pending;if(i.pending_buf.set(i.gzhead.extra.subarray(i.gzindex,i.gzindex+o),i.pending),i.pending=i.pending_buf_size,i.gzhead.hcrc&&i.pending>t&&(e.adler=kn(e.adler,i.pending_buf,i.pending-t,t)),i.gzindex+=o,ro(e),0!==i.pending)return i.last_flush=-1,Bn;t=0,n-=o}let o=new Uint8Array(i.gzhead.extra);i.pending_buf.set(o.subarray(i.gzindex,i.gzindex+n),i.pending),i.pending+=n,i.gzhead.hcrc&&i.pending>t&&(e.adler=kn(e.adler,i.pending_buf,i.pending-t,t)),i.gzindex=0}i.status=73}if(73===i.status){if(i.gzhead.name){let t,n=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>n&&(e.adler=kn(e.adler,i.pending_buf,i.pending-n,n)),ro(e),0!==i.pending)return i.last_flush=-1,Bn;n=0}t=i.gzindexn&&(e.adler=kn(e.adler,i.pending_buf,i.pending-n,n)),i.gzindex=0}i.status=91}if(91===i.status){if(i.gzhead.comment){let t,n=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>n&&(e.adler=kn(e.adler,i.pending_buf,i.pending-n,n)),ro(e),0!==i.pending)return i.last_flush=-1,Bn;n=0}t=i.gzindexn&&(e.adler=kn(e.adler,i.pending_buf,i.pending-n,n))}i.status=103}if(103===i.status){if(i.gzhead.hcrc){if(i.pending+2>i.pending_buf_size&&(ro(e),0!==i.pending))return i.last_flush=-1,Bn;so(i,255&e.adler),so(i,e.adler>>8&255),e.adler=0}if(i.status=Qn,ro(e),0!==i.pending)return i.last_flush=-1,Bn}if(0!==e.avail_in||0!==i.lookahead||t!==On&&i.status!==Jn){let n=0===i.level?po(i,t):i.strategy===Vn?((e,t)=>{let i;for(;;){if(0===e.lookahead&&(mo(e),0===e.lookahead)){if(t===On)return 1;break}if(e.match_length=0,i=Tn(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(ao(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===zn?(ao(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ao(e,!1),0===e.strm.avail_out)?1:2})(i,t):i.strategy===Wn?((e,t)=>{let i,n,o,r;const a=e.window;for(;;){if(e.lookahead<=qn){if(mo(e),e.lookahead<=qn&&t===On)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(o=e.strstart-1,n=a[o],n===a[++o]&&n===a[++o]&&n===a[++o])){r=e.strstart+qn;do{}while(n===a[++o]&&n===a[++o]&&n===a[++o]&&n===a[++o]&&n===a[++o]&&n===a[++o]&&n===a[++o]&&n===a[++o]&&oe.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(i=Tn(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=Tn(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&(ao(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===zn?(ao(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ao(e,!1),0===e.strm.avail_out)?1:2})(i,t):bo[i.level].func(i,t);if(3!==n&&4!==n||(i.status=Jn),1===n||3===n)return 0===e.avail_out&&(i.last_flush=-1),Bn;if(2===n&&(t===Ln?Sn(i):t!==Dn&&(Cn(i,0,0,!1),t===Fn&&(io(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),ro(e),0===e.avail_out))return i.last_flush=-1,Bn}return t!==zn?Bn:i.wrap<=0?Nn:(2===i.wrap?(so(i,255&e.adler),so(i,e.adler>>8&255),so(i,e.adler>>16&255),so(i,e.adler>>24&255),so(i,255&e.total_in),so(i,e.total_in>>8&255),so(i,e.total_in>>16&255),so(i,e.total_in>>24&255)):(lo(i,e.adler>>>16),lo(i,65535&e.adler)),ro(e),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?Bn:Nn)},Eo=(e,t)=>{let i=t.length;if(xo(e))return $n;const n=e.state,o=n.wrap;if(2===o||1===o&&n.status!==Kn||n.lookahead)return $n;if(1===o&&(e.adler=yn(e.adler,t,i,0)),n.wrap=0,i>=n.w_size){0===o&&(io(n.head),n.strstart=0,n.block_start=0,n.insert=0);let e=new Uint8Array(n.w_size);e.set(t.subarray(i-n.w_size,i),0),t=e,i=n.w_size}const r=e.avail_in,a=e.next_in,d=e.input;for(e.avail_in=i,e.next_in=0,e.input=t,mo(n);n.lookahead>=3;){let e=n.strstart,t=n.lookahead-2;do{n.ins_h=oo(n,n.ins_h,n.window[e+3-1]),n.prev[e&n.w_mask]=n.head[n.ins_h],n.head[n.ins_h]=e,e++}while(--t);n.strstart=e,n.lookahead=2,mo(n)}return n.strstart+=n.lookahead,n.block_start=n.strstart,n.insert=n.lookahead,n.lookahead=0,n.match_length=n.prev_length=2,n.match_available=0,e.next_in=a,e.input=d,e.avail_in=r,n.wrap=o,Bn},Io={deflateInit:(e,t)=>wo(e,t,Yn,15,8,Xn),deflateInit2:wo,deflateReset:yo,deflateResetKeep:vo,deflateSetHeader:(e,t)=>xo(e)||2!==e.state.wrap?$n:(e.state.gzhead=t,Bn),deflate:ko,deflateEnd:e=>{if(xo(e))return $n;const t=e.state.status;return e.state=null,t===Qn?eo(e,Mn):Bn},deflateSetDictionary:Eo,deflateInfo:"pako deflate (from Nodeca project)"};const Ro=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var Co={assign:function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const i=t.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const t in i)Ro(i,t)&&(e[t]=i[t])}}return e},flattenChunks:e=>{let t=0;for(let i=0,n=e.length;i=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;To[254]=To[254]=1;var So={string2buf:e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,i,n,o,r,a=e.length,d=0;for(o=0;o>>6,t[r++]=128|63&i):i<65536?(t[r++]=224|i>>>12,t[r++]=128|i>>>6&63,t[r++]=128|63&i):(t[r++]=240|i>>>18,t[r++]=128|i>>>12&63,t[r++]=128|i>>>6&63,t[r++]=128|63&i);return t},buf2string:(e,t)=>{const i=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let n,o;const r=new Array(2*i);for(o=0,n=0;n4)r[o++]=65533,n+=a-1;else{for(t&=2===a?31:3===a?15:7;a>1&&n1?r[o++]=65533:t<65536?r[o++]=t:(t-=65536,r[o++]=55296|t>>10&1023,r[o++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&Ao)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let i="";for(let n=0;n{(t=t||e.length)>e.length&&(t=e.length);let i=t-1;for(;i>=0&&128==(192&e[i]);)i--;return i<0||0===i?t:i+To[e[i]]>t?i:t}};var Oo=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Lo=Object.prototype.toString,{Z_NO_FLUSH:Fo,Z_SYNC_FLUSH:zo,Z_FULL_FLUSH:Do,Z_FINISH:Bo,Z_OK:No,Z_STREAM_END:$o,Z_DEFAULT_COMPRESSION:Mo,Z_DEFAULT_STRATEGY:Uo,Z_DEFLATED:Po}=In;function Ho(e){this.options=Co.assign({level:Mo,method:Po,chunkSize:16384,windowBits:15,memLevel:8,strategy:Uo},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Oo,this.strm.avail_out=0;let i=Io.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==No)throw new Error(En[i]);if(t.header&&Io.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?So.string2buf(t.dictionary):"[object ArrayBuffer]"===Lo.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,i=Io.deflateSetDictionary(this.strm,e),i!==No)throw new Error(En[i]);this._dict_set=!0}}function Vo(e,t){const i=new Ho(t);if(i.push(e,!0),i.err)throw i.msg||En[i.err];return i.result}Ho.prototype.push=function(e,t){const i=this.strm,n=this.options.chunkSize;let o,r;if(this.ended)return!1;for(r=t===~~t?t:!0===t?Bo:Fo,"string"==typeof e?i.input=So.string2buf(e):"[object ArrayBuffer]"===Lo.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),(r===zo||r===Do)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(o=Io.deflate(i,r),o===$o)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),o=Io.deflateEnd(this.strm),this.onEnd(o),this.ended=!0,o===No;if(0!==i.avail_out){if(r>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},Ho.prototype.onData=function(e){this.chunks.push(e)},Ho.prototype.onEnd=function(e){e===No&&(this.result=Co.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Wo={Deflate:Ho,deflate:Vo,deflateRaw:function(e,t){return(t=t||{}).raw=!0,Vo(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,Vo(e,t)},constants:In};const Go=16209;var Xo=function(e,t){let i,n,o,r,a,d,s,l,c,h,m,p,u,f,g,b,_,x,v,y,w,k,E,I;const R=e.state;i=e.next_in,E=e.input,n=i+(e.avail_in-5),o=e.next_out,I=e.output,r=o-(t-e.avail_out),a=o+(e.avail_out-257),d=R.dmax,s=R.wsize,l=R.whave,c=R.wnext,h=R.window,m=R.hold,p=R.bits,u=R.lencode,f=R.distcode,g=(1<>>24,m>>>=x,p-=x,x=_>>>16&255,0===x)I[o++]=65535&_;else{if(!(16&x)){if(0==(64&x)){_=u[(65535&_)+(m&(1<>>=x,p-=x),p<15&&(m+=E[i++]<>>24,m>>>=x,p-=x,x=_>>>16&255,!(16&x)){if(0==(64&x)){_=f[(65535&_)+(m&(1<d){e.msg="invalid distance too far back",R.mode=Go;break e}if(m>>>=x,p-=x,x=o-r,y>x){if(x=y-x,x>l&&R.sane){e.msg="invalid distance too far back",R.mode=Go;break e}if(w=0,k=h,0===c){if(w+=s-x,x2;)I[o++]=k[w++],I[o++]=k[w++],I[o++]=k[w++],v-=3;v&&(I[o++]=k[w++],v>1&&(I[o++]=k[w++]))}else{w=o-y;do{I[o++]=I[w++],I[o++]=I[w++],I[o++]=I[w++],v-=3}while(v>2);v&&(I[o++]=I[w++],v>1&&(I[o++]=I[w++]))}break}}break}}while(i>3,i-=v,p-=v<<3,m&=(1<{const s=d.bits;let l,c,h,m,p,u,f=0,g=0,b=0,_=0,x=0,v=0,y=0,w=0,k=0,E=0,I=null;const R=new Uint16Array(16),C=new Uint16Array(16);let A,T,S,O=null;for(f=0;f<=jo;f++)R[f]=0;for(g=0;g=1&&0===R[_];_--);if(x>_&&(x=_),0===_)return o[r++]=20971520,o[r++]=20971520,d.bits=1,0;for(b=1;b<_&&0===R[b];b++);for(x0&&(0===e||1!==_))return-1;for(C[1]=0,f=1;f852||2===e&&k>592)return 1;for(;;){A=f-y,a[g]+1=u?(T=O[a[g]-u],S=I[a[g]-u]):(T=96,S=0),l=1<>y)+c]=A<<24|T<<16|S|0}while(0!==c);for(l=1<>=1;if(0!==l?(E&=l-1,E+=l):E=0,g++,0==--R[f]){if(f===_)break;f=t[i+a[g]]}if(f>x&&(E&m)!==h){for(0===y&&(y=x),p+=b,v=f-y,w=1<852||2===e&&k>592)return 1;h=E&m,o[h]=x<<24|v<<16|p-r|0}}return 0!==E&&(o[p+E]=f-y<<24|64<<16|0),d.bits=x,0};const{Z_FINISH:Jo,Z_BLOCK:er,Z_TREES:tr,Z_OK:ir,Z_STREAM_END:nr,Z_NEED_DICT:or,Z_STREAM_ERROR:rr,Z_DATA_ERROR:ar,Z_MEM_ERROR:dr,Z_BUF_ERROR:sr,Z_DEFLATED:lr}=In,cr=16180,hr=16190,mr=16191,pr=16192,ur=16194,fr=16199,gr=16200,br=16206,_r=16209,xr=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function vr(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const yr=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode16211?1:0},wr=e=>{if(yr(e))return rr;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=cr,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,ir},kr=e=>{if(yr(e))return rr;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,wr(e)},Er=(e,t)=>{let i;if(yr(e))return rr;const n=e.state;return t<0?(i=0,t=-t):(i=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?rr:(null!==n.window&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,kr(e))},Ir=(e,t)=>{if(!e)return rr;const i=new vr;e.state=i,i.strm=e,i.window=null,i.mode=cr;const n=Er(e,t);return n!==ir&&(e.state=null),n};let Rr,Cr,Ar=!0;const Tr=e=>{if(Ar){Rr=new Int32Array(512),Cr=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Qo(1,e.lens,0,288,Rr,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Qo(2,e.lens,0,32,Cr,0,e.work,{bits:5}),Ar=!1}e.lencode=Rr,e.lenbits=9,e.distcode=Cr,e.distbits=5},Sr=(e,t,i,n)=>{let o;const r=e.state;return null===r.window&&(r.wsize=1<=r.wsize?(r.window.set(t.subarray(i-r.wsize,i),0),r.wnext=0,r.whave=r.wsize):(o=r.wsize-r.wnext,o>n&&(o=n),r.window.set(t.subarray(i-n,i-n+o),r.wnext),(n-=o)?(r.window.set(t.subarray(i-n,i),0),r.wnext=n,r.whave=r.wsize):(r.wnext+=o,r.wnext===r.wsize&&(r.wnext=0),r.whave{let i,n,o,r,a,d,s,l,c,h,m,p,u,f,g,b,_,x,v,y,w,k,E=0;const I=new Uint8Array(4);let R,C;const A=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(yr(e)||!e.output||!e.input&&0!==e.avail_in)return rr;i=e.state,i.mode===mr&&(i.mode=pr),a=e.next_out,o=e.output,s=e.avail_out,r=e.next_in,n=e.input,d=e.avail_in,l=i.hold,c=i.bits,h=d,m=s,k=ir;e:for(;;)switch(i.mode){case cr:if(0===i.wrap){i.mode=pr;break}for(;c<16;){if(0===d)break e;d--,l+=n[r++]<>>8&255,i.check=kn(i.check,I,2,0),l=0,c=0,i.mode=16181;break}if(i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&l)<<8)+(l>>8))%31){e.msg="incorrect header check",i.mode=_r;break}if((15&l)!==lr){e.msg="unknown compression method",i.mode=_r;break}if(l>>>=4,c-=4,w=8+(15&l),0===i.wbits&&(i.wbits=w),w>15||w>i.wbits){e.msg="invalid window size",i.mode=_r;break}i.dmax=1<>8&1),512&i.flags&&4&i.wrap&&(I[0]=255&l,I[1]=l>>>8&255,i.check=kn(i.check,I,2,0)),l=0,c=0,i.mode=16182;case 16182:for(;c<32;){if(0===d)break e;d--,l+=n[r++]<>>8&255,I[2]=l>>>16&255,I[3]=l>>>24&255,i.check=kn(i.check,I,4,0)),l=0,c=0,i.mode=16183;case 16183:for(;c<16;){if(0===d)break e;d--,l+=n[r++]<>8),512&i.flags&&4&i.wrap&&(I[0]=255&l,I[1]=l>>>8&255,i.check=kn(i.check,I,2,0)),l=0,c=0,i.mode=16184;case 16184:if(1024&i.flags){for(;c<16;){if(0===d)break e;d--,l+=n[r++]<>>8&255,i.check=kn(i.check,I,2,0)),l=0,c=0}else i.head&&(i.head.extra=null);i.mode=16185;case 16185:if(1024&i.flags&&(p=i.length,p>d&&(p=d),p&&(i.head&&(w=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(n.subarray(r,r+p),w)),512&i.flags&&4&i.wrap&&(i.check=kn(i.check,n,p,r)),d-=p,r+=p,i.length-=p),i.length))break e;i.length=0,i.mode=16186;case 16186:if(2048&i.flags){if(0===d)break e;p=0;do{w=n[r+p++],i.head&&w&&i.length<65536&&(i.head.name+=String.fromCharCode(w))}while(w&&p>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=mr;break;case 16189:for(;c<32;){if(0===d)break e;d--,l+=n[r++]<>>=7&c,c-=7&c,i.mode=br;break}for(;c<3;){if(0===d)break e;d--,l+=n[r++]<>>=1,c-=1,3&l){case 0:i.mode=16193;break;case 1:if(Tr(i),i.mode=fr,t===tr){l>>>=2,c-=2;break e}break;case 2:i.mode=16196;break;case 3:e.msg="invalid block type",i.mode=_r}l>>>=2,c-=2;break;case 16193:for(l>>>=7&c,c-=7&c;c<32;){if(0===d)break e;d--,l+=n[r++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=_r;break}if(i.length=65535&l,l=0,c=0,i.mode=ur,t===tr)break e;case ur:i.mode=16195;case 16195:if(p=i.length,p){if(p>d&&(p=d),p>s&&(p=s),0===p)break e;o.set(n.subarray(r,r+p),a),d-=p,r+=p,s-=p,a+=p,i.length-=p;break}i.mode=mr;break;case 16196:for(;c<14;){if(0===d)break e;d--,l+=n[r++]<>>=5,c-=5,i.ndist=1+(31&l),l>>>=5,c-=5,i.ncode=4+(15&l),l>>>=4,c-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=_r;break}i.have=0,i.mode=16197;case 16197:for(;i.have>>=3,c-=3}for(;i.have<19;)i.lens[A[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,R={bits:i.lenbits},k=Qo(0,i.lens,0,19,i.lencode,0,i.work,R),i.lenbits=R.bits,k){e.msg="invalid code lengths set",i.mode=_r;break}i.have=0,i.mode=16198;case 16198:for(;i.have>>24,b=E>>>16&255,_=65535&E,!(g<=c);){if(0===d)break e;d--,l+=n[r++]<>>=g,c-=g,i.lens[i.have++]=_;else{if(16===_){for(C=g+2;c>>=g,c-=g,0===i.have){e.msg="invalid bit length repeat",i.mode=_r;break}w=i.lens[i.have-1],p=3+(3&l),l>>>=2,c-=2}else if(17===_){for(C=g+3;c>>=g,c-=g,w=0,p=3+(7&l),l>>>=3,c-=3}else{for(C=g+7;c>>=g,c-=g,w=0,p=11+(127&l),l>>>=7,c-=7}if(i.have+p>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=_r;break}for(;p--;)i.lens[i.have++]=w}}if(i.mode===_r)break;if(0===i.lens[256]){e.msg="invalid code -- missing end-of-block",i.mode=_r;break}if(i.lenbits=9,R={bits:i.lenbits},k=Qo(1,i.lens,0,i.nlen,i.lencode,0,i.work,R),i.lenbits=R.bits,k){e.msg="invalid literal/lengths set",i.mode=_r;break}if(i.distbits=6,i.distcode=i.distdyn,R={bits:i.distbits},k=Qo(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,R),i.distbits=R.bits,k){e.msg="invalid distances set",i.mode=_r;break}if(i.mode=fr,t===tr)break e;case fr:i.mode=gr;case gr:if(d>=6&&s>=258){e.next_out=a,e.avail_out=s,e.next_in=r,e.avail_in=d,i.hold=l,i.bits=c,Xo(e,m),a=e.next_out,o=e.output,s=e.avail_out,r=e.next_in,n=e.input,d=e.avail_in,l=i.hold,c=i.bits,i.mode===mr&&(i.back=-1);break}for(i.back=0;E=i.lencode[l&(1<>>24,b=E>>>16&255,_=65535&E,!(g<=c);){if(0===d)break e;d--,l+=n[r++]<>x)],g=E>>>24,b=E>>>16&255,_=65535&E,!(x+g<=c);){if(0===d)break e;d--,l+=n[r++]<>>=x,c-=x,i.back+=x}if(l>>>=g,c-=g,i.back+=g,i.length=_,0===b){i.mode=16205;break}if(32&b){i.back=-1,i.mode=mr;break}if(64&b){e.msg="invalid literal/length code",i.mode=_r;break}i.extra=15&b,i.mode=16201;case 16201:if(i.extra){for(C=i.extra;c>>=i.extra,c-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=16202;case 16202:for(;E=i.distcode[l&(1<>>24,b=E>>>16&255,_=65535&E,!(g<=c);){if(0===d)break e;d--,l+=n[r++]<>x)],g=E>>>24,b=E>>>16&255,_=65535&E,!(x+g<=c);){if(0===d)break e;d--,l+=n[r++]<>>=x,c-=x,i.back+=x}if(l>>>=g,c-=g,i.back+=g,64&b){e.msg="invalid distance code",i.mode=_r;break}i.offset=_,i.extra=15&b,i.mode=16203;case 16203:if(i.extra){for(C=i.extra;c>>=i.extra,c-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=_r;break}i.mode=16204;case 16204:if(0===s)break e;if(p=m-s,i.offset>p){if(p=i.offset-p,p>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=_r;break}p>i.wnext?(p-=i.wnext,u=i.wsize-p):u=i.wnext-p,p>i.length&&(p=i.length),f=i.window}else f=o,u=a-i.offset,p=i.length;p>s&&(p=s),s-=p,i.length-=p;do{o[a++]=f[u++]}while(--p);0===i.length&&(i.mode=gr);break;case 16205:if(0===s)break e;o[a++]=i.length,s--,i.mode=gr;break;case br:if(i.wrap){for(;c<32;){if(0===d)break e;d--,l|=n[r++]<Ir(e,15),inflateInit2:Ir,inflate:Or,inflateEnd:e=>{if(yr(e))return rr;let t=e.state;return t.window&&(t.window=null),e.state=null,ir},inflateGetHeader:(e,t)=>{if(yr(e))return rr;const i=e.state;return 0==(2&i.wrap)?rr:(i.head=t,t.done=!1,ir)},inflateSetDictionary:(e,t)=>{const i=t.length;let n,o,r;return yr(e)?rr:(n=e.state,0!==n.wrap&&n.mode!==hr?rr:n.mode===hr&&(o=1,o=yn(o,t,i,0),o!==n.check)?ar:(r=Sr(e,t,i,i),r?(n.mode=16210,dr):(n.havedict=1,ir)))},inflateInfo:"pako inflate (from Nodeca project)"};var Fr=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const zr=Object.prototype.toString,{Z_NO_FLUSH:Dr,Z_FINISH:Br,Z_OK:Nr,Z_STREAM_END:$r,Z_NEED_DICT:Mr,Z_STREAM_ERROR:Ur,Z_DATA_ERROR:Pr,Z_MEM_ERROR:Hr}=In;function Vr(e){this.options=Co.assign({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&0==(15&t.windowBits)&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Oo,this.strm.avail_out=0;let i=Lr.inflateInit2(this.strm,t.windowBits);if(i!==Nr)throw new Error(En[i]);if(this.header=new Fr,Lr.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=So.string2buf(t.dictionary):"[object ArrayBuffer]"===zr.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Lr.inflateSetDictionary(this.strm,t.dictionary),i!==Nr)))throw new Error(En[i])}Vr.prototype.push=function(e,t){const i=this.strm,n=this.options.chunkSize,o=this.options.dictionary;let r,a,d;if(this.ended)return!1;for(a=t===~~t?t:!0===t?Br:Dr,"[object ArrayBuffer]"===zr.call(e)?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(n),i.next_out=0,i.avail_out=n),r=Lr.inflate(i,a),r===Mr&&o&&(r=Lr.inflateSetDictionary(i,o),r===Nr?r=Lr.inflate(i,a):r===Pr&&(r=Mr));i.avail_in>0&&r===$r&&i.state.wrap>0&&0!==e[i.next_in];)Lr.inflateReset(i),r=Lr.inflate(i,a);switch(r){case Ur:case Pr:case Mr:case Hr:return this.onEnd(r),this.ended=!0,!1}if(d=i.avail_out,i.next_out&&(0===i.avail_out||r===$r))if("string"===this.options.to){let e=So.utf8border(i.output,i.next_out),t=i.next_out-e,o=So.buf2string(i.output,e);i.next_out=t,i.avail_out=n-t,t&&i.output.set(i.output.subarray(e,e+t),0),this.onData(o)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(r!==Nr||0!==d){if(r===$r)return r=Lr.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},Vr.prototype.onData=function(e){this.chunks.push(e)},Vr.prototype.onEnd=function(e){e===Nr&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Co.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};const{Deflate:Wr,deflate:Gr,deflateRaw:Xr,gzip:jr}=Wo;var Yr=Gr;const qr={b:{u:DataView.prototype.getInt8,p:DataView.prototype.setInt8,bytes:1},B:{u:DataView.prototype.getUint8,p:DataView.prototype.setUint8,bytes:1},h:{u:DataView.prototype.getInt16,p:DataView.prototype.setInt16,bytes:2},H:{u:DataView.prototype.getUint16,p:DataView.prototype.setUint16,bytes:2},i:{u:DataView.prototype.getInt32,p:DataView.prototype.setInt32,bytes:4},I:{u:DataView.prototype.getUint32,p:DataView.prototype.setUint32,bytes:4},q:{u:DataView.prototype.getInt64,p:DataView.prototype.setInt64,bytes:8},Q:{u:DataView.prototype.getUint64,p:DataView.prototype.setUint64,bytes:8}},Zr=(e,...t)=>{let i=0;if(e.replace(/[<>]/,"").length!=t.length)throw"Pack format to Argument count mismatch";let n=[],o=!0;for(let n=0;n"==e[n]?o=!1:(r(e[n],t[i]),i++);function r(e,t){if(!(e in qr))throw"Unhandled character '"+e+"' in pack format";let i=qr[e].bytes,r=new DataView(new ArrayBuffer(i));qr[e].p.bind(r)(0,t,o);for(let e=0;e{let i=0,n=[],o=!0;for(let t of e)"<"==t?o=!0:">"==t?o=!1:r(t);function r(e){if(!(e in qr))throw"Unhandled character '"+e+"' in unpack format";let r=qr[e].bytes,a=new DataView(new ArrayBuffer(r));for(let e=0;e>>0];if(void 0===t)throw new Error(`Unknown Chip: Hex: ${ui(e>>>0,8).toLowerCase()} Number: ${e}`);this.chipName=t.name,this.chipFamily=t.family;let i=Si(this.getChipFamily()).macFuse;for(let e=0;e<4;e++)this._efuses[e]=await this.readRegister(i+4*e);this.logger.log(`Chip type ${this.chipName}`)}async readLoop(){this.debug&&this.logger.debug("Starting read loop"),this._reader=this.port.readable.getReader();try{for(;;){const{value:e,done:t}=await this._reader.read();if(t){this._reader.releaseLock();break}e&&0!==e.length&&this._inputBuffer.push(...Array.from(e))}}catch(e){console.error("Read loop got disconnected")}this.connected=!1,this.dispatchEvent(new Event("disconnect")),this.logger.debug("Finished read loop")}sleep(e=100){return new Promise((t=>setTimeout(t,e)))}async setRTS(e){await this.port.setSignals({requestToSend:e}),await this.setDTR(this.state_DTR)}async setDTR(e){this.state_DTR=e,await this.port.setSignals({dataTerminalReady:e})}async hardReset(e=!1){this.logger.log("Try hard reset."),e?4097===this.port.getInfo().usbProductId?(await this.setDTR(!1),await this.setRTS(!1),await this.sleep(100),await this.setDTR(!0),await this.setRTS(!1),await this.sleep(100),await this.setRTS(!0),await this.setDTR(!1),await this.setRTS(!0),await this.sleep(100),await this.setDTR(!1),await this.setRTS(!1)):(await this.setDTR(!1),await this.setRTS(!0),await this.sleep(100),await this.setDTR(!0),await this.setRTS(!1),await this.sleep(50),await this.setDTR(!1)):(await this.setRTS(!0),await this.sleep(100),await this.setRTS(!1)),await new Promise((e=>setTimeout(e,1e3)))}macAddr(){let e,t=new Array(6).fill(0),i=this._efuses[0],n=this._efuses[1],o=this._efuses[2],r=this._efuses[3];if(this.chipFamily==_i){if(0!=r)e=[r>>16&255,r>>8&255,255&r];else if(0==(n>>16&255))e=[24,254,52];else{if(1!=(n>>16&255))throw new Error("Couldnt determine OUI");e=[172,208,116]}t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=n>>8&255,t[4]=255&n,t[5]=i>>24&255}else if(this.chipFamily==xi)t[0]=o>>8&255,t[1]=255&o,t[2]=n>>24&255,t[3]=n>>16&255,t[4]=n>>8&255,t[5]=255&n;else{if(this.chipFamily!=vi&&this.chipFamily!=yi&&this.chipFamily!=wi&&this.chipFamily!=ki&&this.chipFamily!=Ei&&this.chipFamily!=Ii)throw new Error("Unknown chip family");t[0]=n>>8&255,t[1]=255&n,t[2]=i>>24&255,t[3]=i>>16&255,t[4]=i>>8&255,t[5]=255&i}return t}async readRegister(e){this.debug&&this.logger.debug("Reading from Register "+ui(e,8));let t=Zr("{let t=[192];for(let i of e)219==i?t=t.concat([219,221]):192==i?t=t.concat([219,220]):t.push(i);return t.push(192),t})([...Zr("0){n.push(this._inputBuffer.shift());break}await fi(10)}if(0==n.length){throw new Oi("Timed out waiting for packet "+(null===t?"header":"content"))}this.debug&&this.logger.debug("Read "+n.length+" bytes: "+pi(n));for(let e of n)if(null===t){if(192!=e)throw this.debug&&(this.logger.debug("Read invalid data: "+pi(n)),this.logger.debug("Remaining data in serial buffer: "+pi(this._inputBuffer))),new Oi("Invalid head of packet ("+ui(e)+")");t=[]}else if(i)if(i=!1,220==e)t.push(192);else{if(221!=e)throw this.debug&&(this.logger.debug("Read invalid data: "+pi(n)),this.logger.debug("Remaining data in serial buffer: "+pi(this._inputBuffer))),new Oi("Invalid SLIP escape (0xdb, "+ui(e)+")");t.push(219)}else if(219==e)i=!0;else{if(192==e)return this.debug&&this.logger.debug("Received full packet: "+pi(t)),t;t.push(e)}}throw new Oi("Invalid state")}async getResponse(e,t=3e3){for(let i=0;i<100;i++){const i=await this.readPacket(t);if(i.length<8)continue;const[n,o,r,a]=Kr("1&&0==t[0]&&0==t[1])return!0}catch(e){}return!1}getFlashWriteSize(){return this.IS_STUB?16384:1024}async flashData(e,t,i=0,n=!1){if(e.byteLength>=8){var o=Array.from(new Uint8Array(e,0,4));let t=o[0],i=o[2],n=o[3];this.logger.log(`Image header, Magic=${ui(t)}, FlashMode=${ui(i)}, FlashSizeFreq=${ui(n)}`)}let r,a=e.byteLength,d=0,s=Ci;n?(r=Yr(new Uint8Array(e),{level:9}).buffer,d=r.byteLength,this.logger.log(`Writing data with filesize: ${a}. Compressed Size: ${d}`),s=await this.flashDeflBegin(a,d,i)):(this.logger.log(`Writing data with filesize: ${a}`),r=e,await this.flashBegin(a,i));let l=[],c=0,h=0,m=0,p=Date.now(),u=this.getFlashWriteSize(),f=n?d:a;for(;f-m>0;)this.debug&&this.logger.log(`Writing at ${ui(i+c*u,8)} `),f-m>=u?l=Array.from(new Uint8Array(r,m,u)):(l=Array.from(new Uint8Array(r,m,f-m)),n||(l=l.concat(new Array(u-l.length).fill(255)))),n?await this.flashDeflBlock(l,c,s):await this.flashBlock(l,c),c+=1,h+=n?Math.round(l.length*a/d):l.length,m+=u,t(Math.min(h,a),a);this.logger.log("Took "+(Date.now()-p)+"ms to write "+f+" bytes"),this.IS_STUB&&(await this.flashBegin(0,0),n?await this.flashDeflFinish():await this.flashFinish())}async flashBlock(e,t,i=3e3){await this.checkCommand(3,Zr("0&&r.concat(Zr("0&&await this.writeRegister(n,t-1),i>0&&await this.writeRegister(o,i-1)}else{let n=e.regBase+e.usr1Offs,o=(0==i?0:i-1)<<8|(0==t?0:t-1)<<17;await this.writeRegister(n,o)}}async waitDone(e,t){for(let i=0;i<10;i++){if(0==(await this.readRegister(e)&t))return}throw Error("SPI command did not complete in time")}async runSpiFlashCommand(e,t,i=0){let n=Si(this.getChipFamily()),o=n.regBase,r=o,a=o+n.usrOffs,d=o+n.usr2Offs,s=o+n.w0Offs,l=1<<18;if(i>32)throw new Error("Reading more than 32 bits back from a SPI flash operation is unsupported");if(t.length>64)throw new Error("Writing more than 64 bytes of data with one SPI command is unsupported");let c=8*t.length,h=await this.readRegister(a),m=await this.readRegister(d),p=1<<31;if(i>0&&(p|=268435456),c>0&&(p|=134217728),await this.setDataLengths(n,c,i),await this.writeRegister(a,p),await this.writeRegister(d,7<<28|e),0==c)await this.writeRegister(s,0);else{t.concat(new Array(t.length%4).fill(0));let e=Kr("I".repeat(Math.floor(t.length/4)),t),i=s;this.logger.debug(`Words Length: ${e.length}`);for(const t of e)this.logger.debug(`Writing word ${ui(t)} to register offset ${ui(i)}`),await this.writeRegister(i,t),i+=4}await this.writeRegister(r,l),await this.waitDone(r,l);let u=await this.readRegister(s);return await this.writeRegister(a,h),await this.writeRegister(d,m),u}async detectFlashSize(){this.logger.log("Detecting Flash Size");let e=await this.flashId(),t=255&e,i=e>>16&255;this.logger.log(`FlashId: ${ui(e)}`),this.logger.log(`Flash Manufacturer: ${t.toString(16)}`),this.logger.log(`Flash Device: ${(e>>8&255).toString(16)}${i.toString(16)}`),this.flashSize=gi[i],this.logger.log(`Auto-detected Flash size: ${this.flashSize}`)}getEraseSize(e,t){let i=4096,n=Math.floor((t+i-1)/i),o=16-Math.floor(e/i)%16;return no&&(a=o),await this.memBlock(e[t].slice(r,a),n)}}this.logger.log("Running stub..."),await this.memFinish(e.entry);const n=await this.readPacket(500);if(t=String.fromCharCode(...n),"OHAI"!=t)throw new Error("Failed to start stub. Unexpected response: "+t);this.logger.log("Stub is now running...");const o=new Jr(this.port,this.logger,this);return await o.detectFlashSize(),o}async writeToStream(e){const t=this.port.writable.getWriter();await t.write(new Uint8Array(e));try{t.releaseLock()}catch(e){console.error("Ignoring release lock error",e)}}async disconnect(){this._parent?await this._parent.disconnect():(await this.port.writable.getWriter().close(),await new Promise((e=>{this._reader||e(void 0),this.addEventListener("disconnect",e,{once:!0}),this._reader.cancel()})),this.connected=!1)}}class Jr extends Qr{constructor(){super(...arguments),this.IS_STUB=!0}async memBegin(e,t,i,n){let o=await Li(this.chipFamily),r=n,a=n+e;console.log(r,a),console.log(o.data_start,o.data.length,o.text_start,o.text.length);for(let[e,t]of[[o.data_start,o.data_start+o.data.length],[o.text_start,o.text_start+o.text.length]])if(re)throw new Error("Software loader is resident at "+ui(e,8)+"-"+ui(t,8)+". Can't load binary at overlapping address range "+ui(r,8)+"-"+ui(a,8)+". Try changing the binary loading address.")}async eraseFlash(){await this.checkCommand(208,[],0,Ai)}}const ea=async(e,t,i,n,o,r)=>{let a,d,s;const l=t=>e({...t,manifest:a,build:d,chipFamily:s});var c=null,h="";try{c=JSON.parse(n)}catch{h=new URL(n,location.toString()).toString(),c=fetch(h).then((e=>e.json()))}const m=new Qr(t,i);window.esploader=m,l({state:"initializing",message:"Initializing...",details:{done:!1}});try{await m.initialize()}catch(e){return i.error(e),l({state:"error",message:"Failed to initialize. Try resetting your device or holding the BOOT button while clicking INSTALL.",details:{error:"failed_initialize",details:e}}),void(m.connected&&await m.disconnect())}s=(e=>{switch(e.chipFamily){case xi:return"ESP32";case vi:return"ESP32-S2";case yi:return"ESP32-S3";case wi:return"ESP32-C2";case ki:return"ESP32-C3";case Ei:return"ESP32-C6";case Ii:return"ESP32-H2";case _i:return"ESP8266";default:return"Unknown Chip"}})(m),l({state:"initializing",message:`Initialized. Found ${s}`,details:{done:!0}}),l({state:"manifest",message:"Fetching manifest...",details:{done:!1}});try{a=await c}catch(e){return l({state:"error",message:`Unable to fetch manifest: ${e}`,details:{error:"fetch_manifest_failed",details:e}}),void await m.disconnect()}if(d=a.builds.find((e=>e.chipFamily===s)),l({state:"manifest",message:`Found manifest for ${a.name}`,details:{done:!0}}),!d)return l({state:"error",message:`Your ${s} board is not supported.`,details:{error:"not_supported",details:s}}),void await m.disconnect();l({state:"preparing",message:"Preparing installation...",details:{done:!1}});const p=d.parts.map((async e=>{if(0==r.length){const t=new URL(e.path,h).toString(),i=await fetch(t);if(!i.ok)throw new Error(`Downlading firmware ${e.path} failed: ${i.status}`);return i.arrayBuffer()}return r})),u=await m.runStub(),f=[];let g=0;for(const e of p)try{const t=await e;f.push(t),g+=t.byteLength}catch(e){return l({state:"error",message:e.message,details:{error:"failed_firmware_download",details:e.message}}),void await m.disconnect()}l({state:"preparing",message:"Installation prepared",details:{done:!0}}),o&&(l({state:"erasing",message:"Erasing device...",details:{done:!1}}),await u.eraseFlash(),l({state:"erasing",message:"Device erased",details:{done:!0}}));let b=0;l({state:"writing",message:`Writing progress: ${b}%`,details:{bytesTotal:g,bytesWritten:0,percentage:b}});let _=0;for(const e of d.parts){const t=f.shift();try{await u.flashData(t,(e=>{const t=Math.floor((_+e)/g*100);t!==b&&(b=t,l({state:"writing",message:`Writing progress: ${t}%`,details:{bytesTotal:g,bytesWritten:_+e,percentage:t}}))}),e.offset,!0)}catch(e){return l({state:"error",message:e.message,details:{error:"write_failed",details:e}}),void await m.disconnect()}_+=t.byteLength}l({state:"writing",message:"Writing complete",details:{bytesTotal:g,bytesWritten:_,percentage:100}}),await V(100),console.log("DISCONNECT"),await m.disconnect(),console.log("HARD RESET"),await m.hardReset(),l({state:"finished",message:"All done!"})},ta=(e,t="")=>{const i=new Blob([e],{type:"text/plain"}),n=URL.createObjectURL(i);((e,t="")=>{const i=document.createElement("a");i.target="_blank",i.href=e,i.download=t,document.body.appendChild(i),i.dispatchEvent(new MouseEvent("click")),document.body.removeChild(i)})(n,t),setTimeout((()=>URL.revokeObjectURL(n)),0)};class ia extends x{constructor(){super(...arguments),this.logger=console,this._state="DASHBOARD",this._installErase=!1,this._installConfirmed=!1,this._provisionForce=!1,this._wasProvisioned=!1,this._busy=!1,this._selectedSsid=-1,this._handleDisconnect=()=>{this._state="ERROR",this._error="Disconnected"}}render(){if(!this.port)return h``;let e,t,i=!1,n=!1;return void 0===this._client&&"INSTALL"!==this._state&&"LOGS"!==this._state?this._error?[e,t,i]=this._renderError(this._error):(t=this._renderProgress("Connecting"),i=!0):"INSTALL"===this._state?[e,t,i,n]=this._renderInstall():"ASK_ERASE"===this._state?[e,t]=this._renderAskErase():"ERROR"===this._state?[e,t,i]=this._renderError(this._error):"DASHBOARD"===this._state?[e,t,i,n]=this._client?this._renderDashboard():this._renderDashboardNoImprov():"PROVISION"===this._state?[e,t,i]=this._renderProvision():"LOGS"===this._state&&([e,t,i]=this._renderLogs()),h`