esp-web-flasher
Advanced tools
Comparing version 5.1.2 to 5.1.3
@@ -490,3 +490,3 @@ import { CHIP_FAMILY_ESP32, CHIP_FAMILY_ESP32S2, CHIP_FAMILY_ESP32S3, CHIP_FAMILY_ESP32C3, CHIP_FAMILY_ESP8266, MAX_TIMEOUT, DEFAULT_TIMEOUT, ERASE_REGION_TIMEOUT_PER_MB, ESP_CHANGE_BAUDRATE, ESP_CHECKSUM_MAGIC, ESP_FLASH_BEGIN, ESP_FLASH_DATA, ESP_FLASH_END, ESP_MEM_BEGIN, ESP_MEM_DATA, ESP_MEM_END, ESP_READ_REG, ESP_WRITE_REG, ESP_SPI_ATTACH, ESP_SYNC, FLASH_SECTOR_SIZE, FLASH_WRITE_SIZE, STUB_FLASH_WRITE_SIZE, MEM_END_ROM_TIMEOUT, ROM_INVALID_RECV_MSG, SYNC_PACKET, SYNC_TIMEOUT, USB_RAM_BLOCK, ESP_ERASE_FLASH, CHIP_ERASE_TIMEOUT, timeoutPerMb, ESP_ROM_BAUD, ESP_FLASH_DEFL_BEGIN, ESP_FLASH_DEFL_DATA, ESP_FLASH_DEFL_END, getSpiFlashAddresses, DETECTED_FLASH_SIZES, CHIP_DETECT_MAGIC_REG_ADDR, CHIP_DETECT_MAGIC_VALUES, SlipReadError, } from "./const"; | ||
position += flashWriteSize; | ||
updateProgress(Math.min(written, filesize), filesize); | ||
updateProgress(Math.min(written, uncompressedFilesize), uncompressedFilesize); | ||
} | ||
@@ -493,0 +493,0 @@ this.logger.log("Took " + (Date.now() - stamp) + "ms to write " + filesize + " bytes"); |
@@ -1,1 +0,1 @@ | ||
const t=t=>{let e=[];for(let a=0;a<t.length;a++){let i=t.charCodeAt(a);i<=255&&e.push(i)}return e},e=t=>"["+t.map((t=>a(t))).join(", ")+"]",a=(t,e=2)=>{let a=t.toString(16).toUpperCase();return a.startsWith("-")?"-0x"+a.substring(1).padStart(e,"0"):"0x"+a.padStart(e,"0")},i=t=>new Promise((e=>setTimeout(e,t))),s={18:"256KB",19:"512KB",20:"1MB",21:"2MB",22:"4MB",23:"8MB",24:"16MB",25:"32MB",26:"64MB"},r=t(" UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"),n=33382,o=50,l=12882,h=12883,d=12995,f=12998,c=12914,_={4293968129:{name:"ESP8266",family:33382},15736195:{name:"ESP32",family:o},1990:{name:"ESP32-S2",family:l},9:{name:"ESP32-S3",family:h},3942662454:{name:"ESP32-S3(beta2)",family:h},1763790959:{name:"ESP32-C3",family:d},456216687:{name:"ESP32-C3",family:d},3391540258:{name:"ESP32-H2",family:12914},228687983:{name:"ESP32-C6(beta)",family:12998}},u=(t,e)=>{let a=Math.floor(t*(e/486));return a<3e3?3e3:a},g=t=>{switch(t){case o:return{regBase:1072963584,baseFuse:1073061888,macFuse:1073061888,usrOffs:28,usr1Offs:32,usr2Offs:36,mosiDlenOffs:40,misoDlenOffs:44,w0Offs:128,uartDateReg:1610612856,flashOffs:4096};case l:return{regBase:1061167104,baseFuse:1061265408,macFuse:1061265476,usrOffs:24,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612856,flashOffs:4096};case h:return{regBase:1610620928,usrOffs:24,baseFuse:1610641408,macFuse:1610641476,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612864,flashOffs:0};case 33382:return{regBase:1610613248,usrOffs:28,baseFuse:1072693328,macFuse:1072693328,usr1Offs:32,usr2Offs:36,mosiDlenOffs:-1,misoDlenOffs:-1,w0Offs:64,uartDateReg:1610612856,flashOffs:0};case d:return{regBase:1610620928,baseFuse:1610647552,macFuse:1610647620,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 w extends Error{constructor(t){super(t),this.name="SlipReadError"}}const m=async e=>{let a;return e==o?a=await import("./esp32-273074c1.js"):e==l?a=await import("./esp32s2-f8cf1215.js"):e==h?a=await import("./esp32s3-b0a5f517.js"):33382==e?a=await import("./esp8266-b7fae3a7.js"):e==d&&(a=await import("./esp32c3-8f007052.js")),{...a,text:t(atob(a.text)),data:t(atob(a.data))}};function p(t){let e=t.length;for(;--e>=0;)t[e]=0}const b=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]),y=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]),k=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),v=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),x=new Array(576);p(x);const z=new Array(60);p(z);const S=new Array(512);p(S);const U=new Array(256);p(U);const E=new Array(29);p(E);const R=new Array(30);function A(t,e,a,i,s){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=s,this.has_stree=t&&t.length}let I,D,F;function B(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}p(R);const O=t=>t<256?S[t]:S[256+(t>>>7)],T=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},Z=(t,e,a)=>{t.bi_valid>16-a?(t.bi_buf|=e<<t.bi_valid&65535,T(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=a-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=a)},C=(t,e,a)=>{Z(t,a[2*e],a[2*e+1])},L=(t,e)=>{let a=0;do{a|=1&t,t>>>=1,a<<=1}while(--e>0);return a>>>1},M=(t,e,a)=>{const i=new Array(16);let s,r,n=0;for(s=1;s<=15;s++)i[s]=n=n+a[s-1]<<1;for(r=0;r<=e;r++){let e=t[2*r+1];0!==e&&(t[2*r]=L(i[e]++,e))}},N=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},P=t=>{t.bi_valid>8?T(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},H=(t,e,a,i)=>{const s=2*e,r=2*a;return t[s]<t[r]||t[s]===t[r]&&i[e]<=i[a]},$=(t,e,a)=>{const i=t.heap[a];let s=a<<1;for(;s<=t.heap_len&&(s<t.heap_len&&H(e,t.heap[s+1],t.heap[s],t.depth)&&s++,!H(e,i,t.heap[s],t.depth));)t.heap[a]=t.heap[s],a=s,s<<=1;t.heap[a]=i},j=(t,e,a)=>{let i,s,r,n,o=0;if(0!==t.last_lit)do{i=t.pending_buf[t.d_buf+2*o]<<8|t.pending_buf[t.d_buf+2*o+1],s=t.pending_buf[t.l_buf+o],o++,0===i?C(t,s,e):(r=U[s],C(t,r+256+1,e),n=b[r],0!==n&&(s-=E[r],Z(t,s,n)),i--,r=O(i),C(t,r,a),n=y[r],0!==n&&(i-=R[r],Z(t,i,n)))}while(o<t.last_lit);C(t,256,e)},V=(t,e)=>{const a=e.dyn_tree,i=e.stat_desc.static_tree,s=e.stat_desc.has_stree,r=e.stat_desc.elems;let n,o,l,h=-1;for(t.heap_len=0,t.heap_max=573,n=0;n<r;n++)0!==a[2*n]?(t.heap[++t.heap_len]=h=n,t.depth[n]=0):a[2*n+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=h<2?++h:0,a[2*l]=1,t.depth[l]=0,t.opt_len--,s&&(t.static_len-=i[2*l+1]);for(e.max_code=h,n=t.heap_len>>1;n>=1;n--)$(t,a,n);l=r;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],$(t,a,1),o=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=o,a[2*l]=a[2*n]+a[2*o],t.depth[l]=(t.depth[n]>=t.depth[o]?t.depth[n]:t.depth[o])+1,a[2*n+1]=a[2*o+1]=l,t.heap[1]=l++,$(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const a=e.dyn_tree,i=e.max_code,s=e.stat_desc.static_tree,r=e.stat_desc.has_stree,n=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,l=e.stat_desc.max_length;let h,d,f,c,_,u,g=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(a[2*t.heap[t.heap_max]+1]=0,h=t.heap_max+1;h<573;h++)d=t.heap[h],c=a[2*a[2*d+1]+1]+1,c>l&&(c=l,g++),a[2*d+1]=c,d>i||(t.bl_count[c]++,_=0,d>=o&&(_=n[d-o]),u=a[2*d],t.opt_len+=u*(c+_),r&&(t.static_len+=u*(s[2*d+1]+_)));if(0!==g){do{for(c=l-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[l]--,g-=2}while(g>0);for(c=l;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--h],f>i||(a[2*f+1]!==c&&(t.opt_len+=(c-a[2*f+1])*a[2*f],a[2*f+1]=c),d--)}})(t,e),M(a,h,t.bl_count)},W=(t,e,a)=>{let i,s,r=-1,n=e[1],o=0,l=7,h=4;for(0===n&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)s=n,n=e[2*(i+1)+1],++o<l&&s===n||(o<h?t.bl_tree[2*s]+=o:0!==s?(s!==r&&t.bl_tree[2*s]++,t.bl_tree[32]++):o<=10?t.bl_tree[34]++:t.bl_tree[36]++,o=0,r=s,0===n?(l=138,h=3):s===n?(l=6,h=3):(l=7,h=4))},K=(t,e,a)=>{let i,s,r=-1,n=e[1],o=0,l=7,h=4;for(0===n&&(l=138,h=3),i=0;i<=a;i++)if(s=n,n=e[2*(i+1)+1],!(++o<l&&s===n)){if(o<h)do{C(t,s,t.bl_tree)}while(0!=--o);else 0!==s?(s!==r&&(C(t,s,t.bl_tree),o--),C(t,16,t.bl_tree),Z(t,o-3,2)):o<=10?(C(t,17,t.bl_tree),Z(t,o-3,3)):(C(t,18,t.bl_tree),Z(t,o-11,7));o=0,r=s,0===n?(l=138,h=3):s===n?(l=6,h=3):(l=7,h=4)}};let Y=!1;const q=(t,e,a,i)=>{Z(t,0+(i?1:0),3),((t,e,a,i)=>{P(t),i&&(T(t,a),T(t,~a)),t.pending_buf.set(t.window.subarray(e,e+a),t.pending),t.pending+=a})(t,e,a,!0)};var G={_tr_init:t=>{Y||((()=>{let t,e,a,i,s;const r=new Array(16);for(a=0,i=0;i<28;i++)for(E[i]=a,t=0;t<1<<b[i];t++)U[a++]=i;for(U[a-1]=i,s=0,i=0;i<16;i++)for(R[i]=s,t=0;t<1<<y[i];t++)S[s++]=i;for(s>>=7;i<30;i++)for(R[i]=s<<7,t=0;t<1<<y[i]-7;t++)S[256+s++]=i;for(e=0;e<=15;e++)r[e]=0;for(t=0;t<=143;)x[2*t+1]=8,t++,r[8]++;for(;t<=255;)x[2*t+1]=9,t++,r[9]++;for(;t<=279;)x[2*t+1]=7,t++,r[7]++;for(;t<=287;)x[2*t+1]=8,t++,r[8]++;for(M(x,287,r),t=0;t<30;t++)z[2*t+1]=5,z[2*t]=L(t,5);I=new A(x,b,257,286,15),D=new A(z,y,0,30,15),F=new A(new Array(0),k,0,19,7)})(),Y=!0),t.l_desc=new B(t.dyn_ltree,I),t.d_desc=new B(t.dyn_dtree,D),t.bl_desc=new B(t.bl_tree,F),t.bi_buf=0,t.bi_valid=0,N(t)},_tr_stored_block:q,_tr_flush_block:(t,e,a,i)=>{let s,r,n=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,a=4093624447;for(e=0;e<=31;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),V(t,t.l_desc),V(t,t.d_desc),n=(t=>{let e;for(W(t,t.dyn_ltree,t.l_desc.max_code),W(t,t.dyn_dtree,t.d_desc.max_code),V(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*v[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),s=t.opt_len+3+7>>>3,r=t.static_len+3+7>>>3,r<=s&&(s=r)):s=r=a+5,a+4<=s&&-1!==e?q(t,e,a,i):4===t.strategy||r===s?(Z(t,2+(i?1:0),3),j(t,x,z)):(Z(t,4+(i?1:0),3),((t,e,a,i)=>{let s;for(Z(t,e-257,5),Z(t,a-1,5),Z(t,i-4,4),s=0;s<i;s++)Z(t,t.bl_tree[2*v[s]+1],3);K(t,t.dyn_ltree,e-1),K(t,t.dyn_dtree,a-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,n+1),j(t,t.dyn_ltree,t.dyn_dtree)),N(t),i&&P(t)},_tr_tally:(t,e,a)=>(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(U[a]+256+1)]++,t.dyn_dtree[2*O(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{Z(t,2,3),C(t,256,x),(t=>{16===t.bi_valid?(T(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}};var X=(t,e,a,i)=>{let s=65535&t|0,r=t>>>16&65535|0,n=0;for(;0!==a;){n=a>2e3?2e3:a,a-=n;do{s=s+e[i++]|0,r=r+s|0}while(--n);s%=65521,r%=65521}return s|r<<16|0};const Q=new Uint32Array((()=>{let t,e=[];for(var a=0;a<256;a++){t=a;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e})());var J=(t,e,a,i)=>{const s=Q,r=i+a;t^=-1;for(let a=i;a<r;a++)t=t>>>8^s[255&(t^e[a])];return-1^t},tt={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"},et={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:at,_tr_stored_block:it,_tr_flush_block:st,_tr_tally:rt,_tr_align:nt}=G,{Z_NO_FLUSH:ot,Z_PARTIAL_FLUSH:lt,Z_FULL_FLUSH:ht,Z_FINISH:dt,Z_BLOCK:ft,Z_OK:ct,Z_STREAM_END:_t,Z_STREAM_ERROR:ut,Z_DATA_ERROR:gt,Z_BUF_ERROR:wt,Z_DEFAULT_COMPRESSION:mt,Z_FILTERED:pt,Z_HUFFMAN_ONLY:bt,Z_RLE:yt,Z_FIXED:kt,Z_DEFAULT_STRATEGY:vt,Z_UNKNOWN:xt,Z_DEFLATED:zt}=et,St=(t,e)=>(t.msg=tt[e],e),Ut=t=>(t<<1)-(t>4?9:0),Et=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let Rt=(t,e,a)=>(e<<t.hash_shift^a)&t.hash_mask;const At=t=>{const e=t.state;let a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+a),t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))},It=(t,e)=>{st(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,At(t.strm)},Dt=(t,e)=>{t.pending_buf[t.pending++]=e},Ft=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Bt=(t,e,a,i)=>{let s=t.avail_in;return s>i&&(s=i),0===s?0:(t.avail_in-=s,e.set(t.input.subarray(t.next_in,t.next_in+s),a),1===t.state.wrap?t.adler=X(t.adler,e,s,a):2===t.state.wrap&&(t.adler=J(t.adler,e,s,a)),t.next_in+=s,t.total_in+=s,s)},Ot=(t,e)=>{let a,i,s=t.max_chain_length,r=t.strstart,n=t.prev_length,o=t.nice_match;const l=t.strstart>t.w_size-262?t.strstart-(t.w_size-262):0,h=t.window,d=t.w_mask,f=t.prev,c=t.strstart+258;let _=h[r+n-1],u=h[r+n];t.prev_length>=t.good_match&&(s>>=2),o>t.lookahead&&(o=t.lookahead);do{if(a=e,h[a+n]===u&&h[a+n-1]===_&&h[a]===h[r]&&h[++a]===h[r+1]){r+=2,a++;do{}while(h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&r<c);if(i=258-(c-r),r=c-258,i>n){if(t.match_start=e,n=i,i>=o)break;_=h[r+n-1],u=h[r+n]}}}while((e=f[e&d])>l&&0!=--s);return n<=t.lookahead?n:t.lookahead},Tt=t=>{const e=t.w_size;let a,i,s,r,n;do{if(r=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-262)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,i=t.hash_size,a=i;do{s=t.head[--a],t.head[a]=s>=e?s-e:0}while(--i);i=e,a=i;do{s=t.prev[--a],t.prev[a]=s>=e?s-e:0}while(--i);r+=e}if(0===t.strm.avail_in)break;if(i=Bt(t.strm,t.window,t.strstart+t.lookahead,r),t.lookahead+=i,t.lookahead+t.insert>=3)for(n=t.strstart-t.insert,t.ins_h=t.window[n],t.ins_h=Rt(t,t.ins_h,t.window[n+1]);t.insert&&(t.ins_h=Rt(t,t.ins_h,t.window[n+3-1]),t.prev[n&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=n,n++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<262&&0!==t.strm.avail_in)},Zt=(t,e)=>{let a,i;for(;;){if(t.lookahead<262){if(Tt(t),t.lookahead<262&&e===ot)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==a&&t.strstart-a<=t.w_size-262&&(t.match_length=Ot(t,a)),t.match_length>=3)if(i=rt(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+1]);else i=rt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2},Ct=(t,e)=>{let a,i,s;for(;;){if(t.lookahead<262){if(Tt(t),t.lookahead<262&&e===ot)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==a&&t.prev_length<t.max_lazy_match&&t.strstart-a<=t.w_size-262&&(t.match_length=Ot(t,a),t.match_length<=5&&(t.strategy===pt||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){s=t.strstart+t.lookahead-3,i=rt(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=s&&(t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(It(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=rt(t,0,t.window[t.strstart-1]),i&&It(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=rt(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,a,i,s){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=s}const Mt=[new Lt(0,0,0,0,((t,e)=>{let a=65535;for(a>t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Tt(t),0===t.lookahead&&e===ot)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,It(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-262&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(It(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,Zt),new Lt(4,5,16,8,Zt),new Lt(4,6,32,32,Zt),new Lt(4,4,16,16,Ct),new Lt(8,16,32,32,Ct),new Lt(8,16,128,128,Ct),new Lt(8,32,128,256,Ct),new Lt(32,128,258,1024,Ct),new Lt(32,258,258,4096,Ct)];function Nt(){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=zt,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),Et(this.dyn_ltree),Et(this.dyn_dtree),Et(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),Et(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Et(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Pt=t=>{if(!t||!t.state)return St(t,ut);t.total_in=t.total_out=0,t.data_type=xt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:113,t.adler=2===e.wrap?0:1,e.last_flush=ot,at(e),ct},Ht=t=>{const e=Pt(t);var a;return e===ct&&((a=t.state).window_size=2*a.w_size,Et(a.head),a.max_lazy_match=Mt[a.level].max_lazy,a.good_match=Mt[a.level].good_length,a.nice_match=Mt[a.level].nice_length,a.max_chain_length=Mt[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=2,a.match_available=0,a.ins_h=0),e},$t=(t,e,a,i,s,r)=>{if(!t)return ut;let n=1;if(e===mt&&(e=6),i<0?(n=0,i=-i):i>15&&(n=2,i-=16),s<1||s>9||a!==zt||i<8||i>15||e<0||e>9||r<0||r>kt)return St(t,ut);8===i&&(i=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=n,o.gzhead=null,o.w_bits=i,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=s+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+3-1)/3),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<s+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.d_buf=1*o.lit_bufsize,o.l_buf=3*o.lit_bufsize,o.level=e,o.strategy=r,o.method=a,Ht(t)};var jt={deflateInit:(t,e)=>$t(t,e,zt,15,8,vt),deflateInit2:$t,deflateReset:Ht,deflateResetKeep:Pt,deflateSetHeader:(t,e)=>t&&t.state?2!==t.state.wrap?ut:(t.state.gzhead=e,ct):ut,deflate:(t,e)=>{let a,i;if(!t||!t.state||e>ft||e<0)return t?St(t,ut):ut;const s=t.state;if(!t.output||!t.input&&0!==t.avail_in||666===s.status&&e!==dt)return St(t,0===t.avail_out?wt:ut);s.strm=t;const r=s.last_flush;if(s.last_flush=e,42===s.status)if(2===s.wrap)t.adler=0,Dt(s,31),Dt(s,139),Dt(s,8),s.gzhead?(Dt(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),Dt(s,255&s.gzhead.time),Dt(s,s.gzhead.time>>8&255),Dt(s,s.gzhead.time>>16&255),Dt(s,s.gzhead.time>>24&255),Dt(s,9===s.level?2:s.strategy>=bt||s.level<2?4:0),Dt(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(Dt(s,255&s.gzhead.extra.length),Dt(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(t.adler=J(t.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=69):(Dt(s,0),Dt(s,0),Dt(s,0),Dt(s,0),Dt(s,0),Dt(s,9===s.level?2:s.strategy>=bt||s.level<2?4:0),Dt(s,3),s.status=113);else{let e=zt+(s.w_bits-8<<4)<<8,a=-1;a=s.strategy>=bt||s.level<2?0:s.level<6?1:6===s.level?2:3,e|=a<<6,0!==s.strstart&&(e|=32),e+=31-e%31,s.status=113,Ft(s,e),0!==s.strstart&&(Ft(s,t.adler>>>16),Ft(s,65535&t.adler)),t.adler=1}if(69===s.status)if(s.gzhead.extra){for(a=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),At(t),a=s.pending,s.pending!==s.pending_buf_size));)Dt(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=73)}else s.status=73;if(73===s.status)if(s.gzhead.name){a=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),At(t),a=s.pending,s.pending===s.pending_buf_size)){i=1;break}i=s.gzindex<s.gzhead.name.length?255&s.gzhead.name.charCodeAt(s.gzindex++):0,Dt(s,i)}while(0!==i);s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),0===i&&(s.gzindex=0,s.status=91)}else s.status=91;if(91===s.status)if(s.gzhead.comment){a=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),At(t),a=s.pending,s.pending===s.pending_buf_size)){i=1;break}i=s.gzindex<s.gzhead.comment.length?255&s.gzhead.comment.charCodeAt(s.gzindex++):0,Dt(s,i)}while(0!==i);s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),0===i&&(s.status=103)}else s.status=103;if(103===s.status&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&At(t),s.pending+2<=s.pending_buf_size&&(Dt(s,255&t.adler),Dt(s,t.adler>>8&255),t.adler=0,s.status=113)):s.status=113),0!==s.pending){if(At(t),0===t.avail_out)return s.last_flush=-1,ct}else if(0===t.avail_in&&Ut(e)<=Ut(r)&&e!==dt)return St(t,wt);if(666===s.status&&0!==t.avail_in)return St(t,wt);if(0!==t.avail_in||0!==s.lookahead||e!==ot&&666!==s.status){let a=s.strategy===bt?((t,e)=>{let a;for(;;){if(0===t.lookahead&&(Tt(t),0===t.lookahead)){if(e===ot)return 1;break}if(t.match_length=0,a=rt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2})(s,e):s.strategy===yt?((t,e)=>{let a,i,s,r;const n=t.window;for(;;){if(t.lookahead<=258){if(Tt(t),t.lookahead<=258&&e===ot)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(s=t.strstart-1,i=n[s],i===n[++s]&&i===n[++s]&&i===n[++s])){r=t.strstart+258;do{}while(i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&s<r);t.match_length=258-(r-s),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(a=rt(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=rt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2})(s,e):Mt[s.level].func(s,e);if(3!==a&&4!==a||(s.status=666),1===a||3===a)return 0===t.avail_out&&(s.last_flush=-1),ct;if(2===a&&(e===lt?nt(s):e!==ft&&(it(s,0,0,!1),e===ht&&(Et(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),At(t),0===t.avail_out))return s.last_flush=-1,ct}return e!==dt?ct:s.wrap<=0?_t:(2===s.wrap?(Dt(s,255&t.adler),Dt(s,t.adler>>8&255),Dt(s,t.adler>>16&255),Dt(s,t.adler>>24&255),Dt(s,255&t.total_in),Dt(s,t.total_in>>8&255),Dt(s,t.total_in>>16&255),Dt(s,t.total_in>>24&255)):(Ft(s,t.adler>>>16),Ft(s,65535&t.adler)),At(t),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?ct:_t)},deflateEnd:t=>{if(!t||!t.state)return ut;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&103!==e&&113!==e&&666!==e?St(t,ut):(t.state=null,113===e?St(t,gt):ct)},deflateSetDictionary:(t,e)=>{let a=e.length;if(!t||!t.state)return ut;const i=t.state,s=i.wrap;if(2===s||1===s&&42!==i.status||i.lookahead)return ut;if(1===s&&(t.adler=X(t.adler,e,a,0)),i.wrap=0,a>=i.w_size){0===s&&(Et(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(a-i.w_size,a),0),e=t,a=i.w_size}const r=t.avail_in,n=t.next_in,o=t.input;for(t.avail_in=a,t.next_in=0,t.input=e,Tt(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=Rt(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,Tt(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=n,t.input=o,t.avail_in=r,i.wrap=s,ct},deflateInfo:"pako deflate (from Nodeca project)"};const Vt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Wt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(const e in a)Vt(a,e)&&(t[e]=a[e])}}return t},Kt=t=>{let e=0;for(let a=0,i=t.length;a<i;a++)e+=t[a].length;const a=new Uint8Array(e);for(let e=0,i=0,s=t.length;e<s;e++){let s=t[e];a.set(s,i),i+=s.length}return a};let Yt=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){Yt=!1}const qt=new Uint8Array(256);for(let t=0;t<256;t++)qt[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;qt[254]=qt[254]=1;var Gt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,a,i,s,r,n=t.length,o=0;for(s=0;s<n;s++)a=t.charCodeAt(s),55296==(64512&a)&&s+1<n&&(i=t.charCodeAt(s+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),s++)),o+=a<128?1:a<2048?2:a<65536?3:4;for(e=new Uint8Array(o),r=0,s=0;r<o;s++)a=t.charCodeAt(s),55296==(64512&a)&&s+1<n&&(i=t.charCodeAt(s+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),s++)),a<128?e[r++]=a:a<2048?(e[r++]=192|a>>>6,e[r++]=128|63&a):a<65536?(e[r++]=224|a>>>12,e[r++]=128|a>>>6&63,e[r++]=128|63&a):(e[r++]=240|a>>>18,e[r++]=128|a>>>12&63,e[r++]=128|a>>>6&63,e[r++]=128|63&a);return e},Xt=(t,e)=>{const a=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,s;const r=new Array(2*a);for(s=0,i=0;i<a;){let e=t[i++];if(e<128){r[s++]=e;continue}let n=qt[e];if(n>4)r[s++]=65533,i+=n-1;else{for(e&=2===n?31:3===n?15:7;n>1&&i<a;)e=e<<6|63&t[i++],n--;n>1?r[s++]=65533:e<65536?r[s++]=e:(e-=65536,r[s++]=55296|e>>10&1023,r[s++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Yt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let a="";for(let i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a})(r,s)},Qt=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let a=e-1;for(;a>=0&&128==(192&t[a]);)a--;return a<0||0===a?e:a+qt[t[a]]>e?a:e};var Jt=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 te=Object.prototype.toString,{Z_NO_FLUSH:ee,Z_SYNC_FLUSH:ae,Z_FULL_FLUSH:ie,Z_FINISH:se,Z_OK:re,Z_STREAM_END:ne,Z_DEFAULT_COMPRESSION:oe,Z_DEFAULT_STRATEGY:le,Z_DEFLATED:he}=et;function de(t){this.options=Wt({level:oe,method:he,chunkSize:16384,windowBits:15,memLevel:8,strategy:le},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Jt,this.strm.avail_out=0;let a=jt.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==re)throw new Error(tt[a]);if(e.header&&jt.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Gt(e.dictionary):"[object ArrayBuffer]"===te.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,a=jt.deflateSetDictionary(this.strm,t),a!==re)throw new Error(tt[a]);this._dict_set=!0}}function fe(t,e){const a=new de(e);if(a.push(t,!0),a.err)throw a.msg||tt[a.err];return a.result}de.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize;let s,r;if(this.ended)return!1;for(r=e===~~e?e:!0===e?se:ee,"string"==typeof t?a.input=Gt(t):"[object ArrayBuffer]"===te.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;)if(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),(r===ae||r===ie)&&a.avail_out<=6)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else{if(s=jt.deflate(a,r),s===ne)return a.next_out>0&&this.onData(a.output.subarray(0,a.next_out)),s=jt.deflateEnd(this.strm),this.onEnd(s),this.ended=!0,s===re;if(0!==a.avail_out){if(r>0&&a.next_out>0)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else if(0===a.avail_in)break}else this.onData(a.output)}return!0},de.prototype.onData=function(t){this.chunks.push(t)},de.prototype.onEnd=function(t){t===re&&(this.result=Kt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var ce={Deflate:de,deflate:fe,deflateRaw:function(t,e){return(e=e||{}).raw=!0,fe(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,fe(t,e)},constants:et};var _e=function(t,e){let a,i,s,r,n,o,l,h,d,f,c,_,u,g,w,m,p,b,y,k,v,x,z,S;const U=t.state;a=t.next_in,z=t.input,i=a+(t.avail_in-5),s=t.next_out,S=t.output,r=s-(e-t.avail_out),n=s+(t.avail_out-257),o=U.dmax,l=U.wsize,h=U.whave,d=U.wnext,f=U.window,c=U.hold,_=U.bits,u=U.lencode,g=U.distcode,w=(1<<U.lenbits)-1,m=(1<<U.distbits)-1;t:do{_<15&&(c+=z[a++]<<_,_+=8,c+=z[a++]<<_,_+=8),p=u[c&w];e:for(;;){if(b=p>>>24,c>>>=b,_-=b,b=p>>>16&255,0===b)S[s++]=65535&p;else{if(!(16&b)){if(0==(64&b)){p=u[(65535&p)+(c&(1<<b)-1)];continue e}if(32&b){U.mode=12;break t}t.msg="invalid literal/length code",U.mode=30;break t}y=65535&p,b&=15,b&&(_<b&&(c+=z[a++]<<_,_+=8),y+=c&(1<<b)-1,c>>>=b,_-=b),_<15&&(c+=z[a++]<<_,_+=8,c+=z[a++]<<_,_+=8),p=g[c&m];a:for(;;){if(b=p>>>24,c>>>=b,_-=b,b=p>>>16&255,!(16&b)){if(0==(64&b)){p=g[(65535&p)+(c&(1<<b)-1)];continue a}t.msg="invalid distance code",U.mode=30;break t}if(k=65535&p,b&=15,_<b&&(c+=z[a++]<<_,_+=8,_<b&&(c+=z[a++]<<_,_+=8)),k+=c&(1<<b)-1,k>o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=b,_-=b,b=s-r,k>b){if(b=k-b,b>h&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(v=0,x=f,0===d){if(v+=l-b,b<y){y-=b;do{S[s++]=f[v++]}while(--b);v=s-k,x=S}}else if(d<b){if(v+=l+d-b,b-=d,b<y){y-=b;do{S[s++]=f[v++]}while(--b);if(v=0,d<y){b=d,y-=b;do{S[s++]=f[v++]}while(--b);v=s-k,x=S}}}else if(v+=d-b,b<y){y-=b;do{S[s++]=f[v++]}while(--b);v=s-k,x=S}for(;y>2;)S[s++]=x[v++],S[s++]=x[v++],S[s++]=x[v++],y-=3;y&&(S[s++]=x[v++],y>1&&(S[s++]=x[v++]))}else{v=s-k;do{S[s++]=S[v++],S[s++]=S[v++],S[s++]=S[v++],y-=3}while(y>2);y&&(S[s++]=S[v++],y>1&&(S[s++]=S[v++]))}break}}break}}while(a<i&&s<n);y=_>>3,a-=y,_-=y<<3,c&=(1<<_)-1,t.next_in=a,t.next_out=s,t.avail_in=a<i?i-a+5:5-(a-i),t.avail_out=s<n?n-s+257:257-(s-n),U.hold=c,U.bits=_};const ue=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),ge=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),we=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),me=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var pe=(t,e,a,i,s,r,n,o)=>{const l=o.bits;let h,d,f,c,_,u,g=0,w=0,m=0,p=0,b=0,y=0,k=0,v=0,x=0,z=0,S=null,U=0;const E=new Uint16Array(16),R=new Uint16Array(16);let A,I,D,F=null,B=0;for(g=0;g<=15;g++)E[g]=0;for(w=0;w<i;w++)E[e[a+w]]++;for(b=l,p=15;p>=1&&0===E[p];p--);if(b>p&&(b=p),0===p)return s[r++]=20971520,s[r++]=20971520,o.bits=1,0;for(m=1;m<p&&0===E[m];m++);for(b<m&&(b=m),v=1,g=1;g<=15;g++)if(v<<=1,v-=E[g],v<0)return-1;if(v>0&&(0===t||1!==p))return-1;for(R[1]=0,g=1;g<15;g++)R[g+1]=R[g]+E[g];for(w=0;w<i;w++)0!==e[a+w]&&(n[R[e[a+w]]++]=w);if(0===t?(S=F=n,u=19):1===t?(S=ue,U-=257,F=ge,B-=257,u=256):(S=we,F=me,u=-1),z=0,w=0,g=m,_=r,y=b,k=0,f=-1,x=1<<b,c=x-1,1===t&&x>852||2===t&&x>592)return 1;for(;;){A=g-k,n[w]<u?(I=0,D=n[w]):n[w]>u?(I=F[B+n[w]],D=S[U+n[w]]):(I=96,D=0),h=1<<g-k,d=1<<y,m=d;do{d-=h,s[_+(z>>k)+d]=A<<24|I<<16|D|0}while(0!==d);for(h=1<<g-1;z&h;)h>>=1;if(0!==h?(z&=h-1,z+=h):z=0,w++,0==--E[g]){if(g===p)break;g=e[a+n[w]]}if(g>b&&(z&c)!==f){for(0===k&&(k=b),_+=m,y=g-k,v=1<<y;y+k<p&&(v-=E[y+k],!(v<=0));)y++,v<<=1;if(x+=1<<y,1===t&&x>852||2===t&&x>592)return 1;f=z&c,s[f]=b<<24|y<<16|_-r|0}}return 0!==z&&(s[_+z]=g-k<<24|64<<16|0),o.bits=b,0};const{Z_FINISH:be,Z_BLOCK:ye,Z_TREES:ke,Z_OK:ve,Z_STREAM_END:xe,Z_NEED_DICT:ze,Z_STREAM_ERROR:Se,Z_DATA_ERROR:Ue,Z_MEM_ERROR:Ee,Z_BUF_ERROR:Re,Z_DEFLATED:Ae}=et,Ie=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function De(){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 Fe=t=>{if(!t||!t.state)return Se;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,ve},Be=t=>{if(!t||!t.state)return Se;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,Fe(t)},Oe=(t,e)=>{let a;if(!t||!t.state)return Se;const i=t.state;return e<0?(a=0,e=-e):(a=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?Se:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,Be(t))},Te=(t,e)=>{if(!t)return Se;const a=new De;t.state=a,a.window=null;const i=Oe(t,e);return i!==ve&&(t.state=null),i};let Ze,Ce,Le=!0;const Me=t=>{if(Le){Ze=new Int32Array(512),Ce=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(pe(1,t.lens,0,288,Ze,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;pe(2,t.lens,0,32,Ce,0,t.work,{bits:5}),Le=!1}t.lencode=Ze,t.lenbits=9,t.distcode=Ce,t.distbits=5},Ne=(t,e,a,i)=>{let s;const r=t.state;return null===r.window&&(r.wsize=1<<r.wbits,r.wnext=0,r.whave=0,r.window=new Uint8Array(r.wsize)),i>=r.wsize?(r.window.set(e.subarray(a-r.wsize,a),0),r.wnext=0,r.whave=r.wsize):(s=r.wsize-r.wnext,s>i&&(s=i),r.window.set(e.subarray(a-i,a-i+s),r.wnext),(i-=s)?(r.window.set(e.subarray(a-i,a),0),r.wnext=i,r.whave=r.wsize):(r.wnext+=s,r.wnext===r.wsize&&(r.wnext=0),r.whave<r.wsize&&(r.whave+=s))),0};var Pe={inflateReset:Be,inflateReset2:Oe,inflateResetKeep:Fe,inflateInit:t=>Te(t,15),inflateInit2:Te,inflate:(t,e)=>{let a,i,s,r,n,o,l,h,d,f,c,_,u,g,w,m,p,b,y,k,v,x,z=0;const S=new Uint8Array(4);let U,E;const R=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return Se;a=t.state,12===a.mode&&(a.mode=13),n=t.next_out,s=t.output,l=t.avail_out,r=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,f=o,c=l,x=ve;t:for(;;)switch(a.mode){case 1:if(0===a.wrap){a.mode=13;break}for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(2&a.wrap&&35615===h){a.check=0,S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0),h=0,d=0,a.mode=2;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",a.mode=30;break}if((15&h)!==Ae){t.msg="unknown compression method",a.mode=30;break}if(h>>>=4,d-=4,v=8+(15&h),0===a.wbits)a.wbits=v;else if(v>a.wbits){t.msg="invalid window size",a.mode=30;break}a.dmax=1<<a.wbits,t.adler=a.check=1,a.mode=512&h?10:12,h=0,d=0;break;case 2:for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(a.flags=h,(255&a.flags)!==Ae){t.msg="unknown compression method",a.mode=30;break}if(57344&a.flags){t.msg="unknown header flags set",a.mode=30;break}a.head&&(a.head.text=h>>8&1),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0)),h=0,d=0,a.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.head&&(a.head.time=h),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,S[2]=h>>>16&255,S[3]=h>>>24&255,a.check=J(a.check,S,4,0)),h=0,d=0,a.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.head&&(a.head.xflags=255&h,a.head.os=h>>8),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0)),h=0,d=0,a.mode=5;case 5:if(1024&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.length=h,a.head&&(a.head.extra_len=h),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0)),h=0,d=0}else a.head&&(a.head.extra=null);a.mode=6;case 6:if(1024&a.flags&&(_=a.length,_>o&&(_=o),_&&(a.head&&(v=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(i.subarray(r,r+_),v)),512&a.flags&&(a.check=J(a.check,i,_,r)),o-=_,r+=_,a.length-=_),a.length))break t;a.length=0,a.mode=7;case 7:if(2048&a.flags){if(0===o)break t;_=0;do{v=i[r+_++],a.head&&v&&a.length<65536&&(a.head.name+=String.fromCharCode(v))}while(v&&_<o);if(512&a.flags&&(a.check=J(a.check,i,_,r)),o-=_,r+=_,v)break t}else a.head&&(a.head.name=null);a.length=0,a.mode=8;case 8:if(4096&a.flags){if(0===o)break t;_=0;do{v=i[r+_++],a.head&&v&&a.length<65536&&(a.head.comment+=String.fromCharCode(v))}while(v&&_<o);if(512&a.flags&&(a.check=J(a.check,i,_,r)),o-=_,r+=_,v)break t}else a.head&&(a.head.comment=null);a.mode=9;case 9:if(512&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h!==(65535&a.check)){t.msg="header crc mismatch",a.mode=30;break}h=0,d=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=12;break;case 10:for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}t.adler=a.check=Ie(h),h=0,d=0,a.mode=11;case 11:if(0===a.havedict)return t.next_out=n,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,ze;t.adler=a.check=1,a.mode=12;case 12:if(e===ye||e===ke)break t;case 13:if(a.last){h>>>=7&d,d-=7&d,a.mode=27;break}for(;d<3;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}switch(a.last=1&h,h>>>=1,d-=1,3&h){case 0:a.mode=14;break;case 1:if(Me(a),a.mode=20,e===ke){h>>>=2,d-=2;break t}break;case 2:a.mode=17;break;case 3:t.msg="invalid block type",a.mode=30}h>>>=2,d-=2;break;case 14:for(h>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if((65535&h)!=(h>>>16^65535)){t.msg="invalid stored block lengths",a.mode=30;break}if(a.length=65535&h,h=0,d=0,a.mode=15,e===ke)break t;case 15:a.mode=16;case 16:if(_=a.length,_){if(_>o&&(_=o),_>l&&(_=l),0===_)break t;s.set(i.subarray(r,r+_),n),o-=_,r+=_,l-=_,n+=_,a.length-=_;break}a.mode=12;break;case 17:for(;d<14;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(a.nlen=257+(31&h),h>>>=5,d-=5,a.ndist=1+(31&h),h>>>=5,d-=5,a.ncode=4+(15&h),h>>>=4,d-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=30;break}a.have=0,a.mode=18;case 18:for(;a.have<a.ncode;){for(;d<3;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.lens[R[a.have++]]=7&h,h>>>=3,d-=3}for(;a.have<19;)a.lens[R[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,U={bits:a.lenbits},x=pe(0,a.lens,0,19,a.lencode,0,a.work,U),a.lenbits=U.bits,x){t.msg="invalid code lengths set",a.mode=30;break}a.have=0,a.mode=19;case 19:for(;a.have<a.nlen+a.ndist;){for(;z=a.lencode[h&(1<<a.lenbits)-1],w=z>>>24,m=z>>>16&255,p=65535&z,!(w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(p<16)h>>>=w,d-=w,a.lens[a.have++]=p;else{if(16===p){for(E=w+2;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h>>>=w,d-=w,0===a.have){t.msg="invalid bit length repeat",a.mode=30;break}v=a.lens[a.have-1],_=3+(3&h),h>>>=2,d-=2}else if(17===p){for(E=w+3;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=w,d-=w,v=0,_=3+(7&h),h>>>=3,d-=3}else{for(E=w+7;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=w,d-=w,v=0,_=11+(127&h),h>>>=7,d-=7}if(a.have+_>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=30;break}for(;_--;)a.lens[a.have++]=v}}if(30===a.mode)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=30;break}if(a.lenbits=9,U={bits:a.lenbits},x=pe(1,a.lens,0,a.nlen,a.lencode,0,a.work,U),a.lenbits=U.bits,x){t.msg="invalid literal/lengths set",a.mode=30;break}if(a.distbits=6,a.distcode=a.distdyn,U={bits:a.distbits},x=pe(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,U),a.distbits=U.bits,x){t.msg="invalid distances set",a.mode=30;break}if(a.mode=20,e===ke)break t;case 20:a.mode=21;case 21:if(o>=6&&l>=258){t.next_out=n,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,_e(t,c),n=t.next_out,s=t.output,l=t.avail_out,r=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,12===a.mode&&(a.back=-1);break}for(a.back=0;z=a.lencode[h&(1<<a.lenbits)-1],w=z>>>24,m=z>>>16&255,p=65535&z,!(w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(m&&0==(240&m)){for(b=w,y=m,k=p;z=a.lencode[k+((h&(1<<b+y)-1)>>b)],w=z>>>24,m=z>>>16&255,p=65535&z,!(b+w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=b,d-=b,a.back+=b}if(h>>>=w,d-=w,a.back+=w,a.length=p,0===m){a.mode=26;break}if(32&m){a.back=-1,a.mode=12;break}if(64&m){t.msg="invalid literal/length code",a.mode=30;break}a.extra=15&m,a.mode=22;case 22:if(a.extra){for(E=a.extra;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.length+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=23;case 23:for(;z=a.distcode[h&(1<<a.distbits)-1],w=z>>>24,m=z>>>16&255,p=65535&z,!(w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(0==(240&m)){for(b=w,y=m,k=p;z=a.distcode[k+((h&(1<<b+y)-1)>>b)],w=z>>>24,m=z>>>16&255,p=65535&z,!(b+w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=b,d-=b,a.back+=b}if(h>>>=w,d-=w,a.back+=w,64&m){t.msg="invalid distance code",a.mode=30;break}a.offset=p,a.extra=15&m,a.mode=24;case 24:if(a.extra){for(E=a.extra;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.offset+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=30;break}a.mode=25;case 25:if(0===l)break t;if(_=c-l,a.offset>_){if(_=a.offset-_,_>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=30;break}_>a.wnext?(_-=a.wnext,u=a.wsize-_):u=a.wnext-_,_>a.length&&(_=a.length),g=a.window}else g=s,u=n-a.offset,_=a.length;_>l&&(_=l),l-=_,a.length-=_;do{s[n++]=g[u++]}while(--_);0===a.length&&(a.mode=21);break;case 26:if(0===l)break t;s[n++]=a.length,l--,a.mode=21;break;case 27:if(a.wrap){for(;d<32;){if(0===o)break t;o--,h|=i[r++]<<d,d+=8}if(c-=l,t.total_out+=c,a.total+=c,c&&(t.adler=a.check=a.flags?J(a.check,s,c,n-c):X(a.check,s,c,n-c)),c=l,(a.flags?h:Ie(h))!==a.check){t.msg="incorrect data check",a.mode=30;break}h=0,d=0}a.mode=28;case 28:if(a.wrap&&a.flags){for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h!==(4294967295&a.total)){t.msg="incorrect length check",a.mode=30;break}h=0,d=0}a.mode=29;case 29:x=xe;break t;case 30:x=Ue;break t;case 31:return Ee;case 32:default:return Se}return t.next_out=n,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,(a.wsize||c!==t.avail_out&&a.mode<30&&(a.mode<27||e!==be))&&Ne(t,t.output,t.next_out,c-t.avail_out),f-=t.avail_in,c-=t.avail_out,t.total_in+=f,t.total_out+=c,a.total+=c,a.wrap&&c&&(t.adler=a.check=a.flags?J(a.check,s,c,t.next_out-c):X(a.check,s,c,t.next_out-c)),t.data_type=a.bits+(a.last?64:0)+(12===a.mode?128:0)+(20===a.mode||15===a.mode?256:0),(0===f&&0===c||e===be)&&x===ve&&(x=Re),x},inflateEnd:t=>{if(!t||!t.state)return Se;let e=t.state;return e.window&&(e.window=null),t.state=null,ve},inflateGetHeader:(t,e)=>{if(!t||!t.state)return Se;const a=t.state;return 0==(2&a.wrap)?Se:(a.head=e,e.done=!1,ve)},inflateSetDictionary:(t,e)=>{const a=e.length;let i,s,r;return t&&t.state?(i=t.state,0!==i.wrap&&11!==i.mode?Se:11===i.mode&&(s=1,s=X(s,e,a,0),s!==i.check)?Ue:(r=Ne(t,e,a,a),r?(i.mode=31,Ee):(i.havedict=1,ve))):Se},inflateInfo:"pako inflate (from Nodeca project)"};var He=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 $e=Object.prototype.toString,{Z_NO_FLUSH:je,Z_FINISH:Ve,Z_OK:We,Z_STREAM_END:Ke,Z_NEED_DICT:Ye,Z_STREAM_ERROR:qe,Z_DATA_ERROR:Ge,Z_MEM_ERROR:Xe}=et;function Qe(t){this.options=Wt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Jt,this.strm.avail_out=0;let a=Pe.inflateInit2(this.strm,e.windowBits);if(a!==We)throw new Error(tt[a]);if(this.header=new He,Pe.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Gt(e.dictionary):"[object ArrayBuffer]"===$e.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(a=Pe.inflateSetDictionary(this.strm,e.dictionary),a!==We)))throw new Error(tt[a])}Qe.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize,s=this.options.dictionary;let r,n,o;if(this.ended)return!1;for(n=e===~~e?e:!0===e?Ve:je,"[object ArrayBuffer]"===$e.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),r=Pe.inflate(a,n),r===Ye&&s&&(r=Pe.inflateSetDictionary(a,s),r===We?r=Pe.inflate(a,n):r===Ge&&(r=Ye));a.avail_in>0&&r===Ke&&a.state.wrap>0&&0!==t[a.next_in];)Pe.inflateReset(a),r=Pe.inflate(a,n);switch(r){case qe:case Ge:case Ye:case Xe:return this.onEnd(r),this.ended=!0,!1}if(o=a.avail_out,a.next_out&&(0===a.avail_out||r===Ke))if("string"===this.options.to){let t=Qt(a.output,a.next_out),e=a.next_out-t,s=Xt(a.output,t);a.next_out=e,a.avail_out=i-e,e&&a.output.set(a.output.subarray(t,t+e),0),this.onData(s)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==We||0!==o){if(r===Ke)return r=Pe.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Qe.prototype.onData=function(t){this.chunks.push(t)},Qe.prototype.onEnd=function(t){t===We&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Kt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};const{Deflate:Je,deflate:ta,deflateRaw:ea,gzip:aa}=ce;var ia=ta;const sa={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}},ra=(t,...e)=>{let a=0;if(t.replace(/[<>]/,"").length!=e.length)throw"Pack format to Argument count mismatch";let i=[],s=!0;for(let i=0;i<t.length;i++)"<"==t[i]?s=!0:">"==t[i]?s=!1:(r(t[i],e[a]),a++);function r(t,e){if(!(t in sa))throw"Unhandled character '"+t+"' in pack format";let a=sa[t].bytes,r=new DataView(new ArrayBuffer(a));sa[t].p.bind(r)(0,e,s);for(let t=0;t<a;t++)i.push(r.getUint8(t))}return i},na=(t,e)=>{let a=0,i=[],s=!0;for(let e of t)"<"==e?s=!0:">"==e?s=!1:r(e);function r(t){if(!(t in sa))throw"Unhandled character '"+t+"' in unpack format";let r=sa[t].bytes,n=new DataView(new ArrayBuffer(r));for(let t=0;t<r;t++)n.setUint8(t,255&e[a+t]);let o=sa[t].u.bind(n);i.push(o(0,s)),a+=r}return i};class oa extends EventTarget{constructor(t,e,a){super(),this.port=t,this.logger=e,this._parent=a,this.chipName=null,this._efuses=new Array(4).fill(0),this._flashsize=4194304,this.debug=!1,this.IS_STUB=!1,this.connected=!0,this.flashSize=null}get _inputBuffer(){return this._parent?this._parent._inputBuffer:this.__inputBuffer}async initialize(){await this.hardReset(!0),this._parent||(this.__inputBuffer=[],this.readLoop()),await this.sync();let t=await this.readRegister(1073745920),e=_[t>>>0];if(void 0===e)throw new Error(`Unknown Chip: Hex: ${a(t>>>0,8).toLowerCase()} Number: ${t}`);this.chipName=e.name,this.chipFamily=e.family;let i=g(this.getChipFamily()).macFuse;for(let t=0;t<4;t++)this._efuses[t]=await this.readRegister(i+4*t);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:t,done:e}=await this._reader.read();if(e){this._reader.releaseLock();break}t&&0!==t.length&&this._inputBuffer.push(...Array.from(t))}}catch(t){console.error("Read loop got disconnected")}this.connected=!1,this.dispatchEvent(new Event("disconnect")),this.logger.debug("Finished read loop")}async hardReset(t=!1){this.logger.log("Try hard reset."),await this.port.setSignals({dataTerminalReady:!1,requestToSend:!0}),await this.port.setSignals({dataTerminalReady:t,requestToSend:!1}),await new Promise((t=>setTimeout(t,1e3)))}macAddr(){let t,e=new Array(6).fill(0),a=this._efuses[0],i=this._efuses[1],s=this._efuses[2],r=this._efuses[3];if(33382==this.chipFamily){if(0!=r)t=[r>>16&255,r>>8&255,255&r];else if(0==(i>>16&255))t=[24,254,52];else{if(1!=(i>>16&255))throw new Error("Couldnt determine OUI");t=[172,208,116]}e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=i>>8&255,e[4]=255&i,e[5]=a>>24&255}else if(this.chipFamily==o)e[0]=s>>8&255,e[1]=255&s,e[2]=i>>24&255,e[3]=i>>16&255,e[4]=i>>8&255,e[5]=255&i;else{if(this.chipFamily!=l&&this.chipFamily!=h&&this.chipFamily!=d)throw new Error("Unknown chip family");e[0]=i>>8&255,e[1]=255&i,e[2]=a>>24&255,e[3]=a>>16&255,e[4]=a>>8&255,e[5]=255&a}return e}async readRegister(t){this.debug&&this.logger.debug("Reading from Register "+a(t,8));let e=ra("<I",t);await this.sendCommand(10,e);let[i,s]=await this.getResponse(10);return i}async checkCommand(t,e,i=0,s=3e3){s=Math.min(s,12e5),await this.sendCommand(t,e,i);let[r,n]=await this.getResponse(t,s);if(null===n)throw new Error("Didn't get enough status bytes");let f=0;if(this.IS_STUB||33382==this.chipFamily?f=2:[o,l,h,d].includes(this.chipFamily)?f=4:[2,4].includes(n.length)&&(f=n.length),n.length<f)throw new Error("Didn't get enough status bytes");let c=n.slice(-f,n.length);if(n=n.slice(0,-f),this.debug&&(this.logger.debug("status",c),this.logger.debug("value",r),this.logger.debug("data",n)),1==c[0])throw 5==c[1]?new Error("Invalid (unsupported) command "+a(t)):new Error("Command failure error code "+a(c[1]));return[r,n]}async sendCommand(t,e,a=0){let i=(t=>{let e=[192];for(let a of t)219==a?e=e.concat([219,221]):192==a?e=e.concat([219,220]):e.push(a);return e.push(192),e})([...ra("<BBHI",0,t,e.length,a),...e]);this.debug&&this.logger.debug(`Writing ${i.length} byte${1==i.length?"":"s"}:`,i),await this.writeToStream(i)}async readPacket(t){let s=null,r=!1,n=[];for(;;){let o=Date.now();for(n=[];Date.now()-o<t;){if(this._inputBuffer.length>0){n.push(this._inputBuffer.shift());break}await i(10)}if(0==n.length){throw new w("Timed out waiting for packet "+(null===s?"header":"content"))}this.debug&&this.logger.debug("Read "+n.length+" bytes: "+e(n));for(let t of n)if(null===s){if(192!=t)throw this.debug&&(this.logger.debug("Read invalid data: "+e(n)),this.logger.debug("Remaining data in serial buffer: "+e(this._inputBuffer))),new w("Invalid head of packet ("+a(t)+")");s=[]}else if(r)if(r=!1,220==t)s.push(192);else{if(221!=t)throw this.debug&&(this.logger.debug("Read invalid data: "+e(n)),this.logger.debug("Remaining data in serial buffer: "+e(this._inputBuffer))),new w("Invalid SLIP escape (0xdb, "+a(t)+")");s.push(219)}else if(219==t)r=!0;else{if(192==t)return this.debug&&this.logger.debug("Received full packet: "+e(s)),s;s.push(t)}}throw new w("Invalid state")}async getResponse(t,e=3e3){for(let i=0;i<100;i++){const i=await this.readPacket(e);if(i.length<8)continue;const[s,r,n,o]=na("<BBHI",i.slice(0,8));if(1!=s)continue;const l=i.slice(8);if(null==t||r==t)return[o,l];if(0!=l[0]&&5==l[1])throw this._inputBuffer.length=0,new Error(`Invalid (unsupported) command ${a(t)}`)}throw"Response doesn't match request"}checksum(t,e=239){for(let a of t)e^=a;return e}async setBaudrate(t){if(33382==this.chipFamily)throw new Error("Changing baud rate is not supported on the ESP8266");this.logger.log("Attempting to change baud rate to "+t+"...");try{let e=ra("<II",t,this.IS_STUB?115200:0);await this.checkCommand(15,e)}catch(e){throw console.error(e),new Error(`Unable to change the baud rate to ${t}: No response from set baud rate command.`)}this._parent?await this._parent.reconfigurePort(t):await this.reconfigurePort(t)}async reconfigurePort(t){var e;try{await(null===(e=this._reader)||void 0===e?void 0:e.cancel()),await this.port.close(),await this.port.open({baudRate:t}),this.readLoop(),this.logger.log(`Changed baud rate to ${t}`)}catch(e){throw console.error(e),new Error(`Unable to change the baud rate to ${t}: ${e}`)}}async sync(){for(let t=0;t<5;t++){if(this._inputBuffer.length=0,await this._sync())return await i(100),!0;await i(100)}throw new Error("Couldn't sync to ESP. Try resetting.")}async _sync(){await this.sendCommand(8,r);for(let t=0;t<8;t++)try{let[t,e]=await this.getResponse(8,100);if(e.length>1&&0==e[0]&&0==e[1])return!0}catch(t){}return!1}getFlashWriteSize(){return this.IS_STUB?16384:1024}async flashData(t,e,i=0,s=!1){if(t.byteLength>=8){var r=Array.from(new Uint8Array(t,0,4));let e=r[0],i=r[2],s=r[3];this.logger.log(`Image header, Magic=${a(e)}, FlashMode=${a(i)}, FlashSizeFreq=${a(s)}`)}let n,o=t.byteLength,l=0;s?(n=ia(new Uint8Array(t),{level:9}).buffer,l=n.byteLength,this.logger.log(`Writing data with filesize: ${o}. Compressed Size: ${l}`),await this.flashDeflBegin(o,l,i)):(this.logger.log(`Writing data with filesize: ${o}`),n=t,await this.flashBegin(o,i));let h=[],d=0,f=0,c=0,_=Date.now(),u=this.getFlashWriteSize(),g=s?l:o;for(;g-c>0;)this.debug&&this.logger.log(`Writing at ${a(i+d*u,8)} `),g-c>=u?h=Array.from(new Uint8Array(n,c,u)):(h=Array.from(new Uint8Array(n,c,g-c)),s||(h=h.concat(new Array(u-h.length).fill(255)))),s?await this.flashDeflBlock(h,d):await this.flashBlock(h,d),d+=1,f+=s?Math.round(h.length*o/l):h.length,c+=u,e(Math.min(f,g),g);this.logger.log("Took "+(Date.now()-_)+"ms to write "+g+" bytes"),this.IS_STUB&&(await this.flashBegin(0,0),s?await this.flashDeflFinish():await this.flashFinish())}async flashBlock(t,e,a=3e3){await this.checkCommand(3,ra("<IIII",t.length,e,0,0).concat(t),this.checksum(t),a)}async flashDeflBlock(t,e,a=3e3){await this.checkCommand(17,ra("<IIII",t.length,e,0,0).concat(t),this.checksum(t))}async flashBegin(t=0,e=0,i=!1){let s,r,n=this.getFlashWriteSize();!this.IS_STUB&&[o,l,h,d].includes(this.chipFamily)&&await this.checkCommand(13,new Array(8).fill(0));let f,c=Math.floor((t+n-1)/n);s=33382==this.chipFamily?this.getEraseSize(e,t):t,f=this.IS_STUB?3e3:u(3e4,t);let _=Date.now();return r=ra("<IIII",s,c,n,e),this.chipFamily!=o&&this.chipFamily!=l&&this.chipFamily!=h&&this.chipFamily!=d||(r=r.concat(ra("<I",i?1:0))),this.logger.log("Erase size "+s+", blocks "+c+", block size "+a(n,4)+", offset "+a(e,4)+", encrypted "+(i?"yes":"no")),await this.checkCommand(2,r,0,f),0==t||this.IS_STUB||this.logger.log("Took "+(Date.now()-_)+"ms to erase "+c+" bytes"),c}async flashDeflBegin(t=0,e=0,a=0,i=!1){let s,r=this.getFlashWriteSize(),n=Math.floor((e+r-1)/r),o=Math.floor((t+r-1)/r),l=0,h=0;return this.IS_STUB?(l=t,h=3e3):(l=o*r,h=u(3e4,l)),s=ra("<IIII",l,n,r,a),await this.checkCommand(16,s,0,h),n}async flashFinish(){let t=ra("<I",1);await this.checkCommand(4,t)}async flashDeflFinish(){let t=ra("<I",1);await this.checkCommand(18,t)}getBootloaderOffset(){return g(this.getChipFamily()).flashOffs}async flashId(){return await this.runSpiFlashCommand(159,[],24)}getChipFamily(){return this._parent?this._parent.chipFamily:this.chipFamily}async writeRegister(t,e,a=4294967295,i=0,s=0){let r=ra("<IIII",t,e,a,i);s>0&&r.concat(ra("<IIII",g(this.getChipFamily()).uartDateReg,0,0,s)),await this.checkCommand(9,r)}async setDataLengths(t,e,a){if(-1!=t.mosiDlenOffs){let i=t.regBase+t.mosiDlenOffs,s=t.regBase+t.misoDlenOffs;e>0&&await this.writeRegister(i,e-1),a>0&&await this.writeRegister(s,a-1)}else{let i=t.regBase+t.usr1Offs,s=(0==a?0:a-1)<<8|(0==e?0:e-1)<<17;await this.writeRegister(i,s)}}async waitDone(t,e){for(let a=0;a<10;a++){if(0==(await this.readRegister(t)&e))return}throw Error("SPI command did not complete in time")}async runSpiFlashCommand(t,e,i=0){let s=g(this.getChipFamily()),r=s.regBase,n=r,o=r+s.usrOffs,l=r+s.usr2Offs,h=r+s.w0Offs,d=1<<18;if(i>32)throw new Error("Reading more than 32 bits back from a SPI flash operation is unsupported");if(e.length>64)throw new Error("Writing more than 64 bytes of data with one SPI command is unsupported");let f=8*e.length,c=await this.readRegister(o),_=await this.readRegister(l),u=1<<31;if(i>0&&(u|=268435456),f>0&&(u|=134217728),await this.setDataLengths(s,f,i),await this.writeRegister(o,u),await this.writeRegister(l,7<<28|t),0==f)await this.writeRegister(h,0);else{e.concat(new Array(e.length%4).fill(0));let t=na("I".repeat(Math.floor(e.length/4)),e),i=h;this.logger.debug(`Words Length: ${t.length}`);for(const e of t)this.logger.debug(`Writing word ${a(e)} to register offset ${a(i)}`),await this.writeRegister(i,e),i+=4}await this.writeRegister(n,d),await this.waitDone(n,d);let w=await this.readRegister(h);return await this.writeRegister(o,c),await this.writeRegister(l,_),w}async detectFlashSize(){this.logger.log("Detecting Flash Size");let t=await this.flashId(),e=255&t,i=t>>16&255;this.logger.log(`FlashId: ${a(t)}`),this.logger.log(`Flash Manufacturer: ${e.toString(16)}`),this.logger.log(`Flash Device: ${(t>>8&255).toString(16)}${i.toString(16)}`),this.flashSize=s[i],this.logger.log(`Auto-detected Flash size: ${this.flashSize}`)}getEraseSize(t,e){let a=4096,i=Math.floor((e+a-1)/a),s=16-Math.floor(t/a)%16;return i<s&&(s=i),i<2*s?Math.floor((i+1)/2*a):(i-s)*a}async memBegin(t,e,a,i){return await this.checkCommand(5,ra("<IIII",t,e,a,i))}async memBlock(t,e){return await this.checkCommand(7,ra("<IIII",t.length,e,0,0).concat(t),this.checksum(t))}async memFinish(t=0){let e=this.IS_STUB?3e3:500,a=ra("<II",0==t?1:0,t);return await this.checkCommand(6,a,0,e)}async runStub(){const t=await m(this.chipFamily);let e,a=2048;this.logger.log("Uploading stub...");for(let e of["text","data"])if(Object.keys(t).includes(e)){let i=t[e+"_start"],s=t[e].length,r=Math.floor((s+a-1)/a);await this.memBegin(s,r,a,i);for(let i of Array(r).keys()){let r=i*a,n=r+a;n>s&&(n=s),await this.memBlock(t[e].slice(r,n),i)}}this.logger.log("Running stub..."),await this.memFinish(t.entry);const i=await this.readPacket(500);if(e=String.fromCharCode(...i),"OHAI"!=e)throw new Error("Failed to start stub. Unexpected response: "+e);this.logger.log("Stub is now running...");const s=new la(this.port,this.logger,this);return await s.detectFlashSize(),s}async writeToStream(t){const e=this.port.writable.getWriter();await e.write(new Uint8Array(t));try{e.releaseLock()}catch(t){console.error("Ignoring release lock error",t)}}async disconnect(){this._parent?await this._parent.disconnect():(await this.port.writable.getWriter().close(),await new Promise((t=>{this._reader||t(void 0),this.addEventListener("disconnect",t,{once:!0}),this._reader.cancel()})),this.connected=!1)}}class la extends oa{constructor(){super(...arguments),this.IS_STUB=!0}async memBegin(t,e,i,s){let r=await m(this.chipFamily),n=s,o=s+t;console.log(n,o),console.log(r.data_start,r.data.length,r.text_start,r.text.length);for(let[t,e]of[[r.data_start,r.data_start+r.data.length],[r.text_start,r.text_start+r.text.length]])if(n<e&&o>t)throw new Error("Software loader is resident at "+a(t,8)+"-"+a(e,8)+". Can't load binary at overlapping address range "+a(n,8)+"-"+a(o,8)+". Try changing the binary loading address.")}async eraseFlash(){await this.checkCommand(208,[],0,6e5)}}const ha=async t=>{const e=await navigator.serial.requestPort();return t.log("Connecting..."),await e.open({baudRate:115200}),t.log("Connected successfully."),new oa(e,t)};export{o as CHIP_FAMILY_ESP32,d as CHIP_FAMILY_ESP32C3,f as CHIP_FAMILY_ESP32C6,c as CHIP_FAMILY_ESP32H2,l as CHIP_FAMILY_ESP32S2,h as CHIP_FAMILY_ESP32S3,n as CHIP_FAMILY_ESP8266,oa as ESPLoader,ha as connect}; | ||
const t=t=>{let e=[];for(let a=0;a<t.length;a++){let i=t.charCodeAt(a);i<=255&&e.push(i)}return e},e=t=>"["+t.map((t=>a(t))).join(", ")+"]",a=(t,e=2)=>{let a=t.toString(16).toUpperCase();return a.startsWith("-")?"-0x"+a.substring(1).padStart(e,"0"):"0x"+a.padStart(e,"0")},i=t=>new Promise((e=>setTimeout(e,t))),s={18:"256KB",19:"512KB",20:"1MB",21:"2MB",22:"4MB",23:"8MB",24:"16MB",25:"32MB",26:"64MB"},r=t(" UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"),n=33382,o=50,l=12882,h=12883,d=12995,f=12998,c=12914,_={4293968129:{name:"ESP8266",family:33382},15736195:{name:"ESP32",family:o},1990:{name:"ESP32-S2",family:l},9:{name:"ESP32-S3",family:h},3942662454:{name:"ESP32-S3(beta2)",family:h},1763790959:{name:"ESP32-C3",family:d},456216687:{name:"ESP32-C3",family:d},3391540258:{name:"ESP32-H2",family:12914},228687983:{name:"ESP32-C6(beta)",family:12998}},u=(t,e)=>{let a=Math.floor(t*(e/486));return a<3e3?3e3:a},g=t=>{switch(t){case o:return{regBase:1072963584,baseFuse:1073061888,macFuse:1073061888,usrOffs:28,usr1Offs:32,usr2Offs:36,mosiDlenOffs:40,misoDlenOffs:44,w0Offs:128,uartDateReg:1610612856,flashOffs:4096};case l:return{regBase:1061167104,baseFuse:1061265408,macFuse:1061265476,usrOffs:24,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612856,flashOffs:4096};case h:return{regBase:1610620928,usrOffs:24,baseFuse:1610641408,macFuse:1610641476,usr1Offs:28,usr2Offs:32,mosiDlenOffs:36,misoDlenOffs:40,w0Offs:88,uartDateReg:1610612864,flashOffs:0};case 33382:return{regBase:1610613248,usrOffs:28,baseFuse:1072693328,macFuse:1072693328,usr1Offs:32,usr2Offs:36,mosiDlenOffs:-1,misoDlenOffs:-1,w0Offs:64,uartDateReg:1610612856,flashOffs:0};case d:return{regBase:1610620928,baseFuse:1610647552,macFuse:1610647620,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 w extends Error{constructor(t){super(t),this.name="SlipReadError"}}const m=async e=>{let a;return e==o?a=await import("./esp32-273074c1.js"):e==l?a=await import("./esp32s2-f8cf1215.js"):e==h?a=await import("./esp32s3-b0a5f517.js"):33382==e?a=await import("./esp8266-b7fae3a7.js"):e==d&&(a=await import("./esp32c3-8f007052.js")),{...a,text:t(atob(a.text)),data:t(atob(a.data))}};function p(t){let e=t.length;for(;--e>=0;)t[e]=0}const b=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]),y=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]),k=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),v=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),x=new Array(576);p(x);const z=new Array(60);p(z);const S=new Array(512);p(S);const U=new Array(256);p(U);const E=new Array(29);p(E);const R=new Array(30);function A(t,e,a,i,s){this.static_tree=t,this.extra_bits=e,this.extra_base=a,this.elems=i,this.max_length=s,this.has_stree=t&&t.length}let I,D,F;function B(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}p(R);const O=t=>t<256?S[t]:S[256+(t>>>7)],T=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},Z=(t,e,a)=>{t.bi_valid>16-a?(t.bi_buf|=e<<t.bi_valid&65535,T(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=a-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=a)},C=(t,e,a)=>{Z(t,a[2*e],a[2*e+1])},L=(t,e)=>{let a=0;do{a|=1&t,t>>>=1,a<<=1}while(--e>0);return a>>>1},M=(t,e,a)=>{const i=new Array(16);let s,r,n=0;for(s=1;s<=15;s++)i[s]=n=n+a[s-1]<<1;for(r=0;r<=e;r++){let e=t[2*r+1];0!==e&&(t[2*r]=L(i[e]++,e))}},N=t=>{let e;for(e=0;e<286;e++)t.dyn_ltree[2*e]=0;for(e=0;e<30;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.last_lit=t.matches=0},P=t=>{t.bi_valid>8?T(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},H=(t,e,a,i)=>{const s=2*e,r=2*a;return t[s]<t[r]||t[s]===t[r]&&i[e]<=i[a]},$=(t,e,a)=>{const i=t.heap[a];let s=a<<1;for(;s<=t.heap_len&&(s<t.heap_len&&H(e,t.heap[s+1],t.heap[s],t.depth)&&s++,!H(e,i,t.heap[s],t.depth));)t.heap[a]=t.heap[s],a=s,s<<=1;t.heap[a]=i},j=(t,e,a)=>{let i,s,r,n,o=0;if(0!==t.last_lit)do{i=t.pending_buf[t.d_buf+2*o]<<8|t.pending_buf[t.d_buf+2*o+1],s=t.pending_buf[t.l_buf+o],o++,0===i?C(t,s,e):(r=U[s],C(t,r+256+1,e),n=b[r],0!==n&&(s-=E[r],Z(t,s,n)),i--,r=O(i),C(t,r,a),n=y[r],0!==n&&(i-=R[r],Z(t,i,n)))}while(o<t.last_lit);C(t,256,e)},V=(t,e)=>{const a=e.dyn_tree,i=e.stat_desc.static_tree,s=e.stat_desc.has_stree,r=e.stat_desc.elems;let n,o,l,h=-1;for(t.heap_len=0,t.heap_max=573,n=0;n<r;n++)0!==a[2*n]?(t.heap[++t.heap_len]=h=n,t.depth[n]=0):a[2*n+1]=0;for(;t.heap_len<2;)l=t.heap[++t.heap_len]=h<2?++h:0,a[2*l]=1,t.depth[l]=0,t.opt_len--,s&&(t.static_len-=i[2*l+1]);for(e.max_code=h,n=t.heap_len>>1;n>=1;n--)$(t,a,n);l=r;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],$(t,a,1),o=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=o,a[2*l]=a[2*n]+a[2*o],t.depth[l]=(t.depth[n]>=t.depth[o]?t.depth[n]:t.depth[o])+1,a[2*n+1]=a[2*o+1]=l,t.heap[1]=l++,$(t,a,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const a=e.dyn_tree,i=e.max_code,s=e.stat_desc.static_tree,r=e.stat_desc.has_stree,n=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,l=e.stat_desc.max_length;let h,d,f,c,_,u,g=0;for(c=0;c<=15;c++)t.bl_count[c]=0;for(a[2*t.heap[t.heap_max]+1]=0,h=t.heap_max+1;h<573;h++)d=t.heap[h],c=a[2*a[2*d+1]+1]+1,c>l&&(c=l,g++),a[2*d+1]=c,d>i||(t.bl_count[c]++,_=0,d>=o&&(_=n[d-o]),u=a[2*d],t.opt_len+=u*(c+_),r&&(t.static_len+=u*(s[2*d+1]+_)));if(0!==g){do{for(c=l-1;0===t.bl_count[c];)c--;t.bl_count[c]--,t.bl_count[c+1]+=2,t.bl_count[l]--,g-=2}while(g>0);for(c=l;0!==c;c--)for(d=t.bl_count[c];0!==d;)f=t.heap[--h],f>i||(a[2*f+1]!==c&&(t.opt_len+=(c-a[2*f+1])*a[2*f],a[2*f+1]=c),d--)}})(t,e),M(a,h,t.bl_count)},W=(t,e,a)=>{let i,s,r=-1,n=e[1],o=0,l=7,h=4;for(0===n&&(l=138,h=3),e[2*(a+1)+1]=65535,i=0;i<=a;i++)s=n,n=e[2*(i+1)+1],++o<l&&s===n||(o<h?t.bl_tree[2*s]+=o:0!==s?(s!==r&&t.bl_tree[2*s]++,t.bl_tree[32]++):o<=10?t.bl_tree[34]++:t.bl_tree[36]++,o=0,r=s,0===n?(l=138,h=3):s===n?(l=6,h=3):(l=7,h=4))},K=(t,e,a)=>{let i,s,r=-1,n=e[1],o=0,l=7,h=4;for(0===n&&(l=138,h=3),i=0;i<=a;i++)if(s=n,n=e[2*(i+1)+1],!(++o<l&&s===n)){if(o<h)do{C(t,s,t.bl_tree)}while(0!=--o);else 0!==s?(s!==r&&(C(t,s,t.bl_tree),o--),C(t,16,t.bl_tree),Z(t,o-3,2)):o<=10?(C(t,17,t.bl_tree),Z(t,o-3,3)):(C(t,18,t.bl_tree),Z(t,o-11,7));o=0,r=s,0===n?(l=138,h=3):s===n?(l=6,h=3):(l=7,h=4)}};let Y=!1;const q=(t,e,a,i)=>{Z(t,0+(i?1:0),3),((t,e,a,i)=>{P(t),i&&(T(t,a),T(t,~a)),t.pending_buf.set(t.window.subarray(e,e+a),t.pending),t.pending+=a})(t,e,a,!0)};var G={_tr_init:t=>{Y||((()=>{let t,e,a,i,s;const r=new Array(16);for(a=0,i=0;i<28;i++)for(E[i]=a,t=0;t<1<<b[i];t++)U[a++]=i;for(U[a-1]=i,s=0,i=0;i<16;i++)for(R[i]=s,t=0;t<1<<y[i];t++)S[s++]=i;for(s>>=7;i<30;i++)for(R[i]=s<<7,t=0;t<1<<y[i]-7;t++)S[256+s++]=i;for(e=0;e<=15;e++)r[e]=0;for(t=0;t<=143;)x[2*t+1]=8,t++,r[8]++;for(;t<=255;)x[2*t+1]=9,t++,r[9]++;for(;t<=279;)x[2*t+1]=7,t++,r[7]++;for(;t<=287;)x[2*t+1]=8,t++,r[8]++;for(M(x,287,r),t=0;t<30;t++)z[2*t+1]=5,z[2*t]=L(t,5);I=new A(x,b,257,286,15),D=new A(z,y,0,30,15),F=new A(new Array(0),k,0,19,7)})(),Y=!0),t.l_desc=new B(t.dyn_ltree,I),t.d_desc=new B(t.dyn_dtree,D),t.bl_desc=new B(t.bl_tree,F),t.bi_buf=0,t.bi_valid=0,N(t)},_tr_stored_block:q,_tr_flush_block:(t,e,a,i)=>{let s,r,n=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,a=4093624447;for(e=0;e<=31;e++,a>>>=1)if(1&a&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<256;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),V(t,t.l_desc),V(t,t.d_desc),n=(t=>{let e;for(W(t,t.dyn_ltree,t.l_desc.max_code),W(t,t.dyn_dtree,t.d_desc.max_code),V(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*v[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),s=t.opt_len+3+7>>>3,r=t.static_len+3+7>>>3,r<=s&&(s=r)):s=r=a+5,a+4<=s&&-1!==e?q(t,e,a,i):4===t.strategy||r===s?(Z(t,2+(i?1:0),3),j(t,x,z)):(Z(t,4+(i?1:0),3),((t,e,a,i)=>{let s;for(Z(t,e-257,5),Z(t,a-1,5),Z(t,i-4,4),s=0;s<i;s++)Z(t,t.bl_tree[2*v[s]+1],3);K(t,t.dyn_ltree,e-1),K(t,t.dyn_dtree,a-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,n+1),j(t,t.dyn_ltree,t.dyn_dtree)),N(t),i&&P(t)},_tr_tally:(t,e,a)=>(t.pending_buf[t.d_buf+2*t.last_lit]=e>>>8&255,t.pending_buf[t.d_buf+2*t.last_lit+1]=255&e,t.pending_buf[t.l_buf+t.last_lit]=255&a,t.last_lit++,0===e?t.dyn_ltree[2*a]++:(t.matches++,e--,t.dyn_ltree[2*(U[a]+256+1)]++,t.dyn_dtree[2*O(e)]++),t.last_lit===t.lit_bufsize-1),_tr_align:t=>{Z(t,2,3),C(t,256,x),(t=>{16===t.bi_valid?(T(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}};var X=(t,e,a,i)=>{let s=65535&t|0,r=t>>>16&65535|0,n=0;for(;0!==a;){n=a>2e3?2e3:a,a-=n;do{s=s+e[i++]|0,r=r+s|0}while(--n);s%=65521,r%=65521}return s|r<<16|0};const Q=new Uint32Array((()=>{let t,e=[];for(var a=0;a<256;a++){t=a;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[a]=t}return e})());var J=(t,e,a,i)=>{const s=Q,r=i+a;t^=-1;for(let a=i;a<r;a++)t=t>>>8^s[255&(t^e[a])];return-1^t},tt={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"},et={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:at,_tr_stored_block:it,_tr_flush_block:st,_tr_tally:rt,_tr_align:nt}=G,{Z_NO_FLUSH:ot,Z_PARTIAL_FLUSH:lt,Z_FULL_FLUSH:ht,Z_FINISH:dt,Z_BLOCK:ft,Z_OK:ct,Z_STREAM_END:_t,Z_STREAM_ERROR:ut,Z_DATA_ERROR:gt,Z_BUF_ERROR:wt,Z_DEFAULT_COMPRESSION:mt,Z_FILTERED:pt,Z_HUFFMAN_ONLY:bt,Z_RLE:yt,Z_FIXED:kt,Z_DEFAULT_STRATEGY:vt,Z_UNKNOWN:xt,Z_DEFLATED:zt}=et,St=(t,e)=>(t.msg=tt[e],e),Ut=t=>(t<<1)-(t>4?9:0),Et=t=>{let e=t.length;for(;--e>=0;)t[e]=0};let Rt=(t,e,a)=>(e<<t.hash_shift^a)&t.hash_mask;const At=t=>{const e=t.state;let a=e.pending;a>t.avail_out&&(a=t.avail_out),0!==a&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+a),t.next_out),t.next_out+=a,e.pending_out+=a,t.total_out+=a,t.avail_out-=a,e.pending-=a,0===e.pending&&(e.pending_out=0))},It=(t,e)=>{st(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,At(t.strm)},Dt=(t,e)=>{t.pending_buf[t.pending++]=e},Ft=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Bt=(t,e,a,i)=>{let s=t.avail_in;return s>i&&(s=i),0===s?0:(t.avail_in-=s,e.set(t.input.subarray(t.next_in,t.next_in+s),a),1===t.state.wrap?t.adler=X(t.adler,e,s,a):2===t.state.wrap&&(t.adler=J(t.adler,e,s,a)),t.next_in+=s,t.total_in+=s,s)},Ot=(t,e)=>{let a,i,s=t.max_chain_length,r=t.strstart,n=t.prev_length,o=t.nice_match;const l=t.strstart>t.w_size-262?t.strstart-(t.w_size-262):0,h=t.window,d=t.w_mask,f=t.prev,c=t.strstart+258;let _=h[r+n-1],u=h[r+n];t.prev_length>=t.good_match&&(s>>=2),o>t.lookahead&&(o=t.lookahead);do{if(a=e,h[a+n]===u&&h[a+n-1]===_&&h[a]===h[r]&&h[++a]===h[r+1]){r+=2,a++;do{}while(h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&h[++r]===h[++a]&&r<c);if(i=258-(c-r),r=c-258,i>n){if(t.match_start=e,n=i,i>=o)break;_=h[r+n-1],u=h[r+n]}}}while((e=f[e&d])>l&&0!=--s);return n<=t.lookahead?n:t.lookahead},Tt=t=>{const e=t.w_size;let a,i,s,r,n;do{if(r=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-262)){t.window.set(t.window.subarray(e,e+e),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,i=t.hash_size,a=i;do{s=t.head[--a],t.head[a]=s>=e?s-e:0}while(--i);i=e,a=i;do{s=t.prev[--a],t.prev[a]=s>=e?s-e:0}while(--i);r+=e}if(0===t.strm.avail_in)break;if(i=Bt(t.strm,t.window,t.strstart+t.lookahead,r),t.lookahead+=i,t.lookahead+t.insert>=3)for(n=t.strstart-t.insert,t.ins_h=t.window[n],t.ins_h=Rt(t,t.ins_h,t.window[n+1]);t.insert&&(t.ins_h=Rt(t,t.ins_h,t.window[n+3-1]),t.prev[n&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=n,n++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<262&&0!==t.strm.avail_in)},Zt=(t,e)=>{let a,i;for(;;){if(t.lookahead<262){if(Tt(t),t.lookahead<262&&e===ot)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==a&&t.strstart-a<=t.w_size-262&&(t.match_length=Ot(t,a)),t.match_length>=3)if(i=rt(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+1]);else i=rt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2},Ct=(t,e)=>{let a,i,s;for(;;){if(t.lookahead<262){if(Tt(t),t.lookahead<262&&e===ot)return 1;if(0===t.lookahead)break}if(a=0,t.lookahead>=3&&(t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==a&&t.prev_length<t.max_lazy_match&&t.strstart-a<=t.w_size-262&&(t.match_length=Ot(t,a),t.match_length<=5&&(t.strategy===pt||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){s=t.strstart+t.lookahead-3,i=rt(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=s&&(t.ins_h=Rt(t,t.ins_h,t.window[t.strstart+3-1]),a=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(It(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=rt(t,0,t.window[t.strstart-1]),i&&It(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=rt(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2};function Lt(t,e,a,i,s){this.good_length=t,this.max_lazy=e,this.nice_length=a,this.max_chain=i,this.func=s}const Mt=[new Lt(0,0,0,0,((t,e)=>{let a=65535;for(a>t.pending_buf_size-5&&(a=t.pending_buf_size-5);;){if(t.lookahead<=1){if(Tt(t),0===t.lookahead&&e===ot)return 1;if(0===t.lookahead)break}t.strstart+=t.lookahead,t.lookahead=0;const i=t.block_start+a;if((0===t.strstart||t.strstart>=i)&&(t.lookahead=t.strstart-i,t.strstart=i,It(t,!1),0===t.strm.avail_out))return 1;if(t.strstart-t.block_start>=t.w_size-262&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):(t.strstart>t.block_start&&(It(t,!1),t.strm.avail_out),1)})),new Lt(4,4,8,4,Zt),new Lt(4,5,16,8,Zt),new Lt(4,6,32,32,Zt),new Lt(4,4,16,16,Ct),new Lt(8,16,32,32,Ct),new Lt(8,16,128,128,Ct),new Lt(8,32,128,256,Ct),new Lt(32,128,258,1024,Ct),new Lt(32,258,258,4096,Ct)];function Nt(){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=zt,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),Et(this.dyn_ltree),Et(this.dyn_dtree),Et(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),Et(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Et(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Pt=t=>{if(!t||!t.state)return St(t,ut);t.total_in=t.total_out=0,t.data_type=xt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=e.wrap?42:113,t.adler=2===e.wrap?0:1,e.last_flush=ot,at(e),ct},Ht=t=>{const e=Pt(t);var a;return e===ct&&((a=t.state).window_size=2*a.w_size,Et(a.head),a.max_lazy_match=Mt[a.level].max_lazy,a.good_match=Mt[a.level].good_length,a.nice_match=Mt[a.level].nice_length,a.max_chain_length=Mt[a.level].max_chain,a.strstart=0,a.block_start=0,a.lookahead=0,a.insert=0,a.match_length=a.prev_length=2,a.match_available=0,a.ins_h=0),e},$t=(t,e,a,i,s,r)=>{if(!t)return ut;let n=1;if(e===mt&&(e=6),i<0?(n=0,i=-i):i>15&&(n=2,i-=16),s<1||s>9||a!==zt||i<8||i>15||e<0||e>9||r<0||r>kt)return St(t,ut);8===i&&(i=9);const o=new Nt;return t.state=o,o.strm=t,o.wrap=n,o.gzhead=null,o.w_bits=i,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=s+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+3-1)/3),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<s+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.d_buf=1*o.lit_bufsize,o.l_buf=3*o.lit_bufsize,o.level=e,o.strategy=r,o.method=a,Ht(t)};var jt={deflateInit:(t,e)=>$t(t,e,zt,15,8,vt),deflateInit2:$t,deflateReset:Ht,deflateResetKeep:Pt,deflateSetHeader:(t,e)=>t&&t.state?2!==t.state.wrap?ut:(t.state.gzhead=e,ct):ut,deflate:(t,e)=>{let a,i;if(!t||!t.state||e>ft||e<0)return t?St(t,ut):ut;const s=t.state;if(!t.output||!t.input&&0!==t.avail_in||666===s.status&&e!==dt)return St(t,0===t.avail_out?wt:ut);s.strm=t;const r=s.last_flush;if(s.last_flush=e,42===s.status)if(2===s.wrap)t.adler=0,Dt(s,31),Dt(s,139),Dt(s,8),s.gzhead?(Dt(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),Dt(s,255&s.gzhead.time),Dt(s,s.gzhead.time>>8&255),Dt(s,s.gzhead.time>>16&255),Dt(s,s.gzhead.time>>24&255),Dt(s,9===s.level?2:s.strategy>=bt||s.level<2?4:0),Dt(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(Dt(s,255&s.gzhead.extra.length),Dt(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(t.adler=J(t.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=69):(Dt(s,0),Dt(s,0),Dt(s,0),Dt(s,0),Dt(s,0),Dt(s,9===s.level?2:s.strategy>=bt||s.level<2?4:0),Dt(s,3),s.status=113);else{let e=zt+(s.w_bits-8<<4)<<8,a=-1;a=s.strategy>=bt||s.level<2?0:s.level<6?1:6===s.level?2:3,e|=a<<6,0!==s.strstart&&(e|=32),e+=31-e%31,s.status=113,Ft(s,e),0!==s.strstart&&(Ft(s,t.adler>>>16),Ft(s,65535&t.adler)),t.adler=1}if(69===s.status)if(s.gzhead.extra){for(a=s.pending;s.gzindex<(65535&s.gzhead.extra.length)&&(s.pending!==s.pending_buf_size||(s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),At(t),a=s.pending,s.pending!==s.pending_buf_size));)Dt(s,255&s.gzhead.extra[s.gzindex]),s.gzindex++;s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),s.gzindex===s.gzhead.extra.length&&(s.gzindex=0,s.status=73)}else s.status=73;if(73===s.status)if(s.gzhead.name){a=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),At(t),a=s.pending,s.pending===s.pending_buf_size)){i=1;break}i=s.gzindex<s.gzhead.name.length?255&s.gzhead.name.charCodeAt(s.gzindex++):0,Dt(s,i)}while(0!==i);s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),0===i&&(s.gzindex=0,s.status=91)}else s.status=91;if(91===s.status)if(s.gzhead.comment){a=s.pending;do{if(s.pending===s.pending_buf_size&&(s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),At(t),a=s.pending,s.pending===s.pending_buf_size)){i=1;break}i=s.gzindex<s.gzhead.comment.length?255&s.gzhead.comment.charCodeAt(s.gzindex++):0,Dt(s,i)}while(0!==i);s.gzhead.hcrc&&s.pending>a&&(t.adler=J(t.adler,s.pending_buf,s.pending-a,a)),0===i&&(s.status=103)}else s.status=103;if(103===s.status&&(s.gzhead.hcrc?(s.pending+2>s.pending_buf_size&&At(t),s.pending+2<=s.pending_buf_size&&(Dt(s,255&t.adler),Dt(s,t.adler>>8&255),t.adler=0,s.status=113)):s.status=113),0!==s.pending){if(At(t),0===t.avail_out)return s.last_flush=-1,ct}else if(0===t.avail_in&&Ut(e)<=Ut(r)&&e!==dt)return St(t,wt);if(666===s.status&&0!==t.avail_in)return St(t,wt);if(0!==t.avail_in||0!==s.lookahead||e!==ot&&666!==s.status){let a=s.strategy===bt?((t,e)=>{let a;for(;;){if(0===t.lookahead&&(Tt(t),0===t.lookahead)){if(e===ot)return 1;break}if(t.match_length=0,a=rt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,a&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2})(s,e):s.strategy===yt?((t,e)=>{let a,i,s,r;const n=t.window;for(;;){if(t.lookahead<=258){if(Tt(t),t.lookahead<=258&&e===ot)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(s=t.strstart-1,i=n[s],i===n[++s]&&i===n[++s]&&i===n[++s])){r=t.strstart+258;do{}while(i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&i===n[++s]&&s<r);t.match_length=258-(r-s),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(a=rt(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(a=rt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),a&&(It(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===dt?(It(t,!0),0===t.strm.avail_out?3:4):t.last_lit&&(It(t,!1),0===t.strm.avail_out)?1:2})(s,e):Mt[s.level].func(s,e);if(3!==a&&4!==a||(s.status=666),1===a||3===a)return 0===t.avail_out&&(s.last_flush=-1),ct;if(2===a&&(e===lt?nt(s):e!==ft&&(it(s,0,0,!1),e===ht&&(Et(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),At(t),0===t.avail_out))return s.last_flush=-1,ct}return e!==dt?ct:s.wrap<=0?_t:(2===s.wrap?(Dt(s,255&t.adler),Dt(s,t.adler>>8&255),Dt(s,t.adler>>16&255),Dt(s,t.adler>>24&255),Dt(s,255&t.total_in),Dt(s,t.total_in>>8&255),Dt(s,t.total_in>>16&255),Dt(s,t.total_in>>24&255)):(Ft(s,t.adler>>>16),Ft(s,65535&t.adler)),At(t),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?ct:_t)},deflateEnd:t=>{if(!t||!t.state)return ut;const e=t.state.status;return 42!==e&&69!==e&&73!==e&&91!==e&&103!==e&&113!==e&&666!==e?St(t,ut):(t.state=null,113===e?St(t,gt):ct)},deflateSetDictionary:(t,e)=>{let a=e.length;if(!t||!t.state)return ut;const i=t.state,s=i.wrap;if(2===s||1===s&&42!==i.status||i.lookahead)return ut;if(1===s&&(t.adler=X(t.adler,e,a,0)),i.wrap=0,a>=i.w_size){0===s&&(Et(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(a-i.w_size,a),0),e=t,a=i.w_size}const r=t.avail_in,n=t.next_in,o=t.input;for(t.avail_in=a,t.next_in=0,t.input=e,Tt(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=Rt(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,Tt(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=n,t.input=o,t.avail_in=r,i.wrap=s,ct},deflateInfo:"pako deflate (from Nodeca project)"};const Vt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var Wt=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const a=e.shift();if(a){if("object"!=typeof a)throw new TypeError(a+"must be non-object");for(const e in a)Vt(a,e)&&(t[e]=a[e])}}return t},Kt=t=>{let e=0;for(let a=0,i=t.length;a<i;a++)e+=t[a].length;const a=new Uint8Array(e);for(let e=0,i=0,s=t.length;e<s;e++){let s=t[e];a.set(s,i),i+=s.length}return a};let Yt=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){Yt=!1}const qt=new Uint8Array(256);for(let t=0;t<256;t++)qt[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;qt[254]=qt[254]=1;var Gt=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,a,i,s,r,n=t.length,o=0;for(s=0;s<n;s++)a=t.charCodeAt(s),55296==(64512&a)&&s+1<n&&(i=t.charCodeAt(s+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),s++)),o+=a<128?1:a<2048?2:a<65536?3:4;for(e=new Uint8Array(o),r=0,s=0;r<o;s++)a=t.charCodeAt(s),55296==(64512&a)&&s+1<n&&(i=t.charCodeAt(s+1),56320==(64512&i)&&(a=65536+(a-55296<<10)+(i-56320),s++)),a<128?e[r++]=a:a<2048?(e[r++]=192|a>>>6,e[r++]=128|63&a):a<65536?(e[r++]=224|a>>>12,e[r++]=128|a>>>6&63,e[r++]=128|63&a):(e[r++]=240|a>>>18,e[r++]=128|a>>>12&63,e[r++]=128|a>>>6&63,e[r++]=128|63&a);return e},Xt=(t,e)=>{const a=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,s;const r=new Array(2*a);for(s=0,i=0;i<a;){let e=t[i++];if(e<128){r[s++]=e;continue}let n=qt[e];if(n>4)r[s++]=65533,i+=n-1;else{for(e&=2===n?31:3===n?15:7;n>1&&i<a;)e=e<<6|63&t[i++],n--;n>1?r[s++]=65533:e<65536?r[s++]=e:(e-=65536,r[s++]=55296|e>>10&1023,r[s++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&Yt)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let a="";for(let i=0;i<e;i++)a+=String.fromCharCode(t[i]);return a})(r,s)},Qt=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let a=e-1;for(;a>=0&&128==(192&t[a]);)a--;return a<0||0===a?e:a+qt[t[a]]>e?a:e};var Jt=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 te=Object.prototype.toString,{Z_NO_FLUSH:ee,Z_SYNC_FLUSH:ae,Z_FULL_FLUSH:ie,Z_FINISH:se,Z_OK:re,Z_STREAM_END:ne,Z_DEFAULT_COMPRESSION:oe,Z_DEFAULT_STRATEGY:le,Z_DEFLATED:he}=et;function de(t){this.options=Wt({level:oe,method:he,chunkSize:16384,windowBits:15,memLevel:8,strategy:le},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Jt,this.strm.avail_out=0;let a=jt.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(a!==re)throw new Error(tt[a]);if(e.header&&jt.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?Gt(e.dictionary):"[object ArrayBuffer]"===te.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,a=jt.deflateSetDictionary(this.strm,t),a!==re)throw new Error(tt[a]);this._dict_set=!0}}function fe(t,e){const a=new de(e);if(a.push(t,!0),a.err)throw a.msg||tt[a.err];return a.result}de.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize;let s,r;if(this.ended)return!1;for(r=e===~~e?e:!0===e?se:ee,"string"==typeof t?a.input=Gt(t):"[object ArrayBuffer]"===te.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;)if(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),(r===ae||r===ie)&&a.avail_out<=6)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else{if(s=jt.deflate(a,r),s===ne)return a.next_out>0&&this.onData(a.output.subarray(0,a.next_out)),s=jt.deflateEnd(this.strm),this.onEnd(s),this.ended=!0,s===re;if(0!==a.avail_out){if(r>0&&a.next_out>0)this.onData(a.output.subarray(0,a.next_out)),a.avail_out=0;else if(0===a.avail_in)break}else this.onData(a.output)}return!0},de.prototype.onData=function(t){this.chunks.push(t)},de.prototype.onEnd=function(t){t===re&&(this.result=Kt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var ce={Deflate:de,deflate:fe,deflateRaw:function(t,e){return(e=e||{}).raw=!0,fe(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,fe(t,e)},constants:et};var _e=function(t,e){let a,i,s,r,n,o,l,h,d,f,c,_,u,g,w,m,p,b,y,k,v,x,z,S;const U=t.state;a=t.next_in,z=t.input,i=a+(t.avail_in-5),s=t.next_out,S=t.output,r=s-(e-t.avail_out),n=s+(t.avail_out-257),o=U.dmax,l=U.wsize,h=U.whave,d=U.wnext,f=U.window,c=U.hold,_=U.bits,u=U.lencode,g=U.distcode,w=(1<<U.lenbits)-1,m=(1<<U.distbits)-1;t:do{_<15&&(c+=z[a++]<<_,_+=8,c+=z[a++]<<_,_+=8),p=u[c&w];e:for(;;){if(b=p>>>24,c>>>=b,_-=b,b=p>>>16&255,0===b)S[s++]=65535&p;else{if(!(16&b)){if(0==(64&b)){p=u[(65535&p)+(c&(1<<b)-1)];continue e}if(32&b){U.mode=12;break t}t.msg="invalid literal/length code",U.mode=30;break t}y=65535&p,b&=15,b&&(_<b&&(c+=z[a++]<<_,_+=8),y+=c&(1<<b)-1,c>>>=b,_-=b),_<15&&(c+=z[a++]<<_,_+=8,c+=z[a++]<<_,_+=8),p=g[c&m];a:for(;;){if(b=p>>>24,c>>>=b,_-=b,b=p>>>16&255,!(16&b)){if(0==(64&b)){p=g[(65535&p)+(c&(1<<b)-1)];continue a}t.msg="invalid distance code",U.mode=30;break t}if(k=65535&p,b&=15,_<b&&(c+=z[a++]<<_,_+=8,_<b&&(c+=z[a++]<<_,_+=8)),k+=c&(1<<b)-1,k>o){t.msg="invalid distance too far back",U.mode=30;break t}if(c>>>=b,_-=b,b=s-r,k>b){if(b=k-b,b>h&&U.sane){t.msg="invalid distance too far back",U.mode=30;break t}if(v=0,x=f,0===d){if(v+=l-b,b<y){y-=b;do{S[s++]=f[v++]}while(--b);v=s-k,x=S}}else if(d<b){if(v+=l+d-b,b-=d,b<y){y-=b;do{S[s++]=f[v++]}while(--b);if(v=0,d<y){b=d,y-=b;do{S[s++]=f[v++]}while(--b);v=s-k,x=S}}}else if(v+=d-b,b<y){y-=b;do{S[s++]=f[v++]}while(--b);v=s-k,x=S}for(;y>2;)S[s++]=x[v++],S[s++]=x[v++],S[s++]=x[v++],y-=3;y&&(S[s++]=x[v++],y>1&&(S[s++]=x[v++]))}else{v=s-k;do{S[s++]=S[v++],S[s++]=S[v++],S[s++]=S[v++],y-=3}while(y>2);y&&(S[s++]=S[v++],y>1&&(S[s++]=S[v++]))}break}}break}}while(a<i&&s<n);y=_>>3,a-=y,_-=y<<3,c&=(1<<_)-1,t.next_in=a,t.next_out=s,t.avail_in=a<i?i-a+5:5-(a-i),t.avail_out=s<n?n-s+257:257-(s-n),U.hold=c,U.bits=_};const ue=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),ge=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),we=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),me=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var pe=(t,e,a,i,s,r,n,o)=>{const l=o.bits;let h,d,f,c,_,u,g=0,w=0,m=0,p=0,b=0,y=0,k=0,v=0,x=0,z=0,S=null,U=0;const E=new Uint16Array(16),R=new Uint16Array(16);let A,I,D,F=null,B=0;for(g=0;g<=15;g++)E[g]=0;for(w=0;w<i;w++)E[e[a+w]]++;for(b=l,p=15;p>=1&&0===E[p];p--);if(b>p&&(b=p),0===p)return s[r++]=20971520,s[r++]=20971520,o.bits=1,0;for(m=1;m<p&&0===E[m];m++);for(b<m&&(b=m),v=1,g=1;g<=15;g++)if(v<<=1,v-=E[g],v<0)return-1;if(v>0&&(0===t||1!==p))return-1;for(R[1]=0,g=1;g<15;g++)R[g+1]=R[g]+E[g];for(w=0;w<i;w++)0!==e[a+w]&&(n[R[e[a+w]]++]=w);if(0===t?(S=F=n,u=19):1===t?(S=ue,U-=257,F=ge,B-=257,u=256):(S=we,F=me,u=-1),z=0,w=0,g=m,_=r,y=b,k=0,f=-1,x=1<<b,c=x-1,1===t&&x>852||2===t&&x>592)return 1;for(;;){A=g-k,n[w]<u?(I=0,D=n[w]):n[w]>u?(I=F[B+n[w]],D=S[U+n[w]]):(I=96,D=0),h=1<<g-k,d=1<<y,m=d;do{d-=h,s[_+(z>>k)+d]=A<<24|I<<16|D|0}while(0!==d);for(h=1<<g-1;z&h;)h>>=1;if(0!==h?(z&=h-1,z+=h):z=0,w++,0==--E[g]){if(g===p)break;g=e[a+n[w]]}if(g>b&&(z&c)!==f){for(0===k&&(k=b),_+=m,y=g-k,v=1<<y;y+k<p&&(v-=E[y+k],!(v<=0));)y++,v<<=1;if(x+=1<<y,1===t&&x>852||2===t&&x>592)return 1;f=z&c,s[f]=b<<24|y<<16|_-r|0}}return 0!==z&&(s[_+z]=g-k<<24|64<<16|0),o.bits=b,0};const{Z_FINISH:be,Z_BLOCK:ye,Z_TREES:ke,Z_OK:ve,Z_STREAM_END:xe,Z_NEED_DICT:ze,Z_STREAM_ERROR:Se,Z_DATA_ERROR:Ue,Z_MEM_ERROR:Ee,Z_BUF_ERROR:Re,Z_DEFLATED:Ae}=et,Ie=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function De(){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 Fe=t=>{if(!t||!t.state)return Se;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=1,e.last=0,e.havedict=0,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,ve},Be=t=>{if(!t||!t.state)return Se;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,Fe(t)},Oe=(t,e)=>{let a;if(!t||!t.state)return Se;const i=t.state;return e<0?(a=0,e=-e):(a=1+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?Se:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=a,i.wbits=e,Be(t))},Te=(t,e)=>{if(!t)return Se;const a=new De;t.state=a,a.window=null;const i=Oe(t,e);return i!==ve&&(t.state=null),i};let Ze,Ce,Le=!0;const Me=t=>{if(Le){Ze=new Int32Array(512),Ce=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(pe(1,t.lens,0,288,Ze,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;pe(2,t.lens,0,32,Ce,0,t.work,{bits:5}),Le=!1}t.lencode=Ze,t.lenbits=9,t.distcode=Ce,t.distbits=5},Ne=(t,e,a,i)=>{let s;const r=t.state;return null===r.window&&(r.wsize=1<<r.wbits,r.wnext=0,r.whave=0,r.window=new Uint8Array(r.wsize)),i>=r.wsize?(r.window.set(e.subarray(a-r.wsize,a),0),r.wnext=0,r.whave=r.wsize):(s=r.wsize-r.wnext,s>i&&(s=i),r.window.set(e.subarray(a-i,a-i+s),r.wnext),(i-=s)?(r.window.set(e.subarray(a-i,a),0),r.wnext=i,r.whave=r.wsize):(r.wnext+=s,r.wnext===r.wsize&&(r.wnext=0),r.whave<r.wsize&&(r.whave+=s))),0};var Pe={inflateReset:Be,inflateReset2:Oe,inflateResetKeep:Fe,inflateInit:t=>Te(t,15),inflateInit2:Te,inflate:(t,e)=>{let a,i,s,r,n,o,l,h,d,f,c,_,u,g,w,m,p,b,y,k,v,x,z=0;const S=new Uint8Array(4);let U,E;const R=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(!t||!t.state||!t.output||!t.input&&0!==t.avail_in)return Se;a=t.state,12===a.mode&&(a.mode=13),n=t.next_out,s=t.output,l=t.avail_out,r=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,f=o,c=l,x=ve;t:for(;;)switch(a.mode){case 1:if(0===a.wrap){a.mode=13;break}for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(2&a.wrap&&35615===h){a.check=0,S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0),h=0,d=0,a.mode=2;break}if(a.flags=0,a.head&&(a.head.done=!1),!(1&a.wrap)||(((255&h)<<8)+(h>>8))%31){t.msg="incorrect header check",a.mode=30;break}if((15&h)!==Ae){t.msg="unknown compression method",a.mode=30;break}if(h>>>=4,d-=4,v=8+(15&h),0===a.wbits)a.wbits=v;else if(v>a.wbits){t.msg="invalid window size",a.mode=30;break}a.dmax=1<<a.wbits,t.adler=a.check=1,a.mode=512&h?10:12,h=0,d=0;break;case 2:for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(a.flags=h,(255&a.flags)!==Ae){t.msg="unknown compression method",a.mode=30;break}if(57344&a.flags){t.msg="unknown header flags set",a.mode=30;break}a.head&&(a.head.text=h>>8&1),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0)),h=0,d=0,a.mode=3;case 3:for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.head&&(a.head.time=h),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,S[2]=h>>>16&255,S[3]=h>>>24&255,a.check=J(a.check,S,4,0)),h=0,d=0,a.mode=4;case 4:for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.head&&(a.head.xflags=255&h,a.head.os=h>>8),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0)),h=0,d=0,a.mode=5;case 5:if(1024&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.length=h,a.head&&(a.head.extra_len=h),512&a.flags&&(S[0]=255&h,S[1]=h>>>8&255,a.check=J(a.check,S,2,0)),h=0,d=0}else a.head&&(a.head.extra=null);a.mode=6;case 6:if(1024&a.flags&&(_=a.length,_>o&&(_=o),_&&(a.head&&(v=a.head.extra_len-a.length,a.head.extra||(a.head.extra=new Uint8Array(a.head.extra_len)),a.head.extra.set(i.subarray(r,r+_),v)),512&a.flags&&(a.check=J(a.check,i,_,r)),o-=_,r+=_,a.length-=_),a.length))break t;a.length=0,a.mode=7;case 7:if(2048&a.flags){if(0===o)break t;_=0;do{v=i[r+_++],a.head&&v&&a.length<65536&&(a.head.name+=String.fromCharCode(v))}while(v&&_<o);if(512&a.flags&&(a.check=J(a.check,i,_,r)),o-=_,r+=_,v)break t}else a.head&&(a.head.name=null);a.length=0,a.mode=8;case 8:if(4096&a.flags){if(0===o)break t;_=0;do{v=i[r+_++],a.head&&v&&a.length<65536&&(a.head.comment+=String.fromCharCode(v))}while(v&&_<o);if(512&a.flags&&(a.check=J(a.check,i,_,r)),o-=_,r+=_,v)break t}else a.head&&(a.head.comment=null);a.mode=9;case 9:if(512&a.flags){for(;d<16;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h!==(65535&a.check)){t.msg="header crc mismatch",a.mode=30;break}h=0,d=0}a.head&&(a.head.hcrc=a.flags>>9&1,a.head.done=!0),t.adler=a.check=0,a.mode=12;break;case 10:for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}t.adler=a.check=Ie(h),h=0,d=0,a.mode=11;case 11:if(0===a.havedict)return t.next_out=n,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,ze;t.adler=a.check=1,a.mode=12;case 12:if(e===ye||e===ke)break t;case 13:if(a.last){h>>>=7&d,d-=7&d,a.mode=27;break}for(;d<3;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}switch(a.last=1&h,h>>>=1,d-=1,3&h){case 0:a.mode=14;break;case 1:if(Me(a),a.mode=20,e===ke){h>>>=2,d-=2;break t}break;case 2:a.mode=17;break;case 3:t.msg="invalid block type",a.mode=30}h>>>=2,d-=2;break;case 14:for(h>>>=7&d,d-=7&d;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if((65535&h)!=(h>>>16^65535)){t.msg="invalid stored block lengths",a.mode=30;break}if(a.length=65535&h,h=0,d=0,a.mode=15,e===ke)break t;case 15:a.mode=16;case 16:if(_=a.length,_){if(_>o&&(_=o),_>l&&(_=l),0===_)break t;s.set(i.subarray(r,r+_),n),o-=_,r+=_,l-=_,n+=_,a.length-=_;break}a.mode=12;break;case 17:for(;d<14;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(a.nlen=257+(31&h),h>>>=5,d-=5,a.ndist=1+(31&h),h>>>=5,d-=5,a.ncode=4+(15&h),h>>>=4,d-=4,a.nlen>286||a.ndist>30){t.msg="too many length or distance symbols",a.mode=30;break}a.have=0,a.mode=18;case 18:for(;a.have<a.ncode;){for(;d<3;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.lens[R[a.have++]]=7&h,h>>>=3,d-=3}for(;a.have<19;)a.lens[R[a.have++]]=0;if(a.lencode=a.lendyn,a.lenbits=7,U={bits:a.lenbits},x=pe(0,a.lens,0,19,a.lencode,0,a.work,U),a.lenbits=U.bits,x){t.msg="invalid code lengths set",a.mode=30;break}a.have=0,a.mode=19;case 19:for(;a.have<a.nlen+a.ndist;){for(;z=a.lencode[h&(1<<a.lenbits)-1],w=z>>>24,m=z>>>16&255,p=65535&z,!(w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(p<16)h>>>=w,d-=w,a.lens[a.have++]=p;else{if(16===p){for(E=w+2;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h>>>=w,d-=w,0===a.have){t.msg="invalid bit length repeat",a.mode=30;break}v=a.lens[a.have-1],_=3+(3&h),h>>>=2,d-=2}else if(17===p){for(E=w+3;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=w,d-=w,v=0,_=3+(7&h),h>>>=3,d-=3}else{for(E=w+7;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=w,d-=w,v=0,_=11+(127&h),h>>>=7,d-=7}if(a.have+_>a.nlen+a.ndist){t.msg="invalid bit length repeat",a.mode=30;break}for(;_--;)a.lens[a.have++]=v}}if(30===a.mode)break;if(0===a.lens[256]){t.msg="invalid code -- missing end-of-block",a.mode=30;break}if(a.lenbits=9,U={bits:a.lenbits},x=pe(1,a.lens,0,a.nlen,a.lencode,0,a.work,U),a.lenbits=U.bits,x){t.msg="invalid literal/lengths set",a.mode=30;break}if(a.distbits=6,a.distcode=a.distdyn,U={bits:a.distbits},x=pe(2,a.lens,a.nlen,a.ndist,a.distcode,0,a.work,U),a.distbits=U.bits,x){t.msg="invalid distances set",a.mode=30;break}if(a.mode=20,e===ke)break t;case 20:a.mode=21;case 21:if(o>=6&&l>=258){t.next_out=n,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,_e(t,c),n=t.next_out,s=t.output,l=t.avail_out,r=t.next_in,i=t.input,o=t.avail_in,h=a.hold,d=a.bits,12===a.mode&&(a.back=-1);break}for(a.back=0;z=a.lencode[h&(1<<a.lenbits)-1],w=z>>>24,m=z>>>16&255,p=65535&z,!(w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(m&&0==(240&m)){for(b=w,y=m,k=p;z=a.lencode[k+((h&(1<<b+y)-1)>>b)],w=z>>>24,m=z>>>16&255,p=65535&z,!(b+w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=b,d-=b,a.back+=b}if(h>>>=w,d-=w,a.back+=w,a.length=p,0===m){a.mode=26;break}if(32&m){a.back=-1,a.mode=12;break}if(64&m){t.msg="invalid literal/length code",a.mode=30;break}a.extra=15&m,a.mode=22;case 22:if(a.extra){for(E=a.extra;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.length+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}a.was=a.length,a.mode=23;case 23:for(;z=a.distcode[h&(1<<a.distbits)-1],w=z>>>24,m=z>>>16&255,p=65535&z,!(w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(0==(240&m)){for(b=w,y=m,k=p;z=a.distcode[k+((h&(1<<b+y)-1)>>b)],w=z>>>24,m=z>>>16&255,p=65535&z,!(b+w<=d);){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}h>>>=b,d-=b,a.back+=b}if(h>>>=w,d-=w,a.back+=w,64&m){t.msg="invalid distance code",a.mode=30;break}a.offset=p,a.extra=15&m,a.mode=24;case 24:if(a.extra){for(E=a.extra;d<E;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}a.offset+=h&(1<<a.extra)-1,h>>>=a.extra,d-=a.extra,a.back+=a.extra}if(a.offset>a.dmax){t.msg="invalid distance too far back",a.mode=30;break}a.mode=25;case 25:if(0===l)break t;if(_=c-l,a.offset>_){if(_=a.offset-_,_>a.whave&&a.sane){t.msg="invalid distance too far back",a.mode=30;break}_>a.wnext?(_-=a.wnext,u=a.wsize-_):u=a.wnext-_,_>a.length&&(_=a.length),g=a.window}else g=s,u=n-a.offset,_=a.length;_>l&&(_=l),l-=_,a.length-=_;do{s[n++]=g[u++]}while(--_);0===a.length&&(a.mode=21);break;case 26:if(0===l)break t;s[n++]=a.length,l--,a.mode=21;break;case 27:if(a.wrap){for(;d<32;){if(0===o)break t;o--,h|=i[r++]<<d,d+=8}if(c-=l,t.total_out+=c,a.total+=c,c&&(t.adler=a.check=a.flags?J(a.check,s,c,n-c):X(a.check,s,c,n-c)),c=l,(a.flags?h:Ie(h))!==a.check){t.msg="incorrect data check",a.mode=30;break}h=0,d=0}a.mode=28;case 28:if(a.wrap&&a.flags){for(;d<32;){if(0===o)break t;o--,h+=i[r++]<<d,d+=8}if(h!==(4294967295&a.total)){t.msg="incorrect length check",a.mode=30;break}h=0,d=0}a.mode=29;case 29:x=xe;break t;case 30:x=Ue;break t;case 31:return Ee;case 32:default:return Se}return t.next_out=n,t.avail_out=l,t.next_in=r,t.avail_in=o,a.hold=h,a.bits=d,(a.wsize||c!==t.avail_out&&a.mode<30&&(a.mode<27||e!==be))&&Ne(t,t.output,t.next_out,c-t.avail_out),f-=t.avail_in,c-=t.avail_out,t.total_in+=f,t.total_out+=c,a.total+=c,a.wrap&&c&&(t.adler=a.check=a.flags?J(a.check,s,c,t.next_out-c):X(a.check,s,c,t.next_out-c)),t.data_type=a.bits+(a.last?64:0)+(12===a.mode?128:0)+(20===a.mode||15===a.mode?256:0),(0===f&&0===c||e===be)&&x===ve&&(x=Re),x},inflateEnd:t=>{if(!t||!t.state)return Se;let e=t.state;return e.window&&(e.window=null),t.state=null,ve},inflateGetHeader:(t,e)=>{if(!t||!t.state)return Se;const a=t.state;return 0==(2&a.wrap)?Se:(a.head=e,e.done=!1,ve)},inflateSetDictionary:(t,e)=>{const a=e.length;let i,s,r;return t&&t.state?(i=t.state,0!==i.wrap&&11!==i.mode?Se:11===i.mode&&(s=1,s=X(s,e,a,0),s!==i.check)?Ue:(r=Ne(t,e,a,a),r?(i.mode=31,Ee):(i.havedict=1,ve))):Se},inflateInfo:"pako inflate (from Nodeca project)"};var He=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 $e=Object.prototype.toString,{Z_NO_FLUSH:je,Z_FINISH:Ve,Z_OK:We,Z_STREAM_END:Ke,Z_NEED_DICT:Ye,Z_STREAM_ERROR:qe,Z_DATA_ERROR:Ge,Z_MEM_ERROR:Xe}=et;function Qe(t){this.options=Wt({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&0==(15&e.windowBits)&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Jt,this.strm.avail_out=0;let a=Pe.inflateInit2(this.strm,e.windowBits);if(a!==We)throw new Error(tt[a]);if(this.header=new He,Pe.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=Gt(e.dictionary):"[object ArrayBuffer]"===$e.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(a=Pe.inflateSetDictionary(this.strm,e.dictionary),a!==We)))throw new Error(tt[a])}Qe.prototype.push=function(t,e){const a=this.strm,i=this.options.chunkSize,s=this.options.dictionary;let r,n,o;if(this.ended)return!1;for(n=e===~~e?e:!0===e?Ve:je,"[object ArrayBuffer]"===$e.call(t)?a.input=new Uint8Array(t):a.input=t,a.next_in=0,a.avail_in=a.input.length;;){for(0===a.avail_out&&(a.output=new Uint8Array(i),a.next_out=0,a.avail_out=i),r=Pe.inflate(a,n),r===Ye&&s&&(r=Pe.inflateSetDictionary(a,s),r===We?r=Pe.inflate(a,n):r===Ge&&(r=Ye));a.avail_in>0&&r===Ke&&a.state.wrap>0&&0!==t[a.next_in];)Pe.inflateReset(a),r=Pe.inflate(a,n);switch(r){case qe:case Ge:case Ye:case Xe:return this.onEnd(r),this.ended=!0,!1}if(o=a.avail_out,a.next_out&&(0===a.avail_out||r===Ke))if("string"===this.options.to){let t=Qt(a.output,a.next_out),e=a.next_out-t,s=Xt(a.output,t);a.next_out=e,a.avail_out=i-e,e&&a.output.set(a.output.subarray(t,t+e),0),this.onData(s)}else this.onData(a.output.length===a.next_out?a.output:a.output.subarray(0,a.next_out));if(r!==We||0!==o){if(r===Ke)return r=Pe.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(0===a.avail_in)break}}return!0},Qe.prototype.onData=function(t){this.chunks.push(t)},Qe.prototype.onEnd=function(t){t===We&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=Kt(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};const{Deflate:Je,deflate:ta,deflateRaw:ea,gzip:aa}=ce;var ia=ta;const sa={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}},ra=(t,...e)=>{let a=0;if(t.replace(/[<>]/,"").length!=e.length)throw"Pack format to Argument count mismatch";let i=[],s=!0;for(let i=0;i<t.length;i++)"<"==t[i]?s=!0:">"==t[i]?s=!1:(r(t[i],e[a]),a++);function r(t,e){if(!(t in sa))throw"Unhandled character '"+t+"' in pack format";let a=sa[t].bytes,r=new DataView(new ArrayBuffer(a));sa[t].p.bind(r)(0,e,s);for(let t=0;t<a;t++)i.push(r.getUint8(t))}return i},na=(t,e)=>{let a=0,i=[],s=!0;for(let e of t)"<"==e?s=!0:">"==e?s=!1:r(e);function r(t){if(!(t in sa))throw"Unhandled character '"+t+"' in unpack format";let r=sa[t].bytes,n=new DataView(new ArrayBuffer(r));for(let t=0;t<r;t++)n.setUint8(t,255&e[a+t]);let o=sa[t].u.bind(n);i.push(o(0,s)),a+=r}return i};class oa extends EventTarget{constructor(t,e,a){super(),this.port=t,this.logger=e,this._parent=a,this.chipName=null,this._efuses=new Array(4).fill(0),this._flashsize=4194304,this.debug=!1,this.IS_STUB=!1,this.connected=!0,this.flashSize=null}get _inputBuffer(){return this._parent?this._parent._inputBuffer:this.__inputBuffer}async initialize(){await this.hardReset(!0),this._parent||(this.__inputBuffer=[],this.readLoop()),await this.sync();let t=await this.readRegister(1073745920),e=_[t>>>0];if(void 0===e)throw new Error(`Unknown Chip: Hex: ${a(t>>>0,8).toLowerCase()} Number: ${t}`);this.chipName=e.name,this.chipFamily=e.family;let i=g(this.getChipFamily()).macFuse;for(let t=0;t<4;t++)this._efuses[t]=await this.readRegister(i+4*t);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:t,done:e}=await this._reader.read();if(e){this._reader.releaseLock();break}t&&0!==t.length&&this._inputBuffer.push(...Array.from(t))}}catch(t){console.error("Read loop got disconnected")}this.connected=!1,this.dispatchEvent(new Event("disconnect")),this.logger.debug("Finished read loop")}async hardReset(t=!1){this.logger.log("Try hard reset."),await this.port.setSignals({dataTerminalReady:!1,requestToSend:!0}),await this.port.setSignals({dataTerminalReady:t,requestToSend:!1}),await new Promise((t=>setTimeout(t,1e3)))}macAddr(){let t,e=new Array(6).fill(0),a=this._efuses[0],i=this._efuses[1],s=this._efuses[2],r=this._efuses[3];if(33382==this.chipFamily){if(0!=r)t=[r>>16&255,r>>8&255,255&r];else if(0==(i>>16&255))t=[24,254,52];else{if(1!=(i>>16&255))throw new Error("Couldnt determine OUI");t=[172,208,116]}e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=i>>8&255,e[4]=255&i,e[5]=a>>24&255}else if(this.chipFamily==o)e[0]=s>>8&255,e[1]=255&s,e[2]=i>>24&255,e[3]=i>>16&255,e[4]=i>>8&255,e[5]=255&i;else{if(this.chipFamily!=l&&this.chipFamily!=h&&this.chipFamily!=d)throw new Error("Unknown chip family");e[0]=i>>8&255,e[1]=255&i,e[2]=a>>24&255,e[3]=a>>16&255,e[4]=a>>8&255,e[5]=255&a}return e}async readRegister(t){this.debug&&this.logger.debug("Reading from Register "+a(t,8));let e=ra("<I",t);await this.sendCommand(10,e);let[i,s]=await this.getResponse(10);return i}async checkCommand(t,e,i=0,s=3e3){s=Math.min(s,12e5),await this.sendCommand(t,e,i);let[r,n]=await this.getResponse(t,s);if(null===n)throw new Error("Didn't get enough status bytes");let f=0;if(this.IS_STUB||33382==this.chipFamily?f=2:[o,l,h,d].includes(this.chipFamily)?f=4:[2,4].includes(n.length)&&(f=n.length),n.length<f)throw new Error("Didn't get enough status bytes");let c=n.slice(-f,n.length);if(n=n.slice(0,-f),this.debug&&(this.logger.debug("status",c),this.logger.debug("value",r),this.logger.debug("data",n)),1==c[0])throw 5==c[1]?new Error("Invalid (unsupported) command "+a(t)):new Error("Command failure error code "+a(c[1]));return[r,n]}async sendCommand(t,e,a=0){let i=(t=>{let e=[192];for(let a of t)219==a?e=e.concat([219,221]):192==a?e=e.concat([219,220]):e.push(a);return e.push(192),e})([...ra("<BBHI",0,t,e.length,a),...e]);this.debug&&this.logger.debug(`Writing ${i.length} byte${1==i.length?"":"s"}:`,i),await this.writeToStream(i)}async readPacket(t){let s=null,r=!1,n=[];for(;;){let o=Date.now();for(n=[];Date.now()-o<t;){if(this._inputBuffer.length>0){n.push(this._inputBuffer.shift());break}await i(10)}if(0==n.length){throw new w("Timed out waiting for packet "+(null===s?"header":"content"))}this.debug&&this.logger.debug("Read "+n.length+" bytes: "+e(n));for(let t of n)if(null===s){if(192!=t)throw this.debug&&(this.logger.debug("Read invalid data: "+e(n)),this.logger.debug("Remaining data in serial buffer: "+e(this._inputBuffer))),new w("Invalid head of packet ("+a(t)+")");s=[]}else if(r)if(r=!1,220==t)s.push(192);else{if(221!=t)throw this.debug&&(this.logger.debug("Read invalid data: "+e(n)),this.logger.debug("Remaining data in serial buffer: "+e(this._inputBuffer))),new w("Invalid SLIP escape (0xdb, "+a(t)+")");s.push(219)}else if(219==t)r=!0;else{if(192==t)return this.debug&&this.logger.debug("Received full packet: "+e(s)),s;s.push(t)}}throw new w("Invalid state")}async getResponse(t,e=3e3){for(let i=0;i<100;i++){const i=await this.readPacket(e);if(i.length<8)continue;const[s,r,n,o]=na("<BBHI",i.slice(0,8));if(1!=s)continue;const l=i.slice(8);if(null==t||r==t)return[o,l];if(0!=l[0]&&5==l[1])throw this._inputBuffer.length=0,new Error(`Invalid (unsupported) command ${a(t)}`)}throw"Response doesn't match request"}checksum(t,e=239){for(let a of t)e^=a;return e}async setBaudrate(t){if(33382==this.chipFamily)throw new Error("Changing baud rate is not supported on the ESP8266");this.logger.log("Attempting to change baud rate to "+t+"...");try{let e=ra("<II",t,this.IS_STUB?115200:0);await this.checkCommand(15,e)}catch(e){throw console.error(e),new Error(`Unable to change the baud rate to ${t}: No response from set baud rate command.`)}this._parent?await this._parent.reconfigurePort(t):await this.reconfigurePort(t)}async reconfigurePort(t){var e;try{await(null===(e=this._reader)||void 0===e?void 0:e.cancel()),await this.port.close(),await this.port.open({baudRate:t}),this.readLoop(),this.logger.log(`Changed baud rate to ${t}`)}catch(e){throw console.error(e),new Error(`Unable to change the baud rate to ${t}: ${e}`)}}async sync(){for(let t=0;t<5;t++){if(this._inputBuffer.length=0,await this._sync())return await i(100),!0;await i(100)}throw new Error("Couldn't sync to ESP. Try resetting.")}async _sync(){await this.sendCommand(8,r);for(let t=0;t<8;t++)try{let[t,e]=await this.getResponse(8,100);if(e.length>1&&0==e[0]&&0==e[1])return!0}catch(t){}return!1}getFlashWriteSize(){return this.IS_STUB?16384:1024}async flashData(t,e,i=0,s=!1){if(t.byteLength>=8){var r=Array.from(new Uint8Array(t,0,4));let e=r[0],i=r[2],s=r[3];this.logger.log(`Image header, Magic=${a(e)}, FlashMode=${a(i)}, FlashSizeFreq=${a(s)}`)}let n,o=t.byteLength,l=0;s?(n=ia(new Uint8Array(t),{level:9}).buffer,l=n.byteLength,this.logger.log(`Writing data with filesize: ${o}. Compressed Size: ${l}`),await this.flashDeflBegin(o,l,i)):(this.logger.log(`Writing data with filesize: ${o}`),n=t,await this.flashBegin(o,i));let h=[],d=0,f=0,c=0,_=Date.now(),u=this.getFlashWriteSize(),g=s?l:o;for(;g-c>0;)this.debug&&this.logger.log(`Writing at ${a(i+d*u,8)} `),g-c>=u?h=Array.from(new Uint8Array(n,c,u)):(h=Array.from(new Uint8Array(n,c,g-c)),s||(h=h.concat(new Array(u-h.length).fill(255)))),s?await this.flashDeflBlock(h,d):await this.flashBlock(h,d),d+=1,f+=s?Math.round(h.length*o/l):h.length,c+=u,e(Math.min(f,o),o);this.logger.log("Took "+(Date.now()-_)+"ms to write "+g+" bytes"),this.IS_STUB&&(await this.flashBegin(0,0),s?await this.flashDeflFinish():await this.flashFinish())}async flashBlock(t,e,a=3e3){await this.checkCommand(3,ra("<IIII",t.length,e,0,0).concat(t),this.checksum(t),a)}async flashDeflBlock(t,e,a=3e3){await this.checkCommand(17,ra("<IIII",t.length,e,0,0).concat(t),this.checksum(t))}async flashBegin(t=0,e=0,i=!1){let s,r,n=this.getFlashWriteSize();!this.IS_STUB&&[o,l,h,d].includes(this.chipFamily)&&await this.checkCommand(13,new Array(8).fill(0));let f,c=Math.floor((t+n-1)/n);s=33382==this.chipFamily?this.getEraseSize(e,t):t,f=this.IS_STUB?3e3:u(3e4,t);let _=Date.now();return r=ra("<IIII",s,c,n,e),this.chipFamily!=o&&this.chipFamily!=l&&this.chipFamily!=h&&this.chipFamily!=d||(r=r.concat(ra("<I",i?1:0))),this.logger.log("Erase size "+s+", blocks "+c+", block size "+a(n,4)+", offset "+a(e,4)+", encrypted "+(i?"yes":"no")),await this.checkCommand(2,r,0,f),0==t||this.IS_STUB||this.logger.log("Took "+(Date.now()-_)+"ms to erase "+c+" bytes"),c}async flashDeflBegin(t=0,e=0,a=0,i=!1){let s,r=this.getFlashWriteSize(),n=Math.floor((e+r-1)/r),o=Math.floor((t+r-1)/r),l=0,h=0;return this.IS_STUB?(l=t,h=3e3):(l=o*r,h=u(3e4,l)),s=ra("<IIII",l,n,r,a),await this.checkCommand(16,s,0,h),n}async flashFinish(){let t=ra("<I",1);await this.checkCommand(4,t)}async flashDeflFinish(){let t=ra("<I",1);await this.checkCommand(18,t)}getBootloaderOffset(){return g(this.getChipFamily()).flashOffs}async flashId(){return await this.runSpiFlashCommand(159,[],24)}getChipFamily(){return this._parent?this._parent.chipFamily:this.chipFamily}async writeRegister(t,e,a=4294967295,i=0,s=0){let r=ra("<IIII",t,e,a,i);s>0&&r.concat(ra("<IIII",g(this.getChipFamily()).uartDateReg,0,0,s)),await this.checkCommand(9,r)}async setDataLengths(t,e,a){if(-1!=t.mosiDlenOffs){let i=t.regBase+t.mosiDlenOffs,s=t.regBase+t.misoDlenOffs;e>0&&await this.writeRegister(i,e-1),a>0&&await this.writeRegister(s,a-1)}else{let i=t.regBase+t.usr1Offs,s=(0==a?0:a-1)<<8|(0==e?0:e-1)<<17;await this.writeRegister(i,s)}}async waitDone(t,e){for(let a=0;a<10;a++){if(0==(await this.readRegister(t)&e))return}throw Error("SPI command did not complete in time")}async runSpiFlashCommand(t,e,i=0){let s=g(this.getChipFamily()),r=s.regBase,n=r,o=r+s.usrOffs,l=r+s.usr2Offs,h=r+s.w0Offs,d=1<<18;if(i>32)throw new Error("Reading more than 32 bits back from a SPI flash operation is unsupported");if(e.length>64)throw new Error("Writing more than 64 bytes of data with one SPI command is unsupported");let f=8*e.length,c=await this.readRegister(o),_=await this.readRegister(l),u=1<<31;if(i>0&&(u|=268435456),f>0&&(u|=134217728),await this.setDataLengths(s,f,i),await this.writeRegister(o,u),await this.writeRegister(l,7<<28|t),0==f)await this.writeRegister(h,0);else{e.concat(new Array(e.length%4).fill(0));let t=na("I".repeat(Math.floor(e.length/4)),e),i=h;this.logger.debug(`Words Length: ${t.length}`);for(const e of t)this.logger.debug(`Writing word ${a(e)} to register offset ${a(i)}`),await this.writeRegister(i,e),i+=4}await this.writeRegister(n,d),await this.waitDone(n,d);let w=await this.readRegister(h);return await this.writeRegister(o,c),await this.writeRegister(l,_),w}async detectFlashSize(){this.logger.log("Detecting Flash Size");let t=await this.flashId(),e=255&t,i=t>>16&255;this.logger.log(`FlashId: ${a(t)}`),this.logger.log(`Flash Manufacturer: ${e.toString(16)}`),this.logger.log(`Flash Device: ${(t>>8&255).toString(16)}${i.toString(16)}`),this.flashSize=s[i],this.logger.log(`Auto-detected Flash size: ${this.flashSize}`)}getEraseSize(t,e){let a=4096,i=Math.floor((e+a-1)/a),s=16-Math.floor(t/a)%16;return i<s&&(s=i),i<2*s?Math.floor((i+1)/2*a):(i-s)*a}async memBegin(t,e,a,i){return await this.checkCommand(5,ra("<IIII",t,e,a,i))}async memBlock(t,e){return await this.checkCommand(7,ra("<IIII",t.length,e,0,0).concat(t),this.checksum(t))}async memFinish(t=0){let e=this.IS_STUB?3e3:500,a=ra("<II",0==t?1:0,t);return await this.checkCommand(6,a,0,e)}async runStub(){const t=await m(this.chipFamily);let e,a=2048;this.logger.log("Uploading stub...");for(let e of["text","data"])if(Object.keys(t).includes(e)){let i=t[e+"_start"],s=t[e].length,r=Math.floor((s+a-1)/a);await this.memBegin(s,r,a,i);for(let i of Array(r).keys()){let r=i*a,n=r+a;n>s&&(n=s),await this.memBlock(t[e].slice(r,n),i)}}this.logger.log("Running stub..."),await this.memFinish(t.entry);const i=await this.readPacket(500);if(e=String.fromCharCode(...i),"OHAI"!=e)throw new Error("Failed to start stub. Unexpected response: "+e);this.logger.log("Stub is now running...");const s=new la(this.port,this.logger,this);return await s.detectFlashSize(),s}async writeToStream(t){const e=this.port.writable.getWriter();await e.write(new Uint8Array(t));try{e.releaseLock()}catch(t){console.error("Ignoring release lock error",t)}}async disconnect(){this._parent?await this._parent.disconnect():(await this.port.writable.getWriter().close(),await new Promise((t=>{this._reader||t(void 0),this.addEventListener("disconnect",t,{once:!0}),this._reader.cancel()})),this.connected=!1)}}class la extends oa{constructor(){super(...arguments),this.IS_STUB=!0}async memBegin(t,e,i,s){let r=await m(this.chipFamily),n=s,o=s+t;console.log(n,o),console.log(r.data_start,r.data.length,r.text_start,r.text.length);for(let[t,e]of[[r.data_start,r.data_start+r.data.length],[r.text_start,r.text_start+r.text.length]])if(n<e&&o>t)throw new Error("Software loader is resident at "+a(t,8)+"-"+a(e,8)+". Can't load binary at overlapping address range "+a(n,8)+"-"+a(o,8)+". Try changing the binary loading address.")}async eraseFlash(){await this.checkCommand(208,[],0,6e5)}}const ha=async t=>{const e=await navigator.serial.requestPort();return t.log("Connecting..."),await e.open({baudRate:115200}),t.log("Connected successfully."),new oa(e,t)};export{o as CHIP_FAMILY_ESP32,d as CHIP_FAMILY_ESP32C3,f as CHIP_FAMILY_ESP32C6,c as CHIP_FAMILY_ESP32H2,l as CHIP_FAMILY_ESP32S2,h as CHIP_FAMILY_ESP32S3,n as CHIP_FAMILY_ESP8266,oa as ESPLoader,ha as connect}; |
{ | ||
"name": "esp-web-flasher", | ||
"version": "5.1.2", | ||
"version": "5.1.3", | ||
"description": "Flash ESP devices using WebSerial", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -21,4 +21,5 @@ # ESP Web Flasher | ||
This project started as a fork of [Adafruit WebSerial ESPTool](https://github.com/adafruit/Adafruit_WebSerial_ESPTool) in June 2021. At the time fo the fork, the original repository was a single-use website. This fork converted the code into a reusable package and published it to NPM. | ||
This project started as a fork of [Adafruit WebSerial ESPTool](https://github.com/adafruit/Adafruit_WebSerial_ESPTool) written by | ||
[Melissa LeBlanc-Williams](https://github.com/makermelissa) in June 2021. At the time fo the fork, the original repository was a single-use website. This fork converted the code into a reusable package and published it to NPM. | ||
In March 2022 Nabu Casa took over maintenance from Adafruit and this fork became the main code base. | ||
In March 2022 [Nabu Casa](https://www.nabucasa.com) took over maintenance from Adafruit and this fork became the main code base. |
@@ -621,3 +621,6 @@ import { | ||
position += flashWriteSize; | ||
updateProgress(Math.min(written, filesize), filesize); | ||
updateProgress( | ||
Math.min(written, uncompressedFilesize), | ||
uncompressedFilesize | ||
); | ||
} | ||
@@ -624,0 +627,0 @@ this.logger.log( |
@@ -16,5 +16,6 @@ { | ||
"strict": true, | ||
"suppressImplicitAnyIndexErrors": true | ||
"suppressImplicitAnyIndexErrors": true, | ||
"importHelpers": true | ||
}, | ||
"include": ["src/*"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
321327
4656
25