locar-tiler 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -153,19 +153,19 @@ export declare interface LineString {
153
153
  }
154
154
 
155
155
  /** Represents a longitude/latitude.
156
- * @property {number} lon - the longitude.
157
- * @property {number} lat -the latitude.
156
+ * @property {number} longitude - the longitude.
157
+ * @property {number} latitude -the latitude.
158
158
  */
159
159
  export declare class LonLat {
160
- lon: number;
161
- lat: number;
160
+ longitude: number;
161
+ latitude: number;
162
162
  /**
163
163
  * Creates a LonLat.
164
164
  * @class
165
- * @param {number} lon - the longitude.
166
- * @param {number} lat - the latitude.
165
+ * @param {number} longitude - the longitude.
166
+ * @param {number} latitude - the latitude.
167
167
  */
168
- constructor(lon: any, lat: any);
168
+ constructor(longitude: any, latitude: any);
169
169
  /**
170
170
  * Returns a string representation of the LonLat.
171
171
  * @return {string} the string representation.
@@ -57,7 +57,7 @@ class Se {
57
57
  * @return {EastNorth} the Spherical Mercator coordinates.
58
58
  */
59
59
  project(e) {
60
- return { e: this.#e(e.lon), n: this.#t(e.lat) };
60
+ return { e: this.#e(e.longitude), n: this.#t(e.latitude) };
61
61
  }
62
62
  /**
63
63
  * Unproject Spherical Mercator into longitude/latitude.
@@ -65,7 +65,7 @@ class Se {
65
65
  * @return {LonLat} the longitude/latitude.
66
66
  */
67
67
  unproject(e) {
68
- return { lon: this.#n(e[0]), lat: this.#i(e[1]) };
68
+ return { longitude: this.#n(e[0]), latitude: this.#i(e[1]) };
69
69
  }
70
70
  #e(e) {
71
71
  return e / 180 * N.HALF_EARTH;
@@ -2556,23 +2556,23 @@ class Tn {
2556
2556
  }
2557
2557
  }
2558
2558
  class ee {
2559
- lon;
2560
- lat;
2559
+ longitude;
2560
+ latitude;
2561
2561
  /**
2562
2562
  * Creates a LonLat.
2563
2563
  * @class
2564
- * @param {number} lon - the longitude.
2565
- * @param {number} lat - the latitude.
2564
+ * @param {number} longitude - the longitude.
2565
+ * @param {number} latitude - the latitude.
2566
2566
  */
2567
2567
  constructor(e, t) {
2568
- this.lon = e, this.lat = t;
2568
+ this.longitude = e, this.latitude = t;
2569
2569
  }
2570
2570
  /**
2571
2571
  * Returns a string representation of the LonLat.
2572
2572
  * @return {string} the string representation.
2573
2573
  */
2574
2574
  toString() {
2575
- return `lon: ${this.lon}, lat: ${this.lat}`;
2575
+ return `longitude: ${this.longitude}, latitude: ${this.latitude}`;
2576
2576
  }
2577
2577
  }
2578
2578
  class mn {
@@ -1 +1 @@
1
- (function(I,O){typeof exports=="object"&&typeof module<"u"?O(exports):typeof define=="function"&&define.amd?define(["exports"],O):(I=typeof globalThis<"u"?globalThis:I||self,O(I["locar-tiler"]={}))})(this,(function(I){"use strict";class O{static EARTH=4007501668e-2;static HALF_EARTH=2003750834e-2}class Z{x;y;z;constructor(e,t,n){this.x=e,this.y=t,this.z=n}getMetresInTile(){return O.EARTH/Math.pow(2,this.z)}getBottomLeft(){var e=this.getMetresInTile();return{e:this.x*e-O.HALF_EARTH,n:O.HALF_EARTH-(this.y+1)*e}}getTopRight(){var e=this.getBottomLeft(),t=this.getMetresInTile();return e.e+=t,e.n+=t,e}getIndex(){return`${this.z}/${this.x}/${this.y}`}toString(){return this.getIndex()}}class yt{project(e){return{e:this.#e(e.lon),n:this.#t(e.lat)}}unproject(e){return{lon:this.#n(e[0]),lat:this.#i(e[1])}}#e(e){return e/180*O.HALF_EARTH}#t(e){var t=Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180);return t*O.HALF_EARTH/180}#n(e){return e/O.HALF_EARTH*180}#i(e){var t=e/O.HALF_EARTH*180;return t=180/Math.PI*(2*Math.atan(Math.exp(t*Math.PI/180))-Math.PI/2),t}getTile(e,t){var n=new Z(-1,-1,t),a=n.getMetresInTile();return n.x=Math.floor((O.HALF_EARTH+e.e)/a),n.y=Math.floor((O.HALF_EARTH-e.n)/a),n}getTileFromLonLat(e,t){return this.getTile(this.project(e),t)}getID(){return"epsg:3857"}}class it{tile;url;sphMerc;dataTiles;constructor(e){this.tile=new Z(0,0,13),this.url=e,this.sphMerc=new yt,this.dataTiles=new Map}setZoom(e){this.tile.z=e}lonLatToSphMerc(e){return this.sphMerc.project(e)}getTile(e,t){return this.sphMerc.getTile(e,t)}async update(e){const t=[];let n=null;if(n=this.#e(e)){this.tile=n;const a=[n.x,n.x-1,n.x+1],s=[n.y,n.y-1,n.y+1];for(let l=0;l<a.length;l++)for(let h=0;h<s.length;h++){const d=new Z(a[l],s[h],n.z),r=await this.#t(d);r!==null&&t.push({data:r.data,tile:d})}}return t}async updateByLonLat(e){return this.update(this.lonLatToSphMerc(e))}getCurrentTiles(){const e=[],t=[this.tile.x,this.tile.x-1,this.tile.x+1],n=[this.tile.y,this.tile.y-1,this.tile.y+1];for(let a=0;a<t.length;a++)for(let s=0;s<n.length;s++){const l=new Z(t[a],n[s],this.tile.z),h=this.dataTiles.get(l.getIndex());h!==null&&e.push({data:h,tile:l})}return e}#e(e){if(this.tile){const t=this.sphMerc.getTile(e,this.tile.z);return t.x!=this.tile.x||t.y!=this.tile.y?t:null}return null}async#t(e){const t=e.getIndex();if(this.dataTiles.get(t)===void 0){const n=await this.readTile(this.url.replace("{x}",e.x.toString()).replace("{y}",e.y.toString()).replace("{z}",e.z.toString()));return this.dataTiles.set(t,this.rawTileToStoredTile(e,n)),this.dataTiles.get(t)}return null}async getData(e,t=13){await this.update(e);const n=this.sphMerc.getTile(e,t);return this.dataTiles.get(`${t}/${n.x}/${n.y}`)}rawTileToStoredTile(e,t){return{tile:e,data:t}}}function kt(i,e="utf8"){return new TextDecoder(e).decode(i)}const Re=new TextEncoder;function Ce(i){return Re.encode(i)}const De=1024*8,Ne=(()=>{const i=new Uint8Array(4),e=new Uint32Array(i.buffer);return!((e[0]=1)&i[0])})(),nt={int8:globalThis.Int8Array,uint8:globalThis.Uint8Array,int16:globalThis.Int16Array,uint16:globalThis.Uint16Array,int32:globalThis.Int32Array,uint32:globalThis.Uint32Array,uint64:globalThis.BigUint64Array,int64:globalThis.BigInt64Array,float32:globalThis.Float32Array,float64:globalThis.Float64Array};class st{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(e=De,t={}){let n=!1;typeof e=="number"?e=new ArrayBuffer(e):(n=!0,this.lastWrittenByte=e.byteLength);const a=t.offset?t.offset>>>0:0,s=e.byteLength-a;let l=a;(ArrayBuffer.isView(e)||e instanceof st)&&(e.byteLength!==e.buffer.byteLength&&(l=e.byteOffset+a),e=e.buffer),n?this.lastWrittenByte=s:this.lastWrittenByte=0,this.buffer=e,this.length=s,this.byteLength=s,this.byteOffset=l,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,l,s),this._mark=0,this._marks=[]}available(e=1){return this.offset+e<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(e=1){return this.offset+=e,this}back(e=1){return this.offset-=e,this}seek(e){return this.offset=e,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const e=this._marks.pop();if(e===void 0)throw new Error("Mark stack empty");return this.seek(e),this}rewind(){return this.offset=0,this}ensureAvailable(e=1){if(!this.available(e)){const n=(this.offset+e)*2,a=new Uint8Array(n);a.set(new Uint8Array(this.buffer)),this.buffer=a.buffer,this.length=n,this.byteLength=n,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(e=1){return this.readArray(e,"uint8")}readArray(e,t){const n=nt[t].BYTES_PER_ELEMENT*e,a=this.byteOffset+this.offset,s=this.buffer.slice(a,a+n);if(this.littleEndian===Ne&&t!=="uint8"&&t!=="int8"){const h=new Uint8Array(this.buffer.slice(a,a+n));h.reverse();const d=new nt[t](h.buffer);return this.offset+=n,d.reverse(),d}const l=new nt[t](s);return this.offset+=n,l}readInt16(){const e=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}readUint16(){const e=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}readInt32(){const e=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}readUint32(){const e=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat32(){const e=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat64(){const e=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}readBigInt64(){const e=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,e}readBigUint64(){const e=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,e}readChar(){return String.fromCharCode(this.readInt8())}readChars(e=1){let t="";for(let n=0;n<e;n++)t+=this.readChar();return t}readUtf8(e=1){return kt(this.readBytes(e))}decodeText(e=1,t="utf8"){return kt(this.readBytes(e),t)}writeBoolean(e){return this.writeUint8(e?255:0),this}writeInt8(e){return this.ensureAvailable(1),this._data.setInt8(this.offset++,e),this._updateLastWrittenByte(),this}writeUint8(e){return this.ensureAvailable(1),this._data.setUint8(this.offset++,e),this._updateLastWrittenByte(),this}writeByte(e){return this.writeUint8(e)}writeBytes(e){this.ensureAvailable(e.length);for(let t=0;t<e.length;t++)this._data.setUint8(this.offset++,e[t]);return this._updateLastWrittenByte(),this}writeInt16(e){return this.ensureAvailable(2),this._data.setInt16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(e){return this.ensureAvailable(2),this._data.setUint16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(e){return this.ensureAvailable(4),this._data.setInt32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(e){return this.ensureAvailable(4),this._data.setUint32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(e){return this.ensureAvailable(4),this._data.setFloat32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(e){return this.ensureAvailable(8),this._data.setFloat64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(e){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(e){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(e){return this.writeUint8(e.charCodeAt(0))}writeChars(e){for(let t=0;t<e.length;t++)this.writeUint8(e.charCodeAt(t));return this}writeUtf8(e){return this.writeBytes(Ce(e))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}getWrittenByteLength(){return this.lastWrittenByte-this.byteOffset}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function F(i){let e=i.length;for(;--e>=0;)i[e]=0}const Me=3,Le=258,Et=29,Be=256+1+Et,At=30,$e=512,Fe=new Array((Be+2)*2);F(Fe);const He=new Array(At*2);F(He);const Ze=new Array($e);F(Ze);const We=new Array(Le-Me+1);F(We);const Pe=new Array(Et);F(Pe);const ze=new Array(At);F(ze);var at=(i,e,t,n)=>{let a=i&65535|0,s=i>>>16&65535|0,l=0;for(;t!==0;){l=t>2e3?2e3:t,t-=l;do a=a+e[n++]|0,s=s+a|0;while(--l);a%=65521,s%=65521}return a|s<<16|0};const Ge=()=>{let i,e=[];for(var t=0;t<256;t++){i=t;for(var n=0;n<8;n++)i=i&1?3988292384^i>>>1:i>>>1;e[t]=i}return e},je=new Uint32Array(Ge());var D=(i,e,t,n)=>{const a=je,s=n+t;i^=-1;for(let l=n;l<s;l++)i=i>>>8^a[(i^e[l])&255];return i^-1},rt={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"},Tt={Z_NO_FLUSH:0,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_DEFLATED:8};const Ke=(i,e)=>Object.prototype.hasOwnProperty.call(i,e);var Ye=function(i){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const t=e.shift();if(t){if(typeof t!="object")throw new TypeError(t+"must be non-object");for(const n in t)Ke(t,n)&&(i[n]=t[n])}}return i},Xe=i=>{let e=0;for(let n=0,a=i.length;n<a;n++)e+=i[n].length;const t=new Uint8Array(e);for(let n=0,a=0,s=i.length;n<s;n++){let l=i[n];t.set(l,a),a+=l.length}return t},mt={assign:Ye,flattenChunks:Xe};let vt=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{vt=!1}const W=new Uint8Array(256);for(let i=0;i<256;i++)W[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;W[254]=W[254]=1;var Ve=i=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(i);let e,t,n,a,s,l=i.length,h=0;for(a=0;a<l;a++)t=i.charCodeAt(a),(t&64512)===55296&&a+1<l&&(n=i.charCodeAt(a+1),(n&64512)===56320&&(t=65536+(t-55296<<10)+(n-56320),a++)),h+=t<128?1:t<2048?2:t<65536?3:4;for(e=new Uint8Array(h),s=0,a=0;s<h;a++)t=i.charCodeAt(a),(t&64512)===55296&&a+1<l&&(n=i.charCodeAt(a+1),(n&64512)===56320&&(t=65536+(t-55296<<10)+(n-56320),a++)),t<128?e[s++]=t:t<2048?(e[s++]=192|t>>>6,e[s++]=128|t&63):t<65536?(e[s++]=224|t>>>12,e[s++]=128|t>>>6&63,e[s++]=128|t&63):(e[s++]=240|t>>>18,e[s++]=128|t>>>12&63,e[s++]=128|t>>>6&63,e[s++]=128|t&63);return e};const qe=(i,e)=>{if(e<65534&&i.subarray&&vt)return String.fromCharCode.apply(null,i.length===e?i:i.subarray(0,e));let t="";for(let n=0;n<e;n++)t+=String.fromCharCode(i[n]);return t};var Je=(i,e)=>{const t=e||i.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(i.subarray(0,e));let n,a;const s=new Array(t*2);for(a=0,n=0;n<t;){let l=i[n++];if(l<128){s[a++]=l;continue}let h=W[l];if(h>4){s[a++]=65533,n+=h-1;continue}for(l&=h===2?31:h===3?15:7;h>1&&n<t;)l=l<<6|i[n++]&63,h--;if(h>1){s[a++]=65533;continue}l<65536?s[a++]=l:(l-=65536,s[a++]=55296|l>>10&1023,s[a++]=56320|l&1023)}return qe(s,a)},Qe=(i,e)=>{e=e||i.length,e>i.length&&(e=i.length);let t=e-1;for(;t>=0&&(i[t]&192)===128;)t--;return t<0||t===0?e:t+W[i[t]]>e?t:e},ot={string2buf:Ve,buf2string:Je,utf8border:Qe};function ti(){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}var ei=ti;const j=16209,ii=16191;var ni=function(e,t){let n,a,s,l,h,d,r,o,w,u,f,_,U,x,g,T,y,c,E,S,p,m,A,b;const k=e.state;n=e.next_in,A=e.input,a=n+(e.avail_in-5),s=e.next_out,b=e.output,l=s-(t-e.avail_out),h=s+(e.avail_out-257),d=k.dmax,r=k.wsize,o=k.whave,w=k.wnext,u=k.window,f=k.hold,_=k.bits,U=k.lencode,x=k.distcode,g=(1<<k.lenbits)-1,T=(1<<k.distbits)-1;t:do{_<15&&(f+=A[n++]<<_,_+=8,f+=A[n++]<<_,_+=8),y=U[f&g];e:for(;;){if(c=y>>>24,f>>>=c,_-=c,c=y>>>16&255,c===0)b[s++]=y&65535;else if(c&16){E=y&65535,c&=15,c&&(_<c&&(f+=A[n++]<<_,_+=8),E+=f&(1<<c)-1,f>>>=c,_-=c),_<15&&(f+=A[n++]<<_,_+=8,f+=A[n++]<<_,_+=8),y=x[f&T];i:for(;;){if(c=y>>>24,f>>>=c,_-=c,c=y>>>16&255,c&16){if(S=y&65535,c&=15,_<c&&(f+=A[n++]<<_,_+=8,_<c&&(f+=A[n++]<<_,_+=8)),S+=f&(1<<c)-1,S>d){e.msg="invalid distance too far back",k.mode=j;break t}if(f>>>=c,_-=c,c=s-l,S>c){if(c=S-c,c>o&&k.sane){e.msg="invalid distance too far back",k.mode=j;break t}if(p=0,m=u,w===0){if(p+=r-c,c<E){E-=c;do b[s++]=u[p++];while(--c);p=s-S,m=b}}else if(w<c){if(p+=r+w-c,c-=w,c<E){E-=c;do b[s++]=u[p++];while(--c);if(p=0,w<E){c=w,E-=c;do b[s++]=u[p++];while(--c);p=s-S,m=b}}}else if(p+=w-c,c<E){E-=c;do b[s++]=u[p++];while(--c);p=s-S,m=b}for(;E>2;)b[s++]=m[p++],b[s++]=m[p++],b[s++]=m[p++],E-=3;E&&(b[s++]=m[p++],E>1&&(b[s++]=m[p++]))}else{p=s-S;do b[s++]=b[p++],b[s++]=b[p++],b[s++]=b[p++],E-=3;while(E>2);E&&(b[s++]=b[p++],E>1&&(b[s++]=b[p++]))}}else if((c&64)===0){y=x[(y&65535)+(f&(1<<c)-1)];continue i}else{e.msg="invalid distance code",k.mode=j;break t}break}}else if((c&64)===0){y=U[(y&65535)+(f&(1<<c)-1)];continue e}else if(c&32){k.mode=ii;break t}else{e.msg="invalid literal/length code",k.mode=j;break t}break}}while(n<a&&s<h);E=_>>3,n-=E,_-=E<<3,f&=(1<<_)-1,e.next_in=n,e.next_out=s,e.avail_in=n<a?5+(a-n):5-(n-a),e.avail_out=s<h?257+(h-s):257-(s-h),k.hold=f,k.bits=_};const H=15,Ut=852,St=592,It=0,ht=1,Ot=2,si=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]),ai=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]),ri=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]),oi=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 P=(i,e,t,n,a,s,l,h)=>{const d=h.bits;let r=0,o=0,w=0,u=0,f=0,_=0,U=0,x=0,g=0,T=0,y,c,E,S,p,m=null,A;const b=new Uint16Array(H+1),k=new Uint16Array(H+1);let $=null,Oe,tt,et;for(r=0;r<=H;r++)b[r]=0;for(o=0;o<n;o++)b[e[t+o]]++;for(f=d,u=H;u>=1&&b[u]===0;u--);if(f>u&&(f=u),u===0)return a[s++]=1<<24|64<<16|0,a[s++]=1<<24|64<<16|0,h.bits=1,0;for(w=1;w<u&&b[w]===0;w++);for(f<w&&(f=w),x=1,r=1;r<=H;r++)if(x<<=1,x-=b[r],x<0)return-1;if(x>0&&(i===It||u!==1))return-1;for(k[1]=0,r=1;r<H;r++)k[r+1]=k[r]+b[r];for(o=0;o<n;o++)e[t+o]!==0&&(l[k[e[t+o]]++]=o);if(i===It?(m=$=l,A=20):i===ht?(m=si,$=ai,A=257):(m=ri,$=oi,A=0),T=0,o=0,r=w,p=s,_=f,U=0,E=-1,g=1<<f,S=g-1,i===ht&&g>Ut||i===Ot&&g>St)return 1;for(;;){Oe=r-U,l[o]+1<A?(tt=0,et=l[o]):l[o]>=A?(tt=$[l[o]-A],et=m[l[o]-A]):(tt=96,et=0),y=1<<r-U,c=1<<_,w=c;do c-=y,a[p+(T>>U)+c]=Oe<<24|tt<<16|et|0;while(c!==0);for(y=1<<r-1;T&y;)y>>=1;if(y!==0?(T&=y-1,T+=y):T=0,o++,--b[r]===0){if(r===u)break;r=e[t+l[o]]}if(r>f&&(T&S)!==E){for(U===0&&(U=f),p+=w,_=r-U,x=1<<_;_+U<u&&(x-=b[_+U],!(x<=0));)_++,x<<=1;if(g+=1<<_,i===ht&&g>Ut||i===Ot&&g>St)return 1;E=T&S,a[E]=f<<24|_<<16|p-s|0}}return T!==0&&(a[p+T]=r-U<<24|64<<16|0),h.bits=f,0};const hi=0,Rt=1,Ct=2,{Z_FINISH:Dt,Z_BLOCK:li,Z_TREES:K,Z_OK:L,Z_STREAM_END:fi,Z_NEED_DICT:ci,Z_STREAM_ERROR:C,Z_DATA_ERROR:Nt,Z_MEM_ERROR:Mt,Z_BUF_ERROR:di,Z_DEFLATED:Lt}=Tt,Y=16180,Bt=16181,$t=16182,Ft=16183,Ht=16184,Zt=16185,Wt=16186,Pt=16187,zt=16188,Gt=16189,X=16190,N=16191,lt=16192,jt=16193,ft=16194,Kt=16195,Yt=16196,Xt=16197,Vt=16198,V=16199,q=16200,qt=16201,Jt=16202,Qt=16203,te=16204,ee=16205,ct=16206,ie=16207,ne=16208,v=16209,se=16210,ae=16211,ui=852,_i=592,pi=15,re=i=>(i>>>24&255)+(i>>>8&65280)+((i&65280)<<8)+((i&255)<<24);function wi(){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 B=i=>{if(!i)return 1;const e=i.state;return!e||e.strm!==i||e.mode<Y||e.mode>ae?1:0},oe=i=>{if(B(i))return C;const e=i.state;return i.total_in=i.total_out=e.total=0,i.msg="",e.wrap&&(i.adler=e.wrap&1),e.mode=Y,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(ui),e.distcode=e.distdyn=new Int32Array(_i),e.sane=1,e.back=-1,L},he=i=>{if(B(i))return C;const e=i.state;return e.wsize=0,e.whave=0,e.wnext=0,oe(i)},le=(i,e)=>{let t;if(B(i))return C;const n=i.state;return e<0?(t=0,e=-e):(t=(e>>4)+5,e<48&&(e&=15)),e&&(e<8||e>15)?C:(n.window!==null&&n.wbits!==e&&(n.window=null),n.wrap=t,n.wbits=e,he(i))},fe=(i,e)=>{if(!i)return C;const t=new wi;i.state=t,t.strm=i,t.window=null,t.mode=Y;const n=le(i,e);return n!==L&&(i.state=null),n},gi=i=>fe(i,pi);let ce=!0,dt,ut;const bi=i=>{if(ce){dt=new Int32Array(512),ut=new Int32Array(32);let e=0;for(;e<144;)i.lens[e++]=8;for(;e<256;)i.lens[e++]=9;for(;e<280;)i.lens[e++]=7;for(;e<288;)i.lens[e++]=8;for(P(Rt,i.lens,0,288,dt,0,i.work,{bits:9}),e=0;e<32;)i.lens[e++]=5;P(Ct,i.lens,0,32,ut,0,i.work,{bits:5}),ce=!1}i.lencode=dt,i.lenbits=9,i.distcode=ut,i.distbits=5},de=(i,e,t,n)=>{let a;const s=i.state;return s.window===null&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),n>=s.wsize?(s.window.set(e.subarray(t-s.wsize,t),0),s.wnext=0,s.whave=s.wsize):(a=s.wsize-s.wnext,a>n&&(a=n),s.window.set(e.subarray(t-n,t-n+a),s.wnext),n-=a,n?(s.window.set(e.subarray(t-n,t),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=a,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=a))),0},xi=(i,e)=>{let t,n,a,s,l,h,d,r,o,w,u,f,_,U,x=0,g,T,y,c,E,S,p,m;const A=new Uint8Array(4);let b,k;const $=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(B(i)||!i.output||!i.input&&i.avail_in!==0)return C;t=i.state,t.mode===N&&(t.mode=lt),l=i.next_out,a=i.output,d=i.avail_out,s=i.next_in,n=i.input,h=i.avail_in,r=t.hold,o=t.bits,w=h,u=d,m=L;t:for(;;)switch(t.mode){case Y:if(t.wrap===0){t.mode=lt;break}for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.wrap&2&&r===35615){t.wbits===0&&(t.wbits=15),t.check=0,A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0),r=0,o=0,t.mode=Bt;break}if(t.head&&(t.head.done=!1),!(t.wrap&1)||(((r&255)<<8)+(r>>8))%31){i.msg="incorrect header check",t.mode=v;break}if((r&15)!==Lt){i.msg="unknown compression method",t.mode=v;break}if(r>>>=4,o-=4,p=(r&15)+8,t.wbits===0&&(t.wbits=p),p>15||p>t.wbits){i.msg="invalid window size",t.mode=v;break}t.dmax=1<<t.wbits,t.flags=0,i.adler=t.check=1,t.mode=r&512?Gt:N,r=0,o=0;break;case Bt:for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.flags=r,(t.flags&255)!==Lt){i.msg="unknown compression method",t.mode=v;break}if(t.flags&57344){i.msg="unknown header flags set",t.mode=v;break}t.head&&(t.head.text=r>>8&1),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0)),r=0,o=0,t.mode=$t;case $t:for(;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.head&&(t.head.time=r),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,A[2]=r>>>16&255,A[3]=r>>>24&255,t.check=D(t.check,A,4,0)),r=0,o=0,t.mode=Ft;case Ft:for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.head&&(t.head.xflags=r&255,t.head.os=r>>8),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0)),r=0,o=0,t.mode=Ht;case Ht:if(t.flags&1024){for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.length=r,t.head&&(t.head.extra_len=r),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0)),r=0,o=0}else t.head&&(t.head.extra=null);t.mode=Zt;case Zt:if(t.flags&1024&&(f=t.length,f>h&&(f=h),f&&(t.head&&(p=t.head.extra_len-t.length,t.head.extra||(t.head.extra=new Uint8Array(t.head.extra_len)),t.head.extra.set(n.subarray(s,s+f),p)),t.flags&512&&t.wrap&4&&(t.check=D(t.check,n,f,s)),h-=f,s+=f,t.length-=f),t.length))break t;t.length=0,t.mode=Wt;case Wt:if(t.flags&2048){if(h===0)break t;f=0;do p=n[s+f++],t.head&&p&&t.length<65536&&(t.head.name+=String.fromCharCode(p));while(p&&f<h);if(t.flags&512&&t.wrap&4&&(t.check=D(t.check,n,f,s)),h-=f,s+=f,p)break t}else t.head&&(t.head.name=null);t.length=0,t.mode=Pt;case Pt:if(t.flags&4096){if(h===0)break t;f=0;do p=n[s+f++],t.head&&p&&t.length<65536&&(t.head.comment+=String.fromCharCode(p));while(p&&f<h);if(t.flags&512&&t.wrap&4&&(t.check=D(t.check,n,f,s)),h-=f,s+=f,p)break t}else t.head&&(t.head.comment=null);t.mode=zt;case zt:if(t.flags&512){for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.wrap&4&&r!==(t.check&65535)){i.msg="header crc mismatch",t.mode=v;break}r=0,o=0}t.head&&(t.head.hcrc=t.flags>>9&1,t.head.done=!0),i.adler=t.check=0,t.mode=N;break;case Gt:for(;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}i.adler=t.check=re(r),r=0,o=0,t.mode=X;case X:if(t.havedict===0)return i.next_out=l,i.avail_out=d,i.next_in=s,i.avail_in=h,t.hold=r,t.bits=o,ci;i.adler=t.check=1,t.mode=N;case N:if(e===li||e===K)break t;case lt:if(t.last){r>>>=o&7,o-=o&7,t.mode=ct;break}for(;o<3;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}switch(t.last=r&1,r>>>=1,o-=1,r&3){case 0:t.mode=jt;break;case 1:if(bi(t),t.mode=V,e===K){r>>>=2,o-=2;break t}break;case 2:t.mode=Yt;break;case 3:i.msg="invalid block type",t.mode=v}r>>>=2,o-=2;break;case jt:for(r>>>=o&7,o-=o&7;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if((r&65535)!==(r>>>16^65535)){i.msg="invalid stored block lengths",t.mode=v;break}if(t.length=r&65535,r=0,o=0,t.mode=ft,e===K)break t;case ft:t.mode=Kt;case Kt:if(f=t.length,f){if(f>h&&(f=h),f>d&&(f=d),f===0)break t;a.set(n.subarray(s,s+f),l),h-=f,s+=f,d-=f,l+=f,t.length-=f;break}t.mode=N;break;case Yt:for(;o<14;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.nlen=(r&31)+257,r>>>=5,o-=5,t.ndist=(r&31)+1,r>>>=5,o-=5,t.ncode=(r&15)+4,r>>>=4,o-=4,t.nlen>286||t.ndist>30){i.msg="too many length or distance symbols",t.mode=v;break}t.have=0,t.mode=Xt;case Xt:for(;t.have<t.ncode;){for(;o<3;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.lens[$[t.have++]]=r&7,r>>>=3,o-=3}for(;t.have<19;)t.lens[$[t.have++]]=0;if(t.lencode=t.lendyn,t.lenbits=7,b={bits:t.lenbits},m=P(hi,t.lens,0,19,t.lencode,0,t.work,b),t.lenbits=b.bits,m){i.msg="invalid code lengths set",t.mode=v;break}t.have=0,t.mode=Vt;case Vt:for(;t.have<t.nlen+t.ndist;){for(;x=t.lencode[r&(1<<t.lenbits)-1],g=x>>>24,T=x>>>16&255,y=x&65535,!(g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(y<16)r>>>=g,o-=g,t.lens[t.have++]=y;else{if(y===16){for(k=g+2;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(r>>>=g,o-=g,t.have===0){i.msg="invalid bit length repeat",t.mode=v;break}p=t.lens[t.have-1],f=3+(r&3),r>>>=2,o-=2}else if(y===17){for(k=g+3;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=g,o-=g,p=0,f=3+(r&7),r>>>=3,o-=3}else{for(k=g+7;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=g,o-=g,p=0,f=11+(r&127),r>>>=7,o-=7}if(t.have+f>t.nlen+t.ndist){i.msg="invalid bit length repeat",t.mode=v;break}for(;f--;)t.lens[t.have++]=p}}if(t.mode===v)break;if(t.lens[256]===0){i.msg="invalid code -- missing end-of-block",t.mode=v;break}if(t.lenbits=9,b={bits:t.lenbits},m=P(Rt,t.lens,0,t.nlen,t.lencode,0,t.work,b),t.lenbits=b.bits,m){i.msg="invalid literal/lengths set",t.mode=v;break}if(t.distbits=6,t.distcode=t.distdyn,b={bits:t.distbits},m=P(Ct,t.lens,t.nlen,t.ndist,t.distcode,0,t.work,b),t.distbits=b.bits,m){i.msg="invalid distances set",t.mode=v;break}if(t.mode=V,e===K)break t;case V:t.mode=q;case q:if(h>=6&&d>=258){i.next_out=l,i.avail_out=d,i.next_in=s,i.avail_in=h,t.hold=r,t.bits=o,ni(i,u),l=i.next_out,a=i.output,d=i.avail_out,s=i.next_in,n=i.input,h=i.avail_in,r=t.hold,o=t.bits,t.mode===N&&(t.back=-1);break}for(t.back=0;x=t.lencode[r&(1<<t.lenbits)-1],g=x>>>24,T=x>>>16&255,y=x&65535,!(g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(T&&(T&240)===0){for(c=g,E=T,S=y;x=t.lencode[S+((r&(1<<c+E)-1)>>c)],g=x>>>24,T=x>>>16&255,y=x&65535,!(c+g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=c,o-=c,t.back+=c}if(r>>>=g,o-=g,t.back+=g,t.length=y,T===0){t.mode=ee;break}if(T&32){t.back=-1,t.mode=N;break}if(T&64){i.msg="invalid literal/length code",t.mode=v;break}t.extra=T&15,t.mode=qt;case qt:if(t.extra){for(k=t.extra;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.length+=r&(1<<t.extra)-1,r>>>=t.extra,o-=t.extra,t.back+=t.extra}t.was=t.length,t.mode=Jt;case Jt:for(;x=t.distcode[r&(1<<t.distbits)-1],g=x>>>24,T=x>>>16&255,y=x&65535,!(g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if((T&240)===0){for(c=g,E=T,S=y;x=t.distcode[S+((r&(1<<c+E)-1)>>c)],g=x>>>24,T=x>>>16&255,y=x&65535,!(c+g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=c,o-=c,t.back+=c}if(r>>>=g,o-=g,t.back+=g,T&64){i.msg="invalid distance code",t.mode=v;break}t.offset=y,t.extra=T&15,t.mode=Qt;case Qt:if(t.extra){for(k=t.extra;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.offset+=r&(1<<t.extra)-1,r>>>=t.extra,o-=t.extra,t.back+=t.extra}if(t.offset>t.dmax){i.msg="invalid distance too far back",t.mode=v;break}t.mode=te;case te:if(d===0)break t;if(f=u-d,t.offset>f){if(f=t.offset-f,f>t.whave&&t.sane){i.msg="invalid distance too far back",t.mode=v;break}f>t.wnext?(f-=t.wnext,_=t.wsize-f):_=t.wnext-f,f>t.length&&(f=t.length),U=t.window}else U=a,_=l-t.offset,f=t.length;f>d&&(f=d),d-=f,t.length-=f;do a[l++]=U[_++];while(--f);t.length===0&&(t.mode=q);break;case ee:if(d===0)break t;a[l++]=t.length,d--,t.mode=q;break;case ct:if(t.wrap){for(;o<32;){if(h===0)break t;h--,r|=n[s++]<<o,o+=8}if(u-=d,i.total_out+=u,t.total+=u,t.wrap&4&&u&&(i.adler=t.check=t.flags?D(t.check,a,u,l-u):at(t.check,a,u,l-u)),u=d,t.wrap&4&&(t.flags?r:re(r))!==t.check){i.msg="incorrect data check",t.mode=v;break}r=0,o=0}t.mode=ie;case ie:if(t.wrap&&t.flags){for(;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.wrap&4&&r!==(t.total&4294967295)){i.msg="incorrect length check",t.mode=v;break}r=0,o=0}t.mode=ne;case ne:m=fi;break t;case v:m=Nt;break t;case se:return Mt;case ae:default:return C}return i.next_out=l,i.avail_out=d,i.next_in=s,i.avail_in=h,t.hold=r,t.bits=o,(t.wsize||u!==i.avail_out&&t.mode<v&&(t.mode<ct||e!==Dt))&&de(i,i.output,i.next_out,u-i.avail_out),w-=i.avail_in,u-=i.avail_out,i.total_in+=w,i.total_out+=u,t.total+=u,t.wrap&4&&u&&(i.adler=t.check=t.flags?D(t.check,a,u,i.next_out-u):at(t.check,a,u,i.next_out-u)),i.data_type=t.bits+(t.last?64:0)+(t.mode===N?128:0)+(t.mode===V||t.mode===ft?256:0),(w===0&&u===0||e===Dt)&&m===L&&(m=di),m},yi=i=>{if(B(i))return C;let e=i.state;return e.window&&(e.window=null),i.state=null,L},ki=(i,e)=>{if(B(i))return C;const t=i.state;return(t.wrap&2)===0?C:(t.head=e,e.done=!1,L)},Ei=(i,e)=>{const t=e.length;let n,a,s;return B(i)||(n=i.state,n.wrap!==0&&n.mode!==X)?C:n.mode===X&&(a=1,a=at(a,e,t,0),a!==n.check)?Nt:(s=de(i,e,t,t),s?(n.mode=se,Mt):(n.havedict=1,L))};var Ai=he,Ti=le,mi=oe,vi=gi,Ui=fe,Si=xi,Ii=yi,Oi=ki,Ri=Ei,Ci="pako inflate (from Nodeca project)",M={inflateReset:Ai,inflateReset2:Ti,inflateResetKeep:mi,inflateInit:vi,inflateInit2:Ui,inflate:Si,inflateEnd:Ii,inflateGetHeader:Oi,inflateSetDictionary:Ri,inflateInfo:Ci};function Di(){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}var Ni=Di;const ue=Object.prototype.toString,{Z_NO_FLUSH:Mi,Z_FINISH:Li,Z_OK:z,Z_STREAM_END:_t,Z_NEED_DICT:pt,Z_STREAM_ERROR:Bi,Z_DATA_ERROR:_e,Z_MEM_ERROR:$i}=Tt;function G(i){this.options=mt.assign({chunkSize:1024*64,windowBits:15,to:""},i||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(i&&i.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15)===0&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new ei,this.strm.avail_out=0;let t=M.inflateInit2(this.strm,e.windowBits);if(t!==z)throw new Error(rt[t]);if(this.header=new Ni,M.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=ot.string2buf(e.dictionary):ue.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(t=M.inflateSetDictionary(this.strm,e.dictionary),t!==z)))throw new Error(rt[t])}G.prototype.push=function(i,e){const t=this.strm,n=this.options.chunkSize,a=this.options.dictionary;let s,l,h;if(this.ended)return!1;for(e===~~e?l=e:l=e===!0?Li:Mi,ue.call(i)==="[object ArrayBuffer]"?t.input=new Uint8Array(i):t.input=i,t.next_in=0,t.avail_in=t.input.length;;){for(t.avail_out===0&&(t.output=new Uint8Array(n),t.next_out=0,t.avail_out=n),s=M.inflate(t,l),s===pt&&a&&(s=M.inflateSetDictionary(t,a),s===z?s=M.inflate(t,l):s===_e&&(s=pt));t.avail_in>0&&s===_t&&t.state.wrap>0&&i[t.next_in]!==0;)M.inflateReset(t),s=M.inflate(t,l);switch(s){case Bi:case _e:case pt:case $i:return this.onEnd(s),this.ended=!0,!1}if(h=t.avail_out,t.next_out&&(t.avail_out===0||s===_t))if(this.options.to==="string"){let d=ot.utf8border(t.output,t.next_out),r=t.next_out-d,o=ot.buf2string(t.output,d);t.next_out=r,t.avail_out=n-r,r&&t.output.set(t.output.subarray(d,d+r),0),this.onData(o)}else this.onData(t.output.length===t.next_out?t.output:t.output.subarray(0,t.next_out));if(!(s===z&&h===0)){if(s===_t)return s=M.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(t.avail_in===0)break}}return!0},G.prototype.onData=function(i){this.chunks.push(i)},G.prototype.onEnd=function(i){i===z&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=mt.flattenChunks(this.chunks)),this.chunks=[],this.err=i,this.msg=this.strm.msg};function Fi(i,e){const t=new G(e);if(t.push(i),t.err)throw t.msg||rt[t.err];return t.result}var Hi=G,Zi=Fi,Wi={Inflate:Hi,inflate:Zi};const{Inflate:Pi,inflate:zi}=Wi;var pe=Pi,Gi=zi;const we=[];for(let i=0;i<256;i++){let e=i;for(let t=0;t<8;t++)e&1?e=3988292384^e>>>1:e=e>>>1;we[i]=e}const ge=4294967295;function ji(i,e,t){let n=i;for(let a=0;a<t;a++)n=we[(n^e[a])&255]^n>>>8;return n}function Ki(i,e){return(ji(ge,i,e)^ge)>>>0}function be(i,e,t){const n=i.readUint32(),a=Ki(new Uint8Array(i.buffer,i.byteOffset+i.offset-e-4,e),e);if(a!==n)throw new Error(`CRC mismatch for chunk ${t}. Expected ${n}, found ${a}`)}function xe(i,e,t){for(let n=0;n<t;n++)e[n]=i[n]}function ye(i,e,t,n){let a=0;for(;a<n;a++)e[a]=i[a];for(;a<t;a++)e[a]=i[a]+e[a-n]&255}function ke(i,e,t,n){let a=0;if(t.length===0)for(;a<n;a++)e[a]=i[a];else for(;a<n;a++)e[a]=i[a]+t[a]&255}function Ee(i,e,t,n,a){let s=0;if(t.length===0){for(;s<a;s++)e[s]=i[s];for(;s<n;s++)e[s]=i[s]+(e[s-a]>>1)&255}else{for(;s<a;s++)e[s]=i[s]+(t[s]>>1)&255;for(;s<n;s++)e[s]=i[s]+(e[s-a]+t[s]>>1)&255}}function Ae(i,e,t,n,a){let s=0;if(t.length===0){for(;s<a;s++)e[s]=i[s];for(;s<n;s++)e[s]=i[s]+e[s-a]&255}else{for(;s<a;s++)e[s]=i[s]+t[s]&255;for(;s<n;s++)e[s]=i[s]+Yi(e[s-a],t[s],t[s-a])&255}}function Yi(i,e,t){const n=i+e-t,a=Math.abs(n-i),s=Math.abs(n-e),l=Math.abs(n-t);return a<=s&&a<=l?i:s<=l?e:t}function Xi(i,e,t,n,a,s){switch(i){case 0:xe(e,t,a);break;case 1:ye(e,t,a,s);break;case 2:ke(e,t,n,a);break;case 3:Ee(e,t,n,a,s);break;case 4:Ae(e,t,n,a,s);break;default:throw new Error(`Unsupported filter: ${i}`)}}const Vi=new Uint16Array([255]),qi=new Uint8Array(Vi.buffer)[0]===255;function Ji(i){const{data:e,width:t,height:n,channels:a,depth:s}=i,l=[{x:0,y:0,xStep:8,yStep:8},{x:4,y:0,xStep:8,yStep:8},{x:0,y:4,xStep:4,yStep:8},{x:2,y:0,xStep:4,yStep:4},{x:0,y:2,xStep:2,yStep:4},{x:1,y:0,xStep:2,yStep:2},{x:0,y:1,xStep:1,yStep:2}],h=Math.ceil(s/8)*a,d=new Uint8Array(n*t*h);let r=0;for(let o=0;o<7;o++){const w=l[o],u=Math.ceil((t-w.x)/w.xStep),f=Math.ceil((n-w.y)/w.yStep);if(u<=0||f<=0)continue;const _=u*h,U=new Uint8Array(_);for(let x=0;x<f;x++){const g=e[r++],T=e.subarray(r,r+_);r+=_;const y=new Uint8Array(_);Xi(g,T,y,U,_,h),U.set(y);for(let c=0;c<u;c++){const E=w.x+c*w.xStep,S=w.y+x*w.yStep;if(!(E>=t||S>=n))for(let p=0;p<h;p++)d[(S*t+E)*h+p]=y[c*h+p]}}}if(s===16){const o=new Uint16Array(d.buffer);if(qi)for(let w=0;w<o.length;w++)o[w]=Qi(o[w]);return o}else return d}function Qi(i){return(i&255)<<8|i>>8&255}const tn=new Uint16Array([255]),en=new Uint8Array(tn.buffer)[0]===255,nn=new Uint8Array(0);function Te(i){const{data:e,width:t,height:n,channels:a,depth:s}=i,l=Math.ceil(s/8)*a,h=Math.ceil(s/8*a*t),d=new Uint8Array(n*h);let r=nn,o=0,w,u;for(let f=0;f<n;f++){switch(w=e.subarray(o+1,o+1+h),u=d.subarray(f*h,(f+1)*h),e[o]){case 0:xe(w,u,h);break;case 1:ye(w,u,h,l);break;case 2:ke(w,u,r,h);break;case 3:Ee(w,u,r,h,l);break;case 4:Ae(w,u,r,h,l);break;default:throw new Error(`Unsupported filter: ${e[o]}`)}r=u,o+=h+1}if(s===16){const f=new Uint16Array(d.buffer);if(en)for(let _=0;_<f.length;_++)f[_]=sn(f[_]);return f}else return d}function sn(i){return(i&255)<<8|i>>8&255}const J=Uint8Array.of(137,80,78,71,13,10,26,10);function me(i){if(!an(i.readBytes(J.length)))throw new Error("wrong PNG signature")}function an(i){if(i.length<J.length)return!1;for(let e=0;e<J.length;e++)if(i[e]!==J[e])return!1;return!0}const rn="tEXt",on=0,ve=new TextDecoder("latin1");function hn(i){if(fn(i),i.length===0||i.length>79)throw new Error("keyword length must be between 1 and 79")}const ln=/^[\u0000-\u00FF]*$/;function fn(i){if(!ln.test(i))throw new Error("invalid latin1 text")}function cn(i,e,t){const n=Ue(e);i[n]=dn(e,t-n.length-1)}function Ue(i){for(i.mark();i.readByte()!==on;);const e=i.offset;i.reset();const t=ve.decode(i.readBytes(e-i.offset-1));return i.skip(1),hn(t),t}function dn(i,e){return ve.decode(i.readBytes(e))}const R={UNKNOWN:-1,GREYSCALE:0,TRUECOLOUR:2,INDEXED_COLOUR:3,GREYSCALE_ALPHA:4,TRUECOLOUR_ALPHA:6},wt={UNKNOWN:-1,DEFLATE:0},Se={UNKNOWN:-1,ADAPTIVE:0},gt={UNKNOWN:-1,NO_INTERLACE:0,ADAM7:1},Q={NONE:0,BACKGROUND:1,PREVIOUS:2},bt={SOURCE:0,OVER:1};class un extends st{_checkCrc;_inflator;_png;_apng;_end;_hasPalette;_palette;_hasTransparency;_transparency;_compressionMethod;_filterMethod;_interlaceMethod;_colorType;_isAnimated;_numberOfFrames;_numberOfPlays;_frames;_writingDataChunks;constructor(e,t={}){super(e);const{checkCrc:n=!1}=t;this._checkCrc=n,this._inflator=new pe,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._apng={width:-1,height:-1,channels:-1,depth:1,numberOfFrames:1,numberOfPlays:0,text:{},frames:[]},this._end=!1,this._hasPalette=!1,this._palette=[],this._hasTransparency=!1,this._transparency=new Uint16Array(0),this._compressionMethod=wt.UNKNOWN,this._filterMethod=Se.UNKNOWN,this._interlaceMethod=gt.UNKNOWN,this._colorType=R.UNKNOWN,this._isAnimated=!1,this._numberOfFrames=1,this._numberOfPlays=0,this._frames=[],this._writingDataChunks=!1,this.setBigEndian()}decode(){for(me(this);!this._end;){const e=this.readUint32(),t=this.readChars(4);this.decodeChunk(e,t)}return this.decodeImage(),this._png}decodeApng(){for(me(this);!this._end;){const e=this.readUint32(),t=this.readChars(4);this.decodeApngChunk(e,t)}return this.decodeApngImage(),this._apng}decodeChunk(e,t){const n=this.offset;switch(t){case"IHDR":this.decodeIHDR();break;case"PLTE":this.decodePLTE(e);break;case"IDAT":this.decodeIDAT(e);break;case"IEND":this._end=!0;break;case"tRNS":this.decodetRNS(e);break;case"iCCP":this.decodeiCCP(e);break;case rn:cn(this._png.text,this,e);break;case"pHYs":this.decodepHYs();break;default:this.skip(e);break}if(this.offset-n!==e)throw new Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?be(this,e+4,t):this.skip(4)}decodeApngChunk(e,t){const n=this.offset;switch(t!=="fdAT"&&t!=="IDAT"&&this._writingDataChunks&&this.pushDataToFrame(),t){case"acTL":this.decodeACTL();break;case"fcTL":this.decodeFCTL();break;case"fdAT":this.decodeFDAT(e);break;default:this.decodeChunk(e,t),this.offset=n+e;break}if(this.offset-n!==e)throw new Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?be(this,e+4,t):this.skip(4)}decodeIHDR(){const e=this._png;e.width=this.readUint32(),e.height=this.readUint32(),e.depth=_n(this.readUint8());const t=this.readUint8();this._colorType=t;let n;switch(t){case R.GREYSCALE:n=1;break;case R.TRUECOLOUR:n=3;break;case R.INDEXED_COLOUR:n=1;break;case R.GREYSCALE_ALPHA:n=2;break;case R.TRUECOLOUR_ALPHA:n=4;break;case R.UNKNOWN:default:throw new Error(`Unknown color type: ${t}`)}if(this._png.channels=n,this._compressionMethod=this.readUint8(),this._compressionMethod!==wt.DEFLATE)throw new Error(`Unsupported compression method: ${this._compressionMethod}`);this._filterMethod=this.readUint8(),this._interlaceMethod=this.readUint8()}decodeACTL(){this._numberOfFrames=this.readUint32(),this._numberOfPlays=this.readUint32(),this._isAnimated=!0}decodeFCTL(){const e={sequenceNumber:this.readUint32(),width:this.readUint32(),height:this.readUint32(),xOffset:this.readUint32(),yOffset:this.readUint32(),delayNumber:this.readUint16(),delayDenominator:this.readUint16(),disposeOp:this.readUint8(),blendOp:this.readUint8(),data:new Uint8Array(0)};this._frames.push(e)}decodePLTE(e){if(e%3!==0)throw new RangeError(`PLTE field length must be a multiple of 3. Got ${e}`);const t=e/3;this._hasPalette=!0;const n=[];this._palette=n;for(let a=0;a<t;a++)n.push([this.readUint8(),this.readUint8(),this.readUint8()])}decodeIDAT(e){this._writingDataChunks=!0;const t=e,n=this.offset+this.byteOffset;if(this._inflator.push(new Uint8Array(this.buffer,n,t)),this._inflator.err)throw new Error(`Error while decompressing the data: ${this._inflator.err}`);this.skip(e)}decodeFDAT(e){this._writingDataChunks=!0;let t=e,n=this.offset+this.byteOffset;if(n+=4,t-=4,this._inflator.push(new Uint8Array(this.buffer,n,t)),this._inflator.err)throw new Error(`Error while decompressing the data: ${this._inflator.err}`);this.skip(e)}decodetRNS(e){switch(this._colorType){case R.GREYSCALE:case R.TRUECOLOUR:{if(e%2!==0)throw new RangeError(`tRNS chunk length must be a multiple of 2. Got ${e}`);if(e/2>this._png.width*this._png.height)throw new Error(`tRNS chunk contains more alpha values than there are pixels (${e/2} vs ${this._png.width*this._png.height})`);this._hasTransparency=!0,this._transparency=new Uint16Array(e/2);for(let t=0;t<e/2;t++)this._transparency[t]=this.readUint16();break}case R.INDEXED_COLOUR:{if(e>this._palette.length)throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${e} vs ${this._palette.length})`);let t=0;for(;t<e;t++){const n=this.readByte();this._palette[t].push(n)}for(;t<this._palette.length;t++)this._palette[t].push(255);break}case R.UNKNOWN:case R.GREYSCALE_ALPHA:case R.TRUECOLOUR_ALPHA:default:throw new Error(`tRNS chunk is not supported for color type ${this._colorType}`)}}decodeiCCP(e){const t=Ue(this),n=this.readUint8();if(n!==wt.DEFLATE)throw new Error(`Unsupported iCCP compression method: ${n}`);const a=this.readBytes(e-t.length-2);this._png.iccEmbeddedProfile={name:t,profile:Gi(a)}}decodepHYs(){const e=this.readUint32(),t=this.readUint32(),n=this.readByte();this._png.resolution={x:e,y:t,unit:n}}decodeApngImage(){this._apng.width=this._png.width,this._apng.height=this._png.height,this._apng.channels=this._png.channels,this._apng.depth=this._png.depth,this._apng.numberOfFrames=this._numberOfFrames,this._apng.numberOfPlays=this._numberOfPlays,this._apng.text=this._png.text,this._apng.resolution=this._png.resolution;for(let e=0;e<this._numberOfFrames;e++){const t={sequenceNumber:this._frames[e].sequenceNumber,delayNumber:this._frames[e].delayNumber,delayDenominator:this._frames[e].delayDenominator,data:this._apng.depth===8?new Uint8Array(this._apng.width*this._apng.height*this._apng.channels):new Uint16Array(this._apng.width*this._apng.height*this._apng.channels)},n=this._frames.at(e);if(n){if(n.data=Te({data:n.data,width:n.width,height:n.height,channels:this._apng.channels,depth:this._apng.depth}),this._hasPalette&&(this._apng.palette=this._palette),this._hasTransparency&&(this._apng.transparency=this._transparency),e===0||n.xOffset===0&&n.yOffset===0&&n.width===this._png.width&&n.height===this._png.height)t.data=n.data;else{const a=this._apng.frames.at(e-1);this.disposeFrame(n,a,t),this.addFrameDataToCanvas(t,n)}this._apng.frames.push(t)}}return this._apng}disposeFrame(e,t,n){switch(e.disposeOp){case Q.NONE:break;case Q.BACKGROUND:for(let a=0;a<this._png.height;a++)for(let s=0;s<this._png.width;s++){const l=(a*e.width+s)*this._png.channels;for(let h=0;h<this._png.channels;h++)n.data[l+h]=0}break;case Q.PREVIOUS:n.data.set(t.data);break;default:throw new Error("Unknown disposeOp")}}addFrameDataToCanvas(e,t){const n=1<<this._png.depth,a=(s,l)=>{const h=((s+t.yOffset)*this._png.width+t.xOffset+l)*this._png.channels,d=(s*t.width+l)*this._png.channels;return{index:h,frameIndex:d}};switch(t.blendOp){case bt.SOURCE:for(let s=0;s<t.height;s++)for(let l=0;l<t.width;l++){const{index:h,frameIndex:d}=a(s,l);for(let r=0;r<this._png.channels;r++)e.data[h+r]=t.data[d+r]}break;case bt.OVER:for(let s=0;s<t.height;s++)for(let l=0;l<t.width;l++){const{index:h,frameIndex:d}=a(s,l);for(let r=0;r<this._png.channels;r++){const o=t.data[d+this._png.channels-1]/n,w=r%(this._png.channels-1)===0?1:t.data[d+r],u=Math.floor(o*w+(1-o)*e.data[h+r]);e.data[h+r]+=u}}break;default:throw new Error("Unknown blendOp")}}decodeImage(){if(this._inflator.err)throw new Error(`Error while decompressing the data: ${this._inflator.err}`);const e=this._isAnimated?(this._frames?.at(0)).data:this._inflator.result;if(this._filterMethod!==Se.ADAPTIVE)throw new Error(`Filter method ${this._filterMethod} not supported`);if(this._interlaceMethod===gt.NO_INTERLACE)this._png.data=Te({data:e,width:this._png.width,height:this._png.height,channels:this._png.channels,depth:this._png.depth});else if(this._interlaceMethod===gt.ADAM7)this._png.data=Ji({data:e,width:this._png.width,height:this._png.height,channels:this._png.channels,depth:this._png.depth});else throw new Error(`Interlace method ${this._interlaceMethod} not supported`);this._hasPalette&&(this._png.palette=this._palette),this._hasTransparency&&(this._png.transparency=this._transparency)}pushDataToFrame(){const e=this._inflator.result,t=this._frames.at(-1);t?t.data=e:this._frames.push({sequenceNumber:0,width:this._png.width,height:this._png.height,xOffset:0,yOffset:0,delayNumber:0,delayDenominator:0,disposeOp:Q.NONE,blendOp:bt.SOURCE,data:e}),this._inflator=new pe,this._writingDataChunks=!1}}function _n(i){if(i!==1&&i!==2&&i!==4&&i!==8&&i!==16)throw new Error(`invalid bit depth: ${i}`);return i}function pn(i,e){return new un(i,e).decode()}class Ie{#e;#t;#n;#i;#s;elevs;constructor(e,t,n,a,s,l){this.#e=t,this.#t=n,this.#n=a,this.elevs=e,this.#i=s,this.#s=l}getElevation(e,t){let n=[e,t],a=Math.floor((n[0]-this.#e.e)/this.#i),s=this.#n-Math.ceil((n[1]-this.#e.n)/this.#s),l,h,d,r,o,w,u,f=null;if(a>=0&&s>=0&&a<this.#t-1&&s<this.#n-1){r=this.elevs[s*this.#t+a],o=this.elevs[s*this.#t+a+1],w=this.elevs[s*this.#t+a+this.#t],u=this.elevs[s*this.#t+a+this.#t+1],l=this.#e.e+a*this.#i,l+this.#i,h=this.#e.n+(this.#n-1-s)*this.#s,d=h-this.#s;let _=(n[0]-l)/this.#i,U=r*(1-_)+o*_,x=w*(1-_)+u*_,g=(n[1]-d)/this.#s;f=x*(1-g)+U*g}return f}}class wn extends it{constructor(e){super(e)}async readTile(e){const n=await(await fetch(e,{signal:AbortSignal.timeout(3e4)})).arrayBuffer(),a=pn(n);let s,l=0;const h=new Array(a.width*a.height);for(let d=0;d<a.height;d++)for(let r=0;r<a.width;r++)s=(d*a.width+r)*a.channels,h[l++]=Math.round(a.data[s]*256+a.data[s+1]+a.data[s+2]/256-32768);return{w:a.width,h:a.height,elevs:h}}getElevation(e){const t=this.getTile(e,this.tile.z),n=this.dataTiles.get(`${t.z}/${t.x}/${t.y}`);return n?n.data.getElevation(e.e,e.n):null}getElevationFromLonLat(e){return this.getElevation(this.sphMerc.project(e))}rawTileToStoredTile(e,t){const n=e.getTopRight(),a=e.getBottomLeft(),s=(n.e-a.e)/(t.w-1),l=(n.n-a.n)/(t.h-1),h=new Ie(t.elevs,a,t.w,t.h,s,l);return{tile:e,data:h}}}class gn extends it{constructor(e){super(e)}async readTile(e){return await(await fetch(e,{signal:AbortSignal.timeout(3e4)})).json()}}class bn{e;n;constructor(e,t){this.e=e,this.n=t}toString(){return`e: ${this.e}, n: ${this.n}`}}class xt{lon;lat;constructor(e,t){this.lon=e,this.lat=t}toString(){return`lon: ${this.lon}, lat: ${this.lat}`}}class xn{demTiler;jsonTiler;constructor(e,t){this.demTiler=e,this.jsonTiler=t}async updateByLonLat(e){const t=this.demTiler.sphMerc.project(e),n=await this.demTiler.update(t),a=await this.jsonTiler.update(t);return n.forEach((s,l)=>{this.#e(s,a[l])}),a}async#e(e,t){t.data.features.forEach((a,s)=>{switch(a.geometry.type){case"LineString":const l=a.geometry;l.coordinates.length>=2&&this.#t(e,l.coordinates);break;case"MultiLineString":const h=a.geometry;for(let o of h.coordinates)o.length>=2&&this.#t(e,o);break;case"Point":a.geometry;const d=this.demTiler.sphMerc.project(new xt(a.geometry.coordinates[0],a.geometry.coordinates[1])),r=e.data?e.data.getElevation(d.e,d.n):0;r>Number.NEGATIVE_INFINITY&&(a.geometry.coordinates[2]=r)}})}#t(e,t){t.forEach(n=>{const a=this.demTiler.sphMerc.project(new xt(n[0],n[1])),s=e.data?.getElevation(a.e,a.n)??0;s>Number.NEGATIVE_INFINITY&&(n[2]=s)})}}I.Constants=O,I.DEM=Ie,I.DemApplier=xn,I.DemTiler=wn,I.EastNorth=bn,I.JsonTiler=gn,I.LonLat=xt,I.SphMercProjection=yt,I.Tile=Z,I.Tiler=it,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(I,O){typeof exports=="object"&&typeof module<"u"?O(exports):typeof define=="function"&&define.amd?define(["exports"],O):(I=typeof globalThis<"u"?globalThis:I||self,O(I["locar-tiler"]={}))})(this,(function(I){"use strict";class O{static EARTH=4007501668e-2;static HALF_EARTH=2003750834e-2}class Z{x;y;z;constructor(e,t,n){this.x=e,this.y=t,this.z=n}getMetresInTile(){return O.EARTH/Math.pow(2,this.z)}getBottomLeft(){var e=this.getMetresInTile();return{e:this.x*e-O.HALF_EARTH,n:O.HALF_EARTH-(this.y+1)*e}}getTopRight(){var e=this.getBottomLeft(),t=this.getMetresInTile();return e.e+=t,e.n+=t,e}getIndex(){return`${this.z}/${this.x}/${this.y}`}toString(){return this.getIndex()}}class yt{project(e){return{e:this.#e(e.longitude),n:this.#t(e.latitude)}}unproject(e){return{longitude:this.#n(e[0]),latitude:this.#i(e[1])}}#e(e){return e/180*O.HALF_EARTH}#t(e){var t=Math.log(Math.tan((90+e)*Math.PI/360))/(Math.PI/180);return t*O.HALF_EARTH/180}#n(e){return e/O.HALF_EARTH*180}#i(e){var t=e/O.HALF_EARTH*180;return t=180/Math.PI*(2*Math.atan(Math.exp(t*Math.PI/180))-Math.PI/2),t}getTile(e,t){var n=new Z(-1,-1,t),a=n.getMetresInTile();return n.x=Math.floor((O.HALF_EARTH+e.e)/a),n.y=Math.floor((O.HALF_EARTH-e.n)/a),n}getTileFromLonLat(e,t){return this.getTile(this.project(e),t)}getID(){return"epsg:3857"}}class it{tile;url;sphMerc;dataTiles;constructor(e){this.tile=new Z(0,0,13),this.url=e,this.sphMerc=new yt,this.dataTiles=new Map}setZoom(e){this.tile.z=e}lonLatToSphMerc(e){return this.sphMerc.project(e)}getTile(e,t){return this.sphMerc.getTile(e,t)}async update(e){const t=[];let n=null;if(n=this.#e(e)){this.tile=n;const a=[n.x,n.x-1,n.x+1],s=[n.y,n.y-1,n.y+1];for(let l=0;l<a.length;l++)for(let h=0;h<s.length;h++){const d=new Z(a[l],s[h],n.z),r=await this.#t(d);r!==null&&t.push({data:r.data,tile:d})}}return t}async updateByLonLat(e){return this.update(this.lonLatToSphMerc(e))}getCurrentTiles(){const e=[],t=[this.tile.x,this.tile.x-1,this.tile.x+1],n=[this.tile.y,this.tile.y-1,this.tile.y+1];for(let a=0;a<t.length;a++)for(let s=0;s<n.length;s++){const l=new Z(t[a],n[s],this.tile.z),h=this.dataTiles.get(l.getIndex());h!==null&&e.push({data:h,tile:l})}return e}#e(e){if(this.tile){const t=this.sphMerc.getTile(e,this.tile.z);return t.x!=this.tile.x||t.y!=this.tile.y?t:null}return null}async#t(e){const t=e.getIndex();if(this.dataTiles.get(t)===void 0){const n=await this.readTile(this.url.replace("{x}",e.x.toString()).replace("{y}",e.y.toString()).replace("{z}",e.z.toString()));return this.dataTiles.set(t,this.rawTileToStoredTile(e,n)),this.dataTiles.get(t)}return null}async getData(e,t=13){await this.update(e);const n=this.sphMerc.getTile(e,t);return this.dataTiles.get(`${t}/${n.x}/${n.y}`)}rawTileToStoredTile(e,t){return{tile:e,data:t}}}function kt(i,e="utf8"){return new TextDecoder(e).decode(i)}const Re=new TextEncoder;function Ce(i){return Re.encode(i)}const De=1024*8,Ne=(()=>{const i=new Uint8Array(4),e=new Uint32Array(i.buffer);return!((e[0]=1)&i[0])})(),nt={int8:globalThis.Int8Array,uint8:globalThis.Uint8Array,int16:globalThis.Int16Array,uint16:globalThis.Uint16Array,int32:globalThis.Int32Array,uint32:globalThis.Uint32Array,uint64:globalThis.BigUint64Array,int64:globalThis.BigInt64Array,float32:globalThis.Float32Array,float64:globalThis.Float64Array};class st{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(e=De,t={}){let n=!1;typeof e=="number"?e=new ArrayBuffer(e):(n=!0,this.lastWrittenByte=e.byteLength);const a=t.offset?t.offset>>>0:0,s=e.byteLength-a;let l=a;(ArrayBuffer.isView(e)||e instanceof st)&&(e.byteLength!==e.buffer.byteLength&&(l=e.byteOffset+a),e=e.buffer),n?this.lastWrittenByte=s:this.lastWrittenByte=0,this.buffer=e,this.length=s,this.byteLength=s,this.byteOffset=l,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,l,s),this._mark=0,this._marks=[]}available(e=1){return this.offset+e<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(e=1){return this.offset+=e,this}back(e=1){return this.offset-=e,this}seek(e){return this.offset=e,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){const e=this._marks.pop();if(e===void 0)throw new Error("Mark stack empty");return this.seek(e),this}rewind(){return this.offset=0,this}ensureAvailable(e=1){if(!this.available(e)){const n=(this.offset+e)*2,a=new Uint8Array(n);a.set(new Uint8Array(this.buffer)),this.buffer=a.buffer,this.length=n,this.byteLength=n,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(e=1){return this.readArray(e,"uint8")}readArray(e,t){const n=nt[t].BYTES_PER_ELEMENT*e,a=this.byteOffset+this.offset,s=this.buffer.slice(a,a+n);if(this.littleEndian===Ne&&t!=="uint8"&&t!=="int8"){const h=new Uint8Array(this.buffer.slice(a,a+n));h.reverse();const d=new nt[t](h.buffer);return this.offset+=n,d.reverse(),d}const l=new nt[t](s);return this.offset+=n,l}readInt16(){const e=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}readUint16(){const e=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,e}readInt32(){const e=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}readUint32(){const e=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat32(){const e=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}readFloat64(){const e=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}readBigInt64(){const e=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,e}readBigUint64(){const e=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,e}readChar(){return String.fromCharCode(this.readInt8())}readChars(e=1){let t="";for(let n=0;n<e;n++)t+=this.readChar();return t}readUtf8(e=1){return kt(this.readBytes(e))}decodeText(e=1,t="utf8"){return kt(this.readBytes(e),t)}writeBoolean(e){return this.writeUint8(e?255:0),this}writeInt8(e){return this.ensureAvailable(1),this._data.setInt8(this.offset++,e),this._updateLastWrittenByte(),this}writeUint8(e){return this.ensureAvailable(1),this._data.setUint8(this.offset++,e),this._updateLastWrittenByte(),this}writeByte(e){return this.writeUint8(e)}writeBytes(e){this.ensureAvailable(e.length);for(let t=0;t<e.length;t++)this._data.setUint8(this.offset++,e[t]);return this._updateLastWrittenByte(),this}writeInt16(e){return this.ensureAvailable(2),this._data.setInt16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(e){return this.ensureAvailable(2),this._data.setUint16(this.offset,e,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(e){return this.ensureAvailable(4),this._data.setInt32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(e){return this.ensureAvailable(4),this._data.setUint32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(e){return this.ensureAvailable(4),this._data.setFloat32(this.offset,e,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(e){return this.ensureAvailable(8),this._data.setFloat64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(e){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(e){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,e,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(e){return this.writeUint8(e.charCodeAt(0))}writeChars(e){for(let t=0;t<e.length;t++)this.writeUint8(e.charCodeAt(t));return this}writeUtf8(e){return this.writeBytes(Ce(e))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}getWrittenByteLength(){return this.lastWrittenByte-this.byteOffset}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}}function F(i){let e=i.length;for(;--e>=0;)i[e]=0}const Me=3,Le=258,Et=29,Be=256+1+Et,At=30,$e=512,Fe=new Array((Be+2)*2);F(Fe);const He=new Array(At*2);F(He);const Ze=new Array($e);F(Ze);const We=new Array(Le-Me+1);F(We);const Pe=new Array(Et);F(Pe);const ze=new Array(At);F(ze);var at=(i,e,t,n)=>{let a=i&65535|0,s=i>>>16&65535|0,l=0;for(;t!==0;){l=t>2e3?2e3:t,t-=l;do a=a+e[n++]|0,s=s+a|0;while(--l);a%=65521,s%=65521}return a|s<<16|0};const Ge=()=>{let i,e=[];for(var t=0;t<256;t++){i=t;for(var n=0;n<8;n++)i=i&1?3988292384^i>>>1:i>>>1;e[t]=i}return e},je=new Uint32Array(Ge());var D=(i,e,t,n)=>{const a=je,s=n+t;i^=-1;for(let l=n;l<s;l++)i=i>>>8^a[(i^e[l])&255];return i^-1},rt={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"},Tt={Z_NO_FLUSH:0,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_DEFLATED:8};const Ke=(i,e)=>Object.prototype.hasOwnProperty.call(i,e);var Ye=function(i){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const t=e.shift();if(t){if(typeof t!="object")throw new TypeError(t+"must be non-object");for(const n in t)Ke(t,n)&&(i[n]=t[n])}}return i},Xe=i=>{let e=0;for(let n=0,a=i.length;n<a;n++)e+=i[n].length;const t=new Uint8Array(e);for(let n=0,a=0,s=i.length;n<s;n++){let l=i[n];t.set(l,a),a+=l.length}return t},mt={assign:Ye,flattenChunks:Xe};let vt=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{vt=!1}const W=new Uint8Array(256);for(let i=0;i<256;i++)W[i]=i>=252?6:i>=248?5:i>=240?4:i>=224?3:i>=192?2:1;W[254]=W[254]=1;var Ve=i=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(i);let e,t,n,a,s,l=i.length,h=0;for(a=0;a<l;a++)t=i.charCodeAt(a),(t&64512)===55296&&a+1<l&&(n=i.charCodeAt(a+1),(n&64512)===56320&&(t=65536+(t-55296<<10)+(n-56320),a++)),h+=t<128?1:t<2048?2:t<65536?3:4;for(e=new Uint8Array(h),s=0,a=0;s<h;a++)t=i.charCodeAt(a),(t&64512)===55296&&a+1<l&&(n=i.charCodeAt(a+1),(n&64512)===56320&&(t=65536+(t-55296<<10)+(n-56320),a++)),t<128?e[s++]=t:t<2048?(e[s++]=192|t>>>6,e[s++]=128|t&63):t<65536?(e[s++]=224|t>>>12,e[s++]=128|t>>>6&63,e[s++]=128|t&63):(e[s++]=240|t>>>18,e[s++]=128|t>>>12&63,e[s++]=128|t>>>6&63,e[s++]=128|t&63);return e};const qe=(i,e)=>{if(e<65534&&i.subarray&&vt)return String.fromCharCode.apply(null,i.length===e?i:i.subarray(0,e));let t="";for(let n=0;n<e;n++)t+=String.fromCharCode(i[n]);return t};var Je=(i,e)=>{const t=e||i.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(i.subarray(0,e));let n,a;const s=new Array(t*2);for(a=0,n=0;n<t;){let l=i[n++];if(l<128){s[a++]=l;continue}let h=W[l];if(h>4){s[a++]=65533,n+=h-1;continue}for(l&=h===2?31:h===3?15:7;h>1&&n<t;)l=l<<6|i[n++]&63,h--;if(h>1){s[a++]=65533;continue}l<65536?s[a++]=l:(l-=65536,s[a++]=55296|l>>10&1023,s[a++]=56320|l&1023)}return qe(s,a)},Qe=(i,e)=>{e=e||i.length,e>i.length&&(e=i.length);let t=e-1;for(;t>=0&&(i[t]&192)===128;)t--;return t<0||t===0?e:t+W[i[t]]>e?t:e},ot={string2buf:Ve,buf2string:Je,utf8border:Qe};function ti(){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}var ei=ti;const j=16209,ii=16191;var ni=function(e,t){let n,a,s,l,h,d,r,o,w,u,f,_,U,x,g,T,y,c,E,S,p,m,A,b;const k=e.state;n=e.next_in,A=e.input,a=n+(e.avail_in-5),s=e.next_out,b=e.output,l=s-(t-e.avail_out),h=s+(e.avail_out-257),d=k.dmax,r=k.wsize,o=k.whave,w=k.wnext,u=k.window,f=k.hold,_=k.bits,U=k.lencode,x=k.distcode,g=(1<<k.lenbits)-1,T=(1<<k.distbits)-1;t:do{_<15&&(f+=A[n++]<<_,_+=8,f+=A[n++]<<_,_+=8),y=U[f&g];e:for(;;){if(c=y>>>24,f>>>=c,_-=c,c=y>>>16&255,c===0)b[s++]=y&65535;else if(c&16){E=y&65535,c&=15,c&&(_<c&&(f+=A[n++]<<_,_+=8),E+=f&(1<<c)-1,f>>>=c,_-=c),_<15&&(f+=A[n++]<<_,_+=8,f+=A[n++]<<_,_+=8),y=x[f&T];i:for(;;){if(c=y>>>24,f>>>=c,_-=c,c=y>>>16&255,c&16){if(S=y&65535,c&=15,_<c&&(f+=A[n++]<<_,_+=8,_<c&&(f+=A[n++]<<_,_+=8)),S+=f&(1<<c)-1,S>d){e.msg="invalid distance too far back",k.mode=j;break t}if(f>>>=c,_-=c,c=s-l,S>c){if(c=S-c,c>o&&k.sane){e.msg="invalid distance too far back",k.mode=j;break t}if(p=0,m=u,w===0){if(p+=r-c,c<E){E-=c;do b[s++]=u[p++];while(--c);p=s-S,m=b}}else if(w<c){if(p+=r+w-c,c-=w,c<E){E-=c;do b[s++]=u[p++];while(--c);if(p=0,w<E){c=w,E-=c;do b[s++]=u[p++];while(--c);p=s-S,m=b}}}else if(p+=w-c,c<E){E-=c;do b[s++]=u[p++];while(--c);p=s-S,m=b}for(;E>2;)b[s++]=m[p++],b[s++]=m[p++],b[s++]=m[p++],E-=3;E&&(b[s++]=m[p++],E>1&&(b[s++]=m[p++]))}else{p=s-S;do b[s++]=b[p++],b[s++]=b[p++],b[s++]=b[p++],E-=3;while(E>2);E&&(b[s++]=b[p++],E>1&&(b[s++]=b[p++]))}}else if((c&64)===0){y=x[(y&65535)+(f&(1<<c)-1)];continue i}else{e.msg="invalid distance code",k.mode=j;break t}break}}else if((c&64)===0){y=U[(y&65535)+(f&(1<<c)-1)];continue e}else if(c&32){k.mode=ii;break t}else{e.msg="invalid literal/length code",k.mode=j;break t}break}}while(n<a&&s<h);E=_>>3,n-=E,_-=E<<3,f&=(1<<_)-1,e.next_in=n,e.next_out=s,e.avail_in=n<a?5+(a-n):5-(n-a),e.avail_out=s<h?257+(h-s):257-(s-h),k.hold=f,k.bits=_};const H=15,Ut=852,St=592,It=0,ht=1,Ot=2,si=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]),ai=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]),ri=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]),oi=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 P=(i,e,t,n,a,s,l,h)=>{const d=h.bits;let r=0,o=0,w=0,u=0,f=0,_=0,U=0,x=0,g=0,T=0,y,c,E,S,p,m=null,A;const b=new Uint16Array(H+1),k=new Uint16Array(H+1);let $=null,Oe,tt,et;for(r=0;r<=H;r++)b[r]=0;for(o=0;o<n;o++)b[e[t+o]]++;for(f=d,u=H;u>=1&&b[u]===0;u--);if(f>u&&(f=u),u===0)return a[s++]=1<<24|64<<16|0,a[s++]=1<<24|64<<16|0,h.bits=1,0;for(w=1;w<u&&b[w]===0;w++);for(f<w&&(f=w),x=1,r=1;r<=H;r++)if(x<<=1,x-=b[r],x<0)return-1;if(x>0&&(i===It||u!==1))return-1;for(k[1]=0,r=1;r<H;r++)k[r+1]=k[r]+b[r];for(o=0;o<n;o++)e[t+o]!==0&&(l[k[e[t+o]]++]=o);if(i===It?(m=$=l,A=20):i===ht?(m=si,$=ai,A=257):(m=ri,$=oi,A=0),T=0,o=0,r=w,p=s,_=f,U=0,E=-1,g=1<<f,S=g-1,i===ht&&g>Ut||i===Ot&&g>St)return 1;for(;;){Oe=r-U,l[o]+1<A?(tt=0,et=l[o]):l[o]>=A?(tt=$[l[o]-A],et=m[l[o]-A]):(tt=96,et=0),y=1<<r-U,c=1<<_,w=c;do c-=y,a[p+(T>>U)+c]=Oe<<24|tt<<16|et|0;while(c!==0);for(y=1<<r-1;T&y;)y>>=1;if(y!==0?(T&=y-1,T+=y):T=0,o++,--b[r]===0){if(r===u)break;r=e[t+l[o]]}if(r>f&&(T&S)!==E){for(U===0&&(U=f),p+=w,_=r-U,x=1<<_;_+U<u&&(x-=b[_+U],!(x<=0));)_++,x<<=1;if(g+=1<<_,i===ht&&g>Ut||i===Ot&&g>St)return 1;E=T&S,a[E]=f<<24|_<<16|p-s|0}}return T!==0&&(a[p+T]=r-U<<24|64<<16|0),h.bits=f,0};const hi=0,Rt=1,Ct=2,{Z_FINISH:Dt,Z_BLOCK:li,Z_TREES:K,Z_OK:L,Z_STREAM_END:fi,Z_NEED_DICT:ci,Z_STREAM_ERROR:C,Z_DATA_ERROR:Nt,Z_MEM_ERROR:Mt,Z_BUF_ERROR:di,Z_DEFLATED:Lt}=Tt,Y=16180,Bt=16181,$t=16182,Ft=16183,Ht=16184,Zt=16185,Wt=16186,Pt=16187,zt=16188,Gt=16189,X=16190,N=16191,lt=16192,jt=16193,ft=16194,Kt=16195,Yt=16196,Xt=16197,Vt=16198,V=16199,q=16200,qt=16201,Jt=16202,Qt=16203,te=16204,ee=16205,ct=16206,ie=16207,ne=16208,v=16209,se=16210,ae=16211,ui=852,_i=592,pi=15,re=i=>(i>>>24&255)+(i>>>8&65280)+((i&65280)<<8)+((i&255)<<24);function wi(){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 B=i=>{if(!i)return 1;const e=i.state;return!e||e.strm!==i||e.mode<Y||e.mode>ae?1:0},oe=i=>{if(B(i))return C;const e=i.state;return i.total_in=i.total_out=e.total=0,i.msg="",e.wrap&&(i.adler=e.wrap&1),e.mode=Y,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(ui),e.distcode=e.distdyn=new Int32Array(_i),e.sane=1,e.back=-1,L},he=i=>{if(B(i))return C;const e=i.state;return e.wsize=0,e.whave=0,e.wnext=0,oe(i)},le=(i,e)=>{let t;if(B(i))return C;const n=i.state;return e<0?(t=0,e=-e):(t=(e>>4)+5,e<48&&(e&=15)),e&&(e<8||e>15)?C:(n.window!==null&&n.wbits!==e&&(n.window=null),n.wrap=t,n.wbits=e,he(i))},fe=(i,e)=>{if(!i)return C;const t=new wi;i.state=t,t.strm=i,t.window=null,t.mode=Y;const n=le(i,e);return n!==L&&(i.state=null),n},gi=i=>fe(i,pi);let ce=!0,dt,ut;const bi=i=>{if(ce){dt=new Int32Array(512),ut=new Int32Array(32);let e=0;for(;e<144;)i.lens[e++]=8;for(;e<256;)i.lens[e++]=9;for(;e<280;)i.lens[e++]=7;for(;e<288;)i.lens[e++]=8;for(P(Rt,i.lens,0,288,dt,0,i.work,{bits:9}),e=0;e<32;)i.lens[e++]=5;P(Ct,i.lens,0,32,ut,0,i.work,{bits:5}),ce=!1}i.lencode=dt,i.lenbits=9,i.distcode=ut,i.distbits=5},de=(i,e,t,n)=>{let a;const s=i.state;return s.window===null&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),n>=s.wsize?(s.window.set(e.subarray(t-s.wsize,t),0),s.wnext=0,s.whave=s.wsize):(a=s.wsize-s.wnext,a>n&&(a=n),s.window.set(e.subarray(t-n,t-n+a),s.wnext),n-=a,n?(s.window.set(e.subarray(t-n,t),0),s.wnext=n,s.whave=s.wsize):(s.wnext+=a,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=a))),0},xi=(i,e)=>{let t,n,a,s,l,h,d,r,o,w,u,f,_,U,x=0,g,T,y,c,E,S,p,m;const A=new Uint8Array(4);let b,k;const $=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(B(i)||!i.output||!i.input&&i.avail_in!==0)return C;t=i.state,t.mode===N&&(t.mode=lt),l=i.next_out,a=i.output,d=i.avail_out,s=i.next_in,n=i.input,h=i.avail_in,r=t.hold,o=t.bits,w=h,u=d,m=L;t:for(;;)switch(t.mode){case Y:if(t.wrap===0){t.mode=lt;break}for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.wrap&2&&r===35615){t.wbits===0&&(t.wbits=15),t.check=0,A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0),r=0,o=0,t.mode=Bt;break}if(t.head&&(t.head.done=!1),!(t.wrap&1)||(((r&255)<<8)+(r>>8))%31){i.msg="incorrect header check",t.mode=v;break}if((r&15)!==Lt){i.msg="unknown compression method",t.mode=v;break}if(r>>>=4,o-=4,p=(r&15)+8,t.wbits===0&&(t.wbits=p),p>15||p>t.wbits){i.msg="invalid window size",t.mode=v;break}t.dmax=1<<t.wbits,t.flags=0,i.adler=t.check=1,t.mode=r&512?Gt:N,r=0,o=0;break;case Bt:for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.flags=r,(t.flags&255)!==Lt){i.msg="unknown compression method",t.mode=v;break}if(t.flags&57344){i.msg="unknown header flags set",t.mode=v;break}t.head&&(t.head.text=r>>8&1),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0)),r=0,o=0,t.mode=$t;case $t:for(;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.head&&(t.head.time=r),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,A[2]=r>>>16&255,A[3]=r>>>24&255,t.check=D(t.check,A,4,0)),r=0,o=0,t.mode=Ft;case Ft:for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.head&&(t.head.xflags=r&255,t.head.os=r>>8),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0)),r=0,o=0,t.mode=Ht;case Ht:if(t.flags&1024){for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.length=r,t.head&&(t.head.extra_len=r),t.flags&512&&t.wrap&4&&(A[0]=r&255,A[1]=r>>>8&255,t.check=D(t.check,A,2,0)),r=0,o=0}else t.head&&(t.head.extra=null);t.mode=Zt;case Zt:if(t.flags&1024&&(f=t.length,f>h&&(f=h),f&&(t.head&&(p=t.head.extra_len-t.length,t.head.extra||(t.head.extra=new Uint8Array(t.head.extra_len)),t.head.extra.set(n.subarray(s,s+f),p)),t.flags&512&&t.wrap&4&&(t.check=D(t.check,n,f,s)),h-=f,s+=f,t.length-=f),t.length))break t;t.length=0,t.mode=Wt;case Wt:if(t.flags&2048){if(h===0)break t;f=0;do p=n[s+f++],t.head&&p&&t.length<65536&&(t.head.name+=String.fromCharCode(p));while(p&&f<h);if(t.flags&512&&t.wrap&4&&(t.check=D(t.check,n,f,s)),h-=f,s+=f,p)break t}else t.head&&(t.head.name=null);t.length=0,t.mode=Pt;case Pt:if(t.flags&4096){if(h===0)break t;f=0;do p=n[s+f++],t.head&&p&&t.length<65536&&(t.head.comment+=String.fromCharCode(p));while(p&&f<h);if(t.flags&512&&t.wrap&4&&(t.check=D(t.check,n,f,s)),h-=f,s+=f,p)break t}else t.head&&(t.head.comment=null);t.mode=zt;case zt:if(t.flags&512){for(;o<16;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.wrap&4&&r!==(t.check&65535)){i.msg="header crc mismatch",t.mode=v;break}r=0,o=0}t.head&&(t.head.hcrc=t.flags>>9&1,t.head.done=!0),i.adler=t.check=0,t.mode=N;break;case Gt:for(;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}i.adler=t.check=re(r),r=0,o=0,t.mode=X;case X:if(t.havedict===0)return i.next_out=l,i.avail_out=d,i.next_in=s,i.avail_in=h,t.hold=r,t.bits=o,ci;i.adler=t.check=1,t.mode=N;case N:if(e===li||e===K)break t;case lt:if(t.last){r>>>=o&7,o-=o&7,t.mode=ct;break}for(;o<3;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}switch(t.last=r&1,r>>>=1,o-=1,r&3){case 0:t.mode=jt;break;case 1:if(bi(t),t.mode=V,e===K){r>>>=2,o-=2;break t}break;case 2:t.mode=Yt;break;case 3:i.msg="invalid block type",t.mode=v}r>>>=2,o-=2;break;case jt:for(r>>>=o&7,o-=o&7;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if((r&65535)!==(r>>>16^65535)){i.msg="invalid stored block lengths",t.mode=v;break}if(t.length=r&65535,r=0,o=0,t.mode=ft,e===K)break t;case ft:t.mode=Kt;case Kt:if(f=t.length,f){if(f>h&&(f=h),f>d&&(f=d),f===0)break t;a.set(n.subarray(s,s+f),l),h-=f,s+=f,d-=f,l+=f,t.length-=f;break}t.mode=N;break;case Yt:for(;o<14;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.nlen=(r&31)+257,r>>>=5,o-=5,t.ndist=(r&31)+1,r>>>=5,o-=5,t.ncode=(r&15)+4,r>>>=4,o-=4,t.nlen>286||t.ndist>30){i.msg="too many length or distance symbols",t.mode=v;break}t.have=0,t.mode=Xt;case Xt:for(;t.have<t.ncode;){for(;o<3;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.lens[$[t.have++]]=r&7,r>>>=3,o-=3}for(;t.have<19;)t.lens[$[t.have++]]=0;if(t.lencode=t.lendyn,t.lenbits=7,b={bits:t.lenbits},m=P(hi,t.lens,0,19,t.lencode,0,t.work,b),t.lenbits=b.bits,m){i.msg="invalid code lengths set",t.mode=v;break}t.have=0,t.mode=Vt;case Vt:for(;t.have<t.nlen+t.ndist;){for(;x=t.lencode[r&(1<<t.lenbits)-1],g=x>>>24,T=x>>>16&255,y=x&65535,!(g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(y<16)r>>>=g,o-=g,t.lens[t.have++]=y;else{if(y===16){for(k=g+2;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(r>>>=g,o-=g,t.have===0){i.msg="invalid bit length repeat",t.mode=v;break}p=t.lens[t.have-1],f=3+(r&3),r>>>=2,o-=2}else if(y===17){for(k=g+3;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=g,o-=g,p=0,f=3+(r&7),r>>>=3,o-=3}else{for(k=g+7;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=g,o-=g,p=0,f=11+(r&127),r>>>=7,o-=7}if(t.have+f>t.nlen+t.ndist){i.msg="invalid bit length repeat",t.mode=v;break}for(;f--;)t.lens[t.have++]=p}}if(t.mode===v)break;if(t.lens[256]===0){i.msg="invalid code -- missing end-of-block",t.mode=v;break}if(t.lenbits=9,b={bits:t.lenbits},m=P(Rt,t.lens,0,t.nlen,t.lencode,0,t.work,b),t.lenbits=b.bits,m){i.msg="invalid literal/lengths set",t.mode=v;break}if(t.distbits=6,t.distcode=t.distdyn,b={bits:t.distbits},m=P(Ct,t.lens,t.nlen,t.ndist,t.distcode,0,t.work,b),t.distbits=b.bits,m){i.msg="invalid distances set",t.mode=v;break}if(t.mode=V,e===K)break t;case V:t.mode=q;case q:if(h>=6&&d>=258){i.next_out=l,i.avail_out=d,i.next_in=s,i.avail_in=h,t.hold=r,t.bits=o,ni(i,u),l=i.next_out,a=i.output,d=i.avail_out,s=i.next_in,n=i.input,h=i.avail_in,r=t.hold,o=t.bits,t.mode===N&&(t.back=-1);break}for(t.back=0;x=t.lencode[r&(1<<t.lenbits)-1],g=x>>>24,T=x>>>16&255,y=x&65535,!(g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(T&&(T&240)===0){for(c=g,E=T,S=y;x=t.lencode[S+((r&(1<<c+E)-1)>>c)],g=x>>>24,T=x>>>16&255,y=x&65535,!(c+g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=c,o-=c,t.back+=c}if(r>>>=g,o-=g,t.back+=g,t.length=y,T===0){t.mode=ee;break}if(T&32){t.back=-1,t.mode=N;break}if(T&64){i.msg="invalid literal/length code",t.mode=v;break}t.extra=T&15,t.mode=qt;case qt:if(t.extra){for(k=t.extra;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.length+=r&(1<<t.extra)-1,r>>>=t.extra,o-=t.extra,t.back+=t.extra}t.was=t.length,t.mode=Jt;case Jt:for(;x=t.distcode[r&(1<<t.distbits)-1],g=x>>>24,T=x>>>16&255,y=x&65535,!(g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if((T&240)===0){for(c=g,E=T,S=y;x=t.distcode[S+((r&(1<<c+E)-1)>>c)],g=x>>>24,T=x>>>16&255,y=x&65535,!(c+g<=o);){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}r>>>=c,o-=c,t.back+=c}if(r>>>=g,o-=g,t.back+=g,T&64){i.msg="invalid distance code",t.mode=v;break}t.offset=y,t.extra=T&15,t.mode=Qt;case Qt:if(t.extra){for(k=t.extra;o<k;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}t.offset+=r&(1<<t.extra)-1,r>>>=t.extra,o-=t.extra,t.back+=t.extra}if(t.offset>t.dmax){i.msg="invalid distance too far back",t.mode=v;break}t.mode=te;case te:if(d===0)break t;if(f=u-d,t.offset>f){if(f=t.offset-f,f>t.whave&&t.sane){i.msg="invalid distance too far back",t.mode=v;break}f>t.wnext?(f-=t.wnext,_=t.wsize-f):_=t.wnext-f,f>t.length&&(f=t.length),U=t.window}else U=a,_=l-t.offset,f=t.length;f>d&&(f=d),d-=f,t.length-=f;do a[l++]=U[_++];while(--f);t.length===0&&(t.mode=q);break;case ee:if(d===0)break t;a[l++]=t.length,d--,t.mode=q;break;case ct:if(t.wrap){for(;o<32;){if(h===0)break t;h--,r|=n[s++]<<o,o+=8}if(u-=d,i.total_out+=u,t.total+=u,t.wrap&4&&u&&(i.adler=t.check=t.flags?D(t.check,a,u,l-u):at(t.check,a,u,l-u)),u=d,t.wrap&4&&(t.flags?r:re(r))!==t.check){i.msg="incorrect data check",t.mode=v;break}r=0,o=0}t.mode=ie;case ie:if(t.wrap&&t.flags){for(;o<32;){if(h===0)break t;h--,r+=n[s++]<<o,o+=8}if(t.wrap&4&&r!==(t.total&4294967295)){i.msg="incorrect length check",t.mode=v;break}r=0,o=0}t.mode=ne;case ne:m=fi;break t;case v:m=Nt;break t;case se:return Mt;case ae:default:return C}return i.next_out=l,i.avail_out=d,i.next_in=s,i.avail_in=h,t.hold=r,t.bits=o,(t.wsize||u!==i.avail_out&&t.mode<v&&(t.mode<ct||e!==Dt))&&de(i,i.output,i.next_out,u-i.avail_out),w-=i.avail_in,u-=i.avail_out,i.total_in+=w,i.total_out+=u,t.total+=u,t.wrap&4&&u&&(i.adler=t.check=t.flags?D(t.check,a,u,i.next_out-u):at(t.check,a,u,i.next_out-u)),i.data_type=t.bits+(t.last?64:0)+(t.mode===N?128:0)+(t.mode===V||t.mode===ft?256:0),(w===0&&u===0||e===Dt)&&m===L&&(m=di),m},yi=i=>{if(B(i))return C;let e=i.state;return e.window&&(e.window=null),i.state=null,L},ki=(i,e)=>{if(B(i))return C;const t=i.state;return(t.wrap&2)===0?C:(t.head=e,e.done=!1,L)},Ei=(i,e)=>{const t=e.length;let n,a,s;return B(i)||(n=i.state,n.wrap!==0&&n.mode!==X)?C:n.mode===X&&(a=1,a=at(a,e,t,0),a!==n.check)?Nt:(s=de(i,e,t,t),s?(n.mode=se,Mt):(n.havedict=1,L))};var Ai=he,Ti=le,mi=oe,vi=gi,Ui=fe,Si=xi,Ii=yi,Oi=ki,Ri=Ei,Ci="pako inflate (from Nodeca project)",M={inflateReset:Ai,inflateReset2:Ti,inflateResetKeep:mi,inflateInit:vi,inflateInit2:Ui,inflate:Si,inflateEnd:Ii,inflateGetHeader:Oi,inflateSetDictionary:Ri,inflateInfo:Ci};function Di(){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}var Ni=Di;const ue=Object.prototype.toString,{Z_NO_FLUSH:Mi,Z_FINISH:Li,Z_OK:z,Z_STREAM_END:_t,Z_NEED_DICT:pt,Z_STREAM_ERROR:Bi,Z_DATA_ERROR:_e,Z_MEM_ERROR:$i}=Tt;function G(i){this.options=mt.assign({chunkSize:1024*64,windowBits:15,to:""},i||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,e.windowBits===0&&(e.windowBits=-15)),e.windowBits>=0&&e.windowBits<16&&!(i&&i.windowBits)&&(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(e.windowBits&15)===0&&(e.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new ei,this.strm.avail_out=0;let t=M.inflateInit2(this.strm,e.windowBits);if(t!==z)throw new Error(rt[t]);if(this.header=new Ni,M.inflateGetHeader(this.strm,this.header),e.dictionary&&(typeof e.dictionary=="string"?e.dictionary=ot.string2buf(e.dictionary):ue.call(e.dictionary)==="[object ArrayBuffer]"&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(t=M.inflateSetDictionary(this.strm,e.dictionary),t!==z)))throw new Error(rt[t])}G.prototype.push=function(i,e){const t=this.strm,n=this.options.chunkSize,a=this.options.dictionary;let s,l,h;if(this.ended)return!1;for(e===~~e?l=e:l=e===!0?Li:Mi,ue.call(i)==="[object ArrayBuffer]"?t.input=new Uint8Array(i):t.input=i,t.next_in=0,t.avail_in=t.input.length;;){for(t.avail_out===0&&(t.output=new Uint8Array(n),t.next_out=0,t.avail_out=n),s=M.inflate(t,l),s===pt&&a&&(s=M.inflateSetDictionary(t,a),s===z?s=M.inflate(t,l):s===_e&&(s=pt));t.avail_in>0&&s===_t&&t.state.wrap>0&&i[t.next_in]!==0;)M.inflateReset(t),s=M.inflate(t,l);switch(s){case Bi:case _e:case pt:case $i:return this.onEnd(s),this.ended=!0,!1}if(h=t.avail_out,t.next_out&&(t.avail_out===0||s===_t))if(this.options.to==="string"){let d=ot.utf8border(t.output,t.next_out),r=t.next_out-d,o=ot.buf2string(t.output,d);t.next_out=r,t.avail_out=n-r,r&&t.output.set(t.output.subarray(d,d+r),0),this.onData(o)}else this.onData(t.output.length===t.next_out?t.output:t.output.subarray(0,t.next_out));if(!(s===z&&h===0)){if(s===_t)return s=M.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(t.avail_in===0)break}}return!0},G.prototype.onData=function(i){this.chunks.push(i)},G.prototype.onEnd=function(i){i===z&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=mt.flattenChunks(this.chunks)),this.chunks=[],this.err=i,this.msg=this.strm.msg};function Fi(i,e){const t=new G(e);if(t.push(i),t.err)throw t.msg||rt[t.err];return t.result}var Hi=G,Zi=Fi,Wi={Inflate:Hi,inflate:Zi};const{Inflate:Pi,inflate:zi}=Wi;var pe=Pi,Gi=zi;const we=[];for(let i=0;i<256;i++){let e=i;for(let t=0;t<8;t++)e&1?e=3988292384^e>>>1:e=e>>>1;we[i]=e}const ge=4294967295;function ji(i,e,t){let n=i;for(let a=0;a<t;a++)n=we[(n^e[a])&255]^n>>>8;return n}function Ki(i,e){return(ji(ge,i,e)^ge)>>>0}function be(i,e,t){const n=i.readUint32(),a=Ki(new Uint8Array(i.buffer,i.byteOffset+i.offset-e-4,e),e);if(a!==n)throw new Error(`CRC mismatch for chunk ${t}. Expected ${n}, found ${a}`)}function xe(i,e,t){for(let n=0;n<t;n++)e[n]=i[n]}function ye(i,e,t,n){let a=0;for(;a<n;a++)e[a]=i[a];for(;a<t;a++)e[a]=i[a]+e[a-n]&255}function ke(i,e,t,n){let a=0;if(t.length===0)for(;a<n;a++)e[a]=i[a];else for(;a<n;a++)e[a]=i[a]+t[a]&255}function Ee(i,e,t,n,a){let s=0;if(t.length===0){for(;s<a;s++)e[s]=i[s];for(;s<n;s++)e[s]=i[s]+(e[s-a]>>1)&255}else{for(;s<a;s++)e[s]=i[s]+(t[s]>>1)&255;for(;s<n;s++)e[s]=i[s]+(e[s-a]+t[s]>>1)&255}}function Ae(i,e,t,n,a){let s=0;if(t.length===0){for(;s<a;s++)e[s]=i[s];for(;s<n;s++)e[s]=i[s]+e[s-a]&255}else{for(;s<a;s++)e[s]=i[s]+t[s]&255;for(;s<n;s++)e[s]=i[s]+Yi(e[s-a],t[s],t[s-a])&255}}function Yi(i,e,t){const n=i+e-t,a=Math.abs(n-i),s=Math.abs(n-e),l=Math.abs(n-t);return a<=s&&a<=l?i:s<=l?e:t}function Xi(i,e,t,n,a,s){switch(i){case 0:xe(e,t,a);break;case 1:ye(e,t,a,s);break;case 2:ke(e,t,n,a);break;case 3:Ee(e,t,n,a,s);break;case 4:Ae(e,t,n,a,s);break;default:throw new Error(`Unsupported filter: ${i}`)}}const Vi=new Uint16Array([255]),qi=new Uint8Array(Vi.buffer)[0]===255;function Ji(i){const{data:e,width:t,height:n,channels:a,depth:s}=i,l=[{x:0,y:0,xStep:8,yStep:8},{x:4,y:0,xStep:8,yStep:8},{x:0,y:4,xStep:4,yStep:8},{x:2,y:0,xStep:4,yStep:4},{x:0,y:2,xStep:2,yStep:4},{x:1,y:0,xStep:2,yStep:2},{x:0,y:1,xStep:1,yStep:2}],h=Math.ceil(s/8)*a,d=new Uint8Array(n*t*h);let r=0;for(let o=0;o<7;o++){const w=l[o],u=Math.ceil((t-w.x)/w.xStep),f=Math.ceil((n-w.y)/w.yStep);if(u<=0||f<=0)continue;const _=u*h,U=new Uint8Array(_);for(let x=0;x<f;x++){const g=e[r++],T=e.subarray(r,r+_);r+=_;const y=new Uint8Array(_);Xi(g,T,y,U,_,h),U.set(y);for(let c=0;c<u;c++){const E=w.x+c*w.xStep,S=w.y+x*w.yStep;if(!(E>=t||S>=n))for(let p=0;p<h;p++)d[(S*t+E)*h+p]=y[c*h+p]}}}if(s===16){const o=new Uint16Array(d.buffer);if(qi)for(let w=0;w<o.length;w++)o[w]=Qi(o[w]);return o}else return d}function Qi(i){return(i&255)<<8|i>>8&255}const tn=new Uint16Array([255]),en=new Uint8Array(tn.buffer)[0]===255,nn=new Uint8Array(0);function Te(i){const{data:e,width:t,height:n,channels:a,depth:s}=i,l=Math.ceil(s/8)*a,h=Math.ceil(s/8*a*t),d=new Uint8Array(n*h);let r=nn,o=0,w,u;for(let f=0;f<n;f++){switch(w=e.subarray(o+1,o+1+h),u=d.subarray(f*h,(f+1)*h),e[o]){case 0:xe(w,u,h);break;case 1:ye(w,u,h,l);break;case 2:ke(w,u,r,h);break;case 3:Ee(w,u,r,h,l);break;case 4:Ae(w,u,r,h,l);break;default:throw new Error(`Unsupported filter: ${e[o]}`)}r=u,o+=h+1}if(s===16){const f=new Uint16Array(d.buffer);if(en)for(let _=0;_<f.length;_++)f[_]=sn(f[_]);return f}else return d}function sn(i){return(i&255)<<8|i>>8&255}const J=Uint8Array.of(137,80,78,71,13,10,26,10);function me(i){if(!an(i.readBytes(J.length)))throw new Error("wrong PNG signature")}function an(i){if(i.length<J.length)return!1;for(let e=0;e<J.length;e++)if(i[e]!==J[e])return!1;return!0}const rn="tEXt",on=0,ve=new TextDecoder("latin1");function hn(i){if(fn(i),i.length===0||i.length>79)throw new Error("keyword length must be between 1 and 79")}const ln=/^[\u0000-\u00FF]*$/;function fn(i){if(!ln.test(i))throw new Error("invalid latin1 text")}function cn(i,e,t){const n=Ue(e);i[n]=dn(e,t-n.length-1)}function Ue(i){for(i.mark();i.readByte()!==on;);const e=i.offset;i.reset();const t=ve.decode(i.readBytes(e-i.offset-1));return i.skip(1),hn(t),t}function dn(i,e){return ve.decode(i.readBytes(e))}const R={UNKNOWN:-1,GREYSCALE:0,TRUECOLOUR:2,INDEXED_COLOUR:3,GREYSCALE_ALPHA:4,TRUECOLOUR_ALPHA:6},wt={UNKNOWN:-1,DEFLATE:0},Se={UNKNOWN:-1,ADAPTIVE:0},gt={UNKNOWN:-1,NO_INTERLACE:0,ADAM7:1},Q={NONE:0,BACKGROUND:1,PREVIOUS:2},bt={SOURCE:0,OVER:1};class un extends st{_checkCrc;_inflator;_png;_apng;_end;_hasPalette;_palette;_hasTransparency;_transparency;_compressionMethod;_filterMethod;_interlaceMethod;_colorType;_isAnimated;_numberOfFrames;_numberOfPlays;_frames;_writingDataChunks;constructor(e,t={}){super(e);const{checkCrc:n=!1}=t;this._checkCrc=n,this._inflator=new pe,this._png={width:-1,height:-1,channels:-1,data:new Uint8Array(0),depth:1,text:{}},this._apng={width:-1,height:-1,channels:-1,depth:1,numberOfFrames:1,numberOfPlays:0,text:{},frames:[]},this._end=!1,this._hasPalette=!1,this._palette=[],this._hasTransparency=!1,this._transparency=new Uint16Array(0),this._compressionMethod=wt.UNKNOWN,this._filterMethod=Se.UNKNOWN,this._interlaceMethod=gt.UNKNOWN,this._colorType=R.UNKNOWN,this._isAnimated=!1,this._numberOfFrames=1,this._numberOfPlays=0,this._frames=[],this._writingDataChunks=!1,this.setBigEndian()}decode(){for(me(this);!this._end;){const e=this.readUint32(),t=this.readChars(4);this.decodeChunk(e,t)}return this.decodeImage(),this._png}decodeApng(){for(me(this);!this._end;){const e=this.readUint32(),t=this.readChars(4);this.decodeApngChunk(e,t)}return this.decodeApngImage(),this._apng}decodeChunk(e,t){const n=this.offset;switch(t){case"IHDR":this.decodeIHDR();break;case"PLTE":this.decodePLTE(e);break;case"IDAT":this.decodeIDAT(e);break;case"IEND":this._end=!0;break;case"tRNS":this.decodetRNS(e);break;case"iCCP":this.decodeiCCP(e);break;case rn:cn(this._png.text,this,e);break;case"pHYs":this.decodepHYs();break;default:this.skip(e);break}if(this.offset-n!==e)throw new Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?be(this,e+4,t):this.skip(4)}decodeApngChunk(e,t){const n=this.offset;switch(t!=="fdAT"&&t!=="IDAT"&&this._writingDataChunks&&this.pushDataToFrame(),t){case"acTL":this.decodeACTL();break;case"fcTL":this.decodeFCTL();break;case"fdAT":this.decodeFDAT(e);break;default:this.decodeChunk(e,t),this.offset=n+e;break}if(this.offset-n!==e)throw new Error(`Length mismatch while decoding chunk ${t}`);this._checkCrc?be(this,e+4,t):this.skip(4)}decodeIHDR(){const e=this._png;e.width=this.readUint32(),e.height=this.readUint32(),e.depth=_n(this.readUint8());const t=this.readUint8();this._colorType=t;let n;switch(t){case R.GREYSCALE:n=1;break;case R.TRUECOLOUR:n=3;break;case R.INDEXED_COLOUR:n=1;break;case R.GREYSCALE_ALPHA:n=2;break;case R.TRUECOLOUR_ALPHA:n=4;break;case R.UNKNOWN:default:throw new Error(`Unknown color type: ${t}`)}if(this._png.channels=n,this._compressionMethod=this.readUint8(),this._compressionMethod!==wt.DEFLATE)throw new Error(`Unsupported compression method: ${this._compressionMethod}`);this._filterMethod=this.readUint8(),this._interlaceMethod=this.readUint8()}decodeACTL(){this._numberOfFrames=this.readUint32(),this._numberOfPlays=this.readUint32(),this._isAnimated=!0}decodeFCTL(){const e={sequenceNumber:this.readUint32(),width:this.readUint32(),height:this.readUint32(),xOffset:this.readUint32(),yOffset:this.readUint32(),delayNumber:this.readUint16(),delayDenominator:this.readUint16(),disposeOp:this.readUint8(),blendOp:this.readUint8(),data:new Uint8Array(0)};this._frames.push(e)}decodePLTE(e){if(e%3!==0)throw new RangeError(`PLTE field length must be a multiple of 3. Got ${e}`);const t=e/3;this._hasPalette=!0;const n=[];this._palette=n;for(let a=0;a<t;a++)n.push([this.readUint8(),this.readUint8(),this.readUint8()])}decodeIDAT(e){this._writingDataChunks=!0;const t=e,n=this.offset+this.byteOffset;if(this._inflator.push(new Uint8Array(this.buffer,n,t)),this._inflator.err)throw new Error(`Error while decompressing the data: ${this._inflator.err}`);this.skip(e)}decodeFDAT(e){this._writingDataChunks=!0;let t=e,n=this.offset+this.byteOffset;if(n+=4,t-=4,this._inflator.push(new Uint8Array(this.buffer,n,t)),this._inflator.err)throw new Error(`Error while decompressing the data: ${this._inflator.err}`);this.skip(e)}decodetRNS(e){switch(this._colorType){case R.GREYSCALE:case R.TRUECOLOUR:{if(e%2!==0)throw new RangeError(`tRNS chunk length must be a multiple of 2. Got ${e}`);if(e/2>this._png.width*this._png.height)throw new Error(`tRNS chunk contains more alpha values than there are pixels (${e/2} vs ${this._png.width*this._png.height})`);this._hasTransparency=!0,this._transparency=new Uint16Array(e/2);for(let t=0;t<e/2;t++)this._transparency[t]=this.readUint16();break}case R.INDEXED_COLOUR:{if(e>this._palette.length)throw new Error(`tRNS chunk contains more alpha values than there are palette colors (${e} vs ${this._palette.length})`);let t=0;for(;t<e;t++){const n=this.readByte();this._palette[t].push(n)}for(;t<this._palette.length;t++)this._palette[t].push(255);break}case R.UNKNOWN:case R.GREYSCALE_ALPHA:case R.TRUECOLOUR_ALPHA:default:throw new Error(`tRNS chunk is not supported for color type ${this._colorType}`)}}decodeiCCP(e){const t=Ue(this),n=this.readUint8();if(n!==wt.DEFLATE)throw new Error(`Unsupported iCCP compression method: ${n}`);const a=this.readBytes(e-t.length-2);this._png.iccEmbeddedProfile={name:t,profile:Gi(a)}}decodepHYs(){const e=this.readUint32(),t=this.readUint32(),n=this.readByte();this._png.resolution={x:e,y:t,unit:n}}decodeApngImage(){this._apng.width=this._png.width,this._apng.height=this._png.height,this._apng.channels=this._png.channels,this._apng.depth=this._png.depth,this._apng.numberOfFrames=this._numberOfFrames,this._apng.numberOfPlays=this._numberOfPlays,this._apng.text=this._png.text,this._apng.resolution=this._png.resolution;for(let e=0;e<this._numberOfFrames;e++){const t={sequenceNumber:this._frames[e].sequenceNumber,delayNumber:this._frames[e].delayNumber,delayDenominator:this._frames[e].delayDenominator,data:this._apng.depth===8?new Uint8Array(this._apng.width*this._apng.height*this._apng.channels):new Uint16Array(this._apng.width*this._apng.height*this._apng.channels)},n=this._frames.at(e);if(n){if(n.data=Te({data:n.data,width:n.width,height:n.height,channels:this._apng.channels,depth:this._apng.depth}),this._hasPalette&&(this._apng.palette=this._palette),this._hasTransparency&&(this._apng.transparency=this._transparency),e===0||n.xOffset===0&&n.yOffset===0&&n.width===this._png.width&&n.height===this._png.height)t.data=n.data;else{const a=this._apng.frames.at(e-1);this.disposeFrame(n,a,t),this.addFrameDataToCanvas(t,n)}this._apng.frames.push(t)}}return this._apng}disposeFrame(e,t,n){switch(e.disposeOp){case Q.NONE:break;case Q.BACKGROUND:for(let a=0;a<this._png.height;a++)for(let s=0;s<this._png.width;s++){const l=(a*e.width+s)*this._png.channels;for(let h=0;h<this._png.channels;h++)n.data[l+h]=0}break;case Q.PREVIOUS:n.data.set(t.data);break;default:throw new Error("Unknown disposeOp")}}addFrameDataToCanvas(e,t){const n=1<<this._png.depth,a=(s,l)=>{const h=((s+t.yOffset)*this._png.width+t.xOffset+l)*this._png.channels,d=(s*t.width+l)*this._png.channels;return{index:h,frameIndex:d}};switch(t.blendOp){case bt.SOURCE:for(let s=0;s<t.height;s++)for(let l=0;l<t.width;l++){const{index:h,frameIndex:d}=a(s,l);for(let r=0;r<this._png.channels;r++)e.data[h+r]=t.data[d+r]}break;case bt.OVER:for(let s=0;s<t.height;s++)for(let l=0;l<t.width;l++){const{index:h,frameIndex:d}=a(s,l);for(let r=0;r<this._png.channels;r++){const o=t.data[d+this._png.channels-1]/n,w=r%(this._png.channels-1)===0?1:t.data[d+r],u=Math.floor(o*w+(1-o)*e.data[h+r]);e.data[h+r]+=u}}break;default:throw new Error("Unknown blendOp")}}decodeImage(){if(this._inflator.err)throw new Error(`Error while decompressing the data: ${this._inflator.err}`);const e=this._isAnimated?(this._frames?.at(0)).data:this._inflator.result;if(this._filterMethod!==Se.ADAPTIVE)throw new Error(`Filter method ${this._filterMethod} not supported`);if(this._interlaceMethod===gt.NO_INTERLACE)this._png.data=Te({data:e,width:this._png.width,height:this._png.height,channels:this._png.channels,depth:this._png.depth});else if(this._interlaceMethod===gt.ADAM7)this._png.data=Ji({data:e,width:this._png.width,height:this._png.height,channels:this._png.channels,depth:this._png.depth});else throw new Error(`Interlace method ${this._interlaceMethod} not supported`);this._hasPalette&&(this._png.palette=this._palette),this._hasTransparency&&(this._png.transparency=this._transparency)}pushDataToFrame(){const e=this._inflator.result,t=this._frames.at(-1);t?t.data=e:this._frames.push({sequenceNumber:0,width:this._png.width,height:this._png.height,xOffset:0,yOffset:0,delayNumber:0,delayDenominator:0,disposeOp:Q.NONE,blendOp:bt.SOURCE,data:e}),this._inflator=new pe,this._writingDataChunks=!1}}function _n(i){if(i!==1&&i!==2&&i!==4&&i!==8&&i!==16)throw new Error(`invalid bit depth: ${i}`);return i}function pn(i,e){return new un(i,e).decode()}class Ie{#e;#t;#n;#i;#s;elevs;constructor(e,t,n,a,s,l){this.#e=t,this.#t=n,this.#n=a,this.elevs=e,this.#i=s,this.#s=l}getElevation(e,t){let n=[e,t],a=Math.floor((n[0]-this.#e.e)/this.#i),s=this.#n-Math.ceil((n[1]-this.#e.n)/this.#s),l,h,d,r,o,w,u,f=null;if(a>=0&&s>=0&&a<this.#t-1&&s<this.#n-1){r=this.elevs[s*this.#t+a],o=this.elevs[s*this.#t+a+1],w=this.elevs[s*this.#t+a+this.#t],u=this.elevs[s*this.#t+a+this.#t+1],l=this.#e.e+a*this.#i,l+this.#i,h=this.#e.n+(this.#n-1-s)*this.#s,d=h-this.#s;let _=(n[0]-l)/this.#i,U=r*(1-_)+o*_,x=w*(1-_)+u*_,g=(n[1]-d)/this.#s;f=x*(1-g)+U*g}return f}}class wn extends it{constructor(e){super(e)}async readTile(e){const n=await(await fetch(e,{signal:AbortSignal.timeout(3e4)})).arrayBuffer(),a=pn(n);let s,l=0;const h=new Array(a.width*a.height);for(let d=0;d<a.height;d++)for(let r=0;r<a.width;r++)s=(d*a.width+r)*a.channels,h[l++]=Math.round(a.data[s]*256+a.data[s+1]+a.data[s+2]/256-32768);return{w:a.width,h:a.height,elevs:h}}getElevation(e){const t=this.getTile(e,this.tile.z),n=this.dataTiles.get(`${t.z}/${t.x}/${t.y}`);return n?n.data.getElevation(e.e,e.n):null}getElevationFromLonLat(e){return this.getElevation(this.sphMerc.project(e))}rawTileToStoredTile(e,t){const n=e.getTopRight(),a=e.getBottomLeft(),s=(n.e-a.e)/(t.w-1),l=(n.n-a.n)/(t.h-1),h=new Ie(t.elevs,a,t.w,t.h,s,l);return{tile:e,data:h}}}class gn extends it{constructor(e){super(e)}async readTile(e){return await(await fetch(e,{signal:AbortSignal.timeout(3e4)})).json()}}class bn{e;n;constructor(e,t){this.e=e,this.n=t}toString(){return`e: ${this.e}, n: ${this.n}`}}class xt{longitude;latitude;constructor(e,t){this.longitude=e,this.latitude=t}toString(){return`longitude: ${this.longitude}, latitude: ${this.latitude}`}}class xn{demTiler;jsonTiler;constructor(e,t){this.demTiler=e,this.jsonTiler=t}async updateByLonLat(e){const t=this.demTiler.sphMerc.project(e),n=await this.demTiler.update(t),a=await this.jsonTiler.update(t);return n.forEach((s,l)=>{this.#e(s,a[l])}),a}async#e(e,t){t.data.features.forEach((a,s)=>{switch(a.geometry.type){case"LineString":const l=a.geometry;l.coordinates.length>=2&&this.#t(e,l.coordinates);break;case"MultiLineString":const h=a.geometry;for(let o of h.coordinates)o.length>=2&&this.#t(e,o);break;case"Point":a.geometry;const d=this.demTiler.sphMerc.project(new xt(a.geometry.coordinates[0],a.geometry.coordinates[1])),r=e.data?e.data.getElevation(d.e,d.n):0;r>Number.NEGATIVE_INFINITY&&(a.geometry.coordinates[2]=r)}})}#t(e,t){t.forEach(n=>{const a=this.demTiler.sphMerc.project(new xt(n[0],n[1])),s=e.data?.getElevation(a.e,a.n)??0;s>Number.NEGATIVE_INFINITY&&(n[2]=s)})}}I.Constants=O,I.DEM=Ie,I.DemApplier=xn,I.DemTiler=wn,I.EastNorth=bn,I.JsonTiler=gn,I.LonLat=xt,I.SphMercProjection=yt,I.Tile=Z,I.Tiler=it,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "locar-tiler",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Tiling system for downloading geodata from APIs by Spherical Mercator XYZ tile. Particularly useful for location-based augmented reality applications as it comes with JSON and Digital Elevation Model (Terrarium DEM) support by default; works nicely with LocAR.js.",
5
5
  "dependencies": {
6
6
  "fast-png": "^7.0.1",