ja-geotiff
Version:
GeoTIFF image decoding in JavaScript
1 lines • 532 kB
JavaScript
!function(A,I){"object"==typeof exports&&"undefined"!=typeof module?I(exports):"function"==typeof define&&define.amd?define(["exports"],I):I((A="undefined"!=typeof globalThis?globalThis:A||self).GeoTIFF={})}(this,function(A){"use strict";function I(A){return(I,...g)=>B(A,I,g)}function g(A,g){return I(i(A,g).get)}const{apply:B,construct:C,defineProperty:Q,get:E,getOwnPropertyDescriptor:i,getPrototypeOf:t,has:e,ownKeys:s,set:o,setPrototypeOf:a}=Reflect,{iterator:r,species:n,toStringTag:h,for:D}=Symbol,w=Object,{create:c,defineProperty:y,freeze:l,is:S}=w,d=Array.prototype[r],G=I(d),N=ArrayBuffer;g(N.prototype,"byteLength");const f="undefined"!=typeof SharedArrayBuffer?SharedArrayBuffer:null;f&&g(f.prototype,"byteLength");const k=t(Uint8Array);k.from;const F=k.prototype;F[r],I(F.keys),I(F.values),I(F.entries),I(F.set),I(F.reverse),I(F.fill),I(F.copyWithin),I(F.sort),I(F.slice),I(F.subarray),g(F,"buffer"),g(F,"byteOffset"),g(F,"length"),g(F,h);const R=Uint8Array,U=Uint16Array,L=Uint32Array,u=Float32Array,Y=t([][r]()),K=I(Y.next),M=I(function*(){}().next),p=t(Y),J=I(DataView.prototype.getUint16),m=WeakMap,H=m.prototype,b=I(H.get),q=I(H.set),x=new m,_=c(null,{next:{value:function(){const A=b(x,this);return K(A)}},[r]:{value:function(){return this}}});const T=new m,O=c(p,{next:{value:function(){const A=b(T,this);return M(A)},writable:!0,configurable:!0}});for(const A of s(Y))"next"!==A&&y(O,A,i(Y,A));const v=new N(4),Z=new u(v),P=new L(v),j=new U(512),W=new R(512);for(let A=0;A<256;++A){const I=A-127;I<-24?(j[A]=0,j[256|A]=32768,W[A]=24,W[256|A]=24):I<-14?(j[A]=1024>>-I-14,j[256|A]=1024>>-I-14|32768,W[A]=-I-1,W[256|A]=-I-1):I<=15?(j[A]=I+15<<10,j[256|A]=I+15<<10|32768,W[A]=13,W[256|A]=13):I<128?(j[A]=31744,j[256|A]=64512,W[A]=24,W[256|A]=24):(j[A]=31744,j[256|A]=64512,W[A]=13,W[256|A]=13)}const V=new L(2048);for(let A=1;A<1024;++A){let I=A<<13,g=0;for(;!(8388608&I);)I<<=1,g-=8388608;I&=-8388609,g+=947912704,V[A]=I|g}for(let A=1024;A<2048;++A)V[A]=939524096+(A-1024<<13);const z=new L(64);for(let A=1;A<31;++A)z[A]=A<<23;z[31]=1199570944,z[32]=2147483648;for(let A=33;A<63;++A)z[A]=2147483648+(A-32<<23);z[63]=3347054592;const X=new U(64);for(let A=1;A<64;++A)32!==A&&(X[A]=1024);function $(A,I,...g){return function(A){const I=A>>10;return P[0]=V[X[I]+(1023&A)]+z[I],Z[0]}(J(A,I,...function(A){if(A[r]===d&&Y.next===K)return A;const I=c(_);return q(x,I,G(A)),I}(g)))}function AA(A,I,g){const B=g&&g.debug||!1;B&&console.log("[xml-utils] getting "+I+" in "+A);const C="object"==typeof A?A.outer:A,Q=C.slice(0,C.indexOf(">")+1),E=['"',"'"];for(let A=0;A<E.length;A++){const g=E[A],C=I+"\\="+g+"([^"+g+"]*)"+g;B&&console.log("[xml-utils] pattern:",C);const i=new RegExp(C).exec(Q);if(B&&console.log("[xml-utils] match:",i),i)return i[1]}}function IA(A,I,g){const B=new RegExp(I).exec(A.slice(g));return B?g+B.index+B[0].length-1:-1}function gA(A,I){const g=new RegExp(I,"g"),B=A.match(g);return B?B.length:0}function BA(A,I,g){const B=g&&g.debug||!1,C=!(g&&!1===typeof g.nested),Q=g&&g.startIndex||0;B&&console.log("[xml-utils] starting findTagByName with",I," and ",g);const E=function(A,I,g){const B=new RegExp(I).exec(A.slice(g));return B?g+B.index:-1}(A,`<${I}[ \n>/]`,Q);if(B&&console.log("[xml-utils] start:",E),-1===E)return;const i=A.slice(E+I.length);let t=IA(i,"^[^<]*[ /]>",0);const e=-1!==t&&"/"===i[t-1];if(B&&console.log("[xml-utils] selfClosing:",e),!1===e)if(C){let A=0,g=1,B=0;for(;-1!==(t=IA(i,"[ /]"+I+">",A));){const C=i.substring(A,t+1);if(g+=gA(C,"<"+I+"[ \n\t>]"),B+=gA(C,"</"+I+">"),B>=g)break;A=t}}else t=IA(i,"[ /]"+I+">",0);const s=E+I.length+t+1;if(B&&console.log("[xml-utils] end:",s),-1===s)return;const o=A.slice(E,s);let a;return a=e?null:o.slice(o.indexOf(">")+1,o.lastIndexOf("<")),{inner:a,outer:o,start:E,end:s}}const CA={315:"Artist",258:"BitsPerSample",265:"CellLength",264:"CellWidth",320:"ColorMap",259:"Compression",33432:"Copyright",306:"DateTime",338:"ExtraSamples",266:"FillOrder",289:"FreeByteCounts",288:"FreeOffsets",291:"GrayResponseCurve",290:"GrayResponseUnit",316:"HostComputer",270:"ImageDescription",257:"ImageLength",256:"ImageWidth",271:"Make",281:"MaxSampleValue",280:"MinSampleValue",272:"Model",254:"NewSubfileType",274:"Orientation",262:"PhotometricInterpretation",284:"PlanarConfiguration",296:"ResolutionUnit",278:"RowsPerStrip",277:"SamplesPerPixel",305:"Software",279:"StripByteCounts",273:"StripOffsets",255:"SubfileType",263:"Threshholding",282:"XResolution",283:"YResolution",326:"BadFaxLines",327:"CleanFaxData",343:"ClipPath",328:"ConsecutiveBadFaxLines",433:"Decode",434:"DefaultImageColor",269:"DocumentName",336:"DotRange",321:"HalftoneHints",346:"Indexed",347:"JPEGTables",285:"PageName",297:"PageNumber",317:"Predictor",319:"PrimaryChromaticities",532:"ReferenceBlackWhite",339:"SampleFormat",340:"SMinSampleValue",341:"SMaxSampleValue",559:"StripRowCounts",330:"SubIFDs",292:"T4Options",293:"T6Options",325:"TileByteCounts",323:"TileLength",324:"TileOffsets",322:"TileWidth",301:"TransferFunction",318:"WhitePoint",344:"XClipPathUnits",286:"XPosition",529:"YCbCrCoefficients",531:"YCbCrPositioning",530:"YCbCrSubSampling",345:"YClipPathUnits",287:"YPosition",37378:"ApertureValue",40961:"ColorSpace",36868:"DateTimeDigitized",36867:"DateTimeOriginal",34665:"Exif IFD",36864:"ExifVersion",33434:"ExposureTime",41728:"FileSource",37385:"Flash",40960:"FlashpixVersion",33437:"FNumber",42016:"ImageUniqueID",37384:"LightSource",37500:"MakerNote",37377:"ShutterSpeedValue",37510:"UserComment",33723:"IPTC",34412:"CZ_LSMINFO",34675:"ICC Profile",700:"XMP",42112:"GDAL_METADATA",42113:"GDAL_NODATA",34377:"Photoshop",33550:"ModelPixelScale",33922:"ModelTiepoint",34264:"ModelTransformation",34735:"GeoKeyDirectory",34736:"GeoDoubleParams",34737:"GeoAsciiParams",50674:"LercParameters"},QA={};for(const A in CA)CA.hasOwnProperty(A)&&(QA[CA[A]]=parseInt(A,10));const EA={256:"SHORT",257:"SHORT",258:"SHORT",259:"SHORT",262:"SHORT",270:"ASCII",271:"ASCII",272:"ASCII",273:"LONG",274:"SHORT",277:"SHORT",278:"LONG",279:"LONG",282:"RATIONAL",283:"RATIONAL",284:"SHORT",286:"SHORT",287:"RATIONAL",296:"SHORT",297:"SHORT",305:"ASCII",306:"ASCII",315:"ASCII",338:"SHORT",339:"SHORT",513:"LONG",514:"LONG",1024:"SHORT",1025:"SHORT",1026:"ASCII",2048:"SHORT",2049:"ASCII",2052:"SHORT",2054:"SHORT",2060:"SHORT",3072:"SHORT",3073:"ASCII",3076:"SHORT",4096:"SHORT",4097:"ASCII",4099:"SHORT",33432:"ASCII",33550:"DOUBLE",33922:"DOUBLE",34264:"DOUBLE",34665:"LONG",34735:"SHORT",34736:"DOUBLE",34737:"ASCII",42113:"ASCII"},iA=[QA.BitsPerSample,QA.ExtraSamples,QA.SampleFormat,QA.StripByteCounts,QA.StripOffsets,QA.StripRowCounts,QA.TileByteCounts,QA.TileOffsets,QA.SubIFDs],tA={1:"BYTE",2:"ASCII",3:"SHORT",4:"LONG",5:"RATIONAL",6:"SBYTE",7:"UNDEFINED",8:"SSHORT",9:"SLONG",10:"SRATIONAL",11:"FLOAT",12:"DOUBLE",13:"IFD",16:"LONG8",17:"SLONG8",18:"IFD8"},eA={};for(const A in tA)tA.hasOwnProperty(A)&&(eA[tA[A]]=parseInt(A,10));const sA={WhiteIsZero:0,BlackIsZero:1,RGB:2,Palette:3,TransparencyMask:4,CMYK:5,YCbCr:6,CIELab:8,ICCLab:9},oA={Unspecified:0,Assocalpha:1,Unassalpha:2},aA={Version:0,AddCompression:1},rA={None:0,Deflate:1,Zstandard:2},nA={1024:"GTModelTypeGeoKey",1025:"GTRasterTypeGeoKey",1026:"GTCitationGeoKey",2048:"GeographicTypeGeoKey",2049:"GeogCitationGeoKey",2050:"GeogGeodeticDatumGeoKey",2051:"GeogPrimeMeridianGeoKey",2052:"GeogLinearUnitsGeoKey",2053:"GeogLinearUnitSizeGeoKey",2054:"GeogAngularUnitsGeoKey",2055:"GeogAngularUnitSizeGeoKey",2056:"GeogEllipsoidGeoKey",2057:"GeogSemiMajorAxisGeoKey",2058:"GeogSemiMinorAxisGeoKey",2059:"GeogInvFlatteningGeoKey",2060:"GeogAzimuthUnitsGeoKey",2061:"GeogPrimeMeridianLongGeoKey",2062:"GeogTOWGS84GeoKey",3072:"ProjectedCSTypeGeoKey",3073:"PCSCitationGeoKey",3074:"ProjectionGeoKey",3075:"ProjCoordTransGeoKey",3076:"ProjLinearUnitsGeoKey",3077:"ProjLinearUnitSizeGeoKey",3078:"ProjStdParallel1GeoKey",3079:"ProjStdParallel2GeoKey",3080:"ProjNatOriginLongGeoKey",3081:"ProjNatOriginLatGeoKey",3082:"ProjFalseEastingGeoKey",3083:"ProjFalseNorthingGeoKey",3084:"ProjFalseOriginLongGeoKey",3085:"ProjFalseOriginLatGeoKey",3086:"ProjFalseOriginEastingGeoKey",3087:"ProjFalseOriginNorthingGeoKey",3088:"ProjCenterLongGeoKey",3089:"ProjCenterLatGeoKey",3090:"ProjCenterEastingGeoKey",3091:"ProjCenterNorthingGeoKey",3092:"ProjScaleAtNatOriginGeoKey",3093:"ProjScaleAtCenterGeoKey",3094:"ProjAzimuthAngleGeoKey",3095:"ProjStraightVertPoleLongGeoKey",3096:"ProjRectifiedGridAngleGeoKey",4096:"VerticalCSTypeGeoKey",4097:"VerticalCitationGeoKey",4098:"VerticalDatumGeoKey",4099:"VerticalUnitsGeoKey"},hA={};for(const A in nA)nA.hasOwnProperty(A)&&(hA[nA[A]]=parseInt(A,10));var DA=Object.freeze({__proto__:null,fieldTagNames:CA,fieldTags:QA,fieldTagTypes:EA,arrayFields:iA,fieldTypeNames:tA,fieldTypes:eA,registerTag:function(A,I,g=void 0,B=!1){QA[I]=A,CA[A]=I,g&&(eA[I]=g),B&&iA.push(A)},photometricInterpretations:sA,ExtraSamplesValues:oA,LercParameters:aA,LercAddCompression:rA,geoKeyNames:nA,geoKeys:hA});function wA(A,I){const{width:g,height:B}=A,C=new Uint8Array(g*B*3);let Q;for(let g=0,B=0;g<A.length;++g,B+=3)Q=256-A[g]/I*256,C[B]=Q,C[B+1]=Q,C[B+2]=Q;return C}function cA(A,I){const{width:g,height:B}=A,C=new Uint8Array(g*B*3);let Q;for(let g=0,B=0;g<A.length;++g,B+=3)Q=A[g]/I*256,C[B]=Q,C[B+1]=Q,C[B+2]=Q;return C}function yA(A,I){const{width:g,height:B}=A,C=new Uint8Array(g*B*3),Q=I.length/3,E=I.length/3*2;for(let g=0,B=0;g<A.length;++g,B+=3){const i=A[g];C[B]=I[i]/65536*256,C[B+1]=I[i+Q]/65536*256,C[B+2]=I[i+E]/65536*256}return C}function lA(A){const{width:I,height:g}=A,B=new Uint8Array(I*g*3);for(let I=0,g=0;I<A.length;I+=4,g+=3){const C=A[I],Q=A[I+1],E=A[I+2],i=A[I+3];B[g]=(255-C)/256*255*((255-i)/256),B[g+1]=(255-Q)/256*255*((255-i)/256),B[g+2]=(255-E)/256*255*((255-i)/256)}return B}function SA(A){const{width:I,height:g}=A,B=new Uint8ClampedArray(I*g*3);for(let I=0,g=0;I<A.length;I+=3,g+=3){const C=A[I],Q=A[I+1],E=A[I+2];B[g]=C+1.402*(E-128),B[g+1]=C-.34414*(Q-128)-.71414*(E-128),B[g+2]=C+1.772*(Q-128)}return B}function dA(A){const{width:I,height:g}=A,B=new Uint8Array(I*g*3);for(let I=0,g=0;I<A.length;I+=3,g+=3){let C,Q,E,i=(A[I+0]+16)/116,t=(A[I+1]<<24>>24)/500+i,e=i-(A[I+2]<<24>>24)/200;t=.95047*(t*t*t>.008856?t*t*t:(t-16/116)/7.787),i=1*(i*i*i>.008856?i*i*i:(i-16/116)/7.787),e=1.08883*(e*e*e>.008856?e*e*e:(e-16/116)/7.787),C=3.2406*t+-1.5372*i+-.4986*e,Q=-.9689*t+1.8758*i+.0415*e,E=.0557*t+-.204*i+1.057*e,C=C>.0031308?1.055*C**(1/2.4)-.055:12.92*C,Q=Q>.0031308?1.055*Q**(1/2.4)-.055:12.92*Q,E=E>.0031308?1.055*E**(1/2.4)-.055:12.92*E,B[g]=255*Math.max(0,Math.min(1,C)),B[g+1]=255*Math.max(0,Math.min(1,Q)),B[g+2]=255*Math.max(0,Math.min(1,E))}return B}var GA=Object.freeze({__proto__:null,fromWhiteIsZero:wA,fromBlackIsZero:cA,fromPalette:yA,fromCMYK:lA,fromYCbCr:SA,fromCIELab:dA});const NA=new Map,fA=new Map;function kA(A,I,g=!0){Array.isArray(A)||(A=[A]),A.forEach(A=>{NA.set(A,I),fA.set(A,g)})}async function FA(A){const I=NA.get(A.Compression);if(!I)throw new Error(`Unknown compression method identifier: ${A.Compression}`);return new(await I())(A)}function RA(A,I,g,B=1){return new(Object.getPrototypeOf(A).constructor)(I*g*B)}function UA(A,I,g){return(1-g)*A+g*I}function LA(A,I,g,B,C,Q="nearest"){switch(Q.toLowerCase()){case"nearest":return function(A,I,g,B,C){const Q=I/B,E=g/C;return A.map(A=>{const i=RA(A,B,C);for(let t=0;t<C;++t){const C=Math.min(Math.round(E*t),g-1);for(let g=0;g<B;++g){const E=Math.min(Math.round(Q*g),I-1),e=A[C*I+E];i[t*B+g]=e}}return i})}(A,I,g,B,C);case"bilinear":case"linear":return function(A,I,g,B,C){const Q=I/B,E=g/C;return A.map(A=>{const i=RA(A,B,C);for(let t=0;t<C;++t){const C=E*t,e=Math.floor(C),s=Math.min(Math.ceil(C),g-1);for(let g=0;g<B;++g){const E=Q*g,o=E%1,a=Math.floor(E),r=Math.min(Math.ceil(E),I-1),n=A[e*I+a],h=A[e*I+r],D=A[s*I+a],w=A[s*I+r],c=UA(UA(n,h,o),UA(D,w,o),C%1);i[t*B+g]=c}}return i})}(A,I,g,B,C);default:throw new Error(`Unsupported resampling method: '${Q}'`)}}function uA(A,I,g,B,C,Q,E="nearest"){switch(E.toLowerCase()){case"nearest":return function(A,I,g,B,C,Q){const E=I/B,i=g/C,t=RA(A,B,C,Q);for(let e=0;e<C;++e){const C=Math.min(Math.round(i*e),g-1);for(let g=0;g<B;++g){const i=Math.min(Math.round(E*g),I-1);for(let E=0;E<Q;++E){const s=A[C*I*Q+i*Q+E];t[e*B*Q+g*Q+E]=s}}}return t}(A,I,g,B,C,Q);case"bilinear":case"linear":return function(A,I,g,B,C,Q){const E=I/B,i=g/C,t=RA(A,B,C,Q);for(let e=0;e<C;++e){const C=i*e,s=Math.floor(C),o=Math.min(Math.ceil(C),g-1);for(let g=0;g<B;++g){const i=E*g,a=i%1,r=Math.floor(i),n=Math.min(Math.ceil(i),I-1);for(let E=0;E<Q;++E){const i=A[s*I*Q+r*Q+E],h=A[s*I*Q+n*Q+E],D=A[o*I*Q+r*Q+E],w=A[o*I*Q+n*Q+E],c=UA(UA(i,h,a),UA(D,w,a),C%1);t[e*B*Q+g*Q+E]=c}}}return t}(A,I,g,B,C,Q);default:throw new Error(`Unsupported resampling method: '${E}'`)}}function YA(A,I,g){let B=0;for(let C=I;C<g;++C)B+=A[C];return B}function KA(A,I,g){switch(A){case 1:if(I<=8)return new Uint8Array(g);if(I<=16)return new Uint16Array(g);if(I<=32)return new Uint32Array(g);break;case 2:if(8===I)return new Int8Array(g);if(16===I)return new Int16Array(g);if(32===I)return new Int32Array(g);break;case 3:switch(I){case 16:case 32:return new Float32Array(g);case 64:return new Float64Array(g)}}throw Error("Unsupported data format/bitsPerSample")}kA([void 0,1],()=>Promise.resolve().then(function(){return xI}).then(A=>A.default),!1),kA(5,()=>Promise.resolve().then(function(){return OI}).then(A=>A.default)),kA(6,()=>{throw new Error("old style JPEG compression is not supported.")}),kA(7,()=>Promise.resolve().then(function(){return Cg}).then(A=>A.default)),kA([8,32946],()=>Promise.resolve().then(function(){return DQ}).then(A=>A.default)),kA(32773,()=>Promise.resolve().then(function(){return wQ}).then(A=>A.default)),kA(34887,()=>Promise.resolve().then(function(){return kQ}).then(async A=>(await A.zstd.init(),A)).then(A=>A.default)),kA(5e4,()=>Promise.resolve().then(function(){return MQ}).then(async A=>(await A.zstd.init(),A)).then(A=>A.default)),kA(50001,()=>Promise.resolve().then(function(){return pQ}).then(A=>A.default),!1);var MA=class{constructor(A,I,g,B,C,Q){this.fileDirectory=A,this.geoKeys=I,this.dataView=g,this.littleEndian=B,this.tiles=C?{}:null,this.isTiled=!A.StripOffsets;const E=A.PlanarConfiguration;if(this.planarConfiguration=void 0===E?1:E,1!==this.planarConfiguration&&2!==this.planarConfiguration)throw new Error("Invalid planar configuration.");this.source=Q}getFileDirectory(){return this.fileDirectory}getGeoKeys(){return this.geoKeys}getWidth(){return this.fileDirectory.ImageWidth}getHeight(){return this.fileDirectory.ImageLength}getSamplesPerPixel(){return void 0!==this.fileDirectory.SamplesPerPixel?this.fileDirectory.SamplesPerPixel:1}getTileWidth(){return this.isTiled?this.fileDirectory.TileWidth:this.getWidth()}getTileHeight(){return this.isTiled?this.fileDirectory.TileLength:void 0!==this.fileDirectory.RowsPerStrip?Math.min(this.fileDirectory.RowsPerStrip,this.getHeight()):this.getHeight()}getBlockWidth(){return this.getTileWidth()}getBlockHeight(A){return this.isTiled||(A+1)*this.getTileHeight()<=this.getHeight()?this.getTileHeight():this.getHeight()-A*this.getTileHeight()}getBytesPerPixel(){let A=0;for(let I=0;I<this.fileDirectory.BitsPerSample.length;++I)A+=this.getSampleByteSize(I);return A}getSampleByteSize(A){if(A>=this.fileDirectory.BitsPerSample.length)throw new RangeError(`Sample index ${A} is out of range.`);return Math.ceil(this.fileDirectory.BitsPerSample[A]/8)}getReaderForSample(A){const I=this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[A]:1,g=this.fileDirectory.BitsPerSample[A];switch(I){case 1:if(g<=8)return DataView.prototype.getUint8;if(g<=16)return DataView.prototype.getUint16;if(g<=32)return DataView.prototype.getUint32;break;case 2:if(g<=8)return DataView.prototype.getInt8;if(g<=16)return DataView.prototype.getInt16;if(g<=32)return DataView.prototype.getInt32;break;case 3:switch(g){case 16:return function(A,I){return $(this,A,I)};case 32:return DataView.prototype.getFloat32;case 64:return DataView.prototype.getFloat64}}throw Error("Unsupported data format/bitsPerSample")}getSampleFormat(A=0){return this.fileDirectory.SampleFormat?this.fileDirectory.SampleFormat[A]:1}getBitsPerSample(A=0){return this.fileDirectory.BitsPerSample[A]}getArrayForSample(A,I){return KA(this.getSampleFormat(A),this.getBitsPerSample(A),I)}async getTileOrStrip(A,I,g,B,C){const Q=Math.ceil(this.getWidth()/this.getTileWidth()),E=Math.ceil(this.getHeight()/this.getTileHeight());let i;const{tiles:t}=this;let e,s;if(1===this.planarConfiguration?i=I*Q+A:2===this.planarConfiguration&&(i=g*Q*E+I*Q+A),this.isTiled?(e=this.fileDirectory.TileOffsets[i],s=this.fileDirectory.TileByteCounts[i]):(e=this.fileDirectory.StripOffsets[i],s=this.fileDirectory.StripByteCounts[i]),0===s){const B=this.getBlockHeight(I)*this.getTileWidth(),C=2===this.planarConfiguration?this.getSampleByteSize(g):this.getBytesPerPixel(),Q=new ArrayBuffer(B*C);return this.getArrayForSample(g,Q).fill(this.getGDALNoData()||0),{x:A,y:I,sample:g,data:Q}}const o=(await this.source.fetch([{offset:e,length:s}],C))[0];let a;return null!==t&&t[i]?a=t[i]:(a=(async()=>{let A=await B.decode(this.fileDirectory,o);const g=this.getSampleFormat(),C=this.getBitsPerSample();return function(A,I){return(1!==A&&2!==A||!(I<=32)||I%8!=0)&&(3!==A||16!==I&&32!==I&&64!==I)}(g,C)&&(A=function(A,I,g,B,C,Q,E){const i=new DataView(A),t=2===g?1:B,e=KA(I,C,2===g?E*Q:E*Q*B),s=parseInt("1".repeat(C),2);if(1===I){let A;A=1===g?B*C:C;let I=Q*A;7&I&&(I=I+7&-8);for(let A=0;A<E;++A){const g=A*I;for(let I=0;I<Q;++I){const B=g+I*t*C;for(let g=0;g<t;++g){const E=B+g*C,o=(A*Q+I)*t+g,a=Math.floor(E/8),r=E%8;if(r+C<=8)e[o]=i.getUint8(a)>>8-C-r&s;else if(r+C<=16)e[o]=i.getUint16(a)>>16-C-r&s;else if(r+C<=24){const A=i.getUint16(a)<<8|i.getUint8(a+2);e[o]=A>>24-C-r&s}else e[o]=i.getUint32(a)>>32-C-r&s}}}}return e.buffer}(A,g,this.planarConfiguration,this.getSamplesPerPixel(),C,this.getTileWidth(),this.getBlockHeight(I))),A})(),null!==t&&(t[i]=a)),{x:A,y:I,sample:g,data:await a}}async _readRaster(A,I,g,B,C,Q,E,i,t){const e=this.getTileWidth(),s=this.getTileHeight(),o=this.getWidth(),a=this.getHeight(),r=Math.max(Math.floor(A[0]/e),0),n=Math.min(Math.ceil(A[2]/e),Math.ceil(o/e)),h=Math.max(Math.floor(A[1]/s),0),D=Math.min(Math.ceil(A[3]/s),Math.ceil(a/s)),w=A[2]-A[0];let c=this.getBytesPerPixel();const y=[],l=[];for(let A=0;A<I.length;++A)1===this.planarConfiguration?y.push(YA(this.fileDirectory.BitsPerSample,0,I[A])/8):y.push(0),l.push(this.getReaderForSample(I[A]));const S=[],{littleEndian:d}=this;for(let Q=h;Q<D;++Q)for(let E=r;E<n;++E){let i;1===this.planarConfiguration&&(i=this.getTileOrStrip(E,Q,0,C,t));for(let r=0;r<I.length;++r){const n=r,h=I[r];2===this.planarConfiguration&&(c=this.getSampleByteSize(h),i=this.getTileOrStrip(E,Q,h,C,t));const D=i.then(C=>{const Q=C.data,E=new DataView(Q),i=this.getBlockHeight(C.y),t=C.y*s,r=C.x*e,h=t+i,D=(C.x+1)*e,S=l[n],G=Math.min(i,i-(h-A[3]),a-t),N=Math.min(e,e-(D-A[2]),o-r);for(let C=Math.max(0,A[1]-t);C<G;++C)for(let Q=Math.max(0,A[0]-r);Q<N;++Q){const i=(C*e+Q)*c,s=S.call(E,i+y[n],d);let o;B?(o=(C+t-A[1])*w*I.length+(Q+r-A[0])*I.length+n,g[o]=s):(o=(C+t-A[1])*w+Q+r-A[0],g[n][o]=s)}});S.push(D)}}if(await Promise.all(S),Q&&A[2]-A[0]!==Q||E&&A[3]-A[1]!==E){let C;return C=B?uA(g,A[2]-A[0],A[3]-A[1],Q,E,I.length,i):LA(g,A[2]-A[0],A[3]-A[1],Q,E,i),C.width=Q,C.height=E,C}return g.width=Q||A[2]-A[0],g.height=E||A[3]-A[1],g}async readRasters({window:A,samples:I=[],interleave:g,pool:B=null,width:C,height:Q,resampleMethod:E,fillValue:i,signal:t}={}){const e=A||[0,0,this.getWidth(),this.getHeight()];if(e[0]>e[2]||e[1]>e[3])throw new Error("Invalid subsets");const s=(e[2]-e[0])*(e[3]-e[1]),o=this.getSamplesPerPixel();if(I&&I.length){for(let A=0;A<I.length;++A)if(I[A]>=o)return Promise.reject(new RangeError(`Invalid sample index '${I[A]}'.`))}else for(let A=0;A<o;++A)I.push(A);let a;if(g){a=KA(this.fileDirectory.SampleFormat?Math.max.apply(null,this.fileDirectory.SampleFormat):1,Math.max.apply(null,this.fileDirectory.BitsPerSample),s*I.length),i&&a.fill(i)}else{a=[];for(let A=0;A<I.length;++A){const g=this.getArrayForSample(I[A],s);Array.isArray(i)&&A<i.length?g.fill(i[A]):i&&!Array.isArray(i)&&g.fill(i),a.push(g)}}const r=B||await FA(this.fileDirectory);return await this._readRaster(e,I,a,g,r,C,Q,E,t)}async readRGB({window:A,interleave:I=!0,pool:g=null,width:B,height:C,resampleMethod:Q,enableAlpha:E=!1,signal:i}={}){const t=A||[0,0,this.getWidth(),this.getHeight()];if(t[0]>t[2]||t[1]>t[3])throw new Error("Invalid subsets");const e=this.fileDirectory.PhotometricInterpretation;if(e===sA.RGB){let t=[0,1,2];if(this.fileDirectory.ExtraSamples!==oA.Unspecified&&E){t=[];for(let A=0;A<this.fileDirectory.BitsPerSample.length;A+=1)t.push(A)}return this.readRasters({window:A,interleave:I,samples:t,pool:g,width:B,height:C,resampleMethod:Q,signal:i})}let s;switch(e){case sA.WhiteIsZero:case sA.BlackIsZero:case sA.Palette:s=[0];break;case sA.CMYK:s=[0,1,2,3];break;case sA.YCbCr:case sA.CIELab:s=[0,1,2];break;default:throw new Error("Invalid or unsupported photometric interpretation.")}const o={window:t,interleave:!0,samples:s,pool:g,width:B,height:C,resampleMethod:Q,signal:i},{fileDirectory:a}=this,r=await this.readRasters(o),n=2**this.fileDirectory.BitsPerSample[0];let h;switch(e){case sA.WhiteIsZero:h=wA(r,n);break;case sA.BlackIsZero:h=cA(r,n);break;case sA.Palette:h=yA(r,a.ColorMap);break;case sA.CMYK:h=lA(r);break;case sA.YCbCr:h=SA(r);break;case sA.CIELab:h=dA(r);break;default:throw new Error("Unsupported photometric interpretation.")}if(!I){const A=new Uint8Array(h.length/3),I=new Uint8Array(h.length/3),g=new Uint8Array(h.length/3);for(let B=0,C=0;B<h.length;B+=3,++C)A[C]=h[B],I[C]=h[B+1],g[C]=h[B+2];h=[A,I,g]}return h.width=r.width,h.height=r.height,h}getTiePoints(){if(!this.fileDirectory.ModelTiepoint)return[];const A=[];for(let I=0;I<this.fileDirectory.ModelTiepoint.length;I+=6)A.push({i:this.fileDirectory.ModelTiepoint[I],j:this.fileDirectory.ModelTiepoint[I+1],k:this.fileDirectory.ModelTiepoint[I+2],x:this.fileDirectory.ModelTiepoint[I+3],y:this.fileDirectory.ModelTiepoint[I+4],z:this.fileDirectory.ModelTiepoint[I+5]});return A}getGDALMetadata(A=null){const I={};if(!this.fileDirectory.GDAL_METADATA)return null;let g=function(A,I,g){const B=[],C=g&&g.debug||!1,Q=!g||"boolean"!=typeof g.nested||g.nested;let E,i=g&&g.startIndex||0;for(;E=BA(A,I,{debug:C,startIndex:i});)i=Q?E.start+1+I.length:E.end,B.push(E);return C&&console.log("findTagsByName found",B.length,"tags"),B}(this.fileDirectory.GDAL_METADATA,"Item");g=null===A?g.filter(A=>void 0===AA(A,"sample")):g.filter(I=>Number(AA(I,"sample"))===A);for(let A=0;A<g.length;++A){const B=g[A];I[AA(B,"name")]=B.inner}return I}getGDALNoData(){if(!this.fileDirectory.GDAL_NODATA)return null;const A=this.fileDirectory.GDAL_NODATA;return Number(A.substring(0,A.length-1))}getOrigin(){const A=this.fileDirectory.ModelTiepoint,I=this.fileDirectory.ModelTransformation;if(A&&6===A.length)return[A[3],A[4],A[5]];if(I)return[I[3],I[7],I[11]];throw new Error("The image does not have an affine transformation.")}getResolution(A=null){const I=this.fileDirectory.ModelPixelScale,g=this.fileDirectory.ModelTransformation;if(I)return[I[0],-I[1],I[2]];if(g)return 0===g[1]&&0===g[4]?[g[0],-g[5],g[10]]:[Math.sqrt(g[0]*g[0]+g[4]*g[4]),-Math.sqrt(g[1]*g[1]+g[5]*g[5]),g[10]];if(A){const[I,g,B]=A.getResolution();return[I*A.getWidth()/this.getWidth(),g*A.getHeight()/this.getHeight(),B*A.getWidth()/this.getWidth()]}throw new Error("The image does not have an affine transformation.")}pixelIsArea(){return 1===this.geoKeys.GTRasterTypeGeoKey}getBoundingBox(A=!1){const I=this.getHeight(),g=this.getWidth();if(this.fileDirectory.ModelTransformation&&!A){const[A,B,C,Q,E,i,t,e]=this.fileDirectory.ModelTransformation,s=[[0,0],[0,I],[g,0],[g,I]].map(([I,g])=>[Q+A*I+B*g,e+E*I+i*g]),o=s.map(A=>A[0]),a=s.map(A=>A[1]);return[Math.min(...o),Math.min(...a),Math.max(...o),Math.max(...a)]}{const A=this.getOrigin(),B=this.getResolution(),C=A[0],Q=A[1],E=C+B[0]*g,i=Q+B[1]*I;return[Math.min(C,E),Math.min(Q,i),Math.max(C,E),Math.max(Q,i)]}}};class pA{constructor(A){this._dataView=new DataView(A)}get buffer(){return this._dataView.buffer}getUint64(A,I){const g=this.getUint32(A,I),B=this.getUint32(A+4,I);let C;if(I){if(C=g+2**32*B,!Number.isSafeInteger(C))throw new Error(`${C} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return C}if(C=2**32*g+B,!Number.isSafeInteger(C))throw new Error(`${C} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return C}getInt64(A,I){let g=0;const B=(128&this._dataView.getUint8(A+(I?7:0)))>0;let C=!0;for(let Q=0;Q<8;Q++){let E=this._dataView.getUint8(A+(I?Q:7-Q));B&&(C?0!==E&&(E=255&~(E-1),C=!1):E=255&~E),g+=E*256**Q}return B&&(g=-g),g}getUint8(A,I){return this._dataView.getUint8(A,I)}getInt8(A,I){return this._dataView.getInt8(A,I)}getUint16(A,I){return this._dataView.getUint16(A,I)}getInt16(A,I){return this._dataView.getInt16(A,I)}getUint32(A,I){return this._dataView.getUint32(A,I)}getInt32(A,I){return this._dataView.getInt32(A,I)}getFloat16(A,I){return $(this._dataView,A,I)}getFloat32(A,I){return this._dataView.getFloat32(A,I)}getFloat64(A,I){return this._dataView.getFloat64(A,I)}}class JA{constructor(A,I,g,B){this._dataView=new DataView(A),this._sliceOffset=I,this._littleEndian=g,this._bigTiff=B}get sliceOffset(){return this._sliceOffset}get sliceTop(){return this._sliceOffset+this.buffer.byteLength}get littleEndian(){return this._littleEndian}get bigTiff(){return this._bigTiff}get buffer(){return this._dataView.buffer}covers(A,I){return this.sliceOffset<=A&&this.sliceTop>=A+I}readUint8(A){return this._dataView.getUint8(A-this._sliceOffset,this._littleEndian)}readInt8(A){return this._dataView.getInt8(A-this._sliceOffset,this._littleEndian)}readUint16(A){return this._dataView.getUint16(A-this._sliceOffset,this._littleEndian)}readInt16(A){return this._dataView.getInt16(A-this._sliceOffset,this._littleEndian)}readUint32(A){return this._dataView.getUint32(A-this._sliceOffset,this._littleEndian)}readInt32(A){return this._dataView.getInt32(A-this._sliceOffset,this._littleEndian)}readFloat32(A){return this._dataView.getFloat32(A-this._sliceOffset,this._littleEndian)}readFloat64(A){return this._dataView.getFloat64(A-this._sliceOffset,this._littleEndian)}readUint64(A){const I=this.readUint32(A),g=this.readUint32(A+4);let B;if(this._littleEndian){if(B=I+2**32*g,!Number.isSafeInteger(B))throw new Error(`${B} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return B}if(B=2**32*I+g,!Number.isSafeInteger(B))throw new Error(`${B} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);return B}readInt64(A){let I=0;const g=(128&this._dataView.getUint8(A+(this._littleEndian?7:0)))>0;let B=!0;for(let C=0;C<8;C++){let Q=this._dataView.getUint8(A+(this._littleEndian?C:7-C));g&&(B?0!==Q&&(Q=255&~(Q-1),B=!1):Q=255&~Q),I+=Q*256**C}return g&&(I=-I),I}readOffset(A){return this._bigTiff?this.readUint64(A):this.readUint32(A)}}var mA="undefined"!=typeof Worker?Worker:void 0;function HA(){const A='const A=new Map,I=new Map;function g(g,B,C=!0){Array.isArray(g)||(g=[g]),g.forEach(g=>{A.set(g,B),I.set(g,C)})}g([void 0,1],()=>Promise.resolve().then(function(){return i}).then(A=>A.default),!1),g(5,()=>Promise.resolve().then(function(){return o}).then(A=>A.default)),g(6,()=>{throw new Error("old style JPEG compression is not supported.")}),g(7,()=>Promise.resolve().then(function(){return k}).then(A=>A.default)),g([8,32946],()=>Promise.resolve().then(function(){return Hg}).then(A=>A.default)),g(32773,()=>Promise.resolve().then(function(){return pg}).then(A=>A.default)),g(34887,()=>Promise.resolve().then(function(){return zg}).then(async A=>(await A.zstd.init(),A)).then(A=>A.default)),g(5e4,()=>Promise.resolve().then(function(){return QB}).then(async A=>(await A.zstd.init(),A)).then(A=>A.default)),g(50001,()=>Promise.resolve().then(function(){return EB}).then(A=>A.default),!1);const B=globalThis;function C(A,I){let g=A.length-I,B=0;do{for(let g=I;g>0;g--)A[B+I]+=A[B],B++;g-=I}while(g>0)}function Q(A,I,g){let B=0,C=A.length;const Q=C/g;for(;C>I;){for(let g=I;g>0;--g)A[B+I]+=A[B],++B;C-=I}const E=A.slice();for(let I=0;I<Q;++I)for(let B=0;B<g;++B)A[g*I+B]=E[(g-B-1)*Q+I]}B.addEventListener("message",async I=>{const{fileDirectory:g,buffer:C,...Q}=I.data;try{const I=await async function(I){const g=A.get(I.Compression);if(!g)throw new Error(`Unknown compression method identifier: ${I.Compression}`);return new(await g())(I)}(g),E=await I.decode(g,C);B.postMessage({decoded:E,...Q},[E])}catch(A){B.postMessage({error:A.message,...Q})}});class E{async decode(A,I){const g=await this.decodeBlock(I),B=A.Predictor||1;if(1!==B){const I=!A.StripOffsets;return function(A,I,g,B,E,i){if(!I||1===I)return A;for(let A=0;A<E.length;++A){if(E[A]%8!=0)throw new Error("When decoding with predictor, only multiple of 8 bits are supported.");if(E[A]!==E[0])throw new Error("When decoding with predictor, all samples must have the same size.")}const s=E[0]/8,t=2===i?1:E.length;for(let i=0;i<B&&!(i*t*g*s>=A.byteLength);++i){let B;if(2===I){switch(E[0]){case 8:B=new Uint8Array(A,i*t*g*s,t*g*s);break;case 16:B=new Uint16Array(A,i*t*g*s,t*g*s/2);break;case 32:B=new Uint32Array(A,i*t*g*s,t*g*s/4);break;default:throw new Error(`Predictor 2 not allowed with ${E[0]} bits per sample.`)}C(B,t)}else 3===I&&(B=new Uint8Array(A,i*t*g*s,t*g*s),Q(B,t,s))}return A}(g,B,I?A.TileWidth:A.ImageWidth,I?A.TileLength:A.RowsPerStrip||A.ImageLength,A.BitsPerSample,A.PlanarConfiguration)}return g}}var i=Object.freeze({__proto__:null,default:class extends E{decodeBlock(A){return A}}});function s(A,I){for(let g=I.length-1;g>=0;g--)A.push(I[g]);return A}function t(A){const I=new Uint16Array(4093),g=new Uint8Array(4093);for(let A=0;A<=257;A++)I[A]=4096,g[A]=A;let B=258,C=9,Q=0;function E(){B=258,C=9}function i(A){const I=function(A,I,g){const B=I%8,C=Math.floor(I/8),Q=8-B,E=I+g-8*(C+1);let i=8*(C+2)-(I+g);const s=8*(C+2)-I;if(i=Math.max(0,i),C>=A.length)return console.warn("ran off the end of the buffer before finding EOI_CODE (end on input code)"),257;let t=A[C]&2**(8-B)-1;t<<=g-Q;let o=t;if(C+1<A.length){let I=A[C+1]>>>i;I<<=Math.max(0,g-s),o+=I}if(E>8&&C+2<A.length){const B=8*(C+3)-(I+g);o+=A[C+2]>>>B}return o}(A,Q,C);return Q+=C,I}function t(A,C){return g[B]=C,I[B]=A,B++,B-1}function o(A){const B=[];for(let C=A;4096!==C;C=I[C])B.push(g[C]);return B}const a=[];E();const e=new Uint8Array(A);let r,D=i(e);for(;257!==D;){if(256===D){for(E(),D=i(e);256===D;)D=i(e);if(257===D)break;if(D>256)throw new Error(`corrupted code at scanline ${D}`);s(a,o(D)),r=D}else if(D<B){const A=o(D);s(a,A),t(r,A[A.length-1]),r=D}else{const A=o(r);if(!A)throw new Error(`Bogus entry. Not in dictionary, ${r} / ${B}, position: ${Q}`);s(a,A),a.push(A[A.length-1]),t(r,A[A.length-1]),r=D}B+1>=2**C&&(12===C?r=void 0:C++),D=i(e)}return new Uint8Array(a)}var o=Object.freeze({__proto__:null,default:class extends E{decodeBlock(A){return t(A).buffer}}});const a=new Int32Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),e=4017,r=799,D=3406,h=2276,n=1567,w=3784,y=5793,G=2896;function S(A,I){let g=0;const B=[];let C=16;for(;C>0&&!A[C-1];)--C;B.push({children:[],index:0});let Q,E=B[0];for(let i=0;i<C;i++){for(let C=0;C<A[i];C++){for(E=B.pop(),E.children[E.index]=I[g];E.index>0;)E=B.pop();for(E.index++,B.push(E);B.length<=i;)B.push(Q={children:[],index:0}),E.children[E.index]=Q.children,E=Q;g++}i+1<C&&(B.push(Q={children:[],index:0}),E.children[E.index]=Q.children,E=Q)}return B[0].children}function N(A,I,g,B,C,Q,E,i,s){const{mcusPerLine:t,progressive:o}=g,e=I;let r=I,D=0,h=0;function n(){if(h>0)return h--,D>>h&1;if(D=A[r++],255===D){const I=A[r++];if(I)throw new Error(`unexpected marker: ${(D<<8|I).toString(16)}`)}return h=7,D>>>7}function w(A){let I,g=A;for(;null!==(I=n());){if(g=g[I],"number"==typeof g)return g;if("object"!=typeof g)throw new Error("invalid huffman sequence")}return null}function y(A){let I=A,g=0;for(;I>0;){const A=n();if(null===A)return;g=g<<1|A,--I}return g}function G(A){const I=y(A);return I>=1<<A-1?I:I+(-1<<A)+1}let S=0;let N,c=0;function d(A,I,g,B,C){const Q=g%t,E=(g/t|0)*A.v+B,i=Q*A.h+C;I(A,A.blocks[E][i])}function k(A,I,g){const B=g/A.blocksPerLine|0,C=g%A.blocksPerLine;I(A,A.blocks[B][C])}const F=B.length;let l,R,U,L,Y,f;f=o?0===Q?0===i?function(A,I){const g=w(A.huffmanTableDC),B=0===g?0:G(g)<<s;A.pred+=B,I[0]=A.pred}:function(A,I){I[0]|=n()<<s}:0===i?function(A,I){if(S>0)return void S--;let g=Q;const B=E;for(;g<=B;){const B=w(A.huffmanTableAC),C=15&B,Q=B>>4;if(0===C){if(Q<15){S=y(Q)+(1<<Q)-1;break}g+=16}else g+=Q,I[a[g]]=G(C)*(1<<s),g++}}:function(A,I){let g=Q;const B=E;let C=0;for(;g<=B;){const B=a[g],Q=I[B]<0?-1:1;switch(c){case 0:{const I=w(A.huffmanTableAC),g=15&I;if(C=I>>4,0===g)C<15?(S=y(C)+(1<<C),c=4):(C=16,c=1);else{if(1!==g)throw new Error("invalid ACn encoding");N=G(g),c=C?2:3}continue}case 1:case 2:I[B]?I[B]+=(n()<<s)*Q:(C--,0===C&&(c=2===c?3:0));break;case 3:I[B]?I[B]+=(n()<<s)*Q:(I[B]=N<<s,c=0);break;case 4:I[B]&&(I[B]+=(n()<<s)*Q)}g++}4===c&&(S--,0===S&&(c=0))}:function(A,I){const g=w(A.huffmanTableDC),B=0===g?0:G(g);A.pred+=B,I[0]=A.pred;let C=1;for(;C<64;){const g=w(A.huffmanTableAC),B=15&g,Q=g>>4;if(0===B){if(Q<15)break;C+=16}else C+=Q,I[a[C]]=G(B),C++}};let K,u,M=0;u=1===F?B[0].blocksPerLine*B[0].blocksPerColumn:t*g.mcusPerColumn;const J=C||u;for(;M<u;){for(R=0;R<F;R++)B[R].pred=0;if(S=0,1===F)for(l=B[0],Y=0;Y<J;Y++)k(l,f,M),M++;else for(Y=0;Y<J;Y++){for(R=0;R<F;R++){l=B[R];const{h:A,v:I}=l;for(U=0;U<I;U++)for(L=0;L<A;L++)d(l,f,M,U,L)}if(M++,M===u)break}if(h=0,K=A[r]<<8|A[r+1],K<65280)throw new Error("marker was not found");if(!(K>=65488&&K<=65495))break;r+=2}return r-e}function c(A,I){const g=[],{blocksPerLine:B,blocksPerColumn:C}=I,Q=B<<3,E=new Int32Array(64),i=new Uint8Array(64);function s(A,g,B){const C=I.quantizationTable;let Q,E,i,s,t,o,a,S,N;const c=B;let d;for(d=0;d<64;d++)c[d]=A[d]*C[d];for(d=0;d<8;++d){const A=8*d;0!==c[1+A]||0!==c[2+A]||0!==c[3+A]||0!==c[4+A]||0!==c[5+A]||0!==c[6+A]||0!==c[7+A]?(Q=y*c[0+A]+128>>8,E=y*c[4+A]+128>>8,i=c[2+A],s=c[6+A],t=G*(c[1+A]-c[7+A])+128>>8,S=G*(c[1+A]+c[7+A])+128>>8,o=c[3+A]<<4,a=c[5+A]<<4,N=Q-E+1>>1,Q=Q+E+1>>1,E=N,N=i*w+s*n+128>>8,i=i*n-s*w+128>>8,s=N,N=t-a+1>>1,t=t+a+1>>1,a=N,N=S+o+1>>1,o=S-o+1>>1,S=N,N=Q-s+1>>1,Q=Q+s+1>>1,s=N,N=E-i+1>>1,E=E+i+1>>1,i=N,N=t*h+S*D+2048>>12,t=t*D-S*h+2048>>12,S=N,N=o*r+a*e+2048>>12,o=o*e-a*r+2048>>12,a=N,c[0+A]=Q+S,c[7+A]=Q-S,c[1+A]=E+a,c[6+A]=E-a,c[2+A]=i+o,c[5+A]=i-o,c[3+A]=s+t,c[4+A]=s-t):(N=y*c[0+A]+512>>10,c[0+A]=N,c[1+A]=N,c[2+A]=N,c[3+A]=N,c[4+A]=N,c[5+A]=N,c[6+A]=N,c[7+A]=N)}for(d=0;d<8;++d){const A=d;0!==c[8+A]||0!==c[16+A]||0!==c[24+A]||0!==c[32+A]||0!==c[40+A]||0!==c[48+A]||0!==c[56+A]?(Q=y*c[0+A]+2048>>12,E=y*c[32+A]+2048>>12,i=c[16+A],s=c[48+A],t=G*(c[8+A]-c[56+A])+2048>>12,S=G*(c[8+A]+c[56+A])+2048>>12,o=c[24+A],a=c[40+A],N=Q-E+1>>1,Q=Q+E+1>>1,E=N,N=i*w+s*n+2048>>12,i=i*n-s*w+2048>>12,s=N,N=t-a+1>>1,t=t+a+1>>1,a=N,N=S+o+1>>1,o=S-o+1>>1,S=N,N=Q-s+1>>1,Q=Q+s+1>>1,s=N,N=E-i+1>>1,E=E+i+1>>1,i=N,N=t*h+S*D+2048>>12,t=t*D-S*h+2048>>12,S=N,N=o*r+a*e+2048>>12,o=o*e-a*r+2048>>12,a=N,c[0+A]=Q+S,c[56+A]=Q-S,c[8+A]=E+a,c[48+A]=E-a,c[16+A]=i+o,c[40+A]=i-o,c[24+A]=s+t,c[32+A]=s-t):(N=y*B[d+0]+8192>>14,c[0+A]=N,c[8+A]=N,c[16+A]=N,c[24+A]=N,c[32+A]=N,c[40+A]=N,c[48+A]=N,c[56+A]=N)}for(d=0;d<64;++d){const A=128+(c[d]+8>>4);g[d]=A<0?0:A>255?255:A}}for(let A=0;A<C;A++){const C=A<<3;for(let A=0;A<8;A++)g.push(new Uint8Array(Q));for(let Q=0;Q<B;Q++){s(I.blocks[A][Q],i,E);let B=0;const t=Q<<3;for(let A=0;A<8;A++){const I=g[C+A];for(let A=0;A<8;A++)I[t+A]=i[B++]}}}return g}class d{constructor(){this.jfif=null,this.adobe=null,this.quantizationTables=[],this.huffmanTablesAC=[],this.huffmanTablesDC=[],this.resetFrames()}resetFrames(){this.frames=[]}parse(A){let I=0;function g(){const g=A[I]<<8|A[I+1];return I+=2,g}function B(){const B=g(),C=A.subarray(I,I+B-2);return I+=C.length,C}function C(A){let I,g,B=0,C=0;for(g in A.components)A.components.hasOwnProperty(g)&&(I=A.components[g],B<I.h&&(B=I.h),C<I.v&&(C=I.v));const Q=Math.ceil(A.samplesPerLine/8/B),E=Math.ceil(A.scanLines/8/C);for(g in A.components)if(A.components.hasOwnProperty(g)){I=A.components[g];const i=Math.ceil(Math.ceil(A.samplesPerLine/8)*I.h/B),s=Math.ceil(Math.ceil(A.scanLines/8)*I.v/C),t=Q*I.h,o=E*I.v,a=[];for(let A=0;A<o;A++){const A=[];for(let I=0;I<t;I++)A.push(new Int32Array(64));a.push(A)}I.blocksPerLine=i,I.blocksPerColumn=s,I.blocks=a}A.maxH=B,A.maxV=C,A.mcusPerLine=Q,A.mcusPerColumn=E}let Q=g();if(65496!==Q)throw new Error("SOI not found");for(Q=g();65497!==Q;){switch(Q){case 65280:break;case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:{const A=B();65504===Q&&74===A[0]&&70===A[1]&&73===A[2]&&70===A[3]&&0===A[4]&&(this.jfif={version:{major:A[5],minor:A[6]},densityUnits:A[7],xDensity:A[8]<<8|A[9],yDensity:A[10]<<8|A[11],thumbWidth:A[12],thumbHeight:A[13],thumbData:A.subarray(14,14+3*A[12]*A[13])}),65518===Q&&65===A[0]&&100===A[1]&&111===A[2]&&98===A[3]&&101===A[4]&&0===A[5]&&(this.adobe={version:A[6],flags0:A[7]<<8|A[8],flags1:A[9]<<8|A[10],transformCode:A[11]});break}case 65499:{const B=g()+I-2;for(;I<B;){const B=A[I++],C=new Int32Array(64);if(B>>4){if(B>>4!=1)throw new Error("DQT: invalid table spec");for(let A=0;A<64;A++){C[a[A]]=g()}}else for(let g=0;g<64;g++){C[a[g]]=A[I++]}this.quantizationTables[15&B]=C}break}case 65472:case 65473:case 65474:{g();const B={extended:65473===Q,progressive:65474===Q,precision:A[I++],scanLines:g(),samplesPerLine:g(),components:{},componentsOrder:[]},E=A[I++];let i;for(let g=0;g<E;g++){i=A[I];const g=A[I+1]>>4,C=15&A[I+1],Q=A[I+2];B.componentsOrder.push(i),B.components[i]={h:g,v:C,quantizationIdx:Q},I+=3}C(B),this.frames.push(B);break}case 65476:{const B=g();for(let g=2;g<B;){const B=A[I++],C=new Uint8Array(16);let Q=0;for(let g=0;g<16;g++,I++)C[g]=A[I],Q+=C[g];const E=new Uint8Array(Q);for(let g=0;g<Q;g++,I++)E[g]=A[I];g+=17+Q,B>>4?this.huffmanTablesAC[15&B]=S(C,E):this.huffmanTablesDC[15&B]=S(C,E)}break}case 65501:g(),this.resetInterval=g();break;case 65498:{g();const B=A[I++],C=[],Q=this.frames[0];for(let g=0;g<B;g++){const g=Q.components[A[I++]],B=A[I++];g.huffmanTableDC=this.huffmanTablesDC[B>>4],g.huffmanTableAC=this.huffmanTablesAC[15&B],C.push(g)}const E=A[I++],i=A[I++],s=A[I++],t=N(A,I,Q,C,this.resetInterval,E,i,s>>4,15&s);I+=t;break}case 65535:255!==A[I]&&I--;break;default:if(255===A[I-3]&&A[I-2]>=192&&A[I-2]<=254){I-=3;break}throw new Error(`unknown JPEG marker ${Q.toString(16)}`)}Q=g()}}getResult(){const{frames:A}=this;if(0===this.frames.length)throw new Error("no frames were decoded");this.frames.length>1&&console.warn("more than one frame is not supported");for(let A=0;A<this.frames.length;A++){const I=this.frames[A].components;for(const A of Object.keys(I))I[A].quantizationTable=this.quantizationTables[I[A].quantizationIdx],delete I[A].quantizationIdx}const I=A[0],{components:g,componentsOrder:B}=I,C=[],Q=I.samplesPerLine,E=I.scanLines;for(let A=0;A<B.length;A++){const Q=g[B[A]];C.push({lines:c(0,Q),scaleX:Q.h/I.maxH,scaleY:Q.v/I.maxV})}const i=new Uint8Array(Q*E*C.length);let s=0;for(let A=0;A<E;++A)for(let I=0;I<Q;++I)for(let g=0;g<C.length;++g){const B=C[g];i[s]=B.lines[0|A*B.scaleY][0|I*B.scaleX],++s}return i}}var k=Object.freeze({__proto__:null,default:class extends E{constructor(A){super(),this.reader=new d,A.JPEGTables&&this.reader.parse(A.JPEGTables)}decodeBlock(A){return this.reader.resetFrames(),this.reader.parse(new Uint8Array(A)),this.reader.getResult().buffer}}});\n/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function F(A){let I=A.length;for(;--I>=0;)A[I]=0}const l=256,R=286,U=30,L=15,Y=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),f=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),K=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),u=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),M=new Array(576);F(M);const J=new Array(60);F(J);const H=new Array(512);F(H);const m=new Array(256);F(m);const p=new Array(29);F(p);const q=new Array(U);function b(A,I,g,B,C){this.static_tree=A,this.extra_bits=I,this.extra_base=g,this.elems=B,this.max_length=C,this.has_stree=A&&A.length}let x,_,O;function T(A,I){this.dyn_tree=A,this.max_code=0,this.stat_desc=I}F(q);const Z=A=>A<256?H[A]:H[256+(A>>>7)],v=(A,I)=>{A.pending_buf[A.pending++]=255&I,A.pending_buf[A.pending++]=I>>>8&255},P=(A,I,g)=>{A.bi_valid>16-g?(A.bi_buf|=I<<A.bi_valid&65535,v(A,A.bi_buf),A.bi_buf=I>>16-A.bi_valid,A.bi_valid+=g-16):(A.bi_buf|=I<<A.bi_valid&65535,A.bi_valid+=g)},j=(A,I,g)=>{P(A,g[2*I],g[2*I+1])},W=(A,I)=>{let g=0;do{g|=1&A,A>>>=1,g<<=1}while(--I>0);return g>>>1},V=(A,I,g)=>{const B=new Array(16);let C,Q,E=0;for(C=1;C<=L;C++)E=E+g[C-1]<<1,B[C]=E;for(Q=0;Q<=I;Q++){let I=A[2*Q+1];0!==I&&(A[2*Q]=W(B[I]++,I))}},z=A=>{let I;for(I=0;I<R;I++)A.dyn_ltree[2*I]=0;for(I=0;I<U;I++)A.dyn_dtree[2*I]=0;for(I=0;I<19;I++)A.bl_tree[2*I]=0;A.dyn_ltree[512]=1,A.opt_len=A.static_len=0,A.sym_next=A.matches=0},X=A=>{A.bi_valid>8?v(A,A.bi_buf):A.bi_valid>0&&(A.pending_buf[A.pending++]=A.bi_buf),A.bi_buf=0,A.bi_valid=0},$=(A,I,g,B)=>{const C=2*I,Q=2*g;return A[C]<A[Q]||A[C]===A[Q]&&B[I]<=B[g]},AA=(A,I,g)=>{const B=A.heap[g];let C=g<<1;for(;C<=A.heap_len&&(C<A.heap_len&&$(I,A.heap[C+1],A.heap[C],A.depth)&&C++,!$(I,B,A.heap[C],A.depth));)A.heap[g]=A.heap[C],g=C,C<<=1;A.heap[g]=B},IA=(A,I,g)=>{let B,C,Q,E,i=0;if(0!==A.sym_next)do{B=255&A.pending_buf[A.sym_buf+i++],B+=(255&A.pending_buf[A.sym_buf+i++])<<8,C=A.pending_buf[A.sym_buf+i++],0===B?j(A,C,I):(Q=m[C],j(A,Q+l+1,I),E=Y[Q],0!==E&&(C-=p[Q],P(A,C,E)),B--,Q=Z(B),j(A,Q,g),E=f[Q],0!==E&&(B-=q[Q],P(A,B,E)))}while(i<A.sym_next);j(A,256,I)},gA=(A,I)=>{const g=I.dyn_tree,B=I.stat_desc.static_tree,C=I.stat_desc.has_stree,Q=I.stat_desc.elems;let E,i,s,t=-1;for(A.heap_len=0,A.heap_max=573,E=0;E<Q;E++)0!==g[2*E]?(A.heap[++A.heap_len]=t=E,A.depth[E]=0):g[2*E+1]=0;for(;A.heap_len<2;)s=A.heap[++A.heap_len]=t<2?++t:0,g[2*s]=1,A.depth[s]=0,A.opt_len--,C&&(A.static_len-=B[2*s+1]);for(I.max_code=t,E=A.heap_len>>1;E>=1;E--)AA(A,g,E);s=Q;do{E=A.heap[1],A.heap[1]=A.heap[A.heap_len--],AA(A,g,1),i=A.heap[1],A.heap[--A.heap_max]=E,A.heap[--A.heap_max]=i,g[2*s]=g[2*E]+g[2*i],A.depth[s]=(A.depth[E]>=A.depth[i]?A.depth[E]:A.depth[i])+1,g[2*E+1]=g[2*i+1]=s,A.heap[1]=s++,AA(A,g,1)}while(A.heap_len>=2);A.heap[--A.heap_max]=A.heap[1],((A,I)=>{const g=I.dyn_tree,B=I.max_code,C=I.stat_desc.static_tree,Q=I.stat_desc.has_stree,E=I.stat_desc.extra_bits,i=I.stat_desc.extra_base,s=I.stat_desc.max_length;let t,o,a,e,r,D,h=0;for(e=0;e<=L;e++)A.bl_count[e]=0;for(g[2*A.heap[A.heap_max]+1]=0,t=A.heap_max+1;t<573;t++)o=A.heap[t],e=g[2*g[2*o+1]+1]+1,e>s&&(e=s,h++),g[2*o+1]=e,o>B||(A.bl_count[e]++,r=0,o>=i&&(r=E[o-i]),D=g[2*o],A.opt_len+=D*(e+r),Q&&(A.static_len+=D*(C[2*o+1]+r)));if(0!==h){do{for(e=s-1;0===A.bl_count[e];)e--;A.bl_count[e]--,A.bl_count[e+1]+=2,A.bl_count[s]--,h-=2}while(h>0);for(e=s;0!==e;e--)for(o=A.bl_count[e];0!==o;)a=A.heap[--t],a>B||(g[2*a+1]!==e&&(A.opt_len+=(e-g[2*a+1])*g[2*a],g[2*a+1]=e),o--)}})(A,I),V(g,t,A.bl_count)},BA=(A,I,g)=>{let B,C,Q=-1,E=I[1],i=0,s=7,t=4;for(0===E&&(s=138,t=3),I[2*(g+1)+1]=65535,B=0;B<=g;B++)C=E,E=I[2*(B+1)+1],++i<s&&C===E||(i<t?A.bl_tree[2*C]+=i:0!==C?(C!==Q&&A.bl_tree[2*C]++,A.bl_tree[32]++):i<=10?A.bl_tree[34]++:A.bl_tree[36]++,i=0,Q=C,0===E?(s=138,t=3):C===E?(s=6,t=3):(s=7,t=4))},CA=(A,I,g)=>{let B,C,Q=-1,E=I[1],i=0,s=7,t=4;for(0===E&&(s=138,t=3),B=0;B<=g;B++)if(C=E,E=I[2*(B+1)+1],!(++i<s&&C===E)){if(i<t)do{j(A,C,A.bl_tree)}while(0!==--i);else 0!==C?(C!==Q&&(j(A,C,A.bl_tree),i--),j(A,16,A.bl_tree),P(A,i-3,2)):i<=10?(j(A,17,A.bl_tree),P(A,i-3,3)):(j(A,18,A.bl_tree),P(A,i-11,7));i=0,Q=C,0===E?(s=138,t=3):C===E?(s=6,t=3):(s=7,t=4)}};let QA=!1;const EA=(A,I,g,B)=>{P(A,0+(B?1:0),3),X(A),v(A,g),v(A,~g),g&&A.pending_buf.set(A.window.subarray(I,I+g),A.pending),A.pending+=g};var iA=(A,I,g,B)=>{let C,Q,E=0;A.level>0?(2===A.strm.data_type&&(A.strm.data_type=(A=>{let I,g=4093624447;for(I=0;I<=31;I++,g>>>=1)if(1&g&&0!==A.dyn_ltree[2*I])return 0;if(0!==A.dyn_ltree[18]||0!==A.dyn_ltree[20]||0!==A.dyn_ltree[26])return 1;for(I=32;I<l;I++)if(0!==A.dyn_ltree[2*I])return 1;return 0})(A)),gA(A,A.l_desc),gA(A,A.d_desc),E=(A=>{let I;for(BA(A,A.dyn_ltree,A.l_desc.max_code),BA(A,A.dyn_dtree,A.d_desc.max_code),gA(A,A.bl_desc),I=18;I>=3&&0===A.bl_tree[2*u[I]+1];I--);return A.opt_len+=3*(I+1)+5+5+4,I})(A),C=A.opt_len+3+7>>>3,Q=A.static_len+3+7>>>3,Q<=C&&(C=Q)):C=Q=g+5,g+4<=C&&-1!==I?EA(A,I,g,B):4===A.strategy||Q===C?(P(A,2+(B?1:0),3),IA(A,M,J)):(P(A,4+(B?1:0),3),((A,I,g,B)=>{let C;for(P(A,I-257,5),P(A,g-1,5),P(A,B-4,4),C=0;C<B;C++)P(A,A.bl_tree[2*u[C]+1],3);CA(A,A.dyn_ltree,I-1),CA(A,A.dyn_dtree,g-1)})(A,A.l_desc.max_code+1,A.d_desc.max_code+1,E+1),IA(A,A.dyn_ltree,A.dyn_dtree)),z(A),B&&X(A)},sA={_tr_init:A=>{QA||((()=>{let A,I,g,B,C;const Q=new Array(16);for(g=0,B=0;B<28;B++)for(p[B]=g,A=0;A<1<<Y[B];A++)m[g++]=B;for(m[g-1]=B,C=0,B=0;B<16;B++)for(q[B]=C,A=0;A<1<<f[B];A++)H[C++]=B;for(C>>=7;B<U;B++)for(q[B]=C<<7,A=0;A<1<<f[B]-7;A++)H[256+C++]=B;for(I=0;I<=L;I++)Q[I]=0;for(A=0;A<=143;)M[2*A+1]=8,A++,Q[8]++;for(;A<=255;)M[2*A+1]=9,A++,Q[9]++;for(;A<=279;)M[2*A+1]=7,A++,Q[7]++;for(;A<=287;)M[2*A+1]=8,A++,Q[8]++;for(V(M,287,Q),A=0;A<U;A++)J[2*A+1]=5,J[2*A]=W(A,5);x=new b(M,Y,257,R,L),_=new b(J,f,0,U,L),O=new b(new Array(0),K,0,19,7)})(),QA=!0),A.l_desc=new T(A.dyn_ltree,x),A.d_desc=new T(A.dyn_dtree,_),A.bl_desc=new T(A.bl_tree,O),A.bi_buf=0,A.bi_valid=0,z(A)},_tr_stored_block:EA,_tr_flush_block:iA,_tr_tally:(A,I,g)=>(A.pending_buf[A.sym_buf+A.sym_next++]=I,A.pending_buf[A.sym_buf+A.sym_next++]=I>>8,A.pending_buf[A.sym_buf+A.sym_next++]=g,0===I?A.dyn_ltree[2*g]++:(A.matches++,I--,A.dyn_ltree[2*(m[g]+l+1)]++,A.dyn_dtree[2*Z(I)]++),A.sym_next===A.sym_end),_tr_align:A=>{P(A,2,3),j(A,256,M),(A=>{16===A.bi_valid?(v(A,A.bi_buf),A.bi_buf=0,A.bi_valid=0):A.bi_valid>=8&&(A.pending_buf[A.pending++]=255&A.bi_buf,A.bi_buf>>=8,A.bi_valid-=8)})(A)}};var tA=(A,I,g,B)=>{let C=65535&A,Q=A>>>16&65535,E=0;for(;0!==g;){E=g>2e3?2e3:g,g-=E;do{C=C+I[B++]|0,Q=Q+C|0}while(--E);C%=65521,Q%=65521}return C|Q<<16};const oA=new Uint32Array((()=>{let A,I=[];for(var g=0;g<256;g++){A=g;for(var B=0;B<8;B++)A=1&A?3988292384^A>>>1:A>>>1;I[g]=A}return I})());var aA=(A,I,g,B)=>{const C=oA,Q=B+g;A^=-1;for(let g=B;g<Q;g++)A=A>>>8^C[255&(A^I[g])];return-1^A},eA={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"},rA={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:DA,_tr_stored_block:hA,_tr_flush_block:nA,_tr_tally:wA,_tr_align:yA}=sA,{Z_NO_FLUSH:GA,Z_PARTIAL_FLUSH:SA,Z_FULL_FLUSH:NA,Z_FINISH:cA,Z_BLOCK:dA,Z_OK:kA,Z_STREAM_END:FA,Z_STREAM_ERROR:lA,Z_DATA_ERROR:RA,Z_BUF_ERROR:UA,Z_DEFAULT_COMPRESSION:LA,Z_FILTERED:YA,Z_HUFFMAN_ONLY:fA,Z_RLE:KA,Z_FIXED:uA,Z_DEFAULT_STRATEGY:MA,Z_UNKNOWN:JA,Z_DEFLATED:HA}=rA,mA=258,pA=262,qA=42,bA=113,xA=666,_A=(A,I)=>(A.msg=eA[I],I),OA=A=>2*A-(A>4?9:0),TA=A=>{let I=A.length;for(;--I>=0;)A[I]=0},ZA=A=>{let I,g,B,C=A.w_size;I=A.hash_size,B=I;do{g=A.head[--B],A.head[B]=g>=C?g-C:0}while(--I);I=C,B=I;do{g=A.prev[--B],A.prev[B]=g>=C?g-C:0}while(--I)};let vA=(A,I,g)=>(I<<A.hash_shift^g)&A.hash_mask;const PA=A=>{const I=A.state;let g=I.pending;g>A.avail_out&&(g=A.avail_out),0!==g&&(A.output.set(I.pending_buf.subarray(I.pending_out,I.pending_out+g),A.next_out),A.next_out+=g,I.pending_out+=g,A.total_out+=g,A.avail_out-=g,I.pending-=g,0===I.pending&&(I.pending_out=0))},jA=(A,I)=>{nA(A,A.block_start>=0?A.block_start:-1,A.strstart-A.block_start,I),A.block_start=A.strstart,PA(A.strm)},WA=(A,I)=>{A.pending_buf[A.pending++]=I},VA=(A,I)=>{A.pending_buf[A.pending++]=I>>>8&255,A.pending_buf[A.pending++]=255&I},zA=(A,I,g,B)=>{let C=A.avail_in;return C>B&&(C=B),0===C?0:(A.avail_in-=C,I.set(A.input.subarray(A.next_in,A.next_in+C),g),1===A.state.wrap?A.adler=tA(A.adler,I,C,g):2===A.state.wrap&&(A.adler=aA(A.adler,I,C,g)),A.next_in+=C,A.total_in+=C,C)},XA=(A,I)=>{let g,B,C=A.max_chain_length,Q=A.strstart,E=A.prev_length,i=A.nice_match;const s=A.strstart>A.w_size-pA?A.strstart-(A.w_size-pA):0,t=A.window,o=A.w_mask,a=A.prev,e=A.strstart+mA;let r=t[Q+E-1],D=t[Q+E];A.prev_length>=A.good_match&&(C>>=2),i>A.lookahead&&(i=A.lookahead);do{if(g=I,t[g+E]===D&&t[g+E-1]===r&&t[g]===t[Q]&&t[++g]===t[Q+1]){Q+=2,g++;do{}while(t[++Q]===t[++g]&&t[++Q]===t[++g]&&t[++Q]===t[++g]&&t[++Q]===t[++g]&&t[++Q]===t[++g]&&t[++Q]===t[++g]&&t[++Q]===t[++g]&&t[++Q]===t[++g]&&Q<e);if(B=mA-(e-Q),Q=e-mA,B>E){if(A.match_start=I,E=B,B>=i)break;r=t[Q+E-1],D=t[Q+E]}}}while((I=a[I&o])>s&&0!==--C);return E<=A.lookahead?E:A.lookahead},$A=A=>{const I=A.w_size;let g,B,C;do{if(B=A.window_size-A.lookahead-A.strstart,A.strstart>=I+(I-pA)&&(A.window.set(A.window.subarray(I,I+I-B),0),A.match_start-=I,A.strstart-=I,A.block_start-=I,A.insert>A.strstart&&(A.insert=A.strstart),ZA(A),B+=I),0===A.strm.avail_in)break;if(g=zA(A.strm,A.window,A.strstart+A.lookahead,B),A.lookahead+=g,A.lookahead+A.insert>=3)for(C=A.strstart-A.insert,A.ins_h=A.win