import{_ as t,d as e,g as i,n as r,y as a,H as s,I as n,q as o,v as h,w as _}from"./c.998383f4.js";class l extends r{constructor(){super(...arguments),this.indeterminate=!1,this.progress=0,this.density=0,this.closed=!1}open(){this.closed=!1}close(){this.closed=!0}render(){const t={"mdc-circular-progress--closed":this.closed,"mdc-circular-progress--indeterminate":this.indeterminate},e=48+4*this.density,i={width:`${e}px`,height:`${e}px`};return a`
      <div
        class="mdc-circular-progress ${s(t)}"
        style="${n(i)}"
        role="progressbar"
        aria-label="${o(this.ariaLabel)}"
        aria-valuemin="0"
        aria-valuemax="1"
        aria-valuenow="${o(this.indeterminate?void 0:this.progress)}">
        ${this.renderDeterminateContainer()}
        ${this.renderIndeterminateContainer()}
      </div>`}renderDeterminateContainer(){const t=48+4*this.density,e=t/2,i=this.density>=-3?18+11*this.density/6:12.5+5*(this.density+3)/4,r=6.2831852*i,s=(1-this.progress)*r,n=this.density>=-3?4+this.density*(1/3):3+(this.density+3)*(1/6);return a`
      <div class="mdc-circular-progress__determinate-container">
        <svg class="mdc-circular-progress__determinate-circle-graphic"
             viewBox="0 0 ${t} ${t}">
          <circle class="mdc-circular-progress__determinate-track"
                  cx="${e}" cy="${e}" r="${i}"
                  stroke-width="${n}"></circle>
          <circle class="mdc-circular-progress__determinate-circle"
                  cx="${e}" cy="${e}" r="${i}"
                  stroke-dasharray="${6.2831852*i}"
                  stroke-dashoffset="${s}"
                  stroke-width="${n}"></circle>
        </svg>
      </div>`}renderIndeterminateContainer(){return a`
      <div class="mdc-circular-progress__indeterminate-container">
        <div class="mdc-circular-progress__spinner-layer">
          ${this.renderIndeterminateSpinnerLayer()}
        </div>
      </div>`}renderIndeterminateSpinnerLayer(){const t=48+4*this.density,e=t/2,i=this.density>=-3?18+11*this.density/6:12.5+5*(this.density+3)/4,r=6.2831852*i,s=.5*r,n=this.density>=-3?4+this.density*(1/3):3+(this.density+3)*(1/6);return a`
        <div class="mdc-circular-progress__circle-clipper mdc-circular-progress__circle-left">
          <svg class="mdc-circular-progress__indeterminate-circle-graphic"
               viewBox="0 0 ${t} ${t}">
            <circle cx="${e}" cy="${e}" r="${i}"
                    stroke-dasharray="${r}"
                    stroke-dashoffset="${s}"
                    stroke-width="${n}"></circle>
          </svg>
        </div>
        <div class="mdc-circular-progress__gap-patch">
          <svg class="mdc-circular-progress__indeterminate-circle-graphic"
               viewBox="0 0 ${t} ${t}">
            <circle cx="${e}" cy="${e}" r="${i}"
                    stroke-dasharray="${r}"
                    stroke-dashoffset="${s}"
                    stroke-width="${.8*n}"></circle>
          </svg>
        </div>
        <div class="mdc-circular-progress__circle-clipper mdc-circular-progress__circle-right">
          <svg class="mdc-circular-progress__indeterminate-circle-graphic"
               viewBox="0 0 ${t} ${t}">
            <circle cx="${e}" cy="${e}" r="${i}"
                    stroke-dasharray="${r}"
                    stroke-dashoffset="${s}"
                    stroke-width="${n}"></circle>
          </svg>
        </div>`}update(t){super.update(t),t.has("progress")&&(this.progress>1&&(this.progress=1),this.progress<0&&(this.progress=0))}}t([e({type:Boolean,reflect:!0})],l.prototype,"indeterminate",void 0),t([e({type:Number,reflect:!0})],l.prototype,"progress",void 0),t([e({type:Number,reflect:!0})],l.prototype,"density",void 0),t([e({type:Boolean,reflect:!0})],l.prototype,"closed",void 0),t([i,e({type:String,attribute:"aria-label"})],l.prototype,"ariaLabel",void 0);const c=h`.mdc-circular-progress__determinate-circle,.mdc-circular-progress__indeterminate-circle-graphic{stroke:#6200ee;stroke:var(--mdc-theme-primary, #6200ee)}.mdc-circular-progress__determinate-track{stroke:transparent}@keyframes mdc-circular-progress-container-rotate{to{transform:rotate(360deg)}}@keyframes mdc-circular-progress-spinner-layer-rotate{12.5%{transform:rotate(135deg)}25%{transform:rotate(270deg)}37.5%{transform:rotate(405deg)}50%{transform:rotate(540deg)}62.5%{transform:rotate(675deg)}75%{transform:rotate(810deg)}87.5%{transform:rotate(945deg)}100%{transform:rotate(1080deg)}}@keyframes mdc-circular-progress-color-1-fade-in-out{from{opacity:.99}25%{opacity:.99}26%{opacity:0}89%{opacity:0}90%{opacity:.99}to{opacity:.99}}@keyframes mdc-circular-progress-color-2-fade-in-out{from{opacity:0}15%{opacity:0}25%{opacity:.99}50%{opacity:.99}51%{opacity:0}to{opacity:0}}@keyframes mdc-circular-progress-color-3-fade-in-out{from{opacity:0}40%{opacity:0}50%{opacity:.99}75%{opacity:.99}76%{opacity:0}to{opacity:0}}@keyframes mdc-circular-progress-color-4-fade-in-out{from{opacity:0}65%{opacity:0}75%{opacity:.99}90%{opacity:.99}to{opacity:0}}@keyframes mdc-circular-progress-left-spin{from{transform:rotate(265deg)}50%{transform:rotate(130deg)}to{transform:rotate(265deg)}}@keyframes mdc-circular-progress-right-spin{from{transform:rotate(-265deg)}50%{transform:rotate(-130deg)}to{transform:rotate(-265deg)}}.mdc-circular-progress{display:inline-flex;position:relative;direction:ltr;line-height:0;transition:opacity 250ms 0ms cubic-bezier(0.4, 0, 0.6, 1)}.mdc-circular-progress__determinate-container,.mdc-circular-progress__indeterminate-circle-graphic,.mdc-circular-progress__indeterminate-container,.mdc-circular-progress__spinner-layer{position:absolute;width:100%;height:100%}.mdc-circular-progress__determinate-container{transform:rotate(-90deg)}.mdc-circular-progress__indeterminate-container{font-size:0;letter-spacing:0;white-space:nowrap;opacity:0}.mdc-circular-progress__determinate-circle-graphic,.mdc-circular-progress__indeterminate-circle-graphic{fill:transparent}.mdc-circular-progress__determinate-circle{transition:stroke-dashoffset 500ms 0ms cubic-bezier(0, 0, 0.2, 1)}.mdc-circular-progress__gap-patch{position:absolute;top:0;left:47.5%;box-sizing:border-box;width:5%;height:100%;overflow:hidden}.mdc-circular-progress__gap-patch .mdc-circular-progress__indeterminate-circle-graphic{left:-900%;width:2000%;transform:rotate(180deg)}.mdc-circular-progress__circle-clipper{display:inline-flex;position:relative;width:50%;height:100%;overflow:hidden}.mdc-circular-progress__circle-clipper .mdc-circular-progress__indeterminate-circle-graphic{width:200%}.mdc-circular-progress__circle-right .mdc-circular-progress__indeterminate-circle-graphic{left:-100%}.mdc-circular-progress--indeterminate .mdc-circular-progress__determinate-container{opacity:0}.mdc-circular-progress--indeterminate .mdc-circular-progress__indeterminate-container{opacity:1}.mdc-circular-progress--indeterminate .mdc-circular-progress__indeterminate-container{animation:mdc-circular-progress-container-rotate 1568.2352941176ms linear infinite}.mdc-circular-progress--indeterminate .mdc-circular-progress__spinner-layer{animation:mdc-circular-progress-spinner-layer-rotate 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both}.mdc-circular-progress--indeterminate .mdc-circular-progress__color-1{animation:mdc-circular-progress-spinner-layer-rotate 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both,mdc-circular-progress-color-1-fade-in-out 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both}.mdc-circular-progress--indeterminate .mdc-circular-progress__color-2{animation:mdc-circular-progress-spinner-layer-rotate 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both,mdc-circular-progress-color-2-fade-in-out 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both}.mdc-circular-progress--indeterminate .mdc-circular-progress__color-3{animation:mdc-circular-progress-spinner-layer-rotate 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both,mdc-circular-progress-color-3-fade-in-out 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both}.mdc-circular-progress--indeterminate .mdc-circular-progress__color-4{animation:mdc-circular-progress-spinner-layer-rotate 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both,mdc-circular-progress-color-4-fade-in-out 5332ms cubic-bezier(0.4, 0, 0.2, 1) infinite both}.mdc-circular-progress--indeterminate .mdc-circular-progress__circle-left .mdc-circular-progress__indeterminate-circle-graphic{animation:mdc-circular-progress-left-spin 1333ms cubic-bezier(0.4, 0, 0.2, 1) infinite both}.mdc-circular-progress--indeterminate .mdc-circular-progress__circle-right .mdc-circular-progress__indeterminate-circle-graphic{animation:mdc-circular-progress-right-spin 1333ms cubic-bezier(0.4, 0, 0.2, 1) infinite both}.mdc-circular-progress--closed{opacity:0}:host{display:inline-flex}.mdc-circular-progress__determinate-track{stroke:transparent;stroke:var(--mdc-circular-progress-track-color, transparent)}`;let d=class extends l{};d.styles=[c],d=t([_("mwc-circular-progress")],d);const f=async t=>{import("./c.274132bb.js");const e=document.createElement("esphome-no-port-picked-dialog");return e.doTryAgain=t,document.body.append(e),!0};class u extends Error{}function p(t){let e=t.length;for(;--e>=0;)t[e]=0}const m=256,g=286,w=30,b=15,y=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]),k=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]),v=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),E=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),S=new Array(576);p(S);const A=new Array(60);p(A);const x=new Array(512);p(x);const R=new Array(256);p(R);const T=new Array(29);p(T);const I=new Array(w);function z(t,e,i,r,a){this.static_tree=t,this.extra_bits=e,this.extra_base=i,this.elems=r,this.max_length=a,this.has_stree=t&&t.length}let U,D,L;function M(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}p(I);const F=t=>t<256?x[t]:x[256+(t>>>7)],P=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},B=(t,e,i)=>{t.bi_valid>16-i?(t.bi_buf|=e<<t.bi_valid&65535,P(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=i-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=i)},O=(t,e,i)=>{B(t,i[2*e],i[2*e+1])},Z=(t,e)=>{let i=0;do{i|=1&t,t>>>=1,i<<=1}while(--e>0);return i>>>1},C=(t,e,i)=>{const r=new Array(16);let a,s,n=0;for(a=1;a<=b;a++)n=n+i[a-1]<<1,r[a]=n;for(s=0;s<=e;s++){let e=t[2*s+1];0!==e&&(t[2*s]=Z(r[e]++,e))}},H=t=>{let e;for(e=0;e<g;e++)t.dyn_ltree[2*e]=0;for(e=0;e<w;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.sym_next=t.matches=0},N=t=>{t.bi_valid>8?P(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},$=(t,e,i,r)=>{const a=2*e,s=2*i;return t[a]<t[s]||t[a]===t[s]&&r[e]<=r[i]},G=(t,e,i)=>{const r=t.heap[i];let a=i<<1;for(;a<=t.heap_len&&(a<t.heap_len&&$(e,t.heap[a+1],t.heap[a],t.depth)&&a++,!$(e,r,t.heap[a],t.depth));)t.heap[i]=t.heap[a],i=a,a<<=1;t.heap[i]=r},W=(t,e,i)=>{let r,a,s,n,o=0;if(0!==t.sym_next)do{r=255&t.pending_buf[t.sym_buf+o++],r+=(255&t.pending_buf[t.sym_buf+o++])<<8,a=t.pending_buf[t.sym_buf+o++],0===r?O(t,a,e):(s=R[a],O(t,s+m+1,e),n=y[s],0!==n&&(a-=T[s],B(t,a,n)),r--,s=F(r),O(t,s,i),n=k[s],0!==n&&(r-=I[s],B(t,r,n)))}while(o<t.sym_next);O(t,256,e)},K=(t,e)=>{const i=e.dyn_tree,r=e.stat_desc.static_tree,a=e.stat_desc.has_stree,s=e.stat_desc.elems;let n,o,h,_=-1;for(t.heap_len=0,t.heap_max=573,n=0;n<s;n++)0!==i[2*n]?(t.heap[++t.heap_len]=_=n,t.depth[n]=0):i[2*n+1]=0;for(;t.heap_len<2;)h=t.heap[++t.heap_len]=_<2?++_:0,i[2*h]=1,t.depth[h]=0,t.opt_len--,a&&(t.static_len-=r[2*h+1]);for(e.max_code=_,n=t.heap_len>>1;n>=1;n--)G(t,i,n);h=s;do{n=t.heap[1],t.heap[1]=t.heap[t.heap_len--],G(t,i,1),o=t.heap[1],t.heap[--t.heap_max]=n,t.heap[--t.heap_max]=o,i[2*h]=i[2*n]+i[2*o],t.depth[h]=(t.depth[n]>=t.depth[o]?t.depth[n]:t.depth[o])+1,i[2*n+1]=i[2*o+1]=h,t.heap[1]=h++,G(t,i,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const i=e.dyn_tree,r=e.max_code,a=e.stat_desc.static_tree,s=e.stat_desc.has_stree,n=e.stat_desc.extra_bits,o=e.stat_desc.extra_base,h=e.stat_desc.max_length;let _,l,c,d,f,u,p=0;for(d=0;d<=b;d++)t.bl_count[d]=0;for(i[2*t.heap[t.heap_max]+1]=0,_=t.heap_max+1;_<573;_++)l=t.heap[_],d=i[2*i[2*l+1]+1]+1,d>h&&(d=h,p++),i[2*l+1]=d,l>r||(t.bl_count[d]++,f=0,l>=o&&(f=n[l-o]),u=i[2*l],t.opt_len+=u*(d+f),s&&(t.static_len+=u*(a[2*l+1]+f)));if(0!==p){do{for(d=h-1;0===t.bl_count[d];)d--;t.bl_count[d]--,t.bl_count[d+1]+=2,t.bl_count[h]--,p-=2}while(p>0);for(d=h;0!==d;d--)for(l=t.bl_count[d];0!==l;)c=t.heap[--_],c>r||(i[2*c+1]!==d&&(t.opt_len+=(d-i[2*c+1])*i[2*c],i[2*c+1]=d),l--)}})(t,e),C(i,_,t.bl_count)},j=(t,e,i)=>{let r,a,s=-1,n=e[1],o=0,h=7,_=4;for(0===n&&(h=138,_=3),e[2*(i+1)+1]=65535,r=0;r<=i;r++)a=n,n=e[2*(r+1)+1],++o<h&&a===n||(o<_?t.bl_tree[2*a]+=o:0!==a?(a!==s&&t.bl_tree[2*a]++,t.bl_tree[32]++):o<=10?t.bl_tree[34]++:t.bl_tree[36]++,o=0,s=a,0===n?(h=138,_=3):a===n?(h=6,_=3):(h=7,_=4))},Y=(t,e,i)=>{let r,a,s=-1,n=e[1],o=0,h=7,_=4;for(0===n&&(h=138,_=3),r=0;r<=i;r++)if(a=n,n=e[2*(r+1)+1],!(++o<h&&a===n)){if(o<_)do{O(t,a,t.bl_tree)}while(0!=--o);else 0!==a?(a!==s&&(O(t,a,t.bl_tree),o--),O(t,16,t.bl_tree),B(t,o-3,2)):o<=10?(O(t,17,t.bl_tree),B(t,o-3,3)):(O(t,18,t.bl_tree),B(t,o-11,7));o=0,s=a,0===n?(h=138,_=3):a===n?(h=6,_=3):(h=7,_=4)}};let q=!1;const V=(t,e,i,r)=>{B(t,0+(r?1:0),3),N(t),P(t,i),P(t,~i),i&&t.pending_buf.set(t.window.subarray(e,e+i),t.pending),t.pending+=i};var X=t=>{q||((()=>{let t,e,i,r,a;const s=new Array(16);for(i=0,r=0;r<28;r++)for(T[r]=i,t=0;t<1<<y[r];t++)R[i++]=r;for(R[i-1]=r,a=0,r=0;r<16;r++)for(I[r]=a,t=0;t<1<<k[r];t++)x[a++]=r;for(a>>=7;r<w;r++)for(I[r]=a<<7,t=0;t<1<<k[r]-7;t++)x[256+a++]=r;for(e=0;e<=b;e++)s[e]=0;for(t=0;t<=143;)S[2*t+1]=8,t++,s[8]++;for(;t<=255;)S[2*t+1]=9,t++,s[9]++;for(;t<=279;)S[2*t+1]=7,t++,s[7]++;for(;t<=287;)S[2*t+1]=8,t++,s[8]++;for(C(S,287,s),t=0;t<w;t++)A[2*t+1]=5,A[2*t]=Z(t,5);U=new z(S,y,257,g,b),D=new z(A,k,0,w,b),L=new z(new Array(0),v,0,19,7)})(),q=!0),t.l_desc=new M(t.dyn_ltree,U),t.d_desc=new M(t.dyn_dtree,D),t.bl_desc=new M(t.bl_tree,L),t.bi_buf=0,t.bi_valid=0,H(t)},J=(t,e,i,r)=>{let a,s,n=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,i=4093624447;for(e=0;e<=31;e++,i>>>=1)if(1&i&&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<m;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),K(t,t.l_desc),K(t,t.d_desc),n=(t=>{let e;for(j(t,t.dyn_ltree,t.l_desc.max_code),j(t,t.dyn_dtree,t.d_desc.max_code),K(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*E[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),a=t.opt_len+3+7>>>3,s=t.static_len+3+7>>>3,s<=a&&(a=s)):a=s=i+5,i+4<=a&&-1!==e?V(t,e,i,r):4===t.strategy||s===a?(B(t,2+(r?1:0),3),W(t,S,A)):(B(t,4+(r?1:0),3),((t,e,i,r)=>{let a;for(B(t,e-257,5),B(t,i-1,5),B(t,r-4,4),a=0;a<r;a++)B(t,t.bl_tree[2*E[a]+1],3);Y(t,t.dyn_ltree,e-1),Y(t,t.dyn_dtree,i-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,n+1),W(t,t.dyn_ltree,t.dyn_dtree)),H(t),r&&N(t)},Q=(t,e,i)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=i,0===e?t.dyn_ltree[2*i]++:(t.matches++,e--,t.dyn_ltree[2*(R[i]+m+1)]++,t.dyn_dtree[2*F(e)]++),t.sym_next===t.sym_end),tt=t=>{B(t,2,3),O(t,256,S),(t=>{16===t.bi_valid?(P(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)},et={_tr_init:X,_tr_stored_block:V,_tr_flush_block:J,_tr_tally:Q,_tr_align:tt};var it=(t,e,i,r)=>{let a=65535&t|0,s=t>>>16&65535|0,n=0;for(;0!==i;){n=i>2e3?2e3:i,i-=n;do{a=a+e[r++]|0,s=s+a|0}while(--n);a%=65521,s%=65521}return a|s<<16|0};const rt=new Uint32Array((()=>{let t,e=[];for(var i=0;i<256;i++){t=i;for(var r=0;r<8;r++)t=1&t?3988292384^t>>>1:t>>>1;e[i]=t}return e})());var at=(t,e,i,r)=>{const a=rt,s=r+i;t^=-1;for(let i=r;i<s;i++)t=t>>>8^a[255&(t^e[i])];return-1^t},st={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"},nt={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:ot,_tr_stored_block:ht,_tr_flush_block:_t,_tr_tally:lt,_tr_align:ct}=et,{Z_NO_FLUSH:dt,Z_PARTIAL_FLUSH:ft,Z_FULL_FLUSH:ut,Z_FINISH:pt,Z_BLOCK:mt,Z_OK:gt,Z_STREAM_END:wt,Z_STREAM_ERROR:bt,Z_DATA_ERROR:yt,Z_BUF_ERROR:kt,Z_DEFAULT_COMPRESSION:vt,Z_FILTERED:Et,Z_HUFFMAN_ONLY:St,Z_RLE:At,Z_FIXED:xt,Z_DEFAULT_STRATEGY:Rt,Z_UNKNOWN:Tt,Z_DEFLATED:It}=nt,zt=258,Ut=262,Dt=42,Lt=113,Mt=666,Ft=(t,e)=>(t.msg=st[e],e),Pt=t=>2*t-(t>4?9:0),Bt=t=>{let e=t.length;for(;--e>=0;)t[e]=0},Ot=t=>{let e,i,r,a=t.w_size;e=t.hash_size,r=e;do{i=t.head[--r],t.head[r]=i>=a?i-a:0}while(--e);e=a,r=e;do{i=t.prev[--r],t.prev[r]=i>=a?i-a:0}while(--e)};let Zt=(t,e,i)=>(e<<t.hash_shift^i)&t.hash_mask;const Ct=t=>{const e=t.state;let i=e.pending;i>t.avail_out&&(i=t.avail_out),0!==i&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+i),t.next_out),t.next_out+=i,e.pending_out+=i,t.total_out+=i,t.avail_out-=i,e.pending-=i,0===e.pending&&(e.pending_out=0))},Ht=(t,e)=>{_t(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,Ct(t.strm)},Nt=(t,e)=>{t.pending_buf[t.pending++]=e},$t=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Gt=(t,e,i,r)=>{let a=t.avail_in;return a>r&&(a=r),0===a?0:(t.avail_in-=a,e.set(t.input.subarray(t.next_in,t.next_in+a),i),1===t.state.wrap?t.adler=it(t.adler,e,a,i):2===t.state.wrap&&(t.adler=at(t.adler,e,a,i)),t.next_in+=a,t.total_in+=a,a)},Wt=(t,e)=>{let i,r,a=t.max_chain_length,s=t.strstart,n=t.prev_length,o=t.nice_match;const h=t.strstart>t.w_size-Ut?t.strstart-(t.w_size-Ut):0,_=t.window,l=t.w_mask,c=t.prev,d=t.strstart+zt;let f=_[s+n-1],u=_[s+n];t.prev_length>=t.good_match&&(a>>=2),o>t.lookahead&&(o=t.lookahead);do{if(i=e,_[i+n]===u&&_[i+n-1]===f&&_[i]===_[s]&&_[++i]===_[s+1]){s+=2,i++;do{}while(_[++s]===_[++i]&&_[++s]===_[++i]&&_[++s]===_[++i]&&_[++s]===_[++i]&&_[++s]===_[++i]&&_[++s]===_[++i]&&_[++s]===_[++i]&&_[++s]===_[++i]&&s<d);if(r=zt-(d-s),s=d-zt,r>n){if(t.match_start=e,n=r,r>=o)break;f=_[s+n-1],u=_[s+n]}}}while((e=c[e&l])>h&&0!=--a);return n<=t.lookahead?n:t.lookahead},Kt=t=>{const e=t.w_size;let i,r,a;do{if(r=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-Ut)&&(t.window.set(t.window.subarray(e,e+e-r),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),Ot(t),r+=e),0===t.strm.avail_in)break;if(i=Gt(t.strm,t.window,t.strstart+t.lookahead,r),t.lookahead+=i,t.lookahead+t.insert>=3)for(a=t.strstart-t.insert,t.ins_h=t.window[a],t.ins_h=Zt(t,t.ins_h,t.window[a+1]);t.insert&&(t.ins_h=Zt(t,t.ins_h,t.window[a+3-1]),t.prev[a&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=a,a++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<Ut&&0!==t.strm.avail_in)},jt=(t,e)=>{let i,r,a,s=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,n=0,o=t.strm.avail_in;do{if(i=65535,a=t.bi_valid+42>>3,t.strm.avail_out<a)break;if(a=t.strm.avail_out-a,r=t.strstart-t.block_start,i>r+t.strm.avail_in&&(i=r+t.strm.avail_in),i>a&&(i=a),i<s&&(0===i&&e!==pt||e===dt||i!==r+t.strm.avail_in))break;n=e===pt&&i===r+t.strm.avail_in?1:0,ht(t,0,0,n),t.pending_buf[t.pending-4]=i,t.pending_buf[t.pending-3]=i>>8,t.pending_buf[t.pending-2]=~i,t.pending_buf[t.pending-1]=~i>>8,Ct(t.strm),r&&(r>i&&(r=i),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+r),t.strm.next_out),t.strm.next_out+=r,t.strm.avail_out-=r,t.strm.total_out+=r,t.block_start+=r,i-=r),i&&(Gt(t.strm,t.strm.output,t.strm.next_out,i),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i)}while(0===n);return o-=t.strm.avail_in,o&&(o>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=o&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-o,t.strm.next_in),t.strstart),t.strstart+=o,t.insert+=o>t.w_size-t.insert?t.w_size-t.insert:o),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),n?4:e!==dt&&e!==pt&&0===t.strm.avail_in&&t.strstart===t.block_start?2:(a=t.window_size-t.strstart,t.strm.avail_in>a&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,a+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),a>t.strm.avail_in&&(a=t.strm.avail_in),a&&(Gt(t.strm,t.window,t.strstart,a),t.strstart+=a,t.insert+=a>t.w_size-t.insert?t.w_size-t.insert:a),t.high_water<t.strstart&&(t.high_water=t.strstart),a=t.bi_valid+42>>3,a=t.pending_buf_size-a>65535?65535:t.pending_buf_size-a,s=a>t.w_size?t.w_size:a,r=t.strstart-t.block_start,(r>=s||(r||e===pt)&&e!==dt&&0===t.strm.avail_in&&r<=a)&&(i=r>a?a:r,n=e===pt&&0===t.strm.avail_in&&i===r?1:0,ht(t,t.block_start,i,n),t.block_start+=i,Ct(t.strm)),n?3:1)},Yt=(t,e)=>{let i,r;for(;;){if(t.lookahead<Ut){if(Kt(t),t.lookahead<Ut&&e===dt)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=Zt(t,t.ins_h,t.window[t.strstart+3-1]),i=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==i&&t.strstart-i<=t.w_size-Ut&&(t.match_length=Wt(t,i)),t.match_length>=3)if(r=lt(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=Zt(t,t.ins_h,t.window[t.strstart+3-1]),i=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=Zt(t,t.ins_h,t.window[t.strstart+1]);else r=lt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(r&&(Ht(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===pt?(Ht(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Ht(t,!1),0===t.strm.avail_out)?1:2},qt=(t,e)=>{let i,r,a;for(;;){if(t.lookahead<Ut){if(Kt(t),t.lookahead<Ut&&e===dt)return 1;if(0===t.lookahead)break}if(i=0,t.lookahead>=3&&(t.ins_h=Zt(t,t.ins_h,t.window[t.strstart+3-1]),i=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!==i&&t.prev_length<t.max_lazy_match&&t.strstart-i<=t.w_size-Ut&&(t.match_length=Wt(t,i),t.match_length<=5&&(t.strategy===Et||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){a=t.strstart+t.lookahead-3,r=lt(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=a&&(t.ins_h=Zt(t,t.ins_h,t.window[t.strstart+3-1]),i=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++,r&&(Ht(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(r=lt(t,0,t.window[t.strstart-1]),r&&Ht(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&&(r=lt(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===pt?(Ht(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Ht(t,!1),0===t.strm.avail_out)?1:2};function Vt(t,e,i,r,a){this.good_length=t,this.max_lazy=e,this.nice_length=i,this.max_chain=r,this.func=a}const Xt=[new Vt(0,0,0,0,jt),new Vt(4,4,8,4,Yt),new Vt(4,5,16,8,Yt),new Vt(4,6,32,32,Yt),new Vt(4,4,16,16,qt),new Vt(8,16,32,32,qt),new Vt(8,16,128,128,qt),new Vt(8,32,128,256,qt),new Vt(32,128,258,1024,qt),new Vt(32,258,258,4096,qt)];function Jt(){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=It,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),Bt(this.dyn_ltree),Bt(this.dyn_dtree),Bt(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),Bt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Bt(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Qt=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.status!==Dt&&57!==e.status&&69!==e.status&&73!==e.status&&91!==e.status&&103!==e.status&&e.status!==Lt&&e.status!==Mt?1:0},te=t=>{if(Qt(t))return Ft(t,bt);t.total_in=t.total_out=0,t.data_type=Tt;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=2===e.wrap?57:e.wrap?Dt:Lt,t.adler=2===e.wrap?0:1,e.last_flush=-2,ot(e),gt},ee=t=>{const e=te(t);return e===gt&&(t=>{t.window_size=2*t.w_size,Bt(t.head),t.max_lazy_match=Xt[t.level].max_lazy,t.good_match=Xt[t.level].good_length,t.nice_match=Xt[t.level].nice_length,t.max_chain_length=Xt[t.level].max_chain,t.strstart=0,t.block_start=0,t.lookahead=0,t.insert=0,t.match_length=t.prev_length=2,t.match_available=0,t.ins_h=0})(t.state),e},ie=(t,e,i,r,a,s)=>{if(!t)return bt;let n=1;if(e===vt&&(e=6),r<0?(n=0,r=-r):r>15&&(n=2,r-=16),a<1||a>9||i!==It||r<8||r>15||e<0||e>9||s<0||s>xt||8===r&&1!==n)return Ft(t,bt);8===r&&(r=9);const o=new Jt;return t.state=o,o.strm=t,o.status=Dt,o.wrap=n,o.gzhead=null,o.w_bits=r,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=a+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<<a+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.sym_buf=o.lit_bufsize,o.sym_end=3*(o.lit_bufsize-1),o.level=e,o.strategy=s,o.method=i,ee(t)};var re=(t,e)=>{if(Qt(t)||e>mt||e<0)return t?Ft(t,bt):bt;const i=t.state;if(!t.output||0!==t.avail_in&&!t.input||i.status===Mt&&e!==pt)return Ft(t,0===t.avail_out?kt:bt);const r=i.last_flush;if(i.last_flush=e,0!==i.pending){if(Ct(t),0===t.avail_out)return i.last_flush=-1,gt}else if(0===t.avail_in&&Pt(e)<=Pt(r)&&e!==pt)return Ft(t,kt);if(i.status===Mt&&0!==t.avail_in)return Ft(t,kt);if(i.status===Dt&&0===i.wrap&&(i.status=Lt),i.status===Dt){let e=It+(i.w_bits-8<<4)<<8,r=-1;if(r=i.strategy>=St||i.level<2?0:i.level<6?1:6===i.level?2:3,e|=r<<6,0!==i.strstart&&(e|=32),e+=31-e%31,$t(i,e),0!==i.strstart&&($t(i,t.adler>>>16),$t(i,65535&t.adler)),t.adler=1,i.status=Lt,Ct(t),0!==i.pending)return i.last_flush=-1,gt}if(57===i.status)if(t.adler=0,Nt(i,31),Nt(i,139),Nt(i,8),i.gzhead)Nt(i,(i.gzhead.text?1:0)+(i.gzhead.hcrc?2:0)+(i.gzhead.extra?4:0)+(i.gzhead.name?8:0)+(i.gzhead.comment?16:0)),Nt(i,255&i.gzhead.time),Nt(i,i.gzhead.time>>8&255),Nt(i,i.gzhead.time>>16&255),Nt(i,i.gzhead.time>>24&255),Nt(i,9===i.level?2:i.strategy>=St||i.level<2?4:0),Nt(i,255&i.gzhead.os),i.gzhead.extra&&i.gzhead.extra.length&&(Nt(i,255&i.gzhead.extra.length),Nt(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(t.adler=at(t.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=69;else if(Nt(i,0),Nt(i,0),Nt(i,0),Nt(i,0),Nt(i,0),Nt(i,9===i.level?2:i.strategy>=St||i.level<2?4:0),Nt(i,3),i.status=Lt,Ct(t),0!==i.pending)return i.last_flush=-1,gt;if(69===i.status){if(i.gzhead.extra){let e=i.pending,r=(65535&i.gzhead.extra.length)-i.gzindex;for(;i.pending+r>i.pending_buf_size;){let a=i.pending_buf_size-i.pending;if(i.pending_buf.set(i.gzhead.extra.subarray(i.gzindex,i.gzindex+a),i.pending),i.pending=i.pending_buf_size,i.gzhead.hcrc&&i.pending>e&&(t.adler=at(t.adler,i.pending_buf,i.pending-e,e)),i.gzindex+=a,Ct(t),0!==i.pending)return i.last_flush=-1,gt;e=0,r-=a}let a=new Uint8Array(i.gzhead.extra);i.pending_buf.set(a.subarray(i.gzindex,i.gzindex+r),i.pending),i.pending+=r,i.gzhead.hcrc&&i.pending>e&&(t.adler=at(t.adler,i.pending_buf,i.pending-e,e)),i.gzindex=0}i.status=73}if(73===i.status){if(i.gzhead.name){let e,r=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>r&&(t.adler=at(t.adler,i.pending_buf,i.pending-r,r)),Ct(t),0!==i.pending)return i.last_flush=-1,gt;r=0}e=i.gzindex<i.gzhead.name.length?255&i.gzhead.name.charCodeAt(i.gzindex++):0,Nt(i,e)}while(0!==e);i.gzhead.hcrc&&i.pending>r&&(t.adler=at(t.adler,i.pending_buf,i.pending-r,r)),i.gzindex=0}i.status=91}if(91===i.status){if(i.gzhead.comment){let e,r=i.pending;do{if(i.pending===i.pending_buf_size){if(i.gzhead.hcrc&&i.pending>r&&(t.adler=at(t.adler,i.pending_buf,i.pending-r,r)),Ct(t),0!==i.pending)return i.last_flush=-1,gt;r=0}e=i.gzindex<i.gzhead.comment.length?255&i.gzhead.comment.charCodeAt(i.gzindex++):0,Nt(i,e)}while(0!==e);i.gzhead.hcrc&&i.pending>r&&(t.adler=at(t.adler,i.pending_buf,i.pending-r,r))}i.status=103}if(103===i.status){if(i.gzhead.hcrc){if(i.pending+2>i.pending_buf_size&&(Ct(t),0!==i.pending))return i.last_flush=-1,gt;Nt(i,255&t.adler),Nt(i,t.adler>>8&255),t.adler=0}if(i.status=Lt,Ct(t),0!==i.pending)return i.last_flush=-1,gt}if(0!==t.avail_in||0!==i.lookahead||e!==dt&&i.status!==Mt){let r=0===i.level?jt(i,e):i.strategy===St?((t,e)=>{let i;for(;;){if(0===t.lookahead&&(Kt(t),0===t.lookahead)){if(e===dt)return 1;break}if(t.match_length=0,i=lt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,i&&(Ht(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===pt?(Ht(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Ht(t,!1),0===t.strm.avail_out)?1:2})(i,e):i.strategy===At?((t,e)=>{let i,r,a,s;const n=t.window;for(;;){if(t.lookahead<=zt){if(Kt(t),t.lookahead<=zt&&e===dt)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(a=t.strstart-1,r=n[a],r===n[++a]&&r===n[++a]&&r===n[++a])){s=t.strstart+zt;do{}while(r===n[++a]&&r===n[++a]&&r===n[++a]&&r===n[++a]&&r===n[++a]&&r===n[++a]&&r===n[++a]&&r===n[++a]&&a<s);t.match_length=zt-(s-a),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(i=lt(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(i=lt(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),i&&(Ht(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===pt?(Ht(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Ht(t,!1),0===t.strm.avail_out)?1:2})(i,e):Xt[i.level].func(i,e);if(3!==r&&4!==r||(i.status=Mt),1===r||3===r)return 0===t.avail_out&&(i.last_flush=-1),gt;if(2===r&&(e===ft?ct(i):e!==mt&&(ht(i,0,0,!1),e===ut&&(Bt(i.head),0===i.lookahead&&(i.strstart=0,i.block_start=0,i.insert=0))),Ct(t),0===t.avail_out))return i.last_flush=-1,gt}return e!==pt?gt:i.wrap<=0?wt:(2===i.wrap?(Nt(i,255&t.adler),Nt(i,t.adler>>8&255),Nt(i,t.adler>>16&255),Nt(i,t.adler>>24&255),Nt(i,255&t.total_in),Nt(i,t.total_in>>8&255),Nt(i,t.total_in>>16&255),Nt(i,t.total_in>>24&255)):($t(i,t.adler>>>16),$t(i,65535&t.adler)),Ct(t),i.wrap>0&&(i.wrap=-i.wrap),0!==i.pending?gt:wt)},ae=(t,e)=>{let i=e.length;if(Qt(t))return bt;const r=t.state,a=r.wrap;if(2===a||1===a&&r.status!==Dt||r.lookahead)return bt;if(1===a&&(t.adler=it(t.adler,e,i,0)),r.wrap=0,i>=r.w_size){0===a&&(Bt(r.head),r.strstart=0,r.block_start=0,r.insert=0);let t=new Uint8Array(r.w_size);t.set(e.subarray(i-r.w_size,i),0),e=t,i=r.w_size}const s=t.avail_in,n=t.next_in,o=t.input;for(t.avail_in=i,t.next_in=0,t.input=e,Kt(r);r.lookahead>=3;){let t=r.strstart,e=r.lookahead-2;do{r.ins_h=Zt(r,r.ins_h,r.window[t+3-1]),r.prev[t&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=t,t++}while(--e);r.strstart=t,r.lookahead=2,Kt(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,t.next_in=n,t.input=o,t.avail_in=s,r.wrap=a,gt},se={deflateInit:(t,e)=>ie(t,e,It,15,8,Rt),deflateInit2:ie,deflateReset:ee,deflateResetKeep:te,deflateSetHeader:(t,e)=>Qt(t)||2!==t.state.wrap?bt:(t.state.gzhead=e,gt),deflate:re,deflateEnd:t=>{if(Qt(t))return bt;const e=t.state.status;return t.state=null,e===Lt?Ft(t,yt):gt},deflateSetDictionary:ae,deflateInfo:"pako deflate (from Nodeca project)"};const ne=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var oe=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const i=e.shift();if(i){if("object"!=typeof i)throw new TypeError(i+"must be non-object");for(const e in i)ne(i,e)&&(t[e]=i[e])}}return t},he=t=>{let e=0;for(let i=0,r=t.length;i<r;i++)e+=t[i].length;const i=new Uint8Array(e);for(let e=0,r=0,a=t.length;e<a;e++){let a=t[e];i.set(a,r),r+=a.length}return i};let _e=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){_e=!1}const le=new Uint8Array(256);for(let t=0;t<256;t++)le[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;le[254]=le[254]=1;var ce=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,i,r,a,s,n=t.length,o=0;for(a=0;a<n;a++)i=t.charCodeAt(a),55296==(64512&i)&&a+1<n&&(r=t.charCodeAt(a+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),a++)),o+=i<128?1:i<2048?2:i<65536?3:4;for(e=new Uint8Array(o),s=0,a=0;s<o;a++)i=t.charCodeAt(a),55296==(64512&i)&&a+1<n&&(r=t.charCodeAt(a+1),56320==(64512&r)&&(i=65536+(i-55296<<10)+(r-56320),a++)),i<128?e[s++]=i:i<2048?(e[s++]=192|i>>>6,e[s++]=128|63&i):i<65536?(e[s++]=224|i>>>12,e[s++]=128|i>>>6&63,e[s++]=128|63&i):(e[s++]=240|i>>>18,e[s++]=128|i>>>12&63,e[s++]=128|i>>>6&63,e[s++]=128|63&i);return e},de=(t,e)=>{const i=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let r,a;const s=new Array(2*i);for(a=0,r=0;r<i;){let e=t[r++];if(e<128){s[a++]=e;continue}let n=le[e];if(n>4)s[a++]=65533,r+=n-1;else{for(e&=2===n?31:3===n?15:7;n>1&&r<i;)e=e<<6|63&t[r++],n--;n>1?s[a++]=65533:e<65536?s[a++]=e:(e-=65536,s[a++]=55296|e>>10&1023,s[a++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&_e)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let i="";for(let r=0;r<e;r++)i+=String.fromCharCode(t[r]);return i})(s,a)},fe=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let i=e-1;for(;i>=0&&128==(192&t[i]);)i--;return i<0||0===i?e:i+le[t[i]]>e?i:e};var ue=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 pe=Object.prototype.toString,{Z_NO_FLUSH:me,Z_SYNC_FLUSH:ge,Z_FULL_FLUSH:we,Z_FINISH:be,Z_OK:ye,Z_STREAM_END:ke,Z_DEFAULT_COMPRESSION:ve,Z_DEFAULT_STRATEGY:Ee,Z_DEFLATED:Se}=nt;function Ae(t){this.options=oe({level:ve,method:Se,chunkSize:16384,windowBits:15,memLevel:8,strategy:Ee},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 ue,this.strm.avail_out=0;let i=se.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(i!==ye)throw new Error(st[i]);if(e.header&&se.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?ce(e.dictionary):"[object ArrayBuffer]"===pe.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,i=se.deflateSetDictionary(this.strm,t),i!==ye)throw new Error(st[i]);this._dict_set=!0}}function xe(t,e){const i=new Ae(e);if(i.push(t,!0),i.err)throw i.msg||st[i.err];return i.result}Ae.prototype.push=function(t,e){const i=this.strm,r=this.options.chunkSize;let a,s;if(this.ended)return!1;for(s=e===~~e?e:!0===e?be:me,"string"==typeof t?i.input=ce(t):"[object ArrayBuffer]"===pe.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;)if(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),(s===ge||s===we)&&i.avail_out<=6)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else{if(a=se.deflate(i,s),a===ke)return i.next_out>0&&this.onData(i.output.subarray(0,i.next_out)),a=se.deflateEnd(this.strm),this.onEnd(a),this.ended=!0,a===ye;if(0!==i.avail_out){if(s>0&&i.next_out>0)this.onData(i.output.subarray(0,i.next_out)),i.avail_out=0;else if(0===i.avail_in)break}else this.onData(i.output)}return!0},Ae.prototype.onData=function(t){this.chunks.push(t)},Ae.prototype.onEnd=function(t){t===ye&&(this.result=he(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Re={Deflate:Ae,deflate:xe,deflateRaw:function(t,e){return(e=e||{}).raw=!0,xe(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,xe(t,e)},constants:nt};const Te=16209;var Ie=function(t,e){let i,r,a,s,n,o,h,_,l,c,d,f,u,p,m,g,w,b,y,k,v,E,S,A;const x=t.state;i=t.next_in,S=t.input,r=i+(t.avail_in-5),a=t.next_out,A=t.output,s=a-(e-t.avail_out),n=a+(t.avail_out-257),o=x.dmax,h=x.wsize,_=x.whave,l=x.wnext,c=x.window,d=x.hold,f=x.bits,u=x.lencode,p=x.distcode,m=(1<<x.lenbits)-1,g=(1<<x.distbits)-1;t:do{f<15&&(d+=S[i++]<<f,f+=8,d+=S[i++]<<f,f+=8),w=u[d&m];e:for(;;){if(b=w>>>24,d>>>=b,f-=b,b=w>>>16&255,0===b)A[a++]=65535&w;else{if(!(16&b)){if(0==(64&b)){w=u[(65535&w)+(d&(1<<b)-1)];continue e}if(32&b){x.mode=16191;break t}t.msg="invalid literal/length code",x.mode=Te;break t}y=65535&w,b&=15,b&&(f<b&&(d+=S[i++]<<f,f+=8),y+=d&(1<<b)-1,d>>>=b,f-=b),f<15&&(d+=S[i++]<<f,f+=8,d+=S[i++]<<f,f+=8),w=p[d&g];i:for(;;){if(b=w>>>24,d>>>=b,f-=b,b=w>>>16&255,!(16&b)){if(0==(64&b)){w=p[(65535&w)+(d&(1<<b)-1)];continue i}t.msg="invalid distance code",x.mode=Te;break t}if(k=65535&w,b&=15,f<b&&(d+=S[i++]<<f,f+=8,f<b&&(d+=S[i++]<<f,f+=8)),k+=d&(1<<b)-1,k>o){t.msg="invalid distance too far back",x.mode=Te;break t}if(d>>>=b,f-=b,b=a-s,k>b){if(b=k-b,b>_&&x.sane){t.msg="invalid distance too far back",x.mode=Te;break t}if(v=0,E=c,0===l){if(v+=h-b,b<y){y-=b;do{A[a++]=c[v++]}while(--b);v=a-k,E=A}}else if(l<b){if(v+=h+l-b,b-=l,b<y){y-=b;do{A[a++]=c[v++]}while(--b);if(v=0,l<y){b=l,y-=b;do{A[a++]=c[v++]}while(--b);v=a-k,E=A}}}else if(v+=l-b,b<y){y-=b;do{A[a++]=c[v++]}while(--b);v=a-k,E=A}for(;y>2;)A[a++]=E[v++],A[a++]=E[v++],A[a++]=E[v++],y-=3;y&&(A[a++]=E[v++],y>1&&(A[a++]=E[v++]))}else{v=a-k;do{A[a++]=A[v++],A[a++]=A[v++],A[a++]=A[v++],y-=3}while(y>2);y&&(A[a++]=A[v++],y>1&&(A[a++]=A[v++]))}break}}break}}while(i<r&&a<n);y=f>>3,i-=y,f-=y<<3,d&=(1<<f)-1,t.next_in=i,t.next_out=a,t.avail_in=i<r?r-i+5:5-(i-r),t.avail_out=a<n?n-a+257:257-(a-n),x.hold=d,x.bits=f};const ze=15,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]),De=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]),Le=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 Fe=(t,e,i,r,a,s,n,o)=>{const h=o.bits;let _,l,c,d,f,u,p=0,m=0,g=0,w=0,b=0,y=0,k=0,v=0,E=0,S=0,A=null;const x=new Uint16Array(16),R=new Uint16Array(16);let T,I,z,U=null;for(p=0;p<=ze;p++)x[p]=0;for(m=0;m<r;m++)x[e[i+m]]++;for(b=h,w=ze;w>=1&&0===x[w];w--);if(b>w&&(b=w),0===w)return a[s++]=20971520,a[s++]=20971520,o.bits=1,0;for(g=1;g<w&&0===x[g];g++);for(b<g&&(b=g),v=1,p=1;p<=ze;p++)if(v<<=1,v-=x[p],v<0)return-1;if(v>0&&(0===t||1!==w))return-1;for(R[1]=0,p=1;p<ze;p++)R[p+1]=R[p]+x[p];for(m=0;m<r;m++)0!==e[i+m]&&(n[R[e[i+m]]++]=m);if(0===t?(A=U=n,u=20):1===t?(A=Ue,U=De,u=257):(A=Le,U=Me,u=0),S=0,m=0,p=g,f=s,y=b,k=0,c=-1,E=1<<b,d=E-1,1===t&&E>852||2===t&&E>592)return 1;for(;;){T=p-k,n[m]+1<u?(I=0,z=n[m]):n[m]>=u?(I=U[n[m]-u],z=A[n[m]-u]):(I=96,z=0),_=1<<p-k,l=1<<y,g=l;do{l-=_,a[f+(S>>k)+l]=T<<24|I<<16|z|0}while(0!==l);for(_=1<<p-1;S&_;)_>>=1;if(0!==_?(S&=_-1,S+=_):S=0,m++,0==--x[p]){if(p===w)break;p=e[i+n[m]]}if(p>b&&(S&d)!==c){for(0===k&&(k=b),f+=g,y=p-k,v=1<<y;y+k<w&&(v-=x[y+k],!(v<=0));)y++,v<<=1;if(E+=1<<y,1===t&&E>852||2===t&&E>592)return 1;c=S&d,a[c]=b<<24|y<<16|f-s|0}}return 0!==S&&(a[f+S]=p-k<<24|64<<16|0),o.bits=b,0};const{Z_FINISH:Pe,Z_BLOCK:Be,Z_TREES:Oe,Z_OK:Ze,Z_STREAM_END:Ce,Z_NEED_DICT:He,Z_STREAM_ERROR:Ne,Z_DATA_ERROR:$e,Z_MEM_ERROR:Ge,Z_BUF_ERROR:We,Z_DEFLATED:Ke}=nt,je=16180,Ye=16190,qe=16191,Ve=16192,Xe=16194,Je=16199,Qe=16200,ti=16206,ei=16209,ii=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function ri(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const ai=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.mode<je||e.mode>16211?1:0},si=t=>{if(ai(t))return Ne;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=je,e.last=0,e.havedict=0,e.flags=-1,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,Ze},ni=t=>{if(ai(t))return Ne;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,si(t)},oi=(t,e)=>{let i;if(ai(t))return Ne;const r=t.state;return e<0?(i=0,e=-e):(i=5+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?Ne:(null!==r.window&&r.wbits!==e&&(r.window=null),r.wrap=i,r.wbits=e,ni(t))},hi=(t,e)=>{if(!t)return Ne;const i=new ri;t.state=i,i.strm=t,i.window=null,i.mode=je;const r=oi(t,e);return r!==Ze&&(t.state=null),r};let _i,li,ci=!0;const di=t=>{if(ci){_i=new Int32Array(512),li=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(Fe(1,t.lens,0,288,_i,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Fe(2,t.lens,0,32,li,0,t.work,{bits:5}),ci=!1}t.lencode=_i,t.lenbits=9,t.distcode=li,t.distbits=5},fi=(t,e,i,r)=>{let a;const s=t.state;return null===s.window&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),r>=s.wsize?(s.window.set(e.subarray(i-s.wsize,i),0),s.wnext=0,s.whave=s.wsize):(a=s.wsize-s.wnext,a>r&&(a=r),s.window.set(e.subarray(i-r,i-r+a),s.wnext),(r-=a)?(s.window.set(e.subarray(i-r,i),0),s.wnext=r,s.whave=s.wsize):(s.wnext+=a,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=a))),0};var ui=(t,e)=>{let i,r,a,s,n,o,h,_,l,c,d,f,u,p,m,g,w,b,y,k,v,E,S=0;const A=new Uint8Array(4);let x,R;const T=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(ai(t)||!t.output||!t.input&&0!==t.avail_in)return Ne;i=t.state,i.mode===qe&&(i.mode=Ve),n=t.next_out,a=t.output,h=t.avail_out,s=t.next_in,r=t.input,o=t.avail_in,_=i.hold,l=i.bits,c=o,d=h,E=Ze;t:for(;;)switch(i.mode){case je:if(0===i.wrap){i.mode=Ve;break}for(;l<16;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(2&i.wrap&&35615===_){0===i.wbits&&(i.wbits=15),i.check=0,A[0]=255&_,A[1]=_>>>8&255,i.check=at(i.check,A,2,0),_=0,l=0,i.mode=16181;break}if(i.head&&(i.head.done=!1),!(1&i.wrap)||(((255&_)<<8)+(_>>8))%31){t.msg="incorrect header check",i.mode=ei;break}if((15&_)!==Ke){t.msg="unknown compression method",i.mode=ei;break}if(_>>>=4,l-=4,v=8+(15&_),0===i.wbits&&(i.wbits=v),v>15||v>i.wbits){t.msg="invalid window size",i.mode=ei;break}i.dmax=1<<i.wbits,i.flags=0,t.adler=i.check=1,i.mode=512&_?16189:qe,_=0,l=0;break;case 16181:for(;l<16;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(i.flags=_,(255&i.flags)!==Ke){t.msg="unknown compression method",i.mode=ei;break}if(57344&i.flags){t.msg="unknown header flags set",i.mode=ei;break}i.head&&(i.head.text=_>>8&1),512&i.flags&&4&i.wrap&&(A[0]=255&_,A[1]=_>>>8&255,i.check=at(i.check,A,2,0)),_=0,l=0,i.mode=16182;case 16182:for(;l<32;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}i.head&&(i.head.time=_),512&i.flags&&4&i.wrap&&(A[0]=255&_,A[1]=_>>>8&255,A[2]=_>>>16&255,A[3]=_>>>24&255,i.check=at(i.check,A,4,0)),_=0,l=0,i.mode=16183;case 16183:for(;l<16;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}i.head&&(i.head.xflags=255&_,i.head.os=_>>8),512&i.flags&&4&i.wrap&&(A[0]=255&_,A[1]=_>>>8&255,i.check=at(i.check,A,2,0)),_=0,l=0,i.mode=16184;case 16184:if(1024&i.flags){for(;l<16;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}i.length=_,i.head&&(i.head.extra_len=_),512&i.flags&&4&i.wrap&&(A[0]=255&_,A[1]=_>>>8&255,i.check=at(i.check,A,2,0)),_=0,l=0}else i.head&&(i.head.extra=null);i.mode=16185;case 16185:if(1024&i.flags&&(f=i.length,f>o&&(f=o),f&&(i.head&&(v=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Uint8Array(i.head.extra_len)),i.head.extra.set(r.subarray(s,s+f),v)),512&i.flags&&4&i.wrap&&(i.check=at(i.check,r,f,s)),o-=f,s+=f,i.length-=f),i.length))break t;i.length=0,i.mode=16186;case 16186:if(2048&i.flags){if(0===o)break t;f=0;do{v=r[s+f++],i.head&&v&&i.length<65536&&(i.head.name+=String.fromCharCode(v))}while(v&&f<o);if(512&i.flags&&4&i.wrap&&(i.check=at(i.check,r,f,s)),o-=f,s+=f,v)break t}else i.head&&(i.head.name=null);i.length=0,i.mode=16187;case 16187:if(4096&i.flags){if(0===o)break t;f=0;do{v=r[s+f++],i.head&&v&&i.length<65536&&(i.head.comment+=String.fromCharCode(v))}while(v&&f<o);if(512&i.flags&&4&i.wrap&&(i.check=at(i.check,r,f,s)),o-=f,s+=f,v)break t}else i.head&&(i.head.comment=null);i.mode=16188;case 16188:if(512&i.flags){for(;l<16;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(4&i.wrap&&_!==(65535&i.check)){t.msg="header crc mismatch",i.mode=ei;break}_=0,l=0}i.head&&(i.head.hcrc=i.flags>>9&1,i.head.done=!0),t.adler=i.check=0,i.mode=qe;break;case 16189:for(;l<32;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}t.adler=i.check=ii(_),_=0,l=0,i.mode=Ye;case Ye:if(0===i.havedict)return t.next_out=n,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=_,i.bits=l,He;t.adler=i.check=1,i.mode=qe;case qe:if(e===Be||e===Oe)break t;case Ve:if(i.last){_>>>=7&l,l-=7&l,i.mode=ti;break}for(;l<3;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}switch(i.last=1&_,_>>>=1,l-=1,3&_){case 0:i.mode=16193;break;case 1:if(di(i),i.mode=Je,e===Oe){_>>>=2,l-=2;break t}break;case 2:i.mode=16196;break;case 3:t.msg="invalid block type",i.mode=ei}_>>>=2,l-=2;break;case 16193:for(_>>>=7&l,l-=7&l;l<32;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if((65535&_)!=(_>>>16^65535)){t.msg="invalid stored block lengths",i.mode=ei;break}if(i.length=65535&_,_=0,l=0,i.mode=Xe,e===Oe)break t;case Xe:i.mode=16195;case 16195:if(f=i.length,f){if(f>o&&(f=o),f>h&&(f=h),0===f)break t;a.set(r.subarray(s,s+f),n),o-=f,s+=f,h-=f,n+=f,i.length-=f;break}i.mode=qe;break;case 16196:for(;l<14;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(i.nlen=257+(31&_),_>>>=5,l-=5,i.ndist=1+(31&_),_>>>=5,l-=5,i.ncode=4+(15&_),_>>>=4,l-=4,i.nlen>286||i.ndist>30){t.msg="too many length or distance symbols",i.mode=ei;break}i.have=0,i.mode=16197;case 16197:for(;i.have<i.ncode;){for(;l<3;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}i.lens[T[i.have++]]=7&_,_>>>=3,l-=3}for(;i.have<19;)i.lens[T[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,x={bits:i.lenbits},E=Fe(0,i.lens,0,19,i.lencode,0,i.work,x),i.lenbits=x.bits,E){t.msg="invalid code lengths set",i.mode=ei;break}i.have=0,i.mode=16198;case 16198:for(;i.have<i.nlen+i.ndist;){for(;S=i.lencode[_&(1<<i.lenbits)-1],m=S>>>24,g=S>>>16&255,w=65535&S,!(m<=l);){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(w<16)_>>>=m,l-=m,i.lens[i.have++]=w;else{if(16===w){for(R=m+2;l<R;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(_>>>=m,l-=m,0===i.have){t.msg="invalid bit length repeat",i.mode=ei;break}v=i.lens[i.have-1],f=3+(3&_),_>>>=2,l-=2}else if(17===w){for(R=m+3;l<R;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}_>>>=m,l-=m,v=0,f=3+(7&_),_>>>=3,l-=3}else{for(R=m+7;l<R;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}_>>>=m,l-=m,v=0,f=11+(127&_),_>>>=7,l-=7}if(i.have+f>i.nlen+i.ndist){t.msg="invalid bit length repeat",i.mode=ei;break}for(;f--;)i.lens[i.have++]=v}}if(i.mode===ei)break;if(0===i.lens[256]){t.msg="invalid code -- missing end-of-block",i.mode=ei;break}if(i.lenbits=9,x={bits:i.lenbits},E=Fe(1,i.lens,0,i.nlen,i.lencode,0,i.work,x),i.lenbits=x.bits,E){t.msg="invalid literal/lengths set",i.mode=ei;break}if(i.distbits=6,i.distcode=i.distdyn,x={bits:i.distbits},E=Fe(2,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,x),i.distbits=x.bits,E){t.msg="invalid distances set",i.mode=ei;break}if(i.mode=Je,e===Oe)break t;case Je:i.mode=Qe;case Qe:if(o>=6&&h>=258){t.next_out=n,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=_,i.bits=l,Ie(t,d),n=t.next_out,a=t.output,h=t.avail_out,s=t.next_in,r=t.input,o=t.avail_in,_=i.hold,l=i.bits,i.mode===qe&&(i.back=-1);break}for(i.back=0;S=i.lencode[_&(1<<i.lenbits)-1],m=S>>>24,g=S>>>16&255,w=65535&S,!(m<=l);){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(g&&0==(240&g)){for(b=m,y=g,k=w;S=i.lencode[k+((_&(1<<b+y)-1)>>b)],m=S>>>24,g=S>>>16&255,w=65535&S,!(b+m<=l);){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}_>>>=b,l-=b,i.back+=b}if(_>>>=m,l-=m,i.back+=m,i.length=w,0===g){i.mode=16205;break}if(32&g){i.back=-1,i.mode=qe;break}if(64&g){t.msg="invalid literal/length code",i.mode=ei;break}i.extra=15&g,i.mode=16201;case 16201:if(i.extra){for(R=i.extra;l<R;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}i.length+=_&(1<<i.extra)-1,_>>>=i.extra,l-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=16202;case 16202:for(;S=i.distcode[_&(1<<i.distbits)-1],m=S>>>24,g=S>>>16&255,w=65535&S,!(m<=l);){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(0==(240&g)){for(b=m,y=g,k=w;S=i.distcode[k+((_&(1<<b+y)-1)>>b)],m=S>>>24,g=S>>>16&255,w=65535&S,!(b+m<=l);){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}_>>>=b,l-=b,i.back+=b}if(_>>>=m,l-=m,i.back+=m,64&g){t.msg="invalid distance code",i.mode=ei;break}i.offset=w,i.extra=15&g,i.mode=16203;case 16203:if(i.extra){for(R=i.extra;l<R;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}i.offset+=_&(1<<i.extra)-1,_>>>=i.extra,l-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){t.msg="invalid distance too far back",i.mode=ei;break}i.mode=16204;case 16204:if(0===h)break t;if(f=d-h,i.offset>f){if(f=i.offset-f,f>i.whave&&i.sane){t.msg="invalid distance too far back",i.mode=ei;break}f>i.wnext?(f-=i.wnext,u=i.wsize-f):u=i.wnext-f,f>i.length&&(f=i.length),p=i.window}else p=a,u=n-i.offset,f=i.length;f>h&&(f=h),h-=f,i.length-=f;do{a[n++]=p[u++]}while(--f);0===i.length&&(i.mode=Qe);break;case 16205:if(0===h)break t;a[n++]=i.length,h--,i.mode=Qe;break;case ti:if(i.wrap){for(;l<32;){if(0===o)break t;o--,_|=r[s++]<<l,l+=8}if(d-=h,t.total_out+=d,i.total+=d,4&i.wrap&&d&&(t.adler=i.check=i.flags?at(i.check,a,d,n-d):it(i.check,a,d,n-d)),d=h,4&i.wrap&&(i.flags?_:ii(_))!==i.check){t.msg="incorrect data check",i.mode=ei;break}_=0,l=0}i.mode=16207;case 16207:if(i.wrap&&i.flags){for(;l<32;){if(0===o)break t;o--,_+=r[s++]<<l,l+=8}if(4&i.wrap&&_!==(4294967295&i.total)){t.msg="incorrect length check",i.mode=ei;break}_=0,l=0}i.mode=16208;case 16208:E=Ce;break t;case ei:E=$e;break t;case 16210:return Ge;default:return Ne}return t.next_out=n,t.avail_out=h,t.next_in=s,t.avail_in=o,i.hold=_,i.bits=l,(i.wsize||d!==t.avail_out&&i.mode<ei&&(i.mode<ti||e!==Pe))&&fi(t,t.output,t.next_out,d-t.avail_out),c-=t.avail_in,d-=t.avail_out,t.total_in+=c,t.total_out+=d,i.total+=d,4&i.wrap&&d&&(t.adler=i.check=i.flags?at(i.check,a,d,t.next_out-d):it(i.check,a,d,t.next_out-d)),t.data_type=i.bits+(i.last?64:0)+(i.mode===qe?128:0)+(i.mode===Je||i.mode===Xe?256:0),(0===c&&0===d||e===Pe)&&E===Ze&&(E=We),E},pi={inflateReset:ni,inflateReset2:oi,inflateResetKeep:si,inflateInit:t=>hi(t,15),inflateInit2:hi,inflate:ui,inflateEnd:t=>{if(ai(t))return Ne;let e=t.state;return e.window&&(e.window=null),t.state=null,Ze},inflateGetHeader:(t,e)=>{if(ai(t))return Ne;const i=t.state;return 0==(2&i.wrap)?Ne:(i.head=e,e.done=!1,Ze)},inflateSetDictionary:(t,e)=>{const i=e.length;let r,a,s;return ai(t)?Ne:(r=t.state,0!==r.wrap&&r.mode!==Ye?Ne:r.mode===Ye&&(a=1,a=it(a,e,i,0),a!==r.check)?$e:(s=fi(t,e,i,i),s?(r.mode=16210,Ge):(r.havedict=1,Ze)))},inflateInfo:"pako inflate (from Nodeca project)"};var mi=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 gi=Object.prototype.toString,{Z_NO_FLUSH:wi,Z_FINISH:bi,Z_OK:yi,Z_STREAM_END:ki,Z_NEED_DICT:vi,Z_STREAM_ERROR:Ei,Z_DATA_ERROR:Si,Z_MEM_ERROR:Ai}=nt;function xi(t){this.options=oe({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 ue,this.strm.avail_out=0;let i=pi.inflateInit2(this.strm,e.windowBits);if(i!==yi)throw new Error(st[i]);if(this.header=new mi,pi.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=ce(e.dictionary):"[object ArrayBuffer]"===gi.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(i=pi.inflateSetDictionary(this.strm,e.dictionary),i!==yi)))throw new Error(st[i])}xi.prototype.push=function(t,e){const i=this.strm,r=this.options.chunkSize,a=this.options.dictionary;let s,n,o;if(this.ended)return!1;for(n=e===~~e?e:!0===e?bi:wi,"[object ArrayBuffer]"===gi.call(t)?i.input=new Uint8Array(t):i.input=t,i.next_in=0,i.avail_in=i.input.length;;){for(0===i.avail_out&&(i.output=new Uint8Array(r),i.next_out=0,i.avail_out=r),s=pi.inflate(i,n),s===vi&&a&&(s=pi.inflateSetDictionary(i,a),s===yi?s=pi.inflate(i,n):s===Si&&(s=vi));i.avail_in>0&&s===ki&&i.state.wrap>0&&0!==t[i.next_in];)pi.inflateReset(i),s=pi.inflate(i,n);switch(s){case Ei:case Si:case vi:case Ai:return this.onEnd(s),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(0===i.avail_out||s===ki))if("string"===this.options.to){let t=fe(i.output,i.next_out),e=i.next_out-t,a=de(i.output,t);i.next_out=e,i.avail_out=r-e,e&&i.output.set(i.output.subarray(t,t+e),0),this.onData(a)}else this.onData(i.output.length===i.next_out?i.output:i.output.subarray(0,i.next_out));if(s!==yi||0!==o){if(s===ki)return s=pi.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(0===i.avail_in)break}}return!0},xi.prototype.onData=function(t){this.chunks.push(t)},xi.prototype.onEnd=function(t){t===yi&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=he(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};const{Deflate:Ri,deflate:Ti,deflateRaw:Ii,gzip:zi}=Re;var Ui=Ti;class Di{constructor(t,e,i,r=115200,a=!1){this.transport=t,this.baudrate=e,this.terminal=i,this.rom_baudrate=r,this.debugLogging=a,this.ESP_RAM_BLOCK=6144,this.ESP_FLASH_BEGIN=2,this.ESP_FLASH_DATA=3,this.ESP_FLASH_END=4,this.ESP_MEM_BEGIN=5,this.ESP_MEM_END=6,this.ESP_MEM_DATA=7,this.ESP_WRITE_REG=9,this.ESP_READ_REG=10,this.ESP_SPI_ATTACH=13,this.ESP_CHANGE_BAUDRATE=15,this.ESP_FLASH_DEFL_BEGIN=16,this.ESP_FLASH_DEFL_DATA=17,this.ESP_FLASH_DEFL_END=18,this.ESP_SPI_FLASH_MD5=19,this.ESP_ERASE_FLASH=208,this.ESP_ERASE_REGION=209,this.ESP_RUN_USER_CODE=211,this.ESP_IMAGE_MAGIC=233,this.ESP_CHECKSUM_MAGIC=239,this.ROM_INVALID_RECV_MSG=5,this.ERASE_REGION_TIMEOUT_PER_MB=3e4,this.ERASE_WRITE_TIMEOUT_PER_MB=4e4,this.MD5_TIMEOUT_PER_MB=8e3,this.CHIP_ERASE_TIMEOUT=12e4,this.MAX_TIMEOUT=2*this.CHIP_ERASE_TIMEOUT,this.CHIP_DETECT_MAGIC_REG_ADDR=1073745920,this.DETECTED_FLASH_SIZES={18:"256KB",19:"512KB",20:"1MB",21:"2MB",22:"4MB",23:"8MB",24:"16MB"},this.USB_JTAG_SERIAL_PID=4097,this.checksum=function(t){let e,i=239;for(e=0;e<t.length;e++)i^=t[e];return i},this.timeout_per_mb=function(t,e){const i=t*(e/1e6);return i<3e3?3e3:i},this.flash_size_bytes=function(t){let e=-1;return-1!==t.indexOf("KB")?e=1024*parseInt(t.slice(0,t.indexOf("KB"))):-1!==t.indexOf("MB")&&(e=1024*parseInt(t.slice(0,t.indexOf("MB")))*1024),e},this.IS_STUB=!1,this.chip=null,this.FLASH_WRITE_SIZE=16384,this.terminal&&this.terminal.clean(),this.info("esptool.js v0.1-dev"),this.info("Serial port "+this.transport.get_info())}_sleep(t){return new Promise((e=>setTimeout(e,t)))}write(t,e=!0){this.terminal?e?this.terminal.writeLine(t):this.terminal.write(t):console.log(t)}error(t,e=!0){this.write(`Error: ${t}`,e)}info(t,e=!0){this.write(t,e)}debug(t,e=!0){this.debugLogging&&this.write(`Debug: ${t}`,e)}_short_to_bytearray(t){return new Uint8Array([255&t,t>>8&255])}_int_to_bytearray(t){return new Uint8Array([255&t,t>>8&255,t>>16&255,t>>24&255])}_bytearray_to_short(t,e){return t|e>>8}_bytearray_to_int(t,e,i,r){return t|e<<8|i<<16|r<<24}_appendBuffer(t,e){const i=new Uint8Array(t.byteLength+e.byteLength);return i.set(new Uint8Array(t),0),i.set(new Uint8Array(e),t.byteLength),i.buffer}_appendArray(t,e){const i=new Uint8Array(t.length+e.length);return i.set(t,0),i.set(e,t.length),i}ui8ToBstr(t){let e="";for(let i=0;i<t.length;i++)e+=String.fromCharCode(t[i]);return e}bstrToUi8(t){const e=new Uint8Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return e}async flush_input(){try{await this.transport.rawRead(200)}catch(t){this.error(t)}}async command(t=null,e=new Uint8Array(0),i=0,r=!0,a=3e3){if(null!=t){const r=new Uint8Array(8+e.length);let a;for(r[0]=0,r[1]=t,r[2]=this._short_to_bytearray(e.length)[0],r[3]=this._short_to_bytearray(e.length)[1],r[4]=this._int_to_bytearray(i)[0],r[5]=this._int_to_bytearray(i)[1],r[6]=this._int_to_bytearray(i)[2],r[7]=this._int_to_bytearray(i)[3],a=0;a<e.length;a++)r[8+a]=e[a];await this.transport.write(r)}if(!r)return[0,new Uint8Array(0)];for(let e=0;e<100;e++){const e=await this.transport.read(a),i=e[0],r=e[1],s=this._bytearray_to_int(e[4],e[5],e[6],e[7]),n=e.slice(8);if(1==i){if(null==t||r==t)return[s,n];if(0!=n[0]&&n[1]==this.ROM_INVALID_RECV_MSG)throw await this.flush_input(),new u("unsupported command error")}}throw new u("invalid response")}async read_reg(t,e=3e3){const i=this._int_to_bytearray(t);return(await this.command(this.ESP_READ_REG,i,void 0,void 0,e))[0]}async write_reg(t,e,i=4294967295,r=0,a=0){let s=this._appendArray(this._int_to_bytearray(t),this._int_to_bytearray(e));s=this._appendArray(s,this._int_to_bytearray(i)),s=this._appendArray(s,this._int_to_bytearray(r)),a>0&&(s=this._appendArray(s,this._int_to_bytearray(this.chip.UART_DATE_REG_ADDR)),s=this._appendArray(s,this._int_to_bytearray(0)),s=this._appendArray(s,this._int_to_bytearray(0)),s=this._appendArray(s,this._int_to_bytearray(a))),await this.check_command("write target memory",this.ESP_WRITE_REG,s)}async sync(){this.debug("Sync");const t=new Uint8Array(36);let e;for(t[0]=7,t[1]=7,t[2]=18,t[3]=32,e=0;e<32;e++)t[4+e]=85;try{return await this.command(8,t,void 0,void 0,100)}catch(t){throw this.debug("Sync err "+t),t}}async _connect_attempt(t="default_reset",e=!1){this.debug("_connect_attempt "+t+" "+e),"no_reset"!==t&&(this.transport.get_pid()===this.USB_JTAG_SERIAL_PID?(await this.transport.setRTS(!1),await this.transport.setDTR(!1),await this._sleep(100),await this.transport.setDTR(!0),await this.transport.setRTS(!1),await this._sleep(100),await this.transport.setRTS(!0),await this.transport.setDTR(!1),await this.transport.setRTS(!0),await this._sleep(100),await this.transport.setRTS(!1),await this.transport.setDTR(!1)):(await this.transport.setDTR(!1),await this.transport.setRTS(!0),await this._sleep(100),e&&await this._sleep(2e3),await this.transport.setDTR(!0),await this.transport.setRTS(!1),await this._sleep(50),await this.transport.setDTR(!1)));let i=0,r=!0;for(;r;){try{i+=(await this.transport.read(1e3)).length}catch(t){if(this.debug(t),t instanceof Error){r=!1;break}}await this._sleep(50)}for(this.transport.slip_reader_enabled=!0,i=7;i--;){try{const t=await this.sync();return this.debug(t[0].toString()),"success"}catch(t){this.debug(t),t instanceof Error&&(e?this.info("_",!1):this.info(".",!1))}await this._sleep(50)}return"error"}async connect(t="default_reset",e=7,i=!1){let r,a;for(this.info("Connecting...",!1),await this.transport.connect(this.rom_baudrate),r=0;r<e&&(a=await this._connect_attempt(t,!1),"success"!==a)&&(a=await this._connect_attempt(t,!0),"success"!==a);r++);if("success"!==a)throw new u("Failed to connect with the device");if(this.info("\n\r",!1),!i){const t=await this.read_reg(1073745920)>>>0;if(this.debug("Chip Magic "+t.toString(16)),this.chip=await async function(t){switch(t){case 15736195:{const{ESP32ROM:t}=await import("./c.286ad693.js");return new t}case 1763790959:case 456216687:{const{ESP32C3ROM:t}=await import("./c.c74d5ae3.js");return new t}case 9:{const{ESP32S3ROM:t}=await import("./c.f4034d2e.js");return new t}case 1990:{const{ESP32S2ROM:t}=await import("./c.417d3d2d.js");return new t}case 4293968129:{const{ESP8266ROM:t}=await import("./c.c0a69417.js");return new t}default:return null}}(t),null===this.chip)throw new u(`Unexpected CHIP magic value ${t}. Failed to autodetect chip type.`)}}async detect_chip(t="default_reset"){await this.connect(t),this.info("Detecting chip type... ",!1),null!=this.chip?this.info(this.chip.CHIP_NAME):this.info("unknown!")}async check_command(t="",e=null,i=new Uint8Array(0),r=0,a=3e3){this.debug("check_command "+t);const s=await this.command(e,i,r,void 0,a);return s[1].length>4?s[1]:s[0]}async mem_begin(t,e,i,r){this.debug("mem_begin "+t+" "+e+" "+i+" "+r.toString(16));let a=this._appendArray(this._int_to_bytearray(t),this._int_to_bytearray(e));a=this._appendArray(a,this._int_to_bytearray(i)),a=this._appendArray(a,this._int_to_bytearray(r)),await this.check_command("enter RAM download mode",this.ESP_MEM_BEGIN,a)}async mem_block(t,e){let i=this._appendArray(this._int_to_bytearray(t.length),this._int_to_bytearray(e));i=this._appendArray(i,this._int_to_bytearray(0)),i=this._appendArray(i,this._int_to_bytearray(0)),i=this._appendArray(i,t);const r=this.checksum(t);await this.check_command("write to target RAM",this.ESP_MEM_DATA,i,r)}async mem_finish(t){const e=0===t?1:0,i=this._appendArray(this._int_to_bytearray(e),this._int_to_bytearray(t));await this.check_command("leave RAM download mode",this.ESP_MEM_END,i,void 0,50)}async flash_spi_attach(t){const e=this._int_to_bytearray(t);await this.check_command("configure SPI flash pins",this.ESP_SPI_ATTACH,e)}async flash_begin(t,e){const i=Math.floor((t+this.FLASH_WRITE_SIZE-1)/this.FLASH_WRITE_SIZE),r=this.chip.get_erase_size(e,t),a=new Date,s=a.getTime();let n=3e3;0==this.IS_STUB&&(n=this.timeout_per_mb(this.ERASE_REGION_TIMEOUT_PER_MB,t)),this.debug("flash begin "+r+" "+i+" "+this.FLASH_WRITE_SIZE+" "+e+" "+t);let o=this._appendArray(this._int_to_bytearray(r),this._int_to_bytearray(i));o=this._appendArray(o,this._int_to_bytearray(this.FLASH_WRITE_SIZE)),o=this._appendArray(o,this._int_to_bytearray(e)),0==this.IS_STUB&&(o=this._appendArray(o,this._int_to_bytearray(0))),await this.check_command("enter Flash download mode",this.ESP_FLASH_BEGIN,o,void 0,n);const h=a.getTime();return 0!=t&&0==this.IS_STUB&&this.info("Took "+(h-s)/1e3+"."+(h-s)%1e3+"s to erase flash block"),i}async flash_defl_begin(t,e,i){const r=Math.floor((e+this.FLASH_WRITE_SIZE-1)/this.FLASH_WRITE_SIZE),a=Math.floor((t+this.FLASH_WRITE_SIZE-1)/this.FLASH_WRITE_SIZE),s=new Date,n=s.getTime();let o,h;this.IS_STUB?(o=t,h=3e3):(o=a*this.FLASH_WRITE_SIZE,h=this.timeout_per_mb(this.ERASE_REGION_TIMEOUT_PER_MB,o)),this.info("Compressed "+t+" bytes to "+e+"...");let _=this._appendArray(this._int_to_bytearray(o),this._int_to_bytearray(r));_=this._appendArray(_,this._int_to_bytearray(this.FLASH_WRITE_SIZE)),_=this._appendArray(_,this._int_to_bytearray(i)),"ESP32-S2"!==this.chip.CHIP_NAME&&"ESP32-S3"!==this.chip.CHIP_NAME&&"ESP32-C3"!==this.chip.CHIP_NAME||!1!==this.IS_STUB||(_=this._appendArray(_,this._int_to_bytearray(0))),await this.check_command("enter compressed flash mode",this.ESP_FLASH_DEFL_BEGIN,_,void 0,h);const l=s.getTime();return 0!=t&&!1===this.IS_STUB&&this.info("Took "+(l-n)/1e3+"."+(l-n)%1e3+"s to erase flash block"),r}async flash_block(t,e,i){let r=this._appendArray(this._int_to_bytearray(t.length),this._int_to_bytearray(e));r=this._appendArray(r,this._int_to_bytearray(0)),r=this._appendArray(r,this._int_to_bytearray(0)),r=this._appendArray(r,t);const a=this.checksum(t);await this.check_command("write to target Flash after seq "+e,this.ESP_FLASH_DATA,r,a,i)}async flash_defl_block(t,e,i){let r=this._appendArray(this._int_to_bytearray(t.length),this._int_to_bytearray(e));r=this._appendArray(r,this._int_to_bytearray(0)),r=this._appendArray(r,this._int_to_bytearray(0)),r=this._appendArray(r,t);const a=this.checksum(t);this.debug("flash_defl_block "+t[0].toString(16)+" "+t[1].toString(16)),await this.check_command("write compressed data to flash after seq "+e,this.ESP_FLASH_DEFL_DATA,r,a,i)}async flash_finish(t=!1){const e=t?0:1,i=this._int_to_bytearray(e);await this.check_command("leave Flash mode",this.ESP_FLASH_END,i)}async flash_defl_finish(t=!1){const e=t?0:1,i=this._int_to_bytearray(e);await this.check_command("leave compressed flash mode",this.ESP_FLASH_DEFL_END,i)}async run_spiflash_command(t,e,i){const r=this.chip.SPI_REG_BASE,a=r+0,s=r+this.chip.SPI_USR_OFFS,n=r+this.chip.SPI_USR1_OFFS,o=r+this.chip.SPI_USR2_OFFS,h=r+this.chip.SPI_W0_OFFS;let _;_=null!=this.chip.SPI_MOSI_DLEN_OFFS?async(t,e)=>{const i=r+this.chip.SPI_MOSI_DLEN_OFFS,a=r+this.chip.SPI_MISO_DLEN_OFFS;t>0&&await this.write_reg(i,t-1),e>0&&await this.write_reg(a,e-1)}:async(t,e)=>{const i=n,r=(0===e?0:e-1)<<8|(0===t?0:t-1)<<17;await this.write_reg(i,r)};const l=1<<18;if(i>32)throw new u("Reading more than 32 bits back from a SPI flash operation is unsupported");if(e.length>64)throw new u("Writing more than 64 bytes of data with one SPI command is unsupported");const c=8*e.length,d=await this.read_reg(s),f=await this.read_reg(o);let p,m=1<<31;i>0&&(m|=268435456),c>0&&(m|=134217728),await _(c,i),await this.write_reg(s,m);let g=7<<28|t;if(await this.write_reg(o,g),0==c)await this.write_reg(h,0);else{if(e.length%4!=0){const t=new Uint8Array(e.length%4);e=this._appendArray(e,t)}let t=h;for(p=0;p<e.length-4;p+=4)g=this._bytearray_to_int(e[p],e[p+1],e[p+2],e[p+3]),await this.write_reg(t,g),t+=4}for(await this.write_reg(a,l),p=0;p<10&&(g=await this.read_reg(a)&l,0!=g);p++);if(10===p)throw new u("SPI command did not complete in time");const w=await this.read_reg(h);return await this.write_reg(s,d),await this.write_reg(o,f),w}async read_flash_id(){const t=new Uint8Array(0);return await this.run_spiflash_command(159,t,24)}async erase_flash(){this.info("Erasing flash (this may take a while)...");let t=new Date;const e=t.getTime(),i=await this.check_command("erase flash",this.ESP_ERASE_FLASH,void 0,void 0,this.CHIP_ERASE_TIMEOUT);t=new Date;const r=t.getTime();return this.info("Chip erase completed successfully in "+(r-e)/1e3+"s"),i}toHex(t){return Array.prototype.map.call(t,(t=>("00"+t.toString(16)).slice(-2))).join("")}async flash_md5sum(t,e){const i=this.timeout_per_mb(this.MD5_TIMEOUT_PER_MB,e);let r=this._appendArray(this._int_to_bytearray(t),this._int_to_bytearray(e));r=this._appendArray(r,this._int_to_bytearray(0)),r=this._appendArray(r,this._int_to_bytearray(0));let a=await this.check_command("calculate md5sum",this.ESP_SPI_FLASH_MD5,r,void 0,i);a instanceof Uint8Array&&a.length>16&&(a=a.slice(0,16));return this.toHex(a)}async run_stub(){this.info("Uploading stub...");let t=atob(this.chip.ROM_TEXT),e=t.split("").map((function(t){return t.charCodeAt(0)}));const i=new Uint8Array(e);t=atob(this.chip.ROM_DATA),e=t.split("").map((function(t){return t.charCodeAt(0)}));const r=new Uint8Array(e);let a,s=Math.floor((i.length+this.ESP_RAM_BLOCK-1)/this.ESP_RAM_BLOCK);for(await this.mem_begin(i.length,s,this.ESP_RAM_BLOCK,this.chip.TEXT_START),a=0;a<s;a++){const t=a*this.ESP_RAM_BLOCK,e=t+this.ESP_RAM_BLOCK;await this.mem_block(i.slice(t,e),a)}for(s=Math.floor((r.length+this.ESP_RAM_BLOCK-1)/this.ESP_RAM_BLOCK),await this.mem_begin(r.length,s,this.ESP_RAM_BLOCK,this.chip.DATA_START),a=0;a<s;a++){const t=a*this.ESP_RAM_BLOCK,e=t+this.ESP_RAM_BLOCK;await this.mem_block(r.slice(t,e),a)}this.info("Running stub..."),await this.mem_finish(this.chip.ENTRY);for(let t=0;t<100;t++){const t=await this.transport.read(1e3,6);if(79===t[0]&&72===t[1]&&65===t[2]&&73===t[3])return this.info("Stub running..."),this.IS_STUB=!0,this.FLASH_WRITE_SIZE=16384,this.chip}throw new u("Failed to start stub. Unexpected response")}async change_baud(){this.info("Changing baudrate to "+this.baudrate);const t=this.IS_STUB?this.transport.baudrate:0,e=this._appendArray(this._int_to_bytearray(this.baudrate),this._int_to_bytearray(t)),i=await this.command(this.ESP_CHANGE_BAUDRATE,e);this.debug(i[0].toString()),this.info("Changed"),await this.transport.disconnect(),await this._sleep(50),await this.transport.connect(this.baudrate);try{await this.transport.rawRead(500)}catch(t){this.debug(t)}}async main_fn(t="default_reset"){await this.detect_chip(t);const e=await this.chip.get_chip_description(this);return this.info("Chip is "+e),this.info("Features: "+await this.chip.get_chip_features(this)),this.info("Crystal is "+await this.chip.get_crystal_freq(this)+"MHz"),this.info("MAC: "+await this.chip.read_mac(this)),await this.chip.read_mac(this),void 0!==this.chip._post_connect&&await this.chip._post_connect(this),await this.run_stub(),e}parse_flash_size_arg(t){if(void 0===this.chip.FLASH_SIZES[t])throw new u("Flash size "+t+" is not supported by this chip type. Supported sizes: "+this.chip.FLASH_SIZES);return this.chip.FLASH_SIZES[t]}_update_image_flash_params(t,e,i,r,a){if(this.debug("_update_image_flash_params "+i+" "+r+" "+a),t.length<8)return t;if(e!=this.chip.BOOTLOADER_FLASH_OFFSET)return t;if("keep"===i&&"keep"===r&&"keep"===a)return this.info("Not changing the image"),t;const s=parseInt(t[0]);let n=parseInt(t[2]);const o=parseInt(t[3]);if(s!==this.ESP_IMAGE_MAGIC)return this.info("Warning: Image file at 0x"+e.toString(16)+" doesn't look like an image file, so not changing any flash settings."),t;if("keep"!==r){n={qio:0,qout:1,dio:2,dout:3}[r]}let h=15&o;if("keep"!==a){h={"40m":0,"26m":1,"20m":2,"80m":15}[a]}let _=240&o;"keep"!==i&&(_=this.parse_flash_size_arg(i));const l=n<<8|h+_;return this.info("Flash params set to "+l.toString(16)),parseInt(t[2])!==n<<8&&(t=t.substring(0,2)+(n<<8).toString()+t.substring(3)),parseInt(t[3])!==h+_&&(t=t.substring(0,3)+(h+_).toString()+t.substring(4)),t}async write_flash(t,e="keep",i="keep",r="keep",a=!1,s=!0,n,o){if(this.debug("EspLoader program"),"keep"!==e){const i=this.flash_size_bytes(e);for(let e=0;e<t.length;e++)if(t[e].data.length+t[e].address>i)throw new u(`File ${e+1} doesn't fit in the available flash`)}let h,_;!0===this.IS_STUB&&!0===a&&await this.erase_flash();for(let a=0;a<t.length;a++){this.debug("Data Length "+t[a].data.length),h=t[a].data;const l=t[a].data.length%4;if(l>0&&(h+="ÿÿÿÿ".substring(4-l)),_=t[a].address,this.debug("Image Length "+h.length),0===h.length){this.debug("Warning: File is empty");continue}let c;h=this._update_image_flash_params(h,_,e,i,r),o&&(c=o(h),this.debug("Image MD5 "+c));const d=h.length;let f;if(s){const t=this.bstrToUi8(h);h=this.ui8ToBstr(Ui(t,{level:9})),f=await this.flash_defl_begin(d,h.length,_)}else f=await this.flash_begin(d,_);let p=0,m=0;const g=h.length;n&&n(a,0,g);let w=new Date;const b=w.getTime();let y=5e3;for(;h.length>0;){this.debug("Write loop "+_+" "+p+" "+f),this.info("Writing at 0x"+(_+p*this.FLASH_WRITE_SIZE).toString(16)+"... ("+Math.floor(100*(p+1)/f)+"%)");const t=this.bstrToUi8(h.slice(0,this.FLASH_WRITE_SIZE));if(!s)throw new u("Yet to handle Non Compressed writes");{const e=5e3;!1===this.IS_STUB&&(y=e),await this.flash_defl_block(t,p,y),this.IS_STUB&&(y=e)}m+=t.length,h=h.slice(this.FLASH_WRITE_SIZE,h.length),p++,n&&n(a,m,g)}this.IS_STUB&&await this.read_reg(this.CHIP_DETECT_MAGIC_REG_ADDR,y),w=new Date;const k=w.getTime()-b;if(s&&this.info("Wrote "+d+" bytes ("+m+" compressed) at 0x"+_.toString(16)+" in "+k/1e3+" seconds."),c){const t=await this.flash_md5sum(_,d);if(new String(t).valueOf()!=new String(c).valueOf())throw this.info("File  md5: "+c),this.info("Flash md5: "+t),new u("MD5 of file does not match data in flash!");this.info("Hash of data verified.")}}this.info("Leaving..."),this.IS_STUB&&(await this.flash_begin(0,0),s?await this.flash_defl_finish():await this.flash_finish())}async flash_id(){this.debug("flash_id");const t=await this.read_flash_id();this.info("Manufacturer: "+(255&t).toString(16));const e=t>>16&255;this.info("Device: "+(t>>8&255).toString(16)+e.toString(16)),this.info("Detected flash size: "+this.DETECTED_FLASH_SIZES[e])}async hard_reset(){await this.transport.setRTS(!0),await this._sleep(100),await this.transport.setRTS(!1)}async soft_reset(){if(this.IS_STUB){if("ESP8266"!=this.chip.CHIP_NAME)throw new u("Soft resetting is currently only supported on ESP8266");await this.command(this.ESP_RUN_USER_CODE,void 0,void 0,!1)}else await this.flash_begin(0,0),await this.flash_finish(!1)}}class Li{constructor(t){this.device=t,this.slip_reader_enabled=!1,this.left_over=new Uint8Array(0),this.baudrate=0,this._DTR_state=!1}get_info(){const t=this.device.getInfo();return t.usbVendorId&&t.usbProductId?`WebSerial VendorID 0x${t.usbVendorId.toString(16)} ProductID 0x${t.usbProductId.toString(16)}`:""}get_pid(){return this.device.getInfo().usbProductId}slip_writer(t){let e=0,i=0,r=0;for(i=0;i<t.length;i++)192!==t[i]&&219!==t[i]||e++;const a=new Uint8Array(2+e+t.length);for(a[0]=192,r=1,i=0;i<t.length;i++,r++)192!==t[i]?219!==t[i]?a[r]=t[i]:(a[r++]=219,a[r]=221):(a[r++]=219,a[r]=220);return a[r]=192,a}async write(t){const e=this.slip_writer(t);if(this.device.writable){const t=this.device.writable.getWriter();await t.write(e),t.releaseLock()}}_appendBuffer(t,e){const i=new Uint8Array(t.byteLength+e.byteLength);return i.set(new Uint8Array(t),0),i.set(new Uint8Array(e),t.byteLength),i.buffer}slip_reader(t){let e=0,i=0,r=0,a="init";for(;e<t.length;)if("init"!==a||192!=t[e]){if("valid_data"===a&&192==t[e]){r=e-1,a="packet_complete";break}e++}else i=e+1,a="valid_data",e++;if("packet_complete"!==a)return this.left_over=t,new Uint8Array(0);this.left_over=t.slice(r+2);const s=new Uint8Array(r-i+1);let n=0;for(e=i;e<=r;e++,n++)219!==t[e]||220!==t[e+1]?219!==t[e]||221!==t[e+1]?s[n]=t[e]:(s[n]=219,e++):(s[n]=192,e++);return s.slice(0,n)}async read(t=0,e=12){let i,r=this.left_over;if(this.left_over=new Uint8Array(0),this.slip_reader_enabled){const t=this.slip_reader(r);if(t.length>0)return t;r=this.left_over,this.left_over=new Uint8Array(0)}if(void 0===this.device.readable)return this.left_over;const a=this.device.readable.getReader();try{t>0&&(i=setTimeout((function(){a.cancel()}),t));do{const{value:t,done:e}=await a.read();if(e)throw this.left_over=r,new Error("Timeout");r=new Uint8Array(this._appendBuffer(r.buffer,t.buffer))}while(r.length<e)}finally{t>0&&clearTimeout(i),a.releaseLock()}return this.slip_reader_enabled?this.slip_reader(r):r}async rawRead(t=0){if(0!=this.left_over.length){const t=this.left_over;return this.left_over=new Uint8Array(0),t}if(!this.device.readable)return this.left_over;const e=this.device.readable.getReader();let i;try{t>0&&(i=setTimeout((function(){e.cancel()}),t));const{value:r,done:a}=await e.read();if(a)throw new Error("Timeout");return r}finally{t>0&&clearTimeout(i),e.releaseLock()}}async setRTS(t){await this.device.setSignals({requestToSend:t}),await this.setDTR(this._DTR_state)}async setDTR(t){this._DTR_state=t,await this.device.setSignals({dataTerminalReady:t})}async connect(t=115200){await this.device.open({baudRate:t}),this.baudrate=t,this.left_over=new Uint8Array(0)}async sleep(t){return new Promise((e=>setTimeout(e,t)))}async waitForUnlock(t){for(;this.device.readable&&this.device.readable.locked||this.device.writable&&this.device.writable.locked;)await this.sleep(t)}async disconnect(){await this.waitForUnlock(400),await this.device.close()}}const Mi=t=>{const e=new Li(t);return new Di(e,115200,void 0)};export{Mi as c,f as o};
